diff --git a/ACL_PyTorch/built-in/audio/Jasper_for_PyTorch/pth2onnx.py b/ACL_PyTorch/built-in/audio/Jasper_for_PyTorch/pth2onnx.py index a3aec9ce403f52cfa6b2af3e0285615e6cafabb4..1178e0b2df44f3f439efb91d2bf39bb4b8465fbd 100644 --- a/ACL_PyTorch/built-in/audio/Jasper_for_PyTorch/pth2onnx.py +++ b/ACL_PyTorch/built-in/audio/Jasper_for_PyTorch/pth2onnx.py @@ -1,44 +1,44 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -from jasper import config -from common import helpers -from jasper.model import Jasper - - -def main(): - cfg = config.load('configs/jasper10x5dr_speedp-online_speca.yaml') - model = Jasper(encoder_kw=config.encoder(cfg), - decoder_kw=config.decoder(cfg, n_classes=29)) - checkpoint = torch.load('checkpoints/jasper_fp16.pt', map_location="cpu") - state_dict = helpers.convert_v1_state_dict(checkpoint['ema_state_dict']) - model.load_state_dict(state_dict, strict=True) - model.eval() - - feats = torch.randn([4, 64, 4000], dtype=torch.float32) - feat_lens = torch.tensor([1000], dtype=torch.int32) - dynamic_axes = {'feats': {2: '-1'}, 'output': {1: '-1'}} - torch.onnx.export(model, - (feats, feat_lens), - 'jasper_dynamic.onnx', - input_names=['feats', 'feat_lens'], - output_names=['output'], - dynamic_axes=dynamic_axes, - verbose=True, - opset_version=11) - - -if __name__ == '__main__': - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +from jasper import config +from common import helpers +from jasper.model import Jasper + + +def main(): + cfg = config.load('configs/jasper10x5dr_speedp-online_speca.yaml') + model = Jasper(encoder_kw=config.encoder(cfg), + decoder_kw=config.decoder(cfg, n_classes=29)) + checkpoint = torch.load('checkpoints/jasper_fp16.pt', map_location="cpu") + state_dict = helpers.convert_v1_state_dict(checkpoint['ema_state_dict']) + model.load_state_dict(state_dict, strict=True) + model.eval() + + feats = torch.randn([4, 64, 4000], dtype=torch.float32) + feat_lens = torch.tensor([1000], dtype=torch.int32) + dynamic_axes = {'feats': {2: '-1'}, 'output': {1: '-1'}} + torch.onnx.export(model, + (feats, feat_lens), + 'jasper_dynamic.onnx', + input_names=['feats', 'feat_lens'], + output_names=['output'], + dynamic_axes=dynamic_axes, + verbose=True, + opset_version=11) + + +if __name__ == '__main__': + main() diff --git a/ACL_PyTorch/built-in/audio/Jasper_for_PyTorch/requirements.txt b/ACL_PyTorch/built-in/audio/Jasper_for_PyTorch/requirements.txt index 36faa7e8ae5def0758173bdfd674c34e1858d0c7..5ad9b7d6cc62f483ab75300264ccecae9ac18917 100644 --- a/ACL_PyTorch/built-in/audio/Jasper_for_PyTorch/requirements.txt +++ b/ACL_PyTorch/built-in/audio/Jasper_for_PyTorch/requirements.txt @@ -1,16 +1,16 @@ -torchvision==0.9.0 -torch==1.8.0 -onnx==1.8.0 -numpy==1.18.5 -ascii-graph==1.5.1 -inflect==5.3.0 -ipdb -librosa==0.8.0 -pandas==1.1.4 -pycuda==2020.1 -pyyaml>=5.4 -soundfile -sox==1.4.1 -tqdm==4.53.0 -unidecode==1.2.0 +torchvision==0.9.0 +torch==1.8.0 +onnx==1.8.0 +numpy==1.18.5 +ascii-graph==1.5.1 +inflect==5.3.0 +ipdb +librosa==0.8.0 +pandas==1.1.4 +pycuda==2020.1 +pyyaml>=5.4 +soundfile +sox==1.4.1 +tqdm==4.53.0 +unidecode==1.2.0 wrapt==1.10.11 \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/LSTM/LICENSE b/ACL_PyTorch/built-in/audio/LSTM/LICENSE index 6052d47b9e4fad14635ad0392bfd592af254b951..835428fbaa90df1fa50963023aacfb2305ad9cd9 100644 --- a/ACL_PyTorch/built-in/audio/LSTM/LICENSE +++ b/ACL_PyTorch/built-in/audio/LSTM/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/LSTM/LSTM_get_info.py b/ACL_PyTorch/built-in/audio/LSTM/LSTM_get_info.py index ea8300ce457d7dc6234ce80b56d5c59256da67d6..f89051ed81320fb541f1b97150781dae21d7aeaf 100644 --- a/ACL_PyTorch/built-in/audio/LSTM/LSTM_get_info.py +++ b/ACL_PyTorch/built-in/audio/LSTM/LSTM_get_info.py @@ -1,34 +1,34 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import argparse - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('--batchsize', help='conf file for training') - args = parser.parse_args() - - test_num = 400 // int(args.batchsize) - lstm_path = './lstm_bin/' - - with open('./lstm.info', 'w') as f: - for i in range(test_num): - ids_name = lstm_path + 'inputs_{}.bin'.format(i) - f.write(str(i) + ' ' + ids_name + ' ' + '(' + args.batchsize + ',390,243)') - f.write('\n') - -if __name__ == '__main__': +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import argparse + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--batchsize', help='conf file for training') + args = parser.parse_args() + + test_num = 400 // int(args.batchsize) + lstm_path = './lstm_bin/' + + with open('./lstm.info', 'w') as f: + for i in range(test_num): + ids_name = lstm_path + 'inputs_{}.bin'.format(i) + f.write(str(i) + ' ' + ids_name + ' ' + '(' + args.batchsize + ',390,243)') + f.write('\n') + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/LSTM/LSTM_postprocess_data.py b/ACL_PyTorch/built-in/audio/LSTM/LSTM_postprocess_data.py index 4ec77e30d6c05ee46d6db400e4cf641a5d5bbd53..8fd0d995c67152b8aaebf1527eb48f7a789776ac 100644 --- a/ACL_PyTorch/built-in/audio/LSTM/LSTM_postprocess_data.py +++ b/ACL_PyTorch/built-in/audio/LSTM/LSTM_postprocess_data.py @@ -1,114 +1,114 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#!/usr/bin/python -#encoding=utf-8 - -import os -import time -import sys -import torch -import yaml -import argparse -import torch.nn as nn -import numpy as np - -sys.path.append('./') -from models.model_ctc import * -from utils.ctcDecoder import GreedyDecoder, BeamDecoder -from utils.data_loader import Vocab, SpeechDataset, SpeechDataLoader - -parser = argparse.ArgumentParser() -parser.add_argument('--conf', help='conf file for training') -parser.add_argument('--npu_path', help='infer file for postprocessing') -parser.add_argument('--batchsize', help='batchsize for postprocessing') - -class Config(object): - batch_size = 4 - dropout = 0.1 - -def test(): - args = parser.parse_args() - try: - conf = yaml.safe_load(open(args.conf,'r')) - except: - print("Config file not exist!") - sys.exit(1) - - opts = Config() - for k,v in conf.items(): - setattr(opts, k, v) - print('{:50}:{}'.format(k, v)) - - beam_width = opts.beam_width - lm_alpha = opts.lm_alpha - decoder_type = opts.decode_type - vocab_file = opts.vocab_file - - vocab = Vocab(vocab_file) - batchsize = int(args.batchsize) - - test_dataset = SpeechDataset(vocab, opts.valid_scp_path, opts.valid_lab_path, opts) - test_loader = SpeechDataLoader(test_dataset, batch_size=batchsize, shuffle=False, num_workers=opts.num_workers, pin_memory=False) - - if decoder_type == 'Greedy': - decoder = GreedyDecoder(vocab.index2word, space_idx=-1, blank_index=0) - else: - decoder = BeamDecoder(vocab.index2word, beam_width=beam_width, blank_index=0, space_idx=-1, lm_path=opts.lm_path, lm_alpha=opts.lm_alpha) - - total_wer = 0 - total_cer = 0 - start = time.time() - - npu_path = args.npu_path - test_num = 399 // batchsize - with torch.no_grad(): - for i, data in zip(range(test_num), test_loader): - inputs, input_sizes, targets, target_sizes, utt_list = data - probs_1_np = np.load('{}{}.0.npy'.format(npu_path, i)) - probs_1 = torch.from_numpy(probs_1_np) - - max_length = probs_1.size(0) - input_sizes = (input_sizes * max_length).long() - - decoded = decoder.decode(probs_1, input_sizes.numpy().tolist()) - targets, target_sizes = targets.numpy(), target_sizes.numpy() - labels = [] - for i in range(len(targets)): - label = [ vocab.index2word[num] for num in targets[i][:target_sizes[i]]] - labels.append(' '.join(label)) - - for x in range(len(targets)): - print("origin : " + labels[x]) - print("decoded: " + decoded[x]) - cer = 0 - wer = 0 - for x in range(len(labels)): - cer += decoder.cer(decoded[x], labels[x]) - wer += decoder.wer(decoded[x], labels[x]) - decoder.num_word += len(labels[x].split()) - decoder.num_char += len(labels[x]) - total_cer += cer - total_wer += wer - - CER = (float(total_cer) / decoder.num_char)*100 - WER = (float(total_wer) / decoder.num_word)*100 - print("Character error rate on test set: %.4f" % CER) - print("Word error rate on test set: %.4f" % WER) - end = time.time() - time_used = (end - start) / 60.0 - print("time used for decode %d sentences: %.4f minutes." % (len(test_dataset), time_used)) - -if __name__ == "__main__": - test() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#!/usr/bin/python +#encoding=utf-8 + +import os +import time +import sys +import torch +import yaml +import argparse +import torch.nn as nn +import numpy as np + +sys.path.append('./') +from models.model_ctc import * +from utils.ctcDecoder import GreedyDecoder, BeamDecoder +from utils.data_loader import Vocab, SpeechDataset, SpeechDataLoader + +parser = argparse.ArgumentParser() +parser.add_argument('--conf', help='conf file for training') +parser.add_argument('--npu_path', help='infer file for postprocessing') +parser.add_argument('--batchsize', help='batchsize for postprocessing') + +class Config(object): + batch_size = 4 + dropout = 0.1 + +def test(): + args = parser.parse_args() + try: + conf = yaml.safe_load(open(args.conf,'r')) + except: + print("Config file not exist!") + sys.exit(1) + + opts = Config() + for k,v in conf.items(): + setattr(opts, k, v) + print('{:50}:{}'.format(k, v)) + + beam_width = opts.beam_width + lm_alpha = opts.lm_alpha + decoder_type = opts.decode_type + vocab_file = opts.vocab_file + + vocab = Vocab(vocab_file) + batchsize = int(args.batchsize) + + test_dataset = SpeechDataset(vocab, opts.valid_scp_path, opts.valid_lab_path, opts) + test_loader = SpeechDataLoader(test_dataset, batch_size=batchsize, shuffle=False, num_workers=opts.num_workers, pin_memory=False) + + if decoder_type == 'Greedy': + decoder = GreedyDecoder(vocab.index2word, space_idx=-1, blank_index=0) + else: + decoder = BeamDecoder(vocab.index2word, beam_width=beam_width, blank_index=0, space_idx=-1, lm_path=opts.lm_path, lm_alpha=opts.lm_alpha) + + total_wer = 0 + total_cer = 0 + start = time.time() + + npu_path = args.npu_path + test_num = 399 // batchsize + with torch.no_grad(): + for i, data in zip(range(test_num), test_loader): + inputs, input_sizes, targets, target_sizes, utt_list = data + probs_1_np = np.load('{}{}.0.npy'.format(npu_path, i)) + probs_1 = torch.from_numpy(probs_1_np) + + max_length = probs_1.size(0) + input_sizes = (input_sizes * max_length).long() + + decoded = decoder.decode(probs_1, input_sizes.numpy().tolist()) + targets, target_sizes = targets.numpy(), target_sizes.numpy() + labels = [] + for i in range(len(targets)): + label = [ vocab.index2word[num] for num in targets[i][:target_sizes[i]]] + labels.append(' '.join(label)) + + for x in range(len(targets)): + print("origin : " + labels[x]) + print("decoded: " + decoded[x]) + cer = 0 + wer = 0 + for x in range(len(labels)): + cer += decoder.cer(decoded[x], labels[x]) + wer += decoder.wer(decoded[x], labels[x]) + decoder.num_word += len(labels[x].split()) + decoder.num_char += len(labels[x]) + total_cer += cer + total_wer += wer + + CER = (float(total_cer) / decoder.num_char)*100 + WER = (float(total_wer) / decoder.num_word)*100 + print("Character error rate on test set: %.4f" % CER) + print("Word error rate on test set: %.4f" % WER) + end = time.time() + time_used = (end - start) / 60.0 + print("time used for decode %d sentences: %.4f minutes." % (len(test_dataset), time_used)) + +if __name__ == "__main__": + test() diff --git a/ACL_PyTorch/built-in/audio/LSTM/LSTM_preprocess_data.py b/ACL_PyTorch/built-in/audio/LSTM/LSTM_preprocess_data.py index 75f129861d27b71770ae6082697cd92ffcfd1773..297aa1b0d7a5b42fc2910e65eeb322013c251364 100644 --- a/ACL_PyTorch/built-in/audio/LSTM/LSTM_preprocess_data.py +++ b/ACL_PyTorch/built-in/audio/LSTM/LSTM_preprocess_data.py @@ -1,80 +1,80 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# !/usr/bin/python -# encoding=utf-8 - -import os -import sys -import copy -import time -import yaml -import shutil -import argparse -import numpy as np -import random -import torch -import torch.nn as nn -import torch.backends.cudnn as cudnn -from torch.utils.tensorboard import SummaryWriter - -sys.path.append('./') -from models.model_ctc import * -from utils.data_loader import Vocab, SpeechDataset, SpeechDataLoader - -supported_rnn = {'nn.LSTM': nn.LSTM, 'nn.GRU': nn.GRU, 'nn.RNN': nn.RNN} -supported_activate = {'relu': nn.ReLU, 'tanh': nn.Tanh, 'sigmoid': nn.Sigmoid} - -parser = argparse.ArgumentParser() -parser.add_argument('--conf', help='conf file for training') -parser.add_argument('--batchsize', help='batchsize for preprocessing') - -class Config(object): - batch_size = 4 - dropout = 0.1 - -def main(): - args = parser.parse_args() - try: - conf = yaml.safe_load(open(args.conf,'r')) - except: - print("Config file not exist!") - sys.exit(1) - - opts = Config() - for k,v in conf.items(): - setattr(opts, k, v) - print('{:50}:{}'.format(k, v)) - - # Data Loader - batchsize = int(args.batchsize) - vocab = Vocab(opts.vocab_file) - dev_dataset = SpeechDataset(vocab, opts.valid_scp_path, opts.valid_lab_path, opts) - dev_loader = SpeechDataLoader(dev_dataset, batch_size=batchsize, shuffle=False, num_workers=opts.num_workers, - drop_last=True, pin_memory=True) - - bin_path = "./lstm_bin" - if os.path.exists(bin_path): - shutil.rmtree(bin_path) - os.makedirs(bin_path) - i = -1 - for data in dev_loader: - i = i + 1 - print("[info] file", "===", i) - inputs, input_sizes, targets, target_sizes, utt_list = data - inputs_np = inputs.numpy() - inputs_np.tofile(os.path.join(bin_path, "inputs_" + str(i) + '.bin')) - -if __name__ == '__main__': - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# !/usr/bin/python +# encoding=utf-8 + +import os +import sys +import copy +import time +import yaml +import shutil +import argparse +import numpy as np +import random +import torch +import torch.nn as nn +import torch.backends.cudnn as cudnn +from torch.utils.tensorboard import SummaryWriter + +sys.path.append('./') +from models.model_ctc import * +from utils.data_loader import Vocab, SpeechDataset, SpeechDataLoader + +supported_rnn = {'nn.LSTM': nn.LSTM, 'nn.GRU': nn.GRU, 'nn.RNN': nn.RNN} +supported_activate = {'relu': nn.ReLU, 'tanh': nn.Tanh, 'sigmoid': nn.Sigmoid} + +parser = argparse.ArgumentParser() +parser.add_argument('--conf', help='conf file for training') +parser.add_argument('--batchsize', help='batchsize for preprocessing') + +class Config(object): + batch_size = 4 + dropout = 0.1 + +def main(): + args = parser.parse_args() + try: + conf = yaml.safe_load(open(args.conf,'r')) + except: + print("Config file not exist!") + sys.exit(1) + + opts = Config() + for k,v in conf.items(): + setattr(opts, k, v) + print('{:50}:{}'.format(k, v)) + + # Data Loader + batchsize = int(args.batchsize) + vocab = Vocab(opts.vocab_file) + dev_dataset = SpeechDataset(vocab, opts.valid_scp_path, opts.valid_lab_path, opts) + dev_loader = SpeechDataLoader(dev_dataset, batch_size=batchsize, shuffle=False, num_workers=opts.num_workers, + drop_last=True, pin_memory=True) + + bin_path = "./lstm_bin" + if os.path.exists(bin_path): + shutil.rmtree(bin_path) + os.makedirs(bin_path) + i = -1 + for data in dev_loader: + i = i + 1 + print("[info] file", "===", i) + inputs, input_sizes, targets, target_sizes, utt_list = data + inputs_np = inputs.numpy() + inputs_np.tofile(os.path.join(bin_path, "inputs_" + str(i) + '.bin')) + +if __name__ == '__main__': + main() diff --git a/ACL_PyTorch/built-in/audio/LSTM/LSTM_pth2onnx.py b/ACL_PyTorch/built-in/audio/LSTM/LSTM_pth2onnx.py index 0b68d2f79557d4404743a73ccc26df3247736a48..2aa34a62a33aaa0dee7070098c82f8955a35e2aa 100644 --- a/ACL_PyTorch/built-in/audio/LSTM/LSTM_pth2onnx.py +++ b/ACL_PyTorch/built-in/audio/LSTM/LSTM_pth2onnx.py @@ -1,231 +1,231 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#!/usr/bin/python -#encoding=utf-8 - -import os -import sys -import copy -import time -import yaml -import argparse -import numpy as np -import random -import torch -import torch.nn as nn -import torch.backends.cudnn as cudnn -from torch.utils.tensorboard import SummaryWriter -import torch.onnx -from collections import OrderedDict -import ssl -sys.path.append('./') -from models.model_ctc import * - -supported_rnn = {'nn.LSTM':nn.LSTM, 'nn.GRU': nn.GRU, 'nn.RNN':nn.RNN} -supported_activate = {'relu':nn.ReLU, 'tanh':nn.Tanh, 'sigmoid':nn.Sigmoid} - -parser = argparse.ArgumentParser(description='cnn_lstm_ctc') -parser.add_argument('--conf', default='conf/ctc_config.yaml' , help='conf file with argument of LSTM and training') -parser.add_argument('--batchsize', default=1, help='batchszie for transfer onnx batch') - -class Vocab(object): - def __init__(self, vocab_file): - self.vocab_file = vocab_file - self.word2index = {"blank": 0, "UNK": 1} - self.index2word = {0: "blank", 1: "UNK"} - self.word2count = {} - self.n_words = 2 - self.read_lang() - - def add_sentence(self, sentence): - for word in sentence.split(' '): - self.add_word(word) - - def add_word(self, word): - if word not in self.word2index: - self.word2index[word] = self.n_words - self.word2count[word] = 1 - self.index2word[self.n_words] = word - self.n_words += 1 - else: - self.word2count[word] += 1 - - def read_lang(self): - print("Reading vocabulary from {}".format(self.vocab_file)) - with open(self.vocab_file, 'r') as rf: - line = rf.readline() - while line: - line = line.strip().split(' ') - if len(line) > 1: - sen = ' '.join(line[1:]) - else: - sen = line[0] - self.add_sentence(sen) - line = rf.readline() - print("Vocabulary size is {}".format(self.n_words)) - - -def proc_nodes_module(checkpoint,AttrName): - new_state_dict = OrderedDict() - for k,v in checkpoint[AttrName].items(): - if(k[0:7] == "module."): - name = k[7:] - else: - name = k[0:] - - new_state_dict[name]=v - return new_state_dict - -def run_epoch(epoch_id, model, data_iter, loss_fn, device, opts, sum_writer, optimizer=None, print_every=20, is_training=True): - if is_training: - model.train() - else: - model.eval() - batch_time = 0 - data_time = 0 - total_loss = 0 - total_tokens = 0 - total_errs = 0 - cur_loss = 0 - i = 0 - steps_per_epoch = len(data_iter) - end = time.time() - for i, data in enumerate(data_iter): - data_time += (time.time() - end) - - global_step = epoch_id * steps_per_epoch + i - inputs, input_sizes, targets, target_sizes, utt_list = data - with torch.autograd.profiler.profile(record_shapes=True, use_cuda=True) as prof: - inputs = inputs.to(device) - input_sizes = input_sizes.to(device) - targets = targets.to(device) - target_sizes = target_sizes.to(device) - out = model(inputs) - out_len, batch_size, _ = out.size() - input_sizes = (input_sizes * out_len).long() - print(out.shape, targets.shape) - print("input_sizes:", input_sizes.shape) - print("target_sizes:", target_sizes.shape) - loss = loss_fn(out, targets, input_sizes, target_sizes) - loss /= batch_size - cur_loss += loss.item() - total_loss += loss.item() - prob, index = torch.max(out, dim=-1) - batch_errs, batch_tokens = model.compute_wer(index.transpose(0,1).cpu().numpy(), input_sizes.cpu().numpy(), targets.cpu().numpy(), target_sizes.cpu().numpy()) - total_errs += batch_errs - total_tokens += batch_tokens - - if is_training: - optimizer.zero_grad() - if opts.opt_level and opts.use_gpu: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - sum_writer.add_scalar('Accuary/train/total_loss', total_loss / (i+1), global_step) - sum_writer.add_scalar('Accuary/train/total_wer', total_errs / total_tokens, global_step) - prof.export_chrome_trace('prof/'+str(i) + "_cuda_lstm.prof") - batch_time += (time.time() - end) - if is_training: - print('Epoch: [%d] [%d / %d], Time %.6f Data %.6f s, total_loss = %.5f s, total_wer = %.5f' % (epoch_id, - i+1, steps_per_epoch, batch_time / (i+1), data_time / (i+1), total_loss / (i+1), total_errs / total_tokens )) - end = time.time() - - - average_loss = total_loss / (i+1) - training = "Train" if is_training else "Valid" - return 1-total_errs / total_tokens, average_loss - -class Config(object): - batch_size = 4 - dropout = 0.1 - -def seed_everything(seed): - random.seed(seed) - os.environ['PYTHONHASHSEED'] = str(seed) - np.random.seed(seed) - torch.manual_seed(seed) - torch.cuda.manual_seed(seed) - torch.cuda.manual_seed_all(seed) - cudnn.deterministic = True - torch.backends.cudnn.deterministic = True - torch.backends.cudnn.benchmark = False - -def main(conf, batchsize): - checkpoint = torch.load("./checkpoint/ctc_fbank_cnn/ctc_best_model.pth", map_location='cpu') - checkpoint['state_dict'] = proc_nodes_module(checkpoint,'state_dict') - opts = Config() - for k, v in conf.items(): - setattr(opts, k, v) - print('{:50}:{}'.format(k, v)) - - device = torch.device('cpu') - sum_writer = SummaryWriter(opts.summary_path) - - if opts.seed is not None: - seed_everything(opts.seed) - - #Data Loader - vocab = Vocab(opts.vocab_file) - #Define Model - rnn_type = supported_rnn[opts.rnn_type] - rnn_param = {"rnn_input_size":opts.rnn_input_size, "rnn_hidden_size":opts.rnn_hidden_size, "rnn_layers":opts.rnn_layers, - "rnn_type":rnn_type, "bidirectional":opts.bidirectional, "batch_norm":opts.batch_norm} - - num_class = vocab.n_words - opts.output_class_dim = vocab.n_words - drop_out = opts.drop_out - add_cnn = opts.add_cnn - - cnn_param = {} - channel = eval(opts.channel) - kernel_size = eval(opts.kernel_size) - stride = eval(opts.stride) - padding = eval(opts.padding) - pooling = eval(opts.pooling) - activation_function = supported_activate[opts.activation_function] - cnn_param['batch_norm'] = opts.batch_norm - cnn_param['activate_function'] = activation_function - cnn_param["layer"] = [] - for layer in range(opts.layers): - layer_param = [channel[layer], kernel_size[layer], stride[layer], padding[layer]] - if pooling is not None: - layer_param.append(pooling[layer]) - else: - layer_param.append(None) - cnn_param["layer"].append(layer_param) - model = CTC_Model(add_cnn=add_cnn, cnn_param=cnn_param, rnn_param=rnn_param, num_class=num_class, drop_out=drop_out) - model = model.to('cpu') - model.load_state_dict(checkpoint['state_dict'],strict=False) - model.eval() - input_names = ["actual_input_1"] - output_names = ["output1"] - batch_size = int(batchsize) - dummy_input = torch.randn(batch_size, 390, 243, device='cpu') - dynamic_axes = {'actual_input_1': {0: '-1'}, 'output1': {1: '-1'}} - output_file = "lstm_ctc_{}batch.onnx".format(str(batch_size)) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, output_names = output_names, opset_version=11) -if __name__ == '__main__': - ssl._create_default_https_context = ssl._create_unverified_context - args = parser.parse_args() - batchsize = args.batchsize - try: - config_path = args.conf - conf = yaml.safe_load(open(config_path, 'r')) - except: - print("No input config or config file missing, please check.") - sys.exit(1) - main(conf, batchsize) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#!/usr/bin/python +#encoding=utf-8 + +import os +import sys +import copy +import time +import yaml +import argparse +import numpy as np +import random +import torch +import torch.nn as nn +import torch.backends.cudnn as cudnn +from torch.utils.tensorboard import SummaryWriter +import torch.onnx +from collections import OrderedDict +import ssl +sys.path.append('./') +from models.model_ctc import * + +supported_rnn = {'nn.LSTM':nn.LSTM, 'nn.GRU': nn.GRU, 'nn.RNN':nn.RNN} +supported_activate = {'relu':nn.ReLU, 'tanh':nn.Tanh, 'sigmoid':nn.Sigmoid} + +parser = argparse.ArgumentParser(description='cnn_lstm_ctc') +parser.add_argument('--conf', default='conf/ctc_config.yaml' , help='conf file with argument of LSTM and training') +parser.add_argument('--batchsize', default=1, help='batchszie for transfer onnx batch') + +class Vocab(object): + def __init__(self, vocab_file): + self.vocab_file = vocab_file + self.word2index = {"blank": 0, "UNK": 1} + self.index2word = {0: "blank", 1: "UNK"} + self.word2count = {} + self.n_words = 2 + self.read_lang() + + def add_sentence(self, sentence): + for word in sentence.split(' '): + self.add_word(word) + + def add_word(self, word): + if word not in self.word2index: + self.word2index[word] = self.n_words + self.word2count[word] = 1 + self.index2word[self.n_words] = word + self.n_words += 1 + else: + self.word2count[word] += 1 + + def read_lang(self): + print("Reading vocabulary from {}".format(self.vocab_file)) + with open(self.vocab_file, 'r') as rf: + line = rf.readline() + while line: + line = line.strip().split(' ') + if len(line) > 1: + sen = ' '.join(line[1:]) + else: + sen = line[0] + self.add_sentence(sen) + line = rf.readline() + print("Vocabulary size is {}".format(self.n_words)) + + +def proc_nodes_module(checkpoint,AttrName): + new_state_dict = OrderedDict() + for k,v in checkpoint[AttrName].items(): + if(k[0:7] == "module."): + name = k[7:] + else: + name = k[0:] + + new_state_dict[name]=v + return new_state_dict + +def run_epoch(epoch_id, model, data_iter, loss_fn, device, opts, sum_writer, optimizer=None, print_every=20, is_training=True): + if is_training: + model.train() + else: + model.eval() + batch_time = 0 + data_time = 0 + total_loss = 0 + total_tokens = 0 + total_errs = 0 + cur_loss = 0 + i = 0 + steps_per_epoch = len(data_iter) + end = time.time() + for i, data in enumerate(data_iter): + data_time += (time.time() - end) + + global_step = epoch_id * steps_per_epoch + i + inputs, input_sizes, targets, target_sizes, utt_list = data + with torch.autograd.profiler.profile(record_shapes=True, use_cuda=True) as prof: + inputs = inputs.to(device) + input_sizes = input_sizes.to(device) + targets = targets.to(device) + target_sizes = target_sizes.to(device) + out = model(inputs) + out_len, batch_size, _ = out.size() + input_sizes = (input_sizes * out_len).long() + print(out.shape, targets.shape) + print("input_sizes:", input_sizes.shape) + print("target_sizes:", target_sizes.shape) + loss = loss_fn(out, targets, input_sizes, target_sizes) + loss /= batch_size + cur_loss += loss.item() + total_loss += loss.item() + prob, index = torch.max(out, dim=-1) + batch_errs, batch_tokens = model.compute_wer(index.transpose(0,1).cpu().numpy(), input_sizes.cpu().numpy(), targets.cpu().numpy(), target_sizes.cpu().numpy()) + total_errs += batch_errs + total_tokens += batch_tokens + + if is_training: + optimizer.zero_grad() + if opts.opt_level and opts.use_gpu: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + sum_writer.add_scalar('Accuary/train/total_loss', total_loss / (i+1), global_step) + sum_writer.add_scalar('Accuary/train/total_wer', total_errs / total_tokens, global_step) + prof.export_chrome_trace('prof/'+str(i) + "_cuda_lstm.prof") + batch_time += (time.time() - end) + if is_training: + print('Epoch: [%d] [%d / %d], Time %.6f Data %.6f s, total_loss = %.5f s, total_wer = %.5f' % (epoch_id, + i+1, steps_per_epoch, batch_time / (i+1), data_time / (i+1), total_loss / (i+1), total_errs / total_tokens )) + end = time.time() + + + average_loss = total_loss / (i+1) + training = "Train" if is_training else "Valid" + return 1-total_errs / total_tokens, average_loss + +class Config(object): + batch_size = 4 + dropout = 0.1 + +def seed_everything(seed): + random.seed(seed) + os.environ['PYTHONHASHSEED'] = str(seed) + np.random.seed(seed) + torch.manual_seed(seed) + torch.cuda.manual_seed(seed) + torch.cuda.manual_seed_all(seed) + cudnn.deterministic = True + torch.backends.cudnn.deterministic = True + torch.backends.cudnn.benchmark = False + +def main(conf, batchsize): + checkpoint = torch.load("./checkpoint/ctc_fbank_cnn/ctc_best_model.pth", map_location='cpu') + checkpoint['state_dict'] = proc_nodes_module(checkpoint,'state_dict') + opts = Config() + for k, v in conf.items(): + setattr(opts, k, v) + print('{:50}:{}'.format(k, v)) + + device = torch.device('cpu') + sum_writer = SummaryWriter(opts.summary_path) + + if opts.seed is not None: + seed_everything(opts.seed) + + #Data Loader + vocab = Vocab(opts.vocab_file) + #Define Model + rnn_type = supported_rnn[opts.rnn_type] + rnn_param = {"rnn_input_size":opts.rnn_input_size, "rnn_hidden_size":opts.rnn_hidden_size, "rnn_layers":opts.rnn_layers, + "rnn_type":rnn_type, "bidirectional":opts.bidirectional, "batch_norm":opts.batch_norm} + + num_class = vocab.n_words + opts.output_class_dim = vocab.n_words + drop_out = opts.drop_out + add_cnn = opts.add_cnn + + cnn_param = {} + channel = eval(opts.channel) + kernel_size = eval(opts.kernel_size) + stride = eval(opts.stride) + padding = eval(opts.padding) + pooling = eval(opts.pooling) + activation_function = supported_activate[opts.activation_function] + cnn_param['batch_norm'] = opts.batch_norm + cnn_param['activate_function'] = activation_function + cnn_param["layer"] = [] + for layer in range(opts.layers): + layer_param = [channel[layer], kernel_size[layer], stride[layer], padding[layer]] + if pooling is not None: + layer_param.append(pooling[layer]) + else: + layer_param.append(None) + cnn_param["layer"].append(layer_param) + model = CTC_Model(add_cnn=add_cnn, cnn_param=cnn_param, rnn_param=rnn_param, num_class=num_class, drop_out=drop_out) + model = model.to('cpu') + model.load_state_dict(checkpoint['state_dict'],strict=False) + model.eval() + input_names = ["actual_input_1"] + output_names = ["output1"] + batch_size = int(batchsize) + dummy_input = torch.randn(batch_size, 390, 243, device='cpu') + dynamic_axes = {'actual_input_1': {0: '-1'}, 'output1': {1: '-1'}} + output_file = "lstm_ctc_{}batch.onnx".format(str(batch_size)) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, output_names = output_names, opset_version=11) +if __name__ == '__main__': + ssl._create_default_https_context = ssl._create_unverified_context + args = parser.parse_args() + batchsize = args.batchsize + try: + config_path = args.conf + conf = yaml.safe_load(open(config_path, 'r')) + except: + print("No input config or config file missing, please check.") + sys.exit(1) + main(conf, batchsize) diff --git a/ACL_PyTorch/built-in/audio/LSTM/ReadMe.md b/ACL_PyTorch/built-in/audio/LSTM/ReadMe.md index 8eea54372f446a3eb0142e302a783f338781601f..4c9db9caaf36b9cbd44b63e7b6a2ecfb89046a00 100644 --- a/ACL_PyTorch/built-in/audio/LSTM/ReadMe.md +++ b/ACL_PyTorch/built-in/audio/LSTM/ReadMe.md @@ -1,341 +1,341 @@ -# LSTM Onnx模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理精度统计](#61-离线推理精度统计) - - [6.2 精度对比](#62-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - [7.2 T4性能数据](#72-T4性能数据) - - [7.3 性能对比](#73-性能对比) - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -npu训练组依据客户给的模型进行训练所得,无参考论文 - -### 1.2 代码地址 -[LSTM代码]https://gitee.com/ascend/modelzoo.git) -branch:master -commit_id=8ed54e7d0fc9b632e1e3b9420bed96ee2c7fa1e3 -code_path=modelzoo/tree/master/built-in/PyTorch/Official/nlp/LSTM_for_PyTorch - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 -``` -pytorch = 1.8.0 -torchvision = 0.9.0 -``` -### 2.2 python第三方库 - -``` -ONNX == 1.7.0 -kaldi == https://github.com/kaldi-asr/kaldi -Pillow == 7.2.0 -onnxruntime-gpu == 1.7.0 -kaldiio == 2.17.2 -``` -kaldi需要安装在ModelZoo的LSTM源码仓中“modelzoo/built-in/PyTorch/Official/nlp/LSTM_for_PyTorch/NPU/1p/”目录下。ModelZoo的LSTM源码仓下载方法. -``` -git clone https://gitee.com/ascend/modelzoo.git -cd modelzoo -git reset --hard 8ed54e7d0fc9b632e1e3b9420bed96ee2c7fa1e3 -``` -1.下载ModelZoo的LSTM源码仓 -``` -git clone https://gitee.com/ascend/modelzoo.git -cd modelzoo -git reset --hard 8ed54e7d0fc9b632e1e3b9420bed96ee2c7fa1e3 -cd built-in/PyTorch/Official/nlp/LSTM_for_PyTorch/NPU/1p/ -``` -2.下载kaldi工具包 -源码搭建kaldi工具包环境。以arm 64位环境为例说明,推荐安装至conda环境: -``` -git clone https://github.com/kaldi-asr/kaldi -cd kaldi -``` -3.检查工具包所需依赖并安装缺少依赖 -``` -tools/extras/check_dependencies.sh -``` -根据检查结果和提示,安装缺少的依赖。安装完依赖再次检查工具包所需依赖是否都安装ok -4.编译 -``` -cd tools -make -j 64 -``` -5.安装依赖库成功之后安装第三方工具,Kaldi使用FST作为状态图的表现形式,安装方式如下: -``` -make openfst -extras/install_irstlm.sh -extras/install_openblas.sh -``` - -``` -输出:Installation of IRSTLM finished successfully -输出:OpenBLAS is installed successfully -``` -6.配置源码 -``` -cd ../src/ -./configure --shared -输出"Kaldi has been successfully configured." -``` -7.编译安装 -``` -make -j clean depend -make -j 64 - -输出:echo Done -Done -``` -源码中使用的python2.7版本,如果系统python版本与该版本不同,可使用系统默认python,在目录kaldi/python/下创建空文件.use_default_python。其他安装问题可参见kaldi官方安装教程. - -**说明:** -> 将源码包中的全部脚本移动到已安装kaldi工具的“modelzoo/built-in/PyTorch/Official/nlp/LSTM_for_PyTorch/NPU/1p/”目录下。 -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 -1.下载pth权重文件 -权重文件由华为npu模型训练组提供。 -2.lstm模型代码在代码仓中 -``` -git clone https://gitee.com/ascend/modelzoo.git -``` - 3.编写pth2onnx脚本LSTM_pth2onnx.py -本模型基于开源框架PyTorch训练的lstm进行模型转换。使用PyTorch将模型权重文件.pth转换为.onnx文件,再使用ATC工具将.onnx文件转为离线推理模型文件.om文件。权重文件由npu模型训练组提供,gpu训练模型ctc_best_model.pth。源码包中已提供ctc_best_model.pth权重文件。在1p目录下创建checkpoint/ctc_fbank_cnn/目录并将权重文件移到到该目录下。 -``` -mkdir -p checkpoint/ctc_fbank_cnnmv ./ctc_best_model.pth ./checkpoint/ctc_fbank_cnn/ -``` - - **说明:** ->注意目前ATC支持的onnx算子版本为11 - -4.执行pth2onnx脚本,生成onnx模型文件 -``` -python3.7 ./steps/LSTM_pth2onnx.py --batchsize=16 -``` - -### 3.2 onnx转om模型 - -1.修改lstm_atc.sh脚本,通过ATC工具使用脚本完成转换,具体的脚本示例如下: -``` -# 配置环境变量 -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -``` -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 -``` -atc --input_format=ND --framework=5 --model=lstm_ctc_16batch.onnx --input_shape="actual_input_1:16,390,243" --output=lstm_ctc_16batch_auto --auto_tune_mode="RL,GA" --log=info --soc_version=Ascend310 -``` -参数说明: - --model:为ONNX模型文件。 - --framework:5代表ONNX模型。 - --output:输出的OM模型。 - --input_format:输入数据的格式。 - --input_shape:输入数据的shape。 - --log:日志级别。 - --soc_version:处理器型号。 - -执行lstm_atc.sh脚本,将.onnx文件转为离线推理模型文件.om文件。 -``` -bash lstm_atc.sh -``` -运行成功后生成lstm_ctc_npu_16batch.om用于二进制输入推理的模型文件。 - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -本模型支持timit语音包的验证集。timit数据集与训练对齐,使用训练提供的语音数据包。需用户自行获取数据集,并将数据集命名为data.zip,并上传数据集data.zip至服务器ModelZoo的LSTM源码仓下的built-in/PyTorch/Official/nlp/LSTM_for_PyTorch/NPU/目录中。数据集结构如下。 -``` -├── DOC -├── README.DOC -├── TEST -└── TRAIN -``` - -### 4.2 数据集预处理 -目的、处理过程及方法、处理后输出文件介绍及用途模型输入数据为二进制格式。将原始数据(audio数据)转化为二进制文件(.bin)。 -1.解压数据集 -``` -unzip data.zip -cd p1 -``` -2.修改1p目录下path.sh里第一行代码如下: -``` -KALDI_ROOT=./kaldi -``` -3.创建data文件夹 -``` -mkdir data -``` -4.执行prepare_data.sh脚本。 -``` -chmod +x local/timit_data_prep.sh -chmod +x steps/make_feat.sh -bash prepare_data.sh -``` -执行prepare_data.sh脚本之后,在当前目录下会生成tmp文件夹和在data文件夹下生成dev,test,train三个数据集文件夹。 -5.移动LSTM_preprocess_data.py至1p/steps目录下, -6.修改./conf/ctc_config.yaml文件内容 -``` -#[test] -test_scp_path: 'data/dev/fbank.scp' -test_lab_path: 'data/dev/phn_text' -decode_type: "Greedy" -beam_width: 10 -lm_alpha: 0.1 -lm_path: 'data/lm_phone_bg.arpa' -``` -data文件夹即为执行prepare_data.sh之后所生成,使用此目录下的dev数据集进行验证。 -7.执行LSTM_preprocess_data.py脚本 -``` -python3.7 ./steps/LSTM_preprocess_data.py --conf=./conf/ctc_config.yaml --batchsize=16 -``` -参数为配置文件。 -### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本LSTM_get_info.py -使用pyacl推理需要输入二进制数据集的info文件,用于获取数据集。使用LSTM_get_info.py脚本,输入已经得到的二进制文件,输出生成二进制数据集的info文件。上传LSTM_get_info.py至1p文件夹下,运行LSTM_get_info.py脚本。 - -2.执行生成数据集信息脚本,生成数据集信息文件 -``` -python3.7 LSTM_get_info.py --batchsize=16 -``` -参数为om模型推理batchsize。运行成功后,在当前目录中生成lstm.info。 -## 5 离线推理 -1.配置pyacl推理环境变量 -``` -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -``` -2.执行pyacl离线推理 -``` -#pyacl推理命令 -python3.7 ./pyacl_infer.py --model_path=./lstm_ctc_16batch_auto.om --device_id=0 --cpu_run=True --sync_infer=True --workspace=10 --input_info_file_path=./lstm.info --input_dtypes=float32 --infer_res_save_path=./infer_res --res_save_type=npy -``` -参数说明: ---model_path:om模型文件 ---input_info_file_path:处理后的数据集信息info文件 ---infer_res_save_path:pyacl推理后结果保存路径 ---res_save_type:推理结果保存格式,npy格式为含有shape信息的数据,bin格式为不含shape-信息的二进制numpy数据 - - -## 6 精度对比 -- **[离线推理精度](#61-离线推理精度)** -- **[精度对比](#62-精度对比)** - -### 6.1 离线推理精度统计 - -1. 后处理统计精度 -上传LSTM_postprocess_data.py脚本至1p/steps目录下,执行LSTM_postprocess_data.py脚本进行数据后处理。 -``` -python3.7 ./steps/LSTM_postprocess_data.py --conf=./conf/ctc_config.yaml --npu_path=./infer_res/ --batchsize=16 -``` -conf参数为模型配置文件, npu_path参数为pyacl推理结果目录。执行后处理脚本之后,精度数据由WER 与CER给出,字母错误率与单词错误率。 -``` -Character error rate on test set: 13.5877 -Word error rate on test set: 18.9075 -``` -经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 - -### 6.2 精度对比 -推理模型om精度与onnx精度一致,且与训练测试pth模型精度一致。 - **精度调试:** - ->没有遇到精度不达标的问题,故不需要进行精度调试 - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** -- **[T4性能数据](#72-T4性能数据)** -- **[性能对比](#73-性能对比)** - -### 7.1 npu性能数据 -1.该模型不支持benchmark推理,使用pyacl推理获取npu性能数据。 -batch1的性能 -``` -Bs1: average pure infer time(ms):179.183 -``` -Interface throughputRate: 1000/179.183 = 5.58,5.58x4既是batch1 310单卡吞吐率 -batch4的性能 -``` -Bs4: average pure infer time(ms):187.361 -``` -Interface throughputRate: 1000/187.361* 4 = 21.35,21.35*4既是batch4 310单卡吞吐率 -batch8性能 -``` -Bs8: average pure infer time(ms):202.751 -``` -batch8 310单卡吞吐率:1000/202.751 * 8 = 157.83 fps -batch16性能: -``` -Bs16: average pure infer time(ms):195.763 -``` -batch16 310单卡吞吐率:1000/195.763 * 16 * 4 = 326.93fps -batch32性能: -``` -Bs32: average pure infer time(ms):260.119 -``` -batch32 310单卡吞吐率:1000/260.119 * 32 * 4 = 492.08fps - -### 7.2 T4性能数据 -gpu下onnx在线推理获取T4性能基线 -在T4环境下搭建环境,将预处理好的bin文件数据打包和lstm_infer_onnx.py脚本上传至服务器上1p目录下,进行onnx在线推理,执行lstm_onnx_infer.py脚本. -``` -python3.7 lstm_onnx_infer.py --conf=./conf/ctc_config.yaml --model_path=./lstm_ctc_16batch.onnx --bin_file_path=./lstm_bin/ --pred_res_save_path=./lstm_onnx_infer --batchsize=16 -``` -性能基线数据为: -``` -total infer time(ms): 2308.3143849999997 -average infer time(ms): 92.3325754 -``` -batch16 t4吞吐率:1000/92.33 * 16 = 173.29fps - -### 7.3 性能对比 -batch16: 326.93 >1000/(92.33/16) - -310单个device的吞吐率乘4即单卡吞吐率比T4单卡的吞吐率大,故310性能高于T4性能,性能达标。 - - **性能优化:** ->该模型性能优于T4,不用进行优化 +# LSTM Onnx模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理精度统计](#61-离线推理精度统计) + - [6.2 精度对比](#62-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + - [7.2 T4性能数据](#72-T4性能数据) + - [7.3 性能对比](#73-性能对比) + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +npu训练组依据客户给的模型进行训练所得,无参考论文 + +### 1.2 代码地址 +[LSTM代码]https://gitee.com/ascend/modelzoo.git) +branch:master +commit_id=8ed54e7d0fc9b632e1e3b9420bed96ee2c7fa1e3 +code_path=modelzoo/tree/master/built-in/PyTorch/Official/nlp/LSTM_for_PyTorch + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +pytorch = 1.8.0 +torchvision = 0.9.0 +``` +### 2.2 python第三方库 + +``` +ONNX == 1.7.0 +kaldi == https://github.com/kaldi-asr/kaldi +Pillow == 7.2.0 +onnxruntime-gpu == 1.7.0 +kaldiio == 2.17.2 +``` +kaldi需要安装在ModelZoo的LSTM源码仓中“modelzoo/built-in/PyTorch/Official/nlp/LSTM_for_PyTorch/NPU/1p/”目录下。ModelZoo的LSTM源码仓下载方法. +``` +git clone https://gitee.com/ascend/modelzoo.git +cd modelzoo +git reset --hard 8ed54e7d0fc9b632e1e3b9420bed96ee2c7fa1e3 +``` +1.下载ModelZoo的LSTM源码仓 +``` +git clone https://gitee.com/ascend/modelzoo.git +cd modelzoo +git reset --hard 8ed54e7d0fc9b632e1e3b9420bed96ee2c7fa1e3 +cd built-in/PyTorch/Official/nlp/LSTM_for_PyTorch/NPU/1p/ +``` +2.下载kaldi工具包 +源码搭建kaldi工具包环境。以arm 64位环境为例说明,推荐安装至conda环境: +``` +git clone https://github.com/kaldi-asr/kaldi +cd kaldi +``` +3.检查工具包所需依赖并安装缺少依赖 +``` +tools/extras/check_dependencies.sh +``` +根据检查结果和提示,安装缺少的依赖。安装完依赖再次检查工具包所需依赖是否都安装ok +4.编译 +``` +cd tools +make -j 64 +``` +5.安装依赖库成功之后安装第三方工具,Kaldi使用FST作为状态图的表现形式,安装方式如下: +``` +make openfst +extras/install_irstlm.sh +extras/install_openblas.sh +``` + +``` +输出:Installation of IRSTLM finished successfully +输出:OpenBLAS is installed successfully +``` +6.配置源码 +``` +cd ../src/ +./configure --shared +输出"Kaldi has been successfully configured." +``` +7.编译安装 +``` +make -j clean depend +make -j 64 + +输出:echo Done +Done +``` +源码中使用的python2.7版本,如果系统python版本与该版本不同,可使用系统默认python,在目录kaldi/python/下创建空文件.use_default_python。其他安装问题可参见kaldi官方安装教程. + +**说明:** +> 将源码包中的全部脚本移动到已安装kaldi工具的“modelzoo/built-in/PyTorch/Official/nlp/LSTM_for_PyTorch/NPU/1p/”目录下。 +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 +1.下载pth权重文件 +权重文件由华为npu模型训练组提供。 +2.lstm模型代码在代码仓中 +``` +git clone https://gitee.com/ascend/modelzoo.git +``` + 3.编写pth2onnx脚本LSTM_pth2onnx.py +本模型基于开源框架PyTorch训练的lstm进行模型转换。使用PyTorch将模型权重文件.pth转换为.onnx文件,再使用ATC工具将.onnx文件转为离线推理模型文件.om文件。权重文件由npu模型训练组提供,gpu训练模型ctc_best_model.pth。源码包中已提供ctc_best_model.pth权重文件。在1p目录下创建checkpoint/ctc_fbank_cnn/目录并将权重文件移到到该目录下。 +``` +mkdir -p checkpoint/ctc_fbank_cnnmv ./ctc_best_model.pth ./checkpoint/ctc_fbank_cnn/ +``` + + **说明:** +>注意目前ATC支持的onnx算子版本为11 + +4.执行pth2onnx脚本,生成onnx模型文件 +``` +python3.7 ./steps/LSTM_pth2onnx.py --batchsize=16 +``` + +### 3.2 onnx转om模型 + +1.修改lstm_atc.sh脚本,通过ATC工具使用脚本完成转换,具体的脚本示例如下: +``` +# 配置环境变量 +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 +``` +atc --input_format=ND --framework=5 --model=lstm_ctc_16batch.onnx --input_shape="actual_input_1:16,390,243" --output=lstm_ctc_16batch_auto --auto_tune_mode="RL,GA" --log=info --soc_version=Ascend310 +``` +参数说明: + --model:为ONNX模型文件。 + --framework:5代表ONNX模型。 + --output:输出的OM模型。 + --input_format:输入数据的格式。 + --input_shape:输入数据的shape。 + --log:日志级别。 + --soc_version:处理器型号。 + +执行lstm_atc.sh脚本,将.onnx文件转为离线推理模型文件.om文件。 +``` +bash lstm_atc.sh +``` +运行成功后生成lstm_ctc_npu_16batch.om用于二进制输入推理的模型文件。 + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +本模型支持timit语音包的验证集。timit数据集与训练对齐,使用训练提供的语音数据包。需用户自行获取数据集,并将数据集命名为data.zip,并上传数据集data.zip至服务器ModelZoo的LSTM源码仓下的built-in/PyTorch/Official/nlp/LSTM_for_PyTorch/NPU/目录中。数据集结构如下。 +``` +├── DOC +├── README.DOC +├── TEST +└── TRAIN +``` + +### 4.2 数据集预处理 +目的、处理过程及方法、处理后输出文件介绍及用途模型输入数据为二进制格式。将原始数据(audio数据)转化为二进制文件(.bin)。 +1.解压数据集 +``` +unzip data.zip +cd p1 +``` +2.修改1p目录下path.sh里第一行代码如下: +``` +KALDI_ROOT=./kaldi +``` +3.创建data文件夹 +``` +mkdir data +``` +4.执行prepare_data.sh脚本。 +``` +chmod +x local/timit_data_prep.sh +chmod +x steps/make_feat.sh +bash prepare_data.sh +``` +执行prepare_data.sh脚本之后,在当前目录下会生成tmp文件夹和在data文件夹下生成dev,test,train三个数据集文件夹。 +5.移动LSTM_preprocess_data.py至1p/steps目录下, +6.修改./conf/ctc_config.yaml文件内容 +``` +#[test] +test_scp_path: 'data/dev/fbank.scp' +test_lab_path: 'data/dev/phn_text' +decode_type: "Greedy" +beam_width: 10 +lm_alpha: 0.1 +lm_path: 'data/lm_phone_bg.arpa' +``` +data文件夹即为执行prepare_data.sh之后所生成,使用此目录下的dev数据集进行验证。 +7.执行LSTM_preprocess_data.py脚本 +``` +python3.7 ./steps/LSTM_preprocess_data.py --conf=./conf/ctc_config.yaml --batchsize=16 +``` +参数为配置文件。 +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本LSTM_get_info.py +使用pyacl推理需要输入二进制数据集的info文件,用于获取数据集。使用LSTM_get_info.py脚本,输入已经得到的二进制文件,输出生成二进制数据集的info文件。上传LSTM_get_info.py至1p文件夹下,运行LSTM_get_info.py脚本。 + +2.执行生成数据集信息脚本,生成数据集信息文件 +``` +python3.7 LSTM_get_info.py --batchsize=16 +``` +参数为om模型推理batchsize。运行成功后,在当前目录中生成lstm.info。 +## 5 离线推理 +1.配置pyacl推理环境变量 +``` +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +``` +2.执行pyacl离线推理 +``` +#pyacl推理命令 +python3.7 ./pyacl_infer.py --model_path=./lstm_ctc_16batch_auto.om --device_id=0 --cpu_run=True --sync_infer=True --workspace=10 --input_info_file_path=./lstm.info --input_dtypes=float32 --infer_res_save_path=./infer_res --res_save_type=npy +``` +参数说明: +--model_path:om模型文件 +--input_info_file_path:处理后的数据集信息info文件 +--infer_res_save_path:pyacl推理后结果保存路径 +--res_save_type:推理结果保存格式,npy格式为含有shape信息的数据,bin格式为不含shape-信息的二进制numpy数据 + + +## 6 精度对比 +- **[离线推理精度](#61-离线推理精度)** +- **[精度对比](#62-精度对比)** + +### 6.1 离线推理精度统计 + +1. 后处理统计精度 +上传LSTM_postprocess_data.py脚本至1p/steps目录下,执行LSTM_postprocess_data.py脚本进行数据后处理。 +``` +python3.7 ./steps/LSTM_postprocess_data.py --conf=./conf/ctc_config.yaml --npu_path=./infer_res/ --batchsize=16 +``` +conf参数为模型配置文件, npu_path参数为pyacl推理结果目录。执行后处理脚本之后,精度数据由WER 与CER给出,字母错误率与单词错误率。 +``` +Character error rate on test set: 13.5877 +Word error rate on test set: 18.9075 +``` +经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 + +### 6.2 精度对比 +推理模型om精度与onnx精度一致,且与训练测试pth模型精度一致。 + **精度调试:** + +>没有遇到精度不达标的问题,故不需要进行精度调试 + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** +- **[T4性能数据](#72-T4性能数据)** +- **[性能对比](#73-性能对比)** + +### 7.1 npu性能数据 +1.该模型不支持benchmark推理,使用pyacl推理获取npu性能数据。 +batch1的性能 +``` +Bs1: average pure infer time(ms):179.183 +``` +Interface throughputRate: 1000/179.183 = 5.58,5.58x4既是batch1 310单卡吞吐率 +batch4的性能 +``` +Bs4: average pure infer time(ms):187.361 +``` +Interface throughputRate: 1000/187.361* 4 = 21.35,21.35*4既是batch4 310单卡吞吐率 +batch8性能 +``` +Bs8: average pure infer time(ms):202.751 +``` +batch8 310单卡吞吐率:1000/202.751 * 8 = 157.83 fps +batch16性能: +``` +Bs16: average pure infer time(ms):195.763 +``` +batch16 310单卡吞吐率:1000/195.763 * 16 * 4 = 326.93fps +batch32性能: +``` +Bs32: average pure infer time(ms):260.119 +``` +batch32 310单卡吞吐率:1000/260.119 * 32 * 4 = 492.08fps + +### 7.2 T4性能数据 +gpu下onnx在线推理获取T4性能基线 +在T4环境下搭建环境,将预处理好的bin文件数据打包和lstm_infer_onnx.py脚本上传至服务器上1p目录下,进行onnx在线推理,执行lstm_onnx_infer.py脚本. +``` +python3.7 lstm_onnx_infer.py --conf=./conf/ctc_config.yaml --model_path=./lstm_ctc_16batch.onnx --bin_file_path=./lstm_bin/ --pred_res_save_path=./lstm_onnx_infer --batchsize=16 +``` +性能基线数据为: +``` +total infer time(ms): 2308.3143849999997 +average infer time(ms): 92.3325754 +``` +batch16 t4吞吐率:1000/92.33 * 16 = 173.29fps + +### 7.3 性能对比 +batch16: 326.93 >1000/(92.33/16) + +310单个device的吞吐率乘4即单卡吞吐率比T4单卡的吞吐率大,故310性能高于T4性能,性能达标。 + + **性能优化:** +>该模型性能优于T4,不用进行优化 diff --git a/ACL_PyTorch/built-in/audio/LSTM/acl_net.py b/ACL_PyTorch/built-in/audio/LSTM/acl_net.py index b7bd73a27ec670854d0265862867026e33d6c8a2..0b5c208db5a296746e4b11eb65b55660298ade98 100644 --- a/ACL_PyTorch/built-in/audio/LSTM/acl_net.py +++ b/ACL_PyTorch/built-in/audio/LSTM/acl_net.py @@ -1,289 +1,289 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import acl -import functools -import numpy as np -import torch -import time - -# error code -ACL_ERROR_NONE = 0 - -# rule for memory copy -ACL_MEMCPY_HOST_TO_HOST = 0 -ACL_MEMCPY_HOST_TO_DEVICE = 1 -ACL_MEMCPY_DEVICE_TO_HOST = 2 -ACL_MEMCPY_DEVICE_TO_DEVICE = 3 - -# dtype -ACL_DTYPE = { - 0: 'float32', - 1: 'float16', - 2: 'int8', - 3: 'int32', - 4: 'uint8', - 6: 'int16', - 7: 'uint16', - 8: 'uint32', - 9: 'int64', - 10: 'uint64', - 11: 'float64', - 12: 'bool', -} - - -def check_ret(message, ret): - if ret != ACL_ERROR_NONE: - raise Exception(f"{message} failed ret = {ret}") - - -class MeasureTime(): - def __init__(self, measurements, key, cpu_run=True): - self.measurements = measurements - self.key = key - self.cpu_run = cpu_run - - def __enter__(self): - if not self.cpu_run: - torch.cuda.synchronize() - self.t0 = time.perf_counter_ns() - - def __exit__(self, exc_type, exc_value, exc_traceback): - if not self.cpu_run: - torch.cuda.synchronize() - self.measurements[self.key] = time.perf_counter_ns() - self.t0 - - -class AclModel(object): - def __init__(self, device_id, model_path, sync_infer, measurements, key, cpu_run): - self.device_id = device_id - self.sync_infer = sync_infer - self.out_bufs_ptr = [] - self.output_sizes = [] - self.input_sizes = [] - self.input_bufs_ptr = [] - - self.measurements = measurements - self.key = key - self.cpu_run = cpu_run - - ret = acl.init() - check_ret("acl.init", ret) - ret = acl.rt.set_device(self.device_id) - check_ret("acl.rt.set_device", ret) - self.context, ret = acl.rt.create_context(self.device_id) - check_ret("acl.rt.create_context", ret) - self.model_id, ret = acl.mdl.load_from_file(model_path) - check_ret("acl.mdl.load_from_file", ret) - - self.model_desc = acl.mdl.create_desc() - assert self.model_desc is not None - acl.mdl.get_desc(self.model_desc, self.model_id) - self.dataset_in = acl.mdl.create_dataset() - assert self.dataset_in is not None - self.dataset_out = acl.mdl.create_dataset() - assert self.dataset_out is not None - self.in_size, self.out_size = 0, 0 - self.stm, ret = acl.rt.create_stream() - assert ret == 0 - - self.desc_init() - self.dataset_init() - - def __call__(self, ori_data, dim): - return self.forward(ori_data, dim) - - def __del__(self): - # unload model - if self.model_id: - ret = acl.mdl.unload(self.model_id) - assert ret == 0 - - # destroy model desc - ret = acl.mdl.destroy_desc(self.model_desc) - assert ret == 0 - - self.destroy_data_set(self.dataset_in) - self.destroy_data_set(self.dataset_out) - - # destroy input/output tensor - for i in range(len(self.input_bufs_ptr)): - acl.rt.free(self.input_bufs_ptr[i]["buffer"]) - self.input_bufs_ptr[i] = None - - for i in range(len(self.out_bufs_ptr)): - acl.rt.free(self.out_bufs_ptr[i]["buffer"]) - self.out_bufs_ptr[i] = None - - ret = acl.rt.destroy_stream(self.stm) - assert ret == 0 - - def desc_init(self): - tensor_size = acl.mdl.get_num_inputs(self.model_desc) - if not tensor_size: - raise Exception("get_num_inputs failed") - self.in_size = tensor_size - - for i in range(tensor_size): - size = acl.mdl.get_input_size_by_index(self.model_desc, i) - data, ret = acl.rt.malloc(size, 0) - assert ret == 0 - - self.input_bufs_ptr.append({'size': size, 'buffer': data}) - self.input_sizes.append(size) - - tensor_size = acl.mdl.get_num_outputs(self.model_desc) - self.out_size = tensor_size - for i in range(tensor_size): - dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) - assert ret == 0 - size = acl.mdl.get_output_size_by_index(self.model_desc, i) - - data, ret = acl.rt.malloc(size, 0) - assert ret == 0 - - self.output_sizes.append(size) - self.out_bufs_ptr.append({'size': size, 'buffer': data}) - - def dataset_init(self): - self.create_data_set(self.dataset_in, self.input_bufs_ptr, self.input_sizes) - self.create_data_set(self.dataset_out, self.out_bufs_ptr, self.output_sizes) - - def create_data_set(self, dataset, bufs_ptr_list, size_list): - # create dataset buffer then add to dataset - for i in range(len(size_list)): - buffer = acl.create_data_buffer(bufs_ptr_list[i]["buffer"], size_list[i]) - if not buffer: - self.destroy_data_set(dataset) - raise Exception("create_data_buffer failed") - - # add to dataset - _, ret = acl.mdl.add_dataset_buffer(dataset, buffer) - if ret != 0: - self.destroy_data_set(dataset) - raise Exception("add_dataset_buffer failed, ret = {}".format(ret)) - - return dataset - - def destroy_data_set(self, dataset): - data_buf_num = acl.mdl.get_dataset_num_buffers(dataset) - for i in range(data_buf_num): - # get data buffer by index - data_buf = acl.mdl.get_dataset_buffer(dataset, i) - if data_buf is not None: - acl.destroy_data_buffer(data_buf) - - acl.mdl.destroy_dataset(dataset) - - def copy_data_to_device(self, data): - for i in range(len(data)): - if 'bytes_to_ptr' in dir(acl.util): - ptr = acl.util.bytes_to_ptr(data[i]["buffer"].tobytes()) - else: - ptr, np = acl.util.numpy_contiguous_to_ptr(data[i]["buffer"]) - acl.rt.memcpy(self.input_bufs_ptr[i]["buffer"], data[i]["size"], ptr, - data[i]["size"], ACL_MEMCPY_HOST_TO_DEVICE) - - def copy_output_to_host(self): - output_data = [] - for i in range(len(self.out_bufs_ptr)): - temp = dict() - temp["size"] = self.out_bufs_ptr[i]["size"] - temp["buffer"], ret = acl.rt.malloc_host(temp["size"]) - output_data.append(temp) - acl.rt.memcpy(temp["buffer"], temp["size"], self.out_bufs_ptr[i]["buffer"], - temp["size"], ACL_MEMCPY_DEVICE_TO_HOST) - - return output_data - - def model_exe(self): - with MeasureTime(self.measurements, self.key, self.cpu_run): - ret = acl.mdl.execute(self.model_id, self.dataset_in, self.dataset_out) - assert ret == 0 - output_data = self.copy_output_to_host() - dataset = [] - for i in range(len(output_data)): - dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) - data_shape = dims.get("dims") - data_type = acl.mdl.get_output_data_type(self.model_desc, i) - data_len = functools.reduce(lambda x, y: x * y, data_shape) - ftype = np.dtype(ACL_DTYPE.get(data_type)) - - size = output_data[i]["size"] - ptr = output_data[i]["buffer"] - if 'ptr_to_bytes' in dir(acl.util): - data = acl.util.ptr_to_bytes(ptr, size) - np_arr = np.frombuffer(data, dtype=ftype, count=data_len) - else: - data = acl.util.ptr_to_numpy(ptr, (size,), 1) - np_arr = np.frombuffer( - bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) - np_arr = np_arr.reshape(data_shape) - dataset.append(np_arr) - return dataset - - def model_exe_async(self): - with MeasureTime(self.measurements, self.key, self.cpu_run): - ret = acl.mdl.execute_async(self.model_id, self.dataset_in, self.dataset_out, self.stm) - assert ret == 0 - ret = acl.rt.synchronize_stream(self.stm) - assert ret == 0 - output_data = self.copy_output_to_host() - - dataset = [] - for i in range(len(output_data)): - dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) - # check_ret("acl.mdl.get_cur_output_dims", ret) - data_shape = dims.get("dims") - - data_type = acl.mdl.get_output_data_type(self.model_desc, i) - data_len = functools.reduce(lambda x, y: x * y, data_shape) - ftype = np.dtype(ACL_DTYPE.get(data_type)) - - size = output_data[i]["size"] - ptr = output_data[i]["buffer"] - if 'ptr_to_bytes' in dir(acl.util): - data = acl.util.ptr_to_bytes(ptr, size) - np_arr = np.frombuffer(data, dtype=ftype, count=data_len) - else: - data = acl.util.ptr_to_numpy(ptr, (size,), 1) - np_arr = np.frombuffer( - bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) - np_arr = np_arr.reshape(data_shape) - dataset.append(np_arr) - return dataset - - def model_exe_with_dynamic_dims(self, input_data, dims): - index, ret = acl.mdl.get_input_index_by_name(self.model_desc, 'ascend_mbatch_shape_data') - ret = acl.mdl.set_input_dynamic_dims(self.model_id, self.dataset_in, index, dims) - gear_count, ret = acl.mdl.get_input_dynamic_gear_count(self.model_desc, -1) - dims_out, ret = acl.mdl.get_input_dynamic_dims(self.model_desc, -1, gear_count) - self.copy_data_to_device(input_data) - if self.sync_infer is True: - res = self.model_exe() - else: - res = self.model_exe_async() - - return res - - def forward(self, input_data, dims): - input_data_dic = [] - for i in range(len(input_data)): - temp = {} - temp["size"] = input_data[i].size * input_data[i].itemsize - temp["buffer"] = input_data[i] - input_data_dic.append(temp) - result = self.model_exe_with_dynamic_dims(input_data_dic, dims) - return result +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import acl +import functools +import numpy as np +import torch +import time + +# error code +ACL_ERROR_NONE = 0 + +# rule for memory copy +ACL_MEMCPY_HOST_TO_HOST = 0 +ACL_MEMCPY_HOST_TO_DEVICE = 1 +ACL_MEMCPY_DEVICE_TO_HOST = 2 +ACL_MEMCPY_DEVICE_TO_DEVICE = 3 + +# dtype +ACL_DTYPE = { + 0: 'float32', + 1: 'float16', + 2: 'int8', + 3: 'int32', + 4: 'uint8', + 6: 'int16', + 7: 'uint16', + 8: 'uint32', + 9: 'int64', + 10: 'uint64', + 11: 'float64', + 12: 'bool', +} + + +def check_ret(message, ret): + if ret != ACL_ERROR_NONE: + raise Exception(f"{message} failed ret = {ret}") + + +class MeasureTime(): + def __init__(self, measurements, key, cpu_run=True): + self.measurements = measurements + self.key = key + self.cpu_run = cpu_run + + def __enter__(self): + if not self.cpu_run: + torch.cuda.synchronize() + self.t0 = time.perf_counter_ns() + + def __exit__(self, exc_type, exc_value, exc_traceback): + if not self.cpu_run: + torch.cuda.synchronize() + self.measurements[self.key] = time.perf_counter_ns() - self.t0 + + +class AclModel(object): + def __init__(self, device_id, model_path, sync_infer, measurements, key, cpu_run): + self.device_id = device_id + self.sync_infer = sync_infer + self.out_bufs_ptr = [] + self.output_sizes = [] + self.input_sizes = [] + self.input_bufs_ptr = [] + + self.measurements = measurements + self.key = key + self.cpu_run = cpu_run + + ret = acl.init() + check_ret("acl.init", ret) + ret = acl.rt.set_device(self.device_id) + check_ret("acl.rt.set_device", ret) + self.context, ret = acl.rt.create_context(self.device_id) + check_ret("acl.rt.create_context", ret) + self.model_id, ret = acl.mdl.load_from_file(model_path) + check_ret("acl.mdl.load_from_file", ret) + + self.model_desc = acl.mdl.create_desc() + assert self.model_desc is not None + acl.mdl.get_desc(self.model_desc, self.model_id) + self.dataset_in = acl.mdl.create_dataset() + assert self.dataset_in is not None + self.dataset_out = acl.mdl.create_dataset() + assert self.dataset_out is not None + self.in_size, self.out_size = 0, 0 + self.stm, ret = acl.rt.create_stream() + assert ret == 0 + + self.desc_init() + self.dataset_init() + + def __call__(self, ori_data, dim): + return self.forward(ori_data, dim) + + def __del__(self): + # unload model + if self.model_id: + ret = acl.mdl.unload(self.model_id) + assert ret == 0 + + # destroy model desc + ret = acl.mdl.destroy_desc(self.model_desc) + assert ret == 0 + + self.destroy_data_set(self.dataset_in) + self.destroy_data_set(self.dataset_out) + + # destroy input/output tensor + for i in range(len(self.input_bufs_ptr)): + acl.rt.free(self.input_bufs_ptr[i]["buffer"]) + self.input_bufs_ptr[i] = None + + for i in range(len(self.out_bufs_ptr)): + acl.rt.free(self.out_bufs_ptr[i]["buffer"]) + self.out_bufs_ptr[i] = None + + ret = acl.rt.destroy_stream(self.stm) + assert ret == 0 + + def desc_init(self): + tensor_size = acl.mdl.get_num_inputs(self.model_desc) + if not tensor_size: + raise Exception("get_num_inputs failed") + self.in_size = tensor_size + + for i in range(tensor_size): + size = acl.mdl.get_input_size_by_index(self.model_desc, i) + data, ret = acl.rt.malloc(size, 0) + assert ret == 0 + + self.input_bufs_ptr.append({'size': size, 'buffer': data}) + self.input_sizes.append(size) + + tensor_size = acl.mdl.get_num_outputs(self.model_desc) + self.out_size = tensor_size + for i in range(tensor_size): + dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) + assert ret == 0 + size = acl.mdl.get_output_size_by_index(self.model_desc, i) + + data, ret = acl.rt.malloc(size, 0) + assert ret == 0 + + self.output_sizes.append(size) + self.out_bufs_ptr.append({'size': size, 'buffer': data}) + + def dataset_init(self): + self.create_data_set(self.dataset_in, self.input_bufs_ptr, self.input_sizes) + self.create_data_set(self.dataset_out, self.out_bufs_ptr, self.output_sizes) + + def create_data_set(self, dataset, bufs_ptr_list, size_list): + # create dataset buffer then add to dataset + for i in range(len(size_list)): + buffer = acl.create_data_buffer(bufs_ptr_list[i]["buffer"], size_list[i]) + if not buffer: + self.destroy_data_set(dataset) + raise Exception("create_data_buffer failed") + + # add to dataset + _, ret = acl.mdl.add_dataset_buffer(dataset, buffer) + if ret != 0: + self.destroy_data_set(dataset) + raise Exception("add_dataset_buffer failed, ret = {}".format(ret)) + + return dataset + + def destroy_data_set(self, dataset): + data_buf_num = acl.mdl.get_dataset_num_buffers(dataset) + for i in range(data_buf_num): + # get data buffer by index + data_buf = acl.mdl.get_dataset_buffer(dataset, i) + if data_buf is not None: + acl.destroy_data_buffer(data_buf) + + acl.mdl.destroy_dataset(dataset) + + def copy_data_to_device(self, data): + for i in range(len(data)): + if 'bytes_to_ptr' in dir(acl.util): + ptr = acl.util.bytes_to_ptr(data[i]["buffer"].tobytes()) + else: + ptr, np = acl.util.numpy_contiguous_to_ptr(data[i]["buffer"]) + acl.rt.memcpy(self.input_bufs_ptr[i]["buffer"], data[i]["size"], ptr, + data[i]["size"], ACL_MEMCPY_HOST_TO_DEVICE) + + def copy_output_to_host(self): + output_data = [] + for i in range(len(self.out_bufs_ptr)): + temp = dict() + temp["size"] = self.out_bufs_ptr[i]["size"] + temp["buffer"], ret = acl.rt.malloc_host(temp["size"]) + output_data.append(temp) + acl.rt.memcpy(temp["buffer"], temp["size"], self.out_bufs_ptr[i]["buffer"], + temp["size"], ACL_MEMCPY_DEVICE_TO_HOST) + + return output_data + + def model_exe(self): + with MeasureTime(self.measurements, self.key, self.cpu_run): + ret = acl.mdl.execute(self.model_id, self.dataset_in, self.dataset_out) + assert ret == 0 + output_data = self.copy_output_to_host() + dataset = [] + for i in range(len(output_data)): + dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) + data_shape = dims.get("dims") + data_type = acl.mdl.get_output_data_type(self.model_desc, i) + data_len = functools.reduce(lambda x, y: x * y, data_shape) + ftype = np.dtype(ACL_DTYPE.get(data_type)) + + size = output_data[i]["size"] + ptr = output_data[i]["buffer"] + if 'ptr_to_bytes' in dir(acl.util): + data = acl.util.ptr_to_bytes(ptr, size) + np_arr = np.frombuffer(data, dtype=ftype, count=data_len) + else: + data = acl.util.ptr_to_numpy(ptr, (size,), 1) + np_arr = np.frombuffer( + bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) + np_arr = np_arr.reshape(data_shape) + dataset.append(np_arr) + return dataset + + def model_exe_async(self): + with MeasureTime(self.measurements, self.key, self.cpu_run): + ret = acl.mdl.execute_async(self.model_id, self.dataset_in, self.dataset_out, self.stm) + assert ret == 0 + ret = acl.rt.synchronize_stream(self.stm) + assert ret == 0 + output_data = self.copy_output_to_host() + + dataset = [] + for i in range(len(output_data)): + dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) + # check_ret("acl.mdl.get_cur_output_dims", ret) + data_shape = dims.get("dims") + + data_type = acl.mdl.get_output_data_type(self.model_desc, i) + data_len = functools.reduce(lambda x, y: x * y, data_shape) + ftype = np.dtype(ACL_DTYPE.get(data_type)) + + size = output_data[i]["size"] + ptr = output_data[i]["buffer"] + if 'ptr_to_bytes' in dir(acl.util): + data = acl.util.ptr_to_bytes(ptr, size) + np_arr = np.frombuffer(data, dtype=ftype, count=data_len) + else: + data = acl.util.ptr_to_numpy(ptr, (size,), 1) + np_arr = np.frombuffer( + bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) + np_arr = np_arr.reshape(data_shape) + dataset.append(np_arr) + return dataset + + def model_exe_with_dynamic_dims(self, input_data, dims): + index, ret = acl.mdl.get_input_index_by_name(self.model_desc, 'ascend_mbatch_shape_data') + ret = acl.mdl.set_input_dynamic_dims(self.model_id, self.dataset_in, index, dims) + gear_count, ret = acl.mdl.get_input_dynamic_gear_count(self.model_desc, -1) + dims_out, ret = acl.mdl.get_input_dynamic_dims(self.model_desc, -1, gear_count) + self.copy_data_to_device(input_data) + if self.sync_infer is True: + res = self.model_exe() + else: + res = self.model_exe_async() + + return res + + def forward(self, input_data, dims): + input_data_dic = [] + for i in range(len(input_data)): + temp = {} + temp["size"] = input_data[i].size * input_data[i].itemsize + temp["buffer"] = input_data[i] + input_data_dic.append(temp) + result = self.model_exe_with_dynamic_dims(input_data_dic, dims) + return result diff --git a/ACL_PyTorch/built-in/audio/LSTM/lstm_atc.sh b/ACL_PyTorch/built-in/audio/LSTM/lstm_atc.sh index 738f842581831a9bb68775ccba85f8233d7be167..42ed54470d55466987c00fdaec89a81ff5b5e2c5 100644 --- a/ACL_PyTorch/built-in/audio/LSTM/lstm_atc.sh +++ b/ACL_PyTorch/built-in/audio/LSTM/lstm_atc.sh @@ -1,6 +1,6 @@ -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATHexport ASCEND_OPP_PATH=${install_path}/opp - +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATHexport ASCEND_OPP_PATH=${install_path}/opp + /usr/local/Ascend/ascend-toolkit/latest/atc/bin/atc --input_format=ND --framework=5 --model=lstm_ctc_16batch.onnx --input_shape="actual_input_1:16,390,243" --output=lstm_ctc_16batch_auto --auto_tune_mode="RL,GA" --log=info --soc_version=Ascend310 \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/LSTM/lstm_onnx_infer.py b/ACL_PyTorch/built-in/audio/LSTM/lstm_onnx_infer.py index b62b2e882cb40856c1f577bcbea1d2b60d20ed84..6e94edaf2027af5532026dfb6b225622bac88146 100644 --- a/ACL_PyTorch/built-in/audio/LSTM/lstm_onnx_infer.py +++ b/ACL_PyTorch/built-in/audio/LSTM/lstm_onnx_infer.py @@ -1,155 +1,155 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import time -import sys -import torch -import yaml -import argparse -import onnxruntime -import torch.nn as nn -import numpy as np -from glob import glob -from tqdm import tqdm - -sys.path.append('./') -from models.model_ctc import * -from utils.ctcDecoder import GreedyDecoder, BeamDecoder - -parser = argparse.ArgumentParser() -parser.add_argument('--conf', help='conf file for training') - -parser.add_argument('--model_path', required=True) -parser.add_argument('--bin_file_path', required=True) -parser.add_argument('--pred_res_save_path', required=True) -parser.add_argument('--batchsize', required=True, help='batchsize for onnx infering') - -class Config(object): - batch_size = 4 - dropout = 0.1 - -class Vocab(object): - def __init__(self, vocab_file): - self.vocab_file = vocab_file - self.word2index = {"blank": 0, "UNK": 1} - self.index2word = {0: "blank", 1: "UNK"} - self.word2count = {} - self.n_words = 2 - self.read_lang() - - def add_sentence(self, sentence): - for word in sentence.split(' '): - self.add_word(word) - - def add_word(self, word): - if word not in self.word2index: - self.word2index[word] = self.n_words - self.word2count[word] = 1 - self.index2word[self.n_words] = word - self.n_words += 1 - else: - self.word2count[word] += 1 - - def read_lang(self): - print("Reading vocabulary from {}".format(self.vocab_file)) - with open(self.vocab_file, 'r') as rf: - line = rf.readline() - while line: - line = line.strip().split(' ') - if len(line) > 1: - sen = ' '.join(line[1:]) - else: - sen = line[0] - self.add_sentence(sen) - line = rf.readline() - print("Vocabulary size is {}".format(self.n_words)) - -def lstm_onnx_infer(): - args = parser.parse_args() - - model_path = args.model_path - bin_file_path = args.bin_file_path - pred_res_save_path = args.pred_res_save_path - - try: - conf = yaml.safe_load(open(args.conf,'r')) - except: - print("Config file not exist!") - sys.exit(1) - - opts = Config() - for k,v in conf.items(): - setattr(opts, k, v) - print('{:50}:{}'.format(k, v)) - - beam_width = opts.beam_width - lm_alpha = opts.lm_alpha - decoder_type = opts.decode_type - vocab_file = opts.vocab_file - batchsize = int(args.batchsize) - - vocab = Vocab(vocab_file) - - # 读取数据目录 - bin_file_list = glob(os.path.join(bin_file_path, '*.bin')) - bin_file_num = len(bin_file_list) - - # 创建目录 - pardir = os.path.dirname(pred_res_save_path) - if not os.path.exists(pardir): - os.makedirs(pardir) - - # 推理 - print('[INFO] Infer on dataset ...') - transcription_list = [] - total_infer_time = 0 - total_infer_num = 0 - - with open(pred_res_save_path, 'wt', encoding='utf-8') as f_pred: - onnx_run_sess = onnxruntime.InferenceSession(model_path) - for i in tqdm(range(bin_file_num)): - # 数据预处理 - input = np.fromfile(os.path.join(bin_file_path, 'inputs_' + str(i) + '.bin'), dtype=np.float32) - input = input.reshape(batchsize, 390, 243) - - # 推理 - start_time = time.perf_counter_ns() - output = onnx_run_sess.run(None, {"actual_input_1":input}) - end_time = time.perf_counter_ns() - total_infer_time += end_time - start_time - total_infer_num += 1 - - #推理时间 - print('[INFO] Time:') - msg = 'total infer num: ' + str(total_infer_num) + '\n' + \ - 'total infer time(ms): ' + str(total_infer_time / 1000 / 1000) + '\n' + \ - 'average infer time(ms): ' + str(total_infer_time / total_infer_num / 1000 / 1000) + '\n' - print(msg) - with open(os.path.join(pardir, 'infer_time.txt'), 'wt', encoding='utf-8') as f_infer_time: - f_infer_time.write(msg) - - -if __name__ == '__main__': - ''' - Using Example: - - python onnx_local_infer.py \ - --conf=./conf/ctc_config.yaml \ - --model_path=./lstm_onnx/lstm_ctc_npu_16batch1_67.onnx \ - --bin_file_path=--bin_file_path=./lstm_bin/ \ - --pred_res_save_path=./lstm_onnx_infer \ - --batchsize=16 - ''' - lstm_onnx_infer() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import time +import sys +import torch +import yaml +import argparse +import onnxruntime +import torch.nn as nn +import numpy as np +from glob import glob +from tqdm import tqdm + +sys.path.append('./') +from models.model_ctc import * +from utils.ctcDecoder import GreedyDecoder, BeamDecoder + +parser = argparse.ArgumentParser() +parser.add_argument('--conf', help='conf file for training') + +parser.add_argument('--model_path', required=True) +parser.add_argument('--bin_file_path', required=True) +parser.add_argument('--pred_res_save_path', required=True) +parser.add_argument('--batchsize', required=True, help='batchsize for onnx infering') + +class Config(object): + batch_size = 4 + dropout = 0.1 + +class Vocab(object): + def __init__(self, vocab_file): + self.vocab_file = vocab_file + self.word2index = {"blank": 0, "UNK": 1} + self.index2word = {0: "blank", 1: "UNK"} + self.word2count = {} + self.n_words = 2 + self.read_lang() + + def add_sentence(self, sentence): + for word in sentence.split(' '): + self.add_word(word) + + def add_word(self, word): + if word not in self.word2index: + self.word2index[word] = self.n_words + self.word2count[word] = 1 + self.index2word[self.n_words] = word + self.n_words += 1 + else: + self.word2count[word] += 1 + + def read_lang(self): + print("Reading vocabulary from {}".format(self.vocab_file)) + with open(self.vocab_file, 'r') as rf: + line = rf.readline() + while line: + line = line.strip().split(' ') + if len(line) > 1: + sen = ' '.join(line[1:]) + else: + sen = line[0] + self.add_sentence(sen) + line = rf.readline() + print("Vocabulary size is {}".format(self.n_words)) + +def lstm_onnx_infer(): + args = parser.parse_args() + + model_path = args.model_path + bin_file_path = args.bin_file_path + pred_res_save_path = args.pred_res_save_path + + try: + conf = yaml.safe_load(open(args.conf,'r')) + except: + print("Config file not exist!") + sys.exit(1) + + opts = Config() + for k,v in conf.items(): + setattr(opts, k, v) + print('{:50}:{}'.format(k, v)) + + beam_width = opts.beam_width + lm_alpha = opts.lm_alpha + decoder_type = opts.decode_type + vocab_file = opts.vocab_file + batchsize = int(args.batchsize) + + vocab = Vocab(vocab_file) + + # 读取数据目录 + bin_file_list = glob(os.path.join(bin_file_path, '*.bin')) + bin_file_num = len(bin_file_list) + + # 创建目录 + pardir = os.path.dirname(pred_res_save_path) + if not os.path.exists(pardir): + os.makedirs(pardir) + + # 推理 + print('[INFO] Infer on dataset ...') + transcription_list = [] + total_infer_time = 0 + total_infer_num = 0 + + with open(pred_res_save_path, 'wt', encoding='utf-8') as f_pred: + onnx_run_sess = onnxruntime.InferenceSession(model_path) + for i in tqdm(range(bin_file_num)): + # 数据预处理 + input = np.fromfile(os.path.join(bin_file_path, 'inputs_' + str(i) + '.bin'), dtype=np.float32) + input = input.reshape(batchsize, 390, 243) + + # 推理 + start_time = time.perf_counter_ns() + output = onnx_run_sess.run(None, {"actual_input_1":input}) + end_time = time.perf_counter_ns() + total_infer_time += end_time - start_time + total_infer_num += 1 + + #推理时间 + print('[INFO] Time:') + msg = 'total infer num: ' + str(total_infer_num) + '\n' + \ + 'total infer time(ms): ' + str(total_infer_time / 1000 / 1000) + '\n' + \ + 'average infer time(ms): ' + str(total_infer_time / total_infer_num / 1000 / 1000) + '\n' + print(msg) + with open(os.path.join(pardir, 'infer_time.txt'), 'wt', encoding='utf-8') as f_infer_time: + f_infer_time.write(msg) + + +if __name__ == '__main__': + ''' + Using Example: + + python onnx_local_infer.py \ + --conf=./conf/ctc_config.yaml \ + --model_path=./lstm_onnx/lstm_ctc_npu_16batch1_67.onnx \ + --bin_file_path=--bin_file_path=./lstm_bin/ \ + --pred_res_save_path=./lstm_onnx_infer \ + --batchsize=16 + ''' + lstm_onnx_infer() diff --git a/ACL_PyTorch/built-in/audio/LSTM/prepare_data.sh b/ACL_PyTorch/built-in/audio/LSTM/prepare_data.sh index 29bd7427efb2bda0c6a280281cced0644552a77a..0010bac6161e92c0fc05ec55471034391326d8e4 100644 --- a/ACL_PyTorch/built-in/audio/LSTM/prepare_data.sh +++ b/ACL_PyTorch/built-in/audio/LSTM/prepare_data.sh @@ -1,31 +1,31 @@ -#!/bin/bash - -#Author: Ruchao Fan -#2017.11.1 Training acoustic model and decode with phoneme-level bigram -#2018.4.30 Replace the h5py with ark and simplify the data_loader.py -#2019.12.20 Update to pytorch1.2 and python3.7 - -. path.sh - -stage=0 - -timit_dir='../data' -phoneme_map='60-39' -feat_dir='data' #dir to save feature -feat_type='fbank' #fbank, mfcc, spectrogram -config_file='conf/ctc_config.yaml' - -if [ ! -z $1 ]; then - stage=$1 -fi - -if [ $stage -le 0 ]; then - echo "Step 0: Data Preparation ..." - local/timit_data_prep.sh $timit_dir $phoneme_map || exit 1; - python3 steps/get_model_units.py $feat_dir/train/phn_text -fi - -if [ $stage -le 1 ]; then - echo "Step 1: Feature Extraction..." - steps/make_feat.sh $feat_type $feat_dir || exit 1; -fi +#!/bin/bash + +#Author: Ruchao Fan +#2017.11.1 Training acoustic model and decode with phoneme-level bigram +#2018.4.30 Replace the h5py with ark and simplify the data_loader.py +#2019.12.20 Update to pytorch1.2 and python3.7 + +. path.sh + +stage=0 + +timit_dir='../data' +phoneme_map='60-39' +feat_dir='data' #dir to save feature +feat_type='fbank' #fbank, mfcc, spectrogram +config_file='conf/ctc_config.yaml' + +if [ ! -z $1 ]; then + stage=$1 +fi + +if [ $stage -le 0 ]; then + echo "Step 0: Data Preparation ..." + local/timit_data_prep.sh $timit_dir $phoneme_map || exit 1; + python3 steps/get_model_units.py $feat_dir/train/phn_text +fi + +if [ $stage -le 1 ]; then + echo "Step 1: Feature Extraction..." + steps/make_feat.sh $feat_type $feat_dir || exit 1; +fi diff --git a/ACL_PyTorch/built-in/audio/LSTM/pyacl_infer.py b/ACL_PyTorch/built-in/audio/LSTM/pyacl_infer.py index de1af0191e7fe9728bf0c84a1760cc6eb4e175b2..26284c1cdef3ab0fc6d6780e7b00811c3b7b0a0d 100644 --- a/ACL_PyTorch/built-in/audio/LSTM/pyacl_infer.py +++ b/ACL_PyTorch/built-in/audio/LSTM/pyacl_infer.py @@ -1,157 +1,157 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import acl -from acl_net import AclModel - -import os -import shutil -import argparse -import numpy as np -from tqdm import tqdm - -DTYPE = { - 'float32': np.float32, - 'float64': np.float64, - 'int32': np.int32, - 'int64': np.int64 -} - -if __name__ == '__main__': - ''' - 参数说明: - --model_path:模型路径 - --device_id:npu id - --cpu_run:MeasureTime类的cpu_run参数,True or False - --sync_infer:推理方式: - True:同步推理 - False:异步推理 - --workspace:类似TensorRT `workspace`参数,计算平均推理时间时排除前n次推理 - --input_info_file_path:类似benchmark的bin_info文件 - --input_dtypes:模型输入的类型,用逗号分割(`DTYPE`变量) - e.g. 模型只有一个输入:--input_dtypes=float32 - e.g. 模型有多个输入:--input_dtypes=float32,float32,float32(需要和bin_info文件多输入排列一致) - --infer_res_save_path:推理结果保存目录 - --res_save_type:推理结果保存类型,bin或npy - - info文件说明: - 因为支持动态shape,相比于benchmark的info文件,需要多加一列shape信息,e.g. - ``` - 0 ./bert_bin/input_ids_0.bin (1,512) - 0 ./bert_bin/segment_ids_0.bin (1,512) - 0 ./bert_bin/input_mask_0.bin (1,512) - 1 ./bert_bin/input_ids_1.bin (1,512) - 1 ./bert_bin/segment_ids_1.bin (1,512) - 1 ./bert_bin/input_mask_1.bin (1,512) - ``` - - Using Example: - python3.7 pyacl_infer.py \ - --model_path=./bert_base_batch_1_sim_auto.om \ - --device_id=0 \ - --cpu_run=True \ - --sync_infer=True \ - --workspace=10 \ - --input_info_file_path=./input.info \ - --input_dtypes=int64,int64,int64 \ - --infer_res_save_path=./infer_res \ - --res_save_type=bin - ''' - - # 参数解析 - parser = argparse.ArgumentParser() - parser.add_argument('--model_path', required=True) - parser.add_argument('--device_id', required=True, type=int) - parser.add_argument('--cpu_run', required=True, choices=['True', 'False']) - parser.add_argument('--sync_infer', required=True, choices=['True', 'False']) - parser.add_argument('--workspace', required=True, type=int) - parser.add_argument('--input_info_file_path', required=True) - parser.add_argument('--input_dtypes', required=True) - parser.add_argument('--infer_res_save_path', required=True) - parser.add_argument('--res_save_type', required=True, choices=['bin', 'npy']) - opt = parser.parse_args() - - # 创建模型 - measurements = {} - om_model = AclModel(device_id=opt.device_id, - model_path=opt.model_path, - sync_infer=eval(opt.sync_infer), - measurements=measurements, - key='per_infer_time_ns', - cpu_run=eval(opt.cpu_run)) - - # 创建目录 - if os.path.exists(opt.infer_res_save_path): - shutil.rmtree(opt.infer_res_save_path) - os.makedirs(opt.infer_res_save_path) - - # 读取info_file - inputs_info = {} - with open(opt.input_info_file_path, 'rt', encoding='utf-8') as f_info: - line = f_info.readline() - while line: - line = line.rstrip('\n') - contents = line.split() - info = {'path': contents[1], 'shape': eval(contents[2])} - inputs_info.setdefault(contents[0], []).append(info) - line = f_info.readline() - - # 解析输入类型 - input_dtypes = opt.input_dtypes.split(',') - input_dtypes = list(map(lambda x: DTYPE[x], input_dtypes)) - - # 读取文件推理 - total_infer_time = 0 - total_infer_time_workspace = 0 - total_infer_num = 0 - for key, values in tqdm(inputs_info.items()): - # 构造输入 - inputs = [] - dims = [] - for idx, value in enumerate(values): - x = np.fromfile(value['path'], dtype=input_dtypes[idx]).reshape(value['shape']) - inputs.append(x) - dims.extend(value['shape']) - dims_info = {'dimCount': len(dims), 'name': '', 'dims': dims} - - # 推理得到输出 - output = om_model(inputs, dims_info) - #print("[INFO]: output()", len(output)) - #print("[INFO]: output.shape()", output[0].shape) - #exit() - total_infer_num += 1 - - # 保存文件 - if opt.res_save_type == 'bin': - for idx, data in enumerate(output): - data.tofile(os.path.join(opt.infer_res_save_path, key + '.' + str(idx) + '.bin')) - else: - for idx, data in enumerate(output): - np.save(os.path.join(opt.infer_res_save_path, key + '.' + str(idx) + '.npy'), data) - - # 计算时间 - total_infer_time += measurements['per_infer_time_ns'] - if total_infer_num > opt.workspace: - total_infer_time_workspace += measurements['per_infer_time_ns'] - - # 推理时间 - print('[INFO] Infer time:') - msg = 'total infer num: ' + str(total_infer_num) + '\n' + \ - 'total pure infer time(ms): ' + str(total_infer_time / 1000 / 1000) + '\n' + \ - 'average pure infer time(ms): ' + str(total_infer_time / total_infer_num / 1000 / 1000) + '\n' + \ - 'average pure infer time after workspace(ms): ' + str(abs( - total_infer_time_workspace / (total_infer_num - opt.workspace) / 1000 / 1000)) + '\n' - print(msg) - with open(os.path.join(opt.infer_res_save_path, 'infer_time.txt'), 'wt', encoding='utf-8') as f_infer_time: - f_infer_time.write(msg) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import acl +from acl_net import AclModel + +import os +import shutil +import argparse +import numpy as np +from tqdm import tqdm + +DTYPE = { + 'float32': np.float32, + 'float64': np.float64, + 'int32': np.int32, + 'int64': np.int64 +} + +if __name__ == '__main__': + ''' + 参数说明: + --model_path:模型路径 + --device_id:npu id + --cpu_run:MeasureTime类的cpu_run参数,True or False + --sync_infer:推理方式: + True:同步推理 + False:异步推理 + --workspace:类似TensorRT `workspace`参数,计算平均推理时间时排除前n次推理 + --input_info_file_path:类似benchmark的bin_info文件 + --input_dtypes:模型输入的类型,用逗号分割(`DTYPE`变量) + e.g. 模型只有一个输入:--input_dtypes=float32 + e.g. 模型有多个输入:--input_dtypes=float32,float32,float32(需要和bin_info文件多输入排列一致) + --infer_res_save_path:推理结果保存目录 + --res_save_type:推理结果保存类型,bin或npy + + info文件说明: + 因为支持动态shape,相比于benchmark的info文件,需要多加一列shape信息,e.g. + ``` + 0 ./bert_bin/input_ids_0.bin (1,512) + 0 ./bert_bin/segment_ids_0.bin (1,512) + 0 ./bert_bin/input_mask_0.bin (1,512) + 1 ./bert_bin/input_ids_1.bin (1,512) + 1 ./bert_bin/segment_ids_1.bin (1,512) + 1 ./bert_bin/input_mask_1.bin (1,512) + ``` + + Using Example: + python3.7 pyacl_infer.py \ + --model_path=./bert_base_batch_1_sim_auto.om \ + --device_id=0 \ + --cpu_run=True \ + --sync_infer=True \ + --workspace=10 \ + --input_info_file_path=./input.info \ + --input_dtypes=int64,int64,int64 \ + --infer_res_save_path=./infer_res \ + --res_save_type=bin + ''' + + # 参数解析 + parser = argparse.ArgumentParser() + parser.add_argument('--model_path', required=True) + parser.add_argument('--device_id', required=True, type=int) + parser.add_argument('--cpu_run', required=True, choices=['True', 'False']) + parser.add_argument('--sync_infer', required=True, choices=['True', 'False']) + parser.add_argument('--workspace', required=True, type=int) + parser.add_argument('--input_info_file_path', required=True) + parser.add_argument('--input_dtypes', required=True) + parser.add_argument('--infer_res_save_path', required=True) + parser.add_argument('--res_save_type', required=True, choices=['bin', 'npy']) + opt = parser.parse_args() + + # 创建模型 + measurements = {} + om_model = AclModel(device_id=opt.device_id, + model_path=opt.model_path, + sync_infer=eval(opt.sync_infer), + measurements=measurements, + key='per_infer_time_ns', + cpu_run=eval(opt.cpu_run)) + + # 创建目录 + if os.path.exists(opt.infer_res_save_path): + shutil.rmtree(opt.infer_res_save_path) + os.makedirs(opt.infer_res_save_path) + + # 读取info_file + inputs_info = {} + with open(opt.input_info_file_path, 'rt', encoding='utf-8') as f_info: + line = f_info.readline() + while line: + line = line.rstrip('\n') + contents = line.split() + info = {'path': contents[1], 'shape': eval(contents[2])} + inputs_info.setdefault(contents[0], []).append(info) + line = f_info.readline() + + # 解析输入类型 + input_dtypes = opt.input_dtypes.split(',') + input_dtypes = list(map(lambda x: DTYPE[x], input_dtypes)) + + # 读取文件推理 + total_infer_time = 0 + total_infer_time_workspace = 0 + total_infer_num = 0 + for key, values in tqdm(inputs_info.items()): + # 构造输入 + inputs = [] + dims = [] + for idx, value in enumerate(values): + x = np.fromfile(value['path'], dtype=input_dtypes[idx]).reshape(value['shape']) + inputs.append(x) + dims.extend(value['shape']) + dims_info = {'dimCount': len(dims), 'name': '', 'dims': dims} + + # 推理得到输出 + output = om_model(inputs, dims_info) + #print("[INFO]: output()", len(output)) + #print("[INFO]: output.shape()", output[0].shape) + #exit() + total_infer_num += 1 + + # 保存文件 + if opt.res_save_type == 'bin': + for idx, data in enumerate(output): + data.tofile(os.path.join(opt.infer_res_save_path, key + '.' + str(idx) + '.bin')) + else: + for idx, data in enumerate(output): + np.save(os.path.join(opt.infer_res_save_path, key + '.' + str(idx) + '.npy'), data) + + # 计算时间 + total_infer_time += measurements['per_infer_time_ns'] + if total_infer_num > opt.workspace: + total_infer_time_workspace += measurements['per_infer_time_ns'] + + # 推理时间 + print('[INFO] Infer time:') + msg = 'total infer num: ' + str(total_infer_num) + '\n' + \ + 'total pure infer time(ms): ' + str(total_infer_time / 1000 / 1000) + '\n' + \ + 'average pure infer time(ms): ' + str(total_infer_time / total_infer_num / 1000 / 1000) + '\n' + \ + 'average pure infer time after workspace(ms): ' + str(abs( + total_infer_time_workspace / (total_infer_num - opt.workspace) / 1000 / 1000)) + '\n' + print(msg) + with open(os.path.join(opt.infer_res_save_path, 'infer_time.txt'), 'wt', encoding='utf-8') as f_infer_time: + f_infer_time.write(msg) diff --git a/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/LICENSE b/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/LICENSE index 6ae23f3ae77ebaaf09980b82ec0ae2b1e7ba138f..68faf63cc5e11d595689e449524fe79c100d5bd9 100644 --- a/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/LICENSE +++ b/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/LICENSE @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2021 eurecom-asp - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +MIT License + +Copyright (c) 2021 eurecom-asp + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/README.md b/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/README.md index e90ac7edc5385d33ef56732c6a72a2699727d6b2..b97f4f754c6cc3fcbd5b3d0777d8810a7c428ddf 100644 --- a/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/README.md +++ b/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/README.md @@ -1,100 +1,100 @@ -# RawNet2模型推理指导 - -- [1 文件说明](#1-文件说明) -- [2 环境准备](#2-环境准备) - - [2.1 文件下载](#21-文件下载) - - [2.2 文件拷贝](#22-文件拷贝) - - [2.3 设置环境变量](#23-设置环境变量) -- [3 端到端推理步骤](#3-端到端推理步骤) - - [3.1 修改pytorch模型源码](#31-修改pytorch模型源码) - - [3.2 pth转onnx模型](#32-pth转onnx模型) - - [3.3 修改导出的onnx模型](#33-修改导出的onnx模型) - - [3.4 利用ATC工具转换为om模型](#34-利用ATC工具转换为om模型) - - [3.5 om模型推理](#35-om模型推理) - ------- - -## 1 文件说明 -``` -RawNet2_for_Pytorch - ├── env.sh 设置环境变量 - ├── pth2onnx.py pytorch模型导出onnx模型 - ├── modify_onnx.py 修改导出的onnx模型 - ├── atc.sh onnx模型转om - ├── om_infer.py 推理导出的om模型 - └── acl_net.py PyACL推理工具代码 -``` - -## 2 环境准备 - -### 2.1 文件下载 -- [RawNet2_Pytorch源码下载](https://github.com/asvspoof-challenge/2021/tree/main/LA/Baseline-RawNet2) - ``` - git clone https://github.com/asvspoof-challenge/2021.git - cd 2021/LA/Baseline-RawNet2/ - ``` -- [权重下载](https://www.asvspoof.org/asvspoof2021/pre_trained_DF_RawNet2.zip) -- [数据集下载](https://datashare.ed.ac.uk/handle/10283/3336) - om推理采用ASVspoof2019数据集的验证集进行精度评估。 - -### 2.2 文件拷贝 -拷贝env.sh,pth2onnx.py,modify_onnx.py,atc.sh,om_infer.py,acl_net.py文件到2021/LA/Baseline-RawNet2/目录下。 -将下载的权重文件pre_trained_DF_RawNet2.pth放在和代码同一目录下。 -在同一目录下创建data目录并将下载的数据集放入,data目录中的文件结构如下所示。 -``` -data - └── LA - ├── ASVspoof2019_LA_asv_protocols - ├── ASVspoof2019_LA_asv_scores - ├── ASVspoof2019_LA_cm_protocols - ├── ASVspoof2019_LA_dev - ├── ASVspoof2019_LA_eval - └── ASVspoof2019_LA_train -``` - -### 2.3 设置环境变量 -```shell -source env.sh -``` - -## 3 端到端推理步骤 - -### 3.1 修改pytorch模型源码 -导onnx模型需要修改2021/LA/Baseline-RawNet2/model.py中的SincConv类,在该类的forward函数中增加一行,如下所示。 -```python -self.band_pass = torch.from_numpy(self.band_pass.numpy()) # 增加行,和下行缩进保持一致 -band_pass_filter=self.band_pass.to(self.device) # 根据该行代码找到增加位置 -``` - -### 3.2 pth导出onnx -```python -python3.7 pth2onnx.py \ - --pth_model=pre_trained_DF_RawNet2.pth \ - --onnx_model=rawnet2_ori.onnx \ - --batch_size=1 -``` - -### 3.3 修改导出的onnx模型 -```python -python3.7 -m onnxsim rawnet2_ori.onnx rawnet2_sim.onnx - -python3.7 modify_onnx.py \ - --input_onnx=rawnet2_sim.onnx \ - --output_onnx=rawnet2_modify.onnx -``` - -### 3.4 利用ATC工具转换为om模型 -```shell -bash atc.sh rawnet2_modify.onnx rawnet2_modify input:1,64600 -``` -注:目前ATC支持的onnx算子版本为11 - -### 3.5 om模型推理 -```python -python3.7 om_infer.py \ - --batch_size=1 \ - --om_path=rawnet2_modify.om \ - --eval_output='rawnet2_modify_om.txt' \ - --database_path='data/LA/' \ - --protocols_path='data/LA/' +# RawNet2模型推理指导 + +- [1 文件说明](#1-文件说明) +- [2 环境准备](#2-环境准备) + - [2.1 文件下载](#21-文件下载) + - [2.2 文件拷贝](#22-文件拷贝) + - [2.3 设置环境变量](#23-设置环境变量) +- [3 端到端推理步骤](#3-端到端推理步骤) + - [3.1 修改pytorch模型源码](#31-修改pytorch模型源码) + - [3.2 pth转onnx模型](#32-pth转onnx模型) + - [3.3 修改导出的onnx模型](#33-修改导出的onnx模型) + - [3.4 利用ATC工具转换为om模型](#34-利用ATC工具转换为om模型) + - [3.5 om模型推理](#35-om模型推理) + +------ + +## 1 文件说明 +``` +RawNet2_for_Pytorch + ├── env.sh 设置环境变量 + ├── pth2onnx.py pytorch模型导出onnx模型 + ├── modify_onnx.py 修改导出的onnx模型 + ├── atc.sh onnx模型转om + ├── om_infer.py 推理导出的om模型 + └── acl_net.py PyACL推理工具代码 +``` + +## 2 环境准备 + +### 2.1 文件下载 +- [RawNet2_Pytorch源码下载](https://github.com/asvspoof-challenge/2021/tree/main/LA/Baseline-RawNet2) + ``` + git clone https://github.com/asvspoof-challenge/2021.git + cd 2021/LA/Baseline-RawNet2/ + ``` +- [权重下载](https://www.asvspoof.org/asvspoof2021/pre_trained_DF_RawNet2.zip) +- [数据集下载](https://datashare.ed.ac.uk/handle/10283/3336) + om推理采用ASVspoof2019数据集的验证集进行精度评估。 + +### 2.2 文件拷贝 +拷贝env.sh,pth2onnx.py,modify_onnx.py,atc.sh,om_infer.py,acl_net.py文件到2021/LA/Baseline-RawNet2/目录下。 +将下载的权重文件pre_trained_DF_RawNet2.pth放在和代码同一目录下。 +在同一目录下创建data目录并将下载的数据集放入,data目录中的文件结构如下所示。 +``` +data + └── LA + ├── ASVspoof2019_LA_asv_protocols + ├── ASVspoof2019_LA_asv_scores + ├── ASVspoof2019_LA_cm_protocols + ├── ASVspoof2019_LA_dev + ├── ASVspoof2019_LA_eval + └── ASVspoof2019_LA_train +``` + +### 2.3 设置环境变量 +```shell +source env.sh +``` + +## 3 端到端推理步骤 + +### 3.1 修改pytorch模型源码 +导onnx模型需要修改2021/LA/Baseline-RawNet2/model.py中的SincConv类,在该类的forward函数中增加一行,如下所示。 +```python +self.band_pass = torch.from_numpy(self.band_pass.numpy()) # 增加行,和下行缩进保持一致 +band_pass_filter=self.band_pass.to(self.device) # 根据该行代码找到增加位置 +``` + +### 3.2 pth导出onnx +```python +python3.7 pth2onnx.py \ + --pth_model=pre_trained_DF_RawNet2.pth \ + --onnx_model=rawnet2_ori.onnx \ + --batch_size=1 +``` + +### 3.3 修改导出的onnx模型 +```python +python3.7 -m onnxsim rawnet2_ori.onnx rawnet2_sim.onnx + +python3.7 modify_onnx.py \ + --input_onnx=rawnet2_sim.onnx \ + --output_onnx=rawnet2_modify.onnx +``` + +### 3.4 利用ATC工具转换为om模型 +```shell +bash atc.sh rawnet2_modify.onnx rawnet2_modify input:1,64600 +``` +注:目前ATC支持的onnx算子版本为11 + +### 3.5 om模型推理 +```python +python3.7 om_infer.py \ + --batch_size=1 \ + --om_path=rawnet2_modify.om \ + --eval_output='rawnet2_modify_om.txt' \ + --database_path='data/LA/' \ + --protocols_path='data/LA/' ``` \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/acl_net.py b/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/acl_net.py index ff5429e2787bad9f98ffaaeac2a14bbd02ea9648..0b1084057017f52f54952ff93b193983488ce838 100644 --- a/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/acl_net.py +++ b/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/acl_net.py @@ -1,259 +1,259 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import time -import numpy as np -import functools -import acl - -# error code -ACL_ERROR_NONE = 0 - -# rule for mem -ACL_MEM_MALLOC_HUGE_FIRST = 0 -ACL_MEM_MALLOC_HUGE_ONLY = 1 -ACL_MEM_MALLOC_NORMAL_ONLY = 2 - -# rule for memory copy -ACL_MEMCPY_HOST_TO_HOST = 0 -ACL_MEMCPY_HOST_TO_DEVICE = 1 -ACL_MEMCPY_DEVICE_TO_HOST = 2 -ACL_MEMCPY_DEVICE_TO_DEVICE = 3 - -ACL_DTYPE = { - 0: 'float32', - 1: 'float16', - 2: 'int8', - 3: 'int32', - 4: 'uint8', - 6: 'int16', - 7: 'uint16', - 8: 'uint32', - 9: 'int64', - 10: 'uint64', - 11: 'float64', - 12: 'bool', -} - -buffer_method = { - "in": acl.mdl.get_input_size_by_index, - "out": acl.mdl.get_output_size_by_index -} - - -def check_ret(message, ret): - if ret != ACL_ERROR_NONE: - raise Exception("{} failed ret={}".format(message, ret)) - - -class Net(object): - def __init__(self, model_path, device_id=0, config_path=None): - self.device_id = device_id # int - self.model_path = model_path # string - self.model_id = None # pointer - self.context = None # pointer - - self.input_data = [] - self.output_data = [] - self.model_desc = None # pointer when using - self.load_input_dataset = None - self.load_output_dataset = None - - self._init_resource(config_path) - - def __call__(self, ori_data): - return self.forward(ori_data) - - def __del__(self): - ret = acl.mdl.unload(self.model_id) - check_ret("acl.mdl.unload", ret) - if self.model_desc: - acl.mdl.destroy_desc(self.model_desc) - self.model_desc = None - - while self.input_data: - item = self.input_data.pop() - ret = acl.rt.free(item["buffer"]) - check_ret("acl.rt.free", ret) - - while self.output_data: - item = self.output_data.pop() - ret = acl.rt.free(item["buffer"]) - check_ret("acl.rt.free", ret) - - if self.context: - ret = acl.rt.destroy_context(self.context) - check_ret("acl.rt.destroy_context", ret) - self.context = None - - ret = acl.rt.reset_device(self.device_id) - check_ret("acl.rt.reset_device", ret) - ret = acl.finalize() - check_ret("acl.finalize", ret) - - def _init_resource(self, config_path=None): - if config_path: - ret = acl.init(config_path) - else: - ret = acl.init() - check_ret("acl.init", ret) - ret = acl.rt.set_device(self.device_id) - check_ret("acl.rt.set_device", ret) - - self.context, ret = acl.rt.create_context(self.device_id) - check_ret("acl.rt.create_context", ret) - - # load_model - self.model_id, ret = acl.mdl.load_from_file(self.model_path) - check_ret("acl.mdl.load_from_file", ret) - - self.model_desc = acl.mdl.create_desc() - self._get_model_info() - - def _get_model_info(self, ): - ret = acl.mdl.get_desc(self.model_desc, self.model_id) - check_ret("acl.mdl.get_desc", ret) - input_size = acl.mdl.get_num_inputs(self.model_desc) - output_size = acl.mdl.get_num_outputs(self.model_desc) - self._gen_data_buffer(input_size, des="in") - self._gen_data_buffer(output_size, des="out") - - def _gen_data_buffer(self, size, des): - func = buffer_method[des] - for i in range(size): - temp_buffer_size = func(self.model_desc, i) - temp_buffer, ret = acl.rt.malloc(temp_buffer_size, - ACL_MEM_MALLOC_HUGE_FIRST) - check_ret("acl.rt.malloc", ret) - - if des == "in": - self.input_data.append({"buffer": temp_buffer, - "size": temp_buffer_size}) - elif des == "out": - self.output_data.append({"buffer": temp_buffer, - "size": temp_buffer_size}) - - def _data_interaction(self, dataset, policy=ACL_MEMCPY_HOST_TO_DEVICE): - temp_data_buffer = self.input_data \ - if policy == ACL_MEMCPY_HOST_TO_DEVICE \ - else self.output_data - if len(dataset) == 0 and policy == ACL_MEMCPY_DEVICE_TO_HOST: - for item in self.output_data: - temp, ret = acl.rt.malloc_host(item["size"]) - if ret != 0: - raise Exception("can't malloc_host ret={}".format(ret)) - dataset.append({"size": item["size"], "buffer": temp}) - - for i, item in enumerate(temp_data_buffer): - if policy == ACL_MEMCPY_HOST_TO_DEVICE: - if 'bytes_to_ptr' in dir(acl.util): - bytes_in = dataset[i].tobytes() - ptr = acl.util.bytes_to_ptr(bytes_in) - else: - ptr = acl.util.numpy_to_ptr(dataset[i]) - ret = acl.rt.memcpy(item["buffer"], item["size"], ptr, item["size"], policy) - check_ret("acl.rt.memcpy", ret) - - else: - ptr = dataset[i]["buffer"] - ret = acl.rt.memcpy(ptr, item["size"], item["buffer"], item["size"], policy) - check_ret("acl.rt.memcpy", ret) - - def _gen_dataset(self, type_str="input"): - dataset = acl.mdl.create_dataset() - - temp_dataset = None - if type_str == "in": - self.load_input_dataset = dataset - temp_dataset = self.input_data - else: - self.load_output_dataset = dataset - temp_dataset = self.output_data - - for item in temp_dataset: - data = acl.create_data_buffer(item["buffer"], item["size"]) - if data is None: - ret = acl.destroy_data_buffer(dataset) - check_ret("acl.destroy_data_buffer", ret) - - _, ret = acl.mdl.add_dataset_buffer(dataset, data) - - if ret != ACL_ERROR_NONE: - ret = acl.destroy_data_buffer(dataset) - check_ret("acl.destroy_data_buffer", ret) - - def _data_from_host_to_device(self, images): - self._data_interaction(images, ACL_MEMCPY_HOST_TO_DEVICE) - self._gen_dataset("in") - self._gen_dataset("out") - - def _data_from_device_to_host(self): - res = [] - self._data_interaction(res, ACL_MEMCPY_DEVICE_TO_HOST) - output = self.get_result(res) - return output - - def _destroy_databuffer(self, ): - for dataset in [self.load_input_dataset, self.load_output_dataset]: - if not dataset: - continue - - num = acl.mdl.get_dataset_num_buffers(dataset) - for i in range(num): - data_buf = acl.mdl.get_dataset_buffer(dataset, i) - if data_buf: - ret = acl.destroy_data_buffer(data_buf) - check_ret("acl.destroy_data_buffer", ret) - ret = acl.mdl.destroy_dataset(dataset) - check_ret("acl.mdl.destroy_dataset", ret) - - def forward(self, input_data): - if not isinstance(input_data, (list, tuple)): - input_data = [input_data] - st = time.time() - self._data_from_host_to_device(input_data) - mem_t = time.time() - st - st = time.time() - ret = acl.mdl.execute(self.model_id, - self.load_input_dataset, - self.load_output_dataset) - exe_t = time.time() - st - st = time.time() - check_ret("acl.mdl.execute", ret) - self._destroy_databuffer() - result = self._data_from_device_to_host() - mem_t += time.time() - st - return result - - def get_result(self, output_data): - dataset = [] - for i in range(len(output_data)): - dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) - check_ret("acl.mdl.get_cur_output_dims", ret) - data_shape = dims.get("dims") - data_type = acl.mdl.get_output_data_type(self.model_desc, i) - data_len = functools.reduce(lambda x, y: x * y, data_shape) - ftype = np.dtype(ACL_DTYPE.get(data_type)) - - size = output_data[i]["size"] - ptr = output_data[i]["buffer"] - if 'ptr_to_bytes' in dir(acl.util): - data = acl.util.ptr_to_bytes(ptr, size) - np_arr = np.frombuffer(data, dtype=ftype, count=data_len) - else: - data = acl.util.ptr_to_numpy(ptr, (size,), 1) - np_arr = np.frombuffer(bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) - np_arr = np_arr.reshape(data_shape) - dataset.append(np_arr) - return dataset +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import time +import numpy as np +import functools +import acl + +# error code +ACL_ERROR_NONE = 0 + +# rule for mem +ACL_MEM_MALLOC_HUGE_FIRST = 0 +ACL_MEM_MALLOC_HUGE_ONLY = 1 +ACL_MEM_MALLOC_NORMAL_ONLY = 2 + +# rule for memory copy +ACL_MEMCPY_HOST_TO_HOST = 0 +ACL_MEMCPY_HOST_TO_DEVICE = 1 +ACL_MEMCPY_DEVICE_TO_HOST = 2 +ACL_MEMCPY_DEVICE_TO_DEVICE = 3 + +ACL_DTYPE = { + 0: 'float32', + 1: 'float16', + 2: 'int8', + 3: 'int32', + 4: 'uint8', + 6: 'int16', + 7: 'uint16', + 8: 'uint32', + 9: 'int64', + 10: 'uint64', + 11: 'float64', + 12: 'bool', +} + +buffer_method = { + "in": acl.mdl.get_input_size_by_index, + "out": acl.mdl.get_output_size_by_index +} + + +def check_ret(message, ret): + if ret != ACL_ERROR_NONE: + raise Exception("{} failed ret={}".format(message, ret)) + + +class Net(object): + def __init__(self, model_path, device_id=0, config_path=None): + self.device_id = device_id # int + self.model_path = model_path # string + self.model_id = None # pointer + self.context = None # pointer + + self.input_data = [] + self.output_data = [] + self.model_desc = None # pointer when using + self.load_input_dataset = None + self.load_output_dataset = None + + self._init_resource(config_path) + + def __call__(self, ori_data): + return self.forward(ori_data) + + def __del__(self): + ret = acl.mdl.unload(self.model_id) + check_ret("acl.mdl.unload", ret) + if self.model_desc: + acl.mdl.destroy_desc(self.model_desc) + self.model_desc = None + + while self.input_data: + item = self.input_data.pop() + ret = acl.rt.free(item["buffer"]) + check_ret("acl.rt.free", ret) + + while self.output_data: + item = self.output_data.pop() + ret = acl.rt.free(item["buffer"]) + check_ret("acl.rt.free", ret) + + if self.context: + ret = acl.rt.destroy_context(self.context) + check_ret("acl.rt.destroy_context", ret) + self.context = None + + ret = acl.rt.reset_device(self.device_id) + check_ret("acl.rt.reset_device", ret) + ret = acl.finalize() + check_ret("acl.finalize", ret) + + def _init_resource(self, config_path=None): + if config_path: + ret = acl.init(config_path) + else: + ret = acl.init() + check_ret("acl.init", ret) + ret = acl.rt.set_device(self.device_id) + check_ret("acl.rt.set_device", ret) + + self.context, ret = acl.rt.create_context(self.device_id) + check_ret("acl.rt.create_context", ret) + + # load_model + self.model_id, ret = acl.mdl.load_from_file(self.model_path) + check_ret("acl.mdl.load_from_file", ret) + + self.model_desc = acl.mdl.create_desc() + self._get_model_info() + + def _get_model_info(self, ): + ret = acl.mdl.get_desc(self.model_desc, self.model_id) + check_ret("acl.mdl.get_desc", ret) + input_size = acl.mdl.get_num_inputs(self.model_desc) + output_size = acl.mdl.get_num_outputs(self.model_desc) + self._gen_data_buffer(input_size, des="in") + self._gen_data_buffer(output_size, des="out") + + def _gen_data_buffer(self, size, des): + func = buffer_method[des] + for i in range(size): + temp_buffer_size = func(self.model_desc, i) + temp_buffer, ret = acl.rt.malloc(temp_buffer_size, + ACL_MEM_MALLOC_HUGE_FIRST) + check_ret("acl.rt.malloc", ret) + + if des == "in": + self.input_data.append({"buffer": temp_buffer, + "size": temp_buffer_size}) + elif des == "out": + self.output_data.append({"buffer": temp_buffer, + "size": temp_buffer_size}) + + def _data_interaction(self, dataset, policy=ACL_MEMCPY_HOST_TO_DEVICE): + temp_data_buffer = self.input_data \ + if policy == ACL_MEMCPY_HOST_TO_DEVICE \ + else self.output_data + if len(dataset) == 0 and policy == ACL_MEMCPY_DEVICE_TO_HOST: + for item in self.output_data: + temp, ret = acl.rt.malloc_host(item["size"]) + if ret != 0: + raise Exception("can't malloc_host ret={}".format(ret)) + dataset.append({"size": item["size"], "buffer": temp}) + + for i, item in enumerate(temp_data_buffer): + if policy == ACL_MEMCPY_HOST_TO_DEVICE: + if 'bytes_to_ptr' in dir(acl.util): + bytes_in = dataset[i].tobytes() + ptr = acl.util.bytes_to_ptr(bytes_in) + else: + ptr = acl.util.numpy_to_ptr(dataset[i]) + ret = acl.rt.memcpy(item["buffer"], item["size"], ptr, item["size"], policy) + check_ret("acl.rt.memcpy", ret) + + else: + ptr = dataset[i]["buffer"] + ret = acl.rt.memcpy(ptr, item["size"], item["buffer"], item["size"], policy) + check_ret("acl.rt.memcpy", ret) + + def _gen_dataset(self, type_str="input"): + dataset = acl.mdl.create_dataset() + + temp_dataset = None + if type_str == "in": + self.load_input_dataset = dataset + temp_dataset = self.input_data + else: + self.load_output_dataset = dataset + temp_dataset = self.output_data + + for item in temp_dataset: + data = acl.create_data_buffer(item["buffer"], item["size"]) + if data is None: + ret = acl.destroy_data_buffer(dataset) + check_ret("acl.destroy_data_buffer", ret) + + _, ret = acl.mdl.add_dataset_buffer(dataset, data) + + if ret != ACL_ERROR_NONE: + ret = acl.destroy_data_buffer(dataset) + check_ret("acl.destroy_data_buffer", ret) + + def _data_from_host_to_device(self, images): + self._data_interaction(images, ACL_MEMCPY_HOST_TO_DEVICE) + self._gen_dataset("in") + self._gen_dataset("out") + + def _data_from_device_to_host(self): + res = [] + self._data_interaction(res, ACL_MEMCPY_DEVICE_TO_HOST) + output = self.get_result(res) + return output + + def _destroy_databuffer(self, ): + for dataset in [self.load_input_dataset, self.load_output_dataset]: + if not dataset: + continue + + num = acl.mdl.get_dataset_num_buffers(dataset) + for i in range(num): + data_buf = acl.mdl.get_dataset_buffer(dataset, i) + if data_buf: + ret = acl.destroy_data_buffer(data_buf) + check_ret("acl.destroy_data_buffer", ret) + ret = acl.mdl.destroy_dataset(dataset) + check_ret("acl.mdl.destroy_dataset", ret) + + def forward(self, input_data): + if not isinstance(input_data, (list, tuple)): + input_data = [input_data] + st = time.time() + self._data_from_host_to_device(input_data) + mem_t = time.time() - st + st = time.time() + ret = acl.mdl.execute(self.model_id, + self.load_input_dataset, + self.load_output_dataset) + exe_t = time.time() - st + st = time.time() + check_ret("acl.mdl.execute", ret) + self._destroy_databuffer() + result = self._data_from_device_to_host() + mem_t += time.time() - st + return result + + def get_result(self, output_data): + dataset = [] + for i in range(len(output_data)): + dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) + check_ret("acl.mdl.get_cur_output_dims", ret) + data_shape = dims.get("dims") + data_type = acl.mdl.get_output_data_type(self.model_desc, i) + data_len = functools.reduce(lambda x, y: x * y, data_shape) + ftype = np.dtype(ACL_DTYPE.get(data_type)) + + size = output_data[i]["size"] + ptr = output_data[i]["buffer"] + if 'ptr_to_bytes' in dir(acl.util): + data = acl.util.ptr_to_bytes(ptr, size) + np_arr = np.frombuffer(data, dtype=ftype, count=data_len) + else: + data = acl.util.ptr_to_numpy(ptr, (size,), 1) + np_arr = np.frombuffer(bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) + np_arr = np_arr.reshape(data_shape) + dataset.append(np_arr) + return dataset diff --git a/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/modelzoo_level.txt b/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/modelzoo_level.txt +++ b/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/modify_onnx.py b/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/modify_onnx.py index ff9cc34aaca0d2c8900e0d8c5310a363179c6eb7..dcbbc457d0979b0be47649bf0c6cd877dd7c0e06 100644 --- a/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/modify_onnx.py +++ b/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/modify_onnx.py @@ -1,222 +1,222 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -*- coding:utf-8 -*- - -import argparse -import numpy as np -import copy -from gener_core.mod_modify.interface import AttrType as AT -from gener_core.mod_modify.onnx_graph import OXGraph - - -def make_conv2d_split_node(mod, conv_node, weight, chk_idx, chk_sz, ksz): - x_node = mod.get_node(conv_node.input_name[0]) - - # slice - rng = np.random.randint(0, 7393) - begin = chk_sz * chk_idx - end = -(ksz - chk_sz) + chk_sz * chk_idx - if end >= 0: - end = np.iinfo(np.int32).max - begin1_node = mod.add_const_node(f"const_begin_{rng}", np.array([begin], np.int32)) - end1_node = mod.add_const_node(f"const_end_{rng}", np.array([end], np.int32)) - axes_node = mod.add_const_node(f"const_axes_{rng}", np.array([-1], np.int32)) - step_node = mod.add_const_node(f"const_step_{rng}", np.array([1], np.int32)) - slice1_node = mod.add_new_node(f"Slice_{rng}", "Slice") - slice1_node.set_input_node(0, [x_node, begin1_node, end1_node, axes_node, step_node]) - - # conv - conv1_node = mod.add_new_node(f"Conv_{np.random.randint(0, 7393)}", "Conv", - {"dilations": (AT.LIST_INT, [1, 1]), - "group": (AT.INT, 1), - "kernel_shape": (AT.LIST_INT, [1, weight.shape[-1]]), - "pads": (AT.LIST_INT, [0, 0, 0, 0]), - "strides": (AT.LIST_INT, [1, 1]), }) - w1_node = mod.add_const_node(f"weight_{np.random.randint(0, 7393)}", weight) - conv1_node.set_input_node(0, [slice1_node, w1_node]) - - return conv1_node - - -def shape_dim_extend(mod, io_map): - # NCD -> NCHW - rshp_node = mod.get_node("Reshape_9") - shape_node = mod.get_node(rshp_node.input_name[1]) - shape_value = shape_node.const_value - rng = np.random.randint(0, 7393) - shape_value = np.insert(shape_value, 2, 1) - new_shape_node = mod.add_const_node(f"const_shape_{rng}", shape_value.astype(np.int32)) - mod.node_replace(shape_node, new_shape_node) - - # modify all nodes for conv and maxpool - g_nodes = mod.get_nodes_by_optype("Conv") - for g_node in g_nodes: - weight_node = mod.get_node(g_node.input_name[1]) - weight_value = weight_node.const_value - - if len(weight_value.shape) == 3: - rng = np.random.randint(0, 7393) - kernel_shape = [1] + g_node.get_attr('kernel_shape', AT.LIST_INT) - dilations = g_node.get_attr('dilations', AT.LIST_INT) * 2 - pads = g_node.get_attr('pads', AT.LIST_INT) - if pads == [0, 0]: - pads = [0, 0, 0, 0] - if pads == [1, 1]: - pads = [0, 1, 0, 1] - strides = g_node.get_attr('strides', AT.LIST_INT) * 2 - g_node.set_attr({"kernel_shape": (AT.LIST_INT, kernel_shape)}) - g_node.set_attr({"dilations": (AT.LIST_INT, dilations)}) - g_node.set_attr({"pads": (AT.LIST_INT, pads)}) - g_node.set_attr({"strides": (AT.LIST_INT, strides)}) - new_weight_node = mod.add_const_node(f"const_weight_{rng}", np.expand_dims(weight_value, axis=2)) - mod.node_replace(weight_node, new_weight_node) - - g_node = mod.get_node("MaxPool_13") - rng = np.random.randint(0, 7393) - kernel_shape = [1] + g_node.get_attr('kernel_shape', AT.LIST_INT) - pads = g_node.get_attr('pads', AT.LIST_INT) * 2 - strides = g_node.get_attr('strides', AT.LIST_INT) * 2 - g_node.set_attr({"kernel_shape": (AT.LIST_INT, kernel_shape), - "dilations": (AT.LIST_INT, dilations), - "pads": (AT.LIST_INT, pads), - "strides": (AT.LIST_INT, strides)}) - - # NCHW -> NCD - res_node = mod.get_node('MaxPool_13') - squeeze_node = mod.add_new_node(f"Squeeze_{np.random.randint(0, 7393)}", "Squeeze", - {"axes": (AT.LIST_INT, [2])}) - squeeze_node.set_input_node(0, [res_node]) - after_res_node = mod.get_node(io_map.get(res_node.name)[0]) - after_res_node.set_input_node(0, [squeeze_node]) - - # NCD -> NCHW - g_nodes = mod.get_nodes_by_optype("Conv") - for g_node in g_nodes: - if g_node.name != "Conv_11" and mod.get_node(g_node.input_name[0]).op_type != "LeakyRelu": - rng = np.random.randint(0, 7393) - unsqueeze_node = mod.add_new_node(f"Unsqueeze_{rng}", "Unsqueeze", - {"axes": (AT.LIST_INT, [2])}) - - before_g_node = mod.get_node(g_node.input_name[0]) - w_node = mod.get_node(g_node.input_name[1]) - if len(g_node.input_name) == 2: - g_node.set_input_node(0, [unsqueeze_node, w_node]) - else: - b_node = mod.get_node(g_node.input_name[2]) - g_node.set_input_node(0, [unsqueeze_node, w_node, b_node]) - unsqueeze_node.set_input_node(0, [before_g_node]) - - # NCHW -> NCD - g_nodes = mod.get_nodes_by_optype("Add") - for g_node in g_nodes: - Add_b0 = mod.get_node(g_node.input_name[0]) - Add_b1 = mod.get_node(g_node.input_name[1]) - if mod.get_node(Add_b0.input_name[0]).op_type == "LeakyRelu": - rng = np.random.randint(0, 7393) - if Add_b1.op_type != "Conv": - unsqueeze_node = mod.add_new_node(f"Unsqueeze_{rng}", "Unsqueeze", - {"axes": (AT.LIST_INT, [2])}) - g_node.set_input_node(0, [unsqueeze_node, Add_b0]) - unsqueeze_node.set_input_node(0, [Add_b1]) - - squeeze_node = mod.add_new_node(f"Squeeze_{rng}", "Squeeze", - {"axes": (AT.LIST_INT, [2])}) - squeeze_node.set_input_node(0, [g_node]) - after_g_node = mod.get_node(io_map.get(g_node.name)[0]) - after_g_node.set_input_node(0, [squeeze_node]) - - -def make_model(input_onnx, output_onnx): - mod = OXGraph(input_onnx) - io_map = mod.get_net_in_out_map() - - # solve accuracy problem - gather_nodes = mod.get_nodes_by_optype("Gather") - for g_node in gather_nodes: - if g_node.name == 'Gather_203': - indices_node = mod.add_const_node(f'Const_{g_node.input_name[1]}', np.array(28).astype('int64')) - g_node.set_input_node(1, [indices_node]) - - # NCD -> NCHW - shape_dim_extend(mod, io_map) - - # conv split - conv_node = mod.get_node("Conv_11") - weight_node = mod.get_node(conv_node.input_name[1]) - weight_value = weight_node.const_value - - np.random.seed(1737) - KSZ = weight_value.shape[-1] - CHK_SZ = 128 - CHK_N = KSZ // CHK_SZ - wgt = [] - for i in range(CHK_N): - wgt.append(weight_value[:, :, :, CHK_SZ * i:CHK_SZ * (i + 1)]) - if KSZ % CHK_SZ != 0: - wgt.append(weight_value[:, :, :, CHK_SZ * CHK_N:]) - - rwn_node = [] - for i, w in enumerate(wgt): - node = make_conv2d_split_node(mod, conv_node, w, i, CHK_SZ, KSZ) - rwn_node.append(node) - - in_node_list = copy.deepcopy(rwn_node[:CHK_N]) - out_node_list = [] - combin_len = CHK_N - while len(in_node_list) > 1: - for j in range(0, combin_len, 2): - add_node = mod.add_new_node(f"Add_{np.random.randint(0, 7393)}", "Add") - add_node.set_input_node(0, [in_node_list[j], in_node_list[j + 1]]) - out_node_list.append(add_node) - in_node_list = copy.deepcopy(out_node_list) - out_node_list.clear() - combin_len //= 2 - - # add all result - if KSZ % CHK_SZ != 0: - add_node = mod.add_new_node(f"Add_{np.random.randint(0, 7393)}", "Add") - add_node.set_input_node(0, [in_node_list[0], rwn_node[-1]]) - else: - add_node = in_node_list[0] - - # relink - after_node = mod.get_node(io_map.get(conv_node.name)[0]) - after_node.set_input_node(0, [add_node]) - - # remove ori node - mod.node_remove([conv_node.name]) - mod.save_new_model(output_onnx) - - -def get_parser(): - parser = argparse.ArgumentParser(description='RawNet2') - parser.add_argument('--input_onnx', default=None, type=str, - help='input original onnx') - parser.add_argument('--output_onnx', default=None, type=str, - help='output modified onnx') - return parser - - -if __name__ == "__main__": - ''' - Example: - python3.7 modify_onnx.py \ - --input_onnx=rawnet2_sim.onnx \ - --output_onnx=rawnet2_modify.onnx - ''' - parser = get_parser() - args = parser.parse_args() - make_model(args.input_onnx, args.output_onnx) - print("modify successfully!") +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -*- coding:utf-8 -*- + +import argparse +import numpy as np +import copy +from gener_core.mod_modify.interface import AttrType as AT +from gener_core.mod_modify.onnx_graph import OXGraph + + +def make_conv2d_split_node(mod, conv_node, weight, chk_idx, chk_sz, ksz): + x_node = mod.get_node(conv_node.input_name[0]) + + # slice + rng = np.random.randint(0, 7393) + begin = chk_sz * chk_idx + end = -(ksz - chk_sz) + chk_sz * chk_idx + if end >= 0: + end = np.iinfo(np.int32).max + begin1_node = mod.add_const_node(f"const_begin_{rng}", np.array([begin], np.int32)) + end1_node = mod.add_const_node(f"const_end_{rng}", np.array([end], np.int32)) + axes_node = mod.add_const_node(f"const_axes_{rng}", np.array([-1], np.int32)) + step_node = mod.add_const_node(f"const_step_{rng}", np.array([1], np.int32)) + slice1_node = mod.add_new_node(f"Slice_{rng}", "Slice") + slice1_node.set_input_node(0, [x_node, begin1_node, end1_node, axes_node, step_node]) + + # conv + conv1_node = mod.add_new_node(f"Conv_{np.random.randint(0, 7393)}", "Conv", + {"dilations": (AT.LIST_INT, [1, 1]), + "group": (AT.INT, 1), + "kernel_shape": (AT.LIST_INT, [1, weight.shape[-1]]), + "pads": (AT.LIST_INT, [0, 0, 0, 0]), + "strides": (AT.LIST_INT, [1, 1]), }) + w1_node = mod.add_const_node(f"weight_{np.random.randint(0, 7393)}", weight) + conv1_node.set_input_node(0, [slice1_node, w1_node]) + + return conv1_node + + +def shape_dim_extend(mod, io_map): + # NCD -> NCHW + rshp_node = mod.get_node("Reshape_9") + shape_node = mod.get_node(rshp_node.input_name[1]) + shape_value = shape_node.const_value + rng = np.random.randint(0, 7393) + shape_value = np.insert(shape_value, 2, 1) + new_shape_node = mod.add_const_node(f"const_shape_{rng}", shape_value.astype(np.int32)) + mod.node_replace(shape_node, new_shape_node) + + # modify all nodes for conv and maxpool + g_nodes = mod.get_nodes_by_optype("Conv") + for g_node in g_nodes: + weight_node = mod.get_node(g_node.input_name[1]) + weight_value = weight_node.const_value + + if len(weight_value.shape) == 3: + rng = np.random.randint(0, 7393) + kernel_shape = [1] + g_node.get_attr('kernel_shape', AT.LIST_INT) + dilations = g_node.get_attr('dilations', AT.LIST_INT) * 2 + pads = g_node.get_attr('pads', AT.LIST_INT) + if pads == [0, 0]: + pads = [0, 0, 0, 0] + if pads == [1, 1]: + pads = [0, 1, 0, 1] + strides = g_node.get_attr('strides', AT.LIST_INT) * 2 + g_node.set_attr({"kernel_shape": (AT.LIST_INT, kernel_shape)}) + g_node.set_attr({"dilations": (AT.LIST_INT, dilations)}) + g_node.set_attr({"pads": (AT.LIST_INT, pads)}) + g_node.set_attr({"strides": (AT.LIST_INT, strides)}) + new_weight_node = mod.add_const_node(f"const_weight_{rng}", np.expand_dims(weight_value, axis=2)) + mod.node_replace(weight_node, new_weight_node) + + g_node = mod.get_node("MaxPool_13") + rng = np.random.randint(0, 7393) + kernel_shape = [1] + g_node.get_attr('kernel_shape', AT.LIST_INT) + pads = g_node.get_attr('pads', AT.LIST_INT) * 2 + strides = g_node.get_attr('strides', AT.LIST_INT) * 2 + g_node.set_attr({"kernel_shape": (AT.LIST_INT, kernel_shape), + "dilations": (AT.LIST_INT, dilations), + "pads": (AT.LIST_INT, pads), + "strides": (AT.LIST_INT, strides)}) + + # NCHW -> NCD + res_node = mod.get_node('MaxPool_13') + squeeze_node = mod.add_new_node(f"Squeeze_{np.random.randint(0, 7393)}", "Squeeze", + {"axes": (AT.LIST_INT, [2])}) + squeeze_node.set_input_node(0, [res_node]) + after_res_node = mod.get_node(io_map.get(res_node.name)[0]) + after_res_node.set_input_node(0, [squeeze_node]) + + # NCD -> NCHW + g_nodes = mod.get_nodes_by_optype("Conv") + for g_node in g_nodes: + if g_node.name != "Conv_11" and mod.get_node(g_node.input_name[0]).op_type != "LeakyRelu": + rng = np.random.randint(0, 7393) + unsqueeze_node = mod.add_new_node(f"Unsqueeze_{rng}", "Unsqueeze", + {"axes": (AT.LIST_INT, [2])}) + + before_g_node = mod.get_node(g_node.input_name[0]) + w_node = mod.get_node(g_node.input_name[1]) + if len(g_node.input_name) == 2: + g_node.set_input_node(0, [unsqueeze_node, w_node]) + else: + b_node = mod.get_node(g_node.input_name[2]) + g_node.set_input_node(0, [unsqueeze_node, w_node, b_node]) + unsqueeze_node.set_input_node(0, [before_g_node]) + + # NCHW -> NCD + g_nodes = mod.get_nodes_by_optype("Add") + for g_node in g_nodes: + Add_b0 = mod.get_node(g_node.input_name[0]) + Add_b1 = mod.get_node(g_node.input_name[1]) + if mod.get_node(Add_b0.input_name[0]).op_type == "LeakyRelu": + rng = np.random.randint(0, 7393) + if Add_b1.op_type != "Conv": + unsqueeze_node = mod.add_new_node(f"Unsqueeze_{rng}", "Unsqueeze", + {"axes": (AT.LIST_INT, [2])}) + g_node.set_input_node(0, [unsqueeze_node, Add_b0]) + unsqueeze_node.set_input_node(0, [Add_b1]) + + squeeze_node = mod.add_new_node(f"Squeeze_{rng}", "Squeeze", + {"axes": (AT.LIST_INT, [2])}) + squeeze_node.set_input_node(0, [g_node]) + after_g_node = mod.get_node(io_map.get(g_node.name)[0]) + after_g_node.set_input_node(0, [squeeze_node]) + + +def make_model(input_onnx, output_onnx): + mod = OXGraph(input_onnx) + io_map = mod.get_net_in_out_map() + + # solve accuracy problem + gather_nodes = mod.get_nodes_by_optype("Gather") + for g_node in gather_nodes: + if g_node.name == 'Gather_203': + indices_node = mod.add_const_node(f'Const_{g_node.input_name[1]}', np.array(28).astype('int64')) + g_node.set_input_node(1, [indices_node]) + + # NCD -> NCHW + shape_dim_extend(mod, io_map) + + # conv split + conv_node = mod.get_node("Conv_11") + weight_node = mod.get_node(conv_node.input_name[1]) + weight_value = weight_node.const_value + + np.random.seed(1737) + KSZ = weight_value.shape[-1] + CHK_SZ = 128 + CHK_N = KSZ // CHK_SZ + wgt = [] + for i in range(CHK_N): + wgt.append(weight_value[:, :, :, CHK_SZ * i:CHK_SZ * (i + 1)]) + if KSZ % CHK_SZ != 0: + wgt.append(weight_value[:, :, :, CHK_SZ * CHK_N:]) + + rwn_node = [] + for i, w in enumerate(wgt): + node = make_conv2d_split_node(mod, conv_node, w, i, CHK_SZ, KSZ) + rwn_node.append(node) + + in_node_list = copy.deepcopy(rwn_node[:CHK_N]) + out_node_list = [] + combin_len = CHK_N + while len(in_node_list) > 1: + for j in range(0, combin_len, 2): + add_node = mod.add_new_node(f"Add_{np.random.randint(0, 7393)}", "Add") + add_node.set_input_node(0, [in_node_list[j], in_node_list[j + 1]]) + out_node_list.append(add_node) + in_node_list = copy.deepcopy(out_node_list) + out_node_list.clear() + combin_len //= 2 + + # add all result + if KSZ % CHK_SZ != 0: + add_node = mod.add_new_node(f"Add_{np.random.randint(0, 7393)}", "Add") + add_node.set_input_node(0, [in_node_list[0], rwn_node[-1]]) + else: + add_node = in_node_list[0] + + # relink + after_node = mod.get_node(io_map.get(conv_node.name)[0]) + after_node.set_input_node(0, [add_node]) + + # remove ori node + mod.node_remove([conv_node.name]) + mod.save_new_model(output_onnx) + + +def get_parser(): + parser = argparse.ArgumentParser(description='RawNet2') + parser.add_argument('--input_onnx', default=None, type=str, + help='input original onnx') + parser.add_argument('--output_onnx', default=None, type=str, + help='output modified onnx') + return parser + + +if __name__ == "__main__": + ''' + Example: + python3.7 modify_onnx.py \ + --input_onnx=rawnet2_sim.onnx \ + --output_onnx=rawnet2_modify.onnx + ''' + parser = get_parser() + args = parser.parse_args() + make_model(args.input_onnx, args.output_onnx) + print("modify successfully!") diff --git a/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/om_infer.py b/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/om_infer.py index 97e3258ff56020b18fc6d3bcc4b2607606789455..0857fbc63018a98d722241be65f4b312f76d7678 100644 --- a/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/om_infer.py +++ b/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/om_infer.py @@ -1,162 +1,162 @@ -# Copyright 2018 NVIDIA Corporation. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import argparse -import time -import math -import numpy as np -from tqdm import tqdm -import librosa -import torch -import torch.nn.functional as F -from torch import Tensor -from torch.utils.data import Dataset -from torch.utils.data import DataLoader -from acl_net import Net - - -def genSpoof_list(dir_meta): - d_meta = {} - file_list = [] - with open(dir_meta, 'r') as f: - l_meta = f.readlines() - - for line in l_meta: - key = line.strip().split(' ')[1] - file_list.append(key) - return file_list - - -def pad(x, max_len=64600): - x_len = x.shape[0] - if x_len >= max_len: - return x[:max_len] - # need to pad - num_repeats = int(max_len / x_len) + 1 - padded_x = np.tile(x, (1, num_repeats))[:, :max_len][0] - return padded_x - - -class Dataset_ASVspoof2019_eval(Dataset): - def __init__(self, list_IDs, base_dir): - '''self.list_IDs : list of strings (each string: utt key)''' - - self.list_IDs = list_IDs - self.base_dir = base_dir - - def __len__(self): - return len(self.list_IDs) - - def __getitem__(self, index): - self.cut = 64600 # take ~4 sec audio (64600 samples) - key = self.list_IDs[index] - X, fs = librosa.load(self.base_dir + 'flac/' + key + '.flac', sr=16000) - X_pad = pad(X, self.cut) - x_inp = Tensor(X_pad) - return x_inp, key - - -def get_parser(): - parser = argparse.ArgumentParser(description='RawNet2') - parser.add_argument('--batch_size', type=int, default=128, - help='batch size') - parser.add_argument('--device_id', type=int, default=1, - help='device id') - parser.add_argument('--om_path', type=str, default="rawnet2.om", - help='path to the om model') - parser.add_argument('--eval_output', type=str, default=None, - help='Path to save the evaluation result') - parser.add_argument('--database_path', type=str, default='/your/path/to/data/ASVspoof_database/', - help='Change this to user\'s full directory address of LA database.') - ''' - % database_path/ - % |- ASVspoof2021_LA_eval/flac - % |- ASVspoof2019_LA_train/flac - % |- ASVspoof2019_LA_dev/flac - ''' - parser.add_argument('--protocols_path', type=str, default='/your/path/to/protocols/ASVspoof_database/', - help='Change with path to user\'s LA database protocols directory address') - ''' - % protocols_path/ - % |- ASVspoof_LA_cm_protocols - % |- ASVspoof2021.LA.cm.eval.trl.txt - % |- ASVspoof2019.LA.cm.dev.trl.txt - % |- ASVspoof2019.LA.cm.train.trn.txt - ''' - return parser - - -if __name__ == "__main__": - ''' - Example: - python3.7 om_infer.py \ - --batch_size=1 \ - --om_path=rawnet2_modify.om \ - --eval_output='rawnet2_modify_om.txt' \ - --database_path='data/LA/' \ - --protocols_path='data/LA/' - ''' - parser = get_parser() - args = parser.parse_args() - - # Load dataset - protocal_dir = os.path.join(args.protocols_path + 'ASVspoof2019_LA_cm_protocols/ASVspoof2019.LA.cm.eval.trl.txt') - file_eval = genSpoof_list(protocal_dir) - database_dir = os.path.join(args.database_path + 'ASVspoof2019_LA_eval/') - eval_set = Dataset_ASVspoof2019_eval(list_IDs=file_eval, base_dir=database_dir) - eval_loader = DataLoader(eval_set, batch_size=args.batch_size, shuffle=False, drop_last=False) - - model = Net(device_id=args.device_id, model_path=args.om_path) - - # Evaluation for RawNet2 om model - with open(args.eval_output, 'w+') as fh: - for idx, (batch_x, utt_id) in tqdm(enumerate(eval_loader)): - fname_list = [] - score_list = [] - n, d = batch_x.shape - if n != args.batch_size: - m = (0, 0, 0, args.batch_size - n) - batch_x = F.pad(batch_x, m, 'constant', 0) - batch_x = batch_x.numpy().astype(np.float32) - batch_out = model(batch_x) - batch_out = torch.from_numpy(np.array(batch_out).astype(np.float32)) - batch_score = (batch_out[:, :, 1]).data.cpu().numpy().ravel() - - # add outputs - if len(batch_score) != len(utt_id): - batch_score = batch_score[:len(utt_id)] - fname_list.extend(utt_id) - score_list.extend(batch_score.tolist()) - - for f, cm in zip(fname_list, score_list): - fh.write('{} {}\n'.format(f, cm)) - print('Scores saved to {}'.format(args.eval_output)) - +# Copyright 2018 NVIDIA Corporation. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import argparse +import time +import math +import numpy as np +from tqdm import tqdm +import librosa +import torch +import torch.nn.functional as F +from torch import Tensor +from torch.utils.data import Dataset +from torch.utils.data import DataLoader +from acl_net import Net + + +def genSpoof_list(dir_meta): + d_meta = {} + file_list = [] + with open(dir_meta, 'r') as f: + l_meta = f.readlines() + + for line in l_meta: + key = line.strip().split(' ')[1] + file_list.append(key) + return file_list + + +def pad(x, max_len=64600): + x_len = x.shape[0] + if x_len >= max_len: + return x[:max_len] + # need to pad + num_repeats = int(max_len / x_len) + 1 + padded_x = np.tile(x, (1, num_repeats))[:, :max_len][0] + return padded_x + + +class Dataset_ASVspoof2019_eval(Dataset): + def __init__(self, list_IDs, base_dir): + '''self.list_IDs : list of strings (each string: utt key)''' + + self.list_IDs = list_IDs + self.base_dir = base_dir + + def __len__(self): + return len(self.list_IDs) + + def __getitem__(self, index): + self.cut = 64600 # take ~4 sec audio (64600 samples) + key = self.list_IDs[index] + X, fs = librosa.load(self.base_dir + 'flac/' + key + '.flac', sr=16000) + X_pad = pad(X, self.cut) + x_inp = Tensor(X_pad) + return x_inp, key + + +def get_parser(): + parser = argparse.ArgumentParser(description='RawNet2') + parser.add_argument('--batch_size', type=int, default=128, + help='batch size') + parser.add_argument('--device_id', type=int, default=1, + help='device id') + parser.add_argument('--om_path', type=str, default="rawnet2.om", + help='path to the om model') + parser.add_argument('--eval_output', type=str, default=None, + help='Path to save the evaluation result') + parser.add_argument('--database_path', type=str, default='/your/path/to/data/ASVspoof_database/', + help='Change this to user\'s full directory address of LA database.') + ''' + % database_path/ + % |- ASVspoof2021_LA_eval/flac + % |- ASVspoof2019_LA_train/flac + % |- ASVspoof2019_LA_dev/flac + ''' + parser.add_argument('--protocols_path', type=str, default='/your/path/to/protocols/ASVspoof_database/', + help='Change with path to user\'s LA database protocols directory address') + ''' + % protocols_path/ + % |- ASVspoof_LA_cm_protocols + % |- ASVspoof2021.LA.cm.eval.trl.txt + % |- ASVspoof2019.LA.cm.dev.trl.txt + % |- ASVspoof2019.LA.cm.train.trn.txt + ''' + return parser + + +if __name__ == "__main__": + ''' + Example: + python3.7 om_infer.py \ + --batch_size=1 \ + --om_path=rawnet2_modify.om \ + --eval_output='rawnet2_modify_om.txt' \ + --database_path='data/LA/' \ + --protocols_path='data/LA/' + ''' + parser = get_parser() + args = parser.parse_args() + + # Load dataset + protocal_dir = os.path.join(args.protocols_path + 'ASVspoof2019_LA_cm_protocols/ASVspoof2019.LA.cm.eval.trl.txt') + file_eval = genSpoof_list(protocal_dir) + database_dir = os.path.join(args.database_path + 'ASVspoof2019_LA_eval/') + eval_set = Dataset_ASVspoof2019_eval(list_IDs=file_eval, base_dir=database_dir) + eval_loader = DataLoader(eval_set, batch_size=args.batch_size, shuffle=False, drop_last=False) + + model = Net(device_id=args.device_id, model_path=args.om_path) + + # Evaluation for RawNet2 om model + with open(args.eval_output, 'w+') as fh: + for idx, (batch_x, utt_id) in tqdm(enumerate(eval_loader)): + fname_list = [] + score_list = [] + n, d = batch_x.shape + if n != args.batch_size: + m = (0, 0, 0, args.batch_size - n) + batch_x = F.pad(batch_x, m, 'constant', 0) + batch_x = batch_x.numpy().astype(np.float32) + batch_out = model(batch_x) + batch_out = torch.from_numpy(np.array(batch_out).astype(np.float32)) + batch_score = (batch_out[:, :, 1]).data.cpu().numpy().ravel() + + # add outputs + if len(batch_score) != len(utt_id): + batch_score = batch_score[:len(utt_id)] + fname_list.extend(utt_id) + score_list.extend(batch_score.tolist()) + + for f, cm in zip(fname_list, score_list): + fh.write('{} {}\n'.format(f, cm)) + print('Scores saved to {}'.format(args.eval_output)) + del model \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/pth2onnx.py b/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/pth2onnx.py index df6b221b5809fa822ac5073b7d43cc003bb6f220..297f2dcf12feb0ccbc26e8692d4be2b92e677cd2 100644 --- a/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/pth2onnx.py +++ b/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch/pth2onnx.py @@ -1,69 +1,69 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import os -import argparse -import yaml -import torch -import onnx -import torch.onnx -from model import RawNet - - -def convert(pth_model, onnx_model, batch_size): - dir_yaml = os.path.splitext('model_config_RawNet')[0] + '.yaml' - with open(dir_yaml, 'r') as f_yaml: - parser1 = yaml.load(f_yaml) - model = RawNet(parser1['model'], 'cpu') - checkpoint = torch.load(pth_model, map_location='cpu') - model.load_state_dict(checkpoint) - model.eval() - - input_names = ["input"] - output_names = ["output"] - dummy_input = torch.randn(int(batch_size), 64600) - print('\nStarting ONNX export with onnx %s...' % onnx.__version__) - torch.onnx.export(model, dummy_input, onnx_model, - input_names=input_names, output_names=output_names, - opset_version=11, - dynamic_axes=None, - export_params=True, - verbose=True, - do_constant_folding=True) - - -def get_parser(): - parser = argparse.ArgumentParser(description='RawNet2') - parser.add_argument('--pth_model', default=None, type=str, - help='Path to pytorch model') - parser.add_argument('--onnx_model', default=None, type=str, - help='Path to onnx model') - parser.add_argument('--batch_size', default=1, type=int, - help='Data batch size') - return parser - - -if __name__ == "__main__": - ''' - Example: - python3.7 pth2onnx.py \ - --pth_model=pre_trained_DF_RawNet2.pth \ - --onnx_model=rawnet2_ori.onnx \ - --batch_size=1 - ''' - parser = get_parser() - args = parser.parse_args() - convert(args.pth_model, args.onnx_model, args.batch_size) - print('pytorch to onnx successfully!') +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import os +import argparse +import yaml +import torch +import onnx +import torch.onnx +from model import RawNet + + +def convert(pth_model, onnx_model, batch_size): + dir_yaml = os.path.splitext('model_config_RawNet')[0] + '.yaml' + with open(dir_yaml, 'r') as f_yaml: + parser1 = yaml.load(f_yaml) + model = RawNet(parser1['model'], 'cpu') + checkpoint = torch.load(pth_model, map_location='cpu') + model.load_state_dict(checkpoint) + model.eval() + + input_names = ["input"] + output_names = ["output"] + dummy_input = torch.randn(int(batch_size), 64600) + print('\nStarting ONNX export with onnx %s...' % onnx.__version__) + torch.onnx.export(model, dummy_input, onnx_model, + input_names=input_names, output_names=output_names, + opset_version=11, + dynamic_axes=None, + export_params=True, + verbose=True, + do_constant_folding=True) + + +def get_parser(): + parser = argparse.ArgumentParser(description='RawNet2') + parser.add_argument('--pth_model', default=None, type=str, + help='Path to pytorch model') + parser.add_argument('--onnx_model', default=None, type=str, + help='Path to onnx model') + parser.add_argument('--batch_size', default=1, type=int, + help='Data batch size') + return parser + + +if __name__ == "__main__": + ''' + Example: + python3.7 pth2onnx.py \ + --pth_model=pre_trained_DF_RawNet2.pth \ + --onnx_model=rawnet2_ori.onnx \ + --batch_size=1 + ''' + parser = get_parser() + args = parser.parse_args() + convert(args.pth_model, args.onnx_model, args.batch_size) + print('pytorch to onnx successfully!') diff --git a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/LICENSE b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/LICENSE index 4ba4fdcab3dbdb4d64ce4cccdfd990698b4d596a..a0e03103591c1158a839681f3c404ee9118b182e 100644 --- a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/LICENSE +++ b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/LICENSE @@ -1,29 +1,29 @@ -BSD 3-Clause License - -Copyright (c) 2017, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +BSD 3-Clause License + +Copyright (c) 2017, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/ReadMe.md b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/ReadMe.md index 4ea7fca8b3b280b392827ae443e4193f3a0f22cc..d961290140ed39e2d0f350d430b8410af699591a 100644 --- a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/ReadMe.md +++ b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/ReadMe.md @@ -1,59 +1,59 @@ -# TDNN模型pytorch离线推理指导 - -## 1 环境准备 - -1.获取,修改与安装开源模型代码 - -```shell -git clone https://github.com/speechbrain/speechbrain.git -cd speechbrain -git checkout develop -git reset --hard 51a2becdcf3a337578a9307a0b2fc3906bf20391 -export PYTHONPATH=`pwd`:$PYTHONPATH -cd .. -git clone https://gitee.com/Ronnie_zheng/MagicONNX.git -cd MagicONNX && git checkout 8d62ae9dde478f35bece4b3d04eef573448411c9 -pip install . -``` -将源码包中文件放入speechbrain/templates/speaker_id中 -```shell -cd speechbrain -git apply --reject --whitespace=fix templates/speaker_id/modify.patch -``` - -2.获取权重文件 - -https://www.hiascend.com/zh/software/modelzoo/detail/1/f4f4103245624c1a8637f8a5eadd950c -将模型权重文件夹best_model放入speechbrain/templates/speaker_id下,将hyperparams.yaml文件放入best_model中 - -3.获取数据集 - -预处理阶段自动下载 -```shell -python3 tdnn_preprocess.py -``` - -## 2 模型转换 -```shell -# 生成tdnn_bs64.onnx -python3 tdnn_pth2onnx.py 64 -# 优化onnx模型 -python3 -m onnxsim tdnn_bs64.onnx tdnn_bs64s.onnx -python3 modify_onnx.py tdnn_bs64s.onnx -# 生成om模型 -bash atc.sh tdnn_bs64s.onnx -``` - -## 3 离线推理 - -```shell -bash om_infer.sh 64 -python3 tdnn_postprocess.py -``` -**评测结果:** - -由于TensorRT不支持原模型,故只能对比修改后的模型性能。 -| 模型 | pth精度 | 710离线推理精度 | 基准性能 | 710性能 | -| :------: | :------: | :------: | :------: | :------: | -| TDNN bs64 | 99.93% | 99.93% | - | 2467fps | +# TDNN模型pytorch离线推理指导 + +## 1 环境准备 + +1.获取,修改与安装开源模型代码 + +```shell +git clone https://github.com/speechbrain/speechbrain.git +cd speechbrain +git checkout develop +git reset --hard 51a2becdcf3a337578a9307a0b2fc3906bf20391 +export PYTHONPATH=`pwd`:$PYTHONPATH +cd .. +git clone https://gitee.com/Ronnie_zheng/MagicONNX.git +cd MagicONNX && git checkout 8d62ae9dde478f35bece4b3d04eef573448411c9 +pip install . +``` +将源码包中文件放入speechbrain/templates/speaker_id中 +```shell +cd speechbrain +git apply --reject --whitespace=fix templates/speaker_id/modify.patch +``` + +2.获取权重文件 + +https://www.hiascend.com/zh/software/modelzoo/detail/1/f4f4103245624c1a8637f8a5eadd950c +将模型权重文件夹best_model放入speechbrain/templates/speaker_id下,将hyperparams.yaml文件放入best_model中 + +3.获取数据集 + +预处理阶段自动下载 +```shell +python3 tdnn_preprocess.py +``` + +## 2 模型转换 +```shell +# 生成tdnn_bs64.onnx +python3 tdnn_pth2onnx.py 64 +# 优化onnx模型 +python3 -m onnxsim tdnn_bs64.onnx tdnn_bs64s.onnx +python3 modify_onnx.py tdnn_bs64s.onnx +# 生成om模型 +bash atc.sh tdnn_bs64s.onnx +``` + +## 3 离线推理 + +```shell +bash om_infer.sh 64 +python3 tdnn_postprocess.py +``` +**评测结果:** + +由于TensorRT不支持原模型,故只能对比修改后的模型性能。 +| 模型 | pth精度 | 710离线推理精度 | 基准性能 | 710性能 | +| :------: | :------: | :------: | :------: | :------: | +| TDNN bs64 | 99.93% | 99.93% | - | 2467fps | | TDNN修改 bs64 | - | - | 2345.179 fps | 3815.886fps | \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/mo.py b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/mo.py index cad5851dcb001b21baaa792a87cb8fd18a9d4c89..0b4dee7f3b3c5eb6fe85fb03c032ee7484634553 100644 --- a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/mo.py +++ b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/mo.py @@ -1,32 +1,32 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys - -from magiconnx import OnnxGraph - -bs = sys.argv[1] -model_name = 'tdnn_bs%s'%bs -graph = OnnxGraph(model_name+'.onnx') -ph = graph.add_placeholder('random','float32',[64,1500]) - -rm = graph.get_nodes("ReduceMin")[0] -rm.inputs = ['random'] -sub = graph.get_nodes("Sub")[-1] -sub.inputs = ['random', rm.outputs[0]] - -rn = graph.get_nodes("RandomNormalLike")[0] -graph.del_node(rn.name, auto_connection=False) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys + +from magiconnx import OnnxGraph + +bs = sys.argv[1] +model_name = 'tdnn_bs%s'%bs +graph = OnnxGraph(model_name+'.onnx') +ph = graph.add_placeholder('random','float32',[64,1500]) + +rm = graph.get_nodes("ReduceMin")[0] +rm.inputs = ['random'] +sub = graph.get_nodes("Sub")[-1] +sub.inputs = ['random', rm.outputs[0]] + +rn = graph.get_nodes("RandomNormalLike")[0] +graph.del_node(rn.name, auto_connection=False) + graph.save('%s_mod.onnx'%model_name) \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/modelzoo_level.txt b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/modelzoo_level.txt +++ b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/modify.patch b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/modify.patch index d246c604253e17f74eadc96273b359b43f78eff1..ce78514dbd877b2af710a5fc41ba865d21b84d83 100644 --- a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/modify.patch +++ b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/modify.patch @@ -260,11 +260,11 @@ index c22add8..7a777df 100644 --- a/templates/speaker_id/mini_librispeech_prepare.py +++ b/templates/speaker_id/mini_librispeech_prepare.py @@ -171,7 +171,7 @@ def split_sets(wav_list, split_ratio): - dictionary containing train, valid, and test splits. - """ - # Random shuffle of the list -- random.shuffle(wav_list) -+ # random.shuffle(wav_list) - tot_split = sum(split_ratio) - tot_snts = len(wav_list) - data_split = {} + dictionary containing train, valid, and test splits. + """ + # Random shuffle of the list +- random.shuffle(wav_list) ++ # random.shuffle(wav_list) + tot_split = sum(split_ratio) + tot_snts = len(wav_list) + data_split = {} diff --git a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/modify_onnx.py b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/modify_onnx.py index ab8273817c401d35e61b736d66809b57365641d8..3939324a1dd5a9b237a5da0c1eddd5397e61e1b2 100644 --- a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/modify_onnx.py +++ b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/modify_onnx.py @@ -1,51 +1,51 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys - -import numpy as np -import onnx - -from magiconnx import OnnxGraph - -model_name = sys.argv[1] -graph = OnnxGraph(model_name) - -axes = onnx.helper.make_attribute("axes", [0,1]) -rd_min = graph.get_nodes("ReduceMin")[0] -rd_min._node.attribute.append(axes) -rd_max = graph.get_nodes("ReduceMax")[0] -rd_max._node.attribute.append(axes) - -us = graph.add_node('Unsq_1', 'Unsqueeze', {'axes': [2]}) -graph.insert_node(graph.get_nodes("Conv")[0].name, us, mode='before') -sq = graph.add_node('Sq_291', 'Squeeze', {'axes': [2]}) -graph.insert_node(graph.get_nodes('BatchNormalization')[4].name, sq, mode='after') - -convs = graph.get_nodes("Conv") -for conv in convs: - print(conv.name) - dil = conv['dilations'][0] - ks = conv['kernel_shape'][0] - pds = conv['pads'][0] - stri = conv['strides'][0] - conv['dilations'] = [1, dil] - conv['kernel_shape'] = [1, ks] - conv['pads'] = [0, pds, 0, pds] - conv['strides'] = [1, stri] - conv_w = graph[conv.inputs[1]].value - conv_w = np.expand_dims(conv_w, axis=-2) - graph[conv.inputs[1]].value = conv_w - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys + +import numpy as np +import onnx + +from magiconnx import OnnxGraph + +model_name = sys.argv[1] +graph = OnnxGraph(model_name) + +axes = onnx.helper.make_attribute("axes", [0,1]) +rd_min = graph.get_nodes("ReduceMin")[0] +rd_min._node.attribute.append(axes) +rd_max = graph.get_nodes("ReduceMax")[0] +rd_max._node.attribute.append(axes) + +us = graph.add_node('Unsq_1', 'Unsqueeze', {'axes': [2]}) +graph.insert_node(graph.get_nodes("Conv")[0].name, us, mode='before') +sq = graph.add_node('Sq_291', 'Squeeze', {'axes': [2]}) +graph.insert_node(graph.get_nodes('BatchNormalization')[4].name, sq, mode='after') + +convs = graph.get_nodes("Conv") +for conv in convs: + print(conv.name) + dil = conv['dilations'][0] + ks = conv['kernel_shape'][0] + pds = conv['pads'][0] + stri = conv['strides'][0] + conv['dilations'] = [1, dil] + conv['kernel_shape'] = [1, ks] + conv['pads'] = [0, pds, 0, pds] + conv['strides'] = [1, stri] + conv_w = graph[conv.inputs[1]].value + conv_w = np.expand_dims(conv_w, axis=-2) + graph[conv.inputs[1]].value = conv_w + graph.save(model_name) \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/requirements.txt b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/requirements.txt index 561b93c4e71366123f8b5988b9379a59bda13edc..aafb425ee5371a22665b371f6e7ef21fceb3b19d 100644 --- a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/requirements.txt +++ b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/requirements.txt @@ -1,8 +1,8 @@ -onnx==1.10.2 -torch==1.10.0 -torchaudio==0.10.2 -tqdm==4.63.0 -HyperPyYAML==1.0.0 -huggingface-hub==0.4.0 - - +onnx==1.10.2 +torch==1.10.0 +torchaudio==0.10.2 +tqdm==4.63.0 +HyperPyYAML==1.0.0 +huggingface-hub==0.4.0 + + diff --git a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_postprocess.py b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_postprocess.py index c04619873410ca49ce6ff8e75d31947718e54f85..cb0b04f187f7ee237e267f26d614b8a62314fa60 100644 --- a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_postprocess.py +++ b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_postprocess.py @@ -1,53 +1,53 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import re -import argparse -import numpy as np -label = {0:'163', 1:'7367', 2:'332', 3:'1970', 4:'4640', 5:'8629', 6:'6848', 7:'1088', 8:'460', 9:'6272', 10:'7312', 11:'2136', 12:'1867', 13:'669', 14:'3526', 15:'3664', 16:'3242', 17:'19', 18:'32', 19:'5789', 20:'118', 21:'226', 22:'7859', 23:'3947', 24:'1898', 25:'2416', 26:'1737', 27:'4680'} - -if __name__ == '__main__': - ''' - 参数说明: - --data_info: 数据集信息 - --result_dir: 二进制推理结果目录 - ''' - - # arg parser - parser = argparse.ArgumentParser() - parser.add_argument('--data_info', default='mini_librispeech_test.info') - parser.add_argument('--result_dir', default='result') - - opt = parser.parse_args() - error = 0 - total = 0 - - with open('mini_librispeech_test.info', 'r') as f: - for line in f.readlines(): - # line format example - # 0 mini_librispeech_test_bin/4680-16042-0024.bin (1,1600,23) - split = line.split(' ') - index = split[0] - input_file = split[1] - target = re.search('/(\d*)-', input_file).group()[1:-1] - output_file = opt.result_dir + '/' + index + '.0.bin' - output = np.fromfile(output_file, np.float32) - res = np.argmax(output) - print('Predicted:', label[res], 'Target:', target) - total += 1 - if label[res] != target: - error += 1 - accuracy = (total - error) / total * 100 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import re +import argparse +import numpy as np +label = {0:'163', 1:'7367', 2:'332', 3:'1970', 4:'4640', 5:'8629', 6:'6848', 7:'1088', 8:'460', 9:'6272', 10:'7312', 11:'2136', 12:'1867', 13:'669', 14:'3526', 15:'3664', 16:'3242', 17:'19', 18:'32', 19:'5789', 20:'118', 21:'226', 22:'7859', 23:'3947', 24:'1898', 25:'2416', 26:'1737', 27:'4680'} + +if __name__ == '__main__': + ''' + 参数说明: + --data_info: 数据集信息 + --result_dir: 二进制推理结果目录 + ''' + + # arg parser + parser = argparse.ArgumentParser() + parser.add_argument('--data_info', default='mini_librispeech_test.info') + parser.add_argument('--result_dir', default='result') + + opt = parser.parse_args() + error = 0 + total = 0 + + with open('mini_librispeech_test.info', 'r') as f: + for line in f.readlines(): + # line format example + # 0 mini_librispeech_test_bin/4680-16042-0024.bin (1,1600,23) + split = line.split(' ') + index = split[0] + input_file = split[1] + target = re.search('/(\d*)-', input_file).group()[1:-1] + output_file = opt.result_dir + '/' + index + '.0.bin' + output = np.fromfile(output_file, np.float32) + res = np.argmax(output) + print('Predicted:', label[res], 'Target:', target) + total += 1 + if label[res] != target: + error += 1 + accuracy = (total - error) / total * 100 print('\nClassification Accuracy: {:.2f}%\n'.format(accuracy)) \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_preprocess.py b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_preprocess.py index dcaa76a0e84e9ad2a27781d71f371cbd4b478d57..855ec5fa537a458e96f77d43a7915a34283a0655 100644 --- a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_preprocess.py +++ b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_preprocess.py @@ -1,52 +1,52 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import json -import torchaudio -import torch.nn.functional as F -from speechbrain.pretrained import EncoderClassifier -from mini_librispeech_prepare import prepare_mini_librispeech - -prepare_mini_librispeech(data_folder='data', save_json_train='train.json', save_json_valid='valid.json', - save_json_test='test.json', split_ratio=[0, 0, 100]) - -if not os.path.exists('mini_librispeech_test_bin'): - os.makedirs('mini_librispeech_test_bin') - -file = open('mini_librispeech_test.info', 'w') -classifier = EncoderClassifier.from_hparams(source='best_model', savedir='best_model') - -with open('test.json', 'r') as f: - data_info = json.load(f) - i = 0 - - for key, value in data_info.items(): - wav_file = 'data' + value['wav'][11:] # prefix length 11 - signal, fs = torchaudio.load(wav_file) - feats = classifier.extract_feats(signal) - # pad signal - pad = (feats.shape[1] // 100 + 1) * 100 - feats.shape[1] - feats = F.pad(feats, (0,0,0,pad,0,0), value=0) - - # dump bin file - output = 'mini_librispeech_test_bin/' + value['wav'].split('/')[-1][:-4] + 'bin' - feats.numpy().tofile(output) - # write shape info - file.write(str(i) + ' ' + output + ' (' + str(feats.shape[0]) + ',' + str(feats.shape[1]) + ',' + str(feats.shape[2]) + ')') - file.write('\n') - i += 1 - - print('data preprocess done') +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import json +import torchaudio +import torch.nn.functional as F +from speechbrain.pretrained import EncoderClassifier +from mini_librispeech_prepare import prepare_mini_librispeech + +prepare_mini_librispeech(data_folder='data', save_json_train='train.json', save_json_valid='valid.json', + save_json_test='test.json', split_ratio=[0, 0, 100]) + +if not os.path.exists('mini_librispeech_test_bin'): + os.makedirs('mini_librispeech_test_bin') + +file = open('mini_librispeech_test.info', 'w') +classifier = EncoderClassifier.from_hparams(source='best_model', savedir='best_model') + +with open('test.json', 'r') as f: + data_info = json.load(f) + i = 0 + + for key, value in data_info.items(): + wav_file = 'data' + value['wav'][11:] # prefix length 11 + signal, fs = torchaudio.load(wav_file) + feats = classifier.extract_feats(signal) + # pad signal + pad = (feats.shape[1] // 100 + 1) * 100 - feats.shape[1] + feats = F.pad(feats, (0,0,0,pad,0,0), value=0) + + # dump bin file + output = 'mini_librispeech_test_bin/' + value['wav'].split('/')[-1][:-4] + 'bin' + feats.numpy().tofile(output) + # write shape info + file.write(str(i) + ' ' + output + ' (' + str(feats.shape[0]) + ',' + str(feats.shape[1]) + ',' + str(feats.shape[2]) + ')') + file.write('\n') + i += 1 + + print('data preprocess done') file.close() \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_pth2onnx.py b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_pth2onnx.py index 2e830e2802450284ea025f6263c500ee60f3ecc2..b93409b45328267ea2a193869ec0bad93bd9ec67 100644 --- a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_pth2onnx.py +++ b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_pth2onnx.py @@ -1,47 +1,47 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys - -import torch -import torchaudio -from speechbrain.pretrained import EncoderClassifier - -classifier = EncoderClassifier.from_hparams(source='best_model', savedir='best_model') - -# Download Thai language sample from Omniglot -class Xvector(torch.nn.Module): - def __init__(self, model): - super().__init__() - self.classifier = model - - def forward(self, feats): - res = self.classifier.feats_classify(feats) - return res - -model = Xvector(classifier) -batch_size=int(sys.argv[1]) -feats = torch.randn([batch_size, 1800, 23]) - -torch.onnx.export( - model, - feats, - 'tdnn_bs%d.onnx'%(batch_size), - input_names=['feats'], - output_names=['output'], - export_params=True, - do_constant_folding=True, - verbose=True, - opset_version=11 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys + +import torch +import torchaudio +from speechbrain.pretrained import EncoderClassifier + +classifier = EncoderClassifier.from_hparams(source='best_model', savedir='best_model') + +# Download Thai language sample from Omniglot +class Xvector(torch.nn.Module): + def __init__(self, model): + super().__init__() + self.classifier = model + + def forward(self, feats): + res = self.classifier.feats_classify(feats) + return res + +model = Xvector(classifier) +batch_size=int(sys.argv[1]) +feats = torch.randn([batch_size, 1800, 23]) + +torch.onnx.export( + model, + feats, + 'tdnn_bs%d.onnx'%(batch_size), + input_names=['feats'], + output_names=['output'], + export_params=True, + do_constant_folding=True, + verbose=True, + opset_version=11 ) \ No newline at end of file diff --git a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_pyacl_infer.py b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_pyacl_infer.py index 87967a5d26605f765d8ab99093101f2263a764a1..6b7a783b2ef2db3ede0f688edf129708502cb502 100644 --- a/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_pyacl_infer.py +++ b/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch/tdnn_pyacl_infer.py @@ -1,201 +1,201 @@ -# Copyright 2018 NVIDIA Corporation. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import acl -from acl_net import AclModel - -import os -import shutil -import argparse -import numpy as np -from tqdm import tqdm - -DTYPE = { - 'float32': np.float32, - 'float64': np.float64, - 'int32': np.int32, - 'int64': np.int64 -} - -if __name__ == '__main__': - ''' - 参数说明: - --model_path:模型路径 - --device_id:npu id - --cpu_run:MeasureTime类的cpu_run参数,True or False - --sync_infer:推理方式: - True:同步推理 - False:异步推理 - --workspace:类似TensorRT `workspace`参数,计算平均推理时间时排除前n次推理 - --input_info_file_path:类似benchmark的bin_info文件 - --input_dtypes:模型输入的类型,用逗号分割(`DTYPE`变量) - e.g. 模型只有一个输入:--input_dtypes=float32 - e.g. 模型有多个输入:--input_dtypes=float32,float32,float32(需要和bin_info文件多输入排列一致) - --infer_res_save_path:推理结果保存目录 - --res_save_type:推理结果保存类型,bin或npy - - info文件说明: - 因为支持动态shape,相比于benchmark的info文件,需要多加一列shape信息,e.g. - ``` - 0 ./bert_bin/input_ids_0.bin (1,512) - 0 ./bert_bin/segment_ids_0.bin (1,512) - 0 ./bert_bin/input_mask_0.bin (1,512) - 1 ./bert_bin/input_ids_1.bin (1,512) - 1 ./bert_bin/segment_ids_1.bin (1,512) - 1 ./bert_bin/input_mask_1.bin (1,512) - ``` - - Using Example: - python3.7 pyacl_infer.py \ - --model_path=./bert_base_batch_1_sim_auto.om \ - --device_id=0 \ - --cpu_run=True \ - --sync_infer=True \ - --workspace=10 \ - --input_info_file_path=./input.info \ - --input_dtypes=int64,int64,int64 \ - --infer_res_save_path=./infer_res \ - --res_save_type=bin - ''' - - # 参数解析 - parser = argparse.ArgumentParser() - parser.add_argument('--model_path', required=True) - parser.add_argument('--batch_size', required=True) - parser.add_argument('--device_id', required=True, type=int) - parser.add_argument('--cpu_run', required=True, choices=['True', 'False']) - parser.add_argument('--sync_infer', required=True, choices=['True', 'False']) - parser.add_argument('--workspace', required=True, type=int) - parser.add_argument('--input_info_file_path', required=True) - parser.add_argument('--input_dtypes', required=True) - parser.add_argument('--infer_res_save_path', required=True) - parser.add_argument('--res_save_type', required=True, choices=['bin', 'npy']) - opt = parser.parse_args() - - # 创建模型 - measurements = {} - om_model = AclModel(device_id=opt.device_id, - model_path=opt.model_path, - sync_infer=eval(opt.sync_infer), - measurements=measurements, - key='per_infer_time_ns', - cpu_run=eval(opt.cpu_run)) - - # 创建目录 - if os.path.exists(opt.infer_res_save_path): - shutil.rmtree(opt.infer_res_save_path) - os.makedirs(opt.infer_res_save_path) - - # 读取info_file - inputs_info = {} - with open(opt.input_info_file_path, 'rt', encoding='utf-8') as f_info: - line = f_info.readline() - while line: - line = line.rstrip('\n') - contents = line.split() - info = {'path': contents[1], 'shape': eval(contents[2])} - inputs_info.setdefault(contents[0], []).append(info) - line = f_info.readline() - - # 解析输入类型 - input_dtypes = opt.input_dtypes.split(',') - input_dtypes = list(map(lambda x: DTYPE[x], input_dtypes)) - - # 读取文件推理 - total_infer_time = 0 - total_infer_time_workspace = 0 - total_infer_num = 0 - dataset = {} - dims_infos = {} - bs = int(opt.batch_size) - for key, values in inputs_info.items(): - # 构造输入 - inputs = [] - dims = [] - for idx, value in enumerate(values): - x = np.fromfile(value['path'], dtype=input_dtypes[idx]).reshape(value['shape']) - inputs.append((key,x)) - dims.extend((bs, value['shape'][1], value['shape'][2])) - dims_info = {'dimCount': len(dims), 'name': '', 'dims': dims} - - # (1, 1500, 23) {'dimCount': 3, 'name': '', 'dims': [1, 1500, 23]} - length = inputs[0][1].shape[1] - dataset[length] = dataset.get(length,[]) + inputs - dims_infos[length] = dims_infos.get(length,dims_info) - - total_inputs = [] - total_keys = [] - for k in sorted(dataset.keys()): - total_len = len(dataset[k]) - batch_input = [] - batch_key = [] - for i, (key, ipt) in enumerate(dataset[k]): - batch_input.append(ipt) - batch_key.append(key) - if (i+1) % bs == 0: - total_inputs.append(batch_input) - total_keys.append(batch_key) - batch_input = [] - batch_key = [] - if batch_input != []: - total_inputs.append(batch_input) - total_keys.append(batch_key) - - for i, b_ipt in tqdm(enumerate(total_inputs)): - batch_input = np.squeeze(np.array(b_ipt), axis=1) - if batch_input.shape[0] < bs: - batch_input = np.pad(batch_input, [(0, bs-batch_input.shape[0]), (0, 0), (0, 0)], mode='constant') - - # 推理得到输出 - # (bs, 28) - output = om_model([batch_input], dims_infos[batch_input.shape[1]]) - - total_infer_num += 1 - - # 保存文件 - for j, key in enumerate(total_keys[i]): - if opt.res_save_type == 'bin': - output[0][j].tofile(os.path.join(opt.infer_res_save_path, key + '.' + str(0) + '.bin')) - else: - np.save(os.path.join(opt.infer_res_save_path, key + '.' + str(0) + '.npy'), output[0][j]) - - # 计算时间 - total_infer_time += measurements['per_infer_time_ns'] - if total_infer_num > opt.workspace: - total_infer_time_workspace += measurements['per_infer_time_ns'] - - # 推理时间 - print('[INFO] Infer time:') - msg = 'total infer num: ' + str(total_infer_num) + '\n' + \ - 'total pure infer time(ms): ' + str(total_infer_time / 1000 / 1000) + '\n' + \ - 'average pure infer time(ms): ' + str(total_infer_time / total_infer_num / 1000 / 1000) + '\n' + \ - 'average pure infer time after workspace(ms): ' + str(abs( - total_infer_time_workspace / (total_infer_num - opt.workspace) / 1000 / 1000)) + '\n' - print(msg) - with open(os.path.join(opt.infer_res_save_path, 'infer_time.txt'), 'wt', encoding='utf-8') as f_infer_time: +# Copyright 2018 NVIDIA Corporation. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import acl +from acl_net import AclModel + +import os +import shutil +import argparse +import numpy as np +from tqdm import tqdm + +DTYPE = { + 'float32': np.float32, + 'float64': np.float64, + 'int32': np.int32, + 'int64': np.int64 +} + +if __name__ == '__main__': + ''' + 参数说明: + --model_path:模型路径 + --device_id:npu id + --cpu_run:MeasureTime类的cpu_run参数,True or False + --sync_infer:推理方式: + True:同步推理 + False:异步推理 + --workspace:类似TensorRT `workspace`参数,计算平均推理时间时排除前n次推理 + --input_info_file_path:类似benchmark的bin_info文件 + --input_dtypes:模型输入的类型,用逗号分割(`DTYPE`变量) + e.g. 模型只有一个输入:--input_dtypes=float32 + e.g. 模型有多个输入:--input_dtypes=float32,float32,float32(需要和bin_info文件多输入排列一致) + --infer_res_save_path:推理结果保存目录 + --res_save_type:推理结果保存类型,bin或npy + + info文件说明: + 因为支持动态shape,相比于benchmark的info文件,需要多加一列shape信息,e.g. + ``` + 0 ./bert_bin/input_ids_0.bin (1,512) + 0 ./bert_bin/segment_ids_0.bin (1,512) + 0 ./bert_bin/input_mask_0.bin (1,512) + 1 ./bert_bin/input_ids_1.bin (1,512) + 1 ./bert_bin/segment_ids_1.bin (1,512) + 1 ./bert_bin/input_mask_1.bin (1,512) + ``` + + Using Example: + python3.7 pyacl_infer.py \ + --model_path=./bert_base_batch_1_sim_auto.om \ + --device_id=0 \ + --cpu_run=True \ + --sync_infer=True \ + --workspace=10 \ + --input_info_file_path=./input.info \ + --input_dtypes=int64,int64,int64 \ + --infer_res_save_path=./infer_res \ + --res_save_type=bin + ''' + + # 参数解析 + parser = argparse.ArgumentParser() + parser.add_argument('--model_path', required=True) + parser.add_argument('--batch_size', required=True) + parser.add_argument('--device_id', required=True, type=int) + parser.add_argument('--cpu_run', required=True, choices=['True', 'False']) + parser.add_argument('--sync_infer', required=True, choices=['True', 'False']) + parser.add_argument('--workspace', required=True, type=int) + parser.add_argument('--input_info_file_path', required=True) + parser.add_argument('--input_dtypes', required=True) + parser.add_argument('--infer_res_save_path', required=True) + parser.add_argument('--res_save_type', required=True, choices=['bin', 'npy']) + opt = parser.parse_args() + + # 创建模型 + measurements = {} + om_model = AclModel(device_id=opt.device_id, + model_path=opt.model_path, + sync_infer=eval(opt.sync_infer), + measurements=measurements, + key='per_infer_time_ns', + cpu_run=eval(opt.cpu_run)) + + # 创建目录 + if os.path.exists(opt.infer_res_save_path): + shutil.rmtree(opt.infer_res_save_path) + os.makedirs(opt.infer_res_save_path) + + # 读取info_file + inputs_info = {} + with open(opt.input_info_file_path, 'rt', encoding='utf-8') as f_info: + line = f_info.readline() + while line: + line = line.rstrip('\n') + contents = line.split() + info = {'path': contents[1], 'shape': eval(contents[2])} + inputs_info.setdefault(contents[0], []).append(info) + line = f_info.readline() + + # 解析输入类型 + input_dtypes = opt.input_dtypes.split(',') + input_dtypes = list(map(lambda x: DTYPE[x], input_dtypes)) + + # 读取文件推理 + total_infer_time = 0 + total_infer_time_workspace = 0 + total_infer_num = 0 + dataset = {} + dims_infos = {} + bs = int(opt.batch_size) + for key, values in inputs_info.items(): + # 构造输入 + inputs = [] + dims = [] + for idx, value in enumerate(values): + x = np.fromfile(value['path'], dtype=input_dtypes[idx]).reshape(value['shape']) + inputs.append((key,x)) + dims.extend((bs, value['shape'][1], value['shape'][2])) + dims_info = {'dimCount': len(dims), 'name': '', 'dims': dims} + + # (1, 1500, 23) {'dimCount': 3, 'name': '', 'dims': [1, 1500, 23]} + length = inputs[0][1].shape[1] + dataset[length] = dataset.get(length,[]) + inputs + dims_infos[length] = dims_infos.get(length,dims_info) + + total_inputs = [] + total_keys = [] + for k in sorted(dataset.keys()): + total_len = len(dataset[k]) + batch_input = [] + batch_key = [] + for i, (key, ipt) in enumerate(dataset[k]): + batch_input.append(ipt) + batch_key.append(key) + if (i+1) % bs == 0: + total_inputs.append(batch_input) + total_keys.append(batch_key) + batch_input = [] + batch_key = [] + if batch_input != []: + total_inputs.append(batch_input) + total_keys.append(batch_key) + + for i, b_ipt in tqdm(enumerate(total_inputs)): + batch_input = np.squeeze(np.array(b_ipt), axis=1) + if batch_input.shape[0] < bs: + batch_input = np.pad(batch_input, [(0, bs-batch_input.shape[0]), (0, 0), (0, 0)], mode='constant') + + # 推理得到输出 + # (bs, 28) + output = om_model([batch_input], dims_infos[batch_input.shape[1]]) + + total_infer_num += 1 + + # 保存文件 + for j, key in enumerate(total_keys[i]): + if opt.res_save_type == 'bin': + output[0][j].tofile(os.path.join(opt.infer_res_save_path, key + '.' + str(0) + '.bin')) + else: + np.save(os.path.join(opt.infer_res_save_path, key + '.' + str(0) + '.npy'), output[0][j]) + + # 计算时间 + total_infer_time += measurements['per_infer_time_ns'] + if total_infer_num > opt.workspace: + total_infer_time_workspace += measurements['per_infer_time_ns'] + + # 推理时间 + print('[INFO] Infer time:') + msg = 'total infer num: ' + str(total_infer_num) + '\n' + \ + 'total pure infer time(ms): ' + str(total_infer_time / 1000 / 1000) + '\n' + \ + 'average pure infer time(ms): ' + str(total_infer_time / total_infer_num / 1000 / 1000) + '\n' + \ + 'average pure infer time after workspace(ms): ' + str(abs( + total_infer_time_workspace / (total_infer_num - opt.workspace) / 1000 / 1000)) + '\n' + print(msg) + with open(os.path.join(opt.infer_res_save_path, 'infer_time.txt'), 'wt', encoding='utf-8') as f_infer_time: f_infer_time.write(msg) \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/ReadMe.md b/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/ReadMe.md index e42fd69be299f535fe5c0ecd169c4e3d647a7497..cae1ac9e4b9f273ee42fe4b4cd1c76ffde81694e 100644 --- a/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/ReadMe.md +++ b/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/ReadMe.md @@ -1,37 +1,37 @@ -文件作用说明: - -- Pth转换om脚本,pth转换om脚本 -- ATC转换脚本atc_crnn.sh -- benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer -- ONNX模型lstm算子修改脚本lstm_revise.py -- 测试数据集生成脚本parse_testdata.py -- 推理后处理脚本postpossess_CRNN_pytorch.py -- ReadMe.md -- - -推理端到端步骤: - -(1) 使用脚本pth2onnx.py将pth文件导出为onnx文件 - - - -(2)运行atc_crnn.sh脚本转换om模型 - -本demo已提供调优完成的om模型 - - - -(3)用parse_testdata.py脚本处理数据集 - - - -(4)./benchmark.x86_64 -model_type=vision -batch_size=16 -device_id=0 -input_text_path=./crnn.info -input_width=100 -input_height=32 -om_path=./crnn_sim.om -useDvpp=False - -运行benchmark推理,结果保存在 ./result 目录下 - - - -(5)python3.7 postpossess_CRNN_pytorch.py - -验证推理结果 - +文件作用说明: + +- Pth转换om脚本,pth转换om脚本 +- ATC转换脚本atc_crnn.sh +- benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer +- ONNX模型lstm算子修改脚本lstm_revise.py +- 测试数据集生成脚本parse_testdata.py +- 推理后处理脚本postpossess_CRNN_pytorch.py +- ReadMe.md +- + +推理端到端步骤: + +(1) 使用脚本pth2onnx.py将pth文件导出为onnx文件 + + + +(2)运行atc_crnn.sh脚本转换om模型 + +本demo已提供调优完成的om模型 + + + +(3)用parse_testdata.py脚本处理数据集 + + + +(4)./benchmark.x86_64 -model_type=vision -batch_size=16 -device_id=0 -input_text_path=./crnn.info -input_width=100 -input_height=32 -om_path=./crnn_sim.om -useDvpp=False + +运行benchmark推理,结果保存在 ./result 目录下 + + + +(5)python3.7 postpossess_CRNN_pytorch.py + +验证推理结果 + diff --git a/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/lstm_revise.py b/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/lstm_revise.py index e68e93fc7e61d54481cba0a0aa859360260cfce9..8e91400188b3a56877bcc352693b8cc771209a66 100644 --- a/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/lstm_revise.py +++ b/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/lstm_revise.py @@ -1,286 +1,286 @@ -import os -import numpy as np -import torch -import onnx -import copy -from onnx import numpy_helper -G_ONNX_OPSET_VER = 11 -''' -def onnx_LSTM(batch, seq_len, input_size, hidden_size, num_layers, bidirectional, work_dir): - mod = torch.nn.LSTM(input_size, hidden_size, num_layers,bidirectional=bidirectional) - input = torch.randn(seq_len, batch, input_size)#(seq_len, batch, input_size) - h0 = torch.randn(2, 3, 20) - c0 = torch.randn(2, 3, 20) - print(mod.weight_ih_l0.size()) - print(mod.bias_hh_l0.size()) - print(mod.bias_ih_l0.size()) - output, _ = mod(input) - onnx_name = os.path.join(work_dir, "LSTM.onnx") - torch.onnx.export(mod, (input), f=onnx_name, - opset_version=G_ONNX_OPSET_VER) - return output -''' - -def GetNodeIndex(graph, node_name): - index = 0 - for i in range(len(graph.node)): - if graph.node[i].name == node_name: - index = i - break - return index - -def modify1(src_path,save_path): - model = onnx.load(src_path) - new_model = onnx.ModelProto() - for init in model.graph.initializer: - if init.name == "441": #95 - tmp1 = numpy_helper.to_array(init) - if init.name == "442": #96 - tmp2 = numpy_helper.to_array(init) - if init.name == "443": #97 - tmp3 = numpy_helper.to_array(init) - remove_weight = [] - for init in model.graph.initializer: - if init.name == "442": #96 - remove_weight.append(init) - if init.name == "441": #95 - remove_weight.append(init) - if init.name == "443": #97 - remove_weight.append(init) - for i in remove_weight: - model.graph.initializer.remove(i) - tmp = np.concatenate((tmp1,tmp2),axis=-1) - tmp_shape = tmp.shape - tmp = tmp.reshape(4,tmp_shape[-2]//4,tmp_shape[-1]).tolist() - #print(tmp[0]) - weight = np.array(tmp[0] + tmp[3] + tmp[2] + tmp[1]).reshape(tmp_shape[-2],tmp_shape[-1]).transpose(1,0) - init_tmp = numpy_helper.from_array(weight.astype(np.float32),name="441") #95 - model.graph.initializer.append(init_tmp) - bais_shape = [tmp3.shape[-1]] - tmp3 = tmp3.reshape(2,4,bais_shape[-1]//8).tolist() - bais1 = np.array(tmp3[0][0] + tmp3[0][3] + tmp3[0][2] + tmp3[0][1]).reshape(bais_shape[-1]//2) - bais2 = np.array(tmp3[1][0] + tmp3[1][3] + tmp3[1][2] + tmp3[1][1]).reshape(bais_shape[-1]//2) - bais = bais1 + bais2 - init_bais = numpy_helper.from_array(bais.astype(np.float32),name="443") #97 - model.graph.initializer.append(init_bais) - for idx,node in enumerate(model.graph.node): - if node.name == "LSTM_29": - print(model.graph.node[idx].input) - #model.graph.node[idx].input[1] = '' - #model.graph.node[idx].input[2] = '' - model.graph.node[idx].input.remove('442') #96 - model.graph.node[idx].input.remove('82') #14 - model.graph.node[idx].input.remove('82') #14 - model.graph.node[idx].input.remove('') #'' - model.graph.node[idx].input[1] = '441' #95 - model.graph.node[idx].input[2] = '443' #97 - #model.graph.node[idx].input[3] = '87' - - #去除Squeeze - remove_list = [] - for idx,node in enumerate(model.graph.node): - if node.name in {"Shape_23", "Gather_25", "Unsqueeze_26","Concat_27","ConstantOfShape_28","Constant_24","Squeeze_30"}: - remove_list.append(node) - - for node in remove_list: - model.graph.node.remove(node) - - - - model.graph.node[GetNodeIndex(model.graph,'Concat_49')].input[0] = '140' - onnx.save(model,save_path) - - -def modify2(src_path,save_path): - model = onnx.load(src_path) - new_model = onnx.ModelProto() - for init in model.graph.initializer: - if init.name == "463": #95 - tmp1 = numpy_helper.to_array(init) - if init.name == "464": #96 - tmp2 = numpy_helper.to_array(init) - if init.name == "465": #97 - tmp3 = numpy_helper.to_array(init) - remove_weight = [] - for init in model.graph.initializer: - if init.name == "464": #96 - remove_weight.append(init) - if init.name == "463": #95 - remove_weight.append(init) - if init.name == "465": #97 - remove_weight.append(init) - for i in remove_weight: - model.graph.initializer.remove(i) - tmp = np.concatenate((tmp1,tmp2),axis=-1) - tmp_shape = tmp.shape - tmp = tmp.reshape(4,tmp_shape[-2]//4,tmp_shape[-1]).tolist() - #print(tmp[0]) - weight = np.array(tmp[0] + tmp[3] + tmp[2] + tmp[1]).reshape(tmp_shape[-2],tmp_shape[-1]).transpose(1,0) - init_tmp = numpy_helper.from_array(weight.astype(np.float32),name="463") #95 - model.graph.initializer.append(init_tmp) - bais_shape = [tmp3.shape[-1]] - tmp3 = tmp3.reshape(2,4,bais_shape[-1]//8).tolist() - bais1 = np.array(tmp3[0][0] + tmp3[0][3] + tmp3[0][2] + tmp3[0][1]).reshape(bais_shape[-1]//2) - bais2 = np.array(tmp3[1][0] + tmp3[1][3] + tmp3[1][2] + tmp3[1][1]).reshape(bais_shape[-1]//2) - bais = bais1 + bais2 - init_bais = numpy_helper.from_array(bais.astype(np.float32),name="465") #97 - model.graph.initializer.append(init_bais) - for idx,node in enumerate(model.graph.node): - if node.name == "LSTM_42": - print(model.graph.node[idx].input) - #model.graph.node[idx].input[1] = '' - #model.graph.node[idx].input[2] = '' - model.graph.node[idx].input.remove('464') #96 - model.graph.node[idx].input.remove('158') #14 - model.graph.node[idx].input.remove('158') #14 - model.graph.node[idx].input.remove('') #'' - model.graph.node[idx].input[1] = '463' #95 - model.graph.node[idx].input[2] = '465' #97 - #model.graph.node[idx].input[3] = '87' - - remove_list = [] - for idx,node in enumerate(model.graph.node): - if node.name in {"Shape_36", "Gather_38", "Unsqueeze_39","Concat_40","ConstantOfShape_41","Constant_37","Squeeze_43"}: - remove_list.append(node) - - for node in remove_list: - model.graph.node.remove(node) - - model.graph.node[GetNodeIndex(model.graph,'Slice_48')].input[0] = '216' - - onnx.save(model,save_path) - -def modify3(src_path,save_path): - model = onnx.load(src_path) - new_model = onnx.ModelProto() - for init in model.graph.initializer: - if init.name == "486": #95 - tmp1 = numpy_helper.to_array(init) - if init.name == "487": #96 - tmp2 = numpy_helper.to_array(init) - if init.name == "488": #97 - tmp3 = numpy_helper.to_array(init) - remove_weight = [] - for init in model.graph.initializer: - if init.name == "487": #96 - remove_weight.append(init) - if init.name == "486": #95 - remove_weight.append(init) - if init.name == "488": #97 - remove_weight.append(init) - for i in remove_weight: - model.graph.initializer.remove(i) - tmp = np.concatenate((tmp1,tmp2),axis=-1) - tmp_shape = tmp.shape - tmp = tmp.reshape(4,tmp_shape[-2]//4,tmp_shape[-1]).tolist() - #print(tmp[0]) - weight = np.array(tmp[0] + tmp[3] + tmp[2] + tmp[1]).reshape(tmp_shape[-2],tmp_shape[-1]).transpose(1,0) - init_tmp = numpy_helper.from_array(weight.astype(np.float32),name="486") #95 - model.graph.initializer.append(init_tmp) - bais_shape = [tmp3.shape[-1]] - tmp3 = tmp3.reshape(2,4,bais_shape[-1]//8).tolist() - bais1 = np.array(tmp3[0][0] + tmp3[0][3] + tmp3[0][2] + tmp3[0][1]).reshape(bais_shape[-1]//2) - bais2 = np.array(tmp3[1][0] + tmp3[1][3] + tmp3[1][2] + tmp3[1][1]).reshape(bais_shape[-1]//2) - bais = bais1 + bais2 - init_bais = numpy_helper.from_array(bais.astype(np.float32),name="488") #97 - model.graph.initializer.append(init_bais) - for idx,node in enumerate(model.graph.node): - if node.name == "LSTM_75": - print(model.graph.node[idx].input) - #model.graph.node[idx].input[1] = '' - #model.graph.node[idx].input[2] = '' - model.graph.node[idx].input.remove('487') #96 - model.graph.node[idx].input.remove('256') #14 - model.graph.node[idx].input.remove('256') #14 - model.graph.node[idx].input.remove('') #'' - model.graph.node[idx].input[1] = '486' #95 - model.graph.node[idx].input[2] = '488' #97 - #model.graph.node[idx].input[3] = '87' - - remove_list = [] - for idx,node in enumerate(model.graph.node): - if node.name in {"Shape_69", "Gather_71", "Unsqueeze_72","Concat_73","ConstantOfShape_74","Constant_70","Squeeze_76"}: - remove_list.append(node) - - for node in remove_list: - model.graph.node.remove(node) - - model.graph.node[GetNodeIndex(model.graph,'Concat_95')].input[0] = '314' - - - onnx.save(model,save_path) - -def modify4(src_path,save_path): - model = onnx.load(src_path) - new_model = onnx.ModelProto() - for init in model.graph.initializer: - if init.name == "508": #95 - tmp1 = numpy_helper.to_array(init) - if init.name == "509": #96 - tmp2 = numpy_helper.to_array(init) - if init.name == "510": #97 - tmp3 = numpy_helper.to_array(init) - remove_weight = [] - for init in model.graph.initializer: - if init.name == "509": #96 - remove_weight.append(init) - if init.name == "508": #95 - remove_weight.append(init) - if init.name == "510": #97 - remove_weight.append(init) - for i in remove_weight: - model.graph.initializer.remove(i) - tmp = np.concatenate((tmp1,tmp2),axis=-1) - tmp_shape = tmp.shape - tmp = tmp.reshape(4,tmp_shape[-2]//4,tmp_shape[-1]).tolist() - #print(tmp[0]) - weight = np.array(tmp[0] + tmp[3] + tmp[2] + tmp[1]).reshape(tmp_shape[-2],tmp_shape[-1]).transpose(1,0) - init_tmp = numpy_helper.from_array(weight.astype(np.float32),name="508") #95 - model.graph.initializer.append(init_tmp) - bais_shape = [tmp3.shape[-1]] - tmp3 = tmp3.reshape(2,4,bais_shape[-1]//8).tolist() - bais1 = np.array(tmp3[0][0] + tmp3[0][3] + tmp3[0][2] + tmp3[0][1]).reshape(bais_shape[-1]//2) - bais2 = np.array(tmp3[1][0] + tmp3[1][3] + tmp3[1][2] + tmp3[1][1]).reshape(bais_shape[-1]//2) - bais = bais1 + bais2 - init_bais = numpy_helper.from_array(bais.astype(np.float32),name="510") #97 - model.graph.initializer.append(init_bais) - for idx,node in enumerate(model.graph.node): - if node.name == "LSTM_88": - print(model.graph.node[idx].input) - #model.graph.node[idx].input[1] = '' - #model.graph.node[idx].input[2] = '' - model.graph.node[idx].input.remove('509') #96 - model.graph.node[idx].input.remove('332') #14 - model.graph.node[idx].input.remove('332') #14 - model.graph.node[idx].input.remove('') #'' - model.graph.node[idx].input[1] = '508' #95 - model.graph.node[idx].input[2] = '510' #97 - #model.graph.node[idx].input[3] = '87' - - remove_list = [] - for idx,node in enumerate(model.graph.node): - if node.name in {"Shape_82", "Gather_84", "Unsqueeze_85","Concat_86","ConstantOfShape_87","Constant_83","Squeeze_89"}: - remove_list.append(node) - - for node in remove_list: - model.graph.node.remove(node) - model.graph.node[GetNodeIndex(model.graph,'Slice_94')].input[0] = '390' - - onnx.save(model,save_path) - -if __name__ == "__main__": - work_dir = "./" - batch = 1 - seq_len = 10 - input_size = 50 - hidden_size = 32 - num_layers = 1 - #onnx_LSTM(batch, seq_len, input_size, hidden_size, num_layers, False, work_dir) - modify1("./crnn_sim.onnx","./1.onnx") - modify2("./1.onnx","./2.onnx") - modify3("./2.onnx","./3.onnx") - modify4("./3.onnx","./crnn_revised.onnx") - os.remove("1.onnx") - os.remove("2.onnx") - os.remove("3.onnx") - print('Done') +import os +import numpy as np +import torch +import onnx +import copy +from onnx import numpy_helper +G_ONNX_OPSET_VER = 11 +''' +def onnx_LSTM(batch, seq_len, input_size, hidden_size, num_layers, bidirectional, work_dir): + mod = torch.nn.LSTM(input_size, hidden_size, num_layers,bidirectional=bidirectional) + input = torch.randn(seq_len, batch, input_size)#(seq_len, batch, input_size) + h0 = torch.randn(2, 3, 20) + c0 = torch.randn(2, 3, 20) + print(mod.weight_ih_l0.size()) + print(mod.bias_hh_l0.size()) + print(mod.bias_ih_l0.size()) + output, _ = mod(input) + onnx_name = os.path.join(work_dir, "LSTM.onnx") + torch.onnx.export(mod, (input), f=onnx_name, + opset_version=G_ONNX_OPSET_VER) + return output +''' + +def GetNodeIndex(graph, node_name): + index = 0 + for i in range(len(graph.node)): + if graph.node[i].name == node_name: + index = i + break + return index + +def modify1(src_path,save_path): + model = onnx.load(src_path) + new_model = onnx.ModelProto() + for init in model.graph.initializer: + if init.name == "441": #95 + tmp1 = numpy_helper.to_array(init) + if init.name == "442": #96 + tmp2 = numpy_helper.to_array(init) + if init.name == "443": #97 + tmp3 = numpy_helper.to_array(init) + remove_weight = [] + for init in model.graph.initializer: + if init.name == "442": #96 + remove_weight.append(init) + if init.name == "441": #95 + remove_weight.append(init) + if init.name == "443": #97 + remove_weight.append(init) + for i in remove_weight: + model.graph.initializer.remove(i) + tmp = np.concatenate((tmp1,tmp2),axis=-1) + tmp_shape = tmp.shape + tmp = tmp.reshape(4,tmp_shape[-2]//4,tmp_shape[-1]).tolist() + #print(tmp[0]) + weight = np.array(tmp[0] + tmp[3] + tmp[2] + tmp[1]).reshape(tmp_shape[-2],tmp_shape[-1]).transpose(1,0) + init_tmp = numpy_helper.from_array(weight.astype(np.float32),name="441") #95 + model.graph.initializer.append(init_tmp) + bais_shape = [tmp3.shape[-1]] + tmp3 = tmp3.reshape(2,4,bais_shape[-1]//8).tolist() + bais1 = np.array(tmp3[0][0] + tmp3[0][3] + tmp3[0][2] + tmp3[0][1]).reshape(bais_shape[-1]//2) + bais2 = np.array(tmp3[1][0] + tmp3[1][3] + tmp3[1][2] + tmp3[1][1]).reshape(bais_shape[-1]//2) + bais = bais1 + bais2 + init_bais = numpy_helper.from_array(bais.astype(np.float32),name="443") #97 + model.graph.initializer.append(init_bais) + for idx,node in enumerate(model.graph.node): + if node.name == "LSTM_29": + print(model.graph.node[idx].input) + #model.graph.node[idx].input[1] = '' + #model.graph.node[idx].input[2] = '' + model.graph.node[idx].input.remove('442') #96 + model.graph.node[idx].input.remove('82') #14 + model.graph.node[idx].input.remove('82') #14 + model.graph.node[idx].input.remove('') #'' + model.graph.node[idx].input[1] = '441' #95 + model.graph.node[idx].input[2] = '443' #97 + #model.graph.node[idx].input[3] = '87' + + #去除Squeeze + remove_list = [] + for idx,node in enumerate(model.graph.node): + if node.name in {"Shape_23", "Gather_25", "Unsqueeze_26","Concat_27","ConstantOfShape_28","Constant_24","Squeeze_30"}: + remove_list.append(node) + + for node in remove_list: + model.graph.node.remove(node) + + + + model.graph.node[GetNodeIndex(model.graph,'Concat_49')].input[0] = '140' + onnx.save(model,save_path) + + +def modify2(src_path,save_path): + model = onnx.load(src_path) + new_model = onnx.ModelProto() + for init in model.graph.initializer: + if init.name == "463": #95 + tmp1 = numpy_helper.to_array(init) + if init.name == "464": #96 + tmp2 = numpy_helper.to_array(init) + if init.name == "465": #97 + tmp3 = numpy_helper.to_array(init) + remove_weight = [] + for init in model.graph.initializer: + if init.name == "464": #96 + remove_weight.append(init) + if init.name == "463": #95 + remove_weight.append(init) + if init.name == "465": #97 + remove_weight.append(init) + for i in remove_weight: + model.graph.initializer.remove(i) + tmp = np.concatenate((tmp1,tmp2),axis=-1) + tmp_shape = tmp.shape + tmp = tmp.reshape(4,tmp_shape[-2]//4,tmp_shape[-1]).tolist() + #print(tmp[0]) + weight = np.array(tmp[0] + tmp[3] + tmp[2] + tmp[1]).reshape(tmp_shape[-2],tmp_shape[-1]).transpose(1,0) + init_tmp = numpy_helper.from_array(weight.astype(np.float32),name="463") #95 + model.graph.initializer.append(init_tmp) + bais_shape = [tmp3.shape[-1]] + tmp3 = tmp3.reshape(2,4,bais_shape[-1]//8).tolist() + bais1 = np.array(tmp3[0][0] + tmp3[0][3] + tmp3[0][2] + tmp3[0][1]).reshape(bais_shape[-1]//2) + bais2 = np.array(tmp3[1][0] + tmp3[1][3] + tmp3[1][2] + tmp3[1][1]).reshape(bais_shape[-1]//2) + bais = bais1 + bais2 + init_bais = numpy_helper.from_array(bais.astype(np.float32),name="465") #97 + model.graph.initializer.append(init_bais) + for idx,node in enumerate(model.graph.node): + if node.name == "LSTM_42": + print(model.graph.node[idx].input) + #model.graph.node[idx].input[1] = '' + #model.graph.node[idx].input[2] = '' + model.graph.node[idx].input.remove('464') #96 + model.graph.node[idx].input.remove('158') #14 + model.graph.node[idx].input.remove('158') #14 + model.graph.node[idx].input.remove('') #'' + model.graph.node[idx].input[1] = '463' #95 + model.graph.node[idx].input[2] = '465' #97 + #model.graph.node[idx].input[3] = '87' + + remove_list = [] + for idx,node in enumerate(model.graph.node): + if node.name in {"Shape_36", "Gather_38", "Unsqueeze_39","Concat_40","ConstantOfShape_41","Constant_37","Squeeze_43"}: + remove_list.append(node) + + for node in remove_list: + model.graph.node.remove(node) + + model.graph.node[GetNodeIndex(model.graph,'Slice_48')].input[0] = '216' + + onnx.save(model,save_path) + +def modify3(src_path,save_path): + model = onnx.load(src_path) + new_model = onnx.ModelProto() + for init in model.graph.initializer: + if init.name == "486": #95 + tmp1 = numpy_helper.to_array(init) + if init.name == "487": #96 + tmp2 = numpy_helper.to_array(init) + if init.name == "488": #97 + tmp3 = numpy_helper.to_array(init) + remove_weight = [] + for init in model.graph.initializer: + if init.name == "487": #96 + remove_weight.append(init) + if init.name == "486": #95 + remove_weight.append(init) + if init.name == "488": #97 + remove_weight.append(init) + for i in remove_weight: + model.graph.initializer.remove(i) + tmp = np.concatenate((tmp1,tmp2),axis=-1) + tmp_shape = tmp.shape + tmp = tmp.reshape(4,tmp_shape[-2]//4,tmp_shape[-1]).tolist() + #print(tmp[0]) + weight = np.array(tmp[0] + tmp[3] + tmp[2] + tmp[1]).reshape(tmp_shape[-2],tmp_shape[-1]).transpose(1,0) + init_tmp = numpy_helper.from_array(weight.astype(np.float32),name="486") #95 + model.graph.initializer.append(init_tmp) + bais_shape = [tmp3.shape[-1]] + tmp3 = tmp3.reshape(2,4,bais_shape[-1]//8).tolist() + bais1 = np.array(tmp3[0][0] + tmp3[0][3] + tmp3[0][2] + tmp3[0][1]).reshape(bais_shape[-1]//2) + bais2 = np.array(tmp3[1][0] + tmp3[1][3] + tmp3[1][2] + tmp3[1][1]).reshape(bais_shape[-1]//2) + bais = bais1 + bais2 + init_bais = numpy_helper.from_array(bais.astype(np.float32),name="488") #97 + model.graph.initializer.append(init_bais) + for idx,node in enumerate(model.graph.node): + if node.name == "LSTM_75": + print(model.graph.node[idx].input) + #model.graph.node[idx].input[1] = '' + #model.graph.node[idx].input[2] = '' + model.graph.node[idx].input.remove('487') #96 + model.graph.node[idx].input.remove('256') #14 + model.graph.node[idx].input.remove('256') #14 + model.graph.node[idx].input.remove('') #'' + model.graph.node[idx].input[1] = '486' #95 + model.graph.node[idx].input[2] = '488' #97 + #model.graph.node[idx].input[3] = '87' + + remove_list = [] + for idx,node in enumerate(model.graph.node): + if node.name in {"Shape_69", "Gather_71", "Unsqueeze_72","Concat_73","ConstantOfShape_74","Constant_70","Squeeze_76"}: + remove_list.append(node) + + for node in remove_list: + model.graph.node.remove(node) + + model.graph.node[GetNodeIndex(model.graph,'Concat_95')].input[0] = '314' + + + onnx.save(model,save_path) + +def modify4(src_path,save_path): + model = onnx.load(src_path) + new_model = onnx.ModelProto() + for init in model.graph.initializer: + if init.name == "508": #95 + tmp1 = numpy_helper.to_array(init) + if init.name == "509": #96 + tmp2 = numpy_helper.to_array(init) + if init.name == "510": #97 + tmp3 = numpy_helper.to_array(init) + remove_weight = [] + for init in model.graph.initializer: + if init.name == "509": #96 + remove_weight.append(init) + if init.name == "508": #95 + remove_weight.append(init) + if init.name == "510": #97 + remove_weight.append(init) + for i in remove_weight: + model.graph.initializer.remove(i) + tmp = np.concatenate((tmp1,tmp2),axis=-1) + tmp_shape = tmp.shape + tmp = tmp.reshape(4,tmp_shape[-2]//4,tmp_shape[-1]).tolist() + #print(tmp[0]) + weight = np.array(tmp[0] + tmp[3] + tmp[2] + tmp[1]).reshape(tmp_shape[-2],tmp_shape[-1]).transpose(1,0) + init_tmp = numpy_helper.from_array(weight.astype(np.float32),name="508") #95 + model.graph.initializer.append(init_tmp) + bais_shape = [tmp3.shape[-1]] + tmp3 = tmp3.reshape(2,4,bais_shape[-1]//8).tolist() + bais1 = np.array(tmp3[0][0] + tmp3[0][3] + tmp3[0][2] + tmp3[0][1]).reshape(bais_shape[-1]//2) + bais2 = np.array(tmp3[1][0] + tmp3[1][3] + tmp3[1][2] + tmp3[1][1]).reshape(bais_shape[-1]//2) + bais = bais1 + bais2 + init_bais = numpy_helper.from_array(bais.astype(np.float32),name="510") #97 + model.graph.initializer.append(init_bais) + for idx,node in enumerate(model.graph.node): + if node.name == "LSTM_88": + print(model.graph.node[idx].input) + #model.graph.node[idx].input[1] = '' + #model.graph.node[idx].input[2] = '' + model.graph.node[idx].input.remove('509') #96 + model.graph.node[idx].input.remove('332') #14 + model.graph.node[idx].input.remove('332') #14 + model.graph.node[idx].input.remove('') #'' + model.graph.node[idx].input[1] = '508' #95 + model.graph.node[idx].input[2] = '510' #97 + #model.graph.node[idx].input[3] = '87' + + remove_list = [] + for idx,node in enumerate(model.graph.node): + if node.name in {"Shape_82", "Gather_84", "Unsqueeze_85","Concat_86","ConstantOfShape_87","Constant_83","Squeeze_89"}: + remove_list.append(node) + + for node in remove_list: + model.graph.node.remove(node) + model.graph.node[GetNodeIndex(model.graph,'Slice_94')].input[0] = '390' + + onnx.save(model,save_path) + +if __name__ == "__main__": + work_dir = "./" + batch = 1 + seq_len = 10 + input_size = 50 + hidden_size = 32 + num_layers = 1 + #onnx_LSTM(batch, seq_len, input_size, hidden_size, num_layers, False, work_dir) + modify1("./crnn_sim.onnx","./1.onnx") + modify2("./1.onnx","./2.onnx") + modify3("./2.onnx","./3.onnx") + modify4("./3.onnx","./crnn_revised.onnx") + os.remove("1.onnx") + os.remove("2.onnx") + os.remove("3.onnx") + print('Done') diff --git a/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/parse_testdata.py b/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/parse_testdata.py index 62185425c7532021390878a032549892ed2af08d..d9a1926a6e4bcadcd6390ba082afe6a8d7d10cd6 100644 --- a/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/parse_testdata.py +++ b/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/parse_testdata.py @@ -1,79 +1,79 @@ -import os -import re -import six -import lmdb -from PIL import Image -import numpy as np -import torchvision - - -test_dir = '/home/ltsong/1230/CRNN/IIIT5K_lmdb/' -alphabets = '0123456789abcdefghijklmnopqrstuvwxyz' -output_bin = './input_bin/' - - -class resizeNormalize(object): - def __init__(self, size, interpolation=Image.BICUBIC): - self.size = size - self.interpolation = interpolation - self.toTensor = torchvision.transforms.ToTensor() - - def __call__(self, img): - img = img.resize(self.size, self.interpolation) - img = self.toTensor(img) - img.sub_(0.5).div_(0.5) - return img - - -def gen_data_label(test_dir, data_dir): - if not os.path.exists(data_dir): - os.mkdir(data_dir) - - env = lmdb.open(test_dir, max_readers=32, readonly=True, lock=False, readahead=False, meminit=False) - if not env: - print('cannot open lmdb from %s' % (test_dir)) - sys.exit(0) - with env.begin(write=False) as txn: - nSamples = int(txn.get('num-samples'.encode()).decode('utf-8')) - print('origin nSamples is:', nSamples) - filtered_index_list = [] - - with open('label.txt', 'w') as f: - for index in range(nSamples): - index += 1 - # images - img_key = 'image-%09d'.encode() % index - imgbuf = txn.get(img_key) - buf = six.BytesIO() - buf.write(imgbuf) - buf.seek(0) - try: - img = Image.open(buf).convert('L') - img.show() - # transform - transform = resizeNormalize((100, 32)) - img = transform(img) - img = np.array(img, np.float32) - img.tofile('{}/test_{}.bin'.format(data_dir, index)) - - except IOError: - print('Corrupted image for %d' % index) - - # label - label_key = 'label-%09d'.encode() % index - label = txn.get(label_key).decode('utf-8') - label = label.lower() - - line = 'test_{}.bin:{}'.format(index, label) - f.write(line) - f.write('\n') - out_of_char = f'[^{alphabets}]' - if re.search(out_of_char, label.lower()): - continue - filtered_index_list.append(index) - new_Samples = len(filtered_index_list) - print('new nSamples is:', new_Samples) - - -if __name__ == '__main__': - gen_data_label(test_dir, output_bin) +import os +import re +import six +import lmdb +from PIL import Image +import numpy as np +import torchvision + + +test_dir = '/home/ltsong/1230/CRNN/IIIT5K_lmdb/' +alphabets = '0123456789abcdefghijklmnopqrstuvwxyz' +output_bin = './input_bin/' + + +class resizeNormalize(object): + def __init__(self, size, interpolation=Image.BICUBIC): + self.size = size + self.interpolation = interpolation + self.toTensor = torchvision.transforms.ToTensor() + + def __call__(self, img): + img = img.resize(self.size, self.interpolation) + img = self.toTensor(img) + img.sub_(0.5).div_(0.5) + return img + + +def gen_data_label(test_dir, data_dir): + if not os.path.exists(data_dir): + os.mkdir(data_dir) + + env = lmdb.open(test_dir, max_readers=32, readonly=True, lock=False, readahead=False, meminit=False) + if not env: + print('cannot open lmdb from %s' % (test_dir)) + sys.exit(0) + with env.begin(write=False) as txn: + nSamples = int(txn.get('num-samples'.encode()).decode('utf-8')) + print('origin nSamples is:', nSamples) + filtered_index_list = [] + + with open('label.txt', 'w') as f: + for index in range(nSamples): + index += 1 + # images + img_key = 'image-%09d'.encode() % index + imgbuf = txn.get(img_key) + buf = six.BytesIO() + buf.write(imgbuf) + buf.seek(0) + try: + img = Image.open(buf).convert('L') + img.show() + # transform + transform = resizeNormalize((100, 32)) + img = transform(img) + img = np.array(img, np.float32) + img.tofile('{}/test_{}.bin'.format(data_dir, index)) + + except IOError: + print('Corrupted image for %d' % index) + + # label + label_key = 'label-%09d'.encode() % index + label = txn.get(label_key).decode('utf-8') + label = label.lower() + + line = 'test_{}.bin:{}'.format(index, label) + f.write(line) + f.write('\n') + out_of_char = f'[^{alphabets}]' + if re.search(out_of_char, label.lower()): + continue + filtered_index_list.append(index) + new_Samples = len(filtered_index_list) + print('new nSamples is:', new_Samples) + + +if __name__ == '__main__': + gen_data_label(test_dir, output_bin) diff --git a/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/postpossess_CRNN_pytorch.py b/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/postpossess_CRNN_pytorch.py index 75ed28482d1aa6d4e64872b74140c3ceef89e3fe..b78f0785e7dd6758d4a3d70674fa386daaa7ea10 100644 --- a/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/postpossess_CRNN_pytorch.py +++ b/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/postpossess_CRNN_pytorch.py @@ -1,138 +1,138 @@ -import os -import sys -import numpy as np -import torch - - -class strLabelConverter(object): - """Convert between str and label. - NOTE: - Insert `blank` to the alphabet for CTC. - Args: - alphabet (str): set of the possible characters. - ignore_case (bool, default=True): whether or not to ignore all of the case. - """ - - def __init__(self, alphabet, ignore_case=False): - self._ignore_case = ignore_case - if self._ignore_case: - alphabet = alphabet.lower() - self.alphabet = alphabet + '-' # for `-1` index - self.dict = {} - for i, char in enumerate(alphabet): - # NOTE: 0 is reserved for 'blank' required by wrap_ctc - self.dict[char] = i + 1 - - def encode(self, text): - """Support batch or single str. - Args: - text (str or list of str): texts to convert. - Returns: - torch.LongTensor [length_0 + length_1 + ... length_{n - 1}]: encoded texts. - torch.LongTensor [n]: length of each text. - """ - - length = [] - result = [] - for item in text: - length.append(len(item)) - r = [] - for char in item: - index = self.dict[char] - # result.append(index) - r.append(index) - result.append(r) - max_len = 0 - for r in result: - if len(r) > max_len: - max_len = len(r) - result_temp = [] - for r in result: - for i in range(max_len - len(r)): - r.append(0) - result_temp.append(r) - text = result_temp - return (torch.LongTensor(text), torch.LongTensor(length)) - - def decode(self, t, length, raw=False): - """Decode encoded texts back into strs. - Args: - torch.LongTensor [length_0 + length_1 + ... length_{n - 1}]: encoded texts. - torch.LongTensor [n]: length of each text. - Raises: - AssertionError: when the texts and its length does not match. - Returns: - text (str or list of str): texts to convert. - """ - if length.numel() == 1: - length = length[0] - assert t.numel() == length, "text with length: {} does not match declared length: {}".format(t.numel(), length) - if raw: - return ''.join([self.alphabet[i - 1] for i in t]) - else: - char_list = [] - for i in range(length): - if t[i] != 0 and (not (i > 0 and t[i - 1] == t[i])): - char_list.append(self.alphabet[t[i] - 1]) - return ''.join(char_list) - else: - # batch mode - assert t.numel() == length.sum(), "texts with length: {} does not match declared length: {}".format(t.numel(), length.sum()) - texts = [] - index = 0 - for i in range(length.numel()): - l = length[i] - texts.append( - self.decode( - t[index:index + l], torch.LongTensor([l]), raw=raw)) - index += l - return texts - - -total_img = 3000 - -def get_Acc(bin_path, label, batch_size): - # label - keys, vals = [], [] - with open(label, 'r') as f: - content = f.read() - contents = content.split('\n')[:-1] - for cot in contents: - cot = cot.split(':') - keys.append(cot[0]) - vals.append(cot[1]) - - labels = dict(zip(keys, vals)) - count = 0 - for index in range(total_img): - index += 1 - - preds = np.fromfile('{}/test_{}_1.bin'.format(bin_path, index), np.float32).reshape(26, -1, 37) - preds = torch.from_numpy(preds) - # print("preds.shape:", preds.shape) - preds_size = torch.LongTensor([preds.size(0)] * batch_size) - - _, preds = preds.max(2) - preds = preds.transpose(1, 0).contiguous().view(-1) - - converter = strLabelConverter('0123456789abcdefghijklmnopqrstuvwxyz') - sim_preds = converter.decode(preds.data, preds_size.data, raw=False) - # print("preds_size.data:",preds_size.data) - key = 'test_{}.bin'.format(index) - if sim_preds == labels[key]: - count += 1 - else: - print("label:{} pred:{}".format(labels[key], sim_preds)) - - # acc - print('*'*50) - print('rightNum: {}'.format(count)) - print('totalNum: {}'.format(total_img)) - print("accuracy_rate %.2f" % (count / total_img * 100)) - print('*'*50) - - -if __name__ == '__main__': - bin_path = 'result/dumpOutput_device1/' - label = './label.txt' - get_Acc(bin_path, label, 1) +import os +import sys +import numpy as np +import torch + + +class strLabelConverter(object): + """Convert between str and label. + NOTE: + Insert `blank` to the alphabet for CTC. + Args: + alphabet (str): set of the possible characters. + ignore_case (bool, default=True): whether or not to ignore all of the case. + """ + + def __init__(self, alphabet, ignore_case=False): + self._ignore_case = ignore_case + if self._ignore_case: + alphabet = alphabet.lower() + self.alphabet = alphabet + '-' # for `-1` index + self.dict = {} + for i, char in enumerate(alphabet): + # NOTE: 0 is reserved for 'blank' required by wrap_ctc + self.dict[char] = i + 1 + + def encode(self, text): + """Support batch or single str. + Args: + text (str or list of str): texts to convert. + Returns: + torch.LongTensor [length_0 + length_1 + ... length_{n - 1}]: encoded texts. + torch.LongTensor [n]: length of each text. + """ + + length = [] + result = [] + for item in text: + length.append(len(item)) + r = [] + for char in item: + index = self.dict[char] + # result.append(index) + r.append(index) + result.append(r) + max_len = 0 + for r in result: + if len(r) > max_len: + max_len = len(r) + result_temp = [] + for r in result: + for i in range(max_len - len(r)): + r.append(0) + result_temp.append(r) + text = result_temp + return (torch.LongTensor(text), torch.LongTensor(length)) + + def decode(self, t, length, raw=False): + """Decode encoded texts back into strs. + Args: + torch.LongTensor [length_0 + length_1 + ... length_{n - 1}]: encoded texts. + torch.LongTensor [n]: length of each text. + Raises: + AssertionError: when the texts and its length does not match. + Returns: + text (str or list of str): texts to convert. + """ + if length.numel() == 1: + length = length[0] + assert t.numel() == length, "text with length: {} does not match declared length: {}".format(t.numel(), length) + if raw: + return ''.join([self.alphabet[i - 1] for i in t]) + else: + char_list = [] + for i in range(length): + if t[i] != 0 and (not (i > 0 and t[i - 1] == t[i])): + char_list.append(self.alphabet[t[i] - 1]) + return ''.join(char_list) + else: + # batch mode + assert t.numel() == length.sum(), "texts with length: {} does not match declared length: {}".format(t.numel(), length.sum()) + texts = [] + index = 0 + for i in range(length.numel()): + l = length[i] + texts.append( + self.decode( + t[index:index + l], torch.LongTensor([l]), raw=raw)) + index += l + return texts + + +total_img = 3000 + +def get_Acc(bin_path, label, batch_size): + # label + keys, vals = [], [] + with open(label, 'r') as f: + content = f.read() + contents = content.split('\n')[:-1] + for cot in contents: + cot = cot.split(':') + keys.append(cot[0]) + vals.append(cot[1]) + + labels = dict(zip(keys, vals)) + count = 0 + for index in range(total_img): + index += 1 + + preds = np.fromfile('{}/test_{}_1.bin'.format(bin_path, index), np.float32).reshape(26, -1, 37) + preds = torch.from_numpy(preds) + # print("preds.shape:", preds.shape) + preds_size = torch.LongTensor([preds.size(0)] * batch_size) + + _, preds = preds.max(2) + preds = preds.transpose(1, 0).contiguous().view(-1) + + converter = strLabelConverter('0123456789abcdefghijklmnopqrstuvwxyz') + sim_preds = converter.decode(preds.data, preds_size.data, raw=False) + # print("preds_size.data:",preds_size.data) + key = 'test_{}.bin'.format(index) + if sim_preds == labels[key]: + count += 1 + else: + print("label:{} pred:{}".format(labels[key], sim_preds)) + + # acc + print('*'*50) + print('rightNum: {}'.format(count)) + print('totalNum: {}'.format(total_img)) + print("accuracy_rate %.2f" % (count / total_img * 100)) + print('*'*50) + + +if __name__ == '__main__': + bin_path = 'result/dumpOutput_device1/' + label = './label.txt' + get_Acc(bin_path, label, 1) diff --git a/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/pth2onnx.py b/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/pth2onnx.py index f3c48a4f12ef604fa85b17690d5993dfa584ad66..9e1b2a80c247e27dc63753aebac9fd5b6d68309d 100644 --- a/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/pth2onnx.py +++ b/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch/pth2onnx.py @@ -1,22 +1,22 @@ -import torch -import crnn -import onnx -import torch.onnx - -def convert(): - checkpoint = torch.load("./checkpoint_16_CRNN_acc_0.7963.pth", map_location='cpu') - model = crnn.CRNN(32,1,37,256) - model.load_state_dict(checkpoint['state_dict']) - model.eval() - print(model) - - input_names = ["actual_input_1"] - output_names = ["output1"] - dummy_input = torch.randn(1, 1, 32, 100) - dynamic_axes = {'actual_input_1':{0:'-1'},'output1':{1:'-1'}} - print('\nStarting ONNX export with onnx %s...' % onnx.__version__) - torch.onnx.export(model, dummy_input, "crnn_npu_dy.onnx", input_names=input_names,dynamic_axes = dynamic_axes, output_names=output_names, opset_version=11) - - -if __name__ == "__main__": - convert() +import torch +import crnn +import onnx +import torch.onnx + +def convert(): + checkpoint = torch.load("./checkpoint_16_CRNN_acc_0.7963.pth", map_location='cpu') + model = crnn.CRNN(32,1,37,256) + model.load_state_dict(checkpoint['state_dict']) + model.eval() + print(model) + + input_names = ["actual_input_1"] + output_names = ["output1"] + dummy_input = torch.randn(1, 1, 32, 100) + dynamic_axes = {'actual_input_1':{0:'-1'},'output1':{1:'-1'}} + print('\nStarting ONNX export with onnx %s...' % onnx.__version__) + torch.onnx.export(model, dummy_input, "crnn_npu_dy.onnx", input_names=input_names,dynamic_axes = dynamic_axes, output_names=output_names, opset_version=11) + + +if __name__ == "__main__": + convert() diff --git a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/LICENSE b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/LICENSE index 4ba4fdcab3dbdb4d64ce4cccdfd990698b4d596a..a0e03103591c1158a839681f3c404ee9118b182e 100644 --- a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/LICENSE +++ b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/LICENSE @@ -1,29 +1,29 @@ -BSD 3-Clause License - -Copyright (c) 2017, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +BSD 3-Clause License + +Copyright (c) 2017, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/OXInterface.py b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/OXInterface.py index 658c5ff9a95c602dd225d1e71aa71cab4309b53b..08e9180e6554b600470b82acbb09f189dd14d511 100644 --- a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/OXInterface.py +++ b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/OXInterface.py @@ -1,1249 +1,1249 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - -''' -环境: - python==3.8.5 - onnx==1.8.1 - onnxruntime==1.7.0 - skl2onnx==1.8.0 - numpy==1.19.5 -''' - -import os -import sys -import onnx -import copy -import time -import shutil -import numpy as np -import onnxruntime - -from enum import IntEnum -from onnx import NodeProto -from datetime import datetime -from functools import lru_cache -from typing import List, Dict, Any, NoReturn -from onnx.numpy_helper import from_array, to_array -from onnx.onnx_ml_pb2 import TensorProto, ValueInfoProto, AttributeProto -from onnx.helper import make_attribute, make_node, make_graph, make_model -from skl2onnx.helpers.onnx_helper import enumerate_model_node_outputs, select_model_inputs_outputs, save_onnx_model - -# 修改递归深度限制 -sys.setrecursionlimit(100000) - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> enum OXDataType -# onnx类型枚举值 -class OXDataType(IntEnum): - float32 = 1 - uint8 = 2 - int8 = 3 - uint16 = 4 - int16 = 5 - int32 = 6 - int64 = 7 - string = 8 - bool = 9 - float16 = 10 - double = 11 - uint32 = 12 - uint64 = 13 - complex64 = 14 - complex128 = 15 - bfloat16 = 16 - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> calss GV -# 全局变量,GV = global variable -class GV: - # onnx和numpy数据类型映射字典 - ONNX_2_NUMPY_DATATYPE_DICT = { - 1: np.float32, - 2: np.uint8, - 3: np.int8, - 4: np.uint16, - 5: np.int16, - 6: np.int32, - 7: np.int64, - 9: np.bool_, - 10: np.float16, - 11: np.float64, - 12: np.uint32, - 13: np.uint64, - 14: np.complex64, - 15: np.complex128, - np.float32: 1, - np.uint8: 2, - np.int8: 3, - np.uint16: 4, - np.int16: 5, - np.int32: 6, - np.int64: 7, - np.bool_: 9, - np.float16: 10, - np.float64: 11, - np.uint32: 12, - np.uint64: 13, - np.complex64: 14, - np.complex128: 15, - 'tensor(float)': np.float32, - 'tensor(uint8)': np.uint8, - 'tensor(int8)': np.int8, - 'tensor(uint16)': np.uint16, - 'tensor(int16)': np.int16, - 'tensor(int32)': np.int32, - 'tensor(int64)': np.int64, - 'tensor(bool)': np.bool_, - 'tensor(float16)': np.float16, - 'tensor(double)': np.float64, - 'tensor(uint32)': np.uint32, - 'tensor(uint64)': np.uint64, - } - - # initializer,node索引字典(实现快速查找) - OXINITIALIZER_DICT = {} - OXNODE_DICT = {} - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> calss OXInitializer -class OXInitializer: - ''' - If you print a Initializer variable in the terminal, you will get something like this, and you can modify it - directly. - dims: 1 - data_type: 6 - name: '4239' - raw_data: '\000\000\000\00' - - @dims: google.protobuf.pyext._message.RepeatedScalarContainer - @data_type: int - @name: str - @raw_data: bytes - ''' - - def __init__(self, initializer: TensorProto): - self._initializer = initializer - - def __str__(self): - ndarray = to_array(self._initializer) - msg = 'name: ' + str(self._initializer.name) + '\n' + \ - 'dims: ' + str(self._initializer.dims) + '\n' + \ - 'data_type: ' + str(self._initializer.data_type) + '\n' + \ - 'dtype: ' + str(ndarray.dtype) + '\n' + \ - 'shape: ' + str(ndarray.shape) + '\n' + \ - 'ndarray:\n' + str(ndarray) - return msg - - def get_initializer(self) -> TensorProto: - return self._initializer - - def get_name(self) -> str: - ''' - 获取initializer的名字 - ''' - - return self._initializer.name - - def set_name(self, new_name) -> NoReturn: - ''' - 设置/修改initializer的名字 - ''' - - old_name = self._initializer.name - self._initializer.name = new_name - GV.OXINITIALIZER_DICT[new_name] = GV.OXINITIALIZER_DICT[old_name] - GV.OXINITIALIZER_DICT.pop(old_name) - - def get_data_type(self) -> int: - ''' - 获取initializer的数据类型 - ''' - - return self._initializer.data_type - - def set_data_type(self, ox_data_type: OXDataType) -> NoReturn: - ''' - 设置/修改initializer的数据类型 - ''' - - ndarray = to_array(self._initializer).astype(GV.ONNX_2_NUMPY_DATATYPE_DICT[int(ox_data_type)]) - self._initializer.raw_data = ndarray.tobytes() - self._initializer.data_type = int(ox_data_type) - - def get_data(self) -> np.ndarray: - ''' - 获取initializer的数据 - ''' - - return to_array(self._initializer) - - def set_data(self, ndarray: np.ndarray) -> NoReturn: - ''' - 设置/修改initializer的数据 - ''' - - self._initializer.raw_data = ndarray.tobytes() - self._initializer.data_type = GV.ONNX_2_NUMPY_DATATYPE_DICT[eval('np.' + str(ndarray.dtype))] - _clear_list(self._initializer.dims) - _extend_list(self._initializer.dims, ndarray.shape) - - def save_data(self, file_path: str) -> NoReturn: - ''' - 保存initializer的数据 - ''' - - np.save(file_path, to_array(self._initializer)) - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> calss OXNode -class OXNode: - ''' - If you print a NodeProto variable in the terminal, you will get something like this, and you can modify it directly. - input: '494' - input: 'fc.weight' - input: 'fc.bias' - output: 'class' - name: 'Gemm_121' - op_type: 'Gemm' - attribute { - name: 'alpha' - f: 1.0 - type: FLOAT - } - attribute { - name: 'beta' - f: 1.0 - type: FLOAT - } - attribute { - name: 'transB' - i: 1 - type: INT - } - - @input: google.protobuf.pyext._message.RepeatedScalarContainer - @output: google.protobuf.pyext._message.RepeatedScalarContainer - @name: str - @op_type: str - @attribute: google.protobuf.pyext._message.RepeatedCompositeContainer - ''' - - def __init__(self, node: NodeProto): - self._node = node - - def __str__(self): - return str(self._node) - - def get_node(self) -> NodeProto: - return self._node - - @property - def input(self): # -> google.protobuf.pyext._message.RepeatedScalarContainer - ''' - 获取节点的输入列表 - ''' - - return self._node.input - - @property - def output(self): # -> google.protobuf.pyext._message.RepeatedScalarContainer - ''' - 获取节点的输出列表 - ''' - - return self._node.output - - def get_name(self) -> str: - ''' - 获取节点的名字 - ''' - - return self._node.name - - def set_name(self, new_name) -> NoReturn: - ''' - 设置/修改节点的名字 - ''' - - old_name = self._node.name - self._node.name = new_name - GV.OXNODE_DICT[new_name] = GV.OXNODE_DICT[old_name] - GV.OXNODE_DICT.pop(old_name) - - def get_op_type(self) -> int: - ''' - 获取节点的类型 - ''' - - return self._node.op_type - - def set_op_type(self, op_type) -> NoReturn: - ''' - 设置/修改节点的类型 - ''' - - self._node.op_type = op_type - - def get_attribute(self): # -> google.protobuf.pyext._message.RepeatedCompositeContainer - ''' - 获取节点属性 - ''' - - return self._node.attribute - - def set_attribute(self, attr_name: str, attr_value: Any) -> AttributeProto: - ''' - 设置/修改节点属性 - - Args: - attr_name: 属性名字 - attr_value: 属性值 - - Returns: 修改后的属性 - ''' - - # 构造新attr - new_attr = make_attribute(attr_name, attr_value) - - # 删除旧的 - for attr in self._node.attribute: - if attr.name == attr_name: - self._node.attribute.remove(attr) - break - - # 添加新的 - self._node.attribute.append(new_attr) - - return new_attr - - def add_attribute(self, attr_name: str, attr_value: Any) -> AttributeProto: - ''' - 给节点增加新属性 - - Args: - attr_name: 属性名字 - attr_value: 属性值 - - Returns: 新增的属性 - ''' - - # 构造新attr - new_attr = make_attribute(attr_name, attr_value) - - # 增加 - self._node.attribute.append(new_attr) - - return new_attr - - def remove_attribute(self, attr_name: str) -> AttributeProto: - ''' - 删除节点的某个属性 - - Args: - attr_name: 属性名字 - attr_value: 属性值 - - Returns: 被删除的属性 - ''' - - for attr in self._node.attribute: - if attr.name == attr_name: - removed_attr = attr - self._node.attribute.remove(attr) - break - - return removed_attr - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> calss OXGraph -class OXGraph: - def __init__(self, model_path: str): - print('[INFO] Start initializing.') - start_time = datetime.now() - - self._model_path = model_path - self._model = onnx.load_model(model_path) - self._graph = self._model.graph - self._initializer = self._graph.initializer - self._node = self._graph.node - self._input_tensor_2_oxnode_dict = {} - self._output_tensor_2_oxnode_dict = {} - - # initializer - for initializer in self._initializer: - GV.OXINITIALIZER_DICT[initializer.name] = OXInitializer(initializer) - - # node - for idx, node in enumerate(self._node): - oxnode = OXNode(node) - GV.OXNODE_DICT[node.name] = oxnode - - # 创建tensor_2_oxnode字典 - self._update_tensor_2_oxnode_dict( - self._input_tensor_2_oxnode_dict, - self._output_tensor_2_oxnode_dict, - ) - - # 获取所有tensor信息 - try: - self._all_tensor_info = self.get_all_tensor_info() - except: - os.remove(os.path.join(os.path.dirname(self._model_path), 'temp.onnx')) - print('[WARNING] There are custom operators in the model, ' - 'and these functions are not available: get_input_tensor_info()、get_output_tensor_info()、' - 'get_all_tensor_info()、infer_shape()、dump_all_node_data()、trunc_model().') - - # 屏蔽check_model - def check_model(model): - pass - - onnx.checker.check_model = check_model - - end_time = datetime.now() - cost_time = (end_time - start_time).seconds - print('[INFO] Initialization completed! Cost {} seconds.'.format(cost_time)) - - def __str__(self): - return str(self._model) - - # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Initializer相关函数 - def get_oxinitializer_by_name(self, oxinitializer_name: str, can_return_none: bool = False) -> OXInitializer: - ''' - 根据initializer的名字获取OXInitializer - ''' - - if oxinitializer_name not in GV.OXINITIALIZER_DICT: - if can_return_none is True: - return None - else: - raise RuntimeError('[ERROR] {} not found.'.format(oxinitializer_name)) - return GV.OXINITIALIZER_DICT[oxinitializer_name] - - def add_initializer(self, initializer_name: str, ndarray: np.ndarray) -> OXInitializer: - ''' - 向模型中新增一个initializer - - Args: - initializer_name: initializer的名字 - ndarray: initializer的数据 - - Returns: 新增的OXInitializer - ''' - - if initializer_name in GV.OXINITIALIZER_DICT: - raise RuntimeError( - '[ERROR] {} has already exists in the model, please use a different name!'.format(initializer_name)) - - initializer = from_array(ndarray, initializer_name) - self._initializer.append(initializer) # 这里是复制,而不是引用,id已经变了 - initializer = self._initializer[-1] - oxinitializer = OXInitializer(initializer) - GV.OXINITIALIZER_DICT[initializer_name] = oxinitializer - - return oxinitializer - - def remove_initializer(self, initializer_name: str) -> OXInitializer: - ''' - 从模型中删除指定的initializer - - Args: - initializer_name: initializer的名字 - - Returns: 删除的OXInitializer - ''' - - oxinitializer = self.get_oxinitializer_by_name(initializer_name) - GV.OXINITIALIZER_DICT.pop(initializer_name) - self._initializer.remove(oxinitializer.get_initializer()) - - return oxinitializer - - # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Node相关函数 - def get_oxnode_by_name(self, oxnode_name: str, can_return_none: bool = False) -> OXNode: - ''' - 根据节点名字获取OXNode - ''' - - if oxnode_name not in GV.OXNODE_DICT: - if can_return_none is True: - return None - else: - raise RuntimeError('[ERROR] {} not found.'.format(oxnode_name)) - return GV.OXNODE_DICT[oxnode_name] - - def get_oxnode_by_op_type(self, op_type: str) -> List[OXNode]: - ''' - 根据节点类型获取OXNode - ''' - - res = set() - for oxnode in GV.OXNODE_DICT.values(): - if oxnode.get_op_type() == op_type: - res.add(oxnode) - return list(res) - - def get_oxnode_whose_input_contain_this(self, input_name: str) -> List[OXNode]: - ''' - 遍历所有OXNode,获取输入包含`input_name`的那些OXNode - ''' - - res = set() - for oxnode in GV.OXNODE_DICT.values(): - for oxinput_name in oxnode.input: - if oxinput_name == input_name: - res.add(oxnode) - break - return list(res) - - def get_oxnode_whose_output_contain_this(self, output_name: str) -> List[OXNode]: - ''' - 遍历所有OXNode,获取输出包含`output_name`的那些OXNode - ''' - - res = set() - for oxnode in GV.OXNODE_DICT.values(): - for oxoutput_name in oxnode.output: - if oxoutput_name == output_name: - res.add(oxnode) - break - return list(res) - - def get_previous_oxnode(self, oxnode_name: str) -> List[OXNode]: - ''' - 获取一个节点的前驱节点 - ''' - - res = set() - inputs = self.get_oxnode_by_name(oxnode_name).input - for input in inputs: - oxnode_set = self._output_tensor_2_oxnode_dict.get(input) - if oxnode_set is not None: - res.update(oxnode_set) - return list(res) - - def get_next_oxnode(self, oxnode_name: str) -> List[OXNode]: - ''' - 获取一个节点的后继节点 - ''' - - res = set() - outputs = self.get_oxnode_by_name(oxnode_name).output - for output in outputs: - oxnode_set = self._input_tensor_2_oxnode_dict.get(output) - if oxnode_set is not None: - res.update(oxnode_set) - return list(res) - - def insert_node(self, bef_node_info_list: List[Dict], aft_node_info_list: List[Dict], op_type: str, op_name: str, - **attributes: Dict) -> OXNode: - ''' - 向模型中插入新节点,并自动连边,注意和`add_node`的区别 - - 限制:无法涵盖所有场景,若结果不符合预期,请用`add_node`函数,并手动指定连边关系。 - - Args: - bef_node_info_list:参见README.md用例 - aft_node_info_list:参见README.md用例 - op_type:节点的类型 - op_name:节点的名字 - attributes:节点的属性 - - Returns: 插入的OXNode - ''' - - # 校验插入的节点是否已经存在 - if op_name in GV.OXNODE_DICT: - raise RuntimeError( - '[ERROR] {} has already exists in the model, please use a different name!'.format(op_name)) - - # 解析信息 - bef_node_info_list, aft_node_info_list = self._parse_insert_node_info(bef_node_info_list, aft_node_info_list) - - # 插入节点 - # + 构造新节点的输入 - new_node_input = [] - for bef_node_info in bef_node_info_list: - oxnode = self.get_oxnode_by_name(bef_node_info['bef_node_name'], True) - if oxnode is None: # 说明此节点是模型的输入节点 - new_node_input.append(bef_node_info['bef_node_name']) - else: - for idx in bef_node_info['link_output_idx']: - if oxnode.output[idx] in self.get_output_tensor_info().keys(): # 说明此节点紧接模型的输出节点 - oxnode.output[idx] = oxnode.get_name() + '_m_' + str(idx) - new_node_input.append(oxnode.output[idx]) - - # + 构造新节点的输出 - new_node_output = [op_name + '_0'] - - # + 构造新节点 - insert_oxnode = self.add_node(op_type=op_type, - op_name=op_name, - inputs=new_node_input, - outputs=new_node_output, - **attributes) - - # 和后继节点连边 - for aft_node_info in aft_node_info_list: - oxnode = self.get_oxnode_by_name(aft_node_info['aft_node_name'], True) - if oxnode is None: # 说明此节点是模型的输出节点 - if len(aft_node_info_list) != 1: - raise RuntimeError('[ERROR] Please check aft_node_info_list!') - - # 修改insert_oxnode的输出为模型的输出节点 - insert_oxnode.output[0] = aft_node_info['aft_node_name'] - else: - for idx in aft_node_info['link_input_idx']: - oxnode.input[idx] = new_node_output[0] - - # 更新tensor_2_oxnode字典 - self._update_tensor_2_oxnode_dict( - self._input_tensor_2_oxnode_dict, - self._output_tensor_2_oxnode_dict, - ) - - return insert_oxnode - - def add_node(self, op_type: str, op_name: str, inputs: List[str], outputs: List[str], **attributes: Dict) -> OXNode: - ''' - 向模型中增加新节点,不会自动连边,注意和`insert_node`的区别 - - Args: - op_type:节点的类型 - op_name:节点的名字 - inputs:节点的输入 - outputs:节点的输出 - attributes:节点的属性 - - Returns: 新增的OXNode - ''' - - if op_name in GV.OXNODE_DICT: - raise RuntimeError( - '[ERROR] {} has already exists in the model, please use a different name!'.format(op_name)) - - new_node = make_node(op_type=op_type, name=op_name, inputs=inputs, outputs=outputs, **attributes) - self._node.append(new_node) # 这里复制,而不是用引用,id已经变了 - new_node = self._node[-1] - new_oxnode = OXNode(new_node) - GV.OXNODE_DICT[new_oxnode.get_name()] = new_oxnode - - # 更新tensor_2_oxnode字典 - self._update_tensor_2_oxnode_dict( - self._input_tensor_2_oxnode_dict, - self._output_tensor_2_oxnode_dict, - ) - - return new_oxnode - - def remove_node(self, node_name: str, auto_link: bool = True) -> OXNode: - ''' - 从模型中删除节点 - - 限制:若开启自动连边,则删除的节点必须只有一个前驱节点,否则需要手动连边。若结果不符合预期,也需要自己手动连边。 - - Args: - node_name:要删除的节点名字 - auto_link:是否自动连边 - - Returns: 删除的OXNode - ''' - - if node_name not in GV.OXNODE_DICT: - raise RuntimeError('[ERROR] {} not found.'.format(node_name)) - - if auto_link is False: - oxnode = self.get_oxnode_by_name(node_name) - else: - oxnode = self.get_oxnode_by_name(node_name) - previous_node = self.get_previous_oxnode(node_name) - next_node = self.get_next_oxnode(node_name) - - if len(previous_node) > 1: - raise RuntimeError('[ERROR] Remove node can only have one previous node.') - - _clear_list(previous_node[0].output) - _extend_list(previous_node[0].output, oxnode.output) - - # 删除节点 - GV.OXNODE_DICT.pop(node_name) - self._node.remove(oxnode.get_node()) - - # 更新tensor_2_oxnode字典 - self._update_tensor_2_oxnode_dict( - self._input_tensor_2_oxnode_dict, - self._output_tensor_2_oxnode_dict, - ) - - return oxnode - - # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 输入输出相关函数 - def get_input_tensor_info(self) -> Dict: - ''' - 获取模型输入tensor的信息 - 信息包括:tensor名字、shape、类型 - - Returns: {'tensor_name': {'shape': np.shape, 'dtype': np.dtype}, ...} - ''' - - session = onnxruntime.InferenceSession(self._model_path) - - input_tensor_info = {} - for input_item in session.get_inputs(): - input_tensor_info[input_item.name] = { - 'shape': tuple(input_item.shape), - 'dtype': GV.ONNX_2_NUMPY_DATATYPE_DICT[input_item.type] - } - - return input_tensor_info - - def get_output_tensor_info(self) -> Dict: - ''' - 获取模型输出tensor的信息 - 信息包括:tensor名字、shape、类型 - - Returns: {'tensor_name': {'shape': np.shape, 'dtype': np.dtype}, ...} - ''' - - session = onnxruntime.InferenceSession(self._model_path) - - output_tensor_info = {} - for output_item in session.get_outputs(): - output_tensor_info[output_item.name] = { - 'shape': tuple(output_item.shape), - 'dtype': GV.ONNX_2_NUMPY_DATATYPE_DICT[output_item.type] - } - - return output_tensor_info - - def get_all_tensor_info(self) -> Dict: - ''' - 获取模型中所有tensor的信息 - 所有tensor包括:模型输入tensor、模型输出tensor、模型中间tensor - 信息包括:tensor名字、shape、类型 - - Returns: {'tensor_name': {'shape': np.shape, 'dtype': np.dtype}, ...} - ''' - - old_onnx_model = onnx.load(self._model_path) - - output_name = [] - for name in enumerate_model_node_outputs(old_onnx_model): - output_name.append(name) - - new_onnx_model = select_model_inputs_outputs(old_onnx_model, output_name) - new_model_path = os.path.join(os.path.dirname(self._model_path), 'temp.onnx') - save_onnx_model(new_onnx_model, new_model_path) - - session = onnxruntime.InferenceSession(new_model_path) - os.remove(new_model_path) - - all_tensor_info = {} - - for input_item in session.get_inputs(): - all_tensor_info[input_item.name] = { - 'shape': tuple(input_item.shape), - 'dtype': GV.ONNX_2_NUMPY_DATATYPE_DICT[input_item.type] - } - - for output_item in session.get_outputs(): - all_tensor_info[output_item.name] = { - 'shape': tuple(output_item.shape), - 'dtype': GV.ONNX_2_NUMPY_DATATYPE_DICT[output_item.type] - } - - for oxinitializer in GV.OXINITIALIZER_DICT.values(): - all_tensor_info[oxinitializer.get_name()] = { - 'shape': oxinitializer.get_data().shape, - 'dtype': eval('np.' + str(oxinitializer.get_data().dtype)) - } - - return all_tensor_info - - def infer_shape(self, input_data_info_list: List[Dict]) -> Dict: - ''' - 推导模型各个算子的输出shape信息。 - - 用途:有些模型从onnx图中无法看出算子输出shape信息,也无法获取shape信息,通过此函数可以推导出shape信息。 - - 原理:用真实数据运行一遍模型,记录各个算子的输出shape信息。 - - Args: - input_data_info_list: - [ - { - 'model_input_name': 'input1_name', - 'shape': '(1, 3, 224, 224)', - 'dtype': 'np.float32' - }, - { - 'model_input_name': 'input2_name', - 'shape': '(1, 3, 224, 224)', - 'dtype': 'np.float32' - } - ] - - Returns: {'op_name': {'shape': np.shape, 'dtype': np.dtype}, ...} - ''' - - # 构造输入数据 - input_data_dict = {} - for input_data_info in input_data_info_list: - input_data_dict[input_data_info['model_input_name']] = np.full(eval(input_data_info['shape']), - 1, - dtype=eval(input_data_info['dtype'])) - - # 修改模型,增加输出节点 - old_onnx_model = onnx.load(self._model_path) - output = [] - for out in enumerate_model_node_outputs(old_onnx_model): - output.append(out) - new_onnx_model = select_model_inputs_outputs(old_onnx_model, outputs=output) - onnx_save_path = './temp.onnx' - save_onnx_model(new_onnx_model, onnx_save_path) - - # 推理得到输出 - sess = onnxruntime.InferenceSession(onnx_save_path) - os.remove(onnx_save_path) - output_name = [node.name for node in sess.get_outputs()] - res = sess.run(output_name, input_data_dict) - - # 保存数据 - infer_tensor_info = {} - idx = 0 - for node in old_onnx_model.graph.node: - for i in range(len(node.output)): - infer_tensor_info[node.name] = {'output_idx': i, 'shape': res[idx].shape, 'dtype': res[idx].dtype} - idx += 1 - - return infer_tensor_info - - def dump_all_node_data(self, input_data_info_list: List[Dict], dump_data_save_path: str) -> NoReturn: - ''' - dump模型所有节点的数据 - - Args: - input_data_info_list: - [ - { - 'model_input_name': 'input1_name', - 'npy_file_path': './0.npy', - }, - { - 'model_input_name': 'input2_name', - 'npy_file_path': './1.npy', - }, - ] - dump_data_save_path: e.g. './dump_data' - - Returns: NoReturn - ''' - - # 创建目录 - if os.path.exists(dump_data_save_path): - shutil.rmtree(dump_data_save_path) - os.makedirs(dump_data_save_path) - - # 修改模型,增加输出节点 - old_onnx_model = onnx.load(self._model_path) - output = [] - for out in enumerate_model_node_outputs(old_onnx_model): - output.append(out) - new_onnx_model = select_model_inputs_outputs(old_onnx_model, outputs=output) - onnx_save_path = os.path.join(dump_data_save_path, "./temp.onnx") - save_onnx_model(new_onnx_model, onnx_save_path) - - # 获取输入数据 - input_data_dict = {} - for input_data_info in input_data_info_list: - input_data_dict[input_data_info['model_input_name']] = np.load(input_data_info['npy_file_path']) - - # 推理得到输出 - sess = onnxruntime.InferenceSession(onnx_save_path) - os.remove(onnx_save_path) - output_name = [node.name for node in sess.get_outputs()] - res = sess.run(output_name, input_data_dict) - - # 保存数据 - idx = 0 - for node in old_onnx_model.graph.node: - for i in range(len(node.output)): - file_name = node.name + "." + str(i) + "." + str(round(time.time() * 1000000)) + ".npy" - data_save_path = os.path.join(dump_data_save_path, file_name) - np.save(data_save_path, res[idx]) - idx += 1 - - # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 截图函数 - def extract_model(self, input_tensor_name_list: List[str], output_tensor_name_list: List[str], - new_model_save_path: str) -> NoReturn: - ''' - 从onnx 1.8.1开始,onnx官方提供了截图函数,此函数是对官方`onnx.utils.extract_model`函数的封装, - 以使其集成到`OXGraph`类中。另外,此函数屏蔽了`check_model`操作,使包含自定义算子的onnx提取子图后 - 在保存模型时跳过检查操作,使之可以顺利保存。以下是官方`onnx.utils.extract_model`函数的说明: - - Extracts sub-model from an ONNX model. - - The sub-model is defined by the names of the input and output tensors *exactly*. - - Note: For control-flow operators, e.g. If and Loop, the _boundary of sub-model_, - which is defined by the input and output tensors, should not _cut through_ the - subgraph that is connected to the _main graph_ as attributes of these operators. - - Arguments: - input_path (string): The path to original ONNX model. - output_path (string): The path to save the extracted ONNX model. - input_names (list of string): The names of the input tensors that to be extracted. - output_names (list of string): The names of the output tensors that to be extracted. - ''' - - print('[INFO] Begin to extract the model.') - start_time = datetime.now() - onnx.utils.extract_model(self._model_path, new_model_save_path, input_tensor_name_list, output_tensor_name_list) - end_time = datetime.now() - cost_time = (end_time - start_time).seconds - print('[INFO] Extract model completed! Cost {} seconds.'.format(cost_time)) - - def trunc_model(self, - trunc_beg_node_name_list: List[str], - trunc_end_node_name_list: List[str], - new_model_save_path: str, - keep_input_initializer: bool = False, - userdef_trunc_beg_node_info_list: List[Dict] = None) -> NoReturn: - ''' - 截取一段模型 - - 用途:可以用来单独验证某段网络的精度 - - 注意: - 从onnx 1.8.1开始,onnx官方提供了截图函数,若onnx版本>=1.8.1,请使用`extract_model`函数。 - `extract_model`函数是对官方`onnx.utils.extract_model`函数的封装,以使其集成到`OXGraph`类中。 - 此`trunc_model`函数是自己写的,功能可能有缺陷,但截图速度一般来说更快,模型较大时可以对比尝试。 - ''' - - print('[WARNING] 从onnx 1.8.1开始,onnx官方提供了截图函数,若onnx版本>=1.8.1,请使用`extract_model`函数。' - '`extract_model`函数是对官方`onnx.utils.extract_model`函数的封装,以使其集成到`OXGraph`类中。' - '此`trunc_model`函数是自己写的,功能可能有缺陷,但截图速度一般来说更快,模型较大时可以对比尝试。') - - print('[INFO] Begin to truncate the model.') - start_time = datetime.now() - - # 修改输出节点 - new_output = [] - for elem in trunc_end_node_name_list: - output = self.get_oxnode_by_name(elem).output - new_output.extend(x for x in output) - new_onnx = select_model_inputs_outputs(self._model, outputs=new_output) - save_onnx_model(new_onnx, new_model_save_path) - - # 加载模型 - model = onnx.load_model(new_model_save_path) - graph = model.graph - nodes = graph.node - initializers = graph.initializer - - # 搜索节点 - def find_trunc_beg_node(node_name): - is_find = False - for node in nodes: - if node.name == node_name: - trunc_beg_node = node - is_find = True - break - if is_find is True: - return trunc_beg_node - else: - raise RuntimeError('[ERROR] {} not found.'.format(node_name)) - - # 获取trunc_beg_node详细信息,构造一个这样的list: - ''' - [ - { - 'trunc_beg_node': node, - 'new_input_info_list': [ - { - 'input_name': 'input_A', - 'dtype': OXDataType.float32, - 'shape': (1, 256, 56, 56), - 'input_idx': 0 - }, - { - 'input_name': 'input_B', - 'dtype': OXDataType.float32, - 'shape': (1, 256, 56, 56), - 'input_idx': 1 - } - ] - } - ] - ''' - if userdef_trunc_beg_node_info_list is None: - trunc_beg_node_info_list = [] - initializer_name_set = set() - initializer_name_set.update([oxinitializer.get_name() for oxinitializer in GV.OXINITIALIZER_DICT.values()]) - count = 0 - for trunc_beg_node_name in trunc_beg_node_name_list: - trunc_beg_node = find_trunc_beg_node(trunc_beg_node_name) - new_input_info_list = [] - for idx, input in enumerate(trunc_beg_node.input): - if (keep_input_initializer is True) and (input in initializer_name_set): - continue - else: - new_input_info = {} - new_input_info['input_name'] = 'new_input_' + str(count) - count += 1 - new_input_info['dtype'] = GV.ONNX_2_NUMPY_DATATYPE_DICT[self._all_tensor_info[input]['dtype']] - new_input_info['shape'] = self._all_tensor_info[input]['shape'] - new_input_info['input_idx'] = idx - new_input_info_list.append(new_input_info) - trunc_beg_node_info = {} - trunc_beg_node_info['trunc_beg_node'] = trunc_beg_node - trunc_beg_node_info['new_input_info_list'] = new_input_info_list - trunc_beg_node_info_list.append(trunc_beg_node_info) - else: - trunc_beg_node_info_list = userdef_trunc_beg_node_info_list - - # 构造新输入 - new_inputs = [] - for trunc_beg_node_info in trunc_beg_node_info_list: - if userdef_trunc_beg_node_info_list is None: - trunc_begin_node = trunc_beg_node_info['trunc_beg_node'] - else: - trunc_begin_node = find_trunc_beg_node(trunc_beg_node_info['trunc_beg_node_name']) - for new_input_info in trunc_beg_node_info['new_input_info_list']: - new_input = self._make_new_input(new_input_info['input_name'], new_input_info['dtype'], - new_input_info['shape']) - new_inputs.append(new_input) - trunc_begin_node.input[new_input_info['input_idx']] = new_input_info['input_name'] - - # 查找有用节点 - useful_node_name_set = set() - useful_node_name_set.update(trunc_beg_node_name_list) - useful_node_name_set.update(trunc_end_node_name_list) - - # + 正向查找 - @lru_cache() - def find_useful_node(next_node_name_tuple): - for next_node_name in next_node_name_tuple: - if next_node_name not in trunc_end_node_name_list: - output_oxnode_list = self.get_next_oxnode(next_node_name) - output_oxnode_name_tuple = tuple([oxnode.get_name() for oxnode in output_oxnode_list]) - useful_node_name_set.update(output_oxnode_name_tuple) - find_useful_node(output_oxnode_name_tuple) - - # + 反向查找 - @lru_cache() - def find_useful_node_reverse(next_node_name_tuple): - for next_node_name in next_node_name_tuple: - if next_node_name not in trunc_beg_node_name_list: - input_oxnode_list = self.get_previous_oxnode(next_node_name) - input_oxnode_name_tuple = tuple([oxnode.get_name() for oxnode in input_oxnode_list]) - useful_node_name_set.update(input_oxnode_name_tuple) - find_useful_node_reverse(input_oxnode_name_tuple) - - # + 正向和反向都查找一遍,防止漏查 - find_useful_node(tuple(trunc_beg_node_name_list)) - find_useful_node_reverse(tuple(trunc_end_node_name_list)) - - # 删除多余节点 - for node in copy.deepcopy(nodes): - if node.name not in useful_node_name_set: - nodes.remove(node) - - # 删除多余输入 - _clear_list(graph.input) - _extend_list(graph.input, new_inputs) - - # 删除多余Initializer - all_input = set() - for node in nodes: - all_input.update(node.input) - for initializer in copy.deepcopy(initializers): - if initializer.name not in all_input: - initializers.remove(initializer) - - # 保存模型 - name = 'Extracted from {' + self._graph.name + '}' - graph = make_graph(nodes, - name, - graph.input, - graph.output, - initializer=initializers, - value_info=graph.value_info) - meta = { - 'ir_version': self._model.ir_version, - 'opset_imports': self._model.opset_import, - 'producer_name': 'OXGraph.trunc_model()', - } - new_mode = make_model(graph, **meta) - onnx.save(new_mode, new_model_save_path) - end_time = datetime.now() - cost_time = (end_time - start_time).seconds - print('[INFO] Truncate model completed! Cost {} seconds.'.format(cost_time)) - - # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 保存模型 - def save_new_model(self, new_model_path) -> NoReturn: - ''' - 保存修改后的模型 - ''' - - onnx.save_model(self._model, new_model_path) - - # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 私有函数 - def _update_tensor_2_oxnode_dict(self, input_tensor_2_oxnode_dict, output_tensor_2_oxnode_dict) -> NoReturn: - # 清空字典 - input_tensor_2_oxnode_dict.clear() - output_tensor_2_oxnode_dict.clear() - - # 创建字典 - for oxnode in GV.OXNODE_DICT.values(): - inputs = oxnode.input - outputs = oxnode.output - for input in inputs: - input_tensor_2_oxnode_dict.setdefault(input, set()).add(oxnode) - for output in outputs: - output_tensor_2_oxnode_dict.setdefault(output, set()).add(oxnode) - - def _make_new_input(self, new_input_name: str, ox_data_type: OXDataType, shape: tuple) -> ValueInfoProto: - ''' - If you print the model input in the terminal, you will get something like this, and you can modify it directly. - `dim_param` means dynamic shape. - [name: 'image' - type { - tensor_type { - elem_type: 1 - shape { - dim { - dim_param: '-1' - } - dim { - dim_value: 3 - } - dim { - dim_value: 224 - } - dim { - dim_value: 224 - } - } - } - } - ] - ''' - - new_input = copy.deepcopy(self._graph.input[0]) - new_input.name = new_input_name - new_input.type.tensor_type.elem_type = int(ox_data_type) - - dim_diff = len(shape) - len(new_input.type.tensor_type.shape.dim) - if dim_diff > 0: - for i in range(dim_diff): - new_input.type.tensor_type.shape.dim.append(copy.deepcopy(new_input.type.tensor_type.shape.dim[0])) - elif dim_diff < 0: - for i in range(abs(dim_diff)): - new_input.type.tensor_type.shape.dim.pop() - - for index in range(len(shape)): - if isinstance(shape[index], str): - new_input.type.tensor_type.shape.dim[index].dim_param = shape[index] - elif shape[index] is None: - new_input.type.tensor_type.shape.dim[index].dim_param = '-1' - print('[WARNING] Can not infer tensor shape, set it to "-1" here, which may cause an error! ' - 'Please specify `userdef_trunc_beg_node_info_list` parameters and retry.') - else: - new_input.type.tensor_type.shape.dim[index].dim_value = shape[index] - - return new_input - - def _parse_insert_node_info(self, bef_node_info_list, aft_node_info_list): - ''' - parse bef_node_info_list = ['Relu_1:0'] and aft_node_info_list = ['MaxPool_2:0'] into: - - bef_node_info_list=[{ - 'bef_node_name': 'Relu_1', - 'link_output_idx': [0] - }] - - aft_node_info_list=[{ - 'aft_node_name': 'MaxPool_2', - 'link_input_idx': [0] - }] - - 默认的`:0`可以省略 - ''' - - # 变量定义 - new_bef_node_info_list = [] - new_aft_node_info_list = [] - - # 解析bef_node_info_list - for bef_node_info in bef_node_info_list: - bef_node_info_dict = {} - info_list = bef_node_info.split(':') - bef_node_info_dict['bef_node_name'] = info_list[0] - if len(info_list) == 1: - bef_node_info_dict['link_output_idx'] = [0] - else: - bef_node_info_dict['link_output_idx'] = [int(elem) for idx, elem in enumerate(info_list) if idx > 0] - new_bef_node_info_list.append(bef_node_info_dict) - - # 解析aft_node_info_list - for aft_node_info in aft_node_info_list: - aft_node_info_dict = {} - info_list = aft_node_info.split(':') - aft_node_info_dict['aft_node_name'] = info_list[0] - if len(info_list) == 1: - aft_node_info_dict['link_input_idx'] = [0] - else: - aft_node_info_dict['link_input_idx'] = [int(elem) for idx, elem in enumerate(info_list) if idx > 0] - new_aft_node_info_list.append(aft_node_info_dict) - - return new_bef_node_info_list, new_aft_node_info_list - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 公共函数 -def _clear_list(list) -> NoReturn: - ''' - 清空RepeatedScalarContainer或RepeatedCompositeContainer列表 - ''' - - list_len = len(list) - for _ in range(list_len): - list.pop() - - -def _extend_list(list, what_to_add) -> NoReturn: - ''' - 扩展RepeatedScalarContainer或RepeatedCompositeContainer列表 - ''' - - for elem in what_to_add: - list.append(elem) +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + +''' +环境: + python==3.8.5 + onnx==1.8.1 + onnxruntime==1.7.0 + skl2onnx==1.8.0 + numpy==1.19.5 +''' + +import os +import sys +import onnx +import copy +import time +import shutil +import numpy as np +import onnxruntime + +from enum import IntEnum +from onnx import NodeProto +from datetime import datetime +from functools import lru_cache +from typing import List, Dict, Any, NoReturn +from onnx.numpy_helper import from_array, to_array +from onnx.onnx_ml_pb2 import TensorProto, ValueInfoProto, AttributeProto +from onnx.helper import make_attribute, make_node, make_graph, make_model +from skl2onnx.helpers.onnx_helper import enumerate_model_node_outputs, select_model_inputs_outputs, save_onnx_model + +# 修改递归深度限制 +sys.setrecursionlimit(100000) + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> enum OXDataType +# onnx类型枚举值 +class OXDataType(IntEnum): + float32 = 1 + uint8 = 2 + int8 = 3 + uint16 = 4 + int16 = 5 + int32 = 6 + int64 = 7 + string = 8 + bool = 9 + float16 = 10 + double = 11 + uint32 = 12 + uint64 = 13 + complex64 = 14 + complex128 = 15 + bfloat16 = 16 + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> calss GV +# 全局变量,GV = global variable +class GV: + # onnx和numpy数据类型映射字典 + ONNX_2_NUMPY_DATATYPE_DICT = { + 1: np.float32, + 2: np.uint8, + 3: np.int8, + 4: np.uint16, + 5: np.int16, + 6: np.int32, + 7: np.int64, + 9: np.bool_, + 10: np.float16, + 11: np.float64, + 12: np.uint32, + 13: np.uint64, + 14: np.complex64, + 15: np.complex128, + np.float32: 1, + np.uint8: 2, + np.int8: 3, + np.uint16: 4, + np.int16: 5, + np.int32: 6, + np.int64: 7, + np.bool_: 9, + np.float16: 10, + np.float64: 11, + np.uint32: 12, + np.uint64: 13, + np.complex64: 14, + np.complex128: 15, + 'tensor(float)': np.float32, + 'tensor(uint8)': np.uint8, + 'tensor(int8)': np.int8, + 'tensor(uint16)': np.uint16, + 'tensor(int16)': np.int16, + 'tensor(int32)': np.int32, + 'tensor(int64)': np.int64, + 'tensor(bool)': np.bool_, + 'tensor(float16)': np.float16, + 'tensor(double)': np.float64, + 'tensor(uint32)': np.uint32, + 'tensor(uint64)': np.uint64, + } + + # initializer,node索引字典(实现快速查找) + OXINITIALIZER_DICT = {} + OXNODE_DICT = {} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> calss OXInitializer +class OXInitializer: + ''' + If you print a Initializer variable in the terminal, you will get something like this, and you can modify it + directly. + dims: 1 + data_type: 6 + name: '4239' + raw_data: '\000\000\000\00' + + @dims: google.protobuf.pyext._message.RepeatedScalarContainer + @data_type: int + @name: str + @raw_data: bytes + ''' + + def __init__(self, initializer: TensorProto): + self._initializer = initializer + + def __str__(self): + ndarray = to_array(self._initializer) + msg = 'name: ' + str(self._initializer.name) + '\n' + \ + 'dims: ' + str(self._initializer.dims) + '\n' + \ + 'data_type: ' + str(self._initializer.data_type) + '\n' + \ + 'dtype: ' + str(ndarray.dtype) + '\n' + \ + 'shape: ' + str(ndarray.shape) + '\n' + \ + 'ndarray:\n' + str(ndarray) + return msg + + def get_initializer(self) -> TensorProto: + return self._initializer + + def get_name(self) -> str: + ''' + 获取initializer的名字 + ''' + + return self._initializer.name + + def set_name(self, new_name) -> NoReturn: + ''' + 设置/修改initializer的名字 + ''' + + old_name = self._initializer.name + self._initializer.name = new_name + GV.OXINITIALIZER_DICT[new_name] = GV.OXINITIALIZER_DICT[old_name] + GV.OXINITIALIZER_DICT.pop(old_name) + + def get_data_type(self) -> int: + ''' + 获取initializer的数据类型 + ''' + + return self._initializer.data_type + + def set_data_type(self, ox_data_type: OXDataType) -> NoReturn: + ''' + 设置/修改initializer的数据类型 + ''' + + ndarray = to_array(self._initializer).astype(GV.ONNX_2_NUMPY_DATATYPE_DICT[int(ox_data_type)]) + self._initializer.raw_data = ndarray.tobytes() + self._initializer.data_type = int(ox_data_type) + + def get_data(self) -> np.ndarray: + ''' + 获取initializer的数据 + ''' + + return to_array(self._initializer) + + def set_data(self, ndarray: np.ndarray) -> NoReturn: + ''' + 设置/修改initializer的数据 + ''' + + self._initializer.raw_data = ndarray.tobytes() + self._initializer.data_type = GV.ONNX_2_NUMPY_DATATYPE_DICT[eval('np.' + str(ndarray.dtype))] + _clear_list(self._initializer.dims) + _extend_list(self._initializer.dims, ndarray.shape) + + def save_data(self, file_path: str) -> NoReturn: + ''' + 保存initializer的数据 + ''' + + np.save(file_path, to_array(self._initializer)) + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> calss OXNode +class OXNode: + ''' + If you print a NodeProto variable in the terminal, you will get something like this, and you can modify it directly. + input: '494' + input: 'fc.weight' + input: 'fc.bias' + output: 'class' + name: 'Gemm_121' + op_type: 'Gemm' + attribute { + name: 'alpha' + f: 1.0 + type: FLOAT + } + attribute { + name: 'beta' + f: 1.0 + type: FLOAT + } + attribute { + name: 'transB' + i: 1 + type: INT + } + + @input: google.protobuf.pyext._message.RepeatedScalarContainer + @output: google.protobuf.pyext._message.RepeatedScalarContainer + @name: str + @op_type: str + @attribute: google.protobuf.pyext._message.RepeatedCompositeContainer + ''' + + def __init__(self, node: NodeProto): + self._node = node + + def __str__(self): + return str(self._node) + + def get_node(self) -> NodeProto: + return self._node + + @property + def input(self): # -> google.protobuf.pyext._message.RepeatedScalarContainer + ''' + 获取节点的输入列表 + ''' + + return self._node.input + + @property + def output(self): # -> google.protobuf.pyext._message.RepeatedScalarContainer + ''' + 获取节点的输出列表 + ''' + + return self._node.output + + def get_name(self) -> str: + ''' + 获取节点的名字 + ''' + + return self._node.name + + def set_name(self, new_name) -> NoReturn: + ''' + 设置/修改节点的名字 + ''' + + old_name = self._node.name + self._node.name = new_name + GV.OXNODE_DICT[new_name] = GV.OXNODE_DICT[old_name] + GV.OXNODE_DICT.pop(old_name) + + def get_op_type(self) -> int: + ''' + 获取节点的类型 + ''' + + return self._node.op_type + + def set_op_type(self, op_type) -> NoReturn: + ''' + 设置/修改节点的类型 + ''' + + self._node.op_type = op_type + + def get_attribute(self): # -> google.protobuf.pyext._message.RepeatedCompositeContainer + ''' + 获取节点属性 + ''' + + return self._node.attribute + + def set_attribute(self, attr_name: str, attr_value: Any) -> AttributeProto: + ''' + 设置/修改节点属性 + + Args: + attr_name: 属性名字 + attr_value: 属性值 + + Returns: 修改后的属性 + ''' + + # 构造新attr + new_attr = make_attribute(attr_name, attr_value) + + # 删除旧的 + for attr in self._node.attribute: + if attr.name == attr_name: + self._node.attribute.remove(attr) + break + + # 添加新的 + self._node.attribute.append(new_attr) + + return new_attr + + def add_attribute(self, attr_name: str, attr_value: Any) -> AttributeProto: + ''' + 给节点增加新属性 + + Args: + attr_name: 属性名字 + attr_value: 属性值 + + Returns: 新增的属性 + ''' + + # 构造新attr + new_attr = make_attribute(attr_name, attr_value) + + # 增加 + self._node.attribute.append(new_attr) + + return new_attr + + def remove_attribute(self, attr_name: str) -> AttributeProto: + ''' + 删除节点的某个属性 + + Args: + attr_name: 属性名字 + attr_value: 属性值 + + Returns: 被删除的属性 + ''' + + for attr in self._node.attribute: + if attr.name == attr_name: + removed_attr = attr + self._node.attribute.remove(attr) + break + + return removed_attr + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> calss OXGraph +class OXGraph: + def __init__(self, model_path: str): + print('[INFO] Start initializing.') + start_time = datetime.now() + + self._model_path = model_path + self._model = onnx.load_model(model_path) + self._graph = self._model.graph + self._initializer = self._graph.initializer + self._node = self._graph.node + self._input_tensor_2_oxnode_dict = {} + self._output_tensor_2_oxnode_dict = {} + + # initializer + for initializer in self._initializer: + GV.OXINITIALIZER_DICT[initializer.name] = OXInitializer(initializer) + + # node + for idx, node in enumerate(self._node): + oxnode = OXNode(node) + GV.OXNODE_DICT[node.name] = oxnode + + # 创建tensor_2_oxnode字典 + self._update_tensor_2_oxnode_dict( + self._input_tensor_2_oxnode_dict, + self._output_tensor_2_oxnode_dict, + ) + + # 获取所有tensor信息 + try: + self._all_tensor_info = self.get_all_tensor_info() + except: + os.remove(os.path.join(os.path.dirname(self._model_path), 'temp.onnx')) + print('[WARNING] There are custom operators in the model, ' + 'and these functions are not available: get_input_tensor_info()、get_output_tensor_info()、' + 'get_all_tensor_info()、infer_shape()、dump_all_node_data()、trunc_model().') + + # 屏蔽check_model + def check_model(model): + pass + + onnx.checker.check_model = check_model + + end_time = datetime.now() + cost_time = (end_time - start_time).seconds + print('[INFO] Initialization completed! Cost {} seconds.'.format(cost_time)) + + def __str__(self): + return str(self._model) + + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Initializer相关函数 + def get_oxinitializer_by_name(self, oxinitializer_name: str, can_return_none: bool = False) -> OXInitializer: + ''' + 根据initializer的名字获取OXInitializer + ''' + + if oxinitializer_name not in GV.OXINITIALIZER_DICT: + if can_return_none is True: + return None + else: + raise RuntimeError('[ERROR] {} not found.'.format(oxinitializer_name)) + return GV.OXINITIALIZER_DICT[oxinitializer_name] + + def add_initializer(self, initializer_name: str, ndarray: np.ndarray) -> OXInitializer: + ''' + 向模型中新增一个initializer + + Args: + initializer_name: initializer的名字 + ndarray: initializer的数据 + + Returns: 新增的OXInitializer + ''' + + if initializer_name in GV.OXINITIALIZER_DICT: + raise RuntimeError( + '[ERROR] {} has already exists in the model, please use a different name!'.format(initializer_name)) + + initializer = from_array(ndarray, initializer_name) + self._initializer.append(initializer) # 这里是复制,而不是引用,id已经变了 + initializer = self._initializer[-1] + oxinitializer = OXInitializer(initializer) + GV.OXINITIALIZER_DICT[initializer_name] = oxinitializer + + return oxinitializer + + def remove_initializer(self, initializer_name: str) -> OXInitializer: + ''' + 从模型中删除指定的initializer + + Args: + initializer_name: initializer的名字 + + Returns: 删除的OXInitializer + ''' + + oxinitializer = self.get_oxinitializer_by_name(initializer_name) + GV.OXINITIALIZER_DICT.pop(initializer_name) + self._initializer.remove(oxinitializer.get_initializer()) + + return oxinitializer + + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Node相关函数 + def get_oxnode_by_name(self, oxnode_name: str, can_return_none: bool = False) -> OXNode: + ''' + 根据节点名字获取OXNode + ''' + + if oxnode_name not in GV.OXNODE_DICT: + if can_return_none is True: + return None + else: + raise RuntimeError('[ERROR] {} not found.'.format(oxnode_name)) + return GV.OXNODE_DICT[oxnode_name] + + def get_oxnode_by_op_type(self, op_type: str) -> List[OXNode]: + ''' + 根据节点类型获取OXNode + ''' + + res = set() + for oxnode in GV.OXNODE_DICT.values(): + if oxnode.get_op_type() == op_type: + res.add(oxnode) + return list(res) + + def get_oxnode_whose_input_contain_this(self, input_name: str) -> List[OXNode]: + ''' + 遍历所有OXNode,获取输入包含`input_name`的那些OXNode + ''' + + res = set() + for oxnode in GV.OXNODE_DICT.values(): + for oxinput_name in oxnode.input: + if oxinput_name == input_name: + res.add(oxnode) + break + return list(res) + + def get_oxnode_whose_output_contain_this(self, output_name: str) -> List[OXNode]: + ''' + 遍历所有OXNode,获取输出包含`output_name`的那些OXNode + ''' + + res = set() + for oxnode in GV.OXNODE_DICT.values(): + for oxoutput_name in oxnode.output: + if oxoutput_name == output_name: + res.add(oxnode) + break + return list(res) + + def get_previous_oxnode(self, oxnode_name: str) -> List[OXNode]: + ''' + 获取一个节点的前驱节点 + ''' + + res = set() + inputs = self.get_oxnode_by_name(oxnode_name).input + for input in inputs: + oxnode_set = self._output_tensor_2_oxnode_dict.get(input) + if oxnode_set is not None: + res.update(oxnode_set) + return list(res) + + def get_next_oxnode(self, oxnode_name: str) -> List[OXNode]: + ''' + 获取一个节点的后继节点 + ''' + + res = set() + outputs = self.get_oxnode_by_name(oxnode_name).output + for output in outputs: + oxnode_set = self._input_tensor_2_oxnode_dict.get(output) + if oxnode_set is not None: + res.update(oxnode_set) + return list(res) + + def insert_node(self, bef_node_info_list: List[Dict], aft_node_info_list: List[Dict], op_type: str, op_name: str, + **attributes: Dict) -> OXNode: + ''' + 向模型中插入新节点,并自动连边,注意和`add_node`的区别 + + 限制:无法涵盖所有场景,若结果不符合预期,请用`add_node`函数,并手动指定连边关系。 + + Args: + bef_node_info_list:参见README.md用例 + aft_node_info_list:参见README.md用例 + op_type:节点的类型 + op_name:节点的名字 + attributes:节点的属性 + + Returns: 插入的OXNode + ''' + + # 校验插入的节点是否已经存在 + if op_name in GV.OXNODE_DICT: + raise RuntimeError( + '[ERROR] {} has already exists in the model, please use a different name!'.format(op_name)) + + # 解析信息 + bef_node_info_list, aft_node_info_list = self._parse_insert_node_info(bef_node_info_list, aft_node_info_list) + + # 插入节点 + # + 构造新节点的输入 + new_node_input = [] + for bef_node_info in bef_node_info_list: + oxnode = self.get_oxnode_by_name(bef_node_info['bef_node_name'], True) + if oxnode is None: # 说明此节点是模型的输入节点 + new_node_input.append(bef_node_info['bef_node_name']) + else: + for idx in bef_node_info['link_output_idx']: + if oxnode.output[idx] in self.get_output_tensor_info().keys(): # 说明此节点紧接模型的输出节点 + oxnode.output[idx] = oxnode.get_name() + '_m_' + str(idx) + new_node_input.append(oxnode.output[idx]) + + # + 构造新节点的输出 + new_node_output = [op_name + '_0'] + + # + 构造新节点 + insert_oxnode = self.add_node(op_type=op_type, + op_name=op_name, + inputs=new_node_input, + outputs=new_node_output, + **attributes) + + # 和后继节点连边 + for aft_node_info in aft_node_info_list: + oxnode = self.get_oxnode_by_name(aft_node_info['aft_node_name'], True) + if oxnode is None: # 说明此节点是模型的输出节点 + if len(aft_node_info_list) != 1: + raise RuntimeError('[ERROR] Please check aft_node_info_list!') + + # 修改insert_oxnode的输出为模型的输出节点 + insert_oxnode.output[0] = aft_node_info['aft_node_name'] + else: + for idx in aft_node_info['link_input_idx']: + oxnode.input[idx] = new_node_output[0] + + # 更新tensor_2_oxnode字典 + self._update_tensor_2_oxnode_dict( + self._input_tensor_2_oxnode_dict, + self._output_tensor_2_oxnode_dict, + ) + + return insert_oxnode + + def add_node(self, op_type: str, op_name: str, inputs: List[str], outputs: List[str], **attributes: Dict) -> OXNode: + ''' + 向模型中增加新节点,不会自动连边,注意和`insert_node`的区别 + + Args: + op_type:节点的类型 + op_name:节点的名字 + inputs:节点的输入 + outputs:节点的输出 + attributes:节点的属性 + + Returns: 新增的OXNode + ''' + + if op_name in GV.OXNODE_DICT: + raise RuntimeError( + '[ERROR] {} has already exists in the model, please use a different name!'.format(op_name)) + + new_node = make_node(op_type=op_type, name=op_name, inputs=inputs, outputs=outputs, **attributes) + self._node.append(new_node) # 这里复制,而不是用引用,id已经变了 + new_node = self._node[-1] + new_oxnode = OXNode(new_node) + GV.OXNODE_DICT[new_oxnode.get_name()] = new_oxnode + + # 更新tensor_2_oxnode字典 + self._update_tensor_2_oxnode_dict( + self._input_tensor_2_oxnode_dict, + self._output_tensor_2_oxnode_dict, + ) + + return new_oxnode + + def remove_node(self, node_name: str, auto_link: bool = True) -> OXNode: + ''' + 从模型中删除节点 + + 限制:若开启自动连边,则删除的节点必须只有一个前驱节点,否则需要手动连边。若结果不符合预期,也需要自己手动连边。 + + Args: + node_name:要删除的节点名字 + auto_link:是否自动连边 + + Returns: 删除的OXNode + ''' + + if node_name not in GV.OXNODE_DICT: + raise RuntimeError('[ERROR] {} not found.'.format(node_name)) + + if auto_link is False: + oxnode = self.get_oxnode_by_name(node_name) + else: + oxnode = self.get_oxnode_by_name(node_name) + previous_node = self.get_previous_oxnode(node_name) + next_node = self.get_next_oxnode(node_name) + + if len(previous_node) > 1: + raise RuntimeError('[ERROR] Remove node can only have one previous node.') + + _clear_list(previous_node[0].output) + _extend_list(previous_node[0].output, oxnode.output) + + # 删除节点 + GV.OXNODE_DICT.pop(node_name) + self._node.remove(oxnode.get_node()) + + # 更新tensor_2_oxnode字典 + self._update_tensor_2_oxnode_dict( + self._input_tensor_2_oxnode_dict, + self._output_tensor_2_oxnode_dict, + ) + + return oxnode + + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 输入输出相关函数 + def get_input_tensor_info(self) -> Dict: + ''' + 获取模型输入tensor的信息 + 信息包括:tensor名字、shape、类型 + + Returns: {'tensor_name': {'shape': np.shape, 'dtype': np.dtype}, ...} + ''' + + session = onnxruntime.InferenceSession(self._model_path) + + input_tensor_info = {} + for input_item in session.get_inputs(): + input_tensor_info[input_item.name] = { + 'shape': tuple(input_item.shape), + 'dtype': GV.ONNX_2_NUMPY_DATATYPE_DICT[input_item.type] + } + + return input_tensor_info + + def get_output_tensor_info(self) -> Dict: + ''' + 获取模型输出tensor的信息 + 信息包括:tensor名字、shape、类型 + + Returns: {'tensor_name': {'shape': np.shape, 'dtype': np.dtype}, ...} + ''' + + session = onnxruntime.InferenceSession(self._model_path) + + output_tensor_info = {} + for output_item in session.get_outputs(): + output_tensor_info[output_item.name] = { + 'shape': tuple(output_item.shape), + 'dtype': GV.ONNX_2_NUMPY_DATATYPE_DICT[output_item.type] + } + + return output_tensor_info + + def get_all_tensor_info(self) -> Dict: + ''' + 获取模型中所有tensor的信息 + 所有tensor包括:模型输入tensor、模型输出tensor、模型中间tensor + 信息包括:tensor名字、shape、类型 + + Returns: {'tensor_name': {'shape': np.shape, 'dtype': np.dtype}, ...} + ''' + + old_onnx_model = onnx.load(self._model_path) + + output_name = [] + for name in enumerate_model_node_outputs(old_onnx_model): + output_name.append(name) + + new_onnx_model = select_model_inputs_outputs(old_onnx_model, output_name) + new_model_path = os.path.join(os.path.dirname(self._model_path), 'temp.onnx') + save_onnx_model(new_onnx_model, new_model_path) + + session = onnxruntime.InferenceSession(new_model_path) + os.remove(new_model_path) + + all_tensor_info = {} + + for input_item in session.get_inputs(): + all_tensor_info[input_item.name] = { + 'shape': tuple(input_item.shape), + 'dtype': GV.ONNX_2_NUMPY_DATATYPE_DICT[input_item.type] + } + + for output_item in session.get_outputs(): + all_tensor_info[output_item.name] = { + 'shape': tuple(output_item.shape), + 'dtype': GV.ONNX_2_NUMPY_DATATYPE_DICT[output_item.type] + } + + for oxinitializer in GV.OXINITIALIZER_DICT.values(): + all_tensor_info[oxinitializer.get_name()] = { + 'shape': oxinitializer.get_data().shape, + 'dtype': eval('np.' + str(oxinitializer.get_data().dtype)) + } + + return all_tensor_info + + def infer_shape(self, input_data_info_list: List[Dict]) -> Dict: + ''' + 推导模型各个算子的输出shape信息。 + + 用途:有些模型从onnx图中无法看出算子输出shape信息,也无法获取shape信息,通过此函数可以推导出shape信息。 + + 原理:用真实数据运行一遍模型,记录各个算子的输出shape信息。 + + Args: + input_data_info_list: + [ + { + 'model_input_name': 'input1_name', + 'shape': '(1, 3, 224, 224)', + 'dtype': 'np.float32' + }, + { + 'model_input_name': 'input2_name', + 'shape': '(1, 3, 224, 224)', + 'dtype': 'np.float32' + } + ] + + Returns: {'op_name': {'shape': np.shape, 'dtype': np.dtype}, ...} + ''' + + # 构造输入数据 + input_data_dict = {} + for input_data_info in input_data_info_list: + input_data_dict[input_data_info['model_input_name']] = np.full(eval(input_data_info['shape']), + 1, + dtype=eval(input_data_info['dtype'])) + + # 修改模型,增加输出节点 + old_onnx_model = onnx.load(self._model_path) + output = [] + for out in enumerate_model_node_outputs(old_onnx_model): + output.append(out) + new_onnx_model = select_model_inputs_outputs(old_onnx_model, outputs=output) + onnx_save_path = './temp.onnx' + save_onnx_model(new_onnx_model, onnx_save_path) + + # 推理得到输出 + sess = onnxruntime.InferenceSession(onnx_save_path) + os.remove(onnx_save_path) + output_name = [node.name for node in sess.get_outputs()] + res = sess.run(output_name, input_data_dict) + + # 保存数据 + infer_tensor_info = {} + idx = 0 + for node in old_onnx_model.graph.node: + for i in range(len(node.output)): + infer_tensor_info[node.name] = {'output_idx': i, 'shape': res[idx].shape, 'dtype': res[idx].dtype} + idx += 1 + + return infer_tensor_info + + def dump_all_node_data(self, input_data_info_list: List[Dict], dump_data_save_path: str) -> NoReturn: + ''' + dump模型所有节点的数据 + + Args: + input_data_info_list: + [ + { + 'model_input_name': 'input1_name', + 'npy_file_path': './0.npy', + }, + { + 'model_input_name': 'input2_name', + 'npy_file_path': './1.npy', + }, + ] + dump_data_save_path: e.g. './dump_data' + + Returns: NoReturn + ''' + + # 创建目录 + if os.path.exists(dump_data_save_path): + shutil.rmtree(dump_data_save_path) + os.makedirs(dump_data_save_path) + + # 修改模型,增加输出节点 + old_onnx_model = onnx.load(self._model_path) + output = [] + for out in enumerate_model_node_outputs(old_onnx_model): + output.append(out) + new_onnx_model = select_model_inputs_outputs(old_onnx_model, outputs=output) + onnx_save_path = os.path.join(dump_data_save_path, "./temp.onnx") + save_onnx_model(new_onnx_model, onnx_save_path) + + # 获取输入数据 + input_data_dict = {} + for input_data_info in input_data_info_list: + input_data_dict[input_data_info['model_input_name']] = np.load(input_data_info['npy_file_path']) + + # 推理得到输出 + sess = onnxruntime.InferenceSession(onnx_save_path) + os.remove(onnx_save_path) + output_name = [node.name for node in sess.get_outputs()] + res = sess.run(output_name, input_data_dict) + + # 保存数据 + idx = 0 + for node in old_onnx_model.graph.node: + for i in range(len(node.output)): + file_name = node.name + "." + str(i) + "." + str(round(time.time() * 1000000)) + ".npy" + data_save_path = os.path.join(dump_data_save_path, file_name) + np.save(data_save_path, res[idx]) + idx += 1 + + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 截图函数 + def extract_model(self, input_tensor_name_list: List[str], output_tensor_name_list: List[str], + new_model_save_path: str) -> NoReturn: + ''' + 从onnx 1.8.1开始,onnx官方提供了截图函数,此函数是对官方`onnx.utils.extract_model`函数的封装, + 以使其集成到`OXGraph`类中。另外,此函数屏蔽了`check_model`操作,使包含自定义算子的onnx提取子图后 + 在保存模型时跳过检查操作,使之可以顺利保存。以下是官方`onnx.utils.extract_model`函数的说明: + + Extracts sub-model from an ONNX model. + + The sub-model is defined by the names of the input and output tensors *exactly*. + + Note: For control-flow operators, e.g. If and Loop, the _boundary of sub-model_, + which is defined by the input and output tensors, should not _cut through_ the + subgraph that is connected to the _main graph_ as attributes of these operators. + + Arguments: + input_path (string): The path to original ONNX model. + output_path (string): The path to save the extracted ONNX model. + input_names (list of string): The names of the input tensors that to be extracted. + output_names (list of string): The names of the output tensors that to be extracted. + ''' + + print('[INFO] Begin to extract the model.') + start_time = datetime.now() + onnx.utils.extract_model(self._model_path, new_model_save_path, input_tensor_name_list, output_tensor_name_list) + end_time = datetime.now() + cost_time = (end_time - start_time).seconds + print('[INFO] Extract model completed! Cost {} seconds.'.format(cost_time)) + + def trunc_model(self, + trunc_beg_node_name_list: List[str], + trunc_end_node_name_list: List[str], + new_model_save_path: str, + keep_input_initializer: bool = False, + userdef_trunc_beg_node_info_list: List[Dict] = None) -> NoReturn: + ''' + 截取一段模型 + + 用途:可以用来单独验证某段网络的精度 + + 注意: + 从onnx 1.8.1开始,onnx官方提供了截图函数,若onnx版本>=1.8.1,请使用`extract_model`函数。 + `extract_model`函数是对官方`onnx.utils.extract_model`函数的封装,以使其集成到`OXGraph`类中。 + 此`trunc_model`函数是自己写的,功能可能有缺陷,但截图速度一般来说更快,模型较大时可以对比尝试。 + ''' + + print('[WARNING] 从onnx 1.8.1开始,onnx官方提供了截图函数,若onnx版本>=1.8.1,请使用`extract_model`函数。' + '`extract_model`函数是对官方`onnx.utils.extract_model`函数的封装,以使其集成到`OXGraph`类中。' + '此`trunc_model`函数是自己写的,功能可能有缺陷,但截图速度一般来说更快,模型较大时可以对比尝试。') + + print('[INFO] Begin to truncate the model.') + start_time = datetime.now() + + # 修改输出节点 + new_output = [] + for elem in trunc_end_node_name_list: + output = self.get_oxnode_by_name(elem).output + new_output.extend(x for x in output) + new_onnx = select_model_inputs_outputs(self._model, outputs=new_output) + save_onnx_model(new_onnx, new_model_save_path) + + # 加载模型 + model = onnx.load_model(new_model_save_path) + graph = model.graph + nodes = graph.node + initializers = graph.initializer + + # 搜索节点 + def find_trunc_beg_node(node_name): + is_find = False + for node in nodes: + if node.name == node_name: + trunc_beg_node = node + is_find = True + break + if is_find is True: + return trunc_beg_node + else: + raise RuntimeError('[ERROR] {} not found.'.format(node_name)) + + # 获取trunc_beg_node详细信息,构造一个这样的list: + ''' + [ + { + 'trunc_beg_node': node, + 'new_input_info_list': [ + { + 'input_name': 'input_A', + 'dtype': OXDataType.float32, + 'shape': (1, 256, 56, 56), + 'input_idx': 0 + }, + { + 'input_name': 'input_B', + 'dtype': OXDataType.float32, + 'shape': (1, 256, 56, 56), + 'input_idx': 1 + } + ] + } + ] + ''' + if userdef_trunc_beg_node_info_list is None: + trunc_beg_node_info_list = [] + initializer_name_set = set() + initializer_name_set.update([oxinitializer.get_name() for oxinitializer in GV.OXINITIALIZER_DICT.values()]) + count = 0 + for trunc_beg_node_name in trunc_beg_node_name_list: + trunc_beg_node = find_trunc_beg_node(trunc_beg_node_name) + new_input_info_list = [] + for idx, input in enumerate(trunc_beg_node.input): + if (keep_input_initializer is True) and (input in initializer_name_set): + continue + else: + new_input_info = {} + new_input_info['input_name'] = 'new_input_' + str(count) + count += 1 + new_input_info['dtype'] = GV.ONNX_2_NUMPY_DATATYPE_DICT[self._all_tensor_info[input]['dtype']] + new_input_info['shape'] = self._all_tensor_info[input]['shape'] + new_input_info['input_idx'] = idx + new_input_info_list.append(new_input_info) + trunc_beg_node_info = {} + trunc_beg_node_info['trunc_beg_node'] = trunc_beg_node + trunc_beg_node_info['new_input_info_list'] = new_input_info_list + trunc_beg_node_info_list.append(trunc_beg_node_info) + else: + trunc_beg_node_info_list = userdef_trunc_beg_node_info_list + + # 构造新输入 + new_inputs = [] + for trunc_beg_node_info in trunc_beg_node_info_list: + if userdef_trunc_beg_node_info_list is None: + trunc_begin_node = trunc_beg_node_info['trunc_beg_node'] + else: + trunc_begin_node = find_trunc_beg_node(trunc_beg_node_info['trunc_beg_node_name']) + for new_input_info in trunc_beg_node_info['new_input_info_list']: + new_input = self._make_new_input(new_input_info['input_name'], new_input_info['dtype'], + new_input_info['shape']) + new_inputs.append(new_input) + trunc_begin_node.input[new_input_info['input_idx']] = new_input_info['input_name'] + + # 查找有用节点 + useful_node_name_set = set() + useful_node_name_set.update(trunc_beg_node_name_list) + useful_node_name_set.update(trunc_end_node_name_list) + + # + 正向查找 + @lru_cache() + def find_useful_node(next_node_name_tuple): + for next_node_name in next_node_name_tuple: + if next_node_name not in trunc_end_node_name_list: + output_oxnode_list = self.get_next_oxnode(next_node_name) + output_oxnode_name_tuple = tuple([oxnode.get_name() for oxnode in output_oxnode_list]) + useful_node_name_set.update(output_oxnode_name_tuple) + find_useful_node(output_oxnode_name_tuple) + + # + 反向查找 + @lru_cache() + def find_useful_node_reverse(next_node_name_tuple): + for next_node_name in next_node_name_tuple: + if next_node_name not in trunc_beg_node_name_list: + input_oxnode_list = self.get_previous_oxnode(next_node_name) + input_oxnode_name_tuple = tuple([oxnode.get_name() for oxnode in input_oxnode_list]) + useful_node_name_set.update(input_oxnode_name_tuple) + find_useful_node_reverse(input_oxnode_name_tuple) + + # + 正向和反向都查找一遍,防止漏查 + find_useful_node(tuple(trunc_beg_node_name_list)) + find_useful_node_reverse(tuple(trunc_end_node_name_list)) + + # 删除多余节点 + for node in copy.deepcopy(nodes): + if node.name not in useful_node_name_set: + nodes.remove(node) + + # 删除多余输入 + _clear_list(graph.input) + _extend_list(graph.input, new_inputs) + + # 删除多余Initializer + all_input = set() + for node in nodes: + all_input.update(node.input) + for initializer in copy.deepcopy(initializers): + if initializer.name not in all_input: + initializers.remove(initializer) + + # 保存模型 + name = 'Extracted from {' + self._graph.name + '}' + graph = make_graph(nodes, + name, + graph.input, + graph.output, + initializer=initializers, + value_info=graph.value_info) + meta = { + 'ir_version': self._model.ir_version, + 'opset_imports': self._model.opset_import, + 'producer_name': 'OXGraph.trunc_model()', + } + new_mode = make_model(graph, **meta) + onnx.save(new_mode, new_model_save_path) + end_time = datetime.now() + cost_time = (end_time - start_time).seconds + print('[INFO] Truncate model completed! Cost {} seconds.'.format(cost_time)) + + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 保存模型 + def save_new_model(self, new_model_path) -> NoReturn: + ''' + 保存修改后的模型 + ''' + + onnx.save_model(self._model, new_model_path) + + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 私有函数 + def _update_tensor_2_oxnode_dict(self, input_tensor_2_oxnode_dict, output_tensor_2_oxnode_dict) -> NoReturn: + # 清空字典 + input_tensor_2_oxnode_dict.clear() + output_tensor_2_oxnode_dict.clear() + + # 创建字典 + for oxnode in GV.OXNODE_DICT.values(): + inputs = oxnode.input + outputs = oxnode.output + for input in inputs: + input_tensor_2_oxnode_dict.setdefault(input, set()).add(oxnode) + for output in outputs: + output_tensor_2_oxnode_dict.setdefault(output, set()).add(oxnode) + + def _make_new_input(self, new_input_name: str, ox_data_type: OXDataType, shape: tuple) -> ValueInfoProto: + ''' + If you print the model input in the terminal, you will get something like this, and you can modify it directly. + `dim_param` means dynamic shape. + [name: 'image' + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_param: '-1' + } + dim { + dim_value: 3 + } + dim { + dim_value: 224 + } + dim { + dim_value: 224 + } + } + } + } + ] + ''' + + new_input = copy.deepcopy(self._graph.input[0]) + new_input.name = new_input_name + new_input.type.tensor_type.elem_type = int(ox_data_type) + + dim_diff = len(shape) - len(new_input.type.tensor_type.shape.dim) + if dim_diff > 0: + for i in range(dim_diff): + new_input.type.tensor_type.shape.dim.append(copy.deepcopy(new_input.type.tensor_type.shape.dim[0])) + elif dim_diff < 0: + for i in range(abs(dim_diff)): + new_input.type.tensor_type.shape.dim.pop() + + for index in range(len(shape)): + if isinstance(shape[index], str): + new_input.type.tensor_type.shape.dim[index].dim_param = shape[index] + elif shape[index] is None: + new_input.type.tensor_type.shape.dim[index].dim_param = '-1' + print('[WARNING] Can not infer tensor shape, set it to "-1" here, which may cause an error! ' + 'Please specify `userdef_trunc_beg_node_info_list` parameters and retry.') + else: + new_input.type.tensor_type.shape.dim[index].dim_value = shape[index] + + return new_input + + def _parse_insert_node_info(self, bef_node_info_list, aft_node_info_list): + ''' + parse bef_node_info_list = ['Relu_1:0'] and aft_node_info_list = ['MaxPool_2:0'] into: + + bef_node_info_list=[{ + 'bef_node_name': 'Relu_1', + 'link_output_idx': [0] + }] + + aft_node_info_list=[{ + 'aft_node_name': 'MaxPool_2', + 'link_input_idx': [0] + }] + + 默认的`:0`可以省略 + ''' + + # 变量定义 + new_bef_node_info_list = [] + new_aft_node_info_list = [] + + # 解析bef_node_info_list + for bef_node_info in bef_node_info_list: + bef_node_info_dict = {} + info_list = bef_node_info.split(':') + bef_node_info_dict['bef_node_name'] = info_list[0] + if len(info_list) == 1: + bef_node_info_dict['link_output_idx'] = [0] + else: + bef_node_info_dict['link_output_idx'] = [int(elem) for idx, elem in enumerate(info_list) if idx > 0] + new_bef_node_info_list.append(bef_node_info_dict) + + # 解析aft_node_info_list + for aft_node_info in aft_node_info_list: + aft_node_info_dict = {} + info_list = aft_node_info.split(':') + aft_node_info_dict['aft_node_name'] = info_list[0] + if len(info_list) == 1: + aft_node_info_dict['link_input_idx'] = [0] + else: + aft_node_info_dict['link_input_idx'] = [int(elem) for idx, elem in enumerate(info_list) if idx > 0] + new_aft_node_info_list.append(aft_node_info_dict) + + return new_bef_node_info_list, new_aft_node_info_list + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 公共函数 +def _clear_list(list) -> NoReturn: + ''' + 清空RepeatedScalarContainer或RepeatedCompositeContainer列表 + ''' + + list_len = len(list) + for _ in range(list_len): + list.pop() + + +def _extend_list(list, what_to_add) -> NoReturn: + ''' + 扩展RepeatedScalarContainer或RepeatedCompositeContainer列表 + ''' + + for elem in what_to_add: + list.append(elem) diff --git a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/ReadMe.md b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/ReadMe.md index 111fc7bc1079b93c0ce0a5c11d80845fa09609a9..1d37439f430d4f43f43bc6a2a2c04035e7c11935 100644 --- a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/ReadMe.md +++ b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/ReadMe.md @@ -1,310 +1,310 @@ -# 参考论文 - -- [Objects as Points](https://arxiv.org/abs/1904.07850) - -# 参考实现 - -- [xingyizhou/CenterNet](https://github.com/xingyizhou/CenterNet) -- [CaoWGG/TensorRT-CenterNet](https://github.com/CaoWGG/TensorRT-CenterNet) - -# 环境搭建 - -1、创建一个conda环境 - -```shell -conda create --nameCenterNet python=3.6 -``` - -激活环境 - -``` -conda activate CenterNet -``` - -2、clone仓库 - -``` -git clone https://github.com/xingyizhou/CenterNet -``` - -3、安装依赖 - -``` -cd CenterNet -pip install -r requirements.txt -``` - -4、安装pytorch v1.0.0 - -1) 下载[torch-1.0.0-cp36-cp36m-linux_x86_64.whl](https://download.pytorch.org/whl/cu100/torch-1.0.0-cp36-cp36m-linux_x86_64.whl) - -2) 安装 - -``` -pip install torch-1.0.0-cp36-cp36m-linux_x86_64.whl -``` - -**注意:**1) pytorch版本必须是1.0.0;2) 需确保是GPU环境;3) CUDA版本为10.2 - -5、安装其它依赖 - -``` -pip install tqdm==4.19.9 torchvision==0.2.2 onnx==1.8.1 onnxruntime==1.7.0 skl2onnx==1.8.0 -``` - -6、确保gcc和g++版本>=7.2.0 - -7、安装COCO API - -``` -cd CenterNet -git clone https://github.com/cocodataset/cocoapi.git -cd cocoapi/PythonAPI -make -python setup.py install --user -``` - -8、把THC-based DCNv2替换为ATen-based DCNv2 - -``` -cd CenterNet -git clone https://github.com/CaoWGG/TensorRT-CenterNet.gitcp -r TensorRT-CenterNet/readme/dcn src/lib/models/networks -``` - -**说明:**主要用的是TensorRT-CenterNet仓下的dcn目录,也可以仅下载dcn目录,然后放入到`CenterNet/src/lib/models/networks`目录下。 - -9、编译Deform Conv - -``` -cd src/lib/models/networks/dcn -python setup.py build_ext --inplace -``` - -**注意:**gcc和g++版本必须>=7.2.0,否则可能导致出错。 - -10、Change import - -把`CenterNet/src/lib/models/networks/pose_dla_dcn.py`和`CenterNet/src/lib/models/networks/resnet_dcn.py`中的`from .DCNv2.dcn_v2 import DCN`改为`from .dcn.modules.deform_conv import ModulatedDeformConvPack as DCN` - -11、打开`/root/anaconda3/envs/CenterNet/lib/python3.6/site-packages/torch/autograd/function.py`,定位到273行,把`_iter_filter(...)`函数改为如下: - -``` -def _iter_filter(condition, allow_unknown=False, condition_msg=None, - conversion=None): - def _iter(obj): - if conversion is not None: - obj = conversion(obj) - if condition(obj): - yield obj - #M<<<<<< - elif isinstance(obj,int): ## int to tensor - yield torch.tensor(obj) - #>>>>>> - elif obj is None: - return - elif isinstance(obj, (list, tuple)): - for o in obj: - for var in _iter(o): - yield var - elif allow_unknown: - yield obj - else: - raise ValueError("Auto nesting doesn't know how to process " - "an input object of type " + torch.typename(obj) + - (". Accepted types: " + condition_msg + - ", or lists/tuples of them" - if condition_msg else "")) - - - return _iter -``` - -12、下载[ctdet_coco_dla_2x.pth](https://drive.google.com/open?id=1pl_-ael8wERdUREEnaIfqOV_VF2bEVRT)模型,放入`CenterNet/models`目录下 -13、把`CenterNet/src/lib/opts.py中的add_argument('task', default='ctdet'....)`改为`add_argument('--task', default='ctdet'....)` -14、把提供的代码和脚本放入`CenterNet/src`目录下。 - -# 准备数据集 - -根据CenterNet官方数据集安装指导准备数据集:[DATA.md](https://github.com/xingyizhou/CenterNet/blob/master/readme/DATA.md),本示例以 **COCO 2017 Val** 数据集为例。 - -# PyTorch在线推理 - -由于后续导出onnx时需要修改CenterNet源码,修改后的代码无法进行PyTorch在线推理。因此这里先进行PyTorch在线推理验证。 - -运行pth_eval.py进行推理,推理完毕之后会输入精度和推理时间信息。 - -``` -python pth_eval.py --res_data_save_path=./pth_result -``` - -参数说明: - - --res_data_save_path:推理结果保存路径 - -# om模型推理模型转换 - -1. 模型转换。 - - 使用PyTorch将模型权重文件pth转换为onnx文件,再使用atc工具将onnx文件转为离线推理模型om文件。 - - - 导出onnx文件。 - - - 打开`CenterNet/src/lib/models/networks/dcn/functions/deform_conv.py`文件 - - - 修改`ModulatedDeformConvFunction`的`symbolic(...)`函数,把原函数改为如下: - - ``` - @staticmethod - def symbolic(g, input, weight, offset, bias, stride, padding, dilation, groups, deformable_groups): - return g.op("DeformableConv2D", - input, - weight, - offset, - bias, - deformable_groups_i=deformable_groups, - dilations_i=dilation, - groups_i=groups, - pads_i=padding, strides_i=stride) - ``` - - - 修改`ModulatedDeformConvFunction`的`forward(...)`函数,把原函数改为如下: - - ``` - @staticmethod - def forward(ctx, input, weight, offset, bias=None, stride=1, padding=0, dilation=1, groups=1, deformable_groups=1): - ctx.stride = stride - ctx.padding = padding - ctx.dilation = dilation - ctx.groups = groups - ctx.deformable_groups = deformable_groups - ctx.with_bias = bias is not None - if not ctx.with_bias: - bias = input.new_empty(1) # fake tensor - output = input.new_empty(ModulatedDeformConvFunction._infer_shape(ctx, input, weight)) - return output - ``` - - 打开`CenterNet/src/lib/models/networks/dcn/modules/deform_conv.py`文件,修改`ModulatedDeformConvPack`的`forward(...)`函数,把原函数改为如下: - - ``` - def forward(self, x): - out = self.conv_offset_mask(x) - o1, o2, mask = torch.chunk(out, 3, dim=1) - offset = torch.cat((o1, o2), dim=1) - mask = torch.sigmoid(mask) - - offset_y = offset.reshape(1, -1, 2, offset.shape[2], - offset.shape[3])[:, :, 0, ...].reshape(1, offset.shape[1] // 2, offset.shape[2], - offset.shape[3]) - offset_x = offset.reshape(1, -1, 2, offset.shape[2], - offset.shape[3])[:, :, 1, ...].reshape(1, offset.shape[1] // 2, offset.shape[2], - offset.shape[3]) - offset = torch.cat((offset_x, offset_y, mask), 1) - - return modulated_deform_conv(x, self.weight, offset, self.bias, self.stride, self.padding, self.dilation, self.groups, self.deformable_groups) - ``` - - 打开`/root/anaconda3/envs/CenterNet/lib/python3.6/site-packages/torch/onnx/symbolic.py`,在`reciprocal(...)`函数后边增加两个函数: - - ``` - def reshape(g, self, shape): - return view(g, self, shape) - - - def reshape_as(g, self, other): - shape = g.op('Shape', other) - return reshape(g, self, shape) - ``` - - - 运行`export_onnx.py`文件,导出onnx模型 - - ``` - python export_onnx.py - ``` - - 运行完之后,会在`CenterNet/models`目录下生成`ctdet_coco_dla_2x.onnx`模型文件。 - - - 运行`modify_onnx.py`文件,修改onnx模型文件 - - ``` - python modify_onnx.py - ``` - - 运行完之后,会在`CenterNet/models`目录下生成`ctdet_coco_dla_2x_modify.onnx`模型文件。 - - 2. 使用atc工具将onnx模型转om模型。 - - - 根据实际情况,修改`onnx2om.sh`脚本中的环境变量,具体的脚本示例如下: - - ``` - #!/bin/bash - clear - - export install_path=/usr/local/Ascend/ascend-toolkit/latest - export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH - export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH - export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH - export ASCEND_OPP_PATH=${install_path}/opp - - atc --framework=5 --model=../models/ctdet_coco_dla_2x_modify.onnx --output=../models/ctdet_coco_dla_2x \ - --input_format=NCHW --input_shape=image:1,3,512,512 --log=error --soc_version=Ascend310 - rm -rf fusion_result.json kernel_meta - ``` - - 参数说明: - - - --model:为onnx模型文件 - - --framework:5代表onnx模型 - - - --output:输出的om模型 - - --input_format:输入数据的格式 - - --input_shape:输入数据的shape - - --log:日志等级 - - --soc_version:部署芯片类型 - - - 执行onnx2om.sh脚本,将onnx文件转为离线推理模型文件om文件。 - - ``` - bash onnx2om.sh - ``` - - 运行完之后,会在`CenterNet/models`目录下生成`ctdet_coco_dla_2x.om`模型文件。 - -2. 开始推理验证。 - - - 根据实际情况,修改`benchmark_infer.sh`脚本中的代码,具体的脚本示例如下: - - ``` - #!/bin/bash - clear - - export install_path=/usr/local/Ascend/ascend-toolkit/latest - export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH - export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH - export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH - export ASCEND_OPP_PATH=${install_path}/opp - - ./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=../models/ctdet_coco_dla_2x.om \-input_text_path=./pre_bin/bin_file.info -input_width=512 -input_height=512 -output_binary=true -useDvpp=false - ``` - - - 执行`benchmark_infer.sh`脚本,进行benchmark推理。 - - ``` - sh benchmark_infer.sh - ``` - - - 推理数据后处理与精度统计。 - 运行postprocess.py脚本,进行后处理和精度统计。 - - ``` - python postprocess.py \ - --infer_res_save_path=./result/dumpOutput_device0 \ - --pre_data_save_path=./pre_bin \ - --res_data_save_path=./om_result - ``` - - 参数说明: - - - --infer_res_save_path:benchmark推理结果保存路径 - - --pre_data_save_path:预处理数据保存路径 - - --res_data_save_path:后处理结果保存路径 - - - +# 参考论文 + +- [Objects as Points](https://arxiv.org/abs/1904.07850) + +# 参考实现 + +- [xingyizhou/CenterNet](https://github.com/xingyizhou/CenterNet) +- [CaoWGG/TensorRT-CenterNet](https://github.com/CaoWGG/TensorRT-CenterNet) + +# 环境搭建 + +1、创建一个conda环境 + +```shell +conda create --nameCenterNet python=3.6 +``` + +激活环境 + +``` +conda activate CenterNet +``` + +2、clone仓库 + +``` +git clone https://github.com/xingyizhou/CenterNet +``` + +3、安装依赖 + +``` +cd CenterNet +pip install -r requirements.txt +``` + +4、安装pytorch v1.0.0 + +1) 下载[torch-1.0.0-cp36-cp36m-linux_x86_64.whl](https://download.pytorch.org/whl/cu100/torch-1.0.0-cp36-cp36m-linux_x86_64.whl) + +2) 安装 + +``` +pip install torch-1.0.0-cp36-cp36m-linux_x86_64.whl +``` + +**注意:**1) pytorch版本必须是1.0.0;2) 需确保是GPU环境;3) CUDA版本为10.2 + +5、安装其它依赖 + +``` +pip install tqdm==4.19.9 torchvision==0.2.2 onnx==1.8.1 onnxruntime==1.7.0 skl2onnx==1.8.0 +``` + +6、确保gcc和g++版本>=7.2.0 + +7、安装COCO API + +``` +cd CenterNet +git clone https://github.com/cocodataset/cocoapi.git +cd cocoapi/PythonAPI +make +python setup.py install --user +``` + +8、把THC-based DCNv2替换为ATen-based DCNv2 + +``` +cd CenterNet +git clone https://github.com/CaoWGG/TensorRT-CenterNet.gitcp -r TensorRT-CenterNet/readme/dcn src/lib/models/networks +``` + +**说明:**主要用的是TensorRT-CenterNet仓下的dcn目录,也可以仅下载dcn目录,然后放入到`CenterNet/src/lib/models/networks`目录下。 + +9、编译Deform Conv + +``` +cd src/lib/models/networks/dcn +python setup.py build_ext --inplace +``` + +**注意:**gcc和g++版本必须>=7.2.0,否则可能导致出错。 + +10、Change import + +把`CenterNet/src/lib/models/networks/pose_dla_dcn.py`和`CenterNet/src/lib/models/networks/resnet_dcn.py`中的`from .DCNv2.dcn_v2 import DCN`改为`from .dcn.modules.deform_conv import ModulatedDeformConvPack as DCN` + +11、打开`/root/anaconda3/envs/CenterNet/lib/python3.6/site-packages/torch/autograd/function.py`,定位到273行,把`_iter_filter(...)`函数改为如下: + +``` +def _iter_filter(condition, allow_unknown=False, condition_msg=None, + conversion=None): + def _iter(obj): + if conversion is not None: + obj = conversion(obj) + if condition(obj): + yield obj + #M<<<<<< + elif isinstance(obj,int): ## int to tensor + yield torch.tensor(obj) + #>>>>>> + elif obj is None: + return + elif isinstance(obj, (list, tuple)): + for o in obj: + for var in _iter(o): + yield var + elif allow_unknown: + yield obj + else: + raise ValueError("Auto nesting doesn't know how to process " + "an input object of type " + torch.typename(obj) + + (". Accepted types: " + condition_msg + + ", or lists/tuples of them" + if condition_msg else "")) + + + return _iter +``` + +12、下载[ctdet_coco_dla_2x.pth](https://drive.google.com/open?id=1pl_-ael8wERdUREEnaIfqOV_VF2bEVRT)模型,放入`CenterNet/models`目录下 +13、把`CenterNet/src/lib/opts.py中的add_argument('task', default='ctdet'....)`改为`add_argument('--task', default='ctdet'....)` +14、把提供的代码和脚本放入`CenterNet/src`目录下。 + +# 准备数据集 + +根据CenterNet官方数据集安装指导准备数据集:[DATA.md](https://github.com/xingyizhou/CenterNet/blob/master/readme/DATA.md),本示例以 **COCO 2017 Val** 数据集为例。 + +# PyTorch在线推理 + +由于后续导出onnx时需要修改CenterNet源码,修改后的代码无法进行PyTorch在线推理。因此这里先进行PyTorch在线推理验证。 + +运行pth_eval.py进行推理,推理完毕之后会输入精度和推理时间信息。 + +``` +python pth_eval.py --res_data_save_path=./pth_result +``` + +参数说明: + - --res_data_save_path:推理结果保存路径 + +# om模型推理模型转换 + +1. 模型转换。 + + 使用PyTorch将模型权重文件pth转换为onnx文件,再使用atc工具将onnx文件转为离线推理模型om文件。 + + - 导出onnx文件。 + + - 打开`CenterNet/src/lib/models/networks/dcn/functions/deform_conv.py`文件 + + - 修改`ModulatedDeformConvFunction`的`symbolic(...)`函数,把原函数改为如下: + + ``` + @staticmethod + def symbolic(g, input, weight, offset, bias, stride, padding, dilation, groups, deformable_groups): + return g.op("DeformableConv2D", + input, + weight, + offset, + bias, + deformable_groups_i=deformable_groups, + dilations_i=dilation, + groups_i=groups, + pads_i=padding, strides_i=stride) + ``` + + - 修改`ModulatedDeformConvFunction`的`forward(...)`函数,把原函数改为如下: + + ``` + @staticmethod + def forward(ctx, input, weight, offset, bias=None, stride=1, padding=0, dilation=1, groups=1, deformable_groups=1): + ctx.stride = stride + ctx.padding = padding + ctx.dilation = dilation + ctx.groups = groups + ctx.deformable_groups = deformable_groups + ctx.with_bias = bias is not None + if not ctx.with_bias: + bias = input.new_empty(1) # fake tensor + output = input.new_empty(ModulatedDeformConvFunction._infer_shape(ctx, input, weight)) + return output + ``` + - 打开`CenterNet/src/lib/models/networks/dcn/modules/deform_conv.py`文件,修改`ModulatedDeformConvPack`的`forward(...)`函数,把原函数改为如下: + + ``` + def forward(self, x): + out = self.conv_offset_mask(x) + o1, o2, mask = torch.chunk(out, 3, dim=1) + offset = torch.cat((o1, o2), dim=1) + mask = torch.sigmoid(mask) + + offset_y = offset.reshape(1, -1, 2, offset.shape[2], + offset.shape[3])[:, :, 0, ...].reshape(1, offset.shape[1] // 2, offset.shape[2], + offset.shape[3]) + offset_x = offset.reshape(1, -1, 2, offset.shape[2], + offset.shape[3])[:, :, 1, ...].reshape(1, offset.shape[1] // 2, offset.shape[2], + offset.shape[3]) + offset = torch.cat((offset_x, offset_y, mask), 1) + + return modulated_deform_conv(x, self.weight, offset, self.bias, self.stride, self.padding, self.dilation, self.groups, self.deformable_groups) + ``` + - 打开`/root/anaconda3/envs/CenterNet/lib/python3.6/site-packages/torch/onnx/symbolic.py`,在`reciprocal(...)`函数后边增加两个函数: + + ``` + def reshape(g, self, shape): + return view(g, self, shape) + + + def reshape_as(g, self, other): + shape = g.op('Shape', other) + return reshape(g, self, shape) + ``` + + - 运行`export_onnx.py`文件,导出onnx模型 + + ``` + python export_onnx.py + ``` + + 运行完之后,会在`CenterNet/models`目录下生成`ctdet_coco_dla_2x.onnx`模型文件。 + + - 运行`modify_onnx.py`文件,修改onnx模型文件 + + ``` + python modify_onnx.py + ``` + + 运行完之后,会在`CenterNet/models`目录下生成`ctdet_coco_dla_2x_modify.onnx`模型文件。 + + 2. 使用atc工具将onnx模型转om模型。 + + - 根据实际情况,修改`onnx2om.sh`脚本中的环境变量,具体的脚本示例如下: + + ``` + #!/bin/bash + clear + + export install_path=/usr/local/Ascend/ascend-toolkit/latest + export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH + export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH + export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH + export ASCEND_OPP_PATH=${install_path}/opp + + atc --framework=5 --model=../models/ctdet_coco_dla_2x_modify.onnx --output=../models/ctdet_coco_dla_2x \ + --input_format=NCHW --input_shape=image:1,3,512,512 --log=error --soc_version=Ascend310 + rm -rf fusion_result.json kernel_meta + ``` + + 参数说明: + + - --model:为onnx模型文件 + - --framework:5代表onnx模型 + + - --output:输出的om模型 + - --input_format:输入数据的格式 + - --input_shape:输入数据的shape + - --log:日志等级 + - --soc_version:部署芯片类型 + + - 执行onnx2om.sh脚本,将onnx文件转为离线推理模型文件om文件。 + + ``` + bash onnx2om.sh + ``` + + 运行完之后,会在`CenterNet/models`目录下生成`ctdet_coco_dla_2x.om`模型文件。 + +2. 开始推理验证。 + + - 根据实际情况,修改`benchmark_infer.sh`脚本中的代码,具体的脚本示例如下: + + ``` + #!/bin/bash + clear + + export install_path=/usr/local/Ascend/ascend-toolkit/latest + export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH + export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH + export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH + export ASCEND_OPP_PATH=${install_path}/opp + + ./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=../models/ctdet_coco_dla_2x.om \-input_text_path=./pre_bin/bin_file.info -input_width=512 -input_height=512 -output_binary=true -useDvpp=false + ``` + + - 执行`benchmark_infer.sh`脚本,进行benchmark推理。 + + ``` + sh benchmark_infer.sh + ``` + + - 推理数据后处理与精度统计。 + 运行postprocess.py脚本,进行后处理和精度统计。 + + ``` + python postprocess.py \ + --infer_res_save_path=./result/dumpOutput_device0 \ + --pre_data_save_path=./pre_bin \ + --res_data_save_path=./om_result + ``` + + 参数说明: + + - --infer_res_save_path:benchmark推理结果保存路径 + - --pre_data_save_path:预处理数据保存路径 + - --res_data_save_path:后处理结果保存路径 + + + diff --git a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/export_onnx.py b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/export_onnx.py index 7d6d385c280ec888539eacc112da28e59882f5cc..5173af1d6e49b2b801081b77178094b57789a9dd 100644 --- a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/export_onnx.py +++ b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/export_onnx.py @@ -1,114 +1,114 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - -import _init_paths -import os -import torch -import torch.onnx as onnx -from lib.opts import opts -from types import MethodType -from collections import OrderedDict -from torch.onnx import OperatorExportTypes -from lib.models.model import create_model, load_model - -# 清空终端 -os.system('clear') - - -## onnx is not support dict return value -## for dla34 -def pose_dla_forward(self, x): - x = self.base(x) - x = self.dla_up(x) - y = [] - for i in range(self.last_level - self.first_level): - y.append(x[i].clone()) - self.ida_up(y, 0, len(y)) - ret = [] ## change dict to list - for head in self.heads: - ret.append(self.__getattr__(head)(y[-1])) - return ret - - -## for dla34v0 -def dlav0_forward(self, x): - x = self.base(x) - x = self.dla_up(x[self.first_level:]) - # x = self.fc(x) - # y = self.softmax(self.up(x)) - ret = [] ## change dict to list - for head in self.heads: - ret.append(self.__getattr__(head)(x)) - return ret - - -## for resdcn -def resnet_dcn_forward(self, x): - x = self.conv1(x) - x = self.bn1(x) - x = self.relu(x) - x = self.maxpool(x) - - x = self.layer1(x) - x = self.layer2(x) - x = self.layer3(x) - x = self.layer4(x) - x = self.deconv_layers(x) - ret = [] ## change dict to list - for head in self.heads: - ret.append(self.__getattr__(head)(x)) - return ret - - -forward = {'dla': pose_dla_forward, 'dlav0': dlav0_forward, 'resdcn': resnet_dcn_forward} - -opt = opts().init() -opt.arch = 'dla_34' -opt.heads = OrderedDict([('hm', 80), ('reg', 2), ('wh', 2)]) -opt.head_conv = 256 if 'dla' in opt.arch else 64 -print(opt) -model = create_model(opt.arch, opt.heads, opt.head_conv) -model.forward = MethodType(forward[opt.arch.split('_')[0]], model) -load_model(model, '../models/ctdet_coco_dla_2x.pth') -model.eval() -model.cuda() - -print('\n[INFO] Export to onnx ...') -input = torch.ones([1, 3, 512, 512]).cuda() -onnx.export(model, - input, - "../models/ctdet_coco_dla_2x.onnx", - operator_export_type=OperatorExportTypes.ONNX, - verbose=True, - input_names=['image'], - output_names=['hm', 'wh', 'reg']) -print('[INFO] Done!') +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + +import _init_paths +import os +import torch +import torch.onnx as onnx +from lib.opts import opts +from types import MethodType +from collections import OrderedDict +from torch.onnx import OperatorExportTypes +from lib.models.model import create_model, load_model + +# 清空终端 +os.system('clear') + + +## onnx is not support dict return value +## for dla34 +def pose_dla_forward(self, x): + x = self.base(x) + x = self.dla_up(x) + y = [] + for i in range(self.last_level - self.first_level): + y.append(x[i].clone()) + self.ida_up(y, 0, len(y)) + ret = [] ## change dict to list + for head in self.heads: + ret.append(self.__getattr__(head)(y[-1])) + return ret + + +## for dla34v0 +def dlav0_forward(self, x): + x = self.base(x) + x = self.dla_up(x[self.first_level:]) + # x = self.fc(x) + # y = self.softmax(self.up(x)) + ret = [] ## change dict to list + for head in self.heads: + ret.append(self.__getattr__(head)(x)) + return ret + + +## for resdcn +def resnet_dcn_forward(self, x): + x = self.conv1(x) + x = self.bn1(x) + x = self.relu(x) + x = self.maxpool(x) + + x = self.layer1(x) + x = self.layer2(x) + x = self.layer3(x) + x = self.layer4(x) + x = self.deconv_layers(x) + ret = [] ## change dict to list + for head in self.heads: + ret.append(self.__getattr__(head)(x)) + return ret + + +forward = {'dla': pose_dla_forward, 'dlav0': dlav0_forward, 'resdcn': resnet_dcn_forward} + +opt = opts().init() +opt.arch = 'dla_34' +opt.heads = OrderedDict([('hm', 80), ('reg', 2), ('wh', 2)]) +opt.head_conv = 256 if 'dla' in opt.arch else 64 +print(opt) +model = create_model(opt.arch, opt.heads, opt.head_conv) +model.forward = MethodType(forward[opt.arch.split('_')[0]], model) +load_model(model, '../models/ctdet_coco_dla_2x.pth') +model.eval() +model.cuda() + +print('\n[INFO] Export to onnx ...') +input = torch.ones([1, 3, 512, 512]).cuda() +onnx.export(model, + input, + "../models/ctdet_coco_dla_2x.onnx", + operator_export_type=OperatorExportTypes.ONNX, + verbose=True, + input_names=['image'], + output_names=['hm', 'wh', 'reg']) +print('[INFO] Done!') diff --git a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/modelzoo_level.txt b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/modelzoo_level.txt index a17c8f95fa388fbc6d253e2cd7cfd0b73b734073..a829ab59b97a1022dd6fc33b59b7ae0d55009432 100644 --- a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/modelzoo_level.txt +++ b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/modify_onnx.py b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/modify_onnx.py index 5371b354999dc8efa5a9338b4572891f36c7627d..99d51ad1487994eaef6ebf6686d41cb6eacb46de 100644 --- a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/modify_onnx.py +++ b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/modify_onnx.py @@ -1,57 +1,57 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - -import os -from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode - -# 清空终端 -os.system('clear') - -# 加载模型 -oxgraph = OXGraph('../models/ctdet_coco_dla_2x.onnx') - -# 给节点添加名字 -for idx, node in enumerate(oxgraph._node): - node.name = node.op_type + '_' + str(idx) - node.doc_string = '' -oxgraph.save_new_model('../models/ctdet_coco_dla_2x_modify.onnx') - -# 修改DeformableConv2D的属性 -oxgraph = OXGraph('../models/ctdet_coco_dla_2x_modify.onnx') -oxnodes = oxgraph.get_oxnode_by_op_type('DeformableConv2D') -for oxnode in oxnodes: - oxnode.set_attribute('dilations', [1, 1]) - oxnode.set_attribute('pads', [1, 1]) - oxnode.set_attribute('strides', [1, 1]) - -# 保存新模型 -oxgraph.save_new_model('../models/ctdet_coco_dla_2x_modify.onnx') +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + +import os +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +# 清空终端 +os.system('clear') + +# 加载模型 +oxgraph = OXGraph('../models/ctdet_coco_dla_2x.onnx') + +# 给节点添加名字 +for idx, node in enumerate(oxgraph._node): + node.name = node.op_type + '_' + str(idx) + node.doc_string = '' +oxgraph.save_new_model('../models/ctdet_coco_dla_2x_modify.onnx') + +# 修改DeformableConv2D的属性 +oxgraph = OXGraph('../models/ctdet_coco_dla_2x_modify.onnx') +oxnodes = oxgraph.get_oxnode_by_op_type('DeformableConv2D') +for oxnode in oxnodes: + oxnode.set_attribute('dilations', [1, 1]) + oxnode.set_attribute('pads', [1, 1]) + oxnode.set_attribute('strides', [1, 1]) + +# 保存新模型 +oxgraph.save_new_model('../models/ctdet_coco_dla_2x_modify.onnx') diff --git a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/postprocess.py b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/postprocess.py index a79f03d9795174e9a8847837435c809b636d90bf..099262c6326750e16774f6b0ba9ba41e076905cf 100644 --- a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/postprocess.py +++ b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/postprocess.py @@ -1,157 +1,157 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - -import _init_paths -import os -from tqdm import tqdm -import argparse -import shutil -import pickle -import glob -from os.path import join -import numpy as np -import torch -from logger import Logger -from datasets.dataset_factory import dataset_factory -from lib.detectors.ctdet import CtdetDetector -from lib.detectors.detector_factory import detector_factory -from lib.opts import opts -from lib.models.utils import flip_tensor -from lib.models.decode import ctdet_decode - -# 清空终端 -os.system('clear') - - -class ModelWarper(CtdetDetector): - def __init__(self, opt): - super(CtdetDetector, self).__init__(opt) - - def process(self, output): - hm = torch.from_numpy(output['hm']).sigmoid_() - wh = torch.from_numpy(output['wh']) - reg = torch.from_numpy(output['reg']) if self.opt.reg_offset else None - if self.opt.flip_test: - hm = (hm[0:1] + flip_tensor(hm[1:2])) / 2 - wh = (wh[0:1] + flip_tensor(wh[1:2])) / 2 - reg = reg[0:1] if reg is not None else None - dets = ctdet_decode(hm, wh, reg=reg, cat_spec_wh=self.opt.cat_spec_wh, K=self.opt.K) - - return dets - - def run(self, output, meta, scale): - detections = [] - dets = self.process(output) - dets = self.post_process(dets, meta, scale) - detections.append(dets) - - results = self.merge_outputs(detections) - return results - - -def postprocess(infer_res_save_path, pre_data_save_path, opt): - os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpus_str - - Dataset = dataset_factory[opt.dataset] - opt = opts().update_dataset_info_and_set_heads(opt, Dataset) - print(opt) - Logger(opt) - Detector = detector_factory[opt.task] - - split = 'val' if not opt.trainval else 'test' - dataset = Dataset(opt, split) - detector = Detector(opt) - - model_warper = ModelWarper(detector.opt) - - # 创建目录 - if os.path.exists(res_data_save_path): - shutil.rmtree(res_data_save_path) - os.makedirs(res_data_save_path) - - # 读取文件个数 - bin_file_list = glob.glob(join(infer_res_save_path, '*.bin')) - bin_file_num = len(bin_file_list) // 3 - - # 加载字典 - image_id_dict = pickle.load(open(join(pre_data_save_path, 'image_id_dict.pkl'), 'rb')) - meta_dict = pickle.load(open(join(pre_data_save_path, 'meta_dict.pkl'), 'rb')) - - # 后处理 - print('\n[INFO] Postprocessing ...') - results = {} - for i in tqdm(range(bin_file_num)): - hm = np.fromfile(join(infer_res_save_path, str(i) + '_3.bin'), dtype=np.float32).reshape(1, 80, 128, 128) - wh = np.fromfile(join(infer_res_save_path, str(i) + '_1.bin'), dtype=np.float32).reshape(1, 2, 128, 128) - reg = np.fromfile(join(infer_res_save_path, str(i) + '_2.bin'), dtype=np.float32).reshape(1, 2, 128, 128) - - output = {'hm': hm, "wh": wh, "reg": reg} - meta = meta_dict[i] - scale = [1.0] - - result = model_warper.run(output, meta, scale) - - results[image_id_dict[i]] = result - print('[INFO] Postprocess done!') - - # 计算精度 - print('\n[INFO] Calculate accuracy ...') - dataset.run_eval(results, res_data_save_path) - - -if __name__ == '__main__': - ''' - Using Example: - - python postprocess.py \ - --infer_res_save_path=./result/dumpOutput_device0 \ - --pre_data_save_path=./pre_bin \ - --res_data_save_path=./om_result - ''' - - # 解析参数 - parser = argparse.ArgumentParser() - parser.add_argument('--infer_res_save_path', required=True) - parser.add_argument('--pre_data_save_path', required=True) - parser.add_argument('--res_data_save_path', required=True) - - opt = parser.parse_args() - infer_res_save_path = opt.infer_res_save_path - pre_data_save_path = opt.pre_data_save_path - res_data_save_path = opt.res_data_save_path - - # 创建并解析opt - opt = opts().init('--task ctdet --exp_id coco_dla --not_prefetch_test ' - '--load_model ../models/ctdet_coco_dla_2x.pth'.split(' ')) - - # 处理数据 - results = postprocess(infer_res_save_path, pre_data_save_path, opt) +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + +import _init_paths +import os +from tqdm import tqdm +import argparse +import shutil +import pickle +import glob +from os.path import join +import numpy as np +import torch +from logger import Logger +from datasets.dataset_factory import dataset_factory +from lib.detectors.ctdet import CtdetDetector +from lib.detectors.detector_factory import detector_factory +from lib.opts import opts +from lib.models.utils import flip_tensor +from lib.models.decode import ctdet_decode + +# 清空终端 +os.system('clear') + + +class ModelWarper(CtdetDetector): + def __init__(self, opt): + super(CtdetDetector, self).__init__(opt) + + def process(self, output): + hm = torch.from_numpy(output['hm']).sigmoid_() + wh = torch.from_numpy(output['wh']) + reg = torch.from_numpy(output['reg']) if self.opt.reg_offset else None + if self.opt.flip_test: + hm = (hm[0:1] + flip_tensor(hm[1:2])) / 2 + wh = (wh[0:1] + flip_tensor(wh[1:2])) / 2 + reg = reg[0:1] if reg is not None else None + dets = ctdet_decode(hm, wh, reg=reg, cat_spec_wh=self.opt.cat_spec_wh, K=self.opt.K) + + return dets + + def run(self, output, meta, scale): + detections = [] + dets = self.process(output) + dets = self.post_process(dets, meta, scale) + detections.append(dets) + + results = self.merge_outputs(detections) + return results + + +def postprocess(infer_res_save_path, pre_data_save_path, opt): + os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpus_str + + Dataset = dataset_factory[opt.dataset] + opt = opts().update_dataset_info_and_set_heads(opt, Dataset) + print(opt) + Logger(opt) + Detector = detector_factory[opt.task] + + split = 'val' if not opt.trainval else 'test' + dataset = Dataset(opt, split) + detector = Detector(opt) + + model_warper = ModelWarper(detector.opt) + + # 创建目录 + if os.path.exists(res_data_save_path): + shutil.rmtree(res_data_save_path) + os.makedirs(res_data_save_path) + + # 读取文件个数 + bin_file_list = glob.glob(join(infer_res_save_path, '*.bin')) + bin_file_num = len(bin_file_list) // 3 + + # 加载字典 + image_id_dict = pickle.load(open(join(pre_data_save_path, 'image_id_dict.pkl'), 'rb')) + meta_dict = pickle.load(open(join(pre_data_save_path, 'meta_dict.pkl'), 'rb')) + + # 后处理 + print('\n[INFO] Postprocessing ...') + results = {} + for i in tqdm(range(bin_file_num)): + hm = np.fromfile(join(infer_res_save_path, str(i) + '_3.bin'), dtype=np.float32).reshape(1, 80, 128, 128) + wh = np.fromfile(join(infer_res_save_path, str(i) + '_1.bin'), dtype=np.float32).reshape(1, 2, 128, 128) + reg = np.fromfile(join(infer_res_save_path, str(i) + '_2.bin'), dtype=np.float32).reshape(1, 2, 128, 128) + + output = {'hm': hm, "wh": wh, "reg": reg} + meta = meta_dict[i] + scale = [1.0] + + result = model_warper.run(output, meta, scale) + + results[image_id_dict[i]] = result + print('[INFO] Postprocess done!') + + # 计算精度 + print('\n[INFO] Calculate accuracy ...') + dataset.run_eval(results, res_data_save_path) + + +if __name__ == '__main__': + ''' + Using Example: + + python postprocess.py \ + --infer_res_save_path=./result/dumpOutput_device0 \ + --pre_data_save_path=./pre_bin \ + --res_data_save_path=./om_result + ''' + + # 解析参数 + parser = argparse.ArgumentParser() + parser.add_argument('--infer_res_save_path', required=True) + parser.add_argument('--pre_data_save_path', required=True) + parser.add_argument('--res_data_save_path', required=True) + + opt = parser.parse_args() + infer_res_save_path = opt.infer_res_save_path + pre_data_save_path = opt.pre_data_save_path + res_data_save_path = opt.res_data_save_path + + # 创建并解析opt + opt = opts().init('--task ctdet --exp_id coco_dla --not_prefetch_test ' + '--load_model ../models/ctdet_coco_dla_2x.pth'.split(' ')) + + # 处理数据 + results = postprocess(infer_res_save_path, pre_data_save_path, opt) diff --git a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/preprocess.py b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/preprocess.py index 7001d61d09c865da61e03f859ba412ff03c36d75..84347016ba46344edf2d37760bb94cf3c9678ab5 100644 --- a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/preprocess.py +++ b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/preprocess.py @@ -1,127 +1,127 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - -import _init_paths -import argparse -import shutil -import pickle -import os -import cv2 -from os.path import join -from logger import Logger -from tqdm import tqdm -from datasets.dataset_factory import dataset_factory -from lib.detectors.ctdet import CtdetDetector -from lib.detectors.detector_factory import detector_factory -from lib.opts import opts - -# 清空终端 -os.system('clear') - - -class ModelWarper(CtdetDetector): - def __init__(self, opt): - super(CtdetDetector, self).__init__(opt) - - def run(self, image_path, image_save_path, meta_save_path): - image = cv2.imread(image_path) - scale = self.scales[0] - images, meta = self.pre_process(image, scale, None) - - # 保存数据 - images = images.numpy() - images.tofile(image_save_path) - - return meta - - -def preprocess(opt, pre_data_save_path): - os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpus_str - - Dataset = dataset_factory[opt.dataset] - opt = opts().update_dataset_info_and_set_heads(opt, Dataset) - print(opt) - Logger(opt) - Detector = detector_factory[opt.task] - - split = 'val' if not opt.trainval else 'test' - dataset = Dataset(opt, split) - detector = Detector(opt) - - model_warper = ModelWarper(detector.opt) - - # 创建目录 - if os.path.exists(pre_data_save_path): - shutil.rmtree(pre_data_save_path) - os.makedirs(pre_data_save_path) - - # 处理数据 - info_file_path = join(pre_data_save_path, 'bin_file.info') - with open(info_file_path, 'wt', encoding='utf-8') as f_info: - image_id_dict = {} - meta_dict = {} - num_iters = len(dataset) - for i in tqdm(range(num_iters)): - image_id = dataset.images[i] - image_info = dataset.coco.loadImgs(ids=[image_id])[0] - image_path = join(dataset.img_dir, image_info['file_name']) - image_save_path = join(pre_data_save_path, str(i) + '.bin') - meta_save_path = join(pre_data_save_path, str(i) + '.pkl') - meta = model_warper.run(image_path, image_save_path, meta_save_path) - f_info.write(str(i) + " ./" + str(i) + '.bin 512 512' + '\n') - image_id_dict[i] = image_id - meta_dict[i] = meta - pickle.dump(image_id_dict, open(join(pre_data_save_path, 'image_id_dict.pkl'), 'wb')) - pickle.dump(meta_dict, open(join(pre_data_save_path, 'meta_dict.pkl'), 'wb')) - - -if __name__ == '__main__': - ''' - Using Example: - - python preprocess.py --pre_data_save_path=./pre_bin - ''' - - # 解析参数 - parser = argparse.ArgumentParser() - parser.add_argument('--pre_data_save_path', required=True) - opt = parser.parse_args() - pre_data_save_path = opt.pre_data_save_path - - # 创建并解析opt - opt = opts().init('--task ctdet --exp_id coco_dla --not_prefetch_test ' - '--load_model ../models/ctdet_coco_dla_2x.pth'.split(' ')) - - # 处理数据 - print('\n[INFO] Preprocessing ...') - preprocess(opt, pre_data_save_path) - print('[INFO] Preprocess done!') +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + +import _init_paths +import argparse +import shutil +import pickle +import os +import cv2 +from os.path import join +from logger import Logger +from tqdm import tqdm +from datasets.dataset_factory import dataset_factory +from lib.detectors.ctdet import CtdetDetector +from lib.detectors.detector_factory import detector_factory +from lib.opts import opts + +# 清空终端 +os.system('clear') + + +class ModelWarper(CtdetDetector): + def __init__(self, opt): + super(CtdetDetector, self).__init__(opt) + + def run(self, image_path, image_save_path, meta_save_path): + image = cv2.imread(image_path) + scale = self.scales[0] + images, meta = self.pre_process(image, scale, None) + + # 保存数据 + images = images.numpy() + images.tofile(image_save_path) + + return meta + + +def preprocess(opt, pre_data_save_path): + os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpus_str + + Dataset = dataset_factory[opt.dataset] + opt = opts().update_dataset_info_and_set_heads(opt, Dataset) + print(opt) + Logger(opt) + Detector = detector_factory[opt.task] + + split = 'val' if not opt.trainval else 'test' + dataset = Dataset(opt, split) + detector = Detector(opt) + + model_warper = ModelWarper(detector.opt) + + # 创建目录 + if os.path.exists(pre_data_save_path): + shutil.rmtree(pre_data_save_path) + os.makedirs(pre_data_save_path) + + # 处理数据 + info_file_path = join(pre_data_save_path, 'bin_file.info') + with open(info_file_path, 'wt', encoding='utf-8') as f_info: + image_id_dict = {} + meta_dict = {} + num_iters = len(dataset) + for i in tqdm(range(num_iters)): + image_id = dataset.images[i] + image_info = dataset.coco.loadImgs(ids=[image_id])[0] + image_path = join(dataset.img_dir, image_info['file_name']) + image_save_path = join(pre_data_save_path, str(i) + '.bin') + meta_save_path = join(pre_data_save_path, str(i) + '.pkl') + meta = model_warper.run(image_path, image_save_path, meta_save_path) + f_info.write(str(i) + " ./" + str(i) + '.bin 512 512' + '\n') + image_id_dict[i] = image_id + meta_dict[i] = meta + pickle.dump(image_id_dict, open(join(pre_data_save_path, 'image_id_dict.pkl'), 'wb')) + pickle.dump(meta_dict, open(join(pre_data_save_path, 'meta_dict.pkl'), 'wb')) + + +if __name__ == '__main__': + ''' + Using Example: + + python preprocess.py --pre_data_save_path=./pre_bin + ''' + + # 解析参数 + parser = argparse.ArgumentParser() + parser.add_argument('--pre_data_save_path', required=True) + opt = parser.parse_args() + pre_data_save_path = opt.pre_data_save_path + + # 创建并解析opt + opt = opts().init('--task ctdet --exp_id coco_dla --not_prefetch_test ' + '--load_model ../models/ctdet_coco_dla_2x.pth'.split(' ')) + + # 处理数据 + print('\n[INFO] Preprocessing ...') + preprocess(opt, pre_data_save_path) + print('[INFO] Preprocess done!') diff --git a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/pth_eval.py b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/pth_eval.py index 0fa6035d108345e88ff806a2237a9255bd5b9bdc..7a5b41ce8523e5ae83d0a80dcdd2458f485fa941 100644 --- a/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/pth_eval.py +++ b/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch/pth_eval.py @@ -1,115 +1,115 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - -import _init_paths -import os -import time -import shutil -import argparse -from tqdm import tqdm -from opts import opts -from logger import Logger -from datasets.dataset_factory import dataset_factory -from detectors.detector_factory import detector_factory - -# 清空终端 -os.system('clear') - - -def eval(opt, res_data_save_path): - os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpus_str - - Dataset = dataset_factory[opt.dataset] - opt = opts().update_dataset_info_and_set_heads(opt, Dataset) - print(opt) - Logger(opt) - Detector = detector_factory[opt.task] - - split = 'val' if not opt.trainval else 'test' - dataset = Dataset(opt, split) - detector = Detector(opt) - - # 创建目录 - if os.path.exists(res_data_save_path): - shutil.rmtree(res_data_save_path) - os.makedirs(res_data_save_path) - - print('\n[INFO] Infering ...') - results = {} - num_iters = len(dataset) - total_infer_time = 0 - total_infer_num = 0 - for ind in tqdm(range(num_iters)): - img_id = dataset.images[ind] - img_info = dataset.coco.loadImgs(ids=[img_id])[0] - img_path = os.path.join(dataset.img_dir, img_info['file_name']) - - start_time = time.perf_counter() - ret = detector.run(img_path) - end_time = time.perf_counter() - total_infer_time += end_time - start_time - total_infer_num += 1 - - results[img_id] = ret['results'] - print('\n[INFO] Infer done!') - - print('\n[INFO] Calculate accuracy ...') - dataset.run_eval(results, res_data_save_path) - - # 推理时间 - print('\n[INFO] Time:') - msg = 'total infer num: ' + str(total_infer_num) + '\n' + \ - 'total infer time(ms): ' + str(total_infer_time * 1000) + '\n' + \ - 'average infer time(ms): ' + str(total_infer_time * 1000 / total_infer_num) + '\n' - print(msg) - - -if __name__ == '__main__': - ''' - Using Example: - - python pth_eval.py --res_data_save_path=./pth_result - ''' - - # 解析参数 - parser = argparse.ArgumentParser() - parser.add_argument('--res_data_save_path', required=True) - - opt = parser.parse_args() - res_data_save_path = opt.res_data_save_path - - # 创建并解析opt - opt = opts().init('--task ctdet --exp_id coco_dla --not_prefetch_test ' - '--load_model ../models/ctdet_coco_dla_2x.pth'.split(' ')) - - # 处理数据 - eval(opt, res_data_save_path) +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + +import _init_paths +import os +import time +import shutil +import argparse +from tqdm import tqdm +from opts import opts +from logger import Logger +from datasets.dataset_factory import dataset_factory +from detectors.detector_factory import detector_factory + +# 清空终端 +os.system('clear') + + +def eval(opt, res_data_save_path): + os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpus_str + + Dataset = dataset_factory[opt.dataset] + opt = opts().update_dataset_info_and_set_heads(opt, Dataset) + print(opt) + Logger(opt) + Detector = detector_factory[opt.task] + + split = 'val' if not opt.trainval else 'test' + dataset = Dataset(opt, split) + detector = Detector(opt) + + # 创建目录 + if os.path.exists(res_data_save_path): + shutil.rmtree(res_data_save_path) + os.makedirs(res_data_save_path) + + print('\n[INFO] Infering ...') + results = {} + num_iters = len(dataset) + total_infer_time = 0 + total_infer_num = 0 + for ind in tqdm(range(num_iters)): + img_id = dataset.images[ind] + img_info = dataset.coco.loadImgs(ids=[img_id])[0] + img_path = os.path.join(dataset.img_dir, img_info['file_name']) + + start_time = time.perf_counter() + ret = detector.run(img_path) + end_time = time.perf_counter() + total_infer_time += end_time - start_time + total_infer_num += 1 + + results[img_id] = ret['results'] + print('\n[INFO] Infer done!') + + print('\n[INFO] Calculate accuracy ...') + dataset.run_eval(results, res_data_save_path) + + # 推理时间 + print('\n[INFO] Time:') + msg = 'total infer num: ' + str(total_infer_num) + '\n' + \ + 'total infer time(ms): ' + str(total_infer_time * 1000) + '\n' + \ + 'average infer time(ms): ' + str(total_infer_time * 1000 / total_infer_num) + '\n' + print(msg) + + +if __name__ == '__main__': + ''' + Using Example: + + python pth_eval.py --res_data_save_path=./pth_result + ''' + + # 解析参数 + parser = argparse.ArgumentParser() + parser.add_argument('--res_data_save_path', required=True) + + opt = parser.parse_args() + res_data_save_path = opt.res_data_save_path + + # 创建并解析opt + opt = opts().init('--task ctdet --exp_id coco_dla --not_prefetch_test ' + '--load_model ../models/ctdet_coco_dla_2x.pth'.split(' ')) + + # 处理数据 + eval(opt, res_data_save_path) diff --git a/ACL_PyTorch/built-in/cv/DB_for_PyTorch/LICENSE b/ACL_PyTorch/built-in/cv/DB_for_PyTorch/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/built-in/cv/DB_for_PyTorch/LICENSE +++ b/ACL_PyTorch/built-in/cv/DB_for_PyTorch/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/DB_for_PyTorch/db.diff b/ACL_PyTorch/built-in/cv/DB_for_PyTorch/db.diff index 47cb2d745e4535e7a4a27b852b0b940edcae60e6..c4550dd3256a7ca6a3119774dd32934596d3fef1 100644 --- a/ACL_PyTorch/built-in/cv/DB_for_PyTorch/db.diff +++ b/ACL_PyTorch/built-in/cv/DB_for_PyTorch/db.diff @@ -103,24 +103,24 @@ index df6e5a2..796b02f 100644 --- a/backbones/resnet.py +++ b/backbones/resnet.py @@ -129,7 +129,8 @@ class Bottleneck(nn.Module): - self.conv2_offset = nn.Conv2d( - planes, deformable_groups * offset_channels, - kernel_size=3, -- padding=1) -+ padding=1, -+ stride=stride) - self.conv2 = conv_op( - planes, planes, kernel_size=3, padding=1, stride=stride, - deformable_groups=deformable_groups, bias=False) + self.conv2_offset = nn.Conv2d( + planes, deformable_groups * offset_channels, + kernel_size=3, +- padding=1) ++ padding=1, ++ stride=stride) + self.conv2 = conv_op( + planes, planes, kernel_size=3, padding=1, stride=stride, + deformable_groups=deformable_groups, bias=False) @@ -295,7 +296,7 @@ def resnet50(pretrained=True, **kwargs): - return model - - --def deformable_resnet50(pretrained=True, **kwargs): -+def deformable_resnet50(pretrained=False, **kwargs): - """Constructs a ResNet-50 model with deformable conv. - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet + return model + + +-def deformable_resnet50(pretrained=True, **kwargs): ++def deformable_resnet50(pretrained=False, **kwargs): + """Constructs a ResNet-50 model with deformable conv. + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet diff --git a/structure/model.py b/structure/model.py index 060191b..ea1705b 100644 --- a/structure/model.py diff --git a/ACL_PyTorch/built-in/cv/DB_for_PyTorch/db_pth2onnx.py b/ACL_PyTorch/built-in/cv/DB_for_PyTorch/db_pth2onnx.py index 93555759cf636963692fd1ad4a46eed5f140c19d..6f65e5a62ccef615f75b280792dfa2f7b6742010 100644 --- a/ACL_PyTorch/built-in/cv/DB_for_PyTorch/db_pth2onnx.py +++ b/ACL_PyTorch/built-in/cv/DB_for_PyTorch/db_pth2onnx.py @@ -1,57 +1,57 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import torch.onnx -import argparse -from experiment import Structure, Experiment -from concern.config import Configurable, Config -from collections import OrderedDict - -def proc_nodes_modile(checkpoint): - new_state_dict = OrderedDict() - for k, v in checkpoint.items(): - if "module." in k: - name = k.replace("module.", "") - else: - name = k - new_state_dict[name] = v - return new_state_dict - -def pth2onnx(model): - #https://github.com/MhLiao/DB - input_names = ["actual_input_1"] - output_names = ["output1"] - dynamic_axes = {'actual_input_1': {0: '-1'}, 'output1': {0: '-1'}} - dummy_input = torch.randn(1, 3, 736, 1280) - - torch.onnx.export(model, dummy_input, "dbnet.onnx", input_names=input_names, dynamic_axes=dynamic_axes, output_names=output_names, opset_version=11, verbose=True) - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='db pth2onnx') - parser.add_argument('exp', type=str) - parser.add_argument('--resume', type=str, help='Resume from checkpoint') - args = parser.parse_args() - args = vars(args) - args = {k: v for k, v in args.items() if v is not None} - conf = Config() - experiment_args = conf.compile(conf.load(args['exp']))['Experiment'] - experiment_args.update(cmd=args) - experiment = Configurable.construct_class_from_config(experiment_args) - model = experiment.structure.builder.build(torch.device('cpu')) - checkpoint = torch.load(args['resume'], map_location=torch.device('cpu')) - checkpoint = proc_nodes_modile(checkpoint) - model.load_state_dict(checkpoint) - model.eval() - pth2onnx(model) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import torch.onnx +import argparse +from experiment import Structure, Experiment +from concern.config import Configurable, Config +from collections import OrderedDict + +def proc_nodes_modile(checkpoint): + new_state_dict = OrderedDict() + for k, v in checkpoint.items(): + if "module." in k: + name = k.replace("module.", "") + else: + name = k + new_state_dict[name] = v + return new_state_dict + +def pth2onnx(model): + #https://github.com/MhLiao/DB + input_names = ["actual_input_1"] + output_names = ["output1"] + dynamic_axes = {'actual_input_1': {0: '-1'}, 'output1': {0: '-1'}} + dummy_input = torch.randn(1, 3, 736, 1280) + + torch.onnx.export(model, dummy_input, "dbnet.onnx", input_names=input_names, dynamic_axes=dynamic_axes, output_names=output_names, opset_version=11, verbose=True) + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='db pth2onnx') + parser.add_argument('exp', type=str) + parser.add_argument('--resume', type=str, help='Resume from checkpoint') + args = parser.parse_args() + args = vars(args) + args = {k: v for k, v in args.items() if v is not None} + conf = Config() + experiment_args = conf.compile(conf.load(args['exp']))['Experiment'] + experiment_args.update(cmd=args) + experiment = Configurable.construct_class_from_config(experiment_args) + model = experiment.structure.builder.build(torch.device('cpu')) + checkpoint = torch.load(args['resume'], map_location=torch.device('cpu')) + checkpoint = proc_nodes_modile(checkpoint) + model.load_state_dict(checkpoint) + model.eval() + pth2onnx(model) diff --git a/ACL_PyTorch/built-in/cv/DB_for_PyTorch/modelzoo_level.txt b/ACL_PyTorch/built-in/cv/DB_for_PyTorch/modelzoo_level.txt index 2233d9218a6b952e4bde5939ae170ecacb443827..9137dc380d2c2e7b046d270ddeea5496152ff1ca 100644 --- a/ACL_PyTorch/built-in/cv/DB_for_PyTorch/modelzoo_level.txt +++ b/ACL_PyTorch/built-in/cv/DB_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK -PerfStatus:OK +FuncStatus:OK +PrecisionStatus:OK +PerfStatus:OK diff --git a/ACL_PyTorch/built-in/cv/DB_for_PyTorch/test/parse.py b/ACL_PyTorch/built-in/cv/DB_for_PyTorch/test/parse.py index 85920a3be88f97f93cfead86a10b6286cf214aca..2b1f1406a73cace34bef8e1667033a53df5a0e24 100644 --- a/ACL_PyTorch/built-in/cv/DB_for_PyTorch/test/parse.py +++ b/ACL_PyTorch/built-in/cv/DB_for_PyTorch/test/parse.py @@ -1,33 +1,33 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - #tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - #print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - print(content) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 - print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + #tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + #print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + print(content) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 + print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) diff --git a/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/ReadMe.md b/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/ReadMe.md index b72db5dd9f23a821813b09736847740acf5f8017..2f762d2bd4f9f1c4f02af63dc88f31b08e1228a9 100644 --- a/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/ReadMe.md +++ b/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/ReadMe.md @@ -1,46 +1,46 @@ -文件作用说明: - -1.auto_tune.sh:模型转换脚本,集成了auto tune功能,可以手动关闭 - -2.pthtar2onnx.py:用于转换pth.tar文件到onnx文件 - -3.deepmar.info:PETA数据集信息,用于benchmark推理获取数据集 - -4.preprocess_deepmar_pytorch.py:数据集预处理脚本,通过均值方差处理归一化图片 - -5.label.json:PETA数据集标签,用于验证推理结果 - -6.postprocess_deepmar_pytorch.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy - -7.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer - - - - - -推理端到端步骤: - -(1) 从开源仓https://github.com/dangweili/pedestrian-attribute-recognition-pytorch/blob/master/baseline/model/DeepMAR.py下载deepamar模型或者指定自己训练好的pth文件路径,使用提供的DeepMar.py替换掉模型中的DeepMar.py, 通过export_onnx.py脚本转化为onnx模型 - - - -(2)为提高性能,可以使用remove_pad.py剔除掉pad算子,运行auto_tune.sh脚本转换om模型,也可以选择手动关闭auto_tune,由于提出pad算子后,性能已经较好,本包中提供的om为未经auto_tune调优的om模型 - - -(3)运行python script/dataset/transform_peta.py得到数据集,python split_test_data.py得到测试集txt信息image.txt和标签json文件label.json - - -(4)运行python preprocess_deepmar_pytorch.py dataset/peta/images input_bin image.txt,根据测试集image.txt生成对应bin文件 - -(5)运行python get_info.py input_bin deepmar.info 224 224 生成deepmar.info文件,存储bin文件的信息 - -(6)./benchmark.x86_64 -model_type=vision -batch_size=1 -device_id=0 -om_path=deepmar_bs1.om -input_width=224 -input_height=224 -input_text_path=deepmar.info -useDvpp=false -output_binary=true - -运行benchmark推理,结果保存在 ./result/dumpOutput_device0下 目录下 - - - -(7)python postprocess_deepmar_pytorch.py result/dumpOutput_device0/ label.json - -验证推理结果,第一项即为acc - +文件作用说明: + +1.auto_tune.sh:模型转换脚本,集成了auto tune功能,可以手动关闭 + +2.pthtar2onnx.py:用于转换pth.tar文件到onnx文件 + +3.deepmar.info:PETA数据集信息,用于benchmark推理获取数据集 + +4.preprocess_deepmar_pytorch.py:数据集预处理脚本,通过均值方差处理归一化图片 + +5.label.json:PETA数据集标签,用于验证推理结果 + +6.postprocess_deepmar_pytorch.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy + +7.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer + + + + + +推理端到端步骤: + +(1) 从开源仓https://github.com/dangweili/pedestrian-attribute-recognition-pytorch/blob/master/baseline/model/DeepMAR.py下载deepamar模型或者指定自己训练好的pth文件路径,使用提供的DeepMar.py替换掉模型中的DeepMar.py, 通过export_onnx.py脚本转化为onnx模型 + + + +(2)为提高性能,可以使用remove_pad.py剔除掉pad算子,运行auto_tune.sh脚本转换om模型,也可以选择手动关闭auto_tune,由于提出pad算子后,性能已经较好,本包中提供的om为未经auto_tune调优的om模型 + + +(3)运行python script/dataset/transform_peta.py得到数据集,python split_test_data.py得到测试集txt信息image.txt和标签json文件label.json + + +(4)运行python preprocess_deepmar_pytorch.py dataset/peta/images input_bin image.txt,根据测试集image.txt生成对应bin文件 + +(5)运行python get_info.py input_bin deepmar.info 224 224 生成deepmar.info文件,存储bin文件的信息 + +(6)./benchmark.x86_64 -model_type=vision -batch_size=1 -device_id=0 -om_path=deepmar_bs1.om -input_width=224 -input_height=224 -input_text_path=deepmar.info -useDvpp=false -output_binary=true + +运行benchmark推理,结果保存在 ./result/dumpOutput_device0下 目录下 + + + +(7)python postprocess_deepmar_pytorch.py result/dumpOutput_device0/ label.json + +验证推理结果,第一项即为acc + diff --git a/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/export_onnx.py b/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/export_onnx.py index ddab3eb951dce15e8f67eec8208a48b818e641bc..c61f9e75671d202a041e68a7dc63e790471109d5 100644 --- a/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/export_onnx.py +++ b/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/export_onnx.py @@ -1,38 +1,38 @@ -import torch -from baseline.model import DeepMAR -import torch.onnx -from collections import OrderedDict -import torch._utils - - -def proc_nodes_module(checkpoint, AttrName): - new_state_dict = OrderedDict() - for k, v in checkpoint[AttrName].items(): - if (k[0:7] == "module."): - name = k[7:] - else: - name = k[0:] - - new_state_dict[name] = v - return new_state_dict - - -def convert(): - checkpoint = torch.load("./checkpoint.pth.tar", map_location='cpu') - checkpoint['state_dict'] = proc_nodes_module(checkpoint, 'state_dict') - model = DeepMAR.DeepMAR_ResNet50() - model.load_state_dict(checkpoint['state_dict']) - model.eval() - print(model) - - input_names = ["actual_input_1"] - output_names = ["output1"] - dummy_input = torch.randn(1, 3, 224, 224) - import onnx - print('\nStarting ONNX export with onnx %s...' % onnx.__version__) - torch.onnx.export(model, dummy_input, "Deepmar_bs1.onnx", input_names=input_names, output_names=output_names, - opset_version=11, do_constant_folding=True) - - -if __name__ == "__main__": - convert() +import torch +from baseline.model import DeepMAR +import torch.onnx +from collections import OrderedDict +import torch._utils + + +def proc_nodes_module(checkpoint, AttrName): + new_state_dict = OrderedDict() + for k, v in checkpoint[AttrName].items(): + if (k[0:7] == "module."): + name = k[7:] + else: + name = k[0:] + + new_state_dict[name] = v + return new_state_dict + + +def convert(): + checkpoint = torch.load("./checkpoint.pth.tar", map_location='cpu') + checkpoint['state_dict'] = proc_nodes_module(checkpoint, 'state_dict') + model = DeepMAR.DeepMAR_ResNet50() + model.load_state_dict(checkpoint['state_dict']) + model.eval() + print(model) + + input_names = ["actual_input_1"] + output_names = ["output1"] + dummy_input = torch.randn(1, 3, 224, 224) + import onnx + print('\nStarting ONNX export with onnx %s...' % onnx.__version__) + torch.onnx.export(model, dummy_input, "Deepmar_bs1.onnx", input_names=input_names, output_names=output_names, + opset_version=11, do_constant_folding=True) + + +if __name__ == "__main__": + convert() diff --git a/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/get_info.py b/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/get_info.py index da181d8d0342e52eb33b38fa475ae812a61575cf..c68e7705e47c90970ab04e5f139e52192a634364 100644 --- a/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/get_info.py +++ b/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/get_info.py @@ -1,16 +1,16 @@ -import os -import sys -from glob import glob - -file_path = sys.argv[1] -info_name = sys.argv[2] -width = sys.argv[3] -height = sys.argv[4] - -bin_images = glob(os.path.join(file_path, '*')) - -with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') +import os +import sys +from glob import glob + +file_path = sys.argv[1] +info_name = sys.argv[2] +width = sys.argv[3] +height = sys.argv[4] + +bin_images = glob(os.path.join(file_path, '*')) + +with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') diff --git a/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/postprocess_deepmar_pytorch.py b/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/postprocess_deepmar_pytorch.py index 14c2c834bfcafb267756f92251d4f1f1c8380f8e..f6032390a585ac505cce8ff00e89c09a82a9ed09 100644 --- a/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/postprocess_deepmar_pytorch.py +++ b/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/postprocess_deepmar_pytorch.py @@ -1,94 +1,94 @@ -import os -import sys -import json -import numpy as np - - -def attribute_evaluate_lidw(gt_result, pt_result): - """ - Input: - gt_result, pt_result, N*L, with 0/1 - Output: - result - a dictionary, including label-based and instance-based evaluation - label-based: label_pos_acc, label_neg_acc, label_acc - instance-based: instance_acc, instance_precision, instance_recall, instance_F1 - """ - # obtain the label-based and instance-based accuracy - # compute the label-based accuracy - if gt_result.shape != pt_result.shape: - print('Shape beteen groundtruth and predicted results are different') - # compute the label-based accuracy - result = {} - gt_pos = np.sum((gt_result == 1).astype(float), axis=0) - gt_neg = np.sum((gt_result == 0).astype(float), axis=0) - pt_pos = np.sum((gt_result == 1).astype(float) * (pt_result == 1).astype(float), axis=0) - pt_neg = np.sum((gt_result == 0).astype(float) * (pt_result == 0).astype(float), axis=0) - label_pos_acc = 1.0*pt_pos/gt_pos - label_neg_acc = 1.0*pt_neg/gt_neg - label_acc = (label_pos_acc + label_neg_acc)/2 - result['label_pos_acc'] = label_pos_acc - result['label_neg_acc'] = label_neg_acc - result['label_acc'] = label_acc - # compute the instance-based accuracy - # precision - gt_pos = np.sum((gt_result == 1).astype(float), axis=1) - pt_pos = np.sum((pt_result == 1).astype(float), axis=1) - floatersect_pos = np.sum((gt_result == 1).astype(float)*(pt_result == 1).astype(float), axis=1) - union_pos = np.sum(((gt_result == 1)+(pt_result == 1)).astype(float),axis=1) - # avoid empty label in predicted results - cnt_eff = float(gt_result.shape[0]) - for iter, key in enumerate(gt_pos): - if key == 0: - union_pos[iter] = 1 - pt_pos[iter] = 1 - gt_pos[iter] = 1 - cnt_eff = cnt_eff - 1 - continue - if pt_pos[iter] == 0: - pt_pos[iter] = 1 - instance_acc = np.sum(floatersect_pos/union_pos)/cnt_eff - instance_precision = np.sum(floatersect_pos/pt_pos)/cnt_eff - instance_recall = np.sum(floatersect_pos/gt_pos)/cnt_eff - floatance_F1 = 2*instance_precision*instance_recall/(instance_precision+instance_recall) - result['instance_acc'] = instance_acc - result['instance_precision'] = instance_precision - result['instance_recall'] = instance_recall - result['instance_F1'] = floatance_F1 - return result - - -def postprocess_deepmar(npu_result, label_file): - with open(label_file, 'r') as json_file: - image_label = json.load(json_file) - bin_files = os.listdir(npu_result) - counts = len(bin_files) - gt_result = np.zeros((counts, 35)) - pt_result = np.zeros((counts, 35)) - - for index, bin_file in enumerate(bin_files): - result = np.fromfile(os.path.join(npu_result, bin_file), dtype='float32').reshape((35, )) - result[result >= 0] = 1 - result[result < 0] = 0 - pt_result[index, :] = result - - # label - key = bin_file[:bin_file.rfind('_')] + '.png' - label = image_label[key] - label = np.array(label, dtype=np.uint8) - gt_result[index, :] = label - - result = attribute_evaluate_lidw(gt_result, pt_result) - print('-'*80) - print('instance_acc: {}'.format(result['instance_acc'])) - print('instance_precision: {}'.format(result['instance_precision'])) - print('instance_recall: {}'.format(result['instance_recall'])) - print('instance_F1: {}'.format(result['instance_F1'])) - print('-' * 80) - - -if __name__ == "__main__": - npu_result = os.path.abspath(sys.argv[1]) - label_file = os.path.abspath(sys.argv[2]) - postprocess_deepmar(npu_result, label_file) - +import os +import sys +import json +import numpy as np + + +def attribute_evaluate_lidw(gt_result, pt_result): + """ + Input: + gt_result, pt_result, N*L, with 0/1 + Output: + result + a dictionary, including label-based and instance-based evaluation + label-based: label_pos_acc, label_neg_acc, label_acc + instance-based: instance_acc, instance_precision, instance_recall, instance_F1 + """ + # obtain the label-based and instance-based accuracy + # compute the label-based accuracy + if gt_result.shape != pt_result.shape: + print('Shape beteen groundtruth and predicted results are different') + # compute the label-based accuracy + result = {} + gt_pos = np.sum((gt_result == 1).astype(float), axis=0) + gt_neg = np.sum((gt_result == 0).astype(float), axis=0) + pt_pos = np.sum((gt_result == 1).astype(float) * (pt_result == 1).astype(float), axis=0) + pt_neg = np.sum((gt_result == 0).astype(float) * (pt_result == 0).astype(float), axis=0) + label_pos_acc = 1.0*pt_pos/gt_pos + label_neg_acc = 1.0*pt_neg/gt_neg + label_acc = (label_pos_acc + label_neg_acc)/2 + result['label_pos_acc'] = label_pos_acc + result['label_neg_acc'] = label_neg_acc + result['label_acc'] = label_acc + # compute the instance-based accuracy + # precision + gt_pos = np.sum((gt_result == 1).astype(float), axis=1) + pt_pos = np.sum((pt_result == 1).astype(float), axis=1) + floatersect_pos = np.sum((gt_result == 1).astype(float)*(pt_result == 1).astype(float), axis=1) + union_pos = np.sum(((gt_result == 1)+(pt_result == 1)).astype(float),axis=1) + # avoid empty label in predicted results + cnt_eff = float(gt_result.shape[0]) + for iter, key in enumerate(gt_pos): + if key == 0: + union_pos[iter] = 1 + pt_pos[iter] = 1 + gt_pos[iter] = 1 + cnt_eff = cnt_eff - 1 + continue + if pt_pos[iter] == 0: + pt_pos[iter] = 1 + instance_acc = np.sum(floatersect_pos/union_pos)/cnt_eff + instance_precision = np.sum(floatersect_pos/pt_pos)/cnt_eff + instance_recall = np.sum(floatersect_pos/gt_pos)/cnt_eff + floatance_F1 = 2*instance_precision*instance_recall/(instance_precision+instance_recall) + result['instance_acc'] = instance_acc + result['instance_precision'] = instance_precision + result['instance_recall'] = instance_recall + result['instance_F1'] = floatance_F1 + return result + + +def postprocess_deepmar(npu_result, label_file): + with open(label_file, 'r') as json_file: + image_label = json.load(json_file) + bin_files = os.listdir(npu_result) + counts = len(bin_files) + gt_result = np.zeros((counts, 35)) + pt_result = np.zeros((counts, 35)) + + for index, bin_file in enumerate(bin_files): + result = np.fromfile(os.path.join(npu_result, bin_file), dtype='float32').reshape((35, )) + result[result >= 0] = 1 + result[result < 0] = 0 + pt_result[index, :] = result + + # label + key = bin_file[:bin_file.rfind('_')] + '.png' + label = image_label[key] + label = np.array(label, dtype=np.uint8) + gt_result[index, :] = label + + result = attribute_evaluate_lidw(gt_result, pt_result) + print('-'*80) + print('instance_acc: {}'.format(result['instance_acc'])) + print('instance_precision: {}'.format(result['instance_precision'])) + print('instance_recall: {}'.format(result['instance_recall'])) + print('instance_F1: {}'.format(result['instance_F1'])) + print('-' * 80) + + +if __name__ == "__main__": + npu_result = os.path.abspath(sys.argv[1]) + label_file = os.path.abspath(sys.argv[2]) + postprocess_deepmar(npu_result, label_file) + diff --git a/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/preprocess_deepmar_pytorch.py b/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/preprocess_deepmar_pytorch.py index 76f285439f7b744b04abb51e968696f4b9ed811a..1a9fd52a6028d063aa62556f6b4f005f24a9e367 100644 --- a/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/preprocess_deepmar_pytorch.py +++ b/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/preprocess_deepmar_pytorch.py @@ -1,73 +1,73 @@ -import os -import sys -import numpy as np -from PIL import Image - - -def resize(img, size, interpolation=Image.BILINEAR): - r"""Resize the input PIL Image to the given size. - - Args: - img (PIL Image): Image to be resized. - size (sequence or int): Desired output size. If size is a sequence like - (h, w), the output size will be matched to this. If size is an int, - the smaller edge of the image will be matched to this number maintaining - the aspect ratio. i.e, if height > width, then image will be rescaled to - :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)` - interpolation (int, optional): Desired interpolation. Default is - ``PIL.Image.BILINEAR`` - - Returns: - PIL Image: Resized image. - """ - - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def deepmar_onnx(file_path, bin_path, image_info): - if not os.path.exists(bin_path): - os.makedirs(bin_path) - i = 0 - in_files = open(image_info, 'r').read().split('\n')[:-1] - input_size = (224, 224) - mean = [0.485, 0.456, 0.406] - std = [0.229, 0.224, 0.225] - for file in in_files: - i = i + 1 - print(file, "====", i) - img = Image.open(os.path.join(file_path, file)).convert('RGB') - img = resize(img, input_size) - - img = np.array(img, dtype=np.float32) - img = img / 255. - - # 均值方差 - img[..., 0] -= mean[0] - img[..., 1] -= mean[1] - img[..., 2] -= mean[2] - img[..., 0] /= std[0] - img[..., 1] /= std[1] - img[..., 2] /= std[2] - - img = img.transpose(2, 0, 1) # HWC -> CHW - img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) - - -if __name__ == "__main__": - file_path = os.path.abspath(sys.argv[1]) - bin_path = os.path.abspath(sys.argv[2]) - image_info = sys.argv[3] - deepmar_onnx(file_path, bin_path, image_info) +import os +import sys +import numpy as np +from PIL import Image + + +def resize(img, size, interpolation=Image.BILINEAR): + r"""Resize the input PIL Image to the given size. + + Args: + img (PIL Image): Image to be resized. + size (sequence or int): Desired output size. If size is a sequence like + (h, w), the output size will be matched to this. If size is an int, + the smaller edge of the image will be matched to this number maintaining + the aspect ratio. i.e, if height > width, then image will be rescaled to + :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)` + interpolation (int, optional): Desired interpolation. Default is + ``PIL.Image.BILINEAR`` + + Returns: + PIL Image: Resized image. + """ + + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def deepmar_onnx(file_path, bin_path, image_info): + if not os.path.exists(bin_path): + os.makedirs(bin_path) + i = 0 + in_files = open(image_info, 'r').read().split('\n')[:-1] + input_size = (224, 224) + mean = [0.485, 0.456, 0.406] + std = [0.229, 0.224, 0.225] + for file in in_files: + i = i + 1 + print(file, "====", i) + img = Image.open(os.path.join(file_path, file)).convert('RGB') + img = resize(img, input_size) + + img = np.array(img, dtype=np.float32) + img = img / 255. + + # 均值方差 + img[..., 0] -= mean[0] + img[..., 1] -= mean[1] + img[..., 2] -= mean[2] + img[..., 0] /= std[0] + img[..., 1] /= std[1] + img[..., 2] /= std[2] + + img = img.transpose(2, 0, 1) # HWC -> CHW + img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) + + +if __name__ == "__main__": + file_path = os.path.abspath(sys.argv[1]) + bin_path = os.path.abspath(sys.argv[2]) + image_info = sys.argv[3] + deepmar_onnx(file_path, bin_path, image_info) diff --git a/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/remove_pad.py b/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/remove_pad.py index 572c41f3f516645453cc2d2f4bf654beecd9260d..70e8ccfb7ea1b567ea0e84d0781383287e304f80 100644 --- a/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/remove_pad.py +++ b/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/remove_pad.py @@ -1,19 +1,19 @@ -import onnx - -model = onnx.load("Deepmar.onnx") - -model.graph.node[174].input[0] = '492' - -node_list = ["Pad_173",'Constant_172'] -max_idx = len(model.graph.node) -rm_cnt = 0 -for i in range(len(model.graph.node)): - if i < max_idx: - n = model.graph.node[i - rm_cnt] - if n.name in node_list: - print("remove {} total {}".format(n.name, len(model.graph.node))) - model.graph.node.remove(n) - max_idx -= 1 - rm_cnt += 1 -onnx.checker.check_model(model) +import onnx + +model = onnx.load("Deepmar.onnx") + +model.graph.node[174].input[0] = '492' + +node_list = ["Pad_173",'Constant_172'] +max_idx = len(model.graph.node) +rm_cnt = 0 +for i in range(len(model.graph.node)): + if i < max_idx: + n = model.graph.node[i - rm_cnt] + if n.name in node_list: + print("remove {} total {}".format(n.name, len(model.graph.node))) + model.graph.node.remove(n) + max_idx -= 1 + rm_cnt += 1 +onnx.checker.check_model(model) onnx.save(model, "Deepmar_nopad.onnx") \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/split_test_data.py b/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/split_test_data.py index 955f4722d39dc267b8e20b398a952c12fe43cda7..19a81059a630778cfa47cc5e10395d9443e88ef5 100644 --- a/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/split_test_data.py +++ b/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch/split_test_data.py @@ -1,25 +1,25 @@ -import pickle -import numpy as np -import json - - -image = [] -label = [] -dataset = pickle.load(open('./dataset/peta/peta_dataset.pkl', 'rb'), encoding='utf-8') -train_split = pickle.load(open('./dataset/peta/peta_partition.pkl', 'rb'), encoding='utf-8') - -for idx in train_split['test'][0]: - image.append(dataset['image'][idx]) - label_tmp = np.array(dataset['att'][idx])[dataset['selected_attribute']].tolist() - label.append(label_tmp) - -with open('image.txt', 'w') as f: - for name in image: - f.write(name) - f.write('\n') - -image_label = dict(zip(image, label)) -with open('label.json', 'w') as json_file: - json.dump(image_label, json_file) - - +import pickle +import numpy as np +import json + + +image = [] +label = [] +dataset = pickle.load(open('./dataset/peta/peta_dataset.pkl', 'rb'), encoding='utf-8') +train_split = pickle.load(open('./dataset/peta/peta_partition.pkl', 'rb'), encoding='utf-8') + +for idx in train_split['test'][0]: + image.append(dataset['image'][idx]) + label_tmp = np.array(dataset['att'][idx])[dataset['selected_attribute']].tolist() + label.append(label_tmp) + +with open('image.txt', 'w') as f: + for name in image: + f.write(name) + f.write('\n') + +image_label = dict(zip(image, label)) +with open('label.json', 'w') as json_file: + json.dump(image_label, json_file) + + diff --git a/ACL_PyTorch/built-in/cv/Deepsort_for_Pytorch/modelzoo_level.txt b/ACL_PyTorch/built-in/cv/Deepsort_for_Pytorch/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/ACL_PyTorch/built-in/cv/Deepsort_for_Pytorch/modelzoo_level.txt +++ b/ACL_PyTorch/built-in/cv/Deepsort_for_Pytorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/PytorchTransfer.py b/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/PytorchTransfer.py index 1c8e9d29c92f2d69001ba19ba7cd9d0fc0ff3508..c002102863d7a72985903ee80e328dcfd4664da5 100644 --- a/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/PytorchTransfer.py +++ b/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/PytorchTransfer.py @@ -1,46 +1,46 @@ -import sys -import os -import torch -import cv2 -from PIL import Image -import numpy as np -import torch.utils.data -import torchvision.transforms as transforms -from torch.autograd import Variable - - -def resnet50_onnx(input_path: str, output_path: str): - img = cv2.imread(input_path) - img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) - pilimg = Image.fromarray(img) - normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], - std=[0.229, 0.224, 0.225]) - val_transformer = transforms.Compose([ - transforms.Scale(256), - transforms.CenterCrop(224), - transforms.ToTensor(), - normalize - ]) - - img_tensor = val_transformer(pilimg) - img_tensor = torch.unsqueeze(img_tensor, dim=0).float() - img_tensor = Variable(img_tensor, requires_grad=False) - img_tensor.reshape(1, 3, 224, 224) - img_numpy = img_tensor.cpu().numpy() - - img_name = input_path.split('/')[-1] - bin_name = img_name.split('.')[0] + ".bin" - output_fl = os.path.join(output_path, bin_name) - # save img_tensor as binary file for om inference input - img_numpy.tofile(output_fl) - -if __name__ == "__main__": - input_img_dir = sys.argv[1] - output_img_dir = sys.argv[2] - images = os.listdir(input_img_dir) - for image_name in images: - if not image_name.endswith(".jpeg"): - continue - print("start to process image {}....".format(image_name)) - path_image = os.path.join(input_img_dir, image_name) +import sys +import os +import torch +import cv2 +from PIL import Image +import numpy as np +import torch.utils.data +import torchvision.transforms as transforms +from torch.autograd import Variable + + +def resnet50_onnx(input_path: str, output_path: str): + img = cv2.imread(input_path) + img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) + pilimg = Image.fromarray(img) + normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]) + val_transformer = transforms.Compose([ + transforms.Scale(256), + transforms.CenterCrop(224), + transforms.ToTensor(), + normalize + ]) + + img_tensor = val_transformer(pilimg) + img_tensor = torch.unsqueeze(img_tensor, dim=0).float() + img_tensor = Variable(img_tensor, requires_grad=False) + img_tensor.reshape(1, 3, 224, 224) + img_numpy = img_tensor.cpu().numpy() + + img_name = input_path.split('/')[-1] + bin_name = img_name.split('.')[0] + ".bin" + output_fl = os.path.join(output_path, bin_name) + # save img_tensor as binary file for om inference input + img_numpy.tofile(output_fl) + +if __name__ == "__main__": + input_img_dir = sys.argv[1] + output_img_dir = sys.argv[2] + images = os.listdir(input_img_dir) + for image_name in images: + if not image_name.endswith(".jpeg"): + continue + print("start to process image {}....".format(image_name)) + path_image = os.path.join(input_img_dir, image_name) resnet50_onnx(path_image, output_img_dir) \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/ReadMe.md b/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/ReadMe.md index 740e2ce6aea460a99c62dd0cb16fc6c28ee929bf..0e9f686545e1d92bb84cbb28d42ff7e1d2d310e8 100644 --- a/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/ReadMe.md +++ b/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/ReadMe.md @@ -1,48 +1,48 @@ -文件作用说明: - -1.auto_tune.sh:模型转换脚本,集成了auto tune功能,可以手动关闭 - -2.pth2onnx.py:用于转换pth文件到onnx文件 - -3.pthtar2onnx.py:用于转换pth.tar文件到onnx文件 - -4.BinaryImageNet.info:ImageNet数据集信息,用于benchmark推理获取数据集 - -5.PytorchTransfer.py:数据集预处理脚本,通过均值方差处理归一化图片 - -6.val_label.txt:ImageNet数据集标签,用于验证推理结果 - -7.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy - -8.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer - - - - - -推理端到端步骤: - -(1) 从Torchvision下载resnet50模型或者指定自己训练好的pth文件路径,通过pth2onnx.py脚本转化为onnx模型 - - - -(2)运行auto_tune.sh脚本转换om模型,也可以选择手动关闭auto_tune - -本demo已提供调优完成的om模型 - - - -(3)用PytorchTransfer.py脚本处理数据集,参考BinaryImageNet.Info配置处理后的二进制数据集路径 - - - -(4)./benchmark.x86_64 -model_type=vision -batch_size=16 -device_id=0 -input_text_path=./BinaryImageNet.info -input_width=224 -input_height=224 -om_path=./resnet50_pytorch.om -useDvpp=False - -运行benchmark推理,结果保存在 ./result 目录下 - - - -(5)python3.7 vision_metric_ImageNet.py result/dumpOutput/ ./val_label.txt ./ result.json - -验证推理结果 - +文件作用说明: + +1.auto_tune.sh:模型转换脚本,集成了auto tune功能,可以手动关闭 + +2.pth2onnx.py:用于转换pth文件到onnx文件 + +3.pthtar2onnx.py:用于转换pth.tar文件到onnx文件 + +4.BinaryImageNet.info:ImageNet数据集信息,用于benchmark推理获取数据集 + +5.PytorchTransfer.py:数据集预处理脚本,通过均值方差处理归一化图片 + +6.val_label.txt:ImageNet数据集标签,用于验证推理结果 + +7.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy + +8.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer + + + + + +推理端到端步骤: + +(1) 从Torchvision下载resnet50模型或者指定自己训练好的pth文件路径,通过pth2onnx.py脚本转化为onnx模型 + + + +(2)运行auto_tune.sh脚本转换om模型,也可以选择手动关闭auto_tune + +本demo已提供调优完成的om模型 + + + +(3)用PytorchTransfer.py脚本处理数据集,参考BinaryImageNet.Info配置处理后的二进制数据集路径 + + + +(4)./benchmark.x86_64 -model_type=vision -batch_size=16 -device_id=0 -input_text_path=./BinaryImageNet.info -input_width=224 -input_height=224 -om_path=./resnet50_pytorch.om -useDvpp=False + +运行benchmark推理,结果保存在 ./result 目录下 + + + +(5)python3.7 vision_metric_ImageNet.py result/dumpOutput/ ./val_label.txt ./ result.json + +验证推理结果 + diff --git a/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/pthtar2onnx.py b/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/pthtar2onnx.py index 0784264fc9e869584f24cb1c0fa621d48d5ab5a2..10fd93f53f9bf3d6ce92e6aaf0a88ce8cfa29ed3 100644 --- a/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/pthtar2onnx.py +++ b/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/pthtar2onnx.py @@ -1,36 +1,36 @@ -import torch -#from efficientnet_pytorch import EfficientNet -from NPU.efficientnet_pytorch import EfficientNet -import torch.onnx - -from collections import OrderedDict - -def proc_nodes_module(checkpoint,AttrName): - new_state_dict = OrderedDict() - for k,v in checkpoint[AttrName].items(): - if(k[0:7] == "module."): - name = k[7:] - else: - name = k[0:] - - new_state_dict[name]=v - return new_state_dict - -def convert(): - checkpoint = torch.load("./checkpoint.pth.140.ok.cpu", map_location='cpu') - checkpoint['state_dict'] = proc_nodes_module(checkpoint,'state_dict') - model = EfficientNet.from_name('efficientnet-b0') - model.set_swish(memory_efficient=False) - model.load_state_dict(checkpoint['state_dict']) - model.eval() - #print(model) - - input_names = ["actual_input_1"] - output_names = ["output1"] - dummy_input = torch.randn(1, 3, 224, 224) - #dynamic_axes = {'actual_input_1': {0: '-1'}, 'output1': {0: '-1'}} - torch.onnx.export(model, dummy_input, "efficientnet_tr.onnx", input_names = input_names, output_names = output_names, opset_version=11) - #torch.onnx.export(model, dummy_input, "efficientnet_dynamic.onnx", input_names = input_names, output_names = output_names, dynamic_axes = dynamic_axes, opset_version=11) - -if __name__ == "__main__": - convert() +import torch +#from efficientnet_pytorch import EfficientNet +from NPU.efficientnet_pytorch import EfficientNet +import torch.onnx + +from collections import OrderedDict + +def proc_nodes_module(checkpoint,AttrName): + new_state_dict = OrderedDict() + for k,v in checkpoint[AttrName].items(): + if(k[0:7] == "module."): + name = k[7:] + else: + name = k[0:] + + new_state_dict[name]=v + return new_state_dict + +def convert(): + checkpoint = torch.load("./checkpoint.pth.140.ok.cpu", map_location='cpu') + checkpoint['state_dict'] = proc_nodes_module(checkpoint,'state_dict') + model = EfficientNet.from_name('efficientnet-b0') + model.set_swish(memory_efficient=False) + model.load_state_dict(checkpoint['state_dict']) + model.eval() + #print(model) + + input_names = ["actual_input_1"] + output_names = ["output1"] + dummy_input = torch.randn(1, 3, 224, 224) + #dynamic_axes = {'actual_input_1': {0: '-1'}, 'output1': {0: '-1'}} + torch.onnx.export(model, dummy_input, "efficientnet_tr.onnx", input_names = input_names, output_names = output_names, opset_version=11) + #torch.onnx.export(model, dummy_input, "efficientnet_dynamic.onnx", input_names = input_names, output_names = output_names, dynamic_axes = dynamic_axes, opset_version=11) + +if __name__ == "__main__": + convert() diff --git a/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/vision_metric_ImageNet.py b/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/vision_metric_ImageNet.py index 7bba5f8346a8893b4567d92b900fc4a651115976..f07c93617e661619c0e00be6a972e39fbde966a0 100644 --- a/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/vision_metric_ImageNet.py +++ b/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch/vision_metric_ImageNet.py @@ -1,173 +1,173 @@ -#coding = utf-8 -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = "" - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - #print(filepath) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - #print(img_gt_dict) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - # print(img_name) - #print(n_labels) - # print(gt) - - resCnt = min(len(sort_index), topn) - # print(sort_index[:5]) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - #print("***************") - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - #print("Top" + str(i + 1) + " accuracy" + ": " + str(round(accuracy[i] * 100, 2)) + '%') - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - #print("Time used:", elapsed) +#coding = utf-8 +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = "" + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + #print(filepath) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + #print(img_gt_dict) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + # print(img_name) + #print(n_labels) + # print(gt) + + resCnt = min(len(sort_index), topn) + # print(sort_index[:5]) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + #print("***************") + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + #print("Top" + str(i + 1) + " accuracy" + ": " + str(round(accuracy[i] * 100, 2)) + '%') + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + #print("Time used:", elapsed) diff --git a/ACL_PyTorch/built-in/cv/Flownet2_for_Pytorch/LICENSE b/ACL_PyTorch/built-in/cv/Flownet2_for_Pytorch/LICENSE index 8904c8516082056802ee732a4213ceab8c4a93af..5f7aa69fea22dade3f519868400025de434ae8ca 100644 --- a/ACL_PyTorch/built-in/cv/Flownet2_for_Pytorch/LICENSE +++ b/ACL_PyTorch/built-in/cv/Flownet2_for_Pytorch/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/Flownet2_for_Pytorch/flownet2.patch b/ACL_PyTorch/built-in/cv/Flownet2_for_Pytorch/flownet2.patch index be8fdbe2c67ba45ee9c119295e6d17457e88b3ea..4b175db7dab2aa172a433038939af6d8c190c628 100644 --- a/ACL_PyTorch/built-in/cv/Flownet2_for_Pytorch/flownet2.patch +++ b/ACL_PyTorch/built-in/cv/Flownet2_for_Pytorch/flownet2.patch @@ -3,58 +3,58 @@ index 8457d2f..34380a6 100755 --- a/models.py +++ b/models.py @@ -6,8 +6,10 @@ import math - import numpy as np - - try: -- from networks.resample2d_package.resample2d import Resample2d -- from networks.channelnorm_package.channelnorm import ChannelNorm -+ # from networks.resample2d_package.resample2d import Resample2d -+ # from networks.channelnorm_package.channelnorm import ChannelNorm -+ from networks.resample2d_onnx import Resample2d -+ from networks.channelnorm_onnx import ChannelNorm - - from networks import FlowNetC - from networks import FlowNetS + import numpy as np + + try: +- from networks.resample2d_package.resample2d import Resample2d +- from networks.channelnorm_package.channelnorm import ChannelNorm ++ # from networks.resample2d_package.resample2d import Resample2d ++ # from networks.channelnorm_package.channelnorm import ChannelNorm ++ from networks.resample2d_onnx import Resample2d ++ from networks.channelnorm_onnx import ChannelNorm + + from networks import FlowNetC + from networks import FlowNetS @@ -16,8 +18,10 @@ try: - - from networks.submodules import * - except: -- from .networks.resample2d_package.resample2d import Resample2d -- from .networks.channelnorm_package.channelnorm import ChannelNorm -+ # from .networks.resample2d_package.resample2d import Resample2d -+ # from .networks.channelnorm_package.channelnorm import ChannelNorm -+ from .networks.resample2d_onnx import Resample2d -+ from .networks.channelnorm_onnx import ChannelNorm - - from .networks import FlowNetC - from .networks import FlowNetS + + from networks.submodules import * + except: +- from .networks.resample2d_package.resample2d import Resample2d +- from .networks.channelnorm_package.channelnorm import ChannelNorm ++ # from .networks.resample2d_package.resample2d import Resample2d ++ # from .networks.channelnorm_package.channelnorm import ChannelNorm ++ from .networks.resample2d_onnx import Resample2d ++ from .networks.channelnorm_onnx import ChannelNorm + + from .networks import FlowNetC + from .networks import FlowNetS @@ -33,7 +37,7 @@ class FlowNet2(nn.Module): - super(FlowNet2,self).__init__() - self.batchNorm = batchNorm - self.div_flow = div_flow -- self.rgb_max = args.rgb_max -+ # self.rgb_max = args.rgb_max - self.args = args - - self.channelnorm = ChannelNorm() + super(FlowNet2,self).__init__() + self.batchNorm = batchNorm + self.div_flow = div_flow +- self.rgb_max = args.rgb_max ++ # self.rgb_max = args.rgb_max + self.args = args + + self.channelnorm = ChannelNorm() @@ -117,12 +121,12 @@ class FlowNet2(nn.Module): - weight.data[i,i,:,:] = torch.from_numpy(bilinear) - return - -- def forward(self, inputs): -- rgb_mean = inputs.contiguous().view(inputs.size()[:2]+(-1,)).mean(dim=-1).view(inputs.size()[:2] + (1,1,1,)) -+ def forward(self, x1, x2): -+ # rgb_mean = inputs.contiguous().view(inputs.size()[:2]+(-1,)).mean(dim=-1).view(inputs.size()[:2] + (1,1,1,)) - -- x = (inputs - rgb_mean) / self.rgb_max -- x1 = x[:,:,0,:,:] -- x2 = x[:,:,1,:,:] -+ # x = (inputs - rgb_mean) / self.rgb_max -+ # x1 = x[:,:,0,:,:] -+ # x2 = x[:,:,1,:,:] - x = torch.cat((x1,x2), dim = 1) - - # flownetc + weight.data[i,i,:,:] = torch.from_numpy(bilinear) + return + +- def forward(self, inputs): +- rgb_mean = inputs.contiguous().view(inputs.size()[:2]+(-1,)).mean(dim=-1).view(inputs.size()[:2] + (1,1,1,)) ++ def forward(self, x1, x2): ++ # rgb_mean = inputs.contiguous().view(inputs.size()[:2]+(-1,)).mean(dim=-1).view(inputs.size()[:2] + (1,1,1,)) + +- x = (inputs - rgb_mean) / self.rgb_max +- x1 = x[:,:,0,:,:] +- x2 = x[:,:,1,:,:] ++ # x = (inputs - rgb_mean) / self.rgb_max ++ # x1 = x[:,:,0,:,:] ++ # x2 = x[:,:,1,:,:] + x = torch.cat((x1,x2), dim = 1) + + # flownetc diff --git a/networks/FlowNetC.py b/networks/FlowNetC.py index 61e117a..32e130d 100755 --- a/networks/FlowNetC.py diff --git a/ACL_PyTorch/built-in/cv/GoogleNet_for_Pytorch/ReadMe.md b/ACL_PyTorch/built-in/cv/GoogleNet_for_Pytorch/ReadMe.md index 7e082d9620853e4373b2381a488999551ec324bd..bec682de971ac4ebc7fd220ad28dcd3fa9cdc0df 100644 --- a/ACL_PyTorch/built-in/cv/GoogleNet_for_Pytorch/ReadMe.md +++ b/ACL_PyTorch/built-in/cv/GoogleNet_for_Pytorch/ReadMe.md @@ -1,63 +1,63 @@ -文件作用说明: - -1.googlenet_pth2onnx.py:用于转换pth模型文件到onnx模型文件 - -2.googlenet_atc.sh:onnx模型转换om模型脚本 - -3.preprocess_googlenet_pth.py:数据集预处理脚本,通过均值方差处理归一化图片,生成图片二进制文件 - -4.aipp_googlenet_pth.config:数据集aipp预处理配置文件 - -5.get_info.py:生成推理输入的数据集二进制info文件或jpg info文件 - -6.googlenet_val.info:ImageNet验证集二进制info文件,用于benchmark推理获取数据集 - -7.ImageNet.info:ImageNet验证集jpg info文件,用于benchmark推理获取数据集 - -8.val_label.txt:ImageNet数据集标签,用于验证推理结果 - -9.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer - -10.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy - - - - - -推理端到端步骤: - -(1) 从Torchvision下载googlenet模型,通过googlenet_pth2onnx.py脚本转化为onnx模型 - - - -(2)运行googlenet_atc.sh脚本转换om模型 - -本demo已提供调优完成的om模型 - - - -(3)用preprocess_googlenet_pth.py脚本处理数据集,参考googlenet_val.info配置处理后的二进制数据集路径。或者配置数据集aipp预处理文件aipp_googlenet_pth.config。 - python3 preprocess_googlenet_pth.py dataset/ImageNet/val_union/ pre_bin - - - -(4)生成推理输入的数据集二进制info文件或jpg info文件 - python3 get_info.py bin pre_bin googlenet_val.info 224 224 - python3 get_info.py jpg dataset/ImageNet/val_union ImageNet.info - - - -(5)使用benchmark离线推理 - ./benchmark -model_type=vision -om_path=googlenet_bs16.om -device_id=0 -batch_size=16 -input_text_path=googlenet_val.info -input_width=224 -input_height=224 -useDvpp=false - 或者 - ./benchmark -model_type=vision -om_path=googlenet_bs1.om -device_id=0 -batch_size=1 -input_text_path=ImageNet.info -input_width=256 -input_height=256 -useDvpp=true - - -运行benchmark推理,结果保存在 ./result 目录下 - - - -(6)python3.7 vision_metric_ImageNet.py result/dumpOutput_device0/ ./val_label.txt ./ result.json - -验证推理结果 - +文件作用说明: + +1.googlenet_pth2onnx.py:用于转换pth模型文件到onnx模型文件 + +2.googlenet_atc.sh:onnx模型转换om模型脚本 + +3.preprocess_googlenet_pth.py:数据集预处理脚本,通过均值方差处理归一化图片,生成图片二进制文件 + +4.aipp_googlenet_pth.config:数据集aipp预处理配置文件 + +5.get_info.py:生成推理输入的数据集二进制info文件或jpg info文件 + +6.googlenet_val.info:ImageNet验证集二进制info文件,用于benchmark推理获取数据集 + +7.ImageNet.info:ImageNet验证集jpg info文件,用于benchmark推理获取数据集 + +8.val_label.txt:ImageNet数据集标签,用于验证推理结果 + +9.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer + +10.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy + + + + + +推理端到端步骤: + +(1) 从Torchvision下载googlenet模型,通过googlenet_pth2onnx.py脚本转化为onnx模型 + + + +(2)运行googlenet_atc.sh脚本转换om模型 + +本demo已提供调优完成的om模型 + + + +(3)用preprocess_googlenet_pth.py脚本处理数据集,参考googlenet_val.info配置处理后的二进制数据集路径。或者配置数据集aipp预处理文件aipp_googlenet_pth.config。 + python3 preprocess_googlenet_pth.py dataset/ImageNet/val_union/ pre_bin + + + +(4)生成推理输入的数据集二进制info文件或jpg info文件 + python3 get_info.py bin pre_bin googlenet_val.info 224 224 + python3 get_info.py jpg dataset/ImageNet/val_union ImageNet.info + + + +(5)使用benchmark离线推理 + ./benchmark -model_type=vision -om_path=googlenet_bs16.om -device_id=0 -batch_size=16 -input_text_path=googlenet_val.info -input_width=224 -input_height=224 -useDvpp=false + 或者 + ./benchmark -model_type=vision -om_path=googlenet_bs1.om -device_id=0 -batch_size=1 -input_text_path=ImageNet.info -input_width=256 -input_height=256 -useDvpp=true + + +运行benchmark推理,结果保存在 ./result 目录下 + + + +(6)python3.7 vision_metric_ImageNet.py result/dumpOutput_device0/ ./val_label.txt ./ result.json + +验证推理结果 + diff --git a/ACL_PyTorch/built-in/cv/GoogleNet_for_Pytorch/get_info.py b/ACL_PyTorch/built-in/cv/GoogleNet_for_Pytorch/get_info.py index 0578e4f00cd9661c6dcfa7db7b72f196677ff422..7b14c54b909b60730e9e3471ee0435ee4cb8622f 100644 --- a/ACL_PyTorch/built-in/cv/GoogleNet_for_Pytorch/get_info.py +++ b/ACL_PyTorch/built-in/cv/GoogleNet_for_Pytorch/get_info.py @@ -1,46 +1,46 @@ -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/GoogleNet_for_Pytorch/preprocess_googlenet_pth.py b/ACL_PyTorch/built-in/cv/GoogleNet_for_Pytorch/preprocess_googlenet_pth.py index 04f41f75979bcbc2ca8c939b37b29d8a59f8d22a..965681f30d9a5413948b7fb1cdd158d1ac2e5e22 100644 --- a/ACL_PyTorch/built-in/cv/GoogleNet_for_Pytorch/preprocess_googlenet_pth.py +++ b/ACL_PyTorch/built-in/cv/GoogleNet_for_Pytorch/preprocess_googlenet_pth.py @@ -1,85 +1,85 @@ -import os -import sys -import numpy as np -from PIL import Image - - -def resize(img, size, interpolation=Image.BILINEAR): - r"""Resize the input PIL Image to the given size. - - Args: - img (PIL Image): Image to be resized. - size (sequence or int): Desired output size. If size is a sequence like - (h, w), the output size will be matched to this. If size is an int, - the smaller edge of the image will be matched to this number maintaining - the aspect ratio. i.e, if height > width, then image will be rescaled to - :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)` - interpolation (int, optional): Desired interpolation. Default is - ``PIL.Image.BILINEAR`` - - Returns: - PIL Image: Resized image. - """ - - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def center_crop(img, out_height, out_width): - height, width, _ = img.shape - left = int((width - out_width) / 2) - right = int((width + out_width) / 2) - top = int((height - out_height) / 2) - bottom = int((height + out_height) / 2) - img = img[top:bottom, left:right] - return img - - -def preprocess(file_path, bin_path): - in_files = os.listdir(file_path) - if not os.path.exists(bin_path): - os.makedirs(bin_path) - i = 0 - - resize_size = 256 - mean = [0.485, 0.456, 0.406] - std = [0.229, 0.224, 0.225] - - for file in in_files: - i = i + 1 - print(file, "===", i) - - img = Image.open(os.path.join(file_path, file)).convert('RGB') - - img = resize(img, resize_size) # transforms.Resize(256) - img = np.array(img, dtype=np.float32) - img = center_crop(img, 224, 224) # transforms.CenterCrop(224) - img = img / 255. # transforms.ToTensor() - # 均值方差 - img[..., 0] -= mean[0] - img[..., 1] -= mean[1] - img[..., 2] -= mean[2] - img[..., 0] /= std[0] - img[..., 1] /= std[1] - img[..., 2] /= std[2] - img = img.transpose(2, 0, 1) # HWC -> CHW - - img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) - - -if __name__ == "__main__": - file_path = os.path.abspath(sys.argv[1]) - bin_path = os.path.abspath(sys.argv[2]) - preprocess(file_path, bin_path) +import os +import sys +import numpy as np +from PIL import Image + + +def resize(img, size, interpolation=Image.BILINEAR): + r"""Resize the input PIL Image to the given size. + + Args: + img (PIL Image): Image to be resized. + size (sequence or int): Desired output size. If size is a sequence like + (h, w), the output size will be matched to this. If size is an int, + the smaller edge of the image will be matched to this number maintaining + the aspect ratio. i.e, if height > width, then image will be rescaled to + :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)` + interpolation (int, optional): Desired interpolation. Default is + ``PIL.Image.BILINEAR`` + + Returns: + PIL Image: Resized image. + """ + + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def center_crop(img, out_height, out_width): + height, width, _ = img.shape + left = int((width - out_width) / 2) + right = int((width + out_width) / 2) + top = int((height - out_height) / 2) + bottom = int((height + out_height) / 2) + img = img[top:bottom, left:right] + return img + + +def preprocess(file_path, bin_path): + in_files = os.listdir(file_path) + if not os.path.exists(bin_path): + os.makedirs(bin_path) + i = 0 + + resize_size = 256 + mean = [0.485, 0.456, 0.406] + std = [0.229, 0.224, 0.225] + + for file in in_files: + i = i + 1 + print(file, "===", i) + + img = Image.open(os.path.join(file_path, file)).convert('RGB') + + img = resize(img, resize_size) # transforms.Resize(256) + img = np.array(img, dtype=np.float32) + img = center_crop(img, 224, 224) # transforms.CenterCrop(224) + img = img / 255. # transforms.ToTensor() + # 均值方差 + img[..., 0] -= mean[0] + img[..., 1] -= mean[1] + img[..., 2] -= mean[2] + img[..., 0] /= std[0] + img[..., 1] /= std[1] + img[..., 2] /= std[2] + img = img.transpose(2, 0, 1) # HWC -> CHW + + img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) + + +if __name__ == "__main__": + file_path = os.path.abspath(sys.argv[1]) + bin_path = os.path.abspath(sys.argv[2]) + preprocess(file_path, bin_path) diff --git a/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/ReadMe.md b/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/ReadMe.md index ec24e9ba99349208babf44d30998a10b12777715..ffd9dfc52a03b17b8a7c92201304a020183cda1a 100644 --- a/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/ReadMe.md +++ b/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/ReadMe.md @@ -1,95 +1,95 @@ -文件作用说明: - -1. inceptionv3_pth2onnx.py:用于转换pth模型文件到onnx模型文件 -2. gen_calibration_bin.py:生成bin格式数据集脚本,数据集用于量化校准 -3. inceptionv3_atc.sh:onnx模型转换om模型脚本 -4. imagenet_torch_preprocess.py:数据集预处理脚本,对图片进行缩放裁剪,生成图片二进制文件 -5. aipp_inceptionv3_pth.config:数据集aipp预处理配置文件 -6. gen_dataset_info.py:生成推理输入的数据集二进制info文件 -7. env.sh:环境变量文件 -8. benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer -9. vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy - - - -推理端到端步骤: - -1. 从Torchvision下载inceptionv3模型,通过inceptionv3_pth2onnx.py脚本转化为onnx模型 - -2. ONNX模型量化 - - 1. AMCT工具包安装,具体参考《[CANN 开发辅助工具指南 01](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools)》中的昇腾模型压缩工具使用指南(ONNX)章节; - - 2. 生成bin格式数据集,数据集用于校正量化因子。当前模型为动态batch,建议使用较大的batch size: - - ``` - python3.7 gen_calibration_bin.py inceptionv3 /root/dataset/ImageNet/val_union ./calibration_bin 32 1 - ``` - - 参数说明: - - - inceptionv3:模型类型 - - /root/dataset/ImageNet/val_union :模型使用的数据集路径; - - ./calibration_bin:生成的bin格式数据集路径; - - 32:batch size; - - 1:batch num。 - - 3. ONNX模型量化 - - ``` - amct_onnx calibration --model inceptionv3.onnx --save_path ./result/inceptionv3 --input_shape "actual_input_1:32,3,299,299" --data_dir "./calibration_bin" --data_types "float32" - ``` - - 会在result目录下生成inceptionv3_deploy_model.onnx量化模型 - - 4. 量化模型后续的推理验证流程和非量化一致。 - -3. 运行inceptionv3_atc.sh脚本转换om模型 - -4. 用imagenet_torch_preprocess.py脚本处理数据集 - -``` -python3.7 imagenet_torch_preprocess.py inceptionv3 /root/dataset/ImageNet/val_union ./prep_dataset -``` - -5. 生成推理输入的数据集二进制info文件 - -``` -python3.7 gen_dataset_info.py bin ./prep_dataset ./inceptionv3_prep_bin.info 299 299 -``` - -6. 设置环境变量 - -``` -source env.sh -``` - -7. 使用benchmark离线推理 - -``` -./benchmark.x86_64 -model_type=vision -om_path=inceptionv3_bs8.om -device_id=0 -batch_size=8 -input_text_path=inceptionv3_prep_bin.info -input_width=299 -input_height=299 -output_binary=False -useDvpp=False -``` - -运行benchmark推理,结果保存在 ./result 目录下 - -8. 验证推理结果 - -``` -python3.7 vision_metric_ImageNet.py result/dumpOutput_device0/ /root/dataset/ImageNet/val_label.txt ./ result.json -``` - - - - -模型获取 - -可以使用如下命令获取PyTorch框架的原始模型和转换后的Onnx模型 - -Pytorch: -``` -wget https://modelzoo-train-atc.obs.cn-north-4.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/InceptionV3/inception_v3.pth -``` -ONNX: -``` -wget https://modelzoo-train-atc.obs.cn-north-4.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/InceptionV3/inceptionv3.onnx -``` +文件作用说明: + +1. inceptionv3_pth2onnx.py:用于转换pth模型文件到onnx模型文件 +2. gen_calibration_bin.py:生成bin格式数据集脚本,数据集用于量化校准 +3. inceptionv3_atc.sh:onnx模型转换om模型脚本 +4. imagenet_torch_preprocess.py:数据集预处理脚本,对图片进行缩放裁剪,生成图片二进制文件 +5. aipp_inceptionv3_pth.config:数据集aipp预处理配置文件 +6. gen_dataset_info.py:生成推理输入的数据集二进制info文件 +7. env.sh:环境变量文件 +8. benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer +9. vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy + + + +推理端到端步骤: + +1. 从Torchvision下载inceptionv3模型,通过inceptionv3_pth2onnx.py脚本转化为onnx模型 + +2. ONNX模型量化 + + 1. AMCT工具包安装,具体参考《[CANN 开发辅助工具指南 01](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools)》中的昇腾模型压缩工具使用指南(ONNX)章节; + + 2. 生成bin格式数据集,数据集用于校正量化因子。当前模型为动态batch,建议使用较大的batch size: + + ``` + python3.7 gen_calibration_bin.py inceptionv3 /root/dataset/ImageNet/val_union ./calibration_bin 32 1 + ``` + + 参数说明: + + - inceptionv3:模型类型 + - /root/dataset/ImageNet/val_union :模型使用的数据集路径; + - ./calibration_bin:生成的bin格式数据集路径; + - 32:batch size; + - 1:batch num。 + + 3. ONNX模型量化 + + ``` + amct_onnx calibration --model inceptionv3.onnx --save_path ./result/inceptionv3 --input_shape "actual_input_1:32,3,299,299" --data_dir "./calibration_bin" --data_types "float32" + ``` + + 会在result目录下生成inceptionv3_deploy_model.onnx量化模型 + + 4. 量化模型后续的推理验证流程和非量化一致。 + +3. 运行inceptionv3_atc.sh脚本转换om模型 + +4. 用imagenet_torch_preprocess.py脚本处理数据集 + +``` +python3.7 imagenet_torch_preprocess.py inceptionv3 /root/dataset/ImageNet/val_union ./prep_dataset +``` + +5. 生成推理输入的数据集二进制info文件 + +``` +python3.7 gen_dataset_info.py bin ./prep_dataset ./inceptionv3_prep_bin.info 299 299 +``` + +6. 设置环境变量 + +``` +source env.sh +``` + +7. 使用benchmark离线推理 + +``` +./benchmark.x86_64 -model_type=vision -om_path=inceptionv3_bs8.om -device_id=0 -batch_size=8 -input_text_path=inceptionv3_prep_bin.info -input_width=299 -input_height=299 -output_binary=False -useDvpp=False +``` + +运行benchmark推理,结果保存在 ./result 目录下 + +8. 验证推理结果 + +``` +python3.7 vision_metric_ImageNet.py result/dumpOutput_device0/ /root/dataset/ImageNet/val_label.txt ./ result.json +``` + + + + +模型获取 + +可以使用如下命令获取PyTorch框架的原始模型和转换后的Onnx模型 + +Pytorch: +``` +wget https://modelzoo-train-atc.obs.cn-north-4.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/InceptionV3/inception_v3.pth +``` +ONNX: +``` +wget https://modelzoo-train-atc.obs.cn-north-4.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/InceptionV3/inceptionv3.onnx +``` diff --git a/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/gen_dataset_info.py b/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/gen_dataset_info.py index 61450b4410663ae5e66ec29ed296ff6584203e31..5381839f653a885666e3fc456db9a1c22b8583a1 100644 --- a/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/gen_dataset_info.py +++ b/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/gen_dataset_info.py @@ -1,61 +1,61 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) + diff --git a/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/imagenet_torch_preprocess.py b/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/imagenet_torch_preprocess.py index ed4b4e2a5380e3ee608287596412963d92b9bb79..6f89d347b52642cc3a1fc8ba73dae2d4230e7a0c 100644 --- a/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/imagenet_torch_preprocess.py +++ b/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/imagenet_torch_preprocess.py @@ -1,113 +1,113 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from PIL import Image -import numpy as np -import multiprocessing - - -model_config = { - 'resnet': { - 'resize': 256, - 'centercrop': 224, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv3': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv4': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.5, 0.5, 0.5], - 'std': [0.5, 0.5, 0.5], - }, -} - - -def center_crop(img, output_size): - if isinstance(output_size, int): - output_size = (int(output_size), int(output_size)) - image_width, image_height = img.size - crop_height, crop_width = output_size - crop_top = int(round((image_height - crop_height) / 2.)) - crop_left = int(round((image_width - crop_width) / 2.)) - return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) - - -def resize(img, size, interpolation=Image.BILINEAR): - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def gen_input_bin(mode_type, file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - # RGBA to RGB - image = Image.open(os.path.join(src_path, file)).convert('RGB') - image = resize(image, model_config[mode_type]['resize']) # Resize - image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop - img = np.array(image, dtype=np.int8) - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - - -def preprocess(mode_type, src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") - mode_type = sys.argv[1] - src_path = sys.argv[2] - save_path = sys.argv[3] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - if mode_type not in model_config: - model_type_help = "model type: " - for key in model_config.keys(): - model_type_help += key - model_type_help += ' ' - raise Exception(model_type_help) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - preprocess(mode_type, src_path, save_path) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from PIL import Image +import numpy as np +import multiprocessing + + +model_config = { + 'resnet': { + 'resize': 256, + 'centercrop': 224, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv3': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv4': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.5, 0.5, 0.5], + 'std': [0.5, 0.5, 0.5], + }, +} + + +def center_crop(img, output_size): + if isinstance(output_size, int): + output_size = (int(output_size), int(output_size)) + image_width, image_height = img.size + crop_height, crop_width = output_size + crop_top = int(round((image_height - crop_height) / 2.)) + crop_left = int(round((image_width - crop_width) / 2.)) + return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) + + +def resize(img, size, interpolation=Image.BILINEAR): + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def gen_input_bin(mode_type, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + # RGBA to RGB + image = Image.open(os.path.join(src_path, file)).convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.int8) + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +def preprocess(mode_type, src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") + mode_type = sys.argv[1] + src_path = sys.argv[2] + save_path = sys.argv[3] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if mode_type not in model_config: + model_type_help = "model type: " + for key in model_config.keys(): + model_type_help += key + model_type_help += ' ' + raise Exception(model_type_help) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess(mode_type, src_path, save_path) + diff --git a/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/requirements.txt b/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/requirements.txt index 112989ef5d8909e534ff5ee3b793acb47df14ee0..1845fd861663faaea2c8d5fc747bbb4b35552526 100644 --- a/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/requirements.txt +++ b/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch/requirements.txt @@ -1,5 +1,5 @@ -torch == 1.6.0 -torchvision == 0.7.0 -onnx == 1.7.0 -numpy == 1.18.5 -Pillow == 7.2.0 +torch == 1.6.0 +torchvision == 0.7.0 +onnx == 1.7.0 +numpy == 1.18.5 +Pillow == 7.2.0 diff --git a/ACL_PyTorch/built-in/cv/InceptionV4_for_Pytorch/ReadMe.md b/ACL_PyTorch/built-in/cv/InceptionV4_for_Pytorch/ReadMe.md index 6cab5096719f409f408e4f7f715e7ae88dcf363e..287a11d8a27e8dbdedad7b4c563f4333a1baa77a 100644 --- a/ACL_PyTorch/built-in/cv/InceptionV4_for_Pytorch/ReadMe.md +++ b/ACL_PyTorch/built-in/cv/InceptionV4_for_Pytorch/ReadMe.md @@ -1,63 +1,63 @@ -文件作用说明: - -1.inceptionv4_pth2onnx.py:用于转换pth模型文件到onnx模型文件 - -2.inceptionv4_atc.sh:onnx模型转换om模型脚本 - -3.preprocess_inceptionv4_pth.py:数据集预处理脚本,通过均值方差处理归一化图片,生成图片二进制文件 - -4.aipp_inceptionv4_pth.config:数据集aipp预处理配置文件 - -5.get_info.py:生成推理输入的数据集二进制info文件或jpg info文件 - -6.inceptionv4_val.info:ImageNet验证集二进制info文件,用于benchmark推理获取数据集 - -7.ImageNet.info:ImageNet验证集jpg info文件,用于benchmark推理获取数据集 - -8.val_label.txt:ImageNet数据集标签,用于验证推理结果 - -9.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer - -10.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy - - - - - -推理端到端步骤: - -(1) 从https://github.com/Cadene/pretrained-models.pytorch下载inceptionv4模型,通过inceptionv4_pth2onnx.py脚本转化为onnx模型 - 安装pretrainedmodels后需修改pretrained-models.pytorch/pretrainedmodels/models/inceptionv4.py:adaptiveAvgPoolWidth = features.shape[2].item() - - - -(2)运行inceptionv4_atc.sh脚本转换om模型 - -本demo已提供调优完成的om模型 - - - -(3)用preprocess_inceptionv4_pth.py脚本处理数据集,参考inceptionv4_val.info配置处理后的二进制数据集路径。或者配置数据集aipp预处理文件aipp_inceptionv4_pth.config。 - python3 preprocess_inceptionv4_pth.py dataset/ImageNet/val_union/ prep_bin - - - -(4)生成推理输入的数据集二进制info文件或jpg info文件 - python3 get_info.py bin prep_bin inceptionv4_val.info 299 299 - python3 get_info.py jpg dataset/ImageNet/val_union ImageNet.info - - - -(5)使用benchmark离线推理 - ./benchmark -model_type=vision -om_path=inceptionv4_bs16.om -device_id=0 -batch_size=16 -input_text_path=inceptionv4_val.info -input_width=299 -input_height=299 -useDvpp=false - 或者 - ./benchmark -model_type=vision -om_path=inceptionv4_bs1.om -device_id=0 -batch_size=1 -input_text_path=ImageNet.info -input_width=336 -input_height=336 -useDvpp=true - -运行benchmark推理,结果保存在 ./result 目录下 - - - -(6)python3.7 vision_metric_ImageNet.py result/dumpOutput_device0/ ./val_label.txt ./ result.json - -验证推理结果 - +文件作用说明: + +1.inceptionv4_pth2onnx.py:用于转换pth模型文件到onnx模型文件 + +2.inceptionv4_atc.sh:onnx模型转换om模型脚本 + +3.preprocess_inceptionv4_pth.py:数据集预处理脚本,通过均值方差处理归一化图片,生成图片二进制文件 + +4.aipp_inceptionv4_pth.config:数据集aipp预处理配置文件 + +5.get_info.py:生成推理输入的数据集二进制info文件或jpg info文件 + +6.inceptionv4_val.info:ImageNet验证集二进制info文件,用于benchmark推理获取数据集 + +7.ImageNet.info:ImageNet验证集jpg info文件,用于benchmark推理获取数据集 + +8.val_label.txt:ImageNet数据集标签,用于验证推理结果 + +9.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer + +10.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy + + + + + +推理端到端步骤: + +(1) 从https://github.com/Cadene/pretrained-models.pytorch下载inceptionv4模型,通过inceptionv4_pth2onnx.py脚本转化为onnx模型 + 安装pretrainedmodels后需修改pretrained-models.pytorch/pretrainedmodels/models/inceptionv4.py:adaptiveAvgPoolWidth = features.shape[2].item() + + + +(2)运行inceptionv4_atc.sh脚本转换om模型 + +本demo已提供调优完成的om模型 + + + +(3)用preprocess_inceptionv4_pth.py脚本处理数据集,参考inceptionv4_val.info配置处理后的二进制数据集路径。或者配置数据集aipp预处理文件aipp_inceptionv4_pth.config。 + python3 preprocess_inceptionv4_pth.py dataset/ImageNet/val_union/ prep_bin + + + +(4)生成推理输入的数据集二进制info文件或jpg info文件 + python3 get_info.py bin prep_bin inceptionv4_val.info 299 299 + python3 get_info.py jpg dataset/ImageNet/val_union ImageNet.info + + + +(5)使用benchmark离线推理 + ./benchmark -model_type=vision -om_path=inceptionv4_bs16.om -device_id=0 -batch_size=16 -input_text_path=inceptionv4_val.info -input_width=299 -input_height=299 -useDvpp=false + 或者 + ./benchmark -model_type=vision -om_path=inceptionv4_bs1.om -device_id=0 -batch_size=1 -input_text_path=ImageNet.info -input_width=336 -input_height=336 -useDvpp=true + +运行benchmark推理,结果保存在 ./result 目录下 + + + +(6)python3.7 vision_metric_ImageNet.py result/dumpOutput_device0/ ./val_label.txt ./ result.json + +验证推理结果 + diff --git a/ACL_PyTorch/built-in/cv/InceptionV4_for_Pytorch/get_info.py b/ACL_PyTorch/built-in/cv/InceptionV4_for_Pytorch/get_info.py index 0578e4f00cd9661c6dcfa7db7b72f196677ff422..7b14c54b909b60730e9e3471ee0435ee4cb8622f 100644 --- a/ACL_PyTorch/built-in/cv/InceptionV4_for_Pytorch/get_info.py +++ b/ACL_PyTorch/built-in/cv/InceptionV4_for_Pytorch/get_info.py @@ -1,46 +1,46 @@ -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/InceptionV4_for_Pytorch/preprocess_inceptionv4_pth.py b/ACL_PyTorch/built-in/cv/InceptionV4_for_Pytorch/preprocess_inceptionv4_pth.py index bf9f930b05be0bba0482fc85e8f72b84db205d32..591fdb1db16ba4e37b813afc1b1242b932dd8b10 100644 --- a/ACL_PyTorch/built-in/cv/InceptionV4_for_Pytorch/preprocess_inceptionv4_pth.py +++ b/ACL_PyTorch/built-in/cv/InceptionV4_for_Pytorch/preprocess_inceptionv4_pth.py @@ -1,85 +1,85 @@ -import os -import sys -import numpy as np -from PIL import Image - - -def resize(img, size, interpolation=Image.BILINEAR): - r"""Resize the input PIL Image to the given size. - - Args: - img (PIL Image): Image to be resized. - size (sequence or int): Desired output size. If size is a sequence like - (h, w), the output size will be matched to this. If size is an int, - the smaller edge of the image will be matched to this number maintaining - the aspect ratio. i.e, if height > width, then image will be rescaled to - :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)` - interpolation (int, optional): Desired interpolation. Default is - ``PIL.Image.BILINEAR`` - - Returns: - PIL Image: Resized image. - """ - - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def center_crop(img, out_height, out_width): - height, width, _ = img.shape - left = int((width - out_width) / 2) - right = int((width + out_width) / 2) - top = int((height - out_height) / 2) - bottom = int((height + out_height) / 2) - img = img[top:bottom, left:right] - return img - - -def preprocess(file_path, bin_path): - in_files = os.listdir(file_path) - if not os.path.exists(bin_path): - os.makedirs(bin_path) - i = 0 - - resize_size = 342 - mean = [0.5, 0.5, 0.5] - std = [0.5, 0.5, 0.5] - - for file in in_files: - i = i + 1 - print(file, "===", i) - - img = Image.open(os.path.join(file_path, file)).convert('RGB') - - img = resize(img, resize_size) # transforms.Resize(342) - img = np.array(img, dtype=np.float32) - img = center_crop(img, 299, 299) # transforms.CenterCrop(299) - img = img / 255. # transforms.ToTensor() - # 均值方差 - img[..., 0] -= mean[0] - img[..., 1] -= mean[1] - img[..., 2] -= mean[2] - img[..., 0] /= std[0] - img[..., 1] /= std[1] - img[..., 2] /= std[2] - img = img.transpose(2, 0, 1) # HWC -> CHW - - img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) - - -if __name__ == "__main__": - file_path = os.path.abspath(sys.argv[1]) - bin_path = os.path.abspath(sys.argv[2]) - preprocess(file_path, bin_path) +import os +import sys +import numpy as np +from PIL import Image + + +def resize(img, size, interpolation=Image.BILINEAR): + r"""Resize the input PIL Image to the given size. + + Args: + img (PIL Image): Image to be resized. + size (sequence or int): Desired output size. If size is a sequence like + (h, w), the output size will be matched to this. If size is an int, + the smaller edge of the image will be matched to this number maintaining + the aspect ratio. i.e, if height > width, then image will be rescaled to + :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)` + interpolation (int, optional): Desired interpolation. Default is + ``PIL.Image.BILINEAR`` + + Returns: + PIL Image: Resized image. + """ + + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def center_crop(img, out_height, out_width): + height, width, _ = img.shape + left = int((width - out_width) / 2) + right = int((width + out_width) / 2) + top = int((height - out_height) / 2) + bottom = int((height + out_height) / 2) + img = img[top:bottom, left:right] + return img + + +def preprocess(file_path, bin_path): + in_files = os.listdir(file_path) + if not os.path.exists(bin_path): + os.makedirs(bin_path) + i = 0 + + resize_size = 342 + mean = [0.5, 0.5, 0.5] + std = [0.5, 0.5, 0.5] + + for file in in_files: + i = i + 1 + print(file, "===", i) + + img = Image.open(os.path.join(file_path, file)).convert('RGB') + + img = resize(img, resize_size) # transforms.Resize(342) + img = np.array(img, dtype=np.float32) + img = center_crop(img, 299, 299) # transforms.CenterCrop(299) + img = img / 255. # transforms.ToTensor() + # 均值方差 + img[..., 0] -= mean[0] + img[..., 1] -= mean[1] + img[..., 2] -= mean[2] + img[..., 0] /= std[0] + img[..., 1] /= std[1] + img[..., 2] /= std[2] + img = img.transpose(2, 0, 1) # HWC -> CHW + + img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) + + +if __name__ == "__main__": + file_path = os.path.abspath(sys.argv[1]) + bin_path = os.path.abspath(sys.argv[2]) + preprocess(file_path, bin_path) diff --git a/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/PytorchTransfer.py b/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/PytorchTransfer.py index 15680c59ff5a61a0b0d01d869bc39087000b7dc1..15eeaaa895e24bcf280649fb8f5bc9a8f1288f31 100644 --- a/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/PytorchTransfer.py +++ b/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/PytorchTransfer.py @@ -1,47 +1,47 @@ -import sys -import os -import torch -import cv2 -from PIL import Image -import numpy as np -import torch.utils.data -import torchvision.transforms as transforms -from torch.autograd import Variable - - -def mobilenet_onnx(input_path: str, output_path: str): - img = cv2.imread(input_path) - img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) - pilimg = Image.fromarray(img) - normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], - std=[0.229, 0.224, 0.225]) - val_transformer = transforms.Compose([ - transforms.Scale(256), - transforms.CenterCrop(224), - transforms.ToTensor(), - normalize - ]) - - img_tensor = val_transformer(pilimg) - img_tensor = torch.unsqueeze(img_tensor, dim=0).float() - img_tensor = Variable(img_tensor, requires_grad=False) - img_tensor.reshape(1, 3, 224, 224) - img_numpy = img_tensor.cpu().numpy() - - img_name = input_path.split('/')[-1] - bin_name = img_name.split('.')[0] + ".bin" - output_fl = os.path.join(output_path, bin_name) - # save img_tensor as binary file for om inference input - img_numpy.tofile(output_fl) - - -if __name__ == "__main__": - input_img_dir = sys.argv[1] - output_img_dir = sys.argv[2] - images = os.listdir(input_img_dir) - for image_name in images: - if not image_name.endswith(".jpeg"): - continue - print("start to process image {}....".format(image_name)) - path_image = os.path.join(input_img_dir, image_name) - mobilenet_onnx(path_image, output_img_dir) +import sys +import os +import torch +import cv2 +from PIL import Image +import numpy as np +import torch.utils.data +import torchvision.transforms as transforms +from torch.autograd import Variable + + +def mobilenet_onnx(input_path: str, output_path: str): + img = cv2.imread(input_path) + img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) + pilimg = Image.fromarray(img) + normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]) + val_transformer = transforms.Compose([ + transforms.Scale(256), + transforms.CenterCrop(224), + transforms.ToTensor(), + normalize + ]) + + img_tensor = val_transformer(pilimg) + img_tensor = torch.unsqueeze(img_tensor, dim=0).float() + img_tensor = Variable(img_tensor, requires_grad=False) + img_tensor.reshape(1, 3, 224, 224) + img_numpy = img_tensor.cpu().numpy() + + img_name = input_path.split('/')[-1] + bin_name = img_name.split('.')[0] + ".bin" + output_fl = os.path.join(output_path, bin_name) + # save img_tensor as binary file for om inference input + img_numpy.tofile(output_fl) + + +if __name__ == "__main__": + input_img_dir = sys.argv[1] + output_img_dir = sys.argv[2] + images = os.listdir(input_img_dir) + for image_name in images: + if not image_name.endswith(".jpeg"): + continue + print("start to process image {}....".format(image_name)) + path_image = os.path.join(input_img_dir, image_name) + mobilenet_onnx(path_image, output_img_dir) diff --git a/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/ReadMe.md b/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/ReadMe.md index 2d95c4d9fe555d6663f3d0822d3d897758ff1a5a..37b1c856380e43dfa866479f1dab53645e9e5a1c 100644 --- a/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/ReadMe.md +++ b/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/ReadMe.md @@ -1,48 +1,48 @@ -文件作用说明: - -1.auto_tune.sh:模型转换脚本,集成了auto tune功能,可以手动关闭 - -2.pth2onnx.py:用于转换pth文件到onnx文件 - -3.pthtar2onnx.py:用于转换pth.tar文件到onnx文件 - -4.BinaryImageNet.info:ImageNet数据集信息,用于benchmark推理获取数据集 - -5.PytorchTransfer.py:数据集预处理脚本,通过均值方差处理归一化图片 - -6.val_label.txt:ImageNet数据集标签,用于验证推理结果 - -7.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy - -8.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer - - - - - -推理端到端步骤: - -(1) 从Torchvision下载mobilenetV2模型或者指定自己训练好的pth文件路径,通过pth2onnx.py脚本转化为onnx模型 - - - -(2)运行auto_tune.sh脚本转换om模型,也可以选择手动关闭auto_tune - -本demo已提供调优完成的om模型 - - - -(3)用PytorchTransfer.py脚本处理数据集,参考BinaryImageNet.Info配置处理后的二进制数据集路径 - - - -(4)./benchmark.x86_64 -model_type=vision -batch_size=16 -device_id=0 -input_text_path=./BinaryImageNet.info -input_width=224 -input_height=224 -om_path=./resnet50_pytorch.om -useDvpp=False - -运行benchmark推理,结果保存在 ./result 目录下 - - - -(5)python3.7 vision_metric_ImageNet.py result/dumpOutput/ ./val_label.txt ./ result.json - -验证推理结果 - +文件作用说明: + +1.auto_tune.sh:模型转换脚本,集成了auto tune功能,可以手动关闭 + +2.pth2onnx.py:用于转换pth文件到onnx文件 + +3.pthtar2onnx.py:用于转换pth.tar文件到onnx文件 + +4.BinaryImageNet.info:ImageNet数据集信息,用于benchmark推理获取数据集 + +5.PytorchTransfer.py:数据集预处理脚本,通过均值方差处理归一化图片 + +6.val_label.txt:ImageNet数据集标签,用于验证推理结果 + +7.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy + +8.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer + + + + + +推理端到端步骤: + +(1) 从Torchvision下载mobilenetV2模型或者指定自己训练好的pth文件路径,通过pth2onnx.py脚本转化为onnx模型 + + + +(2)运行auto_tune.sh脚本转换om模型,也可以选择手动关闭auto_tune + +本demo已提供调优完成的om模型 + + + +(3)用PytorchTransfer.py脚本处理数据集,参考BinaryImageNet.Info配置处理后的二进制数据集路径 + + + +(4)./benchmark.x86_64 -model_type=vision -batch_size=16 -device_id=0 -input_text_path=./BinaryImageNet.info -input_width=224 -input_height=224 -om_path=./resnet50_pytorch.om -useDvpp=False + +运行benchmark推理,结果保存在 ./result 目录下 + + + +(5)python3.7 vision_metric_ImageNet.py result/dumpOutput/ ./val_label.txt ./ result.json + +验证推理结果 + diff --git a/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/pth2onnx.py b/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/pth2onnx.py index e147398b6df571332e3c5191153ce7496ce30a4b..8b54912bf92699148db1b0d2d314c68761a99f58 100644 --- a/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/pth2onnx.py +++ b/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/pth2onnx.py @@ -1,27 +1,27 @@ -import torch -import torch.onnx -import torchvision.models as models - - -def convert(): - model = models.mobilenet_v2(pretrained=False) - pthfile = './mobilenet_v2-b0353104.pth' - mobilenet_v2 = torch.load(pthfile, map_location='cpu') - model.load_state_dict(mobilenet_v2) - print(model) - - input_names = ["actual_input_1"] - output_names = ["output1"] - dummy_input = torch.randn(16, 3, 224, 224) - torch.onnx.export( - model, - dummy_input, - "mobilenet_v2_16.onnx", - input_names=input_names, - output_names=output_names, - opset_version=11) - - -if __name__ == "__main__": - convert() - +import torch +import torch.onnx +import torchvision.models as models + + +def convert(): + model = models.mobilenet_v2(pretrained=False) + pthfile = './mobilenet_v2-b0353104.pth' + mobilenet_v2 = torch.load(pthfile, map_location='cpu') + model.load_state_dict(mobilenet_v2) + print(model) + + input_names = ["actual_input_1"] + output_names = ["output1"] + dummy_input = torch.randn(16, 3, 224, 224) + torch.onnx.export( + model, + dummy_input, + "mobilenet_v2_16.onnx", + input_names=input_names, + output_names=output_names, + opset_version=11) + + +if __name__ == "__main__": + convert() + diff --git a/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/pthtar2onnx.py b/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/pthtar2onnx.py index ba5c4a2a594a478f4039950abc22e8fe439bf3c4..96cfdc837274461c7bc4e5cfe81e5cd01dba7fd5 100644 --- a/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/pthtar2onnx.py +++ b/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/pthtar2onnx.py @@ -1,41 +1,41 @@ -import torch -import torch.onnx -import mobilenet -from collections import OrderedDict - - -def proc_nodes_module(checkpoint, attr_name): - new_state_dict = OrderedDict() - for key, value in checkpoint[attr_name].items(): - if key == "module.features.0.0.weight": - print(value) - if key[0:7] == "module.": - name = key[7:] - else: - name = key[0:] - - new_state_dict[name] = value - return new_state_dict - - -def convert(): - checkpoint = torch.load("./mobilenet_cpu.pth.tar", map_location=torch.device('cpu')) - checkpoint['state_dict'] = proc_nodes_module(checkpoint, 'state_dict') - model = mobilenet.mobilenet_v2(pretrained=False) - model.load_state_dict(checkpoint['state_dict']) - model.eval() - print(model) - - input_names = ["actual_input_1"] - output_names = ["output1"] - dummy_input = torch.randn(1, 3, 224, 224) - torch.onnx.export( - model, dummy_input, - "mobilenet_v2_npu.onnx", - input_names=input_names, - output_names=output_names, - opset_version=11) # 7 - - -if __name__ == "__main__": - convert() +import torch +import torch.onnx +import mobilenet +from collections import OrderedDict + + +def proc_nodes_module(checkpoint, attr_name): + new_state_dict = OrderedDict() + for key, value in checkpoint[attr_name].items(): + if key == "module.features.0.0.weight": + print(value) + if key[0:7] == "module.": + name = key[7:] + else: + name = key[0:] + + new_state_dict[name] = value + return new_state_dict + + +def convert(): + checkpoint = torch.load("./mobilenet_cpu.pth.tar", map_location=torch.device('cpu')) + checkpoint['state_dict'] = proc_nodes_module(checkpoint, 'state_dict') + model = mobilenet.mobilenet_v2(pretrained=False) + model.load_state_dict(checkpoint['state_dict']) + model.eval() + print(model) + + input_names = ["actual_input_1"] + output_names = ["output1"] + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export( + model, dummy_input, + "mobilenet_v2_npu.onnx", + input_names=input_names, + output_names=output_names, + opset_version=11) # 7 + + +if __name__ == "__main__": + convert() diff --git a/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/vision_metric_ImageNet.py b/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/vision_metric_ImageNet.py index 7bba5f8346a8893b4567d92b900fc4a651115976..f07c93617e661619c0e00be6a972e39fbde966a0 100644 --- a/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/vision_metric_ImageNet.py +++ b/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch/vision_metric_ImageNet.py @@ -1,173 +1,173 @@ -#coding = utf-8 -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = "" - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - #print(filepath) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - #print(img_gt_dict) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - # print(img_name) - #print(n_labels) - # print(gt) - - resCnt = min(len(sort_index), topn) - # print(sort_index[:5]) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - #print("***************") - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - #print("Top" + str(i + 1) + " accuracy" + ": " + str(round(accuracy[i] * 100, 2)) + '%') - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - #print("Time used:", elapsed) +#coding = utf-8 +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = "" + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + #print(filepath) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + #print(img_gt_dict) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + # print(img_name) + #print(n_labels) + # print(gt) + + resCnt = min(len(sort_index), topn) + # print(sort_index[:5]) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + #print("***************") + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + #print("Top" + str(i + 1) + " accuracy" + ": " + str(round(accuracy[i] * 100, 2)) + '%') + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + #print("Time used:", elapsed) diff --git a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/README.md b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/README.md index 66128e38a68c134cb17d5f8b28c807ab3843cfad..151e89d97449d52fcbd31720455d504d5d14983b 100644 --- a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/README.md +++ b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/README.md @@ -1,9 +1,9 @@ -### demo 文件夹内容说明 -- pth转换onnx脚本: export_onnx.py -- ATC转换脚本 run.sh / auto_tune.sh,及aipp配置文件 aipp.conf -- benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer -- 数据集信息 ImgPSENet.info 及二进制数据集信息 PSENet.info -- 二进制数据集预处理脚本: preprocess_psenet_pytorch.py -- 数据集标签: gt.zip -- 二进制后处理脚本: pth_bintotxt_nearest.py, pth_bintotxt_bilinear.py, pypse.py -- 精度评测脚本: Post-processing文件夹,script.py +### demo 文件夹内容说明 +- pth转换onnx脚本: export_onnx.py +- ATC转换脚本 run.sh / auto_tune.sh,及aipp配置文件 aipp.conf +- benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer +- 数据集信息 ImgPSENet.info 及二进制数据集信息 PSENet.info +- 二进制数据集预处理脚本: preprocess_psenet_pytorch.py +- 数据集标签: gt.zip +- 二进制后处理脚本: pth_bintotxt_nearest.py, pth_bintotxt_bilinear.py, pypse.py +- 精度评测脚本: Post-processing文件夹,script.py diff --git a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/export_onnx.py b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/export_onnx.py index 8f0d02b1545f6f4ea5dc6b018b4f92e6b44b7c25..9d5e7ed3ca283c1c3a18a36e5d5a4fe368d315a9 100644 --- a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/export_onnx.py +++ b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/export_onnx.py @@ -1,39 +1,39 @@ -import torch -from fpn_resnet_nearest import resnet50 -import torch.onnx -from collections import OrderedDict -import torch._utils - - -def proc_nodes_module(checkpoint, AttrName): - new_state_dict = OrderedDict() - for k, v in checkpoint[AttrName].items(): - if (k[0:7] == "module."): - name = k[7:] - else: - name = k[0:] - - new_state_dict[name] = v - return new_state_dict - - -def convert(): - checkpoint = torch.load("./PSENet_nearest.pth", map_location='cpu') - checkpoint['state_dict'] = proc_nodes_module(checkpoint, 'state_dict') - # model = mobilenet.mobilenet_v2(pretrained = False) - model = resnet50() - model.load_state_dict(checkpoint['state_dict']) - model.eval() - print(model) - - input_names = ["actual_input_1"] - output_names = ["output1"] - dummy_input = torch.randn(1, 3, 704, 1216) - import onnx - dynamic_axes = {'actual_input_1':{0:'-1'},'output1':{0:'-1'}} - print('\nStarting ONNX export with onnx %s...' % onnx.__version__) - torch.onnx.export(model, dummy_input, "PSENet_704_1216_nearest.onnx", input_names=input_names, output_names=output_names,dynamic_axes = dynamic_axes, opset_version=11) - - -if __name__ == "__main__": - convert() +import torch +from fpn_resnet_nearest import resnet50 +import torch.onnx +from collections import OrderedDict +import torch._utils + + +def proc_nodes_module(checkpoint, AttrName): + new_state_dict = OrderedDict() + for k, v in checkpoint[AttrName].items(): + if (k[0:7] == "module."): + name = k[7:] + else: + name = k[0:] + + new_state_dict[name] = v + return new_state_dict + + +def convert(): + checkpoint = torch.load("./PSENet_nearest.pth", map_location='cpu') + checkpoint['state_dict'] = proc_nodes_module(checkpoint, 'state_dict') + # model = mobilenet.mobilenet_v2(pretrained = False) + model = resnet50() + model.load_state_dict(checkpoint['state_dict']) + model.eval() + print(model) + + input_names = ["actual_input_1"] + output_names = ["output1"] + dummy_input = torch.randn(1, 3, 704, 1216) + import onnx + dynamic_axes = {'actual_input_1':{0:'-1'},'output1':{0:'-1'}} + print('\nStarting ONNX export with onnx %s...' % onnx.__version__) + torch.onnx.export(model, dummy_input, "PSENet_704_1216_nearest.onnx", input_names=input_names, output_names=output_names,dynamic_axes = dynamic_axes, opset_version=11) + + +if __name__ == "__main__": + convert() diff --git a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/fpn_resnet.py b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/fpn_resnet.py index 0305cf9e321751b436b534fd1e2160dde68e912b..2ee46e12299a997ebab5d86f249b8dbce828c6e6 100644 --- a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/fpn_resnet.py +++ b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/fpn_resnet.py @@ -1,341 +1,341 @@ -import torch.nn as nn -import time -import math -import torch.utils.model_zoo as model_zoo -import torch.nn.functional as F -import torch -import pdb - - -__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101', - 'resnet152'] - - -model_urls = { - 'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth', - 'resnet34': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth', - 'resnet50': 'https://download.pytorch.org/models/resnet50-19c8e357.pth', - 'resnet101': 'https://download.pytorch.org/models/resnet101-5d3mb4d8f.pth', - 'resnet152': 'https://download.pytorch.org/models/resnet152-b121ed2d.pth', -} - - -def conv3x3(in_planes, out_planes, stride=1): - """3x3 convolution with padding""" - return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, - padding=1, bias=False) - - -class BasicBlock(nn.Module): - expansion = 1 - - def __init__(self, inplanes, planes, stride=1, downsample=None): - super(BasicBlock, self).__init__() - self.conv1 = conv3x3(inplanes, planes, stride) - self.bn1 = nn.BatchNorm2d(planes) - self.relu = nn.ReLU(inplace=True) - self.conv2 = conv3x3(planes, planes) - self.bn2 = nn.BatchNorm2d(planes) - self.downsample = downsample - self.stride = stride - - def forward(self, x): - residual = x - - out = self.conv1(x) - out = self.bn1(out) - out = self.relu(out) - - out = self.conv2(out) - out = self.bn2(out) - - if self.downsample is not None: - residual = self.downsample(x) - - out += residual - out = self.relu(out) - - return out - - -class Bottleneck(nn.Module): - expansion = 4 - - def __init__(self, inplanes, planes, stride=1, downsample=None): - super(Bottleneck, self).__init__() - self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False) - self.bn1 = nn.BatchNorm2d(planes) - self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, - padding=1, bias=False) - self.bn2 = nn.BatchNorm2d(planes) - self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False) - self.bn3 = nn.BatchNorm2d(planes * 4) - self.relu = nn.ReLU(inplace=True) - self.downsample = downsample - self.stride = stride - - def forward(self, x): - residual = x - - out = self.conv1(x) - out = self.bn1(out) - out = self.relu(out) - - out = self.conv2(out) - out = self.bn2(out) - out = self.relu(out) - - out = self.conv3(out) - out = self.bn3(out) - - if self.downsample is not None: - residual = self.downsample(x) - - out += residual - out = self.relu(out) - - return out - - -class ResNet(nn.Module): - - def __init__(self, block, layers, num_classes=7, scale=1): - self.inplanes = 64 - super(ResNet, self).__init__() - self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, - bias=False) - self.bn1 = nn.BatchNorm2d(64) - self.relu1 = nn.ReLU(inplace=True) - self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1, return_indices = False) - self.layer1 = self._make_layer(block, 64, layers[0]) - self.layer2 = self._make_layer(block, 128, layers[1], stride=2) - self.layer3 = self._make_layer(block, 256, layers[2], stride=2) - self.layer4 = self._make_layer(block, 512, layers[3], stride=2) - # self.avgpool = nn.AvgPool2d(7, stride=1) - # self.fc = nn.Linear(512 * block.expansion, num_classes) - - # Top layer - self.toplayer = nn.Conv2d(2048, 256, kernel_size=1, stride=1, padding=0) # Reduce channels - self.toplayer_bn = nn.BatchNorm2d(256) - self.toplayer_relu = nn.ReLU(inplace=True) - - # Smooth layers - self.smooth1 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) - self.smooth1_bn = nn.BatchNorm2d(256) - self.smooth1_relu = nn.ReLU(inplace=True) - - self.smooth2 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) - self.smooth2_bn = nn.BatchNorm2d(256) - self.smooth2_relu = nn.ReLU(inplace=True) - - self.smooth3 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) - self.smooth3_bn = nn.BatchNorm2d(256) - self.smooth3_relu = nn.ReLU(inplace=True) - - # Lateral layers - self.latlayer1 = nn.Conv2d(1024, 256, kernel_size=1, stride=1, padding=0) - self.latlayer1_bn = nn.BatchNorm2d(256) - self.latlayer1_relu = nn.ReLU(inplace=True) - - self.latlayer2 = nn.Conv2d(512, 256, kernel_size=1, stride=1, padding=0) - self.latlayer2_bn = nn.BatchNorm2d(256) - self.latlayer2_relu = nn.ReLU(inplace=True) - - self.latlayer3 = nn.Conv2d(256, 256, kernel_size=1, stride=1, padding=0) - self.latlayer3_bn = nn.BatchNorm2d(256) - self.latlayer3_relu = nn.ReLU(inplace=True) - - self.conv2 = nn.Conv2d(1024, 256, kernel_size=3, stride=1, padding=1) - self.bn2 = nn.BatchNorm2d(256) - self.relu2 = nn.ReLU(inplace=True) - self.conv3 = nn.Conv2d(256, num_classes, kernel_size=1, stride=1, padding=0) - self.upsample = nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True) - - self.scale = scale - - for m in self.modules(): - if isinstance(m, nn.Conv2d): - n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels - m.weight.data.normal_(0, math.sqrt(2. / n)) - elif isinstance(m, nn.BatchNorm2d): - m.weight.data.fill_(1) - m.bias.data.zero_() - - def _make_layer(self, block, planes, blocks, stride=1): - downsample = None - if stride != 1 or self.inplanes != planes * block.expansion: - downsample = nn.Sequential( - nn.Conv2d(self.inplanes, planes * block.expansion, - kernel_size=1, stride=stride, bias=False), - nn.BatchNorm2d(planes * block.expansion), - ) - - layers = [] - layers.append(block(self.inplanes, planes, stride, downsample)) - self.inplanes = planes * block.expansion - for i in range(1, blocks): - layers.append(block(self.inplanes, planes)) - - return nn.Sequential(*layers) - - def _upsample(self, x, y, scale=1): - _, _, H, W = y.size() - # return self.upsample(x) - return F.interpolate(x, size=(H // scale, W // scale), mode='bilinear', align_corners=False) - - def _upsample_add(self, x, y): - _, _, H, W = y.size() - # print(x.shape) - # print(y.shape) - # print('x:',x.type()) - # print('out:',F.interpolate(x, size=(H,W), mode='bilinear').type()) - # print('y:', y.type()) - # return self.upsample(x) + y - return F.interpolate(x, size=(H, W), mode='bilinear', align_corners=False).half() + y - - def forward(self, x): - h = x - h = self.conv1(h) - h = self.bn1(h) - h = self.relu1(h) - - h = self.maxpool(h) - - h = self.layer1(h) - c2 = h - h = self.layer2(h) - c3 = h - h = self.layer3(h) - c4 = h - h = self.layer4(h) - c5 = h - - # Top-down - p5 = self.toplayer(c5) - p5 = self.toplayer_relu(self.toplayer_bn(p5)) - - c4 = self.latlayer1(c4) - c4 = self.latlayer1_relu(self.latlayer1_bn(c4)) - t = time.time() - # print('c4:',c4.type()) - p4 = self._upsample_add(p5, c4) - p4 = self.smooth1(p4) - p4 = self.smooth1_relu(self.smooth1_bn(p4)) - - c3 = self.latlayer2(c3) - c3 = self.latlayer2_relu(self.latlayer2_bn(c3)) - t = time.time() - # print('t:',t) - p3 = self._upsample_add(p4, c3) - # print('t2:',time.time()-t) - p3 = self.smooth2(p3) - p3 = self.smooth2_relu(self.smooth2_bn(p3)) - - c2 = self.latlayer3(c2) - c2 = self.latlayer3_relu(self.latlayer3_bn(c2)) - p2 = self._upsample_add(p3, c2) - p2 = self.smooth3(p2) - p2 = self.smooth3_relu(self.smooth3_bn(p2)) - - p3 = self._upsample(p3, p2) - p4 = self._upsample(p4, p2) - p5 = self._upsample(p5, p2) - - # p2, p3, p4, p5 = p2.cpu(), p3.cpu(), p4.cpu(), p5.cpu() - out = torch.cat((p2, p3, p4, p5), 1) - # out = out.to(dev) - - - # self.conv2 = self.conv2.cpu() - out = self.conv2(out) - # self.conv2 = self.conv2.to(dev) - - # self.relu2 = self.relu2.cpu() - # self.bn2 = self.bn2.cpu() - out = self.relu2(self.bn2(out)) - # self.relu2 = self.relu2.to(dev) - # self.bn2 = self.bn2.to(dev) - - # self.conv3 = self.conv3.cpu() - out = self.conv3(out) - # self.conv3 = self.conv3.to(dev) - - # out = out.to(dev) - # p2, p3, p4, p5 = p2.to(dev), p3.to(dev), p4.to(dev), p5.to(dev) - out = self._upsample(out, x, scale=self.scale) - - return out - - -def resnet18(pretrained=False, **kwargs): - """Constructs a ResNet-18 model. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(BasicBlock, [2, 2, 2, 2], **kwargs) - if pretrained: - model.load_state_dict(model_zoo.load_url(model_urls['resnet18'])) - return model - - -def resnet34(pretrained=False, **kwargs): - """Constructs a ResNet-34 model. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(BasicBlock, [3, 4, 6, 3], **kwargs) - if pretrained: - model.load_state_dict(model_zoo.load_url(model_urls['resnet34'])) - return model - - -def resnet50(pretrained=False, **kwargs): - """Constructs a ResNet-50 model. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(Bottleneck, [3, 4, 6, 3], **kwargs) - if pretrained: - pretrained_model = model_zoo.load_url(model_urls['resnet50']) - state = model.state_dict() - for key in state.keys(): - if key in pretrained_model.keys(): - state[key] = pretrained_model[key] - model.load_state_dict(state) - return model - - -def resnet101(pretrained=False, **kwargs): - """Constructs a ResNet-101 model. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(Bottleneck, [3, 4, 23, 3], **kwargs) - if pretrained: - pretrained_model = model_zoo.load_url(model_urls['resnet101']) - state = model.state_dict() - for key in state.keys(): - if key in pretrained_model.keys(): - state[key] = pretrained_model[key] - model.load_state_dict(state) - return model - -def resnet152(pretrained=False, **kwargs): - """Constructs a ResNet-152 model. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(Bottleneck, [3, 8, 36, 3], **kwargs) - if pretrained: - pretrained_model = model_zoo.load_url(model_urls['resnet152']) - state = model.state_dict() - for key in state.keys(): - if key in pretrained_model.keys(): - state[key] = pretrained_model[key] - model.load_state_dict(state) - return model +import torch.nn as nn +import time +import math +import torch.utils.model_zoo as model_zoo +import torch.nn.functional as F +import torch +import pdb + + +__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101', + 'resnet152'] + + +model_urls = { + 'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth', + 'resnet34': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth', + 'resnet50': 'https://download.pytorch.org/models/resnet50-19c8e357.pth', + 'resnet101': 'https://download.pytorch.org/models/resnet101-5d3mb4d8f.pth', + 'resnet152': 'https://download.pytorch.org/models/resnet152-b121ed2d.pth', +} + + +def conv3x3(in_planes, out_planes, stride=1): + """3x3 convolution with padding""" + return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, + padding=1, bias=False) + + +class BasicBlock(nn.Module): + expansion = 1 + + def __init__(self, inplanes, planes, stride=1, downsample=None): + super(BasicBlock, self).__init__() + self.conv1 = conv3x3(inplanes, planes, stride) + self.bn1 = nn.BatchNorm2d(planes) + self.relu = nn.ReLU(inplace=True) + self.conv2 = conv3x3(planes, planes) + self.bn2 = nn.BatchNorm2d(planes) + self.downsample = downsample + self.stride = stride + + def forward(self, x): + residual = x + + out = self.conv1(x) + out = self.bn1(out) + out = self.relu(out) + + out = self.conv2(out) + out = self.bn2(out) + + if self.downsample is not None: + residual = self.downsample(x) + + out += residual + out = self.relu(out) + + return out + + +class Bottleneck(nn.Module): + expansion = 4 + + def __init__(self, inplanes, planes, stride=1, downsample=None): + super(Bottleneck, self).__init__() + self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False) + self.bn1 = nn.BatchNorm2d(planes) + self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, + padding=1, bias=False) + self.bn2 = nn.BatchNorm2d(planes) + self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False) + self.bn3 = nn.BatchNorm2d(planes * 4) + self.relu = nn.ReLU(inplace=True) + self.downsample = downsample + self.stride = stride + + def forward(self, x): + residual = x + + out = self.conv1(x) + out = self.bn1(out) + out = self.relu(out) + + out = self.conv2(out) + out = self.bn2(out) + out = self.relu(out) + + out = self.conv3(out) + out = self.bn3(out) + + if self.downsample is not None: + residual = self.downsample(x) + + out += residual + out = self.relu(out) + + return out + + +class ResNet(nn.Module): + + def __init__(self, block, layers, num_classes=7, scale=1): + self.inplanes = 64 + super(ResNet, self).__init__() + self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, + bias=False) + self.bn1 = nn.BatchNorm2d(64) + self.relu1 = nn.ReLU(inplace=True) + self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1, return_indices = False) + self.layer1 = self._make_layer(block, 64, layers[0]) + self.layer2 = self._make_layer(block, 128, layers[1], stride=2) + self.layer3 = self._make_layer(block, 256, layers[2], stride=2) + self.layer4 = self._make_layer(block, 512, layers[3], stride=2) + # self.avgpool = nn.AvgPool2d(7, stride=1) + # self.fc = nn.Linear(512 * block.expansion, num_classes) + + # Top layer + self.toplayer = nn.Conv2d(2048, 256, kernel_size=1, stride=1, padding=0) # Reduce channels + self.toplayer_bn = nn.BatchNorm2d(256) + self.toplayer_relu = nn.ReLU(inplace=True) + + # Smooth layers + self.smooth1 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) + self.smooth1_bn = nn.BatchNorm2d(256) + self.smooth1_relu = nn.ReLU(inplace=True) + + self.smooth2 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) + self.smooth2_bn = nn.BatchNorm2d(256) + self.smooth2_relu = nn.ReLU(inplace=True) + + self.smooth3 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) + self.smooth3_bn = nn.BatchNorm2d(256) + self.smooth3_relu = nn.ReLU(inplace=True) + + # Lateral layers + self.latlayer1 = nn.Conv2d(1024, 256, kernel_size=1, stride=1, padding=0) + self.latlayer1_bn = nn.BatchNorm2d(256) + self.latlayer1_relu = nn.ReLU(inplace=True) + + self.latlayer2 = nn.Conv2d(512, 256, kernel_size=1, stride=1, padding=0) + self.latlayer2_bn = nn.BatchNorm2d(256) + self.latlayer2_relu = nn.ReLU(inplace=True) + + self.latlayer3 = nn.Conv2d(256, 256, kernel_size=1, stride=1, padding=0) + self.latlayer3_bn = nn.BatchNorm2d(256) + self.latlayer3_relu = nn.ReLU(inplace=True) + + self.conv2 = nn.Conv2d(1024, 256, kernel_size=3, stride=1, padding=1) + self.bn2 = nn.BatchNorm2d(256) + self.relu2 = nn.ReLU(inplace=True) + self.conv3 = nn.Conv2d(256, num_classes, kernel_size=1, stride=1, padding=0) + self.upsample = nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True) + + self.scale = scale + + for m in self.modules(): + if isinstance(m, nn.Conv2d): + n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels + m.weight.data.normal_(0, math.sqrt(2. / n)) + elif isinstance(m, nn.BatchNorm2d): + m.weight.data.fill_(1) + m.bias.data.zero_() + + def _make_layer(self, block, planes, blocks, stride=1): + downsample = None + if stride != 1 or self.inplanes != planes * block.expansion: + downsample = nn.Sequential( + nn.Conv2d(self.inplanes, planes * block.expansion, + kernel_size=1, stride=stride, bias=False), + nn.BatchNorm2d(planes * block.expansion), + ) + + layers = [] + layers.append(block(self.inplanes, planes, stride, downsample)) + self.inplanes = planes * block.expansion + for i in range(1, blocks): + layers.append(block(self.inplanes, planes)) + + return nn.Sequential(*layers) + + def _upsample(self, x, y, scale=1): + _, _, H, W = y.size() + # return self.upsample(x) + return F.interpolate(x, size=(H // scale, W // scale), mode='bilinear', align_corners=False) + + def _upsample_add(self, x, y): + _, _, H, W = y.size() + # print(x.shape) + # print(y.shape) + # print('x:',x.type()) + # print('out:',F.interpolate(x, size=(H,W), mode='bilinear').type()) + # print('y:', y.type()) + # return self.upsample(x) + y + return F.interpolate(x, size=(H, W), mode='bilinear', align_corners=False).half() + y + + def forward(self, x): + h = x + h = self.conv1(h) + h = self.bn1(h) + h = self.relu1(h) + + h = self.maxpool(h) + + h = self.layer1(h) + c2 = h + h = self.layer2(h) + c3 = h + h = self.layer3(h) + c4 = h + h = self.layer4(h) + c5 = h + + # Top-down + p5 = self.toplayer(c5) + p5 = self.toplayer_relu(self.toplayer_bn(p5)) + + c4 = self.latlayer1(c4) + c4 = self.latlayer1_relu(self.latlayer1_bn(c4)) + t = time.time() + # print('c4:',c4.type()) + p4 = self._upsample_add(p5, c4) + p4 = self.smooth1(p4) + p4 = self.smooth1_relu(self.smooth1_bn(p4)) + + c3 = self.latlayer2(c3) + c3 = self.latlayer2_relu(self.latlayer2_bn(c3)) + t = time.time() + # print('t:',t) + p3 = self._upsample_add(p4, c3) + # print('t2:',time.time()-t) + p3 = self.smooth2(p3) + p3 = self.smooth2_relu(self.smooth2_bn(p3)) + + c2 = self.latlayer3(c2) + c2 = self.latlayer3_relu(self.latlayer3_bn(c2)) + p2 = self._upsample_add(p3, c2) + p2 = self.smooth3(p2) + p2 = self.smooth3_relu(self.smooth3_bn(p2)) + + p3 = self._upsample(p3, p2) + p4 = self._upsample(p4, p2) + p5 = self._upsample(p5, p2) + + # p2, p3, p4, p5 = p2.cpu(), p3.cpu(), p4.cpu(), p5.cpu() + out = torch.cat((p2, p3, p4, p5), 1) + # out = out.to(dev) + + + # self.conv2 = self.conv2.cpu() + out = self.conv2(out) + # self.conv2 = self.conv2.to(dev) + + # self.relu2 = self.relu2.cpu() + # self.bn2 = self.bn2.cpu() + out = self.relu2(self.bn2(out)) + # self.relu2 = self.relu2.to(dev) + # self.bn2 = self.bn2.to(dev) + + # self.conv3 = self.conv3.cpu() + out = self.conv3(out) + # self.conv3 = self.conv3.to(dev) + + # out = out.to(dev) + # p2, p3, p4, p5 = p2.to(dev), p3.to(dev), p4.to(dev), p5.to(dev) + out = self._upsample(out, x, scale=self.scale) + + return out + + +def resnet18(pretrained=False, **kwargs): + """Constructs a ResNet-18 model. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(BasicBlock, [2, 2, 2, 2], **kwargs) + if pretrained: + model.load_state_dict(model_zoo.load_url(model_urls['resnet18'])) + return model + + +def resnet34(pretrained=False, **kwargs): + """Constructs a ResNet-34 model. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(BasicBlock, [3, 4, 6, 3], **kwargs) + if pretrained: + model.load_state_dict(model_zoo.load_url(model_urls['resnet34'])) + return model + + +def resnet50(pretrained=False, **kwargs): + """Constructs a ResNet-50 model. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(Bottleneck, [3, 4, 6, 3], **kwargs) + if pretrained: + pretrained_model = model_zoo.load_url(model_urls['resnet50']) + state = model.state_dict() + for key in state.keys(): + if key in pretrained_model.keys(): + state[key] = pretrained_model[key] + model.load_state_dict(state) + return model + + +def resnet101(pretrained=False, **kwargs): + """Constructs a ResNet-101 model. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(Bottleneck, [3, 4, 23, 3], **kwargs) + if pretrained: + pretrained_model = model_zoo.load_url(model_urls['resnet101']) + state = model.state_dict() + for key in state.keys(): + if key in pretrained_model.keys(): + state[key] = pretrained_model[key] + model.load_state_dict(state) + return model + +def resnet152(pretrained=False, **kwargs): + """Constructs a ResNet-152 model. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(Bottleneck, [3, 8, 36, 3], **kwargs) + if pretrained: + pretrained_model = model_zoo.load_url(model_urls['resnet152']) + state = model.state_dict() + for key in state.keys(): + if key in pretrained_model.keys(): + state[key] = pretrained_model[key] + model.load_state_dict(state) + return model diff --git a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/fpn_resnet_nearest.py b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/fpn_resnet_nearest.py index 87999dd4dccc33eac151b20bd714c67c179790ab..b3400aa3c5ca8e284319e870498f6b65e387d818 100644 --- a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/fpn_resnet_nearest.py +++ b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/fpn_resnet_nearest.py @@ -1,555 +1,555 @@ -# Apache License -# Version 2.0, January 2004 -# http://www.apache.org/licenses/ -# -# TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION -# -# 1. Definitions. -# -# "License" shall mean the terms and conditions for use, reproduction, -# and distribution as defined by Sections 1 through 9 of this document. -# -# "Licensor" shall mean the copyright owner or entity authorized by -# the copyright owner that is granting the License. -# -# "Legal Entity" shall mean the union of the acting entity and all -# other entities that control, are controlled by, or are under common -# control with that entity. For the purposes of this definition, -# "control" means (i) the power, direct or indirect, to cause the -# direction or management of such entity, whether by contract or -# otherwise, or (ii) ownership of fifty percent (50%) or more of the -# outstanding shares, or (iii) beneficial ownership of such entity. -# -# "You" (or "Your") shall mean an individual or Legal Entity -# exercising permissions granted by this License. -# -# "Source" form shall mean the preferred form for making modifications, -# including but not limited to software source code, documentation -# source, and configuration files. -# -# "Object" form shall mean any form resulting from mechanical -# transformation or translation of a Source form, including but -# not limited to compiled object code, generated documentation, -# and conversions to other media types. -# -# "Work" shall mean the work of authorship, whether in Source or -# Object form, made available under the License, as indicated by a -# copyright notice that is included in or attached to the work -# (an example is provided in the Appendix below). -# -# "Derivative Works" shall mean any work, whether in Source or Object -# form, that is based on (or derived from) the Work and for which the -# editorial revisions, annotations, elaborations, or other modifications -# represent, as a whole, an original work of authorship. For the purposes -# of this License, Derivative Works shall not include works that remain -# separable from, or merely link (or bind by name) to the interfaces of, -# the Work and Derivative Works thereof. -# -# "Contribution" shall mean any work of authorship, including -# the original version of the Work and any modifications or additions -# to that Work or Derivative Works thereof, that is intentionally -# submitted to Licensor for inclusion in the Work by the copyright owner -# or by an individual or Legal Entity authorized to submit on behalf of -# the copyright owner. For the purposes of this definition, "submitted" -# means any form of electronic, verbal, or written communication sent -# to the Licensor or its representatives, including but not limited to -# communication on electronic mailing lists, source code control systems, -# and issue tracking systems that are managed by, or on behalf of, the -# Licensor for the purpose of discussing and improving the Work, but -# excluding communication that is conspicuously marked or otherwise -# designated in writing by the copyright owner as "Not a Contribution." -# -# "Contributor" shall mean Licensor and any individual or Legal Entity -# on behalf of whom a Contribution has been received by Licensor and -# subsequently incorporated within the Work. -# -# 2. Grant of Copyright License. Subject to the terms and conditions of -# this License, each Contributor hereby grants to You a perpetual, -# worldwide, non-exclusive, no-charge, royalty-free, irrevocable -# copyright license to reproduce, prepare Derivative Works of, -# publicly display, publicly perform, sublicense, and distribute the -# Work and such Derivative Works in Source or Object form. -# -# 3. Grant of Patent License. Subject to the terms and conditions of -# this License, each Contributor hereby grants to You a perpetual, -# worldwide, non-exclusive, no-charge, royalty-free, irrevocable -# (except as stated in this section) patent license to make, have made, -# use, offer to sell, sell, import, and otherwise transfer the Work, -# where such license applies only to those patent claims licensable -# by such Contributor that are necessarily infringed by their -# Contribution(s) alone or by combination of their Contribution(s) -# with the Work to which such Contribution(s) was submitted. If You -# institute patent litigation against any entity (including a -# cross-claim or counterclaim in a lawsuit) alleging that the Work -# or a Contribution incorporated within the Work constitutes direct -# or contributory patent infringement, then any patent licenses -# granted to You under this License for that Work shall terminate -# as of the date such litigation is filed. -# -# 4. Redistribution. You may reproduce and distribute copies of the -# Work or Derivative Works thereof in any medium, with or without -# modifications, and in Source or Object form, provided that You -# meet the following conditions: -# -# (a) You must give any other recipients of the Work or -# Derivative Works a copy of this License; and -# -# (b) You must cause any modified files to carry prominent notices -# stating that You changed the files; and -# -# (c) You must retain, in the Source form of any Derivative Works -# that You distribute, all copyright, patent, trademark, and -# attribution notices from the Source form of the Work, -# excluding those notices that do not pertain to any part of -# the Derivative Works; and -# -# (d) If the Work includes a "NOTICE" text file as part of its -# distribution, then any Derivative Works that You distribute must -# include a readable copy of the attribution notices contained -# within such NOTICE file, excluding those notices that do not -# pertain to any part of the Derivative Works, in at least one -# of the following places: within a NOTICE text file distributed -# as part of the Derivative Works; within the Source form or -# documentation, if provided along with the Derivative Works; or, -# within a display generated by the Derivative Works, if and -# wherever such third-party notices normally appear. The contents -# of the NOTICE file are for informational purposes only and -# do not modify the License. You may add Your own attribution -# notices within Derivative Works that You distribute, alongside -# or as an addendum to the NOTICE text from the Work, provided -# that such additional attribution notices cannot be construed -# as modifying the License. -# -# You may add Your own copyright statement to Your modifications and -# may provide additional or different license terms and conditions -# for use, reproduction, or distribution of Your modifications, or -# for any such Derivative Works as a whole, provided Your use, -# reproduction, and distribution of the Work otherwise complies with -# the conditions stated in this License. -# -# 5. Submission of Contributions. Unless You explicitly state otherwise, -# any Contribution intentionally submitted for inclusion in the Work -# by You to the Licensor shall be under the terms and conditions of -# this License, without any additional terms or conditions. -# Notwithstanding the above, nothing herein shall supersede or modify -# the terms of any separate license agreement you may have executed -# with Licensor regarding such Contributions. -# -# 6. Trademarks. This License does not grant permission to use the trade -# names, trademarks, service marks, or product names of the Licensor, -# except as required for reasonable and customary use in describing the -# origin of the Work and reproducing the content of the NOTICE file. -# -# 7. Disclaimer of Warranty. Unless required by applicable law or -# agreed to in writing, Licensor provides the Work (and each -# Contributor provides its Contributions) on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied, including, without limitation, any warranties or conditions -# of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A -# PARTICULAR PURPOSE. You are solely responsible for determining the -# appropriateness of using or redistributing the Work and assume any -# risks associated with Your exercise of permissions under this License. -# -# 8. Limitation of Liability. In no event and under no legal theory, -# whether in tort (including negligence), contract, or otherwise, -# unless required by applicable law (such as deliberate and grossly -# negligent acts) or agreed to in writing, shall any Contributor be -# liable to You for damages, including any direct, indirect, special, -# incidental, or consequential damages of any character arising as a -# result of this License or out of the use or inability to use the -# Work (including but not limited to damages for loss of goodwill, -# work stoppage, computer failure or malfunction, or any and all -# other commercial damages or losses), even if such Contributor -# has been advised of the possibility of such damages. -# -# 9. Accepting Warranty or Additional Liability. While redistributing -# the Work or Derivative Works thereof, You may choose to offer, -# and charge a fee for, acceptance of support, warranty, indemnity, -# or other liability obligations and/or rights consistent with this -# License. However, in accepting such obligations, You may act only -# on Your own behalf and on Your sole responsibility, not on behalf -# of any other Contributor, and only if You agree to indemnify, -# defend, and hold each Contributor harmless for any liability -# incurred by, or claims asserted against, such Contributor by reason -# of your accepting any such warranty or additional liability. -# -# END OF TERMS AND CONDITIONS -# -# APPENDIX: How to apply the Apache License to your work. -# -# To apply the Apache License to your work, attach the following -# boilerplate notice, with the fields enclosed by brackets "[]" -# replaced with your own identifying information. (Don't include -# the brackets!) The text should be enclosed in the appropriate -# comment syntax for the file format. We also recommend that a -# file or class name and description of purpose be included on the -# same "printed page" as the copyright notice for easier -# identification within third-party archives. -# -# Copyright [yyyy] [name of copyright owner] -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import math -import time - -import torch -import torch.nn as nn -import torch.nn.functional as F -import torch.utils.model_zoo as model_zoo - -__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101', - 'resnet152'] - -model_urls = { - 'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth', - 'resnet34': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth', - 'resnet50': 'https://download.pytorch.org/models/resnet50-19c8e357.pth', - 'resnet101': 'https://download.pytorch.org/models/resnet101-5d3mb4d8f.pth', - 'resnet152': 'https://download.pytorch.org/models/resnet152-b121ed2d.pth', -} - - -def conv3x3(in_planes, out_planes, stride=1): - """3x3 convolution with padding""" - return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, - padding=1, bias=False) - - -class BasicBlock(nn.Module): - expansion = 1 - - def __init__(self, inplanes, planes, stride=1, downsample=None): - super(BasicBlock, self).__init__() - self.conv1 = conv3x3(inplanes, planes, stride) - self.bn1 = nn.BatchNorm2d(planes) - self.relu = nn.ReLU(inplace=True) - self.conv2 = conv3x3(planes, planes) - self.bn2 = nn.BatchNorm2d(planes) - self.downsample = downsample - self.stride = stride - - def forward(self, x): - residual = x - - out = self.conv1(x) - out = self.bn1(out) - out = self.relu(out) - - out = self.conv2(out) - out = self.bn2(out) - - if self.downsample is not None: - residual = self.downsample(x) - - out += residual - out = self.relu(out) - - return out - - -class Bottleneck(nn.Module): - expansion = 4 - - def __init__(self, inplanes, planes, stride=1, downsample=None): - super(Bottleneck, self).__init__() - self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False) - self.bn1 = nn.BatchNorm2d(planes) - self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, - padding=1, bias=False) - self.bn2 = nn.BatchNorm2d(planes) - self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False) - self.bn3 = nn.BatchNorm2d(planes * 4) - self.relu = nn.ReLU(inplace=True) - self.downsample = downsample - self.stride = stride - - def forward(self, x): - residual = x - - out = self.conv1(x) - out = self.bn1(out) - out = self.relu(out) - - out = self.conv2(out) - out = self.bn2(out) - out = self.relu(out) - - out = self.conv3(out) - out = self.bn3(out) - - if self.downsample is not None: - residual = self.downsample(x) - - out += residual - out = self.relu(out) - - return out - - -class ResNet(nn.Module): - - def __init__(self, block, layers, num_classes=7, scale=1): - self.inplanes = 64 - super(ResNet, self).__init__() - self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, - bias=False) - self.bn1 = nn.BatchNorm2d(64) - self.relu1 = nn.ReLU(inplace=True) - self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1, return_indices=False) - self.layer1 = self._make_layer(block, 64, layers[0]) - self.layer2 = self._make_layer(block, 128, layers[1], stride=2) - self.layer3 = self._make_layer(block, 256, layers[2], stride=2) - self.layer4 = self._make_layer(block, 512, layers[3], stride=2) - # self.avgpool = nn.AvgPool2d(7, stride=1) - # self.fc = nn.Linear(512 * block.expansion, num_classes) - - # Top layer - self.toplayer = nn.Conv2d(2048, 256, kernel_size=1, stride=1, padding=0) # Reduce channels - self.toplayer_bn = nn.BatchNorm2d(256) - self.toplayer_relu = nn.ReLU(inplace=True) - - # Smooth layers - self.smooth1 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) - self.smooth1_bn = nn.BatchNorm2d(256) - self.smooth1_relu = nn.ReLU(inplace=True) - - self.smooth2 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) - self.smooth2_bn = nn.BatchNorm2d(256) - self.smooth2_relu = nn.ReLU(inplace=True) - - self.smooth3 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) - self.smooth3_bn = nn.BatchNorm2d(256) - self.smooth3_relu = nn.ReLU(inplace=True) - - # Lateral layers - self.latlayer1 = nn.Conv2d(1024, 256, kernel_size=1, stride=1, padding=0) - self.latlayer1_bn = nn.BatchNorm2d(256) - self.latlayer1_relu = nn.ReLU(inplace=True) - - self.latlayer2 = nn.Conv2d(512, 256, kernel_size=1, stride=1, padding=0) - self.latlayer2_bn = nn.BatchNorm2d(256) - self.latlayer2_relu = nn.ReLU(inplace=True) - - self.latlayer3 = nn.Conv2d(256, 256, kernel_size=1, stride=1, padding=0) - self.latlayer3_bn = nn.BatchNorm2d(256) - self.latlayer3_relu = nn.ReLU(inplace=True) - - self.conv2 = nn.Conv2d(1024, 256, kernel_size=3, stride=1, padding=1) - self.bn2 = nn.BatchNorm2d(256) - self.relu2 = nn.ReLU(inplace=True) - self.conv3 = nn.Conv2d(256, num_classes, kernel_size=1, stride=1, padding=0) - self.upsample = nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True) - - self.scale = scale - - for m in self.modules(): - if isinstance(m, nn.Conv2d): - n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels - m.weight.data.normal_(0, math.sqrt(2. / n)) - elif isinstance(m, nn.BatchNorm2d): - m.weight.data.fill_(1) - m.bias.data.zero_() - - def _make_layer(self, block, planes, blocks, stride=1): - downsample = None - if stride != 1 or self.inplanes != planes * block.expansion: - downsample = nn.Sequential( - nn.Conv2d(self.inplanes, planes * block.expansion, - kernel_size=1, stride=stride, bias=False), - nn.BatchNorm2d(planes * block.expansion), - ) - - layers = [] - layers.append(block(self.inplanes, planes, stride, downsample)) - self.inplanes = planes * block.expansion - for i in range(1, blocks): - layers.append(block(self.inplanes, planes)) - - return nn.Sequential(*layers) - - def _upsample(self, x, y, scale=1): - _, _, H, W = y.size() - # return self.upsample(x) - return F.interpolate(x, size=(H // scale, W // scale), mode='nearest') - - def _upsample_add(self, x, y): - _, _, H, W = y.size() - # return F.interpolate(x, size=(H, W), mode='bilinear', align_corners=False).half() + y - return F.interpolate(x, size=(H, W), mode='nearest') + y - - def forward(self, x): - h = x - h = self.conv1(h) - h = self.bn1(h) - h = self.relu1(h) - - #h = h.float() - h = self.maxpool(h) - #h = h.half() - # self.maxpool = self.maxpool.cpu() - # h = self.maxpool(h.cpu()) - # h = h.npu() - # self.maxpool = self.maxpool.npu() - - h = self.layer1(h) - c2 = h - h = self.layer2(h) - c3 = h - h = self.layer3(h) - c4 = h - h = self.layer4(h) - c5 = h - - # Top-down - p5 = self.toplayer(c5) - p5 = self.toplayer_relu(self.toplayer_bn(p5)) - - c4 = self.latlayer1(c4) - c4 = self.latlayer1_relu(self.latlayer1_bn(c4)) - t = time.time() - # print('c4:',c4.type()) - p4 = self._upsample_add(p5, c4) - p4 = self.smooth1(p4) - p4 = self.smooth1_relu(self.smooth1_bn(p4)) - - c3 = self.latlayer2(c3) - c3 = self.latlayer2_relu(self.latlayer2_bn(c3)) - t = time.time() - # print('t:',t) - p3 = self._upsample_add(p4, c3) - # print('t2:',time.time()-t) - p3 = self.smooth2(p3) - p3 = self.smooth2_relu(self.smooth2_bn(p3)) - - c2 = self.latlayer3(c2) - c2 = self.latlayer3_relu(self.latlayer3_bn(c2)) - p2 = self._upsample_add(p3, c2) - p2 = self.smooth3(p2) - p2 = self.smooth3_relu(self.smooth3_bn(p2)) - - p3 = self._upsample(p3, p2) - p4 = self._upsample(p4, p2) - p5 = self._upsample(p5, p2) - - # p2, p3, p4, p5 = p2.cpu(), p3.cpu(), p4.cpu(), p5.cpu() - out = torch.cat((p2, p3, p4, p5), 1) - # out = out.to(dev) - - # self.conv2 = self.conv2.cpu() - out = self.conv2(out) - # self.conv2 = self.conv2.to(dev) - - # self.relu2 = self.relu2.cpu() - # self.bn2 = self.bn2.cpu() - out = self.relu2(self.bn2(out)) - # self.relu2 = self.relu2.to(dev) - # self.bn2 = self.bn2.to(dev) - - # self.conv3 = self.conv3.cpu() - out = self.conv3(out) - # self.conv3 = self.conv3.to(dev) - - # out = out.to(dev) - # p2, p3, p4, p5 = p2.to(dev), p3.to(dev), p4.to(dev), p5.to(dev) - out = self._upsample(out, x, scale=self.scale) - - return out - - -def resnet18(pretrained=False, **kwargs): - """Constructs a ResNet-18 model. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(BasicBlock, [2, 2, 2, 2], **kwargs) - if pretrained: - model.load_state_dict(model_zoo.load_url(model_urls['resnet18'])) - return model - - -def resnet34(pretrained=False, **kwargs): - """Constructs a ResNet-34 model. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(BasicBlock, [3, 4, 6, 3], **kwargs) - if pretrained: - model.load_state_dict(model_zoo.load_url(model_urls['resnet34'])) - return model - - -def resnet50(pretrained=False, **kwargs): - """Constructs a ResNet-50 model. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(Bottleneck, [3, 4, 6, 3], **kwargs) - if pretrained: - pretrained_model = model_zoo.load_url(model_urls['resnet50']) - state = model.state_dict() - for key in state.keys(): - if key in pretrained_model.keys(): - state[key] = pretrained_model[key] - model.load_state_dict(state) - return model - - -def resnet101(pretrained=False, **kwargs): - """Constructs a ResNet-101 model. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(Bottleneck, [3, 4, 23, 3], **kwargs) - if pretrained: - pretrained_model = model_zoo.load_url(model_urls['resnet101']) - state = model.state_dict() - for key in state.keys(): - if key in pretrained_model.keys(): - state[key] = pretrained_model[key] - model.load_state_dict(state) - return model - - -def resnet152(pretrained=False, **kwargs): - """Constructs a ResNet-152 model. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(Bottleneck, [3, 8, 36, 3], **kwargs) - if pretrained: - pretrained_model = model_zoo.load_url(model_urls['resnet152']) - state = model.state_dict() - for key in state.keys(): - if key in pretrained_model.keys(): - state[key] = pretrained_model[key] - model.load_state_dict(state) - return model +# Apache License +# Version 2.0, January 2004 +# http://www.apache.org/licenses/ +# +# TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION +# +# 1. Definitions. +# +# "License" shall mean the terms and conditions for use, reproduction, +# and distribution as defined by Sections 1 through 9 of this document. +# +# "Licensor" shall mean the copyright owner or entity authorized by +# the copyright owner that is granting the License. +# +# "Legal Entity" shall mean the union of the acting entity and all +# other entities that control, are controlled by, or are under common +# control with that entity. For the purposes of this definition, +# "control" means (i) the power, direct or indirect, to cause the +# direction or management of such entity, whether by contract or +# otherwise, or (ii) ownership of fifty percent (50%) or more of the +# outstanding shares, or (iii) beneficial ownership of such entity. +# +# "You" (or "Your") shall mean an individual or Legal Entity +# exercising permissions granted by this License. +# +# "Source" form shall mean the preferred form for making modifications, +# including but not limited to software source code, documentation +# source, and configuration files. +# +# "Object" form shall mean any form resulting from mechanical +# transformation or translation of a Source form, including but +# not limited to compiled object code, generated documentation, +# and conversions to other media types. +# +# "Work" shall mean the work of authorship, whether in Source or +# Object form, made available under the License, as indicated by a +# copyright notice that is included in or attached to the work +# (an example is provided in the Appendix below). +# +# "Derivative Works" shall mean any work, whether in Source or Object +# form, that is based on (or derived from) the Work and for which the +# editorial revisions, annotations, elaborations, or other modifications +# represent, as a whole, an original work of authorship. For the purposes +# of this License, Derivative Works shall not include works that remain +# separable from, or merely link (or bind by name) to the interfaces of, +# the Work and Derivative Works thereof. +# +# "Contribution" shall mean any work of authorship, including +# the original version of the Work and any modifications or additions +# to that Work or Derivative Works thereof, that is intentionally +# submitted to Licensor for inclusion in the Work by the copyright owner +# or by an individual or Legal Entity authorized to submit on behalf of +# the copyright owner. For the purposes of this definition, "submitted" +# means any form of electronic, verbal, or written communication sent +# to the Licensor or its representatives, including but not limited to +# communication on electronic mailing lists, source code control systems, +# and issue tracking systems that are managed by, or on behalf of, the +# Licensor for the purpose of discussing and improving the Work, but +# excluding communication that is conspicuously marked or otherwise +# designated in writing by the copyright owner as "Not a Contribution." +# +# "Contributor" shall mean Licensor and any individual or Legal Entity +# on behalf of whom a Contribution has been received by Licensor and +# subsequently incorporated within the Work. +# +# 2. Grant of Copyright License. Subject to the terms and conditions of +# this License, each Contributor hereby grants to You a perpetual, +# worldwide, non-exclusive, no-charge, royalty-free, irrevocable +# copyright license to reproduce, prepare Derivative Works of, +# publicly display, publicly perform, sublicense, and distribute the +# Work and such Derivative Works in Source or Object form. +# +# 3. Grant of Patent License. Subject to the terms and conditions of +# this License, each Contributor hereby grants to You a perpetual, +# worldwide, non-exclusive, no-charge, royalty-free, irrevocable +# (except as stated in this section) patent license to make, have made, +# use, offer to sell, sell, import, and otherwise transfer the Work, +# where such license applies only to those patent claims licensable +# by such Contributor that are necessarily infringed by their +# Contribution(s) alone or by combination of their Contribution(s) +# with the Work to which such Contribution(s) was submitted. If You +# institute patent litigation against any entity (including a +# cross-claim or counterclaim in a lawsuit) alleging that the Work +# or a Contribution incorporated within the Work constitutes direct +# or contributory patent infringement, then any patent licenses +# granted to You under this License for that Work shall terminate +# as of the date such litigation is filed. +# +# 4. Redistribution. You may reproduce and distribute copies of the +# Work or Derivative Works thereof in any medium, with or without +# modifications, and in Source or Object form, provided that You +# meet the following conditions: +# +# (a) You must give any other recipients of the Work or +# Derivative Works a copy of this License; and +# +# (b) You must cause any modified files to carry prominent notices +# stating that You changed the files; and +# +# (c) You must retain, in the Source form of any Derivative Works +# that You distribute, all copyright, patent, trademark, and +# attribution notices from the Source form of the Work, +# excluding those notices that do not pertain to any part of +# the Derivative Works; and +# +# (d) If the Work includes a "NOTICE" text file as part of its +# distribution, then any Derivative Works that You distribute must +# include a readable copy of the attribution notices contained +# within such NOTICE file, excluding those notices that do not +# pertain to any part of the Derivative Works, in at least one +# of the following places: within a NOTICE text file distributed +# as part of the Derivative Works; within the Source form or +# documentation, if provided along with the Derivative Works; or, +# within a display generated by the Derivative Works, if and +# wherever such third-party notices normally appear. The contents +# of the NOTICE file are for informational purposes only and +# do not modify the License. You may add Your own attribution +# notices within Derivative Works that You distribute, alongside +# or as an addendum to the NOTICE text from the Work, provided +# that such additional attribution notices cannot be construed +# as modifying the License. +# +# You may add Your own copyright statement to Your modifications and +# may provide additional or different license terms and conditions +# for use, reproduction, or distribution of Your modifications, or +# for any such Derivative Works as a whole, provided Your use, +# reproduction, and distribution of the Work otherwise complies with +# the conditions stated in this License. +# +# 5. Submission of Contributions. Unless You explicitly state otherwise, +# any Contribution intentionally submitted for inclusion in the Work +# by You to the Licensor shall be under the terms and conditions of +# this License, without any additional terms or conditions. +# Notwithstanding the above, nothing herein shall supersede or modify +# the terms of any separate license agreement you may have executed +# with Licensor regarding such Contributions. +# +# 6. Trademarks. This License does not grant permission to use the trade +# names, trademarks, service marks, or product names of the Licensor, +# except as required for reasonable and customary use in describing the +# origin of the Work and reproducing the content of the NOTICE file. +# +# 7. Disclaimer of Warranty. Unless required by applicable law or +# agreed to in writing, Licensor provides the Work (and each +# Contributor provides its Contributions) on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied, including, without limitation, any warranties or conditions +# of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +# PARTICULAR PURPOSE. You are solely responsible for determining the +# appropriateness of using or redistributing the Work and assume any +# risks associated with Your exercise of permissions under this License. +# +# 8. Limitation of Liability. In no event and under no legal theory, +# whether in tort (including negligence), contract, or otherwise, +# unless required by applicable law (such as deliberate and grossly +# negligent acts) or agreed to in writing, shall any Contributor be +# liable to You for damages, including any direct, indirect, special, +# incidental, or consequential damages of any character arising as a +# result of this License or out of the use or inability to use the +# Work (including but not limited to damages for loss of goodwill, +# work stoppage, computer failure or malfunction, or any and all +# other commercial damages or losses), even if such Contributor +# has been advised of the possibility of such damages. +# +# 9. Accepting Warranty or Additional Liability. While redistributing +# the Work or Derivative Works thereof, You may choose to offer, +# and charge a fee for, acceptance of support, warranty, indemnity, +# or other liability obligations and/or rights consistent with this +# License. However, in accepting such obligations, You may act only +# on Your own behalf and on Your sole responsibility, not on behalf +# of any other Contributor, and only if You agree to indemnify, +# defend, and hold each Contributor harmless for any liability +# incurred by, or claims asserted against, such Contributor by reason +# of your accepting any such warranty or additional liability. +# +# END OF TERMS AND CONDITIONS +# +# APPENDIX: How to apply the Apache License to your work. +# +# To apply the Apache License to your work, attach the following +# boilerplate notice, with the fields enclosed by brackets "[]" +# replaced with your own identifying information. (Don't include +# the brackets!) The text should be enclosed in the appropriate +# comment syntax for the file format. We also recommend that a +# file or class name and description of purpose be included on the +# same "printed page" as the copyright notice for easier +# identification within third-party archives. +# +# Copyright [yyyy] [name of copyright owner] +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import math +import time + +import torch +import torch.nn as nn +import torch.nn.functional as F +import torch.utils.model_zoo as model_zoo + +__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101', + 'resnet152'] + +model_urls = { + 'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth', + 'resnet34': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth', + 'resnet50': 'https://download.pytorch.org/models/resnet50-19c8e357.pth', + 'resnet101': 'https://download.pytorch.org/models/resnet101-5d3mb4d8f.pth', + 'resnet152': 'https://download.pytorch.org/models/resnet152-b121ed2d.pth', +} + + +def conv3x3(in_planes, out_planes, stride=1): + """3x3 convolution with padding""" + return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, + padding=1, bias=False) + + +class BasicBlock(nn.Module): + expansion = 1 + + def __init__(self, inplanes, planes, stride=1, downsample=None): + super(BasicBlock, self).__init__() + self.conv1 = conv3x3(inplanes, planes, stride) + self.bn1 = nn.BatchNorm2d(planes) + self.relu = nn.ReLU(inplace=True) + self.conv2 = conv3x3(planes, planes) + self.bn2 = nn.BatchNorm2d(planes) + self.downsample = downsample + self.stride = stride + + def forward(self, x): + residual = x + + out = self.conv1(x) + out = self.bn1(out) + out = self.relu(out) + + out = self.conv2(out) + out = self.bn2(out) + + if self.downsample is not None: + residual = self.downsample(x) + + out += residual + out = self.relu(out) + + return out + + +class Bottleneck(nn.Module): + expansion = 4 + + def __init__(self, inplanes, planes, stride=1, downsample=None): + super(Bottleneck, self).__init__() + self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False) + self.bn1 = nn.BatchNorm2d(planes) + self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, + padding=1, bias=False) + self.bn2 = nn.BatchNorm2d(planes) + self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False) + self.bn3 = nn.BatchNorm2d(planes * 4) + self.relu = nn.ReLU(inplace=True) + self.downsample = downsample + self.stride = stride + + def forward(self, x): + residual = x + + out = self.conv1(x) + out = self.bn1(out) + out = self.relu(out) + + out = self.conv2(out) + out = self.bn2(out) + out = self.relu(out) + + out = self.conv3(out) + out = self.bn3(out) + + if self.downsample is not None: + residual = self.downsample(x) + + out += residual + out = self.relu(out) + + return out + + +class ResNet(nn.Module): + + def __init__(self, block, layers, num_classes=7, scale=1): + self.inplanes = 64 + super(ResNet, self).__init__() + self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, + bias=False) + self.bn1 = nn.BatchNorm2d(64) + self.relu1 = nn.ReLU(inplace=True) + self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1, return_indices=False) + self.layer1 = self._make_layer(block, 64, layers[0]) + self.layer2 = self._make_layer(block, 128, layers[1], stride=2) + self.layer3 = self._make_layer(block, 256, layers[2], stride=2) + self.layer4 = self._make_layer(block, 512, layers[3], stride=2) + # self.avgpool = nn.AvgPool2d(7, stride=1) + # self.fc = nn.Linear(512 * block.expansion, num_classes) + + # Top layer + self.toplayer = nn.Conv2d(2048, 256, kernel_size=1, stride=1, padding=0) # Reduce channels + self.toplayer_bn = nn.BatchNorm2d(256) + self.toplayer_relu = nn.ReLU(inplace=True) + + # Smooth layers + self.smooth1 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) + self.smooth1_bn = nn.BatchNorm2d(256) + self.smooth1_relu = nn.ReLU(inplace=True) + + self.smooth2 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) + self.smooth2_bn = nn.BatchNorm2d(256) + self.smooth2_relu = nn.ReLU(inplace=True) + + self.smooth3 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) + self.smooth3_bn = nn.BatchNorm2d(256) + self.smooth3_relu = nn.ReLU(inplace=True) + + # Lateral layers + self.latlayer1 = nn.Conv2d(1024, 256, kernel_size=1, stride=1, padding=0) + self.latlayer1_bn = nn.BatchNorm2d(256) + self.latlayer1_relu = nn.ReLU(inplace=True) + + self.latlayer2 = nn.Conv2d(512, 256, kernel_size=1, stride=1, padding=0) + self.latlayer2_bn = nn.BatchNorm2d(256) + self.latlayer2_relu = nn.ReLU(inplace=True) + + self.latlayer3 = nn.Conv2d(256, 256, kernel_size=1, stride=1, padding=0) + self.latlayer3_bn = nn.BatchNorm2d(256) + self.latlayer3_relu = nn.ReLU(inplace=True) + + self.conv2 = nn.Conv2d(1024, 256, kernel_size=3, stride=1, padding=1) + self.bn2 = nn.BatchNorm2d(256) + self.relu2 = nn.ReLU(inplace=True) + self.conv3 = nn.Conv2d(256, num_classes, kernel_size=1, stride=1, padding=0) + self.upsample = nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True) + + self.scale = scale + + for m in self.modules(): + if isinstance(m, nn.Conv2d): + n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels + m.weight.data.normal_(0, math.sqrt(2. / n)) + elif isinstance(m, nn.BatchNorm2d): + m.weight.data.fill_(1) + m.bias.data.zero_() + + def _make_layer(self, block, planes, blocks, stride=1): + downsample = None + if stride != 1 or self.inplanes != planes * block.expansion: + downsample = nn.Sequential( + nn.Conv2d(self.inplanes, planes * block.expansion, + kernel_size=1, stride=stride, bias=False), + nn.BatchNorm2d(planes * block.expansion), + ) + + layers = [] + layers.append(block(self.inplanes, planes, stride, downsample)) + self.inplanes = planes * block.expansion + for i in range(1, blocks): + layers.append(block(self.inplanes, planes)) + + return nn.Sequential(*layers) + + def _upsample(self, x, y, scale=1): + _, _, H, W = y.size() + # return self.upsample(x) + return F.interpolate(x, size=(H // scale, W // scale), mode='nearest') + + def _upsample_add(self, x, y): + _, _, H, W = y.size() + # return F.interpolate(x, size=(H, W), mode='bilinear', align_corners=False).half() + y + return F.interpolate(x, size=(H, W), mode='nearest') + y + + def forward(self, x): + h = x + h = self.conv1(h) + h = self.bn1(h) + h = self.relu1(h) + + #h = h.float() + h = self.maxpool(h) + #h = h.half() + # self.maxpool = self.maxpool.cpu() + # h = self.maxpool(h.cpu()) + # h = h.npu() + # self.maxpool = self.maxpool.npu() + + h = self.layer1(h) + c2 = h + h = self.layer2(h) + c3 = h + h = self.layer3(h) + c4 = h + h = self.layer4(h) + c5 = h + + # Top-down + p5 = self.toplayer(c5) + p5 = self.toplayer_relu(self.toplayer_bn(p5)) + + c4 = self.latlayer1(c4) + c4 = self.latlayer1_relu(self.latlayer1_bn(c4)) + t = time.time() + # print('c4:',c4.type()) + p4 = self._upsample_add(p5, c4) + p4 = self.smooth1(p4) + p4 = self.smooth1_relu(self.smooth1_bn(p4)) + + c3 = self.latlayer2(c3) + c3 = self.latlayer2_relu(self.latlayer2_bn(c3)) + t = time.time() + # print('t:',t) + p3 = self._upsample_add(p4, c3) + # print('t2:',time.time()-t) + p3 = self.smooth2(p3) + p3 = self.smooth2_relu(self.smooth2_bn(p3)) + + c2 = self.latlayer3(c2) + c2 = self.latlayer3_relu(self.latlayer3_bn(c2)) + p2 = self._upsample_add(p3, c2) + p2 = self.smooth3(p2) + p2 = self.smooth3_relu(self.smooth3_bn(p2)) + + p3 = self._upsample(p3, p2) + p4 = self._upsample(p4, p2) + p5 = self._upsample(p5, p2) + + # p2, p3, p4, p5 = p2.cpu(), p3.cpu(), p4.cpu(), p5.cpu() + out = torch.cat((p2, p3, p4, p5), 1) + # out = out.to(dev) + + # self.conv2 = self.conv2.cpu() + out = self.conv2(out) + # self.conv2 = self.conv2.to(dev) + + # self.relu2 = self.relu2.cpu() + # self.bn2 = self.bn2.cpu() + out = self.relu2(self.bn2(out)) + # self.relu2 = self.relu2.to(dev) + # self.bn2 = self.bn2.to(dev) + + # self.conv3 = self.conv3.cpu() + out = self.conv3(out) + # self.conv3 = self.conv3.to(dev) + + # out = out.to(dev) + # p2, p3, p4, p5 = p2.to(dev), p3.to(dev), p4.to(dev), p5.to(dev) + out = self._upsample(out, x, scale=self.scale) + + return out + + +def resnet18(pretrained=False, **kwargs): + """Constructs a ResNet-18 model. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(BasicBlock, [2, 2, 2, 2], **kwargs) + if pretrained: + model.load_state_dict(model_zoo.load_url(model_urls['resnet18'])) + return model + + +def resnet34(pretrained=False, **kwargs): + """Constructs a ResNet-34 model. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(BasicBlock, [3, 4, 6, 3], **kwargs) + if pretrained: + model.load_state_dict(model_zoo.load_url(model_urls['resnet34'])) + return model + + +def resnet50(pretrained=False, **kwargs): + """Constructs a ResNet-50 model. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(Bottleneck, [3, 4, 6, 3], **kwargs) + if pretrained: + pretrained_model = model_zoo.load_url(model_urls['resnet50']) + state = model.state_dict() + for key in state.keys(): + if key in pretrained_model.keys(): + state[key] = pretrained_model[key] + model.load_state_dict(state) + return model + + +def resnet101(pretrained=False, **kwargs): + """Constructs a ResNet-101 model. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(Bottleneck, [3, 4, 23, 3], **kwargs) + if pretrained: + pretrained_model = model_zoo.load_url(model_urls['resnet101']) + state = model.state_dict() + for key in state.keys(): + if key in pretrained_model.keys(): + state[key] = pretrained_model[key] + model.load_state_dict(state) + return model + + +def resnet152(pretrained=False, **kwargs): + """Constructs a ResNet-152 model. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(Bottleneck, [3, 8, 36, 3], **kwargs) + if pretrained: + pretrained_model = model_zoo.load_url(model_urls['resnet152']) + state = model.state_dict() + for key in state.keys(): + if key in pretrained_model.keys(): + state[key] = pretrained_model[key] + model.load_state_dict(state) + return model diff --git a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/preprocess_psenet_pytorch.py b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/preprocess_psenet_pytorch.py index 4ae58b56f5a72ddf1320dd3ea2621dd570c52020..dfad45a0096b0d2147277aeac149bcbe4495903a 100644 --- a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/preprocess_psenet_pytorch.py +++ b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/preprocess_psenet_pytorch.py @@ -1,50 +1,50 @@ -import os -import sys -import numpy as np -import cv2 -from PIL import Image - - -def scale(img, long_size=2240): - h, w = img.shape[0:2] - scale = long_size * 1.0 / max(h, w) - img = cv2.resize(img, dsize=None, fx=scale, fy=scale) - # img = cv2.resize(img, (1260, 2240)) - print(img.shape) - return img - - -def psenet_onnx(file_path, bin_path): - if not os.path.exists(bin_path): - os.makedirs(bin_path) - i = 0 - in_files = os.listdir(file_path) - mean = [0.485, 0.456, 0.406] - std = [0.229, 0.224, 0.225] - for file in in_files: - i = i + 1 - print(file, "====", i) - img = cv2.imread(os.path.join(file_path, file)) - img = img[:, :, [2, 1, 0]] # bgr -> rgb - # img = scale(img) - img = cv2.resize(img, (1216, 704)) - - img = np.array(img, dtype=np.float32) - img = img / 255. - - # 均值方差 - img[..., 0] -= mean[0] - img[..., 1] -= mean[1] - img[..., 2] -= mean[2] - img[..., 0] /= std[0] - img[..., 1] /= std[1] - img[..., 2] /= std[2] - - img = img.transpose(2, 0, 1) # HWC -> CHW - img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) - - -if __name__ == "__main__": - file_path = os.path.abspath(sys.argv[1]) - bin_path = os.path.abspath(sys.argv[2]) - psenet_onnx(file_path, bin_path) +import os +import sys +import numpy as np +import cv2 +from PIL import Image + + +def scale(img, long_size=2240): + h, w = img.shape[0:2] + scale = long_size * 1.0 / max(h, w) + img = cv2.resize(img, dsize=None, fx=scale, fy=scale) + # img = cv2.resize(img, (1260, 2240)) + print(img.shape) + return img + + +def psenet_onnx(file_path, bin_path): + if not os.path.exists(bin_path): + os.makedirs(bin_path) + i = 0 + in_files = os.listdir(file_path) + mean = [0.485, 0.456, 0.406] + std = [0.229, 0.224, 0.225] + for file in in_files: + i = i + 1 + print(file, "====", i) + img = cv2.imread(os.path.join(file_path, file)) + img = img[:, :, [2, 1, 0]] # bgr -> rgb + # img = scale(img) + img = cv2.resize(img, (1216, 704)) + + img = np.array(img, dtype=np.float32) + img = img / 255. + + # 均值方差 + img[..., 0] -= mean[0] + img[..., 1] -= mean[1] + img[..., 2] -= mean[2] + img[..., 0] /= std[0] + img[..., 1] /= std[1] + img[..., 2] /= std[2] + + img = img.transpose(2, 0, 1) # HWC -> CHW + img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) + + +if __name__ == "__main__": + file_path = os.path.abspath(sys.argv[1]) + bin_path = os.path.abspath(sys.argv[2]) + psenet_onnx(file_path, bin_path) diff --git a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/pth_bintotxt_bilinear.py b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/pth_bintotxt_bilinear.py index ef040d7f9321578cc033e894f0d574ae2e22f888..b88459ff3352f46ad4abc1d63e03403fb0af7b8d 100644 --- a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/pth_bintotxt_bilinear.py +++ b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/pth_bintotxt_bilinear.py @@ -1,105 +1,105 @@ -import os -import sys -import numpy as np -import torch -import cv2 -from pypse import pse as pypse -import torch.nn.functional as F - - -img_path = sys.argv[1] -bin_path = sys.argv[2] -txt_path = sys.argv[3] - -if not os.path.exists(txt_path): - os.makedirs(txt_path) - -kernel_num=7 -min_kernel_area=5.0 -scale=1 -min_score = 0.9 -min_area = 600 - - -def get_images(): - ''' - find image files in test data path - :return: list of files found - ''' - files = [] - exts = ['jpg', 'png', 'jpeg', 'JPG'] - - for parent, _, filenames in os.walk(img_path): - for filename in filenames: - for ext in exts: - if filename.endswith(ext): - files.append(os.path.join(parent, filename)) - break - return files - - -im_fn_list = get_images() -for im_fn in im_fn_list: - print(im_fn) - im = cv2.imread(im_fn) - idx = os.path.basename(im_fn).split('/')[-1].split('.')[0].split('_')[1] - seg_maps = np.fromfile(bin_path+"/img_{}_1.bin".format(idx), "float32") - seg_maps = np.reshape(seg_maps, (1, 7, 176, 304)) - seg_maps = torch.from_numpy(seg_maps) - - # Resize 算子 - seg_maps = F.interpolate(seg_maps, size=(704, 1216), mode='bilinear', align_corners=False) - # print(seg_maps) - # print(seg_maps.shape) - # - # seg_maps = seg_maps.float() - score = torch.sigmoid(seg_maps[:, 0, :, :]) - outputs = (torch.sign(seg_maps - 1.0) + 1) / 2 - - text = outputs[:, 0, :, :] - kernels = outputs[:, 0:kernel_num, :, :] * text - - score = score.data.numpy()[0].astype(np.float32) - text = text.data.numpy()[0].astype(np.uint8) - kernels = kernels.numpy()[0].astype(np.uint8) - - # python version pse - pred = pypse(kernels, min_kernel_area / (scale * scale)) - - img_scale = (im.shape[1] * 1.0 / pred.shape[1], im.shape[0] * 1.0 / pred.shape[0]) - label = pred - label_num = np.max(label) + 1 - bboxes = [] - - for i in range(1, label_num): - points = np.array(np.where(label == i)).transpose((1, 0))[:, ::-1] - - if points.shape[0] < min_area: - continue - - score_i = np.mean(score[label == i]) - if score_i < min_score: - continue - - rect = cv2.minAreaRect(points) - bbox = cv2.boxPoints(rect) * img_scale - bbox = bbox.astype('int32') - bboxes.append(bbox.reshape(-1)) - # print(bboxes) - # save txt - res_file = os.path.join(txt_path,'{}.txt'.format(os.path.splitext(os.path.basename(im_fn))[0])) - with open(res_file, 'w') as f: - for b_idx, bbox in enumerate(bboxes): - values = [int(v) for v in bbox] - line = "%d, %d, %d, %d, %d, %d, %d, %d\n" % tuple(values) - f.write(line) - - - # show result - # for bbox in bboxes: - # cv2.drawContours(im, [bbox.reshape(4, 2)], -1, (0, 255, 0), 2) - # cv2.namedWindow('result', cv2.WINDOW_NORMAL) - # cv2.imshow('result', im) - # cv2.waitKey() - - +import os +import sys +import numpy as np +import torch +import cv2 +from pypse import pse as pypse +import torch.nn.functional as F + + +img_path = sys.argv[1] +bin_path = sys.argv[2] +txt_path = sys.argv[3] + +if not os.path.exists(txt_path): + os.makedirs(txt_path) + +kernel_num=7 +min_kernel_area=5.0 +scale=1 +min_score = 0.9 +min_area = 600 + + +def get_images(): + ''' + find image files in test data path + :return: list of files found + ''' + files = [] + exts = ['jpg', 'png', 'jpeg', 'JPG'] + + for parent, _, filenames in os.walk(img_path): + for filename in filenames: + for ext in exts: + if filename.endswith(ext): + files.append(os.path.join(parent, filename)) + break + return files + + +im_fn_list = get_images() +for im_fn in im_fn_list: + print(im_fn) + im = cv2.imread(im_fn) + idx = os.path.basename(im_fn).split('/')[-1].split('.')[0].split('_')[1] + seg_maps = np.fromfile(bin_path+"/img_{}_1.bin".format(idx), "float32") + seg_maps = np.reshape(seg_maps, (1, 7, 176, 304)) + seg_maps = torch.from_numpy(seg_maps) + + # Resize 算子 + seg_maps = F.interpolate(seg_maps, size=(704, 1216), mode='bilinear', align_corners=False) + # print(seg_maps) + # print(seg_maps.shape) + # + # seg_maps = seg_maps.float() + score = torch.sigmoid(seg_maps[:, 0, :, :]) + outputs = (torch.sign(seg_maps - 1.0) + 1) / 2 + + text = outputs[:, 0, :, :] + kernels = outputs[:, 0:kernel_num, :, :] * text + + score = score.data.numpy()[0].astype(np.float32) + text = text.data.numpy()[0].astype(np.uint8) + kernels = kernels.numpy()[0].astype(np.uint8) + + # python version pse + pred = pypse(kernels, min_kernel_area / (scale * scale)) + + img_scale = (im.shape[1] * 1.0 / pred.shape[1], im.shape[0] * 1.0 / pred.shape[0]) + label = pred + label_num = np.max(label) + 1 + bboxes = [] + + for i in range(1, label_num): + points = np.array(np.where(label == i)).transpose((1, 0))[:, ::-1] + + if points.shape[0] < min_area: + continue + + score_i = np.mean(score[label == i]) + if score_i < min_score: + continue + + rect = cv2.minAreaRect(points) + bbox = cv2.boxPoints(rect) * img_scale + bbox = bbox.astype('int32') + bboxes.append(bbox.reshape(-1)) + # print(bboxes) + # save txt + res_file = os.path.join(txt_path,'{}.txt'.format(os.path.splitext(os.path.basename(im_fn))[0])) + with open(res_file, 'w') as f: + for b_idx, bbox in enumerate(bboxes): + values = [int(v) for v in bbox] + line = "%d, %d, %d, %d, %d, %d, %d, %d\n" % tuple(values) + f.write(line) + + + # show result + # for bbox in bboxes: + # cv2.drawContours(im, [bbox.reshape(4, 2)], -1, (0, 255, 0), 2) + # cv2.namedWindow('result', cv2.WINDOW_NORMAL) + # cv2.imshow('result', im) + # cv2.waitKey() + + diff --git a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/pth_bintotxt_nearest.py b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/pth_bintotxt_nearest.py index 13240c3f4f39733c2e1c984aa5175bdad516fca9..813bf982af3727544ff69c9aff1312c9a6c9f759 100644 --- a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/pth_bintotxt_nearest.py +++ b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/pth_bintotxt_nearest.py @@ -1,105 +1,105 @@ -import os -import sys -import numpy as np -import torch -import cv2 -from pypse import pse as pypse -import torch.nn.functional as F - - -img_path = sys.argv[1] -bin_path = sys.argv[2] -txt_path = sys.argv[3] - -if not os.path.exists(txt_path): - os.makedirs(txt_path) - -kernel_num=7 -min_kernel_area=5.0 -scale=1 -min_score = 0.9 -min_area = 600 - - -def get_images(): - ''' - find image files in test data path - :return: list of files found - ''' - files = [] - exts = ['jpg', 'png', 'jpeg', 'JPG'] - - for parent, _, filenames in os.walk(img_path): - for filename in filenames: - for ext in exts: - if filename.endswith(ext): - files.append(os.path.join(parent, filename)) - break - return files - - -im_fn_list = get_images() -for im_fn in im_fn_list: - print(im_fn) - im = cv2.imread(im_fn) - idx = os.path.basename(im_fn).split('/')[-1].split('.')[0].split('_')[1] - seg_maps = np.fromfile(bin_path+"/img_{}_1.bin".format(idx), "float32") - seg_maps = np.reshape(seg_maps, (1, 7, 704, 1216)) - seg_maps = torch.from_numpy(seg_maps) - - # Resize 算子 - # seg_maps = F.interpolate(seg_maps, size=(704, 1216), mode='bilinear', align_corners=False) - # print(seg_maps) - # print(seg_maps.shape) - # - # seg_maps = seg_maps.float() - score = torch.sigmoid(seg_maps[:, 0, :, :]) - outputs = (torch.sign(seg_maps - 1.0) + 1) / 2 - - text = outputs[:, 0, :, :] - kernels = outputs[:, 0:kernel_num, :, :] * text - - score = score.data.numpy()[0].astype(np.float32) - text = text.data.numpy()[0].astype(np.uint8) - kernels = kernels.numpy()[0].astype(np.uint8) - - # python version pse - pred = pypse(kernels, min_kernel_area / (scale * scale)) - - img_scale = (im.shape[1] * 1.0 / pred.shape[1], im.shape[0] * 1.0 / pred.shape[0]) - label = pred - label_num = np.max(label) + 1 - bboxes = [] - - for i in range(1, label_num): - points = np.array(np.where(label == i)).transpose((1, 0))[:, ::-1] - - if points.shape[0] < min_area: - continue - - score_i = np.mean(score[label == i]) - if score_i < min_score: - continue - - rect = cv2.minAreaRect(points) - bbox = cv2.boxPoints(rect) * img_scale - bbox = bbox.astype('int32') - bboxes.append(bbox.reshape(-1)) - # print(bboxes) - # save txt - res_file = os.path.join(txt_path,'{}.txt'.format(os.path.splitext(os.path.basename(im_fn))[0])) - with open(res_file, 'w') as f: - for b_idx, bbox in enumerate(bboxes): - values = [int(v) for v in bbox] - line = "%d, %d, %d, %d, %d, %d, %d, %d\n" % tuple(values) - f.write(line) - - - # show result - # for bbox in bboxes: - # cv2.drawContours(im, [bbox.reshape(4, 2)], -1, (0, 255, 0), 2) - # cv2.namedWindow('result', cv2.WINDOW_NORMAL) - # cv2.imshow('result', im) - # cv2.waitKey() - - +import os +import sys +import numpy as np +import torch +import cv2 +from pypse import pse as pypse +import torch.nn.functional as F + + +img_path = sys.argv[1] +bin_path = sys.argv[2] +txt_path = sys.argv[3] + +if not os.path.exists(txt_path): + os.makedirs(txt_path) + +kernel_num=7 +min_kernel_area=5.0 +scale=1 +min_score = 0.9 +min_area = 600 + + +def get_images(): + ''' + find image files in test data path + :return: list of files found + ''' + files = [] + exts = ['jpg', 'png', 'jpeg', 'JPG'] + + for parent, _, filenames in os.walk(img_path): + for filename in filenames: + for ext in exts: + if filename.endswith(ext): + files.append(os.path.join(parent, filename)) + break + return files + + +im_fn_list = get_images() +for im_fn in im_fn_list: + print(im_fn) + im = cv2.imread(im_fn) + idx = os.path.basename(im_fn).split('/')[-1].split('.')[0].split('_')[1] + seg_maps = np.fromfile(bin_path+"/img_{}_1.bin".format(idx), "float32") + seg_maps = np.reshape(seg_maps, (1, 7, 704, 1216)) + seg_maps = torch.from_numpy(seg_maps) + + # Resize 算子 + # seg_maps = F.interpolate(seg_maps, size=(704, 1216), mode='bilinear', align_corners=False) + # print(seg_maps) + # print(seg_maps.shape) + # + # seg_maps = seg_maps.float() + score = torch.sigmoid(seg_maps[:, 0, :, :]) + outputs = (torch.sign(seg_maps - 1.0) + 1) / 2 + + text = outputs[:, 0, :, :] + kernels = outputs[:, 0:kernel_num, :, :] * text + + score = score.data.numpy()[0].astype(np.float32) + text = text.data.numpy()[0].astype(np.uint8) + kernels = kernels.numpy()[0].astype(np.uint8) + + # python version pse + pred = pypse(kernels, min_kernel_area / (scale * scale)) + + img_scale = (im.shape[1] * 1.0 / pred.shape[1], im.shape[0] * 1.0 / pred.shape[0]) + label = pred + label_num = np.max(label) + 1 + bboxes = [] + + for i in range(1, label_num): + points = np.array(np.where(label == i)).transpose((1, 0))[:, ::-1] + + if points.shape[0] < min_area: + continue + + score_i = np.mean(score[label == i]) + if score_i < min_score: + continue + + rect = cv2.minAreaRect(points) + bbox = cv2.boxPoints(rect) * img_scale + bbox = bbox.astype('int32') + bboxes.append(bbox.reshape(-1)) + # print(bboxes) + # save txt + res_file = os.path.join(txt_path,'{}.txt'.format(os.path.splitext(os.path.basename(im_fn))[0])) + with open(res_file, 'w') as f: + for b_idx, bbox in enumerate(bboxes): + values = [int(v) for v in bbox] + line = "%d, %d, %d, %d, %d, %d, %d, %d\n" % tuple(values) + f.write(line) + + + # show result + # for bbox in bboxes: + # cv2.drawContours(im, [bbox.reshape(4, 2)], -1, (0, 255, 0), 2) + # cv2.namedWindow('result', cv2.WINDOW_NORMAL) + # cv2.imshow('result', im) + # cv2.waitKey() + + diff --git a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/pypse.py b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/pypse.py index 3200742b96b7c06f07ef9c78509a6b65317cbb84..70436680e1877cc6e06b3c2418bb6e749cb93425 100644 --- a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/pypse.py +++ b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/pypse.py @@ -1,56 +1,56 @@ -import numpy as np -import cv2 -import queue as Queue - -def pse(kernals, min_area): - kernal_num = len(kernals) - pred = np.zeros(kernals[0].shape, dtype='int32') - - label_num, label = cv2.connectedComponents(kernals[kernal_num - 1], connectivity=4) - - for label_idx in range(1, label_num): - if np.sum(label == label_idx) < min_area: - label[label == label_idx] = 0 - - queue = Queue.Queue(maxsize = 0) - next_queue = Queue.Queue(maxsize = 0) - points = np.array(np.where(label > 0)).transpose((1, 0)) - - for point_idx in range(points.shape[0]): - x, y = points[point_idx, 0], points[point_idx, 1] - l = label[x, y] - queue.put((x, y, l)) - pred[x, y] = l - - dx = [-1, 1, 0, 0] - dy = [0, 0, -1, 1] - for kernal_idx in range(kernal_num - 2, -1, -1): - kernal = kernals[kernal_idx].copy() - while not queue.empty(): - (x, y, l) = queue.get() - - is_edge = True - for j in range(4): - tmpx = x + dx[j] - tmpy = y + dy[j] - if tmpx < 0 or tmpx >= kernal.shape[0] or tmpy < 0 or tmpy >= kernal.shape[1]: - continue - if kernal[tmpx, tmpy] == 0 or pred[tmpx, tmpy] > 0: - continue - - queue.put((tmpx, tmpy, l)) - pred[tmpx, tmpy] = l - is_edge = False - if is_edge: - next_queue.put((x, y, l)) - - # kernal[pred > 0] = 0 - queue, next_queue = next_queue, queue - - # points = np.array(np.where(pred > 0)).transpose((1, 0)) - # for point_idx in range(points.shape[0]): - # x, y = points[point_idx, 0], points[point_idx, 1] - # l = pred[x, y] - # queue.put((x, y, l)) - +import numpy as np +import cv2 +import queue as Queue + +def pse(kernals, min_area): + kernal_num = len(kernals) + pred = np.zeros(kernals[0].shape, dtype='int32') + + label_num, label = cv2.connectedComponents(kernals[kernal_num - 1], connectivity=4) + + for label_idx in range(1, label_num): + if np.sum(label == label_idx) < min_area: + label[label == label_idx] = 0 + + queue = Queue.Queue(maxsize = 0) + next_queue = Queue.Queue(maxsize = 0) + points = np.array(np.where(label > 0)).transpose((1, 0)) + + for point_idx in range(points.shape[0]): + x, y = points[point_idx, 0], points[point_idx, 1] + l = label[x, y] + queue.put((x, y, l)) + pred[x, y] = l + + dx = [-1, 1, 0, 0] + dy = [0, 0, -1, 1] + for kernal_idx in range(kernal_num - 2, -1, -1): + kernal = kernals[kernal_idx].copy() + while not queue.empty(): + (x, y, l) = queue.get() + + is_edge = True + for j in range(4): + tmpx = x + dx[j] + tmpy = y + dy[j] + if tmpx < 0 or tmpx >= kernal.shape[0] or tmpy < 0 or tmpy >= kernal.shape[1]: + continue + if kernal[tmpx, tmpy] == 0 or pred[tmpx, tmpy] > 0: + continue + + queue.put((tmpx, tmpy, l)) + pred[tmpx, tmpy] = l + is_edge = False + if is_edge: + next_queue.put((x, y, l)) + + # kernal[pred > 0] = 0 + queue, next_queue = next_queue, queue + + # points = np.array(np.where(pred > 0)).transpose((1, 0)) + # for point_idx in range(points.shape[0]): + # x, y = points[point_idx, 0], points[point_idx, 1] + # l = pred[x, y] + # queue.put((x, y, l)) + return pred \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/revise_PSENET_bilinear.py b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/revise_PSENET_bilinear.py index b9b81a56887eff43dafc93ed269d491605e94720..8ce2e8a367a42e173e31589ed7441f3d2c37dc62 100644 --- a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/revise_PSENET_bilinear.py +++ b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/revise_PSENET_bilinear.py @@ -1,296 +1,296 @@ -import numpy as np -import onnx -import onnxruntime as rt -from onnx import shape_inference -import sys -model_path = sys.argv[1] -model = onnx.load(model_path) - -# model = onnx.shape_inference.infer_shapes(model) - -def getNodeAndIOname(nodename,model): - for i in range(len(model.graph.node)): - if model.graph.node[i].name == nodename: - Node = model.graph.node[i] - return Node,input_name,output_name - -def FindPeerOutNode(graph, edge_name): - for i, x in enumerate(graph.node): - if edge_name in x.output: - return i - return -1 - - -def RemoveNode(graph, node_list): - cnt = 0 - for i in range(len(model.graph.node)): - if model.graph.node[i].name in node_list: - graph.node.remove(graph.node[i - cnt]) # 因为节点个数变少了 - cnt += 1 -def FindDependNode(graph, end_node, start_node): - ''' - find dependency node, [end_node, start_node) - ''' - def dfs(graph, idx, start_node, n_list): - for edge in graph.node[idx].input: - node_idx = FindPeerOutNode(graph, edge) - if node_idx < 0: - # print('bad peerout index') - continue - n = graph.node[node_idx] - if n.name != start_node: - n_list.append(n.name) - # print('n.name', n.name) - n_list = dfs(graph, node_idx, start_node, n_list) - return n_list - - index = GetNodeIndex(graph, end_node) - n_list = [end_node, ] - return dfs(graph, index, start_node, n_list) - - -def createGraphMemberMap(graph_member_list): - member_map=dict(); - for n in graph_member_list: - member_map[n.name]=n; - return member_map - -def GetNodeIndex(graph, node_name): - index = 0 - for i in range(len(graph.node)): - if graph.node[i].name == node_name: - index = i - break - return index -def RemoveNode2(graph,node_list): - for name in node_list: - print("name",name) - ind = GetNodeIndex(graph,name) - print("ind:",ind) - graph.node.remove(graph.node[ind]) - - -for i in range(len(model.graph.node)): - if model.graph.node[i].op_type == "Resize": - print("Resize", i, model.graph.node[i].input, model.graph.node[i].output) - -sizes1 = onnx.helper.make_tensor('size1', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) -sizes2 = onnx.helper.make_tensor('size2', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) -sizes3 = onnx.helper.make_tensor('size3', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) -sizes4 = onnx.helper.make_tensor('size4', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) -sizes5 = onnx.helper.make_tensor('size5', onnx.TensorProto.FLOAT, [4], [1, 1, 4, 4]) -sizes6 = onnx.helper.make_tensor('size6', onnx.TensorProto.FLOAT, [4], [1, 1, 8, 8]) -sizes7 = onnx.helper.make_tensor('size7', onnx.TensorProto.FLOAT, [4], [1, 1, 4, 4]) - - -model.graph.initializer.append(sizes1) -model.graph.initializer.append(sizes2) -model.graph.initializer.append(sizes3) -model.graph.initializer.append(sizes4) -model.graph.initializer.append(sizes5) -model.graph.initializer.append(sizes6) -model.graph.initializer.append(sizes7) - - -newnode = onnx.helper.make_node( - 'Resize', - name='Resize_196', - # inputs=['551', '564', '572', 'size1'], - inputs=['551', '564', 'size1'], - outputs=['573'], - coordinate_transformation_mode='pytorch_half_pixel', - cubic_coeff_a=-0.75, - mode='nearest', - nearest_mode='floor' -) - -newnode2 = onnx.helper.make_node( - 'Resize', - name='Resize_224', - # inputs=['347', '367', '375', 'size2'], - inputs=['579', '592', 'size2'], - outputs=['601'], - coordinate_transformation_mode='pytorch_half_pixel', - cubic_coeff_a=-0.75, - mode='nearest', - nearest_mode='floor' -) - -newnode3 = onnx.helper.make_node( - 'Resize', - name='Resize_252', - # inputs=['347', '367', '375', 'size2'], - inputs=['607', '620', 'size3'], - outputs=['629'], - coordinate_transformation_mode='pytorch_half_pixel', - cubic_coeff_a=-0.75, - mode='nearest', - nearest_mode='floor' -) - -newnode4 = onnx.helper.make_node( - 'Resize', - name='Resize_285', - # inputs=['347', '367', '375', 'size2'], - inputs=['607', '653', 'size4'], - outputs=['662'], - coordinate_transformation_mode='pytorch_half_pixel', - cubic_coeff_a=-0.75, - mode='nearest', - nearest_mode='floor' -) - - -newnode5 = onnx.helper.make_node( - 'Resize', - name='Resize_312', - # inputs=['347', '367', '375', 'size2'], - inputs=['579', '680', 'size5'], - outputs=['689'], - coordinate_transformation_mode='pytorch_half_pixel', - cubic_coeff_a=-0.75, - mode='nearest', - nearest_mode='floor' -) - - -newnode6 = onnx.helper.make_node( - 'Resize', - name='Resize_339', - # inputs=['347', '367', '375', 'size2'], - inputs=['551', '707', 'size6'], - outputs=['716'], - coordinate_transformation_mode='pytorch_half_pixel', - cubic_coeff_a=-0.75, - mode='nearest', - nearest_mode='floor' -) - - -newnode7= onnx.helper.make_node( - 'Resize', - name='Resize_371', - # inputs=['347', '367', '375', 'size2'], - inputs=['721', '739', 'size7'], - outputs=['output1'], - coordinate_transformation_mode='pytorch_half_pixel', - cubic_coeff_a=-0.75, - mode='nearest', - nearest_mode='floor' -) - - - - -model.graph.node.remove(model.graph.node[196]) -model.graph.node.insert(196, newnode) - -model.graph.node.remove(model.graph.node[224]) -model.graph.node.insert(224, newnode2) - -model.graph.node.remove(model.graph.node[252]) -model.graph.node.insert(252, newnode3) - -model.graph.node.remove(model.graph.node[285]) -model.graph.node.insert(285, newnode4) - -model.graph.node.remove(model.graph.node[312]) -model.graph.node.insert(312, newnode5) - -model.graph.node.remove(model.graph.node[339]) -model.graph.node.insert(339, newnode6) - -model.graph.node.remove(model.graph.node[371]) -model.graph.node.insert(371, newnode7) - -slice_node1_1 = FindDependNode(model.graph, 'Slice_192', 'Relu_174') #结尾(will be deleted) qishi -print('node map:', slice_node1_1) - -slice_node1_2 = FindDependNode(model.graph, 'Cast_193', 'Relu_177') -print('node map:', slice_node1_2) - -slice_node2_1 = FindDependNode(model.graph, 'Slice_220', 'Relu_202') -print('node map:', slice_node2_1) - -slice_node2_2 = FindDependNode(model.graph, 'Cast_221', 'Relu_205') -print('node map:', slice_node2_2) - -slice_node3_1 = FindDependNode(model.graph, 'Slice_248', 'Relu_230') -print('node map:', slice_node3_1) -slice_node3_2 = FindDependNode(model.graph, 'Cast_249', 'Relu_233') -print('node map:', slice_node3_2) - - -slice_node4_1 = FindDependNode(model.graph, 'Slice_281', 'Relu_230') -print('node map:', slice_node4_1) -slice_node4_2 = FindDependNode(model.graph, 'Cast_282', 'Relu_258') -print('node map:', slice_node4_2) - - -slice_node5_1 = FindDependNode(model.graph, 'Slice_308', 'Relu_202') -print('node map:', slice_node5_1) -slice_node5_2 = FindDependNode(model.graph, 'Cast_309', 'Relu_258') -print('node map:', slice_node5_2) - -slice_node6_1 = FindDependNode(model.graph, 'Slice_335', 'Relu_174') -print('node map:', slice_node6_1) -slice_node6_2 = FindDependNode(model.graph, 'Cast_336', 'Relu_258') -print('node map:', slice_node6_2) - -slice_node7_1 = FindDependNode(model.graph, 'Slice_367', 'Conv_344') -print('node map:', slice_node7_1) -slice_node7_2 = FindDependNode(model.graph, 'Cast_368', 'actual_input_1') -print('node map:', slice_node7_2) - - -node_list = [] -node_list.extend(slice_node1_1) -node_list.extend(slice_node1_2) -node_list.extend(slice_node2_1) -node_list.extend(slice_node2_2) -node_list.extend(slice_node3_1) -node_list.extend(slice_node3_2) -node_list.extend(slice_node4_1) -node_list.extend(slice_node4_2) -node_list.extend(slice_node5_1) -node_list.extend(slice_node5_2) -node_list.extend(slice_node6_1) -node_list.extend(slice_node6_2) -node_list.extend(slice_node7_1) -node_list.extend(slice_node7_2) -node_list.extend(['Concat_194']) - -node_list.extend(['Concat_222']) - -node_list.extend(['Concat_250']) - -node_list.extend(['Concat_283']) - -node_list.extend(['Concat_337']) - -node_list.extend(['Concat_369']) -node_list.extend(['Concat_310']) -#node_list.extend(['Concat_308','Constant_140','Constant_166','Constant_192','Constant_224','Constant_251','Constant_278','Constant_301','Constant_309']) -print(node_list) -RemoveNode2(model.graph, node_list) - -#移除最后一个Resize -# 去除最后一个resize节点 -node_list=[] -node_list.extend(['Resize_371']) -print(node_list) -RemoveNode2(model.graph, node_list) #将最后一个Resize节点移除 -#将ouput1移除,并建立一个新的,插入进去 - -out0_info = onnx.helper.make_tensor_value_info('721', onnx.TensorProto.FLOAT, [-1, 7, 176, 304]) -model.graph.output.remove(model.graph.output[0]) -model.graph.output.insert(0, out0_info) - -onnx.checker.check_model(model) - - -onnx.save(model, sys.argv[1].split('.')[0] + "_revised.onnx") -# m = onnx.load("modify.onnx") - - - +import numpy as np +import onnx +import onnxruntime as rt +from onnx import shape_inference +import sys +model_path = sys.argv[1] +model = onnx.load(model_path) + +# model = onnx.shape_inference.infer_shapes(model) + +def getNodeAndIOname(nodename,model): + for i in range(len(model.graph.node)): + if model.graph.node[i].name == nodename: + Node = model.graph.node[i] + return Node,input_name,output_name + +def FindPeerOutNode(graph, edge_name): + for i, x in enumerate(graph.node): + if edge_name in x.output: + return i + return -1 + + +def RemoveNode(graph, node_list): + cnt = 0 + for i in range(len(model.graph.node)): + if model.graph.node[i].name in node_list: + graph.node.remove(graph.node[i - cnt]) # 因为节点个数变少了 + cnt += 1 +def FindDependNode(graph, end_node, start_node): + ''' + find dependency node, [end_node, start_node) + ''' + def dfs(graph, idx, start_node, n_list): + for edge in graph.node[idx].input: + node_idx = FindPeerOutNode(graph, edge) + if node_idx < 0: + # print('bad peerout index') + continue + n = graph.node[node_idx] + if n.name != start_node: + n_list.append(n.name) + # print('n.name', n.name) + n_list = dfs(graph, node_idx, start_node, n_list) + return n_list + + index = GetNodeIndex(graph, end_node) + n_list = [end_node, ] + return dfs(graph, index, start_node, n_list) + + +def createGraphMemberMap(graph_member_list): + member_map=dict(); + for n in graph_member_list: + member_map[n.name]=n; + return member_map + +def GetNodeIndex(graph, node_name): + index = 0 + for i in range(len(graph.node)): + if graph.node[i].name == node_name: + index = i + break + return index +def RemoveNode2(graph,node_list): + for name in node_list: + print("name",name) + ind = GetNodeIndex(graph,name) + print("ind:",ind) + graph.node.remove(graph.node[ind]) + + +for i in range(len(model.graph.node)): + if model.graph.node[i].op_type == "Resize": + print("Resize", i, model.graph.node[i].input, model.graph.node[i].output) + +sizes1 = onnx.helper.make_tensor('size1', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) +sizes2 = onnx.helper.make_tensor('size2', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) +sizes3 = onnx.helper.make_tensor('size3', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) +sizes4 = onnx.helper.make_tensor('size4', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) +sizes5 = onnx.helper.make_tensor('size5', onnx.TensorProto.FLOAT, [4], [1, 1, 4, 4]) +sizes6 = onnx.helper.make_tensor('size6', onnx.TensorProto.FLOAT, [4], [1, 1, 8, 8]) +sizes7 = onnx.helper.make_tensor('size7', onnx.TensorProto.FLOAT, [4], [1, 1, 4, 4]) + + +model.graph.initializer.append(sizes1) +model.graph.initializer.append(sizes2) +model.graph.initializer.append(sizes3) +model.graph.initializer.append(sizes4) +model.graph.initializer.append(sizes5) +model.graph.initializer.append(sizes6) +model.graph.initializer.append(sizes7) + + +newnode = onnx.helper.make_node( + 'Resize', + name='Resize_196', + # inputs=['551', '564', '572', 'size1'], + inputs=['551', '564', 'size1'], + outputs=['573'], + coordinate_transformation_mode='pytorch_half_pixel', + cubic_coeff_a=-0.75, + mode='nearest', + nearest_mode='floor' +) + +newnode2 = onnx.helper.make_node( + 'Resize', + name='Resize_224', + # inputs=['347', '367', '375', 'size2'], + inputs=['579', '592', 'size2'], + outputs=['601'], + coordinate_transformation_mode='pytorch_half_pixel', + cubic_coeff_a=-0.75, + mode='nearest', + nearest_mode='floor' +) + +newnode3 = onnx.helper.make_node( + 'Resize', + name='Resize_252', + # inputs=['347', '367', '375', 'size2'], + inputs=['607', '620', 'size3'], + outputs=['629'], + coordinate_transformation_mode='pytorch_half_pixel', + cubic_coeff_a=-0.75, + mode='nearest', + nearest_mode='floor' +) + +newnode4 = onnx.helper.make_node( + 'Resize', + name='Resize_285', + # inputs=['347', '367', '375', 'size2'], + inputs=['607', '653', 'size4'], + outputs=['662'], + coordinate_transformation_mode='pytorch_half_pixel', + cubic_coeff_a=-0.75, + mode='nearest', + nearest_mode='floor' +) + + +newnode5 = onnx.helper.make_node( + 'Resize', + name='Resize_312', + # inputs=['347', '367', '375', 'size2'], + inputs=['579', '680', 'size5'], + outputs=['689'], + coordinate_transformation_mode='pytorch_half_pixel', + cubic_coeff_a=-0.75, + mode='nearest', + nearest_mode='floor' +) + + +newnode6 = onnx.helper.make_node( + 'Resize', + name='Resize_339', + # inputs=['347', '367', '375', 'size2'], + inputs=['551', '707', 'size6'], + outputs=['716'], + coordinate_transformation_mode='pytorch_half_pixel', + cubic_coeff_a=-0.75, + mode='nearest', + nearest_mode='floor' +) + + +newnode7= onnx.helper.make_node( + 'Resize', + name='Resize_371', + # inputs=['347', '367', '375', 'size2'], + inputs=['721', '739', 'size7'], + outputs=['output1'], + coordinate_transformation_mode='pytorch_half_pixel', + cubic_coeff_a=-0.75, + mode='nearest', + nearest_mode='floor' +) + + + + +model.graph.node.remove(model.graph.node[196]) +model.graph.node.insert(196, newnode) + +model.graph.node.remove(model.graph.node[224]) +model.graph.node.insert(224, newnode2) + +model.graph.node.remove(model.graph.node[252]) +model.graph.node.insert(252, newnode3) + +model.graph.node.remove(model.graph.node[285]) +model.graph.node.insert(285, newnode4) + +model.graph.node.remove(model.graph.node[312]) +model.graph.node.insert(312, newnode5) + +model.graph.node.remove(model.graph.node[339]) +model.graph.node.insert(339, newnode6) + +model.graph.node.remove(model.graph.node[371]) +model.graph.node.insert(371, newnode7) + +slice_node1_1 = FindDependNode(model.graph, 'Slice_192', 'Relu_174') #结尾(will be deleted) qishi +print('node map:', slice_node1_1) + +slice_node1_2 = FindDependNode(model.graph, 'Cast_193', 'Relu_177') +print('node map:', slice_node1_2) + +slice_node2_1 = FindDependNode(model.graph, 'Slice_220', 'Relu_202') +print('node map:', slice_node2_1) + +slice_node2_2 = FindDependNode(model.graph, 'Cast_221', 'Relu_205') +print('node map:', slice_node2_2) + +slice_node3_1 = FindDependNode(model.graph, 'Slice_248', 'Relu_230') +print('node map:', slice_node3_1) +slice_node3_2 = FindDependNode(model.graph, 'Cast_249', 'Relu_233') +print('node map:', slice_node3_2) + + +slice_node4_1 = FindDependNode(model.graph, 'Slice_281', 'Relu_230') +print('node map:', slice_node4_1) +slice_node4_2 = FindDependNode(model.graph, 'Cast_282', 'Relu_258') +print('node map:', slice_node4_2) + + +slice_node5_1 = FindDependNode(model.graph, 'Slice_308', 'Relu_202') +print('node map:', slice_node5_1) +slice_node5_2 = FindDependNode(model.graph, 'Cast_309', 'Relu_258') +print('node map:', slice_node5_2) + +slice_node6_1 = FindDependNode(model.graph, 'Slice_335', 'Relu_174') +print('node map:', slice_node6_1) +slice_node6_2 = FindDependNode(model.graph, 'Cast_336', 'Relu_258') +print('node map:', slice_node6_2) + +slice_node7_1 = FindDependNode(model.graph, 'Slice_367', 'Conv_344') +print('node map:', slice_node7_1) +slice_node7_2 = FindDependNode(model.graph, 'Cast_368', 'actual_input_1') +print('node map:', slice_node7_2) + + +node_list = [] +node_list.extend(slice_node1_1) +node_list.extend(slice_node1_2) +node_list.extend(slice_node2_1) +node_list.extend(slice_node2_2) +node_list.extend(slice_node3_1) +node_list.extend(slice_node3_2) +node_list.extend(slice_node4_1) +node_list.extend(slice_node4_2) +node_list.extend(slice_node5_1) +node_list.extend(slice_node5_2) +node_list.extend(slice_node6_1) +node_list.extend(slice_node6_2) +node_list.extend(slice_node7_1) +node_list.extend(slice_node7_2) +node_list.extend(['Concat_194']) + +node_list.extend(['Concat_222']) + +node_list.extend(['Concat_250']) + +node_list.extend(['Concat_283']) + +node_list.extend(['Concat_337']) + +node_list.extend(['Concat_369']) +node_list.extend(['Concat_310']) +#node_list.extend(['Concat_308','Constant_140','Constant_166','Constant_192','Constant_224','Constant_251','Constant_278','Constant_301','Constant_309']) +print(node_list) +RemoveNode2(model.graph, node_list) + +#移除最后一个Resize +# 去除最后一个resize节点 +node_list=[] +node_list.extend(['Resize_371']) +print(node_list) +RemoveNode2(model.graph, node_list) #将最后一个Resize节点移除 +#将ouput1移除,并建立一个新的,插入进去 + +out0_info = onnx.helper.make_tensor_value_info('721', onnx.TensorProto.FLOAT, [-1, 7, 176, 304]) +model.graph.output.remove(model.graph.output[0]) +model.graph.output.insert(0, out0_info) + +onnx.checker.check_model(model) + + +onnx.save(model, sys.argv[1].split('.')[0] + "_revised.onnx") +# m = onnx.load("modify.onnx") + + + diff --git a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/revise_PSENET_nearest2.py b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/revise_PSENET_nearest2.py index 509e413da4ea0df6b666d137f9539f3636668324..241aad3caf85675a2c299d692477e37704513c52 100644 --- a/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/revise_PSENET_nearest2.py +++ b/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch/revise_PSENET_nearest2.py @@ -1,274 +1,274 @@ -import numpy as np -import onnx -import onnxruntime as rt -from onnx import shape_inference -import sys - - -model_path = sys.argv[1] -model = onnx.load(model_path) - - -def getNodeAndIOname(nodename,model): - for i in range(len(model.graph.node)): - if model.graph.node[i].name == nodename: - Node = model.graph.node[i] - return Node,input_name,output_name - -def FindPeerOutNode(graph, edge_name): - for i, x in enumerate(graph.node): - if edge_name in x.output: - return i - return -1 - - -def RemoveNode(graph, node_list): - cnt = 0 - for i in range(len(model.graph.node)): - if model.graph.node[i].name in node_list: - graph.node.remove(graph.node[i - cnt]) # 因为节点个数变少了 - cnt += 1 - - -def FindDependNode(graph, end_node, start_node): - ''' - find dependency node, [end_node, start_node) - ''' - def dfs(graph, idx, start_node, n_list): - for edge in graph.node[idx].input: - node_idx = FindPeerOutNode(graph, edge) - if node_idx < 0: - # print('bad peerout index') - continue - n = graph.node[node_idx] - if n.name != start_node: - n_list.append(n.name) - # print('n.name', n.name) - n_list = dfs(graph, node_idx, start_node, n_list) - return n_list - - index = GetNodeIndex(graph, end_node) - n_list = [end_node, ] - return dfs(graph, index, start_node, n_list) - - -def createGraphMemberMap(graph_member_list): - member_map=dict(); - for n in graph_member_list: - member_map[n.name]=n; - return member_map - -def GetNodeIndex(graph, node_name): - index = 0 - for i in range(len(graph.node)): - if graph.node[i].name == node_name: - index = i - break - return index -def RemoveNode2(graph,node_list): - for name in node_list: - print("name",name) - ind = GetNodeIndex(graph,name) - print("ind:",ind) - graph.node.remove(graph.node[ind]) - - -for i in range(len(model.graph.node)): - if model.graph.node[i].op_type == "Resize": - print("Resize", i, model.graph.node[i].input, model.graph.node[i].output) - -sizes1 = onnx.helper.make_tensor('size1', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) -sizes2 = onnx.helper.make_tensor('size2', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) -sizes3 = onnx.helper.make_tensor('size3', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) -sizes4 = onnx.helper.make_tensor('size4', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) -sizes5 = onnx.helper.make_tensor('size5', onnx.TensorProto.FLOAT, [4], [1, 1, 4, 4]) -sizes6 = onnx.helper.make_tensor('size6', onnx.TensorProto.FLOAT, [4], [1, 1, 8, 8]) -sizes7 = onnx.helper.make_tensor('size7', onnx.TensorProto.FLOAT, [4], [1, 1, 4, 4]) - - -model.graph.initializer.append(sizes1) -model.graph.initializer.append(sizes2) -model.graph.initializer.append(sizes3) -model.graph.initializer.append(sizes4) -model.graph.initializer.append(sizes5) -model.graph.initializer.append(sizes6) -model.graph.initializer.append(sizes7) - - -newnode = onnx.helper.make_node( - 'Resize', - name='Resize_141', - # inputs=['551', '564', '572', 'size1'], - inputs=['551', '564', 'size1'], - outputs=['573'], - coordinate_transformation_mode='asymmetric', - cubic_coeff_a=-0.75, - mode='nearest', - nearest_mode='floor' -) - -newnode2 = onnx.helper.make_node( - 'Resize', - name='Resize_165', - # inputs=['347', '367', '375', 'size2'], - inputs=['577', '590', 'size2'], - outputs=['599'], - coordinate_transformation_mode='asymmetric', - cubic_coeff_a=-0.75, - mode='nearest', - nearest_mode='floor' -) - -newnode3 = onnx.helper.make_node( - 'Resize', - name='Resize_189', - # inputs=['347', '367', '375', 'size2'], - inputs=['603', '616', 'size3'], - outputs=['625'], - coordinate_transformation_mode='asymmetric', - cubic_coeff_a=-0.75, - mode='nearest', - nearest_mode='floor' -) - -newnode4 = onnx.helper.make_node( - 'Resize', - name='Resize_219', - # inputs=['347', '367', '375', 'size2'], - inputs=['603', '647', 'size4'], - outputs=['656'], - coordinate_transformation_mode='asymmetric', - cubic_coeff_a=-0.75, - mode='nearest', - nearest_mode='floor' -) - - -newnode5 = onnx.helper.make_node( - 'Resize', - name='Resize_246', - # inputs=['347', '367', '375', 'size2'], - inputs=['577', '674', 'size5'], - outputs=['683'], - coordinate_transformation_mode='asymmetric', - cubic_coeff_a=-0.75, - mode='nearest', - nearest_mode='floor' -) - - -newnode6 = onnx.helper.make_node( - 'Resize', - name='Resize_273', - # inputs=['347', '367', '375', 'size2'], - inputs=['551', '701', 'size6'], - outputs=['710'], - coordinate_transformation_mode='asymmetric', - cubic_coeff_a=-0.75, - mode='nearest', - nearest_mode='floor' -) - - -newnode7= onnx.helper.make_node( - 'Resize', - name='Resize_304', - # inputs=['347', '367', '375', 'size2'], - inputs=['715', '733', 'size7'], - outputs=['output1'], - coordinate_transformation_mode='asymmetric', - cubic_coeff_a=-0.75, - mode='nearest', - nearest_mode='floor' -) - - -model.graph.node.remove(model.graph.node[141]) -model.graph.node.insert(141, newnode) - -model.graph.node.remove(model.graph.node[165]) -model.graph.node.insert(165, newnode2) - -model.graph.node.remove(model.graph.node[189]) -model.graph.node.insert(189, newnode3) - -model.graph.node.remove(model.graph.node[219]) -model.graph.node.insert(219, newnode4) - -model.graph.node.remove(model.graph.node[246]) -model.graph.node.insert(246, newnode5) - -model.graph.node.remove(model.graph.node[273]) -model.graph.node.insert(273, newnode6) - -model.graph.node.remove(model.graph.node[304]) -model.graph.node.insert(304, newnode7) - -slice_node1_1 = FindDependNode(model.graph, 'Slice_137', 'Relu_120') #结尾(will be deleted) qishi -print('node map:', slice_node1_1) - -slice_node1_2 = FindDependNode(model.graph, 'Cast_138', 'Relu_122') -print('node map:', slice_node1_2) - -slice_node2_1 = FindDependNode(model.graph, 'Slice_161', 'Relu_144') -print('node map:', slice_node2_1) - -slice_node2_2 = FindDependNode(model.graph, 'Cast_162', 'Relu_146') -print('node map:', slice_node2_2) - -slice_node3_1 = FindDependNode(model.graph, 'Slice_185', 'Relu_168') -print('node map:', slice_node3_1) -slice_node3_2 = FindDependNode(model.graph, 'Cast_186', 'Relu_170') -print('node map:', slice_node3_2) - - -slice_node4_1 = FindDependNode(model.graph, 'Slice_215', 'Relu_168') -print('node map:', slice_node4_1) -slice_node4_2 = FindDependNode(model.graph, 'Cast_216', 'Relu_192') -print('node map:', slice_node4_2) - - -slice_node5_1 = FindDependNode(model.graph, 'Slice_242', 'Relu_144') -print('node map:', slice_node5_1) -slice_node5_2 = FindDependNode(model.graph, 'Cast_243', 'Relu_192') -print('node map:', slice_node5_2) - -slice_node6_1 = FindDependNode(model.graph, 'Slice_269', 'Relu_120') -print('node map:', slice_node6_1) -slice_node6_2 = FindDependNode(model.graph, 'Cast_270', 'Relu_192') -print('node map:', slice_node6_2) - -slice_node7_1 = FindDependNode(model.graph, 'Slice_300', 'Conv_277') -print('node map:', slice_node7_1) -slice_node7_2 = FindDependNode(model.graph, 'Cast_301', 'actual_input_1') -print('node map:', slice_node7_2) - - -node_list = [] -node_list.extend(slice_node1_1) -node_list.extend(slice_node1_2) -node_list.extend(slice_node2_1) -node_list.extend(slice_node2_2) -node_list.extend(slice_node3_1) -node_list.extend(slice_node3_2) -node_list.extend(slice_node4_1) -node_list.extend(slice_node4_2) -node_list.extend(slice_node5_1) -node_list.extend(slice_node5_2) -node_list.extend(slice_node6_1) -node_list.extend(slice_node6_2) -node_list.extend(slice_node7_1) -node_list.extend(slice_node7_2) -node_list.extend(['Concat_139']) -node_list.extend(['Concat_163']) -node_list.extend(['Concat_187']) -node_list.extend(['Concat_217']) -node_list.extend(['Concat_271']) -node_list.extend(['Concat_302']) -node_list.extend(['Concat_244']) -print(node_list) -RemoveNode2(model.graph, node_list) - - -onnx.checker.check_model(model) -onnx.save(model, sys.argv[1].split('.')[0] + "_revised2.onnx") +import numpy as np +import onnx +import onnxruntime as rt +from onnx import shape_inference +import sys + + +model_path = sys.argv[1] +model = onnx.load(model_path) + + +def getNodeAndIOname(nodename,model): + for i in range(len(model.graph.node)): + if model.graph.node[i].name == nodename: + Node = model.graph.node[i] + return Node,input_name,output_name + +def FindPeerOutNode(graph, edge_name): + for i, x in enumerate(graph.node): + if edge_name in x.output: + return i + return -1 + + +def RemoveNode(graph, node_list): + cnt = 0 + for i in range(len(model.graph.node)): + if model.graph.node[i].name in node_list: + graph.node.remove(graph.node[i - cnt]) # 因为节点个数变少了 + cnt += 1 + + +def FindDependNode(graph, end_node, start_node): + ''' + find dependency node, [end_node, start_node) + ''' + def dfs(graph, idx, start_node, n_list): + for edge in graph.node[idx].input: + node_idx = FindPeerOutNode(graph, edge) + if node_idx < 0: + # print('bad peerout index') + continue + n = graph.node[node_idx] + if n.name != start_node: + n_list.append(n.name) + # print('n.name', n.name) + n_list = dfs(graph, node_idx, start_node, n_list) + return n_list + + index = GetNodeIndex(graph, end_node) + n_list = [end_node, ] + return dfs(graph, index, start_node, n_list) + + +def createGraphMemberMap(graph_member_list): + member_map=dict(); + for n in graph_member_list: + member_map[n.name]=n; + return member_map + +def GetNodeIndex(graph, node_name): + index = 0 + for i in range(len(graph.node)): + if graph.node[i].name == node_name: + index = i + break + return index +def RemoveNode2(graph,node_list): + for name in node_list: + print("name",name) + ind = GetNodeIndex(graph,name) + print("ind:",ind) + graph.node.remove(graph.node[ind]) + + +for i in range(len(model.graph.node)): + if model.graph.node[i].op_type == "Resize": + print("Resize", i, model.graph.node[i].input, model.graph.node[i].output) + +sizes1 = onnx.helper.make_tensor('size1', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) +sizes2 = onnx.helper.make_tensor('size2', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) +sizes3 = onnx.helper.make_tensor('size3', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) +sizes4 = onnx.helper.make_tensor('size4', onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) +sizes5 = onnx.helper.make_tensor('size5', onnx.TensorProto.FLOAT, [4], [1, 1, 4, 4]) +sizes6 = onnx.helper.make_tensor('size6', onnx.TensorProto.FLOAT, [4], [1, 1, 8, 8]) +sizes7 = onnx.helper.make_tensor('size7', onnx.TensorProto.FLOAT, [4], [1, 1, 4, 4]) + + +model.graph.initializer.append(sizes1) +model.graph.initializer.append(sizes2) +model.graph.initializer.append(sizes3) +model.graph.initializer.append(sizes4) +model.graph.initializer.append(sizes5) +model.graph.initializer.append(sizes6) +model.graph.initializer.append(sizes7) + + +newnode = onnx.helper.make_node( + 'Resize', + name='Resize_141', + # inputs=['551', '564', '572', 'size1'], + inputs=['551', '564', 'size1'], + outputs=['573'], + coordinate_transformation_mode='asymmetric', + cubic_coeff_a=-0.75, + mode='nearest', + nearest_mode='floor' +) + +newnode2 = onnx.helper.make_node( + 'Resize', + name='Resize_165', + # inputs=['347', '367', '375', 'size2'], + inputs=['577', '590', 'size2'], + outputs=['599'], + coordinate_transformation_mode='asymmetric', + cubic_coeff_a=-0.75, + mode='nearest', + nearest_mode='floor' +) + +newnode3 = onnx.helper.make_node( + 'Resize', + name='Resize_189', + # inputs=['347', '367', '375', 'size2'], + inputs=['603', '616', 'size3'], + outputs=['625'], + coordinate_transformation_mode='asymmetric', + cubic_coeff_a=-0.75, + mode='nearest', + nearest_mode='floor' +) + +newnode4 = onnx.helper.make_node( + 'Resize', + name='Resize_219', + # inputs=['347', '367', '375', 'size2'], + inputs=['603', '647', 'size4'], + outputs=['656'], + coordinate_transformation_mode='asymmetric', + cubic_coeff_a=-0.75, + mode='nearest', + nearest_mode='floor' +) + + +newnode5 = onnx.helper.make_node( + 'Resize', + name='Resize_246', + # inputs=['347', '367', '375', 'size2'], + inputs=['577', '674', 'size5'], + outputs=['683'], + coordinate_transformation_mode='asymmetric', + cubic_coeff_a=-0.75, + mode='nearest', + nearest_mode='floor' +) + + +newnode6 = onnx.helper.make_node( + 'Resize', + name='Resize_273', + # inputs=['347', '367', '375', 'size2'], + inputs=['551', '701', 'size6'], + outputs=['710'], + coordinate_transformation_mode='asymmetric', + cubic_coeff_a=-0.75, + mode='nearest', + nearest_mode='floor' +) + + +newnode7= onnx.helper.make_node( + 'Resize', + name='Resize_304', + # inputs=['347', '367', '375', 'size2'], + inputs=['715', '733', 'size7'], + outputs=['output1'], + coordinate_transformation_mode='asymmetric', + cubic_coeff_a=-0.75, + mode='nearest', + nearest_mode='floor' +) + + +model.graph.node.remove(model.graph.node[141]) +model.graph.node.insert(141, newnode) + +model.graph.node.remove(model.graph.node[165]) +model.graph.node.insert(165, newnode2) + +model.graph.node.remove(model.graph.node[189]) +model.graph.node.insert(189, newnode3) + +model.graph.node.remove(model.graph.node[219]) +model.graph.node.insert(219, newnode4) + +model.graph.node.remove(model.graph.node[246]) +model.graph.node.insert(246, newnode5) + +model.graph.node.remove(model.graph.node[273]) +model.graph.node.insert(273, newnode6) + +model.graph.node.remove(model.graph.node[304]) +model.graph.node.insert(304, newnode7) + +slice_node1_1 = FindDependNode(model.graph, 'Slice_137', 'Relu_120') #结尾(will be deleted) qishi +print('node map:', slice_node1_1) + +slice_node1_2 = FindDependNode(model.graph, 'Cast_138', 'Relu_122') +print('node map:', slice_node1_2) + +slice_node2_1 = FindDependNode(model.graph, 'Slice_161', 'Relu_144') +print('node map:', slice_node2_1) + +slice_node2_2 = FindDependNode(model.graph, 'Cast_162', 'Relu_146') +print('node map:', slice_node2_2) + +slice_node3_1 = FindDependNode(model.graph, 'Slice_185', 'Relu_168') +print('node map:', slice_node3_1) +slice_node3_2 = FindDependNode(model.graph, 'Cast_186', 'Relu_170') +print('node map:', slice_node3_2) + + +slice_node4_1 = FindDependNode(model.graph, 'Slice_215', 'Relu_168') +print('node map:', slice_node4_1) +slice_node4_2 = FindDependNode(model.graph, 'Cast_216', 'Relu_192') +print('node map:', slice_node4_2) + + +slice_node5_1 = FindDependNode(model.graph, 'Slice_242', 'Relu_144') +print('node map:', slice_node5_1) +slice_node5_2 = FindDependNode(model.graph, 'Cast_243', 'Relu_192') +print('node map:', slice_node5_2) + +slice_node6_1 = FindDependNode(model.graph, 'Slice_269', 'Relu_120') +print('node map:', slice_node6_1) +slice_node6_2 = FindDependNode(model.graph, 'Cast_270', 'Relu_192') +print('node map:', slice_node6_2) + +slice_node7_1 = FindDependNode(model.graph, 'Slice_300', 'Conv_277') +print('node map:', slice_node7_1) +slice_node7_2 = FindDependNode(model.graph, 'Cast_301', 'actual_input_1') +print('node map:', slice_node7_2) + + +node_list = [] +node_list.extend(slice_node1_1) +node_list.extend(slice_node1_2) +node_list.extend(slice_node2_1) +node_list.extend(slice_node2_2) +node_list.extend(slice_node3_1) +node_list.extend(slice_node3_2) +node_list.extend(slice_node4_1) +node_list.extend(slice_node4_2) +node_list.extend(slice_node5_1) +node_list.extend(slice_node5_2) +node_list.extend(slice_node6_1) +node_list.extend(slice_node6_2) +node_list.extend(slice_node7_1) +node_list.extend(slice_node7_2) +node_list.extend(['Concat_139']) +node_list.extend(['Concat_163']) +node_list.extend(['Concat_187']) +node_list.extend(['Concat_217']) +node_list.extend(['Concat_271']) +node_list.extend(['Concat_302']) +node_list.extend(['Concat_244']) +print(node_list) +RemoveNode2(model.graph, node_list) + + +onnx.checker.check_model(model) +onnx.save(model, sys.argv[1].split('.')[0] + "_revised2.onnx") diff --git a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/ imagenet_torch_preprocess.py b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/ imagenet_torch_preprocess.py index b0af0d5d04f9a5db20c5332764b2cc5b03b312a2..91cf3472e5b257246f7cc94fde2f64b23c5e9208 100644 --- a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/ imagenet_torch_preprocess.py +++ b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/ imagenet_torch_preprocess.py @@ -1,116 +1,116 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from PIL import Image -import numpy as np -import multiprocessing - - -model_config = { - 'res2net101': { - 'resize': 256, - 'centercrop': 224, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv3': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv4': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.5, 0.5, 0.5], - 'std': [0.5, 0.5, 0.5], - }, -} - - -def center_crop(img, output_size): - if isinstance(output_size, int): - output_size = (int(output_size), int(output_size)) - image_width, image_height = img.size - crop_height, crop_width = output_size - crop_top = int(round((image_height - crop_height) / 2.)) - crop_left = int(round((image_width - crop_width) / 2.)) - return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) - - -def resize(img, size, interpolation=Image.BILINEAR): - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def gen_input_bin(mode_type, file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - # RGBA to RGB - image = Image.open(os.path.join(src_path, file)).convert('RGB') - image = resize(image, model_config[mode_type]['resize']) # Resize - image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop - img = np.array(image, dtype=np.float32) - img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW - img = img / 255. # ToTensor: div 255 - img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean - img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - - -def preprocess(mode_type, src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") - mode_type = sys.argv[1] - src_path = sys.argv[2] - save_path = sys.argv[3] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - if mode_type not in model_config: - model_type_help = "model type: " - for key in model_config.keys(): - model_type_help += key - model_type_help += ' ' - raise Exception(model_type_help) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - preprocess(mode_type, src_path, save_path) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from PIL import Image +import numpy as np +import multiprocessing + + +model_config = { + 'res2net101': { + 'resize': 256, + 'centercrop': 224, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv3': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv4': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.5, 0.5, 0.5], + 'std': [0.5, 0.5, 0.5], + }, +} + + +def center_crop(img, output_size): + if isinstance(output_size, int): + output_size = (int(output_size), int(output_size)) + image_width, image_height = img.size + crop_height, crop_width = output_size + crop_top = int(round((image_height - crop_height) / 2.)) + crop_left = int(round((image_width - crop_width) / 2.)) + return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) + + +def resize(img, size, interpolation=Image.BILINEAR): + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def gen_input_bin(mode_type, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + # RGBA to RGB + image = Image.open(os.path.join(src_path, file)).convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.float32) + img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW + img = img / 255. # ToTensor: div 255 + img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean + img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +def preprocess(mode_type, src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") + mode_type = sys.argv[1] + src_path = sys.argv[2] + save_path = sys.argv[3] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if mode_type not in model_config: + model_type_help = "model type: " + for key in model_config.keys(): + model_type_help += key + model_type_help += ' ' + raise Exception(model_type_help) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess(mode_type, src_path, save_path) diff --git a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/ requirements.txt b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/ requirements.txt index 6f7e11bdad5e237f1ba95da215d2262add251e53..e71bbad34d386cdbf0cdbab0461c29ac72d0aa40 100644 --- a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/ requirements.txt +++ b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/ requirements.txt @@ -1,6 +1,6 @@ -matplotlib==3.5.0 -Pillow==8.4.0 -numpy==1.19.5 -torchvision==0.11.0 -torch==1.10.0 +matplotlib==3.5.0 +Pillow==8.4.0 +numpy==1.19.5 +torchvision==0.11.0 +torch==1.10.0 onnx==1.7.0 \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/LICENSE b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/LICENSE index 29f81d812f3e768fa89638d1f72920dbfd1413a8..261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64 100644 --- a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/LICENSE +++ b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/README.md b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/README.md index 69fa898a117ea50952a777d8b53a7596c4653c9c..d6ed0a7f18ea82c8a06519372f6679218da75f57 100644 --- a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/README.md +++ b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/README.md @@ -1,86 +1,86 @@ -# Res2Net_v1b_101模型测试指导 - -- [1 文件说明](#1-文件说明) -- [2 设置环境变量](#2-设置环境变量) -- [3 端到端推理步骤](#3-端到端推理步骤) - - [3.1 下载代码](#31-下载代码) - - [3.2 om模型转换](#32-om模型转换) - - [3.3 om模型推理](#33-om模型推理) - ------- - -## 1 文件说明 -``` -Res2Net_v1b_101_for_PyTorch - ├── get_info.py // 生成推理输入的数据集二进制info文件或jpg info文件 - ├── pth2onnx.py // 用于转换pth模型文件到onnx模型文件 - ├── diff.patch // 修改开源代码的patch文件 - ├── imagenet_torch_preprocess.py // imagenet数据集预处理,生成图片二进制文件 - ├── README.md - ├── atc.sh // onnx模型转换om模型脚本 - └── vision_metric_ImageNet.py // 验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy - -``` - -## 2 设置环境变量 - -```shell -source env.sh -``` - -## 3 端到端推理步骤 - -### 3.1 下载代码 -git clone 开源仓 https://github.com/Res2Net/Res2Net-PretrainedModels ,切换到所需tag。 -```shell -git clone https://github.com/Res2Net/Res2Net-PretrainedModels.git -cd Res2Net-PretrainedModels -git reset 1d51000f3340fb61b4 --hard -git apply diff.patch -``` - -### 3.2 om模型转换 - -通过pth2onnx.py脚本转化为onnx模型 - -```shell -# 直接导出原始ONNX -python3.7 pth2onnx.py -m ./res2net101_v1b_26w_4s-0812c246.pth -o ./res2net.onnx - -# 导出NPU上优化后的ONNX -python3.7 pth2onnx.py -m ./res2net101_v1b_26w_4s-0812c246.pth -o ./res2net.onnx --optimizer -``` - -利用ATC工具转换为om模型 -```shell -bash atc.sh -``` - -### 3.3 om模型推理 - -(1) 数据集预处理 - - 数据预处理,把ImageNet 50000张图片转为二进制文件(.bin) - - ```shell - python3.7 imagenet_torch_preprocess.py res2net101 /home/HwHiAiUser/dataset/ImageNet/ILSVRC2012_img_val ./prep_bin - ``` - 生成数据集info文件 - - ```shell - python3.7 get_info.py bin ./prep_bin ./BinaryImageNet.info 224 224 - ``` -(2)推理 - 配置环境变量,运行benchmark工具进行推理,参数说明参见 [cann-benchmark](https://gitee.com/ascend/cann-benchmark/tree/master/infer) - - ```shell - source env.sh # 如果前面配置过,这里不用执行 - ./benchmark -model_type=vision -om_path=resnet_bs16.om -device_id=0 -batch_size=16 -input_text_path=BinaryImageNet.info -input_width=256 -input_height=256 -useDvpp=false -output_binary=false - ``` - -(3)统计Accuracy值 - 精度验证,调用vision_metric_ImageNet.py脚本与数据集标签val_label.txt比对,可以获得Accuracy数据,结果保存在result.json中 - - ```shell - python3.7 vision_metric_ImageNet.py result/dumpOutput_device0/ ./val_label.txt ./ result.json - ``` +# Res2Net_v1b_101模型测试指导 + +- [1 文件说明](#1-文件说明) +- [2 设置环境变量](#2-设置环境变量) +- [3 端到端推理步骤](#3-端到端推理步骤) + - [3.1 下载代码](#31-下载代码) + - [3.2 om模型转换](#32-om模型转换) + - [3.3 om模型推理](#33-om模型推理) + +------ + +## 1 文件说明 +``` +Res2Net_v1b_101_for_PyTorch + ├── get_info.py // 生成推理输入的数据集二进制info文件或jpg info文件 + ├── pth2onnx.py // 用于转换pth模型文件到onnx模型文件 + ├── diff.patch // 修改开源代码的patch文件 + ├── imagenet_torch_preprocess.py // imagenet数据集预处理,生成图片二进制文件 + ├── README.md + ├── atc.sh // onnx模型转换om模型脚本 + └── vision_metric_ImageNet.py // 验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy + +``` + +## 2 设置环境变量 + +```shell +source env.sh +``` + +## 3 端到端推理步骤 + +### 3.1 下载代码 +git clone 开源仓 https://github.com/Res2Net/Res2Net-PretrainedModels ,切换到所需tag。 +```shell +git clone https://github.com/Res2Net/Res2Net-PretrainedModels.git +cd Res2Net-PretrainedModels +git reset 1d51000f3340fb61b4 --hard +git apply diff.patch +``` + +### 3.2 om模型转换 + +通过pth2onnx.py脚本转化为onnx模型 + +```shell +# 直接导出原始ONNX +python3.7 pth2onnx.py -m ./res2net101_v1b_26w_4s-0812c246.pth -o ./res2net.onnx + +# 导出NPU上优化后的ONNX +python3.7 pth2onnx.py -m ./res2net101_v1b_26w_4s-0812c246.pth -o ./res2net.onnx --optimizer +``` + +利用ATC工具转换为om模型 +```shell +bash atc.sh +``` + +### 3.3 om模型推理 + +(1) 数据集预处理 + + 数据预处理,把ImageNet 50000张图片转为二进制文件(.bin) + + ```shell + python3.7 imagenet_torch_preprocess.py res2net101 /home/HwHiAiUser/dataset/ImageNet/ILSVRC2012_img_val ./prep_bin + ``` + 生成数据集info文件 + + ```shell + python3.7 get_info.py bin ./prep_bin ./BinaryImageNet.info 224 224 + ``` +(2)推理 + 配置环境变量,运行benchmark工具进行推理,参数说明参见 [cann-benchmark](https://gitee.com/ascend/cann-benchmark/tree/master/infer) + + ```shell + source env.sh # 如果前面配置过,这里不用执行 + ./benchmark -model_type=vision -om_path=resnet_bs16.om -device_id=0 -batch_size=16 -input_text_path=BinaryImageNet.info -input_width=256 -input_height=256 -useDvpp=false -output_binary=false + ``` + +(3)统计Accuracy值 + 精度验证,调用vision_metric_ImageNet.py脚本与数据集标签val_label.txt比对,可以获得Accuracy数据,结果保存在result.json中 + + ```shell + python3.7 vision_metric_ImageNet.py result/dumpOutput_device0/ ./val_label.txt ./ result.json + ``` diff --git a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/atc.sh b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/atc.sh index e98af05173364eed0b1a581105d3685178fe157b..39a1992278cbd212bbc7cd01da53bff2044e14e4 100644 --- a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/atc.sh +++ b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/atc.sh @@ -1,16 +1,16 @@ -# 配置环境变量 -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp - -# 710 fp16,执行如下命令 -atc --model=./res2net.onnx \ - --framework=5 \ - --output=res2net_bs16 \ - --input_format=NCHW \ - --input_shape="x:16,3,224,224" \ - --log=error \ - --soc_version=Ascend710 \ - --enable_small_channel=1 +# 配置环境变量 +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp + +# 710 fp16,执行如下命令 +atc --model=./res2net.onnx \ + --framework=5 \ + --output=res2net_bs16 \ + --input_format=NCHW \ + --input_shape="x:16,3,224,224" \ + --log=error \ + --soc_version=Ascend710 \ + --enable_small_channel=1 diff --git a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/diff.patch b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/diff.patch index dd78507002396a8ee889afc1337cec2d5009c129..5770c5852f1aa458ed7224afbd3cbba5e3156f14 100644 --- a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/diff.patch +++ b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/diff.patch @@ -1,32 +1,32 @@ -diff --git a/res2net_v1b.py b/res2net_v1b.py -index 6ced156..0ec1ce8 100644 ---- a/res2net_v1b.py -+++ b/res2net_v1b.py -@@ -64,6 +64,7 @@ class Bottle2neck(nn.Module): - out = self.relu(out) - - spx = torch.split(out, self.width, 1) -+ out_list = [] - for i in range(self.nums): - if i==0 or self.stype=='stage': - sp = spx[i] -@@ -71,15 +72,13 @@ class Bottle2neck(nn.Module): - sp = sp + spx[i] - sp = self.convs[i](sp) - sp = self.relu(self.bns[i](sp)) -- if i==0: -- out = sp -- else: -- out = torch.cat((out, sp), 1) -+ out_list.append(sp) - if self.scale != 1 and self.stype=='normal': -- out = torch.cat((out, spx[self.nums]),1) -+ out_list.append(spx[self.nums]) - elif self.scale != 1 and self.stype=='stage': -- out = torch.cat((out, self.pool(spx[self.nums])),1) -+ out_list.append(self.pool(spx[self.nums])) - -+ out = torch.cat(out_list, 1) - out = self.conv3(out) - out = self.bn3(out) - +diff --git a/res2net_v1b.py b/res2net_v1b.py +index 6ced156..0ec1ce8 100644 +--- a/res2net_v1b.py ++++ b/res2net_v1b.py +@@ -64,6 +64,7 @@ class Bottle2neck(nn.Module): + out = self.relu(out) + + spx = torch.split(out, self.width, 1) ++ out_list = [] + for i in range(self.nums): + if i==0 or self.stype=='stage': + sp = spx[i] +@@ -71,15 +72,13 @@ class Bottle2neck(nn.Module): + sp = sp + spx[i] + sp = self.convs[i](sp) + sp = self.relu(self.bns[i](sp)) +- if i==0: +- out = sp +- else: +- out = torch.cat((out, sp), 1) ++ out_list.append(sp) + if self.scale != 1 and self.stype=='normal': +- out = torch.cat((out, spx[self.nums]),1) ++ out_list.append(spx[self.nums]) + elif self.scale != 1 and self.stype=='stage': +- out = torch.cat((out, self.pool(spx[self.nums])),1) ++ out_list.append(self.pool(spx[self.nums])) + ++ out = torch.cat(out_list, 1) + out = self.conv3(out) + out = self.bn3(out) + diff --git a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/env.sh b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/env.sh index 91b1a00516e987530b481fcbe989e0944a460e06..96389fea980ff6e57785a3f35c29e34dc862089e 100644 --- a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/env.sh +++ b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/env.sh @@ -1,7 +1,7 @@ -#!/bin/bash -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:/usr/local/Ascend/ascend-toolkit/latest/pyACL/python/site-packages/acl:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp +#!/bin/bash +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:/usr/local/Ascend/ascend-toolkit/latest/pyACL/python/site-packages/acl:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp echo "successfully!!" \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/get_info.py b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/get_info.py index 6077f1416bb441d98401472d96aeddd4e0b66bb2..fa3108bd7ff139c64f3d1b11c09c67e808888f90 100644 --- a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/get_info.py +++ b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/get_info.py @@ -1,60 +1,60 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) diff --git a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/modelzoo_level.txt b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/modelzoo_level.txt +++ b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/pth2onnx.py b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/pth2onnx.py index 776b44620a53a8bb57fcdc03ff413838f0d7d6b5..af37a616d9b913088cfebf774d1f1926aeb54d40 100644 --- a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/pth2onnx.py +++ b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/pth2onnx.py @@ -1,85 +1,85 @@ -# Copyright 2022 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import itertools -import argparse -from res2net_v1b import res2net101_v1b_26w_4s -import torch -import torch.nn.functional as F - -parser = argparse.ArgumentParser(description='res2net101_v1b inference') -parser.add_argument('-m', '--trained_model', default=None, - type=str, help='Trained state_dict file path to open') -parser.add_argument('-o', '--output', default=None, - type=str, help='ONNX model file') -parser.add_argument('--optimizer', default='store_ture', - help='ONNX model optimizer') -args = parser.parse_args() - -model = res2net101_v1b_26w_4s() -checkpoint = torch.load(args.trained_model, map_location=torch.device('cpu')) - - -def optimizer(model, checkpoint): - presistent_buffers = {k: v for k, v in model.named_buffers() if k not in model._non_persistent_buffers_set} - local_name_params = itertools.chain(model.named_parameters(), presistent_buffers.items()) - local_state = {k: v for k, v in local_name_params if v is not None} - - for name, param in checkpoint.items(): - if local_state[name].shape != param.shape: - if 'conv1' in name or 'conv3' in name: - n1, c1, h, w = local_state[name].shape - n2, c2, h, w = param.shape - if n1 == n2: - c = (c1 - c2) // 4 - cell = c2 // 4 - checkpoint[name] = torch.cat([torch.cat((param[:, i * cell: (i + 1) * cell, ...], - torch.zeros(n1, c, h, w, dtype=param.dtype)), - 1) for i in range(4)], 1) - else: - n = (n1 - n2) // 4 - cell = n2 // 4 - checkpoint[name] = torch.cat([torch.cat((param[i * cell: (i + 1) * cell, ...], - torch.zeros(n, c1, h, w, dtype=param.dtype)), - 0) for i in range(4)], 0) - elif 'bn1' in name or 'bn3' in name: - cell = param.size(0) // 4 - n = (local_state[name].size(0) - param.size(0)) // 4 - checkpoint[name] = torch.cat([torch.cat((param[i * cell: (i + 1) * cell], - torch.zeros(n, dtype=param.dtype)), - 0) for i in range(4)]) - else: - if param.dim() == 1: - checkpoint[name] = torch.cat((param, - torch.zeros(local_state[name].size(0) - param.size(0), dtype=param.dtype)), - 0) - else: - n1, c1, h, w = local_state[name].shape - n2, c2, h, w = param.shape - param = torch.cat((param, torch.zeros(n2, c1 - c2, h, w, dtype=param.dtype)), 1) - checkpoint[name] = torch.cat((param, torch.zeros(n1 - n2, c1, h, w, dtype=param.dtype)), 0) - return checkpoint - - -if __name__ == '__main__': - if args.optimizer: - checkpoint = optimizer(model, checkpoint) - model.load_state_dict(checkpoint) - model.eval() - - inputs = torch.rand(1, 3, 224, 224) - torch.onnx.export(model, inputs, args.output, - input_names=["x"], output_names=["output"], - dynamic_axes={"x": {0: "-1"}}, opset_version=11) +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import itertools +import argparse +from res2net_v1b import res2net101_v1b_26w_4s +import torch +import torch.nn.functional as F + +parser = argparse.ArgumentParser(description='res2net101_v1b inference') +parser.add_argument('-m', '--trained_model', default=None, + type=str, help='Trained state_dict file path to open') +parser.add_argument('-o', '--output', default=None, + type=str, help='ONNX model file') +parser.add_argument('--optimizer', default='store_ture', + help='ONNX model optimizer') +args = parser.parse_args() + +model = res2net101_v1b_26w_4s() +checkpoint = torch.load(args.trained_model, map_location=torch.device('cpu')) + + +def optimizer(model, checkpoint): + presistent_buffers = {k: v for k, v in model.named_buffers() if k not in model._non_persistent_buffers_set} + local_name_params = itertools.chain(model.named_parameters(), presistent_buffers.items()) + local_state = {k: v for k, v in local_name_params if v is not None} + + for name, param in checkpoint.items(): + if local_state[name].shape != param.shape: + if 'conv1' in name or 'conv3' in name: + n1, c1, h, w = local_state[name].shape + n2, c2, h, w = param.shape + if n1 == n2: + c = (c1 - c2) // 4 + cell = c2 // 4 + checkpoint[name] = torch.cat([torch.cat((param[:, i * cell: (i + 1) * cell, ...], + torch.zeros(n1, c, h, w, dtype=param.dtype)), + 1) for i in range(4)], 1) + else: + n = (n1 - n2) // 4 + cell = n2 // 4 + checkpoint[name] = torch.cat([torch.cat((param[i * cell: (i + 1) * cell, ...], + torch.zeros(n, c1, h, w, dtype=param.dtype)), + 0) for i in range(4)], 0) + elif 'bn1' in name or 'bn3' in name: + cell = param.size(0) // 4 + n = (local_state[name].size(0) - param.size(0)) // 4 + checkpoint[name] = torch.cat([torch.cat((param[i * cell: (i + 1) * cell], + torch.zeros(n, dtype=param.dtype)), + 0) for i in range(4)]) + else: + if param.dim() == 1: + checkpoint[name] = torch.cat((param, + torch.zeros(local_state[name].size(0) - param.size(0), dtype=param.dtype)), + 0) + else: + n1, c1, h, w = local_state[name].shape + n2, c2, h, w = param.shape + param = torch.cat((param, torch.zeros(n2, c1 - c2, h, w, dtype=param.dtype)), 1) + checkpoint[name] = torch.cat((param, torch.zeros(n1 - n2, c1, h, w, dtype=param.dtype)), 0) + return checkpoint + + +if __name__ == '__main__': + if args.optimizer: + checkpoint = optimizer(model, checkpoint) + model.load_state_dict(checkpoint) + model.eval() + + inputs = torch.rand(1, 3, 224, 224) + torch.onnx.export(model, inputs, args.output, + input_names=["x"], output_names=["output"], + dynamic_axes={"x": {0: "-1"}}, opset_version=11) diff --git a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/vision_metric_ImageNet.py b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/vision_metric_ImageNet.py index 183db2eddaa4f19986b8028b371ea9f51c9c4ba0..6542f9e50c17f6d4045c27ea7be84edaeb925e5a 100644 --- a/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/vision_metric_ImageNet.py +++ b/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch/vision_metric_ImageNet.py @@ -1,177 +1,177 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = "" - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = "" + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) diff --git a/ACL_PyTorch/built-in/cv/ResNeXt50_for_Pytorch/ReadMe.md b/ACL_PyTorch/built-in/cv/ResNeXt50_for_Pytorch/ReadMe.md index 0c3fb44c828a7631c73aa27685e8e2548abaf932..64dc33b67d3f17d7e26ca31dee6e7aae0ed4a88b 100644 --- a/ACL_PyTorch/built-in/cv/ResNeXt50_for_Pytorch/ReadMe.md +++ b/ACL_PyTorch/built-in/cv/ResNeXt50_for_Pytorch/ReadMe.md @@ -1,62 +1,62 @@ -文件作用说明: - -1.resnext50_pth2onnx.py:用于转换pth模型文件到onnx模型文件 - -2.resnext50_atc.sh:onnx模型转换om模型脚本 - -3.preprocess_resnext50_pth.py:数据集预处理脚本,通过均值方差处理归一化图片,生成图片二进制文件 - -4.aipp_resnext50_pth.config:数据集aipp预处理配置文件 - -5.get_info.py:生成推理输入的数据集二进制info文件或jpg info文件 - -6.resnext50_val.info:ImageNet验证集二进制info文件,用于benchmark推理获取数据集 - -7.ImageNet.info:ImageNet验证集jpg info文件,用于benchmark推理获取数据集 - -8.val_label.txt:ImageNet数据集标签,用于验证推理结果 - -9.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer - -10.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy - - - - - -推理端到端步骤: - -(1) 从Torchvision下载resnext50模型,通过resnext50_pth2onnx.py脚本转化为onnx模型 - - - -(2)运行resnext50_atc.sh脚本转换om模型 - -本demo已提供调优完成的om模型 - - - -(3)用preprocess_resnext50_pth.py脚本处理数据集,参考resnext50_val.info配置处理后的二进制数据集路径。或者配置数据集aipp预处理文件aipp_resnext50_pth.config。 - python3 preprocess_resnext50_pth.py dataset/ImageNet/val_union/ pre_bin - - - -(4)生成推理输入的数据集二进制info文件或jpg info文件 - python3 get_info.py bin pre_bin resnext50_val.info 224 224 - python3 get_info.py jpg dataset/ImageNet/val_union ImageNet.info - - - -(5)使用benchmark离线推理 - ./benchmark -model_type=vision -om_path=resnext50_bs16.om -device_id=0 -batch_size=16 -input_text_path=resnext50_val.info -input_width=224 -input_height=224 -useDvpp=false - 或者 - ./benchmark -model_type=vision -om_path=resnext50_bs1.om -device_id=0 -batch_size=1 -input_text_path=ImageNet.info -input_width=256 -input_height=256 -useDvpp=true - -运行benchmark推理,结果保存在 ./result 目录下 - - - -(6)python3.7 vision_metric_ImageNet.py result/dumpOutput_device0/ ./val_label.txt ./ result.json - -验证推理结果 - +文件作用说明: + +1.resnext50_pth2onnx.py:用于转换pth模型文件到onnx模型文件 + +2.resnext50_atc.sh:onnx模型转换om模型脚本 + +3.preprocess_resnext50_pth.py:数据集预处理脚本,通过均值方差处理归一化图片,生成图片二进制文件 + +4.aipp_resnext50_pth.config:数据集aipp预处理配置文件 + +5.get_info.py:生成推理输入的数据集二进制info文件或jpg info文件 + +6.resnext50_val.info:ImageNet验证集二进制info文件,用于benchmark推理获取数据集 + +7.ImageNet.info:ImageNet验证集jpg info文件,用于benchmark推理获取数据集 + +8.val_label.txt:ImageNet数据集标签,用于验证推理结果 + +9.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer + +10.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy + + + + + +推理端到端步骤: + +(1) 从Torchvision下载resnext50模型,通过resnext50_pth2onnx.py脚本转化为onnx模型 + + + +(2)运行resnext50_atc.sh脚本转换om模型 + +本demo已提供调优完成的om模型 + + + +(3)用preprocess_resnext50_pth.py脚本处理数据集,参考resnext50_val.info配置处理后的二进制数据集路径。或者配置数据集aipp预处理文件aipp_resnext50_pth.config。 + python3 preprocess_resnext50_pth.py dataset/ImageNet/val_union/ pre_bin + + + +(4)生成推理输入的数据集二进制info文件或jpg info文件 + python3 get_info.py bin pre_bin resnext50_val.info 224 224 + python3 get_info.py jpg dataset/ImageNet/val_union ImageNet.info + + + +(5)使用benchmark离线推理 + ./benchmark -model_type=vision -om_path=resnext50_bs16.om -device_id=0 -batch_size=16 -input_text_path=resnext50_val.info -input_width=224 -input_height=224 -useDvpp=false + 或者 + ./benchmark -model_type=vision -om_path=resnext50_bs1.om -device_id=0 -batch_size=1 -input_text_path=ImageNet.info -input_width=256 -input_height=256 -useDvpp=true + +运行benchmark推理,结果保存在 ./result 目录下 + + + +(6)python3.7 vision_metric_ImageNet.py result/dumpOutput_device0/ ./val_label.txt ./ result.json + +验证推理结果 + diff --git a/ACL_PyTorch/built-in/cv/ResNeXt50_for_Pytorch/get_info.py b/ACL_PyTorch/built-in/cv/ResNeXt50_for_Pytorch/get_info.py index 0578e4f00cd9661c6dcfa7db7b72f196677ff422..7b14c54b909b60730e9e3471ee0435ee4cb8622f 100644 --- a/ACL_PyTorch/built-in/cv/ResNeXt50_for_Pytorch/get_info.py +++ b/ACL_PyTorch/built-in/cv/ResNeXt50_for_Pytorch/get_info.py @@ -1,46 +1,46 @@ -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/ResNeXt50_for_Pytorch/preprocess_resnext50_pth.py b/ACL_PyTorch/built-in/cv/ResNeXt50_for_Pytorch/preprocess_resnext50_pth.py index 04f41f75979bcbc2ca8c939b37b29d8a59f8d22a..965681f30d9a5413948b7fb1cdd158d1ac2e5e22 100644 --- a/ACL_PyTorch/built-in/cv/ResNeXt50_for_Pytorch/preprocess_resnext50_pth.py +++ b/ACL_PyTorch/built-in/cv/ResNeXt50_for_Pytorch/preprocess_resnext50_pth.py @@ -1,85 +1,85 @@ -import os -import sys -import numpy as np -from PIL import Image - - -def resize(img, size, interpolation=Image.BILINEAR): - r"""Resize the input PIL Image to the given size. - - Args: - img (PIL Image): Image to be resized. - size (sequence or int): Desired output size. If size is a sequence like - (h, w), the output size will be matched to this. If size is an int, - the smaller edge of the image will be matched to this number maintaining - the aspect ratio. i.e, if height > width, then image will be rescaled to - :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)` - interpolation (int, optional): Desired interpolation. Default is - ``PIL.Image.BILINEAR`` - - Returns: - PIL Image: Resized image. - """ - - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def center_crop(img, out_height, out_width): - height, width, _ = img.shape - left = int((width - out_width) / 2) - right = int((width + out_width) / 2) - top = int((height - out_height) / 2) - bottom = int((height + out_height) / 2) - img = img[top:bottom, left:right] - return img - - -def preprocess(file_path, bin_path): - in_files = os.listdir(file_path) - if not os.path.exists(bin_path): - os.makedirs(bin_path) - i = 0 - - resize_size = 256 - mean = [0.485, 0.456, 0.406] - std = [0.229, 0.224, 0.225] - - for file in in_files: - i = i + 1 - print(file, "===", i) - - img = Image.open(os.path.join(file_path, file)).convert('RGB') - - img = resize(img, resize_size) # transforms.Resize(256) - img = np.array(img, dtype=np.float32) - img = center_crop(img, 224, 224) # transforms.CenterCrop(224) - img = img / 255. # transforms.ToTensor() - # 均值方差 - img[..., 0] -= mean[0] - img[..., 1] -= mean[1] - img[..., 2] -= mean[2] - img[..., 0] /= std[0] - img[..., 1] /= std[1] - img[..., 2] /= std[2] - img = img.transpose(2, 0, 1) # HWC -> CHW - - img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) - - -if __name__ == "__main__": - file_path = os.path.abspath(sys.argv[1]) - bin_path = os.path.abspath(sys.argv[2]) - preprocess(file_path, bin_path) +import os +import sys +import numpy as np +from PIL import Image + + +def resize(img, size, interpolation=Image.BILINEAR): + r"""Resize the input PIL Image to the given size. + + Args: + img (PIL Image): Image to be resized. + size (sequence or int): Desired output size. If size is a sequence like + (h, w), the output size will be matched to this. If size is an int, + the smaller edge of the image will be matched to this number maintaining + the aspect ratio. i.e, if height > width, then image will be rescaled to + :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)` + interpolation (int, optional): Desired interpolation. Default is + ``PIL.Image.BILINEAR`` + + Returns: + PIL Image: Resized image. + """ + + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def center_crop(img, out_height, out_width): + height, width, _ = img.shape + left = int((width - out_width) / 2) + right = int((width + out_width) / 2) + top = int((height - out_height) / 2) + bottom = int((height + out_height) / 2) + img = img[top:bottom, left:right] + return img + + +def preprocess(file_path, bin_path): + in_files = os.listdir(file_path) + if not os.path.exists(bin_path): + os.makedirs(bin_path) + i = 0 + + resize_size = 256 + mean = [0.485, 0.456, 0.406] + std = [0.229, 0.224, 0.225] + + for file in in_files: + i = i + 1 + print(file, "===", i) + + img = Image.open(os.path.join(file_path, file)).convert('RGB') + + img = resize(img, resize_size) # transforms.Resize(256) + img = np.array(img, dtype=np.float32) + img = center_crop(img, 224, 224) # transforms.CenterCrop(224) + img = img / 255. # transforms.ToTensor() + # 均值方差 + img[..., 0] -= mean[0] + img[..., 1] -= mean[1] + img[..., 2] -= mean[2] + img[..., 0] /= std[0] + img[..., 1] /= std[1] + img[..., 2] /= std[2] + img = img.transpose(2, 0, 1) # HWC -> CHW + + img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) + + +if __name__ == "__main__": + file_path = os.path.abspath(sys.argv[1]) + bin_path = os.path.abspath(sys.argv[2]) + preprocess(file_path, bin_path) diff --git a/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/ReadMe.md b/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/ReadMe.md index b89cfb0e6e79831f8da11db45d48085a48276ca1..285adc2feccb00acf368c919818782466573e39b 100644 --- a/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/ReadMe.md +++ b/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/ReadMe.md @@ -1,381 +1,381 @@ -# ResNet101 Onnx模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx模型量化](#32-onnx模型量化) - - [3.3 onnx转om模型](#33-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) - - [6.2 开源TopN精度](#62-开源TopN精度) - - [6.3 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - [7.2 T4性能数据](#72-T4性能数据) - - [7.3 性能对比](#73-性能对比) - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[ResNet101论文](https://arxiv.org/pdf/1512.03385.pdf) - -### 1.2 代码地址 -[ResNet101代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) -branch:master -commit_id:7d955df73fe0e9b47f7d6c77c699324b256fc41f - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 -``` -CANN 5.0.4 - -torch == 1.5.1 -torchvision == 0.6.1 -onnx == 1.9.0 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.19.2 -Pillow == 8.2.0 -opencv-python == 4.5.2 -``` - -**说明:** -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 - -1.下载pth权重文件 -请参考[pytorch原始仓](https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py)给出的ResNet101权重文件下载地址获取权重文件:resnet101-63fe2227.pth - -2.ResNet101模型代码在torchvision里,安装torchvision,arm下需源码安装,参考torchvision官网,若安装过程报错请百度解决 - -``` -git clone https://github.com/pytorch/vision -cd vision -python3.7 setup.py install -cd .. -``` -3.编写pth2onnx脚本resnet101_pth2onnx.py - - **说明:** ->注意目前ATC支持的onnx算子版本为11 - -4.执行pth2onnx脚本,生成onnx模型文件 -``` -python3.7 resnet101_pth2onnx.py ./resnet101-63fe2227.pth resnet101.onnx -``` - - **模型转换要点:** ->此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 - -### 3.2 onnx模型量化 - -1.AMCT工具包安装,具体参考《[CANN 开发辅助工具指南 01](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools)》中的昇腾模型压缩工具使用指南(ONNX)章节; - -2.生成bin格式数据集,数据集用于校正量化因子。当前模型为动态batch,建议使用较大的batch size: - -``` -python3.7 gen_calibration_bin.py resnet /root/datasets/imagenet/val ./calibration_bin 32 1 -``` - -参数说明: - -- resnet:模型类型 -- /root/datasets/imagenet/val:模型使用的数据集路径; -- ./calibration_bin:生成的bin格式数据集路径; -- 32:batch size; -- 1:batch num。 - -3.ONNX模型量化 - -``` -amct_onnx calibration --model resnet101.onnx --save_path ./result/resnet101 --input_shape "image:32,3,224,224" --data_dir "./calibration_bin" --data_types "float32" -``` - -会在result目录下生成resnet101_deploy_model.onnx量化模型 - -4.量化模型后续的推理验证流程和非量化一致。 - -### 3.3 onnx转om模型 - -1.设置环境变量 - -``` -source env.sh -``` -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考《[CANN 开发辅助工具指南 01](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools)》中的ATC工具使用指南章节 - -``` -atc --framework=5 --model=./resnet101.onnx --output=resnet101_bs16 --input_format=NCHW --input_shape="image:16,3,224,224" --log=debug --soc_version=Ascend310 --insert_op_conf=aipp.config -``` - -**说明:** - -> 若设备类型为Ascend710,设置soc_version==Ascend710即可; -> -> aipp.config是AIPP工具数据集预处理配置文件,详细说明可参考"ATC工具使用指南"中的"AIPP配置"章节。 - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -该模型使用ImageNet的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 - -### 4.2 数据集预处理 - -1.预处理脚本imagenet_torch_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 -``` -python3.7 imagenet_torch_preprocess.py resnet /root/datasets/imagenet/val ./prep_dataset -``` -### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本gen_dataset_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 -``` -python3.7 gen_dataset_info.py bin ./prep_dataset ./resnet101_prep_bin.info 224 224 -``` -第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310、710上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考《[CANN 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools)》 -### 5.2 离线推理 -1.设置环境变量 -``` -source env.sh -``` -2.执行离线推理 -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=resnet101_bs16.om -input_text_path=./resnet101_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False -``` -输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 - -## 6 精度对比 - -- **[离线推理TopN精度](#61-离线推理TopN精度)** -- **[开源TopN精度](#62-开源TopN精度)** -- **[精度对比](#63-精度对比)** - -### 6.1 离线推理TopN精度统计 - -后处理统计TopN精度 - -调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 -``` -python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /root/datasets/imagenet/val_label.txt ./ result.json -``` -第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 -查看输出结果: -``` -{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "77.37%"}, {"key": "Top2 accuracy", "value": "87.1%"}, {"key": "Top3 accuracy", "value": "90.61%"}, {"key": "Top4 accuracy", "value": "92.42%"}, {"key": "Top5 accuracy", "value": "93.54%"}]} -``` -经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 - -### 6.2 开源TopN精度 -[torchvision官网精度](https://pytorch.org/vision/stable/models.html) -``` -Model Acc@1 Acc@5 -ResNet-101 77.374 93.546 -``` -### 6.3 精度对比 -将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 - **精度调试:** ->没有遇到精度不达标的问题,故不需要进行精度调试 - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** -- **[T4性能数据](#72-T4性能数据)** -- **[性能对比](#73-性能对比)** - -### 7.1 npu性能数据 -benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 -1.benchmark工具在整个数据集上推理获得性能数据 (Ascend310) -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: -``` -[e2e] throughputRate: 170.628, latency: 293035 -[data read] throughputRate: 181.571, moduleLatency: 5.50749 -[preprocess] throughputRate: 180.466, moduleLatency: 5.5412 -[infer] throughputRate: 171.595, Interface throughputRate: 247.898, moduleLatency: 5.12562 -[post] throughputRate: 171.595, moduleLatency: 5.82768 -``` -Interface throughputRate: 247.898,247.898x4=991.592既是batch1 310单卡吞吐率 -batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: -``` -[e2e] throughputRate: 185.903, latency: 268957 -[data read] throughputRate: 191.266, moduleLatency: 5.22833 -[preprocess] throughputRate: 190.761, moduleLatency: 5.24217 -[infer] throughputRate: 187.131, Interface throughputRate: 401.046, moduleLatency: 3.94051 -[post] throughputRate: 11.6954, moduleLatency: 85.5035 -``` -Interface throughputRate: 401.046,401.046x4=1604.184既是batch16 310单卡吞吐率 -batch4的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_4_device_0.txt: -``` -[e2e] throughputRate: 184.444, latency: 271085 -[data read] throughputRate: 196.412, moduleLatency: 5.09134 -[preprocess] throughputRate: 195.837, moduleLatency: 5.1063 -[infer] throughputRate: 185.624, Interface throughputRate: 331.096, moduleLatency: 4.52436 -[post] throughputRate: 46.4056, moduleLatency: 21.5491 -``` -Interface throughputRate: 331.096,331.096x4=1324.384既是batch4 310单卡吞吐率 -batch8的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_8_device_0.txt: -``` -[e2e] throughputRate: 196.051, latency: 255036 -[data read] throughputRate: 209.29, moduleLatency: 4.77806 -[preprocess] throughputRate: 207.914, moduleLatency: 4.80969 -[infer] throughputRate: 197.513, Interface throughputRate: 371.905, moduleLatency: 4.15513 -[post] throughputRate: 24.6888, moduleLatency: 40.5042 -``` -Interface throughputRate: 371.905,371.905x4=1487.62既是batch8 310单卡吞吐率 -batch32的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_32_device_0.txt: -``` -[e2e] throughputRate: 176.215, latency: 283744 -[data read] throughputRate: 187.024, moduleLatency: 5.34691 -[preprocess] throughputRate: 186.183, moduleLatency: 5.37105 -[infer] throughputRate: 177.675, Interface throughputRate: 370.456, moduleLatency: 4.14361 -[post] throughputRate: 5.55402, moduleLatency: 180.05 - -``` -Interface throughputRate: 370.456,370.456x4=1481.82既是batch32 310单卡吞吐率 - - **说明:** - -> 注意如果设备为Ascend710,则Interface throughputRate的值就是710的单卡吞吐率,不需要像310那样x4 - -### 7.2 T4性能数据 -在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2 -batch1性能: -``` -trtexec --onnx=resnet101.onnx --fp16 --shapes=image:1x3x224x224 --threads -``` -gpu T4是4个device并行执行的结果,mean是时延(tensorrt的时延是batch个数据的推理时间),即吞吐率的倒数乘以batch -``` -[06/10/2021-17:40:51] [I] GPU Compute -[06/10/2021-17:40:51] [I] min: 2.01935 ms -[06/10/2021-17:40:51] [I] max: 3.53485 ms -[06/10/2021-17:40:51] [I] mean: 2.1015 ms -[06/10/2021-17:40:51] [I] median: 2.07254 ms -[06/10/2021-17:40:51] [I] percentile: 3.52882 ms at 99% -[06/10/2021-17:40:51] [I] total compute time: 2.99674 s - -``` -batch1 t4单卡吞吐率:1000/(2.1015/1)=475.851fps - -batch16性能: -``` -trtexec --onnx=resnet101.onnx --fp16 --shapes=image:16x3x224x224 --threads -``` -``` -[06/10/2021-17:42:06] [I] GPU Compute -[06/10/2021-17:42:06] [I] min: 13.8094 ms -[06/10/2021-17:42:06] [I] max: 24.5842 ms -[06/10/2021-17:42:06] [I] mean: 14.5182 ms -[06/10/2021-17:42:06] [I] median: 14.4042 ms -[06/10/2021-17:42:06] [I] percentile: 15.7213 ms at 99% -[06/10/2021-17:42:06] [I] total compute time: 3.03431 s - -``` -batch16 t4单卡吞吐率:1000/(14.5182/16)=1102.065fps - -batch4性能: -``` -trtexec --onnx=resnet101.onnx --fp16 --shapes=image:4x3x224x224 --threads -``` -``` -[06/11/2021-12:47:51] [I] GPU Compute -[06/11/2021-12:47:51] [I] min: 4.27863 ms -[06/11/2021-12:47:51] [I] max: 6.56378 ms -[06/11/2021-12:47:51] [I] mean: 4.52613 ms -[06/11/2021-12:47:51] [I] median: 4.49536 ms -[06/11/2021-12:47:51] [I] percentile: 6.54581 ms at 99% -[06/11/2021-12:47:51] [I] total compute time: 3.00535 s - -``` -batch4 t4单卡吞吐率:1000/(4.52613/4)=883.7572054fps - -batch8性能: -``` -trtexec --onnx=resnet101.onnx --fp16 --shapes=image:8x3x224x224 --threads -``` -``` -[06/11/2021-12:49:50] [I] GPU Compute -[06/11/2021-12:49:50] [I] min: 7.38504 ms -[06/11/2021-12:49:50] [I] max: 8.36267 ms -[06/11/2021-12:49:50] [I] mean: 7.73195 ms -[06/11/2021-12:49:50] [I] median: 7.68652 ms -[06/11/2021-12:49:50] [I] percentile: 8.33948 ms at 99% -[06/11/2021-12:49:50] [I] total compute time: 3.00773 s - -``` -batch8 t4单卡吞吐率:1000/(7.73195/8)=1034.667839fps - -batch32性能: -``` -trtexec --onnx=resnet101.onnx --fp16 --shapes=image:32x3x224x224 --threads -``` -``` -[06/11/2021-12:52:51] [I] GPU Compute -[06/11/2021-12:52:51] [I] min: 24.7151 ms -[06/11/2021-12:52:51] [I] max: 34.8919 ms -[06/11/2021-12:52:51] [I] mean: 25.7435 ms -[06/11/2021-12:52:51] [I] median: 25.4695 ms -[06/11/2021-12:52:51] [I] percentile: 33.3713 ms at 99% -[06/11/2021-12:52:51] [I] total compute time: 3.03773 s - -``` -batch32 t4单卡吞吐率:1000/(25.7435/32)=1243.032222fps - -### 7.3 性能对比 -batch1:247.898x4 > 1000/(2.1015/1) -batch16:401.046x4 > 1000/(14.5182/16) -batch4,8,32的npu性能也都大于T4 -310单个device的吞吐率乘4即单卡吞吐率比T4单卡的吞吐率大,故310性能高于T4性能,性能达标。 -对于batch1的310性能高于T4性能2.08倍,batch16的310性能高于T4性能1.46倍,对于batch1与batch16,310性能均高于T4性能1.2倍,该模型放在Benchmark/cv/classification目录下。 - -710单卡吞吐率要求最优batchsize情况下为310的1.5倍,当前已符合要求,具体数据不在此赘述。 - +# ResNet101 Onnx模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx模型量化](#32-onnx模型量化) + - [3.3 onnx转om模型](#33-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) + - [6.2 开源TopN精度](#62-开源TopN精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + - [7.2 T4性能数据](#72-T4性能数据) + - [7.3 性能对比](#73-性能对比) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[ResNet101论文](https://arxiv.org/pdf/1512.03385.pdf) + +### 1.2 代码地址 +[ResNet101代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) +branch:master +commit_id:7d955df73fe0e9b47f7d6c77c699324b256fc41f + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +CANN 5.0.4 + +torch == 1.5.1 +torchvision == 0.6.1 +onnx == 1.9.0 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.19.2 +Pillow == 8.2.0 +opencv-python == 4.5.2 +``` + +**说明:** +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 + +1.下载pth权重文件 +请参考[pytorch原始仓](https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py)给出的ResNet101权重文件下载地址获取权重文件:resnet101-63fe2227.pth + +2.ResNet101模型代码在torchvision里,安装torchvision,arm下需源码安装,参考torchvision官网,若安装过程报错请百度解决 + +``` +git clone https://github.com/pytorch/vision +cd vision +python3.7 setup.py install +cd .. +``` +3.编写pth2onnx脚本resnet101_pth2onnx.py + + **说明:** +>注意目前ATC支持的onnx算子版本为11 + +4.执行pth2onnx脚本,生成onnx模型文件 +``` +python3.7 resnet101_pth2onnx.py ./resnet101-63fe2227.pth resnet101.onnx +``` + + **模型转换要点:** +>此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 + +### 3.2 onnx模型量化 + +1.AMCT工具包安装,具体参考《[CANN 开发辅助工具指南 01](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools)》中的昇腾模型压缩工具使用指南(ONNX)章节; + +2.生成bin格式数据集,数据集用于校正量化因子。当前模型为动态batch,建议使用较大的batch size: + +``` +python3.7 gen_calibration_bin.py resnet /root/datasets/imagenet/val ./calibration_bin 32 1 +``` + +参数说明: + +- resnet:模型类型 +- /root/datasets/imagenet/val:模型使用的数据集路径; +- ./calibration_bin:生成的bin格式数据集路径; +- 32:batch size; +- 1:batch num。 + +3.ONNX模型量化 + +``` +amct_onnx calibration --model resnet101.onnx --save_path ./result/resnet101 --input_shape "image:32,3,224,224" --data_dir "./calibration_bin" --data_types "float32" +``` + +会在result目录下生成resnet101_deploy_model.onnx量化模型 + +4.量化模型后续的推理验证流程和非量化一致。 + +### 3.3 onnx转om模型 + +1.设置环境变量 + +``` +source env.sh +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考《[CANN 开发辅助工具指南 01](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools)》中的ATC工具使用指南章节 + +``` +atc --framework=5 --model=./resnet101.onnx --output=resnet101_bs16 --input_format=NCHW --input_shape="image:16,3,224,224" --log=debug --soc_version=Ascend310 --insert_op_conf=aipp.config +``` + +**说明:** + +> 若设备类型为Ascend710,设置soc_version==Ascend710即可; +> +> aipp.config是AIPP工具数据集预处理配置文件,详细说明可参考"ATC工具使用指南"中的"AIPP配置"章节。 + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用ImageNet的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 + +### 4.2 数据集预处理 + +1.预处理脚本imagenet_torch_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 +``` +python3.7 imagenet_torch_preprocess.py resnet /root/datasets/imagenet/val ./prep_dataset +``` +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本gen_dataset_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 +``` +python3.7 gen_dataset_info.py bin ./prep_dataset ./resnet101_prep_bin.info 224 224 +``` +第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310、710上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考《[CANN 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools)》 +### 5.2 离线推理 +1.设置环境变量 +``` +source env.sh +``` +2.执行离线推理 +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=resnet101_bs16.om -input_text_path=./resnet101_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +``` +输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 + +## 6 精度对比 + +- **[离线推理TopN精度](#61-离线推理TopN精度)** +- **[开源TopN精度](#62-开源TopN精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理TopN精度统计 + +后处理统计TopN精度 + +调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 +``` +python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /root/datasets/imagenet/val_label.txt ./ result.json +``` +第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 +查看输出结果: +``` +{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "77.37%"}, {"key": "Top2 accuracy", "value": "87.1%"}, {"key": "Top3 accuracy", "value": "90.61%"}, {"key": "Top4 accuracy", "value": "92.42%"}, {"key": "Top5 accuracy", "value": "93.54%"}]} +``` +经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 + +### 6.2 开源TopN精度 +[torchvision官网精度](https://pytorch.org/vision/stable/models.html) +``` +Model Acc@1 Acc@5 +ResNet-101 77.374 93.546 +``` +### 6.3 精度对比 +将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + **精度调试:** +>没有遇到精度不达标的问题,故不需要进行精度调试 + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** +- **[T4性能数据](#72-T4性能数据)** +- **[性能对比](#73-性能对比)** + +### 7.1 npu性能数据 +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 +1.benchmark工具在整个数据集上推理获得性能数据 (Ascend310) +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: +``` +[e2e] throughputRate: 170.628, latency: 293035 +[data read] throughputRate: 181.571, moduleLatency: 5.50749 +[preprocess] throughputRate: 180.466, moduleLatency: 5.5412 +[infer] throughputRate: 171.595, Interface throughputRate: 247.898, moduleLatency: 5.12562 +[post] throughputRate: 171.595, moduleLatency: 5.82768 +``` +Interface throughputRate: 247.898,247.898x4=991.592既是batch1 310单卡吞吐率 +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: +``` +[e2e] throughputRate: 185.903, latency: 268957 +[data read] throughputRate: 191.266, moduleLatency: 5.22833 +[preprocess] throughputRate: 190.761, moduleLatency: 5.24217 +[infer] throughputRate: 187.131, Interface throughputRate: 401.046, moduleLatency: 3.94051 +[post] throughputRate: 11.6954, moduleLatency: 85.5035 +``` +Interface throughputRate: 401.046,401.046x4=1604.184既是batch16 310单卡吞吐率 +batch4的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_4_device_0.txt: +``` +[e2e] throughputRate: 184.444, latency: 271085 +[data read] throughputRate: 196.412, moduleLatency: 5.09134 +[preprocess] throughputRate: 195.837, moduleLatency: 5.1063 +[infer] throughputRate: 185.624, Interface throughputRate: 331.096, moduleLatency: 4.52436 +[post] throughputRate: 46.4056, moduleLatency: 21.5491 +``` +Interface throughputRate: 331.096,331.096x4=1324.384既是batch4 310单卡吞吐率 +batch8的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_8_device_0.txt: +``` +[e2e] throughputRate: 196.051, latency: 255036 +[data read] throughputRate: 209.29, moduleLatency: 4.77806 +[preprocess] throughputRate: 207.914, moduleLatency: 4.80969 +[infer] throughputRate: 197.513, Interface throughputRate: 371.905, moduleLatency: 4.15513 +[post] throughputRate: 24.6888, moduleLatency: 40.5042 +``` +Interface throughputRate: 371.905,371.905x4=1487.62既是batch8 310单卡吞吐率 +batch32的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_32_device_0.txt: +``` +[e2e] throughputRate: 176.215, latency: 283744 +[data read] throughputRate: 187.024, moduleLatency: 5.34691 +[preprocess] throughputRate: 186.183, moduleLatency: 5.37105 +[infer] throughputRate: 177.675, Interface throughputRate: 370.456, moduleLatency: 4.14361 +[post] throughputRate: 5.55402, moduleLatency: 180.05 + +``` +Interface throughputRate: 370.456,370.456x4=1481.82既是batch32 310单卡吞吐率 + + **说明:** + +> 注意如果设备为Ascend710,则Interface throughputRate的值就是710的单卡吞吐率,不需要像310那样x4 + +### 7.2 T4性能数据 +在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2 +batch1性能: +``` +trtexec --onnx=resnet101.onnx --fp16 --shapes=image:1x3x224x224 --threads +``` +gpu T4是4个device并行执行的结果,mean是时延(tensorrt的时延是batch个数据的推理时间),即吞吐率的倒数乘以batch +``` +[06/10/2021-17:40:51] [I] GPU Compute +[06/10/2021-17:40:51] [I] min: 2.01935 ms +[06/10/2021-17:40:51] [I] max: 3.53485 ms +[06/10/2021-17:40:51] [I] mean: 2.1015 ms +[06/10/2021-17:40:51] [I] median: 2.07254 ms +[06/10/2021-17:40:51] [I] percentile: 3.52882 ms at 99% +[06/10/2021-17:40:51] [I] total compute time: 2.99674 s + +``` +batch1 t4单卡吞吐率:1000/(2.1015/1)=475.851fps + +batch16性能: +``` +trtexec --onnx=resnet101.onnx --fp16 --shapes=image:16x3x224x224 --threads +``` +``` +[06/10/2021-17:42:06] [I] GPU Compute +[06/10/2021-17:42:06] [I] min: 13.8094 ms +[06/10/2021-17:42:06] [I] max: 24.5842 ms +[06/10/2021-17:42:06] [I] mean: 14.5182 ms +[06/10/2021-17:42:06] [I] median: 14.4042 ms +[06/10/2021-17:42:06] [I] percentile: 15.7213 ms at 99% +[06/10/2021-17:42:06] [I] total compute time: 3.03431 s + +``` +batch16 t4单卡吞吐率:1000/(14.5182/16)=1102.065fps + +batch4性能: +``` +trtexec --onnx=resnet101.onnx --fp16 --shapes=image:4x3x224x224 --threads +``` +``` +[06/11/2021-12:47:51] [I] GPU Compute +[06/11/2021-12:47:51] [I] min: 4.27863 ms +[06/11/2021-12:47:51] [I] max: 6.56378 ms +[06/11/2021-12:47:51] [I] mean: 4.52613 ms +[06/11/2021-12:47:51] [I] median: 4.49536 ms +[06/11/2021-12:47:51] [I] percentile: 6.54581 ms at 99% +[06/11/2021-12:47:51] [I] total compute time: 3.00535 s + +``` +batch4 t4单卡吞吐率:1000/(4.52613/4)=883.7572054fps + +batch8性能: +``` +trtexec --onnx=resnet101.onnx --fp16 --shapes=image:8x3x224x224 --threads +``` +``` +[06/11/2021-12:49:50] [I] GPU Compute +[06/11/2021-12:49:50] [I] min: 7.38504 ms +[06/11/2021-12:49:50] [I] max: 8.36267 ms +[06/11/2021-12:49:50] [I] mean: 7.73195 ms +[06/11/2021-12:49:50] [I] median: 7.68652 ms +[06/11/2021-12:49:50] [I] percentile: 8.33948 ms at 99% +[06/11/2021-12:49:50] [I] total compute time: 3.00773 s + +``` +batch8 t4单卡吞吐率:1000/(7.73195/8)=1034.667839fps + +batch32性能: +``` +trtexec --onnx=resnet101.onnx --fp16 --shapes=image:32x3x224x224 --threads +``` +``` +[06/11/2021-12:52:51] [I] GPU Compute +[06/11/2021-12:52:51] [I] min: 24.7151 ms +[06/11/2021-12:52:51] [I] max: 34.8919 ms +[06/11/2021-12:52:51] [I] mean: 25.7435 ms +[06/11/2021-12:52:51] [I] median: 25.4695 ms +[06/11/2021-12:52:51] [I] percentile: 33.3713 ms at 99% +[06/11/2021-12:52:51] [I] total compute time: 3.03773 s + +``` +batch32 t4单卡吞吐率:1000/(25.7435/32)=1243.032222fps + +### 7.3 性能对比 +batch1:247.898x4 > 1000/(2.1015/1) +batch16:401.046x4 > 1000/(14.5182/16) +batch4,8,32的npu性能也都大于T4 +310单个device的吞吐率乘4即单卡吞吐率比T4单卡的吞吐率大,故310性能高于T4性能,性能达标。 +对于batch1的310性能高于T4性能2.08倍,batch16的310性能高于T4性能1.46倍,对于batch1与batch16,310性能均高于T4性能1.2倍,该模型放在Benchmark/cv/classification目录下。 + +710单卡吞吐率要求最优batchsize情况下为310的1.5倍,当前已符合要求,具体数据不在此赘述。 + diff --git a/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/gen_dataset_info.py b/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/gen_dataset_info.py index 61450b4410663ae5e66ec29ed296ff6584203e31..5381839f653a885666e3fc456db9a1c22b8583a1 100644 --- a/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/gen_dataset_info.py +++ b/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/gen_dataset_info.py @@ -1,61 +1,61 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) + diff --git a/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/imagenet_acc_eval.py b/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/imagenet_acc_eval.py index 362f2484e8288dd3df6fa212678dc9449dbbed29..583340a19f2fc6e99faed85526c906f8bd12d7ba 100644 --- a/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/imagenet_acc_eval.py +++ b/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/imagenet_acc_eval.py @@ -1,184 +1,184 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - if data == '': - n_label = 0 - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - print("Time used:", elapsed) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) + diff --git a/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/imagenet_torch_preprocess.py b/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/imagenet_torch_preprocess.py index ed4b4e2a5380e3ee608287596412963d92b9bb79..6f89d347b52642cc3a1fc8ba73dae2d4230e7a0c 100644 --- a/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/imagenet_torch_preprocess.py +++ b/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/imagenet_torch_preprocess.py @@ -1,113 +1,113 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from PIL import Image -import numpy as np -import multiprocessing - - -model_config = { - 'resnet': { - 'resize': 256, - 'centercrop': 224, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv3': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv4': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.5, 0.5, 0.5], - 'std': [0.5, 0.5, 0.5], - }, -} - - -def center_crop(img, output_size): - if isinstance(output_size, int): - output_size = (int(output_size), int(output_size)) - image_width, image_height = img.size - crop_height, crop_width = output_size - crop_top = int(round((image_height - crop_height) / 2.)) - crop_left = int(round((image_width - crop_width) / 2.)) - return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) - - -def resize(img, size, interpolation=Image.BILINEAR): - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def gen_input_bin(mode_type, file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - # RGBA to RGB - image = Image.open(os.path.join(src_path, file)).convert('RGB') - image = resize(image, model_config[mode_type]['resize']) # Resize - image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop - img = np.array(image, dtype=np.int8) - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - - -def preprocess(mode_type, src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") - mode_type = sys.argv[1] - src_path = sys.argv[2] - save_path = sys.argv[3] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - if mode_type not in model_config: - model_type_help = "model type: " - for key in model_config.keys(): - model_type_help += key - model_type_help += ' ' - raise Exception(model_type_help) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - preprocess(mode_type, src_path, save_path) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from PIL import Image +import numpy as np +import multiprocessing + + +model_config = { + 'resnet': { + 'resize': 256, + 'centercrop': 224, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv3': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv4': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.5, 0.5, 0.5], + 'std': [0.5, 0.5, 0.5], + }, +} + + +def center_crop(img, output_size): + if isinstance(output_size, int): + output_size = (int(output_size), int(output_size)) + image_width, image_height = img.size + crop_height, crop_width = output_size + crop_top = int(round((image_height - crop_height) / 2.)) + crop_left = int(round((image_width - crop_width) / 2.)) + return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) + + +def resize(img, size, interpolation=Image.BILINEAR): + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def gen_input_bin(mode_type, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + # RGBA to RGB + image = Image.open(os.path.join(src_path, file)).convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.int8) + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +def preprocess(mode_type, src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") + mode_type = sys.argv[1] + src_path = sys.argv[2] + save_path = sys.argv[3] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if mode_type not in model_config: + model_type_help = "model type: " + for key in model_config.keys(): + model_type_help += key + model_type_help += ' ' + raise Exception(model_type_help) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess(mode_type, src_path, save_path) + diff --git a/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/requirements.txt b/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/requirements.txt index 2fc4e802c476feda2a9866a85630f7f3b29428d7..d072d9aa6f2e7a7b0044ff93d036c3c0347ee5c9 100644 --- a/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/requirements.txt +++ b/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.5.1 -torchvision == 0.6.1 -onnx == 1.9.0 -numpy == 1.19.2 -Pillow == 8.2.0 +torch == 1.5.1 +torchvision == 0.6.1 +onnx == 1.9.0 +numpy == 1.19.2 +Pillow == 8.2.0 opencv-python == 4.5.2 \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/resnet101_pth2onnx.py b/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/resnet101_pth2onnx.py index 46ab195411a21bf39c1d67d864a72ef0e7f9310f..8eff59a68086db8153e345f4956f018710ffaf7c 100644 --- a/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/resnet101_pth2onnx.py +++ b/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer/resnet101_pth2onnx.py @@ -1,35 +1,35 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import torch -import torch.onnx -import torchvision.models as models - -def pth2onnx(input_file, output_file): - model = models.resnet101(pretrained=False) - checkpoint = torch.load(input_file, map_location=None) - model.load_state_dict(checkpoint) - - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) - -if __name__ == "__main__": - input_file = sys.argv[1] - output_file = sys.argv[2] - pth2onnx(input_file, output_file) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import torch +import torch.onnx +import torchvision.models as models + +def pth2onnx(input_file, output_file): + model = models.resnet101(pretrained=False) + checkpoint = torch.load(input_file, map_location=None) + model.load_state_dict(checkpoint) + + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) + +if __name__ == "__main__": + input_file = sys.argv[1] + output_file = sys.argv[2] + pth2onnx(input_file, output_file) diff --git a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/LICENSE b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/LICENSE +++ b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/README.md b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/README.md index 9495982f9e63226d3fa8b3b0d32444de0003df2d..733721a8b2a48485a92585081f0d96b936b4ed66 100644 --- a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/README.md +++ b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/README.md @@ -1,156 +1,156 @@ -# ResNet18 Onnx模型端到端推理指导 - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[ResNet18论文](https://arxiv.org/pdf/1512.03385.pdf) - -### 1.2 代码地址 -[ResNet18代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) -branch:master -commit_id:7d955df73fe0e9b47f7d6c77c699324b256fc41f - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 -``` -CANN 5.0.3 - -torch == 1.5.1 -torchvision == 0.6.1 -onnx == 1.9.0 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.19.2 -Pillow == 8.2.0 -opencv-python == 4.5.2 -``` - -**说明:** -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 数据集预处理 - -- **[数据集获取](#31-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 3.1 数据集获取 -该模型使用ImageNet的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 - -### 3.2 数据集预处理 -1.预处理脚本imagenet_torch_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 -``` -python3.7 imagenet_torch_preprocess.py resnet /root/datasets/imagenet/val ./prep_dataset -``` -### 3.3 生成数据集信息文件 -1.生成数据集信息文件脚本gen_dataset_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 -``` -python3.7 gen_dataset_info.py bin ./prep_dataset ./resnet18_prep_bin.info 224 224 -``` -第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 - -## 4 模型推理 - -- **[pth转onnx模型](#41-pth转onnx模型)** - -- **[onnx转om模型](#42-onnx转om模型)** - -### 4.1 pth转onnx模型 - -1.下载pth权重文件 -从https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py的第26行获取对应权重下载链接,使用wget命令下载对应权重 - -文件MD5sum:e0b1c919e74f9a193d36871d9964bf7d - -2.ResNet18模型代码在torchvision里,安装torchvision,arm下需源码安装,参考torchvision官网 -``` -git clone https://github.com/pytorch/vision -cd vision -python3.7 setup.py install -cd .. -``` -3.编写pth2onnx脚本resnet18_pth2onnx.py - - **说明:** ->注意目前ATC支持的onnx算子版本为11 - -3.执行pth2onnx脚本,生成onnx模型文件 -``` -python3.7 resnet18_pth2onnx.py ./resnet18-f37072fd.pth resnet18.onnx -``` -### 4.2 onnx模型量化(可选) -1.AMCT工具包安装,具体参考[CANN 开发辅助工具指南 (推理)](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools) - -2.数据预处理,用于量化因子矫正。当前模型为动态batch,建议用多batch_size的预处理文件矫正量化因子。 -执行以下命令: -``` -python3.7.5 calibration_bin.py prep_dataset calibration_bin 64 -``` - -3.ONNX模型量化,具体参考[CANN 开发辅助工具指南 (推理)](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools) -在result目录下生成resnet18_deploy_model.onnx量化模型 - -4.量化模型验证,除onnx离线模型转换om模型命令有区别外,其余一致 - -### 4.3 onnx转om模型 - -1.设置环境变量 -``` -source env.sh -``` -**说明** ->此脚本中环境变量只供参考,请以实际安装环境配置环境变量 - -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN 开发辅助工具指南 (推理)](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools) -``` -atc --framework=5 --model=./resnet18.onnx --output=resnet18_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 --insert_op_conf=aipp.config --enable_small_channel=1 - - -## Int8量化(可选) -atc --framework=5 --model=./result/resnet18_deploy_model.onnx --output=resnet18_bs1_int8 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend710 --insert_op_conf=aipp.config --enable_small_channel=1 -``` - -### 4.4 模型离线推理 - -1.设置环境变量 -``` -source env.sh -``` -**说明** ->此脚本中环境变量只供参考,请以实际安装环境配置环境变量 - -2.增加benchmark.{arch}可执行权限 -``` -chmod u+x benchmark.x86_64 -``` - -3.执行离线推理 -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=resnet18_bs1.om -input_text_path=./resnet18_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False -执行./benchmark.x86_64工具请选择与运行环境架构相同的命令。详情参考[CANN 推理benchmark工具用户指南](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools) - -4.精度验证 -调用imagenet_acc_eval.py脚本与数据集标签val_label.txt比对,可以获得Accuracy Top5数据,结果保存在result.json中。 -``` -python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /home/HwHiAiUser/dataset/imagenet/val_label.txt ./ result.json -``` +# ResNet18 Onnx模型端到端推理指导 + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[ResNet18论文](https://arxiv.org/pdf/1512.03385.pdf) + +### 1.2 代码地址 +[ResNet18代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) +branch:master +commit_id:7d955df73fe0e9b47f7d6c77c699324b256fc41f + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +CANN 5.0.3 + +torch == 1.5.1 +torchvision == 0.6.1 +onnx == 1.9.0 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.19.2 +Pillow == 8.2.0 +opencv-python == 4.5.2 +``` + +**说明:** +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 数据集预处理 + +- **[数据集获取](#31-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 3.1 数据集获取 +该模型使用ImageNet的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 + +### 3.2 数据集预处理 +1.预处理脚本imagenet_torch_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 +``` +python3.7 imagenet_torch_preprocess.py resnet /root/datasets/imagenet/val ./prep_dataset +``` +### 3.3 生成数据集信息文件 +1.生成数据集信息文件脚本gen_dataset_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 +``` +python3.7 gen_dataset_info.py bin ./prep_dataset ./resnet18_prep_bin.info 224 224 +``` +第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 + +## 4 模型推理 + +- **[pth转onnx模型](#41-pth转onnx模型)** + +- **[onnx转om模型](#42-onnx转om模型)** + +### 4.1 pth转onnx模型 + +1.下载pth权重文件 +从https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py的第26行获取对应权重下载链接,使用wget命令下载对应权重 + +文件MD5sum:e0b1c919e74f9a193d36871d9964bf7d + +2.ResNet18模型代码在torchvision里,安装torchvision,arm下需源码安装,参考torchvision官网 +``` +git clone https://github.com/pytorch/vision +cd vision +python3.7 setup.py install +cd .. +``` +3.编写pth2onnx脚本resnet18_pth2onnx.py + + **说明:** +>注意目前ATC支持的onnx算子版本为11 + +3.执行pth2onnx脚本,生成onnx模型文件 +``` +python3.7 resnet18_pth2onnx.py ./resnet18-f37072fd.pth resnet18.onnx +``` +### 4.2 onnx模型量化(可选) +1.AMCT工具包安装,具体参考[CANN 开发辅助工具指南 (推理)](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools) + +2.数据预处理,用于量化因子矫正。当前模型为动态batch,建议用多batch_size的预处理文件矫正量化因子。 +执行以下命令: +``` +python3.7.5 calibration_bin.py prep_dataset calibration_bin 64 +``` + +3.ONNX模型量化,具体参考[CANN 开发辅助工具指南 (推理)](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools) +在result目录下生成resnet18_deploy_model.onnx量化模型 + +4.量化模型验证,除onnx离线模型转换om模型命令有区别外,其余一致 + +### 4.3 onnx转om模型 + +1.设置环境变量 +``` +source env.sh +``` +**说明** +>此脚本中环境变量只供参考,请以实际安装环境配置环境变量 + +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN 开发辅助工具指南 (推理)](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools) +``` +atc --framework=5 --model=./resnet18.onnx --output=resnet18_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 --insert_op_conf=aipp.config --enable_small_channel=1 + + +## Int8量化(可选) +atc --framework=5 --model=./result/resnet18_deploy_model.onnx --output=resnet18_bs1_int8 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend710 --insert_op_conf=aipp.config --enable_small_channel=1 +``` + +### 4.4 模型离线推理 + +1.设置环境变量 +``` +source env.sh +``` +**说明** +>此脚本中环境变量只供参考,请以实际安装环境配置环境变量 + +2.增加benchmark.{arch}可执行权限 +``` +chmod u+x benchmark.x86_64 +``` + +3.执行离线推理 +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=resnet18_bs1.om -input_text_path=./resnet18_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +执行./benchmark.x86_64工具请选择与运行环境架构相同的命令。详情参考[CANN 推理benchmark工具用户指南](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools) + +4.精度验证 +调用imagenet_acc_eval.py脚本与数据集标签val_label.txt比对,可以获得Accuracy Top5数据,结果保存在result.json中。 +``` +python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /home/HwHiAiUser/dataset/imagenet/val_label.txt ./ result.json +``` 第一个参数为生成推理结果所在路径,第二个参数为标签数据,第三个参数为生成结果文件路径,第四个参数为生成结果文件名称 \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/calibration_bin.py b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/calibration_bin.py index 0af890d1323d9d200b92dd38293c697d2c7e29d5..0839502aa7b2340f29102533a53c45c13367c039 100644 --- a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/calibration_bin.py +++ b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/calibration_bin.py @@ -1,56 +1,56 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import numpy as np -import multiprocessing - -max_bin=10 -def preprocess(src_path, save_path, batch_size): - files = os.listdir(src_path) - - output_data = [0] - for i, file in enumerate(files): - input_data = np.fromfile(os.path.join(src_path, file), dtype=np.float32) - input_data = input_data.reshape(1, 3, 224, 224) - - if i % batch_size == 0: - output_data = input_data - else: - output_data = np.concatenate((output_data, input_data), axis=0) - - # only save 10 bin files - loop_id = (i + 1) // batch_size - if loop_id > max_bin: - break - - if (i + 1) % batch_size == 0: - output_data.tofile("{}/img_{}_bs{}.bin".format(save_path, loop_id, batch_size)) - output_data = [0] - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python3 xxx.py [src_path] [save_path] [batch_size]") - src_path = sys.argv[1] - save_path = sys.argv[2] - batch_size = int(sys.argv[3]) - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - preprocess(src_path, save_path, batch_size) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import numpy as np +import multiprocessing + +max_bin=10 +def preprocess(src_path, save_path, batch_size): + files = os.listdir(src_path) + + output_data = [0] + for i, file in enumerate(files): + input_data = np.fromfile(os.path.join(src_path, file), dtype=np.float32) + input_data = input_data.reshape(1, 3, 224, 224) + + if i % batch_size == 0: + output_data = input_data + else: + output_data = np.concatenate((output_data, input_data), axis=0) + + # only save 10 bin files + loop_id = (i + 1) // batch_size + if loop_id > max_bin: + break + + if (i + 1) % batch_size == 0: + output_data.tofile("{}/img_{}_bs{}.bin".format(save_path, loop_id, batch_size)) + output_data = [0] + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [src_path] [save_path] [batch_size]") + src_path = sys.argv[1] + save_path = sys.argv[2] + batch_size = int(sys.argv[3]) + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess(src_path, save_path, batch_size) + diff --git a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/gen_dataset_info.py b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/gen_dataset_info.py index 61450b4410663ae5e66ec29ed296ff6584203e31..5381839f653a885666e3fc456db9a1c22b8583a1 100644 --- a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/gen_dataset_info.py +++ b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/gen_dataset_info.py @@ -1,61 +1,61 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) + diff --git a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/imagenet_acc_eval.py b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/imagenet_acc_eval.py index 362f2484e8288dd3df6fa212678dc9449dbbed29..583340a19f2fc6e99faed85526c906f8bd12d7ba 100644 --- a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/imagenet_acc_eval.py +++ b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/imagenet_acc_eval.py @@ -1,184 +1,184 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - if data == '': - n_label = 0 - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - print("Time used:", elapsed) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) + diff --git a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/imagenet_torch_preprocess.py b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/imagenet_torch_preprocess.py index 4787c75a5e8cb10b4be97bc439dab8bb91501e9b..2cdb4994cacf5cd5c22f8944f28ff99f8d1a7de6 100644 --- a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/imagenet_torch_preprocess.py +++ b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/imagenet_torch_preprocess.py @@ -1,114 +1,114 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from PIL import Image -import numpy as np -import multiprocessing - - -model_config = { - 'resnet': { - 'resize': 256, - 'centercrop': 224, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv3': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv4': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.5, 0.5, 0.5], - 'std': [0.5, 0.5, 0.5], - }, -} - - -def center_crop(img, output_size): - if isinstance(output_size, int): - output_size = (int(output_size), int(output_size)) - image_width, image_height = img.size - crop_height, crop_width = output_size - crop_top = int(round((image_height - crop_height) / 2.)) - crop_left = int(round((image_width - crop_width) / 2.)) - return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) - - -def resize(img, size, interpolation=Image.BILINEAR): - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def gen_input_bin(mode_type, file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - # RGBA to RGB - image = Image.open(os.path.join(src_path, file)).convert('RGB') - image = resize(image, model_config[mode_type]['resize']) # Resize - image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop - img = np.array(image, dtype=np.int8) - - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - - -def preprocess(mode_type, src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") - mode_type = sys.argv[1] - src_path = sys.argv[2] - save_path = sys.argv[3] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - if mode_type not in model_config: - model_type_help = "model type: " - for key in model_config.keys(): - model_type_help += key - model_type_help += ' ' - raise Exception(model_type_help) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - preprocess(mode_type, src_path, save_path) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from PIL import Image +import numpy as np +import multiprocessing + + +model_config = { + 'resnet': { + 'resize': 256, + 'centercrop': 224, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv3': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv4': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.5, 0.5, 0.5], + 'std': [0.5, 0.5, 0.5], + }, +} + + +def center_crop(img, output_size): + if isinstance(output_size, int): + output_size = (int(output_size), int(output_size)) + image_width, image_height = img.size + crop_height, crop_width = output_size + crop_top = int(round((image_height - crop_height) / 2.)) + crop_left = int(round((image_width - crop_width) / 2.)) + return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) + + +def resize(img, size, interpolation=Image.BILINEAR): + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def gen_input_bin(mode_type, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + # RGBA to RGB + image = Image.open(os.path.join(src_path, file)).convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.int8) + + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +def preprocess(mode_type, src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") + mode_type = sys.argv[1] + src_path = sys.argv[2] + save_path = sys.argv[3] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if mode_type not in model_config: + model_type_help = "model type: " + for key in model_config.keys(): + model_type_help += key + model_type_help += ' ' + raise Exception(model_type_help) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess(mode_type, src_path, save_path) + diff --git a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/modelzoo_level.txt b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/modelzoo_level.txt index 484664c2399ae4109859a67aba6cb9facff03cf1..55a9add9fa74832ca908108d73946cd76281a9cd 100644 --- a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/modelzoo_level.txt +++ b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:POK \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/requirements.txt b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/requirements.txt index 2fc4e802c476feda2a9866a85630f7f3b29428d7..d072d9aa6f2e7a7b0044ff93d036c3c0347ee5c9 100644 --- a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/requirements.txt +++ b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.5.1 -torchvision == 0.6.1 -onnx == 1.9.0 -numpy == 1.19.2 -Pillow == 8.2.0 +torch == 1.5.1 +torchvision == 0.6.1 +onnx == 1.9.0 +numpy == 1.19.2 +Pillow == 8.2.0 opencv-python == 4.5.2 \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/resnet18_pth2onnx.py b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/resnet18_pth2onnx.py index f7972ea3e1ecb2a5adee7e400d77ca66dec258ce..5933787407e4b3f92af4a90ad32c21d52704b04d 100644 --- a/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/resnet18_pth2onnx.py +++ b/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch/resnet18_pth2onnx.py @@ -1,35 +1,35 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import torch -import torch.onnx -import torchvision.models as models - -def pth2onnx(input_file, output_file): - model = models.resnet18(pretrained=False) - checkpoint = torch.load(input_file, map_location=None) - model.load_state_dict(checkpoint) - - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) - -if __name__ == "__main__": - input_file = sys.argv[1] - output_file = sys.argv[2] - pth2onnx(input_file, output_file) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import torch +import torch.onnx +import torchvision.models as models + +def pth2onnx(input_file, output_file): + model = models.resnet18(pretrained=False) + checkpoint = torch.load(input_file, map_location=None) + model.load_state_dict(checkpoint) + + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) + +if __name__ == "__main__": + input_file = sys.argv[1] + output_file = sys.argv[2] + pth2onnx(input_file, output_file) diff --git a/ACL_PyTorch/built-in/cv/Resnet50_Pytorch_Infer/aipp_resnet50_710.aippconfig b/ACL_PyTorch/built-in/cv/Resnet50_Pytorch_Infer/aipp_resnet50_710.aippconfig index 71e0923f2ae25bb4ece78356a9bd9ee865f6bcc0..173c2d80353dc9de5b252a0b612cec5cde113361 100644 --- a/ACL_PyTorch/built-in/cv/Resnet50_Pytorch_Infer/aipp_resnet50_710.aippconfig +++ b/ACL_PyTorch/built-in/cv/Resnet50_Pytorch_Infer/aipp_resnet50_710.aippconfig @@ -1,20 +1,20 @@ -aipp_op{ - aipp_mode:static - input_format : RGB888_U8 - - src_image_size_w : 256 - src_image_size_h : 256 - - crop: true - load_start_pos_h : 16 - load_start_pos_w : 16 - crop_size_w : 224 - crop_size_h: 224 - - min_chn_0 : 123.675 - min_chn_1 : 116.28 - min_chn_2 : 103.53 - var_reci_chn_0: 0.0171247538316637 - var_reci_chn_1: 0.0175070028011204 - var_reci_chn_2: 0.0174291938997821 +aipp_op{ + aipp_mode:static + input_format : RGB888_U8 + + src_image_size_w : 256 + src_image_size_h : 256 + + crop: true + load_start_pos_h : 16 + load_start_pos_w : 16 + crop_size_w : 224 + crop_size_h: 224 + + min_chn_0 : 123.675 + min_chn_1 : 116.28 + min_chn_2 : 103.53 + var_reci_chn_0: 0.0171247538316637 + var_reci_chn_1: 0.0175070028011204 + var_reci_chn_2: 0.0174291938997821 } \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/Resnet50_Pytorch_Infer/gen_dataset_info.py b/ACL_PyTorch/built-in/cv/Resnet50_Pytorch_Infer/gen_dataset_info.py index 0af8797d669db96ae2e7da28cad7d1f69ef8f723..5ed4309f9e2ab6ec9622f832905225277fa3d688 100644 --- a/ACL_PyTorch/built-in/cv/Resnet50_Pytorch_Infer/gen_dataset_info.py +++ b/ACL_PyTorch/built-in/cv/Resnet50_Pytorch_Infer/gen_dataset_info.py @@ -1,61 +1,61 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) + diff --git a/ACL_PyTorch/built-in/cv/Resnet50_Pytorch_Infer/imagenet_torch_preprocess.py b/ACL_PyTorch/built-in/cv/Resnet50_Pytorch_Infer/imagenet_torch_preprocess.py index b715ddd3f5c5b8f9c9f774378510c06e10fb4aed..a34814146feacbe159ce0c05d10abb8baff2d972 100644 --- a/ACL_PyTorch/built-in/cv/Resnet50_Pytorch_Infer/imagenet_torch_preprocess.py +++ b/ACL_PyTorch/built-in/cv/Resnet50_Pytorch_Infer/imagenet_torch_preprocess.py @@ -1,129 +1,129 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from PIL import Image -import numpy as np -import multiprocessing - - -model_config = { - 'resnet': { - 'resize': 256, - 'centercrop': 256, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv3': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv4': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.5, 0.5, 0.5], - 'std': [0.5, 0.5, 0.5], - }, -} - - -def center_crop(img, output_size): - if isinstance(output_size, int): - output_size = (int(output_size), int(output_size)) - image_width, image_height = img.size - crop_height, crop_width = output_size - crop_top = int(round((image_height - crop_height) / 2.)) - crop_left = int(round((image_width - crop_width) / 2.)) - return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) - - -def resize(img, size, interpolation=Image.BILINEAR): - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def gen_input_bin(mode_type, file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - # RGBA to RGB - image = Image.open(os.path.join(src_path, file)).convert('RGB') - image = resize(image, model_config[mode_type]['resize']) # Resize - image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop - img = np.array(image, dtype=np.int8) - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - -def preprocess_s(mode_type, src_path, save_path): - files = os.listdir(src_path) - i = 0 - for file in files: - if not file.endswith(".jpeg"): - continue - print("start to process image {}....".format(file)) - i = i + 1 - print("file", file, "===", i) - path_image = os.path.join(src_path, file) - # RGBA to RGB - image = Image.open(path_image).convert('RGB') - image = resize(image, model_config[mode_type]['resize']) # Resize - image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop - img = np.array(image, dtype=np.int8) - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - -def preprocess(mode_type, src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") - mode_type = sys.argv[1] - src_path = sys.argv[2] - save_path = sys.argv[3] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - if mode_type not in model_config: - model_type_help = "model type: " - for key in model_config.keys(): - model_type_help += key - model_type_help += ' ' - raise Exception(model_type_help) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - preprocess_s(mode_type, src_path, save_path) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from PIL import Image +import numpy as np +import multiprocessing + + +model_config = { + 'resnet': { + 'resize': 256, + 'centercrop': 256, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv3': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv4': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.5, 0.5, 0.5], + 'std': [0.5, 0.5, 0.5], + }, +} + + +def center_crop(img, output_size): + if isinstance(output_size, int): + output_size = (int(output_size), int(output_size)) + image_width, image_height = img.size + crop_height, crop_width = output_size + crop_top = int(round((image_height - crop_height) / 2.)) + crop_left = int(round((image_width - crop_width) / 2.)) + return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) + + +def resize(img, size, interpolation=Image.BILINEAR): + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def gen_input_bin(mode_type, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + # RGBA to RGB + image = Image.open(os.path.join(src_path, file)).convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.int8) + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + +def preprocess_s(mode_type, src_path, save_path): + files = os.listdir(src_path) + i = 0 + for file in files: + if not file.endswith(".jpeg"): + continue + print("start to process image {}....".format(file)) + i = i + 1 + print("file", file, "===", i) + path_image = os.path.join(src_path, file) + # RGBA to RGB + image = Image.open(path_image).convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.int8) + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + +def preprocess(mode_type, src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") + mode_type = sys.argv[1] + src_path = sys.argv[2] + save_path = sys.argv[3] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if mode_type not in model_config: + model_type_help = "model type: " + for key in model_config.keys(): + model_type_help += key + model_type_help += ' ' + raise Exception(model_type_help) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess_s(mode_type, src_path, save_path) + diff --git a/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/README.md b/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/README.md index d9e1c75e635f0b818038f7f385f7ac8b0141483b..803c1aebb3fa8d3b2e0a40a4cee4ba37798a0b64 100644 --- a/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/README.md +++ b/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/README.md @@ -1,234 +1,234 @@ -# SE_ResNet50 Onnx模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 推理硬件设备](#21-推理硬件设备) - - [2.2 深度学习框架](#22-深度学习框架) - - [2.3 Python第三方库](#23-Python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 获取pth权重文件](#31-获取pth权重文件) - - [3.2 获取pth权重文件](#32-pth转onnx模型) - - [3.3 pth转om模型](#33-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) - - [5.3 性能验证](#53-性能验证) -- [6 评测结果](#6-评测结果) -- [7 test目录说明](#7-test目录说明) - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[SE_ResNet50论文](https://openaccess.thecvf.com/content_cvpr_2018/papers/Hu_Squeeze-and-Excitation_Networks_CVPR_2018_paper.pdf) - -### 1.2 代码地址 -[SE_ResNet50代码](https://github.com/Cadene/pretrained-models.pytorch/blob/master/pretrainedmodels/models/senet.py) - -## 2 环境说明 - -- **[推理硬件设备](#21-推理硬件设备)** - -- **[深度学习框架](#22-深度学习框架)** - -- **[Python第三方库](#23-Python第三方库)** - -### 2.1 推理硬件设备 -``` -Ascend710 -``` - -### 2.2 深度学习框架 -``` -CANN 5.0.4 - -torch == 1.8.0 -torchvision == 0.9.0 -onnx == 1.10.2 -``` - -### 2.3 Python第三方库 - -``` -numpy == 1.21.4 -opencv-python == 4.5.4.58 -pretrainedmodels == 0.7.4 -``` - -**说明:** -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[获取pth权重文件](#31-获取pth权重文件)** - -- **[pth转onnx模型](#32-pth转onnx模型)** - -- **[onnx转om模型](#33-onnx转om模型)** - -### 3.1 获取pth权重文件 -执行命令: - -``` -wget https://data.lip6.fr/cadene/pretrainedmodels/se_resnet50-ce0d4300.pth -``` -执行后在当前目录下获取pth权重文件:se_resnet50-ce0d4300.pth。 - -### 3.2 pth转onnx模型 -执行命令: - -``` -python3 SE_ResNet50_pth2onnx.py ./se_resnet50-ce0d4300.pth ./se_resnet50_dynamic_bs.onnx -``` - -命令参数分别为输入pth文件:./se_resnet50-ce0d4300.pth和输出onnx文件:./se_resnet50_dynamic_bs.onnx -执行后在当前路径下生成se_resnet50_dynamic_bs.onnx模型文件。 - -### 3.3 onnx转om模型 - -a.设置环境变量: - -``` -source /usr/local/Ascend/ascend-toolkit/set_env.sh -``` - -该命令中使用CANN默认安装路径(/usr/local/Ascend/ascend-toolkit)中的环境变量,使用过程中请按照实际安装路径设置环境变量。 - -b.执行atc模型转换命令: - -``` -atc --model=./se_resnet50_dynamic_bs.onnx --framework=5 --input_format=NCHW --input_shape="image:32,3,224,224" --output=./se_resnet50_fp16_bs32 --log=error --soc_version=Ascend710 --insert_op_conf=./aipp_SE_ResNet50_pth.config --enable_small_channel=1 -``` - -参数说明: - --model:为ONNX模型文件。 - --framework:5代表ONNX模型。 - --input_format:输入数据的格式。 - --input_shape:输入数据的shape。 - --output:输出的OM模型。 - --log:日志级别。 - --soc_version:处理器型号,Ascend310或Ascend710。 - --insert_op_config:插入算子的配置文件路径与文件名,例如aipp预处理算子。 - --enable_small_channel:Set enable small channel. 0(default): disable; 1: enable - -执行后在当前目录下生成om模型文件:se_resnet50_fp16_bs32.om。 - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -该模型使用ImageNet的5万张验证集进行测试,图片与标签分别存放在/home/HwHiAiUser/dataset/ImageNet/val_union路径与/home/HwHiAiUser/dataset/ImageNet/val_label.txt文件下。 - -数据集获取请参考[pytorch原始仓](https://github.com/pytorch/examples/tree/master/imagenet)说明。 - -### 4.2 数据集预处理 - -1.预处理工具为:imagenet_torch_preprocess.py -2.执行工具命令: -``` -python3 ./imagenet_torch_preprocess.py /home/HwHiAiUser/dataset/ImageNet/val_union ./data/ImageNet_bin -``` -命令参数分别数据集图片路径:/home/HwHiAiUser/dataset/ImageNet/val_union和处理结果bin文件保存路径:./data/ImageNet_bin。 -执行后在./data/ImageNet_bin路径下生成数据处理后的bin文件。 - -### 4.3 生成数据集信息文件 -1.生成数据集信息文件工具为:gen_dataset_info.py。 -2.执行工具命令: - -``` -python3 ./gen_dataset_info.py bin ./data/ImageNet_bin ./data/ImageNet_bin.info 224 224 -``` -命令参数分别为数据集文件类型:bin、文件路径:./data/ImageNet_bin、数据集信息文件:./data/ImageNet_bin.info、图片像素长:224、图片像素宽:224。 -执行后在./data路径下生成数据集信息文件:ImageNet_bin.info。 - -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -- **[性能验证](#52-性能验证)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend710上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) -### 5.2 离线推理 -1.设置环境变量: - -``` -source /usr/local/Ascend/ascend-toolkit/set_env.sh -``` - -2.执行推理命令: - -``` -./benchmark.x86_64 -model_type=vision -om_path=./se_resnet50_fp16_bs32.om -device_id=0 -batch_size=32 -input_text_path=./data/ImageNet_bin.info -input_width=256 -input_height=256 -output_binary=false -useDvpp=false -``` - -分辨率(input_width,input_height)要与aipp_SE_ResNet50_pth.config文件中配置(src_image_size_w,src_image_size_h)保持一致,执行后推理结果保存在./result/dumpOutput_device0路径下。 - -3.精度验证: -调用vision_metric_ImageNet.py工具脚本与数据集标签val_label.txt比对,可以获得Accuracy Top5数据: - -``` -python3 ./vision_metric_ImageNet.py ./result/dumpOutput_device0/ /home/HwHiAiUser/dataset/ImageNet/val_label.txt ./result accuracy_result.json -``` - -第一个参数为生成推理结果所在路径,第二个参数为标签数据,第三个参数为生成结果文件路径,第四个参数为生成结果文件名称。 -执行后模型精度结果保存在./result/accuracy_result.json文件中 - -### 5.3 性能验证 -1.设置环境变量: - -``` -source /usr/local/Ascend/ascend-toolkit/set_env.sh -``` - -2.执行性能测试命令: - -``` -./benchmark.x86_64 -round=50 -om_path=./se_resnet50_fp16_bs32.om -device_id=0 -batch_size=32 > ./result/performace_result.json -``` - -执行后性能测试结果保存在./result/performace_result.json文件中 - -## 6 评测结果 - -评测结果 -| 模型 | pth精度 | 710精度 | 性能基准 | 710性能 | -| --------------- | ---------------------- | ------------------------- | ------------ | ----------- | -| SE_ResNet50 bs32 | Acc@1 77.63,Acc@5 93.64| Acc@1 77.36,Acc@5 93.76 | 1554.726fps | 2690.43fps | - -## 6 test目录说明 - -test目录下存放的为测试脚本,其中: -1.pth2om.sh为pth模型转om模型脚本,使用命令为: - -``` -bash ./test/pth2om.sh /usr/local/Ascend -``` - -其中/usr/local/Ascend为cann包默认安装路径,执行后在当前目录下生成om模型: se_resnet50_fp16_bs32.om。 - -2.eval_acc_perf.sh为om模型,精度、性能测试脚本,使用命令为: - -``` -bash ./test/eval_acc_perf.sh /usr/local/Ascend ./se_resnet50_fp16_bs32.om 32 0 /home/HwHiAiUser/dataset/ImageNet/val_label.txt -``` - +# SE_ResNet50 Onnx模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 推理硬件设备](#21-推理硬件设备) + - [2.2 深度学习框架](#22-深度学习框架) + - [2.3 Python第三方库](#23-Python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 获取pth权重文件](#31-获取pth权重文件) + - [3.2 获取pth权重文件](#32-pth转onnx模型) + - [3.3 pth转om模型](#33-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) + - [5.3 性能验证](#53-性能验证) +- [6 评测结果](#6-评测结果) +- [7 test目录说明](#7-test目录说明) + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[SE_ResNet50论文](https://openaccess.thecvf.com/content_cvpr_2018/papers/Hu_Squeeze-and-Excitation_Networks_CVPR_2018_paper.pdf) + +### 1.2 代码地址 +[SE_ResNet50代码](https://github.com/Cadene/pretrained-models.pytorch/blob/master/pretrainedmodels/models/senet.py) + +## 2 环境说明 + +- **[推理硬件设备](#21-推理硬件设备)** + +- **[深度学习框架](#22-深度学习框架)** + +- **[Python第三方库](#23-Python第三方库)** + +### 2.1 推理硬件设备 +``` +Ascend710 +``` + +### 2.2 深度学习框架 +``` +CANN 5.0.4 + +torch == 1.8.0 +torchvision == 0.9.0 +onnx == 1.10.2 +``` + +### 2.3 Python第三方库 + +``` +numpy == 1.21.4 +opencv-python == 4.5.4.58 +pretrainedmodels == 0.7.4 +``` + +**说明:** +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[获取pth权重文件](#31-获取pth权重文件)** + +- **[pth转onnx模型](#32-pth转onnx模型)** + +- **[onnx转om模型](#33-onnx转om模型)** + +### 3.1 获取pth权重文件 +执行命令: + +``` +wget https://data.lip6.fr/cadene/pretrainedmodels/se_resnet50-ce0d4300.pth +``` +执行后在当前目录下获取pth权重文件:se_resnet50-ce0d4300.pth。 + +### 3.2 pth转onnx模型 +执行命令: + +``` +python3 SE_ResNet50_pth2onnx.py ./se_resnet50-ce0d4300.pth ./se_resnet50_dynamic_bs.onnx +``` + +命令参数分别为输入pth文件:./se_resnet50-ce0d4300.pth和输出onnx文件:./se_resnet50_dynamic_bs.onnx +执行后在当前路径下生成se_resnet50_dynamic_bs.onnx模型文件。 + +### 3.3 onnx转om模型 + +a.设置环境变量: + +``` +source /usr/local/Ascend/ascend-toolkit/set_env.sh +``` + +该命令中使用CANN默认安装路径(/usr/local/Ascend/ascend-toolkit)中的环境变量,使用过程中请按照实际安装路径设置环境变量。 + +b.执行atc模型转换命令: + +``` +atc --model=./se_resnet50_dynamic_bs.onnx --framework=5 --input_format=NCHW --input_shape="image:32,3,224,224" --output=./se_resnet50_fp16_bs32 --log=error --soc_version=Ascend710 --insert_op_conf=./aipp_SE_ResNet50_pth.config --enable_small_channel=1 +``` + +参数说明: + --model:为ONNX模型文件。 + --framework:5代表ONNX模型。 + --input_format:输入数据的格式。 + --input_shape:输入数据的shape。 + --output:输出的OM模型。 + --log:日志级别。 + --soc_version:处理器型号,Ascend310或Ascend710。 + --insert_op_config:插入算子的配置文件路径与文件名,例如aipp预处理算子。 + --enable_small_channel:Set enable small channel. 0(default): disable; 1: enable + +执行后在当前目录下生成om模型文件:se_resnet50_fp16_bs32.om。 + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用ImageNet的5万张验证集进行测试,图片与标签分别存放在/home/HwHiAiUser/dataset/ImageNet/val_union路径与/home/HwHiAiUser/dataset/ImageNet/val_label.txt文件下。 + +数据集获取请参考[pytorch原始仓](https://github.com/pytorch/examples/tree/master/imagenet)说明。 + +### 4.2 数据集预处理 + +1.预处理工具为:imagenet_torch_preprocess.py +2.执行工具命令: +``` +python3 ./imagenet_torch_preprocess.py /home/HwHiAiUser/dataset/ImageNet/val_union ./data/ImageNet_bin +``` +命令参数分别数据集图片路径:/home/HwHiAiUser/dataset/ImageNet/val_union和处理结果bin文件保存路径:./data/ImageNet_bin。 +执行后在./data/ImageNet_bin路径下生成数据处理后的bin文件。 + +### 4.3 生成数据集信息文件 +1.生成数据集信息文件工具为:gen_dataset_info.py。 +2.执行工具命令: + +``` +python3 ./gen_dataset_info.py bin ./data/ImageNet_bin ./data/ImageNet_bin.info 224 224 +``` +命令参数分别为数据集文件类型:bin、文件路径:./data/ImageNet_bin、数据集信息文件:./data/ImageNet_bin.info、图片像素长:224、图片像素宽:224。 +执行后在./data路径下生成数据集信息文件:ImageNet_bin.info。 + +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +- **[性能验证](#52-性能验证)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend710上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) +### 5.2 离线推理 +1.设置环境变量: + +``` +source /usr/local/Ascend/ascend-toolkit/set_env.sh +``` + +2.执行推理命令: + +``` +./benchmark.x86_64 -model_type=vision -om_path=./se_resnet50_fp16_bs32.om -device_id=0 -batch_size=32 -input_text_path=./data/ImageNet_bin.info -input_width=256 -input_height=256 -output_binary=false -useDvpp=false +``` + +分辨率(input_width,input_height)要与aipp_SE_ResNet50_pth.config文件中配置(src_image_size_w,src_image_size_h)保持一致,执行后推理结果保存在./result/dumpOutput_device0路径下。 + +3.精度验证: +调用vision_metric_ImageNet.py工具脚本与数据集标签val_label.txt比对,可以获得Accuracy Top5数据: + +``` +python3 ./vision_metric_ImageNet.py ./result/dumpOutput_device0/ /home/HwHiAiUser/dataset/ImageNet/val_label.txt ./result accuracy_result.json +``` + +第一个参数为生成推理结果所在路径,第二个参数为标签数据,第三个参数为生成结果文件路径,第四个参数为生成结果文件名称。 +执行后模型精度结果保存在./result/accuracy_result.json文件中 + +### 5.3 性能验证 +1.设置环境变量: + +``` +source /usr/local/Ascend/ascend-toolkit/set_env.sh +``` + +2.执行性能测试命令: + +``` +./benchmark.x86_64 -round=50 -om_path=./se_resnet50_fp16_bs32.om -device_id=0 -batch_size=32 > ./result/performace_result.json +``` + +执行后性能测试结果保存在./result/performace_result.json文件中 + +## 6 评测结果 + +评测结果 +| 模型 | pth精度 | 710精度 | 性能基准 | 710性能 | +| --------------- | ---------------------- | ------------------------- | ------------ | ----------- | +| SE_ResNet50 bs32 | Acc@1 77.63,Acc@5 93.64| Acc@1 77.36,Acc@5 93.76 | 1554.726fps | 2690.43fps | + +## 6 test目录说明 + +test目录下存放的为测试脚本,其中: +1.pth2om.sh为pth模型转om模型脚本,使用命令为: + +``` +bash ./test/pth2om.sh /usr/local/Ascend +``` + +其中/usr/local/Ascend为cann包默认安装路径,执行后在当前目录下生成om模型: se_resnet50_fp16_bs32.om。 + +2.eval_acc_perf.sh为om模型,精度、性能测试脚本,使用命令为: + +``` +bash ./test/eval_acc_perf.sh /usr/local/Ascend ./se_resnet50_fp16_bs32.om 32 0 /home/HwHiAiUser/dataset/ImageNet/val_label.txt +``` + 其中第1个参数为cann包安装路径,第2个参数为om模型,第3个参数为batch_size,第4个参数为device_id,第5个参数为标签数据。执行后精度结果保存在./result/accuracy_result.json文件中,性能结果保存在./result/performace_result.json文件中。 \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/SE_ResNet50_pth2onnx.py b/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/SE_ResNet50_pth2onnx.py index 94a9bce4b9d4cfff1799b4d5ebbbd0949e0cc593..9a96a251560f3eff356e5006070284f7dc57c14e 100644 --- a/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/SE_ResNet50_pth2onnx.py +++ b/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/SE_ResNet50_pth2onnx.py @@ -1,39 +1,39 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# coding=UTF-8 - -import sys -import torch -import onnx -from pretrainedmodels.models.senet import se_resnet50 - - -def pth2onnx(pth_file, onnx_file): - model = se_resnet50(num_classes=1000, pretrained=None) - model.load_state_dict(torch.load(pth_file)) - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, onnx_file, input_names=input_names, dynamic_axes=dynamic_axes, - output_names=output_names, opset_version=11) - -if __name__ == '__main__': - if len(sys.argv) != 3: - raise Exception("usage: python SE_ResNet50_pth2onnx.py ") - pth_file = sys.argv[1] - onnx_file = sys.argv[2] - pth2onnx(pth_file, onnx_file) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# coding=UTF-8 + +import sys +import torch +import onnx +from pretrainedmodels.models.senet import se_resnet50 + + +def pth2onnx(pth_file, onnx_file): + model = se_resnet50(num_classes=1000, pretrained=None) + model.load_state_dict(torch.load(pth_file)) + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, onnx_file, input_names=input_names, dynamic_axes=dynamic_axes, + output_names=output_names, opset_version=11) + +if __name__ == '__main__': + if len(sys.argv) != 3: + raise Exception("usage: python SE_ResNet50_pth2onnx.py ") + pth_file = sys.argv[1] + onnx_file = sys.argv[2] + pth2onnx(pth_file, onnx_file) diff --git a/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/aipp_SE_ResNet50_pth.config b/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/aipp_SE_ResNet50_pth.config index 01600d0fa197ad6fe64e732c8bd3a637121a7de5..16b6c79d159944423dc0e63accf92a26d8ebb3e8 100644 --- a/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/aipp_SE_ResNet50_pth.config +++ b/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/aipp_SE_ResNet50_pth.config @@ -1,21 +1,21 @@ -aipp_op{ - aipp_mode:static - input_format : RGB888_U8 - - src_image_size_w : 256 - src_image_size_h : 256 - - crop: true - load_start_pos_h : 16 - load_start_pos_w : 16 - crop_size_w : 224 - crop_size_h: 224 - - min_chn_0 : 123.675 - min_chn_1 : 116.28 - min_chn_2 : 103.53 - var_reci_chn_0: 0.0171247538316637 - var_reci_chn_1: 0.0175070028011204 - var_reci_chn_2: 0.0174291938997821 - -} +aipp_op{ + aipp_mode:static + input_format : RGB888_U8 + + src_image_size_w : 256 + src_image_size_h : 256 + + crop: true + load_start_pos_h : 16 + load_start_pos_w : 16 + crop_size_w : 224 + crop_size_h: 224 + + min_chn_0 : 123.675 + min_chn_1 : 116.28 + min_chn_2 : 103.53 + var_reci_chn_0: 0.0171247538316637 + var_reci_chn_1: 0.0175070028011204 + var_reci_chn_2: 0.0174291938997821 + +} diff --git a/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/gen_dataset_info.py b/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/gen_dataset_info.py index be7ee43a39e0c8a199c8c0aa78c94ead2a0d1b54..9b9fa05d70b54edecba8722b48a8b35e2c62824c 100644 --- a/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/gen_dataset_info.py +++ b/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/gen_dataset_info.py @@ -1,61 +1,61 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# coding=UTF-8 - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img[7:], width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img[7:], str(width), str(height)]) - file.write(content) - file.write('\n') - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# coding=UTF-8 + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img[7:], width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img[7:], str(width), str(height)]) + file.write(content) + file.write('\n') + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) diff --git a/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/imagenet_torch_preprocess.py b/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/imagenet_torch_preprocess.py index ab5ad9b2bc57d2a366130ce64723df39dba26918..9f0c2cf3b74b2548f6e1ad5f39576e9d218aa537 100644 --- a/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/imagenet_torch_preprocess.py +++ b/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/imagenet_torch_preprocess.py @@ -1,58 +1,58 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# coding=UTF-8 - -import os -import sys -import cv2 -import numpy as np - - -def center_crop(img, out_height, out_width): - height, width, _ = img.shape - left = int((width - out_width) / 2) - right = int((width + out_width) / 2) - top = int((height - out_height) / 2) - bottom = int((height + out_height) / 2) - img = img[top:bottom, left:right] - return img - -def preprocess(file_path, bin_path): - in_files = os.listdir(file_path) - if not os.path.exists(bin_path): - os.makedirs(bin_path) - i = 0 - - resize_size = 256 - mean = [0.485, 0.456, 0.406] - std = [0.229, 0.224, 0.225] - - for file in in_files: - i = i + 1 - print(file, "===", i) - - img = cv2.imread(os.path.join(file_path, file)) - b, g, r = cv2.split(img) - - img = cv2.merge([r, g, b]) - img = cv2.resize(img, (resize_size, resize_size), interpolation=cv2.INTER_CUBIC) - img = np.array(img, dtype=np.int8) - - img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) - -if __name__ == "__main__": - file_path = os.path.abspath(sys.argv[1]) - bin_path = os.path.abspath(sys.argv[2]) - preprocess(file_path, bin_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# coding=UTF-8 + +import os +import sys +import cv2 +import numpy as np + + +def center_crop(img, out_height, out_width): + height, width, _ = img.shape + left = int((width - out_width) / 2) + right = int((width + out_width) / 2) + top = int((height - out_height) / 2) + bottom = int((height + out_height) / 2) + img = img[top:bottom, left:right] + return img + +def preprocess(file_path, bin_path): + in_files = os.listdir(file_path) + if not os.path.exists(bin_path): + os.makedirs(bin_path) + i = 0 + + resize_size = 256 + mean = [0.485, 0.456, 0.406] + std = [0.229, 0.224, 0.225] + + for file in in_files: + i = i + 1 + print(file, "===", i) + + img = cv2.imread(os.path.join(file_path, file)) + b, g, r = cv2.split(img) + + img = cv2.merge([r, g, b]) + img = cv2.resize(img, (resize_size, resize_size), interpolation=cv2.INTER_CUBIC) + img = np.array(img, dtype=np.int8) + + img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) + +if __name__ == "__main__": + file_path = os.path.abspath(sys.argv[1]) + bin_path = os.path.abspath(sys.argv[2]) + preprocess(file_path, bin_path) diff --git a/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/vision_metric_ImageNet.py b/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/vision_metric_ImageNet.py index 82580bab7dca794f52f3465d9b9fdaa82e1f21fc..3ae9c66b2ea5aa5ee6776fca435b2b07affe7d22 100644 --- a/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/vision_metric_ImageNet.py +++ b/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer/vision_metric_ImageNet.py @@ -1,184 +1,184 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# coding=UTF-8 - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - print("Time used:", elapsed) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# coding=UTF-8 + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) + diff --git a/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/PytorchTransfer.py b/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/PytorchTransfer.py index 15680c59ff5a61a0b0d01d869bc39087000b7dc1..15eeaaa895e24bcf280649fb8f5bc9a8f1288f31 100644 --- a/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/PytorchTransfer.py +++ b/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/PytorchTransfer.py @@ -1,47 +1,47 @@ -import sys -import os -import torch -import cv2 -from PIL import Image -import numpy as np -import torch.utils.data -import torchvision.transforms as transforms -from torch.autograd import Variable - - -def mobilenet_onnx(input_path: str, output_path: str): - img = cv2.imread(input_path) - img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) - pilimg = Image.fromarray(img) - normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], - std=[0.229, 0.224, 0.225]) - val_transformer = transforms.Compose([ - transforms.Scale(256), - transforms.CenterCrop(224), - transforms.ToTensor(), - normalize - ]) - - img_tensor = val_transformer(pilimg) - img_tensor = torch.unsqueeze(img_tensor, dim=0).float() - img_tensor = Variable(img_tensor, requires_grad=False) - img_tensor.reshape(1, 3, 224, 224) - img_numpy = img_tensor.cpu().numpy() - - img_name = input_path.split('/')[-1] - bin_name = img_name.split('.')[0] + ".bin" - output_fl = os.path.join(output_path, bin_name) - # save img_tensor as binary file for om inference input - img_numpy.tofile(output_fl) - - -if __name__ == "__main__": - input_img_dir = sys.argv[1] - output_img_dir = sys.argv[2] - images = os.listdir(input_img_dir) - for image_name in images: - if not image_name.endswith(".jpeg"): - continue - print("start to process image {}....".format(image_name)) - path_image = os.path.join(input_img_dir, image_name) - mobilenet_onnx(path_image, output_img_dir) +import sys +import os +import torch +import cv2 +from PIL import Image +import numpy as np +import torch.utils.data +import torchvision.transforms as transforms +from torch.autograd import Variable + + +def mobilenet_onnx(input_path: str, output_path: str): + img = cv2.imread(input_path) + img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) + pilimg = Image.fromarray(img) + normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]) + val_transformer = transforms.Compose([ + transforms.Scale(256), + transforms.CenterCrop(224), + transforms.ToTensor(), + normalize + ]) + + img_tensor = val_transformer(pilimg) + img_tensor = torch.unsqueeze(img_tensor, dim=0).float() + img_tensor = Variable(img_tensor, requires_grad=False) + img_tensor.reshape(1, 3, 224, 224) + img_numpy = img_tensor.cpu().numpy() + + img_name = input_path.split('/')[-1] + bin_name = img_name.split('.')[0] + ".bin" + output_fl = os.path.join(output_path, bin_name) + # save img_tensor as binary file for om inference input + img_numpy.tofile(output_fl) + + +if __name__ == "__main__": + input_img_dir = sys.argv[1] + output_img_dir = sys.argv[2] + images = os.listdir(input_img_dir) + for image_name in images: + if not image_name.endswith(".jpeg"): + continue + print("start to process image {}....".format(image_name)) + path_image = os.path.join(input_img_dir, image_name) + mobilenet_onnx(path_image, output_img_dir) diff --git a/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/ReadMe.md b/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/ReadMe.md index 89d9026fb4b7f9c7dc761d809e3a410e1d688362..fd5be016308e01ae8d4d43219e136c10d8076660 100644 --- a/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/ReadMe.md +++ b/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/ReadMe.md @@ -1,48 +1,48 @@ -文件作用说明: - -1.auto_tune.sh:模型转换脚本,集成了auto tune功能,可以手动关闭 - -2.shufflenetv2.py:官方模型用于转换pth文件到onnx文件 - -3.shufflenetv2_wock_op_woct.py:NPU下训练模型用于转换pth文件到onnx文件 - -4.BinaryImageNet.info:ImageNet数据集信息,用于benchmark推理获取数据集 - -5.PytorchTransfer.py:数据集预处理脚本,通过均值方差处理归一化图片 - -6.val_label.txt:ImageNet数据集标签,用于验证推理结果 - -7.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy - -8.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer - - - - - -推理端到端步骤: - -(1) 从Torchvision下载shufflenetv2模型或者指定自己训练好的pth文件路径,通过pth2onnx.py脚本转化为onnx模型 - - - -(2)运行auto_tune.sh脚本转换om模型,也可以选择手动关闭auto_tune - -本demo已提供调优完成的om模型 - - - -(3)用PytorchTransfer.py脚本处理数据集,参考BinaryImageNet.Info配置处理后的二进制数据集路径 - - - -(4)./benchmark.x86_64 -model_type=vision -batch_size=16 -device_id=0 -input_text_path=./BinaryImageNet.info -input_width=224 -input_height=224 -om_path=./shufflenetv2_bs16.om -useDvpp=False - -运行benchmark推理,结果保存在 ./result 目录下 - - - -(5)python3.7 vision_metric_ImageNet.py result/dumpOutput/ ./val_label.txt ./ result.json - -验证推理结果 - +文件作用说明: + +1.auto_tune.sh:模型转换脚本,集成了auto tune功能,可以手动关闭 + +2.shufflenetv2.py:官方模型用于转换pth文件到onnx文件 + +3.shufflenetv2_wock_op_woct.py:NPU下训练模型用于转换pth文件到onnx文件 + +4.BinaryImageNet.info:ImageNet数据集信息,用于benchmark推理获取数据集 + +5.PytorchTransfer.py:数据集预处理脚本,通过均值方差处理归一化图片 + +6.val_label.txt:ImageNet数据集标签,用于验证推理结果 + +7.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy + +8.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer + + + + + +推理端到端步骤: + +(1) 从Torchvision下载shufflenetv2模型或者指定自己训练好的pth文件路径,通过pth2onnx.py脚本转化为onnx模型 + + + +(2)运行auto_tune.sh脚本转换om模型,也可以选择手动关闭auto_tune + +本demo已提供调优完成的om模型 + + + +(3)用PytorchTransfer.py脚本处理数据集,参考BinaryImageNet.Info配置处理后的二进制数据集路径 + + + +(4)./benchmark.x86_64 -model_type=vision -batch_size=16 -device_id=0 -input_text_path=./BinaryImageNet.info -input_width=224 -input_height=224 -om_path=./shufflenetv2_bs16.om -useDvpp=False + +运行benchmark推理,结果保存在 ./result 目录下 + + + +(5)python3.7 vision_metric_ImageNet.py result/dumpOutput/ ./val_label.txt ./ result.json + +验证推理结果 + diff --git a/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/shufflenetv2.py b/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/shufflenetv2.py index 4c107ef0330d13b434b39630fc1d3e3752f9a9dd..ecf11fda97c51bf348b1c9ecae2a139057e206b2 100644 --- a/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/shufflenetv2.py +++ b/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/shufflenetv2.py @@ -1,213 +1,213 @@ -import torch -import torch.nn as nn - - -__all__ = [ - 'ShuffleNetV2', 'shufflenet_v2_x0_5', 'shufflenet_v2_x1_0', - 'shufflenet_v2_x1_5', 'shufflenet_v2_x2_0' -] - -model_urls = { - 'shufflenetv2_x0.5': 'https://download.pytorch.org/models/shufflenetv2_x0.5-f707e7126e.pth', - 'shufflenetv2_x1.0': 'https://download.pytorch.org/models/shufflenetv2_x1-5666bf0f80.pth', - 'shufflenetv2_x1.5': None, - 'shufflenetv2_x2.0': None, -} - - -def channel_shuffle(x, groups): - # type: (torch.Tensor, int) -> torch.Tensor - batchsize, num_channels, height, width = x.data.size() - channels_per_group = num_channels // groups - - # reshape - x = x.view(batchsize, groups, - channels_per_group, height, width) - - x = torch.transpose(x, 1, 2).contiguous() - - # flatten - x = x.view(batchsize, -1, height, width) - - return x - - -class InvertedResidual(nn.Module): - def __init__(self, inp, oup, stride): - super(InvertedResidual, self).__init__() - - if not (1 <= stride <= 3): - raise ValueError('illegal stride value') - self.stride = stride - - branch_features = oup // 2 - assert (self.stride != 1) or (inp == branch_features << 1) - - if self.stride > 1: - self.branch1 = nn.Sequential( - self.depthwise_conv(inp, inp, kernel_size=3, stride=self.stride, padding=1), - nn.BatchNorm2d(inp), - nn.Conv2d(inp, branch_features, kernel_size=1, stride=1, padding=0, bias=False), - nn.BatchNorm2d(branch_features), - nn.ReLU(inplace=True), - ) - else: - self.branch1 = nn.Sequential() - - self.branch2 = nn.Sequential( - nn.Conv2d(inp if (self.stride > 1) else branch_features, - branch_features, kernel_size=1, stride=1, padding=0, bias=False), - nn.BatchNorm2d(branch_features), - nn.ReLU(inplace=True), - self.depthwise_conv(branch_features, branch_features, kernel_size=3, stride=self.stride, padding=1), - nn.BatchNorm2d(branch_features), - nn.Conv2d(branch_features, branch_features, kernel_size=1, stride=1, padding=0, bias=False), - nn.BatchNorm2d(branch_features), - nn.ReLU(inplace=True), - ) - - @staticmethod - def depthwise_conv(i, o, kernel_size, stride=1, padding=0, bias=False): - return nn.Conv2d(i, o, kernel_size, stride, padding, bias=bias, groups=i) - - def forward(self, x): - if self.stride == 1: - x1, x2 = x.chunk(2, dim=1) - out = torch.cat((x1, self.branch2(x2)), dim=1) - else: - out = torch.cat((self.branch1(x), self.branch2(x)), dim=1) - - out = channel_shuffle(out, 2) - - return out - - -class ShuffleNetV2(nn.Module): - def __init__(self, stages_repeats, stages_out_channels, num_classes=1000, inverted_residual=InvertedResidual): - super(ShuffleNetV2, self).__init__() - - if len(stages_repeats) != 3: - raise ValueError('expected stages_repeats as list of 3 positive ints') - if len(stages_out_channels) != 5: - raise ValueError('expected stages_out_channels as list of 5 positive ints') - self._stage_out_channels = stages_out_channels - - input_channels = 3 - output_channels = self._stage_out_channels[0] - self.conv1 = nn.Sequential( - nn.Conv2d(input_channels, output_channels, 3, 2, 1, bias=False), - nn.BatchNorm2d(output_channels), - nn.ReLU(inplace=True), - ) - input_channels = output_channels - - self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) - - stage_names = ['stage{}'.format(i) for i in [2, 3, 4]] - for name, repeats, output_channels in zip( - stage_names, stages_repeats, self._stage_out_channels[1:]): - seq = [inverted_residual(input_channels, output_channels, 2)] - for i in range(repeats - 1): - seq.append(inverted_residual(output_channels, output_channels, 1)) - setattr(self, name, nn.Sequential(*seq)) - input_channels = output_channels - - output_channels = self._stage_out_channels[-1] - self.conv5 = nn.Sequential( - nn.Conv2d(input_channels, output_channels, 1, 1, 0, bias=False), - nn.BatchNorm2d(output_channels), - nn.ReLU(inplace=True), - ) - - self.fc = nn.Linear(output_channels, num_classes) - - def _forward_impl(self, x): - # See note [TorchScript super()] - x = self.conv1(x) - x = self.maxpool(x) - x = self.stage2(x) - x = self.stage3(x) - x = self.stage4(x) - x = self.conv5(x) - x = x.mean([2, 3]) # globalpool - x = self.fc(x) - return x - - def forward(self, x): - return self._forward_impl(x) - - -def _shufflenetv2(arch, pretrained, progress, *args, **kwargs): - model = ShuffleNetV2(*args, **kwargs) - - if pretrained: - model_url = model_urls[arch] - if model_url is None: - raise NotImplementedError('pretrained {} is not supported as of now'.format(arch)) - else: - state_dict = load_state_dict_from_url(model_url, progress=progress) - model.load_state_dict(state_dict) - - return model - - -def shufflenet_v2_x0_5(pretrained=False, progress=True, **kwargs): - """ - Constructs a ShuffleNetV2 with 0.5x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" - `_. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - progress (bool): If True, displays a progress bar of the download to stderr - """ - return _shufflenetv2('shufflenetv2_x0.5', pretrained, progress, - [4, 8, 4], [24, 48, 96, 192, 1024], **kwargs) - - -def shufflenet_v2_x1_0(pretrained=False, progress=True, **kwargs): - """ - Constructs a ShuffleNetV2 with 1.0x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" - `_. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - progress (bool): If True, displays a progress bar of the download to stderr - """ - return _shufflenetv2('shufflenetv2_x1.0', pretrained, progress, - [4, 8, 4], [24, 116, 232, 464, 1024], **kwargs) - - -def shufflenet_v2_x1_5(pretrained=False, progress=True, **kwargs): - """ - Constructs a ShuffleNetV2 with 1.5x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" - `_. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - progress (bool): If True, displays a progress bar of the download to stderr - """ - return _shufflenetv2('shufflenetv2_x1.5', pretrained, progress, - [4, 8, 4], [24, 176, 352, 704, 1024], **kwargs) - - -def shufflenet_v2_x2_0(pretrained=False, progress=True, **kwargs): - """ - Constructs a ShuffleNetV2 with 2.0x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" - `_. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - progress (bool): If True, displays a progress bar of the download to stderr - """ - return _shufflenetv2('shufflenetv2_x2.0', pretrained, progress, - [4, 8, 4], [24, 244, 488, 976, 2048], **kwargs) - -if __name__ == '__main__': - dummy_input = torch.randn(1, 3, 224, 224) - model = shufflenet_v2_x1_0() - torch.onnx.export(model, dummy_input, "shufflenetv2.onnx", verbose=True,opset_version=11) - +import torch +import torch.nn as nn + + +__all__ = [ + 'ShuffleNetV2', 'shufflenet_v2_x0_5', 'shufflenet_v2_x1_0', + 'shufflenet_v2_x1_5', 'shufflenet_v2_x2_0' +] + +model_urls = { + 'shufflenetv2_x0.5': 'https://download.pytorch.org/models/shufflenetv2_x0.5-f707e7126e.pth', + 'shufflenetv2_x1.0': 'https://download.pytorch.org/models/shufflenetv2_x1-5666bf0f80.pth', + 'shufflenetv2_x1.5': None, + 'shufflenetv2_x2.0': None, +} + + +def channel_shuffle(x, groups): + # type: (torch.Tensor, int) -> torch.Tensor + batchsize, num_channels, height, width = x.data.size() + channels_per_group = num_channels // groups + + # reshape + x = x.view(batchsize, groups, + channels_per_group, height, width) + + x = torch.transpose(x, 1, 2).contiguous() + + # flatten + x = x.view(batchsize, -1, height, width) + + return x + + +class InvertedResidual(nn.Module): + def __init__(self, inp, oup, stride): + super(InvertedResidual, self).__init__() + + if not (1 <= stride <= 3): + raise ValueError('illegal stride value') + self.stride = stride + + branch_features = oup // 2 + assert (self.stride != 1) or (inp == branch_features << 1) + + if self.stride > 1: + self.branch1 = nn.Sequential( + self.depthwise_conv(inp, inp, kernel_size=3, stride=self.stride, padding=1), + nn.BatchNorm2d(inp), + nn.Conv2d(inp, branch_features, kernel_size=1, stride=1, padding=0, bias=False), + nn.BatchNorm2d(branch_features), + nn.ReLU(inplace=True), + ) + else: + self.branch1 = nn.Sequential() + + self.branch2 = nn.Sequential( + nn.Conv2d(inp if (self.stride > 1) else branch_features, + branch_features, kernel_size=1, stride=1, padding=0, bias=False), + nn.BatchNorm2d(branch_features), + nn.ReLU(inplace=True), + self.depthwise_conv(branch_features, branch_features, kernel_size=3, stride=self.stride, padding=1), + nn.BatchNorm2d(branch_features), + nn.Conv2d(branch_features, branch_features, kernel_size=1, stride=1, padding=0, bias=False), + nn.BatchNorm2d(branch_features), + nn.ReLU(inplace=True), + ) + + @staticmethod + def depthwise_conv(i, o, kernel_size, stride=1, padding=0, bias=False): + return nn.Conv2d(i, o, kernel_size, stride, padding, bias=bias, groups=i) + + def forward(self, x): + if self.stride == 1: + x1, x2 = x.chunk(2, dim=1) + out = torch.cat((x1, self.branch2(x2)), dim=1) + else: + out = torch.cat((self.branch1(x), self.branch2(x)), dim=1) + + out = channel_shuffle(out, 2) + + return out + + +class ShuffleNetV2(nn.Module): + def __init__(self, stages_repeats, stages_out_channels, num_classes=1000, inverted_residual=InvertedResidual): + super(ShuffleNetV2, self).__init__() + + if len(stages_repeats) != 3: + raise ValueError('expected stages_repeats as list of 3 positive ints') + if len(stages_out_channels) != 5: + raise ValueError('expected stages_out_channels as list of 5 positive ints') + self._stage_out_channels = stages_out_channels + + input_channels = 3 + output_channels = self._stage_out_channels[0] + self.conv1 = nn.Sequential( + nn.Conv2d(input_channels, output_channels, 3, 2, 1, bias=False), + nn.BatchNorm2d(output_channels), + nn.ReLU(inplace=True), + ) + input_channels = output_channels + + self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) + + stage_names = ['stage{}'.format(i) for i in [2, 3, 4]] + for name, repeats, output_channels in zip( + stage_names, stages_repeats, self._stage_out_channels[1:]): + seq = [inverted_residual(input_channels, output_channels, 2)] + for i in range(repeats - 1): + seq.append(inverted_residual(output_channels, output_channels, 1)) + setattr(self, name, nn.Sequential(*seq)) + input_channels = output_channels + + output_channels = self._stage_out_channels[-1] + self.conv5 = nn.Sequential( + nn.Conv2d(input_channels, output_channels, 1, 1, 0, bias=False), + nn.BatchNorm2d(output_channels), + nn.ReLU(inplace=True), + ) + + self.fc = nn.Linear(output_channels, num_classes) + + def _forward_impl(self, x): + # See note [TorchScript super()] + x = self.conv1(x) + x = self.maxpool(x) + x = self.stage2(x) + x = self.stage3(x) + x = self.stage4(x) + x = self.conv5(x) + x = x.mean([2, 3]) # globalpool + x = self.fc(x) + return x + + def forward(self, x): + return self._forward_impl(x) + + +def _shufflenetv2(arch, pretrained, progress, *args, **kwargs): + model = ShuffleNetV2(*args, **kwargs) + + if pretrained: + model_url = model_urls[arch] + if model_url is None: + raise NotImplementedError('pretrained {} is not supported as of now'.format(arch)) + else: + state_dict = load_state_dict_from_url(model_url, progress=progress) + model.load_state_dict(state_dict) + + return model + + +def shufflenet_v2_x0_5(pretrained=False, progress=True, **kwargs): + """ + Constructs a ShuffleNetV2 with 0.5x output channels, as described in + `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" + `_. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + progress (bool): If True, displays a progress bar of the download to stderr + """ + return _shufflenetv2('shufflenetv2_x0.5', pretrained, progress, + [4, 8, 4], [24, 48, 96, 192, 1024], **kwargs) + + +def shufflenet_v2_x1_0(pretrained=False, progress=True, **kwargs): + """ + Constructs a ShuffleNetV2 with 1.0x output channels, as described in + `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" + `_. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + progress (bool): If True, displays a progress bar of the download to stderr + """ + return _shufflenetv2('shufflenetv2_x1.0', pretrained, progress, + [4, 8, 4], [24, 116, 232, 464, 1024], **kwargs) + + +def shufflenet_v2_x1_5(pretrained=False, progress=True, **kwargs): + """ + Constructs a ShuffleNetV2 with 1.5x output channels, as described in + `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" + `_. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + progress (bool): If True, displays a progress bar of the download to stderr + """ + return _shufflenetv2('shufflenetv2_x1.5', pretrained, progress, + [4, 8, 4], [24, 176, 352, 704, 1024], **kwargs) + + +def shufflenet_v2_x2_0(pretrained=False, progress=True, **kwargs): + """ + Constructs a ShuffleNetV2 with 2.0x output channels, as described in + `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" + `_. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + progress (bool): If True, displays a progress bar of the download to stderr + """ + return _shufflenetv2('shufflenetv2_x2.0', pretrained, progress, + [4, 8, 4], [24, 244, 488, 976, 2048], **kwargs) + +if __name__ == '__main__': + dummy_input = torch.randn(1, 3, 224, 224) + model = shufflenet_v2_x1_0() + torch.onnx.export(model, dummy_input, "shufflenetv2.onnx", verbose=True,opset_version=11) + diff --git a/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/shufflenetv2_wock_op_woct.py b/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/shufflenetv2_wock_op_woct.py index 5982afc50ecff3625f985155a2f9cd42de8dff05..e81cb5aebe348d09fee9680e6f0794f6d8b7ded0 100644 --- a/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/shufflenetv2_wock_op_woct.py +++ b/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/shufflenetv2_wock_op_woct.py @@ -1,256 +1,256 @@ -import torch -import torch.nn as nn - -try: - from .utils import load_state_dict_from_url -except: - pass - -import numpy as np - -__all__ = [ - 'ShuffleNetV2', 'shufflenet_v2_x0_5', 'shufflenet_v2_x1_0', - 'shufflenet_v2_x1_5', 'shufflenet_v2_x2_0' -] - -model_urls = { - 'shufflenetv2_x0.5': 'https://download.pytorch.org/models/shufflenetv2_x0.5-f707e7126e.pth', - 'shufflenetv2_x1.0': 'https://download.pytorch.org/models/shufflenetv2_x1-5666bf0f80.pth', - 'shufflenetv2_x1.5': None, - 'shufflenetv2_x2.0': None, -} - - - -def IndexSelectFullImplementationforward(x1, x2, fp_index, bp_index1, bp_index2): - x = torch.cat([x1, x2], dim=1) - result = x.index_select(1, fp_index) - return result - -def IndexSelectHalfImplementationforward(x1, x2, fp_index1, fp_index2, bp_index1, bp_index2): - x = torch.cat([x1, x2], dim=1) - return x.index_select(1, fp_index1), x.index_select(1, fp_index2) - - -class Channel_Shuffle(nn.Module): - def __init__(self, inp, groups=2, split_shuffle=True): - super(Channel_Shuffle, self).__init__() - - self.split_shuffle = split_shuffle - self.group_len = inp // groups - self.out = np.array(list(range(inp))).reshape(groups, self.group_len).transpose(1, 0).flatten().tolist() - if self.split_shuffle: - self.register_buffer('fp_index1', torch.tensor(self.out[:self.group_len])) - self.register_buffer('fp_index2', torch.tensor(self.out[self.group_len:])) - else: - self.register_buffer('fp_index', torch.tensor(self.out)) - # self.register_buffer('bp_index', torch.tensor(list(range(0, inp, 2))+list(range(1,inp,2)))) - self.register_buffer('bp_index1', torch.tensor(list(range(0, inp, 2)))) - self.register_buffer('bp_index2', torch.tensor(list(range(1, inp, 2)))) - - def forward(self, x1, x2): - if self.split_shuffle: - return IndexSelectHalfImplementationforward(x1, x2, self.fp_index1, self.fp_index2, self.bp_index1, - self.bp_index2) - else: - return IndexSelectFullImplementationforward(x1, x2, self.fp_index, self.bp_index1, self.bp_index2) - - -class InvertedResidual(nn.Module): - def __init__(self, inp, oup, stride, split_shuffle=True): - super(InvertedResidual, self).__init__() - - if not (1 <= stride <= 3): - raise ValueError('illegal stride value') - self.stride = stride - - branch_features = oup // 2 - assert (self.stride != 1) or (inp == branch_features << 1) - - if self.stride > 1: - self.branch1 = nn.Sequential( - self.depthwise_conv(inp, inp, kernel_size=3, stride=self.stride, padding=1), - nn.BatchNorm2d(inp), - nn.Conv2d(inp, branch_features, kernel_size=1, stride=1, padding=0, bias=False), - nn.BatchNorm2d(branch_features), - nn.ReLU(inplace=True), - ) - else: - self.branch1 = nn.Sequential() - - self.branch2 = nn.Sequential( - nn.Conv2d(inp if (self.stride > 1) else branch_features, - branch_features, kernel_size=1, stride=1, padding=0, bias=False), - nn.BatchNorm2d(branch_features), - nn.ReLU(inplace=True), - self.depthwise_conv(branch_features, branch_features, kernel_size=3, stride=self.stride, padding=1), - nn.BatchNorm2d(branch_features), - nn.Conv2d(branch_features, branch_features, kernel_size=1, stride=1, padding=0, bias=False), - nn.BatchNorm2d(branch_features), - nn.ReLU(inplace=True), - ) - - if self.stride > 1: - self.channel_shuffle = Channel_Shuffle(inp=branch_features + branch_features, groups=2, - split_shuffle=split_shuffle) - else: - self.channel_shuffle = Channel_Shuffle(inp=inp, groups=2, split_shuffle=split_shuffle) - - @staticmethod - def depthwise_conv(i, o, kernel_size, stride=1, padding=0, bias=False): - return nn.Conv2d(i, o, kernel_size, stride, padding, bias=bias, groups=i) - - def forward(self, x): - if self.stride == 1: - x1, x2 = x - x2 = self.branch2(x2) - else: - x1 = self.branch1(x) - x2 = self.branch2(x) - - # out = channel_shuffle(out, 2) - out = self.channel_shuffle(x1, x2) - - return out - - -class ShuffleNetV2(nn.Module): - def __init__(self, stages_repeats, stages_out_channels, num_classes=1000, inverted_residual=InvertedResidual): - super(ShuffleNetV2, self).__init__() - - if len(stages_repeats) != 3: - raise ValueError('expected stages_repeats as list of 3 positive ints') - if len(stages_out_channels) != 5: - raise ValueError('expected stages_out_channels as list of 5 positive ints') - self._stage_out_channels = stages_out_channels - - input_channels = 3 - output_channels = self._stage_out_channels[0] - self.conv1 = nn.Sequential( - nn.Conv2d(input_channels, output_channels, 3, 2, 1, bias=False), - nn.BatchNorm2d(output_channels), - nn.ReLU(inplace=True), - ) - input_channels = output_channels - - self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) - - stage_names = ['stage{}'.format(i) for i in [2, 3, 4]] - for name, repeats, output_channels in zip( - stage_names, stages_repeats, self._stage_out_channels[1:]): - seq = [inverted_residual(input_channels, output_channels, 2)] - for i in range(repeats - 1): - if i == repeats - 2: - seq.append(inverted_residual(output_channels, output_channels, 1, split_shuffle=False)) - else: - seq.append(inverted_residual(output_channels, output_channels, 1)) - setattr(self, name, nn.Sequential(*seq)) - input_channels = output_channels - - output_channels = self._stage_out_channels[-1] - self.conv5 = nn.Sequential( - nn.Conv2d(input_channels, output_channels, 1, 1, 0, bias=False), - nn.BatchNorm2d(output_channels), - nn.ReLU(inplace=True), - ) - - self.fc = nn.Linear(output_channels, num_classes) - - self.avgpool = nn.AdaptiveAvgPool2d((1, 1)) - - def _forward_impl(self, x): - - # See note [TorchScript super()] - x = self.conv1(x) - x = self.maxpool(x) - x = self.stage2(x) - x = self.stage3(x) - x = self.stage4(x) - x = self.conv5(x) - # x = x.mean([2, 3]) # globalpool - x = self.avgpool(x) - x = torch.flatten(x, 1) - - x = self.fc(x) - return x - - def forward(self, x): - return self._forward_impl(x) - - -def _shufflenetv2(arch, pretrained, progress, *args, **kwargs): - model = ShuffleNetV2(*args, **kwargs) - - if pretrained: - model_url = model_urls[arch] - if model_url is None: - raise NotImplementedError('pretrained {} is not supported as of now'.format(arch)) - else: - state_dict = load_state_dict_from_url(model_url, progress=progress) - model.load_state_dict(state_dict) - - return model - - -def shufflenet_v2_x0_5(pretrained=False, progress=True, **kwargs): - """ - Constructs a ShuffleNetV2 with 0.5x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" - `_. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - progress (bool): If True, displays a progress bar of the download to stderr - """ - return _shufflenetv2('shufflenetv2_x0.5', pretrained, progress, - [4, 8, 4], [24, 48, 96, 192, 1024], **kwargs) - - -def shufflenet_v2_x1_0(pretrained=False, progress=True, **kwargs): - """ - Constructs a ShuffleNetV2 with 1.0x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" - `_. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - progress (bool): If True, displays a progress bar of the download to stderr - """ - return _shufflenetv2('shufflenetv2_x1.0', pretrained, progress, - [4, 8, 4], [24, 116, 232, 464, 1024], **kwargs) - # return _shufflenetv2('shufflenetv2_x1.0', pretrained, progress, - # [4, 8, 4], [16, 128, 256, 464, 1024], **kwargs) - - -def shufflenet_v2_x1_5(pretrained=False, progress=True, **kwargs): - """ - Constructs a ShuffleNetV2 with 1.5x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" - `_. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - progress (bool): If True, displays a progress bar of the download to stderr - """ - return _shufflenetv2('shufflenetv2_x1.5', pretrained, progress, - [4, 8, 4], [24, 176, 352, 704, 1024], **kwargs) - - -def shufflenet_v2_x2_0(pretrained=False, progress=True, **kwargs): - """ - Constructs a ShuffleNetV2 with 2.0x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" - `_. - - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - progress (bool): If True, displays a progress bar of the download to stderr - """ - return _shufflenetv2('shufflenetv2_x2.0', pretrained, progress, - [4, 8, 4], [24, 244, 488, 976, 2048], **kwargs) - - -if __name__ == '__main__': - dummy_input = torch.randn(1, 3, 224, 224) - model = shufflenet_v2_x1_0() - torch.onnx.export(model, dummy_input, "shufflenetv2.onnx", verbose=True,opset_version=11) +import torch +import torch.nn as nn + +try: + from .utils import load_state_dict_from_url +except: + pass + +import numpy as np + +__all__ = [ + 'ShuffleNetV2', 'shufflenet_v2_x0_5', 'shufflenet_v2_x1_0', + 'shufflenet_v2_x1_5', 'shufflenet_v2_x2_0' +] + +model_urls = { + 'shufflenetv2_x0.5': 'https://download.pytorch.org/models/shufflenetv2_x0.5-f707e7126e.pth', + 'shufflenetv2_x1.0': 'https://download.pytorch.org/models/shufflenetv2_x1-5666bf0f80.pth', + 'shufflenetv2_x1.5': None, + 'shufflenetv2_x2.0': None, +} + + + +def IndexSelectFullImplementationforward(x1, x2, fp_index, bp_index1, bp_index2): + x = torch.cat([x1, x2], dim=1) + result = x.index_select(1, fp_index) + return result + +def IndexSelectHalfImplementationforward(x1, x2, fp_index1, fp_index2, bp_index1, bp_index2): + x = torch.cat([x1, x2], dim=1) + return x.index_select(1, fp_index1), x.index_select(1, fp_index2) + + +class Channel_Shuffle(nn.Module): + def __init__(self, inp, groups=2, split_shuffle=True): + super(Channel_Shuffle, self).__init__() + + self.split_shuffle = split_shuffle + self.group_len = inp // groups + self.out = np.array(list(range(inp))).reshape(groups, self.group_len).transpose(1, 0).flatten().tolist() + if self.split_shuffle: + self.register_buffer('fp_index1', torch.tensor(self.out[:self.group_len])) + self.register_buffer('fp_index2', torch.tensor(self.out[self.group_len:])) + else: + self.register_buffer('fp_index', torch.tensor(self.out)) + # self.register_buffer('bp_index', torch.tensor(list(range(0, inp, 2))+list(range(1,inp,2)))) + self.register_buffer('bp_index1', torch.tensor(list(range(0, inp, 2)))) + self.register_buffer('bp_index2', torch.tensor(list(range(1, inp, 2)))) + + def forward(self, x1, x2): + if self.split_shuffle: + return IndexSelectHalfImplementationforward(x1, x2, self.fp_index1, self.fp_index2, self.bp_index1, + self.bp_index2) + else: + return IndexSelectFullImplementationforward(x1, x2, self.fp_index, self.bp_index1, self.bp_index2) + + +class InvertedResidual(nn.Module): + def __init__(self, inp, oup, stride, split_shuffle=True): + super(InvertedResidual, self).__init__() + + if not (1 <= stride <= 3): + raise ValueError('illegal stride value') + self.stride = stride + + branch_features = oup // 2 + assert (self.stride != 1) or (inp == branch_features << 1) + + if self.stride > 1: + self.branch1 = nn.Sequential( + self.depthwise_conv(inp, inp, kernel_size=3, stride=self.stride, padding=1), + nn.BatchNorm2d(inp), + nn.Conv2d(inp, branch_features, kernel_size=1, stride=1, padding=0, bias=False), + nn.BatchNorm2d(branch_features), + nn.ReLU(inplace=True), + ) + else: + self.branch1 = nn.Sequential() + + self.branch2 = nn.Sequential( + nn.Conv2d(inp if (self.stride > 1) else branch_features, + branch_features, kernel_size=1, stride=1, padding=0, bias=False), + nn.BatchNorm2d(branch_features), + nn.ReLU(inplace=True), + self.depthwise_conv(branch_features, branch_features, kernel_size=3, stride=self.stride, padding=1), + nn.BatchNorm2d(branch_features), + nn.Conv2d(branch_features, branch_features, kernel_size=1, stride=1, padding=0, bias=False), + nn.BatchNorm2d(branch_features), + nn.ReLU(inplace=True), + ) + + if self.stride > 1: + self.channel_shuffle = Channel_Shuffle(inp=branch_features + branch_features, groups=2, + split_shuffle=split_shuffle) + else: + self.channel_shuffle = Channel_Shuffle(inp=inp, groups=2, split_shuffle=split_shuffle) + + @staticmethod + def depthwise_conv(i, o, kernel_size, stride=1, padding=0, bias=False): + return nn.Conv2d(i, o, kernel_size, stride, padding, bias=bias, groups=i) + + def forward(self, x): + if self.stride == 1: + x1, x2 = x + x2 = self.branch2(x2) + else: + x1 = self.branch1(x) + x2 = self.branch2(x) + + # out = channel_shuffle(out, 2) + out = self.channel_shuffle(x1, x2) + + return out + + +class ShuffleNetV2(nn.Module): + def __init__(self, stages_repeats, stages_out_channels, num_classes=1000, inverted_residual=InvertedResidual): + super(ShuffleNetV2, self).__init__() + + if len(stages_repeats) != 3: + raise ValueError('expected stages_repeats as list of 3 positive ints') + if len(stages_out_channels) != 5: + raise ValueError('expected stages_out_channels as list of 5 positive ints') + self._stage_out_channels = stages_out_channels + + input_channels = 3 + output_channels = self._stage_out_channels[0] + self.conv1 = nn.Sequential( + nn.Conv2d(input_channels, output_channels, 3, 2, 1, bias=False), + nn.BatchNorm2d(output_channels), + nn.ReLU(inplace=True), + ) + input_channels = output_channels + + self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) + + stage_names = ['stage{}'.format(i) for i in [2, 3, 4]] + for name, repeats, output_channels in zip( + stage_names, stages_repeats, self._stage_out_channels[1:]): + seq = [inverted_residual(input_channels, output_channels, 2)] + for i in range(repeats - 1): + if i == repeats - 2: + seq.append(inverted_residual(output_channels, output_channels, 1, split_shuffle=False)) + else: + seq.append(inverted_residual(output_channels, output_channels, 1)) + setattr(self, name, nn.Sequential(*seq)) + input_channels = output_channels + + output_channels = self._stage_out_channels[-1] + self.conv5 = nn.Sequential( + nn.Conv2d(input_channels, output_channels, 1, 1, 0, bias=False), + nn.BatchNorm2d(output_channels), + nn.ReLU(inplace=True), + ) + + self.fc = nn.Linear(output_channels, num_classes) + + self.avgpool = nn.AdaptiveAvgPool2d((1, 1)) + + def _forward_impl(self, x): + + # See note [TorchScript super()] + x = self.conv1(x) + x = self.maxpool(x) + x = self.stage2(x) + x = self.stage3(x) + x = self.stage4(x) + x = self.conv5(x) + # x = x.mean([2, 3]) # globalpool + x = self.avgpool(x) + x = torch.flatten(x, 1) + + x = self.fc(x) + return x + + def forward(self, x): + return self._forward_impl(x) + + +def _shufflenetv2(arch, pretrained, progress, *args, **kwargs): + model = ShuffleNetV2(*args, **kwargs) + + if pretrained: + model_url = model_urls[arch] + if model_url is None: + raise NotImplementedError('pretrained {} is not supported as of now'.format(arch)) + else: + state_dict = load_state_dict_from_url(model_url, progress=progress) + model.load_state_dict(state_dict) + + return model + + +def shufflenet_v2_x0_5(pretrained=False, progress=True, **kwargs): + """ + Constructs a ShuffleNetV2 with 0.5x output channels, as described in + `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" + `_. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + progress (bool): If True, displays a progress bar of the download to stderr + """ + return _shufflenetv2('shufflenetv2_x0.5', pretrained, progress, + [4, 8, 4], [24, 48, 96, 192, 1024], **kwargs) + + +def shufflenet_v2_x1_0(pretrained=False, progress=True, **kwargs): + """ + Constructs a ShuffleNetV2 with 1.0x output channels, as described in + `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" + `_. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + progress (bool): If True, displays a progress bar of the download to stderr + """ + return _shufflenetv2('shufflenetv2_x1.0', pretrained, progress, + [4, 8, 4], [24, 116, 232, 464, 1024], **kwargs) + # return _shufflenetv2('shufflenetv2_x1.0', pretrained, progress, + # [4, 8, 4], [16, 128, 256, 464, 1024], **kwargs) + + +def shufflenet_v2_x1_5(pretrained=False, progress=True, **kwargs): + """ + Constructs a ShuffleNetV2 with 1.5x output channels, as described in + `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" + `_. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + progress (bool): If True, displays a progress bar of the download to stderr + """ + return _shufflenetv2('shufflenetv2_x1.5', pretrained, progress, + [4, 8, 4], [24, 176, 352, 704, 1024], **kwargs) + + +def shufflenet_v2_x2_0(pretrained=False, progress=True, **kwargs): + """ + Constructs a ShuffleNetV2 with 2.0x output channels, as described in + `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" + `_. + + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + progress (bool): If True, displays a progress bar of the download to stderr + """ + return _shufflenetv2('shufflenetv2_x2.0', pretrained, progress, + [4, 8, 4], [24, 244, 488, 976, 2048], **kwargs) + + +if __name__ == '__main__': + dummy_input = torch.randn(1, 3, 224, 224) + model = shufflenet_v2_x1_0() + torch.onnx.export(model, dummy_input, "shufflenetv2.onnx", verbose=True,opset_version=11) diff --git a/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/vision_metric_ImageNet.py b/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/vision_metric_ImageNet.py index 7bba5f8346a8893b4567d92b900fc4a651115976..f07c93617e661619c0e00be6a972e39fbde966a0 100644 --- a/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/vision_metric_ImageNet.py +++ b/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch/vision_metric_ImageNet.py @@ -1,173 +1,173 @@ -#coding = utf-8 -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = "" - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - #print(filepath) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - #print(img_gt_dict) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - # print(img_name) - #print(n_labels) - # print(gt) - - resCnt = min(len(sort_index), topn) - # print(sort_index[:5]) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - #print("***************") - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - #print("Top" + str(i + 1) + " accuracy" + ": " + str(round(accuracy[i] * 100, 2)) + '%') - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - #print("Time used:", elapsed) +#coding = utf-8 +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = "" + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + #print(filepath) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + #print(img_gt_dict) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + # print(img_name) + #print(n_labels) + # print(gt) + + resCnt = min(len(sort_index), topn) + # print(sort_index[:5]) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + #print("***************") + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + #print("Top" + str(i + 1) + " accuracy" + ": " + str(round(accuracy[i] * 100, 2)) + '%') + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + #print("Time used:", elapsed) diff --git a/ACL_PyTorch/built-in/cv/U2-Net_for_PyTorch/gen_dataset_info.py b/ACL_PyTorch/built-in/cv/U2-Net_for_PyTorch/gen_dataset_info.py index efe82aef071e229c2f3212e1ec5a8531ad4d3e53..3656966b4cd924e11ac53b6449cdec237c0c64f7 100644 --- a/ACL_PyTorch/built-in/cv/U2-Net_for_PyTorch/gen_dataset_info.py +++ b/ACL_PyTorch/built-in/cv/U2-Net_for_PyTorch/gen_dataset_info.py @@ -1,65 +1,65 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(fpath, info_n, width, height): - ''' - Describe - ''' - bin_images = glob(os.path.join(fpath, '*.bin')) - with open(info_n, 'w') as f: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - f.write(content) - f.write('\n') - - -def get_jpg_info(fpath, info_n): - ''' - Describe - ''' - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(fpath, '*.' + extension))) - with open(info_n, 'w') as f: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - f.write(content) - f.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - Width = sys.argv[4] - Height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, Width, Height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(fpath, info_n, width, height): + ''' + Describe + ''' + bin_images = glob(os.path.join(fpath, '*.bin')) + with open(info_n, 'w') as f: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + f.write(content) + f.write('\n') + + +def get_jpg_info(fpath, info_n): + ''' + Describe + ''' + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(fpath, '*.' + extension))) + with open(info_n, 'w') as f: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + f.write(content) + f.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + Width = sys.argv[4] + Height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, Width, Height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) diff --git a/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/ReadMe.md b/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/ReadMe.md index 740e2ce6aea460a99c62dd0cb16fc6c28ee929bf..0e9f686545e1d92bb84cbb28d42ff7e1d2d310e8 100644 --- a/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/ReadMe.md +++ b/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/ReadMe.md @@ -1,48 +1,48 @@ -文件作用说明: - -1.auto_tune.sh:模型转换脚本,集成了auto tune功能,可以手动关闭 - -2.pth2onnx.py:用于转换pth文件到onnx文件 - -3.pthtar2onnx.py:用于转换pth.tar文件到onnx文件 - -4.BinaryImageNet.info:ImageNet数据集信息,用于benchmark推理获取数据集 - -5.PytorchTransfer.py:数据集预处理脚本,通过均值方差处理归一化图片 - -6.val_label.txt:ImageNet数据集标签,用于验证推理结果 - -7.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy - -8.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer - - - - - -推理端到端步骤: - -(1) 从Torchvision下载resnet50模型或者指定自己训练好的pth文件路径,通过pth2onnx.py脚本转化为onnx模型 - - - -(2)运行auto_tune.sh脚本转换om模型,也可以选择手动关闭auto_tune - -本demo已提供调优完成的om模型 - - - -(3)用PytorchTransfer.py脚本处理数据集,参考BinaryImageNet.Info配置处理后的二进制数据集路径 - - - -(4)./benchmark.x86_64 -model_type=vision -batch_size=16 -device_id=0 -input_text_path=./BinaryImageNet.info -input_width=224 -input_height=224 -om_path=./resnet50_pytorch.om -useDvpp=False - -运行benchmark推理,结果保存在 ./result 目录下 - - - -(5)python3.7 vision_metric_ImageNet.py result/dumpOutput/ ./val_label.txt ./ result.json - -验证推理结果 - +文件作用说明: + +1.auto_tune.sh:模型转换脚本,集成了auto tune功能,可以手动关闭 + +2.pth2onnx.py:用于转换pth文件到onnx文件 + +3.pthtar2onnx.py:用于转换pth.tar文件到onnx文件 + +4.BinaryImageNet.info:ImageNet数据集信息,用于benchmark推理获取数据集 + +5.PytorchTransfer.py:数据集预处理脚本,通过均值方差处理归一化图片 + +6.val_label.txt:ImageNet数据集标签,用于验证推理结果 + +7.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy + +8.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer + + + + + +推理端到端步骤: + +(1) 从Torchvision下载resnet50模型或者指定自己训练好的pth文件路径,通过pth2onnx.py脚本转化为onnx模型 + + + +(2)运行auto_tune.sh脚本转换om模型,也可以选择手动关闭auto_tune + +本demo已提供调优完成的om模型 + + + +(3)用PytorchTransfer.py脚本处理数据集,参考BinaryImageNet.Info配置处理后的二进制数据集路径 + + + +(4)./benchmark.x86_64 -model_type=vision -batch_size=16 -device_id=0 -input_text_path=./BinaryImageNet.info -input_width=224 -input_height=224 -om_path=./resnet50_pytorch.om -useDvpp=False + +运行benchmark推理,结果保存在 ./result 目录下 + + + +(5)python3.7 vision_metric_ImageNet.py result/dumpOutput/ ./val_label.txt ./ result.json + +验证推理结果 + diff --git a/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/get_info.py b/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/get_info.py index da181d8d0342e52eb33b38fa475ae812a61575cf..c68e7705e47c90970ab04e5f139e52192a634364 100644 --- a/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/get_info.py +++ b/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/get_info.py @@ -1,16 +1,16 @@ -import os -import sys -from glob import glob - -file_path = sys.argv[1] -info_name = sys.argv[2] -width = sys.argv[3] -height = sys.argv[4] - -bin_images = glob(os.path.join(file_path, '*')) - -with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') +import os +import sys +from glob import glob + +file_path = sys.argv[1] +info_name = sys.argv[2] +width = sys.argv[3] +height = sys.argv[4] + +bin_images = glob(os.path.join(file_path, '*')) + +with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') diff --git a/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/preprocess_vgg_pytorch.py b/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/preprocess_vgg_pytorch.py index a36b47f2fbb1990f49256c64a4727aa823759e46..1ac2a414d22d45cc37f09e2cb412b5057e81e694 100644 --- a/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/preprocess_vgg_pytorch.py +++ b/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/preprocess_vgg_pytorch.py @@ -1,83 +1,83 @@ -import os -import sys -import numpy as np -from PIL import Image - - -def resize(img, size, interpolation=Image.BILINEAR): - r"""Resize the input PIL Image to the given size. - - Args: - img (PIL Image): Image to be resized. - size (sequence or int): Desired output size. If size is a sequence like - (h, w), the output size will be matched to this. If size is an int, - the smaller edge of the image will be matched to this number maintaining - the aspect ratio. i.e, if height > width, then image will be rescaled to - :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)` - interpolation (int, optional): Desired interpolation. Default is - ``PIL.Image.BILINEAR`` - - Returns: - PIL Image: Resized image. - """ - - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def center_crop(img, out_height, out_width): - height, width, _ = img.shape - left = int((width - out_width) / 2) - right = int((width + out_width) / 2) - top = int((height - out_height) / 2) - bottom = int((height + out_height) / 2) - img = img[top:bottom, left:right] - return img - - -def deepmar_onnx(file_path, bin_path): - in_files = os.listdir(file_path) - if not os.path.exists(bin_path): - os.makedirs(bin_path) - i = 0 - input_size = (256, 256) - mean = [0.485, 0.456, 0.406] - std = [0.229, 0.224, 0.225] - for file in in_files: - i = i + 1 - print(file, "====", i) - img = Image.open(os.path.join(file_path, file)).convert('RGB') - img = resize(img, input_size) # transforms.Resize(256) - img = np.array(img, dtype=np.float32) - img = center_crop(img, 224, 224) # transforms.CenterCrop(224) - - img = img / 255. # transforms.ToTensor() - - # 均值方差 - img[..., 0] -= mean[0] - img[..., 1] -= mean[1] - img[..., 2] -= mean[2] - img[..., 0] /= std[0] - img[..., 1] /= std[1] - img[..., 2] /= std[2] - - img = img.transpose(2, 0, 1) # HWC -> CHW - img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) - - -if __name__ == "__main__": - file_path = os.path.abspath(sys.argv[1]) - bin_path = os.path.abspath(sys.argv[2]) - deepmar_onnx(file_path, bin_path) +import os +import sys +import numpy as np +from PIL import Image + + +def resize(img, size, interpolation=Image.BILINEAR): + r"""Resize the input PIL Image to the given size. + + Args: + img (PIL Image): Image to be resized. + size (sequence or int): Desired output size. If size is a sequence like + (h, w), the output size will be matched to this. If size is an int, + the smaller edge of the image will be matched to this number maintaining + the aspect ratio. i.e, if height > width, then image will be rescaled to + :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)` + interpolation (int, optional): Desired interpolation. Default is + ``PIL.Image.BILINEAR`` + + Returns: + PIL Image: Resized image. + """ + + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def center_crop(img, out_height, out_width): + height, width, _ = img.shape + left = int((width - out_width) / 2) + right = int((width + out_width) / 2) + top = int((height - out_height) / 2) + bottom = int((height + out_height) / 2) + img = img[top:bottom, left:right] + return img + + +def deepmar_onnx(file_path, bin_path): + in_files = os.listdir(file_path) + if not os.path.exists(bin_path): + os.makedirs(bin_path) + i = 0 + input_size = (256, 256) + mean = [0.485, 0.456, 0.406] + std = [0.229, 0.224, 0.225] + for file in in_files: + i = i + 1 + print(file, "====", i) + img = Image.open(os.path.join(file_path, file)).convert('RGB') + img = resize(img, input_size) # transforms.Resize(256) + img = np.array(img, dtype=np.float32) + img = center_crop(img, 224, 224) # transforms.CenterCrop(224) + + img = img / 255. # transforms.ToTensor() + + # 均值方差 + img[..., 0] -= mean[0] + img[..., 1] -= mean[1] + img[..., 2] -= mean[2] + img[..., 0] /= std[0] + img[..., 1] /= std[1] + img[..., 2] /= std[2] + + img = img.transpose(2, 0, 1) # HWC -> CHW + img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) + + +if __name__ == "__main__": + file_path = os.path.abspath(sys.argv[1]) + bin_path = os.path.abspath(sys.argv[2]) + deepmar_onnx(file_path, bin_path) diff --git a/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/vision_metric_ImageNet.py b/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/vision_metric_ImageNet.py index 7bba5f8346a8893b4567d92b900fc4a651115976..f07c93617e661619c0e00be6a972e39fbde966a0 100644 --- a/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/vision_metric_ImageNet.py +++ b/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch/vision_metric_ImageNet.py @@ -1,173 +1,173 @@ -#coding = utf-8 -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = "" - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - #print(filepath) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - #print(img_gt_dict) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - # print(img_name) - #print(n_labels) - # print(gt) - - resCnt = min(len(sort_index), topn) - # print(sort_index[:5]) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - #print("***************") - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - #print("Top" + str(i + 1) + " accuracy" + ": " + str(round(accuracy[i] * 100, 2)) + '%') - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - #print("Time used:", elapsed) +#coding = utf-8 +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = "" + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + #print(filepath) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + #print(img_gt_dict) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + # print(img_name) + #print(n_labels) + # print(gt) + + resCnt = min(len(sort_index), topn) + # print(sort_index[:5]) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + #print("***************") + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + #print("Top" + str(i + 1) + " accuracy" + ": " + str(round(accuracy[i] * 100, 2)) + '%') + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + #print("Time used:", elapsed) diff --git a/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/ReadMe.md b/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/ReadMe.md index 740e2ce6aea460a99c62dd0cb16fc6c28ee929bf..0e9f686545e1d92bb84cbb28d42ff7e1d2d310e8 100644 --- a/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/ReadMe.md +++ b/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/ReadMe.md @@ -1,48 +1,48 @@ -文件作用说明: - -1.auto_tune.sh:模型转换脚本,集成了auto tune功能,可以手动关闭 - -2.pth2onnx.py:用于转换pth文件到onnx文件 - -3.pthtar2onnx.py:用于转换pth.tar文件到onnx文件 - -4.BinaryImageNet.info:ImageNet数据集信息,用于benchmark推理获取数据集 - -5.PytorchTransfer.py:数据集预处理脚本,通过均值方差处理归一化图片 - -6.val_label.txt:ImageNet数据集标签,用于验证推理结果 - -7.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy - -8.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer - - - - - -推理端到端步骤: - -(1) 从Torchvision下载resnet50模型或者指定自己训练好的pth文件路径,通过pth2onnx.py脚本转化为onnx模型 - - - -(2)运行auto_tune.sh脚本转换om模型,也可以选择手动关闭auto_tune - -本demo已提供调优完成的om模型 - - - -(3)用PytorchTransfer.py脚本处理数据集,参考BinaryImageNet.Info配置处理后的二进制数据集路径 - - - -(4)./benchmark.x86_64 -model_type=vision -batch_size=16 -device_id=0 -input_text_path=./BinaryImageNet.info -input_width=224 -input_height=224 -om_path=./resnet50_pytorch.om -useDvpp=False - -运行benchmark推理,结果保存在 ./result 目录下 - - - -(5)python3.7 vision_metric_ImageNet.py result/dumpOutput/ ./val_label.txt ./ result.json - -验证推理结果 - +文件作用说明: + +1.auto_tune.sh:模型转换脚本,集成了auto tune功能,可以手动关闭 + +2.pth2onnx.py:用于转换pth文件到onnx文件 + +3.pthtar2onnx.py:用于转换pth.tar文件到onnx文件 + +4.BinaryImageNet.info:ImageNet数据集信息,用于benchmark推理获取数据集 + +5.PytorchTransfer.py:数据集预处理脚本,通过均值方差处理归一化图片 + +6.val_label.txt:ImageNet数据集标签,用于验证推理结果 + +7.vision_metric_ImageNet.py:验证推理结果脚本,比对benchmark输出的分类结果和标签,给出Accuracy + +8.benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer + + + + + +推理端到端步骤: + +(1) 从Torchvision下载resnet50模型或者指定自己训练好的pth文件路径,通过pth2onnx.py脚本转化为onnx模型 + + + +(2)运行auto_tune.sh脚本转换om模型,也可以选择手动关闭auto_tune + +本demo已提供调优完成的om模型 + + + +(3)用PytorchTransfer.py脚本处理数据集,参考BinaryImageNet.Info配置处理后的二进制数据集路径 + + + +(4)./benchmark.x86_64 -model_type=vision -batch_size=16 -device_id=0 -input_text_path=./BinaryImageNet.info -input_width=224 -input_height=224 -om_path=./resnet50_pytorch.om -useDvpp=False + +运行benchmark推理,结果保存在 ./result 目录下 + + + +(5)python3.7 vision_metric_ImageNet.py result/dumpOutput/ ./val_label.txt ./ result.json + +验证推理结果 + diff --git a/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/get_info.py b/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/get_info.py index da181d8d0342e52eb33b38fa475ae812a61575cf..c68e7705e47c90970ab04e5f139e52192a634364 100644 --- a/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/get_info.py +++ b/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/get_info.py @@ -1,16 +1,16 @@ -import os -import sys -from glob import glob - -file_path = sys.argv[1] -info_name = sys.argv[2] -width = sys.argv[3] -height = sys.argv[4] - -bin_images = glob(os.path.join(file_path, '*')) - -with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') +import os +import sys +from glob import glob + +file_path = sys.argv[1] +info_name = sys.argv[2] +width = sys.argv[3] +height = sys.argv[4] + +bin_images = glob(os.path.join(file_path, '*')) + +with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') diff --git a/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/preprocess_vgg_pytorch.py b/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/preprocess_vgg_pytorch.py index a36b47f2fbb1990f49256c64a4727aa823759e46..1ac2a414d22d45cc37f09e2cb412b5057e81e694 100644 --- a/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/preprocess_vgg_pytorch.py +++ b/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/preprocess_vgg_pytorch.py @@ -1,83 +1,83 @@ -import os -import sys -import numpy as np -from PIL import Image - - -def resize(img, size, interpolation=Image.BILINEAR): - r"""Resize the input PIL Image to the given size. - - Args: - img (PIL Image): Image to be resized. - size (sequence or int): Desired output size. If size is a sequence like - (h, w), the output size will be matched to this. If size is an int, - the smaller edge of the image will be matched to this number maintaining - the aspect ratio. i.e, if height > width, then image will be rescaled to - :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)` - interpolation (int, optional): Desired interpolation. Default is - ``PIL.Image.BILINEAR`` - - Returns: - PIL Image: Resized image. - """ - - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def center_crop(img, out_height, out_width): - height, width, _ = img.shape - left = int((width - out_width) / 2) - right = int((width + out_width) / 2) - top = int((height - out_height) / 2) - bottom = int((height + out_height) / 2) - img = img[top:bottom, left:right] - return img - - -def deepmar_onnx(file_path, bin_path): - in_files = os.listdir(file_path) - if not os.path.exists(bin_path): - os.makedirs(bin_path) - i = 0 - input_size = (256, 256) - mean = [0.485, 0.456, 0.406] - std = [0.229, 0.224, 0.225] - for file in in_files: - i = i + 1 - print(file, "====", i) - img = Image.open(os.path.join(file_path, file)).convert('RGB') - img = resize(img, input_size) # transforms.Resize(256) - img = np.array(img, dtype=np.float32) - img = center_crop(img, 224, 224) # transforms.CenterCrop(224) - - img = img / 255. # transforms.ToTensor() - - # 均值方差 - img[..., 0] -= mean[0] - img[..., 1] -= mean[1] - img[..., 2] -= mean[2] - img[..., 0] /= std[0] - img[..., 1] /= std[1] - img[..., 2] /= std[2] - - img = img.transpose(2, 0, 1) # HWC -> CHW - img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) - - -if __name__ == "__main__": - file_path = os.path.abspath(sys.argv[1]) - bin_path = os.path.abspath(sys.argv[2]) - deepmar_onnx(file_path, bin_path) +import os +import sys +import numpy as np +from PIL import Image + + +def resize(img, size, interpolation=Image.BILINEAR): + r"""Resize the input PIL Image to the given size. + + Args: + img (PIL Image): Image to be resized. + size (sequence or int): Desired output size. If size is a sequence like + (h, w), the output size will be matched to this. If size is an int, + the smaller edge of the image will be matched to this number maintaining + the aspect ratio. i.e, if height > width, then image will be rescaled to + :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)` + interpolation (int, optional): Desired interpolation. Default is + ``PIL.Image.BILINEAR`` + + Returns: + PIL Image: Resized image. + """ + + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def center_crop(img, out_height, out_width): + height, width, _ = img.shape + left = int((width - out_width) / 2) + right = int((width + out_width) / 2) + top = int((height - out_height) / 2) + bottom = int((height + out_height) / 2) + img = img[top:bottom, left:right] + return img + + +def deepmar_onnx(file_path, bin_path): + in_files = os.listdir(file_path) + if not os.path.exists(bin_path): + os.makedirs(bin_path) + i = 0 + input_size = (256, 256) + mean = [0.485, 0.456, 0.406] + std = [0.229, 0.224, 0.225] + for file in in_files: + i = i + 1 + print(file, "====", i) + img = Image.open(os.path.join(file_path, file)).convert('RGB') + img = resize(img, input_size) # transforms.Resize(256) + img = np.array(img, dtype=np.float32) + img = center_crop(img, 224, 224) # transforms.CenterCrop(224) + + img = img / 255. # transforms.ToTensor() + + # 均值方差 + img[..., 0] -= mean[0] + img[..., 1] -= mean[1] + img[..., 2] -= mean[2] + img[..., 0] /= std[0] + img[..., 1] /= std[1] + img[..., 2] /= std[2] + + img = img.transpose(2, 0, 1) # HWC -> CHW + img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) + + +if __name__ == "__main__": + file_path = os.path.abspath(sys.argv[1]) + bin_path = os.path.abspath(sys.argv[2]) + deepmar_onnx(file_path, bin_path) diff --git a/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/vision_metric_ImageNet.py b/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/vision_metric_ImageNet.py index 7bba5f8346a8893b4567d92b900fc4a651115976..f07c93617e661619c0e00be6a972e39fbde966a0 100644 --- a/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/vision_metric_ImageNet.py +++ b/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch/vision_metric_ImageNet.py @@ -1,173 +1,173 @@ -#coding = utf-8 -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = "" - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - #print(filepath) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - #print(img_gt_dict) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - # print(img_name) - #print(n_labels) - # print(gt) - - resCnt = min(len(sort_index), topn) - # print(sort_index[:5]) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - #print("***************") - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - #print("Top" + str(i + 1) + " accuracy" + ": " + str(round(accuracy[i] * 100, 2)) + '%') - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - #print("Time used:", elapsed) +#coding = utf-8 +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = "" + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + #print(filepath) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + #print(img_gt_dict) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + # print(img_name) + #print(n_labels) + # print(gt) + + resCnt = min(len(sort_index), topn) + # print(sort_index[:5]) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + #print("***************") + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + #print("Top" + str(i + 1) + " accuracy" + ": " + str(round(accuracy[i] * 100, 2)) + '%') + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + #print("Time used:", elapsed) diff --git a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/LICENSE b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/LICENSE index df2c2f2c3e55bfbad1aebe53321a94ee5a3854bc..c8ec075d5b892f823d0b485ad4fdd01355c57b3e 100644 --- a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/LICENSE +++ b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/LICENSE @@ -1,203 +1,203 @@ -Copyright 2018-2019 Open-MMLab. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2018-2019 Open-MMLab. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and +Copyright 2018-2019 Open-MMLab. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2019 Open-MMLab. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/README.md b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/README.md index a66e9ee510332636b4b9e64d372a4a90911ce7b0..c7ab4c279c1da9dea8d02b3435f0d853e81fcec5 100644 --- a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/README.md +++ b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/README.md @@ -1,112 +1,112 @@ -# yolact_edge模型推理指导 - -- [yolact_edge模型推理指导](#yolact_edge模型推理指导) - - [1 文件说明](#1-文件说明) - - [2 环境准备](#2-环境准备) - - [2.1 安装依赖](#21-安装依赖) - - [2.2 文件下载](#22-文件下载) - - [2.3 文件拷贝](#23-文件拷贝) - - [2.4 设置环境变量](#24-设置环境变量) - - [3 端到端推理步骤](#3-端到端推理步骤) - - [3.1 pth导出onnx](#31-pth导出onnx) - - [3.2 利用ATC工具转换为om模型](#32-利用atc工具转换为om模型) - - [3.3 om模型推理](#33-om模型推理) - - [3.4 纯推理性能获取](#34-纯推理性能获取) - - [4 评测结果](#4-评测结果) - ------- - -## 1 文件说明 -``` -yolact_edge_for_Pytorch - ├── env.sh 设置环境变量 - ├── pth2onnx.py pytorch模型导出onnx模型 - ├── atc.sh onnx模型转om - ├── yolact_edge.diff 补丁文件 - └── acl_net.py PyACL推理工具代码 -``` - -## 2 环境准备 - -### 2.1 安装依赖 - -根据pytorch官网教程安装1.10.0版本的PyTorch -```shell -pip install torch==1.10.0+cpu torchvision==0.11.1+cpu torchaudio==0.10.0+cpu -pip install -r requirements.txt -pip install git+https://github.com/haotian-liu/cocoapi.git#"egg=pycocotools&subdirectory=PythonAPI" -``` - -### 2.2 文件下载 -- [yolact_edge_Pytorch源码下载](https://github.com/haotian-liu/yolact_edge) - - ```shell - git clone git@github.com:haotian-liu/yolact_edge.git - cd yolact_edge - git reset a9a00281b33b3ac90253a4939773308a8f95e21d --hard - git apply yolact_edge.diff - ``` - -- 权重下载 - - 创建 `weights` 目录,并将下载的权重文件 `yolact_edge_resnet50_54_800000.pth` 拷贝到 `weights` 目录下。 - 可参见[yolact_edge_Pytorch主页](https://github.com/haotian-liu/yolact_edge)说明下载权重 - -- 数据集下载 - - om推理采用COCO2017数据集的验证集进行精度评估。将下载好的数据集拷贝到 `data/coco` 目录下,data目录中的文件结构如下所示。数据集下载可以网页搜索 - ```shell - data - └── coco - ├── annotations - ├── images - ├── scripts - ├── yolact_edge_example_1.gif - ├── yolact_edge_example_2.gif - ├── yolact_edge_example_3.gif - ``` - -### 2.3 文件拷贝 -拷贝env.sh,pth2onnx.py,atc.sh,acl_net.py文件到yolact_edge目录下。 - - -### 2.4 设置环境变量 -```shell -source env.sh -``` - -## 3 端到端推理步骤 - -### 3.1 pth导出onnx -```python -python3.7 pth2onnx.py \ - --config=yolact_edge_resnet50_config \ - --trained_model=./weights/yolact_edge_resnet50_54_800000.pth -``` - -### 3.2 利用ATC工具转换为om模型 -```shell -bash atc.sh yolact_edge.onnx yolact_edge -``` - -### 3.3 om模型推理 -```python -python3.7 eval.py \ - --config=yolact_edge_resnet50_config \ - --trained_model=./weights/yolact_edge_resnet50_54_800000.pth \ - --cuda=False \ - --disable_tensorrt -``` - -### 3.4 纯推理性能获取 - -下载 [benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) 并拷贝到当前目录 -```shell -./benchmark.${arch} -device_id=0 -batch_size=1 -om_path=./yolact_edge.om -round=20 -``` - -## 4 评测结果 - -| 模型 | pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| --------------- | -------- | --------------- | -------- | ------- | -| yolact_edge | [mAP:27.0](https://github.com/haotian-liu/yolact_edge) | mAP:27.6 | 167fps | 157fps | +# yolact_edge模型推理指导 + +- [yolact_edge模型推理指导](#yolact_edge模型推理指导) + - [1 文件说明](#1-文件说明) + - [2 环境准备](#2-环境准备) + - [2.1 安装依赖](#21-安装依赖) + - [2.2 文件下载](#22-文件下载) + - [2.3 文件拷贝](#23-文件拷贝) + - [2.4 设置环境变量](#24-设置环境变量) + - [3 端到端推理步骤](#3-端到端推理步骤) + - [3.1 pth导出onnx](#31-pth导出onnx) + - [3.2 利用ATC工具转换为om模型](#32-利用atc工具转换为om模型) + - [3.3 om模型推理](#33-om模型推理) + - [3.4 纯推理性能获取](#34-纯推理性能获取) + - [4 评测结果](#4-评测结果) + +------ + +## 1 文件说明 +``` +yolact_edge_for_Pytorch + ├── env.sh 设置环境变量 + ├── pth2onnx.py pytorch模型导出onnx模型 + ├── atc.sh onnx模型转om + ├── yolact_edge.diff 补丁文件 + └── acl_net.py PyACL推理工具代码 +``` + +## 2 环境准备 + +### 2.1 安装依赖 + +根据pytorch官网教程安装1.10.0版本的PyTorch +```shell +pip install torch==1.10.0+cpu torchvision==0.11.1+cpu torchaudio==0.10.0+cpu +pip install -r requirements.txt +pip install git+https://github.com/haotian-liu/cocoapi.git#"egg=pycocotools&subdirectory=PythonAPI" +``` + +### 2.2 文件下载 +- [yolact_edge_Pytorch源码下载](https://github.com/haotian-liu/yolact_edge) + + ```shell + git clone git@github.com:haotian-liu/yolact_edge.git + cd yolact_edge + git reset a9a00281b33b3ac90253a4939773308a8f95e21d --hard + git apply yolact_edge.diff + ``` + +- 权重下载 + + 创建 `weights` 目录,并将下载的权重文件 `yolact_edge_resnet50_54_800000.pth` 拷贝到 `weights` 目录下。 + 可参见[yolact_edge_Pytorch主页](https://github.com/haotian-liu/yolact_edge)说明下载权重 + +- 数据集下载 + + om推理采用COCO2017数据集的验证集进行精度评估。将下载好的数据集拷贝到 `data/coco` 目录下,data目录中的文件结构如下所示。数据集下载可以网页搜索 + ```shell + data + └── coco + ├── annotations + ├── images + ├── scripts + ├── yolact_edge_example_1.gif + ├── yolact_edge_example_2.gif + ├── yolact_edge_example_3.gif + ``` + +### 2.3 文件拷贝 +拷贝env.sh,pth2onnx.py,atc.sh,acl_net.py文件到yolact_edge目录下。 + + +### 2.4 设置环境变量 +```shell +source env.sh +``` + +## 3 端到端推理步骤 + +### 3.1 pth导出onnx +```python +python3.7 pth2onnx.py \ + --config=yolact_edge_resnet50_config \ + --trained_model=./weights/yolact_edge_resnet50_54_800000.pth +``` + +### 3.2 利用ATC工具转换为om模型 +```shell +bash atc.sh yolact_edge.onnx yolact_edge +``` + +### 3.3 om模型推理 +```python +python3.7 eval.py \ + --config=yolact_edge_resnet50_config \ + --trained_model=./weights/yolact_edge_resnet50_54_800000.pth \ + --cuda=False \ + --disable_tensorrt +``` + +### 3.4 纯推理性能获取 + +下载 [benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) 并拷贝到当前目录 +```shell +./benchmark.${arch} -device_id=0 -batch_size=1 -om_path=./yolact_edge.om -round=20 +``` + +## 4 评测结果 + +| 模型 | pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| --------------- | -------- | --------------- | -------- | ------- | +| yolact_edge | [mAP:27.0](https://github.com/haotian-liu/yolact_edge) | mAP:27.6 | 167fps | 157fps | diff --git a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/acl_net.py b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/acl_net.py index ff5429e2787bad9f98ffaaeac2a14bbd02ea9648..0b1084057017f52f54952ff93b193983488ce838 100644 --- a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/acl_net.py +++ b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/acl_net.py @@ -1,259 +1,259 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import time -import numpy as np -import functools -import acl - -# error code -ACL_ERROR_NONE = 0 - -# rule for mem -ACL_MEM_MALLOC_HUGE_FIRST = 0 -ACL_MEM_MALLOC_HUGE_ONLY = 1 -ACL_MEM_MALLOC_NORMAL_ONLY = 2 - -# rule for memory copy -ACL_MEMCPY_HOST_TO_HOST = 0 -ACL_MEMCPY_HOST_TO_DEVICE = 1 -ACL_MEMCPY_DEVICE_TO_HOST = 2 -ACL_MEMCPY_DEVICE_TO_DEVICE = 3 - -ACL_DTYPE = { - 0: 'float32', - 1: 'float16', - 2: 'int8', - 3: 'int32', - 4: 'uint8', - 6: 'int16', - 7: 'uint16', - 8: 'uint32', - 9: 'int64', - 10: 'uint64', - 11: 'float64', - 12: 'bool', -} - -buffer_method = { - "in": acl.mdl.get_input_size_by_index, - "out": acl.mdl.get_output_size_by_index -} - - -def check_ret(message, ret): - if ret != ACL_ERROR_NONE: - raise Exception("{} failed ret={}".format(message, ret)) - - -class Net(object): - def __init__(self, model_path, device_id=0, config_path=None): - self.device_id = device_id # int - self.model_path = model_path # string - self.model_id = None # pointer - self.context = None # pointer - - self.input_data = [] - self.output_data = [] - self.model_desc = None # pointer when using - self.load_input_dataset = None - self.load_output_dataset = None - - self._init_resource(config_path) - - def __call__(self, ori_data): - return self.forward(ori_data) - - def __del__(self): - ret = acl.mdl.unload(self.model_id) - check_ret("acl.mdl.unload", ret) - if self.model_desc: - acl.mdl.destroy_desc(self.model_desc) - self.model_desc = None - - while self.input_data: - item = self.input_data.pop() - ret = acl.rt.free(item["buffer"]) - check_ret("acl.rt.free", ret) - - while self.output_data: - item = self.output_data.pop() - ret = acl.rt.free(item["buffer"]) - check_ret("acl.rt.free", ret) - - if self.context: - ret = acl.rt.destroy_context(self.context) - check_ret("acl.rt.destroy_context", ret) - self.context = None - - ret = acl.rt.reset_device(self.device_id) - check_ret("acl.rt.reset_device", ret) - ret = acl.finalize() - check_ret("acl.finalize", ret) - - def _init_resource(self, config_path=None): - if config_path: - ret = acl.init(config_path) - else: - ret = acl.init() - check_ret("acl.init", ret) - ret = acl.rt.set_device(self.device_id) - check_ret("acl.rt.set_device", ret) - - self.context, ret = acl.rt.create_context(self.device_id) - check_ret("acl.rt.create_context", ret) - - # load_model - self.model_id, ret = acl.mdl.load_from_file(self.model_path) - check_ret("acl.mdl.load_from_file", ret) - - self.model_desc = acl.mdl.create_desc() - self._get_model_info() - - def _get_model_info(self, ): - ret = acl.mdl.get_desc(self.model_desc, self.model_id) - check_ret("acl.mdl.get_desc", ret) - input_size = acl.mdl.get_num_inputs(self.model_desc) - output_size = acl.mdl.get_num_outputs(self.model_desc) - self._gen_data_buffer(input_size, des="in") - self._gen_data_buffer(output_size, des="out") - - def _gen_data_buffer(self, size, des): - func = buffer_method[des] - for i in range(size): - temp_buffer_size = func(self.model_desc, i) - temp_buffer, ret = acl.rt.malloc(temp_buffer_size, - ACL_MEM_MALLOC_HUGE_FIRST) - check_ret("acl.rt.malloc", ret) - - if des == "in": - self.input_data.append({"buffer": temp_buffer, - "size": temp_buffer_size}) - elif des == "out": - self.output_data.append({"buffer": temp_buffer, - "size": temp_buffer_size}) - - def _data_interaction(self, dataset, policy=ACL_MEMCPY_HOST_TO_DEVICE): - temp_data_buffer = self.input_data \ - if policy == ACL_MEMCPY_HOST_TO_DEVICE \ - else self.output_data - if len(dataset) == 0 and policy == ACL_MEMCPY_DEVICE_TO_HOST: - for item in self.output_data: - temp, ret = acl.rt.malloc_host(item["size"]) - if ret != 0: - raise Exception("can't malloc_host ret={}".format(ret)) - dataset.append({"size": item["size"], "buffer": temp}) - - for i, item in enumerate(temp_data_buffer): - if policy == ACL_MEMCPY_HOST_TO_DEVICE: - if 'bytes_to_ptr' in dir(acl.util): - bytes_in = dataset[i].tobytes() - ptr = acl.util.bytes_to_ptr(bytes_in) - else: - ptr = acl.util.numpy_to_ptr(dataset[i]) - ret = acl.rt.memcpy(item["buffer"], item["size"], ptr, item["size"], policy) - check_ret("acl.rt.memcpy", ret) - - else: - ptr = dataset[i]["buffer"] - ret = acl.rt.memcpy(ptr, item["size"], item["buffer"], item["size"], policy) - check_ret("acl.rt.memcpy", ret) - - def _gen_dataset(self, type_str="input"): - dataset = acl.mdl.create_dataset() - - temp_dataset = None - if type_str == "in": - self.load_input_dataset = dataset - temp_dataset = self.input_data - else: - self.load_output_dataset = dataset - temp_dataset = self.output_data - - for item in temp_dataset: - data = acl.create_data_buffer(item["buffer"], item["size"]) - if data is None: - ret = acl.destroy_data_buffer(dataset) - check_ret("acl.destroy_data_buffer", ret) - - _, ret = acl.mdl.add_dataset_buffer(dataset, data) - - if ret != ACL_ERROR_NONE: - ret = acl.destroy_data_buffer(dataset) - check_ret("acl.destroy_data_buffer", ret) - - def _data_from_host_to_device(self, images): - self._data_interaction(images, ACL_MEMCPY_HOST_TO_DEVICE) - self._gen_dataset("in") - self._gen_dataset("out") - - def _data_from_device_to_host(self): - res = [] - self._data_interaction(res, ACL_MEMCPY_DEVICE_TO_HOST) - output = self.get_result(res) - return output - - def _destroy_databuffer(self, ): - for dataset in [self.load_input_dataset, self.load_output_dataset]: - if not dataset: - continue - - num = acl.mdl.get_dataset_num_buffers(dataset) - for i in range(num): - data_buf = acl.mdl.get_dataset_buffer(dataset, i) - if data_buf: - ret = acl.destroy_data_buffer(data_buf) - check_ret("acl.destroy_data_buffer", ret) - ret = acl.mdl.destroy_dataset(dataset) - check_ret("acl.mdl.destroy_dataset", ret) - - def forward(self, input_data): - if not isinstance(input_data, (list, tuple)): - input_data = [input_data] - st = time.time() - self._data_from_host_to_device(input_data) - mem_t = time.time() - st - st = time.time() - ret = acl.mdl.execute(self.model_id, - self.load_input_dataset, - self.load_output_dataset) - exe_t = time.time() - st - st = time.time() - check_ret("acl.mdl.execute", ret) - self._destroy_databuffer() - result = self._data_from_device_to_host() - mem_t += time.time() - st - return result - - def get_result(self, output_data): - dataset = [] - for i in range(len(output_data)): - dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) - check_ret("acl.mdl.get_cur_output_dims", ret) - data_shape = dims.get("dims") - data_type = acl.mdl.get_output_data_type(self.model_desc, i) - data_len = functools.reduce(lambda x, y: x * y, data_shape) - ftype = np.dtype(ACL_DTYPE.get(data_type)) - - size = output_data[i]["size"] - ptr = output_data[i]["buffer"] - if 'ptr_to_bytes' in dir(acl.util): - data = acl.util.ptr_to_bytes(ptr, size) - np_arr = np.frombuffer(data, dtype=ftype, count=data_len) - else: - data = acl.util.ptr_to_numpy(ptr, (size,), 1) - np_arr = np.frombuffer(bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) - np_arr = np_arr.reshape(data_shape) - dataset.append(np_arr) - return dataset +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import time +import numpy as np +import functools +import acl + +# error code +ACL_ERROR_NONE = 0 + +# rule for mem +ACL_MEM_MALLOC_HUGE_FIRST = 0 +ACL_MEM_MALLOC_HUGE_ONLY = 1 +ACL_MEM_MALLOC_NORMAL_ONLY = 2 + +# rule for memory copy +ACL_MEMCPY_HOST_TO_HOST = 0 +ACL_MEMCPY_HOST_TO_DEVICE = 1 +ACL_MEMCPY_DEVICE_TO_HOST = 2 +ACL_MEMCPY_DEVICE_TO_DEVICE = 3 + +ACL_DTYPE = { + 0: 'float32', + 1: 'float16', + 2: 'int8', + 3: 'int32', + 4: 'uint8', + 6: 'int16', + 7: 'uint16', + 8: 'uint32', + 9: 'int64', + 10: 'uint64', + 11: 'float64', + 12: 'bool', +} + +buffer_method = { + "in": acl.mdl.get_input_size_by_index, + "out": acl.mdl.get_output_size_by_index +} + + +def check_ret(message, ret): + if ret != ACL_ERROR_NONE: + raise Exception("{} failed ret={}".format(message, ret)) + + +class Net(object): + def __init__(self, model_path, device_id=0, config_path=None): + self.device_id = device_id # int + self.model_path = model_path # string + self.model_id = None # pointer + self.context = None # pointer + + self.input_data = [] + self.output_data = [] + self.model_desc = None # pointer when using + self.load_input_dataset = None + self.load_output_dataset = None + + self._init_resource(config_path) + + def __call__(self, ori_data): + return self.forward(ori_data) + + def __del__(self): + ret = acl.mdl.unload(self.model_id) + check_ret("acl.mdl.unload", ret) + if self.model_desc: + acl.mdl.destroy_desc(self.model_desc) + self.model_desc = None + + while self.input_data: + item = self.input_data.pop() + ret = acl.rt.free(item["buffer"]) + check_ret("acl.rt.free", ret) + + while self.output_data: + item = self.output_data.pop() + ret = acl.rt.free(item["buffer"]) + check_ret("acl.rt.free", ret) + + if self.context: + ret = acl.rt.destroy_context(self.context) + check_ret("acl.rt.destroy_context", ret) + self.context = None + + ret = acl.rt.reset_device(self.device_id) + check_ret("acl.rt.reset_device", ret) + ret = acl.finalize() + check_ret("acl.finalize", ret) + + def _init_resource(self, config_path=None): + if config_path: + ret = acl.init(config_path) + else: + ret = acl.init() + check_ret("acl.init", ret) + ret = acl.rt.set_device(self.device_id) + check_ret("acl.rt.set_device", ret) + + self.context, ret = acl.rt.create_context(self.device_id) + check_ret("acl.rt.create_context", ret) + + # load_model + self.model_id, ret = acl.mdl.load_from_file(self.model_path) + check_ret("acl.mdl.load_from_file", ret) + + self.model_desc = acl.mdl.create_desc() + self._get_model_info() + + def _get_model_info(self, ): + ret = acl.mdl.get_desc(self.model_desc, self.model_id) + check_ret("acl.mdl.get_desc", ret) + input_size = acl.mdl.get_num_inputs(self.model_desc) + output_size = acl.mdl.get_num_outputs(self.model_desc) + self._gen_data_buffer(input_size, des="in") + self._gen_data_buffer(output_size, des="out") + + def _gen_data_buffer(self, size, des): + func = buffer_method[des] + for i in range(size): + temp_buffer_size = func(self.model_desc, i) + temp_buffer, ret = acl.rt.malloc(temp_buffer_size, + ACL_MEM_MALLOC_HUGE_FIRST) + check_ret("acl.rt.malloc", ret) + + if des == "in": + self.input_data.append({"buffer": temp_buffer, + "size": temp_buffer_size}) + elif des == "out": + self.output_data.append({"buffer": temp_buffer, + "size": temp_buffer_size}) + + def _data_interaction(self, dataset, policy=ACL_MEMCPY_HOST_TO_DEVICE): + temp_data_buffer = self.input_data \ + if policy == ACL_MEMCPY_HOST_TO_DEVICE \ + else self.output_data + if len(dataset) == 0 and policy == ACL_MEMCPY_DEVICE_TO_HOST: + for item in self.output_data: + temp, ret = acl.rt.malloc_host(item["size"]) + if ret != 0: + raise Exception("can't malloc_host ret={}".format(ret)) + dataset.append({"size": item["size"], "buffer": temp}) + + for i, item in enumerate(temp_data_buffer): + if policy == ACL_MEMCPY_HOST_TO_DEVICE: + if 'bytes_to_ptr' in dir(acl.util): + bytes_in = dataset[i].tobytes() + ptr = acl.util.bytes_to_ptr(bytes_in) + else: + ptr = acl.util.numpy_to_ptr(dataset[i]) + ret = acl.rt.memcpy(item["buffer"], item["size"], ptr, item["size"], policy) + check_ret("acl.rt.memcpy", ret) + + else: + ptr = dataset[i]["buffer"] + ret = acl.rt.memcpy(ptr, item["size"], item["buffer"], item["size"], policy) + check_ret("acl.rt.memcpy", ret) + + def _gen_dataset(self, type_str="input"): + dataset = acl.mdl.create_dataset() + + temp_dataset = None + if type_str == "in": + self.load_input_dataset = dataset + temp_dataset = self.input_data + else: + self.load_output_dataset = dataset + temp_dataset = self.output_data + + for item in temp_dataset: + data = acl.create_data_buffer(item["buffer"], item["size"]) + if data is None: + ret = acl.destroy_data_buffer(dataset) + check_ret("acl.destroy_data_buffer", ret) + + _, ret = acl.mdl.add_dataset_buffer(dataset, data) + + if ret != ACL_ERROR_NONE: + ret = acl.destroy_data_buffer(dataset) + check_ret("acl.destroy_data_buffer", ret) + + def _data_from_host_to_device(self, images): + self._data_interaction(images, ACL_MEMCPY_HOST_TO_DEVICE) + self._gen_dataset("in") + self._gen_dataset("out") + + def _data_from_device_to_host(self): + res = [] + self._data_interaction(res, ACL_MEMCPY_DEVICE_TO_HOST) + output = self.get_result(res) + return output + + def _destroy_databuffer(self, ): + for dataset in [self.load_input_dataset, self.load_output_dataset]: + if not dataset: + continue + + num = acl.mdl.get_dataset_num_buffers(dataset) + for i in range(num): + data_buf = acl.mdl.get_dataset_buffer(dataset, i) + if data_buf: + ret = acl.destroy_data_buffer(data_buf) + check_ret("acl.destroy_data_buffer", ret) + ret = acl.mdl.destroy_dataset(dataset) + check_ret("acl.mdl.destroy_dataset", ret) + + def forward(self, input_data): + if not isinstance(input_data, (list, tuple)): + input_data = [input_data] + st = time.time() + self._data_from_host_to_device(input_data) + mem_t = time.time() - st + st = time.time() + ret = acl.mdl.execute(self.model_id, + self.load_input_dataset, + self.load_output_dataset) + exe_t = time.time() - st + st = time.time() + check_ret("acl.mdl.execute", ret) + self._destroy_databuffer() + result = self._data_from_device_to_host() + mem_t += time.time() - st + return result + + def get_result(self, output_data): + dataset = [] + for i in range(len(output_data)): + dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) + check_ret("acl.mdl.get_cur_output_dims", ret) + data_shape = dims.get("dims") + data_type = acl.mdl.get_output_data_type(self.model_desc, i) + data_len = functools.reduce(lambda x, y: x * y, data_shape) + ftype = np.dtype(ACL_DTYPE.get(data_type)) + + size = output_data[i]["size"] + ptr = output_data[i]["buffer"] + if 'ptr_to_bytes' in dir(acl.util): + data = acl.util.ptr_to_bytes(ptr, size) + np_arr = np.frombuffer(data, dtype=ftype, count=data_len) + else: + data = acl.util.ptr_to_numpy(ptr, (size,), 1) + np_arr = np.frombuffer(bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) + np_arr = np_arr.reshape(data_shape) + dataset.append(np_arr) + return dataset diff --git a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/atc.sh b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/atc.sh index b5e775f899bad22ab18e422ab272e4e4ef5ab9f7..dc10c8186c2f5d6ad4ff6f1d48e69d136b8b0d0e 100644 --- a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/atc.sh +++ b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/atc.sh @@ -1,5 +1,5 @@ -atc --model=$1 \ - --framework=5 \ - --output=$2 \ - --log=error \ - --soc_version=Ascend310 +atc --model=$1 \ + --framework=5 \ + --output=$2 \ + --log=error \ + --soc_version=Ascend310 diff --git a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/env.sh b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/env.sh index 9ce0d242f029dcb9ddd237071dcbda75546035a6..7fb2c8a43dd00b83c9015932311d4be770a1a10f 100644 --- a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/env.sh +++ b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/env.sh @@ -1,5 +1,5 @@ -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH -export ASCEND_OPP_PATH=${install_path}/opp +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH +export ASCEND_OPP_PATH=${install_path}/opp diff --git a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/modelzoo_level.txt b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/modelzoo_level.txt index d44ba5698b045b8a30e107962f295dbc24585d8c..70801afc42b6d9eb5cdd98b5430d9b2101f3146a 100644 --- a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/modelzoo_level.txt +++ b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/requirements.txt b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/requirements.txt index 511f52dc35b4e6e860ff90c76d4be5d2e3f441ab..306a8a990ac1ef166e97c0506f09bc19e1392c66 100644 --- a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/requirements.txt +++ b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/requirements.txt @@ -1,7 +1,7 @@ -cython -opencv-python -pillow -matplotlib -GitPython -termcolor +cython +opencv-python +pillow +matplotlib +GitPython +termcolor tensorboard \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/yolact_edge.diff b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/yolact_edge.diff index 3f2db5f2405684d8e6cce4230607d89e31ce701a..e5b26f350dcf25a04e09b184e6c3e430251a3e03 100644 --- a/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/yolact_edge.diff +++ b/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch/yolact_edge.diff @@ -1,171 +1,171 @@ -diff --git a/eval.py b/eval.py -index f2a833f..8644391 100644 ---- a/eval.py -+++ b/eval.py -@@ -412,8 +412,9 @@ def prep_metrics(ap_data, dets, img, gt, gt_masks, h, w, num_crowd, image_id, de - - classes = list(classes.cpu().numpy().astype(int)) - scores = list(scores.cpu().numpy().astype(float)) -- masks = masks.view(-1, h*w).cuda() -- boxes = boxes.cuda() -+ #masks = masks.view(-1, h*w).cuda() -+ masks = masks.view(-1, h*w) -+ #boxes = boxes.cuda() - - - if args.output_coco_json: -@@ -1075,6 +1076,8 @@ def evaluate(net:Yolact, dataset, train_mode=False, train_cfg=None): - - else: - # Main eval loop -+ from acl_net import Net -+ model = Net(device_id=0, model_path='./yolact_edge.om') - for it, image_idx in enumerate(dataset_indices): - timer.reset() - -@@ -1092,9 +1095,15 @@ def evaluate(net:Yolact, dataset, train_mode=False, train_cfg=None): - batch = batch.cuda() - - with timer.env('Network Extra'): -- extras = {"backbone": "full", "interrupt": False, -- "moving_statistics": {"aligned_feats": []}} -- preds = net(batch, extras=extras)["pred_outs"] -+ # pytorch forward -+ # outs, proto_out = net(batch) -+ # om forward -+ res = model([batch.numpy()]) -+ outs = [torch.from_numpy(ele) for ele in res[:5]] -+ proto_out = torch.from_numpy(res[-1]) -+ -+ # common postprocess -+ preds = net.postprocess(outs, proto_out) - - # Perform the meat of the operation here depending on our mode. - if args.display: -diff --git a/yolact_edge/yolact.py b/yolact_edge/yolact.py -index b6efdf7..7a167f3 100644 ---- a/yolact_edge/yolact.py -+++ b/yolact_edge/yolact.py -@@ -33,10 +33,10 @@ except: - - # This is required for Pytorch 1.0.1 on Windows to initialize Cuda on some driver versions. - # See the bug report here: https://github.com/pytorch/pytorch/issues/17108 --torch.cuda.current_device() -+#torch.cuda.current_device() - - # As of March 10, 2019, Pytorch DataParallel still doesn't support JIT Script Modules --use_jit = False if use_torch2trt else torch.cuda.device_count() <= 1 -+use_jit = False #if use_torch2trt else torch.cuda.device_count() <= 1 - - ScriptModuleWrapper = torch.jit.ScriptModule if use_jit else nn.Module - script_method_wrapper = torch.jit.script_method if use_jit else lambda fn, _rcn=None: fn -@@ -1089,6 +1089,9 @@ class Yolact(nn.Module): - def __init__(self, training=True): - super().__init__() - -+ self.extras = {"backbone": "full", "interrupt": False, -+ "moving_statistics": {"aligned_feats": []}} -+ - self.backbone = construct_backbone(cfg.backbone) - - self.training = training -@@ -1608,19 +1611,19 @@ class Yolact(nn.Module): - x = torch.ones((1, lateral_channels * 2, 69, 69)).cuda() - self.trt_load_if("flow_net", trt_fn, [x], int8_mode, parent=self.flow_net, batch_size=batch_size) - -- def forward(self, x, extras=None): -+ def forward(self, x): - """ The input should be of size [batch_size, 3, img_h, img_w] """ - - if cfg.flow.train_flow: -- return self.forward_flow(extras) -+ return self.forward_flow(self.extras) - - outs_wrapper = {} - - with timer.env('backbone'): -- if cfg.flow is None or extras is None or extras["backbone"] == "full": -+ if cfg.flow is None or self.extras is None or self.extras["backbone"] == "full": - outs = self.backbone(x) - -- elif extras is not None and extras["backbone"] == "partial": -+ elif self.extras is not None and self.extras["backbone"] == "partial": - if hasattr(self, 'partial_backbone'): - outs = self.partial_backbone(x) - else: -@@ -1631,22 +1634,22 @@ class Yolact(nn.Module): - - if cfg.flow is not None: - with timer.env('fpn'): -- assert type(extras) == dict -- if extras["backbone"] == "full": -+ assert type(self.extras) == dict -+ if self.extras["backbone"] == "full": - outs = [outs[i] for i in cfg.backbone.selected_layers] - outs_fpn_phase_1_wrapper = self.fpn_phase_1(*outs) - outs_phase_1, lats_phase_1 = outs_fpn_phase_1_wrapper[:len(outs)], outs_fpn_phase_1_wrapper[len(outs):] - lateral = lats_phase_1[0].detach() -- moving_statistics = extras["moving_statistics"] -+ moving_statistics = self.extras["moving_statistics"] - -- if extras.get("keep_statistics", False): -+ if self.extras.get("keep_statistics", False): - outs_wrapper["feats"] = [out.detach() for out in outs_phase_1] - outs_wrapper["lateral"] = lateral - - outs_wrapper["outs_phase_1"] = [out.detach() for out in outs_phase_1] - else: -- assert extras["moving_statistics"] is not None -- moving_statistics = extras["moving_statistics"] -+ assert self.extras["moving_statistics"] is not None -+ moving_statistics = self.extras["moving_statistics"] - outs_phase_1 = moving_statistics["feats"].copy() - - if cfg.flow.warp_mode != 'take': -@@ -1699,7 +1702,7 @@ class Yolact(nn.Module): - outs_wrapper["outs_phase_1"] = outs_phase_1.copy() - - outs = self.fpn_phase_2(*outs_phase_1) -- if extras["backbone"] == "partial": -+ if self.extras["backbone"] == "partial": - outs_wrapper["outs_phase_2"] = [out for out in outs] - else: - outs_wrapper["outs_phase_2"] = [out.detach() for out in outs] -@@ -1709,7 +1712,7 @@ class Yolact(nn.Module): - outs = [outs[i] for i in cfg.backbone.selected_layers] - outs = self.fpn(outs) - -- if extras is not None and extras.get("interrupt", None): -+ if self.extras is not None and self.extras.get("interrupt", None): - return outs_wrapper - - proto_out = None -@@ -1740,6 +1743,9 @@ class Yolact(nn.Module): - bias_shape[-1] = 1 - proto_out = torch.cat([proto_out, torch.ones(*bias_shape)], -1) - -+ return outs, proto_out -+ -+ def postprocess(self, outs, proto_out): - with timer.env('pred_heads'): - pred_outs = { 'loc': [], 'conf': [], 'mask': [], 'priors': [] } - -@@ -1779,7 +1785,6 @@ class Yolact(nn.Module): - if cfg.use_semantic_segmentation_loss: - pred_outs['segm'] = self.semantic_seg_conv(outs[0]) - -- outs_wrapper["pred_outs"] = pred_outs - else: - if cfg.use_sigmoid_focal_loss: - # Note: even though conf[0] exists, this mode doesn't train it so don't use it -@@ -1792,8 +1797,8 @@ class Yolact(nn.Module): - else: - pred_outs['conf'] = F.softmax(pred_outs['conf'], -1) - -- outs_wrapper["pred_outs"] = self.detect(pred_outs) -- return outs_wrapper -+ pred_outs = self.detect(pred_outs) -+ return pred_outs - - - # Some testing code +diff --git a/eval.py b/eval.py +index f2a833f..8644391 100644 +--- a/eval.py ++++ b/eval.py +@@ -412,8 +412,9 @@ def prep_metrics(ap_data, dets, img, gt, gt_masks, h, w, num_crowd, image_id, de + + classes = list(classes.cpu().numpy().astype(int)) + scores = list(scores.cpu().numpy().astype(float)) +- masks = masks.view(-1, h*w).cuda() +- boxes = boxes.cuda() ++ #masks = masks.view(-1, h*w).cuda() ++ masks = masks.view(-1, h*w) ++ #boxes = boxes.cuda() + + + if args.output_coco_json: +@@ -1075,6 +1076,8 @@ def evaluate(net:Yolact, dataset, train_mode=False, train_cfg=None): + + else: + # Main eval loop ++ from acl_net import Net ++ model = Net(device_id=0, model_path='./yolact_edge.om') + for it, image_idx in enumerate(dataset_indices): + timer.reset() + +@@ -1092,9 +1095,15 @@ def evaluate(net:Yolact, dataset, train_mode=False, train_cfg=None): + batch = batch.cuda() + + with timer.env('Network Extra'): +- extras = {"backbone": "full", "interrupt": False, +- "moving_statistics": {"aligned_feats": []}} +- preds = net(batch, extras=extras)["pred_outs"] ++ # pytorch forward ++ # outs, proto_out = net(batch) ++ # om forward ++ res = model([batch.numpy()]) ++ outs = [torch.from_numpy(ele) for ele in res[:5]] ++ proto_out = torch.from_numpy(res[-1]) ++ ++ # common postprocess ++ preds = net.postprocess(outs, proto_out) + + # Perform the meat of the operation here depending on our mode. + if args.display: +diff --git a/yolact_edge/yolact.py b/yolact_edge/yolact.py +index b6efdf7..7a167f3 100644 +--- a/yolact_edge/yolact.py ++++ b/yolact_edge/yolact.py +@@ -33,10 +33,10 @@ except: + + # This is required for Pytorch 1.0.1 on Windows to initialize Cuda on some driver versions. + # See the bug report here: https://github.com/pytorch/pytorch/issues/17108 +-torch.cuda.current_device() ++#torch.cuda.current_device() + + # As of March 10, 2019, Pytorch DataParallel still doesn't support JIT Script Modules +-use_jit = False if use_torch2trt else torch.cuda.device_count() <= 1 ++use_jit = False #if use_torch2trt else torch.cuda.device_count() <= 1 + + ScriptModuleWrapper = torch.jit.ScriptModule if use_jit else nn.Module + script_method_wrapper = torch.jit.script_method if use_jit else lambda fn, _rcn=None: fn +@@ -1089,6 +1089,9 @@ class Yolact(nn.Module): + def __init__(self, training=True): + super().__init__() + ++ self.extras = {"backbone": "full", "interrupt": False, ++ "moving_statistics": {"aligned_feats": []}} ++ + self.backbone = construct_backbone(cfg.backbone) + + self.training = training +@@ -1608,19 +1611,19 @@ class Yolact(nn.Module): + x = torch.ones((1, lateral_channels * 2, 69, 69)).cuda() + self.trt_load_if("flow_net", trt_fn, [x], int8_mode, parent=self.flow_net, batch_size=batch_size) + +- def forward(self, x, extras=None): ++ def forward(self, x): + """ The input should be of size [batch_size, 3, img_h, img_w] """ + + if cfg.flow.train_flow: +- return self.forward_flow(extras) ++ return self.forward_flow(self.extras) + + outs_wrapper = {} + + with timer.env('backbone'): +- if cfg.flow is None or extras is None or extras["backbone"] == "full": ++ if cfg.flow is None or self.extras is None or self.extras["backbone"] == "full": + outs = self.backbone(x) + +- elif extras is not None and extras["backbone"] == "partial": ++ elif self.extras is not None and self.extras["backbone"] == "partial": + if hasattr(self, 'partial_backbone'): + outs = self.partial_backbone(x) + else: +@@ -1631,22 +1634,22 @@ class Yolact(nn.Module): + + if cfg.flow is not None: + with timer.env('fpn'): +- assert type(extras) == dict +- if extras["backbone"] == "full": ++ assert type(self.extras) == dict ++ if self.extras["backbone"] == "full": + outs = [outs[i] for i in cfg.backbone.selected_layers] + outs_fpn_phase_1_wrapper = self.fpn_phase_1(*outs) + outs_phase_1, lats_phase_1 = outs_fpn_phase_1_wrapper[:len(outs)], outs_fpn_phase_1_wrapper[len(outs):] + lateral = lats_phase_1[0].detach() +- moving_statistics = extras["moving_statistics"] ++ moving_statistics = self.extras["moving_statistics"] + +- if extras.get("keep_statistics", False): ++ if self.extras.get("keep_statistics", False): + outs_wrapper["feats"] = [out.detach() for out in outs_phase_1] + outs_wrapper["lateral"] = lateral + + outs_wrapper["outs_phase_1"] = [out.detach() for out in outs_phase_1] + else: +- assert extras["moving_statistics"] is not None +- moving_statistics = extras["moving_statistics"] ++ assert self.extras["moving_statistics"] is not None ++ moving_statistics = self.extras["moving_statistics"] + outs_phase_1 = moving_statistics["feats"].copy() + + if cfg.flow.warp_mode != 'take': +@@ -1699,7 +1702,7 @@ class Yolact(nn.Module): + outs_wrapper["outs_phase_1"] = outs_phase_1.copy() + + outs = self.fpn_phase_2(*outs_phase_1) +- if extras["backbone"] == "partial": ++ if self.extras["backbone"] == "partial": + outs_wrapper["outs_phase_2"] = [out for out in outs] + else: + outs_wrapper["outs_phase_2"] = [out.detach() for out in outs] +@@ -1709,7 +1712,7 @@ class Yolact(nn.Module): + outs = [outs[i] for i in cfg.backbone.selected_layers] + outs = self.fpn(outs) + +- if extras is not None and extras.get("interrupt", None): ++ if self.extras is not None and self.extras.get("interrupt", None): + return outs_wrapper + + proto_out = None +@@ -1740,6 +1743,9 @@ class Yolact(nn.Module): + bias_shape[-1] = 1 + proto_out = torch.cat([proto_out, torch.ones(*bias_shape)], -1) + ++ return outs, proto_out ++ ++ def postprocess(self, outs, proto_out): + with timer.env('pred_heads'): + pred_outs = { 'loc': [], 'conf': [], 'mask': [], 'priors': [] } + +@@ -1779,7 +1785,6 @@ class Yolact(nn.Module): + if cfg.use_semantic_segmentation_loss: + pred_outs['segm'] = self.semantic_seg_conv(outs[0]) + +- outs_wrapper["pred_outs"] = pred_outs + else: + if cfg.use_sigmoid_focal_loss: + # Note: even though conf[0] exists, this mode doesn't train it so don't use it +@@ -1792,8 +1797,8 @@ class Yolact(nn.Module): + else: + pred_outs['conf'] = F.softmax(pred_outs['conf'], -1) + +- outs_wrapper["pred_outs"] = self.detect(pred_outs) +- return outs_wrapper ++ pred_outs = self.detect(pred_outs) ++ return pred_outs + + + # Some testing code diff --git a/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/README.md b/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/README.md index 4df2045dbb774e9cdfd26626683fdae09c655c41..0b3ee782915873c9119f8e1273d58943028b1af7 100644 --- a/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/README.md +++ b/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/README.md @@ -1,73 +1,73 @@ -文件作用说明: - -1. env.sh:ATC工具环境变量配置脚本 -2. require.txt:脚本运行所需的第三方库 -3. parse_json.py: coco数据集标签json文件解析脚本 -4. preprocess_yolov3_pytorch.py: 二进制数据集预处理脚本 -5. get_coco_info.py: yolov3.info生成脚本 -6. bin_to_predict_yolo_pytorch.py: benchmark输出bin文件解析脚本 -7. map_calculate.py: 精度统计脚本 -8. benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer - -推理端到端步骤: - -(1) git clone 开源仓https://github.com/ultralytics/yolov3/, 并下载对应的权重文件,修改**models/export.py**脚本生成onnx文件 - -``` -git clone https://github.com/ultralytics/yolov3/ -python3.7 models/export.py --weights ./yolov3.pt --img 416 --batch 1 -``` - -(2)配置环境变量转换om模型 - -``` -source env.sh -atc --model=yolov3.onnx --framework=5 --output=yolov3_bs1 --input_format=NCHW --log=info --soc_version=Ascend310 --input_shape="images:1,3,416,416" --out_nodes="Reshape_219:0;Reshape_203:0;Reshape_187:0" -``` - -(3)解析数据集 - -下载coco2014数据集val2014和label文件**instances_valminusminival2014.json**,运行**parse_json.py**解析数据集 - -``` -python3.7 parse_json.py -``` - -生成coco2014.names和coco_2014.info以及gronud-truth文件夹 - -(5)数据预处理 - -运行脚本preprocess_yolov3_pytorch.py处理数据集 - -``` -python3.7 preprocess_yolov3_pytorch.py coco_2014.info yolov3_bin -``` - -(6)benchmark推理 - -运行get_coco_info.py生成info文件 - -``` -python3.7 get_coco_info.py yolo_coco_bin_tf coco_2014.info yolov3.info -``` - -执行benchmark命令,结果保存在同级目录 result/dumpOutput_device0/ - -``` -python3.7 get_coco_info.py yolo_coco_bin_tf coco_2014.info yolov3.info -``` - -(7)后处理 - -运行 bin_to_predict_yolo_pytorch.py 解析模型输出 - -``` -python3.7 bin_to_predict_yolo_pytorch.py --bin_data_path result/dumpOutput_device0/ --det_results_path detection-results/ --origin_jpg_path /root/dataset/coco2014/val2014/ --coco_class_names /root/dataset/coco2014/coco2014.names --model_type yolov3 --net_input_size 416 -``` - -运行map_cauculate.py统计mAP值 - -``` -python3 map_calculate.py --label_path ./ground-truth --npu_txt_path ./detection-results -na -np -``` - +文件作用说明: + +1. env.sh:ATC工具环境变量配置脚本 +2. require.txt:脚本运行所需的第三方库 +3. parse_json.py: coco数据集标签json文件解析脚本 +4. preprocess_yolov3_pytorch.py: 二进制数据集预处理脚本 +5. get_coco_info.py: yolov3.info生成脚本 +6. bin_to_predict_yolo_pytorch.py: benchmark输出bin文件解析脚本 +7. map_calculate.py: 精度统计脚本 +8. benchmark工具源码地址:https://gitee.com/ascend/cann-benchmark/tree/master/infer + +推理端到端步骤: + +(1) git clone 开源仓https://github.com/ultralytics/yolov3/, 并下载对应的权重文件,修改**models/export.py**脚本生成onnx文件 + +``` +git clone https://github.com/ultralytics/yolov3/ +python3.7 models/export.py --weights ./yolov3.pt --img 416 --batch 1 +``` + +(2)配置环境变量转换om模型 + +``` +source env.sh +atc --model=yolov3.onnx --framework=5 --output=yolov3_bs1 --input_format=NCHW --log=info --soc_version=Ascend310 --input_shape="images:1,3,416,416" --out_nodes="Reshape_219:0;Reshape_203:0;Reshape_187:0" +``` + +(3)解析数据集 + +下载coco2014数据集val2014和label文件**instances_valminusminival2014.json**,运行**parse_json.py**解析数据集 + +``` +python3.7 parse_json.py +``` + +生成coco2014.names和coco_2014.info以及gronud-truth文件夹 + +(5)数据预处理 + +运行脚本preprocess_yolov3_pytorch.py处理数据集 + +``` +python3.7 preprocess_yolov3_pytorch.py coco_2014.info yolov3_bin +``` + +(6)benchmark推理 + +运行get_coco_info.py生成info文件 + +``` +python3.7 get_coco_info.py yolo_coco_bin_tf coco_2014.info yolov3.info +``` + +执行benchmark命令,结果保存在同级目录 result/dumpOutput_device0/ + +``` +python3.7 get_coco_info.py yolo_coco_bin_tf coco_2014.info yolov3.info +``` + +(7)后处理 + +运行 bin_to_predict_yolo_pytorch.py 解析模型输出 + +``` +python3.7 bin_to_predict_yolo_pytorch.py --bin_data_path result/dumpOutput_device0/ --det_results_path detection-results/ --origin_jpg_path /root/dataset/coco2014/val2014/ --coco_class_names /root/dataset/coco2014/coco2014.names --model_type yolov3 --net_input_size 416 +``` + +运行map_cauculate.py统计mAP值 + +``` +python3 map_calculate.py --label_path ./ground-truth --npu_txt_path ./detection-results -na -np +``` + diff --git a/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/bin_to_predict_yolo_pytorch.py b/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/bin_to_predict_yolo_pytorch.py index cb84f103816ac836844e9c672d15e554b706ef7b..2cfababcda4e29aa42feab5b02bafcb9d240cae1 100644 --- a/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/bin_to_predict_yolo_pytorch.py +++ b/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/bin_to_predict_yolo_pytorch.py @@ -1,255 +1,255 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import numpy as np -import argparse -import time -import torch -import torchvision -import cv2 - - -def _make_grid(nx=20, ny=20): - xv, yv = np.meshgrid(np.arange(nx), np.arange(ny)) - return np.stack((xv, yv), 2).reshape((1, 1, ny, nx, 2)).astype(np.float) - - -def sigmoid(x0): - s = 1 / (1 + np.exp(-x0)) - return s - -def detect(x, model_type): - """ - x(bs,3,20,20,85) - """ - - # x(bs,3,20,20,85) - z = [] - grid = [] - for i in range(3): - _, _, ny, nx, _ = x[i].shape - grid.append(_make_grid(nx, ny)) - if model_type == 'yolov5': - stride = np.array([8, 16, 32]) - anchor_grid = np.array( - [[10., 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]])\ - .reshape(3, 1, 3, 1, 1, 2) - elif model_type == 'yolov3': - stride = np.array([32, 16, 8]) - anchor_grid = np.array( - [[116, 90, 156, 198, 373, 326], [30, 61, 62, 45, 59, 119], [10., 13, 16, 30, 33, 23]])\ - .reshape(3, 1, 3, 1, 1, 2) - - for i in range(3): - y = sigmoid(x[i]) - y[..., 0:2] = (y[..., 0:2] * 2. - 0.5 + grid[i]) * stride[i] # xy - y[..., 2:4] = (y[..., 2:4] * 2) ** 2 * anchor_grid[i] # wh - z.append(y.reshape(1, -1, 85)) - return np.concatenate(z, 1) - - -def xywh2xyxy(x): - # Convert nx4 boxes from [x, y, w, h] to [x1, y1, x2, y2] where xy1=top-left, xy2=bottom-right - y = torch.zeros_like(x) if isinstance(x, torch.Tensor) else np.zeros_like(x) - y[:, 0] = x[:, 0] - x[:, 2] / 2 # top left x - y[:, 1] = x[:, 1] - x[:, 3] / 2 # top left y - y[:, 2] = x[:, 0] + x[:, 2] / 2 # bottom right x - y[:, 3] = x[:, 1] + x[:, 3] / 2 # bottom right y - return y - - -def non_max_suppression(prediction, conf_thres=0.1, iou_thres=0.6, merge=False, classes=None, agnostic=False): - """Performs Non-Maximum Suppression (NMS) on inference results - - Returns: - detections with shape: nx6 (x1, y1, x2, y2, conf, cls) - """ - - nc = prediction[0].shape[1] - 5 # number of classes - xc = prediction[..., 4] > conf_thres # candidates - - # Settings - min_wh, max_wh = 2, 4096 # (pixels) minimum and maximum box width and height - max_det = 300 # maximum number of detections per image - time_limit = 10.0 # seconds to quit after - redundant = True # require redundant detections - multi_label = nc > 1 # multiple labels per box (adds 0.5ms/img) - - t = time.time() - output = [None] * prediction.shape[0] - for xi, x in enumerate(prediction): # image index, image inference - # Apply constraints - # x[((x[..., 2:4] < min_wh) | (x[..., 2:4] > max_wh)).any(1), 4] = 0 # width-height - x = x[xc[xi]] # confidence - - # If none remain process next image - if not x.shape[0]: - continue - - # Compute conf - x[:, 5:] *= x[:, 4:5] # conf = obj_conf * cls_conf - - # Box (center x, center y, width, height) to (x1, y1, x2, y2) - box = xywh2xyxy(x[:, :4]) - - # Detections matrix nx6 (xyxy, conf, cls) - if multi_label: - i, j = (x[:, 5:] > conf_thres).nonzero(as_tuple=False).T - x = torch.cat((box[i], x[i, j + 5, None], j[:, None].float()), 1) - else: # best class only - conf, j = x[:, 5:].max(1, keepdim=True) - x = torch.cat((box, conf, j.float()), 1)[conf.view(-1) > conf_thres] - - # Filter by class - if classes: - x = x[(x[:, 5:6] == torch.tensor(classes, device=x.device)).any(1)] - - # Apply finite constraint - # if not torch.isfinite(x).all(): - # x = x[torch.isfinite(x).all(1)] - - # If none remain process next image - n = x.shape[0] # number of boxes - if not n: - continue - # Sort by confidence - # x = x[x[:, 4].argsort(descending=True)] - - # Batched NMS - c = x[:, 5:6] * (0 if agnostic else max_wh) # classes - boxes, scores = x[:, :4] + c, x[:, 4] # boxes (offset by class), scores - i = torchvision.ops.nms(boxes, scores, iou_thres) - if i.shape[0] > max_det: # limit detections - i = i[:max_det] - if merge and (1 < n < 3E3): # Merge NMS (boxes merged using weighted mean) - try: # update boxes as boxes(i,4) = weights(i,n) * boxes(n,4) - iou = box_iou(boxes[i], boxes) > iou_thres # iou matrix - weights = iou * scores[None] # box weights - x[i, :4] = torch.mm(weights, x[:, :4]).float() / weights.sum(1, keepdim=True) # merged boxes - if redundant: - i = i[iou.sum(1) > 1] # require redundancy - except: # possible CUDA error https://github.com/ultralytics/yolov3/issues/1139 - print(x, i, x.shape, i.shape) - pass - - output[xi] = x[i] - if (time.time() - t) > time_limit: - break # time limit exceeded - - return output - - -def clip_coords(boxes, img_shape): - # Clip bounding xyxy bounding boxes to image shape (height, width) - boxes[:, 0].clamp_(0, img_shape[1]) # x1 - boxes[:, 1].clamp_(0, img_shape[0]) # y1 - boxes[:, 2].clamp_(0, img_shape[1]) # x2 - boxes[:, 3].clamp_(0, img_shape[0]) # y2 - - -def scale_coords(img1_shape, coords, img0_shape, ratio_pad=None): - # Rescale coords (xyxy) from img1_shape to img0_shape - if ratio_pad is None: # calculate from img0_shape - gain = min(img1_shape[0] / img0_shape[0], img1_shape[1] / img0_shape[1]) # gain = old / new - pad = (img1_shape[1] - img0_shape[1] * gain) / 2, (img1_shape[0] - img0_shape[0] * gain) / 2 # wh padding - else: - gain = ratio_pad[0][0] - pad = ratio_pad[1] - - coords[:, [0, 2]] -= pad[0] # x padding - coords[:, [1, 3]] -= pad[1] # y padding - coords[:, :4] /= gain - clip_coords(coords, img0_shape) - return coords - - -def post_process(flags): - names = np.loadtxt(flags.coco_class_names, dtype='str', delimiter='\n') - img = torch.zeros((1, 3, flags.net_input_size, flags.net_input_size)) - - # 读取bin文件用于生成预测结果 - bin_path = flags.bin_data_path - ori_path = flags.origin_jpg_path - - det_results_path = flags.det_results_path - os.makedirs(det_results_path, exist_ok=True) - total_img = set([name[:name.rfind('_')] - for name in os.listdir(bin_path) if "bin" in name]) - for bin_file in sorted(total_img): - path_base = os.path.join(bin_path, bin_file) - src_img = cv2.imread(os.path.join(ori_path, '{}.jpg'.format(bin_file))) - assert src_img is not None, 'Image Not Found ' + bin_file - - # 加载检测的所有输出tensor - res_buff = [] - - if flags.model_type == 'yolov5': - yolo_shape = [[1, 3, 85, 80, 80], [1, 3, 85, 40, 40], [1, 3, 85, 20, 20]] - elif flags.model_type == 'yolov3': - yolo_shape = [[1, 3, 85, 13, 13], [1, 3, 85, 26, 26], [1, 3, 85, 52, 52]] - - for num in range(flags.net_out_num): - # print(path_base + "_" + str(num + 1) + ".bin") - if os.path.exists(path_base + "_" + str(num + 1) + ".bin"): - buf = np.fromfile(path_base + "_" + - str(num + 1) + ".bin", dtype="float32") - res_buff.append(buf.reshape(yolo_shape[num]).transpose((0, 1, 3, 4, 2))) # 1,3,85,h,w ->1,3,h,w,85 - else: - print("[ERROR] file not exist", path_base + - "_" + str(num + 1) + ".bin") - - res_tensor = detect(res_buff, flags.model_type) - res_tensor = torch.from_numpy(res_tensor) - # Apply NMS - pred = non_max_suppression(res_tensor, conf_thres=0.33, iou_thres=0.5, classes=None, agnostic=False) - det_results_file = os.path.join(det_results_path, bin_file + ".txt") - - # Process detections - for i, det in enumerate(pred): # detections per image - size = '' - size += '%gx%g ' % img.shape[2:] # print string - gn = torch.tensor(src_img.shape)[[1, 0, 1, 0]] # normalization gain whwh - # Rescale boxes from img_size to im0 size - if det is not None: - det[:, :4] = scale_coords(img.shape[2:], det[:, :4], src_img.shape).round() - - # Print results - for c in det[:, -1].unique(): - n = (det[:, -1] == c).sum() # detections per class - size += '%g %ss, ' % (n, names[int(c)]) # add to string - with open(det_results_file, 'w') as f: - for *xyxy, conf, cls in det: - content = '{} {} {} {} {} {}'.format(names[int(cls)], conf, *xyxy) - print(content) - f.write(content) - f.write('\n') - else: - with open(det_results_file, 'w') as f: - f.write('') - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0") - parser.add_argument("--origin_jpg_path", default="./val2014/") - parser.add_argument("--det_results_path", - default="./detection-results/") - parser.add_argument("--coco_class_names", default="./coco2014.names") - parser.add_argument("--net_input_size", default=640, type=int) - parser.add_argument("--net_out_num", default=3) - parser.add_argument("--model_type", default='yolov5') - flags = parser.parse_args() - - post_process(flags) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import numpy as np +import argparse +import time +import torch +import torchvision +import cv2 + + +def _make_grid(nx=20, ny=20): + xv, yv = np.meshgrid(np.arange(nx), np.arange(ny)) + return np.stack((xv, yv), 2).reshape((1, 1, ny, nx, 2)).astype(np.float) + + +def sigmoid(x0): + s = 1 / (1 + np.exp(-x0)) + return s + +def detect(x, model_type): + """ + x(bs,3,20,20,85) + """ + + # x(bs,3,20,20,85) + z = [] + grid = [] + for i in range(3): + _, _, ny, nx, _ = x[i].shape + grid.append(_make_grid(nx, ny)) + if model_type == 'yolov5': + stride = np.array([8, 16, 32]) + anchor_grid = np.array( + [[10., 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]])\ + .reshape(3, 1, 3, 1, 1, 2) + elif model_type == 'yolov3': + stride = np.array([32, 16, 8]) + anchor_grid = np.array( + [[116, 90, 156, 198, 373, 326], [30, 61, 62, 45, 59, 119], [10., 13, 16, 30, 33, 23]])\ + .reshape(3, 1, 3, 1, 1, 2) + + for i in range(3): + y = sigmoid(x[i]) + y[..., 0:2] = (y[..., 0:2] * 2. - 0.5 + grid[i]) * stride[i] # xy + y[..., 2:4] = (y[..., 2:4] * 2) ** 2 * anchor_grid[i] # wh + z.append(y.reshape(1, -1, 85)) + return np.concatenate(z, 1) + + +def xywh2xyxy(x): + # Convert nx4 boxes from [x, y, w, h] to [x1, y1, x2, y2] where xy1=top-left, xy2=bottom-right + y = torch.zeros_like(x) if isinstance(x, torch.Tensor) else np.zeros_like(x) + y[:, 0] = x[:, 0] - x[:, 2] / 2 # top left x + y[:, 1] = x[:, 1] - x[:, 3] / 2 # top left y + y[:, 2] = x[:, 0] + x[:, 2] / 2 # bottom right x + y[:, 3] = x[:, 1] + x[:, 3] / 2 # bottom right y + return y + + +def non_max_suppression(prediction, conf_thres=0.1, iou_thres=0.6, merge=False, classes=None, agnostic=False): + """Performs Non-Maximum Suppression (NMS) on inference results + + Returns: + detections with shape: nx6 (x1, y1, x2, y2, conf, cls) + """ + + nc = prediction[0].shape[1] - 5 # number of classes + xc = prediction[..., 4] > conf_thres # candidates + + # Settings + min_wh, max_wh = 2, 4096 # (pixels) minimum and maximum box width and height + max_det = 300 # maximum number of detections per image + time_limit = 10.0 # seconds to quit after + redundant = True # require redundant detections + multi_label = nc > 1 # multiple labels per box (adds 0.5ms/img) + + t = time.time() + output = [None] * prediction.shape[0] + for xi, x in enumerate(prediction): # image index, image inference + # Apply constraints + # x[((x[..., 2:4] < min_wh) | (x[..., 2:4] > max_wh)).any(1), 4] = 0 # width-height + x = x[xc[xi]] # confidence + + # If none remain process next image + if not x.shape[0]: + continue + + # Compute conf + x[:, 5:] *= x[:, 4:5] # conf = obj_conf * cls_conf + + # Box (center x, center y, width, height) to (x1, y1, x2, y2) + box = xywh2xyxy(x[:, :4]) + + # Detections matrix nx6 (xyxy, conf, cls) + if multi_label: + i, j = (x[:, 5:] > conf_thres).nonzero(as_tuple=False).T + x = torch.cat((box[i], x[i, j + 5, None], j[:, None].float()), 1) + else: # best class only + conf, j = x[:, 5:].max(1, keepdim=True) + x = torch.cat((box, conf, j.float()), 1)[conf.view(-1) > conf_thres] + + # Filter by class + if classes: + x = x[(x[:, 5:6] == torch.tensor(classes, device=x.device)).any(1)] + + # Apply finite constraint + # if not torch.isfinite(x).all(): + # x = x[torch.isfinite(x).all(1)] + + # If none remain process next image + n = x.shape[0] # number of boxes + if not n: + continue + # Sort by confidence + # x = x[x[:, 4].argsort(descending=True)] + + # Batched NMS + c = x[:, 5:6] * (0 if agnostic else max_wh) # classes + boxes, scores = x[:, :4] + c, x[:, 4] # boxes (offset by class), scores + i = torchvision.ops.nms(boxes, scores, iou_thres) + if i.shape[0] > max_det: # limit detections + i = i[:max_det] + if merge and (1 < n < 3E3): # Merge NMS (boxes merged using weighted mean) + try: # update boxes as boxes(i,4) = weights(i,n) * boxes(n,4) + iou = box_iou(boxes[i], boxes) > iou_thres # iou matrix + weights = iou * scores[None] # box weights + x[i, :4] = torch.mm(weights, x[:, :4]).float() / weights.sum(1, keepdim=True) # merged boxes + if redundant: + i = i[iou.sum(1) > 1] # require redundancy + except: # possible CUDA error https://github.com/ultralytics/yolov3/issues/1139 + print(x, i, x.shape, i.shape) + pass + + output[xi] = x[i] + if (time.time() - t) > time_limit: + break # time limit exceeded + + return output + + +def clip_coords(boxes, img_shape): + # Clip bounding xyxy bounding boxes to image shape (height, width) + boxes[:, 0].clamp_(0, img_shape[1]) # x1 + boxes[:, 1].clamp_(0, img_shape[0]) # y1 + boxes[:, 2].clamp_(0, img_shape[1]) # x2 + boxes[:, 3].clamp_(0, img_shape[0]) # y2 + + +def scale_coords(img1_shape, coords, img0_shape, ratio_pad=None): + # Rescale coords (xyxy) from img1_shape to img0_shape + if ratio_pad is None: # calculate from img0_shape + gain = min(img1_shape[0] / img0_shape[0], img1_shape[1] / img0_shape[1]) # gain = old / new + pad = (img1_shape[1] - img0_shape[1] * gain) / 2, (img1_shape[0] - img0_shape[0] * gain) / 2 # wh padding + else: + gain = ratio_pad[0][0] + pad = ratio_pad[1] + + coords[:, [0, 2]] -= pad[0] # x padding + coords[:, [1, 3]] -= pad[1] # y padding + coords[:, :4] /= gain + clip_coords(coords, img0_shape) + return coords + + +def post_process(flags): + names = np.loadtxt(flags.coco_class_names, dtype='str', delimiter='\n') + img = torch.zeros((1, 3, flags.net_input_size, flags.net_input_size)) + + # 读取bin文件用于生成预测结果 + bin_path = flags.bin_data_path + ori_path = flags.origin_jpg_path + + det_results_path = flags.det_results_path + os.makedirs(det_results_path, exist_ok=True) + total_img = set([name[:name.rfind('_')] + for name in os.listdir(bin_path) if "bin" in name]) + for bin_file in sorted(total_img): + path_base = os.path.join(bin_path, bin_file) + src_img = cv2.imread(os.path.join(ori_path, '{}.jpg'.format(bin_file))) + assert src_img is not None, 'Image Not Found ' + bin_file + + # 加载检测的所有输出tensor + res_buff = [] + + if flags.model_type == 'yolov5': + yolo_shape = [[1, 3, 85, 80, 80], [1, 3, 85, 40, 40], [1, 3, 85, 20, 20]] + elif flags.model_type == 'yolov3': + yolo_shape = [[1, 3, 85, 13, 13], [1, 3, 85, 26, 26], [1, 3, 85, 52, 52]] + + for num in range(flags.net_out_num): + # print(path_base + "_" + str(num + 1) + ".bin") + if os.path.exists(path_base + "_" + str(num + 1) + ".bin"): + buf = np.fromfile(path_base + "_" + + str(num + 1) + ".bin", dtype="float32") + res_buff.append(buf.reshape(yolo_shape[num]).transpose((0, 1, 3, 4, 2))) # 1,3,85,h,w ->1,3,h,w,85 + else: + print("[ERROR] file not exist", path_base + + "_" + str(num + 1) + ".bin") + + res_tensor = detect(res_buff, flags.model_type) + res_tensor = torch.from_numpy(res_tensor) + # Apply NMS + pred = non_max_suppression(res_tensor, conf_thres=0.33, iou_thres=0.5, classes=None, agnostic=False) + det_results_file = os.path.join(det_results_path, bin_file + ".txt") + + # Process detections + for i, det in enumerate(pred): # detections per image + size = '' + size += '%gx%g ' % img.shape[2:] # print string + gn = torch.tensor(src_img.shape)[[1, 0, 1, 0]] # normalization gain whwh + # Rescale boxes from img_size to im0 size + if det is not None: + det[:, :4] = scale_coords(img.shape[2:], det[:, :4], src_img.shape).round() + + # Print results + for c in det[:, -1].unique(): + n = (det[:, -1] == c).sum() # detections per class + size += '%g %ss, ' % (n, names[int(c)]) # add to string + with open(det_results_file, 'w') as f: + for *xyxy, conf, cls in det: + content = '{} {} {} {} {} {}'.format(names[int(cls)], conf, *xyxy) + print(content) + f.write(content) + f.write('\n') + else: + with open(det_results_file, 'w') as f: + f.write('') + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0") + parser.add_argument("--origin_jpg_path", default="./val2014/") + parser.add_argument("--det_results_path", + default="./detection-results/") + parser.add_argument("--coco_class_names", default="./coco2014.names") + parser.add_argument("--net_input_size", default=640, type=int) + parser.add_argument("--net_out_num", default=3) + parser.add_argument("--model_type", default='yolov5') + flags = parser.parse_args() + + post_process(flags) diff --git a/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/get_coco_info.py b/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/get_coco_info.py index 6e9dcabeec788ddaa3c740fc671148b845ea07c9..2d795eed2ed7fc391a4e36bd92025ec9b213bb6d 100644 --- a/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/get_coco_info.py +++ b/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/get_coco_info.py @@ -1,31 +1,31 @@ -import os -import sys - -file_path = sys.argv[1] -coco_info = sys.argv[2] -info_name = sys.argv[3] - -image_names = [] -image_size = [] - -with open(coco_info, 'r') as file: - contents = file.read().split('\n') - -for content in contents[:-1]: - temp = content.split() - key = temp[1] - image_names.append(key[key.rfind('/') + 1:].split('.')[0]) - image_size.append([temp[2], temp[3]]) - -name_size = dict(zip(image_names, image_size)) - -with open(info_name, 'w') as file: - index = 0 - for key, val in name_size.items(): - bin_name = os.path.join(file_path, '{}.bin'.format(key)) - content = ' '.join([str(index), bin_name, val[0], val[1]]) - file.write(content) - file.write('\n') - index += 1 - - +import os +import sys + +file_path = sys.argv[1] +coco_info = sys.argv[2] +info_name = sys.argv[3] + +image_names = [] +image_size = [] + +with open(coco_info, 'r') as file: + contents = file.read().split('\n') + +for content in contents[:-1]: + temp = content.split() + key = temp[1] + image_names.append(key[key.rfind('/') + 1:].split('.')[0]) + image_size.append([temp[2], temp[3]]) + +name_size = dict(zip(image_names, image_size)) + +with open(info_name, 'w') as file: + index = 0 + for key, val in name_size.items(): + bin_name = os.path.join(file_path, '{}.bin'.format(key)) + content = ' '.join([str(index), bin_name, val[0], val[1]]) + file.write(content) + file.write('\n') + index += 1 + + diff --git a/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/parse_json.py b/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/parse_json.py index 2711914e8595d30942a9d02be62976cb18964ec2..29ea10ed8d251f96314e528e4c4d6d5c47e3e8f6 100644 --- a/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/parse_json.py +++ b/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/parse_json.py @@ -1,77 +1,77 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import json - -with open('./instances_val2014.json', 'r') as file: - content = file.read() -content = json.loads(content) -info = content.get('info') -licenses = content.get('licenses') -images = content.get('images') -annotations = content.get('annotations') -categroies = content.get('categories') - -with open('./coco2014.names', 'w') as f: - for categroie in categroies: - f.write(categroie.get('name').replace(' ', '_')) - f.write('\n') - -file_names = [image.get('file_name') for image in images] -widths = [image.get('width') for image in images] -heights = [image.get('height') for image in images] -image_ids = [image.get('id') for image in images] -assert len(file_names) == len(widths) == len(heights) == len(image_ids), "must be equal" - -annotation_ids = [annotation.get('image_id') for annotation in annotations] -bboxs = [annotation.get('bbox') for annotation in annotations] -category_ids = [annotation.get('category_id') for annotation in annotations] -segmentations = [annotation.get('segmentation') for annotation in annotations] -iscrowds = [annotation.get('iscrowd') for annotation in annotations] - -assert len(annotation_ids) == len(bboxs) == len(category_ids) ==len(segmentations) # 255094 - -with open('coco_2014.info', 'w') as f: - for index, file_name in enumerate(file_names): - file_name = 'val2014/' + file_name - line = "{} {} {} {}".format(index, file_name, widths[index], heights[index]) - f.write(line) - f.write('\n') - -def get_all_index(lst, item): - return [index for (index, value) in enumerate(lst) if value == item] - -def get_categroie_name(lst, item): - categroie_name = [dt.get('name') for dt in lst if item == dt.get('id')][0] - if len(categroie_name.split()) == 2: - temp = categroie_name.split() - categroie_name = temp[0] + '_' + temp[1] - return categroie_name - -for index, image_id in enumerate(image_ids): - indexs = get_all_index(annotation_ids, image_id) - with open('./ground-truth-split/{}.txt'.format(file_names[index].split('.')[0]), 'w') as f: - for idx in indexs: - f.write(get_categroie_name(categroies, category_ids[idx])) - print(get_categroie_name(categroies, category_ids[idx])) - f.write(' ') - # change label - bboxs[idx][2] = bboxs[idx][0] + bboxs[idx][2] - bboxs[idx][3] = bboxs[idx][1] + bboxs[idx][3] - f.write(' '.join(map(str, bboxs[idx]))) - f.write('\n') - - - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json + +with open('./instances_val2014.json', 'r') as file: + content = file.read() +content = json.loads(content) +info = content.get('info') +licenses = content.get('licenses') +images = content.get('images') +annotations = content.get('annotations') +categroies = content.get('categories') + +with open('./coco2014.names', 'w') as f: + for categroie in categroies: + f.write(categroie.get('name').replace(' ', '_')) + f.write('\n') + +file_names = [image.get('file_name') for image in images] +widths = [image.get('width') for image in images] +heights = [image.get('height') for image in images] +image_ids = [image.get('id') for image in images] +assert len(file_names) == len(widths) == len(heights) == len(image_ids), "must be equal" + +annotation_ids = [annotation.get('image_id') for annotation in annotations] +bboxs = [annotation.get('bbox') for annotation in annotations] +category_ids = [annotation.get('category_id') for annotation in annotations] +segmentations = [annotation.get('segmentation') for annotation in annotations] +iscrowds = [annotation.get('iscrowd') for annotation in annotations] + +assert len(annotation_ids) == len(bboxs) == len(category_ids) ==len(segmentations) # 255094 + +with open('coco_2014.info', 'w') as f: + for index, file_name in enumerate(file_names): + file_name = 'val2014/' + file_name + line = "{} {} {} {}".format(index, file_name, widths[index], heights[index]) + f.write(line) + f.write('\n') + +def get_all_index(lst, item): + return [index for (index, value) in enumerate(lst) if value == item] + +def get_categroie_name(lst, item): + categroie_name = [dt.get('name') for dt in lst if item == dt.get('id')][0] + if len(categroie_name.split()) == 2: + temp = categroie_name.split() + categroie_name = temp[0] + '_' + temp[1] + return categroie_name + +for index, image_id in enumerate(image_ids): + indexs = get_all_index(annotation_ids, image_id) + with open('./ground-truth-split/{}.txt'.format(file_names[index].split('.')[0]), 'w') as f: + for idx in indexs: + f.write(get_categroie_name(categroies, category_ids[idx])) + print(get_categroie_name(categroies, category_ids[idx])) + f.write(' ') + # change label + bboxs[idx][2] = bboxs[idx][0] + bboxs[idx][2] + bboxs[idx][3] = bboxs[idx][1] + bboxs[idx][3] + f.write(' '.join(map(str, bboxs[idx]))) + f.write('\n') + + + + diff --git a/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/preprocess_yolov3_pytorch.py b/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/preprocess_yolov3_pytorch.py index f10d988816f42ef71b442a7fefcbb7118422a0d8..ffb49084c628acda1c06a07f7410c6d7da60bbcf 100644 --- a/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/preprocess_yolov3_pytorch.py +++ b/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch/preprocess_yolov3_pytorch.py @@ -1,79 +1,79 @@ -import sys -import os -import cv2 -import numpy as np - - -def letterbox(img, new_shape=(640, 640), color=(114, 114, 114), auto=True, scaleFill=False, scaleup=True): - # Resize image to a 32-pixel-multiple rectangle https://github.com/ultralytics/yolov3/issues/232 - shape = img.shape[:2] # current shape [height, width] - if isinstance(new_shape, int): - new_shape = (new_shape, new_shape) - - # Scale ratio (new / old) - r = min(new_shape[0] / shape[0], new_shape[1] / shape[1]) - if not scaleup: # only scale down, do not scale up (for better test mAP) - r = min(r, 1.0) - - # Compute padding - ratio = r, r # width, height ratios - new_unpad = int(round(shape[1] * r)), int(round(shape[0] * r)) - dw, dh = new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1] # wh padding - # if auto: # minimum rectangle - # dw, dh = np.mod(dw, 64), np.mod(dh, 64) # wh padding - # elif scaleFill: # stretch - # dw, dh = 0.0, 0.0 - # new_unpad = (new_shape[1], new_shape[0]) - # ratio = new_shape[1] / shape[1], new_shape[0] / shape[0] # width, height ratios - - dw /= 2 # divide padding into 2 sides - dh /= 2 - - if shape[::-1] != new_unpad: # resize - img = cv2.resize(img, new_unpad, interpolation=cv2.INTER_LINEAR) - top, bottom = int(round(dh - 0.1)), int(round(dh + 0.1)) - left, right = int(round(dw - 0.1)), int(round(dw + 0.1)) - img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color) # add border - return img, ratio, (dw, dh) - - -def yolov3_onnx(src_info, output_path): - in_files = [] - if not os.path.exists(output_path): - os.makedirs(output_path) - - with open(src_info, 'r') as file: - contents = file.read().split('\n') - for i in contents[:-1]: - in_files.append(i.split()[1]) - - i = 0 - for file in in_files: - i = i + 1 - print(file, "====", i) - img0 = cv2.imread(file) - # Padded resize - img = letterbox(img0, new_shape=416)[0] - # cv2.imshow('image', img) - # cv2.waitKey(0) - # Convert - img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x640x640 - image_np = np.array(img, dtype=np.float32) - image_np /= 255.0 - # image_np = np.transpose(image_np, (2, 0, 1)) # HWC -> CHW - image_np_expanded = np.expand_dims(image_np, axis=0) # NCHW - # Focus - print("shape:", image_np_expanded.shape) - img_numpy = np.ascontiguousarray(image_np_expanded) - - # save img_tensor as binary file for om inference input - temp_name = file[file.rfind('/') + 1:] - img_numpy.tofile(os.path.join(output_path, temp_name.split('.')[0] + ".bin")) - - -if __name__ == "__main__": - src_info = os.path.abspath(sys.argv[1]) - bin_path = os.path.abspath(sys.argv[2]) - yolov3_onnx(src_info, bin_path) - - +import sys +import os +import cv2 +import numpy as np + + +def letterbox(img, new_shape=(640, 640), color=(114, 114, 114), auto=True, scaleFill=False, scaleup=True): + # Resize image to a 32-pixel-multiple rectangle https://github.com/ultralytics/yolov3/issues/232 + shape = img.shape[:2] # current shape [height, width] + if isinstance(new_shape, int): + new_shape = (new_shape, new_shape) + + # Scale ratio (new / old) + r = min(new_shape[0] / shape[0], new_shape[1] / shape[1]) + if not scaleup: # only scale down, do not scale up (for better test mAP) + r = min(r, 1.0) + + # Compute padding + ratio = r, r # width, height ratios + new_unpad = int(round(shape[1] * r)), int(round(shape[0] * r)) + dw, dh = new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1] # wh padding + # if auto: # minimum rectangle + # dw, dh = np.mod(dw, 64), np.mod(dh, 64) # wh padding + # elif scaleFill: # stretch + # dw, dh = 0.0, 0.0 + # new_unpad = (new_shape[1], new_shape[0]) + # ratio = new_shape[1] / shape[1], new_shape[0] / shape[0] # width, height ratios + + dw /= 2 # divide padding into 2 sides + dh /= 2 + + if shape[::-1] != new_unpad: # resize + img = cv2.resize(img, new_unpad, interpolation=cv2.INTER_LINEAR) + top, bottom = int(round(dh - 0.1)), int(round(dh + 0.1)) + left, right = int(round(dw - 0.1)), int(round(dw + 0.1)) + img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color) # add border + return img, ratio, (dw, dh) + + +def yolov3_onnx(src_info, output_path): + in_files = [] + if not os.path.exists(output_path): + os.makedirs(output_path) + + with open(src_info, 'r') as file: + contents = file.read().split('\n') + for i in contents[:-1]: + in_files.append(i.split()[1]) + + i = 0 + for file in in_files: + i = i + 1 + print(file, "====", i) + img0 = cv2.imread(file) + # Padded resize + img = letterbox(img0, new_shape=416)[0] + # cv2.imshow('image', img) + # cv2.waitKey(0) + # Convert + img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x640x640 + image_np = np.array(img, dtype=np.float32) + image_np /= 255.0 + # image_np = np.transpose(image_np, (2, 0, 1)) # HWC -> CHW + image_np_expanded = np.expand_dims(image_np, axis=0) # NCHW + # Focus + print("shape:", image_np_expanded.shape) + img_numpy = np.ascontiguousarray(image_np_expanded) + + # save img_tensor as binary file for om inference input + temp_name = file[file.rfind('/') + 1:] + img_numpy.tofile(os.path.join(output_path, temp_name.split('.')[0] + ".bin")) + + +if __name__ == "__main__": + src_info = os.path.abspath(sys.argv[1]) + bin_path = os.path.abspath(sys.argv[2]) + yolov3_onnx(src_info, bin_path) + + diff --git a/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/README.md b/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/README.md index bfd8ba1dbeeb6dd01466c8be91a444d3daffec44..62f196a12425d450734d43d52dbe8be39d8e6dc1 100644 --- a/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/README.md +++ b/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/README.md @@ -1,106 +1,106 @@ -文件作用说明: - -1. dy_resize.py:onnx算子修改脚本 -2. env.sh:ATC工具环境变量配置脚本 -3. parse_json.py: coco数据集标签json文件解析脚本 -4. preprocess_yolov4_pytorch.py: 二进制数据集预处理脚本 -5. get_coco_info.py: yolov4.info生成脚本 -6. bin_to_predict_yolov4_pytorch.py: benchmark输出bin文件解析脚本 -7. map_calculate.py: 精度统计脚本 -8. aipp.config 配置文件 -9. require.txt:脚本运行所需的第三方库 - -推理端到端步骤: - -(1) git clone 开源仓https://github.com/Tianxiaomo/pytorch-YOLOv4,并下载对应的权重文件, 修改**demo_pytorch2onnx.py**脚本生成onnx文件 - -```shell -git clone https://github.com/Tianxiaomo/pytorch-YOLOv4 -python3 demo_pytorch2onnx.py yolov4.pth data/dog.jpg -1 80 608 608 -``` - -(2)运行dy_resize.py修改生成的onnx文件 - -```shell -python3.7 dy_resize.py yolov4_-1_3_608_608_dynamic.onnx -``` - -(3)配置环境变量转换om模型 - -``` -source env.sh - -# soc_version:支持Ascend310和Ascend710 - -# 二进制输入 -atc --model=yolov4_-1_3_608_608_dynamic_dbs.onnx --framework=5 --output=yolov4_bs1 --input_format=NCHW --log=info --soc_version=Ascend310 --input_shape="input:1,3,608,608" --insert_op_conf=aipp.config --enable_small_channel=1 - -# 二进制输入 int8量化 -atc --model=yolov4_deploy_model.onnx --framework=5 --output=yolov4_bs1 --input_format=NCHW --log=info --soc_version=Ascend310 --input_shape="input:1,3,608,608" --insert_op_conf=aipp.config --enable_small_channel=1 - -``` - -(4)解析数据集 - -下载coco2014数据集val2014和label文件**instances_valminusminival2014.json**,运行**parse_json.py**解析数据集 - -``` -python3.7 parse_json.py -``` - -生成coco2014.name和coco_2014.info以及gronud-truth文件夹 - -(5)数据预处理 - -运行脚本preprocess_yolov4_pytorch.py处理数据集 - -``` -python3.7 preprocess_yolov4_pytorch.py coco_2014.info yolov4_bin int8 -1 -``` - -(6)onnx模型量化(可选) - -1.AMCT工具包安装,具体参考[CANN 开发辅助工具指南 (推理)](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools) - -2.数据预处理,用于量化因子矫正。当前模型为动态batch,建议用多batch_size的预处理文件矫正量化因子。 -执行以下命令: -``` -python3.7 preprocess_yolov4_pytorch.py coco_2014.info uncalibration_bin float32 1000 -python3.7.5 calibration_bin.py uncalibration_bin calibration_bin 32 -``` - -3.ONNX模型量化,具体参考[CANN 开发辅助工具指南 (推理)](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools) -在result目录下生成yolov4_deploy_model.onnx量化模型 - -4.量化模型验证,除onnx离线模型转换om模型命令有区别外,其余一致 - - -(7)benchmark推理 - -运行get_coco_info.py生成info文件 - -``` -python3.7 get_coco_info.py yolov4_bin coco_2014.info yolov4.info -``` - -执行benchmark命令,结果保存在同级目录 result/dumpOutput_device0/ - -``` -# 二进制 -./benchmark.x86_64 -model_type=vision -batch_size=1 -device_id=0 -om_path=yolov4_bs1.om -input_width=608 -input_height=608 -input_text_path=yolov4.info -useDvpp=false -output_binary=true -``` - -(8)后处理 - -运行 bin_to_predict_yolov4_pytorch.py 解析模型输出 - -``` -python3.7 bin_to_predict_yolov4_pytorch.py --bin_data_path result/dumpOutput_device0/ --det_results_path detection-results/ --origin_jpg_path /root/dataset/coco2014/val2014/ --coco_class_names /root/dataset/coco2014/coco2014.names -``` - -运行map_cauculate.py统计mAP值 - -``` -python3 map_calculate.py --label_path ./ground-truth --npu_txt_path ./detection-results -na -np -``` - +文件作用说明: + +1. dy_resize.py:onnx算子修改脚本 +2. env.sh:ATC工具环境变量配置脚本 +3. parse_json.py: coco数据集标签json文件解析脚本 +4. preprocess_yolov4_pytorch.py: 二进制数据集预处理脚本 +5. get_coco_info.py: yolov4.info生成脚本 +6. bin_to_predict_yolov4_pytorch.py: benchmark输出bin文件解析脚本 +7. map_calculate.py: 精度统计脚本 +8. aipp.config 配置文件 +9. require.txt:脚本运行所需的第三方库 + +推理端到端步骤: + +(1) git clone 开源仓https://github.com/Tianxiaomo/pytorch-YOLOv4,并下载对应的权重文件, 修改**demo_pytorch2onnx.py**脚本生成onnx文件 + +```shell +git clone https://github.com/Tianxiaomo/pytorch-YOLOv4 +python3 demo_pytorch2onnx.py yolov4.pth data/dog.jpg -1 80 608 608 +``` + +(2)运行dy_resize.py修改生成的onnx文件 + +```shell +python3.7 dy_resize.py yolov4_-1_3_608_608_dynamic.onnx +``` + +(3)配置环境变量转换om模型 + +``` +source env.sh + +# soc_version:支持Ascend310和Ascend710 + +# 二进制输入 +atc --model=yolov4_-1_3_608_608_dynamic_dbs.onnx --framework=5 --output=yolov4_bs1 --input_format=NCHW --log=info --soc_version=Ascend310 --input_shape="input:1,3,608,608" --insert_op_conf=aipp.config --enable_small_channel=1 + +# 二进制输入 int8量化 +atc --model=yolov4_deploy_model.onnx --framework=5 --output=yolov4_bs1 --input_format=NCHW --log=info --soc_version=Ascend310 --input_shape="input:1,3,608,608" --insert_op_conf=aipp.config --enable_small_channel=1 + +``` + +(4)解析数据集 + +下载coco2014数据集val2014和label文件**instances_valminusminival2014.json**,运行**parse_json.py**解析数据集 + +``` +python3.7 parse_json.py +``` + +生成coco2014.name和coco_2014.info以及gronud-truth文件夹 + +(5)数据预处理 + +运行脚本preprocess_yolov4_pytorch.py处理数据集 + +``` +python3.7 preprocess_yolov4_pytorch.py coco_2014.info yolov4_bin int8 -1 +``` + +(6)onnx模型量化(可选) + +1.AMCT工具包安装,具体参考[CANN 开发辅助工具指南 (推理)](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools) + +2.数据预处理,用于量化因子矫正。当前模型为动态batch,建议用多batch_size的预处理文件矫正量化因子。 +执行以下命令: +``` +python3.7 preprocess_yolov4_pytorch.py coco_2014.info uncalibration_bin float32 1000 +python3.7.5 calibration_bin.py uncalibration_bin calibration_bin 32 +``` + +3.ONNX模型量化,具体参考[CANN 开发辅助工具指南 (推理)](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=developer-documents&subcategory=auxiliary-development-tools) +在result目录下生成yolov4_deploy_model.onnx量化模型 + +4.量化模型验证,除onnx离线模型转换om模型命令有区别外,其余一致 + + +(7)benchmark推理 + +运行get_coco_info.py生成info文件 + +``` +python3.7 get_coco_info.py yolov4_bin coco_2014.info yolov4.info +``` + +执行benchmark命令,结果保存在同级目录 result/dumpOutput_device0/ + +``` +# 二进制 +./benchmark.x86_64 -model_type=vision -batch_size=1 -device_id=0 -om_path=yolov4_bs1.om -input_width=608 -input_height=608 -input_text_path=yolov4.info -useDvpp=false -output_binary=true +``` + +(8)后处理 + +运行 bin_to_predict_yolov4_pytorch.py 解析模型输出 + +``` +python3.7 bin_to_predict_yolov4_pytorch.py --bin_data_path result/dumpOutput_device0/ --det_results_path detection-results/ --origin_jpg_path /root/dataset/coco2014/val2014/ --coco_class_names /root/dataset/coco2014/coco2014.names +``` + +运行map_cauculate.py统计mAP值 + +``` +python3 map_calculate.py --label_path ./ground-truth --npu_txt_path ./detection-results -na -np +``` + diff --git a/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/bin_to_predict_yolov4_pytorch.py b/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/bin_to_predict_yolov4_pytorch.py index bb932cbf332e0984ac1e161c8a8d5f5b65bef75a..9f58821cafe0235384c9c1717a99f7d37fc49add 100644 --- a/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/bin_to_predict_yolov4_pytorch.py +++ b/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/bin_to_predict_yolov4_pytorch.py @@ -1,361 +1,361 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import numpy as np -import argparse -import time -import torch -import torchvision -import cv2 - - -def yolo_forward_dynamic(output, num_classes, anchors, num_anchors, scale_x_y): - bxy_list = [] - bwh_list = [] - det_confs_list = [] - cls_confs_list = [] - - for i in range(num_anchors): - begin = i * (5 + num_classes) - end = (i + 1) * (5 + num_classes) - - bxy_list.append(output[:, begin: begin + 2]) - bwh_list.append(output[:, begin + 2: begin + 4]) - det_confs_list.append(output[:, begin + 4: begin + 5]) - cls_confs_list.append(output[:, begin + 5: end]) - - # Shape: [batch, num_anchors * 2, H, W] - bxy = torch.cat(bxy_list, dim=1) - # Shape: [batch, num_anchors * 2, H, W] - bwh = torch.cat(bwh_list, dim=1) - - # Shape: [batch, num_anchors, H, W] - det_confs = torch.cat(det_confs_list, dim=1) - # Shape: [batch, num_anchors * H * W] - det_confs = det_confs.view(output.size(0), num_anchors * output.size(2) * output.size(3)) - - # Shape: [batch, num_anchors * num_classes, H, W] - cls_confs = torch.cat(cls_confs_list, dim=1) - # Shape: [batch, num_anchors, num_classes, H * W] - cls_confs = cls_confs.view(output.size(0), num_anchors, num_classes, output.size(2) * output.size(3)) - # Shape: [batch, num_anchors, num_classes, H * W] --> [batch, num_anchors * H * W, num_classes] - cls_confs = cls_confs.permute(0, 1, 3, 2).reshape(output.size(0), num_anchors * output.size(2) * output.size(3), - num_classes) - - # Apply sigmoid(), exp() and softmax() to slices - bxy = torch.sigmoid(bxy) * scale_x_y - 0.5 * (scale_x_y - 1) - bwh = torch.exp(bwh) - det_confs = torch.sigmoid(det_confs) - cls_confs = torch.sigmoid(cls_confs) - - # Prepare C-x, C-y, P-w, P-h (None of them are torch related) - grid_x = np.expand_dims(np.expand_dims( - np.expand_dims(np.linspace(0, output.size(3) - 1, output.size(3)), axis=0).repeat(output.size(2), 0), axis=0), - axis=0) - grid_y = np.expand_dims(np.expand_dims( - np.expand_dims(np.linspace(0, output.size(2) - 1, output.size(2)), axis=1).repeat(output.size(3), 1), axis=0), - axis=0) - - anchor_w = [] - anchor_h = [] - for i in range(num_anchors): - anchor_w.append(anchors[i * 2]) - anchor_h.append(anchors[i * 2 + 1]) - - device = None - cuda_check = output.is_cuda - if cuda_check: - device = output.get_device() - - bx_list = [] - by_list = [] - bw_list = [] - bh_list = [] - - # Apply C-x, C-y, P-w, P-h - for i in range(num_anchors): - ii = i * 2 - # Shape: [batch, 1, H, W] - bx = bxy[:, ii: ii + 1] + torch.tensor(grid_x, device=device, - dtype=torch.float32) # grid_x.to(device=device, dtype=torch.float32) - # Shape: [batch, 1, H, W] - by = bxy[:, ii + 1: ii + 2] + torch.tensor(grid_y, device=device, - dtype=torch.float32) # grid_y.to(device=device, dtype=torch.float32) - # Shape: [batch, 1, H, W] - bw = bwh[:, ii: ii + 1] * anchor_w[i] - # Shape: [batch, 1, H, W] - bh = bwh[:, ii + 1: ii + 2] * anchor_h[i] - - bx_list.append(bx) - by_list.append(by) - bw_list.append(bw) - bh_list.append(bh) - - ######################################## - # Figure out bboxes from slices # - ######################################## - - # Shape: [batch, num_anchors, H, W] - bx = torch.cat(bx_list, dim=1) - # Shape: [batch, num_anchors, H, W] - by = torch.cat(by_list, dim=1) - # Shape: [batch, num_anchors, H, W] - bw = torch.cat(bw_list, dim=1) - # Shape: [batch, num_anchors, H, W] - bh = torch.cat(bh_list, dim=1) - - # Shape: [batch, 2 * num_anchors, H, W] - bx_bw = torch.cat((bx, bw), dim=1) - # Shape: [batch, 2 * num_anchors, H, W] - by_bh = torch.cat((by, bh), dim=1) - - # normalize coordinates to [0, 1] - bx_bw /= output.size(3) - by_bh /= output.size(2) - - # Shape: [batch, num_anchors * H * W, 1] - bx = bx_bw[:, :num_anchors].view(output.size(0), num_anchors * output.size(2) * output.size(3), 1) - by = by_bh[:, :num_anchors].view(output.size(0), num_anchors * output.size(2) * output.size(3), 1) - bw = bx_bw[:, num_anchors:].view(output.size(0), num_anchors * output.size(2) * output.size(3), 1) - bh = by_bh[:, num_anchors:].view(output.size(0), num_anchors * output.size(2) * output.size(3), 1) - - bx1 = bx - bw * 0.5 - by1 = by - bh * 0.5 - bx2 = bx1 + bw - by2 = by1 + bh - - # Shape: [batch, num_anchors * h * w, 4] -> [batch, num_anchors * h * w, 1, 4] - boxes = torch.cat((bx1, by1, bx2, by2), dim=2).view(output.size(0), num_anchors * output.size(2) * output.size(3), - 1, 4) - - det_confs = det_confs.view(output.size(0), num_anchors * output.size(2) * output.size(3), 1) - confs = cls_confs * det_confs - - return boxes, confs - - -class YoloLayer(object): - ''' Yolo layer - model_out: while inference,is post-processing inside or outside the model - true:outside - ''' - def __init__(self, anchor_mask=[], num_classes=0, anchors=[], num_anchors=1, stride=32, model_out=False): - - self.anchor_mask = anchor_mask - self.num_classes = num_classes - self.anchors = anchors - self.num_anchors = num_anchors - self.anchor_step = len(anchors) // num_anchors - self.coord_scale = 1 - self.noobject_scale = 1 - self.object_scale = 5 - self.class_scale = 1 - self.thresh = 0.6 - self.stride = stride - self.seen = 0 - self.scale_x_y = 1 - - self.model_out = model_out - - - def forward(self, output): - masked_anchors = [] - for m in self.anchor_mask: - masked_anchors += self.anchors[m * self.anchor_step:(m + 1) * self.anchor_step] - masked_anchors = [anchor / self.stride for anchor in masked_anchors] - - return yolo_forward_dynamic(output, self.num_classes, masked_anchors, - len(self.anchor_mask), scale_x_y=self.scale_x_y) - - -def get_region_boxes(boxes_and_confs): - # print('Getting boxes from boxes and confs ...') - - boxes_list = [] - confs_list = [] - - for item in boxes_and_confs: - boxes_list.append(item[0]) - confs_list.append(item[1]) - - # boxes: [batch, num1 + num2 + num3, 1, 4] - # confs: [batch, num1 + num2 + num3, num_classes] - boxes = torch.cat(boxes_list, dim=1) - confs = torch.cat(confs_list, dim=1) - - return [boxes, confs] - - -def nms_cpu(boxes, confs, nms_thresh=0.5, min_mode=False): - # print(boxes.shape) - x1 = boxes[:, 0] - y1 = boxes[:, 1] - x2 = boxes[:, 2] - y2 = boxes[:, 3] - - areas = (x2 - x1) * (y2 - y1) - order = confs.argsort()[::-1] - - keep = [] - while order.size > 0: - idx_self = order[0] - idx_other = order[1:] - - keep.append(idx_self) - - xx1 = np.maximum(x1[idx_self], x1[idx_other]) - yy1 = np.maximum(y1[idx_self], y1[idx_other]) - xx2 = np.minimum(x2[idx_self], x2[idx_other]) - yy2 = np.minimum(y2[idx_self], y2[idx_other]) - - w = np.maximum(0.0, xx2 - xx1) - h = np.maximum(0.0, yy2 - yy1) - inter = w * h - - if min_mode: - over = inter / np.minimum(areas[order[0]], areas[order[1:]]) - else: - over = inter / (areas[order[0]] + areas[order[1:]] - inter) - - inds = np.where(over <= nms_thresh)[0] - order = order[inds + 1] - - return np.array(keep) - - -def nms(conf_thresh, nms_thresh, output): - # [batch, num, 1, 4] - box_array = output[0] - # [batch, num, num_classes] - confs = output[1] - - if type(box_array).__name__ != 'ndarray': - box_array = box_array.cpu().detach().numpy() - confs = confs.cpu().detach().numpy() - - num_classes = confs.shape[2] - - # [batch, num, 4] - box_array = box_array[:, :, 0] - - # [batch, num, num_classes] --> [batch, num] - max_conf = np.max(confs, axis=2) - max_id = np.argmax(confs, axis=2) - - bboxes_batch = [] - for i in range(box_array.shape[0]): - - argwhere = max_conf[i] > conf_thresh - l_box_array = box_array[i, argwhere, :] - l_max_conf = max_conf[i, argwhere] - l_max_id = max_id[i, argwhere] - - bboxes = [] - # nms for each class - for j in range(num_classes): - - cls_argwhere = l_max_id == j - ll_box_array = l_box_array[cls_argwhere, :] - ll_max_conf = l_max_conf[cls_argwhere] - ll_max_id = l_max_id[cls_argwhere] - - keep = nms_cpu(ll_box_array, ll_max_conf, nms_thresh) - - if (keep.size > 0): - ll_box_array = ll_box_array[keep, :] - ll_max_conf = ll_max_conf[keep] - ll_max_id = ll_max_id[keep] - - for k in range(ll_box_array.shape[0]): - bboxes.append( - [ll_box_array[k, 0], ll_box_array[k, 1], ll_box_array[k, 2], ll_box_array[k, 3], - ll_max_conf[k], ll_max_id[k]]) - - bboxes_batch.append(bboxes) - - return bboxes_batch - - -def post_process(flags): - names = np.loadtxt(flags.coco_class_names, dtype='str', delimiter='\n') - - # 读取bin文件用于生成预测结果 - bin_path = flags.bin_data_path - ori_path = flags.origin_jpg_path - - anchors = [12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401] - num_classes = 80 - - det_results_path = flags.det_results_path - os.makedirs(det_results_path, exist_ok=True) - total_img = set([name[:name.rfind('_')] - for name in os.listdir(bin_path) if "bin" in name]) - - yolo1 = YoloLayer(anchor_mask=[0, 1, 2], num_classes=num_classes, anchors=anchors, num_anchors=9, stride=8) - yolo2 = YoloLayer(anchor_mask=[3, 4, 5], num_classes=num_classes, anchors=anchors, num_anchors=9, stride=16) - yolo3 = YoloLayer(anchor_mask=[6, 7, 8], num_classes=num_classes, anchors=anchors, num_anchors=9, stride=32) - - yolo_shape = [[1, 255, 76, 76], [1, 255, 38, 38], [1, 255, 19, 19]] - - for bin_file in sorted(total_img): - path_base = os.path.join(bin_path, bin_file) - src_img = cv2.imread(os.path.join(ori_path, '{}.jpg'.format(bin_file))) - assert src_img is not None, 'Image Not Found ' + bin_file - - # 加载检测的所有输出tensor - feature_map_1 = np.fromfile(path_base + "_" + '1' + ".bin", dtype="float32").reshape(yolo_shape[0]) - feature_map_2 = np.fromfile(path_base + "_" + '2' + ".bin", dtype="float32").reshape(yolo_shape[1]) - feature_map_3 = np.fromfile(path_base + "_" + '3' + ".bin", dtype="float32").reshape(yolo_shape[2]) - - pred_1 = yolo1.forward(torch.from_numpy(feature_map_1)) - pred_2 = yolo2.forward(torch.from_numpy(feature_map_2)) - pred_3 = yolo3.forward(torch.from_numpy(feature_map_3)) - - # nms - output = get_region_boxes([pred_1, pred_2, pred_3]) - pred = nms(conf_thresh=0.4, nms_thresh=0.6, output=output)[0] - - # save result - det_results_file = os.path.join(det_results_path, bin_file + ".txt") - print(det_results_file) - with open(det_results_file, 'w') as f: - width = src_img.shape[1] - height = src_img.shape[0] - for i in range(len(pred)): - box = pred[i] - x1 = int(box[0] * width) - y1 = int(box[1] * height) - x2 = int(box[2] * width) - y2 = int(box[3] * height) - cls_conf = box[4] - cls_id = box[5] - - content = '{} {} {} {} {} {}'.format(names[int(cls_id)], cls_conf, x1, y1, x2, y2) - f.write(content) - f.write('\n') - - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0") - parser.add_argument("--origin_jpg_path", default="./val2014/") - parser.add_argument("--det_results_path", - default="./detection-results/") - parser.add_argument("--coco_class_names", default="./coco2014.names") - parser.add_argument("--net_out_num", default=3) - flags = parser.parse_args() - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import numpy as np +import argparse +import time +import torch +import torchvision +import cv2 + + +def yolo_forward_dynamic(output, num_classes, anchors, num_anchors, scale_x_y): + bxy_list = [] + bwh_list = [] + det_confs_list = [] + cls_confs_list = [] + + for i in range(num_anchors): + begin = i * (5 + num_classes) + end = (i + 1) * (5 + num_classes) + + bxy_list.append(output[:, begin: begin + 2]) + bwh_list.append(output[:, begin + 2: begin + 4]) + det_confs_list.append(output[:, begin + 4: begin + 5]) + cls_confs_list.append(output[:, begin + 5: end]) + + # Shape: [batch, num_anchors * 2, H, W] + bxy = torch.cat(bxy_list, dim=1) + # Shape: [batch, num_anchors * 2, H, W] + bwh = torch.cat(bwh_list, dim=1) + + # Shape: [batch, num_anchors, H, W] + det_confs = torch.cat(det_confs_list, dim=1) + # Shape: [batch, num_anchors * H * W] + det_confs = det_confs.view(output.size(0), num_anchors * output.size(2) * output.size(3)) + + # Shape: [batch, num_anchors * num_classes, H, W] + cls_confs = torch.cat(cls_confs_list, dim=1) + # Shape: [batch, num_anchors, num_classes, H * W] + cls_confs = cls_confs.view(output.size(0), num_anchors, num_classes, output.size(2) * output.size(3)) + # Shape: [batch, num_anchors, num_classes, H * W] --> [batch, num_anchors * H * W, num_classes] + cls_confs = cls_confs.permute(0, 1, 3, 2).reshape(output.size(0), num_anchors * output.size(2) * output.size(3), + num_classes) + + # Apply sigmoid(), exp() and softmax() to slices + bxy = torch.sigmoid(bxy) * scale_x_y - 0.5 * (scale_x_y - 1) + bwh = torch.exp(bwh) + det_confs = torch.sigmoid(det_confs) + cls_confs = torch.sigmoid(cls_confs) + + # Prepare C-x, C-y, P-w, P-h (None of them are torch related) + grid_x = np.expand_dims(np.expand_dims( + np.expand_dims(np.linspace(0, output.size(3) - 1, output.size(3)), axis=0).repeat(output.size(2), 0), axis=0), + axis=0) + grid_y = np.expand_dims(np.expand_dims( + np.expand_dims(np.linspace(0, output.size(2) - 1, output.size(2)), axis=1).repeat(output.size(3), 1), axis=0), + axis=0) + + anchor_w = [] + anchor_h = [] + for i in range(num_anchors): + anchor_w.append(anchors[i * 2]) + anchor_h.append(anchors[i * 2 + 1]) + + device = None + cuda_check = output.is_cuda + if cuda_check: + device = output.get_device() + + bx_list = [] + by_list = [] + bw_list = [] + bh_list = [] + + # Apply C-x, C-y, P-w, P-h + for i in range(num_anchors): + ii = i * 2 + # Shape: [batch, 1, H, W] + bx = bxy[:, ii: ii + 1] + torch.tensor(grid_x, device=device, + dtype=torch.float32) # grid_x.to(device=device, dtype=torch.float32) + # Shape: [batch, 1, H, W] + by = bxy[:, ii + 1: ii + 2] + torch.tensor(grid_y, device=device, + dtype=torch.float32) # grid_y.to(device=device, dtype=torch.float32) + # Shape: [batch, 1, H, W] + bw = bwh[:, ii: ii + 1] * anchor_w[i] + # Shape: [batch, 1, H, W] + bh = bwh[:, ii + 1: ii + 2] * anchor_h[i] + + bx_list.append(bx) + by_list.append(by) + bw_list.append(bw) + bh_list.append(bh) + + ######################################## + # Figure out bboxes from slices # + ######################################## + + # Shape: [batch, num_anchors, H, W] + bx = torch.cat(bx_list, dim=1) + # Shape: [batch, num_anchors, H, W] + by = torch.cat(by_list, dim=1) + # Shape: [batch, num_anchors, H, W] + bw = torch.cat(bw_list, dim=1) + # Shape: [batch, num_anchors, H, W] + bh = torch.cat(bh_list, dim=1) + + # Shape: [batch, 2 * num_anchors, H, W] + bx_bw = torch.cat((bx, bw), dim=1) + # Shape: [batch, 2 * num_anchors, H, W] + by_bh = torch.cat((by, bh), dim=1) + + # normalize coordinates to [0, 1] + bx_bw /= output.size(3) + by_bh /= output.size(2) + + # Shape: [batch, num_anchors * H * W, 1] + bx = bx_bw[:, :num_anchors].view(output.size(0), num_anchors * output.size(2) * output.size(3), 1) + by = by_bh[:, :num_anchors].view(output.size(0), num_anchors * output.size(2) * output.size(3), 1) + bw = bx_bw[:, num_anchors:].view(output.size(0), num_anchors * output.size(2) * output.size(3), 1) + bh = by_bh[:, num_anchors:].view(output.size(0), num_anchors * output.size(2) * output.size(3), 1) + + bx1 = bx - bw * 0.5 + by1 = by - bh * 0.5 + bx2 = bx1 + bw + by2 = by1 + bh + + # Shape: [batch, num_anchors * h * w, 4] -> [batch, num_anchors * h * w, 1, 4] + boxes = torch.cat((bx1, by1, bx2, by2), dim=2).view(output.size(0), num_anchors * output.size(2) * output.size(3), + 1, 4) + + det_confs = det_confs.view(output.size(0), num_anchors * output.size(2) * output.size(3), 1) + confs = cls_confs * det_confs + + return boxes, confs + + +class YoloLayer(object): + ''' Yolo layer + model_out: while inference,is post-processing inside or outside the model + true:outside + ''' + def __init__(self, anchor_mask=[], num_classes=0, anchors=[], num_anchors=1, stride=32, model_out=False): + + self.anchor_mask = anchor_mask + self.num_classes = num_classes + self.anchors = anchors + self.num_anchors = num_anchors + self.anchor_step = len(anchors) // num_anchors + self.coord_scale = 1 + self.noobject_scale = 1 + self.object_scale = 5 + self.class_scale = 1 + self.thresh = 0.6 + self.stride = stride + self.seen = 0 + self.scale_x_y = 1 + + self.model_out = model_out + + + def forward(self, output): + masked_anchors = [] + for m in self.anchor_mask: + masked_anchors += self.anchors[m * self.anchor_step:(m + 1) * self.anchor_step] + masked_anchors = [anchor / self.stride for anchor in masked_anchors] + + return yolo_forward_dynamic(output, self.num_classes, masked_anchors, + len(self.anchor_mask), scale_x_y=self.scale_x_y) + + +def get_region_boxes(boxes_and_confs): + # print('Getting boxes from boxes and confs ...') + + boxes_list = [] + confs_list = [] + + for item in boxes_and_confs: + boxes_list.append(item[0]) + confs_list.append(item[1]) + + # boxes: [batch, num1 + num2 + num3, 1, 4] + # confs: [batch, num1 + num2 + num3, num_classes] + boxes = torch.cat(boxes_list, dim=1) + confs = torch.cat(confs_list, dim=1) + + return [boxes, confs] + + +def nms_cpu(boxes, confs, nms_thresh=0.5, min_mode=False): + # print(boxes.shape) + x1 = boxes[:, 0] + y1 = boxes[:, 1] + x2 = boxes[:, 2] + y2 = boxes[:, 3] + + areas = (x2 - x1) * (y2 - y1) + order = confs.argsort()[::-1] + + keep = [] + while order.size > 0: + idx_self = order[0] + idx_other = order[1:] + + keep.append(idx_self) + + xx1 = np.maximum(x1[idx_self], x1[idx_other]) + yy1 = np.maximum(y1[idx_self], y1[idx_other]) + xx2 = np.minimum(x2[idx_self], x2[idx_other]) + yy2 = np.minimum(y2[idx_self], y2[idx_other]) + + w = np.maximum(0.0, xx2 - xx1) + h = np.maximum(0.0, yy2 - yy1) + inter = w * h + + if min_mode: + over = inter / np.minimum(areas[order[0]], areas[order[1:]]) + else: + over = inter / (areas[order[0]] + areas[order[1:]] - inter) + + inds = np.where(over <= nms_thresh)[0] + order = order[inds + 1] + + return np.array(keep) + + +def nms(conf_thresh, nms_thresh, output): + # [batch, num, 1, 4] + box_array = output[0] + # [batch, num, num_classes] + confs = output[1] + + if type(box_array).__name__ != 'ndarray': + box_array = box_array.cpu().detach().numpy() + confs = confs.cpu().detach().numpy() + + num_classes = confs.shape[2] + + # [batch, num, 4] + box_array = box_array[:, :, 0] + + # [batch, num, num_classes] --> [batch, num] + max_conf = np.max(confs, axis=2) + max_id = np.argmax(confs, axis=2) + + bboxes_batch = [] + for i in range(box_array.shape[0]): + + argwhere = max_conf[i] > conf_thresh + l_box_array = box_array[i, argwhere, :] + l_max_conf = max_conf[i, argwhere] + l_max_id = max_id[i, argwhere] + + bboxes = [] + # nms for each class + for j in range(num_classes): + + cls_argwhere = l_max_id == j + ll_box_array = l_box_array[cls_argwhere, :] + ll_max_conf = l_max_conf[cls_argwhere] + ll_max_id = l_max_id[cls_argwhere] + + keep = nms_cpu(ll_box_array, ll_max_conf, nms_thresh) + + if (keep.size > 0): + ll_box_array = ll_box_array[keep, :] + ll_max_conf = ll_max_conf[keep] + ll_max_id = ll_max_id[keep] + + for k in range(ll_box_array.shape[0]): + bboxes.append( + [ll_box_array[k, 0], ll_box_array[k, 1], ll_box_array[k, 2], ll_box_array[k, 3], + ll_max_conf[k], ll_max_id[k]]) + + bboxes_batch.append(bboxes) + + return bboxes_batch + + +def post_process(flags): + names = np.loadtxt(flags.coco_class_names, dtype='str', delimiter='\n') + + # 读取bin文件用于生成预测结果 + bin_path = flags.bin_data_path + ori_path = flags.origin_jpg_path + + anchors = [12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401] + num_classes = 80 + + det_results_path = flags.det_results_path + os.makedirs(det_results_path, exist_ok=True) + total_img = set([name[:name.rfind('_')] + for name in os.listdir(bin_path) if "bin" in name]) + + yolo1 = YoloLayer(anchor_mask=[0, 1, 2], num_classes=num_classes, anchors=anchors, num_anchors=9, stride=8) + yolo2 = YoloLayer(anchor_mask=[3, 4, 5], num_classes=num_classes, anchors=anchors, num_anchors=9, stride=16) + yolo3 = YoloLayer(anchor_mask=[6, 7, 8], num_classes=num_classes, anchors=anchors, num_anchors=9, stride=32) + + yolo_shape = [[1, 255, 76, 76], [1, 255, 38, 38], [1, 255, 19, 19]] + + for bin_file in sorted(total_img): + path_base = os.path.join(bin_path, bin_file) + src_img = cv2.imread(os.path.join(ori_path, '{}.jpg'.format(bin_file))) + assert src_img is not None, 'Image Not Found ' + bin_file + + # 加载检测的所有输出tensor + feature_map_1 = np.fromfile(path_base + "_" + '1' + ".bin", dtype="float32").reshape(yolo_shape[0]) + feature_map_2 = np.fromfile(path_base + "_" + '2' + ".bin", dtype="float32").reshape(yolo_shape[1]) + feature_map_3 = np.fromfile(path_base + "_" + '3' + ".bin", dtype="float32").reshape(yolo_shape[2]) + + pred_1 = yolo1.forward(torch.from_numpy(feature_map_1)) + pred_2 = yolo2.forward(torch.from_numpy(feature_map_2)) + pred_3 = yolo3.forward(torch.from_numpy(feature_map_3)) + + # nms + output = get_region_boxes([pred_1, pred_2, pred_3]) + pred = nms(conf_thresh=0.4, nms_thresh=0.6, output=output)[0] + + # save result + det_results_file = os.path.join(det_results_path, bin_file + ".txt") + print(det_results_file) + with open(det_results_file, 'w') as f: + width = src_img.shape[1] + height = src_img.shape[0] + for i in range(len(pred)): + box = pred[i] + x1 = int(box[0] * width) + y1 = int(box[1] * height) + x2 = int(box[2] * width) + y2 = int(box[3] * height) + cls_conf = box[4] + cls_id = box[5] + + content = '{} {} {} {} {} {}'.format(names[int(cls_id)], cls_conf, x1, y1, x2, y2) + f.write(content) + f.write('\n') + + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0") + parser.add_argument("--origin_jpg_path", default="./val2014/") + parser.add_argument("--det_results_path", + default="./detection-results/") + parser.add_argument("--coco_class_names", default="./coco2014.names") + parser.add_argument("--net_out_num", default=3) + flags = parser.parse_args() + post_process(flags) \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/get_coco_info.py b/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/get_coco_info.py index e0aa1581833a4698e2222a01cfda7cc8719027bc..e452569bf781741d1e2c4790aae4f4fb784b0bdc 100644 --- a/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/get_coco_info.py +++ b/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/get_coco_info.py @@ -1,46 +1,46 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import os -import sys - -file_path = sys.argv[1] -coco_info = sys.argv[2] -info_name = sys.argv[3] - -image_names = [] -image_size = [] - -with open(coco_info, 'r') as file: - contents = file.read().split('\n') - -for content in contents[:-1]: - temp = content.split() - key = temp[1] - image_names.append(key[key.rfind('/') + 1:].split('.')[0]) - image_size.append([temp[2], temp[3]]) - -name_size = dict(zip(image_names, image_size)) - -with open(info_name, 'w') as file: - index = 0 - for key, val in name_size.items(): - bin_name = os.path.join(file_path, '{}.bin'.format(key)) - content = ' '.join([str(index), bin_name, val[0], val[1]]) - file.write(content) - file.write('\n') - index += 1 - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import os +import sys + +file_path = sys.argv[1] +coco_info = sys.argv[2] +info_name = sys.argv[3] + +image_names = [] +image_size = [] + +with open(coco_info, 'r') as file: + contents = file.read().split('\n') + +for content in contents[:-1]: + temp = content.split() + key = temp[1] + image_names.append(key[key.rfind('/') + 1:].split('.')[0]) + image_size.append([temp[2], temp[3]]) + +name_size = dict(zip(image_names, image_size)) + +with open(info_name, 'w') as file: + index = 0 + for key, val in name_size.items(): + bin_name = os.path.join(file_path, '{}.bin'.format(key)) + content = ' '.join([str(index), bin_name, val[0], val[1]]) + file.write(content) + file.write('\n') + index += 1 + + diff --git a/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/parse_json.py b/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/parse_json.py index 2661bc483bf3ffc50a8d0289dba8ea0ccfaa2f0b..4c984a0891f7114ecf64c525a785421615dbe5b0 100644 --- a/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/parse_json.py +++ b/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/parse_json.py @@ -1,77 +1,77 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import json - -with open('./instances_valminusminival2014.json', 'r') as file: - content = file.read() -content = json.loads(content) -info = content.get('info') -licenses = content.get('licenses') -images = content.get('images') -annotations = content.get('annotations') -categroies = content.get('categories') - -with open('./coco2014.names', 'w') as f: - for categroie in categroies: - f.write(categroie.get('name').replace(' ', '_')) - f.write('\n') - -file_names = [image.get('file_name') for image in images] -widths = [image.get('width') for image in images] -heights = [image.get('height') for image in images] -image_ids = [image.get('id') for image in images] -assert len(file_names) == len(widths) == len(heights) == len(image_ids), "must be equal" - -annotation_ids = [annotation.get('image_id') for annotation in annotations] -bboxs = [annotation.get('bbox') for annotation in annotations] -category_ids = [annotation.get('category_id') for annotation in annotations] -segmentations = [annotation.get('segmentation') for annotation in annotations] -iscrowds = [annotation.get('iscrowd') for annotation in annotations] - -assert len(annotation_ids) == len(bboxs) == len(category_ids) ==len(segmentations) # 255094 - -with open('coco_2014.info', 'w') as f: - for index, file_name in enumerate(file_names): - file_name = 'val2014/' + file_name - line = "{} {} {} {}".format(index, file_name, widths[index], heights[index]) - f.write(line) - f.write('\n') - -def get_all_index(lst, item): - return [index for (index, value) in enumerate(lst) if value == item] - -def get_categroie_name(lst, item): - categroie_name = [dt.get('name') for dt in lst if item == dt.get('id')][0] - if len(categroie_name.split()) == 2: - temp = categroie_name.split() - categroie_name = temp[0] + '_' + temp[1] - return categroie_name - -for index, image_id in enumerate(image_ids): - indexs = get_all_index(annotation_ids, image_id) - with open('./ground-truth/{}.txt'.format(file_names[index].split('.')[0]), 'w') as f: - for idx in indexs: - f.write(get_categroie_name(categroies, category_ids[idx])) - - f.write(' ') - # change label - bboxs[idx][2] = bboxs[idx][0] + bboxs[idx][2] - bboxs[idx][3] = bboxs[idx][1] + bboxs[idx][3] - f.write(' '.join(map(str, bboxs[idx]))) - f.write('\n') - - - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json + +with open('./instances_valminusminival2014.json', 'r') as file: + content = file.read() +content = json.loads(content) +info = content.get('info') +licenses = content.get('licenses') +images = content.get('images') +annotations = content.get('annotations') +categroies = content.get('categories') + +with open('./coco2014.names', 'w') as f: + for categroie in categroies: + f.write(categroie.get('name').replace(' ', '_')) + f.write('\n') + +file_names = [image.get('file_name') for image in images] +widths = [image.get('width') for image in images] +heights = [image.get('height') for image in images] +image_ids = [image.get('id') for image in images] +assert len(file_names) == len(widths) == len(heights) == len(image_ids), "must be equal" + +annotation_ids = [annotation.get('image_id') for annotation in annotations] +bboxs = [annotation.get('bbox') for annotation in annotations] +category_ids = [annotation.get('category_id') for annotation in annotations] +segmentations = [annotation.get('segmentation') for annotation in annotations] +iscrowds = [annotation.get('iscrowd') for annotation in annotations] + +assert len(annotation_ids) == len(bboxs) == len(category_ids) ==len(segmentations) # 255094 + +with open('coco_2014.info', 'w') as f: + for index, file_name in enumerate(file_names): + file_name = 'val2014/' + file_name + line = "{} {} {} {}".format(index, file_name, widths[index], heights[index]) + f.write(line) + f.write('\n') + +def get_all_index(lst, item): + return [index for (index, value) in enumerate(lst) if value == item] + +def get_categroie_name(lst, item): + categroie_name = [dt.get('name') for dt in lst if item == dt.get('id')][0] + if len(categroie_name.split()) == 2: + temp = categroie_name.split() + categroie_name = temp[0] + '_' + temp[1] + return categroie_name + +for index, image_id in enumerate(image_ids): + indexs = get_all_index(annotation_ids, image_id) + with open('./ground-truth/{}.txt'.format(file_names[index].split('.')[0]), 'w') as f: + for idx in indexs: + f.write(get_categroie_name(categroies, category_ids[idx])) + + f.write(' ') + # change label + bboxs[idx][2] = bboxs[idx][0] + bboxs[idx][2] + bboxs[idx][3] = bboxs[idx][1] + bboxs[idx][3] + f.write(' '.join(map(str, bboxs[idx]))) + f.write('\n') + + + + diff --git a/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/preprocess_yolov4_pytorch.py b/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/preprocess_yolov4_pytorch.py index 95df9a16b50e27d5ef3221cf5775c24d0dba470a..f5991e956fe068a53d4da4da8eb308231e8d1360 100644 --- a/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/preprocess_yolov4_pytorch.py +++ b/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/preprocess_yolov4_pytorch.py @@ -1,65 +1,65 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import os -import cv2 -import numpy as np - -def yolov4_onnx(src_info, output_path, bin_type, frame_num): - in_files = [] - if not os.path.exists(output_path): - os.makedirs(output_path) - - with open(src_info, 'r') as file: - contents = file.read().split('\n') - for i in contents[:-1]: - in_files.append(i.split()[1]) - - i = 0 - for file in in_files: - i = i + 1 - print(file, "====", i) - img0 = cv2.imread(file) - resized = cv2.resize(img0, (608, 608), interpolation=cv2.INTER_LINEAR) - img_in = cv2.cvtColor(resized, cv2.COLOR_BGR2RGB) - - if frame_num != -1 and i > frame_num: - break - - if bin_type == "float32": - img_in = np.transpose(img_in, (2, 0, 1)).astype(np.float32) - img_in = np.expand_dims(img_in, axis=0) - img_in /= 255.0 - elif bin_type == "int8": - img_in = img_in.astype(np.int8) - else: - print("error type") - break - - # save img_tensor as binary file for om inference input - temp_name = file[file.rfind('/') + 1:] - img_in.tofile(os.path.join(output_path, temp_name.split('.')[0] + ".bin")) - - -if __name__ == "__main__": - if len(sys.argv) < 5: - raise Exception("usage: python3 xxx.py [src_path] [save_path] [bin_type] [frame_num]") - - src_path = os.path.realpath(sys.argv[1]) - save_path = os.path.realpath(sys.argv[2]) - bin_type = sys.argv[3] - frame_num = int(sys.argv[4]) - - yolov4_onnx(src_path, save_path, bin_type, frame_num) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import os +import cv2 +import numpy as np + +def yolov4_onnx(src_info, output_path, bin_type, frame_num): + in_files = [] + if not os.path.exists(output_path): + os.makedirs(output_path) + + with open(src_info, 'r') as file: + contents = file.read().split('\n') + for i in contents[:-1]: + in_files.append(i.split()[1]) + + i = 0 + for file in in_files: + i = i + 1 + print(file, "====", i) + img0 = cv2.imread(file) + resized = cv2.resize(img0, (608, 608), interpolation=cv2.INTER_LINEAR) + img_in = cv2.cvtColor(resized, cv2.COLOR_BGR2RGB) + + if frame_num != -1 and i > frame_num: + break + + if bin_type == "float32": + img_in = np.transpose(img_in, (2, 0, 1)).astype(np.float32) + img_in = np.expand_dims(img_in, axis=0) + img_in /= 255.0 + elif bin_type == "int8": + img_in = img_in.astype(np.int8) + else: + print("error type") + break + + # save img_tensor as binary file for om inference input + temp_name = file[file.rfind('/') + 1:] + img_in.tofile(os.path.join(output_path, temp_name.split('.')[0] + ".bin")) + + +if __name__ == "__main__": + if len(sys.argv) < 5: + raise Exception("usage: python3 xxx.py [src_path] [save_path] [bin_type] [frame_num]") + + src_path = os.path.realpath(sys.argv[1]) + save_path = os.path.realpath(sys.argv[2]) + bin_type = sys.argv[3] + frame_num = int(sys.argv[4]) + + yolov4_onnx(src_path, save_path, bin_type, frame_num) diff --git a/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/requirements.txt b/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/requirements.txt index 8842750f942520b7f6b15ad0529acb6044841a33..14059e3d54498729123839e666b6d9c8377b3399 100644 --- a/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/requirements.txt +++ b/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch/requirements.txt @@ -1,5 +1,5 @@ -numpy == 1.18.5 -opencv-python == 4.2.0.34 -torch == 1.6.0 -torchvision == 0.7.0 +numpy == 1.18.5 +opencv-python == 4.2.0.34 +torch == 1.6.0 +torchvision == 0.7.0 onnx == 1.7.0 \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/Yolov5_for_Pytorch/generate_data.py b/ACL_PyTorch/built-in/cv/Yolov5_for_Pytorch/generate_data.py index 3ccceafb0f8ee7b31d0f591fb58e72dabcbfa9d0..06a030669eedc6b0bd538a484800f12a13247de2 100644 --- a/ACL_PyTorch/built-in/cv/Yolov5_for_Pytorch/generate_data.py +++ b/ACL_PyTorch/built-in/cv/Yolov5_for_Pytorch/generate_data.py @@ -1,65 +1,65 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import os -import cv2 -import numpy as np -import argparse - -def preprocess(img_info_file, save_path, batch_size): - in_files = [] - output_data = [] - if not os.path.exists(save_path): - os.makedirs(save_path) - - with open(img_info_file, 'r') as file: - contents = file.read().split('\n') - for i in contents[:-1]: - in_files.append(i.split()[1]) - - for i, file in enumerate(in_files): - img0 = cv2.imread(file) - resized = cv2.resize(img0, (640, 640), interpolation=cv2.INTER_LINEAR) - input_data = cv2.cvtColor(resized, cv2.COLOR_BGR2RGB) - input_data = np.transpose(input_data, (2, 0, 1)).astype(np.float32) - input_data = np.expand_dims(input_data, axis=0) - input_data /= 255.0 - print("shape:", input_data.shape) - - if i % batch_size == 0: - output_data = input_data - else: - output_data = np.concatenate((output_data, input_data), axis=0) - - if (i + 1) % batch_size == 0: - output_data.tofile("{}/img_bs{}_n{}.bin".format(save_path, batch_size, i)) - - -if __name__ == "__main__": - """ - python3 generate_data.py \ - --img_info_file=img_info_amct.txt \ - --save_path=amct_data \ - --batch_size=1 - """ - parser = argparse.ArgumentParser(description='YoloV5 offline model inference.') - parser.add_argument('--img_info_file', type=str, default="img_info_amct.txt", help='original data') - parser.add_argument('--save_path', type=str, default="./amct_data", help='data for amct') - parser.add_argument('--batch_size', type=int, default=1, help='om batch size') - args = parser.parse_args() - - print(os.path.abspath(args.img_info_file)) - print(os.path.abspath(args.save_path)) - preprocess(args.img_info_file, args.save_path, args.batch_size) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import os +import cv2 +import numpy as np +import argparse + +def preprocess(img_info_file, save_path, batch_size): + in_files = [] + output_data = [] + if not os.path.exists(save_path): + os.makedirs(save_path) + + with open(img_info_file, 'r') as file: + contents = file.read().split('\n') + for i in contents[:-1]: + in_files.append(i.split()[1]) + + for i, file in enumerate(in_files): + img0 = cv2.imread(file) + resized = cv2.resize(img0, (640, 640), interpolation=cv2.INTER_LINEAR) + input_data = cv2.cvtColor(resized, cv2.COLOR_BGR2RGB) + input_data = np.transpose(input_data, (2, 0, 1)).astype(np.float32) + input_data = np.expand_dims(input_data, axis=0) + input_data /= 255.0 + print("shape:", input_data.shape) + + if i % batch_size == 0: + output_data = input_data + else: + output_data = np.concatenate((output_data, input_data), axis=0) + + if (i + 1) % batch_size == 0: + output_data.tofile("{}/img_bs{}_n{}.bin".format(save_path, batch_size, i)) + + +if __name__ == "__main__": + """ + python3 generate_data.py \ + --img_info_file=img_info_amct.txt \ + --save_path=amct_data \ + --batch_size=1 + """ + parser = argparse.ArgumentParser(description='YoloV5 offline model inference.') + parser.add_argument('--img_info_file', type=str, default="img_info_amct.txt", help='original data') + parser.add_argument('--save_path', type=str, default="./amct_data", help='data for amct') + parser.add_argument('--batch_size', type=int, default=1, help='om batch size') + args = parser.parse_args() + + print(os.path.abspath(args.img_info_file)) + print(os.path.abspath(args.save_path)) + preprocess(args.img_info_file, args.save_path, args.batch_size) diff --git a/ACL_PyTorch/built-in/cv/Yolov5_for_Pytorch/img.png b/ACL_PyTorch/built-in/cv/Yolov5_for_Pytorch/img.png deleted file mode 100644 index 752d68e6af32a0e14dd71d2e4ab687bc214d8d05..0000000000000000000000000000000000000000 Binary files a/ACL_PyTorch/built-in/cv/Yolov5_for_Pytorch/img.png and /dev/null differ diff --git a/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/LICENSE b/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/LICENSE index db05a35866f7f1e2bc78bdfe9e7048e779552d8c..09d493bf1fc257505c1336f3f87425568ab9da3c 100644 --- a/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/LICENSE +++ b/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/LICENSE @@ -1,29 +1,29 @@ -BSD 3-Clause License - -Copyright (c) 2017, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +BSD 3-Clause License + +Copyright (c) 2017, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/ReadMe.md b/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/ReadMe.md index 38b94eb75703250254eb5f8efd66c4585a1350b0..280219cc5f70c0d3506b50b3ca64d20ff3eda173 100644 --- a/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/ReadMe.md +++ b/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/ReadMe.md @@ -1,169 +1,169 @@ -# 参考库文 - -- [wav2vec 2.0: A Framework for Self-Supervised Learning of Speech Representations](https://arxiv.org/abs/2006.11477) - -# 参考实现 - -- [facebook/wav2vec2-base-960h](https://huggingface.co/facebook/wav2vec2-base-960h) - -# 依赖 - -| 依赖名称 | 版本 | -| ------------ | :----------- | -| pytorch | 1.6.0 | -| soundfile | 0.10.3.post1 | -| transformers | 4.3.3 | -| tqdm | 4.49.0 | -| numpy | 1.19.5 | -| datasets | 1.6.2 | -| jiwer | 2.2.0 | - -# 准备数据集 - -运行`preprocess.py`脚本,会自动在线下载所需的分词器模型、Librispeech数据集(下载过程可能比较长),并把数据处理为bin文件,同时生成数据集的info文件。 - -``` -python3.7 preprocess.py --pre_data_save_path=./pre_data/clean --which_dataset=clean -``` - -参数说明: - -- --pre_data_save_path:预处理数据保存路径 -- --which_dataset:指定所用的数据集 - - validation:patrickvonplaten/librispeech_asr_dummy数据集,特别小,只有70多条音频数据 - - clean:Librispeech clean数据集 - - other:Librispeech other数据集 - -官方提供了模型在Librispeech clean和Librispeech other数据集上的精度,本示例中仅用Librispeech clean测试精度。 - -# 模型推理 - -1. 模型转换。 - - 使用PyTorch将模型权重文件pth转换为onnx文件,再使用atc工具将onnx文件转为离线推理模型om文件。 - - 1. 导出onnx文件。 - - 运行`export_onnx.py`脚本,会自动在线下载pth模型,并把pth模型转换为onnx模型。 - - ``` - python3.7 export_onnx.py --model_save_dir=./models - ``` - - 运行完之后,会在当前目录的`models`目录下生成`wav2vec2-base-960h.onnx`模型文件。 - - 使用atc工具将onnx文件转换为om文件,导出onnx模型文件时需设置算子版本为11。 - - 2. 使用atc工具将onnx模型转om模型。 - - 1. 根据实际情况,修改`onnx2om.sh`脚本中的环境变量,具体的脚本示例如下: - - ``` - #!/bin/bash - export install_path=/usr/local/Ascend/ascend-toolkit/latest - export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH - export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH - export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH - export ASCEND_OPP_PATH=${install_path}/opp - - atc --framework=5 --model=./models/wav2vec2-base-960h.onnx --output=./models/wav2vec2-base-960h --input_format=ND --input_shape="input:1,-1" --dynamic_dims="10000;20000;30000;40000;50000;60000;70000;80000;90000;100000;110000;120000;130000;140000;150000;160000;170000;180000;190000;200000;210000;220000;230000;240000;250000;260000;270000;280000;290000;300000;310000;320000;330000;340000;350000;360000;370000;380000;390000;400000;410000;420000;430000;440000;450000;460000;470000;480000;490000;500000;510000;520000;530000;540000;550000;560000" --log=error --soc_version=Ascend710 - ``` - - 参数说明: - - - --model:为ONNX模型文件。 - - --framework:5代表ONNX模型。 - - --output:输出的OM模型。 - - --input_format:输入数据的格式。 - - --input_shape:输入数据的shape。 - - --log:日志等级。 - - --soc_version:部署芯片类型。 - - 2. 执行onnx2om.sh脚本,将onnx文件转为离线推理模型文件om文件。 - - ``` - bash onnx2om.sh - ``` - - 运行成功后在`models`目录下生成`wav2vec2-base-960h.om`模型文件。 - -2. 开始推理验证。 - - 1. 配置环境变量 - - ``` - export install_path=/usr/local/Ascend/ascend-toolkit/latest - export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH - export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH - export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH - export ASCEND_OPP_PATH=${install_path}/opp - ``` - - `install_path`请修改为Toolkit的实际安装路径。 - - 2. 运行`pyacl_infer.py`进行推理,同时输出推理性能数据。 - - ``` - python3.7 pyacl_infer.py \ - --model_path=./models/wav2vec2-base-960h.om \ - --device_id=0 \ - --cpu_run=True \ - --sync_infer=True \ - --workspace=0 \ - --input_info_file_path=./pre_data/clean/bin_file.info \ - --input_dtypes=float32 \ - --infer_res_save_path=./om_infer_res_clean \ --res_save_type=bin - ``` - - 参数说明: - - - --model_path:模型路径 - - --device_id:npu id - - --cpu_run:MeasureTime类的cpu_run参数,True or False - - --sync_infer:推理方式: - - True:同步推理 - - False:异步推理 - - --workspace:类似TensorRT‘workspace’参数,计算平均推理时间时排除前n次推理 - - --input_info_file_path:bin_info文件 - - --input_dtypes:模型输入的类型,用逗号分割(参考`DTYPE`变量) - - e.g. 模型只有一个输入:--input_dtypes=float32 - - e.g. 模型有多个输入:--input_dtypes=float32,float32,float32(需要和bin_info文件多输入排列一致) - - --infer_res_save_path:推理结果保存目录 - - --res_save_type:推理结果保存类型,bin或npy - 3. 推理数据后处理与精度统计。 - - 运行`postprocess.py`,会进行推理数据后处理,并进行精度统计。 - - ``` - python3.7 postprocess.py \ - --bin_file_path=./om_infer_res_clean \ - --res_save_path=./om_infer_res_clean/transcriptions.txt \ - --which_dataset=clean - ``` - - 参数说明: - - - --bin_file_path:pyacl推理结果存放路径 - - --res_save_path:后处理结果存放txt文件 - - --which_dataset:精度统计所用的数据集,参看preprocess.py的参数说明 - -4. 性能测试 - - 由于TensorRT无法运行`wav2vec2-base-960h.onnx`模型,所以性能测试以pyacl得到的om推理性能和pytorch在线推理性能作比较。 - - 在GPU环境上运行`pth_online_infer.py`脚本,得到pytorch在线推理性能。 - - ``` - python pth_online_infer.py \ - --pred_res_save_path=./pth_online_infer_res/clean/transcriptions.txt \ - --which_dataset=clean - ``` - - 参数说明: - - - --pred_res_save_path:pytorch在线推理结果存放路径 - - --which_dataset:参看preprocess.py的参数说明 - - 脚本执行完毕后,会在屏幕上输出pytorch在线推理平均推理时间(average infer time(ms)),假定为![Figure Name:202155144621.png CAD Name:zh-cn_formulaimage_0000001124002380.png](http://resource.idp.huawei.com/idpresource/nasshare/editor/image/34040284354/1_zh-cn_formulaimage_0000001124002380.png),换算为单卡后pytorch在线推理的每秒推理数量为:![Figure Name:202153161710.png CAD Name:zh-cn_formulaimage_0000001166163171.png](http://resource.idp.huawei.com/idpresource/nasshare/editor/image/34040284354/3_zh-cn_formulaimage_0000001166163171.png)。 - +# 参考库文 + +- [wav2vec 2.0: A Framework for Self-Supervised Learning of Speech Representations](https://arxiv.org/abs/2006.11477) + +# 参考实现 + +- [facebook/wav2vec2-base-960h](https://huggingface.co/facebook/wav2vec2-base-960h) + +# 依赖 + +| 依赖名称 | 版本 | +| ------------ | :----------- | +| pytorch | 1.6.0 | +| soundfile | 0.10.3.post1 | +| transformers | 4.3.3 | +| tqdm | 4.49.0 | +| numpy | 1.19.5 | +| datasets | 1.6.2 | +| jiwer | 2.2.0 | + +# 准备数据集 + +运行`preprocess.py`脚本,会自动在线下载所需的分词器模型、Librispeech数据集(下载过程可能比较长),并把数据处理为bin文件,同时生成数据集的info文件。 + +``` +python3.7 preprocess.py --pre_data_save_path=./pre_data/clean --which_dataset=clean +``` + +参数说明: + +- --pre_data_save_path:预处理数据保存路径 +- --which_dataset:指定所用的数据集 + - validation:patrickvonplaten/librispeech_asr_dummy数据集,特别小,只有70多条音频数据 + - clean:Librispeech clean数据集 + - other:Librispeech other数据集 + +官方提供了模型在Librispeech clean和Librispeech other数据集上的精度,本示例中仅用Librispeech clean测试精度。 + +# 模型推理 + +1. 模型转换。 + + 使用PyTorch将模型权重文件pth转换为onnx文件,再使用atc工具将onnx文件转为离线推理模型om文件。 + + 1. 导出onnx文件。 + + 运行`export_onnx.py`脚本,会自动在线下载pth模型,并把pth模型转换为onnx模型。 + + ``` + python3.7 export_onnx.py --model_save_dir=./models + ``` + + 运行完之后,会在当前目录的`models`目录下生成`wav2vec2-base-960h.onnx`模型文件。 + + 使用atc工具将onnx文件转换为om文件,导出onnx模型文件时需设置算子版本为11。 + + 2. 使用atc工具将onnx模型转om模型。 + + 1. 根据实际情况,修改`onnx2om.sh`脚本中的环境变量,具体的脚本示例如下: + + ``` + #!/bin/bash + export install_path=/usr/local/Ascend/ascend-toolkit/latest + export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH + export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH + export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH + export ASCEND_OPP_PATH=${install_path}/opp + + atc --framework=5 --model=./models/wav2vec2-base-960h.onnx --output=./models/wav2vec2-base-960h --input_format=ND --input_shape="input:1,-1" --dynamic_dims="10000;20000;30000;40000;50000;60000;70000;80000;90000;100000;110000;120000;130000;140000;150000;160000;170000;180000;190000;200000;210000;220000;230000;240000;250000;260000;270000;280000;290000;300000;310000;320000;330000;340000;350000;360000;370000;380000;390000;400000;410000;420000;430000;440000;450000;460000;470000;480000;490000;500000;510000;520000;530000;540000;550000;560000" --log=error --soc_version=Ascend710 + ``` + + 参数说明: + + - --model:为ONNX模型文件。 + - --framework:5代表ONNX模型。 + - --output:输出的OM模型。 + - --input_format:输入数据的格式。 + - --input_shape:输入数据的shape。 + - --log:日志等级。 + - --soc_version:部署芯片类型。 + + 2. 执行onnx2om.sh脚本,将onnx文件转为离线推理模型文件om文件。 + + ``` + bash onnx2om.sh + ``` + + 运行成功后在`models`目录下生成`wav2vec2-base-960h.om`模型文件。 + +2. 开始推理验证。 + + 1. 配置环境变量 + + ``` + export install_path=/usr/local/Ascend/ascend-toolkit/latest + export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH + export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH + export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH + export ASCEND_OPP_PATH=${install_path}/opp + ``` + + `install_path`请修改为Toolkit的实际安装路径。 + + 2. 运行`pyacl_infer.py`进行推理,同时输出推理性能数据。 + + ``` + python3.7 pyacl_infer.py \ + --model_path=./models/wav2vec2-base-960h.om \ + --device_id=0 \ + --cpu_run=True \ + --sync_infer=True \ + --workspace=0 \ + --input_info_file_path=./pre_data/clean/bin_file.info \ + --input_dtypes=float32 \ + --infer_res_save_path=./om_infer_res_clean \ --res_save_type=bin + ``` + + 参数说明: + + - --model_path:模型路径 + - --device_id:npu id + - --cpu_run:MeasureTime类的cpu_run参数,True or False + - --sync_infer:推理方式: + - True:同步推理 + - False:异步推理 + - --workspace:类似TensorRT‘workspace’参数,计算平均推理时间时排除前n次推理 + - --input_info_file_path:bin_info文件 + - --input_dtypes:模型输入的类型,用逗号分割(参考`DTYPE`变量) + - e.g. 模型只有一个输入:--input_dtypes=float32 + - e.g. 模型有多个输入:--input_dtypes=float32,float32,float32(需要和bin_info文件多输入排列一致) + - --infer_res_save_path:推理结果保存目录 + - --res_save_type:推理结果保存类型,bin或npy + 3. 推理数据后处理与精度统计。 + + 运行`postprocess.py`,会进行推理数据后处理,并进行精度统计。 + + ``` + python3.7 postprocess.py \ + --bin_file_path=./om_infer_res_clean \ + --res_save_path=./om_infer_res_clean/transcriptions.txt \ + --which_dataset=clean + ``` + + 参数说明: + + - --bin_file_path:pyacl推理结果存放路径 + - --res_save_path:后处理结果存放txt文件 + - --which_dataset:精度统计所用的数据集,参看preprocess.py的参数说明 + +4. 性能测试 + + 由于TensorRT无法运行`wav2vec2-base-960h.onnx`模型,所以性能测试以pyacl得到的om推理性能和pytorch在线推理性能作比较。 + + 在GPU环境上运行`pth_online_infer.py`脚本,得到pytorch在线推理性能。 + + ``` + python pth_online_infer.py \ + --pred_res_save_path=./pth_online_infer_res/clean/transcriptions.txt \ + --which_dataset=clean + ``` + + 参数说明: + + - --pred_res_save_path:pytorch在线推理结果存放路径 + - --which_dataset:参看preprocess.py的参数说明 + + 脚本执行完毕后,会在屏幕上输出pytorch在线推理平均推理时间(average infer time(ms)),假定为![Figure Name:202155144621.png CAD Name:zh-cn_formulaimage_0000001124002380.png](http://resource.idp.huawei.com/idpresource/nasshare/editor/image/34040284354/1_zh-cn_formulaimage_0000001124002380.png),换算为单卡后pytorch在线推理的每秒推理数量为:![Figure Name:202153161710.png CAD Name:zh-cn_formulaimage_0000001166163171.png](http://resource.idp.huawei.com/idpresource/nasshare/editor/image/34040284354/3_zh-cn_formulaimage_0000001166163171.png)。 + 上述运行pyacl_infer.py脚本会得到om平均推理时间(average infer time(ms)),假定为![Figure Name:202153161914.png CAD Name:zh-cn_formulaimage_0000001166164017.png](http://resource.idp.huawei.com/idpresource/nasshare/editor/image/34040284354/1_zh-cn_formulaimage_0000001166164017.png),换算为单卡后om的每秒推理数量为:![Figure Name:202153161758.png CAD Name:zh-cn_formulaimage_0000001119363638.png](http://resource.idp.huawei.com/idpresource/nasshare/editor/image/34040284354/2_zh-cn_formulaimage_0000001119363638.png)。 \ No newline at end of file diff --git a/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/modelzoo_level.txt b/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/modelzoo_level.txt index a17c8f95fa388fbc6d253e2cd7cfd0b73b734073..a829ab59b97a1022dd6fc33b59b7ae0d55009432 100644 --- a/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/modelzoo_level.txt +++ b/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/pyacl_infer.py b/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/pyacl_infer.py index 1ef7e4a5c8244e98642c9b61e59cfe9e448ff924..c41c1a20dfd7cf567ddb589ff908ea9be5e67746 100644 --- a/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/pyacl_infer.py +++ b/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch/pyacl_infer.py @@ -1,138 +1,138 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - -import acl -from acl_net import AclModel - -import os -import shutil -import argparse -import numpy as np -from tqdm import tqdm - -DTYPE = { - 'float16': np.float16, - 'float32': np.float32, - 'float64': np.float64, - 'int16': np.int16, - 'int32': np.int32, - 'int64': np.int64, - 'uint8': np.uint8, - 'uint16': np.uint16, - 'uint32': np.uint32, - 'uint64': np.uint64 -} - -if __name__ == '__main__': - # 参数解析 - parser = argparse.ArgumentParser() - parser.add_argument('--model_path', required=True) - parser.add_argument('--device_id', required=True, type=int) - parser.add_argument('--cpu_run', required=True, choices=['True', 'False']) - parser.add_argument('--sync_infer', required=True, choices=['True', 'False']) - parser.add_argument('--workspace', required=True, type=int) - parser.add_argument('--input_info_file_path', required=True) - parser.add_argument('--input_dtypes', required=True) - parser.add_argument('--infer_res_save_path', required=True) - parser.add_argument('--res_save_type', required=True, choices=['bin', 'npy']) - opt = parser.parse_args() - - # 创建模型 - measurements = {} - om_model = AclModel(device_id=opt.device_id, - model_path=opt.model_path, - sync_infer=eval(opt.sync_infer), - measurements=measurements, - key='per_infer_time_ns', - cpu_run=eval(opt.cpu_run)) - - # 创建目录 - if os.path.exists(opt.infer_res_save_path): - shutil.rmtree(opt.infer_res_save_path) - os.makedirs(opt.infer_res_save_path) - - # 读取info_file - inputs_info = {} - with open(opt.input_info_file_path, 'rt', encoding='utf-8') as f_info: - line = f_info.readline() - while line: - line = line.rstrip('\n') - contents = line.split() - info = {'path': contents[1], 'shape': eval(contents[2])} - inputs_info.setdefault(contents[0], []).append(info) - line = f_info.readline() - - # 解析输入类型 - input_dtypes = opt.input_dtypes.split(',') - input_dtypes = list(map(lambda x: DTYPE[x], input_dtypes)) - - # 读取文件推理 - total_infer_time = 0 - total_infer_time_workspace = 0 - total_infer_num = 0 - for key, values in tqdm(inputs_info.items()): - # 构造输入 - inputs = [] - dims = [] - for idx, value in enumerate(values): - x = np.fromfile(value['path'], dtype=input_dtypes[idx]).reshape(value['shape']) - inputs.append(x) - dims.extend(value['shape']) - dims_info = {'dimCount': len(dims), 'name': '', 'dims': dims} - - # 推理得到输出 - output = om_model(inputs, dims_info) - total_infer_num += 1 - - # 保存文件 - if opt.res_save_type == 'bin': - for idx, data in enumerate(output): - data.tofile(os.path.join(opt.infer_res_save_path, key + '.' + str(idx) + '.bin')) - else: - for idx, data in enumerate(output): - np.save(os.path.join(opt.infer_res_save_path, key + '.' + str(idx) + '.npy'), data) - - # 计算时间 - total_infer_time += measurements['per_infer_time_ns'] - if total_infer_num > opt.workspace: - total_infer_time_workspace += measurements['per_infer_time_ns'] - - # 推理时间 - print('[INFO] Infer time:') - msg = 'total infer num: ' + str(total_infer_num) + '\n' + \ - 'total pure infer time(ms): ' + str(total_infer_time / 1000 / 1000) + '\n' + \ - 'average pure infer time(ms): ' + str(total_infer_time / total_infer_num / 1000 / 1000) + '\n' + \ - 'average pure infer time after workspace(ms): ' + str(abs( - total_infer_time_workspace / (total_infer_num - opt.workspace) / 1000 / 1000)) + '\n' - print(msg) - with open(os.path.join(opt.infer_res_save_path, 'infer_time.txt'), 'wt', encoding='utf-8') as f_infer_time: - f_infer_time.write(msg) +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + +import acl +from acl_net import AclModel + +import os +import shutil +import argparse +import numpy as np +from tqdm import tqdm + +DTYPE = { + 'float16': np.float16, + 'float32': np.float32, + 'float64': np.float64, + 'int16': np.int16, + 'int32': np.int32, + 'int64': np.int64, + 'uint8': np.uint8, + 'uint16': np.uint16, + 'uint32': np.uint32, + 'uint64': np.uint64 +} + +if __name__ == '__main__': + # 参数解析 + parser = argparse.ArgumentParser() + parser.add_argument('--model_path', required=True) + parser.add_argument('--device_id', required=True, type=int) + parser.add_argument('--cpu_run', required=True, choices=['True', 'False']) + parser.add_argument('--sync_infer', required=True, choices=['True', 'False']) + parser.add_argument('--workspace', required=True, type=int) + parser.add_argument('--input_info_file_path', required=True) + parser.add_argument('--input_dtypes', required=True) + parser.add_argument('--infer_res_save_path', required=True) + parser.add_argument('--res_save_type', required=True, choices=['bin', 'npy']) + opt = parser.parse_args() + + # 创建模型 + measurements = {} + om_model = AclModel(device_id=opt.device_id, + model_path=opt.model_path, + sync_infer=eval(opt.sync_infer), + measurements=measurements, + key='per_infer_time_ns', + cpu_run=eval(opt.cpu_run)) + + # 创建目录 + if os.path.exists(opt.infer_res_save_path): + shutil.rmtree(opt.infer_res_save_path) + os.makedirs(opt.infer_res_save_path) + + # 读取info_file + inputs_info = {} + with open(opt.input_info_file_path, 'rt', encoding='utf-8') as f_info: + line = f_info.readline() + while line: + line = line.rstrip('\n') + contents = line.split() + info = {'path': contents[1], 'shape': eval(contents[2])} + inputs_info.setdefault(contents[0], []).append(info) + line = f_info.readline() + + # 解析输入类型 + input_dtypes = opt.input_dtypes.split(',') + input_dtypes = list(map(lambda x: DTYPE[x], input_dtypes)) + + # 读取文件推理 + total_infer_time = 0 + total_infer_time_workspace = 0 + total_infer_num = 0 + for key, values in tqdm(inputs_info.items()): + # 构造输入 + inputs = [] + dims = [] + for idx, value in enumerate(values): + x = np.fromfile(value['path'], dtype=input_dtypes[idx]).reshape(value['shape']) + inputs.append(x) + dims.extend(value['shape']) + dims_info = {'dimCount': len(dims), 'name': '', 'dims': dims} + + # 推理得到输出 + output = om_model(inputs, dims_info) + total_infer_num += 1 + + # 保存文件 + if opt.res_save_type == 'bin': + for idx, data in enumerate(output): + data.tofile(os.path.join(opt.infer_res_save_path, key + '.' + str(idx) + '.bin')) + else: + for idx, data in enumerate(output): + np.save(os.path.join(opt.infer_res_save_path, key + '.' + str(idx) + '.npy'), data) + + # 计算时间 + total_infer_time += measurements['per_infer_time_ns'] + if total_infer_num > opt.workspace: + total_infer_time_workspace += measurements['per_infer_time_ns'] + + # 推理时间 + print('[INFO] Infer time:') + msg = 'total infer num: ' + str(total_infer_num) + '\n' + \ + 'total pure infer time(ms): ' + str(total_infer_time / 1000 / 1000) + '\n' + \ + 'average pure infer time(ms): ' + str(total_infer_time / total_infer_num / 1000 / 1000) + '\n' + \ + 'average pure infer time after workspace(ms): ' + str(abs( + total_infer_time_workspace / (total_infer_num - opt.workspace) / 1000 / 1000)) + '\n' + print(msg) + with open(os.path.join(opt.infer_res_save_path, 'infer_time.txt'), 'wt', encoding='utf-8') as f_infer_time: + f_infer_time.write(msg) diff --git a/ACL_PyTorch/built-in/nlp/textcnn/License b/ACL_PyTorch/built-in/nlp/textcnn/License index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/built-in/nlp/textcnn/License +++ b/ACL_PyTorch/built-in/nlp/textcnn/License @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/built-in/nlp/textcnn/README.md b/ACL_PyTorch/built-in/nlp/textcnn/README.md index 0d1a1be488841150f7e7f32d8b5d0f8d9c547e29..19f9da537e45ba6c660681a314620e7b3d2a0d03 100644 --- a/ACL_PyTorch/built-in/nlp/textcnn/README.md +++ b/ACL_PyTorch/built-in/nlp/textcnn/README.md @@ -1,62 +1,62 @@ -# 用于Textcnn模型离线推理指导 -## 1 获取开源代码 - -``` -https://gitee.com/zhang_kaiqi/ascend-textcnn.git -cd ascend-textcnn -git checkout 7cd94c509dc3f615a5d8f4b3816e43ad837a649e -cd - -git clone https://gitee.com/Ronnie_zheng/MagicONNX.git -cd MagicONNX && git checkout 8d62ae9dde478f35bece4b3d04eef573448411c9 -cd - -``` -## 2 文件放置 -把TextCNN*脚本和gen_dataset_info.py脚本放到ascend_textcnn文件夹里;把*.sh脚本和fit_onnx.py放在ascend_textcnn的平行文件夹 - -## 3 模型推理 -1. 前处理 - -``` -cd ascend_textcnn -python3 TextCNN_preprocess.py --save_folder bin -python3 gen_dataset_info.py bin info -``` - -2. 转onnx - -获取[TextCNN_9045_seed460473.pth](https://gitee.com/hex5b25/ascend-textcnn/raw/master/Chinese-Text-Classification-Pytorch/THUCNews/saved_dict/TextCNN_9045_seed460473.pth) - -``` -python3 TextCNN_pth2onnx.py --weight_path ./TextCNN_9045_seed460473.pth --onnx_path ./dy_textcnn.onnx -``` - -3. 转om - -``` -cd .. -bash onnxsim.sh -bash onnx2mgonnx.sh -bash onnx2om.sh -``` - -4. 后处理得到精度 - -精度结果保存在result_bs*.json中。*代表具体的batch_size值(从4开始) - -``` -./benchmark.x86_64 -batch_size=* -om_path=mg_om_dir/textcnn_*bs_mg.om -output_binary=True -input_text_path=ascend-textcnn/info -useDvpp=False -model_type=nlp -python3 ascend-textcnn/TextCNN_postprocess.py result/dumpOutput_device0 >result_bs*.json -``` -5. 性能数据 - -推理结果打屏显示 - -``` -./msame --model mg_om_dir/trextcnn_*bs_mg.om --loop 100 -``` - -## 3 自验 -| 模型 | 官网精度 | 710离线推理精度 | 710性能 | -|--------------|--------|-----------|-------| -| Textcnn 64bs | [91.22%](https://gitee.com/huangyd8/Chinese-Text-Classification-Pytorch) | 90.47% | 27242.83 | - +# 用于Textcnn模型离线推理指导 +## 1 获取开源代码 + +``` +https://gitee.com/zhang_kaiqi/ascend-textcnn.git +cd ascend-textcnn +git checkout 7cd94c509dc3f615a5d8f4b3816e43ad837a649e +cd - +git clone https://gitee.com/Ronnie_zheng/MagicONNX.git +cd MagicONNX && git checkout 8d62ae9dde478f35bece4b3d04eef573448411c9 +cd - +``` +## 2 文件放置 +把TextCNN*脚本和gen_dataset_info.py脚本放到ascend_textcnn文件夹里;把*.sh脚本和fit_onnx.py放在ascend_textcnn的平行文件夹 + +## 3 模型推理 +1. 前处理 + +``` +cd ascend_textcnn +python3 TextCNN_preprocess.py --save_folder bin +python3 gen_dataset_info.py bin info +``` + +2. 转onnx + +获取[TextCNN_9045_seed460473.pth](https://gitee.com/hex5b25/ascend-textcnn/raw/master/Chinese-Text-Classification-Pytorch/THUCNews/saved_dict/TextCNN_9045_seed460473.pth) + +``` +python3 TextCNN_pth2onnx.py --weight_path ./TextCNN_9045_seed460473.pth --onnx_path ./dy_textcnn.onnx +``` + +3. 转om + +``` +cd .. +bash onnxsim.sh +bash onnx2mgonnx.sh +bash onnx2om.sh +``` + +4. 后处理得到精度 + +精度结果保存在result_bs*.json中。*代表具体的batch_size值(从4开始) + +``` +./benchmark.x86_64 -batch_size=* -om_path=mg_om_dir/textcnn_*bs_mg.om -output_binary=True -input_text_path=ascend-textcnn/info -useDvpp=False -model_type=nlp +python3 ascend-textcnn/TextCNN_postprocess.py result/dumpOutput_device0 >result_bs*.json +``` +5. 性能数据 + +推理结果打屏显示 + +``` +./msame --model mg_om_dir/trextcnn_*bs_mg.om --loop 100 +``` + +## 3 自验 +| 模型 | 官网精度 | 710离线推理精度 | 710性能 | +|--------------|--------|-----------|-------| +| Textcnn 64bs | [91.22%](https://gitee.com/huangyd8/Chinese-Text-Classification-Pytorch) | 90.47% | 27242.83 | + diff --git a/ACL_PyTorch/built-in/nlp/textcnn/TextCNN_postprocess.py b/ACL_PyTorch/built-in/nlp/textcnn/TextCNN_postprocess.py index 39e8d8db7b33b57f71b523493ae217993bee7824..2c926fa8f1dd94a108d94c0af4f7709f7f6995a0 100644 --- a/ACL_PyTorch/built-in/nlp/textcnn/TextCNN_postprocess.py +++ b/ACL_PyTorch/built-in/nlp/textcnn/TextCNN_postprocess.py @@ -1,29 +1,29 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import struct -import numpy as np -import sys -result_root = sys.argv[1] -correct, total = 0, 0 - -for result_path in os.listdir(result_root): - label = int(result_path.split('.')[0].split('_')[1]) - - data_raw = np.fromfile(os.path.join(result_root, result_path), dtype=np.float16) - result = int(np.argmax(data_raw)) - total += 1 - correct += 1 if label == result else 0 -print('acc: ', correct/total) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import struct +import numpy as np +import sys +result_root = sys.argv[1] +correct, total = 0, 0 + +for result_path in os.listdir(result_root): + label = int(result_path.split('.')[0].split('_')[1]) + + data_raw = np.fromfile(os.path.join(result_root, result_path), dtype=np.float16) + result = int(np.argmax(data_raw)) + total += 1 + correct += 1 if label == result else 0 +print('acc: ', correct/total) diff --git a/ACL_PyTorch/built-in/nlp/textcnn/TextCNN_preprocess.py b/ACL_PyTorch/built-in/nlp/textcnn/TextCNN_preprocess.py index 525a57acca9c16d46fe49f58e6920df5dad30f95..a3c6c7daa100c0846c564ff97915c0fb1a9f6241 100644 --- a/ACL_PyTorch/built-in/nlp/textcnn/TextCNN_preprocess.py +++ b/ACL_PyTorch/built-in/nlp/textcnn/TextCNN_preprocess.py @@ -1,108 +1,108 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# coding: UTF-8 - -import os -import argparse -import pickle as pkl -import numpy as np - - -parser = argparse.ArgumentParser(description='Chinese Text Classification') -parser.add_argument('--embedding', default='pre_trained', type=str, help='random or pre_trained') -parser.add_argument('--word', default=False, type=bool, help='True for word, False for char') -parser.add_argument('--vocab_path', type=str, default='data/vocab.pkl') -parser.add_argument('--dataset', type=str, default='./Chinese-Text-Classification-Pytorch/THUCNews') -parser.add_argument('--pad_size', type=int, default=32) -parser.add_argument('--train_path', type=str, default='data/train.txt') -parser.add_argument('--test_path', type=str, default='data/test.txt') -parser.add_argument('--save_folder', type=str, default='') -args = parser.parse_args() - -args.test_path = os.path.join(args.dataset, args.test_path) -args.train_path = os.path.join(args.dataset, args.train_path) -args.vocab_path = os.path.join(args.dataset, args.vocab_path) -if args.save_folder == '': - args.save_folder = args.dataset + '_bin' -if not os.path.exists(args.save_folder): - os.mkdir(args.save_folder) - -MAX_VOCAB_SIZE = 10000 # 词表长度限制 -UNK, PAD = '', '' # 未知字,padding符号 - - -def build_vocab(file_path, tokenizer_, max_size, min_freq): - vocab_dic = {} - with open(file_path, 'r', encoding='UTF-8') as f_: - for line_ in f_: - lin = line_.strip() - if not lin: - continue - content_ = lin.split('\t')[0] - for word_ in tokenizer_(content_): - vocab_dic[word_] = vocab_dic.get(word_, 0) + 1 - vocab_list = sorted([_ for _ in vocab_dic.items() if _[1] >= min_freq], key=lambda x: x[1], reverse=True) - vocab_list = vocab_list[:max_size] - vocab_dic = {word_count[0]: idx for idx, word_count in enumerate(vocab_list)} - vocab_dic.update({UNK: len(vocab_dic), PAD: len(vocab_dic) + 1}) - return vocab_dic - - -if __name__ == '__main__': - - """ - Usage: - python preprocess_to_bin.py - """ - - if args.word: - tokenizer = lambda x: x.split(' ') # 以空格隔开,word-level - else: - tokenizer = lambda x: [y for y in x] # char-level - if os.path.exists(args.vocab_path): - vocab = pkl.load(open(args.vocab_path, 'rb')) - else: - assert args.train_path != '' - vocab = build_vocab(args.train_path, tokenizer_=tokenizer, max_size=MAX_VOCAB_SIZE, min_freq=1) - pkl.dump(vocab, open(args.vocab_path, 'wb+')) - print(f"Vocab size: {len(vocab)}") - print('bin file save path: ', os.path.abspath(args.save_folder)) - - contents = [] - f = open(args.test_path, 'r', encoding='UTF-8') - idx = 0 - for line in f: - lin = line.strip() - if not lin: - continue - content, label = lin.split('\t') - words_line = [] - token = tokenizer(content) - if args.pad_size: - if len(token) < args.pad_size: - token.extend([PAD] * (args.pad_size - len(token))) - else: - token = token[:args.pad_size] - # word to id - for word in token: - words_line.append(vocab.get(word, vocab.get(UNK))) - - # convert to bin - words_line_np = np.asarray(words_line, dtype=np.int64) - bin_file_path = os.path.join(args.save_folder, '{}_{}.bin'.format(idx, label)) - words_line_np.tofile(bin_file_path) - idx += 1 - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# coding: UTF-8 + +import os +import argparse +import pickle as pkl +import numpy as np + + +parser = argparse.ArgumentParser(description='Chinese Text Classification') +parser.add_argument('--embedding', default='pre_trained', type=str, help='random or pre_trained') +parser.add_argument('--word', default=False, type=bool, help='True for word, False for char') +parser.add_argument('--vocab_path', type=str, default='data/vocab.pkl') +parser.add_argument('--dataset', type=str, default='./Chinese-Text-Classification-Pytorch/THUCNews') +parser.add_argument('--pad_size', type=int, default=32) +parser.add_argument('--train_path', type=str, default='data/train.txt') +parser.add_argument('--test_path', type=str, default='data/test.txt') +parser.add_argument('--save_folder', type=str, default='') +args = parser.parse_args() + +args.test_path = os.path.join(args.dataset, args.test_path) +args.train_path = os.path.join(args.dataset, args.train_path) +args.vocab_path = os.path.join(args.dataset, args.vocab_path) +if args.save_folder == '': + args.save_folder = args.dataset + '_bin' +if not os.path.exists(args.save_folder): + os.mkdir(args.save_folder) + +MAX_VOCAB_SIZE = 10000 # 词表长度限制 +UNK, PAD = '', '' # 未知字,padding符号 + + +def build_vocab(file_path, tokenizer_, max_size, min_freq): + vocab_dic = {} + with open(file_path, 'r', encoding='UTF-8') as f_: + for line_ in f_: + lin = line_.strip() + if not lin: + continue + content_ = lin.split('\t')[0] + for word_ in tokenizer_(content_): + vocab_dic[word_] = vocab_dic.get(word_, 0) + 1 + vocab_list = sorted([_ for _ in vocab_dic.items() if _[1] >= min_freq], key=lambda x: x[1], reverse=True) + vocab_list = vocab_list[:max_size] + vocab_dic = {word_count[0]: idx for idx, word_count in enumerate(vocab_list)} + vocab_dic.update({UNK: len(vocab_dic), PAD: len(vocab_dic) + 1}) + return vocab_dic + + +if __name__ == '__main__': + + """ + Usage: + python preprocess_to_bin.py + """ + + if args.word: + tokenizer = lambda x: x.split(' ') # 以空格隔开,word-level + else: + tokenizer = lambda x: [y for y in x] # char-level + if os.path.exists(args.vocab_path): + vocab = pkl.load(open(args.vocab_path, 'rb')) + else: + assert args.train_path != '' + vocab = build_vocab(args.train_path, tokenizer_=tokenizer, max_size=MAX_VOCAB_SIZE, min_freq=1) + pkl.dump(vocab, open(args.vocab_path, 'wb+')) + print(f"Vocab size: {len(vocab)}") + print('bin file save path: ', os.path.abspath(args.save_folder)) + + contents = [] + f = open(args.test_path, 'r', encoding='UTF-8') + idx = 0 + for line in f: + lin = line.strip() + if not lin: + continue + content, label = lin.split('\t') + words_line = [] + token = tokenizer(content) + if args.pad_size: + if len(token) < args.pad_size: + token.extend([PAD] * (args.pad_size - len(token))) + else: + token = token[:args.pad_size] + # word to id + for word in token: + words_line.append(vocab.get(word, vocab.get(UNK))) + + # convert to bin + words_line_np = np.asarray(words_line, dtype=np.int64) + bin_file_path = os.path.join(args.save_folder, '{}_{}.bin'.format(idx, label)) + words_line_np.tofile(bin_file_path) + idx += 1 + f.close() \ No newline at end of file diff --git a/ACL_PyTorch/built-in/nlp/textcnn/TextCNN_pth2onnx.py b/ACL_PyTorch/built-in/nlp/textcnn/TextCNN_pth2onnx.py index 314d0090cf19dc9c1cdfbf0ae4bb11e0331cb27b..f121879a6284f477e9d2f70be7779a895d6e460b 100644 --- a/ACL_PyTorch/built-in/nlp/textcnn/TextCNN_pth2onnx.py +++ b/ACL_PyTorch/built-in/nlp/textcnn/TextCNN_pth2onnx.py @@ -1,57 +1,57 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import argparse -import pickle as pkl -import torch - -sys.path.append(r'./Chinese-Text-Classification-Pytorch') -from models import TextCNN - -parser = argparse.ArgumentParser(description='TextCNN_pth2onnx.py') -parser.add_argument('--weight_path', required=True, help='Path to model weight file, abs path recommended.') -parser.add_argument('--dataset', default='./Chinese-Text-Classification-Pytorch/THUCNews', - help="""Dataset path, train: $dataset/data/train.txt, dev: $dataset/data/dev.txt, \n - test: $dataset/data/text.txt, classes list: $dataset/data/class.txt, \n - vocab: $dataset/data/vocab.pkl, embedding file should be in $dataset/data/""") -parser.add_argument('--embedding', default='embedding_SougouNews.npz', - help="embedding file of $dataset/data/") -parser.add_argument('--onnx_path', required=True, help='Path to save onnx weights.') -args = parser.parse_args() - - -def main(): - config = TextCNN.Config(args.dataset, args.embedding) - vocab = pkl.load(open(config.vocab_path, 'rb')) - config.n_vocab = len(vocab) - - model = TextCNN.Model(config) - model.load_state_dict(torch.load(args.weight_path, map_location=torch.device('cpu'))) - model.eval() - input_names = ['sentence'] - output_names = ['class'] - dynamic_axes = {'sentence': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randint(100, (1, 32)) - torch.onnx.export(model, dummy_input, args.onnx_path, input_names=input_names, verbose=True, - output_names=output_names, dynamic_axes=dynamic_axes, opset_version=11) - -if __name__ == '__main__': - """ - Usage Example: - python TextCNN_pth2onnx.py \ - --weight_path ./TextCNN_9045_seed460473.pth \ - --onnx_path ./dy_textcnn.onnx - """ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import argparse +import pickle as pkl +import torch + +sys.path.append(r'./Chinese-Text-Classification-Pytorch') +from models import TextCNN + +parser = argparse.ArgumentParser(description='TextCNN_pth2onnx.py') +parser.add_argument('--weight_path', required=True, help='Path to model weight file, abs path recommended.') +parser.add_argument('--dataset', default='./Chinese-Text-Classification-Pytorch/THUCNews', + help="""Dataset path, train: $dataset/data/train.txt, dev: $dataset/data/dev.txt, \n + test: $dataset/data/text.txt, classes list: $dataset/data/class.txt, \n + vocab: $dataset/data/vocab.pkl, embedding file should be in $dataset/data/""") +parser.add_argument('--embedding', default='embedding_SougouNews.npz', + help="embedding file of $dataset/data/") +parser.add_argument('--onnx_path', required=True, help='Path to save onnx weights.') +args = parser.parse_args() + + +def main(): + config = TextCNN.Config(args.dataset, args.embedding) + vocab = pkl.load(open(config.vocab_path, 'rb')) + config.n_vocab = len(vocab) + + model = TextCNN.Model(config) + model.load_state_dict(torch.load(args.weight_path, map_location=torch.device('cpu'))) + model.eval() + input_names = ['sentence'] + output_names = ['class'] + dynamic_axes = {'sentence': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randint(100, (1, 32)) + torch.onnx.export(model, dummy_input, args.onnx_path, input_names=input_names, verbose=True, + output_names=output_names, dynamic_axes=dynamic_axes, opset_version=11) + +if __name__ == '__main__': + """ + Usage Example: + python TextCNN_pth2onnx.py \ + --weight_path ./TextCNN_9045_seed460473.pth \ + --onnx_path ./dy_textcnn.onnx + """ main() \ No newline at end of file diff --git a/ACL_PyTorch/built-in/nlp/textcnn/env.sh b/ACL_PyTorch/built-in/nlp/textcnn/env.sh index 0ee18a645237140bba9cb37d8083c2bc6256eeaf..a39fd265bf8056f1c34eac9340580563ae99b199 100644 --- a/ACL_PyTorch/built-in/nlp/textcnn/env.sh +++ b/ACL_PyTorch/built-in/nlp/textcnn/env.sh @@ -1,8 +1,8 @@ -#! /bin/bash - -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -export ASCEND_AICPU_PATH=${install_path} +#! /bin/bash + +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +export ASCEND_AICPU_PATH=${install_path} diff --git a/ACL_PyTorch/built-in/nlp/textcnn/fix_onnx.py b/ACL_PyTorch/built-in/nlp/textcnn/fix_onnx.py index 330b61a21c91a59514fd37dce7bcd3c1b3ef6384..a9ac8a63b54c3a40b3d7936dff9f69ae836d37d5 100644 --- a/ACL_PyTorch/built-in/nlp/textcnn/fix_onnx.py +++ b/ACL_PyTorch/built-in/nlp/textcnn/fix_onnx.py @@ -1,65 +1,65 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -from copy import deepcopy -import onnx -from onnx import (helper, TensorProto) -from onnx.onnx_ml_pb2 import ModelProto -from magiconnx import OnnxGraph -import numpy as np - - -batch_size = sys.argv[1] - -graph = OnnxGraph(f'onnx_sim_dir/textcnn_{batch_size}bs_sim.onnx') - - - - -graph.del_node('Squeeze_5',{0:0},auto_connection=True) -graph.del_node('Squeeze_11',{0:0},auto_connection=True) -graph.del_node('Squeeze_17',{0:0},auto_connection=True) - -Maxpool_1 = graph.add_node('maxpool_1', - 'MaxPool', - {'ceil_mode': 0, 'kernel_shape': [31,1], 'pads': 0, 'strides':[31,1]}) -graph['MaxPool_6'] = Maxpool_1 - - -Maxpool_2 = graph.add_node('maxpool_2', - 'MaxPool', - {'ceil_mode': 0, 'kernel_shape': [30,1], 'pads': 0, 'strides':[30,1]}) -graph['MaxPool_12'] = Maxpool_2 - - -Maxpool_3 = graph.add_node('maxpool_3', - 'MaxPool', - {'ceil_mode': 0, 'kernel_shape': [29,1], 'pads': 0, 'strides':[29,1]}) -graph['MaxPool_18'] = Maxpool_3 - -graph.del_node('Squeeze_7',{0:0},auto_connection=True) -graph.del_node('Squeeze_13',{0:1},auto_connection=True) -graph.del_node('Squeeze_19',{0:2},auto_connection=True) - - - - -squeeze = graph.add_node('squeeze_1', - 'Squeeze', - {'axis': [2,3]}) -graph.insert_node('Gemm_21', squeeze, mode='before') - - -graph.save(f'mg_onnx_dir/textcnn_{batch_size}bs_mg.onnx') +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +from copy import deepcopy +import onnx +from onnx import (helper, TensorProto) +from onnx.onnx_ml_pb2 import ModelProto +from magiconnx import OnnxGraph +import numpy as np + + +batch_size = sys.argv[1] + +graph = OnnxGraph(f'onnx_sim_dir/textcnn_{batch_size}bs_sim.onnx') + + + + +graph.del_node('Squeeze_5',{0:0},auto_connection=True) +graph.del_node('Squeeze_11',{0:0},auto_connection=True) +graph.del_node('Squeeze_17',{0:0},auto_connection=True) + +Maxpool_1 = graph.add_node('maxpool_1', + 'MaxPool', + {'ceil_mode': 0, 'kernel_shape': [31,1], 'pads': 0, 'strides':[31,1]}) +graph['MaxPool_6'] = Maxpool_1 + + +Maxpool_2 = graph.add_node('maxpool_2', + 'MaxPool', + {'ceil_mode': 0, 'kernel_shape': [30,1], 'pads': 0, 'strides':[30,1]}) +graph['MaxPool_12'] = Maxpool_2 + + +Maxpool_3 = graph.add_node('maxpool_3', + 'MaxPool', + {'ceil_mode': 0, 'kernel_shape': [29,1], 'pads': 0, 'strides':[29,1]}) +graph['MaxPool_18'] = Maxpool_3 + +graph.del_node('Squeeze_7',{0:0},auto_connection=True) +graph.del_node('Squeeze_13',{0:1},auto_connection=True) +graph.del_node('Squeeze_19',{0:2},auto_connection=True) + + + + +squeeze = graph.add_node('squeeze_1', + 'Squeeze', + {'axis': [2,3]}) +graph.insert_node('Gemm_21', squeeze, mode='before') + + +graph.save(f'mg_onnx_dir/textcnn_{batch_size}bs_mg.onnx') diff --git a/ACL_PyTorch/built-in/nlp/textcnn/gen_dataset_info.py b/ACL_PyTorch/built-in/nlp/textcnn/gen_dataset_info.py index 296ac9bd0a7b79d1dcae0d391562cc0504cdcf31..459cea2154e13175ebd70a1d0ff6e55344a76626 100644 --- a/ACL_PyTorch/built-in/nlp/textcnn/gen_dataset_info.py +++ b/ACL_PyTorch/built-in/nlp/textcnn/gen_dataset_info.py @@ -1,26 +1,26 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from glob import glob -import os -import sys - -dataset_path = sys.argv[1] -info_path = sys.argv[2] - -bin_texts = glob(os.path.join(dataset_path, '*.bin')) -with open(info_path, 'w+') as f: - for index, texts in enumerate(bin_texts): - content = str(index) + ' ' + str(texts) + '\n' - f.write(content) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from glob import glob +import os +import sys + +dataset_path = sys.argv[1] +info_path = sys.argv[2] + +bin_texts = glob(os.path.join(dataset_path, '*.bin')) +with open(info_path, 'w+') as f: + for index, texts in enumerate(bin_texts): + content = str(index) + ' ' + str(texts) + '\n' + f.write(content) diff --git a/ACL_PyTorch/built-in/nlp/textcnn/modelzoo_level.txt b/ACL_PyTorch/built-in/nlp/textcnn/modelzoo_level.txt index eb7302d66b9f6f96acc9eef6f133455b35669a8d..f866572922453df1c80a3fb3a2a870ace374c835 100644 --- a/ACL_PyTorch/built-in/nlp/textcnn/modelzoo_level.txt +++ b/ACL_PyTorch/built-in/nlp/textcnn/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:NOK \ No newline at end of file diff --git a/ACL_PyTorch/built-in/nlp/textcnn/onnx2mgonnx.sh b/ACL_PyTorch/built-in/nlp/textcnn/onnx2mgonnx.sh index 006370d607eb7c87ffc0a4fa6a6c00e97ffcf5d3..a0d93e0783859b47655d7a43a60402e4d058e7dc 100644 --- a/ACL_PyTorch/built-in/nlp/textcnn/onnx2mgonnx.sh +++ b/ACL_PyTorch/built-in/nlp/textcnn/onnx2mgonnx.sh @@ -1,11 +1,11 @@ -#!/bin/bash - -if [ ! -d "./mg_onnx_dir" ] -then - mkdir ./mg_onnx_dir -fi - -for i in 4 8 16 32 64 -do - python3 ./fix_onnx.py ${i} -done +#!/bin/bash + +if [ ! -d "./mg_onnx_dir" ] +then + mkdir ./mg_onnx_dir +fi + +for i in 4 8 16 32 64 +do + python3 ./fix_onnx.py ${i} +done diff --git a/ACL_PyTorch/built-in/nlp/textcnn/onnx2om.sh b/ACL_PyTorch/built-in/nlp/textcnn/onnx2om.sh index bc9eefcb40734b206e80d67e57da967558fdadc8..7786db7940733bffdf290d122d81aeb4a50df325 100644 --- a/ACL_PyTorch/built-in/nlp/textcnn/onnx2om.sh +++ b/ACL_PyTorch/built-in/nlp/textcnn/onnx2om.sh @@ -1,11 +1,11 @@ -#!/bin/bash - -if [ ! -d "./mg_om_dir" ] -then - mkdir ./mg_om_dir -fi - -for i in 4 8 16 32 64 -do - atc --model=mg_onnx_dir/textcnn_${i}bs_mg.onnx --framework=5 --output=mg_om_dir/textcnn_${i}bs_mg --output_type=FP16 --soc_version=Ascend710 --enable_small_channel=1 -done +#!/bin/bash + +if [ ! -d "./mg_om_dir" ] +then + mkdir ./mg_om_dir +fi + +for i in 4 8 16 32 64 +do + atc --model=mg_onnx_dir/textcnn_${i}bs_mg.onnx --framework=5 --output=mg_om_dir/textcnn_${i}bs_mg --output_type=FP16 --soc_version=Ascend710 --enable_small_channel=1 +done diff --git a/ACL_PyTorch/built-in/nlp/textcnn/onnxsim.sh b/ACL_PyTorch/built-in/nlp/textcnn/onnxsim.sh index ac659a92af86e63545c36ba45edb497100151c6b..11287a55b33749a960f4ffda3016c9a36829ef9f 100644 --- a/ACL_PyTorch/built-in/nlp/textcnn/onnxsim.sh +++ b/ACL_PyTorch/built-in/nlp/textcnn/onnxsim.sh @@ -1,11 +1,11 @@ -#!/bin/bash - -if [ ! -d "./onnx_sim_dir" ] -then - mkdir ./onnx_sim_dir -fi - -for i in 1 4 8 16 32 64 -do - python3 -m onnxsim --input-shape="sentence:${i},32" ./ascend_textcnn/dy_textcnn.onnx ./onnx_sim_dir/textcnn_${i}bs_sim.onnx -done +#!/bin/bash + +if [ ! -d "./onnx_sim_dir" ] +then + mkdir ./onnx_sim_dir +fi + +for i in 1 4 8 16 32 64 +do + python3 -m onnxsim --input-shape="sentence:${i},32" ./ascend_textcnn/dy_textcnn.onnx ./onnx_sim_dir/textcnn_${i}bs_sim.onnx +done diff --git a/ACL_PyTorch/built-in/nlp/textcnn/requirements.txt b/ACL_PyTorch/built-in/nlp/textcnn/requirements.txt index fc5acc7efa792f8ddea52f2d606b3be4c5285b29..51fc9b2831e0f2a5e1fd178fbdd58481a07492a7 100644 --- a/ACL_PyTorch/built-in/nlp/textcnn/requirements.txt +++ b/ACL_PyTorch/built-in/nlp/textcnn/requirements.txt @@ -1,5 +1,5 @@ -numpy==1.19.2 -onnx==1.10.1 -Pillow==8.3.1 -torch==1.5.0 -torchvision==0.6.0 +numpy==1.19.2 +onnx==1.10.1 +Pillow==8.3.1 +torch==1.5.0 +torchvision==0.6.0 diff --git a/ACL_PyTorch/contrib/CONTRIBUTING.md b/ACL_PyTorch/contrib/CONTRIBUTING.md index 886fae1007aa07d5711d863a1941c4cd7356bdb9..dc9d11e8ea435028f1e4dd85543104c7547b7469 100644 --- a/ACL_PyTorch/contrib/CONTRIBUTING.md +++ b/ACL_PyTorch/contrib/CONTRIBUTING.md @@ -1,314 +1,314 @@ - **介绍** - -Ascend ModelZoo,欢迎各位开发者 - - **贡献要求** - -开发者提交的模型包括源码、readme、参考模型license文件、测试用例和readme,并遵循以下标准 - -请贡献者在提交代码之前签署CLA协议,“个人签署”,[链接](https://clasign.osinfra.cn/sign/Z2l0ZWUlMkZhc2NlbmQ=) - -如您完成签署,可在自己提交的PR评论区输入/check-cla进行核实校验 - - **一、源码** - -1、训练及在线推理请使用python代码实现,Ascend平台离线推理请使用C++或python代码,符合第四部分编码规范 - -2、参考[sample](https://gitee.com/ascend/modelzoo/tree/master/built-in/TensorFlow/Official/nlp/Transformer_for_TensorFlow) - -3、贡献者模型代码目录规则:"modelzoo/contrib/框架/Research/应用领域(nlp、cv、audio等)/网络名_IDxxx_for_TensorFlow"(以tf为例,社区管理团队会在贡献完成进行整合) - -4、从其他开源迁移的代码,请增加License声明 - - **二、License规则** - -* TensorFlow - - 迁移场景 - - 1、迁移TensorFlow模型中若源项目已包含License文件则必须拷贝引用,否则在模型顶层目录下添加TensorFlow Apache 2.0 License [TensorFlow License链接](https://github.com/tensorflow/tensorflow/blob/master/LICENSE) - - 2、迁移TensorFlow框架开发的模型,需要在模型目录下每个源文件附上源社区TensorFlow Apache 2.0 License头部声明,并在其下追加新增完整华为公司License声明 - - ``` - # Copyright 2017 The TensorFlow Authors. All Rights Reserved. - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - # ============================================================================ - # Copyright 2021 Huawei Technologies Co., Ltd - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ``` - 开发场景 - - 1、基于TensorFlow框架开发模型,需在模型项目顶层目录下添加TensorFlow Apache 2.0 License [TensorFlow License链接](https://github.com/tensorflow/tensorflow/blob/master/LICENSE) - - 2、基于TensorFlow框架开发模型,需要在模型目录下每个源文件附上源社区华为公司Apache 2.0 License头部声明 - ``` - # Copyright 2021 Huawei Technologies Co., Ltd - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ``` -* PyTorch - - 迁移场景 - - 1、迁移PyTorch模型中若源项目录已包含PyTorch License文件则必须拷贝引用,否则在模型顶层目录下添加PyTorch BSD-3 License [PyTorch License链接](https://github.com/pytorch/examples/blob/master/LICENSE) - - 2、迁移PyTorch第三方框架开发的模型,需要在模型目录下每个源文件附上源社区PyTorch BSD-3 License头部声明,并在其下追加新增一行华为公司License声明 - ``` - # BSD 3-Clause License - # - # Copyright (c) 2017 xxxx - # All rights reserved. - # Copyright 2021 Huawei Technologies Co., Ltd - # - # Redistribution and use in source and binary forms, with or without - # modification, are permitted provided that the following conditions are met: - # - # * Redistributions of source code must retain the above copyright notice, this - # list of conditions and the following disclaimer. - # - # * Redistributions in binary form must reproduce the above copyright notice, - # this list of conditions and the following disclaimer in the documentation - # and/or other materials provided with the distribution. - # - # * Neither the name of the copyright holder nor the names of its - # contributors may be used to endorse or promote products derived from - # this software without specific prior written permission. - # - # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - # ============================================================================ - ``` - - 开发场景 - - 1、基于PyTorch框架开发模型,需在模型项目下添加PyTorch BSD-3 License [PyTorch License链接](https://github.com/pytorch/examples/blob/master/LICENSE) - - 2、基于PyTorch框架开发模型,需要在模型目录下每个源文件附上源社区华为公司Apache 2.0 License头部声明 - ``` - # Copyright 2021 Huawei Technologies Co., Ltd - # - # Licensed under the BSD 3-Clause License (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # https://opensource.org/licenses/BSD-3-Clause - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ``` - -* MindSpore/ACL - - 1、迁移或开发场景下MindSpore/ACL模型顶层目录下需要包含华为公司 License [华为公司 License链接](https://gitee.com/mindspore/mindspore/blob/master/LICENSE) - - 2、迁移或开发场景下MindSpore/ACL模型,需要在模型目录下每个源文件中添加区华为公司Apache 2.0 License头部声明 - ``` - # Copyright 2021 Huawei Technologies Co., Ltd - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ``` - -> 关于License声明时间,应注意: 2021年新建的文件,应该是Copyright 2021 Huawei Technologies Co., Ltd 2020年创建年份,2020年修改年份,应该是Copyright 2020 Huawei Technologies Co., Ltd - - **三、readme** - -readme用于指导用户理解和部署样例,要包含如下内容: - -- 简介: - -1、模型的来源及原理; - -2、模型复现的步骤,含训练、eval、在线/离线推理等,入口请封装成`.sh`、`.py`; - -- 关键要求: - -1、模型的出处、对数据的要求、免责声明等,开源代码文件修改需要增加版权说明; - -2、模型转换得到的离线模型对输入数据的要求; - -3、环境变量设置,依赖的第三方软件包和库,以及安装方法; - -4、精度和性能达成要求:尽量达到原始模型水平; - -5、预训练checkpoint、结果checkpoint请提供归档OBS、网盘链接,如来自开源需明确来源地址 - -6、数据集说明 - -- [ ] 不允许直接提供数据集的下载链接,可使用词汇:用户自行准备好数据集,可选用“XXX”,“XXX”,“XXX” - - 例如:请用户自行准备好数据集,包含训练集和验证集两部分,可选用的数据集包括ImageNet2012,CIFAR10、Flower等,包含train和val两部分。 - -- [ ] 脚本中不允许提供链接下载数据集,如果开源脚本上存在对应的链接,请修改或者删除对应的脚本 - -训练ReadMe写作可参考下面两个链接: - -[Readme example1](https://gitee.com/ascend/modelzoo/blob/master/built-in/TensorFlow/Official/cv/image_classification/DenseNet121_ID0067_for_TensorFlow/README.md) - -[Readme example2](https://www.hiascend.com/zh/software/modelzoo/detail/C/093ed0219cb14f068af33784c62cf7ec) - -离线推理ReadMe写作可参考下面链接: - -[Readme example1](https://gitee.com/ascend/modelzoo/tree/master/contrib/ACL_TensorFlow/Research/cv/AdvancedEAST_ID0130_for_ACL/README.md) - - **四、自测试用例** - -提供模型的自测试用例和readme,提交PR需要门禁及模型测试用例通过,性能和精度检查通过 - -- 简介: - -1、不同于完整的训练过程和全量数据集的推理,自测试用例的目的是验证提交代码基本功能可用,执行时长控制在10min之内(推理或训练只需执行有限的图片或step); - -2、提交PR中训练用例入口`train_testcase.sh`, 在线推理用例入口`online_inference_testcase.sh`, 离线推理用例入口`offline_inference_testcase.sh`; - -3、提交PR后,会自动触发门禁流水,后台会根据用例入口shell,自动将代码分发到对应执行环境; - -4、Jenkins预置账号:登录账号请联系华为工程师/接口人获取,登录之后,可以查看到用例执行日志 - -5、如果提交失败,请查看日志,修复代码或其他问题后,在你当前的PR中,评论“compile”即可重新触发用例执行 - -- 关键要求: - -1、自测试用例命名严格按照上述简介2要求来书写,否则门禁会校验失败; - -2、用例应当包含功能、精度(Loss值)、性能检查,检查通过打印"Run testcase success!",失败则打印"Run testcase failed!"; - -3、执行环境已预装软件包和Python3.7.5环境,调用命令"python3"、"python3.7"、"python3.7.5"均可,安装第三方库依赖使用"pip3"、"pip3.7"均可; - -4、数据集和模型:小于500M的文件,建议使用`obsutil`命令下载(已预装),过大的文件,建议提交Issue,注明数据集和下载地址,会提前下载到执行环境上, - -已预置数据集&python第三方库: [Environments](https://gitee.com/ascend/modelzoo/blob/master/contrib/ENVIRONMENTS.md) - -5、环境和其他问题,请提交Issue跟踪; - -6、测试用例开发参考: -- [训练](https://gitee.com/ascend/modelzoo/tree/master/built-in/TensorFlow/Official/nlp/Transformer_for_TensorFlow) -- [离线推理](https://gitee.com/alexcheng88/modelzoo/tree/master/contrib/TensorFlow/Research/cv/efficientnet-b8/ATC_efficientnet-b8_tf_nkxiaolei) - - **五、PR提交** - -- 关键要求: - -1、请将modelzoo仓fork到个人分支,基于个人分支新增、修改和提交PR; - -2、PR标题:线上活动,请在标题注明[线上贡献];高校活动,请注明[xxx学校][高校贡献]; - -3、built-in用户根据网络状态必须配置modelzoo_level.txt文件,且文件内容包含三个关键字段:FuncStatus(OK-流程通过/ **NOK-流程失败,不允许模型代码提交主仓** );PerfStatus(OK-持平GPU/POK-0.5倍GPU/NOK-小于0.5倍GPU/PERFECT-1.2倍GPU);PrecisionStatus(OK-精度达标,POK-Loss拟合但精度未实施, **NOK-Loss不拟合,不允许模型代码提交主仓** );内容格式如下所示(注:“:”两侧无需空格,英文格式;): - -``` - FuncStatus:OK/NOK - PerfStatus:PERFECT/OK/POK/NOK - PrecisionStatus:OK/POK/NOK -``` -4、contrib用户根据网络状态必须配置modelzoo_level.txt文件,且文件内容包含关键字段:GPUStatus(OK-GPU复现/NOK-GPU未复现); NPUMigrationStatus(OK-自动迁移成功/POK-自动迁移失败, 手写规避成功/NOK-均失败); FuncStatus(OK-基础功能打通/NOK-基础功能失败,不允许模型代码提交到master); PrecisionStatus(OK-精度达标/POK-Loss拟合但精度未完全达标/NOK-精度不达标, 不允许模型代码提交到master); AutoTune(OK-性能持平或高于GPU/POK-性能有提升但低于GPU/NOK-性能无提升或者功能失败); PerfStatus(训练:PERFECT-性能1.2倍GPU/OK-性能持平GPU/POK-性能0.5倍GPU/NOK-性能小于0.5倍GPU;推理:OK-4*310单卡>GPU/NOK-其它); ModelConvert:OK/NOK(仅推理, OK-om转换成功/NOK-om转换失败); QuantStatus:OK/NOK(仅推理, OK-精度损失1%以内,性能有提升/POK-性能有提升但未达标/NOK-量化失败); - -样例:modelzoo_level.txt文件 - ------仅限训练----- - - -``` -GPUStatus:OK/NOK -NPUMigrationStatus:OK/POK/NOK -``` - - ------仅限推理----- - -``` -ModelConvert:OK/POK/NOK -QuantStatus:OK/POK/NOK -``` - ------通用部分----- - -``` -FuncStatus:OK/NOK -PrecisionStatus:OK/POK/NOK -AutoTune:OK/POK/NOK -PerfStatus:PERFECT/OK/POK/NOK -``` -5、网络名称命名规范:*_for_框架,注:*代表任意内容,如网络名称或网络名称+网络ID; - - **六、编程规范** - -- 规范标准 - -1、C++代码遵循google编程规范:Google C++ Coding Guidelines;单元测测试遵循规范: Googletest Primer。 - -2、Python代码遵循PEP8规范:Python PEP 8 Coding Style;单元测试遵循规范: pytest - -- 规范备注 - -1、优先使用string类型,避免使用char*; - -2、禁止使用printf,一律使用cout; - -3、内存管理尽量使用智能指针; - -4、不准在函数里调用exit; - -5、禁止使用IDE等工具自动生成代码; - -6、控制第三方库依赖,如果引入第三方依赖,则需要提供第三方依赖安装和使用指导书; - -7、一律使用英文注释,注释率30%--40%,鼓励自注释; - -8、函数头必须有注释,说明函数作用,入参、出参; - -9、统一错误码,通过错误码可以确认那个分支返回错误; - -10、禁止出现打印一堆无影响的错误级别的日志; + **介绍** + +Ascend ModelZoo,欢迎各位开发者 + + **贡献要求** + +开发者提交的模型包括源码、readme、参考模型license文件、测试用例和readme,并遵循以下标准 + +请贡献者在提交代码之前签署CLA协议,“个人签署”,[链接](https://clasign.osinfra.cn/sign/Z2l0ZWUlMkZhc2NlbmQ=) + +如您完成签署,可在自己提交的PR评论区输入/check-cla进行核实校验 + + **一、源码** + +1、训练及在线推理请使用python代码实现,Ascend平台离线推理请使用C++或python代码,符合第四部分编码规范 + +2、参考[sample](https://gitee.com/ascend/modelzoo/tree/master/built-in/TensorFlow/Official/nlp/Transformer_for_TensorFlow) + +3、贡献者模型代码目录规则:"modelzoo/contrib/框架/Research/应用领域(nlp、cv、audio等)/网络名_IDxxx_for_TensorFlow"(以tf为例,社区管理团队会在贡献完成进行整合) + +4、从其他开源迁移的代码,请增加License声明 + + **二、License规则** + +* TensorFlow + + 迁移场景 + + 1、迁移TensorFlow模型中若源项目已包含License文件则必须拷贝引用,否则在模型顶层目录下添加TensorFlow Apache 2.0 License [TensorFlow License链接](https://github.com/tensorflow/tensorflow/blob/master/LICENSE) + + 2、迁移TensorFlow框架开发的模型,需要在模型目录下每个源文件附上源社区TensorFlow Apache 2.0 License头部声明,并在其下追加新增完整华为公司License声明 + + ``` + # Copyright 2017 The TensorFlow Authors. All Rights Reserved. + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + # ============================================================================ + # Copyright 2021 Huawei Technologies Co., Ltd + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ``` + 开发场景 + + 1、基于TensorFlow框架开发模型,需在模型项目顶层目录下添加TensorFlow Apache 2.0 License [TensorFlow License链接](https://github.com/tensorflow/tensorflow/blob/master/LICENSE) + + 2、基于TensorFlow框架开发模型,需要在模型目录下每个源文件附上源社区华为公司Apache 2.0 License头部声明 + ``` + # Copyright 2021 Huawei Technologies Co., Ltd + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ``` +* PyTorch + + 迁移场景 + + 1、迁移PyTorch模型中若源项目录已包含PyTorch License文件则必须拷贝引用,否则在模型顶层目录下添加PyTorch BSD-3 License [PyTorch License链接](https://github.com/pytorch/examples/blob/master/LICENSE) + + 2、迁移PyTorch第三方框架开发的模型,需要在模型目录下每个源文件附上源社区PyTorch BSD-3 License头部声明,并在其下追加新增一行华为公司License声明 + ``` + # BSD 3-Clause License + # + # Copyright (c) 2017 xxxx + # All rights reserved. + # Copyright 2021 Huawei Technologies Co., Ltd + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are met: + # + # * Redistributions of source code must retain the above copyright notice, this + # list of conditions and the following disclaimer. + # + # * Redistributions in binary form must reproduce the above copyright notice, + # this list of conditions and the following disclaimer in the documentation + # and/or other materials provided with the distribution. + # + # * Neither the name of the copyright holder nor the names of its + # contributors may be used to endorse or promote products derived from + # this software without specific prior written permission. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + # ============================================================================ + ``` + + 开发场景 + + 1、基于PyTorch框架开发模型,需在模型项目下添加PyTorch BSD-3 License [PyTorch License链接](https://github.com/pytorch/examples/blob/master/LICENSE) + + 2、基于PyTorch框架开发模型,需要在模型目录下每个源文件附上源社区华为公司Apache 2.0 License头部声明 + ``` + # Copyright 2021 Huawei Technologies Co., Ltd + # + # Licensed under the BSD 3-Clause License (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # https://opensource.org/licenses/BSD-3-Clause + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ``` + +* MindSpore/ACL + + 1、迁移或开发场景下MindSpore/ACL模型顶层目录下需要包含华为公司 License [华为公司 License链接](https://gitee.com/mindspore/mindspore/blob/master/LICENSE) + + 2、迁移或开发场景下MindSpore/ACL模型,需要在模型目录下每个源文件中添加区华为公司Apache 2.0 License头部声明 + ``` + # Copyright 2021 Huawei Technologies Co., Ltd + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ``` + +> 关于License声明时间,应注意: 2021年新建的文件,应该是Copyright 2021 Huawei Technologies Co., Ltd 2020年创建年份,2020年修改年份,应该是Copyright 2020 Huawei Technologies Co., Ltd + + **三、readme** + +readme用于指导用户理解和部署样例,要包含如下内容: + +- 简介: + +1、模型的来源及原理; + +2、模型复现的步骤,含训练、eval、在线/离线推理等,入口请封装成`.sh`、`.py`; + +- 关键要求: + +1、模型的出处、对数据的要求、免责声明等,开源代码文件修改需要增加版权说明; + +2、模型转换得到的离线模型对输入数据的要求; + +3、环境变量设置,依赖的第三方软件包和库,以及安装方法; + +4、精度和性能达成要求:尽量达到原始模型水平; + +5、预训练checkpoint、结果checkpoint请提供归档OBS、网盘链接,如来自开源需明确来源地址 + +6、数据集说明 + +- [ ] 不允许直接提供数据集的下载链接,可使用词汇:用户自行准备好数据集,可选用“XXX”,“XXX”,“XXX” + + 例如:请用户自行准备好数据集,包含训练集和验证集两部分,可选用的数据集包括ImageNet2012,CIFAR10、Flower等,包含train和val两部分。 + +- [ ] 脚本中不允许提供链接下载数据集,如果开源脚本上存在对应的链接,请修改或者删除对应的脚本 + +训练ReadMe写作可参考下面两个链接: + +[Readme example1](https://gitee.com/ascend/modelzoo/blob/master/built-in/TensorFlow/Official/cv/image_classification/DenseNet121_ID0067_for_TensorFlow/README.md) + +[Readme example2](https://www.hiascend.com/zh/software/modelzoo/detail/C/093ed0219cb14f068af33784c62cf7ec) + +离线推理ReadMe写作可参考下面链接: + +[Readme example1](https://gitee.com/ascend/modelzoo/tree/master/contrib/ACL_TensorFlow/Research/cv/AdvancedEAST_ID0130_for_ACL/README.md) + + **四、自测试用例** + +提供模型的自测试用例和readme,提交PR需要门禁及模型测试用例通过,性能和精度检查通过 + +- 简介: + +1、不同于完整的训练过程和全量数据集的推理,自测试用例的目的是验证提交代码基本功能可用,执行时长控制在10min之内(推理或训练只需执行有限的图片或step); + +2、提交PR中训练用例入口`train_testcase.sh`, 在线推理用例入口`online_inference_testcase.sh`, 离线推理用例入口`offline_inference_testcase.sh`; + +3、提交PR后,会自动触发门禁流水,后台会根据用例入口shell,自动将代码分发到对应执行环境; + +4、Jenkins预置账号:登录账号请联系华为工程师/接口人获取,登录之后,可以查看到用例执行日志 + +5、如果提交失败,请查看日志,修复代码或其他问题后,在你当前的PR中,评论“compile”即可重新触发用例执行 + +- 关键要求: + +1、自测试用例命名严格按照上述简介2要求来书写,否则门禁会校验失败; + +2、用例应当包含功能、精度(Loss值)、性能检查,检查通过打印"Run testcase success!",失败则打印"Run testcase failed!"; + +3、执行环境已预装软件包和Python3.7.5环境,调用命令"python3"、"python3.7"、"python3.7.5"均可,安装第三方库依赖使用"pip3"、"pip3.7"均可; + +4、数据集和模型:小于500M的文件,建议使用`obsutil`命令下载(已预装),过大的文件,建议提交Issue,注明数据集和下载地址,会提前下载到执行环境上, + +已预置数据集&python第三方库: [Environments](https://gitee.com/ascend/modelzoo/blob/master/contrib/ENVIRONMENTS.md) + +5、环境和其他问题,请提交Issue跟踪; + +6、测试用例开发参考: +- [训练](https://gitee.com/ascend/modelzoo/tree/master/built-in/TensorFlow/Official/nlp/Transformer_for_TensorFlow) +- [离线推理](https://gitee.com/alexcheng88/modelzoo/tree/master/contrib/TensorFlow/Research/cv/efficientnet-b8/ATC_efficientnet-b8_tf_nkxiaolei) + + **五、PR提交** + +- 关键要求: + +1、请将modelzoo仓fork到个人分支,基于个人分支新增、修改和提交PR; + +2、PR标题:线上活动,请在标题注明[线上贡献];高校活动,请注明[xxx学校][高校贡献]; + +3、built-in用户根据网络状态必须配置modelzoo_level.txt文件,且文件内容包含三个关键字段:FuncStatus(OK-流程通过/ **NOK-流程失败,不允许模型代码提交主仓** );PerfStatus(OK-持平GPU/POK-0.5倍GPU/NOK-小于0.5倍GPU/PERFECT-1.2倍GPU);PrecisionStatus(OK-精度达标,POK-Loss拟合但精度未实施, **NOK-Loss不拟合,不允许模型代码提交主仓** );内容格式如下所示(注:“:”两侧无需空格,英文格式;): + +``` + FuncStatus:OK/NOK + PerfStatus:PERFECT/OK/POK/NOK + PrecisionStatus:OK/POK/NOK +``` +4、contrib用户根据网络状态必须配置modelzoo_level.txt文件,且文件内容包含关键字段:GPUStatus(OK-GPU复现/NOK-GPU未复现); NPUMigrationStatus(OK-自动迁移成功/POK-自动迁移失败, 手写规避成功/NOK-均失败); FuncStatus(OK-基础功能打通/NOK-基础功能失败,不允许模型代码提交到master); PrecisionStatus(OK-精度达标/POK-Loss拟合但精度未完全达标/NOK-精度不达标, 不允许模型代码提交到master); AutoTune(OK-性能持平或高于GPU/POK-性能有提升但低于GPU/NOK-性能无提升或者功能失败); PerfStatus(训练:PERFECT-性能1.2倍GPU/OK-性能持平GPU/POK-性能0.5倍GPU/NOK-性能小于0.5倍GPU;推理:OK-4*310单卡>GPU/NOK-其它); ModelConvert:OK/NOK(仅推理, OK-om转换成功/NOK-om转换失败); QuantStatus:OK/NOK(仅推理, OK-精度损失1%以内,性能有提升/POK-性能有提升但未达标/NOK-量化失败); + +样例:modelzoo_level.txt文件 + +-----仅限训练----- + + +``` +GPUStatus:OK/NOK +NPUMigrationStatus:OK/POK/NOK +``` + + +-----仅限推理----- + +``` +ModelConvert:OK/POK/NOK +QuantStatus:OK/POK/NOK +``` + +-----通用部分----- + +``` +FuncStatus:OK/NOK +PrecisionStatus:OK/POK/NOK +AutoTune:OK/POK/NOK +PerfStatus:PERFECT/OK/POK/NOK +``` +5、网络名称命名规范:*_for_框架,注:*代表任意内容,如网络名称或网络名称+网络ID; + + **六、编程规范** + +- 规范标准 + +1、C++代码遵循google编程规范:Google C++ Coding Guidelines;单元测测试遵循规范: Googletest Primer。 + +2、Python代码遵循PEP8规范:Python PEP 8 Coding Style;单元测试遵循规范: pytest + +- 规范备注 + +1、优先使用string类型,避免使用char*; + +2、禁止使用printf,一律使用cout; + +3、内存管理尽量使用智能指针; + +4、不准在函数里调用exit; + +5、禁止使用IDE等工具自动生成代码; + +6、控制第三方库依赖,如果引入第三方依赖,则需要提供第三方依赖安装和使用指导书; + +7、一律使用英文注释,注释率30%--40%,鼓励自注释; + +8、函数头必须有注释,说明函数作用,入参、出参; + +9、统一错误码,通过错误码可以确认那个分支返回错误; + +10、禁止出现打印一堆无影响的错误级别的日志; diff --git a/ACL_PyTorch/contrib/audio/FastPitch/README.md b/ACL_PyTorch/contrib/audio/FastPitch/README.md index 0365271515d93198a62df562d8f58eea951fd55b..89f0244c823e6cccc219a3074464f192ed10fa28 100644 --- a/ACL_PyTorch/contrib/audio/FastPitch/README.md +++ b/ACL_PyTorch/contrib/audio/FastPitch/README.md @@ -1,225 +1,225 @@ -# FastPitch模型端到端推理指导 - -## 1 模型概述 - -- **[论文地址](https://arxiv.org/abs/2006.06873)** -- **[代码地址](https://github.com/NVIDIA/DeepLearningExamples/tree/master/PyTorch/SpeechSynthesis/FastPitch)** - -### 1.1 论文地址 - -[FastPitch论文](https://arxiv.org/abs/2006.06873) -Fastpitch模型由双向 Transformer 主干(也称为 Transformer 编码器)、音调预测器和持续时间预测器组成。 在通过第一组 N 个 Transformer 块、编码后,信号用基音信息增强并离散上采样。 然后它通过另一组 N个 Transformer 块,目的是平滑上采样信号,并构建梅尔谱图。 - -### 1.2 开源代码地址 - -[FastPitch开源代码](https://github.com/NVIDIA/DeepLearningExamples/tree/master/PyTorch/SpeechSynthesis/FastPitch) - -## 2 环境说明 - -### 2.1 深度学习框架 - -``` -onnx==1.9.0 -torch==1.8.0 -``` - -### 2.2 python第三方库 - -``` -matplotlib -numpy -inflect -librosa==0.8.0 -scipy -Unidecode -praat-parselmouth==0.3.3 -tensorboardX==2.0 -dllogger -``` - -**说明:** - -> X86架构:pytorch和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -### pth转om模型 - -1.下载pth权重文件 -``` -wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/audio/FastPitch/pretrained_models.zip -``` -(waveglow为语音生成器,不在本模型范围内, 但为了确保代码能正常运行,需要下载) - -2.安装相关依赖 - -``` -cd FastPitch -pip install -r requirements.txt -``` - -3.激活相关环境 - -``` -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest -``` - -3.pth转onnx, onnx简化,onnx转om。(以batch_size=1为例) - -``` -# 导出onnx -python pth2onnx.py -i phrases/tui_val100.tsv -o ./output/audio_tui_val100 --log-file ./output/audio_tui_val100/nvlog_infer.json --fastpitch pretrained_models/fastpitch/nvidia_fastpitch_210824.pt --waveglow pretrained_models/waveglow/nvidia_waveglow256pyt_fp16.pt --wn-channels 256 --energy-conditioning --batch-size 1 -# 简化onnx -python -m onnxsim ./test/models/FastPitch_bs1.onnx ./test/models/FastPitch_bs1_sim.onnx -# 转出om -atc --framework=5 --model=./test/models/FastPitch_bs1_sim.onnx --output=./test/models/FastPitch_bs1 --input_format=ND --input_shape="input:1,200" --out_nodes='Transpose_2044:0' --log=debug --soc_version=Ascend310 -``` - -输出在/test/models中。 - - - -## 4 数据集预处理 - -### 4.1 数据集获取 - -(可选)本项目默认将数据集存放于/opt/npu/ - -``` -cd .. -wget https://ascend-pytorch-one-datasets.obs.cn-north-4.myhuaweicloud.com/train/zip/LJSpeech-1.1.zip -unzip LJSpeech-1.1.zip -mv /LJSpeech-1.1 /opt/npu/ -``` - -### 4.2 数据集预处理 - -生成输入数据,并准备输出标签和pth权重的输出数据。本模型的验证集大小为100,具体信息在phrases/tui_val100.tsv文件中。 - -- FastPitch模型的输入数据是由文字编码组成,输入长度不等,模型已经将其补零成固定长度200。将输入数据转换为bin文件方便后续推理,存入test/input_bin文件夹下,且生成生成数据集预处理后的bin文件以及相应的info文件。 -- 在语音合成推理过程中,输出为mel图谱,本模型的输出维度为batch_size×900×80。将其输出tensor存为pth文件存入test/mel_tgt_pth文件夹下。 -- 同时,为了后面推理结束后将推理精度与原模型pth权重精度进行对比,将输入数据在pth模型中前传得到的输出tensor村委pth文件存入test/mel_out_pth文件夹下。 - -以上步骤均执行下面指令完成: - -``` -python data_process.py -i phrases/tui_val100.tsv -o ./output/audio_tui_val100 --log-file ./output/audio_tui_val100/nvlog_infer.json --fastpitch pretrained_models/fastpitch/nvidia_fastpitch_210824.pt --waveglow pretrained_models/waveglow/nvidia_waveglow256pyt_fp16.pt -``` - -## 5 离线推理及精度对比 - -### 5.1 使用benchmark工具推理 - -获取benchmark工具 - -### 5.2 模型推理 - -- 使用benchmark工具进行推理(以batch_size=1为例): - -benchmark模型推理工具,其输入是om模型以及模型所需要的输入bin文件,其输出是模型根据相应输入产生的输出文件。推理得到的结果会在test/result中。 - -将推理得到的结果重新转换为tensor形式,与标签mel_tgt计算mel_loss1。同时,将原模型pth权重前传得到的输出mel_out与标签mel_tgt计算出mel_loss2。mel_loss1与mel_loss2精度对齐则推理正确。 - -``` -source /usr/local/Ascend/ascend-toolkit/set_env.sh -cd test -./benchmark.x86_64 -model_type=nlp -device_id=0 -batch_size=1 -om_path=./models/FastPitch_bs1.om -input_text_path=./input_bin_info.info -output_binary=True -useDvpp=False -``` - - - -### 5.3 精度对比 - -``` -cd .. -python infer_test.py -``` - -以下为测试出的batch_size=1和16的精度对比: - -``` -mel_loss: - om pth -bs1 11.246 11.265 -bs16 11.330 11.265 -``` - - - -## 6 性能对比 - -### 6.1 npu性能数据 - -1. 运行test/performance.sh脚本 - -``` -cd test -./benchmark.x86_64 -round=20 -device_id=0 -batch_size=1 -om_path=./models/FastPitch_bs1.om -``` - -测试出来的ave_throughputRate,将其乘以4即为吞吐率。 - -以下计算结果为batch_size=1的结果。 - -![img](file:///C:\Users\1\AppData\Local\Temp\ksohtml\wps9EEB.tmp.jpg) - - - - - - - -### 6.2 T4性能数据 - -提供以下测试代码作参考: - -```python -import time - -model=...(导入模型及加载pth权重) - -input = torch.ones(size=(1, 200), dtype=torch.int64, device=device) -total_time = 0 -lens = 20 -for _ in range(lens): - start = time.time() - output = model(input) - end = time.time() - total_time += end - start -print(f"batch_size=1, FPS:{1.0/(total_time/lens)}") - - -input = torch.ones(size=(16, 200), dtype=torch.int64, device=device) -total_time = 0 -lens = 20 -for _ in range(lens): - start = time.time() - output = model(input) - end = time.time() - total_time += end - start -print(f"batch_size=16, FPS:{16.0/(total_time/lens)}") -``` - - - - - -### 6.3 性能对比 - -| Model | Batch Size | A300 Throughput/Card | T4 Throughput/Card | A300/T4 | -| --------- | ---------- | -------------------- | ------------------ | ------- | -| FasfPitch | 1 | 54.1476 | 28.828 | 1.878 | -| FasfPitch | 4 | 51.728 | - | - | -| FasfPitch | 8 | 51.3684 | - | - | -| FasfPitch | 16 | 51.714 | 64.94 | 0.796 | -| FasfPitch | 32 | 52.0696 | - | - | - -由于模型并没有性能要求,bs1、bs4、bs8、bs16、bs32时npu的性能高于T4性能的0.5倍,性能达标。 - +# FastPitch模型端到端推理指导 + +## 1 模型概述 + +- **[论文地址](https://arxiv.org/abs/2006.06873)** +- **[代码地址](https://github.com/NVIDIA/DeepLearningExamples/tree/master/PyTorch/SpeechSynthesis/FastPitch)** + +### 1.1 论文地址 + +[FastPitch论文](https://arxiv.org/abs/2006.06873) +Fastpitch模型由双向 Transformer 主干(也称为 Transformer 编码器)、音调预测器和持续时间预测器组成。 在通过第一组 N 个 Transformer 块、编码后,信号用基音信息增强并离散上采样。 然后它通过另一组 N个 Transformer 块,目的是平滑上采样信号,并构建梅尔谱图。 + +### 1.2 开源代码地址 + +[FastPitch开源代码](https://github.com/NVIDIA/DeepLearningExamples/tree/master/PyTorch/SpeechSynthesis/FastPitch) + +## 2 环境说明 + +### 2.1 深度学习框架 + +``` +onnx==1.9.0 +torch==1.8.0 +``` + +### 2.2 python第三方库 + +``` +matplotlib +numpy +inflect +librosa==0.8.0 +scipy +Unidecode +praat-parselmouth==0.3.3 +tensorboardX==2.0 +dllogger +``` + +**说明:** + +> X86架构:pytorch和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +### pth转om模型 + +1.下载pth权重文件 +``` +wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/audio/FastPitch/pretrained_models.zip +``` +(waveglow为语音生成器,不在本模型范围内, 但为了确保代码能正常运行,需要下载) + +2.安装相关依赖 + +``` +cd FastPitch +pip install -r requirements.txt +``` + +3.激活相关环境 + +``` +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest +``` + +3.pth转onnx, onnx简化,onnx转om。(以batch_size=1为例) + +``` +# 导出onnx +python pth2onnx.py -i phrases/tui_val100.tsv -o ./output/audio_tui_val100 --log-file ./output/audio_tui_val100/nvlog_infer.json --fastpitch pretrained_models/fastpitch/nvidia_fastpitch_210824.pt --waveglow pretrained_models/waveglow/nvidia_waveglow256pyt_fp16.pt --wn-channels 256 --energy-conditioning --batch-size 1 +# 简化onnx +python -m onnxsim ./test/models/FastPitch_bs1.onnx ./test/models/FastPitch_bs1_sim.onnx +# 转出om +atc --framework=5 --model=./test/models/FastPitch_bs1_sim.onnx --output=./test/models/FastPitch_bs1 --input_format=ND --input_shape="input:1,200" --out_nodes='Transpose_2044:0' --log=debug --soc_version=Ascend310 +``` + +输出在/test/models中。 + + + +## 4 数据集预处理 + +### 4.1 数据集获取 + +(可选)本项目默认将数据集存放于/opt/npu/ + +``` +cd .. +wget https://ascend-pytorch-one-datasets.obs.cn-north-4.myhuaweicloud.com/train/zip/LJSpeech-1.1.zip +unzip LJSpeech-1.1.zip +mv /LJSpeech-1.1 /opt/npu/ +``` + +### 4.2 数据集预处理 + +生成输入数据,并准备输出标签和pth权重的输出数据。本模型的验证集大小为100,具体信息在phrases/tui_val100.tsv文件中。 + +- FastPitch模型的输入数据是由文字编码组成,输入长度不等,模型已经将其补零成固定长度200。将输入数据转换为bin文件方便后续推理,存入test/input_bin文件夹下,且生成生成数据集预处理后的bin文件以及相应的info文件。 +- 在语音合成推理过程中,输出为mel图谱,本模型的输出维度为batch_size×900×80。将其输出tensor存为pth文件存入test/mel_tgt_pth文件夹下。 +- 同时,为了后面推理结束后将推理精度与原模型pth权重精度进行对比,将输入数据在pth模型中前传得到的输出tensor村委pth文件存入test/mel_out_pth文件夹下。 + +以上步骤均执行下面指令完成: + +``` +python data_process.py -i phrases/tui_val100.tsv -o ./output/audio_tui_val100 --log-file ./output/audio_tui_val100/nvlog_infer.json --fastpitch pretrained_models/fastpitch/nvidia_fastpitch_210824.pt --waveglow pretrained_models/waveglow/nvidia_waveglow256pyt_fp16.pt +``` + +## 5 离线推理及精度对比 + +### 5.1 使用benchmark工具推理 + +获取benchmark工具 + +### 5.2 模型推理 + +- 使用benchmark工具进行推理(以batch_size=1为例): + +benchmark模型推理工具,其输入是om模型以及模型所需要的输入bin文件,其输出是模型根据相应输入产生的输出文件。推理得到的结果会在test/result中。 + +将推理得到的结果重新转换为tensor形式,与标签mel_tgt计算mel_loss1。同时,将原模型pth权重前传得到的输出mel_out与标签mel_tgt计算出mel_loss2。mel_loss1与mel_loss2精度对齐则推理正确。 + +``` +source /usr/local/Ascend/ascend-toolkit/set_env.sh +cd test +./benchmark.x86_64 -model_type=nlp -device_id=0 -batch_size=1 -om_path=./models/FastPitch_bs1.om -input_text_path=./input_bin_info.info -output_binary=True -useDvpp=False +``` + + + +### 5.3 精度对比 + +``` +cd .. +python infer_test.py +``` + +以下为测试出的batch_size=1和16的精度对比: + +``` +mel_loss: + om pth +bs1 11.246 11.265 +bs16 11.330 11.265 +``` + + + +## 6 性能对比 + +### 6.1 npu性能数据 + +1. 运行test/performance.sh脚本 + +``` +cd test +./benchmark.x86_64 -round=20 -device_id=0 -batch_size=1 -om_path=./models/FastPitch_bs1.om +``` + +测试出来的ave_throughputRate,将其乘以4即为吞吐率。 + +以下计算结果为batch_size=1的结果。 + +![img](file:///C:\Users\1\AppData\Local\Temp\ksohtml\wps9EEB.tmp.jpg) + + + + + + + +### 6.2 T4性能数据 + +提供以下测试代码作参考: + +```python +import time + +model=...(导入模型及加载pth权重) + +input = torch.ones(size=(1, 200), dtype=torch.int64, device=device) +total_time = 0 +lens = 20 +for _ in range(lens): + start = time.time() + output = model(input) + end = time.time() + total_time += end - start +print(f"batch_size=1, FPS:{1.0/(total_time/lens)}") + + +input = torch.ones(size=(16, 200), dtype=torch.int64, device=device) +total_time = 0 +lens = 20 +for _ in range(lens): + start = time.time() + output = model(input) + end = time.time() + total_time += end - start +print(f"batch_size=16, FPS:{16.0/(total_time/lens)}") +``` + + + + + +### 6.3 性能对比 + +| Model | Batch Size | A300 Throughput/Card | T4 Throughput/Card | A300/T4 | +| --------- | ---------- | -------------------- | ------------------ | ------- | +| FasfPitch | 1 | 54.1476 | 28.828 | 1.878 | +| FasfPitch | 4 | 51.728 | - | - | +| FasfPitch | 8 | 51.3684 | - | - | +| FasfPitch | 16 | 51.714 | 64.94 | 0.796 | +| FasfPitch | 32 | 52.0696 | - | - | + +由于模型并没有性能要求,bs1、bs4、bs8、bs16、bs32时npu的性能高于T4性能的0.5倍,性能达标。 + diff --git a/ACL_PyTorch/contrib/audio/FastPitch/fastpitch/loss_function.py b/ACL_PyTorch/contrib/audio/FastPitch/fastpitch/loss_function.py index 9baf4a6c31ccb0e0e038190d55ce38a93d4ad3ee..0fe133abd4fdf5d8397ab2bdebbd96a61e443959 100644 --- a/ACL_PyTorch/contrib/audio/FastPitch/fastpitch/loss_function.py +++ b/ACL_PyTorch/contrib/audio/FastPitch/fastpitch/loss_function.py @@ -1,108 +1,108 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import torch -import torch.nn.functional as F -from torch import nn - -from common.utils import mask_from_lens -from fastpitch.attn_loss_function import AttentionCTCLoss - - -class FastPitchLoss(nn.Module): - def __init__(self, dur_predictor_loss_scale=1.0, - pitch_predictor_loss_scale=1.0, attn_loss_scale=1.0, - energy_predictor_loss_scale=0.1): - super(FastPitchLoss, self).__init__() - self.dur_predictor_loss_scale = dur_predictor_loss_scale - self.pitch_predictor_loss_scale = pitch_predictor_loss_scale - self.energy_predictor_loss_scale = energy_predictor_loss_scale - self.attn_loss_scale = attn_loss_scale - self.attn_ctc_loss = AttentionCTCLoss() - - def forward(self, model_out, targets, is_training=True, meta_agg='mean'): - (mel_out, dec_mask, dur_pred, log_dur_pred, pitch_pred, pitch_tgt, - energy_pred, energy_tgt, attn_soft, attn_hard, attn_dur, - attn_logprob) = model_out - - (mel_tgt, in_lens, out_lens) = targets - - dur_tgt = attn_dur - dur_lens = in_lens - - mel_tgt.requires_grad = False - # (B,H,T) => (B,T,H) - mel_tgt = mel_tgt.transpose(1, 2) - - dur_mask = mask_from_lens(dur_lens, max_len=dur_tgt.size(1)) - dur_mask_sum = dur_mask.sum() - - log_dur_tgt = torch.log(dur_tgt.float() + 1) - loss_fn = F.mse_loss - dur_pred_loss = loss_fn(log_dur_pred, log_dur_tgt, reduction='none') - dur_pred_loss = (dur_pred_loss * dur_mask).sum() / dur_mask_sum - - ldiff = mel_tgt.size(1) - mel_out.size(1) - mel_out = F.pad(mel_out, (0, 0, 0, ldiff, 0, 0), value=0.0) - - mel_mask = mel_tgt.ne(0).float() - mel_mask_sum = mel_mask.sum() - - loss_fn = F.mse_loss - mel_loss = loss_fn(mel_out, mel_tgt, reduction='none') - mel_loss = (mel_loss * mel_mask).sum() / mel_mask_sum - - ldiff = pitch_tgt.size(2) - pitch_pred.size(2) - pitch_pred = F.pad(pitch_pred, (0, ldiff, 0, 0, 0, 0), value=0.0) - pitch_loss = F.mse_loss(pitch_tgt, pitch_pred, reduction='none') - pitch_loss = (pitch_loss * dur_mask.unsqueeze(1)).sum() / dur_mask_sum - - if energy_pred is not None: - energy_pred = F.pad(energy_pred, (0, ldiff, 0, 0), value=0.0) - energy_loss = F.mse_loss(energy_tgt, energy_pred, reduction='none') - energy_loss = (energy_loss * dur_mask).sum() / dur_mask_sum - else: - energy_loss = 0 - - # Attention loss - attn_loss = self.attn_ctc_loss(attn_logprob, in_lens, out_lens) - - loss = (mel_loss - + dur_pred_loss * self.dur_predictor_loss_scale - + pitch_loss * self.pitch_predictor_loss_scale - + energy_loss * self.energy_predictor_loss_scale - + attn_loss * self.attn_loss_scale) - - meta = { - 'loss': loss.clone().detach(), - 'mel_loss': mel_loss.clone().detach(), - 'duration_predictor_loss': dur_pred_loss.clone().detach(), - 'pitch_loss': pitch_loss.clone().detach(), - 'energy_loss': energy_loss.clone().detach(), - 'attn_loss': attn_loss.clone().detach(), - 'dur_mask_sum': dur_mask_sum.clone().detach(), - 'mel_mask_sum': mel_mask_sum.clone().detach(), - 'dur_error': (torch.abs(dur_pred - dur_tgt).sum() - / dur_mask_sum).detach(), - } - - if energy_pred is not None: - meta['energy_loss'] = energy_loss.clone().detach() - - assert meta_agg in ('sum', 'mean') - if meta_agg == 'sum': - bsz = mel_out.size(0) - meta = {k: v * bsz for k, v in meta.items()} - return loss, meta +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import torch +import torch.nn.functional as F +from torch import nn + +from common.utils import mask_from_lens +from fastpitch.attn_loss_function import AttentionCTCLoss + + +class FastPitchLoss(nn.Module): + def __init__(self, dur_predictor_loss_scale=1.0, + pitch_predictor_loss_scale=1.0, attn_loss_scale=1.0, + energy_predictor_loss_scale=0.1): + super(FastPitchLoss, self).__init__() + self.dur_predictor_loss_scale = dur_predictor_loss_scale + self.pitch_predictor_loss_scale = pitch_predictor_loss_scale + self.energy_predictor_loss_scale = energy_predictor_loss_scale + self.attn_loss_scale = attn_loss_scale + self.attn_ctc_loss = AttentionCTCLoss() + + def forward(self, model_out, targets, is_training=True, meta_agg='mean'): + (mel_out, dec_mask, dur_pred, log_dur_pred, pitch_pred, pitch_tgt, + energy_pred, energy_tgt, attn_soft, attn_hard, attn_dur, + attn_logprob) = model_out + + (mel_tgt, in_lens, out_lens) = targets + + dur_tgt = attn_dur + dur_lens = in_lens + + mel_tgt.requires_grad = False + # (B,H,T) => (B,T,H) + mel_tgt = mel_tgt.transpose(1, 2) + + dur_mask = mask_from_lens(dur_lens, max_len=dur_tgt.size(1)) + dur_mask_sum = dur_mask.sum() + + log_dur_tgt = torch.log(dur_tgt.float() + 1) + loss_fn = F.mse_loss + dur_pred_loss = loss_fn(log_dur_pred, log_dur_tgt, reduction='none') + dur_pred_loss = (dur_pred_loss * dur_mask).sum() / dur_mask_sum + + ldiff = mel_tgt.size(1) - mel_out.size(1) + mel_out = F.pad(mel_out, (0, 0, 0, ldiff, 0, 0), value=0.0) + + mel_mask = mel_tgt.ne(0).float() + mel_mask_sum = mel_mask.sum() + + loss_fn = F.mse_loss + mel_loss = loss_fn(mel_out, mel_tgt, reduction='none') + mel_loss = (mel_loss * mel_mask).sum() / mel_mask_sum + + ldiff = pitch_tgt.size(2) - pitch_pred.size(2) + pitch_pred = F.pad(pitch_pred, (0, ldiff, 0, 0, 0, 0), value=0.0) + pitch_loss = F.mse_loss(pitch_tgt, pitch_pred, reduction='none') + pitch_loss = (pitch_loss * dur_mask.unsqueeze(1)).sum() / dur_mask_sum + + if energy_pred is not None: + energy_pred = F.pad(energy_pred, (0, ldiff, 0, 0), value=0.0) + energy_loss = F.mse_loss(energy_tgt, energy_pred, reduction='none') + energy_loss = (energy_loss * dur_mask).sum() / dur_mask_sum + else: + energy_loss = 0 + + # Attention loss + attn_loss = self.attn_ctc_loss(attn_logprob, in_lens, out_lens) + + loss = (mel_loss + + dur_pred_loss * self.dur_predictor_loss_scale + + pitch_loss * self.pitch_predictor_loss_scale + + energy_loss * self.energy_predictor_loss_scale + + attn_loss * self.attn_loss_scale) + + meta = { + 'loss': loss.clone().detach(), + 'mel_loss': mel_loss.clone().detach(), + 'duration_predictor_loss': dur_pred_loss.clone().detach(), + 'pitch_loss': pitch_loss.clone().detach(), + 'energy_loss': energy_loss.clone().detach(), + 'attn_loss': attn_loss.clone().detach(), + 'dur_mask_sum': dur_mask_sum.clone().detach(), + 'mel_mask_sum': mel_mask_sum.clone().detach(), + 'dur_error': (torch.abs(dur_pred - dur_tgt).sum() + / dur_mask_sum).detach(), + } + + if energy_pred is not None: + meta['energy_loss'] = energy_loss.clone().detach() + + assert meta_agg in ('sum', 'mean') + if meta_agg == 'sum': + bsz = mel_out.size(0) + meta = {k: v * bsz for k, v in meta.items()} + return loss, meta diff --git a/ACL_PyTorch/contrib/audio/FastPitch/infer.py b/ACL_PyTorch/contrib/audio/FastPitch/infer.py index c44a66dc1682d116e867e5cc775aedf4ef41e446..8281758ff3487db6d90ae73b78894eb3b058aaf4 100644 --- a/ACL_PyTorch/contrib/audio/FastPitch/infer.py +++ b/ACL_PyTorch/contrib/audio/FastPitch/infer.py @@ -1,90 +1,90 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import numpy as np -import torch -import torch.nn.functional as F -import os -import struct - - -def bin2tensor(binName): - size = os.path.getsize(binName) - binfile = open(binName, 'rb') - Len = int(size / 4) - res=[] - for i in range(Len): - data = binfile.read(4) - num = struct.unpack('f', data) - res.append(num[0]) - - binfile.close() - dim_res = np.array(res) - dim_res = torch.from_numpy(dim_res) - - return dim_res - - -def mel_loss(mel_out, mel_tgt): - """ - mel_out: torch.tensor, shape(batchsize, 80, 900) - mel_tgt: torch.tensor, shape(batchsize, 80, 900) - """ - mel_tgt = mel_tgt.transpose(1, 2) - mel_out = mel_out.transpose(1, 2) - - mel_mask = mel_tgt.ne(0).float() - mel_mask_sum = mel_mask.sum() - - loss_fn = F.mse_loss - mel_loss = loss_fn(mel_out, mel_tgt, reduction='none') - mel_loss = (mel_loss * mel_mask).sum() / mel_mask_sum - - return mel_loss - - -def test_om(): - tgt_path = "./test/mel_tgt_pth/" - out_path = './test/result/dumpOutput_device0/' - data_len = 100 - mel_loss_total = 0 - for i in range(data_len): - mel_out = bin2tensor(os.path.join(out_path, f"data{i}.bin")).reshape(1, 80, 900) - mel_tgt = torch.load(os.path.join(tgt_path, f"mel_tgt{i}.pth")) - mel_loss_ = mel_loss(mel_out, mel_tgt) - mel_loss_total += mel_loss_ - mel_loss_average = mel_loss_total / data_len - print("mel_loss_average", mel_loss_average.item()) - -def test_pth(): - out_path = './test/mel_out_pth/' - tgt_path = './test/mel_tgt_pth/' - data_len = 100 - mel_loss_total = 0 - for i in range(data_len): - mel_out = torch.load(os.path.join(out_path, f"mel_out{i}.pth")) - mel_tgt = torch.load(os.path.join(tgt_path, f"mel_tgt{i}.pth")) - mel_loss_ = mel_loss(mel_out, mel_tgt) - mel_loss_total += mel_loss_ - mel_loss_average = mel_loss_total / data_len - print("mel_loss_average", mel_loss_average.item()) - - - -if __name__ == "__main__": - print("==================om==================") - test_om() - print("==================pth==================") +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import numpy as np +import torch +import torch.nn.functional as F +import os +import struct + + +def bin2tensor(binName): + size = os.path.getsize(binName) + binfile = open(binName, 'rb') + Len = int(size / 4) + res=[] + for i in range(Len): + data = binfile.read(4) + num = struct.unpack('f', data) + res.append(num[0]) + + binfile.close() + dim_res = np.array(res) + dim_res = torch.from_numpy(dim_res) + + return dim_res + + +def mel_loss(mel_out, mel_tgt): + """ + mel_out: torch.tensor, shape(batchsize, 80, 900) + mel_tgt: torch.tensor, shape(batchsize, 80, 900) + """ + mel_tgt = mel_tgt.transpose(1, 2) + mel_out = mel_out.transpose(1, 2) + + mel_mask = mel_tgt.ne(0).float() + mel_mask_sum = mel_mask.sum() + + loss_fn = F.mse_loss + mel_loss = loss_fn(mel_out, mel_tgt, reduction='none') + mel_loss = (mel_loss * mel_mask).sum() / mel_mask_sum + + return mel_loss + + +def test_om(): + tgt_path = "./test/mel_tgt_pth/" + out_path = './test/result/dumpOutput_device0/' + data_len = 100 + mel_loss_total = 0 + for i in range(data_len): + mel_out = bin2tensor(os.path.join(out_path, f"data{i}.bin")).reshape(1, 80, 900) + mel_tgt = torch.load(os.path.join(tgt_path, f"mel_tgt{i}.pth")) + mel_loss_ = mel_loss(mel_out, mel_tgt) + mel_loss_total += mel_loss_ + mel_loss_average = mel_loss_total / data_len + print("mel_loss_average", mel_loss_average.item()) + +def test_pth(): + out_path = './test/mel_out_pth/' + tgt_path = './test/mel_tgt_pth/' + data_len = 100 + mel_loss_total = 0 + for i in range(data_len): + mel_out = torch.load(os.path.join(out_path, f"mel_out{i}.pth")) + mel_tgt = torch.load(os.path.join(tgt_path, f"mel_tgt{i}.pth")) + mel_loss_ = mel_loss(mel_out, mel_tgt) + mel_loss_total += mel_loss_ + mel_loss_average = mel_loss_total / data_len + print("mel_loss_average", mel_loss_average.item()) + + + +if __name__ == "__main__": + print("==================om==================") + test_om() + print("==================pth==================") test_pth() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/audio/FastPitch/infer_test.py b/ACL_PyTorch/contrib/audio/FastPitch/infer_test.py index c44a66dc1682d116e867e5cc775aedf4ef41e446..8281758ff3487db6d90ae73b78894eb3b058aaf4 100644 --- a/ACL_PyTorch/contrib/audio/FastPitch/infer_test.py +++ b/ACL_PyTorch/contrib/audio/FastPitch/infer_test.py @@ -1,90 +1,90 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import numpy as np -import torch -import torch.nn.functional as F -import os -import struct - - -def bin2tensor(binName): - size = os.path.getsize(binName) - binfile = open(binName, 'rb') - Len = int(size / 4) - res=[] - for i in range(Len): - data = binfile.read(4) - num = struct.unpack('f', data) - res.append(num[0]) - - binfile.close() - dim_res = np.array(res) - dim_res = torch.from_numpy(dim_res) - - return dim_res - - -def mel_loss(mel_out, mel_tgt): - """ - mel_out: torch.tensor, shape(batchsize, 80, 900) - mel_tgt: torch.tensor, shape(batchsize, 80, 900) - """ - mel_tgt = mel_tgt.transpose(1, 2) - mel_out = mel_out.transpose(1, 2) - - mel_mask = mel_tgt.ne(0).float() - mel_mask_sum = mel_mask.sum() - - loss_fn = F.mse_loss - mel_loss = loss_fn(mel_out, mel_tgt, reduction='none') - mel_loss = (mel_loss * mel_mask).sum() / mel_mask_sum - - return mel_loss - - -def test_om(): - tgt_path = "./test/mel_tgt_pth/" - out_path = './test/result/dumpOutput_device0/' - data_len = 100 - mel_loss_total = 0 - for i in range(data_len): - mel_out = bin2tensor(os.path.join(out_path, f"data{i}.bin")).reshape(1, 80, 900) - mel_tgt = torch.load(os.path.join(tgt_path, f"mel_tgt{i}.pth")) - mel_loss_ = mel_loss(mel_out, mel_tgt) - mel_loss_total += mel_loss_ - mel_loss_average = mel_loss_total / data_len - print("mel_loss_average", mel_loss_average.item()) - -def test_pth(): - out_path = './test/mel_out_pth/' - tgt_path = './test/mel_tgt_pth/' - data_len = 100 - mel_loss_total = 0 - for i in range(data_len): - mel_out = torch.load(os.path.join(out_path, f"mel_out{i}.pth")) - mel_tgt = torch.load(os.path.join(tgt_path, f"mel_tgt{i}.pth")) - mel_loss_ = mel_loss(mel_out, mel_tgt) - mel_loss_total += mel_loss_ - mel_loss_average = mel_loss_total / data_len - print("mel_loss_average", mel_loss_average.item()) - - - -if __name__ == "__main__": - print("==================om==================") - test_om() - print("==================pth==================") +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import numpy as np +import torch +import torch.nn.functional as F +import os +import struct + + +def bin2tensor(binName): + size = os.path.getsize(binName) + binfile = open(binName, 'rb') + Len = int(size / 4) + res=[] + for i in range(Len): + data = binfile.read(4) + num = struct.unpack('f', data) + res.append(num[0]) + + binfile.close() + dim_res = np.array(res) + dim_res = torch.from_numpy(dim_res) + + return dim_res + + +def mel_loss(mel_out, mel_tgt): + """ + mel_out: torch.tensor, shape(batchsize, 80, 900) + mel_tgt: torch.tensor, shape(batchsize, 80, 900) + """ + mel_tgt = mel_tgt.transpose(1, 2) + mel_out = mel_out.transpose(1, 2) + + mel_mask = mel_tgt.ne(0).float() + mel_mask_sum = mel_mask.sum() + + loss_fn = F.mse_loss + mel_loss = loss_fn(mel_out, mel_tgt, reduction='none') + mel_loss = (mel_loss * mel_mask).sum() / mel_mask_sum + + return mel_loss + + +def test_om(): + tgt_path = "./test/mel_tgt_pth/" + out_path = './test/result/dumpOutput_device0/' + data_len = 100 + mel_loss_total = 0 + for i in range(data_len): + mel_out = bin2tensor(os.path.join(out_path, f"data{i}.bin")).reshape(1, 80, 900) + mel_tgt = torch.load(os.path.join(tgt_path, f"mel_tgt{i}.pth")) + mel_loss_ = mel_loss(mel_out, mel_tgt) + mel_loss_total += mel_loss_ + mel_loss_average = mel_loss_total / data_len + print("mel_loss_average", mel_loss_average.item()) + +def test_pth(): + out_path = './test/mel_out_pth/' + tgt_path = './test/mel_tgt_pth/' + data_len = 100 + mel_loss_total = 0 + for i in range(data_len): + mel_out = torch.load(os.path.join(out_path, f"mel_out{i}.pth")) + mel_tgt = torch.load(os.path.join(tgt_path, f"mel_tgt{i}.pth")) + mel_loss_ = mel_loss(mel_out, mel_tgt) + mel_loss_total += mel_loss_ + mel_loss_average = mel_loss_total / data_len + print("mel_loss_average", mel_loss_average.item()) + + + +if __name__ == "__main__": + print("==================om==================") + test_om() + print("==================pth==================") test_pth() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/audio/rawnet2/README.md b/ACL_PyTorch/contrib/audio/rawnet2/README.md index 4ead1dd821661c9e1067ef9d47ad53c94bbf6ed2..a0b55e2b85296be83337db606f380a3445527c6c 100644 --- a/ACL_PyTorch/contrib/audio/rawnet2/README.md +++ b/ACL_PyTorch/contrib/audio/rawnet2/README.md @@ -1,50 +1,50 @@ -### 1.环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - -``` -pip3 install -r requirements.txt -``` - -2.获取,开源模型代码 - -``` -git clone https://github.com/Jungjee/RawNet.git -cd RawNet -patch -p1 < ../rawnet2.patch -cd .. -``` - -3.获取权重文件 - -通过2获得代码仓后,权重文件位置:RawNet\python\RawNet2\Pre-trained_model\rawnet2_best_weights.pt,将其放到当前目录 - -4.获取数据集 [VoxCeleb1](https://www.robots.ox.ac.uk/~vgg/data/voxceleb/vox1.html) ,下载Audio files测试集,重命名VoxCeleb1,确保VoxCeleb1下全部为id1xxxx文件夹,放到/root/datasets目录,注:该路径为绝对路径 - -5.获取 [msame工具](https://gitee.com/ascend/tools/tree/master/msame) 和 [benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) - -将msame和benchmark.x86_64放到与test文件夹同级目录下。 - -### 2.离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 - -备注: - -1.需要对onnx模型进行onnxsim优化,否则无法达到精度要求,pth2om.sh脚本首先将pth文件转换为onnx模型,然后分别对bs1和bs16进行onnxsim优化,最后分别转化为om模型 - -2.eval_acc_perf.sh脚本逐步完成数据前处理bin文件输出、bs1和bs16模型推理、bs1和bs16精度测试,以及bs1和bs16benchmark的性能测试 - -``` -bash test/pth2om.sh - -bash test/eval_acc_perf.sh --datasets_path=/root/datasets/VoxCeleb1/ -``` - -评测结果: - -| 模型 | 官网pth精度 | 310精度 | 基准性能 | 310性能 | -| --------------------- | ----------------------------------------------- | --------- | -------- | ------- | -| Baseline-RawNet2 bs1 | [EER 2.49%](https://github.com/Jungjee/RawNet/) | EER 2.50% | 285.7fps | 72.8fps | -| Baseline-RawNet2 bs16 | [EER 2.49%](https://github.com/Jungjee/RawNet/) | EER 2.50% | 489.3fps | 77.6fps | - +### 1.环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + +``` +pip3 install -r requirements.txt +``` + +2.获取,开源模型代码 + +``` +git clone https://github.com/Jungjee/RawNet.git +cd RawNet +patch -p1 < ../rawnet2.patch +cd .. +``` + +3.获取权重文件 + +通过2获得代码仓后,权重文件位置:RawNet\python\RawNet2\Pre-trained_model\rawnet2_best_weights.pt,将其放到当前目录 + +4.获取数据集 [VoxCeleb1](https://www.robots.ox.ac.uk/~vgg/data/voxceleb/vox1.html) ,下载Audio files测试集,重命名VoxCeleb1,确保VoxCeleb1下全部为id1xxxx文件夹,放到/root/datasets目录,注:该路径为绝对路径 + +5.获取 [msame工具](https://gitee.com/ascend/tools/tree/master/msame) 和 [benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) + +将msame和benchmark.x86_64放到与test文件夹同级目录下。 + +### 2.离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 + +备注: + +1.需要对onnx模型进行onnxsim优化,否则无法达到精度要求,pth2om.sh脚本首先将pth文件转换为onnx模型,然后分别对bs1和bs16进行onnxsim优化,最后分别转化为om模型 + +2.eval_acc_perf.sh脚本逐步完成数据前处理bin文件输出、bs1和bs16模型推理、bs1和bs16精度测试,以及bs1和bs16benchmark的性能测试 + +``` +bash test/pth2om.sh + +bash test/eval_acc_perf.sh --datasets_path=/root/datasets/VoxCeleb1/ +``` + +评测结果: + +| 模型 | 官网pth精度 | 310精度 | 基准性能 | 310性能 | +| --------------------- | ----------------------------------------------- | --------- | -------- | ------- | +| Baseline-RawNet2 bs1 | [EER 2.49%](https://github.com/Jungjee/RawNet/) | EER 2.50% | 285.7fps | 72.8fps | +| Baseline-RawNet2 bs16 | [EER 2.49%](https://github.com/Jungjee/RawNet/) | EER 2.50% | 489.3fps | 77.6fps | + diff --git a/ACL_PyTorch/contrib/audio/rawnet2/RawNet2_postprocess.py b/ACL_PyTorch/contrib/audio/rawnet2/RawNet2_postprocess.py index a0263c606aaa5356b020b795568a12e6a0e8d7aa..a6a9b03a3c424b59cf8b03355cf82ebb0e083399 100644 --- a/ACL_PyTorch/contrib/audio/rawnet2/RawNet2_postprocess.py +++ b/ACL_PyTorch/contrib/audio/rawnet2/RawNet2_postprocess.py @@ -1,121 +1,121 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import os -import sys -import numpy as np -from sklearn.metrics import roc_curve -from scipy.optimize import brentq -from scipy.interpolate import interp1d -from tqdm import tqdm -import argparse - -sys.path.append('RawNet/python/RawNet2/') -from utils import cos_sim - -def get_l_embeddings(list_embeddings,bs,path="def"): - temp = "" - l_embeddings = [] - index = 0 - l_utt = [] - l_code = [] - with tqdm(total=len(list_embeddings), ncols=70) as pbar: - if bs==1: - files = sorted(list_embeddings) - else: - files = list_embeddings.keys() - for f in files: - if bs==1: - t = np.loadtxt(path + "/" + f) - t = t.astype(np.float32) - else: - t = list_embeddings[f] - index += 1 - key = f.replace("$", "/", 2).split("$")[0] - if (temp == ""): - temp = key - l_utt.append(key) - if (key == temp): - l_code.append(t) - else: - l_embeddings.append(np.mean(l_code, axis=0)) - temp = key - l_utt.append(key) - l_code = [] - l_code.append(t) - if (index == len(files)): - l_embeddings.append(np.mean(l_code, axis=0)) - pbar.update(1) - if not len(l_utt) == len(l_embeddings): - print(len(l_utt), len(l_embeddings)) - exit() - d_embeddings = {} - for k, v in zip(l_utt, l_embeddings): - d_embeddings[k] = v - return d_embeddings - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('--input', help='bin path', default="", required=True) - parser.add_argument('--batch_size', help='batch size', required=True) - parser.add_argument('--output', help='result path', default="result/") - args = parser.parse_args() - batch_size = int(args.batch_size) - base = args.input - save_dir = args.output - d_embeddings = {} - if batch_size == 1: - for path, dirs, files in os.walk(base): - d_embeddings = get_l_embeddings(files,batch_size,path); - else: - with open('bs16_key.txt', 'r') as f: - l_val = f.readlines() - bs16_out = [] - for path, dirs, files in os.walk(base): - files = sorted(files, key=lambda x: [int(x.split('_')[0])]) - for f in files: - t = np.loadtxt(path + "/" + f) - for i in t: - i.reshape(1024, ) - bs16_out.append(i) - bs16_out_embeddings = {} - if not len(l_val) == len(bs16_out): - print(len(l_val), len(bs16_out)) - exit() - for k, v in zip(l_val, bs16_out): - bs16_out_embeddings[k] = v - d_embeddings = get_l_embeddings(bs16_out_embeddings,batch_size); - - with open('RawNet/trials/vox_original.txt', 'r') as f: - l_val_trial = f.readlines() - y_score = [] - y = [] - f_res = open(save_dir + 'result_detail_bs{}.txt'.format(batch_size), 'w') - for line in l_val_trial: - trg, utt_a, utt_b = line.strip().split(' ') - y.append(int(trg)) - y_score.append(cos_sim(d_embeddings[utt_a], d_embeddings[utt_b])) - f_res.write('{score} {target}\n'.format(score=y_score[-1], target=y[-1])) - f_res.close() - fpr, tpr, _ = roc_curve(y, y_score, pos_label=1) - eer = brentq(lambda x: 1. - x - interp1d(fpr, tpr)(x), 0., 1.) - f_eer_301 = open(save_dir + 'result_eer_{}.txt'.format(batch_size), 'w') - f_eer_301.write('bs{dir} evaluation EER: {eer}\n'.format(dir=batch_size, eer=eer)) - f_eer_301.close() - print('bs{dir} evaluation EER: {eer}\n'.format(dir=batch_size, eer=eer)) - - -if __name__ == '__main__': - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import os +import sys +import numpy as np +from sklearn.metrics import roc_curve +from scipy.optimize import brentq +from scipy.interpolate import interp1d +from tqdm import tqdm +import argparse + +sys.path.append('RawNet/python/RawNet2/') +from utils import cos_sim + +def get_l_embeddings(list_embeddings,bs,path="def"): + temp = "" + l_embeddings = [] + index = 0 + l_utt = [] + l_code = [] + with tqdm(total=len(list_embeddings), ncols=70) as pbar: + if bs==1: + files = sorted(list_embeddings) + else: + files = list_embeddings.keys() + for f in files: + if bs==1: + t = np.loadtxt(path + "/" + f) + t = t.astype(np.float32) + else: + t = list_embeddings[f] + index += 1 + key = f.replace("$", "/", 2).split("$")[0] + if (temp == ""): + temp = key + l_utt.append(key) + if (key == temp): + l_code.append(t) + else: + l_embeddings.append(np.mean(l_code, axis=0)) + temp = key + l_utt.append(key) + l_code = [] + l_code.append(t) + if (index == len(files)): + l_embeddings.append(np.mean(l_code, axis=0)) + pbar.update(1) + if not len(l_utt) == len(l_embeddings): + print(len(l_utt), len(l_embeddings)) + exit() + d_embeddings = {} + for k, v in zip(l_utt, l_embeddings): + d_embeddings[k] = v + return d_embeddings + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--input', help='bin path', default="", required=True) + parser.add_argument('--batch_size', help='batch size', required=True) + parser.add_argument('--output', help='result path', default="result/") + args = parser.parse_args() + batch_size = int(args.batch_size) + base = args.input + save_dir = args.output + d_embeddings = {} + if batch_size == 1: + for path, dirs, files in os.walk(base): + d_embeddings = get_l_embeddings(files,batch_size,path); + else: + with open('bs16_key.txt', 'r') as f: + l_val = f.readlines() + bs16_out = [] + for path, dirs, files in os.walk(base): + files = sorted(files, key=lambda x: [int(x.split('_')[0])]) + for f in files: + t = np.loadtxt(path + "/" + f) + for i in t: + i.reshape(1024, ) + bs16_out.append(i) + bs16_out_embeddings = {} + if not len(l_val) == len(bs16_out): + print(len(l_val), len(bs16_out)) + exit() + for k, v in zip(l_val, bs16_out): + bs16_out_embeddings[k] = v + d_embeddings = get_l_embeddings(bs16_out_embeddings,batch_size); + + with open('RawNet/trials/vox_original.txt', 'r') as f: + l_val_trial = f.readlines() + y_score = [] + y = [] + f_res = open(save_dir + 'result_detail_bs{}.txt'.format(batch_size), 'w') + for line in l_val_trial: + trg, utt_a, utt_b = line.strip().split(' ') + y.append(int(trg)) + y_score.append(cos_sim(d_embeddings[utt_a], d_embeddings[utt_b])) + f_res.write('{score} {target}\n'.format(score=y_score[-1], target=y[-1])) + f_res.close() + fpr, tpr, _ = roc_curve(y, y_score, pos_label=1) + eer = brentq(lambda x: 1. - x - interp1d(fpr, tpr)(x), 0., 1.) + f_eer_301 = open(save_dir + 'result_eer_{}.txt'.format(batch_size), 'w') + f_eer_301.write('bs{dir} evaluation EER: {eer}\n'.format(dir=batch_size, eer=eer)) + f_eer_301.close() + print('bs{dir} evaluation EER: {eer}\n'.format(dir=batch_size, eer=eer)) + + +if __name__ == '__main__': + main() diff --git a/ACL_PyTorch/contrib/audio/rawnet2/RawNet2_preprocess.py b/ACL_PyTorch/contrib/audio/rawnet2/RawNet2_preprocess.py index a0e421fb775828d7a58efc6a9d9100e3e3b06471..8249f16a440319c288bd49a8907e5be757678b41 100644 --- a/ACL_PyTorch/contrib/audio/rawnet2/RawNet2_preprocess.py +++ b/ACL_PyTorch/contrib/audio/rawnet2/RawNet2_preprocess.py @@ -1,84 +1,84 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import os -import numpy as np -import argparse -import sys -sys.path.append('RawNet/python/RawNet2/') -from dataloader import TA_Dataset_VoxCeleb2 - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('--input', help='dataset path', default="/root/datasets/VoxCeleb1/") - parser.add_argument('--batch_size', help='batch size', default=1) - parser.add_argument('--output', help='out bin path', default="bin_out_bs1/") - args = parser.parse_args() - base_dir = args.input - out_dir = args.output - batch_size = int(args.batch_size) - - def get_utt_list(src_dir): - l_utt = [] - for path, dirs, files in os.walk(src_dir): - path = path.replace('\\', '/') - base = '/'.join(path.split('/')[-2:]) + '/' - for f in files: - if f[-3:] != 'wav': - continue - l_utt.append(base + f) - return l_utt - - l_val = sorted(get_utt_list(base_dir)) - TA_evalset = TA_Dataset_VoxCeleb2(list_IDs=l_val, - return_label=True, - window_size=11810, - nb_samp=59049, - base_dir=base_dir) - if batch_size == 1: - for item in TA_evalset: - n = 0 - for i in item[0]: - i.tofile(out_dir + item[1].replace('/', '$') + "$" + str(n) + ".bin") - n += 1 - else: - bs16_key = open('bs16_key.txt', mode='w') - bs16 = [] - n = 0 - i = 0 - for item in TA_evalset: - l = 0 - for t in item[0]: - bs16_key.write(item[1].replace('/', '$') + "$" + str(n) + ".bin" + "$" + str(l) + "\n") - l += 1 - n += 1 - bs16.append(t) - if n == batch_size: - np.vstack(bs16).tofile(out_dir + str(i) + ".bin") - i += 1 - bs16 = [] - n = 0 - if n % batch_size == 0: - return - for j in range(batch_size - (n % batch_size)): - bs16_key.write("temp$" + str(j) + "\n") - bs16.append(np.empty((59049,), dtype='float32')) - bs16_key.close() - np.vstack(bs16).tofile(out_dir + str(i) + ".bin") - - -if __name__ == '__main__': - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import os +import numpy as np +import argparse +import sys +sys.path.append('RawNet/python/RawNet2/') +from dataloader import TA_Dataset_VoxCeleb2 + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--input', help='dataset path', default="/root/datasets/VoxCeleb1/") + parser.add_argument('--batch_size', help='batch size', default=1) + parser.add_argument('--output', help='out bin path', default="bin_out_bs1/") + args = parser.parse_args() + base_dir = args.input + out_dir = args.output + batch_size = int(args.batch_size) + + def get_utt_list(src_dir): + l_utt = [] + for path, dirs, files in os.walk(src_dir): + path = path.replace('\\', '/') + base = '/'.join(path.split('/')[-2:]) + '/' + for f in files: + if f[-3:] != 'wav': + continue + l_utt.append(base + f) + return l_utt + + l_val = sorted(get_utt_list(base_dir)) + TA_evalset = TA_Dataset_VoxCeleb2(list_IDs=l_val, + return_label=True, + window_size=11810, + nb_samp=59049, + base_dir=base_dir) + if batch_size == 1: + for item in TA_evalset: + n = 0 + for i in item[0]: + i.tofile(out_dir + item[1].replace('/', '$') + "$" + str(n) + ".bin") + n += 1 + else: + bs16_key = open('bs16_key.txt', mode='w') + bs16 = [] + n = 0 + i = 0 + for item in TA_evalset: + l = 0 + for t in item[0]: + bs16_key.write(item[1].replace('/', '$') + "$" + str(n) + ".bin" + "$" + str(l) + "\n") + l += 1 + n += 1 + bs16.append(t) + if n == batch_size: + np.vstack(bs16).tofile(out_dir + str(i) + ".bin") + i += 1 + bs16 = [] + n = 0 + if n % batch_size == 0: + return + for j in range(batch_size - (n % batch_size)): + bs16_key.write("temp$" + str(j) + "\n") + bs16.append(np.empty((59049,), dtype='float32')) + bs16_key.close() + np.vstack(bs16).tofile(out_dir + str(i) + ".bin") + + +if __name__ == '__main__': + main() diff --git a/ACL_PyTorch/contrib/audio/rawnet2/RawNet2_pth2onnx.py b/ACL_PyTorch/contrib/audio/rawnet2/RawNet2_pth2onnx.py index 8cdefee1d34c7c0d35e9c1c58554041471cb548a..a202509a73511017f476ed527a61281774f13e82 100644 --- a/ACL_PyTorch/contrib/audio/rawnet2/RawNet2_pth2onnx.py +++ b/ACL_PyTorch/contrib/audio/rawnet2/RawNet2_pth2onnx.py @@ -1,34 +1,34 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import sys -import torch - -sys.path.append('RawNet/python/RawNet2/Pre-trained_model') -from RawNet.python.RawNet2.parser import get_args -from model_RawNet2_original_code import RawNet - -ptfile = "rawnet2_best_weights.pt" -args = get_args() -args.model['nb_classes'] = 6112 -model = RawNet(args.model, device="cpu") -model.load_state_dict(torch.load(ptfile, map_location=torch.device('cpu'))) -input_names = ["wav"] -output_names = ["class"] -dynamic_axes = {'wav': {0: '-1'}, 'class': {0: '-1'}} -dummy_input = torch.randn(1, 59049) -export_onnx_file = "RawNet2.onnx" -torch.onnx.export(model, dummy_input, export_onnx_file, input_names=input_names, dynamic_axes=dynamic_axes, - output_names=output_names, opset_version=11, verbose=True) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import sys +import torch + +sys.path.append('RawNet/python/RawNet2/Pre-trained_model') +from RawNet.python.RawNet2.parser import get_args +from model_RawNet2_original_code import RawNet + +ptfile = "rawnet2_best_weights.pt" +args = get_args() +args.model['nb_classes'] = 6112 +model = RawNet(args.model, device="cpu") +model.load_state_dict(torch.load(ptfile, map_location=torch.device('cpu'))) +input_names = ["wav"] +output_names = ["class"] +dynamic_axes = {'wav': {0: '-1'}, 'class': {0: '-1'}} +dummy_input = torch.randn(1, 59049) +export_onnx_file = "RawNet2.onnx" +torch.onnx.export(model, dummy_input, export_onnx_file, input_names=input_names, dynamic_axes=dynamic_axes, + output_names=output_names, opset_version=11, verbose=True) diff --git a/ACL_PyTorch/contrib/audio/rawnet2/env.sh b/ACL_PyTorch/contrib/audio/rawnet2/env.sh index ea514e10c5375ef01ed40d5e7e612e000606e074..52554cfca2bdaa7918b38a82ab05b0c83cd28a15 100644 --- a/ACL_PyTorch/contrib/audio/rawnet2/env.sh +++ b/ACL_PyTorch/contrib/audio/rawnet2/env.sh @@ -1,6 +1,6 @@ -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest diff --git a/ACL_PyTorch/contrib/audio/rawnet2/fusion_switch.cfg b/ACL_PyTorch/contrib/audio/rawnet2/fusion_switch.cfg index ece7f48ff26239ec868a76a38d6f6b3c5577a4f9..9f8ef7e7a67a86c517c12550462c28c316105271 100644 --- a/ACL_PyTorch/contrib/audio/rawnet2/fusion_switch.cfg +++ b/ACL_PyTorch/contrib/audio/rawnet2/fusion_switch.cfg @@ -1,7 +1,7 @@ -{ - "Switch":{ - "UBFusion":{ - "TbeEltwiseFusionPass":"off" - } - } +{ + "Switch":{ + "UBFusion":{ + "TbeEltwiseFusionPass":"off" + } + } } \ No newline at end of file diff --git a/ACL_PyTorch/contrib/audio/rawnet2/modelzoo_level.txt b/ACL_PyTorch/contrib/audio/rawnet2/modelzoo_level.txt index 20e36b3f785cf4dbfc970929d2d793911d57c314..85fa1416d33effb8f710f3ac3f6772fcbc898eaa 100644 --- a/ACL_PyTorch/contrib/audio/rawnet2/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/audio/rawnet2/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:NOK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/audio/rawnet2/perf_t4.sh b/ACL_PyTorch/contrib/audio/rawnet2/perf_t4.sh index 26aa1c974822b20801cd53cd8dda1842560b8248..56e04681b167c948b6a9aaec608faecdb90d6c67 100644 --- a/ACL_PyTorch/contrib/audio/rawnet2/perf_t4.sh +++ b/ACL_PyTorch/contrib/audio/rawnet2/perf_t4.sh @@ -1,21 +1,21 @@ -#! /bin/bash - -trtexec --onnx=RawNet2_sim_bs1.onnx --fp16 --shapes=wav:1x59049 > RawNet2_bs1.log -perf_str=`grep "GPU.* mean.*ms$" ReID_bs1.log` -if [ -n "$perf_str" ]; then - perf_num=`echo $perf_str | awk -F' ' '{print $16}'` -else - perf_str=`grep "mean.*ms$" ReID_bs1.log` - perf_num=`echo $perf_str | awk -F' ' '{print $4}'` -fi -awk 'BEGIN{printf "gpu bs1 fps:%.3f\n", 1000*1/('$perf_num'/1)}' - -trtexec --onnx=RawNet2_sim_bs16.onnx --fp16 --shapes=wav:16x59049 > RawNet2_bs16.log -perf_str=`grep "GPU.* mean.*ms$" ReID_bs16.log` -if [ -n "$perf_str" ]; then - perf_num=`echo $perf_str | awk -F' ' '{print $16}'` -else - perf_str=`grep "mean.*ms$" ReID_bs16.log` - perf_num=`echo $perf_str | awk -F' ' '{print $4}'` -fi -awk 'BEGIN{printf "gpu bs16 fps:%.3f\n", 1000*1/('$perf_num'/16)}' +#! /bin/bash + +trtexec --onnx=RawNet2_sim_bs1.onnx --fp16 --shapes=wav:1x59049 > RawNet2_bs1.log +perf_str=`grep "GPU.* mean.*ms$" ReID_bs1.log` +if [ -n "$perf_str" ]; then + perf_num=`echo $perf_str | awk -F' ' '{print $16}'` +else + perf_str=`grep "mean.*ms$" ReID_bs1.log` + perf_num=`echo $perf_str | awk -F' ' '{print $4}'` +fi +awk 'BEGIN{printf "gpu bs1 fps:%.3f\n", 1000*1/('$perf_num'/1)}' + +trtexec --onnx=RawNet2_sim_bs16.onnx --fp16 --shapes=wav:16x59049 > RawNet2_bs16.log +perf_str=`grep "GPU.* mean.*ms$" ReID_bs16.log` +if [ -n "$perf_str" ]; then + perf_num=`echo $perf_str | awk -F' ' '{print $16}'` +else + perf_str=`grep "mean.*ms$" ReID_bs16.log` + perf_num=`echo $perf_str | awk -F' ' '{print $4}'` +fi +awk 'BEGIN{printf "gpu bs16 fps:%.3f\n", 1000*1/('$perf_num'/16)}' diff --git a/ACL_PyTorch/contrib/audio/rawnet2/requirements.txt b/ACL_PyTorch/contrib/audio/rawnet2/requirements.txt index 4c42a0cc0aeca63750fc209152436c342b452cfa..dbb1bfa1b61ec0049a3ea874249a204172a07813 100644 --- a/ACL_PyTorch/contrib/audio/rawnet2/requirements.txt +++ b/ACL_PyTorch/contrib/audio/rawnet2/requirements.txt @@ -1,9 +1,9 @@ -torch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.10.1 -onnx-simplifier==0.3.6 -numpy -scikit-learn -scipy -tqdm +torch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.10.1 +onnx-simplifier==0.3.6 +numpy +scikit-learn +scipy +tqdm soundfile \ No newline at end of file diff --git a/ACL_PyTorch/contrib/audio/rawnet2/test/parse.py b/ACL_PyTorch/contrib/audio/rawnet2/test/parse.py index 6cdf1420bd3d3e7d14f5add67c57cfe2ad399407..64b47e3cff99e9e20539ae0c03b95d691d92aa1d 100644 --- a/ACL_PyTorch/contrib/audio/rawnet2/test/parse.py +++ b/ACL_PyTorch/contrib/audio/rawnet2/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 - print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 + print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) diff --git a/ACL_PyTorch/contrib/audio/tdnn/LICENSE b/ACL_PyTorch/contrib/audio/tdnn/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/audio/tdnn/LICENSE +++ b/ACL_PyTorch/contrib/audio/tdnn/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/audio/tdnn/ReadMe.md b/ACL_PyTorch/contrib/audio/tdnn/ReadMe.md index 4ee27e8c1136c62145ace0b59b84ac8b43ed39e8..95f84433d2494ac8294e0dc04c48de9fd72c51c8 100644 --- a/ACL_PyTorch/contrib/audio/tdnn/ReadMe.md +++ b/ACL_PyTorch/contrib/audio/tdnn/ReadMe.md @@ -1,276 +1,276 @@ -# Tdnn Onnx模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理精度统计](#61-离线推理精度统计) - - [6.2 精度对比](#62-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - [7.2 T4性能数据](#72-T4性能数据) - - [7.3 性能对比](#73-性能对比) - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -华为npu模型训练组依据客户给的模型进行训练所得,无参考论文 - -### 1.2 代码地址 -[Tdnn代码]https://gitee.com/ascend/modelzoo.git) -branch:master -commit_id= -code_path= - - - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 -``` -pytorch = 昇腾1.5.0 -torchaudio = 0.5.0 -``` -### 2.2 python第三方库 -``` -speechbrain = 0.5.9 -onnx == 1.7.0 -onnxruntime-gpu == 1.8.1 -sox == 14.4.0 -``` -1.gpu环境搭建 -在安装了Anaconda或Miniconda的gpu环境下,首先执行命令 -``` -conda create -n tdnn python==3.7 -``` -创建名为tdnn的虚拟环境,再执行命令 -``` -conda activate tdnn -``` -进入该环境,先后执行下面两条命令 -``` -pip3 install torch==1.5.0 -pip3 install torchaudio==0.5.0 -``` -安装pytorch及torchaudio,再前往 -``` -https://codeload.github.com/speechbrain/speechbrain/zip/refs/tags/v0.5.9 -``` -下载speechbrain 0.5.9源码包,解压并进入speechbrain项目根目录,在speechbrain/speechbrain文件夹下找到requirement.txt,删除torch和torchaudio对应行,然后执行 -``` -pip install -r requirements.txt -pip install --editable . -``` -完成speechbrain安装,接着执行 -``` -pip install onnx==1.7.0 -``` -安装ONNX,执行 -``` -pip install onnxruntime-gpu==1.7.0 -``` -安装onnxruntime-gpu - -2.npu环境搭建 -在安装了Anaconda或Miniconda的npu环境下,首先执行命令 -``` -conda create -n tdnn python==3.7 -``` -创建名为tdnn的虚拟环境,再执行命令 -``` -conda activate tdnn -``` -进入该环境,先执行 -``` -pip3 install torch==1.5.0 -``` -安装pytorch,再尝试执行 -``` -pip3 install torchaudio==0.5.0 -``` -安装torchaudio,确保安装成功后再前往 -``` -https://codeload.github.com/speechbrain/speechbrain/zip/refs/tags/v0.5.9 -``` -下载speechbrain 0.5.9源码包,解压并进入speechbrain项目根目录,在speechbrain/speechbrain文件夹下找到requirement.txt,删除torch和torchaudio对应行,然后执行 -``` -pip install -r requirements.txt -pip install --editable . -``` -完成speechbrain安装 - -**说明:** -> 如果torchaudio安装失败,或者安装之后出现读取.flac文件报错的情况, -> 请前往https://e.gitee.com/HUAWEI-ASCEND/notifications/infos?issue=I48AZM -> 按步骤完成sox 14.4.0和torchaudio 0.5.0安装,再安装speechbrain - -## 3 模型转换 - -本模型基于开源框架PyTorch训练的TDNN模型进行转换。 -首先使用PyTorch将模型权重文件tdnn.pth转换为tdnn.onnx文件,再使用ATC工具将tdnn.onnx文件转为tdnn.om文件。 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 -以下步骤均在gpu环境完成。 -1.转换前的代码处理 -在上一步安装的speechbrain文件夹中,进入文件夹speechbrain/nnet,找到CNN.py文件,将第349行修改为 -``` -padding_mode='constant' -``` -再进入文件夹speechbrain/pretrained,用本仓库的interfaces.py替换该目录下的同名文件 - -2.获取pth权重文件 -权重文件由华为npu模型训练组通过训练TDNN模型得到。 -在speechbrain/templates/speaker_id目录下新建文件夹best_model,将训练保存的模型文件及本仓库提供的hyperparams.yaml文件一并放到best_model。 -best_model文件夹下应包含以下文件: -``` -classifier.ckpt -hyperparams.yaml -embedding_model.ckpt -``` - -3.生成onnx模型文件 -将Tdnn_pth2onnx.py脚本放到speechbrain/templates/speaker_id目录下,并在该目录下执行 -``` -python Tdnn_pth2onnx.py -``` -运行成功后,该目录下将生成tdnn.onnx文件 - - **说明:** ->注意目前ATC支持的onnx算子版本为11 - - -### 3.2 onnx转om模型 - -以下步骤在npu环境进行。 -1.生成om模型文件 -将atc.sh脚本放到speechbrain/templates/speaker_id目录下,并在该目录下执行 -``` -bash atc.sh tdnn.onnx tdnn -``` -运行成功后,将生成tdnn.om模型 - - - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -用户将自行获取的数据集上传到speechbrain/templates/speaker_id目录 - -### 4.2 数据集预处理 -进入speechbrain/templates/speaker_id目录,将mini_librispeech_prepare.py文件的第174行代码random.shuffle(wav_list)注释掉,然后在该目录下执行 -``` -python Tdnn_preprocess.py -``` -预处理后的数据集在新生成的目录mini_librispeech_test_bin中 -### 4.3 生成数据集信息文件 -上一步的数据集预处理会同步生成一个文件mini_librispeech_test.info,该文件即数据集信息文件 - - - -## 5 离线推理 -1.设置离线推理环境 -将acl_net.py, pyacl_infer.py, om_infer.sh三个文件放到speechbrain/templates/speaker_id目录下 -2.执行pyacl离线推理 -在speechbrain/templates/speaker_id目录下执行 -``` -bash om_infer.sh -``` -推理结果将会输出到result目录下 - - - -## 6 精度对比 -- **[离线推理精度](#61-离线推理精度)** -- **[精度对比](#62-精度对比)** - -### 6.1 离线推理精度统计 - -将Tdnn_postprocess.py文件放到speechbrain/templates/speaker_id目录下,并在该目录下执行 -``` -python Tdnn_postprocess.py -``` -精度统计结果将直接输出到控制台 - -### 6.2 精度对比 -pth模型精度99.10%,om模型精度98.69%,模型转换后精度损失不超过1% - **精度调试:** - ->模型转换后精度损失不超过1%,精度达标,故不需要进行精度调试 - - - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** -- **[T4性能数据](#72-T4性能数据)** -- **[性能对比](#73-性能对比)** - -### 7.1 npu性能数据 -该模型不支持benchmark推理,故使用pyacl离线推理获取npu性能数据,npu性能数据为 -``` -average pure infer time(ms):10.24 -``` -Interface throughputRate: 1000/10.24 = 97.37 -310单卡吞吐率:1000/10.54*16 = 1562.50 fps - -### 7.2 T4性能数据 -1.搭建环境 -在T4服务器搭建onnx模型推理环境,然后新建test文件夹,将下列文件上传至该文件夹 -``` -tdnn.onnx文件 -Tdnn_onnx_infer.py文件 -speechbrain/templates/speaker_id目录下的mini_librispeech_test.info文件 -speechbrain/templates/speaker_id目录下的mini_librispeech_bin文件夹及其全部文件 -``` -2.执行在线推理 -在test目录下执行 -``` -python Tdnn_onnx_infer.py -``` -性能数据将会输出到gpu_result目录下 -T4性能基线数据为 -``` -average pure infer time(ms): 12.98 -``` -T4单卡吞吐率:1000/12.98*16 = 1232.67 fps - -### 7.3 性能对比 -单卡吞吐率 -``` -npu-310:1562.50 fps -gpu-t4 :1232.67 fps -``` -310性能高于T4性能,性能达标 - - **性能优化:** ->该模型性能优于T4,不用进行优化 +# Tdnn Onnx模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理精度统计](#61-离线推理精度统计) + - [6.2 精度对比](#62-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + - [7.2 T4性能数据](#72-T4性能数据) + - [7.3 性能对比](#73-性能对比) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +华为npu模型训练组依据客户给的模型进行训练所得,无参考论文 + +### 1.2 代码地址 +[Tdnn代码]https://gitee.com/ascend/modelzoo.git) +branch:master +commit_id= +code_path= + + + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +pytorch = 昇腾1.5.0 +torchaudio = 0.5.0 +``` +### 2.2 python第三方库 +``` +speechbrain = 0.5.9 +onnx == 1.7.0 +onnxruntime-gpu == 1.8.1 +sox == 14.4.0 +``` +1.gpu环境搭建 +在安装了Anaconda或Miniconda的gpu环境下,首先执行命令 +``` +conda create -n tdnn python==3.7 +``` +创建名为tdnn的虚拟环境,再执行命令 +``` +conda activate tdnn +``` +进入该环境,先后执行下面两条命令 +``` +pip3 install torch==1.5.0 +pip3 install torchaudio==0.5.0 +``` +安装pytorch及torchaudio,再前往 +``` +https://codeload.github.com/speechbrain/speechbrain/zip/refs/tags/v0.5.9 +``` +下载speechbrain 0.5.9源码包,解压并进入speechbrain项目根目录,在speechbrain/speechbrain文件夹下找到requirement.txt,删除torch和torchaudio对应行,然后执行 +``` +pip install -r requirements.txt +pip install --editable . +``` +完成speechbrain安装,接着执行 +``` +pip install onnx==1.7.0 +``` +安装ONNX,执行 +``` +pip install onnxruntime-gpu==1.7.0 +``` +安装onnxruntime-gpu + +2.npu环境搭建 +在安装了Anaconda或Miniconda的npu环境下,首先执行命令 +``` +conda create -n tdnn python==3.7 +``` +创建名为tdnn的虚拟环境,再执行命令 +``` +conda activate tdnn +``` +进入该环境,先执行 +``` +pip3 install torch==1.5.0 +``` +安装pytorch,再尝试执行 +``` +pip3 install torchaudio==0.5.0 +``` +安装torchaudio,确保安装成功后再前往 +``` +https://codeload.github.com/speechbrain/speechbrain/zip/refs/tags/v0.5.9 +``` +下载speechbrain 0.5.9源码包,解压并进入speechbrain项目根目录,在speechbrain/speechbrain文件夹下找到requirement.txt,删除torch和torchaudio对应行,然后执行 +``` +pip install -r requirements.txt +pip install --editable . +``` +完成speechbrain安装 + +**说明:** +> 如果torchaudio安装失败,或者安装之后出现读取.flac文件报错的情况, +> 请前往https://e.gitee.com/HUAWEI-ASCEND/notifications/infos?issue=I48AZM +> 按步骤完成sox 14.4.0和torchaudio 0.5.0安装,再安装speechbrain + +## 3 模型转换 + +本模型基于开源框架PyTorch训练的TDNN模型进行转换。 +首先使用PyTorch将模型权重文件tdnn.pth转换为tdnn.onnx文件,再使用ATC工具将tdnn.onnx文件转为tdnn.om文件。 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 +以下步骤均在gpu环境完成。 +1.转换前的代码处理 +在上一步安装的speechbrain文件夹中,进入文件夹speechbrain/nnet,找到CNN.py文件,将第349行修改为 +``` +padding_mode='constant' +``` +再进入文件夹speechbrain/pretrained,用本仓库的interfaces.py替换该目录下的同名文件 + +2.获取pth权重文件 +权重文件由华为npu模型训练组通过训练TDNN模型得到。 +在speechbrain/templates/speaker_id目录下新建文件夹best_model,将训练保存的模型文件及本仓库提供的hyperparams.yaml文件一并放到best_model。 +best_model文件夹下应包含以下文件: +``` +classifier.ckpt +hyperparams.yaml +embedding_model.ckpt +``` + +3.生成onnx模型文件 +将Tdnn_pth2onnx.py脚本放到speechbrain/templates/speaker_id目录下,并在该目录下执行 +``` +python Tdnn_pth2onnx.py +``` +运行成功后,该目录下将生成tdnn.onnx文件 + + **说明:** +>注意目前ATC支持的onnx算子版本为11 + + +### 3.2 onnx转om模型 + +以下步骤在npu环境进行。 +1.生成om模型文件 +将atc.sh脚本放到speechbrain/templates/speaker_id目录下,并在该目录下执行 +``` +bash atc.sh tdnn.onnx tdnn +``` +运行成功后,将生成tdnn.om模型 + + + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +用户将自行获取的数据集上传到speechbrain/templates/speaker_id目录 + +### 4.2 数据集预处理 +进入speechbrain/templates/speaker_id目录,将mini_librispeech_prepare.py文件的第174行代码random.shuffle(wav_list)注释掉,然后在该目录下执行 +``` +python Tdnn_preprocess.py +``` +预处理后的数据集在新生成的目录mini_librispeech_test_bin中 +### 4.3 生成数据集信息文件 +上一步的数据集预处理会同步生成一个文件mini_librispeech_test.info,该文件即数据集信息文件 + + + +## 5 离线推理 +1.设置离线推理环境 +将acl_net.py, pyacl_infer.py, om_infer.sh三个文件放到speechbrain/templates/speaker_id目录下 +2.执行pyacl离线推理 +在speechbrain/templates/speaker_id目录下执行 +``` +bash om_infer.sh +``` +推理结果将会输出到result目录下 + + + +## 6 精度对比 +- **[离线推理精度](#61-离线推理精度)** +- **[精度对比](#62-精度对比)** + +### 6.1 离线推理精度统计 + +将Tdnn_postprocess.py文件放到speechbrain/templates/speaker_id目录下,并在该目录下执行 +``` +python Tdnn_postprocess.py +``` +精度统计结果将直接输出到控制台 + +### 6.2 精度对比 +pth模型精度99.10%,om模型精度98.69%,模型转换后精度损失不超过1% + **精度调试:** + +>模型转换后精度损失不超过1%,精度达标,故不需要进行精度调试 + + + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** +- **[T4性能数据](#72-T4性能数据)** +- **[性能对比](#73-性能对比)** + +### 7.1 npu性能数据 +该模型不支持benchmark推理,故使用pyacl离线推理获取npu性能数据,npu性能数据为 +``` +average pure infer time(ms):10.24 +``` +Interface throughputRate: 1000/10.24 = 97.37 +310单卡吞吐率:1000/10.54*16 = 1562.50 fps + +### 7.2 T4性能数据 +1.搭建环境 +在T4服务器搭建onnx模型推理环境,然后新建test文件夹,将下列文件上传至该文件夹 +``` +tdnn.onnx文件 +Tdnn_onnx_infer.py文件 +speechbrain/templates/speaker_id目录下的mini_librispeech_test.info文件 +speechbrain/templates/speaker_id目录下的mini_librispeech_bin文件夹及其全部文件 +``` +2.执行在线推理 +在test目录下执行 +``` +python Tdnn_onnx_infer.py +``` +性能数据将会输出到gpu_result目录下 +T4性能基线数据为 +``` +average pure infer time(ms): 12.98 +``` +T4单卡吞吐率:1000/12.98*16 = 1232.67 fps + +### 7.3 性能对比 +单卡吞吐率 +``` +npu-310:1562.50 fps +gpu-t4 :1232.67 fps +``` +310性能高于T4性能,性能达标 + + **性能优化:** +>该模型性能优于T4,不用进行优化 diff --git a/ACL_PyTorch/contrib/audio/tdnn/Tdnn_onnx_infer.py b/ACL_PyTorch/contrib/audio/tdnn/Tdnn_onnx_infer.py index 9e5bcbc80720bb24e81c6fb518c1758c1f7e83df..7b74337de0bd498bc371f8c1445262cfdae3876b 100644 --- a/ACL_PyTorch/contrib/audio/tdnn/Tdnn_onnx_infer.py +++ b/ACL_PyTorch/contrib/audio/tdnn/Tdnn_onnx_infer.py @@ -1,125 +1,125 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import time -import torch -import onnxruntime # WARNING: there must be onnxruntime-gpu only in the running environment ! -import torch.nn as nn -import numpy as np -from tqdm import tqdm -import datetime -import torchaudio - -# step 0: set the running settings here (mainly the file path) -'''-----------------------------------------------------------------------------------''' -model_path = 'tdnn.onnx' # path of the onnx model -input_info_file_path = 'mini_librispeech_test.info' # path of the input_info file -batchsize = 16 # the tested batchsize - -# path of the infer result ( actually the infer time ), create if not exists -infer_res_save_path = './gpu_result' -if not(os.path.exists(infer_res_save_path)): - os.makedirs(infer_res_save_path) - -# original 'MeasureTime' copied from acl_net.py, which is used in pyacl_infer.py -class MeasureTime(): - def __init__(self, measurements, key, cpu_run=True): - self.measurements = measurements - self.key = key - self.cpu_run = cpu_run - - def __enter__(self): - if not self.cpu_run: - torch.cuda.synchronize() - self.t0 = time.perf_counter_ns() - - def __exit__(self, exc_type, exc_value, exc_traceback): - if not self.cpu_run: - torch.cuda.synchronize() - self.measurements[self.key] = time.perf_counter_ns() - self.t0 -'''-----------------------------------------------------------------------------------''' - -# step 1: get the input file path according to the input_info file -'''-----------------------------------------------------------------------------------''' -input_file_path = {} -with open(input_info_file_path, 'rt', encoding='utf-8') as f_info: - line = f_info.readline() - while line: - line = line.rstrip('\n') - contents = line.split() - info = {'path': contents[1], 'shape': eval(contents[2])} - input_file_path.setdefault(contents[0], []).append(info) - line = f_info.readline() -'''-----------------------------------------------------------------------------------''' - -# step 2: perform infer for files listed in input_file_path -'''-----------------------------------------------------------------------------------''' -if __name__ == '__main__': - # step 2.1: set the counters - total_infer_time = 0 - total_infer_time_workspace = 0 - total_infer_num = 0 - workspace = 10 - measurements = {} - key = 'per_infer_time_ns' - dim_1 = 1800 - cpu_run = False - - # step 2.2: load the model to the onnx running session - # WARNING: there must be onnxruntime-gpu only in the running environment! - # if cpu and gpu exist at the same time, it will get wrong. - onnx_run_sess = onnxruntime.InferenceSession(model_path) - - # step 2.3: for each input file, load it and perform the infer - for key, values in tqdm(input_file_path.items()): - # step 2.3.1: load the input data - inputs = [] - dims = [] # dims and dims_info is actually unused here - for idx, value in enumerate(values): - x = np.fromfile(value['path'], dtype=np.float32).reshape(value['shape']) - inputs.append(x) - dims.extend(value['shape']) - dims_info = {'dimCount': len(dims), 'name': '', 'dims': dims} - inputs = torch.tensor(np.array(inputs).squeeze(axis = 0)) - pad = dim_1 - inputs.shape[1] - inputs = torch.nn.functional.pad(inputs, (0,0,0,pad,0,0), value=0).numpy() - - # step 2.3.2: perform the infer - with MeasureTime(measurements, key, cpu_run): - _ = onnx_run_sess.run(None, {onnx_run_sess.get_inputs()[0].name:inputs}) - total_infer_num += 1 - - # step 2.3.3: save the output => pass - - # step 2.3.4: calculate the time - total_infer_time += measurements[key] - if total_infer_num > workspace: - total_infer_time_workspace += measurements[key] - - # step 2.4: calculate the infer time needed - now = datetime.datetime.now() - print('[INFO] Infer time:') - msg = 'test at: ' + str(now) + '\n' + \ - 'total infer num: ' + str(total_infer_num) + '\n' + \ - 'total pure infer time(ms): ' + str(total_infer_time / 1000 / 1000) + '\n' + \ - 'average pure infer time(ms): ' + str(total_infer_time / total_infer_num / 1000 / 1000) + '\n' + \ - 'average pure infer time after workspace(ms): ' + str(abs( - total_infer_time_workspace / (total_infer_num - workspace) / 1000 / 1000)) + '\n' + '\n\n\n\n' - print(msg) - - result_txt='batch_' + str(batchsize) + '_infer_time.txt' - with open(os.path.join(infer_res_save_path, result_txt), 'a', encoding='utf-8') as f_infer_time: - f_infer_time.write(msg) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import time +import torch +import onnxruntime # WARNING: there must be onnxruntime-gpu only in the running environment ! +import torch.nn as nn +import numpy as np +from tqdm import tqdm +import datetime +import torchaudio + +# step 0: set the running settings here (mainly the file path) +'''-----------------------------------------------------------------------------------''' +model_path = 'tdnn.onnx' # path of the onnx model +input_info_file_path = 'mini_librispeech_test.info' # path of the input_info file +batchsize = 16 # the tested batchsize + +# path of the infer result ( actually the infer time ), create if not exists +infer_res_save_path = './gpu_result' +if not(os.path.exists(infer_res_save_path)): + os.makedirs(infer_res_save_path) + +# original 'MeasureTime' copied from acl_net.py, which is used in pyacl_infer.py +class MeasureTime(): + def __init__(self, measurements, key, cpu_run=True): + self.measurements = measurements + self.key = key + self.cpu_run = cpu_run + + def __enter__(self): + if not self.cpu_run: + torch.cuda.synchronize() + self.t0 = time.perf_counter_ns() + + def __exit__(self, exc_type, exc_value, exc_traceback): + if not self.cpu_run: + torch.cuda.synchronize() + self.measurements[self.key] = time.perf_counter_ns() - self.t0 +'''-----------------------------------------------------------------------------------''' + +# step 1: get the input file path according to the input_info file +'''-----------------------------------------------------------------------------------''' +input_file_path = {} +with open(input_info_file_path, 'rt', encoding='utf-8') as f_info: + line = f_info.readline() + while line: + line = line.rstrip('\n') + contents = line.split() + info = {'path': contents[1], 'shape': eval(contents[2])} + input_file_path.setdefault(contents[0], []).append(info) + line = f_info.readline() +'''-----------------------------------------------------------------------------------''' + +# step 2: perform infer for files listed in input_file_path +'''-----------------------------------------------------------------------------------''' +if __name__ == '__main__': + # step 2.1: set the counters + total_infer_time = 0 + total_infer_time_workspace = 0 + total_infer_num = 0 + workspace = 10 + measurements = {} + key = 'per_infer_time_ns' + dim_1 = 1800 + cpu_run = False + + # step 2.2: load the model to the onnx running session + # WARNING: there must be onnxruntime-gpu only in the running environment! + # if cpu and gpu exist at the same time, it will get wrong. + onnx_run_sess = onnxruntime.InferenceSession(model_path) + + # step 2.3: for each input file, load it and perform the infer + for key, values in tqdm(input_file_path.items()): + # step 2.3.1: load the input data + inputs = [] + dims = [] # dims and dims_info is actually unused here + for idx, value in enumerate(values): + x = np.fromfile(value['path'], dtype=np.float32).reshape(value['shape']) + inputs.append(x) + dims.extend(value['shape']) + dims_info = {'dimCount': len(dims), 'name': '', 'dims': dims} + inputs = torch.tensor(np.array(inputs).squeeze(axis = 0)) + pad = dim_1 - inputs.shape[1] + inputs = torch.nn.functional.pad(inputs, (0,0,0,pad,0,0), value=0).numpy() + + # step 2.3.2: perform the infer + with MeasureTime(measurements, key, cpu_run): + _ = onnx_run_sess.run(None, {onnx_run_sess.get_inputs()[0].name:inputs}) + total_infer_num += 1 + + # step 2.3.3: save the output => pass + + # step 2.3.4: calculate the time + total_infer_time += measurements[key] + if total_infer_num > workspace: + total_infer_time_workspace += measurements[key] + + # step 2.4: calculate the infer time needed + now = datetime.datetime.now() + print('[INFO] Infer time:') + msg = 'test at: ' + str(now) + '\n' + \ + 'total infer num: ' + str(total_infer_num) + '\n' + \ + 'total pure infer time(ms): ' + str(total_infer_time / 1000 / 1000) + '\n' + \ + 'average pure infer time(ms): ' + str(total_infer_time / total_infer_num / 1000 / 1000) + '\n' + \ + 'average pure infer time after workspace(ms): ' + str(abs( + total_infer_time_workspace / (total_infer_num - workspace) / 1000 / 1000)) + '\n' + '\n\n\n\n' + print(msg) + + result_txt='batch_' + str(batchsize) + '_infer_time.txt' + with open(os.path.join(infer_res_save_path, result_txt), 'a', encoding='utf-8') as f_infer_time: + f_infer_time.write(msg) '''-----------------------------------------------------------------------------------''' \ No newline at end of file diff --git a/ACL_PyTorch/contrib/audio/tdnn/Tdnn_postprocess.py b/ACL_PyTorch/contrib/audio/tdnn/Tdnn_postprocess.py index 027a48319704a0cca294ab879d01b3c37b0674f9..411a53eeefcd2a320ff6785389f61997f1b2ad78 100644 --- a/ACL_PyTorch/contrib/audio/tdnn/Tdnn_postprocess.py +++ b/ACL_PyTorch/contrib/audio/tdnn/Tdnn_postprocess.py @@ -1,58 +1,58 @@ -# -*- coding: utf-8 -*- -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import re -import argparse -import numpy as np -label = {0:'3526', 1:'7312', 2:'1088', 3:'32', 4:'460', 5:'7859', 6:'118', 7:'6848', 8:'8629', 9:'163', 10:'2416', 11:'3947', 12:'332', 13:'19', 14:'6272', 15:'7367', 16:'1898', 17:'3664', 18:'2136', 19:'4640', 20:'1867', 21:'1970', 22:'4680', 23:'226', 24:'5789', 25:'3242', 26:'667', 27:'1737'} - -if __name__ == '__main__': - ''' - 参数说明: - --data_info: 数据集信息 - --result_dir: 二进制推理结果目录 - ''' - - # arg parser - parser = argparse.ArgumentParser() - parser.add_argument('--data_info', default='mini_librispeech_test.info') - parser.add_argument('--result_dir', default='result') - - opt = parser.parse_args() - error = 0 - total = 0 - - with open('mini_librispeech_test.info', 'r') as f: - for line in f.readlines(): - # line format example - # 0 mini_librispeech_test_bin/4680-16042-0024.bin (1,1600,23) - split = line.split(' ') - index = split[0] - input_file = split[1] - target = re.search('/(\d*)-', input_file).group()[1:-1] - - # output result/index.0.bin => index range from 0 to 152 - output_file='result/'+index+'.0.bin' - - - output = np.fromfile(output_file, np.float32) - res = np.argmax(output) - print('Predicted:', label[res], 'Target:', target) - total += 1 - if label[res] != target: - error += 1 - accuracy = float(total - error) / total * 100 - print('\nClassification Accuracy: {:.2f}%\n'.format(accuracy)) +# -*- coding: utf-8 -*- +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import re +import argparse +import numpy as np +label = {0:'3526', 1:'7312', 2:'1088', 3:'32', 4:'460', 5:'7859', 6:'118', 7:'6848', 8:'8629', 9:'163', 10:'2416', 11:'3947', 12:'332', 13:'19', 14:'6272', 15:'7367', 16:'1898', 17:'3664', 18:'2136', 19:'4640', 20:'1867', 21:'1970', 22:'4680', 23:'226', 24:'5789', 25:'3242', 26:'667', 27:'1737'} + +if __name__ == '__main__': + ''' + 参数说明: + --data_info: 数据集信息 + --result_dir: 二进制推理结果目录 + ''' + + # arg parser + parser = argparse.ArgumentParser() + parser.add_argument('--data_info', default='mini_librispeech_test.info') + parser.add_argument('--result_dir', default='result') + + opt = parser.parse_args() + error = 0 + total = 0 + + with open('mini_librispeech_test.info', 'r') as f: + for line in f.readlines(): + # line format example + # 0 mini_librispeech_test_bin/4680-16042-0024.bin (1,1600,23) + split = line.split(' ') + index = split[0] + input_file = split[1] + target = re.search('/(\d*)-', input_file).group()[1:-1] + + # output result/index.0.bin => index range from 0 to 152 + output_file='result/'+index+'.0.bin' + + + output = np.fromfile(output_file, np.float32) + res = np.argmax(output) + print('Predicted:', label[res], 'Target:', target) + total += 1 + if label[res] != target: + error += 1 + accuracy = float(total - error) / total * 100 + print('\nClassification Accuracy: {:.2f}%\n'.format(accuracy)) diff --git a/ACL_PyTorch/contrib/audio/tdnn/Tdnn_preprocess.py b/ACL_PyTorch/contrib/audio/tdnn/Tdnn_preprocess.py index dcaa76a0e84e9ad2a27781d71f371cbd4b478d57..855ec5fa537a458e96f77d43a7915a34283a0655 100644 --- a/ACL_PyTorch/contrib/audio/tdnn/Tdnn_preprocess.py +++ b/ACL_PyTorch/contrib/audio/tdnn/Tdnn_preprocess.py @@ -1,52 +1,52 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import json -import torchaudio -import torch.nn.functional as F -from speechbrain.pretrained import EncoderClassifier -from mini_librispeech_prepare import prepare_mini_librispeech - -prepare_mini_librispeech(data_folder='data', save_json_train='train.json', save_json_valid='valid.json', - save_json_test='test.json', split_ratio=[0, 0, 100]) - -if not os.path.exists('mini_librispeech_test_bin'): - os.makedirs('mini_librispeech_test_bin') - -file = open('mini_librispeech_test.info', 'w') -classifier = EncoderClassifier.from_hparams(source='best_model', savedir='best_model') - -with open('test.json', 'r') as f: - data_info = json.load(f) - i = 0 - - for key, value in data_info.items(): - wav_file = 'data' + value['wav'][11:] # prefix length 11 - signal, fs = torchaudio.load(wav_file) - feats = classifier.extract_feats(signal) - # pad signal - pad = (feats.shape[1] // 100 + 1) * 100 - feats.shape[1] - feats = F.pad(feats, (0,0,0,pad,0,0), value=0) - - # dump bin file - output = 'mini_librispeech_test_bin/' + value['wav'].split('/')[-1][:-4] + 'bin' - feats.numpy().tofile(output) - # write shape info - file.write(str(i) + ' ' + output + ' (' + str(feats.shape[0]) + ',' + str(feats.shape[1]) + ',' + str(feats.shape[2]) + ')') - file.write('\n') - i += 1 - - print('data preprocess done') +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import json +import torchaudio +import torch.nn.functional as F +from speechbrain.pretrained import EncoderClassifier +from mini_librispeech_prepare import prepare_mini_librispeech + +prepare_mini_librispeech(data_folder='data', save_json_train='train.json', save_json_valid='valid.json', + save_json_test='test.json', split_ratio=[0, 0, 100]) + +if not os.path.exists('mini_librispeech_test_bin'): + os.makedirs('mini_librispeech_test_bin') + +file = open('mini_librispeech_test.info', 'w') +classifier = EncoderClassifier.from_hparams(source='best_model', savedir='best_model') + +with open('test.json', 'r') as f: + data_info = json.load(f) + i = 0 + + for key, value in data_info.items(): + wav_file = 'data' + value['wav'][11:] # prefix length 11 + signal, fs = torchaudio.load(wav_file) + feats = classifier.extract_feats(signal) + # pad signal + pad = (feats.shape[1] // 100 + 1) * 100 - feats.shape[1] + feats = F.pad(feats, (0,0,0,pad,0,0), value=0) + + # dump bin file + output = 'mini_librispeech_test_bin/' + value['wav'].split('/')[-1][:-4] + 'bin' + feats.numpy().tofile(output) + # write shape info + file.write(str(i) + ' ' + output + ' (' + str(feats.shape[0]) + ',' + str(feats.shape[1]) + ',' + str(feats.shape[2]) + ')') + file.write('\n') + i += 1 + + print('data preprocess done') file.close() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/audio/tdnn/Tdnn_pth2onnx.py b/ACL_PyTorch/contrib/audio/tdnn/Tdnn_pth2onnx.py index 4d6b3b31e4c019a1b3f84c33d651344cb58f5047..f9632d4ecd9c7c619cbe9ca44aa3cca6efb55a8d 100644 --- a/ACL_PyTorch/contrib/audio/tdnn/Tdnn_pth2onnx.py +++ b/ACL_PyTorch/contrib/audio/tdnn/Tdnn_pth2onnx.py @@ -1,44 +1,44 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import torchaudio -from speechbrain.pretrained.interfaces import EncoderClassifier - -classifier = EncoderClassifier.from_hparams(source='best_model', savedir='best_model') - -# Download Thai language sample from Omniglot -class Xvector(torch.nn.Module): - def __init__(self, model): - super().__init__() - self.classifier = model - - def forward(self, feats): - res = self.classifier.feats_classify(feats) - return res - -model = Xvector(classifier) -feats = torch.randn([1, 1800, 23]) - -torch.onnx.export( - model, - feats, - 'tdnn.onnx', - input_names=['feats'], - output_names=['output'], - export_params=True, - do_constant_folding=True, - verbose=True, - opset_version=11 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import torchaudio +from speechbrain.pretrained.interfaces import EncoderClassifier + +classifier = EncoderClassifier.from_hparams(source='best_model', savedir='best_model') + +# Download Thai language sample from Omniglot +class Xvector(torch.nn.Module): + def __init__(self, model): + super().__init__() + self.classifier = model + + def forward(self, feats): + res = self.classifier.feats_classify(feats) + return res + +model = Xvector(classifier) +feats = torch.randn([1, 1800, 23]) + +torch.onnx.export( + model, + feats, + 'tdnn.onnx', + input_names=['feats'], + output_names=['output'], + export_params=True, + do_constant_folding=True, + verbose=True, + opset_version=11 ) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/audio/tdnn/Tdnn_pyacl_infer.py b/ACL_PyTorch/contrib/audio/tdnn/Tdnn_pyacl_infer.py index fa36db8401ebb27d38477ee2655fef9860846e15..d488b0c10a14e7ada3a6fff092d8b66527475ab0 100644 --- a/ACL_PyTorch/contrib/audio/tdnn/Tdnn_pyacl_infer.py +++ b/ACL_PyTorch/contrib/audio/tdnn/Tdnn_pyacl_infer.py @@ -1,176 +1,176 @@ -# Copyright 2018 NVIDIA Corporation. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import acl -from acl_net import AclModel - - -import os -import shutil - - -import argparse -import numpy as np -from tqdm import tqdm - -DTYPE = { - 'float32': np.float32, - 'float64': np.float64, - 'int32': np.int32, - 'int64': np.int64 -} - -if __name__ == '__main__': - ''' - 参数说明: - --model_path:模型路径 - --device_id:npu id - --cpu_run:MeasureTime类的cpu_run参数,True or False - --sync_infer:推理方式: - True:同步推理 - False:异步推理 - --workspace:类似TensorRT `workspace`参数,计算平均推理时间时排除前n次推理 - --input_info_file_path:类似benchmark的bin_info文件 - --input_dtypes:模型输入的类型,用逗号分割(`DTYPE`变量) - e.g. 模型只有一个输入:--input_dtypes=float32 - e.g. 模型有多个输入:--input_dtypes=float32,float32,float32(需要和bin_info文件多输入排列一致) - --infer_res_save_path:推理结果保存目录 - --res_save_type:推理结果保存类型,bin或npy - - info文件说明: - 因为支持动态shape,相比于benchmark的info文件,需要多加一列shape信息,e.g. - ``` - 0 ./bert_bin/input_ids_0.bin (1,512) - 0 ./bert_bin/segment_ids_0.bin (1,512) - 0 ./bert_bin/input_mask_0.bin (1,512) - 1 ./bert_bin/input_ids_1.bin (1,512) - 1 ./bert_bin/segment_ids_1.bin (1,512) - 1 ./bert_bin/input_mask_1.bin (1,512) - ``` - - Using Example: - python3.7 pyacl_infer.py \ - --model_path=./bert_base_batch_1_sim_auto.om \ - --device_id=0 \ - --cpu_run=True \ - --sync_infer=True \ - --workspace=10 \ - --input_info_file_path=./input.info \ - --input_dtypes=int64,int64,int64 \ - --infer_res_save_path=./infer_res \ - --res_save_type=bin - ''' - - # 参数解析 - parser = argparse.ArgumentParser() - parser.add_argument('--model_path', required=True) - parser.add_argument('--device_id', required=True, type=int) - parser.add_argument('--cpu_run', required=True, choices=['True', 'False']) - parser.add_argument('--sync_infer', required=True, choices=['True', 'False']) - parser.add_argument('--workspace', required=True, type=int) - parser.add_argument('--input_info_file_path', required=True) - parser.add_argument('--input_dtypes', required=True) - parser.add_argument('--infer_res_save_path', required=True) - parser.add_argument('--res_save_type', required=True, choices=['bin', 'npy']) - opt = parser.parse_args() - - - # 创建模型 - measurements = {} - om_model = AclModel(device_id=opt.device_id, - model_path=opt.model_path, - sync_infer=eval(opt.sync_infer), - measurements=measurements, - key='per_infer_time_ns', - cpu_run=eval(opt.cpu_run)) - - - # 创建目录 - if os.path.exists(opt.infer_res_save_path): - shutil.rmtree(opt.infer_res_save_path) - os.makedirs(opt.infer_res_save_path) - - - # 读取info_file - inputs_info = {} - with open(opt.input_info_file_path, 'rt', encoding='utf-8') as f_info: - line = f_info.readline() - while line: - line = line.rstrip('\n') - contents = line.split() - info = {'path': contents[1], 'shape': eval(contents[2])} - inputs_info.setdefault(contents[0], []).append(info) - line = f_info.readline() - - - # 解析输入类型 - input_dtypes = opt.input_dtypes.split(',') - input_dtypes = list(map(lambda x: DTYPE[x], input_dtypes)) - - - # 读取文件推理 - total_infer_time = 0 - total_infer_time_workspace = 0 - total_infer_num = 0 - for key, values in tqdm(inputs_info.items()): - # 构造输入 - inputs = [] - dims = [] - for idx, value in enumerate(values): - x = np.fromfile(value['path'], dtype=input_dtypes[idx]).reshape(value['shape']) - inputs.append(x) - dims.extend(value['shape']) - dims_info = {'dimCount': len(dims), 'name': '', 'dims': dims} - - # 推理得到输出 - output = om_model(inputs, dims_info) - total_infer_num += 1 - - # 保存文件 - if opt.res_save_type == 'bin': - for idx, data in enumerate(output): - data.tofile(os.path.join(opt.infer_res_save_path, key + '.' + str(idx) + '.bin')) - else: - for idx, data in enumerate(output): - np.save(os.path.join(opt.infer_res_save_path, key + '.' + str(idx) + '.npy'), data) - - # 计算时间 - total_infer_time += measurements['per_infer_time_ns'] - if total_infer_num > opt.workspace: - total_infer_time_workspace += measurements['per_infer_time_ns'] - - # 推理时间 - print('[INFO] Infer time:') - msg = 'total infer num: ' + str(total_infer_num) + '\n' + \ - 'total pure infer time(ms): ' + str(total_infer_time / 1000 / 1000) + '\n' + \ - 'average pure infer time(ms): ' + str(total_infer_time / total_infer_num / 1000 / 1000) + '\n' + \ - 'average pure infer time after workspace(ms): ' + str(abs( - total_infer_time_workspace / (total_infer_num - opt.workspace) / 1000 / 1000)) + '\n' - print(msg) - with open(os.path.join(opt.infer_res_save_path, 'infer_time.txt'), 'wt', encoding='utf-8') as f_infer_time: - f_infer_time.write(msg) +# Copyright 2018 NVIDIA Corporation. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import acl +from acl_net import AclModel + + +import os +import shutil + + +import argparse +import numpy as np +from tqdm import tqdm + +DTYPE = { + 'float32': np.float32, + 'float64': np.float64, + 'int32': np.int32, + 'int64': np.int64 +} + +if __name__ == '__main__': + ''' + 参数说明: + --model_path:模型路径 + --device_id:npu id + --cpu_run:MeasureTime类的cpu_run参数,True or False + --sync_infer:推理方式: + True:同步推理 + False:异步推理 + --workspace:类似TensorRT `workspace`参数,计算平均推理时间时排除前n次推理 + --input_info_file_path:类似benchmark的bin_info文件 + --input_dtypes:模型输入的类型,用逗号分割(`DTYPE`变量) + e.g. 模型只有一个输入:--input_dtypes=float32 + e.g. 模型有多个输入:--input_dtypes=float32,float32,float32(需要和bin_info文件多输入排列一致) + --infer_res_save_path:推理结果保存目录 + --res_save_type:推理结果保存类型,bin或npy + + info文件说明: + 因为支持动态shape,相比于benchmark的info文件,需要多加一列shape信息,e.g. + ``` + 0 ./bert_bin/input_ids_0.bin (1,512) + 0 ./bert_bin/segment_ids_0.bin (1,512) + 0 ./bert_bin/input_mask_0.bin (1,512) + 1 ./bert_bin/input_ids_1.bin (1,512) + 1 ./bert_bin/segment_ids_1.bin (1,512) + 1 ./bert_bin/input_mask_1.bin (1,512) + ``` + + Using Example: + python3.7 pyacl_infer.py \ + --model_path=./bert_base_batch_1_sim_auto.om \ + --device_id=0 \ + --cpu_run=True \ + --sync_infer=True \ + --workspace=10 \ + --input_info_file_path=./input.info \ + --input_dtypes=int64,int64,int64 \ + --infer_res_save_path=./infer_res \ + --res_save_type=bin + ''' + + # 参数解析 + parser = argparse.ArgumentParser() + parser.add_argument('--model_path', required=True) + parser.add_argument('--device_id', required=True, type=int) + parser.add_argument('--cpu_run', required=True, choices=['True', 'False']) + parser.add_argument('--sync_infer', required=True, choices=['True', 'False']) + parser.add_argument('--workspace', required=True, type=int) + parser.add_argument('--input_info_file_path', required=True) + parser.add_argument('--input_dtypes', required=True) + parser.add_argument('--infer_res_save_path', required=True) + parser.add_argument('--res_save_type', required=True, choices=['bin', 'npy']) + opt = parser.parse_args() + + + # 创建模型 + measurements = {} + om_model = AclModel(device_id=opt.device_id, + model_path=opt.model_path, + sync_infer=eval(opt.sync_infer), + measurements=measurements, + key='per_infer_time_ns', + cpu_run=eval(opt.cpu_run)) + + + # 创建目录 + if os.path.exists(opt.infer_res_save_path): + shutil.rmtree(opt.infer_res_save_path) + os.makedirs(opt.infer_res_save_path) + + + # 读取info_file + inputs_info = {} + with open(opt.input_info_file_path, 'rt', encoding='utf-8') as f_info: + line = f_info.readline() + while line: + line = line.rstrip('\n') + contents = line.split() + info = {'path': contents[1], 'shape': eval(contents[2])} + inputs_info.setdefault(contents[0], []).append(info) + line = f_info.readline() + + + # 解析输入类型 + input_dtypes = opt.input_dtypes.split(',') + input_dtypes = list(map(lambda x: DTYPE[x], input_dtypes)) + + + # 读取文件推理 + total_infer_time = 0 + total_infer_time_workspace = 0 + total_infer_num = 0 + for key, values in tqdm(inputs_info.items()): + # 构造输入 + inputs = [] + dims = [] + for idx, value in enumerate(values): + x = np.fromfile(value['path'], dtype=input_dtypes[idx]).reshape(value['shape']) + inputs.append(x) + dims.extend(value['shape']) + dims_info = {'dimCount': len(dims), 'name': '', 'dims': dims} + + # 推理得到输出 + output = om_model(inputs, dims_info) + total_infer_num += 1 + + # 保存文件 + if opt.res_save_type == 'bin': + for idx, data in enumerate(output): + data.tofile(os.path.join(opt.infer_res_save_path, key + '.' + str(idx) + '.bin')) + else: + for idx, data in enumerate(output): + np.save(os.path.join(opt.infer_res_save_path, key + '.' + str(idx) + '.npy'), data) + + # 计算时间 + total_infer_time += measurements['per_infer_time_ns'] + if total_infer_num > opt.workspace: + total_infer_time_workspace += measurements['per_infer_time_ns'] + + # 推理时间 + print('[INFO] Infer time:') + msg = 'total infer num: ' + str(total_infer_num) + '\n' + \ + 'total pure infer time(ms): ' + str(total_infer_time / 1000 / 1000) + '\n' + \ + 'average pure infer time(ms): ' + str(total_infer_time / total_infer_num / 1000 / 1000) + '\n' + \ + 'average pure infer time after workspace(ms): ' + str(abs( + total_infer_time_workspace / (total_infer_num - opt.workspace) / 1000 / 1000)) + '\n' + print(msg) + with open(os.path.join(opt.infer_res_save_path, 'infer_time.txt'), 'wt', encoding='utf-8') as f_infer_time: + f_infer_time.write(msg) diff --git a/ACL_PyTorch/contrib/audio/tdnn/acl_net.py b/ACL_PyTorch/contrib/audio/tdnn/acl_net.py index 54aeed007cb088c032740f8a6459d734b8320abd..f62098f69ca0449b3214c7ccc9ba64141cb9a6c2 100644 --- a/ACL_PyTorch/contrib/audio/tdnn/acl_net.py +++ b/ACL_PyTorch/contrib/audio/tdnn/acl_net.py @@ -1,289 +1,289 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import acl -import functools -import numpy as np -import torch -import time - -# error code -ACL_ERROR_NONE = 0 - -# rule for memory copy -ACL_MEMCPY_HOST_TO_HOST = 0 -ACL_MEMCPY_HOST_TO_DEVICE = 1 -ACL_MEMCPY_DEVICE_TO_HOST = 2 -ACL_MEMCPY_DEVICE_TO_DEVICE = 3 - -# dtype -ACL_DTYPE = { - 0: 'float32', - 1: 'float16', - 2: 'int8', - 3: 'int32', - 4: 'uint8', - 6: 'int16', - 7: 'uint16', - 8: 'uint32', - 9: 'int64', - 10: 'uint64', - 11: 'float64', - 12: 'bool', -} - - -def check_ret(message, ret): - if ret != ACL_ERROR_NONE: - raise Exception(f"{message} failed ret={ret}") - - -class MeasureTime(): - def __init__(self, measurements, key, cpu_run=True): - self.measurements = measurements - self.key = key - self.cpu_run = cpu_run - - def __enter__(self): - if not self.cpu_run: - torch.cuda.synchronize() - self.t0 = time.perf_counter_ns() - - def __exit__(self, exc_type, exc_value, exc_traceback): - if not self.cpu_run: - torch.cuda.synchronize() - self.measurements[self.key] = time.perf_counter_ns() - self.t0 - - -class AclModel(object): - def __init__(self, device_id, model_path, sync_infer, measurements, key, cpu_run): - self.device_id = device_id - self.sync_infer = sync_infer - self.out_bufs_ptr = [] - self.output_sizes = [] - self.input_sizes = [] - self.input_bufs_ptr = [] - - self.measurements = measurements - self.key = key - self.cpu_run = cpu_run - - ret = acl.init() - check_ret("acl.init", ret) - ret = acl.rt.set_device(self.device_id) - check_ret("acl.rt.set_device", ret) - self.context, ret = acl.rt.create_context(self.device_id) - check_ret("acl.rt.create_context", ret) - self.model_id, ret = acl.mdl.load_from_file(model_path) - check_ret("acl.mdl.load_from_file", ret) - - self.model_desc = acl.mdl.create_desc() - assert self.model_desc is not None - acl.mdl.get_desc(self.model_desc, self.model_id) - self.dataset_in = acl.mdl.create_dataset() - assert self.dataset_in is not None - self.dataset_out = acl.mdl.create_dataset() - assert self.dataset_out is not None - self.in_size, self.out_size = 0, 0 - self.stm, ret = acl.rt.create_stream() - assert ret == 0 - - self.desc_init() - self.dataset_init() - - def __call__(self, ori_data, dim): - return self.forward(ori_data, dim) - - def __del__(self): - # unload model - if self.model_id: - ret = acl.mdl.unload(self.model_id) - assert ret == 0 - - # destroy model desc - ret = acl.mdl.destroy_desc(self.model_desc) - assert ret == 0 - - self.destroy_data_set(self.dataset_in) - self.destroy_data_set(self.dataset_out) - - # destroy input/output tensor - for i in range(len(self.input_bufs_ptr)): - acl.rt.free(self.input_bufs_ptr[i]["buffer"]) - self.input_bufs_ptr[i] = None - - for i in range(len(self.out_bufs_ptr)): - acl.rt.free(self.out_bufs_ptr[i]["buffer"]) - self.out_bufs_ptr[i] = None - - ret = acl.rt.destroy_stream(self.stm) - assert ret == 0 - - def desc_init(self): - tensor_size = acl.mdl.get_num_inputs(self.model_desc) - if not tensor_size: - raise Exception("get_num_inputs failed") - self.in_size = tensor_size - - for i in range(tensor_size): - size = acl.mdl.get_input_size_by_index(self.model_desc, i) - data, ret = acl.rt.malloc(size, 0) - assert ret == 0 - - self.input_bufs_ptr.append({'size': size, 'buffer': data}) - self.input_sizes.append(size) - - tensor_size = acl.mdl.get_num_outputs(self.model_desc) - self.out_size = tensor_size - for i in range(tensor_size): - dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) - assert ret == 0 - size = acl.mdl.get_output_size_by_index(self.model_desc, i) - - data, ret = acl.rt.malloc(size, 0) - assert ret == 0 - - self.output_sizes.append(size) - self.out_bufs_ptr.append({'size': size, 'buffer': data}) - - def dataset_init(self): - self.create_data_set(self.dataset_in, self.input_bufs_ptr, self.input_sizes) - self.create_data_set(self.dataset_out, self.out_bufs_ptr, self.output_sizes) - - def create_data_set(self, dataset, bufs_ptr_list, size_list): - # create dataset buffer then add to dataset - for i in range(len(size_list)): - buffer = acl.create_data_buffer(bufs_ptr_list[i]["buffer"], size_list[i]) - if not buffer: - self.destroy_data_set(dataset) - raise Exception("create_data_buffer failed") - - # add to dataset - _, ret = acl.mdl.add_dataset_buffer(dataset, buffer) - if ret != 0: - self.destroy_data_set(dataset) - raise Exception("add_dataset_buffer failed, ret = {}".format(ret)) - - return dataset - - def destroy_data_set(self, dataset): - data_buf_num = acl.mdl.get_dataset_num_buffers(dataset) - for i in range(data_buf_num): - # get data buffer by index - data_buf = acl.mdl.get_dataset_buffer(dataset, i) - if data_buf is not None: - acl.destroy_data_buffer(data_buf) - - acl.mdl.destroy_dataset(dataset) - - def copy_data_to_device(self, data): - for i in range(len(data)): - if 'bytes_to_ptr' in dir(acl.util): - ptr = acl.util.bytes_to_ptr(data[i]["buffer"].tobytes()) - else: - ptr, np = acl.util.numpy_contiguous_to_ptr(data[i]["buffer"]) - acl.rt.memcpy(self.input_bufs_ptr[i]["buffer"], data[i]["size"], ptr, - data[i]["size"], ACL_MEMCPY_HOST_TO_DEVICE) - - def copy_output_to_host(self): - output_data = [] - for i in range(len(self.out_bufs_ptr)): - temp = dict() - temp["size"] = self.out_bufs_ptr[i]["size"] - temp["buffer"], ret = acl.rt.malloc_host(temp["size"]) - output_data.append(temp) - acl.rt.memcpy(temp["buffer"], temp["size"], self.out_bufs_ptr[i]["buffer"], - temp["size"], ACL_MEMCPY_DEVICE_TO_HOST) - - return output_data - - def model_exe(self): - with MeasureTime(self.measurements, self.key, self.cpu_run): - ret = acl.mdl.execute(self.model_id, self.dataset_in, self.dataset_out) - assert ret == 0 - output_data = self.copy_output_to_host() - dataset = [] - for i in range(len(output_data)): - dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) - data_shape = dims.get("dims") - data_type = acl.mdl.get_output_data_type(self.model_desc, i) - data_len = functools.reduce(lambda x, y: x * y, data_shape) - ftype = np.dtype(ACL_DTYPE.get(data_type)) - - size = output_data[i]["size"] - ptr = output_data[i]["buffer"] - if 'ptr_to_bytes' in dir(acl.util): - data = acl.util.ptr_to_bytes(ptr, size) - np_arr = np.frombuffer(data, dtype=ftype, count=data_len) - else: - data = acl.util.ptr_to_numpy(ptr, (size,), 1) - np_arr = np.frombuffer( - bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) - np_arr = np_arr.reshape(data_shape) - dataset.append(np_arr) - return dataset - - def model_exe_async(self): - with MeasureTime(self.measurements, self.key, self.cpu_run): - ret = acl.mdl.execute_async(self.model_id, self.dataset_in, self.dataset_out, self.stm) - assert ret == 0 - ret = acl.rt.synchronize_stream(self.stm) - assert ret == 0 - output_data = self.copy_output_to_host() - - dataset = [] - for i in range(len(output_data)): - dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) - # check_ret("acl.mdl.get_cur_output_dims", ret) - data_shape = dims.get("dims") - - data_type = acl.mdl.get_output_data_type(self.model_desc, i) - data_len = functools.reduce(lambda x, y: x * y, data_shape) - ftype = np.dtype(ACL_DTYPE.get(data_type)) - - size = output_data[i]["size"] - ptr = output_data[i]["buffer"] - if 'ptr_to_bytes' in dir(acl.util): - data = acl.util.ptr_to_bytes(ptr, size) - np_arr = np.frombuffer(data, dtype=ftype, count=data_len) - else: - data = acl.util.ptr_to_numpy(ptr, (size,), 1) - np_arr = np.frombuffer( - bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) - np_arr = np_arr.reshape(data_shape) - dataset.append(np_arr) - return dataset - - def model_exe_with_dynamic_dims(self, input_data, dims): - index, ret = acl.mdl.get_input_index_by_name(self.model_desc, 'ascend_mbatch_shape_data') - ret = acl.mdl.set_input_dynamic_dims(self.model_id, self.dataset_in, index, dims) - gear_count, ret = acl.mdl.get_input_dynamic_gear_count(self.model_desc, -1) - dims_out, ret = acl.mdl.get_input_dynamic_dims(self.model_desc, -1, gear_count) - self.copy_data_to_device(input_data) - if self.sync_infer is True: - res = self.model_exe() - else: - res = self.model_exe_async() - - return res - - def forward(self, input_data, dims): - input_data_dic = [] - for i in range(len(input_data)): - temp = {} - temp["size"] = input_data[i].size * input_data[i].itemsize - temp["buffer"] = input_data[i] - input_data_dic.append(temp) - result = self.model_exe_with_dynamic_dims(input_data_dic, dims) - return result +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import acl +import functools +import numpy as np +import torch +import time + +# error code +ACL_ERROR_NONE = 0 + +# rule for memory copy +ACL_MEMCPY_HOST_TO_HOST = 0 +ACL_MEMCPY_HOST_TO_DEVICE = 1 +ACL_MEMCPY_DEVICE_TO_HOST = 2 +ACL_MEMCPY_DEVICE_TO_DEVICE = 3 + +# dtype +ACL_DTYPE = { + 0: 'float32', + 1: 'float16', + 2: 'int8', + 3: 'int32', + 4: 'uint8', + 6: 'int16', + 7: 'uint16', + 8: 'uint32', + 9: 'int64', + 10: 'uint64', + 11: 'float64', + 12: 'bool', +} + + +def check_ret(message, ret): + if ret != ACL_ERROR_NONE: + raise Exception(f"{message} failed ret={ret}") + + +class MeasureTime(): + def __init__(self, measurements, key, cpu_run=True): + self.measurements = measurements + self.key = key + self.cpu_run = cpu_run + + def __enter__(self): + if not self.cpu_run: + torch.cuda.synchronize() + self.t0 = time.perf_counter_ns() + + def __exit__(self, exc_type, exc_value, exc_traceback): + if not self.cpu_run: + torch.cuda.synchronize() + self.measurements[self.key] = time.perf_counter_ns() - self.t0 + + +class AclModel(object): + def __init__(self, device_id, model_path, sync_infer, measurements, key, cpu_run): + self.device_id = device_id + self.sync_infer = sync_infer + self.out_bufs_ptr = [] + self.output_sizes = [] + self.input_sizes = [] + self.input_bufs_ptr = [] + + self.measurements = measurements + self.key = key + self.cpu_run = cpu_run + + ret = acl.init() + check_ret("acl.init", ret) + ret = acl.rt.set_device(self.device_id) + check_ret("acl.rt.set_device", ret) + self.context, ret = acl.rt.create_context(self.device_id) + check_ret("acl.rt.create_context", ret) + self.model_id, ret = acl.mdl.load_from_file(model_path) + check_ret("acl.mdl.load_from_file", ret) + + self.model_desc = acl.mdl.create_desc() + assert self.model_desc is not None + acl.mdl.get_desc(self.model_desc, self.model_id) + self.dataset_in = acl.mdl.create_dataset() + assert self.dataset_in is not None + self.dataset_out = acl.mdl.create_dataset() + assert self.dataset_out is not None + self.in_size, self.out_size = 0, 0 + self.stm, ret = acl.rt.create_stream() + assert ret == 0 + + self.desc_init() + self.dataset_init() + + def __call__(self, ori_data, dim): + return self.forward(ori_data, dim) + + def __del__(self): + # unload model + if self.model_id: + ret = acl.mdl.unload(self.model_id) + assert ret == 0 + + # destroy model desc + ret = acl.mdl.destroy_desc(self.model_desc) + assert ret == 0 + + self.destroy_data_set(self.dataset_in) + self.destroy_data_set(self.dataset_out) + + # destroy input/output tensor + for i in range(len(self.input_bufs_ptr)): + acl.rt.free(self.input_bufs_ptr[i]["buffer"]) + self.input_bufs_ptr[i] = None + + for i in range(len(self.out_bufs_ptr)): + acl.rt.free(self.out_bufs_ptr[i]["buffer"]) + self.out_bufs_ptr[i] = None + + ret = acl.rt.destroy_stream(self.stm) + assert ret == 0 + + def desc_init(self): + tensor_size = acl.mdl.get_num_inputs(self.model_desc) + if not tensor_size: + raise Exception("get_num_inputs failed") + self.in_size = tensor_size + + for i in range(tensor_size): + size = acl.mdl.get_input_size_by_index(self.model_desc, i) + data, ret = acl.rt.malloc(size, 0) + assert ret == 0 + + self.input_bufs_ptr.append({'size': size, 'buffer': data}) + self.input_sizes.append(size) + + tensor_size = acl.mdl.get_num_outputs(self.model_desc) + self.out_size = tensor_size + for i in range(tensor_size): + dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) + assert ret == 0 + size = acl.mdl.get_output_size_by_index(self.model_desc, i) + + data, ret = acl.rt.malloc(size, 0) + assert ret == 0 + + self.output_sizes.append(size) + self.out_bufs_ptr.append({'size': size, 'buffer': data}) + + def dataset_init(self): + self.create_data_set(self.dataset_in, self.input_bufs_ptr, self.input_sizes) + self.create_data_set(self.dataset_out, self.out_bufs_ptr, self.output_sizes) + + def create_data_set(self, dataset, bufs_ptr_list, size_list): + # create dataset buffer then add to dataset + for i in range(len(size_list)): + buffer = acl.create_data_buffer(bufs_ptr_list[i]["buffer"], size_list[i]) + if not buffer: + self.destroy_data_set(dataset) + raise Exception("create_data_buffer failed") + + # add to dataset + _, ret = acl.mdl.add_dataset_buffer(dataset, buffer) + if ret != 0: + self.destroy_data_set(dataset) + raise Exception("add_dataset_buffer failed, ret = {}".format(ret)) + + return dataset + + def destroy_data_set(self, dataset): + data_buf_num = acl.mdl.get_dataset_num_buffers(dataset) + for i in range(data_buf_num): + # get data buffer by index + data_buf = acl.mdl.get_dataset_buffer(dataset, i) + if data_buf is not None: + acl.destroy_data_buffer(data_buf) + + acl.mdl.destroy_dataset(dataset) + + def copy_data_to_device(self, data): + for i in range(len(data)): + if 'bytes_to_ptr' in dir(acl.util): + ptr = acl.util.bytes_to_ptr(data[i]["buffer"].tobytes()) + else: + ptr, np = acl.util.numpy_contiguous_to_ptr(data[i]["buffer"]) + acl.rt.memcpy(self.input_bufs_ptr[i]["buffer"], data[i]["size"], ptr, + data[i]["size"], ACL_MEMCPY_HOST_TO_DEVICE) + + def copy_output_to_host(self): + output_data = [] + for i in range(len(self.out_bufs_ptr)): + temp = dict() + temp["size"] = self.out_bufs_ptr[i]["size"] + temp["buffer"], ret = acl.rt.malloc_host(temp["size"]) + output_data.append(temp) + acl.rt.memcpy(temp["buffer"], temp["size"], self.out_bufs_ptr[i]["buffer"], + temp["size"], ACL_MEMCPY_DEVICE_TO_HOST) + + return output_data + + def model_exe(self): + with MeasureTime(self.measurements, self.key, self.cpu_run): + ret = acl.mdl.execute(self.model_id, self.dataset_in, self.dataset_out) + assert ret == 0 + output_data = self.copy_output_to_host() + dataset = [] + for i in range(len(output_data)): + dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) + data_shape = dims.get("dims") + data_type = acl.mdl.get_output_data_type(self.model_desc, i) + data_len = functools.reduce(lambda x, y: x * y, data_shape) + ftype = np.dtype(ACL_DTYPE.get(data_type)) + + size = output_data[i]["size"] + ptr = output_data[i]["buffer"] + if 'ptr_to_bytes' in dir(acl.util): + data = acl.util.ptr_to_bytes(ptr, size) + np_arr = np.frombuffer(data, dtype=ftype, count=data_len) + else: + data = acl.util.ptr_to_numpy(ptr, (size,), 1) + np_arr = np.frombuffer( + bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) + np_arr = np_arr.reshape(data_shape) + dataset.append(np_arr) + return dataset + + def model_exe_async(self): + with MeasureTime(self.measurements, self.key, self.cpu_run): + ret = acl.mdl.execute_async(self.model_id, self.dataset_in, self.dataset_out, self.stm) + assert ret == 0 + ret = acl.rt.synchronize_stream(self.stm) + assert ret == 0 + output_data = self.copy_output_to_host() + + dataset = [] + for i in range(len(output_data)): + dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) + # check_ret("acl.mdl.get_cur_output_dims", ret) + data_shape = dims.get("dims") + + data_type = acl.mdl.get_output_data_type(self.model_desc, i) + data_len = functools.reduce(lambda x, y: x * y, data_shape) + ftype = np.dtype(ACL_DTYPE.get(data_type)) + + size = output_data[i]["size"] + ptr = output_data[i]["buffer"] + if 'ptr_to_bytes' in dir(acl.util): + data = acl.util.ptr_to_bytes(ptr, size) + np_arr = np.frombuffer(data, dtype=ftype, count=data_len) + else: + data = acl.util.ptr_to_numpy(ptr, (size,), 1) + np_arr = np.frombuffer( + bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) + np_arr = np_arr.reshape(data_shape) + dataset.append(np_arr) + return dataset + + def model_exe_with_dynamic_dims(self, input_data, dims): + index, ret = acl.mdl.get_input_index_by_name(self.model_desc, 'ascend_mbatch_shape_data') + ret = acl.mdl.set_input_dynamic_dims(self.model_id, self.dataset_in, index, dims) + gear_count, ret = acl.mdl.get_input_dynamic_gear_count(self.model_desc, -1) + dims_out, ret = acl.mdl.get_input_dynamic_dims(self.model_desc, -1, gear_count) + self.copy_data_to_device(input_data) + if self.sync_infer is True: + res = self.model_exe() + else: + res = self.model_exe_async() + + return res + + def forward(self, input_data, dims): + input_data_dic = [] + for i in range(len(input_data)): + temp = {} + temp["size"] = input_data[i].size * input_data[i].itemsize + temp["buffer"] = input_data[i] + input_data_dic.append(temp) + result = self.model_exe_with_dynamic_dims(input_data_dic, dims) + return result diff --git a/ACL_PyTorch/contrib/audio/tdnn/atc.sh b/ACL_PyTorch/contrib/audio/tdnn/atc.sh index cede3be1b0165794da2b13e8b1d7c10196c7eafe..a2e925085516ccc447a5d65da86f89cf4331927f 100644 --- a/ACL_PyTorch/contrib/audio/tdnn/atc.sh +++ b/ACL_PyTorch/contrib/audio/tdnn/atc.sh @@ -1,9 +1,9 @@ -#!/bin/bash -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -#export DUMP_GE_GRAPH=2 - +#!/bin/bash +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +#export DUMP_GE_GRAPH=2 + atc --model=$1 --framework=5 --input_format=ND --input_shape="feats:1,-1,23" --dynamic_dims='200;300;400;500;600;700;800;900;1000;1100;1200;1300;1400;1500;1600;1700;1800' --output=$2 --soc_version=Ascend310 --log=info \ No newline at end of file diff --git a/ACL_PyTorch/contrib/audio/tdnn/hyperparams.yaml b/ACL_PyTorch/contrib/audio/tdnn/hyperparams.yaml index a24b5a03b29a7e195d2c3660d8e7848428dd7dee..0407ff5d223fd285d1334a57205b468414f30346 100644 --- a/ACL_PyTorch/contrib/audio/tdnn/hyperparams.yaml +++ b/ACL_PyTorch/contrib/audio/tdnn/hyperparams.yaml @@ -1,67 +1,67 @@ - - -# ################################# -# Basic inference parameters for speaker-id. We have first a network that -# computes some embeddings. On the top of that, we employ a classifier. -# -# Author: -# * Mirco Ravanelli 2021 -# ################################# - -# pretrain folders: -pretrained_path: best_model - - -# Model parameters -n_mels: 23 -sample_rate: 16000 -n_classes: 28 # In this case, we have 28 speakers -emb_dim: 512 # dimensionality of the embeddings - -# Feature extraction -compute_features: !new:speechbrain.lobes.features.Fbank - n_mels: !ref - -# Mean and std normalization of the input features -mean_var_norm: !new:speechbrain.processing.features.InputNormalization - norm_type: sentence - std_norm: False - -# To design a custom model, either just edit the simple CustomModel -# class that's listed here, or replace this `!new` call with a line -# pointing to a different file you've defined. -embedding_model: !new:custom_model.Xvector - in_channels: !ref - activation: !name:torch.nn.LeakyReLU - tdnn_blocks: 5 - tdnn_channels: [512, 512, 512, 512, 1500] - tdnn_kernel_sizes: [5, 3, 3, 1, 1] - tdnn_dilations: [1, 2, 3, 1, 1] - lin_neurons: !ref - -classifier: !new:custom_model.Classifier - input_shape: [null, null, !ref ] - activation: !name:torch.nn.LeakyReLU - lin_blocks: 1 - lin_neurons: !ref - out_neurons: !ref - -label_encoder: !new:speechbrain.dataio.encoder.CategoricalEncoder - -# Objects in "modules" dict will have their parameters moved to the correct -# device, as well as having train()/eval() called on them by the Brain class. -modules: - compute_features: !ref - embedding_model: !ref - classifier: !ref - mean_var_norm: !ref - -pretrainer: !new:speechbrain.utils.parameter_transfer.Pretrainer - loadables: - embedding_model: !ref - classifier: !ref - label_encoder: !ref - paths: - embedding_model: !ref /embedding_model.ckpt - classifier: !ref /classifier.ckpt - label_encoder: !ref /label_encoder.txt + + +# ################################# +# Basic inference parameters for speaker-id. We have first a network that +# computes some embeddings. On the top of that, we employ a classifier. +# +# Author: +# * Mirco Ravanelli 2021 +# ################################# + +# pretrain folders: +pretrained_path: best_model + + +# Model parameters +n_mels: 23 +sample_rate: 16000 +n_classes: 28 # In this case, we have 28 speakers +emb_dim: 512 # dimensionality of the embeddings + +# Feature extraction +compute_features: !new:speechbrain.lobes.features.Fbank + n_mels: !ref + +# Mean and std normalization of the input features +mean_var_norm: !new:speechbrain.processing.features.InputNormalization + norm_type: sentence + std_norm: False + +# To design a custom model, either just edit the simple CustomModel +# class that's listed here, or replace this `!new` call with a line +# pointing to a different file you've defined. +embedding_model: !new:custom_model.Xvector + in_channels: !ref + activation: !name:torch.nn.LeakyReLU + tdnn_blocks: 5 + tdnn_channels: [512, 512, 512, 512, 1500] + tdnn_kernel_sizes: [5, 3, 3, 1, 1] + tdnn_dilations: [1, 2, 3, 1, 1] + lin_neurons: !ref + +classifier: !new:custom_model.Classifier + input_shape: [null, null, !ref ] + activation: !name:torch.nn.LeakyReLU + lin_blocks: 1 + lin_neurons: !ref + out_neurons: !ref + +label_encoder: !new:speechbrain.dataio.encoder.CategoricalEncoder + +# Objects in "modules" dict will have their parameters moved to the correct +# device, as well as having train()/eval() called on them by the Brain class. +modules: + compute_features: !ref + embedding_model: !ref + classifier: !ref + mean_var_norm: !ref + +pretrainer: !new:speechbrain.utils.parameter_transfer.Pretrainer + loadables: + embedding_model: !ref + classifier: !ref + label_encoder: !ref + paths: + embedding_model: !ref /embedding_model.ckpt + classifier: !ref /classifier.ckpt + label_encoder: !ref /label_encoder.txt diff --git a/ACL_PyTorch/contrib/audio/tdnn/interfaces.py b/ACL_PyTorch/contrib/audio/tdnn/interfaces.py index ddbf99b74bd4cc5d562f675124be5cd3389ae430..ead6a0634d21dbf8aa4c62d2a6be8afda0abf3ef 100644 --- a/ACL_PyTorch/contrib/audio/tdnn/interfaces.py +++ b/ACL_PyTorch/contrib/audio/tdnn/interfaces.py @@ -1,958 +1,958 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Defines interfaces for simple inference with pretrained models - -Authors: - * Aku Rouhe 2021 - * Peter Plantinga 2021 - * Loren Lugosch 2020 - * Mirco Ravanelli 2020 - * Titouan Parcollet 2021 -""" -import torch -import torchaudio -from types import SimpleNamespace -from torch.nn import SyncBatchNorm -from torch.nn import DataParallel as DP -from hyperpyyaml import load_hyperpyyaml -from speechbrain.pretrained.fetching import fetch -from speechbrain.dataio.preprocess import AudioNormalizer -import torch.nn.functional as F -from torch.nn.parallel import DistributedDataParallel as DDP -from speechbrain.utils.data_utils import split_path -from speechbrain.utils.distributed import run_on_main - - -class Pretrained: - """Takes a trained model and makes predictions on new data. - - This is a base class which handles some common boilerplate. - It intentionally has an interface similar to ``Brain`` - these base - classes handle similar things. - - Subclasses of Pretrained should implement the actual logic of how - the pretrained system runs, and add methods with descriptive names - (e.g. transcribe_file() for ASR). - - Arguments - --------- - modules : dict of str:torch.nn.Module pairs - The Torch modules that make up the learned system. These can be treated - in special ways (put on the right device, frozen, etc.) - hparams : dict - Each key:value pair should consist of a string key and a hyperparameter - that is used within the overridden methods. These will - be accessible via an ``hparams`` attribute, using "dot" notation: - e.g., self.hparams.model(x). - run_opts : dict - Options parsed from command line. See ``speechbrain.parse_arguments()``. - List that are supported here: - * device - * data_parallel_count - * data_parallel_backend - * distributed_launch - * distributed_backend - * jit_module_keys - freeze_params : bool - To freeze (requires_grad=False) parameters or not. Normally in inference - you want to freeze the params. Also calls .eval() on all modules. - """ - - HPARAMS_NEEDED = [] - MODULES_NEEDED = [] - - def __init__( - self, modules=None, hparams=None, run_opts=None, freeze_params=True - ): - - # Arguments passed via the run opts dictionary. Set a limited - # number of these, since some don't apply to inference. - run_opt_defaults = { - "device": "cpu", - "data_parallel_count": -1, - "data_parallel_backend": False, - "distributed_launch": False, - "distributed_backend": "nccl", - "jit_module_keys": None, - } - for arg, default in run_opt_defaults.items(): - if run_opts is not None and arg in run_opts: - setattr(self, arg, run_opts[arg]) - else: - # If any arg from run_opt_defaults exist in hparams and - # not in command line args "run_opts" - if hparams is not None and arg in hparams: - setattr(self, arg, hparams[arg]) - else: - setattr(self, arg, default) - - # Put modules on the right device, accessible with dot notation - self.modules = torch.nn.ModuleDict(modules) - for mod in self.modules: - self.modules[mod].to(self.device) - - for mod in self.MODULES_NEEDED: - if mod not in modules: - raise ValueError(f"Need modules['{mod}']") - - # Check MODULES_NEEDED and HPARAMS_NEEDED and - # make hyperparams available with dot notation - if self.HPARAMS_NEEDED and hparams is None: - raise ValueError("Need to provide hparams dict.") - if hparams is not None: - # Also first check that all required params are found: - for hp in self.HPARAMS_NEEDED: - if hp not in hparams: - raise ValueError(f"Need hparams['{hp}']") - self.hparams = SimpleNamespace(**hparams) - - # Prepare modules for computation, e.g. jit - self._prepare_modules(freeze_params) - - # Audio normalization - self.audio_normalizer = hparams.get( - "audio_normalizer", AudioNormalizer() - ) - - def _prepare_modules(self, freeze_params): - """Prepare modules for computation, e.g. jit. - - Arguments - --------- - freeze_params : bool - Whether to freeze the parameters and call ``eval()``. - """ - - # Make jit-able - self._compile_jit() - self._wrap_distributed() - - # If we don't want to backprop, freeze the pretrained parameters - if freeze_params: - self.modules.eval() - for p in self.modules.parameters(): - p.requires_grad = False - - def load_audio(self, path, savedir="."): - """Load an audio file with this model"s input spec - - When using a speech model, it is important to use the same type of data, - as was used to train the model. This means for example using the same - sampling rate and number of channels. It is, however, possible to - convert a file from a higher sampling rate to a lower one (downsampling). - Similarly, it is simple to downmix a stereo file to mono. - The path can be a local path, a web url, or a link to a huggingface repo. - """ - source, fl = split_path(path) - path = fetch(fl, source=source, savedir=savedir) - signal, sr = torchaudio.load(path, channels_first=False) - return self.audio_normalizer(signal, sr) - - def _compile_jit(self): - """Compile requested modules with ``torch.jit.script``.""" - if self.jit_module_keys is None: - return - - for name in self.jit_module_keys: - if name not in self.modules: - raise ValueError( - "module " + name + " cannot be jit compiled because " - "it is not defined in your hparams file." - ) - module = torch.jit.script(self.modules[name]) - self.modules[name] = module.to(self.device) - - def _wrap_distributed(self): - """Wrap modules with distributed wrapper when requested.""" - if not self.distributed_launch and not self.data_parallel_backend: - return - elif self.distributed_launch: - for name, module in self.modules.items(): - if any(p.requires_grad for p in module.parameters()): - # for ddp, all module must run on same GPU - module = SyncBatchNorm.convert_sync_batchnorm(module) - module = DDP(module, device_ids=[self.device]) - self.modules[name] = module - else: - # data_parallel_backend - for name, module in self.modules.items(): - if any(p.requires_grad for p in module.parameters()): - # if distributed_count = -1 then use all gpus - # otherwise, specify the set of gpu to use - if self.data_parallel_count == -1: - module = DP(module) - else: - module = DP( - module, - [i for i in range(self.data_parallel_count)], - ) - self.modules[name] = module - - @classmethod - def from_hparams( - cls, - source, - hparams_file="hyperparams.yaml", - overrides={}, - savedir=None, - use_auth_token=False, - **kwargs, - ): - """Fetch and load based from outside source based on HyperPyYAML file - - The source can be a location on the filesystem or online/huggingface - - The hyperparams file should contain a "modules" key, which is a - dictionary of torch modules used for computation. - - The hyperparams file should contain a "pretrainer" key, which is a - speechbrain.utils.parameter_transfer.Pretrainer - - Arguments - --------- - source : str - The location to use for finding the model. See - ``speechbrain.pretrained.fetching.fetch`` for details. - hparams_file : str - The name of the hyperparameters file to use for constructing - the modules necessary for inference. Must contain two keys: - "modules" and "pretrainer", as described. - overrides : dict - Any changes to make to the hparams file when it is loaded. - savedir : str or Path - Where to put the pretraining material. If not given, will use - ./pretrained_models/-hash(source). - use_auth_token : bool (default: False) - If true Hugginface's auth_token will be used to load private models from the HuggingFace Hub, - default is False because majority of models are public. - """ - if savedir is None: - clsname = cls.__name__ - savedir = f"./pretrained_models/{clsname}-{hash(source)}" - hparams_local_path = fetch( - hparams_file, source, savedir, use_auth_token - ) - - # Load the modules: - with open(hparams_local_path) as fin: - hparams = load_hyperpyyaml(fin, overrides) - - # Pretraining: - pretrainer = hparams["pretrainer"] - pretrainer.set_collect_in(savedir) - # For distributed setups, have this here: - run_on_main(pretrainer.collect_files, kwargs={"default_source": source}) - # Load on the CPU. Later the params can be moved elsewhere by specifying - # run_opts={"device": ...} - pretrainer.load_collected(device="cpu") - - # Now return the system - return cls(hparams["modules"], hparams, **kwargs) - - -class EndToEndSLU(Pretrained): - """A end-to-end SLU model. - - The class can be used either to run only the encoder (encode()) to extract - features or to run the entire model (decode()) to map the speech to its semantics. - - Example - ------- - >>> from speechbrain.pretrained import EndToEndSLU - >>> tmpdir = getfixture("tmpdir") - >>> slu_model = EndToEndSLU.from_hparams( - ... source="speechbrain/slu-timers-and-such-direct-librispeech-asr", - ... savedir=tmpdir, - ... ) - >>> slu_model.decode_file("samples/audio_samples/example6.wav") - "{'intent': 'SimpleMath', 'slots': {'number1': 37.67, 'number2': 75.7, 'op': ' minus '}}" - """ - - HPARAMS_NEEDED = ["tokenizer", "asr_model_source"] - MODULES_NEEDED = [ - "slu_enc", - "beam_searcher", - ] - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.tokenizer = self.hparams.tokenizer - self.asr_model = EncoderDecoderASR.from_hparams( - source=self.hparams.asr_model_source, - run_opts={"device": self.device}, - ) - - def decode_file(self, path): - """Maps the given audio file to a string representing the - semantic dictionary for the utterance. - - Arguments - --------- - path : str - Path to audio file to decode. - - Returns - ------- - str - The predicted semantics. - """ - waveform = self.load_audio(path) - waveform = waveform.to(self.device) - # Fake a batch: - batch = waveform.unsqueeze(0) - rel_length = torch.tensor([1.0]) - predicted_words, predicted_tokens = self.decode_batch(batch, rel_length) - return predicted_words[0] - - def encode_batch(self, wavs, wav_lens): - """Encodes the input audio into a sequence of hidden states - - Arguments - --------- - wavs : torch.tensor - Batch of waveforms [batch, time, channels] or [batch, time] - depending on the model. - wav_lens : torch.tensor - Lengths of the waveforms relative to the longest one in the - batch, tensor of shape [batch]. The longest one should have - relative length 1.0 and others len(waveform) / max_length. - Used for ignoring padding. - - Returns - ------- - torch.tensor - The encoded batch - """ - wavs = wavs.float() - wavs, wav_lens = wavs.to(self.device), wav_lens.to(self.device) - with torch.no_grad(): - ASR_encoder_out = self.asr_model.encode_batch( - wavs.detach(), wav_lens - ) - encoder_out = self.modules.slu_enc(ASR_encoder_out) - return encoder_out - - def decode_batch(self, wavs, wav_lens): - """Maps the input audio to its semantics - - Arguments - --------- - wavs : torch.tensor - Batch of waveforms [batch, time, channels] or [batch, time] - depending on the model. - wav_lens : torch.tensor - Lengths of the waveforms relative to the longest one in the - batch, tensor of shape [batch]. The longest one should have - relative length 1.0 and others len(waveform) / max_length. - Used for ignoring padding. - - Returns - ------- - list - Each waveform in the batch decoded. - tensor - Each predicted token id. - """ - with torch.no_grad(): - wavs, wav_lens = wavs.to(self.device), wav_lens.to(self.device) - encoder_out = self.encode_batch(wavs, wav_lens) - predicted_tokens, scores = self.modules.beam_searcher( - encoder_out, wav_lens - ) - predicted_words = [ - self.tokenizer.decode_ids(token_seq) - for token_seq in predicted_tokens - ] - return predicted_words, predicted_tokens - - -class EncoderDecoderASR(Pretrained): - """A ready-to-use Encoder-Decoder ASR model - - The class can be used either to run only the encoder (encode()) to extract - features or to run the entire encoder-decoder model - (transcribe()) to transcribe speech. The given YAML must contains the fields - specified in the *_NEEDED[] lists. - - Example - ------- - >>> from speechbrain.pretrained import EncoderDecoderASR - >>> tmpdir = getfixture("tmpdir") - >>> asr_model = EncoderDecoderASR.from_hparams( - ... source="speechbrain/asr-crdnn-rnnlm-librispeech", - ... savedir=tmpdir, - ... ) - >>> asr_model.transcribe_file("samples/audio_samples/example2.flac") - "MY FATHER HAS REVEALED THE CULPRIT'S NAME" - """ - - HPARAMS_NEEDED = ["tokenizer"] - MODULES_NEEDED = [ - "encoder", - "decoder", - ] - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.tokenizer = self.hparams.tokenizer - - def transcribe_file(self, path): - """Transcribes the given audiofile into a sequence of words. - - Arguments - --------- - path : str - Path to audio file which to transcribe. - - Returns - ------- - str - The audiofile transcription produced by this ASR system. - """ - waveform = self.load_audio(path) - # Fake a batch: - batch = waveform.unsqueeze(0) - rel_length = torch.tensor([1.0]) - predicted_words, predicted_tokens = self.transcribe_batch( - batch, rel_length - ) - return predicted_words[0] - - def encode_batch(self, wavs, wav_lens): - """Encodes the input audio into a sequence of hidden states - - The waveforms should already be in the model's desired format. - You can call: - ``normalized = EncoderDecoderASR.normalizer(signal, sample_rate)`` - to get a correctly converted signal in most cases. - - Arguments - --------- - wavs : torch.tensor - Batch of waveforms [batch, time, channels] or [batch, time] - depending on the model. - wav_lens : torch.tensor - Lengths of the waveforms relative to the longest one in the - batch, tensor of shape [batch]. The longest one should have - relative length 1.0 and others len(waveform) / max_length. - Used for ignoring padding. - - Returns - ------- - torch.tensor - The encoded batch - """ - wavs = wavs.float() - wavs, wav_lens = wavs.to(self.device), wav_lens.to(self.device) - encoder_out = self.modules.encoder(wavs, wav_lens) - return encoder_out - - def transcribe_batch(self, wavs, wav_lens): - """Transcribes the input audio into a sequence of words - - The waveforms should already be in the model's desired format. - You can call: - ``normalized = EncoderDecoderASR.normalizer(signal, sample_rate)`` - to get a correctly converted signal in most cases. - - Arguments - --------- - wavs : torch.tensor - Batch of waveforms [batch, time, channels] or [batch, time] - depending on the model. - wav_lens : torch.tensor - Lengths of the waveforms relative to the longest one in the - batch, tensor of shape [batch]. The longest one should have - relative length 1.0 and others len(waveform) / max_length. - Used for ignoring padding. - - Returns - ------- - list - Each waveform in the batch transcribed. - tensor - Each predicted token id. - """ - with torch.no_grad(): - wav_lens = wav_lens.to(self.device) - encoder_out = self.encode_batch(wavs, wav_lens) - predicted_tokens, scores = self.modules.decoder( - encoder_out, wav_lens - ) - predicted_words = [ - self.tokenizer.decode_ids(token_seq) - for token_seq in predicted_tokens - ] - return predicted_words, predicted_tokens - - -class EncoderClassifier(Pretrained): - """A ready-to-use class for utterance-level classification (e.g, speaker-id, - language-id, emotion recognition, keyword spotting, etc). - - The class assumes that an encoder called "embedding_model" and a model - called "classifier" are defined in the yaml file. If you want to - convert the predicted index into a corresponding text label, please - provide the path of the label_encoder in a variable called 'lab_encoder_file' - within the yaml. - - The class can be used either to run only the encoder (encode_batch()) to - extract embeddings or to run a classification step (classify_batch()). - ``` - - Example - ------- - >>> import torchaudio - >>> from speechbrain.pretrained import EncoderClassifier - >>> # Model is downloaded from the speechbrain HuggingFace repo - >>> tmpdir = getfixture("tmpdir") - >>> classifier = EncoderClassifier.from_hparams( - ... source="speechbrain/spkrec-ecapa-voxceleb", - ... savedir=tmpdir, - ... ) - - >>> # Compute embeddings - >>> signal, fs = torchaudio.load("samples/audio_samples/example1.wav") - >>> embeddings = classifier.encode_batch(signal) - - >>> # Classification - >>> prediction = classifier .classify_batch(signal) - """ - - MODULES_NEEDED = [ - "compute_features", - "mean_var_norm", - "embedding_model", - "classifier", - ] - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - def extract_feats(self, wavs, wav_lens=None): - # wav to feats - wavs = wavs.to('cpu').float() - if wav_lens is None: - wav_lens = torch.ones(wavs.shape[0], device='cpu') - - feats = self.modules.compute_features(wavs) - feats = self.modules.mean_var_norm(feats, wav_lens) - - return feats - - def feats_classify(self, feats, wav_lens=None): - emb = self.modules.embedding_model(feats, wav_lens) - out_prob = self.modules.classifier(emb).squeeze(1) - - return out_prob - - def encode_batch(self, wavs, wav_lens=None, normalize=False): - """Encodes the input audio into a single vector embedding. - - The waveforms should already be in the model's desired format. - You can call: - ``normalized = .normalizer(signal, sample_rate)`` - to get a correctly converted signal in most cases. - - Arguments - --------- - wavs : torch.tensor - Batch of waveforms [batch, time, channels] or [batch, time] - depending on the model. Make sure the sample rate is fs=16000 Hz. - wav_lens : torch.tensor - Lengths of the waveforms relative to the longest one in the - batch, tensor of shape [batch]. The longest one should have - relative length 1.0 and others len(waveform) / max_length. - Used for ignoring padding. - normalize : bool - If True, it normalizes the embeddings with the statistics - contained in mean_var_norm_emb. - - Returns - ------- - torch.tensor - The encoded batch - """ - # Manage single waveforms in input - if len(wavs.shape) == 1: - wavs = wavs.unsqueeze(0) - - # Assign full length if wav_lens is not assigned - if wav_lens is None: - wav_lens = torch.ones(wavs.shape[0], device=self.device) - - # Storing waveform in the specified device - wavs, wav_lens = wavs.to(self.device), wav_lens.to(self.device) - wavs = wavs.float() - - # Computing features and embeddings - feats = self.modules.compute_features(wavs) - feats = self.modules.mean_var_norm(feats, wav_lens) - embeddings = self.modules.embedding_model(feats, wav_lens) - if normalize: - embeddings = self.hparams.mean_var_norm_emb( - embeddings, torch.ones(embeddings.shape[0], device=self.device) - ) - return embeddings - - def classify_batch(self, wavs, wav_lens=None): - """Performs classification on the top of the encoded features. - - It returns the posterior probabilities, the index and, if the label - encoder is specified it also the text label. - - Arguments - --------- - wavs : torch.tensor - Batch of waveforms [batch, time, channels] or [batch, time] - depending on the model. Make sure the sample rate is fs=16000 Hz. - wav_lens : torch.tensor - Lengths of the waveforms relative to the longest one in the - batch, tensor of shape [batch]. The longest one should have - relative length 1.0 and others len(waveform) / max_length. - Used for ignoring padding. - - Returns - ------- - out_prob - The log posterior probabilities of each class ([batch, N_class]) - score: - It is the value of the log-posterior for the best class ([batch,]) - index - The indexes of the best class ([batch,]) - text_lab: - List with the text labels corresponding to the indexes. - (label encoder should be provided). - """ - emb = self.encode_batch(wavs, wav_lens) - out_prob = self.modules.classifier(emb).squeeze(1) - score, index = torch.max(out_prob, dim=-1) - text_lab = self.hparams.label_encoder.decode_torch(index) - return out_prob, score, index, text_lab - - def classify_file(self, path): - """Classifies the given audiofile into the given set of labels. - - Arguments - --------- - path : str - Path to audio file to classify. - - Returns - ------- - out_prob - The log posterior probabilities of each class ([batch, N_class]) - score: - It is the value of the log-posterior for the best class ([batch,]) - index - The indexes of the best class ([batch,]) - text_lab: - List with the text labels corresponding to the indexes. - (label encoder should be provided). - """ - waveform = self.load_audio(path) - # Fake a batch: - batch = waveform.unsqueeze(0) - rel_length = torch.tensor([1.0]) - emb = self.encode_batch(batch, rel_length) - out_prob = self.modules.classifier(emb).squeeze(1) - score, index = torch.max(out_prob, dim=-1) - text_lab = self.hparams.label_encoder.decode_torch(index) - return out_prob, score, index, text_lab - - -class SpeakerRecognition(EncoderClassifier): - """A ready-to-use model for speaker recognition. It can be used to - perform speaker verification with verify_batch(). - - ``` - Example - ------- - >>> import torchaudio - >>> from speechbrain.pretrained import SpeakerRecognition - >>> # Model is downloaded from the speechbrain HuggingFace repo - >>> tmpdir = getfixture("tmpdir") - >>> verification = SpeakerRecognition.from_hparams( - ... source="speechbrain/spkrec-ecapa-voxceleb", - ... savedir=tmpdir, - ... ) - - >>> # Perform verification - >>> signal, fs = torchaudio.load("samples/audio_samples/example1.wav") - >>> signal2, fs = torchaudio.load("samples/audio_samples/example2.flac") - >>> score, prediction = verification.verify_batch(signal, signal2) - """ - - MODULES_NEEDED = [ - "compute_features", - "mean_var_norm", - "embedding_model", - "mean_var_norm_emb", - ] - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.similarity = torch.nn.CosineSimilarity(dim=-1, eps=1e-6) - - def verify_batch( - self, wavs1, wavs2, wav1_lens=None, wav2_lens=None, threshold=0.25 - ): - """Performs speaker verification with cosine distance. - - It returns the score and the decision (0 different speakers, - 1 same speakers). - - Arguments - --------- - wavs1 : Torch.Tensor - Tensor containing the speech waveform1 (batch, time). - Make sure the sample rate is fs=16000 Hz. - wavs2 : Torch.Tensor - Tensor containing the speech waveform2 (batch, time). - Make sure the sample rate is fs=16000 Hz. - wav1_lens: Torch.Tensor - Tensor containing the relative length for each sentence - in the length (e.g., [0.8 0.6 1.0]) - wav2_lens: Torch.Tensor - Tensor containing the relative length for each sentence - in the length (e.g., [0.8 0.6 1.0]) - threshold: Float - Threshold applied to the cosine distance to decide if the - speaker is different (0) or the same (1). - - Returns - ------- - score - The score associated to the binary verification output - (cosine distance). - prediction - The prediction is 1 if the two signals in input are from the same - speaker and 0 otherwise. - """ - emb1 = self.encode_batch(wavs1, wav1_lens, normalize=True) - emb2 = self.encode_batch(wavs2, wav2_lens, normalize=True) - score = self.similarity(emb1, emb2) - return score, score > threshold - - def verify_files(self, path_x, path_y): - """Speaker verification with cosine distance - - Returns the score and the decision (0 different speakers, - 1 same speakers). - - Returns - ------- - score - The score associated to the binary verification output - (cosine distance). - prediction - The prediction is 1 if the two signals in input are from the same - speaker and 0 otherwise. - """ - waveform_x = self.load_audio(path_x) - waveform_y = self.load_audio(path_y) - # Fake batches: - batch_x = waveform_x.unsqueeze(0) - batch_y = waveform_y.unsqueeze(0) - # Verify: - score, decision = self.verify_batch(batch_x, batch_y) - # Squeeze: - return score[0], decision[0] - - -class SepformerSeparation(Pretrained): - """A "ready-to-use" speech separation model. - - Uses Sepformer architecture. - - Example - ------- - >>> tmpdir = getfixture("tmpdir") - >>> model = SepformerSeparation.from_hparams( - ... source="speechbrain/sepformer-wsj02mix", - ... savedir=tmpdir) - >>> mix = torch.randn(1, 400) - >>> est_sources = model.separate_batch(mix) - >>> print(est_sources.shape) - torch.Size([1, 400, 2]) - """ - - MODULES_NEEDED = ["encoder", "masknet", "decoder"] - - def separate_batch(self, mix): - """Run source separation on batch of audio. - - Arguments - --------- - mix : torch.tensor - The mixture of sources. - - Returns - ------- - tensor - Separated sources - """ - - # Separation - mix = mix.to(self.device) - mix_w = self.modules.encoder(mix) - est_mask = self.modules.masknet(mix_w) - mix_w = torch.stack([mix_w] * self.hparams.num_spks) - sep_h = mix_w * est_mask - - # Decoding - est_source = torch.cat( - [ - self.modules.decoder(sep_h[i]).unsqueeze(-1) - for i in range(self.hparams.num_spks) - ], - dim=-1, - ) - - # T changed after conv1d in encoder, fix it here - T_origin = mix.size(1) - T_est = est_source.size(1) - if T_origin > T_est: - est_source = F.pad(est_source, (0, 0, 0, T_origin - T_est)) - else: - est_source = est_source[:, :T_origin, :] - return est_source - - def separate_file(self, path, savedir="."): - """Separate sources from file. - - Arguments - --------- - path : str - Path to file which has a mixture of sources. It can be a local - path, a web url, or a huggingface repo. - savedir : path - Path where to store the wav signals (when downloaded from the web). - Returns - ------- - tensor - Separated sources - """ - source, fl = split_path(path) - path = fetch(fl, source=source, savedir=savedir) - - batch, fs_file = torchaudio.load(path) - batch = batch.to(self.device) - fs_model = self.hparams.sample_rate - - # resample the data if needed - if fs_file != fs_model: - print( - "Resampling the audio from {} Hz to {} Hz".format( - fs_file, fs_model - ) - ) - tf = torchaudio.transforms.Resample( - orig_freq=fs_file, new_freq=fs_model - ) - batch = batch.mean(dim=0, keepdim=True) - batch = tf(batch) - - est_sources = self.separate_batch(batch) - est_sources = est_sources / est_sources.max(dim=1, keepdim=True)[0] - return est_sources - - -class SpectralMaskEnhancement(Pretrained): - """A ready-to-use model for speech enhancement. - - Arguments - --------- - See ``Pretrained``. - - Example - ------- - >>> import torchaudio - >>> from speechbrain.pretrained import SpectralMaskEnhancement - >>> # Model is downloaded from the speechbrain HuggingFace repo - >>> tmpdir = getfixture("tmpdir") - >>> enhancer = SpectralMaskEnhancement.from_hparams( - ... source="speechbrain/mtl-mimic-voicebank", - ... savedir=tmpdir, - ... ) - >>> noisy, fs = torchaudio.load("samples/audio_samples/example_noisy.wav") - >>> # Channel dimension is interpreted as batch dimension here - >>> enhanced = enhancer.enhance_batch(noisy) - """ - - HPARAMS_NEEDED = ["compute_stft", "spectral_magnitude", "resynth"] - MODULES_NEEDED = ["enhance_model"] - - def compute_features(self, wavs): - """Compute the log spectral magnitude features for masking. - - Arguments - --------- - wavs : torch.tensor - A batch of waveforms to convert to log spectral mags. - """ - feats = self.hparams.compute_stft(wavs) - feats = self.hparams.spectral_magnitude(feats) - return torch.log1p(feats) - - def enhance_batch(self, noisy, lengths=None): - """Enhance a batch of noisy waveforms. - - Arguments - --------- - noisy : torch.tensor - A batch of waveforms to perform enhancement on. - lengths : torch.tensor - The lengths of the waveforms if the enhancement model handles them. - - Returns - ------- - torch.tensor - A batch of enhanced waveforms of the same shape as input. - """ - noisy = noisy.to(self.device) - noisy_features = self.compute_features(noisy) - - # Perform masking-based enhancement, multiplying output with input. - if lengths is not None: - mask = self.modules.enhance_model(noisy_features, lengths=lengths) - else: - mask = self.modules.enhance_model(noisy_features) - enhanced = torch.mul(mask, noisy_features) - - # Return resynthesized waveforms - return self.hparams.resynth(torch.expm1(enhanced), noisy) - - def enhance_file(self, filename, output_filename=None): - """Enhance a wav file. - - Arguments - --------- - filename : str - Location on disk to load file for enhancement. - output_filename : str - If provided, writes enhanced data to this file. - """ - noisy = self.load_audio(filename) - noisy = noisy.to(self.device) - - # Fake a batch: - batch = noisy.unsqueeze(0) - enhanced = self.enhance_batch(batch) - - if output_filename is not None: - torchaudio.save(output_filename, enhanced, channels_first=False) - - return enhanced.squeeze(0) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Defines interfaces for simple inference with pretrained models + +Authors: + * Aku Rouhe 2021 + * Peter Plantinga 2021 + * Loren Lugosch 2020 + * Mirco Ravanelli 2020 + * Titouan Parcollet 2021 +""" +import torch +import torchaudio +from types import SimpleNamespace +from torch.nn import SyncBatchNorm +from torch.nn import DataParallel as DP +from hyperpyyaml import load_hyperpyyaml +from speechbrain.pretrained.fetching import fetch +from speechbrain.dataio.preprocess import AudioNormalizer +import torch.nn.functional as F +from torch.nn.parallel import DistributedDataParallel as DDP +from speechbrain.utils.data_utils import split_path +from speechbrain.utils.distributed import run_on_main + + +class Pretrained: + """Takes a trained model and makes predictions on new data. + + This is a base class which handles some common boilerplate. + It intentionally has an interface similar to ``Brain`` - these base + classes handle similar things. + + Subclasses of Pretrained should implement the actual logic of how + the pretrained system runs, and add methods with descriptive names + (e.g. transcribe_file() for ASR). + + Arguments + --------- + modules : dict of str:torch.nn.Module pairs + The Torch modules that make up the learned system. These can be treated + in special ways (put on the right device, frozen, etc.) + hparams : dict + Each key:value pair should consist of a string key and a hyperparameter + that is used within the overridden methods. These will + be accessible via an ``hparams`` attribute, using "dot" notation: + e.g., self.hparams.model(x). + run_opts : dict + Options parsed from command line. See ``speechbrain.parse_arguments()``. + List that are supported here: + * device + * data_parallel_count + * data_parallel_backend + * distributed_launch + * distributed_backend + * jit_module_keys + freeze_params : bool + To freeze (requires_grad=False) parameters or not. Normally in inference + you want to freeze the params. Also calls .eval() on all modules. + """ + + HPARAMS_NEEDED = [] + MODULES_NEEDED = [] + + def __init__( + self, modules=None, hparams=None, run_opts=None, freeze_params=True + ): + + # Arguments passed via the run opts dictionary. Set a limited + # number of these, since some don't apply to inference. + run_opt_defaults = { + "device": "cpu", + "data_parallel_count": -1, + "data_parallel_backend": False, + "distributed_launch": False, + "distributed_backend": "nccl", + "jit_module_keys": None, + } + for arg, default in run_opt_defaults.items(): + if run_opts is not None and arg in run_opts: + setattr(self, arg, run_opts[arg]) + else: + # If any arg from run_opt_defaults exist in hparams and + # not in command line args "run_opts" + if hparams is not None and arg in hparams: + setattr(self, arg, hparams[arg]) + else: + setattr(self, arg, default) + + # Put modules on the right device, accessible with dot notation + self.modules = torch.nn.ModuleDict(modules) + for mod in self.modules: + self.modules[mod].to(self.device) + + for mod in self.MODULES_NEEDED: + if mod not in modules: + raise ValueError(f"Need modules['{mod}']") + + # Check MODULES_NEEDED and HPARAMS_NEEDED and + # make hyperparams available with dot notation + if self.HPARAMS_NEEDED and hparams is None: + raise ValueError("Need to provide hparams dict.") + if hparams is not None: + # Also first check that all required params are found: + for hp in self.HPARAMS_NEEDED: + if hp not in hparams: + raise ValueError(f"Need hparams['{hp}']") + self.hparams = SimpleNamespace(**hparams) + + # Prepare modules for computation, e.g. jit + self._prepare_modules(freeze_params) + + # Audio normalization + self.audio_normalizer = hparams.get( + "audio_normalizer", AudioNormalizer() + ) + + def _prepare_modules(self, freeze_params): + """Prepare modules for computation, e.g. jit. + + Arguments + --------- + freeze_params : bool + Whether to freeze the parameters and call ``eval()``. + """ + + # Make jit-able + self._compile_jit() + self._wrap_distributed() + + # If we don't want to backprop, freeze the pretrained parameters + if freeze_params: + self.modules.eval() + for p in self.modules.parameters(): + p.requires_grad = False + + def load_audio(self, path, savedir="."): + """Load an audio file with this model"s input spec + + When using a speech model, it is important to use the same type of data, + as was used to train the model. This means for example using the same + sampling rate and number of channels. It is, however, possible to + convert a file from a higher sampling rate to a lower one (downsampling). + Similarly, it is simple to downmix a stereo file to mono. + The path can be a local path, a web url, or a link to a huggingface repo. + """ + source, fl = split_path(path) + path = fetch(fl, source=source, savedir=savedir) + signal, sr = torchaudio.load(path, channels_first=False) + return self.audio_normalizer(signal, sr) + + def _compile_jit(self): + """Compile requested modules with ``torch.jit.script``.""" + if self.jit_module_keys is None: + return + + for name in self.jit_module_keys: + if name not in self.modules: + raise ValueError( + "module " + name + " cannot be jit compiled because " + "it is not defined in your hparams file." + ) + module = torch.jit.script(self.modules[name]) + self.modules[name] = module.to(self.device) + + def _wrap_distributed(self): + """Wrap modules with distributed wrapper when requested.""" + if not self.distributed_launch and not self.data_parallel_backend: + return + elif self.distributed_launch: + for name, module in self.modules.items(): + if any(p.requires_grad for p in module.parameters()): + # for ddp, all module must run on same GPU + module = SyncBatchNorm.convert_sync_batchnorm(module) + module = DDP(module, device_ids=[self.device]) + self.modules[name] = module + else: + # data_parallel_backend + for name, module in self.modules.items(): + if any(p.requires_grad for p in module.parameters()): + # if distributed_count = -1 then use all gpus + # otherwise, specify the set of gpu to use + if self.data_parallel_count == -1: + module = DP(module) + else: + module = DP( + module, + [i for i in range(self.data_parallel_count)], + ) + self.modules[name] = module + + @classmethod + def from_hparams( + cls, + source, + hparams_file="hyperparams.yaml", + overrides={}, + savedir=None, + use_auth_token=False, + **kwargs, + ): + """Fetch and load based from outside source based on HyperPyYAML file + + The source can be a location on the filesystem or online/huggingface + + The hyperparams file should contain a "modules" key, which is a + dictionary of torch modules used for computation. + + The hyperparams file should contain a "pretrainer" key, which is a + speechbrain.utils.parameter_transfer.Pretrainer + + Arguments + --------- + source : str + The location to use for finding the model. See + ``speechbrain.pretrained.fetching.fetch`` for details. + hparams_file : str + The name of the hyperparameters file to use for constructing + the modules necessary for inference. Must contain two keys: + "modules" and "pretrainer", as described. + overrides : dict + Any changes to make to the hparams file when it is loaded. + savedir : str or Path + Where to put the pretraining material. If not given, will use + ./pretrained_models/-hash(source). + use_auth_token : bool (default: False) + If true Hugginface's auth_token will be used to load private models from the HuggingFace Hub, + default is False because majority of models are public. + """ + if savedir is None: + clsname = cls.__name__ + savedir = f"./pretrained_models/{clsname}-{hash(source)}" + hparams_local_path = fetch( + hparams_file, source, savedir, use_auth_token + ) + + # Load the modules: + with open(hparams_local_path) as fin: + hparams = load_hyperpyyaml(fin, overrides) + + # Pretraining: + pretrainer = hparams["pretrainer"] + pretrainer.set_collect_in(savedir) + # For distributed setups, have this here: + run_on_main(pretrainer.collect_files, kwargs={"default_source": source}) + # Load on the CPU. Later the params can be moved elsewhere by specifying + # run_opts={"device": ...} + pretrainer.load_collected(device="cpu") + + # Now return the system + return cls(hparams["modules"], hparams, **kwargs) + + +class EndToEndSLU(Pretrained): + """A end-to-end SLU model. + + The class can be used either to run only the encoder (encode()) to extract + features or to run the entire model (decode()) to map the speech to its semantics. + + Example + ------- + >>> from speechbrain.pretrained import EndToEndSLU + >>> tmpdir = getfixture("tmpdir") + >>> slu_model = EndToEndSLU.from_hparams( + ... source="speechbrain/slu-timers-and-such-direct-librispeech-asr", + ... savedir=tmpdir, + ... ) + >>> slu_model.decode_file("samples/audio_samples/example6.wav") + "{'intent': 'SimpleMath', 'slots': {'number1': 37.67, 'number2': 75.7, 'op': ' minus '}}" + """ + + HPARAMS_NEEDED = ["tokenizer", "asr_model_source"] + MODULES_NEEDED = [ + "slu_enc", + "beam_searcher", + ] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.tokenizer = self.hparams.tokenizer + self.asr_model = EncoderDecoderASR.from_hparams( + source=self.hparams.asr_model_source, + run_opts={"device": self.device}, + ) + + def decode_file(self, path): + """Maps the given audio file to a string representing the + semantic dictionary for the utterance. + + Arguments + --------- + path : str + Path to audio file to decode. + + Returns + ------- + str + The predicted semantics. + """ + waveform = self.load_audio(path) + waveform = waveform.to(self.device) + # Fake a batch: + batch = waveform.unsqueeze(0) + rel_length = torch.tensor([1.0]) + predicted_words, predicted_tokens = self.decode_batch(batch, rel_length) + return predicted_words[0] + + def encode_batch(self, wavs, wav_lens): + """Encodes the input audio into a sequence of hidden states + + Arguments + --------- + wavs : torch.tensor + Batch of waveforms [batch, time, channels] or [batch, time] + depending on the model. + wav_lens : torch.tensor + Lengths of the waveforms relative to the longest one in the + batch, tensor of shape [batch]. The longest one should have + relative length 1.0 and others len(waveform) / max_length. + Used for ignoring padding. + + Returns + ------- + torch.tensor + The encoded batch + """ + wavs = wavs.float() + wavs, wav_lens = wavs.to(self.device), wav_lens.to(self.device) + with torch.no_grad(): + ASR_encoder_out = self.asr_model.encode_batch( + wavs.detach(), wav_lens + ) + encoder_out = self.modules.slu_enc(ASR_encoder_out) + return encoder_out + + def decode_batch(self, wavs, wav_lens): + """Maps the input audio to its semantics + + Arguments + --------- + wavs : torch.tensor + Batch of waveforms [batch, time, channels] or [batch, time] + depending on the model. + wav_lens : torch.tensor + Lengths of the waveforms relative to the longest one in the + batch, tensor of shape [batch]. The longest one should have + relative length 1.0 and others len(waveform) / max_length. + Used for ignoring padding. + + Returns + ------- + list + Each waveform in the batch decoded. + tensor + Each predicted token id. + """ + with torch.no_grad(): + wavs, wav_lens = wavs.to(self.device), wav_lens.to(self.device) + encoder_out = self.encode_batch(wavs, wav_lens) + predicted_tokens, scores = self.modules.beam_searcher( + encoder_out, wav_lens + ) + predicted_words = [ + self.tokenizer.decode_ids(token_seq) + for token_seq in predicted_tokens + ] + return predicted_words, predicted_tokens + + +class EncoderDecoderASR(Pretrained): + """A ready-to-use Encoder-Decoder ASR model + + The class can be used either to run only the encoder (encode()) to extract + features or to run the entire encoder-decoder model + (transcribe()) to transcribe speech. The given YAML must contains the fields + specified in the *_NEEDED[] lists. + + Example + ------- + >>> from speechbrain.pretrained import EncoderDecoderASR + >>> tmpdir = getfixture("tmpdir") + >>> asr_model = EncoderDecoderASR.from_hparams( + ... source="speechbrain/asr-crdnn-rnnlm-librispeech", + ... savedir=tmpdir, + ... ) + >>> asr_model.transcribe_file("samples/audio_samples/example2.flac") + "MY FATHER HAS REVEALED THE CULPRIT'S NAME" + """ + + HPARAMS_NEEDED = ["tokenizer"] + MODULES_NEEDED = [ + "encoder", + "decoder", + ] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.tokenizer = self.hparams.tokenizer + + def transcribe_file(self, path): + """Transcribes the given audiofile into a sequence of words. + + Arguments + --------- + path : str + Path to audio file which to transcribe. + + Returns + ------- + str + The audiofile transcription produced by this ASR system. + """ + waveform = self.load_audio(path) + # Fake a batch: + batch = waveform.unsqueeze(0) + rel_length = torch.tensor([1.0]) + predicted_words, predicted_tokens = self.transcribe_batch( + batch, rel_length + ) + return predicted_words[0] + + def encode_batch(self, wavs, wav_lens): + """Encodes the input audio into a sequence of hidden states + + The waveforms should already be in the model's desired format. + You can call: + ``normalized = EncoderDecoderASR.normalizer(signal, sample_rate)`` + to get a correctly converted signal in most cases. + + Arguments + --------- + wavs : torch.tensor + Batch of waveforms [batch, time, channels] or [batch, time] + depending on the model. + wav_lens : torch.tensor + Lengths of the waveforms relative to the longest one in the + batch, tensor of shape [batch]. The longest one should have + relative length 1.0 and others len(waveform) / max_length. + Used for ignoring padding. + + Returns + ------- + torch.tensor + The encoded batch + """ + wavs = wavs.float() + wavs, wav_lens = wavs.to(self.device), wav_lens.to(self.device) + encoder_out = self.modules.encoder(wavs, wav_lens) + return encoder_out + + def transcribe_batch(self, wavs, wav_lens): + """Transcribes the input audio into a sequence of words + + The waveforms should already be in the model's desired format. + You can call: + ``normalized = EncoderDecoderASR.normalizer(signal, sample_rate)`` + to get a correctly converted signal in most cases. + + Arguments + --------- + wavs : torch.tensor + Batch of waveforms [batch, time, channels] or [batch, time] + depending on the model. + wav_lens : torch.tensor + Lengths of the waveforms relative to the longest one in the + batch, tensor of shape [batch]. The longest one should have + relative length 1.0 and others len(waveform) / max_length. + Used for ignoring padding. + + Returns + ------- + list + Each waveform in the batch transcribed. + tensor + Each predicted token id. + """ + with torch.no_grad(): + wav_lens = wav_lens.to(self.device) + encoder_out = self.encode_batch(wavs, wav_lens) + predicted_tokens, scores = self.modules.decoder( + encoder_out, wav_lens + ) + predicted_words = [ + self.tokenizer.decode_ids(token_seq) + for token_seq in predicted_tokens + ] + return predicted_words, predicted_tokens + + +class EncoderClassifier(Pretrained): + """A ready-to-use class for utterance-level classification (e.g, speaker-id, + language-id, emotion recognition, keyword spotting, etc). + + The class assumes that an encoder called "embedding_model" and a model + called "classifier" are defined in the yaml file. If you want to + convert the predicted index into a corresponding text label, please + provide the path of the label_encoder in a variable called 'lab_encoder_file' + within the yaml. + + The class can be used either to run only the encoder (encode_batch()) to + extract embeddings or to run a classification step (classify_batch()). + ``` + + Example + ------- + >>> import torchaudio + >>> from speechbrain.pretrained import EncoderClassifier + >>> # Model is downloaded from the speechbrain HuggingFace repo + >>> tmpdir = getfixture("tmpdir") + >>> classifier = EncoderClassifier.from_hparams( + ... source="speechbrain/spkrec-ecapa-voxceleb", + ... savedir=tmpdir, + ... ) + + >>> # Compute embeddings + >>> signal, fs = torchaudio.load("samples/audio_samples/example1.wav") + >>> embeddings = classifier.encode_batch(signal) + + >>> # Classification + >>> prediction = classifier .classify_batch(signal) + """ + + MODULES_NEEDED = [ + "compute_features", + "mean_var_norm", + "embedding_model", + "classifier", + ] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def extract_feats(self, wavs, wav_lens=None): + # wav to feats + wavs = wavs.to('cpu').float() + if wav_lens is None: + wav_lens = torch.ones(wavs.shape[0], device='cpu') + + feats = self.modules.compute_features(wavs) + feats = self.modules.mean_var_norm(feats, wav_lens) + + return feats + + def feats_classify(self, feats, wav_lens=None): + emb = self.modules.embedding_model(feats, wav_lens) + out_prob = self.modules.classifier(emb).squeeze(1) + + return out_prob + + def encode_batch(self, wavs, wav_lens=None, normalize=False): + """Encodes the input audio into a single vector embedding. + + The waveforms should already be in the model's desired format. + You can call: + ``normalized = .normalizer(signal, sample_rate)`` + to get a correctly converted signal in most cases. + + Arguments + --------- + wavs : torch.tensor + Batch of waveforms [batch, time, channels] or [batch, time] + depending on the model. Make sure the sample rate is fs=16000 Hz. + wav_lens : torch.tensor + Lengths of the waveforms relative to the longest one in the + batch, tensor of shape [batch]. The longest one should have + relative length 1.0 and others len(waveform) / max_length. + Used for ignoring padding. + normalize : bool + If True, it normalizes the embeddings with the statistics + contained in mean_var_norm_emb. + + Returns + ------- + torch.tensor + The encoded batch + """ + # Manage single waveforms in input + if len(wavs.shape) == 1: + wavs = wavs.unsqueeze(0) + + # Assign full length if wav_lens is not assigned + if wav_lens is None: + wav_lens = torch.ones(wavs.shape[0], device=self.device) + + # Storing waveform in the specified device + wavs, wav_lens = wavs.to(self.device), wav_lens.to(self.device) + wavs = wavs.float() + + # Computing features and embeddings + feats = self.modules.compute_features(wavs) + feats = self.modules.mean_var_norm(feats, wav_lens) + embeddings = self.modules.embedding_model(feats, wav_lens) + if normalize: + embeddings = self.hparams.mean_var_norm_emb( + embeddings, torch.ones(embeddings.shape[0], device=self.device) + ) + return embeddings + + def classify_batch(self, wavs, wav_lens=None): + """Performs classification on the top of the encoded features. + + It returns the posterior probabilities, the index and, if the label + encoder is specified it also the text label. + + Arguments + --------- + wavs : torch.tensor + Batch of waveforms [batch, time, channels] or [batch, time] + depending on the model. Make sure the sample rate is fs=16000 Hz. + wav_lens : torch.tensor + Lengths of the waveforms relative to the longest one in the + batch, tensor of shape [batch]. The longest one should have + relative length 1.0 and others len(waveform) / max_length. + Used for ignoring padding. + + Returns + ------- + out_prob + The log posterior probabilities of each class ([batch, N_class]) + score: + It is the value of the log-posterior for the best class ([batch,]) + index + The indexes of the best class ([batch,]) + text_lab: + List with the text labels corresponding to the indexes. + (label encoder should be provided). + """ + emb = self.encode_batch(wavs, wav_lens) + out_prob = self.modules.classifier(emb).squeeze(1) + score, index = torch.max(out_prob, dim=-1) + text_lab = self.hparams.label_encoder.decode_torch(index) + return out_prob, score, index, text_lab + + def classify_file(self, path): + """Classifies the given audiofile into the given set of labels. + + Arguments + --------- + path : str + Path to audio file to classify. + + Returns + ------- + out_prob + The log posterior probabilities of each class ([batch, N_class]) + score: + It is the value of the log-posterior for the best class ([batch,]) + index + The indexes of the best class ([batch,]) + text_lab: + List with the text labels corresponding to the indexes. + (label encoder should be provided). + """ + waveform = self.load_audio(path) + # Fake a batch: + batch = waveform.unsqueeze(0) + rel_length = torch.tensor([1.0]) + emb = self.encode_batch(batch, rel_length) + out_prob = self.modules.classifier(emb).squeeze(1) + score, index = torch.max(out_prob, dim=-1) + text_lab = self.hparams.label_encoder.decode_torch(index) + return out_prob, score, index, text_lab + + +class SpeakerRecognition(EncoderClassifier): + """A ready-to-use model for speaker recognition. It can be used to + perform speaker verification with verify_batch(). + + ``` + Example + ------- + >>> import torchaudio + >>> from speechbrain.pretrained import SpeakerRecognition + >>> # Model is downloaded from the speechbrain HuggingFace repo + >>> tmpdir = getfixture("tmpdir") + >>> verification = SpeakerRecognition.from_hparams( + ... source="speechbrain/spkrec-ecapa-voxceleb", + ... savedir=tmpdir, + ... ) + + >>> # Perform verification + >>> signal, fs = torchaudio.load("samples/audio_samples/example1.wav") + >>> signal2, fs = torchaudio.load("samples/audio_samples/example2.flac") + >>> score, prediction = verification.verify_batch(signal, signal2) + """ + + MODULES_NEEDED = [ + "compute_features", + "mean_var_norm", + "embedding_model", + "mean_var_norm_emb", + ] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.similarity = torch.nn.CosineSimilarity(dim=-1, eps=1e-6) + + def verify_batch( + self, wavs1, wavs2, wav1_lens=None, wav2_lens=None, threshold=0.25 + ): + """Performs speaker verification with cosine distance. + + It returns the score and the decision (0 different speakers, + 1 same speakers). + + Arguments + --------- + wavs1 : Torch.Tensor + Tensor containing the speech waveform1 (batch, time). + Make sure the sample rate is fs=16000 Hz. + wavs2 : Torch.Tensor + Tensor containing the speech waveform2 (batch, time). + Make sure the sample rate is fs=16000 Hz. + wav1_lens: Torch.Tensor + Tensor containing the relative length for each sentence + in the length (e.g., [0.8 0.6 1.0]) + wav2_lens: Torch.Tensor + Tensor containing the relative length for each sentence + in the length (e.g., [0.8 0.6 1.0]) + threshold: Float + Threshold applied to the cosine distance to decide if the + speaker is different (0) or the same (1). + + Returns + ------- + score + The score associated to the binary verification output + (cosine distance). + prediction + The prediction is 1 if the two signals in input are from the same + speaker and 0 otherwise. + """ + emb1 = self.encode_batch(wavs1, wav1_lens, normalize=True) + emb2 = self.encode_batch(wavs2, wav2_lens, normalize=True) + score = self.similarity(emb1, emb2) + return score, score > threshold + + def verify_files(self, path_x, path_y): + """Speaker verification with cosine distance + + Returns the score and the decision (0 different speakers, + 1 same speakers). + + Returns + ------- + score + The score associated to the binary verification output + (cosine distance). + prediction + The prediction is 1 if the two signals in input are from the same + speaker and 0 otherwise. + """ + waveform_x = self.load_audio(path_x) + waveform_y = self.load_audio(path_y) + # Fake batches: + batch_x = waveform_x.unsqueeze(0) + batch_y = waveform_y.unsqueeze(0) + # Verify: + score, decision = self.verify_batch(batch_x, batch_y) + # Squeeze: + return score[0], decision[0] + + +class SepformerSeparation(Pretrained): + """A "ready-to-use" speech separation model. + + Uses Sepformer architecture. + + Example + ------- + >>> tmpdir = getfixture("tmpdir") + >>> model = SepformerSeparation.from_hparams( + ... source="speechbrain/sepformer-wsj02mix", + ... savedir=tmpdir) + >>> mix = torch.randn(1, 400) + >>> est_sources = model.separate_batch(mix) + >>> print(est_sources.shape) + torch.Size([1, 400, 2]) + """ + + MODULES_NEEDED = ["encoder", "masknet", "decoder"] + + def separate_batch(self, mix): + """Run source separation on batch of audio. + + Arguments + --------- + mix : torch.tensor + The mixture of sources. + + Returns + ------- + tensor + Separated sources + """ + + # Separation + mix = mix.to(self.device) + mix_w = self.modules.encoder(mix) + est_mask = self.modules.masknet(mix_w) + mix_w = torch.stack([mix_w] * self.hparams.num_spks) + sep_h = mix_w * est_mask + + # Decoding + est_source = torch.cat( + [ + self.modules.decoder(sep_h[i]).unsqueeze(-1) + for i in range(self.hparams.num_spks) + ], + dim=-1, + ) + + # T changed after conv1d in encoder, fix it here + T_origin = mix.size(1) + T_est = est_source.size(1) + if T_origin > T_est: + est_source = F.pad(est_source, (0, 0, 0, T_origin - T_est)) + else: + est_source = est_source[:, :T_origin, :] + return est_source + + def separate_file(self, path, savedir="."): + """Separate sources from file. + + Arguments + --------- + path : str + Path to file which has a mixture of sources. It can be a local + path, a web url, or a huggingface repo. + savedir : path + Path where to store the wav signals (when downloaded from the web). + Returns + ------- + tensor + Separated sources + """ + source, fl = split_path(path) + path = fetch(fl, source=source, savedir=savedir) + + batch, fs_file = torchaudio.load(path) + batch = batch.to(self.device) + fs_model = self.hparams.sample_rate + + # resample the data if needed + if fs_file != fs_model: + print( + "Resampling the audio from {} Hz to {} Hz".format( + fs_file, fs_model + ) + ) + tf = torchaudio.transforms.Resample( + orig_freq=fs_file, new_freq=fs_model + ) + batch = batch.mean(dim=0, keepdim=True) + batch = tf(batch) + + est_sources = self.separate_batch(batch) + est_sources = est_sources / est_sources.max(dim=1, keepdim=True)[0] + return est_sources + + +class SpectralMaskEnhancement(Pretrained): + """A ready-to-use model for speech enhancement. + + Arguments + --------- + See ``Pretrained``. + + Example + ------- + >>> import torchaudio + >>> from speechbrain.pretrained import SpectralMaskEnhancement + >>> # Model is downloaded from the speechbrain HuggingFace repo + >>> tmpdir = getfixture("tmpdir") + >>> enhancer = SpectralMaskEnhancement.from_hparams( + ... source="speechbrain/mtl-mimic-voicebank", + ... savedir=tmpdir, + ... ) + >>> noisy, fs = torchaudio.load("samples/audio_samples/example_noisy.wav") + >>> # Channel dimension is interpreted as batch dimension here + >>> enhanced = enhancer.enhance_batch(noisy) + """ + + HPARAMS_NEEDED = ["compute_stft", "spectral_magnitude", "resynth"] + MODULES_NEEDED = ["enhance_model"] + + def compute_features(self, wavs): + """Compute the log spectral magnitude features for masking. + + Arguments + --------- + wavs : torch.tensor + A batch of waveforms to convert to log spectral mags. + """ + feats = self.hparams.compute_stft(wavs) + feats = self.hparams.spectral_magnitude(feats) + return torch.log1p(feats) + + def enhance_batch(self, noisy, lengths=None): + """Enhance a batch of noisy waveforms. + + Arguments + --------- + noisy : torch.tensor + A batch of waveforms to perform enhancement on. + lengths : torch.tensor + The lengths of the waveforms if the enhancement model handles them. + + Returns + ------- + torch.tensor + A batch of enhanced waveforms of the same shape as input. + """ + noisy = noisy.to(self.device) + noisy_features = self.compute_features(noisy) + + # Perform masking-based enhancement, multiplying output with input. + if lengths is not None: + mask = self.modules.enhance_model(noisy_features, lengths=lengths) + else: + mask = self.modules.enhance_model(noisy_features) + enhanced = torch.mul(mask, noisy_features) + + # Return resynthesized waveforms + return self.hparams.resynth(torch.expm1(enhanced), noisy) + + def enhance_file(self, filename, output_filename=None): + """Enhance a wav file. + + Arguments + --------- + filename : str + Location on disk to load file for enhancement. + output_filename : str + If provided, writes enhanced data to this file. + """ + noisy = self.load_audio(filename) + noisy = noisy.to(self.device) + + # Fake a batch: + batch = noisy.unsqueeze(0) + enhanced = self.enhance_batch(batch) + + if output_filename is not None: + torchaudio.save(output_filename, enhanced, channels_first=False) + + return enhanced.squeeze(0) diff --git a/ACL_PyTorch/contrib/audio/tdnn/modelzoo_level.txt b/ACL_PyTorch/contrib/audio/tdnn/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/ACL_PyTorch/contrib/audio/tdnn/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/audio/tdnn/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/audio/tdnn/om_infer.sh b/ACL_PyTorch/contrib/audio/tdnn/om_infer.sh index 499be09436055b75ba47d32b74fcbadb7d7c17df..718f9f6a8e0edcebbc7202c194226b02098ba69d 100644 --- a/ACL_PyTorch/contrib/audio/tdnn/om_infer.sh +++ b/ACL_PyTorch/contrib/audio/tdnn/om_infer.sh @@ -1,23 +1,23 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - - -install_path=/usr/local/Ascend/ascend-toolkit/latest -#export PYTHONUNBUFFERD=1 -#export PYTHONPATH=${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH - -#export LD_LIBRARY_PATH=${install_path}/fwkacllib/lib64/:${install_path}/acllib/lib64/:${install_path}/atc/lib64/:$LD_LIBRARY_PATH - -python Tdnn_pyacl_infer.py --model_path=tdnn.om --device_id=0 --cpu_run=True --sync_infer=True --workspace=10 --input_info_file_path=mini_librispeech_test.info --input_dtypes=float32 --infer_res_save_path=result --res_save_type=bin +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + + +install_path=/usr/local/Ascend/ascend-toolkit/latest +#export PYTHONUNBUFFERD=1 +#export PYTHONPATH=${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH + +#export LD_LIBRARY_PATH=${install_path}/fwkacllib/lib64/:${install_path}/acllib/lib64/:${install_path}/atc/lib64/:$LD_LIBRARY_PATH + +python Tdnn_pyacl_infer.py --model_path=tdnn.om --device_id=0 --cpu_run=True --sync_infer=True --workspace=10 --input_info_file_path=mini_librispeech_test.info --input_dtypes=float32 --infer_res_save_path=result --res_save_type=bin diff --git a/ACL_PyTorch/contrib/audio/tdnn/requirements.txt b/ACL_PyTorch/contrib/audio/tdnn/requirements.txt index 902c74751a5d7d9872c7787dcd49a9e49350d9f2..f4e019b9128e61cda0173e2b23d5ba89ca9eec65 100644 --- a/ACL_PyTorch/contrib/audio/tdnn/requirements.txt +++ b/ACL_PyTorch/contrib/audio/tdnn/requirements.txt @@ -1,11 +1,11 @@ --r lint-requirements.txt -huggingface_hub>=0.0.6 -hyperpyyaml>=0.0.1 -joblib>=0.14.1 -numpy>=1.17.0 -packaging -pre-commit>=2.3.0 -scipy>=1.4.1 -sentencepiece>=0.1.91 -SoundFile; sys_platform == 'win32' -tqdm>=4.42.0 +-r lint-requirements.txt +huggingface_hub>=0.0.6 +hyperpyyaml>=0.0.1 +joblib>=0.14.1 +numpy>=1.17.0 +packaging +pre-commit>=2.3.0 +scipy>=1.4.1 +sentencepiece>=0.1.91 +SoundFile; sys_platform == 'win32' +tqdm>=4.42.0 diff --git a/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/3d_attention_net_pkl2onnx.py b/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/3d_attention_net_pkl2onnx.py index 9d15792a6e44650412830047652ea61ac173b437..5927f173e59b62b51fdb732f5ed7be1833a080db 100644 --- a/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/3d_attention_net_pkl2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/3d_attention_net_pkl2onnx.py @@ -1,34 +1,34 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import torch -import torch.onnx -from model.residual_attention_network import ResidualAttentionModel_92_32input_update as ResidualAttentionModel - - -def pkl2onnx(input_file = "model_92_sgd.pkl", output_file = "3d_attention_net.onnx"): - model = ResidualAttentionModel() - model.load_state_dict((torch.load(input_file, map_location = "cpu"))) - model.eval() - input_name = ["image"] - output_name = ["class"] - dynamic_axes = {"image": {0:"-1"}, "class": {0:"-1"}} - dummy_input = torch.randn(1, 3, 32, 32) - torch.onnx.export(model, dummy_input, output_file, input_names = input_name, dynamic_axes = dynamic_axes, output_names = output_name, opset_version=11, verbose=True) - -if __name__ == "__main__": - print("----------start----------") - pkl2onnx() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import torch +import torch.onnx +from model.residual_attention_network import ResidualAttentionModel_92_32input_update as ResidualAttentionModel + + +def pkl2onnx(input_file = "model_92_sgd.pkl", output_file = "3d_attention_net.onnx"): + model = ResidualAttentionModel() + model.load_state_dict((torch.load(input_file, map_location = "cpu"))) + model.eval() + input_name = ["image"] + output_name = ["class"] + dynamic_axes = {"image": {0:"-1"}, "class": {0:"-1"}} + dummy_input = torch.randn(1, 3, 32, 32) + torch.onnx.export(model, dummy_input, output_file, input_names = input_name, dynamic_axes = dynamic_axes, output_names = output_name, opset_version=11, verbose=True) + +if __name__ == "__main__": + print("----------start----------") + pkl2onnx() print("----------end----------") \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/3d_attention_net_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/3d_attention_net_preprocess.py index 4b94690e34ba1a97b52e3adb5903087f713131b2..4ce91ea226b86c7d4bfe85559651904905861aec 100644 --- a/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/3d_attention_net_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/3d_attention_net_preprocess.py @@ -1,68 +1,68 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import os -import torch -import numpy as np -from torch.utils.data import Dataset, DataLoader -import torchvision -from torchvision import transforms, datasets, models - -def preprocess(data_path = "./data/", save_path = "./pre_process_result/"): - # Image Preprocessing - transform = transforms.Compose([ - transforms.RandomHorizontalFlip(), - transforms.RandomCrop((32, 32), padding=4), #left, top, right, bottom - transforms.ToTensor() - ]) - test_transform = transforms.Compose([ - transforms.ToTensor() - ]) - # when image is rgb, totensor do the division 255 - # CIFAR-10 Dataset - train_dataset = datasets.CIFAR10(root=data_path, - train=True, - transform=transform, - download=True) - - test_dataset = datasets.CIFAR10(root=data_path, - train=False, - transform=test_transform) - - # Data Loader (Input Pipeline) - train_loader = torch.utils.data.DataLoader(dataset=train_dataset, - batch_size=64, # 64 - shuffle=True, num_workers=8) - test_loader = torch.utils.data.DataLoader(dataset=test_dataset, - batch_size=32, - shuffle=False) - - classes = ('plane', 'car', 'bird', 'cat', - 'deer', 'dog', 'frog', 'horse', 'ship', 'truck') - if not os.path.exists(save_path): - os.makedirs(save_path) - cnt = -1 - for images, labels in test_loader: - for i in range(len(images)): - cnt += 1 - image = images[i] - label = labels[i] - image = np.array(image).astype(np.float32) - image.tofile(f"{save_path}image_{cnt}.bin") - if(cnt % 100 == 9): - print(f"current: {cnt}") - -if __name__ == "__main__": +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import os +import torch +import numpy as np +from torch.utils.data import Dataset, DataLoader +import torchvision +from torchvision import transforms, datasets, models + +def preprocess(data_path = "./data/", save_path = "./pre_process_result/"): + # Image Preprocessing + transform = transforms.Compose([ + transforms.RandomHorizontalFlip(), + transforms.RandomCrop((32, 32), padding=4), #left, top, right, bottom + transforms.ToTensor() + ]) + test_transform = transforms.Compose([ + transforms.ToTensor() + ]) + # when image is rgb, totensor do the division 255 + # CIFAR-10 Dataset + train_dataset = datasets.CIFAR10(root=data_path, + train=True, + transform=transform, + download=True) + + test_dataset = datasets.CIFAR10(root=data_path, + train=False, + transform=test_transform) + + # Data Loader (Input Pipeline) + train_loader = torch.utils.data.DataLoader(dataset=train_dataset, + batch_size=64, # 64 + shuffle=True, num_workers=8) + test_loader = torch.utils.data.DataLoader(dataset=test_dataset, + batch_size=32, + shuffle=False) + + classes = ('plane', 'car', 'bird', 'cat', + 'deer', 'dog', 'frog', 'horse', 'ship', 'truck') + if not os.path.exists(save_path): + os.makedirs(save_path) + cnt = -1 + for images, labels in test_loader: + for i in range(len(images)): + cnt += 1 + image = images[i] + label = labels[i] + image = np.array(image).astype(np.float32) + image.tofile(f"{save_path}image_{cnt}.bin") + if(cnt % 100 == 9): + print(f"current: {cnt}") + +if __name__ == "__main__": preprocess() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/LICENSE b/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/LICENSE index b1fac45f02e2f98395fd96a7e4f4a39e257ac0bc..989e2c59e973a05cfbfe9de678b7f2af777b0713 100644 --- a/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/LICENSE @@ -1,201 +1,201 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/modelzoo_level.txt index 9e95396651cc4382fe60ee1ee053674f527a448c..27e6c78b37535fe4f5a17029546fe257ad164d34 100644 --- a/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:POK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/readme.md b/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/readme.md index b7efb7ace2a24a91235b6f37e5842b7fc1775760..db4cf57a7e99fe0cb04e2e93124e60a6353602a7 100644 --- a/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/readme.md +++ b/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/readme.md @@ -1,98 +1,98 @@ -# 一. 环境准备 -1. 安装必要的依赖,运行所需的依赖详见requirements.txt -2. 获取开源模型代码及权重文件 -``` -git clone https://github.com/tengshaofeng/ResidualAttentionNetwork-pytorch.git -cd ResidualAttentionNetwork-pytorch -git checkout 44d09fe9afc0d5fba6f3f63b8375069ae9d54a56 -cd Residual-Attention-Network -cp -r model ../.. -cp model_92_sgd.pkl ../.. -cd ../.. -``` -3. 由于python版本问题,原模型代码在执行过程中会出现数据类型转换问题,依次执行以下命令 -``` -cd model/ -patch -p1 <../3d_attention_net.patch -cd .. -``` - -4. 获取benchmark工具 - 将benchmark.x86_64放到当前目录。 -5. 获取OXInterface.py -``` -git clone https://gitee.com/zheng-wengang1/onnx_tools.git -cd onnx_tools -git checkout cbb099e5f2cef3d76c7630bffe0ee8250b03d921 -cd .. -``` - -# 二. 数据预处理 -1. 获取CIFAR-10数据集 -``` -website:https://www.cs.toronto.edu/~kriz/cifar.html -#Version:CIFAR-10 python version -#md5sum:c58f30108f718f92721af3b95e74349a -``` -2. 上传数据集 -``` -mkdir data -``` -3. 将下载的CIFAR-10数据集上传至data文件夹,而后执行如下命令: -``` -tar -zxvf data/cifar-10-python.tar.gz -C data/ -``` -4. 数据预处理 -``` -python3.7 3d_attention_net_preprocess.py -``` - -5. 生成预处理后的数据集信息文件 -``` -python3.7 gen_dataset_info.py bin ./pre_process_result/ ./3d_attention_net_prep_bin.info 32 32 -``` - -# 三. pkl文件转om模型 -1. 读取源代码仓中的pkl文件,将原始模型转换为onnx -``` -python3.7 3d_attention_net_pkl2onnx.py -``` - -2. 对onnx模型中的resize操作进行优化 -``` -python3.7 resize_optimize.py -``` - -3. 通过Autotune进行性能调优并转换为om模型 -``` -bash test/3d_attention_net_onnx2om.bash -``` - -# 四. om模型离线推理,性能及精度测试 -1. bs1离线推理测试 -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=3d_attention_net_resize_autotune_optimized_bs1.om -input_text_path=3d_attention_net_prep_bin.info -input_width=32 -input_height=32 -output_binary=False -useDvpp=False -python3.7 3d_attention_net_postprocess.py 0 -``` -python3.7 3d_attention_net_postprocess.py $DEVICE_ID -传入的第一个参数DEVICE_ID为指定device的输出,应与benchmark传入的device_id保持一致,下同 - -2. bs16离线推理测试 -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=3d_attention_net_resize_autotune_optimized_bs16.om -input_text_path=3d_attention_net_prep_bin.info -input_width=32 -input_height=32 -output_binary=False -useDvpp=False -python3.7 3d_attention_net_postprocess.py 0 -``` - -3. GPU性能测试 -``` -bash perf_g.sh -``` - -4. 性能&精度对比 - - -|模型|官网pkl精度|310离线推理精度|基准性能|310性能|精度对比
(310/基准)|性能对比
(310/基准)| -|-|:-:|:-:|:-:|:-:|:-:|:-:| -|3d_attention_net_bs1|Top-1:95.4%|Top-1:95.34%|659.2fps|1479.5fps|99.94%|1479.5/659.2| -|3d_attention_net_bs16|Top-1:95.4%|Top-1:95.34%|3494.16fps|3980.4fps|99.94%|3980.4/3494.16| - +# 一. 环境准备 +1. 安装必要的依赖,运行所需的依赖详见requirements.txt +2. 获取开源模型代码及权重文件 +``` +git clone https://github.com/tengshaofeng/ResidualAttentionNetwork-pytorch.git +cd ResidualAttentionNetwork-pytorch +git checkout 44d09fe9afc0d5fba6f3f63b8375069ae9d54a56 +cd Residual-Attention-Network +cp -r model ../.. +cp model_92_sgd.pkl ../.. +cd ../.. +``` +3. 由于python版本问题,原模型代码在执行过程中会出现数据类型转换问题,依次执行以下命令 +``` +cd model/ +patch -p1 <../3d_attention_net.patch +cd .. +``` + +4. 获取benchmark工具 + 将benchmark.x86_64放到当前目录。 +5. 获取OXInterface.py +``` +git clone https://gitee.com/zheng-wengang1/onnx_tools.git +cd onnx_tools +git checkout cbb099e5f2cef3d76c7630bffe0ee8250b03d921 +cd .. +``` + +# 二. 数据预处理 +1. 获取CIFAR-10数据集 +``` +website:https://www.cs.toronto.edu/~kriz/cifar.html +#Version:CIFAR-10 python version +#md5sum:c58f30108f718f92721af3b95e74349a +``` +2. 上传数据集 +``` +mkdir data +``` +3. 将下载的CIFAR-10数据集上传至data文件夹,而后执行如下命令: +``` +tar -zxvf data/cifar-10-python.tar.gz -C data/ +``` +4. 数据预处理 +``` +python3.7 3d_attention_net_preprocess.py +``` + +5. 生成预处理后的数据集信息文件 +``` +python3.7 gen_dataset_info.py bin ./pre_process_result/ ./3d_attention_net_prep_bin.info 32 32 +``` + +# 三. pkl文件转om模型 +1. 读取源代码仓中的pkl文件,将原始模型转换为onnx +``` +python3.7 3d_attention_net_pkl2onnx.py +``` + +2. 对onnx模型中的resize操作进行优化 +``` +python3.7 resize_optimize.py +``` + +3. 通过Autotune进行性能调优并转换为om模型 +``` +bash test/3d_attention_net_onnx2om.bash +``` + +# 四. om模型离线推理,性能及精度测试 +1. bs1离线推理测试 +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=3d_attention_net_resize_autotune_optimized_bs1.om -input_text_path=3d_attention_net_prep_bin.info -input_width=32 -input_height=32 -output_binary=False -useDvpp=False +python3.7 3d_attention_net_postprocess.py 0 +``` +python3.7 3d_attention_net_postprocess.py $DEVICE_ID +传入的第一个参数DEVICE_ID为指定device的输出,应与benchmark传入的device_id保持一致,下同 + +2. bs16离线推理测试 +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=3d_attention_net_resize_autotune_optimized_bs16.om -input_text_path=3d_attention_net_prep_bin.info -input_width=32 -input_height=32 -output_binary=False -useDvpp=False +python3.7 3d_attention_net_postprocess.py 0 +``` + +3. GPU性能测试 +``` +bash perf_g.sh +``` + +4. 性能&精度对比 + + +|模型|官网pkl精度|310离线推理精度|基准性能|310性能|精度对比
(310/基准)|性能对比
(310/基准)| +|-|:-:|:-:|:-:|:-:|:-:|:-:| +|3d_attention_net_bs1|Top-1:95.4%|Top-1:95.34%|659.2fps|1479.5fps|99.94%|1479.5/659.2| +|3d_attention_net_bs16|Top-1:95.4%|Top-1:95.34%|3494.16fps|3980.4fps|99.94%|3980.4/3494.16| + diff --git a/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/requirements.txt index a89309f6209794e8311b29a4aae342a80243c8af..ec79d9f308d9ee670ae7c7a2266458ef9da2da5b 100644 --- a/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/requirements.txt @@ -1,6 +1,6 @@ -torch=1.8.1 -torchvision=0.9.0 -numpy=1.19.5 -glob2=0.7 -opencv-python=4.2.0.34 -onnx=1.8.1 +torch=1.8.1 +torchvision=0.9.0 +numpy=1.19.5 +glob2=0.7 +opencv-python=4.2.0.34 +onnx=1.8.1 diff --git a/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/resize_optimize.py b/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/resize_optimize.py index 426bc3a82455eb35ebba8e3d51f5644db4769b2d..52fa75baf494a0e4e8220d7291f6e6f4ee6b043a 100644 --- a/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/resize_optimize.py +++ b/ACL_PyTorch/contrib/cv/classfication/3d_attention_net/resize_optimize.py @@ -1,39 +1,39 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import os -import onnx -import numpy as np -from pprint import pprint -from onnx_tools.OXInterface.OXInterface import OXDataType, OXGraph, OXInitializer, OXNode - -oxgraph = OXGraph('3d_attention_net.onnx') -oxnode = oxgraph.get_oxnode_by_name('Resize_77') -oxnode.set_attribute(attr_name='coordinate_transformation_mode', attr_value="asymmetric") -oxnode.set_attribute(attr_name='mode', attr_value="nearest") - -oxnode = oxgraph.get_oxnode_by_name('Resize_96') -oxnode.set_attribute(attr_name='coordinate_transformation_mode', attr_value="asymmetric") -oxnode.set_attribute(attr_name='mode', attr_value="nearest") - -oxnode = oxgraph.get_oxnode_by_name('Resize_173') -oxnode.set_attribute(attr_name='coordinate_transformation_mode', attr_value="asymmetric") -oxnode.set_attribute(attr_name='mode', attr_value="nearest") - -oxnode = oxgraph.get_oxnode_by_name('Resize_241') -oxnode.set_attribute(attr_name='coordinate_transformation_mode', attr_value="asymmetric") -oxnode.set_attribute(attr_name='mode', attr_value="nearest") - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import os +import onnx +import numpy as np +from pprint import pprint +from onnx_tools.OXInterface.OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('3d_attention_net.onnx') +oxnode = oxgraph.get_oxnode_by_name('Resize_77') +oxnode.set_attribute(attr_name='coordinate_transformation_mode', attr_value="asymmetric") +oxnode.set_attribute(attr_name='mode', attr_value="nearest") + +oxnode = oxgraph.get_oxnode_by_name('Resize_96') +oxnode.set_attribute(attr_name='coordinate_transformation_mode', attr_value="asymmetric") +oxnode.set_attribute(attr_name='mode', attr_value="nearest") + +oxnode = oxgraph.get_oxnode_by_name('Resize_173') +oxnode.set_attribute(attr_name='coordinate_transformation_mode', attr_value="asymmetric") +oxnode.set_attribute(attr_name='mode', attr_value="nearest") + +oxnode = oxgraph.get_oxnode_by_name('Resize_241') +oxnode.set_attribute(attr_name='coordinate_transformation_mode', attr_value="asymmetric") +oxnode.set_attribute(attr_name='mode', attr_value="nearest") + oxgraph.save_new_model('3d_attention_net_resize_optimized.onnx') \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/AlexNet/LICENSE b/ACL_PyTorch/contrib/cv/classfication/AlexNet/LICENSE index b1fac45f02e2f98395fd96a7e4f4a39e257ac0bc..989e2c59e973a05cfbfe9de678b7f2af777b0713 100644 --- a/ACL_PyTorch/contrib/cv/classfication/AlexNet/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/AlexNet/LICENSE @@ -1,201 +1,201 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/C3D/C3D_postprocess.py b/ACL_PyTorch/contrib/cv/classfication/C3D/C3D_postprocess.py index e2aefdbbe904e8c21b7aa6a65ee0220f65403f3f..38cd64d13a80734ab8c0e1d651a4783960f25edf 100644 --- a/ACL_PyTorch/contrib/cv/classfication/C3D/C3D_postprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/C3D/C3D_postprocess.py @@ -1,68 +1,68 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import json -import torch -import sys - - -result_dir = sys.argv[1] # result_dir:推理得到的输出文件夹 -label_dir = sys.argv[2] # label_dir:标注文件的路径 -json_dir = sys.argv[3] -result_dir = os.listdir(result_dir) - -# 处理annotation文件,得到一个label字典,key为类名称,value为类的索引 -# label = {'v_Skiing_g04_c03': '80', 'v_SoccerPenalty_g02_c04': '84', ......} -label = dict() -f = open(label_dir) -x = f.readlines() -f.close() -for i in range(len(x)): - class_name = x[i].split(' ')[0].split('/')[1] - class_idx = x[i].split(' ')[2].replace('\n', '').replace('\r', '') - label[class_name] = class_idx - -file_name = result_dir - -num_correct_top1 = 0 -num_total = len(file_name) - -# 统计top1正确的个数 -for file_idx in range(num_total): - x = file_name[file_idx] - f = open(os.path.join(sys.argv[1], x)) - score = f.readline().replace('\n', '').replace('\r', '').split(' ') # score:list[str] - score = score[0:1010] - score = [float(i) for i in score] - f.close() - s = [[], [], [], [], [], [], [], [], [], []] - for i in range(10): - s[i] = score[101*i:101*i + 101] # 对于score中的1010个分数,每隔101个将其取出放到s数组中 - cls_score = torch.tensor(s).mean(dim=0) # 对10个clips得到的输出结果求平均 - max_value = cls_score[0] - idx = 0 - for i in range(len(cls_score)): - if cls_score[i] >= max_value: - max_value = cls_score[i] - idx = i - if label[x.split('.')[0].replace('_1', '')] == str(idx): - num_correct_top1 += 1 - -top1_acc = num_correct_top1/num_total -result_dict = {"top1_acc": top1_acc} -print(result_dict) -json_str = json.dumps(result_dict) -with open(json_dir, 'w') as json_file: - json_file.write(json_str) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import json +import torch +import sys + + +result_dir = sys.argv[1] # result_dir:推理得到的输出文件夹 +label_dir = sys.argv[2] # label_dir:标注文件的路径 +json_dir = sys.argv[3] +result_dir = os.listdir(result_dir) + +# 处理annotation文件,得到一个label字典,key为类名称,value为类的索引 +# label = {'v_Skiing_g04_c03': '80', 'v_SoccerPenalty_g02_c04': '84', ......} +label = dict() +f = open(label_dir) +x = f.readlines() +f.close() +for i in range(len(x)): + class_name = x[i].split(' ')[0].split('/')[1] + class_idx = x[i].split(' ')[2].replace('\n', '').replace('\r', '') + label[class_name] = class_idx + +file_name = result_dir + +num_correct_top1 = 0 +num_total = len(file_name) + +# 统计top1正确的个数 +for file_idx in range(num_total): + x = file_name[file_idx] + f = open(os.path.join(sys.argv[1], x)) + score = f.readline().replace('\n', '').replace('\r', '').split(' ') # score:list[str] + score = score[0:1010] + score = [float(i) for i in score] + f.close() + s = [[], [], [], [], [], [], [], [], [], []] + for i in range(10): + s[i] = score[101*i:101*i + 101] # 对于score中的1010个分数,每隔101个将其取出放到s数组中 + cls_score = torch.tensor(s).mean(dim=0) # 对10个clips得到的输出结果求平均 + max_value = cls_score[0] + idx = 0 + for i in range(len(cls_score)): + if cls_score[i] >= max_value: + max_value = cls_score[i] + idx = i + if label[x.split('.')[0].replace('_1', '')] == str(idx): + num_correct_top1 += 1 + +top1_acc = num_correct_top1/num_total +result_dict = {"top1_acc": top1_acc} +print(result_dict) +json_str = json.dumps(result_dict) +with open(json_dir, 'w') as json_file: + json_file.write(json_str) diff --git a/ACL_PyTorch/contrib/cv/classfication/C3D/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/C3D/modelzoo_level.txt index 403465b84e39e2cc8a387c33aaf5a1043f8d267a..ec6168981c278bbe672c13a4eb251b6ec184eda4 100644 --- a/ACL_PyTorch/contrib/cv/classfication/C3D/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/C3D/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:Perfect \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/CSPResneXt50/LICENSE b/ACL_PyTorch/contrib/cv/classfication/CSPResneXt50/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/CSPResneXt50/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/CSPResneXt50/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Deit_Small/LICENSE b/ACL_PyTorch/contrib/cv/classfication/Deit_Small/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Deit_Small/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/Deit_Small/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Deit_Small/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/classfication/Deit_Small/gen_dataset_info.py index 80c2b0fc300d7037330a166b23c562015cd17148..f80f45a34c450d57f0ea49d93167892d93a30e88 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Deit_Small/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/Deit_Small/gen_dataset_info.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) diff --git a/ACL_PyTorch/contrib/cv/classfication/Deit_Small/imagenet_acc_eval.py b/ACL_PyTorch/contrib/cv/classfication/Deit_Small/imagenet_acc_eval.py index 0e1db27e816a0cf3ec4fb21ee23e691315f3f959..9ec7d5da536ecdab1cf4fa8253dba62604376179 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Deit_Small/imagenet_acc_eval.py +++ b/ACL_PyTorch/contrib/cv/classfication/Deit_Small/imagenet_acc_eval.py @@ -1,183 +1,183 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - if data == '': - n_label = 0 - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - print("Time used:", elapsed) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) diff --git a/ACL_PyTorch/contrib/cv/classfication/Deit_Small/imagenet_torch_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/Deit_Small/imagenet_torch_preprocess.py index f7ca84a2561f8e3d907f6d81cb34b792cd3e25a5..f1ed2bf166ecc2e790724d02526d68f9a5f9e022 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Deit_Small/imagenet_torch_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/Deit_Small/imagenet_torch_preprocess.py @@ -1,104 +1,104 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from PIL import Image -import numpy as np -import multiprocessing - - -model_config = { - 'deit': { - 'resize': 256, - 'centercrop': 224, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, -} - - -def center_crop(img, output_size): - if isinstance(output_size, int): - output_size = (int(output_size), int(output_size)) - image_width, image_height = img.size - crop_height, crop_width = output_size - crop_top = int(round((image_height - crop_height) / 2.)) - crop_left = int(round((image_width - crop_width) / 2.)) - return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) - - -def resize(img, size, interpolation=Image.BILINEAR): - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def gen_input_bin(mode_type, file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - # RGBA to RGB - image = Image.open(os.path.join(src_path, file)).convert('RGB') - image = resize(image, model_config[mode_type]['resize']) # Resize - image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop - img = np.array(image, dtype=np.float32) - img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW - img = img / 255. # ToTensor: div 255 - img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean - img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - - -def preprocess(mode_type, src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python imagenet_torch_preprocess.py [model_type] [src_path] [save_path]") - mode_type = sys.argv[1] - src_path = sys.argv[2] - save_path = sys.argv[3] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - if mode_type not in model_config: - model_type_help = "model type: " - for key in model_config.keys(): - model_type_help += key - model_type_help += ' ' - raise Exception(model_type_help) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - preprocess(mode_type, src_path, save_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from PIL import Image +import numpy as np +import multiprocessing + + +model_config = { + 'deit': { + 'resize': 256, + 'centercrop': 224, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, +} + + +def center_crop(img, output_size): + if isinstance(output_size, int): + output_size = (int(output_size), int(output_size)) + image_width, image_height = img.size + crop_height, crop_width = output_size + crop_top = int(round((image_height - crop_height) / 2.)) + crop_left = int(round((image_width - crop_width) / 2.)) + return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) + + +def resize(img, size, interpolation=Image.BILINEAR): + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def gen_input_bin(mode_type, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + # RGBA to RGB + image = Image.open(os.path.join(src_path, file)).convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.float32) + img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW + img = img / 255. # ToTensor: div 255 + img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean + img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +def preprocess(mode_type, src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python imagenet_torch_preprocess.py [model_type] [src_path] [save_path]") + mode_type = sys.argv[1] + src_path = sys.argv[2] + save_path = sys.argv[3] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if mode_type not in model_config: + model_type_help = "model type: " + for key in model_config.keys(): + model_type_help += key + model_type_help += ' ' + raise Exception(model_type_help) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess(mode_type, src_path, save_path) diff --git a/ACL_PyTorch/contrib/cv/classfication/Deit_Small/parse.py b/ACL_PyTorch/contrib/cv/classfication/Deit_Small/parse.py index b9c74f41d7848e1250356f14472b237a18bb3489..82af69cd183218c3263723c20b652b3f7ec2bc27 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Deit_Small/parse.py +++ b/ACL_PyTorch/contrib/cv/classfication/Deit_Small/parse.py @@ -1,32 +1,32 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Deit_Small/test/README.md b/ACL_PyTorch/contrib/cv/classfication/Deit_Small/test/README.md index 0c8bb48bce3a21d432f0e88ab08f907e38029dcb..d53433c40a39e596782660f4357ce1de0932e106 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Deit_Small/test/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/Deit_Small/test/README.md @@ -1,24 +1,24 @@ -环境准备: - -1.数据集路径 -通用的数据集统一放在/root/datasets/或/opt/npu/ -本模型数据集路径为 /opt/npu/ - -2.进入工作目录 -cd Deit-Small - -3.导入所需的环境 -pip3.7 install -r requirements.txt - -4.获取模型代码 -git clone https://github.com/facebookresearch/deit.git - -5.获取权重文件 -wget https://dl.fbaipublicfiles.com/deit/deit_small_patch16_224-cd65a155.pth - -6.获取benchmark工具 -将benchmark.x86_64 benchmark.aarch64放在当前目录 - -7.310上执行,执行时确保device空闲 -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets +环境准备: + +1.数据集路径 +通用的数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集路径为 /opt/npu/ + +2.进入工作目录 +cd Deit-Small + +3.导入所需的环境 +pip3.7 install -r requirements.txt + +4.获取模型代码 +git clone https://github.com/facebookresearch/deit.git + +5.获取权重文件 +wget https://dl.fbaipublicfiles.com/deit/deit_small_patch16_224-cd65a155.pth + +6.获取benchmark工具 +将benchmark.x86_64 benchmark.aarch64放在当前目录 + +7.310上执行,执行时确保device空闲 +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets diff --git a/ACL_PyTorch/contrib/cv/classfication/Deit_Small/test/pth2om.sh b/ACL_PyTorch/contrib/cv/classfication/Deit_Small/test/pth2om.sh old mode 100755 new mode 100644 diff --git a/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/Efficient-3DCNNs_postprocess.py b/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/Efficient-3DCNNs_postprocess.py index c4bb75bf7dad764e801d6e98551e4224e1c4ef41..58cd26aba36b86eecd582294652280ca774155c6 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/Efficient-3DCNNs_postprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/Efficient-3DCNNs_postprocess.py @@ -1,113 +1,113 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import argparse -from pathlib import Path -import torch -import torch.nn.functional as F -import numpy as np -sys.path.append(r"./Efficient-3DCNNs/utils") -from eval_ucf101 import UCFclassification - -CLASS_NAMES = {0: 'ApplyEyeMakeup', 1: 'ApplyLipstick', 2: 'Archery', 3: 'BabyCrawling', 4: 'BalanceBeam', 5: 'BandMarching', - 6: 'BaseballPitch', 7: 'Basketball', 8: 'BasketballDunk', 9: 'BenchPress', 10: 'Biking', - 11: 'Billiards', 12: 'BlowDryHair', 13: 'BlowingCandles', 14: 'BodyWeightSquats', 15: 'Bowling', - 16: 'BoxingPunchingBag', 17: 'BoxingSpeedBag', 18: 'BreastStroke', 19: 'BrushingTeeth', 20: 'CleanAndJerk', - 21: 'CliffDiving', 22: 'CricketBowling', 23: 'CricketShot', 24: 'CuttingInKitchen', 25: 'Diving', - 26: 'Drumming', 27: 'Fencing', 28: 'FieldHockeyPenalty', 29: 'FloorGymnastics', 30: 'FrisbeeCatch', - 31: 'FrontCrawl', 32: 'GolfSwing', 33: 'Haircut', 34: 'Hammering', 35: 'HammerThrow', - 36: 'HandstandPushups', 37: 'HandstandWalking', 38: 'HeadMassage', 39: 'HighJump', 40: 'HorseRace', - 41: 'HorseRiding', 42: 'HulaHoop', 43: 'IceDancing', 44: 'JavelinThrow', 45: 'JugglingBalls', - 46: 'JumpingJack', 47: 'JumpRope', 48: 'Kayaking', 49: 'Knitting', 50: 'LongJump', - 51: 'Lunges', 52: 'MilitaryParade', 53: 'Mixing', 54: 'MoppingFloor', 55: 'Nunchucks', - 56: 'ParallelBars', 57: 'PizzaTossing', 58: 'PlayingCello', 59: 'PlayingDaf', 60: 'PlayingDhol', - 61: 'PlayingFlute', 62: 'PlayingGuitar', 63: 'PlayingPiano', 64: 'PlayingSitar', 65: 'PlayingTabla', - 66: 'PlayingViolin', 67: 'PoleVault', 68: 'PommelHorse', 69: 'PullUps', 70: 'Punch', - 71: 'PushUps', 72: 'Rafting', 73: 'RockClimbingIndoor', 74: 'RopeClimbing', 75: 'Rowing', - 76: 'SalsaSpin', 77: 'ShavingBeard', 78: 'Shotput', 79: 'SkateBoarding', 80: 'Skiing', - 81: 'Skijet', 82: 'SkyDiving', 83: 'SoccerJuggling', 84: 'SoccerPenalty', 85: 'StillRings', - 86: 'SumoWrestling', 87: 'Surfing', 88: 'Swing', 89: 'TableTennisShot', 90: 'TaiChi', - 91: 'TennisSwing', 92: 'ThrowDiscus', 93: 'TrampolineJumping', 94: 'Typing', 95: 'UnevenBars', - 96: 'VolleyballSpiking', 97: 'WalkingWithDog', 98: 'WallPushups', 99: 'WritingOnBoard', 100: 'YoYo'} - -def calculate_video_results(output_buffer, video_id, test_results, class_names): - video_outputs = torch.stack(output_buffer) - average_scores = torch.mean(video_outputs, dim=0) - sorted_scores, locs = torch.topk(average_scores, k=10) - - video_results = [] - for i in range(sorted_scores.size(0)): - video_results.append({ - 'label': class_names[int(locs[i])], - 'score': float(sorted_scores[i]) - }) - - test_results['results'][video_id] = video_results - -def evaluate(result_path, class_names, info_path, annotation_path, acc_file): - print('postprocessing') - f = open(info_path, 'r') - ucf101_info = f.readlines() - bin_path = os.listdir(result_path)[0] - result_path = os.path.join(result_path, bin_path) - bin_list = os.listdir(result_path) - bin_list.sort(key= lambda x:int(x[:-13])) - output_buffer = [] - previous_video_id = '' - test_results = {'results': {}} - for i, line in enumerate(ucf101_info): - targets = line.split(' ') - targets = targets[0:len(targets)-1] - bin_path = os.path.join(result_path, bin_list[i]) - outputs = np.fromfile(bin_path, dtype=np.float32).reshape(-1, 101) - outputs = torch.from_numpy(outputs) - outputs = F.softmax(outputs, dim=1).cpu() - for j in range(outputs.size(0)): - if not (i == 0 and j == 0) and targets[j] != previous_video_id: - calculate_video_results(output_buffer, previous_video_id, - test_results, class_names) - output_buffer = [] - output_buffer.append(outputs[j].data.cpu()) - previous_video_id = targets[j] - - if (i % 100) == 0: - with open('val.json', 'w') as f: - json.dump(test_results, f) - if (i % 1000) == 0: - print('[{}/{}]'.format(i+1, len(bin_list))) - with open('val.json', 'w') as f: - json.dump(test_results, f) - - ucf_acc_t1 = UCFclassification(annotation_path, 'val.json', subset='validation', top_k=1) - ucf_acc_t1.evaluate() - - ucf_acc_t5 = UCFclassification(annotation_path, 'val.json', subset='validation', top_k=5) - ucf_acc_t5.evaluate() - - with open(acc_file, 'w') as f: - json.dump('top1 acc:'+str(ucf_acc_t1.hit_at_k)+'; top5 acc:'+str(ucf_acc_t5.hit_at_k), f) - print('postprocess finised') - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='preprocess of 3D-ResNets') - parser.add_argument('--result_path', default='', type=Path, help='Directory path of videos') - parser.add_argument('--info_path', default='', type=Path, help='Directory path of binary output data') - parser.add_argument('--annotation_path', default='', type=Path, help='Annotation file path') - parser.add_argument('--acc_file', default='', type=Path, help='Directory path of binary output data') - opt = parser.parse_args() - evaluate(opt.result_path, CLASS_NAMES, opt.info_path, opt.annotation_path, opt.acc_file) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import argparse +from pathlib import Path +import torch +import torch.nn.functional as F +import numpy as np +sys.path.append(r"./Efficient-3DCNNs/utils") +from eval_ucf101 import UCFclassification + +CLASS_NAMES = {0: 'ApplyEyeMakeup', 1: 'ApplyLipstick', 2: 'Archery', 3: 'BabyCrawling', 4: 'BalanceBeam', 5: 'BandMarching', + 6: 'BaseballPitch', 7: 'Basketball', 8: 'BasketballDunk', 9: 'BenchPress', 10: 'Biking', + 11: 'Billiards', 12: 'BlowDryHair', 13: 'BlowingCandles', 14: 'BodyWeightSquats', 15: 'Bowling', + 16: 'BoxingPunchingBag', 17: 'BoxingSpeedBag', 18: 'BreastStroke', 19: 'BrushingTeeth', 20: 'CleanAndJerk', + 21: 'CliffDiving', 22: 'CricketBowling', 23: 'CricketShot', 24: 'CuttingInKitchen', 25: 'Diving', + 26: 'Drumming', 27: 'Fencing', 28: 'FieldHockeyPenalty', 29: 'FloorGymnastics', 30: 'FrisbeeCatch', + 31: 'FrontCrawl', 32: 'GolfSwing', 33: 'Haircut', 34: 'Hammering', 35: 'HammerThrow', + 36: 'HandstandPushups', 37: 'HandstandWalking', 38: 'HeadMassage', 39: 'HighJump', 40: 'HorseRace', + 41: 'HorseRiding', 42: 'HulaHoop', 43: 'IceDancing', 44: 'JavelinThrow', 45: 'JugglingBalls', + 46: 'JumpingJack', 47: 'JumpRope', 48: 'Kayaking', 49: 'Knitting', 50: 'LongJump', + 51: 'Lunges', 52: 'MilitaryParade', 53: 'Mixing', 54: 'MoppingFloor', 55: 'Nunchucks', + 56: 'ParallelBars', 57: 'PizzaTossing', 58: 'PlayingCello', 59: 'PlayingDaf', 60: 'PlayingDhol', + 61: 'PlayingFlute', 62: 'PlayingGuitar', 63: 'PlayingPiano', 64: 'PlayingSitar', 65: 'PlayingTabla', + 66: 'PlayingViolin', 67: 'PoleVault', 68: 'PommelHorse', 69: 'PullUps', 70: 'Punch', + 71: 'PushUps', 72: 'Rafting', 73: 'RockClimbingIndoor', 74: 'RopeClimbing', 75: 'Rowing', + 76: 'SalsaSpin', 77: 'ShavingBeard', 78: 'Shotput', 79: 'SkateBoarding', 80: 'Skiing', + 81: 'Skijet', 82: 'SkyDiving', 83: 'SoccerJuggling', 84: 'SoccerPenalty', 85: 'StillRings', + 86: 'SumoWrestling', 87: 'Surfing', 88: 'Swing', 89: 'TableTennisShot', 90: 'TaiChi', + 91: 'TennisSwing', 92: 'ThrowDiscus', 93: 'TrampolineJumping', 94: 'Typing', 95: 'UnevenBars', + 96: 'VolleyballSpiking', 97: 'WalkingWithDog', 98: 'WallPushups', 99: 'WritingOnBoard', 100: 'YoYo'} + +def calculate_video_results(output_buffer, video_id, test_results, class_names): + video_outputs = torch.stack(output_buffer) + average_scores = torch.mean(video_outputs, dim=0) + sorted_scores, locs = torch.topk(average_scores, k=10) + + video_results = [] + for i in range(sorted_scores.size(0)): + video_results.append({ + 'label': class_names[int(locs[i])], + 'score': float(sorted_scores[i]) + }) + + test_results['results'][video_id] = video_results + +def evaluate(result_path, class_names, info_path, annotation_path, acc_file): + print('postprocessing') + f = open(info_path, 'r') + ucf101_info = f.readlines() + bin_path = os.listdir(result_path)[0] + result_path = os.path.join(result_path, bin_path) + bin_list = os.listdir(result_path) + bin_list.sort(key= lambda x:int(x[:-13])) + output_buffer = [] + previous_video_id = '' + test_results = {'results': {}} + for i, line in enumerate(ucf101_info): + targets = line.split(' ') + targets = targets[0:len(targets)-1] + bin_path = os.path.join(result_path, bin_list[i]) + outputs = np.fromfile(bin_path, dtype=np.float32).reshape(-1, 101) + outputs = torch.from_numpy(outputs) + outputs = F.softmax(outputs, dim=1).cpu() + for j in range(outputs.size(0)): + if not (i == 0 and j == 0) and targets[j] != previous_video_id: + calculate_video_results(output_buffer, previous_video_id, + test_results, class_names) + output_buffer = [] + output_buffer.append(outputs[j].data.cpu()) + previous_video_id = targets[j] + + if (i % 100) == 0: + with open('val.json', 'w') as f: + json.dump(test_results, f) + if (i % 1000) == 0: + print('[{}/{}]'.format(i+1, len(bin_list))) + with open('val.json', 'w') as f: + json.dump(test_results, f) + + ucf_acc_t1 = UCFclassification(annotation_path, 'val.json', subset='validation', top_k=1) + ucf_acc_t1.evaluate() + + ucf_acc_t5 = UCFclassification(annotation_path, 'val.json', subset='validation', top_k=5) + ucf_acc_t5.evaluate() + + with open(acc_file, 'w') as f: + json.dump('top1 acc:'+str(ucf_acc_t1.hit_at_k)+'; top5 acc:'+str(ucf_acc_t5.hit_at_k), f) + print('postprocess finised') + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='preprocess of 3D-ResNets') + parser.add_argument('--result_path', default='', type=Path, help='Directory path of videos') + parser.add_argument('--info_path', default='', type=Path, help='Directory path of binary output data') + parser.add_argument('--annotation_path', default='', type=Path, help='Annotation file path') + parser.add_argument('--acc_file', default='', type=Path, help='Directory path of binary output data') + opt = parser.parse_args() + evaluate(opt.result_path, CLASS_NAMES, opt.info_path, opt.annotation_path, opt.acc_file) diff --git a/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/Efficient-3DCNNs_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/Efficient-3DCNNs_preprocess.py index ff18e7092f24607ede4772bf5df5f715e6e59be5..4b9ee37b7f31bca4b048ef94d07f647963b2cdb0 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/Efficient-3DCNNs_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/Efficient-3DCNNs_preprocess.py @@ -1,92 +1,92 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import argparse -from pathlib import Path -import torch -import numpy as np -sys.path.append(r"./Efficient-3DCNNs") -from dataset import get_test_set -from spatial_transforms import Normalize, Compose, Scale, CornerCrop -from temporal_transforms import TemporalRandomCrop -from target_transforms import VideoID - -class ToTensor(object): - def __init__(self, norm_value=255): - self.norm_value = norm_value - - def __call__(self, pic): - img = np.array(pic, dtype=np.float32) - img = img.transpose(2, 0, 1) - img = img / self.norm_value - return torch.from_numpy(img) - - def randomize_parameters(self): - pass - -def preprocess(save_path): - print('preprocessing') - norm_method = Normalize([114.7748, 107.7354, 99.4750], [1, 1, 1]) - - spatial_transform = Compose([ - Scale(int(112 / 1.0)), - CornerCrop(112, 'c'), - ToTensor(1), norm_method - ]) - temporal_transform = TemporalRandomCrop(16, 1) - target_transform = VideoID() - - test_data = get_test_set(opt, spatial_transform, temporal_transform, - target_transform) - - test_loader = torch.utils.data.DataLoader(test_data, - batch_size=opt.inference_batch_size, - shuffle=False, - num_workers=0, - pin_memory=True) - if not os.path.exists(save_path): - os.makedirs(save_path) - file = open(opt.info_path, 'w') - cid = 0 - for i, (inputs, targets) in enumerate(test_loader): - if(len(targets) == opt.inference_batch_size): - info = '' - for j in range(len(targets)): - info = info + targets[j] + ' ' - batch_bin = inputs.cpu().numpy() - path_bin = str(save_path) + '/' + str(cid) + '.bin' - cid = cid + 1 - batch_bin.tofile(path_bin) - file.write(info) - file.write('\n') - if (i % 1000) == 0: - print('[{}/{}]'.format(i+1, len(test_loader))) - print('preprocess finished') - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='preprocess of 3D-ResNets') - parser.add_argument('--video_path', default='C:/Users/17270/Efficient-3DCNNs-master-2/annotation_UCF101/UCF-101-image/UCF-101-image', type=Path, help='Directory path of videos') - parser.add_argument('--annotation_path', default='ucf101_01.json', type=Path, help='Annotation file path') - parser.add_argument('--dataset', default='ucf101', type=str, help='Used dataset (activitynet | kinetics | ucf101 | hmdb51)') - parser.add_argument('--test_subset', default='val', type=str, help='Used subset in inference (train | val | test)') - parser.add_argument('--output_path', default='zjbintt', type=Path, help='Directory path of binary output data') - parser.add_argument('--info_path', default='zjbin1.info', type=Path, help='Directory path of binary output data') - parser.add_argument('--inference_batch_size', default=16, type=int, help='Batch Size for inference. 0 means this is the same as batch_size.') - parser.add_argument('--sample_duration', default=16, type=int, help='Temporal duration of inputs') - opt = parser.parse_args() - - preprocess(opt.output_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import argparse +from pathlib import Path +import torch +import numpy as np +sys.path.append(r"./Efficient-3DCNNs") +from dataset import get_test_set +from spatial_transforms import Normalize, Compose, Scale, CornerCrop +from temporal_transforms import TemporalRandomCrop +from target_transforms import VideoID + +class ToTensor(object): + def __init__(self, norm_value=255): + self.norm_value = norm_value + + def __call__(self, pic): + img = np.array(pic, dtype=np.float32) + img = img.transpose(2, 0, 1) + img = img / self.norm_value + return torch.from_numpy(img) + + def randomize_parameters(self): + pass + +def preprocess(save_path): + print('preprocessing') + norm_method = Normalize([114.7748, 107.7354, 99.4750], [1, 1, 1]) + + spatial_transform = Compose([ + Scale(int(112 / 1.0)), + CornerCrop(112, 'c'), + ToTensor(1), norm_method + ]) + temporal_transform = TemporalRandomCrop(16, 1) + target_transform = VideoID() + + test_data = get_test_set(opt, spatial_transform, temporal_transform, + target_transform) + + test_loader = torch.utils.data.DataLoader(test_data, + batch_size=opt.inference_batch_size, + shuffle=False, + num_workers=0, + pin_memory=True) + if not os.path.exists(save_path): + os.makedirs(save_path) + file = open(opt.info_path, 'w') + cid = 0 + for i, (inputs, targets) in enumerate(test_loader): + if(len(targets) == opt.inference_batch_size): + info = '' + for j in range(len(targets)): + info = info + targets[j] + ' ' + batch_bin = inputs.cpu().numpy() + path_bin = str(save_path) + '/' + str(cid) + '.bin' + cid = cid + 1 + batch_bin.tofile(path_bin) + file.write(info) + file.write('\n') + if (i % 1000) == 0: + print('[{}/{}]'.format(i+1, len(test_loader))) + print('preprocess finished') + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='preprocess of 3D-ResNets') + parser.add_argument('--video_path', default='C:/Users/17270/Efficient-3DCNNs-master-2/annotation_UCF101/UCF-101-image/UCF-101-image', type=Path, help='Directory path of videos') + parser.add_argument('--annotation_path', default='ucf101_01.json', type=Path, help='Annotation file path') + parser.add_argument('--dataset', default='ucf101', type=str, help='Used dataset (activitynet | kinetics | ucf101 | hmdb51)') + parser.add_argument('--test_subset', default='val', type=str, help='Used subset in inference (train | val | test)') + parser.add_argument('--output_path', default='zjbintt', type=Path, help='Directory path of binary output data') + parser.add_argument('--info_path', default='zjbin1.info', type=Path, help='Directory path of binary output data') + parser.add_argument('--inference_batch_size', default=16, type=int, help='Batch Size for inference. 0 means this is the same as batch_size.') + parser.add_argument('--sample_duration', default=16, type=int, help='Temporal duration of inputs') + opt = parser.parse_args() + + preprocess(opt.output_path) diff --git a/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/LICENSE b/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/LICENSE index 797bf40e85c5d2986ebcec9cb51aed979ca88b82..04adf5cbc620ad190547b092fa449e36df5f7bf4 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/LICENSE @@ -1,203 +1,203 @@ -Copyright 2018-2019 Open-MMLab. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2018-2019 Open-MMLab. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Copyright 2018-2019 Open-MMLab. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2019 Open-MMLab. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/README.md b/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/README.md index ae5d6a93cefccd3583bd3b82147b0f4e8e4d3091..532928808675d492552eb8fcc1ed8da10993d163 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/README.md @@ -1,49 +1,49 @@ -# Efficient-3DCNNs模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -``` -pip3.7 install -r requirements.txt -``` - -2.安装开源模型代码 -``` -git clone https://github.com/okankop/Efficient-3DCNNs -``` -> branch: master - -> commit id: d60c6c48cf2e81380d0a513e22e9d7f8467731af - -3.获取权重文件 - -[ucf101_mobilenetv2_1.0x_RGB_16_best.pth](https://drive.google.com/drive/folders/1u4DO7kjAQP6Zdh8CN65iT5ozp11mvE-H?usp=sharing) - -4.[获取UCF-101数据集](https://www.crcv.ucf.edu/data/UCF101/UCF101.rar) -将UCF101.rar文件解压,重命名为ucf101,放在 /root/datasets/文件夹下 - -``` -python3.7 Efficient-3DCNNs/utils/video_jpg_ucf101_hmdb51.py /root/datasets/ucf101/videos/ /root/datasets/ucf101/rawframes -python3.7 Efficient-3DCNNs/utils/n_frames_ucf101_hmdb51.py /root/datasets/ucf101/rawframes -``` -[获取json形式的annotation文件](https://github.com/okankop/Efficient-3DCNNs/tree/master/annotation_UCF101) -将ucf101_01.json放到当前目录 - -5.获取[msame](https://gitee.com/ascend/tools/tree/master/msame)和[benchmark](https://gitee.com/ascend/cann-benchmark/tree/master/infer)工具 -将msame和benchmark.x86_64(或benchmark.aarch64)放到当前目录 - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets/ -``` - **评测结果:** -| 模型 | pth精度 | 310精度 | 性能基准 | 310性能 | -| :------: | :------: | :------: | :------: | :------: | -| Efficient-3DCNNs bs1 | top1:81.100% top5:96.326% | top1:81.126% top5:96.299% | 619.767fps | 641.728fps | -| Efficient-3DCNNs bs16 | top1:81.100% top5:96.326% | top1:81.126% top5:96.299% | 393.696fps | 744.432fps | - - - +# Efficient-3DCNNs模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip3.7 install -r requirements.txt +``` + +2.安装开源模型代码 +``` +git clone https://github.com/okankop/Efficient-3DCNNs +``` +> branch: master + +> commit id: d60c6c48cf2e81380d0a513e22e9d7f8467731af + +3.获取权重文件 + +[ucf101_mobilenetv2_1.0x_RGB_16_best.pth](https://drive.google.com/drive/folders/1u4DO7kjAQP6Zdh8CN65iT5ozp11mvE-H?usp=sharing) + +4.[获取UCF-101数据集](https://www.crcv.ucf.edu/data/UCF101/UCF101.rar) +将UCF101.rar文件解压,重命名为ucf101,放在 /root/datasets/文件夹下 + +``` +python3.7 Efficient-3DCNNs/utils/video_jpg_ucf101_hmdb51.py /root/datasets/ucf101/videos/ /root/datasets/ucf101/rawframes +python3.7 Efficient-3DCNNs/utils/n_frames_ucf101_hmdb51.py /root/datasets/ucf101/rawframes +``` +[获取json形式的annotation文件](https://github.com/okankop/Efficient-3DCNNs/tree/master/annotation_UCF101) +将ucf101_01.json放到当前目录 + +5.获取[msame](https://gitee.com/ascend/tools/tree/master/msame)和[benchmark](https://gitee.com/ascend/cann-benchmark/tree/master/infer)工具 +将msame和benchmark.x86_64(或benchmark.aarch64)放到当前目录 + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets/ +``` + **评测结果:** +| 模型 | pth精度 | 310精度 | 性能基准 | 310性能 | +| :------: | :------: | :------: | :------: | :------: | +| Efficient-3DCNNs bs1 | top1:81.100% top5:96.326% | top1:81.126% top5:96.299% | 619.767fps | 641.728fps | +| Efficient-3DCNNs bs16 | top1:81.100% top5:96.326% | top1:81.126% top5:96.299% | 393.696fps | 744.432fps | + + + diff --git a/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/modelzoo_level.txt index 731399223951dc50392319c2f4e8e5245174c192..108cc882d65c41bd354b9c6373bcf882d112c26b 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:PERFECT \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/requirements.txt index ef82dd062536f09a47198a22e6147bd46ff69a1a..5768d0bd49edff9b27bc10315bd9b80d5b59b9ec 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs/requirements.txt @@ -1,7 +1,7 @@ -torch==1.5.0 -torchvision==0.6.0 -onnx == 1.7.0 -onnx-simplifier==0.3.6 -opencv-python==4.5.3.56 -scipy +torch==1.5.0 +torchvision==0.6.0 +onnx == 1.7.0 +onnx-simplifier==0.3.6 +opencv-python==4.5.3.56 +scipy pandas \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/Efficient-B1_postprocess.py b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/Efficient-B1_postprocess.py index d51eb6e5f91ae430de0518a476cb4d6f5162cef1..7f8389d56eb971ec0f5eab66f088b72cbf570a29 100644 --- a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/Efficient-B1_postprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/Efficient-B1_postprocess.py @@ -1,72 +1,72 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import os -import argparse -import re -import numpy -import json - -def rename(data_dir, pre_dir): - txtfile_2_class = dict() - for classname in os.listdir(data_dir): - for imgname in os.listdir(os.path.join(data_dir, classname)): - txtfile_2_class[os.path.splitext(imgname)[0].split("_")[2]] = classname - omoutput_txts = os.listdir(pre_dir) - for omtxt in omoutput_txts: - if omtxt.split("_")[0] not in txtfile_2_class.values(): - os.rename(os.path.join(pre_dir, omtxt), os.path.join(pre_dir, txtfile_2_class.get(omtxt.split("_")[2]) + "_" + omtxt)) - -def classification(data_path): - files = os.listdir(data_path) - class_ids = sorted(f for f in files if re.match(r"^n[0-9]+$", f)) - return class_ids - - -def eval(data_dir, pred_dir, save_file): - txtfiles = os.listdir(pred_dir) - top1_acc = 0 - top5_acc = 0 - for txtfile in txtfiles: - print("loading {}".format(txtfile)) - pre_num = numpy.loadtxt(os.path.join(pred_dir, txtfile)) - class_ids = classification(data_dir) - class_pres = zip(class_ids, pre_num) - class_pres_dict = dict((class_id, value) for class_id, value in class_pres) - class_sort = max(class_pres_dict.items(), key=lambda x: x[1]) - if txtfile.split('_')[0] == class_sort[0]: - top1_acc = top1_acc + 1 - iteams = sorted(class_pres_dict.items(), key=lambda x: x[1]) - if txtfile.split('_')[0] in [iteams[999][0], iteams[998][0], iteams[997][0], iteams[996][0], iteams[995][0]]: - top5_acc = top5_acc + 1 - - topn_acc = dict() - topn_acc['Top1 accuracy'] = str(top1_acc / 50000 * 100) + "%" - topn_acc['Top5 accuracy'] = str(top5_acc / 50000 * 100) + "%" - print(topn_acc['Top1 accuracy']) - print(topn_acc['Top5 accuracy']) - writer = open(save_file, 'w') - json.dump(topn_acc, writer) - writer.close() - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--data_dir", default="./imagenet/val") - parser.add_argument("--pre_dir", default="./result/dumpOutput_device0/") - parser.add_argument("--save_file", default="./result.json") - args = parser.parse_args() - rename(args.data_dir, args.pre_dir) - eval(args.data_dir, args.pre_dir, args.save_file) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import os +import argparse +import re +import numpy +import json + +def rename(data_dir, pre_dir): + txtfile_2_class = dict() + for classname in os.listdir(data_dir): + for imgname in os.listdir(os.path.join(data_dir, classname)): + txtfile_2_class[os.path.splitext(imgname)[0].split("_")[2]] = classname + omoutput_txts = os.listdir(pre_dir) + for omtxt in omoutput_txts: + if omtxt.split("_")[0] not in txtfile_2_class.values(): + os.rename(os.path.join(pre_dir, omtxt), os.path.join(pre_dir, txtfile_2_class.get(omtxt.split("_")[2]) + "_" + omtxt)) + +def classification(data_path): + files = os.listdir(data_path) + class_ids = sorted(f for f in files if re.match(r"^n[0-9]+$", f)) + return class_ids + + +def eval(data_dir, pred_dir, save_file): + txtfiles = os.listdir(pred_dir) + top1_acc = 0 + top5_acc = 0 + for txtfile in txtfiles: + print("loading {}".format(txtfile)) + pre_num = numpy.loadtxt(os.path.join(pred_dir, txtfile)) + class_ids = classification(data_dir) + class_pres = zip(class_ids, pre_num) + class_pres_dict = dict((class_id, value) for class_id, value in class_pres) + class_sort = max(class_pres_dict.items(), key=lambda x: x[1]) + if txtfile.split('_')[0] == class_sort[0]: + top1_acc = top1_acc + 1 + iteams = sorted(class_pres_dict.items(), key=lambda x: x[1]) + if txtfile.split('_')[0] in [iteams[999][0], iteams[998][0], iteams[997][0], iteams[996][0], iteams[995][0]]: + top5_acc = top5_acc + 1 + + topn_acc = dict() + topn_acc['Top1 accuracy'] = str(top1_acc / 50000 * 100) + "%" + topn_acc['Top5 accuracy'] = str(top5_acc / 50000 * 100) + "%" + print(topn_acc['Top1 accuracy']) + print(topn_acc['Top5 accuracy']) + writer = open(save_file, 'w') + json.dump(topn_acc, writer) + writer.close() + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--data_dir", default="./imagenet/val") + parser.add_argument("--pre_dir", default="./result/dumpOutput_device0/") + parser.add_argument("--save_file", default="./result.json") + args = parser.parse_args() + rename(args.data_dir, args.pre_dir) + eval(args.data_dir, args.pre_dir, args.save_file) diff --git a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/Efficient-B1_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/Efficient-B1_preprocess.py index 09fb97aadc02bfeb9f90a0e5e3731778e4a3cb9f..a9b71deb632572f83bfaa8b1666d98a81937ada0 100644 --- a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/Efficient-B1_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/Efficient-B1_preprocess.py @@ -1,63 +1,63 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -sys.path.append("./pycls") -import numpy as np -import cv2 - -from pycls.datasets import transforms - -_EIG_VALS = [[0.2175, 0.0188, 0.0045]] -_EIG_VECS = [ - [-0.5675, 0.7192, 0.4009], - [-0.5808, -0.0045, -0.8140], - [-0.5836, -0.6948, 0.4203], -] -_MEAN = [0.485, 0.456, 0.406] -_STD = [0.229, 0.224, 0.225] - -train_size = 240 -test_size = 274 - -def trans(im): - im = im[:, :, ::-1].astype(np.float32) / 255 - im = transforms.scale_and_center_crop(im, test_size, train_size) - im = transforms.color_norm(im, _MEAN, _STD) - im = np.ascontiguousarray(im[:, :, ::-1].transpose([2, 0, 1])) - return im - -def EffnetB1_preprocess(src_path, save_path): - i = 0 - classes = os.listdir(src_path) - for classname in classes: - dirs = os.path.join(src_path, classname) - save_dir = os.path.join(save_path, classname) - if not os.path.isdir(save_dir): - os.makedirs(os.path.realpath(save_dir)) - for img in os.listdir(dirs): - i = i + 1 - print(img, "===", i) - img_path = os.path.join(dirs, img) - im = cv2.imread(img_path) - im = trans(im) - im.tofile(os.path.join(save_dir, img.split('.')[0] + ".bin")) - -if __name__ == '__main__': - src_path = sys.argv[1] - save_path = sys.argv[2] - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +sys.path.append("./pycls") +import numpy as np +import cv2 + +from pycls.datasets import transforms + +_EIG_VALS = [[0.2175, 0.0188, 0.0045]] +_EIG_VECS = [ + [-0.5675, 0.7192, 0.4009], + [-0.5808, -0.0045, -0.8140], + [-0.5836, -0.6948, 0.4203], +] +_MEAN = [0.485, 0.456, 0.406] +_STD = [0.229, 0.224, 0.225] + +train_size = 240 +test_size = 274 + +def trans(im): + im = im[:, :, ::-1].astype(np.float32) / 255 + im = transforms.scale_and_center_crop(im, test_size, train_size) + im = transforms.color_norm(im, _MEAN, _STD) + im = np.ascontiguousarray(im[:, :, ::-1].transpose([2, 0, 1])) + return im + +def EffnetB1_preprocess(src_path, save_path): + i = 0 + classes = os.listdir(src_path) + for classname in classes: + dirs = os.path.join(src_path, classname) + save_dir = os.path.join(save_path, classname) + if not os.path.isdir(save_dir): + os.makedirs(os.path.realpath(save_dir)) + for img in os.listdir(dirs): + i = i + 1 + print(img, "===", i) + img_path = os.path.join(dirs, img) + im = cv2.imread(img_path) + im = trans(im) + im.tofile(os.path.join(save_dir, img.split('.')[0] + ".bin")) + +if __name__ == '__main__': + src_path = sys.argv[1] + save_path = sys.argv[2] + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) EffnetB1_preprocess(src_path, save_path) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/Efficient-B1_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/Efficient-B1_pth2onnx.py index f79c4391c06a5492c4c082d0074fd0595ae3363a..53a95a7aae76624996b6561f6e9aa9fa929dc4f5 100644 --- a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/Efficient-B1_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/Efficient-B1_pth2onnx.py @@ -1,51 +1,51 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import argparse -import sys -import torch -from collections import OrderedDict -sys.path.append('./pycls') -from pycls.models.effnet import EffNet -import pycls.core.config as config -from pycls.core.config import cfg - -def proc_node_module(checkpoint, attr_name): - new_model_state = OrderedDict() - for k, v in checkpoint[attr_name].items(): - if(k[0: 7] == "module."): - name = k[7:] - else: - name = k[0:] - new_model_state[name] = v - return new_model_state - -def main(input_file, yaml_file, output_file): - config.load_cfg(yaml_file) - cfg.freeze() - model = EffNet() - checkpoint = torch.load(input_file, map_location='cpu') - checkpoint['model_state'] = proc_node_module(checkpoint, 'model_state') - model.load_state_dict(checkpoint["model_state"]) - model.eval() - input_names = ["image"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(1, 3, 240, 240) - torch.onnx.export(model, dummy_input, output_file, input_names=input_names, dynamic_axes=dynamic_axes, opset_version=11, verbose=True) - - -if __name__ == '__main__': - input_file = sys.argv[1] - yaml_file= sys.argv[2] - output_file = sys.argv[3] - main(input_file, yaml_file, output_file) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import argparse +import sys +import torch +from collections import OrderedDict +sys.path.append('./pycls') +from pycls.models.effnet import EffNet +import pycls.core.config as config +from pycls.core.config import cfg + +def proc_node_module(checkpoint, attr_name): + new_model_state = OrderedDict() + for k, v in checkpoint[attr_name].items(): + if(k[0: 7] == "module."): + name = k[7:] + else: + name = k[0:] + new_model_state[name] = v + return new_model_state + +def main(input_file, yaml_file, output_file): + config.load_cfg(yaml_file) + cfg.freeze() + model = EffNet() + checkpoint = torch.load(input_file, map_location='cpu') + checkpoint['model_state'] = proc_node_module(checkpoint, 'model_state') + model.load_state_dict(checkpoint["model_state"]) + model.eval() + input_names = ["image"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 240, 240) + torch.onnx.export(model, dummy_input, output_file, input_names=input_names, dynamic_axes=dynamic_axes, opset_version=11, verbose=True) + + +if __name__ == '__main__': + input_file = sys.argv[1] + yaml_file= sys.argv[2] + output_file = sys.argv[3] + main(input_file, yaml_file, output_file) diff --git a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/ImageNet_val_split.py b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/ImageNet_val_split.py index 3d5780c7cbb83466a7cf74b82d3908ca3e038a4a..244e28b791b82b82fba7e649fc0d69b3133530c5 100644 --- a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/ImageNet_val_split.py +++ b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/ImageNet_val_split.py @@ -1,62 +1,62 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import scipy -import sys -import shutil -from scipy import io - -def move_valimg(val_dir='./val', devkit_dir='./ILSVRC2012_devkit_t12'): - """ - move valimg to correspongding folders. - val_id(start from 1) -> ILSVRC_ID(start from 1) -> WIND - organize like: - /val - /n01440764 - images - /n01443537 - images - ..... - """ - # load synset, val ground truth and val images list - synset = io.loadmat(os.path.join(devkit_dir, 'data', 'meta.mat')) - - ground_truth = open(os.path.join(devkit_dir, 'data', 'ILSVRC2012_validation_ground_truth.txt')) - lines = ground_truth.readlines() - labels = [int(line[:-1]) for line in lines] - - root, _, filenames = next(os.walk(val_dir)) - for filename in filenames: - # val image name -> ILSVRC ID -> WIND - val_id = int(filename.split('.')[0].split('_')[-1]) - ILSVRC_ID = labels[val_id-1] - WIND = synset['synsets'][ILSVRC_ID-1][0][1][0] - print("val_id:%d, ILSVRC_ID:%d, WIND:%s" % (val_id, ILSVRC_ID, WIND)) - - # move val images - output_dir = os.path.join(root, WIND) - if os.path.isdir(output_dir): - pass - else: - os.mkdir(output_dir) - shutil.move(os.path.join(root, filename), os.path.join(output_dir, filename)) - -def main(val_path, devkit_path): - move_valimg(val_path, devkit_path) - -if __name__ == '__main__': - val_path = sys.argv[1] - devkit_path = sys.argv[2] - main(val_path, devkit_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import scipy +import sys +import shutil +from scipy import io + +def move_valimg(val_dir='./val', devkit_dir='./ILSVRC2012_devkit_t12'): + """ + move valimg to correspongding folders. + val_id(start from 1) -> ILSVRC_ID(start from 1) -> WIND + organize like: + /val + /n01440764 + images + /n01443537 + images + ..... + """ + # load synset, val ground truth and val images list + synset = io.loadmat(os.path.join(devkit_dir, 'data', 'meta.mat')) + + ground_truth = open(os.path.join(devkit_dir, 'data', 'ILSVRC2012_validation_ground_truth.txt')) + lines = ground_truth.readlines() + labels = [int(line[:-1]) for line in lines] + + root, _, filenames = next(os.walk(val_dir)) + for filename in filenames: + # val image name -> ILSVRC ID -> WIND + val_id = int(filename.split('.')[0].split('_')[-1]) + ILSVRC_ID = labels[val_id-1] + WIND = synset['synsets'][ILSVRC_ID-1][0][1][0] + print("val_id:%d, ILSVRC_ID:%d, WIND:%s" % (val_id, ILSVRC_ID, WIND)) + + # move val images + output_dir = os.path.join(root, WIND) + if os.path.isdir(output_dir): + pass + else: + os.mkdir(output_dir) + shutil.move(os.path.join(root, filename), os.path.join(output_dir, filename)) + +def main(val_path, devkit_path): + move_valimg(val_path, devkit_path) + +if __name__ == '__main__': + val_path = sys.argv[1] + devkit_path = sys.argv[2] + main(val_path, devkit_path) diff --git a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/LICENSE b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/LICENSE index 29f81d812f3e768fa89638d1f72920dbfd1413a8..261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64 100644 --- a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/README.md b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/README.md index edbf5b3267d4a11fad19674662708cf959cb5476..aa1efa1719fb0978a9a182472f402fe18d7973d9 100644 --- a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/README.md @@ -1,48 +1,48 @@ -# EfficientNet-B1模型PyTorch离线推理指导 -# 环境准备: - -1.数据集 - -测试数据集为ImageNet的官方 2012的val数据集,5w张图片放置在一个文件夹下,并由官方对应的 ILSVRC2012_devkit_t12 文件夹。 - -第一个参数为 新下载且未分类的 imagenet的val 数据集路径, - -第二个参数为官方 提供的 devkit 文件夹,如果要保留val文件夹请先备份 - -``` -python3.7 ImageNet_val_split.py ./val ./ILSVRC2012_devkit_t12 -``` - -2.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -``` -pip3.7 install -r requirements.txt -``` -3.获取模型代码 -``` -git clone https://github.com/facebookresearch/pycls -cd pycls -git reset f20820e01eef7b9a47b77f13464e3e77c44d5e1f --hard -cd .. -``` - -4.获取权重文件 -``` -wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/image_classification/EfficientNet-B1/EN-B1_dds_8gpu.pyth -``` -5.获取benchmark工具 -将benchmark.x86_64 benchmark.aarch64放在当前目录 - -# 2 离线推理 - -310上执行,执行时确保device空闲 -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets -``` -评测结果: - -| 模型 | 开源仓pth精度 | 310精度 | 性能基准 | 310性能 | -| :---------------: | :--------: | :--------------------: | :---------: | :---------: | -| Efficient-B1 bs1 | top1:75.9% | top1:75.5% top5:92.78% | 694.137fps | 940.524fps | -| Efficient-B1 bs16 | top1:75.9% | top1:75.5% top5:92.78% | 1408.138fps | 1490.54fps | - +# EfficientNet-B1模型PyTorch离线推理指导 +# 环境准备: + +1.数据集 + +测试数据集为ImageNet的官方 2012的val数据集,5w张图片放置在一个文件夹下,并由官方对应的 ILSVRC2012_devkit_t12 文件夹。 + +第一个参数为 新下载且未分类的 imagenet的val 数据集路径, + +第二个参数为官方 提供的 devkit 文件夹,如果要保留val文件夹请先备份 + +``` +python3.7 ImageNet_val_split.py ./val ./ILSVRC2012_devkit_t12 +``` + +2.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip3.7 install -r requirements.txt +``` +3.获取模型代码 +``` +git clone https://github.com/facebookresearch/pycls +cd pycls +git reset f20820e01eef7b9a47b77f13464e3e77c44d5e1f --hard +cd .. +``` + +4.获取权重文件 +``` +wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/image_classification/EfficientNet-B1/EN-B1_dds_8gpu.pyth +``` +5.获取benchmark工具 +将benchmark.x86_64 benchmark.aarch64放在当前目录 + +# 2 离线推理 + +310上执行,执行时确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets +``` +评测结果: + +| 模型 | 开源仓pth精度 | 310精度 | 性能基准 | 310性能 | +| :---------------: | :--------: | :--------------------: | :---------: | :---------: | +| Efficient-B1 bs1 | top1:75.9% | top1:75.5% top5:92.78% | 694.137fps | 940.524fps | +| Efficient-B1 bs16 | top1:75.9% | top1:75.5% top5:92.78% | 1408.138fps | 1490.54fps | + diff --git a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/gen_dataset_info.py index 9ecd822b4e47491a1e81663266eed5dfbf1d8b88..a07929cc79bb21b6799890a82e394e396a70519a 100644 --- a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/gen_dataset_info.py @@ -1,43 +1,43 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - index = 0 - with open(info_name, 'w') as file: - for classes in os.listdir(file_path): - bin_dir_path = os.path.join(file_path, classes) - bin_images = glob(os.path.join(bin_dir_path, '*.bin')) - for img in bin_images: - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - index = index + 1 - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - assert file_type == 'bin', 'The file_type must is bin' - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + index = 0 + with open(info_name, 'w') as file: + for classes in os.listdir(file_path): + bin_dir_path = os.path.join(file_path, classes) + bin_images = glob(os.path.join(bin_dir_path, '*.bin')) + for img in bin_images: + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + index = index + 1 + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + assert file_type == 'bin', 'The file_type must is bin' + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' get_bin_info(file_path, info_name, width, height) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/modelzoo_level.txt index fc92458a08f881b475b9a56c45153a0e3fdfe450..76842f45b5f43d10e5fcda3085032ef975a1aea0 100644 --- a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PerfStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PerfStatus:OK +PrecisionStatus:OK AutoTune:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/requirements.txt index 4e04e4fb8a87ca9732e3aea239b3d5bac59a18b9..2b7911c419eba854b915880f82040c6a9774a2d6 100644 --- a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/requirements.txt @@ -1,9 +1,9 @@ -pytorch==1.5.0 -torchvision==0.6.0 -onnx==1.7.0 -numpy==1.18.5 -Pillow==7.2.0 -opencv-python3==1.0 -yacs -iopath +pytorch==1.5.0 +torchvision==0.6.0 +onnx==1.7.0 +numpy==1.18.5 +Pillow==7.2.0 +opencv-python3==1.0 +yacs +iopath submitit \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/test/parse.py b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/test/parse.py index 335e170932c5210fad286b8e49ad092d1ea2b272..5461d015b668fdba0ad902dd7f355676ff71ed57 100644 --- a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/test/parse.py +++ b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1/test/parse.py @@ -1,41 +1,41 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): # Accuracy - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - print(content) - elif sys.argv[1].endswith('.txt'): # Perform - result_txt = sys.argv[1] - if 'PureInfer' in result_txt: # Pure Infer - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r'=(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[0].replace('samples/s', '')) * 4 - print('310 {} fps:{}'.format(result_txt.split('_')[3], fps)) - else: # Infer based on dataset - with open(result_txt, 'r') as f: - lines = f.readlines() - for line in lines: - if 'infer' in line: - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', line.replace('\n', ',') + ',')] - fps = float(txt_data_list[1]) * 4 - print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) - break +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): # Accuracy + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + print(content) + elif sys.argv[1].endswith('.txt'): # Perform + result_txt = sys.argv[1] + if 'PureInfer' in result_txt: # Pure Infer + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r'=(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[0].replace('samples/s', '')) * 4 + print('310 {} fps:{}'.format(result_txt.split('_')[3], fps)) + else: # Infer based on dataset + with open(result_txt, 'r') as f: + lines = f.readlines() + for line in lines: + if 'infer' in line: + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', line.replace('\n', ',') + ',')] + fps = float(txt_data_list[1]) * 4 + print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) + break diff --git a/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B3/README.md b/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B3/README.md old mode 100755 new mode 100644 diff --git a/ACL_PyTorch/contrib/cv/classfication/FixRes/README.md b/ACL_PyTorch/contrib/cv/classfication/FixRes/README.md index f6ac6db0fbb09da1c34532ed60eac34d605e3e31..e1f6a17863f3158dae006cf94cbea5a59ab0bf21 100644 --- a/ACL_PyTorch/contrib/cv/classfication/FixRes/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/FixRes/README.md @@ -1,43 +1,43 @@ -# FixRes模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -``` -pip3.7 install -r requirements.txt -``` - - -2.获取,修改与安装开源模型代码 -``` -git clone https://github.com/facebookresearch/FixRes.git -b main -cd FixRes -git reset c9be6acc7a6b32f896e62c28a97c20c2348327d3 --hard -cd .. -``` - -3.获取权重文件 - -FixResNet50.pth - -4.数据集 -获取ImageNet 2012 - -5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) -将benchmark.x86_64或benchmark.aarch64放到当前目录 - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲。测试时需下载imagenet_labels_fixres.json文件,并放在imagenet文件夹下。 -``` -# 生成om模型 -bash test/pth2om.sh - -# om模型离线推理并测试 -bash test/eval_acc_perf.sh --datasets_path=/root/datasets -``` - **评测结果:** -| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| :------: | :------: | :------: | :------: | :------: | -| FixRes bs1 | [rank1:79.0%](https://github.com/facebookresearch/FixRes) | rank1:79.0% | 507fps | 785.208fps | -| FixRes bs16 | [rank1:79.0%](https://github.com/facebookresearch/FixRes) | rank1:79.0% | 734fps | 788.566fps | +# FixRes模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip3.7 install -r requirements.txt +``` + + +2.获取,修改与安装开源模型代码 +``` +git clone https://github.com/facebookresearch/FixRes.git -b main +cd FixRes +git reset c9be6acc7a6b32f896e62c28a97c20c2348327d3 --hard +cd .. +``` + +3.获取权重文件 + +FixResNet50.pth + +4.数据集 +获取ImageNet 2012 + +5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) +将benchmark.x86_64或benchmark.aarch64放到当前目录 + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲。测试时需下载imagenet_labels_fixres.json文件,并放在imagenet文件夹下。 +``` +# 生成om模型 +bash test/pth2om.sh + +# om模型离线推理并测试 +bash test/eval_acc_perf.sh --datasets_path=/root/datasets +``` + **评测结果:** +| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| :------: | :------: | :------: | :------: | :------: | +| FixRes bs1 | [rank1:79.0%](https://github.com/facebookresearch/FixRes) | rank1:79.0% | 507fps | 785.208fps | +| FixRes bs16 | [rank1:79.0%](https://github.com/facebookresearch/FixRes) | rank1:79.0% | 734fps | 788.566fps | diff --git a/ACL_PyTorch/contrib/cv/classfication/FixRes/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/FixRes/modelzoo_level.txt index 38700fca05402f52c3ae1c4be0889eb60e1f80f1..2e42553460a4f3687654b6ad3f91ab0bcc3aadac 100644 --- a/ACL_PyTorch/contrib/cv/classfication/FixRes/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/FixRes/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/GENet/LICENSE b/ACL_PyTorch/contrib/cv/classfication/GENet/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GENet/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/GENet/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/GENet/cifar10_acc_eval.py b/ACL_PyTorch/contrib/cv/classfication/GENet/cifar10_acc_eval.py index b4909b98e94a89b1257c7fcdadb8ef4231610189..c09177bd3636ff0495abbd9bab0c69f8e9ebf626 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GENet/cifar10_acc_eval.py +++ b/ACL_PyTorch/contrib/cv/classfication/GENet/cifar10_acc_eval.py @@ -1,186 +1,186 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - if data == '': - n_label = 0 - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - print(sort_index) - gt = img_gt_dict[img_name] - print(gt) - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - print("Time used:", elapsed) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + print(sort_index) + gt = img_gt_dict[img_name] + print(gt) + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) diff --git a/ACL_PyTorch/contrib/cv/classfication/GENet/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/GENet/modelzoo_level.txt index 8aa12b7f8cee362eb18ccc16baf537ddcda2ac92..1073929d0d827b6cbb27a2539adc9ecab98923d8 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GENet/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/GENet/modelzoo_level.txt @@ -1,6 +1,6 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK -PerfStatus:OK -ModelConvert:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK +PerfStatus:OK +ModelConvert:OK QuantStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/GENet/test/infer_bin.sh b/ACL_PyTorch/contrib/cv/classfication/GENet/test/infer_bin.sh index feff85f5dd0d5d82857bfa38d9f188b04e4f622f..9f64b810a01ccf882e6d1297bfeacc4627bf1d39 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GENet/test/infer_bin.sh +++ b/ACL_PyTorch/contrib/cv/classfication/GENet/test/infer_bin.sh @@ -1,2 +1,2 @@ -benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=genet_bs1_tuned.om -input_text_path=genet_prep_bin.info -input_width=32 -input_height=32 -output_binary=False -useDvpp=False +benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=genet_bs1_tuned.om -input_text_path=genet_prep_bin.info -input_width=32 -input_height=32 -output_binary=False -useDvpp=False benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=genet_bs16_tuned.om -input_text_path=genet_prep_bin.info -input_width=32 -input_height=32 -output_binary=False -useDvpp=False \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/LICENSE b/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/ghostnet_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/ghostnet_pth2onnx.py index e74fdc48c2d17a3e3a22d8fe2893f3b0e2c8dad6..27218ecece5f1eb03a2b6092dabaef49f8a5aab8 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/ghostnet_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/ghostnet_pth2onnx.py @@ -1,33 +1,33 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import sys -sys.path.append("./CV-Backbones/ghostnet_pytorch") -from ghostnet import ghostnet - -def pth2onnx(input_file, output_file): - model = ghostnet() - model.load_state_dict(torch.load(input_file)) - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, opset_version=11, verbose=True) - -if __name__=="__main__": - input_file = sys.argv[1] - output_file = sys.argv[2] - pth2onnx(input_file, output_file) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import sys +sys.path.append("./CV-Backbones/ghostnet_pytorch") +from ghostnet import ghostnet + +def pth2onnx(input_file, output_file): + model = ghostnet() + model.load_state_dict(torch.load(input_file)) + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, opset_version=11, verbose=True) + +if __name__=="__main__": + input_file = sys.argv[1] + output_file = sys.argv[2] + pth2onnx(input_file, output_file) diff --git a/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/imagenet_torch_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/imagenet_torch_preprocess.py index 92885b0a3fbaabea73989b28e48ae62d54590444..6ff9be559247f0e096019217e72d7dc551ec393b 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/imagenet_torch_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/imagenet_torch_preprocess.py @@ -1,122 +1,122 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from PIL import Image -import numpy as np -import multiprocessing - - -model_config = { - 'resnet': { - 'resize': 256, - 'centercrop': 224, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv3': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv4': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.5, 0.5, 0.5], - 'std': [0.5, 0.5, 0.5], - }, - 'ghostnet':{ - 'resize': 256, - 'centercrop': 224, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - } -} - - -def center_crop(img, output_size): - if isinstance(output_size, int): - output_size = (int(output_size), int(output_size)) - image_width, image_height = img.size - crop_height, crop_width = output_size - crop_top = int(round((image_height - crop_height) / 2.)) - crop_left = int(round((image_width - crop_width) / 2.)) - return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) - - -def resize(img, size, interpolation=Image.BILINEAR): - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def gen_input_bin(mode_type, file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - # RGBA to RGB - image = Image.open(os.path.join(src_path, file)).convert('RGB') - image = resize(image, model_config[mode_type]['resize']) # Resize - image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop - img = np.array(image, dtype=np.float32) - img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW - img = img / 255. # ToTensor: div 255 - img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean - img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - - -def preprocess(mode_type, src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") - mode_type = sys.argv[1] - src_path = sys.argv[2] - save_path = sys.argv[3] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - if mode_type not in model_config: - model_type_help = "model type: " - for key in model_config.keys(): - model_type_help += key - model_type_help += ' ' - raise Exception(model_type_help) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from PIL import Image +import numpy as np +import multiprocessing + + +model_config = { + 'resnet': { + 'resize': 256, + 'centercrop': 224, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv3': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv4': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.5, 0.5, 0.5], + 'std': [0.5, 0.5, 0.5], + }, + 'ghostnet':{ + 'resize': 256, + 'centercrop': 224, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + } +} + + +def center_crop(img, output_size): + if isinstance(output_size, int): + output_size = (int(output_size), int(output_size)) + image_width, image_height = img.size + crop_height, crop_width = output_size + crop_top = int(round((image_height - crop_height) / 2.)) + crop_left = int(round((image_width - crop_width) / 2.)) + return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) + + +def resize(img, size, interpolation=Image.BILINEAR): + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def gen_input_bin(mode_type, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + # RGBA to RGB + image = Image.open(os.path.join(src_path, file)).convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.float32) + img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW + img = img / 255. # ToTensor: div 255 + img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean + img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +def preprocess(mode_type, src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") + mode_type = sys.argv[1] + src_path = sys.argv[2] + save_path = sys.argv[3] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if mode_type not in model_config: + model_type_help = "model type: " + for key in model_config.keys(): + model_type_help += key + model_type_help += ' ' + raise Exception(model_type_help) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) preprocess(mode_type, src_path, save_path) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/requirements.txt index 9b075f0172e3c8b7fd476cc931b2dc54263584c8..0ce89e67a6442eafcaf4f55a51187b3be97962fa 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.6.0 -torchvision == 0.7.0 -onnx == 1.7.0 -numpy == 1.18.5 -Pillow == 7.2.0 +torch == 1.6.0 +torchvision == 0.7.0 +onnx == 1.7.0 +numpy == 1.18.5 +Pillow == 7.2.0 opencv-python == 4.5.1.48 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/test/README.md b/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/test/README.md index d9024b48e503084720406945986c49b360adcd72..fe76d976f32de56d67af5f75fa04fc39f7bd002a 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/test/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x/test/README.md @@ -1,24 +1,24 @@ -环境准备: - -1.数据集路径 -通用的数据集统一放在/root/datasets/或/opt/npu/ -本模型数据集放在/root/datasets/ - -2.进入工作目录 -cd GhostNet1.0x - -3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -pip3.7 install -r requirements.txt - -4.获取模型代码 -git clone https://github.com/huawei-noah/CV-Backbones.git - -5.获取权重文件 -cp ./CV-Backbones/ghostnet_pytorch/models/state_dict_73.98.pth . - -6.获取benchmark工具 -将benchmark.x86_64 benchmark.aarch64放在当前目录 - -7.310上执行,执行时确保device空闲 -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets +环境准备: + +1.数据集路径 +通用的数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集放在/root/datasets/ + +2.进入工作目录 +cd GhostNet1.0x + +3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +pip3.7 install -r requirements.txt + +4.获取模型代码 +git clone https://github.com/huawei-noah/CV-Backbones.git + +5.获取权重文件 +cp ./CV-Backbones/ghostnet_pytorch/models/state_dict_73.98.pth . + +6.获取benchmark工具 +将benchmark.x86_64 benchmark.aarch64放在当前目录 + +7.310上执行,执行时确保device空闲 +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets diff --git a/ACL_PyTorch/contrib/cv/classfication/GloRe/GloRe_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/GloRe/GloRe_pth2onnx.py index 3d9975c78bef436054953307725a0800b48291cd..c1f7f6f764933b692b6bb9a58db088dd820ace02 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GloRe/GloRe_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/GloRe/GloRe_pth2onnx.py @@ -1,33 +1,33 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import torch -import sys -import os -from GloRe.network.resnet50_3d_gcn_x5 import RESNET50_3D_GCN_X5 -def pth2onnx(input_file, output_file): - net = RESNET50_3D_GCN_X5(num_classes=101, pretrained=False) - state_dict = torch.load(input_file,map_location='cpu') - net.load_state_dict(state_dict['state_dict']) - net.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(1, 3, 8, 224, 224) - torch.onnx.export(net, dummy_input, output_file, input_names=input_names, dynamic_axes=dynamic_axes, - output_names=output_names, opset_version=11, verbose=True) - - -if __name__ == '__main__': - args = sys.argv - pth2onnx(args[1], args[2]) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import torch +import sys +import os +from GloRe.network.resnet50_3d_gcn_x5 import RESNET50_3D_GCN_X5 +def pth2onnx(input_file, output_file): + net = RESNET50_3D_GCN_X5(num_classes=101, pretrained=False) + state_dict = torch.load(input_file,map_location='cpu') + net.load_state_dict(state_dict['state_dict']) + net.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 8, 224, 224) + torch.onnx.export(net, dummy_input, output_file, input_names=input_names, dynamic_axes=dynamic_axes, + output_names=output_names, opset_version=11, verbose=True) + + +if __name__ == '__main__': + args = sys.argv + pth2onnx(args[1], args[2]) diff --git a/ACL_PyTorch/contrib/cv/classfication/GloRe/LICENSE b/ACL_PyTorch/contrib/cv/classfication/GloRe/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GloRe/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/GloRe/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/GloRe/README.md b/ACL_PyTorch/contrib/cv/classfication/GloRe/README.md index 715965b4324654480b7a05524886aa4619d6c291..8cd66f582af23f49ef69ff18ebd6bbf05fd868ca 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GloRe/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/GloRe/README.md @@ -1,43 +1,43 @@ -# GloRe模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - -``` -pip3.7 install -r requirements.txt -``` - -2.获取,修改与安装开源模型代码 - -``` - -git clone https://github.com/facebookresearch/GloRe -b master -cd GloRe -git reset --hard 9c6a7340ebb44a66a3bf1945094fc685fb7b730d -cd .. -``` -3.[获取基于UCF101数据集训练出来的权重](https://ascend-pytorch-model-file.obs.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/GloRe/GloRe.pth) - - -4.[获取数据集UCF101](https://www.crcv.ucf.edu/data/UCF101/UCF101.rar) - - -5.[获取msame工具](https://gitee.com/ascend/tools/tree/master/msame) - -6.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) - -将benchmark.x86_64或benchmark.aarch64放到当前目录 - - - -## 2 离线推理 -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets/UCF-101 -``` - | 模型 | pth精度 | 310精度 | 基准性能 | 310性能 | - | :------: | :------: | :------: | :------: | :------: | - | GloRe bs1 | top1:87.79% top5:98.02% | top1:87.77% top5:98.05% | 122.4380fps | 67.3636fps | - | GloRe bs16 | top1:87.79% top5:98.02% | top1:87.77% top5:98.05% | 148.0453fps | 71.7856fps | +# GloRe模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + +``` +pip3.7 install -r requirements.txt +``` + +2.获取,修改与安装开源模型代码 + +``` + +git clone https://github.com/facebookresearch/GloRe -b master +cd GloRe +git reset --hard 9c6a7340ebb44a66a3bf1945094fc685fb7b730d +cd .. +``` +3.[获取基于UCF101数据集训练出来的权重](https://ascend-pytorch-model-file.obs.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/GloRe/GloRe.pth) + + +4.[获取数据集UCF101](https://www.crcv.ucf.edu/data/UCF101/UCF101.rar) + + +5.[获取msame工具](https://gitee.com/ascend/tools/tree/master/msame) + +6.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) + +将benchmark.x86_64或benchmark.aarch64放到当前目录 + + + +## 2 离线推理 +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets/UCF-101 +``` + | 模型 | pth精度 | 310精度 | 基准性能 | 310性能 | + | :------: | :------: | :------: | :------: | :------: | + | GloRe bs1 | top1:87.79% top5:98.02% | top1:87.77% top5:98.05% | 122.4380fps | 67.3636fps | + | GloRe bs16 | top1:87.79% top5:98.02% | top1:87.77% top5:98.05% | 148.0453fps | 71.7856fps | diff --git a/ACL_PyTorch/contrib/cv/classfication/GloRe/env.sh b/ACL_PyTorch/contrib/cv/classfication/GloRe/env.sh index 7cf86a22a607ba18523498bcfb5617e97b28a0e0..e4c421dd8d10faa7f5e617cb1f91d34e8ee685bc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GloRe/env.sh +++ b/ACL_PyTorch/contrib/cv/classfication/GloRe/env.sh @@ -1,6 +1,6 @@ -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp export ASCEND_AICPU_PATH=${install_path} \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/GloRe/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/GloRe/modelzoo_level.txt index 20e36b3f785cf4dbfc970929d2d793911d57c314..85fa1416d33effb8f710f3ac3f6772fcbc898eaa 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GloRe/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/GloRe/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:NOK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/GloRe/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/GloRe/requirements.txt index dfd372e307dc153c8aadc1012baaa6c5e8bf4722..384b6e620823c853805f1ad4ebfebc6240843dc9 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GloRe/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/GloRe/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.7.0 -numpy == 1.21.1 -Pillow == 8.2.0 +torch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.7.0 +numpy == 1.21.1 +Pillow == 8.2.0 opencv_python == 4.5.3.56 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/GloRe/test/parse.py b/ACL_PyTorch/contrib/cv/classfication/GloRe/test/parse.py index b9c74f41d7848e1250356f14472b237a18bb3489..82af69cd183218c3263723c20b652b3f7ec2bc27 100644 --- a/ACL_PyTorch/contrib/cv/classfication/GloRe/test/parse.py +++ b/ACL_PyTorch/contrib/cv/classfication/GloRe/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/LICENSE b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/LICENSE index 657549b86065a3d34c7dd038edee91cedb8cb05a..dcc65541a1b5f985560b92c275b8328469d50742 100644 --- a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/LICENSE @@ -1,30 +1,30 @@ -BSD 3-Clause License - -Copyright (c) 2017, -All rights reserved. -Copyright 2020 Huawei Technologies Co., Ltd - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +BSD 3-Clause License + +Copyright (c) 2017, +All rights reserved. +Copyright 2020 Huawei Technologies Co., Ltd + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/README.md b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/README.md index 74462c68cfc2215046fe28babf92ae29ce3a39a9..90da3dd00b54dd93c370a36ebcb5c3237cd8e985 100644 --- a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/README.md @@ -1,270 +1,270 @@ -# HRNet Onnx模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) - - [6.2 开源TopN精度](#62-开源TopN精度) - - [6.3 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[HRNet论文](https://arxiv.org/pdf/1908.07919.pdf) -Abstract—High-resolution representations are essential for position-sensitive vision problems, such as human pose estimation, semantic segmentation, and object detection. Existing state-of-the-art frameworks first encode the input image as a low-resolution representation through a subnetwork that is formed by connecting high-to-low resolution convolutions in series (e.g., ResNet, VGGNet), and then recover the high-resolution representation from the encoded low-resolution representation. Instead, our proposed network, named as High-Resolution Network (HRNet), maintains high-resolution representations through the whole process. There are two key characteristics: (i) Connect the high-to-low resolution convolution streams in parallel; (ii) Repeatedly exchange the information across resolutions. The benefit is that the resulting representation is semantically richer and spatially more precise. We show the superiority of the proposed HRNet in a wide range of applications, including human pose estimation, semantic segmentation, and object detection, suggesting that the HRNet is a stronger backbone for computer vision problems. All the codes are available at https://github.com/HRNet. - -### 1.2 代码地址 -[HRNet代码](https://github.com/HRNet/HRNet-Image-Classification) -branch:master -commit_id:f130a24bf09b7f23ebd0075271f76c4a188093b2 - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 -``` -pytorch >= 1.5.0 -torchvision >= 0.6.0 -onnx >= 1.7.0 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.20.2 -opencv-python == 4.5.2.52 -Pillow == 8.0.1 -``` - -**说明:** -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 - -1.下载HRNet模型 -git clone https://github.com/HRNet/HRNet-Image-Classification.git - -2.获取权重文件 -wget https://ascend-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/image_classification/HRNet/NPU/8P/model_best.pth.tar -file name:model_best.pth.tar -md5sum:1f1d61e242ac9ca4cab5d0c49299cb76 - -3.编写pth2onnx脚本hrnet_pth2onnx.py - - **说明:** ->注意目前ATC支持的onnx算子版本为11 - -4.执行pth2onnx脚本,生成onnx模型文件 -``` -python3.7 hrnet_pth2onnx.py --cfg ./HRNet-Image-Classification/experiments/cls_hrnet_w18_sgd_lr5e-2_wd1e-4_bs32_x100.yaml --input model_best.pth.tar --output hrnet_w18.onnx -``` - - **模型转换要点:** ->此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 - -### 3.2 onnx转om模型 - -1.设置环境变量 -``` -source env.sh -``` -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) - -``` -atc --framework=5 --model=./hrnet_w18.onnx --input_format=NCHW --input_shape="image:16,3,224,224" --output=hrnet_bs16 --log=debug --soc_version=Ascend310 -``` - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/opt/npu/imagenet/val与/opt/npu/imagenet/val_label.txt。 - -### 4.2 数据集预处理 -1.预处理脚本imagenet_torch_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 - -``` -datasets_path = '/opt/npu/' -python3.7 imagenet_torch_preprocess.py hrnet ${datasets_path}/imagenet/val ./prep_dataset -``` -### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本get_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 - -``` -python3.7 get_info.py bin ./prep_dataset ./hrnet_prep_bin.info 224 224 -``` -第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) -### 5.2 离线推理 -1.设置环境变量 - -``` -source env.sh -``` -2.执行离线推理 -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=hrnet_bs16.om -input_text_path=./hrnet_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False -``` -输出结果默认保存在当前目录result/dumpOutput_devicex,模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 - -## 6 精度对比 - -- **[离线推理TopN精度](#61-离线推理TopN精度)** -- **[开源TopN精度](#62-开源TopN精度)** -- **[精度对比](#63-精度对比)** - -### 6.1 离线推理TopN精度统计 - -后处理统计TopN精度 - -调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 -``` -python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ ${datasets_path}/imagenet/val_label.txt ./ result.json -``` -第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 -查看输出结果: - -``` -{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "76.46%"}, {"key": "Top2 accuracy", "value": "86.33%"}, {"key": "Top3 accuracy", "value": "90.0%"}, {"key": "Top4 accuracy", "value": "91.97%"}, {"key": "Top5 accuracy", "value": "93.14%"}]} -``` -batch1,batch16的精度相同如上. - -### 6.2 开源TopN精度 -[torchvision官网精度](https://pytorch.org/vision/stable/models.html) -``` -Model Acc@1 Acc@5 -HRNet-Image-Classification 76.8 93.4 -``` -### 6.3 精度对比 -将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 - **精度调试:** ->没有遇到精度不达标的问题,故不需要进行精度调试 - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** - -### 7.1 npu性能数据 -需要测试batch1,batch4,batch8,batch16,batch32的性能,这里用batch1与batch16做示例 -benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device。为快速获取性能数据,也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准。这里给出两种方式,模型的测试脚本使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准。 -1.benchmark工具在整个数据集上推理获得性能数据 -以batch1为例,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: - -``` -[e2e] throughputRate: 125.08, latency: 399743 -[data read] throughputRate: 132.686, moduleLatency: 7.53661 -[preprocess] throughputRate: 132.548, moduleLatency: 7.54441 -[infer] throughputRate: 125.448, Interface throughputRate: 156.216, moduleLatency: 7.35352 -[post] throughputRate: 125.448, moduleLatency: 7.97142 -``` -Interface throughputRate: 156.216,156.216乘以4既是310单卡吞吐率 -2.benchmark纯推理功能测得性能数据 -batch1的性能: - 测试npu性能要确保device空闲,使用npu-smi info命令可查看device是否在运行其它推理任务 - -``` -./benchmark.x86_64 -round=20 -om_path=hrnet_bs1.om -device_id=0 -batch_size=1 -``` -执行20次纯推理取均值,统计吞吐率与其倒数时延(benchmark的时延是单个数据的推理时间),npu性能是一个device执行的结果 -``` -[INFO] Dataset number: 19 finished cost 2.635ms -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_hrnet_bs1_in_device_0.txt ------------------PureInfer Performance Summary------------------ -ave_throughputRate = 155.975samples/s, ave_latency = 6.42435ms -``` -bs1 310单卡吞吐率:155.975x4=623.9fps/card -batch4的性能: -``` -./benchmark.x86_64 -round=20 -om_path=hrnet_w18_bs4.om -device_id=0 -batch_size=4 -``` -``` -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_hrnet_w18_bs4_in_device_0.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 224.608samples/s, ave_latency: 4.56663ms -``` -bs4 310单卡吞吐率:224.608x4=898.432fps/card -batch8的性能: -``` -./benchmark.x86_64 -round=20 -om_path=hrnet_w18_bs8.om -device_id=0 -batch_size=8 -``` -``` -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_hrnet_w18_bs8_in_device_0.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 248.514samples/s, ave_latency: 4.09695ms -``` -bs8 310单卡吞吐率:248.514x4=994.056fps/card -batch16的性能: - -``` -./benchmark.x86_64 -round=20 -om_path=hrnet_w18_bs16.om -device_id=0 -batch_size=16 -``` -``` -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_hrnet_w18_bs16_in_device_0.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 269.512samples/s, ave_latency: 3.73541ms -``` -bs16 310单卡吞吐率:269.512x4=1078.048fps/card -batch32的性能: -``` -./benchmark.x86_64 -round=20 -om_path=hrnet_w18_bs32.om -device_id=0 -batch_size=32 -``` -``` -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_hrnet_w18_bs32_in_device_0.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 271.562samples/s, ave_latency: 3.69597ms -``` -bs32 310单卡吞吐率:271.562x4=1086.248fps/card - - **性能优化:** - ->没有遇到性能不达标的问题,故不需要进行性能优化 - +# HRNet Onnx模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) + - [6.2 开源TopN精度](#62-开源TopN精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[HRNet论文](https://arxiv.org/pdf/1908.07919.pdf) +Abstract—High-resolution representations are essential for position-sensitive vision problems, such as human pose estimation, semantic segmentation, and object detection. Existing state-of-the-art frameworks first encode the input image as a low-resolution representation through a subnetwork that is formed by connecting high-to-low resolution convolutions in series (e.g., ResNet, VGGNet), and then recover the high-resolution representation from the encoded low-resolution representation. Instead, our proposed network, named as High-Resolution Network (HRNet), maintains high-resolution representations through the whole process. There are two key characteristics: (i) Connect the high-to-low resolution convolution streams in parallel; (ii) Repeatedly exchange the information across resolutions. The benefit is that the resulting representation is semantically richer and spatially more precise. We show the superiority of the proposed HRNet in a wide range of applications, including human pose estimation, semantic segmentation, and object detection, suggesting that the HRNet is a stronger backbone for computer vision problems. All the codes are available at https://github.com/HRNet. + +### 1.2 代码地址 +[HRNet代码](https://github.com/HRNet/HRNet-Image-Classification) +branch:master +commit_id:f130a24bf09b7f23ebd0075271f76c4a188093b2 + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +pytorch >= 1.5.0 +torchvision >= 0.6.0 +onnx >= 1.7.0 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.20.2 +opencv-python == 4.5.2.52 +Pillow == 8.0.1 +``` + +**说明:** +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 + +1.下载HRNet模型 +git clone https://github.com/HRNet/HRNet-Image-Classification.git + +2.获取权重文件 +wget https://ascend-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/image_classification/HRNet/NPU/8P/model_best.pth.tar +file name:model_best.pth.tar +md5sum:1f1d61e242ac9ca4cab5d0c49299cb76 + +3.编写pth2onnx脚本hrnet_pth2onnx.py + + **说明:** +>注意目前ATC支持的onnx算子版本为11 + +4.执行pth2onnx脚本,生成onnx模型文件 +``` +python3.7 hrnet_pth2onnx.py --cfg ./HRNet-Image-Classification/experiments/cls_hrnet_w18_sgd_lr5e-2_wd1e-4_bs32_x100.yaml --input model_best.pth.tar --output hrnet_w18.onnx +``` + + **模型转换要点:** +>此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 + +### 3.2 onnx转om模型 + +1.设置环境变量 +``` +source env.sh +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) + +``` +atc --framework=5 --model=./hrnet_w18.onnx --input_format=NCHW --input_shape="image:16,3,224,224" --output=hrnet_bs16 --log=debug --soc_version=Ascend310 +``` + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/opt/npu/imagenet/val与/opt/npu/imagenet/val_label.txt。 + +### 4.2 数据集预处理 +1.预处理脚本imagenet_torch_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 + +``` +datasets_path = '/opt/npu/' +python3.7 imagenet_torch_preprocess.py hrnet ${datasets_path}/imagenet/val ./prep_dataset +``` +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本get_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 + +``` +python3.7 get_info.py bin ./prep_dataset ./hrnet_prep_bin.info 224 224 +``` +第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) +### 5.2 离线推理 +1.设置环境变量 + +``` +source env.sh +``` +2.执行离线推理 +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=hrnet_bs16.om -input_text_path=./hrnet_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +``` +输出结果默认保存在当前目录result/dumpOutput_devicex,模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 + +## 6 精度对比 + +- **[离线推理TopN精度](#61-离线推理TopN精度)** +- **[开源TopN精度](#62-开源TopN精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理TopN精度统计 + +后处理统计TopN精度 + +调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 +``` +python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ ${datasets_path}/imagenet/val_label.txt ./ result.json +``` +第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 +查看输出结果: + +``` +{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "76.46%"}, {"key": "Top2 accuracy", "value": "86.33%"}, {"key": "Top3 accuracy", "value": "90.0%"}, {"key": "Top4 accuracy", "value": "91.97%"}, {"key": "Top5 accuracy", "value": "93.14%"}]} +``` +batch1,batch16的精度相同如上. + +### 6.2 开源TopN精度 +[torchvision官网精度](https://pytorch.org/vision/stable/models.html) +``` +Model Acc@1 Acc@5 +HRNet-Image-Classification 76.8 93.4 +``` +### 6.3 精度对比 +将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + **精度调试:** +>没有遇到精度不达标的问题,故不需要进行精度调试 + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** + +### 7.1 npu性能数据 +需要测试batch1,batch4,batch8,batch16,batch32的性能,这里用batch1与batch16做示例 +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device。为快速获取性能数据,也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准。这里给出两种方式,模型的测试脚本使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准。 +1.benchmark工具在整个数据集上推理获得性能数据 +以batch1为例,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: + +``` +[e2e] throughputRate: 125.08, latency: 399743 +[data read] throughputRate: 132.686, moduleLatency: 7.53661 +[preprocess] throughputRate: 132.548, moduleLatency: 7.54441 +[infer] throughputRate: 125.448, Interface throughputRate: 156.216, moduleLatency: 7.35352 +[post] throughputRate: 125.448, moduleLatency: 7.97142 +``` +Interface throughputRate: 156.216,156.216乘以4既是310单卡吞吐率 +2.benchmark纯推理功能测得性能数据 +batch1的性能: + 测试npu性能要确保device空闲,使用npu-smi info命令可查看device是否在运行其它推理任务 + +``` +./benchmark.x86_64 -round=20 -om_path=hrnet_bs1.om -device_id=0 -batch_size=1 +``` +执行20次纯推理取均值,统计吞吐率与其倒数时延(benchmark的时延是单个数据的推理时间),npu性能是一个device执行的结果 +``` +[INFO] Dataset number: 19 finished cost 2.635ms +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_hrnet_bs1_in_device_0.txt +-----------------PureInfer Performance Summary------------------ +ave_throughputRate = 155.975samples/s, ave_latency = 6.42435ms +``` +bs1 310单卡吞吐率:155.975x4=623.9fps/card +batch4的性能: +``` +./benchmark.x86_64 -round=20 -om_path=hrnet_w18_bs4.om -device_id=0 -batch_size=4 +``` +``` +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_hrnet_w18_bs4_in_device_0.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 224.608samples/s, ave_latency: 4.56663ms +``` +bs4 310单卡吞吐率:224.608x4=898.432fps/card +batch8的性能: +``` +./benchmark.x86_64 -round=20 -om_path=hrnet_w18_bs8.om -device_id=0 -batch_size=8 +``` +``` +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_hrnet_w18_bs8_in_device_0.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 248.514samples/s, ave_latency: 4.09695ms +``` +bs8 310单卡吞吐率:248.514x4=994.056fps/card +batch16的性能: + +``` +./benchmark.x86_64 -round=20 -om_path=hrnet_w18_bs16.om -device_id=0 -batch_size=16 +``` +``` +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_hrnet_w18_bs16_in_device_0.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 269.512samples/s, ave_latency: 3.73541ms +``` +bs16 310单卡吞吐率:269.512x4=1078.048fps/card +batch32的性能: +``` +./benchmark.x86_64 -round=20 -om_path=hrnet_w18_bs32.om -device_id=0 -batch_size=32 +``` +``` +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_hrnet_w18_bs32_in_device_0.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 271.562samples/s, ave_latency: 3.69597ms +``` +bs32 310单卡吞吐率:271.562x4=1086.248fps/card + + **性能优化:** + +>没有遇到性能不达标的问题,故不需要进行性能优化 + diff --git a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/get_info.py b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/get_info.py index e43d4415cb667c31dcb6ea7228736d6f8056ad39..7f9afb06d1dcce471c92cdaf3fa13aabe0913f09 100644 --- a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/get_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/get_info.py @@ -1,59 +1,59 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/hrnet_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/hrnet_pth2onnx.py index 078a8a65a7833a006626738856693b91c526be1c..ec9444cc2f85ad1232c7ec0d59252e8643fdd35a 100644 --- a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/hrnet_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/hrnet_pth2onnx.py @@ -1,92 +1,92 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import argparse -import torch -import torch.onnx -from collections import OrderedDict -sys.path.append(r"./HRNet-Image-Classification") -sys.path.append(r"./HRNet-Image-Classification/lib") -from lib.models import cls_hrnet -from lib.config import config -from lib.config import update_config -def parse_args(): - parser = argparse.ArgumentParser(description='Train classification network') - parser.add_argument('--cfg', - help='experiment configure file name', - required=True, - type=str) - - parser.add_argument('--modelDir', - help='model directory', - type=str, - default='') - parser.add_argument('--logDir', - help='log directory', - type=str, - default='') - parser.add_argument('--dataDir', - help='data directory', - type=str, - default='') - parser.add_argument('--testModel', - help='testModel', - type=str, - default='') - - parser.add_argument('--input', - help='input pytorch model', - required=True, - type=str) - - parser.add_argument('--output', - help='output onnx model', - required=True, - type=str) - - args = parser.parse_args() - update_config(config, args) - - return args - -def proc_node_module(checkpoint, AttrName): - new_state_dict = OrderedDict() - for k, v in checkpoint[AttrName].items(): - if(k[0:7] == "module."): - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - -def pth2onnx(): - args = parse_args() - print(config.MODEL) - modelpth = args.input - checkpoint = torch.load(modelpth, map_location='cpu') - model = cls_hrnet.get_cls_net(config) - output_file = args.output - print("output:",output_file) - model.load_state_dict(checkpoint) - model.eval() - print(model) - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) - -if __name__ == "__main__": - pth2onnx() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import argparse +import torch +import torch.onnx +from collections import OrderedDict +sys.path.append(r"./HRNet-Image-Classification") +sys.path.append(r"./HRNet-Image-Classification/lib") +from lib.models import cls_hrnet +from lib.config import config +from lib.config import update_config +def parse_args(): + parser = argparse.ArgumentParser(description='Train classification network') + parser.add_argument('--cfg', + help='experiment configure file name', + required=True, + type=str) + + parser.add_argument('--modelDir', + help='model directory', + type=str, + default='') + parser.add_argument('--logDir', + help='log directory', + type=str, + default='') + parser.add_argument('--dataDir', + help='data directory', + type=str, + default='') + parser.add_argument('--testModel', + help='testModel', + type=str, + default='') + + parser.add_argument('--input', + help='input pytorch model', + required=True, + type=str) + + parser.add_argument('--output', + help='output onnx model', + required=True, + type=str) + + args = parser.parse_args() + update_config(config, args) + + return args + +def proc_node_module(checkpoint, AttrName): + new_state_dict = OrderedDict() + for k, v in checkpoint[AttrName].items(): + if(k[0:7] == "module."): + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + +def pth2onnx(): + args = parse_args() + print(config.MODEL) + modelpth = args.input + checkpoint = torch.load(modelpth, map_location='cpu') + model = cls_hrnet.get_cls_net(config) + output_file = args.output + print("output:",output_file) + model.load_state_dict(checkpoint) + model.eval() + print(model) + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) + +if __name__ == "__main__": + pth2onnx() diff --git a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/imagenet_acc_eval.py b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/imagenet_acc_eval.py index d85b7dcf59856b5df3a7a9b27033a0334fc2dbc4..58e389352ec8578e685fa999f6724c73eebf59f4 100644 --- a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/imagenet_acc_eval.py +++ b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/imagenet_acc_eval.py @@ -1,187 +1,187 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - if data == '': - n_label = 0 - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - print(folder_davinci_target) - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - print(annotation_file_path) - # the path to store the results json path - result_json_path = sys.argv[3] - print(result_json_path) - # result json file name - json_file_name = sys.argv[4] - print(json_file_name) - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - print("Time used:", elapsed) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + print(folder_davinci_target) + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + print(annotation_file_path) + # the path to store the results json path + result_json_path = sys.argv[3] + print(result_json_path) + # result json file name + json_file_name = sys.argv[4] + print(json_file_name) + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) diff --git a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/imagenet_torch_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/imagenet_torch_preprocess.py index 4ce024bfb5edd96dbdd2d27b47db1ee6fda6d0b1..61e574128ad0a582be7d9c79e4b5e0ea5ef1c006 100644 --- a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/imagenet_torch_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/imagenet_torch_preprocess.py @@ -1,103 +1,103 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from PIL import Image -import numpy as np -import multiprocessing - - -model_config = { - 'hrnet': { - 'resize': 256, - 'centercrop': 224, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - } -} - -def center_crop(img, output_size): - if isinstance(output_size, int): - output_size = (int(output_size), int(output_size)) - image_width, image_height = img.size - crop_height, crop_width = output_size - crop_top = int(round((image_height - crop_height) / 2.)) - crop_left = int(round((image_width - crop_width) / 2.)) - return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) - - -def resize(img, size, interpolation=Image.BILINEAR): - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def gen_input_bin(mode_type, file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - # RGBA to RGB - s = os.path.join(src_path,file) - image = Image.open(os.path.join(src_path, file))# - image = image.convert('RGB') - image = resize(image, model_config[mode_type]['resize']) # Resize - image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop - img = np.array(image, dtype=np.float32) - img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW - img = img / 255. # ToTensor: div 255 - img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean - img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - - -def preprocess(mode_type, src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") - mode_type = sys.argv[1] - src_path = sys.argv[2] - save_path = sys.argv[3] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - if mode_type not in model_config: - model_type_help = "model type: " - for key in model_config.keys(): - model_type_help += key - model_type_help += ' ' - raise Exception(model_type_help) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - preprocess(mode_type, src_path, save_path) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from PIL import Image +import numpy as np +import multiprocessing + + +model_config = { + 'hrnet': { + 'resize': 256, + 'centercrop': 224, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + } +} + +def center_crop(img, output_size): + if isinstance(output_size, int): + output_size = (int(output_size), int(output_size)) + image_width, image_height = img.size + crop_height, crop_width = output_size + crop_top = int(round((image_height - crop_height) / 2.)) + crop_left = int(round((image_width - crop_width) / 2.)) + return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) + + +def resize(img, size, interpolation=Image.BILINEAR): + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def gen_input_bin(mode_type, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + # RGBA to RGB + s = os.path.join(src_path,file) + image = Image.open(os.path.join(src_path, file))# + image = image.convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.float32) + img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW + img = img / 255. # ToTensor: div 255 + img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean + img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +def preprocess(mode_type, src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") + mode_type = sys.argv[1] + src_path = sys.argv[2] + save_path = sys.argv[3] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if mode_type not in model_config: + model_type_help = "model type: " + for key in model_config.keys(): + model_type_help += key + model_type_help += ' ' + raise Exception(model_type_help) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess(mode_type, src_path, save_path) diff --git a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/requirements.txt index d5135180ffdd48a42df10fa1e50245411ffe868a..77ef9d68a5a1516f7066fe5315eb1cb7410364f0 100644 --- a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/requirements.txt @@ -1,11 +1,11 @@ -torch==1.8.0 -torchvision==0.9.0 -onnx==1.9.0 -numpy==1.20.2 -opencv-python==4.5.2.52 -Pillow==8.0.1 -Cython -scipy -pandas -pyyaml +torch==1.8.0 +torchvision==0.9.0 +onnx==1.9.0 +numpy==1.20.2 +opencv-python==4.5.2.52 +Pillow==8.0.1 +Cython +scipy +pandas +pyyaml scikit-image \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/test/README.md b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/test/README.md index 7ac4947ef7719de703db8346b6ca8eecc85f2853..db2329251abf7deae2a33d221bfdf1522715ffa9 100644 --- a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/test/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/test/README.md @@ -1,29 +1,29 @@ -环境准备: - -1.数据集路径 -数据集统一放在/root/datasets/或/opt/npu/ -本模型数据集放在/opt/npu/ - -2.进入工作目录 -cd HRNet - -3.安装必要的依赖 -pip3.7 install -r requirements.txt - -4.获取模型代码 -git clone https://github.com/HRNet/HRNet-Image-Classification.git - -5.获取权重文件 -wget https://ascend-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/image_classification/HRNet/NPU/8P/model_best.pth.tar -file name:model_best.pth.tar -md5sum:1f1d61e242ac9ca4cab5d0c49299cb76 - -6.获取benchmark工具 -将benchmark.x86_64 benckmark.aarch64放在当前目录 - -7.310上执行 - -bash test/pth2om.sh - -bash test/eval_acc_perf.sh --datasets_path=/opt/npu +环境准备: + +1.数据集路径 +数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集放在/opt/npu/ + +2.进入工作目录 +cd HRNet + +3.安装必要的依赖 +pip3.7 install -r requirements.txt + +4.获取模型代码 +git clone https://github.com/HRNet/HRNet-Image-Classification.git + +5.获取权重文件 +wget https://ascend-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/image_classification/HRNet/NPU/8P/model_best.pth.tar +file name:model_best.pth.tar +md5sum:1f1d61e242ac9ca4cab5d0c49299cb76 + +6.获取benchmark工具 +将benchmark.x86_64 benckmark.aarch64放在当前目录 + +7.310上执行 + +bash test/pth2om.sh + +bash test/eval_acc_perf.sh --datasets_path=/opt/npu \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/test/parse.py b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/test/parse.py index a0f253b055047b199b33d4b65cdc79177b6b250b..27eae0d0acf98687edd95f1f024cf77c49cd4dc4 100644 --- a/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/test/parse.py +++ b/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/LV-Vit/LICENSE b/ACL_PyTorch/contrib/cv/classfication/LV-Vit/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/LV-Vit/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/LV-Vit/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/LV-Vit/LV_Vit_postprocess.py b/ACL_PyTorch/contrib/cv/classfication/LV-Vit/LV_Vit_postprocess.py index 1781a4eef505306766adb7b1b52c0d4d37430b12..3fd86adf053c42e3845b6e43a5b26b1020d7582b 100644 --- a/ACL_PyTorch/contrib/cv/classfication/LV-Vit/LV_Vit_postprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/LV-Vit/LV_Vit_postprocess.py @@ -1,47 +1,47 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os - -import os -import numpy as np -import sys - -''' -sys.argv[1]: om_output -sys.argv[2]: ground_truth -''' -om_output_files = sorted(os.listdir(sys.argv[1])) - -output_labels = [] -# 读取om输出 -for file in om_output_files: - with open(sys.argv[1] + file, mode='r') as f: - content = f.read().split(' ')[:-1] - content = list(map(lambda x: float(x), content)) - content = np.array(content) - output_labels.append(np.argmax(content)) - -# 读取ground_truth -with open(sys.argv[2], mode='r') as f: - ground_truth = list(map(lambda x: int(x.rstrip('\n').split(' ')[1]), f.readlines())) - -count = 0 -for i in range(len(output_labels)): - if ground_truth[i] == output_labels[i]: - count += 1 - -print(f"accuracy: {count / len(output_labels)}") -# print(count, len(output_labels)) -# print(output_labels) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import os +import numpy as np +import sys + +''' +sys.argv[1]: om_output +sys.argv[2]: ground_truth +''' +om_output_files = sorted(os.listdir(sys.argv[1])) + +output_labels = [] +# 读取om输出 +for file in om_output_files: + with open(sys.argv[1] + file, mode='r') as f: + content = f.read().split(' ')[:-1] + content = list(map(lambda x: float(x), content)) + content = np.array(content) + output_labels.append(np.argmax(content)) + +# 读取ground_truth +with open(sys.argv[2], mode='r') as f: + ground_truth = list(map(lambda x: int(x.rstrip('\n').split(' ')[1]), f.readlines())) + +count = 0 +for i in range(len(output_labels)): + if ground_truth[i] == output_labels[i]: + count += 1 + +print(f"accuracy: {count / len(output_labels)}") +# print(count, len(output_labels)) +# print(output_labels) diff --git a/ACL_PyTorch/contrib/cv/classfication/LV-Vit/LV_Vit_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/LV-Vit/LV_Vit_pth2onnx.py index fefb429f0ff6b7317a4045acb75cae2dc4b7daad..69866709e2a9b0ab1b12bac149ad547a06dc75b2 100644 --- a/ACL_PyTorch/contrib/cv/classfication/LV-Vit/LV_Vit_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/LV-Vit/LV_Vit_pth2onnx.py @@ -1,78 +1,78 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys - -sys.path.append(r"./TokenLabeling") - -import torch -# import argparse -from timm.models import create_model, apply_test_time_pool, load_checkpoint, is_model, list_models -import tlt.models - -import os -import numpy as np - -from timm.data.transforms_factory import transforms_imagenet_eval -from torchvision import transforms -from PIL import Image - - -# parser = argparse.ArgumentParser() -# parser.add_argument('--model', type=str, default='lvvit_s') -# parser.add_argument('--use-ema', dest='use_ema', action='store_true', -# help='use ema version of weights if present') -# parser.add_argument('--checkpoint', type=str, default='') -# parser.add_argument('--pretrained', dest='pretrained', action='store_true', -# help='use pre-trained model') -# parser.add_argument('--gp', default=None, type=str, metavar='POOL', -# help='Global pool type, one of (fast, avg, max, avgmax, avgmaxc). Model default if None.') -# parser.add_argument('--output_file', default='lvvit_s.onnx', type=str) -# parser.add_argument('-b', '--batch_size', default=16, type=int) - - -def main(): - if not os.path.exists('./model'): - os.mkdir('./model') - - device = torch.device('cpu') - input_names = ["image"] - output_names = ["features"] - dynamic_axes = {'image': {0: f'{sys.argv[3]}'}, 'features': {0: f'{sys.argv[3]}'}} - model = create_model( - 'lvvit_s', - pretrained=False, - num_classes=None, - in_chans=3, - global_pool=None, - scriptable=False, - img_size=224) - # model.cuda() - # load_checkpoint(model, args.checkpoint, args.use_ema, strict=False) - load_checkpoint(model, sys.argv[1], False, strict=False) - model.to(device) - model.eval() - dummy_input = torch.randn(int(sys.argv[3]), 3, 224, 224, device='cpu') - torch.onnx.export(model, - dummy_input, - sys.argv[2], - input_names=input_names, - output_names=output_names, - dynamic_axes=dynamic_axes, - opset_version=13, - verbose=True) - - -main() - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys + +sys.path.append(r"./TokenLabeling") + +import torch +# import argparse +from timm.models import create_model, apply_test_time_pool, load_checkpoint, is_model, list_models +import tlt.models + +import os +import numpy as np + +from timm.data.transforms_factory import transforms_imagenet_eval +from torchvision import transforms +from PIL import Image + + +# parser = argparse.ArgumentParser() +# parser.add_argument('--model', type=str, default='lvvit_s') +# parser.add_argument('--use-ema', dest='use_ema', action='store_true', +# help='use ema version of weights if present') +# parser.add_argument('--checkpoint', type=str, default='') +# parser.add_argument('--pretrained', dest='pretrained', action='store_true', +# help='use pre-trained model') +# parser.add_argument('--gp', default=None, type=str, metavar='POOL', +# help='Global pool type, one of (fast, avg, max, avgmax, avgmaxc). Model default if None.') +# parser.add_argument('--output_file', default='lvvit_s.onnx', type=str) +# parser.add_argument('-b', '--batch_size', default=16, type=int) + + +def main(): + if not os.path.exists('./model'): + os.mkdir('./model') + + device = torch.device('cpu') + input_names = ["image"] + output_names = ["features"] + dynamic_axes = {'image': {0: f'{sys.argv[3]}'}, 'features': {0: f'{sys.argv[3]}'}} + model = create_model( + 'lvvit_s', + pretrained=False, + num_classes=None, + in_chans=3, + global_pool=None, + scriptable=False, + img_size=224) + # model.cuda() + # load_checkpoint(model, args.checkpoint, args.use_ema, strict=False) + load_checkpoint(model, sys.argv[1], False, strict=False) + model.to(device) + model.eval() + dummy_input = torch.randn(int(sys.argv[3]), 3, 224, 224, device='cpu') + torch.onnx.export(model, + dummy_input, + sys.argv[2], + input_names=input_names, + output_names=output_names, + dynamic_axes=dynamic_axes, + opset_version=13, + verbose=True) + + +main() + diff --git a/ACL_PyTorch/contrib/cv/classfication/LV-Vit/README.md b/ACL_PyTorch/contrib/cv/classfication/LV-Vit/README.md index cae18df27c440807f29d133dfc38280a28c890ef..96c03d43b844236dd3b4987ccdc701ff2b3c6df1 100644 --- a/ACL_PyTorch/contrib/cv/classfication/LV-Vit/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/LV-Vit/README.md @@ -1,381 +1,381 @@ -# LV-Vit Onnx模型端到端推理指导 - -+ [1模型概述](#1 模型概述) - - + [1.1 论文地址](##1.1 论文地址) - + [1.2 代码地址](##1.2 代码地址) - -+ [2 环境说明](#2 环境说明) - - + [2.1 深度学习框架](##2.1 深度学习框架) - + [2.2 python第三方库](##2.2 python第三方库) - -+ [3 模型转换](#3 模型转换) - - + [3.1 pth转onnx模型](##3.1 pth转onnx模型) - + [3.2 onnx转om模型](##3.2 onnx转om模型) - -+ [4 数据集预处理](#4 数据集预处理) - - + [4.1 数据集获取](##4.1 数据集获取) - + [4.2 数据集预处理](##4.2 数据集预处理) - + [4.3 生成预处理数据集信息文件](##4.3 生成预处理数据集信息文件) - -+ [5 离线推理](#5 离线推理) - - + [5.1 benchmark工具概述](##5.1 benchmark工具概述) - + [5.2 离线推理](##5.2 离线推理) - -+ [6 精度对比](#6 精度对比) - - + [6.1 离线推理精度统计](##6.1 离线推理精度统计) - + [6.2 开源精度](##6.2 开源精度) - + [6.3 精度对比](##6.3 精度对比) - -+ [7 性能对比](#7 性能对比) - - + [7.1 npu性能数据](##7.1 npu性能数据) - + [7.2 gpu和npu性能对比](##7.2 gpu和npu性能对比) - - - -## 1 模型概述 - -### 1.1 论文地址 - -[LV-Vit论文](https://arxiv.org/abs/2104.10858 ) - -### 1.2 代码地址 - -[LV-Vit代码](https://github.com/zihangJiang/TokenLabeling ) - - - -## 2 环境说明 - -### 2.1 深度学习框架 - -``` -torch==1.8.0 -torchvision==0.9.0 -onnx==1.10.1 -onnx-simplifier==0.3.6 -``` - -### 2.2 python第三方库 - -``` -numpy==1.21.2 -pyyaml==5.4.1 -pillow==8.3.1 -timm==0.4.5 -scipy==0.24.2 -``` - - - -## 3 模型转换 - -### 3.1 pth转onnx模型 - -1.LV-Vit模型代码下载 - -```bash -# 切换到工作目录 -cd LV-Vit - -git clone https://github.com/zihangJiang/TokenLabeling.git -cd TokenLabeling -patch -p1 < ../LV-Vit.patch -cd .. -``` - -2.获取模型权重,并放在工作目录的model文件夹下 -在model/下已经存放了在gpu8p上训练得到的pth,如需下载官方pth,则执行以下代码 -```bash -wget https://github.com/zihangJiang/TokenLabeling/releases/download/1.0/lvvit_s-26M-224-83.3.pth.tar -mv lvvit_s-26M-224-83.3.pth.tar model_best.pth.tar - -rm ./model/model_best.pth.tar -mv model_best.pth.tar ./model/ -``` - - - -3.使用 LV_Vit_pth2onnx.py 脚本将pth模型文件转为onnx模型文件 - -+ 参数1:pth模型权重的路径 - -+ 参数2:onnx模型权重的存储路径 - -+ 参数3:batch size - -```bash. -python LV_Vit_pth2onnx.py ./model/model_best.pth.tar ./model/model_best_bs1.onnx 1 -python LV_Vit_pth2onnx.py ./model/model_best.pth.tar ./model/model_best_bs16.onnx 16 -``` - -4.使用 onnxsim 工具优化onnx模型 - -+ 参数1:输入的shape -+ 参数2:onnx模型权重的存储路径 -+ 参数3:优化后onnx模型权重的存储路径 - -``` -python -m onnxsim --input-shape="1,3,224,224" ./model/model_best_bs1.onnx ./model/model_best_bs1_sim.onnx -python -m onnxsim --input-shape="16,3,224,224" ./model/model_best_bs16.onnx ./model/model_best_bs16_sim.onnx -``` - -5.使用tensorRT工具测试onnx模型性能 - -请自行软链接trtexec工具 - -``` -./trtexec --onnx=model/model_best_bs1_sim.onnx --fp16 --shapes=image:1x3x112x112 --device=0 > sim_onnx_bs1.log -./trtexec --onnx=model/model_best_bs16_sim.onnx --fp16 --shapes=image:16x3x112x112 --device=0 > sim_onnx_bs16.log -``` - - - -### 3.2 onnx转om模型 - -1.设置环境变量 - -```bash -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest -``` - -2.使用 atc 将 onnx 模型转换为 om 模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) - -请注意,为了优化softmax算子,在其前后添加了transpose算子,故一并优化transpose,须在白名单中添加(batch_size,6,197,197)和 -(batch_size,197,197,6) - -路径:/usr/local/Ascend/ascend-toolkit/latest/x86_64-linux/opp/op_impl/built-in/ai_core/tbe/impl/dynamic/transpose.py - -```bash -atc --framework=5 --model=./model/model_best_bs1_sim.onnx --output=./model/model_best_bs1_sim --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 - -atc --framework=5 --model=./model/model_best_bs16_sim.onnx --output=./model/model_best_bs16_sim --input_format=NCHW --input_shape="image:16,3,224,224" --log=debug --soc_version=Ascend310 -``` - - - -## 4 数据集预处理 - -### 4.1 数据集获取 - -获取imagenet纯验证数据集,放在该目录:/opt/npu/imagenet/PureVal/ - - - -### 4.2 数据集预处理 - -执行预处理脚本,会在工作目录的data目录下生成数据集预处理后的 bin 文件和 数据集信息文件 - -LV_Vit_preprocess.py: -+ --src_path: imagenet纯验证集路径; --save_path: bin文件存放路径 - -gen_dataset_info.py -+ 参数1:bin文件 -+ 参数2:数据bin文件存放目录 - -``` -python LV_Vit_preprocess.py --src_path /opt/npu/imagenet/PureVal/ --save_path ./data/prep_dataset; -python gen_dataset_info.py ./data/prep_dataset ./data/lvvit_prep_bin.info; -``` - - -## 5 离线推理 - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) - -### 5.2 离线推理 - -1.设置环境变量 - -```bash -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest/ -``` - -2.执行离线推理, 输出结果默认保存在当前目录result/dumpOutput_device0 - -```bash -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./model/model_best_bs1_sim.om -input_text_path=lvvit_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False - -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=./model/model_best_bs16_sim.om -input_text_path=lvvit_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False -``` - - - -## 6 精度对比 - -### 6.1 离线推理精度统计 - -执行后处理脚本统计om模型推理结果的Accuracy - -+ 参数1:om模型预测结果目录 -+ 参数2:imagenet纯验证集标签 - -```shell -python LV_Vit_postprocess.py ./result/dumpOutput_device0 ./data/val.txt -``` - -控制台输出如下信息 - -``` -accuracy: 0.8317 -``` - - - -### 6.2 开源精度 - -源代码仓公布精度 - -``` -Model Dataset Accuracy -LV-Vit imagenet 0.833 -``` - - - -### 6.3 精度对比 - -将得到的om离线模型推理Accuracy与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 - - - -## 7 性能对比 - -### 7.1 npu性能数据 - -**1. batch_size=1** - -``` -[e2e] throughputRate: 35.5884, latency: 1.40495e+06 -[data read] throughputRate: 37.666, moduleLatency:26.5491 -[preprocess] throughputRate: 37.5823, moduleLatency: 26.6802 -[infer] throughputRate: 35.6308 Interface throughputRate: 37.941, moduleLatency: 27.3942 -[post] throughputRate: 35.6308, moduleLatency: 28.0656 -``` - -batch_size=1 Ascend310单卡吞吐率:37.941*4=151.764 fps - - - -**2. batch_size=4** - -``` -[e2e] throughputRate: 37.4274, latency: 1.33592e+06 -[data read] throughputRate: 39.6399, moduleLatency: 25.2271 -[preprocess] throughputRate: 39.5442, moduleLatency: 25.2882 -[infer] throughputRate: 37.4711, Interface throughputRate: 40.477, moduleLatency: 26.1715 -[post] throughputRate: 9.36777, moduleLatency: 106.749 -``` - -batch_size=4 Ascend310单卡吞吐率:40.477*4=161.908 fps - - - -**3. batch_size=8** - -``` -[e2e] throughputRate: 34.8915, latency: 1.43301e+06 -[data read] throughputRate: 36.8978, moduleLatency: 27.1019 -[preprocess] throughputRate: 36.8307, moduleLatency: 27.1513 -[infer] throughputRate: 34.9252, Interface throughputRate: 38.3992, moduleLatency: 27.4573 -[post] throughputRate: 4.36564, moduleLatency: 229.062 -``` - -batch_size=16 Ascend310单卡吞吐率:38.3992*4=153.5968 fps - - - -**4. batch_size=16** - -``` -[e2e] throughputRate: 34.3406, latency: 1.456e+06 -[data read] throughputRate: 36.3651, moduleLatency: 27.4989 -[preprocess] throughputRate: 36.2989, moduleLatency: 27.5491 -[infer] throughputRate: 34.378, Interface throughputRate: 36.9249, moduleLatency: 28.4462 -[post] throughputRate: 2.14862, moduleLatency: 465.415 -``` - -batch_size=16 Ascend310单卡吞吐率:36.9249*4=147.6996 fps - - - -**5. batch_size=32** - -``` -[e2e] throughputRate: 33.136, latency: 1.50893e+06 -[data read] throughputRate: 35.0612, moduleLatency: 28.5215 -[preprocess] throughputRate: 34.9918, moduleLatency: 28.5781 -[infer] throughputRate: 33.1637, Interface throughputRate: 36.1795, moduleLatency: 28.9776 -[post] throughputRate: 1.03669, moduleLatency: 964.608 -``` - -batch_size=16 Ascend310单卡吞吐率:36.1795*4=144.718 fps - - - -### 7.2 npu性能优化 - -云盘:[model_best_bs1_sim.om](https://pan.baidu.com/s/1bMuSj4PbvuYE-pX2j_e-0Q),提取码:ad5f - -[model_best_bs16_sim.om](https://pan.baidu.com/s/11gYb6RpBbuaEL-aIql2qkg),提取码:jiev - -**1. batch_size=1** - -``` -[e2e] throughputRate: 40.7217, latency: 1.22785e+06 -[data read] throughputRate: 43.0838, moduleLatency: 23.2106 -[preprocess] throughputRate: 42.997, moduleLatency: 23.2575 -[infer] throughputRate: 40.769, Interface throughputRate: 44.0188, moduleLatency: 23.7945 -[post] throughputRate: 40.769, moduleLatency: 24.5285 -``` - -batch_size=1 Ascend310单卡吞吐率:44.0188*4=176.0752 fps - -**2. batch_size=16** - -``` -[e2e] throughputRate: 51.2825, latency: 974992 -[data read] throughputRate: 54.323, moduleLatency: 18.4084 -[preprocess] throughputRate: 54.1712, moduleLatency: 18.46 -[infer] throughputRate: 51.3613, Interface throughputRate: 57.8179, moduleLatency: 18.6629 -[post] throughputRate: 3.21005, moduleLatency: 311.521 -``` - -batch_size=16 Ascend310单卡吞吐率:57.8179*4=231.2716 fps - -### 7.3 npu性能优化前后对比 - -| batch size | 优化前 | 优化后 | -| :--------: | :------: | :------: | -| 1 | 151.764 | 176.0752 | -| 16 | 147.6996 | 231.2716 | - - - -### 7.4 gpu和npu性能对比 - -| batch size | GPU(FPS) | NPU(FPS) | -| :--------: | -------- | -------- | -| 1 | 290.41 | 176.0752 | -| 16 | 559.35 | 231.2716 | - - - +# LV-Vit Onnx模型端到端推理指导 + ++ [1模型概述](#1 模型概述) + + + [1.1 论文地址](##1.1 论文地址) + + [1.2 代码地址](##1.2 代码地址) + ++ [2 环境说明](#2 环境说明) + + + [2.1 深度学习框架](##2.1 深度学习框架) + + [2.2 python第三方库](##2.2 python第三方库) + ++ [3 模型转换](#3 模型转换) + + + [3.1 pth转onnx模型](##3.1 pth转onnx模型) + + [3.2 onnx转om模型](##3.2 onnx转om模型) + ++ [4 数据集预处理](#4 数据集预处理) + + + [4.1 数据集获取](##4.1 数据集获取) + + [4.2 数据集预处理](##4.2 数据集预处理) + + [4.3 生成预处理数据集信息文件](##4.3 生成预处理数据集信息文件) + ++ [5 离线推理](#5 离线推理) + + + [5.1 benchmark工具概述](##5.1 benchmark工具概述) + + [5.2 离线推理](##5.2 离线推理) + ++ [6 精度对比](#6 精度对比) + + + [6.1 离线推理精度统计](##6.1 离线推理精度统计) + + [6.2 开源精度](##6.2 开源精度) + + [6.3 精度对比](##6.3 精度对比) + ++ [7 性能对比](#7 性能对比) + + + [7.1 npu性能数据](##7.1 npu性能数据) + + [7.2 gpu和npu性能对比](##7.2 gpu和npu性能对比) + + + +## 1 模型概述 + +### 1.1 论文地址 + +[LV-Vit论文](https://arxiv.org/abs/2104.10858 ) + +### 1.2 代码地址 + +[LV-Vit代码](https://github.com/zihangJiang/TokenLabeling ) + + + +## 2 环境说明 + +### 2.1 深度学习框架 + +``` +torch==1.8.0 +torchvision==0.9.0 +onnx==1.10.1 +onnx-simplifier==0.3.6 +``` + +### 2.2 python第三方库 + +``` +numpy==1.21.2 +pyyaml==5.4.1 +pillow==8.3.1 +timm==0.4.5 +scipy==0.24.2 +``` + + + +## 3 模型转换 + +### 3.1 pth转onnx模型 + +1.LV-Vit模型代码下载 + +```bash +# 切换到工作目录 +cd LV-Vit + +git clone https://github.com/zihangJiang/TokenLabeling.git +cd TokenLabeling +patch -p1 < ../LV-Vit.patch +cd .. +``` + +2.获取模型权重,并放在工作目录的model文件夹下 +在model/下已经存放了在gpu8p上训练得到的pth,如需下载官方pth,则执行以下代码 +```bash +wget https://github.com/zihangJiang/TokenLabeling/releases/download/1.0/lvvit_s-26M-224-83.3.pth.tar +mv lvvit_s-26M-224-83.3.pth.tar model_best.pth.tar + +rm ./model/model_best.pth.tar +mv model_best.pth.tar ./model/ +``` + + + +3.使用 LV_Vit_pth2onnx.py 脚本将pth模型文件转为onnx模型文件 + ++ 参数1:pth模型权重的路径 + ++ 参数2:onnx模型权重的存储路径 + ++ 参数3:batch size + +```bash. +python LV_Vit_pth2onnx.py ./model/model_best.pth.tar ./model/model_best_bs1.onnx 1 +python LV_Vit_pth2onnx.py ./model/model_best.pth.tar ./model/model_best_bs16.onnx 16 +``` + +4.使用 onnxsim 工具优化onnx模型 + ++ 参数1:输入的shape ++ 参数2:onnx模型权重的存储路径 ++ 参数3:优化后onnx模型权重的存储路径 + +``` +python -m onnxsim --input-shape="1,3,224,224" ./model/model_best_bs1.onnx ./model/model_best_bs1_sim.onnx +python -m onnxsim --input-shape="16,3,224,224" ./model/model_best_bs16.onnx ./model/model_best_bs16_sim.onnx +``` + +5.使用tensorRT工具测试onnx模型性能 + +请自行软链接trtexec工具 + +``` +./trtexec --onnx=model/model_best_bs1_sim.onnx --fp16 --shapes=image:1x3x112x112 --device=0 > sim_onnx_bs1.log +./trtexec --onnx=model/model_best_bs16_sim.onnx --fp16 --shapes=image:16x3x112x112 --device=0 > sim_onnx_bs16.log +``` + + + +### 3.2 onnx转om模型 + +1.设置环境变量 + +```bash +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest +``` + +2.使用 atc 将 onnx 模型转换为 om 模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) + +请注意,为了优化softmax算子,在其前后添加了transpose算子,故一并优化transpose,须在白名单中添加(batch_size,6,197,197)和 +(batch_size,197,197,6) + +路径:/usr/local/Ascend/ascend-toolkit/latest/x86_64-linux/opp/op_impl/built-in/ai_core/tbe/impl/dynamic/transpose.py + +```bash +atc --framework=5 --model=./model/model_best_bs1_sim.onnx --output=./model/model_best_bs1_sim --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 + +atc --framework=5 --model=./model/model_best_bs16_sim.onnx --output=./model/model_best_bs16_sim --input_format=NCHW --input_shape="image:16,3,224,224" --log=debug --soc_version=Ascend310 +``` + + + +## 4 数据集预处理 + +### 4.1 数据集获取 + +获取imagenet纯验证数据集,放在该目录:/opt/npu/imagenet/PureVal/ + + + +### 4.2 数据集预处理 + +执行预处理脚本,会在工作目录的data目录下生成数据集预处理后的 bin 文件和 数据集信息文件 + +LV_Vit_preprocess.py: ++ --src_path: imagenet纯验证集路径; --save_path: bin文件存放路径 + +gen_dataset_info.py ++ 参数1:bin文件 ++ 参数2:数据bin文件存放目录 + +``` +python LV_Vit_preprocess.py --src_path /opt/npu/imagenet/PureVal/ --save_path ./data/prep_dataset; +python gen_dataset_info.py ./data/prep_dataset ./data/lvvit_prep_bin.info; +``` + + +## 5 离线推理 + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) + +### 5.2 离线推理 + +1.设置环境变量 + +```bash +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest/ +``` + +2.执行离线推理, 输出结果默认保存在当前目录result/dumpOutput_device0 + +```bash +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./model/model_best_bs1_sim.om -input_text_path=lvvit_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False + +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=./model/model_best_bs16_sim.om -input_text_path=lvvit_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +``` + + + +## 6 精度对比 + +### 6.1 离线推理精度统计 + +执行后处理脚本统计om模型推理结果的Accuracy + ++ 参数1:om模型预测结果目录 ++ 参数2:imagenet纯验证集标签 + +```shell +python LV_Vit_postprocess.py ./result/dumpOutput_device0 ./data/val.txt +``` + +控制台输出如下信息 + +``` +accuracy: 0.8317 +``` + + + +### 6.2 开源精度 + +源代码仓公布精度 + +``` +Model Dataset Accuracy +LV-Vit imagenet 0.833 +``` + + + +### 6.3 精度对比 + +将得到的om离线模型推理Accuracy与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + + + +## 7 性能对比 + +### 7.1 npu性能数据 + +**1. batch_size=1** + +``` +[e2e] throughputRate: 35.5884, latency: 1.40495e+06 +[data read] throughputRate: 37.666, moduleLatency:26.5491 +[preprocess] throughputRate: 37.5823, moduleLatency: 26.6802 +[infer] throughputRate: 35.6308 Interface throughputRate: 37.941, moduleLatency: 27.3942 +[post] throughputRate: 35.6308, moduleLatency: 28.0656 +``` + +batch_size=1 Ascend310单卡吞吐率:37.941*4=151.764 fps + + + +**2. batch_size=4** + +``` +[e2e] throughputRate: 37.4274, latency: 1.33592e+06 +[data read] throughputRate: 39.6399, moduleLatency: 25.2271 +[preprocess] throughputRate: 39.5442, moduleLatency: 25.2882 +[infer] throughputRate: 37.4711, Interface throughputRate: 40.477, moduleLatency: 26.1715 +[post] throughputRate: 9.36777, moduleLatency: 106.749 +``` + +batch_size=4 Ascend310单卡吞吐率:40.477*4=161.908 fps + + + +**3. batch_size=8** + +``` +[e2e] throughputRate: 34.8915, latency: 1.43301e+06 +[data read] throughputRate: 36.8978, moduleLatency: 27.1019 +[preprocess] throughputRate: 36.8307, moduleLatency: 27.1513 +[infer] throughputRate: 34.9252, Interface throughputRate: 38.3992, moduleLatency: 27.4573 +[post] throughputRate: 4.36564, moduleLatency: 229.062 +``` + +batch_size=16 Ascend310单卡吞吐率:38.3992*4=153.5968 fps + + + +**4. batch_size=16** + +``` +[e2e] throughputRate: 34.3406, latency: 1.456e+06 +[data read] throughputRate: 36.3651, moduleLatency: 27.4989 +[preprocess] throughputRate: 36.2989, moduleLatency: 27.5491 +[infer] throughputRate: 34.378, Interface throughputRate: 36.9249, moduleLatency: 28.4462 +[post] throughputRate: 2.14862, moduleLatency: 465.415 +``` + +batch_size=16 Ascend310单卡吞吐率:36.9249*4=147.6996 fps + + + +**5. batch_size=32** + +``` +[e2e] throughputRate: 33.136, latency: 1.50893e+06 +[data read] throughputRate: 35.0612, moduleLatency: 28.5215 +[preprocess] throughputRate: 34.9918, moduleLatency: 28.5781 +[infer] throughputRate: 33.1637, Interface throughputRate: 36.1795, moduleLatency: 28.9776 +[post] throughputRate: 1.03669, moduleLatency: 964.608 +``` + +batch_size=16 Ascend310单卡吞吐率:36.1795*4=144.718 fps + + + +### 7.2 npu性能优化 + +云盘:[model_best_bs1_sim.om](https://pan.baidu.com/s/1bMuSj4PbvuYE-pX2j_e-0Q),提取码:ad5f + +[model_best_bs16_sim.om](https://pan.baidu.com/s/11gYb6RpBbuaEL-aIql2qkg),提取码:jiev + +**1. batch_size=1** + +``` +[e2e] throughputRate: 40.7217, latency: 1.22785e+06 +[data read] throughputRate: 43.0838, moduleLatency: 23.2106 +[preprocess] throughputRate: 42.997, moduleLatency: 23.2575 +[infer] throughputRate: 40.769, Interface throughputRate: 44.0188, moduleLatency: 23.7945 +[post] throughputRate: 40.769, moduleLatency: 24.5285 +``` + +batch_size=1 Ascend310单卡吞吐率:44.0188*4=176.0752 fps + +**2. batch_size=16** + +``` +[e2e] throughputRate: 51.2825, latency: 974992 +[data read] throughputRate: 54.323, moduleLatency: 18.4084 +[preprocess] throughputRate: 54.1712, moduleLatency: 18.46 +[infer] throughputRate: 51.3613, Interface throughputRate: 57.8179, moduleLatency: 18.6629 +[post] throughputRate: 3.21005, moduleLatency: 311.521 +``` + +batch_size=16 Ascend310单卡吞吐率:57.8179*4=231.2716 fps + +### 7.3 npu性能优化前后对比 + +| batch size | 优化前 | 优化后 | +| :--------: | :------: | :------: | +| 1 | 151.764 | 176.0752 | +| 16 | 147.6996 | 231.2716 | + + + +### 7.4 gpu和npu性能对比 + +| batch size | GPU(FPS) | NPU(FPS) | +| :--------: | -------- | -------- | +| 1 | 290.41 | 176.0752 | +| 16 | 559.35 | 231.2716 | + + + diff --git a/ACL_PyTorch/contrib/cv/classfication/LV-Vit/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/classfication/LV-Vit/gen_dataset_info.py index 5415fd9ae55679e3eb072ffe0930925e061d4098..0ef2e2354d872b36e15a4b748793267b0c96e564 100644 --- a/ACL_PyTorch/contrib/cv/classfication/LV-Vit/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/LV-Vit/gen_dataset_info.py @@ -1,31 +1,31 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys - - -def main(): - src_path = sys.argv[1] - output_file = sys.argv[2] - in_files = sorted(os.listdir(src_path)) - i = 0 - with open(output_file, mode='w') as f: - for file in in_files: - f.write(str(i) + ' ' + src_path + file + ' 224 224\n') - i += 1 - - -if __name__ == '__main__': - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys + + +def main(): + src_path = sys.argv[1] + output_file = sys.argv[2] + in_files = sorted(os.listdir(src_path)) + i = 0 + with open(output_file, mode='w') as f: + for file in in_files: + f.write(str(i) + ' ' + src_path + file + ' 224 224\n') + i += 1 + + +if __name__ == '__main__': + main() diff --git a/ACL_PyTorch/contrib/cv/classfication/LV-Vit/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/LV-Vit/modelzoo_level.txt index 9e95396651cc4382fe60ee1ee053674f527a448c..27e6c78b37535fe4f5a17029546fe257ad164d34 100644 --- a/ACL_PyTorch/contrib/cv/classfication/LV-Vit/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/LV-Vit/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:POK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/LV-Vit/test/README.md b/ACL_PyTorch/contrib/cv/classfication/LV-Vit/test/README.md index cf67d697df934347675c939256ed24168315f550..23be8e80830a2ac71d368036026d1ff5acd726aa 100644 --- a/ACL_PyTorch/contrib/cv/classfication/LV-Vit/test/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/LV-Vit/test/README.md @@ -1,77 +1,77 @@ -# Shell 脚本 说明 - -**必要目录结构及说明 (Ascend310)** - -``` -|—— TokenLabeling # 源码目录 -|-- LV-Vit.patch # 源码补丁 -|-- test -|------ eval_acc_perf.sh # 预处理推理后处理一条龙 -|------ pth2om.sh # pth转onnx,onnx转om脚本 -|—— data # 用于存放imagenet验证集二进制文件 -|------ val.txt # imagenet 纯验证集标签 -|—— model -|——---- model_best.pth.tar # 模型权重 -|—— env.sh # NPU环境变量脚本 -|—— LV_Vit_postprocess.py # 后处理脚本 -|—— LV_Vit_preprocess.py # 预处理脚本 -|—— LV_Vit_pth2onnx.py # pth转onnx脚本 -|-- benchmark.x86_64 # benckmark工具 -``` - -**step1:准备阶段修改源码** - -```bash -git clone https://github.com/zihangJiang/TokenLabeling.git -cd TokenLabeling -patch -p1 < ../LV-Vit.patch -cd .. -``` - -**step2:获取模型权重,并放在工作目录的model文件夹下** - -```bash -wget https://github.com/zihangJiang/TokenLabeling/releases/download/1.0/lvvit_s-26M-224-83.3.pth.tar - -mv lvvit_s-26M-224-83.3.pth.tar ./model/model_best.pth.tar -``` - -**step3:获取imagenet纯验证数据集,放在该目录** - -/opt/npu/imagenet/PureVal/ - - -**1.pth转om模型** - -```shell -bash test/pth2om.sh -``` - -**2.npu性能数据及精度数据** - ---datasets_path=imagenet纯验证集路径 - -```shell -bash test/eval_acc_perf.sh --datasets_path=/opt/npu/imagenet/PureVal/ -``` - -**必要目录结构及说明 (t4)** - -onnx模型权重由第一步 pth转om 模型生成在 model 文件夹下 -请自行软链接trtexec工具! - -``` -|-- test -|------ pref_gpu.sh # onnx性能数据脚本 -|—— model -|——---- model_best_bs1_sim.onnx # bs=1 模型权重 -|——---- model_best_bs16_sim.onnx # bs=16 模型权重 -|-- trtexec # trtexec工具 -``` - -**3.测试t4性能数据** - -``` -bash test/pref_gpu.sh -``` - +# Shell 脚本 说明 + +**必要目录结构及说明 (Ascend310)** + +``` +|—— TokenLabeling # 源码目录 +|-- LV-Vit.patch # 源码补丁 +|-- test +|------ eval_acc_perf.sh # 预处理推理后处理一条龙 +|------ pth2om.sh # pth转onnx,onnx转om脚本 +|—— data # 用于存放imagenet验证集二进制文件 +|------ val.txt # imagenet 纯验证集标签 +|—— model +|——---- model_best.pth.tar # 模型权重 +|—— env.sh # NPU环境变量脚本 +|—— LV_Vit_postprocess.py # 后处理脚本 +|—— LV_Vit_preprocess.py # 预处理脚本 +|—— LV_Vit_pth2onnx.py # pth转onnx脚本 +|-- benchmark.x86_64 # benckmark工具 +``` + +**step1:准备阶段修改源码** + +```bash +git clone https://github.com/zihangJiang/TokenLabeling.git +cd TokenLabeling +patch -p1 < ../LV-Vit.patch +cd .. +``` + +**step2:获取模型权重,并放在工作目录的model文件夹下** + +```bash +wget https://github.com/zihangJiang/TokenLabeling/releases/download/1.0/lvvit_s-26M-224-83.3.pth.tar + +mv lvvit_s-26M-224-83.3.pth.tar ./model/model_best.pth.tar +``` + +**step3:获取imagenet纯验证数据集,放在该目录** + +/opt/npu/imagenet/PureVal/ + + +**1.pth转om模型** + +```shell +bash test/pth2om.sh +``` + +**2.npu性能数据及精度数据** + +--datasets_path=imagenet纯验证集路径 + +```shell +bash test/eval_acc_perf.sh --datasets_path=/opt/npu/imagenet/PureVal/ +``` + +**必要目录结构及说明 (t4)** + +onnx模型权重由第一步 pth转om 模型生成在 model 文件夹下 +请自行软链接trtexec工具! + +``` +|-- test +|------ pref_gpu.sh # onnx性能数据脚本 +|—— model +|——---- model_best_bs1_sim.onnx # bs=1 模型权重 +|——---- model_best_bs16_sim.onnx # bs=16 模型权重 +|-- trtexec # trtexec工具 +``` + +**3.测试t4性能数据** + +``` +bash test/pref_gpu.sh +``` + diff --git a/ACL_PyTorch/contrib/cv/classfication/MobileNet-v1/mobilenet-v1_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/MobileNet-v1/mobilenet-v1_pth2onnx.py index 82981e308d3bcfae6f54b409d7d21c53f9e39761..f254c26ddfc1cf0b7fafd9d8a34eeda0813d9609 100644 --- a/ACL_PyTorch/contrib/cv/classfication/MobileNet-v1/mobilenet-v1_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/MobileNet-v1/mobilenet-v1_pth2onnx.py @@ -1,107 +1,107 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from collections import OrderedDict - -import torch -import torch.nn as nn -import torch.onnx - - -class Net(nn.Module): - def __init__(self): - super(Net, self).__init__() - - def conv_bn(inp, oup, stride): - return nn.Sequential( - nn.Conv2d(inp, oup, 3, stride, 1, bias=False), - nn.BatchNorm2d(oup), - nn.ReLU(inplace=True) - ) - - def conv_dw(inp, oup, stride): - return nn.Sequential( - nn.Conv2d(inp, inp, 3, stride, 1, groups=inp, bias=False), - nn.BatchNorm2d(inp), - nn.ReLU(inplace=True), - - nn.Conv2d(inp, oup, 1, 1, 0, bias=False), - nn.BatchNorm2d(oup), - nn.ReLU(inplace=True), - ) - - self.model = nn.Sequential( - conv_bn(3, 32, 2), - conv_dw(32, 64, 1), - conv_dw(64, 128, 2), - conv_dw(128, 128, 1), - conv_dw(128, 256, 2), - conv_dw(256, 256, 1), - conv_dw(256, 512, 2), - conv_dw(512, 512, 1), - conv_dw(512, 512, 1), - conv_dw(512, 512, 1), - conv_dw(512, 512, 1), - conv_dw(512, 512, 1), - conv_dw(512, 1024, 2), - conv_dw(1024, 1024, 1), - nn.AvgPool2d(7), - ) - self.fc = nn.Linear(1024, 1000) - - def forward(self, x): - x = self.model(x) - x = x.view(-1, 1024) - x = self.fc(x) - return x - - -def proc_nodes_module(checkpoint, AttrName): - new_state_dict = OrderedDict() - for k, v in checkpoint[AttrName].items(): - if k[0:7] == "module.": - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - - -def convert_model_to_onnx(model_state, output_file): - model = Net() - if model_state: - model.load_state_dict(model_state) - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(32, 3, 224, 224) # (batch_size, channels, width, height) - torch.onnx.export(model, dummy_input, output_file, input_names=input_names, dynamic_axes=dynamic_axes, - output_names=output_names, opset_version=11, verbose=True) - - -if __name__ == '__main__': - checkpoint_file = sys.argv[1] - output_file = sys.argv[2] - - if os.path.isfile(checkpoint_file): - checkpoint = torch.load(checkpoint_file, map_location='cpu') - print("{} successfully loaded.".format(checkpoint_file)) - model_state = proc_nodes_module(checkpoint, 'state_dict') - else: - print("Failed to load checkpoint from {}! Output model with initial state.".format(checkpoint_file)) - model_state = OrderedDict() - convert_model_to_onnx(model_state, output_file) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from collections import OrderedDict + +import torch +import torch.nn as nn +import torch.onnx + + +class Net(nn.Module): + def __init__(self): + super(Net, self).__init__() + + def conv_bn(inp, oup, stride): + return nn.Sequential( + nn.Conv2d(inp, oup, 3, stride, 1, bias=False), + nn.BatchNorm2d(oup), + nn.ReLU(inplace=True) + ) + + def conv_dw(inp, oup, stride): + return nn.Sequential( + nn.Conv2d(inp, inp, 3, stride, 1, groups=inp, bias=False), + nn.BatchNorm2d(inp), + nn.ReLU(inplace=True), + + nn.Conv2d(inp, oup, 1, 1, 0, bias=False), + nn.BatchNorm2d(oup), + nn.ReLU(inplace=True), + ) + + self.model = nn.Sequential( + conv_bn(3, 32, 2), + conv_dw(32, 64, 1), + conv_dw(64, 128, 2), + conv_dw(128, 128, 1), + conv_dw(128, 256, 2), + conv_dw(256, 256, 1), + conv_dw(256, 512, 2), + conv_dw(512, 512, 1), + conv_dw(512, 512, 1), + conv_dw(512, 512, 1), + conv_dw(512, 512, 1), + conv_dw(512, 512, 1), + conv_dw(512, 1024, 2), + conv_dw(1024, 1024, 1), + nn.AvgPool2d(7), + ) + self.fc = nn.Linear(1024, 1000) + + def forward(self, x): + x = self.model(x) + x = x.view(-1, 1024) + x = self.fc(x) + return x + + +def proc_nodes_module(checkpoint, AttrName): + new_state_dict = OrderedDict() + for k, v in checkpoint[AttrName].items(): + if k[0:7] == "module.": + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + + +def convert_model_to_onnx(model_state, output_file): + model = Net() + if model_state: + model.load_state_dict(model_state) + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(32, 3, 224, 224) # (batch_size, channels, width, height) + torch.onnx.export(model, dummy_input, output_file, input_names=input_names, dynamic_axes=dynamic_axes, + output_names=output_names, opset_version=11, verbose=True) + + +if __name__ == '__main__': + checkpoint_file = sys.argv[1] + output_file = sys.argv[2] + + if os.path.isfile(checkpoint_file): + checkpoint = torch.load(checkpoint_file, map_location='cpu') + print("{} successfully loaded.".format(checkpoint_file)) + model_state = proc_nodes_module(checkpoint, 'state_dict') + else: + print("Failed to load checkpoint from {}! Output model with initial state.".format(checkpoint_file)) + model_state = OrderedDict() + convert_model_to_onnx(model_state, output_file) diff --git a/ACL_PyTorch/contrib/cv/classfication/MobileNet-v1/test/eval_acc_perf.sh b/ACL_PyTorch/contrib/cv/classfication/MobileNet-v1/test/eval_acc_perf.sh old mode 100755 new mode 100644 diff --git a/ACL_PyTorch/contrib/cv/classfication/MobileNet-v1/test/pth2om.sh b/ACL_PyTorch/contrib/cv/classfication/MobileNet-v1/test/pth2om.sh old mode 100755 new mode 100644 diff --git a/ACL_PyTorch/contrib/cv/classfication/OSNet/README.md b/ACL_PyTorch/contrib/cv/classfication/OSNet/README.md index 2373008b8a055d792549c5d7ed4620af01316b27..160d86240d697e2f03da69a8f8ea7fd2114054bc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/OSNet/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/OSNet/README.md @@ -1,248 +1,248 @@ -# OSNet Onnx模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理精度统计](#61-离线推理精度统计) - - [6.2 开源精度](#62-开源精度) - - [6.3 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[OSNet论文](https://arxiv.org/abs/1905.00953) -作为一个实例级的识别问题,行人再识别(ReID)依赖于具有识别能力的特征,它不仅能捕获不同的空间尺度,还能封装多个尺度的任意组合。这些同构和异构尺度的特征为全尺度特征。本文设计了一种新颖的深度CNN,称为全尺度网络(OSNet),用于ReID的全尺度特征学习。这是通过设计一个由多个卷积特征流组成的残差块来实现的,每个残差块检测一定尺度的特征。重要的是,引入了一种新的统一聚合门用输入依赖的每个通道权重进行动态多尺度特征融合。为了有效地学习空间通道相关性,避免过拟合,构建块同时使用点卷积和深度卷积。通过逐层叠加这些块,OSNet非常轻量,可以在现有的ReID基准上从零开始训练。尽管OSNet模型很小,但其在6个Reid数据集上到达了SOTA结果。 - -### 1.2 代码地址 -[OSNet代码](https://github.com/KaiyangZhou/deep-person-reid) -branch:master -commit_id:e580b699c34b6f753a9a06223d840317546c98aa - -## 2 环境说明 - -深度学习框架与第三方库 -``` -pytorch == 1.8.1 -torchvision == 0.9.1 -onnx == 1.7.0 -protobuf==3.13.0 -onnx-simplifier==0.3.6 -isort==4.3.21 -numpy -Cython -h5py -Pillow -six -scipy -matplotlib -opencv-python -tb-nightly -future -yacs -gdown -flake8 -yapf -imageio -``` - -**说明:** -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 - -1.下载pth权重文件 -[OSNet训练pth权重文件(google下载)](https://drive.google.com/file/d/1vduhq5DpN2q1g4fYEZfPI17MJeh9qyrA/view?usp=sharing) -[OSNet训练pth权重文件(百度网盘下载,提取码:gcfe)](https://pan.baidu.com/s/1Xkwa9TCZss_ygkC8obsEMg) -osnet_x1_0_market_256x128_amsgrad_ep150_stp60_lr0.0015_b64_fb10_softmax_labelsmooth_flip.pth - -2.下载OSNet源码: -``` -git clone https://github.com/KaiyangZhou/deep-person-reid.git -cd deep-person-reid/ -# install dependencies -pip install -r requirements.txt -# install torchreid (don't need to re-build it if you modify the source code) -python3.7 setup.py develop -``` -3.编写pth2onnx脚本pth2onnx.py -4.执行pth2onnx脚本,生成onnx模型文件 -``` -python3.7 pth2onnx.py osnet_x1_0_market_256x128_amsgrad_ep150_stp60_lr0.0015_b64_fb10_softmax_labelsmooth_flip.pth osnet_x1_0.onnx # 生成onnx模型文件 -``` -5.对onnx模型进行简化 -``` -python3.7 -m onnxsim osnet_x1_0.onnx osnet_x1_0_bs1_sim.onnx --input-shape 1,3,256,128 # batch_size = 1 -python3.7 -m onnxsim osnet_x1_0.onnx osnet_x1_0_bs16_sim.onnx --input-shape 16,3,256,128 # batch_size = 16 -``` -### 3.2 onnx转om模型 - -1.设置环境变量 -``` -source env.sh -``` -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) -``` -atc --framework=5 --model=./osnet_x1_0_bs1_sim.onnx --input_format=NCHW --input_shape="image:1,3,256,128" --output=osnet_x1_0_bs1 --log=debug --soc_version=Ascend310 # batch_size = 1 -atc --framework=5 --model=./osnet_x1_0_bs16_sim.onnx --input_format=NCHW --input_shape="image:16,3,256,128" --output=osnet_x1_0_bs16 --log=debug --soc_version=Ascend310 # batch_size = 16 -``` - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -该模型使用Market1501数据集进行测试。Market-1501数据集在清华大学校园中采集,夏天拍摄,在2015年构建并公开。它包括由6个摄像头(其中5个高清摄像头和1个低清摄像头)拍摄的1501个行人的32217张图片。每个行人至少由2个摄像头捕获到,并且在一个摄像头中可能具有多张图像。 -训练集bounding_box_train有751人,包含12,936张图像,平均每个人有17.2张训练数据; -测试集bounding_box_test有750人,包含19,732张图像,平均每个人有26.3张测试数据; -查询集query有3368张查询图像。 -[Market1501数据集(百度网盘下载,提取码:me3q)](https://pan.baidu.com/s/1Nl8tMEvq-MwNGd1pG4_6bg) -Market1501数据集放在/root/datasets/,并将数据集文件夹命名为market1501。 - -### 4.2 数据集预处理 -1.预处理脚本market1501_torch_preprocess.py -2.执行预处理脚本,生成数据集预处理后的bin文件 -``` -# 处理gallery数据集,即bounding_box_test测试集 -python3.7 market1501_torch_preprocess.py /root/datasets/market1501/bounding_box_test ./gallery_prep_dataset/ -# 处理query数据集 -python3.7 market1501_torch_preprocess.py /root/datasets/market1501/query ./query_prep_dataset/ -``` -### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本gen_dataset_info.py -2.执行生成数据集信息脚本,生成gallery和query数据集信息文件 -``` -python3.7 gen_dataset_info.py bin ./gallery_prep_dataset ./gallery_prep_bin.info 128 256 -python3.7 gen_dataset_info.py bin ./query_prep_dataset ./query_prep_bin.info 128 256 -``` -第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) -### 5.2 离线推理 -``` -#对query_prep_bin.info进行处理 -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=osnet_x1_0_bs1.om -input_text_path=./query_prep_bin.info -input_width=128 -input_height=256 -output_binary=False -useDvpp=False -``` -输出结果默认保存在当前目录result/dumpOutput_device0,模型只有一个名为feature的输出,每个输入对应的输出对应一个_x.bin文件。 - -``` -#对gallery_prep_bin.info进行处理 -./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=1 -om_path=osnet_x1_0_bs1.om -input_text_path=./gallery_prep_bin.info -input_width=128 -input_height=256 -output_binary=False -useDvpp=False -``` -输出结果默认保存在当前目录result/dumpOutput_device1,模型只有一个名为feature的输出,每个输入对应的输出对应一个_x.bin文件。 - -## 6 精度对比 - -- **[离线推理精度](#61-离线推理精度)** -- **[开源精度](#62-开源精度)** -- **[精度对比](#63-精度对比)** - -### 6.1 离线推理精度统计 -调用osnet_metrics_market1501_bs1.py脚本,可以获得rank1和mAP数据,结果保存在result_bs1.json中。 -``` -python3.7 osnet_x1_0_metrics_market1501.py result/dumpOutput_device0/ result/dumpOutput_device1/ ./ result_bs1.json -``` -第一个为benchmark输出目录,第二个为query数据集配套标签,第三个为gallery数据集配套标签,第四个是生成的文件名。 -查看输出结果: -``` -{"title": "Overall statistical evaluation", "value": [{"key": "R1", "value": "0.94299287"}, {"key": "mAP", "value": "0.8257416732159705"}]} -``` -### 6.2 开源精度 -[OSNet开源代码仓精度](https://kaiyangzhou.github.io/deep-person-reid/MODEL_ZOO) -``` -模型:osnet_x1_0,R1=94.2%,mAP=82.6% -``` -### 6.3 精度对比 -将得到的om离线模型推理结果R1、mAP进行比较,与该模型github代码仓上公布的精度对比,R1比代码仓结果略高,mAP下降在1%范围之内,故精度达标。 - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** - -### 7.1 npu性能数据 -batch1的性能: - 测试npu性能要确保device空闲,使用npu-smi info命令可查看device是否在运行其它推理任务 -``` -./benchmark.x86_64 -round=50 -om_path=osnet_x1_0_bs1.om -device_id=0 -batch_size=1 -``` -执行50次纯推理取均值,统计吞吐率与其倒数时延(benchmark的时延是单个数据的推理时间),npu性能是一个device执行的结果 -``` -[INFO] Dataset number: 49 finished cost 4.174ms -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_osnet_x1_0_bs1_sim_in_device_0.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 240.622samples/s, ave_latency: 4.24716ms -``` -batch1 310单卡吞吐率:240.622×4=962.488fps -batch16的性能: -``` -./benchmark.x86_64 -round=50 -om_path=osnet_x1_0_bs16.om -device_id=2 -batch_size=16 -``` -得到batch16的性能为: -``` -[INFO] Dataset number: 49 finished cost 24.885ms -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_osnet_x1_0_bs16_sim_in_device_2.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 643.052samples/s, ave_latency: 1.55994ms -``` -batch16 310单卡吞吐率:643.052×4=2572.208fps -batch4的性能: -``` -[INFO] Dataset number: 49 finished cost 6.434ms -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_osnet_x1_0_bs4_in_device_0.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 604.718samples/s, ave_latency: 1.68188ms -``` -batch4 310单卡吞吐率:604.718×4=2418.872fps -batch8的性能: -``` -[INFO] Dataset number: 49 finished cost 11.107ms -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_osnet_x1_0_bs8_in_device_0.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 715.699samples/s, ave_latency: 1.41114ms -``` -batch8 310单卡吞吐率:715.699×4=2862.796fps -batch32的性能: -``` -[INFO] Dataset number: 49 finished cost 50.178ms -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_osnet_x1_0_bs32_in_device_0.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 632.875samples/s, ave_latency: 1.58384ms -``` -batch32 310单卡吞吐率:632.875×4=2531.5fps +# OSNet Onnx模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理精度统计](#61-离线推理精度统计) + - [6.2 开源精度](#62-开源精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[OSNet论文](https://arxiv.org/abs/1905.00953) +作为一个实例级的识别问题,行人再识别(ReID)依赖于具有识别能力的特征,它不仅能捕获不同的空间尺度,还能封装多个尺度的任意组合。这些同构和异构尺度的特征为全尺度特征。本文设计了一种新颖的深度CNN,称为全尺度网络(OSNet),用于ReID的全尺度特征学习。这是通过设计一个由多个卷积特征流组成的残差块来实现的,每个残差块检测一定尺度的特征。重要的是,引入了一种新的统一聚合门用输入依赖的每个通道权重进行动态多尺度特征融合。为了有效地学习空间通道相关性,避免过拟合,构建块同时使用点卷积和深度卷积。通过逐层叠加这些块,OSNet非常轻量,可以在现有的ReID基准上从零开始训练。尽管OSNet模型很小,但其在6个Reid数据集上到达了SOTA结果。 + +### 1.2 代码地址 +[OSNet代码](https://github.com/KaiyangZhou/deep-person-reid) +branch:master +commit_id:e580b699c34b6f753a9a06223d840317546c98aa + +## 2 环境说明 + +深度学习框架与第三方库 +``` +pytorch == 1.8.1 +torchvision == 0.9.1 +onnx == 1.7.0 +protobuf==3.13.0 +onnx-simplifier==0.3.6 +isort==4.3.21 +numpy +Cython +h5py +Pillow +six +scipy +matplotlib +opencv-python +tb-nightly +future +yacs +gdown +flake8 +yapf +imageio +``` + +**说明:** +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 + +1.下载pth权重文件 +[OSNet训练pth权重文件(google下载)](https://drive.google.com/file/d/1vduhq5DpN2q1g4fYEZfPI17MJeh9qyrA/view?usp=sharing) +[OSNet训练pth权重文件(百度网盘下载,提取码:gcfe)](https://pan.baidu.com/s/1Xkwa9TCZss_ygkC8obsEMg) +osnet_x1_0_market_256x128_amsgrad_ep150_stp60_lr0.0015_b64_fb10_softmax_labelsmooth_flip.pth + +2.下载OSNet源码: +``` +git clone https://github.com/KaiyangZhou/deep-person-reid.git +cd deep-person-reid/ +# install dependencies +pip install -r requirements.txt +# install torchreid (don't need to re-build it if you modify the source code) +python3.7 setup.py develop +``` +3.编写pth2onnx脚本pth2onnx.py +4.执行pth2onnx脚本,生成onnx模型文件 +``` +python3.7 pth2onnx.py osnet_x1_0_market_256x128_amsgrad_ep150_stp60_lr0.0015_b64_fb10_softmax_labelsmooth_flip.pth osnet_x1_0.onnx # 生成onnx模型文件 +``` +5.对onnx模型进行简化 +``` +python3.7 -m onnxsim osnet_x1_0.onnx osnet_x1_0_bs1_sim.onnx --input-shape 1,3,256,128 # batch_size = 1 +python3.7 -m onnxsim osnet_x1_0.onnx osnet_x1_0_bs16_sim.onnx --input-shape 16,3,256,128 # batch_size = 16 +``` +### 3.2 onnx转om模型 + +1.设置环境变量 +``` +source env.sh +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) +``` +atc --framework=5 --model=./osnet_x1_0_bs1_sim.onnx --input_format=NCHW --input_shape="image:1,3,256,128" --output=osnet_x1_0_bs1 --log=debug --soc_version=Ascend310 # batch_size = 1 +atc --framework=5 --model=./osnet_x1_0_bs16_sim.onnx --input_format=NCHW --input_shape="image:16,3,256,128" --output=osnet_x1_0_bs16 --log=debug --soc_version=Ascend310 # batch_size = 16 +``` + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用Market1501数据集进行测试。Market-1501数据集在清华大学校园中采集,夏天拍摄,在2015年构建并公开。它包括由6个摄像头(其中5个高清摄像头和1个低清摄像头)拍摄的1501个行人的32217张图片。每个行人至少由2个摄像头捕获到,并且在一个摄像头中可能具有多张图像。 +训练集bounding_box_train有751人,包含12,936张图像,平均每个人有17.2张训练数据; +测试集bounding_box_test有750人,包含19,732张图像,平均每个人有26.3张测试数据; +查询集query有3368张查询图像。 +[Market1501数据集(百度网盘下载,提取码:me3q)](https://pan.baidu.com/s/1Nl8tMEvq-MwNGd1pG4_6bg) +Market1501数据集放在/root/datasets/,并将数据集文件夹命名为market1501。 + +### 4.2 数据集预处理 +1.预处理脚本market1501_torch_preprocess.py +2.执行预处理脚本,生成数据集预处理后的bin文件 +``` +# 处理gallery数据集,即bounding_box_test测试集 +python3.7 market1501_torch_preprocess.py /root/datasets/market1501/bounding_box_test ./gallery_prep_dataset/ +# 处理query数据集 +python3.7 market1501_torch_preprocess.py /root/datasets/market1501/query ./query_prep_dataset/ +``` +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本gen_dataset_info.py +2.执行生成数据集信息脚本,生成gallery和query数据集信息文件 +``` +python3.7 gen_dataset_info.py bin ./gallery_prep_dataset ./gallery_prep_bin.info 128 256 +python3.7 gen_dataset_info.py bin ./query_prep_dataset ./query_prep_bin.info 128 256 +``` +第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) +### 5.2 离线推理 +``` +#对query_prep_bin.info进行处理 +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=osnet_x1_0_bs1.om -input_text_path=./query_prep_bin.info -input_width=128 -input_height=256 -output_binary=False -useDvpp=False +``` +输出结果默认保存在当前目录result/dumpOutput_device0,模型只有一个名为feature的输出,每个输入对应的输出对应一个_x.bin文件。 + +``` +#对gallery_prep_bin.info进行处理 +./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=1 -om_path=osnet_x1_0_bs1.om -input_text_path=./gallery_prep_bin.info -input_width=128 -input_height=256 -output_binary=False -useDvpp=False +``` +输出结果默认保存在当前目录result/dumpOutput_device1,模型只有一个名为feature的输出,每个输入对应的输出对应一个_x.bin文件。 + +## 6 精度对比 + +- **[离线推理精度](#61-离线推理精度)** +- **[开源精度](#62-开源精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理精度统计 +调用osnet_metrics_market1501_bs1.py脚本,可以获得rank1和mAP数据,结果保存在result_bs1.json中。 +``` +python3.7 osnet_x1_0_metrics_market1501.py result/dumpOutput_device0/ result/dumpOutput_device1/ ./ result_bs1.json +``` +第一个为benchmark输出目录,第二个为query数据集配套标签,第三个为gallery数据集配套标签,第四个是生成的文件名。 +查看输出结果: +``` +{"title": "Overall statistical evaluation", "value": [{"key": "R1", "value": "0.94299287"}, {"key": "mAP", "value": "0.8257416732159705"}]} +``` +### 6.2 开源精度 +[OSNet开源代码仓精度](https://kaiyangzhou.github.io/deep-person-reid/MODEL_ZOO) +``` +模型:osnet_x1_0,R1=94.2%,mAP=82.6% +``` +### 6.3 精度对比 +将得到的om离线模型推理结果R1、mAP进行比较,与该模型github代码仓上公布的精度对比,R1比代码仓结果略高,mAP下降在1%范围之内,故精度达标。 + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** + +### 7.1 npu性能数据 +batch1的性能: + 测试npu性能要确保device空闲,使用npu-smi info命令可查看device是否在运行其它推理任务 +``` +./benchmark.x86_64 -round=50 -om_path=osnet_x1_0_bs1.om -device_id=0 -batch_size=1 +``` +执行50次纯推理取均值,统计吞吐率与其倒数时延(benchmark的时延是单个数据的推理时间),npu性能是一个device执行的结果 +``` +[INFO] Dataset number: 49 finished cost 4.174ms +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_osnet_x1_0_bs1_sim_in_device_0.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 240.622samples/s, ave_latency: 4.24716ms +``` +batch1 310单卡吞吐率:240.622×4=962.488fps +batch16的性能: +``` +./benchmark.x86_64 -round=50 -om_path=osnet_x1_0_bs16.om -device_id=2 -batch_size=16 +``` +得到batch16的性能为: +``` +[INFO] Dataset number: 49 finished cost 24.885ms +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_osnet_x1_0_bs16_sim_in_device_2.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 643.052samples/s, ave_latency: 1.55994ms +``` +batch16 310单卡吞吐率:643.052×4=2572.208fps +batch4的性能: +``` +[INFO] Dataset number: 49 finished cost 6.434ms +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_osnet_x1_0_bs4_in_device_0.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 604.718samples/s, ave_latency: 1.68188ms +``` +batch4 310单卡吞吐率:604.718×4=2418.872fps +batch8的性能: +``` +[INFO] Dataset number: 49 finished cost 11.107ms +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_osnet_x1_0_bs8_in_device_0.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 715.699samples/s, ave_latency: 1.41114ms +``` +batch8 310单卡吞吐率:715.699×4=2862.796fps +batch32的性能: +``` +[INFO] Dataset number: 49 finished cost 50.178ms +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_osnet_x1_0_bs32_in_device_0.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 632.875samples/s, ave_latency: 1.58384ms +``` +batch32 310单卡吞吐率:632.875×4=2531.5fps diff --git a/ACL_PyTorch/contrib/cv/classfication/OSNet/test/README.md b/ACL_PyTorch/contrib/cv/classfication/OSNet/test/README.md index 06c60701b2f4bf68b0a9c863e53b899c71fcb1ba..e27dc3d1ac07b9ed7d515459b578e4c073ada738 100644 --- a/ACL_PyTorch/contrib/cv/classfication/OSNet/test/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/OSNet/test/README.md @@ -1,31 +1,31 @@ -环境准备: - -1.数据集路径 -[Market1501数据集(百度网盘下载,提取码:me3q)](https://pan.baidu.com/s/1Nl8tMEvq-MwNGd1pG4_6bg) -Market1501数据集放在/root/datasets/,并将数据集文件夹命名为market1501。 - -2.进入工作目录 -cd OSNet - -3.安装必要的依赖 -pip3.7 install -r requirements.txt - -4.获取模型代码 -git clone https://github.com/KaiyangZhou/deep-person-reid.git -cd deep-person-reid - -5.加载模型 -python3.7 setup.py develop - -6.获取权重文件 -[OSNet训练pth权重文件(google下载)](https://drive.google.com/file/d/1vduhq5DpN2q1g4fYEZfPI17MJeh9qyrA/view?usp=sharing) -[OSNet训练pth权重文件(百度网盘下载,提取码:gcfe)](https://pan.baidu.com/s/1Xkwa9TCZss_ygkC8obsEMg) -将权重文件osnet_x1_0_market_256x128_amsgrad_ep150_stp60_lr0.0015_b64_fb10_softmax_labelsmooth_flip.pth放于OSNet目录下 - -7.获取benchmark工具 -将benchmark.x86_64 benchmark.aarch64放于OSNet目录下 - -8.310上执行,执行时确保device空闲 -cd OSNet -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets +环境准备: + +1.数据集路径 +[Market1501数据集(百度网盘下载,提取码:me3q)](https://pan.baidu.com/s/1Nl8tMEvq-MwNGd1pG4_6bg) +Market1501数据集放在/root/datasets/,并将数据集文件夹命名为market1501。 + +2.进入工作目录 +cd OSNet + +3.安装必要的依赖 +pip3.7 install -r requirements.txt + +4.获取模型代码 +git clone https://github.com/KaiyangZhou/deep-person-reid.git +cd deep-person-reid + +5.加载模型 +python3.7 setup.py develop + +6.获取权重文件 +[OSNet训练pth权重文件(google下载)](https://drive.google.com/file/d/1vduhq5DpN2q1g4fYEZfPI17MJeh9qyrA/view?usp=sharing) +[OSNet训练pth权重文件(百度网盘下载,提取码:gcfe)](https://pan.baidu.com/s/1Xkwa9TCZss_ygkC8obsEMg) +将权重文件osnet_x1_0_market_256x128_amsgrad_ep150_stp60_lr0.0015_b64_fb10_softmax_labelsmooth_flip.pth放于OSNet目录下 + +7.获取benchmark工具 +将benchmark.x86_64 benchmark.aarch64放于OSNet目录下 + +8.310上执行,执行时确保device空闲 +cd OSNet +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets diff --git a/ACL_PyTorch/contrib/cv/classfication/PAMTRI/PAMTRI_postprocess.py b/ACL_PyTorch/contrib/cv/classfication/PAMTRI/PAMTRI_postprocess.py index aecfa9467e31b0c609e4ccd6ec7b159e348e71f5..99e472dcc8e8d39e6b41646e8251f89a9f04d492 100644 --- a/ACL_PyTorch/contrib/cv/classfication/PAMTRI/PAMTRI_postprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/PAMTRI/PAMTRI_postprocess.py @@ -1,140 +1,140 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -from __future__ import print_function -from __future__ import division - - -import argparse -import numpy as np -import torch -from torch.utils.data import DataLoader -from torchreid import models -from torchreid.data_manager import DatasetManager -from torchreid.dataset_loader import ImageDataset -from torchreid.eval_metrics import evaluate -from torchreid import transforms as T -torch.multiprocessing.set_sharing_strategy('file_system') -import os - -def postprocess(ranks=range(1, 51)): - - dataset = DatasetManager(dataset_dir=args.dataset, root=args.root) - - transform_test = T.Compose_Keypt([ - T.Resize_Keypt((256,256)), - T.ToTensor_Keypt(), - T.Normalize_Keypt(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), - ]) - - queryloader = DataLoader( - ImageDataset(dataset.query, keyptaware=False, heatmapaware=False, - segmentaware=False, - transform=transform_test, imagesize=(256,256)), - batch_size=args.test_batch, shuffle=False, num_workers=args.workers, - drop_last=False, - ) - - galleryloader = DataLoader( - ImageDataset(dataset.gallery, keyptaware=False, heatmapaware=False, - segmentaware=False, - transform=transform_test, imagesize=(256,256)), - batch_size=args.test_batch, shuffle=False, num_workers=args.workers, - drop_last=False, - ) - qf = [] - q_vids = [] - q_camids = [] - for batch_idx, (imgs, vids, camids, vcolors, vtypes, vkeypts) in enumerate(queryloader): - q_vids.extend(vids) - q_camids.extend(camids) - q_vids = np.asarray(q_vids) - q_camids = np.asarray(q_camids) - - for root, folder, files in os.walk(args.queryfeature_path): - files.sort(key=lambda x:int(x.split('_')[0])) - for file in files: - truefile1 = file.split('_')[1] - if truefile1 == "4.bin": #将benckmark推理出的第四个输出"features"读入,features为计算mAP值的特征 - file_path = os.path.join(root, file) - with open(file_path,'rb') as f: - featuresq = np.fromfile(f, dtype="float32") - featuresq = torch.from_numpy(featuresq) - featuresq = featuresq.unsqueeze(0) - featuresq = featuresq.data.cpu() - qf.append(featuresq) - qf = torch.cat(qf, 0) - - print("Extracted features for query set, obtained {}-by-{} matrix".format(qf.size(0), qf.size(1))) - - gf = [] - g_vids = [] - g_camids = [] - for batch_idx, (imgs, vids, camids, vcolors, vtypes, vkeypts) in enumerate(galleryloader): - g_vids.extend(vids) - g_camids.extend(camids) - g_vids = np.asarray(g_vids) - g_camids = np.asarray(g_camids) - - for root, folder, files in os.walk(args.galleryfeature_path): - files.sort(key=lambda x: int(x.split('_')[0])) - for file in files: - truefile2 = file.split('_')[1] - if truefile2== "4.bin": #将benckmark推理出的第四个输出"features"读入,features为计算mAP值的特征 - file_path = os.path.join(root, file) - with open(file_path,'rb') as f: - featuresg = np.fromfile(f, dtype="float32") - featuresg = torch.from_numpy(featuresg) - featuresg = featuresg.unsqueeze(0) - featuresg = featuresg.data.cpu() - gf.append(featuresg) - gf = torch.cat(gf, 0) - - print("Extracted features for gallery set, obtained {}-by-{} matrix".format(gf.size(0), gf.size(1))) - - m, n = qf.size(0), gf.size(0) - distmat = torch.pow(qf, 2).sum(dim=1, keepdim=True).expand(m, n) + \ - torch.pow(gf, 2).sum(dim=1, keepdim=True).expand(n, m).t() - distmat.addmm_(1, -2, qf, gf.t()) - distmat = distmat.numpy() - - print("Computing CMC and mAP") - cmc, mAP = evaluate(distmat, q_vids, g_vids, q_camids, g_camids) - - print("Results ----------") - print("mAP: {:.2%}".format(mAP)) - print("CMC curve") - for r in ranks: - print("Rank-{:<3}: {:.2%}".format(r, cmc[r - 1])) - print("------------------") - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--query_dir", default="./data/veri/image_query") - parser.add_argument("--gallery_dir", default="./data/veri/image_test") - parser.add_argument("--queryfeature_path", default="./result/dumpOutput_device0_query") - parser.add_argument("--galleryfeature_path", default="./result/dumpOutput_device0_gallery") - parser.add_argument('--root', type=str, default='data', - help="root path to data directory") - parser.add_argument('-d', '--dataset', type=str, default='veri', - help="name of the dataset") - parser.add_argument('-j', '--workers', default=4, type=int, - help="number of data loading workers (default: 4)") - parser.add_argument('--test-batch', default=1, type=int, - help="test batch size") - parser.add_argument('-a', '--arch', type=str, default='densenet121', choices=models.get_names()) - args = parser.parse_args() - - postprocess() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from __future__ import print_function +from __future__ import division + + +import argparse +import numpy as np +import torch +from torch.utils.data import DataLoader +from torchreid import models +from torchreid.data_manager import DatasetManager +from torchreid.dataset_loader import ImageDataset +from torchreid.eval_metrics import evaluate +from torchreid import transforms as T +torch.multiprocessing.set_sharing_strategy('file_system') +import os + +def postprocess(ranks=range(1, 51)): + + dataset = DatasetManager(dataset_dir=args.dataset, root=args.root) + + transform_test = T.Compose_Keypt([ + T.Resize_Keypt((256,256)), + T.ToTensor_Keypt(), + T.Normalize_Keypt(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), + ]) + + queryloader = DataLoader( + ImageDataset(dataset.query, keyptaware=False, heatmapaware=False, + segmentaware=False, + transform=transform_test, imagesize=(256,256)), + batch_size=args.test_batch, shuffle=False, num_workers=args.workers, + drop_last=False, + ) + + galleryloader = DataLoader( + ImageDataset(dataset.gallery, keyptaware=False, heatmapaware=False, + segmentaware=False, + transform=transform_test, imagesize=(256,256)), + batch_size=args.test_batch, shuffle=False, num_workers=args.workers, + drop_last=False, + ) + qf = [] + q_vids = [] + q_camids = [] + for batch_idx, (imgs, vids, camids, vcolors, vtypes, vkeypts) in enumerate(queryloader): + q_vids.extend(vids) + q_camids.extend(camids) + q_vids = np.asarray(q_vids) + q_camids = np.asarray(q_camids) + + for root, folder, files in os.walk(args.queryfeature_path): + files.sort(key=lambda x:int(x.split('_')[0])) + for file in files: + truefile1 = file.split('_')[1] + if truefile1 == "4.bin": #将benckmark推理出的第四个输出"features"读入,features为计算mAP值的特征 + file_path = os.path.join(root, file) + with open(file_path,'rb') as f: + featuresq = np.fromfile(f, dtype="float32") + featuresq = torch.from_numpy(featuresq) + featuresq = featuresq.unsqueeze(0) + featuresq = featuresq.data.cpu() + qf.append(featuresq) + qf = torch.cat(qf, 0) + + print("Extracted features for query set, obtained {}-by-{} matrix".format(qf.size(0), qf.size(1))) + + gf = [] + g_vids = [] + g_camids = [] + for batch_idx, (imgs, vids, camids, vcolors, vtypes, vkeypts) in enumerate(galleryloader): + g_vids.extend(vids) + g_camids.extend(camids) + g_vids = np.asarray(g_vids) + g_camids = np.asarray(g_camids) + + for root, folder, files in os.walk(args.galleryfeature_path): + files.sort(key=lambda x: int(x.split('_')[0])) + for file in files: + truefile2 = file.split('_')[1] + if truefile2== "4.bin": #将benckmark推理出的第四个输出"features"读入,features为计算mAP值的特征 + file_path = os.path.join(root, file) + with open(file_path,'rb') as f: + featuresg = np.fromfile(f, dtype="float32") + featuresg = torch.from_numpy(featuresg) + featuresg = featuresg.unsqueeze(0) + featuresg = featuresg.data.cpu() + gf.append(featuresg) + gf = torch.cat(gf, 0) + + print("Extracted features for gallery set, obtained {}-by-{} matrix".format(gf.size(0), gf.size(1))) + + m, n = qf.size(0), gf.size(0) + distmat = torch.pow(qf, 2).sum(dim=1, keepdim=True).expand(m, n) + \ + torch.pow(gf, 2).sum(dim=1, keepdim=True).expand(n, m).t() + distmat.addmm_(1, -2, qf, gf.t()) + distmat = distmat.numpy() + + print("Computing CMC and mAP") + cmc, mAP = evaluate(distmat, q_vids, g_vids, q_camids, g_camids) + + print("Results ----------") + print("mAP: {:.2%}".format(mAP)) + print("CMC curve") + for r in ranks: + print("Rank-{:<3}: {:.2%}".format(r, cmc[r - 1])) + print("------------------") + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--query_dir", default="./data/veri/image_query") + parser.add_argument("--gallery_dir", default="./data/veri/image_test") + parser.add_argument("--queryfeature_path", default="./result/dumpOutput_device0_query") + parser.add_argument("--galleryfeature_path", default="./result/dumpOutput_device0_gallery") + parser.add_argument('--root', type=str, default='data', + help="root path to data directory") + parser.add_argument('-d', '--dataset', type=str, default='veri', + help="name of the dataset") + parser.add_argument('-j', '--workers', default=4, type=int, + help="number of data loading workers (default: 4)") + parser.add_argument('--test-batch', default=1, type=int, + help="test batch size") + parser.add_argument('-a', '--arch', type=str, default='densenet121', choices=models.get_names()) + args = parser.parse_args() + + postprocess() diff --git a/ACL_PyTorch/contrib/cv/classfication/PAMTRI/PAMTRI_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/PAMTRI/PAMTRI_preprocess.py index b3ce371f5bf73615cd59a4e4c234d65c375d3779..78665cafef37e1ed0aecc8f808dd0581ab449923 100644 --- a/ACL_PyTorch/contrib/cv/classfication/PAMTRI/PAMTRI_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/PAMTRI/PAMTRI_preprocess.py @@ -1,92 +1,92 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -from __future__ import print_function -from __future__ import division -import os -import argparse -import numpy as np -from torch.utils.data import DataLoader -from torchreid.data_manager import DatasetManager -from torchreid.dataset_loader import ImageDataset -from torchreid import transforms as T -from torchreid import models -from PIL import Image -import sys - -def preprocess(): - print("==========\nArgs:{}\n==========".format(args)) - print("Initializing dataset {}".format(args.dataset)) - dataset = DatasetManager(dataset_dir=args.dataset, root=args.root) - - transform_test = T.Compose_Keypt([ - T.Resize_Keypt((256, 256)), - T.ToTensor_Keypt(), - T.Normalize_Keypt(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), - ]) - - queryloader = DataLoader( - ImageDataset(dataset.query, keyptaware=False, heatmapaware=False, segmentaware=False, - transform=transform_test, imagesize=(256, 256)), - batch_size=args.test_batch, shuffle=False, num_workers=args.workers, - pin_memory=False, drop_last=False, - ) - - galleryloader = DataLoader( - ImageDataset(dataset.gallery, keyptaware=False, heatmapaware=False, segmentaware=False, - transform=transform_test, imagesize=(256, 256)), - batch_size=args.test_batch, shuffle=False, num_workers=args.workers, - pin_memory=False, drop_last=False, - ) - - get_bin(queryloader, galleryloader) - - -def get_bin(queryloader, galleryloader): - queryloader_num = 0 - galleryloader_num = 0 - for batch_idx, (imgs, vids, camids, vcolors, vtypes, vkeypts) in enumerate(queryloader): - query = imgs.numpy() - query.tofile(os.path.join(args.save_path1, "{}.bin".format(queryloader_num))) - queryloader_num = queryloader_num + 1 - - for batch_idx, (imgs, vids, camids, vcolors, vtypes, vkeypts) in enumerate(galleryloader): - gallery = imgs.numpy() - gallery.tofile(os.path.join(args.save_path2, "{}.bin".format(galleryloader_num))) - galleryloader_num = galleryloader_num + 1 - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--query_dir", default="./data/veri/image_query") - parser.add_argument("--gallery_dir", default="./data/veri/image_test") - parser.add_argument("--save_path1", default="./prep_dataset_query") - parser.add_argument("--save_path2", default="./prep_dataset_gallery") - parser.add_argument('--root', type=str, default='data', - help="root path to data directory") - parser.add_argument('-d', '--dataset', type=str, default='veri', - help="name of the dataset") - parser.add_argument('-j', '--workers', default=4, type=int, - help="number of data loading workers (default: 4)") - parser.add_argument('--test-batch', default=1, type=int, - help="test batch size") - parser.add_argument('-a', '--arch', type=str, default='densenet121', choices=models.get_names()) - args = parser.parse_args() - - if not os.path.isdir(args.save_path1): - os.makedirs(os.path.realpath(args.save_path1)) - if not os.path.isdir(args.save_path2): - os.makedirs(os.path.realpath(args.save_path2)) - preprocess() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from __future__ import print_function +from __future__ import division +import os +import argparse +import numpy as np +from torch.utils.data import DataLoader +from torchreid.data_manager import DatasetManager +from torchreid.dataset_loader import ImageDataset +from torchreid import transforms as T +from torchreid import models +from PIL import Image +import sys + +def preprocess(): + print("==========\nArgs:{}\n==========".format(args)) + print("Initializing dataset {}".format(args.dataset)) + dataset = DatasetManager(dataset_dir=args.dataset, root=args.root) + + transform_test = T.Compose_Keypt([ + T.Resize_Keypt((256, 256)), + T.ToTensor_Keypt(), + T.Normalize_Keypt(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), + ]) + + queryloader = DataLoader( + ImageDataset(dataset.query, keyptaware=False, heatmapaware=False, segmentaware=False, + transform=transform_test, imagesize=(256, 256)), + batch_size=args.test_batch, shuffle=False, num_workers=args.workers, + pin_memory=False, drop_last=False, + ) + + galleryloader = DataLoader( + ImageDataset(dataset.gallery, keyptaware=False, heatmapaware=False, segmentaware=False, + transform=transform_test, imagesize=(256, 256)), + batch_size=args.test_batch, shuffle=False, num_workers=args.workers, + pin_memory=False, drop_last=False, + ) + + get_bin(queryloader, galleryloader) + + +def get_bin(queryloader, galleryloader): + queryloader_num = 0 + galleryloader_num = 0 + for batch_idx, (imgs, vids, camids, vcolors, vtypes, vkeypts) in enumerate(queryloader): + query = imgs.numpy() + query.tofile(os.path.join(args.save_path1, "{}.bin".format(queryloader_num))) + queryloader_num = queryloader_num + 1 + + for batch_idx, (imgs, vids, camids, vcolors, vtypes, vkeypts) in enumerate(galleryloader): + gallery = imgs.numpy() + gallery.tofile(os.path.join(args.save_path2, "{}.bin".format(galleryloader_num))) + galleryloader_num = galleryloader_num + 1 + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--query_dir", default="./data/veri/image_query") + parser.add_argument("--gallery_dir", default="./data/veri/image_test") + parser.add_argument("--save_path1", default="./prep_dataset_query") + parser.add_argument("--save_path2", default="./prep_dataset_gallery") + parser.add_argument('--root', type=str, default='data', + help="root path to data directory") + parser.add_argument('-d', '--dataset', type=str, default='veri', + help="name of the dataset") + parser.add_argument('-j', '--workers', default=4, type=int, + help="number of data loading workers (default: 4)") + parser.add_argument('--test-batch', default=1, type=int, + help="test batch size") + parser.add_argument('-a', '--arch', type=str, default='densenet121', choices=models.get_names()) + args = parser.parse_args() + + if not os.path.isdir(args.save_path1): + os.makedirs(os.path.realpath(args.save_path1)) + if not os.path.isdir(args.save_path2): + os.makedirs(os.path.realpath(args.save_path2)) + preprocess() diff --git a/ACL_PyTorch/contrib/cv/classfication/PAMTRI/README.md b/ACL_PyTorch/contrib/cv/classfication/PAMTRI/README.md index 580a7bfd667b53aaccc336b5bb33e905d90f5317..b78602300127b37758d5b5c05fbd7df0d89ce102 100644 --- a/ACL_PyTorch/contrib/cv/classfication/PAMTRI/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/PAMTRI/README.md @@ -1,70 +1,70 @@ -# PAMTR模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -``` -pip3.7 install -r requirements.txt -``` - - -2.获取,修改与安装开源模型代码 -``` -git clone https://github.com/NVlabs/PAMTRI -b master -cd MultiTaskNet -mv ./densenet.patch ./torchreid/models/ -cd ./torchreid/models/ -patch -p1 < densenet.patch -``` - -3.获取权重文件 - -将权重文件densenet121-a639ec97.pth放到当前工作目录(执行pth2onnx时会自动下载) -可以通过以下命令下载: -``` -wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/PAMTRI/densenet121-a639ec97.pth -``` - -4.数据集 - -参考[github开源代码仓内数据集获取方法](https://github.com/NVlabs/PAMTRI),将数据集放到./data目录。 -下载[数据集的label文件](https://github.com/NVlabs/PAMTRI.git),在PAMTRI/MultiTaskNet/data/veri/下获取label.csv文件。将数据集解压在./data/veri/目录下,应包含image_train、image_test、image_query三个数据集文件以及相应的.csv文件。 - -5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) -将benchmark.x86_64或benchmark.aarch64放到当前工作目录 - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -bash ./test/pth2om.sh -#启动脚本内3-8行为pth2onnx,10-19行为onnx2om,脚本执行完成后会生成PAMTRI.onnx、PAMTRI_bs1.om、PAMTRI_bs16.om三个模型。 -bash ./test/eval_acc_perf.sh --datasets_path=./data #datesets_path参数为指定数据集路径 -#启动脚本内12-15行为前处理,将图片信息转换为二进制bin文件;17-24行为提取与汇总前处理生成的bin文件信息;32-58行为benckmark推理,会生成推理后的特征信息与推理性能文件;60-69行为后处理,对推理出的特征信息进行评测,生成精度信息文件;70-92行为打印推理性能和精度信息。 -``` - **评测结果:** -| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| :-----------------------: | :----------------------------------------------------------: | :-------------------: | :------: | :---------: | -| PAMTRI bs1 | [mAP:68.64%](https://github.com/NVlabs/PAMTRI) | mAP:68.64% | 215.932fps | 627.662fps | -| PAMTRI bs16 | [mAP:68.64%](https://github.com/NVlabs/PAMTRI) | mAP:68.64% | 810.976fps | 833.668fps | -# 自检报告 - -``` -# pth是否能正确转换为om -bash test/pth2om.sh -# 验收结果: OK - -# 精度数据是否达标 -# npu性能数据 -bash test/eval_acc_perf.sh -# 验收结果: 是 - -# 在t4环境测试性能数据 -bash test/perf_t4.sh -# 验收结果: OK - -# 310性能是否符合标准: 是 -bs1:310=2.9倍t4 -bs16:310=1.03倍t4 - -``` +# PAMTR模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip3.7 install -r requirements.txt +``` + + +2.获取,修改与安装开源模型代码 +``` +git clone https://github.com/NVlabs/PAMTRI -b master +cd MultiTaskNet +mv ./densenet.patch ./torchreid/models/ +cd ./torchreid/models/ +patch -p1 < densenet.patch +``` + +3.获取权重文件 + +将权重文件densenet121-a639ec97.pth放到当前工作目录(执行pth2onnx时会自动下载) +可以通过以下命令下载: +``` +wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/PAMTRI/densenet121-a639ec97.pth +``` + +4.数据集 + +参考[github开源代码仓内数据集获取方法](https://github.com/NVlabs/PAMTRI),将数据集放到./data目录。 +下载[数据集的label文件](https://github.com/NVlabs/PAMTRI.git),在PAMTRI/MultiTaskNet/data/veri/下获取label.csv文件。将数据集解压在./data/veri/目录下,应包含image_train、image_test、image_query三个数据集文件以及相应的.csv文件。 + +5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) +将benchmark.x86_64或benchmark.aarch64放到当前工作目录 + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +bash ./test/pth2om.sh +#启动脚本内3-8行为pth2onnx,10-19行为onnx2om,脚本执行完成后会生成PAMTRI.onnx、PAMTRI_bs1.om、PAMTRI_bs16.om三个模型。 +bash ./test/eval_acc_perf.sh --datasets_path=./data #datesets_path参数为指定数据集路径 +#启动脚本内12-15行为前处理,将图片信息转换为二进制bin文件;17-24行为提取与汇总前处理生成的bin文件信息;32-58行为benckmark推理,会生成推理后的特征信息与推理性能文件;60-69行为后处理,对推理出的特征信息进行评测,生成精度信息文件;70-92行为打印推理性能和精度信息。 +``` + **评测结果:** +| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| :-----------------------: | :----------------------------------------------------------: | :-------------------: | :------: | :---------: | +| PAMTRI bs1 | [mAP:68.64%](https://github.com/NVlabs/PAMTRI) | mAP:68.64% | 215.932fps | 627.662fps | +| PAMTRI bs16 | [mAP:68.64%](https://github.com/NVlabs/PAMTRI) | mAP:68.64% | 810.976fps | 833.668fps | +# 自检报告 + +``` +# pth是否能正确转换为om +bash test/pth2om.sh +# 验收结果: OK + +# 精度数据是否达标 +# npu性能数据 +bash test/eval_acc_perf.sh +# 验收结果: 是 + +# 在t4环境测试性能数据 +bash test/perf_t4.sh +# 验收结果: OK + +# 310性能是否符合标准: 是 +bs1:310=2.9倍t4 +bs16:310=1.03倍t4 + +``` diff --git a/ACL_PyTorch/contrib/cv/classfication/PAMTRI/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/PAMTRI/modelzoo_level.txt index 38700fca05402f52c3ae1c4be0889eb60e1f80f1..2e42553460a4f3687654b6ad3f91ab0bcc3aadac 100644 --- a/ACL_PyTorch/contrib/cv/classfication/PAMTRI/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/PAMTRI/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/LICENSE b/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/LICENSE index b1fac45f02e2f98395fd96a7e4f4a39e257ac0bc..989e2c59e973a05cfbfe9de678b7f2af777b0713 100644 --- a/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/LICENSE @@ -1,201 +1,201 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/PointNetCNN_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/PointNetCNN_preprocess.py index 9a11d950d8bada821daf2a115e08d99ca6f5aec3..2dd816aacc7f8474dddcc1881fb9826583b0d281 100644 --- a/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/PointNetCNN_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/PointNetCNN_preprocess.py @@ -1,56 +1,56 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import numpy as np -import os -import sys -import provider -BASE_DIR = os.path.dirname(os.path.abspath(__file__)) -sys.path.append(BASE_DIR) -sys.path.append(os.path.join(BASE_DIR, 'models')) -sys.path.append(os.path.join(BASE_DIR, 'utils')) - -TEST_FILES = provider.getDataFiles(os.path.join(BASE_DIR, 'data/modelnet40_ply_hdf5_2048/test_files.txt')) -BATCH_SIZE = 1 - -def preprocess(save_path,label_save_path): - i = 0 - test_file_idxs = np.arange(0, len(TEST_FILES)) - for fn in range(len(TEST_FILES)): - current_data, current_label = provider.loadDataFile(TEST_FILES[test_file_idxs[fn]]) - current_data = current_data[:, 0:1024, :] - file_size = current_data.shape[0] - num_batches = file_size // BATCH_SIZE - for batch_idx in range(num_batches): - i += 1 - start_idx = batch_idx * BATCH_SIZE - end_idx = (batch_idx + 1) * BATCH_SIZE - label = current_label[start_idx:end_idx] - rotated_data = provider.rotate_point_cloud(current_data[start_idx:end_idx, :, :]) - jittered_data = provider.jitter_point_cloud(rotated_data) # P_Sampled - P_sampled = np.array(torch.from_numpy(jittered_data).float(), dtype=np.float32) - - P_sampled.tofile(os.path.join(save_path, "data" +str(i) + ".bin")) - np.save(os.path.join(label_save_path,'label'+str(i)),label) - -if __name__ == "__main__": - save_path = sys.argv[1] - label_save_path = sys.argv[2] - save_path = os.path.realpath(save_path) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - if not os.path.isdir(label_save_path): - os.makedirs(os.path.realpath(label_save_path)) - preprocess( save_path,label_save_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import numpy as np +import os +import sys +import provider +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(BASE_DIR) +sys.path.append(os.path.join(BASE_DIR, 'models')) +sys.path.append(os.path.join(BASE_DIR, 'utils')) + +TEST_FILES = provider.getDataFiles(os.path.join(BASE_DIR, 'data/modelnet40_ply_hdf5_2048/test_files.txt')) +BATCH_SIZE = 1 + +def preprocess(save_path,label_save_path): + i = 0 + test_file_idxs = np.arange(0, len(TEST_FILES)) + for fn in range(len(TEST_FILES)): + current_data, current_label = provider.loadDataFile(TEST_FILES[test_file_idxs[fn]]) + current_data = current_data[:, 0:1024, :] + file_size = current_data.shape[0] + num_batches = file_size // BATCH_SIZE + for batch_idx in range(num_batches): + i += 1 + start_idx = batch_idx * BATCH_SIZE + end_idx = (batch_idx + 1) * BATCH_SIZE + label = current_label[start_idx:end_idx] + rotated_data = provider.rotate_point_cloud(current_data[start_idx:end_idx, :, :]) + jittered_data = provider.jitter_point_cloud(rotated_data) # P_Sampled + P_sampled = np.array(torch.from_numpy(jittered_data).float(), dtype=np.float32) + + P_sampled.tofile(os.path.join(save_path, "data" +str(i) + ".bin")) + np.save(os.path.join(label_save_path,'label'+str(i)),label) + +if __name__ == "__main__": + save_path = sys.argv[1] + label_save_path = sys.argv[2] + save_path = os.path.realpath(save_path) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + if not os.path.isdir(label_save_path): + os.makedirs(os.path.realpath(label_save_path)) + preprocess( save_path,label_save_path) diff --git a/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/README.md b/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/README.md index 1d2cd0c57b9141185e68a95ebf3d3545d8cb9181..bed77d35e3e6ac61062f5df629ee861fcd94fc14 100644 --- a/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/README.md @@ -1,64 +1,64 @@ -# PointNetCNN模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -``` -pip3.7 install -r requirements.txt -``` - -2.获取,修改与安装开源模型代码 -``` -git clone https://github.com/hxdengBerkeley/PointCNN.Pytorch -b master -cd PointCNN.Pytorch -git reset 6ec6c291cf97923a84fb6ed8c82e98bf01e7e96d --hard -patch -p1 < ../PointNetCNN.patch -cd .. -git clone https://gitee.com/Ronnie_zheng/MagicONNX.git -cd MagicONNX -pip install . -cd .. -cp -r PointCNN.Pytorch/utils PointCNN.Pytorch/provider.py ./ -``` -3.获取权重文件 - -将权重文件pointcnn_epoch240.pth放到当前工作目录 -``` -wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/PointNetCNN/pointcnn_epoch240.pth -``` - -4.数据集 -获取modelnet40_ply_hdf5_2048数据集,解压并放在./data目录下, -``` -mkdir data -cd data -wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/PointNetCNN/modelnet40_ply_hdf5_2048.zip -unzip -d modelnet40_ply_hdf5_2048 modelnet40_ply_hdf5_2048.zip -cd .. -``` - -5.[获取msame工具](https://gitee.com/ascend/tools/tree/master/msame#https://gitee.com/ascend/tools.git) -将msame工具放到当前工作目录 - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -1-6行是 转onnx -7-14行是 onnx转om -``` -bash test/pth2om.sh -``` -1-10行是 基本配置 -11-16行是 预处理 -17-22行是 使用msase工具推理 -23-30行是 使用benchmark工具推理 -38-43行是 精度统计 -44-50行是 性能统计 -``` -bash test/eval_acc_perf.sh --datasets_path=/root/datasets -``` - **评测结果:** -| 模型 | pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| :-------------: | :-----: | :-------------: | :------: | :-------: | -| PointNetCNN bs1 | 82.61% | 82.61% | 31fps | 27.3fps | - +# PointNetCNN模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip3.7 install -r requirements.txt +``` + +2.获取,修改与安装开源模型代码 +``` +git clone https://github.com/hxdengBerkeley/PointCNN.Pytorch -b master +cd PointCNN.Pytorch +git reset 6ec6c291cf97923a84fb6ed8c82e98bf01e7e96d --hard +patch -p1 < ../PointNetCNN.patch +cd .. +git clone https://gitee.com/Ronnie_zheng/MagicONNX.git +cd MagicONNX +pip install . +cd .. +cp -r PointCNN.Pytorch/utils PointCNN.Pytorch/provider.py ./ +``` +3.获取权重文件 + +将权重文件pointcnn_epoch240.pth放到当前工作目录 +``` +wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/PointNetCNN/pointcnn_epoch240.pth +``` + +4.数据集 +获取modelnet40_ply_hdf5_2048数据集,解压并放在./data目录下, +``` +mkdir data +cd data +wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/PointNetCNN/modelnet40_ply_hdf5_2048.zip +unzip -d modelnet40_ply_hdf5_2048 modelnet40_ply_hdf5_2048.zip +cd .. +``` + +5.[获取msame工具](https://gitee.com/ascend/tools/tree/master/msame#https://gitee.com/ascend/tools.git) +将msame工具放到当前工作目录 + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +1-6行是 转onnx +7-14行是 onnx转om +``` +bash test/pth2om.sh +``` +1-10行是 基本配置 +11-16行是 预处理 +17-22行是 使用msase工具推理 +23-30行是 使用benchmark工具推理 +38-43行是 精度统计 +44-50行是 性能统计 +``` +bash test/eval_acc_perf.sh --datasets_path=/root/datasets +``` + **评测结果:** +| 模型 | pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| :-------------: | :-----: | :-------------: | :------: | :-------: | +| PointNetCNN bs1 | 82.61% | 82.61% | 31fps | 27.3fps | + diff --git a/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/modelzoo_level.txt index 38700fca05402f52c3ae1c4be0889eb60e1f80f1..2e42553460a4f3687654b6ad3f91ab0bcc3aadac 100644 --- a/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/requirements.txt index 45587c8b52062a755f93cb3c1c41c213331b46d7..76f08412ee79abd7894132e6094be92fa85cfba6 100644 --- a/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/PointNetCNN/requirements.txt @@ -1,8 +1,8 @@ -torch == 1.8.0 -onnx == 1.10.2 -onnxruntime == 1.9.0 -onnx-simplifier == 0.3.6 -numpy == 1.20.3 -h5py == 3.1.0 -scipy == 1.2.0 -sklearn == 0.0 +torch == 1.8.0 +onnx == 1.10.2 +onnxruntime == 1.9.0 +onnx-simplifier == 0.3.6 +numpy == 1.20.3 +h5py == 3.1.0 +scipy == 1.2.0 +sklearn == 0.0 diff --git a/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/README.md b/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/README.md index 26f76975ae1f27800bd34defb4898b5c770d9a3c..9bd6b8f83d855f22fc58ec9205750ba82190a686 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/README.md @@ -1,69 +1,69 @@ -# PointNet++ Onnx模型端到端推理指导 - -## 1. 环境准备 -1.1.安装必要的依赖 - -```shell -pip3.7 install -r requirements.txt -``` - -1.2.获取,修改与安装开源模型代码 - -```shell -git clone https://github.com/yanx27/Pointnet_Pointnet2_pytorch models -cd models -git checkout e365b9f7b9c3d7d6444278d92e298e3f078794e1 -patch -p1 < ../models.patch -cd .. -``` - -1.3. 获取权重文件 - -pth采用开源仓自带的权重,权重位置: -```shell -./models/log/classification/pointnet2_ssg_wo_normals/checkpoints/best_model.pth -``` - -1.4. 数据集 - -[测试集](https://shapenet.cs.stanford.edu) - -1.5. 获取离线推理工具 - -[benchmark](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) -[msame](https://gitee.com/ascend/tools/tree/master/msame) - -## 2. 离线推理 - -2.1 模型转换&&精度测试 -在310上执行,执行时采用npu-smi info查看设备状态,确保device空闲 - -```shell -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets -``` - -2.2 性能测试 - -gpu测速,在对应gpu设备上执行,执行时采用nvidia-smi查看设备状态,确保device空闲 - -```shell -bash test/perf_g.sh -``` -npu测速,在对应npu设备上执行,执行时采用npu-smi info查看设备状态,确保device空闲 - -```shell -./benchmark.x86_64 -round=100 -om_path=Pointnetplus_part1_bs1.om -device_id=0 -batch_size=1 -./benchmark.x86_64 -round=100 -om_path=Pointnetplus_part2_bs1.om -device_id=0 -batch_size=1 -./benchmark.x86_64 -round=100 -om_path=Pointnetplus_part1_bs16.om -device_id=0 -batch_size=16 -./benchmark.x86_64 -round=100 -om_path=Pointnetplus_part2_bs16.om -device_id=0 -batch_size=16 -``` - -**评测结果:** - -| 模型 | batch_size | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -|------------------|------------|---------------------------------------------|-----------------------------------------|----------|---------| -| PointNet++_part1 | 1 | - | - | 2997fps | 5308fps | -| PointNet++_part2 | 1 | Instance Acc: 0.928964, Class Acc: 0.890532 | Instance Acc: 0.9263, Class Acc: 0.8877 | 2571fps | 4105fps | -| PointNet++_part1 | 16 | - | - | 3468fps | 5968fps | -| PointNet++_part2 | 16 | - | Instance Acc: 0.9245, Class Acc: 0.8854 | 3670fps | 3730fps | +# PointNet++ Onnx模型端到端推理指导 + +## 1. 环境准备 +1.1.安装必要的依赖 + +```shell +pip3.7 install -r requirements.txt +``` + +1.2.获取,修改与安装开源模型代码 + +```shell +git clone https://github.com/yanx27/Pointnet_Pointnet2_pytorch models +cd models +git checkout e365b9f7b9c3d7d6444278d92e298e3f078794e1 +patch -p1 < ../models.patch +cd .. +``` + +1.3. 获取权重文件 + +pth采用开源仓自带的权重,权重位置: +```shell +./models/log/classification/pointnet2_ssg_wo_normals/checkpoints/best_model.pth +``` + +1.4. 数据集 + +[测试集](https://shapenet.cs.stanford.edu) + +1.5. 获取离线推理工具 + +[benchmark](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) +[msame](https://gitee.com/ascend/tools/tree/master/msame) + +## 2. 离线推理 + +2.1 模型转换&&精度测试 +在310上执行,执行时采用npu-smi info查看设备状态,确保device空闲 + +```shell +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets +``` + +2.2 性能测试 + +gpu测速,在对应gpu设备上执行,执行时采用nvidia-smi查看设备状态,确保device空闲 + +```shell +bash test/perf_g.sh +``` +npu测速,在对应npu设备上执行,执行时采用npu-smi info查看设备状态,确保device空闲 + +```shell +./benchmark.x86_64 -round=100 -om_path=Pointnetplus_part1_bs1.om -device_id=0 -batch_size=1 +./benchmark.x86_64 -round=100 -om_path=Pointnetplus_part2_bs1.om -device_id=0 -batch_size=1 +./benchmark.x86_64 -round=100 -om_path=Pointnetplus_part1_bs16.om -device_id=0 -batch_size=16 +./benchmark.x86_64 -round=100 -om_path=Pointnetplus_part2_bs16.om -device_id=0 -batch_size=16 +``` + +**评测结果:** + +| 模型 | batch_size | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +|------------------|------------|---------------------------------------------|-----------------------------------------|----------|---------| +| PointNet++_part1 | 1 | - | - | 2997fps | 5308fps | +| PointNet++_part2 | 1 | Instance Acc: 0.928964, Class Acc: 0.890532 | Instance Acc: 0.9263, Class Acc: 0.8877 | 2571fps | 4105fps | +| PointNet++_part1 | 16 | - | - | 3468fps | 5968fps | +| PointNet++_part2 | 16 | - | Instance Acc: 0.9245, Class Acc: 0.8854 | 3670fps | 3730fps | diff --git a/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/pointnetplus_postprocess.py b/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/pointnetplus_postprocess.py index 4c9ab76a6d5105a783e4b43e8bbc33f54f96d2f1..acfce5a38c3e14fcb605486c356349dca01ee93f 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/pointnetplus_postprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/pointnetplus_postprocess.py @@ -1,115 +1,115 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import numpy as np -import os -import torch -import logging -import sys -from tqdm import tqdm - - -def parse_args(): - '''PARAMETERS''' - parser = argparse.ArgumentParser('off_line_pred') - parser.add_argument('--target_path', type=str, default='out/bs1/', - required=False, help='target root') - parser.add_argument('--data_loc', type=str, default='/home/data/modelnet40_normal_resampled/', required=False, help='data location') - parser.add_argument('--batch_size', type=int, default=1, required=False, - help='batch size') - args = parser.parse_args() - out_folder = os.listdir(args.target_path)[-1] - args.target_path = os.path.join(args.target_path, out_folder) - return args - -def pc_normalize(pc): - centroid = np.mean(pc, axis=0) - pc = pc - centroid - m = np.max(np.sqrt(np.sum(pc**2, axis=1))) - pc = pc / m - return pc - -def model_data_loader(data_pth): - data_path = data_pth - catfile = os.path.join(data_path, 'modelnet40_shape_names.txt') - cat = [line.rstrip() for line in open(catfile)] - classes = dict(zip(cat, range(len(cat)))) - shape_ids = {} - shape_ids['test'] = [line.rstrip() for line in open(os.path.join(data_path, 'modelnet40_test.txt'))] - split = 'test' - shape_names = ['_'.join(x.split('_')[0:-1]) for x in shape_ids[split]] - datapath = [(shape_names[i], os.path.join(data_path, shape_names[i], shape_ids[split][i]) + '.txt') for i - in range(len(shape_ids[split]))] - print('The size of %s data is %d' % (split, len(datapath))) - return classes, datapath - -def test(pred_path,data_path): - mean_correct = [] - class_acc = np.zeros((40, 3)) - - classes,data_pth = model_data_loader(data_path) - print('data is %d' % len(data_pth)) - # load infer results - def load_infer_results(): - num_out = len(data_pth) // args.batch_size - for j in range(num_out): - pred_loca = os.path.join(pred_path, 'part2_' + str(j) + '_output_0.bin') - pred = np.fromfile(pred_loca,np.float32) - if args.batch_size == 1: - pred.shape = 1, 40 - pred = torch.from_numpy(pred) - yield pred - else: - pred.shape = args.batch_size, 40 - for d in pred: - d = torch.from_numpy(np.expand_dims(d, axis=0)) - yield d - infer_results = load_infer_results() - - # load gt results - num_results = len(data_pth) // args.batch_size * args.batch_size - for j in tqdm(range(num_results)): - fn = data_pth[j] - cls = classes[data_pth[j][0]] - target = np.array([cls]).astype(np.int32) - point_set = np.loadtxt(fn[1], delimiter=',').astype(np.float32) - point_set = point_set[0:1024, :] - point_set[:, 0:3] = pc_normalize(point_set[:, 0:3]) - point_set = point_set[:, 0:3] - point_set = point_set[None,] - new_point_set = torch.from_numpy(point_set) - points = new_point_set.transpose(2, 1) - target = torch.from_numpy(target) - - pred = next(infer_results) - pred_choice = pred.data.max(1)[1] - '''验证精度''' - for cat in np.unique(target.cpu()): - classacc = pred_choice[target == cat].eq(target[target == cat].long().data).cpu().sum() - class_acc[cat, 0] += classacc.item() / float(points[target == cat].size()[0]) - class_acc[cat, 1] += 1 - correct = pred_choice.eq(target.long().data).cpu().sum() - mean_correct.append(correct.item() / float(points.size()[0])) - - class_acc[:, 2] = class_acc[:, 0] / class_acc[:, 1] - class_acc = np.mean(class_acc[:, 2]) - instance_acc = np.mean(mean_correct) - print('class_acc is %f' % class_acc) - print('instance_acc is %f' % instance_acc) - return instance_acc, class_acc - -if __name__ == '__main__': - args = parse_args() - test(args.target_path, args.data_loc) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import numpy as np +import os +import torch +import logging +import sys +from tqdm import tqdm + + +def parse_args(): + '''PARAMETERS''' + parser = argparse.ArgumentParser('off_line_pred') + parser.add_argument('--target_path', type=str, default='out/bs1/', + required=False, help='target root') + parser.add_argument('--data_loc', type=str, default='/home/data/modelnet40_normal_resampled/', required=False, help='data location') + parser.add_argument('--batch_size', type=int, default=1, required=False, + help='batch size') + args = parser.parse_args() + out_folder = os.listdir(args.target_path)[-1] + args.target_path = os.path.join(args.target_path, out_folder) + return args + +def pc_normalize(pc): + centroid = np.mean(pc, axis=0) + pc = pc - centroid + m = np.max(np.sqrt(np.sum(pc**2, axis=1))) + pc = pc / m + return pc + +def model_data_loader(data_pth): + data_path = data_pth + catfile = os.path.join(data_path, 'modelnet40_shape_names.txt') + cat = [line.rstrip() for line in open(catfile)] + classes = dict(zip(cat, range(len(cat)))) + shape_ids = {} + shape_ids['test'] = [line.rstrip() for line in open(os.path.join(data_path, 'modelnet40_test.txt'))] + split = 'test' + shape_names = ['_'.join(x.split('_')[0:-1]) for x in shape_ids[split]] + datapath = [(shape_names[i], os.path.join(data_path, shape_names[i], shape_ids[split][i]) + '.txt') for i + in range(len(shape_ids[split]))] + print('The size of %s data is %d' % (split, len(datapath))) + return classes, datapath + +def test(pred_path,data_path): + mean_correct = [] + class_acc = np.zeros((40, 3)) + + classes,data_pth = model_data_loader(data_path) + print('data is %d' % len(data_pth)) + # load infer results + def load_infer_results(): + num_out = len(data_pth) // args.batch_size + for j in range(num_out): + pred_loca = os.path.join(pred_path, 'part2_' + str(j) + '_output_0.bin') + pred = np.fromfile(pred_loca,np.float32) + if args.batch_size == 1: + pred.shape = 1, 40 + pred = torch.from_numpy(pred) + yield pred + else: + pred.shape = args.batch_size, 40 + for d in pred: + d = torch.from_numpy(np.expand_dims(d, axis=0)) + yield d + infer_results = load_infer_results() + + # load gt results + num_results = len(data_pth) // args.batch_size * args.batch_size + for j in tqdm(range(num_results)): + fn = data_pth[j] + cls = classes[data_pth[j][0]] + target = np.array([cls]).astype(np.int32) + point_set = np.loadtxt(fn[1], delimiter=',').astype(np.float32) + point_set = point_set[0:1024, :] + point_set[:, 0:3] = pc_normalize(point_set[:, 0:3]) + point_set = point_set[:, 0:3] + point_set = point_set[None,] + new_point_set = torch.from_numpy(point_set) + points = new_point_set.transpose(2, 1) + target = torch.from_numpy(target) + + pred = next(infer_results) + pred_choice = pred.data.max(1)[1] + '''验证精度''' + for cat in np.unique(target.cpu()): + classacc = pred_choice[target == cat].eq(target[target == cat].long().data).cpu().sum() + class_acc[cat, 0] += classacc.item() / float(points[target == cat].size()[0]) + class_acc[cat, 1] += 1 + correct = pred_choice.eq(target.long().data).cpu().sum() + mean_correct.append(correct.item() / float(points.size()[0])) + + class_acc[:, 2] = class_acc[:, 0] / class_acc[:, 1] + class_acc = np.mean(class_acc[:, 2]) + instance_acc = np.mean(mean_correct) + print('class_acc is %f' % class_acc) + print('instance_acc is %f' % instance_acc) + return instance_acc, class_acc + +if __name__ == '__main__': + args = parse_args() + test(args.target_path, args.data_loc) diff --git a/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/pointnetplus_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/pointnetplus_preprocess.py index 5c9fe9aa98836d250eb0cd4c6b6deb2742158245..2167b19ba0b72716c56e85b87b617f21ebbba334 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/pointnetplus_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/pointnetplus_preprocess.py @@ -1,157 +1,157 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import numpy as np -import torch -import argparse -import sys -sys.path.append('./models') -from tqdm import tqdm -from models.pointnet2_utils import sample_and_group, farthest_point_sample -import glob - -def parse_args(): - '''PARAMETERS''' - parser = argparse.ArgumentParser('data_process') - parser.add_argument('--preprocess_part', type=int, default=1, required=False, help='preprocess target') - parser.add_argument('--save_path', type=str, default='./modelnet40_processed/test_preprocess/pointset_chg', required=False, help='target root') - parser.add_argument('--save_path2', type=str, default='./modelnet40_processed/test_preprocess/xyz_chg', required=False, help='target root') - parser.add_argument('--data_loc', type=str, default='', required=False, help='data location') - parser.add_argument('--data_loc2', type=str, default='./modelnet40_processed/test_preprocess/xyz_chg', required=False, help='data location') - parser.add_argument('--batch_size', type=int, default=1, required=False, help='batch size for preprocess') - return parser.parse_args() - - -def pc_normalize(pc): - centroid = np.mean(pc, axis=0) - pc = pc - centroid - m = np.max(np.sqrt(np.sum(pc**2, axis=1))) - pc = pc / m - return pc - - -def preprocess(save_path,save_path2,data_location): - data_path = data_location - save_path = save_path - save_path2 = save_path2 - catfile = os.path.join(data_path, 'modelnet40_shape_names.txt') - cat = [line.rstrip() for line in open(catfile)] - classes = dict(zip(cat, range(len(cat)))) - shape_ids = {} - shape_ids['test'] = [line.rstrip() for line in open(os.path.join(data_path, 'modelnet40_test.txt'))] - split = 'test' - shape_names = ['_'.join(x.split('_')[0:-1]) for x in shape_ids[split]] - datapath = [(shape_names[i], os.path.join(data_path, shape_names[i], shape_ids[split][i]) + '.txt') for i - in range(len(shape_ids[split]))] - print('The size of %s data is %d' % (split, len(datapath))) - os.makedirs(save_path, exist_ok=True) - os.makedirs(save_path2, exist_ok=True) - - point_set_list = [] - new_xyz_list = [] - for index in tqdm(range(len(datapath))): - fn = datapath[index] - cls = classes[datapath[index][0]] - label = np.array([cls]).astype(np.int32) - point_set = np.loadtxt(fn[1], delimiter=',').astype(np.float32) - point_set = point_set[0:1024, :] - point_set[:, 0:3] = pc_normalize(point_set[:, 0:3]) - point_set = point_set[:, 0:3] - point_set = point_set[None,] - # print(point_set.shape) - new_point_set = torch.from_numpy(point_set) - new_point_set = new_point_set.transpose(2, 1) - npoint = 512 - radius = 0.2 - nsample = 32 - points = None - new_point_set = new_point_set.permute(0, 2, 1) - centroid = farthest_point_sample(new_point_set, npoint) - new_xyz, new_points = sample_and_group(npoint, radius, nsample, new_point_set, points, centroid) - - new_xyz = new_xyz.permute(0,2,1) - new_points = new_points.permute(0,3,2,1) - point_set, new_xyz = new_points.numpy(),new_xyz.numpy() - - point_name = 'point_set'+str(index) - if args.batch_size == 1: - point_set.tofile(os.path.join(save_path, point_name.split('.')[0] + ".bin")) - new_xyz.tofile(os.path.join(save_path2, point_name.split('.')[0] + ".bin")) - else: - point_set_list.append(point_set) - new_xyz_list.append(new_xyz) - if len(point_set_list) == args.batch_size: - point_sets = np.array(point_set_list) - new_xyzes = np.array(new_xyz_list) - point_names = 'point_set{}.bin'.format(str(index // 16)) - point_sets.tofile(os.path.join(save_path, point_names)) - new_xyzes.tofile(os.path.join(save_path2, point_names)) - point_set_list.clear() - new_xyz_list.clear() - - -def preprocess2(save_path,save_path2,data_location,data_location2): - data_toal_folder = os.listdir(data_location)[-1] - data_total_path = os.path.join(data_location, data_toal_folder) - save_path = save_path - save_path2 = save_path2 - file_start = 'point_set' - file_end_one = '_output_1.bin' - file_end_zero = '_output_0.bin' - os.makedirs(save_path, exist_ok=True) - os.makedirs(save_path2, exist_ok=True) - test = os.path.join(data_total_path, file_start+str(0)+file_end_zero) - try: - file_end = file_end_zero - test2 = np.fromfile(test,dtype=np.float32) - test_set.shape = args.batch_size,128,512 - except: - file_end = file_end_one - print(file_end) - data_total_path2 = data_location2 - file_end_two = '.bin' - path_file_number=glob.glob(data_location2+'/*.bin') - - for index in tqdm(range(len(path_file_number))): - data_path2 = os.path.join(data_total_path2, file_start+str(index)+file_end_two) - data_path1 = os.path.join(data_total_path, file_start+str(index)+file_end) - point_set = np.fromfile(data_path1,dtype=np.float32) - point_set2 = np.fromfile(data_path2,dtype=np.float32) - point_set.shape = args.batch_size,128,512 - point_set2.shape = args.batch_size,3,512 - new_point_set = torch.from_numpy(point_set2) - point_set2 = torch.from_numpy(point_set) - npoint = 128 - radius = 0.4 - nsample = 64 - new_point_set = new_point_set.permute(0, 2, 1) - point_set2 = point_set2.permute(0,2,1) - centroid = farthest_point_sample(new_point_set, npoint) - new_xyz, new_points = sample_and_group(npoint, radius, nsample, new_point_set, point_set2, centroid) - new_point_set = new_point_set.permute(0, 2, 1) - new_points = new_points.permute(0,3,2,1) - new_xyz = new_xyz.permute(0,2,1) - point_set,new_xyz = new_points.numpy(),new_xyz.numpy() - point_name = 'part2_'+str(index) - point_set.tofile(os.path.join(save_path, point_name.split('.')[0] + ".bin")) - new_xyz.tofile(os.path.join(save_path2, point_name.split('.')[0] + ".bin")) - - -if __name__ == '__main__': - args = parse_args() - if(1 == args.preprocess_part): - preprocess(args.save_path,args.save_path2,args.data_loc) - else: - preprocess2(args.save_path,args.save_path2,args.data_loc,args.data_loc2) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import numpy as np +import torch +import argparse +import sys +sys.path.append('./models') +from tqdm import tqdm +from models.pointnet2_utils import sample_and_group, farthest_point_sample +import glob + +def parse_args(): + '''PARAMETERS''' + parser = argparse.ArgumentParser('data_process') + parser.add_argument('--preprocess_part', type=int, default=1, required=False, help='preprocess target') + parser.add_argument('--save_path', type=str, default='./modelnet40_processed/test_preprocess/pointset_chg', required=False, help='target root') + parser.add_argument('--save_path2', type=str, default='./modelnet40_processed/test_preprocess/xyz_chg', required=False, help='target root') + parser.add_argument('--data_loc', type=str, default='', required=False, help='data location') + parser.add_argument('--data_loc2', type=str, default='./modelnet40_processed/test_preprocess/xyz_chg', required=False, help='data location') + parser.add_argument('--batch_size', type=int, default=1, required=False, help='batch size for preprocess') + return parser.parse_args() + + +def pc_normalize(pc): + centroid = np.mean(pc, axis=0) + pc = pc - centroid + m = np.max(np.sqrt(np.sum(pc**2, axis=1))) + pc = pc / m + return pc + + +def preprocess(save_path,save_path2,data_location): + data_path = data_location + save_path = save_path + save_path2 = save_path2 + catfile = os.path.join(data_path, 'modelnet40_shape_names.txt') + cat = [line.rstrip() for line in open(catfile)] + classes = dict(zip(cat, range(len(cat)))) + shape_ids = {} + shape_ids['test'] = [line.rstrip() for line in open(os.path.join(data_path, 'modelnet40_test.txt'))] + split = 'test' + shape_names = ['_'.join(x.split('_')[0:-1]) for x in shape_ids[split]] + datapath = [(shape_names[i], os.path.join(data_path, shape_names[i], shape_ids[split][i]) + '.txt') for i + in range(len(shape_ids[split]))] + print('The size of %s data is %d' % (split, len(datapath))) + os.makedirs(save_path, exist_ok=True) + os.makedirs(save_path2, exist_ok=True) + + point_set_list = [] + new_xyz_list = [] + for index in tqdm(range(len(datapath))): + fn = datapath[index] + cls = classes[datapath[index][0]] + label = np.array([cls]).astype(np.int32) + point_set = np.loadtxt(fn[1], delimiter=',').astype(np.float32) + point_set = point_set[0:1024, :] + point_set[:, 0:3] = pc_normalize(point_set[:, 0:3]) + point_set = point_set[:, 0:3] + point_set = point_set[None,] + # print(point_set.shape) + new_point_set = torch.from_numpy(point_set) + new_point_set = new_point_set.transpose(2, 1) + npoint = 512 + radius = 0.2 + nsample = 32 + points = None + new_point_set = new_point_set.permute(0, 2, 1) + centroid = farthest_point_sample(new_point_set, npoint) + new_xyz, new_points = sample_and_group(npoint, radius, nsample, new_point_set, points, centroid) + + new_xyz = new_xyz.permute(0,2,1) + new_points = new_points.permute(0,3,2,1) + point_set, new_xyz = new_points.numpy(),new_xyz.numpy() + + point_name = 'point_set'+str(index) + if args.batch_size == 1: + point_set.tofile(os.path.join(save_path, point_name.split('.')[0] + ".bin")) + new_xyz.tofile(os.path.join(save_path2, point_name.split('.')[0] + ".bin")) + else: + point_set_list.append(point_set) + new_xyz_list.append(new_xyz) + if len(point_set_list) == args.batch_size: + point_sets = np.array(point_set_list) + new_xyzes = np.array(new_xyz_list) + point_names = 'point_set{}.bin'.format(str(index // 16)) + point_sets.tofile(os.path.join(save_path, point_names)) + new_xyzes.tofile(os.path.join(save_path2, point_names)) + point_set_list.clear() + new_xyz_list.clear() + + +def preprocess2(save_path,save_path2,data_location,data_location2): + data_toal_folder = os.listdir(data_location)[-1] + data_total_path = os.path.join(data_location, data_toal_folder) + save_path = save_path + save_path2 = save_path2 + file_start = 'point_set' + file_end_one = '_output_1.bin' + file_end_zero = '_output_0.bin' + os.makedirs(save_path, exist_ok=True) + os.makedirs(save_path2, exist_ok=True) + test = os.path.join(data_total_path, file_start+str(0)+file_end_zero) + try: + file_end = file_end_zero + test2 = np.fromfile(test,dtype=np.float32) + test_set.shape = args.batch_size,128,512 + except: + file_end = file_end_one + print(file_end) + data_total_path2 = data_location2 + file_end_two = '.bin' + path_file_number=glob.glob(data_location2+'/*.bin') + + for index in tqdm(range(len(path_file_number))): + data_path2 = os.path.join(data_total_path2, file_start+str(index)+file_end_two) + data_path1 = os.path.join(data_total_path, file_start+str(index)+file_end) + point_set = np.fromfile(data_path1,dtype=np.float32) + point_set2 = np.fromfile(data_path2,dtype=np.float32) + point_set.shape = args.batch_size,128,512 + point_set2.shape = args.batch_size,3,512 + new_point_set = torch.from_numpy(point_set2) + point_set2 = torch.from_numpy(point_set) + npoint = 128 + radius = 0.4 + nsample = 64 + new_point_set = new_point_set.permute(0, 2, 1) + point_set2 = point_set2.permute(0,2,1) + centroid = farthest_point_sample(new_point_set, npoint) + new_xyz, new_points = sample_and_group(npoint, radius, nsample, new_point_set, point_set2, centroid) + new_point_set = new_point_set.permute(0, 2, 1) + new_points = new_points.permute(0,3,2,1) + new_xyz = new_xyz.permute(0,2,1) + point_set,new_xyz = new_points.numpy(),new_xyz.numpy() + point_name = 'part2_'+str(index) + point_set.tofile(os.path.join(save_path, point_name.split('.')[0] + ".bin")) + new_xyz.tofile(os.path.join(save_path2, point_name.split('.')[0] + ".bin")) + + +if __name__ == '__main__': + args = parse_args() + if(1 == args.preprocess_part): + preprocess(args.save_path,args.save_path2,args.data_loc) + else: + preprocess2(args.save_path,args.save_path2,args.data_loc,args.data_loc2) diff --git a/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/pointnetplus_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/pointnetplus_pth2onnx.py index bb92b279f8849a1865e791bc60a632c473db756f..4728535261abf781fb2c64b17a541e62015b5fad 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/pointnetplus_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/pointnetplus_pth2onnx.py @@ -1,104 +1,104 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from collections import OrderedDict -import torch -import torch.onnx -import argparse -import sys -sys.path.append('./models/models') -import pointnet2_cls_ssg as pointnet2_cls -from pointnet2_utils import farthest_point_sample -from pointnet2_utils import sample_and_group - - -def parse_args(): - '''PARAMETERS''' - parser = argparse.ArgumentParser('off_line_pred') - parser.add_argument('--target_model', type=int, default=1, - required=True, help='target trans_models') - parser.add_argument('--pth_dir', type=str, default='', - required=False, help='target trans_models') - parser.add_argument('--batch_size', type=int, default=1, - required=False, help='batch size') - return parser.parse_args() - - -def proc_node_module(checkpoint, AttrName): - new_state_dict = OrderedDict() - for k, v in checkpoint[AttrName].items(): - if k[0:7] == "module.": - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - - -def model_convert(dir): - experiment_dir = dir - dummy_input = torch.randn(args.batch_size, 3, 1024) - checkpoint = torch.load(str(experiment_dir) + '/best_model.pth',map_location = 'cpu') - checkpoint['model_state_dict'] = proc_node_module(checkpoint,'model_state_dict') - model = pointnet2_cls.get_model_part1(normal_channel=False) - model.load_state_dict(checkpoint['model_state_dict']) - model.eval() - npoint = 512 - radius = 0.2 - nsample = 32 - points = None - test_input = dummy_input.permute(0, 2, 1) - centroid = farthest_point_sample(test_input, npoint) - new_xyz, new_points = sample_and_group(npoint, radius, nsample, test_input, points, centroid) - new_points = new_points.permute(0, 3, 2, 1) - input_names = ["xyz", "samp_points"] - output_names = ["l1_xyz", "l1_point"] - torch.onnx.export(model, (new_xyz, new_points), - "Pointnetplus_part1_bs{}.onnx".format(args.batch_size), - input_names=input_names, verbose=True, output_names=output_names, opset_version=11) - - -def model_convert2(dir): - experiment_dir = dir - dummy_xyz_input = torch.randn(args.batch_size, 3, 512) - dummy_point_input = torch.randn(args.batch_size, 128, 512) - checkpoint = torch.load(str(experiment_dir) + '/best_model.pth',map_location = 'cpu') - checkpoint['model_state_dict'] = proc_node_module(checkpoint,'model_state_dict') - model = pointnet2_cls.get_model_part2(normal_channel=False) - model.load_state_dict(checkpoint['model_state_dict']) - model.eval() - npoint = 128 - radius = 0.4 - nsample = 64 - points = None - test_input = dummy_xyz_input.permute(0, 2, 1) - test_points = dummy_point_input.permute(0, 2, 1) - centroid = farthest_point_sample(test_input, npoint) - new_xyz, new_points = sample_and_group(npoint, radius, nsample, test_input, test_points, centroid) - new_points = new_points.permute(0, 3, 2, 1) - new_xyz = new_xyz.permute(0, 2, 1) - input_names = ["l1_xyz", "l1_points"] - output_names = ["class", "l3_point"] - - torch.onnx.export(model, (new_xyz, new_points), - "Pointnetplus_part2_bs{}.onnx".format(args.batch_size), - input_names=input_names, verbose=True, output_names=output_names, opset_version=11) - - -if __name__ == '__main__': - args = parse_args() - if(args.target_model == 1): - model_convert(args.pth_dir) - else: - model_convert2(args.pth_dir) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from collections import OrderedDict +import torch +import torch.onnx +import argparse +import sys +sys.path.append('./models/models') +import pointnet2_cls_ssg as pointnet2_cls +from pointnet2_utils import farthest_point_sample +from pointnet2_utils import sample_and_group + + +def parse_args(): + '''PARAMETERS''' + parser = argparse.ArgumentParser('off_line_pred') + parser.add_argument('--target_model', type=int, default=1, + required=True, help='target trans_models') + parser.add_argument('--pth_dir', type=str, default='', + required=False, help='target trans_models') + parser.add_argument('--batch_size', type=int, default=1, + required=False, help='batch size') + return parser.parse_args() + + +def proc_node_module(checkpoint, AttrName): + new_state_dict = OrderedDict() + for k, v in checkpoint[AttrName].items(): + if k[0:7] == "module.": + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + + +def model_convert(dir): + experiment_dir = dir + dummy_input = torch.randn(args.batch_size, 3, 1024) + checkpoint = torch.load(str(experiment_dir) + '/best_model.pth',map_location = 'cpu') + checkpoint['model_state_dict'] = proc_node_module(checkpoint,'model_state_dict') + model = pointnet2_cls.get_model_part1(normal_channel=False) + model.load_state_dict(checkpoint['model_state_dict']) + model.eval() + npoint = 512 + radius = 0.2 + nsample = 32 + points = None + test_input = dummy_input.permute(0, 2, 1) + centroid = farthest_point_sample(test_input, npoint) + new_xyz, new_points = sample_and_group(npoint, radius, nsample, test_input, points, centroid) + new_points = new_points.permute(0, 3, 2, 1) + input_names = ["xyz", "samp_points"] + output_names = ["l1_xyz", "l1_point"] + torch.onnx.export(model, (new_xyz, new_points), + "Pointnetplus_part1_bs{}.onnx".format(args.batch_size), + input_names=input_names, verbose=True, output_names=output_names, opset_version=11) + + +def model_convert2(dir): + experiment_dir = dir + dummy_xyz_input = torch.randn(args.batch_size, 3, 512) + dummy_point_input = torch.randn(args.batch_size, 128, 512) + checkpoint = torch.load(str(experiment_dir) + '/best_model.pth',map_location = 'cpu') + checkpoint['model_state_dict'] = proc_node_module(checkpoint,'model_state_dict') + model = pointnet2_cls.get_model_part2(normal_channel=False) + model.load_state_dict(checkpoint['model_state_dict']) + model.eval() + npoint = 128 + radius = 0.4 + nsample = 64 + points = None + test_input = dummy_xyz_input.permute(0, 2, 1) + test_points = dummy_point_input.permute(0, 2, 1) + centroid = farthest_point_sample(test_input, npoint) + new_xyz, new_points = sample_and_group(npoint, radius, nsample, test_input, test_points, centroid) + new_points = new_points.permute(0, 3, 2, 1) + new_xyz = new_xyz.permute(0, 2, 1) + input_names = ["l1_xyz", "l1_points"] + output_names = ["class", "l3_point"] + + torch.onnx.export(model, (new_xyz, new_points), + "Pointnetplus_part2_bs{}.onnx".format(args.batch_size), + input_names=input_names, verbose=True, output_names=output_names, opset_version=11) + + +if __name__ == '__main__': + args = parse_args() + if(args.target_model == 1): + model_convert(args.pth_dir) + else: + model_convert2(args.pth_dir) diff --git a/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/requirements.txt index e3e632f5e9d0b64724c7ef67c5e1c6d44ce30425..ad7ae69defba9cbbf3962d079ce68ca2b6a4d5b8 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/Pointnetplus/Pointnetplus/requirements.txt @@ -1,5 +1,5 @@ -torch == 1.9.0 -onnx == 1.9.0 -tqdm == 4.62.2 -torchvision == 0.10.0 -numpy +torch == 1.9.0 +onnx == 1.9.0 +tqdm == 4.62.2 +torchvision == 0.10.0 +numpy diff --git a/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/ LICENSE b/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/ LICENSE index 797bf40e85c5d2986ebcec9cb51aed979ca88b82..04adf5cbc620ad190547b092fa449e36df5f7bf4 100644 --- a/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/ LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/ LICENSE @@ -1,203 +1,203 @@ -Copyright 2018-2019 Open-MMLab. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2018-2019 Open-MMLab. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Copyright 2018-2019 Open-MMLab. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2019 Open-MMLab. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/ modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/ modelzoo_level.txt index d44ba5698b045b8a30e107962f295dbc24585d8c..70801afc42b6d9eb5cdd98b5430d9b2101f3146a 100644 --- a/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/ modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/ modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/ReadME.md b/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/ReadME.md index 1cdecd9b313bad706e5dc9b91be07d45bb0a9705..91cf9a02522497b72701710e8eb12b9e856afec6 100644 --- a/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/ReadME.md +++ b/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/ReadME.md @@ -1,76 +1,76 @@ -# R(2+1)D模型PyTorch离线推理指导 - -## 1 环境准备 - -- **1.1 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装** - -``` -pip3.7 install -r requirements.txt -``` - -- **1.2 获取,修改与安装开源模型代码** - -``` -git clone https://github.com/open-mmlab/mmcv -b master -cd mmcv -git reset --hard 6cb534b775b7502f0dcc59331236e619d3ae5b9f -MMCV_WITH_OPS=1 pip3.7 install -e . - -cd .. -git clone https://github.com/open-mmlab/mmaction2 -b master -cd mmaction2 -git reset --hard acce52d21a2545d9351b1060853c3bcd171b7158 -python3.7 setup.py develop - -``` -注:若上述命令不能下载源码,则将https替换为git(如:git clone git://github.com/open-mmlab/mmcv -b master ) - -将mmaction2/tools/deployment/目录下的pytorch2onnx.py中的torch.onnx.export添加一个参数: - -` dynamic_axes={'0':{0:'-1'}}, ` - -将r2plus1d_r34_8x8x1_180e_ucf101_rgb2.py文件放在mmaction2/configs/recognition/r2plus1d文件夹下 - -- **1.3 [获取权重文件](https://www.aliyundrive.com/drive/folder/6130e24c1b56461015b44659bdc650a9d3cd8e71)** - -- **1.4 [数据集UCF-101](https://www.crcv.ucf.edu/data/UCF101/UCF101.rar)** - -将UCF101.rar文件解压,重命名为ucf101,放在 /root/datasets/文件夹下 - -``` -在当前目录创建videos文件夹 -mkdir -p ./data/ucf101/videos - -将/root/datasets/ucf101文件夹下的视频文件夹复制到videos下 -cp -r /root/datasets/ucf101/* ./data/ucf101/videos - -python3.7 ./mmaction2/tools/data/build_rawframes.py ./data/ucf101/videos/ ./data/ucf101/rawframes/ --task rgb --level 2 --ext avi --use-opencv - -DATA_DIR_AN="./data/ucf101/annotations" - -wget https://www.crcv.ucf.edu/wp-content/uploads/2019/03/UCF101TrainTestSplits-RecognitionTask.zip --no-check-certificate - -unzip -j UCF101TrainTestSplits-RecognitionTask.zip -d ${DATA_DIR_AN}/ -rm UCF101TrainTestSplits-RecognitionTask.zip - -PYTHONPATH=. python3.7 ./mmaction2/tools/data/build_file_list.py ucf101 data/ucf101/rawframes/ --level 2 --format rawframes --shuffle -``` -- **1.5 获取[msame工具](https://gitee.com/ascend/tools/tree/master/msame)和[benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer)** - -将msame和benchmark.x86_64(或benchmark.aarch64)放到当前目录 - -## 2 离线推理 - -- **310上执行,执行时使npu-smi info查看设备状态,确保device空闲** - -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh arch=x86_64 -``` - -- **评测结果:** - -| 模型 | pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| ------------ | ----------------------- | ----------------------- | ---------- | ---------- | -| R(2+1)D-bs1 | [top1:0.8921 top5:0.9741](https://github.com/open-mmlab/mmaction2) | top1:0.8929 top5:0.9749 | 38.7704fps | 36.1684fps | -| R(2+1)D-bs16 | [top1:0.8921 top5:0.9742](https://github.com/open-mmlab/mmaction2) | top1:0.8929 top5:0.9749| 40.8914fps | 40.0332fps | +# R(2+1)D模型PyTorch离线推理指导 + +## 1 环境准备 + +- **1.1 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装** + +``` +pip3.7 install -r requirements.txt +``` + +- **1.2 获取,修改与安装开源模型代码** + +``` +git clone https://github.com/open-mmlab/mmcv -b master +cd mmcv +git reset --hard 6cb534b775b7502f0dcc59331236e619d3ae5b9f +MMCV_WITH_OPS=1 pip3.7 install -e . + +cd .. +git clone https://github.com/open-mmlab/mmaction2 -b master +cd mmaction2 +git reset --hard acce52d21a2545d9351b1060853c3bcd171b7158 +python3.7 setup.py develop + +``` +注:若上述命令不能下载源码,则将https替换为git(如:git clone git://github.com/open-mmlab/mmcv -b master ) + +将mmaction2/tools/deployment/目录下的pytorch2onnx.py中的torch.onnx.export添加一个参数: + +` dynamic_axes={'0':{0:'-1'}}, ` + +将r2plus1d_r34_8x8x1_180e_ucf101_rgb2.py文件放在mmaction2/configs/recognition/r2plus1d文件夹下 + +- **1.3 [获取权重文件](https://www.aliyundrive.com/drive/folder/6130e24c1b56461015b44659bdc650a9d3cd8e71)** + +- **1.4 [数据集UCF-101](https://www.crcv.ucf.edu/data/UCF101/UCF101.rar)** + +将UCF101.rar文件解压,重命名为ucf101,放在 /root/datasets/文件夹下 + +``` +在当前目录创建videos文件夹 +mkdir -p ./data/ucf101/videos + +将/root/datasets/ucf101文件夹下的视频文件夹复制到videos下 +cp -r /root/datasets/ucf101/* ./data/ucf101/videos + +python3.7 ./mmaction2/tools/data/build_rawframes.py ./data/ucf101/videos/ ./data/ucf101/rawframes/ --task rgb --level 2 --ext avi --use-opencv + +DATA_DIR_AN="./data/ucf101/annotations" + +wget https://www.crcv.ucf.edu/wp-content/uploads/2019/03/UCF101TrainTestSplits-RecognitionTask.zip --no-check-certificate + +unzip -j UCF101TrainTestSplits-RecognitionTask.zip -d ${DATA_DIR_AN}/ +rm UCF101TrainTestSplits-RecognitionTask.zip + +PYTHONPATH=. python3.7 ./mmaction2/tools/data/build_file_list.py ucf101 data/ucf101/rawframes/ --level 2 --format rawframes --shuffle +``` +- **1.5 获取[msame工具](https://gitee.com/ascend/tools/tree/master/msame)和[benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer)** + +将msame和benchmark.x86_64(或benchmark.aarch64)放到当前目录 + +## 2 离线推理 + +- **310上执行,执行时使npu-smi info查看设备状态,确保device空闲** + +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh arch=x86_64 +``` + +- **评测结果:** + +| 模型 | pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| ------------ | ----------------------- | ----------------------- | ---------- | ---------- | +| R(2+1)D-bs1 | [top1:0.8921 top5:0.9741](https://github.com/open-mmlab/mmaction2) | top1:0.8929 top5:0.9749 | 38.7704fps | 36.1684fps | +| R(2+1)D-bs16 | [top1:0.8921 top5:0.9742](https://github.com/open-mmlab/mmaction2) | top1:0.8929 top5:0.9749| 40.8914fps | 40.0332fps | diff --git a/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/get_info.py b/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/get_info.py index 5af675c6b0ae3f28a6f191d139ebb44e775e6c1c..fc6cdebb5b4417a3651c1e6e9663d8d1299a0ef5 100644 --- a/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/get_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/get_info.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/r2plus1d_r34_8x8x1_180e_ucf101_rgb2.py b/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/r2plus1d_r34_8x8x1_180e_ucf101_rgb2.py index 6da9ed4e07cd3ae0db8fb01d91a3d7bdb8ffe17f..58e521efcc7273e9ecb0adfae5a94a85a12426de 100644 --- a/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/r2plus1d_r34_8x8x1_180e_ucf101_rgb2.py +++ b/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/r2plus1d_r34_8x8x1_180e_ucf101_rgb2.py @@ -1,96 +1,96 @@ -_base_ = [ - '../../_base_/models/r2plus1d_r34.py', - '../../_base_/default_runtime.py' -] - -# dataset settings -dataset_type = 'RawframeDataset' -data_root = 'data/ucf101/rawframes/' -data_root_val = 'data/ucf101/rawframes/' -split = 1 # official train/test splits. valid numbers: 1, 2, 3 -ann_file_val = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' -ann_file_train = f'data/ucf101/ucf101_train_split_{split}_rawframes.txt' -ann_file_test = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' -img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) -train_pipeline = [ - dict(type='SampleFrames', clip_len=8, frame_interval=8, num_clips=1), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='RandomResizedCrop'), - dict(type='Resize', scale=(224, 224), keep_ratio=False), - dict(type='Flip', flip_ratio=0.5), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs', 'label']) -] -val_pipeline = [ - dict( - type='SampleFrames', - clip_len=8, - frame_interval=8, - num_clips=1, - test_mode=True), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='CenterCrop', crop_size=224), - dict(type='Flip', flip_ratio=0), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs']) -] -test_pipeline = [ - dict( - type='SampleFrames', - clip_len=8, - frame_interval=8, - num_clips=1, - test_mode=True), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='ThreeCrop', crop_size=256), - # dict(type='Flip', flip_ratio=0), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs']) -] -data = dict( - videos_per_gpu=16, - workers_per_gpu=4, - train=dict( - type=dataset_type, - ann_file=ann_file_train, - data_prefix=data_root, - pipeline=train_pipeline), - val=dict( - type=dataset_type, - ann_file=ann_file_val, - data_prefix=data_root_val, - pipeline=val_pipeline), - test=dict( - type=dataset_type, - ann_file=ann_file_val, - data_prefix=data_root_val, - pipeline=test_pipeline)) -# optimizer -optimizer = dict( - type='SGD', lr=0.0025, momentum=0.9, - weight_decay=0.0001) # this lr is used for 8 gpus -optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) -# learning policy -# lr_config = dict(policy='step', steps=[1,2,3], lrs=[1e-3,1e-4,1e-5]) -lr_config = dict(policy='CosineAnnealing', min_lr=0) -total_epochs = 40 -# total_epochs = 90 - -# runtime settings -checkpoint_config = dict(interval=5) -evaluation = dict( - interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) -work_dir = './work_dirs/r2plus1d_r34_8x8x1_180e_ucf101_rgb3/' -find_unused_parameters = False -load_from = 'https://download.openmmlab.com/mmaction/recognition/r2plus1d/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb_20200729-aa94765e.pth' -resume_from = None +_base_ = [ + '../../_base_/models/r2plus1d_r34.py', + '../../_base_/default_runtime.py' +] + +# dataset settings +dataset_type = 'RawframeDataset' +data_root = 'data/ucf101/rawframes/' +data_root_val = 'data/ucf101/rawframes/' +split = 1 # official train/test splits. valid numbers: 1, 2, 3 +ann_file_val = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' +ann_file_train = f'data/ucf101/ucf101_train_split_{split}_rawframes.txt' +ann_file_test = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) +train_pipeline = [ + dict(type='SampleFrames', clip_len=8, frame_interval=8, num_clips=1), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='RandomResizedCrop'), + dict(type='Resize', scale=(224, 224), keep_ratio=False), + dict(type='Flip', flip_ratio=0.5), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs', 'label']) +] +val_pipeline = [ + dict( + type='SampleFrames', + clip_len=8, + frame_interval=8, + num_clips=1, + test_mode=True), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='CenterCrop', crop_size=224), + dict(type='Flip', flip_ratio=0), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs']) +] +test_pipeline = [ + dict( + type='SampleFrames', + clip_len=8, + frame_interval=8, + num_clips=1, + test_mode=True), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='ThreeCrop', crop_size=256), + # dict(type='Flip', flip_ratio=0), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs']) +] +data = dict( + videos_per_gpu=16, + workers_per_gpu=4, + train=dict( + type=dataset_type, + ann_file=ann_file_train, + data_prefix=data_root, + pipeline=train_pipeline), + val=dict( + type=dataset_type, + ann_file=ann_file_val, + data_prefix=data_root_val, + pipeline=val_pipeline), + test=dict( + type=dataset_type, + ann_file=ann_file_val, + data_prefix=data_root_val, + pipeline=test_pipeline)) +# optimizer +optimizer = dict( + type='SGD', lr=0.0025, momentum=0.9, + weight_decay=0.0001) # this lr is used for 8 gpus +optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) +# learning policy +# lr_config = dict(policy='step', steps=[1,2,3], lrs=[1e-3,1e-4,1e-5]) +lr_config = dict(policy='CosineAnnealing', min_lr=0) +total_epochs = 40 +# total_epochs = 90 + +# runtime settings +checkpoint_config = dict(interval=5) +evaluation = dict( + interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) +work_dir = './work_dirs/r2plus1d_r34_8x8x1_180e_ucf101_rgb3/' +find_unused_parameters = False +load_from = 'https://download.openmmlab.com/mmaction/recognition/r2plus1d/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb_20200729-aa94765e.pth' +resume_from = None diff --git a/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/requirements.txt index 2b0bebd47b3f824727bf02c13b513f8d2abc92e6..6255de263372d9093f78840b7ec178d3375fc4b9 100644 --- a/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/R(2+1)D/requirements.txt @@ -1,9 +1,9 @@ -torch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.7.0 -onnx-simplifier == 0.3.6 -numpy == 1.21.1 -Pillow == 8.2.0 -opencv_python == 4.5.3.56 -scipy == 1.7.1 +torch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.7.0 +onnx-simplifier == 0.3.6 +numpy == 1.21.1 +Pillow == 8.2.0 +opencv_python == 4.5.3.56 +scipy == 1.7.1 einops ==0.3.2 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/ReID_for_Pytorch/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/ReID_for_Pytorch/modelzoo_level.txt index 9e95396651cc4382fe60ee1ee053674f527a448c..27e6c78b37535fe4f5a17029546fe257ad164d34 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ReID_for_Pytorch/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/ReID_for_Pytorch/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:POK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/RegNetX-1.6GF/LICENSE b/ACL_PyTorch/contrib/cv/classfication/RegNetX-1.6GF/LICENSE index 753842b6720f7980d411ecf2c78eb4ef220b9df8..f49a4e16e68b128803cc2dcea614603632b04eac 100644 --- a/ACL_PyTorch/contrib/cv/classfication/RegNetX-1.6GF/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/RegNetX-1.6GF/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/RegNetX-1.6GF/get_info.py b/ACL_PyTorch/contrib/cv/classfication/RegNetX-1.6GF/get_info.py index 16bebcfc75fa5903434d2fbcee780e2e7ac4bd84..70e007ac5c49dc1ddc85fcbeb33ba54018f56b06 100644 --- a/ACL_PyTorch/contrib/cv/classfication/RegNetX-1.6GF/get_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/RegNetX-1.6GF/get_info.py @@ -1,62 +1,62 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - print(index,'done') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - print(index,'done') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + print(index,'done') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + print(index,'done') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/RegNetX-1.6GF/vision_metric_ImageNet.py b/ACL_PyTorch/contrib/cv/classfication/RegNetX-1.6GF/vision_metric_ImageNet.py index 362f2484e8288dd3df6fa212678dc9449dbbed29..583340a19f2fc6e99faed85526c906f8bd12d7ba 100644 --- a/ACL_PyTorch/contrib/cv/classfication/RegNetX-1.6GF/vision_metric_ImageNet.py +++ b/ACL_PyTorch/contrib/cv/classfication/RegNetX-1.6GF/vision_metric_ImageNet.py @@ -1,184 +1,184 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - if data == '': - n_label = 0 - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - print("Time used:", elapsed) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) + diff --git a/ACL_PyTorch/contrib/cv/classfication/RegNetY-1.6GF/LICENSE b/ACL_PyTorch/contrib/cv/classfication/RegNetY-1.6GF/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/RegNetY-1.6GF/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/RegNetY-1.6GF/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/RegNetY-1.6GF/get_info.py b/ACL_PyTorch/contrib/cv/classfication/RegNetY-1.6GF/get_info.py index 16bebcfc75fa5903434d2fbcee780e2e7ac4bd84..70e007ac5c49dc1ddc85fcbeb33ba54018f56b06 100644 --- a/ACL_PyTorch/contrib/cv/classfication/RegNetY-1.6GF/get_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/RegNetY-1.6GF/get_info.py @@ -1,62 +1,62 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - print(index,'done') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - print(index,'done') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + print(index,'done') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + print(index,'done') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/RegNetY-1.6GF/vision_metric_ImageNet.py b/ACL_PyTorch/contrib/cv/classfication/RegNetY-1.6GF/vision_metric_ImageNet.py index 362f2484e8288dd3df6fa212678dc9449dbbed29..583340a19f2fc6e99faed85526c906f8bd12d7ba 100644 --- a/ACL_PyTorch/contrib/cv/classfication/RegNetY-1.6GF/vision_metric_ImageNet.py +++ b/ACL_PyTorch/contrib/cv/classfication/RegNetY-1.6GF/vision_metric_ImageNet.py @@ -1,184 +1,184 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - if data == '': - n_label = 0 - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - print("Time used:", elapsed) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) + diff --git a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/LICENSE b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/README.md b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/README.md index b7ed696a9143cf7790906d90f02f23ba5fe9765e..a35e5a7aeb75293b074f466252728b56c0235b8a 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/README.md @@ -1,246 +1,246 @@ -# Res2Net101_v1b Onnx模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) - - [6.2 开源TopN精度](#62-开源TopN精度) - - [6.3 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[Res2Net101_v1b论文](https://arxiv.org/pdf/1904.01169.pdf) - -### 1.2 代码地址 -[Res2Net101_v1b代码](https://github.com/Res2Net/Res2Net-PretrainedModels) -branch:master -commit_id:7ed111407a22723672eac575b300adc04e75e925 - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 -``` -CANN 5.0.1 - -torch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.9.0 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.19.2 -Pillow == 8.2.0 -opencv-python == 4.5.2.52 -``` - -**说明:** -> X86架构:pytorch和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 - -1.下载pth权重文件 -[Res2Net101_v1b预训练pth权重文件](https://shanghuagao.oss-cn-beijing.aliyuncs.com/res2net/res2net101_v1b_26w_4s-0812c246.pth) -``` -wget https://shanghuagao.oss-cn-beijing.aliyuncs.com/res2net/res2net101_v1b_26w_4s-0812c246.pth -``` -文件MD5sum:ebf7af4c138fcf25db859705907af833 - -2.Res2Net101_v1b模型代码获取方式如下 -``` -git clone https://github.com/Res2Net/Res2Net-PretrainedModels.git -``` -3.编写pth2onnx脚本res2net101_v1b_pth2onnx.py - - **说明:** ->注意目前ATC支持的onnx算子版本为11 - -4.执行pth2onnx脚本,生成onnx模型文件 -``` -python3.7 res2net101_v1b_pth2onnx.py res2net101_v1b_26w_4s-0812c246.pth res2net101_v1b.onnx -``` - - **模型转换要点:** ->此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 - -### 3.2 onnx转om模型 - -1.设置环境变量 -``` -source env.sh -``` -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) -``` -atc --framework=5 --model=./res2net101_v1b.onnx --output=res2net101_v1b_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 - -``` - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/opt/npu/imagenet/val与/opt/npu/imagenet/val_label.txt。 - -### 4.2 数据集预处理 -1.预处理脚本imagenet_torch_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 -``` -python3.7 imagenet_torch_preprocess.py res2net101 /opt/npu/imagenet/val ./prep_dataset -``` -### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本gen_dataset_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 -``` -python3.7 gen_dataset_info.py bin ./prep_dataset ./res2net101_v1b_prep_bin.info 224 224 -``` -第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) -### 5.2 离线推理 -1.设置环境变量 -``` -source env.sh -``` -2.执行离线推理 -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=res2net101_v1b_bs1.om -input_text_path=./res2net101_v1b_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False -``` -输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 - -## 6 精度对比 - -- **[离线推理TopN精度](#61-离线推理TopN精度)** -- **[开源TopN精度](#62-开源TopN精度)** -- **[精度对比](#63-精度对比)** - -### 6.1 离线推理TopN精度统计 - -后处理统计TopN精度 - -调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 -``` -python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /opt/npu/imagenet/val_label.txt ./ result.json -``` -第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 -查看输出结果: -``` -{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "81.22%"}, {"key": "Top2 accuracy", "value": "90.21%"}, {"key": "Top3 accuracy", "value": "93.1%"}, {"key": "Top4 accuracy", "value": "94.44%"}, {"key": "Top5 accuracy", "value": "95.36%"}]} -``` -经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 - -### 6.2 开源TopN精度 -[论文代码仓官方精度](https://mmcheng.net/res2net/) -``` -Model Acc@1 Acc@5 -Res2Net101_v1b 81.23 95.36 -``` -### 6.3 精度对比 -将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 - **精度调试:** ->没有遇到精度不达标的问题,故不需要进行精度调试 - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** - -### 7.1 npu性能数据 -1.benchmark工具在整个数据集上推理获得性能数据 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: -``` -[e2e] throughputRate: 55.9084, latency: 894320 -[data read] throughputRate: 59.1894, moduleLatency: 16.8949 -[preprocess] throughputRate: 59.0597, moduleLatency: 16.932 -[infer] throughputRate: 56.0004, Interface throughputRate: 62.9455, moduleLatency: 17.2581 -[post] throughputRate: 56.0004, moduleLatency: 17.857 -``` -Interface throughputRate: 62.9455,62.9455x4=251.782既是batch1 310单卡吞吐率 -batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: -``` -[e2e] throughputRate: 71.4937, latency: 699363 -[data read] throughputRate: 75.8049, moduleLatency: 13.1918 -[preprocess] throughputRate: 75.5936, moduleLatency: 13.2286 -[infer] throughputRate: 71.6788, Interface throughputRate: 86.1957, moduleLatency: 13.0185 -[post] throughputRate: 4.47989, moduleLatency: 223.22 -``` -Interface throughputRate: 86.1957,86.1957x4=344.7828既是batch16 310单卡吞吐率 -batch4性能: -``` -[e2e] throughputRate: 64.92, latency: 770179 -[data read] throughputRate: 68.6591, moduleLatency: 14.5647 -[preprocess] throughputRate: 68.5431, moduleLatency: 14.5894 -[infer] throughputRate: 65.0303, Interface throughputRate: 78.2596, moduleLatency: 14.2895 -[post] throughputRate: 16.2575, moduleLatency: 61.51 -``` -batch4 310单卡吞吐率:78.2596x4=313.0384fps -batch8性能: -``` -[e2e] throughputRate: 69.3296, latency: 721193 -[data read] throughputRate: 73.486, moduleLatency: 13.608 -[preprocess] throughputRate: 73.2601, moduleLatency: 13.65 -[infer] throughputRate: 69.5028, Interface throughputRate: 82.7469, moduleLatency: 13.5299 -[post] throughputRate: 8.68781, moduleLatency: 115.104 -``` -batch8 310单卡吞吐率:82.7469x4=330.9876fps -batch32性能: -``` -[e2e] throughputRate: 70.3878, latency: 710350 -[data read] throughputRate: 74.4979, moduleLatency: 13.4232 -[preprocess] throughputRate: 74.3318, moduleLatency: 13.4532 -[infer] throughputRate: 70.5551, Interface throughputRate: 86.8456, moduleLatency: 12.9157 -[post] throughputRate: 2.20553, moduleLatency: 453.405 -``` -batch32 310单卡吞吐率:86.8456x4=347.3824fps - - **性能优化:** -从profiling性能数据op_statistic_0_1.csv看出,耗时最多的算子主要是TransData,Conv2D与ConcatD,而Conv2D算子不存在性能问题。 -由于格式转换om模型Conv2D前后需要有TransData算子,从op_summary_0_1.csv看出,单个TransData算子aicore耗时不大。 +# Res2Net101_v1b Onnx模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) + - [6.2 开源TopN精度](#62-开源TopN精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[Res2Net101_v1b论文](https://arxiv.org/pdf/1904.01169.pdf) + +### 1.2 代码地址 +[Res2Net101_v1b代码](https://github.com/Res2Net/Res2Net-PretrainedModels) +branch:master +commit_id:7ed111407a22723672eac575b300adc04e75e925 + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +CANN 5.0.1 + +torch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.9.0 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.19.2 +Pillow == 8.2.0 +opencv-python == 4.5.2.52 +``` + +**说明:** +> X86架构:pytorch和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 + +1.下载pth权重文件 +[Res2Net101_v1b预训练pth权重文件](https://shanghuagao.oss-cn-beijing.aliyuncs.com/res2net/res2net101_v1b_26w_4s-0812c246.pth) +``` +wget https://shanghuagao.oss-cn-beijing.aliyuncs.com/res2net/res2net101_v1b_26w_4s-0812c246.pth +``` +文件MD5sum:ebf7af4c138fcf25db859705907af833 + +2.Res2Net101_v1b模型代码获取方式如下 +``` +git clone https://github.com/Res2Net/Res2Net-PretrainedModels.git +``` +3.编写pth2onnx脚本res2net101_v1b_pth2onnx.py + + **说明:** +>注意目前ATC支持的onnx算子版本为11 + +4.执行pth2onnx脚本,生成onnx模型文件 +``` +python3.7 res2net101_v1b_pth2onnx.py res2net101_v1b_26w_4s-0812c246.pth res2net101_v1b.onnx +``` + + **模型转换要点:** +>此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 + +### 3.2 onnx转om模型 + +1.设置环境变量 +``` +source env.sh +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) +``` +atc --framework=5 --model=./res2net101_v1b.onnx --output=res2net101_v1b_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 + +``` + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/opt/npu/imagenet/val与/opt/npu/imagenet/val_label.txt。 + +### 4.2 数据集预处理 +1.预处理脚本imagenet_torch_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 +``` +python3.7 imagenet_torch_preprocess.py res2net101 /opt/npu/imagenet/val ./prep_dataset +``` +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本gen_dataset_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 +``` +python3.7 gen_dataset_info.py bin ./prep_dataset ./res2net101_v1b_prep_bin.info 224 224 +``` +第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) +### 5.2 离线推理 +1.设置环境变量 +``` +source env.sh +``` +2.执行离线推理 +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=res2net101_v1b_bs1.om -input_text_path=./res2net101_v1b_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +``` +输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 + +## 6 精度对比 + +- **[离线推理TopN精度](#61-离线推理TopN精度)** +- **[开源TopN精度](#62-开源TopN精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理TopN精度统计 + +后处理统计TopN精度 + +调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 +``` +python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /opt/npu/imagenet/val_label.txt ./ result.json +``` +第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 +查看输出结果: +``` +{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "81.22%"}, {"key": "Top2 accuracy", "value": "90.21%"}, {"key": "Top3 accuracy", "value": "93.1%"}, {"key": "Top4 accuracy", "value": "94.44%"}, {"key": "Top5 accuracy", "value": "95.36%"}]} +``` +经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 + +### 6.2 开源TopN精度 +[论文代码仓官方精度](https://mmcheng.net/res2net/) +``` +Model Acc@1 Acc@5 +Res2Net101_v1b 81.23 95.36 +``` +### 6.3 精度对比 +将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + **精度调试:** +>没有遇到精度不达标的问题,故不需要进行精度调试 + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** + +### 7.1 npu性能数据 +1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: +``` +[e2e] throughputRate: 55.9084, latency: 894320 +[data read] throughputRate: 59.1894, moduleLatency: 16.8949 +[preprocess] throughputRate: 59.0597, moduleLatency: 16.932 +[infer] throughputRate: 56.0004, Interface throughputRate: 62.9455, moduleLatency: 17.2581 +[post] throughputRate: 56.0004, moduleLatency: 17.857 +``` +Interface throughputRate: 62.9455,62.9455x4=251.782既是batch1 310单卡吞吐率 +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: +``` +[e2e] throughputRate: 71.4937, latency: 699363 +[data read] throughputRate: 75.8049, moduleLatency: 13.1918 +[preprocess] throughputRate: 75.5936, moduleLatency: 13.2286 +[infer] throughputRate: 71.6788, Interface throughputRate: 86.1957, moduleLatency: 13.0185 +[post] throughputRate: 4.47989, moduleLatency: 223.22 +``` +Interface throughputRate: 86.1957,86.1957x4=344.7828既是batch16 310单卡吞吐率 +batch4性能: +``` +[e2e] throughputRate: 64.92, latency: 770179 +[data read] throughputRate: 68.6591, moduleLatency: 14.5647 +[preprocess] throughputRate: 68.5431, moduleLatency: 14.5894 +[infer] throughputRate: 65.0303, Interface throughputRate: 78.2596, moduleLatency: 14.2895 +[post] throughputRate: 16.2575, moduleLatency: 61.51 +``` +batch4 310单卡吞吐率:78.2596x4=313.0384fps +batch8性能: +``` +[e2e] throughputRate: 69.3296, latency: 721193 +[data read] throughputRate: 73.486, moduleLatency: 13.608 +[preprocess] throughputRate: 73.2601, moduleLatency: 13.65 +[infer] throughputRate: 69.5028, Interface throughputRate: 82.7469, moduleLatency: 13.5299 +[post] throughputRate: 8.68781, moduleLatency: 115.104 +``` +batch8 310单卡吞吐率:82.7469x4=330.9876fps +batch32性能: +``` +[e2e] throughputRate: 70.3878, latency: 710350 +[data read] throughputRate: 74.4979, moduleLatency: 13.4232 +[preprocess] throughputRate: 74.3318, moduleLatency: 13.4532 +[infer] throughputRate: 70.5551, Interface throughputRate: 86.8456, moduleLatency: 12.9157 +[post] throughputRate: 2.20553, moduleLatency: 453.405 +``` +batch32 310单卡吞吐率:86.8456x4=347.3824fps + + **性能优化:** +从profiling性能数据op_statistic_0_1.csv看出,耗时最多的算子主要是TransData,Conv2D与ConcatD,而Conv2D算子不存在性能问题。 +由于格式转换om模型Conv2D前后需要有TransData算子,从op_summary_0_1.csv看出,单个TransData算子aicore耗时不大。 如果优化就需要优化掉过多的TransData算子。 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/gen_dataset_info.py index 61450b4410663ae5e66ec29ed296ff6584203e31..5381839f653a885666e3fc456db9a1c22b8583a1 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/gen_dataset_info.py @@ -1,61 +1,61 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) + diff --git a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/imagenet_acc_eval.py b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/imagenet_acc_eval.py index 362f2484e8288dd3df6fa212678dc9449dbbed29..583340a19f2fc6e99faed85526c906f8bd12d7ba 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/imagenet_acc_eval.py +++ b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/imagenet_acc_eval.py @@ -1,184 +1,184 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - if data == '': - n_label = 0 - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - print("Time used:", elapsed) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) + diff --git a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/imagenet_torch_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/imagenet_torch_preprocess.py index 987f8cc776c874f60d629172b52625b22d5a39fc..999675ae55f6b71b54f7384d954bebd818dafd3c 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/imagenet_torch_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/imagenet_torch_preprocess.py @@ -1,117 +1,117 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from PIL import Image -import numpy as np -import multiprocessing - - -model_config = { - 'res2net101': { - 'resize': 256, - 'centercrop': 224, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv3': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv4': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.5, 0.5, 0.5], - 'std': [0.5, 0.5, 0.5], - }, -} - - -def center_crop(img, output_size): - if isinstance(output_size, int): - output_size = (int(output_size), int(output_size)) - image_width, image_height = img.size - crop_height, crop_width = output_size - crop_top = int(round((image_height - crop_height) / 2.)) - crop_left = int(round((image_width - crop_width) / 2.)) - return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) - - -def resize(img, size, interpolation=Image.BILINEAR): - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def gen_input_bin(mode_type, file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - # RGBA to RGB - image = Image.open(os.path.join(src_path, file)).convert('RGB') - image = resize(image, model_config[mode_type]['resize']) # Resize - image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop - img = np.array(image, dtype=np.float32) - img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW - img = img / 255. # ToTensor: div 255 - img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean - img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - - -def preprocess(mode_type, src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") - mode_type = sys.argv[1] - src_path = sys.argv[2] - save_path = sys.argv[3] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - if mode_type not in model_config: - model_type_help = "model type: " - for key in model_config.keys(): - model_type_help += key - model_type_help += ' ' - raise Exception(model_type_help) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - preprocess(mode_type, src_path, save_path) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from PIL import Image +import numpy as np +import multiprocessing + + +model_config = { + 'res2net101': { + 'resize': 256, + 'centercrop': 224, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv3': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv4': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.5, 0.5, 0.5], + 'std': [0.5, 0.5, 0.5], + }, +} + + +def center_crop(img, output_size): + if isinstance(output_size, int): + output_size = (int(output_size), int(output_size)) + image_width, image_height = img.size + crop_height, crop_width = output_size + crop_top = int(round((image_height - crop_height) / 2.)) + crop_left = int(round((image_width - crop_width) / 2.)) + return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) + + +def resize(img, size, interpolation=Image.BILINEAR): + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def gen_input_bin(mode_type, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + # RGBA to RGB + image = Image.open(os.path.join(src_path, file)).convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.float32) + img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW + img = img / 255. # ToTensor: div 255 + img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean + img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +def preprocess(mode_type, src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") + mode_type = sys.argv[1] + src_path = sys.argv[2] + save_path = sys.argv[3] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if mode_type not in model_config: + model_type_help = "model type: " + for key in model_config.keys(): + model_type_help += key + model_type_help += ' ' + raise Exception(model_type_help) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess(mode_type, src_path, save_path) + diff --git a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/requirements.txt index bebc253c759bfdba913bc30de29b6a2de399ccaf..8bccb088d46196b08cfb04ff1c797c95df536a6f 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.9.0 -numpy == 1.19.2 -Pillow == 8.2.0 +torch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.9.0 +numpy == 1.19.2 +Pillow == 8.2.0 opencv-python == 4.5.2.52 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/res2net101_v1b_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/res2net101_v1b_pth2onnx.py index 6d2f9c925a19b619c54c5aed48ced6690a0bb48a..87d0ed15f37344bbf9e7f849e21cf03ca70b82b8 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/res2net101_v1b_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/res2net101_v1b_pth2onnx.py @@ -1,36 +1,36 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import torch -import torch.onnx -sys.path.append(r"./Res2Net-PretrainedModels") -from res2net_v1b import res2net101_v1b - -def pth2onnx(input_file, output_file): - model = res2net101_v1b(pretrained=False) - checkpoint = torch.load(input_file, map_location=torch.device('cpu')) - model.load_state_dict(checkpoint) - - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) - -if __name__ == "__main__": - input_file = sys.argv[1] - output_file = sys.argv[2] - pth2onnx(input_file, output_file) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import torch +import torch.onnx +sys.path.append(r"./Res2Net-PretrainedModels") +from res2net_v1b import res2net101_v1b + +def pth2onnx(input_file, output_file): + model = res2net101_v1b(pretrained=False) + checkpoint = torch.load(input_file, map_location=torch.device('cpu')) + model.load_state_dict(checkpoint) + + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) + +if __name__ == "__main__": + input_file = sys.argv[1] + output_file = sys.argv[2] + pth2onnx(input_file, output_file) diff --git a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/test/README.md b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/test/README.md index 7e5f518ae25b2f972581ef84e2224ec1730c9a1e..027331b15d770f7ab84202a23f584142c7b1f8ca 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/test/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b/test/README.md @@ -1,24 +1,24 @@ -环境准备: - -1.数据集路径 -数据集统一放在/root/datasets/或/opt/npu/ -本模型数据集放在/opt/npu/imagenet - -2.进入工作目录 -cd Res2Net101_v1b - -3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -pip3.7 install -r requirements.txt - -4.获取模型代码 -git clone https://github.com/Res2Net/Res2Net-PretrainedModels.git - -5.获取权重文件 -wget https://shanghuagao.oss-cn-beijing.aliyuncs.com/res2net/res2net101_v1b_26w_4s-0812c246.pth - -6.获取benchmark工具 -将benchmark.x86_64放在当前目录 - -7.310上执行,执行时确保device空闲 -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/opt/npu/imagenet +环境准备: + +1.数据集路径 +数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集放在/opt/npu/imagenet + +2.进入工作目录 +cd Res2Net101_v1b + +3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +pip3.7 install -r requirements.txt + +4.获取模型代码 +git clone https://github.com/Res2Net/Res2Net-PretrainedModels.git + +5.获取权重文件 +wget https://shanghuagao.oss-cn-beijing.aliyuncs.com/res2net/res2net101_v1b_26w_4s-0812c246.pth + +6.获取benchmark工具 +将benchmark.x86_64放在当前目录 + +7.310上执行,执行时确保device空闲 +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/opt/npu/imagenet diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet101/LICENSE b/ACL_PyTorch/contrib/cv/classfication/ResNet101/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet101/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet101/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet101/README.md b/ACL_PyTorch/contrib/cv/classfication/ResNet101/README.md index 864fb944d595b7f4aeee2a2628270a24eb0a2e67..644b8a73255013bdb5ab124ebdc515687cb1f19e 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet101/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet101/README.md @@ -1,250 +1,250 @@ -# ResNet101 Onnx模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) - - [6.2 开源TopN精度](#62-开源TopN精度) - - [6.3 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[ResNet101论文](https://arxiv.org/pdf/1512.03385.pdf) - -### 1.2 代码地址 -[ResNet101代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) -branch:master -commit_id:7d955df73fe0e9b47f7d6c77c699324b256fc41f - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 -``` -CANN 5.0.1 - -torch == 1.5.1 -torchvision == 0.6.1 -onnx == 1.9.0 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.19.2 -Pillow == 8.2.0 -opencv-python == 4.5.2 -``` - -**说明:** -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 - -1.下载pth权重文件 -[ResNet-101预训练pth权重文件](https://download.pytorch.org/models/resnet101-63fe2227.pth) -``` -wget https://download.pytorch.org/models/resnet101-63fe2227.pth -``` -文件MD5sum:b258f8e54abb7de9c960ff19cc662d76 - -2.ResNet101模型代码在torchvision里,安装torchvision,arm下需源码安装,参考torchvision官网,若安装过程报错请百度解决 -``` -git clone https://github.com/pytorch/vision -cd vision -python3.7 setup.py install -cd .. -``` -3.编写pth2onnx脚本resnet101_pth2onnx.py - - **说明:** ->注意目前ATC支持的onnx算子版本为11 - -4.执行pth2onnx脚本,生成onnx模型文件 -``` -python3.7 resnet101_pth2onnx.py ./resnet101-63fe2227.pth resnet101.onnx -``` - - **模型转换要点:** ->此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 - -### 3.2 onnx转om模型 - -1.设置环境变量 -``` -source env.sh -``` -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) -``` -atc --framework=5 --model=./resnet101.onnx --output=resnet101_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 - -``` - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 - -### 4.2 数据集预处理 -1.预处理脚本imagenet_torch_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 -``` -python3.7 imagenet_torch_preprocess.py resnet /root/datasets/imagenet/val ./prep_dataset -``` -### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本gen_dataset_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 -``` -python3.7 gen_dataset_info.py bin ./prep_dataset ./resnet101_prep_bin.info 224 224 -``` -第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) -### 5.2 离线推理 -1.设置环境变量 -``` -source env.sh -``` -2.执行离线推理 -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=resnet101_bs1.om -input_text_path=./resnet101_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False -``` -输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 - -## 6 精度对比 - -- **[离线推理TopN精度](#61-离线推理TopN精度)** -- **[开源TopN精度](#62-开源TopN精度)** -- **[精度对比](#63-精度对比)** - -### 6.1 离线推理TopN精度统计 - -后处理统计TopN精度 - -调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 -``` -python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /root/datasets/imagenet/val_label.txt ./ result.json -``` -第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 -查看输出结果: -``` -{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "77.37%"}, {"key": "Top2 accuracy", "value": "87.1%"}, {"key": "Top3 accuracy", "value": "90.61%"}, {"key": "Top4 accuracy", "value": "92.42%"}, {"key": "Top5 accuracy", "value": "93.54%"}]} -``` -经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 - -### 6.2 开源TopN精度 -[torchvision官网精度](https://pytorch.org/vision/stable/models.html) -``` -Model Acc@1 Acc@5 -ResNet-101 77.374 93.546 -``` -### 6.3 精度对比 -将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 - **精度调试:** ->没有遇到精度不达标的问题,故不需要进行精度调试 - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** - -### 7.1 npu性能数据 -benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 -1.benchmark工具在整个数据集上推理获得性能数据 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: -``` -[e2e] throughputRate: 170.628, latency: 293035 -[data read] throughputRate: 181.571, moduleLatency: 5.50749 -[preprocess] throughputRate: 180.466, moduleLatency: 5.5412 -[infer] throughputRate: 171.595, Interface throughputRate: 247.898, moduleLatency: 5.12562 -[post] throughputRate: 171.595, moduleLatency: 5.82768 -``` -Interface throughputRate: 247.898,247.898x4=991.592既是batch1 310单卡吞吐率 -batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: -``` -[e2e] throughputRate: 185.903, latency: 268957 -[data read] throughputRate: 191.266, moduleLatency: 5.22833 -[preprocess] throughputRate: 190.761, moduleLatency: 5.24217 -[infer] throughputRate: 187.131, Interface throughputRate: 401.046, moduleLatency: 3.94051 -[post] throughputRate: 11.6954, moduleLatency: 85.5035 -``` -Interface throughputRate: 401.046,401.046x4=1604.184既是batch16 310单卡吞吐率 -batch4的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_4_device_0.txt: -``` -[e2e] throughputRate: 184.444, latency: 271085 -[data read] throughputRate: 196.412, moduleLatency: 5.09134 -[preprocess] throughputRate: 195.837, moduleLatency: 5.1063 -[infer] throughputRate: 185.624, Interface throughputRate: 331.096, moduleLatency: 4.52436 -[post] throughputRate: 46.4056, moduleLatency: 21.5491 -``` -Interface throughputRate: 331.096,331.096x4=1324.384既是batch4 310单卡吞吐率 -batch8的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_8_device_0.txt: -``` -[e2e] throughputRate: 196.051, latency: 255036 -[data read] throughputRate: 209.29, moduleLatency: 4.77806 -[preprocess] throughputRate: 207.914, moduleLatency: 4.80969 -[infer] throughputRate: 197.513, Interface throughputRate: 371.905, moduleLatency: 4.15513 -[post] throughputRate: 24.6888, moduleLatency: 40.5042 -``` -Interface throughputRate: 371.905,371.905x4=1487.62既是batch8 310单卡吞吐率 -batch32的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_32_device_0.txt: -``` -[e2e] throughputRate: 176.215, latency: 283744 -[data read] throughputRate: 187.024, moduleLatency: 5.34691 -[preprocess] throughputRate: 186.183, moduleLatency: 5.37105 -[infer] throughputRate: 177.675, Interface throughputRate: 370.456, moduleLatency: 4.14361 -[post] throughputRate: 5.55402, moduleLatency: 180.05 - -``` -Interface throughputRate: 370.456,370.456x4=1481.82既是batch32 310单卡吞吐率 - - **性能优化:** ->没有遇到性能不达标的问题,故不需要进行性能优化 - +# ResNet101 Onnx模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) + - [6.2 开源TopN精度](#62-开源TopN精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[ResNet101论文](https://arxiv.org/pdf/1512.03385.pdf) + +### 1.2 代码地址 +[ResNet101代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) +branch:master +commit_id:7d955df73fe0e9b47f7d6c77c699324b256fc41f + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +CANN 5.0.1 + +torch == 1.5.1 +torchvision == 0.6.1 +onnx == 1.9.0 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.19.2 +Pillow == 8.2.0 +opencv-python == 4.5.2 +``` + +**说明:** +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 + +1.下载pth权重文件 +[ResNet-101预训练pth权重文件](https://download.pytorch.org/models/resnet101-63fe2227.pth) +``` +wget https://download.pytorch.org/models/resnet101-63fe2227.pth +``` +文件MD5sum:b258f8e54abb7de9c960ff19cc662d76 + +2.ResNet101模型代码在torchvision里,安装torchvision,arm下需源码安装,参考torchvision官网,若安装过程报错请百度解决 +``` +git clone https://github.com/pytorch/vision +cd vision +python3.7 setup.py install +cd .. +``` +3.编写pth2onnx脚本resnet101_pth2onnx.py + + **说明:** +>注意目前ATC支持的onnx算子版本为11 + +4.执行pth2onnx脚本,生成onnx模型文件 +``` +python3.7 resnet101_pth2onnx.py ./resnet101-63fe2227.pth resnet101.onnx +``` + + **模型转换要点:** +>此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 + +### 3.2 onnx转om模型 + +1.设置环境变量 +``` +source env.sh +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) +``` +atc --framework=5 --model=./resnet101.onnx --output=resnet101_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 + +``` + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 + +### 4.2 数据集预处理 +1.预处理脚本imagenet_torch_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 +``` +python3.7 imagenet_torch_preprocess.py resnet /root/datasets/imagenet/val ./prep_dataset +``` +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本gen_dataset_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 +``` +python3.7 gen_dataset_info.py bin ./prep_dataset ./resnet101_prep_bin.info 224 224 +``` +第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) +### 5.2 离线推理 +1.设置环境变量 +``` +source env.sh +``` +2.执行离线推理 +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=resnet101_bs1.om -input_text_path=./resnet101_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +``` +输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 + +## 6 精度对比 + +- **[离线推理TopN精度](#61-离线推理TopN精度)** +- **[开源TopN精度](#62-开源TopN精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理TopN精度统计 + +后处理统计TopN精度 + +调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 +``` +python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /root/datasets/imagenet/val_label.txt ./ result.json +``` +第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 +查看输出结果: +``` +{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "77.37%"}, {"key": "Top2 accuracy", "value": "87.1%"}, {"key": "Top3 accuracy", "value": "90.61%"}, {"key": "Top4 accuracy", "value": "92.42%"}, {"key": "Top5 accuracy", "value": "93.54%"}]} +``` +经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 + +### 6.2 开源TopN精度 +[torchvision官网精度](https://pytorch.org/vision/stable/models.html) +``` +Model Acc@1 Acc@5 +ResNet-101 77.374 93.546 +``` +### 6.3 精度对比 +将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + **精度调试:** +>没有遇到精度不达标的问题,故不需要进行精度调试 + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** + +### 7.1 npu性能数据 +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 +1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: +``` +[e2e] throughputRate: 170.628, latency: 293035 +[data read] throughputRate: 181.571, moduleLatency: 5.50749 +[preprocess] throughputRate: 180.466, moduleLatency: 5.5412 +[infer] throughputRate: 171.595, Interface throughputRate: 247.898, moduleLatency: 5.12562 +[post] throughputRate: 171.595, moduleLatency: 5.82768 +``` +Interface throughputRate: 247.898,247.898x4=991.592既是batch1 310单卡吞吐率 +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: +``` +[e2e] throughputRate: 185.903, latency: 268957 +[data read] throughputRate: 191.266, moduleLatency: 5.22833 +[preprocess] throughputRate: 190.761, moduleLatency: 5.24217 +[infer] throughputRate: 187.131, Interface throughputRate: 401.046, moduleLatency: 3.94051 +[post] throughputRate: 11.6954, moduleLatency: 85.5035 +``` +Interface throughputRate: 401.046,401.046x4=1604.184既是batch16 310单卡吞吐率 +batch4的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_4_device_0.txt: +``` +[e2e] throughputRate: 184.444, latency: 271085 +[data read] throughputRate: 196.412, moduleLatency: 5.09134 +[preprocess] throughputRate: 195.837, moduleLatency: 5.1063 +[infer] throughputRate: 185.624, Interface throughputRate: 331.096, moduleLatency: 4.52436 +[post] throughputRate: 46.4056, moduleLatency: 21.5491 +``` +Interface throughputRate: 331.096,331.096x4=1324.384既是batch4 310单卡吞吐率 +batch8的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_8_device_0.txt: +``` +[e2e] throughputRate: 196.051, latency: 255036 +[data read] throughputRate: 209.29, moduleLatency: 4.77806 +[preprocess] throughputRate: 207.914, moduleLatency: 4.80969 +[infer] throughputRate: 197.513, Interface throughputRate: 371.905, moduleLatency: 4.15513 +[post] throughputRate: 24.6888, moduleLatency: 40.5042 +``` +Interface throughputRate: 371.905,371.905x4=1487.62既是batch8 310单卡吞吐率 +batch32的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_32_device_0.txt: +``` +[e2e] throughputRate: 176.215, latency: 283744 +[data read] throughputRate: 187.024, moduleLatency: 5.34691 +[preprocess] throughputRate: 186.183, moduleLatency: 5.37105 +[infer] throughputRate: 177.675, Interface throughputRate: 370.456, moduleLatency: 4.14361 +[post] throughputRate: 5.55402, moduleLatency: 180.05 + +``` +Interface throughputRate: 370.456,370.456x4=1481.82既是batch32 310单卡吞吐率 + + **性能优化:** +>没有遇到性能不达标的问题,故不需要进行性能优化 + diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet101/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/classfication/ResNet101/gen_dataset_info.py index 61450b4410663ae5e66ec29ed296ff6584203e31..5381839f653a885666e3fc456db9a1c22b8583a1 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet101/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet101/gen_dataset_info.py @@ -1,61 +1,61 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) + diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet101/imagenet_acc_eval.py b/ACL_PyTorch/contrib/cv/classfication/ResNet101/imagenet_acc_eval.py index 362f2484e8288dd3df6fa212678dc9449dbbed29..583340a19f2fc6e99faed85526c906f8bd12d7ba 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet101/imagenet_acc_eval.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet101/imagenet_acc_eval.py @@ -1,184 +1,184 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - if data == '': - n_label = 0 - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - print("Time used:", elapsed) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) + diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet101/imagenet_torch_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/ResNet101/imagenet_torch_preprocess.py index 1ab60b54dd7fd5b59ca733666c1dc63e07c980c1..a99dd271d0df5f9b21aa9c7da3fe7edb491a27e6 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet101/imagenet_torch_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet101/imagenet_torch_preprocess.py @@ -1,117 +1,117 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from PIL import Image -import numpy as np -import multiprocessing - - -model_config = { - 'resnet': { - 'resize': 256, - 'centercrop': 224, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv3': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv4': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.5, 0.5, 0.5], - 'std': [0.5, 0.5, 0.5], - }, -} - - -def center_crop(img, output_size): - if isinstance(output_size, int): - output_size = (int(output_size), int(output_size)) - image_width, image_height = img.size - crop_height, crop_width = output_size - crop_top = int(round((image_height - crop_height) / 2.)) - crop_left = int(round((image_width - crop_width) / 2.)) - return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) - - -def resize(img, size, interpolation=Image.BILINEAR): - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def gen_input_bin(mode_type, file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - # RGBA to RGB - image = Image.open(os.path.join(src_path, file)).convert('RGB') - image = resize(image, model_config[mode_type]['resize']) # Resize - image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop - img = np.array(image, dtype=np.float32) - img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW - img = img / 255. # ToTensor: div 255 - img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean - img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - - -def preprocess(mode_type, src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") - mode_type = sys.argv[1] - src_path = sys.argv[2] - save_path = sys.argv[3] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - if mode_type not in model_config: - model_type_help = "model type: " - for key in model_config.keys(): - model_type_help += key - model_type_help += ' ' - raise Exception(model_type_help) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - preprocess(mode_type, src_path, save_path) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from PIL import Image +import numpy as np +import multiprocessing + + +model_config = { + 'resnet': { + 'resize': 256, + 'centercrop': 224, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv3': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv4': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.5, 0.5, 0.5], + 'std': [0.5, 0.5, 0.5], + }, +} + + +def center_crop(img, output_size): + if isinstance(output_size, int): + output_size = (int(output_size), int(output_size)) + image_width, image_height = img.size + crop_height, crop_width = output_size + crop_top = int(round((image_height - crop_height) / 2.)) + crop_left = int(round((image_width - crop_width) / 2.)) + return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) + + +def resize(img, size, interpolation=Image.BILINEAR): + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def gen_input_bin(mode_type, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + # RGBA to RGB + image = Image.open(os.path.join(src_path, file)).convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.float32) + img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW + img = img / 255. # ToTensor: div 255 + img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean + img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +def preprocess(mode_type, src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") + mode_type = sys.argv[1] + src_path = sys.argv[2] + save_path = sys.argv[3] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if mode_type not in model_config: + model_type_help = "model type: " + for key in model_config.keys(): + model_type_help += key + model_type_help += ' ' + raise Exception(model_type_help) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess(mode_type, src_path, save_path) + diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet101/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/ResNet101/requirements.txt index 2fc4e802c476feda2a9866a85630f7f3b29428d7..d072d9aa6f2e7a7b0044ff93d036c3c0347ee5c9 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet101/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet101/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.5.1 -torchvision == 0.6.1 -onnx == 1.9.0 -numpy == 1.19.2 -Pillow == 8.2.0 +torch == 1.5.1 +torchvision == 0.6.1 +onnx == 1.9.0 +numpy == 1.19.2 +Pillow == 8.2.0 opencv-python == 4.5.2 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet101/resnet101_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/ResNet101/resnet101_pth2onnx.py index 46ab195411a21bf39c1d67d864a72ef0e7f9310f..8eff59a68086db8153e345f4956f018710ffaf7c 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet101/resnet101_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet101/resnet101_pth2onnx.py @@ -1,35 +1,35 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import torch -import torch.onnx -import torchvision.models as models - -def pth2onnx(input_file, output_file): - model = models.resnet101(pretrained=False) - checkpoint = torch.load(input_file, map_location=None) - model.load_state_dict(checkpoint) - - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) - -if __name__ == "__main__": - input_file = sys.argv[1] - output_file = sys.argv[2] - pth2onnx(input_file, output_file) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import torch +import torch.onnx +import torchvision.models as models + +def pth2onnx(input_file, output_file): + model = models.resnet101(pretrained=False) + checkpoint = torch.load(input_file, map_location=None) + model.load_state_dict(checkpoint) + + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) + +if __name__ == "__main__": + input_file = sys.argv[1] + output_file = sys.argv[2] + pth2onnx(input_file, output_file) diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet101/test/README.md b/ACL_PyTorch/contrib/cv/classfication/ResNet101/test/README.md index 1c1ba3c42f85af564f8149e303ceb33763593939..d7ffd9773a50e6d2f86f52b2145e94f64b42012f 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet101/test/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet101/test/README.md @@ -1,29 +1,29 @@ -环境准备: - -1.数据集路径 -数据集统一放在/root/datasets/或/opt/npu/ -本模型数据集放在/root/datasets/ - -2.进入工作目录 -cd ResNet101 - -3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -pip3.7 install -r requirements.txt - -4.获取模型代码 -git clone https://github.com/pytorch/vision - -5.如果模型代码需要安装,则安装模型代码 -cd vision -python3.7 setup.py install -cd .. - -6.获取权重文件 -wget https://download.pytorch.org/models/resnet101-63fe2227.pth - -7.获取benchmark工具 -将benchmark.x86_64放在当前目录 - -8.310上执行,执行时确保device空闲 -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets +环境准备: + +1.数据集路径 +数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集放在/root/datasets/ + +2.进入工作目录 +cd ResNet101 + +3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +pip3.7 install -r requirements.txt + +4.获取模型代码 +git clone https://github.com/pytorch/vision + +5.如果模型代码需要安装,则安装模型代码 +cd vision +python3.7 setup.py install +cd .. + +6.获取权重文件 +wget https://download.pytorch.org/models/resnet101-63fe2227.pth + +7.获取benchmark工具 +将benchmark.x86_64放在当前目录 + +8.310上执行,执行时确保device空闲 +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet101/test/parse.py b/ACL_PyTorch/contrib/cv/classfication/ResNet101/test/parse.py index a0f253b055047b199b33d4b65cdc79177b6b250b..27eae0d0acf98687edd95f1f024cf77c49cd4dc4 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet101/test/parse.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet101/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet18/LICENSE b/ACL_PyTorch/contrib/cv/classfication/ResNet18/LICENSE index 657549b86065a3d34c7dd038edee91cedb8cb05a..dcc65541a1b5f985560b92c275b8328469d50742 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet18/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet18/LICENSE @@ -1,30 +1,30 @@ -BSD 3-Clause License - -Copyright (c) 2017, -All rights reserved. -Copyright 2020 Huawei Technologies Co., Ltd - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +BSD 3-Clause License + +Copyright (c) 2017, +All rights reserved. +Copyright 2020 Huawei Technologies Co., Ltd + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet18/README.md b/ACL_PyTorch/contrib/cv/classfication/ResNet18/README.md index 70663bd09a49c00d02fc4c49e8f04955ddc0ed3f..77b0b5b46fb206da70822d50be76f7af8304e77f 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet18/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet18/README.md @@ -1,249 +1,249 @@ -# ResNet18 Onnx模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) - - [6.2 开源TopN精度](#62-开源TopN精度) - - [6.3 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[ResNet18论文](https://arxiv.org/pdf/1512.03385.pdf) - -### 1.2 代码地址 -[ResNet18代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) -branch:master -commit_id:7d955df73fe0e9b47f7d6c77c699324b256fc41f - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 -``` -CANN 5.0.1 - -torch == 1.5.1 -torchvision == 0.6.1 -onnx == 1.9.0 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.19.2 -Pillow == 8.2.0 -opencv-python == 4.5.2 -``` - -**说明:** -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 - -1.下载pth权重文件 -[ResNet-18预训练pth权重文件](https://download.pytorch.org/models/resnet18-f37072fd.pth) -``` -wget https://download.pytorch.org/models/resnet18-f37072fd.pth -``` -文件MD5sum:e0b1c919e74f9a193d36871d9964bf7d - -2.ResNet18模型代码在torchvision里,安装torchvision,arm下需源码安装,参考torchvision官网,若安装过程报错请百度解决 -``` -git clone https://github.com/pytorch/vision -cd vision -python3.7 setup.py install -cd .. -``` -3.编写pth2onnx脚本resnet18_pth2onnx.py - - **说明:** ->注意目前ATC支持的onnx算子版本为11 - -4.执行pth2onnx脚本,生成onnx模型文件 -``` -python3.7 resnet18_pth2onnx.py ./resnet18-f37072fd.pth resnet18.onnx -``` - - **模型转换要点:** ->此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 - -### 3.2 onnx转om模型 - -1.设置环境变量 -``` -source env.sh -``` -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) -``` -atc --framework=5 --model=./resnet18.onnx --output=resnet18_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 - -``` - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 - -### 4.2 数据集预处理 -1.预处理脚本imagenet_torch_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 -``` -python3.7 imagenet_torch_preprocess.py resnet /root/datasets/imagenet/val ./prep_dataset -``` -### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本gen_dataset_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 -``` -python3.7 gen_dataset_info.py bin ./prep_dataset ./resnet18_prep_bin.info 224 224 -``` -第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) -### 5.2 离线推理 -1.设置环境变量 -``` -source env.sh -``` -2.执行离线推理 -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=resnet18_bs1.om -input_text_path=./resnet18_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False -``` -输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 - -## 6 精度对比 - -- **[离线推理TopN精度](#61-离线推理TopN精度)** -- **[开源TopN精度](#62-开源TopN精度)** -- **[精度对比](#63-精度对比)** - -### 6.1 离线推理TopN精度统计 - -后处理统计TopN精度 - -调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 -``` -python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /root/datasets/imagenet/val_label.txt ./ result.json -``` -第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 -查看输出结果: -``` -{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "69.74%"}, {"key": "Top2 accuracy", "value": "80.49%"}, {"key": "Top3 accuracy", "value": "84.96%"}, {"key": "Top4 accuracy", "value": "87.38%"}, {"key": "Top5 accuracy", "value": "89.09%"}]} -``` -经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 - -### 6.2 开源TopN精度 -[torchvision官网精度](https://pytorch.org/vision/stable/models.html) -``` -Model Acc@1 Acc@5 -ResNet-18 69.758 89.078 -``` -### 6.3 精度对比 -将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 - **精度调试:** ->没有遇到精度不达标的问题,故不需要进行精度调试 - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** - -### 7.1 npu性能数据 -benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 -1.benchmark工具在整个数据集上推理获得性能数据 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: -``` -[e2e] throughputRate: 336.39, latency: 148637 -[data read] throughputRate: 357.787, moduleLatency: 2.79496 -[preprocess] throughputRate: 357.147, moduleLatency: 2.79997 -[infer] throughputRate: 338.442, Interface throughputRate: 787.709, moduleLatency: 2.21785 -[post] throughputRate: 338.44, moduleLatency: 2.95473 -``` -Interface throughputRate: 787.709,787.709x4=3150.836既是batch1 310单卡吞吐率 -batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: -``` -[e2e] throughputRate: 355.715, latency: 140562 -[data read] throughputRate: 377.215, moduleLatency: 2.65101 -[preprocess] throughputRate: 376.578, moduleLatency: 2.65549 -[infer] throughputRate: 357.628, Interface throughputRate: 1509.64, moduleLatency: 2.1165 -[post] throughputRate: 22.3509, moduleLatency: 44.7409 -``` -Interface throughputRate: 1509.64,1509.64x4=6038.56既是batch16 310单卡吞吐率 -batch4性能: -``` -[e2e] throughputRate: 218.705, latency: 228619 -[data read] throughputRate: 219.993, moduleLatency: 4.5456 -[preprocess] throughputRate: 219.699, moduleLatency: 4.55169 -[infer] throughputRate: 219.574, Interface throughputRate: 1103.24, moduleLatency: 2.38868 -[post] throughputRate: 54.8929, moduleLatency: 18.2173 -``` -batch4 310单卡吞吐率:1103.24x4=4412.96fps -batch8性能: -``` -[e2e] throughputRate: 175.032, latency: 285662 -[data read] throughputRate: 175.909, moduleLatency: 5.68474 -[preprocess] throughputRate: 175.703, moduleLatency: 5.69143 -[infer] throughputRate: 175.795, Interface throughputRate: 1446.02, moduleLatency: 2.17869 -[post] throughputRate: 21.9741, moduleLatency: 45.5081 -``` -batch8 310单卡吞吐率:1446.02x4=5784.08fps -batch32性能: -``` -[e2e] throughputRate: 151.68, latency: 329642 -[data read] throughputRate: 152.292, moduleLatency: 6.56634 -[preprocess] throughputRate: 152.082, moduleLatency: 6.57541 -[infer] throughputRate: 152.081, Interface throughputRate: 1375.46, moduleLatency: 2.20383 -[post] throughputRate: 4.75395, moduleLatency: 210.352 -``` -batch32 310单卡吞吐率:1375.46x4=5501.84fps - - **性能优化:** ->没有遇到性能不达标的问题,故不需要进行性能优化 - +# ResNet18 Onnx模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) + - [6.2 开源TopN精度](#62-开源TopN精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[ResNet18论文](https://arxiv.org/pdf/1512.03385.pdf) + +### 1.2 代码地址 +[ResNet18代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) +branch:master +commit_id:7d955df73fe0e9b47f7d6c77c699324b256fc41f + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +CANN 5.0.1 + +torch == 1.5.1 +torchvision == 0.6.1 +onnx == 1.9.0 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.19.2 +Pillow == 8.2.0 +opencv-python == 4.5.2 +``` + +**说明:** +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 + +1.下载pth权重文件 +[ResNet-18预训练pth权重文件](https://download.pytorch.org/models/resnet18-f37072fd.pth) +``` +wget https://download.pytorch.org/models/resnet18-f37072fd.pth +``` +文件MD5sum:e0b1c919e74f9a193d36871d9964bf7d + +2.ResNet18模型代码在torchvision里,安装torchvision,arm下需源码安装,参考torchvision官网,若安装过程报错请百度解决 +``` +git clone https://github.com/pytorch/vision +cd vision +python3.7 setup.py install +cd .. +``` +3.编写pth2onnx脚本resnet18_pth2onnx.py + + **说明:** +>注意目前ATC支持的onnx算子版本为11 + +4.执行pth2onnx脚本,生成onnx模型文件 +``` +python3.7 resnet18_pth2onnx.py ./resnet18-f37072fd.pth resnet18.onnx +``` + + **模型转换要点:** +>此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 + +### 3.2 onnx转om模型 + +1.设置环境变量 +``` +source env.sh +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) +``` +atc --framework=5 --model=./resnet18.onnx --output=resnet18_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 + +``` + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 + +### 4.2 数据集预处理 +1.预处理脚本imagenet_torch_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 +``` +python3.7 imagenet_torch_preprocess.py resnet /root/datasets/imagenet/val ./prep_dataset +``` +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本gen_dataset_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 +``` +python3.7 gen_dataset_info.py bin ./prep_dataset ./resnet18_prep_bin.info 224 224 +``` +第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) +### 5.2 离线推理 +1.设置环境变量 +``` +source env.sh +``` +2.执行离线推理 +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=resnet18_bs1.om -input_text_path=./resnet18_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +``` +输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 + +## 6 精度对比 + +- **[离线推理TopN精度](#61-离线推理TopN精度)** +- **[开源TopN精度](#62-开源TopN精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理TopN精度统计 + +后处理统计TopN精度 + +调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 +``` +python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /root/datasets/imagenet/val_label.txt ./ result.json +``` +第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 +查看输出结果: +``` +{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "69.74%"}, {"key": "Top2 accuracy", "value": "80.49%"}, {"key": "Top3 accuracy", "value": "84.96%"}, {"key": "Top4 accuracy", "value": "87.38%"}, {"key": "Top5 accuracy", "value": "89.09%"}]} +``` +经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 + +### 6.2 开源TopN精度 +[torchvision官网精度](https://pytorch.org/vision/stable/models.html) +``` +Model Acc@1 Acc@5 +ResNet-18 69.758 89.078 +``` +### 6.3 精度对比 +将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + **精度调试:** +>没有遇到精度不达标的问题,故不需要进行精度调试 + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** + +### 7.1 npu性能数据 +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 +1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: +``` +[e2e] throughputRate: 336.39, latency: 148637 +[data read] throughputRate: 357.787, moduleLatency: 2.79496 +[preprocess] throughputRate: 357.147, moduleLatency: 2.79997 +[infer] throughputRate: 338.442, Interface throughputRate: 787.709, moduleLatency: 2.21785 +[post] throughputRate: 338.44, moduleLatency: 2.95473 +``` +Interface throughputRate: 787.709,787.709x4=3150.836既是batch1 310单卡吞吐率 +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: +``` +[e2e] throughputRate: 355.715, latency: 140562 +[data read] throughputRate: 377.215, moduleLatency: 2.65101 +[preprocess] throughputRate: 376.578, moduleLatency: 2.65549 +[infer] throughputRate: 357.628, Interface throughputRate: 1509.64, moduleLatency: 2.1165 +[post] throughputRate: 22.3509, moduleLatency: 44.7409 +``` +Interface throughputRate: 1509.64,1509.64x4=6038.56既是batch16 310单卡吞吐率 +batch4性能: +``` +[e2e] throughputRate: 218.705, latency: 228619 +[data read] throughputRate: 219.993, moduleLatency: 4.5456 +[preprocess] throughputRate: 219.699, moduleLatency: 4.55169 +[infer] throughputRate: 219.574, Interface throughputRate: 1103.24, moduleLatency: 2.38868 +[post] throughputRate: 54.8929, moduleLatency: 18.2173 +``` +batch4 310单卡吞吐率:1103.24x4=4412.96fps +batch8性能: +``` +[e2e] throughputRate: 175.032, latency: 285662 +[data read] throughputRate: 175.909, moduleLatency: 5.68474 +[preprocess] throughputRate: 175.703, moduleLatency: 5.69143 +[infer] throughputRate: 175.795, Interface throughputRate: 1446.02, moduleLatency: 2.17869 +[post] throughputRate: 21.9741, moduleLatency: 45.5081 +``` +batch8 310单卡吞吐率:1446.02x4=5784.08fps +batch32性能: +``` +[e2e] throughputRate: 151.68, latency: 329642 +[data read] throughputRate: 152.292, moduleLatency: 6.56634 +[preprocess] throughputRate: 152.082, moduleLatency: 6.57541 +[infer] throughputRate: 152.081, Interface throughputRate: 1375.46, moduleLatency: 2.20383 +[post] throughputRate: 4.75395, moduleLatency: 210.352 +``` +batch32 310单卡吞吐率:1375.46x4=5501.84fps + + **性能优化:** +>没有遇到性能不达标的问题,故不需要进行性能优化 + diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet18/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/classfication/ResNet18/gen_dataset_info.py index 61450b4410663ae5e66ec29ed296ff6584203e31..5381839f653a885666e3fc456db9a1c22b8583a1 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet18/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet18/gen_dataset_info.py @@ -1,61 +1,61 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) + diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet18/imagenet_acc_eval.py b/ACL_PyTorch/contrib/cv/classfication/ResNet18/imagenet_acc_eval.py index 362f2484e8288dd3df6fa212678dc9449dbbed29..583340a19f2fc6e99faed85526c906f8bd12d7ba 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet18/imagenet_acc_eval.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet18/imagenet_acc_eval.py @@ -1,184 +1,184 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - if data == '': - n_label = 0 - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - print("Time used:", elapsed) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) + diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet18/imagenet_torch_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/ResNet18/imagenet_torch_preprocess.py index 1ab60b54dd7fd5b59ca733666c1dc63e07c980c1..a99dd271d0df5f9b21aa9c7da3fe7edb491a27e6 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet18/imagenet_torch_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet18/imagenet_torch_preprocess.py @@ -1,117 +1,117 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from PIL import Image -import numpy as np -import multiprocessing - - -model_config = { - 'resnet': { - 'resize': 256, - 'centercrop': 224, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv3': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv4': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.5, 0.5, 0.5], - 'std': [0.5, 0.5, 0.5], - }, -} - - -def center_crop(img, output_size): - if isinstance(output_size, int): - output_size = (int(output_size), int(output_size)) - image_width, image_height = img.size - crop_height, crop_width = output_size - crop_top = int(round((image_height - crop_height) / 2.)) - crop_left = int(round((image_width - crop_width) / 2.)) - return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) - - -def resize(img, size, interpolation=Image.BILINEAR): - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def gen_input_bin(mode_type, file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - # RGBA to RGB - image = Image.open(os.path.join(src_path, file)).convert('RGB') - image = resize(image, model_config[mode_type]['resize']) # Resize - image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop - img = np.array(image, dtype=np.float32) - img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW - img = img / 255. # ToTensor: div 255 - img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean - img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - - -def preprocess(mode_type, src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") - mode_type = sys.argv[1] - src_path = sys.argv[2] - save_path = sys.argv[3] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - if mode_type not in model_config: - model_type_help = "model type: " - for key in model_config.keys(): - model_type_help += key - model_type_help += ' ' - raise Exception(model_type_help) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - preprocess(mode_type, src_path, save_path) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from PIL import Image +import numpy as np +import multiprocessing + + +model_config = { + 'resnet': { + 'resize': 256, + 'centercrop': 224, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv3': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv4': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.5, 0.5, 0.5], + 'std': [0.5, 0.5, 0.5], + }, +} + + +def center_crop(img, output_size): + if isinstance(output_size, int): + output_size = (int(output_size), int(output_size)) + image_width, image_height = img.size + crop_height, crop_width = output_size + crop_top = int(round((image_height - crop_height) / 2.)) + crop_left = int(round((image_width - crop_width) / 2.)) + return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) + + +def resize(img, size, interpolation=Image.BILINEAR): + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def gen_input_bin(mode_type, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + # RGBA to RGB + image = Image.open(os.path.join(src_path, file)).convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.float32) + img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW + img = img / 255. # ToTensor: div 255 + img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean + img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +def preprocess(mode_type, src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") + mode_type = sys.argv[1] + src_path = sys.argv[2] + save_path = sys.argv[3] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if mode_type not in model_config: + model_type_help = "model type: " + for key in model_config.keys(): + model_type_help += key + model_type_help += ' ' + raise Exception(model_type_help) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess(mode_type, src_path, save_path) + diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet18/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/ResNet18/requirements.txt index 2fc4e802c476feda2a9866a85630f7f3b29428d7..d072d9aa6f2e7a7b0044ff93d036c3c0347ee5c9 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet18/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet18/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.5.1 -torchvision == 0.6.1 -onnx == 1.9.0 -numpy == 1.19.2 -Pillow == 8.2.0 +torch == 1.5.1 +torchvision == 0.6.1 +onnx == 1.9.0 +numpy == 1.19.2 +Pillow == 8.2.0 opencv-python == 4.5.2 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet18/resnet18_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/ResNet18/resnet18_pth2onnx.py index f7972ea3e1ecb2a5adee7e400d77ca66dec258ce..5933787407e4b3f92af4a90ad32c21d52704b04d 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet18/resnet18_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet18/resnet18_pth2onnx.py @@ -1,35 +1,35 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import torch -import torch.onnx -import torchvision.models as models - -def pth2onnx(input_file, output_file): - model = models.resnet18(pretrained=False) - checkpoint = torch.load(input_file, map_location=None) - model.load_state_dict(checkpoint) - - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) - -if __name__ == "__main__": - input_file = sys.argv[1] - output_file = sys.argv[2] - pth2onnx(input_file, output_file) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import torch +import torch.onnx +import torchvision.models as models + +def pth2onnx(input_file, output_file): + model = models.resnet18(pretrained=False) + checkpoint = torch.load(input_file, map_location=None) + model.load_state_dict(checkpoint) + + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) + +if __name__ == "__main__": + input_file = sys.argv[1] + output_file = sys.argv[2] + pth2onnx(input_file, output_file) diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet18/test/README.md b/ACL_PyTorch/contrib/cv/classfication/ResNet18/test/README.md index d9901cc5fc13a3cc2148d71691d4f97ffb24e378..0ae0ab0e82849c72a94ac50082a85518b5aa6495 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet18/test/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet18/test/README.md @@ -1,29 +1,29 @@ -环境准备: - -1.数据集路径 -数据集统一放在/root/datasets/或/opt/npu/ -本模型数据集放在/root/datasets/ - -2.进入工作目录 -cd ResNet18 - -3.安装必要的依赖 -pip3.7 install -r requirements.txt - -4.获取模型代码 -git clone https://github.com/pytorch/vision - -5.如果模型代码需要安装,则安装模型代码 -cd vision -python3.7 setup.py install -cd .. - -6.获取权重文件 -wget https://download.pytorch.org/models/resnet18-f37072fd.pth - -7.获取benchmark工具 -将benchmark.x86_64放在当前目录 - -8.310上执行,执行时确保device空闲 -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets +环境准备: + +1.数据集路径 +数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集放在/root/datasets/ + +2.进入工作目录 +cd ResNet18 + +3.安装必要的依赖 +pip3.7 install -r requirements.txt + +4.获取模型代码 +git clone https://github.com/pytorch/vision + +5.如果模型代码需要安装,则安装模型代码 +cd vision +python3.7 setup.py install +cd .. + +6.获取权重文件 +wget https://download.pytorch.org/models/resnet18-f37072fd.pth + +7.获取benchmark工具 +将benchmark.x86_64放在当前目录 + +8.310上执行,执行时确保device空闲 +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet18/test/parse.py b/ACL_PyTorch/contrib/cv/classfication/ResNet18/test/parse.py index a0f253b055047b199b33d4b65cdc79177b6b250b..27eae0d0acf98687edd95f1f024cf77c49cd4dc4 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet18/test/parse.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet18/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet34/LICENSE b/ACL_PyTorch/contrib/cv/classfication/ResNet34/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet34/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet34/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet34/README.md b/ACL_PyTorch/contrib/cv/classfication/ResNet34/README.md index 2c2062bf5e642598f3d9cb4ddeb85b2f410e6bd2..60c3739d7bc5d57864e5f540345f1db93850fe7c 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet34/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet34/README.md @@ -1,250 +1,250 @@ -# ResNet34 Onnx模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) - - [6.2 开源TopN精度](#62-开源TopN精度) - - [6.3 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[ResNet34论文](https://arxiv.org/pdf/1512.03385.pdf) - -### 1.2 代码地址 -[ResNet34代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) -branch:master -commit_id:7d955df73fe0e9b47f7d6c77c699324b256fc41f - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 -``` -CANN 5.0.1 - -torch == 1.5.1 -torchvision == 0.6.1 -onnx == 1.9.0 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.19.2 -Pillow == 8.2.0 -opencv-python == 4.5.2.52 -``` - -**说明:** -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 - -1.下载pth权重文件 -[ResNet-34预训练pth权重文件](https://download.pytorch.org/models/resnet34-b627a593.pth) -``` -wget https://download.pytorch.org/models/resnet34-b627a593.pth -``` -文件MD5sum:78fe1097b28dbda1373a700020afeed9 - -2.ResNet34模型代码在torchvision里,安装torchvision,arm下需源码安装,参考torchvision官网,若安装过程报错请百度解决 -``` -git clone https://github.com/pytorch/vision -cd vision -python3.7 setup.py install -cd .. -``` -3.编写pth2onnx脚本resnet34_pth2onnx.py - - **说明:** ->注意目前ATC支持的onnx算子版本为11 - -4.执行pth2onnx脚本,生成onnx模型文件 -``` -python3.7 resnet34_pth2onnx.py ./resnet34-b627a593.pth resnet34.onnx -``` - - **模型转换要点:** ->此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 - -### 3.2 onnx转om模型 - -1.设置环境变量 -``` -source env.sh -``` -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) -``` -atc --framework=5 --model=./resnet34.onnx --output=resnet34_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 - -``` - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 - -### 4.2 数据集预处理 -1.预处理脚本imagenet_torch_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 -``` -python3.7 imagenet_torch_preprocess.py resnet /root/datasets/imagenet/val ./prep_dataset -``` -### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本gen_dataset_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 -``` -python3.7 gen_dataset_info.py bin ./prep_dataset ./resnet34_prep_bin.info 224 224 -``` -第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) -### 5.2 离线推理 -1.设置环境变量 -``` -source env.sh -``` -2.执行离线推理 -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=resnet34_bs1.om -input_text_path=./resnet34_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False -``` -输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 - -## 6 精度对比 - -- **[离线推理TopN精度](#61-离线推理TopN精度)** -- **[开源TopN精度](#62-开源TopN精度)** -- **[精度对比](#63-精度对比)** - -### 6.1 离线推理TopN精度统计 - -后处理统计TopN精度 - -调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 -``` -python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /root/datasets/imagenet/val_label.txt ./ result.json -``` -第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 -查看输出结果: -``` -{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "73.31%"}, {"key": "Top2 accuracy", "value": "83.7%"}, {"key": "Top3 accuracy", "value": "87.72%"}, {"key": "Top4 accuracy", "value": "89.92%"}, {"key": "Top5 accuracy", "value": "91.44%"}]} -``` -经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 - -### 6.2 开源TopN精度 -[torchvision官网精度](https://pytorch.org/vision/stable/models.html) -``` -Model Acc@1 Acc@5 -ResNet-34 73.314 91.420 -``` -### 6.3 精度对比 -将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 - **精度调试:** ->没有遇到精度不达标的问题,故不需要进行精度调试 - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** - -### 7.1 npu性能数据 -benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 -1.benchmark工具在整个数据集上推理获得性能数据 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: -``` -[e2e] throughputRate: 275.179, latency: 181700 -[data read] throughputRate: 293.361, moduleLatency: 3.40877 -[preprocess] throughputRate: 292.803, moduleLatency: 3.41527 -[infer] throughputRate: 277.19, Interface throughputRate: 503.525, moduleLatency: 2.7551 -[post] throughputRate: 277.189, moduleLatency: 3.60764 -``` -Interface throughputRate: 503.525,503.525x4=2014.1既是batch1 310单卡吞吐率 -batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: -``` -[e2e] throughputRate: 177.5, latency: 281691 -[data read] throughputRate: 181.124, moduleLatency: 5.52107 -[preprocess] throughputRate: 180.841, moduleLatency: 5.52973 -[infer] throughputRate: 178.082, Interface throughputRate: 938.992, moduleLatency: 2.53232 -[post] throughputRate: 11.1299, moduleLatency: 89.8479 -``` -Interface throughputRate: 938.992,938.992x4=3755.968既是batch16 310单卡吞吐率 -batch4的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_4_device_1.txt: -``` -[e2e] throughputRate: 238.247, latency: 209866 -[data read] throughputRate: 251.629, moduleLatency: 3.97411 -[preprocess] throughputRate: 251.149, moduleLatency: 3.98169 -[infer] throughputRate: 239.788, Interface throughputRate: 672.405, moduleLatency: 3.026 -[post] throughputRate: 59.9466, moduleLatency: 16.6815 -``` -Interface throughputRate: 672.405,672.405x4=2689.62既是batch4 310单卡吞吐率 -batch8的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_8_device_1.txt: -``` -[e2e] throughputRate: 223.522, latency: 223692 -[data read] throughputRate: 233.498, moduleLatency: 4.28269 -[preprocess] throughputRate: 233.151, moduleLatency: 4.28906 -[infer] throughputRate: 224.317, Interface throughputRate: 884.554, moduleLatency: 2.62576 -[post] throughputRate: 28.0393, moduleLatency: 35.6643 -``` -Interface throughputRate: 884.554,884.554x4=3538.216既是batch8 310单卡吞吐率 -batch32的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_32_device_1.txt: -``` -[e2e] throughputRate: 200.951, latency: 248817 -[data read] throughputRate: 209.207, moduleLatency: 4.77995 -[preprocess] throughputRate: 208.778, moduleLatency: 4.78978 -[infer] throughputRate: 202.034, Interface throughputRate: 875.835, moduleLatency: 2.617 -[post] throughputRate: 6.31544, moduleLatency: 158.342 - - -``` -Interface throughputRate: 875.835,875.835x4=3503.34既是batch32 310单卡吞吐率 - - **性能优化:** ->没有遇到性能不达标的问题,故不需要进行性能优化 - +# ResNet34 Onnx模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) + - [6.2 开源TopN精度](#62-开源TopN精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[ResNet34论文](https://arxiv.org/pdf/1512.03385.pdf) + +### 1.2 代码地址 +[ResNet34代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) +branch:master +commit_id:7d955df73fe0e9b47f7d6c77c699324b256fc41f + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +CANN 5.0.1 + +torch == 1.5.1 +torchvision == 0.6.1 +onnx == 1.9.0 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.19.2 +Pillow == 8.2.0 +opencv-python == 4.5.2.52 +``` + +**说明:** +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 + +1.下载pth权重文件 +[ResNet-34预训练pth权重文件](https://download.pytorch.org/models/resnet34-b627a593.pth) +``` +wget https://download.pytorch.org/models/resnet34-b627a593.pth +``` +文件MD5sum:78fe1097b28dbda1373a700020afeed9 + +2.ResNet34模型代码在torchvision里,安装torchvision,arm下需源码安装,参考torchvision官网,若安装过程报错请百度解决 +``` +git clone https://github.com/pytorch/vision +cd vision +python3.7 setup.py install +cd .. +``` +3.编写pth2onnx脚本resnet34_pth2onnx.py + + **说明:** +>注意目前ATC支持的onnx算子版本为11 + +4.执行pth2onnx脚本,生成onnx模型文件 +``` +python3.7 resnet34_pth2onnx.py ./resnet34-b627a593.pth resnet34.onnx +``` + + **模型转换要点:** +>此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 + +### 3.2 onnx转om模型 + +1.设置环境变量 +``` +source env.sh +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) +``` +atc --framework=5 --model=./resnet34.onnx --output=resnet34_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 + +``` + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 + +### 4.2 数据集预处理 +1.预处理脚本imagenet_torch_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 +``` +python3.7 imagenet_torch_preprocess.py resnet /root/datasets/imagenet/val ./prep_dataset +``` +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本gen_dataset_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 +``` +python3.7 gen_dataset_info.py bin ./prep_dataset ./resnet34_prep_bin.info 224 224 +``` +第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) +### 5.2 离线推理 +1.设置环境变量 +``` +source env.sh +``` +2.执行离线推理 +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=resnet34_bs1.om -input_text_path=./resnet34_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +``` +输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 + +## 6 精度对比 + +- **[离线推理TopN精度](#61-离线推理TopN精度)** +- **[开源TopN精度](#62-开源TopN精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理TopN精度统计 + +后处理统计TopN精度 + +调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 +``` +python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /root/datasets/imagenet/val_label.txt ./ result.json +``` +第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 +查看输出结果: +``` +{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "73.31%"}, {"key": "Top2 accuracy", "value": "83.7%"}, {"key": "Top3 accuracy", "value": "87.72%"}, {"key": "Top4 accuracy", "value": "89.92%"}, {"key": "Top5 accuracy", "value": "91.44%"}]} +``` +经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 + +### 6.2 开源TopN精度 +[torchvision官网精度](https://pytorch.org/vision/stable/models.html) +``` +Model Acc@1 Acc@5 +ResNet-34 73.314 91.420 +``` +### 6.3 精度对比 +将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + **精度调试:** +>没有遇到精度不达标的问题,故不需要进行精度调试 + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** + +### 7.1 npu性能数据 +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 +1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: +``` +[e2e] throughputRate: 275.179, latency: 181700 +[data read] throughputRate: 293.361, moduleLatency: 3.40877 +[preprocess] throughputRate: 292.803, moduleLatency: 3.41527 +[infer] throughputRate: 277.19, Interface throughputRate: 503.525, moduleLatency: 2.7551 +[post] throughputRate: 277.189, moduleLatency: 3.60764 +``` +Interface throughputRate: 503.525,503.525x4=2014.1既是batch1 310单卡吞吐率 +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: +``` +[e2e] throughputRate: 177.5, latency: 281691 +[data read] throughputRate: 181.124, moduleLatency: 5.52107 +[preprocess] throughputRate: 180.841, moduleLatency: 5.52973 +[infer] throughputRate: 178.082, Interface throughputRate: 938.992, moduleLatency: 2.53232 +[post] throughputRate: 11.1299, moduleLatency: 89.8479 +``` +Interface throughputRate: 938.992,938.992x4=3755.968既是batch16 310单卡吞吐率 +batch4的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_4_device_1.txt: +``` +[e2e] throughputRate: 238.247, latency: 209866 +[data read] throughputRate: 251.629, moduleLatency: 3.97411 +[preprocess] throughputRate: 251.149, moduleLatency: 3.98169 +[infer] throughputRate: 239.788, Interface throughputRate: 672.405, moduleLatency: 3.026 +[post] throughputRate: 59.9466, moduleLatency: 16.6815 +``` +Interface throughputRate: 672.405,672.405x4=2689.62既是batch4 310单卡吞吐率 +batch8的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_8_device_1.txt: +``` +[e2e] throughputRate: 223.522, latency: 223692 +[data read] throughputRate: 233.498, moduleLatency: 4.28269 +[preprocess] throughputRate: 233.151, moduleLatency: 4.28906 +[infer] throughputRate: 224.317, Interface throughputRate: 884.554, moduleLatency: 2.62576 +[post] throughputRate: 28.0393, moduleLatency: 35.6643 +``` +Interface throughputRate: 884.554,884.554x4=3538.216既是batch8 310单卡吞吐率 +batch32的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_32_device_1.txt: +``` +[e2e] throughputRate: 200.951, latency: 248817 +[data read] throughputRate: 209.207, moduleLatency: 4.77995 +[preprocess] throughputRate: 208.778, moduleLatency: 4.78978 +[infer] throughputRate: 202.034, Interface throughputRate: 875.835, moduleLatency: 2.617 +[post] throughputRate: 6.31544, moduleLatency: 158.342 + + +``` +Interface throughputRate: 875.835,875.835x4=3503.34既是batch32 310单卡吞吐率 + + **性能优化:** +>没有遇到性能不达标的问题,故不需要进行性能优化 + diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet34/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/classfication/ResNet34/gen_dataset_info.py index 61450b4410663ae5e66ec29ed296ff6584203e31..5381839f653a885666e3fc456db9a1c22b8583a1 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet34/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet34/gen_dataset_info.py @@ -1,61 +1,61 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) + diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet34/imagenet_acc_eval.py b/ACL_PyTorch/contrib/cv/classfication/ResNet34/imagenet_acc_eval.py index 362f2484e8288dd3df6fa212678dc9449dbbed29..583340a19f2fc6e99faed85526c906f8bd12d7ba 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet34/imagenet_acc_eval.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet34/imagenet_acc_eval.py @@ -1,184 +1,184 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - if data == '': - n_label = 0 - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - print("Time used:", elapsed) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) + diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet34/imagenet_torch_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/ResNet34/imagenet_torch_preprocess.py index 1ab60b54dd7fd5b59ca733666c1dc63e07c980c1..a99dd271d0df5f9b21aa9c7da3fe7edb491a27e6 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet34/imagenet_torch_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet34/imagenet_torch_preprocess.py @@ -1,117 +1,117 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from PIL import Image -import numpy as np -import multiprocessing - - -model_config = { - 'resnet': { - 'resize': 256, - 'centercrop': 224, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv3': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv4': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.5, 0.5, 0.5], - 'std': [0.5, 0.5, 0.5], - }, -} - - -def center_crop(img, output_size): - if isinstance(output_size, int): - output_size = (int(output_size), int(output_size)) - image_width, image_height = img.size - crop_height, crop_width = output_size - crop_top = int(round((image_height - crop_height) / 2.)) - crop_left = int(round((image_width - crop_width) / 2.)) - return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) - - -def resize(img, size, interpolation=Image.BILINEAR): - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def gen_input_bin(mode_type, file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - # RGBA to RGB - image = Image.open(os.path.join(src_path, file)).convert('RGB') - image = resize(image, model_config[mode_type]['resize']) # Resize - image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop - img = np.array(image, dtype=np.float32) - img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW - img = img / 255. # ToTensor: div 255 - img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean - img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - - -def preprocess(mode_type, src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") - mode_type = sys.argv[1] - src_path = sys.argv[2] - save_path = sys.argv[3] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - if mode_type not in model_config: - model_type_help = "model type: " - for key in model_config.keys(): - model_type_help += key - model_type_help += ' ' - raise Exception(model_type_help) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - preprocess(mode_type, src_path, save_path) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from PIL import Image +import numpy as np +import multiprocessing + + +model_config = { + 'resnet': { + 'resize': 256, + 'centercrop': 224, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv3': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv4': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.5, 0.5, 0.5], + 'std': [0.5, 0.5, 0.5], + }, +} + + +def center_crop(img, output_size): + if isinstance(output_size, int): + output_size = (int(output_size), int(output_size)) + image_width, image_height = img.size + crop_height, crop_width = output_size + crop_top = int(round((image_height - crop_height) / 2.)) + crop_left = int(round((image_width - crop_width) / 2.)) + return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) + + +def resize(img, size, interpolation=Image.BILINEAR): + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def gen_input_bin(mode_type, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + # RGBA to RGB + image = Image.open(os.path.join(src_path, file)).convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.float32) + img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW + img = img / 255. # ToTensor: div 255 + img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean + img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +def preprocess(mode_type, src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") + mode_type = sys.argv[1] + src_path = sys.argv[2] + save_path = sys.argv[3] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if mode_type not in model_config: + model_type_help = "model type: " + for key in model_config.keys(): + model_type_help += key + model_type_help += ' ' + raise Exception(model_type_help) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess(mode_type, src_path, save_path) + diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet34/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/ResNet34/requirements.txt index 0fd8899267c708efec12cfc2fd54254e0f5eade9..a32f45720f6e73b661370f04a24d0090f4fbfdd1 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet34/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet34/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.5.1 -torchvision == 0.6.1 -onnx == 1.9.0 -numpy == 1.19.2 -Pillow == 8.2.0 +torch == 1.5.1 +torchvision == 0.6.1 +onnx == 1.9.0 +numpy == 1.19.2 +Pillow == 8.2.0 opencv-python == 4.5.2.52 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet34/resnet34_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/ResNet34/resnet34_pth2onnx.py index 45bd8bd56cb4d69fa93081c59a4c41dac2b5eea7..b0c2e06f250bfbba4c2fb722bea733ae7484712d 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet34/resnet34_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet34/resnet34_pth2onnx.py @@ -1,35 +1,35 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import torch -import torch.onnx -import torchvision.models as models - -def pth2onnx(input_file, output_file): - model = models.resnet34(pretrained=False) - checkpoint = torch.load(input_file, map_location=None) - model.load_state_dict(checkpoint) - - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) - -if __name__ == "__main__": - input_file = sys.argv[1] - output_file = sys.argv[2] - pth2onnx(input_file, output_file) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import torch +import torch.onnx +import torchvision.models as models + +def pth2onnx(input_file, output_file): + model = models.resnet34(pretrained=False) + checkpoint = torch.load(input_file, map_location=None) + model.load_state_dict(checkpoint) + + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) + +if __name__ == "__main__": + input_file = sys.argv[1] + output_file = sys.argv[2] + pth2onnx(input_file, output_file) diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet34/test/README.md b/ACL_PyTorch/contrib/cv/classfication/ResNet34/test/README.md index 4000a70540f9a0974034f7b29712a13b4c7f6a10..93ff0c492f4e1093b78d6bd496f2e2730b83e050 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet34/test/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet34/test/README.md @@ -1,29 +1,29 @@ -环境准备: - -1.数据集路径 -数据集统一放在/root/datasets/或/opt/npu/ -本模型数据集放在/root/datasets/ - -2.进入工作目录 -cd ResNet34 - -3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -pip3.7 install -r requirements.txt - -4.获取模型代码 -git clone https://github.com/pytorch/vision - -5.如果模型代码需要安装,则安装模型代码 -cd vision -python3.7 setup.py install -cd .. - -6.获取权重文件 -wget https://download.pytorch.org/models/resnet34-b627a593.pth - -7.获取benchmark工具 -将benchmark.x86_64放在当前目录 - -8.310上执行,执行时确保device空闲 -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets +环境准备: + +1.数据集路径 +数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集放在/root/datasets/ + +2.进入工作目录 +cd ResNet34 + +3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +pip3.7 install -r requirements.txt + +4.获取模型代码 +git clone https://github.com/pytorch/vision + +5.如果模型代码需要安装,则安装模型代码 +cd vision +python3.7 setup.py install +cd .. + +6.获取权重文件 +wget https://download.pytorch.org/models/resnet34-b627a593.pth + +7.获取benchmark工具 +将benchmark.x86_64放在当前目录 + +8.310上执行,执行时确保device空闲 +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNet34/test/parse.py b/ACL_PyTorch/contrib/cv/classfication/ResNet34/test/parse.py index a0f253b055047b199b33d4b65cdc79177b6b250b..27eae0d0acf98687edd95f1f024cf77c49cd4dc4 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNet34/test/parse.py +++ b/ACL_PyTorch/contrib/cv/classfication/ResNet34/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/ResNext101_32x8d/README.md b/ACL_PyTorch/contrib/cv/classfication/ResNext101_32x8d/README.md index 174206b05dd1c665a833b61e6de067b3f5ae4b60..289a13ea50a1660f00ecd47181ad43aa337cbe87 100644 --- a/ACL_PyTorch/contrib/cv/classfication/ResNext101_32x8d/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/ResNext101_32x8d/README.md @@ -1,288 +1,288 @@ -# ResNext101_32x8d Onnx模型端到端推理指导 - -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) - - [6.2 开源TopN精度](#62-开源TopN精度) - - [6.3 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 - -[ResNext101_32x8d论文](https://arxiv.org/pdf/1611.05431.pdf) - -### 1.2 代码地址 - -[ResNext101_32x8d代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) - -branch:master commit_id:7d955df73fe0e9b47f7d6c77c699324b256fc41f - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 - -``` -CANN 5.0.1 - -torch == 1.5.1 -torchvision == 0.6.1 -onnx == 1.9.0 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.20.3 -Pillow == 8.2.0 -opencv-python == 4.5.2 -``` - -**说明:** - -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - - - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 - -1.下载pth权重文件 -[ResNext101_32x8d 预训练pth权重文件](https://download.pytorch.org/models/resnext101_32x8d-8ba56ff5.pth) - -``` -wget https://download.pytorch.org/models/resnext101_32x8d-8ba56ff5.pth -``` - -文件MD5sum:4454a42689454b94296e378762f2333f - -3.编写pth2onnx脚本resnext101_32x8d_pth2onnx.py - - **说明:** - ->注意目前ATC支持的onnx算子版本为11 - -4.执行pth2onnx脚本,生成onnx模型文件 - -``` -python3.7 resnext101_32x8d_pth2onnx.py ./resnext101_32x8d-8ba56ff5.pth resnext101_32x8d.onnx -``` - - **模型转换要点:** - ->此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 - -### 3.2 onnx转om模型 - -1.设置环境变量 - -``` -source env.sh -``` - -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) - -``` -atc --framework=5 --model=./resnext101_32x8d.onnx --output=resnext101_32x8d_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 - -``` - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 - -该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 - -### 4.2 数据集预处理 - -1.预处理脚本imagenet_torch_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 - -``` -python3.7 imagenet_torch_preprocess.py resnet /root/datasets/imagenet/val ./prep_dataset -``` - -### 4.3 生成数据集信息文件 - -1.生成数据集信息文件脚本gen_dataset_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 - -``` -python3.7 gen_dataset_info.py bin ./prep_dataset ./resnext101_32x8d.info 224 224 -``` - -第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 - -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) - -### 5.2 离线推理 - -1.设置环境变量 - -``` -source env.sh -``` - -2.执行离线推理 - -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=resnext101_32x8d_bs1.om -input_text_path=./resnext101_32x8d.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False -``` - -输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 - -## 6 精度对比 - -- **[离线推理TopN精度](#61-离线推理TopN精度)** -- **[开源TopN精度](#62-开源TopN精度)** -- **[精度对比](#63-精度对比)** - -### 6.1 离线推理TopN精度统计 - -后处理统计TopN精度 - -调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 - -``` -python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /root/datasets/imagenet/val_label.txt ./ result.json -``` - -第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 -查看输出结果: - -``` -{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"},{"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "79.31%"}, {"key": "Top2 accuracy", "value": "88.68%"}, {"key": "Top3 accuracy", "value": "91.83%"}, {"key": "Top4 accuracy", "value": "93.47%"}, {"key": "Top5 accuracy", "value": "94.52%"}]} -``` - -经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 - -### 6.2 开源TopN精度 - -[torchvision官网精度](https://pytorch.org/vision/stable/models.html) - -``` -Model Acc@1 Acc@5ResNeXt-101-32x8d 79.312 94.526 -``` - -### 6.3 精度对比 - -将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 - **精度调试:** - ->没有遇到精度不达标的问题,故不需要进行精度调试 - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** - -### 7.1 npu性能数据 - -benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 -1.benchmark工具在整个数据集上推理获得性能数据 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: - -``` -[e2e] throughputRate: 113.043, latency: 442310[data read] throughputRate: 119.766, moduleLatency: 8.34965[preprocess] throughputRate: 119.219, moduleLatency: 8.38793[infer] throughputRate: 113.375, Interface throughputRate: 144.766, moduleLatency: 8.19887[post] throughputRate: 113.375, moduleLatency: 8.82032 -``` - -Interface throughputRate: 144.766,144.766x4=579.064既是batch1 310单卡吞吐率 -batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: - -``` -[e2e] throughputRate: 116.034, latency: 430908[data read] throughputRate: 122.878, moduleLatency: 8.13815[preprocess] throughputRate: 122.393, moduleLatency: 8.17039[infer] throughputRate: 116.288, Interface throughputRate: 165.952, moduleLatency: 7.47516[post] throughputRate: 7.2679, moduleLatency: 137.591 -``` - -Interface throughputRate: 165.952,165.952x4=663.808既是batch16 310单卡吞吐率 - - - -batch4的性能,使用benchmark工具进行纯推理,推理后生成result/PureInfer_perf_of_resnext101_32x8d_bs4_in_device_0.txt: - -``` -./benchmark.x86_64 -round=20 -om_path=resnext101_32x8d_bs4.om -device_id=0 -batch_size=4 -``` - - - -``` -ave_throughputRate = 167.46samples/s, ave_latency = 6.02002ms -``` - -ave_throughputRate: 167.46,167.46x4=669.84既是batch4 310单卡吞吐率 - - - -batch8的性能,使用benchmark工具进行纯推理,推理后生成result/PureInfer_perf_of_resnext101_32x8d_bs8_in_device_0.txt: - - - -``` -ave_throughputRate = 167.521samples/s, ave_latency = 5.9993ms -``` - -ave_throughputRate: 167.521,167.521x4=670.084既是batch8 310单卡吞吐率 - - - -batch32的性能,使用benchmark工具进行纯推理,推理后生成result/PureInfer_perf_of_resnext101_32x8d_bs32_in_device_0.txt: - -``` -ave_throughputRate = 108.28samples/s, ave_latency = 9.24227ms -``` - -ave_throughputRate: 108.28,108.28x4=433.12既是batch32 310单卡吞吐率 - - **性能优化:** - -对于batch32的性能不达标,从profiling数据的op_statistic_0_1.csv看出影响性能的是Conv2D算子,从op_summary_0_1.csv看出单个Conv_Relu算子aicore耗时0.6毫秒到6毫秒,shape大的耗时就多,不存在优化问题。 - +# ResNext101_32x8d Onnx模型端到端推理指导 + +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) + - [6.2 开源TopN精度](#62-开源TopN精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 + +[ResNext101_32x8d论文](https://arxiv.org/pdf/1611.05431.pdf) + +### 1.2 代码地址 + +[ResNext101_32x8d代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) + +branch:master commit_id:7d955df73fe0e9b47f7d6c77c699324b256fc41f + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 + +``` +CANN 5.0.1 + +torch == 1.5.1 +torchvision == 0.6.1 +onnx == 1.9.0 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.20.3 +Pillow == 8.2.0 +opencv-python == 4.5.2 +``` + +**说明:** + +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + + + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 + +1.下载pth权重文件 +[ResNext101_32x8d 预训练pth权重文件](https://download.pytorch.org/models/resnext101_32x8d-8ba56ff5.pth) + +``` +wget https://download.pytorch.org/models/resnext101_32x8d-8ba56ff5.pth +``` + +文件MD5sum:4454a42689454b94296e378762f2333f + +3.编写pth2onnx脚本resnext101_32x8d_pth2onnx.py + + **说明:** + +>注意目前ATC支持的onnx算子版本为11 + +4.执行pth2onnx脚本,生成onnx模型文件 + +``` +python3.7 resnext101_32x8d_pth2onnx.py ./resnext101_32x8d-8ba56ff5.pth resnext101_32x8d.onnx +``` + + **模型转换要点:** + +>此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 + +### 3.2 onnx转om模型 + +1.设置环境变量 + +``` +source env.sh +``` + +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) + +``` +atc --framework=5 --model=./resnext101_32x8d.onnx --output=resnext101_32x8d_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 + +``` + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 + +该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 + +### 4.2 数据集预处理 + +1.预处理脚本imagenet_torch_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 + +``` +python3.7 imagenet_torch_preprocess.py resnet /root/datasets/imagenet/val ./prep_dataset +``` + +### 4.3 生成数据集信息文件 + +1.生成数据集信息文件脚本gen_dataset_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 + +``` +python3.7 gen_dataset_info.py bin ./prep_dataset ./resnext101_32x8d.info 224 224 +``` + +第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 + +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) + +### 5.2 离线推理 + +1.设置环境变量 + +``` +source env.sh +``` + +2.执行离线推理 + +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=resnext101_32x8d_bs1.om -input_text_path=./resnext101_32x8d.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +``` + +输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 + +## 6 精度对比 + +- **[离线推理TopN精度](#61-离线推理TopN精度)** +- **[开源TopN精度](#62-开源TopN精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理TopN精度统计 + +后处理统计TopN精度 + +调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 + +``` +python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /root/datasets/imagenet/val_label.txt ./ result.json +``` + +第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 +查看输出结果: + +``` +{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"},{"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "79.31%"}, {"key": "Top2 accuracy", "value": "88.68%"}, {"key": "Top3 accuracy", "value": "91.83%"}, {"key": "Top4 accuracy", "value": "93.47%"}, {"key": "Top5 accuracy", "value": "94.52%"}]} +``` + +经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 + +### 6.2 开源TopN精度 + +[torchvision官网精度](https://pytorch.org/vision/stable/models.html) + +``` +Model Acc@1 Acc@5ResNeXt-101-32x8d 79.312 94.526 +``` + +### 6.3 精度对比 + +将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + **精度调试:** + +>没有遇到精度不达标的问题,故不需要进行精度调试 + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** + +### 7.1 npu性能数据 + +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 +1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: + +``` +[e2e] throughputRate: 113.043, latency: 442310[data read] throughputRate: 119.766, moduleLatency: 8.34965[preprocess] throughputRate: 119.219, moduleLatency: 8.38793[infer] throughputRate: 113.375, Interface throughputRate: 144.766, moduleLatency: 8.19887[post] throughputRate: 113.375, moduleLatency: 8.82032 +``` + +Interface throughputRate: 144.766,144.766x4=579.064既是batch1 310单卡吞吐率 +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: + +``` +[e2e] throughputRate: 116.034, latency: 430908[data read] throughputRate: 122.878, moduleLatency: 8.13815[preprocess] throughputRate: 122.393, moduleLatency: 8.17039[infer] throughputRate: 116.288, Interface throughputRate: 165.952, moduleLatency: 7.47516[post] throughputRate: 7.2679, moduleLatency: 137.591 +``` + +Interface throughputRate: 165.952,165.952x4=663.808既是batch16 310单卡吞吐率 + + + +batch4的性能,使用benchmark工具进行纯推理,推理后生成result/PureInfer_perf_of_resnext101_32x8d_bs4_in_device_0.txt: + +``` +./benchmark.x86_64 -round=20 -om_path=resnext101_32x8d_bs4.om -device_id=0 -batch_size=4 +``` + + + +``` +ave_throughputRate = 167.46samples/s, ave_latency = 6.02002ms +``` + +ave_throughputRate: 167.46,167.46x4=669.84既是batch4 310单卡吞吐率 + + + +batch8的性能,使用benchmark工具进行纯推理,推理后生成result/PureInfer_perf_of_resnext101_32x8d_bs8_in_device_0.txt: + + + +``` +ave_throughputRate = 167.521samples/s, ave_latency = 5.9993ms +``` + +ave_throughputRate: 167.521,167.521x4=670.084既是batch8 310单卡吞吐率 + + + +batch32的性能,使用benchmark工具进行纯推理,推理后生成result/PureInfer_perf_of_resnext101_32x8d_bs32_in_device_0.txt: + +``` +ave_throughputRate = 108.28samples/s, ave_latency = 9.24227ms +``` + +ave_throughputRate: 108.28,108.28x4=433.12既是batch32 310单卡吞吐率 + + **性能优化:** + +对于batch32的性能不达标,从profiling数据的op_statistic_0_1.csv看出影响性能的是Conv2D算子,从op_summary_0_1.csv看出单个Conv_Relu算子aicore耗时0.6毫秒到6毫秒,shape大的耗时就多,不存在优化问题。 + diff --git a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/LICENSE b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/README.md b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/README.md index e6c3abbd49e61c172a2994377781fa815d468210..5566fa1abe1ccb7836e4f0055818f42987ae334a 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/README.md @@ -1,271 +1,271 @@ - # Shufflenetv1 Onnx模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) - - [6.2 开源TopN精度](#62-开源TopN精度) - - [6.3 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - - - ## 1 模型概述 - - - **[论文地址](#11-论文地址)** - - - **[代码地址](#12-代码地址)** - - ### 1.1 论文地址 - [shufflenetv1论文](https://arxiv.org/pdf/1707.01083.pdf) - - ### 1.2 代码地址 - [shufflenetv1代码](https://github.com/megvii-model/ShuffleNet-Series/tree/master/ShuffleNetV1 ) - branch:master - commit_id: d69403d4b5fb3043c7c0da3c2a15df8c5e520d89 - - ## 2 环境说明 - - - **[深度学习框架](#21-深度学习框架)** - - - **[python第三方库](#22-python第三方库)** - - ### 2.1 深度学习框架 - ``` - CANN 5.0.2.alpha003 - pytorch == 1.8.0 - torchvision == 0.9.0 - onnx == 1.9.0 - ``` - - ### 2.2 python第三方库 - - ``` - numpy == 1.18.5 - Pillow == 7.2.0 - opencv-python == 4.5.1.48 - ``` - - **说明:** - > X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 - > - > Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - - ## 3 模型转换 - - - **[pth转onnx模型](#31-pth转onnx模型)** - - - **[onnx转om模型](#32-onnx转om模型)** - - ### 3.1 pth转onnx模型 - - 1.下载pth权重文件 - [Shufflenetv1预训练pth权重文件](https://pan.baidu.com/s/1EUQVoFPb74yZm0JWHKjFOw#list/path=%2F)(提取码:mc24) - 文件md5sum: bc2b8686fe73bf0709af2cbfcff2b895 - ``` - https://pan.baidu.com/s/1EUQVoFPb74yZm0JWHKjFOw#list/path=%2F - ``` -2.shufflenetv1模型代码在代码仓中 - - ``` - github上Shufflenetv1没有安装脚本,在pth2onnx脚本中引用代码仓定义的ShuffleNetv1: - - git clone https://github.com/megvii-model/ShuffleNet-Series.git - - ``` - 3.编写pth2onnx脚本shufflenetv1_pth2onnx.py - - **说明:** - >注意目前ATC支持的onnx算子版本为11 - - 4.执行pth2onnx脚本,生成onnx模型文件 - ``` - python3.7 shufflenetv1_pth2onnx_bs1.py 1.0x.pth.tar shufflenetv1_bs1.onnx - ``` - - **模型转换要点:** - >动态batch的onnx转om失败并且测的性能数据也不对,每个batch的om都需要对应batch的onnx来转换,每个batch的性能数据也需要对应batch的onnx来测 - ### 3.2 onnx转om模型 - - 1.设置环境变量 - ``` - source env.sh - ``` - 2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.2 开发辅助工具指南 (推理) 01 - ``` - atc --framework=5 --model=./shufflenetv1_bs1.onnx --input_format=NCHW --input_shape="image:1,3,224,224" --output=shufflenetv1_bs1 --log=debug --soc_version=Ascend310 - ``` - - ## 4 数据集预处理 - - - **[数据集获取](#41-数据集获取)** - - - **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - ### 4.1 数据集获取 - 该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/opt/npu/imagenet/val与/opt/npu/imagenet/val_label.txt。 - -### 4.2 数据集预处理 - 1.预处理脚本shufflenetv1_torch_preprocess.py - - 2.执行预处理脚本,生成数据集预处理后的bin文件 - ``` - python3.7 shufflenetv1_torch_preprocess.py /opt/npu/imagenet/val ./prep_dataset - ``` - ### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本get_info.py - - 2.执行生成数据集信息脚本,生成数据集信息文件 - ``` - python3.7 get_info.py bin ./prep_dataset ./shufflenetv1_prep_bin.info 224 224 - ``` - 第一个参数为生成的bin文件路径,第二个为输出的info文件,后面为宽高信息 - ## 5 离线推理 - - - **[benchmark工具概述](#51-benchmark工具概述)** - - - **[离线推理](#52-离线推理)** - - ### 5.1 benchmark工具概述 - - benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.2 推理benchmark工具用户指南 01 - ### 5.2 离线推理 - 1.设置环境变量 - ``` - source env.sh - ``` - 2.执行离线推理 - ``` - ./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=shufflenetv1_bs1.om -input_text_path=./shufflenetv1_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False - ``` - 输出结果默认保存在当前目录result/dumpOutput_devicex,模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 - - ## 6 精度对比 - - **[离线推理TopN精度](#61-离线推理TopN精度)** - - **[开源TopN精度](#62-开源TopN精度)** - - **[精度对比](#63-精度对比)** - - ### 6.1 离线推理TopN精度统计 - - 后处理统计TopN精度 - - 调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 - ``` - python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /opt/npu/imagenet/val_label.txt ./ result.json - ``` - 第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 - 查看输出结果: - ``` - {"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value -": "67.66%"}, {"key": "Top2 accuracy", "value": "78.61%"}, {"key": "Top3 accuracy", "value": "83.29%"}, {"key": "Top4 accuracy", "value": "85.83%"}, {"key": "Top5 accuracy", "value": "87.61%"}]} - ``` - 经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 - - ### 6.2 开源TopN精度 - [开源代码仓精度](https://github.com/megvii-model/ShuffleNet-Series/tree/master/ShuffleNetV1 ) - - ``` - | model | top1 | top5 | - | --------------------------- | ---- | ---- | - | ShuffleNetV1 1.0x (group=3) | 67.8 | 87.7 | - ``` - ### 6.3 精度对比 - 将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 - **精度调试:** - >遇到精度不对,首先考虑预处理是不是没有和开源代码仓一致。 - -## 7 性能对比 - - - **[npu性能数据](#71-npu性能数据)** - - ### 7.1 npu性能数据 - benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device。为快速获取性能数据,也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准。这里给出两种方式,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 - 1.benchmark工具在整个数据集上推理获得性能数据 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: -``` -[e2e] throughputRate: 225.491, latency: 221739 -[data read] throughputRate: 238.623, moduleLatency: 4.19071 -[preprocess] throughputRate: 238.364, moduleLatency: 4.19526 -[infer] throughputRate: 226.585, Interface throughputRate: 392.738, moduleLatency: 3.62481 -[post] throughputRate: 226.585, moduleLatency: 4.41336 - ``` - Interface throughputRate: 392.738,392.738乘以4即是310单卡吞吐 - - batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: - - ``` -[e2e] throughputRate: 179.484, latency: 278577 -[data read] throughputRate: 185.65, moduleLatency: 5.38649 -[preprocess] throughputRate: 185.36, moduleLatency: 5.39492 -[infer] throughputRate: 180.299, Interface throughputRate: 1335.44, moduleLatency: 2.25621 -[post] throughputRate: 11.2682, moduleLatency: 88.7455 - - ``` - Interface throughputRate: 1335.44,1335.44x4既是batch16 310单卡吞吐率 - batch4性能: -./benchmark.x86_64 -round=20 -om_path=shufflenetv1_bs4.om -device_id=3 -batch_size=4 - ``` -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_shufflenetv1_bs4_in_device_3.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 986.58samples/s, ave_latency: 1.03751ms ----------------------------------------------------------------- - - ``` - batch4 310单卡吞吐率:986.58x4=3946.32fps - batch8性能: - - ``` -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_shufflenetv1_bs8_in_device_3.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 1235.73samples/s, ave_latency: 0.821675ms ----------------------------------------------------------------- - ``` - batch8 310单卡吞吐率:1235.73x4=4942.92fps - batch32性能: - - ``` - -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_shufflenetv1_bs32_in_device_3.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 1258.14samples/s, ave_latency: 0.795141ms ----------------------------------------------------------------- - ``` - batch32 310单卡吞吐率: 1258.14x4=5032.56fps - - **性能优化:** - 1. CANN 5.0.2.alpha003版本将PadV3D与AvgPoolV2融合提高了性能,所以基于此版本测。 - 2. 从profiling数据的op_statistic_0_1.csv看出影响性能的是Conv2D算子,TransData,Transpose算子,Conv2D算子不存在问题,由于格式转换om模型Transpose前后需要有TransData算子,从op_summary_0_1.csv可以看出单个TransData或Transpose算子aicore耗时,确定是否可以优化。 - 3. dynamic/transpose.py:68中已经通过shape白名单优化掉了TransposeD -> - five_2_four.py:9928 - 修改如下: - > elif dst_format.lower() == "nchw" and dst_shape in [[2560, 512, 4, 26], [2560, 512, 1, 26], [2560, 256, 8, 25], - [16, 240, 7, 7], [16, 120, 14, 14], - [1, 240, 7, 7], [1, 120, 14, 14], - [4, 240, 7, 7], [4, 120, 14, 14], - [8, 240, 7, 7], [8, 120, 14, 14], - [32, 240, 7, 7], [32, 120, 14, 14]]: -> - four_2_five.py:1219 - 修改如下: - > if src_format.upper() == "NCHW" and shape_input in [[16, 240, 7, 7], [16, 120, 14, 14], - [1, 240, 7, 7], [1, 120, 14, 14], - [4, 240, 7, 7], [4, 120, 14, 14], - [8, 240, 7, 7], [8, 120, 14, 14], - [32, 240, 7, 7], [32, 120, 14, 14]] and dtype_input == "float16": + # Shufflenetv1 Onnx模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) + - [6.2 开源TopN精度](#62-开源TopN精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + + + + ## 1 模型概述 + + - **[论文地址](#11-论文地址)** + + - **[代码地址](#12-代码地址)** + + ### 1.1 论文地址 + [shufflenetv1论文](https://arxiv.org/pdf/1707.01083.pdf) + + ### 1.2 代码地址 + [shufflenetv1代码](https://github.com/megvii-model/ShuffleNet-Series/tree/master/ShuffleNetV1 ) + branch:master + commit_id: d69403d4b5fb3043c7c0da3c2a15df8c5e520d89 + + ## 2 环境说明 + + - **[深度学习框架](#21-深度学习框架)** + + - **[python第三方库](#22-python第三方库)** + + ### 2.1 深度学习框架 + ``` + CANN 5.0.2.alpha003 + pytorch == 1.8.0 + torchvision == 0.9.0 + onnx == 1.9.0 + ``` + + ### 2.2 python第三方库 + + ``` + numpy == 1.18.5 + Pillow == 7.2.0 + opencv-python == 4.5.1.48 + ``` + + **说明:** + > X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 + > + > Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + + ## 3 模型转换 + + - **[pth转onnx模型](#31-pth转onnx模型)** + + - **[onnx转om模型](#32-onnx转om模型)** + + ### 3.1 pth转onnx模型 + + 1.下载pth权重文件 + [Shufflenetv1预训练pth权重文件](https://pan.baidu.com/s/1EUQVoFPb74yZm0JWHKjFOw#list/path=%2F)(提取码:mc24) + 文件md5sum: bc2b8686fe73bf0709af2cbfcff2b895 + ``` + https://pan.baidu.com/s/1EUQVoFPb74yZm0JWHKjFOw#list/path=%2F + ``` +2.shufflenetv1模型代码在代码仓中 + + ``` + github上Shufflenetv1没有安装脚本,在pth2onnx脚本中引用代码仓定义的ShuffleNetv1: + + git clone https://github.com/megvii-model/ShuffleNet-Series.git + + ``` + 3.编写pth2onnx脚本shufflenetv1_pth2onnx.py + + **说明:** + >注意目前ATC支持的onnx算子版本为11 + + 4.执行pth2onnx脚本,生成onnx模型文件 + ``` + python3.7 shufflenetv1_pth2onnx_bs1.py 1.0x.pth.tar shufflenetv1_bs1.onnx + ``` + + **模型转换要点:** + >动态batch的onnx转om失败并且测的性能数据也不对,每个batch的om都需要对应batch的onnx来转换,每个batch的性能数据也需要对应batch的onnx来测 + ### 3.2 onnx转om模型 + + 1.设置环境变量 + ``` + source env.sh + ``` + 2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.2 开发辅助工具指南 (推理) 01 + ``` + atc --framework=5 --model=./shufflenetv1_bs1.onnx --input_format=NCHW --input_shape="image:1,3,224,224" --output=shufflenetv1_bs1 --log=debug --soc_version=Ascend310 + ``` + + ## 4 数据集预处理 + + - **[数据集获取](#41-数据集获取)** + + - **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + ### 4.1 数据集获取 + 该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/opt/npu/imagenet/val与/opt/npu/imagenet/val_label.txt。 + +### 4.2 数据集预处理 + 1.预处理脚本shufflenetv1_torch_preprocess.py + + 2.执行预处理脚本,生成数据集预处理后的bin文件 + ``` + python3.7 shufflenetv1_torch_preprocess.py /opt/npu/imagenet/val ./prep_dataset + ``` + ### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本get_info.py + + 2.执行生成数据集信息脚本,生成数据集信息文件 + ``` + python3.7 get_info.py bin ./prep_dataset ./shufflenetv1_prep_bin.info 224 224 + ``` + 第一个参数为生成的bin文件路径,第二个为输出的info文件,后面为宽高信息 + ## 5 离线推理 + + - **[benchmark工具概述](#51-benchmark工具概述)** + + - **[离线推理](#52-离线推理)** + + ### 5.1 benchmark工具概述 + + benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.2 推理benchmark工具用户指南 01 + ### 5.2 离线推理 + 1.设置环境变量 + ``` + source env.sh + ``` + 2.执行离线推理 + ``` + ./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=shufflenetv1_bs1.om -input_text_path=./shufflenetv1_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False + ``` + 输出结果默认保存在当前目录result/dumpOutput_devicex,模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 + + ## 6 精度对比 + - **[离线推理TopN精度](#61-离线推理TopN精度)** + - **[开源TopN精度](#62-开源TopN精度)** + - **[精度对比](#63-精度对比)** + + ### 6.1 离线推理TopN精度统计 + + 后处理统计TopN精度 + + 调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 + ``` + python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /opt/npu/imagenet/val_label.txt ./ result.json + ``` + 第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 + 查看输出结果: + ``` + {"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value +": "67.66%"}, {"key": "Top2 accuracy", "value": "78.61%"}, {"key": "Top3 accuracy", "value": "83.29%"}, {"key": "Top4 accuracy", "value": "85.83%"}, {"key": "Top5 accuracy", "value": "87.61%"}]} + ``` + 经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 + + ### 6.2 开源TopN精度 + [开源代码仓精度](https://github.com/megvii-model/ShuffleNet-Series/tree/master/ShuffleNetV1 ) + + ``` + | model | top1 | top5 | + | --------------------------- | ---- | ---- | + | ShuffleNetV1 1.0x (group=3) | 67.8 | 87.7 | + ``` + ### 6.3 精度对比 + 将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + **精度调试:** + >遇到精度不对,首先考虑预处理是不是没有和开源代码仓一致。 + +## 7 性能对比 + + - **[npu性能数据](#71-npu性能数据)** + + ### 7.1 npu性能数据 + benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device。为快速获取性能数据,也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准。这里给出两种方式,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 + 1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: +``` +[e2e] throughputRate: 225.491, latency: 221739 +[data read] throughputRate: 238.623, moduleLatency: 4.19071 +[preprocess] throughputRate: 238.364, moduleLatency: 4.19526 +[infer] throughputRate: 226.585, Interface throughputRate: 392.738, moduleLatency: 3.62481 +[post] throughputRate: 226.585, moduleLatency: 4.41336 + ``` + Interface throughputRate: 392.738,392.738乘以4即是310单卡吞吐 + + batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: + + ``` +[e2e] throughputRate: 179.484, latency: 278577 +[data read] throughputRate: 185.65, moduleLatency: 5.38649 +[preprocess] throughputRate: 185.36, moduleLatency: 5.39492 +[infer] throughputRate: 180.299, Interface throughputRate: 1335.44, moduleLatency: 2.25621 +[post] throughputRate: 11.2682, moduleLatency: 88.7455 + + ``` + Interface throughputRate: 1335.44,1335.44x4既是batch16 310单卡吞吐率 + batch4性能: +./benchmark.x86_64 -round=20 -om_path=shufflenetv1_bs4.om -device_id=3 -batch_size=4 + ``` +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_shufflenetv1_bs4_in_device_3.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 986.58samples/s, ave_latency: 1.03751ms +---------------------------------------------------------------- + + ``` + batch4 310单卡吞吐率:986.58x4=3946.32fps + batch8性能: + + ``` +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_shufflenetv1_bs8_in_device_3.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 1235.73samples/s, ave_latency: 0.821675ms +---------------------------------------------------------------- + ``` + batch8 310单卡吞吐率:1235.73x4=4942.92fps + batch32性能: + + ``` + +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_shufflenetv1_bs32_in_device_3.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 1258.14samples/s, ave_latency: 0.795141ms +---------------------------------------------------------------- + ``` + batch32 310单卡吞吐率: 1258.14x4=5032.56fps + + **性能优化:** + 1. CANN 5.0.2.alpha003版本将PadV3D与AvgPoolV2融合提高了性能,所以基于此版本测。 + 2. 从profiling数据的op_statistic_0_1.csv看出影响性能的是Conv2D算子,TransData,Transpose算子,Conv2D算子不存在问题,由于格式转换om模型Transpose前后需要有TransData算子,从op_summary_0_1.csv可以看出单个TransData或Transpose算子aicore耗时,确定是否可以优化。 + 3. dynamic/transpose.py:68中已经通过shape白名单优化掉了TransposeD +> + five_2_four.py:9928 + 修改如下: + > elif dst_format.lower() == "nchw" and dst_shape in [[2560, 512, 4, 26], [2560, 512, 1, 26], [2560, 256, 8, 25], + [16, 240, 7, 7], [16, 120, 14, 14], + [1, 240, 7, 7], [1, 120, 14, 14], + [4, 240, 7, 7], [4, 120, 14, 14], + [8, 240, 7, 7], [8, 120, 14, 14], + [32, 240, 7, 7], [32, 120, 14, 14]]: +> + four_2_five.py:1219 + 修改如下: + > if src_format.upper() == "NCHW" and shape_input in [[16, 240, 7, 7], [16, 120, 14, 14], + [1, 240, 7, 7], [1, 120, 14, 14], + [4, 240, 7, 7], [4, 120, 14, 14], + [8, 240, 7, 7], [8, 120, 14, 14], + [32, 240, 7, 7], [32, 120, 14, 14]] and dtype_input == "float16": > \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/requirements.txt index c2203b4465dfc2eed99b7f8329cf8d1dab08e3b6..fe5ade6e250c12797fe224ef8f1a6965ca76d103 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.8.0 -torchvision == 0.9.0 -onnx == 1.9.0 -numpy == 1.18.5 -Pillow == 7.2.0 +torch == 1.8.0 +torchvision == 0.9.0 +onnx == 1.9.0 +numpy == 1.18.5 +Pillow == 7.2.0 opencv-python == 4.5.1.48 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/shufflenetv1_pth2onnx_bs1.py b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/shufflenetv1_pth2onnx_bs1.py index 5da26de3375ebdd7cda443422553a2a1f8e1448b..88a6ada9a13c0b356353f803050783be6dfa3c31 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/shufflenetv1_pth2onnx_bs1.py +++ b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/shufflenetv1_pth2onnx_bs1.py @@ -1,38 +1,38 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import torch -import sys -from collections import OrderedDict -sys.path.append(r"./ShuffleNet-Series/ShuffleNetV1") -from network import ShuffleNetV1 - -def pth2onnx(input_file, output_file): - model = ShuffleNetV1(model_size="1.0x", group=3) - checkpoint = torch.load(input_file, map_location="cpu") - new_state_dict = OrderedDict() - for k, v in checkpoint['state_dict'].items(): - name = k[7:] - new_state_dict[name] = v - model.load_state_dict(new_state_dict) - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.rand(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, - input_names = input_names, dynamic_axes = dynamic_axes, - output_names = output_names, opset_version=11, verbose=True) - -if __name__=="__main__": - pth2onnx(sys.argv[1], sys.argv[2]) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import torch +import sys +from collections import OrderedDict +sys.path.append(r"./ShuffleNet-Series/ShuffleNetV1") +from network import ShuffleNetV1 + +def pth2onnx(input_file, output_file): + model = ShuffleNetV1(model_size="1.0x", group=3) + checkpoint = torch.load(input_file, map_location="cpu") + new_state_dict = OrderedDict() + for k, v in checkpoint['state_dict'].items(): + name = k[7:] + new_state_dict[name] = v + model.load_state_dict(new_state_dict) + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.rand(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, + input_names = input_names, dynamic_axes = dynamic_axes, + output_names = output_names, opset_version=11, verbose=True) + +if __name__=="__main__": + pth2onnx(sys.argv[1], sys.argv[2]) diff --git a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/shufflenetv1_pth2onnx_bs16.py b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/shufflenetv1_pth2onnx_bs16.py index 5b3fa4b69f55bb9a94a3ceb73a9fa6bb5fb28996..d396f8a2e05200f0f95fd10bc5dd57ff5607f972 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/shufflenetv1_pth2onnx_bs16.py +++ b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/shufflenetv1_pth2onnx_bs16.py @@ -1,37 +1,37 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import torch -import sys -from collections import OrderedDict -sys.path.append(r"./ShuffleNet-Series/ShuffleNetV1") -from network import ShuffleNetV1 - -def pth2onnx(input_file, output_file): - model = ShuffleNetV1(model_size="1.0x", group=3) - checkpoint = torch.load(input_file, map_location="cpu") - new_state_dict = OrderedDict() - for k, v in checkpoint['state_dict'].items(): - name = k[7: ] - new_state_dict[name] = v - model.load_state_dict(new_state_dict) - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.rand(16, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, - dynamic_axes = dynamic_axes, output_names = output_names, opset_version=11, verbose=True) - -if __name__ == "__main__": - pth2onnx(sys.argv[1], sys.argv[2]) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import torch +import sys +from collections import OrderedDict +sys.path.append(r"./ShuffleNet-Series/ShuffleNetV1") +from network import ShuffleNetV1 + +def pth2onnx(input_file, output_file): + model = ShuffleNetV1(model_size="1.0x", group=3) + checkpoint = torch.load(input_file, map_location="cpu") + new_state_dict = OrderedDict() + for k, v in checkpoint['state_dict'].items(): + name = k[7: ] + new_state_dict[name] = v + model.load_state_dict(new_state_dict) + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.rand(16, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, + dynamic_axes = dynamic_axes, output_names = output_names, opset_version=11, verbose=True) + +if __name__ == "__main__": + pth2onnx(sys.argv[1], sys.argv[2]) diff --git a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/shufflenetv1_torch_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/shufflenetv1_torch_preprocess.py index 4cf57f07c1e9d23d6a8332b295bb906e3db9e155..58eb781897e830217627df46fd5a38d0f90caca1 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/shufflenetv1_torch_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1/shufflenetv1_torch_preprocess.py @@ -1,79 +1,79 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import sys -import PIL -from PIL import Image -import cv2 -import numpy as np -import torch -from torchvision import transforms -import multiprocessing - -def ToBGRTensor(img): - assert isinstance(img, (np.ndarray, PIL.Image.Image)) - if isinstance(img, PIL.Image.Image): - img = np.asarray(img) - img = img[:, :, ::-1] # 2 BGR - img = np.transpose(img, [2, 0, 1]) # 2 (3, H, W) - img = np.ascontiguousarray(img) - img = torch.from_numpy(img).float() - return img - -def OpencvResize(img,size): - assert isinstance(img, PIL.Image.Image) - img = np.asarray(img) # (H,W,3) RGB - img = img[:, :, ::-1] # 2 BGR - img = np.ascontiguousarray(img) - H, W, _ = img.shape - target_size = (int(size / H * W + 0.5), size) if H < W else (size, int(size / W * H + 0.5)) - img = cv2.resize(img, target_size, interpolation=cv2.INTER_LINEAR) - img = img[:, :, ::-1] # 2 RGB - img = np.ascontiguousarray(img) - img = Image.fromarray(img) - return img - -def gen_input_bin(save_path, file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - # RGBA to RGB - image = Image.open(os.path.join(src_path, file)).convert('RGB') - - image = OpencvResize(image, 256) - crop = transforms.CenterCrop(224) - image = crop(image) - image = ToBGRTensor(image) - img = np.array(image, dtype=np.float32) - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - -def preprocess(src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(save_path, file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - -if __name__ == "__main__": - src_path = sys.argv[1] - save_path = sys.argv[2] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import sys +import PIL +from PIL import Image +import cv2 +import numpy as np +import torch +from torchvision import transforms +import multiprocessing + +def ToBGRTensor(img): + assert isinstance(img, (np.ndarray, PIL.Image.Image)) + if isinstance(img, PIL.Image.Image): + img = np.asarray(img) + img = img[:, :, ::-1] # 2 BGR + img = np.transpose(img, [2, 0, 1]) # 2 (3, H, W) + img = np.ascontiguousarray(img) + img = torch.from_numpy(img).float() + return img + +def OpencvResize(img,size): + assert isinstance(img, PIL.Image.Image) + img = np.asarray(img) # (H,W,3) RGB + img = img[:, :, ::-1] # 2 BGR + img = np.ascontiguousarray(img) + H, W, _ = img.shape + target_size = (int(size / H * W + 0.5), size) if H < W else (size, int(size / W * H + 0.5)) + img = cv2.resize(img, target_size, interpolation=cv2.INTER_LINEAR) + img = img[:, :, ::-1] # 2 RGB + img = np.ascontiguousarray(img) + img = Image.fromarray(img) + return img + +def gen_input_bin(save_path, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + # RGBA to RGB + image = Image.open(os.path.join(src_path, file)).convert('RGB') + + image = OpencvResize(image, 256) + crop = transforms.CenterCrop(224) + image = crop(image) + image = ToBGRTensor(image) + img = np.array(image, dtype=np.float32) + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + +def preprocess(src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(save_path, file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + +if __name__ == "__main__": + src_path = sys.argv[1] + save_path = sys.argv[2] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) preprocess(src_path, save_path) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/LICENSE b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/README.md b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/README.md index 57e58ac3ba1f47790477473bf71a6f67af80e536..4879ab50b9bb1f4af3145c742fe0758b6b3d785d 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/README.md @@ -1,259 +1,259 @@ -Shufflenetv2+ Onnx模型端到端推理指导 - -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) - - [6.2 开源TopN精度](#62-开源TopN精度) - - [6.3 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[shufflenetv2论文](https://arxiv.org/abs/1807.11164) - -### 1.2 代码地址 -[shufflenetv2+代码](https://github.com/megvii-model/ShuffleNet-Series/tree/master/ShuffleNetV2%2B) -branch:master -commit_id:d69403d4b5fb3043c7c0da3c2a15df8c5e520d89 - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 -``` -CANN 5.0.1 -pytorch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.7.0 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.18.5 -Pillow == 7.2.0 -opencv-python == 4.5.1.48 -``` - -**说明:** -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 - -1.下载pth权重文件 -[shufflenetv2+预训练pth权重文件](https://pan.baidu.com/share/init?surl=EUQVoFPb74yZm0JWHKjFOw) -文件md5sum: 1d6611049e6ef03f1d6afa11f6f9023e - -``` -https://pan.baidu.com/share/init?surl=EUQVoFPb74yZm0JWHKjFOw 提取码:mc24 -``` -2.shufflenetv2+模型代码在代码仓里 - -``` -github上Shufflenetv2+没有安装脚本,在pth2onnx脚本中引用代码仓定义的ShuffleNetv2+: - -git clone https://github.com/megvii-model/ShuffleNet-Series.git - - -``` -3.编写pth2onnx脚本shufflenetv2_pth2onnx_bs1.py - - **说明:** ->注意目前ATC支持的onnx算子版本为11 - -4.执行pth2onnx脚本,生成onnx模型文件 -``` -python3.7 shufflenetv2_pth2onnx_bs1.py ShuffleNetV2+.Small.pth.tar shufflenetv2_bs1.onnx -``` - **模型转换要点:** ->动态batch的onnx转om失败并且测的性能数据也不对,每个batch的om都需要对应batch的onnx来转换,每个batch的性能数据也需要对应batch的onnx来测 - - -### 3.2 onnx转om模型 - -1.设置环境变量 -``` -source env.sh -``` -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 -``` -atc --framework=5 --model=./shufflenetv2_bs1.onnx --input_format=NCHW --input_shape="image:1,3,224,224" --output=shufflenetv2_bs1 --log=debug --soc_version=Ascend310 -``` - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 - -### 4.2 数据集预处理 -1.预处理脚本imagenet_torch_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 -``` -python3.7 imagenet_torch_preprocess.py /root/datasets/imagenet/val ./prep_dataset -``` -### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本get_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 - -``` -python3.7 get_info.py bin ./prep_dataset ./shufflenetv2_prep_bin.info 224 224 -``` -第一个参数为生成的bin文件路径,第二个为输出的info文件,后面为宽高信息 -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.1 推理benchmark工具用户指南 01 -### 5.2 离线推理 -1.设置环境变量 -``` -source env.sh -``` -2.执行离线推理 - -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=shufflenetv2_bs1.om -input_text_path=./shufflenetv2_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False -``` -输出结果默认保存在当前目录result/dumpOutput_devicex,模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 - -## 6 精度对比 - -- **[离线推理TopN精度](#61-离线推理TopN精度)** -- **[开源TopN精度](#62-开源TopN精度)** -- **[精度对比](#63-精度对比)** - -### 6.1 离线推理TopN精度统计 - -后处理统计TopN精度 - -调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 -``` -python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /root/datasets/imagenet/val_label.txt ./ result.json -``` -第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 -查看输出结果: -``` -{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value -": "74.06%"}, {"key": "Top2 accuracy", "value": "84.21%"}, {"key": "Top3 accuracy", "value": "88.11%"}, {"key": "Top4 accuracy", "value": "90.3%"}, {"key": "Top5 accuracy", "value": "91.67%"}]} -``` -经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 - -### 6.2 开源TopN精度 -[开源代码仓精度](https://github.com/megvii-model/ShuffleNet-Series/tree/master/ShuffleNetV2%2B) - -``` -Model Acc@1 Acc@5 -shufflenetv2 74.1 91.7 -``` -### 6.3 精度对比 -将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 - **精度调试:** ->没有遇到精度不达标的问题,故不需要进行精度调试 - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** - -### 7.1 npu性能数据 -benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device。为快速获取性能数据,也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准。这里给出两种方式,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 -1.benchmark工具在整个数据集上推理获得性能数据 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: -``` -[e2e] throughputRate: 117.471, latency: 425636 -[data read] throughputRate: 124.47, moduleLatency: 8.03407 -[preprocess] throughputRate: 124.375, moduleLatency: 8.04019 -[infer] throughputRate: 117.823, Interface throughputRate: 147.93, moduleLatency: 7.93347 -[post] throughputRate: 117.822, moduleLatency: 8.48734 -``` -Interface throughputRate: 147.93,147.93x4=591.72既是batch1 310单卡吞吐率 -batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: - -``` -[e2e] throughputRate: 130.7, latency: 382555 -[data read] throughputRate: 131.307, moduleLatency: 7.61574 -[preprocess] throughputRate: 131.19, moduleLatency: 7.62255 -[infer] throughputRate: 131.175, Interface throughputRate: 491.668, moduleLatency: 3.45377 -[post] throughputRate: 8.19833, moduleLatency: 121.976 -``` -Interface throughputRate: 491.668,491.668x4=1966.672既是batch16 310单卡吞吐率 -batch4性能: - -``` -[e2e] throughputRate: 189.011, latency: 264534 -[data read] throughputRate: 198.271, moduleLatency: 5.0436 -[preprocess] throughputRate: 198.037, moduleLatency: 5.04955 -[infer] throughputRate: 189.874, Interface throughputRate: 363.812, moduleLatency: 4.18727 -[post] throughputRate: 47.4682, moduleLatency: 21.0667 -``` -batch4 310单卡吞吐率:363.812x4=1455.248fps -batch8性能: - -``` -[e2e] throughputRate: 139.455, latency: 358539 -[data read] throughputRate: 139.918, moduleLatency: 7.14704 -[preprocess] throughputRate: 139.784, moduleLatency: 7.15391 -[infer] throughputRate: 139.734, Interface throughputRate: 437.088, moduleLatency: 3.72351 -[post] throughputRate: 17.4666, moduleLatency: 57.2522 -``` -batch8 310单卡吞吐率:437.088x4=1748.352fps -batch32性能: - -``` -[e2e] throughputRate: 221.683, latency: 225547 -[data read] throughputRate: 235.234, moduleLatency: 4.25108 -[preprocess] throughputRate: 234.935, moduleLatency: 4.2565 -[infer] throughputRate: 222.362, Interface throughputRate: 475.038, moduleLatency: 3.51711 -[post] throughputRate: 6.95087, moduleLatency: 143.867 -``` -batch32 310单卡吞吐率:475.038x4=1900.152fps - -**性能优化:** - ->没有遇到性能不达标的问题,故不需要进行性能优化 - +Shufflenetv2+ Onnx模型端到端推理指导 + +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) + - [6.2 开源TopN精度](#62-开源TopN精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[shufflenetv2论文](https://arxiv.org/abs/1807.11164) + +### 1.2 代码地址 +[shufflenetv2+代码](https://github.com/megvii-model/ShuffleNet-Series/tree/master/ShuffleNetV2%2B) +branch:master +commit_id:d69403d4b5fb3043c7c0da3c2a15df8c5e520d89 + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +CANN 5.0.1 +pytorch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.7.0 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.18.5 +Pillow == 7.2.0 +opencv-python == 4.5.1.48 +``` + +**说明:** +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 + +1.下载pth权重文件 +[shufflenetv2+预训练pth权重文件](https://pan.baidu.com/share/init?surl=EUQVoFPb74yZm0JWHKjFOw) +文件md5sum: 1d6611049e6ef03f1d6afa11f6f9023e + +``` +https://pan.baidu.com/share/init?surl=EUQVoFPb74yZm0JWHKjFOw 提取码:mc24 +``` +2.shufflenetv2+模型代码在代码仓里 + +``` +github上Shufflenetv2+没有安装脚本,在pth2onnx脚本中引用代码仓定义的ShuffleNetv2+: + +git clone https://github.com/megvii-model/ShuffleNet-Series.git + + +``` +3.编写pth2onnx脚本shufflenetv2_pth2onnx_bs1.py + + **说明:** +>注意目前ATC支持的onnx算子版本为11 + +4.执行pth2onnx脚本,生成onnx模型文件 +``` +python3.7 shufflenetv2_pth2onnx_bs1.py ShuffleNetV2+.Small.pth.tar shufflenetv2_bs1.onnx +``` + **模型转换要点:** +>动态batch的onnx转om失败并且测的性能数据也不对,每个batch的om都需要对应batch的onnx来转换,每个batch的性能数据也需要对应batch的onnx来测 + + +### 3.2 onnx转om模型 + +1.设置环境变量 +``` +source env.sh +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 +``` +atc --framework=5 --model=./shufflenetv2_bs1.onnx --input_format=NCHW --input_shape="image:1,3,224,224" --output=shufflenetv2_bs1 --log=debug --soc_version=Ascend310 +``` + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/root/datasets/imagenet/val与/root/datasets/imagenet/val_label.txt。 + +### 4.2 数据集预处理 +1.预处理脚本imagenet_torch_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 +``` +python3.7 imagenet_torch_preprocess.py /root/datasets/imagenet/val ./prep_dataset +``` +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本get_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 + +``` +python3.7 get_info.py bin ./prep_dataset ./shufflenetv2_prep_bin.info 224 224 +``` +第一个参数为生成的bin文件路径,第二个为输出的info文件,后面为宽高信息 +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.1 推理benchmark工具用户指南 01 +### 5.2 离线推理 +1.设置环境变量 +``` +source env.sh +``` +2.执行离线推理 + +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=shufflenetv2_bs1.om -input_text_path=./shufflenetv2_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +``` +输出结果默认保存在当前目录result/dumpOutput_devicex,模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 + +## 6 精度对比 + +- **[离线推理TopN精度](#61-离线推理TopN精度)** +- **[开源TopN精度](#62-开源TopN精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理TopN精度统计 + +后处理统计TopN精度 + +调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 +``` +python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /root/datasets/imagenet/val_label.txt ./ result.json +``` +第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 +查看输出结果: +``` +{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value +": "74.06%"}, {"key": "Top2 accuracy", "value": "84.21%"}, {"key": "Top3 accuracy", "value": "88.11%"}, {"key": "Top4 accuracy", "value": "90.3%"}, {"key": "Top5 accuracy", "value": "91.67%"}]} +``` +经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 + +### 6.2 开源TopN精度 +[开源代码仓精度](https://github.com/megvii-model/ShuffleNet-Series/tree/master/ShuffleNetV2%2B) + +``` +Model Acc@1 Acc@5 +shufflenetv2 74.1 91.7 +``` +### 6.3 精度对比 +将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + **精度调试:** +>没有遇到精度不达标的问题,故不需要进行精度调试 + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** + +### 7.1 npu性能数据 +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device。为快速获取性能数据,也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准。这里给出两种方式,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 +1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: +``` +[e2e] throughputRate: 117.471, latency: 425636 +[data read] throughputRate: 124.47, moduleLatency: 8.03407 +[preprocess] throughputRate: 124.375, moduleLatency: 8.04019 +[infer] throughputRate: 117.823, Interface throughputRate: 147.93, moduleLatency: 7.93347 +[post] throughputRate: 117.822, moduleLatency: 8.48734 +``` +Interface throughputRate: 147.93,147.93x4=591.72既是batch1 310单卡吞吐率 +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: + +``` +[e2e] throughputRate: 130.7, latency: 382555 +[data read] throughputRate: 131.307, moduleLatency: 7.61574 +[preprocess] throughputRate: 131.19, moduleLatency: 7.62255 +[infer] throughputRate: 131.175, Interface throughputRate: 491.668, moduleLatency: 3.45377 +[post] throughputRate: 8.19833, moduleLatency: 121.976 +``` +Interface throughputRate: 491.668,491.668x4=1966.672既是batch16 310单卡吞吐率 +batch4性能: + +``` +[e2e] throughputRate: 189.011, latency: 264534 +[data read] throughputRate: 198.271, moduleLatency: 5.0436 +[preprocess] throughputRate: 198.037, moduleLatency: 5.04955 +[infer] throughputRate: 189.874, Interface throughputRate: 363.812, moduleLatency: 4.18727 +[post] throughputRate: 47.4682, moduleLatency: 21.0667 +``` +batch4 310单卡吞吐率:363.812x4=1455.248fps +batch8性能: + +``` +[e2e] throughputRate: 139.455, latency: 358539 +[data read] throughputRate: 139.918, moduleLatency: 7.14704 +[preprocess] throughputRate: 139.784, moduleLatency: 7.15391 +[infer] throughputRate: 139.734, Interface throughputRate: 437.088, moduleLatency: 3.72351 +[post] throughputRate: 17.4666, moduleLatency: 57.2522 +``` +batch8 310单卡吞吐率:437.088x4=1748.352fps +batch32性能: + +``` +[e2e] throughputRate: 221.683, latency: 225547 +[data read] throughputRate: 235.234, moduleLatency: 4.25108 +[preprocess] throughputRate: 234.935, moduleLatency: 4.2565 +[infer] throughputRate: 222.362, Interface throughputRate: 475.038, moduleLatency: 3.51711 +[post] throughputRate: 6.95087, moduleLatency: 143.867 +``` +batch32 310单卡吞吐率:475.038x4=1900.152fps + +**性能优化:** + +>没有遇到性能不达标的问题,故不需要进行性能优化 + diff --git a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/imagenet_torch_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/imagenet_torch_preprocess.py index 67877da44e7c9990dafe3d21a2b76da8ebb37ae3..cb19574d4a03c11f0e2bf073e08c9b9df2a383d0 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/imagenet_torch_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/imagenet_torch_preprocess.py @@ -1,72 +1,72 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import sys -import PIL -from PIL import Image -import cv2 -import numpy as np -import torch -from torchvision import transforms - -class ToBGRTensor(object): - - def __call__(self, img): - assert isinstance(img, (np.ndarray, PIL.Image.Image)) - if isinstance(img, PIL.Image.Image): - img = np.asarray(img) - img = img[:,:,::-1] # 2 BGR - img = np.transpose(img, [2, 0, 1]) # 2 (3, H, W) - img = np.ascontiguousarray(img) - img = torch.from_numpy(img).float() - return img - -class OpencvResize(object): - - def __init__(self, size=256): - self.size = size - - def __call__(self, img): - assert isinstance(img, PIL.Image.Image) - img = np.asarray(img) # (H,W,3) RGB - img = img[:,:,::-1] # 2 BGR - img = np.ascontiguousarray(img) - H, W, _ = img.shape - target_size = (int(self.size/H * W + 0.5), self.size) if H < W else (self.size, int(self.size/W * H + 0.5)) - img = cv2.resize(img, target_size, interpolation=cv2.INTER_LINEAR) - img = img[:,:,::-1] # 2 RGB - img = np.ascontiguousarray(img) - img = Image.fromarray(img) - return img - -def preprocess(src_path, save_path): - - preprocess = transforms.Compose([ - OpencvResize(256), - transforms.CenterCrop(224), - ToBGRTensor(), - ]) - - i = 0 - in_files = os.listdir(src_path) - for file in in_files: - i = i + 1 - print(file, "===", i) - input_image = Image.open(src_path + '/' + file).convert('RGB') - input_tensor = preprocess(input_image) - img = np.array(input_tensor).astype(np.float32) - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - -if __name__=="__main__": - preprocess(sys.argv[1],sys.argv[2]) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import sys +import PIL +from PIL import Image +import cv2 +import numpy as np +import torch +from torchvision import transforms + +class ToBGRTensor(object): + + def __call__(self, img): + assert isinstance(img, (np.ndarray, PIL.Image.Image)) + if isinstance(img, PIL.Image.Image): + img = np.asarray(img) + img = img[:,:,::-1] # 2 BGR + img = np.transpose(img, [2, 0, 1]) # 2 (3, H, W) + img = np.ascontiguousarray(img) + img = torch.from_numpy(img).float() + return img + +class OpencvResize(object): + + def __init__(self, size=256): + self.size = size + + def __call__(self, img): + assert isinstance(img, PIL.Image.Image) + img = np.asarray(img) # (H,W,3) RGB + img = img[:,:,::-1] # 2 BGR + img = np.ascontiguousarray(img) + H, W, _ = img.shape + target_size = (int(self.size/H * W + 0.5), self.size) if H < W else (self.size, int(self.size/W * H + 0.5)) + img = cv2.resize(img, target_size, interpolation=cv2.INTER_LINEAR) + img = img[:,:,::-1] # 2 RGB + img = np.ascontiguousarray(img) + img = Image.fromarray(img) + return img + +def preprocess(src_path, save_path): + + preprocess = transforms.Compose([ + OpencvResize(256), + transforms.CenterCrop(224), + ToBGRTensor(), + ]) + + i = 0 + in_files = os.listdir(src_path) + for file in in_files: + i = i + 1 + print(file, "===", i) + input_image = Image.open(src_path + '/' + file).convert('RGB') + input_tensor = preprocess(input_image) + img = np.array(input_tensor).astype(np.float32) + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + +if __name__=="__main__": + preprocess(sys.argv[1],sys.argv[2]) diff --git a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/requirements.txt index 19bf0c33da4a5c3990a53fb79d681b2804a6df47..59f8a711bf24972d8af91f0ba668c3fc5d91a1bb 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.7.0 -numpy == 1.18.5 -Pillow == 7.2.0 +torch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.7.0 +numpy == 1.18.5 +Pillow == 7.2.0 opencv-python == 4.5.1.48 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/shufflenetv2_pth2onnx_bs1.py b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/shufflenetv2_pth2onnx_bs1.py index ff67f2706f25e9c567c94db11af3558fb4574aa5..f428f939b096bc974633b603bcdd78980bc03382 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/shufflenetv2_pth2onnx_bs1.py +++ b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/shufflenetv2_pth2onnx_bs1.py @@ -1,39 +1,39 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import sys -import torch -from collections import OrderedDict -sys.path.append(r"./ShuffleNet-Series/ShuffleNetV2+") -from network import ShuffleNetV2_Plus - -def pth2onnx(input_file, output_file): - architecture = [0, 0, 3, 1, 1, 1, 0, 0, 2, 0, 2, 1, 1, 0, 2, 0, 2, 1, 3, 2] - model = ShuffleNetV2_Plus(architecture=architecture,model_size='Small') - checkpoint = torch.load(input_file, map_location="cpu") - new_state_dict = OrderedDict() - for k, v in checkpoint['state_dict'].items(): - name = k[7:] - new_state_dict[name] = v - model.load_state_dict(new_state_dict) - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.rand(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, - input_names = input_names, dynamic_axes = dynamic_axes, - output_names = output_names, opset_version=11, verbose=True) - -if __name__=="__main__": - pth2onnx(sys.argv[1], sys.argv[2]) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +import torch +from collections import OrderedDict +sys.path.append(r"./ShuffleNet-Series/ShuffleNetV2+") +from network import ShuffleNetV2_Plus + +def pth2onnx(input_file, output_file): + architecture = [0, 0, 3, 1, 1, 1, 0, 0, 2, 0, 2, 1, 1, 0, 2, 0, 2, 1, 3, 2] + model = ShuffleNetV2_Plus(architecture=architecture,model_size='Small') + checkpoint = torch.load(input_file, map_location="cpu") + new_state_dict = OrderedDict() + for k, v in checkpoint['state_dict'].items(): + name = k[7:] + new_state_dict[name] = v + model.load_state_dict(new_state_dict) + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.rand(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, + input_names = input_names, dynamic_axes = dynamic_axes, + output_names = output_names, opset_version=11, verbose=True) + +if __name__=="__main__": + pth2onnx(sys.argv[1], sys.argv[2]) diff --git a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/shufflenetv2_pth2onnx_bs16.py b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/shufflenetv2_pth2onnx_bs16.py index 5eb21c1900f2e35feb1d571b77ea2e15a5754904..708cfba6b53cbfe72676069a9614e7b657ff9870 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/shufflenetv2_pth2onnx_bs16.py +++ b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/shufflenetv2_pth2onnx_bs16.py @@ -1,39 +1,39 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import sys -import torch -from collections import OrderedDict -sys.path.append(r"./ShuffleNet-Series/ShuffleNetV2+") -from network import ShuffleNetV2_Plus - -def pth2onnx(input_file, output_file): - architecture = [0, 0, 3, 1, 1, 1, 0, 0, 2, 0, 2, 1, 1, 0, 2, 0, 2, 1, 3, 2] - model = ShuffleNetV2_Plus(architecture=architecture,model_size='Small') - checkpoint = torch.load(input_file, map_location="cpu") - new_state_dict = OrderedDict() - for k, v in checkpoint['state_dict'].items(): - name = k[7:] - new_state_dict[name] = v - model.load_state_dict(new_state_dict) - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.rand(16, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, - input_names = input_names, dynamic_axes = dynamic_axes, - output_names = output_names, opset_version=11, verbose=True) - -if __name__=="__main__": - pth2onnx(sys.argv[1], sys.argv[2]) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +import torch +from collections import OrderedDict +sys.path.append(r"./ShuffleNet-Series/ShuffleNetV2+") +from network import ShuffleNetV2_Plus + +def pth2onnx(input_file, output_file): + architecture = [0, 0, 3, 1, 1, 1, 0, 0, 2, 0, 2, 1, 1, 0, 2, 0, 2, 1, 3, 2] + model = ShuffleNetV2_Plus(architecture=architecture,model_size='Small') + checkpoint = torch.load(input_file, map_location="cpu") + new_state_dict = OrderedDict() + for k, v in checkpoint['state_dict'].items(): + name = k[7:] + new_state_dict[name] = v + model.load_state_dict(new_state_dict) + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.rand(16, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, + input_names = input_names, dynamic_axes = dynamic_axes, + output_names = output_names, opset_version=11, verbose=True) + +if __name__=="__main__": + pth2onnx(sys.argv[1], sys.argv[2]) diff --git a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/test/readme.md b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/test/readme.md index a8c39573767998c0bf79d1e41514c44e9690da4b..a308c17cb252b33784d7cc1cdb4185d44cf1782a 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/test/readme.md +++ b/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+/test/readme.md @@ -1,27 +1,27 @@ -环境准备: - -1.数据集路径 -通用的数据集统一放在/root/datasets/或/opt/npu/ -本模型数据集放在/opt/npu/ - -2.进入工作目录 -cd Shufflenetv2+ - -3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -pip3.7 install -r requirements.txt - -4.获取模型代码 -git clone https://github.com/megvii-model/ShuffleNet-Series.git - - -5.获取权重文件 -https://pan.baidu.com/share/init?surl=EUQVoFPb74yZm0JWHKjFOw - -提取码:mc24 - -6.获取benchmark工具 -将benchmark.x86_64 benchmark.aarch64放在当前目录 - -7.310上执行,执行时确保device空闲 -bash test/pth2om.sh -bash test/eval_acc_perf.sh +环境准备: + +1.数据集路径 +通用的数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集放在/opt/npu/ + +2.进入工作目录 +cd Shufflenetv2+ + +3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +pip3.7 install -r requirements.txt + +4.获取模型代码 +git clone https://github.com/megvii-model/ShuffleNet-Series.git + + +5.获取权重文件 +https://pan.baidu.com/share/init?surl=EUQVoFPb74yZm0JWHKjFOw + +提取码:mc24 + +6.获取benchmark工具 +将benchmark.x86_64 benchmark.aarch64放在当前目录 + +7.310上执行,执行时确保device空闲 +bash test/pth2om.sh +bash test/eval_acc_perf.sh diff --git a/ACL_PyTorch/contrib/cv/classfication/SimCLR_inference/Simclr_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/SimCLR_inference/Simclr_preprocess.py index d423874602ceb7871b543f552a820d7382b260db..93065389d266b72509ac9de008f5171e08610a34 100644 --- a/ACL_PyTorch/contrib/cv/classfication/SimCLR_inference/Simclr_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/SimCLR_inference/Simclr_preprocess.py @@ -1,106 +1,106 @@ -""" -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -""" - -import numpy as np -from torchvision import transforms -import torch -from torch import nn -import os -from PIL import Image -import sys -import pickle - - -class GaussianBlur(object): - """blur a single image on CPU""" - def __init__(self, kernel_size): - radias = kernel_size // 2 - kernel_size = radias * 2 + 1 - self.blur_h = nn.Conv2d(3, 3, kernel_size=(kernel_size, 1), - stride=1, padding=0, bias=False, groups=3) - self.blur_v = nn.Conv2d(3, 3, kernel_size=(1, kernel_size), - stride=1, padding=0, bias=False, groups=3) - self.k = kernel_size - self.r = radias - - self.blur = nn.Sequential( - nn.ReflectionPad2d(radias), - self.blur_h, - self.blur_v - ) - - self.pil_to_tensor = transforms.ToTensor() - self.tensor_to_pil = transforms.ToPILImage() - - def __call__(self, img): - img = self.pil_to_tensor(img).unsqueeze(0) - - sigma = np.random.uniform(0.1, 2.0) - x = np.arange(-self.r, self.r + 1) - x = np.exp(-np.power(x, 2) / (2 * sigma * sigma)) - x = x / x.sum() - x = torch.from_numpy(x).view(1, -1).repeat(3, 1) - - self.blur_h.weight.data.copy_(x.view(3, 1, self.k, 1)) - self.blur_v.weight.data.copy_(x.view(3, 1, 1, self.k)) - - with torch.no_grad(): - img = self.blur(img) - img = img.squeeze() - - img = self.tensor_to_pil(img) - - return img - - -def preprocess(srcfile_path, savefile_path): - """ data preprocess """ - size = 32 - s = 1 - n_views = 2 - file_num = 0 - data = [] - color_jitter = transforms.ColorJitter(0.8 * s, 0.8 * s, 0.8 * s, 0.2 * s) - data_transforms = transforms.Compose([transforms.RandomResizedCrop(size=size), - transforms.RandomHorizontalFlip(), - transforms.RandomApply([color_jitter], p=0.8), - transforms.RandomGrayscale(p=0.2), - GaussianBlur(kernel_size=int(0.1 * size)), - transforms.ToTensor()]) - if not os.path.exists(savefile_path): - os.mkdir(savefile_path) - with open(srcfile_path, "rb") as f: - entry = pickle.load(f, encoding='latin1') - data.append(entry['data']) - images = np.vstack(data).reshape(-1, 3, 32, 32) - images = np.transpose(images, (0, 2, 3, 1)) - for i in range(images.shape[0]): - image = [data_transforms(Image.fromarray(images[i])) for j in range(n_views)] - file_path = os.path.join(savefile_path, "Simclr_prep_" + str(file_num) + ".bin") - file_num = file_num + 1 - print(i) - image_file = np.array(image[0]).astype(np.float32) - image_file.tofile(file_path) - file_path = os.path.join(savefile_path, "Simclr_prep_" + str(file_num) + ".bin") - image_file = np.array(image[1]).astype(np.float32) - image_file.tofile(file_path) - file_num = file_num + 1 - - -if __name__ == "__main__": - src_path = sys.argv[1] - save_path = sys.argv[2] - preprocess(src_path, save_path) +""" +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" + +import numpy as np +from torchvision import transforms +import torch +from torch import nn +import os +from PIL import Image +import sys +import pickle + + +class GaussianBlur(object): + """blur a single image on CPU""" + def __init__(self, kernel_size): + radias = kernel_size // 2 + kernel_size = radias * 2 + 1 + self.blur_h = nn.Conv2d(3, 3, kernel_size=(kernel_size, 1), + stride=1, padding=0, bias=False, groups=3) + self.blur_v = nn.Conv2d(3, 3, kernel_size=(1, kernel_size), + stride=1, padding=0, bias=False, groups=3) + self.k = kernel_size + self.r = radias + + self.blur = nn.Sequential( + nn.ReflectionPad2d(radias), + self.blur_h, + self.blur_v + ) + + self.pil_to_tensor = transforms.ToTensor() + self.tensor_to_pil = transforms.ToPILImage() + + def __call__(self, img): + img = self.pil_to_tensor(img).unsqueeze(0) + + sigma = np.random.uniform(0.1, 2.0) + x = np.arange(-self.r, self.r + 1) + x = np.exp(-np.power(x, 2) / (2 * sigma * sigma)) + x = x / x.sum() + x = torch.from_numpy(x).view(1, -1).repeat(3, 1) + + self.blur_h.weight.data.copy_(x.view(3, 1, self.k, 1)) + self.blur_v.weight.data.copy_(x.view(3, 1, 1, self.k)) + + with torch.no_grad(): + img = self.blur(img) + img = img.squeeze() + + img = self.tensor_to_pil(img) + + return img + + +def preprocess(srcfile_path, savefile_path): + """ data preprocess """ + size = 32 + s = 1 + n_views = 2 + file_num = 0 + data = [] + color_jitter = transforms.ColorJitter(0.8 * s, 0.8 * s, 0.8 * s, 0.2 * s) + data_transforms = transforms.Compose([transforms.RandomResizedCrop(size=size), + transforms.RandomHorizontalFlip(), + transforms.RandomApply([color_jitter], p=0.8), + transforms.RandomGrayscale(p=0.2), + GaussianBlur(kernel_size=int(0.1 * size)), + transforms.ToTensor()]) + if not os.path.exists(savefile_path): + os.mkdir(savefile_path) + with open(srcfile_path, "rb") as f: + entry = pickle.load(f, encoding='latin1') + data.append(entry['data']) + images = np.vstack(data).reshape(-1, 3, 32, 32) + images = np.transpose(images, (0, 2, 3, 1)) + for i in range(images.shape[0]): + image = [data_transforms(Image.fromarray(images[i])) for j in range(n_views)] + file_path = os.path.join(savefile_path, "Simclr_prep_" + str(file_num) + ".bin") + file_num = file_num + 1 + print(i) + image_file = np.array(image[0]).astype(np.float32) + image_file.tofile(file_path) + file_path = os.path.join(savefile_path, "Simclr_prep_" + str(file_num) + ".bin") + image_file = np.array(image[1]).astype(np.float32) + image_file.tofile(file_path) + file_num = file_num + 1 + + +if __name__ == "__main__": + src_path = sys.argv[1] + save_path = sys.argv[2] + preprocess(src_path, save_path) diff --git a/ACL_PyTorch/contrib/cv/classfication/SimCLR_inference/Simclr_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/SimCLR_inference/Simclr_pth2onnx.py index a3141e636f498bfc0bdd47d546b577d8b0752cb6..17a6214854fbbd9e375f06acdfb18122dfe7242d 100644 --- a/ACL_PyTorch/contrib/cv/classfication/SimCLR_inference/Simclr_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/SimCLR_inference/Simclr_pth2onnx.py @@ -1,79 +1,79 @@ -""" -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -""" - -import torch -import sys -import torch.nn as nn -import torchvision.models as models - - -class BaseSimCLRException(Exception): - """Base exception""" - - -class InvalidBackboneError(BaseSimCLRException): - """Raised when the choice of backbone Convnet is invalid.""" - - -class InvalidDatasetSelection(BaseSimCLRException): - """Raised when the choice of dataset is invalid.""" - -class ResNetSimCLR(nn.Module): - """ Simclr model """ - def __init__(self, base_model, out_dim): - super(ResNetSimCLR, self).__init__() - self.resnet_dict = {"resnet18": models.resnet18(pretrained=False, num_classes=out_dim), - "resnet50": models.resnet50(pretrained=False, num_classes=out_dim)} - - self.backbone = self._get_basemodel(base_model) - dim_mlp = self.backbone.fc.in_features - - # add mlp projection head - self.backbone.fc = nn.Sequential(nn.Linear(dim_mlp, dim_mlp), nn.ReLU(), self.backbone.fc) - - def _get_basemodel(self, model_name): - try: - model = self.resnet_dict[model_name] - except KeyError: - raise InvalidBackboneError( - "Invalid backbone architecture. Check the config file and pass one of: resnet18 or resnet50") - else: - return model - - def forward(self, x): - """forward """ - return self.backbone(x) - - -def pth2onnx(input_file, output_file): - """pth to onnx""" - checkpoint = torch.load(input_file, map_location='cpu') - model = ResNetSimCLR(base_model='resnet18', out_dim=128) - model.load_state_dict(checkpoint["state_dict"]) - model.eval() - - input_name = ["input"] - output_name = ["output"] - - dummy_input = torch.randn(1, 3, 32, 32) - torch.onnx.export(model, dummy_input, output_file, input_names=input_name, output_names=output_name, verbose=True) - - -if __name__ == "__main__": - input_pth = sys.argv[1] - output = sys.argv[2] - pth2onnx(input_pth, output) - +""" +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" + +import torch +import sys +import torch.nn as nn +import torchvision.models as models + + +class BaseSimCLRException(Exception): + """Base exception""" + + +class InvalidBackboneError(BaseSimCLRException): + """Raised when the choice of backbone Convnet is invalid.""" + + +class InvalidDatasetSelection(BaseSimCLRException): + """Raised when the choice of dataset is invalid.""" + +class ResNetSimCLR(nn.Module): + """ Simclr model """ + def __init__(self, base_model, out_dim): + super(ResNetSimCLR, self).__init__() + self.resnet_dict = {"resnet18": models.resnet18(pretrained=False, num_classes=out_dim), + "resnet50": models.resnet50(pretrained=False, num_classes=out_dim)} + + self.backbone = self._get_basemodel(base_model) + dim_mlp = self.backbone.fc.in_features + + # add mlp projection head + self.backbone.fc = nn.Sequential(nn.Linear(dim_mlp, dim_mlp), nn.ReLU(), self.backbone.fc) + + def _get_basemodel(self, model_name): + try: + model = self.resnet_dict[model_name] + except KeyError: + raise InvalidBackboneError( + "Invalid backbone architecture. Check the config file and pass one of: resnet18 or resnet50") + else: + return model + + def forward(self, x): + """forward """ + return self.backbone(x) + + +def pth2onnx(input_file, output_file): + """pth to onnx""" + checkpoint = torch.load(input_file, map_location='cpu') + model = ResNetSimCLR(base_model='resnet18', out_dim=128) + model.load_state_dict(checkpoint["state_dict"]) + model.eval() + + input_name = ["input"] + output_name = ["output"] + + dummy_input = torch.randn(1, 3, 32, 32) + torch.onnx.export(model, dummy_input, output_file, input_names=input_name, output_names=output_name, verbose=True) + + +if __name__ == "__main__": + input_pth = sys.argv[1] + output = sys.argv[2] + pth2onnx(input_pth, output) + diff --git a/ACL_PyTorch/contrib/cv/classfication/SimCLR_inference/test/parse.py b/ACL_PyTorch/contrib/cv/classfication/SimCLR_inference/test/parse.py index b17c1e0d8299f912b49c06bce07d8ca26d83ea07..178bbb3fd36cf0437245470312a8595b37f878b6 100644 --- a/ACL_PyTorch/contrib/cv/classfication/SimCLR_inference/test/parse.py +++ b/ACL_PyTorch/contrib/cv/classfication/SimCLR_inference/test/parse.py @@ -1,31 +1,31 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.log'): - result_log = sys.argv[1] - with open(result_log, 'r') as f: - lines = f.readlines() - RSNR_Res = lines[-1] - print(RSNR_Res.replace('\n', '')) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.log'): + result_log = sys.argv[1] + with open(result_log, 'r') as f: + lines = f.readlines() + RSNR_Res = lines[-1] + print(RSNR_Res.replace('\n', '')) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Sknet50/LICENSE b/ACL_PyTorch/contrib/cv/classfication/Sknet50/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Sknet50/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/Sknet50/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Sknet50/README.md b/ACL_PyTorch/contrib/cv/classfication/Sknet50/README.md index a73c1aea8c99a6200dd3960b507f47fdace0240a..64006615112c8a72798d7b04a3bed4a230edf337 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Sknet50/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/Sknet50/README.md @@ -1,269 +1,269 @@ -# SK-ResNet50 Onnx 模型端到端推理指导 - -- [1. 模型概述](#1) - - [论文地址](#11) - - [代码地址](#12) -- [2. 环境说明](#2) - - [深度学习框架](#21) - - [python第三方库](#22) -- [3. 模型转换](#3) - - [pth转onnx模型](#31) -- [4. 数据预处理](#4) - - [数据集获取](#41) - - [数据集预处理](#42) - - [生成数据集信息文件](#43) -- [5. 离线推理](#5) - - [benchmark工具概述](#51) - - [离线推理](#52) -- [6. 精度对比](#6) - - [离线推理TopN精度](#61) - - [精度对比](#62) -- [7. 性能对比](#7) - - [npu性能数据](#71) - -## 1. 模型概述 - -### 1.1 论文地址 - -[SK-ResNet 论文](https://arxiv.org/pdf/1903.06586.pdf) - -### 1.2 代码地址 - -[SK-ResNet 代码](https://github.com/implus/PytorchInsight) - -branch: master - -commit_id: 2864528f8b83f52c3df76f7c3804aa468b91e5cf - -## 2. 环境说明 - -### 2.1 深度学习框架 - -``` -pytorch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.9.0 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.19.2 -Pillow == 8.2.0 -opencv-python == 4.5.2 -``` - -> **说明:** -> -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3. 模型转换 - -### 3.1 pth转onnx模型 - -1. 下载 pth 权重文件 - - [SK-ResNet50预训练pth权重文件(百度网盘,提取码:tfwn)](https://pan.baidu.com/s/1Lx5CNUeRQXOSWjzTlcO2HQ) - - 文件名:sk_resnet50.pth.tar - - md5sum:979bbb525ee0898003777a8e663e91c0 - -2. 克隆代码仓库代码 - - ```bash - git clone https://github.com/implus/PytorchInsight.git - ``` - -3. 使用 sknet2onnx.py 转换pth为onnx文件,在命令行运行如下指令: - - ```bash - python3.7 sknet2onnx.py --pth sk_resnet50.pth.tar --onnx sknet50_bs1 - ``` - - sk_resnet50.pth.tar文件为步骤1中下载的预训练权重文件,该条指令将在运行处生成一个sknet50_bs1文件,此文件即为目标onnx文件 - -**模型转换要点:** - -> pytorch导出onnx时softmax引入了transpose以操作任意轴,然而在onnx中已支持softmax操作任意轴,故可删除transpose提升性能 - -### 3.2 onnx转om模型 - -下列需要在具备华为Ascend系列芯片的机器上执行: - -1. 设置 atc 工作所需要的环境变量 - - ```bash - export install_path=/usr/local/Ascend/ascend-toolkit/latest - export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH - export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH - export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH - export ASCEND_OPP_PATH=${install_path}/opp - ``` - -2. 使用atc工具将onnx模型转换为om模型,命令参考 - - ```bash - atc --framework=5 --model=sknet50.onnx --output=sknet50_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 - ``` - - 此命令将在运行路径下生成一个sknet50_1bs.om文件,此文件即为目标om模型文件 - -## 4. 数据预处理 - -### 4.1 数据集获取 - -该模型使用[ImageNet官网](http://www.image-net.org/)的5万张验证集进行测试,图片与标签分别存放在/opt/npu/imagenet/val与/opt/npu/imagenet/val_label.txt。 - -### 4.2 数据集预处理 - -使用 sknet_preprocess.py 脚本进行数据预处理,脚本执行命令: - -```bash -python3.7 sknet_preprocess.py -s /opt/npu/imagenet/val -d ./prep_data -``` - -### 4.3 生成数据集信息文件 - -1. 生成数据集信息文件脚本 get_info.py - -2. 执行生成数据集信息脚本,生成数据集信息文件 - - ```bash - python3.7 get_info.py bin ./prep_data ./sknet_prep_bin.info 224 224 - ``` - - 第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 - -## 5. 离线推理 - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN V100R020C10 推理benchmark工具用户指南 01 - -### 5.2 离线推理 - -```bash -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=sknet50_bs1.om -input_text_path=sknet_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False -``` - -输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 - -## 6. 精度对比 - -### 6.1 离线推理TopN精度 - -后处理统计TopN精度,调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中: - -```bash -python3.7 vision_metric_ImageNet.py result/dumpOutput_device0/ ../data/sknet/val_label.txt ./ result.json -``` - -第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。查看输出结果: - -```json -{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "77.54%"}, {"key": "Top2 accuracy", "value": "87.12%"}, {"key": "Top3 accuracy", "value": "90.73%"}, {"key": "Top4 accuracy", "value": "92.55%"}, {"key": "Top5 accuracy", "value": "93.71%"}]} -``` - -经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 - -### 6.2 精度对比 - -| | TOP1 | TOP5 | -| :----------------: | :------: | :------: | -| 原github仓库精度 | 77.5380% | 93.7000% | -| om模型离线推理精度 | 77.54% | 93.71% | - -将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 - -## 7. 性能对比 - -### 7.1 npu性能数据 - -benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 - -benchmark工具作纯推理时使用的命令参考如下: - -```bash -./benchmark.x86_64 -round=20 -om_path=sknet50_bs1.om -batch_size=1 -``` - -1. batch1 性能 - - 使用benchmark工具在整个数据集上推理时获得的性能数据: - - ``` - [e2e] throughputRate: 143.402, latency: 348669 - [data read] throughputRate: 152.003, moduleLatency: 6.57881 - [preprocess] throughputRate: 151.416, moduleLatency: 6.60433 - [infer] throughputRate: 143.733, Interface throughputRate: 210.306, moduleLatency: 6.16176 - [post] throughputRate: 143.732, moduleLatency: 6.95737 - ``` - - Interface throughputRate: 210.306 * 4 = 841.224 即是batch1 310单卡吞吐率 - -2. batch4 性能 - - ``` - [INFO] ave_throughputRate: 315.424samples/s, ave_latency: 3.30141ms - ``` - - Interface throughputRate: 315.424 * 4 = 1261.696 即是batch4 310单卡吞吐率 - -3. batch8 性能 - - ``` - [INFO] ave_throughputRate: 365.813samples/s, ave_latency: 2.76526ms - ``` - - Interface throughputRate: 365.813 * 4 = 1463.252 即是batch8 310单卡吞吐率 - -4. batch16 性能 - - ``` - [e2e] throughputRate: 196.399, latency: 254584 - [data read] throughputRate: 208.891, moduleLatency: 4.78718 - [preprocess] throughputRate: 207.779, moduleLatency: 4.81281 - [infer] throughputRate: 197.514, Interface throughputRate: 392.072, modul - [post] throughputRate: 12.3443, moduleLatency: 81.0088 - ``` - - Interface throughputRate: 392.072 * 4 = 1568.288 即是batch16 310单卡吞吐率 - -5. batch32 性能 - - ``` - [INFO] ave_throughputRate: 376.691samples/s, ave_latency: 2.66319ms - ``` - - Interface throughputRate: 376.691 * 4 = 1506.764 即是batch32 310单卡吞吐率 - -**性能优化** - -> 从profiling数据的op_statistic_0_1.csv看出影响性能的是transpose算子,从onnx结构图看出该算子用于实现softmax任意轴,由pytorch导出时引入,然而softmax在onnx中现已支持任意轴,故可直接删除该算子提升性能,删除代码参考如下: - -```python -model = onnx.load(args.onnx+'.onnx') -graph = model.graph -node = graph.node -softmax_node_index = [] -del_group = [] -for i in range(len(node)): - if node[i].op_type == 'Softmax': - del_group.append((node[i-1], node[i], node[i+1], i)) -for g in del_group: - new_input = g[0].input - new_output = g[2].output - new_name = g[1].name - new_index = g[3] - new_node = onnx.helper.make_node("Softmax", new_input, new_output, new_name, axis=1) - for n in g[:-1]: - graph.node.remove(n) - graph.node.insert(new_index, new_node) -onnx.save(model, args.onnx+'.onnx') -``` - - - +# SK-ResNet50 Onnx 模型端到端推理指导 + +- [1. 模型概述](#1) + - [论文地址](#11) + - [代码地址](#12) +- [2. 环境说明](#2) + - [深度学习框架](#21) + - [python第三方库](#22) +- [3. 模型转换](#3) + - [pth转onnx模型](#31) +- [4. 数据预处理](#4) + - [数据集获取](#41) + - [数据集预处理](#42) + - [生成数据集信息文件](#43) +- [5. 离线推理](#5) + - [benchmark工具概述](#51) + - [离线推理](#52) +- [6. 精度对比](#6) + - [离线推理TopN精度](#61) + - [精度对比](#62) +- [7. 性能对比](#7) + - [npu性能数据](#71) + +## 1. 模型概述 + +### 1.1 论文地址 + +[SK-ResNet 论文](https://arxiv.org/pdf/1903.06586.pdf) + +### 1.2 代码地址 + +[SK-ResNet 代码](https://github.com/implus/PytorchInsight) + +branch: master + +commit_id: 2864528f8b83f52c3df76f7c3804aa468b91e5cf + +## 2. 环境说明 + +### 2.1 深度学习框架 + +``` +pytorch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.9.0 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.19.2 +Pillow == 8.2.0 +opencv-python == 4.5.2 +``` + +> **说明:** +> +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3. 模型转换 + +### 3.1 pth转onnx模型 + +1. 下载 pth 权重文件 + + [SK-ResNet50预训练pth权重文件(百度网盘,提取码:tfwn)](https://pan.baidu.com/s/1Lx5CNUeRQXOSWjzTlcO2HQ) + + 文件名:sk_resnet50.pth.tar + + md5sum:979bbb525ee0898003777a8e663e91c0 + +2. 克隆代码仓库代码 + + ```bash + git clone https://github.com/implus/PytorchInsight.git + ``` + +3. 使用 sknet2onnx.py 转换pth为onnx文件,在命令行运行如下指令: + + ```bash + python3.7 sknet2onnx.py --pth sk_resnet50.pth.tar --onnx sknet50_bs1 + ``` + + sk_resnet50.pth.tar文件为步骤1中下载的预训练权重文件,该条指令将在运行处生成一个sknet50_bs1文件,此文件即为目标onnx文件 + +**模型转换要点:** + +> pytorch导出onnx时softmax引入了transpose以操作任意轴,然而在onnx中已支持softmax操作任意轴,故可删除transpose提升性能 + +### 3.2 onnx转om模型 + +下列需要在具备华为Ascend系列芯片的机器上执行: + +1. 设置 atc 工作所需要的环境变量 + + ```bash + export install_path=/usr/local/Ascend/ascend-toolkit/latest + export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH + export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH + export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH + export ASCEND_OPP_PATH=${install_path}/opp + ``` + +2. 使用atc工具将onnx模型转换为om模型,命令参考 + + ```bash + atc --framework=5 --model=sknet50.onnx --output=sknet50_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=debug --soc_version=Ascend310 + ``` + + 此命令将在运行路径下生成一个sknet50_1bs.om文件,此文件即为目标om模型文件 + +## 4. 数据预处理 + +### 4.1 数据集获取 + +该模型使用[ImageNet官网](http://www.image-net.org/)的5万张验证集进行测试,图片与标签分别存放在/opt/npu/imagenet/val与/opt/npu/imagenet/val_label.txt。 + +### 4.2 数据集预处理 + +使用 sknet_preprocess.py 脚本进行数据预处理,脚本执行命令: + +```bash +python3.7 sknet_preprocess.py -s /opt/npu/imagenet/val -d ./prep_data +``` + +### 4.3 生成数据集信息文件 + +1. 生成数据集信息文件脚本 get_info.py + +2. 执行生成数据集信息脚本,生成数据集信息文件 + + ```bash + python3.7 get_info.py bin ./prep_data ./sknet_prep_bin.info 224 224 + ``` + + 第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 + +## 5. 离线推理 + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN V100R020C10 推理benchmark工具用户指南 01 + +### 5.2 离线推理 + +```bash +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=sknet50_bs1.om -input_text_path=sknet_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +``` + +输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 + +## 6. 精度对比 + +### 6.1 离线推理TopN精度 + +后处理统计TopN精度,调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中: + +```bash +python3.7 vision_metric_ImageNet.py result/dumpOutput_device0/ ../data/sknet/val_label.txt ./ result.json +``` + +第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。查看输出结果: + +```json +{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "77.54%"}, {"key": "Top2 accuracy", "value": "87.12%"}, {"key": "Top3 accuracy", "value": "90.73%"}, {"key": "Top4 accuracy", "value": "92.55%"}, {"key": "Top5 accuracy", "value": "93.71%"}]} +``` + +经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 + +### 6.2 精度对比 + +| | TOP1 | TOP5 | +| :----------------: | :------: | :------: | +| 原github仓库精度 | 77.5380% | 93.7000% | +| om模型离线推理精度 | 77.54% | 93.71% | + +将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + +## 7. 性能对比 + +### 7.1 npu性能数据 + +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 + +benchmark工具作纯推理时使用的命令参考如下: + +```bash +./benchmark.x86_64 -round=20 -om_path=sknet50_bs1.om -batch_size=1 +``` + +1. batch1 性能 + + 使用benchmark工具在整个数据集上推理时获得的性能数据: + + ``` + [e2e] throughputRate: 143.402, latency: 348669 + [data read] throughputRate: 152.003, moduleLatency: 6.57881 + [preprocess] throughputRate: 151.416, moduleLatency: 6.60433 + [infer] throughputRate: 143.733, Interface throughputRate: 210.306, moduleLatency: 6.16176 + [post] throughputRate: 143.732, moduleLatency: 6.95737 + ``` + + Interface throughputRate: 210.306 * 4 = 841.224 即是batch1 310单卡吞吐率 + +2. batch4 性能 + + ``` + [INFO] ave_throughputRate: 315.424samples/s, ave_latency: 3.30141ms + ``` + + Interface throughputRate: 315.424 * 4 = 1261.696 即是batch4 310单卡吞吐率 + +3. batch8 性能 + + ``` + [INFO] ave_throughputRate: 365.813samples/s, ave_latency: 2.76526ms + ``` + + Interface throughputRate: 365.813 * 4 = 1463.252 即是batch8 310单卡吞吐率 + +4. batch16 性能 + + ``` + [e2e] throughputRate: 196.399, latency: 254584 + [data read] throughputRate: 208.891, moduleLatency: 4.78718 + [preprocess] throughputRate: 207.779, moduleLatency: 4.81281 + [infer] throughputRate: 197.514, Interface throughputRate: 392.072, modul + [post] throughputRate: 12.3443, moduleLatency: 81.0088 + ``` + + Interface throughputRate: 392.072 * 4 = 1568.288 即是batch16 310单卡吞吐率 + +5. batch32 性能 + + ``` + [INFO] ave_throughputRate: 376.691samples/s, ave_latency: 2.66319ms + ``` + + Interface throughputRate: 376.691 * 4 = 1506.764 即是batch32 310单卡吞吐率 + +**性能优化** + +> 从profiling数据的op_statistic_0_1.csv看出影响性能的是transpose算子,从onnx结构图看出该算子用于实现softmax任意轴,由pytorch导出时引入,然而softmax在onnx中现已支持任意轴,故可直接删除该算子提升性能,删除代码参考如下: + +```python +model = onnx.load(args.onnx+'.onnx') +graph = model.graph +node = graph.node +softmax_node_index = [] +del_group = [] +for i in range(len(node)): + if node[i].op_type == 'Softmax': + del_group.append((node[i-1], node[i], node[i+1], i)) +for g in del_group: + new_input = g[0].input + new_output = g[2].output + new_name = g[1].name + new_index = g[3] + new_node = onnx.helper.make_node("Softmax", new_input, new_output, new_name, axis=1) + for n in g[:-1]: + graph.node.remove(n) + graph.node.insert(new_index, new_node) +onnx.save(model, args.onnx+'.onnx') +``` + + + diff --git a/ACL_PyTorch/contrib/cv/classfication/Sknet50/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/Sknet50/requirements.txt index 399dbfed087e9d139235f30e8d5991e803b92edd..fbd453de267138a05ccf06d3be32a3d4eb8f68fc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Sknet50/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/Sknet50/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.9.0 -numpy == 1.19.2 -Pillow == 8.2.0 +torch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.9.0 +numpy == 1.19.2 +Pillow == 8.2.0 opencv-python == 4.5.2 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Sknet50/test/README.md b/ACL_PyTorch/contrib/cv/classfication/Sknet50/test/README.md index 11114dc96f8f052a117be63cd87441091f6d8bcd..3c3e2de286d9f49d0c19321e6b03c9a0578372c8 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Sknet50/test/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/Sknet50/test/README.md @@ -1,26 +1,26 @@ -环境准备: - -1.数据集路径 -数据集统一放在/root/datasets/或/opt/npu/ -本模型数据集放在/opt/npu/ - -2.进入工作目录 -cd Sknet50 - -3.安装必要的依赖 -pip3.7 install -r requirements.txt - -4.获取模型代码 -git clone https://github.com/implus/PytorchInsight - -5.如果使用补丁文件修改了模型代码则将补丁打入模型代码,如果需要引用模型代码仓的类或函数通过sys.path.append()添加搜索路径。 - -5.获取权重文件 -[SK-ResNet50预训练pth权重文件(百度网盘,提取码:tfwn)](https://pan.baidu.com/s/1Lx5CNUeRQXOSWjzTlcO2HQ) - -7.获取benchmark工具 -将benchmark.x86_64放在当前目录 - -8.310上执行,执行时确保device空闲 -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets +环境准备: + +1.数据集路径 +数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集放在/opt/npu/ + +2.进入工作目录 +cd Sknet50 + +3.安装必要的依赖 +pip3.7 install -r requirements.txt + +4.获取模型代码 +git clone https://github.com/implus/PytorchInsight + +5.如果使用补丁文件修改了模型代码则将补丁打入模型代码,如果需要引用模型代码仓的类或函数通过sys.path.append()添加搜索路径。 + +5.获取权重文件 +[SK-ResNet50预训练pth权重文件(百度网盘,提取码:tfwn)](https://pan.baidu.com/s/1Lx5CNUeRQXOSWjzTlcO2HQ) + +7.获取benchmark工具 +将benchmark.x86_64放在当前目录 + +8.310上执行,执行时确保device空闲 +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets diff --git a/ACL_PyTorch/contrib/cv/classfication/Sknet50/test/parse.py b/ACL_PyTorch/contrib/cv/classfication/Sknet50/test/parse.py index b9c74f41d7848e1250356f14472b237a18bb3489..82af69cd183218c3263723c20b652b3f7ec2bc27 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Sknet50/test/parse.py +++ b/ACL_PyTorch/contrib/cv/classfication/Sknet50/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/TNT/README.md b/ACL_PyTorch/contrib/cv/classfication/TNT/README.md index 9debc2c022fdb214d9b48ff02b39efbb43d37926..68b21918df519274f2ac957d5b461ba1e62924c6 100644 --- a/ACL_PyTorch/contrib/cv/classfication/TNT/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/TNT/README.md @@ -1,44 +1,44 @@ -# TNT模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -``` -pip3.7 install -r requirements.txt -``` - - -2.获取,修改与安装开源模型代码 -``` -git clone https://github.com/huawei-noah/CV-Backbones.git -cd CV-Backbones -git checkout 7a0760f0b77c2e9ae585dcadfd34ff7575839ace -patch tnt_pytorch/tnt.py ../TNT.patch -cd .. -cp CV-Backbones/tnt_pytorch/tnt.py . -``` - -3.获取权重文件 - -tnt_s_81.5.pth.tar - -4.数据集 -获取ImageNet 2012 - -5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) -将benchmark.x86_64或benchmark.aarch64放到当前目录 - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets -``` - **评测结果:** -| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| :------: | :------: | :------: | :------: | :------: | -| TNT bs1 | [rank1:81.5%](https://github.com/huawei-noah/CV-Backbones/tree/master/tnt_pytorch) | rank1:81.5% | 89fps | 33fps | -| TNT bs16 | [rank1:81.5%](https://github.com/huawei-noah/CV-Backbones/tree/master/tnt_pytorch) | rank1:81.5% | 181fps| 83fps | - - +# TNT模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip3.7 install -r requirements.txt +``` + + +2.获取,修改与安装开源模型代码 +``` +git clone https://github.com/huawei-noah/CV-Backbones.git +cd CV-Backbones +git checkout 7a0760f0b77c2e9ae585dcadfd34ff7575839ace +patch tnt_pytorch/tnt.py ../TNT.patch +cd .. +cp CV-Backbones/tnt_pytorch/tnt.py . +``` + +3.获取权重文件 + +tnt_s_81.5.pth.tar + +4.数据集 +获取ImageNet 2012 + +5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) +将benchmark.x86_64或benchmark.aarch64放到当前目录 + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets +``` + **评测结果:** +| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| :------: | :------: | :------: | :------: | :------: | +| TNT bs1 | [rank1:81.5%](https://github.com/huawei-noah/CV-Backbones/tree/master/tnt_pytorch) | rank1:81.5% | 89fps | 33fps | +| TNT bs16 | [rank1:81.5%](https://github.com/huawei-noah/CV-Backbones/tree/master/tnt_pytorch) | rank1:81.5% | 181fps| 83fps | + + diff --git a/ACL_PyTorch/contrib/cv/classfication/TNT/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/TNT/modelzoo_level.txt index 38700fca05402f52c3ae1c4be0889eb60e1f80f1..2e42553460a4f3687654b6ad3f91ab0bcc3aadac 100644 --- a/ACL_PyTorch/contrib/cv/classfication/TNT/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/TNT/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/TResNet/LICENSE b/ACL_PyTorch/contrib/cv/classfication/TResNet/LICENSE index 26aed103da3d9c1ee453d7cae8904e91cf0d4815..33a78d69acf137ad8a7d7236218b4ea3b8b9d0e2 100644 --- a/ACL_PyTorch/contrib/cv/classfication/TResNet/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/TResNet/LICENSE @@ -1,25 +1,25 @@ -BSD 3-Clause License - -Copyright (c) 2018, Multimedia Laboratary, The Chinese University of Hong Kong -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +BSD 3-Clause License + +Copyright (c) 2018, Multimedia Laboratary, The Chinese University of Hong Kong +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/TResNet/README.md b/ACL_PyTorch/contrib/cv/classfication/TResNet/README.md index b0453f5fb76ff3ae6b3f73198d568ada7c37e371..4e4d1bf3efd59b838014e8e6cc259ad25760631c 100644 --- a/ACL_PyTorch/contrib/cv/classfication/TResNet/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/TResNet/README.md @@ -1,37 +1,37 @@ -# TResNet离线推理指导 - -## 1.环境准备 -以路径${MODEL_ZOO_PATH}/contrib/ACL_PyTorch/Research/cv/classification/TResNet/作为当前目录 - -1.安装必备的依赖 - -``` -pip3.7 install -r requirements.txt -``` - -2.由于没有开源社区的权重,因此需要将训练得到的权重model_best.pth.tar放到当前目录 - -3.获取数据集imagenet,并且以${Path}/imagenet/val作为datasets_path,这将在下面用到 - -4.获取数据集imagenet的val_label.txt,并且以${Path}/val_label.txt作为val_label_path,这将在下面用到 - -5.获取benchmark工具 - -将benchmark.x86_64放到当前目录 - -6.(重要)请确保您的CANN环境为5.0.3.alpha003,以确保能获得最佳性能 - -7.(重要)由于有算子涉及到了TransposeD,因此请将以下shape添加至白名单[ 1,3, 224, 224],[ 1, 3, 56, 4, 56, 4],[ 1, 4, 4, 3, 56, 56], - [ 16, 3, 224, 224],[ 16, 3, 56, 4, 56, 4], [ 16, 4, 4, 3, 56, 56] -8.请确保您能连接github以获取模型源码 - -## 2.离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 - -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets/imagenet/val --val_label_path=/root/datasets/imagenet/val_label.txt -bash test/perf_g.sh -``` - +# TResNet离线推理指导 + +## 1.环境准备 +以路径${MODEL_ZOO_PATH}/contrib/ACL_PyTorch/Research/cv/classification/TResNet/作为当前目录 + +1.安装必备的依赖 + +``` +pip3.7 install -r requirements.txt +``` + +2.由于没有开源社区的权重,因此需要将训练得到的权重model_best.pth.tar放到当前目录 + +3.获取数据集imagenet,并且以${Path}/imagenet/val作为datasets_path,这将在下面用到 + +4.获取数据集imagenet的val_label.txt,并且以${Path}/val_label.txt作为val_label_path,这将在下面用到 + +5.获取benchmark工具 + +将benchmark.x86_64放到当前目录 + +6.(重要)请确保您的CANN环境为5.0.3.alpha003,以确保能获得最佳性能 + +7.(重要)由于有算子涉及到了TransposeD,因此请将以下shape添加至白名单[ 1,3, 224, 224],[ 1, 3, 56, 4, 56, 4],[ 1, 4, 4, 3, 56, 56], + [ 16, 3, 224, 224],[ 16, 3, 56, 4, 56, 4], [ 16, 4, 4, 3, 56, 56] +8.请确保您能连接github以获取模型源码 + +## 2.离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 + +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets/imagenet/val --val_label_path=/root/datasets/imagenet/val_label.txt +bash test/perf_g.sh +``` + diff --git a/ACL_PyTorch/contrib/cv/classfication/TResNet/TResNet_postprocess.py b/ACL_PyTorch/contrib/cv/classfication/TResNet/TResNet_postprocess.py index 7b1037e75d6a864736eb4748c8ef4ada1a956f23..60747729428f9cfe8f384473480251bf21352120 100644 --- a/ACL_PyTorch/contrib/cv/classfication/TResNet/TResNet_postprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/TResNet/TResNet_postprocess.py @@ -1,184 +1,184 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - if data == '': - n_label = 0 - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - print(table_dict) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - print("Time used:", elapsed) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + print(table_dict) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) diff --git a/ACL_PyTorch/contrib/cv/classfication/TResNet/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/TResNet/modelzoo_level.txt index 731399223951dc50392319c2f4e8e5245174c192..108cc882d65c41bd354b9c6373bcf882d112c26b 100644 --- a/ACL_PyTorch/contrib/cv/classfication/TResNet/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/TResNet/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:PERFECT \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/LICENSE b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/LICENSE index 67596b0702591a6b19013c126a71cccce4100591..3d332846513a88288e46b761887e8fc21804f4c4 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/README.md b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/README.md index 11c40ae3542131ae55f1089250b645fbde7540eb..054e47f9cafaf848f57f747967a1123aadac2ddf 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/README.md @@ -1,313 +1,531 @@ -# Wide_ResNet101_2 Onnx模型端到端推理指导 - -- [1 模型概述](#1-模型概述) - - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) - -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) - -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) - -- [4 数据集预处理](#4-数据集预处理) - - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) - -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) - -- [6 精度对比](#6-精度对比) - - [6.1 离线推理精度统计](#61-离线推理精度统计) - - [6.2 开源精度](#62-开源精度) - - [6.3 精度对比](#63-精度对比) - -- [7 性能对比](#7-性能对比) - - - [7.1 npu性能数据](#71-npu性能数据) - - - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 - -[Wide_ResNet论文](https://arxiv.org/pdf/1605.07146.pdf) - -### 1.2 代码地址 - -[Wide_ResNet代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) - -branch:master -commit id:7d955df73fe0e9b47f7d6c77c699324b256fc41f - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 - -``` -CANN 5.0.1 - -pytorch >= 1.5.0 -torchvision >= 0.6.0 -onnx >= 1.7.0 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.18.5 -Pillow == 7.2.0 -opencv-python == 4.2.0.34 -``` - -**说明:** -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 - -1. 下载pth权重文件 - -[wrn101_2权重文件下载](https://download.pytorch.org/models/wide_resnet101_2-32ee1156.pth) - -文件md5sum: 5961435974bb43104b5a3180fea7c2c4 - -``` -wget https://download.pytorch.org/models/wide_resnet101_2-32ee1156.pth -``` - - - -2. 下载模型代码 - -``` -git clone https://github.com/pytorch/vision -cd vision -git reset 7d955df73fe0e9b47f7d6c77c699324b256fc41f --hard -python3.7 setup.py install -cd .. -``` - -3. 编写pth2onnx脚本wrn101_2_pth2onnx.py - - **说明:** ->注意目前ATC支持的onnx算子版本为11 - -4. 执行pth2onnx脚本,生成onnx模型文件 - - -```python -python3.7 wrn101_2_pth2onnx.py wide_resnet101_2-32ee1156.pth wrn101_2_pth.onnx -``` - - **模型转换要点:** ->此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 - -### 3.2 onnx转om模型 - -1.设置环境变量 - -```python -source env.sh -``` -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 - -```python -atc --framework=5 --model=wrn101_2_pth.onnx --output=wrn101_2_bs16 --input_format=NCHW --input_shape="image:16,3,224,224" --log=debug --soc_version=Ascend310 -``` - - - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/opt/npu/imagenet/val与/opt/npu/imagenet/val_label.txt - -### 4.2 数据集预处理 - -1.预处理脚本imagenet_torch_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 - -``` -python3.7 imagenet_torch_preprocess.py resnet /opt/npu/imagenet/val ./prep_dataset -``` -### 4.3 生成数据集信息文件 - -1.生成数据集信息文件脚本gen_dataset_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 - -```python -python3.7 gen_dataset_info.py bin ./prep_dataset ./wrn101_2_prep_bin.info 224 224 -``` -第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 - -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN V100R020C10 推理benchmark工具用户指南 01 - -### 5.2 离线推理 - -1.设置环境变量 - -``` -source env.sh -``` -2.执行离线推理 - -```python -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=wrn101_2_bs16.om -input_text_path=./wrn101_2_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False -``` -输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 - -## 6 精度对比 - -- **[离线推理精度](#61-离线推理精度)** -- **[开源精度](#62-开源精度)** -- **[精度对比](#63-精度对比)** - -### 6.1 离线推理精度统计 - -后处理统计TopN精度 - -调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 -``` -python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /opt/npu/imagenet/val_label.txt ./ result.json -``` -第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 -查看输出结果: - -``` -{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "78.84%"}, {"key": "Top2 accuracy", "value": "88.41%"}, {"key": "Top3 accuracy", "value": "91.66%"}, {"key": "Top4 accuracy", "value": "93.26%"}, {"key": "Top5 accuracy", "value": "94.29%"}]} -``` - -### 6.2 开源精度 - -[torchvision官网精度](https://pytorch.org/vision/stable/models.html) - -``` -Model Acc@1 Acc@5 -wide_resnet101_2 78.848 94.284 -``` -### 6.3 精度对比 - -将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,统计结果如下。精度下降在1%范围之内,故精度达标。 - -``` - Acc@1 Acc@5 -bs1 78.84 94.29 -bs16 78.85 94.29 -``` - - **精度调试:** - ->没有遇到精度不达标的问题,故不需要进行精度调试 - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** - -### 7.1 npu性能数据 - -benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 - -1.benchmark工具在整个数据集上推理获得性能数据 - -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: - -``` -[e2e] throughputRate: 105.142, latency: 475550 -[data read] throughputRate: 111.355, moduleLatency: 8.98031 -[preprocess] throughputRate: 111.053, moduleLatency: 9.00469 -[infer] throughputRate: 105.494, Interface throughputRate: 127.878, moduleLatency: 8.77965 -[post] throughputRate: 105.494, moduleLatency: 9.47924 -``` - -Interface throughputRate: 127.878,127.878x4=511.512即是batch1 310单卡吞吐率 - -batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: - -``` -[e2e] throughputRate: 117.321, latency: 426182 -[data read] throughputRate: 124.66, moduleLatency: 8.0218 -[preprocess] throughputRate: 124.054, moduleLatency: 8.06101 -[infer] throughputRate: 117.825, Interface throughputRate: 169.604, moduleLatency: 7.35524 -[post] throughputRate: 7.36397, moduleLatency: 135.796 -``` - -Interface throughputRate: 169.604,169.604x4=678.416即是batch1 310单卡吞吐率 - -batch4性能: - -``` -[e2e] throughputRate: 114.374, latency: 437161 -[data read] throughputRate: 121.259, moduleLatency: 8.2468 -[preprocess] throughputRate: 121.014, moduleLatency: 8.26352 -[infer] throughputRate: 114.92, Interface throughputRate: 157.07, moduleLatency: 7.83108 -[post] throughputRate: 28.73, moduleLatency: 34.8068 -``` - -batch4 310单卡吞吐率:157.07x4=628.28fps -batch8性能: - -``` -[e2e] throughputRate: 111.341, latency: 449071 -[data read] throughputRate: 117.759, moduleLatency: 8.49194 -[preprocess] throughputRate: 117.55, moduleLatency: 8.50701 -[infer] throughputRate: 111.703, Interface throughputRate: 156.132, moduleLatency: 7.85466 -[post] throughputRate: 13.9628, moduleLatency: 71.6188 -``` - -batch8 310单卡吞吐率:156.132x4=624.528fps -batch32性能: - -``` -[e2e] throughputRate: 102.387, latency: 488344 -[data read] throughputRate: 108.61, moduleLatency: 9.20728 -[preprocess] throughputRate: 108.389, moduleLatency: 9.22602 -[infer] throughputRate: 102.81, Interface throughputRate: 139.595, moduleLatency: 8.59119 -[post] throughputRate: 3.2138, moduleLatency: 311.159 -``` - -batch32 310单卡吞吐率:139.595x4=558.38fps - -**性能优化:** - -> 对于batch32的性能不达标,从profiling数据的op_statistic_0_1.csv看出影响性能的是Conv2D算子,从op_summary_0_1.csv看出单个Conv_Relu算子耗时0.6毫秒到12毫秒,shape大的耗时就多,不存在优化问题 +# Wide_ResNet101_2 Onnx模型端到端推理指导 + +- [1 模型概述](#1-模型概述) + + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) + +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) + +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) + +- [4 数据集预处理](#4-数据集预处理) + + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) + +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) + +- [6 精度对比](#6-精度对比) + - [6.1 离线推理精度统计](#61-离线推理精度统计) + - [6.2 开源精度](#62-开源精度) + - [6.3 精度对比](#63-精度对比) + +- [7 性能对比](#7-性能对比) + + - [7.1 npu性能数据](#71-npu性能数据) + - [7.2 T4性能数据](#72-T4性能数据) + - [7.3 性能对比](#73-性能对比) + + + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 + +[Wide_ResNet论文](https://arxiv.org/pdf/1605.07146.pdf) + +### 1.2 代码地址 + +[Wide_ResNet代码](https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py) + +branch:master +commit id:7d955df73fe0e9b47f7d6c77c699324b256fc41f + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 + +``` +CANN 5.0.1 + +pytorch >= 1.5.0 +torchvision >= 0.6.0 +onnx >= 1.7.0 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.18.5 +Pillow == 7.2.0 +opencv-python == 4.2.0.34 +``` + +**说明:** +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 + +1. 下载pth权重文件 + +[wrn101_2权重文件下载](https://download.pytorch.org/models/wide_resnet101_2-32ee1156.pth) + +文件md5sum: 5961435974bb43104b5a3180fea7c2c4 + +``` +wget https://download.pytorch.org/models/wide_resnet101_2-32ee1156.pth +``` + + + +2. 下载模型代码 + +``` +git clone https://github.com/pytorch/vision +cd vision +git reset 7d955df73fe0e9b47f7d6c77c699324b256fc41f --hard +python3.7 setup.py install +cd .. +``` + +3. 编写pth2onnx脚本wrn101_2_pth2onnx.py + + **说明:** +>注意目前ATC支持的onnx算子版本为11 + +4. 执行pth2onnx脚本,生成onnx模型文件 + + +```python +python3.7 wrn101_2_pth2onnx.py wide_resnet101_2-32ee1156.pth wrn101_2_pth.onnx +``` + + **模型转换要点:** +>此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 + +### 3.2 onnx转om模型 + +1.设置环境变量 + +```python +source env.sh +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 + +```python +atc --framework=5 --model=wrn101_2_pth.onnx --output=wrn101_2_bs16 --input_format=NCHW --input_shape="image:16,3,224,224" --log=debug --soc_version=Ascend310 +``` + + + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/opt/npu/imagenet/val与/opt/npu/imagenet/val_label.txt + +### 4.2 数据集预处理 + +1.预处理脚本imagenet_torch_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 + +``` +python3.7 imagenet_torch_preprocess.py resnet /opt/npu/imagenet/val ./prep_dataset +``` +### 4.3 生成数据集信息文件 + +1.生成数据集信息文件脚本gen_dataset_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 + +```python +python3.7 gen_dataset_info.py bin ./prep_dataset ./wrn101_2_prep_bin.info 224 224 +``` +第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 + +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN V100R020C10 推理benchmark工具用户指南 01 + +### 5.2 离线推理 + +1.设置环境变量 + +``` +source env.sh +``` +2.执行离线推理 + +```python +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=wrn101_2_bs16.om -input_text_path=./wrn101_2_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +``` +输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 + +## 6 精度对比 + +- **[离线推理精度](#61-离线推理精度)** +- **[开源精度](#62-开源精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理精度统计 + +后处理统计TopN精度 + +调用imagenet_acc_eval.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 +``` +python3.7 imagenet_acc_eval.py result/dumpOutput_device0/ /opt/npu/imagenet/val_label.txt ./ result.json +``` +第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 +查看输出结果: + +``` +{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "78.84%"}, {"key": "Top2 accuracy", "value": "88.41%"}, {"key": "Top3 accuracy", "value": "91.66%"}, {"key": "Top4 accuracy", "value": "93.26%"}, {"key": "Top5 accuracy", "value": "94.29%"}]} +``` + +### 6.2 开源精度 + +[torchvision官网精度](https://pytorch.org/vision/stable/models.html) + +``` +Model Acc@1 Acc@5 +wide_resnet101_2 78.848 94.284 +``` +### 6.3 精度对比 + +将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,统计结果如下。精度下降在1%范围之内,故精度达标。 + +``` + Acc@1 Acc@5 +bs1 78.84 94.29 +bs16 78.85 94.29 +``` + + **精度调试:** + +>没有遇到精度不达标的问题,故不需要进行精度调试 + +## 7 性能对比 + +- **[310npu性能数据](#71-310npu性能数据)** +- **[710npu性能数据](#72-710npu性能数据)** +- **[T4性能数据](#73-T4性能数据)** +- **[性能对比](#73-性能对比)** + +### 7.1 310npu性能数据 + +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 + +1.benchmark工具在整个数据集上推理获得性能数据 + +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: + +``` +[e2e] throughputRate: 105.964, latency: 471859 +[data read] throughputRate: 112.337, moduleLatency: 8.90179 +[preprocess] throughputRate: 111.931, moduleLatency: 8.93404 +[infer] throughputRate: 106.222, Interface throughputRate: 129.018, moduleLatency: 8.70911 +[post] throughputRate: 106.222, moduleLatency: 9.41428 +``` + +Interface throughputRate: 129.018,129.018x4=516.072即是batch1 310单卡吞吐率 + +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: + +``` +[e2e] throughputRate: 119.367, latency: 418876 +[data read] throughputRate: 126.399, moduleLatency: 7.91145 +[preprocess] throughputRate: 126.137, moduleLatency: 7.92786 +[infer] throughputRate: 119.647, Interface throughputRate: 170.965, moduleLatency: 7.27049 +[post] throughputRate: 7.47771, moduleLatency: 133.731 +``` + +Interface throughputRate: 170.965,170.965x4=683.86即是batch1 310单卡吞吐率 + +batch4性能: + +``` +[e2e] throughputRate: 101.852, latency: 490910 +[data read] throughputRate: 107.479, moduleLatency: 9.30415 +[preprocess] throughputRate: 107.138, moduleLatency: 9.33379 +[infer] throughputRate: 102.151, Interface throughputRate: 157.248, moduleLatency: 8.78044 +[post] throughputRate: 25.5375, moduleLatency: 39.1581 +``` + +batch4 310单卡吞吐率:157.248x4=628.992fps +batch8性能: + +``` +[e2e] throughputRate: 106.178, latency: 470906 +[data read] throughputRate: 112.19, moduleLatency: 8.91342 +[preprocess] throughputRate: 111.912, moduleLatency: 8.93559 +[infer] throughputRate: 106.421, Interface throughputRate: 157.434, moduleLatency: 8.37058 +[post] throughputRate: 13.3024, moduleLatency: 75.1742 +``` + +batch8 310单卡吞吐率:157.434x4=629.736fps +batch32性能: + +``` +[e2e] throughputRate: 102.387, latency: 488344 +[data read] throughputRate: 108.61, moduleLatency: 9.20728 +[preprocess] throughputRate: 108.389, moduleLatency: 9.22602 +[infer] throughputRate: 102.81, Interface throughputRate: 139.595, moduleLatency: 8.59119 +[post] throughputRate: 3.2138, moduleLatency: 311.159 +``` + +batch32 310单卡吞吐率:139.595x4=591.376fps + +batch64性能: + +``` +[e2e] throughputRate: 90.2739, latency: 553870 +[data read] throughputRate: 95.3212, moduleLatency: 10.4908 +[preprocess] throughputRate: 95.1398, moduleLatency: 10.5108 +[infer] throughputRate: 90.4519, Interface throughputRate: 125.414, moduleLatency: 9.90415 +[post] throughputRate: 1.41463, moduleLatency: 706.898 +``` + +batch64 310单卡吞吐率:125.414x4=501.656fps + + + +### 7.2 710npu性能数据 + +1.benchmark工具在整个数据集上推理获得性能数据 + +batch1的性能(没有执行aoe),benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: + +``` +[e2e] throughputRate: 195.097, latency: 256282 +[data read] throughputRate: 201.138, moduleLatency: 4.97171 +[preprocess] throughputRate: 200.301, moduleLatency: 4.99249 +[infer] throughputRate: 196.592, Interface throughputRate: 265.092, moduleLatency: 4.45654 +[post] throughputRate: 196.592, moduleLatency: 5.08668 +``` + +Interface throughputRate: 265.092是batch1 710调优前的单卡吞吐率 + + + +batch1的性能(执行aoe),benchmark工具在整个数据集上推理后生成result_aoe/perf_vision_batchsize_1_device_0.txt: + +``` +[e2e] throughputRate: 105.883, latency: 472219 +[data read] throughputRate: 107.982, moduleLatency: 9.26082 +[preprocess] throughputRate: 107.76, moduleLatency: 9.27989 +[infer] throughputRate: 106.271, Interface throughputRate: 465.954, moduleLatency: 7.71249 +[post] throughputRate: 106.27, moduleLatency: 9.40996 +``` + +Interface throughputRate: 465.954是batch1 710调优后的单卡吞吐率 + + + +batch8的性能(没有执行aoe),benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: + +``` +[e2e] throughputRate: 166.691, latency: 299956 +[data read] throughputRate: 167.683, moduleLatency: 5.96365 +[preprocess] throughputRate: 167.347, moduleLatency: 5.97561 +[infer] throughputRate: 167.444, Interface throughputRate: 322.615, moduleLatency: 4.05673 +[post] throughputRate: 20.93, moduleLatency: 47.7783 +``` + +Interface throughputRate: 322.615是batch8 710调优前的单卡吞吐率 + + + +batch8的性能(执行aoe),benchmark工具在整个数据集上推理后生成result_aoe/perf_vision_batchsize_8_device_0.txt: + +``` +[e2e] throughputRate: 144.975, latency: 344886 +[data read] throughputRate: 145.776, moduleLatency: 6.85985 +[preprocess] throughputRate: 145.478, moduleLatency: 6.87388 +[infer] throughputRate: 145.664, Interface throughputRate: 1003.8, moduleLatency: 2.76154 +[post] throughputRate: 18.2077, moduleLatency: 54.922 +``` + +Interface throughputRate: 1003.8是batch8 710调优后的单卡吞吐率 + + + +batch4性能(没有执行aoe): + +``` +[e2e] throughputRate: 179.241, latency: 278954 +[data read] throughputRate: 180.657, moduleLatency: 5.53536 +[preprocess] throughputRate: 180.266, moduleLatency: 5.54736 +[infer] throughputRate: 180.403, Interface throughputRate: 318.947, moduleLatency: 4.10043 +[post] throughputRate: 45.1001, moduleLatency: 22.1729 +``` + +batch4 710调优前的单卡吞吐率:318.947fps + +batch4性能(执行aoe): + +``` +[e2e] throughputRate: 168.435, latency: 296851 +[data read] throughputRate: 169.043, moduleLatency: 5.91564 +[preprocess] throughputRate: 168.686, moduleLatency: 5.92816 +[infer] throughputRate: 169.004, Interface throughputRate: 946.034, moduleLatency: 2.43772 +[post] throughputRate: 42.2506, moduleLatency: 23.6683 +``` + +batch4 710调优后的单卡吞吐率:946.034fps + + + +batch16性能(没有执行aoe): + +``` +[e2e] throughputRate: 243.49, latency: 205347 +[data read] throughputRate: 259.265, moduleLatency: 3.85705 +[preprocess] throughputRate: 257.943, moduleLatency: 3.87683 +[infer] throughputRate: 245.795, Interface throughputRate: 407.177, moduleLatency: 3.29788 +[post] throughputRate: 15.3612, moduleLatency: 65.0991 +``` + +batch16 710调优前的单卡吞吐率:407.177fps + +batch16性能(执行aoe): + +``` +[e2e] throughputRate: 116.841, latency: 427930 +[data read] throughputRate: 117.63, moduleLatency: 8.50121 +[preprocess] throughputRate: 117.471, moduleLatency: 8.51277 +[infer] throughputRate: 117.184, Interface throughputRate: 1001.67, moduleLatency: 3.9011 +[post] throughputRate: 7.32378, moduleLatency: 136.542 +``` + +batch16 710调优后的单卡吞吐率:1001.67fps + + + +batch32性能(没有执行aoe): + +``` +[e2e] throughputRate: 214.139, latency: 233494 +[data read] throughputRate: 215.786, moduleLatency: 4.63422 +[preprocess] throughputRate: 214.711, moduleLatency: 4.65742 +[infer] throughputRate: 215.578, Interface throughputRate: 410.758, moduleLatency: 3.28237 +[post] throughputRate: 6.7386, moduleLatency: 148.399 +``` + +batch32 710调优前的单卡吞吐率:410.758fps + +batch32性能(执行aoe): + +``` +[e2e] throughputRate: 99.8225, latency: 500889 +[data read] throughputRate: 102.585, moduleLatency: 9.74806 +[preprocess] throughputRate: 102.428, moduleLatency: 9.76292 +[infer] throughputRate: 100.129, Interface throughputRate: 895.306, moduleLatency: 4.0268 +[post] throughputRate: 3.12995, moduleLatency: 319.494 +``` + +batch32 710调优后的单卡吞吐率:895.306fps + + + +batch64性能(没有执行aoe): + +``` +[e2e] throughputRate: 188.317, latency: 265509 +[data read] throughputRate: 193.949, moduleLatency: 5.15601 +[preprocess] throughputRate: 193.029, moduleLatency: 5.18057 +[infer] throughputRate: 189.853, Interface throughputRate: 275.251, moduleLatency: 4.45045 +[post] throughputRate: 2.96915, moduleLatency: 336.797 +``` + +batch64 710调优前的单卡吞吐率:275.251fps + +batch64性能(执行aoe): + +``` +[e2e] throughputRate: 99.3163, latency: 503442 +[data read] throughputRate: 99.8186, moduleLatency: 10.0182 +[preprocess] throughputRate: 99.6759, moduleLatency: 10.0325 +[infer] throughputRate: 99.7346, Interface throughputRate: 823.149, moduleLatency: 4.09318 +[post] throughputRate: 1.55981, moduleLatency: 641.103 +``` + +batch64 710调优后的单卡吞吐率:823.149fps + +### 7.3 T4性能数据 + +在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2 + +batch1性能: + +``` +trtexec --onnx=wrn101_2_pth.onnx --fp16 --shapes=image:1x3x224x224 --threads +``` + +gpu T4是4个device并行执行的结果,mean是时延(tensorrt的时延是batch个数据的推理时间),即吞吐率的倒数乘以batch。其中--fp16是算子精度,目前算子精度只测--fp16的。注意--shapes是onnx的输入节点名与shape,当onnx输入节点的batch为-1时,可以用同一个onnx文件测不同batch的性能,否则用固定batch的onnx测不同batch的性能不准 + +batch1 t4单卡吞吐率:244.615fps + +batch16性能: + +``` +trtexec --onnx=wrn101_2_pth.onnx --fp16 --shapes=image:64x3x224x224 --threads +``` + + + +batch4 t4单卡吞吐率:421.312fps + +batch8 t4单卡吞吐率:482.41fps + +batch16 t4单卡吞吐率:538.522fps + +batch32 t4单卡吞吐率:570.786fps + + + +### 7.4 性能对比 + +最优batch下,已经达到: + +1. 710调优后的最优batch性能 >=1.2倍310最优batch性能; + +2. 710的最优batch性能 >=1.6倍T4最优batch性能。 + diff --git a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/benchmark.aarch64 b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/benchmark.aarch64 new file mode 100644 index 0000000000000000000000000000000000000000..0d34a7532ce1c41ba9acd8b24aebff45d7a446f3 Binary files /dev/null and b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/benchmark.aarch64 differ diff --git a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/env.sh b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/env.sh index 52554cfca2bdaa7918b38a82ab05b0c83cd28a15..75b5da3c9e5ffbba4aa2369ad801095eb9c69f34 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/env.sh +++ b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/env.sh @@ -1,6 +1,9 @@ -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp +export LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64/common:/usr/local/Ascend/driver/lib64/driver:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=/usr/local/Ascend/ascend-toolkit/latest/lib64:/usr/local/Ascend/ascend-toolkit/latest/lib64/plugin/opskernel:/usr/local/Ascend/ascend-toolkit/latest/lib64/plugin/nnengine:$LD_LIBRARY_PATH +export PYTHONPATH=/usr/local/Ascend/ascend-toolkit/latest/python/site-packages:/usr/local/Ascend/ascend-toolkit/latest/opp/op_impl/built-in/ai_core/tbe:$PYTHONPATH +export PATH=/usr/local/Ascend/ascend-toolkit/latest/bin:/usr/local/Ascend/ascend-toolkit/latest/compiler/ccec_compiler/bin:$PATH export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest +export ASCEND_OPP_PATH=/usr/local/Ascend/ascend-toolkit/latest/opp +export TOOLCHAIN_HOME=/usr/local/Ascend/ascend-toolkit/latest/toolkit +export ASCEND_HOME_PATH=/usr/local/Ascend/ascend-toolkit/latest +# export ASCEND_SLOG_PRINT_TO_STDOUT=1>log.log diff --git a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/gen_dataset_info.py index 61450b4410663ae5e66ec29ed296ff6584203e31..5381839f653a885666e3fc456db9a1c22b8583a1 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/gen_dataset_info.py @@ -1,61 +1,61 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) + diff --git a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/requirements.txt index e201023141a3422919c32979a89352fdc8d0e757..2f94093388da1b197ac1b92db08870011ce2fe79 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.8.1 -torchvision == 0.9.1 -onnx == 1.7.0 -numpy == 1.18.5 -Pillow == 7.2.0 +torch == 1.8.1 +torchvision == 0.9.1 +onnx == 1.7.0 +numpy == 1.18.5 +Pillow == 7.2.0 opencv-python == 4.2.0.34 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/test/README.md b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/test/README.md index e28e57fceb9ea963046de4b516a4d5606db19b5a..66ad246d3689e271c579b67fd30df21807ddaed1 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/test/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/test/README.md @@ -1,48 +1,48 @@ -环境准备: - -1.数据集路径 -通用的数据集统一放在/root/datasets/或/opt/npu/ -本模型数据集放在/opt/npu/ - -2.进入工作目录 - -``` -cd Wide_ResNet101_2 -``` - -3.安装必要的依赖 - -``` -pip3.7 install -r requirements.txt -``` - -4.获取模型代码 - -``` -git clone https://github.com/pytorch/vision -``` - -5.如果模型代码需要安装,则安装模型代码 - -``` -cd vision -git reset 7d955df73fe0e9b47f7d6c77c699324b256fc41f --hard -python3.7 setup.py install -cd .. -``` - -6.获取权重文件 - -``` -wget https://download.pytorch.org/models/wide_resnet101_2-32ee1156.pth -``` - -7.获取benchmark工具 -将benchmark.x86_64 放在当前目录 - -8.310上执行,执行时确保device空闲 - -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/opt/npu/ -``` +环境准备: + +1.数据集路径 +通用的数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集放在/opt/npu/ + +2.进入工作目录 + +``` +cd Wide_ResNet101_2 +``` + +3.安装必要的依赖 + +``` +pip3.7 install -r requirements.txt +``` + +4.获取模型代码 + +``` +git clone https://github.com/pytorch/vision +``` + +5.如果模型代码需要安装,则安装模型代码 + +``` +cd vision +git reset 7d955df73fe0e9b47f7d6c77c699324b256fc41f --hard +python3.7 setup.py install +cd .. +``` + +6.获取权重文件 + +``` +wget https://download.pytorch.org/models/wide_resnet101_2-32ee1156.pth +``` + +7.获取benchmark工具 +将benchmark.x86_64 放在当前目录 + +8.310上执行,执行时确保device空闲 + +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/opt/npu/ +``` diff --git a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/test/parse.py b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/test/parse.py index a0f253b055047b199b33d4b65cdc79177b6b250b..27eae0d0acf98687edd95f1f024cf77c49cd4dc4 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/test/parse.py +++ b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/wrn101_2_prep_bin.info b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/wrn101_2_prep_bin.info new file mode 100644 index 0000000000000000000000000000000000000000..9aab6733205ad00902dc717aa944334827494983 --- /dev/null +++ b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/wrn101_2_prep_bin.info @@ -0,0 +1,50000 @@ +0 ./prep_dataset/ILSVRC2012_val_00001611.bin 224 224 +1 ./prep_dataset/ILSVRC2012_val_00049443.bin 224 224 +2 ./prep_dataset/ILSVRC2012_val_00023648.bin 224 224 +3 ./prep_dataset/ILSVRC2012_val_00000103.bin 224 224 +4 ./prep_dataset/ILSVRC2012_val_00016674.bin 224 224 +5 ./prep_dataset/ILSVRC2012_val_00032260.bin 224 224 +6 ./prep_dataset/ILSVRC2012_val_00047675.bin 224 224 +7 ./prep_dataset/ILSVRC2012_val_00038754.bin 224 224 +8 ./prep_dataset/ILSVRC2012_val_00009622.bin 224 224 +9 ./prep_dataset/ILSVRC2012_val_00049765.bin 224 224 +10 ./prep_dataset/ILSVRC2012_val_00018192.bin 224 224 +11 ./prep_dataset/ILSVRC2012_val_00031939.bin 224 224 +12 ./prep_dataset/ILSVRC2012_val_00023014.bin 224 224 +13 ./prep_dataset/ILSVRC2012_val_00043942.bin 224 224 +14 ./prep_dataset/ILSVRC2012_val_00028701.bin 224 224 +15 ./prep_dataset/ILSVRC2012_val_00004608.bin 224 224 +16 ./prep_dataset/ILSVRC2012_val_00048639.bin 224 224 +17 ./prep_dataset/ILSVRC2012_val_00042722.bin 224 224 +18 ./prep_dataset/ILSVRC2012_val_00010618.bin 224 224 +19 ./prep_dataset/ILSVRC2012_val_00028226.bin 224 224 +20 ./prep_dataset/ILSVRC2012_val_00030458.bin 224 224 +21 ./prep_dataset/ILSVRC2012_val_00011700.bin 224 224 +22 ./prep_dataset/ILSVRC2012_val_00013168.bin 224 224 +23 ./prep_dataset/ILSVRC2012_val_00004931.bin 224 224 +24 ./prep_dataset/ILSVRC2012_val_00004301.bin 224 224 +25 ./prep_dataset/ILSVRC2012_val_00041749.bin 224 224 +26 ./prep_dataset/ILSVRC2012_val_00039302.bin 224 224 +27 ./prep_dataset/ILSVRC2012_val_00022491.bin 224 224 +28 ./prep_dataset/ILSVRC2012_val_00006762.bin 224 224 +29 ./prep_dataset/ILSVRC2012_val_00042211.bin 224 224 +30 ./prep_dataset/ILSVRC2012_val_00036455.bin 224 224 +31 ./prep_dataset/ILSVRC2012_val_00033898.bin 224 224 +32 ./prep_dataset/ILSVRC2012_val_00033848.bin 224 224 +33 ./prep_dataset/ILSVRC2012_val_00034989.bin 224 224 +34 ./prep_dataset/ILSVRC2012_val_00029337.bin 224 224 +35 ./prep_dataset/ILSVRC2012_val_00008368.bin 224 224 +36 ./prep_dataset/ILSVRC2012_val_00033022.bin 224 224 +37 ./prep_dataset/ILSVRC2012_val_00041441.bin 224 224 +38 ./prep_dataset/ILSVRC2012_val_00026213.bin 224 224 +39 ./prep_dataset/ILSVRC2012_val_00031323.bin 224 224 +40 ./prep_dataset/ILSVRC2012_val_00035852.bin 224 224 +41 ./prep_dataset/ILSVRC2012_val_00018744.bin 224 224 +42 ./prep_dataset/ILSVRC2012_val_00002154.bin 224 224 +43 ./prep_dataset/ILSVRC2012_val_00009125.bin 224 224 +44 ./prep_dataset/ILSVRC2012_val_00020917.bin 224 224 +45 ./prep_dataset/ILSVRC2012_val_00007223.bin 224 224 +46 ./prep_dataset/ILSVRC2012_val_00006176.bin 224 224 +47 ./prep_dataset/ILSVRC2012_val_00049958.bin 224 224 +48 ./prep_dataset/ILSVRC2012_val_00036034.bin 224 224 +49 ./prep_dataset/ILSVRC2012_val_00041941.bin 224 224 +50 ./prep_dataset/ILSVRC2012_val_00048528.bin 224 224 +51 ./prep_dataset/ILSVRC2012_val_00007402.bin 224 224 +52 ./prep_dataset/ILSVRC2012_val_00005331.bin 224 224 +53 ./prep_dataset/ILSVRC2012_val_00007085.bin 224 224 +54 ./prep_dataset/ILSVRC2012_val_00002475.bin 224 224 +55 ./prep_dataset/ILSVRC2012_val_00003565.bin 224 224 +56 ./prep_dataset/ILSVRC2012_val_00033500.bin 224 224 +57 ./prep_dataset/ILSVRC2012_val_00009482.bin 224 224 +58 ./prep_dataset/ILSVRC2012_val_00036302.bin 224 224 +59 ./prep_dataset/ILSVRC2012_val_00042316.bin 224 224 +60 ./prep_dataset/ILSVRC2012_val_00026056.bin 224 224 +61 ./prep_dataset/ILSVRC2012_val_00046422.bin 224 224 +62 ./prep_dataset/ILSVRC2012_val_00015958.bin 224 224 +63 ./prep_dataset/ILSVRC2012_val_00041797.bin 224 224 +64 ./prep_dataset/ILSVRC2012_val_00038319.bin 224 224 +65 ./prep_dataset/ILSVRC2012_val_00010694.bin 224 224 +66 ./prep_dataset/ILSVRC2012_val_00018189.bin 224 224 +67 ./prep_dataset/ILSVRC2012_val_00036234.bin 224 224 +68 ./prep_dataset/ILSVRC2012_val_00046087.bin 224 224 +69 ./prep_dataset/ILSVRC2012_val_00022821.bin 224 224 +70 ./prep_dataset/ILSVRC2012_val_00028378.bin 224 224 +71 ./prep_dataset/ILSVRC2012_val_00018857.bin 224 224 +72 ./prep_dataset/ILSVRC2012_val_00022668.bin 224 224 +73 ./prep_dataset/ILSVRC2012_val_00001565.bin 224 224 +74 ./prep_dataset/ILSVRC2012_val_00049719.bin 224 224 +75 ./prep_dataset/ILSVRC2012_val_00022718.bin 224 224 +76 ./prep_dataset/ILSVRC2012_val_00041196.bin 224 224 +77 ./prep_dataset/ILSVRC2012_val_00045992.bin 224 224 +78 ./prep_dataset/ILSVRC2012_val_00000650.bin 224 224 +79 ./prep_dataset/ILSVRC2012_val_00048615.bin 224 224 +80 ./prep_dataset/ILSVRC2012_val_00031296.bin 224 224 +81 ./prep_dataset/ILSVRC2012_val_00025503.bin 224 224 +82 ./prep_dataset/ILSVRC2012_val_00015097.bin 224 224 +83 ./prep_dataset/ILSVRC2012_val_00012244.bin 224 224 +84 ./prep_dataset/ILSVRC2012_val_00004202.bin 224 224 +85 ./prep_dataset/ILSVRC2012_val_00030477.bin 224 224 +86 ./prep_dataset/ILSVRC2012_val_00028303.bin 224 224 +87 ./prep_dataset/ILSVRC2012_val_00033925.bin 224 224 +88 ./prep_dataset/ILSVRC2012_val_00039764.bin 224 224 +89 ./prep_dataset/ILSVRC2012_val_00004885.bin 224 224 +90 ./prep_dataset/ILSVRC2012_val_00005068.bin 224 224 +91 ./prep_dataset/ILSVRC2012_val_00026478.bin 224 224 +92 ./prep_dataset/ILSVRC2012_val_00032940.bin 224 224 +93 ./prep_dataset/ILSVRC2012_val_00012816.bin 224 224 +94 ./prep_dataset/ILSVRC2012_val_00016972.bin 224 224 +95 ./prep_dataset/ILSVRC2012_val_00027932.bin 224 224 +96 ./prep_dataset/ILSVRC2012_val_00022033.bin 224 224 +97 ./prep_dataset/ILSVRC2012_val_00033989.bin 224 224 +98 ./prep_dataset/ILSVRC2012_val_00011453.bin 224 224 +99 ./prep_dataset/ILSVRC2012_val_00040465.bin 224 224 +100 ./prep_dataset/ILSVRC2012_val_00039827.bin 224 224 +101 ./prep_dataset/ILSVRC2012_val_00001552.bin 224 224 +102 ./prep_dataset/ILSVRC2012_val_00026591.bin 224 224 +103 ./prep_dataset/ILSVRC2012_val_00047746.bin 224 224 +104 ./prep_dataset/ILSVRC2012_val_00013758.bin 224 224 +105 ./prep_dataset/ILSVRC2012_val_00020462.bin 224 224 +106 ./prep_dataset/ILSVRC2012_val_00017903.bin 224 224 +107 ./prep_dataset/ILSVRC2012_val_00029256.bin 224 224 +108 ./prep_dataset/ILSVRC2012_val_00026973.bin 224 224 +109 ./prep_dataset/ILSVRC2012_val_00041071.bin 224 224 +110 ./prep_dataset/ILSVRC2012_val_00009733.bin 224 224 +111 ./prep_dataset/ILSVRC2012_val_00041104.bin 224 224 +112 ./prep_dataset/ILSVRC2012_val_00040812.bin 224 224 +113 ./prep_dataset/ILSVRC2012_val_00023216.bin 224 224 +114 ./prep_dataset/ILSVRC2012_val_00028026.bin 224 224 +115 ./prep_dataset/ILSVRC2012_val_00016501.bin 224 224 +116 ./prep_dataset/ILSVRC2012_val_00041581.bin 224 224 +117 ./prep_dataset/ILSVRC2012_val_00042636.bin 224 224 +118 ./prep_dataset/ILSVRC2012_val_00035630.bin 224 224 +119 ./prep_dataset/ILSVRC2012_val_00003460.bin 224 224 +120 ./prep_dataset/ILSVRC2012_val_00030424.bin 224 224 +121 ./prep_dataset/ILSVRC2012_val_00001893.bin 224 224 +122 ./prep_dataset/ILSVRC2012_val_00004667.bin 224 224 +123 ./prep_dataset/ILSVRC2012_val_00010053.bin 224 224 +124 ./prep_dataset/ILSVRC2012_val_00032901.bin 224 224 +125 ./prep_dataset/ILSVRC2012_val_00004585.bin 224 224 +126 ./prep_dataset/ILSVRC2012_val_00000077.bin 224 224 +127 ./prep_dataset/ILSVRC2012_val_00028731.bin 224 224 +128 ./prep_dataset/ILSVRC2012_val_00032922.bin 224 224 +129 ./prep_dataset/ILSVRC2012_val_00026215.bin 224 224 +130 ./prep_dataset/ILSVRC2012_val_00012150.bin 224 224 +131 ./prep_dataset/ILSVRC2012_val_00014679.bin 224 224 +132 ./prep_dataset/ILSVRC2012_val_00018696.bin 224 224 +133 ./prep_dataset/ILSVRC2012_val_00035119.bin 224 224 +134 ./prep_dataset/ILSVRC2012_val_00031244.bin 224 224 +135 ./prep_dataset/ILSVRC2012_val_00043915.bin 224 224 +136 ./prep_dataset/ILSVRC2012_val_00033715.bin 224 224 +137 ./prep_dataset/ILSVRC2012_val_00045642.bin 224 224 +138 ./prep_dataset/ILSVRC2012_val_00020168.bin 224 224 +139 ./prep_dataset/ILSVRC2012_val_00019367.bin 224 224 +140 ./prep_dataset/ILSVRC2012_val_00034752.bin 224 224 +141 ./prep_dataset/ILSVRC2012_val_00013662.bin 224 224 +142 ./prep_dataset/ILSVRC2012_val_00014906.bin 224 224 +143 ./prep_dataset/ILSVRC2012_val_00019948.bin 224 224 +144 ./prep_dataset/ILSVRC2012_val_00032134.bin 224 224 +145 ./prep_dataset/ILSVRC2012_val_00033026.bin 224 224 +146 ./prep_dataset/ILSVRC2012_val_00046561.bin 224 224 +147 ./prep_dataset/ILSVRC2012_val_00028405.bin 224 224 +148 ./prep_dataset/ILSVRC2012_val_00000934.bin 224 224 +149 ./prep_dataset/ILSVRC2012_val_00038140.bin 224 224 +150 ./prep_dataset/ILSVRC2012_val_00016053.bin 224 224 +151 ./prep_dataset/ILSVRC2012_val_00022641.bin 224 224 +152 ./prep_dataset/ILSVRC2012_val_00029241.bin 224 224 +153 ./prep_dataset/ILSVRC2012_val_00000499.bin 224 224 +154 ./prep_dataset/ILSVRC2012_val_00048397.bin 224 224 +155 ./prep_dataset/ILSVRC2012_val_00015760.bin 224 224 +156 ./prep_dataset/ILSVRC2012_val_00016569.bin 224 224 +157 ./prep_dataset/ILSVRC2012_val_00007663.bin 224 224 +158 ./prep_dataset/ILSVRC2012_val_00013818.bin 224 224 +159 ./prep_dataset/ILSVRC2012_val_00015549.bin 224 224 +160 ./prep_dataset/ILSVRC2012_val_00004966.bin 224 224 +161 ./prep_dataset/ILSVRC2012_val_00040764.bin 224 224 +162 ./prep_dataset/ILSVRC2012_val_00022561.bin 224 224 +163 ./prep_dataset/ILSVRC2012_val_00019295.bin 224 224 +164 ./prep_dataset/ILSVRC2012_val_00003214.bin 224 224 +165 ./prep_dataset/ILSVRC2012_val_00041471.bin 224 224 +166 ./prep_dataset/ILSVRC2012_val_00040991.bin 224 224 +167 ./prep_dataset/ILSVRC2012_val_00049590.bin 224 224 +168 ./prep_dataset/ILSVRC2012_val_00001473.bin 224 224 +169 ./prep_dataset/ILSVRC2012_val_00027336.bin 224 224 +170 ./prep_dataset/ILSVRC2012_val_00036668.bin 224 224 +171 ./prep_dataset/ILSVRC2012_val_00046767.bin 224 224 +172 ./prep_dataset/ILSVRC2012_val_00003651.bin 224 224 +173 ./prep_dataset/ILSVRC2012_val_00036411.bin 224 224 +174 ./prep_dataset/ILSVRC2012_val_00022280.bin 224 224 +175 ./prep_dataset/ILSVRC2012_val_00007744.bin 224 224 +176 ./prep_dataset/ILSVRC2012_val_00035262.bin 224 224 +177 ./prep_dataset/ILSVRC2012_val_00045911.bin 224 224 +178 ./prep_dataset/ILSVRC2012_val_00038538.bin 224 224 +179 ./prep_dataset/ILSVRC2012_val_00037373.bin 224 224 +180 ./prep_dataset/ILSVRC2012_val_00016375.bin 224 224 +181 ./prep_dataset/ILSVRC2012_val_00007487.bin 224 224 +182 ./prep_dataset/ILSVRC2012_val_00033953.bin 224 224 +183 ./prep_dataset/ILSVRC2012_val_00047921.bin 224 224 +184 ./prep_dataset/ILSVRC2012_val_00043223.bin 224 224 +185 ./prep_dataset/ILSVRC2012_val_00007792.bin 224 224 +186 ./prep_dataset/ILSVRC2012_val_00047271.bin 224 224 +187 ./prep_dataset/ILSVRC2012_val_00046628.bin 224 224 +188 ./prep_dataset/ILSVRC2012_val_00023937.bin 224 224 +189 ./prep_dataset/ILSVRC2012_val_00009876.bin 224 224 +190 ./prep_dataset/ILSVRC2012_val_00015284.bin 224 224 +191 ./prep_dataset/ILSVRC2012_val_00017947.bin 224 224 +192 ./prep_dataset/ILSVRC2012_val_00033314.bin 224 224 +193 ./prep_dataset/ILSVRC2012_val_00026637.bin 224 224 +194 ./prep_dataset/ILSVRC2012_val_00048763.bin 224 224 +195 ./prep_dataset/ILSVRC2012_val_00007764.bin 224 224 +196 ./prep_dataset/ILSVRC2012_val_00031223.bin 224 224 +197 ./prep_dataset/ILSVRC2012_val_00047869.bin 224 224 +198 ./prep_dataset/ILSVRC2012_val_00039018.bin 224 224 +199 ./prep_dataset/ILSVRC2012_val_00046190.bin 224 224 +200 ./prep_dataset/ILSVRC2012_val_00006881.bin 224 224 +201 ./prep_dataset/ILSVRC2012_val_00015932.bin 224 224 +202 ./prep_dataset/ILSVRC2012_val_00001695.bin 224 224 +203 ./prep_dataset/ILSVRC2012_val_00049170.bin 224 224 +204 ./prep_dataset/ILSVRC2012_val_00002713.bin 224 224 +205 ./prep_dataset/ILSVRC2012_val_00032954.bin 224 224 +206 ./prep_dataset/ILSVRC2012_val_00031955.bin 224 224 +207 ./prep_dataset/ILSVRC2012_val_00027258.bin 224 224 +208 ./prep_dataset/ILSVRC2012_val_00000055.bin 224 224 +209 ./prep_dataset/ILSVRC2012_val_00022126.bin 224 224 +210 ./prep_dataset/ILSVRC2012_val_00033384.bin 224 224 +211 ./prep_dataset/ILSVRC2012_val_00045750.bin 224 224 +212 ./prep_dataset/ILSVRC2012_val_00045964.bin 224 224 +213 ./prep_dataset/ILSVRC2012_val_00018615.bin 224 224 +214 ./prep_dataset/ILSVRC2012_val_00002678.bin 224 224 +215 ./prep_dataset/ILSVRC2012_val_00049985.bin 224 224 +216 ./prep_dataset/ILSVRC2012_val_00042320.bin 224 224 +217 ./prep_dataset/ILSVRC2012_val_00016399.bin 224 224 +218 ./prep_dataset/ILSVRC2012_val_00030665.bin 224 224 +219 ./prep_dataset/ILSVRC2012_val_00035038.bin 224 224 +220 ./prep_dataset/ILSVRC2012_val_00044734.bin 224 224 +221 ./prep_dataset/ILSVRC2012_val_00008334.bin 224 224 +222 ./prep_dataset/ILSVRC2012_val_00031908.bin 224 224 +223 ./prep_dataset/ILSVRC2012_val_00028517.bin 224 224 +224 ./prep_dataset/ILSVRC2012_val_00046949.bin 224 224 +225 ./prep_dataset/ILSVRC2012_val_00006226.bin 224 224 +226 ./prep_dataset/ILSVRC2012_val_00012319.bin 224 224 +227 ./prep_dataset/ILSVRC2012_val_00045471.bin 224 224 +228 ./prep_dataset/ILSVRC2012_val_00012882.bin 224 224 +229 ./prep_dataset/ILSVRC2012_val_00016178.bin 224 224 +230 ./prep_dataset/ILSVRC2012_val_00048662.bin 224 224 +231 ./prep_dataset/ILSVRC2012_val_00047393.bin 224 224 +232 ./prep_dataset/ILSVRC2012_val_00000646.bin 224 224 +233 ./prep_dataset/ILSVRC2012_val_00006557.bin 224 224 +234 ./prep_dataset/ILSVRC2012_val_00017221.bin 224 224 +235 ./prep_dataset/ILSVRC2012_val_00048794.bin 224 224 +236 ./prep_dataset/ILSVRC2012_val_00026970.bin 224 224 +237 ./prep_dataset/ILSVRC2012_val_00021496.bin 224 224 +238 ./prep_dataset/ILSVRC2012_val_00047672.bin 224 224 +239 ./prep_dataset/ILSVRC2012_val_00031311.bin 224 224 +240 ./prep_dataset/ILSVRC2012_val_00031251.bin 224 224 +241 ./prep_dataset/ILSVRC2012_val_00007143.bin 224 224 +242 ./prep_dataset/ILSVRC2012_val_00038823.bin 224 224 +243 ./prep_dataset/ILSVRC2012_val_00012819.bin 224 224 +244 ./prep_dataset/ILSVRC2012_val_00037697.bin 224 224 +245 ./prep_dataset/ILSVRC2012_val_00044289.bin 224 224 +246 ./prep_dataset/ILSVRC2012_val_00015186.bin 224 224 +247 ./prep_dataset/ILSVRC2012_val_00038578.bin 224 224 +248 ./prep_dataset/ILSVRC2012_val_00020115.bin 224 224 +249 ./prep_dataset/ILSVRC2012_val_00027129.bin 224 224 +250 ./prep_dataset/ILSVRC2012_val_00031432.bin 224 224 +251 ./prep_dataset/ILSVRC2012_val_00036545.bin 224 224 +252 ./prep_dataset/ILSVRC2012_val_00008983.bin 224 224 +253 ./prep_dataset/ILSVRC2012_val_00046143.bin 224 224 +254 ./prep_dataset/ILSVRC2012_val_00024815.bin 224 224 +255 ./prep_dataset/ILSVRC2012_val_00036169.bin 224 224 +256 ./prep_dataset/ILSVRC2012_val_00042672.bin 224 224 +257 ./prep_dataset/ILSVRC2012_val_00045812.bin 224 224 +258 ./prep_dataset/ILSVRC2012_val_00035015.bin 224 224 +259 ./prep_dataset/ILSVRC2012_val_00038413.bin 224 224 +260 ./prep_dataset/ILSVRC2012_val_00023152.bin 224 224 +261 ./prep_dataset/ILSVRC2012_val_00019273.bin 224 224 +262 ./prep_dataset/ILSVRC2012_val_00006423.bin 224 224 +263 ./prep_dataset/ILSVRC2012_val_00042715.bin 224 224 +264 ./prep_dataset/ILSVRC2012_val_00025736.bin 224 224 +265 ./prep_dataset/ILSVRC2012_val_00023024.bin 224 224 +266 ./prep_dataset/ILSVRC2012_val_00026990.bin 224 224 +267 ./prep_dataset/ILSVRC2012_val_00035854.bin 224 224 +268 ./prep_dataset/ILSVRC2012_val_00039242.bin 224 224 +269 ./prep_dataset/ILSVRC2012_val_00047943.bin 224 224 +270 ./prep_dataset/ILSVRC2012_val_00015495.bin 224 224 +271 ./prep_dataset/ILSVRC2012_val_00040043.bin 224 224 +272 ./prep_dataset/ILSVRC2012_val_00001139.bin 224 224 +273 ./prep_dataset/ILSVRC2012_val_00001379.bin 224 224 +274 ./prep_dataset/ILSVRC2012_val_00012156.bin 224 224 +275 ./prep_dataset/ILSVRC2012_val_00006837.bin 224 224 +276 ./prep_dataset/ILSVRC2012_val_00036838.bin 224 224 +277 ./prep_dataset/ILSVRC2012_val_00013711.bin 224 224 +278 ./prep_dataset/ILSVRC2012_val_00018060.bin 224 224 +279 ./prep_dataset/ILSVRC2012_val_00028664.bin 224 224 +280 ./prep_dataset/ILSVRC2012_val_00003224.bin 224 224 +281 ./prep_dataset/ILSVRC2012_val_00049791.bin 224 224 +282 ./prep_dataset/ILSVRC2012_val_00030825.bin 224 224 +283 ./prep_dataset/ILSVRC2012_val_00049869.bin 224 224 +284 ./prep_dataset/ILSVRC2012_val_00003294.bin 224 224 +285 ./prep_dataset/ILSVRC2012_val_00017000.bin 224 224 +286 ./prep_dataset/ILSVRC2012_val_00025216.bin 224 224 +287 ./prep_dataset/ILSVRC2012_val_00047926.bin 224 224 +288 ./prep_dataset/ILSVRC2012_val_00013302.bin 224 224 +289 ./prep_dataset/ILSVRC2012_val_00011945.bin 224 224 +290 ./prep_dataset/ILSVRC2012_val_00014397.bin 224 224 +291 ./prep_dataset/ILSVRC2012_val_00008540.bin 224 224 +292 ./prep_dataset/ILSVRC2012_val_00045977.bin 224 224 +293 ./prep_dataset/ILSVRC2012_val_00040183.bin 224 224 +294 ./prep_dataset/ILSVRC2012_val_00034015.bin 224 224 +295 ./prep_dataset/ILSVRC2012_val_00043577.bin 224 224 +296 ./prep_dataset/ILSVRC2012_val_00000656.bin 224 224 +297 ./prep_dataset/ILSVRC2012_val_00032349.bin 224 224 +298 ./prep_dataset/ILSVRC2012_val_00009831.bin 224 224 +299 ./prep_dataset/ILSVRC2012_val_00004320.bin 224 224 +300 ./prep_dataset/ILSVRC2012_val_00015075.bin 224 224 +301 ./prep_dataset/ILSVRC2012_val_00027329.bin 224 224 +302 ./prep_dataset/ILSVRC2012_val_00043391.bin 224 224 +303 ./prep_dataset/ILSVRC2012_val_00025517.bin 224 224 +304 ./prep_dataset/ILSVRC2012_val_00048925.bin 224 224 +305 ./prep_dataset/ILSVRC2012_val_00039080.bin 224 224 +306 ./prep_dataset/ILSVRC2012_val_00031101.bin 224 224 +307 ./prep_dataset/ILSVRC2012_val_00042876.bin 224 224 +308 ./prep_dataset/ILSVRC2012_val_00003576.bin 224 224 +309 ./prep_dataset/ILSVRC2012_val_00033827.bin 224 224 +310 ./prep_dataset/ILSVRC2012_val_00006874.bin 224 224 +311 ./prep_dataset/ILSVRC2012_val_00030371.bin 224 224 +312 ./prep_dataset/ILSVRC2012_val_00027556.bin 224 224 +313 ./prep_dataset/ILSVRC2012_val_00043773.bin 224 224 +314 ./prep_dataset/ILSVRC2012_val_00025021.bin 224 224 +315 ./prep_dataset/ILSVRC2012_val_00009159.bin 224 224 +316 ./prep_dataset/ILSVRC2012_val_00041214.bin 224 224 +317 ./prep_dataset/ILSVRC2012_val_00019856.bin 224 224 +318 ./prep_dataset/ILSVRC2012_val_00032791.bin 224 224 +319 ./prep_dataset/ILSVRC2012_val_00002622.bin 224 224 +320 ./prep_dataset/ILSVRC2012_val_00016679.bin 224 224 +321 ./prep_dataset/ILSVRC2012_val_00002292.bin 224 224 +322 ./prep_dataset/ILSVRC2012_val_00048758.bin 224 224 +323 ./prep_dataset/ILSVRC2012_val_00036871.bin 224 224 +324 ./prep_dataset/ILSVRC2012_val_00038471.bin 224 224 +325 ./prep_dataset/ILSVRC2012_val_00014138.bin 224 224 +326 ./prep_dataset/ILSVRC2012_val_00018818.bin 224 224 +327 ./prep_dataset/ILSVRC2012_val_00020748.bin 224 224 +328 ./prep_dataset/ILSVRC2012_val_00035494.bin 224 224 +329 ./prep_dataset/ILSVRC2012_val_00031091.bin 224 224 +330 ./prep_dataset/ILSVRC2012_val_00034358.bin 224 224 +331 ./prep_dataset/ILSVRC2012_val_00039385.bin 224 224 +332 ./prep_dataset/ILSVRC2012_val_00017586.bin 224 224 +333 ./prep_dataset/ILSVRC2012_val_00044056.bin 224 224 +334 ./prep_dataset/ILSVRC2012_val_00024328.bin 224 224 +335 ./prep_dataset/ILSVRC2012_val_00031113.bin 224 224 +336 ./prep_dataset/ILSVRC2012_val_00048400.bin 224 224 +337 ./prep_dataset/ILSVRC2012_val_00013900.bin 224 224 +338 ./prep_dataset/ILSVRC2012_val_00022442.bin 224 224 +339 ./prep_dataset/ILSVRC2012_val_00045053.bin 224 224 +340 ./prep_dataset/ILSVRC2012_val_00040234.bin 224 224 +341 ./prep_dataset/ILSVRC2012_val_00002041.bin 224 224 +342 ./prep_dataset/ILSVRC2012_val_00030510.bin 224 224 +343 ./prep_dataset/ILSVRC2012_val_00010776.bin 224 224 +344 ./prep_dataset/ILSVRC2012_val_00017308.bin 224 224 +345 ./prep_dataset/ILSVRC2012_val_00036732.bin 224 224 +346 ./prep_dataset/ILSVRC2012_val_00026127.bin 224 224 +347 ./prep_dataset/ILSVRC2012_val_00019678.bin 224 224 +348 ./prep_dataset/ILSVRC2012_val_00010895.bin 224 224 +349 ./prep_dataset/ILSVRC2012_val_00029142.bin 224 224 +350 ./prep_dataset/ILSVRC2012_val_00034329.bin 224 224 +351 ./prep_dataset/ILSVRC2012_val_00033190.bin 224 224 +352 ./prep_dataset/ILSVRC2012_val_00022782.bin 224 224 +353 ./prep_dataset/ILSVRC2012_val_00048539.bin 224 224 +354 ./prep_dataset/ILSVRC2012_val_00045776.bin 224 224 +355 ./prep_dataset/ILSVRC2012_val_00030374.bin 224 224 +356 ./prep_dataset/ILSVRC2012_val_00013112.bin 224 224 +357 ./prep_dataset/ILSVRC2012_val_00012696.bin 224 224 +358 ./prep_dataset/ILSVRC2012_val_00015852.bin 224 224 +359 ./prep_dataset/ILSVRC2012_val_00027637.bin 224 224 +360 ./prep_dataset/ILSVRC2012_val_00016301.bin 224 224 +361 ./prep_dataset/ILSVRC2012_val_00016067.bin 224 224 +362 ./prep_dataset/ILSVRC2012_val_00005717.bin 224 224 +363 ./prep_dataset/ILSVRC2012_val_00027238.bin 224 224 +364 ./prep_dataset/ILSVRC2012_val_00018810.bin 224 224 +365 ./prep_dataset/ILSVRC2012_val_00024822.bin 224 224 +366 ./prep_dataset/ILSVRC2012_val_00002818.bin 224 224 +367 ./prep_dataset/ILSVRC2012_val_00049204.bin 224 224 +368 ./prep_dataset/ILSVRC2012_val_00006587.bin 224 224 +369 ./prep_dataset/ILSVRC2012_val_00038863.bin 224 224 +370 ./prep_dataset/ILSVRC2012_val_00000251.bin 224 224 +371 ./prep_dataset/ILSVRC2012_val_00015582.bin 224 224 +372 ./prep_dataset/ILSVRC2012_val_00011698.bin 224 224 +373 ./prep_dataset/ILSVRC2012_val_00005204.bin 224 224 +374 ./prep_dataset/ILSVRC2012_val_00040906.bin 224 224 +375 ./prep_dataset/ILSVRC2012_val_00021448.bin 224 224 +376 ./prep_dataset/ILSVRC2012_val_00007000.bin 224 224 +377 ./prep_dataset/ILSVRC2012_val_00005832.bin 224 224 +378 ./prep_dataset/ILSVRC2012_val_00019036.bin 224 224 +379 ./prep_dataset/ILSVRC2012_val_00036221.bin 224 224 +380 ./prep_dataset/ILSVRC2012_val_00024346.bin 224 224 +381 ./prep_dataset/ILSVRC2012_val_00042964.bin 224 224 +382 ./prep_dataset/ILSVRC2012_val_00044192.bin 224 224 +383 ./prep_dataset/ILSVRC2012_val_00035975.bin 224 224 +384 ./prep_dataset/ILSVRC2012_val_00003820.bin 224 224 +385 ./prep_dataset/ILSVRC2012_val_00030128.bin 224 224 +386 ./prep_dataset/ILSVRC2012_val_00006617.bin 224 224 +387 ./prep_dataset/ILSVRC2012_val_00002101.bin 224 224 +388 ./prep_dataset/ILSVRC2012_val_00002940.bin 224 224 +389 ./prep_dataset/ILSVRC2012_val_00021054.bin 224 224 +390 ./prep_dataset/ILSVRC2012_val_00047771.bin 224 224 +391 ./prep_dataset/ILSVRC2012_val_00031578.bin 224 224 +392 ./prep_dataset/ILSVRC2012_val_00002247.bin 224 224 +393 ./prep_dataset/ILSVRC2012_val_00000904.bin 224 224 +394 ./prep_dataset/ILSVRC2012_val_00028568.bin 224 224 +395 ./prep_dataset/ILSVRC2012_val_00019529.bin 224 224 +396 ./prep_dataset/ILSVRC2012_val_00023278.bin 224 224 +397 ./prep_dataset/ILSVRC2012_val_00008461.bin 224 224 +398 ./prep_dataset/ILSVRC2012_val_00003668.bin 224 224 +399 ./prep_dataset/ILSVRC2012_val_00027853.bin 224 224 +400 ./prep_dataset/ILSVRC2012_val_00018658.bin 224 224 +401 ./prep_dataset/ILSVRC2012_val_00027378.bin 224 224 +402 ./prep_dataset/ILSVRC2012_val_00007057.bin 224 224 +403 ./prep_dataset/ILSVRC2012_val_00049275.bin 224 224 +404 ./prep_dataset/ILSVRC2012_val_00007845.bin 224 224 +405 ./prep_dataset/ILSVRC2012_val_00042362.bin 224 224 +406 ./prep_dataset/ILSVRC2012_val_00039294.bin 224 224 +407 ./prep_dataset/ILSVRC2012_val_00009912.bin 224 224 +408 ./prep_dataset/ILSVRC2012_val_00034267.bin 224 224 +409 ./prep_dataset/ILSVRC2012_val_00003335.bin 224 224 +410 ./prep_dataset/ILSVRC2012_val_00039005.bin 224 224 +411 ./prep_dataset/ILSVRC2012_val_00029443.bin 224 224 +412 ./prep_dataset/ILSVRC2012_val_00046974.bin 224 224 +413 ./prep_dataset/ILSVRC2012_val_00045341.bin 224 224 +414 ./prep_dataset/ILSVRC2012_val_00026132.bin 224 224 +415 ./prep_dataset/ILSVRC2012_val_00001337.bin 224 224 +416 ./prep_dataset/ILSVRC2012_val_00007120.bin 224 224 +417 ./prep_dataset/ILSVRC2012_val_00040588.bin 224 224 +418 ./prep_dataset/ILSVRC2012_val_00041108.bin 224 224 +419 ./prep_dataset/ILSVRC2012_val_00015463.bin 224 224 +420 ./prep_dataset/ILSVRC2012_val_00009145.bin 224 224 +421 ./prep_dataset/ILSVRC2012_val_00006512.bin 224 224 +422 ./prep_dataset/ILSVRC2012_val_00025670.bin 224 224 +423 ./prep_dataset/ILSVRC2012_val_00021967.bin 224 224 +424 ./prep_dataset/ILSVRC2012_val_00002954.bin 224 224 +425 ./prep_dataset/ILSVRC2012_val_00045757.bin 224 224 +426 ./prep_dataset/ILSVRC2012_val_00018764.bin 224 224 +427 ./prep_dataset/ILSVRC2012_val_00006603.bin 224 224 +428 ./prep_dataset/ILSVRC2012_val_00037996.bin 224 224 +429 ./prep_dataset/ILSVRC2012_val_00041325.bin 224 224 +430 ./prep_dataset/ILSVRC2012_val_00019337.bin 224 224 +431 ./prep_dataset/ILSVRC2012_val_00015143.bin 224 224 +432 ./prep_dataset/ILSVRC2012_val_00003144.bin 224 224 +433 ./prep_dataset/ILSVRC2012_val_00040980.bin 224 224 +434 ./prep_dataset/ILSVRC2012_val_00025973.bin 224 224 +435 ./prep_dataset/ILSVRC2012_val_00011321.bin 224 224 +436 ./prep_dataset/ILSVRC2012_val_00033402.bin 224 224 +437 ./prep_dataset/ILSVRC2012_val_00030445.bin 224 224 +438 ./prep_dataset/ILSVRC2012_val_00027354.bin 224 224 +439 ./prep_dataset/ILSVRC2012_val_00001409.bin 224 224 +440 ./prep_dataset/ILSVRC2012_val_00039040.bin 224 224 +441 ./prep_dataset/ILSVRC2012_val_00014960.bin 224 224 +442 ./prep_dataset/ILSVRC2012_val_00028114.bin 224 224 +443 ./prep_dataset/ILSVRC2012_val_00000791.bin 224 224 +444 ./prep_dataset/ILSVRC2012_val_00004977.bin 224 224 +445 ./prep_dataset/ILSVRC2012_val_00009994.bin 224 224 +446 ./prep_dataset/ILSVRC2012_val_00049279.bin 224 224 +447 ./prep_dataset/ILSVRC2012_val_00007333.bin 224 224 +448 ./prep_dataset/ILSVRC2012_val_00005001.bin 224 224 +449 ./prep_dataset/ILSVRC2012_val_00026284.bin 224 224 +450 ./prep_dataset/ILSVRC2012_val_00049141.bin 224 224 +451 ./prep_dataset/ILSVRC2012_val_00024766.bin 224 224 +452 ./prep_dataset/ILSVRC2012_val_00034541.bin 224 224 +453 ./prep_dataset/ILSVRC2012_val_00022354.bin 224 224 +454 ./prep_dataset/ILSVRC2012_val_00030151.bin 224 224 +455 ./prep_dataset/ILSVRC2012_val_00039500.bin 224 224 +456 ./prep_dataset/ILSVRC2012_val_00044014.bin 224 224 +457 ./prep_dataset/ILSVRC2012_val_00008250.bin 224 224 +458 ./prep_dataset/ILSVRC2012_val_00009455.bin 224 224 +459 ./prep_dataset/ILSVRC2012_val_00009933.bin 224 224 +460 ./prep_dataset/ILSVRC2012_val_00009692.bin 224 224 +461 ./prep_dataset/ILSVRC2012_val_00018507.bin 224 224 +462 ./prep_dataset/ILSVRC2012_val_00008620.bin 224 224 +463 ./prep_dataset/ILSVRC2012_val_00014351.bin 224 224 +464 ./prep_dataset/ILSVRC2012_val_00022873.bin 224 224 +465 ./prep_dataset/ILSVRC2012_val_00033656.bin 224 224 +466 ./prep_dataset/ILSVRC2012_val_00001082.bin 224 224 +467 ./prep_dataset/ILSVRC2012_val_00032407.bin 224 224 +468 ./prep_dataset/ILSVRC2012_val_00008639.bin 224 224 +469 ./prep_dataset/ILSVRC2012_val_00022387.bin 224 224 +470 ./prep_dataset/ILSVRC2012_val_00045035.bin 224 224 +471 ./prep_dataset/ILSVRC2012_val_00001918.bin 224 224 +472 ./prep_dataset/ILSVRC2012_val_00048817.bin 224 224 +473 ./prep_dataset/ILSVRC2012_val_00039082.bin 224 224 +474 ./prep_dataset/ILSVRC2012_val_00034156.bin 224 224 +475 ./prep_dataset/ILSVRC2012_val_00042587.bin 224 224 +476 ./prep_dataset/ILSVRC2012_val_00003276.bin 224 224 +477 ./prep_dataset/ILSVRC2012_val_00006113.bin 224 224 +478 ./prep_dataset/ILSVRC2012_val_00021762.bin 224 224 +479 ./prep_dataset/ILSVRC2012_val_00019645.bin 224 224 +480 ./prep_dataset/ILSVRC2012_val_00027337.bin 224 224 +481 ./prep_dataset/ILSVRC2012_val_00011162.bin 224 224 +482 ./prep_dataset/ILSVRC2012_val_00032546.bin 224 224 +483 ./prep_dataset/ILSVRC2012_val_00006093.bin 224 224 +484 ./prep_dataset/ILSVRC2012_val_00016632.bin 224 224 +485 ./prep_dataset/ILSVRC2012_val_00039118.bin 224 224 +486 ./prep_dataset/ILSVRC2012_val_00048830.bin 224 224 +487 ./prep_dataset/ILSVRC2012_val_00048436.bin 224 224 +488 ./prep_dataset/ILSVRC2012_val_00041101.bin 224 224 +489 ./prep_dataset/ILSVRC2012_val_00010913.bin 224 224 +490 ./prep_dataset/ILSVRC2012_val_00021591.bin 224 224 +491 ./prep_dataset/ILSVRC2012_val_00017989.bin 224 224 +492 ./prep_dataset/ILSVRC2012_val_00043305.bin 224 224 +493 ./prep_dataset/ILSVRC2012_val_00001484.bin 224 224 +494 ./prep_dataset/ILSVRC2012_val_00021029.bin 224 224 +495 ./prep_dataset/ILSVRC2012_val_00039255.bin 224 224 +496 ./prep_dataset/ILSVRC2012_val_00029299.bin 224 224 +497 ./prep_dataset/ILSVRC2012_val_00014364.bin 224 224 +498 ./prep_dataset/ILSVRC2012_val_00005300.bin 224 224 +499 ./prep_dataset/ILSVRC2012_val_00028606.bin 224 224 +500 ./prep_dataset/ILSVRC2012_val_00035925.bin 224 224 +501 ./prep_dataset/ILSVRC2012_val_00045381.bin 224 224 +502 ./prep_dataset/ILSVRC2012_val_00007308.bin 224 224 +503 ./prep_dataset/ILSVRC2012_val_00015026.bin 224 224 +504 ./prep_dataset/ILSVRC2012_val_00024404.bin 224 224 +505 ./prep_dataset/ILSVRC2012_val_00028774.bin 224 224 +506 ./prep_dataset/ILSVRC2012_val_00021495.bin 224 224 +507 ./prep_dataset/ILSVRC2012_val_00025627.bin 224 224 +508 ./prep_dataset/ILSVRC2012_val_00027104.bin 224 224 +509 ./prep_dataset/ILSVRC2012_val_00033994.bin 224 224 +510 ./prep_dataset/ILSVRC2012_val_00025974.bin 224 224 +511 ./prep_dataset/ILSVRC2012_val_00018623.bin 224 224 +512 ./prep_dataset/ILSVRC2012_val_00034170.bin 224 224 +513 ./prep_dataset/ILSVRC2012_val_00015302.bin 224 224 +514 ./prep_dataset/ILSVRC2012_val_00020190.bin 224 224 +515 ./prep_dataset/ILSVRC2012_val_00001749.bin 224 224 +516 ./prep_dataset/ILSVRC2012_val_00032353.bin 224 224 +517 ./prep_dataset/ILSVRC2012_val_00014027.bin 224 224 +518 ./prep_dataset/ILSVRC2012_val_00013334.bin 224 224 +519 ./prep_dataset/ILSVRC2012_val_00010164.bin 224 224 +520 ./prep_dataset/ILSVRC2012_val_00011608.bin 224 224 +521 ./prep_dataset/ILSVRC2012_val_00037424.bin 224 224 +522 ./prep_dataset/ILSVRC2012_val_00045921.bin 224 224 +523 ./prep_dataset/ILSVRC2012_val_00005151.bin 224 224 +524 ./prep_dataset/ILSVRC2012_val_00032390.bin 224 224 +525 ./prep_dataset/ILSVRC2012_val_00046037.bin 224 224 +526 ./prep_dataset/ILSVRC2012_val_00025445.bin 224 224 +527 ./prep_dataset/ILSVRC2012_val_00002538.bin 224 224 +528 ./prep_dataset/ILSVRC2012_val_00010224.bin 224 224 +529 ./prep_dataset/ILSVRC2012_val_00007846.bin 224 224 +530 ./prep_dataset/ILSVRC2012_val_00021427.bin 224 224 +531 ./prep_dataset/ILSVRC2012_val_00047818.bin 224 224 +532 ./prep_dataset/ILSVRC2012_val_00031012.bin 224 224 +533 ./prep_dataset/ILSVRC2012_val_00031516.bin 224 224 +534 ./prep_dataset/ILSVRC2012_val_00035272.bin 224 224 +535 ./prep_dataset/ILSVRC2012_val_00003181.bin 224 224 +536 ./prep_dataset/ILSVRC2012_val_00043717.bin 224 224 +537 ./prep_dataset/ILSVRC2012_val_00009084.bin 224 224 +538 ./prep_dataset/ILSVRC2012_val_00044822.bin 224 224 +539 ./prep_dataset/ILSVRC2012_val_00021765.bin 224 224 +540 ./prep_dataset/ILSVRC2012_val_00034708.bin 224 224 +541 ./prep_dataset/ILSVRC2012_val_00005513.bin 224 224 +542 ./prep_dataset/ILSVRC2012_val_00043361.bin 224 224 +543 ./prep_dataset/ILSVRC2012_val_00013568.bin 224 224 +544 ./prep_dataset/ILSVRC2012_val_00014061.bin 224 224 +545 ./prep_dataset/ILSVRC2012_val_00010469.bin 224 224 +546 ./prep_dataset/ILSVRC2012_val_00039895.bin 224 224 +547 ./prep_dataset/ILSVRC2012_val_00040141.bin 224 224 +548 ./prep_dataset/ILSVRC2012_val_00023508.bin 224 224 +549 ./prep_dataset/ILSVRC2012_val_00032410.bin 224 224 +550 ./prep_dataset/ILSVRC2012_val_00029390.bin 224 224 +551 ./prep_dataset/ILSVRC2012_val_00030063.bin 224 224 +552 ./prep_dataset/ILSVRC2012_val_00037440.bin 224 224 +553 ./prep_dataset/ILSVRC2012_val_00048866.bin 224 224 +554 ./prep_dataset/ILSVRC2012_val_00040642.bin 224 224 +555 ./prep_dataset/ILSVRC2012_val_00001912.bin 224 224 +556 ./prep_dataset/ILSVRC2012_val_00034748.bin 224 224 +557 ./prep_dataset/ILSVRC2012_val_00014646.bin 224 224 +558 ./prep_dataset/ILSVRC2012_val_00021661.bin 224 224 +559 ./prep_dataset/ILSVRC2012_val_00020402.bin 224 224 +560 ./prep_dataset/ILSVRC2012_val_00002451.bin 224 224 +561 ./prep_dataset/ILSVRC2012_val_00039513.bin 224 224 +562 ./prep_dataset/ILSVRC2012_val_00007433.bin 224 224 +563 ./prep_dataset/ILSVRC2012_val_00042019.bin 224 224 +564 ./prep_dataset/ILSVRC2012_val_00012586.bin 224 224 +565 ./prep_dataset/ILSVRC2012_val_00027756.bin 224 224 +566 ./prep_dataset/ILSVRC2012_val_00047006.bin 224 224 +567 ./prep_dataset/ILSVRC2012_val_00042290.bin 224 224 +568 ./prep_dataset/ILSVRC2012_val_00049682.bin 224 224 +569 ./prep_dataset/ILSVRC2012_val_00024984.bin 224 224 +570 ./prep_dataset/ILSVRC2012_val_00047282.bin 224 224 +571 ./prep_dataset/ILSVRC2012_val_00025720.bin 224 224 +572 ./prep_dataset/ILSVRC2012_val_00031427.bin 224 224 +573 ./prep_dataset/ILSVRC2012_val_00008772.bin 224 224 +574 ./prep_dataset/ILSVRC2012_val_00044220.bin 224 224 +575 ./prep_dataset/ILSVRC2012_val_00042172.bin 224 224 +576 ./prep_dataset/ILSVRC2012_val_00025461.bin 224 224 +577 ./prep_dataset/ILSVRC2012_val_00023961.bin 224 224 +578 ./prep_dataset/ILSVRC2012_val_00013470.bin 224 224 +579 ./prep_dataset/ILSVRC2012_val_00017116.bin 224 224 +580 ./prep_dataset/ILSVRC2012_val_00041919.bin 224 224 +581 ./prep_dataset/ILSVRC2012_val_00042392.bin 224 224 +582 ./prep_dataset/ILSVRC2012_val_00024418.bin 224 224 +583 ./prep_dataset/ILSVRC2012_val_00008194.bin 224 224 +584 ./prep_dataset/ILSVRC2012_val_00000274.bin 224 224 +585 ./prep_dataset/ILSVRC2012_val_00025584.bin 224 224 +586 ./prep_dataset/ILSVRC2012_val_00009439.bin 224 224 +587 ./prep_dataset/ILSVRC2012_val_00015892.bin 224 224 +588 ./prep_dataset/ILSVRC2012_val_00034732.bin 224 224 +589 ./prep_dataset/ILSVRC2012_val_00000784.bin 224 224 +590 ./prep_dataset/ILSVRC2012_val_00001461.bin 224 224 +591 ./prep_dataset/ILSVRC2012_val_00001693.bin 224 224 +592 ./prep_dataset/ILSVRC2012_val_00002465.bin 224 224 +593 ./prep_dataset/ILSVRC2012_val_00032567.bin 224 224 +594 ./prep_dataset/ILSVRC2012_val_00037143.bin 224 224 +595 ./prep_dataset/ILSVRC2012_val_00007558.bin 224 224 +596 ./prep_dataset/ILSVRC2012_val_00017260.bin 224 224 +597 ./prep_dataset/ILSVRC2012_val_00008517.bin 224 224 +598 ./prep_dataset/ILSVRC2012_val_00031819.bin 224 224 +599 ./prep_dataset/ILSVRC2012_val_00041753.bin 224 224 +600 ./prep_dataset/ILSVRC2012_val_00016981.bin 224 224 +601 ./prep_dataset/ILSVRC2012_val_00049849.bin 224 224 +602 ./prep_dataset/ILSVRC2012_val_00019998.bin 224 224 +603 ./prep_dataset/ILSVRC2012_val_00047133.bin 224 224 +604 ./prep_dataset/ILSVRC2012_val_00020953.bin 224 224 +605 ./prep_dataset/ILSVRC2012_val_00022921.bin 224 224 +606 ./prep_dataset/ILSVRC2012_val_00023693.bin 224 224 +607 ./prep_dataset/ILSVRC2012_val_00038632.bin 224 224 +608 ./prep_dataset/ILSVRC2012_val_00026165.bin 224 224 +609 ./prep_dataset/ILSVRC2012_val_00005046.bin 224 224 +610 ./prep_dataset/ILSVRC2012_val_00007420.bin 224 224 +611 ./prep_dataset/ILSVRC2012_val_00027349.bin 224 224 +612 ./prep_dataset/ILSVRC2012_val_00027640.bin 224 224 +613 ./prep_dataset/ILSVRC2012_val_00023127.bin 224 224 +614 ./prep_dataset/ILSVRC2012_val_00000349.bin 224 224 +615 ./prep_dataset/ILSVRC2012_val_00004965.bin 224 224 +616 ./prep_dataset/ILSVRC2012_val_00045099.bin 224 224 +617 ./prep_dataset/ILSVRC2012_val_00014445.bin 224 224 +618 ./prep_dataset/ILSVRC2012_val_00026203.bin 224 224 +619 ./prep_dataset/ILSVRC2012_val_00027883.bin 224 224 +620 ./prep_dataset/ILSVRC2012_val_00030352.bin 224 224 +621 ./prep_dataset/ILSVRC2012_val_00004880.bin 224 224 +622 ./prep_dataset/ILSVRC2012_val_00002897.bin 224 224 +623 ./prep_dataset/ILSVRC2012_val_00028487.bin 224 224 +624 ./prep_dataset/ILSVRC2012_val_00005738.bin 224 224 +625 ./prep_dataset/ILSVRC2012_val_00004399.bin 224 224 +626 ./prep_dataset/ILSVRC2012_val_00029020.bin 224 224 +627 ./prep_dataset/ILSVRC2012_val_00030012.bin 224 224 +628 ./prep_dataset/ILSVRC2012_val_00034603.bin 224 224 +629 ./prep_dataset/ILSVRC2012_val_00033828.bin 224 224 +630 ./prep_dataset/ILSVRC2012_val_00040263.bin 224 224 +631 ./prep_dataset/ILSVRC2012_val_00023615.bin 224 224 +632 ./prep_dataset/ILSVRC2012_val_00009382.bin 224 224 +633 ./prep_dataset/ILSVRC2012_val_00037717.bin 224 224 +634 ./prep_dataset/ILSVRC2012_val_00001740.bin 224 224 +635 ./prep_dataset/ILSVRC2012_val_00048246.bin 224 224 +636 ./prep_dataset/ILSVRC2012_val_00026876.bin 224 224 +637 ./prep_dataset/ILSVRC2012_val_00008908.bin 224 224 +638 ./prep_dataset/ILSVRC2012_val_00025564.bin 224 224 +639 ./prep_dataset/ILSVRC2012_val_00025009.bin 224 224 +640 ./prep_dataset/ILSVRC2012_val_00048204.bin 224 224 +641 ./prep_dataset/ILSVRC2012_val_00036111.bin 224 224 +642 ./prep_dataset/ILSVRC2012_val_00014663.bin 224 224 +643 ./prep_dataset/ILSVRC2012_val_00021343.bin 224 224 +644 ./prep_dataset/ILSVRC2012_val_00005301.bin 224 224 +645 ./prep_dataset/ILSVRC2012_val_00010474.bin 224 224 +646 ./prep_dataset/ILSVRC2012_val_00040639.bin 224 224 +647 ./prep_dataset/ILSVRC2012_val_00044217.bin 224 224 +648 ./prep_dataset/ILSVRC2012_val_00018005.bin 224 224 +649 ./prep_dataset/ILSVRC2012_val_00033704.bin 224 224 +650 ./prep_dataset/ILSVRC2012_val_00013624.bin 224 224 +651 ./prep_dataset/ILSVRC2012_val_00033893.bin 224 224 +652 ./prep_dataset/ILSVRC2012_val_00048867.bin 224 224 +653 ./prep_dataset/ILSVRC2012_val_00037056.bin 224 224 +654 ./prep_dataset/ILSVRC2012_val_00003640.bin 224 224 +655 ./prep_dataset/ILSVRC2012_val_00036695.bin 224 224 +656 ./prep_dataset/ILSVRC2012_val_00039380.bin 224 224 +657 ./prep_dataset/ILSVRC2012_val_00017987.bin 224 224 +658 ./prep_dataset/ILSVRC2012_val_00043752.bin 224 224 +659 ./prep_dataset/ILSVRC2012_val_00033172.bin 224 224 +660 ./prep_dataset/ILSVRC2012_val_00036486.bin 224 224 +661 ./prep_dataset/ILSVRC2012_val_00019845.bin 224 224 +662 ./prep_dataset/ILSVRC2012_val_00021989.bin 224 224 +663 ./prep_dataset/ILSVRC2012_val_00042083.bin 224 224 +664 ./prep_dataset/ILSVRC2012_val_00002287.bin 224 224 +665 ./prep_dataset/ILSVRC2012_val_00031989.bin 224 224 +666 ./prep_dataset/ILSVRC2012_val_00003681.bin 224 224 +667 ./prep_dataset/ILSVRC2012_val_00001366.bin 224 224 +668 ./prep_dataset/ILSVRC2012_val_00016234.bin 224 224 +669 ./prep_dataset/ILSVRC2012_val_00009855.bin 224 224 +670 ./prep_dataset/ILSVRC2012_val_00022123.bin 224 224 +671 ./prep_dataset/ILSVRC2012_val_00045666.bin 224 224 +672 ./prep_dataset/ILSVRC2012_val_00044666.bin 224 224 +673 ./prep_dataset/ILSVRC2012_val_00003189.bin 224 224 +674 ./prep_dataset/ILSVRC2012_val_00003836.bin 224 224 +675 ./prep_dataset/ILSVRC2012_val_00019808.bin 224 224 +676 ./prep_dataset/ILSVRC2012_val_00021557.bin 224 224 +677 ./prep_dataset/ILSVRC2012_val_00033028.bin 224 224 +678 ./prep_dataset/ILSVRC2012_val_00041268.bin 224 224 +679 ./prep_dataset/ILSVRC2012_val_00037069.bin 224 224 +680 ./prep_dataset/ILSVRC2012_val_00019561.bin 224 224 +681 ./prep_dataset/ILSVRC2012_val_00021728.bin 224 224 +682 ./prep_dataset/ILSVRC2012_val_00005448.bin 224 224 +683 ./prep_dataset/ILSVRC2012_val_00026148.bin 224 224 +684 ./prep_dataset/ILSVRC2012_val_00025628.bin 224 224 +685 ./prep_dataset/ILSVRC2012_val_00043734.bin 224 224 +686 ./prep_dataset/ILSVRC2012_val_00031044.bin 224 224 +687 ./prep_dataset/ILSVRC2012_val_00021692.bin 224 224 +688 ./prep_dataset/ILSVRC2012_val_00037650.bin 224 224 +689 ./prep_dataset/ILSVRC2012_val_00008381.bin 224 224 +690 ./prep_dataset/ILSVRC2012_val_00024477.bin 224 224 +691 ./prep_dataset/ILSVRC2012_val_00022166.bin 224 224 +692 ./prep_dataset/ILSVRC2012_val_00042111.bin 224 224 +693 ./prep_dataset/ILSVRC2012_val_00010966.bin 224 224 +694 ./prep_dataset/ILSVRC2012_val_00028474.bin 224 224 +695 ./prep_dataset/ILSVRC2012_val_00021927.bin 224 224 +696 ./prep_dataset/ILSVRC2012_val_00048569.bin 224 224 +697 ./prep_dataset/ILSVRC2012_val_00038428.bin 224 224 +698 ./prep_dataset/ILSVRC2012_val_00049897.bin 224 224 +699 ./prep_dataset/ILSVRC2012_val_00027560.bin 224 224 +700 ./prep_dataset/ILSVRC2012_val_00028981.bin 224 224 +701 ./prep_dataset/ILSVRC2012_val_00011728.bin 224 224 +702 ./prep_dataset/ILSVRC2012_val_00006527.bin 224 224 +703 ./prep_dataset/ILSVRC2012_val_00013097.bin 224 224 +704 ./prep_dataset/ILSVRC2012_val_00048573.bin 224 224 +705 ./prep_dataset/ILSVRC2012_val_00046303.bin 224 224 +706 ./prep_dataset/ILSVRC2012_val_00045483.bin 224 224 +707 ./prep_dataset/ILSVRC2012_val_00003609.bin 224 224 +708 ./prep_dataset/ILSVRC2012_val_00027624.bin 224 224 +709 ./prep_dataset/ILSVRC2012_val_00036724.bin 224 224 +710 ./prep_dataset/ILSVRC2012_val_00033872.bin 224 224 +711 ./prep_dataset/ILSVRC2012_val_00008105.bin 224 224 +712 ./prep_dataset/ILSVRC2012_val_00014252.bin 224 224 +713 ./prep_dataset/ILSVRC2012_val_00037270.bin 224 224 +714 ./prep_dataset/ILSVRC2012_val_00001993.bin 224 224 +715 ./prep_dataset/ILSVRC2012_val_00000311.bin 224 224 +716 ./prep_dataset/ILSVRC2012_val_00010850.bin 224 224 +717 ./prep_dataset/ILSVRC2012_val_00008907.bin 224 224 +718 ./prep_dataset/ILSVRC2012_val_00026074.bin 224 224 +719 ./prep_dataset/ILSVRC2012_val_00024371.bin 224 224 +720 ./prep_dataset/ILSVRC2012_val_00002552.bin 224 224 +721 ./prep_dataset/ILSVRC2012_val_00013484.bin 224 224 +722 ./prep_dataset/ILSVRC2012_val_00041714.bin 224 224 +723 ./prep_dataset/ILSVRC2012_val_00049272.bin 224 224 +724 ./prep_dataset/ILSVRC2012_val_00040823.bin 224 224 +725 ./prep_dataset/ILSVRC2012_val_00008019.bin 224 224 +726 ./prep_dataset/ILSVRC2012_val_00014107.bin 224 224 +727 ./prep_dataset/ILSVRC2012_val_00041894.bin 224 224 +728 ./prep_dataset/ILSVRC2012_val_00001904.bin 224 224 +729 ./prep_dataset/ILSVRC2012_val_00036794.bin 224 224 +730 ./prep_dataset/ILSVRC2012_val_00040073.bin 224 224 +731 ./prep_dataset/ILSVRC2012_val_00029686.bin 224 224 +732 ./prep_dataset/ILSVRC2012_val_00039444.bin 224 224 +733 ./prep_dataset/ILSVRC2012_val_00017657.bin 224 224 +734 ./prep_dataset/ILSVRC2012_val_00010212.bin 224 224 +735 ./prep_dataset/ILSVRC2012_val_00041692.bin 224 224 +736 ./prep_dataset/ILSVRC2012_val_00011132.bin 224 224 +737 ./prep_dataset/ILSVRC2012_val_00046512.bin 224 224 +738 ./prep_dataset/ILSVRC2012_val_00025148.bin 224 224 +739 ./prep_dataset/ILSVRC2012_val_00005308.bin 224 224 +740 ./prep_dataset/ILSVRC2012_val_00028182.bin 224 224 +741 ./prep_dataset/ILSVRC2012_val_00037428.bin 224 224 +742 ./prep_dataset/ILSVRC2012_val_00034187.bin 224 224 +743 ./prep_dataset/ILSVRC2012_val_00009997.bin 224 224 +744 ./prep_dataset/ILSVRC2012_val_00047961.bin 224 224 +745 ./prep_dataset/ILSVRC2012_val_00015753.bin 224 224 +746 ./prep_dataset/ILSVRC2012_val_00026937.bin 224 224 +747 ./prep_dataset/ILSVRC2012_val_00008299.bin 224 224 +748 ./prep_dataset/ILSVRC2012_val_00041251.bin 224 224 +749 ./prep_dataset/ILSVRC2012_val_00016860.bin 224 224 +750 ./prep_dataset/ILSVRC2012_val_00026675.bin 224 224 +751 ./prep_dataset/ILSVRC2012_val_00019284.bin 224 224 +752 ./prep_dataset/ILSVRC2012_val_00046521.bin 224 224 +753 ./prep_dataset/ILSVRC2012_val_00010081.bin 224 224 +754 ./prep_dataset/ILSVRC2012_val_00042536.bin 224 224 +755 ./prep_dataset/ILSVRC2012_val_00037984.bin 224 224 +756 ./prep_dataset/ILSVRC2012_val_00043810.bin 224 224 +757 ./prep_dataset/ILSVRC2012_val_00032816.bin 224 224 +758 ./prep_dataset/ILSVRC2012_val_00016989.bin 224 224 +759 ./prep_dataset/ILSVRC2012_val_00018003.bin 224 224 +760 ./prep_dataset/ILSVRC2012_val_00041900.bin 224 224 +761 ./prep_dataset/ILSVRC2012_val_00017696.bin 224 224 +762 ./prep_dataset/ILSVRC2012_val_00022861.bin 224 224 +763 ./prep_dataset/ILSVRC2012_val_00029770.bin 224 224 +764 ./prep_dataset/ILSVRC2012_val_00034225.bin 224 224 +765 ./prep_dataset/ILSVRC2012_val_00033182.bin 224 224 +766 ./prep_dataset/ILSVRC2012_val_00045904.bin 224 224 +767 ./prep_dataset/ILSVRC2012_val_00049276.bin 224 224 +768 ./prep_dataset/ILSVRC2012_val_00047379.bin 224 224 +769 ./prep_dataset/ILSVRC2012_val_00016741.bin 224 224 +770 ./prep_dataset/ILSVRC2012_val_00001572.bin 224 224 +771 ./prep_dataset/ILSVRC2012_val_00046947.bin 224 224 +772 ./prep_dataset/ILSVRC2012_val_00037860.bin 224 224 +773 ./prep_dataset/ILSVRC2012_val_00044755.bin 224 224 +774 ./prep_dataset/ILSVRC2012_val_00000509.bin 224 224 +775 ./prep_dataset/ILSVRC2012_val_00032539.bin 224 224 +776 ./prep_dataset/ILSVRC2012_val_00043526.bin 224 224 +777 ./prep_dataset/ILSVRC2012_val_00027077.bin 224 224 +778 ./prep_dataset/ILSVRC2012_val_00016066.bin 224 224 +779 ./prep_dataset/ILSVRC2012_val_00031402.bin 224 224 +780 ./prep_dataset/ILSVRC2012_val_00009132.bin 224 224 +781 ./prep_dataset/ILSVRC2012_val_00037957.bin 224 224 +782 ./prep_dataset/ILSVRC2012_val_00003799.bin 224 224 +783 ./prep_dataset/ILSVRC2012_val_00002508.bin 224 224 +784 ./prep_dataset/ILSVRC2012_val_00000958.bin 224 224 +785 ./prep_dataset/ILSVRC2012_val_00010360.bin 224 224 +786 ./prep_dataset/ILSVRC2012_val_00005479.bin 224 224 +787 ./prep_dataset/ILSVRC2012_val_00039642.bin 224 224 +788 ./prep_dataset/ILSVRC2012_val_00033418.bin 224 224 +789 ./prep_dataset/ILSVRC2012_val_00048879.bin 224 224 +790 ./prep_dataset/ILSVRC2012_val_00043959.bin 224 224 +791 ./prep_dataset/ILSVRC2012_val_00019286.bin 224 224 +792 ./prep_dataset/ILSVRC2012_val_00021416.bin 224 224 +793 ./prep_dataset/ILSVRC2012_val_00042173.bin 224 224 +794 ./prep_dataset/ILSVRC2012_val_00034631.bin 224 224 +795 ./prep_dataset/ILSVRC2012_val_00040036.bin 224 224 +796 ./prep_dataset/ILSVRC2012_val_00008434.bin 224 224 +797 ./prep_dataset/ILSVRC2012_val_00036237.bin 224 224 +798 ./prep_dataset/ILSVRC2012_val_00044337.bin 224 224 +799 ./prep_dataset/ILSVRC2012_val_00044139.bin 224 224 +800 ./prep_dataset/ILSVRC2012_val_00013778.bin 224 224 +801 ./prep_dataset/ILSVRC2012_val_00048238.bin 224 224 +802 ./prep_dataset/ILSVRC2012_val_00049054.bin 224 224 +803 ./prep_dataset/ILSVRC2012_val_00038176.bin 224 224 +804 ./prep_dataset/ILSVRC2012_val_00025391.bin 224 224 +805 ./prep_dataset/ILSVRC2012_val_00024207.bin 224 224 +806 ./prep_dataset/ILSVRC2012_val_00027522.bin 224 224 +807 ./prep_dataset/ILSVRC2012_val_00013578.bin 224 224 +808 ./prep_dataset/ILSVRC2012_val_00020452.bin 224 224 +809 ./prep_dataset/ILSVRC2012_val_00025894.bin 224 224 +810 ./prep_dataset/ILSVRC2012_val_00049862.bin 224 224 +811 ./prep_dataset/ILSVRC2012_val_00038724.bin 224 224 +812 ./prep_dataset/ILSVRC2012_val_00004846.bin 224 224 +813 ./prep_dataset/ILSVRC2012_val_00037298.bin 224 224 +814 ./prep_dataset/ILSVRC2012_val_00002731.bin 224 224 +815 ./prep_dataset/ILSVRC2012_val_00000704.bin 224 224 +816 ./prep_dataset/ILSVRC2012_val_00014163.bin 224 224 +817 ./prep_dataset/ILSVRC2012_val_00016446.bin 224 224 +818 ./prep_dataset/ILSVRC2012_val_00036742.bin 224 224 +819 ./prep_dataset/ILSVRC2012_val_00013148.bin 224 224 +820 ./prep_dataset/ILSVRC2012_val_00009363.bin 224 224 +821 ./prep_dataset/ILSVRC2012_val_00027034.bin 224 224 +822 ./prep_dataset/ILSVRC2012_val_00043629.bin 224 224 +823 ./prep_dataset/ILSVRC2012_val_00023271.bin 224 224 +824 ./prep_dataset/ILSVRC2012_val_00015710.bin 224 224 +825 ./prep_dataset/ILSVRC2012_val_00009665.bin 224 224 +826 ./prep_dataset/ILSVRC2012_val_00001894.bin 224 224 +827 ./prep_dataset/ILSVRC2012_val_00012731.bin 224 224 +828 ./prep_dataset/ILSVRC2012_val_00045007.bin 224 224 +829 ./prep_dataset/ILSVRC2012_val_00012783.bin 224 224 +830 ./prep_dataset/ILSVRC2012_val_00040572.bin 224 224 +831 ./prep_dataset/ILSVRC2012_val_00009681.bin 224 224 +832 ./prep_dataset/ILSVRC2012_val_00032164.bin 224 224 +833 ./prep_dataset/ILSVRC2012_val_00009603.bin 224 224 +834 ./prep_dataset/ILSVRC2012_val_00008121.bin 224 224 +835 ./prep_dataset/ILSVRC2012_val_00040610.bin 224 224 +836 ./prep_dataset/ILSVRC2012_val_00032384.bin 224 224 +837 ./prep_dataset/ILSVRC2012_val_00026388.bin 224 224 +838 ./prep_dataset/ILSVRC2012_val_00045372.bin 224 224 +839 ./prep_dataset/ILSVRC2012_val_00006860.bin 224 224 +840 ./prep_dataset/ILSVRC2012_val_00011528.bin 224 224 +841 ./prep_dataset/ILSVRC2012_val_00047355.bin 224 224 +842 ./prep_dataset/ILSVRC2012_val_00035254.bin 224 224 +843 ./prep_dataset/ILSVRC2012_val_00012349.bin 224 224 +844 ./prep_dataset/ILSVRC2012_val_00002329.bin 224 224 +845 ./prep_dataset/ILSVRC2012_val_00045151.bin 224 224 +846 ./prep_dataset/ILSVRC2012_val_00003291.bin 224 224 +847 ./prep_dataset/ILSVRC2012_val_00041758.bin 224 224 +848 ./prep_dataset/ILSVRC2012_val_00037827.bin 224 224 +849 ./prep_dataset/ILSVRC2012_val_00018950.bin 224 224 +850 ./prep_dataset/ILSVRC2012_val_00004321.bin 224 224 +851 ./prep_dataset/ILSVRC2012_val_00046606.bin 224 224 +852 ./prep_dataset/ILSVRC2012_val_00007271.bin 224 224 +853 ./prep_dataset/ILSVRC2012_val_00013613.bin 224 224 +854 ./prep_dataset/ILSVRC2012_val_00049422.bin 224 224 +855 ./prep_dataset/ILSVRC2012_val_00029587.bin 224 224 +856 ./prep_dataset/ILSVRC2012_val_00015936.bin 224 224 +857 ./prep_dataset/ILSVRC2012_val_00038005.bin 224 224 +858 ./prep_dataset/ILSVRC2012_val_00049626.bin 224 224 +859 ./prep_dataset/ILSVRC2012_val_00000245.bin 224 224 +860 ./prep_dataset/ILSVRC2012_val_00037415.bin 224 224 +861 ./prep_dataset/ILSVRC2012_val_00019113.bin 224 224 +862 ./prep_dataset/ILSVRC2012_val_00039871.bin 224 224 +863 ./prep_dataset/ILSVRC2012_val_00005103.bin 224 224 +864 ./prep_dataset/ILSVRC2012_val_00023237.bin 224 224 +865 ./prep_dataset/ILSVRC2012_val_00045640.bin 224 224 +866 ./prep_dataset/ILSVRC2012_val_00040774.bin 224 224 +867 ./prep_dataset/ILSVRC2012_val_00027957.bin 224 224 +868 ./prep_dataset/ILSVRC2012_val_00048339.bin 224 224 +869 ./prep_dataset/ILSVRC2012_val_00024379.bin 224 224 +870 ./prep_dataset/ILSVRC2012_val_00024852.bin 224 224 +871 ./prep_dataset/ILSVRC2012_val_00031253.bin 224 224 +872 ./prep_dataset/ILSVRC2012_val_00001396.bin 224 224 +873 ./prep_dataset/ILSVRC2012_val_00006422.bin 224 224 +874 ./prep_dataset/ILSVRC2012_val_00021966.bin 224 224 +875 ./prep_dataset/ILSVRC2012_val_00016942.bin 224 224 +876 ./prep_dataset/ILSVRC2012_val_00039297.bin 224 224 +877 ./prep_dataset/ILSVRC2012_val_00011701.bin 224 224 +878 ./prep_dataset/ILSVRC2012_val_00030077.bin 224 224 +879 ./prep_dataset/ILSVRC2012_val_00024775.bin 224 224 +880 ./prep_dataset/ILSVRC2012_val_00019983.bin 224 224 +881 ./prep_dataset/ILSVRC2012_val_00003318.bin 224 224 +882 ./prep_dataset/ILSVRC2012_val_00039735.bin 224 224 +883 ./prep_dataset/ILSVRC2012_val_00048031.bin 224 224 +884 ./prep_dataset/ILSVRC2012_val_00012500.bin 224 224 +885 ./prep_dataset/ILSVRC2012_val_00018421.bin 224 224 +886 ./prep_dataset/ILSVRC2012_val_00034050.bin 224 224 +887 ./prep_dataset/ILSVRC2012_val_00024603.bin 224 224 +888 ./prep_dataset/ILSVRC2012_val_00024877.bin 224 224 +889 ./prep_dataset/ILSVRC2012_val_00045389.bin 224 224 +890 ./prep_dataset/ILSVRC2012_val_00021068.bin 224 224 +891 ./prep_dataset/ILSVRC2012_val_00034268.bin 224 224 +892 ./prep_dataset/ILSVRC2012_val_00038113.bin 224 224 +893 ./prep_dataset/ILSVRC2012_val_00026231.bin 224 224 +894 ./prep_dataset/ILSVRC2012_val_00041409.bin 224 224 +895 ./prep_dataset/ILSVRC2012_val_00009764.bin 224 224 +896 ./prep_dataset/ILSVRC2012_val_00000735.bin 224 224 +897 ./prep_dataset/ILSVRC2012_val_00001001.bin 224 224 +898 ./prep_dataset/ILSVRC2012_val_00019197.bin 224 224 +899 ./prep_dataset/ILSVRC2012_val_00012329.bin 224 224 +900 ./prep_dataset/ILSVRC2012_val_00005171.bin 224 224 +901 ./prep_dataset/ILSVRC2012_val_00001683.bin 224 224 +902 ./prep_dataset/ILSVRC2012_val_00037326.bin 224 224 +903 ./prep_dataset/ILSVRC2012_val_00047780.bin 224 224 +904 ./prep_dataset/ILSVRC2012_val_00019189.bin 224 224 +905 ./prep_dataset/ILSVRC2012_val_00043540.bin 224 224 +906 ./prep_dataset/ILSVRC2012_val_00046700.bin 224 224 +907 ./prep_dataset/ILSVRC2012_val_00011247.bin 224 224 +908 ./prep_dataset/ILSVRC2012_val_00005455.bin 224 224 +909 ./prep_dataset/ILSVRC2012_val_00020878.bin 224 224 +910 ./prep_dataset/ILSVRC2012_val_00037159.bin 224 224 +911 ./prep_dataset/ILSVRC2012_val_00040320.bin 224 224 +912 ./prep_dataset/ILSVRC2012_val_00015537.bin 224 224 +913 ./prep_dataset/ILSVRC2012_val_00023602.bin 224 224 +914 ./prep_dataset/ILSVRC2012_val_00020317.bin 224 224 +915 ./prep_dataset/ILSVRC2012_val_00049304.bin 224 224 +916 ./prep_dataset/ILSVRC2012_val_00015139.bin 224 224 +917 ./prep_dataset/ILSVRC2012_val_00020809.bin 224 224 +918 ./prep_dataset/ILSVRC2012_val_00034487.bin 224 224 +919 ./prep_dataset/ILSVRC2012_val_00048577.bin 224 224 +920 ./prep_dataset/ILSVRC2012_val_00019047.bin 224 224 +921 ./prep_dataset/ILSVRC2012_val_00045577.bin 224 224 +922 ./prep_dataset/ILSVRC2012_val_00041542.bin 224 224 +923 ./prep_dataset/ILSVRC2012_val_00034079.bin 224 224 +924 ./prep_dataset/ILSVRC2012_val_00044212.bin 224 224 +925 ./prep_dataset/ILSVRC2012_val_00049625.bin 224 224 +926 ./prep_dataset/ILSVRC2012_val_00048334.bin 224 224 +927 ./prep_dataset/ILSVRC2012_val_00048525.bin 224 224 +928 ./prep_dataset/ILSVRC2012_val_00016772.bin 224 224 +929 ./prep_dataset/ILSVRC2012_val_00046762.bin 224 224 +930 ./prep_dataset/ILSVRC2012_val_00022590.bin 224 224 +931 ./prep_dataset/ILSVRC2012_val_00031565.bin 224 224 +932 ./prep_dataset/ILSVRC2012_val_00040413.bin 224 224 +933 ./prep_dataset/ILSVRC2012_val_00025992.bin 224 224 +934 ./prep_dataset/ILSVRC2012_val_00041342.bin 224 224 +935 ./prep_dataset/ILSVRC2012_val_00005875.bin 224 224 +936 ./prep_dataset/ILSVRC2012_val_00016280.bin 224 224 +937 ./prep_dataset/ILSVRC2012_val_00014732.bin 224 224 +938 ./prep_dataset/ILSVRC2012_val_00022598.bin 224 224 +939 ./prep_dataset/ILSVRC2012_val_00003810.bin 224 224 +940 ./prep_dataset/ILSVRC2012_val_00015387.bin 224 224 +941 ./prep_dataset/ILSVRC2012_val_00011983.bin 224 224 +942 ./prep_dataset/ILSVRC2012_val_00037861.bin 224 224 +943 ./prep_dataset/ILSVRC2012_val_00029992.bin 224 224 +944 ./prep_dataset/ILSVRC2012_val_00047642.bin 224 224 +945 ./prep_dataset/ILSVRC2012_val_00037937.bin 224 224 +946 ./prep_dataset/ILSVRC2012_val_00020588.bin 224 224 +947 ./prep_dataset/ILSVRC2012_val_00000009.bin 224 224 +948 ./prep_dataset/ILSVRC2012_val_00040501.bin 224 224 +949 ./prep_dataset/ILSVRC2012_val_00018591.bin 224 224 +950 ./prep_dataset/ILSVRC2012_val_00005164.bin 224 224 +951 ./prep_dataset/ILSVRC2012_val_00009527.bin 224 224 +952 ./prep_dataset/ILSVRC2012_val_00044036.bin 224 224 +953 ./prep_dataset/ILSVRC2012_val_00033560.bin 224 224 +954 ./prep_dataset/ILSVRC2012_val_00045175.bin 224 224 +955 ./prep_dataset/ILSVRC2012_val_00008684.bin 224 224 +956 ./prep_dataset/ILSVRC2012_val_00040994.bin 224 224 +957 ./prep_dataset/ILSVRC2012_val_00042219.bin 224 224 +958 ./prep_dataset/ILSVRC2012_val_00037112.bin 224 224 +959 ./prep_dataset/ILSVRC2012_val_00043241.bin 224 224 +960 ./prep_dataset/ILSVRC2012_val_00003917.bin 224 224 +961 ./prep_dataset/ILSVRC2012_val_00010006.bin 224 224 +962 ./prep_dataset/ILSVRC2012_val_00024654.bin 224 224 +963 ./prep_dataset/ILSVRC2012_val_00049256.bin 224 224 +964 ./prep_dataset/ILSVRC2012_val_00030450.bin 224 224 +965 ./prep_dataset/ILSVRC2012_val_00019835.bin 224 224 +966 ./prep_dataset/ILSVRC2012_val_00042278.bin 224 224 +967 ./prep_dataset/ILSVRC2012_val_00045871.bin 224 224 +968 ./prep_dataset/ILSVRC2012_val_00012583.bin 224 224 +969 ./prep_dataset/ILSVRC2012_val_00048812.bin 224 224 +970 ./prep_dataset/ILSVRC2012_val_00011761.bin 224 224 +971 ./prep_dataset/ILSVRC2012_val_00034052.bin 224 224 +972 ./prep_dataset/ILSVRC2012_val_00002318.bin 224 224 +973 ./prep_dataset/ILSVRC2012_val_00004666.bin 224 224 +974 ./prep_dataset/ILSVRC2012_val_00001942.bin 224 224 +975 ./prep_dataset/ILSVRC2012_val_00048323.bin 224 224 +976 ./prep_dataset/ILSVRC2012_val_00023015.bin 224 224 +977 ./prep_dataset/ILSVRC2012_val_00015595.bin 224 224 +978 ./prep_dataset/ILSVRC2012_val_00014700.bin 224 224 +979 ./prep_dataset/ILSVRC2012_val_00044667.bin 224 224 +980 ./prep_dataset/ILSVRC2012_val_00015769.bin 224 224 +981 ./prep_dataset/ILSVRC2012_val_00030085.bin 224 224 +982 ./prep_dataset/ILSVRC2012_val_00039999.bin 224 224 +983 ./prep_dataset/ILSVRC2012_val_00036007.bin 224 224 +984 ./prep_dataset/ILSVRC2012_val_00030595.bin 224 224 +985 ./prep_dataset/ILSVRC2012_val_00047623.bin 224 224 +986 ./prep_dataset/ILSVRC2012_val_00018244.bin 224 224 +987 ./prep_dataset/ILSVRC2012_val_00010184.bin 224 224 +988 ./prep_dataset/ILSVRC2012_val_00016789.bin 224 224 +989 ./prep_dataset/ILSVRC2012_val_00017678.bin 224 224 +990 ./prep_dataset/ILSVRC2012_val_00049491.bin 224 224 +991 ./prep_dataset/ILSVRC2012_val_00019185.bin 224 224 +992 ./prep_dataset/ILSVRC2012_val_00042148.bin 224 224 +993 ./prep_dataset/ILSVRC2012_val_00026333.bin 224 224 +994 ./prep_dataset/ILSVRC2012_val_00024674.bin 224 224 +995 ./prep_dataset/ILSVRC2012_val_00006578.bin 224 224 +996 ./prep_dataset/ILSVRC2012_val_00006610.bin 224 224 +997 ./prep_dataset/ILSVRC2012_val_00014290.bin 224 224 +998 ./prep_dataset/ILSVRC2012_val_00035032.bin 224 224 +999 ./prep_dataset/ILSVRC2012_val_00006705.bin 224 224 +1000 ./prep_dataset/ILSVRC2012_val_00011411.bin 224 224 +1001 ./prep_dataset/ILSVRC2012_val_00007929.bin 224 224 +1002 ./prep_dataset/ILSVRC2012_val_00002595.bin 224 224 +1003 ./prep_dataset/ILSVRC2012_val_00034771.bin 224 224 +1004 ./prep_dataset/ILSVRC2012_val_00017263.bin 224 224 +1005 ./prep_dataset/ILSVRC2012_val_00032356.bin 224 224 +1006 ./prep_dataset/ILSVRC2012_val_00007043.bin 224 224 +1007 ./prep_dataset/ILSVRC2012_val_00043031.bin 224 224 +1008 ./prep_dataset/ILSVRC2012_val_00003936.bin 224 224 +1009 ./prep_dataset/ILSVRC2012_val_00048756.bin 224 224 +1010 ./prep_dataset/ILSVRC2012_val_00022948.bin 224 224 +1011 ./prep_dataset/ILSVRC2012_val_00042209.bin 224 224 +1012 ./prep_dataset/ILSVRC2012_val_00036733.bin 224 224 +1013 ./prep_dataset/ILSVRC2012_val_00038079.bin 224 224 +1014 ./prep_dataset/ILSVRC2012_val_00000703.bin 224 224 +1015 ./prep_dataset/ILSVRC2012_val_00012293.bin 224 224 +1016 ./prep_dataset/ILSVRC2012_val_00016322.bin 224 224 +1017 ./prep_dataset/ILSVRC2012_val_00044821.bin 224 224 +1018 ./prep_dataset/ILSVRC2012_val_00049582.bin 224 224 +1019 ./prep_dataset/ILSVRC2012_val_00031645.bin 224 224 +1020 ./prep_dataset/ILSVRC2012_val_00007173.bin 224 224 +1021 ./prep_dataset/ILSVRC2012_val_00048353.bin 224 224 +1022 ./prep_dataset/ILSVRC2012_val_00042732.bin 224 224 +1023 ./prep_dataset/ILSVRC2012_val_00033293.bin 224 224 +1024 ./prep_dataset/ILSVRC2012_val_00028507.bin 224 224 +1025 ./prep_dataset/ILSVRC2012_val_00020516.bin 224 224 +1026 ./prep_dataset/ILSVRC2012_val_00010229.bin 224 224 +1027 ./prep_dataset/ILSVRC2012_val_00025125.bin 224 224 +1028 ./prep_dataset/ILSVRC2012_val_00010088.bin 224 224 +1029 ./prep_dataset/ILSVRC2012_val_00029027.bin 224 224 +1030 ./prep_dataset/ILSVRC2012_val_00012474.bin 224 224 +1031 ./prep_dataset/ILSVRC2012_val_00028337.bin 224 224 +1032 ./prep_dataset/ILSVRC2012_val_00007439.bin 224 224 +1033 ./prep_dataset/ILSVRC2012_val_00040517.bin 224 224 +1034 ./prep_dataset/ILSVRC2012_val_00041857.bin 224 224 +1035 ./prep_dataset/ILSVRC2012_val_00019074.bin 224 224 +1036 ./prep_dataset/ILSVRC2012_val_00045811.bin 224 224 +1037 ./prep_dataset/ILSVRC2012_val_00010392.bin 224 224 +1038 ./prep_dataset/ILSVRC2012_val_00044384.bin 224 224 +1039 ./prep_dataset/ILSVRC2012_val_00042725.bin 224 224 +1040 ./prep_dataset/ILSVRC2012_val_00010434.bin 224 224 +1041 ./prep_dataset/ILSVRC2012_val_00040884.bin 224 224 +1042 ./prep_dataset/ILSVRC2012_val_00037608.bin 224 224 +1043 ./prep_dataset/ILSVRC2012_val_00045178.bin 224 224 +1044 ./prep_dataset/ILSVRC2012_val_00036514.bin 224 224 +1045 ./prep_dataset/ILSVRC2012_val_00003720.bin 224 224 +1046 ./prep_dataset/ILSVRC2012_val_00006461.bin 224 224 +1047 ./prep_dataset/ILSVRC2012_val_00014010.bin 224 224 +1048 ./prep_dataset/ILSVRC2012_val_00000007.bin 224 224 +1049 ./prep_dataset/ILSVRC2012_val_00040342.bin 224 224 +1050 ./prep_dataset/ILSVRC2012_val_00018378.bin 224 224 +1051 ./prep_dataset/ILSVRC2012_val_00041072.bin 224 224 +1052 ./prep_dataset/ILSVRC2012_val_00042123.bin 224 224 +1053 ./prep_dataset/ILSVRC2012_val_00000120.bin 224 224 +1054 ./prep_dataset/ILSVRC2012_val_00022252.bin 224 224 +1055 ./prep_dataset/ILSVRC2012_val_00010045.bin 224 224 +1056 ./prep_dataset/ILSVRC2012_val_00025453.bin 224 224 +1057 ./prep_dataset/ILSVRC2012_val_00048053.bin 224 224 +1058 ./prep_dataset/ILSVRC2012_val_00037287.bin 224 224 +1059 ./prep_dataset/ILSVRC2012_val_00024931.bin 224 224 +1060 ./prep_dataset/ILSVRC2012_val_00042632.bin 224 224 +1061 ./prep_dataset/ILSVRC2012_val_00047514.bin 224 224 +1062 ./prep_dataset/ILSVRC2012_val_00034003.bin 224 224 +1063 ./prep_dataset/ILSVRC2012_val_00014238.bin 224 224 +1064 ./prep_dataset/ILSVRC2012_val_00005170.bin 224 224 +1065 ./prep_dataset/ILSVRC2012_val_00049907.bin 224 224 +1066 ./prep_dataset/ILSVRC2012_val_00007963.bin 224 224 +1067 ./prep_dataset/ILSVRC2012_val_00036727.bin 224 224 +1068 ./prep_dataset/ILSVRC2012_val_00009625.bin 224 224 +1069 ./prep_dataset/ILSVRC2012_val_00033843.bin 224 224 +1070 ./prep_dataset/ILSVRC2012_val_00046015.bin 224 224 +1071 ./prep_dataset/ILSVRC2012_val_00046841.bin 224 224 +1072 ./prep_dataset/ILSVRC2012_val_00049241.bin 224 224 +1073 ./prep_dataset/ILSVRC2012_val_00030531.bin 224 224 +1074 ./prep_dataset/ILSVRC2012_val_00037138.bin 224 224 +1075 ./prep_dataset/ILSVRC2012_val_00017405.bin 224 224 +1076 ./prep_dataset/ILSVRC2012_val_00016476.bin 224 224 +1077 ./prep_dataset/ILSVRC2012_val_00037619.bin 224 224 +1078 ./prep_dataset/ILSVRC2012_val_00006736.bin 224 224 +1079 ./prep_dataset/ILSVRC2012_val_00036485.bin 224 224 +1080 ./prep_dataset/ILSVRC2012_val_00045624.bin 224 224 +1081 ./prep_dataset/ILSVRC2012_val_00004012.bin 224 224 +1082 ./prep_dataset/ILSVRC2012_val_00035429.bin 224 224 +1083 ./prep_dataset/ILSVRC2012_val_00011679.bin 224 224 +1084 ./prep_dataset/ILSVRC2012_val_00018266.bin 224 224 +1085 ./prep_dataset/ILSVRC2012_val_00030114.bin 224 224 +1086 ./prep_dataset/ILSVRC2012_val_00046913.bin 224 224 +1087 ./prep_dataset/ILSVRC2012_val_00037354.bin 224 224 +1088 ./prep_dataset/ILSVRC2012_val_00035749.bin 224 224 +1089 ./prep_dataset/ILSVRC2012_val_00020384.bin 224 224 +1090 ./prep_dataset/ILSVRC2012_val_00033283.bin 224 224 +1091 ./prep_dataset/ILSVRC2012_val_00022509.bin 224 224 +1092 ./prep_dataset/ILSVRC2012_val_00013140.bin 224 224 +1093 ./prep_dataset/ILSVRC2012_val_00038082.bin 224 224 +1094 ./prep_dataset/ILSVRC2012_val_00049225.bin 224 224 +1095 ./prep_dataset/ILSVRC2012_val_00034888.bin 224 224 +1096 ./prep_dataset/ILSVRC2012_val_00047526.bin 224 224 +1097 ./prep_dataset/ILSVRC2012_val_00005804.bin 224 224 +1098 ./prep_dataset/ILSVRC2012_val_00049639.bin 224 224 +1099 ./prep_dataset/ILSVRC2012_val_00002566.bin 224 224 +1100 ./prep_dataset/ILSVRC2012_val_00030049.bin 224 224 +1101 ./prep_dataset/ILSVRC2012_val_00030980.bin 224 224 +1102 ./prep_dataset/ILSVRC2012_val_00005248.bin 224 224 +1103 ./prep_dataset/ILSVRC2012_val_00049943.bin 224 224 +1104 ./prep_dataset/ILSVRC2012_val_00016052.bin 224 224 +1105 ./prep_dataset/ILSVRC2012_val_00013282.bin 224 224 +1106 ./prep_dataset/ILSVRC2012_val_00010454.bin 224 224 +1107 ./prep_dataset/ILSVRC2012_val_00029036.bin 224 224 +1108 ./prep_dataset/ILSVRC2012_val_00013948.bin 224 224 +1109 ./prep_dataset/ILSVRC2012_val_00008176.bin 224 224 +1110 ./prep_dataset/ILSVRC2012_val_00012899.bin 224 224 +1111 ./prep_dataset/ILSVRC2012_val_00028959.bin 224 224 +1112 ./prep_dataset/ILSVRC2012_val_00024832.bin 224 224 +1113 ./prep_dataset/ILSVRC2012_val_00027190.bin 224 224 +1114 ./prep_dataset/ILSVRC2012_val_00046764.bin 224 224 +1115 ./prep_dataset/ILSVRC2012_val_00019325.bin 224 224 +1116 ./prep_dataset/ILSVRC2012_val_00025960.bin 224 224 +1117 ./prep_dataset/ILSVRC2012_val_00044408.bin 224 224 +1118 ./prep_dataset/ILSVRC2012_val_00017681.bin 224 224 +1119 ./prep_dataset/ILSVRC2012_val_00002265.bin 224 224 +1120 ./prep_dataset/ILSVRC2012_val_00009627.bin 224 224 +1121 ./prep_dataset/ILSVRC2012_val_00007787.bin 224 224 +1122 ./prep_dataset/ILSVRC2012_val_00024693.bin 224 224 +1123 ./prep_dataset/ILSVRC2012_val_00044962.bin 224 224 +1124 ./prep_dataset/ILSVRC2012_val_00022938.bin 224 224 +1125 ./prep_dataset/ILSVRC2012_val_00046790.bin 224 224 +1126 ./prep_dataset/ILSVRC2012_val_00033437.bin 224 224 +1127 ./prep_dataset/ILSVRC2012_val_00035469.bin 224 224 +1128 ./prep_dataset/ILSVRC2012_val_00022499.bin 224 224 +1129 ./prep_dataset/ILSVRC2012_val_00018059.bin 224 224 +1130 ./prep_dataset/ILSVRC2012_val_00005674.bin 224 224 +1131 ./prep_dataset/ILSVRC2012_val_00014815.bin 224 224 +1132 ./prep_dataset/ILSVRC2012_val_00043218.bin 224 224 +1133 ./prep_dataset/ILSVRC2012_val_00015664.bin 224 224 +1134 ./prep_dataset/ILSVRC2012_val_00008069.bin 224 224 +1135 ./prep_dataset/ILSVRC2012_val_00013801.bin 224 224 +1136 ./prep_dataset/ILSVRC2012_val_00015498.bin 224 224 +1137 ./prep_dataset/ILSVRC2012_val_00020705.bin 224 224 +1138 ./prep_dataset/ILSVRC2012_val_00017614.bin 224 224 +1139 ./prep_dataset/ILSVRC2012_val_00039562.bin 224 224 +1140 ./prep_dataset/ILSVRC2012_val_00019149.bin 224 224 +1141 ./prep_dataset/ILSVRC2012_val_00044891.bin 224 224 +1142 ./prep_dataset/ILSVRC2012_val_00035249.bin 224 224 +1143 ./prep_dataset/ILSVRC2012_val_00013172.bin 224 224 +1144 ./prep_dataset/ILSVRC2012_val_00005463.bin 224 224 +1145 ./prep_dataset/ILSVRC2012_val_00005965.bin 224 224 +1146 ./prep_dataset/ILSVRC2012_val_00024572.bin 224 224 +1147 ./prep_dataset/ILSVRC2012_val_00021455.bin 224 224 +1148 ./prep_dataset/ILSVRC2012_val_00039893.bin 224 224 +1149 ./prep_dataset/ILSVRC2012_val_00020325.bin 224 224 +1150 ./prep_dataset/ILSVRC2012_val_00001373.bin 224 224 +1151 ./prep_dataset/ILSVRC2012_val_00025349.bin 224 224 +1152 ./prep_dataset/ILSVRC2012_val_00018502.bin 224 224 +1153 ./prep_dataset/ILSVRC2012_val_00018125.bin 224 224 +1154 ./prep_dataset/ILSVRC2012_val_00002427.bin 224 224 +1155 ./prep_dataset/ILSVRC2012_val_00037777.bin 224 224 +1156 ./prep_dataset/ILSVRC2012_val_00008305.bin 224 224 +1157 ./prep_dataset/ILSVRC2012_val_00011097.bin 224 224 +1158 ./prep_dataset/ILSVRC2012_val_00010889.bin 224 224 +1159 ./prep_dataset/ILSVRC2012_val_00031330.bin 224 224 +1160 ./prep_dataset/ILSVRC2012_val_00045004.bin 224 224 +1161 ./prep_dataset/ILSVRC2012_val_00019055.bin 224 224 +1162 ./prep_dataset/ILSVRC2012_val_00048309.bin 224 224 +1163 ./prep_dataset/ILSVRC2012_val_00038957.bin 224 224 +1164 ./prep_dataset/ILSVRC2012_val_00010951.bin 224 224 +1165 ./prep_dataset/ILSVRC2012_val_00024043.bin 224 224 +1166 ./prep_dataset/ILSVRC2012_val_00018647.bin 224 224 +1167 ./prep_dataset/ILSVRC2012_val_00016500.bin 224 224 +1168 ./prep_dataset/ILSVRC2012_val_00022451.bin 224 224 +1169 ./prep_dataset/ILSVRC2012_val_00017134.bin 224 224 +1170 ./prep_dataset/ILSVRC2012_val_00011461.bin 224 224 +1171 ./prep_dataset/ILSVRC2012_val_00017170.bin 224 224 +1172 ./prep_dataset/ILSVRC2012_val_00021462.bin 224 224 +1173 ./prep_dataset/ILSVRC2012_val_00021615.bin 224 224 +1174 ./prep_dataset/ILSVRC2012_val_00033976.bin 224 224 +1175 ./prep_dataset/ILSVRC2012_val_00045344.bin 224 224 +1176 ./prep_dataset/ILSVRC2012_val_00016278.bin 224 224 +1177 ./prep_dataset/ILSVRC2012_val_00000926.bin 224 224 +1178 ./prep_dataset/ILSVRC2012_val_00045808.bin 224 224 +1179 ./prep_dataset/ILSVRC2012_val_00048666.bin 224 224 +1180 ./prep_dataset/ILSVRC2012_val_00007171.bin 224 224 +1181 ./prep_dataset/ILSVRC2012_val_00000600.bin 224 224 +1182 ./prep_dataset/ILSVRC2012_val_00019288.bin 224 224 +1183 ./prep_dataset/ILSVRC2012_val_00022229.bin 224 224 +1184 ./prep_dataset/ILSVRC2012_val_00007416.bin 224 224 +1185 ./prep_dataset/ILSVRC2012_val_00012560.bin 224 224 +1186 ./prep_dataset/ILSVRC2012_val_00003457.bin 224 224 +1187 ./prep_dataset/ILSVRC2012_val_00028932.bin 224 224 +1188 ./prep_dataset/ILSVRC2012_val_00011256.bin 224 224 +1189 ./prep_dataset/ILSVRC2012_val_00039163.bin 224 224 +1190 ./prep_dataset/ILSVRC2012_val_00035041.bin 224 224 +1191 ./prep_dataset/ILSVRC2012_val_00000844.bin 224 224 +1192 ./prep_dataset/ILSVRC2012_val_00033493.bin 224 224 +1193 ./prep_dataset/ILSVRC2012_val_00027964.bin 224 224 +1194 ./prep_dataset/ILSVRC2012_val_00035051.bin 224 224 +1195 ./prep_dataset/ILSVRC2012_val_00007906.bin 224 224 +1196 ./prep_dataset/ILSVRC2012_val_00022173.bin 224 224 +1197 ./prep_dataset/ILSVRC2012_val_00009644.bin 224 224 +1198 ./prep_dataset/ILSVRC2012_val_00024864.bin 224 224 +1199 ./prep_dataset/ILSVRC2012_val_00026850.bin 224 224 +1200 ./prep_dataset/ILSVRC2012_val_00039452.bin 224 224 +1201 ./prep_dataset/ILSVRC2012_val_00021634.bin 224 224 +1202 ./prep_dataset/ILSVRC2012_val_00021456.bin 224 224 +1203 ./prep_dataset/ILSVRC2012_val_00041346.bin 224 224 +1204 ./prep_dataset/ILSVRC2012_val_00008825.bin 224 224 +1205 ./prep_dataset/ILSVRC2012_val_00013208.bin 224 224 +1206 ./prep_dataset/ILSVRC2012_val_00007768.bin 224 224 +1207 ./prep_dataset/ILSVRC2012_val_00021853.bin 224 224 +1208 ./prep_dataset/ILSVRC2012_val_00029449.bin 224 224 +1209 ./prep_dataset/ILSVRC2012_val_00046564.bin 224 224 +1210 ./prep_dataset/ILSVRC2012_val_00035760.bin 224 224 +1211 ./prep_dataset/ILSVRC2012_val_00032441.bin 224 224 +1212 ./prep_dataset/ILSVRC2012_val_00042483.bin 224 224 +1213 ./prep_dataset/ILSVRC2012_val_00037889.bin 224 224 +1214 ./prep_dataset/ILSVRC2012_val_00023895.bin 224 224 +1215 ./prep_dataset/ILSVRC2012_val_00020756.bin 224 224 +1216 ./prep_dataset/ILSVRC2012_val_00045773.bin 224 224 +1217 ./prep_dataset/ILSVRC2012_val_00011982.bin 224 224 +1218 ./prep_dataset/ILSVRC2012_val_00037010.bin 224 224 +1219 ./prep_dataset/ILSVRC2012_val_00013928.bin 224 224 +1220 ./prep_dataset/ILSVRC2012_val_00036620.bin 224 224 +1221 ./prep_dataset/ILSVRC2012_val_00003221.bin 224 224 +1222 ./prep_dataset/ILSVRC2012_val_00032181.bin 224 224 +1223 ./prep_dataset/ILSVRC2012_val_00028325.bin 224 224 +1224 ./prep_dataset/ILSVRC2012_val_00009630.bin 224 224 +1225 ./prep_dataset/ILSVRC2012_val_00041583.bin 224 224 +1226 ./prep_dataset/ILSVRC2012_val_00000397.bin 224 224 +1227 ./prep_dataset/ILSVRC2012_val_00015543.bin 224 224 +1228 ./prep_dataset/ILSVRC2012_val_00006378.bin 224 224 +1229 ./prep_dataset/ILSVRC2012_val_00030239.bin 224 224 +1230 ./prep_dataset/ILSVRC2012_val_00021671.bin 224 224 +1231 ./prep_dataset/ILSVRC2012_val_00013067.bin 224 224 +1232 ./prep_dataset/ILSVRC2012_val_00011523.bin 224 224 +1233 ./prep_dataset/ILSVRC2012_val_00047262.bin 224 224 +1234 ./prep_dataset/ILSVRC2012_val_00049264.bin 224 224 +1235 ./prep_dataset/ILSVRC2012_val_00005347.bin 224 224 +1236 ./prep_dataset/ILSVRC2012_val_00008812.bin 224 224 +1237 ./prep_dataset/ILSVRC2012_val_00018508.bin 224 224 +1238 ./prep_dataset/ILSVRC2012_val_00020884.bin 224 224 +1239 ./prep_dataset/ILSVRC2012_val_00044129.bin 224 224 +1240 ./prep_dataset/ILSVRC2012_val_00010772.bin 224 224 +1241 ./prep_dataset/ILSVRC2012_val_00030406.bin 224 224 +1242 ./prep_dataset/ILSVRC2012_val_00033335.bin 224 224 +1243 ./prep_dataset/ILSVRC2012_val_00023569.bin 224 224 +1244 ./prep_dataset/ILSVRC2012_val_00035693.bin 224 224 +1245 ./prep_dataset/ILSVRC2012_val_00027875.bin 224 224 +1246 ./prep_dataset/ILSVRC2012_val_00009137.bin 224 224 +1247 ./prep_dataset/ILSVRC2012_val_00023668.bin 224 224 +1248 ./prep_dataset/ILSVRC2012_val_00012988.bin 224 224 +1249 ./prep_dataset/ILSVRC2012_val_00032024.bin 224 224 +1250 ./prep_dataset/ILSVRC2012_val_00015587.bin 224 224 +1251 ./prep_dataset/ILSVRC2012_val_00038370.bin 224 224 +1252 ./prep_dataset/ILSVRC2012_val_00017061.bin 224 224 +1253 ./prep_dataset/ILSVRC2012_val_00037788.bin 224 224 +1254 ./prep_dataset/ILSVRC2012_val_00004325.bin 224 224 +1255 ./prep_dataset/ILSVRC2012_val_00049467.bin 224 224 +1256 ./prep_dataset/ILSVRC2012_val_00048755.bin 224 224 +1257 ./prep_dataset/ILSVRC2012_val_00031339.bin 224 224 +1258 ./prep_dataset/ILSVRC2012_val_00019160.bin 224 224 +1259 ./prep_dataset/ILSVRC2012_val_00035170.bin 224 224 +1260 ./prep_dataset/ILSVRC2012_val_00047840.bin 224 224 +1261 ./prep_dataset/ILSVRC2012_val_00012366.bin 224 224 +1262 ./prep_dataset/ILSVRC2012_val_00040671.bin 224 224 +1263 ./prep_dataset/ILSVRC2012_val_00039442.bin 224 224 +1264 ./prep_dataset/ILSVRC2012_val_00037797.bin 224 224 +1265 ./prep_dataset/ILSVRC2012_val_00036279.bin 224 224 +1266 ./prep_dataset/ILSVRC2012_val_00033631.bin 224 224 +1267 ./prep_dataset/ILSVRC2012_val_00047347.bin 224 224 +1268 ./prep_dataset/ILSVRC2012_val_00030451.bin 224 224 +1269 ./prep_dataset/ILSVRC2012_val_00022444.bin 224 224 +1270 ./prep_dataset/ILSVRC2012_val_00033375.bin 224 224 +1271 ./prep_dataset/ILSVRC2012_val_00001154.bin 224 224 +1272 ./prep_dataset/ILSVRC2012_val_00041434.bin 224 224 +1273 ./prep_dataset/ILSVRC2012_val_00048114.bin 224 224 +1274 ./prep_dataset/ILSVRC2012_val_00031632.bin 224 224 +1275 ./prep_dataset/ILSVRC2012_val_00021409.bin 224 224 +1276 ./prep_dataset/ILSVRC2012_val_00005014.bin 224 224 +1277 ./prep_dataset/ILSVRC2012_val_00026596.bin 224 224 +1278 ./prep_dataset/ILSVRC2012_val_00013120.bin 224 224 +1279 ./prep_dataset/ILSVRC2012_val_00049020.bin 224 224 +1280 ./prep_dataset/ILSVRC2012_val_00012276.bin 224 224 +1281 ./prep_dataset/ILSVRC2012_val_00042801.bin 224 224 +1282 ./prep_dataset/ILSVRC2012_val_00005605.bin 224 224 +1283 ./prep_dataset/ILSVRC2012_val_00000959.bin 224 224 +1284 ./prep_dataset/ILSVRC2012_val_00002928.bin 224 224 +1285 ./prep_dataset/ILSVRC2012_val_00033207.bin 224 224 +1286 ./prep_dataset/ILSVRC2012_val_00027571.bin 224 224 +1287 ./prep_dataset/ILSVRC2012_val_00048683.bin 224 224 +1288 ./prep_dataset/ILSVRC2012_val_00021034.bin 224 224 +1289 ./prep_dataset/ILSVRC2012_val_00032051.bin 224 224 +1290 ./prep_dataset/ILSVRC2012_val_00014607.bin 224 224 +1291 ./prep_dataset/ILSVRC2012_val_00036206.bin 224 224 +1292 ./prep_dataset/ILSVRC2012_val_00047999.bin 224 224 +1293 ./prep_dataset/ILSVRC2012_val_00049673.bin 224 224 +1294 ./prep_dataset/ILSVRC2012_val_00015027.bin 224 224 +1295 ./prep_dataset/ILSVRC2012_val_00043493.bin 224 224 +1296 ./prep_dataset/ILSVRC2012_val_00045314.bin 224 224 +1297 ./prep_dataset/ILSVRC2012_val_00009661.bin 224 224 +1298 ./prep_dataset/ILSVRC2012_val_00046950.bin 224 224 +1299 ./prep_dataset/ILSVRC2012_val_00016822.bin 224 224 +1300 ./prep_dataset/ILSVRC2012_val_00010345.bin 224 224 +1301 ./prep_dataset/ILSVRC2012_val_00026711.bin 224 224 +1302 ./prep_dataset/ILSVRC2012_val_00030167.bin 224 224 +1303 ./prep_dataset/ILSVRC2012_val_00019652.bin 224 224 +1304 ./prep_dataset/ILSVRC2012_val_00045480.bin 224 224 +1305 ./prep_dataset/ILSVRC2012_val_00046831.bin 224 224 +1306 ./prep_dataset/ILSVRC2012_val_00027687.bin 224 224 +1307 ./prep_dataset/ILSVRC2012_val_00049266.bin 224 224 +1308 ./prep_dataset/ILSVRC2012_val_00043593.bin 224 224 +1309 ./prep_dataset/ILSVRC2012_val_00023458.bin 224 224 +1310 ./prep_dataset/ILSVRC2012_val_00016461.bin 224 224 +1311 ./prep_dataset/ILSVRC2012_val_00024952.bin 224 224 +1312 ./prep_dataset/ILSVRC2012_val_00015630.bin 224 224 +1313 ./prep_dataset/ILSVRC2012_val_00029235.bin 224 224 +1314 ./prep_dataset/ILSVRC2012_val_00024361.bin 224 224 +1315 ./prep_dataset/ILSVRC2012_val_00006201.bin 224 224 +1316 ./prep_dataset/ILSVRC2012_val_00030170.bin 224 224 +1317 ./prep_dataset/ILSVRC2012_val_00005845.bin 224 224 +1318 ./prep_dataset/ILSVRC2012_val_00038496.bin 224 224 +1319 ./prep_dataset/ILSVRC2012_val_00037682.bin 224 224 +1320 ./prep_dataset/ILSVRC2012_val_00006957.bin 224 224 +1321 ./prep_dataset/ILSVRC2012_val_00004934.bin 224 224 +1322 ./prep_dataset/ILSVRC2012_val_00000286.bin 224 224 +1323 ./prep_dataset/ILSVRC2012_val_00034725.bin 224 224 +1324 ./prep_dataset/ILSVRC2012_val_00029315.bin 224 224 +1325 ./prep_dataset/ILSVRC2012_val_00046809.bin 224 224 +1326 ./prep_dataset/ILSVRC2012_val_00020608.bin 224 224 +1327 ./prep_dataset/ILSVRC2012_val_00036333.bin 224 224 +1328 ./prep_dataset/ILSVRC2012_val_00014530.bin 224 224 +1329 ./prep_dataset/ILSVRC2012_val_00032635.bin 224 224 +1330 ./prep_dataset/ILSVRC2012_val_00043019.bin 224 224 +1331 ./prep_dataset/ILSVRC2012_val_00004142.bin 224 224 +1332 ./prep_dataset/ILSVRC2012_val_00029155.bin 224 224 +1333 ./prep_dataset/ILSVRC2012_val_00027154.bin 224 224 +1334 ./prep_dataset/ILSVRC2012_val_00028054.bin 224 224 +1335 ./prep_dataset/ILSVRC2012_val_00027479.bin 224 224 +1336 ./prep_dataset/ILSVRC2012_val_00045790.bin 224 224 +1337 ./prep_dataset/ILSVRC2012_val_00041838.bin 224 224 +1338 ./prep_dataset/ILSVRC2012_val_00049577.bin 224 224 +1339 ./prep_dataset/ILSVRC2012_val_00039618.bin 224 224 +1340 ./prep_dataset/ILSVRC2012_val_00030562.bin 224 224 +1341 ./prep_dataset/ILSVRC2012_val_00005827.bin 224 224 +1342 ./prep_dataset/ILSVRC2012_val_00002202.bin 224 224 +1343 ./prep_dataset/ILSVRC2012_val_00033956.bin 224 224 +1344 ./prep_dataset/ILSVRC2012_val_00027011.bin 224 224 +1345 ./prep_dataset/ILSVRC2012_val_00017658.bin 224 224 +1346 ./prep_dataset/ILSVRC2012_val_00043429.bin 224 224 +1347 ./prep_dataset/ILSVRC2012_val_00000181.bin 224 224 +1348 ./prep_dataset/ILSVRC2012_val_00004240.bin 224 224 +1349 ./prep_dataset/ILSVRC2012_val_00039844.bin 224 224 +1350 ./prep_dataset/ILSVRC2012_val_00005779.bin 224 224 +1351 ./prep_dataset/ILSVRC2012_val_00047851.bin 224 224 +1352 ./prep_dataset/ILSVRC2012_val_00019663.bin 224 224 +1353 ./prep_dataset/ILSVRC2012_val_00038714.bin 224 224 +1354 ./prep_dataset/ILSVRC2012_val_00009285.bin 224 224 +1355 ./prep_dataset/ILSVRC2012_val_00047144.bin 224 224 +1356 ./prep_dataset/ILSVRC2012_val_00017684.bin 224 224 +1357 ./prep_dataset/ILSVRC2012_val_00005435.bin 224 224 +1358 ./prep_dataset/ILSVRC2012_val_00040577.bin 224 224 +1359 ./prep_dataset/ILSVRC2012_val_00005697.bin 224 224 +1360 ./prep_dataset/ILSVRC2012_val_00017949.bin 224 224 +1361 ./prep_dataset/ILSVRC2012_val_00013137.bin 224 224 +1362 ./prep_dataset/ILSVRC2012_val_00005959.bin 224 224 +1363 ./prep_dataset/ILSVRC2012_val_00010616.bin 224 224 +1364 ./prep_dataset/ILSVRC2012_val_00037663.bin 224 224 +1365 ./prep_dataset/ILSVRC2012_val_00018680.bin 224 224 +1366 ./prep_dataset/ILSVRC2012_val_00015927.bin 224 224 +1367 ./prep_dataset/ILSVRC2012_val_00016248.bin 224 224 +1368 ./prep_dataset/ILSVRC2012_val_00049604.bin 224 224 +1369 ./prep_dataset/ILSVRC2012_val_00035480.bin 224 224 +1370 ./prep_dataset/ILSVRC2012_val_00018063.bin 224 224 +1371 ./prep_dataset/ILSVRC2012_val_00006733.bin 224 224 +1372 ./prep_dataset/ILSVRC2012_val_00009412.bin 224 224 +1373 ./prep_dataset/ILSVRC2012_val_00035202.bin 224 224 +1374 ./prep_dataset/ILSVRC2012_val_00044581.bin 224 224 +1375 ./prep_dataset/ILSVRC2012_val_00045602.bin 224 224 +1376 ./prep_dataset/ILSVRC2012_val_00015448.bin 224 224 +1377 ./prep_dataset/ILSVRC2012_val_00023654.bin 224 224 +1378 ./prep_dataset/ILSVRC2012_val_00024924.bin 224 224 +1379 ./prep_dataset/ILSVRC2012_val_00045920.bin 224 224 +1380 ./prep_dataset/ILSVRC2012_val_00018847.bin 224 224 +1381 ./prep_dataset/ILSVRC2012_val_00023912.bin 224 224 +1382 ./prep_dataset/ILSVRC2012_val_00022153.bin 224 224 +1383 ./prep_dataset/ILSVRC2012_val_00021098.bin 224 224 +1384 ./prep_dataset/ILSVRC2012_val_00048017.bin 224 224 +1385 ./prep_dataset/ILSVRC2012_val_00023174.bin 224 224 +1386 ./prep_dataset/ILSVRC2012_val_00024112.bin 224 224 +1387 ./prep_dataset/ILSVRC2012_val_00038917.bin 224 224 +1388 ./prep_dataset/ILSVRC2012_val_00040643.bin 224 224 +1389 ./prep_dataset/ILSVRC2012_val_00004517.bin 224 224 +1390 ./prep_dataset/ILSVRC2012_val_00038797.bin 224 224 +1391 ./prep_dataset/ILSVRC2012_val_00012507.bin 224 224 +1392 ./prep_dataset/ILSVRC2012_val_00003451.bin 224 224 +1393 ./prep_dataset/ILSVRC2012_val_00040266.bin 224 224 +1394 ./prep_dataset/ILSVRC2012_val_00003246.bin 224 224 +1395 ./prep_dataset/ILSVRC2012_val_00031376.bin 224 224 +1396 ./prep_dataset/ILSVRC2012_val_00024829.bin 224 224 +1397 ./prep_dataset/ILSVRC2012_val_00015237.bin 224 224 +1398 ./prep_dataset/ILSVRC2012_val_00016634.bin 224 224 +1399 ./prep_dataset/ILSVRC2012_val_00047065.bin 224 224 +1400 ./prep_dataset/ILSVRC2012_val_00040132.bin 224 224 +1401 ./prep_dataset/ILSVRC2012_val_00014863.bin 224 224 +1402 ./prep_dataset/ILSVRC2012_val_00041099.bin 224 224 +1403 ./prep_dataset/ILSVRC2012_val_00037700.bin 224 224 +1404 ./prep_dataset/ILSVRC2012_val_00020152.bin 224 224 +1405 ./prep_dataset/ILSVRC2012_val_00030207.bin 224 224 +1406 ./prep_dataset/ILSVRC2012_val_00037304.bin 224 224 +1407 ./prep_dataset/ILSVRC2012_val_00024108.bin 224 224 +1408 ./prep_dataset/ILSVRC2012_val_00012961.bin 224 224 +1409 ./prep_dataset/ILSVRC2012_val_00036462.bin 224 224 +1410 ./prep_dataset/ILSVRC2012_val_00013217.bin 224 224 +1411 ./prep_dataset/ILSVRC2012_val_00008925.bin 224 224 +1412 ./prep_dataset/ILSVRC2012_val_00019982.bin 224 224 +1413 ./prep_dataset/ILSVRC2012_val_00038464.bin 224 224 +1414 ./prep_dataset/ILSVRC2012_val_00011985.bin 224 224 +1415 ./prep_dataset/ILSVRC2012_val_00000389.bin 224 224 +1416 ./prep_dataset/ILSVRC2012_val_00034223.bin 224 224 +1417 ./prep_dataset/ILSVRC2012_val_00004843.bin 224 224 +1418 ./prep_dataset/ILSVRC2012_val_00002599.bin 224 224 +1419 ./prep_dataset/ILSVRC2012_val_00034252.bin 224 224 +1420 ./prep_dataset/ILSVRC2012_val_00024621.bin 224 224 +1421 ./prep_dataset/ILSVRC2012_val_00005577.bin 224 224 +1422 ./prep_dataset/ILSVRC2012_val_00045547.bin 224 224 +1423 ./prep_dataset/ILSVRC2012_val_00001631.bin 224 224 +1424 ./prep_dataset/ILSVRC2012_val_00026667.bin 224 224 +1425 ./prep_dataset/ILSVRC2012_val_00043931.bin 224 224 +1426 ./prep_dataset/ILSVRC2012_val_00000335.bin 224 224 +1427 ./prep_dataset/ILSVRC2012_val_00013343.bin 224 224 +1428 ./prep_dataset/ILSVRC2012_val_00008783.bin 224 224 +1429 ./prep_dataset/ILSVRC2012_val_00042368.bin 224 224 +1430 ./prep_dataset/ILSVRC2012_val_00032931.bin 224 224 +1431 ./prep_dataset/ILSVRC2012_val_00027867.bin 224 224 +1432 ./prep_dataset/ILSVRC2012_val_00034957.bin 224 224 +1433 ./prep_dataset/ILSVRC2012_val_00005469.bin 224 224 +1434 ./prep_dataset/ILSVRC2012_val_00006178.bin 224 224 +1435 ./prep_dataset/ILSVRC2012_val_00026929.bin 224 224 +1436 ./prep_dataset/ILSVRC2012_val_00015195.bin 224 224 +1437 ./prep_dataset/ILSVRC2012_val_00002982.bin 224 224 +1438 ./prep_dataset/ILSVRC2012_val_00046686.bin 224 224 +1439 ./prep_dataset/ILSVRC2012_val_00049546.bin 224 224 +1440 ./prep_dataset/ILSVRC2012_val_00001668.bin 224 224 +1441 ./prep_dataset/ILSVRC2012_val_00000370.bin 224 224 +1442 ./prep_dataset/ILSVRC2012_val_00043545.bin 224 224 +1443 ./prep_dataset/ILSVRC2012_val_00023310.bin 224 224 +1444 ./prep_dataset/ILSVRC2012_val_00006792.bin 224 224 +1445 ./prep_dataset/ILSVRC2012_val_00030318.bin 224 224 +1446 ./prep_dataset/ILSVRC2012_val_00027394.bin 224 224 +1447 ./prep_dataset/ILSVRC2012_val_00000128.bin 224 224 +1448 ./prep_dataset/ILSVRC2012_val_00045320.bin 224 224 +1449 ./prep_dataset/ILSVRC2012_val_00023938.bin 224 224 +1450 ./prep_dataset/ILSVRC2012_val_00005453.bin 224 224 +1451 ./prep_dataset/ILSVRC2012_val_00028860.bin 224 224 +1452 ./prep_dataset/ILSVRC2012_val_00044200.bin 224 224 +1453 ./prep_dataset/ILSVRC2012_val_00010628.bin 224 224 +1454 ./prep_dataset/ILSVRC2012_val_00026367.bin 224 224 +1455 ./prep_dataset/ILSVRC2012_val_00041842.bin 224 224 +1456 ./prep_dataset/ILSVRC2012_val_00003483.bin 224 224 +1457 ./prep_dataset/ILSVRC2012_val_00012914.bin 224 224 +1458 ./prep_dataset/ILSVRC2012_val_00007075.bin 224 224 +1459 ./prep_dataset/ILSVRC2012_val_00003851.bin 224 224 +1460 ./prep_dataset/ILSVRC2012_val_00002741.bin 224 224 +1461 ./prep_dataset/ILSVRC2012_val_00010696.bin 224 224 +1462 ./prep_dataset/ILSVRC2012_val_00022250.bin 224 224 +1463 ./prep_dataset/ILSVRC2012_val_00004002.bin 224 224 +1464 ./prep_dataset/ILSVRC2012_val_00029785.bin 224 224 +1465 ./prep_dataset/ILSVRC2012_val_00020238.bin 224 224 +1466 ./prep_dataset/ILSVRC2012_val_00033926.bin 224 224 +1467 ./prep_dataset/ILSVRC2012_val_00035910.bin 224 224 +1468 ./prep_dataset/ILSVRC2012_val_00027130.bin 224 224 +1469 ./prep_dataset/ILSVRC2012_val_00009207.bin 224 224 +1470 ./prep_dataset/ILSVRC2012_val_00045204.bin 224 224 +1471 ./prep_dataset/ILSVRC2012_val_00008149.bin 224 224 +1472 ./prep_dataset/ILSVRC2012_val_00027281.bin 224 224 +1473 ./prep_dataset/ILSVRC2012_val_00047741.bin 224 224 +1474 ./prep_dataset/ILSVRC2012_val_00002890.bin 224 224 +1475 ./prep_dataset/ILSVRC2012_val_00004368.bin 224 224 +1476 ./prep_dataset/ILSVRC2012_val_00030932.bin 224 224 +1477 ./prep_dataset/ILSVRC2012_val_00011953.bin 224 224 +1478 ./prep_dataset/ILSVRC2012_val_00044491.bin 224 224 +1479 ./prep_dataset/ILSVRC2012_val_00008005.bin 224 224 +1480 ./prep_dataset/ILSVRC2012_val_00012119.bin 224 224 +1481 ./prep_dataset/ILSVRC2012_val_00044273.bin 224 224 +1482 ./prep_dataset/ILSVRC2012_val_00044177.bin 224 224 +1483 ./prep_dataset/ILSVRC2012_val_00037509.bin 224 224 +1484 ./prep_dataset/ILSVRC2012_val_00045435.bin 224 224 +1485 ./prep_dataset/ILSVRC2012_val_00032995.bin 224 224 +1486 ./prep_dataset/ILSVRC2012_val_00004105.bin 224 224 +1487 ./prep_dataset/ILSVRC2012_val_00007980.bin 224 224 +1488 ./prep_dataset/ILSVRC2012_val_00006704.bin 224 224 +1489 ./prep_dataset/ILSVRC2012_val_00007974.bin 224 224 +1490 ./prep_dataset/ILSVRC2012_val_00046378.bin 224 224 +1491 ./prep_dataset/ILSVRC2012_val_00004023.bin 224 224 +1492 ./prep_dataset/ILSVRC2012_val_00010429.bin 224 224 +1493 ./prep_dataset/ILSVRC2012_val_00020162.bin 224 224 +1494 ./prep_dataset/ILSVRC2012_val_00021642.bin 224 224 +1495 ./prep_dataset/ILSVRC2012_val_00023500.bin 224 224 +1496 ./prep_dataset/ILSVRC2012_val_00025429.bin 224 224 +1497 ./prep_dataset/ILSVRC2012_val_00025024.bin 224 224 +1498 ./prep_dataset/ILSVRC2012_val_00024270.bin 224 224 +1499 ./prep_dataset/ILSVRC2012_val_00020014.bin 224 224 +1500 ./prep_dataset/ILSVRC2012_val_00030508.bin 224 224 +1501 ./prep_dataset/ILSVRC2012_val_00004573.bin 224 224 +1502 ./prep_dataset/ILSVRC2012_val_00024452.bin 224 224 +1503 ./prep_dataset/ILSVRC2012_val_00048352.bin 224 224 +1504 ./prep_dataset/ILSVRC2012_val_00033529.bin 224 224 +1505 ./prep_dataset/ILSVRC2012_val_00019711.bin 224 224 +1506 ./prep_dataset/ILSVRC2012_val_00044178.bin 224 224 +1507 ./prep_dataset/ILSVRC2012_val_00021647.bin 224 224 +1508 ./prep_dataset/ILSVRC2012_val_00009244.bin 224 224 +1509 ./prep_dataset/ILSVRC2012_val_00049565.bin 224 224 +1510 ./prep_dataset/ILSVRC2012_val_00002446.bin 224 224 +1511 ./prep_dataset/ILSVRC2012_val_00047481.bin 224 224 +1512 ./prep_dataset/ILSVRC2012_val_00019204.bin 224 224 +1513 ./prep_dataset/ILSVRC2012_val_00048094.bin 224 224 +1514 ./prep_dataset/ILSVRC2012_val_00022958.bin 224 224 +1515 ./prep_dataset/ILSVRC2012_val_00009962.bin 224 224 +1516 ./prep_dataset/ILSVRC2012_val_00015011.bin 224 224 +1517 ./prep_dataset/ILSVRC2012_val_00025117.bin 224 224 +1518 ./prep_dataset/ILSVRC2012_val_00005139.bin 224 224 +1519 ./prep_dataset/ILSVRC2012_val_00032744.bin 224 224 +1520 ./prep_dataset/ILSVRC2012_val_00027963.bin 224 224 +1521 ./prep_dataset/ILSVRC2012_val_00007935.bin 224 224 +1522 ./prep_dataset/ILSVRC2012_val_00010683.bin 224 224 +1523 ./prep_dataset/ILSVRC2012_val_00008526.bin 224 224 +1524 ./prep_dataset/ILSVRC2012_val_00027882.bin 224 224 +1525 ./prep_dataset/ILSVRC2012_val_00045976.bin 224 224 +1526 ./prep_dataset/ILSVRC2012_val_00036014.bin 224 224 +1527 ./prep_dataset/ILSVRC2012_val_00034884.bin 224 224 +1528 ./prep_dataset/ILSVRC2012_val_00019418.bin 224 224 +1529 ./prep_dataset/ILSVRC2012_val_00011439.bin 224 224 +1530 ./prep_dataset/ILSVRC2012_val_00030759.bin 224 224 +1531 ./prep_dataset/ILSVRC2012_val_00034465.bin 224 224 +1532 ./prep_dataset/ILSVRC2012_val_00036463.bin 224 224 +1533 ./prep_dataset/ILSVRC2012_val_00030862.bin 224 224 +1534 ./prep_dataset/ILSVRC2012_val_00021227.bin 224 224 +1535 ./prep_dataset/ILSVRC2012_val_00014132.bin 224 224 +1536 ./prep_dataset/ILSVRC2012_val_00011469.bin 224 224 +1537 ./prep_dataset/ILSVRC2012_val_00005926.bin 224 224 +1538 ./prep_dataset/ILSVRC2012_val_00029210.bin 224 224 +1539 ./prep_dataset/ILSVRC2012_val_00041423.bin 224 224 +1540 ./prep_dataset/ILSVRC2012_val_00008815.bin 224 224 +1541 ./prep_dataset/ILSVRC2012_val_00025417.bin 224 224 +1542 ./prep_dataset/ILSVRC2012_val_00001237.bin 224 224 +1543 ./prep_dataset/ILSVRC2012_val_00049680.bin 224 224 +1544 ./prep_dataset/ILSVRC2012_val_00022145.bin 224 224 +1545 ./prep_dataset/ILSVRC2012_val_00042292.bin 224 224 +1546 ./prep_dataset/ILSVRC2012_val_00047101.bin 224 224 +1547 ./prep_dataset/ILSVRC2012_val_00020768.bin 224 224 +1548 ./prep_dataset/ILSVRC2012_val_00017481.bin 224 224 +1549 ./prep_dataset/ILSVRC2012_val_00032292.bin 224 224 +1550 ./prep_dataset/ILSVRC2012_val_00000237.bin 224 224 +1551 ./prep_dataset/ILSVRC2012_val_00027969.bin 224 224 +1552 ./prep_dataset/ILSVRC2012_val_00020186.bin 224 224 +1553 ./prep_dataset/ILSVRC2012_val_00016994.bin 224 224 +1554 ./prep_dataset/ILSVRC2012_val_00002315.bin 224 224 +1555 ./prep_dataset/ILSVRC2012_val_00012556.bin 224 224 +1556 ./prep_dataset/ILSVRC2012_val_00010315.bin 224 224 +1557 ./prep_dataset/ILSVRC2012_val_00010046.bin 224 224 +1558 ./prep_dataset/ILSVRC2012_val_00031861.bin 224 224 +1559 ./prep_dataset/ILSVRC2012_val_00034800.bin 224 224 +1560 ./prep_dataset/ILSVRC2012_val_00038548.bin 224 224 +1561 ./prep_dataset/ILSVRC2012_val_00036624.bin 224 224 +1562 ./prep_dataset/ILSVRC2012_val_00009606.bin 224 224 +1563 ./prep_dataset/ILSVRC2012_val_00023038.bin 224 224 +1564 ./prep_dataset/ILSVRC2012_val_00043138.bin 224 224 +1565 ./prep_dataset/ILSVRC2012_val_00014171.bin 224 224 +1566 ./prep_dataset/ILSVRC2012_val_00021490.bin 224 224 +1567 ./prep_dataset/ILSVRC2012_val_00042774.bin 224 224 +1568 ./prep_dataset/ILSVRC2012_val_00014659.bin 224 224 +1569 ./prep_dataset/ILSVRC2012_val_00039136.bin 224 224 +1570 ./prep_dataset/ILSVRC2012_val_00040436.bin 224 224 +1571 ./prep_dataset/ILSVRC2012_val_00012982.bin 224 224 +1572 ./prep_dataset/ILSVRC2012_val_00037548.bin 224 224 +1573 ./prep_dataset/ILSVRC2012_val_00024255.bin 224 224 +1574 ./prep_dataset/ILSVRC2012_val_00005067.bin 224 224 +1575 ./prep_dataset/ILSVRC2012_val_00026021.bin 224 224 +1576 ./prep_dataset/ILSVRC2012_val_00047471.bin 224 224 +1577 ./prep_dataset/ILSVRC2012_val_00019432.bin 224 224 +1578 ./prep_dataset/ILSVRC2012_val_00014388.bin 224 224 +1579 ./prep_dataset/ILSVRC2012_val_00045199.bin 224 224 +1580 ./prep_dataset/ILSVRC2012_val_00026483.bin 224 224 +1581 ./prep_dataset/ILSVRC2012_val_00018728.bin 224 224 +1582 ./prep_dataset/ILSVRC2012_val_00016958.bin 224 224 +1583 ./prep_dataset/ILSVRC2012_val_00031659.bin 224 224 +1584 ./prep_dataset/ILSVRC2012_val_00043039.bin 224 224 +1585 ./prep_dataset/ILSVRC2012_val_00021223.bin 224 224 +1586 ./prep_dataset/ILSVRC2012_val_00013380.bin 224 224 +1587 ./prep_dataset/ILSVRC2012_val_00043825.bin 224 224 +1588 ./prep_dataset/ILSVRC2012_val_00026139.bin 224 224 +1589 ./prep_dataset/ILSVRC2012_val_00028010.bin 224 224 +1590 ./prep_dataset/ILSVRC2012_val_00044710.bin 224 224 +1591 ./prep_dataset/ILSVRC2012_val_00038272.bin 224 224 +1592 ./prep_dataset/ILSVRC2012_val_00043599.bin 224 224 +1593 ./prep_dataset/ILSVRC2012_val_00045687.bin 224 224 +1594 ./prep_dataset/ILSVRC2012_val_00009345.bin 224 224 +1595 ./prep_dataset/ILSVRC2012_val_00018406.bin 224 224 +1596 ./prep_dataset/ILSVRC2012_val_00024268.bin 224 224 +1597 ./prep_dataset/ILSVRC2012_val_00020545.bin 224 224 +1598 ./prep_dataset/ILSVRC2012_val_00033139.bin 224 224 +1599 ./prep_dataset/ILSVRC2012_val_00019395.bin 224 224 +1600 ./prep_dataset/ILSVRC2012_val_00028691.bin 224 224 +1601 ./prep_dataset/ILSVRC2012_val_00036929.bin 224 224 +1602 ./prep_dataset/ILSVRC2012_val_00026397.bin 224 224 +1603 ./prep_dataset/ILSVRC2012_val_00011451.bin 224 224 +1604 ./prep_dataset/ILSVRC2012_val_00044856.bin 224 224 +1605 ./prep_dataset/ILSVRC2012_val_00045308.bin 224 224 +1606 ./prep_dataset/ILSVRC2012_val_00016408.bin 224 224 +1607 ./prep_dataset/ILSVRC2012_val_00042280.bin 224 224 +1608 ./prep_dataset/ILSVRC2012_val_00023348.bin 224 224 +1609 ./prep_dataset/ILSVRC2012_val_00022282.bin 224 224 +1610 ./prep_dataset/ILSVRC2012_val_00018929.bin 224 224 +1611 ./prep_dataset/ILSVRC2012_val_00009864.bin 224 224 +1612 ./prep_dataset/ILSVRC2012_val_00048131.bin 224 224 +1613 ./prep_dataset/ILSVRC2012_val_00006301.bin 224 224 +1614 ./prep_dataset/ILSVRC2012_val_00018410.bin 224 224 +1615 ./prep_dataset/ILSVRC2012_val_00023026.bin 224 224 +1616 ./prep_dataset/ILSVRC2012_val_00019187.bin 224 224 +1617 ./prep_dataset/ILSVRC2012_val_00039282.bin 224 224 +1618 ./prep_dataset/ILSVRC2012_val_00003945.bin 224 224 +1619 ./prep_dataset/ILSVRC2012_val_00018551.bin 224 224 +1620 ./prep_dataset/ILSVRC2012_val_00020313.bin 224 224 +1621 ./prep_dataset/ILSVRC2012_val_00027025.bin 224 224 +1622 ./prep_dataset/ILSVRC2012_val_00000569.bin 224 224 +1623 ./prep_dataset/ILSVRC2012_val_00003199.bin 224 224 +1624 ./prep_dataset/ILSVRC2012_val_00035617.bin 224 224 +1625 ./prep_dataset/ILSVRC2012_val_00042086.bin 224 224 +1626 ./prep_dataset/ILSVRC2012_val_00042622.bin 224 224 +1627 ./prep_dataset/ILSVRC2012_val_00034670.bin 224 224 +1628 ./prep_dataset/ILSVRC2012_val_00016154.bin 224 224 +1629 ./prep_dataset/ILSVRC2012_val_00040675.bin 224 224 +1630 ./prep_dataset/ILSVRC2012_val_00011266.bin 224 224 +1631 ./prep_dataset/ILSVRC2012_val_00011483.bin 224 224 +1632 ./prep_dataset/ILSVRC2012_val_00035769.bin 224 224 +1633 ./prep_dataset/ILSVRC2012_val_00007913.bin 224 224 +1634 ./prep_dataset/ILSVRC2012_val_00042345.bin 224 224 +1635 ./prep_dataset/ILSVRC2012_val_00036635.bin 224 224 +1636 ./prep_dataset/ILSVRC2012_val_00042613.bin 224 224 +1637 ./prep_dataset/ILSVRC2012_val_00010530.bin 224 224 +1638 ./prep_dataset/ILSVRC2012_val_00032248.bin 224 224 +1639 ./prep_dataset/ILSVRC2012_val_00045668.bin 224 224 +1640 ./prep_dataset/ILSVRC2012_val_00029971.bin 224 224 +1641 ./prep_dataset/ILSVRC2012_val_00012849.bin 224 224 +1642 ./prep_dataset/ILSVRC2012_val_00037005.bin 224 224 +1643 ./prep_dataset/ILSVRC2012_val_00034064.bin 224 224 +1644 ./prep_dataset/ILSVRC2012_val_00041934.bin 224 224 +1645 ./prep_dataset/ILSVRC2012_val_00035539.bin 224 224 +1646 ./prep_dataset/ILSVRC2012_val_00038100.bin 224 224 +1647 ./prep_dataset/ILSVRC2012_val_00047569.bin 224 224 +1648 ./prep_dataset/ILSVRC2012_val_00018682.bin 224 224 +1649 ./prep_dataset/ILSVRC2012_val_00047647.bin 224 224 +1650 ./prep_dataset/ILSVRC2012_val_00043489.bin 224 224 +1651 ./prep_dataset/ILSVRC2012_val_00047376.bin 224 224 +1652 ./prep_dataset/ILSVRC2012_val_00034418.bin 224 224 +1653 ./prep_dataset/ILSVRC2012_val_00025798.bin 224 224 +1654 ./prep_dataset/ILSVRC2012_val_00004515.bin 224 224 +1655 ./prep_dataset/ILSVRC2012_val_00007762.bin 224 224 +1656 ./prep_dataset/ILSVRC2012_val_00042983.bin 224 224 +1657 ./prep_dataset/ILSVRC2012_val_00031280.bin 224 224 +1658 ./prep_dataset/ILSVRC2012_val_00023597.bin 224 224 +1659 ./prep_dataset/ILSVRC2012_val_00019020.bin 224 224 +1660 ./prep_dataset/ILSVRC2012_val_00003475.bin 224 224 +1661 ./prep_dataset/ILSVRC2012_val_00035222.bin 224 224 +1662 ./prep_dataset/ILSVRC2012_val_00046737.bin 224 224 +1663 ./prep_dataset/ILSVRC2012_val_00022860.bin 224 224 +1664 ./prep_dataset/ILSVRC2012_val_00036656.bin 224 224 +1665 ./prep_dataset/ILSVRC2012_val_00047755.bin 224 224 +1666 ./prep_dataset/ILSVRC2012_val_00005135.bin 224 224 +1667 ./prep_dataset/ILSVRC2012_val_00044362.bin 224 224 +1668 ./prep_dataset/ILSVRC2012_val_00020946.bin 224 224 +1669 ./prep_dataset/ILSVRC2012_val_00038642.bin 224 224 +1670 ./prep_dataset/ILSVRC2012_val_00009501.bin 224 224 +1671 ./prep_dataset/ILSVRC2012_val_00002554.bin 224 224 +1672 ./prep_dataset/ILSVRC2012_val_00032833.bin 224 224 +1673 ./prep_dataset/ILSVRC2012_val_00004084.bin 224 224 +1674 ./prep_dataset/ILSVRC2012_val_00005968.bin 224 224 +1675 ./prep_dataset/ILSVRC2012_val_00013151.bin 224 224 +1676 ./prep_dataset/ILSVRC2012_val_00005526.bin 224 224 +1677 ./prep_dataset/ILSVRC2012_val_00005710.bin 224 224 +1678 ./prep_dataset/ILSVRC2012_val_00032592.bin 224 224 +1679 ./prep_dataset/ILSVRC2012_val_00016776.bin 224 224 +1680 ./prep_dataset/ILSVRC2012_val_00010325.bin 224 224 +1681 ./prep_dataset/ILSVRC2012_val_00046624.bin 224 224 +1682 ./prep_dataset/ILSVRC2012_val_00044683.bin 224 224 +1683 ./prep_dataset/ILSVRC2012_val_00047606.bin 224 224 +1684 ./prep_dataset/ILSVRC2012_val_00013608.bin 224 224 +1685 ./prep_dataset/ILSVRC2012_val_00009038.bin 224 224 +1686 ./prep_dataset/ILSVRC2012_val_00032831.bin 224 224 +1687 ./prep_dataset/ILSVRC2012_val_00017303.bin 224 224 +1688 ./prep_dataset/ILSVRC2012_val_00038935.bin 224 224 +1689 ./prep_dataset/ILSVRC2012_val_00023494.bin 224 224 +1690 ./prep_dataset/ILSVRC2012_val_00048789.bin 224 224 +1691 ./prep_dataset/ILSVRC2012_val_00019847.bin 224 224 +1692 ./prep_dataset/ILSVRC2012_val_00018253.bin 224 224 +1693 ./prep_dataset/ILSVRC2012_val_00048338.bin 224 224 +1694 ./prep_dataset/ILSVRC2012_val_00018036.bin 224 224 +1695 ./prep_dataset/ILSVRC2012_val_00015247.bin 224 224 +1696 ./prep_dataset/ILSVRC2012_val_00003412.bin 224 224 +1697 ./prep_dataset/ILSVRC2012_val_00029229.bin 224 224 +1698 ./prep_dataset/ILSVRC2012_val_00005387.bin 224 224 +1699 ./prep_dataset/ILSVRC2012_val_00029460.bin 224 224 +1700 ./prep_dataset/ILSVRC2012_val_00014897.bin 224 224 +1701 ./prep_dataset/ILSVRC2012_val_00016001.bin 224 224 +1702 ./prep_dataset/ILSVRC2012_val_00012410.bin 224 224 +1703 ./prep_dataset/ILSVRC2012_val_00034112.bin 224 224 +1704 ./prep_dataset/ILSVRC2012_val_00009967.bin 224 224 +1705 ./prep_dataset/ILSVRC2012_val_00046631.bin 224 224 +1706 ./prep_dataset/ILSVRC2012_val_00014337.bin 224 224 +1707 ./prep_dataset/ILSVRC2012_val_00022360.bin 224 224 +1708 ./prep_dataset/ILSVRC2012_val_00010527.bin 224 224 +1709 ./prep_dataset/ILSVRC2012_val_00008984.bin 224 224 +1710 ./prep_dataset/ILSVRC2012_val_00007808.bin 224 224 +1711 ./prep_dataset/ILSVRC2012_val_00022217.bin 224 224 +1712 ./prep_dataset/ILSVRC2012_val_00017124.bin 224 224 +1713 ./prep_dataset/ILSVRC2012_val_00003540.bin 224 224 +1714 ./prep_dataset/ILSVRC2012_val_00010584.bin 224 224 +1715 ./prep_dataset/ILSVRC2012_val_00016880.bin 224 224 +1716 ./prep_dataset/ILSVRC2012_val_00008838.bin 224 224 +1717 ./prep_dataset/ILSVRC2012_val_00017328.bin 224 224 +1718 ./prep_dataset/ILSVRC2012_val_00019747.bin 224 224 +1719 ./prep_dataset/ILSVRC2012_val_00032996.bin 224 224 +1720 ./prep_dataset/ILSVRC2012_val_00028605.bin 224 224 +1721 ./prep_dataset/ILSVRC2012_val_00004624.bin 224 224 +1722 ./prep_dataset/ILSVRC2012_val_00016996.bin 224 224 +1723 ./prep_dataset/ILSVRC2012_val_00032598.bin 224 224 +1724 ./prep_dataset/ILSVRC2012_val_00000957.bin 224 224 +1725 ./prep_dataset/ILSVRC2012_val_00004658.bin 224 224 +1726 ./prep_dataset/ILSVRC2012_val_00018345.bin 224 224 +1727 ./prep_dataset/ILSVRC2012_val_00016197.bin 224 224 +1728 ./prep_dataset/ILSVRC2012_val_00034265.bin 224 224 +1729 ./prep_dataset/ILSVRC2012_val_00040066.bin 224 224 +1730 ./prep_dataset/ILSVRC2012_val_00017497.bin 224 224 +1731 ./prep_dataset/ILSVRC2012_val_00046600.bin 224 224 +1732 ./prep_dataset/ILSVRC2012_val_00021426.bin 224 224 +1733 ./prep_dataset/ILSVRC2012_val_00031021.bin 224 224 +1734 ./prep_dataset/ILSVRC2012_val_00041145.bin 224 224 +1735 ./prep_dataset/ILSVRC2012_val_00006021.bin 224 224 +1736 ./prep_dataset/ILSVRC2012_val_00035955.bin 224 224 +1737 ./prep_dataset/ILSVRC2012_val_00013765.bin 224 224 +1738 ./prep_dataset/ILSVRC2012_val_00035173.bin 224 224 +1739 ./prep_dataset/ILSVRC2012_val_00047343.bin 224 224 +1740 ./prep_dataset/ILSVRC2012_val_00041702.bin 224 224 +1741 ./prep_dataset/ILSVRC2012_val_00045995.bin 224 224 +1742 ./prep_dataset/ILSVRC2012_val_00005237.bin 224 224 +1743 ./prep_dataset/ILSVRC2012_val_00006976.bin 224 224 +1744 ./prep_dataset/ILSVRC2012_val_00031795.bin 224 224 +1745 ./prep_dataset/ILSVRC2012_val_00011841.bin 224 224 +1746 ./prep_dataset/ILSVRC2012_val_00018420.bin 224 224 +1747 ./prep_dataset/ILSVRC2012_val_00018673.bin 224 224 +1748 ./prep_dataset/ILSVRC2012_val_00029248.bin 224 224 +1749 ./prep_dataset/ILSVRC2012_val_00037328.bin 224 224 +1750 ./prep_dataset/ILSVRC2012_val_00004139.bin 224 224 +1751 ./prep_dataset/ILSVRC2012_val_00011157.bin 224 224 +1752 ./prep_dataset/ILSVRC2012_val_00033068.bin 224 224 +1753 ./prep_dataset/ILSVRC2012_val_00004143.bin 224 224 +1754 ./prep_dataset/ILSVRC2012_val_00027847.bin 224 224 +1755 ./prep_dataset/ILSVRC2012_val_00011271.bin 224 224 +1756 ./prep_dataset/ILSVRC2012_val_00025553.bin 224 224 +1757 ./prep_dataset/ILSVRC2012_val_00049360.bin 224 224 +1758 ./prep_dataset/ILSVRC2012_val_00038115.bin 224 224 +1759 ./prep_dataset/ILSVRC2012_val_00048904.bin 224 224 +1760 ./prep_dataset/ILSVRC2012_val_00004076.bin 224 224 +1761 ./prep_dataset/ILSVRC2012_val_00040082.bin 224 224 +1762 ./prep_dataset/ILSVRC2012_val_00023139.bin 224 224 +1763 ./prep_dataset/ILSVRC2012_val_00037367.bin 224 224 +1764 ./prep_dataset/ILSVRC2012_val_00016347.bin 224 224 +1765 ./prep_dataset/ILSVRC2012_val_00013602.bin 224 224 +1766 ./prep_dataset/ILSVRC2012_val_00001462.bin 224 224 +1767 ./prep_dataset/ILSVRC2012_val_00038557.bin 224 224 +1768 ./prep_dataset/ILSVRC2012_val_00040568.bin 224 224 +1769 ./prep_dataset/ILSVRC2012_val_00008166.bin 224 224 +1770 ./prep_dataset/ILSVRC2012_val_00011806.bin 224 224 +1771 ./prep_dataset/ILSVRC2012_val_00038905.bin 224 224 +1772 ./prep_dataset/ILSVRC2012_val_00020437.bin 224 224 +1773 ./prep_dataset/ILSVRC2012_val_00033489.bin 224 224 +1774 ./prep_dataset/ILSVRC2012_val_00011402.bin 224 224 +1775 ./prep_dataset/ILSVRC2012_val_00041627.bin 224 224 +1776 ./prep_dataset/ILSVRC2012_val_00016395.bin 224 224 +1777 ./prep_dataset/ILSVRC2012_val_00005882.bin 224 224 +1778 ./prep_dataset/ILSVRC2012_val_00046775.bin 224 224 +1779 ./prep_dataset/ILSVRC2012_val_00000747.bin 224 224 +1780 ./prep_dataset/ILSVRC2012_val_00028441.bin 224 224 +1781 ./prep_dataset/ILSVRC2012_val_00010481.bin 224 224 +1782 ./prep_dataset/ILSVRC2012_val_00044427.bin 224 224 +1783 ./prep_dataset/ILSVRC2012_val_00001950.bin 224 224 +1784 ./prep_dataset/ILSVRC2012_val_00005631.bin 224 224 +1785 ./prep_dataset/ILSVRC2012_val_00014778.bin 224 224 +1786 ./prep_dataset/ILSVRC2012_val_00033583.bin 224 224 +1787 ./prep_dataset/ILSVRC2012_val_00031655.bin 224 224 +1788 ./prep_dataset/ILSVRC2012_val_00048388.bin 224 224 +1789 ./prep_dataset/ILSVRC2012_val_00045538.bin 224 224 +1790 ./prep_dataset/ILSVRC2012_val_00013502.bin 224 224 +1791 ./prep_dataset/ILSVRC2012_val_00043065.bin 224 224 +1792 ./prep_dataset/ILSVRC2012_val_00019990.bin 224 224 +1793 ./prep_dataset/ILSVRC2012_val_00026491.bin 224 224 +1794 ./prep_dataset/ILSVRC2012_val_00045479.bin 224 224 +1795 ./prep_dataset/ILSVRC2012_val_00035791.bin 224 224 +1796 ./prep_dataset/ILSVRC2012_val_00015362.bin 224 224 +1797 ./prep_dataset/ILSVRC2012_val_00031225.bin 224 224 +1798 ./prep_dataset/ILSVRC2012_val_00005160.bin 224 224 +1799 ./prep_dataset/ILSVRC2012_val_00001188.bin 224 224 +1800 ./prep_dataset/ILSVRC2012_val_00003670.bin 224 224 +1801 ./prep_dataset/ILSVRC2012_val_00023228.bin 224 224 +1802 ./prep_dataset/ILSVRC2012_val_00048997.bin 224 224 +1803 ./prep_dataset/ILSVRC2012_val_00041146.bin 224 224 +1804 ./prep_dataset/ILSVRC2012_val_00001955.bin 224 224 +1805 ./prep_dataset/ILSVRC2012_val_00047191.bin 224 224 +1806 ./prep_dataset/ILSVRC2012_val_00047544.bin 224 224 +1807 ./prep_dataset/ILSVRC2012_val_00031770.bin 224 224 +1808 ./prep_dataset/ILSVRC2012_val_00042463.bin 224 224 +1809 ./prep_dataset/ILSVRC2012_val_00020775.bin 224 224 +1810 ./prep_dataset/ILSVRC2012_val_00030020.bin 224 224 +1811 ./prep_dataset/ILSVRC2012_val_00024688.bin 224 224 +1812 ./prep_dataset/ILSVRC2012_val_00002477.bin 224 224 +1813 ./prep_dataset/ILSVRC2012_val_00037319.bin 224 224 +1814 ./prep_dataset/ILSVRC2012_val_00023206.bin 224 224 +1815 ./prep_dataset/ILSVRC2012_val_00021707.bin 224 224 +1816 ./prep_dataset/ILSVRC2012_val_00049123.bin 224 224 +1817 ./prep_dataset/ILSVRC2012_val_00010773.bin 224 224 +1818 ./prep_dataset/ILSVRC2012_val_00027516.bin 224 224 +1819 ./prep_dataset/ILSVRC2012_val_00040641.bin 224 224 +1820 ./prep_dataset/ILSVRC2012_val_00021225.bin 224 224 +1821 ./prep_dataset/ILSVRC2012_val_00012208.bin 224 224 +1822 ./prep_dataset/ILSVRC2012_val_00008630.bin 224 224 +1823 ./prep_dataset/ILSVRC2012_val_00033162.bin 224 224 +1824 ./prep_dataset/ILSVRC2012_val_00022248.bin 224 224 +1825 ./prep_dataset/ILSVRC2012_val_00043769.bin 224 224 +1826 ./prep_dataset/ILSVRC2012_val_00009722.bin 224 224 +1827 ./prep_dataset/ILSVRC2012_val_00009988.bin 224 224 +1828 ./prep_dataset/ILSVRC2012_val_00030347.bin 224 224 +1829 ./prep_dataset/ILSVRC2012_val_00017510.bin 224 224 +1830 ./prep_dataset/ILSVRC2012_val_00022488.bin 224 224 +1831 ./prep_dataset/ILSVRC2012_val_00013131.bin 224 224 +1832 ./prep_dataset/ILSVRC2012_val_00046863.bin 224 224 +1833 ./prep_dataset/ILSVRC2012_val_00037821.bin 224 224 +1834 ./prep_dataset/ILSVRC2012_val_00039947.bin 224 224 +1835 ./prep_dataset/ILSVRC2012_val_00015575.bin 224 224 +1836 ./prep_dataset/ILSVRC2012_val_00049387.bin 224 224 +1837 ./prep_dataset/ILSVRC2012_val_00045082.bin 224 224 +1838 ./prep_dataset/ILSVRC2012_val_00007164.bin 224 224 +1839 ./prep_dataset/ILSVRC2012_val_00006257.bin 224 224 +1840 ./prep_dataset/ILSVRC2012_val_00038436.bin 224 224 +1841 ./prep_dataset/ILSVRC2012_val_00024781.bin 224 224 +1842 ./prep_dataset/ILSVRC2012_val_00011199.bin 224 224 +1843 ./prep_dataset/ILSVRC2012_val_00007464.bin 224 224 +1844 ./prep_dataset/ILSVRC2012_val_00002861.bin 224 224 +1845 ./prep_dataset/ILSVRC2012_val_00022054.bin 224 224 +1846 ./prep_dataset/ILSVRC2012_val_00008640.bin 224 224 +1847 ./prep_dataset/ILSVRC2012_val_00044712.bin 224 224 +1848 ./prep_dataset/ILSVRC2012_val_00017277.bin 224 224 +1849 ./prep_dataset/ILSVRC2012_val_00001222.bin 224 224 +1850 ./prep_dataset/ILSVRC2012_val_00012365.bin 224 224 +1851 ./prep_dataset/ILSVRC2012_val_00001104.bin 224 224 +1852 ./prep_dataset/ILSVRC2012_val_00028707.bin 224 224 +1853 ./prep_dataset/ILSVRC2012_val_00031686.bin 224 224 +1854 ./prep_dataset/ILSVRC2012_val_00030723.bin 224 224 +1855 ./prep_dataset/ILSVRC2012_val_00021624.bin 224 224 +1856 ./prep_dataset/ILSVRC2012_val_00040699.bin 224 224 +1857 ./prep_dataset/ILSVRC2012_val_00025587.bin 224 224 +1858 ./prep_dataset/ILSVRC2012_val_00023796.bin 224 224 +1859 ./prep_dataset/ILSVRC2012_val_00025392.bin 224 224 +1860 ./prep_dataset/ILSVRC2012_val_00042953.bin 224 224 +1861 ./prep_dataset/ILSVRC2012_val_00010170.bin 224 224 +1862 ./prep_dataset/ILSVRC2012_val_00000376.bin 224 224 +1863 ./prep_dataset/ILSVRC2012_val_00019489.bin 224 224 +1864 ./prep_dataset/ILSVRC2012_val_00001242.bin 224 224 +1865 ./prep_dataset/ILSVRC2012_val_00021618.bin 224 224 +1866 ./prep_dataset/ILSVRC2012_val_00005960.bin 224 224 +1867 ./prep_dataset/ILSVRC2012_val_00007590.bin 224 224 +1868 ./prep_dataset/ILSVRC2012_val_00011876.bin 224 224 +1869 ./prep_dataset/ILSVRC2012_val_00039362.bin 224 224 +1870 ./prep_dataset/ILSVRC2012_val_00019289.bin 224 224 +1871 ./prep_dataset/ILSVRC2012_val_00019474.bin 224 224 +1872 ./prep_dataset/ILSVRC2012_val_00034599.bin 224 224 +1873 ./prep_dataset/ILSVRC2012_val_00001615.bin 224 224 +1874 ./prep_dataset/ILSVRC2012_val_00044961.bin 224 224 +1875 ./prep_dataset/ILSVRC2012_val_00047211.bin 224 224 +1876 ./prep_dataset/ILSVRC2012_val_00004204.bin 224 224 +1877 ./prep_dataset/ILSVRC2012_val_00018372.bin 224 224 +1878 ./prep_dataset/ILSVRC2012_val_00014564.bin 224 224 +1879 ./prep_dataset/ILSVRC2012_val_00015886.bin 224 224 +1880 ./prep_dataset/ILSVRC2012_val_00035677.bin 224 224 +1881 ./prep_dataset/ILSVRC2012_val_00043099.bin 224 224 +1882 ./prep_dataset/ILSVRC2012_val_00021735.bin 224 224 +1883 ./prep_dataset/ILSVRC2012_val_00016175.bin 224 224 +1884 ./prep_dataset/ILSVRC2012_val_00018637.bin 224 224 +1885 ./prep_dataset/ILSVRC2012_val_00008534.bin 224 224 +1886 ./prep_dataset/ILSVRC2012_val_00007251.bin 224 224 +1887 ./prep_dataset/ILSVRC2012_val_00035613.bin 224 224 +1888 ./prep_dataset/ILSVRC2012_val_00021896.bin 224 224 +1889 ./prep_dataset/ILSVRC2012_val_00003023.bin 224 224 +1890 ./prep_dataset/ILSVRC2012_val_00018635.bin 224 224 +1891 ./prep_dataset/ILSVRC2012_val_00037305.bin 224 224 +1892 ./prep_dataset/ILSVRC2012_val_00045646.bin 224 224 +1893 ./prep_dataset/ILSVRC2012_val_00039509.bin 224 224 +1894 ./prep_dataset/ILSVRC2012_val_00026323.bin 224 224 +1895 ./prep_dataset/ILSVRC2012_val_00049601.bin 224 224 +1896 ./prep_dataset/ILSVRC2012_val_00003542.bin 224 224 +1897 ./prep_dataset/ILSVRC2012_val_00036123.bin 224 224 +1898 ./prep_dataset/ILSVRC2012_val_00047767.bin 224 224 +1899 ./prep_dataset/ILSVRC2012_val_00011003.bin 224 224 +1900 ./prep_dataset/ILSVRC2012_val_00010020.bin 224 224 +1901 ./prep_dataset/ILSVRC2012_val_00018891.bin 224 224 +1902 ./prep_dataset/ILSVRC2012_val_00044792.bin 224 224 +1903 ./prep_dataset/ILSVRC2012_val_00013106.bin 224 224 +1904 ./prep_dataset/ILSVRC2012_val_00030922.bin 224 224 +1905 ./prep_dataset/ILSVRC2012_val_00044670.bin 224 224 +1906 ./prep_dataset/ILSVRC2012_val_00044929.bin 224 224 +1907 ./prep_dataset/ILSVRC2012_val_00023825.bin 224 224 +1908 ./prep_dataset/ILSVRC2012_val_00001477.bin 224 224 +1909 ./prep_dataset/ILSVRC2012_val_00006339.bin 224 224 +1910 ./prep_dataset/ILSVRC2012_val_00044070.bin 224 224 +1911 ./prep_dataset/ILSVRC2012_val_00010216.bin 224 224 +1912 ./prep_dataset/ILSVRC2012_val_00022950.bin 224 224 +1913 ./prep_dataset/ILSVRC2012_val_00017256.bin 224 224 +1914 ./prep_dataset/ILSVRC2012_val_00041879.bin 224 224 +1915 ./prep_dataset/ILSVRC2012_val_00033154.bin 224 224 +1916 ./prep_dataset/ILSVRC2012_val_00013583.bin 224 224 +1917 ./prep_dataset/ILSVRC2012_val_00028344.bin 224 224 +1918 ./prep_dataset/ILSVRC2012_val_00030885.bin 224 224 +1919 ./prep_dataset/ILSVRC2012_val_00037855.bin 224 224 +1920 ./prep_dataset/ILSVRC2012_val_00029205.bin 224 224 +1921 ./prep_dataset/ILSVRC2012_val_00032882.bin 224 224 +1922 ./prep_dataset/ILSVRC2012_val_00045796.bin 224 224 +1923 ./prep_dataset/ILSVRC2012_val_00040664.bin 224 224 +1924 ./prep_dataset/ILSVRC2012_val_00009839.bin 224 224 +1925 ./prep_dataset/ILSVRC2012_val_00035601.bin 224 224 +1926 ./prep_dataset/ILSVRC2012_val_00018166.bin 224 224 +1927 ./prep_dataset/ILSVRC2012_val_00001411.bin 224 224 +1928 ./prep_dataset/ILSVRC2012_val_00025832.bin 224 224 +1929 ./prep_dataset/ILSVRC2012_val_00013464.bin 224 224 +1930 ./prep_dataset/ILSVRC2012_val_00002045.bin 224 224 +1931 ./prep_dataset/ILSVRC2012_val_00040319.bin 224 224 +1932 ./prep_dataset/ILSVRC2012_val_00018805.bin 224 224 +1933 ./prep_dataset/ILSVRC2012_val_00044508.bin 224 224 +1934 ./prep_dataset/ILSVRC2012_val_00039414.bin 224 224 +1935 ./prep_dataset/ILSVRC2012_val_00039211.bin 224 224 +1936 ./prep_dataset/ILSVRC2012_val_00000622.bin 224 224 +1937 ./prep_dataset/ILSVRC2012_val_00006163.bin 224 224 +1938 ./prep_dataset/ILSVRC2012_val_00004242.bin 224 224 +1939 ./prep_dataset/ILSVRC2012_val_00028122.bin 224 224 +1940 ./prep_dataset/ILSVRC2012_val_00047377.bin 224 224 +1941 ./prep_dataset/ILSVRC2012_val_00037079.bin 224 224 +1942 ./prep_dataset/ILSVRC2012_val_00048366.bin 224 224 +1943 ./prep_dataset/ILSVRC2012_val_00046357.bin 224 224 +1944 ./prep_dataset/ILSVRC2012_val_00001181.bin 224 224 +1945 ./prep_dataset/ILSVRC2012_val_00037637.bin 224 224 +1946 ./prep_dataset/ILSVRC2012_val_00008043.bin 224 224 +1947 ./prep_dataset/ILSVRC2012_val_00008479.bin 224 224 +1948 ./prep_dataset/ILSVRC2012_val_00002167.bin 224 224 +1949 ./prep_dataset/ILSVRC2012_val_00027710.bin 224 224 +1950 ./prep_dataset/ILSVRC2012_val_00044190.bin 224 224 +1951 ./prep_dataset/ILSVRC2012_val_00025196.bin 224 224 +1952 ./prep_dataset/ILSVRC2012_val_00022564.bin 224 224 +1953 ./prep_dataset/ILSVRC2012_val_00047116.bin 224 224 +1954 ./prep_dataset/ILSVRC2012_val_00039595.bin 224 224 +1955 ./prep_dataset/ILSVRC2012_val_00002104.bin 224 224 +1956 ./prep_dataset/ILSVRC2012_val_00008336.bin 224 224 +1957 ./prep_dataset/ILSVRC2012_val_00042404.bin 224 224 +1958 ./prep_dataset/ILSVRC2012_val_00007081.bin 224 224 +1959 ./prep_dataset/ILSVRC2012_val_00035512.bin 224 224 +1960 ./prep_dataset/ILSVRC2012_val_00034729.bin 224 224 +1961 ./prep_dataset/ILSVRC2012_val_00005746.bin 224 224 +1962 ./prep_dataset/ILSVRC2012_val_00046387.bin 224 224 +1963 ./prep_dataset/ILSVRC2012_val_00029309.bin 224 224 +1964 ./prep_dataset/ILSVRC2012_val_00011854.bin 224 224 +1965 ./prep_dataset/ILSVRC2012_val_00026705.bin 224 224 +1966 ./prep_dataset/ILSVRC2012_val_00018269.bin 224 224 +1967 ./prep_dataset/ILSVRC2012_val_00025945.bin 224 224 +1968 ./prep_dataset/ILSVRC2012_val_00000954.bin 224 224 +1969 ./prep_dataset/ILSVRC2012_val_00000625.bin 224 224 +1970 ./prep_dataset/ILSVRC2012_val_00002936.bin 224 224 +1971 ./prep_dataset/ILSVRC2012_val_00005917.bin 224 224 +1972 ./prep_dataset/ILSVRC2012_val_00031684.bin 224 224 +1973 ./prep_dataset/ILSVRC2012_val_00036353.bin 224 224 +1974 ./prep_dataset/ILSVRC2012_val_00046926.bin 224 224 +1975 ./prep_dataset/ILSVRC2012_val_00013030.bin 224 224 +1976 ./prep_dataset/ILSVRC2012_val_00006480.bin 224 224 +1977 ./prep_dataset/ILSVRC2012_val_00033436.bin 224 224 +1978 ./prep_dataset/ILSVRC2012_val_00030462.bin 224 224 +1979 ./prep_dataset/ILSVRC2012_val_00035430.bin 224 224 +1980 ./prep_dataset/ILSVRC2012_val_00015878.bin 224 224 +1981 ./prep_dataset/ILSVRC2012_val_00022804.bin 224 224 +1982 ./prep_dataset/ILSVRC2012_val_00016824.bin 224 224 +1983 ./prep_dataset/ILSVRC2012_val_00008661.bin 224 224 +1984 ./prep_dataset/ILSVRC2012_val_00017784.bin 224 224 +1985 ./prep_dataset/ILSVRC2012_val_00047478.bin 224 224 +1986 ./prep_dataset/ILSVRC2012_val_00039306.bin 224 224 +1987 ./prep_dataset/ILSVRC2012_val_00044419.bin 224 224 +1988 ./prep_dataset/ILSVRC2012_val_00042923.bin 224 224 +1989 ./prep_dataset/ILSVRC2012_val_00010974.bin 224 224 +1990 ./prep_dataset/ILSVRC2012_val_00027513.bin 224 224 +1991 ./prep_dataset/ILSVRC2012_val_00040017.bin 224 224 +1992 ./prep_dataset/ILSVRC2012_val_00008118.bin 224 224 +1993 ./prep_dataset/ILSVRC2012_val_00035625.bin 224 224 +1994 ./prep_dataset/ILSVRC2012_val_00021125.bin 224 224 +1995 ./prep_dataset/ILSVRC2012_val_00019205.bin 224 224 +1996 ./prep_dataset/ILSVRC2012_val_00042558.bin 224 224 +1997 ./prep_dataset/ILSVRC2012_val_00040630.bin 224 224 +1998 ./prep_dataset/ILSVRC2012_val_00017621.bin 224 224 +1999 ./prep_dataset/ILSVRC2012_val_00010987.bin 224 224 +2000 ./prep_dataset/ILSVRC2012_val_00032266.bin 224 224 +2001 ./prep_dataset/ILSVRC2012_val_00027462.bin 224 224 +2002 ./prep_dataset/ILSVRC2012_val_00015444.bin 224 224 +2003 ./prep_dataset/ILSVRC2012_val_00023883.bin 224 224 +2004 ./prep_dataset/ILSVRC2012_val_00007799.bin 224 224 +2005 ./prep_dataset/ILSVRC2012_val_00018114.bin 224 224 +2006 ./prep_dataset/ILSVRC2012_val_00036927.bin 224 224 +2007 ./prep_dataset/ILSVRC2012_val_00005576.bin 224 224 +2008 ./prep_dataset/ILSVRC2012_val_00017689.bin 224 224 +2009 ./prep_dataset/ILSVRC2012_val_00018570.bin 224 224 +2010 ./prep_dataset/ILSVRC2012_val_00040228.bin 224 224 +2011 ./prep_dataset/ILSVRC2012_val_00028338.bin 224 224 +2012 ./prep_dataset/ILSVRC2012_val_00019588.bin 224 224 +2013 ./prep_dataset/ILSVRC2012_val_00044069.bin 224 224 +2014 ./prep_dataset/ILSVRC2012_val_00020399.bin 224 224 +2015 ./prep_dataset/ILSVRC2012_val_00033452.bin 224 224 +2016 ./prep_dataset/ILSVRC2012_val_00029287.bin 224 224 +2017 ./prep_dataset/ILSVRC2012_val_00038738.bin 224 224 +2018 ./prep_dataset/ILSVRC2012_val_00021768.bin 224 224 +2019 ./prep_dataset/ILSVRC2012_val_00042162.bin 224 224 +2020 ./prep_dataset/ILSVRC2012_val_00042330.bin 224 224 +2021 ./prep_dataset/ILSVRC2012_val_00044239.bin 224 224 +2022 ./prep_dataset/ILSVRC2012_val_00027318.bin 224 224 +2023 ./prep_dataset/ILSVRC2012_val_00016591.bin 224 224 +2024 ./prep_dataset/ILSVRC2012_val_00027458.bin 224 224 +2025 ./prep_dataset/ILSVRC2012_val_00016928.bin 224 224 +2026 ./prep_dataset/ILSVRC2012_val_00018136.bin 224 224 +2027 ./prep_dataset/ILSVRC2012_val_00020018.bin 224 224 +2028 ./prep_dataset/ILSVRC2012_val_00048961.bin 224 224 +2029 ./prep_dataset/ILSVRC2012_val_00024326.bin 224 224 +2030 ./prep_dataset/ILSVRC2012_val_00031477.bin 224 224 +2031 ./prep_dataset/ILSVRC2012_val_00023018.bin 224 224 +2032 ./prep_dataset/ILSVRC2012_val_00047882.bin 224 224 +2033 ./prep_dataset/ILSVRC2012_val_00006036.bin 224 224 +2034 ./prep_dataset/ILSVRC2012_val_00048032.bin 224 224 +2035 ./prep_dataset/ILSVRC2012_val_00011550.bin 224 224 +2036 ./prep_dataset/ILSVRC2012_val_00037628.bin 224 224 +2037 ./prep_dataset/ILSVRC2012_val_00025129.bin 224 224 +2038 ./prep_dataset/ILSVRC2012_val_00017736.bin 224 224 +2039 ./prep_dataset/ILSVRC2012_val_00000667.bin 224 224 +2040 ./prep_dataset/ILSVRC2012_val_00047396.bin 224 224 +2041 ./prep_dataset/ILSVRC2012_val_00016075.bin 224 224 +2042 ./prep_dataset/ILSVRC2012_val_00036879.bin 224 224 +2043 ./prep_dataset/ILSVRC2012_val_00031214.bin 224 224 +2044 ./prep_dataset/ILSVRC2012_val_00049611.bin 224 224 +2045 ./prep_dataset/ILSVRC2012_val_00003538.bin 224 224 +2046 ./prep_dataset/ILSVRC2012_val_00014438.bin 224 224 +2047 ./prep_dataset/ILSVRC2012_val_00049694.bin 224 224 +2048 ./prep_dataset/ILSVRC2012_val_00007828.bin 224 224 +2049 ./prep_dataset/ILSVRC2012_val_00048655.bin 224 224 +2050 ./prep_dataset/ILSVRC2012_val_00033409.bin 224 224 +2051 ./prep_dataset/ILSVRC2012_val_00045270.bin 224 224 +2052 ./prep_dataset/ILSVRC2012_val_00040814.bin 224 224 +2053 ./prep_dataset/ILSVRC2012_val_00042870.bin 224 224 +2054 ./prep_dataset/ILSVRC2012_val_00014774.bin 224 224 +2055 ./prep_dataset/ILSVRC2012_val_00012638.bin 224 224 +2056 ./prep_dataset/ILSVRC2012_val_00041156.bin 224 224 +2057 ./prep_dataset/ILSVRC2012_val_00030804.bin 224 224 +2058 ./prep_dataset/ILSVRC2012_val_00024875.bin 224 224 +2059 ./prep_dataset/ILSVRC2012_val_00005996.bin 224 224 +2060 ./prep_dataset/ILSVRC2012_val_00007831.bin 224 224 +2061 ./prep_dataset/ILSVRC2012_val_00032095.bin 224 224 +2062 ./prep_dataset/ILSVRC2012_val_00000601.bin 224 224 +2063 ./prep_dataset/ILSVRC2012_val_00049966.bin 224 224 +2064 ./prep_dataset/ILSVRC2012_val_00021126.bin 224 224 +2065 ./prep_dataset/ILSVRC2012_val_00015007.bin 224 224 +2066 ./prep_dataset/ILSVRC2012_val_00034879.bin 224 224 +2067 ./prep_dataset/ILSVRC2012_val_00027627.bin 224 224 +2068 ./prep_dataset/ILSVRC2012_val_00000320.bin 224 224 +2069 ./prep_dataset/ILSVRC2012_val_00001581.bin 224 224 +2070 ./prep_dataset/ILSVRC2012_val_00042944.bin 224 224 +2071 ./prep_dataset/ILSVRC2012_val_00049362.bin 224 224 +2072 ./prep_dataset/ILSVRC2012_val_00036735.bin 224 224 +2073 ./prep_dataset/ILSVRC2012_val_00021522.bin 224 224 +2074 ./prep_dataset/ILSVRC2012_val_00035914.bin 224 224 +2075 ./prep_dataset/ILSVRC2012_val_00012931.bin 224 224 +2076 ./prep_dataset/ILSVRC2012_val_00034934.bin 224 224 +2077 ./prep_dataset/ILSVRC2012_val_00010856.bin 224 224 +2078 ./prep_dataset/ILSVRC2012_val_00018414.bin 224 224 +2079 ./prep_dataset/ILSVRC2012_val_00007287.bin 224 224 +2080 ./prep_dataset/ILSVRC2012_val_00029526.bin 224 224 +2081 ./prep_dataset/ILSVRC2012_val_00005097.bin 224 224 +2082 ./prep_dataset/ILSVRC2012_val_00007897.bin 224 224 +2083 ./prep_dataset/ILSVRC2012_val_00017791.bin 224 224 +2084 ./prep_dataset/ILSVRC2012_val_00003219.bin 224 224 +2085 ./prep_dataset/ILSVRC2012_val_00033598.bin 224 224 +2086 ./prep_dataset/ILSVRC2012_val_00024494.bin 224 224 +2087 ./prep_dataset/ILSVRC2012_val_00021799.bin 224 224 +2088 ./prep_dataset/ILSVRC2012_val_00049382.bin 224 224 +2089 ./prep_dataset/ILSVRC2012_val_00018896.bin 224 224 +2090 ./prep_dataset/ILSVRC2012_val_00034835.bin 224 224 +2091 ./prep_dataset/ILSVRC2012_val_00049561.bin 224 224 +2092 ./prep_dataset/ILSVRC2012_val_00046053.bin 224 224 +2093 ./prep_dataset/ILSVRC2012_val_00026914.bin 224 224 +2094 ./prep_dataset/ILSVRC2012_val_00044020.bin 224 224 +2095 ./prep_dataset/ILSVRC2012_val_00042048.bin 224 224 +2096 ./prep_dataset/ILSVRC2012_val_00011941.bin 224 224 +2097 ./prep_dataset/ILSVRC2012_val_00032052.bin 224 224 +2098 ./prep_dataset/ILSVRC2012_val_00041326.bin 224 224 +2099 ./prep_dataset/ILSVRC2012_val_00011848.bin 224 224 +2100 ./prep_dataset/ILSVRC2012_val_00017088.bin 224 224 +2101 ./prep_dataset/ILSVRC2012_val_00029414.bin 224 224 +2102 ./prep_dataset/ILSVRC2012_val_00035697.bin 224 224 +2103 ./prep_dataset/ILSVRC2012_val_00017787.bin 224 224 +2104 ./prep_dataset/ILSVRC2012_val_00032765.bin 224 224 +2105 ./prep_dataset/ILSVRC2012_val_00002365.bin 224 224 +2106 ./prep_dataset/ILSVRC2012_val_00009657.bin 224 224 +2107 ./prep_dataset/ILSVRC2012_val_00043529.bin 224 224 +2108 ./prep_dataset/ILSVRC2012_val_00022473.bin 224 224 +2109 ./prep_dataset/ILSVRC2012_val_00021398.bin 224 224 +2110 ./prep_dataset/ILSVRC2012_val_00029000.bin 224 224 +2111 ./prep_dataset/ILSVRC2012_val_00006796.bin 224 224 +2112 ./prep_dataset/ILSVRC2012_val_00029382.bin 224 224 +2113 ./prep_dataset/ILSVRC2012_val_00032400.bin 224 224 +2114 ./prep_dataset/ILSVRC2012_val_00026617.bin 224 224 +2115 ./prep_dataset/ILSVRC2012_val_00027635.bin 224 224 +2116 ./prep_dataset/ILSVRC2012_val_00027965.bin 224 224 +2117 ./prep_dataset/ILSVRC2012_val_00033912.bin 224 224 +2118 ./prep_dataset/ILSVRC2012_val_00046225.bin 224 224 +2119 ./prep_dataset/ILSVRC2012_val_00004984.bin 224 224 +2120 ./prep_dataset/ILSVRC2012_val_00010125.bin 224 224 +2121 ./prep_dataset/ILSVRC2012_val_00031152.bin 224 224 +2122 ./prep_dataset/ILSVRC2012_val_00025773.bin 224 224 +2123 ./prep_dataset/ILSVRC2012_val_00048899.bin 224 224 +2124 ./prep_dataset/ILSVRC2012_val_00032328.bin 224 224 +2125 ./prep_dataset/ILSVRC2012_val_00010774.bin 224 224 +2126 ./prep_dataset/ILSVRC2012_val_00041822.bin 224 224 +2127 ./prep_dataset/ILSVRC2012_val_00012574.bin 224 224 +2128 ./prep_dataset/ILSVRC2012_val_00021229.bin 224 224 +2129 ./prep_dataset/ILSVRC2012_val_00043944.bin 224 224 +2130 ./prep_dataset/ILSVRC2012_val_00029950.bin 224 224 +2131 ./prep_dataset/ILSVRC2012_val_00018549.bin 224 224 +2132 ./prep_dataset/ILSVRC2012_val_00030308.bin 224 224 +2133 ./prep_dataset/ILSVRC2012_val_00007049.bin 224 224 +2134 ./prep_dataset/ILSVRC2012_val_00042257.bin 224 224 +2135 ./prep_dataset/ILSVRC2012_val_00033146.bin 224 224 +2136 ./prep_dataset/ILSVRC2012_val_00026423.bin 224 224 +2137 ./prep_dataset/ILSVRC2012_val_00045836.bin 224 224 +2138 ./prep_dataset/ILSVRC2012_val_00006553.bin 224 224 +2139 ./prep_dataset/ILSVRC2012_val_00017659.bin 224 224 +2140 ./prep_dataset/ILSVRC2012_val_00042110.bin 224 224 +2141 ./prep_dataset/ILSVRC2012_val_00000751.bin 224 224 +2142 ./prep_dataset/ILSVRC2012_val_00010883.bin 224 224 +2143 ./prep_dataset/ILSVRC2012_val_00006639.bin 224 224 +2144 ./prep_dataset/ILSVRC2012_val_00030400.bin 224 224 +2145 ./prep_dataset/ILSVRC2012_val_00045064.bin 224 224 +2146 ./prep_dataset/ILSVRC2012_val_00030870.bin 224 224 +2147 ./prep_dataset/ILSVRC2012_val_00009852.bin 224 224 +2148 ./prep_dataset/ILSVRC2012_val_00022495.bin 224 224 +2149 ./prep_dataset/ILSVRC2012_val_00036599.bin 224 224 +2150 ./prep_dataset/ILSVRC2012_val_00048235.bin 224 224 +2151 ./prep_dataset/ILSVRC2012_val_00033578.bin 224 224 +2152 ./prep_dataset/ILSVRC2012_val_00049868.bin 224 224 +2153 ./prep_dataset/ILSVRC2012_val_00047247.bin 224 224 +2154 ./prep_dataset/ILSVRC2012_val_00023076.bin 224 224 +2155 ./prep_dataset/ILSVRC2012_val_00037983.bin 224 224 +2156 ./prep_dataset/ILSVRC2012_val_00047579.bin 224 224 +2157 ./prep_dataset/ILSVRC2012_val_00002906.bin 224 224 +2158 ./prep_dataset/ILSVRC2012_val_00012607.bin 224 224 +2159 ./prep_dataset/ILSVRC2012_val_00048102.bin 224 224 +2160 ./prep_dataset/ILSVRC2012_val_00021596.bin 224 224 +2161 ./prep_dataset/ILSVRC2012_val_00001907.bin 224 224 +2162 ./prep_dataset/ILSVRC2012_val_00026282.bin 224 224 +2163 ./prep_dataset/ILSVRC2012_val_00029424.bin 224 224 +2164 ./prep_dataset/ILSVRC2012_val_00029352.bin 224 224 +2165 ./prep_dataset/ILSVRC2012_val_00048112.bin 224 224 +2166 ./prep_dataset/ILSVRC2012_val_00015266.bin 224 224 +2167 ./prep_dataset/ILSVRC2012_val_00021039.bin 224 224 +2168 ./prep_dataset/ILSVRC2012_val_00000546.bin 224 224 +2169 ./prep_dataset/ILSVRC2012_val_00040904.bin 224 224 +2170 ./prep_dataset/ILSVRC2012_val_00045336.bin 224 224 +2171 ./prep_dataset/ILSVRC2012_val_00018965.bin 224 224 +2172 ./prep_dataset/ILSVRC2012_val_00038749.bin 224 224 +2173 ./prep_dataset/ILSVRC2012_val_00033998.bin 224 224 +2174 ./prep_dataset/ILSVRC2012_val_00003765.bin 224 224 +2175 ./prep_dataset/ILSVRC2012_val_00023004.bin 224 224 +2176 ./prep_dataset/ILSVRC2012_val_00032464.bin 224 224 +2177 ./prep_dataset/ILSVRC2012_val_00027628.bin 224 224 +2178 ./prep_dataset/ILSVRC2012_val_00021112.bin 224 224 +2179 ./prep_dataset/ILSVRC2012_val_00006265.bin 224 224 +2180 ./prep_dataset/ILSVRC2012_val_00045021.bin 224 224 +2181 ./prep_dataset/ILSVRC2012_val_00044711.bin 224 224 +2182 ./prep_dataset/ILSVRC2012_val_00010310.bin 224 224 +2183 ./prep_dataset/ILSVRC2012_val_00043072.bin 224 224 +2184 ./prep_dataset/ILSVRC2012_val_00001676.bin 224 224 +2185 ./prep_dataset/ILSVRC2012_val_00018066.bin 224 224 +2186 ./prep_dataset/ILSVRC2012_val_00029571.bin 224 224 +2187 ./prep_dataset/ILSVRC2012_val_00011691.bin 224 224 +2188 ./prep_dataset/ILSVRC2012_val_00042651.bin 224 224 +2189 ./prep_dataset/ILSVRC2012_val_00025126.bin 224 224 +2190 ./prep_dataset/ILSVRC2012_val_00045798.bin 224 224 +2191 ./prep_dataset/ILSVRC2012_val_00028248.bin 224 224 +2192 ./prep_dataset/ILSVRC2012_val_00049752.bin 224 224 +2193 ./prep_dataset/ILSVRC2012_val_00026994.bin 224 224 +2194 ./prep_dataset/ILSVRC2012_val_00041184.bin 224 224 +2195 ./prep_dataset/ILSVRC2012_val_00029695.bin 224 224 +2196 ./prep_dataset/ILSVRC2012_val_00015016.bin 224 224 +2197 ./prep_dataset/ILSVRC2012_val_00021918.bin 224 224 +2198 ./prep_dataset/ILSVRC2012_val_00024170.bin 224 224 +2199 ./prep_dataset/ILSVRC2012_val_00000606.bin 224 224 +2200 ./prep_dataset/ILSVRC2012_val_00038838.bin 224 224 +2201 ./prep_dataset/ILSVRC2012_val_00030149.bin 224 224 +2202 ./prep_dataset/ILSVRC2012_val_00040729.bin 224 224 +2203 ./prep_dataset/ILSVRC2012_val_00010019.bin 224 224 +2204 ./prep_dataset/ILSVRC2012_val_00033357.bin 224 224 +2205 ./prep_dataset/ILSVRC2012_val_00013648.bin 224 224 +2206 ./prep_dataset/ILSVRC2012_val_00014541.bin 224 224 +2207 ./prep_dataset/ILSVRC2012_val_00036935.bin 224 224 +2208 ./prep_dataset/ILSVRC2012_val_00015915.bin 224 224 +2209 ./prep_dataset/ILSVRC2012_val_00039047.bin 224 224 +2210 ./prep_dataset/ILSVRC2012_val_00003615.bin 224 224 +2211 ./prep_dataset/ILSVRC2012_val_00029947.bin 224 224 +2212 ./prep_dataset/ILSVRC2012_val_00009809.bin 224 224 +2213 ./prep_dataset/ILSVRC2012_val_00046454.bin 224 224 +2214 ./prep_dataset/ILSVRC2012_val_00036136.bin 224 224 +2215 ./prep_dataset/ILSVRC2012_val_00039951.bin 224 224 +2216 ./prep_dataset/ILSVRC2012_val_00015562.bin 224 224 +2217 ./prep_dataset/ILSVRC2012_val_00034718.bin 224 224 +2218 ./prep_dataset/ILSVRC2012_val_00018541.bin 224 224 +2219 ./prep_dataset/ILSVRC2012_val_00001370.bin 224 224 +2220 ./prep_dataset/ILSVRC2012_val_00020179.bin 224 224 +2221 ./prep_dataset/ILSVRC2012_val_00018845.bin 224 224 +2222 ./prep_dataset/ILSVRC2012_val_00003942.bin 224 224 +2223 ./prep_dataset/ILSVRC2012_val_00005685.bin 224 224 +2224 ./prep_dataset/ILSVRC2012_val_00043343.bin 224 224 +2225 ./prep_dataset/ILSVRC2012_val_00027776.bin 224 224 +2226 ./prep_dataset/ILSVRC2012_val_00027202.bin 224 224 +2227 ./prep_dataset/ILSVRC2012_val_00049490.bin 224 224 +2228 ./prep_dataset/ILSVRC2012_val_00049307.bin 224 224 +2229 ./prep_dataset/ILSVRC2012_val_00046755.bin 224 224 +2230 ./prep_dataset/ILSVRC2012_val_00026375.bin 224 224 +2231 ./prep_dataset/ILSVRC2012_val_00027393.bin 224 224 +2232 ./prep_dataset/ILSVRC2012_val_00021379.bin 224 224 +2233 ./prep_dataset/ILSVRC2012_val_00015071.bin 224 224 +2234 ./prep_dataset/ILSVRC2012_val_00005655.bin 224 224 +2235 ./prep_dataset/ILSVRC2012_val_00049361.bin 224 224 +2236 ./prep_dataset/ILSVRC2012_val_00035903.bin 224 224 +2237 ./prep_dataset/ILSVRC2012_val_00006345.bin 224 224 +2238 ./prep_dataset/ILSVRC2012_val_00041405.bin 224 224 +2239 ./prep_dataset/ILSVRC2012_val_00046467.bin 224 224 +2240 ./prep_dataset/ILSVRC2012_val_00012283.bin 224 224 +2241 ./prep_dataset/ILSVRC2012_val_00002185.bin 224 224 +2242 ./prep_dataset/ILSVRC2012_val_00034929.bin 224 224 +2243 ./prep_dataset/ILSVRC2012_val_00039716.bin 224 224 +2244 ./prep_dataset/ILSVRC2012_val_00003149.bin 224 224 +2245 ./prep_dataset/ILSVRC2012_val_00005633.bin 224 224 +2246 ./prep_dataset/ILSVRC2012_val_00000647.bin 224 224 +2247 ./prep_dataset/ILSVRC2012_val_00012639.bin 224 224 +2248 ./prep_dataset/ILSVRC2012_val_00036064.bin 224 224 +2249 ./prep_dataset/ILSVRC2012_val_00015169.bin 224 224 +2250 ./prep_dataset/ILSVRC2012_val_00000092.bin 224 224 +2251 ./prep_dataset/ILSVRC2012_val_00021071.bin 224 224 +2252 ./prep_dataset/ILSVRC2012_val_00004339.bin 224 224 +2253 ./prep_dataset/ILSVRC2012_val_00012434.bin 224 224 +2254 ./prep_dataset/ILSVRC2012_val_00022946.bin 224 224 +2255 ./prep_dataset/ILSVRC2012_val_00033313.bin 224 224 +2256 ./prep_dataset/ILSVRC2012_val_00021012.bin 224 224 +2257 ./prep_dataset/ILSVRC2012_val_00011596.bin 224 224 +2258 ./prep_dataset/ILSVRC2012_val_00037593.bin 224 224 +2259 ./prep_dataset/ILSVRC2012_val_00035558.bin 224 224 +2260 ./prep_dataset/ILSVRC2012_val_00042847.bin 224 224 +2261 ./prep_dataset/ILSVRC2012_val_00036980.bin 224 224 +2262 ./prep_dataset/ILSVRC2012_val_00017871.bin 224 224 +2263 ./prep_dataset/ILSVRC2012_val_00021609.bin 224 224 +2264 ./prep_dataset/ILSVRC2012_val_00006950.bin 224 224 +2265 ./prep_dataset/ILSVRC2012_val_00001534.bin 224 224 +2266 ./prep_dataset/ILSVRC2012_val_00034898.bin 224 224 +2267 ./prep_dataset/ILSVRC2012_val_00038397.bin 224 224 +2268 ./prep_dataset/ILSVRC2012_val_00013414.bin 224 224 +2269 ./prep_dataset/ILSVRC2012_val_00045226.bin 224 224 +2270 ./prep_dataset/ILSVRC2012_val_00036568.bin 224 224 +2271 ./prep_dataset/ILSVRC2012_val_00035704.bin 224 224 +2272 ./prep_dataset/ILSVRC2012_val_00034833.bin 224 224 +2273 ./prep_dataset/ILSVRC2012_val_00008363.bin 224 224 +2274 ./prep_dataset/ILSVRC2012_val_00044329.bin 224 224 +2275 ./prep_dataset/ILSVRC2012_val_00021964.bin 224 224 +2276 ./prep_dataset/ILSVRC2012_val_00037435.bin 224 224 +2277 ./prep_dataset/ILSVRC2012_val_00045121.bin 224 224 +2278 ./prep_dataset/ILSVRC2012_val_00048007.bin 224 224 +2279 ./prep_dataset/ILSVRC2012_val_00002303.bin 224 224 +2280 ./prep_dataset/ILSVRC2012_val_00015041.bin 224 224 +2281 ./prep_dataset/ILSVRC2012_val_00016912.bin 224 224 +2282 ./prep_dataset/ILSVRC2012_val_00005924.bin 224 224 +2283 ./prep_dataset/ILSVRC2012_val_00038170.bin 224 224 +2284 ./prep_dataset/ILSVRC2012_val_00024216.bin 224 224 +2285 ./prep_dataset/ILSVRC2012_val_00031812.bin 224 224 +2286 ./prep_dataset/ILSVRC2012_val_00000080.bin 224 224 +2287 ./prep_dataset/ILSVRC2012_val_00006893.bin 224 224 +2288 ./prep_dataset/ILSVRC2012_val_00021307.bin 224 224 +2289 ./prep_dataset/ILSVRC2012_val_00032160.bin 224 224 +2290 ./prep_dataset/ILSVRC2012_val_00003737.bin 224 224 +2291 ./prep_dataset/ILSVRC2012_val_00044820.bin 224 224 +2292 ./prep_dataset/ILSVRC2012_val_00045973.bin 224 224 +2293 ./prep_dataset/ILSVRC2012_val_00010496.bin 224 224 +2294 ./prep_dataset/ILSVRC2012_val_00032528.bin 224 224 +2295 ./prep_dataset/ILSVRC2012_val_00005075.bin 224 224 +2296 ./prep_dataset/ILSVRC2012_val_00035076.bin 224 224 +2297 ./prep_dataset/ILSVRC2012_val_00011915.bin 224 224 +2298 ./prep_dataset/ILSVRC2012_val_00013984.bin 224 224 +2299 ./prep_dataset/ILSVRC2012_val_00046958.bin 224 224 +2300 ./prep_dataset/ILSVRC2012_val_00023555.bin 224 224 +2301 ./prep_dataset/ILSVRC2012_val_00024397.bin 224 224 +2302 ./prep_dataset/ILSVRC2012_val_00008295.bin 224 224 +2303 ./prep_dataset/ILSVRC2012_val_00039823.bin 224 224 +2304 ./prep_dataset/ILSVRC2012_val_00005066.bin 224 224 +2305 ./prep_dataset/ILSVRC2012_val_00031931.bin 224 224 +2306 ./prep_dataset/ILSVRC2012_val_00041940.bin 224 224 +2307 ./prep_dataset/ILSVRC2012_val_00045950.bin 224 224 +2308 ./prep_dataset/ILSVRC2012_val_00043215.bin 224 224 +2309 ./prep_dataset/ILSVRC2012_val_00033781.bin 224 224 +2310 ./prep_dataset/ILSVRC2012_val_00037066.bin 224 224 +2311 ./prep_dataset/ILSVRC2012_val_00041731.bin 224 224 +2312 ./prep_dataset/ILSVRC2012_val_00019722.bin 224 224 +2313 ./prep_dataset/ILSVRC2012_val_00008143.bin 224 224 +2314 ./prep_dataset/ILSVRC2012_val_00038487.bin 224 224 +2315 ./prep_dataset/ILSVRC2012_val_00033010.bin 224 224 +2316 ./prep_dataset/ILSVRC2012_val_00029773.bin 224 224 +2317 ./prep_dataset/ILSVRC2012_val_00034139.bin 224 224 +2318 ./prep_dataset/ILSVRC2012_val_00021441.bin 224 224 +2319 ./prep_dataset/ILSVRC2012_val_00004662.bin 224 224 +2320 ./prep_dataset/ILSVRC2012_val_00036720.bin 224 224 +2321 ./prep_dataset/ILSVRC2012_val_00036623.bin 224 224 +2322 ./prep_dataset/ILSVRC2012_val_00013086.bin 224 224 +2323 ./prep_dataset/ILSVRC2012_val_00032672.bin 224 224 +2324 ./prep_dataset/ILSVRC2012_val_00009728.bin 224 224 +2325 ./prep_dataset/ILSVRC2012_val_00027870.bin 224 224 +2326 ./prep_dataset/ILSVRC2012_val_00021882.bin 224 224 +2327 ./prep_dataset/ILSVRC2012_val_00018319.bin 224 224 +2328 ./prep_dataset/ILSVRC2012_val_00003108.bin 224 224 +2329 ./prep_dataset/ILSVRC2012_val_00008748.bin 224 224 +2330 ./prep_dataset/ILSVRC2012_val_00017781.bin 224 224 +2331 ./prep_dataset/ILSVRC2012_val_00033747.bin 224 224 +2332 ./prep_dataset/ILSVRC2012_val_00008997.bin 224 224 +2333 ./prep_dataset/ILSVRC2012_val_00046255.bin 224 224 +2334 ./prep_dataset/ILSVRC2012_val_00022874.bin 224 224 +2335 ./prep_dataset/ILSVRC2012_val_00027053.bin 224 224 +2336 ./prep_dataset/ILSVRC2012_val_00047212.bin 224 224 +2337 ./prep_dataset/ILSVRC2012_val_00007123.bin 224 224 +2338 ./prep_dataset/ILSVRC2012_val_00041783.bin 224 224 +2339 ./prep_dataset/ILSVRC2012_val_00046658.bin 224 224 +2340 ./prep_dataset/ILSVRC2012_val_00014299.bin 224 224 +2341 ./prep_dataset/ILSVRC2012_val_00037759.bin 224 224 +2342 ./prep_dataset/ILSVRC2012_val_00006380.bin 224 224 +2343 ./prep_dataset/ILSVRC2012_val_00021662.bin 224 224 +2344 ./prep_dataset/ILSVRC2012_val_00045212.bin 224 224 +2345 ./prep_dataset/ILSVRC2012_val_00036445.bin 224 224 +2346 ./prep_dataset/ILSVRC2012_val_00039896.bin 224 224 +2347 ./prep_dataset/ILSVRC2012_val_00029339.bin 224 224 +2348 ./prep_dataset/ILSVRC2012_val_00001984.bin 224 224 +2349 ./prep_dataset/ILSVRC2012_val_00026152.bin 224 224 +2350 ./prep_dataset/ILSVRC2012_val_00035518.bin 224 224 +2351 ./prep_dataset/ILSVRC2012_val_00041920.bin 224 224 +2352 ./prep_dataset/ILSVRC2012_val_00048761.bin 224 224 +2353 ./prep_dataset/ILSVRC2012_val_00030122.bin 224 224 +2354 ./prep_dataset/ILSVRC2012_val_00013296.bin 224 224 +2355 ./prep_dataset/ILSVRC2012_val_00012749.bin 224 224 +2356 ./prep_dataset/ILSVRC2012_val_00002829.bin 224 224 +2357 ./prep_dataset/ILSVRC2012_val_00015713.bin 224 224 +2358 ./prep_dataset/ILSVRC2012_val_00008421.bin 224 224 +2359 ./prep_dataset/ILSVRC2012_val_00015165.bin 224 224 +2360 ./prep_dataset/ILSVRC2012_val_00024983.bin 224 224 +2361 ./prep_dataset/ILSVRC2012_val_00020193.bin 224 224 +2362 ./prep_dataset/ILSVRC2012_val_00012175.bin 224 224 +2363 ./prep_dataset/ILSVRC2012_val_00006335.bin 224 224 +2364 ./prep_dataset/ILSVRC2012_val_00019912.bin 224 224 +2365 ./prep_dataset/ILSVRC2012_val_00039977.bin 224 224 +2366 ./prep_dataset/ILSVRC2012_val_00037099.bin 224 224 +2367 ./prep_dataset/ILSVRC2012_val_00042103.bin 224 224 +2368 ./prep_dataset/ILSVRC2012_val_00022983.bin 224 224 +2369 ./prep_dataset/ILSVRC2012_val_00026638.bin 224 224 +2370 ./prep_dataset/ILSVRC2012_val_00026890.bin 224 224 +2371 ./prep_dataset/ILSVRC2012_val_00023573.bin 224 224 +2372 ./prep_dataset/ILSVRC2012_val_00011684.bin 224 224 +2373 ./prep_dataset/ILSVRC2012_val_00016628.bin 224 224 +2374 ./prep_dataset/ILSVRC2012_val_00017135.bin 224 224 +2375 ./prep_dataset/ILSVRC2012_val_00009118.bin 224 224 +2376 ./prep_dataset/ILSVRC2012_val_00036074.bin 224 224 +2377 ./prep_dataset/ILSVRC2012_val_00042522.bin 224 224 +2378 ./prep_dataset/ILSVRC2012_val_00033590.bin 224 224 +2379 ./prep_dataset/ILSVRC2012_val_00023112.bin 224 224 +2380 ./prep_dataset/ILSVRC2012_val_00019902.bin 224 224 +2381 ./prep_dataset/ILSVRC2012_val_00046697.bin 224 224 +2382 ./prep_dataset/ILSVRC2012_val_00030478.bin 224 224 +2383 ./prep_dataset/ILSVRC2012_val_00018205.bin 224 224 +2384 ./prep_dataset/ILSVRC2012_val_00046413.bin 224 224 +2385 ./prep_dataset/ILSVRC2012_val_00023286.bin 224 224 +2386 ./prep_dataset/ILSVRC2012_val_00045494.bin 224 224 +2387 ./prep_dataset/ILSVRC2012_val_00048063.bin 224 224 +2388 ./prep_dataset/ILSVRC2012_val_00018754.bin 224 224 +2389 ./prep_dataset/ILSVRC2012_val_00001596.bin 224 224 +2390 ./prep_dataset/ILSVRC2012_val_00014181.bin 224 224 +2391 ./prep_dataset/ILSVRC2012_val_00045505.bin 224 224 +2392 ./prep_dataset/ILSVRC2012_val_00005233.bin 224 224 +2393 ./prep_dataset/ILSVRC2012_val_00018519.bin 224 224 +2394 ./prep_dataset/ILSVRC2012_val_00010091.bin 224 224 +2395 ./prep_dataset/ILSVRC2012_val_00043927.bin 224 224 +2396 ./prep_dataset/ILSVRC2012_val_00009066.bin 224 224 +2397 ./prep_dataset/ILSVRC2012_val_00005715.bin 224 224 +2398 ./prep_dataset/ILSVRC2012_val_00048476.bin 224 224 +2399 ./prep_dataset/ILSVRC2012_val_00037155.bin 224 224 +2400 ./prep_dataset/ILSVRC2012_val_00006469.bin 224 224 +2401 ./prep_dataset/ILSVRC2012_val_00049839.bin 224 224 +2402 ./prep_dataset/ILSVRC2012_val_00047529.bin 224 224 +2403 ./prep_dataset/ILSVRC2012_val_00008298.bin 224 224 +2404 ./prep_dataset/ILSVRC2012_val_00006763.bin 224 224 +2405 ./prep_dataset/ILSVRC2012_val_00020649.bin 224 224 +2406 ./prep_dataset/ILSVRC2012_val_00034556.bin 224 224 +2407 ./prep_dataset/ILSVRC2012_val_00040394.bin 224 224 +2408 ./prep_dataset/ILSVRC2012_val_00035309.bin 224 224 +2409 ./prep_dataset/ILSVRC2012_val_00025338.bin 224 224 +2410 ./prep_dataset/ILSVRC2012_val_00045036.bin 224 224 +2411 ./prep_dataset/ILSVRC2012_val_00047346.bin 224 224 +2412 ./prep_dataset/ILSVRC2012_val_00001336.bin 224 224 +2413 ./prep_dataset/ILSVRC2012_val_00002123.bin 224 224 +2414 ./prep_dataset/ILSVRC2012_val_00020276.bin 224 224 +2415 ./prep_dataset/ILSVRC2012_val_00004032.bin 224 224 +2416 ./prep_dataset/ILSVRC2012_val_00032303.bin 224 224 +2417 ./prep_dataset/ILSVRC2012_val_00024189.bin 224 224 +2418 ./prep_dataset/ILSVRC2012_val_00049059.bin 224 224 +2419 ./prep_dataset/ILSVRC2012_val_00049374.bin 224 224 +2420 ./prep_dataset/ILSVRC2012_val_00002929.bin 224 224 +2421 ./prep_dataset/ILSVRC2012_val_00010623.bin 224 224 +2422 ./prep_dataset/ILSVRC2012_val_00007622.bin 224 224 +2423 ./prep_dataset/ILSVRC2012_val_00000512.bin 224 224 +2424 ./prep_dataset/ILSVRC2012_val_00004623.bin 224 224 +2425 ./prep_dataset/ILSVRC2012_val_00004101.bin 224 224 +2426 ./prep_dataset/ILSVRC2012_val_00049984.bin 224 224 +2427 ./prep_dataset/ILSVRC2012_val_00023411.bin 224 224 +2428 ./prep_dataset/ILSVRC2012_val_00021698.bin 224 224 +2429 ./prep_dataset/ILSVRC2012_val_00031615.bin 224 224 +2430 ./prep_dataset/ILSVRC2012_val_00046520.bin 224 224 +2431 ./prep_dataset/ILSVRC2012_val_00007050.bin 224 224 +2432 ./prep_dataset/ILSVRC2012_val_00044307.bin 224 224 +2433 ./prep_dataset/ILSVRC2012_val_00007324.bin 224 224 +2434 ./prep_dataset/ILSVRC2012_val_00007579.bin 224 224 +2435 ./prep_dataset/ILSVRC2012_val_00007222.bin 224 224 +2436 ./prep_dataset/ILSVRC2012_val_00026535.bin 224 224 +2437 ./prep_dataset/ILSVRC2012_val_00015643.bin 224 224 +2438 ./prep_dataset/ILSVRC2012_val_00027920.bin 224 224 +2439 ./prep_dataset/ILSVRC2012_val_00031985.bin 224 224 +2440 ./prep_dataset/ILSVRC2012_val_00043679.bin 224 224 +2441 ./prep_dataset/ILSVRC2012_val_00018241.bin 224 224 +2442 ./prep_dataset/ILSVRC2012_val_00027358.bin 224 224 +2443 ./prep_dataset/ILSVRC2012_val_00023336.bin 224 224 +2444 ./prep_dataset/ILSVRC2012_val_00028213.bin 224 224 +2445 ./prep_dataset/ILSVRC2012_val_00036254.bin 224 224 +2446 ./prep_dataset/ILSVRC2012_val_00039531.bin 224 224 +2447 ./prep_dataset/ILSVRC2012_val_00031786.bin 224 224 +2448 ./prep_dataset/ILSVRC2012_val_00017387.bin 224 224 +2449 ./prep_dataset/ILSVRC2012_val_00033905.bin 224 224 +2450 ./prep_dataset/ILSVRC2012_val_00024436.bin 224 224 +2451 ./prep_dataset/ILSVRC2012_val_00009978.bin 224 224 +2452 ./prep_dataset/ILSVRC2012_val_00005916.bin 224 224 +2453 ./prep_dataset/ILSVRC2012_val_00026412.bin 224 224 +2454 ./prep_dataset/ILSVRC2012_val_00036713.bin 224 224 +2455 ./prep_dataset/ILSVRC2012_val_00041642.bin 224 224 +2456 ./prep_dataset/ILSVRC2012_val_00043394.bin 224 224 +2457 ./prep_dataset/ILSVRC2012_val_00003350.bin 224 224 +2458 ./prep_dataset/ILSVRC2012_val_00028975.bin 224 224 +2459 ./prep_dataset/ILSVRC2012_val_00020439.bin 224 224 +2460 ./prep_dataset/ILSVRC2012_val_00008294.bin 224 224 +2461 ./prep_dataset/ILSVRC2012_val_00009133.bin 224 224 +2462 ./prep_dataset/ILSVRC2012_val_00024454.bin 224 224 +2463 ./prep_dataset/ILSVRC2012_val_00036406.bin 224 224 +2464 ./prep_dataset/ILSVRC2012_val_00002126.bin 224 224 +2465 ./prep_dataset/ILSVRC2012_val_00016556.bin 224 224 +2466 ./prep_dataset/ILSVRC2012_val_00012246.bin 224 224 +2467 ./prep_dataset/ILSVRC2012_val_00037946.bin 224 224 +2468 ./prep_dataset/ILSVRC2012_val_00046308.bin 224 224 +2469 ./prep_dataset/ILSVRC2012_val_00000437.bin 224 224 +2470 ./prep_dataset/ILSVRC2012_val_00040916.bin 224 224 +2471 ./prep_dataset/ILSVRC2012_val_00028721.bin 224 224 +2472 ./prep_dataset/ILSVRC2012_val_00031679.bin 224 224 +2473 ./prep_dataset/ILSVRC2012_val_00015848.bin 224 224 +2474 ./prep_dataset/ILSVRC2012_val_00033346.bin 224 224 +2475 ./prep_dataset/ILSVRC2012_val_00002988.bin 224 224 +2476 ./prep_dataset/ILSVRC2012_val_00012864.bin 224 224 +2477 ./prep_dataset/ILSVRC2012_val_00036666.bin 224 224 +2478 ./prep_dataset/ILSVRC2012_val_00044188.bin 224 224 +2479 ./prep_dataset/ILSVRC2012_val_00031595.bin 224 224 +2480 ./prep_dataset/ILSVRC2012_val_00033634.bin 224 224 +2481 ./prep_dataset/ILSVRC2012_val_00010771.bin 224 224 +2482 ./prep_dataset/ILSVRC2012_val_00024718.bin 224 224 +2483 ./prep_dataset/ILSVRC2012_val_00009387.bin 224 224 +2484 ./prep_dataset/ILSVRC2012_val_00044421.bin 224 224 +2485 ./prep_dataset/ILSVRC2012_val_00036903.bin 224 224 +2486 ./prep_dataset/ILSVRC2012_val_00043637.bin 224 224 +2487 ./prep_dataset/ILSVRC2012_val_00002036.bin 224 224 +2488 ./prep_dataset/ILSVRC2012_val_00009242.bin 224 224 +2489 ./prep_dataset/ILSVRC2012_val_00016343.bin 224 224 +2490 ./prep_dataset/ILSVRC2012_val_00019216.bin 224 224 +2491 ./prep_dataset/ILSVRC2012_val_00029254.bin 224 224 +2492 ./prep_dataset/ILSVRC2012_val_00046891.bin 224 224 +2493 ./prep_dataset/ILSVRC2012_val_00020477.bin 224 224 +2494 ./prep_dataset/ILSVRC2012_val_00046699.bin 224 224 +2495 ./prep_dataset/ILSVRC2012_val_00030182.bin 224 224 +2496 ./prep_dataset/ILSVRC2012_val_00006200.bin 224 224 +2497 ./prep_dataset/ILSVRC2012_val_00016535.bin 224 224 +2498 ./prep_dataset/ILSVRC2012_val_00005439.bin 224 224 +2499 ./prep_dataset/ILSVRC2012_val_00024057.bin 224 224 +2500 ./prep_dataset/ILSVRC2012_val_00009532.bin 224 224 +2501 ./prep_dataset/ILSVRC2012_val_00020656.bin 224 224 +2502 ./prep_dataset/ILSVRC2012_val_00039883.bin 224 224 +2503 ./prep_dataset/ILSVRC2012_val_00003533.bin 224 224 +2504 ./prep_dataset/ILSVRC2012_val_00039225.bin 224 224 +2505 ./prep_dataset/ILSVRC2012_val_00014739.bin 224 224 +2506 ./prep_dataset/ILSVRC2012_val_00027437.bin 224 224 +2507 ./prep_dataset/ILSVRC2012_val_00016119.bin 224 224 +2508 ./prep_dataset/ILSVRC2012_val_00019766.bin 224 224 +2509 ./prep_dataset/ILSVRC2012_val_00005865.bin 224 224 +2510 ./prep_dataset/ILSVRC2012_val_00001092.bin 224 224 +2511 ./prep_dataset/ILSVRC2012_val_00037749.bin 224 224 +2512 ./prep_dataset/ILSVRC2012_val_00024840.bin 224 224 +2513 ./prep_dataset/ILSVRC2012_val_00010425.bin 224 224 +2514 ./prep_dataset/ILSVRC2012_val_00025789.bin 224 224 +2515 ./prep_dataset/ILSVRC2012_val_00022167.bin 224 224 +2516 ./prep_dataset/ILSVRC2012_val_00043811.bin 224 224 +2517 ./prep_dataset/ILSVRC2012_val_00001374.bin 224 224 +2518 ./prep_dataset/ILSVRC2012_val_00038733.bin 224 224 +2519 ./prep_dataset/ILSVRC2012_val_00007206.bin 224 224 +2520 ./prep_dataset/ILSVRC2012_val_00000059.bin 224 224 +2521 ./prep_dataset/ILSVRC2012_val_00027914.bin 224 224 +2522 ./prep_dataset/ILSVRC2012_val_00045604.bin 224 224 +2523 ./prep_dataset/ILSVRC2012_val_00014440.bin 224 224 +2524 ./prep_dataset/ILSVRC2012_val_00042885.bin 224 224 +2525 ./prep_dataset/ILSVRC2012_val_00032022.bin 224 224 +2526 ./prep_dataset/ILSVRC2012_val_00035530.bin 224 224 +2527 ./prep_dataset/ILSVRC2012_val_00003757.bin 224 224 +2528 ./prep_dataset/ILSVRC2012_val_00026054.bin 224 224 +2529 ./prep_dataset/ILSVRC2012_val_00014725.bin 224 224 +2530 ./prep_dataset/ILSVRC2012_val_00038628.bin 224 224 +2531 ./prep_dataset/ILSVRC2012_val_00049670.bin 224 224 +2532 ./prep_dataset/ILSVRC2012_val_00028969.bin 224 224 +2533 ./prep_dataset/ILSVRC2012_val_00027124.bin 224 224 +2534 ./prep_dataset/ILSVRC2012_val_00040969.bin 224 224 +2535 ./prep_dataset/ILSVRC2012_val_00047303.bin 224 224 +2536 ./prep_dataset/ILSVRC2012_val_00043558.bin 224 224 +2537 ./prep_dataset/ILSVRC2012_val_00012056.bin 224 224 +2538 ./prep_dataset/ILSVRC2012_val_00022595.bin 224 224 +2539 ./prep_dataset/ILSVRC2012_val_00023196.bin 224 224 +2540 ./prep_dataset/ILSVRC2012_val_00027982.bin 224 224 +2541 ./prep_dataset/ILSVRC2012_val_00016801.bin 224 224 +2542 ./prep_dataset/ILSVRC2012_val_00009709.bin 224 224 +2543 ./prep_dataset/ILSVRC2012_val_00006106.bin 224 224 +2544 ./prep_dataset/ILSVRC2012_val_00014092.bin 224 224 +2545 ./prep_dataset/ILSVRC2012_val_00039399.bin 224 224 +2546 ./prep_dataset/ILSVRC2012_val_00009301.bin 224 224 +2547 ./prep_dataset/ILSVRC2012_val_00016839.bin 224 224 +2548 ./prep_dataset/ILSVRC2012_val_00030851.bin 224 224 +2549 ./prep_dataset/ILSVRC2012_val_00039209.bin 224 224 +2550 ./prep_dataset/ILSVRC2012_val_00017884.bin 224 224 +2551 ./prep_dataset/ILSVRC2012_val_00008982.bin 224 224 +2552 ./prep_dataset/ILSVRC2012_val_00042927.bin 224 224 +2553 ./prep_dataset/ILSVRC2012_val_00019200.bin 224 224 +2554 ./prep_dataset/ILSVRC2012_val_00007840.bin 224 224 +2555 ./prep_dataset/ILSVRC2012_val_00035502.bin 224 224 +2556 ./prep_dataset/ILSVRC2012_val_00047923.bin 224 224 +2557 ./prep_dataset/ILSVRC2012_val_00038971.bin 224 224 +2558 ./prep_dataset/ILSVRC2012_val_00044376.bin 224 224 +2559 ./prep_dataset/ILSVRC2012_val_00049672.bin 224 224 +2560 ./prep_dataset/ILSVRC2012_val_00017461.bin 224 224 +2561 ./prep_dataset/ILSVRC2012_val_00021840.bin 224 224 +2562 ./prep_dataset/ILSVRC2012_val_00037144.bin 224 224 +2563 ./prep_dataset/ILSVRC2012_val_00030434.bin 224 224 +2564 ./prep_dataset/ILSVRC2012_val_00015896.bin 224 224 +2565 ./prep_dataset/ILSVRC2012_val_00036440.bin 224 224 +2566 ./prep_dataset/ILSVRC2012_val_00004736.bin 224 224 +2567 ./prep_dataset/ILSVRC2012_val_00030960.bin 224 224 +2568 ./prep_dataset/ILSVRC2012_val_00016054.bin 224 224 +2569 ./prep_dataset/ILSVRC2012_val_00013934.bin 224 224 +2570 ./prep_dataset/ILSVRC2012_val_00015500.bin 224 224 +2571 ./prep_dataset/ILSVRC2012_val_00024098.bin 224 224 +2572 ./prep_dataset/ILSVRC2012_val_00031731.bin 224 224 +2573 ./prep_dataset/ILSVRC2012_val_00021576.bin 224 224 +2574 ./prep_dataset/ILSVRC2012_val_00034696.bin 224 224 +2575 ./prep_dataset/ILSVRC2012_val_00007294.bin 224 224 +2576 ./prep_dataset/ILSVRC2012_val_00021565.bin 224 224 +2577 ./prep_dataset/ILSVRC2012_val_00012149.bin 224 224 +2578 ./prep_dataset/ILSVRC2012_val_00028254.bin 224 224 +2579 ./prep_dataset/ILSVRC2012_val_00045440.bin 224 224 +2580 ./prep_dataset/ILSVRC2012_val_00011383.bin 224 224 +2581 ./prep_dataset/ILSVRC2012_val_00010692.bin 224 224 +2582 ./prep_dataset/ILSVRC2012_val_00004340.bin 224 224 +2583 ./prep_dataset/ILSVRC2012_val_00044333.bin 224 224 +2584 ./prep_dataset/ILSVRC2012_val_00004187.bin 224 224 +2585 ./prep_dataset/ILSVRC2012_val_00006657.bin 224 224 +2586 ./prep_dataset/ILSVRC2012_val_00038349.bin 224 224 +2587 ./prep_dataset/ILSVRC2012_val_00017598.bin 224 224 +2588 ./prep_dataset/ILSVRC2012_val_00035138.bin 224 224 +2589 ./prep_dataset/ILSVRC2012_val_00013161.bin 224 224 +2590 ./prep_dataset/ILSVRC2012_val_00046532.bin 224 224 +2591 ./prep_dataset/ILSVRC2012_val_00009587.bin 224 224 +2592 ./prep_dataset/ILSVRC2012_val_00002525.bin 224 224 +2593 ./prep_dataset/ILSVRC2012_val_00014649.bin 224 224 +2594 ./prep_dataset/ILSVRC2012_val_00007527.bin 224 224 +2595 ./prep_dataset/ILSVRC2012_val_00003919.bin 224 224 +2596 ./prep_dataset/ILSVRC2012_val_00011956.bin 224 224 +2597 ./prep_dataset/ILSVRC2012_val_00032640.bin 224 224 +2598 ./prep_dataset/ILSVRC2012_val_00011727.bin 224 224 +2599 ./prep_dataset/ILSVRC2012_val_00015805.bin 224 224 +2600 ./prep_dataset/ILSVRC2012_val_00036337.bin 224 224 +2601 ./prep_dataset/ILSVRC2012_val_00045330.bin 224 224 +2602 ./prep_dataset/ILSVRC2012_val_00048604.bin 224 224 +2603 ./prep_dataset/ILSVRC2012_val_00016325.bin 224 224 +2604 ./prep_dataset/ILSVRC2012_val_00000845.bin 224 224 +2605 ./prep_dataset/ILSVRC2012_val_00002407.bin 224 224 +2606 ./prep_dataset/ILSVRC2012_val_00025917.bin 224 224 +2607 ./prep_dataset/ILSVRC2012_val_00017810.bin 224 224 +2608 ./prep_dataset/ILSVRC2012_val_00015407.bin 224 224 +2609 ./prep_dataset/ILSVRC2012_val_00028236.bin 224 224 +2610 ./prep_dataset/ILSVRC2012_val_00039610.bin 224 224 +2611 ./prep_dataset/ILSVRC2012_val_00026724.bin 224 224 +2612 ./prep_dataset/ILSVRC2012_val_00046442.bin 224 224 +2613 ./prep_dataset/ILSVRC2012_val_00022903.bin 224 224 +2614 ./prep_dataset/ILSVRC2012_val_00037869.bin 224 224 +2615 ./prep_dataset/ILSVRC2012_val_00019157.bin 224 224 +2616 ./prep_dataset/ILSVRC2012_val_00031205.bin 224 224 +2617 ./prep_dataset/ILSVRC2012_val_00043299.bin 224 224 +2618 ./prep_dataset/ILSVRC2012_val_00039623.bin 224 224 +2619 ./prep_dataset/ILSVRC2012_val_00026157.bin 224 224 +2620 ./prep_dataset/ILSVRC2012_val_00045050.bin 224 224 +2621 ./prep_dataset/ILSVRC2012_val_00000319.bin 224 224 +2622 ./prep_dataset/ILSVRC2012_val_00030233.bin 224 224 +2623 ./prep_dataset/ILSVRC2012_val_00028842.bin 224 224 +2624 ./prep_dataset/ILSVRC2012_val_00023490.bin 224 224 +2625 ./prep_dataset/ILSVRC2012_val_00013167.bin 224 224 +2626 ./prep_dataset/ILSVRC2012_val_00021079.bin 224 224 +2627 ./prep_dataset/ILSVRC2012_val_00001111.bin 224 224 +2628 ./prep_dataset/ILSVRC2012_val_00037876.bin 224 224 +2629 ./prep_dataset/ILSVRC2012_val_00020468.bin 224 224 +2630 ./prep_dataset/ILSVRC2012_val_00011699.bin 224 224 +2631 ./prep_dataset/ILSVRC2012_val_00040088.bin 224 224 +2632 ./prep_dataset/ILSVRC2012_val_00024632.bin 224 224 +2633 ./prep_dataset/ILSVRC2012_val_00021509.bin 224 224 +2634 ./prep_dataset/ILSVRC2012_val_00041370.bin 224 224 +2635 ./prep_dataset/ILSVRC2012_val_00019062.bin 224 224 +2636 ./prep_dataset/ILSVRC2012_val_00025421.bin 224 224 +2637 ./prep_dataset/ILSVRC2012_val_00035357.bin 224 224 +2638 ./prep_dataset/ILSVRC2012_val_00018535.bin 224 224 +2639 ./prep_dataset/ILSVRC2012_val_00035762.bin 224 224 +2640 ./prep_dataset/ILSVRC2012_val_00032891.bin 224 224 +2641 ./prep_dataset/ILSVRC2012_val_00001593.bin 224 224 +2642 ./prep_dataset/ILSVRC2012_val_00013509.bin 224 224 +2643 ./prep_dataset/ILSVRC2012_val_00044720.bin 224 224 +2644 ./prep_dataset/ILSVRC2012_val_00038243.bin 224 224 +2645 ./prep_dataset/ILSVRC2012_val_00014632.bin 224 224 +2646 ./prep_dataset/ILSVRC2012_val_00026877.bin 224 224 +2647 ./prep_dataset/ILSVRC2012_val_00038660.bin 224 224 +2648 ./prep_dataset/ILSVRC2012_val_00048937.bin 224 224 +2649 ./prep_dataset/ILSVRC2012_val_00017719.bin 224 224 +2650 ./prep_dataset/ILSVRC2012_val_00027131.bin 224 224 +2651 ./prep_dataset/ILSVRC2012_val_00017761.bin 224 224 +2652 ./prep_dataset/ILSVRC2012_val_00044831.bin 224 224 +2653 ./prep_dataset/ILSVRC2012_val_00028990.bin 224 224 +2654 ./prep_dataset/ILSVRC2012_val_00010748.bin 224 224 +2655 ./prep_dataset/ILSVRC2012_val_00042489.bin 224 224 +2656 ./prep_dataset/ILSVRC2012_val_00036887.bin 224 224 +2657 ./prep_dataset/ILSVRC2012_val_00037026.bin 224 224 +2658 ./prep_dataset/ILSVRC2012_val_00011605.bin 224 224 +2659 ./prep_dataset/ILSVRC2012_val_00020601.bin 224 224 +2660 ./prep_dataset/ILSVRC2012_val_00010950.bin 224 224 +2661 ./prep_dataset/ILSVRC2012_val_00041751.bin 224 224 +2662 ./prep_dataset/ILSVRC2012_val_00021539.bin 224 224 +2663 ./prep_dataset/ILSVRC2012_val_00041030.bin 224 224 +2664 ./prep_dataset/ILSVRC2012_val_00012416.bin 224 224 +2665 ./prep_dataset/ILSVRC2012_val_00005640.bin 224 224 +2666 ./prep_dataset/ILSVRC2012_val_00019335.bin 224 224 +2667 ./prep_dataset/ILSVRC2012_val_00005621.bin 224 224 +2668 ./prep_dataset/ILSVRC2012_val_00010983.bin 224 224 +2669 ./prep_dataset/ILSVRC2012_val_00007373.bin 224 224 +2670 ./prep_dataset/ILSVRC2012_val_00014826.bin 224 224 +2671 ./prep_dataset/ILSVRC2012_val_00038879.bin 224 224 +2672 ./prep_dataset/ILSVRC2012_val_00047124.bin 224 224 +2673 ./prep_dataset/ILSVRC2012_val_00047605.bin 224 224 +2674 ./prep_dataset/ILSVRC2012_val_00033833.bin 224 224 +2675 ./prep_dataset/ILSVRC2012_val_00049917.bin 224 224 +2676 ./prep_dataset/ILSVRC2012_val_00005022.bin 224 224 +2677 ./prep_dataset/ILSVRC2012_val_00047930.bin 224 224 +2678 ./prep_dataset/ILSVRC2012_val_00029685.bin 224 224 +2679 ./prep_dataset/ILSVRC2012_val_00020359.bin 224 224 +2680 ./prep_dataset/ILSVRC2012_val_00044026.bin 224 224 +2681 ./prep_dataset/ILSVRC2012_val_00015170.bin 224 224 +2682 ./prep_dataset/ILSVRC2012_val_00003299.bin 224 224 +2683 ./prep_dataset/ILSVRC2012_val_00043753.bin 224 224 +2684 ./prep_dataset/ILSVRC2012_val_00007928.bin 224 224 +2685 ./prep_dataset/ILSVRC2012_val_00048707.bin 224 224 +2686 ./prep_dataset/ILSVRC2012_val_00015423.bin 224 224 +2687 ./prep_dataset/ILSVRC2012_val_00019171.bin 224 224 +2688 ./prep_dataset/ILSVRC2012_val_00018678.bin 224 224 +2689 ./prep_dataset/ILSVRC2012_val_00036442.bin 224 224 +2690 ./prep_dataset/ILSVRC2012_val_00002825.bin 224 224 +2691 ./prep_dataset/ILSVRC2012_val_00023008.bin 224 224 +2692 ./prep_dataset/ILSVRC2012_val_00011527.bin 224 224 +2693 ./prep_dataset/ILSVRC2012_val_00004785.bin 224 224 +2694 ./prep_dataset/ILSVRC2012_val_00040143.bin 224 224 +2695 ./prep_dataset/ILSVRC2012_val_00018473.bin 224 224 +2696 ./prep_dataset/ILSVRC2012_val_00043141.bin 224 224 +2697 ./prep_dataset/ILSVRC2012_val_00048892.bin 224 224 +2698 ./prep_dataset/ILSVRC2012_val_00032514.bin 224 224 +2699 ./prep_dataset/ILSVRC2012_val_00017296.bin 224 224 +2700 ./prep_dataset/ILSVRC2012_val_00040996.bin 224 224 +2701 ./prep_dataset/ILSVRC2012_val_00012043.bin 224 224 +2702 ./prep_dataset/ILSVRC2012_val_00021704.bin 224 224 +2703 ./prep_dataset/ILSVRC2012_val_00040258.bin 224 224 +2704 ./prep_dataset/ILSVRC2012_val_00044609.bin 224 224 +2705 ./prep_dataset/ILSVRC2012_val_00005132.bin 224 224 +2706 ./prep_dataset/ILSVRC2012_val_00018788.bin 224 224 +2707 ./prep_dataset/ILSVRC2012_val_00034108.bin 224 224 +2708 ./prep_dataset/ILSVRC2012_val_00043827.bin 224 224 +2709 ./prep_dataset/ILSVRC2012_val_00040797.bin 224 224 +2710 ./prep_dataset/ILSVRC2012_val_00000279.bin 224 224 +2711 ./prep_dataset/ILSVRC2012_val_00047353.bin 224 224 +2712 ./prep_dataset/ILSVRC2012_val_00030331.bin 224 224 +2713 ./prep_dataset/ILSVRC2012_val_00039418.bin 224 224 +2714 ./prep_dataset/ILSVRC2012_val_00015745.bin 224 224 +2715 ./prep_dataset/ILSVRC2012_val_00008106.bin 224 224 +2716 ./prep_dataset/ILSVRC2012_val_00043014.bin 224 224 +2717 ./prep_dataset/ILSVRC2012_val_00010196.bin 224 224 +2718 ./prep_dataset/ILSVRC2012_val_00002099.bin 224 224 +2719 ./prep_dataset/ILSVRC2012_val_00013899.bin 224 224 +2720 ./prep_dataset/ILSVRC2012_val_00049189.bin 224 224 +2721 ./prep_dataset/ILSVRC2012_val_00041468.bin 224 224 +2722 ./prep_dataset/ILSVRC2012_val_00020525.bin 224 224 +2723 ./prep_dataset/ILSVRC2012_val_00035574.bin 224 224 +2724 ./prep_dataset/ILSVRC2012_val_00039915.bin 224 224 +2725 ./prep_dataset/ILSVRC2012_val_00035890.bin 224 224 +2726 ./prep_dataset/ILSVRC2012_val_00021888.bin 224 224 +2727 ./prep_dataset/ILSVRC2012_val_00007365.bin 224 224 +2728 ./prep_dataset/ILSVRC2012_val_00021635.bin 224 224 +2729 ./prep_dataset/ILSVRC2012_val_00006604.bin 224 224 +2730 ./prep_dataset/ILSVRC2012_val_00033805.bin 224 224 +2731 ./prep_dataset/ILSVRC2012_val_00046685.bin 224 224 +2732 ./prep_dataset/ILSVRC2012_val_00017648.bin 224 224 +2733 ./prep_dataset/ILSVRC2012_val_00004501.bin 224 224 +2734 ./prep_dataset/ILSVRC2012_val_00010757.bin 224 224 +2735 ./prep_dataset/ILSVRC2012_val_00022320.bin 224 224 +2736 ./prep_dataset/ILSVRC2012_val_00037991.bin 224 224 +2737 ./prep_dataset/ILSVRC2012_val_00019120.bin 224 224 +2738 ./prep_dataset/ILSVRC2012_val_00015175.bin 224 224 +2739 ./prep_dataset/ILSVRC2012_val_00043893.bin 224 224 +2740 ./prep_dataset/ILSVRC2012_val_00035541.bin 224 224 +2741 ./prep_dataset/ILSVRC2012_val_00011041.bin 224 224 +2742 ./prep_dataset/ILSVRC2012_val_00036290.bin 224 224 +2743 ./prep_dataset/ILSVRC2012_val_00014579.bin 224 224 +2744 ./prep_dataset/ILSVRC2012_val_00034780.bin 224 224 +2745 ./prep_dataset/ILSVRC2012_val_00025071.bin 224 224 +2746 ./prep_dataset/ILSVRC2012_val_00048169.bin 224 224 +2747 ./prep_dataset/ILSVRC2012_val_00024592.bin 224 224 +2748 ./prep_dataset/ILSVRC2012_val_00030084.bin 224 224 +2749 ./prep_dataset/ILSVRC2012_val_00011655.bin 224 224 +2750 ./prep_dataset/ILSVRC2012_val_00005871.bin 224 224 +2751 ./prep_dataset/ILSVRC2012_val_00019501.bin 224 224 +2752 ./prep_dataset/ILSVRC2012_val_00049919.bin 224 224 +2753 ./prep_dataset/ILSVRC2012_val_00032116.bin 224 224 +2754 ./prep_dataset/ILSVRC2012_val_00020322.bin 224 224 +2755 ./prep_dataset/ILSVRC2012_val_00008000.bin 224 224 +2756 ./prep_dataset/ILSVRC2012_val_00041050.bin 224 224 +2757 ./prep_dataset/ILSVRC2012_val_00019925.bin 224 224 +2758 ./prep_dataset/ILSVRC2012_val_00012083.bin 224 224 +2759 ./prep_dataset/ILSVRC2012_val_00014073.bin 224 224 +2760 ./prep_dataset/ILSVRC2012_val_00027454.bin 224 224 +2761 ./prep_dataset/ILSVRC2012_val_00028081.bin 224 224 +2762 ./prep_dataset/ILSVRC2012_val_00014588.bin 224 224 +2763 ./prep_dataset/ILSVRC2012_val_00036665.bin 224 224 +2764 ./prep_dataset/ILSVRC2012_val_00030587.bin 224 224 +2765 ./prep_dataset/ILSVRC2012_val_00047874.bin 224 224 +2766 ./prep_dataset/ILSVRC2012_val_00024751.bin 224 224 +2767 ./prep_dataset/ILSVRC2012_val_00025616.bin 224 224 +2768 ./prep_dataset/ILSVRC2012_val_00003676.bin 224 224 +2769 ./prep_dataset/ILSVRC2012_val_00033056.bin 224 224 +2770 ./prep_dataset/ILSVRC2012_val_00046536.bin 224 224 +2771 ./prep_dataset/ILSVRC2012_val_00008457.bin 224 224 +2772 ./prep_dataset/ILSVRC2012_val_00041596.bin 224 224 +2773 ./prep_dataset/ILSVRC2012_val_00048964.bin 224 224 +2774 ./prep_dataset/ILSVRC2012_val_00018795.bin 224 224 +2775 ./prep_dataset/ILSVRC2012_val_00003685.bin 224 224 +2776 ./prep_dataset/ILSVRC2012_val_00048877.bin 224 224 +2777 ./prep_dataset/ILSVRC2012_val_00011979.bin 224 224 +2778 ./prep_dataset/ILSVRC2012_val_00034084.bin 224 224 +2779 ./prep_dataset/ILSVRC2012_val_00022666.bin 224 224 +2780 ./prep_dataset/ILSVRC2012_val_00047233.bin 224 224 +2781 ./prep_dataset/ILSVRC2012_val_00026824.bin 224 224 +2782 ./prep_dataset/ILSVRC2012_val_00003595.bin 224 224 +2783 ./prep_dataset/ILSVRC2012_val_00019328.bin 224 224 +2784 ./prep_dataset/ILSVRC2012_val_00009908.bin 224 224 +2785 ./prep_dataset/ILSVRC2012_val_00008300.bin 224 224 +2786 ./prep_dataset/ILSVRC2012_val_00034560.bin 224 224 +2787 ./prep_dataset/ILSVRC2012_val_00029439.bin 224 224 +2788 ./prep_dataset/ILSVRC2012_val_00032469.bin 224 224 +2789 ./prep_dataset/ILSVRC2012_val_00019656.bin 224 224 +2790 ./prep_dataset/ILSVRC2012_val_00033910.bin 224 224 +2791 ./prep_dataset/ILSVRC2012_val_00000296.bin 224 224 +2792 ./prep_dataset/ILSVRC2012_val_00006641.bin 224 224 +2793 ./prep_dataset/ILSVRC2012_val_00008224.bin 224 224 +2794 ./prep_dataset/ILSVRC2012_val_00029933.bin 224 224 +2795 ./prep_dataset/ILSVRC2012_val_00046250.bin 224 224 +2796 ./prep_dataset/ILSVRC2012_val_00032450.bin 224 224 +2797 ./prep_dataset/ILSVRC2012_val_00014540.bin 224 224 +2798 ./prep_dataset/ILSVRC2012_val_00007524.bin 224 224 +2799 ./prep_dataset/ILSVRC2012_val_00024105.bin 224 224 +2800 ./prep_dataset/ILSVRC2012_val_00039477.bin 224 224 +2801 ./prep_dataset/ILSVRC2012_val_00006194.bin 224 224 +2802 ./prep_dataset/ILSVRC2012_val_00045326.bin 224 224 +2803 ./prep_dataset/ILSVRC2012_val_00024491.bin 224 224 +2804 ./prep_dataset/ILSVRC2012_val_00020804.bin 224 224 +2805 ./prep_dataset/ILSVRC2012_val_00045410.bin 224 224 +2806 ./prep_dataset/ILSVRC2012_val_00041445.bin 224 224 +2807 ./prep_dataset/ILSVRC2012_val_00026237.bin 224 224 +2808 ./prep_dataset/ILSVRC2012_val_00017053.bin 224 224 +2809 ./prep_dataset/ILSVRC2012_val_00045441.bin 224 224 +2810 ./prep_dataset/ILSVRC2012_val_00035990.bin 224 224 +2811 ./prep_dataset/ILSVRC2012_val_00013543.bin 224 224 +2812 ./prep_dataset/ILSVRC2012_val_00038444.bin 224 224 +2813 ./prep_dataset/ILSVRC2012_val_00027295.bin 224 224 +2814 ./prep_dataset/ILSVRC2012_val_00009901.bin 224 224 +2815 ./prep_dataset/ILSVRC2012_val_00019259.bin 224 224 +2816 ./prep_dataset/ILSVRC2012_val_00037302.bin 224 224 +2817 ./prep_dataset/ILSVRC2012_val_00020496.bin 224 224 +2818 ./prep_dataset/ILSVRC2012_val_00028045.bin 224 224 +2819 ./prep_dataset/ILSVRC2012_val_00010175.bin 224 224 +2820 ./prep_dataset/ILSVRC2012_val_00042916.bin 224 224 +2821 ./prep_dataset/ILSVRC2012_val_00003179.bin 224 224 +2822 ./prep_dataset/ILSVRC2012_val_00034000.bin 224 224 +2823 ./prep_dataset/ILSVRC2012_val_00020475.bin 224 224 +2824 ./prep_dataset/ILSVRC2012_val_00002380.bin 224 224 +2825 ./prep_dataset/ILSVRC2012_val_00008757.bin 224 224 +2826 ./prep_dataset/ILSVRC2012_val_00007130.bin 224 224 +2827 ./prep_dataset/ILSVRC2012_val_00044163.bin 224 224 +2828 ./prep_dataset/ILSVRC2012_val_00010946.bin 224 224 +2829 ./prep_dataset/ILSVRC2012_val_00047297.bin 224 224 +2830 ./prep_dataset/ILSVRC2012_val_00035638.bin 224 224 +2831 ./prep_dataset/ILSVRC2012_val_00001560.bin 224 224 +2832 ./prep_dataset/ILSVRC2012_val_00019568.bin 224 224 +2833 ./prep_dataset/ILSVRC2012_val_00011863.bin 224 224 +2834 ./prep_dataset/ILSVRC2012_val_00012599.bin 224 224 +2835 ./prep_dataset/ILSVRC2012_val_00018224.bin 224 224 +2836 ./prep_dataset/ILSVRC2012_val_00022684.bin 224 224 +2837 ./prep_dataset/ILSVRC2012_val_00034145.bin 224 224 +2838 ./prep_dataset/ILSVRC2012_val_00003777.bin 224 224 +2839 ./prep_dataset/ILSVRC2012_val_00015069.bin 224 224 +2840 ./prep_dataset/ILSVRC2012_val_00032997.bin 224 224 +2841 ./prep_dataset/ILSVRC2012_val_00008599.bin 224 224 +2842 ./prep_dataset/ILSVRC2012_val_00028884.bin 224 224 +2843 ./prep_dataset/ILSVRC2012_val_00032895.bin 224 224 +2844 ./prep_dataset/ILSVRC2012_val_00035212.bin 224 224 +2845 ./prep_dataset/ILSVRC2012_val_00016437.bin 224 224 +2846 ./prep_dataset/ILSVRC2012_val_00015507.bin 224 224 +2847 ./prep_dataset/ILSVRC2012_val_00046673.bin 224 224 +2848 ./prep_dataset/ILSVRC2012_val_00035115.bin 224 224 +2849 ./prep_dataset/ILSVRC2012_val_00042666.bin 224 224 +2850 ./prep_dataset/ILSVRC2012_val_00028205.bin 224 224 +2851 ./prep_dataset/ILSVRC2012_val_00032246.bin 224 224 +2852 ./prep_dataset/ILSVRC2012_val_00032232.bin 224 224 +2853 ./prep_dataset/ILSVRC2012_val_00037200.bin 224 224 +2854 ./prep_dataset/ILSVRC2012_val_00026931.bin 224 224 +2855 ./prep_dataset/ILSVRC2012_val_00015031.bin 224 224 +2856 ./prep_dataset/ILSVRC2012_val_00014333.bin 224 224 +2857 ./prep_dataset/ILSVRC2012_val_00022359.bin 224 224 +2858 ./prep_dataset/ILSVRC2012_val_00049623.bin 224 224 +2859 ./prep_dataset/ILSVRC2012_val_00023085.bin 224 224 +2860 ./prep_dataset/ILSVRC2012_val_00049454.bin 224 224 +2861 ./prep_dataset/ILSVRC2012_val_00043995.bin 224 224 +2862 ./prep_dataset/ILSVRC2012_val_00008706.bin 224 224 +2863 ./prep_dataset/ILSVRC2012_val_00013455.bin 224 224 +2864 ./prep_dataset/ILSVRC2012_val_00015941.bin 224 224 +2865 ./prep_dataset/ILSVRC2012_val_00009291.bin 224 224 +2866 ./prep_dataset/ILSVRC2012_val_00031617.bin 224 224 +2867 ./prep_dataset/ILSVRC2012_val_00003368.bin 224 224 +2868 ./prep_dataset/ILSVRC2012_val_00045612.bin 224 224 +2869 ./prep_dataset/ILSVRC2012_val_00045986.bin 224 224 +2870 ./prep_dataset/ILSVRC2012_val_00036066.bin 224 224 +2871 ./prep_dataset/ILSVRC2012_val_00046985.bin 224 224 +2872 ./prep_dataset/ILSVRC2012_val_00007368.bin 224 224 +2873 ./prep_dataset/ILSVRC2012_val_00002788.bin 224 224 +2874 ./prep_dataset/ILSVRC2012_val_00032440.bin 224 224 +2875 ./prep_dataset/ILSVRC2012_val_00046983.bin 224 224 +2876 ./prep_dataset/ILSVRC2012_val_00043641.bin 224 224 +2877 ./prep_dataset/ILSVRC2012_val_00012089.bin 224 224 +2878 ./prep_dataset/ILSVRC2012_val_00017521.bin 224 224 +2879 ./prep_dataset/ILSVRC2012_val_00024732.bin 224 224 +2880 ./prep_dataset/ILSVRC2012_val_00008893.bin 224 224 +2881 ./prep_dataset/ILSVRC2012_val_00038810.bin 224 224 +2882 ./prep_dataset/ILSVRC2012_val_00024764.bin 224 224 +2883 ./prep_dataset/ILSVRC2012_val_00040204.bin 224 224 +2884 ./prep_dataset/ILSVRC2012_val_00044112.bin 224 224 +2885 ./prep_dataset/ILSVRC2012_val_00021268.bin 224 224 +2886 ./prep_dataset/ILSVRC2012_val_00041998.bin 224 224 +2887 ./prep_dataset/ILSVRC2012_val_00009401.bin 224 224 +2888 ./prep_dataset/ILSVRC2012_val_00031724.bin 224 224 +2889 ./prep_dataset/ILSVRC2012_val_00018781.bin 224 224 +2890 ./prep_dataset/ILSVRC2012_val_00012884.bin 224 224 +2891 ./prep_dataset/ILSVRC2012_val_00030634.bin 224 224 +2892 ./prep_dataset/ILSVRC2012_val_00046228.bin 224 224 +2893 ./prep_dataset/ILSVRC2012_val_00036550.bin 224 224 +2894 ./prep_dataset/ILSVRC2012_val_00002017.bin 224 224 +2895 ./prep_dataset/ILSVRC2012_val_00038147.bin 224 224 +2896 ./prep_dataset/ILSVRC2012_val_00018798.bin 224 224 +2897 ./prep_dataset/ILSVRC2012_val_00049014.bin 224 224 +2898 ./prep_dataset/ILSVRC2012_val_00006212.bin 224 224 +2899 ./prep_dataset/ILSVRC2012_val_00029982.bin 224 224 +2900 ./prep_dataset/ILSVRC2012_val_00037161.bin 224 224 +2901 ./prep_dataset/ILSVRC2012_val_00008501.bin 224 224 +2902 ./prep_dataset/ILSVRC2012_val_00026761.bin 224 224 +2903 ./prep_dataset/ILSVRC2012_val_00043339.bin 224 224 +2904 ./prep_dataset/ILSVRC2012_val_00015000.bin 224 224 +2905 ./prep_dataset/ILSVRC2012_val_00037809.bin 224 224 +2906 ./prep_dataset/ILSVRC2012_val_00007531.bin 224 224 +2907 ./prep_dataset/ILSVRC2012_val_00021845.bin 224 224 +2908 ./prep_dataset/ILSVRC2012_val_00041626.bin 224 224 +2909 ./prep_dataset/ILSVRC2012_val_00011084.bin 224 224 +2910 ./prep_dataset/ILSVRC2012_val_00010307.bin 224 224 +2911 ./prep_dataset/ILSVRC2012_val_00034193.bin 224 224 +2912 ./prep_dataset/ILSVRC2012_val_00008676.bin 224 224 +2913 ./prep_dataset/ILSVRC2012_val_00031111.bin 224 224 +2914 ./prep_dataset/ILSVRC2012_val_00010731.bin 224 224 +2915 ./prep_dataset/ILSVRC2012_val_00003830.bin 224 224 +2916 ./prep_dataset/ILSVRC2012_val_00029717.bin 224 224 +2917 ./prep_dataset/ILSVRC2012_val_00023148.bin 224 224 +2918 ./prep_dataset/ILSVRC2012_val_00035274.bin 224 224 +2919 ./prep_dataset/ILSVRC2012_val_00003130.bin 224 224 +2920 ./prep_dataset/ILSVRC2012_val_00024167.bin 224 224 +2921 ./prep_dataset/ILSVRC2012_val_00018933.bin 224 224 +2922 ./prep_dataset/ILSVRC2012_val_00005251.bin 224 224 +2923 ./prep_dataset/ILSVRC2012_val_00009556.bin 224 224 +2924 ./prep_dataset/ILSVRC2012_val_00031108.bin 224 224 +2925 ./prep_dataset/ILSVRC2012_val_00000497.bin 224 224 +2926 ./prep_dataset/ILSVRC2012_val_00037149.bin 224 224 +2927 ./prep_dataset/ILSVRC2012_val_00028883.bin 224 224 +2928 ./prep_dataset/ILSVRC2012_val_00000550.bin 224 224 +2929 ./prep_dataset/ILSVRC2012_val_00027065.bin 224 224 +2930 ./prep_dataset/ILSVRC2012_val_00034519.bin 224 224 +2931 ./prep_dataset/ILSVRC2012_val_00041012.bin 224 224 +2932 ./prep_dataset/ILSVRC2012_val_00017925.bin 224 224 +2933 ./prep_dataset/ILSVRC2012_val_00033164.bin 224 224 +2934 ./prep_dataset/ILSVRC2012_val_00018756.bin 224 224 +2935 ./prep_dataset/ILSVRC2012_val_00004962.bin 224 224 +2936 ./prep_dataset/ILSVRC2012_val_00019974.bin 224 224 +2937 ./prep_dataset/ILSVRC2012_val_00034522.bin 224 224 +2938 ./prep_dataset/ILSVRC2012_val_00049429.bin 224 224 +2939 ./prep_dataset/ILSVRC2012_val_00043993.bin 224 224 +2940 ./prep_dataset/ILSVRC2012_val_00004833.bin 224 224 +2941 ./prep_dataset/ILSVRC2012_val_00035942.bin 224 224 +2942 ./prep_dataset/ILSVRC2012_val_00040962.bin 224 224 +2943 ./prep_dataset/ILSVRC2012_val_00016911.bin 224 224 +2944 ./prep_dataset/ILSVRC2012_val_00043837.bin 224 224 +2945 ./prep_dataset/ILSVRC2012_val_00024600.bin 224 224 +2946 ./prep_dataset/ILSVRC2012_val_00025416.bin 224 224 +2947 ./prep_dataset/ILSVRC2012_val_00014263.bin 224 224 +2948 ./prep_dataset/ILSVRC2012_val_00010015.bin 224 224 +2949 ./prep_dataset/ILSVRC2012_val_00041384.bin 224 224 +2950 ./prep_dataset/ILSVRC2012_val_00012394.bin 224 224 +2951 ./prep_dataset/ILSVRC2012_val_00015632.bin 224 224 +2952 ./prep_dataset/ILSVRC2012_val_00001851.bin 224 224 +2953 ./prep_dataset/ILSVRC2012_val_00017717.bin 224 224 +2954 ./prep_dataset/ILSVRC2012_val_00044397.bin 224 224 +2955 ./prep_dataset/ILSVRC2012_val_00044844.bin 224 224 +2956 ./prep_dataset/ILSVRC2012_val_00004724.bin 224 224 +2957 ./prep_dataset/ILSVRC2012_val_00031176.bin 224 224 +2958 ./prep_dataset/ILSVRC2012_val_00033621.bin 224 224 +2959 ./prep_dataset/ILSVRC2012_val_00009160.bin 224 224 +2960 ./prep_dataset/ILSVRC2012_val_00004610.bin 224 224 +2961 ./prep_dataset/ILSVRC2012_val_00019618.bin 224 224 +2962 ./prep_dataset/ILSVRC2012_val_00038295.bin 224 224 +2963 ./prep_dataset/ILSVRC2012_val_00027081.bin 224 224 +2964 ./prep_dataset/ILSVRC2012_val_00026277.bin 224 224 +2965 ./prep_dataset/ILSVRC2012_val_00001691.bin 224 224 +2966 ./prep_dataset/ILSVRC2012_val_00036865.bin 224 224 +2967 ./prep_dataset/ILSVRC2012_val_00014817.bin 224 224 +2968 ./prep_dataset/ILSVRC2012_val_00016242.bin 224 224 +2969 ./prep_dataset/ILSVRC2012_val_00020510.bin 224 224 +2970 ./prep_dataset/ILSVRC2012_val_00009106.bin 224 224 +2971 ./prep_dataset/ILSVRC2012_val_00027119.bin 224 224 +2972 ./prep_dataset/ILSVRC2012_val_00039404.bin 224 224 +2973 ./prep_dataset/ILSVRC2012_val_00048395.bin 224 224 +2974 ./prep_dataset/ILSVRC2012_val_00032670.bin 224 224 +2975 ./prep_dataset/ILSVRC2012_val_00007630.bin 224 224 +2976 ./prep_dataset/ILSVRC2012_val_00013119.bin 224 224 +2977 ./prep_dataset/ILSVRC2012_val_00028048.bin 224 224 +2978 ./prep_dataset/ILSVRC2012_val_00042697.bin 224 224 +2979 ./prep_dataset/ILSVRC2012_val_00022776.bin 224 224 +2980 ./prep_dataset/ILSVRC2012_val_00048990.bin 224 224 +2981 ./prep_dataset/ILSVRC2012_val_00004362.bin 224 224 +2982 ./prep_dataset/ILSVRC2012_val_00038577.bin 224 224 +2983 ./prep_dataset/ILSVRC2012_val_00005974.bin 224 224 +2984 ./prep_dataset/ILSVRC2012_val_00043546.bin 224 224 +2985 ./prep_dataset/ILSVRC2012_val_00034507.bin 224 224 +2986 ./prep_dataset/ILSVRC2012_val_00010625.bin 224 224 +2987 ./prep_dataset/ILSVRC2012_val_00045933.bin 224 224 +2988 ./prep_dataset/ILSVRC2012_val_00003807.bin 224 224 +2989 ./prep_dataset/ILSVRC2012_val_00025494.bin 224 224 +2990 ./prep_dataset/ILSVRC2012_val_00041623.bin 224 224 +2991 ./prep_dataset/ILSVRC2012_val_00049507.bin 224 224 +2992 ./prep_dataset/ILSVRC2012_val_00045129.bin 224 224 +2993 ./prep_dataset/ILSVRC2012_val_00025742.bin 224 224 +2994 ./prep_dataset/ILSVRC2012_val_00040613.bin 224 224 +2995 ./prep_dataset/ILSVRC2012_val_00016326.bin 224 224 +2996 ./prep_dataset/ILSVRC2012_val_00001989.bin 224 224 +2997 ./prep_dataset/ILSVRC2012_val_00038736.bin 224 224 +2998 ./prep_dataset/ILSVRC2012_val_00006394.bin 224 224 +2999 ./prep_dataset/ILSVRC2012_val_00024579.bin 224 224 +3000 ./prep_dataset/ILSVRC2012_val_00017699.bin 224 224 +3001 ./prep_dataset/ILSVRC2012_val_00039219.bin 224 224 +3002 ./prep_dataset/ILSVRC2012_val_00035310.bin 224 224 +3003 ./prep_dataset/ILSVRC2012_val_00043485.bin 224 224 +3004 ./prep_dataset/ILSVRC2012_val_00008724.bin 224 224 +3005 ./prep_dataset/ILSVRC2012_val_00009389.bin 224 224 +3006 ./prep_dataset/ILSVRC2012_val_00029546.bin 224 224 +3007 ./prep_dataset/ILSVRC2012_val_00047931.bin 224 224 +3008 ./prep_dataset/ILSVRC2012_val_00021755.bin 224 224 +3009 ./prep_dataset/ILSVRC2012_val_00047548.bin 224 224 +3010 ./prep_dataset/ILSVRC2012_val_00049607.bin 224 224 +3011 ./prep_dataset/ILSVRC2012_val_00018911.bin 224 224 +3012 ./prep_dataset/ILSVRC2012_val_00005384.bin 224 224 +3013 ./prep_dataset/ILSVRC2012_val_00018482.bin 224 224 +3014 ./prep_dataset/ILSVRC2012_val_00018214.bin 224 224 +3015 ./prep_dataset/ILSVRC2012_val_00042662.bin 224 224 +3016 ./prep_dataset/ILSVRC2012_val_00049909.bin 224 224 +3017 ./prep_dataset/ILSVRC2012_val_00025890.bin 224 224 +3018 ./prep_dataset/ILSVRC2012_val_00025926.bin 224 224 +3019 ./prep_dataset/ILSVRC2012_val_00010877.bin 224 224 +3020 ./prep_dataset/ILSVRC2012_val_00024018.bin 224 224 +3021 ./prep_dataset/ILSVRC2012_val_00014354.bin 224 224 +3022 ./prep_dataset/ILSVRC2012_val_00026099.bin 224 224 +3023 ./prep_dataset/ILSVRC2012_val_00017176.bin 224 224 +3024 ./prep_dataset/ILSVRC2012_val_00040979.bin 224 224 +3025 ./prep_dataset/ILSVRC2012_val_00017741.bin 224 224 +3026 ./prep_dataset/ILSVRC2012_val_00017557.bin 224 224 +3027 ./prep_dataset/ILSVRC2012_val_00031836.bin 224 224 +3028 ./prep_dataset/ILSVRC2012_val_00028359.bin 224 224 +3029 ./prep_dataset/ILSVRC2012_val_00022064.bin 224 224 +3030 ./prep_dataset/ILSVRC2012_val_00027212.bin 224 224 +3031 ./prep_dataset/ILSVRC2012_val_00047290.bin 224 224 +3032 ./prep_dataset/ILSVRC2012_val_00000778.bin 224 224 +3033 ./prep_dataset/ILSVRC2012_val_00031326.bin 224 224 +3034 ./prep_dataset/ILSVRC2012_val_00016268.bin 224 224 +3035 ./prep_dataset/ILSVRC2012_val_00006538.bin 224 224 +3036 ./prep_dataset/ILSVRC2012_val_00031415.bin 224 224 +3037 ./prep_dataset/ILSVRC2012_val_00002193.bin 224 224 +3038 ./prep_dataset/ILSVRC2012_val_00014736.bin 224 224 +3039 ./prep_dataset/ILSVRC2012_val_00006760.bin 224 224 +3040 ./prep_dataset/ILSVRC2012_val_00015867.bin 224 224 +3041 ./prep_dataset/ILSVRC2012_val_00005712.bin 224 224 +3042 ./prep_dataset/ILSVRC2012_val_00043676.bin 224 224 +3043 ./prep_dataset/ILSVRC2012_val_00020676.bin 224 224 +3044 ./prep_dataset/ILSVRC2012_val_00046498.bin 224 224 +3045 ./prep_dataset/ILSVRC2012_val_00029812.bin 224 224 +3046 ./prep_dataset/ILSVRC2012_val_00001934.bin 224 224 +3047 ./prep_dataset/ILSVRC2012_val_00038612.bin 224 224 +3048 ./prep_dataset/ILSVRC2012_val_00021439.bin 224 224 +3049 ./prep_dataset/ILSVRC2012_val_00037597.bin 224 224 +3050 ./prep_dataset/ILSVRC2012_val_00007629.bin 224 224 +3051 ./prep_dataset/ILSVRC2012_val_00026759.bin 224 224 +3052 ./prep_dataset/ILSVRC2012_val_00031130.bin 224 224 +3053 ./prep_dataset/ILSVRC2012_val_00047153.bin 224 224 +3054 ./prep_dataset/ILSVRC2012_val_00020023.bin 224 224 +3055 ./prep_dataset/ILSVRC2012_val_00018851.bin 224 224 +3056 ./prep_dataset/ILSVRC2012_val_00046338.bin 224 224 +3057 ./prep_dataset/ILSVRC2012_val_00007038.bin 224 224 +3058 ./prep_dataset/ILSVRC2012_val_00007848.bin 224 224 +3059 ./prep_dataset/ILSVRC2012_val_00033315.bin 224 224 +3060 ./prep_dataset/ILSVRC2012_val_00047494.bin 224 224 +3061 ./prep_dataset/ILSVRC2012_val_00021004.bin 224 224 +3062 ./prep_dataset/ILSVRC2012_val_00005128.bin 224 224 +3063 ./prep_dataset/ILSVRC2012_val_00036793.bin 224 224 +3064 ./prep_dataset/ILSVRC2012_val_00013757.bin 224 224 +3065 ./prep_dataset/ILSVRC2012_val_00018466.bin 224 224 +3066 ./prep_dataset/ILSVRC2012_val_00007654.bin 224 224 +3067 ./prep_dataset/ILSVRC2012_val_00010060.bin 224 224 +3068 ./prep_dataset/ILSVRC2012_val_00040160.bin 224 224 +3069 ./prep_dataset/ILSVRC2012_val_00040485.bin 224 224 +3070 ./prep_dataset/ILSVRC2012_val_00011783.bin 224 224 +3071 ./prep_dataset/ILSVRC2012_val_00039019.bin 224 224 +3072 ./prep_dataset/ILSVRC2012_val_00028323.bin 224 224 +3073 ./prep_dataset/ILSVRC2012_val_00022936.bin 224 224 +3074 ./prep_dataset/ILSVRC2012_val_00015912.bin 224 224 +3075 ./prep_dataset/ILSVRC2012_val_00009547.bin 224 224 +3076 ./prep_dataset/ILSVRC2012_val_00009032.bin 224 224 +3077 ./prep_dataset/ILSVRC2012_val_00041382.bin 224 224 +3078 ./prep_dataset/ILSVRC2012_val_00022979.bin 224 224 +3079 ./prep_dataset/ILSVRC2012_val_00007162.bin 224 224 +3080 ./prep_dataset/ILSVRC2012_val_00022111.bin 224 224 +3081 ./prep_dataset/ILSVRC2012_val_00009557.bin 224 224 +3082 ./prep_dataset/ILSVRC2012_val_00035686.bin 224 224 +3083 ./prep_dataset/ILSVRC2012_val_00021605.bin 224 224 +3084 ./prep_dataset/ILSVRC2012_val_00030877.bin 224 224 +3085 ./prep_dataset/ILSVRC2012_val_00011423.bin 224 224 +3086 ./prep_dataset/ILSVRC2012_val_00031765.bin 224 224 +3087 ./prep_dataset/ILSVRC2012_val_00016452.bin 224 224 +3088 ./prep_dataset/ILSVRC2012_val_00011426.bin 224 224 +3089 ./prep_dataset/ILSVRC2012_val_00020332.bin 224 224 +3090 ./prep_dataset/ILSVRC2012_val_00000423.bin 224 224 +3091 ./prep_dataset/ILSVRC2012_val_00045984.bin 224 224 +3092 ./prep_dataset/ILSVRC2012_val_00020031.bin 224 224 +3093 ./prep_dataset/ILSVRC2012_val_00031909.bin 224 224 +3094 ./prep_dataset/ILSVRC2012_val_00010280.bin 224 224 +3095 ./prep_dataset/ILSVRC2012_val_00029384.bin 224 224 +3096 ./prep_dataset/ILSVRC2012_val_00045882.bin 224 224 +3097 ./prep_dataset/ILSVRC2012_val_00019267.bin 224 224 +3098 ./prep_dataset/ILSVRC2012_val_00048077.bin 224 224 +3099 ./prep_dataset/ILSVRC2012_val_00011276.bin 224 224 +3100 ./prep_dataset/ILSVRC2012_val_00016516.bin 224 224 +3101 ./prep_dataset/ILSVRC2012_val_00028164.bin 224 224 +3102 ./prep_dataset/ILSVRC2012_val_00012032.bin 224 224 +3103 ./prep_dataset/ILSVRC2012_val_00010553.bin 224 224 +3104 ./prep_dataset/ILSVRC2012_val_00035839.bin 224 224 +3105 ./prep_dataset/ILSVRC2012_val_00014944.bin 224 224 +3106 ./prep_dataset/ILSVRC2012_val_00013304.bin 224 224 +3107 ./prep_dataset/ILSVRC2012_val_00020633.bin 224 224 +3108 ./prep_dataset/ILSVRC2012_val_00009671.bin 224 224 +3109 ./prep_dataset/ILSVRC2012_val_00043750.bin 224 224 +3110 ./prep_dataset/ILSVRC2012_val_00010803.bin 224 224 +3111 ./prep_dataset/ILSVRC2012_val_00002520.bin 224 224 +3112 ./prep_dataset/ILSVRC2012_val_00030057.bin 224 224 +3113 ./prep_dataset/ILSVRC2012_val_00029186.bin 224 224 +3114 ./prep_dataset/ILSVRC2012_val_00044474.bin 224 224 +3115 ./prep_dataset/ILSVRC2012_val_00029100.bin 224 224 +3116 ./prep_dataset/ILSVRC2012_val_00049787.bin 224 224 +3117 ./prep_dataset/ILSVRC2012_val_00000199.bin 224 224 +3118 ./prep_dataset/ILSVRC2012_val_00025252.bin 224 224 +3119 ./prep_dataset/ILSVRC2012_val_00006269.bin 224 224 +3120 ./prep_dataset/ILSVRC2012_val_00047395.bin 224 224 +3121 ./prep_dataset/ILSVRC2012_val_00030790.bin 224 224 +3122 ./prep_dataset/ILSVRC2012_val_00011194.bin 224 224 +3123 ./prep_dataset/ILSVRC2012_val_00049883.bin 224 224 +3124 ./prep_dataset/ILSVRC2012_val_00035472.bin 224 224 +3125 ./prep_dataset/ILSVRC2012_val_00013028.bin 224 224 +3126 ./prep_dataset/ILSVRC2012_val_00040122.bin 224 224 +3127 ./prep_dataset/ILSVRC2012_val_00046450.bin 224 224 +3128 ./prep_dataset/ILSVRC2012_val_00043331.bin 224 224 +3129 ./prep_dataset/ILSVRC2012_val_00024750.bin 224 224 +3130 ./prep_dataset/ILSVRC2012_val_00049608.bin 224 224 +3131 ./prep_dataset/ILSVRC2012_val_00045837.bin 224 224 +3132 ./prep_dataset/ILSVRC2012_val_00014880.bin 224 224 +3133 ./prep_dataset/ILSVRC2012_val_00006807.bin 224 224 +3134 ./prep_dataset/ILSVRC2012_val_00024462.bin 224 224 +3135 ./prep_dataset/ILSVRC2012_val_00048291.bin 224 224 +3136 ./prep_dataset/ILSVRC2012_val_00046000.bin 224 224 +3137 ./prep_dataset/ILSVRC2012_val_00036430.bin 224 224 +3138 ./prep_dataset/ILSVRC2012_val_00037781.bin 224 224 +3139 ./prep_dataset/ILSVRC2012_val_00020339.bin 224 224 +3140 ./prep_dataset/ILSVRC2012_val_00030688.bin 224 224 +3141 ./prep_dataset/ILSVRC2012_val_00041312.bin 224 224 +3142 ./prep_dataset/ILSVRC2012_val_00035956.bin 224 224 +3143 ./prep_dataset/ILSVRC2012_val_00015804.bin 224 224 +3144 ./prep_dataset/ILSVRC2012_val_00043189.bin 224 224 +3145 ./prep_dataset/ILSVRC2012_val_00018131.bin 224 224 +3146 ./prep_dataset/ILSVRC2012_val_00005443.bin 224 224 +3147 ./prep_dataset/ILSVRC2012_val_00006472.bin 224 224 +3148 ./prep_dataset/ILSVRC2012_val_00007695.bin 224 224 +3149 ./prep_dataset/ILSVRC2012_val_00028085.bin 224 224 +3150 ./prep_dataset/ILSVRC2012_val_00032551.bin 224 224 +3151 ./prep_dataset/ILSVRC2012_val_00023367.bin 224 224 +3152 ./prep_dataset/ILSVRC2012_val_00015925.bin 224 224 +3153 ./prep_dataset/ILSVRC2012_val_00005214.bin 224 224 +3154 ./prep_dataset/ILSVRC2012_val_00025123.bin 224 224 +3155 ./prep_dataset/ILSVRC2012_val_00023224.bin 224 224 +3156 ./prep_dataset/ILSVRC2012_val_00042741.bin 224 224 +3157 ./prep_dataset/ILSVRC2012_val_00042779.bin 224 224 +3158 ./prep_dataset/ILSVRC2012_val_00035844.bin 224 224 +3159 ./prep_dataset/ILSVRC2012_val_00047944.bin 224 224 +3160 ./prep_dataset/ILSVRC2012_val_00040578.bin 224 224 +3161 ./prep_dataset/ILSVRC2012_val_00010617.bin 224 224 +3162 ./prep_dataset/ILSVRC2012_val_00008373.bin 224 224 +3163 ./prep_dataset/ILSVRC2012_val_00020664.bin 224 224 +3164 ./prep_dataset/ILSVRC2012_val_00017279.bin 224 224 +3165 ./prep_dataset/ILSVRC2012_val_00010654.bin 224 224 +3166 ./prep_dataset/ILSVRC2012_val_00004070.bin 224 224 +3167 ./prep_dataset/ILSVRC2012_val_00014675.bin 224 224 +3168 ./prep_dataset/ILSVRC2012_val_00030383.bin 224 224 +3169 ./prep_dataset/ILSVRC2012_val_00023845.bin 224 224 +3170 ./prep_dataset/ILSVRC2012_val_00027396.bin 224 224 +3171 ./prep_dataset/ILSVRC2012_val_00034988.bin 224 224 +3172 ./prep_dataset/ILSVRC2012_val_00026539.bin 224 224 +3173 ./prep_dataset/ILSVRC2012_val_00012571.bin 224 224 +3174 ./prep_dataset/ILSVRC2012_val_00000658.bin 224 224 +3175 ./prep_dataset/ILSVRC2012_val_00048978.bin 224 224 +3176 ./prep_dataset/ILSVRC2012_val_00003974.bin 224 224 +3177 ./prep_dataset/ILSVRC2012_val_00028390.bin 224 224 +3178 ./prep_dataset/ILSVRC2012_val_00043687.bin 224 224 +3179 ./prep_dataset/ILSVRC2012_val_00016877.bin 224 224 +3180 ./prep_dataset/ILSVRC2012_val_00024035.bin 224 224 +3181 ./prep_dataset/ILSVRC2012_val_00022128.bin 224 224 +3182 ./prep_dataset/ILSVRC2012_val_00036477.bin 224 224 +3183 ./prep_dataset/ILSVRC2012_val_00048198.bin 224 224 +3184 ./prep_dataset/ILSVRC2012_val_00020591.bin 224 224 +3185 ./prep_dataset/ILSVRC2012_val_00046968.bin 224 224 +3186 ./prep_dataset/ILSVRC2012_val_00005533.bin 224 224 +3187 ./prep_dataset/ILSVRC2012_val_00019329.bin 224 224 +3188 ./prep_dataset/ILSVRC2012_val_00008832.bin 224 224 +3189 ./prep_dataset/ILSVRC2012_val_00029904.bin 224 224 +3190 ./prep_dataset/ILSVRC2012_val_00019285.bin 224 224 +3191 ./prep_dataset/ILSVRC2012_val_00049656.bin 224 224 +3192 ./prep_dataset/ILSVRC2012_val_00017330.bin 224 224 +3193 ./prep_dataset/ILSVRC2012_val_00007352.bin 224 224 +3194 ./prep_dataset/ILSVRC2012_val_00019398.bin 224 224 +3195 ./prep_dataset/ILSVRC2012_val_00039313.bin 224 224 +3196 ./prep_dataset/ILSVRC2012_val_00037197.bin 224 224 +3197 ./prep_dataset/ILSVRC2012_val_00047928.bin 224 224 +3198 ./prep_dataset/ILSVRC2012_val_00023940.bin 224 224 +3199 ./prep_dataset/ILSVRC2012_val_00022663.bin 224 224 +3200 ./prep_dataset/ILSVRC2012_val_00045722.bin 224 224 +3201 ./prep_dataset/ILSVRC2012_val_00028321.bin 224 224 +3202 ./prep_dataset/ILSVRC2012_val_00029094.bin 224 224 +3203 ./prep_dataset/ILSVRC2012_val_00021348.bin 224 224 +3204 ./prep_dataset/ILSVRC2012_val_00026273.bin 224 224 +3205 ./prep_dataset/ILSVRC2012_val_00014207.bin 224 224 +3206 ./prep_dataset/ILSVRC2012_val_00048180.bin 224 224 +3207 ./prep_dataset/ILSVRC2012_val_00021435.bin 224 224 +3208 ./prep_dataset/ILSVRC2012_val_00015914.bin 224 224 +3209 ./prep_dataset/ILSVRC2012_val_00000392.bin 224 224 +3210 ./prep_dataset/ILSVRC2012_val_00006283.bin 224 224 +3211 ./prep_dataset/ILSVRC2012_val_00006852.bin 224 224 +3212 ./prep_dataset/ILSVRC2012_val_00026888.bin 224 224 +3213 ./prep_dataset/ILSVRC2012_val_00008551.bin 224 224 +3214 ./prep_dataset/ILSVRC2012_val_00047629.bin 224 224 +3215 ./prep_dataset/ILSVRC2012_val_00001973.bin 224 224 +3216 ./prep_dataset/ILSVRC2012_val_00009297.bin 224 224 +3217 ./prep_dataset/ILSVRC2012_val_00016517.bin 224 224 +3218 ./prep_dataset/ILSVRC2012_val_00013504.bin 224 224 +3219 ./prep_dataset/ILSVRC2012_val_00041385.bin 224 224 +3220 ./prep_dataset/ILSVRC2012_val_00012978.bin 224 224 +3221 ./prep_dataset/ILSVRC2012_val_00015644.bin 224 224 +3222 ./prep_dataset/ILSVRC2012_val_00020966.bin 224 224 +3223 ./prep_dataset/ILSVRC2012_val_00035244.bin 224 224 +3224 ./prep_dataset/ILSVRC2012_val_00039644.bin 224 224 +3225 ./prep_dataset/ILSVRC2012_val_00005761.bin 224 224 +3226 ./prep_dataset/ILSVRC2012_val_00030609.bin 224 224 +3227 ./prep_dataset/ILSVRC2012_val_00027631.bin 224 224 +3228 ./prep_dataset/ILSVRC2012_val_00019686.bin 224 224 +3229 ./prep_dataset/ILSVRC2012_val_00016481.bin 224 224 +3230 ./prep_dataset/ILSVRC2012_val_00007759.bin 224 224 +3231 ./prep_dataset/ILSVRC2012_val_00030429.bin 224 224 +3232 ./prep_dataset/ILSVRC2012_val_00039787.bin 224 224 +3233 ./prep_dataset/ILSVRC2012_val_00022586.bin 224 224 +3234 ./prep_dataset/ILSVRC2012_val_00043264.bin 224 224 +3235 ./prep_dataset/ILSVRC2012_val_00049836.bin 224 224 +3236 ./prep_dataset/ILSVRC2012_val_00007257.bin 224 224 +3237 ./prep_dataset/ILSVRC2012_val_00037329.bin 224 224 +3238 ./prep_dataset/ILSVRC2012_val_00030859.bin 224 224 +3239 ./prep_dataset/ILSVRC2012_val_00002848.bin 224 224 +3240 ./prep_dataset/ILSVRC2012_val_00036046.bin 224 224 +3241 ./prep_dataset/ILSVRC2012_val_00042270.bin 224 224 +3242 ./prep_dataset/ILSVRC2012_val_00011667.bin 224 224 +3243 ./prep_dataset/ILSVRC2012_val_00040905.bin 224 224 +3244 ./prep_dataset/ILSVRC2012_val_00048704.bin 224 224 +3245 ./prep_dataset/ILSVRC2012_val_00001981.bin 224 224 +3246 ./prep_dataset/ILSVRC2012_val_00021399.bin 224 224 +3247 ./prep_dataset/ILSVRC2012_val_00036834.bin 224 224 +3248 ./prep_dataset/ILSVRC2012_val_00026508.bin 224 224 +3249 ./prep_dataset/ILSVRC2012_val_00015584.bin 224 224 +3250 ./prep_dataset/ILSVRC2012_val_00010181.bin 224 224 +3251 ./prep_dataset/ILSVRC2012_val_00042185.bin 224 224 +3252 ./prep_dataset/ILSVRC2012_val_00037667.bin 224 224 +3253 ./prep_dataset/ILSVRC2012_val_00018392.bin 224 224 +3254 ./prep_dataset/ILSVRC2012_val_00017287.bin 224 224 +3255 ./prep_dataset/ILSVRC2012_val_00024883.bin 224 224 +3256 ./prep_dataset/ILSVRC2012_val_00049359.bin 224 224 +3257 ./prep_dataset/ILSVRC2012_val_00022408.bin 224 224 +3258 ./prep_dataset/ILSVRC2012_val_00048142.bin 224 224 +3259 ./prep_dataset/ILSVRC2012_val_00046253.bin 224 224 +3260 ./prep_dataset/ILSVRC2012_val_00031431.bin 224 224 +3261 ./prep_dataset/ILSVRC2012_val_00047363.bin 224 224 +3262 ./prep_dataset/ILSVRC2012_val_00028154.bin 224 224 +3263 ./prep_dataset/ILSVRC2012_val_00046101.bin 224 224 +3264 ./prep_dataset/ILSVRC2012_val_00007142.bin 224 224 +3265 ./prep_dataset/ILSVRC2012_val_00043034.bin 224 224 +3266 ./prep_dataset/ILSVRC2012_val_00025190.bin 224 224 +3267 ./prep_dataset/ILSVRC2012_val_00039733.bin 224 224 +3268 ./prep_dataset/ILSVRC2012_val_00037561.bin 224 224 +3269 ./prep_dataset/ILSVRC2012_val_00030874.bin 224 224 +3270 ./prep_dataset/ILSVRC2012_val_00035171.bin 224 224 +3271 ./prep_dataset/ILSVRC2012_val_00011649.bin 224 224 +3272 ./prep_dataset/ILSVRC2012_val_00006556.bin 224 224 +3273 ./prep_dataset/ILSVRC2012_val_00016935.bin 224 224 +3274 ./prep_dataset/ILSVRC2012_val_00011196.bin 224 224 +3275 ./prep_dataset/ILSVRC2012_val_00044585.bin 224 224 +3276 ./prep_dataset/ILSVRC2012_val_00042442.bin 224 224 +3277 ./prep_dataset/ILSVRC2012_val_00036506.bin 224 224 +3278 ./prep_dataset/ILSVRC2012_val_00021907.bin 224 224 +3279 ./prep_dataset/ILSVRC2012_val_00008087.bin 224 224 +3280 ./prep_dataset/ILSVRC2012_val_00027828.bin 224 224 +3281 ./prep_dataset/ILSVRC2012_val_00007283.bin 224 224 +3282 ./prep_dataset/ILSVRC2012_val_00025548.bin 224 224 +3283 ./prep_dataset/ILSVRC2012_val_00026260.bin 224 224 +3284 ./prep_dataset/ILSVRC2012_val_00017722.bin 224 224 +3285 ./prep_dataset/ILSVRC2012_val_00045386.bin 224 224 +3286 ./prep_dataset/ILSVRC2012_val_00001430.bin 224 224 +3287 ./prep_dataset/ILSVRC2012_val_00006543.bin 224 224 +3288 ./prep_dataset/ILSVRC2012_val_00023703.bin 224 224 +3289 ./prep_dataset/ILSVRC2012_val_00031403.bin 224 224 +3290 ./prep_dataset/ILSVRC2012_val_00026964.bin 224 224 +3291 ./prep_dataset/ILSVRC2012_val_00028176.bin 224 224 +3292 ./prep_dataset/ILSVRC2012_val_00032866.bin 224 224 +3293 ./prep_dataset/ILSVRC2012_val_00019967.bin 224 224 +3294 ./prep_dataset/ILSVRC2012_val_00002106.bin 224 224 +3295 ./prep_dataset/ILSVRC2012_val_00010650.bin 224 224 +3296 ./prep_dataset/ILSVRC2012_val_00005074.bin 224 224 +3297 ./prep_dataset/ILSVRC2012_val_00006442.bin 224 224 +3298 ./prep_dataset/ILSVRC2012_val_00027716.bin 224 224 +3299 ./prep_dataset/ILSVRC2012_val_00033606.bin 224 224 +3300 ./prep_dataset/ILSVRC2012_val_00048320.bin 224 224 +3301 ./prep_dataset/ILSVRC2012_val_00025247.bin 224 224 +3302 ./prep_dataset/ILSVRC2012_val_00033813.bin 224 224 +3303 ./prep_dataset/ILSVRC2012_val_00039714.bin 224 224 +3304 ./prep_dataset/ILSVRC2012_val_00037180.bin 224 224 +3305 ./prep_dataset/ILSVRC2012_val_00025602.bin 224 224 +3306 ./prep_dataset/ILSVRC2012_val_00042408.bin 224 224 +3307 ./prep_dataset/ILSVRC2012_val_00009599.bin 224 224 +3308 ./prep_dataset/ILSVRC2012_val_00008178.bin 224 224 +3309 ./prep_dataset/ILSVRC2012_val_00038023.bin 224 224 +3310 ./prep_dataset/ILSVRC2012_val_00004218.bin 224 224 +3311 ./prep_dataset/ILSVRC2012_val_00008755.bin 224 224 +3312 ./prep_dataset/ILSVRC2012_val_00016808.bin 224 224 +3313 ./prep_dataset/ILSVRC2012_val_00006174.bin 224 224 +3314 ./prep_dataset/ILSVRC2012_val_00038753.bin 224 224 +3315 ./prep_dataset/ILSVRC2012_val_00029222.bin 224 224 +3316 ./prep_dataset/ILSVRC2012_val_00040241.bin 224 224 +3317 ./prep_dataset/ILSVRC2012_val_00036177.bin 224 224 +3318 ./prep_dataset/ILSVRC2012_val_00025195.bin 224 224 +3319 ./prep_dataset/ILSVRC2012_val_00030910.bin 224 224 +3320 ./prep_dataset/ILSVRC2012_val_00037465.bin 224 224 +3321 ./prep_dataset/ILSVRC2012_val_00008532.bin 224 224 +3322 ./prep_dataset/ILSVRC2012_val_00007351.bin 224 224 +3323 ./prep_dataset/ILSVRC2012_val_00009702.bin 224 224 +3324 ./prep_dataset/ILSVRC2012_val_00011610.bin 224 224 +3325 ./prep_dataset/ILSVRC2012_val_00018568.bin 224 224 +3326 ./prep_dataset/ILSVRC2012_val_00036118.bin 224 224 +3327 ./prep_dataset/ILSVRC2012_val_00016574.bin 224 224 +3328 ./prep_dataset/ILSVRC2012_val_00010455.bin 224 224 +3329 ./prep_dataset/ILSVRC2012_val_00039579.bin 224 224 +3330 ./prep_dataset/ILSVRC2012_val_00012687.bin 224 224 +3331 ./prep_dataset/ILSVRC2012_val_00038146.bin 224 224 +3332 ./prep_dataset/ILSVRC2012_val_00038492.bin 224 224 +3333 ./prep_dataset/ILSVRC2012_val_00025644.bin 224 224 +3334 ./prep_dataset/ILSVRC2012_val_00021914.bin 224 224 +3335 ./prep_dataset/ILSVRC2012_val_00036892.bin 224 224 +3336 ./prep_dataset/ILSVRC2012_val_00013391.bin 224 224 +3337 ./prep_dataset/ILSVRC2012_val_00037579.bin 224 224 +3338 ./prep_dataset/ILSVRC2012_val_00023607.bin 224 224 +3339 ./prep_dataset/ILSVRC2012_val_00007205.bin 224 224 +3340 ./prep_dataset/ILSVRC2012_val_00032915.bin 224 224 +3341 ./prep_dataset/ILSVRC2012_val_00028861.bin 224 224 +3342 ./prep_dataset/ILSVRC2012_val_00001103.bin 224 224 +3343 ./prep_dataset/ILSVRC2012_val_00023362.bin 224 224 +3344 ./prep_dataset/ILSVRC2012_val_00027678.bin 224 224 +3345 ./prep_dataset/ILSVRC2012_val_00004818.bin 224 224 +3346 ./prep_dataset/ILSVRC2012_val_00002668.bin 224 224 +3347 ./prep_dataset/ILSVRC2012_val_00017630.bin 224 224 +3348 ./prep_dataset/ILSVRC2012_val_00012260.bin 224 224 +3349 ./prep_dataset/ILSVRC2012_val_00025085.bin 224 224 +3350 ./prep_dataset/ILSVRC2012_val_00049705.bin 224 224 +3351 ./prep_dataset/ILSVRC2012_val_00010035.bin 224 224 +3352 ./prep_dataset/ILSVRC2012_val_00014094.bin 224 224 +3353 ./prep_dataset/ILSVRC2012_val_00036233.bin 224 224 +3354 ./prep_dataset/ILSVRC2012_val_00029011.bin 224 224 +3355 ./prep_dataset/ILSVRC2012_val_00042547.bin 224 224 +3356 ./prep_dataset/ILSVRC2012_val_00033632.bin 224 224 +3357 ./prep_dataset/ILSVRC2012_val_00008785.bin 224 224 +3358 ./prep_dataset/ILSVRC2012_val_00034863.bin 224 224 +3359 ./prep_dataset/ILSVRC2012_val_00015820.bin 224 224 +3360 ./prep_dataset/ILSVRC2012_val_00034184.bin 224 224 +3361 ./prep_dataset/ILSVRC2012_val_00033651.bin 224 224 +3362 ./prep_dataset/ILSVRC2012_val_00020010.bin 224 224 +3363 ./prep_dataset/ILSVRC2012_val_00013554.bin 224 224 +3364 ./prep_dataset/ILSVRC2012_val_00024968.bin 224 224 +3365 ./prep_dataset/ILSVRC2012_val_00009325.bin 224 224 +3366 ./prep_dataset/ILSVRC2012_val_00005692.bin 224 224 +3367 ./prep_dataset/ILSVRC2012_val_00026818.bin 224 224 +3368 ./prep_dataset/ILSVRC2012_val_00004767.bin 224 224 +3369 ./prep_dataset/ILSVRC2012_val_00033868.bin 224 224 +3370 ./prep_dataset/ILSVRC2012_val_00044156.bin 224 224 +3371 ./prep_dataset/ILSVRC2012_val_00045071.bin 224 224 +3372 ./prep_dataset/ILSVRC2012_val_00040634.bin 224 224 +3373 ./prep_dataset/ILSVRC2012_val_00011122.bin 224 224 +3374 ./prep_dataset/ILSVRC2012_val_00035495.bin 224 224 +3375 ./prep_dataset/ILSVRC2012_val_00002089.bin 224 224 +3376 ./prep_dataset/ILSVRC2012_val_00007950.bin 224 224 +3377 ./prep_dataset/ILSVRC2012_val_00038155.bin 224 224 +3378 ./prep_dataset/ILSVRC2012_val_00010802.bin 224 224 +3379 ./prep_dataset/ILSVRC2012_val_00007245.bin 224 224 +3380 ./prep_dataset/ILSVRC2012_val_00031327.bin 224 224 +3381 ./prep_dataset/ILSVRC2012_val_00037093.bin 224 224 +3382 ./prep_dataset/ILSVRC2012_val_00022200.bin 224 224 +3383 ./prep_dataset/ILSVRC2012_val_00015637.bin 224 224 +3384 ./prep_dataset/ILSVRC2012_val_00011972.bin 224 224 +3385 ./prep_dataset/ILSVRC2012_val_00042639.bin 224 224 +3386 ./prep_dataset/ILSVRC2012_val_00008845.bin 224 224 +3387 ./prep_dataset/ILSVRC2012_val_00022077.bin 224 224 +3388 ./prep_dataset/ILSVRC2012_val_00031293.bin 224 224 +3389 ./prep_dataset/ILSVRC2012_val_00046640.bin 224 224 +3390 ./prep_dataset/ILSVRC2012_val_00008610.bin 224 224 +3391 ./prep_dataset/ILSVRC2012_val_00001357.bin 224 224 +3392 ./prep_dataset/ILSVRC2012_val_00002024.bin 224 224 +3393 ./prep_dataset/ILSVRC2012_val_00010838.bin 224 224 +3394 ./prep_dataset/ILSVRC2012_val_00012656.bin 224 224 +3395 ./prep_dataset/ILSVRC2012_val_00031652.bin 224 224 +3396 ./prep_dataset/ILSVRC2012_val_00041392.bin 224 224 +3397 ./prep_dataset/ILSVRC2012_val_00012457.bin 224 224 +3398 ./prep_dataset/ILSVRC2012_val_00040396.bin 224 224 +3399 ./prep_dataset/ILSVRC2012_val_00023471.bin 224 224 +3400 ./prep_dataset/ILSVRC2012_val_00006848.bin 224 224 +3401 ./prep_dataset/ILSVRC2012_val_00045139.bin 224 224 +3402 ./prep_dataset/ILSVRC2012_val_00031787.bin 224 224 +3403 ./prep_dataset/ILSVRC2012_val_00040021.bin 224 224 +3404 ./prep_dataset/ILSVRC2012_val_00015733.bin 224 224 +3405 ./prep_dataset/ILSVRC2012_val_00036839.bin 224 224 +3406 ./prep_dataset/ILSVRC2012_val_00002102.bin 224 224 +3407 ./prep_dataset/ILSVRC2012_val_00030112.bin 224 224 +3408 ./prep_dataset/ILSVRC2012_val_00027985.bin 224 224 +3409 ./prep_dataset/ILSVRC2012_val_00025964.bin 224 224 +3410 ./prep_dataset/ILSVRC2012_val_00037265.bin 224 224 +3411 ./prep_dataset/ILSVRC2012_val_00025414.bin 224 224 +3412 ./prep_dataset/ILSVRC2012_val_00034501.bin 224 224 +3413 ./prep_dataset/ILSVRC2012_val_00020418.bin 224 224 +3414 ./prep_dataset/ILSVRC2012_val_00022273.bin 224 224 +3415 ./prep_dataset/ILSVRC2012_val_00010061.bin 224 224 +3416 ./prep_dataset/ILSVRC2012_val_00011643.bin 224 224 +3417 ./prep_dataset/ILSVRC2012_val_00033787.bin 224 224 +3418 ./prep_dataset/ILSVRC2012_val_00027301.bin 224 224 +3419 ./prep_dataset/ILSVRC2012_val_00008025.bin 224 224 +3420 ./prep_dataset/ILSVRC2012_val_00023111.bin 224 224 +3421 ./prep_dataset/ILSVRC2012_val_00023398.bin 224 224 +3422 ./prep_dataset/ILSVRC2012_val_00006256.bin 224 224 +3423 ./prep_dataset/ILSVRC2012_val_00027679.bin 224 224 +3424 ./prep_dataset/ILSVRC2012_val_00011378.bin 224 224 +3425 ./prep_dataset/ILSVRC2012_val_00011454.bin 224 224 +3426 ./prep_dataset/ILSVRC2012_val_00014405.bin 224 224 +3427 ./prep_dataset/ILSVRC2012_val_00041220.bin 224 224 +3428 ./prep_dataset/ILSVRC2012_val_00013348.bin 224 224 +3429 ./prep_dataset/ILSVRC2012_val_00018443.bin 224 224 +3430 ./prep_dataset/ILSVRC2012_val_00021658.bin 224 224 +3431 ./prep_dataset/ILSVRC2012_val_00036384.bin 224 224 +3432 ./prep_dataset/ILSVRC2012_val_00040495.bin 224 224 +3433 ./prep_dataset/ILSVRC2012_val_00005400.bin 224 224 +3434 ./prep_dataset/ILSVRC2012_val_00004616.bin 224 224 +3435 ./prep_dataset/ILSVRC2012_val_00032205.bin 224 224 +3436 ./prep_dataset/ILSVRC2012_val_00003739.bin 224 224 +3437 ./prep_dataset/ILSVRC2012_val_00000961.bin 224 224 +3438 ./prep_dataset/ILSVRC2012_val_00012888.bin 224 224 +3439 ./prep_dataset/ILSVRC2012_val_00045573.bin 224 224 +3440 ./prep_dataset/ILSVRC2012_val_00015604.bin 224 224 +3441 ./prep_dataset/ILSVRC2012_val_00001032.bin 224 224 +3442 ./prep_dataset/ILSVRC2012_val_00036981.bin 224 224 +3443 ./prep_dataset/ILSVRC2012_val_00027260.bin 224 224 +3444 ./prep_dataset/ILSVRC2012_val_00040363.bin 224 224 +3445 ./prep_dataset/ILSVRC2012_val_00000985.bin 224 224 +3446 ./prep_dataset/ILSVRC2012_val_00030466.bin 224 224 +3447 ./prep_dataset/ILSVRC2012_val_00042291.bin 224 224 +3448 ./prep_dataset/ILSVRC2012_val_00034372.bin 224 224 +3449 ./prep_dataset/ILSVRC2012_val_00043365.bin 224 224 +3450 ./prep_dataset/ILSVRC2012_val_00048373.bin 224 224 +3451 ./prep_dataset/ILSVRC2012_val_00035687.bin 224 224 +3452 ./prep_dataset/ILSVRC2012_val_00023346.bin 224 224 +3453 ./prep_dataset/ILSVRC2012_val_00011211.bin 224 224 +3454 ./prep_dataset/ILSVRC2012_val_00023356.bin 224 224 +3455 ./prep_dataset/ILSVRC2012_val_00017565.bin 224 224 +3456 ./prep_dataset/ILSVRC2012_val_00005773.bin 224 224 +3457 ./prep_dataset/ILSVRC2012_val_00048099.bin 224 224 +3458 ./prep_dataset/ILSVRC2012_val_00030726.bin 224 224 +3459 ./prep_dataset/ILSVRC2012_val_00041169.bin 224 224 +3460 ./prep_dataset/ILSVRC2012_val_00007904.bin 224 224 +3461 ./prep_dataset/ILSVRC2012_val_00002938.bin 224 224 +3462 ./prep_dataset/ILSVRC2012_val_00028423.bin 224 224 +3463 ./prep_dataset/ILSVRC2012_val_00028727.bin 224 224 +3464 ./prep_dataset/ILSVRC2012_val_00023582.bin 224 224 +3465 ./prep_dataset/ILSVRC2012_val_00024179.bin 224 224 +3466 ./prep_dataset/ILSVRC2012_val_00045382.bin 224 224 +3467 ./prep_dataset/ILSVRC2012_val_00001097.bin 224 224 +3468 ./prep_dataset/ILSVRC2012_val_00042057.bin 224 224 +3469 ./prep_dataset/ILSVRC2012_val_00000788.bin 224 224 +3470 ./prep_dataset/ILSVRC2012_val_00032011.bin 224 224 +3471 ./prep_dataset/ILSVRC2012_val_00021313.bin 224 224 +3472 ./prep_dataset/ILSVRC2012_val_00043945.bin 224 224 +3473 ./prep_dataset/ILSVRC2012_val_00048903.bin 224 224 +3474 ./prep_dataset/ILSVRC2012_val_00038061.bin 224 224 +3475 ./prep_dataset/ILSVRC2012_val_00028520.bin 224 224 +3476 ./prep_dataset/ILSVRC2012_val_00006986.bin 224 224 +3477 ./prep_dataset/ILSVRC2012_val_00002703.bin 224 224 +3478 ./prep_dataset/ILSVRC2012_val_00019793.bin 224 224 +3479 ./prep_dataset/ILSVRC2012_val_00017414.bin 224 224 +3480 ./prep_dataset/ILSVRC2012_val_00012000.bin 224 224 +3481 ./prep_dataset/ILSVRC2012_val_00041294.bin 224 224 +3482 ./prep_dataset/ILSVRC2012_val_00018209.bin 224 224 +3483 ./prep_dataset/ILSVRC2012_val_00011175.bin 224 224 +3484 ./prep_dataset/ILSVRC2012_val_00009899.bin 224 224 +3485 ./prep_dataset/ILSVRC2012_val_00004839.bin 224 224 +3486 ./prep_dataset/ILSVRC2012_val_00027402.bin 224 224 +3487 ./prep_dataset/ILSVRC2012_val_00015421.bin 224 224 +3488 ./prep_dataset/ILSVRC2012_val_00026966.bin 224 224 +3489 ./prep_dataset/ILSVRC2012_val_00006137.bin 224 224 +3490 ./prep_dataset/ILSVRC2012_val_00012408.bin 224 224 +3491 ./prep_dataset/ILSVRC2012_val_00048696.bin 224 224 +3492 ./prep_dataset/ILSVRC2012_val_00002181.bin 224 224 +3493 ./prep_dataset/ILSVRC2012_val_00004425.bin 224 224 +3494 ./prep_dataset/ILSVRC2012_val_00014250.bin 224 224 +3495 ./prep_dataset/ILSVRC2012_val_00002698.bin 224 224 +3496 ./prep_dataset/ILSVRC2012_val_00029047.bin 224 224 +3497 ./prep_dataset/ILSVRC2012_val_00044705.bin 224 224 +3498 ./prep_dataset/ILSVRC2012_val_00044914.bin 224 224 +3499 ./prep_dataset/ILSVRC2012_val_00000756.bin 224 224 +3500 ./prep_dataset/ILSVRC2012_val_00024586.bin 224 224 +3501 ./prep_dataset/ILSVRC2012_val_00013186.bin 224 224 +3502 ./prep_dataset/ILSVRC2012_val_00035965.bin 224 224 +3503 ./prep_dataset/ILSVRC2012_val_00011519.bin 224 224 +3504 ./prep_dataset/ILSVRC2012_val_00042833.bin 224 224 +3505 ./prep_dataset/ILSVRC2012_val_00038094.bin 224 224 +3506 ./prep_dataset/ILSVRC2012_val_00012475.bin 224 224 +3507 ./prep_dataset/ILSVRC2012_val_00026765.bin 224 224 +3508 ./prep_dataset/ILSVRC2012_val_00025861.bin 224 224 +3509 ./prep_dataset/ILSVRC2012_val_00048664.bin 224 224 +3510 ./prep_dataset/ILSVRC2012_val_00010926.bin 224 224 +3511 ./prep_dataset/ILSVRC2012_val_00044237.bin 224 224 +3512 ./prep_dataset/ILSVRC2012_val_00043281.bin 224 224 +3513 ./prep_dataset/ILSVRC2012_val_00022693.bin 224 224 +3514 ./prep_dataset/ILSVRC2012_val_00036864.bin 224 224 +3515 ./prep_dataset/ILSVRC2012_val_00013456.bin 224 224 +3516 ./prep_dataset/ILSVRC2012_val_00034992.bin 224 224 +3517 ./prep_dataset/ILSVRC2012_val_00049681.bin 224 224 +3518 ./prep_dataset/ILSVRC2012_val_00034422.bin 224 224 +3519 ./prep_dataset/ILSVRC2012_val_00014182.bin 224 224 +3520 ./prep_dataset/ILSVRC2012_val_00009566.bin 224 224 +3521 ./prep_dataset/ILSVRC2012_val_00049167.bin 224 224 +3522 ./prep_dataset/ILSVRC2012_val_00021904.bin 224 224 +3523 ./prep_dataset/ILSVRC2012_val_00017402.bin 224 224 +3524 ./prep_dataset/ILSVRC2012_val_00025799.bin 224 224 +3525 ./prep_dataset/ILSVRC2012_val_00011198.bin 224 224 +3526 ./prep_dataset/ILSVRC2012_val_00039463.bin 224 224 +3527 ./prep_dataset/ILSVRC2012_val_00015974.bin 224 224 +3528 ./prep_dataset/ILSVRC2012_val_00021101.bin 224 224 +3529 ./prep_dataset/ILSVRC2012_val_00023022.bin 224 224 +3530 ./prep_dataset/ILSVRC2012_val_00004564.bin 224 224 +3531 ./prep_dataset/ILSVRC2012_val_00039810.bin 224 224 +3532 ./prep_dataset/ILSVRC2012_val_00018789.bin 224 224 +3533 ./prep_dataset/ILSVRC2012_val_00046823.bin 224 224 +3534 ./prep_dataset/ILSVRC2012_val_00010401.bin 224 224 +3535 ./prep_dataset/ILSVRC2012_val_00015548.bin 224 224 +3536 ./prep_dataset/ILSVRC2012_val_00002097.bin 224 224 +3537 ./prep_dataset/ILSVRC2012_val_00031550.bin 224 224 +3538 ./prep_dataset/ILSVRC2012_val_00005580.bin 224 224 +3539 ./prep_dataset/ILSVRC2012_val_00015642.bin 224 224 +3540 ./prep_dataset/ILSVRC2012_val_00005348.bin 224 224 +3541 ./prep_dataset/ILSVRC2012_val_00012805.bin 224 224 +3542 ./prep_dataset/ILSVRC2012_val_00014367.bin 224 224 +3543 ./prep_dataset/ILSVRC2012_val_00011689.bin 224 224 +3544 ./prep_dataset/ILSVRC2012_val_00001005.bin 224 224 +3545 ./prep_dataset/ILSVRC2012_val_00023908.bin 224 224 +3546 ./prep_dataset/ILSVRC2012_val_00037928.bin 224 224 +3547 ./prep_dataset/ILSVRC2012_val_00009800.bin 224 224 +3548 ./prep_dataset/ILSVRC2012_val_00026519.bin 224 224 +3549 ./prep_dataset/ILSVRC2012_val_00040961.bin 224 224 +3550 ./prep_dataset/ILSVRC2012_val_00026823.bin 224 224 +3551 ./prep_dataset/ILSVRC2012_val_00032939.bin 224 224 +3552 ./prep_dataset/ILSVRC2012_val_00010862.bin 224 224 +3553 ./prep_dataset/ILSVRC2012_val_00019088.bin 224 224 +3554 ./prep_dataset/ILSVRC2012_val_00029704.bin 224 224 +3555 ./prep_dataset/ILSVRC2012_val_00034485.bin 224 224 +3556 ./prep_dataset/ILSVRC2012_val_00026342.bin 224 224 +3557 ./prep_dataset/ILSVRC2012_val_00041679.bin 224 224 +3558 ./prep_dataset/ILSVRC2012_val_00039691.bin 224 224 +3559 ./prep_dataset/ILSVRC2012_val_00012301.bin 224 224 +3560 ./prep_dataset/ILSVRC2012_val_00013427.bin 224 224 +3561 ./prep_dataset/ILSVRC2012_val_00037613.bin 224 224 +3562 ./prep_dataset/ILSVRC2012_val_00029227.bin 224 224 +3563 ./prep_dataset/ILSVRC2012_val_00019161.bin 224 224 +3564 ./prep_dataset/ILSVRC2012_val_00024396.bin 224 224 +3565 ./prep_dataset/ILSVRC2012_val_00026651.bin 224 224 +3566 ./prep_dataset/ILSVRC2012_val_00012038.bin 224 224 +3567 ./prep_dataset/ILSVRC2012_val_00013803.bin 224 224 +3568 ./prep_dataset/ILSVRC2012_val_00042515.bin 224 224 +3569 ./prep_dataset/ILSVRC2012_val_00022642.bin 224 224 +3570 ./prep_dataset/ILSVRC2012_val_00047332.bin 224 224 +3571 ./prep_dataset/ILSVRC2012_val_00009307.bin 224 224 +3572 ./prep_dataset/ILSVRC2012_val_00019587.bin 224 224 +3573 ./prep_dataset/ILSVRC2012_val_00026820.bin 224 224 +3574 ./prep_dataset/ILSVRC2012_val_00039558.bin 224 224 +3575 ./prep_dataset/ILSVRC2012_val_00039426.bin 224 224 +3576 ./prep_dataset/ILSVRC2012_val_00016042.bin 224 224 +3577 ./prep_dataset/ILSVRC2012_val_00030749.bin 224 224 +3578 ./prep_dataset/ILSVRC2012_val_00018379.bin 224 224 +3579 ./prep_dataset/ILSVRC2012_val_00047786.bin 224 224 +3580 ./prep_dataset/ILSVRC2012_val_00006724.bin 224 224 +3581 ./prep_dataset/ILSVRC2012_val_00029935.bin 224 224 +3582 ./prep_dataset/ILSVRC2012_val_00039322.bin 224 224 +3583 ./prep_dataset/ILSVRC2012_val_00028319.bin 224 224 +3584 ./prep_dataset/ILSVRC2012_val_00046514.bin 224 224 +3585 ./prep_dataset/ILSVRC2012_val_00040245.bin 224 224 +3586 ./prep_dataset/ILSVRC2012_val_00011287.bin 224 224 +3587 ./prep_dataset/ILSVRC2012_val_00039629.bin 224 224 +3588 ./prep_dataset/ILSVRC2012_val_00002485.bin 224 224 +3589 ./prep_dataset/ILSVRC2012_val_00046855.bin 224 224 +3590 ./prep_dataset/ILSVRC2012_val_00045292.bin 224 224 +3591 ./prep_dataset/ILSVRC2012_val_00035221.bin 224 224 +3592 ./prep_dataset/ILSVRC2012_val_00014037.bin 224 224 +3593 ./prep_dataset/ILSVRC2012_val_00006808.bin 224 224 +3594 ./prep_dataset/ILSVRC2012_val_00003561.bin 224 224 +3595 ./prep_dataset/ILSVRC2012_val_00023426.bin 224 224 +3596 ./prep_dataset/ILSVRC2012_val_00020731.bin 224 224 +3597 ./prep_dataset/ILSVRC2012_val_00027520.bin 224 224 +3598 ./prep_dataset/ILSVRC2012_val_00048219.bin 224 224 +3599 ./prep_dataset/ILSVRC2012_val_00043191.bin 224 224 +3600 ./prep_dataset/ILSVRC2012_val_00021549.bin 224 224 +3601 ./prep_dataset/ILSVRC2012_val_00041360.bin 224 224 +3602 ./prep_dataset/ILSVRC2012_val_00016955.bin 224 224 +3603 ./prep_dataset/ILSVRC2012_val_00038569.bin 224 224 +3604 ./prep_dataset/ILSVRC2012_val_00028537.bin 224 224 +3605 ./prep_dataset/ILSVRC2012_val_00005678.bin 224 224 +3606 ./prep_dataset/ILSVRC2012_val_00039730.bin 224 224 +3607 ./prep_dataset/ILSVRC2012_val_00002128.bin 224 224 +3608 ./prep_dataset/ILSVRC2012_val_00045821.bin 224 224 +3609 ./prep_dataset/ILSVRC2012_val_00013720.bin 224 224 +3610 ./prep_dataset/ILSVRC2012_val_00024067.bin 224 224 +3611 ./prep_dataset/ILSVRC2012_val_00025060.bin 224 224 +3612 ./prep_dataset/ILSVRC2012_val_00027293.bin 224 224 +3613 ./prep_dataset/ILSVRC2012_val_00047361.bin 224 224 +3614 ./prep_dataset/ILSVRC2012_val_00038930.bin 224 224 +3615 ./prep_dataset/ILSVRC2012_val_00047805.bin 224 224 +3616 ./prep_dataset/ILSVRC2012_val_00033684.bin 224 224 +3617 ./prep_dataset/ILSVRC2012_val_00021694.bin 224 224 +3618 ./prep_dataset/ILSVRC2012_val_00016222.bin 224 224 +3619 ./prep_dataset/ILSVRC2012_val_00034608.bin 224 224 +3620 ./prep_dataset/ILSVRC2012_val_00003304.bin 224 224 +3621 ./prep_dataset/ILSVRC2012_val_00019509.bin 224 224 +3622 ./prep_dataset/ILSVRC2012_val_00019697.bin 224 224 +3623 ./prep_dataset/ILSVRC2012_val_00038127.bin 224 224 +3624 ./prep_dataset/ILSVRC2012_val_00001391.bin 224 224 +3625 ./prep_dataset/ILSVRC2012_val_00001505.bin 224 224 +3626 ./prep_dataset/ILSVRC2012_val_00021461.bin 224 224 +3627 ./prep_dataset/ILSVRC2012_val_00016756.bin 224 224 +3628 ./prep_dataset/ILSVRC2012_val_00021851.bin 224 224 +3629 ./prep_dataset/ILSVRC2012_val_00030425.bin 224 224 +3630 ./prep_dataset/ILSVRC2012_val_00041090.bin 224 224 +3631 ./prep_dataset/ILSVRC2012_val_00035957.bin 224 224 +3632 ./prep_dataset/ILSVRC2012_val_00035069.bin 224 224 +3633 ./prep_dataset/ILSVRC2012_val_00026631.bin 224 224 +3634 ./prep_dataset/ILSVRC2012_val_00039916.bin 224 224 +3635 ./prep_dataset/ILSVRC2012_val_00023885.bin 224 224 +3636 ./prep_dataset/ILSVRC2012_val_00018848.bin 224 224 +3637 ./prep_dataset/ILSVRC2012_val_00022761.bin 224 224 +3638 ./prep_dataset/ILSVRC2012_val_00031692.bin 224 224 +3639 ./prep_dataset/ILSVRC2012_val_00006659.bin 224 224 +3640 ./prep_dataset/ILSVRC2012_val_00049676.bin 224 224 +3641 ./prep_dataset/ILSVRC2012_val_00007789.bin 224 224 +3642 ./prep_dataset/ILSVRC2012_val_00010245.bin 224 224 +3643 ./prep_dataset/ILSVRC2012_val_00030605.bin 224 224 +3644 ./prep_dataset/ILSVRC2012_val_00044949.bin 224 224 +3645 ./prep_dataset/ILSVRC2012_val_00048668.bin 224 224 +3646 ./prep_dataset/ILSVRC2012_val_00015359.bin 224 224 +3647 ./prep_dataset/ILSVRC2012_val_00044292.bin 224 224 +3648 ./prep_dataset/ILSVRC2012_val_00045265.bin 224 224 +3649 ./prep_dataset/ILSVRC2012_val_00034956.bin 224 224 +3650 ./prep_dataset/ILSVRC2012_val_00022502.bin 224 224 +3651 ./prep_dataset/ILSVRC2012_val_00019855.bin 224 224 +3652 ./prep_dataset/ILSVRC2012_val_00043930.bin 224 224 +3653 ./prep_dataset/ILSVRC2012_val_00002680.bin 224 224 +3654 ./prep_dataset/ILSVRC2012_val_00006241.bin 224 224 +3655 ./prep_dataset/ILSVRC2012_val_00011193.bin 224 224 +3656 ./prep_dataset/ILSVRC2012_val_00004629.bin 224 224 +3657 ./prep_dataset/ILSVRC2012_val_00004113.bin 224 224 +3658 ./prep_dataset/ILSVRC2012_val_00047273.bin 224 224 +3659 ./prep_dataset/ILSVRC2012_val_00041484.bin 224 224 +3660 ./prep_dataset/ILSVRC2012_val_00014606.bin 224 224 +3661 ./prep_dataset/ILSVRC2012_val_00044245.bin 224 224 +3662 ./prep_dataset/ILSVRC2012_val_00049068.bin 224 224 +3663 ./prep_dataset/ILSVRC2012_val_00006130.bin 224 224 +3664 ./prep_dataset/ILSVRC2012_val_00033867.bin 224 224 +3665 ./prep_dataset/ILSVRC2012_val_00000239.bin 224 224 +3666 ./prep_dataset/ILSVRC2012_val_00018476.bin 224 224 +3667 ./prep_dataset/ILSVRC2012_val_00034759.bin 224 224 +3668 ./prep_dataset/ILSVRC2012_val_00021096.bin 224 224 +3669 ./prep_dataset/ILSVRC2012_val_00040040.bin 224 224 +3670 ./prep_dataset/ILSVRC2012_val_00025163.bin 224 224 +3671 ./prep_dataset/ILSVRC2012_val_00047710.bin 224 224 +3672 ./prep_dataset/ILSVRC2012_val_00022767.bin 224 224 +3673 ./prep_dataset/ILSVRC2012_val_00011948.bin 224 224 +3674 ./prep_dataset/ILSVRC2012_val_00024878.bin 224 224 +3675 ./prep_dataset/ILSVRC2012_val_00016090.bin 224 224 +3676 ./prep_dataset/ILSVRC2012_val_00003684.bin 224 224 +3677 ./prep_dataset/ILSVRC2012_val_00017718.bin 224 224 +3678 ./prep_dataset/ILSVRC2012_val_00007942.bin 224 224 +3679 ./prep_dataset/ILSVRC2012_val_00047572.bin 224 224 +3680 ./prep_dataset/ILSVRC2012_val_00042747.bin 224 224 +3681 ./prep_dataset/ILSVRC2012_val_00016990.bin 224 224 +3682 ./prep_dataset/ILSVRC2012_val_00003356.bin 224 224 +3683 ./prep_dataset/ILSVRC2012_val_00021467.bin 224 224 +3684 ./prep_dataset/ILSVRC2012_val_00047648.bin 224 224 +3685 ./prep_dataset/ILSVRC2012_val_00039525.bin 224 224 +3686 ./prep_dataset/ILSVRC2012_val_00000598.bin 224 224 +3687 ./prep_dataset/ILSVRC2012_val_00010460.bin 224 224 +3688 ./prep_dataset/ILSVRC2012_val_00035893.bin 224 224 +3689 ./prep_dataset/ILSVRC2012_val_00013715.bin 224 224 +3690 ./prep_dataset/ILSVRC2012_val_00004083.bin 224 224 +3691 ./prep_dataset/ILSVRC2012_val_00016332.bin 224 224 +3692 ./prep_dataset/ILSVRC2012_val_00009698.bin 224 224 +3693 ./prep_dataset/ILSVRC2012_val_00008576.bin 224 224 +3694 ./prep_dataset/ILSVRC2012_val_00025702.bin 224 224 +3695 ./prep_dataset/ILSVRC2012_val_00033294.bin 224 224 +3696 ./prep_dataset/ILSVRC2012_val_00042488.bin 224 224 +3697 ./prep_dataset/ILSVRC2012_val_00013835.bin 224 224 +3698 ./prep_dataset/ILSVRC2012_val_00032119.bin 224 224 +3699 ./prep_dataset/ILSVRC2012_val_00031086.bin 224 224 +3700 ./prep_dataset/ILSVRC2012_val_00045985.bin 224 224 +3701 ./prep_dataset/ILSVRC2012_val_00042599.bin 224 224 +3702 ./prep_dataset/ILSVRC2012_val_00029596.bin 224 224 +3703 ./prep_dataset/ILSVRC2012_val_00026779.bin 224 224 +3704 ./prep_dataset/ILSVRC2012_val_00042718.bin 224 224 +3705 ./prep_dataset/ILSVRC2012_val_00037468.bin 224 224 +3706 ./prep_dataset/ILSVRC2012_val_00009620.bin 224 224 +3707 ./prep_dataset/ILSVRC2012_val_00004197.bin 224 224 +3708 ./prep_dataset/ILSVRC2012_val_00015807.bin 224 224 +3709 ./prep_dataset/ILSVRC2012_val_00040539.bin 224 224 +3710 ./prep_dataset/ILSVRC2012_val_00016586.bin 224 224 +3711 ./prep_dataset/ILSVRC2012_val_00036303.bin 224 224 +3712 ./prep_dataset/ILSVRC2012_val_00029818.bin 224 224 +3713 ./prep_dataset/ILSVRC2012_val_00039151.bin 224 224 +3714 ./prep_dataset/ILSVRC2012_val_00002280.bin 224 224 +3715 ./prep_dataset/ILSVRC2012_val_00046472.bin 224 224 +3716 ./prep_dataset/ILSVRC2012_val_00043243.bin 224 224 +3717 ./prep_dataset/ILSVRC2012_val_00033472.bin 224 224 +3718 ./prep_dataset/ILSVRC2012_val_00046798.bin 224 224 +3719 ./prep_dataset/ILSVRC2012_val_00038585.bin 224 224 +3720 ./prep_dataset/ILSVRC2012_val_00043724.bin 224 224 +3721 ./prep_dataset/ILSVRC2012_val_00009083.bin 224 224 +3722 ./prep_dataset/ILSVRC2012_val_00032239.bin 224 224 +3723 ./prep_dataset/ILSVRC2012_val_00005436.bin 224 224 +3724 ./prep_dataset/ILSVRC2012_val_00040566.bin 224 224 +3725 ./prep_dataset/ILSVRC2012_val_00046897.bin 224 224 +3726 ./prep_dataset/ILSVRC2012_val_00025514.bin 224 224 +3727 ./prep_dataset/ILSVRC2012_val_00007501.bin 224 224 +3728 ./prep_dataset/ILSVRC2012_val_00000436.bin 224 224 +3729 ./prep_dataset/ILSVRC2012_val_00026682.bin 224 224 +3730 ./prep_dataset/ILSVRC2012_val_00047559.bin 224 224 +3731 ./prep_dataset/ILSVRC2012_val_00048648.bin 224 224 +3732 ./prep_dataset/ILSVRC2012_val_00031820.bin 224 224 +3733 ./prep_dataset/ILSVRC2012_val_00025735.bin 224 224 +3734 ./prep_dataset/ILSVRC2012_val_00032874.bin 224 224 +3735 ./prep_dataset/ILSVRC2012_val_00036605.bin 224 224 +3736 ./prep_dataset/ILSVRC2012_val_00008972.bin 224 224 +3737 ./prep_dataset/ILSVRC2012_val_00002447.bin 224 224 +3738 ./prep_dataset/ILSVRC2012_val_00009386.bin 224 224 +3739 ./prep_dataset/ILSVRC2012_val_00036853.bin 224 224 +3740 ./prep_dataset/ILSVRC2012_val_00045936.bin 224 224 +3741 ./prep_dataset/ILSVRC2012_val_00032973.bin 224 224 +3742 ./prep_dataset/ILSVRC2012_val_00004233.bin 224 224 +3743 ./prep_dataset/ILSVRC2012_val_00049010.bin 224 224 +3744 ./prep_dataset/ILSVRC2012_val_00025390.bin 224 224 +3745 ./prep_dataset/ILSVRC2012_val_00005354.bin 224 224 +3746 ./prep_dataset/ILSVRC2012_val_00025477.bin 224 224 +3747 ./prep_dataset/ILSVRC2012_val_00046733.bin 224 224 +3748 ./prep_dataset/ILSVRC2012_val_00026686.bin 224 224 +3749 ./prep_dataset/ILSVRC2012_val_00049214.bin 224 224 +3750 ./prep_dataset/ILSVRC2012_val_00011283.bin 224 224 +3751 ./prep_dataset/ILSVRC2012_val_00022439.bin 224 224 +3752 ./prep_dataset/ILSVRC2012_val_00048895.bin 224 224 +3753 ./prep_dataset/ILSVRC2012_val_00044425.bin 224 224 +3754 ./prep_dataset/ILSVRC2012_val_00010268.bin 224 224 +3755 ./prep_dataset/ILSVRC2012_val_00032029.bin 224 224 +3756 ./prep_dataset/ILSVRC2012_val_00006375.bin 224 224 +3757 ./prep_dataset/ILSVRC2012_val_00049050.bin 224 224 +3758 ./prep_dataset/ILSVRC2012_val_00038843.bin 224 224 +3759 ./prep_dataset/ILSVRC2012_val_00048217.bin 224 224 +3760 ./prep_dataset/ILSVRC2012_val_00014472.bin 224 224 +3761 ./prep_dataset/ILSVRC2012_val_00009653.bin 224 224 +3762 ./prep_dataset/ILSVRC2012_val_00045023.bin 224 224 +3763 ./prep_dataset/ILSVRC2012_val_00041396.bin 224 224 +3764 ./prep_dataset/ILSVRC2012_val_00014653.bin 224 224 +3765 ./prep_dataset/ILSVRC2012_val_00015863.bin 224 224 +3766 ./prep_dataset/ILSVRC2012_val_00048340.bin 224 224 +3767 ./prep_dataset/ILSVRC2012_val_00005212.bin 224 224 +3768 ./prep_dataset/ILSVRC2012_val_00023900.bin 224 224 +3769 ./prep_dataset/ILSVRC2012_val_00001469.bin 224 224 +3770 ./prep_dataset/ILSVRC2012_val_00003330.bin 224 224 +3771 ./prep_dataset/ILSVRC2012_val_00028454.bin 224 224 +3772 ./prep_dataset/ILSVRC2012_val_00024248.bin 224 224 +3773 ./prep_dataset/ILSVRC2012_val_00049692.bin 224 224 +3774 ./prep_dataset/ILSVRC2012_val_00015216.bin 224 224 +3775 ./prep_dataset/ILSVRC2012_val_00028927.bin 224 224 +3776 ./prep_dataset/ILSVRC2012_val_00021566.bin 224 224 +3777 ./prep_dataset/ILSVRC2012_val_00001524.bin 224 224 +3778 ./prep_dataset/ILSVRC2012_val_00022481.bin 224 224 +3779 ./prep_dataset/ILSVRC2012_val_00033985.bin 224 224 +3780 ./prep_dataset/ILSVRC2012_val_00009588.bin 224 224 +3781 ./prep_dataset/ILSVRC2012_val_00019046.bin 224 224 +3782 ./prep_dataset/ILSVRC2012_val_00005961.bin 224 224 +3783 ./prep_dataset/ILSVRC2012_val_00021928.bin 224 224 +3784 ./prep_dataset/ILSVRC2012_val_00042004.bin 224 224 +3785 ./prep_dataset/ILSVRC2012_val_00000356.bin 224 224 +3786 ./prep_dataset/ILSVRC2012_val_00042143.bin 224 224 +3787 ./prep_dataset/ILSVRC2012_val_00014733.bin 224 224 +3788 ./prep_dataset/ILSVRC2012_val_00040607.bin 224 224 +3789 ./prep_dataset/ILSVRC2012_val_00011491.bin 224 224 +3790 ./prep_dataset/ILSVRC2012_val_00043452.bin 224 224 +3791 ./prep_dataset/ILSVRC2012_val_00016432.bin 224 224 +3792 ./prep_dataset/ILSVRC2012_val_00018334.bin 224 224 +3793 ./prep_dataset/ILSVRC2012_val_00029634.bin 224 224 +3794 ./prep_dataset/ILSVRC2012_val_00040753.bin 224 224 +3795 ./prep_dataset/ILSVRC2012_val_00049790.bin 224 224 +3796 ./prep_dataset/ILSVRC2012_val_00032433.bin 224 224 +3797 ./prep_dataset/ILSVRC2012_val_00048200.bin 224 224 +3798 ./prep_dataset/ILSVRC2012_val_00010762.bin 224 224 +3799 ./prep_dataset/ILSVRC2012_val_00021262.bin 224 224 +3800 ./prep_dataset/ILSVRC2012_val_00042183.bin 224 224 +3801 ./prep_dataset/ILSVRC2012_val_00043517.bin 224 224 +3802 ./prep_dataset/ILSVRC2012_val_00022636.bin 224 224 +3803 ./prep_dataset/ILSVRC2012_val_00040148.bin 224 224 +3804 ./prep_dataset/ILSVRC2012_val_00020407.bin 224 224 +3805 ./prep_dataset/ILSVRC2012_val_00033624.bin 224 224 +3806 ./prep_dataset/ILSVRC2012_val_00042137.bin 224 224 +3807 ./prep_dataset/ILSVRC2012_val_00038605.bin 224 224 +3808 ./prep_dataset/ILSVRC2012_val_00045924.bin 224 224 +3809 ./prep_dataset/ILSVRC2012_val_00023848.bin 224 224 +3810 ./prep_dataset/ILSVRC2012_val_00026704.bin 224 224 +3811 ./prep_dataset/ILSVRC2012_val_00027688.bin 224 224 +3812 ./prep_dataset/ILSVRC2012_val_00040960.bin 224 224 +3813 ./prep_dataset/ILSVRC2012_val_00036227.bin 224 224 +3814 ./prep_dataset/ILSVRC2012_val_00008659.bin 224 224 +3815 ./prep_dataset/ILSVRC2012_val_00016261.bin 224 224 +3816 ./prep_dataset/ILSVRC2012_val_00005600.bin 224 224 +3817 ./prep_dataset/ILSVRC2012_val_00014399.bin 224 224 +3818 ./prep_dataset/ILSVRC2012_val_00043726.bin 224 224 +3819 ./prep_dataset/ILSVRC2012_val_00010554.bin 224 224 +3820 ./prep_dataset/ILSVRC2012_val_00035713.bin 224 224 +3821 ./prep_dataset/ILSVRC2012_val_00038592.bin 224 224 +3822 ./prep_dataset/ILSVRC2012_val_00019446.bin 224 224 +3823 ./prep_dataset/ILSVRC2012_val_00049935.bin 224 224 +3824 ./prep_dataset/ILSVRC2012_val_00036179.bin 224 224 +3825 ./prep_dataset/ILSVRC2012_val_00022343.bin 224 224 +3826 ./prep_dataset/ILSVRC2012_val_00032655.bin 224 224 +3827 ./prep_dataset/ILSVRC2012_val_00036847.bin 224 224 +3828 ./prep_dataset/ILSVRC2012_val_00032691.bin 224 224 +3829 ./prep_dataset/ILSVRC2012_val_00048631.bin 224 224 +3830 ./prep_dataset/ILSVRC2012_val_00038865.bin 224 224 +3831 ./prep_dataset/ILSVRC2012_val_00007514.bin 224 224 +3832 ./prep_dataset/ILSVRC2012_val_00007895.bin 224 224 +3833 ./prep_dataset/ILSVRC2012_val_00039737.bin 224 224 +3834 ./prep_dataset/ILSVRC2012_val_00000925.bin 224 224 +3835 ./prep_dataset/ILSVRC2012_val_00045239.bin 224 224 +3836 ./prep_dataset/ILSVRC2012_val_00048425.bin 224 224 +3837 ./prep_dataset/ILSVRC2012_val_00024071.bin 224 224 +3838 ./prep_dataset/ILSVRC2012_val_00021700.bin 224 224 +3839 ./prep_dataset/ILSVRC2012_val_00035373.bin 224 224 +3840 ./prep_dataset/ILSVRC2012_val_00037284.bin 224 224 +3841 ./prep_dataset/ILSVRC2012_val_00009515.bin 224 224 +3842 ./prep_dataset/ILSVRC2012_val_00006079.bin 224 224 +3843 ./prep_dataset/ILSVRC2012_val_00010130.bin 224 224 +3844 ./prep_dataset/ILSVRC2012_val_00049620.bin 224 224 +3845 ./prep_dataset/ILSVRC2012_val_00016467.bin 224 224 +3846 ./prep_dataset/ILSVRC2012_val_00030030.bin 224 224 +3847 ./prep_dataset/ILSVRC2012_val_00018839.bin 224 224 +3848 ./prep_dataset/ILSVRC2012_val_00022751.bin 224 224 +3849 ./prep_dataset/ILSVRC2012_val_00005117.bin 224 224 +3850 ./prep_dataset/ILSVRC2012_val_00016559.bin 224 224 +3851 ./prep_dataset/ILSVRC2012_val_00019396.bin 224 224 +3852 ./prep_dataset/ILSVRC2012_val_00004642.bin 224 224 +3853 ./prep_dataset/ILSVRC2012_val_00029464.bin 224 224 +3854 ./prep_dataset/ILSVRC2012_val_00005287.bin 224 224 +3855 ./prep_dataset/ILSVRC2012_val_00039141.bin 224 224 +3856 ./prep_dataset/ILSVRC2012_val_00011990.bin 224 224 +3857 ./prep_dataset/ILSVRC2012_val_00017193.bin 224 224 +3858 ./prep_dataset/ILSVRC2012_val_00045123.bin 224 224 +3859 ./prep_dataset/ILSVRC2012_val_00043772.bin 224 224 +3860 ./prep_dataset/ILSVRC2012_val_00042453.bin 224 224 +3861 ./prep_dataset/ILSVRC2012_val_00031776.bin 224 224 +3862 ./prep_dataset/ILSVRC2012_val_00042550.bin 224 224 +3863 ./prep_dataset/ILSVRC2012_val_00038599.bin 224 224 +3864 ./prep_dataset/ILSVRC2012_val_00027387.bin 224 224 +3865 ./prep_dataset/ILSVRC2012_val_00014962.bin 224 224 +3866 ./prep_dataset/ILSVRC2012_val_00034817.bin 224 224 +3867 ./prep_dataset/ILSVRC2012_val_00029647.bin 224 224 +3868 ./prep_dataset/ILSVRC2012_val_00019075.bin 224 224 +3869 ./prep_dataset/ILSVRC2012_val_00004949.bin 224 224 +3870 ./prep_dataset/ILSVRC2012_val_00000020.bin 224 224 +3871 ./prep_dataset/ILSVRC2012_val_00042621.bin 224 224 +3872 ./prep_dataset/ILSVRC2012_val_00024308.bin 224 224 +3873 ./prep_dataset/ILSVRC2012_val_00001541.bin 224 224 +3874 ./prep_dataset/ILSVRC2012_val_00019978.bin 224 224 +3875 ./prep_dataset/ILSVRC2012_val_00008011.bin 224 224 +3876 ./prep_dataset/ILSVRC2012_val_00007435.bin 224 224 +3877 ./prep_dataset/ILSVRC2012_val_00001112.bin 224 224 +3878 ./prep_dataset/ILSVRC2012_val_00001086.bin 224 224 +3879 ./prep_dataset/ILSVRC2012_val_00016445.bin 224 224 +3880 ./prep_dataset/ILSVRC2012_val_00042892.bin 224 224 +3881 ./prep_dataset/ILSVRC2012_val_00002683.bin 224 224 +3882 ./prep_dataset/ILSVRC2012_val_00015566.bin 224 224 +3883 ./prep_dataset/ILSVRC2012_val_00023441.bin 224 224 +3884 ./prep_dataset/ILSVRC2012_val_00018025.bin 224 224 +3885 ./prep_dataset/ILSVRC2012_val_00015135.bin 224 224 +3886 ./prep_dataset/ILSVRC2012_val_00021909.bin 224 224 +3887 ./prep_dataset/ILSVRC2012_val_00039464.bin 224 224 +3888 ./prep_dataset/ILSVRC2012_val_00025626.bin 224 224 +3889 ./prep_dataset/ILSVRC2012_val_00040620.bin 224 224 +3890 ./prep_dataset/ILSVRC2012_val_00007658.bin 224 224 +3891 ./prep_dataset/ILSVRC2012_val_00001422.bin 224 224 +3892 ./prep_dataset/ILSVRC2012_val_00033265.bin 224 224 +3893 ./prep_dataset/ILSVRC2012_val_00002523.bin 224 224 +3894 ./prep_dataset/ILSVRC2012_val_00034309.bin 224 224 +3895 ./prep_dataset/ILSVRC2012_val_00046108.bin 224 224 +3896 ./prep_dataset/ILSVRC2012_val_00025290.bin 224 224 +3897 ./prep_dataset/ILSVRC2012_val_00041590.bin 224 224 +3898 ./prep_dataset/ILSVRC2012_val_00048435.bin 224 224 +3899 ./prep_dataset/ILSVRC2012_val_00017077.bin 224 224 +3900 ./prep_dataset/ILSVRC2012_val_00037198.bin 224 224 +3901 ./prep_dataset/ILSVRC2012_val_00031345.bin 224 224 +3902 ./prep_dataset/ILSVRC2012_val_00003229.bin 224 224 +3903 ./prep_dataset/ILSVRC2012_val_00010333.bin 224 224 +3904 ./prep_dataset/ILSVRC2012_val_00007700.bin 224 224 +3905 ./prep_dataset/ILSVRC2012_val_00010161.bin 224 224 +3906 ./prep_dataset/ILSVRC2012_val_00043980.bin 224 224 +3907 ./prep_dataset/ILSVRC2012_val_00001394.bin 224 224 +3908 ./prep_dataset/ILSVRC2012_val_00042238.bin 224 224 +3909 ./prep_dataset/ILSVRC2012_val_00010711.bin 224 224 +3910 ./prep_dataset/ILSVRC2012_val_00049598.bin 224 224 +3911 ./prep_dataset/ILSVRC2012_val_00046594.bin 224 224 +3912 ./prep_dataset/ILSVRC2012_val_00036746.bin 224 224 +3913 ./prep_dataset/ILSVRC2012_val_00024453.bin 224 224 +3914 ./prep_dataset/ILSVRC2012_val_00049296.bin 224 224 +3915 ./prep_dataset/ILSVRC2012_val_00044639.bin 224 224 +3916 ./prep_dataset/ILSVRC2012_val_00037796.bin 224 224 +3917 ./prep_dataset/ILSVRC2012_val_00022224.bin 224 224 +3918 ./prep_dataset/ILSVRC2012_val_00026281.bin 224 224 +3919 ./prep_dataset/ILSVRC2012_val_00030432.bin 224 224 +3920 ./prep_dataset/ILSVRC2012_val_00043279.bin 224 224 +3921 ./prep_dataset/ILSVRC2012_val_00012700.bin 224 224 +3922 ./prep_dataset/ILSVRC2012_val_00041602.bin 224 224 +3923 ./prep_dataset/ILSVRC2012_val_00036335.bin 224 224 +3924 ./prep_dataset/ILSVRC2012_val_00012392.bin 224 224 +3925 ./prep_dataset/ILSVRC2012_val_00049446.bin 224 224 +3926 ./prep_dataset/ILSVRC2012_val_00036296.bin 224 224 +3927 ./prep_dataset/ILSVRC2012_val_00038348.bin 224 224 +3928 ./prep_dataset/ILSVRC2012_val_00020083.bin 224 224 +3929 ./prep_dataset/ILSVRC2012_val_00029871.bin 224 224 +3930 ./prep_dataset/ILSVRC2012_val_00016030.bin 224 224 +3931 ./prep_dataset/ILSVRC2012_val_00034508.bin 224 224 +3932 ./prep_dataset/ILSVRC2012_val_00048368.bin 224 224 +3933 ./prep_dataset/ILSVRC2012_val_00022127.bin 224 224 +3934 ./prep_dataset/ILSVRC2012_val_00039241.bin 224 224 +3935 ./prep_dataset/ILSVRC2012_val_00048430.bin 224 224 +3936 ./prep_dataset/ILSVRC2012_val_00003228.bin 224 224 +3937 ./prep_dataset/ILSVRC2012_val_00001438.bin 224 224 +3938 ./prep_dataset/ILSVRC2012_val_00005069.bin 224 224 +3939 ./prep_dataset/ILSVRC2012_val_00025273.bin 224 224 +3940 ./prep_dataset/ILSVRC2012_val_00035810.bin 224 224 +3941 ./prep_dataset/ILSVRC2012_val_00003494.bin 224 224 +3942 ./prep_dataset/ILSVRC2012_val_00038438.bin 224 224 +3943 ./prep_dataset/ILSVRC2012_val_00030902.bin 224 224 +3944 ./prep_dataset/ILSVRC2012_val_00039842.bin 224 224 +3945 ./prep_dataset/ILSVRC2012_val_00011249.bin 224 224 +3946 ./prep_dataset/ILSVRC2012_val_00015386.bin 224 224 +3947 ./prep_dataset/ILSVRC2012_val_00028705.bin 224 224 +3948 ./prep_dataset/ILSVRC2012_val_00039924.bin 224 224 +3949 ./prep_dataset/ILSVRC2012_val_00030684.bin 224 224 +3950 ./prep_dataset/ILSVRC2012_val_00022878.bin 224 224 +3951 ./prep_dataset/ILSVRC2012_val_00006969.bin 224 224 +3952 ./prep_dataset/ILSVRC2012_val_00004114.bin 224 224 +3953 ./prep_dataset/ILSVRC2012_val_00004506.bin 224 224 +3954 ./prep_dataset/ILSVRC2012_val_00002755.bin 224 224 +3955 ./prep_dataset/ILSVRC2012_val_00041862.bin 224 224 +3956 ./prep_dataset/ILSVRC2012_val_00000593.bin 224 224 +3957 ./prep_dataset/ILSVRC2012_val_00013819.bin 224 224 +3958 ./prep_dataset/ILSVRC2012_val_00024168.bin 224 224 +3959 ./prep_dataset/ILSVRC2012_val_00007522.bin 224 224 +3960 ./prep_dataset/ILSVRC2012_val_00007403.bin 224 224 +3961 ./prep_dataset/ILSVRC2012_val_00026481.bin 224 224 +3962 ./prep_dataset/ILSVRC2012_val_00002904.bin 224 224 +3963 ./prep_dataset/ILSVRC2012_val_00039995.bin 224 224 +3964 ./prep_dataset/ILSVRC2012_val_00012927.bin 224 224 +3965 ./prep_dataset/ILSVRC2012_val_00012097.bin 224 224 +3966 ./prep_dataset/ILSVRC2012_val_00013286.bin 224 224 +3967 ./prep_dataset/ILSVRC2012_val_00017323.bin 224 224 +3968 ./prep_dataset/ILSVRC2012_val_00043008.bin 224 224 +3969 ./prep_dataset/ILSVRC2012_val_00016284.bin 224 224 +3970 ./prep_dataset/ILSVRC2012_val_00026094.bin 224 224 +3971 ./prep_dataset/ILSVRC2012_val_00039224.bin 224 224 +3972 ./prep_dataset/ILSVRC2012_val_00047793.bin 224 224 +3973 ./prep_dataset/ILSVRC2012_val_00017710.bin 224 224 +3974 ./prep_dataset/ILSVRC2012_val_00036181.bin 224 224 +3975 ./prep_dataset/ILSVRC2012_val_00023748.bin 224 224 +3976 ./prep_dataset/ILSVRC2012_val_00049536.bin 224 224 +3977 ./prep_dataset/ILSVRC2012_val_00021543.bin 224 224 +3978 ./prep_dataset/ILSVRC2012_val_00019544.bin 224 224 +3979 ./prep_dataset/ILSVRC2012_val_00033488.bin 224 224 +3980 ./prep_dataset/ILSVRC2012_val_00023489.bin 224 224 +3981 ./prep_dataset/ILSVRC2012_val_00035019.bin 224 224 +3982 ./prep_dataset/ILSVRC2012_val_00013255.bin 224 224 +3983 ./prep_dataset/ILSVRC2012_val_00018460.bin 224 224 +3984 ./prep_dataset/ILSVRC2012_val_00044283.bin 224 224 +3985 ./prep_dataset/ILSVRC2012_val_00007621.bin 224 224 +3986 ./prep_dataset/ILSVRC2012_val_00016171.bin 224 224 +3987 ./prep_dataset/ILSVRC2012_val_00035855.bin 224 224 +3988 ./prep_dataset/ILSVRC2012_val_00001444.bin 224 224 +3989 ./prep_dataset/ILSVRC2012_val_00034161.bin 224 224 +3990 ./prep_dataset/ILSVRC2012_val_00034974.bin 224 224 +3991 ./prep_dataset/ILSVRC2012_val_00025897.bin 224 224 +3992 ./prep_dataset/ILSVRC2012_val_00033325.bin 224 224 +3993 ./prep_dataset/ILSVRC2012_val_00032855.bin 224 224 +3994 ./prep_dataset/ILSVRC2012_val_00043015.bin 224 224 +3995 ./prep_dataset/ILSVRC2012_val_00023315.bin 224 224 +3996 ./prep_dataset/ILSVRC2012_val_00020681.bin 224 224 +3997 ./prep_dataset/ILSVRC2012_val_00027519.bin 224 224 +3998 ./prep_dataset/ILSVRC2012_val_00045213.bin 224 224 +3999 ./prep_dataset/ILSVRC2012_val_00006288.bin 224 224 +4000 ./prep_dataset/ILSVRC2012_val_00045080.bin 224 224 +4001 ./prep_dataset/ILSVRC2012_val_00037784.bin 224 224 +4002 ./prep_dataset/ILSVRC2012_val_00030024.bin 224 224 +4003 ./prep_dataset/ILSVRC2012_val_00049830.bin 224 224 +4004 ./prep_dataset/ILSVRC2012_val_00027632.bin 224 224 +4005 ./prep_dataset/ILSVRC2012_val_00034405.bin 224 224 +4006 ./prep_dataset/ILSVRC2012_val_00021906.bin 224 224 +4007 ./prep_dataset/ILSVRC2012_val_00025422.bin 224 224 +4008 ./prep_dataset/ILSVRC2012_val_00013187.bin 224 224 +4009 ./prep_dataset/ILSVRC2012_val_00022170.bin 224 224 +4010 ./prep_dataset/ILSVRC2012_val_00041395.bin 224 224 +4011 ./prep_dataset/ILSVRC2012_val_00012660.bin 224 224 +4012 ./prep_dataset/ILSVRC2012_val_00032856.bin 224 224 +4013 ./prep_dataset/ILSVRC2012_val_00023871.bin 224 224 +4014 ./prep_dataset/ILSVRC2012_val_00028587.bin 224 224 +4015 ./prep_dataset/ILSVRC2012_val_00022545.bin 224 224 +4016 ./prep_dataset/ILSVRC2012_val_00034792.bin 224 224 +4017 ./prep_dataset/ILSVRC2012_val_00011374.bin 224 224 +4018 ./prep_dataset/ILSVRC2012_val_00033455.bin 224 224 +4019 ./prep_dataset/ILSVRC2012_val_00018389.bin 224 224 +4020 ./prep_dataset/ILSVRC2012_val_00038327.bin 224 224 +4021 ./prep_dataset/ILSVRC2012_val_00039483.bin 224 224 +4022 ./prep_dataset/ILSVRC2012_val_00026748.bin 224 224 +4023 ./prep_dataset/ILSVRC2012_val_00005434.bin 224 224 +4024 ./prep_dataset/ILSVRC2012_val_00026465.bin 224 224 +4025 ./prep_dataset/ILSVRC2012_val_00032305.bin 224 224 +4026 ./prep_dataset/ILSVRC2012_val_00008537.bin 224 224 +4027 ./prep_dataset/ILSVRC2012_val_00015150.bin 224 224 +4028 ./prep_dataset/ILSVRC2012_val_00045713.bin 224 224 +4029 ./prep_dataset/ILSVRC2012_val_00034476.bin 224 224 +4030 ./prep_dataset/ILSVRC2012_val_00049896.bin 224 224 +4031 ./prep_dataset/ILSVRC2012_val_00022035.bin 224 224 +4032 ./prep_dataset/ILSVRC2012_val_00024241.bin 224 224 +4033 ./prep_dataset/ILSVRC2012_val_00013355.bin 224 224 +4034 ./prep_dataset/ILSVRC2012_val_00045041.bin 224 224 +4035 ./prep_dataset/ILSVRC2012_val_00004155.bin 224 224 +4036 ./prep_dataset/ILSVRC2012_val_00037743.bin 224 224 +4037 ./prep_dataset/ILSVRC2012_val_00024954.bin 224 224 +4038 ./prep_dataset/ILSVRC2012_val_00000369.bin 224 224 +4039 ./prep_dataset/ILSVRC2012_val_00046967.bin 224 224 +4040 ./prep_dataset/ILSVRC2012_val_00046741.bin 224 224 +4041 ./prep_dataset/ILSVRC2012_val_00000513.bin 224 224 +4042 ./prep_dataset/ILSVRC2012_val_00040553.bin 224 224 +4043 ./prep_dataset/ILSVRC2012_val_00041157.bin 224 224 +4044 ./prep_dataset/ILSVRC2012_val_00019580.bin 224 224 +4045 ./prep_dataset/ILSVRC2012_val_00031571.bin 224 224 +4046 ./prep_dataset/ILSVRC2012_val_00033727.bin 224 224 +4047 ./prep_dataset/ILSVRC2012_val_00007320.bin 224 224 +4048 ./prep_dataset/ILSVRC2012_val_00013685.bin 224 224 +4049 ./prep_dataset/ILSVRC2012_val_00012577.bin 224 224 +4050 ./prep_dataset/ILSVRC2012_val_00049618.bin 224 224 +4051 ./prep_dataset/ILSVRC2012_val_00034138.bin 224 224 +4052 ./prep_dataset/ILSVRC2012_val_00013802.bin 224 224 +4053 ./prep_dataset/ILSVRC2012_val_00043914.bin 224 224 +4054 ./prep_dataset/ILSVRC2012_val_00005919.bin 224 224 +4055 ./prep_dataset/ILSVRC2012_val_00047905.bin 224 224 +4056 ./prep_dataset/ILSVRC2012_val_00013713.bin 224 224 +4057 ./prep_dataset/ILSVRC2012_val_00010712.bin 224 224 +4058 ./prep_dataset/ILSVRC2012_val_00011506.bin 224 224 +4059 ./prep_dataset/ILSVRC2012_val_00026270.bin 224 224 +4060 ./prep_dataset/ILSVRC2012_val_00044713.bin 224 224 +4061 ./prep_dataset/ILSVRC2012_val_00020776.bin 224 224 +4062 ./prep_dataset/ILSVRC2012_val_00047550.bin 224 224 +4063 ./prep_dataset/ILSVRC2012_val_00021274.bin 224 224 +4064 ./prep_dataset/ILSVRC2012_val_00022275.bin 224 224 +4065 ./prep_dataset/ILSVRC2012_val_00001655.bin 224 224 +4066 ./prep_dataset/ILSVRC2012_val_00019397.bin 224 224 +4067 ./prep_dataset/ILSVRC2012_val_00030689.bin 224 224 +4068 ./prep_dataset/ILSVRC2012_val_00040492.bin 224 224 +4069 ./prep_dataset/ILSVRC2012_val_00030491.bin 224 224 +4070 ./prep_dataset/ILSVRC2012_val_00002619.bin 224 224 +4071 ./prep_dataset/ILSVRC2012_val_00025086.bin 224 224 +4072 ./prep_dataset/ILSVRC2012_val_00007765.bin 224 224 +4073 ./prep_dataset/ILSVRC2012_val_00028595.bin 224 224 +4074 ./prep_dataset/ILSVRC2012_val_00045085.bin 224 224 +4075 ./prep_dataset/ILSVRC2012_val_00047992.bin 224 224 +4076 ./prep_dataset/ILSVRC2012_val_00020566.bin 224 224 +4077 ./prep_dataset/ILSVRC2012_val_00033009.bin 224 224 +4078 ./prep_dataset/ILSVRC2012_val_00013619.bin 224 224 +4079 ./prep_dataset/ILSVRC2012_val_00021953.bin 224 224 +4080 ./prep_dataset/ILSVRC2012_val_00019972.bin 224 224 +4081 ./prep_dataset/ILSVRC2012_val_00013722.bin 224 224 +4082 ./prep_dataset/ILSVRC2012_val_00019040.bin 224 224 +4083 ./prep_dataset/ILSVRC2012_val_00016920.bin 224 224 +4084 ./prep_dataset/ILSVRC2012_val_00044619.bin 224 224 +4085 ./prep_dataset/ILSVRC2012_val_00001567.bin 224 224 +4086 ./prep_dataset/ILSVRC2012_val_00018737.bin 224 224 +4087 ./prep_dataset/ILSVRC2012_val_00003357.bin 224 224 +4088 ./prep_dataset/ILSVRC2012_val_00014839.bin 224 224 +4089 ./prep_dataset/ILSVRC2012_val_00002272.bin 224 224 +4090 ./prep_dataset/ILSVRC2012_val_00025339.bin 224 224 +4091 ./prep_dataset/ILSVRC2012_val_00015482.bin 224 224 +4092 ./prep_dataset/ILSVRC2012_val_00029301.bin 224 224 +4093 ./prep_dataset/ILSVRC2012_val_00025488.bin 224 224 +4094 ./prep_dataset/ILSVRC2012_val_00001365.bin 224 224 +4095 ./prep_dataset/ILSVRC2012_val_00040215.bin 224 224 +4096 ./prep_dataset/ILSVRC2012_val_00012984.bin 224 224 +4097 ./prep_dataset/ILSVRC2012_val_00023331.bin 224 224 +4098 ./prep_dataset/ILSVRC2012_val_00041846.bin 224 224 +4099 ./prep_dataset/ILSVRC2012_val_00002658.bin 224 224 +4100 ./prep_dataset/ILSVRC2012_val_00021886.bin 224 224 +4101 ./prep_dataset/ILSVRC2012_val_00008246.bin 224 224 +4102 ./prep_dataset/ILSVRC2012_val_00028768.bin 224 224 +4103 ./prep_dataset/ILSVRC2012_val_00015367.bin 224 224 +4104 ./prep_dataset/ILSVRC2012_val_00009650.bin 224 224 +4105 ./prep_dataset/ILSVRC2012_val_00045048.bin 224 224 +4106 ./prep_dataset/ILSVRC2012_val_00000782.bin 224 224 +4107 ./prep_dataset/ILSVRC2012_val_00016984.bin 224 224 +4108 ./prep_dataset/ILSVRC2012_val_00007100.bin 224 224 +4109 ./prep_dataset/ILSVRC2012_val_00000614.bin 224 224 +4110 ./prep_dataset/ILSVRC2012_val_00039905.bin 224 224 +4111 ./prep_dataset/ILSVRC2012_val_00031802.bin 224 224 +4112 ./prep_dataset/ILSVRC2012_val_00041279.bin 224 224 +4113 ./prep_dataset/ILSVRC2012_val_00047091.bin 224 224 +4114 ./prep_dataset/ILSVRC2012_val_00041152.bin 224 224 +4115 ./prep_dataset/ILSVRC2012_val_00047291.bin 224 224 +4116 ./prep_dataset/ILSVRC2012_val_00027289.bin 224 224 +4117 ./prep_dataset/ILSVRC2012_val_00010200.bin 224 224 +4118 ./prep_dataset/ILSVRC2012_val_00049002.bin 224 224 +4119 ./prep_dataset/ILSVRC2012_val_00048110.bin 224 224 +4120 ./prep_dataset/ILSVRC2012_val_00005327.bin 224 224 +4121 ./prep_dataset/ILSVRC2012_val_00045749.bin 224 224 +4122 ./prep_dataset/ILSVRC2012_val_00037633.bin 224 224 +4123 ./prep_dataset/ILSVRC2012_val_00000895.bin 224 224 +4124 ./prep_dataset/ILSVRC2012_val_00018132.bin 224 224 +4125 ./prep_dataset/ILSVRC2012_val_00035590.bin 224 224 +4126 ./prep_dataset/ILSVRC2012_val_00001234.bin 224 224 +4127 ./prep_dataset/ILSVRC2012_val_00049298.bin 224 224 +4128 ./prep_dataset/ILSVRC2012_val_00048407.bin 224 224 +4129 ./prep_dataset/ILSVRC2012_val_00028759.bin 224 224 +4130 ./prep_dataset/ILSVRC2012_val_00033235.bin 224 224 +4131 ./prep_dataset/ILSVRC2012_val_00017998.bin 224 224 +4132 ./prep_dataset/ILSVRC2012_val_00013459.bin 224 224 +4133 ./prep_dataset/ILSVRC2012_val_00044577.bin 224 224 +4134 ./prep_dataset/ILSVRC2012_val_00033879.bin 224 224 +4135 ./prep_dataset/ILSVRC2012_val_00026208.bin 224 224 +4136 ./prep_dataset/ILSVRC2012_val_00045969.bin 224 224 +4137 ./prep_dataset/ILSVRC2012_val_00002474.bin 224 224 +4138 ./prep_dataset/ILSVRC2012_val_00026717.bin 224 224 +4139 ./prep_dataset/ILSVRC2012_val_00036579.bin 224 224 +4140 ./prep_dataset/ILSVRC2012_val_00037972.bin 224 224 +4141 ./prep_dataset/ILSVRC2012_val_00000556.bin 224 224 +4142 ./prep_dataset/ILSVRC2012_val_00045701.bin 224 224 +4143 ./prep_dataset/ILSVRC2012_val_00002865.bin 224 224 +4144 ./prep_dataset/ILSVRC2012_val_00023526.bin 224 224 +4145 ./prep_dataset/ILSVRC2012_val_00028452.bin 224 224 +4146 ./prep_dataset/ILSVRC2012_val_00030676.bin 224 224 +4147 ./prep_dataset/ILSVRC2012_val_00043462.bin 224 224 +4148 ./prep_dataset/ILSVRC2012_val_00013289.bin 224 224 +4149 ./prep_dataset/ILSVRC2012_val_00030575.bin 224 224 +4150 ./prep_dataset/ILSVRC2012_val_00037285.bin 224 224 +4151 ./prep_dataset/ILSVRC2012_val_00028543.bin 224 224 +4152 ./prep_dataset/ILSVRC2012_val_00048009.bin 224 224 +4153 ./prep_dataset/ILSVRC2012_val_00018672.bin 224 224 +4154 ./prep_dataset/ILSVRC2012_val_00026212.bin 224 224 +4155 ./prep_dataset/ILSVRC2012_val_00024988.bin 224 224 +4156 ./prep_dataset/ILSVRC2012_val_00040522.bin 224 224 +4157 ./prep_dataset/ILSVRC2012_val_00022112.bin 224 224 +4158 ./prep_dataset/ILSVRC2012_val_00008952.bin 224 224 +4159 ./prep_dataset/ILSVRC2012_val_00004874.bin 224 224 +4160 ./prep_dataset/ILSVRC2012_val_00015098.bin 224 224 +4161 ./prep_dataset/ILSVRC2012_val_00048438.bin 224 224 +4162 ./prep_dataset/ILSVRC2012_val_00019269.bin 224 224 +4163 ./prep_dataset/ILSVRC2012_val_00045266.bin 224 224 +4164 ./prep_dataset/ILSVRC2012_val_00013392.bin 224 224 +4165 ./prep_dataset/ILSVRC2012_val_00001852.bin 224 224 +4166 ./prep_dataset/ILSVRC2012_val_00010142.bin 224 224 +4167 ./prep_dataset/ILSVRC2012_val_00046010.bin 224 224 +4168 ./prep_dataset/ILSVRC2012_val_00005805.bin 224 224 +4169 ./prep_dataset/ILSVRC2012_val_00026745.bin 224 224 +4170 ./prep_dataset/ILSVRC2012_val_00005852.bin 224 224 +4171 ./prep_dataset/ILSVRC2012_val_00012311.bin 224 224 +4172 ./prep_dataset/ILSVRC2012_val_00044300.bin 224 224 +4173 ./prep_dataset/ILSVRC2012_val_00044673.bin 224 224 +4174 ./prep_dataset/ILSVRC2012_val_00009575.bin 224 224 +4175 ./prep_dataset/ILSVRC2012_val_00022911.bin 224 224 +4176 ./prep_dataset/ILSVRC2012_val_00009199.bin 224 224 +4177 ./prep_dataset/ILSVRC2012_val_00001347.bin 224 224 +4178 ./prep_dataset/ILSVRC2012_val_00015375.bin 224 224 +4179 ./prep_dataset/ILSVRC2012_val_00024965.bin 224 224 +4180 ./prep_dataset/ILSVRC2012_val_00024633.bin 224 224 +4181 ./prep_dataset/ILSVRC2012_val_00029735.bin 224 224 +4182 ./prep_dataset/ILSVRC2012_val_00015190.bin 224 224 +4183 ./prep_dataset/ILSVRC2012_val_00016876.bin 224 224 +4184 ./prep_dataset/ILSVRC2012_val_00035738.bin 224 224 +4185 ./prep_dataset/ILSVRC2012_val_00003753.bin 224 224 +4186 ./prep_dataset/ILSVRC2012_val_00041134.bin 224 224 +4187 ./prep_dataset/ILSVRC2012_val_00028419.bin 224 224 +4188 ./prep_dataset/ILSVRC2012_val_00043105.bin 224 224 +4189 ./prep_dataset/ILSVRC2012_val_00022102.bin 224 224 +4190 ./prep_dataset/ILSVRC2012_val_00027036.bin 224 224 +4191 ./prep_dataset/ILSVRC2012_val_00027831.bin 224 224 +4192 ./prep_dataset/ILSVRC2012_val_00021050.bin 224 224 +4193 ./prep_dataset/ILSVRC2012_val_00015744.bin 224 224 +4194 ./prep_dataset/ILSVRC2012_val_00013893.bin 224 224 +4195 ./prep_dataset/ILSVRC2012_val_00034576.bin 224 224 +4196 ./prep_dataset/ILSVRC2012_val_00002186.bin 224 224 +4197 ./prep_dataset/ILSVRC2012_val_00008750.bin 224 224 +4198 ./prep_dataset/ILSVRC2012_val_00021319.bin 224 224 +4199 ./prep_dataset/ILSVRC2012_val_00004021.bin 224 224 +4200 ./prep_dataset/ILSVRC2012_val_00024204.bin 224 224 +4201 ./prep_dataset/ILSVRC2012_val_00014630.bin 224 224 +4202 ./prep_dataset/ILSVRC2012_val_00024118.bin 224 224 +4203 ./prep_dataset/ILSVRC2012_val_00031193.bin 224 224 +4204 ./prep_dataset/ILSVRC2012_val_00042231.bin 224 224 +4205 ./prep_dataset/ILSVRC2012_val_00020471.bin 224 224 +4206 ./prep_dataset/ILSVRC2012_val_00030193.bin 224 224 +4207 ./prep_dataset/ILSVRC2012_val_00007990.bin 224 224 +4208 ./prep_dataset/ILSVRC2012_val_00003634.bin 224 224 +4209 ./prep_dataset/ILSVRC2012_val_00008564.bin 224 224 +4210 ./prep_dataset/ILSVRC2012_val_00007971.bin 224 224 +4211 ./prep_dataset/ILSVRC2012_val_00032594.bin 224 224 +4212 ./prep_dataset/ILSVRC2012_val_00014463.bin 224 224 +4213 ./prep_dataset/ILSVRC2012_val_00002810.bin 224 224 +4214 ./prep_dataset/ILSVRC2012_val_00040800.bin 224 224 +4215 ./prep_dataset/ILSVRC2012_val_00011776.bin 224 224 +4216 ./prep_dataset/ILSVRC2012_val_00008231.bin 224 224 +4217 ./prep_dataset/ILSVRC2012_val_00042620.bin 224 224 +4218 ./prep_dataset/ILSVRC2012_val_00038017.bin 224 224 +4219 ./prep_dataset/ILSVRC2012_val_00036131.bin 224 224 +4220 ./prep_dataset/ILSVRC2012_val_00009623.bin 224 224 +4221 ./prep_dataset/ILSVRC2012_val_00043686.bin 224 224 +4222 ./prep_dataset/ILSVRC2012_val_00002544.bin 224 224 +4223 ./prep_dataset/ILSVRC2012_val_00047021.bin 224 224 +4224 ./prep_dataset/ILSVRC2012_val_00035151.bin 224 224 +4225 ./prep_dataset/ILSVRC2012_val_00006606.bin 224 224 +4226 ./prep_dataset/ILSVRC2012_val_00035768.bin 224 224 +4227 ./prep_dataset/ILSVRC2012_val_00018274.bin 224 224 +4228 ./prep_dataset/ILSVRC2012_val_00033199.bin 224 224 +4229 ./prep_dataset/ILSVRC2012_val_00033000.bin 224 224 +4230 ./prep_dataset/ILSVRC2012_val_00034428.bin 224 224 +4231 ./prep_dataset/ILSVRC2012_val_00034253.bin 224 224 +4232 ./prep_dataset/ILSVRC2012_val_00024692.bin 224 224 +4233 ./prep_dataset/ILSVRC2012_val_00039559.bin 224 224 +4234 ./prep_dataset/ILSVRC2012_val_00021214.bin 224 224 +4235 ./prep_dataset/ILSVRC2012_val_00002028.bin 224 224 +4236 ./prep_dataset/ILSVRC2012_val_00045111.bin 224 224 +4237 ./prep_dataset/ILSVRC2012_val_00011977.bin 224 224 +4238 ./prep_dataset/ILSVRC2012_val_00044880.bin 224 224 +4239 ./prep_dataset/ILSVRC2012_val_00035113.bin 224 224 +4240 ./prep_dataset/ILSVRC2012_val_00005037.bin 224 224 +4241 ./prep_dataset/ILSVRC2012_val_00045020.bin 224 224 +4242 ./prep_dataset/ILSVRC2012_val_00018072.bin 224 224 +4243 ./prep_dataset/ILSVRC2012_val_00012314.bin 224 224 +4244 ./prep_dataset/ILSVRC2012_val_00028579.bin 224 224 +4245 ./prep_dataset/ILSVRC2012_val_00039592.bin 224 224 +4246 ./prep_dataset/ILSVRC2012_val_00041673.bin 224 224 +4247 ./prep_dataset/ILSVRC2012_val_00024739.bin 224 224 +4248 ./prep_dataset/ILSVRC2012_val_00039792.bin 224 224 +4249 ./prep_dataset/ILSVRC2012_val_00023819.bin 224 224 +4250 ./prep_dataset/ILSVRC2012_val_00023297.bin 224 224 +4251 ./prep_dataset/ILSVRC2012_val_00040973.bin 224 224 +4252 ./prep_dataset/ILSVRC2012_val_00045781.bin 224 224 +4253 ./prep_dataset/ILSVRC2012_val_00019696.bin 224 224 +4254 ./prep_dataset/ILSVRC2012_val_00006489.bin 224 224 +4255 ./prep_dataset/ILSVRC2012_val_00043413.bin 224 224 +4256 ./prep_dataset/ILSVRC2012_val_00021513.bin 224 224 +4257 ./prep_dataset/ILSVRC2012_val_00021607.bin 224 224 +4258 ./prep_dataset/ILSVRC2012_val_00048987.bin 224 224 +4259 ./prep_dataset/ILSVRC2012_val_00019324.bin 224 224 +4260 ./prep_dataset/ILSVRC2012_val_00049771.bin 224 224 +4261 ./prep_dataset/ILSVRC2012_val_00010639.bin 224 224 +4262 ./prep_dataset/ILSVRC2012_val_00046155.bin 224 224 +4263 ./prep_dataset/ILSVRC2012_val_00021660.bin 224 224 +4264 ./prep_dataset/ILSVRC2012_val_00030993.bin 224 224 +4265 ./prep_dataset/ILSVRC2012_val_00018817.bin 224 224 +4266 ./prep_dataset/ILSVRC2012_val_00000924.bin 224 224 +4267 ./prep_dataset/ILSVRC2012_val_00005909.bin 224 224 +4268 ./prep_dataset/ILSVRC2012_val_00008985.bin 224 224 +4269 ./prep_dataset/ILSVRC2012_val_00024537.bin 224 224 +4270 ./prep_dataset/ILSVRC2012_val_00017628.bin 224 224 +4271 ./prep_dataset/ILSVRC2012_val_00007908.bin 224 224 +4272 ./prep_dataset/ILSVRC2012_val_00015544.bin 224 224 +4273 ./prep_dataset/ILSVRC2012_val_00000706.bin 224 224 +4274 ./prep_dataset/ILSVRC2012_val_00037536.bin 224 224 +4275 ./prep_dataset/ILSVRC2012_val_00023823.bin 224 224 +4276 ./prep_dataset/ILSVRC2012_val_00002501.bin 224 224 +4277 ./prep_dataset/ILSVRC2012_val_00013550.bin 224 224 +4278 ./prep_dataset/ILSVRC2012_val_00019008.bin 224 224 +4279 ./prep_dataset/ILSVRC2012_val_00041277.bin 224 224 +4280 ./prep_dataset/ILSVRC2012_val_00036711.bin 224 224 +4281 ./prep_dataset/ILSVRC2012_val_00026585.bin 224 224 +4282 ./prep_dataset/ILSVRC2012_val_00022214.bin 224 224 +4283 ./prep_dataset/ILSVRC2012_val_00022893.bin 224 224 +4284 ./prep_dataset/ILSVRC2012_val_00009538.bin 224 224 +4285 ./prep_dataset/ILSVRC2012_val_00027279.bin 224 224 +4286 ./prep_dataset/ILSVRC2012_val_00003837.bin 224 224 +4287 ./prep_dataset/ILSVRC2012_val_00044616.bin 224 224 +4288 ./prep_dataset/ILSVRC2012_val_00024478.bin 224 224 +4289 ./prep_dataset/ILSVRC2012_val_00021864.bin 224 224 +4290 ./prep_dataset/ILSVRC2012_val_00039846.bin 224 224 +4291 ./prep_dataset/ILSVRC2012_val_00016714.bin 224 224 +4292 ./prep_dataset/ILSVRC2012_val_00006943.bin 224 224 +4293 ./prep_dataset/ILSVRC2012_val_00011533.bin 224 224 +4294 ./prep_dataset/ILSVRC2012_val_00037471.bin 224 224 +4295 ./prep_dataset/ILSVRC2012_val_00014985.bin 224 224 +4296 ./prep_dataset/ILSVRC2012_val_00016126.bin 224 224 +4297 ./prep_dataset/ILSVRC2012_val_00036561.bin 224 224 +4298 ./prep_dataset/ILSVRC2012_val_00049112.bin 224 224 +4299 ./prep_dataset/ILSVRC2012_val_00034965.bin 224 224 +4300 ./prep_dataset/ILSVRC2012_val_00035023.bin 224 224 +4301 ./prep_dataset/ILSVRC2012_val_00041221.bin 224 224 +4302 ./prep_dataset/ILSVRC2012_val_00040487.bin 224 224 +4303 ./prep_dataset/ILSVRC2012_val_00005080.bin 224 224 +4304 ./prep_dataset/ILSVRC2012_val_00002726.bin 224 224 +4305 ./prep_dataset/ILSVRC2012_val_00004423.bin 224 224 +4306 ./prep_dataset/ILSVRC2012_val_00017087.bin 224 224 +4307 ./prep_dataset/ILSVRC2012_val_00035902.bin 224 224 +4308 ./prep_dataset/ILSVRC2012_val_00025722.bin 224 224 +4309 ./prep_dataset/ILSVRC2012_val_00005015.bin 224 224 +4310 ./prep_dataset/ILSVRC2012_val_00026909.bin 224 224 +4311 ./prep_dataset/ILSVRC2012_val_00031575.bin 224 224 +4312 ./prep_dataset/ILSVRC2012_val_00030815.bin 224 224 +4313 ./prep_dataset/ILSVRC2012_val_00037108.bin 224 224 +4314 ./prep_dataset/ILSVRC2012_val_00012987.bin 224 224 +4315 ./prep_dataset/ILSVRC2012_val_00005115.bin 224 224 +4316 ./prep_dataset/ILSVRC2012_val_00009089.bin 224 224 +4317 ./prep_dataset/ILSVRC2012_val_00007375.bin 224 224 +4318 ./prep_dataset/ILSVRC2012_val_00037867.bin 224 224 +4319 ./prep_dataset/ILSVRC2012_val_00014567.bin 224 224 +4320 ./prep_dataset/ILSVRC2012_val_00025217.bin 224 224 +4321 ./prep_dataset/ILSVRC2012_val_00008805.bin 224 224 +4322 ./prep_dataset/ILSVRC2012_val_00027359.bin 224 224 +4323 ./prep_dataset/ILSVRC2012_val_00043096.bin 224 224 +4324 ./prep_dataset/ILSVRC2012_val_00016513.bin 224 224 +4325 ./prep_dataset/ILSVRC2012_val_00001388.bin 224 224 +4326 ./prep_dataset/ILSVRC2012_val_00028724.bin 224 224 +4327 ./prep_dataset/ILSVRC2012_val_00029796.bin 224 224 +4328 ./prep_dataset/ILSVRC2012_val_00018232.bin 224 224 +4329 ./prep_dataset/ILSVRC2012_val_00041993.bin 224 224 +4330 ./prep_dataset/ILSVRC2012_val_00009670.bin 224 224 +4331 ./prep_dataset/ILSVRC2012_val_00023843.bin 224 224 +4332 ./prep_dataset/ILSVRC2012_val_00030277.bin 224 224 +4333 ./prep_dataset/ILSVRC2012_val_00026654.bin 224 224 +4334 ./prep_dataset/ILSVRC2012_val_00033678.bin 224 224 +4335 ./prep_dataset/ILSVRC2012_val_00023546.bin 224 224 +4336 ./prep_dataset/ILSVRC2012_val_00045519.bin 224 224 +4337 ./prep_dataset/ILSVRC2012_val_00032041.bin 224 224 +4338 ./prep_dataset/ILSVRC2012_val_00014329.bin 224 224 +4339 ./prep_dataset/ILSVRC2012_val_00049841.bin 224 224 +4340 ./prep_dataset/ILSVRC2012_val_00004792.bin 224 224 +4341 ./prep_dataset/ILSVRC2012_val_00016230.bin 224 224 +4342 ./prep_dataset/ILSVRC2012_val_00022887.bin 224 224 +4343 ./prep_dataset/ILSVRC2012_val_00009772.bin 224 224 +4344 ./prep_dataset/ILSVRC2012_val_00031400.bin 224 224 +4345 ./prep_dataset/ILSVRC2012_val_00029520.bin 224 224 +4346 ./prep_dataset/ILSVRC2012_val_00000325.bin 224 224 +4347 ./prep_dataset/ILSVRC2012_val_00012866.bin 224 224 +4348 ./prep_dataset/ILSVRC2012_val_00045846.bin 224 224 +4349 ./prep_dataset/ILSVRC2012_val_00008262.bin 224 224 +4350 ./prep_dataset/ILSVRC2012_val_00046973.bin 224 224 +4351 ./prep_dataset/ILSVRC2012_val_00013238.bin 224 224 +4352 ./prep_dataset/ILSVRC2012_val_00035610.bin 224 224 +4353 ./prep_dataset/ILSVRC2012_val_00023829.bin 224 224 +4354 ./prep_dataset/ILSVRC2012_val_00033185.bin 224 224 +4355 ./prep_dataset/ILSVRC2012_val_00019524.bin 224 224 +4356 ./prep_dataset/ILSVRC2012_val_00008939.bin 224 224 +4357 ./prep_dataset/ILSVRC2012_val_00010565.bin 224 224 +4358 ./prep_dataset/ILSVRC2012_val_00028312.bin 224 224 +4359 ./prep_dataset/ILSVRC2012_val_00028770.bin 224 224 +4360 ./prep_dataset/ILSVRC2012_val_00030487.bin 224 224 +4361 ./prep_dataset/ILSVRC2012_val_00028430.bin 224 224 +4362 ./prep_dataset/ILSVRC2012_val_00023130.bin 224 224 +4363 ./prep_dataset/ILSVRC2012_val_00036288.bin 224 224 +4364 ./prep_dataset/ILSVRC2012_val_00022000.bin 224 224 +4365 ./prep_dataset/ILSVRC2012_val_00048495.bin 224 224 +4366 ./prep_dataset/ILSVRC2012_val_00019873.bin 224 224 +4367 ./prep_dataset/ILSVRC2012_val_00030678.bin 224 224 +4368 ./prep_dataset/ILSVRC2012_val_00001322.bin 224 224 +4369 ./prep_dataset/ILSVRC2012_val_00017436.bin 224 224 +4370 ./prep_dataset/ILSVRC2012_val_00001962.bin 224 224 +4371 ./prep_dataset/ILSVRC2012_val_00013209.bin 224 224 +4372 ./prep_dataset/ILSVRC2012_val_00014764.bin 224 224 +4373 ./prep_dataset/ILSVRC2012_val_00002194.bin 224 224 +4374 ./prep_dataset/ILSVRC2012_val_00044614.bin 224 224 +4375 ./prep_dataset/ILSVRC2012_val_00038091.bin 224 224 +4376 ./prep_dataset/ILSVRC2012_val_00036563.bin 224 224 +4377 ./prep_dataset/ILSVRC2012_val_00001536.bin 224 224 +4378 ./prep_dataset/ILSVRC2012_val_00047295.bin 224 224 +4379 ./prep_dataset/ILSVRC2012_val_00016183.bin 224 224 +4380 ./prep_dataset/ILSVRC2012_val_00001773.bin 224 224 +4381 ./prep_dataset/ILSVRC2012_val_00013751.bin 224 224 +4382 ./prep_dataset/ILSVRC2012_val_00015229.bin 224 224 +4383 ./prep_dataset/ILSVRC2012_val_00045585.bin 224 224 +4384 ./prep_dataset/ILSVRC2012_val_00024424.bin 224 224 +4385 ./prep_dataset/ILSVRC2012_val_00032821.bin 224 224 +4386 ./prep_dataset/ILSVRC2012_val_00008139.bin 224 224 +4387 ./prep_dataset/ILSVRC2012_val_00037403.bin 224 224 +4388 ./prep_dataset/ILSVRC2012_val_00009368.bin 224 224 +4389 ./prep_dataset/ILSVRC2012_val_00020827.bin 224 224 +4390 ./prep_dataset/ILSVRC2012_val_00031143.bin 224 224 +4391 ./prep_dataset/ILSVRC2012_val_00046902.bin 224 224 +4392 ./prep_dataset/ILSVRC2012_val_00048354.bin 224 224 +4393 ./prep_dataset/ILSVRC2012_val_00034671.bin 224 224 +4394 ./prep_dataset/ILSVRC2012_val_00019362.bin 224 224 +4395 ./prep_dataset/ILSVRC2012_val_00003061.bin 224 224 +4396 ./prep_dataset/ILSVRC2012_val_00005488.bin 224 224 +4397 ./prep_dataset/ILSVRC2012_val_00044059.bin 224 224 +4398 ./prep_dataset/ILSVRC2012_val_00007080.bin 224 224 +4399 ./prep_dataset/ILSVRC2012_val_00049702.bin 224 224 +4400 ./prep_dataset/ILSVRC2012_val_00026115.bin 224 224 +4401 ./prep_dataset/ILSVRC2012_val_00017702.bin 224 224 +4402 ./prep_dataset/ILSVRC2012_val_00042765.bin 224 224 +4403 ./prep_dataset/ILSVRC2012_val_00025372.bin 224 224 +4404 ./prep_dataset/ILSVRC2012_val_00016998.bin 224 224 +4405 ./prep_dataset/ILSVRC2012_val_00049769.bin 224 224 +4406 ./prep_dataset/ILSVRC2012_val_00020760.bin 224 224 +4407 ./prep_dataset/ILSVRC2012_val_00049274.bin 224 224 +4408 ./prep_dataset/ILSVRC2012_val_00038499.bin 224 224 +4409 ./prep_dataset/ILSVRC2012_val_00006811.bin 224 224 +4410 ./prep_dataset/ILSVRC2012_val_00032798.bin 224 224 +4411 ./prep_dataset/ILSVRC2012_val_00017799.bin 224 224 +4412 ./prep_dataset/ILSVRC2012_val_00004524.bin 224 224 +4413 ./prep_dataset/ILSVRC2012_val_00024495.bin 224 224 +4414 ./prep_dataset/ILSVRC2012_val_00006289.bin 224 224 +4415 ./prep_dataset/ILSVRC2012_val_00012844.bin 224 224 +4416 ./prep_dataset/ILSVRC2012_val_00041036.bin 224 224 +4417 ./prep_dataset/ILSVRC2012_val_00005036.bin 224 224 +4418 ./prep_dataset/ILSVRC2012_val_00049544.bin 224 224 +4419 ./prep_dataset/ILSVRC2012_val_00021926.bin 224 224 +4420 ./prep_dataset/ILSVRC2012_val_00032734.bin 224 224 +4421 ./prep_dataset/ILSVRC2012_val_00029097.bin 224 224 +4422 ./prep_dataset/ILSVRC2012_val_00049318.bin 224 224 +4423 ./prep_dataset/ILSVRC2012_val_00031619.bin 224 224 +4424 ./prep_dataset/ILSVRC2012_val_00001872.bin 224 224 +4425 ./prep_dataset/ILSVRC2012_val_00042461.bin 224 224 +4426 ./prep_dataset/ILSVRC2012_val_00022262.bin 224 224 +4427 ./prep_dataset/ILSVRC2012_val_00037307.bin 224 224 +4428 ./prep_dataset/ILSVRC2012_val_00025498.bin 224 224 +4429 ./prep_dataset/ILSVRC2012_val_00029431.bin 224 224 +4430 ./prep_dataset/ILSVRC2012_val_00037381.bin 224 224 +4431 ./prep_dataset/ILSVRC2012_val_00021900.bin 224 224 +4432 ./prep_dataset/ILSVRC2012_val_00036807.bin 224 224 +4433 ./prep_dataset/ILSVRC2012_val_00005769.bin 224 224 +4434 ./prep_dataset/ILSVRC2012_val_00022675.bin 224 224 +4435 ./prep_dataset/ILSVRC2012_val_00041301.bin 224 224 +4436 ./prep_dataset/ILSVRC2012_val_00027413.bin 224 224 +4437 ./prep_dataset/ILSVRC2012_val_00021930.bin 224 224 +4438 ./prep_dataset/ILSVRC2012_val_00035245.bin 224 224 +4439 ./prep_dataset/ILSVRC2012_val_00046139.bin 224 224 +4440 ./prep_dataset/ILSVRC2012_val_00019951.bin 224 224 +4441 ./prep_dataset/ILSVRC2012_val_00027227.bin 224 224 +4442 ./prep_dataset/ILSVRC2012_val_00049782.bin 224 224 +4443 ./prep_dataset/ILSVRC2012_val_00024276.bin 224 224 +4444 ./prep_dataset/ILSVRC2012_val_00009778.bin 224 224 +4445 ./prep_dataset/ILSVRC2012_val_00026910.bin 224 224 +4446 ./prep_dataset/ILSVRC2012_val_00001282.bin 224 224 +4447 ./prep_dataset/ILSVRC2012_val_00013041.bin 224 224 +4448 ./prep_dataset/ILSVRC2012_val_00020885.bin 224 224 +4449 ./prep_dataset/ILSVRC2012_val_00002483.bin 224 224 +4450 ./prep_dataset/ILSVRC2012_val_00046310.bin 224 224 +4451 ./prep_dataset/ILSVRC2012_val_00040896.bin 224 224 +4452 ./prep_dataset/ILSVRC2012_val_00048391.bin 224 224 +4453 ./prep_dataset/ILSVRC2012_val_00022445.bin 224 224 +4454 ./prep_dataset/ILSVRC2012_val_00021542.bin 224 224 +4455 ./prep_dataset/ILSVRC2012_val_00021365.bin 224 224 +4456 ./prep_dataset/ILSVRC2012_val_00004485.bin 224 224 +4457 ./prep_dataset/ILSVRC2012_val_00010433.bin 224 224 +4458 ./prep_dataset/ILSVRC2012_val_00014546.bin 224 224 +4459 ./prep_dataset/ILSVRC2012_val_00030272.bin 224 224 +4460 ./prep_dataset/ILSVRC2012_val_00003148.bin 224 224 +4461 ./prep_dataset/ILSVRC2012_val_00037128.bin 224 224 +4462 ./prep_dataset/ILSVRC2012_val_00040985.bin 224 224 +4463 ./prep_dataset/ILSVRC2012_val_00046486.bin 224 224 +4464 ./prep_dataset/ILSVRC2012_val_00036876.bin 224 224 +4465 ./prep_dataset/ILSVRC2012_val_00009750.bin 224 224 +4466 ./prep_dataset/ILSVRC2012_val_00008082.bin 224 224 +4467 ./prep_dataset/ILSVRC2012_val_00028109.bin 224 224 +4468 ./prep_dataset/ILSVRC2012_val_00012763.bin 224 224 +4469 ./prep_dataset/ILSVRC2012_val_00002774.bin 224 224 +4470 ./prep_dataset/ILSVRC2012_val_00016769.bin 224 224 +4471 ./prep_dataset/ILSVRC2012_val_00027859.bin 224 224 +4472 ./prep_dataset/ILSVRC2012_val_00034927.bin 224 224 +4473 ./prep_dataset/ILSVRC2012_val_00040260.bin 224 224 +4474 ./prep_dataset/ILSVRC2012_val_00029106.bin 224 224 +4475 ./prep_dataset/ILSVRC2012_val_00022924.bin 224 224 +4476 ./prep_dataset/ILSVRC2012_val_00021373.bin 224 224 +4477 ./prep_dataset/ILSVRC2012_val_00030773.bin 224 224 +4478 ./prep_dataset/ILSVRC2012_val_00023915.bin 224 224 +4479 ./prep_dataset/ILSVRC2012_val_00007921.bin 224 224 +4480 ./prep_dataset/ILSVRC2012_val_00044010.bin 224 224 +4481 ./prep_dataset/ILSVRC2012_val_00048304.bin 224 224 +4482 ./prep_dataset/ILSVRC2012_val_00013353.bin 224 224 +4483 ./prep_dataset/ILSVRC2012_val_00048650.bin 224 224 +4484 ./prep_dataset/ILSVRC2012_val_00003464.bin 224 224 +4485 ./prep_dataset/ILSVRC2012_val_00034542.bin 224 224 +4486 ./prep_dataset/ILSVRC2012_val_00028190.bin 224 224 +4487 ./prep_dataset/ILSVRC2012_val_00032515.bin 224 224 +4488 ./prep_dataset/ILSVRC2012_val_00032354.bin 224 224 +4489 ./prep_dataset/ILSVRC2012_val_00010313.bin 224 224 +4490 ./prep_dataset/ILSVRC2012_val_00002924.bin 224 224 +4491 ./prep_dataset/ILSVRC2012_val_00044845.bin 224 224 +4492 ./prep_dataset/ILSVRC2012_val_00035929.bin 224 224 +4493 ./prep_dataset/ILSVRC2012_val_00033946.bin 224 224 +4494 ./prep_dataset/ILSVRC2012_val_00018653.bin 224 224 +4495 ./prep_dataset/ILSVRC2012_val_00000374.bin 224 224 +4496 ./prep_dataset/ILSVRC2012_val_00011065.bin 224 224 +4497 ./prep_dataset/ILSVRC2012_val_00005071.bin 224 224 +4498 ./prep_dataset/ILSVRC2012_val_00035114.bin 224 224 +4499 ./prep_dataset/ILSVRC2012_val_00034891.bin 224 224 +4500 ./prep_dataset/ILSVRC2012_val_00026955.bin 224 224 +4501 ./prep_dataset/ILSVRC2012_val_00002627.bin 224 224 +4502 ./prep_dataset/ILSVRC2012_val_00015399.bin 224 224 +4503 ./prep_dataset/ILSVRC2012_val_00001130.bin 224 224 +4504 ./prep_dataset/ILSVRC2012_val_00038872.bin 224 224 +4505 ./prep_dataset/ILSVRC2012_val_00030245.bin 224 224 +4506 ./prep_dataset/ILSVRC2012_val_00048389.bin 224 224 +4507 ./prep_dataset/ILSVRC2012_val_00035407.bin 224 224 +4508 ./prep_dataset/ILSVRC2012_val_00032318.bin 224 224 +4509 ./prep_dataset/ILSVRC2012_val_00026520.bin 224 224 +4510 ./prep_dataset/ILSVRC2012_val_00048533.bin 224 224 +4511 ./prep_dataset/ILSVRC2012_val_00035397.bin 224 224 +4512 ./prep_dataset/ILSVRC2012_val_00035104.bin 224 224 +4513 ./prep_dataset/ILSVRC2012_val_00017314.bin 224 224 +4514 ./prep_dataset/ILSVRC2012_val_00033960.bin 224 224 +4515 ./prep_dataset/ILSVRC2012_val_00046021.bin 224 224 +4516 ./prep_dataset/ILSVRC2012_val_00007633.bin 224 224 +4517 ./prep_dataset/ILSVRC2012_val_00019105.bin 224 224 +4518 ./prep_dataset/ILSVRC2012_val_00002605.bin 224 224 +4519 ./prep_dataset/ILSVRC2012_val_00029890.bin 224 224 +4520 ./prep_dataset/ILSVRC2012_val_00035492.bin 224 224 +4521 ./prep_dataset/ILSVRC2012_val_00017411.bin 224 224 +4522 ./prep_dataset/ILSVRC2012_val_00019917.bin 224 224 +4523 ./prep_dataset/ILSVRC2012_val_00002613.bin 224 224 +4524 ./prep_dataset/ILSVRC2012_val_00004318.bin 224 224 +4525 ./prep_dataset/ILSVRC2012_val_00025649.bin 224 224 +4526 ./prep_dataset/ILSVRC2012_val_00039997.bin 224 224 +4527 ./prep_dataset/ILSVRC2012_val_00001319.bin 224 224 +4528 ./prep_dataset/ILSVRC2012_val_00044102.bin 224 224 +4529 ./prep_dataset/ILSVRC2012_val_00040111.bin 224 224 +4530 ./prep_dataset/ILSVRC2012_val_00046571.bin 224 224 +4531 ./prep_dataset/ILSVRC2012_val_00032763.bin 224 224 +4532 ./prep_dataset/ILSVRC2012_val_00011868.bin 224 224 +4533 ./prep_dataset/ILSVRC2012_val_00038717.bin 224 224 +4534 ./prep_dataset/ILSVRC2012_val_00032031.bin 224 224 +4535 ./prep_dataset/ILSVRC2012_val_00044388.bin 224 224 +4536 ./prep_dataset/ILSVRC2012_val_00005343.bin 224 224 +4537 ./prep_dataset/ILSVRC2012_val_00007019.bin 224 224 +4538 ./prep_dataset/ILSVRC2012_val_00004370.bin 224 224 +4539 ./prep_dataset/ILSVRC2012_val_00023631.bin 224 224 +4540 ./prep_dataset/ILSVRC2012_val_00020723.bin 224 224 +4541 ./prep_dataset/ILSVRC2012_val_00034517.bin 224 224 +4542 ./prep_dataset/ILSVRC2012_val_00028572.bin 224 224 +4543 ./prep_dataset/ILSVRC2012_val_00017588.bin 224 224 +4544 ./prep_dataset/ILSVRC2012_val_00038236.bin 224 224 +4545 ./prep_dataset/ILSVRC2012_val_00009494.bin 224 224 +4546 ./prep_dataset/ILSVRC2012_val_00047278.bin 224 224 +4547 ./prep_dataset/ILSVRC2012_val_00018917.bin 224 224 +4548 ./prep_dataset/ILSVRC2012_val_00002354.bin 224 224 +4549 ./prep_dataset/ILSVRC2012_val_00008174.bin 224 224 +4550 ./prep_dataset/ILSVRC2012_val_00044497.bin 224 224 +4551 ./prep_dataset/ILSVRC2012_val_00049777.bin 224 224 +4552 ./prep_dataset/ILSVRC2012_val_00011739.bin 224 224 +4553 ./prep_dataset/ILSVRC2012_val_00011150.bin 224 224 +4554 ./prep_dataset/ILSVRC2012_val_00046623.bin 224 224 +4555 ./prep_dataset/ILSVRC2012_val_00020903.bin 224 224 +4556 ./prep_dataset/ILSVRC2012_val_00036297.bin 224 224 +4557 ./prep_dataset/ILSVRC2012_val_00009884.bin 224 224 +4558 ./prep_dataset/ILSVRC2012_val_00004267.bin 224 224 +4559 ./prep_dataset/ILSVRC2012_val_00004553.bin 224 224 +4560 ./prep_dataset/ILSVRC2012_val_00032747.bin 224 224 +4561 ./prep_dataset/ILSVRC2012_val_00037727.bin 224 224 +4562 ./prep_dataset/ILSVRC2012_val_00016158.bin 224 224 +4563 ./prep_dataset/ILSVRC2012_val_00006879.bin 224 224 +4564 ./prep_dataset/ILSVRC2012_val_00043439.bin 224 224 +4565 ./prep_dataset/ILSVRC2012_val_00032603.bin 224 224 +4566 ./prep_dataset/ILSVRC2012_val_00001247.bin 224 224 +4567 ./prep_dataset/ILSVRC2012_val_00030598.bin 224 224 +4568 ./prep_dataset/ILSVRC2012_val_00048556.bin 224 224 +4569 ./prep_dataset/ILSVRC2012_val_00011014.bin 224 224 +4570 ./prep_dataset/ILSVRC2012_val_00005065.bin 224 224 +4571 ./prep_dataset/ILSVRC2012_val_00036324.bin 224 224 +4572 ./prep_dataset/ILSVRC2012_val_00024607.bin 224 224 +4573 ./prep_dataset/ILSVRC2012_val_00021095.bin 224 224 +4574 ./prep_dataset/ILSVRC2012_val_00007389.bin 224 224 +4575 ./prep_dataset/ILSVRC2012_val_00022955.bin 224 224 +4576 ./prep_dataset/ILSVRC2012_val_00001862.bin 224 224 +4577 ./prep_dataset/ILSVRC2012_val_00045726.bin 224 224 +4578 ./prep_dataset/ILSVRC2012_val_00024426.bin 224 224 +4579 ./prep_dataset/ILSVRC2012_val_00001730.bin 224 224 +4580 ./prep_dataset/ILSVRC2012_val_00004996.bin 224 224 +4581 ./prep_dataset/ILSVRC2012_val_00012438.bin 224 224 +4582 ./prep_dataset/ILSVRC2012_val_00003983.bin 224 224 +4583 ./prep_dataset/ILSVRC2012_val_00032805.bin 224 224 +4584 ./prep_dataset/ILSVRC2012_val_00005744.bin 224 224 +4585 ./prep_dataset/ILSVRC2012_val_00001142.bin 224 224 +4586 ./prep_dataset/ILSVRC2012_val_00046407.bin 224 224 +4587 ./prep_dataset/ILSVRC2012_val_00042564.bin 224 224 +4588 ./prep_dataset/ILSVRC2012_val_00016823.bin 224 224 +4589 ./prep_dataset/ILSVRC2012_val_00033355.bin 224 224 +4590 ./prep_dataset/ILSVRC2012_val_00032800.bin 224 224 +4591 ./prep_dataset/ILSVRC2012_val_00021880.bin 224 224 +4592 ./prep_dataset/ILSVRC2012_val_00030818.bin 224 224 +4593 ./prep_dataset/ILSVRC2012_val_00016069.bin 224 224 +4594 ./prep_dataset/ILSVRC2012_val_00016682.bin 224 224 +4595 ./prep_dataset/ILSVRC2012_val_00008088.bin 224 224 +4596 ./prep_dataset/ILSVRC2012_val_00042660.bin 224 224 +4597 ./prep_dataset/ILSVRC2012_val_00046370.bin 224 224 +4598 ./prep_dataset/ILSVRC2012_val_00031838.bin 224 224 +4599 ./prep_dataset/ILSVRC2012_val_00011978.bin 224 224 +4600 ./prep_dataset/ILSVRC2012_val_00018905.bin 224 224 +4601 ./prep_dataset/ILSVRC2012_val_00041194.bin 224 224 +4602 ./prep_dataset/ILSVRC2012_val_00039386.bin 224 224 +4603 ./prep_dataset/ILSVRC2012_val_00026408.bin 224 224 +4604 ./prep_dataset/ILSVRC2012_val_00027782.bin 224 224 +4605 ./prep_dataset/ILSVRC2012_val_00005321.bin 224 224 +4606 ./prep_dataset/ILSVRC2012_val_00028295.bin 224 224 +4607 ./prep_dataset/ILSVRC2012_val_00033862.bin 224 224 +4608 ./prep_dataset/ILSVRC2012_val_00009498.bin 224 224 +4609 ./prep_dataset/ILSVRC2012_val_00006353.bin 224 224 +4610 ./prep_dataset/ILSVRC2012_val_00021527.bin 224 224 +4611 ./prep_dataset/ILSVRC2012_val_00043845.bin 224 224 +4612 ./prep_dataset/ILSVRC2012_val_00043668.bin 224 224 +4613 ./prep_dataset/ILSVRC2012_val_00012997.bin 224 224 +4614 ./prep_dataset/ILSVRC2012_val_00049948.bin 224 224 +4615 ./prep_dataset/ILSVRC2012_val_00011024.bin 224 224 +4616 ./prep_dataset/ILSVRC2012_val_00026550.bin 224 224 +4617 ./prep_dataset/ILSVRC2012_val_00024786.bin 224 224 +4618 ./prep_dataset/ILSVRC2012_val_00047005.bin 224 224 +4619 ./prep_dataset/ILSVRC2012_val_00047197.bin 224 224 +4620 ./prep_dataset/ILSVRC2012_val_00032435.bin 224 224 +4621 ./prep_dataset/ILSVRC2012_val_00044039.bin 224 224 +4622 ./prep_dataset/ILSVRC2012_val_00010606.bin 224 224 +4623 ./prep_dataset/ILSVRC2012_val_00014517.bin 224 224 +4624 ./prep_dataset/ILSVRC2012_val_00029524.bin 224 224 +4625 ./prep_dataset/ILSVRC2012_val_00004336.bin 224 224 +4626 ./prep_dataset/ILSVRC2012_val_00006521.bin 224 224 +4627 ./prep_dataset/ILSVRC2012_val_00041332.bin 224 224 +4628 ./prep_dataset/ILSVRC2012_val_00043233.bin 224 224 +4629 ./prep_dataset/ILSVRC2012_val_00018809.bin 224 224 +4630 ./prep_dataset/ILSVRC2012_val_00011312.bin 224 224 +4631 ./prep_dataset/ILSVRC2012_val_00028505.bin 224 224 +4632 ./prep_dataset/ILSVRC2012_val_00030945.bin 224 224 +4633 ./prep_dataset/ILSVRC2012_val_00011991.bin 224 224 +4634 ./prep_dataset/ILSVRC2012_val_00011741.bin 224 224 +4635 ./prep_dataset/ILSVRC2012_val_00029606.bin 224 224 +4636 ./prep_dataset/ILSVRC2012_val_00031519.bin 224 224 +4637 ./prep_dataset/ILSVRC2012_val_00001660.bin 224 224 +4638 ./prep_dataset/ILSVRC2012_val_00026750.bin 224 224 +4639 ./prep_dataset/ILSVRC2012_val_00000549.bin 224 224 +4640 ./prep_dataset/ILSVRC2012_val_00019791.bin 224 224 +4641 ./prep_dataset/ILSVRC2012_val_00011330.bin 224 224 +4642 ./prep_dataset/ILSVRC2012_val_00046058.bin 224 224 +4643 ./prep_dataset/ILSVRC2012_val_00029503.bin 224 224 +4644 ./prep_dataset/ILSVRC2012_val_00014722.bin 224 224 +4645 ./prep_dataset/ILSVRC2012_val_00006666.bin 224 224 +4646 ./prep_dataset/ILSVRC2012_val_00026912.bin 224 224 +4647 ./prep_dataset/ILSVRC2012_val_00041188.bin 224 224 +4648 ./prep_dataset/ILSVRC2012_val_00016663.bin 224 224 +4649 ./prep_dataset/ILSVRC2012_val_00033917.bin 224 224 +4650 ./prep_dataset/ILSVRC2012_val_00030590.bin 224 224 +4651 ./prep_dataset/ILSVRC2012_val_00044479.bin 224 224 +4652 ./prep_dataset/ILSVRC2012_val_00010318.bin 224 224 +4653 ./prep_dataset/ILSVRC2012_val_00048568.bin 224 224 +4654 ./prep_dataset/ILSVRC2012_val_00045484.bin 224 224 +4655 ./prep_dataset/ILSVRC2012_val_00012939.bin 224 224 +4656 ./prep_dataset/ILSVRC2012_val_00027016.bin 224 224 +4657 ./prep_dataset/ILSVRC2012_val_00027185.bin 224 224 +4658 ./prep_dataset/ILSVRC2012_val_00014063.bin 224 224 +4659 ./prep_dataset/ILSVRC2012_val_00017492.bin 224 224 +4660 ./prep_dataset/ILSVRC2012_val_00014515.bin 224 224 +4661 ./prep_dataset/ILSVRC2012_val_00019410.bin 224 224 +4662 ./prep_dataset/ILSVRC2012_val_00029423.bin 224 224 +4663 ./prep_dataset/ILSVRC2012_val_00030680.bin 224 224 +4664 ./prep_dataset/ILSVRC2012_val_00026792.bin 224 224 +4665 ./prep_dataset/ILSVRC2012_val_00010159.bin 224 224 +4666 ./prep_dataset/ILSVRC2012_val_00020008.bin 224 224 +4667 ./prep_dataset/ILSVRC2012_val_00023750.bin 224 224 +4668 ./prep_dataset/ILSVRC2012_val_00045797.bin 224 224 +4669 ./prep_dataset/ILSVRC2012_val_00046579.bin 224 224 +4670 ./prep_dataset/ILSVRC2012_val_00005366.bin 224 224 +4671 ./prep_dataset/ILSVRC2012_val_00032589.bin 224 224 +4672 ./prep_dataset/ILSVRC2012_val_00018579.bin 224 224 +4673 ./prep_dataset/ILSVRC2012_val_00022771.bin 224 224 +4674 ./prep_dataset/ILSVRC2012_val_00031563.bin 224 224 +4675 ./prep_dataset/ILSVRC2012_val_00023333.bin 224 224 +4676 ./prep_dataset/ILSVRC2012_val_00020473.bin 224 224 +4677 ./prep_dataset/ILSVRC2012_val_00031411.bin 224 224 +4678 ./prep_dataset/ILSVRC2012_val_00008958.bin 224 224 +4679 ./prep_dataset/ILSVRC2012_val_00024807.bin 224 224 +4680 ./prep_dataset/ILSVRC2012_val_00027934.bin 224 224 +4681 ./prep_dataset/ILSVRC2012_val_00014070.bin 224 224 +4682 ./prep_dataset/ILSVRC2012_val_00030840.bin 224 224 +4683 ./prep_dataset/ILSVRC2012_val_00023797.bin 224 224 +4684 ./prep_dataset/ILSVRC2012_val_00048404.bin 224 224 +4685 ./prep_dataset/ILSVRC2012_val_00044993.bin 224 224 +4686 ./prep_dataset/ILSVRC2012_val_00035866.bin 224 224 +4687 ./prep_dataset/ILSVRC2012_val_00019196.bin 224 224 +4688 ./prep_dataset/ILSVRC2012_val_00012022.bin 224 224 +4689 ./prep_dataset/ILSVRC2012_val_00013549.bin 224 224 +4690 ./prep_dataset/ILSVRC2012_val_00034098.bin 224 224 +4691 ./prep_dataset/ILSVRC2012_val_00031984.bin 224 224 +4692 ./prep_dataset/ILSVRC2012_val_00037741.bin 224 224 +4693 ./prep_dataset/ILSVRC2012_val_00003706.bin 224 224 +4694 ./prep_dataset/ILSVRC2012_val_00014947.bin 224 224 +4695 ./prep_dataset/ILSVRC2012_val_00038056.bin 224 224 +4696 ./prep_dataset/ILSVRC2012_val_00049089.bin 224 224 +4697 ./prep_dataset/ILSVRC2012_val_00024736.bin 224 224 +4698 ./prep_dataset/ILSVRC2012_val_00037640.bin 224 224 +4699 ./prep_dataset/ILSVRC2012_val_00037084.bin 224 224 +4700 ./prep_dataset/ILSVRC2012_val_00006004.bin 224 224 +4701 ./prep_dataset/ILSVRC2012_val_00003581.bin 224 224 +4702 ./prep_dataset/ILSVRC2012_val_00022216.bin 224 224 +4703 ./prep_dataset/ILSVRC2012_val_00031239.bin 224 224 +4704 ./prep_dataset/ILSVRC2012_val_00027879.bin 224 224 +4705 ./prep_dataset/ILSVRC2012_val_00016641.bin 224 224 +4706 ./prep_dataset/ILSVRC2012_val_00008689.bin 224 224 +4707 ./prep_dataset/ILSVRC2012_val_00015299.bin 224 224 +4708 ./prep_dataset/ILSVRC2012_val_00001341.bin 224 224 +4709 ./prep_dataset/ILSVRC2012_val_00015438.bin 224 224 +4710 ./prep_dataset/ILSVRC2012_val_00042371.bin 224 224 +4711 ./prep_dataset/ILSVRC2012_val_00018699.bin 224 224 +4712 ./prep_dataset/ILSVRC2012_val_00027708.bin 224 224 +4713 ./prep_dataset/ILSVRC2012_val_00000875.bin 224 224 +4714 ./prep_dataset/ILSVRC2012_val_00022690.bin 224 224 +4715 ./prep_dataset/ILSVRC2012_val_00015707.bin 224 224 +4716 ./prep_dataset/ILSVRC2012_val_00026783.bin 224 224 +4717 ./prep_dataset/ILSVRC2012_val_00024787.bin 224 224 +4718 ./prep_dataset/ILSVRC2012_val_00047292.bin 224 224 +4719 ./prep_dataset/ILSVRC2012_val_00018321.bin 224 224 +4720 ./prep_dataset/ILSVRC2012_val_00044024.bin 224 224 +4721 ./prep_dataset/ILSVRC2012_val_00030498.bin 224 224 +4722 ./prep_dataset/ILSVRC2012_val_00029537.bin 224 224 +4723 ./prep_dataset/ILSVRC2012_val_00032425.bin 224 224 +4724 ./prep_dataset/ILSVRC2012_val_00014222.bin 224 224 +4725 ./prep_dataset/ILSVRC2012_val_00033211.bin 224 224 +4726 ./prep_dataset/ILSVRC2012_val_00040023.bin 224 224 +4727 ./prep_dataset/ILSVRC2012_val_00001873.bin 224 224 +4728 ./prep_dataset/ILSVRC2012_val_00028009.bin 224 224 +4729 ./prep_dataset/ILSVRC2012_val_00029055.bin 224 224 +4730 ./prep_dataset/ILSVRC2012_val_00046656.bin 224 224 +4731 ./prep_dataset/ILSVRC2012_val_00001570.bin 224 224 +4732 ./prep_dataset/ILSVRC2012_val_00005026.bin 224 224 +4733 ./prep_dataset/ILSVRC2012_val_00027282.bin 224 224 +4734 ./prep_dataset/ILSVRC2012_val_00040868.bin 224 224 +4735 ./prep_dataset/ILSVRC2012_val_00018435.bin 224 224 +4736 ./prep_dataset/ILSVRC2012_val_00037401.bin 224 224 +4737 ./prep_dataset/ILSVRC2012_val_00036226.bin 224 224 +4738 ./prep_dataset/ILSVRC2012_val_00028092.bin 224 224 +4739 ./prep_dataset/ILSVRC2012_val_00005573.bin 224 224 +4740 ./prep_dataset/ILSVRC2012_val_00013501.bin 224 224 +4741 ./prep_dataset/ILSVRC2012_val_00009941.bin 224 224 +4742 ./prep_dataset/ILSVRC2012_val_00030833.bin 224 224 +4743 ./prep_dataset/ILSVRC2012_val_00006701.bin 224 224 +4744 ./prep_dataset/ILSVRC2012_val_00047766.bin 224 224 +4745 ./prep_dataset/ILSVRC2012_val_00019007.bin 224 224 +4746 ./prep_dataset/ILSVRC2012_val_00031315.bin 224 224 +4747 ./prep_dataset/ILSVRC2012_val_00049131.bin 224 224 +4748 ./prep_dataset/ILSVRC2012_val_00029450.bin 224 224 +4749 ./prep_dataset/ILSVRC2012_val_00023080.bin 224 224 +4750 ./prep_dataset/ILSVRC2012_val_00030516.bin 224 224 +4751 ./prep_dataset/ILSVRC2012_val_00041982.bin 224 224 +4752 ./prep_dataset/ILSVRC2012_val_00037862.bin 224 224 +4753 ./prep_dataset/ILSVRC2012_val_00023452.bin 224 224 +4754 ./prep_dataset/ILSVRC2012_val_00023589.bin 224 224 +4755 ./prep_dataset/ILSVRC2012_val_00009107.bin 224 224 +4756 ./prep_dataset/ILSVRC2012_val_00027809.bin 224 224 +4757 ./prep_dataset/ILSVRC2012_val_00036924.bin 224 224 +4758 ./prep_dataset/ILSVRC2012_val_00047821.bin 224 224 +4759 ./prep_dataset/ILSVRC2012_val_00044162.bin 224 224 +4760 ./prep_dataset/ILSVRC2012_val_00039746.bin 224 224 +4761 ./prep_dataset/ILSVRC2012_val_00001030.bin 224 224 +4762 ./prep_dataset/ILSVRC2012_val_00014338.bin 224 224 +4763 ./prep_dataset/ILSVRC2012_val_00048165.bin 224 224 +4764 ./prep_dataset/ILSVRC2012_val_00018127.bin 224 224 +4765 ./prep_dataset/ILSVRC2012_val_00005833.bin 224 224 +4766 ./prep_dataset/ILSVRC2012_val_00042644.bin 224 224 +4767 ./prep_dataset/ILSVRC2012_val_00047747.bin 224 224 +4768 ./prep_dataset/ILSVRC2012_val_00005528.bin 224 224 +4769 ./prep_dataset/ILSVRC2012_val_00031287.bin 224 224 +4770 ./prep_dataset/ILSVRC2012_val_00014694.bin 224 224 +4771 ./prep_dataset/ILSVRC2012_val_00017771.bin 224 224 +4772 ./prep_dataset/ILSVRC2012_val_00025957.bin 224 224 +4773 ./prep_dataset/ILSVRC2012_val_00043999.bin 224 224 +4774 ./prep_dataset/ILSVRC2012_val_00039830.bin 224 224 +4775 ./prep_dataset/ILSVRC2012_val_00047620.bin 224 224 +4776 ./prep_dataset/ILSVRC2012_val_00037017.bin 224 224 +4777 ./prep_dataset/ILSVRC2012_val_00040341.bin 224 224 +4778 ./prep_dataset/ILSVRC2012_val_00039338.bin 224 224 +4779 ./prep_dataset/ILSVRC2012_val_00006833.bin 224 224 +4780 ./prep_dataset/ILSVRC2012_val_00004053.bin 224 224 +4781 ./prep_dataset/ILSVRC2012_val_00011332.bin 224 224 +4782 ./prep_dataset/ILSVRC2012_val_00039482.bin 224 224 +4783 ./prep_dataset/ILSVRC2012_val_00007356.bin 224 224 +4784 ./prep_dataset/ILSVRC2012_val_00022999.bin 224 224 +4785 ./prep_dataset/ILSVRC2012_val_00026615.bin 224 224 +4786 ./prep_dataset/ILSVRC2012_val_00041777.bin 224 224 +4787 ./prep_dataset/ILSVRC2012_val_00045379.bin 224 224 +4788 ./prep_dataset/ILSVRC2012_val_00021722.bin 224 224 +4789 ./prep_dataset/ILSVRC2012_val_00036461.bin 224 224 +4790 ./prep_dataset/ILSVRC2012_val_00012962.bin 224 224 +4791 ./prep_dataset/ILSVRC2012_val_00045413.bin 224 224 +4792 ./prep_dataset/ILSVRC2012_val_00028590.bin 224 224 +4793 ./prep_dataset/ILSVRC2012_val_00007331.bin 224 224 +4794 ./prep_dataset/ILSVRC2012_val_00001175.bin 224 224 +4795 ./prep_dataset/ILSVRC2012_val_00019184.bin 224 224 +4796 ./prep_dataset/ILSVRC2012_val_00048236.bin 224 224 +4797 ./prep_dataset/ILSVRC2012_val_00014428.bin 224 224 +4798 ./prep_dataset/ILSVRC2012_val_00023833.bin 224 224 +4799 ./prep_dataset/ILSVRC2012_val_00032789.bin 224 224 +4800 ./prep_dataset/ILSVRC2012_val_00025362.bin 224 224 +4801 ./prep_dataset/ILSVRC2012_val_00016147.bin 224 224 +4802 ./prep_dataset/ILSVRC2012_val_00007834.bin 224 224 +4803 ./prep_dataset/ILSVRC2012_val_00019198.bin 224 224 +4804 ./prep_dataset/ILSVRC2012_val_00047079.bin 224 224 +4805 ./prep_dataset/ILSVRC2012_val_00012584.bin 224 224 +4806 ./prep_dataset/ILSVRC2012_val_00012504.bin 224 224 +4807 ./prep_dataset/ILSVRC2012_val_00001169.bin 224 224 +4808 ./prep_dataset/ILSVRC2012_val_00049646.bin 224 224 +4809 ./prep_dataset/ILSVRC2012_val_00009464.bin 224 224 +4810 ./prep_dataset/ILSVRC2012_val_00009944.bin 224 224 +4811 ./prep_dataset/ILSVRC2012_val_00004797.bin 224 224 +4812 ./prep_dataset/ILSVRC2012_val_00033374.bin 224 224 +4813 ./prep_dataset/ILSVRC2012_val_00027579.bin 224 224 +4814 ./prep_dataset/ILSVRC2012_val_00014580.bin 224 224 +4815 ./prep_dataset/ILSVRC2012_val_00013708.bin 224 224 +4816 ./prep_dataset/ILSVRC2012_val_00020674.bin 224 224 +4817 ./prep_dataset/ILSVRC2012_val_00014480.bin 224 224 +4818 ./prep_dataset/ILSVRC2012_val_00043379.bin 224 224 +4819 ./prep_dataset/ILSVRC2012_val_00018528.bin 224 224 +4820 ./prep_dataset/ILSVRC2012_val_00036251.bin 224 224 +4821 ./prep_dataset/ILSVRC2012_val_00038860.bin 224 224 +4822 ./prep_dataset/ILSVRC2012_val_00036825.bin 224 224 +4823 ./prep_dataset/ILSVRC2012_val_00019326.bin 224 224 +4824 ./prep_dataset/ILSVRC2012_val_00039419.bin 224 224 +4825 ./prep_dataset/ILSVRC2012_val_00043495.bin 224 224 +4826 ./prep_dataset/ILSVRC2012_val_00031522.bin 224 224 +4827 ./prep_dataset/ILSVRC2012_val_00002027.bin 224 224 +4828 ./prep_dataset/ILSVRC2012_val_00049028.bin 224 224 +4829 ./prep_dataset/ILSVRC2012_val_00010009.bin 224 224 +4830 ./prep_dataset/ILSVRC2012_val_00024310.bin 224 224 +4831 ./prep_dataset/ILSVRC2012_val_00046022.bin 224 224 +4832 ./prep_dataset/ILSVRC2012_val_00001304.bin 224 224 +4833 ./prep_dataset/ILSVRC2012_val_00014345.bin 224 224 +4834 ./prep_dataset/ILSVRC2012_val_00040030.bin 224 224 +4835 ./prep_dataset/ILSVRC2012_val_00023666.bin 224 224 +4836 ./prep_dataset/ILSVRC2012_val_00021432.bin 224 224 +4837 ./prep_dataset/ILSVRC2012_val_00027330.bin 224 224 +4838 ./prep_dataset/ILSVRC2012_val_00047972.bin 224 224 +4839 ./prep_dataset/ILSVRC2012_val_00039532.bin 224 224 +4840 ./prep_dataset/ILSVRC2012_val_00025715.bin 224 224 +4841 ./prep_dataset/ILSVRC2012_val_00033505.bin 224 224 +4842 ./prep_dataset/ILSVRC2012_val_00049960.bin 224 224 +4843 ./prep_dataset/ILSVRC2012_val_00021043.bin 224 224 +4844 ./prep_dataset/ILSVRC2012_val_00040709.bin 224 224 +4845 ./prep_dataset/ILSVRC2012_val_00010534.bin 224 224 +4846 ./prep_dataset/ILSVRC2012_val_00016624.bin 224 224 +4847 ./prep_dataset/ILSVRC2012_val_00027057.bin 224 224 +4848 ./prep_dataset/ILSVRC2012_val_00033233.bin 224 224 +4849 ./prep_dataset/ILSVRC2012_val_00015230.bin 224 224 +4850 ./prep_dataset/ILSVRC2012_val_00014157.bin 224 224 +4851 ./prep_dataset/ILSVRC2012_val_00048173.bin 224 224 +4852 ./prep_dataset/ILSVRC2012_val_00011773.bin 224 224 +4853 ./prep_dataset/ILSVRC2012_val_00035043.bin 224 224 +4854 ./prep_dataset/ILSVRC2012_val_00005921.bin 224 224 +4855 ./prep_dataset/ILSVRC2012_val_00012671.bin 224 224 +4856 ./prep_dataset/ILSVRC2012_val_00047238.bin 224 224 +4857 ./prep_dataset/ILSVRC2012_val_00036728.bin 224 224 +4858 ./prep_dataset/ILSVRC2012_val_00002657.bin 224 224 +4859 ./prep_dataset/ILSVRC2012_val_00017100.bin 224 224 +4860 ./prep_dataset/ILSVRC2012_val_00000827.bin 224 224 +4861 ./prep_dataset/ILSVRC2012_val_00039168.bin 224 224 +4862 ./prep_dataset/ILSVRC2012_val_00033641.bin 224 224 +4863 ./prep_dataset/ILSVRC2012_val_00034831.bin 224 224 +4864 ./prep_dataset/ILSVRC2012_val_00011435.bin 224 224 +4865 ./prep_dataset/ILSVRC2012_val_00003997.bin 224 224 +4866 ./prep_dataset/ILSVRC2012_val_00046492.bin 224 224 +4867 ./prep_dataset/ILSVRC2012_val_00009523.bin 224 224 +4868 ./prep_dataset/ILSVRC2012_val_00028983.bin 224 224 +4869 ./prep_dataset/ILSVRC2012_val_00016282.bin 224 224 +4870 ./prep_dataset/ILSVRC2012_val_00006235.bin 224 224 +4871 ./prep_dataset/ILSVRC2012_val_00048004.bin 224 224 +4872 ./prep_dataset/ILSVRC2012_val_00006071.bin 224 224 +4873 ./prep_dataset/ILSVRC2012_val_00012772.bin 224 224 +4874 ./prep_dataset/ILSVRC2012_val_00006549.bin 224 224 +4875 ./prep_dataset/ILSVRC2012_val_00049722.bin 224 224 +4876 ./prep_dataset/ILSVRC2012_val_00005119.bin 224 224 +4877 ./prep_dataset/ILSVRC2012_val_00004649.bin 224 224 +4878 ./prep_dataset/ILSVRC2012_val_00026369.bin 224 224 +4879 ./prep_dataset/ILSVRC2012_val_00011705.bin 224 224 +4880 ./prep_dataset/ILSVRC2012_val_00015841.bin 224 224 +4881 ./prep_dataset/ILSVRC2012_val_00006074.bin 224 224 +4882 ./prep_dataset/ILSVRC2012_val_00039054.bin 224 224 +4883 ./prep_dataset/ILSVRC2012_val_00049104.bin 224 224 +4884 ./prep_dataset/ILSVRC2012_val_00048536.bin 224 224 +4885 ./prep_dataset/ILSVRC2012_val_00002901.bin 224 224 +4886 ./prep_dataset/ILSVRC2012_val_00032537.bin 224 224 +4887 ./prep_dataset/ILSVRC2012_val_00046940.bin 224 224 +4888 ./prep_dataset/ILSVRC2012_val_00047193.bin 224 224 +4889 ./prep_dataset/ILSVRC2012_val_00043662.bin 224 224 +4890 ./prep_dataset/ILSVRC2012_val_00002695.bin 224 224 +4891 ./prep_dataset/ILSVRC2012_val_00019931.bin 224 224 +4892 ./prep_dataset/ILSVRC2012_val_00030748.bin 224 224 +4893 ./prep_dataset/ILSVRC2012_val_00035776.bin 224 224 +4894 ./prep_dataset/ILSVRC2012_val_00042201.bin 224 224 +4895 ./prep_dataset/ILSVRC2012_val_00035052.bin 224 224 +4896 ./prep_dataset/ILSVRC2012_val_00041817.bin 224 224 +4897 ./prep_dataset/ILSVRC2012_val_00006980.bin 224 224 +4898 ./prep_dataset/ILSVRC2012_val_00042281.bin 224 224 +4899 ./prep_dataset/ILSVRC2012_val_00029365.bin 224 224 +4900 ./prep_dataset/ILSVRC2012_val_00009885.bin 224 224 +4901 ./prep_dataset/ILSVRC2012_val_00010340.bin 224 224 +4902 ./prep_dataset/ILSVRC2012_val_00023950.bin 224 224 +4903 ./prep_dataset/ILSVRC2012_val_00000196.bin 224 224 +4904 ./prep_dataset/ILSVRC2012_val_00040284.bin 224 224 +4905 ./prep_dataset/ILSVRC2012_val_00046177.bin 224 224 +4906 ./prep_dataset/ILSVRC2012_val_00035067.bin 224 224 +4907 ./prep_dataset/ILSVRC2012_val_00010451.bin 224 224 +4908 ./prep_dataset/ILSVRC2012_val_00042912.bin 224 224 +4909 ./prep_dataset/ILSVRC2012_val_00034832.bin 224 224 +4910 ./prep_dataset/ILSVRC2012_val_00003611.bin 224 224 +4911 ./prep_dataset/ILSVRC2012_val_00026908.bin 224 224 +4912 ./prep_dataset/ILSVRC2012_val_00039613.bin 224 224 +4913 ./prep_dataset/ILSVRC2012_val_00000809.bin 224 224 +4914 ./prep_dataset/ILSVRC2012_val_00006459.bin 224 224 +4915 ./prep_dataset/ILSVRC2012_val_00017472.bin 224 224 +4916 ./prep_dataset/ILSVRC2012_val_00008910.bin 224 224 +4917 ./prep_dataset/ILSVRC2012_val_00025377.bin 224 224 +4918 ./prep_dataset/ILSVRC2012_val_00015759.bin 224 224 +4919 ./prep_dataset/ILSVRC2012_val_00030309.bin 224 224 +4920 ./prep_dataset/ILSVRC2012_val_00027731.bin 224 224 +4921 ./prep_dataset/ILSVRC2012_val_00000490.bin 224 224 +4922 ./prep_dataset/ILSVRC2012_val_00048548.bin 224 224 +4923 ./prep_dataset/ILSVRC2012_val_00020236.bin 224 224 +4924 ./prep_dataset/ILSVRC2012_val_00040272.bin 224 224 +4925 ./prep_dataset/ILSVRC2012_val_00008809.bin 224 224 +4926 ./prep_dataset/ILSVRC2012_val_00039685.bin 224 224 +4927 ./prep_dataset/ILSVRC2012_val_00016961.bin 224 224 +4928 ./prep_dataset/ILSVRC2012_val_00043180.bin 224 224 +4929 ./prep_dataset/ILSVRC2012_val_00047568.bin 224 224 +4930 ./prep_dataset/ILSVRC2012_val_00046212.bin 224 224 +4931 ./prep_dataset/ILSVRC2012_val_00038364.bin 224 224 +4932 ./prep_dataset/ILSVRC2012_val_00031559.bin 224 224 +4933 ./prep_dataset/ILSVRC2012_val_00012513.bin 224 224 +4934 ./prep_dataset/ILSVRC2012_val_00000254.bin 224 224 +4935 ./prep_dataset/ILSVRC2012_val_00018915.bin 224 224 +4936 ./prep_dataset/ILSVRC2012_val_00000187.bin 224 224 +4937 ./prep_dataset/ILSVRC2012_val_00002158.bin 224 224 +4938 ./prep_dataset/ILSVRC2012_val_00029324.bin 224 224 +4939 ./prep_dataset/ILSVRC2012_val_00043596.bin 224 224 +4940 ./prep_dataset/ILSVRC2012_val_00019096.bin 224 224 +4941 ./prep_dataset/ILSVRC2012_val_00035744.bin 224 224 +4942 ./prep_dataset/ILSVRC2012_val_00035647.bin 224 224 +4943 ./prep_dataset/ILSVRC2012_val_00008543.bin 224 224 +4944 ./prep_dataset/ILSVRC2012_val_00009052.bin 224 224 +4945 ./prep_dataset/ILSVRC2012_val_00013407.bin 224 224 +4946 ./prep_dataset/ILSVRC2012_val_00002878.bin 224 224 +4947 ./prep_dataset/ILSVRC2012_val_00040172.bin 224 224 +4948 ./prep_dataset/ILSVRC2012_val_00013070.bin 224 224 +4949 ./prep_dataset/ILSVRC2012_val_00035207.bin 224 224 +4950 ./prep_dataset/ILSVRC2012_val_00048453.bin 224 224 +4951 ./prep_dataset/ILSVRC2012_val_00000272.bin 224 224 +4952 ./prep_dataset/ILSVRC2012_val_00000976.bin 224 224 +4953 ./prep_dataset/ILSVRC2012_val_00008007.bin 224 224 +4954 ./prep_dataset/ILSVRC2012_val_00014245.bin 224 224 +4955 ./prep_dataset/ILSVRC2012_val_00025695.bin 224 224 +4956 ./prep_dataset/ILSVRC2012_val_00010549.bin 224 224 +4957 ./prep_dataset/ILSVRC2012_val_00008570.bin 224 224 +4958 ./prep_dataset/ILSVRC2012_val_00044863.bin 224 224 +4959 ./prep_dataset/ILSVRC2012_val_00020713.bin 224 224 +4960 ./prep_dataset/ILSVRC2012_val_00020673.bin 224 224 +4961 ./prep_dataset/ILSVRC2012_val_00022098.bin 224 224 +4962 ./prep_dataset/ILSVRC2012_val_00009742.bin 224 224 +4963 ./prep_dataset/ILSVRC2012_val_00005611.bin 224 224 +4964 ./prep_dataset/ILSVRC2012_val_00032639.bin 224 224 +4965 ./prep_dataset/ILSVRC2012_val_00035205.bin 224 224 +4966 ./prep_dataset/ILSVRC2012_val_00008900.bin 224 224 +4967 ./prep_dataset/ILSVRC2012_val_00024215.bin 224 224 +4968 ./prep_dataset/ILSVRC2012_val_00012676.bin 224 224 +4969 ./prep_dataset/ILSVRC2012_val_00045316.bin 224 224 +4970 ./prep_dataset/ILSVRC2012_val_00047822.bin 224 224 +4971 ./prep_dataset/ILSVRC2012_val_00038594.bin 224 224 +4972 ./prep_dataset/ILSVRC2012_val_00007653.bin 224 224 +4973 ./prep_dataset/ILSVRC2012_val_00003093.bin 224 224 +4974 ./prep_dataset/ILSVRC2012_val_00022081.bin 224 224 +4975 ./prep_dataset/ILSVRC2012_val_00045328.bin 224 224 +4976 ./prep_dataset/ILSVRC2012_val_00022931.bin 224 224 +4977 ./prep_dataset/ILSVRC2012_val_00007685.bin 224 224 +4978 ./prep_dataset/ILSVRC2012_val_00029446.bin 224 224 +4979 ./prep_dataset/ILSVRC2012_val_00032207.bin 224 224 +4980 ./prep_dataset/ILSVRC2012_val_00039587.bin 224 224 +4981 ./prep_dataset/ILSVRC2012_val_00037753.bin 224 224 +4982 ./prep_dataset/ILSVRC2012_val_00011051.bin 224 224 +4983 ./prep_dataset/ILSVRC2012_val_00018612.bin 224 224 +4984 ./prep_dataset/ILSVRC2012_val_00035544.bin 224 224 +4985 ./prep_dataset/ILSVRC2012_val_00033806.bin 224 224 +4986 ./prep_dataset/ILSVRC2012_val_00021328.bin 224 224 +4987 ./prep_dataset/ILSVRC2012_val_00033120.bin 224 224 +4988 ./prep_dataset/ILSVRC2012_val_00006809.bin 224 224 +4989 ./prep_dataset/ILSVRC2012_val_00023753.bin 224 224 +4990 ./prep_dataset/ILSVRC2012_val_00002166.bin 224 224 +4991 ./prep_dataset/ILSVRC2012_val_00006373.bin 224 224 +4992 ./prep_dataset/ILSVRC2012_val_00011161.bin 224 224 +4993 ./prep_dataset/ILSVRC2012_val_00045693.bin 224 224 +4994 ./prep_dataset/ILSVRC2012_val_00048947.bin 224 224 +4995 ./prep_dataset/ILSVRC2012_val_00014159.bin 224 224 +4996 ./prep_dataset/ILSVRC2012_val_00037516.bin 224 224 +4997 ./prep_dataset/ILSVRC2012_val_00000492.bin 224 224 +4998 ./prep_dataset/ILSVRC2012_val_00000655.bin 224 224 +4999 ./prep_dataset/ILSVRC2012_val_00046620.bin 224 224 +5000 ./prep_dataset/ILSVRC2012_val_00042787.bin 224 224 +5001 ./prep_dataset/ILSVRC2012_val_00006681.bin 224 224 +5002 ./prep_dataset/ILSVRC2012_val_00038357.bin 224 224 +5003 ./prep_dataset/ILSVRC2012_val_00010000.bin 224 224 +5004 ./prep_dataset/ILSVRC2012_val_00015310.bin 224 224 +5005 ./prep_dataset/ILSVRC2012_val_00029481.bin 224 224 +5006 ./prep_dataset/ILSVRC2012_val_00025594.bin 224 224 +5007 ./prep_dataset/ILSVRC2012_val_00012063.bin 224 224 +5008 ./prep_dataset/ILSVRC2012_val_00029645.bin 224 224 +5009 ./prep_dataset/ILSVRC2012_val_00003986.bin 224 224 +5010 ./prep_dataset/ILSVRC2012_val_00038949.bin 224 224 +5011 ./prep_dataset/ILSVRC2012_val_00013230.bin 224 224 +5012 ./prep_dataset/ILSVRC2012_val_00017358.bin 224 224 +5013 ./prep_dataset/ILSVRC2012_val_00027244.bin 224 224 +5014 ./prep_dataset/ILSVRC2012_val_00041202.bin 224 224 +5015 ./prep_dataset/ILSVRC2012_val_00011031.bin 224 224 +5016 ./prep_dataset/ILSVRC2012_val_00026098.bin 224 224 +5017 ./prep_dataset/ILSVRC2012_val_00037825.bin 224 224 +5018 ./prep_dataset/ILSVRC2012_val_00025635.bin 224 224 +5019 ./prep_dataset/ILSVRC2012_val_00023980.bin 224 224 +5020 ./prep_dataset/ILSVRC2012_val_00034286.bin 224 224 +5021 ./prep_dataset/ILSVRC2012_val_00009051.bin 224 224 +5022 ./prep_dataset/ILSVRC2012_val_00046343.bin 224 224 +5023 ./prep_dataset/ILSVRC2012_val_00038055.bin 224 224 +5024 ./prep_dataset/ILSVRC2012_val_00000661.bin 224 224 +5025 ./prep_dataset/ILSVRC2012_val_00018602.bin 224 224 +5026 ./prep_dataset/ILSVRC2012_val_00004492.bin 224 224 +5027 ./prep_dataset/ILSVRC2012_val_00037790.bin 224 224 +5028 ./prep_dataset/ILSVRC2012_val_00023552.bin 224 224 +5029 ./prep_dataset/ILSVRC2012_val_00023701.bin 224 224 +5030 ./prep_dataset/ILSVRC2012_val_00014220.bin 224 224 +5031 ./prep_dataset/ILSVRC2012_val_00017353.bin 224 224 +5032 ./prep_dataset/ILSVRC2012_val_00046247.bin 224 224 +5033 ./prep_dataset/ILSVRC2012_val_00017770.bin 224 224 +5034 ./prep_dataset/ILSVRC2012_val_00039259.bin 224 224 +5035 ./prep_dataset/ILSVRC2012_val_00007705.bin 224 224 +5036 ./prep_dataset/ILSVRC2012_val_00030113.bin 224 224 +5037 ./prep_dataset/ILSVRC2012_val_00041771.bin 224 224 +5038 ./prep_dataset/ILSVRC2012_val_00040383.bin 224 224 +5039 ./prep_dataset/ILSVRC2012_val_00033133.bin 224 224 +5040 ./prep_dataset/ILSVRC2012_val_00029024.bin 224 224 +5041 ./prep_dataset/ILSVRC2012_val_00020910.bin 224 224 +5042 ./prep_dataset/ILSVRC2012_val_00024928.bin 224 224 +5043 ./prep_dataset/ILSVRC2012_val_00000543.bin 224 224 +5044 ./prep_dataset/ILSVRC2012_val_00038523.bin 224 224 +5045 ./prep_dataset/ILSVRC2012_val_00023576.bin 224 224 +5046 ./prep_dataset/ILSVRC2012_val_00014712.bin 224 224 +5047 ./prep_dataset/ILSVRC2012_val_00020949.bin 224 224 +5048 ./prep_dataset/ILSVRC2012_val_00000444.bin 224 224 +5049 ./prep_dataset/ILSVRC2012_val_00043616.bin 224 224 +5050 ./prep_dataset/ILSVRC2012_val_00018639.bin 224 224 +5051 ./prep_dataset/ILSVRC2012_val_00039425.bin 224 224 +5052 ./prep_dataset/ILSVRC2012_val_00027551.bin 224 224 +5053 ./prep_dataset/ILSVRC2012_val_00005897.bin 224 224 +5054 ./prep_dataset/ILSVRC2012_val_00018552.bin 224 224 +5055 ./prep_dataset/ILSVRC2012_val_00026384.bin 224 224 +5056 ./prep_dataset/ILSVRC2012_val_00004829.bin 224 224 +5057 ./prep_dataset/ILSVRC2012_val_00013641.bin 224 224 +5058 ./prep_dataset/ILSVRC2012_val_00048719.bin 224 224 +5059 ./prep_dataset/ILSVRC2012_val_00022472.bin 224 224 +5060 ./prep_dataset/ILSVRC2012_val_00026715.bin 224 224 +5061 ./prep_dataset/ILSVRC2012_val_00007865.bin 224 224 +5062 ./prep_dataset/ILSVRC2012_val_00048164.bin 224 224 +5063 ./prep_dataset/ILSVRC2012_val_00043730.bin 224 224 +5064 ./prep_dataset/ILSVRC2012_val_00016357.bin 224 224 +5065 ./prep_dataset/ILSVRC2012_val_00019473.bin 224 224 +5066 ./prep_dataset/ILSVRC2012_val_00024625.bin 224 224 +5067 ./prep_dataset/ILSVRC2012_val_00001470.bin 224 224 +5068 ./prep_dataset/ILSVRC2012_val_00031421.bin 224 224 +5069 ./prep_dataset/ILSVRC2012_val_00017045.bin 224 224 +5070 ./prep_dataset/ILSVRC2012_val_00000786.bin 224 224 +5071 ./prep_dataset/ILSVRC2012_val_00023875.bin 224 224 +5072 ./prep_dataset/ILSVRC2012_val_00014407.bin 224 224 +5073 ./prep_dataset/ILSVRC2012_val_00026190.bin 224 224 +5074 ./prep_dataset/ILSVRC2012_val_00006460.bin 224 224 +5075 ./prep_dataset/ILSVRC2012_val_00000232.bin 224 224 +5076 ./prep_dataset/ILSVRC2012_val_00016533.bin 224 224 +5077 ./prep_dataset/ILSVRC2012_val_00014956.bin 224 224 +5078 ./prep_dataset/ILSVRC2012_val_00015272.bin 224 224 +5079 ./prep_dataset/ILSVRC2012_val_00015835.bin 224 224 +5080 ./prep_dataset/ILSVRC2012_val_00036559.bin 224 224 +5081 ./prep_dataset/ILSVRC2012_val_00032421.bin 224 224 +5082 ./prep_dataset/ILSVRC2012_val_00008502.bin 224 224 +5083 ./prep_dataset/ILSVRC2012_val_00020357.bin 224 224 +5084 ./prep_dataset/ILSVRC2012_val_00031275.bin 224 224 +5085 ./prep_dataset/ILSVRC2012_val_00020324.bin 224 224 +5086 ./prep_dataset/ILSVRC2012_val_00020670.bin 224 224 +5087 ./prep_dataset/ILSVRC2012_val_00003788.bin 224 224 +5088 ./prep_dataset/ILSVRC2012_val_00010260.bin 224 224 +5089 ./prep_dataset/ILSVRC2012_val_00046528.bin 224 224 +5090 ./prep_dataset/ILSVRC2012_val_00030366.bin 224 224 +5091 ./prep_dataset/ILSVRC2012_val_00033577.bin 224 224 +5092 ./prep_dataset/ILSVRC2012_val_00010324.bin 224 224 +5093 ./prep_dataset/ILSVRC2012_val_00039961.bin 224 224 +5094 ./prep_dataset/ILSVRC2012_val_00015120.bin 224 224 +5095 ./prep_dataset/ILSVRC2012_val_00016584.bin 224 224 +5096 ./prep_dataset/ILSVRC2012_val_00043336.bin 224 224 +5097 ./prep_dataset/ILSVRC2012_val_00017475.bin 224 224 +5098 ./prep_dataset/ILSVRC2012_val_00014193.bin 224 224 +5099 ./prep_dataset/ILSVRC2012_val_00016844.bin 224 224 +5100 ./prep_dataset/ILSVRC2012_val_00042527.bin 224 224 +5101 ./prep_dataset/ILSVRC2012_val_00030507.bin 224 224 +5102 ./prep_dataset/ILSVRC2012_val_00025824.bin 224 224 +5103 ./prep_dataset/ILSVRC2012_val_00013983.bin 224 224 +5104 ./prep_dataset/ILSVRC2012_val_00044556.bin 224 224 +5105 ./prep_dataset/ILSVRC2012_val_00044930.bin 224 224 +5106 ./prep_dataset/ILSVRC2012_val_00001827.bin 224 224 +5107 ./prep_dataset/ILSVRC2012_val_00041766.bin 224 224 +5108 ./prep_dataset/ILSVRC2012_val_00008223.bin 224 224 +5109 ./prep_dataset/ILSVRC2012_val_00033901.bin 224 224 +5110 ./prep_dataset/ILSVRC2012_val_00017337.bin 224 224 +5111 ./prep_dataset/ILSVRC2012_val_00003673.bin 224 224 +5112 ./prep_dataset/ILSVRC2012_val_00031867.bin 224 224 +5113 ./prep_dataset/ILSVRC2012_val_00024126.bin 224 224 +5114 ./prep_dataset/ILSVRC2012_val_00012528.bin 224 224 +5115 ./prep_dataset/ILSVRC2012_val_00038916.bin 224 224 +5116 ./prep_dataset/ILSVRC2012_val_00031589.bin 224 224 +5117 ./prep_dataset/ILSVRC2012_val_00042794.bin 224 224 +5118 ./prep_dataset/ILSVRC2012_val_00018356.bin 224 224 +5119 ./prep_dataset/ILSVRC2012_val_00038854.bin 224 224 +5120 ./prep_dataset/ILSVRC2012_val_00010101.bin 224 224 +5121 ./prep_dataset/ILSVRC2012_val_00019006.bin 224 224 +5122 ./prep_dataset/ILSVRC2012_val_00034498.bin 224 224 +5123 ./prep_dataset/ILSVRC2012_val_00048361.bin 224 224 +5124 ./prep_dataset/ILSVRC2012_val_00024897.bin 224 224 +5125 ./prep_dataset/ILSVRC2012_val_00036614.bin 224 224 +5126 ./prep_dataset/ILSVRC2012_val_00019182.bin 224 224 +5127 ./prep_dataset/ILSVRC2012_val_00017295.bin 224 224 +5128 ./prep_dataset/ILSVRC2012_val_00025366.bin 224 224 +5129 ./prep_dataset/ILSVRC2012_val_00032881.bin 224 224 +5130 ./prep_dataset/ILSVRC2012_val_00018393.bin 224 224 +5131 ./prep_dataset/ILSVRC2012_val_00027439.bin 224 224 +5132 ./prep_dataset/ILSVRC2012_val_00021472.bin 224 224 +5133 ./prep_dataset/ILSVRC2012_val_00015701.bin 224 224 +5134 ./prep_dataset/ILSVRC2012_val_00007657.bin 224 224 +5135 ./prep_dataset/ILSVRC2012_val_00035248.bin 224 224 +5136 ./prep_dataset/ILSVRC2012_val_00018150.bin 224 224 +5137 ./prep_dataset/ILSVRC2012_val_00043088.bin 224 224 +5138 ./prep_dataset/ILSVRC2012_val_00049641.bin 224 224 +5139 ./prep_dataset/ILSVRC2012_val_00033091.bin 224 224 +5140 ./prep_dataset/ILSVRC2012_val_00040009.bin 224 224 +5141 ./prep_dataset/ILSVRC2012_val_00004537.bin 224 224 +5142 ./prep_dataset/ILSVRC2012_val_00029581.bin 224 224 +5143 ./prep_dataset/ILSVRC2012_val_00012096.bin 224 224 +5144 ./prep_dataset/ILSVRC2012_val_00008227.bin 224 224 +5145 ./prep_dataset/ILSVRC2012_val_00049048.bin 224 224 +5146 ./prep_dataset/ILSVRC2012_val_00037425.bin 224 224 +5147 ./prep_dataset/ILSVRC2012_val_00008835.bin 224 224 +5148 ./prep_dataset/ILSVRC2012_val_00014079.bin 224 224 +5149 ./prep_dataset/ILSVRC2012_val_00011331.bin 224 224 +5150 ./prep_dataset/ILSVRC2012_val_00004403.bin 224 224 +5151 ./prep_dataset/ILSVRC2012_val_00024597.bin 224 224 +5152 ./prep_dataset/ILSVRC2012_val_00025319.bin 224 224 +5153 ./prep_dataset/ILSVRC2012_val_00032148.bin 224 224 +5154 ./prep_dataset/ILSVRC2012_val_00030526.bin 224 224 +5155 ./prep_dataset/ILSVRC2012_val_00022294.bin 224 224 +5156 ./prep_dataset/ILSVRC2012_val_00012518.bin 224 224 +5157 ./prep_dataset/ILSVRC2012_val_00005868.bin 224 224 +5158 ./prep_dataset/ILSVRC2012_val_00038237.bin 224 224 +5159 ./prep_dataset/ILSVRC2012_val_00023253.bin 224 224 +5160 ./prep_dataset/ILSVRC2012_val_00015752.bin 224 224 +5161 ./prep_dataset/ILSVRC2012_val_00044665.bin 224 224 +5162 ./prep_dataset/ILSVRC2012_val_00036404.bin 224 224 +5163 ./prep_dataset/ILSVRC2012_val_00029625.bin 224 224 +5164 ./prep_dataset/ILSVRC2012_val_00008626.bin 224 224 +5165 ./prep_dataset/ILSVRC2012_val_00025312.bin 224 224 +5166 ./prep_dataset/ILSVRC2012_val_00047730.bin 224 224 +5167 ./prep_dataset/ILSVRC2012_val_00024752.bin 224 224 +5168 ./prep_dataset/ILSVRC2012_val_00035271.bin 224 224 +5169 ./prep_dataset/ILSVRC2012_val_00042810.bin 224 224 +5170 ./prep_dataset/ILSVRC2012_val_00025622.bin 224 224 +5171 ./prep_dataset/ILSVRC2012_val_00041259.bin 224 224 +5172 ./prep_dataset/ILSVRC2012_val_00047748.bin 224 224 +5173 ./prep_dataset/ILSVRC2012_val_00018828.bin 224 224 +5174 ./prep_dataset/ILSVRC2012_val_00030733.bin 224 224 +5175 ./prep_dataset/ILSVRC2012_val_00003532.bin 224 224 +5176 ./prep_dataset/ILSVRC2012_val_00010167.bin 224 224 +5177 ./prep_dataset/ILSVRC2012_val_00027865.bin 224 224 +5178 ./prep_dataset/ILSVRC2012_val_00021035.bin 224 224 +5179 ./prep_dataset/ILSVRC2012_val_00009507.bin 224 224 +5180 ./prep_dataset/ILSVRC2012_val_00011438.bin 224 224 +5181 ./prep_dataset/ILSVRC2012_val_00047506.bin 224 224 +5182 ./prep_dataset/ILSVRC2012_val_00035220.bin 224 224 +5183 ./prep_dataset/ILSVRC2012_val_00037865.bin 224 224 +5184 ./prep_dataset/ILSVRC2012_val_00025381.bin 224 224 +5185 ./prep_dataset/ILSVRC2012_val_00045285.bin 224 224 +5186 ./prep_dataset/ILSVRC2012_val_00011884.bin 224 224 +5187 ./prep_dataset/ILSVRC2012_val_00006132.bin 224 224 +5188 ./prep_dataset/ILSVRC2012_val_00009958.bin 224 224 +5189 ./prep_dataset/ILSVRC2012_val_00043270.bin 224 224 +5190 ./prep_dataset/ILSVRC2012_val_00026332.bin 224 224 +5191 ./prep_dataset/ILSVRC2012_val_00032195.bin 224 224 +5192 ./prep_dataset/ILSVRC2012_val_00032136.bin 224 224 +5193 ./prep_dataset/ILSVRC2012_val_00047475.bin 224 224 +5194 ./prep_dataset/ILSVRC2012_val_00030055.bin 224 224 +5195 ./prep_dataset/ILSVRC2012_val_00025895.bin 224 224 +5196 ./prep_dataset/ILSVRC2012_val_00040950.bin 224 224 +5197 ./prep_dataset/ILSVRC2012_val_00010477.bin 224 224 +5198 ./prep_dataset/ILSVRC2012_val_00014729.bin 224 224 +5199 ./prep_dataset/ILSVRC2012_val_00011104.bin 224 224 +5200 ./prep_dataset/ILSVRC2012_val_00029012.bin 224 224 +5201 ./prep_dataset/ILSVRC2012_val_00033249.bin 224 224 +5202 ./prep_dataset/ILSVRC2012_val_00023858.bin 224 224 +5203 ./prep_dataset/ILSVRC2012_val_00028789.bin 224 224 +5204 ./prep_dataset/ILSVRC2012_val_00004987.bin 224 224 +5205 ./prep_dataset/ILSVRC2012_val_00040887.bin 224 224 +5206 ./prep_dataset/ILSVRC2012_val_00043412.bin 224 224 +5207 ./prep_dataset/ILSVRC2012_val_00042788.bin 224 224 +5208 ./prep_dataset/ILSVRC2012_val_00012220.bin 224 224 +5209 ./prep_dataset/ILSVRC2012_val_00012334.bin 224 224 +5210 ./prep_dataset/ILSVRC2012_val_00042310.bin 224 224 +5211 ./prep_dataset/ILSVRC2012_val_00043330.bin 224 224 +5212 ./prep_dataset/ILSVRC2012_val_00029068.bin 224 224 +5213 ./prep_dataset/ILSVRC2012_val_00020409.bin 224 224 +5214 ./prep_dataset/ILSVRC2012_val_00008282.bin 224 224 +5215 ./prep_dataset/ILSVRC2012_val_00049714.bin 224 224 +5216 ./prep_dataset/ILSVRC2012_val_00030929.bin 224 224 +5217 ./prep_dataset/ILSVRC2012_val_00002491.bin 224 224 +5218 ./prep_dataset/ILSVRC2012_val_00042580.bin 224 224 +5219 ./prep_dataset/ILSVRC2012_val_00047180.bin 224 224 +5220 ./prep_dataset/ILSVRC2012_val_00047410.bin 224 224 +5221 ./prep_dataset/ILSVRC2012_val_00035109.bin 224 224 +5222 ./prep_dataset/ILSVRC2012_val_00042755.bin 224 224 +5223 ./prep_dataset/ILSVRC2012_val_00046589.bin 224 224 +5224 ./prep_dataset/ILSVRC2012_val_00034215.bin 224 224 +5225 ./prep_dataset/ILSVRC2012_val_00007168.bin 224 224 +5226 ./prep_dataset/ILSVRC2012_val_00000820.bin 224 224 +5227 ./prep_dataset/ILSVRC2012_val_00007301.bin 224 224 +5228 ./prep_dataset/ILSVRC2012_val_00035034.bin 224 224 +5229 ./prep_dataset/ILSVRC2012_val_00002684.bin 224 224 +5230 ./prep_dataset/ILSVRC2012_val_00029703.bin 224 224 +5231 ./prep_dataset/ILSVRC2012_val_00019604.bin 224 224 +5232 ./prep_dataset/ILSVRC2012_val_00002384.bin 224 224 +5233 ./prep_dataset/ILSVRC2012_val_00020116.bin 224 224 +5234 ./prep_dataset/ILSVRC2012_val_00000143.bin 224 224 +5235 ./prep_dataset/ILSVRC2012_val_00039238.bin 224 224 +5236 ./prep_dataset/ILSVRC2012_val_00046103.bin 224 224 +5237 ./prep_dataset/ILSVRC2012_val_00019076.bin 224 224 +5238 ./prep_dataset/ILSVRC2012_val_00038033.bin 224 224 +5239 ./prep_dataset/ILSVRC2012_val_00026158.bin 224 224 +5240 ./prep_dataset/ILSVRC2012_val_00003046.bin 224 224 +5241 ./prep_dataset/ILSVRC2012_val_00010352.bin 224 224 +5242 ./prep_dataset/ILSVRC2012_val_00012889.bin 224 224 +5243 ./prep_dataset/ILSVRC2012_val_00043109.bin 224 224 +5244 ./prep_dataset/ILSVRC2012_val_00002390.bin 224 224 +5245 ./prep_dataset/ILSVRC2012_val_00035846.bin 224 224 +5246 ./prep_dataset/ILSVRC2012_val_00045625.bin 224 224 +5247 ./prep_dataset/ILSVRC2012_val_00028259.bin 224 224 +5248 ./prep_dataset/ILSVRC2012_val_00048638.bin 224 224 +5249 ./prep_dataset/ILSVRC2012_val_00041048.bin 224 224 +5250 ./prep_dataset/ILSVRC2012_val_00029392.bin 224 224 +5251 ./prep_dataset/ILSVRC2012_val_00044601.bin 224 224 +5252 ./prep_dataset/ILSVRC2012_val_00047294.bin 224 224 +5253 ./prep_dataset/ILSVRC2012_val_00006000.bin 224 224 +5254 ./prep_dataset/ILSVRC2012_val_00007701.bin 224 224 +5255 ./prep_dataset/ILSVRC2012_val_00007783.bin 224 224 +5256 ./prep_dataset/ILSVRC2012_val_00024528.bin 224 224 +5257 ./prep_dataset/ILSVRC2012_val_00030350.bin 224 224 +5258 ./prep_dataset/ILSVRC2012_val_00015883.bin 224 224 +5259 ./prep_dataset/ILSVRC2012_val_00016592.bin 224 224 +5260 ./prep_dataset/ILSVRC2012_val_00010349.bin 224 224 +5261 ./prep_dataset/ILSVRC2012_val_00022527.bin 224 224 +5262 ./prep_dataset/ILSVRC2012_val_00029932.bin 224 224 +5263 ./prep_dataset/ILSVRC2012_val_00006105.bin 224 224 +5264 ./prep_dataset/ILSVRC2012_val_00032852.bin 224 224 +5265 ./prep_dataset/ILSVRC2012_val_00016006.bin 224 224 +5266 ./prep_dataset/ILSVRC2012_val_00006568.bin 224 224 +5267 ./prep_dataset/ILSVRC2012_val_00042595.bin 224 224 +5268 ./prep_dataset/ILSVRC2012_val_00024125.bin 224 224 +5269 ./prep_dataset/ILSVRC2012_val_00005842.bin 224 224 +5270 ./prep_dataset/ILSVRC2012_val_00042961.bin 224 224 +5271 ./prep_dataset/ILSVRC2012_val_00030313.bin 224 224 +5272 ./prep_dataset/ILSVRC2012_val_00043935.bin 224 224 +5273 ./prep_dataset/ILSVRC2012_val_00006320.bin 224 224 +5274 ./prep_dataset/ILSVRC2012_val_00009815.bin 224 224 +5275 ./prep_dataset/ILSVRC2012_val_00015924.bin 224 224 +5276 ./prep_dataset/ILSVRC2012_val_00004108.bin 224 224 +5277 ./prep_dataset/ILSVRC2012_val_00022297.bin 224 224 +5278 ./prep_dataset/ILSVRC2012_val_00038887.bin 224 224 +5279 ./prep_dataset/ILSVRC2012_val_00047860.bin 224 224 +5280 ./prep_dataset/ILSVRC2012_val_00031591.bin 224 224 +5281 ./prep_dataset/ILSVRC2012_val_00019388.bin 224 224 +5282 ./prep_dataset/ILSVRC2012_val_00031631.bin 224 224 +5283 ./prep_dataset/ILSVRC2012_val_00018619.bin 224 224 +5284 ./prep_dataset/ILSVRC2012_val_00047328.bin 224 224 +5285 ./prep_dataset/ILSVRC2012_val_00016333.bin 224 224 +5286 ./prep_dataset/ILSVRC2012_val_00033839.bin 224 224 +5287 ./prep_dataset/ILSVRC2012_val_00007697.bin 224 224 +5288 ./prep_dataset/ILSVRC2012_val_00009268.bin 224 224 +5289 ./prep_dataset/ILSVRC2012_val_00026267.bin 224 224 +5290 ./prep_dataset/ILSVRC2012_val_00033440.bin 224 224 +5291 ./prep_dataset/ILSVRC2012_val_00012183.bin 224 224 +5292 ./prep_dataset/ILSVRC2012_val_00038907.bin 224 224 +5293 ./prep_dataset/ILSVRC2012_val_00014439.bin 224 224 +5294 ./prep_dataset/ILSVRC2012_val_00037985.bin 224 224 +5295 ./prep_dataset/ILSVRC2012_val_00003535.bin 224 224 +5296 ./prep_dataset/ILSVRC2012_val_00029615.bin 224 224 +5297 ./prep_dataset/ILSVRC2012_val_00046235.bin 224 224 +5298 ./prep_dataset/ILSVRC2012_val_00031644.bin 224 224 +5299 ./prep_dataset/ILSVRC2012_val_00044957.bin 224 224 +5300 ./prep_dataset/ILSVRC2012_val_00045030.bin 224 224 +5301 ./prep_dataset/ILSVRC2012_val_00005289.bin 224 224 +5302 ./prep_dataset/ILSVRC2012_val_00021418.bin 224 224 +5303 ./prep_dataset/ILSVRC2012_val_00049030.bin 224 224 +5304 ./prep_dataset/ILSVRC2012_val_00006534.bin 224 224 +5305 ./prep_dataset/ILSVRC2012_val_00047044.bin 224 224 +5306 ./prep_dataset/ILSVRC2012_val_00019957.bin 224 224 +5307 ./prep_dataset/ILSVRC2012_val_00027927.bin 224 224 +5308 ./prep_dataset/ILSVRC2012_val_00009223.bin 224 224 +5309 ./prep_dataset/ILSVRC2012_val_00047788.bin 224 224 +5310 ./prep_dataset/ILSVRC2012_val_00017220.bin 224 224 +5311 ./prep_dataset/ILSVRC2012_val_00030887.bin 224 224 +5312 ./prep_dataset/ILSVRC2012_val_00011315.bin 224 224 +5313 ./prep_dataset/ILSVRC2012_val_00045656.bin 224 224 +5314 ./prep_dataset/ILSVRC2012_val_00005466.bin 224 224 +5315 ./prep_dataset/ILSVRC2012_val_00038332.bin 224 224 +5316 ./prep_dataset/ILSVRC2012_val_00007146.bin 224 224 +5317 ./prep_dataset/ILSVRC2012_val_00030915.bin 224 224 +5318 ./prep_dataset/ILSVRC2012_val_00034714.bin 224 224 +5319 ./prep_dataset/ILSVRC2012_val_00037014.bin 224 224 +5320 ./prep_dataset/ILSVRC2012_val_00039364.bin 224 224 +5321 ./prep_dataset/ILSVRC2012_val_00048127.bin 224 224 +5322 ./prep_dataset/ILSVRC2012_val_00000726.bin 224 224 +5323 ./prep_dataset/ILSVRC2012_val_00020416.bin 224 224 +5324 ./prep_dataset/ILSVRC2012_val_00025671.bin 224 224 +5325 ./prep_dataset/ILSVRC2012_val_00004342.bin 224 224 +5326 ./prep_dataset/ILSVRC2012_val_00025424.bin 224 224 +5327 ./prep_dataset/ILSVRC2012_val_00001537.bin 224 224 +5328 ./prep_dataset/ILSVRC2012_val_00021739.bin 224 224 +5329 ./prep_dataset/ILSVRC2012_val_00016886.bin 224 224 +5330 ./prep_dataset/ILSVRC2012_val_00032859.bin 224 224 +5331 ./prep_dataset/ILSVRC2012_val_00031313.bin 224 224 +5332 ./prep_dataset/ILSVRC2012_val_00047946.bin 224 224 +5333 ./prep_dataset/ILSVRC2012_val_00022459.bin 224 224 +5334 ./prep_dataset/ILSVRC2012_val_00045792.bin 224 224 +5335 ./prep_dataset/ILSVRC2012_val_00045648.bin 224 224 +5336 ./prep_dataset/ILSVRC2012_val_00036065.bin 224 224 +5337 ./prep_dataset/ILSVRC2012_val_00026787.bin 224 224 +5338 ./prep_dataset/ILSVRC2012_val_00041009.bin 224 224 +5339 ./prep_dataset/ILSVRC2012_val_00034299.bin 224 224 +5340 ./prep_dataset/ILSVRC2012_val_00012414.bin 224 224 +5341 ./prep_dataset/ILSVRC2012_val_00011620.bin 224 224 +5342 ./prep_dataset/ILSVRC2012_val_00044145.bin 224 224 +5343 ./prep_dataset/ILSVRC2012_val_00020141.bin 224 224 +5344 ./prep_dataset/ILSVRC2012_val_00003593.bin 224 224 +5345 ./prep_dataset/ILSVRC2012_val_00024470.bin 224 224 +5346 ./prep_dataset/ILSVRC2012_val_00017241.bin 224 224 +5347 ./prep_dataset/ILSVRC2012_val_00011447.bin 224 224 +5348 ./prep_dataset/ILSVRC2012_val_00018178.bin 224 224 +5349 ./prep_dataset/ILSVRC2012_val_00041964.bin 224 224 +5350 ./prep_dataset/ILSVRC2012_val_00016531.bin 224 224 +5351 ./prep_dataset/ILSVRC2012_val_00034127.bin 224 224 +5352 ./prep_dataset/ILSVRC2012_val_00041509.bin 224 224 +5353 ./prep_dataset/ILSVRC2012_val_00018367.bin 224 224 +5354 ./prep_dataset/ILSVRC2012_val_00045632.bin 224 224 +5355 ./prep_dataset/ILSVRC2012_val_00002313.bin 224 224 +5356 ./prep_dataset/ILSVRC2012_val_00033797.bin 224 224 +5357 ./prep_dataset/ILSVRC2012_val_00016706.bin 224 224 +5358 ./prep_dataset/ILSVRC2012_val_00008404.bin 224 224 +5359 ./prep_dataset/ILSVRC2012_val_00025803.bin 224 224 +5360 ./prep_dataset/ILSVRC2012_val_00042619.bin 224 224 +5361 ./prep_dataset/ILSVRC2012_val_00021407.bin 224 224 +5362 ./prep_dataset/ILSVRC2012_val_00031389.bin 224 224 +5363 ./prep_dataset/ILSVRC2012_val_00021712.bin 224 224 +5364 ./prep_dataset/ILSVRC2012_val_00030268.bin 224 224 +5365 ./prep_dataset/ILSVRC2012_val_00017577.bin 224 224 +5366 ./prep_dataset/ILSVRC2012_val_00043129.bin 224 224 +5367 ./prep_dataset/ILSVRC2012_val_00003587.bin 224 224 +5368 ./prep_dataset/ILSVRC2012_val_00001542.bin 224 224 +5369 ./prep_dataset/ILSVRC2012_val_00035843.bin 224 224 +5370 ./prep_dataset/ILSVRC2012_val_00040726.bin 224 224 +5371 ./prep_dataset/ILSVRC2012_val_00015750.bin 224 224 +5372 ./prep_dataset/ILSVRC2012_val_00001564.bin 224 224 +5373 ./prep_dataset/ILSVRC2012_val_00009581.bin 224 224 +5374 ./prep_dataset/ILSVRC2012_val_00043355.bin 224 224 +5375 ./prep_dataset/ILSVRC2012_val_00044850.bin 224 224 +5376 ./prep_dataset/ILSVRC2012_val_00015638.bin 224 224 +5377 ./prep_dataset/ILSVRC2012_val_00045197.bin 224 224 +5378 ./prep_dataset/ILSVRC2012_val_00032438.bin 224 224 +5379 ./prep_dataset/ILSVRC2012_val_00012041.bin 224 224 +5380 ./prep_dataset/ILSVRC2012_val_00011370.bin 224 224 +5381 ./prep_dataset/ILSVRC2012_val_00036470.bin 224 224 +5382 ./prep_dataset/ILSVRC2012_val_00043383.bin 224 224 +5383 ./prep_dataset/ILSVRC2012_val_00013816.bin 224 224 +5384 ./prep_dataset/ILSVRC2012_val_00029780.bin 224 224 +5385 ./prep_dataset/ILSVRC2012_val_00034153.bin 224 224 +5386 ./prep_dataset/ILSVRC2012_val_00032320.bin 224 224 +5387 ./prep_dataset/ILSVRC2012_val_00016184.bin 224 224 +5388 ./prep_dataset/ILSVRC2012_val_00006963.bin 224 224 +5389 ./prep_dataset/ILSVRC2012_val_00029156.bin 224 224 +5390 ./prep_dataset/ILSVRC2012_val_00024388.bin 224 224 +5391 ./prep_dataset/ILSVRC2012_val_00044524.bin 224 224 +5392 ./prep_dataset/ILSVRC2012_val_00018237.bin 224 224 +5393 ./prep_dataset/ILSVRC2012_val_00019166.bin 224 224 +5394 ./prep_dataset/ILSVRC2012_val_00022670.bin 224 224 +5395 ./prep_dataset/ILSVRC2012_val_00047987.bin 224 224 +5396 ./prep_dataset/ILSVRC2012_val_00006303.bin 224 224 +5397 ./prep_dataset/ILSVRC2012_val_00024955.bin 224 224 +5398 ./prep_dataset/ILSVRC2012_val_00034446.bin 224 224 +5399 ./prep_dataset/ILSVRC2012_val_00034067.bin 224 224 +5400 ./prep_dataset/ILSVRC2012_val_00027090.bin 224 224 +5401 ./prep_dataset/ILSVRC2012_val_00029862.bin 224 224 +5402 ./prep_dataset/ILSVRC2012_val_00021137.bin 224 224 +5403 ./prep_dataset/ILSVRC2012_val_00028434.bin 224 224 +5404 ./prep_dataset/ILSVRC2012_val_00035529.bin 224 224 +5405 ./prep_dataset/ILSVRC2012_val_00029015.bin 224 224 +5406 ./prep_dataset/ILSVRC2012_val_00033714.bin 224 224 +5407 ./prep_dataset/ILSVRC2012_val_00033412.bin 224 224 +5408 ./prep_dataset/ILSVRC2012_val_00016623.bin 224 224 +5409 ./prep_dataset/ILSVRC2012_val_00002330.bin 224 224 +5410 ./prep_dataset/ILSVRC2012_val_00014288.bin 224 224 +5411 ./prep_dataset/ILSVRC2012_val_00044282.bin 224 224 +5412 ./prep_dataset/ILSVRC2012_val_00011901.bin 224 224 +5413 ./prep_dataset/ILSVRC2012_val_00005704.bin 224 224 +5414 ./prep_dataset/ILSVRC2012_val_00031846.bin 224 224 +5415 ./prep_dataset/ILSVRC2012_val_00004945.bin 224 224 +5416 ./prep_dataset/ILSVRC2012_val_00010995.bin 224 224 +5417 ./prep_dataset/ILSVRC2012_val_00003140.bin 224 224 +5418 ./prep_dataset/ILSVRC2012_val_00036818.bin 224 224 +5419 ./prep_dataset/ILSVRC2012_val_00034025.bin 224 224 +5420 ./prep_dataset/ILSVRC2012_val_00031598.bin 224 224 +5421 ./prep_dataset/ILSVRC2012_val_00046615.bin 224 224 +5422 ./prep_dataset/ILSVRC2012_val_00018603.bin 224 224 +5423 ./prep_dataset/ILSVRC2012_val_00001166.bin 224 224 +5424 ./prep_dataset/ILSVRC2012_val_00045255.bin 224 224 +5425 ./prep_dataset/ILSVRC2012_val_00024868.bin 224 224 +5426 ./prep_dataset/ILSVRC2012_val_00025135.bin 224 224 +5427 ./prep_dataset/ILSVRC2012_val_00015024.bin 224 224 +5428 ./prep_dataset/ILSVRC2012_val_00012624.bin 224 224 +5429 ./prep_dataset/ILSVRC2012_val_00005818.bin 224 224 +5430 ./prep_dataset/ILSVRC2012_val_00021901.bin 224 224 +5431 ./prep_dataset/ILSVRC2012_val_00017111.bin 224 224 +5432 ./prep_dataset/ILSVRC2012_val_00036151.bin 224 224 +5433 ./prep_dataset/ILSVRC2012_val_00048974.bin 224 224 +5434 ./prep_dataset/ILSVRC2012_val_00017573.bin 224 224 +5435 ./prep_dataset/ILSVRC2012_val_00007683.bin 224 224 +5436 ./prep_dataset/ILSVRC2012_val_00012775.bin 224 224 +5437 ./prep_dataset/ILSVRC2012_val_00042413.bin 224 224 +5438 ./prep_dataset/ILSVRC2012_val_00029959.bin 224 224 +5439 ./prep_dataset/ILSVRC2012_val_00032818.bin 224 224 +5440 ./prep_dataset/ILSVRC2012_val_00015662.bin 224 224 +5441 ./prep_dataset/ILSVRC2012_val_00015152.bin 224 224 +5442 ./prep_dataset/ILSVRC2012_val_00047588.bin 224 224 +5443 ./prep_dataset/ILSVRC2012_val_00020798.bin 224 224 +5444 ./prep_dataset/ILSVRC2012_val_00044904.bin 224 224 +5445 ./prep_dataset/ILSVRC2012_val_00028252.bin 224 224 +5446 ./prep_dataset/ILSVRC2012_val_00003380.bin 224 224 +5447 ./prep_dataset/ILSVRC2012_val_00038773.bin 224 224 +5448 ./prep_dataset/ILSVRC2012_val_00022091.bin 224 224 +5449 ./prep_dataset/ILSVRC2012_val_00026396.bin 224 224 +5450 ./prep_dataset/ILSVRC2012_val_00044451.bin 224 224 +5451 ./prep_dataset/ILSVRC2012_val_00001193.bin 224 224 +5452 ./prep_dataset/ILSVRC2012_val_00025772.bin 224 224 +5453 ./prep_dataset/ILSVRC2012_val_00028750.bin 224 224 +5454 ./prep_dataset/ILSVRC2012_val_00043157.bin 224 224 +5455 ./prep_dataset/ILSVRC2012_val_00033618.bin 224 224 +5456 ./prep_dataset/ILSVRC2012_val_00041687.bin 224 224 +5457 ./prep_dataset/ILSVRC2012_val_00028593.bin 224 224 +5458 ./prep_dataset/ILSVRC2012_val_00019660.bin 224 224 +5459 ./prep_dataset/ILSVRC2012_val_00007800.bin 224 224 +5460 ./prep_dataset/ILSVRC2012_val_00021787.bin 224 224 +5461 ./prep_dataset/ILSVRC2012_val_00004626.bin 224 224 +5462 ./prep_dataset/ILSVRC2012_val_00019382.bin 224 224 +5463 ./prep_dataset/ILSVRC2012_val_00039578.bin 224 224 +5464 ./prep_dataset/ILSVRC2012_val_00031273.bin 224 224 +5465 ./prep_dataset/ILSVRC2012_val_00000295.bin 224 224 +5466 ./prep_dataset/ILSVRC2012_val_00041231.bin 224 224 +5467 ./prep_dataset/ILSVRC2012_val_00000774.bin 224 224 +5468 ./prep_dataset/ILSVRC2012_val_00035691.bin 224 224 +5469 ./prep_dataset/ILSVRC2012_val_00022422.bin 224 224 +5470 ./prep_dataset/ILSVRC2012_val_00005771.bin 224 224 +5471 ./prep_dataset/ILSVRC2012_val_00009420.bin 224 224 +5472 ./prep_dataset/ILSVRC2012_val_00024180.bin 224 224 +5473 ./prep_dataset/ILSVRC2012_val_00039349.bin 224 224 +5474 ./prep_dataset/ILSVRC2012_val_00018583.bin 224 224 +5475 ./prep_dataset/ILSVRC2012_val_00040264.bin 224 224 +5476 ./prep_dataset/ILSVRC2012_val_00032804.bin 224 224 +5477 ./prep_dataset/ILSVRC2012_val_00011887.bin 224 224 +5478 ./prep_dataset/ILSVRC2012_val_00029798.bin 224 224 +5479 ./prep_dataset/ILSVRC2012_val_00037886.bin 224 224 +5480 ./prep_dataset/ILSVRC2012_val_00008138.bin 224 224 +5481 ./prep_dataset/ILSVRC2012_val_00007651.bin 224 224 +5482 ./prep_dataset/ILSVRC2012_val_00011721.bin 224 224 +5483 ./prep_dataset/ILSVRC2012_val_00038582.bin 224 224 +5484 ./prep_dataset/ILSVRC2012_val_00023354.bin 224 224 +5485 ./prep_dataset/ILSVRC2012_val_00020287.bin 224 224 +5486 ./prep_dataset/ILSVRC2012_val_00018139.bin 224 224 +5487 ./prep_dataset/ILSVRC2012_val_00023135.bin 224 224 +5488 ./prep_dataset/ILSVRC2012_val_00011212.bin 224 224 +5489 ./prep_dataset/ILSVRC2012_val_00013977.bin 224 224 +5490 ./prep_dataset/ILSVRC2012_val_00027340.bin 224 224 +5491 ./prep_dataset/ILSVRC2012_val_00030785.bin 224 224 +5492 ./prep_dataset/ILSVRC2012_val_00036869.bin 224 224 +5493 ./prep_dataset/ILSVRC2012_val_00046067.bin 224 224 +5494 ./prep_dataset/ILSVRC2012_val_00020752.bin 224 224 +5495 ./prep_dataset/ILSVRC2012_val_00007939.bin 224 224 +5496 ./prep_dataset/ILSVRC2012_val_00004583.bin 224 224 +5497 ./prep_dataset/ILSVRC2012_val_00034737.bin 224 224 +5498 ./prep_dataset/ILSVRC2012_val_00000050.bin 224 224 +5499 ./prep_dataset/ILSVRC2012_val_00029136.bin 224 224 +5500 ./prep_dataset/ILSVRC2012_val_00016189.bin 224 224 +5501 ./prep_dataset/ILSVRC2012_val_00012855.bin 224 224 +5502 ./prep_dataset/ILSVRC2012_val_00040107.bin 224 224 +5503 ./prep_dataset/ILSVRC2012_val_00033755.bin 224 224 +5504 ./prep_dataset/ILSVRC2012_val_00010986.bin 224 224 +5505 ./prep_dataset/ILSVRC2012_val_00045312.bin 224 224 +5506 ./prep_dataset/ILSVRC2012_val_00020294.bin 224 224 +5507 ./prep_dataset/ILSVRC2012_val_00014201.bin 224 224 +5508 ./prep_dataset/ILSVRC2012_val_00028127.bin 224 224 +5509 ./prep_dataset/ILSVRC2012_val_00039498.bin 224 224 +5510 ./prep_dataset/ILSVRC2012_val_00023877.bin 224 224 +5511 ./prep_dataset/ILSVRC2012_val_00025750.bin 224 224 +5512 ./prep_dataset/ILSVRC2012_val_00012605.bin 224 224 +5513 ./prep_dataset/ILSVRC2012_val_00005889.bin 224 224 +5514 ./prep_dataset/ILSVRC2012_val_00047345.bin 224 224 +5515 ./prep_dataset/ILSVRC2012_val_00011980.bin 224 224 +5516 ./prep_dataset/ILSVRC2012_val_00025898.bin 224 224 +5517 ./prep_dataset/ILSVRC2012_val_00011762.bin 224 224 +5518 ./prep_dataset/ILSVRC2012_val_00009451.bin 224 224 +5519 ./prep_dataset/ILSVRC2012_val_00045537.bin 224 224 +5520 ./prep_dataset/ILSVRC2012_val_00028781.bin 224 224 +5521 ./prep_dataset/ILSVRC2012_val_00035475.bin 224 224 +5522 ./prep_dataset/ILSVRC2012_val_00015417.bin 224 224 +5523 ./prep_dataset/ILSVRC2012_val_00005985.bin 224 224 +5524 ./prep_dataset/ILSVRC2012_val_00026517.bin 224 224 +5525 ./prep_dataset/ILSVRC2012_val_00047997.bin 224 224 +5526 ./prep_dataset/ILSVRC2012_val_00023891.bin 224 224 +5527 ./prep_dataset/ILSVRC2012_val_00030998.bin 224 224 +5528 ./prep_dataset/ILSVRC2012_val_00024292.bin 224 224 +5529 ./prep_dataset/ILSVRC2012_val_00044969.bin 224 224 +5530 ./prep_dataset/ILSVRC2012_val_00026199.bin 224 224 +5531 ./prep_dataset/ILSVRC2012_val_00027312.bin 224 224 +5532 ./prep_dataset/ILSVRC2012_val_00013011.bin 224 224 +5533 ./prep_dataset/ILSVRC2012_val_00034627.bin 224 224 +5534 ./prep_dataset/ILSVRC2012_val_00040556.bin 224 224 +5535 ./prep_dataset/ILSVRC2012_val_00046204.bin 224 224 +5536 ./prep_dataset/ILSVRC2012_val_00041570.bin 224 224 +5537 ./prep_dataset/ILSVRC2012_val_00003730.bin 224 224 +5538 ./prep_dataset/ILSVRC2012_val_00019596.bin 224 224 +5539 ./prep_dataset/ILSVRC2012_val_00013372.bin 224 224 +5540 ./prep_dataset/ILSVRC2012_val_00021245.bin 224 224 +5541 ./prep_dataset/ILSVRC2012_val_00019023.bin 224 224 +5542 ./prep_dataset/ILSVRC2012_val_00033802.bin 224 224 +5543 ./prep_dataset/ILSVRC2012_val_00036258.bin 224 224 +5544 ./prep_dataset/ILSVRC2012_val_00014330.bin 224 224 +5545 ./prep_dataset/ILSVRC2012_val_00026300.bin 224 224 +5546 ./prep_dataset/ILSVRC2012_val_00036773.bin 224 224 +5547 ./prep_dataset/ILSVRC2012_val_00004753.bin 224 224 +5548 ./prep_dataset/ILSVRC2012_val_00037036.bin 224 224 +5549 ./prep_dataset/ILSVRC2012_val_00025588.bin 224 224 +5550 ./prep_dataset/ILSVRC2012_val_00018689.bin 224 224 +5551 ./prep_dataset/ILSVRC2012_val_00005887.bin 224 224 +5552 ./prep_dataset/ILSVRC2012_val_00034549.bin 224 224 +5553 ./prep_dataset/ILSVRC2012_val_00012209.bin 224 224 +5554 ./prep_dataset/ILSVRC2012_val_00026632.bin 224 224 +5555 ./prep_dataset/ILSVRC2012_val_00008306.bin 224 224 +5556 ./prep_dataset/ILSVRC2012_val_00011935.bin 224 224 +5557 ./prep_dataset/ILSVRC2012_val_00045170.bin 224 224 +5558 ./prep_dataset/ILSVRC2012_val_00036135.bin 224 224 +5559 ./prep_dataset/ILSVRC2012_val_00038189.bin 224 224 +5560 ./prep_dataset/ILSVRC2012_val_00002426.bin 224 224 +5561 ./prep_dataset/ILSVRC2012_val_00028369.bin 224 224 +5562 ./prep_dataset/ILSVRC2012_val_00040752.bin 224 224 +5563 ./prep_dataset/ILSVRC2012_val_00028796.bin 224 224 +5564 ./prep_dataset/ILSVRC2012_val_00038568.bin 224 224 +5565 ./prep_dataset/ILSVRC2012_val_00007253.bin 224 224 +5566 ./prep_dataset/ILSVRC2012_val_00047722.bin 224 224 +5567 ./prep_dataset/ILSVRC2012_val_00007467.bin 224 224 +5568 ./prep_dataset/ILSVRC2012_val_00014058.bin 224 224 +5569 ./prep_dataset/ILSVRC2012_val_00008512.bin 224 224 +5570 ./prep_dataset/ILSVRC2012_val_00038489.bin 224 224 +5571 ./prep_dataset/ILSVRC2012_val_00001504.bin 224 224 +5572 ./prep_dataset/ILSVRC2012_val_00001415.bin 224 224 +5573 ./prep_dataset/ILSVRC2012_val_00012542.bin 224 224 +5574 ./prep_dataset/ILSVRC2012_val_00015113.bin 224 224 +5575 ./prep_dataset/ILSVRC2012_val_00005381.bin 224 224 +5576 ./prep_dataset/ILSVRC2012_val_00020769.bin 224 224 +5577 ./prep_dataset/ILSVRC2012_val_00027692.bin 224 224 +5578 ./prep_dataset/ILSVRC2012_val_00017356.bin 224 224 +5579 ./prep_dataset/ILSVRC2012_val_00027446.bin 224 224 +5580 ./prep_dataset/ILSVRC2012_val_00003364.bin 224 224 +5581 ./prep_dataset/ILSVRC2012_val_00015877.bin 224 224 +5582 ./prep_dataset/ILSVRC2012_val_00024307.bin 224 224 +5583 ./prep_dataset/ILSVRC2012_val_00036314.bin 224 224 +5584 ./prep_dataset/ILSVRC2012_val_00031067.bin 224 224 +5585 ./prep_dataset/ILSVRC2012_val_00013374.bin 224 224 +5586 ./prep_dataset/ILSVRC2012_val_00029630.bin 224 224 +5587 ./prep_dataset/ILSVRC2012_val_00006054.bin 224 224 +5588 ./prep_dataset/ILSVRC2012_val_00011770.bin 224 224 +5589 ./prep_dataset/ILSVRC2012_val_00029835.bin 224 224 +5590 ./prep_dataset/ILSVRC2012_val_00033745.bin 224 224 +5591 ./prep_dataset/ILSVRC2012_val_00022982.bin 224 224 +5592 ./prep_dataset/ILSVRC2012_val_00045614.bin 224 224 +5593 ./prep_dataset/ILSVRC2012_val_00020741.bin 224 224 +5594 ./prep_dataset/ILSVRC2012_val_00000413.bin 224 224 +5595 ./prep_dataset/ILSVRC2012_val_00012441.bin 224 224 +5596 ./prep_dataset/ILSVRC2012_val_00001293.bin 224 224 +5597 ./prep_dataset/ILSVRC2012_val_00037150.bin 224 224 +5598 ./prep_dataset/ILSVRC2012_val_00041013.bin 224 224 +5599 ./prep_dataset/ILSVRC2012_val_00024309.bin 224 224 +5600 ./prep_dataset/ILSVRC2012_val_00003063.bin 224 224 +5601 ./prep_dataset/ILSVRC2012_val_00012165.bin 224 224 +5602 ./prep_dataset/ILSVRC2012_val_00032108.bin 224 224 +5603 ./prep_dataset/ILSVRC2012_val_00022516.bin 224 224 +5604 ./prep_dataset/ILSVRC2012_val_00025841.bin 224 224 +5605 ./prep_dataset/ILSVRC2012_val_00020056.bin 224 224 +5606 ./prep_dataset/ILSVRC2012_val_00048125.bin 224 224 +5607 ./prep_dataset/ILSVRC2012_val_00001408.bin 224 224 +5608 ./prep_dataset/ILSVRC2012_val_00019554.bin 224 224 +5609 ./prep_dataset/ILSVRC2012_val_00038726.bin 224 224 +5610 ./prep_dataset/ILSVRC2012_val_00020716.bin 224 224 +5611 ./prep_dataset/ILSVRC2012_val_00016313.bin 224 224 +5612 ./prep_dataset/ILSVRC2012_val_00005670.bin 224 224 +5613 ./prep_dataset/ILSVRC2012_val_00014352.bin 224 224 +5614 ./prep_dataset/ILSVRC2012_val_00017424.bin 224 224 +5615 ./prep_dataset/ILSVRC2012_val_00035606.bin 224 224 +5616 ./prep_dataset/ILSVRC2012_val_00040597.bin 224 224 +5617 ./prep_dataset/ILSVRC2012_val_00038751.bin 224 224 +5618 ./prep_dataset/ILSVRC2012_val_00011963.bin 224 224 +5619 ./prep_dataset/ILSVRC2012_val_00024507.bin 224 224 +5620 ./prep_dataset/ILSVRC2012_val_00036788.bin 224 224 +5621 ./prep_dataset/ILSVRC2012_val_00024391.bin 224 224 +5622 ./prep_dataset/ILSVRC2012_val_00044501.bin 224 224 +5623 ./prep_dataset/ILSVRC2012_val_00045654.bin 224 224 +5624 ./prep_dataset/ILSVRC2012_val_00038936.bin 224 224 +5625 ./prep_dataset/ILSVRC2012_val_00029914.bin 224 224 +5626 ./prep_dataset/ILSVRC2012_val_00026216.bin 224 224 +5627 ./prep_dataset/ILSVRC2012_val_00043403.bin 224 224 +5628 ./prep_dataset/ILSVRC2012_val_00044391.bin 224 224 +5629 ./prep_dataset/ILSVRC2012_val_00035736.bin 224 224 +5630 ./prep_dataset/ILSVRC2012_val_00036638.bin 224 224 +5631 ./prep_dataset/ILSVRC2012_val_00048083.bin 224 224 +5632 ./prep_dataset/ILSVRC2012_val_00013044.bin 224 224 +5633 ./prep_dataset/ILSVRC2012_val_00034540.bin 224 224 +5634 ./prep_dataset/ILSVRC2012_val_00025764.bin 224 224 +5635 ./prep_dataset/ILSVRC2012_val_00048820.bin 224 224 +5636 ./prep_dataset/ILSVRC2012_val_00027871.bin 224 224 +5637 ./prep_dataset/ILSVRC2012_val_00038859.bin 224 224 +5638 ./prep_dataset/ILSVRC2012_val_00037919.bin 224 224 +5639 ./prep_dataset/ILSVRC2012_val_00033236.bin 224 224 +5640 ./prep_dataset/ILSVRC2012_val_00024218.bin 224 224 +5641 ./prep_dataset/ILSVRC2012_val_00016702.bin 224 224 +5642 ./prep_dataset/ILSVRC2012_val_00040229.bin 224 224 +5643 ./prep_dataset/ILSVRC2012_val_00031482.bin 224 224 +5644 ./prep_dataset/ILSVRC2012_val_00000118.bin 224 224 +5645 ./prep_dataset/ILSVRC2012_val_00049493.bin 224 224 +5646 ./prep_dataset/ILSVRC2012_val_00016226.bin 224 224 +5647 ./prep_dataset/ILSVRC2012_val_00005690.bin 224 224 +5648 ./prep_dataset/ILSVRC2012_val_00038670.bin 224 224 +5649 ./prep_dataset/ILSVRC2012_val_00023501.bin 224 224 +5650 ./prep_dataset/ILSVRC2012_val_00029649.bin 224 224 +5651 ./prep_dataset/ILSVRC2012_val_00016266.bin 224 224 +5652 ./prep_dataset/ILSVRC2012_val_00047467.bin 224 224 +5653 ./prep_dataset/ILSVRC2012_val_00035172.bin 224 224 +5654 ./prep_dataset/ILSVRC2012_val_00038191.bin 224 224 +5655 ./prep_dataset/ILSVRC2012_val_00017113.bin 224 224 +5656 ./prep_dataset/ILSVRC2012_val_00037504.bin 224 224 +5657 ./prep_dataset/ILSVRC2012_val_00036766.bin 224 224 +5658 ./prep_dataset/ILSVRC2012_val_00017831.bin 224 224 +5659 ./prep_dataset/ILSVRC2012_val_00035292.bin 224 224 +5660 ./prep_dataset/ILSVRC2012_val_00028950.bin 224 224 +5661 ./prep_dataset/ILSVRC2012_val_00021073.bin 224 224 +5662 ./prep_dataset/ILSVRC2012_val_00017362.bin 224 224 +5663 ./prep_dataset/ILSVRC2012_val_00007042.bin 224 224 +5664 ./prep_dataset/ILSVRC2012_val_00012013.bin 224 224 +5665 ./prep_dataset/ILSVRC2012_val_00047086.bin 224 224 +5666 ./prep_dataset/ILSVRC2012_val_00011842.bin 224 224 +5667 ./prep_dataset/ILSVRC2012_val_00045937.bin 224 224 +5668 ./prep_dataset/ILSVRC2012_val_00041511.bin 224 224 +5669 ./prep_dataset/ILSVRC2012_val_00007991.bin 224 224 +5670 ./prep_dataset/ILSVRC2012_val_00045231.bin 224 224 +5671 ./prep_dataset/ILSVRC2012_val_00037747.bin 224 224 +5672 ./prep_dataset/ILSVRC2012_val_00041525.bin 224 224 +5673 ./prep_dataset/ILSVRC2012_val_00042060.bin 224 224 +5674 ./prep_dataset/ILSVRC2012_val_00029507.bin 224 224 +5675 ./prep_dataset/ILSVRC2012_val_00010842.bin 224 224 +5676 ./prep_dataset/ILSVRC2012_val_00029976.bin 224 224 +5677 ./prep_dataset/ILSVRC2012_val_00032860.bin 224 224 +5678 ./prep_dataset/ILSVRC2012_val_00023365.bin 224 224 +5679 ./prep_dataset/ILSVRC2012_val_00032968.bin 224 224 +5680 ./prep_dataset/ILSVRC2012_val_00017128.bin 224 224 +5681 ./prep_dataset/ILSVRC2012_val_00043335.bin 224 224 +5682 ./prep_dataset/ILSVRC2012_val_00028117.bin 224 224 +5683 ./prep_dataset/ILSVRC2012_val_00039291.bin 224 224 +5684 ./prep_dataset/ILSVRC2012_val_00032978.bin 224 224 +5685 ./prep_dataset/ILSVRC2012_val_00045252.bin 224 224 +5686 ./prep_dataset/ILSVRC2012_val_00012254.bin 224 224 +5687 ./prep_dataset/ILSVRC2012_val_00043320.bin 224 224 +5688 ./prep_dataset/ILSVRC2012_val_00031729.bin 224 224 +5689 ./prep_dataset/ILSVRC2012_val_00001273.bin 224 224 +5690 ./prep_dataset/ILSVRC2012_val_00021958.bin 224 224 +5691 ./prep_dataset/ILSVRC2012_val_00018643.bin 224 224 +5692 ./prep_dataset/ILSVRC2012_val_00014889.bin 224 224 +5693 ./prep_dataset/ILSVRC2012_val_00043653.bin 224 224 +5694 ./prep_dataset/ILSVRC2012_val_00031792.bin 224 224 +5695 ./prep_dataset/ILSVRC2012_val_00011258.bin 224 224 +5696 ./prep_dataset/ILSVRC2012_val_00042837.bin 224 224 +5697 ./prep_dataset/ILSVRC2012_val_00031489.bin 224 224 +5698 ./prep_dataset/ILSVRC2012_val_00018080.bin 224 224 +5699 ./prep_dataset/ILSVRC2012_val_00004310.bin 224 224 +5700 ./prep_dataset/ILSVRC2012_val_00048948.bin 224 224 +5701 ./prep_dataset/ILSVRC2012_val_00014042.bin 224 224 +5702 ./prep_dataset/ILSVRC2012_val_00031320.bin 224 224 +5703 ./prep_dataset/ILSVRC2012_val_00038303.bin 224 224 +5704 ./prep_dataset/ILSVRC2012_val_00002932.bin 224 224 +5705 ./prep_dataset/ILSVRC2012_val_00024601.bin 224 224 +5706 ./prep_dataset/ILSVRC2012_val_00000354.bin 224 224 +5707 ./prep_dataset/ILSVRC2012_val_00016264.bin 224 224 +5708 ./prep_dataset/ILSVRC2012_val_00041451.bin 224 224 +5709 ./prep_dataset/ILSVRC2012_val_00030296.bin 224 224 +5710 ./prep_dataset/ILSVRC2012_val_00000462.bin 224 224 +5711 ./prep_dataset/ILSVRC2012_val_00018664.bin 224 224 +5712 ./prep_dataset/ILSVRC2012_val_00046856.bin 224 224 +5713 ./prep_dataset/ILSVRC2012_val_00009312.bin 224 224 +5714 ./prep_dataset/ILSVRC2012_val_00005795.bin 224 224 +5715 ./prep_dataset/ILSVRC2012_val_00026583.bin 224 224 +5716 ./prep_dataset/ILSVRC2012_val_00014133.bin 224 224 +5717 ./prep_dataset/ILSVRC2012_val_00038262.bin 224 224 +5718 ./prep_dataset/ILSVRC2012_val_00042638.bin 224 224 +5719 ./prep_dataset/ILSVRC2012_val_00007949.bin 224 224 +5720 ./prep_dataset/ILSVRC2012_val_00000797.bin 224 224 +5721 ./prep_dataset/ILSVRC2012_val_00009070.bin 224 224 +5722 ./prep_dataset/ILSVRC2012_val_00046219.bin 224 224 +5723 ./prep_dataset/ILSVRC2012_val_00023255.bin 224 224 +5724 ./prep_dataset/ILSVRC2012_val_00018376.bin 224 224 +5725 ./prep_dataset/ILSVRC2012_val_00034961.bin 224 224 +5726 ./prep_dataset/ILSVRC2012_val_00018872.bin 224 224 +5727 ./prep_dataset/ILSVRC2012_val_00039550.bin 224 224 +5728 ./prep_dataset/ILSVRC2012_val_00000493.bin 224 224 +5729 ./prep_dataset/ILSVRC2012_val_00024720.bin 224 224 +5730 ./prep_dataset/ILSVRC2012_val_00025022.bin 224 224 +5731 ./prep_dataset/ILSVRC2012_val_00002301.bin 224 224 +5732 ./prep_dataset/ILSVRC2012_val_00013614.bin 224 224 +5733 ./prep_dataset/ILSVRC2012_val_00044658.bin 224 224 +5734 ./prep_dataset/ILSVRC2012_val_00040464.bin 224 224 +5735 ./prep_dataset/ILSVRC2012_val_00018749.bin 224 224 +5736 ./prep_dataset/ILSVRC2012_val_00033036.bin 224 224 +5737 ./prep_dataset/ILSVRC2012_val_00015472.bin 224 224 +5738 ./prep_dataset/ILSVRC2012_val_00013714.bin 224 224 +5739 ./prep_dataset/ILSVRC2012_val_00022108.bin 224 224 +5740 ./prep_dataset/ILSVRC2012_val_00032879.bin 224 224 +5741 ./prep_dataset/ILSVRC2012_val_00039216.bin 224 224 +5742 ./prep_dataset/ILSVRC2012_val_00027106.bin 224 224 +5743 ./prep_dataset/ILSVRC2012_val_00019114.bin 224 224 +5744 ./prep_dataset/ILSVRC2012_val_00006247.bin 224 224 +5745 ./prep_dataset/ILSVRC2012_val_00046295.bin 224 224 +5746 ./prep_dataset/ILSVRC2012_val_00030493.bin 224 224 +5747 ./prep_dataset/ILSVRC2012_val_00043957.bin 224 224 +5748 ./prep_dataset/ILSVRC2012_val_00026693.bin 224 224 +5749 ./prep_dataset/ILSVRC2012_val_00020198.bin 224 224 +5750 ./prep_dataset/ILSVRC2012_val_00028189.bin 224 224 +5751 ./prep_dataset/ILSVRC2012_val_00009478.bin 224 224 +5752 ./prep_dataset/ILSVRC2012_val_00003960.bin 224 224 +5753 ./prep_dataset/ILSVRC2012_val_00030991.bin 224 224 +5754 ./prep_dataset/ILSVRC2012_val_00023816.bin 224 224 +5755 ./prep_dataset/ILSVRC2012_val_00038111.bin 224 224 +5756 ./prep_dataset/ILSVRC2012_val_00025767.bin 224 224 +5757 ./prep_dataset/ILSVRC2012_val_00035628.bin 224 224 +5758 ./prep_dataset/ILSVRC2012_val_00002725.bin 224 224 +5759 ./prep_dataset/ILSVRC2012_val_00029111.bin 224 224 +5760 ./prep_dataset/ILSVRC2012_val_00012201.bin 224 224 +5761 ./prep_dataset/ILSVRC2012_val_00020166.bin 224 224 +5762 ./prep_dataset/ILSVRC2012_val_00015849.bin 224 224 +5763 ./prep_dataset/ILSVRC2012_val_00005687.bin 224 224 +5764 ./prep_dataset/ILSVRC2012_val_00037353.bin 224 224 +5765 ./prep_dataset/ILSVRC2012_val_00029778.bin 224 224 +5766 ./prep_dataset/ILSVRC2012_val_00049857.bin 224 224 +5767 ./prep_dataset/ILSVRC2012_val_00005521.bin 224 224 +5768 ./prep_dataset/ILSVRC2012_val_00021632.bin 224 224 +5769 ./prep_dataset/ILSVRC2012_val_00009419.bin 224 224 +5770 ./prep_dataset/ILSVRC2012_val_00009730.bin 224 224 +5771 ./prep_dataset/ILSVRC2012_val_00038633.bin 224 224 +5772 ./prep_dataset/ILSVRC2012_val_00047170.bin 224 224 +5773 ./prep_dataset/ILSVRC2012_val_00005490.bin 224 224 +5774 ./prep_dataset/ILSVRC2012_val_00034649.bin 224 224 +5775 ./prep_dataset/ILSVRC2012_val_00039533.bin 224 224 +5776 ./prep_dataset/ILSVRC2012_val_00022577.bin 224 224 +5777 ./prep_dataset/ILSVRC2012_val_00032269.bin 224 224 +5778 ./prep_dataset/ILSVRC2012_val_00034068.bin 224 224 +5779 ./prep_dataset/ILSVRC2012_val_00028394.bin 224 224 +5780 ./prep_dataset/ILSVRC2012_val_00035461.bin 224 224 +5781 ./prep_dataset/ILSVRC2012_val_00005118.bin 224 224 +5782 ./prep_dataset/ILSVRC2012_val_00030129.bin 224 224 +5783 ./prep_dataset/ILSVRC2012_val_00001153.bin 224 224 +5784 ./prep_dataset/ILSVRC2012_val_00039606.bin 224 224 +5785 ./prep_dataset/ILSVRC2012_val_00029646.bin 224 224 +5786 ./prep_dataset/ILSVRC2012_val_00008751.bin 224 224 +5787 ./prep_dataset/ILSVRC2012_val_00034803.bin 224 224 +5788 ./prep_dataset/ILSVRC2012_val_00011726.bin 224 224 +5789 ./prep_dataset/ILSVRC2012_val_00017544.bin 224 224 +5790 ./prep_dataset/ILSVRC2012_val_00035198.bin 224 224 +5791 ./prep_dataset/ILSVRC2012_val_00007555.bin 224 224 +5792 ./prep_dataset/ILSVRC2012_val_00007230.bin 224 224 +5793 ./prep_dataset/ILSVRC2012_val_00021100.bin 224 224 +5794 ./prep_dataset/ILSVRC2012_val_00029720.bin 224 224 +5795 ./prep_dataset/ILSVRC2012_val_00010837.bin 224 224 +5796 ./prep_dataset/ILSVRC2012_val_00000495.bin 224 224 +5797 ./prep_dataset/ILSVRC2012_val_00007494.bin 224 224 +5798 ./prep_dataset/ILSVRC2012_val_00038116.bin 224 224 +5799 ./prep_dataset/ILSVRC2012_val_00036501.bin 224 224 +5800 ./prep_dataset/ILSVRC2012_val_00025062.bin 224 224 +5801 ./prep_dataset/ILSVRC2012_val_00003990.bin 224 224 +5802 ./prep_dataset/ILSVRC2012_val_00024865.bin 224 224 +5803 ./prep_dataset/ILSVRC2012_val_00010820.bin 224 224 +5804 ./prep_dataset/ILSVRC2012_val_00046438.bin 224 224 +5805 ./prep_dataset/ILSVRC2012_val_00031629.bin 224 224 +5806 ./prep_dataset/ILSVRC2012_val_00028449.bin 224 224 +5807 ./prep_dataset/ILSVRC2012_val_00020512.bin 224 224 +5808 ./prep_dataset/ILSVRC2012_val_00042142.bin 224 224 +5809 ./prep_dataset/ILSVRC2012_val_00041686.bin 224 224 +5810 ./prep_dataset/ILSVRC2012_val_00039736.bin 224 224 +5811 ./prep_dataset/ILSVRC2012_val_00006214.bin 224 224 +5812 ./prep_dataset/ILSVRC2012_val_00049662.bin 224 224 +5813 ./prep_dataset/ILSVRC2012_val_00047967.bin 224 224 +5814 ./prep_dataset/ILSVRC2012_val_00006439.bin 224 224 +5815 ./prep_dataset/ILSVRC2012_val_00026661.bin 224 224 +5816 ./prep_dataset/ILSVRC2012_val_00021187.bin 224 224 +5817 ./prep_dataset/ILSVRC2012_val_00034207.bin 224 224 +5818 ./prep_dataset/ILSVRC2012_val_00044680.bin 224 224 +5819 ./prep_dataset/ILSVRC2012_val_00000136.bin 224 224 +5820 ./prep_dataset/ILSVRC2012_val_00026339.bin 224 224 +5821 ./prep_dataset/ILSVRC2012_val_00039788.bin 224 224 +5822 ./prep_dataset/ILSVRC2012_val_00039172.bin 224 224 +5823 ./prep_dataset/ILSVRC2012_val_00022664.bin 224 224 +5824 ./prep_dataset/ILSVRC2012_val_00049091.bin 224 224 +5825 ./prep_dataset/ILSVRC2012_val_00046761.bin 224 224 +5826 ./prep_dataset/ILSVRC2012_val_00002338.bin 224 224 +5827 ./prep_dataset/ILSVRC2012_val_00018318.bin 224 224 +5828 ./prep_dataset/ILSVRC2012_val_00013573.bin 224 224 +5829 ./prep_dataset/ILSVRC2012_val_00013154.bin 224 224 +5830 ./prep_dataset/ILSVRC2012_val_00047521.bin 224 224 +5831 ./prep_dataset/ILSVRC2012_val_00048432.bin 224 224 +5832 ./prep_dataset/ILSVRC2012_val_00049011.bin 224 224 +5833 ./prep_dataset/ILSVRC2012_val_00026121.bin 224 224 +5834 ./prep_dataset/ILSVRC2012_val_00001493.bin 224 224 +5835 ./prep_dataset/ILSVRC2012_val_00004261.bin 224 224 +5836 ./prep_dataset/ILSVRC2012_val_00044068.bin 224 224 +5837 ./prep_dataset/ILSVRC2012_val_00004927.bin 224 224 +5838 ./prep_dataset/ILSVRC2012_val_00034491.bin 224 224 +5839 ./prep_dataset/ILSVRC2012_val_00027953.bin 224 224 +5840 ./prep_dataset/ILSVRC2012_val_00023373.bin 224 224 +5841 ./prep_dataset/ILSVRC2012_val_00032268.bin 224 224 +5842 ./prep_dataset/ILSVRC2012_val_00048720.bin 224 224 +5843 ./prep_dataset/ILSVRC2012_val_00017070.bin 224 224 +5844 ./prep_dataset/ILSVRC2012_val_00032678.bin 224 224 +5845 ./prep_dataset/ILSVRC2012_val_00031715.bin 224 224 +5846 ./prep_dataset/ILSVRC2012_val_00040438.bin 224 224 +5847 ./prep_dataset/ILSVRC2012_val_00029296.bin 224 224 +5848 ./prep_dataset/ILSVRC2012_val_00037800.bin 224 224 +5849 ./prep_dataset/ILSVRC2012_val_00039357.bin 224 224 +5850 ./prep_dataset/ILSVRC2012_val_00021726.bin 224 224 +5851 ./prep_dataset/ILSVRC2012_val_00005005.bin 224 224 +5852 ./prep_dataset/ILSVRC2012_val_00025402.bin 224 224 +5853 ./prep_dataset/ILSVRC2012_val_00038490.bin 224 224 +5854 ./prep_dataset/ILSVRC2012_val_00041994.bin 224 224 +5855 ./prep_dataset/ILSVRC2012_val_00041948.bin 224 224 +5856 ./prep_dataset/ILSVRC2012_val_00037545.bin 224 224 +5857 ./prep_dataset/ILSVRC2012_val_00049640.bin 224 224 +5858 ./prep_dataset/ILSVRC2012_val_00013032.bin 224 224 +5859 ./prep_dataset/ILSVRC2012_val_00008197.bin 224 224 +5860 ./prep_dataset/ILSVRC2012_val_00002651.bin 224 224 +5861 ./prep_dataset/ILSVRC2012_val_00013069.bin 224 224 +5862 ./prep_dataset/ILSVRC2012_val_00048469.bin 224 224 +5863 ./prep_dataset/ILSVRC2012_val_00016830.bin 224 224 +5864 ./prep_dataset/ILSVRC2012_val_00002650.bin 224 224 +5865 ./prep_dataset/ILSVRC2012_val_00023651.bin 224 224 +5866 ./prep_dataset/ILSVRC2012_val_00011740.bin 224 224 +5867 ./prep_dataset/ILSVRC2012_val_00047879.bin 224 224 +5868 ./prep_dataset/ILSVRC2012_val_00022478.bin 224 224 +5869 ./prep_dataset/ILSVRC2012_val_00031863.bin 224 224 +5870 ./prep_dataset/ILSVRC2012_val_00042096.bin 224 224 +5871 ./prep_dataset/ILSVRC2012_val_00020555.bin 224 224 +5872 ./prep_dataset/ILSVRC2012_val_00017700.bin 224 224 +5873 ./prep_dataset/ILSVRC2012_val_00006334.bin 224 224 +5874 ./prep_dataset/ILSVRC2012_val_00007254.bin 224 224 +5875 ./prep_dataset/ILSVRC2012_val_00007807.bin 224 224 +5876 ./prep_dataset/ILSVRC2012_val_00031027.bin 224 224 +5877 ./prep_dataset/ILSVRC2012_val_00006660.bin 224 224 +5878 ./prep_dataset/ILSVRC2012_val_00046016.bin 224 224 +5879 ./prep_dataset/ILSVRC2012_val_00010085.bin 224 224 +5880 ./prep_dataset/ILSVRC2012_val_00039639.bin 224 224 +5881 ./prep_dataset/ILSVRC2012_val_00001250.bin 224 224 +5882 ./prep_dataset/ILSVRC2012_val_00022625.bin 224 224 +5883 ./prep_dataset/ILSVRC2012_val_00034114.bin 224 224 +5884 ./prep_dataset/ILSVRC2012_val_00003879.bin 224 224 +5885 ./prep_dataset/ILSVRC2012_val_00004186.bin 224 224 +5886 ./prep_dataset/ILSVRC2012_val_00046552.bin 224 224 +5887 ./prep_dataset/ILSVRC2012_val_00001787.bin 224 224 +5888 ./prep_dataset/ILSVRC2012_val_00031155.bin 224 224 +5889 ./prep_dataset/ILSVRC2012_val_00012033.bin 224 224 +5890 ./prep_dataset/ILSVRC2012_val_00022713.bin 224 224 +5891 ./prep_dataset/ILSVRC2012_val_00048148.bin 224 224 +5892 ./prep_dataset/ILSVRC2012_val_00033537.bin 224 224 +5893 ./prep_dataset/ILSVRC2012_val_00011758.bin 224 224 +5894 ./prep_dataset/ILSVRC2012_val_00034221.bin 224 224 +5895 ./prep_dataset/ILSVRC2012_val_00036841.bin 224 224 +5896 ./prep_dataset/ILSVRC2012_val_00019278.bin 224 224 +5897 ./prep_dataset/ILSVRC2012_val_00019162.bin 224 224 +5898 ./prep_dataset/ILSVRC2012_val_00043732.bin 224 224 +5899 ./prep_dataset/ILSVRC2012_val_00022208.bin 224 224 +5900 ./prep_dataset/ILSVRC2012_val_00011942.bin 224 224 +5901 ./prep_dataset/ILSVRC2012_val_00041725.bin 224 224 +5902 ./prep_dataset/ILSVRC2012_val_00013229.bin 224 224 +5903 ./prep_dataset/ILSVRC2012_val_00007163.bin 224 224 +5904 ./prep_dataset/ILSVRC2012_val_00036533.bin 224 224 +5905 ./prep_dataset/ILSVRC2012_val_00037622.bin 224 224 +5906 ./prep_dataset/ILSVRC2012_val_00035721.bin 224 224 +5907 ./prep_dataset/ILSVRC2012_val_00014726.bin 224 224 +5908 ./prep_dataset/ILSVRC2012_val_00037194.bin 224 224 +5909 ./prep_dataset/ILSVRC2012_val_00020642.bin 224 224 +5910 ./prep_dataset/ILSVRC2012_val_00043655.bin 224 224 +5911 ./prep_dataset/ILSVRC2012_val_00004707.bin 224 224 +5912 ./prep_dataset/ILSVRC2012_val_00031158.bin 224 224 +5913 ./prep_dataset/ILSVRC2012_val_00016572.bin 224 224 +5914 ./prep_dataset/ILSVRC2012_val_00030098.bin 224 224 +5915 ./prep_dataset/ILSVRC2012_val_00010937.bin 224 224 +5916 ./prep_dataset/ILSVRC2012_val_00032086.bin 224 224 +5917 ./prep_dataset/ILSVRC2012_val_00003659.bin 224 224 +5918 ./prep_dataset/ILSVRC2012_val_00041836.bin 224 224 +5919 ./prep_dataset/ILSVRC2012_val_00030089.bin 224 224 +5920 ./prep_dataset/ILSVRC2012_val_00031133.bin 224 224 +5921 ./prep_dataset/ILSVRC2012_val_00039512.bin 224 224 +5922 ./prep_dataset/ILSVRC2012_val_00028840.bin 224 224 +5923 ./prep_dataset/ILSVRC2012_val_00006355.bin 224 224 +5924 ./prep_dataset/ILSVRC2012_val_00007884.bin 224 224 +5925 ./prep_dataset/ILSVRC2012_val_00049171.bin 224 224 +5926 ./prep_dataset/ILSVRC2012_val_00045032.bin 224 224 +5927 ./prep_dataset/ILSVRC2012_val_00003082.bin 224 224 +5928 ./prep_dataset/ILSVRC2012_val_00019516.bin 224 224 +5929 ./prep_dataset/ILSVRC2012_val_00001276.bin 224 224 +5930 ./prep_dataset/ILSVRC2012_val_00018503.bin 224 224 +5931 ./prep_dataset/ILSVRC2012_val_00036618.bin 224 224 +5932 ./prep_dataset/ILSVRC2012_val_00037222.bin 224 224 +5933 ./prep_dataset/ILSVRC2012_val_00005517.bin 224 224 +5934 ./prep_dataset/ILSVRC2012_val_00000498.bin 224 224 +5935 ./prep_dataset/ILSVRC2012_val_00037661.bin 224 224 +5936 ./prep_dataset/ILSVRC2012_val_00032256.bin 224 224 +5937 ./prep_dataset/ILSVRC2012_val_00043766.bin 224 224 +5938 ./prep_dataset/ILSVRC2012_val_00009845.bin 224 224 +5939 ./prep_dataset/ILSVRC2012_val_00010610.bin 224 224 +5940 ./prep_dataset/ILSVRC2012_val_00015173.bin 224 224 +5941 ./prep_dataset/ILSVRC2012_val_00005272.bin 224 224 +5942 ./prep_dataset/ILSVRC2012_val_00032890.bin 224 224 +5943 ./prep_dataset/ILSVRC2012_val_00020034.bin 224 224 +5944 ./prep_dataset/ILSVRC2012_val_00030469.bin 224 224 +5945 ./prep_dataset/ILSVRC2012_val_00007314.bin 224 224 +5946 ./prep_dataset/ILSVRC2012_val_00035278.bin 224 224 +5947 ./prep_dataset/ILSVRC2012_val_00020800.bin 224 224 +5948 ./prep_dataset/ILSVRC2012_val_00020991.bin 224 224 +5949 ./prep_dataset/ILSVRC2012_val_00033188.bin 224 224 +5950 ./prep_dataset/ILSVRC2012_val_00048269.bin 224 224 +5951 ./prep_dataset/ILSVRC2012_val_00030335.bin 224 224 +5952 ./prep_dataset/ILSVRC2012_val_00004498.bin 224 224 +5953 ./prep_dataset/ILSVRC2012_val_00021744.bin 224 224 +5954 ./prep_dataset/ILSVRC2012_val_00046770.bin 224 224 +5955 ./prep_dataset/ILSVRC2012_val_00008550.bin 224 224 +5956 ./prep_dataset/ILSVRC2012_val_00008736.bin 224 224 +5957 ./prep_dataset/ILSVRC2012_val_00017582.bin 224 224 +5958 ./prep_dataset/ILSVRC2012_val_00039572.bin 224 224 +5959 ./prep_dataset/ILSVRC2012_val_00020542.bin 224 224 +5960 ./prep_dataset/ILSVRC2012_val_00035485.bin 224 224 +5961 ./prep_dataset/ILSVRC2012_val_00032518.bin 224 224 +5962 ./prep_dataset/ILSVRC2012_val_00007303.bin 224 224 +5963 ./prep_dataset/ILSVRC2012_val_00008244.bin 224 224 +5964 ./prep_dataset/ILSVRC2012_val_00038483.bin 224 224 +5965 ./prep_dataset/ILSVRC2012_val_00047918.bin 224 224 +5966 ./prep_dataset/ILSVRC2012_val_00009925.bin 224 224 +5967 ./prep_dataset/ILSVRC2012_val_00008921.bin 224 224 +5968 ./prep_dataset/ILSVRC2012_val_00009037.bin 224 224 +5969 ./prep_dataset/ILSVRC2012_val_00044439.bin 224 224 +5970 ./prep_dataset/ILSVRC2012_val_00014788.bin 224 224 +5971 ./prep_dataset/ILSVRC2012_val_00025435.bin 224 224 +5972 ./prep_dataset/ILSVRC2012_val_00007119.bin 224 224 +5973 ./prep_dataset/ILSVRC2012_val_00028558.bin 224 224 +5974 ./prep_dataset/ILSVRC2012_val_00013594.bin 224 224 +5975 ./prep_dataset/ILSVRC2012_val_00043960.bin 224 224 +5976 ./prep_dataset/ILSVRC2012_val_00025333.bin 224 224 +5977 ./prep_dataset/ILSVRC2012_val_00049669.bin 224 224 +5978 ./prep_dataset/ILSVRC2012_val_00013724.bin 224 224 +5979 ./prep_dataset/ILSVRC2012_val_00046363.bin 224 224 +5980 ./prep_dataset/ILSVRC2012_val_00013462.bin 224 224 +5981 ./prep_dataset/ILSVRC2012_val_00038188.bin 224 224 +5982 ./prep_dataset/ILSVRC2012_val_00044126.bin 224 224 +5983 ./prep_dataset/ILSVRC2012_val_00040909.bin 224 224 +5984 ./prep_dataset/ILSVRC2012_val_00048857.bin 224 224 +5985 ./prep_dataset/ILSVRC2012_val_00041788.bin 224 224 +5986 ./prep_dataset/ILSVRC2012_val_00033429.bin 224 224 +5987 ./prep_dataset/ILSVRC2012_val_00041488.bin 224 224 +5988 ./prep_dataset/ILSVRC2012_val_00037589.bin 224 224 +5989 ./prep_dataset/ILSVRC2012_val_00046875.bin 224 224 +5990 ./prep_dataset/ILSVRC2012_val_00017759.bin 224 224 +5991 ./prep_dataset/ILSVRC2012_val_00005333.bin 224 224 +5992 ./prep_dataset/ILSVRC2012_val_00034527.bin 224 224 +5993 ./prep_dataset/ILSVRC2012_val_00049441.bin 224 224 +5994 ./prep_dataset/ILSVRC2012_val_00026677.bin 224 224 +5995 ./prep_dataset/ILSVRC2012_val_00021535.bin 224 224 +5996 ./prep_dataset/ILSVRC2012_val_00015081.bin 224 224 +5997 ./prep_dataset/ILSVRC2012_val_00031031.bin 224 224 +5998 ./prep_dataset/ILSVRC2012_val_00042780.bin 224 224 +5999 ./prep_dataset/ILSVRC2012_val_00030816.bin 224 224 +6000 ./prep_dataset/ILSVRC2012_val_00000760.bin 224 224 +6001 ./prep_dataset/ILSVRC2012_val_00040220.bin 224 224 +6002 ./prep_dataset/ILSVRC2012_val_00045450.bin 224 224 +6003 ./prep_dataset/ILSVRC2012_val_00022769.bin 224 224 +6004 ./prep_dataset/ILSVRC2012_val_00043883.bin 224 224 +6005 ./prep_dataset/ILSVRC2012_val_00028745.bin 224 224 +6006 ./prep_dataset/ILSVRC2012_val_00031963.bin 224 224 +6007 ./prep_dataset/ILSVRC2012_val_00004779.bin 224 224 +6008 ./prep_dataset/ILSVRC2012_val_00033356.bin 224 224 +6009 ./prep_dataset/ILSVRC2012_val_00002435.bin 224 224 +6010 ./prep_dataset/ILSVRC2012_val_00035940.bin 224 224 +6011 ./prep_dataset/ILSVRC2012_val_00016251.bin 224 224 +6012 ./prep_dataset/ILSVRC2012_val_00045133.bin 224 224 +6013 ./prep_dataset/ILSVRC2012_val_00046052.bin 224 224 +6014 ./prep_dataset/ILSVRC2012_val_00035282.bin 224 224 +6015 ./prep_dataset/ILSVRC2012_val_00042312.bin 224 224 +6016 ./prep_dataset/ILSVRC2012_val_00046203.bin 224 224 +6017 ./prep_dataset/ILSVRC2012_val_00034604.bin 224 224 +6018 ./prep_dataset/ILSVRC2012_val_00004209.bin 224 224 +6019 ./prep_dataset/ILSVRC2012_val_00019826.bin 224 224 +6020 ./prep_dataset/ILSVRC2012_val_00025480.bin 224 224 +6021 ./prep_dataset/ILSVRC2012_val_00026605.bin 224 224 +6022 ./prep_dataset/ILSVRC2012_val_00034297.bin 224 224 +6023 ./prep_dataset/ILSVRC2012_val_00036196.bin 224 224 +6024 ./prep_dataset/ILSVRC2012_val_00019232.bin 224 224 +6025 ./prep_dataset/ILSVRC2012_val_00019146.bin 224 224 +6026 ./prep_dataset/ILSVRC2012_val_00029811.bin 224 224 +6027 ./prep_dataset/ILSVRC2012_val_00031348.bin 224 224 +6028 ./prep_dataset/ILSVRC2012_val_00027410.bin 224 224 +6029 ./prep_dataset/ILSVRC2012_val_00037927.bin 224 224 +6030 ./prep_dataset/ILSVRC2012_val_00019300.bin 224 224 +6031 ./prep_dataset/ILSVRC2012_val_00030724.bin 224 224 +6032 ./prep_dataset/ILSVRC2012_val_00022327.bin 224 224 +6033 ./prep_dataset/ILSVRC2012_val_00006115.bin 224 224 +6034 ./prep_dataset/ILSVRC2012_val_00043417.bin 224 224 +6035 ./prep_dataset/ILSVRC2012_val_00016848.bin 224 224 +6036 ./prep_dataset/ILSVRC2012_val_00037025.bin 224 224 +6037 ./prep_dataset/ILSVRC2012_val_00023898.bin 224 224 +6038 ./prep_dataset/ILSVRC2012_val_00008045.bin 224 224 +6039 ./prep_dataset/ILSVRC2012_val_00037334.bin 224 224 +6040 ./prep_dataset/ILSVRC2012_val_00042114.bin 224 224 +6041 ./prep_dataset/ILSVRC2012_val_00048995.bin 224 224 +6042 ./prep_dataset/ILSVRC2012_val_00015415.bin 224 224 +6043 ./prep_dataset/ILSVRC2012_val_00031635.bin 224 224 +6044 ./prep_dataset/ILSVRC2012_val_00013804.bin 224 224 +6045 ./prep_dataset/ILSVRC2012_val_00022559.bin 224 224 +6046 ./prep_dataset/ILSVRC2012_val_00047768.bin 224 224 +6047 ./prep_dataset/ILSVRC2012_val_00049085.bin 224 224 +6048 ./prep_dataset/ILSVRC2012_val_00009654.bin 224 224 +6049 ./prep_dataset/ILSVRC2012_val_00008569.bin 224 224 +6050 ./prep_dataset/ILSVRC2012_val_00028116.bin 224 224 +6051 ./prep_dataset/ILSVRC2012_val_00010322.bin 224 224 +6052 ./prep_dataset/ILSVRC2012_val_00024438.bin 224 224 +6053 ./prep_dataset/ILSVRC2012_val_00013424.bin 224 224 +6054 ./prep_dataset/ILSVRC2012_val_00038039.bin 224 224 +6055 ./prep_dataset/ILSVRC2012_val_00046612.bin 224 224 +6056 ./prep_dataset/ILSVRC2012_val_00002052.bin 224 224 +6057 ./prep_dataset/ILSVRC2012_val_00018735.bin 224 224 +6058 ./prep_dataset/ILSVRC2012_val_00013324.bin 224 224 +6059 ./prep_dataset/ILSVRC2012_val_00040777.bin 224 224 +6060 ./prep_dataset/ILSVRC2012_val_00015830.bin 224 224 +6061 ./prep_dataset/ILSVRC2012_val_00012181.bin 224 224 +6062 ./prep_dataset/ILSVRC2012_val_00046429.bin 224 224 +6063 ./prep_dataset/ILSVRC2012_val_00012154.bin 224 224 +6064 ./prep_dataset/ILSVRC2012_val_00000144.bin 224 224 +6065 ./prep_dataset/ILSVRC2012_val_00035979.bin 224 224 +6066 ./prep_dataset/ILSVRC2012_val_00029033.bin 224 224 +6067 ./prep_dataset/ILSVRC2012_val_00001518.bin 224 224 +6068 ./prep_dataset/ILSVRC2012_val_00039077.bin 224 224 +6069 ./prep_dataset/ILSVRC2012_val_00034987.bin 224 224 +6070 ./prep_dataset/ILSVRC2012_val_00022269.bin 224 224 +6071 ./prep_dataset/ILSVRC2012_val_00028783.bin 224 224 +6072 ./prep_dataset/ILSVRC2012_val_00000898.bin 224 224 +6073 ./prep_dataset/ILSVRC2012_val_00015895.bin 224 224 +6074 ./prep_dataset/ILSVRC2012_val_00014911.bin 224 224 +6075 ./prep_dataset/ILSVRC2012_val_00049291.bin 224 224 +6076 ./prep_dataset/ILSVRC2012_val_00031780.bin 224 224 +6077 ./prep_dataset/ILSVRC2012_val_00040694.bin 224 224 +6078 ./prep_dataset/ILSVRC2012_val_00004950.bin 224 224 +6079 ./prep_dataset/ILSVRC2012_val_00003951.bin 224 224 +6080 ./prep_dataset/ILSVRC2012_val_00045117.bin 224 224 +6081 ./prep_dataset/ILSVRC2012_val_00022627.bin 224 224 +6082 ./prep_dataset/ILSVRC2012_val_00000836.bin 224 224 +6083 ./prep_dataset/ILSVRC2012_val_00029555.bin 224 224 +6084 ./prep_dataset/ILSVRC2012_val_00005920.bin 224 224 +6085 ./prep_dataset/ILSVRC2012_val_00016837.bin 224 224 +6086 ./prep_dataset/ILSVRC2012_val_00047666.bin 224 224 +6087 ./prep_dataset/ILSVRC2012_val_00026451.bin 224 224 +6088 ./prep_dataset/ILSVRC2012_val_00044004.bin 224 224 +6089 ./prep_dataset/ILSVRC2012_val_00002604.bin 224 224 +6090 ./prep_dataset/ILSVRC2012_val_00005414.bin 224 224 +6091 ./prep_dataset/ILSVRC2012_val_00036200.bin 224 224 +6092 ./prep_dataset/ILSVRC2012_val_00042099.bin 224 224 +6093 ./prep_dataset/ILSVRC2012_val_00046948.bin 224 224 +6094 ./prep_dataset/ILSVRC2012_val_00012623.bin 224 224 +6095 ./prep_dataset/ILSVRC2012_val_00011507.bin 224 224 +6096 ./prep_dataset/ILSVRC2012_val_00010716.bin 224 224 +6097 ./prep_dataset/ILSVRC2012_val_00049994.bin 224 224 +6098 ./prep_dataset/ILSVRC2012_val_00020613.bin 224 224 +6099 ./prep_dataset/ILSVRC2012_val_00020086.bin 224 224 +6100 ./prep_dataset/ILSVRC2012_val_00044990.bin 224 224 +6101 ./prep_dataset/ILSVRC2012_val_00014838.bin 224 224 +6102 ./prep_dataset/ILSVRC2012_val_00021706.bin 224 224 +6103 ./prep_dataset/ILSVRC2012_val_00001779.bin 224 224 +6104 ./prep_dataset/ILSVRC2012_val_00004791.bin 224 224 +6105 ./prep_dataset/ILSVRC2012_val_00027298.bin 224 224 +6106 ./prep_dataset/ILSVRC2012_val_00029930.bin 224 224 +6107 ./prep_dataset/ILSVRC2012_val_00041832.bin 224 224 +6108 ./prep_dataset/ILSVRC2012_val_00041147.bin 224 224 +6109 ./prep_dataset/ILSVRC2012_val_00036651.bin 224 224 +6110 ./prep_dataset/ILSVRC2012_val_00044812.bin 224 224 +6111 ./prep_dataset/ILSVRC2012_val_00045803.bin 224 224 +6112 ./prep_dataset/ILSVRC2012_val_00018711.bin 224 224 +6113 ./prep_dataset/ILSVRC2012_val_00001783.bin 224 224 +6114 ./prep_dataset/ILSVRC2012_val_00026471.bin 224 224 +6115 ./prep_dataset/ILSVRC2012_val_00001930.bin 224 224 +6116 ./prep_dataset/ILSVRC2012_val_00038162.bin 224 224 +6117 ./prep_dataset/ILSVRC2012_val_00026437.bin 224 224 +6118 ./prep_dataset/ILSVRC2012_val_00006788.bin 224 224 +6119 ./prep_dataset/ILSVRC2012_val_00027127.bin 224 224 +6120 ./prep_dataset/ILSVRC2012_val_00027431.bin 224 224 +6121 ./prep_dataset/ILSVRC2012_val_00040471.bin 224 224 +6122 ./prep_dataset/ILSVRC2012_val_00026434.bin 224 224 +6123 ./prep_dataset/ILSVRC2012_val_00013922.bin 224 224 +6124 ./prep_dataset/ILSVRC2012_val_00008036.bin 224 224 +6125 ./prep_dataset/ILSVRC2012_val_00042862.bin 224 224 +6126 ./prep_dataset/ILSVRC2012_val_00024755.bin 224 224 +6127 ./prep_dataset/ILSVRC2012_val_00033558.bin 224 224 +6128 ./prep_dataset/ILSVRC2012_val_00005277.bin 224 224 +6129 ./prep_dataset/ILSVRC2012_val_00019280.bin 224 224 +6130 ./prep_dataset/ILSVRC2012_val_00020547.bin 224 224 +6131 ./prep_dataset/ILSVRC2012_val_00020185.bin 224 224 +6132 ./prep_dataset/ILSVRC2012_val_00007597.bin 224 224 +6133 ./prep_dataset/ILSVRC2012_val_00045154.bin 224 224 +6134 ./prep_dataset/ILSVRC2012_val_00036321.bin 224 224 +6135 ./prep_dataset/ILSVRC2012_val_00026220.bin 224 224 +6136 ./prep_dataset/ILSVRC2012_val_00005303.bin 224 224 +6137 ./prep_dataset/ILSVRC2012_val_00017144.bin 224 224 +6138 ./prep_dataset/ILSVRC2012_val_00020147.bin 224 224 +6139 ./prep_dataset/ILSVRC2012_val_00019322.bin 224 224 +6140 ./prep_dataset/ILSVRC2012_val_00022673.bin 224 224 +6141 ./prep_dataset/ILSVRC2012_val_00048421.bin 224 224 +6142 ./prep_dataset/ILSVRC2012_val_00001009.bin 224 224 +6143 ./prep_dataset/ILSVRC2012_val_00027702.bin 224 224 +6144 ./prep_dataset/ILSVRC2012_val_00006548.bin 224 224 +6145 ./prep_dataset/ILSVRC2012_val_00009299.bin 224 224 +6146 ./prep_dataset/ILSVRC2012_val_00011801.bin 224 224 +6147 ./prep_dataset/ILSVRC2012_val_00012355.bin 224 224 +6148 ./prep_dataset/ILSVRC2012_val_00046888.bin 224 224 +6149 ./prep_dataset/ILSVRC2012_val_00031762.bin 224 224 +6150 ./prep_dataset/ILSVRC2012_val_00003287.bin 224 224 +6151 ./prep_dataset/ILSVRC2012_val_00015773.bin 224 224 +6152 ./prep_dataset/ILSVRC2012_val_00039287.bin 224 224 +6153 ./prep_dataset/ILSVRC2012_val_00027287.bin 224 224 +6154 ./prep_dataset/ILSVRC2012_val_00009511.bin 224 224 +6155 ./prep_dataset/ILSVRC2012_val_00049316.bin 224 224 +6156 ./prep_dataset/ILSVRC2012_val_00008509.bin 224 224 +6157 ./prep_dataset/ILSVRC2012_val_00035598.bin 224 224 +6158 ./prep_dataset/ILSVRC2012_val_00009544.bin 224 224 +6159 ./prep_dataset/ILSVRC2012_val_00015949.bin 224 224 +6160 ./prep_dataset/ILSVRC2012_val_00010456.bin 224 224 +6161 ./prep_dataset/ILSVRC2012_val_00036294.bin 224 224 +6162 ./prep_dataset/ILSVRC2012_val_00015443.bin 224 224 +6163 ./prep_dataset/ILSVRC2012_val_00032153.bin 224 224 +6164 ./prep_dataset/ILSVRC2012_val_00006751.bin 224 224 +6165 ./prep_dataset/ILSVRC2012_val_00033180.bin 224 224 +6166 ./prep_dataset/ILSVRC2012_val_00032383.bin 224 224 +6167 ./prep_dataset/ILSVRC2012_val_00049886.bin 224 224 +6168 ./prep_dataset/ILSVRC2012_val_00033312.bin 224 224 +6169 ./prep_dataset/ILSVRC2012_val_00039723.bin 224 224 +6170 ./prep_dataset/ILSVRC2012_val_00015371.bin 224 224 +6171 ./prep_dataset/ILSVRC2012_val_00000962.bin 224 224 +6172 ./prep_dataset/ILSVRC2012_val_00023741.bin 224 224 +6173 ./prep_dataset/ILSVRC2012_val_00027041.bin 224 224 +6174 ./prep_dataset/ILSVRC2012_val_00045134.bin 224 224 +6175 ./prep_dataset/ILSVRC2012_val_00027768.bin 224 224 +6176 ./prep_dataset/ILSVRC2012_val_00005648.bin 224 224 +6177 ./prep_dataset/ILSVRC2012_val_00042372.bin 224 224 +6178 ./prep_dataset/ILSVRC2012_val_00026796.bin 224 224 +6179 ./prep_dataset/ILSVRC2012_val_00045704.bin 224 224 +6180 ./prep_dataset/ILSVRC2012_val_00045304.bin 224 224 +6181 ./prep_dataset/ILSVRC2012_val_00018167.bin 224 224 +6182 ./prep_dataset/ILSVRC2012_val_00030982.bin 224 224 +6183 ./prep_dataset/ILSVRC2012_val_00001667.bin 224 224 +6184 ./prep_dataset/ILSVRC2012_val_00010250.bin 224 224 +6185 ./prep_dataset/ILSVRC2012_val_00031508.bin 224 224 +6186 ./prep_dataset/ILSVRC2012_val_00009616.bin 224 224 +6187 ./prep_dataset/ILSVRC2012_val_00018893.bin 224 224 +6188 ./prep_dataset/ILSVRC2012_val_00038992.bin 224 224 +6189 ./prep_dataset/ILSVRC2012_val_00003724.bin 224 224 +6190 ./prep_dataset/ILSVRC2012_val_00036827.bin 224 224 +6191 ./prep_dataset/ILSVRC2012_val_00040806.bin 224 224 +6192 ./prep_dataset/ILSVRC2012_val_00001288.bin 224 224 +6193 ./prep_dataset/ILSVRC2012_val_00048029.bin 224 224 +6194 ./prep_dataset/ILSVRC2012_val_00021466.bin 224 224 +6195 ./prep_dataset/ILSVRC2012_val_00020160.bin 224 224 +6196 ./prep_dataset/ILSVRC2012_val_00036130.bin 224 224 +6197 ./prep_dataset/ILSVRC2012_val_00037798.bin 224 224 +6198 ./prep_dataset/ILSVRC2012_val_00034750.bin 224 224 +6199 ./prep_dataset/ILSVRC2012_val_00010516.bin 224 224 +6200 ./prep_dataset/ILSVRC2012_val_00025845.bin 224 224 +6201 ./prep_dataset/ILSVRC2012_val_00031511.bin 224 224 +6202 ./prep_dataset/ILSVRC2012_val_00000602.bin 224 224 +6203 ./prep_dataset/ILSVRC2012_val_00029840.bin 224 224 +6204 ./prep_dataset/ILSVRC2012_val_00046315.bin 224 224 +6205 ./prep_dataset/ILSVRC2012_val_00017878.bin 224 224 +6206 ./prep_dataset/ILSVRC2012_val_00028262.bin 224 224 +6207 ./prep_dataset/ILSVRC2012_val_00021620.bin 224 224 +6208 ./prep_dataset/ILSVRC2012_val_00004622.bin 224 224 +6209 ./prep_dataset/ILSVRC2012_val_00015413.bin 224 224 +6210 ./prep_dataset/ILSVRC2012_val_00045049.bin 224 224 +6211 ./prep_dataset/ILSVRC2012_val_00021636.bin 224 224 +6212 ./prep_dataset/ILSVRC2012_val_00038844.bin 224 224 +6213 ./prep_dataset/ILSVRC2012_val_00031226.bin 224 224 +6214 ./prep_dataset/ILSVRC2012_val_00042557.bin 224 224 +6215 ./prep_dataset/ILSVRC2012_val_00012222.bin 224 224 +6216 ./prep_dataset/ILSVRC2012_val_00031127.bin 224 224 +6217 ./prep_dataset/ILSVRC2012_val_00020537.bin 224 224 +6218 ./prep_dataset/ILSVRC2012_val_00037006.bin 224 224 +6219 ./prep_dataset/ILSVRC2012_val_00044579.bin 224 224 +6220 ./prep_dataset/ILSVRC2012_val_00039423.bin 224 224 +6221 ./prep_dataset/ILSVRC2012_val_00021561.bin 224 224 +6222 ./prep_dataset/ILSVRC2012_val_00035014.bin 224 224 +6223 ./prep_dataset/ILSVRC2012_val_00036652.bin 224 224 +6224 ./prep_dataset/ILSVRC2012_val_00038697.bin 224 224 +6225 ./prep_dataset/ILSVRC2012_val_00014639.bin 224 224 +6226 ./prep_dataset/ILSVRC2012_val_00033033.bin 224 224 +6227 ./prep_dataset/ILSVRC2012_val_00049329.bin 224 224 +6228 ./prep_dataset/ILSVRC2012_val_00044278.bin 224 224 +6229 ./prep_dataset/ILSVRC2012_val_00000974.bin 224 224 +6230 ./prep_dataset/ILSVRC2012_val_00029661.bin 224 224 +6231 ./prep_dataset/ILSVRC2012_val_00040526.bin 224 224 +6232 ./prep_dataset/ILSVRC2012_val_00015468.bin 224 224 +6233 ./prep_dataset/ILSVRC2012_val_00020658.bin 224 224 +6234 ./prep_dataset/ILSVRC2012_val_00038117.bin 224 224 +6235 ./prep_dataset/ILSVRC2012_val_00037483.bin 224 224 +6236 ./prep_dataset/ILSVRC2012_val_00019038.bin 224 224 +6237 ./prep_dataset/ILSVRC2012_val_00006053.bin 224 224 +6238 ./prep_dataset/ILSVRC2012_val_00031064.bin 224 224 +6239 ./prep_dataset/ILSVRC2012_val_00030521.bin 224 224 +6240 ./prep_dataset/ILSVRC2012_val_00033633.bin 224 224 +6241 ./prep_dataset/ILSVRC2012_val_00023633.bin 224 224 +6242 ./prep_dataset/ILSVRC2012_val_00027994.bin 224 224 +6243 ./prep_dataset/ILSVRC2012_val_00044355.bin 224 224 +6244 ./prep_dataset/ILSVRC2012_val_00017047.bin 224 224 +6245 ./prep_dataset/ILSVRC2012_val_00000321.bin 224 224 +6246 ./prep_dataset/ILSVRC2012_val_00015916.bin 224 224 +6247 ./prep_dataset/ILSVRC2012_val_00049100.bin 224 224 +6248 ./prep_dataset/ILSVRC2012_val_00006019.bin 224 224 +6249 ./prep_dataset/ILSVRC2012_val_00007224.bin 224 224 +6250 ./prep_dataset/ILSVRC2012_val_00006023.bin 224 224 +6251 ./prep_dataset/ILSVRC2012_val_00012681.bin 224 224 +6252 ./prep_dataset/ILSVRC2012_val_00014057.bin 224 224 +6253 ./prep_dataset/ILSVRC2012_val_00017905.bin 224 224 +6254 ./prep_dataset/ILSVRC2012_val_00038454.bin 224 224 +6255 ./prep_dataset/ILSVRC2012_val_00049753.bin 224 224 +6256 ./prep_dataset/ILSVRC2012_val_00038425.bin 224 224 +6257 ./prep_dataset/ILSVRC2012_val_00010907.bin 224 224 +6258 ./prep_dataset/ILSVRC2012_val_00021812.bin 224 224 +6259 ./prep_dataset/ILSVRC2012_val_00047151.bin 224 224 +6260 ./prep_dataset/ILSVRC2012_val_00029304.bin 224 224 +6261 ./prep_dataset/ILSVRC2012_val_00015384.bin 224 224 +6262 ./prep_dataset/ILSVRC2012_val_00034999.bin 224 224 +6263 ./prep_dataset/ILSVRC2012_val_00008151.bin 224 224 +6264 ./prep_dataset/ILSVRC2012_val_00012164.bin 224 224 +6265 ./prep_dataset/ILSVRC2012_val_00023221.bin 224 224 +6266 ./prep_dataset/ILSVRC2012_val_00007034.bin 224 224 +6267 ./prep_dataset/ILSVRC2012_val_00025256.bin 224 224 +6268 ./prep_dataset/ILSVRC2012_val_00011738.bin 224 224 +6269 ./prep_dataset/ILSVRC2012_val_00049717.bin 224 224 +6270 ./prep_dataset/ILSVRC2012_val_00038999.bin 224 224 +6271 ./prep_dataset/ILSVRC2012_val_00037868.bin 224 224 +6272 ./prep_dataset/ILSVRC2012_val_00012903.bin 224 224 +6273 ./prep_dataset/ILSVRC2012_val_00035951.bin 224 224 +6274 ./prep_dataset/ILSVRC2012_val_00004450.bin 224 224 +6275 ./prep_dataset/ILSVRC2012_val_00008083.bin 224 224 +6276 ./prep_dataset/ILSVRC2012_val_00005511.bin 224 224 +6277 ./prep_dataset/ILSVRC2012_val_00036756.bin 224 224 +6278 ./prep_dataset/ILSVRC2012_val_00009553.bin 224 224 +6279 ./prep_dataset/ILSVRC2012_val_00022560.bin 224 224 +6280 ./prep_dataset/ILSVRC2012_val_00026701.bin 224 224 +6281 ./prep_dataset/ILSVRC2012_val_00014129.bin 224 224 +6282 ./prep_dataset/ILSVRC2012_val_00016633.bin 224 224 +6283 ./prep_dataset/ILSVRC2012_val_00046430.bin 224 224 +6284 ./prep_dataset/ILSVRC2012_val_00036417.bin 224 224 +6285 ./prep_dataset/ILSVRC2012_val_00019653.bin 224 224 +6286 ./prep_dataset/ILSVRC2012_val_00010237.bin 224 224 +6287 ./prep_dataset/ILSVRC2012_val_00048263.bin 224 224 +6288 ./prep_dataset/ILSVRC2012_val_00034366.bin 224 224 +6289 ./prep_dataset/ILSVRC2012_val_00018883.bin 224 224 +6290 ./prep_dataset/ILSVRC2012_val_00017739.bin 224 224 +6291 ./prep_dataset/ILSVRC2012_val_00005722.bin 224 224 +6292 ./prep_dataset/ILSVRC2012_val_00008070.bin 224 224 +6293 ./prep_dataset/ILSVRC2012_val_00041163.bin 224 224 +6294 ./prep_dataset/ILSVRC2012_val_00047830.bin 224 224 +6295 ./prep_dataset/ILSVRC2012_val_00029053.bin 224 224 +6296 ./prep_dataset/ILSVRC2012_val_00044364.bin 224 224 +6297 ./prep_dataset/ILSVRC2012_val_00041369.bin 224 224 +6298 ./prep_dataset/ILSVRC2012_val_00005564.bin 224 224 +6299 ./prep_dataset/ILSVRC2012_val_00025743.bin 224 224 +6300 ./prep_dataset/ILSVRC2012_val_00019621.bin 224 224 +6301 ./prep_dataset/ILSVRC2012_val_00034196.bin 224 224 +6302 ./prep_dataset/ILSVRC2012_val_00031442.bin 224 224 +6303 ./prep_dataset/ILSVRC2012_val_00003366.bin 224 224 +6304 ./prep_dataset/ILSVRC2012_val_00015303.bin 224 224 +6305 ./prep_dataset/ILSVRC2012_val_00020474.bin 224 224 +6306 ./prep_dataset/ILSVRC2012_val_00041397.bin 224 224 +6307 ./prep_dataset/ILSVRC2012_val_00036344.bin 224 224 +6308 ./prep_dataset/ILSVRC2012_val_00038671.bin 224 224 +6309 ./prep_dataset/ILSVRC2012_val_00018815.bin 224 224 +6310 ./prep_dataset/ILSVRC2012_val_00023855.bin 224 224 +6311 ./prep_dataset/ILSVRC2012_val_00036073.bin 224 224 +6312 ./prep_dataset/ILSVRC2012_val_00035678.bin 224 224 +6313 ./prep_dataset/ILSVRC2012_val_00028960.bin 224 224 +6314 ./prep_dataset/ILSVRC2012_val_00024656.bin 224 224 +6315 ./prep_dataset/ILSVRC2012_val_00018358.bin 224 224 +6316 ./prep_dataset/ILSVRC2012_val_00008469.bin 224 224 +6317 ./prep_dataset/ILSVRC2012_val_00010022.bin 224 224 +6318 ./prep_dataset/ILSVRC2012_val_00002455.bin 224 224 +6319 ./prep_dataset/ILSVRC2012_val_00013725.bin 224 224 +6320 ./prep_dataset/ILSVRC2012_val_00018657.bin 224 224 +6321 ./prep_dataset/ILSVRC2012_val_00010615.bin 224 224 +6322 ./prep_dataset/ILSVRC2012_val_00020223.bin 224 224 +6323 ./prep_dataset/ILSVRC2012_val_00044721.bin 224 224 +6324 ./prep_dataset/ILSVRC2012_val_00046857.bin 224 224 +6325 ./prep_dataset/ILSVRC2012_val_00001780.bin 224 224 +6326 ./prep_dataset/ILSVRC2012_val_00005186.bin 224 224 +6327 ./prep_dataset/ILSVRC2012_val_00034362.bin 224 224 +6328 ./prep_dataset/ILSVRC2012_val_00049810.bin 224 224 +6329 ./prep_dataset/ILSVRC2012_val_00023184.bin 224 224 +6330 ./prep_dataset/ILSVRC2012_val_00042042.bin 224 224 +6331 ./prep_dataset/ILSVRC2012_val_00000660.bin 224 224 +6332 ./prep_dataset/ILSVRC2012_val_00009928.bin 224 224 +6333 ./prep_dataset/ILSVRC2012_val_00019885.bin 224 224 +6334 ./prep_dataset/ILSVRC2012_val_00040971.bin 224 224 +6335 ./prep_dataset/ILSVRC2012_val_00022154.bin 224 224 +6336 ./prep_dataset/ILSVRC2012_val_00010754.bin 224 224 +6337 ./prep_dataset/ILSVRC2012_val_00027012.bin 224 224 +6338 ./prep_dataset/ILSVRC2012_val_00023617.bin 224 224 +6339 ./prep_dataset/ILSVRC2012_val_00021216.bin 224 224 +6340 ./prep_dataset/ILSVRC2012_val_00023465.bin 224 224 +6341 ./prep_dataset/ILSVRC2012_val_00011046.bin 224 224 +6342 ./prep_dataset/ILSVRC2012_val_00015357.bin 224 224 +6343 ./prep_dataset/ILSVRC2012_val_00028078.bin 224 224 +6344 ./prep_dataset/ILSVRC2012_val_00011988.bin 224 224 +6345 ./prep_dataset/ILSVRC2012_val_00037748.bin 224 224 +6346 ./prep_dataset/ILSVRC2012_val_00037929.bin 224 224 +6347 ./prep_dataset/ILSVRC2012_val_00011495.bin 224 224 +6348 ./prep_dataset/ILSVRC2012_val_00028163.bin 224 224 +6349 ./prep_dataset/ILSVRC2012_val_00017923.bin 224 224 +6350 ./prep_dataset/ILSVRC2012_val_00038662.bin 224 224 +6351 ./prep_dataset/ILSVRC2012_val_00044892.bin 224 224 +6352 ./prep_dataset/ILSVRC2012_val_00001173.bin 224 224 +6353 ./prep_dataset/ILSVRC2012_val_00046009.bin 224 224 +6354 ./prep_dataset/ILSVRC2012_val_00047633.bin 224 224 +6355 ./prep_dataset/ILSVRC2012_val_00014475.bin 224 224 +6356 ./prep_dataset/ILSVRC2012_val_00044745.bin 224 224 +6357 ./prep_dataset/ILSVRC2012_val_00019084.bin 224 224 +6358 ./prep_dataset/ILSVRC2012_val_00020352.bin 224 224 +6359 ./prep_dataset/ILSVRC2012_val_00042790.bin 224 224 +6360 ./prep_dataset/ILSVRC2012_val_00019248.bin 224 224 +6361 ./prep_dataset/ILSVRC2012_val_00047402.bin 224 224 +6362 ./prep_dataset/ILSVRC2012_val_00031164.bin 224 224 +6363 ./prep_dataset/ILSVRC2012_val_00046003.bin 224 224 +6364 ./prep_dataset/ILSVRC2012_val_00039930.bin 224 224 +6365 ./prep_dataset/ILSVRC2012_val_00045852.bin 224 224 +6366 ./prep_dataset/ILSVRC2012_val_00008419.bin 224 224 +6367 ./prep_dataset/ILSVRC2012_val_00014600.bin 224 224 +6368 ./prep_dataset/ILSVRC2012_val_00025562.bin 224 224 +6369 ./prep_dataset/ILSVRC2012_val_00044117.bin 224 224 +6370 ./prep_dataset/ILSVRC2012_val_00022913.bin 224 224 +6371 ./prep_dataset/ILSVRC2012_val_00049130.bin 224 224 +6372 ./prep_dataset/ILSVRC2012_val_00045301.bin 224 224 +6373 ./prep_dataset/ILSVRC2012_val_00009200.bin 224 224 +6374 ./prep_dataset/ILSVRC2012_val_00013150.bin 224 224 +6375 ./prep_dataset/ILSVRC2012_val_00035836.bin 224 224 +6376 ./prep_dataset/ILSVRC2012_val_00011837.bin 224 224 +6377 ./prep_dataset/ILSVRC2012_val_00013108.bin 224 224 +6378 ./prep_dataset/ILSVRC2012_val_00000023.bin 224 224 +6379 ./prep_dataset/ILSVRC2012_val_00022660.bin 224 224 +6380 ./prep_dataset/ILSVRC2012_val_00010546.bin 224 224 +6381 ./prep_dataset/ILSVRC2012_val_00016172.bin 224 224 +6382 ./prep_dataset/ILSVRC2012_val_00033695.bin 224 224 +6383 ./prep_dataset/ILSVRC2012_val_00013620.bin 224 224 +6384 ./prep_dataset/ILSVRC2012_val_00036282.bin 224 224 +6385 ./prep_dataset/ILSVRC2012_val_00005938.bin 224 224 +6386 ./prep_dataset/ILSVRC2012_val_00029535.bin 224 224 +6387 ./prep_dataset/ILSVRC2012_val_00021018.bin 224 224 +6388 ./prep_dataset/ILSVRC2012_val_00003884.bin 224 224 +6389 ./prep_dataset/ILSVRC2012_val_00027585.bin 224 224 +6390 ./prep_dataset/ILSVRC2012_val_00021189.bin 224 224 +6391 ./prep_dataset/ILSVRC2012_val_00025893.bin 224 224 +6392 ./prep_dataset/ILSVRC2012_val_00012655.bin 224 224 +6393 ./prep_dataset/ILSVRC2012_val_00014373.bin 224 224 +6394 ./prep_dataset/ILSVRC2012_val_00047050.bin 224 224 +6395 ./prep_dataset/ILSVRC2012_val_00001102.bin 224 224 +6396 ./prep_dataset/ILSVRC2012_val_00032473.bin 224 224 +6397 ./prep_dataset/ILSVRC2012_val_00023809.bin 224 224 +6398 ./prep_dataset/ILSVRC2012_val_00011119.bin 224 224 +6399 ./prep_dataset/ILSVRC2012_val_00030165.bin 224 224 +6400 ./prep_dataset/ILSVRC2012_val_00043990.bin 224 224 +6401 ./prep_dataset/ILSVRC2012_val_00046996.bin 224 224 +6402 ./prep_dataset/ILSVRC2012_val_00037092.bin 224 224 +6403 ./prep_dataset/ILSVRC2012_val_00049285.bin 224 224 +6404 ./prep_dataset/ILSVRC2012_val_00021355.bin 224 224 +6405 ./prep_dataset/ILSVRC2012_val_00008830.bin 224 224 +6406 ./prep_dataset/ILSVRC2012_val_00004858.bin 224 224 +6407 ./prep_dataset/ILSVRC2012_val_00037384.bin 224 224 +6408 ./prep_dataset/ILSVRC2012_val_00027204.bin 224 224 +6409 ./prep_dataset/ILSVRC2012_val_00019377.bin 224 224 +6410 ./prep_dataset/ILSVRC2012_val_00037109.bin 224 224 +6411 ./prep_dataset/ILSVRC2012_val_00034319.bin 224 224 +6412 ./prep_dataset/ILSVRC2012_val_00021201.bin 224 224 +6413 ./prep_dataset/ILSVRC2012_val_00046885.bin 224 224 +6414 ./prep_dataset/ILSVRC2012_val_00037111.bin 224 224 +6415 ./prep_dataset/ILSVRC2012_val_00019098.bin 224 224 +6416 ./prep_dataset/ILSVRC2012_val_00031367.bin 224 224 +6417 ./prep_dataset/ILSVRC2012_val_00014156.bin 224 224 +6418 ./prep_dataset/ILSVRC2012_val_00047980.bin 224 224 +6419 ./prep_dataset/ILSVRC2012_val_00025787.bin 224 224 +6420 ./prep_dataset/ILSVRC2012_val_00031569.bin 224 224 +6421 ./prep_dataset/ILSVRC2012_val_00011965.bin 224 224 +6422 ./prep_dataset/ILSVRC2012_val_00009594.bin 224 224 +6423 ./prep_dataset/ILSVRC2012_val_00039096.bin 224 224 +6424 ./prep_dataset/ILSVRC2012_val_00047424.bin 224 224 +6425 ./prep_dataset/ILSVRC2012_val_00041532.bin 224 224 +6426 ./prep_dataset/ILSVRC2012_val_00019292.bin 224 224 +6427 ./prep_dataset/ILSVRC2012_val_00008261.bin 224 224 +6428 ./prep_dataset/ILSVRC2012_val_00013774.bin 224 224 +6429 ./prep_dataset/ILSVRC2012_val_00008400.bin 224 224 +6430 ./prep_dataset/ILSVRC2012_val_00044301.bin 224 224 +6431 ./prep_dataset/ILSVRC2012_val_00034359.bin 224 224 +6432 ./prep_dataset/ILSVRC2012_val_00036593.bin 224 224 +6433 ./prep_dataset/ILSVRC2012_val_00001313.bin 224 224 +6434 ./prep_dataset/ILSVRC2012_val_00005077.bin 224 224 +6435 ./prep_dataset/ILSVRC2012_val_00038598.bin 224 224 +6436 ./prep_dataset/ILSVRC2012_val_00042089.bin 224 224 +6437 ./prep_dataset/ILSVRC2012_val_00002918.bin 224 224 +6438 ./prep_dataset/ILSVRC2012_val_00013748.bin 224 224 +6439 ./prep_dataset/ILSVRC2012_val_00000060.bin 224 224 +6440 ./prep_dataset/ILSVRC2012_val_00033490.bin 224 224 +6441 ./prep_dataset/ILSVRC2012_val_00021062.bin 224 224 +6442 ./prep_dataset/ILSVRC2012_val_00047673.bin 224 224 +6443 ./prep_dataset/ILSVRC2012_val_00049615.bin 224 224 +6444 ./prep_dataset/ILSVRC2012_val_00011534.bin 224 224 +6445 ./prep_dataset/ILSVRC2012_val_00012216.bin 224 224 +6446 ./prep_dataset/ILSVRC2012_val_00020784.bin 224 224 +6447 ./prep_dataset/ILSVRC2012_val_00015083.bin 224 224 +6448 ./prep_dataset/ILSVRC2012_val_00007336.bin 224 224 +6449 ./prep_dataset/ILSVRC2012_val_00010179.bin 224 224 +6450 ./prep_dataset/ILSVRC2012_val_00031083.bin 224 224 +6451 ./prep_dataset/ILSVRC2012_val_00022643.bin 224 224 +6452 ./prep_dataset/ILSVRC2012_val_00043714.bin 224 224 +6453 ./prep_dataset/ILSVRC2012_val_00035694.bin 224 224 +6454 ./prep_dataset/ILSVRC2012_val_00039378.bin 224 224 +6455 ./prep_dataset/ILSVRC2012_val_00020682.bin 224 224 +6456 ./prep_dataset/ILSVRC2012_val_00038966.bin 224 224 +6457 ./prep_dataset/ILSVRC2012_val_00006692.bin 224 224 +6458 ./prep_dataset/ILSVRC2012_val_00004904.bin 224 224 +6459 ./prep_dataset/ILSVRC2012_val_00044051.bin 224 224 +6460 ./prep_dataset/ILSVRC2012_val_00018074.bin 224 224 +6461 ./prep_dataset/ILSVRC2012_val_00024596.bin 224 224 +6462 ./prep_dataset/ILSVRC2012_val_00014650.bin 224 224 +6463 ./prep_dataset/ILSVRC2012_val_00023600.bin 224 224 +6464 ./prep_dataset/ILSVRC2012_val_00038818.bin 224 224 +6465 ./prep_dataset/ILSVRC2012_val_00046192.bin 224 224 +6466 ./prep_dataset/ILSVRC2012_val_00022178.bin 224 224 +6467 ./prep_dataset/ILSVRC2012_val_00009248.bin 224 224 +6468 ./prep_dataset/ILSVRC2012_val_00025183.bin 224 224 +6469 ./prep_dataset/ILSVRC2012_val_00022384.bin 224 224 +6470 ./prep_dataset/ILSVRC2012_val_00008447.bin 224 224 +6471 ./prep_dataset/ILSVRC2012_val_00048722.bin 224 224 +6472 ./prep_dataset/ILSVRC2012_val_00020284.bin 224 224 +6473 ./prep_dataset/ILSVRC2012_val_00021850.bin 224 224 +6474 ./prep_dataset/ILSVRC2012_val_00002063.bin 224 224 +6475 ./prep_dataset/ILSVRC2012_val_00001065.bin 224 224 +6476 ./prep_dataset/ILSVRC2012_val_00008667.bin 224 224 +6477 ./prep_dataset/ILSVRC2012_val_00008701.bin 224 224 +6478 ./prep_dataset/ILSVRC2012_val_00046648.bin 224 224 +6479 ./prep_dataset/ILSVRC2012_val_00045223.bin 224 224 +6480 ./prep_dataset/ILSVRC2012_val_00003071.bin 224 224 +6481 ./prep_dataset/ILSVRC2012_val_00025726.bin 224 224 +6482 ./prep_dataset/ILSVRC2012_val_00043610.bin 224 224 +6483 ./prep_dataset/ILSVRC2012_val_00044072.bin 224 224 +6484 ./prep_dataset/ILSVRC2012_val_00007160.bin 224 224 +6485 ./prep_dataset/ILSVRC2012_val_00041264.bin 224 224 +6486 ./prep_dataset/ILSVRC2012_val_00017750.bin 224 224 +6487 ./prep_dataset/ILSVRC2012_val_00042692.bin 224 224 +6488 ./prep_dataset/ILSVRC2012_val_00036264.bin 224 224 +6489 ./prep_dataset/ILSVRC2012_val_00014991.bin 224 224 +6490 ./prep_dataset/ILSVRC2012_val_00025935.bin 224 224 +6491 ./prep_dataset/ILSVRC2012_val_00021264.bin 224 224 +6492 ./prep_dataset/ILSVRC2012_val_00036654.bin 224 224 +6493 ./prep_dataset/ILSVRC2012_val_00004507.bin 224 224 +6494 ./prep_dataset/ILSVRC2012_val_00026364.bin 224 224 +6495 ./prep_dataset/ILSVRC2012_val_00003573.bin 224 224 +6496 ./prep_dataset/ILSVRC2012_val_00037644.bin 224 224 +6497 ./prep_dataset/ILSVRC2012_val_00012996.bin 224 224 +6498 ./prep_dataset/ILSVRC2012_val_00006281.bin 224 224 +6499 ./prep_dataset/ILSVRC2012_val_00017163.bin 224 224 +6500 ./prep_dataset/ILSVRC2012_val_00010541.bin 224 224 +6501 ./prep_dataset/ILSVRC2012_val_00002900.bin 224 224 +6502 ./prep_dataset/ILSVRC2012_val_00046033.bin 224 224 +6503 ./prep_dataset/ILSVRC2012_val_00019976.bin 224 224 +6504 ./prep_dataset/ILSVRC2012_val_00026611.bin 224 224 +6505 ./prep_dataset/ILSVRC2012_val_00039515.bin 224 224 +6506 ./prep_dataset/ILSVRC2012_val_00018351.bin 224 224 +6507 ./prep_dataset/ILSVRC2012_val_00028924.bin 224 224 +6508 ./prep_dataset/ILSVRC2012_val_00049969.bin 224 224 +6509 ./prep_dataset/ILSVRC2012_val_00035261.bin 224 224 +6510 ./prep_dataset/ILSVRC2012_val_00002790.bin 224 224 +6511 ./prep_dataset/ILSVRC2012_val_00002644.bin 224 224 +6512 ./prep_dataset/ILSVRC2012_val_00038408.bin 224 224 +6513 ./prep_dataset/ILSVRC2012_val_00033735.bin 224 224 +6514 ./prep_dataset/ILSVRC2012_val_00038845.bin 224 224 +6515 ./prep_dataset/ILSVRC2012_val_00012427.bin 224 224 +6516 ./prep_dataset/ILSVRC2012_val_00001888.bin 224 224 +6517 ./prep_dataset/ILSVRC2012_val_00008137.bin 224 224 +6518 ./prep_dataset/ILSVRC2012_val_00026755.bin 224 224 +6519 ./prep_dataset/ILSVRC2012_val_00022196.bin 224 224 +6520 ./prep_dataset/ILSVRC2012_val_00024176.bin 224 224 +6521 ./prep_dataset/ILSVRC2012_val_00023896.bin 224 224 +6522 ./prep_dataset/ILSVRC2012_val_00021205.bin 224 224 +6523 ./prep_dataset/ILSVRC2012_val_00000758.bin 224 224 +6524 ./prep_dataset/ILSVRC2012_val_00001204.bin 224 224 +6525 ./prep_dataset/ILSVRC2012_val_00047554.bin 224 224 +6526 ./prep_dataset/ILSVRC2012_val_00000938.bin 224 224 +6527 ./prep_dataset/ILSVRC2012_val_00021213.bin 224 224 +6528 ./prep_dataset/ILSVRC2012_val_00033609.bin 224 224 +6529 ./prep_dataset/ILSVRC2012_val_00037037.bin 224 224 +6530 ./prep_dataset/ILSVRC2012_val_00022009.bin 224 224 +6531 ./prep_dataset/ILSVRC2012_val_00020820.bin 224 224 +6532 ./prep_dataset/ILSVRC2012_val_00020448.bin 224 224 +6533 ./prep_dataset/ILSVRC2012_val_00023787.bin 224 224 +6534 ./prep_dataset/ILSVRC2012_val_00013143.bin 224 224 +6535 ./prep_dataset/ILSVRC2012_val_00001801.bin 224 224 +6536 ./prep_dataset/ILSVRC2012_val_00010204.bin 224 224 +6537 ./prep_dataset/ILSVRC2012_val_00007857.bin 224 224 +6538 ./prep_dataset/ILSVRC2012_val_00045478.bin 224 224 +6539 ./prep_dataset/ILSVRC2012_val_00006844.bin 224 224 +6540 ./prep_dataset/ILSVRC2012_val_00038755.bin 224 224 +6541 ./prep_dataset/ILSVRC2012_val_00016031.bin 224 224 +6542 ./prep_dataset/ILSVRC2012_val_00001786.bin 224 224 +6543 ./prep_dataset/ILSVRC2012_val_00020783.bin 224 224 +6544 ./prep_dataset/ILSVRC2012_val_00023058.bin 224 224 +6545 ./prep_dataset/ILSVRC2012_val_00033603.bin 224 224 +6546 ./prep_dataset/ILSVRC2012_val_00030601.bin 224 224 +6547 ./prep_dataset/ILSVRC2012_val_00019169.bin 224 224 +6548 ./prep_dataset/ILSVRC2012_val_00005145.bin 224 224 +6549 ./prep_dataset/ILSVRC2012_val_00036439.bin 224 224 +6550 ./prep_dataset/ILSVRC2012_val_00011184.bin 224 224 +6551 ./prep_dataset/ILSVRC2012_val_00042906.bin 224 224 +6552 ./prep_dataset/ILSVRC2012_val_00024457.bin 224 224 +6553 ./prep_dataset/ILSVRC2012_val_00034986.bin 224 224 +6554 ./prep_dataset/ILSVRC2012_val_00000067.bin 224 224 +6555 ./prep_dataset/ILSVRC2012_val_00020787.bin 224 224 +6556 ./prep_dataset/ILSVRC2012_val_00018489.bin 224 224 +6557 ./prep_dataset/ILSVRC2012_val_00006770.bin 224 224 +6558 ./prep_dataset/ILSVRC2012_val_00001996.bin 224 224 +6559 ./prep_dataset/ILSVRC2012_val_00038563.bin 224 224 +6560 ./prep_dataset/ILSVRC2012_val_00026142.bin 224 224 +6561 ./prep_dataset/ILSVRC2012_val_00010523.bin 224 224 +6562 ./prep_dataset/ILSVRC2012_val_00048882.bin 224 224 +6563 ./prep_dataset/ILSVRC2012_val_00001257.bin 224 224 +6564 ./prep_dataset/ILSVRC2012_val_00048314.bin 224 224 +6565 ./prep_dataset/ILSVRC2012_val_00040012.bin 224 224 +6566 ./prep_dataset/ILSVRC2012_val_00020698.bin 224 224 +6567 ./prep_dataset/ILSVRC2012_val_00032462.bin 224 224 +6568 ./prep_dataset/ILSVRC2012_val_00033746.bin 224 224 +6569 ./prep_dataset/ILSVRC2012_val_00031036.bin 224 224 +6570 ./prep_dataset/ILSVRC2012_val_00012057.bin 224 224 +6571 ./prep_dataset/ILSVRC2012_val_00010726.bin 224 224 +6572 ./prep_dataset/ILSVRC2012_val_00049819.bin 224 224 +6573 ./prep_dataset/ILSVRC2012_val_00014365.bin 224 224 +6574 ./prep_dataset/ILSVRC2012_val_00003100.bin 224 224 +6575 ./prep_dataset/ILSVRC2012_val_00035514.bin 224 224 +6576 ./prep_dataset/ILSVRC2012_val_00014419.bin 224 224 +6577 ./prep_dataset/ILSVRC2012_val_00030976.bin 224 224 +6578 ./prep_dataset/ILSVRC2012_val_00018264.bin 224 224 +6579 ./prep_dataset/ILSVRC2012_val_00049451.bin 224 224 +6580 ./prep_dataset/ILSVRC2012_val_00023296.bin 224 224 +6581 ./prep_dataset/ILSVRC2012_val_00005604.bin 224 224 +6582 ./prep_dataset/ILSVRC2012_val_00004453.bin 224 224 +6583 ./prep_dataset/ILSVRC2012_val_00049480.bin 224 224 +6584 ./prep_dataset/ILSVRC2012_val_00027269.bin 224 224 +6585 ./prep_dataset/ILSVRC2012_val_00027115.bin 224 224 +6586 ./prep_dataset/ILSVRC2012_val_00037951.bin 224 224 +6587 ./prep_dataset/ILSVRC2012_val_00028144.bin 224 224 +6588 ./prep_dataset/ILSVRC2012_val_00047528.bin 224 224 +6589 ./prep_dataset/ILSVRC2012_val_00040792.bin 224 224 +6590 ./prep_dataset/ILSVRC2012_val_00005101.bin 224 224 +6591 ./prep_dataset/ILSVRC2012_val_00001865.bin 224 224 +6592 ./prep_dataset/ILSVRC2012_val_00030078.bin 224 224 +6593 ./prep_dataset/ILSVRC2012_val_00030579.bin 224 224 +6594 ./prep_dataset/ILSVRC2012_val_00002002.bin 224 224 +6595 ./prep_dataset/ILSVRC2012_val_00025249.bin 224 224 +6596 ./prep_dataset/ILSVRC2012_val_00020592.bin 224 224 +6597 ./prep_dataset/ILSVRC2012_val_00007395.bin 224 224 +6598 ./prep_dataset/ILSVRC2012_val_00048500.bin 224 224 +6599 ./prep_dataset/ILSVRC2012_val_00041722.bin 224 224 +6600 ./prep_dataset/ILSVRC2012_val_00015312.bin 224 224 +6601 ./prep_dataset/ILSVRC2012_val_00046206.bin 224 224 +6602 ./prep_dataset/ILSVRC2012_val_00004857.bin 224 224 +6603 ./prep_dataset/ILSVRC2012_val_00015215.bin 224 224 +6604 ./prep_dataset/ILSVRC2012_val_00009163.bin 224 224 +6605 ./prep_dataset/ILSVRC2012_val_00042382.bin 224 224 +6606 ./prep_dataset/ILSVRC2012_val_00029521.bin 224 224 +6607 ./prep_dataset/ILSVRC2012_val_00008878.bin 224 224 +6608 ./prep_dataset/ILSVRC2012_val_00011373.bin 224 224 +6609 ./prep_dataset/ILSVRC2012_val_00018530.bin 224 224 +6610 ./prep_dataset/ILSVRC2012_val_00013074.bin 224 224 +6611 ./prep_dataset/ILSVRC2012_val_00040233.bin 224 224 +6612 ./prep_dataset/ILSVRC2012_val_00026321.bin 224 224 +6613 ./prep_dataset/ILSVRC2012_val_00004463.bin 224 224 +6614 ./prep_dataset/ILSVRC2012_val_00028186.bin 224 224 +6615 ./prep_dataset/ILSVRC2012_val_00001414.bin 224 224 +6616 ./prep_dataset/ILSVRC2012_val_00046820.bin 224 224 +6617 ./prep_dataset/ILSVRC2012_val_00036998.bin 224 224 +6618 ./prep_dataset/ILSVRC2012_val_00013986.bin 224 224 +6619 ./prep_dataset/ILSVRC2012_val_00037396.bin 224 224 +6620 ./prep_dataset/ILSVRC2012_val_00016351.bin 224 224 +6621 ./prep_dataset/ILSVRC2012_val_00025609.bin 224 224 +6622 ./prep_dataset/ILSVRC2012_val_00042738.bin 224 224 +6623 ./prep_dataset/ILSVRC2012_val_00016511.bin 224 224 +6624 ./prep_dataset/ILSVRC2012_val_00030514.bin 224 224 +6625 ./prep_dataset/ILSVRC2012_val_00046772.bin 224 224 +6626 ./prep_dataset/ILSVRC2012_val_00014160.bin 224 224 +6627 ./prep_dataset/ILSVRC2012_val_00021074.bin 224 224 +6628 ./prep_dataset/ILSVRC2012_val_00036948.bin 224 224 +6629 ./prep_dataset/ILSVRC2012_val_00037039.bin 224 224 +6630 ./prep_dataset/ILSVRC2012_val_00047348.bin 224 224 +6631 ./prep_dataset/ILSVRC2012_val_00026410.bin 224 224 +6632 ./prep_dataset/ILSVRC2012_val_00008057.bin 224 224 +6633 ./prep_dataset/ILSVRC2012_val_00019966.bin 224 224 +6634 ./prep_dataset/ILSVRC2012_val_00000842.bin 224 224 +6635 ./prep_dataset/ILSVRC2012_val_00013469.bin 224 224 +6636 ./prep_dataset/ILSVRC2012_val_00003486.bin 224 224 +6637 ./prep_dataset/ILSVRC2012_val_00010240.bin 224 224 +6638 ./prep_dataset/ILSVRC2012_val_00025170.bin 224 224 +6639 ./prep_dataset/ILSVRC2012_val_00018501.bin 224 224 +6640 ./prep_dataset/ILSVRC2012_val_00016564.bin 224 224 +6641 ./prep_dataset/ILSVRC2012_val_00007479.bin 224 224 +6642 ./prep_dataset/ILSVRC2012_val_00047836.bin 224 224 +6643 ./prep_dataset/ILSVRC2012_val_00031249.bin 224 224 +6644 ./prep_dataset/ILSVRC2012_val_00003491.bin 224 224 +6645 ./prep_dataset/ILSVRC2012_val_00049395.bin 224 224 +6646 ./prep_dataset/ILSVRC2012_val_00016360.bin 224 224 +6647 ./prep_dataset/ILSVRC2012_val_00034605.bin 224 224 +6648 ./prep_dataset/ILSVRC2012_val_00004756.bin 224 224 +6649 ./prep_dataset/ILSVRC2012_val_00011372.bin 224 224 +6650 ./prep_dataset/ILSVRC2012_val_00031171.bin 224 224 +6651 ./prep_dataset/ILSVRC2012_val_00035277.bin 224 224 +6652 ./prep_dataset/ILSVRC2012_val_00029809.bin 224 224 +6653 ./prep_dataset/ILSVRC2012_val_00030174.bin 224 224 +6654 ./prep_dataset/ILSVRC2012_val_00016725.bin 224 224 +6655 ./prep_dataset/ILSVRC2012_val_00048595.bin 224 224 +6656 ./prep_dataset/ILSVRC2012_val_00031167.bin 224 224 +6657 ./prep_dataset/ILSVRC2012_val_00004132.bin 224 224 +6658 ./prep_dataset/ILSVRC2012_val_00000716.bin 224 224 +6659 ./prep_dataset/ILSVRC2012_val_00004332.bin 224 224 +6660 ./prep_dataset/ILSVRC2012_val_00026077.bin 224 224 +6661 ./prep_dataset/ILSVRC2012_val_00041638.bin 224 224 +6662 ./prep_dataset/ILSVRC2012_val_00014065.bin 224 224 +6663 ./prep_dataset/ILSVRC2012_val_00028225.bin 224 224 +6664 ./prep_dataset/ILSVRC2012_val_00009462.bin 224 224 +6665 ./prep_dataset/ILSVRC2012_val_00039106.bin 224 224 +6666 ./prep_dataset/ILSVRC2012_val_00004437.bin 224 224 +6667 ./prep_dataset/ILSVRC2012_val_00000861.bin 224 224 +6668 ./prep_dataset/ILSVRC2012_val_00039377.bin 224 224 +6669 ./prep_dataset/ILSVRC2012_val_00009601.bin 224 224 +6670 ./prep_dataset/ILSVRC2012_val_00038470.bin 224 224 +6671 ./prep_dataset/ILSVRC2012_val_00041020.bin 224 224 +6672 ./prep_dataset/ILSVRC2012_val_00037815.bin 224 224 +6673 ./prep_dataset/ILSVRC2012_val_00044837.bin 224 224 +6674 ./prep_dataset/ILSVRC2012_val_00008776.bin 224 224 +6675 ./prep_dataset/ILSVRC2012_val_00029648.bin 224 224 +6676 ./prep_dataset/ILSVRC2012_val_00033393.bin 224 224 +6677 ./prep_dataset/ILSVRC2012_val_00017619.bin 224 224 +6678 ./prep_dataset/ILSVRC2012_val_00034264.bin 224 224 +6679 ./prep_dataset/ILSVRC2012_val_00013277.bin 224 224 +6680 ./prep_dataset/ILSVRC2012_val_00041877.bin 224 224 +6681 ./prep_dataset/ILSVRC2012_val_00001400.bin 224 224 +6682 ./prep_dataset/ILSVRC2012_val_00040163.bin 224 224 +6683 ./prep_dataset/ILSVRC2012_val_00021951.bin 224 224 +6684 ./prep_dataset/ILSVRC2012_val_00038898.bin 224 224 +6685 ./prep_dataset/ILSVRC2012_val_00006402.bin 224 224 +6686 ./prep_dataset/ILSVRC2012_val_00031310.bin 224 224 +6687 ./prep_dataset/ILSVRC2012_val_00044852.bin 224 224 +6688 ./prep_dataset/ILSVRC2012_val_00044562.bin 224 224 +6689 ./prep_dataset/ILSVRC2012_val_00004427.bin 224 224 +6690 ./prep_dataset/ILSVRC2012_val_00049372.bin 224 224 +6691 ./prep_dataset/ILSVRC2012_val_00005755.bin 224 224 +6692 ./prep_dataset/ILSVRC2012_val_00009862.bin 224 224 +6693 ./prep_dataset/ILSVRC2012_val_00014885.bin 224 224 +6694 ./prep_dataset/ILSVRC2012_val_00048498.bin 224 224 +6695 ./prep_dataset/ILSVRC2012_val_00048700.bin 224 224 +6696 ./prep_dataset/ILSVRC2012_val_00046591.bin 224 224 +6697 ./prep_dataset/ILSVRC2012_val_00043017.bin 224 224 +6698 ./prep_dataset/ILSVRC2012_val_00019542.bin 224 224 +6699 ./prep_dataset/ILSVRC2012_val_00030263.bin 224 224 +6700 ./prep_dataset/ILSVRC2012_val_00010906.bin 224 224 +6701 ./prep_dataset/ILSVRC2012_val_00022940.bin 224 224 +6702 ./prep_dataset/ILSVRC2012_val_00049648.bin 224 224 +6703 ./prep_dataset/ILSVRC2012_val_00016896.bin 224 224 +6704 ./prep_dataset/ILSVRC2012_val_00048514.bin 224 224 +6705 ./prep_dataset/ILSVRC2012_val_00037692.bin 224 224 +6706 ./prep_dataset/ILSVRC2012_val_00032314.bin 224 224 +6707 ./prep_dataset/ILSVRC2012_val_00027138.bin 224 224 +6708 ./prep_dataset/ILSVRC2012_val_00021215.bin 224 224 +6709 ./prep_dataset/ILSVRC2012_val_00040298.bin 224 224 +6710 ./prep_dataset/ILSVRC2012_val_00023863.bin 224 224 +6711 ./prep_dataset/ILSVRC2012_val_00035338.bin 224 224 +6712 ./prep_dataset/ILSVRC2012_val_00039653.bin 224 224 +6713 ./prep_dataset/ILSVRC2012_val_00028621.bin 224 224 +6714 ./prep_dataset/ILSVRC2012_val_00018727.bin 224 224 +6715 ./prep_dataset/ILSVRC2012_val_00040090.bin 224 224 +6716 ./prep_dataset/ILSVRC2012_val_00047865.bin 224 224 +6717 ./prep_dataset/ILSVRC2012_val_00027201.bin 224 224 +6718 ./prep_dataset/ILSVRC2012_val_00048616.bin 224 224 +6719 ./prep_dataset/ILSVRC2012_val_00035395.bin 224 224 +6720 ./prep_dataset/ILSVRC2012_val_00005027.bin 224 224 +6721 ./prep_dataset/ILSVRC2012_val_00039877.bin 224 224 +6722 ./prep_dataset/ILSVRC2012_val_00036202.bin 224 224 +6723 ./prep_dataset/ILSVRC2012_val_00003315.bin 224 224 +6724 ./prep_dataset/ILSVRC2012_val_00020063.bin 224 224 +6725 ./prep_dataset/ILSVRC2012_val_00026317.bin 224 224 +6726 ./prep_dataset/ILSVRC2012_val_00015205.bin 224 224 +6727 ./prep_dataset/ILSVRC2012_val_00021919.bin 224 224 +6728 ./prep_dataset/ILSVRC2012_val_00036374.bin 224 224 +6729 ./prep_dataset/ILSVRC2012_val_00001816.bin 224 224 +6730 ./prep_dataset/ILSVRC2012_val_00033107.bin 224 224 +6731 ./prep_dataset/ILSVRC2012_val_00014153.bin 224 224 +6732 ./prep_dataset/ILSVRC2012_val_00042574.bin 224 224 +6733 ./prep_dataset/ILSVRC2012_val_00029753.bin 224 224 +6734 ./prep_dataset/ILSVRC2012_val_00020089.bin 224 224 +6735 ./prep_dataset/ILSVRC2012_val_00021929.bin 224 224 +6736 ./prep_dataset/ILSVRC2012_val_00002356.bin 224 224 +6737 ./prep_dataset/ILSVRC2012_val_00000863.bin 224 224 +6738 ./prep_dataset/ILSVRC2012_val_00010231.bin 224 224 +6739 ./prep_dataset/ILSVRC2012_val_00009327.bin 224 224 +6740 ./prep_dataset/ILSVRC2012_val_00049312.bin 224 224 +6741 ./prep_dataset/ILSVRC2012_val_00018910.bin 224 224 +6742 ./prep_dataset/ILSVRC2012_val_00042492.bin 224 224 +6743 ./prep_dataset/ILSVRC2012_val_00020125.bin 224 224 +6744 ./prep_dataset/ILSVRC2012_val_00015478.bin 224 224 +6745 ./prep_dataset/ILSVRC2012_val_00034228.bin 224 224 +6746 ./prep_dataset/ILSVRC2012_val_00017806.bin 224 224 +6747 ./prep_dataset/ILSVRC2012_val_00043127.bin 224 224 +6748 ./prep_dataset/ILSVRC2012_val_00011395.bin 224 224 +6749 ./prep_dataset/ILSVRC2012_val_00049776.bin 224 224 +6750 ./prep_dataset/ILSVRC2012_val_00012688.bin 224 224 +6751 ./prep_dataset/ILSVRC2012_val_00018344.bin 224 224 +6752 ./prep_dataset/ILSVRC2012_val_00000303.bin 224 224 +6753 ./prep_dataset/ILSVRC2012_val_00003516.bin 224 224 +6754 ./prep_dataset/ILSVRC2012_val_00014432.bin 224 224 +6755 ./prep_dataset/ILSVRC2012_val_00025858.bin 224 224 +6756 ./prep_dataset/ILSVRC2012_val_00033743.bin 224 224 +6757 ./prep_dataset/ILSVRC2012_val_00018596.bin 224 224 +6758 ./prep_dataset/ILSVRC2012_val_00001673.bin 224 224 +6759 ./prep_dataset/ILSVRC2012_val_00027406.bin 224 224 +6760 ./prep_dataset/ILSVRC2012_val_00010993.bin 224 224 +6761 ./prep_dataset/ILSVRC2012_val_00004490.bin 224 224 +6762 ./prep_dataset/ILSVRC2012_val_00030395.bin 224 224 +6763 ./prep_dataset/ILSVRC2012_val_00032177.bin 224 224 +6764 ./prep_dataset/ILSVRC2012_val_00002541.bin 224 224 +6765 ./prep_dataset/ILSVRC2012_val_00027463.bin 224 224 +6766 ./prep_dataset/ILSVRC2012_val_00010389.bin 224 224 +6767 ./prep_dataset/ILSVRC2012_val_00034481.bin 224 224 +6768 ./prep_dataset/ILSVRC2012_val_00006316.bin 224 224 +6769 ./prep_dataset/ILSVRC2012_val_00022513.bin 224 224 +6770 ./prep_dataset/ILSVRC2012_val_00041119.bin 224 224 +6771 ./prep_dataset/ILSVRC2012_val_00036229.bin 224 224 +6772 ./prep_dataset/ILSVRC2012_val_00003867.bin 224 224 +6773 ./prep_dataset/ILSVRC2012_val_00041754.bin 224 224 +6774 ./prep_dataset/ILSVRC2012_val_00015513.bin 224 224 +6775 ./prep_dataset/ILSVRC2012_val_00005086.bin 224 224 +6776 ./prep_dataset/ILSVRC2012_val_00048840.bin 224 224 +6777 ./prep_dataset/ILSVRC2012_val_00026895.bin 224 224 +6778 ./prep_dataset/ILSVRC2012_val_00045935.bin 224 224 +6779 ./prep_dataset/ILSVRC2012_val_00006204.bin 224 224 +6780 ./prep_dataset/ILSVRC2012_val_00017373.bin 224 224 +6781 ./prep_dataset/ILSVRC2012_val_00028565.bin 224 224 +6782 ./prep_dataset/ILSVRC2012_val_00049568.bin 224 224 +6783 ./prep_dataset/ILSVRC2012_val_00038038.bin 224 224 +6784 ./prep_dataset/ILSVRC2012_val_00026416.bin 224 224 +6785 ./prep_dataset/ILSVRC2012_val_00000175.bin 224 224 +6786 ./prep_dataset/ILSVRC2012_val_00010791.bin 224 224 +6787 ./prep_dataset/ILSVRC2012_val_00026989.bin 224 224 +6788 ./prep_dataset/ILSVRC2012_val_00010183.bin 224 224 +6789 ./prep_dataset/ILSVRC2012_val_00031758.bin 224 224 +6790 ./prep_dataset/ILSVRC2012_val_00005352.bin 224 224 +6791 ./prep_dataset/ILSVRC2012_val_00012182.bin 224 224 +6792 ./prep_dataset/ILSVRC2012_val_00039584.bin 224 224 +6793 ./prep_dataset/ILSVRC2012_val_00018923.bin 224 224 +6794 ./prep_dataset/ILSVRC2012_val_00042768.bin 224 224 +6795 ./prep_dataset/ILSVRC2012_val_00032880.bin 224 224 +6796 ./prep_dataset/ILSVRC2012_val_00034369.bin 224 224 +6797 ./prep_dataset/ILSVRC2012_val_00029856.bin 224 224 +6798 ./prep_dataset/ILSVRC2012_val_00007644.bin 224 224 +6799 ./prep_dataset/ILSVRC2012_val_00004595.bin 224 224 +6800 ./prep_dataset/ILSVRC2012_val_00046671.bin 224 224 +6801 ./prep_dataset/ILSVRC2012_val_00007893.bin 224 224 +6802 ./prep_dataset/ILSVRC2012_val_00045120.bin 224 224 +6803 ./prep_dataset/ILSVRC2012_val_00017180.bin 224 224 +6804 ./prep_dataset/ILSVRC2012_val_00046524.bin 224 224 +6805 ./prep_dataset/ILSVRC2012_val_00029326.bin 224 224 +6806 ./prep_dataset/ILSVRC2012_val_00034344.bin 224 224 +6807 ./prep_dataset/ILSVRC2012_val_00047593.bin 224 224 +6808 ./prep_dataset/ILSVRC2012_val_00045745.bin 224 224 +6809 ./prep_dataset/ILSVRC2012_val_00010382.bin 224 224 +6810 ./prep_dataset/ILSVRC2012_val_00005913.bin 224 224 +6811 ./prep_dataset/ILSVRC2012_val_00023774.bin 224 224 +6812 ./prep_dataset/ILSVRC2012_val_00000024.bin 224 224 +6813 ./prep_dataset/ILSVRC2012_val_00006008.bin 224 224 +6814 ./prep_dataset/ILSVRC2012_val_00015408.bin 224 224 +6815 ./prep_dataset/ILSVRC2012_val_00047329.bin 224 224 +6816 ./prep_dataset/ILSVRC2012_val_00041246.bin 224 224 +6817 ./prep_dataset/ILSVRC2012_val_00004273.bin 224 224 +6818 ./prep_dataset/ILSVRC2012_val_00010058.bin 224 224 +6819 ./prep_dataset/ILSVRC2012_val_00028958.bin 224 224 +6820 ./prep_dataset/ILSVRC2012_val_00038110.bin 224 224 +6821 ./prep_dataset/ILSVRC2012_val_00003963.bin 224 224 +6822 ./prep_dataset/ILSVRC2012_val_00047048.bin 224 224 +6823 ./prep_dataset/ILSVRC2012_val_00045641.bin 224 224 +6824 ./prep_dataset/ILSVRC2012_val_00015623.bin 224 224 +6825 ./prep_dataset/ILSVRC2012_val_00013595.bin 224 224 +6826 ./prep_dataset/ILSVRC2012_val_00031752.bin 224 224 +6827 ./prep_dataset/ILSVRC2012_val_00007809.bin 224 224 +6828 ./prep_dataset/ILSVRC2012_val_00049572.bin 224 224 +6829 ./prep_dataset/ILSVRC2012_val_00039324.bin 224 224 +6830 ./prep_dataset/ILSVRC2012_val_00015414.bin 224 224 +6831 ./prep_dataset/ILSVRC2012_val_00048679.bin 224 224 +6832 ./prep_dataset/ILSVRC2012_val_00012123.bin 224 224 +6833 ./prep_dataset/ILSVRC2012_val_00026622.bin 224 224 +6834 ./prep_dataset/ILSVRC2012_val_00003481.bin 224 224 +6835 ./prep_dataset/ILSVRC2012_val_00013572.bin 224 224 +6836 ./prep_dataset/ILSVRC2012_val_00026880.bin 224 224 +6837 ./prep_dataset/ILSVRC2012_val_00040746.bin 224 224 +6838 ./prep_dataset/ILSVRC2012_val_00037299.bin 224 224 +6839 ./prep_dataset/ILSVRC2012_val_00021843.bin 224 224 +6840 ./prep_dataset/ILSVRC2012_val_00036560.bin 224 224 +6841 ./prep_dataset/ILSVRC2012_val_00037938.bin 224 224 +6842 ./prep_dataset/ILSVRC2012_val_00004074.bin 224 224 +6843 ./prep_dataset/ILSVRC2012_val_00034960.bin 224 224 +6844 ./prep_dataset/ILSVRC2012_val_00036761.bin 224 224 +6845 ./prep_dataset/ILSVRC2012_val_00040589.bin 224 224 +6846 ./prep_dataset/ILSVRC2012_val_00020461.bin 224 224 +6847 ./prep_dataset/ILSVRC2012_val_00000880.bin 224 224 +6848 ./prep_dataset/ILSVRC2012_val_00037163.bin 224 224 +6849 ./prep_dataset/ILSVRC2012_val_00003964.bin 224 224 +6850 ./prep_dataset/ILSVRC2012_val_00036259.bin 224 224 +6851 ./prep_dataset/ILSVRC2012_val_00026101.bin 224 224 +6852 ./prep_dataset/ILSVRC2012_val_00011136.bin 224 224 +6853 ./prep_dataset/ILSVRC2012_val_00028492.bin 224 224 +6854 ./prep_dataset/ILSVRC2012_val_00007581.bin 224 224 +6855 ./prep_dataset/ILSVRC2012_val_00031870.bin 224 224 +6856 ./prep_dataset/ILSVRC2012_val_00042076.bin 224 224 +6857 ./prep_dataset/ILSVRC2012_val_00021193.bin 224 224 +6858 ./prep_dataset/ILSVRC2012_val_00020277.bin 224 224 +6859 ./prep_dataset/ILSVRC2012_val_00024909.bin 224 224 +6860 ./prep_dataset/ILSVRC2012_val_00040580.bin 224 224 +6861 ./prep_dataset/ILSVRC2012_val_00031748.bin 224 224 +6862 ./prep_dataset/ILSVRC2012_val_00028815.bin 224 224 +6863 ./prep_dataset/ILSVRC2012_val_00042013.bin 224 224 +6864 ./prep_dataset/ILSVRC2012_val_00028859.bin 224 224 +6865 ./prep_dataset/ILSVRC2012_val_00027101.bin 224 224 +6866 ./prep_dataset/ILSVRC2012_val_00001589.bin 224 224 +6867 ./prep_dataset/ILSVRC2012_val_00016925.bin 224 224 +6868 ./prep_dataset/ILSVRC2012_val_00014308.bin 224 224 +6869 ./prep_dataset/ILSVRC2012_val_00016304.bin 224 224 +6870 ./prep_dataset/ILSVRC2012_val_00038219.bin 224 224 +6871 ./prep_dataset/ILSVRC2012_val_00043554.bin 224 224 +6872 ./prep_dataset/ILSVRC2012_val_00018731.bin 224 224 +6873 ./prep_dataset/ILSVRC2012_val_00045763.bin 224 224 +6874 ./prep_dataset/ILSVRC2012_val_00016061.bin 224 224 +6875 ./prep_dataset/ILSVRC2012_val_00024348.bin 224 224 +6876 ./prep_dataset/ILSVRC2012_val_00005772.bin 224 224 +6877 ./prep_dataset/ILSVRC2012_val_00015592.bin 224 224 +6878 ./prep_dataset/ILSVRC2012_val_00025535.bin 224 224 +6879 ./prep_dataset/ILSVRC2012_val_00047846.bin 224 224 +6880 ./prep_dataset/ILSVRC2012_val_00046745.bin 224 224 +6881 ./prep_dataset/ILSVRC2012_val_00021037.bin 224 224 +6882 ./prep_dataset/ILSVRC2012_val_00020191.bin 224 224 +6883 ./prep_dataset/ILSVRC2012_val_00038676.bin 224 224 +6884 ./prep_dataset/ILSVRC2012_val_00033637.bin 224 224 +6885 ./prep_dataset/ILSVRC2012_val_00010115.bin 224 224 +6886 ./prep_dataset/ILSVRC2012_val_00002324.bin 224 224 +6887 ./prep_dataset/ILSVRC2012_val_00031246.bin 224 224 +6888 ./prep_dataset/ILSVRC2012_val_00027164.bin 224 224 +6889 ./prep_dataset/ILSVRC2012_val_00019249.bin 224 224 +6890 ./prep_dataset/ILSVRC2012_val_00010845.bin 224 224 +6891 ./prep_dataset/ILSVRC2012_val_00047887.bin 224 224 +6892 ./prep_dataset/ILSVRC2012_val_00024050.bin 224 224 +6893 ./prep_dataset/ILSVRC2012_val_00033908.bin 224 224 +6894 ./prep_dataset/ILSVRC2012_val_00028873.bin 224 224 +6895 ./prep_dataset/ILSVRC2012_val_00000433.bin 224 224 +6896 ./prep_dataset/ILSVRC2012_val_00025614.bin 224 224 +6897 ./prep_dataset/ILSVRC2012_val_00005780.bin 224 224 +6898 ./prep_dataset/ILSVRC2012_val_00023762.bin 224 224 +6899 ./prep_dataset/ILSVRC2012_val_00011248.bin 224 224 +6900 ./prep_dataset/ILSVRC2012_val_00024429.bin 224 224 +6901 ./prep_dataset/ILSVRC2012_val_00043785.bin 224 224 +6902 ./prep_dataset/ILSVRC2012_val_00021482.bin 224 224 +6903 ./prep_dataset/ILSVRC2012_val_00041926.bin 224 224 +6904 ./prep_dataset/ILSVRC2012_val_00043525.bin 224 224 +6905 ./prep_dataset/ILSVRC2012_val_00005297.bin 224 224 +6906 ./prep_dataset/ILSVRC2012_val_00015044.bin 224 224 +6907 ./prep_dataset/ILSVRC2012_val_00027305.bin 224 224 +6908 ./prep_dataset/ILSVRC2012_val_00027761.bin 224 224 +6909 ./prep_dataset/ILSVRC2012_val_00045191.bin 224 224 +6910 ./prep_dataset/ILSVRC2012_val_00033311.bin 224 224 +6911 ./prep_dataset/ILSVRC2012_val_00014790.bin 224 224 +6912 ./prep_dataset/ILSVRC2012_val_00026933.bin 224 224 +6913 ./prep_dataset/ILSVRC2012_val_00017638.bin 224 224 +6914 ./prep_dataset/ILSVRC2012_val_00012944.bin 224 224 +6915 ./prep_dataset/ILSVRC2012_val_00019066.bin 224 224 +6916 ./prep_dataset/ILSVRC2012_val_00009826.bin 224 224 +6917 ./prep_dataset/ILSVRC2012_val_00011716.bin 224 224 +6918 ./prep_dataset/ILSVRC2012_val_00043117.bin 224 224 +6919 ./prep_dataset/ILSVRC2012_val_00028634.bin 224 224 +6920 ./prep_dataset/ILSVRC2012_val_00028811.bin 224 224 +6921 ./prep_dataset/ILSVRC2012_val_00013605.bin 224 224 +6922 ./prep_dataset/ILSVRC2012_val_00049876.bin 224 224 +6923 ./prep_dataset/ILSVRC2012_val_00036667.bin 224 224 +6924 ./prep_dataset/ILSVRC2012_val_00046738.bin 224 224 +6925 ./prep_dataset/ILSVRC2012_val_00006183.bin 224 224 +6926 ./prep_dataset/ILSVRC2012_val_00028951.bin 224 224 +6927 ./prep_dataset/ILSVRC2012_val_00016059.bin 224 224 +6928 ./prep_dataset/ILSVRC2012_val_00030577.bin 224 224 +6929 ./prep_dataset/ILSVRC2012_val_00010624.bin 224 224 +6930 ./prep_dataset/ILSVRC2012_val_00012127.bin 224 224 +6931 ./prep_dataset/ILSVRC2012_val_00006030.bin 224 224 +6932 ./prep_dataset/ILSVRC2012_val_00045186.bin 224 224 +6933 ./prep_dataset/ILSVRC2012_val_00047609.bin 224 224 +6934 ./prep_dataset/ILSVRC2012_val_00045152.bin 224 224 +6935 ./prep_dataset/ILSVRC2012_val_00048327.bin 224 224 +6936 ./prep_dataset/ILSVRC2012_val_00007880.bin 224 224 +6937 ./prep_dataset/ILSVRC2012_val_00021457.bin 224 224 +6938 ./prep_dataset/ILSVRC2012_val_00042610.bin 224 224 +6939 ./prep_dataset/ILSVRC2012_val_00039717.bin 224 224 +6940 ./prep_dataset/ILSVRC2012_val_00014849.bin 224 224 +6941 ./prep_dataset/ILSVRC2012_val_00038795.bin 224 224 +6942 ./prep_dataset/ILSVRC2012_val_00039469.bin 224 224 +6943 ./prep_dataset/ILSVRC2012_val_00008524.bin 224 224 +6944 ./prep_dataset/ILSVRC2012_val_00027739.bin 224 224 +6945 ./prep_dataset/ILSVRC2012_val_00016022.bin 224 224 +6946 ./prep_dataset/ILSVRC2012_val_00036966.bin 224 224 +6947 ./prep_dataset/ILSVRC2012_val_00039458.bin 224 224 +6948 ./prep_dataset/ILSVRC2012_val_00007255.bin 224 224 +6949 ./prep_dataset/ILSVRC2012_val_00030355.bin 224 224 +6950 ./prep_dataset/ILSVRC2012_val_00012807.bin 224 224 +6951 ./prep_dataset/ILSVRC2012_val_00033533.bin 224 224 +6952 ./prep_dataset/ILSVRC2012_val_00038832.bin 224 224 +6953 ./prep_dataset/ILSVRC2012_val_00026146.bin 224 224 +6954 ./prep_dataset/ILSVRC2012_val_00007006.bin 224 224 +6955 ./prep_dataset/ILSVRC2012_val_00023570.bin 224 224 +6956 ./prep_dataset/ILSVRC2012_val_00002598.bin 224 224 +6957 ./prep_dataset/ILSVRC2012_val_00009968.bin 224 224 +6958 ./prep_dataset/ILSVRC2012_val_00021913.bin 224 224 +6959 ./prep_dataset/ILSVRC2012_val_00048596.bin 224 224 +6960 ./prep_dataset/ILSVRC2012_val_00026462.bin 224 224 +6961 ./prep_dataset/ILSVRC2012_val_00007727.bin 224 224 +6962 ./prep_dataset/ILSVRC2012_val_00040628.bin 224 224 +6963 ./prep_dataset/ILSVRC2012_val_00040954.bin 224 224 +6964 ./prep_dataset/ILSVRC2012_val_00010672.bin 224 224 +6965 ./prep_dataset/ILSVRC2012_val_00006670.bin 224 224 +6966 ./prep_dataset/ILSVRC2012_val_00047122.bin 224 224 +6967 ./prep_dataset/ILSVRC2012_val_00020400.bin 224 224 +6968 ./prep_dataset/ILSVRC2012_val_00029112.bin 224 224 +6969 ./prep_dataset/ILSVRC2012_val_00002872.bin 224 224 +6970 ./prep_dataset/ILSVRC2012_val_00037874.bin 224 224 +6971 ./prep_dataset/ILSVRC2012_val_00038894.bin 224 224 +6972 ./prep_dataset/ILSVRC2012_val_00029334.bin 224 224 +6973 ./prep_dataset/ILSVRC2012_val_00040064.bin 224 224 +6974 ./prep_dataset/ILSVRC2012_val_00009475.bin 224 224 +6975 ./prep_dataset/ILSVRC2012_val_00047706.bin 224 224 +6976 ./prep_dataset/ILSVRC2012_val_00020806.bin 224 224 +6977 ./prep_dataset/ILSVRC2012_val_00030412.bin 224 224 +6978 ./prep_dataset/ILSVRC2012_val_00006675.bin 224 224 +6979 ./prep_dataset/ILSVRC2012_val_00039964.bin 224 224 +6980 ./prep_dataset/ILSVRC2012_val_00047964.bin 224 224 +6981 ./prep_dataset/ILSVRC2012_val_00033187.bin 224 224 +6982 ./prep_dataset/ILSVRC2012_val_00005523.bin 224 224 +6983 ./prep_dataset/ILSVRC2012_val_00020498.bin 224 224 +6984 ./prep_dataset/ILSVRC2012_val_00034386.bin 224 224 +6985 ./prep_dataset/ILSVRC2012_val_00022780.bin 224 224 +6986 ./prep_dataset/ILSVRC2012_val_00041966.bin 224 224 +6987 ./prep_dataset/ILSVRC2012_val_00030418.bin 224 224 +6988 ./prep_dataset/ILSVRC2012_val_00008092.bin 224 224 +6989 ./prep_dataset/ILSVRC2012_val_00033288.bin 224 224 +6990 ./prep_dataset/ILSVRC2012_val_00010089.bin 224 224 +6991 ./prep_dataset/ILSVRC2012_val_00028345.bin 224 224 +6992 ./prep_dataset/ILSVRC2012_val_00033915.bin 224 224 +6993 ./prep_dataset/ILSVRC2012_val_00023046.bin 224 224 +6994 ./prep_dataset/ILSVRC2012_val_00048746.bin 224 224 +6995 ./prep_dataset/ILSVRC2012_val_00001310.bin 224 224 +6996 ./prep_dataset/ILSVRC2012_val_00006365.bin 224 224 +6997 ./prep_dataset/ILSVRC2012_val_00022025.bin 224 224 +6998 ./prep_dataset/ILSVRC2012_val_00019202.bin 224 224 +6999 ./prep_dataset/ILSVRC2012_val_00041114.bin 224 224 +7000 ./prep_dataset/ILSVRC2012_val_00029863.bin 224 224 +7001 ./prep_dataset/ILSVRC2012_val_00012782.bin 224 224 +7002 ./prep_dataset/ILSVRC2012_val_00024320.bin 224 224 +7003 ./prep_dataset/ILSVRC2012_val_00023814.bin 224 224 +7004 ./prep_dataset/ILSVRC2012_val_00005739.bin 224 224 +7005 ./prep_dataset/ILSVRC2012_val_00008221.bin 224 224 +7006 ./prep_dataset/ILSVRC2012_val_00036757.bin 224 224 +7007 ./prep_dataset/ILSVRC2012_val_00027980.bin 224 224 +7008 ./prep_dataset/ILSVRC2012_val_00037806.bin 224 224 +7009 ./prep_dataset/ILSVRC2012_val_00047686.bin 224 224 +7010 ./prep_dataset/ILSVRC2012_val_00023011.bin 224 224 +7011 ./prep_dataset/ILSVRC2012_val_00015368.bin 224 224 +7012 ./prep_dataset/ILSVRC2012_val_00019626.bin 224 224 +7013 ./prep_dataset/ILSVRC2012_val_00004487.bin 224 224 +7014 ./prep_dataset/ILSVRC2012_val_00046379.bin 224 224 +7015 ./prep_dataset/ILSVRC2012_val_00032892.bin 224 224 +7016 ./prep_dataset/ILSVRC2012_val_00036085.bin 224 224 +7017 ./prep_dataset/ILSVRC2012_val_00025032.bin 224 224 +7018 ./prep_dataset/ILSVRC2012_val_00002320.bin 224 224 +7019 ./prep_dataset/ILSVRC2012_val_00017753.bin 224 224 +7020 ./prep_dataset/ILSVRC2012_val_00033304.bin 224 224 +7021 ./prep_dataset/ILSVRC2012_val_00042729.bin 224 224 +7022 ./prep_dataset/ILSVRC2012_val_00008252.bin 224 224 +7023 ./prep_dataset/ILSVRC2012_val_00010444.bin 224 224 +7024 ./prep_dataset/ILSVRC2012_val_00045094.bin 224 224 +7025 ./prep_dataset/ILSVRC2012_val_00045470.bin 224 224 +7026 ./prep_dataset/ILSVRC2012_val_00005030.bin 224 224 +7027 ./prep_dataset/ILSVRC2012_val_00012531.bin 224 224 +7028 ./prep_dataset/ILSVRC2012_val_00048027.bin 224 224 +7029 ./prep_dataset/ILSVRC2012_val_00007024.bin 224 224 +7030 ./prep_dataset/ILSVRC2012_val_00019037.bin 224 224 +7031 ./prep_dataset/ILSVRC2012_val_00002655.bin 224 224 +7032 ./prep_dataset/ILSVRC2012_val_00012495.bin 224 224 +7033 ./prep_dataset/ILSVRC2012_val_00006738.bin 224 224 +7034 ./prep_dataset/ILSVRC2012_val_00040573.bin 224 224 +7035 ./prep_dataset/ILSVRC2012_val_00008752.bin 224 224 +7036 ./prep_dataset/ILSVRC2012_val_00013088.bin 224 224 +7037 ./prep_dataset/ILSVRC2012_val_00022843.bin 224 224 +7038 ./prep_dataset/ILSVRC2012_val_00017138.bin 224 224 +7039 ./prep_dataset/ILSVRC2012_val_00047948.bin 224 224 +7040 ./prep_dataset/ILSVRC2012_val_00010599.bin 224 224 +7041 ./prep_dataset/ILSVRC2012_val_00033804.bin 224 224 +7042 ./prep_dataset/ILSVRC2012_val_00020453.bin 224 224 +7043 ./prep_dataset/ILSVRC2012_val_00031352.bin 224 224 +7044 ./prep_dataset/ILSVRC2012_val_00047650.bin 224 224 +7045 ./prep_dataset/ILSVRC2012_val_00026935.bin 224 224 +7046 ./prep_dataset/ILSVRC2012_val_00019889.bin 224 224 +7047 ./prep_dataset/ILSVRC2012_val_00004392.bin 224 224 +7048 ./prep_dataset/ILSVRC2012_val_00037071.bin 224 224 +7049 ./prep_dataset/ILSVRC2012_val_00040112.bin 224 224 +7050 ./prep_dataset/ILSVRC2012_val_00020264.bin 224 224 +7051 ./prep_dataset/ILSVRC2012_val_00020519.bin 224 224 +7052 ./prep_dataset/ILSVRC2012_val_00040953.bin 224 224 +7053 ./prep_dataset/ILSVRC2012_val_00014425.bin 224 224 +7054 ./prep_dataset/ILSVRC2012_val_00047460.bin 224 224 +7055 ./prep_dataset/ILSVRC2012_val_00010793.bin 224 224 +7056 ./prep_dataset/ILSVRC2012_val_00034633.bin 224 224 +7057 ./prep_dataset/ILSVRC2012_val_00029679.bin 224 224 +7058 ./prep_dataset/ILSVRC2012_val_00040894.bin 224 224 +7059 ./prep_dataset/ILSVRC2012_val_00033516.bin 224 224 +7060 ./prep_dataset/ILSVRC2012_val_00008665.bin 224 224 +7061 ./prep_dataset/ILSVRC2012_val_00016205.bin 224 224 +7062 ./prep_dataset/ILSVRC2012_val_00028138.bin 224 224 +7063 ./prep_dataset/ILSVRC2012_val_00020759.bin 224 224 +7064 ./prep_dataset/ILSVRC2012_val_00023734.bin 224 224 +7065 ./prep_dataset/ILSVRC2012_val_00047640.bin 224 224 +7066 ./prep_dataset/ILSVRC2012_val_00047679.bin 224 224 +7067 ./prep_dataset/ILSVRC2012_val_00009760.bin 224 224 +7068 ./prep_dataset/ILSVRC2012_val_00037810.bin 224 224 +7069 ./prep_dataset/ILSVRC2012_val_00021529.bin 224 224 +7070 ./prep_dataset/ILSVRC2012_val_00007922.bin 224 224 +7071 ./prep_dataset/ILSVRC2012_val_00037477.bin 224 224 +7072 ./prep_dataset/ILSVRC2012_val_00037498.bin 224 224 +7073 ./prep_dataset/ILSVRC2012_val_00033191.bin 224 224 +7074 ./prep_dataset/ILSVRC2012_val_00031243.bin 224 224 +7075 ./prep_dataset/ILSVRC2012_val_00042978.bin 224 224 +7076 ./prep_dataset/ILSVRC2012_val_00041571.bin 224 224 +7077 ./prep_dataset/ILSVRC2012_val_00043601.bin 224 224 +7078 ./prep_dataset/ILSVRC2012_val_00013417.bin 224 224 +7079 ./prep_dataset/ILSVRC2012_val_00045416.bin 224 224 +7080 ./prep_dataset/ILSVRC2012_val_00023586.bin 224 224 +7081 ./prep_dataset/ILSVRC2012_val_00000777.bin 224 224 +7082 ./prep_dataset/ILSVRC2012_val_00034810.bin 224 224 +7083 ./prep_dataset/ILSVRC2012_val_00016946.bin 224 224 +7084 ./prep_dataset/ILSVRC2012_val_00035304.bin 224 224 +7085 ./prep_dataset/ILSVRC2012_val_00040217.bin 224 224 +7086 ./prep_dataset/ILSVRC2012_val_00037988.bin 224 224 +7087 ./prep_dataset/ILSVRC2012_val_00049756.bin 224 224 +7088 ./prep_dataset/ILSVRC2012_val_00008103.bin 224 224 +7089 ./prep_dataset/ILSVRC2012_val_00025327.bin 224 224 +7090 ./prep_dataset/ILSVRC2012_val_00031136.bin 224 224 +7091 ./prep_dataset/ILSVRC2012_val_00027536.bin 224 224 +7092 ./prep_dataset/ILSVRC2012_val_00016276.bin 224 224 +7093 ./prep_dataset/ILSVRC2012_val_00016874.bin 224 224 +7094 ./prep_dataset/ILSVRC2012_val_00018487.bin 224 224 +7095 ./prep_dataset/ILSVRC2012_val_00011463.bin 224 224 +7096 ./prep_dataset/ILSVRC2012_val_00006224.bin 224 224 +7097 ./prep_dataset/ILSVRC2012_val_00004042.bin 224 224 +7098 ./prep_dataset/ILSVRC2012_val_00049953.bin 224 224 +7099 ./prep_dataset/ILSVRC2012_val_00021747.bin 224 224 +7100 ./prep_dataset/ILSVRC2012_val_00011190.bin 224 224 +7101 ./prep_dataset/ILSVRC2012_val_00046118.bin 224 224 +7102 ./prep_dataset/ILSVRC2012_val_00026524.bin 224 224 +7103 ./prep_dataset/ILSVRC2012_val_00006313.bin 224 224 +7104 ./prep_dataset/ILSVRC2012_val_00005606.bin 224 224 +7105 ./prep_dataset/ILSVRC2012_val_00011814.bin 224 224 +7106 ./prep_dataset/ILSVRC2012_val_00018499.bin 224 224 +7107 ./prep_dataset/ILSVRC2012_val_00033544.bin 224 224 +7108 ./prep_dataset/ILSVRC2012_val_00024591.bin 224 224 +7109 ./prep_dataset/ILSVRC2012_val_00007561.bin 224 224 +7110 ./prep_dataset/ILSVRC2012_val_00019427.bin 224 224 +7111 ./prep_dataset/ILSVRC2012_val_00019525.bin 224 224 +7112 ./prep_dataset/ILSVRC2012_val_00007740.bin 224 224 +7113 ./prep_dataset/ILSVRC2012_val_00028926.bin 224 224 +7114 ./prep_dataset/ILSVRC2012_val_00013314.bin 224 224 +7115 ./prep_dataset/ILSVRC2012_val_00021998.bin 224 224 +7116 ./prep_dataset/ILSVRC2012_val_00005242.bin 224 224 +7117 ./prep_dataset/ILSVRC2012_val_00007132.bin 224 224 +7118 ./prep_dataset/ILSVRC2012_val_00000042.bin 224 224 +7119 ./prep_dataset/ILSVRC2012_val_00031626.bin 224 224 +7120 ./prep_dataset/ILSVRC2012_val_00006487.bin 224 224 +7121 ./prep_dataset/ILSVRC2012_val_00034753.bin 224 224 +7122 ./prep_dataset/ILSVRC2012_val_00039738.bin 224 224 +7123 ./prep_dataset/ILSVRC2012_val_00047924.bin 224 224 +7124 ./prep_dataset/ILSVRC2012_val_00006359.bin 224 224 +7125 ./prep_dataset/ILSVRC2012_val_00008100.bin 224 224 +7126 ./prep_dataset/ILSVRC2012_val_00025121.bin 224 224 +7127 ./prep_dataset/ILSVRC2012_val_00046493.bin 224 224 +7128 ./prep_dataset/ILSVRC2012_val_00015419.bin 224 224 +7129 ./prep_dataset/ILSVRC2012_val_00019356.bin 224 224 +7130 ./prep_dataset/ILSVRC2012_val_00007117.bin 224 224 +7131 ./prep_dataset/ILSVRC2012_val_00022739.bin 224 224 +7132 ./prep_dataset/ILSVRC2012_val_00002802.bin 224 224 +7133 ./prep_dataset/ILSVRC2012_val_00026543.bin 224 224 +7134 ./prep_dataset/ILSVRC2012_val_00044513.bin 224 224 +7135 ./prep_dataset/ILSVRC2012_val_00012803.bin 224 224 +7136 ./prep_dataset/ILSVRC2012_val_00007370.bin 224 224 +7137 ./prep_dataset/ILSVRC2012_val_00001020.bin 224 224 +7138 ./prep_dataset/ILSVRC2012_val_00019208.bin 224 224 +7139 ./prep_dataset/ILSVRC2012_val_00019920.bin 224 224 +7140 ./prep_dataset/ILSVRC2012_val_00035483.bin 224 224 +7141 ./prep_dataset/ILSVRC2012_val_00044186.bin 224 224 +7142 ./prep_dataset/ILSVRC2012_val_00034680.bin 224 224 +7143 ./prep_dataset/ILSVRC2012_val_00029639.bin 224 224 +7144 ./prep_dataset/ILSVRC2012_val_00019060.bin 224 224 +7145 ./prep_dataset/ILSVRC2012_val_00033098.bin 224 224 +7146 ./prep_dataset/ILSVRC2012_val_00000030.bin 224 224 +7147 ./prep_dataset/ILSVRC2012_val_00031448.bin 224 224 +7148 ./prep_dataset/ILSVRC2012_val_00044979.bin 224 224 +7149 ./prep_dataset/ILSVRC2012_val_00031439.bin 224 224 +7150 ./prep_dataset/ILSVRC2012_val_00012066.bin 224 224 +7151 ./prep_dataset/ILSVRC2012_val_00012764.bin 224 224 +7152 ./prep_dataset/ILSVRC2012_val_00005079.bin 224 224 +7153 ./prep_dataset/ILSVRC2012_val_00007570.bin 224 224 +7154 ./prep_dataset/ILSVRC2012_val_00005138.bin 224 224 +7155 ./prep_dataset/ILSVRC2012_val_00017106.bin 224 224 +7156 ./prep_dataset/ILSVRC2012_val_00005807.bin 224 224 +7157 ./prep_dataset/ILSVRC2012_val_00045588.bin 224 224 +7158 ./prep_dataset/ILSVRC2012_val_00035698.bin 224 224 +7159 ./prep_dataset/ILSVRC2012_val_00046961.bin 224 224 +7160 ./prep_dataset/ILSVRC2012_val_00006634.bin 224 224 +7161 ./prep_dataset/ILSVRC2012_val_00006458.bin 224 224 +7162 ./prep_dataset/ILSVRC2012_val_00007608.bin 224 224 +7163 ./prep_dataset/ILSVRC2012_val_00005395.bin 224 224 +7164 ./prep_dataset/ILSVRC2012_val_00033810.bin 224 224 +7165 ./prep_dataset/ILSVRC2012_val_00007782.bin 224 224 +7166 ./prep_dataset/ILSVRC2012_val_00005529.bin 224 224 +7167 ./prep_dataset/ILSVRC2012_val_00008096.bin 224 224 +7168 ./prep_dataset/ILSVRC2012_val_00035536.bin 224 224 +7169 ./prep_dataset/ILSVRC2012_val_00027937.bin 224 224 +7170 ./prep_dataset/ILSVRC2012_val_00021470.bin 224 224 +7171 ./prep_dataset/ILSVRC2012_val_00030393.bin 224 224 +7172 ./prep_dataset/ILSVRC2012_val_00002821.bin 224 224 +7173 ./prep_dataset/ILSVRC2012_val_00034726.bin 224 224 +7174 ./prep_dataset/ILSVRC2012_val_00026061.bin 224 224 +7175 ./prep_dataset/ILSVRC2012_val_00006635.bin 224 224 +7176 ./prep_dataset/ILSVRC2012_val_00016543.bin 224 224 +7177 ./prep_dataset/ILSVRC2012_val_00001488.bin 224 224 +7178 ./prep_dataset/ILSVRC2012_val_00039023.bin 224 224 +7179 ./prep_dataset/ILSVRC2012_val_00004559.bin 224 224 +7180 ./prep_dataset/ILSVRC2012_val_00013419.bin 224 224 +7181 ./prep_dataset/ILSVRC2012_val_00043052.bin 224 224 +7182 ./prep_dataset/ILSVRC2012_val_00039949.bin 224 224 +7183 ./prep_dataset/ILSVRC2012_val_00014888.bin 224 224 +7184 ./prep_dataset/ILSVRC2012_val_00010985.bin 224 224 +7185 ./prep_dataset/ILSVRC2012_val_00044415.bin 224 224 +7186 ./prep_dataset/ILSVRC2012_val_00046802.bin 224 224 +7187 ./prep_dataset/ILSVRC2012_val_00028064.bin 224 224 +7188 ./prep_dataset/ILSVRC2012_val_00049147.bin 224 224 +7189 ./prep_dataset/ILSVRC2012_val_00048508.bin 224 224 +7190 ./prep_dataset/ILSVRC2012_val_00016691.bin 224 224 +7191 ./prep_dataset/ILSVRC2012_val_00025834.bin 224 224 +7192 ./prep_dataset/ILSVRC2012_val_00011293.bin 224 224 +7193 ./prep_dataset/ILSVRC2012_val_00013920.bin 224 224 +7194 ./prep_dataset/ILSVRC2012_val_00011631.bin 224 224 +7195 ./prep_dataset/ILSVRC2012_val_00023318.bin 224 224 +7196 ./prep_dataset/ILSVRC2012_val_00043471.bin 224 224 +7197 ./prep_dataset/ILSVRC2012_val_00016180.bin 224 224 +7198 ./prep_dataset/ILSVRC2012_val_00016388.bin 224 224 +7199 ./prep_dataset/ILSVRC2012_val_00019063.bin 224 224 +7200 ./prep_dataset/ILSVRC2012_val_00014981.bin 224 224 +7201 ./prep_dataset/ILSVRC2012_val_00040763.bin 224 224 +7202 ./prep_dataset/ILSVRC2012_val_00002593.bin 224 224 +7203 ./prep_dataset/ILSVRC2012_val_00011769.bin 224 224 +7204 ./prep_dataset/ILSVRC2012_val_00012286.bin 224 224 +7205 ./prep_dataset/ILSVRC2012_val_00041796.bin 224 224 +7206 ./prep_dataset/ILSVRC2012_val_00000409.bin 224 224 +7207 ./prep_dataset/ILSVRC2012_val_00021679.bin 224 224 +7208 ./prep_dataset/ILSVRC2012_val_00018221.bin 224 224 +7209 ./prep_dataset/ILSVRC2012_val_00014054.bin 224 224 +7210 ./prep_dataset/ILSVRC2012_val_00036186.bin 224 224 +7211 ./prep_dataset/ILSVRC2012_val_00009607.bin 224 224 +7212 ./prep_dataset/ILSVRC2012_val_00006764.bin 224 224 +7213 ./prep_dataset/ILSVRC2012_val_00019779.bin 224 224 +7214 ./prep_dataset/ILSVRC2012_val_00012479.bin 224 224 +7215 ./prep_dataset/ILSVRC2012_val_00033074.bin 224 224 +7216 ./prep_dataset/ILSVRC2012_val_00038474.bin 224 224 +7217 ./prep_dataset/ILSVRC2012_val_00034173.bin 224 224 +7218 ./prep_dataset/ILSVRC2012_val_00027592.bin 224 224 +7219 ./prep_dataset/ILSVRC2012_val_00040059.bin 224 224 +7220 ./prep_dataset/ILSVRC2012_val_00007544.bin 224 224 +7221 ./prep_dataset/ILSVRC2012_val_00043814.bin 224 224 +7222 ./prep_dataset/ILSVRC2012_val_00001646.bin 224 224 +7223 ./prep_dataset/ILSVRC2012_val_00049956.bin 224 224 +7224 ./prep_dataset/ILSVRC2012_val_00007374.bin 224 224 +7225 ./prep_dataset/ILSVRC2012_val_00018585.bin 224 224 +7226 ./prep_dataset/ILSVRC2012_val_00048887.bin 224 224 +7227 ./prep_dataset/ILSVRC2012_val_00033729.bin 224 224 +7228 ./prep_dataset/ILSVRC2012_val_00019461.bin 224 224 +7229 ./prep_dataset/ILSVRC2012_val_00011931.bin 224 224 +7230 ./prep_dataset/ILSVRC2012_val_00012917.bin 224 224 +7231 ./prep_dataset/ILSVRC2012_val_00005180.bin 224 224 +7232 ./prep_dataset/ILSVRC2012_val_00016913.bin 224 224 +7233 ./prep_dataset/ILSVRC2012_val_00008743.bin 224 224 +7234 ./prep_dataset/ILSVRC2012_val_00020077.bin 224 224 +7235 ./prep_dataset/ILSVRC2012_val_00001360.bin 224 224 +7236 ./prep_dataset/ILSVRC2012_val_00048308.bin 224 224 +7237 ./prep_dataset/ILSVRC2012_val_00036043.bin 224 224 +7238 ./prep_dataset/ILSVRC2012_val_00002078.bin 224 224 +7239 ./prep_dataset/ILSVRC2012_val_00031507.bin 224 224 +7240 ./prep_dataset/ILSVRC2012_val_00002915.bin 224 224 +7241 ./prep_dataset/ILSVRC2012_val_00041744.bin 224 224 +7242 ./prep_dataset/ILSVRC2012_val_00042286.bin 224 224 +7243 ./prep_dataset/ILSVRC2012_val_00025724.bin 224 224 +7244 ./prep_dataset/ILSVRC2012_val_00035036.bin 224 224 +7245 ./prep_dataset/ILSVRC2012_val_00027608.bin 224 224 +7246 ./prep_dataset/ILSVRC2012_val_00030107.bin 224 224 +7247 ./prep_dataset/ILSVRC2012_val_00040379.bin 224 224 +7248 ./prep_dataset/ILSVRC2012_val_00020956.bin 224 224 +7249 ./prep_dataset/ILSVRC2012_val_00033900.bin 224 224 +7250 ./prep_dataset/ILSVRC2012_val_00030150.bin 224 224 +7251 ./prep_dataset/ILSVRC2012_val_00005793.bin 224 224 +7252 ./prep_dataset/ILSVRC2012_val_00011160.bin 224 224 +7253 ./prep_dataset/ILSVRC2012_val_00017174.bin 224 224 +7254 ./prep_dataset/ILSVRC2012_val_00028523.bin 224 224 +7255 ./prep_dataset/ILSVRC2012_val_00018629.bin 224 224 +7256 ./prep_dataset/ILSVRC2012_val_00028649.bin 224 224 +7257 ./prep_dataset/ILSVRC2012_val_00030155.bin 224 224 +7258 ./prep_dataset/ILSVRC2012_val_00032132.bin 224 224 +7259 ./prep_dataset/ILSVRC2012_val_00047756.bin 224 224 +7260 ./prep_dataset/ILSVRC2012_val_00024774.bin 224 224 +7261 ./prep_dataset/ILSVRC2012_val_00049474.bin 224 224 +7262 ./prep_dataset/ILSVRC2012_val_00005244.bin 224 224 +7263 ./prep_dataset/ILSVRC2012_val_00032622.bin 224 224 +7264 ./prep_dataset/ILSVRC2012_val_00019560.bin 224 224 +7265 ./prep_dataset/ILSVRC2012_val_00044152.bin 224 224 +7266 ./prep_dataset/ILSVRC2012_val_00026733.bin 224 224 +7267 ./prep_dataset/ILSVRC2012_val_00004978.bin 224 224 +7268 ./prep_dataset/ILSVRC2012_val_00003184.bin 224 224 +7269 ./prep_dataset/ILSVRC2012_val_00023020.bin 224 224 +7270 ./prep_dataset/ILSVRC2012_val_00038335.bin 224 224 +7271 ./prep_dataset/ILSVRC2012_val_00044869.bin 224 224 +7272 ./prep_dataset/ILSVRC2012_val_00038232.bin 224 224 +7273 ./prep_dataset/ILSVRC2012_val_00045802.bin 224 224 +7274 ./prep_dataset/ILSVRC2012_val_00037446.bin 224 224 +7275 ./prep_dataset/ILSVRC2012_val_00025418.bin 224 224 +7276 ./prep_dataset/ILSVRC2012_val_00018148.bin 224 224 +7277 ./prep_dataset/ILSVRC2012_val_00030752.bin 224 224 +7278 ./prep_dataset/ILSVRC2012_val_00007115.bin 224 224 +7279 ./prep_dataset/ILSVRC2012_val_00008473.bin 224 224 +7280 ./prep_dataset/ILSVRC2012_val_00002964.bin 224 224 +7281 ./prep_dataset/ILSVRC2012_val_00006507.bin 224 224 +7282 ./prep_dataset/ILSVRC2012_val_00008135.bin 224 224 +7283 ./prep_dataset/ILSVRC2012_val_00003087.bin 224 224 +7284 ./prep_dataset/ILSVRC2012_val_00049885.bin 224 224 +7285 ./prep_dataset/ILSVRC2012_val_00012635.bin 224 224 +7286 ./prep_dataset/ILSVRC2012_val_00029593.bin 224 224 +7287 ./prep_dataset/ILSVRC2012_val_00006328.bin 224 224 +7288 ./prep_dataset/ILSVRC2012_val_00032631.bin 224 224 +7289 ./prep_dataset/ILSVRC2012_val_00049114.bin 224 224 +7290 ./prep_dataset/ILSVRC2012_val_00023330.bin 224 224 +7291 ./prep_dataset/ILSVRC2012_val_00007841.bin 224 224 +7292 ./prep_dataset/ILSVRC2012_val_00020358.bin 224 224 +7293 ./prep_dataset/ILSVRC2012_val_00045454.bin 224 224 +7294 ./prep_dataset/ILSVRC2012_val_00042699.bin 224 224 +7295 ./prep_dataset/ILSVRC2012_val_00007866.bin 224 224 +7296 ./prep_dataset/ILSVRC2012_val_00009033.bin 224 224 +7297 ./prep_dataset/ILSVRC2012_val_00034905.bin 224 224 +7298 ./prep_dataset/ILSVRC2012_val_00046659.bin 224 224 +7299 ./prep_dataset/ILSVRC2012_val_00043522.bin 224 224 +7300 ./prep_dataset/ILSVRC2012_val_00000464.bin 224 224 +7301 ./prep_dataset/ILSVRC2012_val_00013737.bin 224 224 +7302 ./prep_dataset/ILSVRC2012_val_00032728.bin 224 224 +7303 ./prep_dataset/ILSVRC2012_val_00043177.bin 224 224 +7304 ./prep_dataset/ILSVRC2012_val_00010199.bin 224 224 +7305 ./prep_dataset/ILSVRC2012_val_00031228.bin 224 224 +7306 ./prep_dataset/ILSVRC2012_val_00020599.bin 224 224 +7307 ./prep_dataset/ILSVRC2012_val_00049795.bin 224 224 +7308 ./prep_dataset/ILSVRC2012_val_00014587.bin 224 224 +7309 ./prep_dataset/ILSVRC2012_val_00031561.bin 224 224 +7310 ./prep_dataset/ILSVRC2012_val_00031480.bin 224 224 +7311 ./prep_dataset/ILSVRC2012_val_00026016.bin 224 224 +7312 ./prep_dataset/ILSVRC2012_val_00037423.bin 224 224 +7313 ./prep_dataset/ILSVRC2012_val_00026426.bin 224 224 +7314 ./prep_dataset/ILSVRC2012_val_00005401.bin 224 224 +7315 ./prep_dataset/ILSVRC2012_val_00026832.bin 224 224 +7316 ./prep_dataset/ILSVRC2012_val_00039289.bin 224 224 +7317 ./prep_dataset/ILSVRC2012_val_00044223.bin 224 224 +7318 ./prep_dataset/ILSVRC2012_val_00013516.bin 224 224 +7319 ./prep_dataset/ILSVRC2012_val_00012444.bin 224 224 +7320 ./prep_dataset/ILSVRC2012_val_00048375.bin 224 224 +7321 ./prep_dataset/ILSVRC2012_val_00009398.bin 224 224 +7322 ./prep_dataset/ILSVRC2012_val_00021286.bin 224 224 +7323 ./prep_dataset/ILSVRC2012_val_00049306.bin 224 224 +7324 ./prep_dataset/ILSVRC2012_val_00033259.bin 224 224 +7325 ./prep_dataset/ILSVRC2012_val_00039158.bin 224 224 +7326 ./prep_dataset/ILSVRC2012_val_00033753.bin 224 224 +7327 ./prep_dataset/ILSVRC2012_val_00001636.bin 224 224 +7328 ./prep_dataset/ILSVRC2012_val_00041412.bin 224 224 +7329 ./prep_dataset/ILSVRC2012_val_00011927.bin 224 224 +7330 ./prep_dataset/ILSVRC2012_val_00039169.bin 224 224 +7331 ./prep_dataset/ILSVRC2012_val_00039401.bin 224 224 +7332 ./prep_dataset/ILSVRC2012_val_00004860.bin 224 224 +7333 ./prep_dataset/ILSVRC2012_val_00032002.bin 224 224 +7334 ./prep_dataset/ILSVRC2012_val_00049163.bin 224 224 +7335 ./prep_dataset/ILSVRC2012_val_00001864.bin 224 224 +7336 ./prep_dataset/ILSVRC2012_val_00018755.bin 224 224 +7337 ./prep_dataset/ILSVRC2012_val_00048170.bin 224 224 +7338 ./prep_dataset/ILSVRC2012_val_00044493.bin 224 224 +7339 ./prep_dataset/ILSVRC2012_val_00022992.bin 224 224 +7340 ./prep_dataset/ILSVRC2012_val_00015021.bin 224 224 +7341 ./prep_dataset/ILSVRC2012_val_00005762.bin 224 224 +7342 ./prep_dataset/ILSVRC2012_val_00047357.bin 224 224 +7343 ./prep_dataset/ILSVRC2012_val_00020874.bin 224 224 +7344 ./prep_dataset/ILSVRC2012_val_00029584.bin 224 224 +7345 ./prep_dataset/ILSVRC2012_val_00015454.bin 224 224 +7346 ./prep_dataset/ILSVRC2012_val_00040725.bin 224 224 +7347 ./prep_dataset/ILSVRC2012_val_00017012.bin 224 224 +7348 ./prep_dataset/ILSVRC2012_val_00049439.bin 224 224 +7349 ./prep_dataset/ILSVRC2012_val_00039098.bin 224 224 +7350 ./prep_dataset/ILSVRC2012_val_00022880.bin 224 224 +7351 ./prep_dataset/ILSVRC2012_val_00001380.bin 224 224 +7352 ./prep_dataset/ILSVRC2012_val_00026436.bin 224 224 +7353 ./prep_dataset/ILSVRC2012_val_00017662.bin 224 224 +7354 ./prep_dataset/ILSVRC2012_val_00003470.bin 224 224 +7355 ./prep_dataset/ILSVRC2012_val_00003263.bin 224 224 +7356 ./prep_dataset/ILSVRC2012_val_00020900.bin 224 224 +7357 ./prep_dataset/ILSVRC2012_val_00035645.bin 224 224 +7358 ./prep_dataset/ILSVRC2012_val_00002596.bin 224 224 +7359 ./prep_dataset/ILSVRC2012_val_00012740.bin 224 224 +7360 ./prep_dataset/ILSVRC2012_val_00037526.bin 224 224 +7361 ./prep_dataset/ILSVRC2012_val_00009019.bin 224 224 +7362 ./prep_dataset/ILSVRC2012_val_00031418.bin 224 224 +7363 ./prep_dataset/ILSVRC2012_val_00002391.bin 224 224 +7364 ./prep_dataset/ILSVRC2012_val_00039668.bin 224 224 +7365 ./prep_dataset/ILSVRC2012_val_00033087.bin 224 224 +7366 ./prep_dataset/ILSVRC2012_val_00008718.bin 224 224 +7367 ./prep_dataset/ILSVRC2012_val_00002646.bin 224 224 +7368 ./prep_dataset/ILSVRC2012_val_00007032.bin 224 224 +7369 ./prep_dataset/ILSVRC2012_val_00002759.bin 224 224 +7370 ./prep_dataset/ILSVRC2012_val_00011718.bin 224 224 +7371 ./prep_dataset/ILSVRC2012_val_00048138.bin 224 224 +7372 ./prep_dataset/ILSVRC2012_val_00016606.bin 224 224 +7373 ./prep_dataset/ILSVRC2012_val_00018441.bin 224 224 +7374 ./prep_dataset/ILSVRC2012_val_00044991.bin 224 224 +7375 ./prep_dataset/ILSVRC2012_val_00000142.bin 224 224 +7376 ./prep_dataset/ILSVRC2012_val_00027400.bin 224 224 +7377 ./prep_dataset/ILSVRC2012_val_00007752.bin 224 224 +7378 ./prep_dataset/ILSVRC2012_val_00022863.bin 224 224 +7379 ./prep_dataset/ILSVRC2012_val_00020852.bin 224 224 +7380 ./prep_dataset/ILSVRC2012_val_00034061.bin 224 224 +7381 ./prep_dataset/ILSVRC2012_val_00037370.bin 224 224 +7382 ./prep_dataset/ILSVRC2012_val_00014634.bin 224 224 +7383 ./prep_dataset/ILSVRC2012_val_00048968.bin 224 224 +7384 ./prep_dataset/ILSVRC2012_val_00030247.bin 224 224 +7385 ./prep_dataset/ILSVRC2012_val_00036475.bin 224 224 +7386 ./prep_dataset/ILSVRC2012_val_00047333.bin 224 224 +7387 ./prep_dataset/ILSVRC2012_val_00004168.bin 224 224 +7388 ./prep_dataset/ILSVRC2012_val_00026664.bin 224 224 +7389 ./prep_dataset/ILSVRC2012_val_00024203.bin 224 224 +7390 ./prep_dataset/ILSVRC2012_val_00018215.bin 224 224 +7391 ./prep_dataset/ILSVRC2012_val_00005952.bin 224 224 +7392 ./prep_dataset/ILSVRC2012_val_00028575.bin 224 224 +7393 ./prep_dataset/ILSVRC2012_val_00004153.bin 224 224 +7394 ./prep_dataset/ILSVRC2012_val_00030789.bin 224 224 +7395 ./prep_dataset/ILSVRC2012_val_00027764.bin 224 224 +7396 ./prep_dataset/ILSVRC2012_val_00025413.bin 224 224 +7397 ./prep_dataset/ILSVRC2012_val_00025655.bin 224 224 +7398 ./prep_dataset/ILSVRC2012_val_00035916.bin 224 224 +7399 ./prep_dataset/ILSVRC2012_val_00007910.bin 224 224 +7400 ./prep_dataset/ILSVRC2012_val_00021106.bin 224 224 +7401 ./prep_dataset/ILSVRC2012_val_00013311.bin 224 224 +7402 ./prep_dataset/ILSVRC2012_val_00016973.bin 224 224 +7403 ./prep_dataset/ILSVRC2012_val_00043981.bin 224 224 +7404 ./prep_dataset/ILSVRC2012_val_00027452.bin 224 224 +7405 ./prep_dataset/ILSVRC2012_val_00028402.bin 224 224 +7406 ./prep_dataset/ILSVRC2012_val_00024139.bin 224 224 +7407 ./prep_dataset/ILSVRC2012_val_00007459.bin 224 224 +7408 ./prep_dataset/ILSVRC2012_val_00012146.bin 224 224 +7409 ./prep_dataset/ILSVRC2012_val_00005927.bin 224 224 +7410 ./prep_dataset/ILSVRC2012_val_00017743.bin 224 224 +7411 ./prep_dataset/ILSVRC2012_val_00012094.bin 224 224 +7412 ./prep_dataset/ILSVRC2012_val_00030671.bin 224 224 +7413 ./prep_dataset/ILSVRC2012_val_00015108.bin 224 224 +7414 ./prep_dataset/ILSVRC2012_val_00029052.bin 224 224 +7415 ./prep_dataset/ILSVRC2012_val_00034273.bin 224 224 +7416 ./prep_dataset/ILSVRC2012_val_00018162.bin 224 224 +7417 ./prep_dataset/ILSVRC2012_val_00024130.bin 224 224 +7418 ./prep_dataset/ILSVRC2012_val_00031831.bin 224 224 +7419 ./prep_dataset/ILSVRC2012_val_00030146.bin 224 224 +7420 ./prep_dataset/ILSVRC2012_val_00004419.bin 224 224 +7421 ./prep_dataset/ILSVRC2012_val_00027555.bin 224 224 +7422 ./prep_dataset/ILSVRC2012_val_00009069.bin 224 224 +7423 ./prep_dataset/ILSVRC2012_val_00012060.bin 224 224 +7424 ./prep_dataset/ILSVRC2012_val_00041507.bin 224 224 +7425 ./prep_dataset/ILSVRC2012_val_00033627.bin 224 224 +7426 ./prep_dataset/ILSVRC2012_val_00036972.bin 224 224 +7427 ./prep_dataset/ILSVRC2012_val_00038906.bin 224 224 +7428 ./prep_dataset/ILSVRC2012_val_00009306.bin 224 224 +7429 ./prep_dataset/ILSVRC2012_val_00028597.bin 224 224 +7430 ./prep_dataset/ILSVRC2012_val_00022952.bin 224 224 +7431 ./prep_dataset/ILSVRC2012_val_00041644.bin 224 224 +7432 ./prep_dataset/ILSVRC2012_val_00003958.bin 224 224 +7433 ./prep_dataset/ILSVRC2012_val_00043510.bin 224 224 +7434 ./prep_dataset/ILSVRC2012_val_00014895.bin 224 224 +7435 ./prep_dataset/ILSVRC2012_val_00027598.bin 224 224 +7436 ./prep_dataset/ILSVRC2012_val_00015660.bin 224 224 +7437 ./prep_dataset/ILSVRC2012_val_00006579.bin 224 224 +7438 ./prep_dataset/ILSVRC2012_val_00039670.bin 224 224 +7439 ./prep_dataset/ILSVRC2012_val_00037921.bin 224 224 +7440 ./prep_dataset/ILSVRC2012_val_00027364.bin 224 224 +7441 ./prep_dataset/ILSVRC2012_val_00043254.bin 224 224 +7442 ./prep_dataset/ILSVRC2012_val_00044632.bin 224 224 +7443 ./prep_dataset/ILSVRC2012_val_00041286.bin 224 224 +7444 ./prep_dataset/ILSVRC2012_val_00012920.bin 224 224 +7445 ./prep_dataset/ILSVRC2012_val_00003340.bin 224 224 +7446 ./prep_dataset/ILSVRC2012_val_00016170.bin 224 224 +7447 ./prep_dataset/ILSVRC2012_val_00048008.bin 224 224 +7448 ./prep_dataset/ILSVRC2012_val_00030722.bin 224 224 +7449 ./prep_dataset/ILSVRC2012_val_00030139.bin 224 224 +7450 ./prep_dataset/ILSVRC2012_val_00017635.bin 224 224 +7451 ./prep_dataset/ILSVRC2012_val_00049892.bin 224 224 +7452 ./prep_dataset/ILSVRC2012_val_00027512.bin 224 224 +7453 ./prep_dataset/ILSVRC2012_val_00036915.bin 224 224 +7454 ./prep_dataset/ILSVRC2012_val_00032228.bin 224 224 +7455 ./prep_dataset/ILSVRC2012_val_00038556.bin 224 224 +7456 ./prep_dataset/ILSVRC2012_val_00023002.bin 224 224 +7457 ./prep_dataset/ILSVRC2012_val_00047702.bin 224 224 +7458 ./prep_dataset/ILSVRC2012_val_00024676.bin 224 224 +7459 ./prep_dataset/ILSVRC2012_val_00012338.bin 224 224 +7460 ./prep_dataset/ILSVRC2012_val_00032112.bin 224 224 +7461 ./prep_dataset/ILSVRC2012_val_00043550.bin 224 224 +7462 ./prep_dataset/ILSVRC2012_val_00031855.bin 224 224 +7463 ./prep_dataset/ILSVRC2012_val_00021803.bin 224 224 +7464 ./prep_dataset/ILSVRC2012_val_00012904.bin 224 224 +7465 ./prep_dataset/ILSVRC2012_val_00040946.bin 224 224 +7466 ./prep_dataset/ILSVRC2012_val_00040077.bin 224 224 +7467 ./prep_dataset/ILSVRC2012_val_00017149.bin 224 224 +7468 ./prep_dataset/ILSVRC2012_val_00016293.bin 224 224 +7469 ./prep_dataset/ILSVRC2012_val_00043037.bin 224 224 +7470 ./prep_dataset/ILSVRC2012_val_00025337.bin 224 224 +7471 ./prep_dataset/ILSVRC2012_val_00001286.bin 224 224 +7472 ./prep_dataset/ILSVRC2012_val_00039994.bin 224 224 +7473 ./prep_dataset/ILSVRC2012_val_00028493.bin 224 224 +7474 ./prep_dataset/ILSVRC2012_val_00036689.bin 224 224 +7475 ./prep_dataset/ILSVRC2012_val_00014112.bin 224 224 +7476 ./prep_dataset/ILSVRC2012_val_00039715.bin 224 224 +7477 ./prep_dataset/ILSVRC2012_val_00049584.bin 224 224 +7478 ./prep_dataset/ILSVRC2012_val_00027098.bin 224 224 +7479 ./prep_dataset/ILSVRC2012_val_00022638.bin 224 224 +7480 ./prep_dataset/ILSVRC2012_val_00022794.bin 224 224 +7481 ./prep_dataset/ILSVRC2012_val_00029037.bin 224 224 +7482 ./prep_dataset/ILSVRC2012_val_00003691.bin 224 224 +7483 ./prep_dataset/ILSVRC2012_val_00012327.bin 224 224 +7484 ./prep_dataset/ILSVRC2012_val_00031587.bin 224 224 +7485 ./prep_dataset/ILSVRC2012_val_00023245.bin 224 224 +7486 ./prep_dataset/ILSVRC2012_val_00032333.bin 224 224 +7487 ./prep_dataset/ILSVRC2012_val_00012632.bin 224 224 +7488 ./prep_dataset/ILSVRC2012_val_00021200.bin 224 224 +7489 ./prep_dataset/ILSVRC2012_val_00013453.bin 224 224 +7490 ./prep_dataset/ILSVRC2012_val_00049414.bin 224 224 +7491 ./prep_dataset/ILSVRC2012_val_00022177.bin 224 224 +7492 ./prep_dataset/ILSVRC2012_val_00049970.bin 224 224 +7493 ./prep_dataset/ILSVRC2012_val_00025968.bin 224 224 +7494 ./prep_dataset/ILSVRC2012_val_00002284.bin 224 224 +7495 ./prep_dataset/ILSVRC2012_val_00030019.bin 224 224 +7496 ./prep_dataset/ILSVRC2012_val_00036901.bin 224 224 +7497 ./prep_dataset/ILSVRC2012_val_00045187.bin 224 224 +7498 ./prep_dataset/ILSVRC2012_val_00042894.bin 224 224 +7499 ./prep_dataset/ILSVRC2012_val_00036050.bin 224 224 +7500 ./prep_dataset/ILSVRC2012_val_00036487.bin 224 224 +7501 ./prep_dataset/ILSVRC2012_val_00008158.bin 224 224 +7502 ./prep_dataset/ILSVRC2012_val_00028808.bin 224 224 +7503 ./prep_dataset/ILSVRC2012_val_00037778.bin 224 224 +7504 ./prep_dataset/ILSVRC2012_val_00039622.bin 224 224 +7505 ./prep_dataset/ILSVRC2012_val_00046218.bin 224 224 +7506 ./prep_dataset/ILSVRC2012_val_00005862.bin 224 224 +7507 ./prep_dataset/ILSVRC2012_val_00038030.bin 224 224 +7508 ./prep_dataset/ILSVRC2012_val_00019370.bin 224 224 +7509 ./prep_dataset/ILSVRC2012_val_00023448.bin 224 224 +7510 ./prep_dataset/ILSVRC2012_val_00019705.bin 224 224 +7511 ./prep_dataset/ILSVRC2012_val_00035920.bin 224 224 +7512 ./prep_dataset/ILSVRC2012_val_00047074.bin 224 224 +7513 ./prep_dataset/ILSVRC2012_val_00036415.bin 224 224 +7514 ./prep_dataset/ILSVRC2012_val_00035934.bin 224 224 +7515 ./prep_dataset/ILSVRC2012_val_00015917.bin 224 224 +7516 ./prep_dataset/ILSVRC2012_val_00005512.bin 224 224 +7517 ./prep_dataset/ILSVRC2012_val_00027960.bin 224 224 +7518 ./prep_dataset/ILSVRC2012_val_00029042.bin 224 224 +7519 ./prep_dataset/ILSVRC2012_val_00004611.bin 224 224 +7520 ./prep_dataset/ILSVRC2012_val_00022533.bin 224 224 +7521 ./prep_dataset/ILSVRC2012_val_00005044.bin 224 224 +7522 ./prep_dataset/ILSVRC2012_val_00037899.bin 224 224 +7523 ./prep_dataset/ILSVRC2012_val_00043475.bin 224 224 +7524 ./prep_dataset/ILSVRC2012_val_00010507.bin 224 224 +7525 ./prep_dataset/ILSVRC2012_val_00023768.bin 224 224 +7526 ./prep_dataset/ILSVRC2012_val_00017815.bin 224 224 +7527 ./prep_dataset/ILSVRC2012_val_00018611.bin 224 224 +7528 ./prep_dataset/ILSVRC2012_val_00037688.bin 224 224 +7529 ./prep_dataset/ILSVRC2012_val_00020886.bin 224 224 +7530 ./prep_dataset/ILSVRC2012_val_00034944.bin 224 224 +7531 ./prep_dataset/ILSVRC2012_val_00017478.bin 224 224 +7532 ./prep_dataset/ILSVRC2012_val_00048060.bin 224 224 +7533 ./prep_dataset/ILSVRC2012_val_00038491.bin 224 224 +7534 ./prep_dataset/ILSVRC2012_val_00025522.bin 224 224 +7535 ./prep_dataset/ILSVRC2012_val_00039940.bin 224 224 +7536 ./prep_dataset/ILSVRC2012_val_00014924.bin 224 224 +7537 ./prep_dataset/ILSVRC2012_val_00023799.bin 224 224 +7538 ./prep_dataset/ILSVRC2012_val_00024796.bin 224 224 +7539 ./prep_dataset/ILSVRC2012_val_00023821.bin 224 224 +7540 ./prep_dataset/ILSVRC2012_val_00016669.bin 224 224 +7541 ./prep_dataset/ILSVRC2012_val_00010102.bin 224 224 +7542 ./prep_dataset/ILSVRC2012_val_00046178.bin 224 224 +7543 ./prep_dataset/ILSVRC2012_val_00028629.bin 224 224 +7544 ./prep_dataset/ILSVRC2012_val_00013312.bin 224 224 +7545 ./prep_dataset/ILSVRC2012_val_00021008.bin 224 224 +7546 ./prep_dataset/ILSVRC2012_val_00004306.bin 224 224 +7547 ./prep_dataset/ILSVRC2012_val_00017514.bin 224 224 +7548 ./prep_dataset/ILSVRC2012_val_00014229.bin 224 224 +7549 ./prep_dataset/ILSVRC2012_val_00036860.bin 224 224 +7550 ./prep_dataset/ILSVRC2012_val_00005918.bin 224 224 +7551 ./prep_dataset/ILSVRC2012_val_00022317.bin 224 224 +7552 ./prep_dataset/ILSVRC2012_val_00048116.bin 224 224 +7553 ./prep_dataset/ILSVRC2012_val_00024563.bin 224 224 +7554 ./prep_dataset/ILSVRC2012_val_00041142.bin 224 224 +7555 ./prep_dataset/ILSVRC2012_val_00014015.bin 224 224 +7556 ./prep_dataset/ILSVRC2012_val_00037372.bin 224 224 +7557 ./prep_dataset/ILSVRC2012_val_00011260.bin 224 224 +7558 ./prep_dataset/ILSVRC2012_val_00021283.bin 224 224 +7559 ./prep_dataset/ILSVRC2012_val_00049113.bin 224 224 +7560 ./prep_dataset/ILSVRC2012_val_00032527.bin 224 224 +7561 ./prep_dataset/ILSVRC2012_val_00013564.bin 224 224 +7562 ./prep_dataset/ILSVRC2012_val_00029744.bin 224 224 +7563 ./prep_dataset/ILSVRC2012_val_00034916.bin 224 224 +7564 ./prep_dataset/ILSVRC2012_val_00021372.bin 224 224 +7565 ./prep_dataset/ILSVRC2012_val_00018276.bin 224 224 +7566 ./prep_dataset/ILSVRC2012_val_00040343.bin 224 224 +7567 ./prep_dataset/ILSVRC2012_val_00021076.bin 224 224 +7568 ./prep_dataset/ILSVRC2012_val_00001041.bin 224 224 +7569 ./prep_dataset/ILSVRC2012_val_00010408.bin 224 224 +7570 ./prep_dataset/ILSVRC2012_val_00014586.bin 224 224 +7571 ./prep_dataset/ILSVRC2012_val_00041205.bin 224 224 +7572 ./prep_dataset/ILSVRC2012_val_00048140.bin 224 224 +7573 ./prep_dataset/ILSVRC2012_val_00021775.bin 224 224 +7574 ./prep_dataset/ILSVRC2012_val_00040570.bin 224 224 +7575 ./prep_dataset/ILSVRC2012_val_00036755.bin 224 224 +7576 ./prep_dataset/ILSVRC2012_val_00028694.bin 224 224 +7577 ./prep_dataset/ILSVRC2012_val_00024331.bin 224 224 +7578 ./prep_dataset/ILSVRC2012_val_00004232.bin 224 224 +7579 ./prep_dataset/ILSVRC2012_val_00049469.bin 224 224 +7580 ./prep_dataset/ILSVRC2012_val_00018175.bin 224 224 +7581 ./prep_dataset/ILSVRC2012_val_00019700.bin 224 224 +7582 ./prep_dataset/ILSVRC2012_val_00013126.bin 224 224 +7583 ./prep_dataset/ILSVRC2012_val_00000727.bin 224 224 +7584 ./prep_dataset/ILSVRC2012_val_00018155.bin 224 224 +7585 ./prep_dataset/ILSVRC2012_val_00047210.bin 224 224 +7586 ./prep_dataset/ILSVRC2012_val_00026406.bin 224 224 +7587 ./prep_dataset/ILSVRC2012_val_00035980.bin 224 224 +7588 ./prep_dataset/ILSVRC2012_val_00007679.bin 224 224 +7589 ./prep_dataset/ILSVRC2012_val_00042469.bin 224 224 +7590 ./prep_dataset/ILSVRC2012_val_00046715.bin 224 224 +7591 ./prep_dataset/ILSVRC2012_val_00046895.bin 224 224 +7592 ./prep_dataset/ILSVRC2012_val_00009123.bin 224 224 +7593 ./prep_dataset/ILSVRC2012_val_00023977.bin 224 224 +7594 ./prep_dataset/ILSVRC2012_val_00015194.bin 224 224 +7595 ./prep_dataset/ILSVRC2012_val_00021175.bin 224 224 +7596 ./prep_dataset/ILSVRC2012_val_00003147.bin 224 224 +7597 ./prep_dataset/ILSVRC2012_val_00038304.bin 224 224 +7598 ./prep_dataset/ILSVRC2012_val_00047827.bin 224 224 +7599 ./prep_dataset/ILSVRC2012_val_00021670.bin 224 224 +7600 ./prep_dataset/ILSVRC2012_val_00044016.bin 224 224 +7601 ./prep_dataset/ILSVRC2012_val_00008130.bin 224 224 +7602 ./prep_dataset/ILSVRC2012_val_00024466.bin 224 224 +7603 ./prep_dataset/ILSVRC2012_val_00018096.bin 224 224 +7604 ./prep_dataset/ILSVRC2012_val_00018293.bin 224 224 +7605 ./prep_dataset/ILSVRC2012_val_00005823.bin 224 224 +7606 ./prep_dataset/ILSVRC2012_val_00021023.bin 224 224 +7607 ./prep_dataset/ILSVRC2012_val_00028867.bin 224 224 +7608 ./prep_dataset/ILSVRC2012_val_00046355.bin 224 224 +7609 ./prep_dataset/ILSVRC2012_val_00034496.bin 224 224 +7610 ./prep_dataset/ILSVRC2012_val_00042192.bin 224 224 +7611 ./prep_dataset/ILSVRC2012_val_00036753.bin 224 224 +7612 ./prep_dataset/ILSVRC2012_val_00001266.bin 224 224 +7613 ./prep_dataset/ILSVRC2012_val_00032319.bin 224 224 +7614 ./prep_dataset/ILSVRC2012_val_00048938.bin 224 224 +7615 ./prep_dataset/ILSVRC2012_val_00049417.bin 224 224 +7616 ./prep_dataset/ILSVRC2012_val_00030090.bin 224 224 +7617 ./prep_dataset/ILSVRC2012_val_00017091.bin 224 224 +7618 ./prep_dataset/ILSVRC2012_val_00025345.bin 224 224 +7619 ./prep_dataset/ILSVRC2012_val_00023150.bin 224 224 +7620 ./prep_dataset/ILSVRC2012_val_00001137.bin 224 224 +7621 ./prep_dataset/ILSVRC2012_val_00033302.bin 224 224 +7622 ./prep_dataset/ILSVRC2012_val_00001026.bin 224 224 +7623 ./prep_dataset/ILSVRC2012_val_00016113.bin 224 224 +7624 ./prep_dataset/ILSVRC2012_val_00020394.bin 224 224 +7625 ./prep_dataset/ILSVRC2012_val_00023621.bin 224 224 +7626 ./prep_dataset/ILSVRC2012_val_00020170.bin 224 224 +7627 ./prep_dataset/ILSVRC2012_val_00027363.bin 224 224 +7628 ./prep_dataset/ILSVRC2012_val_00020634.bin 224 224 +7629 ./prep_dataset/ILSVRC2012_val_00016587.bin 224 224 +7630 ./prep_dataset/ILSVRC2012_val_00011616.bin 224 224 +7631 ./prep_dataset/ILSVRC2012_val_00045225.bin 224 224 +7632 ./prep_dataset/ILSVRC2012_val_00011749.bin 224 224 +7633 ./prep_dataset/ILSVRC2012_val_00024666.bin 224 224 +7634 ./prep_dataset/ILSVRC2012_val_00044047.bin 224 224 +7635 ./prep_dataset/ILSVRC2012_val_00027149.bin 224 224 +7636 ./prep_dataset/ILSVRC2012_val_00013783.bin 224 224 +7637 ./prep_dataset/ILSVRC2012_val_00043881.bin 224 224 +7638 ./prep_dataset/ILSVRC2012_val_00007623.bin 224 224 +7639 ./prep_dataset/ILSVRC2012_val_00012072.bin 224 224 +7640 ./prep_dataset/ILSVRC2012_val_00035135.bin 224 224 +7641 ./prep_dataset/ILSVRC2012_val_00008946.bin 224 224 +7642 ./prep_dataset/ILSVRC2012_val_00039589.bin 224 224 +7643 ./prep_dataset/ILSVRC2012_val_00009504.bin 224 224 +7644 ./prep_dataset/ILSVRC2012_val_00004060.bin 224 224 +7645 ./prep_dataset/ILSVRC2012_val_00018154.bin 224 224 +7646 ./prep_dataset/ILSVRC2012_val_00005978.bin 224 224 +7647 ./prep_dataset/ILSVRC2012_val_00009726.bin 224 224 +7648 ./prep_dataset/ILSVRC2012_val_00026030.bin 224 224 +7649 ./prep_dataset/ILSVRC2012_val_00003038.bin 224 224 +7650 ./prep_dataset/ILSVRC2012_val_00033701.bin 224 224 +7651 ./prep_dataset/ILSVRC2012_val_00024300.bin 224 224 +7652 ./prep_dataset/ILSVRC2012_val_00009539.bin 224 224 +7653 ./prep_dataset/ILSVRC2012_val_00049515.bin 224 224 +7654 ./prep_dataset/ILSVRC2012_val_00025130.bin 224 224 +7655 ./prep_dataset/ILSVRC2012_val_00020483.bin 224 224 +7656 ./prep_dataset/ILSVRC2012_val_00006166.bin 224 224 +7657 ./prep_dataset/ILSVRC2012_val_00024645.bin 224 224 +7658 ./prep_dataset/ILSVRC2012_val_00047963.bin 224 224 +7659 ./prep_dataset/ILSVRC2012_val_00029755.bin 224 224 +7660 ./prep_dataset/ILSVRC2012_val_00047004.bin 224 224 +7661 ./prep_dataset/ILSVRC2012_val_00029430.bin 224 224 +7662 ./prep_dataset/ILSVRC2012_val_00033685.bin 224 224 +7663 ./prep_dataset/ILSVRC2012_val_00048889.bin 224 224 +7664 ./prep_dataset/ILSVRC2012_val_00000799.bin 224 224 +7665 ./prep_dataset/ILSVRC2012_val_00026133.bin 224 224 +7666 ./prep_dataset/ILSVRC2012_val_00000573.bin 224 224 +7667 ./prep_dataset/ILSVRC2012_val_00021385.bin 224 224 +7668 ./prep_dataset/ILSVRC2012_val_00022225.bin 224 224 +7669 ./prep_dataset/ILSVRC2012_val_00044467.bin 224 224 +7670 ./prep_dataset/ILSVRC2012_val_00029994.bin 224 224 +7671 ./prep_dataset/ILSVRC2012_val_00004251.bin 224 224 +7672 ./prep_dataset/ILSVRC2012_val_00029399.bin 224 224 +7673 ./prep_dataset/ILSVRC2012_val_00025982.bin 224 224 +7674 ./prep_dataset/ILSVRC2012_val_00008944.bin 224 224 +7675 ./prep_dataset/ILSVRC2012_val_00005747.bin 224 224 +7676 ./prep_dataset/ILSVRC2012_val_00048371.bin 224 224 +7677 ./prep_dataset/ILSVRC2012_val_00043788.bin 224 224 +7678 ./prep_dataset/ILSVRC2012_val_00044256.bin 224 224 +7679 ./prep_dataset/ILSVRC2012_val_00036301.bin 224 224 +7680 ./prep_dataset/ILSVRC2012_val_00018022.bin 224 224 +7681 ./prep_dataset/ILSVRC2012_val_00039261.bin 224 224 +7682 ./prep_dataset/ILSVRC2012_val_00022943.bin 224 224 +7683 ./prep_dataset/ILSVRC2012_val_00015192.bin 224 224 +7684 ./prep_dataset/ILSVRC2012_val_00022589.bin 224 224 +7685 ./prep_dataset/ILSVRC2012_val_00021873.bin 224 224 +7686 ./prep_dataset/ILSVRC2012_val_00038211.bin 224 224 +7687 ./prep_dataset/ILSVRC2012_val_00000244.bin 224 224 +7688 ./prep_dataset/ILSVRC2012_val_00034078.bin 224 224 +7689 ./prep_dataset/ILSVRC2012_val_00014326.bin 224 224 +7690 ./prep_dataset/ILSVRC2012_val_00032740.bin 224 224 +7691 ./prep_dataset/ILSVRC2012_val_00024353.bin 224 224 +7692 ./prep_dataset/ILSVRC2012_val_00015700.bin 224 224 +7693 ./prep_dataset/ILSVRC2012_val_00033954.bin 224 224 +7694 ./prep_dataset/ILSVRC2012_val_00003514.bin 224 224 +7695 ./prep_dataset/ILSVRC2012_val_00027653.bin 224 224 +7696 ./prep_dataset/ILSVRC2012_val_00029462.bin 224 224 +7697 ./prep_dataset/ILSVRC2012_val_00012137.bin 224 224 +7698 ./prep_dataset/ILSVRC2012_val_00048831.bin 224 224 +7699 ./prep_dataset/ILSVRC2012_val_00027176.bin 224 224 +7700 ./prep_dataset/ILSVRC2012_val_00035467.bin 224 224 +7701 ./prep_dataset/ILSVRC2012_val_00010071.bin 224 224 +7702 ./prep_dataset/ILSVRC2012_val_00033878.bin 224 224 +7703 ./prep_dataset/ILSVRC2012_val_00007286.bin 224 224 +7704 ./prep_dataset/ILSVRC2012_val_00044928.bin 224 224 +7705 ./prep_dataset/ILSVRC2012_val_00046217.bin 224 224 +7706 ./prep_dataset/ILSVRC2012_val_00012103.bin 224 224 +7707 ./prep_dataset/ILSVRC2012_val_00029966.bin 224 224 +7708 ./prep_dataset/ILSVRC2012_val_00007469.bin 224 224 +7709 ./prep_dataset/ILSVRC2012_val_00018576.bin 224 224 +7710 ./prep_dataset/ILSVRC2012_val_00002302.bin 224 224 +7711 ./prep_dataset/ILSVRC2012_val_00012546.bin 224 224 +7712 ./prep_dataset/ILSVRC2012_val_00013315.bin 224 224 +7713 ./prep_dataset/ILSVRC2012_val_00006329.bin 224 224 +7714 ./prep_dataset/ILSVRC2012_val_00019381.bin 224 224 +7715 ./prep_dataset/ILSVRC2012_val_00009296.bin 224 224 +7716 ./prep_dataset/ILSVRC2012_val_00005848.bin 224 224 +7717 ./prep_dataset/ILSVRC2012_val_00013487.bin 224 224 +7718 ./prep_dataset/ILSVRC2012_val_00028387.bin 224 224 +7719 ./prep_dataset/ILSVRC2012_val_00003029.bin 224 224 +7720 ./prep_dataset/ILSVRC2012_val_00031937.bin 224 224 +7721 ./prep_dataset/ILSVRC2012_val_00046314.bin 224 224 +7722 ./prep_dataset/ILSVRC2012_val_00032914.bin 224 224 +7723 ./prep_dataset/ILSVRC2012_val_00004557.bin 224 224 +7724 ./prep_dataset/ILSVRC2012_val_00029913.bin 224 224 +7725 ./prep_dataset/ILSVRC2012_val_00005084.bin 224 224 +7726 ./prep_dataset/ILSVRC2012_val_00041199.bin 224 224 +7727 ./prep_dataset/ILSVRC2012_val_00043422.bin 224 224 +7728 ./prep_dataset/ILSVRC2012_val_00014992.bin 224 224 +7729 ./prep_dataset/ILSVRC2012_val_00023435.bin 224 224 +7730 ./prep_dataset/ILSVRC2012_val_00045407.bin 224 224 +7731 ./prep_dataset/ILSVRC2012_val_00009181.bin 224 224 +7732 ./prep_dataset/ILSVRC2012_val_00019139.bin 224 224 +7733 ./prep_dataset/ILSVRC2012_val_00049908.bin 224 224 +7734 ./prep_dataset/ILSVRC2012_val_00011889.bin 224 224 +7735 ./prep_dataset/ILSVRC2012_val_00019263.bin 224 224 +7736 ./prep_dataset/ILSVRC2012_val_00017926.bin 224 224 +7737 ./prep_dataset/ILSVRC2012_val_00002707.bin 224 224 +7738 ./prep_dataset/ILSVRC2012_val_00003168.bin 224 224 +7739 ./prep_dataset/ILSVRC2012_val_00000037.bin 224 224 +7740 ./prep_dataset/ILSVRC2012_val_00025367.bin 224 224 +7741 ./prep_dataset/ILSVRC2012_val_00024577.bin 224 224 +7742 ./prep_dataset/ILSVRC2012_val_00045160.bin 224 224 +7743 ./prep_dataset/ILSVRC2012_val_00045262.bin 224 224 +7744 ./prep_dataset/ILSVRC2012_val_00028396.bin 224 224 +7745 ./prep_dataset/ILSVRC2012_val_00023675.bin 224 224 +7746 ./prep_dataset/ILSVRC2012_val_00047222.bin 224 224 +7747 ./prep_dataset/ILSVRC2012_val_00011096.bin 224 224 +7748 ./prep_dataset/ILSVRC2012_val_00027668.bin 224 224 +7749 ./prep_dataset/ILSVRC2012_val_00003510.bin 224 224 +7750 ./prep_dataset/ILSVRC2012_val_00029539.bin 224 224 +7751 ./prep_dataset/ILSVRC2012_val_00022678.bin 224 224 +7752 ./prep_dataset/ILSVRC2012_val_00001205.bin 224 224 +7753 ./prep_dataset/ILSVRC2012_val_00029295.bin 224 224 +7754 ./prep_dataset/ILSVRC2012_val_00033004.bin 224 224 +7755 ./prep_dataset/ILSVRC2012_val_00019575.bin 224 224 +7756 ./prep_dataset/ILSVRC2012_val_00044855.bin 224 224 +7757 ./prep_dataset/ILSVRC2012_val_00032981.bin 224 224 +7758 ./prep_dataset/ILSVRC2012_val_00009416.bin 224 224 +7759 ./prep_dataset/ILSVRC2012_val_00026076.bin 224 224 +7760 ./prep_dataset/ILSVRC2012_val_00048450.bin 224 224 +7761 ./prep_dataset/ILSVRC2012_val_00040732.bin 224 224 +7762 ./prep_dataset/ILSVRC2012_val_00015066.bin 224 224 +7763 ./prep_dataset/ILSVRC2012_val_00032991.bin 224 224 +7764 ./prep_dataset/ILSVRC2012_val_00000236.bin 224 224 +7765 ./prep_dataset/ILSVRC2012_val_00000446.bin 224 224 +7766 ./prep_dataset/ILSVRC2012_val_00004569.bin 224 224 +7767 ./prep_dataset/ILSVRC2012_val_00045498.bin 224 224 +7768 ./prep_dataset/ILSVRC2012_val_00045903.bin 224 224 +7769 ./prep_dataset/ILSVRC2012_val_00008647.bin 224 224 +7770 ./prep_dataset/ILSVRC2012_val_00036057.bin 224 224 +7771 ./prep_dataset/ILSVRC2012_val_00048725.bin 224 224 +7772 ./prep_dataset/ILSVRC2012_val_00010426.bin 224 224 +7773 ./prep_dataset/ILSVRC2012_val_00022251.bin 224 224 +7774 ./prep_dataset/ILSVRC2012_val_00010769.bin 224 224 +7775 ./prep_dataset/ILSVRC2012_val_00029108.bin 224 224 +7776 ./prep_dataset/ILSVRC2012_val_00036435.bin 224 224 +7777 ./prep_dataset/ILSVRC2012_val_00025406.bin 224 224 +7778 ./prep_dataset/ILSVRC2012_val_00012340.bin 224 224 +7779 ./prep_dataset/ILSVRC2012_val_00048942.bin 224 224 +7780 ./prep_dataset/ILSVRC2012_val_00024147.bin 224 224 +7781 ./prep_dataset/ILSVRC2012_val_00012919.bin 224 224 +7782 ./prep_dataset/ILSVRC2012_val_00033963.bin 224 224 +7783 ./prep_dataset/ILSVRC2012_val_00042975.bin 224 224 +7784 ./prep_dataset/ILSVRC2012_val_00042739.bin 224 224 +7785 ./prep_dataset/ILSVRC2012_val_00041243.bin 224 224 +7786 ./prep_dataset/ILSVRC2012_val_00002254.bin 224 224 +7787 ./prep_dataset/ILSVRC2012_val_00028839.bin 224 224 +7788 ./prep_dataset/ILSVRC2012_val_00031134.bin 224 224 +7789 ./prep_dataset/ILSVRC2012_val_00003341.bin 224 224 +7790 ./prep_dataset/ILSVRC2012_val_00044286.bin 224 224 +7791 ./prep_dataset/ILSVRC2012_val_00048733.bin 224 224 +7792 ./prep_dataset/ILSVRC2012_val_00042032.bin 224 224 +7793 ./prep_dataset/ILSVRC2012_val_00009138.bin 224 224 +7794 ./prep_dataset/ILSVRC2012_val_00039056.bin 224 224 +7795 ./prep_dataset/ILSVRC2012_val_00026551.bin 224 224 +7796 ./prep_dataset/ILSVRC2012_val_00006761.bin 224 224 +7797 ./prep_dataset/ILSVRC2012_val_00007289.bin 224 224 +7798 ./prep_dataset/ILSVRC2012_val_00016350.bin 224 224 +7799 ./prep_dataset/ILSVRC2012_val_00040719.bin 224 224 +7800 ./prep_dataset/ILSVRC2012_val_00032020.bin 224 224 +7801 ./prep_dataset/ILSVRC2012_val_00031505.bin 224 224 +7802 ./prep_dataset/ILSVRC2012_val_00022255.bin 224 224 +7803 ./prep_dataset/ILSVRC2012_val_00045311.bin 224 224 +7804 ./prep_dataset/ILSVRC2012_val_00024992.bin 224 224 +7805 ./prep_dataset/ILSVRC2012_val_00038317.bin 224 224 +7806 ./prep_dataset/ILSVRC2012_val_00034374.bin 224 224 +7807 ./prep_dataset/ILSVRC2012_val_00029051.bin 224 224 +7808 ./prep_dataset/ILSVRC2012_val_00048886.bin 224 224 +7809 ./prep_dataset/ILSVRC2012_val_00045448.bin 224 224 +7810 ./prep_dataset/ILSVRC2012_val_00009602.bin 224 224 +7811 ./prep_dataset/ILSVRC2012_val_00033874.bin 224 224 +7812 ./prep_dataset/ILSVRC2012_val_00045412.bin 224 224 +7813 ./prep_dataset/ILSVRC2012_val_00019851.bin 224 224 +7814 ./prep_dataset/ILSVRC2012_val_00020167.bin 224 224 +7815 ./prep_dataset/ILSVRC2012_val_00015217.bin 224 224 +7816 ./prep_dataset/ILSVRC2012_val_00014500.bin 224 224 +7817 ./prep_dataset/ILSVRC2012_val_00023360.bin 224 224 +7818 ./prep_dataset/ILSVRC2012_val_00036357.bin 224 224 +7819 ./prep_dataset/ILSVRC2012_val_00017716.bin 224 224 +7820 ./prep_dataset/ILSVRC2012_val_00033082.bin 224 224 +7821 ./prep_dataset/ILSVRC2012_val_00026363.bin 224 224 +7822 ./prep_dataset/ILSVRC2012_val_00014686.bin 224 224 +7823 ./prep_dataset/ILSVRC2012_val_00003546.bin 224 224 +7824 ./prep_dataset/ILSVRC2012_val_00026398.bin 224 224 +7825 ./prep_dataset/ILSVRC2012_val_00030812.bin 224 224 +7826 ./prep_dataset/ILSVRC2012_val_00002796.bin 224 224 +7827 ./prep_dataset/ILSVRC2012_val_00034434.bin 224 224 +7828 ./prep_dataset/ILSVRC2012_val_00000728.bin 224 224 +7829 ./prep_dataset/ILSVRC2012_val_00030212.bin 224 224 +7830 ./prep_dataset/ILSVRC2012_val_00044833.bin 224 224 +7831 ./prep_dataset/ILSVRC2012_val_00013800.bin 224 224 +7832 ./prep_dataset/ILSVRC2012_val_00002823.bin 224 224 +7833 ./prep_dataset/ILSVRC2012_val_00034885.bin 224 224 +7834 ./prep_dataset/ILSVRC2012_val_00003188.bin 224 224 +7835 ./prep_dataset/ILSVRC2012_val_00001521.bin 224 224 +7836 ./prep_dataset/ILSVRC2012_val_00019167.bin 224 224 +7837 ./prep_dataset/ILSVRC2012_val_00026793.bin 224 224 +7838 ./prep_dataset/ILSVRC2012_val_00004605.bin 224 224 +7839 ./prep_dataset/ILSVRC2012_val_00015389.bin 224 224 +7840 ./prep_dataset/ILSVRC2012_val_00007087.bin 224 224 +7841 ./prep_dataset/ILSVRC2012_val_00036138.bin 224 224 +7842 ./prep_dataset/ILSVRC2012_val_00023603.bin 224 224 +7843 ./prep_dataset/ILSVRC2012_val_00012986.bin 224 224 +7844 ./prep_dataset/ILSVRC2012_val_00000570.bin 224 224 +7845 ./prep_dataset/ILSVRC2012_val_00043901.bin 224 224 +7846 ./prep_dataset/ILSVRC2012_val_00004107.bin 224 224 +7847 ./prep_dataset/ILSVRC2012_val_00031711.bin 224 224 +7848 ./prep_dataset/ILSVRC2012_val_00011895.bin 224 224 +7849 ./prep_dataset/ILSVRC2012_val_00038310.bin 224 224 +7850 ./prep_dataset/ILSVRC2012_val_00036826.bin 224 224 +7851 ./prep_dataset/ILSVRC2012_val_00024136.bin 224 224 +7852 ./prep_dataset/ILSVRC2012_val_00027161.bin 224 224 +7853 ./prep_dataset/ILSVRC2012_val_00009585.bin 224 224 +7854 ./prep_dataset/ILSVRC2012_val_00016099.bin 224 224 +7855 ./prep_dataset/ILSVRC2012_val_00014024.bin 224 224 +7856 ./prep_dataset/ILSVRC2012_val_00016890.bin 224 224 +7857 ./prep_dataset/ILSVRC2012_val_00012070.bin 224 224 +7858 ./prep_dataset/ILSVRC2012_val_00029663.bin 224 224 +7859 ./prep_dataset/ILSVRC2012_val_00042832.bin 224 224 +7860 ./prep_dataset/ILSVRC2012_val_00048214.bin 224 224 +7861 ./prep_dataset/ILSVRC2012_val_00027030.bin 224 224 +7862 ./prep_dataset/ILSVRC2012_val_00039355.bin 224 224 +7863 ./prep_dataset/ILSVRC2012_val_00003695.bin 224 224 +7864 ./prep_dataset/ILSVRC2012_val_00022404.bin 224 224 +7865 ./prep_dataset/ILSVRC2012_val_00011118.bin 224 224 +7866 ./prep_dataset/ILSVRC2012_val_00007576.bin 224 224 +7867 ./prep_dataset/ILSVRC2012_val_00017726.bin 224 224 +7868 ./prep_dataset/ILSVRC2012_val_00030004.bin 224 224 +7869 ./prep_dataset/ILSVRC2012_val_00048348.bin 224 224 +7870 ./prep_dataset/ILSVRC2012_val_00034234.bin 224 224 +7871 ./prep_dataset/ILSVRC2012_val_00011855.bin 224 224 +7872 ./prep_dataset/ILSVRC2012_val_00036730.bin 224 224 +7873 ./prep_dataset/ILSVRC2012_val_00004056.bin 224 224 +7874 ./prep_dataset/ILSVRC2012_val_00027481.bin 224 224 +7875 ./prep_dataset/ILSVRC2012_val_00011298.bin 224 224 +7876 ./prep_dataset/ILSVRC2012_val_00034565.bin 224 224 +7877 ./prep_dataset/ILSVRC2012_val_00040240.bin 224 224 +7878 ./prep_dataset/ILSVRC2012_val_00004701.bin 224 224 +7879 ./prep_dataset/ILSVRC2012_val_00046243.bin 224 224 +7880 ./prep_dataset/ILSVRC2012_val_00011734.bin 224 224 +7881 ./prep_dataset/ILSVRC2012_val_00047970.bin 224 224 +7882 ./prep_dataset/ILSVRC2012_val_00024953.bin 224 224 +7883 ./prep_dataset/ILSVRC2012_val_00041000.bin 224 224 +7884 ./prep_dataset/ILSVRC2012_val_00001957.bin 224 224 +7885 ./prep_dataset/ILSVRC2012_val_00036300.bin 224 224 +7886 ./prep_dataset/ILSVRC2012_val_00029367.bin 224 224 +7887 ./prep_dataset/ILSVRC2012_val_00013838.bin 224 224 +7888 ./prep_dataset/ILSVRC2012_val_00006369.bin 224 224 +7889 ./prep_dataset/ILSVRC2012_val_00022096.bin 224 224 +7890 ./prep_dataset/ILSVRC2012_val_00001562.bin 224 224 +7891 ./prep_dataset/ILSVRC2012_val_00040483.bin 224 224 +7892 ./prep_dataset/ILSVRC2012_val_00007941.bin 224 224 +7893 ./prep_dataset/ILSVRC2012_val_00049742.bin 224 224 +7894 ./prep_dataset/ILSVRC2012_val_00041845.bin 224 224 +7895 ./prep_dataset/ILSVRC2012_val_00040301.bin 224 224 +7896 ./prep_dataset/ILSVRC2012_val_00032329.bin 224 224 +7897 ./prep_dataset/ILSVRC2012_val_00020442.bin 224 224 +7898 ./prep_dataset/ILSVRC2012_val_00042602.bin 224 224 +7899 ./prep_dataset/ILSVRC2012_val_00027303.bin 224 224 +7900 ./prep_dataset/ILSVRC2012_val_00031727.bin 224 224 +7901 ./prep_dataset/ILSVRC2012_val_00048730.bin 224 224 +7902 ./prep_dataset/ILSVRC2012_val_00046460.bin 224 224 +7903 ./prep_dataset/ILSVRC2012_val_00001958.bin 224 224 +7904 ./prep_dataset/ILSVRC2012_val_00012603.bin 224 224 +7905 ./prep_dataset/ILSVRC2012_val_00040888.bin 224 224 +7906 ./prep_dataset/ILSVRC2012_val_00036082.bin 224 224 +7907 ./prep_dataset/ILSVRC2012_val_00018705.bin 224 224 +7908 ./prep_dataset/ILSVRC2012_val_00025511.bin 224 224 +7909 ./prep_dataset/ILSVRC2012_val_00017844.bin 224 224 +7910 ./prep_dataset/ILSVRC2012_val_00017324.bin 224 224 +7911 ./prep_dataset/ILSVRC2012_val_00009832.bin 224 224 +7912 ./prep_dataset/ILSVRC2012_val_00038484.bin 224 224 +7913 ./prep_dataset/ILSVRC2012_val_00025508.bin 224 224 +7914 ./prep_dataset/ILSVRC2012_val_00041181.bin 224 224 +7915 ./prep_dataset/ILSVRC2012_val_00019004.bin 224 224 +7916 ./prep_dataset/ILSVRC2012_val_00001545.bin 224 224 +7917 ./prep_dataset/ILSVRC2012_val_00032972.bin 224 224 +7918 ./prep_dataset/ILSVRC2012_val_00041069.bin 224 224 +7919 ./prep_dataset/ILSVRC2012_val_00018268.bin 224 224 +7920 ./prep_dataset/ILSVRC2012_val_00018451.bin 224 224 +7921 ./prep_dataset/ILSVRC2012_val_00005091.bin 224 224 +7922 ./prep_dataset/ILSVRC2012_val_00027928.bin 224 224 +7923 ./prep_dataset/ILSVRC2012_val_00024831.bin 224 224 +7924 ./prep_dataset/ILSVRC2012_val_00034659.bin 224 224 +7925 ./prep_dataset/ILSVRC2012_val_00021165.bin 224 224 +7926 ./prep_dataset/ILSVRC2012_val_00039223.bin 224 224 +7927 ./prep_dataset/ILSVRC2012_val_00005464.bin 224 224 +7928 ./prep_dataset/ILSVRC2012_val_00015702.bin 224 224 +7929 ./prep_dataset/ILSVRC2012_val_00027602.bin 224 224 +7930 ./prep_dataset/ILSVRC2012_val_00040878.bin 224 224 +7931 ./prep_dataset/ILSVRC2012_val_00036018.bin 224 224 +7932 ./prep_dataset/ILSVRC2012_val_00000260.bin 224 224 +7933 ./prep_dataset/ILSVRC2012_val_00027248.bin 224 224 +7934 ./prep_dataset/ILSVRC2012_val_00045013.bin 224 224 +7935 ./prep_dataset/ILSVRC2012_val_00016380.bin 224 224 +7936 ./prep_dataset/ILSVRC2012_val_00036673.bin 224 224 +7937 ./prep_dataset/ILSVRC2012_val_00008623.bin 224 224 +7938 ./prep_dataset/ILSVRC2012_val_00046132.bin 224 224 +7939 ./prep_dataset/ILSVRC2012_val_00009410.bin 224 224 +7940 ./prep_dataset/ILSVRC2012_val_00042462.bin 224 224 +7941 ./prep_dataset/ILSVRC2012_val_00028246.bin 224 224 +7942 ./prep_dataset/ILSVRC2012_val_00015242.bin 224 224 +7943 ./prep_dataset/ILSVRC2012_val_00031968.bin 224 224 +7944 ./prep_dataset/ILSVRC2012_val_00007390.bin 224 224 +7945 ./prep_dataset/ILSVRC2012_val_00038684.bin 224 224 +7946 ./prep_dataset/ILSVRC2012_val_00049576.bin 224 224 +7947 ./prep_dataset/ILSVRC2012_val_00017797.bin 224 224 +7948 ./prep_dataset/ILSVRC2012_val_00028912.bin 224 224 +7949 ./prep_dataset/ILSVRC2012_val_00023190.bin 224 224 +7950 ./prep_dataset/ILSVRC2012_val_00011070.bin 224 224 +7951 ./prep_dataset/ILSVRC2012_val_00032064.bin 224 224 +7952 ./prep_dataset/ILSVRC2012_val_00009340.bin 224 224 +7953 ./prep_dataset/ILSVRC2012_val_00031570.bin 224 224 +7954 ./prep_dataset/ILSVRC2012_val_00007048.bin 224 224 +7955 ./prep_dataset/ILSVRC2012_val_00019769.bin 224 224 +7956 ./prep_dataset/ILSVRC2012_val_00014165.bin 224 224 +7957 ./prep_dataset/ILSVRC2012_val_00007339.bin 224 224 +7958 ./prep_dataset/ILSVRC2012_val_00005231.bin 224 224 +7959 ./prep_dataset/ILSVRC2012_val_00019937.bin 224 224 +7960 ./prep_dataset/ILSVRC2012_val_00012972.bin 224 224 +7961 ./prep_dataset/ILSVRC2012_val_00028136.bin 224 224 +7962 ./prep_dataset/ILSVRC2012_val_00026775.bin 224 224 +7963 ./prep_dataset/ILSVRC2012_val_00019419.bin 224 224 +7964 ./prep_dataset/ILSVRC2012_val_00034913.bin 224 224 +7965 ./prep_dataset/ILSVRC2012_val_00017062.bin 224 224 +7966 ./prep_dataset/ILSVRC2012_val_00007489.bin 224 224 +7967 ./prep_dataset/ILSVRC2012_val_00013539.bin 224 224 +7968 ./prep_dataset/ILSVRC2012_val_00037761.bin 224 224 +7969 ./prep_dataset/ILSVRC2012_val_00003512.bin 224 224 +7970 ./prep_dataset/ILSVRC2012_val_00005590.bin 224 224 +7971 ./prep_dataset/ILSVRC2012_val_00031859.bin 224 224 +7972 ./prep_dataset/ILSVRC2012_val_00020829.bin 224 224 +7973 ./prep_dataset/ILSVRC2012_val_00038497.bin 224 224 +7974 ./prep_dataset/ILSVRC2012_val_00032825.bin 224 224 +7975 ./prep_dataset/ILSVRC2012_val_00030963.bin 224 224 +7976 ./prep_dataset/ILSVRC2012_val_00028106.bin 224 224 +7977 ./prep_dataset/ILSVRC2012_val_00013590.bin 224 224 +7978 ./prep_dataset/ILSVRC2012_val_00027211.bin 224 224 +7979 ./prep_dataset/ILSVRC2012_val_00009854.bin 224 224 +7980 ./prep_dataset/ILSVRC2012_val_00022474.bin 224 224 +7981 ./prep_dataset/ILSVRC2012_val_00012007.bin 224 224 +7982 ./prep_dataset/ILSVRC2012_val_00001457.bin 224 224 +7983 ./prep_dataset/ILSVRC2012_val_00014966.bin 224 224 +7984 ./prep_dataset/ILSVRC2012_val_00048492.bin 224 224 +7985 ./prep_dataset/ILSVRC2012_val_00018023.bin 224 224 +7986 ./prep_dataset/ILSVRC2012_val_00000553.bin 224 224 +7987 ./prep_dataset/ILSVRC2012_val_00020064.bin 224 224 +7988 ./prep_dataset/ILSVRC2012_val_00016758.bin 224 224 +7989 ./prep_dataset/ILSVRC2012_val_00020666.bin 224 224 +7990 ./prep_dataset/ILSVRC2012_val_00002249.bin 224 224 +7991 ./prep_dataset/ILSVRC2012_val_00018182.bin 224 224 +7992 ./prep_dataset/ILSVRC2012_val_00010778.bin 224 224 +7993 ./prep_dataset/ILSVRC2012_val_00007854.bin 224 224 +7994 ./prep_dataset/ILSVRC2012_val_00045628.bin 224 224 +7995 ./prep_dataset/ILSVRC2012_val_00010330.bin 224 224 +7996 ./prep_dataset/ILSVRC2012_val_00022580.bin 224 224 +7997 ./prep_dataset/ILSVRC2012_val_00024615.bin 224 224 +7998 ./prep_dataset/ILSVRC2012_val_00029176.bin 224 224 +7999 ./prep_dataset/ILSVRC2012_val_00013821.bin 224 224 +8000 ./prep_dataset/ILSVRC2012_val_00027858.bin 224 224 +8001 ./prep_dataset/ILSVRC2012_val_00024160.bin 224 224 +8002 ./prep_dataset/ILSVRC2012_val_00040022.bin 224 224 +8003 ./prep_dataset/ILSVRC2012_val_00000771.bin 224 224 +8004 ./prep_dataset/ILSVRC2012_val_00008903.bin 224 224 +8005 ./prep_dataset/ILSVRC2012_val_00020362.bin 224 224 +8006 ./prep_dataset/ILSVRC2012_val_00038526.bin 224 224 +8007 ./prep_dataset/ILSVRC2012_val_00040788.bin 224 224 +8008 ./prep_dataset/ILSVRC2012_val_00034928.bin 224 224 +8009 ./prep_dataset/ILSVRC2012_val_00035186.bin 224 224 +8010 ./prep_dataset/ILSVRC2012_val_00020546.bin 224 224 +8011 ./prep_dataset/ILSVRC2012_val_00032521.bin 224 224 +8012 ./prep_dataset/ILSVRC2012_val_00037807.bin 224 224 +8013 ./prep_dataset/ILSVRC2012_val_00005431.bin 224 224 +8014 ./prep_dataset/ILSVRC2012_val_00012905.bin 224 224 +8015 ./prep_dataset/ILSVRC2012_val_00016253.bin 224 224 +8016 ./prep_dataset/ILSVRC2012_val_00025650.bin 224 224 +8017 ./prep_dataset/ILSVRC2012_val_00041884.bin 224 224 +8018 ./prep_dataset/ILSVRC2012_val_00036705.bin 224 224 +8019 ./prep_dataset/ILSVRC2012_val_00002463.bin 224 224 +8020 ./prep_dataset/ILSVRC2012_val_00043445.bin 224 224 +8021 ./prep_dataset/ILSVRC2012_val_00040080.bin 224 224 +8022 ./prep_dataset/ILSVRC2012_val_00022011.bin 224 224 +8023 ./prep_dataset/ILSVRC2012_val_00046353.bin 224 224 +8024 ./prep_dataset/ILSVRC2012_val_00006727.bin 224 224 +8025 ./prep_dataset/ILSVRC2012_val_00036813.bin 224 224 +8026 ./prep_dataset/ILSVRC2012_val_00049029.bin 224 224 +8027 ./prep_dataset/ILSVRC2012_val_00010227.bin 224 224 +8028 ./prep_dataset/ILSVRC2012_val_00047717.bin 224 224 +8029 ./prep_dataset/ILSVRC2012_val_00030023.bin 224 224 +8030 ./prep_dataset/ILSVRC2012_val_00036249.bin 224 224 +8031 ./prep_dataset/ILSVRC2012_val_00017156.bin 224 224 +8032 ./prep_dataset/ILSVRC2012_val_00032917.bin 224 224 +8033 ./prep_dataset/ILSVRC2012_val_00046688.bin 224 224 +8034 ./prep_dataset/ILSVRC2012_val_00012887.bin 224 224 +8035 ./prep_dataset/ILSVRC2012_val_00038358.bin 224 224 +8036 ./prep_dataset/ILSVRC2012_val_00019010.bin 224 224 +8037 ./prep_dataset/ILSVRC2012_val_00028221.bin 224 224 +8038 ./prep_dataset/ILSVRC2012_val_00029081.bin 224 224 +8039 ./prep_dataset/ILSVRC2012_val_00027709.bin 224 224 +8040 ./prep_dataset/ILSVRC2012_val_00022838.bin 224 224 +8041 ./prep_dataset/ILSVRC2012_val_00008664.bin 224 224 +8042 ./prep_dataset/ILSVRC2012_val_00025215.bin 224 224 +8043 ./prep_dataset/ILSVRC2012_val_00005819.bin 224 224 +8044 ./prep_dataset/ILSVRC2012_val_00030926.bin 224 224 +8045 ./prep_dataset/ILSVRC2012_val_00018849.bin 224 224 +8046 ./prep_dataset/ILSVRC2012_val_00009497.bin 224 224 +8047 ./prep_dataset/ILSVRC2012_val_00002357.bin 224 224 +8048 ./prep_dataset/ILSVRC2012_val_00011228.bin 224 224 +8049 ./prep_dataset/ILSVRC2012_val_00022953.bin 224 224 +8050 ./prep_dataset/ILSVRC2012_val_00020251.bin 224 224 +8051 ./prep_dataset/ILSVRC2012_val_00018235.bin 224 224 +8052 ./prep_dataset/ILSVRC2012_val_00035930.bin 224 224 +8053 ./prep_dataset/ILSVRC2012_val_00009691.bin 224 224 +8054 ./prep_dataset/ILSVRC2012_val_00037732.bin 224 224 +8055 ./prep_dataset/ILSVRC2012_val_00048416.bin 224 224 +8056 ./prep_dataset/ILSVRC2012_val_00037924.bin 224 224 +8057 ./prep_dataset/ILSVRC2012_val_00016613.bin 224 224 +8058 ./prep_dataset/ILSVRC2012_val_00044098.bin 224 224 +8059 ./prep_dataset/ILSVRC2012_val_00039758.bin 224 224 +8060 ./prep_dataset/ILSVRC2012_val_00039403.bin 224 224 +8061 ./prep_dataset/ILSVRC2012_val_00036528.bin 224 224 +8062 ./prep_dataset/ILSVRC2012_val_00008702.bin 224 224 +8063 ./prep_dataset/ILSVRC2012_val_00012058.bin 224 224 +8064 ./prep_dataset/ILSVRC2012_val_00040581.bin 224 224 +8065 ./prep_dataset/ILSVRC2012_val_00014040.bin 224 224 +8066 ./prep_dataset/ILSVRC2012_val_00042979.bin 224 224 +8067 ./prep_dataset/ILSVRC2012_val_00012640.bin 224 224 +8068 ./prep_dataset/ILSVRC2012_val_00019818.bin 224 224 +8069 ./prep_dataset/ILSVRC2012_val_00035071.bin 224 224 +8070 ./prep_dataset/ILSVRC2012_val_00003557.bin 224 224 +8071 ./prep_dataset/ILSVRC2012_val_00004761.bin 224 224 +8072 ./prep_dataset/ILSVRC2012_val_00014197.bin 224 224 +8073 ./prep_dataset/ILSVRC2012_val_00041621.bin 224 224 +8074 ./prep_dataset/ILSVRC2012_val_00048918.bin 224 224 +8075 ./prep_dataset/ILSVRC2012_val_00035137.bin 224 224 +8076 ./prep_dataset/ILSVRC2012_val_00040541.bin 224 224 +8077 ./prep_dataset/ILSVRC2012_val_00019262.bin 224 224 +8078 ./prep_dataset/ILSVRC2012_val_00040614.bin 224 224 +8079 ./prep_dataset/ILSVRC2012_val_00014744.bin 224 224 +8080 ./prep_dataset/ILSVRC2012_val_00048423.bin 224 224 +8081 ./prep_dataset/ILSVRC2012_val_00046421.bin 224 224 +8082 ./prep_dataset/ILSVRC2012_val_00003477.bin 224 224 +8083 ./prep_dataset/ILSVRC2012_val_00036672.bin 224 224 +8084 ./prep_dataset/ILSVRC2012_val_00002317.bin 224 224 +8085 ./prep_dataset/ILSVRC2012_val_00030984.bin 224 224 +8086 ./prep_dataset/ILSVRC2012_val_00036446.bin 224 224 +8087 ./prep_dataset/ILSVRC2012_val_00036493.bin 224 224 +8088 ./prep_dataset/ILSVRC2012_val_00020564.bin 224 224 +8089 ./prep_dataset/ILSVRC2012_val_00004352.bin 224 224 +8090 ./prep_dataset/ILSVRC2012_val_00029533.bin 224 224 +8091 ./prep_dataset/ILSVRC2012_val_00001148.bin 224 224 +8092 ./prep_dataset/ILSVRC2012_val_00037949.bin 224 224 +8093 ./prep_dataset/ILSVRC2012_val_00029403.bin 224 224 +8094 ./prep_dataset/ILSVRC2012_val_00037955.bin 224 224 +8095 ./prep_dataset/ILSVRC2012_val_00015905.bin 224 224 +8096 ./prep_dataset/ILSVRC2012_val_00000350.bin 224 224 +8097 ./prep_dataset/ILSVRC2012_val_00019368.bin 224 224 +8098 ./prep_dataset/ILSVRC2012_val_00004312.bin 224 224 +8099 ./prep_dataset/ILSVRC2012_val_00027499.bin 224 224 +8100 ./prep_dataset/ILSVRC2012_val_00001714.bin 224 224 +8101 ./prep_dataset/ILSVRC2012_val_00017194.bin 224 224 +8102 ./prep_dataset/ILSVRC2012_val_00001278.bin 224 224 +8103 ./prep_dataset/ILSVRC2012_val_00039591.bin 224 224 +8104 ./prep_dataset/ILSVRC2012_val_00031492.bin 224 224 +8105 ./prep_dataset/ILSVRC2012_val_00021842.bin 224 224 +8106 ./prep_dataset/ILSVRC2012_val_00015709.bin 224 224 +8107 ./prep_dataset/ILSVRC2012_val_00023322.bin 224 224 +8108 ./prep_dataset/ILSVRC2012_val_00036565.bin 224 224 +8109 ./prep_dataset/ILSVRC2012_val_00008217.bin 224 224 +8110 ./prep_dataset/ILSVRC2012_val_00017305.bin 224 224 +8111 ./prep_dataset/ILSVRC2012_val_00009135.bin 224 224 +8112 ./prep_dataset/ILSVRC2012_val_00011845.bin 224 224 +8113 ./prep_dataset/ILSVRC2012_val_00000107.bin 224 224 +8114 ./prep_dataset/ILSVRC2012_val_00011284.bin 224 224 +8115 ./prep_dataset/ILSVRC2012_val_00045158.bin 224 224 +8116 ./prep_dataset/ILSVRC2012_val_00007388.bin 224 224 +8117 ./prep_dataset/ILSVRC2012_val_00015409.bin 224 224 +8118 ./prep_dataset/ILSVRC2012_val_00033382.bin 224 224 +8119 ./prep_dataset/ILSVRC2012_val_00002745.bin 224 224 +8120 ./prep_dataset/ILSVRC2012_val_00041126.bin 224 224 +8121 ./prep_dataset/ILSVRC2012_val_00015754.bin 224 224 +8122 ./prep_dataset/ILSVRC2012_val_00028857.bin 224 224 +8123 ./prep_dataset/ILSVRC2012_val_00040976.bin 224 224 +8124 ./prep_dataset/ILSVRC2012_val_00043592.bin 224 224 +8125 ./prep_dataset/ILSVRC2012_val_00016044.bin 224 224 +8126 ./prep_dataset/ILSVRC2012_val_00013856.bin 224 224 +8127 ./prep_dataset/ILSVRC2012_val_00012999.bin 224 224 +8128 ./prep_dataset/ILSVRC2012_val_00018981.bin 224 224 +8129 ./prep_dataset/ILSVRC2012_val_00005344.bin 224 224 +8130 ./prep_dataset/ILSVRC2012_val_00017610.bin 224 224 +8131 ./prep_dataset/ILSVRC2012_val_00031902.bin 224 224 +8132 ./prep_dataset/ILSVRC2012_val_00047275.bin 224 224 +8133 ./prep_dataset/ILSVRC2012_val_00041257.bin 224 224 +8134 ./prep_dataset/ILSVRC2012_val_00000116.bin 224 224 +8135 ./prep_dataset/ILSVRC2012_val_00041549.bin 224 224 +8136 ./prep_dataset/ILSVRC2012_val_00048530.bin 224 224 +8137 ./prep_dataset/ILSVRC2012_val_00028308.bin 224 224 +8138 ./prep_dataset/ILSVRC2012_val_00005192.bin 224 224 +8139 ./prep_dataset/ILSVRC2012_val_00008464.bin 224 224 +8140 ./prep_dataset/ILSVRC2012_val_00012964.bin 224 224 +8141 ./prep_dataset/ILSVRC2012_val_00032562.bin 224 224 +8142 ./prep_dataset/ILSVRC2012_val_00044953.bin 224 224 +8143 ./prep_dataset/ILSVRC2012_val_00012364.bin 224 224 +8144 ./prep_dataset/ILSVRC2012_val_00017537.bin 224 224 +8145 ./prep_dataset/ILSVRC2012_val_00028372.bin 224 224 +8146 ./prep_dataset/ILSVRC2012_val_00017151.bin 224 224 +8147 ./prep_dataset/ILSVRC2012_val_00005682.bin 224 224 +8148 ./prep_dataset/ILSVRC2012_val_00031139.bin 224 224 +8149 ./prep_dataset/ILSVRC2012_val_00011152.bin 224 224 +8150 ./prep_dataset/ILSVRC2012_val_00021132.bin 224 224 +8151 ./prep_dataset/ILSVRC2012_val_00034206.bin 224 224 +8152 ./prep_dataset/ILSVRC2012_val_00021309.bin 224 224 +8153 ./prep_dataset/ILSVRC2012_val_00030528.bin 224 224 +8154 ./prep_dataset/ILSVRC2012_val_00008612.bin 224 224 +8155 ./prep_dataset/ILSVRC2012_val_00024712.bin 224 224 +8156 ./prep_dataset/ILSVRC2012_val_00018806.bin 224 224 +8157 ./prep_dataset/ILSVRC2012_val_00005538.bin 224 224 +8158 ./prep_dataset/ILSVRC2012_val_00029614.bin 224 224 +8159 ./prep_dataset/ILSVRC2012_val_00000210.bin 224 224 +8160 ./prep_dataset/ILSVRC2012_val_00037823.bin 224 224 +8161 ./prep_dataset/ILSVRC2012_val_00009039.bin 224 224 +8162 ./prep_dataset/ILSVRC2012_val_00042689.bin 224 224 +8163 ./prep_dataset/ILSVRC2012_val_00018174.bin 224 224 +8164 ./prep_dataset/ILSVRC2012_val_00010024.bin 224 224 +8165 ./prep_dataset/ILSVRC2012_val_00043093.bin 224 224 +8166 ./prep_dataset/ILSVRC2012_val_00006218.bin 224 224 +8167 ./prep_dataset/ILSVRC2012_val_00045059.bin 224 224 +8168 ./prep_dataset/ILSVRC2012_val_00039012.bin 224 224 +8169 ./prep_dataset/ILSVRC2012_val_00019883.bin 224 224 +8170 ./prep_dataset/ILSVRC2012_val_00044468.bin 224 224 +8171 ./prep_dataset/ILSVRC2012_val_00015684.bin 224 224 +8172 ./prep_dataset/ILSVRC2012_val_00030115.bin 224 224 +8173 ./prep_dataset/ILSVRC2012_val_00028898.bin 224 224 +8174 ./prep_dataset/ILSVRC2012_val_00034730.bin 224 224 +8175 ./prep_dataset/ILSVRC2012_val_00011510.bin 224 224 +8176 ./prep_dataset/ILSVRC2012_val_00001921.bin 224 224 +8177 ./prep_dataset/ILSVRC2012_val_00005302.bin 224 224 +8178 ./prep_dataset/ILSVRC2012_val_00041258.bin 224 224 +8179 ./prep_dataset/ILSVRC2012_val_00011744.bin 224 224 +8180 ./prep_dataset/ILSVRC2012_val_00008619.bin 224 224 +8181 ./prep_dataset/ILSVRC2012_val_00028684.bin 224 224 +8182 ./prep_dataset/ILSVRC2012_val_00042022.bin 224 224 +8183 ./prep_dataset/ILSVRC2012_val_00043763.bin 224 224 +8184 ./prep_dataset/ILSVRC2012_val_00022600.bin 224 224 +8185 ./prep_dataset/ILSVRC2012_val_00017824.bin 224 224 +8186 ./prep_dataset/ILSVRC2012_val_00040901.bin 224 224 +8187 ./prep_dataset/ILSVRC2012_val_00048768.bin 224 224 +8188 ./prep_dataset/ILSVRC2012_val_00036348.bin 224 224 +8189 ./prep_dataset/ILSVRC2012_val_00008545.bin 224 224 +8190 ./prep_dataset/ILSVRC2012_val_00000615.bin 224 224 +8191 ./prep_dataset/ILSVRC2012_val_00010875.bin 224 224 +8192 ./prep_dataset/ILSVRC2012_val_00045456.bin 224 224 +8193 ./prep_dataset/ILSVRC2012_val_00042597.bin 224 224 +8194 ./prep_dataset/ILSVRC2012_val_00031774.bin 224 224 +8195 ./prep_dataset/ILSVRC2012_val_00010829.bin 224 224 +8196 ./prep_dataset/ILSVRC2012_val_00029506.bin 224 224 +8197 ./prep_dataset/ILSVRC2012_val_00038886.bin 224 224 +8198 ./prep_dataset/ILSVRC2012_val_00047845.bin 224 224 +8199 ./prep_dataset/ILSVRC2012_val_00006488.bin 224 224 +8200 ./prep_dataset/ILSVRC2012_val_00007360.bin 224 224 +8201 ./prep_dataset/ILSVRC2012_val_00043597.bin 224 224 +8202 ./prep_dataset/ILSVRC2012_val_00015770.bin 224 224 +8203 ./prep_dataset/ILSVRC2012_val_00048984.bin 224 224 +8204 ./prep_dataset/ILSVRC2012_val_00000721.bin 224 224 +8205 ./prep_dataset/ILSVRC2012_val_00013586.bin 224 224 +8206 ./prep_dataset/ILSVRC2012_val_00034298.bin 224 224 +8207 ./prep_dataset/ILSVRC2012_val_00006032.bin 224 224 +8208 ./prep_dataset/ILSVRC2012_val_00042482.bin 224 224 +8209 ./prep_dataset/ILSVRC2012_val_00044530.bin 224 224 +8210 ./prep_dataset/ILSVRC2012_val_00010583.bin 224 224 +8211 ./prep_dataset/ILSVRC2012_val_00048584.bin 224 224 +8212 ./prep_dataset/ILSVRC2012_val_00040770.bin 224 224 +8213 ./prep_dataset/ILSVRC2012_val_00003236.bin 224 224 +8214 ./prep_dataset/ILSVRC2012_val_00004335.bin 224 224 +8215 ./prep_dataset/ILSVRC2012_val_00026349.bin 224 224 +8216 ./prep_dataset/ILSVRC2012_val_00024487.bin 224 224 +8217 ./prep_dataset/ILSVRC2012_val_00021289.bin 224 224 +8218 ./prep_dataset/ILSVRC2012_val_00001229.bin 224 224 +8219 ./prep_dataset/ILSVRC2012_val_00019179.bin 224 224 +8220 ./prep_dataset/ILSVRC2012_val_00000453.bin 224 224 +8221 ./prep_dataset/ILSVRC2012_val_00045349.bin 224 224 +8222 ./prep_dataset/ILSVRC2012_val_00018398.bin 224 224 +8223 ./prep_dataset/ILSVRC2012_val_00027753.bin 224 224 +8224 ./prep_dataset/ILSVRC2012_val_00011897.bin 224 224 +8225 ./prep_dataset/ILSVRC2012_val_00028028.bin 224 224 +8226 ./prep_dataset/ILSVRC2012_val_00031584.bin 224 224 +8227 ./prep_dataset/ILSVRC2012_val_00017133.bin 224 224 +8228 ./prep_dataset/ILSVRC2012_val_00005904.bin 224 224 +8229 ./prep_dataset/ILSVRC2012_val_00042520.bin 224 224 +8230 ./prep_dataset/ILSVRC2012_val_00022187.bin 224 224 +8231 ./prep_dataset/ILSVRC2012_val_00038806.bin 224 224 +8232 ./prep_dataset/ILSVRC2012_val_00002623.bin 224 224 +8233 ./prep_dataset/ILSVRC2012_val_00019528.bin 224 224 +8234 ./prep_dataset/ILSVRC2012_val_00002120.bin 224 224 +8235 ./prep_dataset/ILSVRC2012_val_00036515.bin 224 224 +8236 ./prep_dataset/ILSVRC2012_val_00000725.bin 224 224 +8237 ./prep_dataset/ILSVRC2012_val_00043539.bin 224 224 +8238 ./prep_dataset/ILSVRC2012_val_00041213.bin 224 224 +8239 ./prep_dataset/ILSVRC2012_val_00035895.bin 224 224 +8240 ./prep_dataset/ILSVRC2012_val_00014527.bin 224 224 +8241 ./prep_dataset/ILSVRC2012_val_00009116.bin 224 224 +8242 ./prep_dataset/ILSVRC2012_val_00044272.bin 224 224 +8243 ./prep_dataset/ILSVRC2012_val_00013218.bin 224 224 +8244 ./prep_dataset/ILSVRC2012_val_00037466.bin 224 224 +8245 ./prep_dataset/ILSVRC2012_val_00009766.bin 224 224 +8246 ./prep_dataset/ILSVRC2012_val_00016504.bin 224 224 +8247 ./prep_dataset/ILSVRC2012_val_00049471.bin 224 224 +8248 ./prep_dataset/ILSVRC2012_val_00023090.bin 224 224 +8249 ./prep_dataset/ILSVRC2012_val_00018827.bin 224 224 +8250 ./prep_dataset/ILSVRC2012_val_00047199.bin 224 224 +8251 ./prep_dataset/ILSVRC2012_val_00020261.bin 224 224 +8252 ./prep_dataset/ILSVRC2012_val_00031088.bin 224 224 +8253 ./prep_dataset/ILSVRC2012_val_00043030.bin 224 224 +8254 ./prep_dataset/ILSVRC2012_val_00032812.bin 224 224 +8255 ./prep_dataset/ILSVRC2012_val_00018461.bin 224 224 +8256 ./prep_dataset/ILSVRC2012_val_00038182.bin 224 224 +8257 ./prep_dataset/ILSVRC2012_val_00036454.bin 224 224 +8258 ./prep_dataset/ILSVRC2012_val_00003057.bin 224 224 +8259 ./prep_dataset/ILSVRC2012_val_00008615.bin 224 224 +8260 ./prep_dataset/ILSVRC2012_val_00049227.bin 224 224 +8261 ./prep_dataset/ILSVRC2012_val_00029023.bin 224 224 +8262 ./prep_dataset/ILSVRC2012_val_00008210.bin 224 224 +8263 ./prep_dataset/ILSVRC2012_val_00046047.bin 224 224 +8264 ./prep_dataset/ILSVRC2012_val_00034994.bin 224 224 +8265 ./prep_dataset/ILSVRC2012_val_00042943.bin 224 224 +8266 ./prep_dataset/ILSVRC2012_val_00029003.bin 224 224 +8267 ./prep_dataset/ILSVRC2012_val_00004244.bin 224 224 +8268 ./prep_dataset/ILSVRC2012_val_00012424.bin 224 224 +8269 ./prep_dataset/ILSVRC2012_val_00024582.bin 224 224 +8270 ./prep_dataset/ILSVRC2012_val_00027371.bin 224 224 +8271 ./prep_dataset/ILSVRC2012_val_00024795.bin 224 224 +8272 ./prep_dataset/ILSVRC2012_val_00001468.bin 224 224 +8273 ./prep_dataset/ILSVRC2012_val_00026283.bin 224 224 +8274 ./prep_dataset/ILSVRC2012_val_00032130.bin 224 224 +8275 ./prep_dataset/ILSVRC2012_val_00038062.bin 224 224 +8276 ./prep_dataset/ILSVRC2012_val_00026919.bin 224 224 +8277 ./prep_dataset/ILSVRC2012_val_00028444.bin 224 224 +8278 ./prep_dataset/ILSVRC2012_val_00004137.bin 224 224 +8279 ./prep_dataset/ILSVRC2012_val_00015825.bin 224 224 +8280 ./prep_dataset/ILSVRC2012_val_00021113.bin 224 224 +8281 ./prep_dataset/ILSVRC2012_val_00038223.bin 224 224 +8282 ./prep_dataset/ILSVRC2012_val_00025932.bin 224 224 +8283 ./prep_dataset/ILSVRC2012_val_00012983.bin 224 224 +8284 ./prep_dataset/ILSVRC2012_val_00026975.bin 224 224 +8285 ./prep_dataset/ILSVRC2012_val_00041356.bin 224 224 +8286 ./prep_dataset/ILSVRC2012_val_00037722.bin 224 224 +8287 ./prep_dataset/ILSVRC2012_val_00010552.bin 224 224 +8288 ./prep_dataset/ILSVRC2012_val_00013680.bin 224 224 +8289 ./prep_dataset/ILSVRC2012_val_00012482.bin 224 224 +8290 ./prep_dataset/ILSVRC2012_val_00018546.bin 224 224 +8291 ./prep_dataset/ILSVRC2012_val_00043700.bin 224 224 +8292 ./prep_dataset/ILSVRC2012_val_00018233.bin 224 224 +8293 ./prep_dataset/ILSVRC2012_val_00036739.bin 224 224 +8294 ./prep_dataset/ILSVRC2012_val_00021789.bin 224 224 +8295 ./prep_dataset/ILSVRC2012_val_00032005.bin 224 224 +8296 ./prep_dataset/ILSVRC2012_val_00002722.bin 224 224 +8297 ./prep_dataset/ILSVRC2012_val_00041924.bin 224 224 +8298 ./prep_dataset/ILSVRC2012_val_00007693.bin 224 224 +8299 ./prep_dataset/ILSVRC2012_val_00004723.bin 224 224 +8300 ./prep_dataset/ILSVRC2012_val_00013705.bin 224 224 +8301 ./prep_dataset/ILSVRC2012_val_00037457.bin 224 224 +8302 ./prep_dataset/ILSVRC2012_val_00032595.bin 224 224 +8303 ./prep_dataset/ILSVRC2012_val_00019001.bin 224 224 +8304 ./prep_dataset/ILSVRC2012_val_00041136.bin 224 224 +8305 ./prep_dataset/ILSVRC2012_val_00017181.bin 224 224 +8306 ./prep_dataset/ILSVRC2012_val_00008489.bin 224 224 +8307 ./prep_dataset/ILSVRC2012_val_00045591.bin 224 224 +8308 ./prep_dataset/ILSVRC2012_val_00010989.bin 224 224 +8309 ./prep_dataset/ILSVRC2012_val_00025282.bin 224 224 +8310 ./prep_dataset/ILSVRC2012_val_00022825.bin 224 224 +8311 ./prep_dataset/ILSVRC2012_val_00041786.bin 224 224 +8312 ./prep_dataset/ILSVRC2012_val_00028331.bin 224 224 +8313 ./prep_dataset/ILSVRC2012_val_00000806.bin 224 224 +8314 ./prep_dataset/ILSVRC2012_val_00045171.bin 224 224 +8315 ./prep_dataset/ILSVRC2012_val_00043307.bin 224 224 +8316 ./prep_dataset/ILSVRC2012_val_00002777.bin 224 224 +8317 ./prep_dataset/ILSVRC2012_val_00000723.bin 224 224 +8318 ./prep_dataset/ILSVRC2012_val_00030989.bin 224 224 +8319 ./prep_dataset/ILSVRC2012_val_00048523.bin 224 224 +8320 ./prep_dataset/ILSVRC2012_val_00029501.bin 224 224 +8321 ./prep_dataset/ILSVRC2012_val_00011557.bin 224 224 +8322 ./prep_dataset/ILSVRC2012_val_00025046.bin 224 224 +8323 ./prep_dataset/ILSVRC2012_val_00020875.bin 224 224 +8324 ./prep_dataset/ILSVRC2012_val_00014662.bin 224 224 +8325 ./prep_dataset/ILSVRC2012_val_00045728.bin 224 224 +8326 ./prep_dataset/ILSVRC2012_val_00018694.bin 224 224 +8327 ./prep_dataset/ILSVRC2012_val_00040704.bin 224 224 +8328 ./prep_dataset/ILSVRC2012_val_00014380.bin 224 224 +8329 ./prep_dataset/ILSVRC2012_val_00033457.bin 224 224 +8330 ./prep_dataset/ILSVRC2012_val_00033969.bin 224 224 +8331 ./prep_dataset/ILSVRC2012_val_00019709.bin 224 224 +8332 ./prep_dataset/ILSVRC2012_val_00041215.bin 224 224 +8333 ./prep_dataset/ILSVRC2012_val_00022073.bin 224 224 +8334 ./prep_dataset/ILSVRC2012_val_00030058.bin 224 224 +8335 ./prep_dataset/ILSVRC2012_val_00044847.bin 224 224 +8336 ./prep_dataset/ILSVRC2012_val_00016337.bin 224 224 +8337 ./prep_dataset/ILSVRC2012_val_00041494.bin 224 224 +8338 ./prep_dataset/ILSVRC2012_val_00036106.bin 224 224 +8339 ./prep_dataset/ILSVRC2012_val_00045929.bin 224 224 +8340 ./prep_dataset/ILSVRC2012_val_00045603.bin 224 224 +8341 ./prep_dataset/ILSVRC2012_val_00009655.bin 224 224 +8342 ./prep_dataset/ILSVRC2012_val_00029028.bin 224 224 +8343 ./prep_dataset/ILSVRC2012_val_00021479.bin 224 224 +8344 ./prep_dataset/ILSVRC2012_val_00048716.bin 224 224 +8345 ./prep_dataset/ILSVRC2012_val_00003815.bin 224 224 +8346 ./prep_dataset/ILSVRC2012_val_00022463.bin 224 224 +8347 ./prep_dataset/ILSVRC2012_val_00030483.bin 224 224 +8348 ./prep_dataset/ILSVRC2012_val_00046322.bin 224 224 +8349 ./prep_dataset/ILSVRC2012_val_00045681.bin 224 224 +8350 ./prep_dataset/ILSVRC2012_val_00043626.bin 224 224 +8351 ./prep_dataset/ILSVRC2012_val_00037135.bin 224 224 +8352 ./prep_dataset/ILSVRC2012_val_00004191.bin 224 224 +8353 ./prep_dataset/ILSVRC2012_val_00029636.bin 224 224 +8354 ./prep_dataset/ILSVRC2012_val_00005396.bin 224 224 +8355 ./prep_dataset/ILSVRC2012_val_00047784.bin 224 224 +8356 ./prep_dataset/ILSVRC2012_val_00045571.bin 224 224 +8357 ./prep_dataset/ILSVRC2012_val_00024620.bin 224 224 +8358 ./prep_dataset/ILSVRC2012_val_00035665.bin 224 224 +8359 ./prep_dataset/ILSVRC2012_val_00024427.bin 224 224 +8360 ./prep_dataset/ILSVRC2012_val_00017887.bin 224 224 +8361 ./prep_dataset/ILSVRC2012_val_00024273.bin 224 224 +8362 ./prep_dataset/ILSVRC2012_val_00003745.bin 224 224 +8363 ./prep_dataset/ILSVRC2012_val_00046661.bin 224 224 +8364 ./prep_dataset/ILSVRC2012_val_00049328.bin 224 224 +8365 ./prep_dataset/ILSVRC2012_val_00018381.bin 224 224 +8366 ./prep_dataset/ILSVRC2012_val_00010004.bin 224 224 +8367 ./prep_dataset/ILSVRC2012_val_00025078.bin 224 224 +8368 ./prep_dataset/ILSVRC2012_val_00009298.bin 224 224 +8369 ./prep_dataset/ILSVRC2012_val_00019050.bin 224 224 +8370 ./prep_dataset/ILSVRC2012_val_00029724.bin 224 224 +8371 ./prep_dataset/ILSVRC2012_val_00022949.bin 224 224 +8372 ./prep_dataset/ILSVRC2012_val_00042095.bin 224 224 +8373 ./prep_dataset/ILSVRC2012_val_00007932.bin 224 224 +8374 ./prep_dataset/ILSVRC2012_val_00033943.bin 224 224 +8375 ./prep_dataset/ILSVRC2012_val_00011191.bin 224 224 +8376 ./prep_dataset/ILSVRC2012_val_00007418.bin 224 224 +8377 ./prep_dataset/ILSVRC2012_val_00016191.bin 224 224 +8378 ./prep_dataset/ILSVRC2012_val_00007409.bin 224 224 +8379 ./prep_dataset/ILSVRC2012_val_00048622.bin 224 224 +8380 ./prep_dataset/ILSVRC2012_val_00006496.bin 224 224 +8381 ./prep_dataset/ILSVRC2012_val_00047042.bin 224 224 +8382 ./prep_dataset/ILSVRC2012_val_00032948.bin 224 224 +8383 ./prep_dataset/ILSVRC2012_val_00013654.bin 224 224 +8384 ./prep_dataset/ILSVRC2012_val_00039485.bin 224 224 +8385 ./prep_dataset/ILSVRC2012_val_00022055.bin 224 224 +8386 ./prep_dataset/ILSVRC2012_val_00032909.bin 224 224 +8387 ./prep_dataset/ILSVRC2012_val_00011939.bin 224 224 +8388 ./prep_dataset/ILSVRC2012_val_00000262.bin 224 224 +8389 ./prep_dataset/ILSVRC2012_val_00015292.bin 224 224 +8390 ./prep_dataset/ILSVRC2012_val_00028407.bin 224 224 +8391 ./prep_dataset/ILSVRC2012_val_00026837.bin 224 224 +8392 ./prep_dataset/ILSVRC2012_val_00042344.bin 224 224 +8393 ./prep_dataset/ILSVRC2012_val_00041295.bin 224 224 +8394 ./prep_dataset/ILSVRC2012_val_00044518.bin 224 224 +8395 ./prep_dataset/ILSVRC2012_val_00015876.bin 224 224 +8396 ./prep_dataset/ILSVRC2012_val_00028617.bin 224 224 +8397 ./prep_dataset/ILSVRC2012_val_00017378.bin 224 224 +8398 ./prep_dataset/ILSVRC2012_val_00006208.bin 224 224 +8399 ./prep_dataset/ILSVRC2012_val_00040780.bin 224 224 +8400 ./prep_dataset/ILSVRC2012_val_00022550.bin 224 224 +8401 ./prep_dataset/ILSVRC2012_val_00012922.bin 224 224 +8402 ./prep_dataset/ILSVRC2012_val_00030608.bin 224 224 +8403 ./prep_dataset/ILSVRC2012_val_00020990.bin 224 224 +8404 ./prep_dataset/ILSVRC2012_val_00015235.bin 224 224 +8405 ./prep_dataset/ILSVRC2012_val_00038880.bin 224 224 +8406 ./prep_dataset/ILSVRC2012_val_00026505.bin 224 224 +8407 ./prep_dataset/ILSVRC2012_val_00027470.bin 224 224 +8408 ./prep_dataset/ILSVRC2012_val_00034314.bin 224 224 +8409 ./prep_dataset/ILSVRC2012_val_00030890.bin 224 224 +8410 ./prep_dataset/ILSVRC2012_val_00032419.bin 224 224 +8411 ./prep_dataset/ILSVRC2012_val_00036379.bin 224 224 +8412 ./prep_dataset/ILSVRC2012_val_00049371.bin 224 224 +8413 ./prep_dataset/ILSVRC2012_val_00008635.bin 224 224 +8414 ./prep_dataset/ILSVRC2012_val_00014934.bin 224 224 +8415 ./prep_dataset/ILSVRC2012_val_00003079.bin 224 224 +8416 ./prep_dataset/ILSVRC2012_val_00027215.bin 224 224 +8417 ./prep_dataset/ILSVRC2012_val_00046157.bin 224 224 +8418 ./prep_dataset/ILSVRC2012_val_00048378.bin 224 224 +8419 ./prep_dataset/ILSVRC2012_val_00033820.bin 224 224 +8420 ./prep_dataset/ILSVRC2012_val_00018831.bin 224 224 +8421 ./prep_dataset/ILSVRC2012_val_00043699.bin 224 224 +8422 ./prep_dataset/ILSVRC2012_val_00018584.bin 224 224 +8423 ./prep_dataset/ILSVRC2012_val_00014339.bin 224 224 +8424 ./prep_dataset/ILSVRC2012_val_00012514.bin 224 224 +8425 ./prep_dataset/ILSVRC2012_val_00003137.bin 224 224 +8426 ./prep_dataset/ILSVRC2012_val_00032725.bin 224 224 +8427 ./prep_dataset/ILSVRC2012_val_00026306.bin 224 224 +8428 ./prep_dataset/ILSVRC2012_val_00038461.bin 224 224 +8429 ./prep_dataset/ILSVRC2012_val_00014595.bin 224 224 +8430 ./prep_dataset/ILSVRC2012_val_00014978.bin 224 224 +8431 ./prep_dataset/ILSVRC2012_val_00043427.bin 224 224 +8432 ./prep_dataset/ILSVRC2012_val_00001164.bin 224 224 +8433 ./prep_dataset/ILSVRC2012_val_00048695.bin 224 224 +8434 ./prep_dataset/ILSVRC2012_val_00025265.bin 224 224 +8435 ./prep_dataset/ILSVRC2012_val_00020844.bin 224 224 +8436 ./prep_dataset/ILSVRC2012_val_00030027.bin 224 224 +8437 ./prep_dataset/ILSVRC2012_val_00023518.bin 224 224 +8438 ./prep_dataset/ILSVRC2012_val_00008766.bin 224 224 +8439 ./prep_dataset/ILSVRC2012_val_00006801.bin 224 224 +8440 ./prep_dataset/ILSVRC2012_val_00022023.bin 224 224 +8441 ./prep_dataset/ILSVRC2012_val_00021751.bin 224 224 +8442 ./prep_dataset/ILSVRC2012_val_00036008.bin 224 224 +8443 ./prep_dataset/ILSVRC2012_val_00049877.bin 224 224 +8444 ./prep_dataset/ILSVRC2012_val_00030372.bin 224 224 +8445 ./prep_dataset/ILSVRC2012_val_00033193.bin 224 224 +8446 ./prep_dataset/ILSVRC2012_val_00039824.bin 224 224 +8447 ./prep_dataset/ILSVRC2012_val_00010714.bin 224 224 +8448 ./prep_dataset/ILSVRC2012_val_00046196.bin 224 224 +8449 ./prep_dataset/ILSVRC2012_val_00004863.bin 224 224 +8450 ./prep_dataset/ILSVRC2012_val_00010289.bin 224 224 +8451 ./prep_dataset/ILSVRC2012_val_00046481.bin 224 224 +8452 ./prep_dataset/ILSVRC2012_val_00043691.bin 224 224 +8453 ./prep_dataset/ILSVRC2012_val_00021120.bin 224 224 +8454 ./prep_dataset/ILSVRC2012_val_00027561.bin 224 224 +8455 ./prep_dataset/ILSVRC2012_val_00021291.bin 224 224 +8456 ./prep_dataset/ILSVRC2012_val_00012953.bin 224 224 +8457 ./prep_dataset/ILSVRC2012_val_00048625.bin 224 224 +8458 ./prep_dataset/ILSVRC2012_val_00029493.bin 224 224 +8459 ./prep_dataset/ILSVRC2012_val_00002945.bin 224 224 +8460 ./prep_dataset/ILSVRC2012_val_00013405.bin 224 224 +8461 ./prep_dataset/ILSVRC2012_val_00025420.bin 224 224 +8462 ./prep_dataset/ILSVRC2012_val_00003375.bin 224 224 +8463 ./prep_dataset/ILSVRC2012_val_00026699.bin 224 224 +8464 ./prep_dataset/ILSVRC2012_val_00038315.bin 224 224 +8465 ./prep_dataset/ILSVRC2012_val_00029693.bin 224 224 +8466 ./prep_dataset/ILSVRC2012_val_00000931.bin 224 224 +8467 ./prep_dataset/ILSVRC2012_val_00038382.bin 224 224 +8468 ./prep_dataset/ILSVRC2012_val_00000949.bin 224 224 +8469 ./prep_dataset/ILSVRC2012_val_00036175.bin 224 224 +8470 ./prep_dataset/ILSVRC2012_val_00004282.bin 224 224 +8471 ./prep_dataset/ILSVRC2012_val_00042546.bin 224 224 +8472 ./prep_dataset/ILSVRC2012_val_00013938.bin 224 224 +8473 ./prep_dataset/ILSVRC2012_val_00032944.bin 224 224 +8474 ./prep_dataset/ILSVRC2012_val_00012693.bin 224 224 +8475 ./prep_dataset/ILSVRC2012_val_00033790.bin 224 224 +8476 ./prep_dataset/ILSVRC2012_val_00031735.bin 224 224 +8477 ./prep_dataset/ILSVRC2012_val_00005265.bin 224 224 +8478 ./prep_dataset/ILSVRC2012_val_00000848.bin 224 224 +8479 ./prep_dataset/ILSVRC2012_val_00030465.bin 224 224 +8480 ./prep_dataset/ILSVRC2012_val_00035167.bin 224 224 +8481 ./prep_dataset/ILSVRC2012_val_00025734.bin 224 224 +8482 ./prep_dataset/ILSVRC2012_val_00027351.bin 224 224 +8483 ./prep_dataset/ILSVRC2012_val_00021423.bin 224 224 +8484 ./prep_dataset/ILSVRC2012_val_00026834.bin 224 224 +8485 ./prep_dataset/ILSVRC2012_val_00049254.bin 224 224 +8486 ./prep_dataset/ILSVRC2012_val_00011441.bin 224 224 +8487 ./prep_dataset/ILSVRC2012_val_00019406.bin 224 224 +8488 ./prep_dataset/ILSVRC2012_val_00036641.bin 224 224 +8489 ./prep_dataset/ILSVRC2012_val_00002096.bin 224 224 +8490 ./prep_dataset/ILSVRC2012_val_00004462.bin 224 224 +8491 ./prep_dataset/ILSVRC2012_val_00018820.bin 224 224 +8492 ./prep_dataset/ILSVRC2012_val_00002621.bin 224 224 +8493 ./prep_dataset/ILSVRC2012_val_00013359.bin 224 224 +8494 ./prep_dataset/ILSVRC2012_val_00007868.bin 224 224 +8495 ./prep_dataset/ILSVRC2012_val_00005914.bin 224 224 +8496 ./prep_dataset/ILSVRC2012_val_00040952.bin 224 224 +8497 ./prep_dataset/ILSVRC2012_val_00031648.bin 224 224 +8498 ./prep_dataset/ILSVRC2012_val_00021390.bin 224 224 +8499 ./prep_dataset/ILSVRC2012_val_00040710.bin 224 224 +8500 ./prep_dataset/ILSVRC2012_val_00024519.bin 224 224 +8501 ./prep_dataset/ILSVRC2012_val_00031704.bin 224 224 +8502 ./prep_dataset/ILSVRC2012_val_00014167.bin 224 224 +8503 ./prep_dataset/ILSVRC2012_val_00035385.bin 224 224 +8504 ./prep_dataset/ILSVRC2012_val_00017818.bin 224 224 +8505 ./prep_dataset/ILSVRC2012_val_00006474.bin 224 224 +8506 ./prep_dataset/ILSVRC2012_val_00042322.bin 224 224 +8507 ./prep_dataset/ILSVRC2012_val_00035659.bin 224 224 +8508 ./prep_dataset/ILSVRC2012_val_00021759.bin 224 224 +8509 ./prep_dataset/ILSVRC2012_val_00005249.bin 224 224 +8510 ./prep_dataset/ILSVRC2012_val_00030229.bin 224 224 +8511 ./prep_dataset/ILSVRC2012_val_00024917.bin 224 224 +8512 ./prep_dataset/ILSVRC2012_val_00024441.bin 224 224 +8513 ./prep_dataset/ILSVRC2012_val_00011736.bin 224 224 +8514 ./prep_dataset/ILSVRC2012_val_00014453.bin 224 224 +8515 ./prep_dataset/ILSVRC2012_val_00037169.bin 224 224 +8516 ./prep_dataset/ILSVRC2012_val_00028713.bin 224 224 +8517 ./prep_dataset/ILSVRC2012_val_00004526.bin 224 224 +8518 ./prep_dataset/ILSVRC2012_val_00024368.bin 224 224 +8519 ./prep_dataset/ILSVRC2012_val_00029327.bin 224 224 +8520 ./prep_dataset/ILSVRC2012_val_00016680.bin 224 224 +8521 ./prep_dataset/ILSVRC2012_val_00004151.bin 224 224 +8522 ./prep_dataset/ILSVRC2012_val_00001186.bin 224 224 +8523 ./prep_dataset/ILSVRC2012_val_00019971.bin 224 224 +8524 ./prep_dataset/ILSVRC2012_val_00041851.bin 224 224 +8525 ./prep_dataset/ILSVRC2012_val_00020584.bin 224 224 +8526 ./prep_dataset/ILSVRC2012_val_00015427.bin 224 224 +8527 ./prep_dataset/ILSVRC2012_val_00016791.bin 224 224 +8528 ./prep_dataset/ILSVRC2012_val_00007242.bin 224 224 +8529 ./prep_dataset/ILSVRC2012_val_00012923.bin 224 224 +8530 ./prep_dataset/ILSVRC2012_val_00048370.bin 224 224 +8531 ./prep_dataset/ILSVRC2012_val_00041318.bin 224 224 +8532 ./prep_dataset/ILSVRC2012_val_00022551.bin 224 224 +8533 ./prep_dataset/ILSVRC2012_val_00034037.bin 224 224 +8534 ./prep_dataset/ILSVRC2012_val_00027888.bin 224 224 +8535 ./prep_dataset/ILSVRC2012_val_00040762.bin 224 224 +8536 ./prep_dataset/ILSVRC2012_val_00048667.bin 224 224 +8537 ./prep_dataset/ILSVRC2012_val_00026228.bin 224 224 +8538 ./prep_dataset/ILSVRC2012_val_00008631.bin 224 224 +8539 ./prep_dataset/ILSVRC2012_val_00048041.bin 224 224 +8540 ./prep_dataset/ILSVRC2012_val_00001644.bin 224 224 +8541 ./prep_dataset/ILSVRC2012_val_00028313.bin 224 224 +8542 ./prep_dataset/ILSVRC2012_val_00037259.bin 224 224 +8543 ./prep_dataset/ILSVRC2012_val_00044187.bin 224 224 +8544 ./prep_dataset/ILSVRC2012_val_00040326.bin 224 224 +8545 ./prep_dataset/ILSVRC2012_val_00019411.bin 224 224 +8546 ./prep_dataset/ILSVRC2012_val_00027061.bin 224 224 +8547 ./prep_dataset/ILSVRC2012_val_00034531.bin 224 224 +8548 ./prep_dataset/ILSVRC2012_val_00022644.bin 224 224 +8549 ./prep_dataset/ILSVRC2012_val_00021109.bin 224 224 +8550 ./prep_dataset/ILSVRC2012_val_00007958.bin 224 224 +8551 ./prep_dataset/ILSVRC2012_val_00045339.bin 224 224 +8552 ./prep_dataset/ILSVRC2012_val_00027758.bin 224 224 +8553 ./prep_dataset/ILSVRC2012_val_00041674.bin 224 224 +8554 ./prep_dataset/ILSVRC2012_val_00046774.bin 224 224 +8555 ./prep_dataset/ILSVRC2012_val_00008679.bin 224 224 +8556 ./prep_dataset/ILSVRC2012_val_00018982.bin 224 224 +8557 ./prep_dataset/ILSVRC2012_val_00031312.bin 224 224 +8558 ./prep_dataset/ILSVRC2012_val_00049148.bin 224 224 +8559 ./prep_dataset/ILSVRC2012_val_00040392.bin 224 224 +8560 ./prep_dataset/ILSVRC2012_val_00041121.bin 224 224 +8561 ./prep_dataset/ILSVRC2012_val_00019141.bin 224 224 +8562 ./prep_dataset/ILSVRC2012_val_00047995.bin 224 224 +8563 ./prep_dataset/ILSVRC2012_val_00001753.bin 224 224 +8564 ./prep_dataset/ILSVRC2012_val_00009915.bin 224 224 +8565 ./prep_dataset/ILSVRC2012_val_00024333.bin 224 224 +8566 ./prep_dataset/ILSVRC2012_val_00024923.bin 224 224 +8567 ./prep_dataset/ILSVRC2012_val_00041302.bin 224 224 +8568 ./prep_dataset/ILSVRC2012_val_00011307.bin 224 224 +8569 ./prep_dataset/ILSVRC2012_val_00043003.bin 224 224 +8570 ./prep_dataset/ILSVRC2012_val_00017447.bin 224 224 +8571 ./prep_dataset/ILSVRC2012_val_00047563.bin 224 224 +8572 ./prep_dataset/ILSVRC2012_val_00034214.bin 224 224 +8573 ./prep_dataset/ILSVRC2012_val_00039303.bin 224 224 +8574 ./prep_dataset/ILSVRC2012_val_00020204.bin 224 224 +8575 ./prep_dataset/ILSVRC2012_val_00014591.bin 224 224 +8576 ./prep_dataset/ILSVRC2012_val_00031834.bin 224 224 +8577 ./prep_dataset/ILSVRC2012_val_00034450.bin 224 224 +8578 ./prep_dataset/ILSVRC2012_val_00005937.bin 224 224 +8579 ./prep_dataset/ILSVRC2012_val_00004216.bin 224 224 +8580 ./prep_dataset/ILSVRC2012_val_00006964.bin 224 224 +8581 ./prep_dataset/ILSVRC2012_val_00028374.bin 224 224 +8582 ./prep_dataset/ILSVRC2012_val_00000757.bin 224 224 +8583 ./prep_dataset/ILSVRC2012_val_00031585.bin 224 224 +8584 ./prep_dataset/ILSVRC2012_val_00013090.bin 224 224 +8585 ./prep_dataset/ILSVRC2012_val_00012454.bin 224 224 +8586 ./prep_dataset/ILSVRC2012_val_00028509.bin 224 224 +8587 ./prep_dataset/ILSVRC2012_val_00041207.bin 224 224 +8588 ./prep_dataset/ILSVRC2012_val_00046318.bin 224 224 +8589 ./prep_dataset/ILSVRC2012_val_00041553.bin 224 224 +8590 ./prep_dataset/ILSVRC2012_val_00015658.bin 224 224 +8591 ./prep_dataset/ILSVRC2012_val_00046987.bin 224 224 +8592 ./prep_dataset/ILSVRC2012_val_00018474.bin 224 224 +8593 ./prep_dataset/ILSVRC2012_val_00010841.bin 224 224 +8594 ./prep_dataset/ILSVRC2012_val_00020002.bin 224 224 +8595 ./prep_dataset/ILSVRC2012_val_00045978.bin 224 224 +8596 ./prep_dataset/ILSVRC2012_val_00033660.bin 224 224 +8597 ./prep_dataset/ILSVRC2012_val_00029948.bin 224 224 +8598 ./prep_dataset/ILSVRC2012_val_00021297.bin 224 224 +8599 ./prep_dataset/ILSVRC2012_val_00040821.bin 224 224 +8600 ./prep_dataset/ILSVRC2012_val_00028527.bin 224 224 +8601 ./prep_dataset/ILSVRC2012_val_00031450.bin 224 224 +8602 ./prep_dataset/ILSVRC2012_val_00012501.bin 224 224 +8603 ./prep_dataset/ILSVRC2012_val_00015265.bin 224 224 +8604 ./prep_dataset/ILSVRC2012_val_00001576.bin 224 224 +8605 ./prep_dataset/ILSVRC2012_val_00024609.bin 224 224 +8606 ./prep_dataset/ILSVRC2012_val_00034492.bin 224 224 +8607 ./prep_dataset/ILSVRC2012_val_00041143.bin 224 224 +8608 ./prep_dataset/ILSVRC2012_val_00035409.bin 224 224 +8609 ./prep_dataset/ILSVRC2012_val_00016365.bin 224 224 +8610 ./prep_dataset/ILSVRC2012_val_00022791.bin 224 224 +8611 ./prep_dataset/ILSVRC2012_val_00023655.bin 224 224 +8612 ./prep_dataset/ILSVRC2012_val_00007184.bin 224 224 +8613 ./prep_dataset/ILSVRC2012_val_00005650.bin 224 224 +8614 ./prep_dataset/ILSVRC2012_val_00031784.bin 224 224 +8615 ./prep_dataset/ILSVRC2012_val_00047798.bin 224 224 +8616 ./prep_dataset/ILSVRC2012_val_00020013.bin 224 224 +8617 ./prep_dataset/ILSVRC2012_val_00015681.bin 224 224 +8618 ./prep_dataset/ILSVRC2012_val_00019811.bin 224 224 +8619 ./prep_dataset/ILSVRC2012_val_00044234.bin 224 224 +8620 ./prep_dataset/ILSVRC2012_val_00017913.bin 224 224 +8621 ./prep_dataset/ILSVRC2012_val_00018626.bin 224 224 +8622 ./prep_dataset/ILSVRC2012_val_00044887.bin 224 224 +8623 ./prep_dataset/ILSVRC2012_val_00008440.bin 224 224 +8624 ./prep_dataset/ILSVRC2012_val_00048367.bin 224 224 +8625 ./prep_dataset/ILSVRC2012_val_00041772.bin 224 224 +8626 ./prep_dataset/ILSVRC2012_val_00042556.bin 224 224 +8627 ./prep_dataset/ILSVRC2012_val_00011436.bin 224 224 +8628 ./prep_dataset/ILSVRC2012_val_00004386.bin 224 224 +8629 ./prep_dataset/ILSVRC2012_val_00001398.bin 224 224 +8630 ./prep_dataset/ILSVRC2012_val_00019039.bin 224 224 +8631 ./prep_dataset/ILSVRC2012_val_00016056.bin 224 224 +8632 ./prep_dataset/ILSVRC2012_val_00041306.bin 224 224 +8633 ./prep_dataset/ILSVRC2012_val_00029716.bin 224 224 +8634 ./prep_dataset/ILSVRC2012_val_00038698.bin 224 224 +8635 ./prep_dataset/ILSVRC2012_val_00023542.bin 224 224 +8636 ./prep_dataset/ILSVRC2012_val_00004870.bin 224 224 +8637 ./prep_dataset/ILSVRC2012_val_00011422.bin 224 224 +8638 ./prep_dataset/ILSVRC2012_val_00021498.bin 224 224 +8639 ./prep_dataset/ILSVRC2012_val_00014716.bin 224 224 +8640 ./prep_dataset/ILSVRC2012_val_00029104.bin 224 224 +8641 ./prep_dataset/ILSVRC2012_val_00022195.bin 224 224 +8642 ./prep_dataset/ILSVRC2012_val_00019643.bin 224 224 +8643 ./prep_dataset/ILSVRC2012_val_00039910.bin 224 224 +8644 ./prep_dataset/ILSVRC2012_val_00006179.bin 224 224 +8645 ./prep_dataset/ILSVRC2012_val_00018745.bin 224 224 +8646 ./prep_dataset/ILSVRC2012_val_00049678.bin 224 224 +8647 ./prep_dataset/ILSVRC2012_val_00021804.bin 224 224 +8648 ./prep_dataset/ILSVRC2012_val_00032018.bin 224 224 +8649 ./prep_dataset/ILSVRC2012_val_00031381.bin 224 224 +8650 ./prep_dataset/ILSVRC2012_val_00042822.bin 224 224 +8651 ./prep_dataset/ILSVRC2012_val_00011292.bin 224 224 +8652 ./prep_dataset/ILSVRC2012_val_00016229.bin 224 224 +8653 ./prep_dataset/ILSVRC2012_val_00042813.bin 224 224 +8654 ./prep_dataset/ILSVRC2012_val_00022118.bin 224 224 +8655 ./prep_dataset/ILSVRC2012_val_00004615.bin 224 224 +8656 ./prep_dataset/ILSVRC2012_val_00043195.bin 224 224 +8657 ./prep_dataset/ILSVRC2012_val_00036187.bin 224 224 +8658 ./prep_dataset/ILSVRC2012_val_00037151.bin 224 224 +8659 ./prep_dataset/ILSVRC2012_val_00009510.bin 224 224 +8660 ./prep_dataset/ILSVRC2012_val_00040345.bin 224 224 +8661 ./prep_dataset/ILSVRC2012_val_00025913.bin 224 224 +8662 ./prep_dataset/ILSVRC2012_val_00017727.bin 224 224 +8663 ./prep_dataset/ILSVRC2012_val_00013364.bin 224 224 +8664 ./prep_dataset/ILSVRC2012_val_00007465.bin 224 224 +8665 ./prep_dataset/ILSVRC2012_val_00047738.bin 224 224 +8666 ./prep_dataset/ILSVRC2012_val_00042945.bin 224 224 +8667 ./prep_dataset/ILSVRC2012_val_00026183.bin 224 224 +8668 ./prep_dataset/ILSVRC2012_val_00016977.bin 224 224 +8669 ./prep_dataset/ILSVRC2012_val_00020345.bin 224 224 +8670 ./prep_dataset/ILSVRC2012_val_00019655.bin 224 224 +8671 ./prep_dataset/ILSVRC2012_val_00009359.bin 224 224 +8672 ./prep_dataset/ILSVRC2012_val_00007095.bin 224 224 +8673 ./prep_dataset/ILSVRC2012_val_00038168.bin 224 224 +8674 ./prep_dataset/ILSVRC2012_val_00037012.bin 224 224 +8675 ./prep_dataset/ILSVRC2012_val_00045258.bin 224 224 +8676 ./prep_dataset/ILSVRC2012_val_00026736.bin 224 224 +8677 ./prep_dataset/ILSVRC2012_val_00003150.bin 224 224 +8678 ./prep_dataset/ILSVRC2012_val_00021078.bin 224 224 +8679 ./prep_dataset/ILSVRC2012_val_00015791.bin 224 224 +8680 ./prep_dataset/ILSVRC2012_val_00037716.bin 224 224 +8681 ./prep_dataset/ILSVRC2012_val_00029425.bin 224 224 +8682 ./prep_dataset/ILSVRC2012_val_00012376.bin 224 224 +8683 ./prep_dataset/ILSVRC2012_val_00023269.bin 224 224 +8684 ./prep_dataset/ILSVRC2012_val_00022321.bin 224 224 +8685 ./prep_dataset/ILSVRC2012_val_00010729.bin 224 224 +8686 ./prep_dataset/ILSVRC2012_val_00008947.bin 224 224 +8687 ./prep_dataset/ILSVRC2012_val_00005376.bin 224 224 +8688 ./prep_dataset/ILSVRC2012_val_00044484.bin 224 224 +8689 ./prep_dataset/ILSVRC2012_val_00048585.bin 224 224 +8690 ./prep_dataset/ILSVRC2012_val_00000202.bin 224 224 +8691 ./prep_dataset/ILSVRC2012_val_00019827.bin 224 224 +8692 ./prep_dataset/ILSVRC2012_val_00038073.bin 224 224 +8693 ./prep_dataset/ILSVRC2012_val_00013369.bin 224 224 +8694 ./prep_dataset/ILSVRC2012_val_00007780.bin 224 224 +8695 ./prep_dataset/ILSVRC2012_val_00002912.bin 224 224 +8696 ./prep_dataset/ILSVRC2012_val_00024224.bin 224 224 +8697 ./prep_dataset/ILSVRC2012_val_00038947.bin 224 224 +8698 ./prep_dataset/ILSVRC2012_val_00040951.bin 224 224 +8699 ./prep_dataset/ILSVRC2012_val_00042213.bin 224 224 +8700 ./prep_dataset/ILSVRC2012_val_00004503.bin 224 224 +8701 ./prep_dataset/ILSVRC2012_val_00022525.bin 224 224 +8702 ./prep_dataset/ILSVRC2012_val_00012266.bin 224 224 +8703 ./prep_dataset/ILSVRC2012_val_00015622.bin 224 224 +8704 ./prep_dataset/ILSVRC2012_val_00028074.bin 224 224 +8705 ./prep_dataset/ILSVRC2012_val_00034105.bin 224 224 +8706 ./prep_dataset/ILSVRC2012_val_00007616.bin 224 224 +8707 ./prep_dataset/ILSVRC2012_val_00031234.bin 224 224 +8708 ./prep_dataset/ILSVRC2012_val_00015082.bin 224 224 +8709 ./prep_dataset/ILSVRC2012_val_00025270.bin 224 224 +8710 ./prep_dataset/ILSVRC2012_val_00016017.bin 224 224 +8711 ./prep_dataset/ILSVRC2012_val_00036426.bin 224 224 +8712 ./prep_dataset/ILSVRC2012_val_00025105.bin 224 224 +8713 ./prep_dataset/ILSVRC2012_val_00040877.bin 224 224 +8714 ./prep_dataset/ILSVRC2012_val_00048293.bin 224 224 +8715 ./prep_dataset/ILSVRC2012_val_00004473.bin 224 224 +8716 ./prep_dataset/ILSVRC2012_val_00003588.bin 224 224 +8717 ./prep_dataset/ILSVRC2012_val_00049197.bin 224 224 +8718 ./prep_dataset/ILSVRC2012_val_00034672.bin 224 224 +8719 ./prep_dataset/ILSVRC2012_val_00015465.bin 224 224 +8720 ./prep_dataset/ILSVRC2012_val_00021185.bin 224 224 +8721 ./prep_dataset/ILSVRC2012_val_00035824.bin 224 224 +8722 ./prep_dataset/ILSVRC2012_val_00004210.bin 224 224 +8723 ./prep_dataset/ILSVRC2012_val_00025004.bin 224 224 +8724 ./prep_dataset/ILSVRC2012_val_00030872.bin 224 224 +8725 ./prep_dataset/ILSVRC2012_val_00013859.bin 224 224 +8726 ./prep_dataset/ILSVRC2012_val_00001099.bin 224 224 +8727 ./prep_dataset/ILSVRC2012_val_00018667.bin 224 224 +8728 ./prep_dataset/ILSVRC2012_val_00036583.bin 224 224 +8729 ./prep_dataset/ILSVRC2012_val_00032646.bin 224 224 +8730 ./prep_dataset/ILSVRC2012_val_00037276.bin 224 224 +8731 ./prep_dataset/ILSVRC2012_val_00045510.bin 224 224 +8732 ./prep_dataset/ILSVRC2012_val_00049009.bin 224 224 +8733 ./prep_dataset/ILSVRC2012_val_00025794.bin 224 224 +8734 ./prep_dataset/ILSVRC2012_val_00020210.bin 224 224 +8735 ./prep_dataset/ILSVRC2012_val_00037834.bin 224 224 +8736 ./prep_dataset/ILSVRC2012_val_00046045.bin 224 224 +8737 ./prep_dataset/ILSVRC2012_val_00001024.bin 224 224 +8738 ./prep_dataset/ILSVRC2012_val_00039366.bin 224 224 +8739 ./prep_dataset/ILSVRC2012_val_00021585.bin 224 224 +8740 ./prep_dataset/ILSVRC2012_val_00032000.bin 224 224 +8741 ./prep_dataset/ILSVRC2012_val_00025716.bin 224 224 +8742 ./prep_dataset/ILSVRC2012_val_00004536.bin 224 224 +8743 ./prep_dataset/ILSVRC2012_val_00032511.bin 224 224 +8744 ./prep_dataset/ILSVRC2012_val_00008133.bin 224 224 +8745 ./prep_dataset/ILSVRC2012_val_00010351.bin 224 224 +8746 ./prep_dataset/ILSVRC2012_val_00019969.bin 224 224 +8747 ./prep_dataset/ILSVRC2012_val_00027338.bin 224 224 +8748 ./prep_dataset/ILSVRC2012_val_00005583.bin 224 224 +8749 ./prep_dataset/ILSVRC2012_val_00036922.bin 224 224 +8750 ./prep_dataset/ILSVRC2012_val_00024934.bin 224 224 +8751 ./prep_dataset/ILSVRC2012_val_00001031.bin 224 224 +8752 ./prep_dataset/ILSVRC2012_val_00009786.bin 224 224 +8753 ./prep_dataset/ILSVRC2012_val_00020218.bin 224 224 +8754 ./prep_dataset/ILSVRC2012_val_00025272.bin 224 224 +8755 ./prep_dataset/ILSVRC2012_val_00017213.bin 224 224 +8756 ./prep_dataset/ILSVRC2012_val_00000021.bin 224 224 +8757 ./prep_dataset/ILSVRC2012_val_00023714.bin 224 224 +8758 ./prep_dataset/ILSVRC2012_val_00031990.bin 224 224 +8759 ./prep_dataset/ILSVRC2012_val_00048658.bin 224 224 +8760 ./prep_dataset/ILSVRC2012_val_00003128.bin 224 224 +8761 ./prep_dataset/ILSVRC2012_val_00030329.bin 224 224 +8762 ./prep_dataset/ILSVRC2012_val_00028646.bin 224 224 +8763 ./prep_dataset/ILSVRC2012_val_00049096.bin 224 224 +8764 ./prep_dataset/ILSVRC2012_val_00024025.bin 224 224 +8765 ./prep_dataset/ILSVRC2012_val_00025070.bin 224 224 +8766 ./prep_dataset/ILSVRC2012_val_00016492.bin 224 224 +8767 ./prep_dataset/ILSVRC2012_val_00004836.bin 224 224 +8768 ./prep_dataset/ILSVRC2012_val_00039265.bin 224 224 +8769 ./prep_dataset/ILSVRC2012_val_00033881.bin 224 224 +8770 ./prep_dataset/ILSVRC2012_val_00049080.bin 224 224 +8771 ./prep_dataset/ILSVRC2012_val_00038423.bin 224 224 +8772 ./prep_dataset/ILSVRC2012_val_00023119.bin 224 224 +8773 ./prep_dataset/ILSVRC2012_val_00000604.bin 224 224 +8774 ./prep_dataset/ILSVRC2012_val_00008671.bin 224 224 +8775 ./prep_dataset/ILSVRC2012_val_00035056.bin 224 224 +8776 ./prep_dataset/ILSVRC2012_val_00002723.bin 224 224 +8777 ./prep_dataset/ILSVRC2012_val_00030251.bin 224 224 +8778 ./prep_dataset/ILSVRC2012_val_00018771.bin 224 224 +8779 ./prep_dataset/ILSVRC2012_val_00010232.bin 224 224 +8780 ./prep_dataset/ILSVRC2012_val_00004741.bin 224 224 +8781 ./prep_dataset/ILSVRC2012_val_00035471.bin 224 224 +8782 ./prep_dataset/ILSVRC2012_val_00038012.bin 224 224 +8783 ./prep_dataset/ILSVRC2012_val_00009290.bin 224 224 +8784 ./prep_dataset/ILSVRC2012_val_00001625.bin 224 224 +8785 ./prep_dataset/ILSVRC2012_val_00036243.bin 224 224 +8786 ./prep_dataset/ILSVRC2012_val_00029158.bin 224 224 +8787 ./prep_dataset/ILSVRC2012_val_00045714.bin 224 224 +8788 ./prep_dataset/ILSVRC2012_val_00018315.bin 224 224 +8789 ./prep_dataset/ILSVRC2012_val_00029076.bin 224 224 +8790 ./prep_dataset/ILSVRC2012_val_00013634.bin 224 224 +8791 ./prep_dataset/ILSVRC2012_val_00044656.bin 224 224 +8792 ./prep_dataset/ILSVRC2012_val_00022092.bin 224 224 +8793 ./prep_dataset/ILSVRC2012_val_00048396.bin 224 224 +8794 ./prep_dataset/ILSVRC2012_val_00006312.bin 224 224 +8795 ./prep_dataset/ILSVRC2012_val_00037828.bin 224 224 +8796 ./prep_dataset/ILSVRC2012_val_00031649.bin 224 224 +8797 ./prep_dataset/ILSVRC2012_val_00030714.bin 224 224 +8798 ./prep_dataset/ILSVRC2012_val_00013216.bin 224 224 +8799 ./prep_dataset/ILSVRC2012_val_00016199.bin 224 224 +8800 ./prep_dataset/ILSVRC2012_val_00035418.bin 224 224 +8801 ./prep_dataset/ILSVRC2012_val_00030474.bin 224 224 +8802 ./prep_dataset/ILSVRC2012_val_00047483.bin 224 224 +8803 ./prep_dataset/ILSVRC2012_val_00001721.bin 224 224 +8804 ./prep_dataset/ILSVRC2012_val_00024190.bin 224 224 +8805 ./prep_dataset/ILSVRC2012_val_00004958.bin 224 224 +8806 ./prep_dataset/ILSVRC2012_val_00044097.bin 224 224 +8807 ./prep_dataset/ILSVRC2012_val_00042117.bin 224 224 +8808 ./prep_dataset/ILSVRC2012_val_00038387.bin 224 224 +8809 ./prep_dataset/ILSVRC2012_val_00001351.bin 224 224 +8810 ./prep_dataset/ILSVRC2012_val_00012582.bin 224 224 +8811 ./prep_dataset/ILSVRC2012_val_00005708.bin 224 224 +8812 ./prep_dataset/ILSVRC2012_val_00032776.bin 224 224 +8813 ./prep_dataset/ILSVRC2012_val_00012263.bin 224 224 +8814 ./prep_dataset/ILSVRC2012_val_00024184.bin 224 224 +8815 ./prep_dataset/ILSVRC2012_val_00001364.bin 224 224 +8816 ./prep_dataset/ILSVRC2012_val_00015910.bin 224 224 +8817 ./prep_dataset/ILSVRC2012_val_00026571.bin 224 224 +8818 ./prep_dataset/ILSVRC2012_val_00011954.bin 224 224 +8819 ./prep_dataset/ILSVRC2012_val_00035917.bin 224 224 +8820 ./prep_dataset/ILSVRC2012_val_00048384.bin 224 224 +8821 ./prep_dataset/ILSVRC2012_val_00022198.bin 224 224 +8822 ./prep_dataset/ILSVRC2012_val_00048121.bin 224 224 +8823 ./prep_dataset/ILSVRC2012_val_00019598.bin 224 224 +8824 ./prep_dataset/ILSVRC2012_val_00005764.bin 224 224 +8825 ./prep_dataset/ILSVRC2012_val_00008339.bin 224 224 +8826 ./prep_dataset/ILSVRC2012_val_00010098.bin 224 224 +8827 ./prep_dataset/ILSVRC2012_val_00011832.bin 224 224 +8828 ./prep_dataset/ILSVRC2012_val_00038228.bin 224 224 +8829 ./prep_dataset/ILSVRC2012_val_00022611.bin 224 224 +8830 ./prep_dataset/ILSVRC2012_val_00032755.bin 224 224 +8831 ./prep_dataset/ILSVRC2012_val_00043860.bin 224 224 +8832 ./prep_dataset/ILSVRC2012_val_00000261.bin 224 224 +8833 ./prep_dataset/ILSVRC2012_val_00024265.bin 224 224 +8834 ./prep_dataset/ILSVRC2012_val_00039796.bin 224 224 +8835 ./prep_dataset/ILSVRC2012_val_00037045.bin 224 224 +8836 ./prep_dataset/ILSVRC2012_val_00002387.bin 224 224 +8837 ./prep_dataset/ILSVRC2012_val_00048657.bin 224 224 +8838 ./prep_dataset/ILSVRC2012_val_00015200.bin 224 224 +8839 ./prep_dataset/ILSVRC2012_val_00041491.bin 224 224 +8840 ./prep_dataset/ILSVRC2012_val_00018388.bin 224 224 +8841 ./prep_dataset/ILSVRC2012_val_00006060.bin 224 224 +8842 ./prep_dataset/ILSVRC2012_val_00016283.bin 224 224 +8843 ./prep_dataset/ILSVRC2012_val_00020428.bin 224 224 +8844 ./prep_dataset/ILSVRC2012_val_00039931.bin 224 224 +8845 ./prep_dataset/ILSVRC2012_val_00047792.bin 224 224 +8846 ./prep_dataset/ILSVRC2012_val_00032850.bin 224 224 +8847 ./prep_dataset/ILSVRC2012_val_00045941.bin 224 224 +8848 ./prep_dataset/ILSVRC2012_val_00036576.bin 224 224 +8849 ./prep_dataset/ILSVRC2012_val_00004619.bin 224 224 +8850 ./prep_dataset/ILSVRC2012_val_00020030.bin 224 224 +8851 ./prep_dataset/ILSVRC2012_val_00020383.bin 224 224 +8852 ./prep_dataset/ILSVRC2012_val_00030241.bin 224 224 +8853 ./prep_dataset/ILSVRC2012_val_00040586.bin 224 224 +8854 ./prep_dataset/ILSVRC2012_val_00044543.bin 224 224 +8855 ./prep_dataset/ILSVRC2012_val_00026507.bin 224 224 +8856 ./prep_dataset/ILSVRC2012_val_00014532.bin 224 224 +8857 ./prep_dataset/ILSVRC2012_val_00039321.bin 224 224 +8858 ./prep_dataset/ILSVRC2012_val_00029150.bin 224 224 +8859 ./prep_dataset/ILSVRC2012_val_00000523.bin 224 224 +8860 ./prep_dataset/ILSVRC2012_val_00032687.bin 224 224 +8861 ./prep_dataset/ILSVRC2012_val_00028473.bin 224 224 +8862 ./prep_dataset/ILSVRC2012_val_00001406.bin 224 224 +8863 ./prep_dataset/ILSVRC2012_val_00003083.bin 224 224 +8864 ./prep_dataset/ILSVRC2012_val_00013980.bin 224 224 +8865 ./prep_dataset/ILSVRC2012_val_00012004.bin 224 224 +8866 ./prep_dataset/ILSVRC2012_val_00015326.bin 224 224 +8867 ./prep_dataset/ILSVRC2012_val_00030807.bin 224 224 +8868 ./prep_dataset/ILSVRC2012_val_00037417.bin 224 224 +8869 ./prep_dataset/ILSVRC2012_val_00037592.bin 224 224 +8870 ./prep_dataset/ILSVRC2012_val_00002275.bin 224 224 +8871 ./prep_dataset/ILSVRC2012_val_00019864.bin 224 224 +8872 ./prep_dataset/ILSVRC2012_val_00001891.bin 224 224 +8873 ./prep_dataset/ILSVRC2012_val_00047001.bin 224 224 +8874 ./prep_dataset/ILSVRC2012_val_00005477.bin 224 224 +8875 ./prep_dataset/ILSVRC2012_val_00007092.bin 224 224 +8876 ./prep_dataset/ILSVRC2012_val_00026582.bin 224 224 +8877 ./prep_dataset/ILSVRC2012_val_00003308.bin 224 224 +8878 ./prep_dataset/ILSVRC2012_val_00036114.bin 224 224 +8879 ./prep_dataset/ILSVRC2012_val_00006475.bin 224 224 +8880 ./prep_dataset/ILSVRC2012_val_00024293.bin 224 224 +8881 ./prep_dataset/ILSVRC2012_val_00001189.bin 224 224 +8882 ./prep_dataset/ILSVRC2012_val_00012395.bin 224 224 +8883 ./prep_dataset/ILSVRC2012_val_00011002.bin 224 224 +8884 ./prep_dataset/ILSVRC2012_val_00004396.bin 224 224 +8885 ./prep_dataset/ILSVRC2012_val_00015944.bin 224 224 +8886 ./prep_dataset/ILSVRC2012_val_00031077.bin 224 224 +8887 ./prep_dataset/ILSVRC2012_val_00049732.bin 224 224 +8888 ./prep_dataset/ILSVRC2012_val_00008278.bin 224 224 +8889 ./prep_dataset/ILSVRC2012_val_00009543.bin 224 224 +8890 ./prep_dataset/ILSVRC2012_val_00027039.bin 224 224 +8891 ./prep_dataset/ILSVRC2012_val_00003132.bin 224 224 +8892 ./prep_dataset/ILSVRC2012_val_00018480.bin 224 224 +8893 ./prep_dataset/ILSVRC2012_val_00003393.bin 224 224 +8894 ./prep_dataset/ILSVRC2012_val_00024220.bin 224 224 +8895 ./prep_dataset/ILSVRC2012_val_00014498.bin 224 224 +8896 ./prep_dataset/ILSVRC2012_val_00017285.bin 224 224 +8897 ./prep_dataset/ILSVRC2012_val_00024516.bin 224 224 +8898 ./prep_dataset/ILSVRC2012_val_00002815.bin 224 224 +8899 ./prep_dataset/ILSVRC2012_val_00046969.bin 224 224 +8900 ./prep_dataset/ILSVRC2012_val_00032008.bin 224 224 +8901 ./prep_dataset/ILSVRC2012_val_00005462.bin 224 224 +8902 ./prep_dataset/ILSVRC2012_val_00002509.bin 224 224 +8903 ./prep_dataset/ILSVRC2012_val_00039235.bin 224 224 +8904 ./prep_dataset/ILSVRC2012_val_00005821.bin 224 224 +8905 ./prep_dataset/ILSVRC2012_val_00030738.bin 224 224 +8906 ./prep_dataset/ILSVRC2012_val_00042401.bin 224 224 +8907 ./prep_dataset/ILSVRC2012_val_00045887.bin 224 224 +8908 ./prep_dataset/ILSVRC2012_val_00007378.bin 224 224 +8909 ./prep_dataset/ILSVRC2012_val_00022496.bin 224 224 +8910 ./prep_dataset/ILSVRC2012_val_00003439.bin 224 224 +8911 ./prep_dataset/ILSVRC2012_val_00010706.bin 224 224 +8912 ./prep_dataset/ILSVRC2012_val_00037494.bin 224 224 +8913 ./prep_dataset/ILSVRC2012_val_00042153.bin 224 224 +8914 ./prep_dataset/ILSVRC2012_val_00028632.bin 224 224 +8915 ./prep_dataset/ILSVRC2012_val_00022461.bin 224 224 +8916 ./prep_dataset/ILSVRC2012_val_00013133.bin 224 224 +8917 ./prep_dataset/ILSVRC2012_val_00031928.bin 224 224 +8918 ./prep_dataset/ILSVRC2012_val_00000155.bin 224 224 +8919 ./prep_dataset/ILSVRC2012_val_00037306.bin 224 224 +8920 ./prep_dataset/ILSVRC2012_val_00021000.bin 224 224 +8921 ./prep_dataset/ILSVRC2012_val_00031137.bin 224 224 +8922 ./prep_dataset/ILSVRC2012_val_00021992.bin 224 224 +8923 ./prep_dataset/ILSVRC2012_val_00003389.bin 224 224 +8924 ./prep_dataset/ILSVRC2012_val_00004609.bin 224 224 +8925 ./prep_dataset/ILSVRC2012_val_00017313.bin 224 224 +8926 ./prep_dataset/ILSVRC2012_val_00013388.bin 224 224 +8927 ./prep_dataset/ILSVRC2012_val_00005216.bin 224 224 +8928 ./prep_dataset/ILSVRC2012_val_00014751.bin 224 224 +8929 ./prep_dataset/ILSVRC2012_val_00034212.bin 224 224 +8930 ./prep_dataset/ILSVRC2012_val_00035354.bin 224 224 +8931 ./prep_dataset/ILSVRC2012_val_00016671.bin 224 224 +8932 ./prep_dataset/ILSVRC2012_val_00035183.bin 224 224 +8933 ./prep_dataset/ILSVRC2012_val_00036194.bin 224 224 +8934 ./prep_dataset/ILSVRC2012_val_00013992.bin 224 224 +8935 ./prep_dataset/ILSVRC2012_val_00024559.bin 224 224 +8936 ./prep_dataset/ILSVRC2012_val_00022818.bin 224 224 +8937 ./prep_dataset/ILSVRC2012_val_00033118.bin 224 224 +8938 ./prep_dataset/ILSVRC2012_val_00032938.bin 224 224 +8939 ./prep_dataset/ILSVRC2012_val_00042581.bin 224 224 +8940 ./prep_dataset/ILSVRC2012_val_00027833.bin 224 224 +8941 ./prep_dataset/ILSVRC2012_val_00022896.bin 224 224 +8942 ./prep_dataset/ILSVRC2012_val_00048139.bin 224 224 +8943 ./prep_dataset/ILSVRC2012_val_00013754.bin 224 224 +8944 ./prep_dataset/ILSVRC2012_val_00038395.bin 224 224 +8945 ./prep_dataset/ILSVRC2012_val_00010366.bin 224 224 +8946 ./prep_dataset/ILSVRC2012_val_00009512.bin 224 224 +8947 ./prep_dataset/ILSVRC2012_val_00034971.bin 224 224 +8948 ./prep_dataset/ILSVRC2012_val_00006250.bin 224 224 +8949 ./prep_dataset/ILSVRC2012_val_00000609.bin 224 224 +8950 ./prep_dataset/ILSVRC2012_val_00044611.bin 224 224 +8951 ./prep_dataset/ILSVRC2012_val_00028329.bin 224 224 +8952 ./prep_dataset/ILSVRC2012_val_00003321.bin 224 224 +8953 ./prep_dataset/ILSVRC2012_val_00007194.bin 224 224 +8954 ./prep_dataset/ILSVRC2012_val_00009029.bin 224 224 +8955 ./prep_dataset/ILSVRC2012_val_00036820.bin 224 224 +8956 ./prep_dataset/ILSVRC2012_val_00000417.bin 224 224 +8957 ./prep_dataset/ILSVRC2012_val_00024936.bin 224 224 +8958 ./prep_dataset/ILSVRC2012_val_00022270.bin 224 224 +8959 ./prep_dataset/ILSVRC2012_val_00006595.bin 224 224 +8960 ./prep_dataset/ILSVRC2012_val_00024753.bin 224 224 +8961 ./prep_dataset/ILSVRC2012_val_00011591.bin 224 224 +8962 ./prep_dataset/ILSVRC2012_val_00036247.bin 224 224 +8963 ./prep_dataset/ILSVRC2012_val_00000768.bin 224 224 +8964 ./prep_dataset/ILSVRC2012_val_00005061.bin 224 224 +8965 ./prep_dataset/ILSVRC2012_val_00024474.bin 224 224 +8966 ./prep_dataset/ILSVRC2012_val_00015607.bin 224 224 +8967 ./prep_dataset/ILSVRC2012_val_00014055.bin 224 224 +8968 ./prep_dataset/ILSVRC2012_val_00004089.bin 224 224 +8969 ./prep_dataset/ILSVRC2012_val_00006500.bin 224 224 +8970 ./prep_dataset/ILSVRC2012_val_00046031.bin 224 224 +8971 ./prep_dataset/ILSVRC2012_val_00042015.bin 224 224 +8972 ./prep_dataset/ILSVRC2012_val_00044649.bin 224 224 +8973 ./prep_dataset/ILSVRC2012_val_00042443.bin 224 224 +8974 ./prep_dataset/ILSVRC2012_val_00036581.bin 224 224 +8975 ./prep_dataset/ILSVRC2012_val_00021653.bin 224 224 +8976 ./prep_dataset/ILSVRC2012_val_00047401.bin 224 224 +8977 ./prep_dataset/ILSVRC2012_val_00001125.bin 224 224 +8978 ./prep_dataset/ILSVRC2012_val_00000559.bin 224 224 +8979 ./prep_dataset/ILSVRC2012_val_00011239.bin 224 224 +8980 ./prep_dataset/ILSVRC2012_val_00012672.bin 224 224 +8981 ./prep_dataset/ILSVRC2012_val_00006344.bin 224 224 +8982 ./prep_dataset/ILSVRC2012_val_00036819.bin 224 224 +8983 ./prep_dataset/ILSVRC2012_val_00020182.bin 224 224 +8984 ./prep_dataset/ILSVRC2012_val_00011660.bin 224 224 +8985 ./prep_dataset/ILSVRC2012_val_00005635.bin 224 224 +8986 ./prep_dataset/ILSVRC2012_val_00036631.bin 224 224 +8987 ./prep_dataset/ILSVRC2012_val_00041913.bin 224 224 +8988 ./prep_dataset/ILSVRC2012_val_00016434.bin 224 224 +8989 ./prep_dataset/ILSVRC2012_val_00045794.bin 224 224 +8990 ./prep_dataset/ILSVRC2012_val_00008012.bin 224 224 +8991 ./prep_dataset/ILSVRC2012_val_00030973.bin 224 224 +8992 ./prep_dataset/ILSVRC2012_val_00044476.bin 224 224 +8993 ./prep_dataset/ILSVRC2012_val_00001246.bin 224 224 +8994 ./prep_dataset/ILSVRC2012_val_00013682.bin 224 224 +8995 ./prep_dataset/ILSVRC2012_val_00027342.bin 224 224 +8996 ./prep_dataset/ILSVRC2012_val_00035681.bin 224 224 +8997 ./prep_dataset/ILSVRC2012_val_00001543.bin 224 224 +8998 ./prep_dataset/ILSVRC2012_val_00003957.bin 224 224 +8999 ./prep_dataset/ILSVRC2012_val_00040707.bin 224 224 +9000 ./prep_dataset/ILSVRC2012_val_00015057.bin 224 224 +9001 ./prep_dataset/ILSVRC2012_val_00013344.bin 224 224 +9002 ./prep_dataset/ILSVRC2012_val_00004121.bin 224 224 +9003 ./prep_dataset/ILSVRC2012_val_00042508.bin 224 224 +9004 ./prep_dataset/ILSVRC2012_val_00030919.bin 224 224 +9005 ./prep_dataset/ILSVRC2012_val_00047115.bin 224 224 +9006 ./prep_dataset/ILSVRC2012_val_00021046.bin 224 224 +9007 ./prep_dataset/ILSVRC2012_val_00028466.bin 224 224 +9008 ./prep_dataset/ILSVRC2012_val_00004391.bin 224 224 +9009 ./prep_dataset/ILSVRC2012_val_00004549.bin 224 224 +9010 ./prep_dataset/ILSVRC2012_val_00023679.bin 224 224 +9011 ./prep_dataset/ILSVRC2012_val_00043154.bin 224 224 +9012 ./prep_dataset/ILSVRC2012_val_00006073.bin 224 224 +9013 ./prep_dataset/ILSVRC2012_val_00006690.bin 224 224 +9014 ./prep_dataset/ILSVRC2012_val_00044627.bin 224 224 +9015 ./prep_dataset/ILSVRC2012_val_00037044.bin 224 224 +9016 ./prep_dataset/ILSVRC2012_val_00023486.bin 224 224 +9017 ./prep_dataset/ILSVRC2012_val_00038743.bin 224 224 +9018 ./prep_dataset/ILSVRC2012_val_00045210.bin 224 224 +9019 ./prep_dataset/ILSVRC2012_val_00011236.bin 224 224 +9020 ./prep_dataset/ILSVRC2012_val_00047196.bin 224 224 +9021 ./prep_dataset/ILSVRC2012_val_00049184.bin 224 224 +9022 ./prep_dataset/ILSVRC2012_val_00007503.bin 224 224 +9023 ./prep_dataset/ILSVRC2012_val_00033390.bin 224 224 +9024 ./prep_dataset/ILSVRC2012_val_00014922.bin 224 224 +9025 ./prep_dataset/ILSVRC2012_val_00037771.bin 224 224 +9026 ./prep_dataset/ILSVRC2012_val_00000981.bin 224 224 +9027 ./prep_dataset/ILSVRC2012_val_00046858.bin 224 224 +9028 ./prep_dataset/ILSVRC2012_val_00044487.bin 224 224 +9029 ./prep_dataset/ILSVRC2012_val_00034611.bin 224 224 +9030 ./prep_dataset/ILSVRC2012_val_00042333.bin 224 224 +9031 ./prep_dataset/ILSVRC2012_val_00025995.bin 224 224 +9032 ./prep_dataset/ILSVRC2012_val_00006244.bin 224 224 +9033 ./prep_dataset/ILSVRC2012_val_00018045.bin 224 224 +9034 ./prep_dataset/ILSVRC2012_val_00046560.bin 224 224 +9035 ./prep_dataset/ILSVRC2012_val_00041316.bin 224 224 +9036 ./prep_dataset/ILSVRC2012_val_00041688.bin 224 224 +9037 ./prep_dataset/ILSVRC2012_val_00032442.bin 224 224 +9038 ./prep_dataset/ILSVRC2012_val_00016003.bin 224 224 +9039 ./prep_dataset/ILSVRC2012_val_00009447.bin 224 224 +9040 ./prep_dataset/ILSVRC2012_val_00045839.bin 224 224 +9041 ./prep_dataset/ILSVRC2012_val_00043026.bin 224 224 +9042 ./prep_dataset/ILSVRC2012_val_00047891.bin 224 224 +9043 ./prep_dataset/ILSVRC2012_val_00005161.bin 224 224 +9044 ./prep_dataset/ILSVRC2012_val_00000718.bin 224 224 +9045 ./prep_dataset/ILSVRC2012_val_00009971.bin 224 224 +9046 ./prep_dataset/ILSVRC2012_val_00022211.bin 224 224 +9047 ./prep_dataset/ILSVRC2012_val_00004786.bin 224 224 +9048 ./prep_dataset/ILSVRC2012_val_00040715.bin 224 224 +9049 ./prep_dataset/ILSVRC2012_val_00041359.bin 224 224 +9050 ./prep_dataset/ILSVRC2012_val_00012397.bin 224 224 +9051 ./prep_dataset/ILSVRC2012_val_00007521.bin 224 224 +9052 ./prep_dataset/ILSVRC2012_val_00031817.bin 224 224 +9053 ./prep_dataset/ILSVRC2012_val_00032212.bin 224 224 +9054 ./prep_dataset/ILSVRC2012_val_00012516.bin 224 224 +9055 ./prep_dataset/ILSVRC2012_val_00033645.bin 224 224 +9056 ./prep_dataset/ILSVRC2012_val_00034443.bin 224 224 +9057 ./prep_dataset/ILSVRC2012_val_00006621.bin 224 224 +9058 ./prep_dataset/ILSVRC2012_val_00007035.bin 224 224 +9059 ./prep_dataset/ILSVRC2012_val_00012792.bin 224 224 +9060 ./prep_dataset/ILSVRC2012_val_00042505.bin 224 224 +9061 ./prep_dataset/ILSVRC2012_val_00032625.bin 224 224 +9062 ./prep_dataset/ILSVRC2012_val_00028177.bin 224 224 +9063 ./prep_dataset/ILSVRC2012_val_00045899.bin 224 224 +9064 ./prep_dataset/ILSVRC2012_val_00030850.bin 224 224 +9065 ./prep_dataset/ILSVRC2012_val_00000645.bin 224 224 +9066 ./prep_dataset/ILSVRC2012_val_00007668.bin 224 224 +9067 ./prep_dataset/ILSVRC2012_val_00028484.bin 224 224 +9068 ./prep_dataset/ILSVRC2012_val_00005752.bin 224 224 +9069 ./prep_dataset/ILSVRC2012_val_00026447.bin 224 224 +9070 ./prep_dataset/ILSVRC2012_val_00013354.bin 224 224 +9071 ./prep_dataset/ILSVRC2012_val_00028120.bin 224 224 +9072 ./prep_dataset/ILSVRC2012_val_00027868.bin 224 224 +9073 ./prep_dataset/ILSVRC2012_val_00002250.bin 224 224 +9074 ./prep_dataset/ILSVRC2012_val_00001707.bin 224 224 +9075 ./prep_dataset/ILSVRC2012_val_00029300.bin 224 224 +9076 ./prep_dataset/ILSVRC2012_val_00033778.bin 224 224 +9077 ./prep_dataset/ILSVRC2012_val_00022783.bin 224 224 +9078 ./prep_dataset/ILSVRC2012_val_00039445.bin 224 224 +9079 ./prep_dataset/ILSVRC2012_val_00025095.bin 224 224 +9080 ./prep_dataset/ILSVRC2012_val_00047729.bin 224 224 +9081 ./prep_dataset/ILSVRC2012_val_00000528.bin 224 224 +9082 ./prep_dataset/ILSVRC2012_val_00024296.bin 224 224 +9083 ./prep_dataset/ILSVRC2012_val_00007788.bin 224 224 +9084 ./prep_dataset/ILSVRC2012_val_00014356.bin 224 224 +9085 ./prep_dataset/ILSVRC2012_val_00031124.bin 224 224 +9086 ./prep_dataset/ILSVRC2012_val_00049619.bin 224 224 +9087 ./prep_dataset/ILSVRC2012_val_00038402.bin 224 224 +9088 ./prep_dataset/ILSVRC2012_val_00012992.bin 224 224 +9089 ./prep_dataset/ILSVRC2012_val_00021422.bin 224 224 +9090 ./prep_dataset/ILSVRC2012_val_00031676.bin 224 224 +9091 ./prep_dataset/ILSVRC2012_val_00012309.bin 224 224 +9092 ./prep_dataset/ILSVRC2012_val_00015797.bin 224 224 +9093 ./prep_dataset/ILSVRC2012_val_00021821.bin 224 224 +9094 ./prep_dataset/ILSVRC2012_val_00042960.bin 224 224 +9095 ./prep_dataset/ILSVRC2012_val_00046269.bin 224 224 +9096 ./prep_dataset/ILSVRC2012_val_00005371.bin 224 224 +9097 ./prep_dataset/ILSVRC2012_val_00030322.bin 224 224 +9098 ./prep_dataset/ILSVRC2012_val_00040606.bin 224 224 +9099 ./prep_dataset/ILSVRC2012_val_00014151.bin 224 224 +9100 ./prep_dataset/ILSVRC2012_val_00017366.bin 224 224 +9101 ./prep_dataset/ILSVRC2012_val_00047245.bin 224 224 +9102 ./prep_dataset/ILSVRC2012_val_00035585.bin 224 224 +9103 ./prep_dataset/ILSVRC2012_val_00034778.bin 224 224 +9104 ./prep_dataset/ILSVRC2012_val_00016312.bin 224 224 +9105 ./prep_dataset/ILSVRC2012_val_00046391.bin 224 224 +9106 ./prep_dataset/ILSVRC2012_val_00036468.bin 224 224 +9107 ./prep_dataset/ILSVRC2012_val_00006947.bin 224 224 +9108 ./prep_dataset/ILSVRC2012_val_00004571.bin 224 224 +9109 ./prep_dataset/ILSVRC2012_val_00016512.bin 224 224 +9110 ./prep_dataset/ILSVRC2012_val_00006140.bin 224 224 +9111 ./prep_dataset/ILSVRC2012_val_00030375.bin 224 224 +9112 ./prep_dataset/ILSVRC2012_val_00031893.bin 224 224 +9113 ./prep_dataset/ILSVRC2012_val_00041680.bin 224 224 +9114 ./prep_dataset/ILSVRC2012_val_00035963.bin 224 224 +9115 ./prep_dataset/ILSVRC2012_val_00010788.bin 224 224 +9116 ./prep_dataset/ILSVRC2012_val_00034036.bin 224 224 +9117 ./prep_dataset/ILSVRC2012_val_00009964.bin 224 224 +9118 ./prep_dataset/ILSVRC2012_val_00013844.bin 224 224 +9119 ./prep_dataset/ILSVRC2012_val_00022272.bin 224 224 +9120 ./prep_dataset/ILSVRC2012_val_00018903.bin 224 224 +9121 ./prep_dataset/ILSVRC2012_val_00034176.bin 224 224 +9122 ./prep_dataset/ILSVRC2012_val_00027535.bin 224 224 +9123 ./prep_dataset/ILSVRC2012_val_00019058.bin 224 224 +9124 ./prep_dataset/ILSVRC2012_val_00038603.bin 224 224 +9125 ./prep_dataset/ILSVRC2012_val_00022883.bin 224 224 +9126 ./prep_dataset/ILSVRC2012_val_00008433.bin 224 224 +9127 ./prep_dataset/ILSVRC2012_val_00015545.bin 224 224 +9128 ./prep_dataset/ILSVRC2012_val_00029964.bin 224 224 +9129 ./prep_dataset/ILSVRC2012_val_00016308.bin 224 224 +9130 ./prep_dataset/ILSVRC2012_val_00016549.bin 224 224 +9131 ./prep_dataset/ILSVRC2012_val_00023559.bin 224 224 +9132 ./prep_dataset/ILSVRC2012_val_00041081.bin 224 224 +9133 ./prep_dataset/ILSVRC2012_val_00010571.bin 224 224 +9134 ./prep_dataset/ILSVRC2012_val_00036077.bin 224 224 +9135 ./prep_dataset/ILSVRC2012_val_00040583.bin 224 224 +9136 ./prep_dataset/ILSVRC2012_val_00038904.bin 224 224 +9137 ./prep_dataset/ILSVRC2012_val_00044206.bin 224 224 +9138 ./prep_dataset/ILSVRC2012_val_00042805.bin 224 224 +9139 ./prep_dataset/ILSVRC2012_val_00024367.bin 224 224 +9140 ./prep_dataset/ILSVRC2012_val_00043134.bin 224 224 +9141 ./prep_dataset/ILSVRC2012_val_00035110.bin 224 224 +9142 ./prep_dataset/ILSVRC2012_val_00001775.bin 224 224 +9143 ./prep_dataset/ILSVRC2012_val_00003583.bin 224 224 +9144 ./prep_dataset/ILSVRC2012_val_00019556.bin 224 224 +9145 ./prep_dataset/ILSVRC2012_val_00048232.bin 224 224 +9146 ./prep_dataset/ILSVRC2012_val_00046112.bin 224 224 +9147 ./prep_dataset/ILSVRC2012_val_00022342.bin 224 224 +9148 ./prep_dataset/ILSVRC2012_val_00006233.bin 224 224 +9149 ./prep_dataset/ILSVRC2012_val_00035573.bin 224 224 +9150 ./prep_dataset/ILSVRC2012_val_00020035.bin 224 224 +9151 ./prep_dataset/ILSVRC2012_val_00023746.bin 224 224 +9152 ./prep_dataset/ILSVRC2012_val_00002227.bin 224 224 +9153 ./prep_dataset/ILSVRC2012_val_00045552.bin 224 224 +9154 ./prep_dataset/ILSVRC2012_val_00047849.bin 224 224 +9155 ./prep_dataset/ILSVRC2012_val_00044854.bin 224 224 +9156 ./prep_dataset/ILSVRC2012_val_00034240.bin 224 224 +9157 ./prep_dataset/ILSVRC2012_val_00032988.bin 224 224 +9158 ./prep_dataset/ILSVRC2012_val_00025725.bin 224 224 +9159 ./prep_dataset/ILSVRC2012_val_00021492.bin 224 224 +9160 ./prep_dataset/ILSVRC2012_val_00029804.bin 224 224 +9161 ./prep_dataset/ILSVRC2012_val_00035653.bin 224 224 +9162 ./prep_dataset/ILSVRC2012_val_00019752.bin 224 224 +9163 ./prep_dataset/ILSVRC2012_val_00025409.bin 224 224 +9164 ./prep_dataset/ILSVRC2012_val_00049658.bin 224 224 +9165 ./prep_dataset/ILSVRC2012_val_00024863.bin 224 224 +9166 ./prep_dataset/ILSVRC2012_val_00034868.bin 224 224 +9167 ./prep_dataset/ILSVRC2012_val_00044557.bin 224 224 +9168 ./prep_dataset/ILSVRC2012_val_00039187.bin 224 224 +9169 ./prep_dataset/ILSVRC2012_val_00037024.bin 224 224 +9170 ./prep_dataset/ILSVRC2012_val_00045780.bin 224 224 +9171 ./prep_dataset/ILSVRC2012_val_00000712.bin 224 224 +9172 ./prep_dataset/ILSVRC2012_val_00006280.bin 224 224 +9173 ./prep_dataset/ILSVRC2012_val_00027432.bin 224 224 +9174 ./prep_dataset/ILSVRC2012_val_00045017.bin 224 224 +9175 ./prep_dataset/ILSVRC2012_val_00014403.bin 224 224 +9176 ./prep_dataset/ILSVRC2012_val_00042995.bin 224 224 +9177 ./prep_dataset/ILSVRC2012_val_00023967.bin 224 224 +9178 ./prep_dataset/ILSVRC2012_val_00006934.bin 224 224 +9179 ./prep_dataset/ILSVRC2012_val_00002772.bin 224 224 +9180 ./prep_dataset/ILSVRC2012_val_00043351.bin 224 224 +9181 ./prep_dataset/ILSVRC2012_val_00036675.bin 224 224 +9182 ./prep_dataset/ILSVRC2012_val_00048480.bin 224 224 +9183 ./prep_dataset/ILSVRC2012_val_00012464.bin 224 224 +9184 ./prep_dataset/ILSVRC2012_val_00023260.bin 224 224 +9185 ./prep_dataset/ILSVRC2012_val_00025640.bin 224 224 +9186 ./prep_dataset/ILSVRC2012_val_00046327.bin 224 224 +9187 ./prep_dataset/ILSVRC2012_val_00031905.bin 224 224 +9188 ./prep_dataset/ILSVRC2012_val_00017325.bin 224 224 +9189 ./prep_dataset/ILSVRC2012_val_00026330.bin 224 224 +9190 ./prep_dataset/ILSVRC2012_val_00030958.bin 224 224 +9191 ./prep_dataset/ILSVRC2012_val_00043316.bin 224 224 +9192 ./prep_dataset/ILSVRC2012_val_00003577.bin 224 224 +9193 ./prep_dataset/ILSVRC2012_val_00024082.bin 224 224 +9194 ./prep_dataset/ILSVRC2012_val_00042789.bin 224 224 +9195 ./prep_dataset/ILSVRC2012_val_00011526.bin 224 224 +9196 ./prep_dataset/ILSVRC2012_val_00032109.bin 224 224 +9197 ./prep_dataset/ILSVRC2012_val_00032590.bin 224 224 +9198 ./prep_dataset/ILSVRC2012_val_00049981.bin 224 224 +9199 ./prep_dataset/ILSVRC2012_val_00041497.bin 224 224 +9200 ./prep_dataset/ILSVRC2012_val_00042136.bin 224 224 +9201 ./prep_dataset/ILSVRC2012_val_00012994.bin 224 224 +9202 ./prep_dataset/ILSVRC2012_val_00013557.bin 224 224 +9203 ./prep_dataset/ILSVRC2012_val_00033396.bin 224 224 +9204 ./prep_dataset/ILSVRC2012_val_00024743.bin 224 224 +9205 ./prep_dataset/ILSVRC2012_val_00016545.bin 224 224 +9206 ./prep_dataset/ILSVRC2012_val_00037752.bin 224 224 +9207 ./prep_dataset/ILSVRC2012_val_00031925.bin 224 224 +9208 ./prep_dataset/ILSVRC2012_val_00046062.bin 224 224 +9209 ./prep_dataset/ILSVRC2012_val_00009724.bin 224 224 +9210 ./prep_dataset/ILSVRC2012_val_00036591.bin 224 224 +9211 ./prep_dataset/ILSVRC2012_val_00045067.bin 224 224 +9212 ./prep_dataset/ILSVRC2012_val_00007025.bin 224 224 +9213 ./prep_dataset/ILSVRC2012_val_00013365.bin 224 224 +9214 ./prep_dataset/ILSVRC2012_val_00004039.bin 224 224 +9215 ./prep_dataset/ILSVRC2012_val_00027862.bin 224 224 +9216 ./prep_dataset/ILSVRC2012_val_00025255.bin 224 224 +9217 ./prep_dataset/ILSVRC2012_val_00035532.bin 224 224 +9218 ./prep_dataset/ILSVRC2012_val_00040295.bin 224 224 +9219 ./prep_dataset/ILSVRC2012_val_00012850.bin 224 224 +9220 ./prep_dataset/ILSVRC2012_val_00019682.bin 224 224 +9221 ./prep_dataset/ILSVRC2012_val_00005009.bin 224 224 +9222 ./prep_dataset/ILSVRC2012_val_00038104.bin 224 224 +9223 ./prep_dataset/ILSVRC2012_val_00004825.bin 224 224 +9224 ./prep_dataset/ILSVRC2012_val_00041732.bin 224 224 +9225 ./prep_dataset/ILSVRC2012_val_00043918.bin 224 224 +9226 ./prep_dataset/ILSVRC2012_val_00030199.bin 224 224 +9227 ./prep_dataset/ILSVRC2012_val_00036215.bin 224 224 +9228 ./prep_dataset/ILSVRC2012_val_00029203.bin 224 224 +9229 ./prep_dataset/ILSVRC2012_val_00013142.bin 224 224 +9230 ./prep_dataset/ILSVRC2012_val_00031618.bin 224 224 +9231 ./prep_dataset/ILSVRC2012_val_00006618.bin 224 224 +9232 ./prep_dataset/ILSVRC2012_val_00018494.bin 224 224 +9233 ./prep_dataset/ILSVRC2012_val_00014596.bin 224 224 +9234 ./prep_dataset/ILSVRC2012_val_00025525.bin 224 224 +9235 ./prep_dataset/ILSVRC2012_val_00011234.bin 224 224 +9236 ./prep_dataset/ILSVRC2012_val_00037408.bin 224 224 +9237 ./prep_dataset/ILSVRC2012_val_00021685.bin 224 224 +9238 ./prep_dataset/ILSVRC2012_val_00028921.bin 224 224 +9239 ./prep_dataset/ILSVRC2012_val_00013281.bin 224 224 +9240 ./prep_dataset/ILSVRC2012_val_00021471.bin 224 224 +9241 ./prep_dataset/ILSVRC2012_val_00046320.bin 224 224 +9242 ./prep_dataset/ILSVRC2012_val_00036210.bin 224 224 +9243 ./prep_dataset/ILSVRC2012_val_00016578.bin 224 224 +9244 ./prep_dataset/ILSVRC2012_val_00016169.bin 224 224 +9245 ./prep_dataset/ILSVRC2012_val_00026445.bin 224 224 +9246 ./prep_dataset/ILSVRC2012_val_00025970.bin 224 224 +9247 ./prep_dataset/ILSVRC2012_val_00004953.bin 224 224 +9248 ./prep_dataset/ILSVRC2012_val_00045148.bin 224 224 +9249 ./prep_dataset/ILSVRC2012_val_00000621.bin 224 224 +9250 ./prep_dataset/ILSVRC2012_val_00018353.bin 224 224 +9251 ./prep_dataset/ILSVRC2012_val_00003776.bin 224 224 +9252 ./prep_dataset/ILSVRC2012_val_00038429.bin 224 224 +9253 ./prep_dataset/ILSVRC2012_val_00040579.bin 224 224 +9254 ./prep_dataset/ILSVRC2012_val_00035356.bin 224 224 +9255 ./prep_dataset/ILSVRC2012_val_00041527.bin 224 224 +9256 ./prep_dataset/ILSVRC2012_val_00044895.bin 224 224 +9257 ./prep_dataset/ILSVRC2012_val_00037117.bin 224 224 +9258 ./prep_dataset/ILSVRC2012_val_00030576.bin 224 224 +9259 ./prep_dataset/ILSVRC2012_val_00024027.bin 224 224 +9260 ./prep_dataset/ILSVRC2012_val_00011831.bin 224 224 +9261 ./prep_dataset/ILSVRC2012_val_00046556.bin 224 224 +9262 ./prep_dataset/ILSVRC2012_val_00008314.bin 224 224 +9263 ./prep_dataset/ILSVRC2012_val_00044584.bin 224 224 +9264 ./prep_dataset/ILSVRC2012_val_00002448.bin 224 224 +9265 ./prep_dataset/ILSVRC2012_val_00018752.bin 224 224 +9266 ./prep_dataset/ILSVRC2012_val_00017994.bin 224 224 +9267 ./prep_dataset/ILSVRC2012_val_00034327.bin 224 224 +9268 ./prep_dataset/ILSVRC2012_val_00002888.bin 224 224 +9269 ./prep_dataset/ILSVRC2012_val_00028679.bin 224 224 +9270 ./prep_dataset/ILSVRC2012_val_00018309.bin 224 224 +9271 ./prep_dataset/ILSVRC2012_val_00039803.bin 224 224 +9272 ./prep_dataset/ILSVRC2012_val_00048504.bin 224 224 +9273 ./prep_dataset/ILSVRC2012_val_00047645.bin 224 224 +9274 ./prep_dataset/ILSVRC2012_val_00038229.bin 224 224 +9275 ./prep_dataset/ILSVRC2012_val_00029673.bin 224 224 +9276 ./prep_dataset/ILSVRC2012_val_00026461.bin 224 224 +9277 ./prep_dataset/ILSVRC2012_val_00021532.bin 224 224 +9278 ./prep_dataset/ILSVRC2012_val_00018055.bin 224 224 +9279 ./prep_dataset/ILSVRC2012_val_00042981.bin 224 224 +9280 ./prep_dataset/ILSVRC2012_val_00033687.bin 224 224 +9281 ./prep_dataset/ILSVRC2012_val_00006310.bin 224 224 +9282 ./prep_dataset/ILSVRC2012_val_00040055.bin 224 224 +9283 ./prep_dataset/ILSVRC2012_val_00010497.bin 224 224 +9284 ./prep_dataset/ILSVRC2012_val_00016271.bin 224 224 +9285 ./prep_dataset/ILSVRC2012_val_00041186.bin 224 224 +9286 ./prep_dataset/ILSVRC2012_val_00039334.bin 224 224 +9287 ./prep_dataset/ILSVRC2012_val_00002080.bin 224 224 +9288 ./prep_dataset/ILSVRC2012_val_00037167.bin 224 224 +9289 ./prep_dataset/ILSVRC2012_val_00000597.bin 224 224 +9290 ./prep_dataset/ILSVRC2012_val_00036944.bin 224 224 +9291 ./prep_dataset/ILSVRC2012_val_00004545.bin 224 224 +9292 ./prep_dataset/ILSVRC2012_val_00021445.bin 224 224 +9293 ./prep_dataset/ILSVRC2012_val_00029237.bin 224 224 +9294 ./prep_dataset/ILSVRC2012_val_00019794.bin 224 224 +9295 ./prep_dataset/ILSVRC2012_val_00048231.bin 224 224 +9296 ./prep_dataset/ILSVRC2012_val_00034690.bin 224 224 +9297 ./prep_dataset/ILSVRC2012_val_00018079.bin 224 224 +9298 ./prep_dataset/ILSVRC2012_val_00010276.bin 224 224 +9299 ./prep_dataset/ILSVRC2012_val_00045015.bin 224 224 +9300 ./prep_dataset/ILSVRC2012_val_00017868.bin 224 224 +9301 ./prep_dataset/ILSVRC2012_val_00043971.bin 224 224 +9302 ./prep_dataset/ILSVRC2012_val_00029261.bin 224 224 +9303 ./prep_dataset/ILSVRC2012_val_00032380.bin 224 224 +9304 ./prep_dataset/ILSVRC2012_val_00028040.bin 224 224 +9305 ./prep_dataset/ILSVRC2012_val_00049914.bin 224 224 +9306 ./prep_dataset/ILSVRC2012_val_00011677.bin 224 224 +9307 ./prep_dataset/ILSVRC2012_val_00035156.bin 224 224 +9308 ./prep_dataset/ILSVRC2012_val_00000635.bin 224 224 +9309 ./prep_dataset/ILSVRC2012_val_00026469.bin 224 224 +9310 ./prep_dataset/ILSVRC2012_val_00007655.bin 224 224 +9311 ./prep_dataset/ILSVRC2012_val_00015188.bin 224 224 +9312 ./prep_dataset/ILSVRC2012_val_00040523.bin 224 224 +9313 ./prep_dataset/ILSVRC2012_val_00024103.bin 224 224 +9314 ./prep_dataset/ILSVRC2012_val_00027711.bin 224 224 +9315 ./prep_dataset/ILSVRC2012_val_00036277.bin 224 224 +9316 ./prep_dataset/ILSVRC2012_val_00017508.bin 224 224 +9317 ./prep_dataset/ILSVRC2012_val_00036309.bin 224 224 +9318 ./prep_dataset/ILSVRC2012_val_00046230.bin 224 224 +9319 ./prep_dataset/ILSVRC2012_val_00026176.bin 224 224 +9320 ./prep_dataset/ILSVRC2012_val_00010079.bin 224 224 +9321 ./prep_dataset/ILSVRC2012_val_00012176.bin 224 224 +9322 ./prep_dataset/ILSVRC2012_val_00008874.bin 224 224 +9323 ./prep_dataset/ILSVRC2012_val_00019340.bin 224 224 +9324 ./prep_dataset/ILSVRC2012_val_00013402.bin 224 224 +9325 ./prep_dataset/ILSVRC2012_val_00028406.bin 224 224 +9326 ./prep_dataset/ILSVRC2012_val_00003809.bin 224 224 +9327 ./prep_dataset/ILSVRC2012_val_00039099.bin 224 224 +9328 ./prep_dataset/ILSVRC2012_val_00042414.bin 224 224 +9329 ./prep_dataset/ILSVRC2012_val_00010855.bin 224 224 +9330 ./prep_dataset/ILSVRC2012_val_00034018.bin 224 224 +9331 ./prep_dataset/ILSVRC2012_val_00042433.bin 224 224 +9332 ./prep_dataset/ILSVRC2012_val_00003692.bin 224 224 +9333 ./prep_dataset/ILSVRC2012_val_00016298.bin 224 224 +9334 ./prep_dataset/ILSVRC2012_val_00010065.bin 224 224 +9335 ./prep_dataset/ILSVRC2012_val_00035200.bin 224 224 +9336 ./prep_dataset/ILSVRC2012_val_00034963.bin 224 224 +9337 ./prep_dataset/ILSVRC2012_val_00048100.bin 224 224 +9338 ./prep_dataset/ILSVRC2012_val_00034864.bin 224 224 +9339 ./prep_dataset/ILSVRC2012_val_00046034.bin 224 224 +9340 ./prep_dataset/ILSVRC2012_val_00047826.bin 224 224 +9341 ./prep_dataset/ILSVRC2012_val_00014973.bin 224 224 +9342 ./prep_dataset/ILSVRC2012_val_00047495.bin 224 224 +9343 ./prep_dataset/ILSVRC2012_val_00009754.bin 224 224 +9344 ./prep_dataset/ILSVRC2012_val_00025472.bin 224 224 +9345 ./prep_dataset/ILSVRC2012_val_00039203.bin 224 224 +9346 ./prep_dataset/ILSVRC2012_val_00024558.bin 224 224 +9347 ./prep_dataset/ILSVRC2012_val_00049174.bin 224 224 +9348 ./prep_dataset/ILSVRC2012_val_00044442.bin 224 224 +9349 ./prep_dataset/ILSVRC2012_val_00019730.bin 224 224 +9350 ./prep_dataset/ILSVRC2012_val_00048647.bin 224 224 +9351 ./prep_dataset/ILSVRC2012_val_00033896.bin 224 224 +9352 ./prep_dataset/ILSVRC2012_val_00014317.bin 224 224 +9353 ./prep_dataset/ILSVRC2012_val_00048496.bin 224 224 +9354 ./prep_dataset/ILSVRC2012_val_00030987.bin 224 224 +9355 ./prep_dataset/ILSVRC2012_val_00003407.bin 224 224 +9356 ./prep_dataset/ILSVRC2012_val_00004556.bin 224 224 +9357 ./prep_dataset/ILSVRC2012_val_00044324.bin 224 224 +9358 ./prep_dataset/ILSVRC2012_val_00040262.bin 224 224 +9359 ./prep_dataset/ILSVRC2012_val_00029734.bin 224 224 +9360 ./prep_dataset/ILSVRC2012_val_00044931.bin 224 224 +9361 ./prep_dataset/ILSVRC2012_val_00010607.bin 224 224 +9362 ./prep_dataset/ILSVRC2012_val_00047496.bin 224 224 +9363 ./prep_dataset/ILSVRC2012_val_00011554.bin 224 224 +9364 ./prep_dataset/ILSVRC2012_val_00034736.bin 224 224 +9365 ./prep_dataset/ILSVRC2012_val_00025393.bin 224 224 +9366 ./prep_dataset/ILSVRC2012_val_00033527.bin 224 224 +9367 ./prep_dataset/ILSVRC2012_val_00013333.bin 224 224 +9368 ./prep_dataset/ILSVRC2012_val_00009344.bin 224 224 +9369 ./prep_dataset/ILSVRC2012_val_00015665.bin 224 224 +9370 ./prep_dataset/ILSVRC2012_val_00039920.bin 224 224 +9371 ./prep_dataset/ILSVRC2012_val_00001824.bin 224 224 +9372 ./prep_dataset/ILSVRC2012_val_00004705.bin 224 224 +9373 ./prep_dataset/ILSVRC2012_val_00048192.bin 224 224 +9374 ./prep_dataset/ILSVRC2012_val_00001837.bin 224 224 +9375 ./prep_dataset/ILSVRC2012_val_00030570.bin 224 224 +9376 ./prep_dataset/ILSVRC2012_val_00030775.bin 224 224 +9377 ./prep_dataset/ILSVRC2012_val_00041790.bin 224 224 +9378 ./prep_dataset/ILSVRC2012_val_00046827.bin 224 224 +9379 ./prep_dataset/ILSVRC2012_val_00004837.bin 224 224 +9380 ./prep_dataset/ILSVRC2012_val_00010328.bin 224 224 +9381 ./prep_dataset/ILSVRC2012_val_00043789.bin 224 224 +9382 ./prep_dataset/ILSVRC2012_val_00045438.bin 224 224 +9383 ./prep_dataset/ILSVRC2012_val_00028067.bin 224 224 +9384 ./prep_dataset/ILSVRC2012_val_00025344.bin 224 224 +9385 ./prep_dataset/ILSVRC2012_val_00038481.bin 224 224 +9386 ./prep_dataset/ILSVRC2012_val_00032111.bin 224 224 +9387 ./prep_dataset/ILSVRC2012_val_00014069.bin 224 224 +9388 ./prep_dataset/ILSVRC2012_val_00043578.bin 224 224 +9389 ./prep_dataset/ILSVRC2012_val_00046750.bin 224 224 +9390 ./prep_dataset/ILSVRC2012_val_00033105.bin 224 224 +9391 ./prep_dataset/ILSVRC2012_val_00021746.bin 224 224 +9392 ./prep_dataset/ILSVRC2012_val_00045043.bin 224 224 +9393 ./prep_dataset/ILSVRC2012_val_00005516.bin 224 224 +9394 ./prep_dataset/ILSVRC2012_val_00001441.bin 224 224 +9395 ./prep_dataset/ILSVRC2012_val_00036693.bin 224 224 +9396 ./prep_dataset/ILSVRC2012_val_00025205.bin 224 224 +9397 ./prep_dataset/ILSVRC2012_val_00045072.bin 224 224 +9398 ./prep_dataset/ILSVRC2012_val_00006376.bin 224 224 +9399 ./prep_dataset/ILSVRC2012_val_00032427.bin 224 224 +9400 ./prep_dataset/ILSVRC2012_val_00023117.bin 224 224 +9401 ./prep_dataset/ILSVRC2012_val_00038734.bin 224 224 +9402 ./prep_dataset/ILSVRC2012_val_00011789.bin 224 224 +9403 ./prep_dataset/ILSVRC2012_val_00022796.bin 224 224 +9404 ./prep_dataset/ILSVRC2012_val_00012975.bin 224 224 +9405 ./prep_dataset/ILSVRC2012_val_00041794.bin 224 224 +9406 ./prep_dataset/ILSVRC2012_val_00040591.bin 224 224 +9407 ./prep_dataset/ILSVRC2012_val_00048626.bin 224 224 +9408 ./prep_dataset/ILSVRC2012_val_00014950.bin 224 224 +9409 ./prep_dataset/ILSVRC2012_val_00018027.bin 224 224 +9410 ./prep_dataset/ILSVRC2012_val_00032310.bin 224 224 +9411 ./prep_dataset/ILSVRC2012_val_00038644.bin 224 224 +9412 ./prep_dataset/ILSVRC2012_val_00041039.bin 224 224 +9413 ./prep_dataset/ILSVRC2012_val_00035935.bin 224 224 +9414 ./prep_dataset/ILSVRC2012_val_00009514.bin 224 224 +9415 ./prep_dataset/ILSVRC2012_val_00038995.bin 224 224 +9416 ./prep_dataset/ILSVRC2012_val_00012453.bin 224 224 +9417 ./prep_dataset/ILSVRC2012_val_00034871.bin 224 224 +9418 ./prep_dataset/ILSVRC2012_val_00026486.bin 224 224 +9419 ./prep_dataset/ILSVRC2012_val_00015334.bin 224 224 +9420 ./prep_dataset/ILSVRC2012_val_00032478.bin 224 224 +9421 ./prep_dataset/ILSVRC2012_val_00020349.bin 224 224 +9422 ./prep_dataset/ILSVRC2012_val_00018812.bin 224 224 +9423 ./prep_dataset/ILSVRC2012_val_00037909.bin 224 224 +9424 ./prep_dataset/ILSVRC2012_val_00018648.bin 224 224 +9425 ./prep_dataset/ILSVRC2012_val_00031117.bin 224 224 +9426 ./prep_dataset/ILSVRC2012_val_00017506.bin 224 224 +9427 ./prep_dataset/ILSVRC2012_val_00001053.bin 224 224 +9428 ./prep_dataset/ILSVRC2012_val_00038681.bin 224 224 +9429 ./prep_dataset/ILSVRC2012_val_00045346.bin 224 224 +9430 ./prep_dataset/ILSVRC2012_val_00047047.bin 224 224 +9431 ./prep_dataset/ILSVRC2012_val_00034027.bin 224 224 +9432 ./prep_dataset/ILSVRC2012_val_00035432.bin 224 224 +9433 ./prep_dataset/ILSVRC2012_val_00015624.bin 224 224 +9434 ./prep_dataset/ILSVRC2012_val_00045287.bin 224 224 +9435 ./prep_dataset/ILSVRC2012_val_00013107.bin 224 224 +9436 ./prep_dataset/ILSVRC2012_val_00014853.bin 224 224 +9437 ./prep_dataset/ILSVRC2012_val_00036092.bin 224 224 +9438 ./prep_dataset/ILSVRC2012_val_00045957.bin 224 224 +9439 ./prep_dataset/ILSVRC2012_val_00032137.bin 224 224 +9440 ./prep_dataset/ILSVRC2012_val_00037359.bin 224 224 +9441 ./prep_dataset/ILSVRC2012_val_00043888.bin 224 224 +9442 ./prep_dataset/ILSVRC2012_val_00036223.bin 224 224 +9443 ./prep_dataset/ILSVRC2012_val_00014421.bin 224 224 +9444 ./prep_dataset/ILSVRC2012_val_00024484.bin 224 224 +9445 ./prep_dataset/ILSVRC2012_val_00033183.bin 224 224 +9446 ./prep_dataset/ILSVRC2012_val_00019135.bin 224 224 +9447 ./prep_dataset/ILSVRC2012_val_00007793.bin 224 224 +9448 ./prep_dataset/ILSVRC2012_val_00006907.bin 224 224 +9449 ./prep_dataset/ILSVRC2012_val_00045418.bin 224 224 +9450 ./prep_dataset/ILSVRC2012_val_00042349.bin 224 224 +9451 ./prep_dataset/ILSVRC2012_val_00010570.bin 224 224 +9452 ./prep_dataset/ILSVRC2012_val_00009704.bin 224 224 +9453 ./prep_dataset/ILSVRC2012_val_00025236.bin 224 224 +9454 ./prep_dataset/ILSVRC2012_val_00038825.bin 224 224 +9455 ./prep_dataset/ILSVRC2012_val_00031546.bin 224 224 +9456 ./prep_dataset/ILSVRC2012_val_00010975.bin 224 224 +9457 ./prep_dataset/ILSVRC2012_val_00030068.bin 224 224 +9458 ./prep_dataset/ILSVRC2012_val_00027662.bin 224 224 +9459 ./prep_dataset/ILSVRC2012_val_00046765.bin 224 224 +9460 ./prep_dataset/ILSVRC2012_val_00033417.bin 224 224 +9461 ./prep_dataset/ILSVRC2012_val_00037244.bin 224 224 +9462 ./prep_dataset/ILSVRC2012_val_00041960.bin 224 224 +9463 ./prep_dataset/ILSVRC2012_val_00042671.bin 224 224 +9464 ./prep_dataset/ILSVRC2012_val_00046850.bin 224 224 +9465 ./prep_dataset/ILSVRC2012_val_00017103.bin 224 224 +9466 ./prep_dataset/ILSVRC2012_val_00044401.bin 224 224 +9467 ./prep_dataset/ILSVRC2012_val_00008021.bin 224 224 +9468 ./prep_dataset/ILSVRC2012_val_00038206.bin 224 224 +9469 ./prep_dataset/ILSVRC2012_val_00002256.bin 224 224 +9470 ./prep_dataset/ILSVRC2012_val_00016562.bin 224 224 +9471 ./prep_dataset/ILSVRC2012_val_00007649.bin 224 224 +9472 ./prep_dataset/ILSVRC2012_val_00025229.bin 224 224 +9473 ./prep_dataset/ILSVRC2012_val_00047564.bin 224 224 +9474 ./prep_dataset/ILSVRC2012_val_00009139.bin 224 224 +9475 ./prep_dataset/ILSVRC2012_val_00042130.bin 224 224 +9476 ./prep_dataset/ILSVRC2012_val_00048134.bin 224 224 +9477 ./prep_dataset/ILSVRC2012_val_00001928.bin 224 224 +9478 ./prep_dataset/ILSVRC2012_val_00019014.bin 224 224 +9479 ./prep_dataset/ILSVRC2012_val_00038018.bin 224 224 +9480 ./prep_dataset/ILSVRC2012_val_00040673.bin 224 224 +9481 ./prep_dataset/ILSVRC2012_val_00042811.bin 224 224 +9482 ./prep_dataset/ILSVRC2012_val_00032167.bin 224 224 +9483 ./prep_dataset/ILSVRC2012_val_00041826.bin 224 224 +9484 ./prep_dataset/ILSVRC2012_val_00046617.bin 224 224 +9485 ./prep_dataset/ILSVRC2012_val_00039217.bin 224 224 +9486 ./prep_dataset/ILSVRC2012_val_00010054.bin 224 224 +9487 ./prep_dataset/ILSVRC2012_val_00042254.bin 224 224 +9488 ./prep_dataset/ILSVRC2012_val_00029949.bin 224 224 +9489 ./prep_dataset/ILSVRC2012_val_00027086.bin 224 224 +9490 ./prep_dataset/ILSVRC2012_val_00008514.bin 224 224 +9491 ./prep_dataset/ILSVRC2012_val_00003688.bin 224 224 +9492 ./prep_dataset/ILSVRC2012_val_00016101.bin 224 224 +9493 ./prep_dataset/ILSVRC2012_val_00030130.bin 224 224 +9494 ./prep_dataset/ILSVRC2012_val_00038731.bin 224 224 +9495 ./prep_dataset/ILSVRC2012_val_00031045.bin 224 224 +9496 ./prep_dataset/ILSVRC2012_val_00026117.bin 224 224 +9497 ./prep_dataset/ILSVRC2012_val_00003982.bin 224 224 +9498 ./prep_dataset/ILSVRC2012_val_00045575.bin 224 224 +9499 ./prep_dataset/ILSVRC2012_val_00014002.bin 224 224 +9500 ./prep_dataset/ILSVRC2012_val_00019053.bin 224 224 +9501 ./prep_dataset/ILSVRC2012_val_00009905.bin 224 224 +9502 ./prep_dataset/ILSVRC2012_val_00003998.bin 224 224 +9503 ./prep_dataset/ILSVRC2012_val_00010136.bin 224 224 +9504 ./prep_dataset/ILSVRC2012_val_00037407.bin 224 224 +9505 ./prep_dataset/ILSVRC2012_val_00002763.bin 224 224 +9506 ./prep_dataset/ILSVRC2012_val_00039065.bin 224 224 +9507 ./prep_dataset/ILSVRC2012_val_00047163.bin 224 224 +9508 ./prep_dataset/ILSVRC2012_val_00014972.bin 224 224 +9509 ./prep_dataset/ILSVRC2012_val_00046123.bin 224 224 +9510 ./prep_dataset/ILSVRC2012_val_00006052.bin 224 224 +9511 ./prep_dataset/ILSVRC2012_val_00014314.bin 224 224 +9512 ./prep_dataset/ILSVRC2012_val_00043005.bin 224 224 +9513 ./prep_dataset/ILSVRC2012_val_00040116.bin 224 224 +9514 ./prep_dataset/ILSVRC2012_val_00003310.bin 224 224 +9515 ./prep_dataset/ILSVRC2012_val_00015328.bin 224 224 +9516 ./prep_dataset/ILSVRC2012_val_00017805.bin 224 224 +9517 ./prep_dataset/ILSVRC2012_val_00007241.bin 224 224 +9518 ./prep_dataset/ILSVRC2012_val_00033748.bin 224 224 +9519 ./prep_dataset/ILSVRC2012_val_00031255.bin 224 224 +9520 ./prep_dataset/ILSVRC2012_val_00000227.bin 224 224 +9521 ./prep_dataset/ILSVRC2012_val_00015838.bin 224 224 +9522 ./prep_dataset/ILSVRC2012_val_00042535.bin 224 224 +9523 ./prep_dataset/ILSVRC2012_val_00002543.bin 224 224 +9524 ./prep_dataset/ILSVRC2012_val_00023894.bin 224 224 +9525 ./prep_dataset/ILSVRC2012_val_00022020.bin 224 224 +9526 ./prep_dataset/ILSVRC2012_val_00047049.bin 224 224 +9527 ./prep_dataset/ILSVRC2012_val_00038740.bin 224 224 +9528 ./prep_dataset/ILSVRC2012_val_00044912.bin 224 224 +9529 ./prep_dataset/ILSVRC2012_val_00019880.bin 224 224 +9530 ./prep_dataset/ILSVRC2012_val_00015522.bin 224 224 +9531 ./prep_dataset/ILSVRC2012_val_00036158.bin 224 224 +9532 ./prep_dataset/ILSVRC2012_val_00009068.bin 224 224 +9533 ./prep_dataset/ILSVRC2012_val_00017745.bin 224 224 +9534 ./prep_dataset/ILSVRC2012_val_00025352.bin 224 224 +9535 ./prep_dataset/ILSVRC2012_val_00014773.bin 224 224 +9536 ./prep_dataset/ILSVRC2012_val_00039906.bin 224 224 +9537 ./prep_dataset/ILSVRC2012_val_00033880.bin 224 224 +9538 ./prep_dataset/ILSVRC2012_val_00001084.bin 224 224 +9539 ./prep_dataset/ILSVRC2012_val_00015614.bin 224 224 +9540 ./prep_dataset/ILSVRC2012_val_00042346.bin 224 224 +9541 ./prep_dataset/ILSVRC2012_val_00002092.bin 224 224 +9542 ./prep_dataset/ILSVRC2012_val_00030893.bin 224 224 +9543 ./prep_dataset/ILSVRC2012_val_00029553.bin 224 224 +9544 ./prep_dataset/ILSVRC2012_val_00022857.bin 224 224 +9545 ./prep_dataset/ILSVRC2012_val_00032875.bin 224 224 +9546 ./prep_dataset/ILSVRC2012_val_00016396.bin 224 224 +9547 ./prep_dataset/ILSVRC2012_val_00010684.bin 224 224 +9548 ./prep_dataset/ILSVRC2012_val_00012384.bin 224 224 +9549 ./prep_dataset/ILSVRC2012_val_00005782.bin 224 224 +9550 ./prep_dataset/ILSVRC2012_val_00045278.bin 224 224 +9551 ./prep_dataset/ILSVRC2012_val_00025368.bin 224 224 +9552 ./prep_dataset/ILSVRC2012_val_00022808.bin 224 224 +9553 ./prep_dataset/ILSVRC2012_val_00029244.bin 224 224 +9554 ./prep_dataset/ILSVRC2012_val_00020539.bin 224 224 +9555 ./prep_dataset/ILSVRC2012_val_00017390.bin 224 224 +9556 ./prep_dataset/ILSVRC2012_val_00048910.bin 224 224 +9557 ./prep_dataset/ILSVRC2012_val_00020924.bin 224 224 +9558 ./prep_dataset/ILSVRC2012_val_00022039.bin 224 224 +9559 ./prep_dataset/ILSVRC2012_val_00048390.bin 224 224 +9560 ./prep_dataset/ILSVRC2012_val_00040437.bin 224 224 +9561 ./prep_dataset/ILSVRC2012_val_00002241.bin 224 224 +9562 ./prep_dataset/ILSVRC2012_val_00047443.bin 224 224 +9563 ./prep_dataset/ILSVRC2012_val_00030274.bin 224 224 +9564 ./prep_dataset/ILSVRC2012_val_00005137.bin 224 224 +9565 ./prep_dataset/ILSVRC2012_val_00012425.bin 224 224 +9566 ./prep_dataset/ILSVRC2012_val_00015171.bin 224 224 +9567 ./prep_dataset/ILSVRC2012_val_00004718.bin 224 224 +9568 ./prep_dataset/ILSVRC2012_val_00038531.bin 224 224 +9569 ./prep_dataset/ILSVRC2012_val_00043021.bin 224 224 +9570 ./prep_dataset/ILSVRC2012_val_00042846.bin 224 224 +9571 ./prep_dataset/ILSVRC2012_val_00043203.bin 224 224 +9572 ./prep_dataset/ILSVRC2012_val_00006876.bin 224 224 +9573 ./prep_dataset/ILSVRC2012_val_00015424.bin 224 224 +9574 ./prep_dataset/ILSVRC2012_val_00009819.bin 224 224 +9575 ./prep_dataset/ILSVRC2012_val_00009099.bin 224 224 +9576 ./prep_dataset/ILSVRC2012_val_00046784.bin 224 224 +9577 ./prep_dataset/ILSVRC2012_val_00029844.bin 224 224 +9578 ./prep_dataset/ILSVRC2012_val_00030871.bin 224 224 +9579 ./prep_dataset/ILSVRC2012_val_00025132.bin 224 224 +9580 ./prep_dataset/ILSVRC2012_val_00034029.bin 224 224 +9581 ./prep_dataset/ILSVRC2012_val_00009393.bin 224 224 +9582 ./prep_dataset/ILSVRC2012_val_00000469.bin 224 224 +9583 ./prep_dataset/ILSVRC2012_val_00006539.bin 224 224 +9584 ./prep_dataset/ILSVRC2012_val_00009390.bin 224 224 +9585 ./prep_dataset/ILSVRC2012_val_00032129.bin 224 224 +9586 ./prep_dataset/ILSVRC2012_val_00023223.bin 224 224 +9587 ./prep_dataset/ILSVRC2012_val_00034470.bin 224 224 +9588 ./prep_dataset/ILSVRC2012_val_00044793.bin 224 224 +9589 ./prep_dataset/ILSVRC2012_val_00029741.bin 224 224 +9590 ./prep_dataset/ILSVRC2012_val_00036387.bin 224 224 +9591 ./prep_dataset/ILSVRC2012_val_00042232.bin 224 224 +9592 ./prep_dataset/ILSVRC2012_val_00048322.bin 224 224 +9593 ./prep_dataset/ILSVRC2012_val_00015290.bin 224 224 +9594 ./prep_dataset/ILSVRC2012_val_00026289.bin 224 224 +9595 ./prep_dataset/ILSVRC2012_val_00027612.bin 224 224 +9596 ./prep_dataset/ILSVRC2012_val_00006627.bin 224 224 +9597 ./prep_dataset/ILSVRC2012_val_00024040.bin 224 224 +9598 ./prep_dataset/ILSVRC2012_val_00049431.bin 224 224 +9599 ./prep_dataset/ILSVRC2012_val_00046278.bin 224 224 +9600 ./prep_dataset/ILSVRC2012_val_00019878.bin 224 224 +9601 ./prep_dataset/ILSVRC2012_val_00012713.bin 224 224 +9602 ./prep_dataset/ILSVRC2012_val_00004798.bin 224 224 +9603 ./prep_dataset/ILSVRC2012_val_00020068.bin 224 224 +9604 ./prep_dataset/ILSVRC2012_val_00031736.bin 224 224 +9605 ./prep_dataset/ILSVRC2012_val_00029931.bin 224 224 +9606 ./prep_dataset/ILSVRC2012_val_00012312.bin 224 224 +9607 ./prep_dataset/ILSVRC2012_val_00001476.bin 224 224 +9608 ./prep_dataset/ILSVRC2012_val_00031613.bin 224 224 +9609 ./prep_dataset/ILSVRC2012_val_00023149.bin 224 224 +9610 ./prep_dataset/ILSVRC2012_val_00031484.bin 224 224 +9611 ./prep_dataset/ILSVRC2012_val_00044314.bin 224 224 +9612 ./prep_dataset/ILSVRC2012_val_00016091.bin 224 224 +9613 ./prep_dataset/ILSVRC2012_val_00036255.bin 224 224 +9614 ./prep_dataset/ILSVRC2012_val_00013776.bin 224 224 +9615 ./prep_dataset/ILSVRC2012_val_00022197.bin 224 224 +9616 ./prep_dataset/ILSVRC2012_val_00017039.bin 224 224 +9617 ./prep_dataset/ILSVRC2012_val_00043589.bin 224 224 +9618 ./prep_dataset/ILSVRC2012_val_00038230.bin 224 224 +9619 ./prep_dataset/ILSVRC2012_val_00045457.bin 224 224 +9620 ./prep_dataset/ILSVRC2012_val_00022398.bin 224 224 +9621 ./prep_dataset/ILSVRC2012_val_00026536.bin 224 224 +9622 ./prep_dataset/ILSVRC2012_val_00045587.bin 224 224 +9623 ./prep_dataset/ILSVRC2012_val_00037338.bin 224 224 +9624 ./prep_dataset/ILSVRC2012_val_00003198.bin 224 224 +9625 ./prep_dataset/ILSVRC2012_val_00049243.bin 224 224 +9626 ./prep_dataset/ILSVRC2012_val_00027142.bin 224 224 +9627 ./prep_dataset/ILSVRC2012_val_00001371.bin 224 224 +9628 ./prep_dataset/ILSVRC2012_val_00045363.bin 224 224 +9629 ./prep_dataset/ILSVRC2012_val_00030517.bin 224 224 +9630 ./prep_dataset/ILSVRC2012_val_00014528.bin 224 224 +9631 ./prep_dataset/ILSVRC2012_val_00020635.bin 224 224 +9632 ./prep_dataset/ILSVRC2012_val_00013535.bin 224 224 +9633 ./prep_dataset/ILSVRC2012_val_00009779.bin 224 224 +9634 ./prep_dataset/ILSVRC2012_val_00034836.bin 224 224 +9635 ./prep_dataset/ILSVRC2012_val_00019275.bin 224 224 +9636 ./prep_dataset/ILSVRC2012_val_00044459.bin 224 224 +9637 ./prep_dataset/ILSVRC2012_val_00044783.bin 224 224 +9638 ./prep_dataset/ILSVRC2012_val_00023447.bin 224 224 +9639 ./prep_dataset/ILSVRC2012_val_00018538.bin 224 224 +9640 ./prep_dataset/ILSVRC2012_val_00014139.bin 224 224 +9641 ./prep_dataset/ILSVRC2012_val_00047511.bin 224 224 +9642 ./prep_dataset/ILSVRC2012_val_00035335.bin 224 224 +9643 ./prep_dataset/ILSVRC2012_val_00024134.bin 224 224 +9644 ./prep_dataset/ILSVRC2012_val_00029574.bin 224 224 +9645 ./prep_dataset/ILSVRC2012_val_00004499.bin 224 224 +9646 ./prep_dataset/ILSVRC2012_val_00023951.bin 224 224 +9647 ./prep_dataset/ILSVRC2012_val_00048449.bin 224 224 +9648 ./prep_dataset/ILSVRC2012_val_00045800.bin 224 224 +9649 ./prep_dataset/ILSVRC2012_val_00043902.bin 224 224 +9650 ./prep_dataset/ILSVRC2012_val_00035063.bin 224 224 +9651 ./prep_dataset/ILSVRC2012_val_00018056.bin 224 224 +9652 ./prep_dataset/ILSVRC2012_val_00007411.bin 224 224 +9653 ./prep_dataset/ILSVRC2012_val_00024813.bin 224 224 +9654 ./prep_dataset/ILSVRC2012_val_00028128.bin 224 224 +9655 ./prep_dataset/ILSVRC2012_val_00039688.bin 224 224 +9656 ./prep_dataset/ILSVRC2012_val_00019090.bin 224 224 +9657 ./prep_dataset/ILSVRC2012_val_00005361.bin 224 224 +9658 ./prep_dataset/ILSVRC2012_val_00035982.bin 224 224 +9659 ./prep_dataset/ILSVRC2012_val_00022397.bin 224 224 +9660 ./prep_dataset/ILSVRC2012_val_00031414.bin 224 224 +9661 ./prep_dataset/ILSVRC2012_val_00046222.bin 224 224 +9662 ./prep_dataset/ILSVRC2012_val_00042877.bin 224 224 +9663 ./prep_dataset/ILSVRC2012_val_00022350.bin 224 224 +9664 ./prep_dataset/ILSVRC2012_val_00017667.bin 224 224 +9665 ./prep_dataset/ILSVRC2012_val_00028885.bin 224 224 +9666 ./prep_dataset/ILSVRC2012_val_00025681.bin 224 224 +9667 ./prep_dataset/ILSVRC2012_val_00013981.bin 224 224 +9668 ./prep_dataset/ILSVRC2012_val_00014483.bin 224 224 +9669 ./prep_dataset/ILSVRC2012_val_00029799.bin 224 224 +9670 ./prep_dataset/ILSVRC2012_val_00042611.bin 224 224 +9671 ./prep_dataset/ILSVRC2012_val_00004359.bin 224 224 +9672 ./prep_dataset/ILSVRC2012_val_00006276.bin 224 224 +9673 ./prep_dataset/ILSVRC2012_val_00045143.bin 224 224 +9674 ./prep_dataset/ILSVRC2012_val_00003635.bin 224 224 +9675 ./prep_dataset/ILSVRC2012_val_00024303.bin 224 224 +9676 ./prep_dataset/ILSVRC2012_val_00045660.bin 224 224 +9677 ./prep_dataset/ILSVRC2012_val_00035226.bin 224 224 +9678 ./prep_dataset/ILSVRC2012_val_00016765.bin 224 224 +9679 ./prep_dataset/ILSVRC2012_val_00047660.bin 224 224 +9680 ./prep_dataset/ILSVRC2012_val_00039903.bin 224 224 +9681 ./prep_dataset/ILSVRC2012_val_00013846.bin 224 224 +9682 ./prep_dataset/ILSVRC2012_val_00023682.bin 224 224 +9683 ./prep_dataset/ILSVRC2012_val_00038313.bin 224 224 +9684 ./prep_dataset/ILSVRC2012_val_00032413.bin 224 224 +9685 ./prep_dataset/ILSVRC2012_val_00037447.bin 224 224 +9686 ./prep_dataset/ILSVRC2012_val_00047871.bin 224 224 +9687 ./prep_dataset/ILSVRC2012_val_00015197.bin 224 224 +9688 ./prep_dataset/ILSVRC2012_val_00049711.bin 224 224 +9689 ./prep_dataset/ILSVRC2012_val_00010391.bin 224 224 +9690 ./prep_dataset/ILSVRC2012_val_00003736.bin 224 224 +9691 ./prep_dataset/ILSVRC2012_val_00041867.bin 224 224 +9692 ./prep_dataset/ILSVRC2012_val_00022028.bin 224 224 +9693 ./prep_dataset/ILSVRC2012_val_00005955.bin 224 224 +9694 ./prep_dataset/ILSVRC2012_val_00006124.bin 224 224 +9695 ./prep_dataset/ILSVRC2012_val_00030778.bin 224 224 +9696 ./prep_dataset/ILSVRC2012_val_00024398.bin 224 224 +9697 ./prep_dataset/ILSVRC2012_val_00036530.bin 224 224 +9698 ./prep_dataset/ILSVRC2012_val_00024848.bin 224 224 +9699 ./prep_dataset/ILSVRC2012_val_00036339.bin 224 224 +9700 ./prep_dataset/ILSVRC2012_val_00026315.bin 224 224 +9701 ./prep_dataset/ILSVRC2012_val_00019994.bin 224 224 +9702 ./prep_dataset/ILSVRC2012_val_00029035.bin 224 224 +9703 ./prep_dataset/ILSVRC2012_val_00000812.bin 224 224 +9704 ./prep_dataset/ILSVRC2012_val_00047764.bin 224 224 +9705 ./prep_dataset/ILSVRC2012_val_00020655.bin 224 224 +9706 ./prep_dataset/ILSVRC2012_val_00005052.bin 224 224 +9707 ./prep_dataset/ILSVRC2012_val_00049798.bin 224 224 +9708 ./prep_dataset/ILSVRC2012_val_00000329.bin 224 224 +9709 ./prep_dataset/ILSVRC2012_val_00017381.bin 224 224 +9710 ./prep_dataset/ILSVRC2012_val_00025762.bin 224 224 +9711 ./prep_dataset/ILSVRC2012_val_00047473.bin 224 224 +9712 ./prep_dataset/ILSVRC2012_val_00012829.bin 224 224 +9713 ./prep_dataset/ILSVRC2012_val_00018569.bin 224 224 +9714 ./prep_dataset/ILSVRC2012_val_00026299.bin 224 224 +9715 ./prep_dataset/ILSVRC2012_val_00044380.bin 224 224 +9716 ./prep_dataset/ILSVRC2012_val_00031017.bin 224 224 +9717 ./prep_dataset/ILSVRC2012_val_00028851.bin 224 224 +9718 ./prep_dataset/ILSVRC2012_val_00038529.bin 224 224 +9719 ./prep_dataset/ILSVRC2012_val_00014366.bin 224 224 +9720 ./prep_dataset/ILSVRC2012_val_00010904.bin 224 224 +9721 ./prep_dataset/ILSVRC2012_val_00017092.bin 224 224 +9722 ./prep_dataset/ILSVRC2012_val_00042085.bin 224 224 +9723 ./prep_dataset/ILSVRC2012_val_00023653.bin 224 224 +9724 ./prep_dataset/ILSVRC2012_val_00038518.bin 224 224 +9725 ./prep_dataset/ILSVRC2012_val_00025822.bin 224 224 +9726 ./prep_dataset/ILSVRC2012_val_00026254.bin 224 224 +9727 ./prep_dataset/ILSVRC2012_val_00003480.bin 224 224 +9728 ./prep_dataset/ILSVRC2012_val_00047165.bin 224 224 +9729 ./prep_dataset/ILSVRC2012_val_00019887.bin 224 224 +9730 ./prep_dataset/ILSVRC2012_val_00007325.bin 224 224 +9731 ./prep_dataset/ILSVRC2012_val_00029413.bin 224 224 +9732 ./prep_dataset/ILSVRC2012_val_00010925.bin 224 224 +9733 ./prep_dataset/ILSVRC2012_val_00037226.bin 224 224 +9734 ./prep_dataset/ILSVRC2012_val_00018194.bin 224 224 +9735 ./prep_dataset/ILSVRC2012_val_00005837.bin 224 224 +9736 ./prep_dataset/ILSVRC2012_val_00020919.bin 224 224 +9737 ./prep_dataset/ILSVRC2012_val_00007131.bin 224 224 +9738 ./prep_dataset/ILSVRC2012_val_00026709.bin 224 224 +9739 ./prep_dataset/ILSVRC2012_val_00027896.bin 224 224 +9740 ./prep_dataset/ILSVRC2012_val_00008462.bin 224 224 +9741 ./prep_dataset/ILSVRC2012_val_00025611.bin 224 224 +9742 ./prep_dataset/ILSVRC2012_val_00044141.bin 224 224 +9743 ./prep_dataset/ILSVRC2012_val_00043974.bin 224 224 +9744 ./prep_dataset/ILSVRC2012_val_00012894.bin 224 224 +9745 ./prep_dataset/ILSVRC2012_val_00002138.bin 224 224 +9746 ./prep_dataset/ILSVRC2012_val_00011538.bin 224 224 +9747 ./prep_dataset/ILSVRC2012_val_00025846.bin 224 224 +9748 ./prep_dataset/ILSVRC2012_val_00045760.bin 224 224 +9749 ./prep_dataset/ILSVRC2012_val_00040631.bin 224 224 +9750 ./prep_dataset/ILSVRC2012_val_00026409.bin 224 224 +9751 ./prep_dataset/ILSVRC2012_val_00006810.bin 224 224 +9752 ./prep_dataset/ILSVRC2012_val_00045627.bin 224 224 +9753 ./prep_dataset/ILSVRC2012_val_00003856.bin 224 224 +9754 ./prep_dataset/ILSVRC2012_val_00048957.bin 224 224 +9755 ./prep_dataset/ILSVRC2012_val_00047936.bin 224 224 +9756 ./prep_dataset/ILSVRC2012_val_00000893.bin 224 224 +9757 ./prep_dataset/ILSVRC2012_val_00037134.bin 224 224 +9758 ./prep_dataset/ILSVRC2012_val_00003876.bin 224 224 +9759 ./prep_dataset/ILSVRC2012_val_00026887.bin 224 224 +9760 ./prep_dataset/ILSVRC2012_val_00040940.bin 224 224 +9761 ./prep_dataset/ILSVRC2012_val_00009280.bin 224 224 +9762 ./prep_dataset/ILSVRC2012_val_00021516.bin 224 224 +9763 ./prep_dataset/ILSVRC2012_val_00018990.bin 224 224 +9764 ./prep_dataset/ILSVRC2012_val_00042679.bin 224 224 +9765 ./prep_dataset/ILSVRC2012_val_00047008.bin 224 224 +9766 ./prep_dataset/ILSVRC2012_val_00002991.bin 224 224 +9767 ./prep_dataset/ILSVRC2012_val_00047779.bin 224 224 +9768 ./prep_dataset/ILSVRC2012_val_00021072.bin 224 224 +9769 ./prep_dataset/ILSVRC2012_val_00026512.bin 224 224 +9770 ./prep_dataset/ILSVRC2012_val_00044472.bin 224 224 +9771 ./prep_dataset/ILSVRC2012_val_00044727.bin 224 224 +9772 ./prep_dataset/ILSVRC2012_val_00025574.bin 224 224 +9773 ./prep_dataset/ILSVRC2012_val_00013087.bin 224 224 +9774 ./prep_dataset/ILSVRC2012_val_00013731.bin 224 224 +9775 ./prep_dataset/ILSVRC2012_val_00006954.bin 224 224 +9776 ./prep_dataset/ILSVRC2012_val_00017438.bin 224 224 +9777 ./prep_dataset/ILSVRC2012_val_00033077.bin 224 224 +9778 ./prep_dataset/ILSVRC2012_val_00004428.bin 224 224 +9779 ./prep_dataset/ILSVRC2012_val_00040304.bin 224 224 +9780 ./prep_dataset/ILSVRC2012_val_00019434.bin 224 224 +9781 ./prep_dataset/ILSVRC2012_val_00034758.bin 224 224 +9782 ./prep_dataset/ILSVRC2012_val_00046375.bin 224 224 +9783 ./prep_dataset/ILSVRC2012_val_00005144.bin 224 224 +9784 ./prep_dataset/ILSVRC2012_val_00010844.bin 224 224 +9785 ./prep_dataset/ILSVRC2012_val_00006554.bin 224 224 +9786 ./prep_dataset/ILSVRC2012_val_00031276.bin 224 224 +9787 ./prep_dataset/ILSVRC2012_val_00010518.bin 224 224 +9788 ./prep_dataset/ILSVRC2012_val_00006638.bin 224 224 +9789 ./prep_dataset/ILSVRC2012_val_00046182.bin 224 224 +9790 ./prep_dataset/ILSVRC2012_val_00030037.bin 224 224 +9791 ./prep_dataset/ILSVRC2012_val_00034703.bin 224 224 +9792 ./prep_dataset/ILSVRC2012_val_00048346.bin 224 224 +9793 ./prep_dataset/ILSVRC2012_val_00024843.bin 224 224 +9794 ./prep_dataset/ILSVRC2012_val_00024450.bin 224 224 +9795 ./prep_dataset/ILSVRC2012_val_00018794.bin 224 224 +9796 ./prep_dataset/ILSVRC2012_val_00024217.bin 224 224 +9797 ./prep_dataset/ILSVRC2012_val_00036000.bin 224 224 +9798 ./prep_dataset/ILSVRC2012_val_00003196.bin 224 224 +9799 ./prep_dataset/ILSVRC2012_val_00028428.bin 224 224 +9800 ./prep_dataset/ILSVRC2012_val_00011676.bin 224 224 +9801 ./prep_dataset/ILSVRC2012_val_00019026.bin 224 224 +9802 ./prep_dataset/ILSVRC2012_val_00037379.bin 224 224 +9803 ./prep_dataset/ILSVRC2012_val_00030103.bin 224 224 +9804 ./prep_dataset/ILSVRC2012_val_00040324.bin 224 224 +9805 ./prep_dataset/ILSVRC2012_val_00028029.bin 224 224 +9806 ./prep_dataset/ILSVRC2012_val_00020102.bin 224 224 +9807 ./prep_dataset/ILSVRC2012_val_00002979.bin 224 224 +9808 ./prep_dataset/ILSVRC2012_val_00029063.bin 224 224 +9809 ./prep_dataset/ILSVRC2012_val_00018590.bin 224 224 +9810 ./prep_dataset/ILSVRC2012_val_00018537.bin 224 224 +9811 ./prep_dataset/ILSVRC2012_val_00025987.bin 224 224 +9812 ./prep_dataset/ILSVRC2012_val_00017826.bin 224 224 +9813 ./prep_dataset/ILSVRC2012_val_00045823.bin 224 224 +9814 ./prep_dataset/ILSVRC2012_val_00017982.bin 224 224 +9815 ./prep_dataset/ILSVRC2012_val_00037729.bin 224 224 +9816 ./prep_dataset/ILSVRC2012_val_00043173.bin 224 224 +9817 ./prep_dataset/ILSVRC2012_val_00039806.bin 224 224 +9818 ./prep_dataset/ILSVRC2012_val_00007957.bin 224 224 +9819 ./prep_dataset/ILSVRC2012_val_00049045.bin 224 224 +9820 ./prep_dataset/ILSVRC2012_val_00021277.bin 224 224 +9821 ./prep_dataset/ILSVRC2012_val_00008467.bin 224 224 +9822 ./prep_dataset/ILSVRC2012_val_00047790.bin 224 224 +9823 ./prep_dataset/ILSVRC2012_val_00008485.bin 224 224 +9824 ./prep_dataset/ILSVRC2012_val_00010812.bin 224 224 +9825 ./prep_dataset/ILSVRC2012_val_00009343.bin 224 224 +9826 ./prep_dataset/ILSVRC2012_val_00001643.bin 224 224 +9827 ./prep_dataset/ILSVRC2012_val_00027032.bin 224 224 +9828 ./prep_dataset/ILSVRC2012_val_00004104.bin 224 224 +9829 ./prep_dataset/ILSVRC2012_val_00013046.bin 224 224 +9830 ./prep_dataset/ILSVRC2012_val_00042353.bin 224 224 +9831 ./prep_dataset/ILSVRC2012_val_00019729.bin 224 224 +9832 ./prep_dataset/ILSVRC2012_val_00006581.bin 224 224 +9833 ./prep_dataset/ILSVRC2012_val_00011214.bin 224 224 +9834 ./prep_dataset/ILSVRC2012_val_00033186.bin 224 224 +9835 ./prep_dataset/ILSVRC2012_val_00030370.bin 224 224 +9836 ./prep_dataset/ILSVRC2012_val_00044197.bin 224 224 +9837 ./prep_dataset/ILSVRC2012_val_00037586.bin 224 224 +9838 ./prep_dataset/ILSVRC2012_val_00036954.bin 224 224 +9839 ./prep_dataset/ILSVRC2012_val_00013473.bin 224 224 +9840 ./prep_dataset/ILSVRC2012_val_00043559.bin 224 224 +9841 ./prep_dataset/ILSVRC2012_val_00002226.bin 224 224 +9842 ./prep_dataset/ILSVRC2012_val_00003333.bin 224 224 +9843 ./prep_dataset/ILSVRC2012_val_00024312.bin 224 224 +9844 ./prep_dataset/ILSVRC2012_val_00003446.bin 224 224 +9845 ./prep_dataset/ILSVRC2012_val_00024979.bin 224 224 +9846 ./prep_dataset/ILSVRC2012_val_00004252.bin 224 224 +9847 ./prep_dataset/ILSVRC2012_val_00044104.bin 224 224 +9848 ./prep_dataset/ILSVRC2012_val_00005173.bin 224 224 +9849 ./prep_dataset/ILSVRC2012_val_00018944.bin 224 224 +9850 ./prep_dataset/ILSVRC2012_val_00027760.bin 224 224 +9851 ./prep_dataset/ILSVRC2012_val_00046752.bin 224 224 +9852 ./prep_dataset/ILSVRC2012_val_00047892.bin 224 224 +9853 ./prep_dataset/ILSVRC2012_val_00024562.bin 224 224 +9854 ./prep_dataset/ILSVRC2012_val_00021235.bin 224 224 +9855 ./prep_dataset/ILSVRC2012_val_00029240.bin 224 224 +9856 ./prep_dataset/ILSVRC2012_val_00018290.bin 224 224 +9857 ./prep_dataset/ILSVRC2012_val_00026291.bin 224 224 +9858 ./prep_dataset/ILSVRC2012_val_00014020.bin 224 224 +9859 ./prep_dataset/ILSVRC2012_val_00032503.bin 224 224 +9860 ./prep_dataset/ILSVRC2012_val_00015489.bin 224 224 +9861 ./prep_dataset/ILSVRC2012_val_00042591.bin 224 224 +9862 ./prep_dataset/ILSVRC2012_val_00039061.bin 224 224 +9863 ./prep_dataset/ILSVRC2012_val_00012253.bin 224 224 +9864 ./prep_dataset/ILSVRC2012_val_00031929.bin 224 224 +9865 ./prep_dataset/ILSVRC2012_val_00030854.bin 224 224 +9866 ./prep_dataset/ILSVRC2012_val_00031274.bin 224 224 +9867 ./prep_dataset/ILSVRC2012_val_00002198.bin 224 224 +9868 ./prep_dataset/ILSVRC2012_val_00010247.bin 224 224 +9869 ./prep_dataset/ILSVRC2012_val_00025883.bin 224 224 +9870 ./prep_dataset/ILSVRC2012_val_00029083.bin 224 224 +9871 ./prep_dataset/ILSVRC2012_val_00034806.bin 224 224 +9872 ./prep_dataset/ILSVRC2012_val_00039887.bin 224 224 +9873 ./prep_dataset/ILSVRC2012_val_00032465.bin 224 224 +9874 ./prep_dataset/ILSVRC2012_val_00039967.bin 224 224 +9875 ./prep_dataset/ILSVRC2012_val_00005284.bin 224 224 +9876 ./prep_dataset/ILSVRC2012_val_00045391.bin 224 224 +9877 ./prep_dataset/ILSVRC2012_val_00013767.bin 224 224 +9878 ./prep_dataset/ILSVRC2012_val_00011603.bin 224 224 +9879 ./prep_dataset/ILSVRC2012_val_00022249.bin 224 224 +9880 ./prep_dataset/ILSVRC2012_val_00043670.bin 224 224 +9881 ./prep_dataset/ILSVRC2012_val_00047933.bin 224 224 +9882 ./prep_dataset/ILSVRC2012_val_00031545.bin 224 224 +9883 ./prep_dataset/ILSVRC2012_val_00008762.bin 224 224 +9884 ./prep_dataset/ILSVRC2012_val_00041537.bin 224 224 +9885 ./prep_dataset/ILSVRC2012_val_00023806.bin 224 224 +9886 ./prep_dataset/ILSVRC2012_val_00002526.bin 224 224 +9887 ./prep_dataset/ILSVRC2012_val_00033342.bin 224 224 +9888 ./prep_dataset/ILSVRC2012_val_00026548.bin 224 224 +9889 ./prep_dataset/ILSVRC2012_val_00046361.bin 224 224 +9890 ./prep_dataset/ILSVRC2012_val_00033812.bin 224 224 +9891 ./prep_dataset/ILSVRC2012_val_00041814.bin 224 224 +9892 ./prep_dataset/ILSVRC2012_val_00035389.bin 224 224 +9893 ./prep_dataset/ILSVRC2012_val_00021254.bin 224 224 +9894 ./prep_dataset/ILSVRC2012_val_00022984.bin 224 224 +9895 ./prep_dataset/ILSVRC2012_val_00043400.bin 224 224 +9896 ./prep_dataset/ILSVRC2012_val_00006435.bin 224 224 +9897 ./prep_dataset/ILSVRC2012_val_00043356.bin 224 224 +9898 ./prep_dataset/ILSVRC2012_val_00011846.bin 224 224 +9899 ./prep_dataset/ILSVRC2012_val_00015319.bin 224 224 +9900 ./prep_dataset/ILSVRC2012_val_00033611.bin 224 224 +9901 ./prep_dataset/ILSVRC2012_val_00012943.bin 224 224 +9902 ./prep_dataset/ILSVRC2012_val_00012828.bin 224 224 +9903 ./prep_dataset/ILSVRC2012_val_00040306.bin 224 224 +9904 ./prep_dataset/ILSVRC2012_val_00002737.bin 224 224 +9905 ./prep_dataset/ILSVRC2012_val_00017066.bin 224 224 +9906 ./prep_dataset/ILSVRC2012_val_00022335.bin 224 224 +9907 ./prep_dataset/ILSVRC2012_val_00015573.bin 224 224 +9908 ./prep_dataset/ILSVRC2012_val_00019933.bin 224 224 +9909 ./prep_dataset/ILSVRC2012_val_00000511.bin 224 224 +9910 ./prep_dataset/ILSVRC2012_val_00009337.bin 224 224 +9911 ./prep_dataset/ILSVRC2012_val_00026344.bin 224 224 +9912 ./prep_dataset/ILSVRC2012_val_00024783.bin 224 224 +9913 ./prep_dataset/ILSVRC2012_val_00014191.bin 224 224 +9914 ./prep_dataset/ILSVRC2012_val_00013269.bin 224 224 +9915 ./prep_dataset/ILSVRC2012_val_00035350.bin 224 224 +9916 ./prep_dataset/ILSVRC2012_val_00008792.bin 224 224 +9917 ./prep_dataset/ILSVRC2012_val_00048551.bin 224 224 +9918 ./prep_dataset/ILSVRC2012_val_00025410.bin 224 224 +9919 ./prep_dataset/ILSVRC2012_val_00020778.bin 224 224 +9920 ./prep_dataset/ILSVRC2012_val_00044328.bin 224 224 +9921 ./prep_dataset/ILSVRC2012_val_00028104.bin 224 224 +9922 ./prep_dataset/ILSVRC2012_val_00011794.bin 224 224 +9923 ./prep_dataset/ILSVRC2012_val_00042484.bin 224 224 +9924 ./prep_dataset/ILSVRC2012_val_00008624.bin 224 224 +9925 ./prep_dataset/ILSVRC2012_val_00015593.bin 224 224 +9926 ./prep_dataset/ILSVRC2012_val_00041154.bin 224 224 +9927 ./prep_dataset/ILSVRC2012_val_00049554.bin 224 224 +9928 ./prep_dataset/ILSVRC2012_val_00011391.bin 224 224 +9929 ./prep_dataset/ILSVRC2012_val_00004745.bin 224 224 +9930 ./prep_dataset/ILSVRC2012_val_00000881.bin 224 224 +9931 ./prep_dataset/ILSVRC2012_val_00032378.bin 224 224 +9932 ./prep_dataset/ILSVRC2012_val_00013985.bin 224 224 +9933 ./prep_dataset/ILSVRC2012_val_00017850.bin 224 224 +9934 ./prep_dataset/ILSVRC2012_val_00044049.bin 224 224 +9935 ./prep_dataset/ILSVRC2012_val_00025496.bin 224 224 +9936 ./prep_dataset/ILSVRC2012_val_00006780.bin 224 224 +9937 ./prep_dataset/ILSVRC2012_val_00049314.bin 224 224 +9938 ./prep_dataset/ILSVRC2012_val_00015834.bin 224 224 +9939 ./prep_dataset/ILSVRC2012_val_00044828.bin 224 224 +9940 ./prep_dataset/ILSVRC2012_val_00012362.bin 224 224 +9941 ./prep_dataset/ILSVRC2012_val_00019858.bin 224 224 +9942 ./prep_dataset/ILSVRC2012_val_00003459.bin 224 224 +9943 ./prep_dataset/ILSVRC2012_val_00023288.bin 224 224 +9944 ./prep_dataset/ILSVRC2012_val_00042003.bin 224 224 +9945 ./prep_dataset/ILSVRC2012_val_00031170.bin 224 224 +9946 ./prep_dataset/ILSVRC2012_val_00025405.bin 224 224 +9947 ./prep_dataset/ILSVRC2012_val_00044089.bin 224 224 +9948 ./prep_dataset/ILSVRC2012_val_00028545.bin 224 224 +9949 ./prep_dataset/ILSVRC2012_val_00034837.bin 224 224 +9950 ./prep_dataset/ILSVRC2012_val_00045764.bin 224 224 +9951 ./prep_dataset/ILSVRC2012_val_00015683.bin 224 224 +9952 ./prep_dataset/ILSVRC2012_val_00038815.bin 224 224 +9953 ./prep_dataset/ILSVRC2012_val_00039944.bin 224 224 +9954 ./prep_dataset/ILSVRC2012_val_00003642.bin 224 224 +9955 ./prep_dataset/ILSVRC2012_val_00037686.bin 224 224 +9956 ./prep_dataset/ILSVRC2012_val_00005264.bin 224 224 +9957 ./prep_dataset/ILSVRC2012_val_00049215.bin 224 224 +9958 ./prep_dataset/ILSVRC2012_val_00002804.bin 224 224 +9959 ./prep_dataset/ILSVRC2012_val_00025245.bin 224 224 +9960 ./prep_dataset/ILSVRC2012_val_00019425.bin 224 224 +9961 ./prep_dataset/ILSVRC2012_val_00049689.bin 224 224 +9962 ./prep_dataset/ILSVRC2012_val_00007945.bin 224 224 +9963 ./prep_dataset/ILSVRC2012_val_00017592.bin 224 224 +9964 ./prep_dataset/ILSVRC2012_val_00034300.bin 224 224 +9965 ./prep_dataset/ILSVRC2012_val_00012798.bin 224 224 +9966 ./prep_dataset/ILSVRC2012_val_00045122.bin 224 224 +9967 ./prep_dataset/ILSVRC2012_val_00005778.bin 224 224 +9968 ./prep_dataset/ILSVRC2012_val_00015879.bin 224 224 +9969 ./prep_dataset/ILSVRC2012_val_00001770.bin 224 224 +9970 ./prep_dataset/ILSVRC2012_val_00004941.bin 224 224 +9971 ./prep_dataset/ILSVRC2012_val_00018038.bin 224 224 +9972 ./prep_dataset/ILSVRC2012_val_00019465.bin 224 224 +9973 ./prep_dataset/ILSVRC2012_val_00011891.bin 224 224 +9974 ./prep_dataset/ILSVRC2012_val_00013936.bin 224 224 +9975 ./prep_dataset/ILSVRC2012_val_00049517.bin 224 224 +9976 ./prep_dataset/ILSVRC2012_val_00031741.bin 224 224 +9977 ./prep_dataset/ILSVRC2012_val_00047485.bin 224 224 +9978 ./prep_dataset/ILSVRC2012_val_00033646.bin 224 224 +9979 ./prep_dataset/ILSVRC2012_val_00027079.bin 224 224 +9980 ./prep_dataset/ILSVRC2012_val_00012989.bin 224 224 +9981 ./prep_dataset/ILSVRC2012_val_00022899.bin 224 224 +9982 ./prep_dataset/ILSVRC2012_val_00030490.bin 224 224 +9983 ./prep_dataset/ILSVRC2012_val_00033561.bin 224 224 +9984 ./prep_dataset/ILSVRC2012_val_00049099.bin 224 224 +9985 ./prep_dataset/ILSVRC2012_val_00013059.bin 224 224 +9986 ./prep_dataset/ILSVRC2012_val_00033471.bin 224 224 +9987 ./prep_dataset/ILSVRC2012_val_00045322.bin 224 224 +9988 ./prep_dataset/ILSVRC2012_val_00003226.bin 224 224 +9989 ./prep_dataset/ILSVRC2012_val_00046395.bin 224 224 +9990 ./prep_dataset/ILSVRC2012_val_00017364.bin 224 224 +9991 ./prep_dataset/ILSVRC2012_val_00005857.bin 224 224 +9992 ./prep_dataset/ILSVRC2012_val_00020329.bin 224 224 +9993 ./prep_dataset/ILSVRC2012_val_00013772.bin 224 224 +9994 ./prep_dataset/ILSVRC2012_val_00014035.bin 224 224 +9995 ./prep_dataset/ILSVRC2012_val_00033643.bin 224 224 +9996 ./prep_dataset/ILSVRC2012_val_00026390.bin 224 224 +9997 ./prep_dataset/ILSVRC2012_val_00046055.bin 224 224 +9998 ./prep_dataset/ILSVRC2012_val_00009166.bin 224 224 +9999 ./prep_dataset/ILSVRC2012_val_00033277.bin 224 224 +10000 ./prep_dataset/ILSVRC2012_val_00001835.bin 224 224 +10001 ./prep_dataset/ILSVRC2012_val_00007005.bin 224 224 +10002 ./prep_dataset/ILSVRC2012_val_00036425.bin 224 224 +10003 ./prep_dataset/ILSVRC2012_val_00000618.bin 224 224 +10004 ./prep_dataset/ILSVRC2012_val_00022226.bin 224 224 +10005 ./prep_dataset/ILSVRC2012_val_00017397.bin 224 224 +10006 ./prep_dataset/ILSVRC2012_val_00030838.bin 224 224 +10007 ./prep_dataset/ILSVRC2012_val_00037229.bin 224 224 +10008 ./prep_dataset/ILSVRC2012_val_00037106.bin 224 224 +10009 ./prep_dataset/ILSVRC2012_val_00001177.bin 224 224 +10010 ./prep_dataset/ILSVRC2012_val_00022332.bin 224 224 +10011 ./prep_dataset/ILSVRC2012_val_00002588.bin 224 224 +10012 ./prep_dataset/ILSVRC2012_val_00010784.bin 224 224 +10013 ./prep_dataset/ILSVRC2012_val_00023811.bin 224 224 +10014 ./prep_dataset/ILSVRC2012_val_00013988.bin 224 224 +10015 ./prep_dataset/ILSVRC2012_val_00024052.bin 224 224 +10016 ./prep_dataset/ILSVRC2012_val_00028591.bin 224 224 +10017 ./prep_dataset/ILSVRC2012_val_00004664.bin 224 224 +10018 ./prep_dataset/ILSVRC2012_val_00049101.bin 224 224 +10019 ./prep_dataset/ILSVRC2012_val_00005489.bin 224 224 +10020 ./prep_dataset/ILSVRC2012_val_00029924.bin 224 224 +10021 ./prep_dataset/ILSVRC2012_val_00003006.bin 224 224 +10022 ./prep_dataset/ILSVRC2012_val_00021066.bin 224 224 +10023 ./prep_dataset/ILSVRC2012_val_00049052.bin 224 224 +10024 ./prep_dataset/ILSVRC2012_val_00020159.bin 224 224 +10025 ./prep_dataset/ILSVRC2012_val_00000531.bin 224 224 +10026 ./prep_dataset/ILSVRC2012_val_00039180.bin 224 224 +10027 ./prep_dataset/ILSVRC2012_val_00041098.bin 224 224 +10028 ./prep_dataset/ILSVRC2012_val_00001682.bin 224 224 +10029 ./prep_dataset/ILSVRC2012_val_00045056.bin 224 224 +10030 ./prep_dataset/ILSVRC2012_val_00004801.bin 224 224 +10031 ./prep_dataset/ILSVRC2012_val_00030497.bin 224 224 +10032 ./prep_dataset/ILSVRC2012_val_00002881.bin 224 224 +10033 ./prep_dataset/ILSVRC2012_val_00028905.bin 224 224 +10034 ./prep_dataset/ILSVRC2012_val_00030827.bin 224 224 +10035 ./prep_dataset/ILSVRC2012_val_00008890.bin 224 224 +10036 ./prep_dataset/ILSVRC2012_val_00041490.bin 224 224 +10037 ./prep_dataset/ILSVRC2012_val_00004711.bin 224 224 +10038 ./prep_dataset/ILSVRC2012_val_00022156.bin 224 224 +10039 ./prep_dataset/ILSVRC2012_val_00012896.bin 224 224 +10040 ./prep_dataset/ILSVRC2012_val_00016945.bin 224 224 +10041 ./prep_dataset/ILSVRC2012_val_00025118.bin 224 224 +10042 ./prep_dataset/ILSVRC2012_val_00038704.bin 224 224 +10043 ./prep_dataset/ILSVRC2012_val_00000306.bin 224 224 +10044 ./prep_dataset/ILSVRC2012_val_00026952.bin 224 224 +10045 ./prep_dataset/ILSVRC2012_val_00010018.bin 224 224 +10046 ./prep_dataset/ILSVRC2012_val_00008687.bin 224 224 +10047 ./prep_dataset/ILSVRC2012_val_00038768.bin 224 224 +10048 ./prep_dataset/ILSVRC2012_val_00046121.bin 224 224 +10049 ./prep_dataset/ILSVRC2012_val_00036974.bin 224 224 +10050 ./prep_dataset/ILSVRC2012_val_00025151.bin 224 224 +10051 ./prep_dataset/ILSVRC2012_val_00046901.bin 224 224 +10052 ./prep_dataset/ILSVRC2012_val_00039962.bin 224 224 +10053 ./prep_dataset/ILSVRC2012_val_00006524.bin 224 224 +10054 ./prep_dataset/ILSVRC2012_val_00025080.bin 224 224 +10055 ./prep_dataset/ILSVRC2012_val_00023773.bin 224 224 +10056 ./prep_dataset/ILSVRC2012_val_00032394.bin 224 224 +10057 ./prep_dataset/ILSVRC2012_val_00005465.bin 224 224 +10058 ./prep_dataset/ILSVRC2012_val_00033126.bin 224 224 +10059 ./prep_dataset/ILSVRC2012_val_00048561.bin 224 224 +10060 ./prep_dataset/ILSVRC2012_val_00017611.bin 224 224 +10061 ./prep_dataset/ILSVRC2012_val_00004578.bin 224 224 +10062 ./prep_dataset/ILSVRC2012_val_00047108.bin 224 224 +10063 ./prep_dataset/ILSVRC2012_val_00029518.bin 224 224 +10064 ./prep_dataset/ILSVRC2012_val_00016019.bin 224 224 +10065 ./prep_dataset/ILSVRC2012_val_00044767.bin 224 224 +10066 ./prep_dataset/ILSVRC2012_val_00033937.bin 224 224 +10067 ./prep_dataset/ILSVRC2012_val_00028253.bin 224 224 +10068 ./prep_dataset/ILSVRC2012_val_00039150.bin 224 224 +10069 ./prep_dataset/ILSVRC2012_val_00027126.bin 224 224 +10070 ./prep_dataset/ILSVRC2012_val_00021815.bin 224 224 +10071 ./prep_dataset/ILSVRC2012_val_00013785.bin 224 224 +10072 ./prep_dataset/ILSVRC2012_val_00009562.bin 224 224 +10073 ./prep_dataset/ILSVRC2012_val_00030553.bin 224 224 +10074 ./prep_dataset/ILSVRC2012_val_00016802.bin 224 224 +10075 ./prep_dataset/ILSVRC2012_val_00012679.bin 224 224 +10076 ./prep_dataset/ILSVRC2012_val_00014759.bin 224 224 +10077 ./prep_dataset/ILSVRC2012_val_00034071.bin 224 224 +10078 ./prep_dataset/ILSVRC2012_val_00042391.bin 224 224 +10079 ./prep_dataset/ILSVRC2012_val_00015281.bin 224 224 +10080 ./prep_dataset/ILSVRC2012_val_00020915.bin 224 224 +10081 ./prep_dataset/ILSVRC2012_val_00012252.bin 224 224 +10082 ./prep_dataset/ILSVRC2012_val_00041804.bin 224 224 +10083 ./prep_dataset/ILSVRC2012_val_00017488.bin 224 224 +10084 ./prep_dataset/ILSVRC2012_val_00028637.bin 224 224 +10085 ./prep_dataset/ILSVRC2012_val_00039284.bin 224 224 +10086 ./prep_dataset/ILSVRC2012_val_00034480.bin 224 224 +10087 ./prep_dataset/ILSVRC2012_val_00040757.bin 224 224 +10088 ./prep_dataset/ILSVRC2012_val_00036942.bin 224 224 +10089 ./prep_dataset/ILSVRC2012_val_00002845.bin 224 224 +10090 ./prep_dataset/ILSVRC2012_val_00006594.bin 224 224 +10091 ./prep_dataset/ILSVRC2012_val_00038053.bin 224 224 +10092 ./prep_dataset/ILSVRC2012_val_00041712.bin 224 224 +10093 ./prep_dataset/ILSVRC2012_val_00001840.bin 224 224 +10094 ./prep_dataset/ILSVRC2012_val_00044858.bin 224 224 +10095 ./prep_dataset/ILSVRC2012_val_00017383.bin 224 224 +10096 ./prep_dataset/ILSVRC2012_val_00014899.bin 224 224 +10097 ./prep_dataset/ILSVRC2012_val_00024337.bin 224 224 +10098 ./prep_dataset/ILSVRC2012_val_00032739.bin 224 224 +10099 ./prep_dataset/ILSVRC2012_val_00033498.bin 224 224 +10100 ./prep_dataset/ILSVRC2012_val_00045621.bin 224 224 +10101 ./prep_dataset/ILSVRC2012_val_00041470.bin 224 224 +10102 ./prep_dataset/ILSVRC2012_val_00046459.bin 224 224 +10103 ./prep_dataset/ILSVRC2012_val_00000183.bin 224 224 +10104 ./prep_dataset/ILSVRC2012_val_00024260.bin 224 224 +10105 ./prep_dataset/ILSVRC2012_val_00017686.bin 224 224 +10106 ./prep_dataset/ILSVRC2012_val_00024372.bin 224 224 +10107 ./prep_dataset/ILSVRC2012_val_00011274.bin 224 224 +10108 ./prep_dataset/ILSVRC2012_val_00009775.bin 224 224 +10109 ./prep_dataset/ILSVRC2012_val_00025175.bin 224 224 +10110 ./prep_dataset/ILSVRC2012_val_00003205.bin 224 224 +10111 ./prep_dataset/ILSVRC2012_val_00018531.bin 224 224 +10112 ./prep_dataset/ILSVRC2012_val_00029865.bin 224 224 +10113 ./prep_dataset/ILSVRC2012_val_00032727.bin 224 224 +10114 ./prep_dataset/ILSVRC2012_val_00020111.bin 224 224 +10115 ./prep_dataset/ILSVRC2012_val_00001634.bin 224 224 +10116 ./prep_dataset/ILSVRC2012_val_00048773.bin 224 224 +10117 ./prep_dataset/ILSVRC2012_val_00002125.bin 224 224 +10118 ./prep_dataset/ILSVRC2012_val_00022781.bin 224 224 +10119 ./prep_dataset/ILSVRC2012_val_00044390.bin 224 224 +10120 ./prep_dataset/ILSVRC2012_val_00010383.bin 224 224 +10121 ./prep_dataset/ILSVRC2012_val_00037738.bin 224 224 +10122 ./prep_dataset/ILSVRC2012_val_00026154.bin 224 224 +10123 ./prep_dataset/ILSVRC2012_val_00043424.bin 224 224 +10124 ./prep_dataset/ILSVRC2012_val_00020503.bin 224 224 +10125 ./prep_dataset/ILSVRC2012_val_00007076.bin 224 224 +10126 ./prep_dataset/ILSVRC2012_val_00002699.bin 224 224 +10127 ./prep_dataset/ILSVRC2012_val_00001604.bin 224 224 +10128 ./prep_dataset/ILSVRC2012_val_00012785.bin 224 224 +10129 ./prep_dataset/ILSVRC2012_val_00049955.bin 224 224 +10130 ./prep_dataset/ILSVRC2012_val_00040185.bin 224 224 +10131 ./prep_dataset/ILSVRC2012_val_00008492.bin 224 224 +10132 ./prep_dataset/ILSVRC2012_val_00001531.bin 224 224 +10133 ./prep_dataset/ILSVRC2012_val_00012383.bin 224 224 +10134 ./prep_dataset/ILSVRC2012_val_00048515.bin 224 224 +10135 ./prep_dataset/ILSVRC2012_val_00005104.bin 224 224 +10136 ./prep_dataset/ILSVRC2012_val_00035777.bin 224 224 +10137 ./prep_dataset/ILSVRC2012_val_00048659.bin 224 224 +10138 ./prep_dataset/ILSVRC2012_val_00015480.bin 224 224 +10139 ./prep_dataset/ILSVRC2012_val_00001878.bin 224 224 +10140 ./prep_dataset/ILSVRC2012_val_00039424.bin 224 224 +10141 ./prep_dataset/ILSVRC2012_val_00010914.bin 224 224 +10142 ./prep_dataset/ILSVRC2012_val_00027128.bin 224 224 +10143 ./prep_dataset/ILSVRC2012_val_00018065.bin 224 224 +10144 ./prep_dataset/ILSVRC2012_val_00023634.bin 224 224 +10145 ./prep_dataset/ILSVRC2012_val_00030522.bin 224 224 +10146 ./prep_dataset/ILSVRC2012_val_00032748.bin 224 224 +10147 ./prep_dataset/ILSVRC2012_val_00006836.bin 224 224 +10148 ./prep_dataset/ILSVRC2012_val_00045467.bin 224 224 +10149 ./prep_dataset/ILSVRC2012_val_00049090.bin 224 224 +10150 ./prep_dataset/ILSVRC2012_val_00046214.bin 224 224 +10151 ./prep_dataset/ILSVRC2012_val_00010517.bin 224 224 +10152 ./prep_dataset/ILSVRC2012_val_00027991.bin 224 224 +10153 ./prep_dataset/ILSVRC2012_val_00013200.bin 224 224 +10154 ./prep_dataset/ILSVRC2012_val_00004580.bin 224 224 +10155 ./prep_dataset/ILSVRC2012_val_00032711.bin 224 224 +10156 ./prep_dataset/ILSVRC2012_val_00039616.bin 224 224 +10157 ./prep_dataset/ILSVRC2012_val_00048801.bin 224 224 +10158 ./prep_dataset/ILSVRC2012_val_00020609.bin 224 224 +10159 ./prep_dataset/ILSVRC2012_val_00021897.bin 224 224 +10160 ./prep_dataset/ILSVRC2012_val_00018714.bin 224 224 +10161 ./prep_dataset/ILSVRC2012_val_00043652.bin 224 224 +10162 ./prep_dataset/ILSVRC2012_val_00008574.bin 224 224 +10163 ./prep_dataset/ILSVRC2012_val_00016897.bin 224 224 +10164 ./prep_dataset/ILSVRC2012_val_00039373.bin 224 224 +10165 ./prep_dataset/ILSVRC2012_val_00005525.bin 224 224 +10166 ./prep_dataset/ILSVRC2012_val_00003391.bin 224 224 +10167 ./prep_dataset/ILSVRC2012_val_00003669.bin 224 224 +10168 ./prep_dataset/ILSVRC2012_val_00001096.bin 224 224 +10169 ./prep_dataset/ILSVRC2012_val_00042895.bin 224 224 +10170 ./prep_dataset/ILSVRC2012_val_00034429.bin 224 224 +10171 ./prep_dataset/ILSVRC2012_val_00027814.bin 224 224 +10172 ./prep_dataset/ILSVRC2012_val_00011286.bin 224 224 +10173 ./prep_dataset/ILSVRC2012_val_00041666.bin 224 224 +10174 ./prep_dataset/ILSVRC2012_val_00034920.bin 224 224 +10175 ./prep_dataset/ILSVRC2012_val_00009078.bin 224 224 +10176 ./prep_dataset/ILSVRC2012_val_00031417.bin 224 224 +10177 ./prep_dataset/ILSVRC2012_val_00005049.bin 224 224 +10178 ./prep_dataset/ILSVRC2012_val_00039342.bin 224 224 +10179 ./prep_dataset/ILSVRC2012_val_00045093.bin 224 224 +10180 ./prep_dataset/ILSVRC2012_val_00033511.bin 224 224 +10181 ./prep_dataset/ILSVRC2012_val_00021033.bin 224 224 +10182 ./prep_dataset/ILSVRC2012_val_00006790.bin 224 224 +10183 ./prep_dataset/ILSVRC2012_val_00023671.bin 224 224 +10184 ./prep_dataset/ILSVRC2012_val_00019815.bin 224 224 +10185 ./prep_dataset/ILSVRC2012_val_00038617.bin 224 224 +10186 ./prep_dataset/ILSVRC2012_val_00006719.bin 224 224 +10187 ./prep_dataset/ILSVRC2012_val_00033593.bin 224 224 +10188 ./prep_dataset/ILSVRC2012_val_00028743.bin 224 224 +10189 ./prep_dataset/ILSVRC2012_val_00029866.bin 224 224 +10190 ./prep_dataset/ILSVRC2012_val_00023167.bin 224 224 +10191 ./prep_dataset/ILSVRC2012_val_00044853.bin 224 224 +10192 ./prep_dataset/ILSVRC2012_val_00045398.bin 224 224 +10193 ./prep_dataset/ILSVRC2012_val_00031488.bin 224 224 +10194 ./prep_dataset/ILSVRC2012_val_00017055.bin 224 224 +10195 ./prep_dataset/ILSVRC2012_val_00044165.bin 224 224 +10196 ./prep_dataset/ILSVRC2012_val_00023084.bin 224 224 +10197 ./prep_dataset/ILSVRC2012_val_00003203.bin 224 224 +10198 ./prep_dataset/ILSVRC2012_val_00017365.bin 224 224 +10199 ./prep_dataset/ILSVRC2012_val_00003894.bin 224 224 +10200 ./prep_dataset/ILSVRC2012_val_00013700.bin 224 224 +10201 ./prep_dataset/ILSVRC2012_val_00023957.bin 224 224 +10202 ./prep_dataset/ILSVRC2012_val_00013878.bin 224 224 +10203 ./prep_dataset/ILSVRC2012_val_00003697.bin 224 224 +10204 ./prep_dataset/ILSVRC2012_val_00033318.bin 224 224 +10205 ./prep_dataset/ILSVRC2012_val_00019447.bin 224 224 +10206 ./prep_dataset/ILSVRC2012_val_00020169.bin 224 224 +10207 ./prep_dataset/ILSVRC2012_val_00039499.bin 224 224 +10208 ./prep_dataset/ILSVRC2012_val_00020213.bin 224 224 +10209 ./prep_dataset/ILSVRC2012_val_00043710.bin 224 224 +10210 ./prep_dataset/ILSVRC2012_val_00010920.bin 224 224 +10211 ./prep_dataset/ILSVRC2012_val_00009758.bin 224 224 +10212 ./prep_dataset/ILSVRC2012_val_00006187.bin 224 224 +10213 ./prep_dataset/ILSVRC2012_val_00002738.bin 224 224 +10214 ./prep_dataset/ILSVRC2012_val_00002570.bin 224 224 +10215 ./prep_dataset/ILSVRC2012_val_00001823.bin 224 224 +10216 ./prep_dataset/ILSVRC2012_val_00011340.bin 224 224 +10217 ./prep_dataset/ILSVRC2012_val_00017298.bin 224 224 +10218 ./prep_dataset/ILSVRC2012_val_00032942.bin 224 224 +10219 ./prep_dataset/ILSVRC2012_val_00029956.bin 224 224 +10220 ./prep_dataset/ILSVRC2012_val_00008801.bin 224 224 +10221 ./prep_dataset/ILSVRC2012_val_00014358.bin 224 224 +10222 ./prep_dataset/ILSVRC2012_val_00040212.bin 224 224 +10223 ./prep_dataset/ILSVRC2012_val_00027880.bin 224 224 +10224 ./prep_dataset/ILSVRC2012_val_00033069.bin 224 224 +10225 ./prep_dataset/ILSVRC2012_val_00030385.bin 224 224 +10226 ./prep_dataset/ILSVRC2012_val_00020982.bin 224 224 +10227 ./prep_dataset/ILSVRC2012_val_00014256.bin 224 224 +10228 ./prep_dataset/ILSVRC2012_val_00040070.bin 224 224 +10229 ./prep_dataset/ILSVRC2012_val_00049738.bin 224 224 +10230 ./prep_dataset/ILSVRC2012_val_00008864.bin 224 224 +10231 ./prep_dataset/ILSVRC2012_val_00004079.bin 224 224 +10232 ./prep_dataset/ILSVRC2012_val_00033079.bin 224 224 +10233 ./prep_dataset/ILSVRC2012_val_00001306.bin 224 224 +10234 ./prep_dataset/ILSVRC2012_val_00025544.bin 224 224 +10235 ./prep_dataset/ILSVRC2012_val_00048211.bin 224 224 +10236 ./prep_dataset/ILSVRC2012_val_00045006.bin 224 224 +10237 ./prep_dataset/ILSVRC2012_val_00002439.bin 224 224 +10238 ./prep_dataset/ILSVRC2012_val_00025144.bin 224 224 +10239 ./prep_dataset/ILSVRC2012_val_00006308.bin 224 224 +10240 ./prep_dataset/ILSVRC2012_val_00041493.bin 224 224 +10241 ./prep_dataset/ILSVRC2012_val_00038735.bin 224 224 +10242 ./prep_dataset/ILSVRC2012_val_00027155.bin 224 224 +10243 ./prep_dataset/ILSVRC2012_val_00002811.bin 224 224 +10244 ./prep_dataset/ILSVRC2012_val_00032569.bin 224 224 +10245 ./prep_dataset/ILSVRC2012_val_00027231.bin 224 224 +10246 ./prep_dataset/ILSVRC2012_val_00000772.bin 224 224 +10247 ./prep_dataset/ILSVRC2012_val_00032078.bin 224 224 +10248 ./prep_dataset/ILSVRC2012_val_00022902.bin 224 224 +10249 ./prep_dataset/ILSVRC2012_val_00040851.bin 224 224 +10250 ./prep_dataset/ILSVRC2012_val_00014109.bin 224 224 +10251 ./prep_dataset/ILSVRC2012_val_00045841.bin 224 224 +10252 ./prep_dataset/ILSVRC2012_val_00028826.bin 224 224 +10253 ./prep_dataset/ILSVRC2012_val_00009178.bin 224 224 +10254 ./prep_dataset/ILSVRC2012_val_00009028.bin 224 224 +10255 ./prep_dataset/ILSVRC2012_val_00043556.bin 224 224 +10256 ./prep_dataset/ILSVRC2012_val_00046128.bin 224 224 +10257 ./prep_dataset/ILSVRC2012_val_00033997.bin 224 224 +10258 ./prep_dataset/ILSVRC2012_val_00028841.bin 224 224 +10259 ./prep_dataset/ILSVRC2012_val_00015327.bin 224 224 +10260 ./prep_dataset/ILSVRC2012_val_00001980.bin 224 224 +10261 ./prep_dataset/ILSVRC2012_val_00023684.bin 224 224 +10262 ./prep_dataset/ILSVRC2012_val_00038961.bin 224 224 +10263 ./prep_dataset/ILSVRC2012_val_00001619.bin 224 224 +10264 ./prep_dataset/ILSVRC2012_val_00017205.bin 224 224 +10265 ./prep_dataset/ILSVRC2012_val_00017593.bin 224 224 +10266 ./prep_dataset/ILSVRC2012_val_00023749.bin 224 224 +10267 ./prep_dataset/ILSVRC2012_val_00011363.bin 224 224 +10268 ./prep_dataset/ILSVRC2012_val_00000711.bin 224 224 +10269 ./prep_dataset/ILSVRC2012_val_00019863.bin 224 224 +10270 ./prep_dataset/ILSVRC2012_val_00043856.bin 224 224 +10271 ./prep_dataset/ILSVRC2012_val_00033451.bin 224 224 +10272 ./prep_dataset/ILSVRC2012_val_00010238.bin 224 224 +10273 ./prep_dataset/ILSVRC2012_val_00026313.bin 224 224 +10274 ./prep_dataset/ILSVRC2012_val_00030388.bin 224 224 +10275 ./prep_dataset/ILSVRC2012_val_00011866.bin 224 224 +10276 ./prep_dataset/ILSVRC2012_val_00007007.bin 224 224 +10277 ./prep_dataset/ILSVRC2012_val_00034006.bin 224 224 +10278 ./prep_dataset/ILSVRC2012_val_00026381.bin 224 224 +10279 ./prep_dataset/ILSVRC2012_val_00040196.bin 224 224 +10280 ./prep_dataset/ILSVRC2012_val_00019884.bin 224 224 +10281 ./prep_dataset/ILSVRC2012_val_00021352.bin 224 224 +10282 ./prep_dataset/ILSVRC2012_val_00033523.bin 224 224 +10283 ./prep_dataset/ILSVRC2012_val_00015304.bin 224 224 +10284 ./prep_dataset/ILSVRC2012_val_00030948.bin 224 224 +10285 ./prep_dataset/ILSVRC2012_val_00014672.bin 224 224 +10286 ./prep_dataset/ILSVRC2012_val_00026657.bin 224 224 +10287 ./prep_dataset/ILSVRC2012_val_00004636.bin 224 224 +10288 ./prep_dataset/ILSVRC2012_val_00010413.bin 224 224 +10289 ./prep_dataset/ILSVRC2012_val_00000889.bin 224 224 +10290 ./prep_dataset/ILSVRC2012_val_00043232.bin 224 224 +10291 ./prep_dataset/ILSVRC2012_val_00007124.bin 224 224 +10292 ./prep_dataset/ILSVRC2012_val_00049783.bin 224 224 +10293 ./prep_dataset/ILSVRC2012_val_00001640.bin 224 224 +10294 ./prep_dataset/ILSVRC2012_val_00045486.bin 224 224 +10295 ./prep_dataset/ILSVRC2012_val_00009982.bin 224 224 +10296 ./prep_dataset/ILSVRC2012_val_00014454.bin 224 224 +10297 ./prep_dataset/ILSVRC2012_val_00001854.bin 224 224 +10298 ./prep_dataset/ILSVRC2012_val_00047974.bin 224 224 +10299 ./prep_dataset/ILSVRC2012_val_00032623.bin 224 224 +10300 ./prep_dataset/ILSVRC2012_val_00033768.bin 224 224 +10301 ./prep_dataset/ILSVRC2012_val_00048332.bin 224 224 +10302 ./prep_dataset/ILSVRC2012_val_00006243.bin 224 224 +10303 ./prep_dataset/ILSVRC2012_val_00015378.bin 224 224 +10304 ./prep_dataset/ILSVRC2012_val_00019985.bin 224 224 +10305 ./prep_dataset/ILSVRC2012_val_00045643.bin 224 224 +10306 ./prep_dataset/ILSVRC2012_val_00041907.bin 224 224 +10307 ./prep_dataset/ILSVRC2012_val_00023069.bin 224 224 +10308 ./prep_dataset/ILSVRC2012_val_00037674.bin 224 224 +10309 ./prep_dataset/ILSVRC2012_val_00005243.bin 224 224 +10310 ./prep_dataset/ILSVRC2012_val_00018741.bin 224 224 +10311 ./prep_dataset/ILSVRC2012_val_00028802.bin 224 224 +10312 ./prep_dataset/ILSVRC2012_val_00002561.bin 224 224 +10313 ./prep_dataset/ILSVRC2012_val_00030213.bin 224 224 +10314 ./prep_dataset/ILSVRC2012_val_00012965.bin 224 224 +10315 ./prep_dataset/ILSVRC2012_val_00039171.bin 224 224 +10316 ./prep_dataset/ILSVRC2012_val_00031825.bin 224 224 +10317 ./prep_dataset/ILSVRC2012_val_00024906.bin 224 224 +10318 ./prep_dataset/ILSVRC2012_val_00003025.bin 224 224 +10319 ./prep_dataset/ILSVRC2012_val_00029355.bin 224 224 +10320 ./prep_dataset/ILSVRC2012_val_00034167.bin 224 224 +10321 ./prep_dataset/ILSVRC2012_val_00025685.bin 224 224 +10322 ./prep_dataset/ILSVRC2012_val_00035961.bin 224 224 +10323 ./prep_dataset/ILSVRC2012_val_00038877.bin 224 224 +10324 ./prep_dataset/ILSVRC2012_val_00032128.bin 224 224 +10325 ./prep_dataset/ILSVRC2012_val_00036796.bin 224 224 +10326 ./prep_dataset/ILSVRC2012_val_00042637.bin 224 224 +10327 ./prep_dataset/ILSVRC2012_val_00044394.bin 224 224 +10328 ./prep_dataset/ILSVRC2012_val_00003781.bin 224 224 +10329 ./prep_dataset/ILSVRC2012_val_00048135.bin 224 224 +10330 ./prep_dataset/ILSVRC2012_val_00004747.bin 224 224 +10331 ./prep_dataset/ILSVRC2012_val_00001662.bin 224 224 +10332 ./prep_dataset/ILSVRC2012_val_00002998.bin 224 224 +10333 ./prep_dataset/ILSVRC2012_val_00048171.bin 224 224 +10334 ./prep_dataset/ILSVRC2012_val_00018654.bin 224 224 +10335 ./prep_dataset/ILSVRC2012_val_00046316.bin 224 224 +10336 ./prep_dataset/ILSVRC2012_val_00017074.bin 224 224 +10337 ./prep_dataset/ILSVRC2012_val_00045259.bin 224 224 +10338 ./prep_dataset/ILSVRC2012_val_00004493.bin 224 224 +10339 ./prep_dataset/ILSVRC2012_val_00009152.bin 224 224 +10340 ./prep_dataset/ILSVRC2012_val_00006277.bin 224 224 +10341 ./prep_dataset/ILSVRC2012_val_00027950.bin 224 224 +10342 ./prep_dataset/ILSVRC2012_val_00018043.bin 224 224 +10343 ./prep_dataset/ILSVRC2012_val_00030472.bin 224 224 +10344 ./prep_dataset/ILSVRC2012_val_00012722.bin 224 224 +10345 ./prep_dataset/ILSVRC2012_val_00041972.bin 224 224 +10346 ./prep_dataset/ILSVRC2012_val_00022356.bin 224 224 +10347 ./prep_dataset/ILSVRC2012_val_00042144.bin 224 224 +10348 ./prep_dataset/ILSVRC2012_val_00036712.bin 224 224 +10349 ./prep_dataset/ILSVRC2012_val_00027420.bin 224 224 +10350 ./prep_dataset/ILSVRC2012_val_00036276.bin 224 224 +10351 ./prep_dataset/ILSVRC2012_val_00028886.bin 224 224 +10352 ./prep_dataset/ILSVRC2012_val_00004193.bin 224 224 +10353 ./prep_dataset/ILSVRC2012_val_00028984.bin 224 224 +10354 ./prep_dataset/ILSVRC2012_val_00037600.bin 224 224 +10355 ./prep_dataset/ILSVRC2012_val_00030651.bin 224 224 +10356 ./prep_dataset/ILSVRC2012_val_00007933.bin 224 224 +10357 ./prep_dataset/ILSVRC2012_val_00030668.bin 224 224 +10358 ./prep_dataset/ILSVRC2012_val_00033344.bin 224 224 +10359 ./prep_dataset/ILSVRC2012_val_00005770.bin 224 224 +10360 ./prep_dataset/ILSVRC2012_val_00045052.bin 224 224 +10361 ./prep_dataset/ILSVRC2012_val_00021356.bin 224 224 +10362 ./prep_dataset/ILSVRC2012_val_00008905.bin 224 224 +10363 ./prep_dataset/ILSVRC2012_val_00046254.bin 224 224 +10364 ./prep_dataset/ILSVRC2012_val_00006678.bin 224 224 +10365 ./prep_dataset/ILSVRC2012_val_00030597.bin 224 224 +10366 ./prep_dataset/ILSVRC2012_val_00021695.bin 224 224 +10367 ./prep_dataset/ILSVRC2012_val_00018437.bin 224 224 +10368 ./prep_dataset/ILSVRC2012_val_00020925.bin 224 224 +10369 ./prep_dataset/ILSVRC2012_val_00010688.bin 224 224 +10370 ./prep_dataset/ILSVRC2012_val_00029454.bin 224 224 +10371 ./prep_dataset/ILSVRC2012_val_00025304.bin 224 224 +10372 ./prep_dataset/ILSVRC2012_val_00012600.bin 224 224 +10373 ./prep_dataset/ILSVRC2012_val_00008182.bin 224 224 +10374 ./prep_dataset/ILSVRC2012_val_00012893.bin 224 224 +10375 ./prep_dataset/ILSVRC2012_val_00033177.bin 224 224 +10376 ./prep_dataset/ILSVRC2012_val_00033200.bin 224 224 +10377 ./prep_dataset/ILSVRC2012_val_00041391.bin 224 224 +10378 ./prep_dataset/ILSVRC2012_val_00018332.bin 224 224 +10379 ./prep_dataset/ILSVRC2012_val_00027878.bin 224 224 +10380 ./prep_dataset/ILSVRC2012_val_00012548.bin 224 224 +10381 ./prep_dataset/ILSVRC2012_val_00026509.bin 224 224 +10382 ./prep_dataset/ILSVRC2012_val_00036883.bin 224 224 +10383 ./prep_dataset/ILSVRC2012_val_00021922.bin 224 224 +10384 ./prep_dataset/ILSVRC2012_val_00018032.bin 224 224 +10385 ./prep_dataset/ILSVRC2012_val_00006092.bin 224 224 +10386 ./prep_dataset/ILSVRC2012_val_00039790.bin 224 224 +10387 ./prep_dataset/ILSVRC2012_val_00032713.bin 224 224 +10388 ./prep_dataset/ILSVRC2012_val_00013170.bin 224 224 +10389 ./prep_dataset/ILSVRC2012_val_00004694.bin 224 224 +10390 ./prep_dataset/ILSVRC2012_val_00018429.bin 224 224 +10391 ./prep_dataset/ILSVRC2012_val_00005557.bin 224 224 +10392 ./prep_dataset/ILSVRC2012_val_00003653.bin 224 224 +10393 ./prep_dataset/ILSVRC2012_val_00017034.bin 224 224 +10394 ./prep_dataset/ILSVRC2012_val_00008198.bin 224 224 +10395 ./prep_dataset/ILSVRC2012_val_00001905.bin 224 224 +10396 ./prep_dataset/ILSVRC2012_val_00028298.bin 224 224 +10397 ./prep_dataset/ILSVRC2012_val_00032185.bin 224 224 +10398 ./prep_dataset/ILSVRC2012_val_00045910.bin 224 224 +10399 ./prep_dataset/ILSVRC2012_val_00005235.bin 224 224 +10400 ./prep_dataset/ILSVRC2012_val_00011026.bin 224 224 +10401 ./prep_dataset/ILSVRC2012_val_00022452.bin 224 224 +10402 ./prep_dataset/ILSVRC2012_val_00048996.bin 224 224 +10403 ./prep_dataset/ILSVRC2012_val_00044486.bin 224 224 +10404 ./prep_dataset/ILSVRC2012_val_00003840.bin 224 224 +10405 ./prep_dataset/ILSVRC2012_val_00016420.bin 224 224 +10406 ./prep_dataset/ILSVRC2012_val_00030291.bin 224 224 +10407 ./prep_dataset/ILSVRC2012_val_00008292.bin 224 224 +10408 ./prep_dataset/ILSVRC2012_val_00009442.bin 224 224 +10409 ./prep_dataset/ILSVRC2012_val_00021044.bin 224 224 +10410 ./prep_dataset/ILSVRC2012_val_00018052.bin 224 224 +10411 ./prep_dataset/ILSVRC2012_val_00002487.bin 224 224 +10412 ./prep_dataset/ILSVRC2012_val_00046625.bin 224 224 +10413 ./prep_dataset/ILSVRC2012_val_00012315.bin 224 224 +10414 ./prep_dataset/ILSVRC2012_val_00042045.bin 224 224 +10415 ./prep_dataset/ILSVRC2012_val_00037616.bin 224 224 +10416 ./prep_dataset/ILSVRC2012_val_00045280.bin 224 224 +10417 ./prep_dataset/ILSVRC2012_val_00035546.bin 224 224 +10418 ./prep_dataset/ILSVRC2012_val_00033039.bin 224 224 +10419 ./prep_dataset/ILSVRC2012_val_00042376.bin 224 224 +10420 ./prep_dataset/ILSVRC2012_val_00049127.bin 224 224 +10421 ./prep_dataset/ILSVRC2012_val_00022160.bin 224 224 +10422 ./prep_dataset/ILSVRC2012_val_00041876.bin 224 224 +10423 ./prep_dataset/ILSVRC2012_val_00010512.bin 224 224 +10424 ./prep_dataset/ILSVRC2012_val_00004095.bin 224 224 +10425 ./prep_dataset/ILSVRC2012_val_00007078.bin 224 224 +10426 ./prep_dataset/ILSVRC2012_val_00033202.bin 224 224 +10427 ./prep_dataset/ILSVRC2012_val_00014293.bin 224 224 +10428 ./prep_dataset/ILSVRC2012_val_00003663.bin 224 224 +10429 ./prep_dataset/ILSVRC2012_val_00011107.bin 224 224 +10430 ./prep_dataset/ILSVRC2012_val_00016523.bin 224 224 +10431 ./prep_dataset/ILSVRC2012_val_00034738.bin 224 224 +10432 ./prep_dataset/ILSVRC2012_val_00013272.bin 224 224 +10433 ./prep_dataset/ILSVRC2012_val_00001383.bin 224 224 +10434 ./prep_dataset/ILSVRC2012_val_00013917.bin 224 224 +10435 ./prep_dataset/ILSVRC2012_val_00016317.bin 224 224 +10436 ./prep_dataset/ILSVRC2012_val_00020898.bin 224 224 +10437 ./prep_dataset/ILSVRC2012_val_00019065.bin 224 224 +10438 ./prep_dataset/ILSVRC2012_val_00045086.bin 224 224 +10439 ./prep_dataset/ILSVRC2012_val_00007027.bin 224 224 +10440 ./prep_dataset/ILSVRC2012_val_00002213.bin 224 224 +10441 ./prep_dataset/ILSVRC2012_val_00018260.bin 224 224 +10442 ./prep_dataset/ILSVRC2012_val_00025931.bin 224 224 +10443 ./prep_dataset/ILSVRC2012_val_00015902.bin 224 224 +10444 ./prep_dataset/ILSVRC2012_val_00019657.bin 224 224 +10445 ./prep_dataset/ILSVRC2012_val_00002428.bin 224 224 +10446 ./prep_dataset/ILSVRC2012_val_00024489.bin 224 224 +10447 ./prep_dataset/ILSVRC2012_val_00049593.bin 224 224 +10448 ./prep_dataset/ILSVRC2012_val_00046059.bin 224 224 +10449 ./prep_dataset/ILSVRC2012_val_00043423.bin 224 224 +10450 ./prep_dataset/ILSVRC2012_val_00016790.bin 224 224 +10451 ./prep_dataset/ILSVRC2012_val_00048186.bin 224 224 +10452 ./prep_dataset/ILSVRC2012_val_00041733.bin 224 224 +10453 ./prep_dataset/ILSVRC2012_val_00007878.bin 224 224 +10454 ./prep_dataset/ILSVRC2012_val_00003754.bin 224 224 +10455 ./prep_dataset/ILSVRC2012_val_00045162.bin 224 224 +10456 ./prep_dataset/ILSVRC2012_val_00001174.bin 224 224 +10457 ./prep_dataset/ILSVRC2012_val_00041915.bin 224 224 +10458 ./prep_dataset/ILSVRC2012_val_00026627.bin 224 224 +10459 ./prep_dataset/ILSVRC2012_val_00026411.bin 224 224 +10460 ./prep_dataset/ILSVRC2012_val_00008119.bin 224 224 +10461 ./prep_dataset/ILSVRC2012_val_00036170.bin 224 224 +10462 ./prep_dataset/ILSVRC2012_val_00020176.bin 224 224 +10463 ./prep_dataset/ILSVRC2012_val_00024714.bin 224 224 +10464 ./prep_dataset/ILSVRC2012_val_00022680.bin 224 224 +10465 ./prep_dataset/ILSVRC2012_val_00032820.bin 224 224 +10466 ./prep_dataset/ILSVRC2012_val_00049521.bin 224 224 +10467 ./prep_dataset/ILSVRC2012_val_00019810.bin 224 224 +10468 ./prep_dataset/ILSVRC2012_val_00040536.bin 224 224 +10469 ./prep_dataset/ILSVRC2012_val_00031642.bin 224 224 +10470 ./prep_dataset/ILSVRC2012_val_00005017.bin 224 224 +10471 ./prep_dataset/ILSVRC2012_val_00046942.bin 224 224 +10472 ./prep_dataset/ILSVRC2012_val_00012206.bin 224 224 +10473 ./prep_dataset/ILSVRC2012_val_00001297.bin 224 224 +10474 ./prep_dataset/ILSVRC2012_val_00021038.bin 224 224 +10475 ./prep_dataset/ILSVRC2012_val_00028251.bin 224 224 +10476 ./prep_dataset/ILSVRC2012_val_00048487.bin 224 224 +10477 ./prep_dataset/ILSVRC2012_val_00035923.bin 224 224 +10478 ./prep_dataset/ILSVRC2012_val_00024907.bin 224 224 +10479 ./prep_dataset/ILSVRC2012_val_00029321.bin 224 224 +10480 ./prep_dataset/ILSVRC2012_val_00006831.bin 224 224 +10481 ./prep_dataset/ILSVRC2012_val_00013033.bin 224 224 +10482 ./prep_dataset/ILSVRC2012_val_00012234.bin 224 224 +10483 ./prep_dataset/ILSVRC2012_val_00002195.bin 224 224 +10484 ./prep_dataset/ILSVRC2012_val_00022928.bin 224 224 +10485 ./prep_dataset/ILSVRC2012_val_00034337.bin 224 224 +10486 ./prep_dataset/ILSVRC2012_val_00028436.bin 224 224 +10487 ./prep_dataset/ILSVRC2012_val_00045332.bin 224 224 +10488 ./prep_dataset/ILSVRC2012_val_00022803.bin 224 224 +10489 ./prep_dataset/ILSVRC2012_val_00010539.bin 224 224 +10490 ./prep_dataset/ILSVRC2012_val_00012232.bin 224 224 +10491 ./prep_dataset/ILSVRC2012_val_00022330.bin 224 224 +10492 ./prep_dataset/ILSVRC2012_val_00017318.bin 224 224 +10493 ./prep_dataset/ILSVRC2012_val_00005398.bin 224 224 +10494 ./prep_dataset/ILSVRC2012_val_00011237.bin 224 224 +10495 ./prep_dataset/ILSVRC2012_val_00043049.bin 224 224 +10496 ./prep_dataset/ILSVRC2012_val_00008645.bin 224 224 +10497 ./prep_dataset/ILSVRC2012_val_00020393.bin 224 224 +10498 ./prep_dataset/ILSVRC2012_val_00025262.bin 224 224 +10499 ./prep_dataset/ILSVRC2012_val_00010210.bin 224 224 +10500 ./prep_dataset/ILSVRC2012_val_00002395.bin 224 224 +10501 ./prep_dataset/ILSVRC2012_val_00022043.bin 224 224 +10502 ./prep_dataset/ILSVRC2012_val_00033986.bin 224 224 +10503 ./prep_dataset/ILSVRC2012_val_00032649.bin 224 224 +10504 ./prep_dataset/ILSVRC2012_val_00042029.bin 224 224 +10505 ./prep_dataset/ILSVRC2012_val_00020323.bin 224 224 +10506 ./prep_dataset/ILSVRC2012_val_00008955.bin 224 224 +10507 ./prep_dataset/ILSVRC2012_val_00002366.bin 224 224 +10508 ./prep_dataset/ILSVRC2012_val_00033446.bin 224 224 +10509 ./prep_dataset/ILSVRC2012_val_00021834.bin 224 224 +10510 ./prep_dataset/ILSVRC2012_val_00026362.bin 224 224 +10511 ./prep_dataset/ILSVRC2012_val_00016121.bin 224 224 +10512 ./prep_dataset/ILSVRC2012_val_00009361.bin 224 224 +10513 ./prep_dataset/ILSVRC2012_val_00043114.bin 224 224 +10514 ./prep_dataset/ILSVRC2012_val_00022428.bin 224 224 +10515 ./prep_dataset/ILSVRC2012_val_00008350.bin 224 224 +10516 ./prep_dataset/ILSVRC2012_val_00039360.bin 224 224 +10517 ./prep_dataset/ILSVRC2012_val_00011912.bin 224 224 +10518 ./prep_dataset/ILSVRC2012_val_00030164.bin 224 224 +10519 ./prep_dataset/ILSVRC2012_val_00047800.bin 224 224 +10520 ./prep_dataset/ILSVRC2012_val_00039049.bin 224 224 +10521 ./prep_dataset/ILSVRC2012_val_00027564.bin 224 224 +10522 ./prep_dataset/ILSVRC2012_val_00012458.bin 224 224 +10523 ./prep_dataset/ILSVRC2012_val_00044963.bin 224 224 +10524 ./prep_dataset/ILSVRC2012_val_00011504.bin 224 224 +10525 ./prep_dataset/ILSVRC2012_val_00029927.bin 224 224 +10526 ./prep_dataset/ILSVRC2012_val_00001647.bin 224 224 +10527 ./prep_dataset/ILSVRC2012_val_00036681.bin 224 224 +10528 ./prep_dataset/ILSVRC2012_val_00033932.bin 224 224 +10529 ./prep_dataset/ILSVRC2012_val_00044978.bin 224 224 +10530 ./prep_dataset/ILSVRC2012_val_00030635.bin 224 224 +10531 ./prep_dataset/ILSVRC2012_val_00016210.bin 224 224 +10532 ./prep_dataset/ILSVRC2012_val_00045943.bin 224 224 +10533 ./prep_dataset/ILSVRC2012_val_00004460.bin 224 224 +10534 ./prep_dataset/ILSVRC2012_val_00024728.bin 224 224 +10535 ./prep_dataset/ILSVRC2012_val_00000551.bin 224 224 +10536 ./prep_dataset/ILSVRC2012_val_00009536.bin 224 224 +10537 ./prep_dataset/ILSVRC2012_val_00033783.bin 224 224 +10538 ./prep_dataset/ILSVRC2012_val_00010411.bin 224 224 +10539 ./prep_dataset/ILSVRC2012_val_00028942.bin 224 224 +10540 ./prep_dataset/ILSVRC2012_val_00010403.bin 224 224 +10541 ./prep_dataset/ILSVRC2012_val_00007625.bin 224 224 +10542 ./prep_dataset/ILSVRC2012_val_00014115.bin 224 224 +10543 ./prep_dataset/ILSVRC2012_val_00005267.bin 224 224 +10544 ./prep_dataset/ILSVRC2012_val_00001274.bin 224 224 +10545 ./prep_dataset/ILSVRC2012_val_00045778.bin 224 224 +10546 ./prep_dataset/ILSVRC2012_val_00017772.bin 224 224 +10547 ./prep_dataset/ILSVRC2012_val_00004844.bin 224 224 +10548 ./prep_dataset/ILSVRC2012_val_00029274.bin 224 224 +10549 ./prep_dataset/ILSVRC2012_val_00026962.bin 224 224 +10550 ./prep_dataset/ILSVRC2012_val_00042208.bin 224 224 +10551 ./prep_dataset/ILSVRC2012_val_00037339.bin 224 224 +10552 ./prep_dataset/ILSVRC2012_val_00018835.bin 224 224 +10553 ./prep_dataset/ILSVRC2012_val_00040599.bin 224 224 +10554 ./prep_dataset/ILSVRC2012_val_00013210.bin 224 224 +10555 ./prep_dataset/ILSVRC2012_val_00035667.bin 224 224 +10556 ./prep_dataset/ILSVRC2012_val_00045608.bin 224 224 +10557 ./prep_dataset/ILSVRC2012_val_00006292.bin 224 224 +10558 ./prep_dataset/ILSVRC2012_val_00011617.bin 224 224 +10559 ./prep_dataset/ILSVRC2012_val_00000163.bin 224 224 +10560 ./prep_dataset/ILSVRC2012_val_00035129.bin 224 224 +10561 ./prep_dataset/ILSVRC2012_val_00010735.bin 224 224 +10562 ./prep_dataset/ILSVRC2012_val_00023188.bin 224 224 +10563 ./prep_dataset/ILSVRC2012_val_00039655.bin 224 224 +10564 ./prep_dataset/ILSVRC2012_val_00042384.bin 224 224 +10565 ./prep_dataset/ILSVRC2012_val_00029672.bin 224 224 +10566 ./prep_dataset/ILSVRC2012_val_00002035.bin 224 224 +10567 ./prep_dataset/ILSVRC2012_val_00009090.bin 224 224 +10568 ./prep_dataset/ILSVRC2012_val_00028398.bin 224 224 +10569 ./prep_dataset/ILSVRC2012_val_00016314.bin 224 224 +10570 ./prep_dataset/ILSVRC2012_val_00008525.bin 224 224 +10571 ./prep_dataset/ILSVRC2012_val_00031286.bin 224 224 +10572 ./prep_dataset/ILSVRC2012_val_00041578.bin 224 224 +10573 ./prep_dataset/ILSVRC2012_val_00001717.bin 224 224 +10574 ./prep_dataset/ILSVRC2012_val_00013342.bin 224 224 +10575 ./prep_dataset/ILSVRC2012_val_00001929.bin 224 224 +10576 ./prep_dataset/ILSVRC2012_val_00014536.bin 224 224 +10577 ./prep_dataset/ILSVRC2012_val_00037657.bin 224 224 +10578 ./prep_dataset/ILSVRC2012_val_00038071.bin 224 224 +10579 ./prep_dataset/ILSVRC2012_val_00014719.bin 224 224 +10580 ./prep_dataset/ILSVRC2012_val_00049697.bin 224 224 +10581 ./prep_dataset/ILSVRC2012_val_00014012.bin 224 224 +10582 ./prep_dataset/ILSVRC2012_val_00005901.bin 224 224 +10583 ./prep_dataset/ILSVRC2012_val_00003614.bin 224 224 +10584 ./prep_dataset/ILSVRC2012_val_00010852.bin 224 224 +10585 ./prep_dataset/ILSVRC2012_val_00017141.bin 224 224 +10586 ./prep_dataset/ILSVRC2012_val_00001664.bin 224 224 +10587 ./prep_dataset/ILSVRC2012_val_00044937.bin 224 224 +10588 ./prep_dataset/ILSVRC2012_val_00039657.bin 224 224 +10589 ./prep_dataset/ILSVRC2012_val_00003789.bin 224 224 +10590 ./prep_dataset/ILSVRC2012_val_00031781.bin 224 224 +10591 ./prep_dataset/ILSVRC2012_val_00047239.bin 224 224 +10592 ./prep_dataset/ILSVRC2012_val_00003969.bin 224 224 +10593 ./prep_dataset/ILSVRC2012_val_00025906.bin 224 224 +10594 ./prep_dataset/ILSVRC2012_val_00026070.bin 224 224 +10595 ./prep_dataset/ILSVRC2012_val_00042351.bin 224 224 +10596 ./prep_dataset/ILSVRC2012_val_00012694.bin 224 224 +10597 ./prep_dataset/ILSVRC2012_val_00049595.bin 224 224 +10598 ./prep_dataset/ILSVRC2012_val_00026747.bin 224 224 +10599 ./prep_dataset/ILSVRC2012_val_00001127.bin 224 224 +10600 ./prep_dataset/ILSVRC2012_val_00011326.bin 224 224 +10601 ./prep_dataset/ILSVRC2012_val_00034652.bin 224 224 +10602 ./prep_dataset/ILSVRC2012_val_00033163.bin 224 224 +10603 ./prep_dataset/ILSVRC2012_val_00040076.bin 224 224 +10604 ./prep_dataset/ILSVRC2012_val_00011994.bin 224 224 +10605 ./prep_dataset/ILSVRC2012_val_00008638.bin 224 224 +10606 ./prep_dataset/ILSVRC2012_val_00032275.bin 224 224 +10607 ./prep_dataset/ILSVRC2012_val_00025396.bin 224 224 +10608 ./prep_dataset/ILSVRC2012_val_00022259.bin 224 224 +10609 ./prep_dataset/ILSVRC2012_val_00034744.bin 224 224 +10610 ./prep_dataset/ILSVRC2012_val_00001917.bin 224 224 +10611 ./prep_dataset/ILSVRC2012_val_00016883.bin 224 224 +10612 ./prep_dataset/ILSVRC2012_val_00038121.bin 224 224 +10613 ./prep_dataset/ILSVRC2012_val_00048805.bin 224 224 +10614 ./prep_dataset/ILSVRC2012_val_00006045.bin 224 224 +10615 ./prep_dataset/ILSVRC2012_val_00045476.bin 224 224 +10616 ./prep_dataset/ILSVRC2012_val_00013529.bin 224 224 +10617 ./prep_dataset/ILSVRC2012_val_00032398.bin 224 224 +10618 ./prep_dataset/ILSVRC2012_val_00000191.bin 224 224 +10619 ./prep_dataset/ILSVRC2012_val_00027381.bin 224 224 +10620 ./prep_dataset/ILSVRC2012_val_00031958.bin 224 224 +10621 ./prep_dataset/ILSVRC2012_val_00027722.bin 224 224 +10622 ./prep_dataset/ILSVRC2012_val_00030492.bin 224 224 +10623 ./prep_dataset/ILSVRC2012_val_00038190.bin 224 224 +10624 ./prep_dataset/ILSVRC2012_val_00047783.bin 224 224 +10625 ./prep_dataset/ILSVRC2012_val_00036586.bin 224 224 +10626 ./prep_dataset/ILSVRC2012_val_00030555.bin 224 224 +10627 ./prep_dataset/ILSVRC2012_val_00014215.bin 224 224 +10628 ./prep_dataset/ILSVRC2012_val_00008142.bin 224 224 +10629 ./prep_dataset/ILSVRC2012_val_00032735.bin 224 224 +10630 ./prep_dataset/ILSVRC2012_val_00030403.bin 224 224 +10631 ./prep_dataset/ILSVRC2012_val_00016537.bin 224 224 +10632 ./prep_dataset/ILSVRC2012_val_00047842.bin 224 224 +10633 ./prep_dataset/ILSVRC2012_val_00035457.bin 224 224 +10634 ./prep_dataset/ILSVRC2012_val_00010262.bin 224 224 +10635 ./prep_dataset/ILSVRC2012_val_00048215.bin 224 224 +10636 ./prep_dataset/ILSVRC2012_val_00038712.bin 224 224 +10637 ./prep_dataset/ILSVRC2012_val_00024455.bin 224 224 +10638 ./prep_dataset/ILSVRC2012_val_00021892.bin 224 224 +10639 ./prep_dataset/ILSVRC2012_val_00017554.bin 224 224 +10640 ./prep_dataset/ILSVRC2012_val_00046382.bin 224 224 +10641 ./prep_dataset/ILSVRC2012_val_00031201.bin 224 224 +10642 ./prep_dataset/ILSVRC2012_val_00002931.bin 224 224 +10643 ./prep_dataset/ILSVRC2012_val_00017676.bin 224 224 +10644 ./prep_dataset/ILSVRC2012_val_00009973.bin 224 224 +10645 ./prep_dataset/ILSVRC2012_val_00043922.bin 224 224 +10646 ./prep_dataset/ILSVRC2012_val_00026354.bin 224 224 +10647 ./prep_dataset/ILSVRC2012_val_00028119.bin 224 224 +10648 ./prep_dataset/ILSVRC2012_val_00031032.bin 224 224 +10649 ./prep_dataset/ILSVRC2012_val_00022410.bin 224 224 +10650 ./prep_dataset/ILSVRC2012_val_00008204.bin 224 224 +10651 ./prep_dataset/ILSVRC2012_val_00041734.bin 224 224 +10652 ./prep_dataset/ILSVRC2012_val_00045566.bin 224 224 +10653 ./prep_dataset/ILSVRC2012_val_00038218.bin 224 224 +10654 ./prep_dataset/ILSVRC2012_val_00041901.bin 224 224 +10655 ./prep_dataset/ILSVRC2012_val_00043645.bin 224 224 +10656 ./prep_dataset/ILSVRC2012_val_00018405.bin 224 224 +10657 ./prep_dataset/ILSVRC2012_val_00026420.bin 224 224 +10658 ./prep_dataset/ILSVRC2012_val_00048259.bin 224 224 +10659 ./prep_dataset/ILSVRC2012_val_00022872.bin 224 224 +10660 ./prep_dataset/ILSVRC2012_val_00031305.bin 224 224 +10661 ./prep_dataset/ILSVRC2012_val_00015471.bin 224 224 +10662 ./prep_dataset/ILSVRC2012_val_00045874.bin 224 224 +10663 ./prep_dataset/ILSVRC2012_val_00011064.bin 224 224 +10664 ./prep_dataset/ILSVRC2012_val_00009890.bin 224 224 +10665 ./prep_dataset/ILSVRC2012_val_00011743.bin 224 224 +10666 ./prep_dataset/ILSVRC2012_val_00007688.bin 224 224 +10667 ./prep_dataset/ILSVRC2012_val_00036967.bin 224 224 +10668 ./prep_dataset/ILSVRC2012_val_00044509.bin 224 224 +10669 ./prep_dataset/ILSVRC2012_val_00008234.bin 224 224 +10670 ./prep_dataset/ILSVRC2012_val_00030484.bin 224 224 +10671 ./prep_dataset/ILSVRC2012_val_00003853.bin 224 224 +10672 ./prep_dataset/ILSVRC2012_val_00000984.bin 224 224 +10673 ./prep_dataset/ILSVRC2012_val_00021811.bin 224 224 +10674 ./prep_dataset/ILSVRC2012_val_00048093.bin 224 224 +10675 ./prep_dataset/ILSVRC2012_val_00021971.bin 224 224 +10676 ./prep_dataset/ILSVRC2012_val_00021711.bin 224 224 +10677 ./prep_dataset/ILSVRC2012_val_00044830.bin 224 224 +10678 ./prep_dataset/ILSVRC2012_val_00000457.bin 224 224 +10679 ./prep_dataset/ILSVRC2012_val_00008125.bin 224 224 +10680 ./prep_dataset/ILSVRC2012_val_00007084.bin 224 224 +10681 ./prep_dataset/ILSVRC2012_val_00040867.bin 224 224 +10682 ./prep_dataset/ILSVRC2012_val_00040508.bin 224 224 +10683 ./prep_dataset/ILSVRC2012_val_00006181.bin 224 224 +10684 ./prep_dataset/ILSVRC2012_val_00019608.bin 224 224 +10685 ./prep_dataset/ILSVRC2012_val_00027829.bin 224 224 +10686 ./prep_dataset/ILSVRC2012_val_00005042.bin 224 224 +10687 ./prep_dataset/ILSVRC2012_val_00036044.bin 224 224 +10688 ./prep_dataset/ILSVRC2012_val_00025198.bin 224 224 +10689 ./prep_dataset/ILSVRC2012_val_00001793.bin 224 224 +10690 ./prep_dataset/ILSVRC2012_val_00033061.bin 224 224 +10691 ./prep_dataset/ILSVRC2012_val_00004563.bin 224 224 +10692 ./prep_dataset/ILSVRC2012_val_00034723.bin 224 224 +10693 ./prep_dataset/ILSVRC2012_val_00047536.bin 224 224 +10694 ./prep_dataset/ILSVRC2012_val_00025058.bin 224 224 +10695 ./prep_dataset/ILSVRC2012_val_00043899.bin 224 224 +10696 ./prep_dataset/ILSVRC2012_val_00016398.bin 224 224 +10697 ./prep_dataset/ILSVRC2012_val_00003949.bin 224 224 +10698 ./prep_dataset/ILSVRC2012_val_00048946.bin 224 224 +10699 ./prep_dataset/ILSVRC2012_val_00018160.bin 224 224 +10700 ./prep_dataset/ILSVRC2012_val_00044224.bin 224 224 +10701 ./prep_dataset/ILSVRC2012_val_00031746.bin 224 224 +10702 ./prep_dataset/ILSVRC2012_val_00040176.bin 224 224 +10703 ./prep_dataset/ILSVRC2012_val_00030387.bin 224 224 +10704 ./prep_dataset/ILSVRC2012_val_00022504.bin 224 224 +10705 ./prep_dataset/ILSVRC2012_val_00022090.bin 224 224 +10706 ./prep_dataset/ILSVRC2012_val_00018287.bin 224 224 +10707 ./prep_dataset/ILSVRC2012_val_00011520.bin 224 224 +10708 ./prep_dataset/ILSVRC2012_val_00023647.bin 224 224 +10709 ./prep_dataset/ILSVRC2012_val_00030344.bin 224 224 +10710 ./prep_dataset/ILSVRC2012_val_00016710.bin 224 224 +10711 ./prep_dataset/ILSVRC2012_val_00008091.bin 224 224 +10712 ./prep_dataset/ILSVRC2012_val_00029120.bin 224 224 +10713 ./prep_dataset/ILSVRC2012_val_00036894.bin 224 224 +10714 ./prep_dataset/ILSVRC2012_val_00011529.bin 224 224 +10715 ./prep_dataset/ILSVRC2012_val_00042170.bin 224 224 +10716 ./prep_dataset/ILSVRC2012_val_00008856.bin 224 224 +10717 ./prep_dataset/ILSVRC2012_val_00007587.bin 224 224 +10718 ./prep_dataset/ILSVRC2012_val_00030033.bin 224 224 +10719 ./prep_dataset/ILSVRC2012_val_00035422.bin 224 224 +10720 ./prep_dataset/ILSVRC2012_val_00024321.bin 224 224 +10721 ./prep_dataset/ILSVRC2012_val_00008819.bin 224 224 +10722 ./prep_dataset/ILSVRC2012_val_00044570.bin 224 224 +10723 ./prep_dataset/ILSVRC2012_val_00010963.bin 224 224 +10724 ./prep_dataset/ILSVRC2012_val_00027609.bin 224 224 +10725 ./prep_dataset/ILSVRC2012_val_00008382.bin 224 224 +10726 ./prep_dataset/ILSVRC2012_val_00044411.bin 224 224 +10727 ./prep_dataset/ILSVRC2012_val_00033483.bin 224 224 +10728 ./prep_dataset/ILSVRC2012_val_00012648.bin 224 224 +10729 ./prep_dataset/ILSVRC2012_val_00029963.bin 224 224 +10730 ./prep_dataset/ILSVRC2012_val_00032864.bin 224 224 +10731 ./prep_dataset/ILSVRC2012_val_00037864.bin 224 224 +10732 ./prep_dataset/ILSVRC2012_val_00032807.bin 224 224 +10733 ./prep_dataset/ILSVRC2012_val_00017038.bin 224 224 +10734 ./prep_dataset/ILSVRC2012_val_00010273.bin 224 224 +10735 ./prep_dataset/ILSVRC2012_val_00016729.bin 224 224 +10736 ./prep_dataset/ILSVRC2012_val_00035995.bin 224 224 +10737 ./prep_dataset/ILSVRC2012_val_00022922.bin 224 224 +10738 ./prep_dataset/ILSVRC2012_val_00046471.bin 224 224 +10739 ./prep_dataset/ILSVRC2012_val_00036805.bin 224 224 +10740 ./prep_dataset/ILSVRC2012_val_00025069.bin 224 224 +10741 ./prep_dataset/ILSVRC2012_val_00020463.bin 224 224 +10742 ./prep_dataset/ILSVRC2012_val_00034094.bin 224 224 +10743 ./prep_dataset/ILSVRC2012_val_00012373.bin 224 224 +10744 ./prep_dataset/ILSVRC2012_val_00002661.bin 224 224 +10745 ./prep_dataset/ILSVRC2012_val_00022219.bin 224 224 +10746 ./prep_dataset/ILSVRC2012_val_00045462.bin 224 224 +10747 ./prep_dataset/ILSVRC2012_val_00026789.bin 224 224 +10748 ./prep_dataset/ILSVRC2012_val_00016794.bin 224 224 +10749 ./prep_dataset/ILSVRC2012_val_00017319.bin 224 224 +10750 ./prep_dataset/ILSVRC2012_val_00048513.bin 224 224 +10751 ./prep_dataset/ILSVRC2012_val_00008329.bin 224 224 +10752 ./prep_dataset/ILSVRC2012_val_00004214.bin 224 224 +10753 ./prep_dataset/ILSVRC2012_val_00030238.bin 224 224 +10754 ./prep_dataset/ILSVRC2012_val_00048579.bin 224 224 +10755 ./prep_dataset/ILSVRC2012_val_00015816.bin 224 224 +10756 ./prep_dataset/ILSVRC2012_val_00036372.bin 224 224 +10757 ./prep_dataset/ILSVRC2012_val_00031343.bin 224 224 +10758 ./prep_dataset/ILSVRC2012_val_00003141.bin 224 224 +10759 ./prep_dataset/ILSVRC2012_val_00010805.bin 224 224 +10760 ./prep_dataset/ILSVRC2012_val_00005098.bin 224 224 +10761 ./prep_dataset/ILSVRC2012_val_00038283.bin 224 224 +10762 ./prep_dataset/ILSVRC2012_val_00010084.bin 224 224 +10763 ./prep_dataset/ILSVRC2012_val_00004633.bin 224 224 +10764 ./prep_dataset/ILSVRC2012_val_00028640.bin 224 224 +10765 ./prep_dataset/ILSVRC2012_val_00012404.bin 224 224 +10766 ./prep_dataset/ILSVRC2012_val_00018688.bin 224 224 +10767 ./prep_dataset/ILSVRC2012_val_00025980.bin 224 224 +10768 ./prep_dataset/ILSVRC2012_val_00014258.bin 224 224 +10769 ./prep_dataset/ILSVRC2012_val_00046607.bin 224 224 +10770 ./prep_dataset/ILSVRC2012_val_00014766.bin 224 224 +10771 ./prep_dataset/ILSVRC2012_val_00014465.bin 224 224 +10772 ./prep_dataset/ILSVRC2012_val_00031847.bin 224 224 +10773 ./prep_dataset/ILSVRC2012_val_00037470.bin 224 224 +10774 ./prep_dataset/ILSVRC2012_val_00040213.bin 224 224 +10775 ./prep_dataset/ILSVRC2012_val_00042125.bin 224 224 +10776 ./prep_dataset/ILSVRC2012_val_00029786.bin 224 224 +10777 ./prep_dataset/ILSVRC2012_val_00000083.bin 224 224 +10778 ./prep_dataset/ILSVRC2012_val_00018145.bin 224 224 +10779 ./prep_dataset/ILSVRC2012_val_00003498.bin 224 224 +10780 ./prep_dataset/ILSVRC2012_val_00011338.bin 224 224 +10781 ./prep_dataset/ILSVRC2012_val_00001588.bin 224 224 +10782 ./prep_dataset/ILSVRC2012_val_00016793.bin 224 224 +10783 ./prep_dataset/ILSVRC2012_val_00041735.bin 224 224 +10784 ./prep_dataset/ILSVRC2012_val_00028350.bin 224 224 +10785 ./prep_dataset/ILSVRC2012_val_00018966.bin 224 224 +10786 ./prep_dataset/ILSVRC2012_val_00005294.bin 224 224 +10787 ./prep_dataset/ILSVRC2012_val_00029059.bin 224 224 +10788 ./prep_dataset/ILSVRC2012_val_00036274.bin 224 224 +10789 ./prep_dataset/ILSVRC2012_val_00007984.bin 224 224 +10790 ./prep_dataset/ILSVRC2012_val_00040235.bin 224 224 +10791 ./prep_dataset/ILSVRC2012_val_00002795.bin 224 224 +10792 ./prep_dataset/ILSVRC2012_val_00042188.bin 224 224 +10793 ./prep_dataset/ILSVRC2012_val_00036437.bin 224 224 +10794 ./prep_dataset/ILSVRC2012_val_00029599.bin 224 224 +10795 ./prep_dataset/ILSVRC2012_val_00025729.bin 224 224 +10796 ./prep_dataset/ILSVRC2012_val_00022103.bin 224 224 +10797 ./prep_dataset/ILSVRC2012_val_00046457.bin 224 224 +10798 ./prep_dataset/ILSVRC2012_val_00029190.bin 224 224 +10799 ./prep_dataset/ILSVRC2012_val_00020460.bin 224 224 +10800 ./prep_dataset/ILSVRC2012_val_00035266.bin 224 224 +10801 ./prep_dataset/ILSVRC2012_val_00024628.bin 224 224 +10802 ./prep_dataset/ILSVRC2012_val_00013904.bin 224 224 +10803 ./prep_dataset/ILSVRC2012_val_00038716.bin 224 224 +10804 ./prep_dataset/ILSVRC2012_val_00023302.bin 224 224 +10805 ./prep_dataset/ILSVRC2012_val_00028192.bin 224 224 +10806 ./prep_dataset/ILSVRC2012_val_00022748.bin 224 224 +10807 ./prep_dataset/ILSVRC2012_val_00020589.bin 224 224 +10808 ./prep_dataset/ILSVRC2012_val_00020000.bin 224 224 +10809 ./prep_dataset/ILSVRC2012_val_00028416.bin 224 224 +10810 ./prep_dataset/ILSVRC2012_val_00006866.bin 224 224 +10811 ./prep_dataset/ILSVRC2012_val_00042046.bin 224 224 +10812 ./prep_dataset/ILSVRC2012_val_00013201.bin 224 224 +10813 ./prep_dataset/ILSVRC2012_val_00003043.bin 224 224 +10814 ./prep_dataset/ILSVRC2012_val_00026559.bin 224 224 +10815 ./prep_dataset/ILSVRC2012_val_00014937.bin 224 224 +10816 ./prep_dataset/ILSVRC2012_val_00049195.bin 224 224 +10817 ./prep_dataset/ILSVRC2012_val_00007696.bin 224 224 +10818 ./prep_dataset/ILSVRC2012_val_00006094.bin 224 224 +10819 ./prep_dataset/ILSVRC2012_val_00011375.bin 224 224 +10820 ./prep_dataset/ILSVRC2012_val_00025486.bin 224 224 +10821 ./prep_dataset/ILSVRC2012_val_00009117.bin 224 224 +10822 ./prep_dataset/ILSVRC2012_val_00047219.bin 224 224 +10823 ./prep_dataset/ILSVRC2012_val_00018006.bin 224 224 +10824 ./prep_dataset/ILSVRC2012_val_00015599.bin 224 224 +10825 ./prep_dataset/ILSVRC2012_val_00048547.bin 224 224 +10826 ./prep_dataset/ILSVRC2012_val_00021885.bin 224 224 +10827 ./prep_dataset/ILSVRC2012_val_00026590.bin 224 224 +10828 ./prep_dataset/ILSVRC2012_val_00038765.bin 224 224 +10829 ./prep_dataset/ILSVRC2012_val_00021315.bin 224 224 +10830 ./prep_dataset/ILSVRC2012_val_00019720.bin 224 224 +10831 ./prep_dataset/ILSVRC2012_val_00047685.bin 224 224 +10832 ./prep_dataset/ILSVRC2012_val_00002363.bin 224 224 +10833 ./prep_dataset/ILSVRC2012_val_00037091.bin 224 224 +10834 ./prep_dataset/ILSVRC2012_val_00037242.bin 224 224 +10835 ./prep_dataset/ILSVRC2012_val_00033945.bin 224 224 +10836 ./prep_dataset/ILSVRC2012_val_00018912.bin 224 224 +10837 ./prep_dataset/ILSVRC2012_val_00024643.bin 224 224 +10838 ./prep_dataset/ILSVRC2012_val_00014743.bin 224 224 +10839 ./prep_dataset/ILSVRC2012_val_00031175.bin 224 224 +10840 ./prep_dataset/ILSVRC2012_val_00023624.bin 224 224 +10841 ./prep_dataset/ILSVRC2012_val_00039159.bin 224 224 +10842 ./prep_dataset/ILSVRC2012_val_00016296.bin 224 224 +10843 ./prep_dataset/ILSVRC2012_val_00039044.bin 224 224 +10844 ./prep_dataset/ILSVRC2012_val_00028601.bin 224 224 +10845 ./prep_dataset/ILSVRC2012_val_00040368.bin 224 224 +10846 ./prep_dataset/ILSVRC2012_val_00037693.bin 224 224 +10847 ./prep_dataset/ILSVRC2012_val_00046283.bin 224 224 +10848 ./prep_dataset/ILSVRC2012_val_00028360.bin 224 224 +10849 ./prep_dataset/ILSVRC2012_val_00039547.bin 224 224 +10850 ./prep_dataset/ILSVRC2012_val_00023370.bin 224 224 +10851 ./prep_dataset/ILSVRC2012_val_00024616.bin 224 224 +10852 ./prep_dataset/ILSVRC2012_val_00046660.bin 224 224 +10853 ./prep_dataset/ILSVRC2012_val_00037792.bin 224 224 +10854 ./prep_dataset/ILSVRC2012_val_00045963.bin 224 224 +10855 ./prep_dataset/ILSVRC2012_val_00043111.bin 224 224 +10856 ./prep_dataset/ILSVRC2012_val_00010734.bin 224 224 +10857 ./prep_dataset/ILSVRC2012_val_00004969.bin 224 224 +10858 ./prep_dataset/ILSVRC2012_val_00002336.bin 224 224 +10859 ./prep_dataset/ILSVRC2012_val_00003891.bin 224 224 +10860 ./prep_dataset/ILSVRC2012_val_00015569.bin 224 224 +10861 ./prep_dataset/ILSVRC2012_val_00002069.bin 224 224 +10862 ./prep_dataset/ILSVRC2012_val_00033258.bin 224 224 +10863 ./prep_dataset/ILSVRC2012_val_00010970.bin 224 224 +10864 ./prep_dataset/ILSVRC2012_val_00004878.bin 224 224 +10865 ./prep_dataset/ILSVRC2012_val_00039358.bin 224 224 +10866 ./prep_dataset/ILSVRC2012_val_00034635.bin 224 224 +10867 ./prep_dataset/ILSVRC2012_val_00019222.bin 224 224 +10868 ./prep_dataset/ILSVRC2012_val_00002295.bin 224 224 +10869 ./prep_dataset/ILSVRC2012_val_00038756.bin 224 224 +10870 ./prep_dataset/ILSVRC2012_val_00034897.bin 224 224 +10871 ./prep_dataset/ILSVRC2012_val_00016292.bin 224 224 +10872 ./prep_dataset/ILSVRC2012_val_00048672.bin 224 224 +10873 ./prep_dataset/ILSVRC2012_val_00021863.bin 224 224 +10874 ./prep_dataset/ILSVRC2012_val_00040355.bin 224 224 +10875 ./prep_dataset/ILSVRC2012_val_00007914.bin 224 224 +10876 ./prep_dataset/ILSVRC2012_val_00036386.bin 224 224 +10877 ./prep_dataset/ILSVRC2012_val_00005404.bin 224 224 +10878 ./prep_dataset/ILSVRC2012_val_00037502.bin 224 224 +10879 ./prep_dataset/ILSVRC2012_val_00025629.bin 224 224 +10880 ./prep_dataset/ILSVRC2012_val_00030866.bin 224 224 +10881 ./prep_dataset/ILSVRC2012_val_00040778.bin 224 224 +10882 ./prep_dataset/ILSVRC2012_val_00040771.bin 224 224 +10883 ./prep_dataset/ILSVRC2012_val_00019353.bin 224 224 +10884 ./prep_dataset/ILSVRC2012_val_00037758.bin 224 224 +10885 ./prep_dataset/ILSVRC2012_val_00034011.bin 224 224 +10886 ./prep_dataset/ILSVRC2012_val_00035454.bin 224 224 +10887 ./prep_dataset/ILSVRC2012_val_00046553.bin 224 224 +10888 ./prep_dataset/ILSVRC2012_val_00047994.bin 224 224 +10889 ./prep_dataset/ILSVRC2012_val_00007498.bin 224 224 +10890 ./prep_dataset/ILSVRC2012_val_00030787.bin 224 224 +10891 ./prep_dataset/ILSVRC2012_val_00024974.bin 224 224 +10892 ./prep_dataset/ILSVRC2012_val_00048572.bin 224 224 +10893 ./prep_dataset/ILSVRC2012_val_00026111.bin 224 224 +10894 ./prep_dataset/ILSVRC2012_val_00015470.bin 224 224 +10895 ./prep_dataset/ILSVRC2012_val_00044174.bin 224 224 +10896 ./prep_dataset/ILSVRC2012_val_00022119.bin 224 224 +10897 ./prep_dataset/ILSVRC2012_val_00042989.bin 224 224 +10898 ./prep_dataset/ILSVRC2012_val_00034140.bin 224 224 +10899 ./prep_dataset/ILSVRC2012_val_00037818.bin 224 224 +10900 ./prep_dataset/ILSVRC2012_val_00011733.bin 224 224 +10901 ./prep_dataset/ILSVRC2012_val_00010536.bin 224 224 +10902 ./prep_dataset/ILSVRC2012_val_00008426.bin 224 224 +10903 ./prep_dataset/ILSVRC2012_val_00023692.bin 224 224 +10904 ./prep_dataset/ILSVRC2012_val_00006150.bin 224 224 +10905 ./prep_dataset/ILSVRC2012_val_00018959.bin 224 224 +10906 ./prep_dataset/ILSVRC2012_val_00034227.bin 224 224 +10907 ./prep_dataset/ILSVRC2012_val_00004250.bin 224 224 +10908 ./prep_dataset/ILSVRC2012_val_00009214.bin 224 224 +10909 ./prep_dataset/ILSVRC2012_val_00004783.bin 224 224 +10910 ./prep_dataset/ILSVRC2012_val_00045626.bin 224 224 +10911 ./prep_dataset/ILSVRC2012_val_00035690.bin 224 224 +10912 ./prep_dataset/ILSVRC2012_val_00018462.bin 224 224 +10913 ./prep_dataset/ILSVRC2012_val_00043647.bin 224 224 +10914 ./prep_dataset/ILSVRC2012_val_00043500.bin 224 224 +10915 ./prep_dataset/ILSVRC2012_val_00026087.bin 224 224 +10916 ./prep_dataset/ILSVRC2012_val_00023374.bin 224 224 +10917 ./prep_dataset/ILSVRC2012_val_00019480.bin 224 224 +10918 ./prep_dataset/ILSVRC2012_val_00013329.bin 224 224 +10919 ./prep_dataset/ILSVRC2012_val_00022419.bin 224 224 +10920 ./prep_dataset/ILSVRC2012_val_00004923.bin 224 224 +10921 ./prep_dataset/ILSVRC2012_val_00034702.bin 224 224 +10922 ./prep_dataset/ILSVRC2012_val_00005094.bin 224 224 +10923 ./prep_dataset/ILSVRC2012_val_00035257.bin 224 224 +10924 ./prep_dataset/ILSVRC2012_val_00047208.bin 224 224 +10925 ./prep_dataset/ILSVRC2012_val_00011466.bin 224 224 +10926 ./prep_dataset/ILSVRC2012_val_00017613.bin 224 224 +10927 ./prep_dataset/ILSVRC2012_val_00008201.bin 224 224 +10928 ./prep_dataset/ILSVRC2012_val_00046716.bin 224 224 +10929 ./prep_dataset/ILSVRC2012_val_00007547.bin 224 224 +10930 ./prep_dataset/ILSVRC2012_val_00049321.bin 224 224 +10931 ./prep_dataset/ILSVRC2012_val_00048285.bin 224 224 +10932 ./prep_dataset/ILSVRC2012_val_00031364.bin 224 224 +10933 ./prep_dataset/ILSVRC2012_val_00022542.bin 224 224 +10934 ./prep_dataset/ILSVRC2012_val_00038618.bin 224 224 +10935 ./prep_dataset/ILSVRC2012_val_00008680.bin 224 224 +10936 ./prep_dataset/ILSVRC2012_val_00037377.bin 224 224 +10937 ./prep_dataset/ILSVRC2012_val_00039491.bin 224 224 +10938 ./prep_dataset/ILSVRC2012_val_00007735.bin 224 224 +10939 ./prep_dataset/ILSVRC2012_val_00047304.bin 224 224 +10940 ./prep_dataset/ILSVRC2012_val_00005281.bin 224 224 +10941 ./prep_dataset/ILSVRC2012_val_00008337.bin 224 224 +10942 ./prep_dataset/ILSVRC2012_val_00003654.bin 224 224 +10943 ./prep_dataset/ILSVRC2012_val_00020093.bin 224 224 +10944 ./prep_dataset/ILSVRC2012_val_00040520.bin 224 224 +10945 ./prep_dataset/ILSVRC2012_val_00020025.bin 224 224 +10946 ./prep_dataset/ILSVRC2012_val_00002394.bin 224 224 +10947 ./prep_dataset/ILSVRC2012_val_00000923.bin 224 224 +10948 ./prep_dataset/ILSVRC2012_val_00000238.bin 224 224 +10949 ./prep_dataset/ILSVRC2012_val_00005116.bin 224 224 +10950 ./prep_dataset/ILSVRC2012_val_00008580.bin 224 224 +10951 ./prep_dataset/ILSVRC2012_val_00031683.bin 224 224 +10952 ./prep_dataset/ILSVRC2012_val_00029375.bin 224 224 +10953 ./prep_dataset/ILSVRC2012_val_00029468.bin 224 224 +10954 ./prep_dataset/ILSVRC2012_val_00005355.bin 224 224 +10955 ./prep_dataset/ILSVRC2012_val_00011213.bin 224 224 +10956 ./prep_dataset/ILSVRC2012_val_00016489.bin 224 224 +10957 ./prep_dataset/ILSVRC2012_val_00038552.bin 224 224 +10958 ./prep_dataset/ILSVRC2012_val_00017725.bin 224 224 +10959 ./prep_dataset/ILSVRC2012_val_00017071.bin 224 224 +10960 ./prep_dataset/ILSVRC2012_val_00022754.bin 224 224 +10961 ./prep_dataset/ILSVRC2012_val_00011715.bin 224 224 +10962 ./prep_dataset/ILSVRC2012_val_00040693.bin 224 224 +10963 ./prep_dataset/ILSVRC2012_val_00008307.bin 224 224 +10964 ./prep_dataset/ILSVRC2012_val_00027641.bin 224 224 +10965 ./prep_dataset/ILSVRC2012_val_00024473.bin 224 224 +10966 ./prep_dataset/ILSVRC2012_val_00023185.bin 224 224 +10967 ./prep_dataset/ILSVRC2012_val_00020552.bin 224 224 +10968 ./prep_dataset/ILSVRC2012_val_00023718.bin 224 224 +10969 ./prep_dataset/ILSVRC2012_val_00000657.bin 224 224 +10970 ./prep_dataset/ILSVRC2012_val_00046944.bin 224 224 +10971 ./prep_dataset/ILSVRC2012_val_00007970.bin 224 224 +10972 ./prep_dataset/ILSVRC2012_val_00022711.bin 224 224 +10973 ./prep_dataset/ILSVRC2012_val_00049221.bin 224 224 +10974 ./prep_dataset/ILSVRC2012_val_00013003.bin 224 224 +10975 ./prep_dataset/ILSVRC2012_val_00020283.bin 224 224 +10976 ./prep_dataset/ILSVRC2012_val_00011752.bin 224 224 +10977 ./prep_dataset/ILSVRC2012_val_00022233.bin 224 224 +10978 ./prep_dataset/ILSVRC2012_val_00008912.bin 224 224 +10979 ./prep_dataset/ILSVRC2012_val_00019485.bin 224 224 +10980 ./prep_dataset/ILSVRC2012_val_00017262.bin 224 224 +10981 ./prep_dataset/ILSVRC2012_val_00028342.bin 224 224 +10982 ./prep_dataset/ILSVRC2012_val_00007961.bin 224 224 +10983 ./prep_dataset/ILSVRC2012_val_00038590.bin 224 224 +10984 ./prep_dataset/ILSVRC2012_val_00044215.bin 224 224 +10985 ./prep_dataset/ILSVRC2012_val_00042010.bin 224 224 +10986 ./prep_dataset/ILSVRC2012_val_00012708.bin 224 224 +10987 ./prep_dataset/ILSVRC2012_val_00019294.bin 224 224 +10988 ./prep_dataset/ILSVRC2012_val_00049813.bin 224 224 +10989 ./prep_dataset/ILSVRC2012_val_00035757.bin 224 224 +10990 ./prep_dataset/ILSVRC2012_val_00019168.bin 224 224 +10991 ./prep_dataset/ILSVRC2012_val_00049715.bin 224 224 +10992 ./prep_dataset/ILSVRC2012_val_00024940.bin 224 224 +10993 ./prep_dataset/ILSVRC2012_val_00009305.bin 224 224 +10994 ./prep_dataset/ILSVRC2012_val_00046592.bin 224 224 +10995 ./prep_dataset/ILSVRC2012_val_00032913.bin 224 224 +10996 ./prep_dataset/ILSVRC2012_val_00008097.bin 224 224 +10997 ./prep_dataset/ILSVRC2012_val_00025139.bin 224 224 +10998 ./prep_dataset/ILSVRC2012_val_00017338.bin 224 224 +10999 ./prep_dataset/ILSVRC2012_val_00017952.bin 224 224 +11000 ./prep_dataset/ILSVRC2012_val_00024140.bin 224 224 +11001 ./prep_dataset/ILSVRC2012_val_00029470.bin 224 224 +11002 ./prep_dataset/ILSVRC2012_val_00033072.bin 224 224 +11003 ./prep_dataset/ILSVRC2012_val_00002739.bin 224 224 +11004 ./prep_dataset/ILSVRC2012_val_00022382.bin 224 224 +11005 ./prep_dataset/ILSVRC2012_val_00040769.bin 224 224 +11006 ./prep_dataset/ILSVRC2012_val_00041483.bin 224 224 +11007 ./prep_dataset/ILSVRC2012_val_00007515.bin 224 224 +11008 ./prep_dataset/ILSVRC2012_val_00022646.bin 224 224 +11009 ./prep_dataset/ILSVRC2012_val_00001478.bin 224 224 +11010 ./prep_dataset/ILSVRC2012_val_00046662.bin 224 224 +11011 ./prep_dataset/ILSVRC2012_val_00049219.bin 224 224 +11012 ./prep_dataset/ILSVRC2012_val_00008326.bin 224 224 +11013 ./prep_dataset/ILSVRC2012_val_00017480.bin 224 224 +11014 ./prep_dataset/ILSVRC2012_val_00033359.bin 224 224 +11015 ./prep_dataset/ILSVRC2012_val_00003503.bin 224 224 +11016 ./prep_dataset/ILSVRC2012_val_00002909.bin 224 224 +11017 ./prep_dataset/ILSVRC2012_val_00038458.bin 224 224 +11018 ./prep_dataset/ILSVRC2012_val_00041113.bin 224 224 +11019 ./prep_dataset/ILSVRC2012_val_00036095.bin 224 224 +11020 ./prep_dataset/ILSVRC2012_val_00045282.bin 224 224 +11021 ./prep_dataset/ILSVRC2012_val_00011970.bin 224 224 +11022 ./prep_dataset/ILSVRC2012_val_00013953.bin 224 224 +11023 ./prep_dataset/ILSVRC2012_val_00042654.bin 224 224 +11024 ./prep_dataset/ILSVRC2012_val_00020062.bin 224 224 +11025 ./prep_dataset/ILSVRC2012_val_00002754.bin 224 224 +11026 ./prep_dataset/ILSVRC2012_val_00017037.bin 224 224 +11027 ./prep_dataset/ILSVRC2012_val_00037199.bin 224 224 +11028 ./prep_dataset/ILSVRC2012_val_00030496.bin 224 224 +11029 ./prep_dataset/ILSVRC2012_val_00003585.bin 224 224 +11030 ./prep_dataset/ILSVRC2012_val_00031898.bin 224 224 +11031 ./prep_dataset/ILSVRC2012_val_00018995.bin 224 224 +11032 ./prep_dataset/ILSVRC2012_val_00014044.bin 224 224 +11033 ./prep_dataset/ILSVRC2012_val_00031534.bin 224 224 +11034 ./prep_dataset/ILSVRC2012_val_00002342.bin 224 224 +11035 ./prep_dataset/ILSVRC2012_val_00024590.bin 224 224 +11036 ./prep_dataset/ILSVRC2012_val_00005846.bin 224 224 +11037 ./prep_dataset/ILSVRC2012_val_00029970.bin 224 224 +11038 ./prep_dataset/ILSVRC2012_val_00035984.bin 224 224 +11039 ./prep_dataset/ILSVRC2012_val_00011120.bin 224 224 +11040 ./prep_dataset/ILSVRC2012_val_00039696.bin 224 224 +11041 ./prep_dataset/ILSVRC2012_val_00046165.bin 224 224 +11042 ./prep_dataset/ILSVRC2012_val_00003869.bin 224 224 +11043 ./prep_dataset/ILSVRC2012_val_00022735.bin 224 224 +11044 ./prep_dataset/ILSVRC2012_val_00020490.bin 224 224 +11045 ./prep_dataset/ILSVRC2012_val_00002205.bin 224 224 +11046 ./prep_dataset/ILSVRC2012_val_00002350.bin 224 224 +11047 ./prep_dataset/ILSVRC2012_val_00004327.bin 224 224 +11048 ./prep_dataset/ILSVRC2012_val_00009966.bin 224 224 +11049 ./prep_dataset/ILSVRC2012_val_00033209.bin 224 224 +11050 ./prep_dataset/ILSVRC2012_val_00031123.bin 224 224 +11051 ./prep_dataset/ILSVRC2012_val_00020543.bin 224 224 +11052 ./prep_dataset/ILSVRC2012_val_00019276.bin 224 224 +11053 ./prep_dataset/ILSVRC2012_val_00037701.bin 224 224 +11054 ./prep_dataset/ILSVRC2012_val_00021460.bin 224 224 +11055 ./prep_dataset/ILSVRC2012_val_00004686.bin 224 224 +11056 ./prep_dataset/ILSVRC2012_val_00009522.bin 224 224 +11057 ./prep_dataset/ILSVRC2012_val_00013251.bin 224 224 +11058 ./prep_dataset/ILSVRC2012_val_00045400.bin 224 224 +11059 ./prep_dataset/ILSVRC2012_val_00023596.bin 224 224 +11060 ./prep_dataset/ILSVRC2012_val_00023006.bin 224 224 +11061 ./prep_dataset/ILSVRC2012_val_00035455.bin 224 224 +11062 ./prep_dataset/ILSVRC2012_val_00032857.bin 224 224 +11063 ./prep_dataset/ILSVRC2012_val_00020881.bin 224 224 +11064 ./prep_dataset/ILSVRC2012_val_00041270.bin 224 224 +11065 ./prep_dataset/ILSVRC2012_val_00015583.bin 224 224 +11066 ./prep_dataset/ILSVRC2012_val_00010157.bin 224 224 +11067 ./prep_dataset/ILSVRC2012_val_00046390.bin 224 224 +11068 ./prep_dataset/ILSVRC2012_val_00049718.bin 224 224 +11069 ./prep_dataset/ILSVRC2012_val_00032840.bin 224 224 +11070 ./prep_dataset/ILSVRC2012_val_00030863.bin 224 224 +11071 ./prep_dataset/ILSVRC2012_val_00022263.bin 224 224 +11072 ./prep_dataset/ILSVRC2012_val_00011080.bin 224 224 +11073 ./prep_dataset/ILSVRC2012_val_00035025.bin 224 224 +11074 ./prep_dataset/ILSVRC2012_val_00034034.bin 224 224 +11075 ./prep_dataset/ILSVRC2012_val_00000810.bin 224 224 +11076 ./prep_dataset/ILSVRC2012_val_00031878.bin 224 224 +11077 ./prep_dataset/ILSVRC2012_val_00011943.bin 224 224 +11078 ./prep_dataset/ILSVRC2012_val_00030540.bin 224 224 +11079 ./prep_dataset/ILSVRC2012_val_00044602.bin 224 224 +11080 ./prep_dataset/ILSVRC2012_val_00003256.bin 224 224 +11081 ./prep_dataset/ILSVRC2012_val_00004345.bin 224 224 +11082 ./prep_dataset/ILSVRC2012_val_00012909.bin 224 224 +11083 ./prep_dataset/ILSVRC2012_val_00037849.bin 224 224 +11084 ./prep_dataset/ILSVRC2012_val_00046576.bin 224 224 +11085 ./prep_dataset/ILSVRC2012_val_00007537.bin 224 224 +11086 ./prep_dataset/ILSVRC2012_val_00044893.bin 224 224 +11087 ./prep_dataset/ILSVRC2012_val_00037352.bin 224 224 +11088 ./prep_dataset/ILSVRC2012_val_00006003.bin 224 224 +11089 ./prep_dataset/ILSVRC2012_val_00020707.bin 224 224 +11090 ./prep_dataset/ILSVRC2012_val_00017625.bin 224 224 +11091 ./prep_dataset/ILSVRC2012_val_00041238.bin 224 224 +11092 ./prep_dataset/ILSVRC2012_val_00034007.bin 224 224 +11093 ./prep_dataset/ILSVRC2012_val_00038178.bin 224 224 +11094 ./prep_dataset/ILSVRC2012_val_00044227.bin 224 224 +11095 ./prep_dataset/ILSVRC2012_val_00045337.bin 224 224 +11096 ./prep_dataset/ILSVRC2012_val_00028754.bin 224 224 +11097 ./prep_dataset/ILSVRC2012_val_00049486.bin 224 224 +11098 ./prep_dataset/ILSVRC2012_val_00017432.bin 224 224 +11099 ./prep_dataset/ILSVRC2012_val_00049437.bin 224 224 +11100 ./prep_dataset/ILSVRC2012_val_00023702.bin 224 224 +11101 ./prep_dataset/ILSVRC2012_val_00012956.bin 224 224 +11102 ./prep_dataset/ILSVRC2012_val_00045451.bin 224 224 +11103 ./prep_dataset/ILSVRC2012_val_00008435.bin 224 224 +11104 ./prep_dataset/ILSVRC2012_val_00006251.bin 224 224 +11105 ./prep_dataset/ILSVRC2012_val_00005393.bin 224 224 +11106 ./prep_dataset/ILSVRC2012_val_00036804.bin 224 224 +11107 ./prep_dataset/ILSVRC2012_val_00047829.bin 224 224 +11108 ./prep_dataset/ILSVRC2012_val_00029602.bin 224 224 +11109 ./prep_dataset/ILSVRC2012_val_00028477.bin 224 224 +11110 ./prep_dataset/ILSVRC2012_val_00020590.bin 224 224 +11111 ./prep_dataset/ILSVRC2012_val_00034026.bin 224 224 +11112 ./prep_dataset/ILSVRC2012_val_00046728.bin 224 224 +11113 ./prep_dataset/ILSVRC2012_val_00030897.bin 224 224 +11114 ./prep_dataset/ILSVRC2012_val_00013256.bin 224 224 +11115 ./prep_dataset/ILSVRC2012_val_00017118.bin 224 224 +11116 ./prep_dataset/ILSVRC2012_val_00044393.bin 224 224 +11117 ./prep_dataset/ILSVRC2012_val_00029273.bin 224 224 +11118 ./prep_dataset/ILSVRC2012_val_00025658.bin 224 224 +11119 ./prep_dataset/ILSVRC2012_val_00011433.bin 224 224 +11120 ./prep_dataset/ILSVRC2012_val_00031777.bin 224 224 +11121 ./prep_dataset/ILSVRC2012_val_00033496.bin 224 224 +11122 ./prep_dataset/ILSVRC2012_val_00006299.bin 224 224 +11123 ./prep_dataset/ILSVRC2012_val_00010943.bin 224 224 +11124 ./prep_dataset/ILSVRC2012_val_00003320.bin 224 224 +11125 ./prep_dataset/ILSVRC2012_val_00005877.bin 224 224 +11126 ./prep_dataset/ILSVRC2012_val_00023530.bin 224 224 +11127 ./prep_dataset/ILSVRC2012_val_00028761.bin 224 224 +11128 ./prep_dataset/ILSVRC2012_val_00003449.bin 224 224 +11129 ./prep_dataset/ILSVRC2012_val_00004586.bin 224 224 +11130 ./prep_dataset/ILSVRC2012_val_00041795.bin 224 224 +11131 ./prep_dataset/ILSVRC2012_val_00015501.bin 224 224 +11132 ./prep_dataset/ILSVRC2012_val_00010854.bin 224 224 +11133 ./prep_dataset/ILSVRC2012_val_00044535.bin 224 224 +11134 ./prep_dataset/ILSVRC2012_val_00005206.bin 224 224 +11135 ./prep_dataset/ILSVRC2012_val_00013213.bin 224 224 +11136 ./prep_dataset/ILSVRC2012_val_00013113.bin 224 224 +11137 ./prep_dataset/ILSVRC2012_val_00002473.bin 224 224 +11138 ./prep_dataset/ILSVRC2012_val_00033775.bin 224 224 +11139 ./prep_dataset/ILSVRC2012_val_00037467.bin 224 224 +11140 ./prep_dataset/ILSVRC2012_val_00043001.bin 224 224 +11141 ./prep_dataset/ILSVRC2012_val_00006307.bin 224 224 +11142 ./prep_dataset/ILSVRC2012_val_00006207.bin 224 224 +11143 ./prep_dataset/ILSVRC2012_val_00000643.bin 224 224 +11144 ./prep_dataset/ILSVRC2012_val_00022227.bin 224 224 +11145 ./prep_dataset/ILSVRC2012_val_00012879.bin 224 224 +11146 ./prep_dataset/ILSVRC2012_val_00022125.bin 224 224 +11147 ./prep_dataset/ILSVRC2012_val_00012649.bin 224 224 +11148 ./prep_dataset/ILSVRC2012_val_00033132.bin 224 224 +11149 ./prep_dataset/ILSVRC2012_val_00033428.bin 224 224 +11150 ./prep_dataset/ILSVRC2012_val_00038649.bin 224 224 +11151 ./prep_dataset/ILSVRC2012_val_00019067.bin 224 224 +11152 ./prep_dataset/ILSVRC2012_val_00009450.bin 224 224 +11153 ./prep_dataset/ILSVRC2012_val_00042809.bin 224 224 +11154 ./prep_dataset/ILSVRC2012_val_00007266.bin 224 224 +11155 ./prep_dataset/ILSVRC2012_val_00013762.bin 224 224 +11156 ./prep_dataset/ILSVRC2012_val_00023290.bin 224 224 +11157 ./prep_dataset/ILSVRC2012_val_00041168.bin 224 224 +11158 ./prep_dataset/ILSVRC2012_val_00010511.bin 224 224 +11159 ./prep_dataset/ILSVRC2012_val_00011346.bin 224 224 +11160 ./prep_dataset/ILSVRC2012_val_00048745.bin 224 224 +11161 ./prep_dataset/ILSVRC2012_val_00044445.bin 224 224 +11162 ./prep_dataset/ILSVRC2012_val_00018695.bin 224 224 +11163 ./prep_dataset/ILSVRC2012_val_00038793.bin 224 224 +11164 ./prep_dataset/ILSVRC2012_val_00041249.bin 224 224 +11165 ./prep_dataset/ILSVRC2012_val_00022256.bin 224 224 +11166 ./prep_dataset/ILSVRC2012_val_00025450.bin 224 224 +11167 ./prep_dataset/ILSVRC2012_val_00020984.bin 224 224 +11168 ./prep_dataset/ILSVRC2012_val_00030573.bin 224 224 +11169 ./prep_dataset/ILSVRC2012_val_00026961.bin 224 224 +11170 ./prep_dataset/ILSVRC2012_val_00029768.bin 224 224 +11171 ./prep_dataset/ILSVRC2012_val_00014816.bin 224 224 +11172 ./prep_dataset/ILSVRC2012_val_00030454.bin 224 224 +11173 ./prep_dataset/ILSVRC2012_val_00010374.bin 224 224 +11174 ./prep_dataset/ILSVRC2012_val_00008317.bin 224 224 +11175 ./prep_dataset/ILSVRC2012_val_00011619.bin 224 224 +11176 ./prep_dataset/ILSVRC2012_val_00048405.bin 224 224 +11177 ./prep_dataset/ILSVRC2012_val_00023722.bin 224 224 +11178 ./prep_dataset/ILSVRC2012_val_00047819.bin 224 224 +11179 ./prep_dataset/ILSVRC2012_val_00046632.bin 224 224 +11180 ./prep_dataset/ILSVRC2012_val_00015846.bin 224 224 +11181 ./prep_dataset/ILSVRC2012_val_00041278.bin 224 224 +11182 ./prep_dataset/ILSVRC2012_val_00037653.bin 224 224 +11183 ./prep_dataset/ILSVRC2012_val_00049384.bin 224 224 +11184 ./prep_dataset/ILSVRC2012_val_00034749.bin 224 224 +11185 ./prep_dataset/ILSVRC2012_val_00008594.bin 224 224 +11186 ./prep_dataset/ILSVRC2012_val_00029263.bin 224 224 +11187 ./prep_dataset/ILSVRC2012_val_00049864.bin 224 224 +11188 ./prep_dataset/ILSVRC2012_val_00018889.bin 224 224 +11189 ./prep_dataset/ILSVRC2012_val_00008539.bin 224 224 +11190 ./prep_dataset/ILSVRC2012_val_00045820.bin 224 224 +11191 ./prep_dataset/ILSVRC2012_val_00028757.bin 224 224 +11192 ./prep_dataset/ILSVRC2012_val_00030256.bin 224 224 +11193 ./prep_dataset/ILSVRC2012_val_00028519.bin 224 224 +11194 ./prep_dataset/ILSVRC2012_val_00048341.bin 224 224 +11195 ./prep_dataset/ILSVRC2012_val_00003623.bin 224 224 +11196 ./prep_dataset/ILSVRC2012_val_00035734.bin 224 224 +11197 ./prep_dataset/ILSVRC2012_val_00038008.bin 224 224 +11198 ./prep_dataset/ILSVRC2012_val_00019708.bin 224 224 +11199 ./prep_dataset/ILSVRC2012_val_00017187.bin 224 224 +11200 ./prep_dataset/ILSVRC2012_val_00035654.bin 224 224 +11201 ./prep_dataset/ILSVRC2012_val_00040138.bin 224 224 +11202 ./prep_dataset/ILSVRC2012_val_00015594.bin 224 224 +11203 ./prep_dataset/ILSVRC2012_val_00007754.bin 224 224 +11204 ./prep_dataset/ILSVRC2012_val_00028991.bin 224 224 +11205 ./prep_dataset/ILSVRC2012_val_00003398.bin 224 224 +11206 ./prep_dataset/ILSVRC2012_val_00027642.bin 224 224 +11207 ./prep_dataset/ILSVRC2012_val_00013796.bin 224 224 +11208 ./prep_dataset/ILSVRC2012_val_00043910.bin 224 224 +11209 ./prep_dataset/ILSVRC2012_val_00022756.bin 224 224 +11210 ./prep_dataset/ILSVRC2012_val_00041364.bin 224 224 +11211 ./prep_dataset/ILSVRC2012_val_00033742.bin 224 224 +11212 ./prep_dataset/ILSVRC2012_val_00002414.bin 224 224 +11213 ./prep_dataset/ILSVRC2012_val_00025113.bin 224 224 +11214 ./prep_dataset/ILSVRC2012_val_00023021.bin 224 224 +11215 ./prep_dataset/ILSVRC2012_val_00017796.bin 224 224 +11216 ./prep_dataset/ILSVRC2012_val_00030599.bin 224 224 +11217 ./prep_dataset/ILSVRC2012_val_00010649.bin 224 224 +11218 ./prep_dataset/ILSVRC2012_val_00039970.bin 224 224 +11219 ./prep_dataset/ILSVRC2012_val_00047731.bin 224 224 +11220 ./prep_dataset/ILSVRC2012_val_00047251.bin 224 224 +11221 ./prep_dataset/ILSVRC2012_val_00007648.bin 224 224 +11222 ./prep_dataset/ILSVRC2012_val_00006361.bin 224 224 +11223 ./prep_dataset/ILSVRC2012_val_00038377.bin 224 224 +11224 ./prep_dataset/ILSVRC2012_val_00009541.bin 224 224 +11225 ./prep_dataset/ILSVRC2012_val_00020126.bin 224 224 +11226 ./prep_dataset/ILSVRC2012_val_00018484.bin 224 224 +11227 ./prep_dataset/ILSVRC2012_val_00011029.bin 224 224 +11228 ./prep_dataset/ILSVRC2012_val_00021988.bin 224 224 +11229 ./prep_dataset/ILSVRC2012_val_00025157.bin 224 224 +11230 ./prep_dataset/ILSVRC2012_val_00040818.bin 224 224 +11231 ./prep_dataset/ILSVRC2012_val_00032674.bin 224 224 +11232 ./prep_dataset/ILSVRC2012_val_00025862.bin 224 224 +11233 ./prep_dataset/ILSVRC2012_val_00046158.bin 224 224 +11234 ./prep_dataset/ILSVRC2012_val_00043425.bin 224 224 +11235 ./prep_dataset/ILSVRC2012_val_00004329.bin 224 224 +11236 ./prep_dataset/ILSVRC2012_val_00021825.bin 224 224 +11237 ./prep_dataset/ILSVRC2012_val_00020044.bin 224 224 +11238 ./prep_dataset/ILSVRC2012_val_00036636.bin 224 224 +11239 ./prep_dataset/ILSVRC2012_val_00019691.bin 224 224 +11240 ./prep_dataset/ILSVRC2012_val_00045228.bin 224 224 +11241 ./prep_dataset/ILSVRC2012_val_00046425.bin 224 224 +11242 ./prep_dataset/ILSVRC2012_val_00045491.bin 224 224 +11243 ./prep_dataset/ILSVRC2012_val_00034899.bin 224 224 +11244 ./prep_dataset/ILSVRC2012_val_00005588.bin 224 224 +11245 ./prep_dataset/ILSVRC2012_val_00040684.bin 224 224 +11246 ./prep_dataset/ILSVRC2012_val_00038970.bin 224 224 +11247 ./prep_dataset/ILSVRC2012_val_00026922.bin 224 224 +11248 ./prep_dataset/ILSVRC2012_val_00043018.bin 224 224 +11249 ./prep_dataset/ILSVRC2012_val_00021179.bin 224 224 +11250 ./prep_dataset/ILSVRC2012_val_00040882.bin 224 224 +11251 ./prep_dataset/ILSVRC2012_val_00040984.bin 224 224 +11252 ./prep_dataset/ILSVRC2012_val_00043541.bin 224 224 +11253 ./prep_dataset/ILSVRC2012_val_00029604.bin 224 224 +11254 ./prep_dataset/ILSVRC2012_val_00024272.bin 224 224 +11255 ./prep_dataset/ILSVRC2012_val_00010581.bin 224 224 +11256 ./prep_dataset/ILSVRC2012_val_00009086.bin 224 224 +11257 ./prep_dataset/ILSVRC2012_val_00021741.bin 224 224 +11258 ./prep_dataset/ILSVRC2012_val_00011128.bin 224 224 +11259 ./prep_dataset/ILSVRC2012_val_00034368.bin 224 224 +11260 ./prep_dataset/ILSVRC2012_val_00008259.bin 224 224 +11261 ./prep_dataset/ILSVRC2012_val_00033411.bin 224 224 +11262 ./prep_dataset/ILSVRC2012_val_00044418.bin 224 224 +11263 ./prep_dataset/ILSVRC2012_val_00029362.bin 224 224 +11264 ./prep_dataset/ILSVRC2012_val_00015618.bin 224 224 +11265 ./prep_dataset/ILSVRC2012_val_00036103.bin 224 224 +11266 ./prep_dataset/ILSVRC2012_val_00041821.bin 224 224 +11267 ./prep_dataset/ILSVRC2012_val_00030673.bin 224 224 +11268 ./prep_dataset/ILSVRC2012_val_00011043.bin 224 224 +11269 ./prep_dataset/ILSVRC2012_val_00029767.bin 224 224 +11270 ./prep_dataset/ILSVRC2012_val_00039794.bin 224 224 +11271 ./prep_dataset/ILSVRC2012_val_00015440.bin 224 224 +11272 ./prep_dataset/ILSVRC2012_val_00000192.bin 224 224 +11273 ./prep_dataset/ILSVRC2012_val_00049424.bin 224 224 +11274 ./prep_dataset/ILSVRC2012_val_00003779.bin 224 224 +11275 ./prep_dataset/ILSVRC2012_val_00039369.bin 224 224 +11276 ./prep_dataset/ILSVRC2012_val_00008629.bin 224 224 +11277 ./prep_dataset/ILSVRC2012_val_00011632.bin 224 224 +11278 ./prep_dataset/ILSVRC2012_val_00025556.bin 224 224 +11279 ./prep_dataset/ILSVRC2012_val_00006261.bin 224 224 +11280 ./prep_dataset/ILSVRC2012_val_00040421.bin 224 224 +11281 ./prep_dataset/ILSVRC2012_val_00043523.bin 224 224 +11282 ./prep_dataset/ILSVRC2012_val_00002830.bin 224 224 +11283 ./prep_dataset/ILSVRC2012_val_00027117.bin 224 224 +11284 ./prep_dataset/ILSVRC2012_val_00023964.bin 224 224 +11285 ./prep_dataset/ILSVRC2012_val_00034058.bin 224 224 +11286 ./prep_dataset/ILSVRC2012_val_00006454.bin 224 224 +11287 ./prep_dataset/ILSVRC2012_val_00011514.bin 224 224 +11288 ./prep_dataset/ILSVRC2012_val_00041992.bin 224 224 +11289 ./prep_dataset/ILSVRC2012_val_00016181.bin 224 224 +11290 ./prep_dataset/ILSVRC2012_val_00024646.bin 224 224 +11291 ./prep_dataset/ILSVRC2012_val_00008668.bin 224 224 +11292 ./prep_dataset/ILSVRC2012_val_00009917.bin 224 224 +11293 ./prep_dataset/ILSVRC2012_val_00034813.bin 224 224 +11294 ./prep_dataset/ILSVRC2012_val_00010107.bin 224 224 +11295 ./prep_dataset/ILSVRC2012_val_00016140.bin 224 224 +11296 ./prep_dataset/ILSVRC2012_val_00018802.bin 224 224 +11297 ./prep_dataset/ILSVRC2012_val_00007202.bin 224 224 +11298 ./prep_dataset/ILSVRC2012_val_00003447.bin 224 224 +11299 ./prep_dataset/ILSVRC2012_val_00035550.bin 224 224 +11300 ./prep_dataset/ILSVRC2012_val_00047998.bin 224 224 +11301 ./prep_dataset/ILSVRC2012_val_00029903.bin 224 224 +11302 ./prep_dataset/ILSVRC2012_val_00005993.bin 224 224 +11303 ./prep_dataset/ILSVRC2012_val_00019156.bin 224 224 +11304 ./prep_dataset/ILSVRC2012_val_00023324.bin 224 224 +11305 ./prep_dataset/ILSVRC2012_val_00000977.bin 224 224 +11306 ./prep_dataset/ILSVRC2012_val_00031624.bin 224 224 +11307 ./prep_dataset/ILSVRC2012_val_00037558.bin 224 224 +11308 ./prep_dataset/ILSVRC2012_val_00009408.bin 224 224 +11309 ./prep_dataset/ILSVRC2012_val_00037817.bin 224 224 +11310 ./prep_dataset/ILSVRC2012_val_00015976.bin 224 224 +11311 ./prep_dataset/ILSVRC2012_val_00018697.bin 224 224 +11312 ./prep_dataset/ILSVRC2012_val_00038019.bin 224 224 +11313 ./prep_dataset/ILSVRC2012_val_00034069.bin 224 224 +11314 ./prep_dataset/ILSVRC2012_val_00039775.bin 224 224 +11315 ./prep_dataset/ILSVRC2012_val_00003930.bin 224 224 +11316 ./prep_dataset/ILSVRC2012_val_00018663.bin 224 224 +11317 ./prep_dataset/ILSVRC2012_val_00040259.bin 224 224 +11318 ./prep_dataset/ILSVRC2012_val_00016708.bin 224 224 +11319 ./prep_dataset/ILSVRC2012_val_00003190.bin 224 224 +11320 ./prep_dataset/ILSVRC2012_val_00028447.bin 224 224 +11321 ./prep_dataset/ILSVRC2012_val_00049313.bin 224 224 +11322 ./prep_dataset/ILSVRC2012_val_00039835.bin 224 224 +11323 ./prep_dataset/ILSVRC2012_val_00001800.bin 224 224 +11324 ./prep_dataset/ILSVRC2012_val_00019316.bin 224 224 +11325 ./prep_dataset/ILSVRC2012_val_00030693.bin 224 224 +11326 ./prep_dataset/ILSVRC2012_val_00002793.bin 224 224 +11327 ./prep_dataset/ILSVRC2012_val_00039588.bin 224 224 +11328 ./prep_dataset/ILSVRC2012_val_00014770.bin 224 224 +11329 ./prep_dataset/ILSVRC2012_val_00026861.bin 224 224 +11330 ./prep_dataset/ILSVRC2012_val_00000173.bin 224 224 +11331 ./prep_dataset/ILSVRC2012_val_00002571.bin 224 224 +11332 ./prep_dataset/ILSVRC2012_val_00013440.bin 224 224 +11333 ./prep_dataset/ILSVRC2012_val_00001630.bin 224 224 +11334 ./prep_dataset/ILSVRC2012_val_00016723.bin 224 224 +11335 ./prep_dataset/ILSVRC2012_val_00042658.bin 224 224 +11336 ./prep_dataset/ILSVRC2012_val_00034610.bin 224 224 +11337 ./prep_dataset/ILSVRC2012_val_00037785.bin 224 224 +11338 ./prep_dataset/ILSVRC2012_val_00008415.bin 224 224 +11339 ./prep_dataset/ILSVRC2012_val_00018305.bin 224 224 +11340 ./prep_dataset/ILSVRC2012_val_00009457.bin 224 224 +11341 ./prep_dataset/ILSVRC2012_val_00031321.bin 224 224 +11342 ./prep_dataset/ILSVRC2012_val_00042283.bin 224 224 +11343 ./prep_dataset/ILSVRC2012_val_00041245.bin 224 224 +11344 ./prep_dataset/ILSVRC2012_val_00048156.bin 224 224 +11345 ./prep_dataset/ILSVRC2012_val_00031633.bin 224 224 +11346 ./prep_dataset/ILSVRC2012_val_00020499.bin 224 224 +11347 ./prep_dataset/ILSVRC2012_val_00047375.bin 224 224 +11348 ./prep_dataset/ILSVRC2012_val_00042588.bin 224 224 +11349 ./prep_dataset/ILSVRC2012_val_00040333.bin 224 224 +11350 ./prep_dataset/ILSVRC2012_val_00046156.bin 224 224 +11351 ./prep_dataset/ILSVRC2012_val_00045302.bin 224 224 +11352 ./prep_dataset/ILSVRC2012_val_00026467.bin 224 224 +11353 ./prep_dataset/ILSVRC2012_val_00008600.bin 224 224 +11354 ./prep_dataset/ILSVRC2012_val_00034382.bin 224 224 +11355 ./prep_dataset/ILSVRC2012_val_00014043.bin 224 224 +11356 ./prep_dataset/ILSVRC2012_val_00021202.bin 224 224 +11357 ./prep_dataset/ILSVRC2012_val_00047383.bin 224 224 +11358 ./prep_dataset/ILSVRC2012_val_00027267.bin 224 224 +11359 ./prep_dataset/ILSVRC2012_val_00032924.bin 224 224 +11360 ./prep_dataset/ILSVRC2012_val_00025467.bin 224 224 +11361 ./prep_dataset/ILSVRC2012_val_00007412.bin 224 224 +11362 ./prep_dataset/ILSVRC2012_val_00033540.bin 224 224 +11363 ./prep_dataset/ILSVRC2012_val_00036914.bin 224 224 +11364 ./prep_dataset/ILSVRC2012_val_00035194.bin 224 224 +11365 ./prep_dataset/ILSVRC2012_val_00037940.bin 224 224 +11366 ./prep_dataset/ILSVRC2012_val_00015379.bin 224 224 +11367 ./prep_dataset/ILSVRC2012_val_00015157.bin 224 224 +11368 ./prep_dataset/ILSVRC2012_val_00031967.bin 224 224 +11369 ./prep_dataset/ILSVRC2012_val_00044285.bin 224 224 +11370 ./prep_dataset/ILSVRC2012_val_00042293.bin 224 224 +11371 ./prep_dataset/ILSVRC2012_val_00011227.bin 224 224 +11372 ./prep_dataset/ILSVRC2012_val_00040074.bin 224 224 +11373 ./prep_dataset/ILSVRC2012_val_00008771.bin 224 224 +11374 ./prep_dataset/ILSVRC2012_val_00016223.bin 224 224 +11375 ./prep_dataset/ILSVRC2012_val_00022841.bin 224 224 +11376 ./prep_dataset/ILSVRC2012_val_00009955.bin 224 224 +11377 ./prep_dataset/ILSVRC2012_val_00046698.bin 224 224 +11378 ./prep_dataset/ILSVRC2012_val_00048261.bin 224 224 +11379 ./prep_dataset/ILSVRC2012_val_00003403.bin 224 224 +11380 ./prep_dataset/ILSVRC2012_val_00011975.bin 224 224 +11381 ./prep_dataset/ILSVRC2012_val_00025361.bin 224 224 +11382 ./prep_dataset/ILSVRC2012_val_00025031.bin 224 224 +11383 ./prep_dataset/ILSVRC2012_val_00013488.bin 224 224 +11384 ./prep_dataset/ILSVRC2012_val_00022965.bin 224 224 +11385 ./prep_dataset/ILSVRC2012_val_00019903.bin 224 224 +11386 ./prep_dataset/ILSVRC2012_val_00009542.bin 224 224 +11387 ./prep_dataset/ILSVRC2012_val_00023712.bin 224 224 +11388 ./prep_dataset/ILSVRC2012_val_00042068.bin 224 224 +11389 ./prep_dataset/ILSVRC2012_val_00043418.bin 224 224 +11390 ./prep_dataset/ILSVRC2012_val_00033217.bin 224 224 +11391 ./prep_dataset/ILSVRC2012_val_00007702.bin 224 224 +11392 ./prep_dataset/ILSVRC2012_val_00024183.bin 224 224 +11393 ./prep_dataset/ILSVRC2012_val_00027745.bin 224 224 +11394 ./prep_dataset/ILSVRC2012_val_00023171.bin 224 224 +11395 ./prep_dataset/ILSVRC2012_val_00035924.bin 224 224 +11396 ./prep_dataset/ILSVRC2012_val_00005558.bin 224 224 +11397 ./prep_dataset/ILSVRC2012_val_00040481.bin 224 224 +11398 ./prep_dataset/ILSVRC2012_val_00020479.bin 224 224 +11399 ./prep_dataset/ILSVRC2012_val_00019523.bin 224 224 +11400 ./prep_dataset/ILSVRC2012_val_00049487.bin 224 224 +11401 ./prep_dataset/ILSVRC2012_val_00004265.bin 224 224 +11402 ./prep_dataset/ILSVRC2012_val_00029328.bin 224 224 +11403 ./prep_dataset/ILSVRC2012_val_00045376.bin 224 224 +11404 ./prep_dataset/ILSVRC2012_val_00027087.bin 224 224 +11405 ./prep_dataset/ILSVRC2012_val_00034403.bin 224 224 +11406 ./prep_dataset/ILSVRC2012_val_00043329.bin 224 224 +11407 ./prep_dataset/ILSVRC2012_val_00017026.bin 224 224 +11408 ./prep_dataset/ILSVRC2012_val_00030690.bin 224 224 +11409 ./prep_dataset/ILSVRC2012_val_00014946.bin 224 224 +11410 ./prep_dataset/ILSVRC2012_val_00012843.bin 224 224 +11411 ./prep_dataset/ILSVRC2012_val_00006038.bin 224 224 +11412 ./prep_dataset/ILSVRC2012_val_00028354.bin 224 224 +11413 ./prep_dataset/ILSVRC2012_val_00000627.bin 224 224 +11414 ./prep_dataset/ILSVRC2012_val_00035520.bin 224 224 +11415 ./prep_dataset/ILSVRC2012_val_00049331.bin 224 224 +11416 ./prep_dataset/ILSVRC2012_val_00035699.bin 224 224 +11417 ./prep_dataset/ILSVRC2012_val_00029748.bin 224 224 +11418 ./prep_dataset/ILSVRC2012_val_00020821.bin 224 224 +11419 ./prep_dataset/ILSVRC2012_val_00019350.bin 224 224 +11420 ./prep_dataset/ILSVRC2012_val_00005982.bin 224 224 +11421 ./prep_dataset/ILSVRC2012_val_00020281.bin 224 224 +11422 ./prep_dataset/ILSVRC2012_val_00001868.bin 224 224 +11423 ./prep_dataset/ILSVRC2012_val_00041150.bin 224 224 +11424 ./prep_dataset/ILSVRC2012_val_00000091.bin 224 224 +11425 ./prep_dataset/ILSVRC2012_val_00016162.bin 224 224 +11426 ./prep_dataset/ILSVRC2012_val_00047314.bin 224 224 +11427 ./prep_dataset/ILSVRC2012_val_00004906.bin 224 224 +11428 ./prep_dataset/ILSVRC2012_val_00035348.bin 224 224 +11429 ./prep_dataset/ILSVRC2012_val_00007660.bin 224 224 +11430 ./prep_dataset/ILSVRC2012_val_00006607.bin 224 224 +11431 ./prep_dataset/ILSVRC2012_val_00014615.bin 224 224 +11432 ./prep_dataset/ILSVRC2012_val_00030218.bin 224 224 +11433 ./prep_dataset/ILSVRC2012_val_00008001.bin 224 224 +11434 ./prep_dataset/ILSVRC2012_val_00026485.bin 224 224 +11435 ./prep_dataset/ILSVRC2012_val_00020667.bin 224 224 +11436 ./prep_dataset/ILSVRC2012_val_00015694.bin 224 224 +11437 ./prep_dataset/ILSVRC2012_val_00017219.bin 224 224 +11438 ./prep_dataset/ILSVRC2012_val_00014986.bin 224 224 +11439 ./prep_dataset/ILSVRC2012_val_00024948.bin 224 224 +11440 ./prep_dataset/ILSVRC2012_val_00048872.bin 224 224 +11441 ./prep_dataset/ILSVRC2012_val_00036122.bin 224 224 +11442 ./prep_dataset/ILSVRC2012_val_00040281.bin 224 224 +11443 ./prep_dataset/ILSVRC2012_val_00011821.bin 224 224 +11444 ./prep_dataset/ILSVRC2012_val_00032710.bin 224 224 +11445 ./prep_dataset/ILSVRC2012_val_00011562.bin 224 224 +11446 ./prep_dataset/ILSVRC2012_val_00019735.bin 224 224 +11447 ./prep_dataset/ILSVRC2012_val_00006491.bin 224 224 +11448 ./prep_dataset/ILSVRC2012_val_00034463.bin 224 224 +11449 ./prep_dataset/ILSVRC2012_val_00028934.bin 224 224 +11450 ./prep_dataset/ILSVRC2012_val_00017629.bin 224 224 +11451 ./prep_dataset/ILSVRC2012_val_00013026.bin 224 224 +11452 ./prep_dataset/ILSVRC2012_val_00022709.bin 224 224 +11453 ./prep_dataset/ILSVRC2012_val_00000044.bin 224 224 +11454 ./prep_dataset/ILSVRC2012_val_00017616.bin 224 224 +11455 ./prep_dataset/ILSVRC2012_val_00018323.bin 224 224 +11456 ./prep_dataset/ILSVRC2012_val_00033282.bin 224 224 +11457 ./prep_dataset/ILSVRC2012_val_00014868.bin 224 224 +11458 ./prep_dataset/ILSVRC2012_val_00014147.bin 224 224 +11459 ./prep_dataset/ILSVRC2012_val_00006510.bin 224 224 +11460 ./prep_dataset/ILSVRC2012_val_00003136.bin 224 224 +11461 ./prep_dataset/ILSVRC2012_val_00009921.bin 224 224 +11462 ./prep_dataset/ILSVRC2012_val_00047520.bin 224 224 +11463 ./prep_dataset/ILSVRC2012_val_00038512.bin 224 224 +11464 ./prep_dataset/ILSVRC2012_val_00022193.bin 224 224 +11465 ./prep_dataset/ILSVRC2012_val_00033224.bin 224 224 +11466 ./prep_dataset/ILSVRC2012_val_00015767.bin 224 224 +11467 ./prep_dataset/ILSVRC2012_val_00016305.bin 224 224 +11468 ./prep_dataset/ILSVRC2012_val_00024266.bin 224 224 +11469 ./prep_dataset/ILSVRC2012_val_00019453.bin 224 224 +11470 ./prep_dataset/ILSVRC2012_val_00034854.bin 224 224 +11471 ./prep_dataset/ILSVRC2012_val_00041614.bin 224 224 +11472 ./prep_dataset/ILSVRC2012_val_00002781.bin 224 224 +11473 ./prep_dataset/ILSVRC2012_val_00010840.bin 224 224 +11474 ./prep_dataset/ILSVRC2012_val_00004692.bin 224 224 +11475 ./prep_dataset/ILSVRC2012_val_00005684.bin 224 224 +11476 ./prep_dataset/ILSVRC2012_val_00049268.bin 224 224 +11477 ./prep_dataset/ILSVRC2012_val_00003420.bin 224 224 +11478 ./prep_dataset/ILSVRC2012_val_00015486.bin 224 224 +11479 ./prep_dataset/ILSVRC2012_val_00015251.bin 224 224 +11480 ./prep_dataset/ILSVRC2012_val_00010509.bin 224 224 +11481 ./prep_dataset/ILSVRC2012_val_00001530.bin 224 224 +11482 ./prep_dataset/ILSVRC2012_val_00005182.bin 224 224 +11483 ./prep_dataset/ILSVRC2012_val_00036840.bin 224 224 +11484 ./prep_dataset/ILSVRC2012_val_00038145.bin 224 224 +11485 ./prep_dataset/ILSVRC2012_val_00035045.bin 224 224 +11486 ./prep_dataset/ILSVRC2012_val_00023342.bin 224 224 +11487 ./prep_dataset/ILSVRC2012_val_00008797.bin 224 224 +11488 ./prep_dataset/ILSVRC2012_val_00016918.bin 224 224 +11489 ./prep_dataset/ILSVRC2012_val_00014277.bin 224 224 +11490 ./prep_dataset/ILSVRC2012_val_00028167.bin 224 224 +11491 ./prep_dataset/ILSVRC2012_val_00049063.bin 224 224 +11492 ./prep_dataset/ILSVRC2012_val_00042538.bin 224 224 +11493 ./prep_dataset/ILSVRC2012_val_00018799.bin 224 224 +11494 ./prep_dataset/ILSVRC2012_val_00007009.bin 224 224 +11495 ./prep_dataset/ILSVRC2012_val_00046706.bin 224 224 +11496 ./prep_dataset/ILSVRC2012_val_00002443.bin 224 224 +11497 ./prep_dataset/ILSVRC2012_val_00028497.bin 224 224 +11498 ./prep_dataset/ILSVRC2012_val_00037281.bin 224 224 +11499 ./prep_dataset/ILSVRC2012_val_00015955.bin 224 224 +11500 ./prep_dataset/ILSVRC2012_val_00007413.bin 224 224 +11501 ./prep_dataset/ILSVRC2012_val_00036676.bin 224 224 +11502 ./prep_dataset/ILSVRC2012_val_00045253.bin 224 224 +11503 ./prep_dataset/ILSVRC2012_val_00016766.bin 224 224 +11504 ./prep_dataset/ILSVRC2012_val_00014520.bin 224 224 +11505 ./prep_dataset/ILSVRC2012_val_00014323.bin 224 224 +11506 ./prep_dataset/ILSVRC2012_val_00000069.bin 224 224 +11507 ./prep_dataset/ILSVRC2012_val_00016759.bin 224 224 +11508 ./prep_dataset/ILSVRC2012_val_00023534.bin 224 224 +11509 ./prep_dataset/ILSVRC2012_val_00036390.bin 224 224 +11510 ./prep_dataset/ILSVRC2012_val_00021049.bin 224 224 +11511 ./prep_dataset/ILSVRC2012_val_00014471.bin 224 224 +11512 ./prep_dataset/ILSVRC2012_val_00022597.bin 224 224 +11513 ./prep_dataset/ILSVRC2012_val_00015028.bin 224 224 +11514 ./prep_dataset/ILSVRC2012_val_00001490.bin 224 224 +11515 ./prep_dataset/ILSVRC2012_val_00023780.bin 224 224 +11516 ./prep_dataset/ILSVRC2012_val_00033080.bin 224 224 +11517 ./prep_dataset/ILSVRC2012_val_00002467.bin 224 224 +11518 ./prep_dataset/ILSVRC2012_val_00044475.bin 224 224 +11519 ./prep_dataset/ILSVRC2012_val_00030237.bin 224 224 +11520 ./prep_dataset/ILSVRC2012_val_00042360.bin 224 224 +11521 ./prep_dataset/ILSVRC2012_val_00005870.bin 224 224 +11522 ./prep_dataset/ILSVRC2012_val_00046746.bin 224 224 +11523 ./prep_dataset/ILSVRC2012_val_00017840.bin 224 224 +11524 ./prep_dataset/ILSVRC2012_val_00018892.bin 224 224 +11525 ./prep_dataset/ILSVRC2012_val_00033148.bin 224 224 +11526 ./prep_dataset/ILSVRC2012_val_00018033.bin 224 224 +11527 ./prep_dataset/ILSVRC2012_val_00023442.bin 224 224 +11528 ./prep_dataset/ILSVRC2012_val_00017816.bin 224 224 +11529 ./prep_dataset/ILSVRC2012_val_00043346.bin 224 224 +11530 ./prep_dataset/ILSVRC2012_val_00040865.bin 224 224 +11531 ./prep_dataset/ILSVRC2012_val_00042098.bin 224 224 +11532 ./prep_dataset/ILSVRC2012_val_00033170.bin 224 224 +11533 ./prep_dataset/ILSVRC2012_val_00049352.bin 224 224 +11534 ./prep_dataset/ILSVRC2012_val_00011244.bin 224 224 +11535 ./prep_dataset/ILSVRC2012_val_00043406.bin 224 224 +11536 ./prep_dataset/ILSVRC2012_val_00033831.bin 224 224 +11537 ./prep_dataset/ILSVRC2012_val_00007953.bin 224 224 +11538 ./prep_dataset/ILSVRC2012_val_00024526.bin 224 224 +11539 ./prep_dataset/ILSVRC2012_val_00011444.bin 224 224 +11540 ./prep_dataset/ILSVRC2012_val_00010296.bin 224 224 +11541 ./prep_dataset/ILSVRC2012_val_00042509.bin 224 224 +11542 ./prep_dataset/ILSVRC2012_val_00018176.bin 224 224 +11543 ./prep_dataset/ILSVRC2012_val_00003550.bin 224 224 +11544 ./prep_dataset/ILSVRC2012_val_00033158.bin 224 224 +11545 ./prep_dataset/ILSVRC2012_val_00046833.bin 224 224 +11546 ./prep_dataset/ILSVRC2012_val_00037696.bin 224 224 +11547 ./prep_dataset/ILSVRC2012_val_00041367.bin 224 224 +11548 ./prep_dataset/ILSVRC2012_val_00018419.bin 224 224 +11549 ./prep_dataset/ILSVRC2012_val_00011722.bin 224 224 +11550 ./prep_dataset/ILSVRC2012_val_00047807.bin 224 224 +11551 ./prep_dataset/ILSVRC2012_val_00043928.bin 224 224 +11552 ./prep_dataset/ILSVRC2012_val_00005362.bin 224 224 +11553 ./prep_dataset/ILSVRC2012_val_00021508.bin 224 224 +11554 ./prep_dataset/ILSVRC2012_val_00000422.bin 224 224 +11555 ./prep_dataset/ILSVRC2012_val_00035340.bin 224 224 +11556 ./prep_dataset/ILSVRC2012_val_00005703.bin 224 224 +11557 ./prep_dataset/ILSVRC2012_val_00000687.bin 224 224 +11558 ./prep_dataset/ILSVRC2012_val_00017917.bin 224 224 +11559 ./prep_dataset/ILSVRC2012_val_00025476.bin 224 224 +11560 ./prep_dataset/ILSVRC2012_val_00006129.bin 224 224 +11561 ./prep_dataset/ILSVRC2012_val_00011888.bin 224 224 +11562 ./prep_dataset/ILSVRC2012_val_00033920.bin 224 224 +11563 ./prep_dataset/ILSVRC2012_val_00018020.bin 224 224 +11564 ./prep_dataset/ILSVRC2012_val_00016496.bin 224 224 +11565 ./prep_dataset/ILSVRC2012_val_00045925.bin 224 224 +11566 ./prep_dataset/ILSVRC2012_val_00036482.bin 224 224 +11567 ./prep_dataset/ILSVRC2012_val_00039720.bin 224 224 +11568 ./prep_dataset/ILSVRC2012_val_00047585.bin 224 224 +11569 ./prep_dataset/ILSVRC2012_val_00018605.bin 224 224 +11570 ./prep_dataset/ILSVRC2012_val_00013702.bin 224 224 +11571 ./prep_dataset/ILSVRC2012_val_00030542.bin 224 224 +11572 ./prep_dataset/ILSVRC2012_val_00029958.bin 224 224 +11573 ./prep_dataset/ILSVRC2012_val_00039873.bin 224 224 +11574 ./prep_dataset/ILSVRC2012_val_00042393.bin 224 224 +11575 ./prep_dataset/ILSVRC2012_val_00001609.bin 224 224 +11576 ./prep_dataset/ILSVRC2012_val_00020481.bin 224 224 +11577 ./prep_dataset/ILSVRC2012_val_00037443.bin 224 224 +11578 ./prep_dataset/ILSVRC2012_val_00032876.bin 224 224 +11579 ./prep_dataset/ILSVRC2012_val_00004184.bin 224 224 +11580 ./prep_dataset/ILSVRC2012_val_00026034.bin 224 224 +11581 ./prep_dataset/ILSVRC2012_val_00029250.bin 224 224 +11582 ./prep_dataset/ILSVRC2012_val_00019595.bin 224 224 +11583 ./prep_dataset/ILSVRC2012_val_00018301.bin 224 224 +11584 ./prep_dataset/ILSVRC2012_val_00049181.bin 224 224 +11585 ./prep_dataset/ILSVRC2012_val_00039215.bin 224 224 +11586 ./prep_dataset/ILSVRC2012_val_00020273.bin 224 224 +11587 ./prep_dataset/ILSVRC2012_val_00010888.bin 224 224 +11588 ./prep_dataset/ILSVRC2012_val_00033972.bin 224 224 +11589 ./prep_dataset/ILSVRC2012_val_00006870.bin 224 224 +11590 ./prep_dataset/ILSVRC2012_val_00046496.bin 224 224 +11591 ./prep_dataset/ILSVRC2012_val_00040934.bin 224 224 +11592 ./prep_dataset/ILSVRC2012_val_00024926.bin 224 224 +11593 ./prep_dataset/ILSVRC2012_val_00008686.bin 224 224 +11594 ./prep_dataset/ILSVRC2012_val_00003000.bin 224 224 +11595 ./prep_dataset/ILSVRC2012_val_00013001.bin 224 224 +11596 ./prep_dataset/ILSVRC2012_val_00008030.bin 224 224 +11597 ./prep_dataset/ILSVRC2012_val_00043492.bin 224 224 +11598 ./prep_dataset/ILSVRC2012_val_00000153.bin 224 224 +11599 ./prep_dataset/ILSVRC2012_val_00017875.bin 224 224 +11600 ./prep_dataset/ILSVRC2012_val_00027362.bin 224 224 +11601 ./prep_dataset/ILSVRC2012_val_00045948.bin 224 224 +11602 ./prep_dataset/ILSVRC2012_val_00003898.bin 224 224 +11603 ./prep_dataset/ILSVRC2012_val_00048652.bin 224 224 +11604 ./prep_dataset/ILSVRC2012_val_00026178.bin 224 224 +11605 ./prep_dataset/ILSVRC2012_val_00048686.bin 224 224 +11606 ./prep_dataset/ILSVRC2012_val_00024966.bin 224 224 +11607 ./prep_dataset/ILSVRC2012_val_00027273.bin 224 224 +11608 ./prep_dataset/ILSVRC2012_val_00008155.bin 224 224 +11609 ./prep_dataset/ILSVRC2012_val_00021878.bin 224 224 +11610 ./prep_dataset/ILSVRC2012_val_00007072.bin 224 224 +11611 ./prep_dataset/ILSVRC2012_val_00019746.bin 224 224 +11612 ./prep_dataset/ILSVRC2012_val_00024740.bin 224 224 +11613 ./prep_dataset/ILSVRC2012_val_00034159.bin 224 224 +11614 ./prep_dataset/ILSVRC2012_val_00026319.bin 224 224 +11615 ./prep_dataset/ILSVRC2012_val_00029369.bin 224 224 +11616 ./prep_dataset/ILSVRC2012_val_00019002.bin 224 224 +11617 ./prep_dataset/ILSVRC2012_val_00030707.bin 224 224 +11618 ./prep_dataset/ILSVRC2012_val_00024564.bin 224 224 +11619 ./prep_dataset/ILSVRC2012_val_00018963.bin 224 224 +11620 ./prep_dataset/ILSVRC2012_val_00045502.bin 224 224 +11621 ./prep_dataset/ILSVRC2012_val_00012593.bin 224 224 +11622 ./prep_dataset/ILSVRC2012_val_00026196.bin 224 224 +11623 ./prep_dataset/ILSVRC2012_val_00001649.bin 224 224 +11624 ./prep_dataset/ILSVRC2012_val_00026023.bin 224 224 +11625 ./prep_dataset/ILSVRC2012_val_00017931.bin 224 224 +11626 ./prep_dataset/ILSVRC2012_val_00041267.bin 224 224 +11627 ./prep_dataset/ILSVRC2012_val_00032453.bin 224 224 +11628 ./prep_dataset/ILSVRC2012_val_00013227.bin 224 224 +11629 ./prep_dataset/ILSVRC2012_val_00033386.bin 224 224 +11630 ./prep_dataset/ILSVRC2012_val_00036885.bin 224 224 +11631 ./prep_dataset/ILSVRC2012_val_00017289.bin 224 224 +11632 ./prep_dataset/ILSVRC2012_val_00043969.bin 224 224 +11633 ./prep_dataset/ILSVRC2012_val_00034136.bin 224 224 +11634 ./prep_dataset/ILSVRC2012_val_00047760.bin 224 224 +11635 ./prep_dataset/ILSVRC2012_val_00002645.bin 224 224 +11636 ./prep_dataset/ILSVRC2012_val_00044335.bin 224 224 +11637 ./prep_dataset/ILSVRC2012_val_00035997.bin 224 224 +11638 ./prep_dataset/ILSVRC2012_val_00004482.bin 224 224 +11639 ./prep_dataset/ILSVRC2012_val_00008953.bin 224 224 +11640 ./prep_dataset/ILSVRC2012_val_00007763.bin 224 224 +11641 ./prep_dataset/ILSVRC2012_val_00028400.bin 224 224 +11642 ./prep_dataset/ILSVRC2012_val_00049701.bin 224 224 +11643 ./prep_dataset/ILSVRC2012_val_00005262.bin 224 224 +11644 ./prep_dataset/ILSVRC2012_val_00049531.bin 224 224 +11645 ./prep_dataset/ILSVRC2012_val_00019963.bin 224 224 +11646 ./prep_dataset/ILSVRC2012_val_00016668.bin 224 224 +11647 ./prep_dataset/ILSVRC2012_val_00020482.bin 224 224 +11648 ./prep_dataset/ILSVRC2012_val_00024490.bin 224 224 +11649 ./prep_dataset/ILSVRC2012_val_00013690.bin 224 224 +11650 ./prep_dataset/ILSVRC2012_val_00043286.bin 224 224 +11651 ./prep_dataset/ILSVRC2012_val_00028902.bin 224 224 +11652 ./prep_dataset/ILSVRC2012_val_00029563.bin 224 224 +11653 ./prep_dataset/ILSVRC2012_val_00024881.bin 224 224 +11654 ./prep_dataset/ILSVRC2012_val_00039946.bin 224 224 +11655 ./prep_dataset/ILSVRC2012_val_00019606.bin 224 224 +11656 ./prep_dataset/ILSVRC2012_val_00041765.bin 224 224 +11657 ./prep_dataset/ILSVRC2012_val_00037268.bin 224 224 +11658 ./prep_dataset/ILSVRC2012_val_00002373.bin 224 224 +11659 ./prep_dataset/ILSVRC2012_val_00003902.bin 224 224 +11660 ./prep_dataset/ILSVRC2012_val_00044426.bin 224 224 +11661 ./prep_dataset/ILSVRC2012_val_00040667.bin 224 224 +11662 ./prep_dataset/ILSVRC2012_val_00041167.bin 224 224 +11663 ./prep_dataset/ILSVRC2012_val_00010978.bin 224 224 +11664 ./prep_dataset/ILSVRC2012_val_00012437.bin 224 224 +11665 ./prep_dataset/ILSVRC2012_val_00039799.bin 224 224 +11666 ./prep_dataset/ILSVRC2012_val_00002799.bin 224 224 +11667 ./prep_dataset/ILSVRC2012_val_00014654.bin 224 224 +11668 ./prep_dataset/ILSVRC2012_val_00019812.bin 224 224 +11669 ./prep_dataset/ILSVRC2012_val_00020426.bin 224 224 +11670 ./prep_dataset/ILSVRC2012_val_00031227.bin 224 224 +11671 ./prep_dataset/ILSVRC2012_val_00029456.bin 224 224 +11672 ./prep_dataset/ILSVRC2012_val_00022235.bin 224 224 +11673 ./prep_dataset/ILSVRC2012_val_00027990.bin 224 224 +11674 ./prep_dataset/ILSVRC2012_val_00023736.bin 224 224 +11675 ./prep_dataset/ILSVRC2012_val_00016344.bin 224 224 +11676 ./prep_dataset/ILSVRC2012_val_00019601.bin 224 224 +11677 ./prep_dataset/ILSVRC2012_val_00039904.bin 224 224 +11678 ./prep_dataset/ILSVRC2012_val_00033774.bin 224 224 +11679 ./prep_dataset/ILSVRC2012_val_00042303.bin 224 224 +11680 ./prep_dataset/ILSVRC2012_val_00000387.bin 224 224 +11681 ./prep_dataset/ILSVRC2012_val_00002871.bin 224 224 +11682 ./prep_dataset/ILSVRC2012_val_00002418.bin 224 224 +11683 ./prep_dataset/ILSVRC2012_val_00019939.bin 224 224 +11684 ./prep_dataset/ILSVRC2012_val_00012665.bin 224 224 +11685 ./prep_dataset/ILSVRC2012_val_00011028.bin 224 224 +11686 ./prep_dataset/ILSVRC2012_val_00045352.bin 224 224 +11687 ./prep_dataset/ILSVRC2012_val_00027046.bin 224 224 +11688 ./prep_dataset/ILSVRC2012_val_00024588.bin 224 224 +11689 ./prep_dataset/ILSVRC2012_val_00044748.bin 224 224 +11690 ./prep_dataset/ILSVRC2012_val_00040849.bin 224 224 +11691 ./prep_dataset/ILSVRC2012_val_00013265.bin 224 224 +11692 ./prep_dataset/ILSVRC2012_val_00033143.bin 224 224 +11693 ./prep_dataset/ILSVRC2012_val_00029895.bin 224 224 +11694 ./prep_dataset/ILSVRC2012_val_00042568.bin 224 224 +11695 ./prep_dataset/ILSVRC2012_val_00009460.bin 224 224 +11696 ./prep_dataset/ILSVRC2012_val_00038322.bin 224 224 +11697 ./prep_dataset/ILSVRC2012_val_00020627.bin 224 224 +11698 ./prep_dataset/ILSVRC2012_val_00036063.bin 224 224 +11699 ./prep_dataset/ILSVRC2012_val_00014657.bin 224 224 +11700 ./prep_dataset/ILSVRC2012_val_00017876.bin 224 224 +11701 ./prep_dataset/ILSVRC2012_val_00025981.bin 224 224 +11702 ./prep_dataset/ILSVRC2012_val_00048597.bin 224 224 +11703 ./prep_dataset/ILSVRC2012_val_00029763.bin 224 224 +11704 ./prep_dataset/ILSVRC2012_val_00030852.bin 224 224 +11705 ./prep_dataset/ILSVRC2012_val_00030320.bin 224 224 +11706 ./prep_dataset/ILSVRC2012_val_00021584.bin 224 224 +11707 ./prep_dataset/ILSVRC2012_val_00009220.bin 224 224 +11708 ./prep_dataset/ILSVRC2012_val_00044313.bin 224 224 +11709 ./prep_dataset/ILSVRC2012_val_00005498.bin 224 224 +11710 ./prep_dataset/ILSVRC2012_val_00018776.bin 224 224 +11711 ./prep_dataset/ILSVRC2012_val_00037565.bin 224 224 +11712 ./prep_dataset/ILSVRC2012_val_00012618.bin 224 224 +11713 ./prep_dataset/ILSVRC2012_val_00026068.bin 224 224 +11714 ./prep_dataset/ILSVRC2012_val_00005288.bin 224 224 +11715 ./prep_dataset/ILSVRC2012_val_00026259.bin 224 224 +11716 ./prep_dataset/ILSVRC2012_val_00006555.bin 224 224 +11717 ./prep_dataset/ILSVRC2012_val_00014127.bin 224 224 +11718 ./prep_dataset/ILSVRC2012_val_00036850.bin 224 224 +11719 ./prep_dataset/ILSVRC2012_val_00014640.bin 224 224 +11720 ./prep_dataset/ILSVRC2012_val_00012111.bin 224 224 +11721 ./prep_dataset/ILSVRC2012_val_00033088.bin 224 224 +11722 ./prep_dataset/ILSVRC2012_val_00007015.bin 224 224 +11723 ./prep_dataset/ILSVRC2012_val_00002711.bin 224 224 +11724 ./prep_dataset/ILSVRC2012_val_00028291.bin 224 224 +11725 ./prep_dataset/ILSVRC2012_val_00012143.bin 224 224 +11726 ./prep_dataset/ILSVRC2012_val_00021905.bin 224 224 +11727 ./prep_dataset/ILSVRC2012_val_00030511.bin 224 224 +11728 ./prep_dataset/ILSVRC2012_val_00027286.bin 224 224 +11729 ./prep_dataset/ILSVRC2012_val_00020540.bin 224 224 +11730 ./prep_dataset/ILSVRC2012_val_00039934.bin 224 224 +11731 ./prep_dataset/ILSVRC2012_val_00041289.bin 224 224 +11732 ./prep_dataset/ILSVRC2012_val_00006726.bin 224 224 +11733 ./prep_dataset/ILSVRC2012_val_00048557.bin 224 224 +11734 ./prep_dataset/ILSVRC2012_val_00039542.bin 224 224 +11735 ./prep_dataset/ILSVRC2012_val_00014830.bin 224 224 +11736 ./prep_dataset/ILSVRC2012_val_00038421.bin 224 224 +11737 ./prep_dataset/ILSVRC2012_val_00040435.bin 224 224 +11738 ./prep_dataset/ILSVRC2012_val_00016366.bin 224 224 +11739 ./prep_dataset/ILSVRC2012_val_00000864.bin 224 224 +11740 ./prep_dataset/ILSVRC2012_val_00001428.bin 224 224 +11741 ./prep_dataset/ILSVRC2012_val_00006813.bin 224 224 +11742 ./prep_dataset/ILSVRC2012_val_00031197.bin 224 224 +11743 ./prep_dataset/ILSVRC2012_val_00039104.bin 224 224 +11744 ./prep_dataset/ILSVRC2012_val_00000517.bin 224 224 +11745 ./prep_dataset/ILSVRC2012_val_00010028.bin 224 224 +11746 ./prep_dataset/ILSVRC2012_val_00028641.bin 224 224 +11747 ./prep_dataset/ILSVRC2012_val_00027084.bin 224 224 +11748 ./prep_dataset/ILSVRC2012_val_00038850.bin 224 224 +11749 ./prep_dataset/ILSVRC2012_val_00037391.bin 224 224 +11750 ./prep_dataset/ILSVRC2012_val_00003630.bin 224 224 +11751 ./prep_dataset/ILSVRC2012_val_00033011.bin 224 224 +11752 ./prep_dataset/ILSVRC2012_val_00007109.bin 224 224 +11753 ./prep_dataset/ILSVRC2012_val_00034269.bin 224 224 +11754 ./prep_dataset/ILSVRC2012_val_00021675.bin 224 224 +11755 ./prep_dataset/ILSVRC2012_val_00018994.bin 224 224 +11756 ./prep_dataset/ILSVRC2012_val_00015172.bin 224 224 +11757 ./prep_dataset/ILSVRC2012_val_00035294.bin 224 224 +11758 ./prep_dataset/ILSVRC2012_val_00032194.bin 224 224 +11759 ./prep_dataset/ILSVRC2012_val_00041137.bin 224 224 +11760 ./prep_dataset/ILSVRC2012_val_00038664.bin 224 224 +11761 ./prep_dataset/ILSVRC2012_val_00027774.bin 224 224 +11762 ./prep_dataset/ILSVRC2012_val_00035821.bin 224 224 +11763 ./prep_dataset/ILSVRC2012_val_00023000.bin 224 224 +11764 ./prep_dataset/ILSVRC2012_val_00007446.bin 224 224 +11765 ./prep_dataset/ILSVRC2012_val_00010317.bin 224 224 +11766 ./prep_dataset/ILSVRC2012_val_00012755.bin 224 224 +11767 ./prep_dataset/ILSVRC2012_val_00011083.bin 224 224 +11768 ./prep_dataset/ILSVRC2012_val_00034360.bin 224 224 +11769 ./prep_dataset/ILSVRC2012_val_00024053.bin 224 224 +11770 ./prep_dataset/ILSVRC2012_val_00011989.bin 224 224 +11771 ./prep_dataset/ILSVRC2012_val_00021600.bin 224 224 +11772 ./prep_dataset/ILSVRC2012_val_00038707.bin 224 224 +11773 ./prep_dataset/ILSVRC2012_val_00013612.bin 224 224 +11774 ./prep_dataset/ILSVRC2012_val_00019756.bin 224 224 +11775 ./prep_dataset/ILSVRC2012_val_00006209.bin 224 224 +11776 ./prep_dataset/ILSVRC2012_val_00006486.bin 224 224 +11777 ./prep_dataset/ILSVRC2012_val_00049457.bin 224 224 +11778 ./prep_dataset/ILSVRC2012_val_00008316.bin 224 224 +11779 ./prep_dataset/ILSVRC2012_val_00010464.bin 224 224 +11780 ./prep_dataset/ILSVRC2012_val_00045667.bin 224 224 +11781 ./prep_dataset/ILSVRC2012_val_00005478.bin 224 224 +11782 ./prep_dataset/ILSVRC2012_val_00039038.bin 224 224 +11783 ./prep_dataset/ILSVRC2012_val_00017280.bin 224 224 +11784 ./prep_dataset/ILSVRC2012_val_00008695.bin 224 224 +11785 ./prep_dataset/ILSVRC2012_val_00030614.bin 224 224 +11786 ./prep_dataset/ILSVRC2012_val_00019386.bin 224 224 +11787 ./prep_dataset/ILSVRC2012_val_00019906.bin 224 224 +11788 ./prep_dataset/ILSVRC2012_val_00020057.bin 224 224 +11789 ./prep_dataset/ILSVRC2012_val_00047889.bin 224 224 +11790 ./prep_dataset/ILSVRC2012_val_00042237.bin 224 224 +11791 ./prep_dataset/ILSVRC2012_val_00010647.bin 224 224 +11792 ./prep_dataset/ILSVRC2012_val_00041943.bin 224 224 +11793 ./prep_dataset/ILSVRC2012_val_00003797.bin 224 224 +11794 ./prep_dataset/ILSVRC2012_val_00031757.bin 224 224 +11795 ./prep_dataset/ILSVRC2012_val_00025248.bin 224 224 +11796 ./prep_dataset/ILSVRC2012_val_00032982.bin 224 224 +11797 ./prep_dataset/ILSVRC2012_val_00048333.bin 224 224 +11798 ./prep_dataset/ILSVRC2012_val_00044067.bin 224 224 +11799 ./prep_dataset/ILSVRC2012_val_00018655.bin 224 224 +11800 ./prep_dataset/ILSVRC2012_val_00038010.bin 224 224 +11801 ./prep_dataset/ILSVRC2012_val_00012452.bin 224 224 +11802 ./prep_dataset/ILSVRC2012_val_00014844.bin 224 224 +11803 ./prep_dataset/ILSVRC2012_val_00009663.bin 224 224 +11804 ./prep_dataset/ILSVRC2012_val_00017579.bin 224 224 +11805 ./prep_dataset/ILSVRC2012_val_00029726.bin 224 224 +11806 ./prep_dataset/ILSVRC2012_val_00020249.bin 224 224 +11807 ./prep_dataset/ILSVRC2012_val_00035330.bin 224 224 +11808 ./prep_dataset/ILSVRC2012_val_00031082.bin 224 224 +11809 ./prep_dataset/ILSVRC2012_val_00031051.bin 224 224 +11810 ./prep_dataset/ILSVRC2012_val_00007093.bin 224 224 +11811 ./prep_dataset/ILSVRC2012_val_00029221.bin 224 224 +11812 ./prep_dataset/ILSVRC2012_val_00026874.bin 224 224 +11813 ./prep_dataset/ILSVRC2012_val_00041179.bin 224 224 +11814 ./prep_dataset/ILSVRC2012_val_00012213.bin 224 224 +11815 ./prep_dataset/ILSVRC2012_val_00000994.bin 224 224 +11816 ./prep_dataset/ILSVRC2012_val_00009258.bin 224 224 +11817 ./prep_dataset/ILSVRC2012_val_00043745.bin 224 224 +11818 ./prep_dataset/ILSVRC2012_val_00037064.bin 224 224 +11819 ./prep_dataset/ILSVRC2012_val_00032273.bin 224 224 +11820 ./prep_dataset/ILSVRC2012_val_00015467.bin 224 224 +11821 ./prep_dataset/ILSVRC2012_val_00010213.bin 224 224 +11822 ./prep_dataset/ILSVRC2012_val_00005911.bin 224 224 +11823 ./prep_dataset/ILSVRC2012_val_00025172.bin 224 224 +11824 ./prep_dataset/ILSVRC2012_val_00021263.bin 224 224 +11825 ./prep_dataset/ILSVRC2012_val_00016829.bin 224 224 +11826 ./prep_dataset/ILSVRC2012_val_00037406.bin 224 224 +11827 ./prep_dataset/ILSVRC2012_val_00034338.bin 224 224 +11828 ./prep_dataset/ILSVRC2012_val_00003566.bin 224 224 +11829 ./prep_dataset/ILSVRC2012_val_00020709.bin 224 224 +11830 ./prep_dataset/ILSVRC2012_val_00034348.bin 224 224 +11831 ./prep_dataset/ILSVRC2012_val_00039062.bin 224 224 +11832 ./prep_dataset/ILSVRC2012_val_00001833.bin 224 224 +11833 ./prep_dataset/ILSVRC2012_val_00004162.bin 224 224 +11834 ./prep_dataset/ILSVRC2012_val_00038027.bin 224 224 +11835 ./prep_dataset/ILSVRC2012_val_00024137.bin 224 224 +11836 ./prep_dataset/ILSVRC2012_val_00029397.bin 224 224 +11837 ./prep_dataset/ILSVRC2012_val_00036770.bin 224 224 +11838 ./prep_dataset/ILSVRC2012_val_00020312.bin 224 224 +11839 ./prep_dataset/ILSVRC2012_val_00009929.bin 224 224 +11840 ./prep_dataset/ILSVRC2012_val_00036104.bin 224 224 +11841 ./prep_dataset/ILSVRC2012_val_00019728.bin 224 224 +11842 ./prep_dataset/ILSVRC2012_val_00004358.bin 224 224 +11843 ./prep_dataset/ILSVRC2012_val_00033977.bin 224 224 +11844 ./prep_dataset/ILSVRC2012_val_00003655.bin 224 224 +11845 ./prep_dataset/ILSVRC2012_val_00015418.bin 224 224 +11846 ./prep_dataset/ILSVRC2012_val_00003620.bin 224 224 +11847 ./prep_dataset/ILSVRC2012_val_00034439.bin 224 224 +11848 ./prep_dataset/ILSVRC2012_val_00049456.bin 224 224 +11849 ./prep_dataset/ILSVRC2012_val_00022383.bin 224 224 +11850 ./prep_dataset/ILSVRC2012_val_00035740.bin 224 224 +11851 ./prep_dataset/ILSVRC2012_val_00020877.bin 224 224 +11852 ./prep_dataset/ILSVRC2012_val_00045378.bin 224 224 +11853 ./prep_dataset/ILSVRC2012_val_00029322.bin 224 224 +11854 ./prep_dataset/ILSVRC2012_val_00030166.bin 224 224 +11855 ./prep_dataset/ILSVRC2012_val_00002662.bin 224 224 +11856 ./prep_dataset/ILSVRC2012_val_00004912.bin 224 224 +11857 ./prep_dataset/ILSVRC2012_val_00039742.bin 224 224 +11858 ./prep_dataset/ILSVRC2012_val_00036022.bin 224 224 +11859 ./prep_dataset/ILSVRC2012_val_00038339.bin 224 224 +11860 ./prep_dataset/ILSVRC2012_val_00000724.bin 224 224 +11861 ./prep_dataset/ILSVRC2012_val_00038931.bin 224 224 +11862 ./prep_dataset/ILSVRC2012_val_00016386.bin 224 224 +11863 ./prep_dataset/ILSVRC2012_val_00030433.bin 224 224 +11864 ./prep_dataset/ILSVRC2012_val_00036405.bin 224 224 +11865 ./prep_dataset/ILSVRC2012_val_00010551.bin 224 224 +11866 ./prep_dataset/ILSVRC2012_val_00000087.bin 224 224 +11867 ./prep_dataset/ILSVRC2012_val_00002948.bin 224 224 +11868 ./prep_dataset/ILSVRC2012_val_00022787.bin 224 224 +11869 ./prep_dataset/ILSVRC2012_val_00016962.bin 224 224 +11870 ./prep_dataset/ILSVRC2012_val_00049967.bin 224 224 +11871 ./prep_dataset/ILSVRC2012_val_00006168.bin 224 224 +11872 ./prep_dataset/ILSVRC2012_val_00047224.bin 224 224 +11873 ./prep_dataset/ILSVRC2012_val_00005013.bin 224 224 +11874 ./prep_dataset/ILSVRC2012_val_00015450.bin 224 224 +11875 ./prep_dataset/ILSVRC2012_val_00042496.bin 224 224 +11876 ./prep_dataset/ILSVRC2012_val_00046742.bin 224 224 +11877 ./prep_dataset/ILSVRC2012_val_00029632.bin 224 224 +11878 ./prep_dataset/ILSVRC2012_val_00015124.bin 224 224 +11879 ./prep_dataset/ILSVRC2012_val_00026067.bin 224 224 +11880 ./prep_dataset/ILSVRC2012_val_00029438.bin 224 224 +11881 ./prep_dataset/ILSVRC2012_val_00031713.bin 224 224 +11882 ./prep_dataset/ILSVRC2012_val_00009036.bin 224 224 +11883 ./prep_dataset/ILSVRC2012_val_00016383.bin 224 224 +11884 ./prep_dataset/ILSVRC2012_val_00031487.bin 224 224 +11885 ./prep_dataset/ILSVRC2012_val_00032519.bin 224 224 +11886 ./prep_dataset/ILSVRC2012_val_00022292.bin 224 224 +11887 ./prep_dataset/ILSVRC2012_val_00025907.bin 224 224 +11888 ./prep_dataset/ILSVRC2012_val_00034189.bin 224 224 +11889 ./prep_dataset/ILSVRC2012_val_00045104.bin 224 224 +11890 ./prep_dataset/ILSVRC2012_val_00023470.bin 224 224 +11891 ./prep_dataset/ILSVRC2012_val_00000839.bin 224 224 +11892 ./prep_dataset/ILSVRC2012_val_00033367.bin 224 224 +11893 ./prep_dataset/ILSVRC2012_val_00006497.bin 224 224 +11894 ./prep_dataset/ILSVRC2012_val_00025874.bin 224 224 +11895 ./prep_dataset/ILSVRC2012_val_00004005.bin 224 224 +11896 ./prep_dataset/ILSVRC2012_val_00020615.bin 224 224 +11897 ./prep_dataset/ILSVRC2012_val_00023554.bin 224 224 +11898 ./prep_dataset/ILSVRC2012_val_00012916.bin 224 224 +11899 ./prep_dataset/ILSVRC2012_val_00040602.bin 224 224 +11900 ./prep_dataset/ILSVRC2012_val_00037240.bin 224 224 +11901 ./prep_dataset/ILSVRC2012_val_00020376.bin 224 224 +11902 ./prep_dataset/ILSVRC2012_val_00033184.bin 224 224 +11903 ./prep_dataset/ILSVRC2012_val_00006238.bin 224 224 +11904 ./prep_dataset/ILSVRC2012_val_00000075.bin 224 224 +11905 ./prep_dataset/ILSVRC2012_val_00019271.bin 224 224 +11906 ./prep_dataset/ILSVRC2012_val_00003843.bin 224 224 +11907 ./prep_dataset/ILSVRC2012_val_00032975.bin 224 224 +11908 ./prep_dataset/ILSVRC2012_val_00010342.bin 224 224 +11909 ./prep_dataset/ILSVRC2012_val_00001550.bin 224 224 +11910 ./prep_dataset/ILSVRC2012_val_00019044.bin 224 224 +11911 ./prep_dataset/ILSVRC2012_val_00000762.bin 224 224 +11912 ./prep_dataset/ILSVRC2012_val_00022062.bin 224 224 +11913 ./prep_dataset/ILSVRC2012_val_00003677.bin 224 224 +11914 ./prep_dataset/ILSVRC2012_val_00017848.bin 224 224 +11915 ./prep_dataset/ILSVRC2012_val_00023414.bin 224 224 +11916 ./prep_dataset/ILSVRC2012_val_00041056.bin 224 224 +11917 ./prep_dataset/ILSVRC2012_val_00027472.bin 224 224 +11918 ./prep_dataset/ILSVRC2012_val_00001909.bin 224 224 +11919 ./prep_dataset/ILSVRC2012_val_00009213.bin 224 224 +11920 ./prep_dataset/ILSVRC2012_val_00044463.bin 224 224 +11921 ./prep_dataset/ILSVRC2012_val_00006959.bin 224 224 +11922 ./prep_dataset/ILSVRC2012_val_00048744.bin 224 224 +11923 ./prep_dataset/ILSVRC2012_val_00020233.bin 224 224 +11924 ./prep_dataset/ILSVRC2012_val_00043239.bin 224 224 +11925 ./prep_dataset/ILSVRC2012_val_00046116.bin 224 224 +11926 ./prep_dataset/ILSVRC2012_val_00047985.bin 224 224 +11927 ./prep_dataset/ILSVRC2012_val_00034031.bin 224 224 +11928 ./prep_dataset/ILSVRC2012_val_00015508.bin 224 224 +11929 ./prep_dataset/ILSVRC2012_val_00039805.bin 224 224 +11930 ./prep_dataset/ILSVRC2012_val_00003667.bin 224 224 +11931 ./prep_dataset/ILSVRC2012_val_00024916.bin 224 224 +11932 ./prep_dataset/ILSVRC2012_val_00042425.bin 224 224 +11933 ./prep_dataset/ILSVRC2012_val_00010510.bin 224 224 +11934 ./prep_dataset/ILSVRC2012_val_00037023.bin 224 224 +11935 ./prep_dataset/ILSVRC2012_val_00019491.bin 224 224 +11936 ./prep_dataset/ILSVRC2012_val_00005056.bin 224 224 +11937 ./prep_dataset/ILSVRC2012_val_00020687.bin 224 224 +11938 ./prep_dataset/ILSVRC2012_val_00014110.bin 224 224 +11939 ./prep_dataset/ILSVRC2012_val_00027125.bin 224 224 +11940 ./prep_dataset/ILSVRC2012_val_00020091.bin 224 224 +11941 ./prep_dataset/ILSVRC2012_val_00019421.bin 224 224 +11942 ./prep_dataset/ILSVRC2012_val_00047214.bin 224 224 +11943 ./prep_dataset/ILSVRC2012_val_00048025.bin 224 224 +11944 ./prep_dataset/ILSVRC2012_val_00024247.bin 224 224 +11945 ./prep_dataset/ILSVRC2012_val_00041860.bin 224 224 +11946 ./prep_dataset/ILSVRC2012_val_00027975.bin 224 224 +11947 ./prep_dataset/ILSVRC2012_val_00038014.bin 224 224 +11948 ./prep_dataset/ILSVRC2012_val_00039519.bin 224 224 +11949 ./prep_dataset/ILSVRC2012_val_00007033.bin 224 224 +11950 ./prep_dataset/ILSVRC2012_val_00029265.bin 224 224 +11951 ./prep_dataset/ILSVRC2012_val_00043818.bin 224 224 +11952 ./prep_dataset/ILSVRC2012_val_00006927.bin 224 224 +11953 ./prep_dataset/ILSVRC2012_val_00009366.bin 224 224 +11954 ./prep_dataset/ILSVRC2012_val_00030447.bin 224 224 +11955 ./prep_dataset/ILSVRC2012_val_00016241.bin 224 224 +11956 ./prep_dataset/ILSVRC2012_val_00002867.bin 224 224 +11957 ./prep_dataset/ILSVRC2012_val_00039626.bin 224 224 +11958 ./prep_dataset/ILSVRC2012_val_00028392.bin 224 224 +11959 ./prep_dataset/ILSVRC2012_val_00007662.bin 224 224 +11960 ./prep_dataset/ILSVRC2012_val_00023042.bin 224 224 +11961 ./prep_dataset/ILSVRC2012_val_00022807.bin 224 224 +11962 ./prep_dataset/ILSVRC2012_val_00027860.bin 224 224 +11963 ./prep_dataset/ILSVRC2012_val_00014447.bin 224 224 +11964 ./prep_dataset/ILSVRC2012_val_00019498.bin 224 224 +11965 ./prep_dataset/ILSVRC2012_val_00028714.bin 224 224 +11966 ./prep_dataset/ILSVRC2012_val_00004812.bin 224 224 +11967 ./prep_dataset/ILSVRC2012_val_00029311.bin 224 224 +11968 ./prep_dataset/ILSVRC2012_val_00028089.bin 224 224 +11969 ./prep_dataset/ILSVRC2012_val_00003045.bin 224 224 +11970 ./prep_dataset/ILSVRC2012_val_00029492.bin 224 224 +11971 ./prep_dataset/ILSVRC2012_val_00045609.bin 224 224 +11972 ./prep_dataset/ILSVRC2012_val_00015824.bin 224 224 +11973 ./prep_dataset/ILSVRC2012_val_00045535.bin 224 224 +11974 ./prep_dataset/ILSVRC2012_val_00026134.bin 224 224 +11975 ./prep_dataset/ILSVRC2012_val_00043612.bin 224 224 +11976 ./prep_dataset/ILSVRC2012_val_00032010.bin 224 224 +11977 ./prep_dataset/ILSVRC2012_val_00028023.bin 224 224 +11978 ./prep_dataset/ILSVRC2012_val_00018368.bin 224 224 +11979 ./prep_dataset/ILSVRC2012_val_00043644.bin 224 224 +11980 ./prep_dataset/ILSVRC2012_val_00007545.bin 224 224 +11981 ./prep_dataset/ILSVRC2012_val_00035383.bin 224 224 +11982 ./prep_dataset/ILSVRC2012_val_00029451.bin 224 224 +11983 ./prep_dataset/ILSVRC2012_val_00033635.bin 224 224 +11984 ./prep_dataset/ILSVRC2012_val_00005688.bin 224 224 +11985 ./prep_dataset/ILSVRC2012_val_00033171.bin 224 224 +11986 ./prep_dataset/ILSVRC2012_val_00004081.bin 224 224 +11987 ./prep_dataset/ILSVRC2012_val_00045593.bin 224 224 +11988 ./prep_dataset/ILSVRC2012_val_00001255.bin 224 224 +11989 ./prep_dataset/ILSVRC2012_val_00007606.bin 224 224 +11990 ./prep_dataset/ILSVRC2012_val_00008303.bin 224 224 +11991 ./prep_dataset/ILSVRC2012_val_00037539.bin 224 224 +11992 ./prep_dataset/ILSVRC2012_val_00011604.bin 224 224 +11993 ./prep_dataset/ILSVRC2012_val_00020867.bin 224 224 +11994 ./prep_dataset/ILSVRC2012_val_00039554.bin 224 224 +11995 ./prep_dataset/ILSVRC2012_val_00024446.bin 224 224 +11996 ./prep_dataset/ILSVRC2012_val_00035508.bin 224 224 +11997 ./prep_dataset/ILSVRC2012_val_00018303.bin 224 224 +11998 ./prep_dataset/ILSVRC2012_val_00042674.bin 224 224 +11999 ./prep_dataset/ILSVRC2012_val_00016485.bin 224 224 +12000 ./prep_dataset/ILSVRC2012_val_00008052.bin 224 224 +12001 ./prep_dataset/ILSVRC2012_val_00032554.bin 224 224 +12002 ./prep_dataset/ILSVRC2012_val_00030864.bin 224 224 +12003 ./prep_dataset/ILSVRC2012_val_00003331.bin 224 224 +12004 ./prep_dataset/ILSVRC2012_val_00029126.bin 224 224 +12005 ./prep_dataset/ILSVRC2012_val_00025675.bin 224 224 +12006 ./prep_dataset/ILSVRC2012_val_00031069.bin 224 224 +12007 ./prep_dataset/ILSVRC2012_val_00046044.bin 224 224 +12008 ./prep_dataset/ILSVRC2012_val_00033226.bin 224 224 +12009 ./prep_dataset/ILSVRC2012_val_00011035.bin 224 224 +12010 ./prep_dataset/ILSVRC2012_val_00023393.bin 224 224 +12011 ./prep_dataset/ILSVRC2012_val_00018120.bin 224 224 +12012 ./prep_dataset/ILSVRC2012_val_00030087.bin 224 224 +12013 ./prep_dataset/ILSVRC2012_val_00039279.bin 224 224 +12014 ./prep_dataset/ILSVRC2012_val_00038675.bin 224 224 +12015 ./prep_dataset/ILSVRC2012_val_00025851.bin 224 224 +12016 ./prep_dataset/ILSVRC2012_val_00030756.bin 224 224 +12017 ./prep_dataset/ILSVRC2012_val_00035631.bin 224 224 +12018 ./prep_dataset/ILSVRC2012_val_00001248.bin 224 224 +12019 ./prep_dataset/ILSVRC2012_val_00020033.bin 224 224 +12020 ./prep_dataset/ILSVRC2012_val_00004302.bin 224 224 +12021 ./prep_dataset/ILSVRC2012_val_00001754.bin 224 224 +12022 ./prep_dataset/ILSVRC2012_val_00012860.bin 224 224 +12023 ./prep_dataset/ILSVRC2012_val_00041651.bin 224 224 +12024 ./prep_dataset/ILSVRC2012_val_00036081.bin 224 224 +12025 ./prep_dataset/ILSVRC2012_val_00009284.bin 224 224 +12026 ./prep_dataset/ILSVRC2012_val_00040822.bin 224 224 +12027 ./prep_dataset/ILSVRC2012_val_00035269.bin 224 224 +12028 ./prep_dataset/ILSVRC2012_val_00029234.bin 224 224 +12029 ./prep_dataset/ILSVRC2012_val_00017001.bin 224 224 +12030 ./prep_dataset/ILSVRC2012_val_00029836.bin 224 224 +12031 ./prep_dataset/ILSVRC2012_val_00048249.bin 224 224 +12032 ./prep_dataset/ILSVRC2012_val_00009746.bin 224 224 +12033 ./prep_dataset/ILSVRC2012_val_00004303.bin 224 224 +12034 ./prep_dataset/ILSVRC2012_val_00040100.bin 224 224 +12035 ./prep_dataset/ILSVRC2012_val_00036109.bin 224 224 +12036 ./prep_dataset/ILSVRC2012_val_00003875.bin 224 224 +12037 ./prep_dataset/ILSVRC2012_val_00023751.bin 224 224 +12038 ./prep_dataset/ILSVRC2012_val_00026038.bin 224 224 +12039 ./prep_dataset/ILSVRC2012_val_00042828.bin 224 224 +12040 ./prep_dataset/ILSVRC2012_val_00006596.bin 224 224 +12041 ./prep_dataset/ILSVRC2012_val_00005799.bin 224 224 +12042 ./prep_dataset/ILSVRC2012_val_00049364.bin 224 224 +12043 ./prep_dataset/ILSVRC2012_val_00031996.bin 224 224 +12044 ./prep_dataset/ILSVRC2012_val_00034135.bin 224 224 +12045 ./prep_dataset/ILSVRC2012_val_00003370.bin 224 224 +12046 ./prep_dataset/ILSVRC2012_val_00018607.bin 224 224 +12047 ./prep_dataset/ILSVRC2012_val_00011089.bin 224 224 +12048 ./prep_dataset/ILSVRC2012_val_00003069.bin 224 224 +12049 ./prep_dataset/ILSVRC2012_val_00010521.bin 224 224 +12050 ./prep_dataset/ILSVRC2012_val_00019487.bin 224 224 +12051 ./prep_dataset/ILSVRC2012_val_00027324.bin 224 224 +12052 ./prep_dataset/ILSVRC2012_val_00017763.bin 224 224 +12053 ./prep_dataset/ILSVRC2012_val_00020370.bin 224 224 +12054 ./prep_dataset/ILSVRC2012_val_00020438.bin 224 224 +12055 ./prep_dataset/ILSVRC2012_val_00005709.bin 224 224 +12056 ./prep_dataset/ILSVRC2012_val_00039911.bin 224 224 +12057 ./prep_dataset/ILSVRC2012_val_00036779.bin 224 224 +12058 ./prep_dataset/ILSVRC2012_val_00043483.bin 224 224 +12059 ./prep_dataset/ILSVRC2012_val_00026116.bin 224 224 +12060 ./prep_dataset/ILSVRC2012_val_00035796.bin 224 224 +12061 ./prep_dataset/ILSVRC2012_val_00000632.bin 224 224 +12062 ./prep_dataset/ILSVRC2012_val_00017574.bin 224 224 +12063 ./prep_dataset/ILSVRC2012_val_00047458.bin 224 224 +12064 ./prep_dataset/ILSVRC2012_val_00033081.bin 224 224 +12065 ./prep_dataset/ILSVRC2012_val_00036099.bin 224 224 +12066 ./prep_dataset/ILSVRC2012_val_00024729.bin 224 224 +12067 ./prep_dataset/ILSVRC2012_val_00019725.bin 224 224 +12068 ./prep_dataset/ILSVRC2012_val_00014637.bin 224 224 +12069 ./prep_dataset/ILSVRC2012_val_00039341.bin 224 224 +12070 ./prep_dataset/ILSVRC2012_val_00033957.bin 224 224 +12071 ./prep_dataset/ILSVRC2012_val_00041667.bin 224 224 +12072 ./prep_dataset/ILSVRC2012_val_00035466.bin 224 224 +12073 ./prep_dataset/ILSVRC2012_val_00025949.bin 224 224 +12074 ./prep_dataset/ILSVRC2012_val_00014482.bin 224 224 +12075 ./prep_dataset/ILSVRC2012_val_00022789.bin 224 224 +12076 ./prep_dataset/ILSVRC2012_val_00001512.bin 224 224 +12077 ./prep_dataset/ILSVRC2012_val_00033267.bin 224 224 +12078 ./prep_dataset/ILSVRC2012_val_00011959.bin 224 224 +12079 ./prep_dataset/ILSVRC2012_val_00047782.bin 224 224 +12080 ./prep_dataset/ILSVRC2012_val_00045022.bin 224 224 +12081 ./prep_dataset/ILSVRC2012_val_00014775.bin 224 224 +12082 ./prep_dataset/ILSVRC2012_val_00004249.bin 224 224 +12083 ./prep_dataset/ILSVRC2012_val_00036907.bin 224 224 +12084 ./prep_dataset/ILSVRC2012_val_00046972.bin 224 224 +12085 ./prep_dataset/ILSVRC2012_val_00021666.bin 224 224 +12086 ./prep_dataset/ILSVRC2012_val_00028499.bin 224 224 +12087 ./prep_dataset/ILSVRC2012_val_00019265.bin 224 224 +12088 ./prep_dataset/ILSVRC2012_val_00039889.bin 224 224 +12089 ./prep_dataset/ILSVRC2012_val_00029683.bin 224 224 +12090 ./prep_dataset/ILSVRC2012_val_00031493.bin 224 224 +12091 ./prep_dataset/ILSVRC2012_val_00025049.bin 224 224 +12092 ./prep_dataset/ILSVRC2012_val_00013053.bin 224 224 +12093 ./prep_dataset/ILSVRC2012_val_00002246.bin 224 224 +12094 ./prep_dataset/ILSVRC2012_val_00041457.bin 224 224 +12095 ./prep_dataset/ILSVRC2012_val_00036500.bin 224 224 +12096 ./prep_dataset/ILSVRC2012_val_00017900.bin 224 224 +12097 ./prep_dataset/ILSVRC2012_val_00002293.bin 224 224 +12098 ./prep_dataset/ILSVRC2012_val_00023761.bin 224 224 +12099 ./prep_dataset/ILSVRC2012_val_00015047.bin 224 224 +12100 ./prep_dataset/ILSVRC2012_val_00015499.bin 224 224 +12101 ./prep_dataset/ILSVRC2012_val_00029803.bin 224 224 +12102 ./prep_dataset/ILSVRC2012_val_00005662.bin 224 224 +12103 ./prep_dataset/ILSVRC2012_val_00002168.bin 224 224 +12104 ./prep_dataset/ILSVRC2012_val_00034241.bin 224 224 +12105 ./prep_dataset/ILSVRC2012_val_00023756.bin 224 224 +12106 ./prep_dataset/ILSVRC2012_val_00049208.bin 224 224 +12107 ./prep_dataset/ILSVRC2012_val_00012970.bin 224 224 +12108 ./prep_dataset/ILSVRC2012_val_00033958.bin 224 224 +12109 ./prep_dataset/ILSVRC2012_val_00036629.bin 224 224 +12110 ./prep_dataset/ILSVRC2012_val_00015469.bin 224 224 +12111 ./prep_dataset/ILSVRC2012_val_00044798.bin 224 224 +12112 ./prep_dataset/ILSVRC2012_val_00012851.bin 224 224 +12113 ./prep_dataset/ILSVRC2012_val_00034733.bin 224 224 +12114 ./prep_dataset/ILSVRC2012_val_00038705.bin 224 224 +12115 ./prep_dataset/ILSVRC2012_val_00021931.bin 224 224 +12116 ./prep_dataset/ILSVRC2012_val_00006793.bin 224 224 +12117 ./prep_dataset/ILSVRC2012_val_00022507.bin 224 224 +12118 ./prep_dataset/ILSVRC2012_val_00011296.bin 224 224 +12119 ./prep_dataset/ILSVRC2012_val_00045645.bin 224 224 +12120 ./prep_dataset/ILSVRC2012_val_00036978.bin 224 224 +12121 ./prep_dataset/ILSVRC2012_val_00045759.bin 224 224 +12122 ./prep_dataset/ILSVRC2012_val_00014902.bin 224 224 +12123 ./prep_dataset/ILSVRC2012_val_00046526.bin 224 224 +12124 ./prep_dataset/ILSVRC2012_val_00021218.bin 224 224 +12125 ./prep_dataset/ILSVRC2012_val_00038746.bin 224 224 +12126 ./prep_dataset/ILSVRC2012_val_00023259.bin 224 224 +12127 ./prep_dataset/ILSVRC2012_val_00048039.bin 224 224 +12128 ./prep_dataset/ILSVRC2012_val_00034208.bin 224 224 +12129 ./prep_dataset/ILSVRC2012_val_00007187.bin 224 224 +12130 ./prep_dataset/ILSVRC2012_val_00003852.bin 224 224 +12131 ./prep_dataset/ILSVRC2012_val_00039539.bin 224 224 +12132 ./prep_dataset/ILSVRC2012_val_00041519.bin 224 224 +12133 ./prep_dataset/ILSVRC2012_val_00021690.bin 224 224 +12134 ./prep_dataset/ILSVRC2012_val_00013931.bin 224 224 +12135 ./prep_dataset/ILSVRC2012_val_00002162.bin 224 224 +12136 ./prep_dataset/ILSVRC2012_val_00016436.bin 224 224 +12137 ./prep_dataset/ILSVRC2012_val_00029832.bin 224 224 +12138 ./prep_dataset/ILSVRC2012_val_00024123.bin 224 224 +12139 ./prep_dataset/ILSVRC2012_val_00009849.bin 224 224 +12140 ./prep_dataset/ILSVRC2012_val_00006425.bin 224 224 +12141 ./prep_dataset/ILSVRC2012_val_00040875.bin 224 224 +12142 ./prep_dataset/ILSVRC2012_val_00034924.bin 224 224 +12143 ./prep_dataset/ILSVRC2012_val_00026927.bin 224 224 +12144 ./prep_dataset/ILSVRC2012_val_00038975.bin 224 224 +12145 ./prep_dataset/ILSVRC2012_val_00029886.bin 224 224 +12146 ./prep_dataset/ILSVRC2012_val_00000300.bin 224 224 +12147 ./prep_dataset/ILSVRC2012_val_00012643.bin 224 224 +12148 ./prep_dataset/ILSVRC2012_val_00023917.bin 224 224 +12149 ./prep_dataset/ILSVRC2012_val_00006540.bin 224 224 +12150 ./prep_dataset/ILSVRC2012_val_00047890.bin 224 224 +12151 ./prep_dataset/ILSVRC2012_val_00023220.bin 224 224 +12152 ./prep_dataset/ILSVRC2012_val_00035973.bin 224 224 +12153 ./prep_dataset/ILSVRC2012_val_00039479.bin 224 224 +12154 ./prep_dataset/ILSVRC2012_val_00037679.bin 224 224 +12155 ./prep_dataset/ILSVRC2012_val_00026123.bin 224 224 +12156 ./prep_dataset/ILSVRC2012_val_00038766.bin 224 224 +12157 ./prep_dataset/ILSVRC2012_val_00027006.bin 224 224 +12158 ./prep_dataset/ILSVRC2012_val_00005391.bin 224 224 +12159 ./prep_dataset/ILSVRC2012_val_00038004.bin 224 224 +12160 ./prep_dataset/ILSVRC2012_val_00044450.bin 224 224 +12161 ./prep_dataset/ILSVRC2012_val_00034490.bin 224 224 +12162 ./prep_dataset/ILSVRC2012_val_00011840.bin 224 224 +12163 ./prep_dataset/ILSVRC2012_val_00044714.bin 224 224 +12164 ./prep_dataset/ILSVRC2012_val_00048558.bin 224 224 +12165 ./prep_dataset/ILSVRC2012_val_00029662.bin 224 224 +12166 ./prep_dataset/ILSVRC2012_val_00039549.bin 224 224 +12167 ./prep_dataset/ILSVRC2012_val_00040225.bin 224 224 +12168 ./prep_dataset/ILSVRC2012_val_00036392.bin 224 224 +12169 ./prep_dataset/ILSVRC2012_val_00032845.bin 224 224 +12170 ./prep_dataset/ILSVRC2012_val_00029131.bin 224 224 +12171 ./prep_dataset/ILSVRC2012_val_00006131.bin 224 224 +12172 ./prep_dataset/ILSVRC2012_val_00008876.bin 224 224 +12173 ./prep_dataset/ILSVRC2012_val_00010703.bin 224 224 +12174 ./prep_dataset/ILSVRC2012_val_00012370.bin 224 224 +12175 ./prep_dataset/ILSVRC2012_val_00049540.bin 224 224 +12176 ./prep_dataset/ILSVRC2012_val_00029134.bin 224 224 +12177 ./prep_dataset/ILSVRC2012_val_00027595.bin 224 224 +12178 ./prep_dataset/ILSVRC2012_val_00028609.bin 224 224 +12179 ./prep_dataset/ILSVRC2012_val_00002981.bin 224 224 +12180 ./prep_dataset/ILSVRC2012_val_00032117.bin 224 224 +12181 ./prep_dataset/ILSVRC2012_val_00028563.bin 224 224 +12182 ./prep_dataset/ILSVRC2012_val_00030799.bin 224 224 +12183 ./prep_dataset/ILSVRC2012_val_00020286.bin 224 224 +12184 ./prep_dataset/ILSVRC2012_val_00030252.bin 224 224 +12185 ./prep_dataset/ILSVRC2012_val_00026722.bin 224 224 +12186 ./prep_dataset/ILSVRC2012_val_00021750.bin 224 224 +12187 ./prep_dataset/ILSVRC2012_val_00030699.bin 224 224 +12188 ./prep_dataset/ILSVRC2012_val_00013298.bin 224 224 +12189 ./prep_dataset/ILSVRC2012_val_00037755.bin 224 224 +12190 ./prep_dataset/ILSVRC2012_val_00015635.bin 224 224 +12191 ./prep_dataset/ILSVRC2012_val_00017869.bin 224 224 +12192 ./prep_dataset/ILSVRC2012_val_00005140.bin 224 224 +12193 ./prep_dataset/ILSVRC2012_val_00005175.bin 224 224 +12194 ./prep_dataset/ILSVRC2012_val_00008397.bin 224 224 +12195 ./prep_dataset/ILSVRC2012_val_00032461.bin 224 224 +12196 ./prep_dataset/ILSVRC2012_val_00003131.bin 224 224 +12197 ./prep_dataset/ILSVRC2012_val_00027395.bin 224 224 +12198 ./prep_dataset/ILSVRC2012_val_00046736.bin 224 224 +12199 ./prep_dataset/ILSVRC2012_val_00002946.bin 224 224 +12200 ./prep_dataset/ILSVRC2012_val_00012845.bin 224 224 +12201 ./prep_dataset/ILSVRC2012_val_00012810.bin 224 224 +12202 ./prep_dataset/ILSVRC2012_val_00007135.bin 224 224 +12203 ./prep_dataset/ILSVRC2012_val_00008162.bin 224 224 +12204 ./prep_dataset/ILSVRC2012_val_00028928.bin 224 224 +12205 ./prep_dataset/ILSVRC2012_val_00043576.bin 224 224 +12206 ./prep_dataset/ILSVRC2012_val_00018459.bin 224 224 +12207 ./prep_dataset/ILSVRC2012_val_00003462.bin 224 224 +12208 ./prep_dataset/ILSVRC2012_val_00023261.bin 224 224 +12209 ./prep_dataset/ILSVRC2012_val_00017458.bin 224 224 +12210 ./prep_dataset/ILSVRC2012_val_00002700.bin 224 224 +12211 ./prep_dataset/ILSVRC2012_val_00001252.bin 224 224 +12212 ./prep_dataset/ILSVRC2012_val_00023197.bin 224 224 +12213 ./prep_dataset/ILSVRC2012_val_00025011.bin 224 224 +12214 ./prep_dataset/ILSVRC2012_val_00022904.bin 224 224 +12215 ./prep_dataset/ILSVRC2012_val_00002026.bin 224 224 +12216 ./prep_dataset/ILSVRC2012_val_00023523.bin 224 224 +12217 ./prep_dataset/ILSVRC2012_val_00047515.bin 224 224 +12218 ./prep_dataset/ILSVRC2012_val_00013894.bin 224 224 +12219 ./prep_dataset/ILSVRC2012_val_00021626.bin 224 224 +12220 ./prep_dataset/ILSVRC2012_val_00018885.bin 224 224 +12221 ./prep_dataset/ILSVRC2012_val_00034865.bin 224 224 +12222 ./prep_dataset/ILSVRC2012_val_00001123.bin 224 224 +12223 ./prep_dataset/ILSVRC2012_val_00038789.bin 224 224 +12224 ./prep_dataset/ILSVRC2012_val_00001055.bin 224 224 +12225 ./prep_dataset/ILSVRC2012_val_00037173.bin 224 224 +12226 ./prep_dataset/ILSVRC2012_val_00040458.bin 224 224 +12227 ./prep_dataset/ILSVRC2012_val_00003862.bin 224 224 +12228 ./prep_dataset/ILSVRC2012_val_00024887.bin 224 224 +12229 ./prep_dataset/ILSVRC2012_val_00020408.bin 224 224 +12230 ./prep_dataset/ILSVRC2012_val_00017512.bin 224 224 +12231 ./prep_dataset/ILSVRC2012_val_00001858.bin 224 224 +12232 ./prep_dataset/ILSVRC2012_val_00021598.bin 224 224 +12233 ./prep_dataset/ILSVRC2012_val_00012196.bin 224 224 +12234 ./prep_dataset/ILSVRC2012_val_00047657.bin 224 224 +12235 ./prep_dataset/ILSVRC2012_val_00012714.bin 224 224 +12236 ./prep_dataset/ILSVRC2012_val_00049053.bin 224 224 +12237 ./prep_dataset/ILSVRC2012_val_00004314.bin 224 224 +12238 ./prep_dataset/ILSVRC2012_val_00030405.bin 224 224 +12239 ./prep_dataset/ILSVRC2012_val_00014050.bin 224 224 +12240 ./prep_dataset/ILSVRC2012_val_00005742.bin 224 224 +12241 ./prep_dataset/ILSVRC2012_val_00023287.bin 224 224 +12242 ./prep_dataset/ILSVRC2012_val_00000101.bin 224 224 +12243 ./prep_dataset/ILSVRC2012_val_00043434.bin 224 224 +12244 ./prep_dataset/ILSVRC2012_val_00044681.bin 224 224 +12245 ./prep_dataset/ILSVRC2012_val_00044109.bin 224 224 +12246 ./prep_dataset/ILSVRC2012_val_00044641.bin 224 224 +12247 ./prep_dataset/ILSVRC2012_val_00042061.bin 224 224 +12248 ./prep_dataset/ILSVRC2012_val_00005177.bin 224 224 +12249 ./prep_dataset/ILSVRC2012_val_00042175.bin 224 224 +12250 ./prep_dataset/ILSVRC2012_val_00047062.bin 224 224 +12251 ./prep_dataset/ILSVRC2012_val_00036534.bin 224 224 +12252 ./prep_dataset/ILSVRC2012_val_00000955.bin 224 224 +12253 ./prep_dataset/ILSVRC2012_val_00005609.bin 224 224 +12254 ./prep_dataset/ILSVRC2012_val_00037038.bin 224 224 +12255 ./prep_dataset/ILSVRC2012_val_00000678.bin 224 224 +12256 ./prep_dataset/ILSVRC2012_val_00016804.bin 224 224 +12257 ./prep_dataset/ILSVRC2012_val_00032839.bin 224 224 +12258 ./prep_dataset/ILSVRC2012_val_00038896.bin 224 224 +12259 ./prep_dataset/ILSVRC2012_val_00030206.bin 224 224 +12260 ./prep_dataset/ILSVRC2012_val_00047489.bin 224 224 +12261 ./prep_dataset/ILSVRC2012_val_00002568.bin 224 224 +12262 ./prep_dataset/ILSVRC2012_val_00041063.bin 224 224 +12263 ./prep_dataset/ILSVRC2012_val_00003039.bin 224 224 +12264 ./prep_dataset/ILSVRC2012_val_00043624.bin 224 224 +12265 ./prep_dataset/ILSVRC2012_val_00039121.bin 224 224 +12266 ./prep_dataset/ILSVRC2012_val_00018262.bin 224 224 +12267 ./prep_dataset/ILSVRC2012_val_00017534.bin 224 224 +12268 ./prep_dataset/ILSVRC2012_val_00002488.bin 224 224 +12269 ./prep_dataset/ILSVRC2012_val_00016838.bin 224 224 +12270 ./prep_dataset/ILSVRC2012_val_00007717.bin 224 224 +12271 ./prep_dataset/ILSVRC2012_val_00011208.bin 224 224 +12272 ./prep_dataset/ILSVRC2012_val_00020596.bin 224 224 +12273 ./prep_dataset/ILSVRC2012_val_00044756.bin 224 224 +12274 ./prep_dataset/ILSVRC2012_val_00024355.bin 224 224 +12275 ./prep_dataset/ILSVRC2012_val_00019011.bin 224 224 +12276 ./prep_dataset/ILSVRC2012_val_00032062.bin 224 224 +12277 ./prep_dataset/ILSVRC2012_val_00027373.bin 224 224 +12278 ./prep_dataset/ILSVRC2012_val_00013658.bin 224 224 +12279 ./prep_dataset/ILSVRC2012_val_00035106.bin 224 224 +12280 ./prep_dataset/ILSVRC2012_val_00033794.bin 224 224 +12281 ./prep_dataset/ILSVRC2012_val_00026102.bin 224 224 +12282 ./prep_dataset/ILSVRC2012_val_00010394.bin 224 224 +12283 ./prep_dataset/ILSVRC2012_val_00047419.bin 224 224 +12284 ./prep_dataset/ILSVRC2012_val_00048424.bin 224 224 +12285 ./prep_dataset/ILSVRC2012_val_00002973.bin 224 224 +12286 ./prep_dataset/ILSVRC2012_val_00047751.bin 224 224 +12287 ./prep_dataset/ILSVRC2012_val_00042886.bin 224 224 +12288 ./prep_dataset/ILSVRC2012_val_00027933.bin 224 224 +12289 ./prep_dataset/ILSVRC2012_val_00005828.bin 224 224 +12290 ./prep_dataset/ILSVRC2012_val_00014521.bin 224 224 +12291 ./prep_dataset/ILSVRC2012_val_00029861.bin 224 224 +12292 ./prep_dataset/ILSVRC2012_val_00035057.bin 224 224 +12293 ./prep_dataset/ILSVRC2012_val_00046271.bin 224 224 +12294 ./prep_dataset/ILSVRC2012_val_00018362.bin 224 224 +12295 ./prep_dataset/ILSVRC2012_val_00006973.bin 224 224 +12296 ./prep_dataset/ILSVRC2012_val_00040346.bin 224 224 +12297 ./prep_dataset/ILSVRC2012_val_00001988.bin 224 224 +12298 ./prep_dataset/ILSVRC2012_val_00018924.bin 224 224 +12299 ./prep_dataset/ILSVRC2012_val_00000478.bin 224 224 +12300 ./prep_dataset/ILSVRC2012_val_00006051.bin 224 224 +12301 ./prep_dataset/ILSVRC2012_val_00028680.bin 224 224 +12302 ./prep_dataset/ILSVRC2012_val_00003468.bin 224 224 +12303 ./prep_dataset/ILSVRC2012_val_00010040.bin 224 224 +12304 ./prep_dataset/ILSVRC2012_val_00037541.bin 224 224 +12305 ./prep_dataset/ILSVRC2012_val_00018491.bin 224 224 +12306 ./prep_dataset/ILSVRC2012_val_00043869.bin 224 224 +12307 ./prep_dataset/ILSVRC2012_val_00014984.bin 224 224 +12308 ./prep_dataset/ILSVRC2012_val_00022885.bin 224 224 +12309 ./prep_dataset/ILSVRC2012_val_00049283.bin 224 224 +12310 ./prep_dataset/ILSVRC2012_val_00033397.bin 224 224 +12311 ./prep_dataset/ILSVRC2012_val_00005936.bin 224 224 +12312 ./prep_dataset/ILSVRC2012_val_00034062.bin 224 224 +12313 ./prep_dataset/ILSVRC2012_val_00046909.bin 224 224 +12314 ./prep_dataset/ILSVRC2012_val_00033741.bin 224 224 +12315 ./prep_dataset/ILSVRC2012_val_00039518.bin 224 224 +12316 ./prep_dataset/ILSVRC2012_val_00016499.bin 224 224 +12317 ./prep_dataset/ILSVRC2012_val_00019174.bin 224 224 +12318 ./prep_dataset/ILSVRC2012_val_00028302.bin 224 224 +12319 ./prep_dataset/ILSVRC2012_val_00025634.bin 224 224 +12320 ./prep_dataset/ILSVRC2012_val_00049337.bin 224 224 +12321 ./prep_dataset/ILSVRC2012_val_00004588.bin 224 224 +12322 ./prep_dataset/ILSVRC2012_val_00040861.bin 224 224 +12323 ./prep_dataset/ILSVRC2012_val_00009493.bin 224 224 +12324 ./prep_dataset/ILSVRC2012_val_00003806.bin 224 224 +12325 ./prep_dataset/ILSVRC2012_val_00021392.bin 224 224 +12326 ./prep_dataset/ILSVRC2012_val_00031141.bin 224 224 +12327 ./prep_dataset/ILSVRC2012_val_00034192.bin 224 224 +12328 ./prep_dataset/ILSVRC2012_val_00005756.bin 224 224 +12329 ./prep_dataset/ILSVRC2012_val_00018865.bin 224 224 +12330 ./prep_dataset/ILSVRC2012_val_00014458.bin 224 224 +12331 ./prep_dataset/ILSVRC2012_val_00046359.bin 224 224 +12332 ./prep_dataset/ILSVRC2012_val_00049081.bin 224 224 +12333 ./prep_dataset/ILSVRC2012_val_00035377.bin 224 224 +12334 ./prep_dataset/ILSVRC2012_val_00049047.bin 224 224 +12335 ./prep_dataset/ILSVRC2012_val_00044114.bin 224 224 +12336 ./prep_dataset/ILSVRC2012_val_00028380.bin 224 224 +12337 ./prep_dataset/ILSVRC2012_val_00049315.bin 224 224 +12338 ./prep_dataset/ILSVRC2012_val_00030468.bin 224 224 +12339 ./prep_dataset/ILSVRC2012_val_00041402.bin 224 224 +12340 ./prep_dataset/ILSVRC2012_val_00029860.bin 224 224 +12341 ./prep_dataset/ILSVRC2012_val_00041659.bin 224 224 +12342 ./prep_dataset/ILSVRC2012_val_00001661.bin 224 224 +12343 ./prep_dataset/ILSVRC2012_val_00017079.bin 224 224 +12344 ./prep_dataset/ILSVRC2012_val_00044646.bin 224 224 +12345 ./prep_dataset/ILSVRC2012_val_00043600.bin 224 224 +12346 ./prep_dataset/ILSVRC2012_val_00001968.bin 224 224 +12347 ./prep_dataset/ILSVRC2012_val_00015455.bin 224 224 +12348 ./prep_dataset/ILSVRC2012_val_00048764.bin 224 224 +12349 ./prep_dataset/ILSVRC2012_val_00015698.bin 224 224 +12350 ./prep_dataset/ILSVRC2012_val_00046362.bin 224 224 +12351 ./prep_dataset/ILSVRC2012_val_00047983.bin 224 224 +12352 ./prep_dataset/ILSVRC2012_val_00036715.bin 224 224 +12353 ./prep_dataset/ILSVRC2012_val_00031498.bin 224 224 +12354 ./prep_dataset/ILSVRC2012_val_00046559.bin 224 224 +12355 ./prep_dataset/ILSVRC2012_val_00018858.bin 224 224 +12356 ./prep_dataset/ILSVRC2012_val_00006121.bin 224 224 +12357 ./prep_dataset/ILSVRC2012_val_00029742.bin 224 224 +12358 ./prep_dataset/ILSVRC2012_val_00000740.bin 224 224 +12359 ./prep_dataset/ILSVRC2012_val_00043760.bin 224 224 +12360 ./prep_dataset/ILSVRC2012_val_00035493.bin 224 224 +12361 ./prep_dataset/ILSVRC2012_val_00020367.bin 224 224 +12362 ./prep_dataset/ILSVRC2012_val_00012826.bin 224 224 +12363 ./prep_dataset/ILSVRC2012_val_00009239.bin 224 224 +12364 ./prep_dataset/ILSVRC2012_val_00026644.bin 224 224 +12365 ./prep_dataset/ILSVRC2012_val_00035683.bin 224 224 +12366 ./prep_dataset/ILSVRC2012_val_00022850.bin 224 224 +12367 ./prep_dataset/ILSVRC2012_val_00048415.bin 224 224 +12368 ./prep_dataset/ILSVRC2012_val_00026726.bin 224 224 +12369 ./prep_dataset/ILSVRC2012_val_00007888.bin 224 224 +12370 ./prep_dataset/ILSVRC2012_val_00017597.bin 224 224 +12371 ./prep_dataset/ILSVRC2012_val_00016130.bin 224 224 +12372 ./prep_dataset/ILSVRC2012_val_00045130.bin 224 224 +12373 ./prep_dataset/ILSVRC2012_val_00036478.bin 224 224 +12374 ./prep_dataset/ILSVRC2012_val_00033739.bin 224 224 +12375 ./prep_dataset/ILSVRC2012_val_00012883.bin 224 224 +12376 ./prep_dataset/ILSVRC2012_val_00019429.bin 224 224 +12377 ./prep_dataset/ILSVRC2012_val_00029688.bin 224 224 +12378 ./prep_dataset/ILSVRC2012_val_00020425.bin 224 224 +12379 ./prep_dataset/ILSVRC2012_val_00046619.bin 224 224 +12380 ./prep_dataset/ILSVRC2012_val_00009289.bin 224 224 +12381 ./prep_dataset/ILSVRC2012_val_00038235.bin 224 224 +12382 ./prep_dataset/ILSVRC2012_val_00008651.bin 224 224 +12383 ./prep_dataset/ILSVRC2012_val_00013278.bin 224 224 +12384 ./prep_dataset/ILSVRC2012_val_00043852.bin 224 224 +12385 ./prep_dataset/ILSVRC2012_val_00008023.bin 224 224 +12386 ./prep_dataset/ILSVRC2012_val_00029293.bin 224 224 +12387 ./prep_dataset/ILSVRC2012_val_00047817.bin 224 224 +12388 ./prep_dataset/ILSVRC2012_val_00016258.bin 224 224 +12389 ./prep_dataset/ILSVRC2012_val_00049992.bin 224 224 +12390 ./prep_dataset/ILSVRC2012_val_00015945.bin 224 224 +12391 ./prep_dataset/ILSVRC2012_val_00033979.bin 224 224 +12392 ./prep_dataset/ILSVRC2012_val_00048517.bin 224 224 +12393 ./prep_dataset/ILSVRC2012_val_00030832.bin 224 224 +12394 ./prep_dataset/ILSVRC2012_val_00017872.bin 224 224 +12395 ./prep_dataset/ILSVRC2012_val_00034645.bin 224 224 +12396 ./prep_dataset/ILSVRC2012_val_00005273.bin 224 224 +12397 ./prep_dataset/ILSVRC2012_val_00016219.bin 224 224 +12398 ./prep_dataset/ILSVRC2012_val_00018677.bin 224 224 +12399 ./prep_dataset/ILSVRC2012_val_00018504.bin 224 224 +12400 ./prep_dataset/ILSVRC2012_val_00030082.bin 224 224 +12401 ./prep_dataset/ILSVRC2012_val_00025186.bin 224 224 +12402 ./prep_dataset/ILSVRC2012_val_00007781.bin 224 224 +12403 ./prep_dataset/ILSVRC2012_val_00012155.bin 224 224 +12404 ./prep_dataset/ILSVRC2012_val_00021332.bin 224 224 +12405 ./prep_dataset/ILSVRC2012_val_00011129.bin 224 224 +12406 ./prep_dataset/ILSVRC2012_val_00020237.bin 224 224 +12407 ./prep_dataset/ILSVRC2012_val_00034910.bin 224 224 +12408 ./prep_dataset/ILSVRC2012_val_00003202.bin 224 224 +12409 ./prep_dataset/ILSVRC2012_val_00000405.bin 224 224 +12410 ./prep_dataset/ILSVRC2012_val_00043680.bin 224 224 +12411 ./prep_dataset/ILSVRC2012_val_00044832.bin 224 224 +12412 ./prep_dataset/ILSVRC2012_val_00014499.bin 224 224 +12413 ./prep_dataset/ILSVRC2012_val_00023610.bin 224 224 +12414 ./prep_dataset/ILSVRC2012_val_00042970.bin 224 224 +12415 ./prep_dataset/ILSVRC2012_val_00018582.bin 224 224 +12416 ./prep_dataset/ILSVRC2012_val_00019401.bin 224 224 +12417 ./prep_dataset/ILSVRC2012_val_00012279.bin 224 224 +12418 ./prep_dataset/ILSVRC2012_val_00045234.bin 224 224 +12419 ./prep_dataset/ILSVRC2012_val_00013908.bin 224 224 +12420 ./prep_dataset/ILSVRC2012_val_00037553.bin 224 224 +12421 ./prep_dataset/ILSVRC2012_val_00022969.bin 224 224 +12422 ./prep_dataset/ILSVRC2012_val_00048906.bin 224 224 +12423 ./prep_dataset/ILSVRC2012_val_00027872.bin 224 224 +12424 ./prep_dataset/ILSVRC2012_val_00035799.bin 224 224 +12425 ./prep_dataset/ILSVRC2012_val_00034482.bin 224 224 +12426 ./prep_dataset/ILSVRC2012_val_00026639.bin 224 224 +12427 ./prep_dataset/ILSVRC2012_val_00022159.bin 224 224 +12428 ./prep_dataset/ILSVRC2012_val_00046451.bin 224 224 +12429 ./prep_dataset/ILSVRC2012_val_00026153.bin 224 224 +12430 ./prep_dataset/ILSVRC2012_val_00003580.bin 224 224 +12431 ./prep_dataset/ILSVRC2012_val_00001472.bin 224 224 +12432 ./prep_dataset/ILSVRC2012_val_00000584.bin 224 224 +12433 ./prep_dataset/ILSVRC2012_val_00006988.bin 224 224 +12434 ./prep_dataset/ILSVRC2012_val_00044080.bin 224 224 +12435 ./prep_dataset/ILSVRC2012_val_00026019.bin 224 224 +12436 ./prep_dataset/ILSVRC2012_val_00035808.bin 224 224 +12437 ./prep_dataset/ILSVRC2012_val_00013635.bin 224 224 +12438 ./prep_dataset/ILSVRC2012_val_00037495.bin 224 224 +12439 ./prep_dataset/ILSVRC2012_val_00026424.bin 224 224 +12440 ./prep_dataset/ILSVRC2012_val_00038685.bin 224 224 +12441 ./prep_dataset/ILSVRC2012_val_00015909.bin 224 224 +12442 ./prep_dataset/ILSVRC2012_val_00041172.bin 224 224 +12443 ./prep_dataset/ILSVRC2012_val_00041661.bin 224 224 +12444 ./prep_dataset/ILSVRC2012_val_00042025.bin 224 224 +12445 ./prep_dataset/ILSVRC2012_val_00004470.bin 224 224 +12446 ./prep_dataset/ILSVRC2012_val_00019081.bin 224 224 +12447 ./prep_dataset/ILSVRC2012_val_00033388.bin 224 224 +12448 ./prep_dataset/ILSVRC2012_val_00025751.bin 224 224 +12449 ./prep_dataset/ILSVRC2012_val_00030254.bin 224 224 +12450 ./prep_dataset/ILSVRC2012_val_00025288.bin 224 224 +12451 ./prep_dataset/ILSVRC2012_val_00041787.bin 224 224 +12452 ./prep_dataset/ILSVRC2012_val_00010160.bin 224 224 +12453 ./prep_dataset/ILSVRC2012_val_00014343.bin 224 224 +12454 ./prep_dataset/ILSVRC2012_val_00012646.bin 224 224 +12455 ./prep_dataset/ILSVRC2012_val_00041139.bin 224 224 +12456 ./prep_dataset/ILSVRC2012_val_00022740.bin 224 224 +12457 ./prep_dataset/ILSVRC2012_val_00022856.bin 224 224 +12458 ./prep_dataset/ILSVRC2012_val_00041521.bin 224 224 +12459 ./prep_dataset/ILSVRC2012_val_00009023.bin 224 224 +12460 ./prep_dataset/ILSVRC2012_val_00013719.bin 224 224 +12461 ./prep_dataset/ILSVRC2012_val_00018766.bin 224 224 +12462 ./prep_dataset/ILSVRC2012_val_00002339.bin 224 224 +12463 ./prep_dataset/ILSVRC2012_val_00006779.bin 224 224 +12464 ./prep_dataset/ILSVRC2012_val_00016762.bin 224 224 +12465 ./prep_dataset/ILSVRC2012_val_00006900.bin 224 224 +12466 ./prep_dataset/ILSVRC2012_val_00019045.bin 224 224 +12467 ./prep_dataset/ILSVRC2012_val_00032624.bin 224 224 +12468 ./prep_dataset/ILSVRC2012_val_00020725.bin 224 224 +12469 ./prep_dataset/ILSVRC2012_val_00046491.bin 224 224 +12470 ./prep_dataset/ILSVRC2012_val_00004013.bin 224 224 +12471 ./prep_dataset/ILSVRC2012_val_00047594.bin 224 224 +12472 ./prep_dataset/ILSVRC2012_val_00022778.bin 224 224 +12473 ./prep_dataset/ILSVRC2012_val_00033738.bin 224 224 +12474 ./prep_dataset/ILSVRC2012_val_00019549.bin 224 224 +12475 ./prep_dataset/ILSVRC2012_val_00016084.bin 224 224 +12476 ./prep_dataset/ILSVRC2012_val_00019281.bin 224 224 +12477 ./prep_dataset/ILSVRC2012_val_00024908.bin 224 224 +12478 ./prep_dataset/ILSVRC2012_val_00049915.bin 224 224 +12479 ./prep_dataset/ILSVRC2012_val_00003782.bin 224 224 +12480 ./prep_dataset/ILSVRC2012_val_00040981.bin 224 224 +12481 ./prep_dataset/ILSVRC2012_val_00002760.bin 224 224 +12482 ./prep_dataset/ILSVRC2012_val_00002298.bin 224 224 +12483 ./prep_dataset/ILSVRC2012_val_00013345.bin 224 224 +12484 ./prep_dataset/ILSVRC2012_val_00008353.bin 224 224 +12485 ./prep_dataset/ILSVRC2012_val_00013034.bin 224 224 +12486 ./prep_dataset/ILSVRC2012_val_00022757.bin 224 224 +12487 ./prep_dataset/ILSVRC2012_val_00035505.bin 224 224 +12488 ./prep_dataset/ILSVRC2012_val_00018608.bin 224 224 +12489 ./prep_dataset/ILSVRC2012_val_00046342.bin 224 224 +12490 ./prep_dataset/ILSVRC2012_val_00008607.bin 224 224 +12491 ./prep_dataset/ILSVRC2012_val_00037956.bin 224 224 +12492 ./prep_dataset/ILSVRC2012_val_00035572.bin 224 224 +12493 ./prep_dataset/ILSVRC2012_val_00029898.bin 224 224 +12494 ./prep_dataset/ILSVRC2012_val_00026688.bin 224 224 +12495 ./prep_dataset/ILSVRC2012_val_00029277.bin 224 224 +12496 ./prep_dataset/ILSVRC2012_val_00020832.bin 224 224 +12497 ./prep_dataset/ILSVRC2012_val_00016949.bin 224 224 +12498 ./prep_dataset/ILSVRC2012_val_00040200.bin 224 224 +12499 ./prep_dataset/ILSVRC2012_val_00042922.bin 224 224 +12500 ./prep_dataset/ILSVRC2012_val_00046286.bin 224 224 +12501 ./prep_dataset/ILSVRC2012_val_00031178.bin 224 224 +12502 ./prep_dataset/ILSVRC2012_val_00042196.bin 224 224 +12503 ./prep_dataset/ILSVRC2012_val_00025473.bin 224 224 +12504 ./prep_dataset/ILSVRC2012_val_00026088.bin 224 224 +12505 ./prep_dataset/ILSVRC2012_val_00018157.bin 224 224 +12506 ./prep_dataset/ILSVRC2012_val_00010297.bin 224 224 +12507 ./prep_dataset/ILSVRC2012_val_00048441.bin 224 224 +12508 ./prep_dataset/ILSVRC2012_val_00029231.bin 224 224 +12509 ./prep_dataset/ILSVRC2012_val_00004122.bin 224 224 +12510 ./prep_dataset/ILSVRC2012_val_00022389.bin 224 224 +12511 ./prep_dataset/ILSVRC2012_val_00035100.bin 224 224 +12512 ./prep_dataset/ILSVRC2012_val_00023292.bin 224 224 +12513 ./prep_dataset/ILSVRC2012_val_00001451.bin 224 224 +12514 ./prep_dataset/ILSVRC2012_val_00013732.bin 224 224 +12515 ./prep_dataset/ILSVRC2012_val_00019123.bin 224 224 +12516 ./prep_dataset/ILSVRC2012_val_00007212.bin 224 224 +12517 ./prep_dataset/ILSVRC2012_val_00004385.bin 224 224 +12518 ./prep_dataset/ILSVRC2012_val_00043632.bin 224 224 +12519 ./prep_dataset/ILSVRC2012_val_00023327.bin 224 224 +12520 ./prep_dataset/ILSVRC2012_val_00006526.bin 224 224 +12521 ./prep_dataset/ILSVRC2012_val_00009335.bin 224 224 +12522 ./prep_dataset/ILSVRC2012_val_00039346.bin 224 224 +12523 ./prep_dataset/ILSVRC2012_val_00024986.bin 224 224 +12524 ./prep_dataset/ILSVRC2012_val_00003672.bin 224 224 +12525 ./prep_dataset/ILSVRC2012_val_00020684.bin 224 224 +12526 ./prep_dataset/ILSVRC2012_val_00009877.bin 224 224 +12527 ./prep_dataset/ILSVRC2012_val_00006033.bin 224 224 +12528 ./prep_dataset/ILSVRC2012_val_00035311.bin 224 224 +12529 ./prep_dataset/ILSVRC2012_val_00009399.bin 224 224 +12530 ./prep_dataset/ILSVRC2012_val_00014078.bin 224 224 +12531 ./prep_dataset/ILSVRC2012_val_00025952.bin 224 224 +12532 ./prep_dataset/ILSVRC2012_val_00038608.bin 224 224 +12533 ./prep_dataset/ILSVRC2012_val_00042856.bin 224 224 +12534 ./prep_dataset/ILSVRC2012_val_00043119.bin 224 224 +12535 ./prep_dataset/ILSVRC2012_val_00031188.bin 224 224 +12536 ./prep_dataset/ILSVRC2012_val_00000460.bin 224 224 +12537 ./prep_dataset/ILSVRC2012_val_00018853.bin 224 224 +12538 ./prep_dataset/ILSVRC2012_val_00032638.bin 224 224 +12539 ./prep_dataset/ILSVRC2012_val_00001067.bin 224 224 +12540 ./prep_dataset/ILSVRC2012_val_00020718.bin 224 224 +12541 ./prep_dataset/ILSVRC2012_val_00012363.bin 224 224 +12542 ./prep_dataset/ILSVRC2012_val_00035521.bin 224 224 +12543 ./prep_dataset/ILSVRC2012_val_00016645.bin 224 224 +12544 ./prep_dataset/ILSVRC2012_val_00035355.bin 224 224 +12545 ./prep_dataset/ILSVRC2012_val_00033582.bin 224 224 +12546 ./prep_dataset/ILSVRC2012_val_00038286.bin 224 224 +12547 ./prep_dataset/ILSVRC2012_val_00036036.bin 224 224 +12548 ./prep_dataset/ILSVRC2012_val_00008304.bin 224 224 +12549 ./prep_dataset/ILSVRC2012_val_00021174.bin 224 224 +12550 ./prep_dataset/ILSVRC2012_val_00037337.bin 224 224 +12551 ./prep_dataset/ILSVRC2012_val_00026946.bin 224 224 +12552 ./prep_dataset/ILSVRC2012_val_00001158.bin 224 224 +12553 ./prep_dataset/ILSVRC2012_val_00009615.bin 224 224 +12554 ./prep_dataset/ILSVRC2012_val_00003715.bin 224 224 +12555 ./prep_dataset/ILSVRC2012_val_00047449.bin 224 224 +12556 ./prep_dataset/ILSVRC2012_val_00025328.bin 224 224 +12557 ./prep_dataset/ILSVRC2012_val_00020028.bin 224 224 +12558 ./prep_dataset/ILSVRC2012_val_00032764.bin 224 224 +12559 ./prep_dataset/ILSVRC2012_val_00017555.bin 224 224 +12560 ./prep_dataset/ILSVRC2012_val_00023971.bin 224 224 +12561 ./prep_dataset/ILSVRC2012_val_00034673.bin 224 224 +12562 ./prep_dataset/ILSVRC2012_val_00034419.bin 224 224 +12563 ./prep_dataset/ILSVRC2012_val_00004100.bin 224 224 +12564 ./prep_dataset/ILSVRC2012_val_00043027.bin 224 224 +12565 ./prep_dataset/ILSVRC2012_val_00016854.bin 224 224 +12566 ./prep_dataset/ILSVRC2012_val_00038574.bin 224 224 +12567 ./prep_dataset/ILSVRC2012_val_00020497.bin 224 224 +12568 ./prep_dataset/ILSVRC2012_val_00027268.bin 224 224 +12569 ./prep_dataset/ILSVRC2012_val_00031426.bin 224 224 +12570 ./prep_dataset/ILSVRC2012_val_00048225.bin 224 224 +12571 ./prep_dataset/ILSVRC2012_val_00008578.bin 224 224 +12572 ./prep_dataset/ILSVRC2012_val_00009380.bin 224 224 +12573 ./prep_dataset/ILSVRC2012_val_00045495.bin 224 224 +12574 ./prep_dataset/ILSVRC2012_val_00048377.bin 224 224 +12575 ./prep_dataset/ILSVRC2012_val_00001114.bin 224 224 +12576 ./prep_dataset/ILSVRC2012_val_00048289.bin 224 224 +12577 ./prep_dataset/ILSVRC2012_val_00026466.bin 224 224 +12578 ./prep_dataset/ILSVRC2012_val_00010148.bin 224 224 +12579 ./prep_dataset/ILSVRC2012_val_00026374.bin 224 224 +12580 ./prep_dataset/ILSVRC2012_val_00046242.bin 224 224 +12581 ./prep_dataset/ILSVRC2012_val_00022099.bin 224 224 +12582 ./prep_dataset/ILSVRC2012_val_00012358.bin 224 224 +12583 ./prep_dataset/ILSVRC2012_val_00003215.bin 224 224 +12584 ./prep_dataset/ILSVRC2012_val_00020652.bin 224 224 +12585 ./prep_dataset/ILSVRC2012_val_00002986.bin 224 224 +12586 ./prep_dataset/ILSVRC2012_val_00045659.bin 224 224 +12587 ./prep_dataset/ILSVRC2012_val_00025294.bin 224 224 +12588 ./prep_dataset/ILSVRC2012_val_00004384.bin 224 224 +12589 ./prep_dataset/ILSVRC2012_val_00012558.bin 224 224 +12590 ./prep_dataset/ILSVRC2012_val_00038097.bin 224 224 +12591 ./prep_dataset/ILSVRC2012_val_00037085.bin 224 224 +12592 ./prep_dataset/ILSVRC2012_val_00020641.bin 224 224 +12593 ./prep_dataset/ILSVRC2012_val_00029771.bin 224 224 +12594 ./prep_dataset/ILSVRC2012_val_00047704.bin 224 224 +12595 ./prep_dataset/ILSVRC2012_val_00035123.bin 224 224 +12596 ./prep_dataset/ILSVRC2012_val_00000648.bin 224 224 +12597 ./prep_dataset/ILSVRC2012_val_00028862.bin 224 224 +12598 ./prep_dataset/ILSVRC2012_val_00039783.bin 224 224 +12599 ./prep_dataset/ILSVRC2012_val_00012177.bin 224 224 +12600 ./prep_dataset/ILSVRC2012_val_00041413.bin 224 224 +12601 ./prep_dataset/ILSVRC2012_val_00026403.bin 224 224 +12602 ./prep_dataset/ILSVRC2012_val_00023419.bin 224 224 +12603 ./prep_dataset/ILSVRC2012_val_00018486.bin 224 224 +12604 ./prep_dataset/ILSVRC2012_val_00020308.bin 224 224 +12605 ./prep_dataset/ILSVRC2012_val_00006977.bin 224 224 +12606 ./prep_dataset/ILSVRC2012_val_00020932.bin 224 224 +12607 ./prep_dataset/ILSVRC2012_val_00042477.bin 224 224 +12608 ./prep_dataset/ILSVRC2012_val_00024846.bin 224 224 +12609 ./prep_dataset/ILSVRC2012_val_00045804.bin 224 224 +12610 ./prep_dataset/ILSVRC2012_val_00012492.bin 224 224 +12611 ./prep_dataset/ILSVRC2012_val_00042198.bin 224 224 +12612 ./prep_dataset/ILSVRC2012_val_00019698.bin 224 224 +12613 ./prep_dataset/ILSVRC2012_val_00029659.bin 224 224 +12614 ./prep_dataset/ILSVRC2012_val_00007682.bin 224 224 +12615 ./prep_dataset/ILSVRC2012_val_00049844.bin 224 224 +12616 ./prep_dataset/ILSVRC2012_val_00011167.bin 224 224 +12617 ./prep_dataset/ILSVRC2012_val_00023028.bin 224 224 +12618 ./prep_dataset/ILSVRC2012_val_00000132.bin 224 224 +12619 ./prep_dataset/ILSVRC2012_val_00030295.bin 224 224 +12620 ./prep_dataset/ILSVRC2012_val_00026444.bin 224 224 +12621 ./prep_dataset/ILSVRC2012_val_00019415.bin 224 224 +12622 ./prep_dataset/ILSVRC2012_val_00042191.bin 224 224 +12623 ./prep_dataset/ILSVRC2012_val_00010538.bin 224 224 +12624 ./prep_dataset/ILSVRC2012_val_00021899.bin 224 224 +12625 ./prep_dataset/ILSVRC2012_val_00003729.bin 224 224 +12626 ./prep_dataset/ILSVRC2012_val_00035159.bin 224 224 +12627 ./prep_dataset/ILSVRC2012_val_00020219.bin 224 224 +12628 ./prep_dataset/ILSVRC2012_val_00040403.bin 224 224 +12629 ./prep_dataset/ILSVRC2012_val_00015951.bin 224 224 +12630 ./prep_dataset/ILSVRC2012_val_00017126.bin 224 224 +12631 ./prep_dataset/ILSVRC2012_val_00023165.bin 224 224 +12632 ./prep_dataset/ILSVRC2012_val_00018061.bin 224 224 +12633 ./prep_dataset/ILSVRC2012_val_00012193.bin 224 224 +12634 ./prep_dataset/ILSVRC2012_val_00002628.bin 224 224 +12635 ./prep_dataset/ILSVRC2012_val_00015962.bin 224 224 +12636 ./prep_dataset/ILSVRC2012_val_00006157.bin 224 224 +12637 ./prep_dataset/ILSVRC2012_val_00042988.bin 224 224 +12638 ./prep_dataset/ILSVRC2012_val_00044959.bin 224 224 +12639 ./prep_dataset/ILSVRC2012_val_00044284.bin 224 224 +12640 ./prep_dataset/ILSVRC2012_val_00008309.bin 224 224 +12641 ./prep_dataset/ILSVRC2012_val_00025400.bin 224 224 +12642 ./prep_dataset/ILSVRC2012_val_00012241.bin 224 224 +12643 ./prep_dataset/ILSVRC2012_val_00034263.bin 224 224 +12644 ./prep_dataset/ILSVRC2012_val_00004703.bin 224 224 +12645 ./prep_dataset/ILSVRC2012_val_00004109.bin 224 224 +12646 ./prep_dataset/ILSVRC2012_val_00029060.bin 224 224 +12647 ./prep_dataset/ILSVRC2012_val_00025754.bin 224 224 +12648 ./prep_dataset/ILSVRC2012_val_00004313.bin 224 224 +12649 ./prep_dataset/ILSVRC2012_val_00016976.bin 224 224 +12650 ./prep_dataset/ILSVRC2012_val_00018800.bin 224 224 +12651 ./prep_dataset/ILSVRC2012_val_00043231.bin 224 224 +12652 ./prep_dataset/ILSVRC2012_val_00008017.bin 224 224 +12653 ./prep_dataset/ILSVRC2012_val_00003860.bin 224 224 +12654 ./prep_dataset/ILSVRC2012_val_00029141.bin 224 224 +12655 ./prep_dataset/ILSVRC2012_val_00043133.bin 224 224 +12656 ./prep_dataset/ILSVRC2012_val_00033453.bin 224 224 +12657 ./prep_dataset/ILSVRC2012_val_00048087.bin 224 224 +12658 ./prep_dataset/ILSVRC2012_val_00032457.bin 224 224 +12659 ./prep_dataset/ILSVRC2012_val_00037562.bin 224 224 +12660 ./prep_dataset/ILSVRC2012_val_00023581.bin 224 224 +12661 ./prep_dataset/ILSVRC2012_val_00032034.bin 224 224 +12662 ./prep_dataset/ILSVRC2012_val_00021219.bin 224 224 +12663 ./prep_dataset/ILSVRC2012_val_00018100.bin 224 224 +12664 ./prep_dataset/ILSVRC2012_val_00024930.bin 224 224 +12665 ./prep_dataset/ILSVRC2012_val_00031938.bin 224 224 +12666 ./prep_dataset/ILSVRC2012_val_00006274.bin 224 224 +12667 ./prep_dataset/ILSVRC2012_val_00049182.bin 224 224 +12668 ./prep_dataset/ILSVRC2012_val_00031678.bin 224 224 +12669 ./prep_dataset/ILSVRC2012_val_00004096.bin 224 224 +12670 ./prep_dataset/ILSVRC2012_val_00036821.bin 224 224 +12671 ./prep_dataset/ILSVRC2012_val_00027137.bin 224 224 +12672 ./prep_dataset/ILSVRC2012_val_00038485.bin 224 224 +12673 ./prep_dataset/ILSVRC2012_val_00024475.bin 224 224 +12674 ./prep_dataset/ILSVRC2012_val_00034712.bin 224 224 +12675 ./prep_dataset/ILSVRC2012_val_00003232.bin 224 224 +12676 ./prep_dataset/ILSVRC2012_val_00035724.bin 224 224 +12677 ./prep_dataset/ILSVRC2012_val_00013073.bin 224 224 +12678 ./prep_dataset/ILSVRC2012_val_00000028.bin 224 224 +12679 ./prep_dataset/ILSVRC2012_val_00019405.bin 224 224 +12680 ./prep_dataset/ILSVRC2012_val_00007186.bin 224 224 +12681 ./prep_dataset/ILSVRC2012_val_00004845.bin 224 224 +12682 ./prep_dataset/ILSVRC2012_val_00047472.bin 224 224 +12683 ./prep_dataset/ILSVRC2012_val_00000668.bin 224 224 +12684 ./prep_dataset/ILSVRC2012_val_00023456.bin 224 224 +12685 ./prep_dataset/ILSVRC2012_val_00032801.bin 224 224 +12686 ./prep_dataset/ILSVRC2012_val_00014800.bin 224 224 +12687 ./prep_dataset/ILSVRC2012_val_00023970.bin 224 224 +12688 ./prep_dataset/ILSVRC2012_val_00013390.bin 224 224 +12689 ./prep_dataset/ILSVRC2012_val_00038828.bin 224 224 +12690 ./prep_dataset/ILSVRC2012_val_00033480.bin 224 224 +12691 ./prep_dataset/ILSVRC2012_val_00012219.bin 224 224 +12692 ./prep_dataset/ILSVRC2012_val_00034249.bin 224 224 +12693 ./prep_dataset/ILSVRC2012_val_00001085.bin 224 224 +12694 ./prep_dataset/ILSVRC2012_val_00025663.bin 224 224 +12695 ./prep_dataset/ILSVRC2012_val_00040972.bin 224 224 +12696 ./prep_dataset/ILSVRC2012_val_00007017.bin 224 224 +12697 ./prep_dataset/ILSVRC2012_val_00028908.bin 224 224 +12698 ./prep_dataset/ILSVRC2012_val_00046256.bin 224 224 +12699 ./prep_dataset/ILSVRC2012_val_00032023.bin 224 224 +12700 ./prep_dataset/ILSVRC2012_val_00003772.bin 224 224 +12701 ./prep_dataset/ILSVRC2012_val_00037719.bin 224 224 +12702 ./prep_dataset/ILSVRC2012_val_00031767.bin 224 224 +12703 ./prep_dataset/ILSVRC2012_val_00034277.bin 224 224 +12704 ./prep_dataset/ILSVRC2012_val_00020534.bin 224 224 +12705 ./prep_dataset/ILSVRC2012_val_00000563.bin 224 224 +12706 ./prep_dataset/ILSVRC2012_val_00035217.bin 224 224 +12707 ./prep_dataset/ILSVRC2012_val_00023234.bin 224 224 +12708 ./prep_dataset/ILSVRC2012_val_00001897.bin 224 224 +12709 ./prep_dataset/ILSVRC2012_val_00026493.bin 224 224 +12710 ./prep_dataset/ILSVRC2012_val_00038411.bin 224 224 +12711 ./prep_dataset/ILSVRC2012_val_00027348.bin 224 224 +12712 ./prep_dataset/ILSVRC2012_val_00034290.bin 224 224 +12713 ./prep_dataset/ILSVRC2012_val_00009990.bin 224 224 +12714 ./prep_dataset/ILSVRC2012_val_00019916.bin 224 224 +12715 ./prep_dataset/ILSVRC2012_val_00038759.bin 224 224 +12716 ./prep_dataset/ILSVRC2012_val_00001369.bin 224 224 +12717 ./prep_dataset/ILSVRC2012_val_00035946.bin 224 224 +12718 ./prep_dataset/ILSVRC2012_val_00042430.bin 224 224 +12719 ./prep_dataset/ILSVRC2012_val_00036184.bin 224 224 +12720 ./prep_dataset/ILSVRC2012_val_00012734.bin 224 224 +12721 ./prep_dataset/ILSVRC2012_val_00049126.bin 224 224 +12722 ./prep_dataset/ILSVRC2012_val_00038650.bin 224 224 +12723 ./prep_dataset/ILSVRC2012_val_00049603.bin 224 224 +12724 ./prep_dataset/ILSVRC2012_val_00015201.bin 224 224 +12725 ./prep_dataset/ILSVRC2012_val_00020006.bin 224 224 +12726 ./prep_dataset/ILSVRC2012_val_00019750.bin 224 224 +12727 ./prep_dataset/ILSVRC2012_val_00014655.bin 224 224 +12728 ./prep_dataset/ILSVRC2012_val_00033323.bin 224 224 +12729 ./prep_dataset/ILSVRC2012_val_00049310.bin 224 224 +12730 ./prep_dataset/ILSVRC2012_val_00041132.bin 224 224 +12731 ./prep_dataset/ILSVRC2012_val_00045183.bin 224 224 +12732 ./prep_dataset/ILSVRC2012_val_00022932.bin 224 224 +12733 ./prep_dataset/ILSVRC2012_val_00042929.bin 224 224 +12734 ./prep_dataset/ILSVRC2012_val_00031208.bin 224 224 +12735 ./prep_dataset/ILSVRC2012_val_00031913.bin 224 224 +12736 ./prep_dataset/ILSVRC2012_val_00006484.bin 224 224 +12737 ./prep_dataset/ILSVRC2012_val_00002355.bin 224 224 +12738 ./prep_dataset/ILSVRC2012_val_00019118.bin 224 224 +12739 ./prep_dataset/ILSVRC2012_val_00007562.bin 224 224 +12740 ./prep_dataset/ILSVRC2012_val_00004901.bin 224 224 +12741 ./prep_dataset/ILSVRC2012_val_00011546.bin 224 224 +12742 ./prep_dataset/ILSVRC2012_val_00045055.bin 224 224 +12743 ./prep_dataset/ILSVRC2012_val_00029723.bin 224 224 +12744 ./prep_dataset/ILSVRC2012_val_00013569.bin 224 224 +12745 ./prep_dataset/ILSVRC2012_val_00021007.bin 224 224 +12746 ./prep_dataset/ILSVRC2012_val_00004167.bin 224 224 +12747 ./prep_dataset/ILSVRC2012_val_00044561.bin 224 224 +12748 ./prep_dataset/ILSVRC2012_val_00037191.bin 224 224 +12749 ./prep_dataset/ILSVRC2012_val_00006622.bin 224 224 +12750 ./prep_dataset/ILSVRC2012_val_00025839.bin 224 224 +12751 ./prep_dataset/ILSVRC2012_val_00045361.bin 224 224 +12752 ./prep_dataset/ILSVRC2012_val_00022626.bin 224 224 +12753 ./prep_dataset/ILSVRC2012_val_00026692.bin 224 224 +12754 ./prep_dataset/ILSVRC2012_val_00024387.bin 224 224 +12755 ./prep_dataset/ILSVRC2012_val_00049835.bin 224 224 +12756 ./prep_dataset/ILSVRC2012_val_00038103.bin 224 224 +12757 ./prep_dataset/ILSVRC2012_val_00040034.bin 224 224 +12758 ./prep_dataset/ILSVRC2012_val_00024395.bin 224 224 +12759 ./prep_dataset/ILSVRC2012_val_00002780.bin 224 224 +12760 ./prep_dataset/ILSVRC2012_val_00044915.bin 224 224 +12761 ./prep_dataset/ILSVRC2012_val_00025543.bin 224 224 +12762 ./prep_dataset/ILSVRC2012_val_00027250.bin 224 224 +12763 ./prep_dataset/ILSVRC2012_val_00013301.bin 224 224 +12764 ./prep_dataset/ILSVRC2012_val_00031282.bin 224 224 +12765 ./prep_dataset/ILSVRC2012_val_00022728.bin 224 224 +12766 ./prep_dataset/ILSVRC2012_val_00019565.bin 224 224 +12767 ./prep_dataset/ILSVRC2012_val_00011999.bin 224 224 +12768 ./prep_dataset/ILSVRC2012_val_00042884.bin 224 224 +12769 ./prep_dataset/ILSVRC2012_val_00029592.bin 224 224 +12770 ./prep_dataset/ILSVRC2012_val_00031388.bin 224 224 +12771 ./prep_dataset/ILSVRC2012_val_00007215.bin 224 224 +12772 ./prep_dataset/ILSVRC2012_val_00047761.bin 224 224 +12773 ./prep_dataset/ILSVRC2012_val_00023543.bin 224 224 +12774 ./prep_dataset/ILSVRC2012_val_00032580.bin 224 224 +12775 ./prep_dataset/ILSVRC2012_val_00024094.bin 224 224 +12776 ./prep_dataset/ILSVRC2012_val_00014994.bin 224 224 +12777 ./prep_dataset/ILSVRC2012_val_00037088.bin 224 224 +12778 ./prep_dataset/ILSVRC2012_val_00016250.bin 224 224 +12779 ./prep_dataset/ILSVRC2012_val_00040360.bin 224 224 +12780 ./prep_dataset/ILSVRC2012_val_00029586.bin 224 224 +12781 ./prep_dataset/ILSVRC2012_val_00005554.bin 224 224 +12782 ./prep_dataset/ILSVRC2012_val_00010614.bin 224 224 +12783 ./prep_dataset/ILSVRC2012_val_00003381.bin 224 224 +12784 ./prep_dataset/ILSVRC2012_val_00048221.bin 224 224 +12785 ./prep_dataset/ILSVRC2012_val_00011126.bin 224 224 +12786 ./prep_dataset/ILSVRC2012_val_00005612.bin 224 224 +12787 ./prep_dataset/ILSVRC2012_val_00003053.bin 224 224 +12788 ./prep_dataset/ILSVRC2012_val_00037910.bin 224 224 +12789 ./prep_dataset/ILSVRC2012_val_00022700.bin 224 224 +12790 ./prep_dataset/ILSVRC2012_val_00020733.bin 224 224 +12791 ./prep_dataset/ILSVRC2012_val_00003698.bin 224 224 +12792 ./prep_dataset/ILSVRC2012_val_00018772.bin 224 224 +12793 ./prep_dataset/ILSVRC2012_val_00014149.bin 224 224 +12794 ./prep_dataset/ILSVRC2012_val_00043764.bin 224 224 +12795 ./prep_dataset/ILSVRC2012_val_00018656.bin 224 224 +12796 ./prep_dataset/ILSVRC2012_val_00018317.bin 224 224 +12797 ./prep_dataset/ILSVRC2012_val_00009169.bin 224 224 +12798 ./prep_dataset/ILSVRC2012_val_00000956.bin 224 224 +12799 ./prep_dataset/ILSVRC2012_val_00030537.bin 224 224 +12800 ./prep_dataset/ILSVRC2012_val_00019387.bin 224 224 +12801 ./prep_dataset/ILSVRC2012_val_00003787.bin 224 224 +12802 ./prep_dataset/ILSVRC2012_val_00038448.bin 224 224 +12803 ./prep_dataset/ILSVRC2012_val_00014862.bin 224 224 +12804 ./prep_dataset/ILSVRC2012_val_00042700.bin 224 224 +12805 ./prep_dataset/ILSVRC2012_val_00025499.bin 224 224 +12806 ./prep_dataset/ILSVRC2012_val_00027228.bin 224 224 +12807 ./prep_dataset/ILSVRC2012_val_00015519.bin 224 224 +12808 ./prep_dataset/ILSVRC2012_val_00043682.bin 224 224 +12809 ./prep_dataset/ILSVRC2012_val_00024576.bin 224 224 +12810 ./prep_dataset/ILSVRC2012_val_00043175.bin 224 224 +12811 ./prep_dataset/ILSVRC2012_val_00034242.bin 224 224 +12812 ./prep_dataset/ILSVRC2012_val_00025493.bin 224 224 +12813 ./prep_dataset/ILSVRC2012_val_00016279.bin 224 224 +12814 ./prep_dataset/ILSVRC2012_val_00046275.bin 224 224 +12815 ./prep_dataset/ILSVRC2012_val_00012770.bin 224 224 +12816 ./prep_dataset/ILSVRC2012_val_00040358.bin 224 224 +12817 ./prep_dataset/ILSVRC2012_val_00048228.bin 224 224 +12818 ./prep_dataset/ILSVRC2012_val_00004157.bin 224 224 +12819 ./prep_dataset/ILSVRC2012_val_00014023.bin 224 224 +12820 ./prep_dataset/ILSVRC2012_val_00044022.bin 224 224 +12821 ./prep_dataset/ILSVRC2012_val_00031254.bin 224 224 +12822 ./prep_dataset/ILSVRC2012_val_00016138.bin 224 224 +12823 ./prep_dataset/ILSVRC2012_val_00006122.bin 224 224 +12824 ./prep_dataset/ILSVRC2012_val_00002406.bin 224 224 +12825 ./prep_dataset/ILSVRC2012_val_00015680.bin 224 224 +12826 ./prep_dataset/ILSVRC2012_val_00013960.bin 224 224 +12827 ./prep_dataset/ILSVRC2012_val_00034022.bin 224 224 +12828 ./prep_dataset/ILSVRC2012_val_00021674.bin 224 224 +12829 ./prep_dataset/ILSVRC2012_val_00045990.bin 224 224 +12830 ./prep_dataset/ILSVRC2012_val_00033719.bin 224 224 +12831 ./prep_dataset/ILSVRC2012_val_00034464.bin 224 224 +12832 ./prep_dataset/ILSVRC2012_val_00013397.bin 224 224 +12833 ./prep_dataset/ILSVRC2012_val_00037664.bin 224 224 +12834 ./prep_dataset/ILSVRC2012_val_00026069.bin 224 224 +12835 ./prep_dataset/ILSVRC2012_val_00014874.bin 224 224 +12836 ./prep_dataset/ILSVRC2012_val_00025320.bin 224 224 +12837 ./prep_dataset/ILSVRC2012_val_00009519.bin 224 224 +12838 ./prep_dataset/ILSVRC2012_val_00015589.bin 224 224 +12839 ./prep_dataset/ILSVRC2012_val_00007090.bin 224 224 +12840 ./prep_dataset/ILSVRC2012_val_00025975.bin 224 224 +12841 ./prep_dataset/ILSVRC2012_val_00029346.bin 224 224 +12842 ./prep_dataset/ILSVRC2012_val_00014249.bin 224 224 +12843 ./prep_dataset/ILSVRC2012_val_00029148.bin 224 224 +12844 ./prep_dataset/ILSVRC2012_val_00000948.bin 224 224 +12845 ./prep_dataset/ILSVRC2012_val_00031890.bin 224 224 +12846 ./prep_dataset/ILSVRC2012_val_00033212.bin 224 224 +12847 ./prep_dataset/ILSVRC2012_val_00038217.bin 224 224 +12848 ./prep_dataset/ILSVRC2012_val_00033672.bin 224 224 +12849 ./prep_dataset/ILSVRC2012_val_00028230.bin 224 224 +12850 ./prep_dataset/ILSVRC2012_val_00017894.bin 224 224 +12851 ./prep_dataset/ILSVRC2012_val_00043476.bin 224 224 +12852 ./prep_dataset/ILSVRC2012_val_00026175.bin 224 224 +12853 ./prep_dataset/ILSVRC2012_val_00040247.bin 224 224 +12854 ./prep_dataset/ILSVRC2012_val_00034861.bin 224 224 +12855 ./prep_dataset/ILSVRC2012_val_00015461.bin 224 224 +12856 ./prep_dataset/ILSVRC2012_val_00045524.bin 224 224 +12857 ./prep_dataset/ILSVRC2012_val_00039167.bin 224 224 +12858 ./prep_dataset/ILSVRC2012_val_00026560.bin 224 224 +12859 ./prep_dataset/ILSVRC2012_val_00046470.bin 224 224 +12860 ./prep_dataset/ILSVRC2012_val_00020246.bin 224 224 +12861 ./prep_dataset/ILSVRC2012_val_00001848.bin 224 224 +12862 ./prep_dataset/ILSVRC2012_val_00009869.bin 224 224 +12863 ./prep_dataset/ILSVRC2012_val_00031353.bin 224 224 +12864 ./prep_dataset/ILSVRC2012_val_00048445.bin 224 224 +12865 ./prep_dataset/ILSVRC2012_val_00036831.bin 224 224 +12866 ./prep_dataset/ILSVRC2012_val_00048898.bin 224 224 +12867 ./prep_dataset/ILSVRC2012_val_00045504.bin 224 224 +12868 ./prep_dataset/ILSVRC2012_val_00015556.bin 224 224 +12869 ./prep_dataset/ILSVRC2012_val_00040903.bin 224 224 +12870 ./prep_dataset/ILSVRC2012_val_00004799.bin 224 224 +12871 ./prep_dataset/ILSVRC2012_val_00001190.bin 224 224 +12872 ./prep_dataset/ILSVRC2012_val_00028954.bin 224 224 +12873 ./prep_dataset/ILSVRC2012_val_00045782.bin 224 224 +12874 ./prep_dataset/ILSVRC2012_val_00011131.bin 224 224 +12875 ./prep_dataset/ILSVRC2012_val_00030376.bin 224 224 +12876 ./prep_dataset/ILSVRC2012_val_00004813.bin 224 224 +12877 ./prep_dataset/ILSVRC2012_val_00029105.bin 224 224 +12878 ./prep_dataset/ILSVRC2012_val_00014859.bin 224 224 +12879 ./prep_dataset/ILSVRC2012_val_00014158.bin 224 224 +12880 ./prep_dataset/ILSVRC2012_val_00043819.bin 224 224 +12881 ./prep_dataset/ILSVRC2012_val_00003808.bin 224 224 +12882 ./prep_dataset/ILSVRC2012_val_00046939.bin 224 224 +12883 ./prep_dataset/ILSVRC2012_val_00000178.bin 224 224 +12884 ./prep_dataset/ILSVRC2012_val_00027626.bin 224 224 +12885 ./prep_dataset/ILSVRC2012_val_00028058.bin 224 224 +12886 ./prep_dataset/ILSVRC2012_val_00009388.bin 224 224 +12887 ./prep_dataset/ILSVRC2012_val_00033705.bin 224 224 +12888 ./prep_dataset/ILSVRC2012_val_00017904.bin 224 224 +12889 ./prep_dataset/ILSVRC2012_val_00018129.bin 224 224 +12890 ./prep_dataset/ILSVRC2012_val_00003425.bin 224 224 +12891 ./prep_dataset/ILSVRC2012_val_00016135.bin 224 224 +12892 ./prep_dataset/ILSVRC2012_val_00035228.bin 224 224 +12893 ./prep_dataset/ILSVRC2012_val_00003348.bin 224 224 +12894 ./prep_dataset/ILSVRC2012_val_00016024.bin 224 224 +12895 ./prep_dataset/ILSVRC2012_val_00023752.bin 224 224 +12896 ./prep_dataset/ILSVRC2012_val_00049888.bin 224 224 +12897 ./prep_dataset/ILSVRC2012_val_00022553.bin 224 224 +12898 ./prep_dataset/ILSVRC2012_val_00046211.bin 224 224 +12899 ./prep_dataset/ILSVRC2012_val_00010504.bin 224 224 +12900 ./prep_dataset/ILSVRC2012_val_00003125.bin 224 224 +12901 ./prep_dataset/ILSVRC2012_val_00031805.bin 224 224 +12902 ./prep_dataset/ILSVRC2012_val_00035685.bin 224 224 +12903 ./prep_dataset/ILSVRC2012_val_00029434.bin 224 224 +12904 ./prep_dataset/ILSVRC2012_val_00035788.bin 224 224 +12905 ./prep_dataset/ILSVRC2012_val_00023786.bin 224 224 +12906 ./prep_dataset/ILSVRC2012_val_00046932.bin 224 224 +12907 ./prep_dataset/ILSVRC2012_val_00031363.bin 224 224 +12908 ./prep_dataset/ILSVRC2012_val_00017870.bin 224 224 +12909 ./prep_dataset/ILSVRC2012_val_00044857.bin 224 224 +12910 ./prep_dataset/ILSVRC2012_val_00020506.bin 224 224 +12911 ./prep_dataset/ILSVRC2012_val_00038432.bin 224 224 +12912 ./prep_dataset/ILSVRC2012_val_00027735.bin 224 224 +12913 ./prep_dataset/ILSVRC2012_val_00002281.bin 224 224 +12914 ./prep_dataset/ILSVRC2012_val_00012294.bin 224 224 +12915 ./prep_dataset/ILSVRC2012_val_00002584.bin 224 224 +12916 ./prep_dataset/ILSVRC2012_val_00024785.bin 224 224 +12917 ./prep_dataset/ILSVRC2012_val_00038926.bin 224 224 +12918 ./prep_dataset/ILSVRC2012_val_00011877.bin 224 224 +12919 ./prep_dataset/ILSVRC2012_val_00045113.bin 224 224 +12920 ./prep_dataset/ILSVRC2012_val_00001614.bin 224 224 +12921 ./prep_dataset/ILSVRC2012_val_00007936.bin 224 224 +12922 ./prep_dataset/ILSVRC2012_val_00026687.bin 224 224 +12923 ./prep_dataset/ILSVRC2012_val_00001555.bin 224 224 +12924 ./prep_dataset/ILSVRC2012_val_00021344.bin 224 224 +12925 ./prep_dataset/ILSVRC2012_val_00009672.bin 224 224 +12926 ./prep_dataset/ILSVRC2012_val_00030081.bin 224 224 +12927 ./prep_dataset/ILSVRC2012_val_00037382.bin 224 224 +12928 ./prep_dataset/ILSVRC2012_val_00039537.bin 224 224 +12929 ./prep_dataset/ILSVRC2012_val_00010359.bin 224 224 +12930 ./prep_dataset/ILSVRC2012_val_00043484.bin 224 224 +12931 ./prep_dataset/ILSVRC2012_val_00047288.bin 224 224 +12932 ./prep_dataset/ILSVRC2012_val_00010064.bin 224 224 +12933 ./prep_dataset/ILSVRC2012_val_00006324.bin 224 224 +12934 ./prep_dataset/ILSVRC2012_val_00004961.bin 224 224 +12935 ./prep_dataset/ILSVRC2012_val_00039129.bin 224 224 +12936 ./prep_dataset/ILSVRC2012_val_00000162.bin 224 224 +12937 ./prep_dataset/ILSVRC2012_val_00025708.bin 224 224 +12938 ./prep_dataset/ILSVRC2012_val_00034100.bin 224 224 +12939 ./prep_dataset/ILSVRC2012_val_00004702.bin 224 224 +12940 ./prep_dataset/ILSVRC2012_val_00023804.bin 224 224 +12941 ./prep_dataset/ILSVRC2012_val_00026934.bin 224 224 +12942 ./prep_dataset/ILSVRC2012_val_00029733.bin 224 224 +12943 ./prep_dataset/ILSVRC2012_val_00040242.bin 224 224 +12944 ./prep_dataset/ILSVRC2012_val_00010248.bin 224 224 +12945 ./prep_dataset/ILSVRC2012_val_00023050.bin 224 224 +12946 ./prep_dataset/ILSVRC2012_val_00028039.bin 224 224 +12947 ./prep_dataset/ILSVRC2012_val_00043992.bin 224 224 +12948 ./prep_dataset/ILSVRC2012_val_00028059.bin 224 224 +12949 ./prep_dataset/ILSVRC2012_val_00004452.bin 224 224 +12950 ./prep_dataset/ILSVRC2012_val_00028464.bin 224 224 +12951 ./prep_dataset/ILSVRC2012_val_00041466.bin 224 224 +12952 ./prep_dataset/ILSVRC2012_val_00039555.bin 224 224 +12953 ./prep_dataset/ILSVRC2012_val_00005016.bin 224 224 +12954 ./prep_dataset/ILSVRC2012_val_00026004.bin 224 224 +12955 ./prep_dataset/ILSVRC2012_val_00014715.bin 224 224 +12956 ./prep_dataset/ILSVRC2012_val_00034384.bin 224 224 +12957 ./prep_dataset/ILSVRC2012_val_00035618.bin 224 224 +12958 ./prep_dataset/ILSVRC2012_val_00002792.bin 224 224 +12959 ./prep_dataset/ILSVRC2012_val_00032822.bin 224 224 +12960 ./prep_dataset/ILSVRC2012_val_00047539.bin 224 224 +12961 ./prep_dataset/ILSVRC2012_val_00015214.bin 224 224 +12962 ./prep_dataset/ILSVRC2012_val_00011267.bin 224 224 +12963 ./prep_dataset/ILSVRC2012_val_00037908.bin 224 224 +12964 ./prep_dataset/ILSVRC2012_val_00029916.bin 224 224 +12965 ./prep_dataset/ILSVRC2012_val_00044839.bin 224 224 +12966 ./prep_dataset/ILSVRC2012_val_00020577.bin 224 224 +12967 ./prep_dataset/ILSVRC2012_val_00027485.bin 224 224 +12968 ./prep_dataset/ILSVRC2012_val_00019064.bin 224 224 +12969 ./prep_dataset/ILSVRC2012_val_00016683.bin 224 224 +12970 ./prep_dataset/ILSVRC2012_val_00036055.bin 224 224 +12971 ./prep_dataset/ILSVRC2012_val_00007677.bin 224 224 +12972 ./prep_dataset/ILSVRC2012_val_00019125.bin 224 224 +12973 ./prep_dataset/ILSVRC2012_val_00032411.bin 224 224 +12974 ./prep_dataset/ILSVRC2012_val_00026673.bin 224 224 +12975 ./prep_dataset/ILSVRC2012_val_00035825.bin 224 224 +12976 ./prep_dataset/ILSVRC2012_val_00028574.bin 224 224 +12977 ./prep_dataset/ILSVRC2012_val_00010466.bin 224 224 +12978 ./prep_dataset/ILSVRC2012_val_00006884.bin 224 224 +12979 ./prep_dataset/ILSVRC2012_val_00002910.bin 224 224 +12980 ./prep_dataset/ILSVRC2012_val_00005743.bin 224 224 +12981 ./prep_dataset/ILSVRC2012_val_00041928.bin 224 224 +12982 ./prep_dataset/ILSVRC2012_val_00033865.bin 224 224 +12983 ./prep_dataset/ILSVRC2012_val_00018401.bin 224 224 +12984 ./prep_dataset/ILSVRC2012_val_00008717.bin 224 224 +12985 ./prep_dataset/ILSVRC2012_val_00027978.bin 224 224 +12986 ./prep_dataset/ILSVRC2012_val_00040883.bin 224 224 +12987 ./prep_dataset/ILSVRC2012_val_00005834.bin 224 224 +12988 ./prep_dataset/ILSVRC2012_val_00003950.bin 224 224 +12989 ./prep_dataset/ILSVRC2012_val_00031749.bin 224 224 +12990 ./prep_dataset/ILSVRC2012_val_00016043.bin 224 224 +12991 ./prep_dataset/ILSVRC2012_val_00029289.bin 224 224 +12992 ./prep_dataset/ILSVRC2012_val_00039111.bin 224 224 +12993 ./prep_dataset/ILSVRC2012_val_00000214.bin 224 224 +12994 ./prep_dataset/ILSVRC2012_val_00010270.bin 224 224 +12995 ./prep_dataset/ILSVRC2012_val_00038525.bin 224 224 +12996 ./prep_dataset/ILSVRC2012_val_00022084.bin 224 224 +12997 ./prep_dataset/ILSVRC2012_val_00022302.bin 224 224 +12998 ./prep_dataset/ILSVRC2012_val_00022730.bin 224 224 +12999 ./prep_dataset/ILSVRC2012_val_00015772.bin 224 224 +13000 ./prep_dataset/ILSVRC2012_val_00049894.bin 224 224 +13001 ./prep_dataset/ILSVRC2012_val_00023947.bin 224 224 +13002 ./prep_dataset/ILSVRC2012_val_00015821.bin 224 224 +13003 ./prep_dataset/ILSVRC2012_val_00014082.bin 224 224 +13004 ./prep_dataset/ILSVRC2012_val_00015259.bin 224 224 +13005 ./prep_dataset/ILSVRC2012_val_00040898.bin 224 224 +13006 ./prep_dataset/ILSVRC2012_val_00000323.bin 224 224 +13007 ./prep_dataset/ILSVRC2012_val_00047459.bin 224 224 +13008 ./prep_dataset/ILSVRC2012_val_00025164.bin 224 224 +13009 ./prep_dataset/ILSVRC2012_val_00033447.bin 224 224 +13010 ./prep_dataset/ILSVRC2012_val_00020507.bin 224 224 +13011 ./prep_dataset/ILSVRC2012_val_00046160.bin 224 224 +13012 ./prep_dataset/ILSVRC2012_val_00009969.bin 224 224 +13013 ./prep_dataset/ILSVRC2012_val_00016426.bin 224 224 +13014 ./prep_dataset/ILSVRC2012_val_00014573.bin 224 224 +13015 ./prep_dataset/ILSVRC2012_val_00036238.bin 224 224 +13016 ./prep_dataset/ILSVRC2012_val_00015627.bin 224 224 +13017 ./prep_dataset/ILSVRC2012_val_00022370.bin 224 224 +13018 ./prep_dataset/ILSVRC2012_val_00030802.bin 224 224 +13019 ./prep_dataset/ILSVRC2012_val_00036520.bin 224 224 +13020 ./prep_dataset/ILSVRC2012_val_00003075.bin 224 224 +13021 ./prep_dataset/ILSVRC2012_val_00041849.bin 224 224 +13022 ./prep_dataset/ILSVRC2012_val_00022423.bin 224 224 +13023 ./prep_dataset/ILSVRC2012_val_00023673.bin 224 224 +13024 ./prep_dataset/ILSVRC2012_val_00018617.bin 224 224 +13025 ./prep_dataset/ILSVRC2012_val_00048678.bin 224 224 +13026 ./prep_dataset/ILSVRC2012_val_00002143.bin 224 224 +13027 ./prep_dataset/ILSVRC2012_val_00012341.bin 224 224 +13028 ./prep_dataset/ILSVRC2012_val_00029271.bin 224 224 +13029 ./prep_dataset/ILSVRC2012_val_00014614.bin 224 224 +13030 ./prep_dataset/ILSVRC2012_val_00014240.bin 224 224 +13031 ./prep_dataset/ILSVRC2012_val_00037911.bin 224 224 +13032 ./prep_dataset/ILSVRC2012_val_00049320.bin 224 224 +13033 ./prep_dataset/ILSVRC2012_val_00005399.bin 224 224 +13034 ./prep_dataset/ILSVRC2012_val_00040469.bin 224 224 +13035 ./prep_dataset/ILSVRC2012_val_00007068.bin 224 224 +13036 ./prep_dataset/ILSVRC2012_val_00011087.bin 224 224 +13037 ./prep_dataset/ILSVRC2012_val_00001884.bin 224 224 +13038 ./prep_dataset/ILSVRC2012_val_00006789.bin 224 224 +13039 ./prep_dataset/ILSVRC2012_val_00017131.bin 224 224 +13040 ./prep_dataset/ILSVRC2012_val_00015983.bin 224 224 +13041 ./prep_dataset/ILSVRC2012_val_00010052.bin 224 224 +13042 ./prep_dataset/ILSVRC2012_val_00024606.bin 224 224 +13043 ./prep_dataset/ILSVRC2012_val_00024306.bin 224 224 +13044 ./prep_dataset/ILSVRC2012_val_00029805.bin 224 224 +13045 ./prep_dataset/ILSVRC2012_val_00012480.bin 224 224 +13046 ./prep_dataset/ILSVRC2012_val_00000944.bin 224 224 +13047 ./prep_dataset/ILSVRC2012_val_00030097.bin 224 224 +13048 ./prep_dataset/ILSVRC2012_val_00000708.bin 224 224 +13049 ./prep_dataset/ILSVRC2012_val_00011640.bin 224 224 +13050 ./prep_dataset/ILSVRC2012_val_00026085.bin 224 224 +13051 ./prep_dataset/ILSVRC2012_val_00042893.bin 224 224 +13052 ./prep_dataset/ILSVRC2012_val_00003752.bin 224 224 +13053 ./prep_dataset/ILSVRC2012_val_00038259.bin 224 224 +13054 ./prep_dataset/ILSVRC2012_val_00017656.bin 224 224 +13055 ./prep_dataset/ILSVRC2012_val_00031917.bin 224 224 +13056 ./prep_dataset/ILSVRC2012_val_00031179.bin 224 224 +13057 ./prep_dataset/ILSVRC2012_val_00004876.bin 224 224 +13058 ./prep_dataset/ILSVRC2012_val_00021330.bin 224 224 +13059 ./prep_dataset/ILSVRC2012_val_00046537.bin 224 224 +13060 ./prep_dataset/ILSVRC2012_val_00036116.bin 224 224 +13061 ./prep_dataset/ILSVRC2012_val_00035120.bin 224 224 +13062 ./prep_dataset/ILSVRC2012_val_00023064.bin 224 224 +13063 ./prep_dataset/ILSVRC2012_val_00032280.bin 224 224 +13064 ./prep_dataset/ILSVRC2012_val_00022753.bin 224 224 +13065 ./prep_dataset/ILSVRC2012_val_00028513.bin 224 224 +13066 ./prep_dataset/ILSVRC2012_val_00006872.bin 224 224 +13067 ./prep_dataset/ILSVRC2012_val_00022799.bin 224 224 +13068 ./prep_dataset/ILSVRC2012_val_00043975.bin 224 224 +13069 ./prep_dataset/ILSVRC2012_val_00037043.bin 224 224 +13070 ./prep_dataset/ILSVRC2012_val_00008351.bin 224 224 +13071 ./prep_dataset/ILSVRC2012_val_00038883.bin 224 224 +13072 ./prep_dataset/ILSVRC2012_val_00002322.bin 224 224 +13073 ./prep_dataset/ILSVRC2012_val_00042289.bin 224 224 +13074 ./prep_dataset/ILSVRC2012_val_00045333.bin 224 224 +13075 ./prep_dataset/ILSVRC2012_val_00023247.bin 224 224 +13076 ./prep_dataset/ILSVRC2012_val_00048455.bin 224 224 +13077 ./prep_dataset/ILSVRC2012_val_00036464.bin 224 224 +13078 ./prep_dataset/ILSVRC2012_val_00025358.bin 224 224 +13079 ./prep_dataset/ILSVRC2012_val_00002351.bin 224 224 +13080 ./prep_dataset/ILSVRC2012_val_00025593.bin 224 224 +13081 ./prep_dataset/ILSVRC2012_val_00046785.bin 224 224 +13082 ./prep_dataset/ILSVRC2012_val_00001346.bin 224 224 +13083 ./prep_dataset/ILSVRC2012_val_00002962.bin 224 224 +13084 ./prep_dataset/ILSVRC2012_val_00020289.bin 224 224 +13085 ./prep_dataset/ILSVRC2012_val_00023873.bin 224 224 +13086 ./prep_dataset/ILSVRC2012_val_00040467.bin 224 224 +13087 ./prep_dataset/ILSVRC2012_val_00040830.bin 224 224 +13088 ./prep_dataset/ILSVRC2012_val_00006650.bin 224 224 +13089 ./prep_dataset/ILSVRC2012_val_00041681.bin 224 224 +13090 ./prep_dataset/ILSVRC2012_val_00020260.bin 224 224 +13091 ./prep_dataset/ILSVRC2012_val_00017612.bin 224 224 +13092 ./prep_dataset/ILSVRC2012_val_00019495.bin 224 224 +13093 ./prep_dataset/ILSVRC2012_val_00017729.bin 224 224 +13094 ./prep_dataset/ILSVRC2012_val_00034805.bin 224 224 +13095 ./prep_dataset/ILSVRC2012_val_00028140.bin 224 224 +13096 ./prep_dataset/ILSVRC2012_val_00017533.bin 224 224 +13097 ./prep_dataset/ILSVRC2012_val_00007185.bin 224 224 +13098 ./prep_dataset/ILSVRC2012_val_00021731.bin 224 224 +13099 ./prep_dataset/ILSVRC2012_val_00013232.bin 224 224 +13100 ./prep_dataset/ILSVRC2012_val_00002515.bin 224 224 +13101 ./prep_dataset/ILSVRC2012_val_00011796.bin 224 224 +13102 ./prep_dataset/ILSVRC2012_val_00032703.bin 224 224 +13103 ./prep_dataset/ILSVRC2012_val_00003925.bin 224 224 +13104 ./prep_dataset/ILSVRC2012_val_00021183.bin 224 224 +13105 ./prep_dataset/ILSVRC2012_val_00002816.bin 224 224 +13106 ./prep_dataset/ILSVRC2012_val_00007756.bin 224 224 +13107 ./prep_dataset/ILSVRC2012_val_00036910.bin 224 224 +13108 ./prep_dataset/ILSVRC2012_val_00045303.bin 224 224 +13109 ./prep_dataset/ILSVRC2012_val_00015050.bin 224 224 +13110 ./prep_dataset/ILSVRC2012_val_00039907.bin 224 224 +13111 ./prep_dataset/ILSVRC2012_val_00036610.bin 224 224 +13112 ./prep_dataset/ILSVRC2012_val_00040349.bin 224 224 +13113 ./prep_dataset/ILSVRC2012_val_00013976.bin 224 224 +13114 ./prep_dataset/ILSVRC2012_val_00014761.bin 224 224 +13115 ./prep_dataset/ILSVRC2012_val_00049574.bin 224 224 +13116 ./prep_dataset/ILSVRC2012_val_00007428.bin 224 224 +13117 ./prep_dataset/ILSVRC2012_val_00037201.bin 224 224 +13118 ./prep_dataset/ILSVRC2012_val_00002519.bin 224 224 +13119 ./prep_dataset/ILSVRC2012_val_00024442.bin 224 224 +13120 ./prep_dataset/ILSVRC2012_val_00025220.bin 224 224 +13121 ./prep_dataset/ILSVRC2012_val_00023041.bin 224 224 +13122 ./prep_dataset/ILSVRC2012_val_00025983.bin 224 224 +13123 ./prep_dataset/ILSVRC2012_val_00040695.bin 224 224 +13124 ./prep_dataset/ILSVRC2012_val_00004278.bin 224 224 +13125 ./prep_dataset/ILSVRC2012_val_00022884.bin 224 224 +13126 ./prep_dataset/ILSVRC2012_val_00049995.bin 224 224 +13127 ./prep_dataset/ILSVRC2012_val_00005190.bin 224 224 +13128 ./prep_dataset/ILSVRC2012_val_00019622.bin 224 224 +13129 ./prep_dataset/ILSVRC2012_val_00011601.bin 224 224 +13130 ./prep_dataset/ILSVRC2012_val_00005028.bin 224 224 +13131 ./prep_dataset/ILSVRC2012_val_00019369.bin 224 224 +13132 ./prep_dataset/ILSVRC2012_val_00017633.bin 224 224 +13133 ./prep_dataset/ILSVRC2012_val_00044841.bin 224 224 +13134 ./prep_dataset/ILSVRC2012_val_00010441.bin 224 224 +13135 ./prep_dataset/ILSVRC2012_val_00046924.bin 224 224 +13136 ./prep_dataset/ILSVRC2012_val_00008190.bin 224 224 +13137 ./prep_dataset/ILSVRC2012_val_00034395.bin 224 224 +13138 ./prep_dataset/ILSVRC2012_val_00011142.bin 224 224 +13139 ./prep_dataset/ILSVRC2012_val_00020657.bin 224 224 +13140 ./prep_dataset/ILSVRC2012_val_00027332.bin 224 224 +13141 ./prep_dataset/ILSVRC2012_val_00041023.bin 224 224 +13142 ./prep_dataset/ILSVRC2012_val_00025739.bin 224 224 +13143 ./prep_dataset/ILSVRC2012_val_00042705.bin 224 224 +13144 ./prep_dataset/ILSVRC2012_val_00023413.bin 224 224 +13145 ./prep_dataset/ILSVRC2012_val_00041740.bin 224 224 +13146 ./prep_dataset/ILSVRC2012_val_00031866.bin 224 224 +13147 ./prep_dataset/ILSVRC2012_val_00015855.bin 224 224 +13148 ./prep_dataset/ILSVRC2012_val_00033466.bin 224 224 +13149 ./prep_dataset/ILSVRC2012_val_00037724.bin 224 224 +13150 ./prep_dataset/ILSVRC2012_val_00024862.bin 224 224 +13151 ./prep_dataset/ILSVRC2012_val_00014204.bin 224 224 +13152 ./prep_dataset/ILSVRC2012_val_00008784.bin 224 224 +13153 ./prep_dataset/ILSVRC2012_val_00025654.bin 224 224 +13154 ./prep_dataset/ILSVRC2012_val_00014804.bin 224 224 +13155 ./prep_dataset/ILSVRC2012_val_00008887.bin 224 224 +13156 ./prep_dataset/ILSVRC2012_val_00036084.bin 224 224 +13157 ./prep_dataset/ILSVRC2012_val_00045581.bin 224 224 +13158 ./prep_dataset/ILSVRC2012_val_00031580.bin 224 224 +13159 ./prep_dataset/ILSVRC2012_val_00021363.bin 224 224 +13160 ./prep_dataset/ILSVRC2012_val_00025902.bin 224 224 +13161 ./prep_dataset/ILSVRC2012_val_00046180.bin 224 224 +13162 ./prep_dataset/ILSVRC2012_val_00024375.bin 224 224 +13163 ./prep_dataset/ILSVRC2012_val_00010602.bin 224 224 +13164 ./prep_dataset/ILSVRC2012_val_00013750.bin 224 224 +13165 ./prep_dataset/ILSVRC2012_val_00025379.bin 224 224 +13166 ./prep_dataset/ILSVRC2012_val_00027741.bin 224 224 +13167 ./prep_dataset/ILSVRC2012_val_00028280.bin 224 224 +13168 ./prep_dataset/ILSVRC2012_val_00041863.bin 224 224 +13169 ./prep_dataset/ILSVRC2012_val_00047938.bin 224 224 +13170 ./prep_dataset/ILSVRC2012_val_00022087.bin 224 224 +13171 ./prep_dataset/ILSVRC2012_val_00013637.bin 224 224 +13172 ./prep_dataset/ILSVRC2012_val_00030337.bin 224 224 +13173 ./prep_dataset/ILSVRC2012_val_00019103.bin 224 224 +13174 ./prep_dataset/ILSVRC2012_val_00046507.bin 224 224 +13175 ./prep_dataset/ILSVRC2012_val_00035912.bin 224 224 +13176 ./prep_dataset/ILSVRC2012_val_00013979.bin 224 224 +13177 ./prep_dataset/ILSVRC2012_val_00042164.bin 224 224 +13178 ./prep_dataset/ILSVRC2012_val_00006363.bin 224 224 +13179 ./prep_dataset/ILSVRC2012_val_00048680.bin 224 224 +13180 ./prep_dataset/ILSVRC2012_val_00035650.bin 224 224 +13181 ./prep_dataset/ILSVRC2012_val_00018998.bin 224 224 +13182 ./prep_dataset/ILSVRC2012_val_00001167.bin 224 224 +13183 ./prep_dataset/ILSVRC2012_val_00006001.bin 224 224 +13184 ./prep_dataset/ILSVRC2012_val_00046201.bin 224 224 +13185 ./prep_dataset/ILSVRC2012_val_00002266.bin 224 224 +13186 ./prep_dataset/ILSVRC2012_val_00048598.bin 224 224 +13187 ./prep_dataset/ILSVRC2012_val_00015212.bin 224 224 +13188 ./prep_dataset/ILSVRC2012_val_00000633.bin 224 224 +13189 ./prep_dataset/ILSVRC2012_val_00015746.bin 224 224 +13190 ./prep_dataset/ILSVRC2012_val_00040359.bin 224 224 +13191 ./prep_dataset/ILSVRC2012_val_00038629.bin 224 224 +13192 ./prep_dataset/ILSVRC2012_val_00009429.bin 224 224 +13193 ./prep_dataset/ILSVRC2012_val_00036990.bin 224 224 +13194 ./prep_dataset/ILSVRC2012_val_00020926.bin 224 224 +13195 ./prep_dataset/ILSVRC2012_val_00033638.bin 224 224 +13196 ./prep_dataset/ILSVRC2012_val_00009503.bin 224 224 +13197 ./prep_dataset/ILSVRC2012_val_00030994.bin 224 224 +13198 ./prep_dataset/ILSVRC2012_val_00001685.bin 224 224 +13199 ./prep_dataset/ILSVRC2012_val_00026442.bin 224 224 +13200 ./prep_dataset/ILSVRC2012_val_00003939.bin 224 224 +13201 ./prep_dataset/ILSVRC2012_val_00025102.bin 224 224 +13202 ./prep_dataset/ILSVRC2012_val_00001959.bin 224 224 +13203 ./prep_dataset/ILSVRC2012_val_00007803.bin 224 224 +13204 ./prep_dataset/ILSVRC2012_val_00001708.bin 224 224 +13205 ./prep_dataset/ILSVRC2012_val_00039145.bin 224 224 +13206 ./prep_dataset/ILSVRC2012_val_00049179.bin 224 224 +13207 ./prep_dataset/ILSVRC2012_val_00045411.bin 224 224 +13208 ./prep_dataset/ILSVRC2012_val_00000693.bin 224 224 +13209 ./prep_dataset/ILSVRC2012_val_00009500.bin 224 224 +13210 ./prep_dataset/ILSVRC2012_val_00037228.bin 224 224 +13211 ./prep_dataset/ILSVRC2012_val_00035746.bin 224 224 +13212 ./prep_dataset/ILSVRC2012_val_00048251.bin 224 224 +13213 ./prep_dataset/ILSVRC2012_val_00032140.bin 224 224 +13214 ./prep_dataset/ILSVRC2012_val_00015521.bin 224 224 +13215 ./prep_dataset/ILSVRC2012_val_00003139.bin 224 224 +13216 ./prep_dataset/ILSVRC2012_val_00018228.bin 224 224 +13217 ./prep_dataset/ILSVRC2012_val_00006697.bin 224 224 +13218 ./prep_dataset/ILSVRC2012_val_00038371.bin 224 224 +13219 ./prep_dataset/ILSVRC2012_val_00024757.bin 224 224 +13220 ./prep_dataset/ILSVRC2012_val_00011521.bin 224 224 +13221 ./prep_dataset/ILSVRC2012_val_00043786.bin 224 224 +13222 ./prep_dataset/ILSVRC2012_val_00043261.bin 224 224 +13223 ./prep_dataset/ILSVRC2012_val_00006930.bin 224 224 +13224 ./prep_dataset/ILSVRC2012_val_00017587.bin 224 224 +13225 ./prep_dataset/ILSVRC2012_val_00026851.bin 224 224 +13226 ./prep_dataset/ILSVRC2012_val_00029652.bin 224 224 +13227 ./prep_dataset/ILSVRC2012_val_00007167.bin 224 224 +13228 ./prep_dataset/ILSVRC2012_val_00005126.bin 224 224 +13229 ./prep_dataset/ILSVRC2012_val_00007342.bin 224 224 +13230 ./prep_dataset/ILSVRC2012_val_00012537.bin 224 224 +13231 ./prep_dataset/ILSVRC2012_val_00014823.bin 224 224 +13232 ./prep_dataset/ILSVRC2012_val_00004625.bin 224 224 +13233 ./prep_dataset/ILSVRC2012_val_00046166.bin 224 224 +13234 ./prep_dataset/ILSVRC2012_val_00007641.bin 224 224 +13235 ./prep_dataset/ILSVRC2012_val_00005136.bin 224 224 +13236 ./prep_dataset/ILSVRC2012_val_00029515.bin 224 224 +13237 ./prep_dataset/ILSVRC2012_val_00048194.bin 224 224 +13238 ./prep_dataset/ILSVRC2012_val_00025657.bin 224 224 +13239 ./prep_dataset/ILSVRC2012_val_00019800.bin 224 224 +13240 ./prep_dataset/ILSVRC2012_val_00002856.bin 224 224 +13241 ./prep_dataset/ILSVRC2012_val_00041379.bin 224 224 +13242 ./prep_dataset/ILSVRC2012_val_00018438.bin 224 224 +13243 ./prep_dataset/ILSVRC2012_val_00041322.bin 224 224 +13244 ./prep_dataset/ILSVRC2012_val_00016781.bin 224 224 +13245 ./prep_dataset/ILSVRC2012_val_00023153.bin 224 224 +13246 ./prep_dataset/ILSVRC2012_val_00024196.bin 224 224 +13247 ./prep_dataset/ILSVRC2012_val_00043283.bin 224 224 +13248 ./prep_dataset/ILSVRC2012_val_00000209.bin 224 224 +13249 ./prep_dataset/ILSVRC2012_val_00040493.bin 224 224 +13250 ./prep_dataset/ILSVRC2012_val_00043505.bin 224 224 +13251 ./prep_dataset/ILSVRC2012_val_00043266.bin 224 224 +13252 ./prep_dataset/ILSVRC2012_val_00046410.bin 224 224 +13253 ./prep_dataset/ILSVRC2012_val_00049529.bin 224 224 +13254 ./prep_dataset/ILSVRC2012_val_00031857.bin 224 224 +13255 ./prep_dataset/ILSVRC2012_val_00047207.bin 224 224 +13256 ./prep_dataset/ILSVRC2012_val_00036001.bin 224 224 +13257 ./prep_dataset/ILSVRC2012_val_00047325.bin 224 224 +13258 ./prep_dataset/ILSVRC2012_val_00044473.bin 224 224 +13259 ./prep_dataset/ILSVRC2012_val_00023876.bin 224 224 +13260 ./prep_dataset/ILSVRC2012_val_00011396.bin 224 224 +13261 ./prep_dataset/ILSVRC2012_val_00014466.bin 224 224 +13262 ./prep_dataset/ILSVRC2012_val_00039144.bin 224 224 +13263 ./prep_dataset/ILSVRC2012_val_00020978.bin 224 224 +13264 ./prep_dataset/ILSVRC2012_val_00018999.bin 224 224 +13265 ./prep_dataset/ILSVRC2012_val_00037438.bin 224 224 +13266 ./prep_dataset/ILSVRC2012_val_00044719.bin 224 224 +13267 ./prep_dataset/ILSVRC2012_val_00004360.bin 224 224 +13268 ./prep_dataset/ILSVRC2012_val_00032877.bin 224 224 +13269 ./prep_dataset/ILSVRC2012_val_00046548.bin 224 224 +13270 ./prep_dataset/ILSVRC2012_val_00008789.bin 224 224 +13271 ./prep_dataset/ILSVRC2012_val_00022377.bin 224 224 +13272 ./prep_dataset/ILSVRC2012_val_00012921.bin 224 224 +13273 ./prep_dataset/ILSVRC2012_val_00029750.bin 224 224 +13274 ./prep_dataset/ILSVRC2012_val_00030519.bin 224 224 +13275 ./prep_dataset/ILSVRC2012_val_00039766.bin 224 224 +13276 ./prep_dataset/ILSVRC2012_val_00041028.bin 224 224 +13277 ./prep_dataset/ILSVRC2012_val_00028053.bin 224 224 +13278 ./prep_dataset/ILSVRC2012_val_00034322.bin 224 224 +13279 ./prep_dataset/ILSVRC2012_val_00001849.bin 224 224 +13280 ./prep_dataset/ILSVRC2012_val_00034588.bin 224 224 +13281 ./prep_dataset/ILSVRC2012_val_00014757.bin 224 224 +13282 ./prep_dataset/ILSVRC2012_val_00040317.bin 224 224 +13283 ./prep_dataset/ILSVRC2012_val_00023705.bin 224 224 +13284 ./prep_dataset/ILSVRC2012_val_00007225.bin 224 224 +13285 ./prep_dataset/ILSVRC2012_val_00048256.bin 224 224 +13286 ./prep_dataset/ILSVRC2012_val_00032990.bin 224 224 +13287 ./prep_dataset/ILSVRC2012_val_00038267.bin 224 224 +13288 ./prep_dataset/ILSVRC2012_val_00036451.bin 224 224 +13289 ./prep_dataset/ILSVRC2012_val_00042760.bin 224 224 +13290 ./prep_dataset/ILSVRC2012_val_00027666.bin 224 224 +13291 ./prep_dataset/ILSVRC2012_val_00022659.bin 224 224 +13292 ./prep_dataset/ILSVRC2012_val_00047728.bin 224 224 +13293 ./prep_dataset/ILSVRC2012_val_00020467.bin 224 224 +13294 ./prep_dataset/ILSVRC2012_val_00042244.bin 224 224 +13295 ./prep_dataset/ILSVRC2012_val_00036362.bin 224 224 +13296 ./prep_dataset/ILSVRC2012_val_00022469.bin 224 224 +13297 ./prep_dataset/ILSVRC2012_val_00043274.bin 224 224 +13298 ./prep_dataset/ILSVRC2012_val_00010113.bin 224 224 +13299 ./prep_dataset/ILSVRC2012_val_00023498.bin 224 224 +13300 ./prep_dataset/ILSVRC2012_val_00026487.bin 224 224 +13301 ./prep_dataset/ILSVRC2012_val_00003563.bin 224 224 +13302 ./prep_dataset/ILSVRC2012_val_00045250.bin 224 224 +13303 ./prep_dataset/ILSVRC2012_val_00032406.bin 224 224 +13304 ./prep_dataset/ILSVRC2012_val_00006721.bin 224 224 +13305 ./prep_dataset/ILSVRC2012_val_00003644.bin 224 224 +13306 ./prep_dataset/ILSVRC2012_val_00023997.bin 224 224 +13307 ./prep_dataset/ILSVRC2012_val_00025527.bin 224 224 +13308 ./prep_dataset/ILSVRC2012_val_00036146.bin 224 224 +13309 ./prep_dataset/ILSVRC2012_val_00030996.bin 224 224 +13310 ./prep_dataset/ILSVRC2012_val_00026205.bin 224 224 +13311 ./prep_dataset/ILSVRC2012_val_00038385.bin 224 224 +13312 ./prep_dataset/ILSVRC2012_val_00042592.bin 224 224 +13313 ./prep_dataset/ILSVRC2012_val_00038226.bin 224 224 +13314 ./prep_dataset/ILSVRC2012_val_00045771.bin 224 224 +13315 ./prep_dataset/ILSVRC2012_val_00032215.bin 224 224 +13316 ./prep_dataset/ILSVRC2012_val_00014206.bin 224 224 +13317 ./prep_dataset/ILSVRC2012_val_00006448.bin 224 224 +13318 ./prep_dataset/ILSVRC2012_val_00000186.bin 224 224 +13319 ./prep_dataset/ILSVRC2012_val_00028352.bin 224 224 +13320 ./prep_dataset/ILSVRC2012_val_00040869.bin 224 224 +13321 ./prep_dataset/ILSVRC2012_val_00032979.bin 224 224 +13322 ./prep_dataset/ILSVRC2012_val_00026773.bin 224 224 +13323 ./prep_dataset/ILSVRC2012_val_00001068.bin 224 224 +13324 ./prep_dataset/ILSVRC2012_val_00000472.bin 224 224 +13325 ./prep_dataset/ILSVRC2012_val_00010077.bin 224 224 +13326 ./prep_dataset/ILSVRC2012_val_00048082.bin 224 224 +13327 ./prep_dataset/ILSVRC2012_val_00047085.bin 224 224 +13328 ./prep_dataset/ILSVRC2012_val_00000510.bin 224 224 +13329 ./prep_dataset/ILSVRC2012_val_00041110.bin 224 224 +13330 ./prep_dataset/ILSVRC2012_val_00019428.bin 224 224 +13331 ./prep_dataset/ILSVRC2012_val_00027093.bin 224 224 +13332 ./prep_dataset/ILSVRC2012_val_00000212.bin 224 224 +13333 ./prep_dataset/ILSVRC2012_val_00009830.bin 224 224 +13334 ./prep_dataset/ILSVRC2012_val_00016274.bin 224 224 +13335 ./prep_dataset/ILSVRC2012_val_00007122.bin 224 224 +13336 ./prep_dataset/ILSVRC2012_val_00002787.bin 224 224 +13337 ./prep_dataset/ILSVRC2012_val_00034520.bin 224 224 +13338 ./prep_dataset/ILSVRC2012_val_00007211.bin 224 224 +13339 ./prep_dataset/ILSVRC2012_val_00019594.bin 224 224 +13340 ./prep_dataset/ILSVRC2012_val_00001375.bin 224 224 +13341 ./prep_dataset/ILSVRC2012_val_00024132.bin 224 224 +13342 ./prep_dataset/ILSVRC2012_val_00026428.bin 224 224 +13343 ./prep_dataset/ILSVRC2012_val_00011971.bin 224 224 +13344 ./prep_dataset/ILSVRC2012_val_00045662.bin 224 224 +13345 ./prep_dataset/ILSVRC2012_val_00001101.bin 224 224 +13346 ./prep_dataset/ILSVRC2012_val_00004146.bin 224 224 +13347 ./prep_dataset/ILSVRC2012_val_00008173.bin 224 224 +13348 ./prep_dataset/ILSVRC2012_val_00044116.bin 224 224 +13349 ./prep_dataset/ILSVRC2012_val_00011367.bin 224 224 +13350 ./prep_dataset/ILSVRC2012_val_00014928.bin 224 224 +13351 ./prep_dataset/ILSVRC2012_val_00025189.bin 224 224 +13352 ./prep_dataset/ILSVRC2012_val_00026499.bin 224 224 +13353 ./prep_dataset/ILSVRC2012_val_00007441.bin 224 224 +13354 ./prep_dataset/ILSVRC2012_val_00044659.bin 224 224 +13355 ./prep_dataset/ILSVRC2012_val_00019584.bin 224 224 +13356 ./prep_dataset/ILSVRC2012_val_00030907.bin 224 224 +13357 ./prep_dataset/ILSVRC2012_val_00001938.bin 224 224 +13358 ./prep_dataset/ILSVRC2012_val_00002409.bin 224 224 +13359 ./prep_dataset/ILSVRC2012_val_00005392.bin 224 224 +13360 ./prep_dataset/ILSVRC2012_val_00028661.bin 224 224 +13361 ./prep_dataset/ILSVRC2012_val_00018759.bin 224 224 +13362 ./prep_dataset/ILSVRC2012_val_00043568.bin 224 224 +13363 ./prep_dataset/ILSVRC2012_val_00000211.bin 224 224 +13364 ./prep_dataset/ILSVRC2012_val_00044436.bin 224 224 +13365 ./prep_dataset/ILSVRC2012_val_00014502.bin 224 224 +13366 ./prep_dataset/ILSVRC2012_val_00030065.bin 224 224 +13367 ./prep_dataset/ILSVRC2012_val_00007327.bin 224 224 +13368 ./prep_dataset/ILSVRC2012_val_00018613.bin 224 224 +13369 ./prep_dataset/ILSVRC2012_val_00032330.bin 224 224 +13370 ./prep_dataset/ILSVRC2012_val_00046181.bin 224 224 +13371 ./prep_dataset/ILSVRC2012_val_00045417.bin 224 224 +13372 ./prep_dataset/ILSVRC2012_val_00002163.bin 224 224 +13373 ./prep_dataset/ILSVRC2012_val_00015111.bin 224 224 +13374 ./prep_dataset/ILSVRC2012_val_00002564.bin 224 224 +13375 ./prep_dataset/ILSVRC2012_val_00018616.bin 224 224 +13376 ./prep_dataset/ILSVRC2012_val_00011967.bin 224 224 +13377 ./prep_dataset/ILSVRC2012_val_00041658.bin 224 224 +13378 ./prep_dataset/ILSVRC2012_val_00017660.bin 224 224 +13379 ./prep_dataset/ILSVRC2012_val_00012562.bin 224 224 +13380 ./prep_dataset/ILSVRC2012_val_00004098.bin 224 224 +13381 ./prep_dataset/ILSVRC2012_val_00002656.bin 224 224 +13382 ./prep_dataset/ILSVRC2012_val_00024133.bin 224 224 +13383 ./prep_dataset/ILSVRC2012_val_00028043.bin 224 224 +13384 ./prep_dataset/ILSVRC2012_val_00039652.bin 224 224 +13385 ./prep_dataset/ILSVRC2012_val_00015277.bin 224 224 +13386 ./prep_dataset/ILSVRC2012_val_00018172.bin 224 224 +13387 ./prep_dataset/ILSVRC2012_val_00047249.bin 224 224 +13388 ./prep_dataset/ILSVRC2012_val_00015819.bin 224 224 +13389 ./prep_dataset/ILSVRC2012_val_00012446.bin 224 224 +13390 ./prep_dataset/ILSVRC2012_val_00031602.bin 224 224 +13391 ./prep_dataset/ILSVRC2012_val_00044164.bin 224 224 +13392 ./prep_dataset/ILSVRC2012_val_00000149.bin 224 224 +13393 ./prep_dataset/ILSVRC2012_val_00044121.bin 224 224 +13394 ./prep_dataset/ILSVRC2012_val_00045905.bin 224 224 +13395 ./prep_dataset/ILSVRC2012_val_00028837.bin 224 224 +13396 ./prep_dataset/ILSVRC2012_val_00017693.bin 224 224 +13397 ./prep_dataset/ILSVRC2012_val_00030503.bin 224 224 +13398 ./prep_dataset/ILSVRC2012_val_00033113.bin 224 224 +13399 ./prep_dataset/ILSVRC2012_val_00008323.bin 224 224 +13400 ./prep_dataset/ILSVRC2012_val_00039597.bin 224 224 +13401 ./prep_dataset/ILSVRC2012_val_00026251.bin 224 224 +13402 ./prep_dataset/ILSVRC2012_val_00048632.bin 224 224 +13403 ./prep_dataset/ILSVRC2012_val_00045974.bin 224 224 +13404 ./prep_dataset/ILSVRC2012_val_00040488.bin 224 224 +13405 ./prep_dataset/ILSVRC2012_val_00031324.bin 224 224 +13406 ./prep_dataset/ILSVRC2012_val_00025703.bin 224 224 +13407 ./prep_dataset/ILSVRC2012_val_00041779.bin 224 224 +13408 ./prep_dataset/ILSVRC2012_val_00035702.bin 224 224 +13409 ./prep_dataset/ILSVRC2012_val_00018483.bin 224 224 +13410 ./prep_dataset/ILSVRC2012_val_00044303.bin 224 224 +13411 ./prep_dataset/ILSVRC2012_val_00023995.bin 224 224 +13412 ./prep_dataset/ILSVRC2012_val_00003499.bin 224 224 +13413 ./prep_dataset/ILSVRC2012_val_00025815.bin 224 224 +13414 ./prep_dataset/ILSVRC2012_val_00000031.bin 224 224 +13415 ./prep_dataset/ILSVRC2012_val_00034639.bin 224 224 +13416 ./prep_dataset/ILSVRC2012_val_00049325.bin 224 224 +13417 ./prep_dataset/ILSVRC2012_val_00049150.bin 224 224 +13418 ./prep_dataset/ILSVRC2012_val_00029486.bin 224 224 +13419 ./prep_dataset/ILSVRC2012_val_00036281.bin 224 224 +13420 ./prep_dataset/ILSVRC2012_val_00026781.bin 224 224 +13421 ./prep_dataset/ILSVRC2012_val_00020611.bin 224 224 +13422 ./prep_dataset/ILSVRC2012_val_00009062.bin 224 224 +13423 ./prep_dataset/ILSVRC2012_val_00002898.bin 224 224 +13424 ./prep_dataset/ILSVRC2012_val_00040621.bin 224 224 +13425 ./prep_dataset/ILSVRC2012_val_00001974.bin 224 224 +13426 ./prep_dataset/ILSVRC2012_val_00046169.bin 224 224 +13427 ./prep_dataset/ILSVRC2012_val_00036744.bin 224 224 +13428 ./prep_dataset/ILSVRC2012_val_00023932.bin 224 224 +13429 ./prep_dataset/ILSVRC2012_val_00006939.bin 224 224 +13430 ./prep_dataset/ILSVRC2012_val_00016371.bin 224 224 +13431 ./prep_dataset/ILSVRC2012_val_00040453.bin 224 224 +13432 ./prep_dataset/ILSVRC2012_val_00042069.bin 224 224 +13433 ./prep_dataset/ILSVRC2012_val_00021593.bin 224 224 +13434 ./prep_dataset/ILSVRC2012_val_00014664.bin 224 224 +13435 ./prep_dataset/ILSVRC2012_val_00044924.bin 224 224 +13436 ./prep_dataset/ILSVRC2012_val_00030180.bin 224 224 +13437 ./prep_dataset/ILSVRC2012_val_00039749.bin 224 224 +13438 ./prep_dataset/ILSVRC2012_val_00001734.bin 224 224 +13439 ./prep_dataset/ILSVRC2012_val_00010594.bin 224 224 +13440 ./prep_dataset/ILSVRC2012_val_00018327.bin 224 224 +13441 ./prep_dataset/ILSVRC2012_val_00010515.bin 224 224 +13442 ./prep_dataset/ILSVRC2012_val_00013231.bin 224 224 +13443 ./prep_dataset/ILSVRC2012_val_00026703.bin 224 224 +13444 ./prep_dataset/ILSVRC2012_val_00043144.bin 224 224 +13445 ./prep_dataset/ILSVRC2012_val_00014368.bin 224 224 +13446 ./prep_dataset/ILSVRC2012_val_00007525.bin 224 224 +13447 ./prep_dataset/ILSVRC2012_val_00041599.bin 224 224 +13448 ./prep_dataset/ILSVRC2012_val_00028195.bin 224 224 +13449 ./prep_dataset/ILSVRC2012_val_00040698.bin 224 224 +13450 ./prep_dataset/ILSVRC2012_val_00026275.bin 224 224 +13451 ./prep_dataset/ILSVRC2012_val_00016757.bin 224 224 +13452 ./prep_dataset/ILSVRC2012_val_00014805.bin 224 224 +13453 ./prep_dataset/ILSVRC2012_val_00028080.bin 224 224 +13454 ./prep_dataset/ILSVRC2012_val_00028171.bin 224 224 +13455 ./prep_dataset/ILSVRC2012_val_00035143.bin 224 224 +13456 ./prep_dataset/ILSVRC2012_val_00007463.bin 224 224 +13457 ./prep_dataset/ILSVRC2012_val_00013771.bin 224 224 +13458 ./prep_dataset/ILSVRC2012_val_00029983.bin 224 224 +13459 ./prep_dataset/ILSVRC2012_val_00015699.bin 224 224 +13460 ./prep_dataset/ILSVRC2012_val_00042385.bin 224 224 +13461 ./prep_dataset/ILSVRC2012_val_00033728.bin 224 224 +13462 ./prep_dataset/ILSVRC2012_val_00027207.bin 224 224 +13463 ./prep_dataset/ILSVRC2012_val_00011474.bin 224 224 +13464 ./prep_dataset/ILSVRC2012_val_00022834.bin 224 224 +13465 ./prep_dataset/ILSVRC2012_val_00000950.bin 224 224 +13466 ./prep_dataset/ILSVRC2012_val_00025330.bin 224 224 +13467 ./prep_dataset/ILSVRC2012_val_00031532.bin 224 224 +13468 ./prep_dataset/ILSVRC2012_val_00036882.bin 224 224 +13469 ./prep_dataset/ILSVRC2012_val_00018594.bin 224 224 +13470 ./prep_dataset/ILSVRC2012_val_00015351.bin 224 224 +13471 ./prep_dataset/ILSVRC2012_val_00037706.bin 224 224 +13472 ./prep_dataset/ILSVRC2012_val_00022438.bin 224 224 +13473 ./prep_dataset/ILSVRC2012_val_00034514.bin 224 224 +13474 ./prep_dataset/ILSVRC2012_val_00004644.bin 224 224 +13475 ./prep_dataset/ILSVRC2012_val_00040164.bin 224 224 +13476 ./prep_dataset/ILSVRC2012_val_00018859.bin 224 224 +13477 ./prep_dataset/ILSVRC2012_val_00031544.bin 224 224 +13478 ./prep_dataset/ILSVRC2012_val_00004793.bin 224 224 +13479 ./prep_dataset/ILSVRC2012_val_00005579.bin 224 224 +13480 ./prep_dataset/ILSVRC2012_val_00045506.bin 224 224 +13481 ./prep_dataset/ILSVRC2012_val_00008112.bin 224 224 +13482 ./prep_dataset/ILSVRC2012_val_00010572.bin 224 224 +13483 ./prep_dataset/ILSVRC2012_val_00015207.bin 224 224 +13484 ./prep_dataset/ILSVRC2012_val_00004099.bin 224 224 +13485 ./prep_dataset/ILSVRC2012_val_00035875.bin 224 224 +13486 ./prep_dataset/ILSVRC2012_val_00024570.bin 224 224 +13487 ./prep_dataset/ILSVRC2012_val_00032817.bin 224 224 +13488 ./prep_dataset/ILSVRC2012_val_00018416.bin 224 224 +13489 ./prep_dataset/ILSVRC2012_val_00036580.bin 224 224 +13490 ./prep_dataset/ILSVRC2012_val_00023461.bin 224 224 +13491 ./prep_dataset/ILSVRC2012_val_00004179.bin 224 224 +13492 ./prep_dataset/ILSVRC2012_val_00021410.bin 224 224 +13493 ./prep_dataset/ILSVRC2012_val_00047226.bin 224 224 +13494 ./prep_dataset/ILSVRC2012_val_00021824.bin 224 224 +13495 ./prep_dataset/ILSVRC2012_val_00002563.bin 224 224 +13496 ./prep_dataset/ILSVRC2012_val_00010756.bin 224 224 +13497 ./prep_dataset/ILSVRC2012_val_00019673.bin 224 224 +13498 ./prep_dataset/ILSVRC2012_val_00048779.bin 224 224 +13499 ./prep_dataset/ILSVRC2012_val_00021974.bin 224 224 +13500 ./prep_dataset/ILSVRC2012_val_00010442.bin 224 224 +13501 ./prep_dataset/ILSVRC2012_val_00026980.bin 224 224 +13502 ./prep_dataset/ILSVRC2012_val_00021127.bin 224 224 +13503 ./prep_dataset/ILSVRC2012_val_00005560.bin 224 224 +13504 ./prep_dataset/ILSVRC2012_val_00046740.bin 224 224 +13505 ./prep_dataset/ILSVRC2012_val_00007624.bin 224 224 +13506 ./prep_dataset/ILSVRC2012_val_00013103.bin 224 224 +13507 ./prep_dataset/ILSVRC2012_val_00018084.bin 224 224 +13508 ./prep_dataset/ILSVRC2012_val_00047457.bin 224 224 +13509 ./prep_dataset/ILSVRC2012_val_00010173.bin 224 224 +13510 ./prep_dataset/ILSVRC2012_val_00000883.bin 224 224 +13511 ./prep_dataset/ILSVRC2012_val_00025955.bin 224 224 +13512 ./prep_dataset/ILSVRC2012_val_00042120.bin 224 224 +13513 ./prep_dataset/ILSVRC2012_val_00012601.bin 224 224 +13514 ./prep_dataset/ILSVRC2012_val_00010005.bin 224 224 +13515 ./prep_dataset/ILSVRC2012_val_00035915.bin 224 224 +13516 ./prep_dataset/ILSVRC2012_val_00003769.bin 224 224 +13517 ./prep_dataset/ILSVRC2012_val_00044898.bin 224 224 +13518 ./prep_dataset/ILSVRC2012_val_00016132.bin 224 224 +13519 ./prep_dataset/ILSVRC2012_val_00016384.bin 224 224 +13520 ./prep_dataset/ILSVRC2012_val_00017907.bin 224 224 +13521 ./prep_dataset/ILSVRC2012_val_00049465.bin 224 224 +13522 ./prep_dataset/ILSVRC2012_val_00029945.bin 224 224 +13523 ./prep_dataset/ILSVRC2012_val_00009012.bin 224 224 +13524 ./prep_dataset/ILSVRC2012_val_00017911.bin 224 224 +13525 ./prep_dataset/ILSVRC2012_val_00035374.bin 224 224 +13526 ./prep_dataset/ILSVRC2012_val_00046701.bin 224 224 +13527 ./prep_dataset/ILSVRC2012_val_00048770.bin 224 224 +13528 ./prep_dataset/ILSVRC2012_val_00046682.bin 224 224 +13529 ./prep_dataset/ILSVRC2012_val_00044532.bin 224 224 +13530 ./prep_dataset/ILSVRC2012_val_00014431.bin 224 224 +13531 ./prep_dataset/ILSVRC2012_val_00042138.bin 224 224 +13532 ./prep_dataset/ILSVRC2012_val_00009521.bin 224 224 +13533 ./prep_dataset/ILSVRC2012_val_00036340.bin 224 224 +13534 ./prep_dataset/ILSVRC2012_val_00004755.bin 224 224 +13535 ./prep_dataset/ILSVRC2012_val_00001223.bin 224 224 +13536 ./prep_dataset/ILSVRC2012_val_00003705.bin 224 224 +13537 ./prep_dataset/ILSVRC2012_val_00030059.bin 224 224 +13538 ./prep_dataset/ILSVRC2012_val_00042065.bin 224 224 +13539 ./prep_dataset/ILSVRC2012_val_00031916.bin 224 224 +13540 ./prep_dataset/ILSVRC2012_val_00032230.bin 224 224 +13541 ./prep_dataset/ILSVRC2012_val_00014535.bin 224 224 +13542 ./prep_dataset/ILSVRC2012_val_00016237.bin 224 224 +13543 ./prep_dataset/ILSVRC2012_val_00035599.bin 224 224 +13544 ./prep_dataset/ILSVRC2012_val_00046845.bin 224 224 +13545 ./prep_dataset/ILSVRC2012_val_00033274.bin 224 224 +13546 ./prep_dataset/ILSVRC2012_val_00015138.bin 224 224 +13547 ./prep_dataset/ILSVRC2012_val_00035700.bin 224 224 +13548 ./prep_dataset/ILSVRC2012_val_00040097.bin 224 224 +13549 ./prep_dataset/ILSVRC2012_val_00042070.bin 224 224 +13550 ./prep_dataset/ILSVRC2012_val_00045150.bin 224 224 +13551 ./prep_dataset/ILSVRC2012_val_00037599.bin 224 224 +13552 ./prep_dataset/ILSVRC2012_val_00007670.bin 224 224 +13553 ./prep_dataset/ILSVRC2012_val_00044499.bin 224 224 +13554 ./prep_dataset/ILSVRC2012_val_00044736.bin 224 224 +13555 ./prep_dataset/ILSVRC2012_val_00044796.bin 224 224 +13556 ./prep_dataset/ILSVRC2012_val_00046844.bin 224 224 +13557 ./prep_dataset/ILSVRC2012_val_00026963.bin 224 224 +13558 ./prep_dataset/ILSVRC2012_val_00043397.bin 224 224 +13559 ./prep_dataset/ILSVRC2012_val_00049932.bin 224 224 +13560 ./prep_dataset/ILSVRC2012_val_00005232.bin 224 224 +13561 ./prep_dataset/ILSVRC2012_val_00000964.bin 224 224 +13562 ./prep_dataset/ILSVRC2012_val_00006965.bin 224 224 +13563 ./prep_dataset/ILSVRC2012_val_00002010.bin 224 224 +13564 ./prep_dataset/ILSVRC2012_val_00000094.bin 224 224 +13565 ./prep_dataset/ILSVRC2012_val_00040010.bin 224 224 +13566 ./prep_dataset/ILSVRC2012_val_00020049.bin 224 224 +13567 ./prep_dataset/ILSVRC2012_val_00044634.bin 224 224 +13568 ./prep_dataset/ILSVRC2012_val_00023805.bin 224 224 +13569 ./prep_dataset/ILSVRC2012_val_00040531.bin 224 224 +13570 ./prep_dataset/ILSVRC2012_val_00001544.bin 224 224 +13571 ./prep_dataset/ILSVRC2012_val_00008791.bin 224 224 +13572 ./prep_dataset/ILSVRC2012_val_00030045.bin 224 224 +13573 ./prep_dataset/ILSVRC2012_val_00034220.bin 224 224 +13574 ./prep_dataset/ILSVRC2012_val_00005991.bin 224 224 +13575 ./prep_dataset/ILSVRC2012_val_00048452.bin 224 224 +13576 ./prep_dataset/ILSVRC2012_val_00005270.bin 224 224 +13577 ./prep_dataset/ILSVRC2012_val_00017821.bin 224 224 +13578 ./prep_dataset/ILSVRC2012_val_00031910.bin 224 224 +13579 ./prep_dataset/ILSVRC2012_val_00009771.bin 224 224 +13580 ./prep_dataset/ILSVRC2012_val_00000299.bin 224 224 +13581 ./prep_dataset/ILSVRC2012_val_00002951.bin 224 224 +13582 ./prep_dataset/ILSVRC2012_val_00014776.bin 224 224 +13583 ./prep_dataset/ILSVRC2012_val_00011830.bin 224 224 +13584 ./prep_dataset/ILSVRC2012_val_00010765.bin 224 224 +13585 ./prep_dataset/ILSVRC2012_val_00023025.bin 224 224 +13586 ./prep_dataset/ILSVRC2012_val_00026125.bin 224 224 +13587 ./prep_dataset/ILSVRC2012_val_00011707.bin 224 224 +13588 ./prep_dataset/ILSVRC2012_val_00015282.bin 224 224 +13589 ./prep_dataset/ILSVRC2012_val_00042223.bin 224 224 +13590 ./prep_dataset/ILSVRC2012_val_00048428.bin 224 224 +13591 ./prep_dataset/ILSVRC2012_val_00016256.bin 224 224 +13592 ./prep_dataset/ILSVRC2012_val_00024305.bin 224 224 +13593 ./prep_dataset/ILSVRC2012_val_00043062.bin 224 224 +13594 ./prep_dataset/ILSVRC2012_val_00014689.bin 224 224 +13595 ./prep_dataset/ILSVRC2012_val_00043178.bin 224 224 +13596 ./prep_dataset/ILSVRC2012_val_00048262.bin 224 224 +13597 ./prep_dataset/ILSVRC2012_val_00014355.bin 224 224 +13598 ./prep_dataset/ILSVRC2012_val_00030505.bin 224 224 +13599 ./prep_dataset/ILSVRC2012_val_00019445.bin 224 224 +13600 ./prep_dataset/ILSVRC2012_val_00018948.bin 224 224 +13601 ./prep_dataset/ILSVRC2012_val_00019838.bin 224 224 +13602 ./prep_dataset/ILSVRC2012_val_00002706.bin 224 224 +13603 ./prep_dataset/ILSVRC2012_val_00014476.bin 224 224 +13604 ./prep_dataset/ILSVRC2012_val_00033470.bin 224 224 +13605 ./prep_dataset/ILSVRC2012_val_00001503.bin 224 224 +13606 ./prep_dataset/ILSVRC2012_val_00028627.bin 224 224 +13607 ./prep_dataset/ILSVRC2012_val_00009976.bin 224 224 +13608 ./prep_dataset/ILSVRC2012_val_00040921.bin 224 224 +13609 ./prep_dataset/ILSVRC2012_val_00015456.bin 224 224 +13610 ./prep_dataset/ILSVRC2012_val_00038835.bin 224 224 +13611 ./prep_dataset/ILSVRC2012_val_00003761.bin 224 224 +13612 ./prep_dataset/ILSVRC2012_val_00029910.bin 224 224 +13613 ./prep_dataset/ILSVRC2012_val_00049327.bin 224 224 +13614 ./prep_dataset/ILSVRC2012_val_00007250.bin 224 224 +13615 ./prep_dataset/ILSVRC2012_val_00028658.bin 224 224 +13616 ./prep_dataset/ILSVRC2012_val_00045879.bin 224 224 +13617 ./prep_dataset/ILSVRC2012_val_00026835.bin 224 224 +13618 ./prep_dataset/ILSVRC2012_val_00048848.bin 224 224 +13619 ./prep_dataset/ILSVRC2012_val_00016855.bin 224 224 +13620 ./prep_dataset/ILSVRC2012_val_00046960.bin 224 224 +13621 ./prep_dataset/ILSVRC2012_val_00000952.bin 224 224 +13622 ./prep_dataset/ILSVRC2012_val_00041100.bin 224 224 +13623 ./prep_dataset/ILSVRC2012_val_00019360.bin 224 224 +13624 ./prep_dataset/ILSVRC2012_val_00039391.bin 224 224 +13625 ./prep_dataset/ILSVRC2012_val_00012353.bin 224 224 +13626 ./prep_dataset/ILSVRC2012_val_00022080.bin 224 224 +13627 ./prep_dataset/ILSVRC2012_val_00020899.bin 224 224 +13628 ./prep_dataset/ILSVRC2012_val_00042757.bin 224 224 +13629 ./prep_dataset/ILSVRC2012_val_00037931.bin 224 224 +13630 ./prep_dataset/ILSVRC2012_val_00008617.bin 224 224 +13631 ./prep_dataset/ILSVRC2012_val_00027076.bin 224 224 +13632 ./prep_dataset/ILSVRC2012_val_00021656.bin 224 224 +13633 ./prep_dataset/ILSVRC2012_val_00006725.bin 224 224 +13634 ./prep_dataset/ILSVRC2012_val_00036032.bin 224 224 +13635 ./prep_dataset/ILSVRC2012_val_00035323.bin 224 224 +13636 ./prep_dataset/ILSVRC2012_val_00020192.bin 224 224 +13637 ./prep_dataset/ILSVRC2012_val_00012616.bin 224 224 +13638 ./prep_dataset/ILSVRC2012_val_00005259.bin 224 224 +13639 ./prep_dataset/ILSVRC2012_val_00039669.bin 224 224 +13640 ./prep_dataset/ILSVRC2012_val_00020695.bin 224 224 +13641 ./prep_dataset/ILSVRC2012_val_00042158.bin 224 224 +13642 ./prep_dataset/ILSVRC2012_val_00036370.bin 224 224 +13643 ./prep_dataset/ILSVRC2012_val_00040339.bin 224 224 +13644 ./prep_dataset/ILSVRC2012_val_00026531.bin 224 224 +13645 ./prep_dataset/ILSVRC2012_val_00005816.bin 224 224 +13646 ./prep_dataset/ILSVRC2012_val_00005925.bin 224 224 +13647 ./prep_dataset/ILSVRC2012_val_00049086.bin 224 224 +13648 ./prep_dataset/ILSVRC2012_val_00016424.bin 224 224 +13649 ./prep_dataset/ILSVRC2012_val_00042014.bin 224 224 +13650 ./prep_dataset/ILSVRC2012_val_00032173.bin 224 224 +13651 ./prep_dataset/ILSVRC2012_val_00037320.bin 224 224 +13652 ./prep_dataset/ILSVRC2012_val_00012113.bin 224 224 +13653 ./prep_dataset/ILSVRC2012_val_00015466.bin 224 224 +13654 ./prep_dataset/ILSVRC2012_val_00028717.bin 224 224 +13655 ./prep_dataset/ILSVRC2012_val_00005614.bin 224 224 +13656 ./prep_dataset/ILSVRC2012_val_00022306.bin 224 224 +13657 ./prep_dataset/ILSVRC2012_val_00043544.bin 224 224 +13658 ./prep_dataset/ILSVRC2012_val_00014605.bin 224 224 +13659 ./prep_dataset/ILSVRC2012_val_00022413.bin 224 224 +13660 ./prep_dataset/ILSVRC2012_val_00049887.bin 224 224 +13661 ./prep_dataset/ILSVRC2012_val_00003258.bin 224 224 +13662 ./prep_dataset/ILSVRC2012_val_00025989.bin 224 224 +13663 ./prep_dataset/ILSVRC2012_val_00020403.bin 224 224 +13664 ./prep_dataset/ILSVRC2012_val_00007518.bin 224 224 +13665 ./prep_dataset/ILSVRC2012_val_00031899.bin 224 224 +13666 ./prep_dataset/ILSVRC2012_val_00016643.bin 224 224 +13667 ./prep_dataset/ILSVRC2012_val_00024790.bin 224 224 +13668 ./prep_dataset/ILSVRC2012_val_00033869.bin 224 224 +13669 ./prep_dataset/ILSVRC2012_val_00032254.bin 224 224 +13670 ./prep_dataset/ILSVRC2012_val_00016340.bin 224 224 +13671 ./prep_dataset/ILSVRC2012_val_00022458.bin 224 224 +13672 ./prep_dataset/ILSVRC2012_val_00018185.bin 224 224 +13673 ./prep_dataset/ILSVRC2012_val_00033576.bin 224 224 +13674 ./prep_dataset/ILSVRC2012_val_00007607.bin 224 224 +13675 ./prep_dataset/ILSVRC2012_val_00035488.bin 224 224 +13676 ./prep_dataset/ILSVRC2012_val_00047725.bin 224 224 +13677 ./prep_dataset/ILSVRC2012_val_00037009.bin 224 224 +13678 ./prep_dataset/ILSVRC2012_val_00045244.bin 224 224 +13679 ./prep_dataset/ILSVRC2012_val_00043826.bin 224 224 +13680 ./prep_dataset/ILSVRC2012_val_00033914.bin 224 224 +13681 ./prep_dataset/ILSVRC2012_val_00006679.bin 224 224 +13682 ./prep_dataset/ILSVRC2012_val_00016462.bin 224 224 +13683 ./prep_dataset/ILSVRC2012_val_00034700.bin 224 224 +13684 ./prep_dataset/ILSVRC2012_val_00034459.bin 224 224 +13685 ./prep_dataset/ILSVRC2012_val_00009699.bin 224 224 +13686 ./prep_dataset/ILSVRC2012_val_00032251.bin 224 224 +13687 ./prep_dataset/ILSVRC2012_val_00037896.bin 224 224 +13688 ./prep_dataset/ILSVRC2012_val_00029668.bin 224 224 +13689 ./prep_dataset/ILSVRC2012_val_00027659.bin 224 224 +13690 ./prep_dataset/ILSVRC2012_val_00044087.bin 224 224 +13691 ./prep_dataset/ILSVRC2012_val_00031681.bin 224 224 +13692 ./prep_dataset/ILSVRC2012_val_00016933.bin 224 224 +13693 ./prep_dataset/ILSVRC2012_val_00018017.bin 224 224 +13694 ./prep_dataset/ILSVRC2012_val_00000888.bin 224 224 +13695 ./prep_dataset/ILSVRC2012_val_00041474.bin 224 224 +13696 ./prep_dataset/ILSVRC2012_val_00011280.bin 224 224 +13697 ./prep_dataset/ILSVRC2012_val_00040310.bin 224 224 +13698 ./prep_dataset/ILSVRC2012_val_00013261.bin 224 224 +13699 ./prep_dataset/ILSVRC2012_val_00019559.bin 224 224 +13700 ./prep_dataset/ILSVRC2012_val_00046952.bin 224 224 +13701 ./prep_dataset/ILSVRC2012_val_00041454.bin 224 224 +13702 ./prep_dataset/ILSVRC2012_val_00035136.bin 224 224 +13703 ./prep_dataset/ILSVRC2012_val_00032712.bin 224 224 +13704 ./prep_dataset/ILSVRC2012_val_00002675.bin 224 224 +13705 ./prep_dataset/ILSVRC2012_val_00014212.bin 224 224 +13706 ./prep_dataset/ILSVRC2012_val_00045512.bin 224 224 +13707 ./prep_dataset/ILSVRC2012_val_00011297.bin 224 224 +13708 ./prep_dataset/ILSVRC2012_val_00034032.bin 224 224 +13709 ./prep_dataset/ILSVRC2012_val_00031202.bin 224 224 +13710 ./prep_dataset/ILSVRC2012_val_00016419.bin 224 224 +13711 ./prep_dataset/ILSVRC2012_val_00003300.bin 224 224 +13712 ./prep_dataset/ILSVRC2012_val_00043213.bin 224 224 +13713 ./prep_dataset/ILSVRC2012_val_00039476.bin 224 224 +13714 ./prep_dataset/ILSVRC2012_val_00042891.bin 224 224 +13715 ./prep_dataset/ILSVRC2012_val_00039673.bin 224 224 +13716 ./prep_dataset/ILSVRC2012_val_00022793.bin 224 224 +13717 ./prep_dataset/ILSVRC2012_val_00027304.bin 224 224 +13718 ./prep_dataset/ILSVRC2012_val_00004117.bin 224 224 +13719 ./prep_dataset/ILSVRC2012_val_00049872.bin 224 224 +13720 ./prep_dataset/ILSVRC2012_val_00040444.bin 224 224 +13721 ./prep_dataset/ILSVRC2012_val_00042939.bin 224 224 +13722 ./prep_dataset/ILSVRC2012_val_00042737.bin 224 224 +13723 ./prep_dataset/ILSVRC2012_val_00021041.bin 224 224 +13724 ./prep_dataset/ILSVRC2012_val_00019270.bin 224 224 +13725 ./prep_dataset/ILSVRC2012_val_00041371.bin 224 224 +13726 ./prep_dataset/ILSVRC2012_val_00046025.bin 224 224 +13727 ./prep_dataset/ILSVRC2012_val_00023156.bin 224 224 +13728 ./prep_dataset/ILSVRC2012_val_00039992.bin 224 224 +13729 ./prep_dataset/ILSVRC2012_val_00048385.bin 224 224 +13730 ./prep_dataset/ILSVRC2012_val_00013848.bin 224 224 +13731 ./prep_dataset/ILSVRC2012_val_00006717.bin 224 224 +13732 ./prep_dataset/ILSVRC2012_val_00025264.bin 224 224 +13733 ./prep_dataset/ILSVRC2012_val_00023558.bin 224 224 +13734 ./prep_dataset/ILSVRC2012_val_00027002.bin 224 224 +13735 ./prep_dataset/ILSVRC2012_val_00010909.bin 224 224 +13736 ./prep_dataset/ILSVRC2012_val_00026923.bin 224 224 +13737 ./prep_dataset/ILSVRC2012_val_00027589.bin 224 224 +13738 ./prep_dataset/ILSVRC2012_val_00008065.bin 224 224 +13739 ./prep_dataset/ILSVRC2012_val_00009518.bin 224 224 +13740 ./prep_dataset/ILSVRC2012_val_00045557.bin 224 224 +13741 ./prep_dataset/ILSVRC2012_val_00016482.bin 224 224 +13742 ./prep_dataset/ILSVRC2012_val_00004989.bin 224 224 +13743 ./prep_dataset/ILSVRC2012_val_00025946.bin 224 224 +13744 ./prep_dataset/ILSVRC2012_val_00046002.bin 224 224 +13745 ./prep_dataset/ILSVRC2012_val_00018195.bin 224 224 +13746 ./prep_dataset/ILSVRC2012_val_00021891.bin 224 224 +13747 ./prep_dataset/ILSVRC2012_val_00005571.bin 224 224 +13748 ./prep_dataset/ILSVRC2012_val_00045816.bin 224 224 +13749 ./prep_dataset/ILSVRC2012_val_00037990.bin 224 224 +13750 ./prep_dataset/ILSVRC2012_val_00042355.bin 224 224 +13751 ./prep_dataset/ILSVRC2012_val_00013733.bin 224 224 +13752 ./prep_dataset/ILSVRC2012_val_00007530.bin 224 224 +13753 ./prep_dataset/ILSVRC2012_val_00048900.bin 224 224 +13754 ./prep_dataset/ILSVRC2012_val_00013843.bin 224 224 +13755 ./prep_dataset/ILSVRC2012_val_00028784.bin 224 224 +13756 ./prep_dataset/ILSVRC2012_val_00023965.bin 224 224 +13757 ./prep_dataset/ILSVRC2012_val_00049309.bin 224 224 +13758 ./prep_dataset/ILSVRC2012_val_00042526.bin 224 224 +13759 ./prep_dataset/ILSVRC2012_val_00002402.bin 224 224 +13760 ./prep_dataset/ILSVRC2012_val_00042101.bin 224 224 +13761 ./prep_dataset/ILSVRC2012_val_00049610.bin 224 224 +13762 ./prep_dataset/ILSVRC2012_val_00017422.bin 224 224 +13763 ./prep_dataset/ILSVRC2012_val_00011659.bin 224 224 +13764 ./prep_dataset/ILSVRC2012_val_00018855.bin 224 224 +13765 ./prep_dataset/ILSVRC2012_val_00034721.bin 224 224 +13766 ./prep_dataset/ILSVRC2012_val_00039676.bin 224 224 +13767 ./prep_dataset/ILSVRC2012_val_00015858.bin 224 224 +13768 ./prep_dataset/ILSVRC2012_val_00016377.bin 224 224 +13769 ./prep_dataset/ILSVRC2012_val_00004815.bin 224 224 +13770 ./prep_dataset/ILSVRC2012_val_00027730.bin 224 224 +13771 ./prep_dataset/ILSVRC2012_val_00003578.bin 224 224 +13772 ./prep_dataset/ILSVRC2012_val_00028145.bin 224 224 +13773 ./prep_dataset/ILSVRC2012_val_00044369.bin 224 224 +13774 ./prep_dataset/ILSVRC2012_val_00015565.bin 224 224 +13775 ./prep_dataset/ILSVRC2012_val_00035745.bin 224 224 +13776 ./prep_dataset/ILSVRC2012_val_00027510.bin 224 224 +13777 ./prep_dataset/ILSVRC2012_val_00029075.bin 224 224 +13778 ./prep_dataset/ILSVRC2012_val_00017333.bin 224 224 +13779 ./prep_dataset/ILSVRC2012_val_00023476.bin 224 224 +13780 ./prep_dataset/ILSVRC2012_val_00048095.bin 224 224 +13781 ./prep_dataset/ILSVRC2012_val_00011713.bin 224 224 +13782 ./prep_dataset/ILSVRC2012_val_00047583.bin 224 224 +13783 ./prep_dataset/ILSVRC2012_val_00032522.bin 224 224 +13784 ./prep_dataset/ILSVRC2012_val_00033223.bin 224 224 +13785 ./prep_dataset/ILSVRC2012_val_00034082.bin 224 224 +13786 ./prep_dataset/ILSVRC2012_val_00019918.bin 224 224 +13787 ./prep_dataset/ILSVRC2012_val_00017469.bin 224 224 +13788 ./prep_dataset/ILSVRC2012_val_00035811.bin 224 224 +13789 ./prep_dataset/ILSVRC2012_val_00003700.bin 224 224 +13790 ./prep_dataset/ILSVRC2012_val_00027146.bin 224 224 +13791 ./prep_dataset/ILSVRC2012_val_00049991.bin 224 224 +13792 ./prep_dataset/ILSVRC2012_val_00021943.bin 224 224 +13793 ./prep_dataset/ILSVRC2012_val_00018730.bin 224 224 +13794 ./prep_dataset/ILSVRC2012_val_00008470.bin 224 224 +13795 ./prep_dataset/ILSVRC2012_val_00003354.bin 224 224 +13796 ./prep_dataset/ILSVRC2012_val_00037331.bin 224 224 +13797 ./prep_dataset/ILSVRC2012_val_00046069.bin 224 224 +13798 ./prep_dataset/ILSVRC2012_val_00010821.bin 224 224 +13799 ./prep_dataset/ILSVRC2012_val_00005874.bin 224 224 +13800 ./prep_dataset/ILSVRC2012_val_00026435.bin 224 224 +13801 ./prep_dataset/ILSVRC2012_val_00001292.bin 224 224 +13802 ./prep_dataset/ILSVRC2012_val_00003988.bin 224 224 +13803 ./prep_dataset/ILSVRC2012_val_00034070.bin 224 224 +13804 ./prep_dataset/ILSVRC2012_val_00017979.bin 224 224 +13805 ./prep_dataset/ILSVRC2012_val_00004775.bin 224 224 +13806 ./prep_dataset/ILSVRC2012_val_00023723.bin 224 224 +13807 ./prep_dataset/ILSVRC2012_val_00045163.bin 224 224 +13808 ./prep_dataset/ILSVRC2012_val_00044802.bin 224 224 +13809 ./prep_dataset/ILSVRC2012_val_00034179.bin 224 224 +13810 ./prep_dataset/ILSVRC2012_val_00016783.bin 224 224 +13811 ./prep_dataset/ILSVRC2012_val_00017957.bin 224 224 +13812 ./prep_dataset/ILSVRC2012_val_00034323.bin 224 224 +13813 ./prep_dataset/ILSVRC2012_val_00000874.bin 224 224 +13814 ./prep_dataset/ILSVRC2012_val_00025098.bin 224 224 +13815 ./prep_dataset/ILSVRC2012_val_00031089.bin 224 224 +13816 ./prep_dataset/ILSVRC2012_val_00043357.bin 224 224 +13817 ./prep_dataset/ILSVRC2012_val_00021167.bin 224 224 +13818 ./prep_dataset/ILSVRC2012_val_00048998.bin 224 224 +13819 ./prep_dataset/ILSVRC2012_val_00018026.bin 224 224 +13820 ./prep_dataset/ILSVRC2012_val_00034600.bin 224 224 +13821 ./prep_dataset/ILSVRC2012_val_00014346.bin 224 224 +13822 ./prep_dataset/ILSVRC2012_val_00003621.bin 224 224 +13823 ./prep_dataset/ILSVRC2012_val_00009583.bin 224 224 +13824 ./prep_dataset/ILSVRC2012_val_00033844.bin 224 224 +13825 ./prep_dataset/ILSVRC2012_val_00035831.bin 224 224 +13826 ./prep_dataset/ILSVRC2012_val_00007882.bin 224 224 +13827 ./prep_dataset/ILSVRC2012_val_00045706.bin 224 224 +13828 ./prep_dataset/ILSVRC2012_val_00040862.bin 224 224 +13829 ./prep_dataset/ILSVRC2012_val_00042882.bin 224 224 +13830 ./prep_dataset/ILSVRC2012_val_00011178.bin 224 224 +13831 ./prep_dataset/ILSVRC2012_val_00011397.bin 224 224 +13832 ./prep_dataset/ILSVRC2012_val_00014549.bin 224 224 +13833 ./prep_dataset/ILSVRC2012_val_00017301.bin 224 224 +13834 ./prep_dataset/ILSVRC2012_val_00040337.bin 224 224 +13835 ./prep_dataset/ILSVRC2012_val_00024977.bin 224 224 +13836 ./prep_dataset/ILSVRC2012_val_00014408.bin 224 224 +13837 ./prep_dataset/ILSVRC2012_val_00025363.bin 224 224 +13838 ./prep_dataset/ILSVRC2012_val_00009092.bin 224 224 +13839 ./prep_dataset/ILSVRC2012_val_00014306.bin 224 224 +13840 ./prep_dataset/ILSVRC2012_val_00046119.bin 224 224 +13841 ./prep_dataset/ILSVRC2012_val_00034930.bin 224 224 +13842 ./prep_dataset/ILSVRC2012_val_00026860.bin 224 224 +13843 ./prep_dataset/ILSVRC2012_val_00017673.bin 224 224 +13844 ./prep_dataset/ILSVRC2012_val_00024410.bin 224 224 +13845 ./prep_dataset/ILSVRC2012_val_00010898.bin 224 224 +13846 ./prep_dataset/ILSVRC2012_val_00038800.bin 224 224 +13847 ./prep_dataset/ILSVRC2012_val_00039868.bin 224 224 +13848 ./prep_dataset/ILSVRC2012_val_00037057.bin 224 224 +13849 ./prep_dataset/ILSVRC2012_val_00041407.bin 224 224 +13850 ./prep_dataset/ILSVRC2012_val_00026310.bin 224 224 +13851 ./prep_dataset/ILSVRC2012_val_00036174.bin 224 224 +13852 ./prep_dataset/ILSVRC2012_val_00044716.bin 224 224 +13853 ./prep_dataset/ILSVRC2012_val_00013563.bin 224 224 +13854 ./prep_dataset/ILSVRC2012_val_00013242.bin 224 224 +13855 ./prep_dataset/ILSVRC2012_val_00011622.bin 224 224 +13856 ./prep_dataset/ILSVRC2012_val_00016720.bin 224 224 +13857 ./prep_dataset/ILSVRC2012_val_00006871.bin 224 224 +13858 ./prep_dataset/ILSVRC2012_val_00041017.bin 224 224 +13859 ./prep_dataset/ILSVRC2012_val_00009748.bin 224 224 +13860 ./prep_dataset/ILSVRC2012_val_00032079.bin 224 224 +13861 ./prep_dataset/ILSVRC2012_val_00044950.bin 224 224 +13862 ./prep_dataset/ILSVRC2012_val_00049232.bin 224 224 +13863 ./prep_dataset/ILSVRC2012_val_00015043.bin 224 224 +13864 ./prep_dataset/ILSVRC2012_val_00031387.bin 224 224 +13865 ./prep_dataset/ILSVRC2012_val_00010928.bin 224 224 +13866 ./prep_dataset/ILSVRC2012_val_00010646.bin 224 224 +13867 ./prep_dataset/ILSVRC2012_val_00013704.bin 224 224 +13868 ./prep_dataset/ILSVRC2012_val_00041200.bin 224 224 +13869 ./prep_dataset/ILSVRC2012_val_00034488.bin 224 224 +13870 ./prep_dataset/ILSVRC2012_val_00044311.bin 224 224 +13871 ./prep_dataset/ILSVRC2012_val_00037770.bin 224 224 +13872 ./prep_dataset/ILSVRC2012_val_00027947.bin 224 224 +13873 ./prep_dataset/ILSVRC2012_val_00042441.bin 224 224 +13874 ./prep_dataset/ILSVRC2012_val_00045817.bin 224 224 +13875 ./prep_dataset/ILSVRC2012_val_00002555.bin 224 224 +13876 ./prep_dataset/ILSVRC2012_val_00005774.bin 224 224 +13877 ./prep_dataset/ILSVRC2012_val_00039548.bin 224 224 +13878 ./prep_dataset/ILSVRC2012_val_00033818.bin 224 224 +13879 ./prep_dataset/ILSVRC2012_val_00038555.bin 224 224 +13880 ./prep_dataset/ILSVRC2012_val_00003559.bin 224 224 +13881 ./prep_dataset/ILSVRC2012_val_00024496.bin 224 224 +13882 ./prep_dataset/ILSVRC2012_val_00034786.bin 224 224 +13883 ./prep_dataset/ILSVRC2012_val_00007328.bin 224 224 +13884 ./prep_dataset/ILSVRC2012_val_00040513.bin 224 224 +13885 ./prep_dataset/ILSVRC2012_val_00026782.bin 224 224 +13886 ./prep_dataset/ILSVRC2012_val_00044862.bin 224 224 +13887 ./prep_dataset/ILSVRC2012_val_00039041.bin 224 224 +13888 ./prep_dataset/ILSVRC2012_val_00036953.bin 224 224 +13889 ./prep_dataset/ILSVRC2012_val_00041552.bin 224 224 +13890 ./prep_dataset/ILSVRC2012_val_00036029.bin 224 224 +13891 ./prep_dataset/ILSVRC2012_val_00024617.bin 224 224 +13892 ./prep_dataset/ILSVRC2012_val_00008285.bin 224 224 +13893 ./prep_dataset/ILSVRC2012_val_00040340.bin 224 224 +13894 ./prep_dataset/ILSVRC2012_val_00003798.bin 224 224 +13895 ./prep_dataset/ILSVRC2012_val_00025948.bin 224 224 +13896 ./prep_dataset/ILSVRC2012_val_00009740.bin 224 224 +13897 ./prep_dataset/ILSVRC2012_val_00046794.bin 224 224 +13898 ./prep_dataset/ILSVRC2012_val_00027426.bin 224 224 +13899 ./prep_dataset/ILSVRC2012_val_00009708.bin 224 224 +13900 ./prep_dataset/ILSVRC2012_val_00016548.bin 224 224 +13901 ./prep_dataset/ILSVRC2012_val_00024264.bin 224 224 +13902 ./prep_dataset/ILSVRC2012_val_00018085.bin 224 224 +13903 ./prep_dataset/ILSVRC2012_val_00013337.bin 224 224 +13904 ./prep_dataset/ILSVRC2012_val_00037893.bin 224 224 +13905 ./prep_dataset/ILSVRC2012_val_00025507.bin 224 224 +13906 ./prep_dataset/ILSVRC2012_val_00004402.bin 224 224 +13907 ./prep_dataset/ILSVRC2012_val_00003158.bin 224 224 +13908 ./prep_dataset/ILSVRC2012_val_00041055.bin 224 224 +13909 ./prep_dataset/ILSVRC2012_val_00036642.bin 224 224 +13910 ./prep_dataset/ILSVRC2012_val_00038131.bin 224 224 +13911 ./prep_dataset/ILSVRC2012_val_00005628.bin 224 224 +13912 ./prep_dataset/ILSVRC2012_val_00003395.bin 224 224 +13913 ./prep_dataset/ILSVRC2012_val_00047339.bin 224 224 +13914 ./prep_dataset/ILSVRC2012_val_00038379.bin 224 224 +13915 ./prep_dataset/ILSVRC2012_val_00004596.bin 224 224 +13916 ./prep_dataset/ILSVRC2012_val_00043929.bin 224 224 +13917 ./prep_dataset/ILSVRC2012_val_00045172.bin 224 224 +13918 ./prep_dataset/ILSVRC2012_val_00048426.bin 224 224 +13919 ./prep_dataset/ILSVRC2012_val_00041798.bin 224 224 +13920 ./prep_dataset/ILSVRC2012_val_00037269.bin 224 224 +13921 ./prep_dataset/ILSVRC2012_val_00049674.bin 224 224 +13922 ./prep_dataset/ILSVRC2012_val_00004474.bin 224 224 +13923 ./prep_dataset/ILSVRC2012_val_00024547.bin 224 224 +13924 ./prep_dataset/ILSVRC2012_val_00048414.bin 224 224 +13925 ./prep_dataset/ILSVRC2012_val_00038081.bin 224 224 +13926 ./prep_dataset/ILSVRC2012_val_00045331.bin 224 224 +13927 ./prep_dataset/ILSVRC2012_val_00016799.bin 224 224 +13928 ./prep_dataset/ILSVRC2012_val_00047753.bin 224 224 +13929 ./prep_dataset/ILSVRC2012_val_00007247.bin 224 224 +13930 ./prep_dataset/ILSVRC2012_val_00011838.bin 224 224 +13931 ./prep_dataset/ILSVRC2012_val_00013068.bin 224 224 +13932 ./prep_dataset/ILSVRC2012_val_00039936.bin 224 224 +13933 ./prep_dataset/ILSVRC2012_val_00043628.bin 224 224 +13934 ./prep_dataset/ILSVRC2012_val_00024749.bin 224 224 +13935 ./prep_dataset/ILSVRC2012_val_00029893.bin 224 224 +13936 ./prep_dataset/ILSVRC2012_val_00028220.bin 224 224 +13937 ./prep_dataset/ILSVRC2012_val_00026474.bin 224 224 +13938 ./prep_dataset/ILSVRC2012_val_00031309.bin 224 224 +13939 ./prep_dataset/ILSVRC2012_val_00027310.bin 224 224 +13940 ./prep_dataset/ILSVRC2012_val_00025436.bin 224 224 +13941 ./prep_dataset/ILSVRC2012_val_00001610.bin 224 224 +13942 ./prep_dataset/ILSVRC2012_val_00000449.bin 224 224 +13943 ./prep_dataset/ILSVRC2012_val_00003941.bin 224 224 +13944 ./prep_dataset/ILSVRC2012_val_00025558.bin 224 224 +13945 ./prep_dataset/ILSVRC2012_val_00042485.bin 224 224 +13946 ./prep_dataset/ILSVRC2012_val_00009348.bin 224 224 +13947 ./prep_dataset/ILSVRC2012_val_00028207.bin 224 224 +13948 ./prep_dataset/ILSVRC2012_val_00048154.bin 224 224 +13949 ./prep_dataset/ILSVRC2012_val_00006049.bin 224 224 +13950 ./prep_dataset/ILSVRC2012_val_00034115.bin 224 224 +13951 ./prep_dataset/ILSVRC2012_val_00041866.bin 224 224 +13952 ./prep_dataset/ILSVRC2012_val_00020986.bin 224 224 +13953 ./prep_dataset/ILSVRC2012_val_00017581.bin 224 224 +13954 ./prep_dataset/ILSVRC2012_val_00048924.bin 224 224 +13955 ./prep_dataset/ILSVRC2012_val_00032741.bin 224 224 +13956 ./prep_dataset/ILSVRC2012_val_00015109.bin 224 224 +13957 ./prep_dataset/ILSVRC2012_val_00008506.bin 224 224 +13958 ./prep_dataset/ILSVRC2012_val_00024517.bin 224 224 +13959 ./prep_dataset/ILSVRC2012_val_00049772.bin 224 224 +13960 ./prep_dataset/ILSVRC2012_val_00041882.bin 224 224 +13961 ./prep_dataset/ILSVRC2012_val_00003479.bin 224 224 +13962 ./prep_dataset/ILSVRC2012_val_00039094.bin 224 224 +13963 ./prep_dataset/ILSVRC2012_val_00033640.bin 224 224 +13964 ./prep_dataset/ILSVRC2012_val_00024935.bin 224 224 +13965 ./prep_dataset/ILSVRC2012_val_00008920.bin 224 224 +13966 ./prep_dataset/ILSVRC2012_val_00002274.bin 224 224 +13967 ./prep_dataset/ILSVRC2012_val_00048379.bin 224 224 +13968 ./prep_dataset/ILSVRC2012_val_00021408.bin 224 224 +13969 ./prep_dataset/ILSVRC2012_val_00018739.bin 224 224 +13970 ./prep_dataset/ILSVRC2012_val_00037662.bin 224 224 +13971 ./prep_dataset/ILSVRC2012_val_00043795.bin 224 224 +13972 ./prep_dataset/ILSVRC2012_val_00014681.bin 224 224 +13973 ./prep_dataset/ILSVRC2012_val_00022052.bin 224 224 +13974 ./prep_dataset/ILSVRC2012_val_00042229.bin 224 224 +13975 ./prep_dataset/ILSVRC2012_val_00033481.bin 224 224 +13976 ./prep_dataset/ILSVRC2012_val_00034766.bin 224 224 +13977 ./prep_dataset/ILSVRC2012_val_00038022.bin 224 224 +13978 ./prep_dataset/ILSVRC2012_val_00033829.bin 224 224 +13979 ./prep_dataset/ILSVRC2012_val_00040371.bin 224 224 +13980 ./prep_dataset/ILSVRC2012_val_00023694.bin 224 224 +13981 ./prep_dataset/ILSVRC2012_val_00028573.bin 224 224 +13982 ./prep_dataset/ILSVRC2012_val_00028240.bin 224 224 +13983 ./prep_dataset/ILSVRC2012_val_00036083.bin 224 224 +13984 ./prep_dataset/ILSVRC2012_val_00034020.bin 224 224 +13985 ./prep_dataset/ILSVRC2012_val_00044846.bin 224 224 +13986 ./prep_dataset/ILSVRC2012_val_00040027.bin 224 224 +13987 ./prep_dataset/ILSVRC2012_val_00048599.bin 224 224 +13988 ./prep_dataset/ILSVRC2012_val_00043658.bin 224 224 +13989 ./prep_dataset/ILSVRC2012_val_00047940.bin 224 224 +13990 ./prep_dataset/ILSVRC2012_val_00023238.bin 224 224 +13991 ./prep_dataset/ILSVRC2012_val_00044330.bin 224 224 +13992 ./prep_dataset/ILSVRC2012_val_00003127.bin 224 224 +13993 ./prep_dataset/ILSVRC2012_val_00025860.bin 224 224 +13994 ./prep_dataset/ILSVRC2012_val_00000787.bin 224 224 +13995 ./prep_dataset/ILSVRC2012_val_00013378.bin 224 224 +13996 ./prep_dataset/ILSVRC2012_val_00004882.bin 224 224 +13997 ./prep_dataset/ILSVRC2012_val_00033536.bin 224 224 +13998 ./prep_dataset/ILSVRC2012_val_00048195.bin 224 224 +13999 ./prep_dataset/ILSVRC2012_val_00047552.bin 224 224 +14000 ./prep_dataset/ILSVRC2012_val_00029708.bin 224 224 +14001 ./prep_dataset/ILSVRC2012_val_00046091.bin 224 224 +14002 ./prep_dataset/ILSVRC2012_val_00007384.bin 224 224 +14003 ./prep_dataset/ILSVRC2012_val_00008086.bin 224 224 +14004 ./prep_dataset/ILSVRC2012_val_00032902.bin 224 224 +14005 ./prep_dataset/ILSVRC2012_val_00034194.bin 224 224 +14006 ./prep_dataset/ILSVRC2012_val_00049178.bin 224 224 +14007 ./prep_dataset/ILSVRC2012_val_00022222.bin 224 224 +14008 ./prep_dataset/ILSVRC2012_val_00010036.bin 224 224 +14009 ./prep_dataset/ILSVRC2012_val_00016227.bin 224 224 +14010 ./prep_dataset/ILSVRC2012_val_00001679.bin 224 224 +14011 ./prep_dataset/ILSVRC2012_val_00047950.bin 224 224 +14012 ./prep_dataset/ILSVRC2012_val_00007220.bin 224 224 +14013 ./prep_dataset/ILSVRC2012_val_00006463.bin 224 224 +14014 ./prep_dataset/ILSVRC2012_val_00014155.bin 224 224 +14015 ./prep_dataset/ILSVRC2012_val_00023488.bin 224 224 +14016 ./prep_dataset/ILSVRC2012_val_00008593.bin 224 224 +14017 ./prep_dataset/ILSVRC2012_val_00045461.bin 224 224 +14018 ./prep_dataset/ILSVRC2012_val_00048129.bin 224 224 +14019 ./prep_dataset/ILSVRC2012_val_00039993.bin 224 224 +14020 ./prep_dataset/ILSVRC2012_val_00029233.bin 224 224 +14021 ./prep_dataset/ILSVRC2012_val_00036438.bin 224 224 +14022 ./prep_dataset/ILSVRC2012_val_00032295.bin 224 224 +14023 ./prep_dataset/ILSVRC2012_val_00001936.bin 224 224 +14024 ./prep_dataset/ILSVRC2012_val_00036658.bin 224 224 +14025 ./prep_dataset/ILSVRC2012_val_00041248.bin 224 224 +14026 ./prep_dataset/ILSVRC2012_val_00021771.bin 224 224 +14027 ./prep_dataset/ILSVRC2012_val_00018782.bin 224 224 +14028 ./prep_dataset/ILSVRC2012_val_00034967.bin 224 224 +14029 ./prep_dataset/ILSVRC2012_val_00004323.bin 224 224 +14030 ./prep_dataset/ILSVRC2012_val_00019762.bin 224 224 +14031 ./prep_dataset/ILSVRC2012_val_00020066.bin 224 224 +14032 ./prep_dataset/ILSVRC2012_val_00024472.bin 224 224 +14033 ./prep_dataset/ILSVRC2012_val_00012720.bin 224 224 +14034 ./prep_dataset/ILSVRC2012_val_00010645.bin 224 224 +14035 ./prep_dataset/ILSVRC2012_val_00015283.bin 224 224 +14036 ./prep_dataset/ILSVRC2012_val_00047134.bin 224 224 +14037 ./prep_dataset/ILSVRC2012_val_00015198.bin 224 224 +14038 ./prep_dataset/ILSVRC2012_val_00010745.bin 224 224 +14039 ./prep_dataset/ILSVRC2012_val_00023189.bin 224 224 +14040 ./prep_dataset/ILSVRC2012_val_00000010.bin 224 224 +14041 ./prep_dataset/ILSVRC2012_val_00041730.bin 224 224 +14042 ./prep_dataset/ILSVRC2012_val_00032570.bin 224 224 +14043 ./prep_dataset/ILSVRC2012_val_00017551.bin 224 224 +14044 ./prep_dataset/ILSVRC2012_val_00046018.bin 224 224 +14045 ./prep_dataset/ILSVRC2012_val_00048422.bin 224 224 +14046 ./prep_dataset/ILSVRC2012_val_00046665.bin 224 224 +14047 ./prep_dataset/ILSVRC2012_val_00040733.bin 224 224 +14048 ./prep_dataset/ILSVRC2012_val_00001339.bin 224 224 +14049 ./prep_dataset/ILSVRC2012_val_00016025.bin 224 224 +14050 ./prep_dataset/ILSVRC2012_val_00018128.bin 224 224 +14051 ./prep_dataset/ILSVRC2012_val_00006293.bin 224 224 +14052 ./prep_dataset/ILSVRC2012_val_00023121.bin 224 224 +14053 ./prep_dataset/ILSVRC2012_val_00037643.bin 224 224 +14054 ./prep_dataset/ILSVRC2012_val_00042035.bin 224 224 +14055 ./prep_dataset/ILSVRC2012_val_00007062.bin 224 224 +14056 ./prep_dataset/ILSVRC2012_val_00001719.bin 224 224 +14057 ./prep_dataset/ILSVRC2012_val_00025306.bin 224 224 +14058 ./prep_dataset/ILSVRC2012_val_00047126.bin 224 224 +14059 ./prep_dataset/ILSVRC2012_val_00028274.bin 224 224 +14060 ./prep_dataset/ILSVRC2012_val_00019087.bin 224 224 +14061 ./prep_dataset/ILSVRC2012_val_00005224.bin 224 224 +14062 ./prep_dataset/ILSVRC2012_val_00032943.bin 224 224 +14063 ./prep_dataset/ILSVRC2012_val_00030981.bin 224 224 +14064 ./prep_dataset/ILSVRC2012_val_00001071.bin 224 224 +14065 ./prep_dataset/ILSVRC2012_val_00017707.bin 224 224 +14066 ./prep_dataset/ILSVRC2012_val_00025153.bin 224 224 +14067 ./prep_dataset/ILSVRC2012_val_00020569.bin 224 224 +14068 ./prep_dataset/ILSVRC2012_val_00035281.bin 224 224 +14069 ./prep_dataset/ILSVRC2012_val_00028853.bin 224 224 +14070 ./prep_dataset/ILSVRC2012_val_00011206.bin 224 224 +14071 ./prep_dataset/ILSVRC2012_val_00040549.bin 224 224 +14072 ./prep_dataset/ILSVRC2012_val_00043996.bin 224 224 +14073 ./prep_dataset/ILSVRC2012_val_00017125.bin 224 224 +14074 ./prep_dataset/ILSVRC2012_val_00035296.bin 224 224 +14075 ./prep_dataset/ILSVRC2012_val_00018716.bin 224 224 +14076 ./prep_dataset/ILSVRC2012_val_00028567.bin 224 224 +14077 ./prep_dataset/ILSVRC2012_val_00033327.bin 224 224 +14078 ./prep_dataset/ILSVRC2012_val_00032401.bin 224 224 +14079 ./prep_dataset/ILSVRC2012_val_00045257.bin 224 224 +14080 ./prep_dataset/ILSVRC2012_val_00018921.bin 224 224 +14081 ./prep_dataset/ILSVRC2012_val_00034351.bin 224 224 +14082 ./prep_dataset/ILSVRC2012_val_00040293.bin 224 224 +14083 ./prep_dataset/ILSVRC2012_val_00004784.bin 224 224 +14084 ./prep_dataset/ILSVRC2012_val_00025847.bin 224 224 +14085 ./prep_dataset/ILSVRC2012_val_00007826.bin 224 224 +14086 ./prep_dataset/ILSVRC2012_val_00027022.bin 224 224 +14087 ./prep_dataset/ILSVRC2012_val_00005824.bin 224 224 +14088 ./prep_dataset/ILSVRC2012_val_00042601.bin 224 224 +14089 ./prep_dataset/ILSVRC2012_val_00043166.bin 224 224 +14090 ./prep_dataset/ILSVRC2012_val_00004732.bin 224 224 +14091 ./prep_dataset/ILSVRC2012_val_00014930.bin 224 224 +14092 ./prep_dataset/ILSVRC2012_val_00023959.bin 224 224 +14093 ./prep_dataset/ILSVRC2012_val_00037295.bin 224 224 +14094 ./prep_dataset/ILSVRC2012_val_00001040.bin 224 224 +14095 ./prep_dataset/ILSVRC2012_val_00044516.bin 224 224 +14096 ./prep_dataset/ILSVRC2012_val_00032669.bin 224 224 +14097 ./prep_dataset/ILSVRC2012_val_00032234.bin 224 224 +14098 ./prep_dataset/ILSVRC2012_val_00008882.bin 224 224 +14099 ./prep_dataset/ILSVRC2012_val_00005663.bin 224 224 +14100 ./prep_dataset/ILSVRC2012_val_00037687.bin 224 224 +14101 ./prep_dataset/ILSVRC2012_val_00008544.bin 224 224 +14102 ./prep_dataset/ILSVRC2012_val_00023638.bin 224 224 +14103 ./prep_dataset/ILSVRC2012_val_00034365.bin 224 224 +14104 ./prep_dataset/ILSVRC2012_val_00034866.bin 224 224 +14105 ./prep_dataset/ILSVRC2012_val_00005021.bin 224 224 +14106 ./prep_dataset/ILSVRC2012_val_00040936.bin 224 224 +14107 ./prep_dataset/ILSVRC2012_val_00004479.bin 224 224 +14108 ./prep_dataset/ILSVRC2012_val_00026857.bin 224 224 +14109 ./prep_dataset/ILSVRC2012_val_00008359.bin 224 224 +14110 ./prep_dataset/ILSVRC2012_val_00010760.bin 224 224 +14111 ./prep_dataset/ILSVRC2012_val_00041418.bin 224 224 +14112 ./prep_dataset/ILSVRC2012_val_00044972.bin 224 224 +14113 ./prep_dataset/ILSVRC2012_val_00027160.bin 224 224 +14114 ./prep_dataset/ILSVRC2012_val_00020610.bin 224 224 +14115 ./prep_dataset/ILSVRC2012_val_00038540.bin 224 224 +14116 ./prep_dataset/ILSVRC2012_val_00045442.bin 224 224 +14117 ./prep_dataset/ILSVRC2012_val_00006154.bin 224 224 +14118 ./prep_dataset/ILSVRC2012_val_00019016.bin 224 224 +14119 ./prep_dataset/ILSVRC2012_val_00011164.bin 224 224 +14120 ./prep_dataset/ILSVRC2012_val_00027379.bin 224 224 +14121 ./prep_dataset/ILSVRC2012_val_00011835.bin 224 224 +14122 ./prep_dataset/ILSVRC2012_val_00017498.bin 224 224 +14123 ./prep_dataset/ILSVRC2012_val_00030918.bin 224 224 +14124 ./prep_dataset/ILSVRC2012_val_00034634.bin 224 224 +14125 ./prep_dataset/ILSVRC2012_val_00038227.bin 224 224 +14126 ./prep_dataset/ILSVRC2012_val_00001911.bin 224 224 +14127 ./prep_dataset/ILSVRC2012_val_00023436.bin 224 224 +14128 ./prep_dataset/ILSVRC2012_val_00039973.bin 224 224 +14129 ./prep_dataset/ILSVRC2012_val_00039832.bin 224 224 +14130 ./prep_dataset/ILSVRC2012_val_00026402.bin 224 224 +14131 ./prep_dataset/ILSVRC2012_val_00016667.bin 224 224 +14132 ./prep_dataset/ILSVRC2012_val_00035428.bin 224 224 +14133 ./prep_dataset/ILSVRC2012_val_00036180.bin 224 224 +14134 ./prep_dataset/ILSVRC2012_val_00046167.bin 224 224 +14135 ./prep_dataset/ILSVRC2012_val_00030876.bin 224 224 +14136 ./prep_dataset/ILSVRC2012_val_00036884.bin 224 224 +14137 ./prep_dataset/ILSVRC2012_val_00007569.bin 224 224 +14138 ./prep_dataset/ILSVRC2012_val_00027923.bin 224 224 +14139 ./prep_dataset/ILSVRC2012_val_00008266.bin 224 224 +14140 ./prep_dataset/ILSVRC2012_val_00033509.bin 224 224 +14141 ./prep_dataset/ILSVRC2012_val_00042701.bin 224 224 +14142 ./prep_dataset/ILSVRC2012_val_00041881.bin 224 224 +14143 ./prep_dataset/ILSVRC2012_val_00024458.bin 224 224 +14144 ./prep_dataset/ILSVRC2012_val_00043078.bin 224 224 +14145 ./prep_dataset/ILSVRC2012_val_00040110.bin 224 224 +14146 ./prep_dataset/ILSVRC2012_val_00040584.bin 224 224 +14147 ./prep_dataset/ILSVRC2012_val_00025191.bin 224 224 +14148 ./prep_dataset/ILSVRC2012_val_00030178.bin 224 224 +14149 ./prep_dataset/ILSVRC2012_val_00000903.bin 224 224 +14150 ./prep_dataset/ILSVRC2012_val_00010949.bin 224 224 +14151 ./prep_dataset/ILSVRC2012_val_00035343.bin 224 224 +14152 ./prep_dataset/ILSVRC2012_val_00045227.bin 224 224 +14153 ./prep_dataset/ILSVRC2012_val_00015669.bin 224 224 +14154 ./prep_dataset/ILSVRC2012_val_00022901.bin 224 224 +14155 ./prep_dataset/ILSVRC2012_val_00009466.bin 224 224 +14156 ./prep_dataset/ILSVRC2012_val_00048506.bin 224 224 +14157 ./prep_dataset/ILSVRC2012_val_00005155.bin 224 224 +14158 ./prep_dataset/ILSVRC2012_val_00013322.bin 224 224 +14159 ./prep_dataset/ILSVRC2012_val_00049173.bin 224 224 +14160 ./prep_dataset/ILSVRC2012_val_00037400.bin 224 224 +14161 ./prep_dataset/ILSVRC2012_val_00028708.bin 224 224 +14162 ./prep_dataset/ILSVRC2012_val_00025615.bin 224 224 +14163 ./prep_dataset/ILSVRC2012_val_00011277.bin 224 224 +14164 ./prep_dataset/ILSVRC2012_val_00004172.bin 224 224 +14165 ./prep_dataset/ILSVRC2012_val_00004650.bin 224 224 +14166 ./prep_dataset/ILSVRC2012_val_00000002.bin 224 224 +14167 ./prep_dataset/ILSVRC2012_val_00030197.bin 224 224 +14168 ./prep_dataset/ILSVRC2012_val_00031277.bin 224 224 +14169 ./prep_dataset/ILSVRC2012_val_00042078.bin 224 224 +14170 ./prep_dataset/ILSVRC2012_val_00042562.bin 224 224 +14171 ./prep_dataset/ILSVRC2012_val_00007451.bin 224 224 +14172 ./prep_dataset/ILSVRC2012_val_00004019.bin 224 224 +14173 ./prep_dataset/ILSVRC2012_val_00001926.bin 224 224 +14174 ./prep_dataset/ILSVRC2012_val_00031268.bin 224 224 +14175 ./prep_dataset/ILSVRC2012_val_00038426.bin 224 224 +14176 ./prep_dataset/ILSVRC2012_val_00036097.bin 224 224 +14177 ./prep_dataset/ILSVRC2012_val_00013197.bin 224 224 +14178 ./prep_dataset/ILSVRC2012_val_00014491.bin 224 224 +14179 ./prep_dataset/ILSVRC2012_val_00025505.bin 224 224 +14180 ./prep_dataset/ILSVRC2012_val_00048372.bin 224 224 +14181 ./prep_dataset/ILSVRC2012_val_00004714.bin 224 224 +14182 ./prep_dataset/ILSVRC2012_val_00036398.bin 224 224 +14183 ./prep_dataset/ILSVRC2012_val_00019911.bin 224 224 +14184 ./prep_dataset/ILSVRC2012_val_00048991.bin 224 224 +14185 ./prep_dataset/ILSVRC2012_val_00024014.bin 224 224 +14186 ./prep_dataset/ILSVRC2012_val_00047425.bin 224 224 +14187 ./prep_dataset/ILSVRC2012_val_00044631.bin 224 224 +14188 ./prep_dataset/ILSVRC2012_val_00039651.bin 224 224 +14189 ./prep_dataset/ILSVRC2012_val_00011459.bin 224 224 +14190 ./prep_dataset/ILSVRC2012_val_00030662.bin 224 224 +14191 ./prep_dataset/ILSVRC2012_val_00021745.bin 224 224 +14192 ./prep_dataset/ILSVRC2012_val_00020389.bin 224 224 +14193 ./prep_dataset/ILSVRC2012_val_00049957.bin 224 224 +14194 ./prep_dataset/ILSVRC2012_val_00003004.bin 224 224 +14195 ./prep_dataset/ILSVRC2012_val_00043735.bin 224 224 +14196 ./prep_dataset/ILSVRC2012_val_00047283.bin 224 224 +14197 ./prep_dataset/ILSVRC2012_val_00031775.bin 224 224 +14198 ./prep_dataset/ILSVRC2012_val_00022097.bin 224 224 +14199 ./prep_dataset/ILSVRC2012_val_00025209.bin 224 224 +14200 ./prep_dataset/ILSVRC2012_val_00020763.bin 224 224 +14201 ./prep_dataset/ILSVRC2012_val_00034416.bin 224 224 +14202 ./prep_dataset/ILSVRC2012_val_00007678.bin 224 224 +14203 ./prep_dataset/ILSVRC2012_val_00024731.bin 224 224 +14204 ./prep_dataset/ILSVRC2012_val_00046749.bin 224 224 +14205 ./prep_dataset/ILSVRC2012_val_00019510.bin 224 224 +14206 ./prep_dataset/ILSVRC2012_val_00000347.bin 224 224 +14207 ./prep_dataset/ILSVRC2012_val_00049196.bin 224 224 +14208 ./prep_dataset/ILSVRC2012_val_00002146.bin 224 224 +14209 ./prep_dataset/ILSVRC2012_val_00009610.bin 224 224 +14210 ./prep_dataset/ILSVRC2012_val_00048153.bin 224 224 +14211 ./prep_dataset/ILSVRC2012_val_00011108.bin 224 224 +14212 ./prep_dataset/ILSVRC2012_val_00047146.bin 224 224 +14213 ./prep_dataset/ILSVRC2012_val_00008148.bin 224 224 +14214 ./prep_dataset/ILSVRC2012_val_00028933.bin 224 224 +14215 ./prep_dataset/ILSVRC2012_val_00031196.bin 224 224 +14216 ./prep_dataset/ILSVRC2012_val_00018536.bin 224 224 +14217 ./prep_dataset/ILSVRC2012_val_00043743.bin 224 224 +14218 ./prep_dataset/ILSVRC2012_val_00007718.bin 224 224 +14219 ./prep_dataset/ILSVRC2012_val_00009365.bin 224 224 +14220 ./prep_dataset/ILSVRC2012_val_00023246.bin 224 224 +14221 ./prep_dataset/ILSVRC2012_val_00032759.bin 224 224 +14222 ./prep_dataset/ILSVRC2012_val_00023822.bin 224 224 +14223 ./prep_dataset/ILSVRC2012_val_00010881.bin 224 224 +14224 ./prep_dataset/ILSVRC2012_val_00002468.bin 224 224 +14225 ./prep_dataset/ILSVRC2012_val_00013190.bin 224 224 +14226 ./prep_dataset/ILSVRC2012_val_00016294.bin 224 224 +14227 ./prep_dataset/ILSVRC2012_val_00022322.bin 224 224 +14228 ./prep_dataset/ILSVRC2012_val_00000603.bin 224 224 +14229 ./prep_dataset/ILSVRC2012_val_00031024.bin 224 224 +14230 ./prep_dataset/ILSVRC2012_val_00022854.bin 224 224 +14231 ./prep_dataset/ILSVRC2012_val_00028472.bin 224 224 +14232 ./prep_dataset/ILSVRC2012_val_00022232.bin 224 224 +14233 ./prep_dataset/ILSVRC2012_val_00023745.bin 224 224 +14234 ./prep_dataset/ILSVRC2012_val_00042194.bin 224 224 +14235 ./prep_dataset/ILSVRC2012_val_00019433.bin 224 224 +14236 ./prep_dataset/ILSVRC2012_val_00027132.bin 224 224 +14237 ./prep_dataset/ILSVRC2012_val_00000973.bin 224 224 +14238 ./prep_dataset/ILSVRC2012_val_00026640.bin 224 224 +14239 ./prep_dataset/ILSVRC2012_val_00015034.bin 224 224 +14240 ./prep_dataset/ILSVRC2012_val_00048003.bin 224 224 +14241 ./prep_dataset/ILSVRC2012_val_00047757.bin 224 224 +14242 ./prep_dataset/ILSVRC2012_val_00013005.bin 224 224 +14243 ./prep_dataset/ILSVRC2012_val_00035147.bin 224 224 +14244 ./prep_dataset/ILSVRC2012_val_00013384.bin 224 224 +14245 ./prep_dataset/ILSVRC2012_val_00026419.bin 224 224 +14246 ./prep_dataset/ILSVRC2012_val_00010689.bin 224 224 +14247 ./prep_dataset/ILSVRC2012_val_00033950.bin 224 224 +14248 ./prep_dataset/ILSVRC2012_val_00031338.bin 224 224 +14249 ./prep_dataset/ILSVRC2012_val_00029412.bin 224 224 +14250 ./prep_dataset/ILSVRC2012_val_00038177.bin 224 224 +14251 ./prep_dataset/ILSVRC2012_val_00001825.bin 224 224 +14252 ./prep_dataset/ILSVRC2012_val_00045241.bin 224 224 +14253 ./prep_dataset/ILSVRC2012_val_00030610.bin 224 224 +14254 ./prep_dataset/ILSVRC2012_val_00040058.bin 224 224 +14255 ./prep_dataset/ILSVRC2012_val_00000992.bin 224 224 +14256 ./prep_dataset/ILSVRC2012_val_00040678.bin 224 224 +14257 ./prep_dataset/ILSVRC2012_val_00011007.bin 224 224 +14258 ./prep_dataset/ILSVRC2012_val_00007079.bin 224 224 +14259 ./prep_dataset/ILSVRC2012_val_00008828.bin 224 224 +14260 ./prep_dataset/ILSVRC2012_val_00035837.bin 224 224 +14261 ./prep_dataset/ILSVRC2012_val_00029732.bin 224 224 +14262 ./prep_dataset/ILSVRC2012_val_00009060.bin 224 224 +14263 ./prep_dataset/ILSVRC2012_val_00020373.bin 224 224 +14264 ./prep_dataset/ILSVRC2012_val_00022429.bin 224 224 +14265 ./prep_dataset/ILSVRC2012_val_00047013.bin 224 224 +14266 ./prep_dataset/ILSVRC2012_val_00024701.bin 224 224 +14267 ./prep_dataset/ILSVRC2012_val_00046336.bin 224 224 +14268 ./prep_dataset/ILSVRC2012_val_00027066.bin 224 224 +14269 ./prep_dataset/ILSVRC2012_val_00022411.bin 224 224 +14270 ./prep_dataset/ILSVRC2012_val_00033358.bin 224 224 +14271 ./prep_dataset/ILSVRC2012_val_00017252.bin 224 224 +14272 ./prep_dataset/ILSVRC2012_val_00035755.bin 224 224 +14273 ./prep_dataset/ILSVRC2012_val_00041897.bin 224 224 +14274 ./prep_dataset/ILSVRC2012_val_00010695.bin 224 224 +14275 ./prep_dataset/ILSVRC2012_val_00002016.bin 224 224 +14276 ./prep_dataset/ILSVRC2012_val_00010742.bin 224 224 +14277 ./prep_dataset/ILSVRC2012_val_00028607.bin 224 224 +14278 ./prep_dataset/ILSVRC2012_val_00000035.bin 224 224 +14279 ./prep_dataset/ILSVRC2012_val_00022800.bin 224 224 +14280 ./prep_dataset/ILSVRC2012_val_00015144.bin 224 224 +14281 ./prep_dataset/ILSVRC2012_val_00046024.bin 224 224 +14282 ./prep_dataset/ILSVRC2012_val_00043295.bin 224 224 +14283 ./prep_dataset/ILSVRC2012_val_00026348.bin 224 224 +14284 ./prep_dataset/ILSVRC2012_val_00046326.bin 224 224 +14285 ./prep_dataset/ILSVRC2012_val_00002369.bin 224 224 +14286 ./prep_dataset/ILSVRC2012_val_00035345.bin 224 224 +14287 ./prep_dataset/ILSVRC2012_val_00003423.bin 224 224 +14288 ./prep_dataset/ILSVRC2012_val_00008321.bin 224 224 +14289 ./prep_dataset/ILSVRC2012_val_00019466.bin 224 224 +14290 ./prep_dataset/ILSVRC2012_val_00032656.bin 224 224 +14291 ./prep_dataset/ILSVRC2012_val_00024195.bin 224 224 +14292 ./prep_dataset/ILSVRC2012_val_00035074.bin 224 224 +14293 ./prep_dataset/ILSVRC2012_val_00023233.bin 224 224 +14294 ./prep_dataset/ILSVRC2012_val_00012690.bin 224 224 +14295 ./prep_dataset/ILSVRC2012_val_00037512.bin 224 224 +14296 ./prep_dataset/ILSVRC2012_val_00037930.bin 224 224 +14297 ./prep_dataset/ILSVRC2012_val_00005045.bin 224 224 +14298 ./prep_dataset/ILSVRC2012_val_00011327.bin 224 224 +14299 ./prep_dataset/ILSVRC2012_val_00025509.bin 224 224 +14300 ./prep_dataset/ILSVRC2012_val_00041936.bin 224 224 +14301 ./prep_dataset/ILSVRC2012_val_00020532.bin 224 224 +14302 ./prep_dataset/ILSVRC2012_val_00034516.bin 224 224 +14303 ./prep_dataset/ILSVRC2012_val_00033782.bin 224 224 +14304 ./prep_dataset/ILSVRC2012_val_00005406.bin 224 224 +14305 ./prep_dataset/ILSVRC2012_val_00030013.bin 224 224 +14306 ./prep_dataset/ILSVRC2012_val_00005162.bin 224 224 +14307 ./prep_dataset/ILSVRC2012_val_00027290.bin 224 224 +14308 ./prep_dataset/ILSVRC2012_val_00019814.bin 224 224 +14309 ./prep_dataset/ILSVRC2012_val_00041505.bin 224 224 +14310 ./prep_dataset/ILSVRC2012_val_00012169.bin 224 224 +14311 ./prep_dataset/ILSVRC2012_val_00033366.bin 224 224 +14312 ./prep_dataset/ILSVRC2012_val_00020983.bin 224 224 +14313 ./prep_dataset/ILSVRC2012_val_00026496.bin 224 224 +14314 ./prep_dataset/ILSVRC2012_val_00036987.bin 224 224 +14315 ./prep_dataset/ILSVRC2012_val_00032651.bin 224 224 +14316 ./prep_dataset/ILSVRC2012_val_00001559.bin 224 224 +14317 ./prep_dataset/ILSVRC2012_val_00029829.bin 224 224 +14318 ./prep_dataset/ILSVRC2012_val_00047939.bin 224 224 +14319 ./prep_dataset/ILSVRC2012_val_00013636.bin 224 224 +14320 ./prep_dataset/ILSVRC2012_val_00041003.bin 224 224 +14321 ./prep_dataset/ILSVRC2012_val_00036660.bin 224 224 +14322 ./prep_dataset/ILSVRC2012_val_00010954.bin 224 224 +14323 ./prep_dataset/ILSVRC2012_val_00046708.bin 224 224 +14324 ./prep_dataset/ILSVRC2012_val_00039393.bin 224 224 +14325 ./prep_dataset/ILSVRC2012_val_00000719.bin 224 224 +14326 ./prep_dataset/ILSVRC2012_val_00006917.bin 224 224 +14327 ./prep_dataset/ILSVRC2012_val_00044496.bin 224 224 +14328 ./prep_dataset/ILSVRC2012_val_00027423.bin 224 224 +14329 ./prep_dataset/ILSVRC2012_val_00002203.bin 224 224 +14330 ./prep_dataset/ILSVRC2012_val_00009440.bin 224 224 +14331 ./prep_dataset/ILSVRC2012_val_00018477.bin 224 224 +14332 ./prep_dataset/ILSVRC2012_val_00039417.bin 224 224 +14333 ./prep_dataset/ILSVRC2012_val_00031549.bin 224 224 +14334 ./prep_dataset/ILSVRC2012_val_00031956.bin 224 224 +14335 ./prep_dataset/ILSVRC2012_val_00001843.bin 224 224 +14336 ./prep_dataset/ILSVRC2012_val_00024520.bin 224 224 +14337 ./prep_dataset/ILSVRC2012_val_00019298.bin 224 224 +14338 ./prep_dataset/ILSVRC2012_val_00005642.bin 224 224 +14339 ./prep_dataset/ILSVRC2012_val_00033494.bin 224 224 +14340 ./prep_dataset/ILSVRC2012_val_00034874.bin 224 224 +14341 ./prep_dataset/ILSVRC2012_val_00045718.bin 224 224 +14342 ./prep_dataset/ILSVRC2012_val_00015787.bin 224 224 +14343 ./prep_dataset/ILSVRC2012_val_00017556.bin 224 224 +14344 ./prep_dataset/ILSVRC2012_val_00028283.bin 224 224 +14345 ./prep_dataset/ILSVRC2012_val_00024360.bin 224 224 +14346 ./prep_dataset/ILSVRC2012_val_00037072.bin 224 224 +14347 ./prep_dataset/ILSVRC2012_val_00004781.bin 224 224 +14348 ./prep_dataset/ILSVRC2012_val_00035410.bin 224 224 +14349 ./prep_dataset/ILSVRC2012_val_00000576.bin 224 224 +14350 ./prep_dataset/ILSVRC2012_val_00048092.bin 224 224 +14351 ./prep_dataset/ILSVRC2012_val_00028179.bin 224 224 +14352 ./prep_dataset/ILSVRC2012_val_00047806.bin 224 224 +14353 ./prep_dataset/ILSVRC2012_val_00040113.bin 224 224 +14354 ./prep_dataset/ILSVRC2012_val_00006114.bin 224 224 +14355 ./prep_dataset/ILSVRC2012_val_00031497.bin 224 224 +14356 ./prep_dataset/ILSVRC2012_val_00038988.bin 224 224 +14357 ./prep_dataset/ILSVRC2012_val_00019102.bin 224 224 +14358 ./prep_dataset/ILSVRC2012_val_00019287.bin 224 224 +14359 ./prep_dataset/ILSVRC2012_val_00000562.bin 224 224 +14360 ./prep_dataset/ILSVRC2012_val_00040532.bin 224 224 +14361 ./prep_dataset/ILSVRC2012_val_00035403.bin 224 224 +14362 ./prep_dataset/ILSVRC2012_val_00018230.bin 224 224 +14363 ./prep_dataset/ILSVRC2012_val_00018156.bin 224 224 +14364 ./prep_dataset/ILSVRC2012_val_00017036.bin 224 224 +14365 ./prep_dataset/ILSVRC2012_val_00030191.bin 224 224 +14366 ./prep_dataset/ILSVRC2012_val_00036969.bin 224 224 +14367 ./prep_dataset/ILSVRC2012_val_00048826.bin 224 224 +14368 ./prep_dataset/ILSVRC2012_val_00032154.bin 224 224 +14369 ./prep_dataset/ILSVRC2012_val_00013438.bin 224 224 +14370 ./prep_dataset/ILSVRC2012_val_00013085.bin 224 224 +14371 ./prep_dataset/ILSVRC2012_val_00021059.bin 224 224 +14372 ./prep_dataset/ILSVRC2012_val_00001345.bin 224 224 +14373 ./prep_dataset/ILSVRC2012_val_00011737.bin 224 224 +14374 ./prep_dataset/ILSVRC2012_val_00001951.bin 224 224 +14375 ./prep_dataset/ILSVRC2012_val_00004447.bin 224 224 +14376 ./prep_dataset/ILSVRC2012_val_00001622.bin 224 224 +14377 ./prep_dataset/ILSVRC2012_val_00028481.bin 224 224 +14378 ./prep_dataset/ILSVRC2012_val_00038443.bin 224 224 +14379 ./prep_dataset/ILSVRC2012_val_00027140.bin 224 224 +14380 ./prep_dataset/ILSVRC2012_val_00013591.bin 224 224 +14381 ./prep_dataset/ILSVRC2012_val_00037901.bin 224 224 +14382 ./prep_dataset/ILSVRC2012_val_00016002.bin 224 224 +14383 ./prep_dataset/ILSVRC2012_val_00019072.bin 224 224 +14384 ./prep_dataset/ILSVRC2012_val_00006878.bin 224 224 +14385 ./prep_dataset/ILSVRC2012_val_00049060.bin 224 224 +14386 ./prep_dataset/ILSVRC2012_val_00030750.bin 224 224 +14387 ./prep_dataset/ILSVRC2012_val_00009189.bin 224 224 +14388 ./prep_dataset/ILSVRC2012_val_00030356.bin 224 224 +14389 ./prep_dataset/ILSVRC2012_val_00047209.bin 224 224 +14390 ./prep_dataset/ILSVRC2012_val_00032142.bin 224 224 +14391 ./prep_dataset/ILSVRC2012_val_00019195.bin 224 224 +14392 ./prep_dataset/ILSVRC2012_val_00049903.bin 224 224 +14393 ./prep_dataset/ILSVRC2012_val_00032144.bin 224 224 +14394 ./prep_dataset/ILSVRC2012_val_00032298.bin 224 224 +14395 ./prep_dataset/ILSVRC2012_val_00013749.bin 224 224 +14396 ./prep_dataset/ILSVRC2012_val_00019787.bin 224 224 +14397 ./prep_dataset/ILSVRC2012_val_00020720.bin 224 224 +14398 ./prep_dataset/ILSVRC2012_val_00024185.bin 224 224 +14399 ./prep_dataset/ILSVRC2012_val_00023713.bin 224 224 +14400 ./prep_dataset/ILSVRC2012_val_00018628.bin 224 224 +14401 ./prep_dataset/ILSVRC2012_val_00041958.bin 224 224 +14402 ./prep_dataset/ILSVRC2012_val_00009241.bin 224 224 +14403 ./prep_dataset/ILSVRC2012_val_00015431.bin 224 224 +14404 ./prep_dataset/ILSVRC2012_val_00040457.bin 224 224 +14405 ./prep_dataset/ILSVRC2012_val_00037476.bin 224 224 +14406 ./prep_dataset/ILSVRC2012_val_00021382.bin 224 224 +14407 ./prep_dataset/ILSVRC2012_val_00033425.bin 224 224 +14408 ./prep_dataset/ILSVRC2012_val_00043392.bin 224 224 +14409 ./prep_dataset/ILSVRC2012_val_00045878.bin 224 224 +14410 ./prep_dataset/ILSVRC2012_val_00007472.bin 224 224 +14411 ./prep_dataset/ILSVRC2012_val_00007680.bin 224 224 +14412 ./prep_dataset/ILSVRC2012_val_00047632.bin 224 224 +14413 ./prep_dataset/ILSVRC2012_val_00044105.bin 224 224 +14414 ./prep_dataset/ILSVRC2012_val_00042396.bin 224 224 +14415 ./prep_dataset/ILSVRC2012_val_00026731.bin 224 224 +14416 ./prep_dataset/ILSVRC2012_val_00030823.bin 224 224 +14417 ./prep_dataset/ILSVRC2012_val_00000170.bin 224 224 +14418 ./prep_dataset/ILSVRC2012_val_00024120.bin 224 224 +14419 ./prep_dataset/ILSVRC2012_val_00003208.bin 224 224 +14420 ./prep_dataset/ILSVRC2012_val_00022554.bin 224 224 +14421 ./prep_dataset/ILSVRC2012_val_00024905.bin 224 224 +14422 ./prep_dataset/ILSVRC2012_val_00045787.bin 224 224 +14423 ./prep_dataset/ILSVRC2012_val_00020758.bin 224 224 +14424 ./prep_dataset/ILSVRC2012_val_00029801.bin 224 224 +14425 ./prep_dataset/ILSVRC2012_val_00036261.bin 224 224 +14426 ./prep_dataset/ILSVRC2012_val_00020215.bin 224 224 +14427 ./prep_dataset/ILSVRC2012_val_00040086.bin 224 224 +14428 ./prep_dataset/ILSVRC2012_val_00014402.bin 224 224 +14429 ./prep_dataset/ILSVRC2012_val_00027139.bin 224 224 +14430 ./prep_dataset/ILSVRC2012_val_00000082.bin 224 224 +14431 ./prep_dataset/ILSVRC2012_val_00037740.bin 224 224 +14432 ./prep_dataset/ILSVRC2012_val_00046324.bin 224 224 +14433 ./prep_dataset/ILSVRC2012_val_00007385.bin 224 224 +14434 ./prep_dataset/ILSVRC2012_val_00008844.bin 224 224 +14435 ./prep_dataset/ILSVRC2012_val_00040480.bin 224 224 +14436 ./prep_dataset/ILSVRC2012_val_00006773.bin 224 224 +14437 ./prep_dataset/ILSVRC2012_val_00017090.bin 224 224 +14438 ./prep_dataset/ILSVRC2012_val_00045574.bin 224 224 +14439 ./prep_dataset/ILSVRC2012_val_00028214.bin 224 224 +14440 ./prep_dataset/ILSVRC2012_val_00017084.bin 224 224 +14441 ./prep_dataset/ILSVRC2012_val_00024747.bin 224 224 +14442 ./prep_dataset/ILSVRC2012_val_00029085.bin 224 224 +14443 ./prep_dataset/ILSVRC2012_val_00026594.bin 224 224 +14444 ./prep_dataset/ILSVRC2012_val_00046241.bin 224 224 +14445 ./prep_dataset/ILSVRC2012_val_00007193.bin 224 224 +14446 ./prep_dataset/ILSVRC2012_val_00001877.bin 224 224 +14447 ./prep_dataset/ILSVRC2012_val_00011294.bin 224 224 +14448 ./prep_dataset/ILSVRC2012_val_00044138.bin 224 224 +14449 ./prep_dataset/ILSVRC2012_val_00022707.bin 224 224 +14450 ./prep_dataset/ILSVRC2012_val_00005707.bin 224 224 +14451 ./prep_dataset/ILSVRC2012_val_00032045.bin 224 224 +14452 ./prep_dataset/ILSVRC2012_val_00032643.bin 224 224 +14453 ./prep_dataset/ILSVRC2012_val_00019117.bin 224 224 +14454 ./prep_dataset/ILSVRC2012_val_00008446.bin 224 224 +14455 ./prep_dataset/ILSVRC2012_val_00038521.bin 224 224 +14456 ./prep_dataset/ILSVRC2012_val_00039440.bin 224 224 +14457 ./prep_dataset/ILSVRC2012_val_00034856.bin 224 224 +14458 ./prep_dataset/ILSVRC2012_val_00041829.bin 224 224 +14459 ./prep_dataset/ILSVRC2012_val_00025471.bin 224 224 +14460 ./prep_dataset/ILSVRC2012_val_00015211.bin 224 224 +14461 ./prep_dataset/ILSVRC2012_val_00031698.bin 224 224 +14462 ./prep_dataset/ILSVRC2012_val_00030048.bin 224 224 +14463 ./prep_dataset/ILSVRC2012_val_00033546.bin 224 224 +14464 ./prep_dataset/ILSVRC2012_val_00015485.bin 224 224 +14465 ./prep_dataset/ILSVRC2012_val_00014829.bin 224 224 +14466 ./prep_dataset/ILSVRC2012_val_00024464.bin 224 224 +14467 ./prep_dataset/ILSVRC2012_val_00023927.bin 224 224 +14468 ./prep_dataset/ILSVRC2012_val_00009753.bin 224 224 +14469 ./prep_dataset/ILSVRC2012_val_00030581.bin 224 224 +14470 ./prep_dataset/ILSVRC2012_val_00045202.bin 224 224 +14471 ./prep_dataset/ILSVRC2012_val_00038480.bin 224 224 +14472 ./prep_dataset/ILSVRC2012_val_00010082.bin 224 224 +14473 ./prep_dataset/ILSVRC2012_val_00005275.bin 224 224 +14474 ./prep_dataset/ILSVRC2012_val_00015608.bin 224 224 +14475 ./prep_dataset/ILSVRC2012_val_00041856.bin 224 224 +14476 ./prep_dataset/ILSVRC2012_val_00017830.bin 224 224 +14477 ./prep_dataset/ILSVRC2012_val_00008099.bin 224 224 +14478 ./prep_dataset/ILSVRC2012_val_00044606.bin 224 224 +14479 ./prep_dataset/ILSVRC2012_val_00020753.bin 224 224 +14480 ./prep_dataset/ILSVRC2012_val_00021814.bin 224 224 +14481 ./prep_dataset/ILSVRC2012_val_00041603.bin 224 224 +14482 ./prep_dataset/ILSVRC2012_val_00011746.bin 224 224 +14483 ./prep_dataset/ILSVRC2012_val_00006829.bin 224 224 +14484 ./prep_dataset/ILSVRC2012_val_00047081.bin 224 224 +14485 ./prep_dataset/ILSVRC2012_val_00038312.bin 224 224 +14486 ./prep_dataset/ILSVRC2012_val_00006325.bin 224 224 +14487 ./prep_dataset/ILSVRC2012_val_00015185.bin 224 224 +14488 ./prep_dataset/ILSVRC2012_val_00029495.bin 224 224 +14489 ./prep_dataset/ILSVRC2012_val_00019150.bin 224 224 +14490 ./prep_dataset/ILSVRC2012_val_00035260.bin 224 224 +14491 ./prep_dataset/ILSVRC2012_val_00001935.bin 224 224 +14492 ./prep_dataset/ILSVRC2012_val_00013924.bin 224 224 +14493 ./prep_dataset/ILSVRC2012_val_00022810.bin 224 224 +14494 ./prep_dataset/ILSVRC2012_val_00037873.bin 224 224 +14495 ./prep_dataset/ILSVRC2012_val_00001098.bin 224 224 +14496 ./prep_dataset/ILSVRC2012_val_00000006.bin 224 224 +14497 ./prep_dataset/ILSVRC2012_val_00005546.bin 224 224 +14498 ./prep_dataset/ILSVRC2012_val_00041446.bin 224 224 +14499 ./prep_dataset/ILSVRC2012_val_00000986.bin 224 224 +14500 ./prep_dataset/ILSVRC2012_val_00041707.bin 224 224 +14501 ./prep_dataset/ILSVRC2012_val_00015119.bin 224 224 +14502 ./prep_dataset/ILSVRC2012_val_00007367.bin 224 224 +14503 ./prep_dataset/ILSVRC2012_val_00033414.bin 224 224 +14504 ./prep_dataset/ILSVRC2012_val_00028994.bin 224 224 +14505 ./prep_dataset/ILSVRC2012_val_00024889.bin 224 224 +14506 ./prep_dataset/ILSVRC2012_val_00047668.bin 224 224 +14507 ./prep_dataset/ILSVRC2012_val_00043149.bin 224 224 +14508 ./prep_dataset/ILSVRC2012_val_00045900.bin 224 224 +14509 ./prep_dataset/ILSVRC2012_val_00010701.bin 224 224 +14510 ./prep_dataset/ILSVRC2012_val_00011365.bin 224 224 +14511 ./prep_dataset/ILSVRC2012_val_00028897.bin 224 224 +14512 ./prep_dataset/ILSVRC2012_val_00002687.bin 224 224 +14513 ./prep_dataset/ILSVRC2012_val_00005394.bin 224 224 +14514 ./prep_dataset/ILSVRC2012_val_00000224.bin 224 224 +14515 ./prep_dataset/ILSVRC2012_val_00047565.bin 224 224 +14516 ./prep_dataset/ILSVRC2012_val_00043165.bin 224 224 +14517 ./prep_dataset/ILSVRC2012_val_00020962.bin 224 224 +14518 ./prep_dataset/ILSVRC2012_val_00004040.bin 224 224 +14519 ./prep_dataset/ILSVRC2012_val_00004834.bin 224 224 +14520 ./prep_dataset/ILSVRC2012_val_00044888.bin 224 224 +14521 ./prep_dataset/ILSVRC2012_val_00020854.bin 224 224 +14522 ./prep_dataset/ILSVRC2012_val_00024463.bin 224 224 +14523 ./prep_dataset/ILSVRC2012_val_00009332.bin 224 224 +14524 ./prep_dataset/ILSVRC2012_val_00012417.bin 224 224 +14525 ./prep_dataset/ILSVRC2012_val_00001348.bin 224 224 +14526 ./prep_dataset/ILSVRC2012_val_00025749.bin 224 224 +14527 ./prep_dataset/ILSVRC2012_val_00018285.bin 224 224 +14528 ./prep_dataset/ILSVRC2012_val_00014525.bin 224 224 +14529 ./prep_dataset/ILSVRC2012_val_00021631.bin 224 224 +14530 ./prep_dataset/ILSVRC2012_val_00004594.bin 224 224 +14531 ./prep_dataset/ILSVRC2012_val_00040255.bin 224 224 +14532 ./prep_dataset/ILSVRC2012_val_00028683.bin 224 224 +14533 ./prep_dataset/ILSVRC2012_val_00032191.bin 224 224 +14534 ./prep_dataset/ILSVRC2012_val_00042503.bin 224 224 +14535 ./prep_dataset/ILSVRC2012_val_00025864.bin 224 224 +14536 ./prep_dataset/ILSVRC2012_val_00027027.bin 224 224 +14537 ./prep_dataset/ILSVRC2012_val_00037754.bin 224 224 +14538 ./prep_dataset/ILSVRC2012_val_00016051.bin 224 224 +14539 ./prep_dataset/ILSVRC2012_val_00034935.bin 224 224 +14540 ./prep_dataset/ILSVRC2012_val_00010010.bin 224 224 +14541 ./prep_dataset/ILSVRC2012_val_00020916.bin 224 224 +14542 ./prep_dataset/ILSVRC2012_val_00000112.bin 224 224 +14543 ./prep_dataset/ILSVRC2012_val_00042514.bin 224 224 +14544 ./prep_dataset/ILSVRC2012_val_00049044.bin 224 224 +14545 ./prep_dataset/ILSVRC2012_val_00004319.bin 224 224 +14546 ./prep_dataset/ILSVRC2012_val_00014009.bin 224 224 +14547 ./prep_dataset/ILSVRC2012_val_00032688.bin 224 224 +14548 ./prep_dataset/ILSVRC2012_val_00040708.bin 224 224 +14549 ./prep_dataset/ILSVRC2012_val_00024513.bin 224 224 +14550 ./prep_dataset/ILSVRC2012_val_00008332.bin 224 224 +14551 ./prep_dataset/ILSVRC2012_val_00044502.bin 224 224 +14552 ./prep_dataset/ILSVRC2012_val_00008147.bin 224 224 +14553 ./prep_dataset/ILSVRC2012_val_00015267.bin 224 224 +14554 ./prep_dataset/ILSVRC2012_val_00047300.bin 224 224 +14555 ./prep_dataset/ILSVRC2012_val_00008729.bin 224 224 +14556 ./prep_dataset/ILSVRC2012_val_00045578.bin 224 224 +14557 ./prep_dataset/ILSVRC2012_val_00024199.bin 224 224 +14558 ./prep_dataset/ILSVRC2012_val_00017132.bin 224 224 +14559 ./prep_dataset/ILSVRC2012_val_00011984.bin 224 224 +14560 ./prep_dataset/ILSVRC2012_val_00038036.bin 224 224 +14561 ./prep_dataset/ILSVRC2012_val_00000064.bin 224 224 +14562 ./prep_dataset/ILSVRC2012_val_00015342.bin 224 224 +14563 ./prep_dataset/ILSVRC2012_val_00041148.bin 224 224 +14564 ./prep_dataset/ILSVRC2012_val_00021234.bin 224 224 +14565 ./prep_dataset/ILSVRC2012_val_00000745.bin 224 224 +14566 ./prep_dataset/ILSVRC2012_val_00048931.bin 224 224 +14567 ./prep_dataset/ILSVRC2012_val_00035448.bin 224 224 +14568 ./prep_dataset/ILSVRC2012_val_00010768.bin 224 224 +14569 ./prep_dataset/ILSVRC2012_val_00014626.bin 224 224 +14570 ./prep_dataset/ILSVRC2012_val_00038048.bin 224 224 +14571 ./prep_dataset/ILSVRC2012_val_00045264.bin 224 224 +14572 ./prep_dataset/ILSVRC2012_val_00042363.bin 224 224 +14573 ./prep_dataset/ILSVRC2012_val_00009889.bin 224 224 +14574 ./prep_dataset/ILSVRC2012_val_00030758.bin 224 224 +14575 ./prep_dataset/ILSVRC2012_val_00027183.bin 224 224 +14576 ./prep_dataset/ILSVRC2012_val_00022109.bin 224 224 +14577 ./prep_dataset/ILSVRC2012_val_00018778.bin 224 224 +14578 ./prep_dataset/ILSVRC2012_val_00042857.bin 224 224 +14579 ./prep_dataset/ILSVRC2012_val_00037241.bin 224 224 +14580 ./prep_dataset/ILSVRC2012_val_00033752.bin 224 224 +14581 ./prep_dataset/ILSVRC2012_val_00032357.bin 224 224 +14582 ./prep_dataset/ILSVRC2012_val_00010073.bin 224 224 +14583 ./prep_dataset/ILSVRC2012_val_00020015.bin 224 224 +14584 ./prep_dataset/ILSVRC2012_val_00031203.bin 224 224 +14585 ./prep_dataset/ILSVRC2012_val_00026678.bin 224 224 +14586 ./prep_dataset/ILSVRC2012_val_00018112.bin 224 224 +14587 ./prep_dataset/ILSVRC2012_val_00021910.bin 224 224 +14588 ./prep_dataset/ILSVRC2012_val_00040915.bin 224 224 +14589 ./prep_dataset/ILSVRC2012_val_00044861.bin 224 224 +14590 ./prep_dataset/ILSVRC2012_val_00040449.bin 224 224 +14591 ./prep_dataset/ILSVRC2012_val_00038505.bin 224 224 +14592 ./prep_dataset/ILSVRC2012_val_00042165.bin 224 224 +14593 ./prep_dataset/ILSVRC2012_val_00006142.bin 224 224 +14594 ./prep_dataset/ILSVRC2012_val_00001658.bin 224 224 +14595 ./prep_dataset/ILSVRC2012_val_00040166.bin 224 224 +14596 ./prep_dataset/ILSVRC2012_val_00009227.bin 224 224 +14597 ./prep_dataset/ILSVRC2012_val_00001464.bin 224 224 +14598 ./prep_dataset/ILSVRC2012_val_00021087.bin 224 224 +14599 ./prep_dataset/ILSVRC2012_val_00048834.bin 224 224 +14600 ./prep_dataset/ILSVRC2012_val_00043614.bin 224 224 +14601 ./prep_dataset/ILSVRC2012_val_00015861.bin 224 224 +14602 ./prep_dataset/ILSVRC2012_val_00034352.bin 224 224 +14603 ./prep_dataset/ILSVRC2012_val_00031798.bin 224 224 +14604 ./prep_dataset/ILSVRC2012_val_00020230.bin 224 224 +14605 ./prep_dataset/ILSVRC2012_val_00006655.bin 224 224 +14606 ./prep_dataset/ILSVRC2012_val_00048250.bin 224 224 +14607 ./prep_dataset/ILSVRC2012_val_00010150.bin 224 224 +14608 ./prep_dataset/ILSVRC2012_val_00009302.bin 224 224 +14609 ./prep_dataset/ILSVRC2012_val_00005803.bin 224 224 +14610 ./prep_dataset/ILSVRC2012_val_00008672.bin 224 224 +14611 ./prep_dataset/ILSVRC2012_val_00026448.bin 224 224 +14612 ./prep_dataset/ILSVRC2012_val_00036479.bin 224 224 +14613 ./prep_dataset/ILSVRC2012_val_00041968.bin 224 224 +14614 ./prep_dataset/ILSVRC2012_val_00025403.bin 224 224 +14615 ./prep_dataset/ILSVRC2012_val_00030361.bin 224 224 +14616 ./prep_dataset/ILSVRC2012_val_00004603.bin 224 224 +14617 ./prep_dataset/ILSVRC2012_val_00007313.bin 224 224 +14618 ./prep_dataset/ILSVRC2012_val_00044691.bin 224 224 +14619 ./prep_dataset/ILSVRC2012_val_00043859.bin 224 224 +14620 ./prep_dataset/ILSVRC2012_val_00008054.bin 224 224 +14621 ./prep_dataset/ILSVRC2012_val_00034093.bin 224 224 +14622 ./prep_dataset/ILSVRC2012_val_00032723.bin 224 224 +14623 ./prep_dataset/ILSVRC2012_val_00030300.bin 224 224 +14624 ./prep_dataset/ILSVRC2012_val_00016707.bin 224 224 +14625 ./prep_dataset/ILSVRC2012_val_00032053.bin 224 224 +14626 ./prep_dataset/ILSVRC2012_val_00041536.bin 224 224 +14627 ./prep_dataset/ILSVRC2012_val_00046911.bin 224 224 +14628 ./prep_dataset/ILSVRC2012_val_00046779.bin 224 224 +14629 ./prep_dataset/ILSVRC2012_val_00049180.bin 224 224 +14630 ./prep_dataset/ILSVRC2012_val_00033942.bin 224 224 +14631 ./prep_dataset/ILSVRC2012_val_00030703.bin 224 224 +14632 ./prep_dataset/ILSVRC2012_val_00028532.bin 224 224 +14633 ./prep_dataset/ILSVRC2012_val_00024938.bin 224 224 +14634 ./prep_dataset/ILSVRC2012_val_00004670.bin 224 224 +14635 ./prep_dataset/ILSVRC2012_val_00046455.bin 224 224 +14636 ./prep_dataset/ILSVRC2012_val_00004248.bin 224 224 +14637 ./prep_dataset/ILSVRC2012_val_00030234.bin 224 224 +14638 ./prep_dataset/ILSVRC2012_val_00012942.bin 224 224 +14639 ./prep_dataset/ILSVRC2012_val_00026601.bin 224 224 +14640 ./prep_dataset/ILSVRC2012_val_00013495.bin 224 224 +14641 ./prep_dataset/ILSVRC2012_val_00015315.bin 224 224 +14642 ./prep_dataset/ILSVRC2012_val_00012549.bin 224 224 +14643 ./prep_dataset/ILSVRC2012_val_00023708.bin 224 224 +14644 ./prep_dataset/ILSVRC2012_val_00036619.bin 224 224 +14645 ./prep_dataset/ILSVRC2012_val_00007417.bin 224 224 +14646 ./prep_dataset/ILSVRC2012_val_00001514.bin 224 224 +14647 ./prep_dataset/ILSVRC2012_val_00046928.bin 224 224 +14648 ./prep_dataset/ILSVRC2012_val_00027744.bin 224 224 +14649 ./prep_dataset/ILSVRC2012_val_00029162.bin 224 224 +14650 ./prep_dataset/ILSVRC2012_val_00019667.bin 224 224 +14651 ./prep_dataset/ILSVRC2012_val_00032650.bin 224 224 +14652 ./prep_dataset/ILSVRC2012_val_00027169.bin 224 224 +14653 ./prep_dataset/ILSVRC2012_val_00039010.bin 224 224 +14654 ./prep_dataset/ILSVRC2012_val_00006070.bin 224 224 +14655 ./prep_dataset/ILSVRC2012_val_00038197.bin 224 224 +14656 ./prep_dataset/ILSVRC2012_val_00011498.bin 224 224 +14657 ./prep_dataset/ILSVRC2012_val_00006572.bin 224 224 +14658 ./prep_dataset/ILSVRC2012_val_00016678.bin 224 224 +14659 ./prep_dataset/ILSVRC2012_val_00009180.bin 224 224 +14660 ./prep_dataset/ILSVRC2012_val_00005787.bin 224 224 +14661 ./prep_dataset/ILSVRC2012_val_00025909.bin 224 224 +14662 ./prep_dataset/ILSVRC2012_val_00044968.bin 224 224 +14663 ./prep_dataset/ILSVRC2012_val_00004266.bin 224 224 +14664 ./prep_dataset/ILSVRC2012_val_00024709.bin 224 224 +14665 ./prep_dataset/ILSVRC2012_val_00029876.bin 224 224 +14666 ./prep_dataset/ILSVRC2012_val_00049952.bin 224 224 +14667 ./prep_dataset/ILSVRC2012_val_00008662.bin 224 224 +14668 ./prep_dataset/ILSVRC2012_val_00039505.bin 224 224 +14669 ./prep_dataset/ILSVRC2012_val_00022293.bin 224 224 +14670 ./prep_dataset/ILSVRC2012_val_00039756.bin 224 224 +14671 ./prep_dataset/ILSVRC2012_val_00032057.bin 224 224 +14672 ./prep_dataset/ILSVRC2012_val_00048757.bin 224 224 +14673 ./prep_dataset/ILSVRC2012_val_00040019.bin 224 224 +14674 ./prep_dataset/ILSVRC2012_val_00005620.bin 224 224 +14675 ./prep_dataset/ILSVRC2012_val_00025061.bin 224 224 +14676 ./prep_dataset/ILSVRC2012_val_00005420.bin 224 224 +14677 ./prep_dataset/ILSVRC2012_val_00013565.bin 224 224 +14678 ./prep_dataset/ILSVRC2012_val_00000937.bin 224 224 +14679 ./prep_dataset/ILSVRC2012_val_00000253.bin 224 224 +14680 ./prep_dataset/ILSVRC2012_val_00007361.bin 224 224 +14681 ./prep_dataset/ILSVRC2012_val_00024401.bin 224 224 +14682 ./prep_dataset/ILSVRC2012_val_00022464.bin 224 224 +14683 ./prep_dataset/ILSVRC2012_val_00002208.bin 224 224 +14684 ./prep_dataset/ILSVRC2012_val_00009947.bin 224 224 +14685 ./prep_dataset/ILSVRC2012_val_00037323.bin 224 224 +14686 ./prep_dataset/ILSVRC2012_val_00041641.bin 224 224 +14687 ./prep_dataset/ILSVRC2012_val_00002385.bin 224 224 +14688 ./prep_dataset/ILSVRC2012_val_00036079.bin 224 224 +14689 ./prep_dataset/ILSVRC2012_val_00030672.bin 224 224 +14690 ./prep_dataset/ILSVRC2012_val_00035050.bin 224 224 +14691 ./prep_dataset/ILSVRC2012_val_00048023.bin 224 224 +14692 ./prep_dataset/ILSVRC2012_val_00038761.bin 224 224 +14693 ./prep_dataset/ILSVRC2012_val_00042844.bin 224 224 +14694 ./prep_dataset/ILSVRC2012_val_00049558.bin 224 224 +14695 ./prep_dataset/ILSVRC2012_val_00004687.bin 224 224 +14696 ./prep_dataset/ILSVRC2012_val_00038122.bin 224 224 +14697 ./prep_dataset/ILSVRC2012_val_00016062.bin 224 224 +14698 ./prep_dataset/ILSVRC2012_val_00006729.bin 224 224 +14699 ./prep_dataset/ILSVRC2012_val_00033031.bin 224 224 +14700 ./prep_dataset/ILSVRC2012_val_00000868.bin 224 224 +14701 ./prep_dataset/ILSVRC2012_val_00049533.bin 224 224 +14702 ./prep_dataset/ILSVRC2012_val_00010381.bin 224 224 +14703 ./prep_dataset/ILSVRC2012_val_00026100.bin 224 224 +14704 ./prep_dataset/ILSVRC2012_val_00038391.bin 224 224 +14705 ./prep_dataset/ILSVRC2012_val_00034260.bin 224 224 +14706 ./prep_dataset/ILSVRC2012_val_00036280.bin 224 224 +14707 ./prep_dataset/ILSVRC2012_val_00016015.bin 224 224 +14708 ./prep_dataset/ILSVRC2012_val_00009147.bin 224 224 +14709 ./prep_dataset/ILSVRC2012_val_00014146.bin 224 224 +14710 ./prep_dataset/ILSVRC2012_val_00048627.bin 224 224 +14711 ./prep_dataset/ILSVRC2012_val_00020342.bin 224 224 +14712 ./prep_dataset/ILSVRC2012_val_00036431.bin 224 224 +14713 ./prep_dataset/ILSVRC2012_val_00000305.bin 224 224 +14714 ./prep_dataset/ILSVRC2012_val_00042157.bin 224 224 +14715 ./prep_dataset/ILSVRC2012_val_00042417.bin 224 224 +14716 ./prep_dataset/ILSVRC2012_val_00028193.bin 224 224 +14717 ./prep_dataset/ILSVRC2012_val_00036371.bin 224 224 +14718 ./prep_dataset/ILSVRC2012_val_00024990.bin 224 224 +14719 ./prep_dataset/ILSVRC2012_val_00014433.bin 224 224 +14720 ./prep_dataset/ILSVRC2012_val_00008414.bin 224 224 +14721 ./prep_dataset/ILSVRC2012_val_00022307.bin 224 224 +14722 ./prep_dataset/ILSVRC2012_val_00025768.bin 224 224 +14723 ./prep_dataset/ILSVRC2012_val_00020430.bin 224 224 +14724 ./prep_dataset/ILSVRC2012_val_00043513.bin 224 224 +14725 ./prep_dataset/ILSVRC2012_val_00007730.bin 224 224 +14726 ./prep_dataset/ILSVRC2012_val_00013763.bin 224 224 +14727 ./prep_dataset/ILSVRC2012_val_00038980.bin 224 224 +14728 ./prep_dataset/ILSVRC2012_val_00045975.bin 224 224 +14729 ./prep_dataset/ILSVRC2012_val_00011551.bin 224 224 +14730 ./prep_dataset/ILSVRC2012_val_00032799.bin 224 224 +14731 ./prep_dataset/ILSVRC2012_val_00015430.bin 224 224 +14732 ./prep_dataset/ILSVRC2012_val_00000798.bin 224 224 +14733 ./prep_dataset/ILSVRC2012_val_00010514.bin 224 224 +14734 ./prep_dataset/ILSVRC2012_val_00042460.bin 224 224 +14735 ./prep_dataset/ILSVRC2012_val_00046293.bin 224 224 +14736 ./prep_dataset/ILSVRC2012_val_00018413.bin 224 224 +14737 ./prep_dataset/ILSVRC2012_val_00049523.bin 224 224 +14738 ./prep_dataset/ILSVRC2012_val_00026967.bin 224 224 +14739 ./prep_dataset/ILSVRC2012_val_00010480.bin 224 224 +14740 ./prep_dataset/ILSVRC2012_val_00044677.bin 224 224 +14741 ./prep_dataset/ILSVRC2012_val_00042633.bin 224 224 +14742 ./prep_dataset/ILSVRC2012_val_00007795.bin 224 224 +14743 ./prep_dataset/ILSVRC2012_val_00023943.bin 224 224 +14744 ./prep_dataset/ILSVRC2012_val_00029357.bin 224 224 +14745 ./prep_dataset/ILSVRC2012_val_00005721.bin 224 224 +14746 ./prep_dataset/ILSVRC2012_val_00009629.bin 224 224 +14747 ./prep_dataset/ILSVRC2012_val_00035065.bin 224 224 +14748 ./prep_dataset/ILSVRC2012_val_00021895.bin 224 224 +14749 ./prep_dataset/ILSVRC2012_val_00019003.bin 224 224 +14750 ./prep_dataset/ILSVRC2012_val_00022443.bin 224 224 +14751 ./prep_dataset/ILSVRC2012_val_00006752.bin 224 224 +14752 ./prep_dataset/ILSVRC2012_val_00014375.bin 224 224 +14753 ./prep_dataset/ILSVRC2012_val_00015376.bin 224 224 +14754 ./prep_dataset/ILSVRC2012_val_00040106.bin 224 224 +14755 ./prep_dataset/ILSVRC2012_val_00025668.bin 224 224 +14756 ./prep_dataset/ILSVRC2012_val_00038143.bin 224 224 +14757 ./prep_dataset/ILSVRC2012_val_00029200.bin 224 224 +14758 ./prep_dataset/ILSVRC2012_val_00044485.bin 224 224 +14759 ./prep_dataset/ILSVRC2012_val_00005254.bin 224 224 +14760 ./prep_dataset/ILSVRC2012_val_00003295.bin 224 224 +14761 ./prep_dataset/ILSVRC2012_val_00048189.bin 224 224 +14762 ./prep_dataset/ILSVRC2012_val_00005473.bin 224 224 +14763 ./prep_dataset/ILSVRC2012_val_00024115.bin 224 224 +14764 ./prep_dataset/ILSVRC2012_val_00013084.bin 224 224 +14765 ./prep_dataset/ILSVRC2012_val_00027163.bin 224 224 +14766 ./prep_dataset/ILSVRC2012_val_00038090.bin 224 224 +14767 ./prep_dataset/ILSVRC2012_val_00047955.bin 224 224 +14768 ./prep_dataset/ILSVRC2012_val_00049875.bin 224 224 +14769 ./prep_dataset/ILSVRC2012_val_00037361.bin 224 224 +14770 ./prep_dataset/ILSVRC2012_val_00006864.bin 224 224 +14771 ./prep_dataset/ILSVRC2012_val_00045998.bin 224 224 +14772 ./prep_dataset/ILSVRC2012_val_00004367.bin 224 224 +14773 ./prep_dataset/ILSVRC2012_val_00010910.bin 224 224 +14774 ./prep_dataset/ILSVRC2012_val_00014374.bin 224 224 +14775 ./prep_dataset/ILSVRC2012_val_00004007.bin 224 224 +14776 ./prep_dataset/ILSVRC2012_val_00009065.bin 224 224 +14777 ./prep_dataset/ILSVRC2012_val_00016908.bin 224 224 +14778 ./prep_dataset/ILSVRC2012_val_00015979.bin 224 224 +14779 ./prep_dataset/ILSVRC2012_val_00014242.bin 224 224 +14780 ./prep_dataset/ILSVRC2012_val_00040431.bin 224 224 +14781 ./prep_dataset/ILSVRC2012_val_00047670.bin 224 224 +14782 ./prep_dataset/ILSVRC2012_val_00041263.bin 224 224 +14783 ./prep_dataset/ILSVRC2012_val_00012735.bin 224 224 +14784 ./prep_dataset/ILSVRC2012_val_00031261.bin 224 224 +14785 ./prep_dataset/ILSVRC2012_val_00008108.bin 224 224 +14786 ./prep_dataset/ILSVRC2012_val_00024949.bin 224 224 +14787 ./prep_dataset/ILSVRC2012_val_00021524.bin 224 224 +14788 ./prep_dataset/ILSVRC2012_val_00006098.bin 224 224 +14789 ./prep_dataset/ILSVRC2012_val_00004106.bin 224 224 +14790 ./prep_dataset/ILSVRC2012_val_00010419.bin 224 224 +14791 ./prep_dataset/ILSVRC2012_val_00038870.bin 224 224 +14792 ./prep_dataset/ILSVRC2012_val_00041802.bin 224 224 +14793 ./prep_dataset/ILSVRC2012_val_00021009.bin 224 224 +14794 ./prep_dataset/ILSVRC2012_val_00015563.bin 224 224 +14795 ./prep_dataset/ILSVRC2012_val_00018306.bin 224 224 +14796 ./prep_dataset/ILSVRC2012_val_00040947.bin 224 224 +14797 ./prep_dataset/ILSVRC2012_val_00001382.bin 224 224 +14798 ./prep_dataset/ILSVRC2012_val_00041808.bin 224 224 +14799 ./prep_dataset/ILSVRC2012_val_00000427.bin 224 224 +14800 ./prep_dataset/ILSVRC2012_val_00043840.bin 224 224 +14801 ./prep_dataset/ILSVRC2012_val_00024773.bin 224 224 +14802 ./prep_dataset/ILSVRC2012_val_00034834.bin 224 224 +14803 ./prep_dataset/ILSVRC2012_val_00023737.bin 224 224 +14804 ./prep_dataset/ILSVRC2012_val_00026525.bin 224 224 +14805 ./prep_dataset/ILSVRC2012_val_00015572.bin 224 224 +14806 ./prep_dataset/ILSVRC2012_val_00007128.bin 224 224 +14807 ./prep_dataset/ILSVRC2012_val_00021287.bin 224 224 +14808 ./prep_dataset/ILSVRC2012_val_00002505.bin 224 224 +14809 ./prep_dataset/ILSVRC2012_val_00001768.bin 224 224 +14810 ./prep_dataset/ILSVRC2012_val_00011850.bin 224 224 +14811 ./prep_dataset/ILSVRC2012_val_00020607.bin 224 224 +14812 ./prep_dataset/ILSVRC2012_val_00030369.bin 224 224 +14813 ./prep_dataset/ILSVRC2012_val_00017022.bin 224 224 +14814 ./prep_dataset/ILSVRC2012_val_00034860.bin 224 224 +14815 ./prep_dataset/ILSVRC2012_val_00014907.bin 224 224 +14816 ./prep_dataset/ILSVRC2012_val_00014319.bin 224 224 +14817 ./prep_dataset/ILSVRC2012_val_00028663.bin 224 224 +14818 ./prep_dataset/ILSVRC2012_val_00014016.bin 224 224 +14819 ./prep_dataset/ILSVRC2012_val_00047413.bin 224 224 +14820 ./prep_dataset/ILSVRC2012_val_00017164.bin 224 224 +14821 ./prep_dataset/ILSVRC2012_val_00014469.bin 224 224 +14822 ./prep_dataset/ILSVRC2012_val_00029682.bin 224 224 +14823 ./prep_dataset/ILSVRC2012_val_00039604.bin 224 224 +14824 ./prep_dataset/ILSVRC2012_val_00042707.bin 224 224 +14825 ./prep_dataset/ILSVRC2012_val_00014891.bin 224 224 +14826 ./prep_dataset/ILSVRC2012_val_00029637.bin 224 224 +14827 ./prep_dataset/ILSVRC2012_val_00001170.bin 224 224 +14828 ./prep_dataset/ILSVRC2012_val_00008370.bin 224 224 +14829 ./prep_dataset/ILSVRC2012_val_00017975.bin 224 224 +14830 ./prep_dataset/ILSVRC2012_val_00012744.bin 224 224 +14831 ./prep_dataset/ILSVRC2012_val_00047077.bin 224 224 +14832 ./prep_dataset/ILSVRC2012_val_00027246.bin 224 224 +14833 ./prep_dataset/ILSVRC2012_val_00017774.bin 224 224 +14834 ./prep_dataset/ILSVRC2012_val_00002454.bin 224 224 +14835 ./prep_dataset/ILSVRC2012_val_00018874.bin 224 224 +14836 ./prep_dataset/ILSVRC2012_val_00001711.bin 224 224 +14837 ./prep_dataset/ILSVRC2012_val_00043853.bin 224 224 +14838 ./prep_dataset/ILSVRC2012_val_00032227.bin 224 224 +14839 ./prep_dataset/ILSVRC2012_val_00012602.bin 224 224 +14840 ./prep_dataset/ILSVRC2012_val_00003200.bin 224 224 +14841 ./prep_dataset/ILSVRC2012_val_00049549.bin 224 224 +14842 ./prep_dataset/ILSVRC2012_val_00038613.bin 224 224 +14843 ./prep_dataset/ILSVRC2012_val_00035247.bin 224 224 +14844 ./prep_dataset/ILSVRC2012_val_00000268.bin 224 224 +14845 ./prep_dataset/ILSVRC2012_val_00014608.bin 224 224 +14846 ./prep_dataset/ILSVRC2012_val_00043146.bin 224 224 +14847 ./prep_dataset/ILSVRC2012_val_00041859.bin 224 224 +14848 ./prep_dataset/ILSVRC2012_val_00040983.bin 224 224 +14849 ./prep_dataset/ILSVRC2012_val_00025015.bin 224 224 +14850 ./prep_dataset/ILSVRC2012_val_00019684.bin 224 224 +14851 ./prep_dataset/ILSVRC2012_val_00025919.bin 224 224 +14852 ./prep_dataset/ILSVRC2012_val_00004299.bin 224 224 +14853 ./prep_dataset/ILSVRC2012_val_00002382.bin 224 224 +14854 ./prep_dataset/ILSVRC2012_val_00041336.bin 224 224 +14855 ./prep_dataset/ILSVRC2012_val_00023034.bin 224 224 +14856 ./prep_dataset/ILSVRC2012_val_00014315.bin 224 224 +14857 ./prep_dataset/ILSVRC2012_val_00023899.bin 224 224 +14858 ./prep_dataset/ILSVRC2012_val_00033763.bin 224 224 +14859 ./prep_dataset/ILSVRC2012_val_00043293.bin 224 224 +14860 ./prep_dataset/ILSVRC2012_val_00009097.bin 224 224 +14861 ./prep_dataset/ILSVRC2012_val_00036498.bin 224 224 +14862 ./prep_dataset/ILSVRC2012_val_00047371.bin 224 224 +14863 ./prep_dataset/ILSVRC2012_val_00030970.bin 224 224 +14864 ./prep_dataset/ILSVRC2012_val_00028011.bin 224 224 +14865 ./prep_dataset/ILSVRC2012_val_00034512.bin 224 224 +14866 ./prep_dataset/ILSVRC2012_val_00013101.bin 224 224 +14867 ./prep_dataset/ILSVRC2012_val_00005470.bin 224 224 +14868 ./prep_dataset/ILSVRC2012_val_00005460.bin 224 224 +14869 ./prep_dataset/ILSVRC2012_val_00001874.bin 224 224 +14870 ./prep_dataset/ILSVRC2012_val_00037369.bin 224 224 +14871 ./prep_dataset/ILSVRC2012_val_00038205.bin 224 224 +14872 ./prep_dataset/ILSVRC2012_val_00042816.bin 224 224 +14873 ./prep_dataset/ILSVRC2012_val_00002413.bin 224 224 +14874 ./prep_dataset/ILSVRC2012_val_00012615.bin 224 224 +14875 ./prep_dataset/ILSVRC2012_val_00024869.bin 224 224 +14876 ./prep_dataset/ILSVRC2012_val_00038804.bin 224 224 +14877 ./prep_dataset/ILSVRC2012_val_00007916.bin 224 224 +14878 ./prep_dataset/ILSVRC2012_val_00034126.bin 224 224 +14879 ./prep_dataset/ILSVRC2012_val_00011010.bin 224 224 +14880 ./prep_dataset/ILSVRC2012_val_00010598.bin 224 224 +14881 ./prep_dataset/ILSVRC2012_val_00020346.bin 224 224 +14882 ./prep_dataset/ILSVRC2012_val_00032947.bin 224 224 +14883 ./prep_dataset/ILSVRC2012_val_00049747.bin 224 224 +14884 ./prep_dataset/ILSVRC2012_val_00003180.bin 224 224 +14885 ./prep_dataset/ILSVRC2012_val_00023623.bin 224 224 +14886 ./prep_dataset/ILSVRC2012_val_00024560.bin 224 224 +14887 ./prep_dataset/ILSVRC2012_val_00006720.bin 224 224 +14888 ./prep_dataset/ILSVRC2012_val_00028016.bin 224 224 +14889 ./prep_dataset/ILSVRC2012_val_00045755.bin 224 224 +14890 ./prep_dataset/ILSVRC2012_val_00003895.bin 224 224 +14891 ./prep_dataset/ILSVRC2012_val_00000507.bin 224 224 +14892 ./prep_dataset/ILSVRC2012_val_00025665.bin 224 224 +14893 ./prep_dataset/ILSVRC2012_val_00043514.bin 224 224 +14894 ./prep_dataset/ILSVRC2012_val_00049679.bin 224 224 +14895 ./prep_dataset/ILSVRC2012_val_00006982.bin 224 224 +14896 ./prep_dataset/ILSVRC2012_val_00048567.bin 224 224 +14897 ./prep_dataset/ILSVRC2012_val_00023088.bin 224 224 +14898 ./prep_dataset/ILSVRC2012_val_00018660.bin 224 224 +14899 ./prep_dataset/ILSVRC2012_val_00005502.bin 224 224 +14900 ./prep_dataset/ILSVRC2012_val_00046240.bin 224 224 +14901 ./prep_dataset/ILSVRC2012_val_00019493.bin 224 224 +14902 ./prep_dataset/ILSVRC2012_val_00020146.bin 224 224 +14903 ./prep_dataset/ILSVRC2012_val_00038150.bin 224 224 +14904 ./prep_dataset/ILSVRC2012_val_00019164.bin 224 224 +14905 ./prep_dataset/ILSVRC2012_val_00000524.bin 224 224 +14906 ./prep_dataset/ILSVRC2012_val_00035239.bin 224 224 +14907 ./prep_dataset/ILSVRC2012_val_00000789.bin 224 224 +14908 ./prep_dataset/ILSVRC2012_val_00048796.bin 224 224 +14909 ./prep_dataset/ILSVRC2012_val_00010255.bin 224 224 +14910 ./prep_dataset/ILSVRC2012_val_00036801.bin 224 224 +14911 ./prep_dataset/ILSVRC2012_val_00013052.bin 224 224 +14912 ./prep_dataset/ILSVRC2012_val_00046504.bin 224 224 +14913 ./prep_dataset/ILSVRC2012_val_00021625.bin 224 224 +14914 ./prep_dataset/ILSVRC2012_val_00001558.bin 224 224 +14915 ./prep_dataset/ILSVRC2012_val_00035252.bin 224 224 +14916 ./prep_dataset/ILSVRC2012_val_00045065.bin 224 224 +14917 ./prep_dataset/ILSVRC2012_val_00025619.bin 224 224 +14918 ./prep_dataset/ILSVRC2012_val_00036771.bin 224 224 +14919 ./prep_dataset/ILSVRC2012_val_00012330.bin 224 224 +14920 ./prep_dataset/ILSVRC2012_val_00016615.bin 224 224 +14921 ./prep_dataset/ILSVRC2012_val_00034399.bin 224 224 +14922 ./prep_dataset/ILSVRC2012_val_00040902.bin 224 224 +14923 ./prep_dataset/ILSVRC2012_val_00047752.bin 224 224 +14924 ./prep_dataset/ILSVRC2012_val_00004689.bin 224 224 +14925 ./prep_dataset/ILSVRC2012_val_00000122.bin 224 224 +14926 ./prep_dataset/ILSVRC2012_val_00023173.bin 224 224 +14927 ./prep_dataset/ILSVRC2012_val_00001792.bin 224 224 +14928 ./prep_dataset/ILSVRC2012_val_00023640.bin 224 224 +14929 ./prep_dataset/ILSVRC2012_val_00021357.bin 224 224 +14930 ./prep_dataset/ILSVRC2012_val_00017605.bin 224 224 +14931 ./prep_dataset/ILSVRC2012_val_00006397.bin 224 224 +14932 ./prep_dataset/ILSVRC2012_val_00040161.bin 224 224 +14933 ./prep_dataset/ILSVRC2012_val_00034311.bin 224 224 +14934 ./prep_dataset/ILSVRC2012_val_00019035.bin 224 224 +14935 ./prep_dataset/ILSVRC2012_val_00006615.bin 224 224 +14936 ./prep_dataset/ILSVRC2012_val_00024298.bin 224 224 +14937 ./prep_dataset/ILSVRC2012_val_00009146.bin 224 224 +14938 ./prep_dataset/ILSVRC2012_val_00024745.bin 224 224 +14939 ./prep_dataset/ILSVRC2012_val_00019385.bin 224 224 +14940 ./prep_dataset/ILSVRC2012_val_00029172.bin 224 224 +14941 ./prep_dataset/ILSVRC2012_val_00006161.bin 224 224 +14942 ./prep_dataset/ILSVRC2012_val_00037127.bin 224 224 +14943 ./prep_dataset/ILSVRC2012_val_00010249.bin 224 224 +14944 ./prep_dataset/ILSVRC2012_val_00035553.bin 224 224 +14945 ./prep_dataset/ILSVRC2012_val_00003444.bin 224 224 +14946 ./prep_dataset/ILSVRC2012_val_00022068.bin 224 224 +14947 ./prep_dataset/ILSVRC2012_val_00043997.bin 224 224 +14948 ./prep_dataset/ILSVRC2012_val_00036595.bin 224 224 +14949 ./prep_dataset/ILSVRC2012_val_00028948.bin 224 224 +14950 ./prep_dataset/ILSVRC2012_val_00018841.bin 224 224 +14951 ./prep_dataset/ILSVRC2012_val_00013847.bin 224 224 +14952 ./prep_dataset/ILSVRC2012_val_00000927.bin 224 224 +14953 ./prep_dataset/ILSVRC2012_val_00045297.bin 224 224 +14954 ./prep_dataset/ILSVRC2012_val_00004110.bin 224 224 +14955 ./prep_dataset/ILSVRC2012_val_00028061.bin 224 224 +14956 ./prep_dataset/ILSVRC2012_val_00015597.bin 224 224 +14957 ./prep_dataset/ILSVRC2012_val_00016782.bin 224 224 +14958 ./prep_dataset/ILSVRC2012_val_00032272.bin 224 224 +14959 ./prep_dataset/ILSVRC2012_val_00038466.bin 224 224 +14960 ./prep_dataset/ILSVRC2012_val_00013389.bin 224 224 +14961 ./prep_dataset/ILSVRC2012_val_00030766.bin 224 224 +14962 ./prep_dataset/ILSVRC2012_val_00042819.bin 224 224 +14963 ./prep_dataset/ILSVRC2012_val_00039090.bin 224 224 +14964 ./prep_dataset/ILSVRC2012_val_00000840.bin 224 224 +14965 ./prep_dataset/ILSVRC2012_val_00048222.bin 224 224 +14966 ./prep_dataset/ILSVRC2012_val_00026943.bin 224 224 +14967 ./prep_dataset/ILSVRC2012_val_00008181.bin 224 224 +14968 ./prep_dataset/ILSVRC2012_val_00035962.bin 224 224 +14969 ./prep_dataset/ILSVRC2012_val_00000503.bin 224 224 +14970 ./prep_dataset/ILSVRC2012_val_00027419.bin 224 224 +14971 ./prep_dataset/ILSVRC2012_val_00037787.bin 224 224 +14972 ./prep_dataset/ILSVRC2012_val_00027968.bin 224 224 +14973 ./prep_dataset/ILSVRC2012_val_00014426.bin 224 224 +14974 ./prep_dataset/ILSVRC2012_val_00039020.bin 224 224 +14975 ./prep_dataset/ILSVRC2012_val_00005553.bin 224 224 +14976 ./prep_dataset/ILSVRC2012_val_00029597.bin 224 224 +14977 ./prep_dataset/ILSVRC2012_val_00010361.bin 224 224 +14978 ./prep_dataset/ILSVRC2012_val_00012436.bin 224 224 +14979 ./prep_dataset/ILSVRC2012_val_00016247.bin 224 224 +14980 ./prep_dataset/ILSVRC2012_val_00042348.bin 224 224 +14981 ./prep_dataset/ILSVRC2012_val_00014150.bin 224 224 +14982 ./prep_dataset/ILSVRC2012_val_00032027.bin 224 224 +14983 ./prep_dataset/ILSVRC2012_val_00008428.bin 224 224 +14984 ./prep_dataset/ILSVRC2012_val_00005686.bin 224 224 +14985 ./prep_dataset/ILSVRC2012_val_00045084.bin 224 224 +14986 ./prep_dataset/ILSVRC2012_val_00046717.bin 224 224 +14987 ./prep_dataset/ILSVRC2012_val_00020347.bin 224 224 +14988 ./prep_dataset/ILSVRC2012_val_00000249.bin 224 224 +14989 ./prep_dataset/ILSVRC2012_val_00037525.bin 224 224 +14990 ./prep_dataset/ILSVRC2012_val_00049228.bin 224 224 +14991 ./prep_dataset/ILSVRC2012_val_00009791.bin 224 224 +14992 ./prep_dataset/ILSVRC2012_val_00026492.bin 224 224 +14993 ./prep_dataset/ILSVRC2012_val_00020781.bin 224 224 +14994 ./prep_dataset/ILSVRC2012_val_00004935.bin 224 224 +14995 ./prep_dataset/ILSVRC2012_val_00003711.bin 224 224 +14996 ./prep_dataset/ILSVRC2012_val_00010857.bin 224 224 +14997 ./prep_dataset/ILSVRC2012_val_00014881.bin 224 224 +14998 ./prep_dataset/ILSVRC2012_val_00048709.bin 224 224 +14999 ./prep_dataset/ILSVRC2012_val_00023211.bin 224 224 +15000 ./prep_dataset/ILSVRC2012_val_00024468.bin 224 224 +15001 ./prep_dataset/ILSVRC2012_val_00027754.bin 224 224 +15002 ./prep_dataset/ILSVRC2012_val_00029819.bin 224 224 +15003 ./prep_dataset/ILSVRC2012_val_00000126.bin 224 224 +15004 ./prep_dataset/ILSVRC2012_val_00025901.bin 224 224 +15005 ./prep_dataset/ILSVRC2012_val_00047535.bin 224 224 +15006 ./prep_dataset/ILSVRC2012_val_00019541.bin 224 224 +15007 ./prep_dataset/ILSVRC2012_val_00010721.bin 224 224 +15008 ./prep_dataset/ILSVRC2012_val_00009957.bin 224 224 +15009 ./prep_dataset/ILSVRC2012_val_00022934.bin 224 224 +15010 ./prep_dataset/ILSVRC2012_val_00047837.bin 224 224 +15011 ./prep_dataset/ILSVRC2012_val_00011567.bin 224 224 +15012 ./prep_dataset/ILSVRC2012_val_00035265.bin 224 224 +15013 ./prep_dataset/ILSVRC2012_val_00025603.bin 224 224 +15014 ./prep_dataset/ILSVRC2012_val_00019264.bin 224 224 +15015 ./prep_dataset/ILSVRC2012_val_00003056.bin 224 224 +15016 ./prep_dataset/ILSVRC2012_val_00012512.bin 224 224 +15017 ./prep_dataset/ILSVRC2012_val_00037311.bin 224 224 +15018 ./prep_dataset/ILSVRC2012_val_00026029.bin 224 224 +15019 ./prep_dataset/ILSVRC2012_val_00029850.bin 224 224 +15020 ./prep_dataset/ILSVRC2012_val_00048274.bin 224 224 +15021 ./prep_dataset/ILSVRC2012_val_00001863.bin 224 224 +15022 ./prep_dataset/ILSVRC2012_val_00001953.bin 224 224 +15023 ./prep_dataset/ILSVRC2012_val_00042987.bin 224 224 +15024 ./prep_dataset/ILSVRC2012_val_00033614.bin 224 224 +15025 ./prep_dataset/ILSVRC2012_val_00010916.bin 224 224 +15026 ./prep_dataset/ILSVRC2012_val_00025526.bin 224 224 +15027 ./prep_dataset/ILSVRC2012_val_00034124.bin 224 224 +15028 ./prep_dataset/ILSVRC2012_val_00047412.bin 224 224 +15029 ./prep_dataset/ILSVRC2012_val_00030135.bin 224 224 +15030 ./prep_dataset/ILSVRC2012_val_00040292.bin 224 224 +15031 ./prep_dataset/ILSVRC2012_val_00006449.bin 224 224 +15032 ./prep_dataset/ILSVRC2012_val_00031588.bin 224 224 +15033 ./prep_dataset/ILSVRC2012_val_00025343.bin 224 224 +15034 ./prep_dataset/ILSVRC2012_val_00043161.bin 224 224 +15035 ./prep_dataset/ILSVRC2012_val_00019347.bin 224 224 +15036 ./prep_dataset/ILSVRC2012_val_00033020.bin 224 224 +15037 ./prep_dataset/ILSVRC2012_val_00005461.bin 224 224 +15038 ./prep_dataset/ILSVRC2012_val_00023619.bin 224 224 +15039 ./prep_dataset/ILSVRC2012_val_00033929.bin 224 224 +15040 ./prep_dataset/ILSVRC2012_val_00013077.bin 224 224 +15041 ./prep_dataset/ILSVRC2012_val_00017027.bin 224 224 +15042 ./prep_dataset/ILSVRC2012_val_00007232.bin 224 224 +15043 ./prep_dataset/ILSVRC2012_val_00008352.bin 224 224 +15044 ./prep_dataset/ILSVRC2012_val_00034059.bin 224 224 +15045 ./prep_dataset/ILSVRC2012_val_00036127.bin 224 224 +15046 ./prep_dataset/ILSVRC2012_val_00015045.bin 224 224 +15047 ./prep_dataset/ILSVRC2012_val_00012521.bin 224 224 +15048 ./prep_dataset/ILSVRC2012_val_00008024.bin 224 224 +15049 ./prep_dataset/ILSVRC2012_val_00001235.bin 224 224 +15050 ./prep_dataset/ILSVRC2012_val_00010471.bin 224 224 +15051 ./prep_dataset/ILSVRC2012_val_00023953.bin 224 224 +15052 ./prep_dataset/ILSVRC2012_val_00025385.bin 224 224 +15053 ./prep_dataset/ILSVRC2012_val_00001281.bin 224 224 +15054 ./prep_dataset/ILSVRC2012_val_00020206.bin 224 224 +15055 ./prep_dataset/ILSVRC2012_val_00003058.bin 224 224 +15056 ./prep_dataset/ILSVRC2012_val_00002110.bin 224 224 +15057 ./prep_dataset/ILSVRC2012_val_00022427.bin 224 224 +15058 ./prep_dataset/ILSVRC2012_val_00044939.bin 224 224 +15059 ./prep_dataset/ILSVRC2012_val_00019299.bin 224 224 +15060 ./prep_dataset/ILSVRC2012_val_00001847.bin 224 224 +15061 ./prep_dataset/ILSVRC2012_val_00029569.bin 224 224 +15062 ./prep_dataset/ILSVRC2012_val_00006191.bin 224 224 +15063 ./prep_dataset/ILSVRC2012_val_00017354.bin 224 224 +15064 ./prep_dataset/ILSVRC2012_val_00048012.bin 224 224 +15065 ./prep_dataset/ILSVRC2012_val_00035947.bin 224 224 +15066 ./prep_dataset/ILSVRC2012_val_00006268.bin 224 224 +15067 ./prep_dataset/ILSVRC2012_val_00044512.bin 224 224 +15068 ./prep_dataset/ILSVRC2012_val_00048636.bin 224 224 +15069 ./prep_dataset/ILSVRC2012_val_00029469.bin 224 224 +15070 ./prep_dataset/ILSVRC2012_val_00017273.bin 224 224 +15071 ./prep_dataset/ILSVRC2012_val_00045551.bin 224 224 +15072 ./prep_dataset/ILSVRC2012_val_00000620.bin 224 224 +15073 ./prep_dataset/ILSVRC2012_val_00034367.bin 224 224 +15074 ./prep_dataset/ILSVRC2012_val_00044935.bin 224 224 +15075 ./prep_dataset/ILSVRC2012_val_00020697.bin 224 224 +15076 ./prep_dataset/ILSVRC2012_val_00014710.bin 224 224 +15077 ./prep_dataset/ILSVRC2012_val_00030646.bin 224 224 +15078 ./prep_dataset/ILSVRC2012_val_00015158.bin 224 224 +15079 ./prep_dataset/ILSVRC2012_val_00028522.bin 224 224 +15080 ./prep_dataset/ILSVRC2012_val_00035655.bin 224 224 +15081 ./prep_dataset/ILSVRC2012_val_00047327.bin 224 224 +15082 ./prep_dataset/ILSVRC2012_val_00049434.bin 224 224 +15083 ./prep_dataset/ILSVRC2012_val_00021197.bin 224 224 +15084 ./prep_dataset/ILSVRC2012_val_00037176.bin 224 224 +15085 ./prep_dataset/ILSVRC2012_val_00028854.bin 224 224 +15086 ./prep_dataset/ILSVRC2012_val_00017760.bin 224 224 +15087 ./prep_dataset/ILSVRC2012_val_00045555.bin 224 224 +15088 ./prep_dataset/ILSVRC2012_val_00034535.bin 224 224 +15089 ./prep_dataset/ILSVRC2012_val_00048813.bin 224 224 +15090 ./prep_dataset/ILSVRC2012_val_00037500.bin 224 224 +15091 ./prep_dataset/ILSVRC2012_val_00006144.bin 224 224 +15092 ./prep_dataset/ILSVRC2012_val_00010702.bin 224 224 +15093 ./prep_dataset/ILSVRC2012_val_00021852.bin 224 224 +15094 ./prep_dataset/ILSVRC2012_val_00009148.bin 224 224 +15095 ./prep_dataset/ILSVRC2012_val_00001764.bin 224 224 +15096 ./prep_dataset/ILSVRC2012_val_00010308.bin 224 224 +15097 ./prep_dataset/ILSVRC2012_val_00031071.bin 224 224 +15098 ./prep_dataset/ILSVRC2012_val_00038089.bin 224 224 +15099 ./prep_dataset/ILSVRC2012_val_00030436.bin 224 224 +15100 ./prep_dataset/ILSVRC2012_val_00024386.bin 224 224 +15101 ./prep_dataset/ILSVRC2012_val_00037145.bin 224 224 +15102 ./prep_dataset/ILSVRC2012_val_00029242.bin 224 224 +15103 ./prep_dataset/ILSVRC2012_val_00013109.bin 224 224 +15104 ./prep_dataset/ILSVRC2012_val_00048191.bin 224 224 +15105 ./prep_dataset/ILSVRC2012_val_00019879.bin 224 224 +15106 ./prep_dataset/ILSVRC2012_val_00043816.bin 224 224 +15107 ./prep_dataset/ILSVRC2012_val_00044171.bin 224 224 +15108 ./prep_dataset/ILSVRC2012_val_00032829.bin 224 224 +15109 ./prep_dataset/ILSVRC2012_val_00049412.bin 224 224 +15110 ./prep_dataset/ILSVRC2012_val_00049381.bin 224 224 +15111 ./prep_dataset/ILSVRC2012_val_00003251.bin 224 224 +15112 ./prep_dataset/ILSVRC2012_val_00032576.bin 224 224 +15113 ./prep_dataset/ILSVRC2012_val_00032838.bin 224 224 +15114 ./prep_dataset/ILSVRC2012_val_00020622.bin 224 224 +15115 ./prep_dataset/ILSVRC2012_val_00040595.bin 224 224 +15116 ./prep_dataset/ILSVRC2012_val_00001298.bin 224 224 +15117 ./prep_dataset/ILSVRC2012_val_00004743.bin 224 224 +15118 ./prep_dataset/ILSVRC2012_val_00038374.bin 224 224 +15119 ./prep_dataset/ILSVRC2012_val_00033012.bin 224 224 +15120 ./prep_dataset/ILSVRC2012_val_00023744.bin 224 224 +15121 ./prep_dataset/ILSVRC2012_val_00022286.bin 224 224 +15122 ./prep_dataset/ILSVRC2012_val_00030828.bin 224 224 +15123 ./prep_dataset/ILSVRC2012_val_00009952.bin 224 224 +15124 ./prep_dataset/ILSVRC2012_val_00047056.bin 224 224 +15125 ./prep_dataset/ILSVRC2012_val_00048605.bin 224 224 +15126 ./prep_dataset/ILSVRC2012_val_00005063.bin 224 224 +15127 ./prep_dataset/ILSVRC2012_val_00026128.bin 224 224 +15128 ./prep_dataset/ILSVRC2012_val_00048363.bin 224 224 +15129 ./prep_dataset/ILSVRC2012_val_00000599.bin 224 224 +15130 ./prep_dataset/ILSVRC2012_val_00000628.bin 224 224 +15131 ./prep_dataset/ILSVRC2012_val_00019024.bin 224 224 +15132 ./prep_dataset/ILSVRC2012_val_00012207.bin 224 224 +15133 ./prep_dataset/ILSVRC2012_val_00013703.bin 224 224 +15134 ./prep_dataset/ILSVRC2012_val_00028947.bin 224 224 +15135 ./prep_dataset/ILSVRC2012_val_00024022.bin 224 224 +15136 ./prep_dataset/ILSVRC2012_val_00043000.bin 224 224 +15137 ./prep_dataset/ILSVRC2012_val_00009238.bin 224 224 +15138 ./prep_dataset/ILSVRC2012_val_00024164.bin 224 224 +15139 ./prep_dataset/ILSVRC2012_val_00002375.bin 224 224 +15140 ./prep_dataset/ILSVRC2012_val_00029784.bin 224 224 +15141 ./prep_dataset/ILSVRC2012_val_00000940.bin 224 224 +15142 ./prep_dataset/ILSVRC2012_val_00025462.bin 224 224 +15143 ./prep_dataset/ILSVRC2012_val_00012226.bin 224 224 +15144 ./prep_dataset/ILSVRC2012_val_00036465.bin 224 224 +15145 ./prep_dataset/ILSVRC2012_val_00013710.bin 224 224 +15146 ./prep_dataset/ILSVRC2012_val_00027441.bin 224 224 +15147 ./prep_dataset/ILSVRC2012_val_00024161.bin 224 224 +15148 ./prep_dataset/ILSVRC2012_val_00019530.bin 224 224 +15149 ./prep_dataset/ILSVRC2012_val_00022231.bin 224 224 +15150 ./prep_dataset/ILSVRC2012_val_00032946.bin 224 224 +15151 ./prep_dataset/ILSVRC2012_val_00011484.bin 224 224 +15152 ./prep_dataset/ILSVRC2012_val_00018592.bin 224 224 +15153 ./prep_dataset/ILSVRC2012_val_00002001.bin 224 224 +15154 ./prep_dataset/ILSVRC2012_val_00024803.bin 224 224 +15155 ./prep_dataset/ILSVRC2012_val_00000240.bin 224 224 +15156 ./prep_dataset/ILSVRC2012_val_00007358.bin 224 224 +15157 ./prep_dataset/ILSVRC2012_val_00040794.bin 224 224 +15158 ./prep_dataset/ILSVRC2012_val_00038890.bin 224 224 +15159 ./prep_dataset/ILSVRC2012_val_00046339.bin 224 224 +15160 ./prep_dataset/ILSVRC2012_val_00008289.bin 224 224 +15161 ./prep_dataset/ILSVRC2012_val_00005711.bin 224 224 +15162 ./prep_dataset/ILSVRC2012_val_00014840.bin 224 224 +15163 ./prep_dataset/ILSVRC2012_val_00042468.bin 224 224 +15164 ./prep_dataset/ILSVRC2012_val_00028485.bin 224 224 +15165 ./prep_dataset/ILSVRC2012_val_00027216.bin 224 224 +15166 ./prep_dataset/ILSVRC2012_val_00010348.bin 224 224 +15167 ./prep_dataset/ILSVRC2012_val_00019670.bin 224 224 +15168 ./prep_dataset/ILSVRC2012_val_00018775.bin 224 224 +15169 ./prep_dataset/ILSVRC2012_val_00034091.bin 224 224 +15170 ./prep_dataset/ILSVRC2012_val_00038601.bin 224 224 +15171 ./prep_dataset/ILSVRC2012_val_00047118.bin 224 224 +15172 ./prep_dataset/ILSVRC2012_val_00008711.bin 224 224 +15173 ./prep_dataset/ILSVRC2012_val_00028216.bin 224 224 +15174 ./prep_dataset/ILSVRC2012_val_00010117.bin 224 224 +15175 ./prep_dataset/ILSVRC2012_val_00040510.bin 224 224 +15176 ./prep_dataset/ILSVRC2012_val_00040505.bin 224 224 +15177 ./prep_dataset/ILSVRC2012_val_00021212.bin 224 224 +15178 ./prep_dataset/ILSVRC2012_val_00033733.bin 224 224 +15179 ./prep_dataset/ILSVRC2012_val_00048005.bin 224 224 +15180 ./prep_dataset/ILSVRC2012_val_00010595.bin 224 224 +15181 ./prep_dataset/ILSVRC2012_val_00028526.bin 224 224 +15182 ./prep_dataset/ILSVRC2012_val_00024229.bin 224 224 +15183 ./prep_dataset/ILSVRC2012_val_00047403.bin 224 224 +15184 ./prep_dataset/ILSVRC2012_val_00036115.bin 224 224 +15185 ./prep_dataset/ILSVRC2012_val_00045044.bin 224 224 +15186 ./prep_dataset/ILSVRC2012_val_00049851.bin 224 224 +15187 ./prep_dataset/ILSVRC2012_val_00040982.bin 224 224 +15188 ./prep_dataset/ILSVRC2012_val_00027876.bin 224 224 +15189 ./prep_dataset/ILSVRC2012_val_00038401.bin 224 224 +15190 ./prep_dataset/ILSVRC2012_val_00036212.bin 224 224 +15191 ./prep_dataset/ILSVRC2012_val_00012002.bin 224 224 +15192 ./prep_dataset/ILSVRC2012_val_00021477.bin 224 224 +15193 ./prep_dataset/ILSVRC2012_val_00015246.bin 224 224 +15194 ./prep_dataset/ILSVRC2012_val_00028056.bin 224 224 +15195 ./prep_dataset/ILSVRC2012_val_00035251.bin 224 224 +15196 ./prep_dataset/ILSVRC2012_val_00035581.bin 224 224 +15197 ./prep_dataset/ILSVRC2012_val_00019669.bin 224 224 +15198 ./prep_dataset/ILSVRC2012_val_00037249.bin 224 224 +15199 ./prep_dataset/ILSVRC2012_val_00021536.bin 224 224 +15200 ./prep_dataset/ILSVRC2012_val_00001723.bin 224 224 +15201 ./prep_dataset/ILSVRC2012_val_00006533.bin 224 224 +15202 ./prep_dataset/ILSVRC2012_val_00041073.bin 224 224 +15203 ./prep_dataset/ILSVRC2012_val_00042264.bin 224 224 +15204 ./prep_dataset/ILSVRC2012_val_00044777.bin 224 224 +15205 ./prep_dataset/ILSVRC2012_val_00014935.bin 224 224 +15206 ./prep_dataset/ILSVRC2012_val_00021654.bin 224 224 +15207 ./prep_dataset/ILSVRC2012_val_00032187.bin 224 224 +15208 ./prep_dataset/ILSVRC2012_val_00035188.bin 224 224 +15209 ./prep_dataset/ILSVRC2012_val_00042585.bin 224 224 +15210 ./prep_dataset/ILSVRC2012_val_00004239.bin 224 224 +15211 ./prep_dataset/ILSVRC2012_val_00003266.bin 224 224 +15212 ./prep_dataset/ILSVRC2012_val_00009904.bin 224 224 +15213 ./prep_dataset/ILSVRC2012_val_00009614.bin 224 224 +15214 ./prep_dataset/ILSVRC2012_val_00039314.bin 224 224 +15215 ./prep_dataset/ILSVRC2012_val_00002312.bin 224 224 +15216 ./prep_dataset/ILSVRC2012_val_00019091.bin 224 224 +15217 ./prep_dataset/ILSVRC2012_val_00000506.bin 224 224 +15218 ./prep_dataset/ILSVRC2012_val_00005133.bin 224 224 +15219 ./prep_dataset/ILSVRC2012_val_00019897.bin 224 224 +15220 ./prep_dataset/ILSVRC2012_val_00014531.bin 224 224 +15221 ./prep_dataset/ILSVRC2012_val_00022721.bin 224 224 +15222 ./prep_dataset/ILSVRC2012_val_00043280.bin 224 224 +15223 ./prep_dataset/ILSVRC2012_val_00024827.bin 224 224 +15224 ./prep_dataset/ILSVRC2012_val_00010681.bin 224 224 +15225 ./prep_dataset/ILSVRC2012_val_00041345.bin 224 224 +15226 ./prep_dataset/ILSVRC2012_val_00035379.bin 224 224 +15227 ./prep_dataset/ILSVRC2012_val_00012398.bin 224 224 +15228 ./prep_dataset/ILSVRC2012_val_00049976.bin 224 224 +15229 ./prep_dataset/ILSVRC2012_val_00026189.bin 224 224 +15230 ./prep_dataset/ILSVRC2012_val_00015985.bin 224 224 +15231 ./prep_dataset/ILSVRC2012_val_00004229.bin 224 224 +15232 ./prep_dataset/ILSVRC2012_val_00006994.bin 224 224 +15233 ./prep_dataset/ILSVRC2012_val_00002535.bin 224 224 +15234 ./prep_dataset/ILSVRC2012_val_00022336.bin 224 224 +15235 ./prep_dataset/ILSVRC2012_val_00028328.bin 224 224 +15236 ./prep_dataset/ILSVRC2012_val_00045075.bin 224 224 +15237 ./prep_dataset/ILSVRC2012_val_00002553.bin 224 224 +15238 ./prep_dataset/ILSVRC2012_val_00014593.bin 224 224 +15239 ./prep_dataset/ILSVRC2012_val_00025235.bin 224 224 +15240 ./prep_dataset/ILSVRC2012_val_00020285.bin 224 224 +15241 ./prep_dataset/ILSVRC2012_val_00021665.bin 224 224 +15242 ./prep_dataset/ILSVRC2012_val_00015353.bin 224 224 +15243 ./prep_dataset/ILSVRC2012_val_00035042.bin 224 224 +15244 ./prep_dataset/ILSVRC2012_val_00032565.bin 224 224 +15245 ./prep_dataset/ILSVRC2012_val_00005994.bin 224 224 +15246 ./prep_dataset/ILSVRC2012_val_00048566.bin 224 224 +15247 ./prep_dataset/ILSVRC2012_val_00007507.bin 224 224 +15248 ./prep_dataset/ILSVRC2012_val_00007376.bin 224 224 +15249 ./prep_dataset/ILSVRC2012_val_00038300.bin 224 224 +15250 ./prep_dataset/ILSVRC2012_val_00012402.bin 224 224 +15251 ./prep_dataset/ILSVRC2012_val_00024317.bin 224 224 +15252 ./prep_dataset/ILSVRC2012_val_00033694.bin 224 224 +15253 ./prep_dataset/ILSVRC2012_val_00038541.bin 224 224 +15254 ./prep_dataset/ILSVRC2012_val_00048640.bin 224 224 +15255 ./prep_dataset/ILSVRC2012_val_00034802.bin 224 224 +15256 ./prep_dataset/ILSVRC2012_val_00039564.bin 224 224 +15257 ./prep_dataset/ILSVRC2012_val_00044987.bin 224 224 +15258 ./prep_dataset/ILSVRC2012_val_00023887.bin 224 224 +15259 ./prep_dataset/ILSVRC2012_val_00022888.bin 224 224 +15260 ./prep_dataset/ILSVRC2012_val_00016751.bin 224 224 +15261 ./prep_dataset/ILSVRC2012_val_00028318.bin 224 224 +15262 ./prep_dataset/ILSVRC2012_val_00040751.bin 224 224 +15263 ./prep_dataset/ILSVRC2012_val_00034852.bin 224 224 +15264 ./prep_dataset/ILSVRC2012_val_00023889.bin 224 224 +15265 ./prep_dataset/ILSVRC2012_val_00024521.bin 224 224 +15266 ./prep_dataset/ILSVRC2012_val_00027390.bin 224 224 +15267 ./prep_dataset/ILSVRC2012_val_00011816.bin 224 224 +15268 ./prep_dataset/ILSVRC2012_val_00031671.bin 224 224 +15269 ./prep_dataset/ILSVRC2012_val_00003436.bin 224 224 +15270 ./prep_dataset/ILSVRC2012_val_00026365.bin 224 224 +15271 ./prep_dataset/ILSVRC2012_val_00006702.bin 224 224 +15272 ./prep_dataset/ILSVRC2012_val_00027665.bin 224 224 +15273 ./prep_dataset/ILSVRC2012_val_00031837.bin 224 224 +15274 ./prep_dataset/ILSVRC2012_val_00025601.bin 224 224 +15275 ./prep_dataset/ILSVRC2012_val_00031009.bin 224 224 +15276 ./prep_dataset/ILSVRC2012_val_00035732.bin 224 224 +15277 ./prep_dataset/ILSVRC2012_val_00041311.bin 224 224 +15278 ./prep_dataset/ILSVRC2012_val_00045090.bin 224 224 +15279 ./prep_dataset/ILSVRC2012_val_00016721.bin 224 224 +15280 ./prep_dataset/ILSVRC2012_val_00004716.bin 224 224 +15281 ./prep_dataset/ILSVRC2012_val_00012622.bin 224 224 +15282 ./prep_dataset/ILSVRC2012_val_00019315.bin 224 224 +15283 ./prep_dataset/ILSVRC2012_val_00026008.bin 224 224 +15284 ./prep_dataset/ILSVRC2012_val_00005980.bin 224 224 +15285 ./prep_dataset/ILSVRC2012_val_00036823.bin 224 224 +15286 ./prep_dataset/ILSVRC2012_val_00023892.bin 224 224 +15287 ./prep_dataset/ILSVRC2012_val_00048321.bin 224 224 +15288 ./prep_dataset/ILSVRC2012_val_00020677.bin 224 224 +15289 ./prep_dataset/ILSVRC2012_val_00035932.bin 224 224 +15290 ./prep_dataset/ILSVRC2012_val_00035401.bin 224 224 +15291 ./prep_dataset/ILSVRC2012_val_00035463.bin 224 224 +15292 ./prep_dataset/ILSVRC2012_val_00023928.bin 224 224 +15293 ./prep_dataset/ILSVRC2012_val_00045890.bin 224 224 +15294 ./prep_dataset/ILSVRC2012_val_00026293.bin 224 224 +15295 ./prep_dataset/ILSVRC2012_val_00024885.bin 224 224 +15296 ./prep_dataset/ILSVRC2012_val_00015005.bin 224 224 +15297 ./prep_dataset/ILSVRC2012_val_00009744.bin 224 224 +15298 ./prep_dataset/ILSVRC2012_val_00046089.bin 224 224 +15299 ./prep_dataset/ILSVRC2012_val_00003018.bin 224 224 +15300 ./prep_dataset/ILSVRC2012_val_00025165.bin 224 224 +15301 ./prep_dataset/ILSVRC2012_val_00038181.bin 224 224 +15302 ./prep_dataset/ILSVRC2012_val_00017550.bin 224 224 +15303 ./prep_dataset/ILSVRC2012_val_00003526.bin 224 224 +15304 ./prep_dataset/ILSVRC2012_val_00029122.bin 224 224 +15305 ./prep_dataset/ILSVRC2012_val_00042347.bin 224 224 +15306 ./prep_dataset/ILSVRC2012_val_00014756.bin 224 224 +15307 ./prep_dataset/ILSVRC2012_val_00017400.bin 224 224 +15308 ./prep_dataset/ILSVRC2012_val_00018116.bin 224 224 +15309 ./prep_dataset/ILSVRC2012_val_00009469.bin 224 224 +15310 ./prep_dataset/ILSVRC2012_val_00038280.bin 224 224 +15311 ./prep_dataset/ILSVRC2012_val_00049609.bin 224 224 +15312 ./prep_dataset/ILSVRC2012_val_00012153.bin 224 224 +15313 ./prep_dataset/ILSVRC2012_val_00026739.bin 224 224 +15314 ./prep_dataset/ILSVRC2012_val_00049078.bin 224 224 +15315 ./prep_dataset/ILSVRC2012_val_00021677.bin 224 224 +15316 ./prep_dataset/ILSVRC2012_val_00046522.bin 224 224 +15317 ./prep_dataset/ILSVRC2012_val_00007226.bin 224 224 +15318 ./prep_dataset/ILSVRC2012_val_00008093.bin 224 224 +15319 ./prep_dataset/ILSVRC2012_val_00027675.bin 224 224 +15320 ./prep_dataset/ILSVRC2012_val_00045818.bin 224 224 +15321 ./prep_dataset/ILSVRC2012_val_00032574.bin 224 224 +15322 ./prep_dataset/ILSVRC2012_val_00009262.bin 224 224 +15323 ./prep_dataset/ILSVRC2012_val_00022518.bin 224 224 +15324 ./prep_dataset/ILSVRC2012_val_00018188.bin 224 224 +15325 ./prep_dataset/ILSVRC2012_val_00040700.bin 224 224 +15326 ./prep_dataset/ILSVRC2012_val_00031184.bin 224 224 +15327 ./prep_dataset/ILSVRC2012_val_00019230.bin 224 224 +15328 ./prep_dataset/ILSVRC2012_val_00045481.bin 224 224 +15329 ./prep_dataset/ILSVRC2012_val_00029872.bin 224 224 +15330 ./prep_dataset/ILSVRC2012_val_00029363.bin 224 224 +15331 ./prep_dataset/ILSVRC2012_val_00012269.bin 224 224 +15332 ./prep_dataset/ILSVRC2012_val_00014320.bin 224 224 +15333 ./prep_dataset/ILSVRC2012_val_00045508.bin 224 224 +15334 ./prep_dataset/ILSVRC2012_val_00023323.bin 224 224 +15335 ./prep_dataset/ILSVRC2012_val_00032221.bin 224 224 +15336 ./prep_dataset/ILSVRC2012_val_00029747.bin 224 224 +15337 ./prep_dataset/ILSVRC2012_val_00039972.bin 224 224 +15338 ./prep_dataset/ILSVRC2012_val_00006541.bin 224 224 +15339 ./prep_dataset/ILSVRC2012_val_00024291.bin 224 224 +15340 ./prep_dataset/ILSVRC2012_val_00022403.bin 224 224 +15341 ./prep_dataset/ILSVRC2012_val_00003847.bin 224 224 +15342 ./prep_dataset/ILSVRC2012_val_00017500.bin 224 224 +15343 ./prep_dataset/ILSVRC2012_val_00000568.bin 224 224 +15344 ./prep_dataset/ILSVRC2012_val_00008049.bin 224 224 +15345 ./prep_dataset/ILSVRC2012_val_00031896.bin 224 224 +15346 ./prep_dataset/ILSVRC2012_val_00039075.bin 224 224 +15347 ./prep_dataset/ILSVRC2012_val_00034247.bin 224 224 +15348 ./prep_dataset/ILSVRC2012_val_00034607.bin 224 224 +15349 ./prep_dataset/ILSVRC2012_val_00031002.bin 224 224 +15350 ./prep_dataset/ILSVRC2012_val_00006626.bin 224 224 +15351 ./prep_dataset/ILSVRC2012_val_00049541.bin 224 224 +15352 ./prep_dataset/ILSVRC2012_val_00044028.bin 224 224 +15353 ./prep_dataset/ILSVRC2012_val_00040790.bin 224 224 +15354 ./prep_dataset/ILSVRC2012_val_00010123.bin 224 224 +15355 ./prep_dataset/ILSVRC2012_val_00046194.bin 224 224 +15356 ./prep_dataset/ILSVRC2012_val_00039817.bin 224 224 +15357 ./prep_dataset/ILSVRC2012_val_00035084.bin 224 224 +15358 ./prep_dataset/ILSVRC2012_val_00027903.bin 224 224 +15359 ./prep_dataset/ILSVRC2012_val_00049801.bin 224 224 +15360 ./prep_dataset/ILSVRC2012_val_00011516.bin 224 224 +15361 ./prep_dataset/ILSVRC2012_val_00026506.bin 224 224 +15362 ./prep_dataset/ILSVRC2012_val_00012795.bin 224 224 +15363 ./prep_dataset/ILSVRC2012_val_00016389.bin 224 224 +15364 ./prep_dataset/ILSVRC2012_val_00028535.bin 224 224 +15365 ./prep_dataset/ILSVRC2012_val_00015725.bin 224 224 +15366 ./prep_dataset/ILSVRC2012_val_00007964.bin 224 224 +15367 ./prep_dataset/ILSVRC2012_val_00001060.bin 224 224 +15368 ./prep_dataset/ILSVRC2012_val_00047094.bin 224 224 +15369 ./prep_dataset/ILSVRC2012_val_00017899.bin 224 224 +15370 ./prep_dataset/ILSVRC2012_val_00011385.bin 224 224 +15371 ./prep_dataset/ILSVRC2012_val_00026197.bin 224 224 +15372 ./prep_dataset/ILSVRC2012_val_00038052.bin 224 224 +15373 ./prep_dataset/ILSVRC2012_val_00033392.bin 224 224 +15374 ./prep_dataset/ILSVRC2012_val_00004047.bin 224 224 +15375 ./prep_dataset/ILSVRC2012_val_00017540.bin 224 224 +15376 ./prep_dataset/ILSVRC2012_val_00047721.bin 224 224 +15377 ./prep_dataset/ILSVRC2012_val_00010635.bin 224 224 +15378 ./prep_dataset/ILSVRC2012_val_00039777.bin 224 224 +15379 ./prep_dataset/ILSVRC2012_val_00030010.bin 224 224 +15380 ./prep_dataset/ILSVRC2012_val_00026799.bin 224 224 +15381 ./prep_dataset/ILSVRC2012_val_00038623.bin 224 224 +15382 ./prep_dataset/ILSVRC2012_val_00031502.bin 224 224 +15383 ./prep_dataset/ILSVRC2012_val_00038059.bin 224 224 +15384 ./prep_dataset/ILSVRC2012_val_00023272.bin 224 224 +15385 ./prep_dataset/ILSVRC2012_val_00017350.bin 224 224 +15386 ./prep_dataset/ILSVRC2012_val_00024323.bin 224 224 +15387 ./prep_dataset/ILSVRC2012_val_00011112.bin 224 224 +15388 ./prep_dataset/ILSVRC2012_val_00021738.bin 224 224 +15389 ./prep_dataset/ILSVRC2012_val_00026600.bin 224 224 +15390 ./prep_dataset/ILSVRC2012_val_00028156.bin 224 224 +15391 ./prep_dataset/ILSVRC2012_val_00014731.bin 224 224 +15392 ./prep_dataset/ILSVRC2012_val_00002267.bin 224 224 +15393 ./prep_dataset/ILSVRC2012_val_00017347.bin 224 224 +15394 ./prep_dataset/ILSVRC2012_val_00041567.bin 224 224 +15395 ./prep_dataset/ILSVRC2012_val_00032732.bin 224 224 +15396 ./prep_dataset/ILSVRC2012_val_00048559.bin 224 224 +15397 ./prep_dataset/ILSVRC2012_val_00037264.bin 224 224 +15398 ./prep_dataset/ILSVRC2012_val_00036420.bin 224 224 +15399 ./prep_dataset/ILSVRC2012_val_00039333.bin 224 224 +15400 ./prep_dataset/ILSVRC2012_val_00048489.bin 224 224 +15401 ./prep_dataset/ILSVRC2012_val_00038579.bin 224 224 +15402 ./prep_dataset/ILSVRC2012_val_00035406.bin 224 224 +15403 ./prep_dataset/ILSVRC2012_val_00007837.bin 224 224 +15404 ./prep_dataset/ILSVRC2012_val_00038878.bin 224 224 +15405 ./prep_dataset/ILSVRC2012_val_00015751.bin 224 224 +15406 ./prep_dataset/ILSVRC2012_val_00039998.bin 224 224 +15407 ./prep_dataset/ILSVRC2012_val_00045058.bin 224 224 +15408 ./prep_dataset/ILSVRC2012_val_00032499.bin 224 224 +15409 ./prep_dataset/ILSVRC2012_val_00013792.bin 224 224 +15410 ./prep_dataset/ILSVRC2012_val_00044404.bin 224 224 +15411 ./prep_dataset/ILSVRC2012_val_00011920.bin 224 224 +15412 ./prep_dataset/ILSVRC2012_val_00016846.bin 224 224 +15413 ./prep_dataset/ILSVRC2012_val_00006743.bin 224 224 +15414 ./prep_dataset/ILSVRC2012_val_00017075.bin 224 224 +15415 ./prep_dataset/ILSVRC2012_val_00048521.bin 224 224 +15416 ./prep_dataset/ILSVRC2012_val_00020824.bin 224 224 +15417 ./prep_dataset/ILSVRC2012_val_00004182.bin 224 224 +15418 ./prep_dataset/ILSVRC2012_val_00012331.bin 224 224 +15419 ./prep_dataset/ILSVRC2012_val_00048883.bin 224 224 +15420 ./prep_dataset/ILSVRC2012_val_00021680.bin 224 224 +15421 ./prep_dataset/ILSVRC2012_val_00025097.bin 224 224 +15422 ./prep_dataset/ILSVRC2012_val_00016288.bin 224 224 +15423 ./prep_dataset/ILSVRC2012_val_00033666.bin 224 224 +15424 ./prep_dataset/ILSVRC2012_val_00006336.bin 224 224 +15425 ./prep_dataset/ILSVRC2012_val_00005172.bin 224 224 +15426 ./prep_dataset/ILSVRC2012_val_00001045.bin 224 224 +15427 ./prep_dataset/ILSVRC2012_val_00010320.bin 224 224 +15428 ./prep_dataset/ILSVRC2012_val_00038016.bin 224 224 +15429 ./prep_dataset/ILSVRC2012_val_00028008.bin 224 224 +15430 ./prep_dataset/ILSVRC2012_val_00017376.bin 224 224 +15431 ./prep_dataset/ILSVRC2012_val_00048814.bin 224 224 +15432 ./prep_dataset/ILSVRC2012_val_00003277.bin 224 224 +15433 ./prep_dataset/ILSVRC2012_val_00037426.bin 224 224 +15434 ./prep_dataset/ILSVRC2012_val_00026649.bin 224 224 +15435 ./prep_dataset/ILSVRC2012_val_00009378.bin 224 224 +15436 ./prep_dataset/ILSVRC2012_val_00032492.bin 224 224 +15437 ./prep_dataset/ILSVRC2012_val_00026846.bin 224 224 +15438 ./prep_dataset/ILSVRC2012_val_00030953.bin 224 224 +15439 ./prep_dataset/ILSVRC2012_val_00000396.bin 224 224 +15440 ./prep_dataset/ILSVRC2012_val_00023789.bin 224 224 +15441 ./prep_dataset/ILSVRC2012_val_00018796.bin 224 224 +15442 ./prep_dataset/ILSVRC2012_val_00011665.bin 224 224 +15443 ./prep_dataset/ILSVRC2012_val_00037572.bin 224 224 +15444 ./prep_dataset/ILSVRC2012_val_00044043.bin 224 224 +15445 ./prep_dataset/ILSVRC2012_val_00014336.bin 224 224 +15446 ./prep_dataset/ILSVRC2012_val_00049125.bin 224 224 +15447 ./prep_dataset/ILSVRC2012_val_00040149.bin 224 224 +15448 ./prep_dataset/ILSVRC2012_val_00005653.bin 224 224 +15449 ./prep_dataset/ILSVRC2012_val_00030541.bin 224 224 +15450 ./prep_dataset/ILSVRC2012_val_00001985.bin 224 224 +15451 ./prep_dataset/ILSVRC2012_val_00036716.bin 224 224 +15452 ./prep_dataset/ILSVRC2012_val_00041933.bin 224 224 +15453 ./prep_dataset/ILSVRC2012_val_00014490.bin 224 224 +15454 ./prep_dataset/ILSVRC2012_val_00011864.bin 224 224 +15455 ./prep_dataset/ILSVRC2012_val_00042887.bin 224 224 +15456 ./prep_dataset/ILSVRC2012_val_00021114.bin 224 224 +15457 ./prep_dataset/ILSVRC2012_val_00024944.bin 224 224 +15458 ./prep_dataset/ILSVRC2012_val_00010109.bin 224 224 +15459 ./prep_dataset/ILSVRC2012_val_00017398.bin 224 224 +15460 ./prep_dataset/ILSVRC2012_val_00036985.bin 224 224 +15461 ./prep_dataset/ILSVRC2012_val_00044173.bin 224 224 +15462 ./prep_dataset/ILSVRC2012_val_00027375.bin 224 224 +15463 ./prep_dataset/ILSVRC2012_val_00038963.bin 224 224 +15464 ./prep_dataset/ILSVRC2012_val_00038998.bin 224 224 +15465 ./prep_dataset/ILSVRC2012_val_00023001.bin 224 224 +15466 ./prep_dataset/ILSVRC2012_val_00020262.bin 224 224 +15467 ./prep_dataset/ILSVRC2012_val_00044865.bin 224 224 +15468 ./prep_dataset/ILSVRC2012_val_00043778.bin 224 224 +15469 ./prep_dataset/ILSVRC2012_val_00039174.bin 224 224 +15470 ./prep_dataset/ILSVRC2012_val_00031372.bin 224 224 +15471 ./prep_dataset/ILSVRC2012_val_00022723.bin 224 224 +15472 ./prep_dataset/ILSVRC2012_val_00003803.bin 224 224 +15473 ./prep_dataset/ILSVRC2012_val_00047859.bin 224 224 +15474 ./prep_dataset/ILSVRC2012_val_00039988.bin 224 224 +15475 ./prep_dataset/ILSVRC2012_val_00031093.bin 224 224 +15476 ./prep_dataset/ILSVRC2012_val_00002913.bin 224 224 +15477 ./prep_dataset/ILSVRC2012_val_00024724.bin 224 224 +15478 ./prep_dataset/ILSVRC2012_val_00018651.bin 224 224 +15479 ./prep_dataset/ILSVRC2012_val_00036021.bin 224 224 +15480 ./prep_dataset/ILSVRC2012_val_00005397.bin 224 224 +15481 ./prep_dataset/ILSVRC2012_val_00044302.bin 224 224 +15482 ./prep_dataset/ILSVRC2012_val_00011091.bin 224 224 +15483 ./prep_dataset/ILSVRC2012_val_00038354.bin 224 224 +15484 ./prep_dataset/ILSVRC2012_val_00005986.bin 224 224 +15485 ./prep_dataset/ILSVRC2012_val_00030475.bin 224 224 +15486 ./prep_dataset/ILSVRC2012_val_00033305.bin 224 224 +15487 ./prep_dataset/ILSVRC2012_val_00027797.bin 224 224 +15488 ./prep_dataset/ILSVRC2012_val_00001527.bin 224 224 +15489 ./prep_dataset/ILSVRC2012_val_00033686.bin 224 224 +15490 ./prep_dataset/ILSVRC2012_val_00030470.bin 224 224 +15491 ./prep_dataset/ILSVRC2012_val_00045945.bin 224 224 +15492 ./prep_dataset/ILSVRC2012_val_00032279.bin 224 224 +15493 ./prep_dataset/ILSVRC2012_val_00012139.bin 224 224 +15494 ./prep_dataset/ILSVRC2012_val_00044266.bin 224 224 +15495 ./prep_dataset/ILSVRC2012_val_00019566.bin 224 224 +15496 ./prep_dataset/ILSVRC2012_val_00039348.bin 224 224 +15497 ./prep_dataset/ILSVRC2012_val_00048790.bin 224 224 +15498 ./prep_dataset/ILSVRC2012_val_00030842.bin 224 224 +15499 ./prep_dataset/ILSVRC2012_val_00028101.bin 224 224 +15500 ./prep_dataset/ILSVRC2012_val_00024152.bin 224 224 +15501 ./prep_dataset/ILSVRC2012_val_00015422.bin 224 224 +15502 ./prep_dataset/ILSVRC2012_val_00036163.bin 224 224 +15503 ./prep_dataset/ILSVRC2012_val_00029626.bin 224 224 +15504 ./prep_dataset/ILSVRC2012_val_00008622.bin 224 224 +15505 ./prep_dataset/ILSVRC2012_val_00024434.bin 224 224 +15506 ./prep_dataset/ILSVRC2012_val_00023510.bin 224 224 +15507 ./prep_dataset/ILSVRC2012_val_00034289.bin 224 224 +15508 ./prep_dataset/ILSVRC2012_val_00036650.bin 224 224 +15509 ./prep_dataset/ILSVRC2012_val_00027851.bin 224 224 +15510 ./prep_dataset/ILSVRC2012_val_00006853.bin 224 224 +15511 ./prep_dataset/ILSVRC2012_val_00021875.bin 224 224 +15512 ./prep_dataset/ILSVRC2012_val_00046807.bin 224 224 +15513 ./prep_dataset/ILSVRC2012_val_00021893.bin 224 224 +15514 ./prep_dataset/ILSVRC2012_val_00017227.bin 224 224 +15515 ./prep_dataset/ILSVRC2012_val_00046923.bin 224 224 +15516 ./prep_dataset/ILSVRC2012_val_00004484.bin 224 224 +15517 ./prep_dataset/ILSVRC2012_val_00020299.bin 224 224 +15518 ./prep_dataset/ILSVRC2012_val_00039456.bin 224 224 +15519 ./prep_dataset/ILSVRC2012_val_00012948.bin 224 224 +15520 ./prep_dataset/ILSVRC2012_val_00011090.bin 224 224 +15521 ./prep_dataset/ILSVRC2012_val_00025091.bin 224 224 +15522 ./prep_dataset/ILSVRC2012_val_00016993.bin 224 224 +15523 ./prep_dataset/ILSVRC2012_val_00007491.bin 224 224 +15524 ./prep_dataset/ILSVRC2012_val_00018941.bin 224 224 +15525 ./prep_dataset/ILSVRC2012_val_00026422.bin 224 224 +15526 ./prep_dataset/ILSVRC2012_val_00019241.bin 224 224 +15527 ./prep_dataset/ILSVRC2012_val_00022392.bin 224 224 +15528 ./prep_dataset/ILSVRC2012_val_00003821.bin 224 224 +15529 ./prep_dataset/ILSVRC2012_val_00020455.bin 224 224 +15530 ./prep_dataset/ILSVRC2012_val_00007645.bin 224 224 +15531 ./prep_dataset/ILSVRC2012_val_00027261.bin 224 224 +15532 ./prep_dataset/ILSVRC2012_val_00042276.bin 224 224 +15533 ./prep_dataset/ILSVRC2012_val_00025793.bin 224 224 +15534 ./prep_dataset/ILSVRC2012_val_00032197.bin 224 224 +15535 ./prep_dataset/ILSVRC2012_val_00019853.bin 224 224 +15536 ./prep_dataset/ILSVRC2012_val_00018095.bin 224 224 +15537 ./prep_dataset/ILSVRC2012_val_00045733.bin 224 224 +15538 ./prep_dataset/ILSVRC2012_val_00046073.bin 224 224 +15539 ./prep_dataset/ILSVRC2012_val_00028476.bin 224 224 +15540 ./prep_dataset/ILSVRC2012_val_00045164.bin 224 224 +15541 ./prep_dataset/ILSVRC2012_val_00049006.bin 224 224 +15542 ./prep_dataset/ILSVRC2012_val_00027845.bin 224 224 +15543 ./prep_dataset/ILSVRC2012_val_00002057.bin 224 224 +15544 ./prep_dataset/ILSVRC2012_val_00043669.bin 224 224 +15545 ./prep_dataset/ILSVRC2012_val_00049017.bin 224 224 +15546 ./prep_dataset/ILSVRC2012_val_00022962.bin 224 224 +15547 ./prep_dataset/ILSVRC2012_val_00001965.bin 224 224 +15548 ./prep_dataset/ILSVRC2012_val_00030137.bin 224 224 +15549 ./prep_dataset/ILSVRC2012_val_00032983.bin 224 224 +15550 ./prep_dataset/ILSVRC2012_val_00047441.bin 224 224 +15551 ./prep_dataset/ILSVRC2012_val_00017813.bin 224 224 +15552 ./prep_dataset/ILSVRC2012_val_00038900.bin 224 224 +15553 ./prep_dataset/ILSVRC2012_val_00003161.bin 224 224 +15554 ./prep_dataset/ILSVRC2012_val_00043224.bin 224 224 +15555 ./prep_dataset/ILSVRC2012_val_00012768.bin 224 224 +15556 ./prep_dataset/ILSVRC2012_val_00017712.bin 224 224 +15557 ./prep_dataset/ILSVRC2012_val_00043164.bin 224 224 +15558 ./prep_dataset/ILSVRC2012_val_00019080.bin 224 224 +15559 ./prep_dataset/ILSVRC2012_val_00041745.bin 224 224 +15560 ./prep_dataset/ILSVRC2012_val_00041855.bin 224 224 +15561 ./prep_dataset/ILSVRC2012_val_00008439.bin 224 224 +15562 ./prep_dataset/ILSVRC2012_val_00044341.bin 224 224 +15563 ./prep_dataset/ILSVRC2012_val_00026073.bin 224 224 +15564 ./prep_dataset/ILSVRC2012_val_00022606.bin 224 224 +15565 ./prep_dataset/ILSVRC2012_val_00011820.bin 224 224 +15566 ./prep_dataset/ILSVRC2012_val_00037660.bin 224 224 +15567 ./prep_dataset/ILSVRC2012_val_00032809.bin 224 224 +15568 ./prep_dataset/ILSVRC2012_val_00042410.bin 224 224 +15569 ./prep_dataset/ILSVRC2012_val_00014696.bin 224 224 +15570 ./prep_dataset/ILSVRC2012_val_00015776.bin 224 224 +15571 ./prep_dataset/ILSVRC2012_val_00007140.bin 224 224 +15572 ./prep_dataset/ILSVRC2012_val_00016959.bin 224 224 +15573 ./prep_dataset/ILSVRC2012_val_00009356.bin 224 224 +15574 ./prep_dataset/ILSVRC2012_val_00048109.bin 224 224 +15575 ./prep_dataset/ILSVRC2012_val_00015628.bin 224 224 +15576 ./prep_dataset/ILSVRC2012_val_00011907.bin 224 224 +15577 ./prep_dataset/ILSVRC2012_val_00030810.bin 224 224 +15578 ./prep_dataset/ILSVRC2012_val_00043855.bin 224 224 +15579 ./prep_dataset/ILSVRC2012_val_00026119.bin 224 224 +15580 ./prep_dataset/ILSVRC2012_val_00024100.bin 224 224 +15581 ./prep_dataset/ILSVRC2012_val_00035489.bin 224 224 +15582 ./prep_dataset/ILSVRC2012_val_00044090.bin 224 224 +15583 ./prep_dataset/ILSVRC2012_val_00013443.bin 224 224 +15584 ./prep_dataset/ILSVRC2012_val_00026794.bin 224 224 +15585 ./prep_dataset/ILSVRC2012_val_00034840.bin 224 224 +15586 ./prep_dataset/ILSVRC2012_val_00045824.bin 224 224 +15587 ./prep_dataset/ILSVRC2012_val_00012595.bin 224 224 +15588 ./prep_dataset/ILSVRC2012_val_00002813.bin 224 224 +15589 ./prep_dataset/ILSVRC2012_val_00030210.bin 224 224 +15590 ./prep_dataset/ILSVRC2012_val_00006519.bin 224 224 +15591 ./prep_dataset/ILSVRC2012_val_00045723.bin 224 224 +15592 ./prep_dataset/ILSVRC2012_val_00015002.bin 224 224 +15593 ./prep_dataset/ILSVRC2012_val_00049033.bin 224 224 +15594 ./prep_dataset/ILSVRC2012_val_00031054.bin 224 224 +15595 ./prep_dataset/ILSVRC2012_val_00000856.bin 224 224 +15596 ./prep_dataset/ILSVRC2012_val_00014000.bin 224 224 +15597 ./prep_dataset/ILSVRC2012_val_00038291.bin 224 224 +15598 ./prep_dataset/ILSVRC2012_val_00027728.bin 224 224 +15599 ./prep_dataset/ILSVRC2012_val_00039760.bin 224 224 +15600 ./prep_dataset/ILSVRC2012_val_00010799.bin 224 224 +15601 ./prep_dataset/ILSVRC2012_val_00046557.bin 224 224 +15602 ./prep_dataset/ILSVRC2012_val_00000168.bin 224 224 +15603 ./prep_dataset/ILSVRC2012_val_00041827.bin 224 224 +15604 ./prep_dataset/ILSVRC2012_val_00008059.bin 224 224 +15605 ./prep_dataset/ILSVRC2012_val_00045795.bin 224 224 +15606 ./prep_dataset/ILSVRC2012_val_00002145.bin 224 224 +15607 ./prep_dataset/ILSVRC2012_val_00049817.bin 224 224 +15608 ./prep_dataset/ILSVRC2012_val_00027712.bin 224 224 +15609 ./prep_dataset/ILSVRC2012_val_00031923.bin 224 224 +15610 ./prep_dataset/ILSVRC2012_val_00028598.bin 224 224 +15611 ./prep_dataset/ILSVRC2012_val_00002417.bin 224 224 +15612 ./prep_dataset/ILSVRC2012_val_00010933.bin 224 224 +15613 ./prep_dataset/ILSVRC2012_val_00039368.bin 224 224 +15614 ./prep_dataset/ILSVRC2012_val_00038002.bin 224 224 +15615 ./prep_dataset/ILSVRC2012_val_00007108.bin 224 224 +15616 ./prep_dataset/ILSVRC2012_val_00033178.bin 224 224 +15617 ./prep_dataset/ILSVRC2012_val_00043911.bin 224 224 +15618 ./prep_dataset/ILSVRC2012_val_00013094.bin 224 224 +15619 ./prep_dataset/ILSVRC2012_val_00020841.bin 224 224 +15620 ./prep_dataset/ILSVRC2012_val_00023055.bin 224 224 +15621 ./prep_dataset/ILSVRC2012_val_00004003.bin 224 224 +15622 ./prep_dataset/ILSVRC2012_val_00000364.bin 224 224 +15623 ./prep_dataset/ILSVRC2012_val_00017997.bin 224 224 +15624 ./prep_dataset/ILSVRC2012_val_00044824.bin 224 224 +15625 ./prep_dataset/ILSVRC2012_val_00000471.bin 224 224 +15626 ./prep_dataset/ILSVRC2012_val_00020762.bin 224 224 +15627 ./prep_dataset/ILSVRC2012_val_00006758.bin 224 224 +15628 ./prep_dataset/ILSVRC2012_val_00021010.bin 224 224 +15629 ./prep_dataset/ILSVRC2012_val_00007775.bin 224 224 +15630 ./prep_dataset/ILSVRC2012_val_00047185.bin 224 224 +15631 ./prep_dataset/ILSVRC2012_val_00004133.bin 224 224 +15632 ./prep_dataset/ILSVRC2012_val_00047977.bin 224 224 +15633 ./prep_dataset/ILSVRC2012_val_00034500.bin 224 224 +15634 ./prep_dataset/ILSVRC2012_val_00023502.bin 224 224 +15635 ./prep_dataset/ILSVRC2012_val_00048669.bin 224 224 +15636 ./prep_dataset/ILSVRC2012_val_00026326.bin 224 224 +15637 ./prep_dataset/ILSVRC2012_val_00046075.bin 224 224 +15638 ./prep_dataset/ILSVRC2012_val_00014446.bin 224 224 +15639 ./prep_dataset/ILSVRC2012_val_00027603.bin 224 224 +15640 ./prep_dataset/ILSVRC2012_val_00030067.bin 224 224 +15641 ./prep_dataset/ILSVRC2012_val_00046297.bin 224 224 +15642 ./prep_dataset/ILSVRC2012_val_00028330.bin 224 224 +15643 ./prep_dataset/ILSVRC2012_val_00017209.bin 224 224 +15644 ./prep_dataset/ILSVRC2012_val_00004602.bin 224 224 +15645 ./prep_dataset/ILSVRC2012_val_00009016.bin 224 224 +15646 ./prep_dataset/ILSVRC2012_val_00010537.bin 224 224 +15647 ./prep_dataset/ILSVRC2012_val_00000578.bin 224 224 +15648 ./prep_dataset/ILSVRC2012_val_00042582.bin 224 224 +15649 ./prep_dataset/ILSVRC2012_val_00031753.bin 224 224 +15650 ./prep_dataset/ILSVRC2012_val_00032081.bin 224 224 +15651 ./prep_dataset/ILSVRC2012_val_00017564.bin 224 224 +15652 ./prep_dataset/ILSVRC2012_val_00014673.bin 224 224 +15653 ./prep_dataset/ILSVRC2012_val_00017517.bin 224 224 +15654 ./prep_dataset/ILSVRC2012_val_00005012.bin 224 224 +15655 ./prep_dataset/ILSVRC2012_val_00033410.bin 224 224 +15656 ./prep_dataset/ILSVRC2012_val_00038202.bin 224 224 +15657 ./prep_dataset/ILSVRC2012_val_00020629.bin 224 224 +15658 ./prep_dataset/ILSVRC2012_val_00049538.bin 224 224 +15659 ./prep_dataset/ILSVRC2012_val_00010592.bin 224 224 +15660 ./prep_dataset/ILSVRC2012_val_00041524.bin 224 224 +15661 ./prep_dataset/ILSVRC2012_val_00045639.bin 224 224 +15662 ./prep_dataset/ILSVRC2012_val_00007054.bin 224 224 +15663 ./prep_dataset/ILSVRC2012_val_00013597.bin 224 224 +15664 ./prep_dataset/ILSVRC2012_val_00046076.bin 224 224 +15665 ./prep_dataset/ILSVRC2012_val_00028985.bin 224 224 +15666 ./prep_dataset/ILSVRC2012_val_00007761.bin 224 224 +15667 ./prep_dataset/ILSVRC2012_val_00024389.bin 224 224 +15668 ./prep_dataset/ILSVRC2012_val_00034903.bin 224 224 +15669 ./prep_dataset/ILSVRC2012_val_00034808.bin 224 224 +15670 ./prep_dataset/ILSVRC2012_val_00023137.bin 224 224 +15671 ./prep_dataset/ILSVRC2012_val_00028457.bin 224 224 +15672 ./prep_dataset/ILSVRC2012_val_00040011.bin 224 224 +15673 ./prep_dataset/ILSVRC2012_val_00044372.bin 224 224 +15674 ./prep_dataset/ILSVRC2012_val_00021663.bin 224 224 +15675 ./prep_dataset/ILSVRC2012_val_00037866.bin 224 224 +15676 ./prep_dataset/ILSVRC2012_val_00011384.bin 224 224 +15677 ./prep_dataset/ILSVRC2012_val_00024162.bin 224 224 +15678 ./prep_dataset/ILSVRC2012_val_00018868.bin 224 224 +15679 ./prep_dataset/ILSVRC2012_val_00020188.bin 224 224 +15680 ./prep_dataset/ILSVRC2012_val_00008409.bin 224 224 +15681 ./prep_dataset/ILSVRC2012_val_00043389.bin 224 224 +15682 ./prep_dataset/ILSVRC2012_val_00033324.bin 224 224 +15683 ./prep_dataset/ILSVRC2012_val_00023446.bin 224 224 +15684 ./prep_dataset/ILSVRC2012_val_00018880.bin 224 224 +15685 ./prep_dataset/ILSVRC2012_val_00007424.bin 224 224 +15686 ./prep_dataset/ILSVRC2012_val_00012324.bin 224 224 +15687 ./prep_dataset/ILSVRC2012_val_00020161.bin 224 224 +15688 ./prep_dataset/ILSVRC2012_val_00001810.bin 224 224 +15689 ./prep_dataset/ILSVRC2012_val_00010704.bin 224 224 +15690 ./prep_dataset/ILSVRC2012_val_00020106.bin 224 224 +15691 ./prep_dataset/ILSVRC2012_val_00021221.bin 224 224 +15692 ./prep_dataset/ILSVRC2012_val_00001925.bin 224 224 +15693 ./prep_dataset/ILSVRC2012_val_00006360.bin 224 224 +15694 ./prep_dataset/ILSVRC2012_val_00009094.bin 224 224 +15695 ./prep_dataset/ILSVRC2012_val_00016675.bin 224 224 +15696 ./prep_dataset/ILSVRC2012_val_00002975.bin 224 224 +15697 ./prep_dataset/ILSVRC2012_val_00035668.bin 224 224 +15698 ./prep_dataset/ILSVRC2012_val_00026757.bin 224 224 +15699 ./prep_dataset/ILSVRC2012_val_00006782.bin 224 224 +15700 ./prep_dataset/ILSVRC2012_val_00023280.bin 224 224 +15701 ./prep_dataset/ILSVRC2012_val_00008406.bin 224 224 +15702 ./prep_dataset/ILSVRC2012_val_00014166.bin 224 224 +15703 ./prep_dataset/ILSVRC2012_val_00008170.bin 224 224 +15704 ./prep_dataset/ILSVRC2012_val_00021871.bin 224 224 +15705 ./prep_dataset/ILSVRC2012_val_00012934.bin 224 224 +15706 ./prep_dataset/ILSVRC2012_val_00038974.bin 224 224 +15707 ./prep_dataset/ILSVRC2012_val_00008863.bin 224 224 +15708 ./prep_dataset/ILSVRC2012_val_00028918.bin 224 224 +15709 ./prep_dataset/ILSVRC2012_val_00042227.bin 224 224 +15710 ./prep_dataset/ILSVRC2012_val_00030336.bin 224 224 +15711 ./prep_dataset/ILSVRC2012_val_00001143.bin 224 224 +15712 ./prep_dataset/ILSVRC2012_val_00029650.bin 224 224 +15713 ./prep_dataset/ILSVRC2012_val_00048034.bin 224 224 +15714 ./prep_dataset/ILSVRC2012_val_00002546.bin 224 224 +15715 ./prep_dataset/ILSVRC2012_val_00012723.bin 224 224 +15716 ./prep_dataset/ILSVRC2012_val_00041420.bin 224 224 +15717 ./prep_dataset/ILSVRC2012_val_00044077.bin 224 224 +15718 ./prep_dataset/ILSVRC2012_val_00012793.bin 224 224 +15719 ./prep_dataset/ILSVRC2012_val_00046440.bin 224 224 +15720 ./prep_dataset/ILSVRC2012_val_00041978.bin 224 224 +15721 ./prep_dataset/ILSVRC2012_val_00029905.bin 224 224 +15722 ./prep_dataset/ILSVRC2012_val_00004606.bin 224 224 +15723 ./prep_dataset/ILSVRC2012_val_00019975.bin 224 224 +15724 ./prep_dataset/ILSVRC2012_val_00043720.bin 224 224 +15725 ./prep_dataset/ILSVRC2012_val_00030837.bin 224 224 +15726 ./prep_dataset/ILSVRC2012_val_00006711.bin 224 224 +15727 ./prep_dataset/ILSVRC2012_val_00049265.bin 224 224 +15728 ./prep_dataset/ILSVRC2012_val_00010090.bin 224 224 +15729 ./prep_dataset/ILSVRC2012_val_00030739.bin 224 224 +15730 ./prep_dataset/ILSVRC2012_val_00042180.bin 224 224 +15731 ./prep_dataset/ILSVRC2012_val_00034254.bin 224 224 +15732 ./prep_dataset/ILSVRC2012_val_00029251.bin 224 224 +15733 ./prep_dataset/ILSVRC2012_val_00045700.bin 224 224 +15734 ./prep_dataset/ILSVRC2012_val_00024109.bin 224 224 +15735 ./prep_dataset/ILSVRC2012_val_00024556.bin 224 224 +15736 ./prep_dataset/ILSVRC2012_val_00011618.bin 224 224 +15737 ./prep_dataset/ILSVRC2012_val_00028875.bin 224 224 +15738 ./prep_dataset/ILSVRC2012_val_00037116.bin 224 224 +15739 ./prep_dataset/ILSVRC2012_val_00035633.bin 224 224 +15740 ./prep_dataset/ILSVRC2012_val_00028961.bin 224 224 +15741 ./prep_dataset/ILSVRC2012_val_00014267.bin 224 224 +15742 ./prep_dataset/ILSVRC2012_val_00046405.bin 224 224 +15743 ./prep_dataset/ILSVRC2012_val_00044435.bin 224 224 +15744 ./prep_dataset/ILSVRC2012_val_00049654.bin 224 224 +15745 ./prep_dataset/ILSVRC2012_val_00016047.bin 224 224 +15746 ./prep_dataset/ILSVRC2012_val_00006769.bin 224 224 +15747 ./prep_dataset/ILSVRC2012_val_00019371.bin 224 224 +15748 ./prep_dataset/ILSVRC2012_val_00005928.bin 224 224 +15749 ./prep_dataset/ILSVRC2012_val_00048629.bin 224 224 +15750 ./prep_dataset/ILSVRC2012_val_00049712.bin 224 224 +15751 ./prep_dataset/ILSVRC2012_val_00032196.bin 224 224 +15752 ./prep_dataset/ILSVRC2012_val_00002611.bin 224 224 +15753 ./prep_dataset/ILSVRC2012_val_00019416.bin 224 224 +15754 ./prep_dataset/ILSVRC2012_val_00004051.bin 224 224 +15755 ./prep_dataset/ILSVRC2012_val_00038769.bin 224 224 +15756 ./prep_dataset/ILSVRC2012_val_00028034.bin 224 224 +15757 ./prep_dataset/ILSVRC2012_val_00041755.bin 224 224 +15758 ./prep_dataset/ILSVRC2012_val_00025632.bin 224 224 +15759 ./prep_dataset/ILSVRC2012_val_00024414.bin 224 224 +15760 ./prep_dataset/ILSVRC2012_val_00002926.bin 224 224 +15761 ./prep_dataset/ILSVRC2012_val_00043373.bin 224 224 +15762 ./prep_dataset/ILSVRC2012_val_00036726.bin 224 224 +15763 ./prep_dataset/ILSVRC2012_val_00036351.bin 224 224 +15764 ./prep_dataset/ILSVRC2012_val_00023007.bin 224 224 +15765 ./prep_dataset/ILSVRC2012_val_00038933.bin 224 224 +15766 ./prep_dataset/ILSVRC2012_val_00024267.bin 224 224 +15767 ./prep_dataset/ILSVRC2012_val_00026385.bin 224 224 +15768 ./prep_dataset/ILSVRC2012_val_00042002.bin 224 224 +15769 ./prep_dataset/ILSVRC2012_val_00017344.bin 224 224 +15770 ./prep_dataset/ILSVRC2012_val_00049647.bin 224 224 +15771 ./prep_dataset/ILSVRC2012_val_00011883.bin 224 224 +15772 ./prep_dataset/ILSVRC2012_val_00044074.bin 224 224 +15773 ./prep_dataset/ILSVRC2012_val_00045219.bin 224 224 +15774 ./prep_dataset/ILSVRC2012_val_00018203.bin 224 224 +15775 ./prep_dataset/ILSVRC2012_val_00049087.bin 224 224 +15776 ./prep_dataset/ILSVRC2012_val_00025512.bin 224 224 +15777 ./prep_dataset/ILSVRC2012_val_00028544.bin 224 224 +15778 ./prep_dataset/ILSVRC2012_val_00015967.bin 224 224 +15779 ./prep_dataset/ILSVRC2012_val_00017185.bin 224 224 +15780 ./prep_dataset/ILSVRC2012_val_00010312.bin 224 224 +15781 ./prep_dataset/ILSVRC2012_val_00009411.bin 224 224 +15782 ./prep_dataset/ILSVRC2012_val_00042299.bin 224 224 +15783 ./prep_dataset/ILSVRC2012_val_00027917.bin 224 224 +15784 ./prep_dataset/ILSVRC2012_val_00016502.bin 224 224 +15785 ./prep_dataset/ILSVRC2012_val_00008764.bin 224 224 +15786 ./prep_dataset/ILSVRC2012_val_00031895.bin 224 224 +15787 ./prep_dataset/ILSVRC2012_val_00028669.bin 224 224 +15788 ./prep_dataset/ILSVRC2012_val_00026584.bin 224 224 +15789 ./prep_dataset/ILSVRC2012_val_00046414.bin 224 224 +15790 ./prep_dataset/ILSVRC2012_val_00013013.bin 224 224 +15791 ./prep_dataset/ILSVRC2012_val_00041533.bin 224 224 +15792 ./prep_dataset/ILSVRC2012_val_00048606.bin 224 224 +15793 ./prep_dataset/ILSVRC2012_val_00007509.bin 224 224 +15794 ./prep_dataset/ILSVRC2012_val_00014090.bin 224 224 +15795 ./prep_dataset/ILSVRC2012_val_00039695.bin 224 224 +15796 ./prep_dataset/ILSVRC2012_val_00025976.bin 224 224 +15797 ./prep_dataset/ILSVRC2012_val_00038737.bin 224 224 +15798 ./prep_dataset/ILSVRC2012_val_00006775.bin 224 224 +15799 ./prep_dataset/ILSVRC2012_val_00037967.bin 224 224 +15800 ./prep_dataset/ILSVRC2012_val_00018481.bin 224 224 +15801 ./prep_dataset/ILSVRC2012_val_00037429.bin 224 224 +15802 ./prep_dataset/ILSVRC2012_val_00001056.bin 224 224 +15803 ./prep_dataset/ILSVRC2012_val_00010479.bin 224 224 +15804 ./prep_dataset/ILSVRC2012_val_00031877.bin 224 224 +15805 ./prep_dataset/ILSVRC2012_val_00008592.bin 224 224 +15806 ./prep_dataset/ILSVRC2012_val_00013483.bin 224 224 +15807 ./prep_dataset/ILSVRC2012_val_00046148.bin 224 224 +15808 ./prep_dataset/ILSVRC2012_val_00032796.bin 224 224 +15809 ./prep_dataset/ILSVRC2012_val_00015552.bin 224 224 +15810 ./prep_dataset/ILSVRC2012_val_00013122.bin 224 224 +15811 ./prep_dataset/ILSVRC2012_val_00034606.bin 224 224 +15812 ./prep_dataset/ILSVRC2012_val_00039774.bin 224 224 +15813 ./prep_dataset/ILSVRC2012_val_00023210.bin 224 224 +15814 ./prep_dataset/ILSVRC2012_val_00045633.bin 224 224 +15815 ./prep_dataset/ILSVRC2012_val_00002664.bin 224 224 +15816 ./prep_dataset/ILSVRC2012_val_00047525.bin 224 224 +15817 ./prep_dataset/ILSVRC2012_val_00045599.bin 224 224 +15818 ./prep_dataset/ILSVRC2012_val_00023681.bin 224 224 +15819 ./prep_dataset/ILSVRC2012_val_00037968.bin 224 224 +15820 ./prep_dataset/ILSVRC2012_val_00036028.bin 224 224 +15821 ./prep_dataset/ILSVRC2012_val_00024703.bin 224 224 +15822 ./prep_dataset/ILSVRC2012_val_00040923.bin 224 224 +15823 ./prep_dataset/ILSVRC2012_val_00048303.bin 224 224 +15824 ./prep_dataset/ILSVRC2012_val_00011125.bin 224 224 +15825 ./prep_dataset/ILSVRC2012_val_00019312.bin 224 224 +15826 ./prep_dataset/ILSVRC2012_val_00046466.bin 224 224 +15827 ./prep_dataset/ILSVRC2012_val_00011328.bin 224 224 +15828 ./prep_dataset/ILSVRC2012_val_00013511.bin 224 224 +15829 ./prep_dataset/ILSVRC2012_val_00006473.bin 224 224 +15830 ./prep_dataset/ILSVRC2012_val_00043455.bin 224 224 +15831 ./prep_dataset/ILSVRC2012_val_00000435.bin 224 224 +15832 ./prep_dataset/ILSVRC2012_val_00045207.bin 224 224 +15833 ./prep_dataset/ILSVRC2012_val_00039544.bin 224 224 +15834 ./prep_dataset/ILSVRC2012_val_00038049.bin 224 224 +15835 ./prep_dataset/ILSVRC2012_val_00022380.bin 224 224 +15836 ./prep_dataset/ILSVRC2012_val_00028361.bin 224 224 +15837 ./prep_dataset/ILSVRC2012_val_00049829.bin 224 224 +15838 ./prep_dataset/ILSVRC2012_val_00007721.bin 224 224 +15839 ./prep_dataset/ILSVRC2012_val_00008073.bin 224 224 +15840 ./prep_dataset/ILSVRC2012_val_00013433.bin 224 224 +15841 ./prep_dataset/ILSVRC2012_val_00036518.bin 224 224 +15842 ./prep_dataset/ILSVRC2012_val_00038240.bin 224 224 +15843 ./prep_dataset/ILSVRC2012_val_00000147.bin 224 224 +15844 ./prep_dataset/ILSVRC2012_val_00015512.bin 224 224 +15845 ./prep_dataset/ILSVRC2012_val_00012947.bin 224 224 +15846 ./prep_dataset/ILSVRC2012_val_00044466.bin 224 224 +15847 ./prep_dataset/ILSVRC2012_val_00013810.bin 224 224 +15848 ./prep_dataset/ILSVRC2012_val_00030394.bin 224 224 +15849 ./prep_dataset/ILSVRC2012_val_00018867.bin 224 224 +15850 ./prep_dataset/ILSVRC2012_val_00035393.bin 224 224 +15851 ./prep_dataset/ILSVRC2012_val_00028065.bin 224 224 +15852 ./prep_dataset/ILSVRC2012_val_00022053.bin 224 224 +15853 ./prep_dataset/ILSVRC2012_val_00037714.bin 224 224 +15854 ./prep_dataset/ILSVRC2012_val_00005839.bin 224 224 +15855 ./prep_dataset/ILSVRC2012_val_00007951.bin 224 224 +15856 ./prep_dataset/ILSVRC2012_val_00043212.bin 224 224 +15857 ./prep_dataset/ILSVRC2012_val_00038938.bin 224 224 +15858 ./prep_dataset/ILSVRC2012_val_00013507.bin 224 224 +15859 ./prep_dataset/ILSVRC2012_val_00002070.bin 224 224 +15860 ./prep_dataset/ILSVRC2012_val_00044706.bin 224 224 +15861 ./prep_dataset/ILSVRC2012_val_00016589.bin 224 224 +15862 ./prep_dataset/ILSVRC2012_val_00015801.bin 224 224 +15863 ./prep_dataset/ILSVRC2012_val_00033078.bin 224 224 +15864 ./prep_dataset/ILSVRC2012_val_00036891.bin 224 224 +15865 ./prep_dataset/ILSVRC2012_val_00007304.bin 224 224 +15866 ./prep_dataset/ILSVRC2012_val_00032782.bin 224 224 +15867 ./prep_dataset/ILSVRC2012_val_00008038.bin 224 224 +15868 ./prep_dataset/ILSVRC2012_val_00033251.bin 224 224 +15869 ./prep_dataset/ILSVRC2012_val_00029595.bin 224 224 +15870 ./prep_dataset/ILSVRC2012_val_00004008.bin 224 224 +15871 ./prep_dataset/ILSVRC2012_val_00017341.bin 224 224 +15872 ./prep_dataset/ILSVRC2012_val_00015193.bin 224 224 +15873 ./prep_dataset/ILSVRC2012_val_00011061.bin 224 224 +15874 ./prep_dataset/ILSVRC2012_val_00007588.bin 224 224 +15875 ./prep_dataset/ILSVRC2012_val_00000831.bin 224 224 +15876 ./prep_dataset/ILSVRC2012_val_00040155.bin 224 224 +15877 ./prep_dataset/ILSVRC2012_val_00048255.bin 224 224 +15878 ./prep_dataset/ILSVRC2012_val_00039650.bin 224 224 +15879 ./prep_dataset/ILSVRC2012_val_00024841.bin 224 224 +15880 ./prep_dataset/ILSVRC2012_val_00035124.bin 224 224 +15881 ./prep_dataset/ILSVRC2012_val_00032682.bin 224 224 +15882 ./prep_dataset/ILSVRC2012_val_00008846.bin 224 224 +15883 ./prep_dataset/ILSVRC2012_val_00028626.bin 224 224 +15884 ./prep_dataset/ILSVRC2012_val_00018246.bin 224 224 +15885 ./prep_dataset/ILSVRC2012_val_00010984.bin 224 224 +15886 ./prep_dataset/ILSVRC2012_val_00044437.bin 224 224 +15887 ./prep_dataset/ILSVRC2012_val_00018993.bin 224 224 +15888 ./prep_dataset/ILSVRC2012_val_00003122.bin 224 224 +15889 ./prep_dataset/ILSVRC2012_val_00001434.bin 224 224 +15890 ./prep_dataset/ILSVRC2012_val_00046161.bin 224 224 +15891 ./prep_dataset/ILSVRC2012_val_00013420.bin 224 224 +15892 ./prep_dataset/ILSVRC2012_val_00040049.bin 224 224 +15893 ./prep_dataset/ILSVRC2012_val_00033364.bin 224 224 +15894 ./prep_dataset/ILSVRC2012_val_00040451.bin 224 224 +15895 ./prep_dataset/ILSVRC2012_val_00022907.bin 224 224 +15896 ./prep_dataset/ILSVRC2012_val_00046582.bin 224 224 +15897 ./prep_dataset/ILSVRC2012_val_00023852.bin 224 224 +15898 ./prep_dataset/ILSVRC2012_val_00047612.bin 224 224 +15899 ./prep_dataset/ILSVRC2012_val_00048772.bin 224 224 +15900 ./prep_dataset/ILSVRC2012_val_00036330.bin 224 224 +15901 ./prep_dataset/ILSVRC2012_val_00040287.bin 224 224 +15902 ./prep_dataset/ILSVRC2012_val_00005638.bin 224 224 +15903 ./prep_dataset/ILSVRC2012_val_00005405.bin 224 224 +15904 ./prep_dataset/ILSVRC2012_val_00048759.bin 224 224 +15905 ./prep_dataset/ILSVRC2012_val_00004377.bin 224 224 +15906 ./prep_dataset/ILSVRC2012_val_00022188.bin 224 224 +15907 ./prep_dataset/ILSVRC2012_val_00002093.bin 224 224 +15908 ./prep_dataset/ILSVRC2012_val_00033580.bin 224 224 +15909 ./prep_dataset/ILSVRC2012_val_00028401.bin 224 224 +15910 ./prep_dataset/ILSVRC2012_val_00044375.bin 224 224 +15911 ./prep_dataset/ILSVRC2012_val_00042985.bin 224 224 +15912 ./prep_dataset/ILSVRC2012_val_00009236.bin 224 224 +15913 ./prep_dataset/ILSVRC2012_val_00004057.bin 224 224 +15914 ./prep_dataset/ILSVRC2012_val_00036810.bin 224 224 +15915 ./prep_dataset/ILSVRC2012_val_00018467.bin 224 224 +15916 ./prep_dataset/ILSVRC2012_val_00047263.bin 224 224 +15917 ./prep_dataset/ILSVRC2012_val_00037132.bin 224 224 +15918 ./prep_dataset/ILSVRC2012_val_00011050.bin 224 224 +15919 ./prep_dataset/ILSVRC2012_val_00044908.bin 224 224 +15920 ./prep_dataset/ILSVRC2012_val_00029319.bin 224 224 +15921 ./prep_dataset/ILSVRC2012_val_00014451.bin 224 224 +15922 ./prep_dataset/ILSVRC2012_val_00044676.bin 224 224 +15923 ./prep_dataset/ILSVRC2012_val_00001260.bin 224 224 +15924 ./prep_dataset/ILSVRC2012_val_00001225.bin 224 224 +15925 ./prep_dataset/ILSVRC2012_val_00039719.bin 224 224 +15926 ./prep_dataset/ILSVRC2012_val_00010865.bin 224 224 +15927 ./prep_dataset/ILSVRC2012_val_00030594.bin 224 224 +15928 ./prep_dataset/ILSVRC2012_val_00045655.bin 224 224 +15929 ./prep_dataset/ILSVRC2012_val_00030544.bin 224 224 +15930 ./prep_dataset/ILSVRC2012_val_00047789.bin 224 224 +15931 ./prep_dataset/ILSVRC2012_val_00004161.bin 224 224 +15932 ./prep_dataset/ILSVRC2012_val_00037252.bin 224 224 +15933 ./prep_dataset/ILSVRC2012_val_00041053.bin 224 224 +15934 ./prep_dataset/ILSVRC2012_val_00007681.bin 224 224 +15935 ./prep_dataset/ILSVRC2012_val_00018153.bin 224 224 +15936 ./prep_dataset/ILSVRC2012_val_00016506.bin 224 224 +15937 ./prep_dataset/ILSVRC2012_val_00002184.bin 224 224 +15938 ./prep_dataset/ILSVRC2012_val_00023361.bin 224 224 +15939 ./prep_dataset/ILSVRC2012_val_00012588.bin 224 224 +15940 ./prep_dataset/ILSVRC2012_val_00013873.bin 224 224 +15941 ./prep_dataset/ILSVRC2012_val_00017576.bin 224 224 +15942 ./prep_dataset/ILSVRC2012_val_00012570.bin 224 224 +15943 ./prep_dataset/ILSVRC2012_val_00017212.bin 224 224 +15944 ./prep_dataset/ILSVRC2012_val_00000759.bin 224 224 +15945 ./prep_dataset/ILSVRC2012_val_00034923.bin 224 224 +15946 ./prep_dataset/ILSVRC2012_val_00042323.bin 224 224 +15947 ./prep_dataset/ILSVRC2012_val_00040912.bin 224 224 +15948 ./prep_dataset/ILSVRC2012_val_00022165.bin 224 224 +15949 ./prep_dataset/ILSVRC2012_val_00012910.bin 224 224 +15950 ./prep_dataset/ILSVRC2012_val_00005659.bin 224 224 +15951 ./prep_dataset/ILSVRC2012_val_00001258.bin 224 224 +15952 ./prep_dataset/ILSVRC2012_val_00003812.bin 224 224 +15953 ./prep_dataset/ILSVRC2012_val_00008853.bin 224 224 +15954 ./prep_dataset/ILSVRC2012_val_00021786.bin 224 224 +15955 ./prep_dataset/ILSVRC2012_val_00038699.bin 224 224 +15956 ./prep_dataset/ILSVRC2012_val_00009810.bin 224 224 +15957 ./prep_dataset/ILSVRC2012_val_00004275.bin 224 224 +15958 ./prep_dataset/ILSVRC2012_val_00022674.bin 224 224 +15959 ./prep_dataset/ILSVRC2012_val_00049796.bin 224 224 +15960 ./prep_dataset/ILSVRC2012_val_00004735.bin 224 224 +15961 ./prep_dataset/ILSVRC2012_val_00000738.bin 224 224 +15962 ./prep_dataset/ILSVRC2012_val_00041233.bin 224 224 +15963 ./prep_dataset/ILSVRC2012_val_00023735.bin 224 224 +15964 ./prep_dataset/ILSVRC2012_val_00032044.bin 224 224 +15965 ./prep_dataset/ILSVRC2012_val_00029566.bin 224 224 +15966 ./prep_dataset/ILSVRC2012_val_00004441.bin 224 224 +15967 ./prep_dataset/ILSVRC2012_val_00044021.bin 224 224 +15968 ./prep_dataset/ILSVRC2012_val_00033825.bin 224 224 +15969 ./prep_dataset/ILSVRC2012_val_00002160.bin 224 224 +15970 ./prep_dataset/ILSVRC2012_val_00042169.bin 224 224 +15971 ./prep_dataset/ILSVRC2012_val_00014141.bin 224 224 +15972 ./prep_dataset/ILSVRC2012_val_00011023.bin 224 224 +15973 ./prep_dataset/ILSVRC2012_val_00017060.bin 224 224 +15974 ./prep_dataset/ILSVRC2012_val_00036005.bin 224 224 +15975 ./prep_dataset/ILSVRC2012_val_00042054.bin 224 224 +15976 ./prep_dataset/ILSVRC2012_val_00043973.bin 224 224 +15977 ./prep_dataset/ILSVRC2012_val_00047697.bin 224 224 +15978 ./prep_dataset/ILSVRC2012_val_00002049.bin 224 224 +15979 ./prep_dataset/ILSVRC2012_val_00006089.bin 224 224 +15980 ./prep_dataset/ILSVRC2012_val_00043891.bin 224 224 +15981 ./prep_dataset/ILSVRC2012_val_00049226.bin 224 224 +15982 ./prep_dataset/ILSVRC2012_val_00023382.bin 224 224 +15983 ./prep_dataset/ILSVRC2012_val_00019127.bin 224 224 +15984 ./prep_dataset/ILSVRC2012_val_00028979.bin 224 224 +15985 ./prep_dataset/ILSVRC2012_val_00039754.bin 224 224 +15986 ./prep_dataset/ILSVRC2012_val_00017063.bin 224 224 +15987 ./prep_dataset/ILSVRC2012_val_00040907.bin 224 224 +15988 ./prep_dataset/ILSVRC2012_val_00039770.bin 224 224 +15989 ./prep_dataset/ILSVRC2012_val_00013049.bin 224 224 +15990 ./prep_dataset/ILSVRC2012_val_00026972.bin 224 224 +15991 ./prep_dataset/ILSVRC2012_val_00005618.bin 224 224 +15992 ./prep_dataset/ILSVRC2012_val_00029034.bin 224 224 +15993 ./prep_dataset/ILSVRC2012_val_00022130.bin 224 224 +15994 ./prep_dataset/ILSVRC2012_val_00029822.bin 224 224 +15995 ./prep_dataset/ILSVRC2012_val_00023214.bin 224 224 +15996 ./prep_dataset/ILSVRC2012_val_00036956.bin 224 224 +15997 ./prep_dataset/ILSVRC2012_val_00016934.bin 224 224 +15998 ./prep_dataset/ILSVRC2012_val_00043291.bin 224 224 +15999 ./prep_dataset/ILSVRC2012_val_00019713.bin 224 224 +16000 ./prep_dataset/ILSVRC2012_val_00032760.bin 224 224 +16001 ./prep_dataset/ILSVRC2012_val_00027088.bin 224 224 +16002 ./prep_dataset/ILSVRC2012_val_00035538.bin 224 224 +16003 ./prep_dataset/ILSVRC2012_val_00042260.bin 224 224 +16004 ./prep_dataset/ILSVRC2012_val_00026648.bin 224 224 +16005 ./prep_dataset/ILSVRC2012_val_00005218.bin 224 224 +16006 ./prep_dataset/ILSVRC2012_val_00028890.bin 224 224 +16007 ./prep_dataset/ILSVRC2012_val_00044902.bin 224 224 +16008 ./prep_dataset/ILSVRC2012_val_00002574.bin 224 224 +16009 ./prep_dataset/ILSVRC2012_val_00040645.bin 224 224 +16010 ./prep_dataset/ILSVRC2012_val_00038583.bin 224 224 +16011 ./prep_dataset/ILSVRC2012_val_00002862.bin 224 224 +16012 ./prep_dataset/ILSVRC2012_val_00043415.bin 224 224 +16013 ./prep_dataset/ILSVRC2012_val_00022610.bin 224 224 +16014 ./prep_dataset/ILSVRC2012_val_00023138.bin 224 224 +16015 ./prep_dataset/ILSVRC2012_val_00001762.bin 224 224 +16016 ./prep_dataset/ILSVRC2012_val_00037580.bin 224 224 +16017 ./prep_dataset/ILSVRC2012_val_00025813.bin 224 224 +16018 ./prep_dataset/ILSVRC2012_val_00045474.bin 224 224 +16019 ./prep_dataset/ILSVRC2012_val_00027676.bin 224 224 +16020 ./prep_dataset/ILSVRC2012_val_00048884.bin 224 224 +16021 ./prep_dataset/ILSVRC2012_val_00005505.bin 224 224 +16022 ./prep_dataset/ILSVRC2012_val_00028299.bin 224 224 +16023 ./prep_dataset/ILSVRC2012_val_00021860.bin 224 224 +16024 ./prep_dataset/ILSVRC2012_val_00031592.bin 224 224 +16025 ./prep_dataset/ILSVRC2012_val_00030278.bin 224 224 +16026 ./prep_dataset/ILSVRC2012_val_00011625.bin 224 224 +16027 ./prep_dataset/ILSVRC2012_val_00038440.bin 224 224 +16028 ./prep_dataset/ILSVRC2012_val_00033991.bin 224 224 +16029 ./prep_dataset/ILSVRC2012_val_00002261.bin 224 224 +16030 ./prep_dataset/ILSVRC2012_val_00041810.bin 224 224 +16031 ./prep_dataset/ILSVRC2012_val_00009110.bin 224 224 +16032 ./prep_dataset/ILSVRC2012_val_00008134.bin 224 224 +16033 ./prep_dataset/ILSVRC2012_val_00020639.bin 224 224 +16034 ./prep_dataset/ILSVRC2012_val_00044992.bin 224 224 +16035 ./prep_dataset/ILSVRC2012_val_00020412.bin 224 224 +16036 ./prep_dataset/ILSVRC2012_val_00049965.bin 224 224 +16037 ./prep_dataset/ILSVRC2012_val_00045001.bin 224 224 +16038 ./prep_dataset/ILSVRC2012_val_00027848.bin 224 224 +16039 ./prep_dataset/ILSVRC2012_val_00014494.bin 224 224 +16040 ./prep_dataset/ILSVRC2012_val_00021030.bin 224 224 +16041 ./prep_dataset/ILSVRC2012_val_00023778.bin 224 224 +16042 ./prep_dataset/ILSVRC2012_val_00028739.bin 224 224 +16043 ./prep_dataset/ILSVRC2012_val_00011077.bin 224 224 +16044 ./prep_dataset/ILSVRC2012_val_00033751.bin 224 224 +16045 ./prep_dataset/ILSVRC2012_val_00007580.bin 224 224 +16046 ./prep_dataset/ILSVRC2012_val_00023731.bin 224 224 +16047 ./prep_dataset/ILSVRC2012_val_00007394.bin 224 224 +16048 ./prep_dataset/ILSVRC2012_val_00011539.bin 224 224 +16049 ./prep_dataset/ILSVRC2012_val_00048583.bin 224 224 +16050 ./prep_dataset/ILSVRC2012_val_00000732.bin 224 224 +16051 ./prep_dataset/ILSVRC2012_val_00049401.bin 224 224 +16052 ./prep_dataset/ILSVRC2012_val_00023601.bin 224 224 +16053 ./prep_dataset/ILSVRC2012_val_00019642.bin 224 224 +16054 ./prep_dataset/ILSVRC2012_val_00036423.bin 224 224 +16055 ./prep_dataset/ILSVRC2012_val_00024669.bin 224 224 +16056 ./prep_dataset/ILSVRC2012_val_00001583.bin 224 224 +16057 ./prep_dataset/ILSVRC2012_val_00029342.bin 224 224 +16058 ./prep_dataset/ILSVRC2012_val_00026163.bin 224 224 +16059 ./prep_dataset/ILSVRC2012_val_00015971.bin 224 224 +16060 ./prep_dataset/ILSVRC2012_val_00047360.bin 224 224 +16061 ./prep_dataset/ILSVRC2012_val_00025857.bin 224 224 +16062 ./prep_dataset/ILSVRC2012_val_00012969.bin 224 224 +16063 ./prep_dataset/ILSVRC2012_val_00002108.bin 224 224 +16064 ./prep_dataset/ILSVRC2012_val_00042043.bin 224 224 +16065 ./prep_dataset/ILSVRC2012_val_00048676.bin 224 224 +16066 ./prep_dataset/ILSVRC2012_val_00012824.bin 224 224 +16067 ./prep_dataset/ILSVRC2012_val_00023338.bin 224 224 +16068 ./prep_dataset/ILSVRC2012_val_00004881.bin 224 224 +16069 ./prep_dataset/ILSVRC2012_val_00046513.bin 224 224 +16070 ./prep_dataset/ILSVRC2012_val_00021051.bin 224 224 +16071 ./prep_dataset/ILSVRC2012_val_00004215.bin 224 224 +16072 ./prep_dataset/ILSVRC2012_val_00018049.bin 224 224 +16073 ./prep_dataset/ILSVRC2012_val_00003556.bin 224 224 +16074 ./prep_dataset/ILSVRC2012_val_00015966.bin 224 224 +16075 ./prep_dataset/ILSVRC2012_val_00014951.bin 224 224 +16076 ./prep_dataset/ILSVRC2012_val_00001563.bin 224 224 +16077 ./prep_dataset/ILSVRC2012_val_00023934.bin 224 224 +16078 ./prep_dataset/ILSVRC2012_val_00012375.bin 224 224 +16079 ./prep_dataset/ILSVRC2012_val_00013599.bin 224 224 +16080 ./prep_dataset/ILSVRC2012_val_00047409.bin 224 224 +16081 ./prep_dataset/ILSVRC2012_val_00019342.bin 224 224 +16082 ./prep_dataset/ILSVRC2012_val_00021164.bin 224 224 +16083 ./prep_dataset/ILSVRC2012_val_00036851.bin 224 224 +16084 ./prep_dataset/ILSVRC2012_val_00044209.bin 224 224 +16085 ./prep_dataset/ILSVRC2012_val_00024001.bin 224 224 +16086 ./prep_dataset/ILSVRC2012_val_00011425.bin 224 224 +16087 ./prep_dataset/ILSVRC2012_val_00002172.bin 224 224 +16088 ./prep_dataset/ILSVRC2012_val_00021991.bin 224 224 +16089 ./prep_dataset/ILSVRC2012_val_00036992.bin 224 224 +16090 ./prep_dataset/ILSVRC2012_val_00018801.bin 224 224 +16091 ./prep_dataset/ILSVRC2012_val_00043454.bin 224 224 +16092 ./prep_dataset/ILSVRC2012_val_00038167.bin 224 224 +16093 ./prep_dataset/ILSVRC2012_val_00047438.bin 224 224 +16094 ./prep_dataset/ILSVRC2012_val_00017459.bin 224 224 +16095 ./prep_dataset/ILSVRC2012_val_00047815.bin 224 224 +16096 ./prep_dataset/ILSVRC2012_val_00010636.bin 224 224 +16097 ./prep_dataset/ILSVRC2012_val_00022114.bin 224 224 +16098 ./prep_dataset/ILSVRC2012_val_00017259.bin 224 224 +16099 ./prep_dataset/ILSVRC2012_val_00011017.bin 224 224 +16100 ./prep_dataset/ILSVRC2012_val_00043206.bin 224 224 +16101 ./prep_dataset/ILSVRC2012_val_00013727.bin 224 224 +16102 ./prep_dataset/ILSVRC2012_val_00023499.bin 224 224 +16103 ./prep_dataset/ILSVRC2012_val_00043780.bin 224 224 +16104 ./prep_dataset/ILSVRC2012_val_00037672.bin 224 224 +16105 ./prep_dataset/ILSVRC2012_val_00037527.bin 224 224 +16106 ./prep_dataset/ILSVRC2012_val_00019482.bin 224 224 +16107 ./prep_dataset/ILSVRC2012_val_00001595.bin 224 224 +16108 ./prep_dataset/ILSVRC2012_val_00044219.bin 224 224 +16109 ./prep_dataset/ILSVRC2012_val_00035878.bin 224 224 +16110 ./prep_dataset/ILSVRC2012_val_00037590.bin 224 224 +16111 ./prep_dataset/ILSVRC2012_val_00044640.bin 224 224 +16112 ./prep_dataset/ILSVRC2012_val_00001598.bin 224 224 +16113 ./prep_dataset/ILSVRC2012_val_00012287.bin 224 224 +16114 ./prep_dataset/ILSVRC2012_val_00015345.bin 224 224 +16115 ./prep_dataset/ILSVRC2012_val_00011200.bin 224 224 +16116 ./prep_dataset/ILSVRC2012_val_00027415.bin 224 224 +16117 ./prep_dataset/ILSVRC2012_val_00007924.bin 224 224 +16118 ./prep_dataset/ILSVRC2012_val_00031807.bin 224 224 +16119 ./prep_dataset/ILSVRC2012_val_00036875.bin 224 224 +16120 ./prep_dataset/ILSVRC2012_val_00049706.bin 224 224 +16121 ./prep_dataset/ILSVRC2012_val_00049136.bin 224 224 +16122 ./prep_dataset/ILSVRC2012_val_00020113.bin 224 224 +16123 ./prep_dataset/ILSVRC2012_val_00008625.bin 224 224 +16124 ./prep_dataset/ILSVRC2012_val_00047893.bin 224 224 +16125 ./prep_dataset/ILSVRC2012_val_00048862.bin 224 224 +16126 ./prep_dataset/ILSVRC2012_val_00039245.bin 224 224 +16127 ./prep_dataset/ILSVRC2012_val_00024278.bin 224 224 +16128 ./prep_dataset/ILSVRC2012_val_00020143.bin 224 224 +16129 ./prep_dataset/ILSVRC2012_val_00001012.bin 224 224 +16130 ./prep_dataset/ILSVRC2012_val_00019507.bin 224 224 +16131 ./prep_dataset/ILSVRC2012_val_00017416.bin 224 224 +16132 ./prep_dataset/ILSVRC2012_val_00010154.bin 224 224 +16133 ./prep_dataset/ILSVRC2012_val_00016662.bin 224 224 +16134 ./prep_dataset/ILSVRC2012_val_00005853.bin 224 224 +16135 ./prep_dataset/ILSVRC2012_val_00027767.bin 224 224 +16136 ./prep_dataset/ILSVRC2012_val_00002671.bin 224 224 +16137 ./prep_dataset/ILSVRC2012_val_00006674.bin 224 224 +16138 ./prep_dataset/ILSVRC2012_val_00026104.bin 224 224 +16139 ./prep_dataset/ILSVRC2012_val_00021772.bin 224 224 +16140 ./prep_dataset/ILSVRC2012_val_00024991.bin 224 224 +16141 ./prep_dataset/ILSVRC2012_val_00021725.bin 224 224 +16142 ./prep_dataset/ILSVRC2012_val_00025332.bin 224 224 +16143 ./prep_dataset/ILSVRC2012_val_00034224.bin 224 224 +16144 ./prep_dataset/ILSVRC2012_val_00000105.bin 224 224 +16145 ./prep_dataset/ILSVRC2012_val_00042052.bin 224 224 +16146 ./prep_dataset/ILSVRC2012_val_00005446.bin 224 224 +16147 ./prep_dataset/ILSVRC2012_val_00025490.bin 224 224 +16148 ./prep_dataset/ILSVRC2012_val_00038669.bin 224 224 +16149 ./prep_dataset/ILSVRC2012_val_00046613.bin 224 224 +16150 ./prep_dataset/ILSVRC2012_val_00032065.bin 224 224 +16151 ./prep_dataset/ILSVRC2012_val_00031020.bin 224 224 +16152 ./prep_dataset/ILSVRC2012_val_00019687.bin 224 224 +16153 ./prep_dataset/ILSVRC2012_val_00021016.bin 224 224 +16154 ./prep_dataset/ILSVRC2012_val_00013954.bin 224 224 +16155 ./prep_dataset/ILSVRC2012_val_00008233.bin 224 224 +16156 ./prep_dataset/ILSVRC2012_val_00037235.bin 224 224 +16157 ./prep_dataset/ILSVRC2012_val_00001000.bin 224 224 +16158 ./prep_dataset/ILSVRC2012_val_00028589.bin 224 224 +16159 ./prep_dataset/ILSVRC2012_val_00019378.bin 224 224 +16160 ./prep_dataset/ILSVRC2012_val_00040380.bin 224 224 +16161 ./prep_dataset/ILSVRC2012_val_00000907.bin 224 224 +16162 ./prep_dataset/ILSVRC2012_val_00026725.bin 224 224 +16163 ./prep_dataset/ILSVRC2012_val_00000969.bin 224 224 +16164 ./prep_dataset/ILSVRC2012_val_00003652.bin 224 224 +16165 ./prep_dataset/ILSVRC2012_val_00020535.bin 224 224 +16166 ./prep_dataset/ILSVRC2012_val_00042011.bin 224 224 +16167 ./prep_dataset/ILSVRC2012_val_00011468.bin 224 224 +16168 ./prep_dataset/ILSVRC2012_val_00023516.bin 224 224 +16169 ./prep_dataset/ILSVRC2012_val_00036452.bin 224 224 +16170 ./prep_dataset/ILSVRC2012_val_00014931.bin 224 224 +16171 ./prep_dataset/ILSVRC2012_val_00032220.bin 224 224 +16172 ./prep_dataset/ILSVRC2012_val_00021154.bin 224 224 +16173 ./prep_dataset/ILSVRC2012_val_00043341.bin 224 224 +16174 ./prep_dataset/ILSVRC2012_val_00011865.bin 224 224 +16175 ./prep_dataset/ILSVRC2012_val_00041792.bin 224 224 +16176 ./prep_dataset/ILSVRC2012_val_00038282.bin 224 224 +16177 ./prep_dataset/ILSVRC2012_val_00040516.bin 224 224 +16178 ./prep_dataset/ILSVRC2012_val_00011763.bin 224 224 +16179 ./prep_dataset/ILSVRC2012_val_00020567.bin 224 224 +16180 ./prep_dataset/ILSVRC2012_val_00045610.bin 224 224 +16181 ./prep_dataset/ILSVRC2012_val_00009822.bin 224 224 +16182 ./prep_dataset/ILSVRC2012_val_00037958.bin 224 224 +16183 ./prep_dataset/ILSVRC2012_val_00043833.bin 224 224 +16184 ./prep_dataset/ILSVRC2012_val_00026322.bin 224 224 +16185 ./prep_dataset/ILSVRC2012_val_00047952.bin 224 224 +16186 ./prep_dataset/ILSVRC2012_val_00047025.bin 224 224 +16187 ./prep_dataset/ILSVRC2012_val_00028278.bin 224 224 +16188 ./prep_dataset/ILSVRC2012_val_00016611.bin 224 224 +16189 ./prep_dataset/ILSVRC2012_val_00013695.bin 224 224 +16190 ./prep_dataset/ILSVRC2012_val_00039551.bin 224 224 +16191 ./prep_dataset/ILSVRC2012_val_00030022.bin 224 224 +16192 ./prep_dataset/ILSVRC2012_val_00009609.bin 224 224 +16193 ./prep_dataset/ILSVRC2012_val_00046953.bin 224 224 +16194 ./prep_dataset/ILSVRC2012_val_00039635.bin 224 224 +16195 ./prep_dataset/ILSVRC2012_val_00047576.bin 224 224 +16196 ./prep_dataset/ILSVRC2012_val_00036868.bin 224 224 +16197 ./prep_dataset/ILSVRC2012_val_00037977.bin 224 224 +16198 ./prep_dataset/ILSVRC2012_val_00035105.bin 224 224 +16199 ./prep_dataset/ILSVRC2012_val_00042146.bin 224 224 +16200 ./prep_dataset/ILSVRC2012_val_00037789.bin 224 224 +16201 ./prep_dataset/ILSVRC2012_val_00032558.bin 224 224 +16202 ./prep_dataset/ILSVRC2012_val_00028600.bin 224 224 +16203 ./prep_dataset/ILSVRC2012_val_00000058.bin 224 224 +16204 ./prep_dataset/ILSVRC2012_val_00027339.bin 224 224 +16205 ./prep_dataset/ILSVRC2012_val_00048642.bin 224 224 +16206 ./prep_dataset/ILSVRC2012_val_00003352.bin 224 224 +16207 ./prep_dataset/ILSVRC2012_val_00040466.bin 224 224 +16208 ./prep_dataset/ILSVRC2012_val_00040199.bin 224 224 +16209 ./prep_dataset/ILSVRC2012_val_00011932.bin 224 224 +16210 ./prep_dataset/ILSVRC2012_val_00044136.bin 224 224 +16211 ./prep_dataset/ILSVRC2012_val_00005933.bin 224 224 +16212 ./prep_dataset/ILSVRC2012_val_00007281.bin 224 224 +16213 ./prep_dataset/ILSVRC2012_val_00000850.bin 224 224 +16214 ./prep_dataset/ILSVRC2012_val_00034537.bin 224 224 +16215 ./prep_dataset/ILSVRC2012_val_00027649.bin 224 224 +16216 ./prep_dataset/ILSVRC2012_val_00013422.bin 224 224 +16217 ./prep_dataset/ILSVRC2012_val_00041887.bin 224 224 +16218 ./prep_dataset/ILSVRC2012_val_00009184.bin 224 224 +16219 ./prep_dataset/ILSVRC2012_val_00008131.bin 224 224 +16220 ./prep_dataset/ILSVRC2012_val_00018490.bin 224 224 +16221 ./prep_dataset/ILSVRC2012_val_00002567.bin 224 224 +16222 ./prep_dataset/ILSVRC2012_val_00047051.bin 224 224 +16223 ./prep_dataset/ILSVRC2012_val_00019927.bin 224 224 +16224 ./prep_dataset/ILSVRC2012_val_00003033.bin 224 224 +16225 ./prep_dataset/ILSVRC2012_val_00015001.bin 224 224 +16226 ./prep_dataset/ILSVRC2012_val_00035018.bin 224 224 +16227 ./prep_dataset/ILSVRC2012_val_00022653.bin 224 224 +16228 ./prep_dataset/ILSVRC2012_val_00042802.bin 224 224 +16229 ./prep_dataset/ILSVRC2012_val_00001330.bin 224 224 +16230 ./prep_dataset/ILSVRC2012_val_00024017.bin 224 224 +16231 ./prep_dataset/ILSVRC2012_val_00027893.bin 224 224 +16232 ./prep_dataset/ILSVRC2012_val_00038258.bin 224 224 +16233 ./prep_dataset/ILSVRC2012_val_00019540.bin 224 224 +16234 ./prep_dataset/ILSVRC2012_val_00042839.bin 224 224 +16235 ./prep_dataset/ILSVRC2012_val_00024294.bin 224 224 +16236 ./prep_dataset/ILSVRC2012_val_00026808.bin 224 224 +16237 ./prep_dataset/ILSVRC2012_val_00001815.bin 224 224 +16238 ./prep_dataset/ILSVRC2012_val_00043467.bin 224 224 +16239 ./prep_dataset/ILSVRC2012_val_00040716.bin 224 224 +16240 ./prep_dataset/ILSVRC2012_val_00042186.bin 224 224 +16241 ./prep_dataset/ILSVRC2012_val_00003660.bin 224 224 +16242 ./prep_dataset/ILSVRC2012_val_00003725.bin 224 224 +16243 ./prep_dataset/ILSVRC2012_val_00004511.bin 224 224 +16244 ./prep_dataset/ILSVRC2012_val_00001613.bin 224 224 +16245 ./prep_dataset/ILSVRC2012_val_00014246.bin 224 224 +16246 ./prep_dataset/ILSVRC2012_val_00008453.bin 224 224 +16247 ./prep_dataset/ILSVRC2012_val_00003819.bin 224 224 +16248 ./prep_dataset/ILSVRC2012_val_00021874.bin 224 224 +16249 ./prep_dataset/ILSVRC2012_val_00016695.bin 224 224 +16250 ./prep_dataset/ILSVRC2012_val_00020541.bin 224 224 +16251 ./prep_dataset/ILSVRC2012_val_00034561.bin 224 224 +16252 ./prep_dataset/ILSVRC2012_val_00030942.bin 224 224 +16253 ./prep_dataset/ILSVRC2012_val_00042027.bin 224 224 +16254 ./prep_dataset/ILSVRC2012_val_00017392.bin 224 224 +16255 ./prep_dataset/ILSVRC2012_val_00035344.bin 224 224 +16256 ./prep_dataset/ILSVRC2012_val_00007278.bin 224 224 +16257 ./prep_dataset/ILSVRC2012_val_00037584.bin 224 224 +16258 ./prep_dataset/ILSVRC2012_val_00017161.bin 224 224 +16259 ./prep_dataset/ILSVRC2012_val_00045511.bin 224 224 +16260 ./prep_dataset/ILSVRC2012_val_00032571.bin 224 224 +16261 ./prep_dataset/ILSVRC2012_val_00039206.bin 224 224 +16262 ./prep_dataset/ILSVRC2012_val_00027218.bin 224 224 +16263 ./prep_dataset/ILSVRC2012_val_00013970.bin 224 224 +16264 ./prep_dataset/ILSVRC2012_val_00009897.bin 224 224 +16265 ./prep_dataset/ILSVRC2012_val_00001972.bin 224 224 +16266 ./prep_dataset/ILSVRC2012_val_00031851.bin 224 224 +16267 ./prep_dataset/ILSVRC2012_val_00033419.bin 224 224 +16268 ./prep_dataset/ILSVRC2012_val_00038274.bin 224 224 +16269 ./prep_dataset/ILSVRC2012_val_00041177.bin 224 224 +16270 ./prep_dataset/ILSVRC2012_val_00049950.bin 224 224 +16271 ./prep_dataset/ILSVRC2012_val_00026598.bin 224 224 +16272 ./prep_dataset/ILSVRC2012_val_00037077.bin 224 224 +16273 ./prep_dataset/ILSVRC2012_val_00049792.bin 224 224 +16274 ./prep_dataset/ILSVRC2012_val_00032851.bin 224 224 +16275 ./prep_dataset/ILSVRC2012_val_00038683.bin 224 224 +16276 ./prep_dataset/ILSVRC2012_val_00022215.bin 224 224 +16277 ./prep_dataset/ILSVRC2012_val_00004048.bin 224 224 +16278 ./prep_dataset/ILSVRC2012_val_00002850.bin 224 224 +16279 ./prep_dataset/ILSVRC2012_val_00044226.bin 224 224 +16280 ./prep_dataset/ILSVRC2012_val_00047797.bin 224 224 +16281 ./prep_dataset/ILSVRC2012_val_00045077.bin 224 224 +16282 ./prep_dataset/ILSVRC2012_val_00006754.bin 224 224 +16283 ./prep_dataset/ILSVRC2012_val_00037973.bin 224 224 +16284 ./prep_dataset/ILSVRC2012_val_00002518.bin 224 224 +16285 ./prep_dataset/ILSVRC2012_val_00049793.bin 224 224 +16286 ./prep_dataset/ILSVRC2012_val_00006477.bin 224 224 +16287 ./prep_dataset/ILSVRC2012_val_00023991.bin 224 224 +16288 ./prep_dataset/ILSVRC2012_val_00007152.bin 224 224 +16289 ./prep_dataset/ILSVRC2012_val_00010779.bin 224 224 +16290 ./prep_dataset/ILSVRC2012_val_00032621.bin 224 224 +16291 ./prep_dataset/ILSVRC2012_val_00038032.bin 224 224 +16292 ./prep_dataset/ILSVRC2012_val_00018708.bin 224 224 +16293 ./prep_dataset/ILSVRC2012_val_00012856.bin 224 224 +16294 ./prep_dataset/ILSVRC2012_val_00047109.bin 224 224 +16295 ./prep_dataset/ILSVRC2012_val_00007614.bin 224 224 +16296 ./prep_dataset/ILSVRC2012_val_00004067.bin 224 224 +16297 ./prep_dataset/ILSVRC2012_val_00046499.bin 224 224 +16298 ./prep_dataset/ILSVRC2012_val_00012138.bin 224 224 +16299 ./prep_dataset/ILSVRC2012_val_00027973.bin 224 224 +16300 ./prep_dataset/ILSVRC2012_val_00029696.bin 224 224 +16301 ./prep_dataset/ILSVRC2012_val_00044416.bin 224 224 +16302 ./prep_dataset/ILSVRC2012_val_00027181.bin 224 224 +16303 ./prep_dataset/ILSVRC2012_val_00036933.bin 224 224 +16304 ./prep_dataset/ILSVRC2012_val_00006951.bin 224 224 +16305 ./prep_dataset/ILSVRC2012_val_00015163.bin 224 224 +16306 ./prep_dataset/ILSVRC2012_val_00001285.bin 224 224 +16307 ./prep_dataset/ILSVRC2012_val_00019188.bin 224 224 +16308 ./prep_dataset/ILSVRC2012_val_00033002.bin 224 224 +16309 ./prep_dataset/ILSVRC2012_val_00028687.bin 224 224 +16310 ./prep_dataset/ILSVRC2012_val_00009449.bin 224 224 +16311 ./prep_dataset/ILSVRC2012_val_00037360.bin 224 224 +16312 ./prep_dataset/ILSVRC2012_val_00007486.bin 224 224 +16313 ./prep_dataset/ILSVRC2012_val_00026515.bin 224 224 +16314 ./prep_dataset/ILSVRC2012_val_00049634.bin 224 224 +16315 ./prep_dataset/ILSVRC2012_val_00045500.bin 224 224 +16316 ./prep_dataset/ILSVRC2012_val_00007432.bin 224 224 +16317 ./prep_dataset/ILSVRC2012_val_00006331.bin 224 224 +16318 ./prep_dataset/ILSVRC2012_val_00033636.bin 224 224 +16319 ./prep_dataset/ILSVRC2012_val_00029168.bin 224 224 +16320 ./prep_dataset/ILSVRC2012_val_00029077.bin 224 224 +16321 ./prep_dataset/ILSVRC2012_val_00022030.bin 224 224 +16322 ./prep_dataset/ILSVRC2012_val_00042387.bin 224 224 +16323 ./prep_dataset/ILSVRC2012_val_00040142.bin 224 224 +16324 ./prep_dataset/ILSVRC2012_val_00030072.bin 224 224 +16325 ./prep_dataset/ILSVRC2012_val_00038584.bin 224 224 +16326 ./prep_dataset/ILSVRC2012_val_00026192.bin 224 224 +16327 ./prep_dataset/ILSVRC2012_val_00029050.bin 224 224 +16328 ./prep_dataset/ILSVRC2012_val_00016752.bin 224 224 +16329 ./prep_dataset/ILSVRC2012_val_00021173.bin 224 224 +16330 ./prep_dataset/ILSVRC2012_val_00004685.bin 224 224 +16331 ./prep_dataset/ILSVRC2012_val_00005263.bin 224 224 +16332 ./prep_dataset/ILSVRC2012_val_00004715.bin 224 224 +16333 ./prep_dataset/ILSVRC2012_val_00045853.bin 224 224 +16334 ./prep_dataset/ILSVRC2012_val_00016393.bin 224 224 +16335 ./prep_dataset/ILSVRC2012_val_00046282.bin 224 224 +16336 ./prep_dataset/ILSVRC2012_val_00032102.bin 224 224 +16337 ./prep_dataset/ILSVRC2012_val_00041149.bin 224 224 +16338 ./prep_dataset/ILSVRC2012_val_00028673.bin 224 224 +16339 ./prep_dataset/ILSVRC2012_val_00028806.bin 224 224 +16340 ./prep_dataset/ILSVRC2012_val_00040897.bin 224 224 +16341 ./prep_dataset/ILSVRC2012_val_00007165.bin 224 224 +16342 ./prep_dataset/ILSVRC2012_val_00000421.bin 224 224 +16343 ./prep_dataset/ILSVRC2012_val_00031906.bin 224 224 +16344 ./prep_dataset/ILSVRC2012_val_00006850.bin 224 224 +16345 ./prep_dataset/ILSVRC2012_val_00015210.bin 224 224 +16346 ./prep_dataset/ILSVRC2012_val_00046936.bin 224 224 +16347 ./prep_dataset/ILSVRC2012_val_00022185.bin 224 224 +16348 ./prep_dataset/ILSVRC2012_val_00042770.bin 224 224 +16349 ./prep_dataset/ILSVRC2012_val_00019130.bin 224 224 +16350 ./prep_dataset/ILSVRC2012_val_00008901.bin 224 224 +16351 ./prep_dataset/ILSVRC2012_val_00038653.bin 224 224 +16352 ./prep_dataset/ILSVRC2012_val_00019220.bin 224 224 +16353 ./prep_dataset/ILSVRC2012_val_00010972.bin 224 224 +16354 ./prep_dataset/ILSVRC2012_val_00046323.bin 224 224 +16355 ./prep_dataset/ILSVRC2012_val_00045482.bin 224 224 +16356 ./prep_dataset/ILSVRC2012_val_00049410.bin 224 224 +16357 ./prep_dataset/ILSVRC2012_val_00015130.bin 224 224 +16358 ./prep_dataset/ILSVRC2012_val_00006978.bin 224 224 +16359 ./prep_dataset/ILSVRC2012_val_00006514.bin 224 224 +16360 ./prep_dataset/ILSVRC2012_val_00022630.bin 224 224 +16361 ./prep_dataset/ILSVRC2012_val_00035361.bin 224 224 +16362 ./prep_dataset/ILSVRC2012_val_00016983.bin 224 224 +16363 ./prep_dataset/ILSVRC2012_val_00021657.bin 224 224 +16364 ./prep_dataset/ILSVRC2012_val_00035083.bin 224 224 +16365 ./prep_dataset/ILSVRC2012_val_00044103.bin 224 224 +16366 ./prep_dataset/ILSVRC2012_val_00024981.bin 224 224 +16367 ./prep_dataset/ILSVRC2012_val_00016619.bin 224 224 +16368 ./prep_dataset/ILSVRC2012_val_00031814.bin 224 224 +16369 ./prep_dataset/ILSVRC2012_val_00006188.bin 224 224 +16370 ./prep_dataset/ILSVRC2012_val_00032861.bin 224 224 +16371 ./prep_dataset/ILSVRC2012_val_00020931.bin 224 224 +16372 ./prep_dataset/ILSVRC2012_val_00009719.bin 224 224 +16373 ./prep_dataset/ILSVRC2012_val_00047638.bin 224 224 +16374 ./prep_dataset/ILSVRC2012_val_00000734.bin 224 224 +16375 ./prep_dataset/ILSVRC2012_val_00004908.bin 224 224 +16376 ./prep_dataset/ILSVRC2012_val_00038047.bin 224 224 +16377 ./prep_dataset/ILSVRC2012_val_00007671.bin 224 224 +16378 ./prep_dataset/ILSVRC2012_val_00020356.bin 224 224 +16379 ./prep_dataset/ILSVRC2012_val_00022574.bin 224 224 +16380 ./prep_dataset/ILSVRC2012_val_00010824.bin 224 224 +16381 ./prep_dataset/ILSVRC2012_val_00030377.bin 224 224 +16382 ./prep_dataset/ILSVRC2012_val_00022014.bin 224 224 +16383 ./prep_dataset/ILSVRC2012_val_00004765.bin 224 224 +16384 ./prep_dataset/ILSVRC2012_val_00049252.bin 224 224 +16385 ./prep_dataset/ILSVRC2012_val_00031885.bin 224 224 +16386 ./prep_dataset/ILSVRC2012_val_00021770.bin 224 224 +16387 ./prep_dataset/ILSVRC2012_val_00033197.bin 224 224 +16388 ./prep_dataset/ILSVRC2012_val_00040957.bin 224 224 +16389 ./prep_dataset/ILSVRC2012_val_00003281.bin 224 224 +16390 ./prep_dataset/ILSVRC2012_val_00039278.bin 224 224 +16391 ./prep_dataset/ILSVRC2012_val_00018811.bin 224 224 +16392 ./prep_dataset/ILSVRC2012_val_00037437.bin 224 224 +16393 ./prep_dataset/ILSVRC2012_val_00027315.bin 224 224 +16394 ./prep_dataset/ILSVRC2012_val_00023659.bin 224 224 +16395 ./prep_dataset/ILSVRC2012_val_00049423.bin 224 224 +16396 ./prep_dataset/ILSVRC2012_val_00018387.bin 224 224 +16397 ./prep_dataset/ILSVRC2012_val_00026432.bin 224 224 +16398 ./prep_dataset/ILSVRC2012_val_00030168.bin 224 224 +16399 ./prep_dataset/ILSVRC2012_val_00002371.bin 224 224 +16400 ./prep_dataset/ILSVRC2012_val_00042554.bin 224 224 +16401 ./prep_dataset/ILSVRC2012_val_00037612.bin 224 224 +16402 ./prep_dataset/ILSVRC2012_val_00021911.bin 224 224 +16403 ./prep_dataset/ILSVRC2012_val_00029858.bin 224 224 +16404 ./prep_dataset/ILSVRC2012_val_00015133.bin 224 224 +16405 ./prep_dataset/ILSVRC2012_val_00042350.bin 224 224 +16406 ./prep_dataset/ILSVRC2012_val_00017290.bin 224 224 +16407 ./prep_dataset/ILSVRC2012_val_00046186.bin 224 224 +16408 ./prep_dataset/ILSVRC2012_val_00004740.bin 224 224 +16409 ./prep_dataset/ILSVRC2012_val_00042256.bin 224 224 +16410 ./prep_dataset/ILSVRC2012_val_00005202.bin 224 224 +16411 ./prep_dataset/ILSVRC2012_val_00041551.bin 224 224 +16412 ./prep_dataset/ILSVRC2012_val_00008883.bin 224 224 +16413 ./prep_dataset/ILSVRC2012_val_00041684.bin 224 224 +16414 ./prep_dataset/ILSVRC2012_val_00043878.bin 224 224 +16415 ./prep_dataset/ILSVRC2012_val_00037603.bin 224 224 +16416 ./prep_dataset/ILSVRC2012_val_00033596.bin 224 224 +16417 ./prep_dataset/ILSVRC2012_val_00048782.bin 224 224 +16418 ./prep_dataset/ILSVRC2012_val_00045785.bin 224 224 +16419 ./prep_dataset/ILSVRC2012_val_00043302.bin 224 224 +16420 ./prep_dataset/ILSVRC2012_val_00048739.bin 224 224 +16421 ./prep_dataset/ILSVRC2012_val_00020151.bin 224 224 +16422 ./prep_dataset/ILSVRC2012_val_00002164.bin 224 224 +16423 ./prep_dataset/ILSVRC2012_val_00018581.bin 224 224 +16424 ./prep_dataset/ILSVRC2012_val_00035449.bin 224 224 +16425 ./prep_dataset/ILSVRC2012_val_00043857.bin 224 224 +16426 ./prep_dataset/ILSVRC2012_val_00016464.bin 224 224 +16427 ./prep_dataset/ILSVRC2012_val_00023340.bin 224 224 +16428 ./prep_dataset/ILSVRC2012_val_00025325.bin 224 224 +16429 ./prep_dataset/ILSVRC2012_val_00016155.bin 224 224 +16430 ./prep_dataset/ILSVRC2012_val_00004539.bin 224 224 +16431 ./prep_dataset/ILSVRC2012_val_00045539.bin 224 224 +16432 ./prep_dataset/ILSVRC2012_val_00044870.bin 224 224 +16433 ./prep_dataset/ILSVRC2012_val_00019943.bin 224 224 +16434 ./prep_dataset/ILSVRC2012_val_00037508.bin 224 224 +16435 ./prep_dataset/ILSVRC2012_val_00003359.bin 224 224 +16436 ./prep_dataset/ILSVRC2012_val_00049236.bin 224 224 +16437 ./prep_dataset/ILSVRC2012_val_00026902.bin 224 224 +16438 ./prep_dataset/ILSVRC2012_val_00019218.bin 224 224 +16439 ./prep_dataset/ILSVRC2012_val_00034681.bin 224 224 +16440 ./prep_dataset/ILSVRC2012_val_00028913.bin 224 224 +16441 ./prep_dataset/ILSVRC2012_val_00032156.bin 224 224 +16442 ./prep_dataset/ILSVRC2012_val_00006544.bin 224 224 +16443 ./prep_dataset/ILSVRC2012_val_00038690.bin 224 224 +16444 ./prep_dataset/ILSVRC2012_val_00040852.bin 224 224 +16445 ./prep_dataset/ILSVRC2012_val_00044382.bin 224 224 +16446 ./prep_dataset/ILSVRC2012_val_00033543.bin 224 224 +16447 ./prep_dataset/ILSVRC2012_val_00036768.bin 224 224 +16448 ./prep_dataset/ILSVRC2012_val_00033642.bin 224 224 +16449 ./prep_dataset/ILSVRC2012_val_00005293.bin 224 224 +16450 ./prep_dataset/ILSVRC2012_val_00024668.bin 224 224 +16451 ./prep_dataset/ILSVRC2012_val_00021256.bin 224 224 +16452 ./prep_dataset/ILSVRC2012_val_00044065.bin 224 224 +16453 ./prep_dataset/ILSVRC2012_val_00040130.bin 224 224 +16454 ./prep_dataset/ILSVRC2012_val_00035716.bin 224 224 +16455 ./prep_dataset/ILSVRC2012_val_00018121.bin 224 224 +16456 ./prep_dataset/ILSVRC2012_val_00018992.bin 224 224 +16457 ./prep_dataset/ILSVRC2012_val_00017834.bin 224 224 +16458 ./prep_dataset/ILSVRC2012_val_00006015.bin 224 224 +16459 ./prep_dataset/ILSVRC2012_val_00025686.bin 224 224 +16460 ./prep_dataset/ILSVRC2012_val_00020955.bin 224 224 +16461 ./prep_dataset/ILSVRC2012_val_00019676.bin 224 224 +16462 ./prep_dataset/ILSVRC2012_val_00011182.bin 224 224 +16463 ./prep_dataset/ILSVRC2012_val_00010278.bin 224 224 +16464 ./prep_dataset/ILSVRC2012_val_00040385.bin 224 224 +16465 ./prep_dataset/ILSVRC2012_val_00040193.bin 224 224 +16466 ./prep_dataset/ILSVRC2012_val_00001269.bin 224 224 +16467 ./prep_dataset/ILSVRC2012_val_00036061.bin 224 224 +16468 ./prep_dataset/ILSVRC2012_val_00026201.bin 224 224 +16469 ./prep_dataset/ILSVRC2012_val_00039126.bin 224 224 +16470 ./prep_dataset/ILSVRC2012_val_00007959.bin 224 224 +16471 ./prep_dataset/ILSVRC2012_val_00026407.bin 224 224 +16472 ./prep_dataset/ILSVRC2012_val_00017580.bin 224 224 +16473 ./prep_dataset/ILSVRC2012_val_00005815.bin 224 224 +16474 ./prep_dataset/ILSVRC2012_val_00041663.bin 224 224 +16475 ./prep_dataset/ILSVRC2012_val_00042259.bin 224 224 +16476 ./prep_dataset/ILSVRC2012_val_00032258.bin 224 224 +16477 ./prep_dataset/ILSVRC2012_val_00022607.bin 224 224 +16478 ./prep_dataset/ILSVRC2012_val_00032575.bin 224 224 +16479 ./prep_dataset/ILSVRC2012_val_00027145.bin 224 224 +16480 ./prep_dataset/ILSVRC2012_val_00000445.bin 224 224 +16481 ./prep_dataset/ILSVRC2012_val_00023578.bin 224 224 +16482 ./prep_dataset/ILSVRC2012_val_00021306.bin 224 224 +16483 ./prep_dataset/ILSVRC2012_val_00038941.bin 224 224 +16484 ./prep_dataset/ILSVRC2012_val_00012433.bin 224 224 +16485 ./prep_dataset/ILSVRC2012_val_00035747.bin 224 224 +16486 ./prep_dataset/ILSVRC2012_val_00016529.bin 224 224 +16487 ./prep_dataset/ILSVRC2012_val_00042400.bin 224 224 +16488 ./prep_dataset/ILSVRC2012_val_00013696.bin 224 224 +16489 ./prep_dataset/ILSVRC2012_val_00016607.bin 224 224 +16490 ./prep_dataset/ILSVRC2012_val_00030293.bin 224 224 +16491 ./prep_dataset/ILSVRC2012_val_00048197.bin 224 224 +16492 ./prep_dataset/ILSVRC2012_val_00016618.bin 224 224 +16493 ./prep_dataset/ILSVRC2012_val_00024206.bin 224 224 +16494 ./prep_dataset/ILSVRC2012_val_00036031.bin 224 224 +16495 ./prep_dataset/ILSVRC2012_val_00029195.bin 224 224 +16496 ./prep_dataset/ILSVRC2012_val_00024975.bin 224 224 +16497 ./prep_dataset/ILSVRC2012_val_00028530.bin 224 224 +16498 ./prep_dataset/ILSVRC2012_val_00000504.bin 224 224 +16499 ./prep_dataset/ILSVRC2012_val_00042397.bin 224 224 +16500 ./prep_dataset/ILSVRC2012_val_00025243.bin 224 224 +16501 ./prep_dataset/ILSVRC2012_val_00031047.bin 224 224 +16502 ./prep_dataset/ILSVRC2012_val_00036828.bin 224 224 +16503 ./prep_dataset/ILSVRC2012_val_00044817.bin 224 224 +16504 ./prep_dataset/ILSVRC2012_val_00025877.bin 224 224 +16505 ./prep_dataset/ILSVRC2012_val_00038790.bin 224 224 +16506 ./prep_dataset/ILSVRC2012_val_00048960.bin 224 224 +16507 ./prep_dataset/ILSVRC2012_val_00016290.bin 224 224 +16508 ./prep_dataset/ILSVRC2012_val_00022692.bin 224 224 +16509 ./prep_dataset/ILSVRC2012_val_00021060.bin 224 224 +16510 ./prep_dataset/ILSVRC2012_val_00026532.bin 224 224 +16511 ./prep_dataset/ILSVRC2012_val_00040555.bin 224 224 +16512 ./prep_dataset/ILSVRC2012_val_00007355.bin 224 224 +16513 ./prep_dataset/ILSVRC2012_val_00003525.bin 224 224 +16514 ./prep_dataset/ILSVRC2012_val_00046374.bin 224 224 +16515 ./prep_dataset/ILSVRC2012_val_00021869.bin 224 224 +16516 ./prep_dataset/ILSVRC2012_val_00021267.bin 224 224 +16517 ./prep_dataset/ILSVRC2012_val_00002685.bin 224 224 +16518 ./prep_dataset/ILSVRC2012_val_00030685.bin 224 224 +16519 ./prep_dataset/ILSVRC2012_val_00023213.bin 224 224 +16520 ./prep_dataset/ILSVRC2012_val_00046252.bin 224 224 +16521 ./prep_dataset/ILSVRC2012_val_00001129.bin 224 224 +16522 ./prep_dataset/ILSVRC2012_val_00012344.bin 224 224 +16523 ./prep_dataset/ILSVRC2012_val_00018886.bin 224 224 +16524 ./prep_dataset/ILSVRC2012_val_00037578.bin 224 224 +16525 ./prep_dataset/ILSVRC2012_val_00009081.bin 224 224 +16526 ./prep_dataset/ILSVRC2012_val_00042713.bin 224 224 +16527 ./prep_dataset/ILSVRC2012_val_00010831.bin 224 224 +16528 ./prep_dataset/ILSVRC2012_val_00035339.bin 224 224 +16529 ./prep_dataset/ILSVRC2012_val_00012256.bin 224 224 +16530 ./prep_dataset/ILSVRC2012_val_00040895.bin 224 224 +16531 ./prep_dataset/ILSVRC2012_val_00009946.bin 224 224 +16532 ./prep_dataset/ILSVRC2012_val_00026161.bin 224 224 +16533 ./prep_dataset/ILSVRC2012_val_00008269.bin 224 224 +16534 ./prep_dataset/ILSVRC2012_val_00014341.bin 224 224 +16535 ./prep_dataset/ILSVRC2012_val_00033167.bin 224 224 +16536 ./prep_dataset/ILSVRC2012_val_00009003.bin 224 224 +16537 ./prep_dataset/ILSVRC2012_val_00037321.bin 224 224 +16538 ./prep_dataset/ILSVRC2012_val_00013493.bin 224 224 +16539 ./prep_dataset/ILSVRC2012_val_00044108.bin 224 224 +16540 ./prep_dataset/ILSVRC2012_val_00029421.bin 224 224 +16541 ./prep_dataset/ILSVRC2012_val_00019331.bin 224 224 +16542 ./prep_dataset/ILSVRC2012_val_00000487.bin 224 224 +16543 ./prep_dataset/ILSVRC2012_val_00007776.bin 224 224 +16544 ./prep_dataset/ILSVRC2012_val_00046490.bin 224 224 +16545 ./prep_dataset/ILSVRC2012_val_00033770.bin 224 224 +16546 ./prep_dataset/ILSVRC2012_val_00035325.bin 224 224 +16547 ./prep_dataset/ILSVRC2012_val_00040647.bin 224 224 +16548 ./prep_dataset/ILSVRC2012_val_00023177.bin 224 224 +16549 ./prep_dataset/ILSVRC2012_val_00015085.bin 224 224 +16550 ./prep_dataset/ILSVRC2012_val_00009079.bin 224 224 +16551 ./prep_dataset/ILSVRC2012_val_00028013.bin 224 224 +16552 ./prep_dataset/ILSVRC2012_val_00026561.bin 224 224 +16553 ./prep_dataset/ILSVRC2012_val_00045689.bin 224 224 +16554 ./prep_dataset/ILSVRC2012_val_00040665.bin 224 224 +16555 ./prep_dataset/ILSVRC2012_val_00008458.bin 224 224 +16556 ./prep_dataset/ILSVRC2012_val_00021493.bin 224 224 +16557 ./prep_dataset/ILSVRC2012_val_00046743.bin 224 224 +16558 ./prep_dataset/ILSVRC2012_val_00026177.bin 224 224 +16559 ./prep_dataset/ILSVRC2012_val_00016544.bin 224 224 +16560 ./prep_dataset/ILSVRC2012_val_00039354.bin 224 224 +16561 ./prep_dataset/ILSVRC2012_val_00012743.bin 224 224 +16562 ./prep_dataset/ILSVRC2012_val_00045747.bin 224 224 +16563 ./prep_dataset/ILSVRC2012_val_00027557.bin 224 224 +16564 ./prep_dataset/ILSVRC2012_val_00011950.bin 224 224 +16565 ./prep_dataset/ILSVRC2012_val_00018366.bin 224 224 +16566 ./prep_dataset/ILSVRC2012_val_00002708.bin 224 224 +16567 ./prep_dataset/ILSVRC2012_val_00010864.bin 224 224 +16568 ./prep_dataset/ILSVRC2012_val_00009304.bin 224 224 +16569 ./prep_dataset/ILSVRC2012_val_00049373.bin 224 224 +16570 ./prep_dataset/ILSVRC2012_val_00003442.bin 224 224 +16571 ./prep_dataset/ILSVRC2012_val_00015851.bin 224 224 +16572 ./prep_dataset/ILSVRC2012_val_00002346.bin 224 224 +16573 ./prep_dataset/ILSVRC2012_val_00042159.bin 224 224 +16574 ./prep_dataset/ILSVRC2012_val_00039124.bin 224 224 +16575 ./prep_dataset/ILSVRC2012_val_00026112.bin 224 224 +16576 ./prep_dataset/ILSVRC2012_val_00034387.bin 224 224 +16577 ./prep_dataset/ILSVRC2012_val_00026849.bin 224 224 +16578 ./prep_dataset/ILSVRC2012_val_00023674.bin 224 224 +16579 ./prep_dataset/ILSVRC2012_val_00027455.bin 224 224 +16580 ./prep_dataset/ILSVRC2012_val_00036540.bin 224 224 +16581 ./prep_dataset/ILSVRC2012_val_00010899.bin 224 224 +16582 ./prep_dataset/ILSVRC2012_val_00011531.bin 224 224 +16583 ./prep_dataset/ILSVRC2012_val_00033520.bin 224 224 +16584 ./prep_dataset/ILSVRC2012_val_00007008.bin 224 224 +16585 ./prep_dataset/ILSVRC2012_val_00044296.bin 224 224 +16586 ./prep_dataset/ILSVRC2012_val_00030674.bin 224 224 +16587 ./prep_dataset/ILSVRC2012_val_00000018.bin 224 224 +16588 ./prep_dataset/ILSVRC2012_val_00006236.bin 224 224 +16589 ./prep_dataset/ILSVRC2012_val_00020751.bin 224 224 +16590 ./prep_dataset/ILSVRC2012_val_00015280.bin 224 224 +16591 ./prep_dataset/ILSVRC2012_val_00039262.bin 224 224 +16592 ./prep_dataset/ILSVRC2012_val_00036338.bin 224 224 +16593 ./prep_dataset/ILSVRC2012_val_00020936.bin 224 224 +16594 ./prep_dataset/ILSVRC2012_val_00007578.bin 224 224 +16595 ./prep_dataset/ILSVRC2012_val_00019662.bin 224 224 +16596 ./prep_dataset/ILSVRC2012_val_00031270.bin 224 224 +16597 ./prep_dataset/ILSVRC2012_val_00041321.bin 224 224 +16598 ./prep_dataset/ILSVRC2012_val_00006955.bin 224 224 +16599 ./prep_dataset/ILSVRC2012_val_00006386.bin 224 224 +16600 ./prep_dataset/ILSVRC2012_val_00003213.bin 224 224 +16601 ./prep_dataset/ILSVRC2012_val_00046150.bin 224 224 +16602 ./prep_dataset/ILSVRC2012_val_00032203.bin 224 224 +16603 ./prep_dataset/ILSVRC2012_val_00032602.bin 224 224 +16604 ./prep_dataset/ILSVRC2012_val_00008356.bin 224 224 +16605 ./prep_dataset/ILSVRC2012_val_00024830.bin 224 224 +16606 ./prep_dataset/ILSVRC2012_val_00033042.bin 224 224 +16607 ./prep_dataset/ILSVRC2012_val_00027486.bin 224 224 +16608 ./prep_dataset/ILSVRC2012_val_00007011.bin 224 224 +16609 ./prep_dataset/ILSVRC2012_val_00018123.bin 224 224 +16610 ./prep_dataset/ILSVRC2012_val_00002963.bin 224 224 +16611 ./prep_dataset/ILSVRC2012_val_00008854.bin 224 224 +16612 ./prep_dataset/ILSVRC2012_val_00026899.bin 224 224 +16613 ./prep_dataset/ILSVRC2012_val_00015771.bin 224 224 +16614 ./prep_dataset/ILSVRC2012_val_00046675.bin 224 224 +16615 ./prep_dataset/ILSVRC2012_val_00023359.bin 224 224 +16616 ./prep_dataset/ILSVRC2012_val_00043718.bin 224 224 +16617 ./prep_dataset/ILSVRC2012_val_00030563.bin 224 224 +16618 ./prep_dataset/ILSVRC2012_val_00022034.bin 224 224 +16619 ./prep_dataset/ILSVRC2012_val_00045567.bin 224 224 +16620 ./prep_dataset/ILSVRC2012_val_00003582.bin 224 224 +16621 ./prep_dataset/ILSVRC2012_val_00005536.bin 224 224 +16622 ./prep_dataset/ILSVRC2012_val_00016161.bin 224 224 +16623 ./prep_dataset/ILSVRC2012_val_00008047.bin 224 224 +16624 ./prep_dataset/ILSVRC2012_val_00000176.bin 224 224 +16625 ./prep_dataset/ILSVRC2012_val_00022024.bin 224 224 +16626 ./prep_dataset/ILSVRC2012_val_00024594.bin 224 224 +16627 ./prep_dataset/ILSVRC2012_val_00023564.bin 224 224 +16628 ./prep_dataset/ILSVRC2012_val_00029644.bin 224 224 +16629 ./prep_dataset/ILSVRC2012_val_00026200.bin 224 224 +16630 ./prep_dataset/ILSVRC2012_val_00046305.bin 224 224 +16631 ./prep_dataset/ILSVRC2012_val_00021057.bin 224 224 +16632 ./prep_dataset/ILSVRC2012_val_00026431.bin 224 224 +16633 ./prep_dataset/ILSVRC2012_val_00042600.bin 224 224 +16634 ./prep_dataset/ILSVRC2012_val_00044367.bin 224 224 +16635 ./prep_dataset/ILSVRC2012_val_00029848.bin 224 224 +16636 ./prep_dataset/ILSVRC2012_val_00015484.bin 224 224 +16637 ./prep_dataset/ILSVRC2012_val_00010596.bin 224 224 +16638 ./prep_dataset/ILSVRC2012_val_00026252.bin 224 224 +16639 ./prep_dataset/ILSVRC2012_val_00039128.bin 224 224 +16640 ./prep_dataset/ILSVRC2012_val_00016882.bin 224 224 +16641 ./prep_dataset/ILSVRC2012_val_00013274.bin 224 224 +16642 ./prep_dataset/ILSVRC2012_val_00031883.bin 224 224 +16643 ./prep_dataset/ILSVRC2012_val_00030181.bin 224 224 +16644 ./prep_dataset/ILSVRC2012_val_00042976.bin 224 224 +16645 ./prep_dataset/ILSVRC2012_val_00000341.bin 224 224 +16646 ./prep_dataset/ILSVRC2012_val_00017049.bin 224 224 +16647 ./prep_dataset/ILSVRC2012_val_00028228.bin 224 224 +16648 ./prep_dataset/ILSVRC2012_val_00041051.bin 224 224 +16649 ./prep_dataset/ILSVRC2012_val_00025539.bin 224 224 +16650 ./prep_dataset/ILSVRC2012_val_00003952.bin 224 224 +16651 ./prep_dataset/ILSVRC2012_val_00031695.bin 224 224 +16652 ./prep_dataset/ILSVRC2012_val_00020100.bin 224 224 +16653 ./prep_dataset/ILSVRC2012_val_00012609.bin 224 224 +16654 ./prep_dataset/ILSVRC2012_val_00028086.bin 224 224 +16655 ./prep_dataset/ILSVRC2012_val_00001093.bin 224 224 +16656 ./prep_dataset/ILSVRC2012_val_00041747.bin 224 224 +16657 ./prep_dataset/ILSVRC2012_val_00018472.bin 224 224 +16658 ./prep_dataset/ILSVRC2012_val_00019545.bin 224 224 +16659 ./prep_dataset/ILSVRC2012_val_00024535.bin 224 224 +16660 ./prep_dataset/ILSVRC2012_val_00014485.bin 224 224 +16661 ./prep_dataset/ILSVRC2012_val_00018440.bin 224 224 +16662 ./prep_dataset/ILSVRC2012_val_00038098.bin 224 224 +16663 ./prep_dataset/ILSVRC2012_val_00042829.bin 224 224 +16664 ./prep_dataset/ILSVRC2012_val_00000484.bin 224 224 +16665 ./prep_dataset/ILSVRC2012_val_00048833.bin 224 224 +16666 ./prep_dataset/ILSVRC2012_val_00029788.bin 224 224 +16667 ./prep_dataset/ILSVRC2012_val_00015511.bin 224 224 +16668 ./prep_dataset/ILSVRC2012_val_00036432.bin 224 224 +16669 ./prep_dataset/ILSVRC2012_val_00008218.bin 224 224 +16670 ./prep_dataset/ILSVRC2012_val_00004542.bin 224 224 +16671 ./prep_dataset/ILSVRC2012_val_00038096.bin 224 224 +16672 ./prep_dataset/ILSVRC2012_val_00045445.bin 224 224 +16673 ./prep_dataset/ILSVRC2012_val_00027438.bin 224 224 +16674 ./prep_dataset/ILSVRC2012_val_00042106.bin 224 224 +16675 ./prep_dataset/ILSVRC2012_val_00042643.bin 224 224 +16676 ./prep_dataset/ILSVRC2012_val_00027277.bin 224 224 +16677 ./prep_dataset/ILSVRC2012_val_00018409.bin 224 224 +16678 ./prep_dataset/ILSVRC2012_val_00029154.bin 224 224 +16679 ./prep_dataset/ILSVRC2012_val_00002087.bin 224 224 +16680 ./prep_dataset/ILSVRC2012_val_00014205.bin 224 224 +16681 ./prep_dataset/ILSVRC2012_val_00042206.bin 224 224 +16682 ./prep_dataset/ILSVRC2012_val_00004065.bin 224 224 +16683 ./prep_dataset/ILSVRC2012_val_00048873.bin 224 224 +16684 ./prep_dataset/ILSVRC2012_val_00035437.bin 224 224 +16685 ./prep_dataset/ILSVRC2012_val_00035503.bin 224 224 +16686 ./prep_dataset/ILSVRC2012_val_00003028.bin 224 224 +16687 ./prep_dataset/ILSVRC2012_val_00025905.bin 224 224 +16688 ./prep_dataset/ILSVRC2012_val_00010751.bin 224 224 +16689 ./prep_dataset/ILSVRC2012_val_00033071.bin 224 224 +16690 ./prep_dataset/ILSVRC2012_val_00041260.bin 224 224 +16691 ./prep_dataset/ILSVRC2012_val_00002051.bin 224 224 +16692 ./prep_dataset/ILSVRC2012_val_00019949.bin 224 224 +16693 ./prep_dataset/ILSVRC2012_val_00012484.bin 224 224 +16694 ./prep_dataset/ILSVRC2012_val_00017379.bin 224 224 +16695 ./prep_dataset/ILSVRC2012_val_00034618.bin 224 224 +16696 ./prep_dataset/ILSVRC2012_val_00031035.bin 224 224 +16697 ./prep_dataset/ILSVRC2012_val_00027541.bin 224 224 +16698 ./prep_dataset/ILSVRC2012_val_00032754.bin 224 224 +16699 ./prep_dataset/ILSVRC2012_val_00008387.bin 224 224 +16700 ./prep_dataset/ILSVRC2012_val_00024334.bin 224 224 +16701 ./prep_dataset/ILSVRC2012_val_00026997.bin 224 224 +16702 ./prep_dataset/ILSVRC2012_val_00027669.bin 224 224 +16703 ./prep_dataset/ILSVRC2012_val_00043024.bin 224 224 +16704 ./prep_dataset/ILSVRC2012_val_00017723.bin 224 224 +16705 ./prep_dataset/ILSVRC2012_val_00015738.bin 224 224 +16706 ./prep_dataset/ILSVRC2012_val_00007966.bin 224 224 +16707 ./prep_dataset/ILSVRC2012_val_00048477.bin 224 224 +16708 ./prep_dataset/ILSVRC2012_val_00014441.bin 224 224 +16709 ./prep_dataset/ILSVRC2012_val_00031564.bin 224 224 +16710 ./prep_dataset/ILSVRC2012_val_00007036.bin 224 224 +16711 ./prep_dataset/ILSVRC2012_val_00036522.bin 224 224 +16712 ./prep_dataset/ILSVRC2012_val_00028173.bin 224 224 +16713 ./prep_dataset/ILSVRC2012_val_00042640.bin 224 224 +16714 ./prep_dataset/ILSVRC2012_val_00019962.bin 224 224 +16715 ./prep_dataset/ILSVRC2012_val_00021941.bin 224 224 +16716 ./prep_dataset/ILSVRC2012_val_00042429.bin 224 224 +16717 ./prep_dataset/ILSVRC2012_val_00000683.bin 224 224 +16718 ./prep_dataset/ILSVRC2012_val_00040047.bin 224 224 +16719 ./prep_dataset/ILSVRC2012_val_00020868.bin 224 224 +16720 ./prep_dataset/ILSVRC2012_val_00015035.bin 224 224 +16721 ./prep_dataset/ILSVRC2012_val_00049438.bin 224 224 +16722 ./prep_dataset/ILSVRC2012_val_00003959.bin 224 224 +16723 ./prep_dataset/ILSVRC2012_val_00000180.bin 224 224 +16724 ./prep_dataset/ILSVRC2012_val_00032070.bin 224 224 +16725 ./prep_dataset/ILSVRC2012_val_00037952.bin 224 224 +16726 ./prep_dataset/ILSVRC2012_val_00041723.bin 224 224 +16727 ./prep_dataset/ILSVRC2012_val_00030561.bin 224 224 +16728 ./prep_dataset/ILSVRC2012_val_00020364.bin 224 224 +16729 ./prep_dataset/ILSVRC2012_val_00023560.bin 224 224 +16730 ./prep_dataset/ILSVRC2012_val_00005364.bin 224 224 +16731 ./prep_dataset/ILSVRC2012_val_00026370.bin 224 224 +16732 ./prep_dataset/ILSVRC2012_val_00045371.bin 224 224 +16733 ./prep_dataset/ILSVRC2012_val_00010368.bin 224 224 +16734 ./prep_dataset/ILSVRC2012_val_00037936.bin 224 224 +16735 ./prep_dataset/ILSVRC2012_val_00042627.bin 224 224 +16736 ./prep_dataset/ILSVRC2012_val_00042594.bin 224 224 +16737 ./prep_dataset/ILSVRC2012_val_00002503.bin 224 224 +16738 ./prep_dataset/ILSVRC2012_val_00027578.bin 224 224 +16739 ./prep_dataset/ILSVRC2012_val_00004090.bin 224 224 +16740 ./prep_dataset/ILSVRC2012_val_00002511.bin 224 224 +16741 ./prep_dataset/ILSVRC2012_val_00019695.bin 224 224 +16742 ./prep_dataset/ILSVRC2012_val_00024074.bin 224 224 +16743 ./prep_dataset/ILSVRC2012_val_00046747.bin 224 224 +16744 ./prep_dataset/ILSVRC2012_val_00031413.bin 224 224 +16745 ./prep_dataset/ILSVRC2012_val_00016260.bin 224 224 +16746 ./prep_dataset/ILSVRC2012_val_00014118.bin 224 224 +16747 ./prep_dataset/ILSVRC2012_val_00013693.bin 224 224 +16748 ./prep_dataset/ILSVRC2012_val_00020222.bin 224 224 +16749 ./prep_dataset/ILSVRC2012_val_00026986.bin 224 224 +16750 ./prep_dataset/ILSVRC2012_val_00037844.bin 224 224 +16751 ./prep_dataset/ILSVRC2012_val_00014053.bin 224 224 +16752 ./prep_dataset/ILSVRC2012_val_00025346.bin 224 224 +16753 ./prep_dataset/ILSVRC2012_val_00008767.bin 224 224 +16754 ./prep_dataset/ILSVRC2012_val_00023839.bin 224 224 +16755 ./prep_dataset/ILSVRC2012_val_00022534.bin 224 224 +16756 ./prep_dataset/ILSVRC2012_val_00012388.bin 224 224 +16757 ./prep_dataset/ILSVRC2012_val_00028907.bin 224 224 +16758 ./prep_dataset/ILSVRC2012_val_00028211.bin 224 224 +16759 ./prep_dataset/ILSVRC2012_val_00020797.bin 224 224 +16760 ./prep_dataset/ILSVRC2012_val_00001758.bin 224 224 +16761 ./prep_dataset/ILSVRC2012_val_00042763.bin 224 224 +16762 ./prep_dataset/ILSVRC2012_val_00019629.bin 224 224 +16763 ./prep_dataset/ILSVRC2012_val_00037538.bin 224 224 +16764 ./prep_dataset/ILSVRC2012_val_00032730.bin 224 224 +16765 ./prep_dataset/ILSVRC2012_val_00032131.bin 224 224 +16766 ./prep_dataset/ILSVRC2012_val_00042383.bin 224 224 +16767 ./prep_dataset/ILSVRC2012_val_00011473.bin 224 224 +16768 ./prep_dataset/ILSVRC2012_val_00007244.bin 224 224 +16769 ./prep_dataset/ILSVRC2012_val_00010896.bin 224 224 +16770 ./prep_dataset/ILSVRC2012_val_00045719.bin 224 224 +16771 ./prep_dataset/ILSVRC2012_val_00026553.bin 224 224 +16772 ./prep_dataset/ILSVRC2012_val_00006467.bin 224 224 +16773 ./prep_dataset/ILSVRC2012_val_00009437.bin 224 224 +16774 ./prep_dataset/ILSVRC2012_val_00047200.bin 224 224 +16775 ./prep_dataset/ILSVRC2012_val_00040299.bin 224 224 +16776 ./prep_dataset/ILSVRC2012_val_00009987.bin 224 224 +16777 ./prep_dataset/ILSVRC2012_val_00008140.bin 224 224 +16778 ./prep_dataset/ILSVRC2012_val_00010808.bin 224 224 +16779 ./prep_dataset/ILSVRC2012_val_00026484.bin 224 224 +16780 ./prep_dataset/ILSVRC2012_val_00030351.bin 224 224 +16781 ./prep_dataset/ILSVRC2012_val_00027743.bin 224 224 +16782 ./prep_dataset/ILSVRC2012_val_00014987.bin 224 224 +16783 ./prep_dataset/ILSVRC2012_val_00003167.bin 224 224 +16784 ./prep_dataset/ILSVRC2012_val_00039347.bin 224 224 +16785 ./prep_dataset/ILSVRC2012_val_00017583.bin 224 224 +16786 ./prep_dataset/ILSVRC2012_val_00022788.bin 224 224 +16787 ./prep_dataset/ILSVRC2012_val_00040552.bin 224 224 +16788 ./prep_dataset/ILSVRC2012_val_00047502.bin 224 224 +16789 ./prep_dataset/ILSVRC2012_val_00040184.bin 224 224 +16790 ./prep_dataset/ILSVRC2012_val_00024197.bin 224 224 +16791 ./prep_dataset/ILSVRC2012_val_00007699.bin 224 224 +16792 ./prep_dataset/ILSVRC2012_val_00006614.bin 224 224 +16793 ./prep_dataset/ILSVRC2012_val_00023467.bin 224 224 +16794 ./prep_dataset/ILSVRC2012_val_00017431.bin 224 224 +16795 ./prep_dataset/ILSVRC2012_val_00034996.bin 224 224 +16796 ./prep_dataset/ILSVRC2012_val_00019505.bin 224 224 +16797 ./prep_dataset/ILSVRC2012_val_00044741.bin 224 224 +16798 ./prep_dataset/ILSVRC2012_val_00014495.bin 224 224 +16799 ./prep_dataset/ILSVRC2012_val_00039804.bin 224 224 +16800 ./prep_dataset/ILSVRC2012_val_00022083.bin 224 224 +16801 ./prep_dataset/ILSVRC2012_val_00044983.bin 224 224 +16802 ./prep_dataset/ILSVRC2012_val_00011543.bin 224 224 +16803 ./prep_dataset/ILSVRC2012_val_00000065.bin 224 224 +16804 ./prep_dataset/ILSVRC2012_val_00048969.bin 224 224 +16805 ./prep_dataset/ILSVRC2012_val_00048240.bin 224 224 +16806 ./prep_dataset/ILSVRC2012_val_00003801.bin 224 224 +16807 ./prep_dataset/ILSVRC2012_val_00034973.bin 224 224 +16808 ./prep_dataset/ILSVRC2012_val_00024012.bin 224 224 +16809 ./prep_dataset/ILSVRC2012_val_00010116.bin 224 224 +16810 ./prep_dataset/ILSVRC2012_val_00005829.bin 224 224 +16811 ./prep_dataset/ILSVRC2012_val_00040701.bin 224 224 +16812 ./prep_dataset/ILSVRC2012_val_00041448.bin 224 224 +16813 ./prep_dataset/ILSVRC2012_val_00002132.bin 224 224 +16814 ./prep_dataset/ILSVRC2012_val_00047486.bin 224 224 +16815 ./prep_dataset/ILSVRC2012_val_00001557.bin 224 224 +16816 ./prep_dataset/ILSVRC2012_val_00016552.bin 224 224 +16817 ./prep_dataset/ILSVRC2012_val_00016510.bin 224 224 +16818 ./prep_dataset/ILSVRC2012_val_00020645.bin 224 224 +16819 ./prep_dataset/ILSVRC2012_val_00036775.bin 224 224 +16820 ./prep_dataset/ILSVRC2012_val_00004590.bin 224 224 +16821 ./prep_dataset/ILSVRC2012_val_00009765.bin 224 224 +16822 ./prep_dataset/ILSVRC2012_val_00000979.bin 224 224 +16823 ./prep_dataset/ILSVRC2012_val_00002576.bin 224 224 +16824 ./prep_dataset/ILSVRC2012_val_00043106.bin 224 224 +16825 ./prep_dataset/ILSVRC2012_val_00039748.bin 224 224 +16826 ./prep_dataset/ILSVRC2012_val_00003794.bin 224 224 +16827 ./prep_dataset/ILSVRC2012_val_00017360.bin 224 224 +16828 ./prep_dataset/ILSVRC2012_val_00020735.bin 224 224 +16829 ./prep_dataset/ILSVRC2012_val_00014919.bin 224 224 +16830 ./prep_dataset/ILSVRC2012_val_00022381.bin 224 224 +16831 ./prep_dataset/ILSVRC2012_val_00019539.bin 224 224 +16832 ./prep_dataset/ILSVRC2012_val_00011394.bin 224 224 +16833 ./prep_dataset/ILSVRC2012_val_00025701.bin 224 224 +16834 ./prep_dataset/ILSVRC2012_val_00034148.bin 224 224 +16835 ./prep_dataset/ILSVRC2012_val_00008697.bin 224 224 +16836 ./prep_dataset/ILSVRC2012_val_00043532.bin 224 224 +16837 ./prep_dataset/ILSVRC2012_val_00032937.bin 224 224 +16838 ./prep_dataset/ILSVRC2012_val_00018488.bin 224 224 +16839 ./prep_dataset/ILSVRC2012_val_00037986.bin 224 224 +16840 ./prep_dataset/ILSVRC2012_val_00006196.bin 224 224 +16841 ./prep_dataset/ILSVRC2012_val_00049945.bin 224 224 +16842 ./prep_dataset/ILSVRC2012_val_00046368.bin 224 224 +16843 ./prep_dataset/ILSVRC2012_val_00039527.bin 224 224 +16844 ./prep_dataset/ILSVRC2012_val_00035583.bin 224 224 +16845 ./prep_dataset/ILSVRC2012_val_00027601.bin 224 224 +16846 ./prep_dataset/ILSVRC2012_val_00010508.bin 224 224 +16847 ./prep_dataset/ILSVRC2012_val_00014803.bin 224 224 +16848 ./prep_dataset/ILSVRC2012_val_00048086.bin 224 224 +16849 ./prep_dataset/ILSVRC2012_val_00030413.bin 224 224 +16850 ./prep_dataset/ILSVRC2012_val_00002747.bin 224 224 +16851 ./prep_dataset/ILSVRC2012_val_00008871.bin 224 224 +16852 ./prep_dataset/ILSVRC2012_val_00005639.bin 224 224 +16853 ./prep_dataset/ILSVRC2012_val_00043342.bin 224 224 +16854 ./prep_dataset/ILSVRC2012_val_00038723.bin 224 224 +16855 ./prep_dataset/ILSVRC2012_val_00002135.bin 224 224 +16856 ./prep_dataset/ILSVRC2012_val_00027103.bin 224 224 +16857 ./prep_dataset/ILSVRC2012_val_00002117.bin 224 224 +16858 ./prep_dataset/ILSVRC2012_val_00049727.bin 224 224 +16859 ./prep_dataset/ILSVRC2012_val_00016767.bin 224 224 +16860 ./prep_dataset/ILSVRC2012_val_00028729.bin 224 224 +16861 ./prep_dataset/ILSVRC2012_val_00032969.bin 224 224 +16862 ./prep_dataset/ILSVRC2012_val_00010306.bin 224 224 +16863 ./prep_dataset/ILSVRC2012_val_00030961.bin 224 224 +16864 ./prep_dataset/ILSVRC2012_val_00040890.bin 224 224 +16865 ./prep_dataset/ILSVRC2012_val_00010532.bin 224 224 +16866 ./prep_dataset/ILSVRC2012_val_00030983.bin 224 224 +16867 ./prep_dataset/ILSVRC2012_val_00035080.bin 224 224 +16868 ./prep_dataset/ILSVRC2012_val_00026947.bin 224 224 +16869 ./prep_dataset/ILSVRC2012_val_00035060.bin 224 224 +16870 ./prep_dataset/ILSVRC2012_val_00026258.bin 224 224 +16871 ./prep_dataset/ILSVRC2012_val_00006306.bin 224 224 +16872 ./prep_dataset/ILSVRC2012_val_00022855.bin 224 224 +16873 ./prep_dataset/ILSVRC2012_val_00000694.bin 224 224 +16874 ./prep_dataset/ILSVRC2012_val_00038494.bin 224 224 +16875 ./prep_dataset/ILSVRC2012_val_00034593.bin 224 224 +16876 ./prep_dataset/ILSVRC2012_val_00038760.bin 224 224 +16877 ./prep_dataset/ILSVRC2012_val_00035983.bin 224 224 +16878 ./prep_dataset/ILSVRC2012_val_00019742.bin 224 224 +16879 ./prep_dataset/ILSVRC2012_val_00025329.bin 224 224 +16880 ./prep_dataset/ILSVRC2012_val_00049899.bin 224 224 +16881 ./prep_dataset/ILSVRC2012_val_00011141.bin 224 224 +16882 ./prep_dataset/ILSVRC2012_val_00002400.bin 224 224 +16883 ./prep_dataset/ILSVRC2012_val_00013677.bin 224 224 +16884 ./prep_dataset/ILSVRC2012_val_00019192.bin 224 224 +16885 ./prep_dataset/ILSVRC2012_val_00042542.bin 224 224 +16886 ./prep_dataset/ILSVRC2012_val_00046995.bin 224 224 +16887 ./prep_dataset/ILSVRC2012_val_00022005.bin 224 224 +16888 ./prep_dataset/ILSVRC2012_val_00018620.bin 224 224 +16889 ./prep_dataset/ILSVRC2012_val_00036920.bin 224 224 +16890 ./prep_dataset/ILSVRC2012_val_00032345.bin 224 224 +16891 ./prep_dataset/ILSVRC2012_val_00015406.bin 224 224 +16892 ./prep_dataset/ILSVRC2012_val_00025782.bin 224 224 +16893 ./prep_dataset/ILSVRC2012_val_00014456.bin 224 224 +16894 ./prep_dataset/ILSVRC2012_val_00015921.bin 224 224 +16895 ./prep_dataset/ILSVRC2012_val_00021118.bin 224 224 +16896 ./prep_dataset/ILSVRC2012_val_00009580.bin 224 224 +16897 ./prep_dataset/ILSVRC2012_val_00001324.bin 224 224 +16898 ./prep_dataset/ILSVRC2012_val_00045533.bin 224 224 +16899 ./prep_dataset/ILSVRC2012_val_00038725.bin 224 224 +16900 ./prep_dataset/ILSVRC2012_val_00001789.bin 224 224 +16901 ./prep_dataset/ILSVRC2012_val_00006823.bin 224 224 +16902 ./prep_dataset/ILSVRC2012_val_00035604.bin 224 224 +16903 ./prep_dataset/ILSVRC2012_val_00004262.bin 224 224 +16904 ./prep_dataset/ILSVRC2012_val_00035219.bin 224 224 +16905 ./prep_dataset/ILSVRC2012_val_00033065.bin 224 224 +16906 ./prep_dataset/ILSVRC2012_val_00017600.bin 224 224 +16907 ./prep_dataset/ILSVRC2012_val_00045101.bin 224 224 +16908 ./prep_dataset/ILSVRC2012_val_00016784.bin 224 224 +16909 ./prep_dataset/ILSVRC2012_val_00001387.bin 224 224 +16910 ./prep_dataset/ILSVRC2012_val_00032491.bin 224 224 +16911 ./prep_dataset/ILSVRC2012_val_00017096.bin 224 224 +16912 ./prep_dataset/ILSVRC2012_val_00005943.bin 224 224 +16913 ./prep_dataset/ILSVRC2012_val_00032418.bin 224 224 +16914 ./prep_dataset/ILSVRC2012_val_00039943.bin 224 224 +16915 ./prep_dataset/ILSVRC2012_val_00005121.bin 224 224 +16916 ./prep_dataset/ILSVRC2012_val_00038951.bin 224 224 +16917 ./prep_dataset/ILSVRC2012_val_00020548.bin 224 224 +16918 ./prep_dataset/ILSVRC2012_val_00049571.bin 224 224 +16919 ./prep_dataset/ILSVRC2012_val_00042367.bin 224 224 +16920 ./prep_dataset/ILSVRC2012_val_00009204.bin 224 224 +16921 ./prep_dataset/ILSVRC2012_val_00024020.bin 224 224 +16922 ./prep_dataset/ILSVRC2012_val_00042531.bin 224 224 +16923 ./prep_dataset/ILSVRC2012_val_00036569.bin 224 224 +16924 ./prep_dataset/ILSVRC2012_val_00006882.bin 224 224 +16925 ./prep_dataset/ILSVRC2012_val_00026062.bin 224 224 +16926 ./prep_dataset/ILSVRC2012_val_00010202.bin 224 224 +16927 ./prep_dataset/ILSVRC2012_val_00017225.bin 224 224 +16928 ./prep_dataset/ILSVRC2012_val_00046805.bin 224 224 +16929 ./prep_dataset/ILSVRC2012_val_00010287.bin 224 224 +16930 ./prep_dataset/ILSVRC2012_val_00009842.bin 224 224 +16931 ./prep_dataset/ILSVRC2012_val_00020928.bin 224 224 +16932 ./prep_dataset/ILSVRC2012_val_00000458.bin 224 224 +16933 ./prep_dataset/ILSVRC2012_val_00002770.bin 224 224 +16934 ./prep_dataset/ILSVRC2012_val_00025956.bin 224 224 +16935 ./prep_dataset/ILSVRC2012_val_00015963.bin 224 224 +16936 ./prep_dataset/ILSVRC2012_val_00037742.bin 224 224 +16937 ./prep_dataset/ILSVRC2012_val_00024415.bin 224 224 +16938 ./prep_dataset/ILSVRC2012_val_00016514.bin 224 224 +16939 ./prep_dataset/ILSVRC2012_val_00045690.bin 224 224 +16940 ./prep_dataset/ILSVRC2012_val_00042094.bin 224 224 +16941 ./prep_dataset/ILSVRC2012_val_00018361.bin 224 224 +16942 ./prep_dataset/ILSVRC2012_val_00023258.bin 224 224 +16943 ./prep_dataset/ILSVRC2012_val_00025761.bin 224 224 +16944 ./prep_dataset/ILSVRC2012_val_00027205.bin 224 224 +16945 ./prep_dataset/ILSVRC2012_val_00038542.bin 224 224 +16946 ./prep_dataset/ILSVRC2012_val_00013536.bin 224 224 +16947 ./prep_dataset/ILSVRC2012_val_00044899.bin 224 224 +16948 ./prep_dataset/ILSVRC2012_val_00027981.bin 224 224 +16949 ./prep_dataset/ILSVRC2012_val_00028744.bin 224 224 +16950 ./prep_dataset/ILSVRC2012_val_00000205.bin 224 224 +16951 ./prep_dataset/ILSVRC2012_val_00025119.bin 224 224 +16952 ./prep_dataset/ILSVRC2012_val_00034042.bin 224 224 +16953 ./prep_dataset/ILSVRC2012_val_00001539.bin 224 224 +16954 ./prep_dataset/ILSVRC2012_val_00021253.bin 224 224 +16955 ./prep_dataset/ILSVRC2012_val_00018133.bin 224 224 +16956 ./prep_dataset/ILSVRC2012_val_00013912.bin 224 224 +16957 ./prep_dataset/ILSVRC2012_val_00011123.bin 224 224 +16958 ./prep_dataset/ILSVRC2012_val_00046276.bin 224 224 +16959 ./prep_dataset/ILSVRC2012_val_00046060.bin 224 224 +16960 ./prep_dataset/ILSVRC2012_val_00027014.bin 224 224 +16961 ./prep_dataset/ILSVRC2012_val_00031406.bin 224 224 +16962 ./prep_dataset/ILSVRC2012_val_00017073.bin 224 224 +16963 ./prep_dataset/ILSVRC2012_val_00018588.bin 224 224 +16964 ./prep_dataset/ILSVRC2012_val_00033395.bin 224 224 +16965 ./prep_dataset/ILSVRC2012_val_00013718.bin 224 224 +16966 ./prep_dataset/ILSVRC2012_val_00002358.bin 224 224 +16967 ./prep_dataset/ILSVRC2012_val_00006444.bin 224 224 +16968 ./prep_dataset/ILSVRC2012_val_00002182.bin 224 224 +16969 ./prep_dataset/ILSVRC2012_val_00000793.bin 224 224 +16970 ./prep_dataset/ILSVRC2012_val_00003264.bin 224 224 +16971 ./prep_dataset/ILSVRC2012_val_00025732.bin 224 224 +16972 ./prep_dataset/ILSVRC2012_val_00025150.bin 224 224 +16973 ./prep_dataset/ILSVRC2012_val_00048486.bin 224 224 +16974 ./prep_dataset/ILSVRC2012_val_00021696.bin 224 224 +16975 ./prep_dataset/ILSVRC2012_val_00034557.bin 224 224 +16976 ./prep_dataset/ILSVRC2012_val_00031944.bin 224 224 +16977 ./prep_dataset/ILSVRC2012_val_00000916.bin 224 224 +16978 ./prep_dataset/ILSVRC2012_val_00023473.bin 224 224 +16979 ./prep_dataset/ILSVRC2012_val_00002130.bin 224 224 +16980 ./prep_dataset/ILSVRC2012_val_00036906.bin 224 224 +16981 ./prep_dataset/ILSVRC2012_val_00017406.bin 224 224 +16982 ./prep_dataset/ILSVRC2012_val_00023857.bin 224 224 +16983 ./prep_dataset/ILSVRC2012_val_00002456.bin 224 224 +16984 ./prep_dataset/ILSVRC2012_val_00025899.bin 224 224 +16985 ./prep_dataset/ILSVRC2012_val_00038747.bin 224 224 +16986 ./prep_dataset/ILSVRC2012_val_00032161.bin 224 224 +16987 ./prep_dataset/ILSVRC2012_val_00019821.bin 224 224 +16988 ./prep_dataset/ILSVRC2012_val_00001389.bin 224 224 +16989 ./prep_dataset/ILSVRC2012_val_00029405.bin 224 224 +16990 ./prep_dataset/ILSVRC2012_val_00019701.bin 224 224 +16991 ./prep_dataset/ILSVRC2012_val_00035263.bin 224 224 +16992 ./prep_dataset/ILSVRC2012_val_00028021.bin 224 224 +16993 ./prep_dataset/ILSVRC2012_val_00015919.bin 224 224 +16994 ./prep_dataset/ILSVRC2012_val_00032952.bin 224 224 +16995 ./prep_dataset/ILSVRC2012_val_00012010.bin 224 224 +16996 ./prep_dataset/ILSVRC2012_val_00012857.bin 224 224 +16997 ./prep_dataset/ILSVRC2012_val_00014357.bin 224 224 +16998 ./prep_dataset/ILSVRC2012_val_00000897.bin 224 224 +16999 ./prep_dataset/ILSVRC2012_val_00008066.bin 224 224 +17000 ./prep_dataset/ILSVRC2012_val_00021879.bin 224 224 +17001 ./prep_dataset/ILSVRC2012_val_00013020.bin 224 224 +17002 ./prep_dataset/ILSVRC2012_val_00049067.bin 224 224 +17003 ./prep_dataset/ILSVRC2012_val_00043634.bin 224 224 +17004 ./prep_dataset/ILSVRC2012_val_00013054.bin 224 224 +17005 ./prep_dataset/ILSVRC2012_val_00011302.bin 224 224 +17006 ./prep_dataset/ILSVRC2012_val_00001798.bin 224 224 +17007 ./prep_dataset/ILSVRC2012_val_00026253.bin 224 224 +17008 ./prep_dataset/ILSVRC2012_val_00023276.bin 224 224 +17009 ./prep_dataset/ILSVRC2012_val_00025709.bin 224 224 +17010 ./prep_dataset/ILSVRC2012_val_00001141.bin 224 224 +17011 ./prep_dataset/ILSVRC2012_val_00015677.bin 224 224 +17012 ./prep_dataset/ILSVRC2012_val_00032498.bin 224 224 +17013 ./prep_dataset/ILSVRC2012_val_00001839.bin 224 224 +17014 ./prep_dataset/ILSVRC2012_val_00045711.bin 224 224 +17015 ./prep_dataset/ILSVRC2012_val_00027762.bin 224 224 +17016 ./prep_dataset/ILSVRC2012_val_00035885.bin 224 224 +17017 ./prep_dataset/ILSVRC2012_val_00040651.bin 224 224 +17018 ./prep_dataset/ILSVRC2012_val_00031969.bin 224 224 +17019 ./prep_dataset/ILSVRC2012_val_00020306.bin 224 224 +17020 ./prep_dataset/ILSVRC2012_val_00006314.bin 224 224 +17021 ./prep_dataset/ILSVRC2012_val_00010690.bin 224 224 +17022 ./prep_dataset/ILSVRC2012_val_00033959.bin 224 224 +17023 ./prep_dataset/ILSVRC2012_val_00008715.bin 224 224 +17024 ./prep_dataset/ILSVRC2012_val_00030533.bin 224 224 +17025 ./prep_dataset/ILSVRC2012_val_00035404.bin 224 224 +17026 ./prep_dataset/ILSVRC2012_val_00025258.bin 224 224 +17027 ./prep_dataset/ILSVRC2012_val_00030737.bin 224 224 +17028 ./prep_dataset/ILSVRC2012_val_00032392.bin 224 224 +17029 ./prep_dataset/ILSVRC2012_val_00009426.bin 224 224 +17030 ./prep_dataset/ILSVRC2012_val_00036577.bin 224 224 +17031 ./prep_dataset/ILSVRC2012_val_00003261.bin 224 224 +17032 ./prep_dataset/ILSVRC2012_val_00034951.bin 224 224 +17033 ./prep_dataset/ILSVRC2012_val_00048193.bin 224 224 +17034 ./prep_dataset/ILSVRC2012_val_00002757.bin 224 224 +17035 ./prep_dataset/ILSVRC2012_val_00021776.bin 224 224 +17036 ./prep_dataset/ILSVRC2012_val_00036225.bin 224 224 +17037 ./prep_dataset/ILSVRC2012_val_00020891.bin 224 224 +17038 ./prep_dataset/ILSVRC2012_val_00018952.bin 224 224 +17039 ./prep_dataset/ILSVRC2012_val_00037904.bin 224 224 +17040 ./prep_dataset/ILSVRC2012_val_00026938.bin 224 224 +17041 ./prep_dataset/ILSVRC2012_val_00040083.bin 224 224 +17042 ./prep_dataset/ILSVRC2012_val_00036323.bin 224 224 +17043 ./prep_dataset/ILSVRC2012_val_00027468.bin 224 224 +17044 ./prep_dataset/ILSVRC2012_val_00017933.bin 224 224 +17045 ./prep_dataset/ILSVRC2012_val_00007582.bin 224 224 +17046 ./prep_dataset/ILSVRC2012_val_00040720.bin 224 224 +17047 ./prep_dataset/ILSVRC2012_val_00009215.bin 224 224 +17048 ./prep_dataset/ILSVRC2012_val_00018255.bin 224 224 +17049 ./prep_dataset/ILSVRC2012_val_00004803.bin 224 224 +17050 ./prep_dataset/ILSVRC2012_val_00047311.bin 224 224 +17051 ./prep_dataset/ILSVRC2012_val_00035184.bin 224 224 +17052 ./prep_dataset/ILSVRC2012_val_00024972.bin 224 224 +17053 ./prep_dataset/ILSVRC2012_val_00020574.bin 224 224 +17054 ./prep_dataset/ILSVRC2012_val_00033749.bin 224 224 +17055 ./prep_dataset/ILSVRC2012_val_00027944.bin 224 224 +17056 ./prep_dataset/ILSVRC2012_val_00018263.bin 224 224 +17057 ./prep_dataset/ILSVRC2012_val_00027996.bin 224 224 +17058 ./prep_dataset/ILSVRC2012_val_00009149.bin 224 224 +17059 ./prep_dataset/ILSVRC2012_val_00019145.bin 224 224 +17060 ./prep_dataset/ILSVRC2012_val_00042579.bin 224 224 +17061 ./prep_dataset/ILSVRC2012_val_00020739.bin 224 224 +17062 ./prep_dataset/ILSVRC2012_val_00015093.bin 224 224 +17063 ./prep_dataset/ILSVRC2012_val_00017631.bin 224 224 +17064 ./prep_dataset/ILSVRC2012_val_00023704.bin 224 224 +17065 ./prep_dataset/ILSVRC2012_val_00009767.bin 224 224 +17066 ./prep_dataset/ILSVRC2012_val_00015659.bin 224 224 +17067 ./prep_dataset/ILSVRC2012_val_00029477.bin 224 224 +17068 ./prep_dataset/ILSVRC2012_val_00003981.bin 224 224 +17069 ./prep_dataset/ILSVRC2012_val_00022706.bin 224 224 +17070 ./prep_dataset/ILSVRC2012_val_00021749.bin 224 224 +17071 ./prep_dataset/ILSVRC2012_val_00033711.bin 224 224 +17072 ./prep_dataset/ILSVRC2012_val_00046575.bin 224 224 +17073 ./prep_dataset/ILSVRC2012_val_00040768.bin 224 224 +17074 ./prep_dataset/ILSVRC2012_val_00028894.bin 224 224 +17075 ./prep_dataset/ILSVRC2012_val_00002672.bin 224 224 +17076 ./prep_dataset/ILSVRC2012_val_00014843.bin 224 224 +17077 ./prep_dataset/ILSVRC2012_val_00045982.bin 224 224 +17078 ./prep_dataset/ILSVRC2012_val_00029737.bin 224 224 +17079 ./prep_dataset/ILSVRC2012_val_00044588.bin 224 224 +17080 ./prep_dataset/ILSVRC2012_val_00006296.bin 224 224 +17081 ./prep_dataset/ILSVRC2012_val_00002084.bin 224 224 +17082 ./prep_dataset/ILSVRC2012_val_00007585.bin 224 224 +17083 ./prep_dataset/ILSVRC2012_val_00020082.bin 224 224 +17084 ./prep_dataset/ILSVRC2012_val_00011750.bin 224 224 +17085 ./prep_dataset/ILSVRC2012_val_00035208.bin 224 224 +17086 ./prep_dataset/ILSVRC2012_val_00042403.bin 224 224 +17087 ./prep_dataset/ILSVRC2012_val_00032629.bin 224 224 +17088 ./prep_dataset/ILSVRC2012_val_00033515.bin 224 224 +17089 ./prep_dataset/ILSVRC2012_val_00022792.bin 224 224 +17090 ./prep_dataset/ILSVRC2012_val_00007155.bin 224 224 +17091 ./prep_dataset/ILSVRC2012_val_00002961.bin 224 224 +17092 ./prep_dataset/ILSVRC2012_val_00006774.bin 224 224 +17093 ./prep_dataset/ILSVRC2012_val_00008650.bin 224 224 +17094 ./prep_dataset/ILSVRC2012_val_00027781.bin 224 224 +17095 ./prep_dataset/ILSVRC2012_val_00003327.bin 224 224 +17096 ./prep_dataset/ILSVRC2012_val_00045748.bin 224 224 +17097 ./prep_dataset/ILSVRC2012_val_00024687.bin 224 224 +17098 ./prep_dataset/ILSVRC2012_val_00029008.bin 224 224 +17099 ./prep_dataset/ILSVRC2012_val_00020700.bin 224 224 +17100 ./prep_dataset/ILSVRC2012_val_00027894.bin 224 224 +17101 ./prep_dataset/ILSVRC2012_val_00001635.bin 224 224 +17102 ./prep_dataset/ILSVRC2012_val_00012151.bin 224 224 +17103 ./prep_dataset/ILSVRC2012_val_00033554.bin 224 224 +17104 ./prep_dataset/ILSVRC2012_val_00030152.bin 224 224 +17105 ./prep_dataset/ILSVRC2012_val_00008482.bin 224 224 +17106 ./prep_dataset/ILSVRC2012_val_00033612.bin 224 224 +17107 ./prep_dataset/ILSVRC2012_val_00023146.bin 224 224 +17108 ./prep_dataset/ILSVRC2012_val_00016349.bin 224 224 +17109 ./prep_dataset/ILSVRC2012_val_00016057.bin 224 224 +17110 ./prep_dataset/ILSVRC2012_val_00044007.bin 224 224 +17111 ./prep_dataset/ILSVRC2012_val_00031932.bin 224 224 +17112 ./prep_dataset/ILSVRC2012_val_00014233.bin 224 224 +17113 ./prep_dataset/ILSVRC2012_val_00014783.bin 224 224 +17114 ./prep_dataset/ILSVRC2012_val_00021341.bin 224 224 +17115 ./prep_dataset/ILSVRC2012_val_00035840.bin 224 224 +17116 ./prep_dataset/ILSVRC2012_val_00042840.bin 224 224 +17117 ./prep_dataset/ILSVRC2012_val_00043706.bin 224 224 +17118 ./prep_dataset/ILSVRC2012_val_00048977.bin 224 224 +17119 ./prep_dataset/ILSVRC2012_val_00002432.bin 224 224 +17120 ./prep_dataset/ILSVRC2012_val_00000547.bin 224 224 +17121 ./prep_dataset/ILSVRC2012_val_00024722.bin 224 224 +17122 ./prep_dataset/ILSVRC2012_val_00021366.bin 224 224 +17123 ./prep_dataset/ILSVRC2012_val_00028222.bin 224 224 +17124 ./prep_dataset/ILSVRC2012_val_00041314.bin 224 224 +17125 ./prep_dataset/ILSVRC2012_val_00024828.bin 224 224 +17126 ./prep_dataset/ILSVRC2012_val_00044668.bin 224 224 +17127 ./prep_dataset/ILSVRC2012_val_00031161.bin 224 224 +17128 ./prep_dataset/ILSVRC2012_val_00003015.bin 224 224 +17129 ./prep_dataset/ILSVRC2012_val_00017292.bin 224 224 +17130 ./prep_dataset/ILSVRC2012_val_00004297.bin 224 224 +17131 ./prep_dataset/ILSVRC2012_val_00021284.bin 224 224 +17132 ./prep_dataset/ILSVRC2012_val_00008144.bin 224 224 +17133 ./prep_dataset/ILSVRC2012_val_00020954.bin 224 224 +17134 ./prep_dataset/ILSVRC2012_val_00000739.bin 224 224 +17135 ./prep_dataset/ILSVRC2012_val_00024820.bin 224 224 +17136 ./prep_dataset/ILSVRC2012_val_00015888.bin 224 224 +17137 ./prep_dataset/ILSVRC2012_val_00030627.bin 224 224 +17138 ./prep_dataset/ILSVRC2012_val_00009375.bin 224 224 +17139 ./prep_dataset/ILSVRC2012_val_00009645.bin 224 224 +17140 ./prep_dataset/ILSVRC2012_val_00036615.bin 224 224 +17141 ./prep_dataset/ILSVRC2012_val_00009064.bin 224 224 +17142 ./prep_dataset/ILSVRC2012_val_00012382.bin 224 224 +17143 ./prep_dataset/ILSVRC2012_val_00008474.bin 224 224 +17144 ./prep_dataset/ILSVRC2012_val_00019116.bin 224 224 +17145 ./prep_dataset/ILSVRC2012_val_00041760.bin 224 224 +17146 ./prep_dataset/ILSVRC2012_val_00022656.bin 224 224 +17147 ./prep_dataset/ILSVRC2012_val_00031888.bin 224 224 +17148 ./prep_dataset/ILSVRC2012_val_00019193.bin 224 224 +17149 ./prep_dataset/ILSVRC2012_val_00027726.bin 224 224 +17150 ./prep_dataset/ILSVRC2012_val_00024376.bin 224 224 +17151 ./prep_dataset/ILSVRC2012_val_00014350.bin 224 224 +17152 ./prep_dataset/ILSVRC2012_val_00019180.bin 224 224 +17153 ./prep_dataset/ILSVRC2012_val_00019454.bin 224 224 +17154 ./prep_dataset/ILSVRC2012_val_00023462.bin 224 224 +17155 ./prep_dataset/ILSVRC2012_val_00025938.bin 224 224 +17156 ./prep_dataset/ILSVRC2012_val_00039277.bin 224 224 +17157 ./prep_dataset/ILSVRC2012_val_00046735.bin 224 224 +17158 ./prep_dataset/ILSVRC2012_val_00027157.bin 224 224 +17159 ./prep_dataset/ILSVRC2012_val_00007270.bin 224 224 +17160 ./prep_dataset/ILSVRC2012_val_00016013.bin 224 224 +17161 ./prep_dataset/ILSVRC2012_val_00044505.bin 224 224 +17162 ./prep_dataset/ILSVRC2012_val_00037917.bin 224 224 +17163 ./prep_dataset/ILSVRC2012_val_00041538.bin 224 224 +17164 ./prep_dataset/ILSVRC2012_val_00017888.bin 224 224 +17165 ./prep_dataset/ILSVRC2012_val_00018213.bin 224 224 +17166 ./prep_dataset/ILSVRC2012_val_00019658.bin 224 224 +17167 ./prep_dataset/ILSVRC2012_val_00008597.bin 224 224 +17168 ./prep_dataset/ILSVRC2012_val_00022151.bin 224 224 +17169 ./prep_dataset/ILSVRC2012_val_00049037.bin 224 224 +17170 ./prep_dataset/ILSVRC2012_val_00027655.bin 224 224 +17171 ./prep_dataset/ILSVRC2012_val_00002532.bin 224 224 +17172 ./prep_dataset/ILSVRC2012_val_00033174.bin 224 224 +17173 ./prep_dataset/ILSVRC2012_val_00021144.bin 224 224 +17174 ./prep_dataset/ILSVRC2012_val_00021977.bin 224 224 +17175 ./prep_dataset/ILSVRC2012_val_00022974.bin 224 224 +17176 ./prep_dataset/ILSVRC2012_val_00038307.bin 224 224 +17177 ./prep_dataset/ILSVRC2012_val_00012692.bin 224 224 +17178 ./prep_dataset/ILSVRC2012_val_00039901.bin 224 224 +17179 ./prep_dataset/ILSVRC2012_val_00040334.bin 224 224 +17180 ./prep_dataset/ILSVRC2012_val_00044772.bin 224 224 +17181 ./prep_dataset/ILSVRC2012_val_00031289.bin 224 224 +17182 ./prep_dataset/ILSVRC2012_val_00000670.bin 224 224 +17183 ./prep_dataset/ILSVRC2012_val_00037858.bin 224 224 +17184 ./prep_dataset/ILSVRC2012_val_00021279.bin 224 224 +17185 ./prep_dataset/ILSVRC2012_val_00044133.bin 224 224 +17186 ./prep_dataset/ILSVRC2012_val_00016392.bin 224 224 +17187 ./prep_dataset/ILSVRC2012_val_00038798.bin 224 224 +17188 ./prep_dataset/ILSVRC2012_val_00012132.bin 224 224 +17189 ./prep_dataset/ILSVRC2012_val_00038703.bin 224 224 +17190 ./prep_dataset/ILSVRC2012_val_00012557.bin 224 224 +17191 ./prep_dataset/ILSVRC2012_val_00024611.bin 224 224 +17192 ./prep_dataset/ILSVRC2012_val_00010764.bin 224 224 +17193 ./prep_dataset/ILSVRC2012_val_00007736.bin 224 224 +17194 ./prep_dataset/ILSVRC2012_val_00038543.bin 224 224 +17195 ./prep_dataset/ILSVRC2012_val_00004324.bin 224 224 +17196 ./prep_dataset/ILSVRC2012_val_00012389.bin 224 224 +17197 ./prep_dataset/ILSVRC2012_val_00048967.bin 224 224 +17198 ./prep_dataset/ILSVRC2012_val_00046574.bin 224 224 +17199 ./prep_dataset/ILSVRC2012_val_00042806.bin 224 224 +17200 ./prep_dataset/ILSVRC2012_val_00044368.bin 224 224 +17201 ./prep_dataset/ILSVRC2012_val_00002822.bin 224 224 +17202 ./prep_dataset/ILSVRC2012_val_00022795.bin 224 224 +17203 ./prep_dataset/ILSVRC2012_val_00004589.bin 224 224 +17204 ./prep_dataset/ILSVRC2012_val_00039050.bin 224 224 +17205 ./prep_dataset/ILSVRC2012_val_00012498.bin 224 224 +17206 ./prep_dataset/ILSVRC2012_val_00025025.bin 224 224 +17207 ./prep_dataset/ILSVRC2012_val_00046465.bin 224 224 +17208 ./prep_dataset/ILSVRC2012_val_00022790.bin 224 224 +17209 ./prep_dataset/ILSVRC2012_val_00016792.bin 224 224 +17210 ./prep_dataset/ILSVRC2012_val_00010886.bin 224 224 +17211 ./prep_dataset/ILSVRC2012_val_00044247.bin 224 224 +17212 ./prep_dataset/ILSVRC2012_val_00038118.bin 224 224 +17213 ./prep_dataset/ILSVRC2012_val_00025585.bin 224 224 +17214 ./prep_dataset/ILSVRC2012_val_00019213.bin 224 224 +17215 ./prep_dataset/ILSVRC2012_val_00012210.bin 224 224 +17216 ./prep_dataset/ILSVRC2012_val_00020738.bin 224 224 +17217 ./prep_dataset/ILSVRC2012_val_00006565.bin 224 224 +17218 ./prep_dataset/ILSVRC2012_val_00009918.bin 224 224 +17219 ./prep_dataset/ILSVRC2012_val_00001639.bin 224 224 +17220 ./prep_dataset/ILSVRC2012_val_00000056.bin 224 224 +17221 ./prep_dataset/ILSVRC2012_val_00035378.bin 224 224 +17222 ./prep_dataset/ILSVRC2012_val_00016144.bin 224 224 +17223 ./prep_dataset/ILSVRC2012_val_00017316.bin 224 224 +17224 ./prep_dataset/ILSVRC2012_val_00019404.bin 224 224 +17225 ./prep_dataset/ILSVRC2012_val_00008811.bin 224 224 +17226 ./prep_dataset/ILSVRC2012_val_00034232.bin 224 224 +17227 ./prep_dataset/ILSVRC2012_val_00034826.bin 224 224 +17228 ./prep_dataset/ILSVRC2012_val_00012707.bin 224 224 +17229 ./prep_dataset/ILSVRC2012_val_00047643.bin 224 224 +17230 ./prep_dataset/ILSVRC2012_val_00038953.bin 224 224 +17231 ./prep_dataset/ILSVRC2012_val_00004192.bin 224 224 +17232 ./prep_dataset/ILSVRC2012_val_00007260.bin 224 224 +17233 ./prep_dataset/ILSVRC2012_val_00043186.bin 224 224 +17234 ./prep_dataset/ILSVRC2012_val_00009751.bin 224 224 +17235 ./prep_dataset/ILSVRC2012_val_00012885.bin 224 224 +17236 ./prep_dataset/ILSVRC2012_val_00046590.bin 224 224 +17237 ./prep_dataset/ILSVRC2012_val_00000008.bin 224 224 +17238 ./prep_dataset/ILSVRC2012_val_00047161.bin 224 224 +17239 ./prep_dataset/ILSVRC2012_val_00007874.bin 224 224 +17240 ./prep_dataset/ILSVRC2012_val_00012229.bin 224 224 +17241 ./prep_dataset/ILSVRC2012_val_00004704.bin 224 224 +17242 ./prep_dataset/ILSVRC2012_val_00010897.bin 224 224 +17243 ./prep_dataset/ILSVRC2012_val_00010609.bin 224 224 +17244 ./prep_dataset/ILSVRC2012_val_00008634.bin 224 224 +17245 ./prep_dataset/ILSVRC2012_val_00014989.bin 224 224 +17246 ./prep_dataset/ILSVRC2012_val_00012572.bin 224 224 +17247 ./prep_dataset/ILSVRC2012_val_00045404.bin 224 224 +17248 ./prep_dataset/ILSVRC2012_val_00011599.bin 224 224 +17249 ./prep_dataset/ILSVRC2012_val_00024059.bin 224 224 +17250 ./prep_dataset/ILSVRC2012_val_00019644.bin 224 224 +17251 ./prep_dataset/ILSVRC2012_val_00011537.bin 224 224 +17252 ./prep_dataset/ILSVRC2012_val_00033280.bin 224 224 +17253 ./prep_dataset/ILSVRC2012_val_00036161.bin 224 224 +17254 ./prep_dataset/ILSVRC2012_val_00023556.bin 224 224 +17255 ./prep_dataset/ILSVRC2012_val_00003102.bin 224 224 +17256 ./prep_dataset/ILSVRC2012_val_00049282.bin 224 224 +17257 ./prep_dataset/ILSVRC2012_val_00001580.bin 224 224 +17258 ./prep_dataset/ILSVRC2012_val_00027680.bin 224 224 +17259 ./prep_dataset/ILSVRC2012_val_00048920.bin 224 224 +17260 ./prep_dataset/ILSVRC2012_val_00006842.bin 224 224 +17261 ./prep_dataset/ILSVRC2012_val_00011973.bin 224 224 +17262 ./prep_dataset/ILSVRC2012_val_00027044.bin 224 224 +17263 ./prep_dataset/ILSVRC2012_val_00022942.bin 224 224 +17264 ./prep_dataset/ILSVRC2012_val_00026565.bin 224 224 +17265 ./prep_dataset/ILSVRC2012_val_00009792.bin 224 224 +17266 ./prep_dataset/ILSVRC2012_val_00012255.bin 224 224 +17267 ./prep_dataset/ILSVRC2012_val_00012195.bin 224 224 +17268 ./prep_dataset/ILSVRC2012_val_00006020.bin 224 224 +17269 ./prep_dataset/ILSVRC2012_val_00031340.bin 224 224 +17270 ./prep_dataset/ILSVRC2012_val_00013623.bin 224 224 +17271 ./prep_dataset/ILSVRC2012_val_00029152.bin 224 224 +17272 ./prep_dataset/ILSVRC2012_val_00029213.bin 224 224 +17273 ./prep_dataset/ILSVRC2012_val_00036107.bin 224 224 +17274 ./prep_dataset/ILSVRC2012_val_00046409.bin 224 224 +17275 ./prep_dataset/ILSVRC2012_val_00049190.bin 224 224 +17276 ./prep_dataset/ILSVRC2012_val_00029325.bin 224 224 +17277 ./prep_dataset/ILSVRC2012_val_00016217.bin 224 224 +17278 ./prep_dataset/ILSVRC2012_val_00025378.bin 224 224 +17279 ./prep_dataset/ILSVRC2012_val_00032792.bin 224 224 +17280 ./prep_dataset/ILSVRC2012_val_00013340.bin 224 224 +17281 ./prep_dataset/ILSVRC2012_val_00038911.bin 224 224 +17282 ./prep_dataset/ILSVRC2012_val_00049827.bin 224 224 +17283 ./prep_dataset/ILSVRC2012_val_00030404.bin 224 224 +17284 ./prep_dataset/ILSVRC2012_val_00018024.bin 224 224 +17285 ./prep_dataset/ILSVRC2012_val_00013373.bin 224 224 +17286 ./prep_dataset/ILSVRC2012_val_00020385.bin 224 224 +17287 ./prep_dataset/ILSVRC2012_val_00049881.bin 224 224 +17288 ./prep_dataset/ILSVRC2012_val_00006403.bin 224 224 +17289 ./prep_dataset/ILSVRC2012_val_00035353.bin 224 224 +17290 ./prep_dataset/ILSVRC2012_val_00019946.bin 224 224 +17291 ./prep_dataset/ILSVRC2012_val_00010007.bin 224 224 +17292 ./prep_dataset/ILSVRC2012_val_00030142.bin 224 224 +17293 ./prep_dataset/ILSVRC2012_val_00030028.bin 224 224 +17294 ./prep_dataset/ILSVRC2012_val_00027171.bin 224 224 +17295 ./prep_dataset/ILSVRC2012_val_00042131.bin 224 224 +17296 ./prep_dataset/ILSVRC2012_val_00011900.bin 224 224 +17297 ./prep_dataset/ILSVRC2012_val_00002720.bin 224 224 +17298 ./prep_dataset/ILSVRC2012_val_00033923.bin 224 224 +17299 ./prep_dataset/ILSVRC2012_val_00032395.bin 224 224 +17300 ./prep_dataset/ILSVRC2012_val_00040734.bin 224 224 +17301 ./prep_dataset/ILSVRC2012_val_00019283.bin 224 224 +17302 ./prep_dataset/ILSVRC2012_val_00038564.bin 224 224 +17303 ./prep_dataset/ILSVRC2012_val_00012848.bin 224 224 +17304 ./prep_dataset/ILSVRC2012_val_00015940.bin 224 224 +17305 ./prep_dataset/ILSVRC2012_val_00003589.bin 224 224 +17306 ./prep_dataset/ILSVRC2012_val_00038067.bin 224 224 +17307 ./prep_dataset/ILSVRC2012_val_00026613.bin 224 224 +17308 ./prep_dataset/ILSVRC2012_val_00018171.bin 224 224 +17309 ./prep_dataset/ILSVRC2012_val_00044048.bin 224 224 +17310 ./prep_dataset/ILSVRC2012_val_00044336.bin 224 224 +17311 ./prep_dataset/ILSVRC2012_val_00045867.bin 224 224 +17312 ./prep_dataset/ILSVRC2012_val_00042726.bin 224 224 +17313 ./prep_dataset/ILSVRC2012_val_00034125.bin 224 224 +17314 ./prep_dataset/ILSVRC2012_val_00031716.bin 224 224 +17315 ./prep_dataset/ILSVRC2012_val_00046605.bin 224 224 +17316 ./prep_dataset/ILSVRC2012_val_00037449.bin 224 224 +17317 ./prep_dataset/ILSVRC2012_val_00002612.bin 224 224 +17318 ./prep_dataset/ILSVRC2012_val_00032721.bin 224 224 +17319 ./prep_dataset/ILSVRC2012_val_00026014.bin 224 224 +17320 ./prep_dataset/ILSVRC2012_val_00041815.bin 224 224 +17321 ./prep_dataset/ILSVRC2012_val_00004659.bin 224 224 +17322 ./prep_dataset/ILSVRC2012_val_00008167.bin 224 224 +17323 ./prep_dataset/ILSVRC2012_val_00047046.bin 224 224 +17324 ./prep_dataset/ILSVRC2012_val_00031773.bin 224 224 +17325 ./prep_dataset/ILSVRC2012_val_00015400.bin 224 224 +17326 ./prep_dataset/ILSVRC2012_val_00016965.bin 224 224 +17327 ./prep_dataset/ILSVRC2012_val_00049311.bin 224 224 +17328 ./prep_dataset/ILSVRC2012_val_00034316.bin 224 224 +17329 ./prep_dataset/ILSVRC2012_val_00023715.bin 224 224 +17330 ./prep_dataset/ILSVRC2012_val_00049821.bin 224 224 +17331 ./prep_dataset/ILSVRC2012_val_00034573.bin 224 224 +17332 ./prep_dataset/ILSVRC2012_val_00030755.bin 224 224 +17333 ./prep_dataset/ILSVRC2012_val_00008114.bin 224 224 +17334 ./prep_dataset/ILSVRC2012_val_00012317.bin 224 224 +17335 ./prep_dataset/ILSVRC2012_val_00004212.bin 224 224 +17336 ./prep_dataset/ILSVRC2012_val_00041853.bin 224 224 +17337 ./prep_dataset/ILSVRC2012_val_00026547.bin 224 224 +17338 ./prep_dataset/ILSVRC2012_val_00047034.bin 224 224 +17339 ./prep_dataset/ILSVRC2012_val_00046899.bin 224 224 +17340 ./prep_dataset/ILSVRC2012_val_00006248.bin 224 224 +17341 ./prep_dataset/ILSVRC2012_val_00008340.bin 224 224 +17342 ./prep_dataset/ILSVRC2012_val_00028160.bin 224 224 +17343 ./prep_dataset/ILSVRC2012_val_00027540.bin 224 224 +17344 ./prep_dataset/ILSVRC2012_val_00021075.bin 224 224 +17345 ./prep_dataset/ILSVRC2012_val_00023529.bin 224 224 +17346 ./prep_dataset/ILSVRC2012_val_00011509.bin 224 224 +17347 ./prep_dataset/ILSVRC2012_val_00043690.bin 224 224 +17348 ./prep_dataset/ILSVRC2012_val_00001992.bin 224 224 +17349 ./prep_dataset/ILSVRC2012_val_00045927.bin 224 224 +17350 ./prep_dataset/ILSVRC2012_val_00008877.bin 224 224 +17351 ./prep_dataset/ILSVRC2012_val_00017446.bin 224 224 +17352 ./prep_dataset/ILSVRC2012_val_00012791.bin 224 224 +17353 ./prep_dataset/ILSVRC2012_val_00031700.bin 224 224 +17354 ./prep_dataset/ILSVRC2012_val_00023727.bin 224 224 +17355 ./prep_dataset/ILSVRC2012_val_00024156.bin 224 224 +17356 ./prep_dataset/ILSVRC2012_val_00026366.bin 224 224 +17357 ./prep_dataset/ILSVRC2012_val_00041240.bin 224 224 +17358 ./prep_dataset/ILSVRC2012_val_00010958.bin 224 224 +17359 ./prep_dataset/ILSVRC2012_val_00013760.bin 224 224 +17360 ./prep_dataset/ILSVRC2012_val_00015145.bin 224 224 +17361 ./prep_dataset/ILSVRC2012_val_00031935.bin 224 224 +17362 ./prep_dataset/ILSVRC2012_val_00000466.bin 224 224 +17363 ./prep_dataset/ILSVRC2012_val_00029179.bin 224 224 +17364 ./prep_dataset/ILSVRC2012_val_00020335.bin 224 224 +17365 ./prep_dataset/ILSVRC2012_val_00029183.bin 224 224 +17366 ./prep_dataset/ILSVRC2012_val_00029575.bin 224 224 +17367 ./prep_dataset/ILSVRC2012_val_00028987.bin 224 224 +17368 ./prep_dataset/ILSVRC2012_val_00030911.bin 224 224 +17369 ./prep_dataset/ILSVRC2012_val_00032819.bin 224 224 +17370 ./prep_dataset/ILSVRC2012_val_00018058.bin 224 224 +17371 ./prep_dataset/ILSVRC2012_val_00023101.bin 224 224 +17372 ./prep_dataset/ILSVRC2012_val_00041748.bin 224 224 +17373 ./prep_dataset/ILSVRC2012_val_00041517.bin 224 224 +17374 ./prep_dataset/ILSVRC2012_val_00010655.bin 224 224 +17375 ./prep_dataset/ILSVRC2012_val_00046906.bin 224 224 +17376 ./prep_dataset/ILSVRC2012_val_00012476.bin 224 224 +17377 ./prep_dataset/ILSVRC2012_val_00037380.bin 224 224 +17378 ./prep_dataset/ILSVRC2012_val_00021720.bin 224 224 +17379 ./prep_dataset/ILSVRC2012_val_00000242.bin 224 224 +17380 ./prep_dataset/ILSVRC2012_val_00030227.bin 224 224 +17381 ./prep_dataset/ILSVRC2012_val_00014507.bin 224 224 +17382 ./prep_dataset/ILSVRC2012_val_00001239.bin 224 224 +17383 ./prep_dataset/ILSVRC2012_val_00038530.bin 224 224 +17384 ./prep_dataset/ILSVRC2012_val_00028892.bin 224 224 +17385 ./prep_dataset/ILSVRC2012_val_00012859.bin 224 224 +17386 ./prep_dataset/ILSVRC2012_val_00016872.bin 224 224 +17387 ./prep_dataset/ILSVRC2012_val_00029808.bin 224 224 +17388 ./prep_dataset/ILSVRC2012_val_00041717.bin 224 224 +17389 ./prep_dataset/ILSVRC2012_val_00007572.bin 224 224 +17390 ./prep_dataset/ILSVRC2012_val_00004566.bin 224 224 +17391 ./prep_dataset/ILSVRC2012_val_00021996.bin 224 224 +17392 ./prep_dataset/ILSVRC2012_val_00030050.bin 224 224 +17393 ./prep_dataset/ILSVRC2012_val_00042769.bin 224 224 +17394 ./prep_dataset/ILSVRC2012_val_00017531.bin 224 224 +17395 ./prep_dataset/ILSVRC2012_val_00002445.bin 224 224 +17396 ./prep_dataset/ILSVRC2012_val_00042818.bin 224 224 +17397 ./prep_dataset/ILSVRC2012_val_00012847.bin 224 224 +17398 ./prep_dataset/ILSVRC2012_val_00006551.bin 224 224 +17399 ./prep_dataset/ILSVRC2012_val_00039272.bin 224 224 +17400 ./prep_dataset/ILSVRC2012_val_00033100.bin 224 224 +17401 ./prep_dataset/ILSVRC2012_val_00042962.bin 224 224 +17402 ./prep_dataset/ILSVRC2012_val_00001892.bin 224 224 +17403 ./prep_dataset/ILSVRC2012_val_00011114.bin 224 224 +17404 ./prep_dataset/ILSVRC2012_val_00022686.bin 224 224 +17405 ./prep_dataset/ILSVRC2012_val_00045730.bin 224 224 +17406 ./prep_dataset/ILSVRC2012_val_00040190.bin 224 224 +17407 ./prep_dataset/ILSVRC2012_val_00031469.bin 224 224 +17408 ./prep_dataset/ILSVRC2012_val_00035004.bin 224 224 +17409 ./prep_dataset/ILSVRC2012_val_00022766.bin 224 224 +17410 ./prep_dataset/ILSVRC2012_val_00007821.bin 224 224 +17411 ./prep_dataset/ILSVRC2012_val_00043666.bin 224 224 +17412 ./prep_dataset/ILSVRC2012_val_00021247.bin 224 224 +17413 ./prep_dataset/ILSVRC2012_val_00020485.bin 224 224 +17414 ./prep_dataset/ILSVRC2012_val_00021015.bin 224 224 +17415 ./prep_dataset/ILSVRC2012_val_00039267.bin 224 224 +17416 ./prep_dataset/ILSVRC2012_val_00031830.bin 224 224 +17417 ./prep_dataset/ILSVRC2012_val_00001759.bin 224 224 +17418 ./prep_dataset/ILSVRC2012_val_00043625.bin 224 224 +17419 ./prep_dataset/ILSVRC2012_val_00037078.bin 224 224 +17420 ./prep_dataset/ILSVRC2012_val_00039390.bin 224 224 +17421 ./prep_dataset/ILSVRC2012_val_00048080.bin 224 224 +17422 ./prep_dataset/ILSVRC2012_val_00029915.bin 224 224 +17423 ./prep_dataset/ILSVRC2012_val_00032306.bin 224 224 +17424 ./prep_dataset/ILSVRC2012_val_00006112.bin 224 224 +17425 ./prep_dataset/ILSVRC2012_val_00027777.bin 224 224 +17426 ./prep_dataset/ILSVRC2012_val_00004759.bin 224 224 +17427 ./prep_dataset/ILSVRC2012_val_00003866.bin 224 224 +17428 ./prep_dataset/ILSVRC2012_val_00027887.bin 224 224 +17429 ./prep_dataset/ILSVRC2012_val_00019413.bin 224 224 +17430 ./prep_dataset/ILSVRC2012_val_00028277.bin 224 224 +17431 ./prep_dataset/ILSVRC2012_val_00015634.bin 224 224 +17432 ./prep_dataset/ILSVRC2012_val_00016809.bin 224 224 +17433 ./prep_dataset/ILSVRC2012_val_00006101.bin 224 224 +17434 ./prep_dataset/ILSVRC2012_val_00017912.bin 224 224 +17435 ./prep_dataset/ILSVRC2012_val_00043067.bin 224 224 +17436 ./prep_dataset/ILSVRC2012_val_00023598.bin 224 224 +17437 ./prep_dataset/ILSVRC2012_val_00038858.bin 224 224 +17438 ./prep_dataset/ILSVRC2012_val_00003001.bin 224 224 +17439 ./prep_dataset/ILSVRC2012_val_00015631.bin 224 224 +17440 ./prep_dataset/ILSVRC2012_val_00001511.bin 224 224 +17441 ./prep_dataset/ILSVRC2012_val_00014221.bin 224 224 +17442 ./prep_dataset/ILSVRC2012_val_00027945.bin 224 224 +17443 ./prep_dataset/ILSVRC2012_val_00048588.bin 224 224 +17444 ./prep_dataset/ILSVRC2012_val_00031210.bin 224 224 +17445 ./prep_dataset/ILSVRC2012_val_00027534.bin 224 224 +17446 ./prep_dataset/ILSVRC2012_val_00020989.bin 224 224 +17447 ./prep_dataset/ILSVRC2012_val_00014183.bin 224 224 +17448 ./prep_dataset/ILSVRC2012_val_00023422.bin 224 224 +17449 ./prep_dataset/ILSVRC2012_val_00016684.bin 224 224 +17450 ./prep_dataset/ILSVRC2012_val_00049632.bin 224 224 +17451 ./prep_dataset/ILSVRC2012_val_00037964.bin 224 224 +17452 ./prep_dataset/ILSVRC2012_val_00046056.bin 224 224 +17453 ./prep_dataset/ILSVRC2012_val_00009219.bin 224 224 +17454 ./prep_dataset/ILSVRC2012_val_00030623.bin 224 224 +17455 ./prep_dataset/ILSVRC2012_val_00033379.bin 224 224 +17456 ./prep_dataset/ILSVRC2012_val_00028588.bin 224 224 +17457 ./prep_dataset/ILSVRC2012_val_00025922.bin 224 224 +17458 ./prep_dataset/ILSVRC2012_val_00028038.bin 224 224 +17459 ./prep_dataset/ILSVRC2012_val_00028922.bin 224 224 +17460 ./prep_dataset/ILSVRC2012_val_00028044.bin 224 224 +17461 ./prep_dataset/ILSVRC2012_val_00032033.bin 224 224 +17462 ./prep_dataset/ILSVRC2012_val_00006225.bin 224 224 +17463 ./prep_dataset/ILSVRC2012_val_00021503.bin 224 224 +17464 ./prep_dataset/ILSVRC2012_val_00039351.bin 224 224 +17465 ./prep_dataset/ILSVRC2012_val_00023445.bin 224 224 +17466 ./prep_dataset/ILSVRC2012_val_00009093.bin 224 224 +17467 ./prep_dataset/ILSVRC2012_val_00040171.bin 224 224 +17468 ./prep_dataset/ILSVRC2012_val_00042854.bin 224 224 +17469 ./prep_dataset/ILSVRC2012_val_00024411.bin 224 224 +17470 ./prep_dataset/ILSVRC2012_val_00002634.bin 224 224 +17471 ./prep_dataset/ILSVRC2012_val_00012642.bin 224 224 +17472 ./prep_dataset/ILSVRC2012_val_00005241.bin 224 224 +17473 ./prep_dataset/ILSVRC2012_val_00004413.bin 224 224 +17474 ./prep_dataset/ILSVRC2012_val_00010500.bin 224 224 +17475 ./prep_dataset/ILSVRC2012_val_00001146.bin 224 224 +17476 ./prep_dataset/ILSVRC2012_val_00036845.bin 224 224 +17477 ./prep_dataset/ILSVRC2012_val_00032110.bin 224 224 +17478 ./prep_dataset/ILSVRC2012_val_00049946.bin 224 224 +17479 ./prep_dataset/ILSVRC2012_val_00039698.bin 224 224 +17480 ./prep_dataset/ILSVRC2012_val_00008080.bin 224 224 +17481 ./prep_dataset/ILSVRC2012_val_00019238.bin 224 224 +17482 ./prep_dataset/ILSVRC2012_val_00007094.bin 224 224 +17483 ./prep_dataset/ILSVRC2012_val_00037363.bin 224 224 +17484 ./prep_dataset/ILSVRC2012_val_00016525.bin 224 224 +17485 ./prep_dataset/ILSVRC2012_val_00020205.bin 224 224 +17486 ./prep_dataset/ILSVRC2012_val_00030054.bin 224 224 +17487 ./prep_dataset/ILSVRC2012_val_00035414.bin 224 224 +17488 ./prep_dataset/ILSVRC2012_val_00022121.bin 224 224 +17489 ./prep_dataset/ILSVRC2012_val_00017003.bin 224 224 +17490 ./prep_dataset/ILSVRC2012_val_00029707.bin 224 224 +17491 ./prep_dataset/ILSVRC2012_val_00017168.bin 224 224 +17492 ./prep_dataset/ILSVRC2012_val_00025972.bin 224 224 +17493 ./prep_dataset/ILSVRC2012_val_00017765.bin 224 224 +17494 ./prep_dataset/ILSVRC2012_val_00007729.bin 224 224 +17495 ./prep_dataset/ILSVRC2012_val_00000281.bin 224 224 +17496 ./prep_dataset/ILSVRC2012_val_00028445.bin 224 224 +17497 ./prep_dataset/ILSVRC2012_val_00009053.bin 224 224 +17498 ./prep_dataset/ILSVRC2012_val_00014551.bin 224 224 +17499 ./prep_dataset/ILSVRC2012_val_00040091.bin 224 224 +17500 ./prep_dataset/ILSVRC2012_val_00038549.bin 224 224 +17501 ./prep_dataset/ILSVRC2012_val_00042279.bin 224 224 +17502 ./prep_dataset/ILSVRC2012_val_00027074.bin 224 224 +17503 ./prep_dataset/ILSVRC2012_val_00011410.bin 224 224 +17504 ./prep_dataset/ILSVRC2012_val_00020140.bin 224 224 +17505 ./prep_dataset/ILSVRC2012_val_00039173.bin 224 224 +17506 ./prep_dataset/ILSVRC2012_val_00045568.bin 224 224 +17507 ./prep_dataset/ILSVRC2012_val_00033424.bin 224 224 +17508 ./prep_dataset/ILSVRC2012_val_00023969.bin 224 224 +17509 ./prep_dataset/ILSVRC2012_val_00022798.bin 224 224 +17510 ./prep_dataset/ILSVRC2012_val_00036120.bin 224 224 +17511 ./prep_dataset/ILSVRC2012_val_00039299.bin 224 224 +17512 ./prep_dataset/ILSVRC2012_val_00004129.bin 224 224 +17513 ./prep_dataset/ILSVRC2012_val_00049495.bin 224 224 +17514 ./prep_dataset/ILSVRC2012_val_00009222.bin 224 224 +17515 ./prep_dataset/ILSVRC2012_val_00031457.bin 224 224 +17516 ./prep_dataset/ILSVRC2012_val_00033655.bin 224 224 +17517 ./prep_dataset/ILSVRC2012_val_00018510.bin 224 224 +17518 ./prep_dataset/ILSVRC2012_val_00036640.bin 224 224 +17519 ./prep_dataset/ILSVRC2012_val_00035258.bin 224 224 +17520 ./prep_dataset/ILSVRC2012_val_00026227.bin 224 224 +17521 ./prep_dataset/ILSVRC2012_val_00007926.bin 224 224 +17522 ./prep_dataset/ILSVRC2012_val_00023547.bin 224 224 +17523 ./prep_dataset/ILSVRC2012_val_00005575.bin 224 224 +17524 ./prep_dataset/ILSVRC2012_val_00034632.bin 224 224 +17525 ./prep_dataset/ILSVRC2012_val_00032359.bin 224 224 +17526 ./prep_dataset/ILSVRC2012_val_00045269.bin 224 224 +17527 ./prep_dataset/ILSVRC2012_val_00041107.bin 224 224 +17528 ./prep_dataset/ILSVRC2012_val_00032374.bin 224 224 +17529 ./prep_dataset/ILSVRC2012_val_00048499.bin 224 224 +17530 ./prep_dataset/ILSVRC2012_val_00012192.bin 224 224 +17531 ./prep_dataset/ILSVRC2012_val_00013686.bin 224 224 +17532 ./prep_dataset/ILSVRC2012_val_00031468.bin 224 224 +17533 ./prep_dataset/ILSVRC2012_val_00029064.bin 224 224 +17534 ./prep_dataset/ILSVRC2012_val_00019571.bin 224 224 +17535 ./prep_dataset/ILSVRC2012_val_00048612.bin 224 224 +17536 ./prep_dataset/ILSVRC2012_val_00029101.bin 224 224 +17537 ./prep_dataset/ILSVRC2012_val_00004780.bin 224 224 +17538 ./prep_dataset/ILSVRC2012_val_00027769.bin 224 224 +17539 ./prep_dataset/ILSVRC2012_val_00021854.bin 224 224 +17540 ./prep_dataset/ILSVRC2012_val_00032597.bin 224 224 +17541 ./prep_dataset/ILSVRC2012_val_00016143.bin 224 224 +17542 ./prep_dataset/ILSVRC2012_val_00037183.bin 224 224 +17543 ./prep_dataset/ILSVRC2012_val_00027162.bin 224 224 +17544 ./prep_dataset/ILSVRC2012_val_00022632.bin 224 224 +17545 ./prep_dataset/ILSVRC2012_val_00011467.bin 224 224 +17546 ./prep_dataset/ILSVRC2012_val_00024913.bin 224 224 +17547 ./prep_dataset/ILSVRC2012_val_00006332.bin 224 224 +17548 ./prep_dataset/ILSVRC2012_val_00013023.bin 224 224 +17549 ./prep_dataset/ILSVRC2012_val_00020136.bin 224 224 +17550 ./prep_dataset/ILSVRC2012_val_00036070.bin 224 224 +17551 ./prep_dataset/ILSVRC2012_val_00028294.bin 224 224 +17552 ./prep_dataset/ILSVRC2012_val_00035710.bin 224 224 +17553 ./prep_dataset/ILSVRC2012_val_00013577.bin 224 224 +17554 ./prep_dataset/ILSVRC2012_val_00046707.bin 224 224 +17555 ./prep_dataset/ILSVRC2012_val_00019803.bin 224 224 +17556 ./prep_dataset/ILSVRC2012_val_00007010.bin 224 224 +17557 ./prep_dataset/ILSVRC2012_val_00030287.bin 224 224 +17558 ./prep_dataset/ILSVRC2012_val_00013610.bin 224 224 +17559 ./prep_dataset/ILSVRC2012_val_00034002.bin 224 224 +17560 ./prep_dataset/ILSVRC2012_val_00042583.bin 224 224 +17561 ./prep_dataset/ILSVRC2012_val_00027775.bin 224 224 +17562 ./prep_dataset/ILSVRC2012_val_00045858.bin 224 224 +17563 ./prep_dataset/ILSVRC2012_val_00014311.bin 224 224 +17564 ./prep_dataset/ILSVRC2012_val_00005714.bin 224 224 +17565 ./prep_dataset/ILSVRC2012_val_00020715.bin 224 224 +17566 ./prep_dataset/ILSVRC2012_val_00031583.bin 224 224 +17567 ./prep_dataset/ILSVRC2012_val_00013512.bin 224 224 +17568 ./prep_dataset/ILSVRC2012_val_00019745.bin 224 224 +17569 ./prep_dataset/ILSVRC2012_val_00035166.bin 224 224 +17570 ./prep_dataset/ILSVRC2012_val_00007311.bin 224 224 +17571 ./prep_dataset/ILSVRC2012_val_00017827.bin 224 224 +17572 ./prep_dataset/ILSVRC2012_val_00035743.bin 224 224 +17573 ./prep_dataset/ILSVRC2012_val_00016073.bin 224 224 +17574 ./prep_dataset/ILSVRC2012_val_00019631.bin 224 224 +17575 ./prep_dataset/ILSVRC2012_val_00025380.bin 224 224 +17576 ./prep_dataset/ILSVRC2012_val_00034074.bin 224 224 +17577 ./prep_dataset/ILSVRC2012_val_00031107.bin 224 224 +17578 ./prep_dataset/ILSVRC2012_val_00010861.bin 224 224 +17579 ./prep_dataset/ILSVRC2012_val_00043799.bin 224 224 +17580 ./prep_dataset/ILSVRC2012_val_00044801.bin 224 224 +17581 ./prep_dataset/ILSVRC2012_val_00039704.bin 224 224 +17582 ./prep_dataset/ILSVRC2012_val_00030396.bin 224 224 +17583 ./prep_dataset/ILSVRC2012_val_00017980.bin 224 224 +17584 ./prep_dataset/ILSVRC2012_val_00016469.bin 224 224 +17585 ./prep_dataset/ILSVRC2012_val_00036829.bin 224 224 +17586 ./prep_dataset/ILSVRC2012_val_00031576.bin 224 224 +17587 ./prep_dataset/ILSVRC2012_val_00045615.bin 224 224 +17588 ./prep_dataset/ILSVRC2012_val_00024548.bin 224 224 +17589 ./prep_dataset/ILSVRC2012_val_00029532.bin 224 224 +17590 ./prep_dataset/ILSVRC2012_val_00014449.bin 224 224 +17591 ./prep_dataset/ILSVRC2012_val_00048863.bin 224 224 +17592 ./prep_dataset/ILSVRC2012_val_00035648.bin 224 224 +17593 ./prep_dataset/ILSVRC2012_val_00020154.bin 224 224 +17594 ./prep_dataset/ILSVRC2012_val_00027690.bin 224 224 +17595 ./prep_dataset/ILSVRC2012_val_00028877.bin 224 224 +17596 ./prep_dataset/ILSVRC2012_val_00009938.bin 224 224 +17597 ./prep_dataset/ILSVRC2012_val_00032338.bin 224 224 +17598 ./prep_dataset/ILSVRC2012_val_00035013.bin 224 224 +17599 ./prep_dataset/ILSVRC2012_val_00043252.bin 224 224 +17600 ./prep_dataset/ILSVRC2012_val_00033361.bin 224 224 +17601 ./prep_dataset/ILSVRC2012_val_00023215.bin 224 224 +17602 ./prep_dataset/ILSVRC2012_val_00032015.bin 224 224 +17603 ./prep_dataset/ILSVRC2012_val_00008333.bin 224 224 +17604 ./prep_dataset/ILSVRC2012_val_00006471.bin 224 224 +17605 ./prep_dataset/ILSVRC2012_val_00043350.bin 224 224 +17606 ./prep_dataset/ILSVRC2012_val_00023485.bin 224 224 +17607 ./prep_dataset/ILSVRC2012_val_00035729.bin 224 224 +17608 ./prep_dataset/ILSVRC2012_val_00016760.bin 224 224 +17609 ./prep_dataset/ILSVRC2012_val_00042871.bin 224 224 +17610 ./prep_dataset/ILSVRC2012_val_00025916.bin 224 224 +17611 ./prep_dataset/ILSVRC2012_val_00017552.bin 224 224 +17612 ./prep_dataset/ILSVRC2012_val_00019866.bin 224 224 +17613 ./prep_dataset/ILSVRC2012_val_00022138.bin 224 224 +17614 ./prep_dataset/ILSVRC2012_val_00037982.bin 224 224 +17615 ./prep_dataset/ILSVRC2012_val_00045157.bin 224 224 +17616 ./prep_dataset/ILSVRC2012_val_00038553.bin 224 224 +17617 ./prep_dataset/ILSVRC2012_val_00028827.bin 224 224 +17618 ./prep_dataset/ILSVRC2012_val_00003319.bin 224 224 +17619 ./prep_dataset/ILSVRC2012_val_00039985.bin 224 224 +17620 ./prep_dataset/ILSVRC2012_val_00021329.bin 224 224 +17621 ./prep_dataset/ILSVRC2012_val_00019628.bin 224 224 +17622 ./prep_dataset/ILSVRC2012_val_00002071.bin 224 224 +17623 ./prep_dataset/ILSVRC2012_val_00019357.bin 224 224 +17624 ./prep_dataset/ILSVRC2012_val_00013220.bin 224 224 +17625 ./prep_dataset/ILSVRC2012_val_00033894.bin 224 224 +17626 ./prep_dataset/ILSVRC2012_val_00024083.bin 224 224 +17627 ./prep_dataset/ILSVRC2012_val_00047462.bin 224 224 +17628 ./prep_dataset/ILSVRC2012_val_00028418.bin 224 224 +17629 ./prep_dataset/ILSVRC2012_val_00028072.bin 224 224 +17630 ./prep_dataset/ILSVRC2012_val_00031682.bin 224 224 +17631 ./prep_dataset/ILSVRC2012_val_00031849.bin 224 224 +17632 ./prep_dataset/ILSVRC2012_val_00010817.bin 224 224 +17633 ./prep_dataset/ILSVRC2012_val_00021987.bin 224 224 +17634 ./prep_dataset/ILSVRC2012_val_00002556.bin 224 224 +17635 ./prep_dataset/ILSVRC2012_val_00024258.bin 224 224 +17636 ./prep_dataset/ILSVRC2012_val_00033027.bin 224 224 +17637 ./prep_dataset/ILSVRC2012_val_00002271.bin 224 224 +17638 ./prep_dataset/ILSVRC2012_val_00017460.bin 224 224 +17639 ./prep_dataset/ILSVRC2012_val_00025863.bin 224 224 +17640 ./prep_dataset/ILSVRC2012_val_00039641.bin 224 224 +17641 ./prep_dataset/ILSVRC2012_val_00002875.bin 224 224 +17642 ./prep_dataset/ILSVRC2012_val_00001372.bin 224 224 +17643 ./prep_dataset/ILSVRC2012_val_00044843.bin 224 224 +17644 ./prep_dataset/ILSVRC2012_val_00027507.bin 224 224 +17645 ./prep_dataset/ILSVRC2012_val_00032182.bin 224 224 +17646 ./prep_dataset/ILSVRC2012_val_00002597.bin 224 224 +17647 ./prep_dataset/ILSVRC2012_val_00009109.bin 224 224 +17648 ./prep_dataset/ILSVRC2012_val_00012719.bin 224 224 +17649 ./prep_dataset/ILSVRC2012_val_00009423.bin 224 224 +17650 ./prep_dataset/ILSVRC2012_val_00013902.bin 224 224 +17651 ./prep_dataset/ILSVRC2012_val_00028469.bin 224 224 +17652 ./prep_dataset/ILSVRC2012_val_00035242.bin 224 224 +17653 ./prep_dataset/ILSVRC2012_val_00008778.bin 224 224 +17654 ./prep_dataset/ILSVRC2012_val_00046595.bin 224 224 +17655 ./prep_dataset/ILSVRC2012_val_00046915.bin 224 224 +17656 ./prep_dataset/ILSVRC2012_val_00048205.bin 224 224 +17657 ./prep_dataset/ILSVRC2012_val_00029797.bin 224 224 +17658 ./prep_dataset/ILSVRC2012_val_00019303.bin 224 224 +17659 ./prep_dataset/ILSVRC2012_val_00013764.bin 224 224 +17660 ./prep_dataset/ILSVRC2012_val_00002899.bin 224 224 +17661 ./prep_dataset/ILSVRC2012_val_00028742.bin 224 224 +17662 ./prep_dataset/ILSVRC2012_val_00006222.bin 224 224 +17663 ./prep_dataset/ILSVRC2012_val_00001569.bin 224 224 +17664 ./prep_dataset/ILSVRC2012_val_00016771.bin 224 224 +17665 ./prep_dataset/ILSVRC2012_val_00047663.bin 224 224 +17666 ./prep_dataset/ILSVRC2012_val_00029219.bin 224 224 +17667 ./prep_dataset/ILSVRC2012_val_00001728.bin 224 224 +17668 ./prep_dataset/ILSVRC2012_val_00009741.bin 224 224 +17669 ./prep_dataset/ILSVRC2012_val_00038238.bin 224 224 +17670 ./prep_dataset/ILSVRC2012_val_00013698.bin 224 224 +17671 ./prep_dataset/ILSVRC2012_val_00043481.bin 224 224 +17672 ./prep_dataset/ILSVRC2012_val_00010438.bin 224 224 +17673 ./prep_dataset/ILSVRC2012_val_00010918.bin 224 224 +17674 ./prep_dataset/ILSVRC2012_val_00001006.bin 224 224 +17675 ./prep_dataset/ILSVRC2012_val_00009229.bin 224 224 +17676 ./prep_dataset/ILSVRC2012_val_00030986.bin 224 224 +17677 ./prep_dataset/ILSVRC2012_val_00037883.bin 224 224 +17678 ./prep_dataset/ILSVRC2012_val_00023698.bin 224 224 +17679 ./prep_dataset/ILSVRC2012_val_00032868.bin 224 224 +17680 ./prep_dataset/ILSVRC2012_val_00002109.bin 224 224 +17681 ./prep_dataset/ILSVRC2012_val_00002296.bin 224 224 +17682 ./prep_dataset/ILSVRC2012_val_00009900.bin 224 224 +17683 ./prep_dataset/ILSVRC2012_val_00028075.bin 224 224 +17684 ./prep_dataset/ILSVRC2012_val_00023574.bin 224 224 +17685 ./prep_dataset/ILSVRC2012_val_00049570.bin 224 224 +17686 ./prep_dataset/ILSVRC2012_val_00049280.bin 224 224 +17687 ./prep_dataset/ILSVRC2012_val_00022557.bin 224 224 +17688 ./prep_dataset/ILSVRC2012_val_00032122.bin 224 224 +17689 ./prep_dataset/ILSVRC2012_val_00036413.bin 224 224 +17690 ./prep_dataset/ILSVRC2012_val_00006802.bin 224 224 +17691 ./prep_dataset/ILSVRC2012_val_00043775.bin 224 224 +17692 ./prep_dataset/ILSVRC2012_val_00025746.bin 224 224 +17693 ./prep_dataset/ILSVRC2012_val_00011008.bin 224 224 +17694 ./prep_dataset/ILSVRC2012_val_00011000.bin 224 224 +17695 ./prep_dataset/ILSVRC2012_val_00049934.bin 224 224 +17696 ./prep_dataset/ILSVRC2012_val_00045060.bin 224 224 +17697 ./prep_dataset/ILSVRC2012_val_00010911.bin 224 224 +17698 ./prep_dataset/ILSVRC2012_val_00041605.bin 224 224 +17699 ./prep_dataset/ILSVRC2012_val_00009121.bin 224 224 +17700 ./prep_dataset/ILSVRC2012_val_00001349.bin 224 224 +17701 ./prep_dataset/ILSVRC2012_val_00019738.bin 224 224 +17702 ./prep_dataset/ILSVRC2012_val_00011861.bin 224 224 +17703 ./prep_dataset/ILSVRC2012_val_00040191.bin 224 224 +17704 ./prep_dataset/ILSVRC2012_val_00024961.bin 224 224 +17705 ./prep_dataset/ILSVRC2012_val_00044211.bin 224 224 +17706 ./prep_dataset/ILSVRC2012_val_00001665.bin 224 224 +17707 ./prep_dataset/ILSVRC2012_val_00044657.bin 224 224 +17708 ./prep_dataset/ILSVRC2012_val_00023475.bin 224 224 +17709 ./prep_dataset/ILSVRC2012_val_00041985.bin 224 224 +17710 ./prep_dataset/ILSVRC2012_val_00000294.bin 224 224 +17711 ./prep_dataset/ILSVRC2012_val_00000051.bin 224 224 +17712 ./prep_dataset/ILSVRC2012_val_00003888.bin 224 224 +17713 ./prep_dataset/ILSVRC2012_val_00012178.bin 224 224 +17714 ./prep_dataset/ILSVRC2012_val_00042012.bin 224 224 +17715 ./prep_dataset/ILSVRC2012_val_00008046.bin 224 224 +17716 ./prep_dataset/ILSVRC2012_val_00011723.bin 224 224 +17717 ./prep_dataset/ILSVRC2012_val_00005390.bin 224 224 +17718 ./prep_dataset/ILSVRC2012_val_00015014.bin 224 224 +17719 ./prep_dataset/ILSVRC2012_val_00037261.bin 224 224 +17720 ./prep_dataset/ILSVRC2012_val_00027539.bin 224 224 +17721 ./prep_dataset/ILSVRC2012_val_00043828.bin 224 224 +17722 ./prep_dataset/ILSVRC2012_val_00039339.bin 224 224 +17723 ./prep_dataset/ILSVRC2012_val_00012006.bin 224 224 +17724 ./prep_dataset/ILSVRC2012_val_00025747.bin 224 224 +17725 ./prep_dataset/ILSVRC2012_val_00024929.bin 224 224 +17726 ./prep_dataset/ILSVRC2012_val_00016917.bin 224 224 +17727 ./prep_dataset/ILSVRC2012_val_00047002.bin 224 224 +17728 ./prep_dataset/ILSVRC2012_val_00029972.bin 224 224 +17729 ./prep_dataset/ILSVRC2012_val_00010522.bin 224 224 +17730 ./prep_dataset/ILSVRC2012_val_00026048.bin 224 224 +17731 ./prep_dataset/ILSVRC2012_val_00002072.bin 224 224 +17732 ./prep_dataset/ILSVRC2012_val_00047545.bin 224 224 +17733 ./prep_dataset/ILSVRC2012_val_00043300.bin 224 224 +17734 ./prep_dataset/ILSVRC2012_val_00049073.bin 224 224 +17735 ./prep_dataset/ILSVRC2012_val_00036709.bin 224 224 +17736 ./prep_dataset/ILSVRC2012_val_00000833.bin 224 224 +17737 ./prep_dataset/ILSVRC2012_val_00039311.bin 224 224 +17738 ./prep_dataset/ILSVRC2012_val_00007190.bin 224 224 +17739 ./prep_dataset/ILSVRC2012_val_00040268.bin 224 224 +17740 ./prep_dataset/ILSVRC2012_val_00015087.bin 224 224 +17741 ./prep_dataset/ILSVRC2012_val_00026784.bin 224 224 +17742 ./prep_dataset/ILSVRC2012_val_00029348.bin 224 224 +17743 ./prep_dataset/ILSVRC2012_val_00047625.bin 224 224 +17744 ./prep_dataset/ILSVRC2012_val_00028349.bin 224 224 +17745 ./prep_dataset/ILSVRC2012_val_00045970.bin 224 224 +17746 ./prep_dataset/ILSVRC2012_val_00018942.bin 224 224 +17747 ./prep_dataset/ILSVRC2012_val_00039598.bin 224 224 +17748 ./prep_dataset/ILSVRC2012_val_00040554.bin 224 224 +17749 ./prep_dataset/ILSVRC2012_val_00026248.bin 224 224 +17750 ./prep_dataset/ILSVRC2012_val_00037239.bin 224 224 +17751 ./prep_dataset/ILSVRC2012_val_00025566.bin 224 224 +17752 ./prep_dataset/ILSVRC2012_val_00030273.bin 224 224 +17753 ./prep_dataset/ILSVRC2012_val_00012778.bin 224 224 +17754 ./prep_dataset/ILSVRC2012_val_00047691.bin 224 224 +17755 ./prep_dataset/ILSVRC2012_val_00013434.bin 224 224 +17756 ./prep_dataset/ILSVRC2012_val_00019993.bin 224 224 +17757 ./prep_dataset/ILSVRC2012_val_00022760.bin 224 224 +17758 ./prep_dataset/ILSVRC2012_val_00008666.bin 224 224 +17759 ./prep_dataset/ILSVRC2012_val_00000527.bin 224 224 +17760 ./prep_dataset/ILSVRC2012_val_00045619.bin 224 224 +17761 ./prep_dataset/ILSVRC2012_val_00030518.bin 224 224 +17762 ./prep_dataset/ILSVRC2012_val_00040182.bin 224 224 +17763 ./prep_dataset/ILSVRC2012_val_00007802.bin 224 224 +17764 ./prep_dataset/ILSVRC2012_val_00023866.bin 224 224 +17765 ./prep_dataset/ILSVRC2012_val_00017954.bin 224 224 +17766 ./prep_dataset/ILSVRC2012_val_00024802.bin 224 224 +17767 ./prep_dataset/ILSVRC2012_val_00036627.bin 224 224 +17768 ./prep_dataset/ILSVRC2012_val_00016746.bin 224 224 +17769 ./prep_dataset/ILSVRC2012_val_00009452.bin 224 224 +17770 ./prep_dataset/ILSVRC2012_val_00024695.bin 224 224 +17771 ./prep_dataset/ILSVRC2012_val_00034255.bin 224 224 +17772 ./prep_dataset/ILSVRC2012_val_00040507.bin 224 224 +17773 ./prep_dataset/ILSVRC2012_val_00012049.bin 224 224 +17774 ./prep_dataset/ILSVRC2012_val_00024029.bin 224 224 +17775 ./prep_dataset/ILSVRC2012_val_00003073.bin 224 224 +17776 ./prep_dataset/ILSVRC2012_val_00042670.bin 224 224 +17777 ./prep_dataset/ILSVRC2012_val_00040615.bin 224 224 +17778 ./prep_dataset/ILSVRC2012_val_00007994.bin 224 224 +17779 ./prep_dataset/ILSVRC2012_val_00040793.bin 224 224 +17780 ./prep_dataset/ILSVRC2012_val_00047407.bin 224 224 +17781 ./prep_dataset/ILSVRC2012_val_00029246.bin 224 224 +17782 ./prep_dataset/ILSVRC2012_val_00049289.bin 224 224 +17783 ./prep_dataset/ILSVRC2012_val_00026800.bin 224 224 +17784 ./prep_dataset/ILSVRC2012_val_00025625.bin 224 224 +17785 ./prep_dataset/ILSVRC2012_val_00025618.bin 224 224 +17786 ./prep_dataset/ILSVRC2012_val_00014371.bin 224 224 +17787 ./prep_dataset/ILSVRC2012_val_00012136.bin 224 224 +17788 ./prep_dataset/ILSVRC2012_val_00036774.bin 224 224 +17789 ./prep_dataset/ILSVRC2012_val_00002887.bin 224 224 +17790 ./prep_dataset/ILSVRC2012_val_00006298.bin 224 224 +17791 ./prep_dataset/ILSVRC2012_val_00013116.bin 224 224 +17792 ./prep_dataset/ILSVRC2012_val_00023856.bin 224 224 +17793 ./prep_dataset/ILSVRC2012_val_00043842.bin 224 224 +17794 ./prep_dataset/ILSVRC2012_val_00008627.bin 224 224 +17795 ./prep_dataset/ILSVRC2012_val_00021304.bin 224 224 +17796 ./prep_dataset/ILSVRC2012_val_00029483.bin 224 224 +17797 ./prep_dataset/ILSVRC2012_val_00000566.bin 224 224 +17798 ./prep_dataset/ILSVRC2012_val_00010685.bin 224 224 +17799 ./prep_dataset/ILSVRC2012_val_00044622.bin 224 224 +17800 ./prep_dataset/ILSVRC2012_val_00014328.bin 224 224 +17801 ./prep_dataset/ILSVRC2012_val_00024432.bin 224 224 +17802 ./prep_dataset/ILSVRC2012_val_00020621.bin 224 224 +17803 ./prep_dataset/ILSVRC2012_val_00031808.bin 224 224 +17804 ./prep_dataset/ILSVRC2012_val_00010659.bin 224 224 +17805 ./prep_dataset/ILSVRC2012_val_00036835.bin 224 224 +17806 ./prep_dataset/ILSVRC2012_val_00000819.bin 224 224 +17807 ./prep_dataset/ILSVRC2012_val_00027693.bin 224 224 +17808 ./prep_dataset/ILSVRC2012_val_00034437.bin 224 224 +17809 ./prep_dataset/ILSVRC2012_val_00008195.bin 224 224 +17810 ./prep_dataset/ILSVRC2012_val_00025457.bin 224 224 +17811 ./prep_dataset/ILSVRC2012_val_00007918.bin 224 224 +17812 ./prep_dataset/ILSVRC2012_val_00008361.bin 224 224 +17813 ./prep_dataset/ILSVRC2012_val_00045165.bin 224 224 +17814 ./prep_dataset/ILSVRC2012_val_00013777.bin 224 224 +17815 ./prep_dataset/ILSVRC2012_val_00025468.bin 224 224 +17816 ./prep_dataset/ILSVRC2012_val_00032115.bin 224 224 +17817 ./prep_dataset/ILSVRC2012_val_00013429.bin 224 224 +17818 ./prep_dataset/ILSVRC2012_val_00017978.bin 224 224 +17819 ./prep_dataset/ILSVRC2012_val_00012837.bin 224 224 +17820 ./prep_dataset/ILSVRC2012_val_00000649.bin 224 224 +17821 ./prep_dataset/ILSVRC2012_val_00039335.bin 224 224 +17822 ./prep_dataset/ILSVRC2012_val_00005522.bin 224 224 +17823 ./prep_dataset/ILSVRC2012_val_00008293.bin 224 224 +17824 ./prep_dataset/ILSVRC2012_val_00027397.bin 224 224 +17825 ./prep_dataset/ILSVRC2012_val_00015666.bin 224 224 +17826 ./prep_dataset/ILSVRC2012_val_00005940.bin 224 224 +17827 ./prep_dataset/ILSVRC2012_val_00016457.bin 224 224 +17828 ./prep_dataset/ILSVRC2012_val_00004291.bin 224 224 +17829 ./prep_dataset/ILSVRC2012_val_00034324.bin 224 224 +17830 ./prep_dataset/ILSVRC2012_val_00012716.bin 224 224 +17831 ./prep_dataset/ILSVRC2012_val_00023565.bin 224 224 +17832 ./prep_dataset/ILSVRC2012_val_00000402.bin 224 224 +17833 ./prep_dataset/ILSVRC2012_val_00008120.bin 224 224 +17834 ./prep_dataset/ILSVRC2012_val_00031842.bin 224 224 +17835 ./prep_dataset/ILSVRC2012_val_00049015.bin 224 224 +17836 ./prep_dataset/ILSVRC2012_val_00038910.bin 224 224 +17837 ./prep_dataset/ILSVRC2012_val_00036285.bin 224 224 +17838 ./prep_dataset/ILSVRC2012_val_00031538.bin 224 224 +17839 ./prep_dataset/ILSVRC2012_val_00010990.bin 224 224 +17840 ./prep_dataset/ILSVRC2012_val_00023265.bin 224 224 +17841 ./prep_dataset/ILSVRC2012_val_00036844.bin 224 224 +17842 ./prep_dataset/ILSVRC2012_val_00009370.bin 224 224 +17843 ./prep_dataset/ILSVRC2012_val_00044699.bin 224 224 +17844 ./prep_dataset/ILSVRC2012_val_00047286.bin 224 224 +17845 ./prep_dataset/ILSVRC2012_val_00021045.bin 224 224 +17846 ./prep_dataset/ILSVRC2012_val_00041452.bin 224 224 +17847 ./prep_dataset/ILSVRC2012_val_00031453.bin 224 224 +17848 ./prep_dataset/ILSVRC2012_val_00038945.bin 224 224 +17849 ./prep_dataset/ILSVRC2012_val_00044807.bin 224 224 +17850 ./prep_dataset/ILSVRC2012_val_00038918.bin 224 224 +17851 ./prep_dataset/ILSVRC2012_val_00008655.bin 224 224 +17852 ./prep_dataset/ILSVRC2012_val_00023429.bin 224 224 +17853 ./prep_dataset/ILSVRC2012_val_00031144.bin 224 224 +17854 ./prep_dataset/ILSVRC2012_val_00042006.bin 224 224 +17855 ./prep_dataset/ILSVRC2012_val_00036931.bin 224 224 +17856 ./prep_dataset/ILSVRC2012_val_00039051.bin 224 224 +17857 ./prep_dataset/ILSVRC2012_val_00043251.bin 224 224 +17858 ./prep_dataset/ILSVRC2012_val_00006682.bin 224 224 +17859 ./prep_dataset/ILSVRC2012_val_00035944.bin 224 224 +17860 ./prep_dataset/ILSVRC2012_val_00009472.bin 224 224 +17861 ./prep_dataset/ILSVRC2012_val_00033479.bin 224 224 +17862 ./prep_dataset/ILSVRC2012_val_00002783.bin 224 224 +17863 ./prep_dataset/ILSVRC2012_val_00041155.bin 224 224 +17864 ./prep_dataset/ILSVRC2012_val_00014184.bin 224 224 +17865 ./prep_dataset/ILSVRC2012_val_00021478.bin 224 224 +17866 ./prep_dataset/ILSVRC2012_val_00047147.bin 224 224 +17867 ./prep_dataset/ILSVRC2012_val_00010215.bin 224 224 +17868 ./prep_dataset/ILSVRC2012_val_00002074.bin 224 224 +17869 ./prep_dataset/ILSVRC2012_val_00049636.bin 224 224 +17870 ./prep_dataset/ILSVRC2012_val_00035751.bin 224 224 +17871 ./prep_dataset/ILSVRC2012_val_00026394.bin 224 224 +17872 ./prep_dataset/ILSVRC2012_val_00048633.bin 224 224 +17873 ./prep_dataset/ILSVRC2012_val_00030783.bin 224 224 +17874 ./prep_dataset/ILSVRC2012_val_00045944.bin 224 224 +17875 ./prep_dataset/ILSVRC2012_val_00044583.bin 224 224 +17876 ./prep_dataset/ILSVRC2012_val_00028314.bin 224 224 +17877 ./prep_dataset/ILSVRC2012_val_00013706.bin 224 224 +17878 ./prep_dataset/ILSVRC2012_val_00036837.bin 224 224 +17879 ./prep_dataset/ILSVRC2012_val_00029303.bin 224 224 +17880 ./prep_dataset/ILSVRC2012_val_00017258.bin 224 224 +17881 ./prep_dataset/ILSVRC2012_val_00045672.bin 224 224 +17882 ./prep_dataset/ILSVRC2012_val_00029731.bin 224 224 +17883 ./prep_dataset/ILSVRC2012_val_00018718.bin 224 224 +17884 ./prep_dataset/ILSVRC2012_val_00032683.bin 224 224 +17885 ./prep_dataset/ILSVRC2012_val_00027899.bin 224 224 +17886 ./prep_dataset/ILSVRC2012_val_00004375.bin 224 224 +17887 ./prep_dataset/ILSVRC2012_val_00004887.bin 224 224 +17888 ./prep_dataset/ILSVRC2012_val_00027195.bin 224 224 +17889 ./prep_dataset/ILSVRC2012_val_00023114.bin 224 224 +17890 ./prep_dataset/ILSVRC2012_val_00044216.bin 224 224 +17891 ./prep_dataset/ILSVRC2012_val_00025308.bin 224 224 +17892 ./prep_dataset/ILSVRC2012_val_00047723.bin 224 224 +17893 ./prep_dataset/ILSVRC2012_val_00021156.bin 224 224 +17894 ./prep_dataset/ILSVRC2012_val_00007004.bin 224 224 +17895 ./prep_dataset/ILSVRC2012_val_00021335.bin 224 224 +17896 ./prep_dataset/ILSVRC2012_val_00038125.bin 224 224 +17897 ./prep_dataset/ILSVRC2012_val_00011906.bin 224 224 +17898 ./prep_dataset/ILSVRC2012_val_00032430.bin 224 224 +17899 ./prep_dataset/ILSVRC2012_val_00041354.bin 224 224 +17900 ./prep_dataset/ILSVRC2012_val_00000935.bin 224 224 +17901 ./prep_dataset/ILSVRC2012_val_00012617.bin 224 224 +17902 ./prep_dataset/ILSVRC2012_val_00030967.bin 224 224 +17903 ./prep_dataset/ILSVRC2012_val_00012048.bin 224 224 +17904 ./prep_dataset/ILSVRC2012_val_00006528.bin 224 224 +17905 ./prep_dataset/ILSVRC2012_val_00037141.bin 224 224 +17906 ./prep_dataset/ILSVRC2012_val_00033877.bin 224 224 +17907 ./prep_dataset/ILSVRC2012_val_00008263.bin 224 224 +17908 ./prep_dataset/ILSVRC2012_val_00044430.bin 224 224 +17909 ./prep_dataset/ILSVRC2012_val_00011478.bin 224 224 +17910 ./prep_dataset/ILSVRC2012_val_00002985.bin 224 224 +17911 ./prep_dataset/ILSVRC2012_val_00014724.bin 224 224 +17912 ./prep_dataset/ILSVRC2012_val_00040068.bin 224 224 +17913 ./prep_dataset/ILSVRC2012_val_00009608.bin 224 224 +17914 ./prep_dataset/ILSVRC2012_val_00045276.bin 224 224 +17915 ./prep_dataset/ILSVRC2012_val_00034551.bin 224 224 +17916 ./prep_dataset/ILSVRC2012_val_00032606.bin 224 224 +17917 ./prep_dataset/ILSVRC2012_val_00044099.bin 224 224 +17918 ./prep_dataset/ILSVRC2012_val_00005509.bin 224 224 +17919 ./prep_dataset/ILSVRC2012_val_00044175.bin 224 224 +17920 ./prep_dataset/ILSVRC2012_val_00010483.bin 224 224 +17921 ./prep_dataset/ILSVRC2012_val_00029583.bin 224 224 +17922 ./prep_dataset/ILSVRC2012_val_00048670.bin 224 224 +17923 ./prep_dataset/ILSVRC2012_val_00009438.bin 224 224 +17924 ./prep_dataset/ILSVRC2012_val_00005768.bin 224 224 +17925 ./prep_dataset/ILSVRC2012_val_00045299.bin 224 224 +17926 ./prep_dataset/ILSVRC2012_val_00001831.bin 224 224 +17927 ./prep_dataset/ILSVRC2012_val_00044482.bin 224 224 +17928 ./prep_dataset/ILSVRC2012_val_00049690.bin 224 224 +17929 ./prep_dataset/ILSVRC2012_val_00043179.bin 224 224 +17930 ./prep_dataset/ILSVRC2012_val_00015391.bin 224 224 +17931 ./prep_dataset/ILSVRC2012_val_00048578.bin 224 224 +17932 ./prep_dataset/ILSVRC2012_val_00033570.bin 224 224 +17933 ./prep_dataset/ILSVRC2012_val_00018222.bin 224 224 +17934 ./prep_dataset/ILSVRC2012_val_00039885.bin 224 224 +17935 ./prep_dataset/ILSVRC2012_val_00038709.bin 224 224 +17936 ./prep_dataset/ILSVRC2012_val_00010948.bin 224 224 +17937 ./prep_dataset/ILSVRC2012_val_00033668.bin 224 224 +17938 ./prep_dataset/ILSVRC2012_val_00034958.bin 224 224 +17939 ./prep_dataset/ILSVRC2012_val_00041963.bin 224 224 +17940 ./prep_dataset/ILSVRC2012_val_00000853.bin 224 224 +17941 ./prep_dataset/ILSVRC2012_val_00011938.bin 224 224 +17942 ./prep_dataset/ILSVRC2012_val_00016519.bin 224 224 +17943 ./prep_dataset/ILSVRC2012_val_00038656.bin 224 224 +17944 ./prep_dataset/ILSVRC2012_val_00042207.bin 224 224 +17945 ./prep_dataset/ILSVRC2012_val_00049109.bin 224 224 +17946 ./prep_dataset/ILSVRC2012_val_00043435.bin 224 224 +17947 ./prep_dataset/ILSVRC2012_val_00002832.bin 224 224 +17948 ./prep_dataset/ILSVRC2012_val_00047139.bin 224 224 +17949 ./prep_dataset/ILSVRC2012_val_00047546.bin 224 224 +17950 ./prep_dataset/ILSVRC2012_val_00020221.bin 224 224 +17951 ./prep_dataset/ILSVRC2012_val_00000357.bin 224 224 +17952 ./prep_dataset/ILSVRC2012_val_00046447.bin 224 224 +17953 ./prep_dataset/ILSVRC2012_val_00017218.bin 224 224 +17954 ./prep_dataset/ILSVRC2012_val_00007631.bin 224 224 +17955 ./prep_dataset/ILSVRC2012_val_00041653.bin 224 224 +17956 ./prep_dataset/ILSVRC2012_val_00000033.bin 224 224 +17957 ./prep_dataset/ILSVRC2012_val_00023368.bin 224 224 +17958 ./prep_dataset/ILSVRC2012_val_00012413.bin 224 224 +17959 ./prep_dataset/ILSVRC2012_val_00004613.bin 224 224 +17960 ./prep_dataset/ILSVRC2012_val_00019679.bin 224 224 +17961 ./prep_dataset/ILSVRC2012_val_00017348.bin 224 224 +17962 ./prep_dataset/ILSVRC2012_val_00042867.bin 224 224 +17963 ./prep_dataset/ILSVRC2012_val_00038667.bin 224 224 +17964 ./prep_dataset/ILSVRC2012_val_00030286.bin 224 224 +17965 ./prep_dataset/ILSVRC2012_val_00000013.bin 224 224 +17966 ./prep_dataset/ILSVRC2012_val_00010001.bin 224 224 +17967 ./prep_dataset/ILSVRC2012_val_00014976.bin 224 224 +17968 ./prep_dataset/ILSVRC2012_val_00047523.bin 224 224 +17969 ./prep_dataset/ILSVRC2012_val_00043693.bin 224 224 +17970 ./prep_dataset/ILSVRC2012_val_00028671.bin 224 224 +17971 ./prep_dataset/ILSVRC2012_val_00047903.bin 224 224 +17972 ./prep_dataset/ILSVRC2012_val_00035334.bin 224 224 +17973 ./prep_dataset/ILSVRC2012_val_00019314.bin 224 224 +17974 ./prep_dataset/ILSVRC2012_val_00011668.bin 224 224 +17975 ./prep_dataset/ILSVRC2012_val_00013358.bin 224 224 +17976 ./prep_dataset/ILSVRC2012_val_00042926.bin 224 224 +17977 ./prep_dataset/ILSVRC2012_val_00012144.bin 224 224 +17978 ./prep_dataset/ILSVRC2012_val_00031860.bin 224 224 +17979 ./prep_dataset/ILSVRC2012_val_00010416.bin 224 224 +17980 ./prep_dataset/ILSVRC2012_val_00031114.bin 224 224 +17981 ./prep_dataset/ILSVRC2012_val_00011255.bin 224 224 +17982 ./prep_dataset/ILSVRC2012_val_00002639.bin 224 224 +17983 ./prep_dataset/ILSVRC2012_val_00014510.bin 224 224 +17984 ./prep_dataset/ILSVRC2012_val_00047285.bin 224 224 +17985 ./prep_dataset/ILSVRC2012_val_00023716.bin 224 224 +17986 ./prep_dataset/ILSVRC2012_val_00041404.bin 224 224 +17987 ./prep_dataset/ILSVRC2012_val_00029691.bin 224 224 +17988 ./prep_dataset/ILSVRC2012_val_00009700.bin 224 224 +17989 ./prep_dataset/ILSVRC2012_val_00034543.bin 224 224 +17990 ./prep_dataset/ILSVRC2012_val_00031019.bin 224 224 +17991 ./prep_dataset/ILSVRC2012_val_00039013.bin 224 224 +17992 ./prep_dataset/ILSVRC2012_val_00033404.bin 224 224 +17993 ./prep_dataset/ILSVRC2012_val_00034706.bin 224 224 +17994 ./prep_dataset/ILSVRC2012_val_00028584.bin 224 224 +17995 ./prep_dataset/ILSVRC2012_val_00039894.bin 224 224 +17996 ./prep_dataset/ILSVRC2012_val_00000172.bin 224 224 +17997 ./prep_dataset/ILSVRC2012_val_00030261.bin 224 224 +17998 ./prep_dataset/ILSVRC2012_val_00023208.bin 224 224 +17999 ./prep_dataset/ILSVRC2012_val_00033145.bin 224 224 +18000 ./prep_dataset/ILSVRC2012_val_00010457.bin 224 224 +18001 ./prep_dataset/ILSVRC2012_val_00037568.bin 224 224 +18002 ./prep_dataset/ILSVRC2012_val_00005108.bin 224 224 +18003 ./prep_dataset/ILSVRC2012_val_00017374.bin 224 224 +18004 ./prep_dataset/ILSVRC2012_val_00044700.bin 224 224 +18005 ./prep_dataset/ILSVRC2012_val_00010332.bin 224 224 +18006 ./prep_dataset/ILSVRC2012_val_00002022.bin 224 224 +18007 ./prep_dataset/ILSVRC2012_val_00008530.bin 224 224 +18008 ./prep_dataset/ILSVRC2012_val_00041444.bin 224 224 +18009 ./prep_dataset/ILSVRC2012_val_00002151.bin 224 224 +18010 ./prep_dataset/ILSVRC2012_val_00042309.bin 224 224 +18011 ./prep_dataset/ILSVRC2012_val_00017369.bin 224 224 +18012 ./prep_dataset/ILSVRC2012_val_00039283.bin 224 224 +18013 ./prep_dataset/ILSVRC2012_val_00038871.bin 224 224 +18014 ./prep_dataset/ILSVRC2012_val_00045395.bin 224 224 +18015 ./prep_dataset/ILSVRC2012_val_00013489.bin 224 224 +18016 ./prep_dataset/ILSVRC2012_val_00040766.bin 224 224 +18017 ./prep_dataset/ILSVRC2012_val_00043472.bin 224 224 +18018 ./prep_dataset/ILSVRC2012_val_00049413.bin 224 224 +18019 ./prep_dataset/ILSVRC2012_val_00040937.bin 224 224 +18020 ./prep_dataset/ILSVRC2012_val_00004600.bin 224 224 +18021 ./prep_dataset/ILSVRC2012_val_00041576.bin 224 224 +18022 ./prep_dataset/ILSVRC2012_val_00015325.bin 224 224 +18023 ./prep_dataset/ILSVRC2012_val_00023636.bin 224 224 +18024 ./prep_dataset/ILSVRC2012_val_00011399.bin 224 224 +18025 ./prep_dataset/ILSVRC2012_val_00043586.bin 224 224 +18026 ./prep_dataset/ILSVRC2012_val_00040129.bin 224 224 +18027 ./prep_dataset/ILSVRC2012_val_00031383.bin 224 224 +18028 ./prep_dataset/ILSVRC2012_val_00014905.bin 224 224 +18029 ./prep_dataset/ILSVRC2012_val_00032315.bin 224 224 +18030 ./prep_dataset/ILSVRC2012_val_00008993.bin 224 224 +18031 ./prep_dataset/ILSVRC2012_val_00044115.bin 224 224 +18032 ./prep_dataset/ILSVRC2012_val_00030892.bin 224 224 +18033 ./prep_dataset/ILSVRC2012_val_00029387.bin 224 224 +18034 ./prep_dataset/ILSVRC2012_val_00005437.bin 224 224 +18035 ./prep_dataset/ILSVRC2012_val_00016128.bin 224 224 +18036 ./prep_dataset/ILSVRC2012_val_00011476.bin 224 224 +18037 ./prep_dataset/ILSVRC2012_val_00035919.bin 224 224 +18038 ./prep_dataset/ILSVRC2012_val_00027791.bin 224 224 +18039 ./prep_dataset/ILSVRC2012_val_00045788.bin 224 224 +18040 ./prep_dataset/ILSVRC2012_val_00017222.bin 224 224 +18041 ./prep_dataset/ILSVRC2012_val_00023312.bin 224 224 +18042 ./prep_dataset/ILSVRC2012_val_00012296.bin 224 224 +18043 ./prep_dataset/ILSVRC2012_val_00038449.bin 224 224 +18044 ./prep_dataset/ILSVRC2012_val_00033321.bin 224 224 +18045 ./prep_dataset/ILSVRC2012_val_00020736.bin 224 224 +18046 ./prep_dataset/ILSVRC2012_val_00026449.bin 224 224 +18047 ./prep_dataset/ILSVRC2012_val_00033873.bin 224 224 +18048 ./prep_dataset/ILSVRC2012_val_00022705.bin 224 224 +18049 ./prep_dataset/ILSVRC2012_val_00045931.bin 224 224 +18050 ./prep_dataset/ILSVRC2012_val_00010222.bin 224 224 +18051 ./prep_dataset/ILSVRC2012_val_00015818.bin 224 224 +18052 ./prep_dataset/ILSVRC2012_val_00035319.bin 224 224 +18053 ./prep_dataset/ILSVRC2012_val_00030390.bin 224 224 +18054 ./prep_dataset/ILSVRC2012_val_00012332.bin 224 224 +18055 ./prep_dataset/ILSVRC2012_val_00037083.bin 224 224 +18056 ./prep_dataset/ILSVRC2012_val_00047433.bin 224 224 +18057 ./prep_dataset/ILSVRC2012_val_00040722.bin 224 224 +18058 ./prep_dataset/ILSVRC2012_val_00046994.bin 224 224 +18059 ./prep_dataset/ILSVRC2012_val_00030431.bin 224 224 +18060 ./prep_dataset/ILSVRC2012_val_00043854.bin 224 224 +18061 ./prep_dataset/ILSVRC2012_val_00015063.bin 224 224 +18062 ./prep_dataset/ILSVRC2012_val_00041133.bin 224 224 +18063 ./prep_dataset/ILSVRC2012_val_00014583.bin 224 224 +18064 ./prep_dataset/ILSVRC2012_val_00008379.bin 224 224 +18065 ./prep_dataset/ILSVRC2012_val_00029313.bin 224 224 +18066 ./prep_dataset/ILSVRC2012_val_00012291.bin 224 224 +18067 ./prep_dataset/ILSVRC2012_val_00002360.bin 224 224 +18068 ./prep_dataset/ILSVRC2012_val_00025837.bin 224 224 +18069 ./prep_dataset/ILSVRC2012_val_00002837.bin 224 224 +18070 ./prep_dataset/ILSVRC2012_val_00003344.bin 224 224 +18071 ./prep_dataset/ILSVRC2012_val_00019069.bin 224 224 +18072 ./prep_dataset/ILSVRC2012_val_00038942.bin 224 224 +18073 ./prep_dataset/ILSVRC2012_val_00017922.bin 224 224 +18074 ./prep_dataset/ILSVRC2012_val_00033059.bin 224 224 +18075 ./prep_dataset/ILSVRC2012_val_00021157.bin 224 224 +18076 ./prep_dataset/ILSVRC2012_val_00045190.bin 224 224 +18077 ./prep_dataset/ILSVRC2012_val_00014048.bin 224 224 +18078 ./prep_dataset/ILSVRC2012_val_00030549.bin 224 224 +18079 ./prep_dataset/ILSVRC2012_val_00032048.bin 224 224 +18080 ./prep_dataset/ILSVRC2012_val_00018907.bin 224 224 +18081 ./prep_dataset/ILSVRC2012_val_00031747.bin 224 224 +18082 ./prep_dataset/ILSVRC2012_val_00016851.bin 224 224 +18083 ./prep_dataset/ILSVRC2012_val_00003975.bin 224 224 +18084 ./prep_dataset/ILSVRC2012_val_00021458.bin 224 224 +18085 ./prep_dataset/ILSVRC2012_val_00047358.bin 224 224 +18086 ./prep_dataset/ILSVRC2012_val_00032035.bin 224 224 +18087 ./prep_dataset/ILSVRC2012_val_00046334.bin 224 224 +18088 ./prep_dataset/ILSVRC2012_val_00024605.bin 224 224 +18089 ./prep_dataset/ILSVRC2012_val_00007723.bin 224 224 +18090 ./prep_dataset/ILSVRC2012_val_00033600.bin 224 224 +18091 ./prep_dataset/ILSVRC2012_val_00024791.bin 224 224 +18092 ./prep_dataset/ILSVRC2012_val_00017269.bin 224 224 +18093 ./prep_dataset/ILSVRC2012_val_00007474.bin 224 224 +18094 ./prep_dataset/ILSVRC2012_val_00043844.bin 224 224 +18095 ./prep_dataset/ILSVRC2012_val_00049344.bin 224 224 +18096 ./prep_dataset/ILSVRC2012_val_00044000.bin 224 224 +18097 ./prep_dataset/ILSVRC2012_val_00001249.bin 224 224 +18098 ./prep_dataset/ILSVRC2012_val_00042736.bin 224 224 +18099 ./prep_dataset/ILSVRC2012_val_00047105.bin 224 224 +18100 ./prep_dataset/ILSVRC2012_val_00024711.bin 224 224 +18101 ./prep_dataset/ILSVRC2012_val_00022956.bin 224 224 +18102 ./prep_dataset/ILSVRC2012_val_00009951.bin 224 224 +18103 ./prep_dataset/ILSVRC2012_val_00028682.bin 224 224 +18104 ./prep_dataset/ILSVRC2012_val_00044431.bin 224 224 +18105 ./prep_dataset/ILSVRC2012_val_00041523.bin 224 224 +18106 ./prep_dataset/ILSVRC2012_val_00009502.bin 224 224 +18107 ./prep_dataset/ILSVRC2012_val_00029318.bin 224 224 +18108 ./prep_dataset/ILSVRC2012_val_00021533.bin 224 224 +18109 ./prep_dataset/ILSVRC2012_val_00029157.bin 224 224 +18110 ./prep_dataset/ILSVRC2012_val_00038380.bin 224 224 +18111 ./prep_dataset/ILSVRC2012_val_00019558.bin 224 224 +18112 ./prep_dataset/ILSVRC2012_val_00005148.bin 224 224 +18113 ./prep_dataset/ILSVRC2012_val_00020229.bin 224 224 +18114 ./prep_dataset/ILSVRC2012_val_00014740.bin 224 224 +18115 ./prep_dataset/ILSVRC2012_val_00039573.bin 224 224 +18116 ./prep_dataset/ILSVRC2012_val_00040197.bin 224 224 +18117 ./prep_dataset/ILSVRC2012_val_00040899.bin 224 224 +18118 ./prep_dataset/ILSVRC2012_val_00047404.bin 224 224 +18119 ./prep_dataset/ILSVRC2012_val_00018539.bin 224 224 +18120 ./prep_dataset/ILSVRC2012_val_00044951.bin 224 224 +18121 ./prep_dataset/ILSVRC2012_val_00017566.bin 224 224 +18122 ./prep_dataset/ILSVRC2012_val_00001019.bin 224 224 +18123 ./prep_dataset/ILSVRC2012_val_00040269.bin 224 224 +18124 ./prep_dataset/ILSVRC2012_val_00013712.bin 224 224 +18125 ./prep_dataset/ILSVRC2012_val_00018769.bin 224 224 +18126 ./prep_dataset/ILSVRC2012_val_00028159.bin 224 224 +18127 ./prep_dataset/ILSVRC2012_val_00037606.bin 224 224 +18128 ./prep_dataset/ILSVRC2012_val_00035436.bin 224 224 +18129 ./prep_dataset/ILSVRC2012_val_00040179.bin 224 224 +18130 ./prep_dataset/ILSVRC2012_val_00013999.bin 224 224 +18131 ./prep_dataset/ILSVRC2012_val_00002081.bin 224 224 +18132 ./prep_dataset/ILSVRC2012_val_00036047.bin 224 224 +18133 ./prep_dataset/ILSVRC2012_val_00014514.bin 224 224 +18134 ./prep_dataset/ILSVRC2012_val_00024091.bin 224 224 +18135 ./prep_dataset/ILSVRC2012_val_00025953.bin 224 224 +18136 ./prep_dataset/ILSVRC2012_val_00018877.bin 224 224 +18137 ./prep_dataset/ILSVRC2012_val_00038212.bin 224 224 +18138 ./prep_dataset/ILSVRC2012_val_00007639.bin 224 224 +18139 ./prep_dataset/ILSVRC2012_val_00035941.bin 224 224 +18140 ./prep_dataset/ILSVRC2012_val_00021347.bin 224 224 +18141 ./prep_dataset/ILSVRC2012_val_00031236.bin 224 224 +18142 ./prep_dataset/ILSVRC2012_val_00007902.bin 224 224 +18143 ./prep_dataset/ILSVRC2012_val_00049889.bin 224 224 +18144 ./prep_dataset/ILSVRC2012_val_00016374.bin 224 224 +18145 ./prep_dataset/ILSVRC2012_val_00045758.bin 224 224 +18146 ./prep_dataset/ILSVRC2012_val_00044071.bin 224 224 +18147 ./prep_dataset/ILSVRC2012_val_00021430.bin 224 224 +18148 ./prep_dataset/ILSVRC2012_val_00012428.bin 224 224 +18149 ./prep_dataset/ILSVRC2012_val_00011270.bin 224 224 +18150 ./prep_dataset/ILSVRC2012_val_00044694.bin 224 224 +18151 ./prep_dataset/ILSVRC2012_val_00035663.bin 224 224 +18152 ./prep_dataset/ILSVRC2012_val_00017984.bin 224 224 +18153 ./prep_dataset/ILSVRC2012_val_00002305.bin 224 224 +18154 ./prep_dataset/ILSVRC2012_val_00012804.bin 224 224 +18155 ./prep_dataset/ILSVRC2012_val_00010121.bin 224 224 +18156 ./prep_dataset/ILSVRC2012_val_00011706.bin 224 224 +18157 ./prep_dataset/ILSVRC2012_val_00005616.bin 224 224 +18158 ./prep_dataset/ILSVRC2012_val_00045061.bin 224 224 +18159 ./prep_dataset/ILSVRC2012_val_00045777.bin 224 224 +18160 ./prep_dataset/ILSVRC2012_val_00018177.bin 224 224 +18161 ./prep_dataset/ILSVRC2012_val_00026694.bin 224 224 +18162 ./prep_dataset/ILSVRC2012_val_00024804.bin 224 224 +18163 ./prep_dataset/ILSVRC2012_val_00023740.bin 224 224 +18164 ./prep_dataset/ILSVRC2012_val_00012520.bin 224 224 +18165 ./prep_dataset/ILSVRC2012_val_00045089.bin 224 224 +18166 ./prep_dataset/ILSVRC2012_val_00024515.bin 224 224 +18167 ./prep_dataset/ILSVRC2012_val_00011555.bin 224 224 +18168 ./prep_dataset/ILSVRC2012_val_00048576.bin 224 224 +18169 ./prep_dataset/ILSVRC2012_val_00010573.bin 224 224 +18170 ./prep_dataset/ILSVRC2012_val_00048635.bin 224 224 +18171 ./prep_dataset/ILSVRC2012_val_00003135.bin 224 224 +18172 ./prep_dataset/ILSVRC2012_val_00048809.bin 224 224 +18173 ./prep_dataset/ILSVRC2012_val_00043087.bin 224 224 +18174 ./prep_dataset/ILSVRC2012_val_00044941.bin 224 224 +18175 ./prep_dataset/ILSVRC2012_val_00036319.bin 224 224 +18176 ./prep_dataset/ILSVRC2012_val_00027605.bin 224 224 +18177 ./prep_dataset/ILSVRC2012_val_00045685.bin 224 224 +18178 ./prep_dataset/ILSVRC2012_val_00017098.bin 224 224 +18179 ./prep_dataset/ILSVRC2012_val_00020321.bin 224 224 +18180 ./prep_dataset/ILSVRC2012_val_00036305.bin 224 224 +18181 ./prep_dataset/ILSVRC2012_val_00001328.bin 224 224 +18182 ./prep_dataset/ILSVRC2012_val_00038711.bin 224 224 +18183 ./prep_dataset/ILSVRC2012_val_00039812.bin 224 224 +18184 ./prep_dataset/ILSVRC2012_val_00013206.bin 224 224 +18185 ./prep_dataset/ILSVRC2012_val_00042189.bin 224 224 +18186 ./prep_dataset/ILSVRC2012_val_00036383.bin 224 224 +18187 ./prep_dataset/ILSVRC2012_val_00011614.bin 224 224 +18188 ./prep_dataset/ILSVRC2012_val_00045699.bin 224 224 +18189 ./prep_dataset/ILSVRC2012_val_00025554.bin 224 224 +18190 ./prep_dataset/ILSVRC2012_val_00044213.bin 224 224 +18191 ./prep_dataset/ILSVRC2012_val_00003469.bin 224 224 +18192 ./prep_dataset/ILSVRC2012_val_00014025.bin 224 224 +18193 ./prep_dataset/ILSVRC2012_val_00001497.bin 224 224 +18194 ./prep_dataset/ILSVRC2012_val_00041555.bin 224 224 +18195 ./prep_dataset/ILSVRC2012_val_00043107.bin 224 224 +18196 ./prep_dataset/ILSVRC2012_val_00041242.bin 224 224 +18197 ./prep_dataset/ILSVRC2012_val_00007291.bin 224 224 +18198 ./prep_dataset/ILSVRC2012_val_00006399.bin 224 224 +18199 ./prep_dataset/ILSVRC2012_val_00008328.bin 224 224 +18200 ./prep_dataset/ILSVRC2012_val_00013661.bin 224 224 +18201 ./prep_dataset/ILSVRC2012_val_00035468.bin 224 224 +18202 ./prep_dataset/ILSVRC2012_val_00039295.bin 224 224 +18203 ./prep_dataset/ILSVRC2012_val_00038659.bin 224 224 +18204 ./prep_dataset/ILSVRC2012_val_00030848.bin 224 224 +18205 ./prep_dataset/ILSVRC2012_val_00007520.bin 224 224 +18206 ./prep_dataset/ILSVRC2012_val_00007347.bin 224 224 +18207 ./prep_dataset/ILSVRC2012_val_00015340.bin 224 224 +18208 ./prep_dataset/ILSVRC2012_val_00018071.bin 224 224 +18209 ./prep_dataset/ILSVRC2012_val_00045000.bin 224 224 +18210 ./prep_dataset/ILSVRC2012_val_00010959.bin 224 224 +18211 ./prep_dataset/ILSVRC2012_val_00045054.bin 224 224 +18212 ./prep_dataset/ILSVRC2012_val_00034296.bin 224 224 +18213 ./prep_dataset/ILSVRC2012_val_00022988.bin 224 224 +18214 ./prep_dataset/ILSVRC2012_val_00031751.bin 224 224 +18215 ./prep_dataset/ILSVRC2012_val_00038919.bin 224 224 +18216 ./prep_dataset/ILSVRC2012_val_00025836.bin 224 224 +18217 ./prep_dataset/ILSVRC2012_val_00021912.bin 224 224 +18218 ./prep_dataset/ILSVRC2012_val_00046500.bin 224 224 +18219 ./prep_dataset/ILSVRC2012_val_00030340.bin 224 224 +18220 ./prep_dataset/ILSVRC2012_val_00004661.bin 224 224 +18221 ./prep_dataset/ILSVRC2012_val_00036250.bin 224 224 +18222 ./prep_dataset/ILSVRC2012_val_00025672.bin 224 224 +18223 ./prep_dataset/ILSVRC2012_val_00026599.bin 224 224 +18224 ./prep_dataset/ILSVRC2012_val_00018964.bin 224 224 +18225 ./prep_dataset/ILSVRC2012_val_00038892.bin 224 224 +18226 ./prep_dataset/ILSVRC2012_val_00027114.bin 224 224 +18227 ./prep_dataset/ILSVRC2012_val_00000078.bin 224 224 +18228 ./prep_dataset/ILSVRC2012_val_00040039.bin 224 224 +18229 ./prep_dataset/ILSVRC2012_val_00032145.bin 224 224 +18230 ./prep_dataset/ILSVRC2012_val_00010201.bin 224 224 +18231 ./prep_dataset/ILSVRC2012_val_00009435.bin 224 224 +18232 ./prep_dataset/ILSVRC2012_val_00013789.bin 224 224 +18233 ./prep_dataset/ILSVRC2012_val_00042028.bin 224 224 +18234 ./prep_dataset/ILSVRC2012_val_00042072.bin 224 224 +18235 ./prep_dataset/ILSVRC2012_val_00025182.bin 224 224 +18236 ./prep_dataset/ILSVRC2012_val_00034186.bin 224 224 +18237 ./prep_dataset/ILSVRC2012_val_00024002.bin 224 224 +18238 ./prep_dataset/ILSVRC2012_val_00007751.bin 224 224 +18239 ./prep_dataset/ILSVRC2012_val_00022866.bin 224 224 +18240 ./prep_dataset/ILSVRC2012_val_00021672.bin 224 224 +18241 ./prep_dataset/ILSVRC2012_val_00043118.bin 224 224 +18242 ./prep_dataset/ILSVRC2012_val_00049729.bin 224 224 +18243 ./prep_dataset/ILSVRC2012_val_00048816.bin 224 224 +18244 ./prep_dataset/ILSVRC2012_val_00035793.bin 224 224 +18245 ./prep_dataset/ILSVRC2012_val_00021316.bin 224 224 +18246 ./prep_dataset/ILSVRC2012_val_00034308.bin 224 224 +18247 ./prep_dataset/ILSVRC2012_val_00005189.bin 224 224 +18248 ./prep_dataset/ILSVRC2012_val_00009488.bin 224 224 +18249 ./prep_dataset/ILSVRC2012_val_00015671.bin 224 224 +18250 ./prep_dataset/ILSVRC2012_val_00030794.bin 224 224 +18251 ./prep_dataset/ILSVRC2012_val_00013768.bin 224 224 +18252 ./prep_dataset/ILSVRC2012_val_00048787.bin 224 224 +18253 ./prep_dataset/ILSVRC2012_val_00037856.bin 224 224 +18254 ./prep_dataset/ILSVRC2012_val_00018140.bin 224 224 +18255 ./prep_dataset/ILSVRC2012_val_00028467.bin 224 224 +18256 ./prep_dataset/ILSVRC2012_val_00001279.bin 224 224 +18257 ./prep_dataset/ILSVRC2012_val_00017562.bin 224 224 +18258 ./prep_dataset/ILSVRC2012_val_00039428.bin 224 224 +18259 ./prep_dataset/ILSVRC2012_val_00008150.bin 224 224 +18260 ./prep_dataset/ILSVRC2012_val_00026957.bin 224 224 +18261 ./prep_dataset/ILSVRC2012_val_00023966.bin 224 224 +18262 ./prep_dataset/ILSVRC2012_val_00008726.bin 224 224 +18263 ./prep_dataset/ILSVRC2012_val_00023284.bin 224 224 +18264 ./prep_dataset/ILSVRC2012_val_00022353.bin 224 224 +18265 ./prep_dataset/ILSVRC2012_val_00014481.bin 224 224 +18266 ./prep_dataset/ILSVRC2012_val_00035501.bin 224 224 +18267 ./prep_dataset/ILSVRC2012_val_00027738.bin 224 224 +18268 ./prep_dataset/ILSVRC2012_val_00010601.bin 224 224 +18269 ./prep_dataset/ILSVRC2012_val_00027818.bin 224 224 +18270 ./prep_dataset/ILSVRC2012_val_00015616.bin 224 224 +18271 ./prep_dataset/ILSVRC2012_val_00004790.bin 224 224 +18272 ./prep_dataset/ILSVRC2012_val_00007724.bin 224 224 +18273 ./prep_dataset/ILSVRC2012_val_00007986.bin 224 224 +18274 ./prep_dataset/ILSVRC2012_val_00036414.bin 224 224 +18275 ./prep_dataset/ILSVRC2012_val_00020981.bin 224 224 +18276 ./prep_dataset/ILSVRC2012_val_00000222.bin 224 224 +18277 ./prep_dataset/ILSVRC2012_val_00042210.bin 224 224 +18278 ./prep_dataset/ILSVRC2012_val_00003530.bin 224 224 +18279 ./prep_dataset/ILSVRC2012_val_00003397.bin 224 224 +18280 ./prep_dataset/ILSVRC2012_val_00020450.bin 224 224 +18281 ./prep_dataset/ILSVRC2012_val_00029519.bin 224 224 +18282 ./prep_dataset/ILSVRC2012_val_00014552.bin 224 224 +18283 ./prep_dataset/ILSVRC2012_val_00038777.bin 224 224 +18284 ./prep_dataset/ILSVRC2012_val_00035519.bin 224 224 +18285 ./prep_dataset/ILSVRC2012_val_00046380.bin 224 224 +18286 ./prep_dataset/ILSVRC2012_val_00043565.bin 224 224 +18287 ./prep_dataset/ILSVRC2012_val_00034310.bin 224 224 +18288 ./prep_dataset/ILSVRC2012_val_00039862.bin 224 224 +18289 ./prep_dataset/ILSVRC2012_val_00031252.bin 224 224 +18290 ./prep_dataset/ILSVRC2012_val_00004281.bin 224 224 +18291 ./prep_dataset/ILSVRC2012_val_00038720.bin 224 224 +18292 ./prep_dataset/ILSVRC2012_val_00008371.bin 224 224 +18293 ./prep_dataset/ILSVRC2012_val_00025373.bin 224 224 +18294 ./prep_dataset/ILSVRC2012_val_00044696.bin 224 224 +18295 ./prep_dataset/ILSVRC2012_val_00019547.bin 224 224 +18296 ./prep_dataset/ILSVRC2012_val_00014503.bin 224 224 +18297 ./prep_dataset/ILSVRC2012_val_00049505.bin 224 224 +18298 ./prep_dataset/ILSVRC2012_val_00038158.bin 224 224 +18299 ./prep_dataset/ILSVRC2012_val_00044933.bin 224 224 +18300 ./prep_dataset/ILSVRC2012_val_00035392.bin 224 224 +18301 ./prep_dataset/ILSVRC2012_val_00029323.bin 224 224 +18302 ./prep_dataset/ILSVRC2012_val_00031533.bin 224 224 +18303 ./prep_dataset/ILSVRC2012_val_00022862.bin 224 224 +18304 ./prep_dataset/ILSVRC2012_val_00025816.bin 224 224 +18305 ./prep_dataset/ILSVRC2012_val_00011018.bin 224 224 +18306 ./prep_dataset/ILSVRC2012_val_00028872.bin 224 224 +18307 ./prep_dataset/ILSVRC2012_val_00032360.bin 224 224 +18308 ./prep_dataset/ILSVRC2012_val_00047858.bin 224 224 +18309 ./prep_dataset/ILSVRC2012_val_00029177.bin 224 224 +18310 ./prep_dataset/ILSVRC2012_val_00004877.bin 224 224 +18311 ./prep_dataset/ILSVRC2012_val_00048774.bin 224 224 +18312 ./prep_dataset/ILSVRC2012_val_00012465.bin 224 224 +18313 ./prep_dataset/ILSVRC2012_val_00007981.bin 224 224 +18314 ./prep_dataset/ILSVRC2012_val_00000302.bin 224 224 +18315 ./prep_dataset/ILSVRC2012_val_00042475.bin 224 224 +18316 ./prep_dataset/ILSVRC2012_val_00027661.bin 224 224 +18317 ./prep_dataset/ILSVRC2012_val_00016686.bin 224 224 +18318 ./prep_dataset/ILSVRC2012_val_00024539.bin 224 224 +18319 ./prep_dataset/ILSVRC2012_val_00027935.bin 224 224 +18320 ./prep_dataset/ILSVRC2012_val_00019393.bin 224 224 +18321 ./prep_dataset/ILSVRC2012_val_00046106.bin 224 224 +18322 ./prep_dataset/ILSVRC2012_val_00034735.bin 224 224 +18323 ./prep_dataset/ILSVRC2012_val_00042814.bin 224 224 +18324 ./prep_dataset/ILSVRC2012_val_00034528.bin 224 224 +18325 ./prep_dataset/ILSVRC2012_val_00031907.bin 224 224 +18326 ./prep_dataset/ILSVRC2012_val_00030875.bin 224 224 +18327 ./prep_dataset/ILSVRC2012_val_00025292.bin 224 224 +18328 ./prep_dataset/ILSVRC2012_val_00033842.bin 224 224 +18329 ./prep_dataset/ILSVRC2012_val_00002943.bin 224 224 +18330 ./prep_dataset/ILSVRC2012_val_00004045.bin 224 224 +18331 ./prep_dataset/ILSVRC2012_val_00025986.bin 224 224 +18332 ./prep_dataset/ILSVRC2012_val_00001880.bin 224 224 +18333 ./prep_dataset/ILSVRC2012_val_00011048.bin 224 224 +18334 ./prep_dataset/ILSVRC2012_val_00043757.bin 224 224 +18335 ./prep_dataset/ILSVRC2012_val_00030073.bin 224 224 +18336 ./prep_dataset/ILSVRC2012_val_00040689.bin 224 224 +18337 ./prep_dataset/ILSVRC2012_val_00048574.bin 224 224 +18338 ./prep_dataset/ILSVRC2012_val_00048108.bin 224 224 +18339 ./prep_dataset/ILSVRC2012_val_00043768.bin 224 224 +18340 ./prep_dataset/ILSVRC2012_val_00003756.bin 224 224 +18341 ./prep_dataset/ILSVRC2012_val_00046152.bin 224 224 +18342 ./prep_dataset/ILSVRC2012_val_00005223.bin 224 224 +18343 ./prep_dataset/ILSVRC2012_val_00027582.bin 224 224 +18344 ./prep_dataset/ILSVRC2012_val_00023037.bin 224 224 +18345 ./prep_dataset/ILSVRC2012_val_00024009.bin 224 224 +18346 ./prep_dataset/ILSVRC2012_val_00020724.bin 224 224 +18347 ./prep_dataset/ILSVRC2012_val_00045397.bin 224 224 +18348 ./prep_dataset/ILSVRC2012_val_00047318.bin 224 224 +18349 ./prep_dataset/ILSVRC2012_val_00032241.bin 224 224 +18350 ./prep_dataset/ILSVRC2012_val_00036597.bin 224 224 +18351 ./prep_dataset/ILSVRC2012_val_00017535.bin 224 224 +18352 ./prep_dataset/ILSVRC2012_val_00006388.bin 224 224 +18353 ./prep_dataset/ILSVRC2012_val_00022572.bin 224 224 +18354 ./prep_dataset/ILSVRC2012_val_00009073.bin 224 224 +18355 ./prep_dataset/ILSVRC2012_val_00034616.bin 224 224 +18356 ./prep_dataset/ILSVRC2012_val_00028730.bin 224 224 +18357 ./prep_dataset/ILSVRC2012_val_00040038.bin 224 224 +18358 ./prep_dataset/ILSVRC2012_val_00020020.bin 224 224 +18359 ./prep_dataset/ILSVRC2012_val_00027752.bin 224 224 +18360 ./prep_dataset/ILSVRC2012_val_00021822.bin 224 224 +18361 ./prep_dataset/ILSVRC2012_val_00034623.bin 224 224 +18362 ./prep_dataset/ILSVRC2012_val_00042040.bin 224 224 +18363 ./prep_dataset/ILSVRC2012_val_00027725.bin 224 224 +18364 ./prep_dataset/ILSVRC2012_val_00024987.bin 224 224 +18365 ./prep_dataset/ILSVRC2012_val_00022400.bin 224 224 +18366 ./prep_dataset/ILSVRC2012_val_00006928.bin 224 224 +18367 ./prep_dataset/ILSVRC2012_val_00023273.bin 224 224 +18368 ./prep_dataset/ILSVRC2012_val_00003759.bin 224 224 +18369 ./prep_dataset/ILSVRC2012_val_00010087.bin 224 224 +18370 ./prep_dataset/ILSVRC2012_val_00036038.bin 224 224 +18371 ./prep_dataset/ILSVRC2012_val_00004277.bin 224 224 +18372 ./prep_dataset/ILSVRC2012_val_00033559.bin 224 224 +18373 ./prep_dataset/ILSVRC2012_val_00038893.bin 224 224 +18374 ./prep_dataset/ILSVRC2012_val_00013994.bin 224 224 +18375 ./prep_dataset/ILSVRC2012_val_00022416.bin 224 224 +18376 ./prep_dataset/ILSVRC2012_val_00006552.bin 224 224 +18377 ./prep_dataset/ILSVRC2012_val_00039960.bin 224 224 +18378 ./prep_dataset/ILSVRC2012_val_00001515.bin 224 224 +18379 ./prep_dataset/ILSVRC2012_val_00014870.bin 224 224 +18380 ./prep_dataset/ILSVRC2012_val_00034602.bin 224 224 +18381 ./prep_dataset/ILSVRC2012_val_00036447.bin 224 224 +18382 ./prep_dataset/ILSVRC2012_val_00002911.bin 224 224 +18383 ./prep_dataset/ILSVRC2012_val_00007673.bin 224 224 +18384 ./prep_dataset/ILSVRC2012_val_00014455.bin 224 224 +18385 ./prep_dataset/ILSVRC2012_val_00020603.bin 224 224 +18386 ./prep_dataset/ILSVRC2012_val_00017935.bin 224 224 +18387 ./prep_dataset/ILSVRC2012_val_00033619.bin 224 224 +18388 ./prep_dataset/ILSVRC2012_val_00021562.bin 224 224 +18389 ./prep_dataset/ILSVRC2012_val_00036802.bin 224 224 +18390 ./prep_dataset/ILSVRC2012_val_00043719.bin 224 224 +18391 ./prep_dataset/ILSVRC2012_val_00030706.bin 224 224 +18392 ./prep_dataset/ILSVRC2012_val_00026974.bin 224 224 +18393 ./prep_dataset/ILSVRC2012_val_00042648.bin 224 224 +18394 ./prep_dataset/ILSVRC2012_val_00043519.bin 224 224 +18395 ./prep_dataset/ILSVRC2012_val_00042947.bin 224 224 +18396 ./prep_dataset/ILSVRC2012_val_00026501.bin 224 224 +18397 ./prep_dataset/ILSVRC2012_val_00023466.bin 224 224 +18398 ./prep_dataset/ILSVRC2012_val_00032482.bin 224 224 +18399 ./prep_dataset/ILSVRC2012_val_00048019.bin 224 224 +18400 ./prep_dataset/ILSVRC2012_val_00008014.bin 224 224 +18401 ./prep_dataset/ILSVRC2012_val_00035548.bin 224 224 +18402 ./prep_dataset/ILSVRC2012_val_00031900.bin 224 224 +18403 ./prep_dataset/ILSVRC2012_val_00025809.bin 224 224 +18404 ./prep_dataset/ILSVRC2012_val_00009959.bin 224 224 +18405 ./prep_dataset/ILSVRC2012_val_00037209.bin 224 224 +18406 ./prep_dataset/ILSVRC2012_val_00024445.bin 224 224 +18407 ./prep_dataset/ILSVRC2012_val_00033269.bin 224 224 +18408 ./prep_dataset/ILSVRC2012_val_00002896.bin 224 224 +18409 ./prep_dataset/ILSVRC2012_val_00026875.bin 224 224 +18410 ./prep_dataset/ILSVRC2012_val_00026295.bin 224 224 +18411 ./prep_dataset/ILSVRC2012_val_00024860.bin 224 224 +18412 ./prep_dataset/ILSVRC2012_val_00039808.bin 224 224 +18413 ./prep_dataset/ILSVRC2012_val_00029654.bin 224 224 +18414 ./prep_dataset/ILSVRC2012_val_00032761.bin 224 224 +18415 ./prep_dataset/ILSVRC2012_val_00026279.bin 224 224 +18416 ./prep_dataset/ILSVRC2012_val_00047184.bin 224 224 +18417 ./prep_dataset/ILSVRC2012_val_00007452.bin 224 224 +18418 ./prep_dataset/ILSVRC2012_val_00031810.bin 224 224 +18419 ./prep_dataset/ILSVRC2012_val_00000795.bin 224 224 +18420 ./prep_dataset/ILSVRC2012_val_00047897.bin 224 224 +18421 ./prep_dataset/ILSVRC2012_val_00026751.bin 224 224 +18422 ./prep_dataset/ILSVRC2012_val_00022797.bin 224 224 +18423 ./prep_dataset/ILSVRC2012_val_00005342.bin 224 224 +18424 ./prep_dataset/ILSVRC2012_val_00042541.bin 224 224 +18425 ./prep_dataset/ILSVRC2012_val_00031068.bin 224 224 +18426 ./prep_dataset/ILSVRC2012_val_00021940.bin 224 224 +18427 ./prep_dataset/ILSVRC2012_val_00039260.bin 224 224 +18428 ./prep_dataset/ILSVRC2012_val_00016665.bin 224 224 +18429 ./prep_dataset/ILSVRC2012_val_00049696.bin 224 224 +18430 ./prep_dataset/ILSVRC2012_val_00008126.bin 224 224 +18431 ./prep_dataset/ILSVRC2012_val_00013399.bin 224 224 +18432 ./prep_dataset/ILSVRC2012_val_00021780.bin 224 224 +18433 ./prep_dataset/ILSVRC2012_val_00023326.bin 224 224 +18434 ./prep_dataset/ILSVRC2012_val_00048201.bin 224 224 +18435 ./prep_dataset/ILSVRC2012_val_00024849.bin 224 224 +18436 ./prep_dataset/ILSVRC2012_val_00018640.bin 224 224 +18437 ./prep_dataset/ILSVRC2012_val_00009173.bin 224 224 +18438 ./prep_dataset/ILSVRC2012_val_00009058.bin 224 224 +18439 ./prep_dataset/ILSVRC2012_val_00024392.bin 224 224 +18440 ./prep_dataset/ILSVRC2012_val_00046918.bin 224 224 +18441 ./prep_dataset/ILSVRC2012_val_00001699.bin 224 224 +18442 ./prep_dataset/ILSVRC2012_val_00017217.bin 224 224 +18443 ./prep_dataset/ILSVRC2012_val_00016711.bin 224 224 +18444 ./prep_dataset/ILSVRC2012_val_00005087.bin 224 224 +18445 ./prep_dataset/ILSVRC2012_val_00041561.bin 224 224 +18446 ./prep_dataset/ILSVRC2012_val_00005630.bin 224 224 +18447 ./prep_dataset/ILSVRC2012_val_00029140.bin 224 224 +18448 ./prep_dataset/ILSVRC2012_val_00015515.bin 224 224 +18449 ./prep_dataset/ILSVRC2012_val_00031772.bin 224 224 +18450 ./prep_dataset/ILSVRC2012_val_00012870.bin 224 224 +18451 ./prep_dataset/ILSVRC2012_val_00006116.bin 224 224 +18452 ./prep_dataset/ILSVRC2012_val_00005374.bin 224 224 +18453 ./prep_dataset/ILSVRC2012_val_00033124.bin 224 224 +18454 ./prep_dataset/ILSVRC2012_val_00000989.bin 224 224 +18455 ./prep_dataset/ILSVRC2012_val_00030772.bin 224 224 +18456 ./prep_dataset/ILSVRC2012_val_00008889.bin 224 224 +18457 ./prep_dataset/ILSVRC2012_val_00048451.bin 224 224 +18458 ./prep_dataset/ILSVRC2012_val_00034819.bin 224 224 +18459 ./prep_dataset/ILSVRC2012_val_00037839.bin 224 224 +18460 ./prep_dataset/ILSVRC2012_val_00033996.bin 224 224 +18461 ./prep_dataset/ILSVRC2012_val_00031609.bin 224 224 +18462 ./prep_dataset/ILSVRC2012_val_00043847.bin 224 224 +18463 ./prep_dataset/ILSVRC2012_val_00031039.bin 224 224 +18464 ./prep_dataset/ILSVRC2012_val_00034479.bin 224 224 +18465 ./prep_dataset/ILSVRC2012_val_00035571.bin 224 224 +18466 ./prep_dataset/ILSVRC2012_val_00013955.bin 224 224 +18467 ./prep_dataset/ILSVRC2012_val_00045296.bin 224 224 +18468 ./prep_dataset/ILSVRC2012_val_00030190.bin 224 224 +18469 ./prep_dataset/ILSVRC2012_val_00019394.bin 224 224 +18470 ./prep_dataset/ILSVRC2012_val_00010365.bin 224 224 +18471 ./prep_dataset/ILSVRC2012_val_00033275.bin 224 224 +18472 ./prep_dataset/ILSVRC2012_val_00005450.bin 224 224 +18473 ./prep_dataset/ILSVRC2012_val_00022877.bin 224 224 +18474 ./prep_dataset/ILSVRC2012_val_00033439.bin 224 224 +18475 ./prep_dataset/ILSVRC2012_val_00012710.bin 224 224 +18476 ./prep_dataset/ILSVRC2012_val_00033525.bin 224 224 +18477 ./prep_dataset/ILSVRC2012_val_00039656.bin 224 224 +18478 ./prep_dataset/ILSVRC2012_val_00017349.bin 224 224 +18479 ./prep_dataset/ILSVRC2012_val_00010642.bin 224 224 +18480 ./prep_dataset/ILSVRC2012_val_00047364.bin 224 224 +18481 ./prep_dataset/ILSVRC2012_val_00008839.bin 224 224 +18482 ./prep_dataset/ILSVRC2012_val_00009286.bin 224 224 +18483 ./prep_dataset/ILSVRC2012_val_00006576.bin 224 224 +18484 ./prep_dataset/ILSVRC2012_val_00007312.bin 224 224 +18485 ./prep_dataset/ILSVRC2012_val_00040061.bin 224 224 +18486 ./prep_dataset/ILSVRC2012_val_00030679.bin 224 224 +18487 ./prep_dataset/ILSVRC2012_val_00037231.bin 224 224 +18488 ./prep_dataset/ILSVRC2012_val_00012490.bin 224 224 +18489 ./prep_dataset/ILSVRC2012_val_00040219.bin 224 224 +18490 ./prep_dataset/ILSVRC2012_val_00028393.bin 224 224 +18491 ./prep_dataset/ILSVRC2012_val_00001997.bin 224 224 +18492 ./prep_dataset/ILSVRC2012_val_00011922.bin 224 224 +18493 ./prep_dataset/ILSVRC2012_val_00013606.bin 224 224 +18494 ./prep_dataset/ILSVRC2012_val_00038535.bin 224 224 +18495 ./prep_dataset/ILSVRC2012_val_00004466.bin 224 224 +18496 ./prep_dataset/ILSVRC2012_val_00019888.bin 224 224 +18497 ./prep_dataset/ILSVRC2012_val_00006152.bin 224 224 +18498 ./prep_dataset/ILSVRC2012_val_00019550.bin 224 224 +18499 ./prep_dataset/ILSVRC2012_val_00000161.bin 224 224 +18500 ./prep_dataset/ILSVRC2012_val_00021935.bin 224 224 +18501 ./prep_dataset/ILSVRC2012_val_00008941.bin 224 224 +18502 ./prep_dataset/ILSVRC2012_val_00009168.bin 224 224 +18503 ./prep_dataset/ILSVRC2012_val_00021748.bin 224 224 +18504 ./prep_dataset/ILSVRC2012_val_00043573.bin 224 224 +18505 ./prep_dataset/ILSVRC2012_val_00020920.bin 224 224 +18506 ./prep_dataset/ILSVRC2012_val_00039088.bin 224 224 +18507 ./prep_dataset/ILSVRC2012_val_00034431.bin 224 224 +18508 ./prep_dataset/ILSVRC2012_val_00012727.bin 224 224 +18509 ./prep_dataset/ILSVRC2012_val_00009358.bin 224 224 +18510 ./prep_dataset/ILSVRC2012_val_00005723.bin 224 224 +18511 ./prep_dataset/ILSVRC2012_val_00049838.bin 224 224 +18512 ./prep_dataset/ILSVRC2012_val_00037262.bin 224 224 +18513 ./prep_dataset/ILSVRC2012_val_00015177.bin 224 224 +18514 ./prep_dataset/ILSVRC2012_val_00000829.bin 224 224 +18515 ./prep_dataset/ILSVRC2012_val_00033095.bin 224 224 +18516 ./prep_dataset/ILSVRC2012_val_00011563.bin 224 224 +18517 ./prep_dataset/ILSVRC2012_val_00000418.bin 224 224 +18518 ./prep_dataset/ILSVRC2012_val_00028147.bin 224 224 +18519 ./prep_dataset/ILSVRC2012_val_00047427.bin 224 224 +18520 ./prep_dataset/ILSVRC2012_val_00032139.bin 224 224 +18521 ./prep_dataset/ILSVRC2012_val_00011147.bin 224 224 +18522 ./prep_dataset/ILSVRC2012_val_00020275.bin 224 224 +18523 ./prep_dataset/ILSVRC2012_val_00048687.bin 224 224 +18524 ./prep_dataset/ILSVRC2012_val_00010747.bin 224 224 +18525 ./prep_dataset/ILSVRC2012_val_00042062.bin 224 224 +18526 ./prep_dataset/ILSVRC2012_val_00011230.bin 224 224 +18527 ./prep_dataset/ILSVRC2012_val_00020951.bin 224 224 +18528 ./prep_dataset/ILSVRC2012_val_00011849.bin 224 224 +18529 ./prep_dataset/ILSVRC2012_val_00043964.bin 224 224 +18530 ./prep_dataset/ILSVRC2012_val_00039553.bin 224 224 +18531 ./prep_dataset/ILSVRC2012_val_00028829.bin 224 224 +18532 ./prep_dataset/ILSVRC2012_val_00002545.bin 224 224 +18533 ./prep_dataset/ILSVRC2012_val_00014087.bin 224 224 +18534 ./prep_dataset/ILSVRC2012_val_00034245.bin 224 224 +18535 ./prep_dataset/ILSVRC2012_val_00032484.bin 224 224 +18536 ./prep_dataset/ILSVRC2012_val_00022264.bin 224 224 +18537 ./prep_dataset/ILSVRC2012_val_00026920.bin 224 224 +18538 ./prep_dataset/ILSVRC2012_val_00028778.bin 224 224 +18539 ./prep_dataset/ILSVRC2012_val_00037993.bin 224 224 +18540 ./prep_dataset/ILSVRC2012_val_00012346.bin 224 224 +18541 ./prep_dataset/ILSVRC2012_val_00047701.bin 224 224 +18542 ./prep_dataset/ILSVRC2012_val_00017795.bin 224 224 +18543 ./prep_dataset/ILSVRC2012_val_00004364.bin 224 224 +18544 ./prep_dataset/ILSVRC2012_val_00009436.bin 224 224 +18545 ./prep_dataset/ILSVRC2012_val_00034524.bin 224 224 +18546 ./prep_dataset/ILSVRC2012_val_00011393.bin 224 224 +18547 ./prep_dataset/ILSVRC2012_val_00048698.bin 224 224 +18548 ./prep_dataset/ILSVRC2012_val_00035157.bin 224 224 +18549 ./prep_dataset/ILSVRC2012_val_00016719.bin 224 224 +18550 ./prep_dataset/ILSVRC2012_val_00041584.bin 224 224 +18551 ./prep_dataset/ILSVRC2012_val_00013415.bin 224 224 +18552 ./prep_dataset/ILSVRC2012_val_00002691.bin 224 224 +18553 ./prep_dataset/ILSVRC2012_val_00015885.bin 224 224 +18554 ./prep_dataset/ILSVRC2012_val_00020672.bin 224 224 +18555 ./prep_dataset/ILSVRC2012_val_00001978.bin 224 224 +18556 ./prep_dataset/ILSVRC2012_val_00029765.bin 224 224 +18557 ./prep_dataset/ILSVRC2012_val_00041703.bin 224 224 +18558 ./prep_dataset/ILSVRC2012_val_00030304.bin 224 224 +18559 ./prep_dataset/ILSVRC2012_val_00011882.bin 224 224 +18560 ./prep_dataset/ILSVRC2012_val_00015755.bin 224 224 +18561 ./prep_dataset/ILSVRC2012_val_00031079.bin 224 224 +18562 ./prep_dataset/ILSVRC2012_val_00010936.bin 224 224 +18563 ./prep_dataset/ILSVRC2012_val_00035801.bin 224 224 +18564 ./prep_dataset/ILSVRC2012_val_00040964.bin 224 224 +18565 ./prep_dataset/ILSVRC2012_val_00047138.bin 224 224 +18566 ./prep_dataset/ILSVRC2012_val_00049111.bin 224 224 +18567 ./prep_dataset/ILSVRC2012_val_00033885.bin 224 224 +18568 ./prep_dataset/ILSVRC2012_val_00030913.bin 224 224 +18569 ./prep_dataset/ILSVRC2012_val_00040514.bin 224 224 +18570 ./prep_dataset/ILSVRC2012_val_00016291.bin 224 224 +18571 ./prep_dataset/ILSVRC2012_val_00045784.bin 224 224 +18572 ./prep_dataset/ILSVRC2012_val_00042140.bin 224 224 +18573 ./prep_dataset/ILSVRC2012_val_00048781.bin 224 224 +18574 ./prep_dataset/ILSVRC2012_val_00007925.bin 224 224 +18575 ./prep_dataset/ILSVRC2012_val_00024149.bin 224 224 +18576 ./prep_dataset/ILSVRC2012_val_00001885.bin 224 224 +18577 ./prep_dataset/ILSVRC2012_val_00004918.bin 224 224 +18578 ./prep_dataset/ILSVRC2012_val_00030944.bin 224 224 +18579 ./prep_dataset/ILSVRC2012_val_00002082.bin 224 224 +18580 ./prep_dataset/ILSVRC2012_val_00042986.bin 224 224 +18581 ./prep_dataset/ILSVRC2012_val_00030947.bin 224 224 +18582 ./prep_dataset/ILSVRC2012_val_00046065.bin 224 224 +18583 ./prep_dataset/ILSVRC2012_val_00045452.bin 224 224 +18584 ./prep_dataset/ILSVRC2012_val_00022658.bin 224 224 +18585 ./prep_dataset/ILSVRC2012_val_00039451.bin 224 224 +18586 ./prep_dataset/ILSVRC2012_val_00026746.bin 224 224 +18587 ./prep_dataset/ILSVRC2012_val_00010171.bin 224 224 +18588 ./prep_dataset/ILSVRC2012_val_00001703.bin 224 224 +18589 ./prep_dataset/ILSVRC2012_val_00000779.bin 224 224 +18590 ./prep_dataset/ILSVRC2012_val_00017615.bin 224 224 +18591 ./prep_dataset/ILSVRC2012_val_00005632.bin 224 224 +18592 ./prep_dataset/ILSVRC2012_val_00021310.bin 224 224 +18593 ./prep_dataset/ILSVRC2012_val_00014316.bin 224 224 +18594 ./prep_dataset/ILSVRC2012_val_00031994.bin 224 224 +18595 ./prep_dataset/ILSVRC2012_val_00001376.bin 224 224 +18596 ./prep_dataset/ILSVRC2012_val_00006535.bin 224 224 +18597 ./prep_dataset/ILSVRC2012_val_00046173.bin 224 224 +18598 ./prep_dataset/ILSVRC2012_val_00029709.bin 224 224 +18599 ./prep_dataset/ILSVRC2012_val_00018512.bin 224 224 +18600 ./prep_dataset/ILSVRC2012_val_00032873.bin 224 224 +18601 ./prep_dataset/ILSVRC2012_val_00002718.bin 224 224 +18602 ./prep_dataset/ILSVRC2012_val_00020310.bin 224 224 +18603 ./prep_dataset/ILSVRC2012_val_00032225.bin 224 224 +18604 ./prep_dataset/ILSVRC2012_val_00006136.bin 224 224 +18605 ./prep_dataset/ILSVRC2012_val_00015715.bin 224 224 +18606 ./prep_dataset/ILSVRC2012_val_00038609.bin 224 224 +18607 ./prep_dataset/ILSVRC2012_val_00005325.bin 224 224 +18608 ./prep_dataset/ILSVRC2012_val_00033718.bin 224 224 +18609 ./prep_dataset/ILSVRC2012_val_00042606.bin 224 224 +18610 ./prep_dataset/ILSVRC2012_val_00002794.bin 224 224 +18611 ./prep_dataset/ILSVRC2012_val_00025124.bin 224 224 +18612 ./prep_dataset/ILSVRC2012_val_00027175.bin 224 224 +18613 ./prep_dataset/ILSVRC2012_val_00031494.bin 224 224 +18614 ./prep_dataset/ILSVRC2012_val_00012418.bin 224 224 +18615 ./prep_dataset/ILSVRC2012_val_00010568.bin 224 224 +18616 ./prep_dataset/ILSVRC2012_val_00007391.bin 224 224 +18617 ./prep_dataset/ILSVRC2012_val_00047735.bin 224 224 +18618 ./prep_dataset/ILSVRC2012_val_00003080.bin 224 224 +18619 ./prep_dataset/ILSVRC2012_val_00033462.bin 224 224 +18620 ./prep_dataset/ILSVRC2012_val_00018958.bin 224 224 +18621 ./prep_dataset/ILSVRC2012_val_00020980.bin 224 224 +18622 ./prep_dataset/ILSVRC2012_val_00023650.bin 224 224 +18623 ./prep_dataset/ILSVRC2012_val_00008213.bin 224 224 +18624 ./prep_dataset/ILSVRC2012_val_00014136.bin 224 224 +18625 ./prep_dataset/ILSVRC2012_val_00017701.bin 224 224 +18626 ./prep_dataset/ILSVRC2012_val_00028871.bin 224 224 +18627 ./prep_dataset/ILSVRC2012_val_00008696.bin 224 224 +18628 ./prep_dataset/ILSVRC2012_val_00026833.bin 224 224 +18629 ./prep_dataset/ILSVRC2012_val_00040747.bin 224 224 +18630 ./prep_dataset/ILSVRC2012_val_00017254.bin 224 224 +18631 ./prep_dataset/ILSVRC2012_val_00040799.bin 224 224 +18632 ./prep_dataset/ILSVRC2012_val_00008523.bin 224 224 +18633 ./prep_dataset/ILSVRC2012_val_00047160.bin 224 224 +18634 ./prep_dataset/ILSVRC2012_val_00012852.bin 224 224 +18635 ./prep_dataset/ILSVRC2012_val_00008990.bin 224 224 +18636 ./prep_dataset/ILSVRC2012_val_00044917.bin 224 224 +18637 ./prep_dataset/ILSVRC2012_val_00023183.bin 224 224 +18638 ./prep_dataset/ILSVRC2012_val_00037913.bin 224 224 +18639 ./prep_dataset/ILSVRC2012_val_00044678.bin 224 224 +18640 ./prep_dataset/ILSVRC2012_val_00030817.bin 224 224 +18641 ./prep_dataset/ILSVRC2012_val_00042075.bin 224 224 +18642 ./prep_dataset/ILSVRC2012_val_00030786.bin 224 224 +18643 ./prep_dataset/ILSVRC2012_val_00026840.bin 224 224 +18644 ./prep_dataset/ILSVRC2012_val_00021681.bin 224 224 +18645 ./prep_dataset/ILSVRC2012_val_00048226.bin 224 224 +18646 ./prep_dataset/ILSVRC2012_val_00029582.bin 224 224 +18647 ./prep_dataset/ILSVRC2012_val_00005907.bin 224 224 +18648 ./prep_dataset/ILSVRC2012_val_00007343.bin 224 224 +18649 ./prep_dataset/ILSVRC2012_val_00029549.bin 224 224 +18650 ./prep_dataset/ILSVRC2012_val_00040963.bin 224 224 +18651 ./prep_dataset/ILSVRC2012_val_00023316.bin 224 224 +18652 ./prep_dataset/ILSVRC2012_val_00006430.bin 224 224 +18653 ./prep_dataset/ILSVRC2012_val_00016718.bin 224 224 +18654 ./prep_dataset/ILSVRC2012_val_00028998.bin 224 224 +18655 ./prep_dataset/ILSVRC2012_val_00032327.bin 224 224 +18656 ./prep_dataset/ILSVRC2012_val_00033585.bin 224 224 +18657 ./prep_dataset/ILSVRC2012_val_00037195.bin 224 224 +18658 ./prep_dataset/ILSVRC2012_val_00007952.bin 224 224 +18659 ./prep_dataset/ILSVRC2012_val_00002471.bin 224 224 +18660 ./prep_dataset/ILSVRC2012_val_00029988.bin 224 224 +18661 ./prep_dataset/ILSVRC2012_val_00044308.bin 224 224 +18662 ./prep_dataset/ILSVRC2012_val_00028242.bin 224 224 +18663 ./prep_dataset/ILSVRC2012_val_00001501.bin 224 224 +18664 ./prep_dataset/ILSVRC2012_val_00028666.bin 224 224 +18665 ./prep_dataset/ILSVRC2012_val_00032826.bin 224 224 +18666 ./prep_dataset/ILSVRC2012_val_00014822.bin 224 224 +18667 ./prep_dataset/ILSVRC2012_val_00012746.bin 224 224 +18668 ./prep_dataset/ILSVRC2012_val_00032362.bin 224 224 +18669 ./prep_dataset/ILSVRC2012_val_00026003.bin 224 224 +18670 ./prep_dataset/ILSVRC2012_val_00025728.bin 224 224 +18671 ./prep_dataset/ILSVRC2012_val_00032813.bin 224 224 +18672 ./prep_dataset/ILSVRC2012_val_00010590.bin 224 224 +18673 ./prep_dataset/ILSVRC2012_val_00030847.bin 224 224 +18674 ./prep_dataset/ILSVRC2012_val_00026298.bin 224 224 +18675 ./prep_dataset/ILSVRC2012_val_00018556.bin 224 224 +18676 ./prep_dataset/ILSVRC2012_val_00012897.bin 224 224 +18677 ./prep_dataset/ILSVRC2012_val_00019231.bin 224 224 +18678 ./prep_dataset/ILSVRC2012_val_00037922.bin 224 224 +18679 ./prep_dataset/ILSVRC2012_val_00041871.bin 224 224 +18680 ./prep_dataset/ILSVRC2012_val_00034768.bin 224 224 +18681 ./prep_dataset/ILSVRC2012_val_00017641.bin 224 224 +18682 ./prep_dataset/ILSVRC2012_val_00039292.bin 224 224 +18683 ./prep_dataset/ILSVRC2012_val_00028835.bin 224 224 +18684 ./prep_dataset/ILSVRC2012_val_00045989.bin 224 224 +18685 ./prep_dataset/ILSVRC2012_val_00015853.bin 224 224 +18686 ./prep_dataset/ILSVRC2012_val_00010290.bin 224 224 +18687 ./prep_dataset/ILSVRC2012_val_00009264.bin 224 224 +18688 ./prep_dataset/ILSVRC2012_val_00032332.bin 224 224 +18689 ./prep_dataset/ILSVRC2012_val_00001743.bin 224 224 +18690 ./prep_dataset/ILSVRC2012_val_00010739.bin 224 224 +18691 ./prep_dataset/ILSVRC2012_val_00036752.bin 224 224 +18692 ./prep_dataset/ILSVRC2012_val_00009597.bin 224 224 +18693 ./prep_dataset/ILSVRC2012_val_00012678.bin 224 224 +18694 ./prep_dataset/ILSVRC2012_val_00030822.bin 224 224 +18695 ./prep_dataset/ILSVRC2012_val_00019296.bin 224 224 +18696 ./prep_dataset/ILSVRC2012_val_00037233.bin 224 224 +18697 ./prep_dataset/ILSVRC2012_val_00044569.bin 224 224 +18698 ./prep_dataset/ILSVRC2012_val_00004103.bin 224 224 +18699 ./prep_dataset/ILSVRC2012_val_00027509.bin 224 224 +18700 ./prep_dataset/ILSVRC2012_val_00002173.bin 224 224 +18701 ./prep_dataset/ILSVRC2012_val_00019013.bin 224 224 +18702 ./prep_dataset/ILSVRC2012_val_00026242.bin 224 224 +18703 ./prep_dataset/ILSVRC2012_val_00017538.bin 224 224 +18704 ./prep_dataset/ILSVRC2012_val_00039627.bin 224 224 +18705 ./prep_dataset/ILSVRC2012_val_00003388.bin 224 224 +18706 ./prep_dataset/ILSVRC2012_val_00017968.bin 224 224 +18707 ./prep_dataset/ILSVRC2012_val_00010667.bin 224 224 +18708 ./prep_dataset/ILSVRC2012_val_00019253.bin 224 224 +18709 ./prep_dataset/ILSVRC2012_val_00019522.bin 224 224 +18710 ./prep_dataset/ILSVRC2012_val_00018374.bin 224 224 +18711 ./prep_dataset/ILSVRC2012_val_00033422.bin 224 224 +18712 ./prep_dataset/ILSVRC2012_val_00008002.bin 224 224 +18713 ./prep_dataset/ILSVRC2012_val_00028289.bin 224 224 +18714 ./prep_dataset/ILSVRC2012_val_00018001.bin 224 224 +18715 ./prep_dataset/ILSVRC2012_val_00034926.bin 224 224 +18716 ./prep_dataset/ILSVRC2012_val_00013266.bin 224 224 +18717 ./prep_dataset/ILSVRC2012_val_00049879.bin 224 224 +18718 ./prep_dataset/ILSVRC2012_val_00047677.bin 224 224 +18719 ./prep_dataset/ILSVRC2012_val_00013211.bin 224 224 +18720 ./prep_dataset/ILSVRC2012_val_00045214.bin 224 224 +18721 ./prep_dataset/ILSVRC2012_val_00048315.bin 224 224 +18722 ./prep_dataset/ILSVRC2012_val_00018786.bin 224 224 +18723 ./prep_dataset/ILSVRC2012_val_00045694.bin 224 224 +18724 ./prep_dataset/ILSVRC2012_val_00011813.bin 224 224 +18725 ./prep_dataset/ILSVRC2012_val_00041742.bin 224 224 +18726 ./prep_dataset/ILSVRC2012_val_00033474.bin 224 224 +18727 ./prep_dataset/ILSVRC2012_val_00039708.bin 224 224 +18728 ./prep_dataset/ILSVRC2012_val_00010953.bin 224 224 +18729 ./prep_dataset/ILSVRC2012_val_00001986.bin 224 224 +18730 ./prep_dataset/ILSVRC2012_val_00011751.bin 224 224 +18731 ./prep_dataset/ILSVRC2012_val_00046976.bin 224 224 +18732 ./prep_dataset/ILSVRC2012_val_00016726.bin 224 224 +18733 ./prep_dataset/ILSVRC2012_val_00038355.bin 224 224 +18734 ./prep_dataset/ILSVRC2012_val_00006456.bin 224 224 +18735 ./prep_dataset/ILSVRC2012_val_00042431.bin 224 224 +18736 ./prep_dataset/ILSVRC2012_val_00015390.bin 224 224 +18737 ./prep_dataset/ILSVRC2012_val_00031514.bin 224 224 +18738 ./prep_dataset/ILSVRC2012_val_00041282.bin 224 224 +18739 ./prep_dataset/ILSVRC2012_val_00003741.bin 224 224 +18740 ./prep_dataset/ILSVRC2012_val_00032685.bin 224 224 +18741 ./prep_dataset/ILSVRC2012_val_00014921.bin 224 224 +18742 ./prep_dataset/ILSVRC2012_val_00047558.bin 224 224 +18743 ./prep_dataset/ILSVRC2012_val_00044662.bin 224 224 +18744 ./prep_dataset/ILSVRC2012_val_00046804.bin 224 224 +18745 ./prep_dataset/ILSVRC2012_val_00037602.bin 224 224 +18746 ./prep_dataset/ILSVRC2012_val_00004710.bin 224 224 +18747 ./prep_dataset/ILSVRC2012_val_00027319.bin 224 224 +18748 ./prep_dataset/ILSVRC2012_val_00014230.bin 224 224 +18749 ./prep_dataset/ILSVRC2012_val_00003648.bin 224 224 +18750 ./prep_dataset/ILSVRC2012_val_00007620.bin 224 224 +18751 ./prep_dataset/ILSVRC2012_val_00036157.bin 224 224 +18752 ./prep_dataset/ILSVRC2012_val_00013770.bin 224 224 +18753 ./prep_dataset/ILSVRC2012_val_00009993.bin 224 224 +18754 ./prep_dataset/ILSVRC2012_val_00035555.bin 224 224 +18755 ./prep_dataset/ILSVRC2012_val_00024314.bin 224 224 +18756 ./prep_dataset/ILSVRC2012_val_00004995.bin 224 224 +18757 ./prep_dataset/ILSVRC2012_val_00016465.bin 224 224 +18758 ./prep_dataset/ILSVRC2012_val_00042800.bin 224 224 +18759 ./prep_dataset/ILSVRC2012_val_00024238.bin 224 224 +18760 ./prep_dataset/ILSVRC2012_val_00002768.bin 224 224 +18761 ./prep_dataset/ILSVRC2012_val_00022613.bin 224 224 +18762 ./prep_dataset/ILSVRC2012_val_00018300.bin 224 224 +18763 ./prep_dataset/ILSVRC2012_val_00009269.bin 224 224 +18764 ./prep_dataset/ILSVRC2012_val_00045691.bin 224 224 +18765 ./prep_dataset/ILSVRC2012_val_00006628.bin 224 224 +18766 ./prep_dataset/ILSVRC2012_val_00034493.bin 224 224 +18767 ./prep_dataset/ILSVRC2012_val_00022537.bin 224 224 +18768 ./prep_dataset/ILSVRC2012_val_00021975.bin 224 224 +18769 ./prep_dataset/ILSVRC2012_val_00015839.bin 224 224 +18770 ./prep_dataset/ILSVRC2012_val_00021086.bin 224 224 +18771 ./prep_dataset/ILSVRC2012_val_00026450.bin 224 224 +18772 ./prep_dataset/ILSVRC2012_val_00012787.bin 224 224 +18773 ./prep_dataset/ILSVRC2012_val_00029169.bin 224 224 +18774 ./prep_dataset/ILSVRC2012_val_00027278.bin 224 224 +18775 ./prep_dataset/ILSVRC2012_val_00000823.bin 224 224 +18776 ./prep_dataset/ILSVRC2012_val_00022361.bin 224 224 +18777 ./prep_dataset/ILSVRC2012_val_00042696.bin 224 224 +18778 ./prep_dataset/ILSVRC2012_val_00030119.bin 224 224 +18779 ./prep_dataset/ILSVRC2012_val_00020350.bin 224 224 +18780 ./prep_dataset/ILSVRC2012_val_00009769.bin 224 224 +18781 ./prep_dataset/ILSVRC2012_val_00006718.bin 224 224 +18782 ./prep_dataset/ILSVRC2012_val_00029751.bin 224 224 +18783 ./prep_dataset/ILSVRC2012_val_00017724.bin 224 224 +18784 ./prep_dataset/ILSVRC2012_val_00003584.bin 224 224 +18785 ./prep_dataset/ILSVRC2012_val_00043805.bin 224 224 +18786 ./prep_dataset/ILSVRC2012_val_00020502.bin 224 224 +18787 ./prep_dataset/ILSVRC2012_val_00027285.bin 224 224 +18788 ./prep_dataset/ILSVRC2012_val_00024221.bin 224 224 +18789 ./prep_dataset/ILSVRC2012_val_00034594.bin 224 224 +18790 ./prep_dataset/ILSVRC2012_val_00019307.bin 224 224 +18791 ./prep_dataset/ILSVRC2012_val_00018914.bin 224 224 +18792 ./prep_dataset/ILSVRC2012_val_00023105.bin 224 224 +18793 ./prep_dataset/ILSVRC2012_val_00041880.bin 224 224 +18794 ./prep_dataset/ILSVRC2012_val_00014577.bin 224 224 +18795 ./prep_dataset/ILSVRC2012_val_00038179.bin 224 224 +18796 ./prep_dataset/ILSVRC2012_val_00004750.bin 224 224 +18797 ./prep_dataset/ILSVRC2012_val_00027658.bin 224 224 +18798 ./prep_dataset/ILSVRC2012_val_00010353.bin 224 224 +18799 ./prep_dataset/ILSVRC2012_val_00027943.bin 224 224 +18800 ./prep_dataset/ILSVRC2012_val_00014095.bin 224 224 +18801 ./prep_dataset/ILSVRC2012_val_00043832.bin 224 224 +18802 ./prep_dataset/ILSVRC2012_val_00031897.bin 224 224 +18803 ./prep_dataset/ILSVRC2012_val_00008407.bin 224 224 +18804 ./prep_dataset/ILSVRC2012_val_00031521.bin 224 224 +18805 ./prep_dataset/ILSVRC2012_val_00017189.bin 224 224 +18806 ./prep_dataset/ILSVRC2012_val_00044536.bin 224 224 +18807 ./prep_dataset/ILSVRC2012_val_00003217.bin 224 224 +18808 ./prep_dataset/ILSVRC2012_val_00029092.bin 224 224 +18809 ./prep_dataset/ILSVRC2012_val_00024637.bin 224 224 +18810 ./prep_dataset/ILSVRC2012_val_00029790.bin 224 224 +18811 ./prep_dataset/ILSVRC2012_val_00036172.bin 224 224 +18812 ./prep_dataset/ILSVRC2012_val_00033944.bin 224 224 +18813 ./prep_dataset/ILSVRC2012_val_00032342.bin 224 224 +18814 ./prep_dataset/ILSVRC2012_val_00028243.bin 224 224 +18815 ./prep_dataset/ILSVRC2012_val_00005673.bin 224 224 +18816 ./prep_dataset/ILSVRC2012_val_00020227.bin 224 224 +18817 ./prep_dataset/ILSVRC2012_val_00010355.bin 224 224 +18818 ./prep_dataset/ILSVRC2012_val_00005720.bin 224 224 +18819 ./prep_dataset/ILSVRC2012_val_00039941.bin 224 224 +18820 ./prep_dataset/ILSVRC2012_val_00014098.bin 224 224 +18821 ./prep_dataset/ILSVRC2012_val_00025431.bin 224 224 +18822 ./prep_dataset/ILSVRC2012_val_00008927.bin 224 224 +18823 ./prep_dataset/ILSVRC2012_val_00043402.bin 224 224 +18824 ./prep_dataset/ILSVRC2012_val_00000040.bin 224 224 +18825 ./prep_dataset/ILSVRC2012_val_00043767.bin 224 224 +18826 ./prep_dataset/ILSVRC2012_val_00045102.bin 224 224 +18827 ./prep_dataset/ILSVRC2012_val_00020208.bin 224 224 +18828 ./prep_dataset/ILSVRC2012_val_00032998.bin 224 224 +18829 ./prep_dataset/ILSVRC2012_val_00046601.bin 224 224 +18830 ./prep_dataset/ILSVRC2012_val_00040833.bin 224 224 +18831 ./prep_dataset/ILSVRC2012_val_00006057.bin 224 224 +18832 ./prep_dataset/ILSVRC2012_val_00046234.bin 224 224 +18833 ./prep_dataset/ILSVRC2012_val_00030716.bin 224 224 +18834 ./prep_dataset/ILSVRC2012_val_00043372.bin 224 224 +18835 ./prep_dataset/ILSVRC2012_val_00028529.bin 224 224 +18836 ./prep_dataset/ILSVRC2012_val_00041040.bin 224 224 +18837 ./prep_dataset/ILSVRC2012_val_00045368.bin 224 224 +18838 ./prep_dataset/ILSVRC2012_val_00037659.bin 224 224 +18839 ./prep_dataset/ILSVRC2012_val_00029620.bin 224 224 +18840 ./prep_dataset/ILSVRC2012_val_00047816.bin 224 224 +18841 ./prep_dataset/ILSVRC2012_val_00006148.bin 224 224 +18842 ./prep_dataset/ILSVRC2012_val_00029223.bin 224 224 +18843 ./prep_dataset/ILSVRC2012_val_00034150.bin 224 224 +18844 ./prep_dataset/ILSVRC2012_val_00039435.bin 224 224 +18845 ./prep_dataset/ILSVRC2012_val_00003854.bin 224 224 +18846 ./prep_dataset/ILSVRC2012_val_00021810.bin 224 224 +18847 ./prep_dataset/ILSVRC2012_val_00025225.bin 224 224 +18848 ./prep_dataset/ILSVRC2012_val_00025910.bin 224 224 +18849 ./prep_dataset/ILSVRC2012_val_00031355.bin 224 224 +18850 ./prep_dataset/ILSVRC2012_val_00004905.bin 224 224 +18851 ./prep_dataset/ILSVRC2012_val_00011233.bin 224 224 +18852 ./prep_dataset/ILSVRC2012_val_00012135.bin 224 224 +18853 ./prep_dataset/ILSVRC2012_val_00029622.bin 224 224 +18854 ./prep_dataset/ILSVRC2012_val_00037718.bin 224 224 +18855 ./prep_dataset/ILSVRC2012_val_00041577.bin 224 224 +18856 ./prep_dataset/ILSVRC2012_val_00046933.bin 224 224 +18857 ./prep_dataset/ILSVRC2012_val_00014557.bin 224 224 +18858 ./prep_dataset/ILSVRC2012_val_00001442.bin 224 224 +18859 ./prep_dataset/ILSVRC2012_val_00014309.bin 224 224 +18860 ./prep_dataset/ILSVRC2012_val_00046251.bin 224 224 +18861 ./prep_dataset/ILSVRC2012_val_00012003.bin 224 224 +18862 ./prep_dataset/ILSVRC2012_val_00007917.bin 224 224 +18863 ./prep_dataset/ILSVRC2012_val_00022746.bin 224 224 +18864 ./prep_dataset/ILSVRC2012_val_00025678.bin 224 224 +18865 ./prep_dataset/ILSVRC2012_val_00029218.bin 224 224 +18866 ./prep_dataset/ILSVRC2012_val_00000342.bin 224 224 +18867 ./prep_dataset/ILSVRC2012_val_00030284.bin 224 224 +18868 ./prep_dataset/ILSVRC2012_val_00003696.bin 224 224 +18869 ./prep_dataset/ILSVRC2012_val_00046803.bin 224 224 +18870 ./prep_dataset/ILSVRC2012_val_00024867.bin 224 224 +18871 ./prep_dataset/ILSVRC2012_val_00025321.bin 224 224 +18872 ./prep_dataset/ILSVRC2012_val_00018610.bin 224 224 +18873 ./prep_dataset/ILSVRC2012_val_00019694.bin 224 224 +18874 ./prep_dataset/ILSVRC2012_val_00001652.bin 224 224 +18875 ./prep_dataset/ILSVRC2012_val_00049579.bin 224 224 +18876 ./prep_dataset/ILSVRC2012_val_00023632.bin 224 224 +18877 ./prep_dataset/ILSVRC2012_val_00044653.bin 224 224 +18878 ./prep_dataset/ILSVRC2012_val_00011295.bin 224 224 +18879 ./prep_dataset/ILSVRC2012_val_00040390.bin 224 224 +18880 ./prep_dataset/ILSVRC2012_val_00003250.bin 224 224 +18881 ./prep_dataset/ILSVRC2012_val_00019304.bin 224 224 +18882 ./prep_dataset/ILSVRC2012_val_00037564.bin 224 224 +18883 ./prep_dataset/ILSVRC2012_val_00033966.bin 224 224 +18884 ./prep_dataset/ILSVRC2012_val_00045057.bin 224 224 +18885 ./prep_dataset/ILSVRC2012_val_00043201.bin 224 224 +18886 ./prep_dataset/ILSVRC2012_val_00048749.bin 224 224 +18887 ./prep_dataset/ILSVRC2012_val_00024653.bin 224 224 +18888 ./prep_dataset/ILSVRC2012_val_00023984.bin 224 224 +18889 ./prep_dataset/ILSVRC2012_val_00032399.bin 224 224 +18890 ./prep_dataset/ILSVRC2012_val_00034057.bin 224 224 +18891 ./prep_dataset/ILSVRC2012_val_00040656.bin 224 224 +18892 ./prep_dataset/ILSVRC2012_val_00045942.bin 224 224 +18893 ./prep_dataset/ILSVRC2012_val_00034164.bin 224 224 +18894 ./prep_dataset/ILSVRC2012_val_00043028.bin 224 224 +18895 ./prep_dataset/ILSVRC2012_val_00048248.bin 224 224 +18896 ./prep_dataset/ILSVRC2012_val_00008611.bin 224 224 +18897 ./prep_dataset/ILSVRC2012_val_00028780.bin 224 224 +18898 ./prep_dataset/ILSVRC2012_val_00024853.bin 224 224 +18899 ./prep_dataset/ILSVRC2012_val_00047916.bin 224 224 +18900 ./prep_dataset/ILSVRC2012_val_00043663.bin 224 224 +18901 ./prep_dataset/ILSVRC2012_val_00047976.bin 224 224 +18902 ./prep_dataset/ILSVRC2012_val_00026518.bin 224 224 +18903 ./prep_dataset/ILSVRC2012_val_00022152.bin 224 224 +18904 ./prep_dataset/ILSVRC2012_val_00043290.bin 224 224 +18905 ./prep_dataset/ILSVRC2012_val_00000589.bin 224 224 +18906 ./prep_dataset/ILSVRC2012_val_00049812.bin 224 224 +18907 ./prep_dataset/ILSVRC2012_val_00009315.bin 224 224 +18908 ./prep_dataset/ILSVRC2012_val_00049534.bin 224 224 +18909 ./prep_dataset/ILSVRC2012_val_00036483.bin 224 224 +18910 ./prep_dataset/ILSVRC2012_val_00012802.bin 224 224 +18911 ./prep_dataset/ILSVRC2012_val_00025523.bin 224 224 +18912 ./prep_dataset/ILSVRC2012_val_00002392.bin 224 224 +18913 ./prep_dataset/ILSVRC2012_val_00012535.bin 224 224 +18914 ./prep_dataset/ILSVRC2012_val_00013523.bin 224 224 +18915 ./prep_dataset/ILSVRC2012_val_00036456.bin 224 224 +18916 ./prep_dataset/ILSVRC2012_val_00003793.bin 224 224 +18917 ./prep_dataset/ILSVRC2012_val_00014998.bin 224 224 +18918 ./prep_dataset/ILSVRC2012_val_00011852.bin 224 224 +18919 ./prep_dataset/ILSVRC2012_val_00011334.bin 224 224 +18920 ./prep_dataset/ILSVRC2012_val_00008862.bin 224 224 +18921 ./prep_dataset/ILSVRC2012_val_00026007.bin 224 224 +18922 ./prep_dataset/ILSVRC2012_val_00048762.bin 224 224 +18923 ./prep_dataset/ILSVRC2012_val_00038862.bin 224 224 +18924 ./prep_dataset/ILSVRC2012_val_00032883.bin 224 224 +18925 ./prep_dataset/ILSVRC2012_val_00029371.bin 224 224 +18926 ./prep_dataset/ILSVRC2012_val_00002299.bin 224 224 +18927 ./prep_dataset/ILSVRC2012_val_00007564.bin 224 224 +18928 ./prep_dataset/ILSVRC2012_val_00036185.bin 224 224 +18929 ./prep_dataset/ILSVRC2012_val_00037480.bin 224 224 +18930 ./prep_dataset/ILSVRC2012_val_00043594.bin 224 224 +18931 ./prep_dataset/ILSVRC2012_val_00020240.bin 224 224 +18932 ./prep_dataset/ILSVRC2012_val_00043759.bin 224 224 +18933 ./prep_dataset/ILSVRC2012_val_00035111.bin 224 224 +18934 ./prep_dataset/ILSVRC2012_val_00013935.bin 224 224 +18935 ./prep_dataset/ILSVRC2012_val_00039678.bin 224 224 +18936 ./prep_dataset/ILSVRC2012_val_00040844.bin 224 224 +18937 ./prep_dataset/ILSVRC2012_val_00017015.bin 224 224 +18938 ./prep_dataset/ILSVRC2012_val_00043174.bin 224 224 +18939 ./prep_dataset/ILSVRC2012_val_00041208.bin 224 224 +18940 ./prep_dataset/ILSVRC2012_val_00043648.bin 224 224 +18941 ./prep_dataset/ILSVRC2012_val_00049856.bin 224 224 +18942 ./prep_dataset/ILSVRC2012_val_00041886.bin 224 224 +18943 ./prep_dataset/ILSVRC2012_val_00022373.bin 224 224 +18944 ./prep_dataset/ILSVRC2012_val_00044900.bin 224 224 +18945 ./prep_dataset/ILSVRC2012_val_00027214.bin 224 224 +18946 ./prep_dataset/ILSVRC2012_val_00043470.bin 224 224 +18947 ./prep_dataset/ILSVRC2012_val_00046837.bin 224 224 +18948 ./prep_dataset/ILSVRC2012_val_00004770.bin 224 224 +18949 ./prep_dataset/ILSVRC2012_val_00047801.bin 224 224 +18950 ./prep_dataset/ILSVRC2012_val_00003558.bin 224 224 +18951 ./prep_dataset/ILSVRC2012_val_00020128.bin 224 224 +18952 ./prep_dataset/ILSVRC2012_val_00027213.bin 224 224 +18953 ./prep_dataset/ILSVRC2012_val_00034553.bin 224 224 +18954 ./prep_dataset/ILSVRC2012_val_00037227.bin 224 224 +18955 ./prep_dataset/ILSVRC2012_val_00030101.bin 224 224 +18956 ./prep_dataset/ILSVRC2012_val_00015099.bin 224 224 +18957 ./prep_dataset/ILSVRC2012_val_00040600.bin 224 224 +18958 ./prep_dataset/ILSVRC2012_val_00029211.bin 224 224 +18959 ./prep_dataset/ILSVRC2012_val_00015833.bin 224 224 +18960 ./prep_dataset/ILSVRC2012_val_00002727.bin 224 224 +18961 ./prep_dataset/ILSVRC2012_val_00039672.bin 224 224 +18962 ./prep_dataset/ILSVRC2012_val_00004943.bin 224 224 +18963 ./prep_dataset/ILSVRC2012_val_00019792.bin 224 224 +18964 ./prep_dataset/ILSVRC2012_val_00003890.bin 224 224 +18965 ./prep_dataset/ILSVRC2012_val_00029228.bin 224 224 +18966 ./prep_dataset/ILSVRC2012_val_00008773.bin 224 224 +18967 ./prep_dataset/ILSVRC2012_val_00004388.bin 224 224 +18968 ./prep_dataset/ILSVRC2012_val_00012171.bin 224 224 +18969 ./prep_dataset/ILSVRC2012_val_00004911.bin 224 224 +18970 ./prep_dataset/ILSVRC2012_val_00019970.bin 224 224 +18971 ./prep_dataset/ILSVRC2012_val_00044520.bin 224 224 +18972 ./prep_dataset/ILSVRC2012_val_00019424.bin 224 224 +18973 ./prep_dataset/ILSVRC2012_val_00034674.bin 224 224 +18974 ./prep_dataset/ILSVRC2012_val_00023781.bin 224 224 +18975 ./prep_dataset/ILSVRC2012_val_00023635.bin 224 224 +18976 ./prep_dataset/ILSVRC2012_val_00045222.bin 224 224 +18977 ./prep_dataset/ILSVRC2012_val_00004017.bin 224 224 +18978 ./prep_dataset/ILSVRC2012_val_00002388.bin 224 224 +18979 ./prep_dataset/ILSVRC2012_val_00037680.bin 224 224 +18980 ./prep_dataset/ILSVRC2012_val_00001033.bin 224 224 +18981 ./prep_dataset/ILSVRC2012_val_00010367.bin 224 224 +18982 ./prep_dataset/ILSVRC2012_val_00035727.bin 224 224 +18983 ./prep_dataset/ILSVRC2012_val_00043121.bin 224 224 +18984 ./prep_dataset/ILSVRC2012_val_00026816.bin 224 224 +18985 ./prep_dataset/ILSVRC2012_val_00039002.bin 224 224 +18986 ./prep_dataset/ILSVRC2012_val_00008171.bin 224 224 +18987 ./prep_dataset/ILSVRC2012_val_00009731.bin 224 224 +18988 ./prep_dataset/ILSVRC2012_val_00033250.bin 224 224 +18989 ./prep_dataset/ILSVRC2012_val_00042921.bin 224 224 +18990 ./prep_dataset/ILSVRC2012_val_00048296.bin 224 224 +18991 ./prep_dataset/ILSVRC2012_val_00015013.bin 224 224 +18992 ./prep_dataset/ILSVRC2012_val_00019499.bin 224 224 +18993 ./prep_dataset/ILSVRC2012_val_00031574.bin 224 224 +18994 ./prep_dataset/ILSVRC2012_val_00048447.bin 224 224 +18995 ./prep_dataset/ILSVRC2012_val_00032211.bin 224 224 +18996 ./prep_dataset/ILSVRC2012_val_00031600.bin 224 224 +18997 ./prep_dataset/ILSVRC2012_val_00010185.bin 224 224 +18998 ./prep_dataset/ILSVRC2012_val_00035440.bin 224 224 +18999 ./prep_dataset/ILSVRC2012_val_00020045.bin 224 224 +19000 ./prep_dataset/ILSVRC2012_val_00016561.bin 224 224 +19001 ./prep_dataset/ILSVRC2012_val_00043895.bin 224 224 +19002 ./prep_dataset/ILSVRC2012_val_00045826.bin 224 224 +19003 ./prep_dataset/ILSVRC2012_val_00026351.bin 224 224 +19004 ./prep_dataset/ILSVRC2012_val_00011962.bin 224 224 +19005 ./prep_dataset/ILSVRC2012_val_00038013.bin 224 224 +19006 ./prep_dataset/ILSVRC2012_val_00040529.bin 224 224 +19007 ./prep_dataset/ILSVRC2012_val_00048742.bin 224 224 +19008 ./prep_dataset/ILSVRC2012_val_00006350.bin 224 224 +19009 ./prep_dataset/ILSVRC2012_val_00011612.bin 224 224 +19010 ./prep_dataset/ILSVRC2012_val_00024378.bin 224 224 +19011 ./prep_dataset/ILSVRC2012_val_00044954.bin 224 224 +19012 ./prep_dataset/ILSVRC2012_val_00008565.bin 224 224 +19013 ./prep_dataset/ILSVRC2012_val_00026336.bin 224 224 +19014 ./prep_dataset/ILSVRC2012_val_00038462.bin 224 224 +19015 ./prep_dataset/ILSVRC2012_val_00002107.bin 224 224 +19016 ./prep_dataset/ILSVRC2012_val_00038565.bin 224 224 +19017 ./prep_dataset/ILSVRC2012_val_00035259.bin 224 224 +19018 ./prep_dataset/ILSVRC2012_val_00046986.bin 224 224 +19019 ./prep_dataset/ILSVRC2012_val_00044717.bin 224 224 +19020 ./prep_dataset/ILSVRC2012_val_00047087.bin 224 224 +19021 ./prep_dataset/ILSVRC2012_val_00041046.bin 224 224 +19022 ./prep_dataset/ILSVRC2012_val_00020791.bin 224 224 +19023 ./prep_dataset/ILSVRC2012_val_00038345.bin 224 224 +19024 ./prep_dataset/ILSVRC2012_val_00000160.bin 224 224 +19025 ./prep_dataset/ILSVRC2012_val_00032648.bin 224 224 +19026 ./prep_dataset/ILSVRC2012_val_00027187.bin 224 224 +19027 ./prep_dataset/ILSVRC2012_val_00000213.bin 224 224 +19028 ./prep_dataset/ILSVRC2012_val_00009293.bin 224 224 +19029 ./prep_dataset/ILSVRC2012_val_00033663.bin 224 224 +19030 ./prep_dataset/ILSVRC2012_val_00012758.bin 224 224 +19031 ./prep_dataset/ILSVRC2012_val_00037356.bin 224 224 +19032 ./prep_dataset/ILSVRC2012_val_00018054.bin 224 224 +19033 ./prep_dataset/ILSVRC2012_val_00033683.bin 224 224 +19034 ./prep_dataset/ILSVRC2012_val_00015452.bin 224 224 +19035 ./prep_dataset/ILSVRC2012_val_00018340.bin 224 224 +19036 ./prep_dataset/ILSVRC2012_val_00045463.bin 224 224 +19037 ./prep_dataset/ILSVRC2012_val_00029437.bin 224 224 +19038 ./prep_dataset/ILSVRC2012_val_00026706.bin 224 224 +19039 ./prep_dataset/ILSVRC2012_val_00037764.bin 224 224 +19040 ./prep_dataset/ILSVRC2012_val_00008956.bin 224 224 +19041 ./prep_dataset/ILSVRC2012_val_00042598.bin 224 224 +19042 ./prep_dataset/ILSVRC2012_val_00035806.bin 224 224 +19043 ./prep_dataset/ILSVRC2012_val_00025814.bin 224 224 +19044 ./prep_dataset/ILSVRC2012_val_00039152.bin 224 224 +19045 ./prep_dataset/ILSVRC2012_val_00015730.bin 224 224 +19046 ./prep_dataset/ILSVRC2012_val_00013228.bin 224 224 +19047 ./prep_dataset/ILSVRC2012_val_00032552.bin 224 224 +19048 ./prep_dataset/ILSVRC2012_val_00015091.bin 224 224 +19049 ./prep_dataset/ILSVRC2012_val_00014882.bin 224 224 +19050 ./prep_dataset/ILSVRC2012_val_00032146.bin 224 224 +19051 ./prep_dataset/ILSVRC2012_val_00037853.bin 224 224 +19052 ./prep_dataset/ILSVRC2012_val_00044760.bin 224 224 +19053 ./prep_dataset/ILSVRC2012_val_00047484.bin 224 224 +19054 ./prep_dataset/ILSVRC2012_val_00009385.bin 224 224 +19055 ./prep_dataset/ILSVRC2012_val_00025207.bin 224 224 +19056 ./prep_dataset/ILSVRC2012_val_00010621.bin 224 224 +19057 ./prep_dataset/ILSVRC2012_val_00049585.bin 224 224 +19058 ./prep_dataset/ILSVRC2012_val_00046476.bin 224 224 +19059 ./prep_dataset/ILSVRC2012_val_00048463.bin 224 224 +19060 ./prep_dataset/ILSVRC2012_val_00047024.bin 224 224 +19061 ./prep_dataset/ILSVRC2012_val_00037076.bin 224 224 +19062 ./prep_dataset/ILSVRC2012_val_00009357.bin 224 224 +19063 ./prep_dataset/ILSVRC2012_val_00010813.bin 224 224 +19064 ./prep_dataset/ILSVRC2012_val_00000572.bin 224 224 +19065 ./prep_dataset/ILSVRC2012_val_00004125.bin 224 224 +19066 ./prep_dataset/ILSVRC2012_val_00047986.bin 224 224 +19067 ./prep_dataset/ILSVRC2012_val_00033849.bin 224 224 +19068 ./prep_dataset/ILSVRC2012_val_00011585.bin 224 224 +19069 ./prep_dataset/ILSVRC2012_val_00022139.bin 224 224 +19070 ./prep_dataset/ILSVRC2012_val_00014404.bin 224 224 +19071 ./prep_dataset/ILSVRC2012_val_00036622.bin 224 224 +19072 ./prep_dataset/ILSVRC2012_val_00012017.bin 224 224 +19073 ./prep_dataset/ILSVRC2012_val_00027902.bin 224 224 +19074 ./prep_dataset/ILSVRC2012_val_00010885.bin 224 224 +19075 ./prep_dataset/ILSVRC2012_val_00013446.bin 224 224 +19076 ./prep_dataset/ILSVRC2012_val_00016571.bin 224 224 +19077 ./prep_dataset/ILSVRC2012_val_00003351.bin 224 224 +19078 ./prep_dataset/ILSVRC2012_val_00005320.bin 224 224 +19079 ./prep_dataset/ILSVRC2012_val_00007258.bin 224 224 +19080 ./prep_dataset/ILSVRC2012_val_00008609.bin 224 224 +19081 ./prep_dataset/ILSVRC2012_val_00004738.bin 224 224 +19082 ./prep_dataset/ILSVRC2012_val_00023468.bin 224 224 +19083 ./prep_dataset/ILSVRC2012_val_00004838.bin 224 224 +19084 ./prep_dataset/ILSVRC2012_val_00023094.bin 224 224 +19085 ./prep_dataset/ILSVRC2012_val_00043646.bin 224 224 +19086 ./prep_dataset/ILSVRC2012_val_00037160.bin 224 224 +19087 ./prep_dataset/ILSVRC2012_val_00019959.bin 224 224 +19088 ./prep_dataset/ILSVRC2012_val_00040927.bin 224 224 +19089 ./prep_dataset/ILSVRC2012_val_00035211.bin 224 224 +19090 ./prep_dataset/ILSVRC2012_val_00029314.bin 224 224 +19091 ./prep_dataset/ILSVRC2012_val_00038694.bin 224 224 +19092 ./prep_dataset/ILSVRC2012_val_00042226.bin 224 224 +19093 ./prep_dataset/ILSVRC2012_val_00030486.bin 224 224 +19094 ./prep_dataset/ILSVRC2012_val_00031706.bin 224 224 +19095 ./prep_dataset/ILSVRC2012_val_00030121.bin 224 224 +19096 ./prep_dataset/ILSVRC2012_val_00049823.bin 224 224 +19097 ./prep_dataset/ILSVRC2012_val_00010550.bin 224 224 +19098 ./prep_dataset/ILSVRC2012_val_00032532.bin 224 224 +19099 ./prep_dataset/ILSVRC2012_val_00034090.bin 224 224 +19100 ./prep_dataset/ILSVRC2012_val_00001742.bin 224 224 +19101 ./prep_dataset/ILSVRC2012_val_00024651.bin 224 224 +19102 ./prep_dataset/ILSVRC2012_val_00009164.bin 224 224 +19103 ./prep_dataset/ILSVRC2012_val_00018141.bin 224 224 +19104 ./prep_dataset/ILSVRC2012_val_00033485.bin 224 224 +19105 ./prep_dataset/ILSVRC2012_val_00024243.bin 224 224 +19106 ./prep_dataset/ILSVRC2012_val_00025598.bin 224 224 +19107 ./prep_dataset/ILSVRC2012_val_00048760.bin 224 224 +19108 ./prep_dataset/ILSVRC2012_val_00005586.bin 224 224 +19109 ./prep_dataset/ILSVRC2012_val_00013480.bin 224 224 +19110 ./prep_dataset/ILSVRC2012_val_00023341.bin 224 224 +19111 ./prep_dataset/ILSVRC2012_val_00044395.bin 224 224 +19112 ./prep_dataset/ILSVRC2012_val_00024584.bin 224 224 +19113 ./prep_dataset/ILSVRC2012_val_00047418.bin 224 224 +19114 ./prep_dataset/ILSVRC2012_val_00030675.bin 224 224 +19115 ./prep_dataset/ILSVRC2012_val_00005476.bin 224 224 +19116 ./prep_dataset/ILSVRC2012_val_00009031.bin 224 224 +19117 ./prep_dataset/ILSVRC2012_val_00006398.bin 224 224 +19118 ./prep_dataset/ILSVRC2012_val_00004062.bin 224 224 +19119 ./prep_dataset/ILSVRC2012_val_00035959.bin 224 224 +19120 ./prep_dataset/ILSVRC2012_val_00037153.bin 224 224 +19121 ./prep_dataset/ILSVRC2012_val_00022395.bin 224 224 +19122 ./prep_dataset/ILSVRC2012_val_00012704.bin 224 224 +19123 ./prep_dataset/ILSVRC2012_val_00047221.bin 224 224 +19124 ./prep_dataset/ILSVRC2012_val_00018256.bin 224 224 +19125 ./prep_dataset/ILSVRC2012_val_00016567.bin 224 224 +19126 ./prep_dataset/ILSVRC2012_val_00044575.bin 224 224 +19127 ./prep_dataset/ILSVRC2012_val_00039709.bin 224 224 +19128 ./prep_dataset/ILSVRC2012_val_00047276.bin 224 224 +19129 ./prep_dataset/ILSVRC2012_val_00034293.bin 224 224 +19130 ./prep_dataset/ILSVRC2012_val_00049954.bin 224 224 +19131 ./prep_dataset/ILSVRC2012_val_00046709.bin 224 224 +19132 ./prep_dataset/ILSVRC2012_val_00041087.bin 224 224 +19133 ./prep_dataset/ILSVRC2012_val_00021693.bin 224 224 +19134 ./prep_dataset/ILSVRC2012_val_00036833.bin 224 224 +19135 ./prep_dataset/ILSVRC2012_val_00041921.bin 224 224 +19136 ./prep_dataset/ILSVRC2012_val_00023168.bin 224 224 +19137 ./prep_dataset/ILSVRC2012_val_00022764.bin 224 224 +19138 ./prep_dataset/ILSVRC2012_val_00042548.bin 224 224 +19139 ./prep_dataset/ILSVRC2012_val_00035270.bin 224 224 +19140 ./prep_dataset/ILSVRC2012_val_00045365.bin 224 224 +19141 ./prep_dataset/ILSVRC2012_val_00041640.bin 224 224 +19142 ./prep_dataset/ILSVRC2012_val_00006737.bin 224 224 +19143 ./prep_dataset/ILSVRC2012_val_00035611.bin 224 224 +19144 ./prep_dataset/ILSVRC2012_val_00044877.bin 224 224 +19145 ./prep_dataset/ILSVRC2012_val_00005062.bin 224 224 +19146 ./prep_dataset/ILSVRC2012_val_00022985.bin 224 224 +19147 ./prep_dataset/ILSVRC2012_val_00045393.bin 224 224 +19148 ./prep_dataset/ILSVRC2012_val_00024999.bin 224 224 +19149 ./prep_dataset/ILSVRC2012_val_00037563.bin 224 224 +19150 ./prep_dataset/ILSVRC2012_val_00038570.bin 224 224 +19151 ./prep_dataset/ILSVRC2012_val_00007199.bin 224 224 +19152 ./prep_dataset/ILSVRC2012_val_00025604.bin 224 224 +19153 ./prep_dataset/ILSVRC2012_val_00023509.bin 224 224 +19154 ./prep_dataset/ILSVRC2012_val_00045516.bin 224 224 +19155 ./prep_dataset/ILSVRC2012_val_00021568.bin 224 224 +19156 ./prep_dataset/ILSVRC2012_val_00031281.bin 224 224 +19157 ./prep_dataset/ILSVRC2012_val_00049162.bin 224 224 +19158 ./prep_dataset/ILSVRC2012_val_00027796.bin 224 224 +19159 ./prep_dataset/ILSVRC2012_val_00024903.bin 224 224 +19160 ./prep_dataset/ILSVRC2012_val_00008187.bin 224 224 +19161 ./prep_dataset/ILSVRC2012_val_00014809.bin 224 224 +19162 ./prep_dataset/ILSVRC2012_val_00008937.bin 224 224 +19163 ./prep_dataset/ILSVRC2012_val_00040576.bin 224 224 +19164 ./prep_dataset/ILSVRC2012_val_00025495.bin 224 224 +19165 ./prep_dataset/ILSVRC2012_val_00012536.bin 224 224 +19166 ./prep_dataset/ILSVRC2012_val_00018787.bin 224 224 +19167 ./prep_dataset/ILSVRC2012_val_00042044.bin 224 224 +19168 ./prep_dataset/ILSVRC2012_val_00021047.bin 224 224 +19169 ./prep_dataset/ILSVRC2012_val_00018425.bin 224 224 +19170 ./prep_dataset/ILSVRC2012_val_00033038.bin 224 224 +19171 ./prep_dataset/ILSVRC2012_val_00033448.bin 224 224 +19172 ./prep_dataset/ILSVRC2012_val_00048448.bin 224 224 +19173 ./prep_dataset/ILSVRC2012_val_00049638.bin 224 224 +19174 ./prep_dataset/ILSVRC2012_val_00048168.bin 224 224 +19175 ./prep_dataset/ILSVRC2012_val_00002368.bin 224 224 +19176 ./prep_dataset/ILSVRC2012_val_00010569.bin 224 224 +19177 ./prep_dataset/ILSVRC2012_val_00016449.bin 224 224 +19178 ./prep_dataset/ILSVRC2012_val_00040477.bin 224 224 +19179 ./prep_dataset/ILSVRC2012_val_00020693.bin 224 224 +19180 ./prep_dataset/ILSVRC2012_val_00004432.bin 224 224 +19181 ./prep_dataset/ILSVRC2012_val_00018746.bin 224 224 +19182 ./prep_dataset/ILSVRC2012_val_00049046.bin 224 224 +19183 ./prep_dataset/ILSVRC2012_val_00025181.bin 224 224 +19184 ./prep_dataset/ILSVRC2012_val_00041716.bin 224 224 +19185 ./prep_dataset/ILSVRC2012_val_00019768.bin 224 224 +19186 ./prep_dataset/ILSVRC2012_val_00008268.bin 224 224 +19187 ./prep_dataset/ILSVRC2012_val_00006632.bin 224 224 +19188 ./prep_dataset/ILSVRC2012_val_00049386.bin 224 224 +19189 ./prep_dataset/ILSVRC2012_val_00026825.bin 224 224 +19190 ./prep_dataset/ILSVRC2012_val_00049805.bin 224 224 +19191 ./prep_dataset/ILSVRC2012_val_00008172.bin 224 224 +19192 ./prep_dataset/ILSVRC2012_val_00023725.bin 224 224 +19193 ./prep_dataset/ILSVRC2012_val_00018505.bin 224 224 +19194 ./prep_dataset/ILSVRC2012_val_00042030.bin 224 224 +19195 ./prep_dataset/ILSVRC2012_val_00032806.bin 224 224 +19196 ./prep_dataset/ILSVRC2012_val_00001513.bin 224 224 +19197 ./prep_dataset/ILSVRC2012_val_00028736.bin 224 224 +19198 ./prep_dataset/ILSVRC2012_val_00011076.bin 224 224 +19199 ./prep_dataset/ILSVRC2012_val_00035285.bin 224 224 +19200 ./prep_dataset/ILSVRC2012_val_00012750.bin 224 224 +19201 ./prep_dataset/ILSVRC2012_val_00037948.bin 224 224 +19202 ./prep_dataset/ILSVRC2012_val_00002870.bin 224 224 +19203 ./prep_dataset/ILSVRC2012_val_00048270.bin 224 224 +19204 ./prep_dataset/ILSVRC2012_val_00003152.bin 224 224 +19205 ./prep_dataset/ILSVRC2012_val_00042917.bin 224 224 +19206 ./prep_dataset/ILSVRC2012_val_00032584.bin 224 224 +19207 ./prep_dataset/ILSVRC2012_val_00010205.bin 224 224 +19208 ./prep_dataset/ILSVRC2012_val_00034146.bin 224 224 +19209 ./prep_dataset/ILSVRC2012_val_00007943.bin 224 224 +19210 ./prep_dataset/ILSVRC2012_val_00026795.bin 224 224 +19211 ./prep_dataset/ILSVRC2012_val_00012030.bin 224 224 +19212 ./prep_dataset/ILSVRC2012_val_00029902.bin 224 224 +19213 ./prep_dataset/ILSVRC2012_val_00018277.bin 224 224 +19214 ./prep_dataset/ILSVRC2012_val_00048582.bin 224 224 +19215 ./prep_dataset/ILSVRC2012_val_00008528.bin 224 224 +19216 ./prep_dataset/ILSVRC2012_val_00043362.bin 224 224 +19217 ./prep_dataset/ILSVRC2012_val_00010727.bin 224 224 +19218 ./prep_dataset/ILSVRC2012_val_00008802.bin 224 224 +19219 ./prep_dataset/ILSVRC2012_val_00001118.bin 224 224 +19220 ./prep_dataset/ILSVRC2012_val_00037205.bin 224 224 +19221 ./prep_dataset/ILSVRC2012_val_00037188.bin 224 224 +19222 ./prep_dataset/ILSVRC2012_val_00012391.bin 224 224 +19223 ./prep_dataset/ILSVRC2012_val_00026114.bin 224 224 +19224 ./prep_dataset/ILSVRC2012_val_00041362.bin 224 224 +19225 ./prep_dataset/ILSVRC2012_val_00022701.bin 224 224 +19226 ./prep_dataset/ILSVRC2012_val_00036700.bin 224 224 +19227 ./prep_dataset/ILSVRC2012_val_00017866.bin 224 224 +19228 ./prep_dataset/ILSVRC2012_val_00041324.bin 224 224 +19229 ./prep_dataset/ILSVRC2012_val_00026554.bin 224 224 +19230 ./prep_dataset/ILSVRC2012_val_00001648.bin 224 224 +19231 ./prep_dataset/ILSVRC2012_val_00001482.bin 224 224 +19232 ./prep_dataset/ILSVRC2012_val_00042616.bin 224 224 +19233 ./prep_dataset/ILSVRC2012_val_00046042.bin 224 224 +19234 ./prep_dataset/ILSVRC2012_val_00018101.bin 224 224 +19235 ./prep_dataset/ILSVRC2012_val_00048868.bin 224 224 +19236 ./prep_dataset/ILSVRC2012_val_00025226.bin 224 224 +19237 ./prep_dataset/ILSVRC2012_val_00024769.bin 224 224 +19238 ./prep_dataset/ILSVRC2012_val_00026574.bin 224 224 +19239 ./prep_dataset/ILSVRC2012_val_00015065.bin 224 224 +19240 ./prep_dataset/ILSVRC2012_val_00014102.bin 224 224 +19241 ./prep_dataset/ILSVRC2012_val_00029197.bin 224 224 +19242 ./prep_dataset/ILSVRC2012_val_00009838.bin 224 224 +19243 ./prep_dataset/ILSVRC2012_val_00009253.bin 224 224 +19244 ./prep_dataset/ILSVRC2012_val_00041241.bin 224 224 +19245 ./prep_dataset/ILSVRC2012_val_00017448.bin 224 224 +19246 ./prep_dataset/ILSVRC2012_val_00022832.bin 224 224 +19247 ./prep_dataset/ILSVRC2012_val_00022994.bin 224 224 +19248 ./prep_dataset/ILSVRC2012_val_00043273.bin 224 224 +19249 ./prep_dataset/ILSVRC2012_val_00034876.bin 224 224 +19250 ./prep_dataset/ILSVRC2012_val_00024855.bin 224 224 +19251 ./prep_dataset/ILSVRC2012_val_00013547.bin 224 224 +19252 ./prep_dataset/ILSVRC2012_val_00001317.bin 224 224 +19253 ./prep_dataset/ILSVRC2012_val_00038927.bin 224 224 +19254 ./prep_dataset/ILSVRC2012_val_00008438.bin 224 224 +19255 ./prep_dataset/ILSVRC2012_val_00014216.bin 224 224 +19256 ./prep_dataset/ILSVRC2012_val_00040123.bin 224 224 +19257 ./prep_dataset/ILSVRC2012_val_00012979.bin 224 224 +19258 ./prep_dataset/ILSVRC2012_val_00014967.bin 224 224 +19259 ./prep_dataset/ILSVRC2012_val_00019515.bin 224 224 +19260 ./prep_dataset/ILSVRC2012_val_00020794.bin 224 224 +19261 ./prep_dataset/ILSVRC2012_val_00043113.bin 224 224 +19262 ./prep_dataset/ILSVRC2012_val_00042934.bin 224 224 +19263 ./prep_dataset/ILSVRC2012_val_00034795.bin 224 224 +19264 ./prep_dataset/ILSVRC2012_val_00002950.bin 224 224 +19265 ./prep_dataset/ILSVRC2012_val_00024282.bin 224 224 +19266 ./prep_dataset/ILSVRC2012_val_00000826.bin 224 224 +19267 ./prep_dataset/ILSVRC2012_val_00031703.bin 224 224 +19268 ./prep_dataset/ILSVRC2012_val_00042390.bin 224 224 +19269 ./prep_dataset/ILSVRC2012_val_00011624.bin 224 224 +19270 ./prep_dataset/ILSVRC2012_val_00021381.bin 224 224 +19271 ./prep_dataset/ILSVRC2012_val_00046030.bin 224 224 +19272 ./prep_dataset/ILSVRC2012_val_00012621.bin 224 224 +19273 ./prep_dataset/ILSVRC2012_val_00045475.bin 224 224 +19274 ./prep_dataset/ILSVRC2012_val_00001747.bin 224 224 +19275 ./prep_dataset/ILSVRC2012_val_00037392.bin 224 224 +19276 ./prep_dataset/ILSVRC2012_val_00043783.bin 224 224 +19277 ./prep_dataset/ILSVRC2012_val_00015723.bin 224 224 +19278 ./prep_dataset/ILSVRC2012_val_00003411.bin 224 224 +19279 ./prep_dataset/ILSVRC2012_val_00037728.bin 224 224 +19280 ./prep_dataset/ILSVRC2012_val_00039586.bin 224 224 +19281 ./prep_dataset/ILSVRC2012_val_00046782.bin 224 224 +19282 ./prep_dataset/ILSVRC2012_val_00006560.bin 224 224 +19283 ./prep_dataset/ILSVRC2012_val_00033602.bin 224 224 +19284 ./prep_dataset/ILSVRC2012_val_00027350.bin 224 224 +19285 ./prep_dataset/ILSVRC2012_val_00024575.bin 224 224 +19286 ./prep_dataset/ILSVRC2012_val_00020996.bin 224 224 +19287 ./prep_dataset/ILSVRC2012_val_00033285.bin 224 224 +19288 ./prep_dataset/ILSVRC2012_val_00011185.bin 224 224 +19289 ./prep_dataset/ILSVRC2012_val_00025998.bin 224 224 +19290 ./prep_dataset/ILSVRC2012_val_00000626.bin 224 224 +19291 ./prep_dataset/ILSVRC2012_val_00048988.bin 224 224 +19292 ./prep_dataset/ILSVRC2012_val_00033508.bin 224 224 +19293 ./prep_dataset/ILSVRC2012_val_00008186.bin 224 224 +19294 ./prep_dataset/ILSVRC2012_val_00005725.bin 224 224 +19295 ./prep_dataset/ILSVRC2012_val_00031535.bin 224 224 +19296 ./prep_dataset/ILSVRC2012_val_00008037.bin 224 224 +19297 ./prep_dataset/ILSVRC2012_val_00049597.bin 224 224 +19298 ./prep_dataset/ILSVRC2012_val_00022968.bin 224 224 +19299 ./prep_dataset/ILSVRC2012_val_00047411.bin 224 224 +19300 ./prep_dataset/ILSVRC2012_val_00041234.bin 224 224 +19301 ./prep_dataset/ILSVRC2012_val_00015243.bin 224 224 +19302 ./prep_dataset/ILSVRC2012_val_00036863.bin 224 224 +19303 ./prep_dataset/ILSVRC2012_val_00002347.bin 224 224 +19304 ./prep_dataset/ILSVRC2012_val_00000866.bin 224 224 +19305 ./prep_dataset/ILSVRC2012_val_00047183.bin 224 224 +19306 ./prep_dataset/ILSVRC2012_val_00037027.bin 224 224 +19307 ./prep_dataset/ILSVRC2012_val_00031921.bin 224 224 +19308 ./prep_dataset/ILSVRC2012_val_00037581.bin 224 224 +19309 ./prep_dataset/ILSVRC2012_val_00018273.bin 224 224 +19310 ./prep_dataset/ILSVRC2012_val_00001195.bin 224 224 +19311 ./prep_dataset/ILSVRC2012_val_00037900.bin 224 224 +19312 ./prep_dataset/ILSVRC2012_val_00033194.bin 224 224 +19313 ./prep_dataset/ILSVRC2012_val_00022987.bin 224 224 +19314 ./prep_dataset/ILSVRC2012_val_00020714.bin 224 224 +19315 ./prep_dataset/ILSVRC2012_val_00032618.bin 224 224 +19316 ./prep_dataset/ILSVRC2012_val_00037773.bin 224 224 +19317 ./prep_dataset/ILSVRC2012_val_00043848.bin 224 224 +19318 ./prep_dataset/ILSVRC2012_val_00001791.bin 224 224 +19319 ./prep_dataset/ILSVRC2012_val_00014533.bin 224 224 +19320 ./prep_dataset/ILSVRC2012_val_00026250.bin 224 224 +19321 ./prep_dataset/ILSVRC2012_val_00041489.bin 224 224 +19322 ./prep_dataset/ILSVRC2012_val_00012064.bin 224 224 +19323 ./prep_dataset/ILSVRC2012_val_00019000.bin 224 224 +19324 ./prep_dataset/ILSVRC2012_val_00021798.bin 224 224 +19325 ./prep_dataset/ILSVRC2012_val_00031335.bin 224 224 +19326 ./prep_dataset/ILSVRC2012_val_00042549.bin 224 224 +19327 ./prep_dataset/ILSVRC2012_val_00026316.bin 224 224 +19328 ./prep_dataset/ILSVRC2012_val_00010192.bin 224 224 +19329 ./prep_dataset/ILSVRC2012_val_00030389.bin 224 224 +19330 ./prep_dataset/ILSVRC2012_val_00047324.bin 224 224 +19331 ./prep_dataset/ILSVRC2012_val_00029124.bin 224 224 +19332 ./prep_dataset/ILSVRC2012_val_00011079.bin 224 224 +19333 ./prep_dataset/ILSVRC2012_val_00025633.bin 224 224 +19334 ./prep_dataset/ILSVRC2012_val_00008713.bin 224 224 +19335 ./prep_dataset/ILSVRC2012_val_00030148.bin 224 224 +19336 ./prep_dataset/ILSVRC2012_val_00033532.bin 224 224 +19337 ./prep_dataset/ILSVRC2012_val_00017250.bin 224 224 +19338 ./prep_dataset/ILSVRC2012_val_00030209.bin 224 224 +19339 ./prep_dataset/ILSVRC2012_val_00037757.bin 224 224 +19340 ./prep_dataset/ILSVRC2012_val_00009196.bin 224 224 +19341 ./prep_dataset/ILSVRC2012_val_00031745.bin 224 224 +19342 ./prep_dataset/ILSVRC2012_val_00005247.bin 224 224 +19343 ./prep_dataset/ILSVRC2012_val_00046458.bin 224 224 +19344 ./prep_dataset/ILSVRC2012_val_00043482.bin 224 224 +19345 ./prep_dataset/ILSVRC2012_val_00041462.bin 224 224 +19346 ./prep_dataset/ILSVRC2012_val_00040872.bin 224 224 +19347 ./prep_dataset/ILSVRC2012_val_00021644.bin 224 224 +19348 ./prep_dataset/ILSVRC2012_val_00042126.bin 224 224 +19349 ./prep_dataset/ILSVRC2012_val_00003900.bin 224 224 +19350 ./prep_dataset/ILSVRC2012_val_00003702.bin 224 224 +19351 ./prep_dataset/ILSVRC2012_val_00035236.bin 224 224 +19352 ./prep_dataset/ILSVRC2012_val_00049426.bin 224 224 +19353 ./prep_dataset/ILSVRC2012_val_00041929.bin 224 224 +19354 ./prep_dataset/ILSVRC2012_val_00025067.bin 224 224 +19355 ./prep_dataset/ILSVRC2012_val_00030283.bin 224 224 +19356 ./prep_dataset/ILSVRC2012_val_00021138.bin 224 224 +19357 ./prep_dataset/ILSVRC2012_val_00001241.bin 224 224 +19358 ./prep_dataset/ILSVRC2012_val_00040479.bin 224 224 +19359 ./prep_dataset/ILSVRC2012_val_00041164.bin 224 224 +19360 ./prep_dataset/ILSVRC2012_val_00025939.bin 224 224 +19361 ./prep_dataset/ILSVRC2012_val_00001883.bin 224 224 +19362 ./prep_dataset/ILSVRC2012_val_00040278.bin 224 224 +19363 ./prep_dataset/ILSVRC2012_val_00021976.bin 224 224 +19364 ./prep_dataset/ILSVRC2012_val_00012110.bin 224 224 +19365 ./prep_dataset/ILSVRC2012_val_00015218.bin 224 224 +19366 ./prep_dataset/ILSVRC2012_val_00047229.bin 224 224 +19367 ./prep_dataset/ILSVRC2012_val_00016055.bin 224 224 +19368 ./prep_dataset/ILSVRC2012_val_00023291.bin 224 224 +19369 ./prep_dataset/ILSVRC2012_val_00027586.bin 224 224 +19370 ./prep_dataset/ILSVRC2012_val_00042534.bin 224 224 +19371 ./prep_dataset/ILSVRC2012_val_00024951.bin 224 224 +19372 ./prep_dataset/ILSVRC2012_val_00031349.bin 224 224 +19373 ./prep_dataset/ILSVRC2012_val_00036685.bin 224 224 +19374 ./prep_dataset/ILSVRC2012_val_00027807.bin 224 224 +19375 ./prep_dataset/ILSVRC2012_val_00022671.bin 224 224 +19376 ./prep_dataset/ILSVRC2012_val_00039819.bin 224 224 +19377 ./prep_dataset/ILSVRC2012_val_00014486.bin 224 224 +19378 ./prep_dataset/ILSVRC2012_val_00015980.bin 224 224 +19379 ./prep_dataset/ILSVRC2012_val_00001156.bin 224 224 +19380 ./prep_dataset/ILSVRC2012_val_00031149.bin 224 224 +19381 ./prep_dataset/ILSVRC2012_val_00044319.bin 224 224 +19382 ./prep_dataset/ILSVRC2012_val_00012881.bin 224 224 +19383 ./prep_dataset/ILSVRC2012_val_00045509.bin 224 224 +19384 ./prep_dataset/ILSVRC2012_val_00038591.bin 224 224 +19385 ./prep_dataset/ILSVRC2012_val_00003709.bin 224 224 +19386 ./prep_dataset/ILSVRC2012_val_00034281.bin 224 224 +19387 ./prep_dataset/ILSVRC2012_val_00023060.bin 224 224 +19388 ./prep_dataset/ILSVRC2012_val_00020774.bin 224 224 +19389 ./prep_dataset/ILSVRC2012_val_00005311.bin 224 224 +19390 ./prep_dataset/ILSVRC2012_val_00023837.bin 224 224 +19391 ./prep_dataset/ILSVRC2012_val_00006110.bin 224 224 +19392 ./prep_dataset/ILSVRC2012_val_00043442.bin 224 224 +19393 ./prep_dataset/ILSVRC2012_val_00021413.bin 224 224 +19394 ./prep_dataset/ILSVRC2012_val_00035848.bin 224 224 +19395 ./prep_dataset/ILSVRC2012_val_00033086.bin 224 224 +19396 ./prep_dataset/ILSVRC2012_val_00034421.bin 224 224 +19397 ./prep_dataset/ILSVRC2012_val_00025412.bin 224 224 +19398 ./prep_dataset/ILSVRC2012_val_00040314.bin 224 224 +19399 ./prep_dataset/ILSVRC2012_val_00002983.bin 224 224 +19400 ./prep_dataset/ILSVRC2012_val_00035682.bin 224 224 +19401 ./prep_dataset/ILSVRC2012_val_00007863.bin 224 224 +19402 ./prep_dataset/ILSVRC2012_val_00008644.bin 224 224 +19403 ./prep_dataset/ILSVRC2012_val_00003473.bin 224 224 +19404 ./prep_dataset/ILSVRC2012_val_00013240.bin 224 224 +19405 ./prep_dataset/ILSVRC2012_val_00038058.bin 224 224 +19406 ./prep_dataset/ILSVRC2012_val_00032099.bin 224 224 +19407 ./prep_dataset/ILSVRC2012_val_00047787.bin 224 224 +19408 ./prep_dataset/ILSVRC2012_val_00025253.bin 224 224 +19409 ./prep_dataset/ILSVRC2012_val_00028395.bin 224 224 +19410 ./prep_dataset/ILSVRC2012_val_00028475.bin 224 224 +19411 ./prep_dataset/ILSVRC2012_val_00010468.bin 224 224 +19412 ./prep_dataset/ILSVRC2012_val_00045951.bin 224 224 +19413 ./prep_dataset/ILSVRC2012_val_00014427.bin 224 224 +19414 ./prep_dataset/ILSVRC2012_val_00042918.bin 224 224 +19415 ./prep_dataset/ILSVRC2012_val_00014175.bin 224 224 +19416 ./prep_dataset/ILSVRC2012_val_00035152.bin 224 224 +19417 ./prep_dataset/ILSVRC2012_val_00027170.bin 224 224 +19418 ./prep_dataset/ILSVRC2012_val_00032729.bin 224 224 +19419 ./prep_dataset/ILSVRC2012_val_00022566.bin 224 224 +19420 ./prep_dataset/ILSVRC2012_val_00022835.bin 224 224 +19421 ./prep_dataset/ILSVRC2012_val_00028980.bin 224 224 +19422 ./prep_dataset/ILSVRC2012_val_00045892.bin 224 224 +19423 ./prep_dataset/ILSVRC2012_val_00030954.bin 224 224 +19424 ./prep_dataset/ILSVRC2012_val_00040846.bin 224 224 +19425 ./prep_dataset/ILSVRC2012_val_00016820.bin 224 224 +19426 ./prep_dataset/ILSVRC2012_val_00000837.bin 224 224 +19427 ./prep_dataset/ILSVRC2012_val_00012818.bin 224 224 +19428 ./prep_dataset/ILSVRC2012_val_00004066.bin 224 224 +19429 ./prep_dataset/ILSVRC2012_val_00006317.bin 224 224 +19430 ./prep_dataset/ILSVRC2012_val_00049261.bin 224 224 +19431 ./prep_dataset/ILSVRC2012_val_00006910.bin 224 224 +19432 ./prep_dataset/ILSVRC2012_val_00022905.bin 224 224 +19433 ./prep_dataset/ILSVRC2012_val_00032423.bin 224 224 +19434 ./prep_dataset/ILSVRC2012_val_00026458.bin 224 224 +19435 ./prep_dataset/ILSVRC2012_val_00039392.bin 224 224 +19436 ./prep_dataset/ILSVRC2012_val_00002290.bin 224 224 +19437 ./prep_dataset/ILSVRC2012_val_00003394.bin 224 224 +19438 ./prep_dataset/ILSVRC2012_val_00029040.bin 224 224 +19439 ./prep_dataset/ILSVRC2012_val_00012871.bin 224 224 +19440 ./prep_dataset/ILSVRC2012_val_00033605.bin 224 224 +19441 ./prep_dataset/ILSVRC2012_val_00038433.bin 224 224 +19442 ./prep_dataset/ILSVRC2012_val_00004366.bin 224 224 +19443 ./prep_dataset/ILSVRC2012_val_00035673.bin 224 224 +19444 ./prep_dataset/ILSVRC2012_val_00008193.bin 224 224 +19445 ./prep_dataset/ILSVRC2012_val_00031500.bin 224 224 +19446 ./prep_dataset/ILSVRC2012_val_00037963.bin 224 224 +19447 ./prep_dataset/ILSVRC2012_val_00041271.bin 224 224 +19448 ./prep_dataset/ILSVRC2012_val_00036328.bin 224 224 +19449 ./prep_dataset/ILSVRC2012_val_00002905.bin 224 224 +19450 ./prep_dataset/ILSVRC2012_val_00027573.bin 224 224 +19451 ./prep_dataset/ILSVRC2012_val_00031290.bin 224 224 +19452 ./prep_dataset/ILSVRC2012_val_00000465.bin 224 224 +19453 ./prep_dataset/ILSVRC2012_val_00030014.bin 224 224 +19454 ./prep_dataset/ILSVRC2012_val_00039927.bin 224 224 +19455 ./prep_dataset/ILSVRC2012_val_00022022.bin 224 224 +19456 ./prep_dataset/ILSVRC2012_val_00034166.bin 224 224 +19457 ./prep_dataset/ILSVRC2012_val_00041351.bin 224 224 +19458 ./prep_dataset/ILSVRC2012_val_00012901.bin 224 224 +19459 ./prep_dataset/ILSVRC2012_val_00012712.bin 224 224 +19460 ./prep_dataset/ILSVRC2012_val_00025575.bin 224 224 +19461 ./prep_dataset/ILSVRC2012_val_00020041.bin 224 224 +19462 ./prep_dataset/ILSVRC2012_val_00020291.bin 224 224 +19463 ./prep_dataset/ILSVRC2012_val_00017776.bin 224 224 +19464 ./prep_dataset/ILSVRC2012_val_00021131.bin 224 224 +19465 ./prep_dataset/ILSVRC2012_val_00022871.bin 224 224 +19466 ./prep_dataset/ILSVRC2012_val_00002150.bin 224 224 +19467 ./prep_dataset/ILSVRC2012_val_00035859.bin 224 224 +19468 ./prep_dataset/ILSVRC2012_val_00014173.bin 224 224 +19469 ./prep_dataset/ILSVRC2012_val_00007778.bin 224 224 +19470 ./prep_dataset/ILSVRC2012_val_00049419.bin 224 224 +19471 ./prep_dataset/ILSVRC2012_val_00002507.bin 224 224 +19472 ./prep_dataset/ILSVRC2012_val_00030757.bin 224 224 +19473 ./prep_dataset/ILSVRC2012_val_00040087.bin 224 224 +19474 ./prep_dataset/ILSVRC2012_val_00032716.bin 224 224 +19475 ./prep_dataset/ILSVRC2012_val_00029939.bin 224 224 +19476 ./prep_dataset/ILSVRC2012_val_00047162.bin 224 224 +19477 ./prep_dataset/ILSVRC2012_val_00027440.bin 224 224 +19478 ./prep_dataset/ILSVRC2012_val_00009680.bin 224 224 +19479 ./prep_dataset/ILSVRC2012_val_00005733.bin 224 224 +19480 ./prep_dataset/ILSVRC2012_val_00019577.bin 224 224 +19481 ./prep_dataset/ILSVRC2012_val_00011355.bin 224 224 +19482 ./prep_dataset/ILSVRC2012_val_00020267.bin 224 224 +19483 ./prep_dataset/ILSVRC2012_val_00044124.bin 224 224 +19484 ./prep_dataset/ILSVRC2012_val_00029487.bin 224 224 +19485 ./prep_dataset/ILSVRC2012_val_00002814.bin 224 224 +19486 ./prep_dataset/ILSVRC2012_val_00044613.bin 224 224 +19487 ./prep_dataset/ILSVRC2012_val_00049061.bin 224 224 +19488 ./prep_dataset/ILSVRC2012_val_00024678.bin 224 224 +19489 ./prep_dataset/ILSVRC2012_val_00041705.bin 224 224 +19490 ./prep_dataset/ILSVRC2012_val_00044958.bin 224 224 +19491 ./prep_dataset/ILSVRC2012_val_00008716.bin 224 224 +19492 ./prep_dataset/ILSVRC2012_val_00011300.bin 224 224 +19493 ./prep_dataset/ILSVRC2012_val_00011753.bin 224 224 +19494 ./prep_dataset/ILSVRC2012_val_00032815.bin 224 224 +19495 ./prep_dataset/ILSVRC2012_val_00043200.bin 224 224 +19496 ./prep_dataset/ILSVRC2012_val_00042356.bin 224 224 +19497 ./prep_dataset/ILSVRC2012_val_00013604.bin 224 224 +19498 ./prep_dataset/ILSVRC2012_val_00015064.bin 224 224 +19499 ./prep_dataset/ILSVRC2012_val_00031876.bin 224 224 +19500 ./prep_dataset/ILSVRC2012_val_00029395.bin 224 224 +19501 ./prep_dataset/ILSVRC2012_val_00002353.bin 224 224 +19502 ./prep_dataset/ILSVRC2012_val_00005296.bin 224 224 +19503 ./prep_dataset/ILSVRC2012_val_00047368.bin 224 224 +19504 ./prep_dataset/ILSVRC2012_val_00037799.bin 224 224 +19505 ./prep_dataset/ILSVRC2012_val_00038007.bin 224 224 +19506 ./prep_dataset/ILSVRC2012_val_00015673.bin 224 224 +19507 ./prep_dataset/ILSVRC2012_val_00003771.bin 224 224 +19508 ./prep_dataset/ILSVRC2012_val_00033111.bin 224 224 +19509 ./prep_dataset/ILSVRC2012_val_00025660.bin 224 224 +19510 ./prep_dataset/ILSVRC2012_val_00024492.bin 224 224 +19511 ./prep_dataset/ILSVRC2012_val_00043345.bin 224 224 +19512 ./prep_dataset/ILSVRC2012_val_00005641.bin 224 224 +19513 ./prep_dataset/ILSVRC2012_val_00006185.bin 224 224 +19514 ./prep_dataset/ILSVRC2012_val_00038873.bin 224 224 +19515 ./prep_dataset/ILSVRC2012_val_00029752.bin 224 224 +19516 ./prep_dataset/ILSVRC2012_val_00048253.bin 224 224 +19517 ./prep_dataset/ILSVRC2012_val_00001766.bin 224 224 +19518 ./prep_dataset/ILSVRC2012_val_00030886.bin 224 224 +19519 ./prep_dataset/ILSVRC2012_val_00047737.bin 224 224 +19520 ./prep_dataset/ILSVRC2012_val_00032242.bin 224 224 +19521 ./prep_dataset/ILSVRC2012_val_00038126.bin 224 224 +19522 ./prep_dataset/ILSVRC2012_val_00034666.bin 224 224 +19523 ./prep_dataset/ILSVRC2012_val_00028376.bin 224 224 +19524 ./prep_dataset/ILSVRC2012_val_00045047.bin 224 224 +19525 ./prep_dataset/ILSVRC2012_val_00004316.bin 224 224 +19526 ./prep_dataset/ILSVRC2012_val_00010295.bin 224 224 +19527 ./prep_dataset/ILSVRC2012_val_00040616.bin 224 224 +19528 ./prep_dataset/ILSVRC2012_val_00019536.bin 224 224 +19529 ./prep_dataset/ILSVRC2012_val_00024239.bin 224 224 +19530 ./prep_dataset/ILSVRC2012_val_00003713.bin 224 224 +19531 ./prep_dataset/ILSVRC2012_val_00021946.bin 224 224 +19532 ./prep_dataset/ILSVRC2012_val_00004037.bin 224 224 +19533 ./prep_dataset/ILSVRC2012_val_00039762.bin 224 224 +19534 ./prep_dataset/ILSVRC2012_val_00024872.bin 224 224 +19535 ./prep_dataset/ILSVRC2012_val_00020789.bin 224 224 +19536 ./prep_dataset/ILSVRC2012_val_00033892.bin 224 224 +19537 ./prep_dataset/ILSVRC2012_val_00010786.bin 224 224 +19538 ./prep_dataset/ILSVRC2012_val_00018913.bin 224 224 +19539 ./prep_dataset/ILSVRC2012_val_00023299.bin 224 224 +19540 ./prep_dataset/ILSVRC2012_val_00008324.bin 224 224 +19541 ./prep_dataset/ILSVRC2012_val_00042512.bin 224 224 +19542 ./prep_dataset/ILSVRC2012_val_00033389.bin 224 224 +19543 ./prep_dataset/ILSVRC2012_val_00031625.bin 224 224 +19544 ./prep_dataset/ILSVRC2012_val_00001922.bin 224 224 +19545 ./prep_dataset/ILSVRC2012_val_00025146.bin 224 224 +19546 ./prep_dataset/ILSVRC2012_val_00029088.bin 224 224 +19547 ./prep_dataset/ILSVRC2012_val_00036213.bin 224 224 +19548 ./prep_dataset/ILSVRC2012_val_00006916.bin 224 224 +19549 ./prep_dataset/ILSVRC2012_val_00034353.bin 224 224 +19550 ./prep_dataset/ILSVRC2012_val_00043871.bin 224 224 +19551 ./prep_dataset/ILSVRC2012_val_00017423.bin 224 224 +19552 ./prep_dataset/ILSVRC2012_val_00046273.bin 224 224 +19553 ./prep_dataset/ILSVRC2012_val_00004333.bin 224 224 +19554 ./prep_dataset/ILSVRC2012_val_00001116.bin 224 224 +19555 ./prep_dataset/ILSVRC2012_val_00030342.bin 224 224 +19556 ./prep_dataset/ILSVRC2012_val_00024481.bin 224 224 +19557 ./prep_dataset/ILSVRC2012_val_00001070.bin 224 224 +19558 ./prep_dataset/ILSVRC2012_val_00006562.bin 224 224 +19559 ./prep_dataset/ILSVRC2012_val_00028153.bin 224 224 +19560 ./prep_dataset/ILSVRC2012_val_00048771.bin 224 224 +19561 ./prep_dataset/ILSVRC2012_val_00029084.bin 224 224 +19562 ./prep_dataset/ILSVRC2012_val_00037404.bin 224 224 +19563 ./prep_dataset/ILSVRC2012_val_00027506.bin 224 224 +19564 ./prep_dataset/ILSVRC2012_val_00039675.bin 224 224 +19565 ./prep_dataset/ILSVRC2012_val_00037271.bin 224 224 +19566 ./prep_dataset/ILSVRC2012_val_00041377.bin 224 224 +19567 ./prep_dataset/ILSVRC2012_val_00021055.bin 224 224 +19568 ./prep_dataset/ILSVRC2012_val_00030653.bin 224 224 +19569 ./prep_dataset/ILSVRC2012_val_00020704.bin 224 224 +19570 ./prep_dataset/ILSVRC2012_val_00017246.bin 224 224 +19571 ./prep_dataset/ILSVRC2012_val_00049479.bin 224 224 +19572 ./prep_dataset/ILSVRC2012_val_00038727.bin 224 224 +19573 ./prep_dataset/ILSVRC2012_val_00017105.bin 224 224 +19574 ./prep_dataset/ILSVRC2012_val_00010866.bin 224 224 +19575 ./prep_dataset/ILSVRC2012_val_00032355.bin 224 224 +19576 ./prep_dataset/ILSVRC2012_val_00023387.bin 224 224 +19577 ./prep_dataset/ILSVRC2012_val_00001208.bin 224 224 +19578 ./prep_dataset/ILSVRC2012_val_00049916.bin 224 224 +19579 ./prep_dataset/ILSVRC2012_val_00020017.bin 224 224 +19580 ./prep_dataset/ILSVRC2012_val_00019240.bin 224 224 +19581 ./prep_dataset/ILSVRC2012_val_00040662.bin 224 224 +19582 ./prep_dataset/ILSVRC2012_val_00013929.bin 224 224 +19583 ./prep_dataset/ILSVRC2012_val_00035634.bin 224 224 +19584 ./prep_dataset/ILSVRC2012_val_00006529.bin 224 224 +19585 ./prep_dataset/ILSVRC2012_val_00004230.bin 224 224 +19586 ./prep_dataset/ILSVRC2012_val_00029305.bin 224 224 +19587 ./prep_dataset/ILSVRC2012_val_00039493.bin 224 224 +19588 ./prep_dataset/ILSVRC2012_val_00034287.bin 224 224 +19589 ./prep_dataset/ILSVRC2012_val_00024664.bin 224 224 +19590 ./prep_dataset/ILSVRC2012_val_00020326.bin 224 224 +19591 ./prep_dataset/ILSVRC2012_val_00033713.bin 224 224 +19592 ./prep_dataset/ILSVRC2012_val_00003826.bin 224 224 +19593 ./prep_dataset/ILSVRC2012_val_00017293.bin 224 224 +19594 ./prep_dataset/ILSVRC2012_val_00007139.bin 224 224 +19595 ./prep_dataset/ILSVRC2012_val_00016871.bin 224 224 +19596 ./prep_dataset/ILSVRC2012_val_00010180.bin 224 224 +19597 ./prep_dataset/ILSVRC2012_val_00002922.bin 224 224 +19598 ./prep_dataset/ILSVRC2012_val_00017928.bin 224 224 +19599 ./prep_dataset/ILSVRC2012_val_00001100.bin 224 224 +19600 ./prep_dataset/ILSVRC2012_val_00007275.bin 224 224 +19601 ./prep_dataset/ILSVRC2012_val_00015126.bin 224 224 +19602 ./prep_dataset/ILSVRC2012_val_00043967.bin 224 224 +19603 ./prep_dataset/ILSVRC2012_val_00036856.bin 224 224 +19604 ./prep_dataset/ILSVRC2012_val_00047843.bin 224 224 +19605 ./prep_dataset/ILSVRC2012_val_00023241.bin 224 224 +19606 ./prep_dataset/ILSVRC2012_val_00039192.bin 224 224 +19607 ./prep_dataset/ILSVRC2012_val_00046294.bin 224 224 +19608 ./prep_dataset/ILSVRC2012_val_00036947.bin 224 224 +19609 ./prep_dataset/ILSVRC2012_val_00031092.bin 224 224 +19610 ./prep_dataset/ILSVRC2012_val_00046981.bin 224 224 +19611 ./prep_dataset/ILSVRC2012_val_00007070.bin 224 224 +19612 ./prep_dataset/ILSVRC2012_val_00012104.bin 224 224 +19613 ./prep_dataset/ILSVRC2012_val_00031100.bin 224 224 +19614 ./prep_dataset/ILSVRC2012_val_00042454.bin 224 224 +19615 ./prep_dataset/ILSVRC2012_val_00025606.bin 224 224 +19616 ./prep_dataset/ILSVRC2012_val_00031699.bin 224 224 +19617 ./prep_dataset/ILSVRC2012_val_00000896.bin 224 224 +19618 ./prep_dataset/ILSVRC2012_val_00005510.bin 224 224 +19619 ./prep_dataset/ILSVRC2012_val_00028079.bin 224 224 +19620 ./prep_dataset/ILSVRC2012_val_00023920.bin 224 224 +19621 ./prep_dataset/ILSVRC2012_val_00026886.bin 224 224 +19622 ./prep_dataset/ILSVRC2012_val_00046006.bin 224 224 +19623 ./prep_dataset/ILSVRC2012_val_00036703.bin 224 224 +19624 ./prep_dataset/ILSVRC2012_val_00007362.bin 224 224 +19625 ./prep_dataset/ILSVRC2012_val_00027013.bin 224 224 +19626 ./prep_dataset/ILSVRC2012_val_00028199.bin 224 224 +19627 ./prep_dataset/ILSVRC2012_val_00048081.bin 224 224 +19628 ./prep_dataset/ILSVRC2012_val_00002873.bin 224 224 +19629 ./prep_dataset/ILSVRC2012_val_00030133.bin 224 224 +19630 ./prep_dataset/ILSVRC2012_val_00008583.bin 224 224 +19631 ./prep_dataset/ILSVRC2012_val_00003864.bin 224 224 +19632 ./prep_dataset/ILSVRC2012_val_00021442.bin 224 224 +19633 ./prep_dataset/ILSVRC2012_val_00039273.bin 224 224 +19634 ./prep_dataset/ILSVRC2012_val_00003206.bin 224 224 +19635 ./prep_dataset/ILSVRC2012_val_00045464.bin 224 224 +19636 ./prep_dataset/ILSVRC2012_val_00000200.bin 224 224 +19637 ./prep_dataset/ILSVRC2012_val_00048300.bin 224 224 +19638 ./prep_dataset/ILSVRC2012_val_00002835.bin 224 224 +19639 ./prep_dataset/ILSVRC2012_val_00043621.bin 224 224 +19640 ./prep_dataset/ILSVRC2012_val_00045141.bin 224 224 +19641 ./prep_dataset/ILSVRC2012_val_00009611.bin 224 224 +19642 ./prep_dataset/ILSVRC2012_val_00049075.bin 224 224 +19643 ./prep_dataset/ILSVRC2012_val_00003527.bin 224 224 +19644 ./prep_dataset/ILSVRC2012_val_00024717.bin 224 224 +19645 ./prep_dataset/ILSVRC2012_val_00031096.bin 224 224 +19646 ./prep_dataset/ILSVRC2012_val_00010178.bin 224 224 +19647 ./prep_dataset/ILSVRC2012_val_00041718.bin 224 224 +19648 ./prep_dataset/ILSVRC2012_val_00004444.bin 224 224 +19649 ./prep_dataset/ILSVRC2012_val_00001781.bin 224 224 +19650 ./prep_dataset/ILSVRC2012_val_00011892.bin 224 224 +19651 ./prep_dataset/ILSVRC2012_val_00000412.bin 224 224 +19652 ./prep_dataset/ILSVRC2012_val_00049928.bin 224 224 +19653 ./prep_dataset/ILSVRC2012_val_00014860.bin 224 224 +19654 ./prep_dataset/ILSVRC2012_val_00039892.bin 224 224 +19655 ./prep_dataset/ILSVRC2012_val_00005113.bin 224 224 +19656 ./prep_dataset/ILSVRC2012_val_00028446.bin 224 224 +19657 ./prep_dataset/ILSVRC2012_val_00033021.bin 224 224 +19658 ./prep_dataset/ILSVRC2012_val_00040420.bin 224 224 +19659 ./prep_dataset/ILSVRC2012_val_00005256.bin 224 224 +19660 ./prep_dataset/ILSVRC2012_val_00032506.bin 224 224 +19661 ./prep_dataset/ILSVRC2012_val_00020572.bin 224 224 +19662 ./prep_dataset/ILSVRC2012_val_00002199.bin 224 224 +19663 ./prep_dataset/ILSVRC2012_val_00001621.bin 224 224 +19664 ./prep_dataset/ILSVRC2012_val_00015182.bin 224 224 +19665 ./prep_dataset/ILSVRC2012_val_00043358.bin 224 224 +19666 ./prep_dataset/ILSVRC2012_val_00043048.bin 224 224 +19667 ./prep_dataset/ILSVRC2012_val_00026802.bin 224 224 +19668 ./prep_dataset/ILSVRC2012_val_00029139.bin 224 224 +19669 ./prep_dataset/ILSVRC2012_val_00030795.bin 224 224 +19670 ./prep_dataset/ILSVRC2012_val_00015491.bin 224 224 +19671 ./prep_dataset/ILSVRC2012_val_00020816.bin 224 224 +19672 ./prep_dataset/ILSVRC2012_val_00043846.bin 224 224 +19673 ./prep_dataset/ILSVRC2012_val_00048279.bin 224 224 +19674 ./prep_dataset/ILSVRC2012_val_00024648.bin 224 224 +19675 ./prep_dataset/ILSVRC2012_val_00010132.bin 224 224 +19676 ./prep_dataset/ILSVRC2012_val_00005800.bin 224 224 +19677 ./prep_dataset/ILSVRC2012_val_00018833.bin 224 224 +19678 ./prep_dataset/ILSVRC2012_val_00044252.bin 224 224 +19679 ./prep_dataset/ILSVRC2012_val_00010034.bin 224 224 +19680 ./prep_dataset/ILSVRC2012_val_00045815.bin 224 224 +19681 ./prep_dataset/ILSVRC2012_val_00022503.bin 224 224 +19682 ./prep_dataset/ILSVRC2012_val_00028281.bin 224 224 +19683 ./prep_dataset/ILSVRC2012_val_00030246.bin 224 224 +19684 ./prep_dataset/ILSVRC2012_val_00001063.bin 224 224 +19685 ./prep_dataset/ILSVRC2012_val_00029684.bin 224 224 +19686 ./prep_dataset/ILSVRC2012_val_00018108.bin 224 224 +19687 ./prep_dataset/ILSVRC2012_val_00013989.bin 224 224 +19688 ./prep_dataset/ILSVRC2012_val_00025474.bin 224 224 +19689 ./prep_dataset/ILSVRC2012_val_00004254.bin 224 224 +19690 ./prep_dataset/ILSVRC2012_val_00024338.bin 224 224 +19691 ./prep_dataset/ILSVRC2012_val_00032074.bin 224 224 +19692 ./prep_dataset/ILSVRC2012_val_00036767.bin 224 224 +19693 ./prep_dataset/ILSVRC2012_val_00014982.bin 224 224 +19694 ./prep_dataset/ILSVRC2012_val_00032003.bin 224 224 +19695 ./prep_dataset/ILSVRC2012_val_00025185.bin 224 224 +19696 ./prep_dataset/ILSVRC2012_val_00026940.bin 224 224 +19697 ./prep_dataset/ILSVRC2012_val_00012203.bin 224 224 +19698 ./prep_dataset/ILSVRC2012_val_00035427.bin 224 224 +19699 ./prep_dataset/ILSVRC2012_val_00031952.bin 224 224 +19700 ./prep_dataset/ILSVRC2012_val_00033298.bin 224 224 +19701 ./prep_dataset/ILSVRC2012_val_00049055.bin 224 224 +19702 ./prep_dataset/ILSVRC2012_val_00044079.bin 224 224 +19703 ./prep_dataset/ILSVRC2012_val_00028760.bin 224 224 +19704 ./prep_dataset/ILSVRC2012_val_00045734.bin 224 224 +19705 ./prep_dataset/ILSVRC2012_val_00027783.bin 224 224 +19706 ./prep_dataset/ILSVRC2012_val_00017652.bin 224 224 +19707 ./prep_dataset/ILSVRC2012_val_00022784.bin 224 224 +19708 ./prep_dataset/ILSVRC2012_val_00016795.bin 224 224 +19709 ./prep_dataset/ILSVRC2012_val_00043947.bin 224 224 +19710 ./prep_dataset/ILSVRC2012_val_00032794.bin 224 224 +19711 ./prep_dataset/ILSVRC2012_val_00047257.bin 224 224 +19712 ./prep_dataset/ILSVRC2012_val_00020290.bin 224 224 +19713 ./prep_dataset/ILSVRC2012_val_00031250.bin 224 224 +19714 ./prep_dataset/ILSVRC2012_val_00049667.bin 224 224 +19715 ./prep_dataset/ILSVRC2012_val_00020456.bin 224 224 +19716 ./prep_dataset/ILSVRC2012_val_00012197.bin 224 224 +19717 ./prep_dataset/ILSVRC2012_val_00028135.bin 224 224 +19718 ./prep_dataset/ILSVRC2012_val_00018679.bin 224 224 +19719 ./prep_dataset/ILSVRC2012_val_00026670.bin 224 224 +19720 ./prep_dataset/ILSVRC2012_val_00047270.bin 224 224 +19721 ./prep_dataset/ILSVRC2012_val_00030767.bin 224 224 +19722 ./prep_dataset/ILSVRC2012_val_00033722.bin 224 224 +19723 ./prep_dataset/ILSVRC2012_val_00014003.bin 224 224 +19724 ./prep_dataset/ILSVRC2012_val_00005070.bin 224 224 +19725 ./prep_dataset/ILSVRC2012_val_00021581.bin 224 224 +19726 ./prep_dataset/ILSVRC2012_val_00030326.bin 224 224 +19727 ./prep_dataset/ILSVRC2012_val_00021688.bin 224 224 +19728 ./prep_dataset/ILSVRC2012_val_00041616.bin 224 224 +19729 ./prep_dataset/ILSVRC2012_val_00009413.bin 224 224 +19730 ./prep_dataset/ILSVRC2012_val_00031062.bin 224 224 +19731 ./prep_dataset/ILSVRC2012_val_00032680.bin 224 224 +19732 ./prep_dataset/ILSVRC2012_val_00031291.bin 224 224 +19733 ./prep_dataset/ILSVRC2012_val_00026187.bin 224 224 +19734 ./prep_dataset/ILSVRC2012_val_00042327.bin 224 224 +19735 ./prep_dataset/ILSVRC2012_val_00012248.bin 224 224 +19736 ./prep_dataset/ILSVRC2012_val_00017082.bin 224 224 +19737 ./prep_dataset/ILSVRC2012_val_00035568.bin 224 224 +19738 ./prep_dataset/ILSVRC2012_val_00004383.bin 224 224 +19739 ./prep_dataset/ILSVRC2012_val_00032334.bin 224 224 +19740 ./prep_dataset/ILSVRC2012_val_00003971.bin 224 224 +19741 ./prep_dataset/ILSVRC2012_val_00035856.bin 224 224 +19742 ./prep_dataset/ILSVRC2012_val_00013100.bin 224 224 +19743 ./prep_dataset/ILSVRC2012_val_00024056.bin 224 224 +19744 ./prep_dataset/ILSVRC2012_val_00031964.bin 224 224 +19745 ./prep_dataset/ILSVRC2012_val_00034644.bin 224 224 +19746 ./prep_dataset/ILSVRC2012_val_00042134.bin 224 224 +19747 ./prep_dataset/ILSVRC2012_val_00028957.bin 224 224 +19748 ./prep_dataset/ILSVRC2012_val_00032259.bin 224 224 +19749 ./prep_dataset/ILSVRC2012_val_00031854.bin 224 224 +19750 ./prep_dataset/ILSVRC2012_val_00001763.bin 224 224 +19751 ./prep_dataset/ILSVRC2012_val_00007419.bin 224 224 +19752 ./prep_dataset/ILSVRC2012_val_00035865.bin 224 224 +19753 ./prep_dataset/ILSVRC2012_val_00042419.bin 224 224 +19754 ./prep_dataset/ILSVRC2012_val_00009525.bin 224 224 +19755 ./prep_dataset/ILSVRC2012_val_00006911.bin 224 224 +19756 ./prep_dataset/ILSVRC2012_val_00034846.bin 224 224 +19757 ./prep_dataset/ILSVRC2012_val_00013445.bin 224 224 +19758 ./prep_dataset/ILSVRC2012_val_00033206.bin 224 224 +19759 ./prep_dataset/ILSVRC2012_val_00014424.bin 224 224 +19760 ./prep_dataset/ILSVRC2012_val_00024501.bin 224 224 +19761 ./prep_dataset/ILSVRC2012_val_00004807.bin 224 224 +19762 ./prep_dataset/ILSVRC2012_val_00033650.bin 224 224 +19763 ./prep_dataset/ILSVRC2012_val_00011885.bin 224 224 +19764 ./prep_dataset/ILSVRC2012_val_00015570.bin 224 224 +19765 ./prep_dataset/ILSVRC2012_val_00032247.bin 224 224 +19766 ./prep_dataset/ILSVRC2012_val_00022801.bin 224 224 +19767 ./prep_dataset/ILSVRC2012_val_00031702.bin 224 224 +19768 ./prep_dataset/ILSVRC2012_val_00020138.bin 224 224 +19769 ./prep_dataset/ILSVRC2012_val_00009755.bin 224 224 +19770 ./prep_dataset/ILSVRC2012_val_00013576.bin 224 224 +19771 ./prep_dataset/ILSVRC2012_val_00009844.bin 224 224 +19772 ./prep_dataset/ILSVRC2012_val_00038403.bin 224 224 +19773 ./prep_dataset/ILSVRC2012_val_00010940.bin 224 224 +19774 ./prep_dataset/ILSVRC2012_val_00029175.bin 224 224 +19775 ./prep_dataset/ILSVRC2012_val_00018086.bin 224 224 +19776 ./prep_dataset/ILSVRC2012_val_00037668.bin 224 224 +19777 ./prep_dataset/ILSVRC2012_val_00010431.bin 224 224 +19778 ./prep_dataset/ILSVRC2012_val_00015827.bin 224 224 +19779 ./prep_dataset/ILSVRC2012_val_00020491.bin 224 224 +19780 ./prep_dataset/ILSVRC2012_val_00021691.bin 224 224 +19781 ./prep_dataset/ILSVRC2012_val_00034303.bin 224 224 +19782 ./prep_dataset/ILSVRC2012_val_00016722.bin 224 224 +19783 ./prep_dataset/ILSVRC2012_val_00009201.bin 224 224 +19784 ./prep_dataset/ILSVRC2012_val_00013451.bin 224 224 +19785 ./prep_dataset/ILSVRC2012_val_00022749.bin 224 224 +19786 ./prep_dataset/ILSVRC2012_val_00037129.bin 224 224 +19787 ./prep_dataset/ILSVRC2012_val_00009870.bin 224 224 +19788 ./prep_dataset/ILSVRC2012_val_00038363.bin 224 224 +19789 ./prep_dataset/ILSVRC2012_val_00030471.bin 224 224 +19790 ./prep_dataset/ILSVRC2012_val_00031661.bin 224 224 +19791 ./prep_dataset/ILSVRC2012_val_00031148.bin 224 224 +19792 ./prep_dataset/ILSVRC2012_val_00017680.bin 224 224 +19793 ./prep_dataset/ILSVRC2012_val_00027613.bin 224 224 +19794 ./prep_dataset/ILSVRC2012_val_00006530.bin 224 224 +19795 ./prep_dataset/ILSVRC2012_val_00040727.bin 224 224 +19796 ./prep_dataset/ILSVRC2012_val_00032237.bin 224 224 +19797 ./prep_dataset/ILSVRC2012_val_00009695.bin 224 224 +19798 ./prep_dataset/ILSVRC2012_val_00011566.bin 224 224 +19799 ./prep_dataset/ILSVRC2012_val_00017412.bin 224 224 +19800 ./prep_dataset/ILSVRC2012_val_00032431.bin 224 224 +19801 ./prep_dataset/ILSVRC2012_val_00018652.bin 224 224 +19802 ./prep_dataset/ILSVRC2012_val_00023628.bin 224 224 +19803 ./prep_dataset/ILSVRC2012_val_00027264.bin 224 224 +19804 ./prep_dataset/ILSVRC2012_val_00010146.bin 224 224 +19805 ./prep_dataset/ILSVRC2012_val_00023453.bin 224 224 +19806 ./prep_dataset/ILSVRC2012_val_00047561.bin 224 224 +19807 ./prep_dataset/ILSVRC2012_val_00011420.bin 224 224 +19808 ./prep_dataset/ILSVRC2012_val_00048553.bin 224 224 +19809 ./prep_dataset/ILSVRC2012_val_00017453.bin 224 224 +19810 ./prep_dataset/ILSVRC2012_val_00039767.bin 224 224 +19811 ./prep_dataset/ILSVRC2012_val_00011921.bin 224 224 +19812 ./prep_dataset/ILSVRC2012_val_00000583.bin 224 224 +19813 ./prep_dataset/ILSVRC2012_val_00019915.bin 224 224 +19814 ./prep_dataset/ILSVRC2012_val_00044352.bin 224 224 +19815 ./prep_dataset/ILSVRC2012_val_00020459.bin 224 224 +19816 ./prep_dataset/ILSVRC2012_val_00037848.bin 224 224 +19817 ./prep_dataset/ILSVRC2012_val_00046919.bin 224 224 +19818 ./prep_dataset/ILSVRC2012_val_00039052.bin 224 224 +19819 ./prep_dataset/ILSVRC2012_val_00016200.bin 224 224 +19820 ./prep_dataset/ILSVRC2012_val_00048036.bin 224 224 +19821 ./prep_dataset/ILSVRC2012_val_00048091.bin 224 224 +19822 ./prep_dataset/ILSVRC2012_val_00001460.bin 224 224 +19823 ./prep_dataset/ILSVRC2012_val_00006922.bin 224 224 +19824 ./prep_dataset/ILSVRC2012_val_00006612.bin 224 224 +19825 ./prep_dataset/ILSVRC2012_val_00005728.bin 224 224 +19826 ./prep_dataset/ILSVRC2012_val_00048535.bin 224 224 +19827 ./prep_dataset/ILSVRC2012_val_00027798.bin 224 224 +19828 ./prep_dataset/ILSVRC2012_val_00036572.bin 224 224 +19829 ./prep_dataset/ILSVRC2012_val_00045184.bin 224 224 +19830 ./prep_dataset/ILSVRC2012_val_00023626.bin 224 224 +19831 ./prep_dataset/ILSVRC2012_val_00031788.bin 224 224 +19832 ./prep_dataset/ILSVRC2012_val_00001866.bin 224 224 +19833 ./prep_dataset/ILSVRC2012_val_00000367.bin 224 224 +19834 ./prep_dataset/ILSVRC2012_val_00000995.bin 224 224 +19835 ./prep_dataset/ILSVRC2012_val_00043988.bin 224 224 +19836 ./prep_dataset/ILSVRC2012_val_00048802.bin 224 224 +19837 ./prep_dataset/ILSVRC2012_val_00008247.bin 224 224 +19838 ./prep_dataset/ILSVRC2012_val_00020228.bin 224 224 +19839 ./prep_dataset/ILSVRC2012_val_00012753.bin 224 224 +19840 ./prep_dataset/ILSVRC2012_val_00032658.bin 224 224 +19841 ./prep_dataset/ILSVRC2012_val_00030240.bin 224 224 +19842 ./prep_dataset/ILSVRC2012_val_00019600.bin 224 224 +19843 ./prep_dataset/ILSVRC2012_val_00048966.bin 224 224 +19844 ./prep_dataset/ILSVRC2012_val_00011532.bin 224 224 +19845 ./prep_dataset/ILSVRC2012_val_00000223.bin 224 224 +19846 ./prep_dataset/ILSVRC2012_val_00006935.bin 224 224 +19847 ./prep_dataset/ILSVRC2012_val_00029345.bin 224 224 +19848 ./prep_dataset/ILSVRC2012_val_00016650.bin 224 224 +19849 ./prep_dataset/ILSVRC2012_val_00024708.bin 224 224 +19850 ./prep_dataset/ILSVRC2012_val_00034824.bin 224 224 +19851 ./prep_dataset/ILSVRC2012_val_00005452.bin 224 224 +19852 ./prep_dataset/ILSVRC2012_val_00024898.bin 224 224 +19853 ./prep_dataset/ILSVRC2012_val_00036033.bin 224 224 +19854 ./prep_dataset/ILSVRC2012_val_00021553.bin 224 224 +19855 ./prep_dataset/ILSVRC2012_val_00012543.bin 224 224 +19856 ./prep_dataset/ILSVRC2012_val_00048637.bin 224 224 +19857 ./prep_dataset/ILSVRC2012_val_00000835.bin 224 224 +19858 ./prep_dataset/ILSVRC2012_val_00031844.bin 224 224 +19859 ./prep_dataset/ILSVRC2012_val_00009865.bin 224 224 +19860 ./prep_dataset/ILSVRC2012_val_00042966.bin 224 224 +19861 ./prep_dataset/ILSVRC2012_val_00049358.bin 224 224 +19862 ./prep_dataset/ILSVRC2012_val_00042938.bin 224 224 +19863 ./prep_dataset/ILSVRC2012_val_00041656.bin 224 224 +19864 ./prep_dataset/ILSVRC2012_val_00035250.bin 224 224 +19865 ./prep_dataset/ILSVRC2012_val_00024066.bin 224 224 +19866 ./prep_dataset/ILSVRC2012_val_00046174.bin 224 224 +19867 ./prep_dataset/ILSVRC2012_val_00011357.bin 224 224 +19868 ./prep_dataset/ILSVRC2012_val_00030397.bin 224 224 +19869 ./prep_dataset/ILSVRC2012_val_00039556.bin 224 224 +19870 ./prep_dataset/ILSVRC2012_val_00024283.bin 224 224 +19871 ./prep_dataset/ILSVRC2012_val_00021603.bin 224 224 +19872 ./prep_dataset/ILSVRC2012_val_00021103.bin 224 224 +19873 ./prep_dataset/ILSVRC2012_val_00023514.bin 224 224 +19874 ./prep_dataset/ILSVRC2012_val_00049365.bin 224 224 +19875 ./prep_dataset/ILSVRC2012_val_00021290.bin 224 224 +19876 ./prep_dataset/ILSVRC2012_val_00017944.bin 224 224 +19877 ./prep_dataset/ILSVRC2012_val_00031177.bin 224 224 +19878 ./prep_dataset/ILSVRC2012_val_00035199.bin 224 224 +19879 ./prep_dataset/ILSVRC2012_val_00037820.bin 224 224 +19880 ./prep_dataset/ILSVRC2012_val_00048190.bin 224 224 +19881 ./prep_dataset/ILSVRC2012_val_00027203.bin 224 224 +19882 ./prep_dataset/ILSVRC2012_val_00018762.bin 224 224 +19883 ./prep_dataset/ILSVRC2012_val_00038680.bin 224 224 +19884 ./prep_dataset/ILSVRC2012_val_00011342.bin 224 224 +19885 ./prep_dataset/ILSVRC2012_val_00041541.bin 224 224 +19886 ./prep_dataset/ILSVRC2012_val_00020904.bin 224 224 +19887 ./prep_dataset/ILSVRC2012_val_00007285.bin 224 224 +19888 ./prep_dataset/ILSVRC2012_val_00008495.bin 224 224 +19889 ./prep_dataset/ILSVRC2012_val_00033149.bin 224 224 +19890 ./prep_dataset/ILSVRC2012_val_00016435.bin 224 224 +19891 ./prep_dataset/ILSVRC2012_val_00007147.bin 224 224 +19892 ./prep_dataset/ILSVRC2012_val_00048268.bin 224 224 +19893 ./prep_dataset/ILSVRC2012_val_00018890.bin 224 224 +19894 ./prep_dataset/ILSVRC2012_val_00024604.bin 224 224 +19895 ./prep_dataset/ILSVRC2012_val_00049191.bin 224 224 +19896 ./prep_dataset/ILSVRC2012_val_00024013.bin 224 224 +19897 ./prep_dataset/ILSVRC2012_val_00043660.bin 224 224 +19898 ./prep_dataset/ILSVRC2012_val_00000177.bin 224 224 +19899 ./prep_dataset/ILSVRC2012_val_00012205.bin 224 224 +19900 ./prep_dataset/ILSVRC2012_val_00004408.bin 224 224 +19901 ./prep_dataset/ILSVRC2012_val_00029613.bin 224 224 +19902 ./prep_dataset/ILSVRC2012_val_00044637.bin 224 224 +19903 ./prep_dataset/ILSVRC2012_val_00009342.bin 224 224 +19904 ./prep_dataset/ILSVRC2012_val_00029543.bin 224 224 +19905 ./prep_dataset/ILSVRC2012_val_00024660.bin 224 224 +19906 ./prep_dataset/ILSVRC2012_val_00003707.bin 224 224 +19907 ./prep_dataset/ILSVRC2012_val_00047644.bin 224 224 +19908 ./prep_dataset/ILSVRC2012_val_00028850.bin 224 224 +19909 ./prep_dataset/ILSVRC2012_val_00046311.bin 224 224 +19910 ./prep_dataset/ILSVRC2012_val_00043617.bin 224 224 +19911 ./prep_dataset/ILSVRC2012_val_00016915.bin 224 224 +19912 ./prep_dataset/ILSVRC2012_val_00018468.bin 224 224 +19913 ./prep_dataset/ILSVRC2012_val_00030900.bin 224 224 +19914 ./prep_dataset/ILSVRC2012_val_00029616.bin 224 224 +19915 ./prep_dataset/ILSVRC2012_val_00009683.bin 224 224 +19916 ./prep_dataset/ILSVRC2012_val_00029631.bin 224 224 +19917 ./prep_dataset/ILSVRC2012_val_00018751.bin 224 224 +19918 ./prep_dataset/ILSVRC2012_val_00031463.bin 224 224 +19919 ./prep_dataset/ILSVRC2012_val_00006734.bin 224 224 +19920 ./prep_dataset/ILSVRC2012_val_00008637.bin 224 224 +19921 ./prep_dataset/ILSVRC2012_val_00044818.bin 224 224 +19922 ./prep_dataset/ILSVRC2012_val_00013194.bin 224 224 +19923 ./prep_dataset/ILSVRC2012_val_00006396.bin 224 224 +19924 ./prep_dataset/ILSVRC2012_val_00044107.bin 224 224 +19925 ./prep_dataset/ILSVRC2012_val_00025706.bin 224 224 +19926 ./prep_dataset/ILSVRC2012_val_00047934.bin 224 224 +19927 ./prep_dataset/ILSVRC2012_val_00033584.bin 224 224 +19928 ./prep_dataset/ILSVRC2012_val_00039076.bin 224 224 +19929 ./prep_dataset/ILSVRC2012_val_00011240.bin 224 224 +19930 ./prep_dataset/ILSVRC2012_val_00007996.bin 224 224 +19931 ./prep_dataset/ILSVRC2012_val_00049703.bin 224 224 +19932 ./prep_dataset/ILSVRC2012_val_00017916.bin 224 224 +19933 ./prep_dataset/ILSVRC2012_val_00028098.bin 224 224 +19934 ./prep_dataset/ILSVRC2012_val_00025447.bin 224 224 +19935 ./prep_dataset/ILSVRC2012_val_00046479.bin 224 224 +19936 ./prep_dataset/ILSVRC2012_val_00007912.bin 224 224 +19937 ./prep_dataset/ILSVRC2012_val_00032905.bin 224 224 +19938 ./prep_dataset/ILSVRC2012_val_00036912.bin 224 224 +19939 ./prep_dataset/ILSVRC2012_val_00030878.bin 224 224 +19940 ./prep_dataset/ILSVRC2012_val_00048644.bin 224 224 +19941 ./prep_dataset/ILSVRC2012_val_00038037.bin 224 224 +19942 ./prep_dataset/ILSVRC2012_val_00048398.bin 224 224 +19943 ./prep_dataset/ILSVRC2012_val_00017756.bin 224 224 +19944 ./prep_dataset/ILSVRC2012_val_00005519.bin 224 224 +19945 ./prep_dataset/ILSVRC2012_val_00036809.bin 224 224 +19946 ./prep_dataset/ILSVRC2012_val_00029117.bin 224 224 +19947 ./prep_dataset/ILSVRC2012_val_00005054.bin 224 224 +19948 ./prep_dataset/ILSVRC2012_val_00008235.bin 224 224 +19949 ./prep_dataset/ILSVRC2012_val_00029422.bin 224 224 +19950 ./prep_dataset/ILSVRC2012_val_00037453.bin 224 224 +19951 ./prep_dataset/ILSVRC2012_val_00038545.bin 224 224 +19952 ./prep_dataset/ILSVRC2012_val_00006273.bin 224 224 +19953 ./prep_dataset/ILSVRC2012_val_00036911.bin 224 224 +19954 ./prep_dataset/ILSVRC2012_val_00049901.bin 224 224 +19955 ./prep_dataset/ILSVRC2012_val_00049158.bin 224 224 +19956 ./prep_dataset/ILSVRC2012_val_00012748.bin 224 224 +19957 ./prep_dataset/ILSVRC2012_val_00002857.bin 224 224 +19958 ./prep_dataset/ILSVRC2012_val_00005556.bin 224 224 +19959 ./prep_dataset/ILSVRC2012_val_00036491.bin 224 224 +19960 ./prep_dataset/ILSVRC2012_val_00028433.bin 224 224 +19961 ./prep_dataset/ILSVRC2012_val_00048311.bin 224 224 +19962 ./prep_dataset/ILSVRC2012_val_00033547.bin 224 224 +19963 ./prep_dataset/ILSVRC2012_val_00014847.bin 224 224 +19964 ./prep_dataset/ILSVRC2012_val_00038324.bin 224 224 +19965 ./prep_dataset/ILSVRC2012_val_00038510.bin 224 224 +19966 ./prep_dataset/ILSVRC2012_val_00047250.bin 224 224 +19967 ./prep_dataset/ILSVRC2012_val_00022402.bin 224 224 +19968 ./prep_dataset/ILSVRC2012_val_00008518.bin 224 224 +19969 ./prep_dataset/ILSVRC2012_val_00005503.bin 224 224 +19970 ./prep_dataset/ILSVRC2012_val_00040781.bin 224 224 +19971 ./prep_dataset/ILSVRC2012_val_00005627.bin 224 224 +19972 ./prep_dataset/ILSVRC2012_val_00029923.bin 224 224 +19973 ./prep_dataset/ILSVRC2012_val_00021298.bin 224 224 +19974 ./prep_dataset/ILSVRC2012_val_00026457.bin 224 224 +19975 ./prep_dataset/ILSVRC2012_val_00048267.bin 224 224 +19976 ./prep_dataset/ILSVRC2012_val_00010221.bin 224 224 +19977 ./prep_dataset/ILSVRC2012_val_00031610.bin 224 224 +19978 ./prep_dataset/ILSVRC2012_val_00048864.bin 224 224 +19979 ./prep_dataset/ILSVRC2012_val_00014066.bin 224 224 +19980 ./prep_dataset/ILSVRC2012_val_00020958.bin 224 224 +19981 ./prep_dataset/ILSVRC2012_val_00045572.bin 224 224 +19982 ./prep_dataset/ILSVRC2012_val_00043077.bin 224 224 +19983 ./prep_dataset/ILSVRC2012_val_00003240.bin 224 224 +19984 ./prep_dataset/ILSVRC2012_val_00041547.bin 224 224 +19985 ./prep_dataset/ILSVRC2012_val_00011036.bin 224 224 +19986 ./prep_dataset/ILSVRC2012_val_00049724.bin 224 224 +19987 ./prep_dataset/ILSVRC2012_val_00011600.bin 224 224 +19988 ./prep_dataset/ILSVRC2012_val_00022056.bin 224 224 +19989 ./prep_dataset/ILSVRC2012_val_00044775.bin 224 224 +19990 ./prep_dataset/ILSVRC2012_val_00048490.bin 224 224 +19991 ./prep_dataset/ILSVRC2012_val_00026812.bin 224 224 +19992 ./prep_dataset/ILSVRC2012_val_00035331.bin 224 224 +19993 ./prep_dataset/ILSVRC2012_val_00030482.bin 224 224 +19994 ./prep_dataset/ILSVRC2012_val_00037081.bin 224 224 +19995 ./prep_dataset/ILSVRC2012_val_00038075.bin 224 224 +19996 ./prep_dataset/ILSVRC2012_val_00008996.bin 224 224 +19997 ./prep_dataset/ILSVRC2012_val_00001218.bin 224 224 +19998 ./prep_dataset/ILSVRC2012_val_00009187.bin 224 224 +19999 ./prep_dataset/ILSVRC2012_val_00049902.bin 224 224 +20000 ./prep_dataset/ILSVRC2012_val_00046549.bin 224 224 +20001 ./prep_dataset/ILSVRC2012_val_00046100.bin 224 224 +20002 ./prep_dataset/ILSVRC2012_val_00034844.bin 224 224 +20003 ./prep_dataset/ILSVRC2012_val_00026233.bin 224 224 +20004 ./prep_dataset/ILSVRC2012_val_00014631.bin 224 224 +20005 ./prep_dataset/ILSVRC2012_val_00017647.bin 224 224 +20006 ./prep_dataset/ILSVRC2012_val_00029791.bin 224 224 +20007 ./prep_dataset/ILSVRC2012_val_00032352.bin 224 224 +20008 ./prep_dataset/ILSVRC2012_val_00004136.bin 224 224 +20009 ./prep_dataset/ILSVRC2012_val_00009446.bin 224 224 +20010 ./prep_dataset/ILSVRC2012_val_00045217.bin 224 224 +20011 ./prep_dataset/ILSVRC2012_val_00041011.bin 224 224 +20012 ./prep_dataset/ILSVRC2012_val_00010661.bin 224 224 +20013 ./prep_dataset/ILSVRC2012_val_00048520.bin 224 224 +20014 ./prep_dataset/ILSVRC2012_val_00039086.bin 224 224 +20015 ./prep_dataset/ILSVRC2012_val_00026272.bin 224 224 +20016 ./prep_dataset/ILSVRC2012_val_00003738.bin 224 224 +20017 ./prep_dataset/ILSVRC2012_val_00043097.bin 224 224 +20018 ./prep_dataset/ILSVRC2012_val_00015728.bin 224 224 +20019 ./prep_dataset/ILSVRC2012_val_00013273.bin 224 224 +20020 ./prep_dataset/ILSVRC2012_val_00007234.bin 224 224 +20021 ./prep_dataset/ILSVRC2012_val_00030677.bin 224 224 +20022 ./prep_dataset/ILSVRC2012_val_00014518.bin 224 224 +20023 ./prep_dataset/ILSVRC2012_val_00029039.bin 224 224 +20024 ./prep_dataset/ILSVRC2012_val_00047601.bin 224 224 +20025 ./prep_dataset/ILSVRC2012_val_00000545.bin 224 224 +20026 ./prep_dataset/ILSVRC2012_val_00016032.bin 224 224 +20027 ./prep_dataset/ILSVRC2012_val_00026400.bin 224 224 +20028 ./prep_dataset/ILSVRC2012_val_00013921.bin 224 224 +20029 ./prep_dataset/ILSVRC2012_val_00040410.bin 224 224 +20030 ./prep_dataset/ILSVRC2012_val_00021337.bin 224 224 +20031 ./prep_dataset/ILSVRC2012_val_00016185.bin 224 224 +20032 ./prep_dataset/ILSVRC2012_val_00035787.bin 224 224 +20033 ./prep_dataset/ILSVRC2012_val_00021067.bin 224 224 +20034 ./prep_dataset/ILSVRC2012_val_00044794.bin 224 224 +20035 ./prep_dataset/ILSVRC2012_val_00029461.bin 224 224 +20036 ./prep_dataset/ILSVRC2012_val_00043059.bin 224 224 +20037 ./prep_dataset/ILSVRC2012_val_00029427.bin 224 224 +20038 ./prep_dataset/ILSVRC2012_val_00010373.bin 224 224 +20039 ./prep_dataset/ILSVRC2012_val_00040688.bin 224 224 +20040 ./prep_dataset/ILSVRC2012_val_00006294.bin 224 224 +20041 ./prep_dataset/ILSVRC2012_val_00022375.bin 224 224 +20042 ./prep_dataset/ILSVRC2012_val_00044370.bin 224 224 +20043 ./prep_dataset/ILSVRC2012_val_00004631.bin 224 224 +20044 ./prep_dataset/ILSVRC2012_val_00033689.bin 224 224 +20045 ./prep_dataset/ILSVRC2012_val_00010236.bin 224 224 +20046 ./prep_dataset/ILSVRC2012_val_00043985.bin 224 224 +20047 ./prep_dataset/ILSVRC2012_val_00040841.bin 224 224 +20048 ./prep_dataset/ILSVRC2012_val_00027558.bin 224 224 +20049 ./prep_dataset/ILSVRC2012_val_00033809.bin 224 224 +20050 ./prep_dataset/ILSVRC2012_val_00031946.bin 224 224 +20051 ./prep_dataset/ILSVRC2012_val_00034089.bin 224 224 +20052 ./prep_dataset/ILSVRC2012_val_00036208.bin 224 224 +20053 ./prep_dataset/ILSVRC2012_val_00023108.bin 224 224 +20054 ./prep_dataset/ILSVRC2012_val_00009813.bin 224 224 +20055 ./prep_dataset/ILSVRC2012_val_00000327.bin 224 224 +20056 ./prep_dataset/ILSVRC2012_val_00026417.bin 224 224 +20057 ./prep_dataset/ILSVRC2012_val_00010832.bin 224 224 +20058 ./prep_dataset/ILSVRC2012_val_00042127.bin 224 224 +20059 ./prep_dataset/ILSVRC2012_val_00007887.bin 224 224 +20060 ./prep_dataset/ILSVRC2012_val_00036124.bin 224 224 +20061 ./prep_dataset/ILSVRC2012_val_00038655.bin 224 224 +20062 ./prep_dataset/ILSVRC2012_val_00004700.bin 224 224 +20063 ./prep_dataset/ILSVRC2012_val_00032459.bin 224 224 +20064 ./prep_dataset/ILSVRC2012_val_00016195.bin 224 224 +20065 ./prep_dataset/ILSVRC2012_val_00049506.bin 224 224 +20066 ./prep_dataset/ILSVRC2012_val_00043466.bin 224 224 +20067 ./prep_dataset/ILSVRC2012_val_00019332.bin 224 224 +20068 ./prep_dataset/ILSVRC2012_val_00045768.bin 224 224 +20069 ./prep_dataset/ILSVRC2012_val_00032217.bin 224 224 +20070 ./prep_dataset/ILSVRC2012_val_00045996.bin 224 224 +20071 ./prep_dataset/ILSVRC2012_val_00043073.bin 224 224 +20072 ./prep_dataset/ILSVRC2012_val_00032699.bin 224 224 +20073 ./prep_dataset/ILSVRC2012_val_00047173.bin 224 224 +20074 ./prep_dataset/ILSVRC2012_val_00004283.bin 224 224 +20075 ./prep_dataset/ILSVRC2012_val_00015174.bin 224 224 +20076 ./prep_dataset/ILSVRC2012_val_00030630.bin 224 224 +20077 ./prep_dataset/ILSVRC2012_val_00031919.bin 224 224 +20078 ./prep_dataset/ILSVRC2012_val_00020728.bin 224 224 +20079 ./prep_dataset/ILSVRC2012_val_00008258.bin 224 224 +20080 ./prep_dataset/ILSVRC2012_val_00036089.bin 224 224 +20081 ./prep_dataset/ILSVRC2012_val_00043574.bin 224 224 +20082 ./prep_dataset/ILSVRC2012_val_00042217.bin 224 224 +20083 ./prep_dataset/ILSVRC2012_val_00023618.bin 224 224 +20084 ./prep_dataset/ILSVRC2012_val_00008331.bin 224 224 +20085 ./prep_dataset/ILSVRC2012_val_00029922.bin 224 224 +20086 ./prep_dataset/ILSVRC2012_val_00008992.bin 224 224 +20087 ./prep_dataset/ILSVRC2012_val_00031248.bin 224 224 +20088 ./prep_dataset/ILSVRC2012_val_00049931.bin 224 224 +20089 ./prep_dataset/ILSVRC2012_val_00004082.bin 224 224 +20090 ./prep_dataset/ILSVRC2012_val_00027820.bin 224 224 +20091 ./prep_dataset/ILSVRC2012_val_00034985.bin 224 224 +20092 ./prep_dataset/ILSVRC2012_val_00028366.bin 224 224 +20093 ./prep_dataset/ILSVRC2012_val_00044738.bin 224 224 +20094 ./prep_dataset/ILSVRC2012_val_00033368.bin 224 224 +20095 ./prep_dataset/ILSVRC2012_val_00029267.bin 224 224 +20096 ./prep_dataset/ILSVRC2012_val_00011564.bin 224 224 +20097 ./prep_dataset/ILSVRC2012_val_00018383.bin 224 224 +20098 ./prep_dataset/ILSVRC2012_val_00006783.bin 224 224 +20099 ./prep_dataset/ILSVRC2012_val_00015986.bin 224 224 +20100 ./prep_dataset/ILSVRC2012_val_00030719.bin 224 224 +20101 ./prep_dataset/ILSVRC2012_val_00040502.bin 224 224 +20102 ./prep_dataset/ILSVRC2012_val_00021209.bin 224 224 +20103 ./prep_dataset/ILSVRC2012_val_00038748.bin 224 224 +20104 ./prep_dataset/ILSVRC2012_val_00018314.bin 224 224 +20105 ./prep_dataset/ILSVRC2012_val_00027929.bin 224 224 +20106 ./prep_dataset/ILSVRC2012_val_00009232.bin 224 224 +20107 ./prep_dataset/ILSVRC2012_val_00040206.bin 224 224 +20108 ./prep_dataset/ILSVRC2012_val_00004819.bin 224 224 +20109 ./prep_dataset/ILSVRC2012_val_00021830.bin 224 224 +20110 ./prep_dataset/ILSVRC2012_val_00002765.bin 224 224 +20111 ./prep_dataset/ILSVRC2012_val_00000113.bin 224 224 +20112 ./prep_dataset/ILSVRC2012_val_00042744.bin 224 224 +20113 ./prep_dataset/ILSVRC2012_val_00008004.bin 224 224 +20114 ./prep_dataset/ILSVRC2012_val_00041151.bin 224 224 +20115 ./prep_dataset/ILSVRC2012_val_00040134.bin 224 224 +20116 ./prep_dataset/ILSVRC2012_val_00048660.bin 224 224 +20117 ./prep_dataset/ILSVRC2012_val_00021637.bin 224 224 +20118 ./prep_dataset/ILSVRC2012_val_00044462.bin 224 224 +20119 ./prep_dataset/ILSVRC2012_val_00006383.bin 224 224 +20120 ./prep_dataset/ILSVRC2012_val_00040623.bin 224 224 +20121 ./prep_dataset/ILSVRC2012_val_00032636.bin 224 224 +20122 ./prep_dataset/ILSVRC2012_val_00018057.bin 224 224 +20123 ./prep_dataset/ILSVRC2012_val_00049056.bin 224 224 +20124 ./prep_dataset/ILSVRC2012_val_00048359.bin 224 224 +20125 ./prep_dataset/ILSVRC2012_val_00048543.bin 224 224 +20126 ./prep_dataset/ILSVRC2012_val_00042914.bin 224 224 +20127 ./prep_dataset/ILSVRC2012_val_00041297.bin 224 224 +20128 ./prep_dataset/ILSVRC2012_val_00029006.bin 224 224 +20129 ./prep_dataset/ILSVRC2012_val_00043697.bin 224 224 +20130 ./prep_dataset/ILSVRC2012_val_00012470.bin 224 224 +20131 ./prep_dataset/ILSVRC2012_val_00004508.bin 224 224 +20132 ./prep_dataset/ILSVRC2012_val_00036816.bin 224 224 +20133 ./prep_dataset/ILSVRC2012_val_00021743.bin 224 224 +20134 ./prep_dataset/ILSVRC2012_val_00016151.bin 224 224 +20135 ./prep_dataset/ILSVRC2012_val_00020417.bin 224 224 +20136 ./prep_dataset/ILSVRC2012_val_00035701.bin 224 224 +20137 ./prep_dataset/ILSVRC2012_val_00033664.bin 224 224 +20138 ./prep_dataset/ILSVRC2012_val_00035363.bin 224 224 +20139 ./prep_dataset/ILSVRC2012_val_00010422.bin 224 224 +20140 ./prep_dataset/ILSVRC2012_val_00027220.bin 224 224 +20141 ./prep_dataset/ILSVRC2012_val_00024899.bin 224 224 +20142 ./prep_dataset/ILSVRC2012_val_00040500.bin 224 224 +20143 ./prep_dataset/ILSVRC2012_val_00029715.bin 224 224 +20144 ./prep_dataset/ILSVRC2012_val_00028952.bin 224 224 +20145 ./prep_dataset/ILSVRC2012_val_00003995.bin 224 224 +20146 ./prep_dataset/ILSVRC2012_val_00038035.bin 224 224 +20147 ./prep_dataset/ILSVRC2012_val_00041004.bin 224 224 +20148 ./prep_dataset/ILSVRC2012_val_00041544.bin 224 224 +20149 ./prep_dataset/ILSVRC2012_val_00042090.bin 224 224 +20150 ./prep_dataset/ILSVRC2012_val_00041115.bin 224 224 +20151 ./prep_dataset/ILSVRC2012_val_00037646.bin 224 224 +20152 ./prep_dataset/ILSVRC2012_val_00035672.bin 224 224 +20153 ./prep_dataset/ILSVRC2012_val_00040739.bin 224 224 +20154 ./prep_dataset/ILSVRC2012_val_00006083.bin 224 224 +20155 ./prep_dataset/ILSVRC2012_val_00036592.bin 224 224 +20156 ./prep_dataset/ILSVRC2012_val_00024019.bin 224 224 +20157 ./prep_dataset/ILSVRC2012_val_00021973.bin 224 224 +20158 ./prep_dataset/ILSVRC2012_val_00043125.bin 224 224 +20159 ./prep_dataset/ILSVRC2012_val_00021554.bin 224 224 +20160 ./prep_dataset/ILSVRC2012_val_00049671.bin 224 224 +20161 ./prep_dataset/ILSVRC2012_val_00046133.bin 224 224 +20162 ./prep_dataset/ILSVRC2012_val_00009707.bin 224 224 +20163 ./prep_dataset/ILSVRC2012_val_00009789.bin 224 224 +20164 ./prep_dataset/ILSVRC2012_val_00020390.bin 224 224 +20165 ./prep_dataset/ILSVRC2012_val_00009658.bin 224 224 +20166 ./prep_dataset/ILSVRC2012_val_00039858.bin 224 224 +20167 ./prep_dataset/ILSVRC2012_val_00040817.bin 224 224 +20168 ./prep_dataset/ILSVRC2012_val_00015650.bin 224 224 +20169 ./prep_dataset/ILSVRC2012_val_00002397.bin 224 224 +20170 ./prep_dataset/ILSVRC2012_val_00044663.bin 224 224 +20171 ./prep_dataset/ILSVRC2012_val_00035424.bin 224 224 +20172 ./prep_dataset/ILSVRC2012_val_00009105.bin 224 224 +20173 ./prep_dataset/ILSVRC2012_val_00005195.bin 224 224 +20174 ./prep_dataset/ILSVRC2012_val_00013198.bin 224 224 +20175 ./prep_dataset/ILSVRC2012_val_00016700.bin 224 224 +20176 ./prep_dataset/ILSVRC2012_val_00007297.bin 224 224 +20177 ./prep_dataset/ILSVRC2012_val_00046644.bin 224 224 +20178 ./prep_dataset/ILSVRC2012_val_00012674.bin 224 224 +20179 ./prep_dataset/ILSVRC2012_val_00021056.bin 224 224 +20180 ./prep_dataset/ILSVRC2012_val_00038527.bin 224 224 +20181 ./prep_dataset/ILSVRC2012_val_00018526.bin 224 224 +20182 ./prep_dataset/ILSVRC2012_val_00008988.bin 224 224 +20183 ./prep_dataset/ILSVRC2012_val_00048727.bin 224 224 +20184 ./prep_dataset/ILSVRC2012_val_00041476.bin 224 224 +20185 ./prep_dataset/ILSVRC2012_val_00037837.bin 224 224 +20186 ./prep_dataset/ILSVRC2012_val_00009379.bin 224 224 +20187 ./prep_dataset/ILSVRC2012_val_00030556.bin 224 224 +20188 ./prep_dataset/ILSVRC2012_val_00036145.bin 224 224 +20189 ./prep_dataset/ILSVRC2012_val_00017643.bin 224 224 +20190 ./prep_dataset/ILSVRC2012_val_00031190.bin 224 224 +20191 ./prep_dataset/ILSVRC2012_val_00012451.bin 224 224 +20192 ./prep_dataset/ILSVRC2012_val_00035719.bin 224 224 +20193 ./prep_dataset/ILSVRC2012_val_00009720.bin 224 224 +20194 ./prep_dataset/ILSVRC2012_val_00026753.bin 224 224 +20195 ./prep_dataset/ILSVRC2012_val_00048581.bin 224 224 +20196 ./prep_dataset/ILSVRC2012_val_00016422.bin 224 224 +20197 ./prep_dataset/ILSVRC2012_val_00044896.bin 224 224 +20198 ./prep_dataset/ILSVRC2012_val_00005268.bin 224 224 +20199 ./prep_dataset/ILSVRC2012_val_00031884.bin 224 224 +20200 ./prep_dataset/ILSVRC2012_val_00003419.bin 224 224 +20201 ./prep_dataset/ILSVRC2012_val_00029447.bin 224 224 +20202 ./prep_dataset/ILSVRC2012_val_00042104.bin 224 224 +20203 ./prep_dataset/ILSVRC2012_val_00031555.bin 224 224 +20204 ./prep_dataset/ILSVRC2012_val_00016412.bin 224 224 +20205 ./prep_dataset/ILSVRC2012_val_00046651.bin 224 224 +20206 ./prep_dataset/ILSVRC2012_val_00048836.bin 224 224 +20207 ./prep_dataset/ILSVRC2012_val_00000308.bin 224 224 +20208 ./prep_dataset/ILSVRC2012_val_00003441.bin 224 224 +20209 ./prep_dataset/ILSVRC2012_val_00006282.bin 224 224 +20210 ./prep_dataset/ILSVRC2012_val_00049924.bin 224 224 +20211 ./prep_dataset/ILSVRC2012_val_00025003.bin 224 224 +20212 ./prep_dataset/ILSVRC2012_val_00016345.bin 224 224 +20213 ./prep_dataset/ILSVRC2012_val_00022205.bin 224 224 +20214 ./prep_dataset/ILSVRC2012_val_00029025.bin 224 224 +20215 ./prep_dataset/ILSVRC2012_val_00005566.bin 224 224 +20216 ./prep_dataset/ILSVRC2012_val_00013441.bin 224 224 +20217 ./prep_dataset/ILSVRC2012_val_00001605.bin 224 224 +20218 ./prep_dataset/ILSVRC2012_val_00024811.bin 224 224 +20219 ./prep_dataset/ILSVRC2012_val_00007513.bin 224 224 +20220 ./prep_dataset/ILSVRC2012_val_00012494.bin 224 224 +20221 ./prep_dataset/ILSVRC2012_val_00028438.bin 224 224 +20222 ./prep_dataset/ILSVRC2012_val_00043831.bin 224 224 +20223 ./prep_dataset/ILSVRC2012_val_00010344.bin 224 224 +20224 ./prep_dataset/ILSVRC2012_val_00006342.bin 224 224 +20225 ./prep_dataset/ILSVRC2012_val_00011345.bin 224 224 +20226 ./prep_dataset/ILSVRC2012_val_00024011.bin 224 224 +20227 ./prep_dataset/ILSVRC2012_val_00038861.bin 224 224 +20228 ./prep_dataset/ILSVRC2012_val_00035312.bin 224 224 +20229 ./prep_dataset/ILSVRC2012_val_00000744.bin 224 224 +20230 ./prep_dataset/ILSVRC2012_val_00028483.bin 224 224 +20231 ./prep_dataset/ILSVRC2012_val_00002103.bin 224 224 +20232 ./prep_dataset/ILSVRC2012_val_00008895.bin 224 224 +20233 ./prep_dataset/ILSVRC2012_val_00037000.bin 224 224 +20234 ./prep_dataset/ILSVRC2012_val_00048855.bin 224 224 +20235 ./prep_dataset/ILSVRC2012_val_00030163.bin 224 224 +20236 ./prep_dataset/ILSVRC2012_val_00033698.bin 224 224 +20237 ./prep_dataset/ILSVRC2012_val_00032113.bin 224 224 +20238 ./prep_dataset/ILSVRC2012_val_00034687.bin 224 224 +20239 ./prep_dataset/ILSVRC2012_val_00015602.bin 224 224 +20240 ./prep_dataset/ILSVRC2012_val_00036555.bin 224 224 +20241 ./prep_dataset/ILSVRC2012_val_00029826.bin 224 224 +20242 ./prep_dataset/ILSVRC2012_val_00037204.bin 224 224 +20243 ./prep_dataset/ILSVRC2012_val_00035322.bin 224 224 +20244 ./prep_dataset/ILSVRC2012_val_00044813.bin 224 224 +20245 ./prep_dataset/ILSVRC2012_val_00030558.bin 224 224 +20246 ./prep_dataset/ILSVRC2012_val_00033239.bin 224 224 +20247 ./prep_dataset/ILSVRC2012_val_00029061.bin 224 224 +20248 ./prep_dataset/ILSVRC2012_val_00011998.bin 224 224 +20249 ./prep_dataset/ILSVRC2012_val_00036790.bin 224 224 +20250 ./prep_dataset/ILSVRC2012_val_00015729.bin 224 224 +20251 ./prep_dataset/ILSVRC2012_val_00007745.bin 224 224 +20252 ./prep_dataset/ILSVRC2012_val_00037850.bin 224 224 +20253 ./prep_dataset/ILSVRC2012_val_00015373.bin 224 224 +20254 ./prep_dataset/ILSVRC2012_val_00048609.bin 224 224 +20255 ./prep_dataset/ILSVRC2012_val_00019254.bin 224 224 +20256 ./prep_dataset/ILSVRC2012_val_00046616.bin 224 224 +20257 ./prep_dataset/ILSVRC2012_val_00043747.bin 224 224 +20258 ./prep_dataset/ILSVRC2012_val_00027511.bin 224 224 +20259 ./prep_dataset/ILSVRC2012_val_00004257.bin 224 224 +20260 ./prep_dataset/ILSVRC2012_val_00005454.bin 224 224 +20261 ./prep_dataset/ILSVRC2012_val_00045825.bin 224 224 +20262 ./prep_dataset/ILSVRC2012_val_00028799.bin 224 224 +20263 ./prep_dataset/ILSVRC2012_val_00038940.bin 224 224 +20264 ./prep_dataset/ILSVRC2012_val_00030018.bin 224 224 +20265 ./prep_dataset/ILSVRC2012_val_00020595.bin 224 224 +20266 ./prep_dataset/ILSVRC2012_val_00006892.bin 224 224 +20267 ./prep_dataset/ILSVRC2012_val_00007779.bin 224 224 +20268 ./prep_dataset/ILSVRC2012_val_00044002.bin 224 224 +20269 ./prep_dataset/ILSVRC2012_val_00037735.bin 224 224 +20270 ./prep_dataset/ILSVRC2012_val_00000592.bin 224 224 +20271 ./prep_dataset/ILSVRC2012_val_00044786.bin 224 224 +20272 ./prep_dataset/ILSVRC2012_val_00029333.bin 224 224 +20273 ./prep_dataset/ILSVRC2012_val_00028258.bin 224 224 +20274 ./prep_dataset/ILSVRC2012_val_00031612.bin 224 224 +20275 ./prep_dataset/ILSVRC2012_val_00006193.bin 224 224 +20276 ./prep_dataset/ILSVRC2012_val_00016334.bin 224 224 +20277 ./prep_dataset/ILSVRC2012_val_00038187.bin 224 224 +20278 ./prep_dataset/ILSVRC2012_val_00015155.bin 224 224 +20279 ./prep_dataset/ILSVRC2012_val_00039305.bin 224 224 +20280 ./prep_dataset/ILSVRC2012_val_00029918.bin 224 224 +20281 ./prep_dataset/ILSVRC2012_val_00047414.bin 224 224 +20282 ./prep_dataset/ILSVRC2012_val_00004138.bin 224 224 +20283 ./prep_dataset/ILSVRC2012_val_00022129.bin 224 224 +20284 ./prep_dataset/ILSVRC2012_val_00012323.bin 224 224 +20285 ./prep_dataset/ILSVRC2012_val_00006354.bin 224 224 +20286 ./prep_dataset/ILSVRC2012_val_00025261.bin 224 224 +20287 ./prep_dataset/ILSVRC2012_val_00015777.bin 224 224 +20288 ./prep_dataset/ILSVRC2012_val_00046209.bin 224 224 +20289 ./prep_dataset/ILSVRC2012_val_00005456.bin 224 224 +20290 ./prep_dataset/ILSVRC2012_val_00042049.bin 224 224 +20291 ./prep_dataset/ILSVRC2012_val_00024808.bin 224 224 +20292 ./prep_dataset/ILSVRC2012_val_00029718.bin 224 224 +20293 ./prep_dataset/ILSVRC2012_val_00023817.bin 224 224 +20294 ./prep_dataset/ILSVRC2012_val_00014792.bin 224 224 +20295 ./prep_dataset/ILSVRC2012_val_00044326.bin 224 224 +20296 ./prep_dataset/ILSVRC2012_val_00000736.bin 224 224 +20297 ./prep_dataset/ILSVRC2012_val_00038074.bin 224 224 +20298 ./prep_dataset/ILSVRC2012_val_00034163.bin 224 224 +20299 ./prep_dataset/ILSVRC2012_val_00034274.bin 224 224 +20300 ./prep_dataset/ILSVRC2012_val_00018352.bin 224 224 +20301 ./prep_dataset/ILSVRC2012_val_00029121.bin 224 224 +20302 ./prep_dataset/ILSVRC2012_val_00041106.bin 224 224 +20303 ./prep_dataset/ILSVRC2012_val_00025542.bin 224 224 +20304 ./prep_dataset/ILSVRC2012_val_00012407.bin 224 224 +20305 ./prep_dataset/ILSVRC2012_val_00017013.bin 224 224 +20306 ./prep_dataset/ILSVRC2012_val_00045291.bin 224 224 +20307 ./prep_dataset/ILSVRC2012_val_00042664.bin 224 224 +20308 ./prep_dataset/ILSVRC2012_val_00012005.bin 224 224 +20309 ./prep_dataset/ILSVRC2012_val_00033058.bin 224 224 +20310 ./prep_dataset/ILSVRC2012_val_00034717.bin 224 224 +20311 ./prep_dataset/ILSVRC2012_val_00048265.bin 224 224 +20312 ./prep_dataset/ILSVRC2012_val_00032531.bin 224 224 +20313 ./prep_dataset/ILSVRC2012_val_00013717.bin 224 224 +20314 ./prep_dataset/ILSVRC2012_val_00000079.bin 224 224 +20315 ./prep_dataset/ILSVRC2012_val_00039971.bin 224 224 +20316 ./prep_dataset/ILSVRC2012_val_00047351.bin 224 224 +20317 ./prep_dataset/ILSVRC2012_val_00042994.bin 224 224 +20318 ./prep_dataset/ILSVRC2012_val_00045710.bin 224 224 +20319 ./prep_dataset/ILSVRC2012_val_00045620.bin 224 224 +20320 ./prep_dataset/ILSVRC2012_val_00022848.bin 224 224 +20321 ./prep_dataset/ILSVRC2012_val_00043673.bin 224 224 +20322 ./prep_dataset/ILSVRC2012_val_00003191.bin 224 224 +20323 ./prep_dataset/ILSVRC2012_val_00046274.bin 224 224 +20324 ./prep_dataset/ILSVRC2012_val_00021294.bin 224 224 +20325 ./prep_dataset/ILSVRC2012_val_00032092.bin 224 224 +20326 ./prep_dataset/ILSVRC2012_val_00040221.bin 224 224 +20327 ./prep_dataset/ILSVRC2012_val_00048653.bin 224 224 +20328 ./prep_dataset/ILSVRC2012_val_00046444.bin 224 224 +20329 ./prep_dataset/ILSVRC2012_val_00023231.bin 224 224 +20330 ./prep_dataset/ILSVRC2012_val_00015227.bin 224 224 +20331 ./prep_dataset/ILSVRC2012_val_00021884.bin 224 224 +20332 ./prep_dataset/ILSVRC2012_val_00010733.bin 224 224 +20333 ./prep_dataset/ILSVRC2012_val_00026897.bin 224 224 +20334 ./prep_dataset/ILSVRC2012_val_00031818.bin 224 224 +20335 ./prep_dataset/ILSVRC2012_val_00013066.bin 224 224 +20336 ./prep_dataset/ILSVRC2012_val_00037454.bin 224 224 +20337 ./prep_dataset/ILSVRC2012_val_00031577.bin 224 224 +20338 ./prep_dataset/ILSVRC2012_val_00021459.bin 224 224 +20339 ./prep_dataset/ILSVRC2012_val_00039331.bin 224 224 +20340 ./prep_dataset/ILSVRC2012_val_00047072.bin 224 224 +20341 ./prep_dataset/ILSVRC2012_val_00009463.bin 224 224 +20342 ./prep_dataset/ILSVRC2012_val_00017089.bin 224 224 +20343 ./prep_dataset/ILSVRC2012_val_00010669.bin 224 224 +20344 ./prep_dataset/ILSVRC2012_val_00039506.bin 224 224 +20345 ./prep_dataset/ILSVRC2012_val_00005658.bin 224 224 +20346 ./prep_dataset/ILSVRC2012_val_00048799.bin 224 224 +20347 ./prep_dataset/ILSVRC2012_val_00046114.bin 224 224 +20348 ./prep_dataset/ILSVRC2012_val_00048137.bin 224 224 +20349 ./prep_dataset/ILSVRC2012_val_00038406.bin 224 224 +20350 ./prep_dataset/ILSVRC2012_val_00040967.bin 224 224 +20351 ./prep_dataset/ILSVRC2012_val_00020410.bin 224 224 +20352 ./prep_dataset/ILSVRC2012_val_00032613.bin 224 224 +20353 ./prep_dataset/ILSVRC2012_val_00048355.bin 224 224 +20354 ./prep_dataset/ILSVRC2012_val_00015696.bin 224 224 +20355 ./prep_dataset/ILSVRC2012_val_00030266.bin 224 224 +20356 ./prep_dataset/ILSVRC2012_val_00003074.bin 224 224 +20357 ./prep_dataset/ILSVRC2012_val_00034872.bin 224 224 +20358 ./prep_dataset/ILSVRC2012_val_00009263.bin 224 224 +20359 ./prep_dataset/ILSVRC2012_val_00018884.bin 224 224 +20360 ./prep_dataset/ILSVRC2012_val_00010083.bin 224 224 +20361 ./prep_dataset/ILSVRC2012_val_00032568.bin 224 224 +20362 ./prep_dataset/ILSVRC2012_val_00007170.bin 224 224 +20363 ./prep_dataset/ILSVRC2012_val_00032632.bin 224 224 +20364 ./prep_dataset/ILSVRC2012_val_00006723.bin 224 224 +20365 ./prep_dataset/ILSVRC2012_val_00004719.bin 224 224 +20366 ./prep_dataset/ILSVRC2012_val_00013667.bin 224 224 +20367 ./prep_dataset/ILSVRC2012_val_00003307.bin 224 224 +20368 ./prep_dataset/ILSVRC2012_val_00048710.bin 224 224 +20369 ./prep_dataset/ILSVRC2012_val_00048258.bin 224 224 +20370 ./prep_dataset/ILSVRC2012_val_00017890.bin 224 224 +20371 ./prep_dataset/ILSVRC2012_val_00036164.bin 224 224 +20372 ./prep_dataset/ILSVRC2012_val_00029618.bin 224 224 +20373 ./prep_dataset/ILSVRC2012_val_00047727.bin 224 224 +20374 ./prep_dataset/ILSVRC2012_val_00041671.bin 224 224 +20375 ./prep_dataset/ILSVRC2012_val_00006075.bin 224 224 +20376 ./prep_dataset/ILSVRC2012_val_00004968.bin 224 224 +20377 ./prep_dataset/ILSVRC2012_val_00040692.bin 224 224 +20378 ./prep_dataset/ILSVRC2012_val_00049905.bin 224 224 +20379 ./prep_dataset/ILSVRC2012_val_00000317.bin 224 224 +20380 ./prep_dataset/ILSVRC2012_val_00044707.bin 224 224 +20381 ./prep_dataset/ILSVRC2012_val_00022063.bin 224 224 +20382 ./prep_dataset/ILSVRC2012_val_00011960.bin 224 224 +20383 ./prep_dataset/ILSVRC2012_val_00007599.bin 224 224 +20384 ./prep_dataset/ILSVRC2012_val_00001689.bin 224 224 +20385 ./prep_dataset/ILSVRC2012_val_00040547.bin 224 224 +20386 ./prep_dataset/ILSVRC2012_val_00040144.bin 224 224 +20387 ./prep_dataset/ILSVRC2012_val_00036377.bin 224 224 +20388 ./prep_dataset/ILSVRC2012_val_00002359.bin 224 224 +20389 ./prep_dataset/ILSVRC2012_val_00049220.bin 224 224 +20390 ./prep_dataset/ILSVRC2012_val_00020092.bin 224 224 +20391 ./prep_dataset/ILSVRC2012_val_00037340.bin 224 224 +20392 ./prep_dataset/ILSVRC2012_val_00034983.bin 224 224 +20393 ./prep_dataset/ILSVRC2012_val_00026109.bin 224 224 +20394 ./prep_dataset/ILSVRC2012_val_00032343.bin 224 224 +20395 ./prep_dataset/ILSVRC2012_val_00017819.bin 224 224 +20396 ./prep_dataset/ILSVRC2012_val_00012506.bin 224 224 +20397 ./prep_dataset/ILSVRC2012_val_00031799.bin 224 224 +20398 ./prep_dataset/ILSVRC2012_val_00008392.bin 224 224 +20399 ./prep_dataset/ILSVRC2012_val_00005700.bin 224 224 +20400 ./prep_dataset/ILSVRC2012_val_00024095.bin 224 224 +20401 ./prep_dataset/ILSVRC2012_val_00022775.bin 224 224 +20402 ./prep_dataset/ILSVRC2012_val_00047071.bin 224 224 +20403 ./prep_dataset/ILSVRC2012_val_00022543.bin 224 224 +20404 ./prep_dataset/ILSVRC2012_val_00017788.bin 224 224 +20405 ./prep_dataset/ILSVRC2012_val_00019771.bin 224 224 +20406 ./prep_dataset/ILSVRC2012_val_00014619.bin 224 224 +20407 ./prep_dataset/ILSVRC2012_val_00023142.bin 224 224 +20408 ./prep_dataset/ILSVRC2012_val_00039240.bin 224 224 +20409 ./prep_dataset/ILSVRC2012_val_00048072.bin 224 224 +20410 ./prep_dataset/ILSVRC2012_val_00012669.bin 224 224 +20411 ./prep_dataset/ILSVRC2012_val_00032542.bin 224 224 +20412 ./prep_dataset/ILSVRC2012_val_00030858.bin 224 224 +20413 ./prep_dataset/ILSVRC2012_val_00046957.bin 224 224 +20414 ./prep_dataset/ILSVRC2012_val_00029567.bin 224 224 +20415 ./prep_dataset/ILSVRC2012_val_00011225.bin 224 224 +20416 ./prep_dataset/ILSVRC2012_val_00040713.bin 224 224 +20417 ./prep_dataset/ILSVRC2012_val_00026320.bin 224 224 +20418 ./prep_dataset/ILSVRC2012_val_00021129.bin 224 224 +20419 ./prep_dataset/ILSVRC2012_val_00049117.bin 224 224 +20420 ./prep_dataset/ILSVRC2012_val_00002430.bin 224 224 +20421 ./prep_dataset/ILSVRC2012_val_00039976.bin 224 224 +20422 ./prep_dataset/ILSVRC2012_val_00019839.bin 224 224 +20423 ./prep_dataset/ILSVRC2012_val_00049824.bin 224 224 +20424 ./prep_dataset/ILSVRC2012_val_00045766.bin 224 224 +20425 ./prep_dataset/ILSVRC2012_val_00019681.bin 224 224 +20426 ./prep_dataset/ILSVRC2012_val_00025776.bin 224 224 +20427 ./prep_dataset/ILSVRC2012_val_00016041.bin 224 224 +20428 ./prep_dataset/ILSVRC2012_val_00027913.bin 224 224 +20429 ./prep_dataset/ILSVRC2012_val_00004421.bin 224 224 +20430 ./prep_dataset/ILSVRC2012_val_00003885.bin 224 224 +20431 ./prep_dataset/ILSVRC2012_val_00023775.bin 224 224 +20432 ./prep_dataset/ILSVRC2012_val_00018010.bin 224 224 +20433 ./prep_dataset/ILSVRC2012_val_00017847.bin 224 224 +20434 ./prep_dataset/ILSVRC2012_val_00046424.bin 224 224 +20435 ./prep_dataset/ILSVRC2012_val_00010086.bin 224 224 +20436 ./prep_dataset/ILSVRC2012_val_00017216.bin 224 224 +20437 ./prep_dataset/ILSVRC2012_val_00015354.bin 224 224 +20438 ./prep_dataset/ILSVRC2012_val_00010059.bin 224 224 +20439 ./prep_dataset/ILSVRC2012_val_00000395.bin 224 224 +20440 ./prep_dataset/ILSVRC2012_val_00001314.bin 224 224 +20441 ./prep_dataset/ILSVRC2012_val_00041739.bin 224 224 +20442 ./prep_dataset/ILSVRC2012_val_00028852.bin 224 224 +20443 ./prep_dataset/ILSVRC2012_val_00016039.bin 224 224 +20444 ./prep_dataset/ILSVRC2012_val_00029517.bin 224 224 +20445 ./prep_dataset/ILSVRC2012_val_00001724.bin 224 224 +20446 ./prep_dataset/ILSVRC2012_val_00014126.bin 224 224 +20447 ./prep_dataset/ILSVRC2012_val_00041809.bin 224 224 +20448 ./prep_dataset/ILSVRC2012_val_00004491.bin 224 224 +20449 ./prep_dataset/ILSVRC2012_val_00021569.bin 224 224 +20450 ./prep_dataset/ILSVRC2012_val_00000054.bin 224 224 +20451 ./prep_dataset/ILSVRC2012_val_00018633.bin 224 224 +20452 ./prep_dataset/ILSVRC2012_val_00048442.bin 224 224 +20453 ./prep_dataset/ILSVRC2012_val_00042519.bin 224 224 +20454 ./prep_dataset/ILSVRC2012_val_00020197.bin 224 224 +20455 ./prep_dataset/ILSVRC2012_val_00041893.bin 224 224 +20456 ./prep_dataset/ILSVRC2012_val_00013234.bin 224 224 +20457 ./prep_dataset/ILSVRC2012_val_00035108.bin 224 224 +20458 ./prep_dataset/ILSVRC2012_val_00042668.bin 224 224 +20459 ./prep_dataset/ILSVRC2012_val_00010755.bin 224 224 +20460 ./prep_dataset/ILSVRC2012_val_00048151.bin 224 224 +20461 ./prep_dataset/ILSVRC2012_val_00016156.bin 224 224 +20462 ./prep_dataset/ILSVRC2012_val_00033667.bin 224 224 +20463 ./prep_dataset/ILSVRC2012_val_00018478.bin 224 224 +20464 ./prep_dataset/ILSVRC2012_val_00011344.bin 224 224 +20465 ./prep_dataset/ILSVRC2012_val_00013408.bin 224 224 +20466 ./prep_dataset/ILSVRC2012_val_00001602.bin 224 224 +20467 ./prep_dataset/ILSVRC2012_val_00017109.bin 224 224 +20468 ./prep_dataset/ILSVRC2012_val_00049581.bin 224 224 +20469 ./prep_dataset/ILSVRC2012_val_00032417.bin 224 224 +20470 ./prep_dataset/ILSVRC2012_val_00029746.bin 224 224 +20471 ./prep_dataset/ILSVRC2012_val_00010244.bin 224 224 +20472 ./prep_dataset/ILSVRC2012_val_00032976.bin 224 224 +20473 ./prep_dataset/ILSVRC2012_val_00036925.bin 224 224 +20474 ./prep_dataset/ILSVRC2012_val_00021281.bin 224 224 +20475 ./prep_dataset/ILSVRC2012_val_00046871.bin 224 224 +20476 ./prep_dataset/ILSVRC2012_val_00036932.bin 224 224 +20477 ./prep_dataset/ILSVRC2012_val_00032004.bin 224 224 +20478 ./prep_dataset/ILSVRC2012_val_00024698.bin 224 224 +20479 ./prep_dataset/ILSVRC2012_val_00048026.bin 224 224 +20480 ./prep_dataset/ILSVRC2012_val_00048337.bin 224 224 +20481 ./prep_dataset/ILSVRC2012_val_00012108.bin 224 224 +20482 ./prep_dataset/ILSVRC2012_val_00033089.bin 224 224 +20483 ./prep_dataset/ILSVRC2012_val_00039093.bin 224 224 +20484 ./prep_dataset/ILSVRC2012_val_00036428.bin 224 224 +20485 ./prep_dataset/ILSVRC2012_val_00034259.bin 224 224 +20486 ./prep_dataset/ILSVRC2012_val_00014077.bin 224 224 +20487 ./prep_dataset/ILSVRC2012_val_00042255.bin 224 224 +20488 ./prep_dataset/ILSVRC2012_val_00023496.bin 224 224 +20489 ./prep_dataset/ILSVRC2012_val_00030633.bin 224 224 +20490 ./prep_dataset/ILSVRC2012_val_00002197.bin 224 224 +20491 ./prep_dataset/ILSVRC2012_val_00004518.bin 224 224 +20492 ./prep_dataset/ILSVRC2012_val_00030328.bin 224 224 +20493 ./prep_dataset/ILSVRC2012_val_00022703.bin 224 224 +20494 ./prep_dataset/ILSVRC2012_val_00032525.bin 224 224 +20495 ./prep_dataset/ILSVRC2012_val_00015929.bin 224 224 +20496 ./prep_dataset/ILSVRC2012_val_00043982.bin 224 224 +20497 ./prep_dataset/ILSVRC2012_val_00027380.bin 224 224 +20498 ./prep_dataset/ILSVRC2012_val_00008860.bin 224 224 +20499 ./prep_dataset/ILSVRC2012_val_00010194.bin 224 224 +20500 ./prep_dataset/ILSVRC2012_val_00006912.bin 224 224 +20501 ./prep_dataset/ILSVRC2012_val_00023611.bin 224 224 +20502 ./prep_dataset/ILSVRC2012_val_00031697.bin 224 224 +20503 ./prep_dataset/ILSVRC2012_val_00038544.bin 224 224 +20504 ./prep_dataset/ILSVRC2012_val_00029800.bin 224 224 +20505 ./prep_dataset/ILSVRC2012_val_00035584.bin 224 224 +20506 ./prep_dataset/ILSVRC2012_val_00000372.bin 224 224 +20507 ./prep_dataset/ILSVRC2012_val_00012564.bin 224 224 +20508 ./prep_dataset/ILSVRC2012_val_00030224.bin 224 224 +20509 ./prep_dataset/ILSVRC2012_val_00021497.bin 224 224 +20510 ./prep_dataset/ILSVRC2012_val_00016021.bin 224 224 +20511 ./prep_dataset/ILSVRC2012_val_00011218.bin 224 224 +20512 ./prep_dataset/ILSVRC2012_val_00035620.bin 224 224 +20513 ./prep_dataset/ILSVRC2012_val_00036418.bin 224 224 +20514 ./prep_dataset/ILSVRC2012_val_00011020.bin 224 224 +20515 ./prep_dataset/ILSVRC2012_val_00033381.bin 224 224 +20516 ./prep_dataset/ILSVRC2012_val_00000375.bin 224 224 +20517 ./prep_dataset/ILSVRC2012_val_00012840.bin 224 224 +20518 ./prep_dataset/ILSVRC2012_val_00030836.bin 224 224 +20519 ./prep_dataset/ILSVRC2012_val_00001323.bin 224 224 +20520 ./prep_dataset/ILSVRC2012_val_00034948.bin 224 224 +20521 ./prep_dataset/ILSVRC2012_val_00027599.bin 224 224 +20522 ./prep_dataset/ILSVRC2012_val_00012167.bin 224 224 +20523 ./prep_dataset/ILSVRC2012_val_00041973.bin 224 224 +20524 ./prep_dataset/ILSVRC2012_val_00043611.bin 224 224 +20525 ./prep_dataset/ILSVRC2012_val_00008589.bin 224 224 +20526 ./prep_dataset/ILSVRC2012_val_00033067.bin 224 224 +20527 ./prep_dataset/ILSVRC2012_val_00007148.bin 224 224 +20528 ./prep_dataset/ILSVRC2012_val_00020157.bin 224 224 +20529 ./prep_dataset/ILSVRC2012_val_00039000.bin 224 224 +20530 ./prep_dataset/ILSVRC2012_val_00042650.bin 224 224 +20531 ./prep_dataset/ILSVRC2012_val_00032886.bin 224 224 +20532 ./prep_dataset/ILSVRC2012_val_00019899.bin 224 224 +20533 ./prep_dataset/ILSVRC2012_val_00023103.bin 224 224 +20534 ./prep_dataset/ILSVRC2012_val_00032548.bin 224 224 +20535 ./prep_dataset/ILSVRC2012_val_00003044.bin 224 224 +20536 ./prep_dataset/ILSVRC2012_val_00007267.bin 224 224 +20537 ./prep_dataset/ILSVRC2012_val_00041043.bin 224 224 +20538 ./prep_dataset/ILSVRC2012_val_00047575.bin 224 224 +20539 ./prep_dataset/ILSVRC2012_val_00026290.bin 224 224 +20540 ./prep_dataset/ILSVRC2012_val_00038785.bin 224 224 +20541 ./prep_dataset/ILSVRC2012_val_00003994.bin 224 224 +20542 ./prep_dataset/ILSVRC2012_val_00046777.bin 224 224 +20543 ./prep_dataset/ILSVRC2012_val_00006709.bin 224 224 +20544 ./prep_dataset/ILSVRC2012_val_00049277.bin 224 224 +20545 ./prep_dataset/ILSVRC2012_val_00026623.bin 224 224 +20546 ./prep_dataset/ILSVRC2012_val_00018442.bin 224 224 +20547 ./prep_dataset/ILSVRC2012_val_00014913.bin 224 224 +20548 ./prep_dataset/ILSVRC2012_val_00000630.bin 224 224 +20549 ./prep_dataset/ILSVRC2012_val_00021715.bin 224 224 +20550 ./prep_dataset/ILSVRC2012_val_00012959.bin 224 224 +20551 ./prep_dataset/ILSVRC2012_val_00020368.bin 224 224 +20552 ./prep_dataset/ILSVRC2012_val_00047954.bin 224 224 +20553 ./prep_dataset/ILSVRC2012_val_00018126.bin 224 224 +20554 ./prep_dataset/ILSVRC2012_val_00002717.bin 224 224 +20555 ./prep_dataset/ILSVRC2012_val_00026901.bin 224 224 +20556 ./prep_dataset/ILSVRC2012_val_00003143.bin 224 224 +20557 ./prep_dataset/ILSVRC2012_val_00040054.bin 224 224 +20558 ./prep_dataset/ILSVRC2012_val_00038435.bin 224 224 +20559 ./prep_dataset/ILSVRC2012_val_00020576.bin 224 224 +20560 ./prep_dataset/ILSVRC2012_val_00007927.bin 224 224 +20561 ./prep_dataset/ILSVRC2012_val_00016733.bin 224 224 +20562 ./prep_dataset/ILSVRC2012_val_00019330.bin 224 224 +20563 ./prep_dataset/ILSVRC2012_val_00046734.bin 224 224 +20564 ./prep_dataset/ILSVRC2012_val_00000269.bin 224 224 +20565 ./prep_dataset/ILSVRC2012_val_00017757.bin 224 224 +20566 ./prep_dataset/ILSVRC2012_val_00007851.bin 224 224 +20567 ./prep_dataset/ILSVRC2012_val_00024784.bin 224 224 +20568 ./prep_dataset/ILSVRC2012_val_00004026.bin 224 224 +20569 ./prep_dataset/ILSVRC2012_val_00010435.bin 224 224 +20570 ./prep_dataset/ILSVRC2012_val_00037980.bin 224 224 +20571 ./prep_dataset/ILSVRC2012_val_00003575.bin 224 224 +20572 ./prep_dataset/ILSVRC2012_val_00027502.bin 224 224 +20573 ./prep_dataset/ILSVRC2012_val_00041285.bin 224 224 +20574 ./prep_dataset/ILSVRC2012_val_00037255.bin 224 224 +20575 ./prep_dataset/ILSVRC2012_val_00007429.bin 224 224 +20576 ./prep_dataset/ILSVRC2012_val_00031822.bin 224 224 +20577 ./prep_dataset/ILSVRC2012_val_00040575.bin 224 224 +20578 ./prep_dataset/ILSVRC2012_val_00019820.bin 224 224 +20579 ./prep_dataset/ILSVRC2012_val_00039745.bin 224 224 +20580 ./prep_dataset/ILSVRC2012_val_00012822.bin 224 224 +20581 ./prep_dataset/ILSVRC2012_val_00032673.bin 224 224 +20582 ./prep_dataset/ILSVRC2012_val_00026841.bin 224 224 +20583 ./prep_dataset/ILSVRC2012_val_00014920.bin 224 224 +20584 ./prep_dataset/ILSVRC2012_val_00028753.bin 224 224 +20585 ./prep_dataset/ILSVRC2012_val_00030074.bin 224 224 +20586 ./prep_dataset/ILSVRC2012_val_00022348.bin 224 224 +20587 ./prep_dataset/ILSVRC2012_val_00013663.bin 224 224 +20588 ./prep_dataset/ILSVRC2012_val_00006385.bin 224 224 +20589 ./prep_dataset/ILSVRC2012_val_00029774.bin 224 224 +20590 ./prep_dataset/ILSVRC2012_val_00043936.bin 224 224 +20591 ./prep_dataset/ILSVRC2012_val_00045735.bin 224 224 +20592 ./prep_dataset/ILSVRC2012_val_00025335.bin 224 224 +20593 ./prep_dataset/ILSVRC2012_val_00007733.bin 224 224 +20594 ./prep_dataset/ILSVRC2012_val_00042340.bin 224 224 +20595 ./prep_dataset/ILSVRC2012_val_00025316.bin 224 224 +20596 ./prep_dataset/ILSVRC2012_val_00008888.bin 224 224 +20597 ./prep_dataset/ILSVRC2012_val_00046873.bin 224 224 +20598 ./prep_dataset/ILSVRC2012_val_00034509.bin 224 224 +20599 ./prep_dataset/ILSVRC2012_val_00038450.bin 224 224 +20600 ./prep_dataset/ILSVRC2012_val_00029820.bin 224 224 +20601 ./prep_dataset/ILSVRC2012_val_00000963.bin 224 224 +20602 ./prep_dataset/ILSVRC2012_val_00017204.bin 224 224 +20603 ./prep_dataset/ILSVRC2012_val_00048630.bin 224 224 +20604 ./prep_dataset/ILSVRC2012_val_00004936.bin 224 224 +20605 ./prep_dataset/ILSVRC2012_val_00031146.bin 224 224 +20606 ./prep_dataset/ILSVRC2012_val_00013806.bin 224 224 +20607 ./prep_dataset/ILSVRC2012_val_00035561.bin 224 224 +20608 ./prep_dataset/ILSVRC2012_val_00006427.bin 224 224 +20609 ./prep_dataset/ILSVRC2012_val_00045087.bin 224 224 +20610 ./prep_dataset/ILSVRC2012_val_00007665.bin 224 224 +20611 ./prep_dataset/ILSVRC2012_val_00026287.bin 224 224 +20612 ./prep_dataset/ILSVRC2012_val_00026013.bin 224 224 +20613 ./prep_dataset/ILSVRC2012_val_00024055.bin 224 224 +20614 ./prep_dataset/ILSVRC2012_val_00026472.bin 224 224 +20615 ./prep_dataset/ILSVRC2012_val_00028524.bin 224 224 +20616 ./prep_dataset/ILSVRC2012_val_00024234.bin 224 224 +20617 ./prep_dataset/ILSVRC2012_val_00036958.bin 224 224 +20618 ./prep_dataset/ILSVRC2012_val_00017950.bin 224 224 +20619 ./prep_dataset/ILSVRC2012_val_00042799.bin 224 224 +20620 ./prep_dataset/ILSVRC2012_val_00023670.bin 224 224 +20621 ./prep_dataset/ILSVRC2012_val_00032176.bin 224 224 +20622 ./prep_dataset/ILSVRC2012_val_00047872.bin 224 224 +20623 ./prep_dataset/ILSVRC2012_val_00015032.bin 224 224 +20624 ./prep_dataset/ILSVRC2012_val_00003164.bin 224 224 +20625 ./prep_dataset/ILSVRC2012_val_00034945.bin 224 224 +20626 ./prep_dataset/ILSVRC2012_val_00031034.bin 224 224 +20627 ./prep_dataset/ILSVRC2012_val_00041762.bin 224 224 +20628 ./prep_dataset/ILSVRC2012_val_00013207.bin 224 224 +20629 ./prep_dataset/ILSVRC2012_val_00030809.bin 224 224 +20630 ./prep_dataset/ILSVRC2012_val_00006058.bin 224 224 +20631 ./prep_dataset/ILSVRC2012_val_00034902.bin 224 224 +20632 ./prep_dataset/ILSVRC2012_val_00018925.bin 224 224 +20633 ./prep_dataset/ILSVRC2012_val_00002179.bin 224 224 +20634 ./prep_dataset/ILSVRC2012_val_00042261.bin 224 224 +20635 ./prep_dataset/ILSVRC2012_val_00023563.bin 224 224 +20636 ./prep_dataset/ILSVRC2012_val_00005760.bin 224 224 +20637 ./prep_dataset/ILSVRC2012_val_00018916.bin 224 224 +20638 ./prep_dataset/ILSVRC2012_val_00044170.bin 224 224 +20639 ./prep_dataset/ILSVRC2012_val_00036571.bin 224 224 +20640 ./prep_dataset/ILSVRC2012_val_00008239.bin 224 224 +20641 ./prep_dataset/ILSVRC2012_val_00032858.bin 224 224 +20642 ./prep_dataset/ILSVRC2012_val_00015866.bin 224 224 +20643 ./prep_dataset/ILSVRC2012_val_00027854.bin 224 224 +20644 ./prep_dataset/ILSVRC2012_val_00031674.bin 224 224 +20645 ./prep_dataset/ILSVRC2012_val_00005310.bin 224 224 +20646 ./prep_dataset/ILSVRC2012_val_00036322.bin 224 224 +20647 ./prep_dataset/ILSVRC2012_val_00017454.bin 224 224 +20648 ./prep_dataset/ILSVRC2012_val_00009737.bin 224 224 +20649 ./prep_dataset/ILSVRC2012_val_00035301.bin 224 224 +20650 ./prep_dataset/ILSVRC2012_val_00041669.bin 224 224 +20651 ./prep_dataset/ILSVRC2012_val_00046999.bin 224 224 +20652 ./prep_dataset/ILSVRC2012_val_00048010.bin 224 224 +20653 ./prep_dataset/ILSVRC2012_val_00011324.bin 224 224 +20654 ./prep_dataset/ILSVRC2012_val_00020872.bin 224 224 +20655 ./prep_dataset/ILSVRC2012_val_00001399.bin 224 224 +20656 ./prep_dataset/ILSVRC2012_val_00048306.bin 224 224 +20657 ./prep_dataset/ILSVRC2012_val_00040660.bin 224 224 +20658 ./prep_dataset/ILSVRC2012_val_00002609.bin 224 224 +20659 ./prep_dataset/ILSVRC2012_val_00035246.bin 224 224 +20660 ./prep_dataset/ILSVRC2012_val_00036218.bin 224 224 +20661 ./prep_dataset/ILSVRC2012_val_00036687.bin 224 224 +20662 ./prep_dataset/ILSVRC2012_val_00031920.bin 224 224 +20663 ./prep_dataset/ILSVRC2012_val_00011319.bin 224 224 +20664 ./prep_dataset/ILSVRC2012_val_00045949.bin 224 224 +20665 ./prep_dataset/ILSVRC2012_val_00009273.bin 224 224 +20666 ./prep_dataset/ILSVRC2012_val_00014999.bin 224 224 +20667 ./prep_dataset/ILSVRC2012_val_00040098.bin 224 224 +20668 ./prep_dataset/ILSVRC2012_val_00032170.bin 224 224 +20669 ./prep_dataset/ILSVRC2012_val_00034129.bin 224 224 +20670 ./prep_dataset/ILSVRC2012_val_00015365.bin 224 224 +20671 ./prep_dataset/ILSVRC2012_val_00010903.bin 224 224 +20672 ./prep_dataset/ILSVRC2012_val_00042915.bin 224 224 +20673 ./prep_dataset/ILSVRC2012_val_00026720.bin 224 224 +20674 ./prep_dataset/ILSVRC2012_val_00006798.bin 224 224 +20675 ./prep_dataset/ILSVRC2012_val_00037181.bin 224 224 +20676 ./prep_dataset/ILSVRC2012_val_00019526.bin 224 224 +20677 ./prep_dataset/ILSVRC2012_val_00039280.bin 224 224 +20678 ./prep_dataset/ILSVRC2012_val_00013175.bin 224 224 +20679 ./prep_dataset/ILSVRC2012_val_00042578.bin 224 224 +20680 ./prep_dataset/ILSVRC2012_val_00000204.bin 224 224 +20681 ./prep_dataset/ILSVRC2012_val_00017031.bin 224 224 +20682 ./prep_dataset/ILSVRC2012_val_00048689.bin 224 224 +20683 ./prep_dataset/ILSVRC2012_val_00032271.bin 224 224 +20684 ./prep_dataset/ILSVRC2012_val_00047129.bin 224 224 +20685 ./prep_dataset/ILSVRC2012_val_00030884.bin 224 224 +20686 ./prep_dataset/ILSVRC2012_val_00035842.bin 224 224 +20687 ./prep_dataset/ILSVRC2012_val_00048280.bin 224 224 +20688 ./prep_dataset/ILSVRC2012_val_00005584.bin 224 224 +20689 ./prep_dataset/ILSVRC2012_val_00040612.bin 224 224 +20690 ./prep_dataset/ILSVRC2012_val_00019132.bin 224 224 +20691 ./prep_dataset/ILSVRC2012_val_00036125.bin 224 224 +20692 ./prep_dataset/ILSVRC2012_val_00002752.bin 224 224 +20693 ./prep_dataset/ILSVRC2012_val_00005813.bin 224 224 +20694 ./prep_dataset/ILSVRC2012_val_00041625.bin 224 224 +20695 ./prep_dataset/ILSVRC2012_val_00045698.bin 224 224 +20696 ./prep_dataset/ILSVRC2012_val_00034301.bin 224 224 +20697 ./prep_dataset/ILSVRC2012_val_00032302.bin 224 224 +20698 ./prep_dataset/ILSVRC2012_val_00015817.bin 224 224 +20699 ./prep_dataset/ILSVRC2012_val_00008834.bin 224 224 +20700 ./prep_dataset/ILSVRC2012_val_00011207.bin 224 224 +20701 ./prep_dataset/ILSVRC2012_val_00041587.bin 224 224 +20702 ./prep_dataset/ILSVRC2012_val_00024980.bin 224 224 +20703 ./prep_dataset/ILSVRC2012_val_00040427.bin 224 224 +20704 ./prep_dataset/ILSVRC2012_val_00039577.bin 224 224 +20705 ./prep_dataset/ILSVRC2012_val_00013975.bin 224 224 +20706 ./prep_dataset/ILSVRC2012_val_00042820.bin 224 224 +20707 ./prep_dataset/ILSVRC2012_val_00001547.bin 224 224 +20708 ./prep_dataset/ILSVRC2012_val_00025438.bin 224 224 +20709 ./prep_dataset/ILSVRC2012_val_00011081.bin 224 224 +20710 ./prep_dataset/ILSVRC2012_val_00018529.bin 224 224 +20711 ./prep_dataset/ILSVRC2012_val_00032463.bin 224 224 +20712 ./prep_dataset/ILSVRC2012_val_00036943.bin 224 224 +20713 ./prep_dataset/ILSVRC2012_val_00047656.bin 224 224 +20714 ./prep_dataset/ILSVRC2012_val_00037402.bin 224 224 +20715 ./prep_dataset/ILSVRC2012_val_00029377.bin 224 224 +20716 ./prep_dataset/ILSVRC2012_val_00012950.bin 224 224 +20717 ./prep_dataset/ILSVRC2012_val_00040842.bin 224 224 +20718 ./prep_dataset/ILSVRC2012_val_00042652.bin 224 224 +20719 ./prep_dataset/ILSVRC2012_val_00046666.bin 224 224 +20720 ./prep_dataset/ILSVRC2012_val_00030865.bin 224 224 +20721 ./prep_dataset/ILSVRC2012_val_00012760.bin 224 224 +20722 ./prep_dataset/ILSVRC2012_val_00020549.bin 224 224 +20723 ./prep_dataset/ILSVRC2012_val_00006776.bin 224 224 +20724 ./prep_dataset/ILSVRC2012_val_00041676.bin 224 224 +20725 ./prep_dataset/ILSVRC2012_val_00033817.bin 224 224 +20726 ./prep_dataset/ILSVRC2012_val_00015010.bin 224 224 +20727 ./prep_dataset/ILSVRC2012_val_00035589.bin 224 224 +20728 ./prep_dataset/ILSVRC2012_val_00044443.bin 224 224 +20729 ./prep_dataset/ILSVRC2012_val_00036484.bin 224 224 +20730 ./prep_dataset/ILSVRC2012_val_00030359.bin 224 224 +20731 ./prep_dataset/ILSVRC2012_val_00032408.bin 224 224 +20732 ./prep_dataset/ILSVRC2012_val_00020812.bin 224 224 +20733 ./prep_dataset/ILSVRC2012_val_00003138.bin 224 224 +20734 ./prep_dataset/ILSVRC2012_val_00004826.bin 224 224 +20735 ./prep_dataset/ILSVRC2012_val_00033291.bin 224 224 +20736 ./prep_dataset/ILSVRC2012_val_00045415.bin 224 224 +20737 ./prep_dataset/ILSVRC2012_val_00008478.bin 224 224 +20738 ./prep_dataset/ILSVRC2012_val_00035877.bin 224 224 +20739 ./prep_dataset/ILSVRC2012_val_00040426.bin 224 224 +20740 ./prep_dataset/ILSVRC2012_val_00004043.bin 224 224 +20741 ./prep_dataset/ILSVRC2012_val_00047745.bin 224 224 +20742 ./prep_dataset/ILSVRC2012_val_00039921.bin 224 224 +20743 ./prep_dataset/ILSVRC2012_val_00011078.bin 224 224 +20744 ./prep_dataset/ILSVRC2012_val_00020098.bin 224 224 +20745 ./prep_dataset/ILSVRC2012_val_00020423.bin 224 224 +20746 ./prep_dataset/ILSVRC2012_val_00020817.bin 224 224 +20747 ./prep_dataset/ILSVRC2012_val_00005329.bin 224 224 +20748 ./prep_dataset/ILSVRC2012_val_00040585.bin 224 224 +20749 ./prep_dataset/ILSVRC2012_val_00039560.bin 224 224 +20750 ./prep_dataset/ILSVRC2012_val_00011462.bin 224 224 +20751 ./prep_dataset/ILSVRC2012_val_00018229.bin 224 224 +20752 ./prep_dataset/ILSVRC2012_val_00000130.bin 224 224 +20753 ./prep_dataset/ILSVRC2012_val_00026645.bin 224 224 +20754 ./prep_dataset/ILSVRC2012_val_00034304.bin 224 224 +20755 ./prep_dataset/ILSVRC2012_val_00038422.bin 224 224 +20756 ./prep_dataset/ILSVRC2012_val_00000390.bin 224 224 +20757 ./prep_dataset/ILSVRC2012_val_00004561.bin 224 224 +20758 ./prep_dataset/ILSVRC2012_val_00006517.bin 224 224 +20759 ./prep_dataset/ILSVRC2012_val_00014359.bin 224 224 +20760 ./prep_dataset/ILSVRC2012_val_00021149.bin 224 224 +20761 ./prep_dataset/ILSVRC2012_val_00037175.bin 224 224 +20762 ./prep_dataset/ILSVRC2012_val_00029810.bin 224 224 +20763 ./prep_dataset/ILSVRC2012_val_00002464.bin 224 224 +20764 ./prep_dataset/ILSVRC2012_val_00004981.bin 224 224 +20765 ./prep_dataset/ILSVRC2012_val_00043887.bin 224 224 +20766 ./prep_dataset/ILSVRC2012_val_00003355.bin 224 224 +20767 ./prep_dataset/ILSVRC2012_val_00026454.bin 224 224 +20768 ./prep_dataset/ILSVRC2012_val_00027729.bin 224 224 +20769 ./prep_dataset/ILSVRC2012_val_00044076.bin 224 224 +20770 ./prep_dataset/ILSVRC2012_val_00034142.bin 224 224 +20771 ./prep_dataset/ILSVRC2012_val_00045962.bin 224 224 +20772 ./prep_dataset/ILSVRC2012_val_00029435.bin 224 224 +20773 ./prep_dataset/ILSVRC2012_val_00017668.bin 224 224 +20774 ./prep_dataset/ILSVRC2012_val_00028082.bin 224 224 +20775 ./prep_dataset/ILSVRC2012_val_00013972.bin 224 224 +20776 ./prep_dataset/ILSVRC2012_val_00038021.bin 224 224 +20777 ./prep_dataset/ILSVRC2012_val_00020199.bin 224 224 +20778 ./prep_dataset/ILSVRC2012_val_00013842.bin 224 224 +20779 ./prep_dataset/ILSVRC2012_val_00005313.bin 224 224 +20780 ./prep_dataset/ILSVRC2012_val_00042156.bin 224 224 +20781 ./prep_dataset/ILSVRC2012_val_00027916.bin 224 224 +20782 ./prep_dataset/ILSVRC2012_val_00030476.bin 224 224 +20783 ./prep_dataset/ILSVRC2012_val_00000243.bin 224 224 +20784 ./prep_dataset/ILSVRC2012_val_00046657.bin 224 224 +20785 ./prep_dataset/ILSVRC2012_val_00048382.bin 224 224 +20786 ./prep_dataset/ILSVRC2012_val_00020765.bin 224 224 +20787 ./prep_dataset/ILSVRC2012_val_00027184.bin 224 224 +20788 ./prep_dataset/ILSVRC2012_val_00033292.bin 224 224 +20789 ./prep_dataset/ILSVRC2012_val_00049394.bin 224 224 +20790 ./prep_dataset/ILSVRC2012_val_00044399.bin 224 224 +20791 ./prep_dataset/ILSVRC2012_val_00011817.bin 224 224 +20792 ./prep_dataset/ILSVRC2012_val_00009143.bin 224 224 +20793 ./prep_dataset/ILSVRC2012_val_00035711.bin 224 224 +20794 ./prep_dataset/ILSVRC2012_val_00032714.bin 224 224 +20795 ./prep_dataset/ILSVRC2012_val_00010264.bin 224 224 +20796 ./prep_dataset/ILSVRC2012_val_00020052.bin 224 224 +20797 ./prep_dataset/ILSVRC2012_val_00047000.bin 224 224 +20798 ./prep_dataset/ILSVRC2012_val_00029740.bin 224 224 +20799 ./prep_dataset/ILSVRC2012_val_00046917.bin 224 224 +20800 ./prep_dataset/ILSVRC2012_val_00045590.bin 224 224 +20801 ./prep_dataset/ILSVRC2012_val_00022879.bin 224 224 +20802 ./prep_dataset/ILSVRC2012_val_00014327.bin 224 224 +20803 ./prep_dataset/ILSVRC2012_val_00022468.bin 224 224 +20804 ./prep_dataset/ILSVRC2012_val_00047380.bin 224 224 +20805 ./prep_dataset/ILSVRC2012_val_00012387.bin 224 224 +20806 ./prep_dataset/ILSVRC2012_val_00043092.bin 224 224 +20807 ./prep_dataset/ILSVRC2012_val_00014378.bin 224 224 +20808 ./prep_dataset/ILSVRC2012_val_00015402.bin 224 224 +20809 ./prep_dataset/ILSVRC2012_val_00008418.bin 224 224 +20810 ./prep_dataset/ILSVRC2012_val_00000108.bin 224 224 +20811 ./prep_dataset/ILSVRC2012_val_00031531.bin 224 224 +20812 ./prep_dataset/ILSVRC2012_val_00004933.bin 224 224 +20813 ./prep_dataset/ILSVRC2012_val_00039682.bin 224 224 +20814 ./prep_dataset/ILSVRC2012_val_00038163.bin 224 224 +20815 ./prep_dataset/ILSVRC2012_val_00037308.bin 224 224 +20816 ./prep_dataset/ILSVRC2012_val_00036389.bin 224 224 +20817 ./prep_dataset/ILSVRC2012_val_00021419.bin 224 224 +20818 ./prep_dataset/ILSVRC2012_val_00040289.bin 224 224 +20819 ./prep_dataset/ILSVRC2012_val_00035937.bin 224 224 +20820 ./prep_dataset/ILSVRC2012_val_00037258.bin 224 224 +20821 ./prep_dataset/ILSVRC2012_val_00015154.bin 224 224 +20822 ./prep_dataset/ILSVRC2012_val_00013544.bin 224 224 +20823 ./prep_dataset/ILSVRC2012_val_00026683.bin 224 224 +20824 ./prep_dataset/ILSVRC2012_val_00043388.bin 224 224 +20825 ./prep_dataset/ILSVRC2012_val_00030681.bin 224 224 +20826 ./prep_dataset/ILSVRC2012_val_00032698.bin 224 224 +20827 ./prep_dataset/ILSVRC2012_val_00027503.bin 224 224 +20828 ./prep_dataset/ILSVRC2012_val_00004763.bin 224 224 +20829 ./prep_dataset/ILSVRC2012_val_00048858.bin 224 224 +20830 ./prep_dataset/ILSVRC2012_val_00010195.bin 224 224 +20831 ./prep_dataset/ILSVRC2012_val_00041230.bin 224 224 +20832 ./prep_dataset/ILSVRC2012_val_00037620.bin 224 224 +20833 ./prep_dataset/ILSVRC2012_val_00001690.bin 224 224 +20834 ./prep_dataset/ILSVRC2012_val_00000574.bin 224 224 +20835 ./prep_dataset/ILSVRC2012_val_00017801.bin 224 224 +20836 ./prep_dataset/ILSVRC2012_val_00000623.bin 224 224 +20837 ./prep_dataset/ILSVRC2012_val_00025365.bin 224 224 +20838 ./prep_dataset/ILSVRC2012_val_00039750.bin 224 224 +20839 ./prep_dataset/ILSVRC2012_val_00039615.bin 224 224 +20840 ./prep_dataset/ILSVRC2012_val_00045334.bin 224 224 +20841 ./prep_dataset/ILSVRC2012_val_00016190.bin 224 224 +20842 ./prep_dataset/ILSVRC2012_val_00020265.bin 224 224 +20843 ./prep_dataset/ILSVRC2012_val_00048281.bin 224 224 +20844 ./prep_dataset/ILSVRC2012_val_00028916.bin 224 224 +20845 ./prep_dataset/ILSVRC2012_val_00033476.bin 224 224 +20846 ./prep_dataset/ILSVRC2012_val_00042742.bin 224 224 +20847 ./prep_dataset/ILSVRC2012_val_00038888.bin 224 224 +20848 ./prep_dataset/ILSVRC2012_val_00014645.bin 224 224 +20849 ./prep_dataset/ILSVRC2012_val_00000363.bin 224 224 +20850 ./prep_dataset/ILSVRC2012_val_00034713.bin 224 224 +20851 ./prep_dataset/ILSVRC2012_val_00028723.bin 224 224 +20852 ./prep_dataset/ILSVRC2012_val_00028062.bin 224 224 +20853 ./prep_dataset/ILSVRC2012_val_00007960.bin 224 224 +20854 ./prep_dataset/ILSVRC2012_val_00000813.bin 224 224 +20855 ./prep_dataset/ILSVRC2012_val_00041058.bin 224 224 +20856 ./prep_dataset/ILSVRC2012_val_00045195.bin 224 224 +20857 ./prep_dataset/ILSVRC2012_val_00004919.bin 224 224 +20858 ./prep_dataset/ILSVRC2012_val_00005908.bin 224 224 +20859 ./prep_dataset/ILSVRC2012_val_00006025.bin 224 224 +20860 ./prep_dataset/ILSVRC2012_val_00016819.bin 224 224 +20861 ./prep_dataset/ILSVRC2012_val_00027697.bin 224 224 +20862 ./prep_dataset/ILSVRC2012_val_00007383.bin 224 224 +20863 ./prep_dataset/ILSVRC2012_val_00044207.bin 224 224 +20864 ./prep_dataset/ILSVRC2012_val_00013782.bin 224 224 +20865 ./prep_dataset/ILSVRC2012_val_00033859.bin 224 224 +20866 ./prep_dataset/ILSVRC2012_val_00021420.bin 224 224 +20867 ./prep_dataset/ILSVRC2012_val_00049757.bin 224 224 +20868 ./prep_dataset/ILSVRC2012_val_00013288.bin 224 224 +20869 ./prep_dataset/ILSVRC2012_val_00044744.bin 224 224 +20870 ./prep_dataset/ILSVRC2012_val_00038901.bin 224 224 +20871 ./prep_dataset/ILSVRC2012_val_00012431.bin 224 224 +20872 ./prep_dataset/ILSVRC2012_val_00015226.bin 224 224 +20873 ./prep_dataset/ILSVRC2012_val_00028785.bin 224 224 +20874 ./prep_dataset/ILSVRC2012_val_00049720.bin 224 224 +20875 ./prep_dataset/ILSVRC2012_val_00009183.bin 224 224 +20876 ./prep_dataset/ILSVRC2012_val_00016297.bin 224 224 +20877 ./prep_dataset/ILSVRC2012_val_00020876.bin 224 224 +20878 ./prep_dataset/ILSVRC2012_val_00026959.bin 224 224 +20879 ./prep_dataset/ILSVRC2012_val_00012592.bin 224 224 +20880 ./prep_dataset/ILSVRC2012_val_00013461.bin 224 224 +20881 ./prep_dataset/ILSVRC2012_val_00025081.bin 224 224 +20882 ./prep_dataset/ILSVRC2012_val_00014227.bin 224 224 +20883 ./prep_dataset/ILSVRC2012_val_00038783.bin 224 224 +20884 ./prep_dataset/ILSVRC2012_val_00000594.bin 224 224 +20885 ./prep_dataset/ILSVRC2012_val_00018226.bin 224 224 +20886 ./prep_dataset/ILSVRC2012_val_00009140.bin 224 224 +20887 ./prep_dataset/ILSVRC2012_val_00029330.bin 224 224 +20888 ./prep_dataset/ILSVRC2012_val_00010356.bin 224 224 +20889 ./prep_dataset/ILSVRC2012_val_00005610.bin 224 224 +20890 ./prep_dataset/ILSVRC2012_val_00012265.bin 224 224 +20891 ./prep_dataset/ILSVRC2012_val_00034640.bin 224 224 +20892 ./prep_dataset/ILSVRC2012_val_00037863.bin 224 224 +20893 ./prep_dataset/ILSVRC2012_val_00047957.bin 224 224 +20894 ./prep_dataset/ILSVRC2012_val_00021841.bin 224 224 +20895 ./prep_dataset/ILSVRC2012_val_00029789.bin 224 224 +20896 ./prep_dataset/ILSVRC2012_val_00043196.bin 224 224 +20897 ./prep_dataset/ILSVRC2012_val_00031504.bin 224 224 +20898 ./prep_dataset/ILSVRC2012_val_00037767.bin 224 224 +20899 ./prep_dataset/ILSVRC2012_val_00004737.bin 224 224 +20900 ./prep_dataset/ILSVRC2012_val_00016407.bin 224 224 +20901 ./prep_dataset/ILSVRC2012_val_00027597.bin 224 224 +20902 ./prep_dataset/ILSVRC2012_val_00018897.bin 224 224 +20903 ./prep_dataset/ILSVRC2012_val_00007881.bin 224 224 +20904 ./prep_dataset/ILSVRC2012_val_00005003.bin 224 224 +20905 ./prep_dataset/ILSVRC2012_val_00027673.bin 224 224 +20906 ./prep_dataset/ILSVRC2012_val_00008362.bin 224 224 +20907 ./prep_dataset/ILSVRC2012_val_00048828.bin 224 224 +20908 ./prep_dataset/ILSVRC2012_val_00005944.bin 224 224 +20909 ./prep_dataset/ILSVRC2012_val_00038943.bin 224 224 +20910 ./prep_dataset/ILSVRC2012_val_00024065.bin 224 224 +20911 ./prep_dataset/ILSVRC2012_val_00028494.bin 224 224 +20912 ./prep_dataset/ILSVRC2012_val_00015747.bin 224 224 +20913 ./prep_dataset/ILSVRC2012_val_00018458.bin 224 224 +20914 ./prep_dataset/ILSVRC2012_val_00048067.bin 224 224 +20915 ./prep_dataset/ILSVRC2012_val_00047009.bin 224 224 +20916 ./prep_dataset/ILSVRC2012_val_00025884.bin 224 224 +20917 ./prep_dataset/ILSVRC2012_val_00028365.bin 224 224 +20918 ./prep_dataset/ILSVRC2012_val_00035073.bin 224 224 +20919 ./prep_dataset/ILSVRC2012_val_00008124.bin 224 224 +20920 ./prep_dataset/ILSVRC2012_val_00027447.bin 224 224 +20921 ./prep_dataset/ILSVRC2012_val_00023023.bin 224 224 +20922 ./prep_dataset/ILSVRC2012_val_00015336.bin 224 224 +20923 ./prep_dataset/ILSVRC2012_val_00015232.bin 224 224 +20924 ./prep_dataset/ILSVRC2012_val_00045042.bin 224 224 +20925 ./prep_dataset/ILSVRC2012_val_00011259.bin 224 224 +20926 ./prep_dataset/ILSVRC2012_val_00007551.bin 224 224 +20927 ./prep_dataset/ILSVRC2012_val_00042878.bin 224 224 +20928 ./prep_dataset/ILSVRC2012_val_00024758.bin 224 224 +20929 ./prep_dataset/ILSVRC2012_val_00042248.bin 224 224 +20930 ./prep_dataset/ILSVRC2012_val_00032784.bin 224 224 +20931 ./prep_dataset/ILSVRC2012_val_00031074.bin 224 224 +20932 ./prep_dataset/ILSVRC2012_val_00041403.bin 224 224 +20933 ./prep_dataset/ILSVRC2012_val_00040826.bin 224 224 +20934 ./prep_dataset/ILSVRC2012_val_00029167.bin 224 224 +20935 ./prep_dataset/ILSVRC2012_val_00007309.bin 224 224 +20936 ./prep_dataset/ILSVRC2012_val_00040094.bin 224 224 +20937 ./prep_dataset/ILSVRC2012_val_00005781.bin 224 224 +20938 ./prep_dataset/ILSVRC2012_val_00040718.bin 224 224 +20939 ./prep_dataset/ILSVRC2012_val_00022565.bin 224 224 +20940 ./prep_dataset/ILSVRC2012_val_00019355.bin 224 224 +20941 ./prep_dataset/ILSVRC2012_val_00045489.bin 224 224 +20942 ./prep_dataset/ILSVRC2012_val_00016810.bin 224 224 +20943 ./prep_dataset/ILSVRC2012_val_00016076.bin 224 224 +20944 ./prep_dataset/ILSVRC2012_val_00006464.bin 224 224 +20945 ./prep_dataset/ILSVRC2012_val_00043938.bin 224 224 +20946 ./prep_dataset/ILSVRC2012_val_00045095.bin 224 224 +20947 ./prep_dataset/ILSVRC2012_val_00040016.bin 224 224 +20948 ./prep_dataset/ILSVRC2012_val_00013460.bin 224 224 +20949 ./prep_dataset/ILSVRC2012_val_00011134.bin 224 224 +20950 ./prep_dataset/ILSVRC2012_val_00020104.bin 224 224 +20951 ./prep_dataset/ILSVRC2012_val_00015761.bin 224 224 +20952 ./prep_dataset/ILSVRC2012_val_00024286.bin 224 224 +20953 ./prep_dataset/ILSVRC2012_val_00044358.bin 224 224 +20954 ./prep_dataset/ILSVRC2012_val_00044018.bin 224 224 +20955 ./prep_dataset/ILSVRC2012_val_00013744.bin 224 224 +20956 ./prep_dataset/ILSVRC2012_val_00022544.bin 224 224 +20957 ./prep_dataset/ILSVRC2012_val_00037803.bin 224 224 +20958 ./prep_dataset/ILSVRC2012_val_00026057.bin 224 224 +20959 ./prep_dataset/ILSVRC2012_val_00046090.bin 224 224 +20960 ./prep_dataset/ILSVRC2012_val_00049726.bin 224 224 +20961 ./prep_dataset/ILSVRC2012_val_00008902.bin 224 224 +20962 ./prep_dataset/ILSVRC2012_val_00046676.bin 224 224 +20963 ./prep_dataset/ILSVRC2012_val_00047636.bin 224 224 +20964 ./prep_dataset/ILSVRC2012_val_00018955.bin 224 224 +20965 ./prep_dataset/ILSVRC2012_val_00011485.bin 224 224 +20966 ./prep_dataset/ILSVRC2012_val_00021499.bin 224 224 +20967 ./prep_dataset/ILSVRC2012_val_00010938.bin 224 224 +20968 ./prep_dataset/ILSVRC2012_val_00034851.bin 224 224 +20969 ./prep_dataset/ILSVRC2012_val_00019341.bin 224 224 +20970 ./prep_dataset/ILSVRC2012_val_00018164.bin 224 224 +20971 ./prep_dataset/ILSVRC2012_val_00036217.bin 224 224 +20972 ./prep_dataset/ILSVRC2012_val_00023010.bin 224 224 +20973 ./prep_dataset/ILSVRC2012_val_00048318.bin 224 224 +20974 ./prep_dataset/ILSVRC2012_val_00038427.bin 224 224 +20975 ./prep_dataset/ILSVRC2012_val_00024435.bin 224 224 +20976 ./prep_dataset/ILSVRC2012_val_00021500.bin 224 224 +20977 ./prep_dataset/ILSVRC2012_val_00024099.bin 224 224 +20978 ./prep_dataset/ILSVRC2012_val_00018601.bin 224 224 +20979 ./prep_dataset/ILSVRC2012_val_00040050.bin 224 224 +20980 ./prep_dataset/ILSVRC2012_val_00023469.bin 224 224 +20981 ./prep_dataset/ILSVRC2012_val_00002396.bin 224 224 +20982 ./prep_dataset/ILSVRC2012_val_00045805.bin 224 224 +20983 ./prep_dataset/ILSVRC2012_val_00032404.bin 224 224 +20984 ./prep_dataset/ILSVRC2012_val_00022466.bin 224 224 +20985 ./prep_dataset/ILSVRC2012_val_00033369.bin 224 224 +20986 ./prep_dataset/ILSVRC2012_val_00028899.bin 224 224 +20987 ./prep_dataset/ILSVRC2012_val_00005535.bin 224 224 +20988 ./prep_dataset/ILSVRC2012_val_00007134.bin 224 224 +20989 ./prep_dataset/ILSVRC2012_val_00010992.bin 224 224 +20990 ./prep_dataset/ILSVRC2012_val_00037346.bin 224 224 +20991 ./prep_dataset/ILSVRC2012_val_00008081.bin 224 224 +20992 ./prep_dataset/ILSVRC2012_val_00020371.bin 224 224 +20993 ./prep_dataset/ILSVRC2012_val_00008909.bin 224 224 +20994 ./prep_dataset/ILSVRC2012_val_00031934.bin 224 224 +20995 ./prep_dataset/ILSVRC2012_val_00001215.bin 224 224 +20996 ./prep_dataset/ILSVRC2012_val_00025831.bin 224 224 +20997 ./prep_dataset/ILSVRC2012_val_00030301.bin 224 224 +20998 ./prep_dataset/ILSVRC2012_val_00008455.bin 224 224 +20999 ./prep_dataset/ILSVRC2012_val_00027048.bin 224 224 +21000 ./prep_dataset/ILSVRC2012_val_00027353.bin 224 224 +21001 ./prep_dataset/ILSVRC2012_val_00038903.bin 224 224 +21002 ./prep_dataset/ILSVRC2012_val_00027518.bin 224 224 +21003 ./prep_dataset/ILSVRC2012_val_00014462.bin 224 224 +21004 ./prep_dataset/ILSVRC2012_val_00042746.bin 224 224 +21005 ./prep_dataset/ILSVRC2012_val_00034131.bin 224 224 +21006 ./prep_dataset/ILSVRC2012_val_00014787.bin 224 224 +21007 ./prep_dataset/ILSVRC2012_val_00018574.bin 224 224 +21008 ./prep_dataset/ILSVRC2012_val_00021732.bin 224 224 +21009 ./prep_dataset/ILSVRC2012_val_00022619.bin 224 224 +21010 ./prep_dataset/ILSVRC2012_val_00042998.bin 224 224 +21011 ./prep_dataset/ILSVRC2012_val_00000393.bin 224 224 +21012 ./prep_dataset/ILSVRC2012_val_00049342.bin 224 224 +21013 ./prep_dataset/ILSVRC2012_val_00048554.bin 224 224 +21014 ./prep_dataset/ILSVRC2012_val_00043498.bin 224 224 +21015 ./prep_dataset/ILSVRC2012_val_00035657.bin 224 224 +21016 ./prep_dataset/ILSVRC2012_val_00038575.bin 224 224 +21017 ./prep_dataset/ILSVRC2012_val_00038003.bin 224 224 +21018 ./prep_dataset/ILSVRC2012_val_00036750.bin 224 224 +21019 ./prep_dataset/ILSVRC2012_val_00038811.bin 224 224 +21020 ./prep_dataset/ILSVRC2012_val_00029127.bin 224 224 +21021 ./prep_dataset/ILSVRC2012_val_00007023.bin 224 224 +21022 ./prep_dataset/ILSVRC2012_val_00008861.bin 224 224 +21023 ./prep_dataset/ILSVRC2012_val_00005776.bin 224 224 +21024 ./prep_dataset/ILSVRC2012_val_00007455.bin 224 224 +21025 ./prep_dataset/ILSVRC2012_val_00019961.bin 224 224 +21026 ./prep_dataset/ILSVRC2012_val_00037042.bin 224 224 +21027 ./prep_dataset/ILSVRC2012_val_00022358.bin 224 224 +21028 ./prep_dataset/ILSVRC2012_val_00015090.bin 224 224 +21029 ./prep_dataset/ILSVRC2012_val_00030569.bin 224 224 +21030 ./prep_dataset/ILSVRC2012_val_00004288.bin 224 224 +21031 ./prep_dataset/ILSVRC2012_val_00003954.bin 224 224 +21032 ./prep_dataset/ILSVRC2012_val_00017742.bin 224 224 +21033 ./prep_dataset/ILSVRC2012_val_00039074.bin 224 224 +21034 ./prep_dataset/ILSVRC2012_val_00024352.bin 224 224 +21035 ./prep_dataset/ILSVRC2012_val_00039328.bin 224 224 +21036 ./prep_dataset/ILSVRC2012_val_00028229.bin 224 224 +21037 ./prep_dataset/ILSVRC2012_val_00003094.bin 224 224 +21038 ./prep_dataset/ILSVRC2012_val_00004851.bin 224 224 +21039 ./prep_dataset/ILSVRC2012_val_00015678.bin 224 224 +21040 ./prep_dataset/ILSVRC2012_val_00047598.bin 224 224 +21041 ./prep_dataset/ILSVRC2012_val_00003171.bin 224 224 +21042 ./prep_dataset/ILSVRC2012_val_00037232.bin 224 224 +21043 ./prep_dataset/ILSVRC2012_val_00042544.bin 224 224 +21044 ./prep_dataset/ILSVRC2012_val_00023929.bin 224 224 +21045 ./prep_dataset/ILSVRC2012_val_00044423.bin 224 224 +21046 ./prep_dataset/ILSVRC2012_val_00037675.bin 224 224 +21047 ./prep_dataset/ILSVRC2012_val_00038762.bin 224 224 +21048 ./prep_dataset/ILSVRC2012_val_00044774.bin 224 224 +21049 ./prep_dataset/ILSVRC2012_val_00039933.bin 224 224 +21050 ./prep_dataset/ILSVRC2012_val_00049925.bin 224 224 +21051 ./prep_dataset/ILSVRC2012_val_00019704.bin 224 224 +21052 ./prep_dataset/ILSVRC2012_val_00009075.bin 224 224 +21053 ./prep_dataset/ILSVRC2012_val_00044754.bin 224 224 +21054 ./prep_dataset/ILSVRC2012_val_00007659.bin 224 224 +21055 ./prep_dataset/ILSVRC2012_val_00035215.bin 224 224 +21056 ./prep_dataset/ILSVRC2012_val_00016447.bin 224 224 +21057 ./prep_dataset/ILSVRC2012_val_00006337.bin 224 224 +21058 ./prep_dataset/ILSVRC2012_val_00026635.bin 224 224 +21059 ./prep_dataset/ILSVRC2012_val_00047274.bin 224 224 +21060 ./prep_dataset/ILSVRC2012_val_00031537.bin 224 224 +21061 ./prep_dataset/ILSVRC2012_val_00011595.bin 224 224 +21062 ./prep_dataset/ILSVRC2012_val_00021320.bin 224 224 +21063 ./prep_dataset/ILSVRC2012_val_00043822.bin 224 224 +21064 ./prep_dataset/ILSVRC2012_val_00035481.bin 224 224 +21065 ./prep_dataset/ILSVRC2012_val_00006891.bin 224 224 +21066 ./prep_dataset/ILSVRC2012_val_00036760.bin 224 224 +21067 ./prep_dataset/ILSVRC2012_val_00008061.bin 224 224 +21068 ./prep_dataset/ILSVRC2012_val_00048245.bin 224 224 +21069 ./prep_dataset/ILSVRC2012_val_00009167.bin 224 224 +21070 ./prep_dataset/ILSVRC2012_val_00026037.bin 224 224 +21071 ./prep_dataset/ILSVRC2012_val_00025697.bin 224 224 +21072 ./prep_dataset/ILSVRC2012_val_00026261.bin 224 224 +21073 ./prep_dataset/ILSVRC2012_val_00015040.bin 224 224 +21074 ./prep_dataset/ILSVRC2012_val_00041203.bin 224 224 +21075 ./prep_dataset/ILSVRC2012_val_00015339.bin 224 224 +21076 ./prep_dataset/ILSVRC2012_val_00031717.bin 224 224 +21077 ./prep_dataset/ILSVRC2012_val_00030545.bin 224 224 +21078 ./prep_dataset/ILSVRC2012_val_00032218.bin 224 224 +21079 ./prep_dataset/ILSVRC2012_val_00008401.bin 224 224 +21080 ./prep_dataset/ILSVRC2012_val_00033750.bin 224 224 +21081 ./prep_dataset/ILSVRC2012_val_00026758.bin 224 224 +21082 ./prep_dataset/ILSVRC2012_val_00024566.bin 224 224 +21083 ./prep_dataset/ILSVRC2012_val_00006495.bin 224 224 +21084 ./prep_dataset/ILSVRC2012_val_00032485.bin 224 224 +21085 ./prep_dataset/ILSVRC2012_val_00036002.bin 224 224 +21086 ./prep_dataset/ILSVRC2012_val_00029554.bin 224 224 +21087 ./prep_dataset/ILSVRC2012_val_00014235.bin 224 224 +21088 ./prep_dataset/ILSVRC2012_val_00023622.bin 224 224 +21089 ./prep_dataset/ILSVRC2012_val_00010443.bin 224 224 +21090 ./prep_dataset/ILSVRC2012_val_00039166.bin 224 224 +21091 ./prep_dataset/ILSVRC2012_val_00047076.bin 224 224 +21092 ./prep_dataset/ILSVRC2012_val_00032626.bin 224 224 +21093 ./prep_dataset/ILSVRC2012_val_00029336.bin 224 224 +21094 ./prep_dataset/ILSVRC2012_val_00042537.bin 224 224 +21095 ./prep_dataset/ILSVRC2012_val_00042240.bin 224 224 +21096 ./prep_dataset/ILSVRC2012_val_00026232.bin 224 224 +21097 ./prep_dataset/ILSVRC2012_val_00007414.bin 224 224 +21098 ./prep_dataset/ILSVRC2012_val_00034237.bin 224 224 +21099 ./prep_dataset/ILSVRC2012_val_00027765.bin 224 224 +21100 ./prep_dataset/ILSVRC2012_val_00031824.bin 224 224 +21101 ./prep_dataset/ILSVRC2012_val_00011040.bin 224 224 +21102 ./prep_dataset/ILSVRC2012_val_00027695.bin 224 224 +21103 ./prep_dataset/ILSVRC2012_val_00024512.bin 224 224 +21104 ./prep_dataset/ILSVRC2012_val_00030704.bin 224 224 +21105 ./prep_dataset/ILSVRC2012_val_00047762.bin 224 224 +21106 ./prep_dataset/ILSVRC2012_val_00017016.bin 224 224 +21107 ./prep_dataset/ILSVRC2012_val_00035554.bin 224 224 +21108 ./prep_dataset/ILSVRC2012_val_00039165.bin 224 224 +21109 ./prep_dataset/ILSVRC2012_val_00010891.bin 224 224 +21110 ./prep_dataset/ILSVRC2012_val_00044868.bin 224 224 +21111 ./prep_dataset/ILSVRC2012_val_00010259.bin 224 224 +21112 ./prep_dataset/ILSVRC2012_val_00032284.bin 224 224 +21113 ./prep_dataset/ILSVRC2012_val_00026105.bin 224 224 +21114 ./prep_dataset/ILSVRC2012_val_00026075.bin 224 224 +21115 ./prep_dataset/ILSVRC2012_val_00008156.bin 224 224 +21116 ./prep_dataset/ILSVRC2012_val_00012489.bin 224 224 +21117 ./prep_dataset/ILSVRC2012_val_00023767.bin 224 224 +21118 ./prep_dataset/ILSVRC2012_val_00006338.bin 224 224 +21119 ./prep_dataset/ILSVRC2012_val_00034709.bin 224 224 +21120 ./prep_dataset/ILSVRC2012_val_00034772.bin 224 224 +21121 ./prep_dataset/ILSVRC2012_val_00038627.bin 224 224 +21122 ./prep_dataset/ILSVRC2012_val_00048505.bin 224 224 +21123 ./prep_dataset/ILSVRC2012_val_00029069.bin 224 224 +21124 ./prep_dataset/ILSVRC2012_val_00021551.bin 224 224 +21125 ./prep_dataset/ILSVRC2012_val_00002094.bin 224 224 +21126 ./prep_dataset/ILSVRC2012_val_00017081.bin 224 224 +21127 ./prep_dataset/ILSVRC2012_val_00025208.bin 224 224 +21128 ./prep_dataset/ILSVRC2012_val_00034682.bin 224 224 +21129 ./prep_dataset/ILSVRC2012_val_00043091.bin 224 224 +21130 ./prep_dataset/ILSVRC2012_val_00048212.bin 224 224 +21131 ./prep_dataset/ILSVRC2012_val_00010075.bin 224 224 +21132 ./prep_dataset/ILSVRC2012_val_00035816.bin 224 224 +21133 ./prep_dataset/ILSVRC2012_val_00046232.bin 224 224 +21134 ./prep_dataset/ILSVRC2012_val_00035464.bin 224 224 +21135 ./prep_dataset/ILSVRC2012_val_00006503.bin 224 224 +21136 ./prep_dataset/ILSVRC2012_val_00024290.bin 224 224 +21137 ./prep_dataset/ILSVRC2012_val_00041606.bin 224 224 +21138 ./prep_dataset/ILSVRC2012_val_00018190.bin 224 224 +21139 ./prep_dataset/ILSVRC2012_val_00024343.bin 224 224 +21140 ./prep_dataset/ILSVRC2012_val_00039514.bin 224 224 +21141 ./prep_dataset/ILSVRC2012_val_00013297.bin 224 224 +21142 ./prep_dataset/ILSVRC2012_val_00031804.bin 224 224 +21143 ./prep_dataset/ILSVRC2012_val_00034546.bin 224 224 +21144 ./prep_dataset/ILSVRC2012_val_00028620.bin 224 224 +21145 ./prep_dataset/ILSVRC2012_val_00013781.bin 224 224 +21146 ./prep_dataset/ILSVRC2012_val_00017695.bin 224 224 +21147 ./prep_dataset/ILSVRC2012_val_00041288.bin 224 224 +21148 ./prep_dataset/ILSVRC2012_val_00044260.bin 224 224 +21149 ./prep_dataset/ILSVRC2012_val_00031371.bin 224 224 +21150 ./prep_dataset/ILSVRC2012_val_00031850.bin 224 224 +21151 ./prep_dataset/ILSVRC2012_val_00044189.bin 224 224 +21152 ./prep_dataset/ILSVRC2012_val_00038144.bin 224 224 +21153 ./prep_dataset/ILSVRC2012_val_00031219.bin 224 224 +21154 ./prep_dataset/ILSVRC2012_val_00000324.bin 224 224 +21155 ./prep_dataset/ILSVRC2012_val_00014045.bin 224 224 +21156 ./prep_dataset/ILSVRC2012_val_00005759.bin 224 224 +21157 ./prep_dataset/ILSVRC2012_val_00031377.bin 224 224 +21158 ./prep_dataset/ILSVRC2012_val_00003450.bin 224 224 +21159 ./prep_dataset/ILSVRC2012_val_00046692.bin 224 224 +21160 ./prep_dataset/ILSVRC2012_val_00017798.bin 224 224 +21161 ./prep_dataset/ILSVRC2012_val_00014825.bin 224 224 +21162 ./prep_dataset/ILSVRC2012_val_00009641.bin 224 224 +21163 ./prep_dataset/ILSVRC2012_val_00039112.bin 224 224 +21164 ./prep_dataset/ILSVRC2012_val_00003617.bin 224 224 +21165 ./prep_dataset/ILSVRC2012_val_00025386.bin 224 224 +21166 ./prep_dataset/ILSVRC2012_val_00042438.bin 224 224 +21167 ./prep_dataset/ILSVRC2012_val_00030603.bin 224 224 +21168 ./prep_dataset/ILSVRC2012_val_00026210.bin 224 224 +21169 ./prep_dataset/ILSVRC2012_val_00007216.bin 224 224 +21170 ./prep_dataset/ILSVRC2012_val_00027787.bin 224 224 +21171 ./prep_dataset/ILSVRC2012_val_00027489.bin 224 224 +21172 ./prep_dataset/ILSVRC2012_val_00028355.bin 224 224 +21173 ./prep_dataset/ILSVRC2012_val_00031783.bin 224 224 +21174 ./prep_dataset/ILSVRC2012_val_00049400.bin 224 224 +21175 ./prep_dataset/ILSVRC2012_val_00037765.bin 224 224 +21176 ./prep_dataset/ILSVRC2012_val_00046894.bin 224 224 +21177 ./prep_dataset/ILSVRC2012_val_00010076.bin 224 224 +21178 ./prep_dataset/ILSVRC2012_val_00011153.bin 224 224 +21179 ./prep_dataset/ILSVRC2012_val_00018000.bin 224 224 +21180 ./prep_dataset/ILSVRC2012_val_00008146.bin 224 224 +21181 ./prep_dataset/ILSVRC2012_val_00043123.bin 224 224 +21182 ./prep_dataset/ILSVRC2012_val_00006198.bin 224 224 +21183 ./prep_dataset/ILSVRC2012_val_00042093.bin 224 224 +21184 ./prep_dataset/ILSVRC2012_val_00031979.bin 224 224 +21185 ./prep_dataset/ILSVRC2012_val_00033851.bin 224 224 +21186 ./prep_dataset/ILSVRC2012_val_00016859.bin 224 224 +21187 ./prep_dataset/ILSVRC2012_val_00024511.bin 224 224 +21188 ./prep_dataset/ILSVRC2012_val_00027412.bin 224 224 +21189 ./prep_dataset/ILSVRC2012_val_00030667.bin 224 224 +21190 ./prep_dataset/ILSVRC2012_val_00046145.bin 224 224 +21191 ./prep_dataset/ILSVRC2012_val_00035958.bin 224 224 +21192 ./prep_dataset/ILSVRC2012_val_00044005.bin 224 224 +21193 ./prep_dataset/ILSVRC2012_val_00025266.bin 224 224 +21194 ./prep_dataset/ILSVRC2012_val_00011102.bin 224 224 +21195 ./prep_dataset/ILSVRC2012_val_00006125.bin 224 224 +21196 ./prep_dataset/ILSVRC2012_val_00022498.bin 224 224 +21197 ./prep_dataset/ILSVRC2012_val_00009526.bin 224 224 +21198 ./prep_dataset/ILSVRC2012_val_00008602.bin 224 224 +21199 ./prep_dataset/ILSVRC2012_val_00000129.bin 224 224 +21200 ./prep_dataset/ILSVRC2012_val_00006684.bin 224 224 +21201 ./prep_dataset/ILSVRC2012_val_00041820.bin 224 224 +21202 ./prep_dataset/ILSVRC2012_val_00002065.bin 224 224 +21203 ./prep_dataset/ILSVRC2012_val_00023195.bin 224 224 +21204 ./prep_dataset/ILSVRC2012_val_00034452.bin 224 224 +21205 ./prep_dataset/ILSVRC2012_val_00008403.bin 224 224 +21206 ./prep_dataset/ILSVRC2012_val_00039408.bin 224 224 +21207 ./prep_dataset/ILSVRC2012_val_00005368.bin 224 224 +21208 ./prep_dataset/ILSVRC2012_val_00044605.bin 224 224 +21209 ./prep_dataset/ILSVRC2012_val_00000385.bin 224 224 +21210 ./prep_dataset/ILSVRC2012_val_00025565.bin 224 224 +21211 ./prep_dataset/ILSVRC2012_val_00033871.bin 224 224 +21212 ./prep_dataset/ILSVRC2012_val_00017086.bin 224 224 +21213 ./prep_dataset/ILSVRC2012_val_00036091.bin 224 224 +21214 ./prep_dataset/ILSVRC2012_val_00022824.bin 224 224 +21215 ./prep_dataset/ILSVRC2012_val_00032541.bin 224 224 +21216 ./prep_dataset/ILSVRC2012_val_00003929.bin 224 224 +21217 ./prep_dataset/ILSVRC2012_val_00029787.bin 224 224 +21218 ./prep_dataset/ILSVRC2012_val_00037673.bin 224 224 +21219 ./prep_dataset/ILSVRC2012_val_00047989.bin 224 224 +21220 ./prep_dataset/ILSVRC2012_val_00038551.bin 224 224 +21221 ./prep_dataset/ILSVRC2012_val_00040267.bin 224 224 +21222 ./prep_dataset/ILSVRC2012_val_00014292.bin 224 224 +21223 ./prep_dataset/ILSVRC2012_val_00026621.bin 224 224 +21224 ./prep_dataset/ILSVRC2012_val_00047621.bin 224 224 +21225 ./prep_dataset/ILSVRC2012_val_00036526.bin 224 224 +21226 ./prep_dataset/ILSVRC2012_val_00000072.bin 224 224 +21227 ./prep_dataset/ILSVRC2012_val_00025465.bin 224 224 +21228 ./prep_dataset/ILSVRC2012_val_00003267.bin 224 224 +21229 ./prep_dataset/ILSVRC2012_val_00037011.bin 224 224 +21230 ./prep_dataset/ILSVRC2012_val_00021572.bin 224 224 +21231 ./prep_dataset/ILSVRC2012_val_00017223.bin 224 224 +21232 ./prep_dataset/ILSVRC2012_val_00035075.bin 224 224 +21233 ./prep_dataset/ILSVRC2012_val_00041290.bin 224 224 +21234 ./prep_dataset/ILSVRC2012_val_00026072.bin 224 224 +21235 ./prep_dataset/ILSVRC2012_val_00030378.bin 224 224 +21236 ./prep_dataset/ILSVRC2012_val_00049755.bin 224 224 +21237 ./prep_dataset/ILSVRC2012_val_00037223.bin 224 224 +21238 ./prep_dataset/ILSVRC2012_val_00038778.bin 224 224 +21239 ./prep_dataset/ILSVRC2012_val_00037464.bin 224 224 +21240 ./prep_dataset/ILSVRC2012_val_00003290.bin 224 224 +21241 ./prep_dataset/ILSVRC2012_val_00037992.bin 224 224 +21242 ./prep_dataset/ILSVRC2012_val_00024723.bin 224 224 +21243 ./prep_dataset/ILSVRC2012_val_00026294.bin 224 224 +21244 ./prep_dataset/ILSVRC2012_val_00006643.bin 224 224 +21245 ./prep_dataset/ILSVRC2012_val_00027389.bin 224 224 +21246 ./prep_dataset/ILSVRC2012_val_00021400.bin 224 224 +21247 ./prep_dataset/ILSVRC2012_val_00008320.bin 224 224 +21248 ./prep_dataset/ILSVRC2012_val_00017688.bin 224 224 +21249 ./prep_dataset/ILSVRC2012_val_00019710.bin 224 224 +21250 ./prep_dataset/ILSVRC2012_val_00009563.bin 224 224 +21251 ./prep_dataset/ILSVRC2012_val_00043838.bin 224 224 +21252 ./prep_dataset/ILSVRC2012_val_00045277.bin 224 224 +21253 ./prep_dataset/ILSVRC2012_val_00025781.bin 224 224 +21254 ./prep_dataset/ILSVRC2012_val_00035739.bin 224 224 +21255 ./prep_dataset/ILSVRC2012_val_00041953.bin 224 224 +21256 ./prep_dataset/ILSVRC2012_val_00025213.bin 224 224 +21257 ./prep_dataset/ILSVRC2012_val_00032563.bin 224 224 +21258 ./prep_dataset/ILSVRC2012_val_00023172.bin 224 224 +21259 ./prep_dataset/ILSVRC2012_val_00037511.bin 224 224 +21260 ./prep_dataset/ILSVRC2012_val_00021764.bin 224 224 +21261 ./prep_dataset/ILSVRC2012_val_00044191.bin 224 224 +21262 ./prep_dataset/ILSVRC2012_val_00022209.bin 224 224 +21263 ./prep_dataset/ILSVRC2012_val_00035992.bin 224 224 +21264 ./prep_dataset/ILSVRC2012_val_00035223.bin 224 224 +21265 ./prep_dataset/ILSVRC2012_val_00011156.bin 224 224 +21266 ./prep_dataset/ILSVRC2012_val_00026572.bin 224 224 +21267 ./prep_dataset/ILSVRC2012_val_00013545.bin 224 224 +21268 ./prep_dataset/ILSVRC2012_val_00030997.bin 224 224 +21269 ./prep_dataset/ILSVRC2012_val_00035470.bin 224 224 +21270 ./prep_dataset/ILSVRC2012_val_00042657.bin 224 224 +21271 ./prep_dataset/ILSVRC2012_val_00024800.bin 224 224 +21272 ./prep_dataset/ILSVRC2012_val_00032664.bin 224 224 +21273 ./prep_dataset/ILSVRC2012_val_00043044.bin 224 224 +21274 ./prep_dataset/ILSVRC2012_val_00009640.bin 224 224 +21275 ./prep_dataset/ILSVRC2012_val_00048726.bin 224 224 +21276 ./prep_dataset/ILSVRC2012_val_00006653.bin 224 224 +21277 ./prep_dataset/ILSVRC2012_val_00046703.bin 224 224 +21278 ./prep_dataset/ILSVRC2012_val_00042954.bin 224 224 +21279 ./prep_dataset/ILSVRC2012_val_00011219.bin 224 224 +21280 ./prep_dataset/ILSVRC2012_val_00025219.bin 224 224 +21281 ./prep_dataset/ILSVRC2012_val_00026774.bin 224 224 +21282 ./prep_dataset/ILSVRC2012_val_00003632.bin 224 224 +21283 ./prep_dataset/ILSVRC2012_val_00046329.bin 224 224 +21284 ./prep_dataset/ILSVRC2012_val_00038078.bin 224 224 +21285 ./prep_dataset/ILSVRC2012_val_00032006.bin 224 224 +21286 ./prep_dataset/ILSVRC2012_val_00044883.bin 224 224 +21287 ./prep_dataset/ILSVRC2012_val_00026862.bin 224 224 +21288 ./prep_dataset/ILSVRC2012_val_00022026.bin 224 224 +21289 ./prep_dataset/ILSVRC2012_val_00038025.bin 224 224 +21290 ./prep_dataset/ILSVRC2012_val_00024630.bin 224 224 +21291 ./prep_dataset/ILSVRC2012_val_00023605.bin 224 224 +21292 ./prep_dataset/ILSVRC2012_val_00017709.bin 224 224 +21293 ./prep_dataset/ILSVRC2012_val_00037063.bin 224 224 +21294 ./prep_dataset/ILSVRC2012_val_00039978.bin 224 224 +21295 ./prep_dataset/ILSVRC2012_val_00011019.bin 224 224 +21296 ./prep_dataset/ILSVRC2012_val_00031394.bin 224 224 +21297 ./prep_dataset/ILSVRC2012_val_00001651.bin 224 224 +21298 ./prep_dataset/ILSVRC2012_val_00040512.bin 224 224 +21299 ./prep_dataset/ILSVRC2012_val_00046690.bin 224 224 +21300 ./prep_dataset/ILSVRC2012_val_00043741.bin 224 224 +21301 ./prep_dataset/ILSVRC2012_val_00030564.bin 224 224 +21302 ./prep_dataset/ILSVRC2012_val_00028204.bin 224 224 +21303 ./prep_dataset/ILSVRC2012_val_00019996.bin 224 224 +21304 ./prep_dataset/ILSVRC2012_val_00024226.bin 224 224 +21305 ./prep_dataset/ILSVRC2012_val_00016761.bin 224 224 +21306 ./prep_dataset/ILSVRC2012_val_00036293.bin 224 224 +21307 ./prep_dataset/ILSVRC2012_val_00046801.bin 224 224 +21308 ./prep_dataset/ILSVRC2012_val_00036159.bin 224 224 +21309 ./prep_dataset/ILSVRC2012_val_00015865.bin 224 224 +21310 ./prep_dataset/ILSVRC2012_val_00040779.bin 224 224 +21311 ./prep_dataset/ILSVRC2012_val_00036706.bin 224 224 +21312 ./prep_dataset/ILSVRC2012_val_00049939.bin 224 224 +21313 ./prep_dataset/ILSVRC2012_val_00045329.bin 224 224 +21314 ./prep_dataset/ILSVRC2012_val_00039878.bin 224 224 +21315 ./prep_dataset/ILSVRC2012_val_00037007.bin 224 224 +21316 ./prep_dataset/ILSVRC2012_val_00020073.bin 224 224 +21317 ./prep_dataset/ILSVRC2012_val_00037576.bin 224 224 +21318 ./prep_dataset/ILSVRC2012_val_00029103.bin 224 224 +21319 ./prep_dataset/ILSVRC2012_val_00035761.bin 224 224 +21320 ./prep_dataset/ILSVRC2012_val_00025434.bin 224 224 +21321 ./prep_dataset/ILSVRC2012_val_00033405.bin 224 224 +21322 ./prep_dataset/ILSVRC2012_val_00005442.bin 224 224 +21323 ./prep_dataset/ILSVRC2012_val_00014599.bin 224 224 +21324 ./prep_dataset/ILSVRC2012_val_00045809.bin 224 224 +21325 ./prep_dataset/ILSVRC2012_val_00042205.bin 224 224 +21326 ./prep_dataset/ILSVRC2012_val_00034144.bin 224 224 +21327 ./prep_dataset/ILSVRC2012_val_00021521.bin 224 224 +21328 ./prep_dataset/ILSVRC2012_val_00003353.bin 224 224 +21329 ./prep_dataset/ILSVRC2012_val_00030408.bin 224 224 +21330 ./prep_dataset/ILSVRC2012_val_00038376.bin 224 224 +21331 ./prep_dataset/ILSVRC2012_val_00018219.bin 224 224 +21332 ./prep_dataset/ILSVRC2012_val_00004749.bin 224 224 +21333 ./prep_dataset/ILSVRC2012_val_00014106.bin 224 224 +21334 ./prep_dataset/ILSVRC2012_val_00029550.bin 224 224 +21335 ./prep_dataset/ILSVRC2012_val_00007387.bin 224 224 +21336 ./prep_dataset/ILSVRC2012_val_00045611.bin 224 224 +21337 ./prep_dataset/ILSVRC2012_val_00019186.bin 224 224 +21338 ./prep_dataset/ILSVRC2012_val_00004044.bin 224 224 +21339 ./prep_dataset/ILSVRC2012_val_00002640.bin 224 224 +21340 ./prep_dataset/ILSVRC2012_val_00020377.bin 224 224 +21341 ./prep_dataset/ILSVRC2012_val_00008240.bin 224 224 +21342 ./prep_dataset/ILSVRC2012_val_00030189.bin 224 224 +21343 ./prep_dataset/ILSVRC2012_val_00030006.bin 224 224 +21344 ./prep_dataset/ILSVRC2012_val_00000235.bin 224 224 +21345 ./prep_dataset/ILSVRC2012_val_00040150.bin 224 224 +21346 ./prep_dataset/ILSVRC2012_val_00034878.bin 224 224 +21347 ./prep_dataset/ILSVRC2012_val_00026948.bin 224 224 +21348 ./prep_dataset/ILSVRC2012_val_00040754.bin 224 224 +21349 ./prep_dataset/ILSVRC2012_val_00016785.bin 224 224 +21350 ./prep_dataset/ILSVRC2012_val_00029359.bin 224 224 +21351 ./prep_dataset/ILSVRC2012_val_00036986.bin 224 224 +21352 ./prep_dataset/ILSVRC2012_val_00046951.bin 224 224 +21353 ./prep_dataset/ILSVRC2012_val_00046614.bin 224 224 +21354 ./prep_dataset/ILSVRC2012_val_00016016.bin 224 224 +21355 ./prep_dataset/ILSVRC2012_val_00041180.bin 224 224 +21356 ./prep_dataset/ILSVRC2012_val_00003212.bin 224 224 +21357 ./prep_dataset/ILSVRC2012_val_00002457.bin 224 224 +21358 ./prep_dataset/ILSVRC2012_val_00004850.bin 224 224 +21359 ./prep_dataset/ILSVRC2012_val_00033947.bin 224 224 +21360 ./prep_dataset/ILSVRC2012_val_00009668.bin 224 224 +21361 ./prep_dataset/ILSVRC2012_val_00010720.bin 224 224 +21362 ./prep_dataset/ILSVRC2012_val_00035317.bin 224 224 +21363 ./prep_dataset/ILSVRC2012_val_00027418.bin 224 224 +21364 ./prep_dataset/ILSVRC2012_val_00002705.bin 224 224 +21365 ./prep_dataset/ILSVRC2012_val_00028672.bin 224 224 +21366 ./prep_dataset/ILSVRC2012_val_00018783.bin 224 224 +21367 ./prep_dataset/ILSVRC2012_val_00006300.bin 224 224 +21368 ./prep_dataset/ILSVRC2012_val_00028129.bin 224 224 +21369 ./prep_dataset/ILSVRC2012_val_00048552.bin 224 224 +21370 ./prep_dataset/ILSVRC2012_val_00021065.bin 224 224 +21371 ./prep_dataset/ILSVRC2012_val_00016295.bin 224 224 +21372 ./prep_dataset/ILSVRC2012_val_00029674.bin 224 224 +21373 ./prep_dataset/ILSVRC2012_val_00022908.bin 224 224 +21374 ./prep_dataset/ILSVRC2012_val_00023307.bin 224 224 +21375 ./prep_dataset/ILSVRC2012_val_00012462.bin 224 224 +21376 ./prep_dataset/ILSVRC2012_val_00008257.bin 224 224 +21377 ./prep_dataset/ILSVRC2012_val_00026136.bin 224 224 +21378 ./prep_dataset/ILSVRC2012_val_00038360.bin 224 224 +21379 ./prep_dataset/ILSVRC2012_val_00037489.bin 224 224 +21380 ./prep_dataset/ILSVRC2012_val_00017494.bin 224 224 +21381 ./prep_dataset/ILSVRC2012_val_00039687.bin 224 224 +21382 ./prep_dataset/ILSVRC2012_val_00042603.bin 224 224 +21383 ./prep_dataset/ILSVRC2012_val_00014340.bin 224 224 +21384 ./prep_dataset/ILSVRC2012_val_00028688.bin 224 224 +21385 ./prep_dataset/ILSVRC2012_val_00003433.bin 224 224 +21386 ./prep_dataset/ILSVRC2012_val_00021252.bin 224 224 +21387 ./prep_dataset/ILSVRC2012_val_00003943.bin 224 224 +21388 ./prep_dataset/ILSVRC2012_val_00023270.bin 224 224 +21389 ./prep_dataset/ILSVRC2012_val_00015517.bin 224 224 +21390 ./prep_dataset/ILSVRC2012_val_00001901.bin 224 224 +21391 ./prep_dataset/ILSVRC2012_val_00033535.bin 224 224 +21392 ./prep_dataset/ILSVRC2012_val_00007214.bin 224 224 +21393 ./prep_dataset/ILSVRC2012_val_00029358.bin 224 224 +21394 ./prep_dataset/ILSVRC2012_val_00012833.bin 224 224 +21395 ./prep_dataset/ILSVRC2012_val_00040188.bin 224 224 +21396 ./prep_dataset/ILSVRC2012_val_00007277.bin 224 224 +21397 ./prep_dataset/ILSVRC2012_val_00041406.bin 224 224 +21398 ./prep_dataset/ILSVRC2012_val_00021537.bin 224 224 +21399 ./prep_dataset/ILSVRC2012_val_00035670.bin 224 224 +21400 ./prep_dataset/ILSVRC2012_val_00014883.bin 224 224 +21401 ./prep_dataset/ILSVRC2012_val_00004050.bin 224 224 +21402 ./prep_dataset/ILSVRC2012_val_00037190.bin 224 224 +21403 ./prep_dataset/ILSVRC2012_val_00004294.bin 224 224 +21404 ./prep_dataset/ILSVRC2012_val_00049330.bin 224 224 +21405 ./prep_dataset/ILSVRC2012_val_00025008.bin 224 224 +21406 ./prep_dataset/ILSVRC2012_val_00012400.bin 224 224 +21407 ./prep_dataset/ILSVRC2012_val_00000680.bin 224 224 +21408 ./prep_dataset/ILSVRC2012_val_00022021.bin 224 224 +21409 ./prep_dataset/ILSVRC2012_val_00034053.bin 224 224 +21410 ./prep_dataset/ILSVRC2012_val_00022929.bin 224 224 +21411 ./prep_dataset/ILSVRC2012_val_00048962.bin 224 224 +21412 ./prep_dataset/ILSVRC2012_val_00049019.bin 224 224 +21413 ./prep_dataset/ILSVRC2012_val_00015176.bin 224 224 +21414 ./prep_dataset/ILSVRC2012_val_00000290.bin 224 224 +21415 ./prep_dataset/ILSVRC2012_val_00035364.bin 224 224 +21416 ./prep_dataset/ILSVRC2012_val_00047732.bin 224 224 +21417 ./prep_dataset/ILSVRC2012_val_00004434.bin 224 224 +21418 ./prep_dataset/ILSVRC2012_val_00017670.bin 224 224 +21419 ./prep_dataset/ILSVRC2012_val_00017523.bin 224 224 +21420 ./prep_dataset/ILSVRC2012_val_00018399.bin 224 224 +21421 ./prep_dataset/ILSVRC2012_val_00001875.bin 224 224 +21422 ./prep_dataset/ILSVRC2012_val_00009612.bin 224 224 +21423 ./prep_dataset/ILSVRC2012_val_00044331.bin 224 224 +21424 ./prep_dataset/ILSVRC2012_val_00025667.bin 224 224 +21425 ./prep_dataset/ILSVRC2012_val_00010321.bin 224 224 +21426 ./prep_dataset/ILSVRC2012_val_00035256.bin 224 224 +21427 ./prep_dataset/ILSVRC2012_val_00013454.bin 224 224 +21428 ./prep_dataset/ILSVRC2012_val_00006059.bin 224 224 +21429 ./prep_dataset/ILSVRC2012_val_00028255.bin 224 224 +21430 ./prep_dataset/ILSVRC2012_val_00005441.bin 224 224 +21431 ./prep_dataset/ILSVRC2012_val_00013857.bin 224 224 +21432 ./prep_dataset/ILSVRC2012_val_00002724.bin 224 224 +21433 ./prep_dataset/ILSVRC2012_val_00036529.bin 224 224 +21434 ./prep_dataset/ILSVRC2012_val_00013132.bin 224 224 +21435 ./prep_dataset/ILSVRC2012_val_00038114.bin 224 224 +21436 ./prep_dataset/ILSVRC2012_val_00010029.bin 224 224 +21437 ./prep_dataset/ILSVRC2012_val_00026530.bin 224 224 +21438 ./prep_dataset/ILSVRC2012_val_00002514.bin 224 224 +21439 ./prep_dataset/ILSVRC2012_val_00034383.bin 224 224 +21440 ./prep_dataset/ILSVRC2012_val_00014879.bin 224 224 +21441 ./prep_dataset/ILSVRC2012_val_00003145.bin 224 224 +21442 ./prep_dataset/ILSVRC2012_val_00029621.bin 224 224 +21443 ./prep_dataset/ILSVRC2012_val_00003325.bin 224 224 +21444 ./prep_dataset/ILSVRC2012_val_00005276.bin 224 224 +21445 ./prep_dataset/ILSVRC2012_val_00038990.bin 224 224 +21446 ./prep_dataset/ILSVRC2012_val_00041432.bin 224 224 +21447 ./prep_dataset/ILSVRC2012_val_00009738.bin 224 224 +21448 ./prep_dataset/ILSVRC2012_val_00025744.bin 224 224 +21449 ./prep_dataset/ILSVRC2012_val_00008384.bin 224 224 +21450 ./prep_dataset/ILSVRC2012_val_00016622.bin 224 224 +21451 ./prep_dataset/ILSVRC2012_val_00049421.bin 224 224 +21452 ./prep_dataset/ILSVRC2012_val_00004810.bin 224 224 +21453 ./prep_dataset/ILSVRC2012_val_00022732.bin 224 224 +21454 ./prep_dataset/ILSVRC2012_val_00014196.bin 224 224 +21455 ./prep_dataset/ILSVRC2012_val_00037960.bin 224 224 +21456 ./prep_dataset/ILSVRC2012_val_00048172.bin 224 224 +21457 ./prep_dataset/ILSVRC2012_val_00026053.bin 224 224 +21458 ./prep_dataset/ILSVRC2012_val_00046445.bin 224 224 +21459 ./prep_dataset/ILSVRC2012_val_00028692.bin 224 224 +21460 ./prep_dataset/ILSVRC2012_val_00029919.bin 224 224 +21461 ./prep_dataset/ILSVRC2012_val_00015780.bin 224 224 +21462 ./prep_dataset/ILSVRC2012_val_00045132.bin 224 224 +21463 ./prep_dataset/ILSVRC2012_val_00021486.bin 224 224 +21464 ./prep_dataset/ILSVRC2012_val_00002244.bin 224 224 +21465 ./prep_dataset/ILSVRC2012_val_00037278.bin 224 224 +21466 ./prep_dataset/ILSVRC2012_val_00007689.bin 224 224 +21467 ./prep_dataset/ILSVRC2012_val_00026225.bin 224 224 +21468 ./prep_dataset/ILSVRC2012_val_00006759.bin 224 224 +21469 ./prep_dataset/ILSVRC2012_val_00016354.bin 224 224 +21470 ./prep_dataset/ILSVRC2012_val_00043183.bin 224 224 +21471 ./prep_dataset/ILSVRC2012_val_00018598.bin 224 224 +21472 ./prep_dataset/ILSVRC2012_val_00048446.bin 224 224 +21473 ./prep_dataset/ILSVRC2012_val_00026634.bin 224 224 +21474 ./prep_dataset/ILSVRC2012_val_00039974.bin 224 224 +21475 ./prep_dataset/ILSVRC2012_val_00047096.bin 224 224 +21476 ./prep_dataset/ILSVRC2012_val_00045819.bin 224 224 +21477 ./prep_dataset/ILSVRC2012_val_00031362.bin 224 224 +21478 ./prep_dataset/ILSVRC2012_val_00031419.bin 224 224 +21479 ./prep_dataset/ILSVRC2012_val_00041694.bin 224 224 +21480 ./prep_dataset/ILSVRC2012_val_00040618.bin 224 224 +21481 ./prep_dataset/ILSVRC2012_val_00009278.bin 224 224 +21482 ./prep_dataset/ILSVRC2012_val_00040679.bin 224 224 +21483 ./prep_dataset/ILSVRC2012_val_00011822.bin 224 224 +21484 ./prep_dataset/ILSVRC2012_val_00014901.bin 224 224 +21485 ./prep_dataset/ILSVRC2012_val_00002600.bin 224 224 +21486 ./prep_dataset/ILSVRC2012_val_00029877.bin 224 224 +21487 ./prep_dataset/ILSVRC2012_val_00008277.bin 224 224 +21488 ./prep_dataset/ILSVRC2012_val_00024069.bin 224 224 +21489 ./prep_dataset/ILSVRC2012_val_00001420.bin 224 224 +21490 ./prep_dataset/ILSVRC2012_val_00046401.bin 224 224 +21491 ./prep_dataset/ILSVRC2012_val_00004430.bin 224 224 +21492 ./prep_dataset/ILSVRC2012_val_00013267.bin 224 224 +21493 ./prep_dataset/ILSVRC2012_val_00026391.bin 224 224 +21494 ./prep_dataset/ILSVRC2012_val_00015199.bin 224 224 +21495 ./prep_dataset/ILSVRC2012_val_00026879.bin 224 224 +21496 ./prep_dataset/ILSVRC2012_val_00009427.bin 224 224 +21497 ./prep_dataset/ILSVRC2012_val_00008481.bin 224 224 +21498 ./prep_dataset/ILSVRC2012_val_00003996.bin 224 224 +21499 ./prep_dataset/ILSVRC2012_val_00045959.bin 224 224 +21500 ./prep_dataset/ILSVRC2012_val_00013426.bin 224 224 +21501 ./prep_dataset/ILSVRC2012_val_00030032.bin 224 224 +21502 ./prep_dataset/ILSVRC2012_val_00036959.bin 224 224 +21503 ./prep_dataset/ILSVRC2012_val_00004722.bin 224 224 +21504 ./prep_dataset/ILSVRC2012_val_00032159.bin 224 224 +21505 ./prep_dataset/ILSVRC2012_val_00013012.bin 224 224 +21506 ./prep_dataset/ILSVRC2012_val_00032743.bin 224 224 +21507 ./prep_dataset/ILSVRC2012_val_00046049.bin 224 224 +21508 ./prep_dataset/ILSVRC2012_val_00041041.bin 224 224 +21509 ./prep_dataset/ILSVRC2012_val_00046221.bin 224 224 +21510 ./prep_dataset/ILSVRC2012_val_00038093.bin 224 224 +21511 ./prep_dataset/ILSVRC2012_val_00024148.bin 224 224 +21512 ./prep_dataset/ILSVRC2012_val_00018630.bin 224 224 +21513 ./prep_dataset/ILSVRC2012_val_00012555.bin 224 224 +21514 ./prep_dataset/ILSVRC2012_val_00014609.bin 224 224 +21515 ./prep_dataset/ILSVRC2012_val_00022937.bin 224 224 +21516 ./prep_dataset/ILSVRC2012_val_00007774.bin 224 224 +21517 ./prep_dataset/ILSVRC2012_val_00017854.bin 224 224 +21518 ./prep_dataset/ILSVRC2012_val_00048254.bin 224 224 +21519 ./prep_dataset/ILSVRC2012_val_00000291.bin 224 224 +21520 ./prep_dataset/ILSVRC2012_val_00034857.bin 224 224 +21521 ./prep_dataset/ILSVRC2012_val_00016509.bin 224 224 +21522 ./prep_dataset/ILSVRC2012_val_00003099.bin 224 224 +21523 ./prep_dataset/ILSVRC2012_val_00028999.bin 224 224 +21524 ./prep_dataset/ILSVRC2012_val_00038171.bin 224 224 +21525 ./prep_dataset/ILSVRC2012_val_00009015.bin 224 224 +21526 ./prep_dataset/ILSVRC2012_val_00045288.bin 224 224 +21527 ./prep_dataset/ILSVRC2012_val_00033351.bin 224 224 +21528 ./prep_dataset/ILSVRC2012_val_00047595.bin 224 224 +21529 ./prep_dataset/ILSVRC2012_val_00023989.bin 224 224 +21530 ./prep_dataset/ILSVRC2012_val_00028655.bin 224 224 +21531 ./prep_dataset/ILSVRC2012_val_00012926.bin 224 224 +21532 ./prep_dataset/ILSVRC2012_val_00043751.bin 224 224 +21533 ./prep_dataset/ILSVRC2012_val_00020786.bin 224 224 +21534 ./prep_dataset/ILSVRC2012_val_00015845.bin 224 224 +21535 ./prep_dataset/ILSVRC2012_val_00014904.bin 224 224 +21536 ./prep_dataset/ILSVRC2012_val_00010329.bin 224 224 +21537 ./prep_dataset/ILSVRC2012_val_00044444.bin 224 224 +21538 ./prep_dataset/ILSVRC2012_val_00043321.bin 224 224 +21539 ./prep_dataset/ILSVRC2012_val_00031042.bin 224 224 +21540 ./prep_dataset/ILSVRC2012_val_00009334.bin 224 224 +21541 ./prep_dataset/ILSVRC2012_val_00016818.bin 224 224 +21542 ./prep_dataset/ILSVRC2012_val_00029381.bin 224 224 +21543 ./prep_dataset/ILSVRC2012_val_00015862.bin 224 224 +21544 ./prep_dataset/ILSVRC2012_val_00023449.bin 224 224 +21545 ./prep_dataset/ILSVRC2012_val_00040564.bin 224 224 +21546 ./prep_dataset/ILSVRC2012_val_00007044.bin 224 224 +21547 ./prep_dataset/ILSVRC2012_val_00004929.bin 224 224 +21548 ./prep_dataset/ILSVRC2012_val_00027563.bin 224 224 +21549 ./prep_dataset/ILSVRC2012_val_00034307.bin 224 224 +21550 ./prep_dataset/ILSVRC2012_val_00008904.bin 224 224 +21551 ./prep_dataset/ILSVRC2012_val_00021795.bin 224 224 +21552 ./prep_dataset/ILSVRC2012_val_00006584.bin 224 224 +21553 ./prep_dataset/ILSVRC2012_val_00036849.bin 224 224 +21554 ./prep_dataset/ILSVRC2012_val_00027450.bin 224 224 +21555 ./prep_dataset/ILSVRC2012_val_00000968.bin 224 224 +21556 ./prep_dataset/ILSVRC2012_val_00028012.bin 224 224 +21557 ./prep_dataset/ILSVRC2012_val_00040864.bin 224 224 +21558 ./prep_dataset/ILSVRC2012_val_00032375.bin 224 224 +21559 ./prep_dataset/ILSVRC2012_val_00032448.bin 224 224 +21560 ./prep_dataset/ILSVRC2012_val_00032350.bin 224 224 +21561 ./prep_dataset/ILSVRC2012_val_00009395.bin 224 224 +21562 ./prep_dataset/ILSVRC2012_val_00013747.bin 224 224 +21563 ./prep_dataset/ILSVRC2012_val_00024546.bin 224 224 +21564 ./prep_dataset/ILSVRC2012_val_00044034.bin 224 224 +21565 ./prep_dataset/ILSVRC2012_val_00006424.bin 224 224 +21566 ./prep_dataset/ILSVRC2012_val_00003567.bin 224 224 +21567 ./prep_dataset/ILSVRC2012_val_00045459.bin 224 224 +21568 ./prep_dataset/ILSVRC2012_val_00008033.bin 224 224 +21569 ./prep_dataset/ILSVRC2012_val_00028356.bin 224 224 +21570 ./prep_dataset/ILSVRC2012_val_00035841.bin 224 224 +21571 ./prep_dataset/ILSVRC2012_val_00013317.bin 224 224 +21572 ./prep_dataset/ILSVRC2012_val_00047243.bin 224 224 +21573 ./prep_dataset/ILSVRC2012_val_00010152.bin 224 224 +21574 ./prep_dataset/ILSVRC2012_val_00006571.bin 224 224 +21575 ./prep_dataset/ILSVRC2012_val_00043684.bin 224 224 +21576 ./prep_dataset/ILSVRC2012_val_00002192.bin 224 224 +21577 ./prep_dataset/ILSVRC2012_val_00039725.bin 224 224 +21578 ./prep_dataset/ILSVRC2012_val_00031562.bin 224 224 +21579 ./prep_dataset/ILSVRC2012_val_00013130.bin 224 224 +21580 ./prep_dataset/ILSVRC2012_val_00012285.bin 224 224 +21581 ./prep_dataset/ILSVRC2012_val_00047518.bin 224 224 +21582 ./prep_dataset/ILSVRC2012_val_00015898.bin 224 224 +21583 ./prep_dataset/ILSVRC2012_val_00032835.bin 224 224 +21584 ./prep_dataset/ILSVRC2012_val_00034579.bin 224 224 +21585 ./prep_dataset/ILSVRC2012_val_00040836.bin 224 224 +21586 ./prep_dataset/ILSVRC2012_val_00039288.bin 224 224 +21587 ./prep_dataset/ILSVRC2012_val_00017604.bin 224 224 +21588 ./prep_dataset/ILSVRC2012_val_00023298.bin 224 224 +21589 ./prep_dataset/ILSVRC2012_val_00029340.bin 224 224 +21590 ./prep_dataset/ILSVRC2012_val_00014898.bin 224 224 +21591 ./prep_dataset/ILSVRC2012_val_00045338.bin 224 224 +21592 ./prep_dataset/ILSVRC2012_val_00015086.bin 224 224 +21593 ./prep_dataset/ILSVRC2012_val_00007811.bin 224 224 +21594 ./prep_dataset/ILSVRC2012_val_00049744.bin 224 224 +21595 ./prep_dataset/ILSVRC2012_val_00019715.bin 224 224 +21596 ./prep_dataset/ILSVRC2012_val_00015332.bin 224 224 +21597 ./prep_dataset/ILSVRC2012_val_00025423.bin 224 224 +21598 ./prep_dataset/ILSVRC2012_val_00021981.bin 224 224 +21599 ./prep_dataset/ILSVRC2012_val_00039897.bin 224 224 +21600 ./prep_dataset/ILSVRC2012_val_00043115.bin 224 224 +21601 ./prep_dataset/ILSVRC2012_val_00028843.bin 224 224 +21602 ./prep_dataset/ILSVRC2012_val_00020024.bin 224 224 +21603 ./prep_dataset/ILSVRC2012_val_00005034.bin 224 224 +21604 ./prep_dataset/ILSVRC2012_val_00011611.bin 224 224 +21605 ./prep_dataset/ILSVRC2012_val_00022743.bin 224 224 +21606 ./prep_dataset/ILSVRC2012_val_00026852.bin 224 224 +21607 ./prep_dataset/ILSVRC2012_val_00001579.bin 224 224 +21608 ./prep_dataset/ILSVRC2012_val_00003428.bin 224 224 +21609 ./prep_dataset/ILSVRC2012_val_00007987.bin 224 224 +21610 ./prep_dataset/ILSVRC2012_val_00046381.bin 224 224 +21611 ./prep_dataset/ILSVRC2012_val_00012080.bin 224 224 +21612 ./prep_dataset/ILSVRC2012_val_00031471.bin 224 224 +21613 ./prep_dataset/ILSVRC2012_val_00014871.bin 224 224 +21614 ./prep_dataset/ILSVRC2012_val_00038682.bin 224 224 +21615 ./prep_dataset/ILSVRC2012_val_00029466.bin 224 224 +21616 ./prep_dataset/ILSVRC2012_val_00005975.bin 224 224 +21617 ./prep_dataset/ILSVRC2012_val_00003485.bin 224 224 +21618 ./prep_dataset/ILSVRC2012_val_00045261.bin 224 224 +21619 ./prep_dataset/ILSVRC2012_val_00048832.bin 224 224 +21620 ./prep_dataset/ILSVRC2012_val_00006135.bin 224 224 +21621 ./prep_dataset/ILSVRC2012_val_00037171.bin 224 224 +21622 ./prep_dataset/ILSVRC2012_val_00021579.bin 224 224 +21623 ./prep_dataset/ILSVRC2012_val_00003823.bin 224 224 +21624 ./prep_dataset/ILSVRC2012_val_00043696.bin 224 224 +21625 ./prep_dataset/ILSVRC2012_val_00035009.bin 224 224 +21626 ./prep_dataset/ILSVRC2012_val_00035789.bin 224 224 +21627 ./prep_dataset/ILSVRC2012_val_00009930.bin 224 224 +21628 ./prep_dataset/ILSVRC2012_val_00020921.bin 224 224 +21629 ./prep_dataset/ILSVRC2012_val_00013203.bin 224 224 +21630 ./prep_dataset/ILSVRC2012_val_00013095.bin 224 224 +21631 ./prep_dataset/ILSVRC2012_val_00046668.bin 224 224 +21632 ./prep_dataset/ILSVRC2012_val_00045396.bin 224 224 +21633 ./prep_dataset/ILSVRC2012_val_00015473.bin 224 224 +21634 ./prep_dataset/ILSVRC2012_val_00020960.bin 224 224 +21635 ./prep_dataset/ILSVRC2012_val_00044823.bin 224 224 +21636 ./prep_dataset/ILSVRC2012_val_00042868.bin 224 224 +21637 ./prep_dataset/ILSVRC2012_val_00038546.bin 224 224 +21638 ./prep_dataset/ILSVRC2012_val_00021962.bin 224 224 +21639 ./prep_dataset/ILSVRC2012_val_00036278.bin 224 224 +21640 ./prep_dataset/ILSVRC2012_val_00044277.bin 224 224 +21641 ./prep_dataset/ILSVRC2012_val_00024173.bin 224 224 +21642 ./prep_dataset/ILSVRC2012_val_00032530.bin 224 224 +21643 ./prep_dataset/ILSVRC2012_val_00027940.bin 224 224 +21644 ./prep_dataset/ILSVRC2012_val_00029957.bin 224 224 +21645 ./prep_dataset/ILSVRC2012_val_00034646.bin 224 224 +21646 ./prep_dataset/ILSVRC2012_val_00019765.bin 224 224 +21647 ./prep_dataset/ILSVRC2012_val_00016968.bin 224 224 +21648 ./prep_dataset/ILSVRC2012_val_00028071.bin 224 224 +21649 ./prep_dataset/ILSVRC2012_val_00011571.bin 224 224 +21650 ./prep_dataset/ILSVRC2012_val_00022454.bin 224 224 +21651 ./prep_dataset/ILSVRC2012_val_00036889.bin 224 224 +21652 ./prep_dataset/ILSVRC2012_val_00027283.bin 224 224 +21653 ./prep_dataset/ILSVRC2012_val_00022352.bin 224 224 +21654 ./prep_dataset/ILSVRC2012_val_00048735.bin 224 224 +21655 ./prep_dataset/ILSVRC2012_val_00015023.bin 224 224 +21656 ./prep_dataset/ILSVRC2012_val_00007369.bin 224 224 +21657 ./prep_dataset/ILSVRC2012_val_00008847.bin 224 224 +21658 ./prep_dataset/ILSVRC2012_val_00014076.bin 224 224 +21659 ./prep_dataset/ILSVRC2012_val_00032573.bin 224 224 +21660 ./prep_dataset/ILSVRC2012_val_00037947.bin 224 224 +21661 ./prep_dataset/ILSVRC2012_val_00015732.bin 224 224 +21662 ./prep_dataset/ILSVRC2012_val_00011289.bin 224 224 +21663 ./prep_dataset/ILSVRC2012_val_00033210.bin 224 224 +21664 ./prep_dataset/ILSVRC2012_val_00044101.bin 224 224 +21665 ./prep_dataset/ILSVRC2012_val_00024679.bin 224 224 +21666 ./prep_dataset/ILSVRC2012_val_00007377.bin 224 224 +21667 ./prep_dataset/ILSVRC2012_val_00035506.bin 224 224 +21668 ./prep_dataset/ILSVRC2012_val_00001932.bin 224 224 +21669 ./prep_dataset/ILSVRC2012_val_00024585.bin 224 224 +21670 ./prep_dataset/ILSVRC2012_val_00003835.bin 224 224 +21671 ./prep_dataset/ILSVRC2012_val_00018363.bin 224 224 +21672 ./prep_dataset/ILSVRC2012_val_00036661.bin 224 224 +21673 ./prep_dataset/ILSVRC2012_val_00035293.bin 224 224 +21674 ./prep_dataset/ILSVRC2012_val_00047803.bin 224 224 +21675 ./prep_dataset/ILSVRC2012_val_00011808.bin 224 224 +21676 ./prep_dataset/ILSVRC2012_val_00028528.bin 224 224 +21677 ./prep_dataset/ILSVRC2012_val_00046393.bin 224 224 +21678 ./prep_dataset/ILSVRC2012_val_00045403.bin 224 224 +21679 ./prep_dataset/ILSVRC2012_val_00041909.bin 224 224 +21680 ./prep_dataset/ILSVRC2012_val_00008456.bin 224 224 +21681 ./prep_dataset/ILSVRC2012_val_00000415.bin 224 224 +21682 ./prep_dataset/ILSVRC2012_val_00049455.bin 224 224 +21683 ./prep_dataset/ILSVRC2012_val_00019497.bin 224 224 +21684 ./prep_dataset/ILSVRC2012_val_00034046.bin 224 224 +21685 ./prep_dataset/ILSVRC2012_val_00004398.bin 224 224 +21686 ./prep_dataset/ILSVRC2012_val_00042184.bin 224 224 +21687 ./prep_dataset/ILSVRC2012_val_00049730.bin 224 224 +21688 ./prep_dataset/ILSVRC2012_val_00049092.bin 224 224 +21689 ./prep_dataset/ILSVRC2012_val_00022930.bin 224 224 +21690 ./prep_dataset/ILSVRC2012_val_00016861.bin 224 224 +21691 ./prep_dataset/ILSVRC2012_val_00008214.bin 224 224 +21692 ./prep_dataset/ILSVRC2012_val_00008765.bin 224 224 +21693 ./prep_dataset/ILSVRC2012_val_00047487.bin 224 224 +21694 ./prep_dataset/ILSVRC2012_val_00026788.bin 224 224 +21695 ./prep_dataset/ILSVRC2012_val_00023520.bin 224 224 +21696 ./prep_dataset/ILSVRC2012_val_00004947.bin 224 224 +21697 ./prep_dataset/ILSVRC2012_val_00019165.bin 224 224 +21698 ./prep_dataset/ILSVRC2012_val_00025967.bin 224 224 +21699 ./prep_dataset/ILSVRC2012_val_00036499.bin 224 224 +21700 ./prep_dataset/ILSVRC2012_val_00014448.bin 224 224 +21701 ./prep_dataset/ILSVRC2012_val_00031936.bin 224 224 +21702 ./prep_dataset/ILSVRC2012_val_00041309.bin 224 224 +21703 ./prep_dataset/ILSVRC2012_val_00012759.bin 224 224 +21704 ./prep_dataset/ILSVRC2012_val_00040918.bin 224 224 +21705 ./prep_dataset/ILSVRC2012_val_00009550.bin 224 224 +21706 ./prep_dataset/ILSVRC2012_val_00026441.bin 224 224 +21707 ./prep_dataset/ILSVRC2012_val_00030819.bin 224 224 +21708 ./prep_dataset/ILSVRC2012_val_00000343.bin 224 224 +21709 ./prep_dataset/ILSVRC2012_val_00041192.bin 224 224 +21710 ./prep_dataset/ILSVRC2012_val_00024145.bin 224 224 +21711 ./prep_dataset/ILSVRC2012_val_00008735.bin 224 224 +21712 ./prep_dataset/ILSVRC2012_val_00046768.bin 224 224 +21713 ./prep_dataset/ILSVRC2012_val_00003555.bin 224 224 +21714 ./prep_dataset/ILSVRC2012_val_00012029.bin 224 224 +21715 ./prep_dataset/ILSVRC2012_val_00019236.bin 224 224 +21716 ./prep_dataset/ILSVRC2012_val_00033408.bin 224 224 +21717 ./prep_dataset/ILSVRC2012_val_00044379.bin 224 224 +21718 ./prep_dataset/ILSVRC2012_val_00027759.bin 224 224 +21719 ./prep_dataset/ILSVRC2012_val_00006387.bin 224 224 +21720 ./prep_dataset/ILSVRC2012_val_00023815.bin 224 224 +21721 ./prep_dataset/ILSVRC2012_val_00045650.bin 224 224 +21722 ./prep_dataset/ILSVRC2012_val_00003878.bin 224 224 +21723 ./prep_dataset/ILSVRC2012_val_00003012.bin 224 224 +21724 ./prep_dataset/ILSVRC2012_val_00047785.bin 224 224 +21725 ./prep_dataset/ILSVRC2012_val_00000544.bin 224 224 +21726 ./prep_dataset/ILSVRC2012_val_00040881.bin 224 224 +21727 ./prep_dataset/ILSVRC2012_val_00044797.bin 224 224 +21728 ./prep_dataset/ILSVRC2012_val_00022594.bin 224 224 +21729 ./prep_dataset/ILSVRC2012_val_00016664.bin 224 224 +21730 ./prep_dataset/ILSVRC2012_val_00025617.bin 224 224 +21731 ./prep_dataset/ILSVRC2012_val_00017558.bin 224 224 +21732 ./prep_dataset/ILSVRC2012_val_00024854.bin 224 224 +21733 ./prep_dataset/ILSVRC2012_val_00022131.bin 224 224 +21734 ./prep_dataset/ILSVRC2012_val_00027830.bin 224 224 +21735 ./prep_dataset/ILSVRC2012_val_00018364.bin 224 224 +21736 ./prep_dataset/ILSVRC2012_val_00021667.bin 224 224 +21737 ./prep_dataset/ILSVRC2012_val_00039869.bin 224 224 +21738 ./prep_dataset/ILSVRC2012_val_00048210.bin 224 224 +21739 ./prep_dataset/ILSVRC2012_val_00033760.bin 224 224 +21740 ./prep_dataset/ILSVRC2012_val_00028440.bin 224 224 +21741 ./prep_dataset/ILSVRC2012_val_00026274.bin 224 224 +21742 ./prep_dataset/ILSVRC2012_val_00002294.bin 224 224 +21743 ./prep_dataset/ILSVRC2012_val_00013730.bin 224 224 +21744 ./prep_dataset/ILSVRC2012_val_00018972.bin 224 224 +21745 ./prep_dataset/ILSVRC2012_val_00027587.bin 224 224 +21746 ./prep_dataset/ILSVRC2012_val_00023870.bin 224 224 +21747 ./prep_dataset/ILSVRC2012_val_00042740.bin 224 224 +21748 ./prep_dataset/ILSVRC2012_val_00034110.bin 224 224 +21749 ./prep_dataset/ILSVRC2012_val_00009128.bin 224 224 +21750 ./prep_dataset/ILSVRC2012_val_00034202.bin 224 224 +21751 ./prep_dataset/ILSVRC2012_val_00038261.bin 224 224 +21752 ./prep_dataset/ILSVRC2012_val_00021944.bin 224 224 +21753 ./prep_dataset/ILSVRC2012_val_00042930.bin 224 224 +21754 ./prep_dataset/ILSVRC2012_val_00012047.bin 224 224 +21755 ./prep_dataset/ILSVRC2012_val_00012085.bin 224 224 +21756 ./prep_dataset/ILSVRC2012_val_00019257.bin 224 224 +21757 ./prep_dataset/ILSVRC2012_val_00015810.bin 224 224 +21758 ./prep_dataset/ILSVRC2012_val_00002149.bin 224 224 +21759 ./prep_dataset/ILSVRC2012_val_00007749.bin 224 224 +21760 ./prep_dataset/ILSVRC2012_val_00027265.bin 224 224 +21761 ./prep_dataset/ILSVRC2012_val_00026760.bin 224 224 +21762 ./prep_dataset/ILSVRC2012_val_00033073.bin 224 224 +21763 ./prep_dataset/ILSVRC2012_val_00037744.bin 224 224 +21764 ./prep_dataset/ILSVRC2012_val_00035675.bin 224 224 +21765 ./prep_dataset/ILSVRC2012_val_00018396.bin 224 224 +21766 ./prep_dataset/ILSVRC2012_val_00019344.bin 224 224 +21767 ./prep_dataset/ILSVRC2012_val_00043797.bin 224 224 +21768 ./prep_dataset/ILSVRC2012_val_00010387.bin 224 224 +21769 ./prep_dataset/ILSVRC2012_val_00034701.bin 224 224 +21770 ./prep_dataset/ILSVRC2012_val_00029143.bin 224 224 +21771 ./prep_dataset/ILSVRC2012_val_00017468.bin 224 224 +21772 ./prep_dataset/ILSVRC2012_val_00049267.bin 224 224 +21773 ./prep_dataset/ILSVRC2012_val_00018962.bin 224 224 +21774 ./prep_dataset/ILSVRC2012_val_00036030.bin 224 224 +21775 ./prep_dataset/ILSVRC2012_val_00031880.bin 224 224 +21776 ./prep_dataset/ILSVRC2012_val_00026368.bin 224 224 +21777 ./prep_dataset/ILSVRC2012_val_00009886.bin 224 224 +21778 ./prep_dataset/ILSVRC2012_val_00012830.bin 224 224 +21779 ./prep_dataset/ILSVRC2012_val_00024847.bin 224 224 +21780 ./prep_dataset/ILSVRC2012_val_00030031.bin 224 224 +21781 ./prep_dataset/ILSVRC2012_val_00017160.bin 224 224 +21782 ./prep_dataset/ILSVRC2012_val_00023599.bin 224 224 +21783 ./prep_dataset/ILSVRC2012_val_00036025.bin 224 224 +21784 ./prep_dataset/ILSVRC2012_val_00014508.bin 224 224 +21785 ./prep_dataset/ILSVRC2012_val_00039095.bin 224 224 +21786 ./prep_dataset/ILSVRC2012_val_00009465.bin 224 224 +21787 ./prep_dataset/ILSVRC2012_val_00018938.bin 224 224 +21788 ./prep_dataset/ILSVRC2012_val_00048705.bin 224 224 +21789 ./prep_dataset/ILSVRC2012_val_00003244.bin 224 224 +21790 ./prep_dataset/ILSVRC2012_val_00023687.bin 224 224 +21791 ./prep_dataset/ILSVRC2012_val_00014088.bin 224 224 +21792 ./prep_dataset/ILSVRC2012_val_00012390.bin 224 224 +21793 ./prep_dataset/ILSVRC2012_val_00042605.bin 224 224 +21794 ./prep_dataset/ILSVRC2012_val_00049750.bin 224 224 +21795 ./prep_dataset/ILSVRC2012_val_00042695.bin 224 224 +21796 ./prep_dataset/ILSVRC2012_val_00045895.bin 224 224 +21797 ./prep_dataset/ILSVRC2012_val_00001163.bin 224 224 +21798 ./prep_dataset/ILSVRC2012_val_00037762.bin 224 224 +21799 ./prep_dataset/ILSVRC2012_val_00040524.bin 224 224 +21800 ./prep_dataset/ILSVRC2012_val_00011760.bin 224 224 +21801 ./prep_dataset/ILSVRC2012_val_00029262.bin 224 224 +21802 ./prep_dataset/ILSVRC2012_val_00030127.bin 224 224 +21803 ./prep_dataset/ILSVRC2012_val_00010338.bin 224 224 +21804 ./prep_dataset/ILSVRC2012_val_00003601.bin 224 224 +21805 ./prep_dataset/ILSVRC2012_val_00046568.bin 224 224 +21806 ./prep_dataset/ILSVRC2012_val_00048182.bin 224 224 +21807 ./prep_dataset/ILSVRC2012_val_00024358.bin 224 224 +21808 ./prep_dataset/ILSVRC2012_val_00023198.bin 224 224 +21809 ./prep_dataset/ILSVRC2012_val_00031862.bin 224 224 +21810 ./prep_dataset/ILSVRC2012_val_00002934.bin 224 224 +21811 ./prep_dataset/ILSVRC2012_val_00031216.bin 224 224 +21812 ./prep_dataset/ILSVRC2012_val_00016068.bin 224 224 +21813 ./prep_dataset/ILSVRC2012_val_00012636.bin 224 224 +21814 ./prep_dataset/ILSVRC2012_val_00004909.bin 224 224 +21815 ./prep_dataset/ILSVRC2012_val_00017649.bin 224 224 +21816 ./prep_dataset/ILSVRC2012_val_00001291.bin 224 224 +21817 ./prep_dataset/ILSVRC2012_val_00037642.bin 224 224 +21818 ./prep_dataset/ILSVRC2012_val_00009040.bin 224 224 +21819 ./prep_dataset/ILSVRC2012_val_00035387.bin 224 224 +21820 ./prep_dataset/ILSVRC2012_val_00011159.bin 224 224 +21821 ./prep_dataset/ILSVRC2012_val_00010398.bin 224 224 +21822 ./prep_dataset/ILSVRC2012_val_00036908.bin 224 224 +21823 ./prep_dataset/ILSVRC2012_val_00033845.bin 224 224 +21824 ./prep_dataset/ILSVRC2012_val_00036402.bin 224 224 +21825 ./prep_dataset/ILSVRC2012_val_00003628.bin 224 224 +21826 ./prep_dataset/ILSVRC2012_val_00043022.bin 224 224 +21827 ./prep_dataset/ILSVRC2012_val_00046991.bin 224 224 +21828 ./prep_dataset/ILSVRC2012_val_00028235.bin 224 224 +21829 ./prep_dataset/ILSVRC2012_val_00034848.bin 224 224 +21830 ./prep_dataset/ILSVRC2012_val_00003766.bin 224 224 +21831 ./prep_dataset/ILSVRC2012_val_00041930.bin 224 224 +21832 ./prep_dataset/ILSVRC2012_val_00032313.bin 224 224 +21833 ./prep_dataset/ILSVRC2012_val_00037624.bin 224 224 +21834 ./prep_dataset/ILSVRC2012_val_00033757.bin 224 224 +21835 ./prep_dataset/ILSVRC2012_val_00027451.bin 224 224 +21836 ./prep_dataset/ILSVRC2012_val_00005146.bin 224 224 +21837 ./prep_dataset/ILSVRC2012_val_00031970.bin 224 224 +21838 ./prep_dataset/ILSVRC2012_val_00016879.bin 224 224 +21839 ./prep_dataset/ILSVRC2012_val_00019390.bin 224 224 +21840 ./prep_dataset/ILSVRC2012_val_00047198.bin 224 224 +21841 ./prep_dataset/ILSVRC2012_val_00011093.bin 224 224 +21842 ./prep_dataset/ILSVRC2012_val_00018093.bin 224 224 +21843 ./prep_dataset/ILSVRC2012_val_00015557.bin 224 224 +21844 ./prep_dataset/ILSVRC2012_val_00026858.bin 224 224 +21845 ./prep_dataset/ILSVRC2012_val_00000049.bin 224 224 +21846 ./prep_dataset/ILSVRC2012_val_00000038.bin 224 224 +21847 ./prep_dataset/ILSVRC2012_val_00030584.bin 224 224 +21848 ./prep_dataset/ILSVRC2012_val_00003877.bin 224 224 +21849 ./prep_dataset/ILSVRC2012_val_00034321.bin 224 224 +21850 ./prep_dataset/ILSVRC2012_val_00010478.bin 224 224 +21851 ./prep_dataset/ILSVRC2012_val_00039266.bin 224 224 +21852 ./prep_dataset/ILSVRC2012_val_00031329.bin 224 224 +21853 ./prep_dataset/ILSVRC2012_val_00044153.bin 224 224 +21854 ./prep_dataset/ILSVRC2012_val_00032179.bin 224 224 +21855 ./prep_dataset/ILSVRC2012_val_00046142.bin 224 224 +21856 ./prep_dataset/ILSVRC2012_val_00043451.bin 224 224 +21857 ./prep_dataset/ILSVRC2012_val_00009114.bin 224 224 +21858 ./prep_dataset/ILSVRC2012_val_00014304.bin 224 224 +21859 ./prep_dataset/ILSVRC2012_val_00022822.bin 224 224 +21860 ./prep_dataset/ILSVRC2012_val_00043187.bin 224 224 +21861 ./prep_dataset/ILSVRC2012_val_00040162.bin 224 224 +21862 ./prep_dataset/ILSVRC2012_val_00014643.bin 224 224 +21863 ./prep_dataset/ILSVRC2012_val_00011898.bin 224 224 +21864 ./prep_dataset/ILSVRC2012_val_00004535.bin 224 224 +21865 ./prep_dataset/ILSVRC2012_val_00021405.bin 224 224 +21866 ./prep_dataset/ILSVRC2012_val_00034336.bin 224 224 +21867 ./prep_dataset/ILSVRC2012_val_00020685.bin 224 224 +21868 ./prep_dataset/ILSVRC2012_val_00047340.bin 224 224 +21869 ./prep_dataset/ILSVRC2012_val_00008558.bin 224 224 +21870 ./prep_dataset/ILSVRC2012_val_00001771.bin 224 224 +21871 ./prep_dataset/ILSVRC2012_val_00034816.bin 224 224 +21872 ./prep_dataset/ILSVRC2012_val_00005424.bin 224 224 +21873 ./prep_dataset/ILSVRC2012_val_00018638.bin 224 224 +21874 ./prep_dataset/ILSVRC2012_val_00037121.bin 224 224 +21875 ./prep_dataset/ILSVRC2012_val_00031665.bin 224 224 +21876 ./prep_dataset/ILSVRC2012_val_00003619.bin 224 224 +21877 ./prep_dataset/ILSVRC2012_val_00006234.bin 224 224 +21878 ./prep_dataset/ILSVRC2012_val_00006665.bin 224 224 +21879 ./prep_dataset/ILSVRC2012_val_00000004.bin 224 224 +21880 ./prep_dataset/ILSVRC2012_val_00030358.bin 224 224 +21881 ./prep_dataset/ILSVRC2012_val_00020766.bin 224 224 +21882 ./prep_dataset/ILSVRC2012_val_00026355.bin 224 224 +21883 ./prep_dataset/ILSVRC2012_val_00007290.bin 224 224 +21884 ./prep_dataset/ILSVRC2012_val_00036150.bin 224 224 +21885 ./prep_dataset/ILSVRC2012_val_00033486.bin 224 224 +21886 ./prep_dataset/ILSVRC2012_val_00039660.bin 224 224 +21887 ./prep_dataset/ILSVRC2012_val_00022696.bin 224 224 +21888 ./prep_dataset/ILSVRC2012_val_00002304.bin 224 224 +21889 ./prep_dataset/ILSVRC2012_val_00009300.bin 224 224 +21890 ./prep_dataset/ILSVRC2012_val_00032339.bin 224 224 +21891 ./prep_dataset/ILSVRC2012_val_00011782.bin 224 224 +21892 ./prep_dataset/ILSVRC2012_val_00024128.bin 224 224 +21893 ./prep_dataset/ILSVRC2012_val_00035163.bin 224 224 +21894 ./prep_dataset/ILSVRC2012_val_00035833.bin 224 224 +21895 ./prep_dataset/ILSVRC2012_val_00009984.bin 224 224 +21896 ./prep_dataset/ILSVRC2012_val_00026854.bin 224 224 +21897 ./prep_dataset/ILSVRC2012_val_00048185.bin 224 224 +21898 ./prep_dataset/ILSVRC2012_val_00037684.bin 224 224 +21899 ./prep_dataset/ILSVRC2012_val_00011581.bin 224 224 +21900 ./prep_dataset/ILSVRC2012_val_00042115.bin 224 224 +21901 ./prep_dataset/ILSVRC2012_val_00017970.bin 224 224 +21902 ./prep_dataset/ILSVRC2012_val_00028938.bin 224 224 +21903 ./prep_dataset/ILSVRC2012_val_00007672.bin 224 224 +21904 ./prep_dataset/ILSVRC2012_val_00005581.bin 224 224 +21905 ./prep_dataset/ILSVRC2012_val_00025077.bin 224 224 +21906 ./prep_dataset/ILSVRC2012_val_00019034.bin 224 224 +21907 ./prep_dataset/ILSVRC2012_val_00046970.bin 224 224 +21908 ./prep_dataset/ILSVRC2012_val_00002233.bin 224 224 +21909 ./prep_dataset/ILSVRC2012_val_00000564.bin 224 224 +21910 ./prep_dataset/ILSVRC2012_val_00008115.bin 224 224 +21911 ./prep_dataset/ILSVRC2012_val_00044166.bin 224 224 +21912 ./prep_dataset/ILSVRC2012_val_00018974.bin 224 224 +21913 ./prep_dataset/ILSVRC2012_val_00019364.bin 224 224 +21914 ./prep_dataset/ILSVRC2012_val_00019290.bin 224 224 +21915 ./prep_dataset/ILSVRC2012_val_00006800.bin 224 224 +21916 ./prep_dataset/ILSVRC2012_val_00047512.bin 224 224 +21917 ./prep_dataset/ILSVRC2012_val_00015687.bin 224 224 +21918 ./prep_dataset/ILSVRC2012_val_00002033.bin 224 224 +21919 ./prep_dataset/ILSVRC2012_val_00001540.bin 224 224 +21920 ./prep_dataset/ILSVRC2012_val_00006895.bin 224 224 +21921 ./prep_dataset/ILSVRC2012_val_00017808.bin 224 224 +21922 ./prep_dataset/ILSVRC2012_val_00004365.bin 224 224 +21923 ./prep_dataset/ILSVRC2012_val_00011273.bin 224 224 +21924 ./prep_dataset/ILSVRC2012_val_00004720.bin 224 224 +21925 ./prep_dataset/ILSVRC2012_val_00003410.bin 224 224 +21926 ./prep_dataset/ILSVRC2012_val_00033380.bin 224 224 +21927 ./prep_dataset/ILSVRC2012_val_00011183.bin 224 224 +21928 ./prep_dataset/ILSVRC2012_val_00029206.bin 224 224 +21929 ./prep_dataset/ILSVRC2012_val_00000526.bin 224 224 +21930 ./prep_dataset/ILSVRC2012_val_00024994.bin 224 224 +21931 ./prep_dataset/ILSVRC2012_val_00026610.bin 224 224 +21932 ./prep_dataset/ILSVRC2012_val_00017107.bin 224 224 +21933 ./prep_dataset/ILSVRC2012_val_00000381.bin 224 224 +21934 ./prep_dataset/ILSVRC2012_val_00015800.bin 224 224 +21935 ./prep_dataset/ILSVRC2012_val_00043433.bin 224 224 +21936 ./prep_dataset/ILSVRC2012_val_00047503.bin 224 224 +21937 ./prep_dataset/ILSVRC2012_val_00020338.bin 224 224 +21938 ./prep_dataset/ILSVRC2012_val_00024214.bin 224 224 +21939 ./prep_dataset/ILSVRC2012_val_00014504.bin 224 224 +21940 ./prep_dataset/ILSVRC2012_val_00018951.bin 224 224 +21941 ./prep_dataset/ILSVRC2012_val_00001939.bin 224 224 +21942 ./prep_dataset/ILSVRC2012_val_00008979.bin 224 224 +21943 ./prep_dataset/ILSVRC2012_val_00022236.bin 224 224 +21944 ./prep_dataset/ILSVRC2012_val_00001155.bin 224 224 +21945 ./prep_dataset/ILSVRC2012_val_00003169.bin 224 224 +21946 ./prep_dataset/ILSVRC2012_val_00000345.bin 224 224 +21947 ./prep_dataset/ILSVRC2012_val_00044690.bin 224 224 +21948 ./prep_dataset/ILSVRC2012_val_00012928.bin 224 224 +21949 ./prep_dataset/ILSVRC2012_val_00029432.bin 224 224 +21950 ./prep_dataset/ILSVRC2012_val_00040598.bin 224 224 +21951 ./prep_dataset/ILSVRC2012_val_00024010.bin 224 224 +21952 ./prep_dataset/ILSVRC2012_val_00024033.bin 224 224 +21953 ./prep_dataset/ILSVRC2012_val_00027515.bin 224 224 +21954 ./prep_dataset/ILSVRC2012_val_00028143.bin 224 224 +21955 ./prep_dataset/ILSVRC2012_val_00023400.bin 224 224 +21956 ./prep_dataset/ILSVRC2012_val_00037795.bin 224 224 +21957 ./prep_dataset/ILSVRC2012_val_00035160.bin 224 224 +21958 ./prep_dataset/ILSVRC2012_val_00028962.bin 224 224 +21959 ./prep_dataset/ILSVRC2012_val_00031398.bin 224 224 +21960 ./prep_dataset/ILSVRC2012_val_00012647.bin 224 224 +21961 ./prep_dataset/ILSVRC2012_val_00013773.bin 224 224 +21962 ./prep_dataset/ILSVRC2012_val_00048825.bin 224 224 +21963 ./prep_dataset/ILSVRC2012_val_00047359.bin 224 224 +21964 ./prep_dataset/ILSVRC2012_val_00026138.bin 224 224 +21965 ./prep_dataset/ILSVRC2012_val_00035049.bin 224 224 +21966 ./prep_dataset/ILSVRC2012_val_00014450.bin 224 224 +21967 ./prep_dataset/ILSVRC2012_val_00009005.bin 224 224 +21968 ./prep_dataset/ILSVRC2012_val_00025567.bin 224 224 +21969 ./prep_dataset/ILSVRC2012_val_00030946.bin 224 224 +21970 ./prep_dataset/ILSVRC2012_val_00018750.bin 224 224 +21971 ./prep_dataset/ILSVRC2012_val_00044132.bin 224 224 +21972 ./prep_dataset/ILSVRC2012_val_00005124.bin 224 224 +21973 ./prep_dataset/ILSVRC2012_val_00042447.bin 224 224 +21974 ./prep_dataset/ILSVRC2012_val_00048671.bin 224 224 +21975 ./prep_dataset/ILSVRC2012_val_00004477.bin 224 224 +21976 ./prep_dataset/ILSVRC2012_val_00004227.bin 224 224 +21977 ./prep_dataset/ILSVRC2012_val_00044600.bin 224 224 +21978 ./prep_dataset/ILSVRC2012_val_00003979.bin 224 224 +21979 ./prep_dataset/ILSVRC2012_val_00034697.bin 224 224 +21980 ./prep_dataset/ILSVRC2012_val_00030729.bin 224 224 +21981 ./prep_dataset/ILSVRC2012_val_00049891.bin 224 224 +21982 ./prep_dataset/ILSVRC2012_val_00014996.bin 224 224 +21983 ./prep_dataset/ILSVRC2012_val_00048896.bin 224 224 +21984 ./prep_dataset/ILSVRC2012_val_00048849.bin 224 224 +21985 ./prep_dataset/ILSVRC2012_val_00043257.bin 224 224 +21986 ./prep_dataset/ILSVRC2012_val_00047265.bin 224 224 +21987 ./prep_dataset/ILSVRC2012_val_00030571.bin 224 224 +21988 ./prep_dataset/ILSVRC2012_val_00045827.bin 224 224 +21989 ./prep_dataset/ILSVRC2012_val_00011767.bin 224 224 +21990 ./prep_dataset/ILSVRC2012_val_00018382.bin 224 224 +21991 ./prep_dataset/ILSVRC2012_val_00047714.bin 224 224 +21992 ./prep_dataset/ILSVRC2012_val_00011335.bin 224 224 +21993 ./prep_dataset/ILSVRC2012_val_00013881.bin 224 224 +21994 ./prep_dataset/ILSVRC2012_val_00031003.bin 224 224 +21995 ./prep_dataset/ILSVRC2012_val_00044151.bin 224 224 +21996 ./prep_dataset/ILSVRC2012_val_00010902.bin 224 224 +21997 ./prep_dataset/ILSVRC2012_val_00017843.bin 224 224 +21998 ./prep_dataset/ILSVRC2012_val_00022277.bin 224 224 +21999 ./prep_dataset/ILSVRC2012_val_00013786.bin 224 224 +22000 ./prep_dataset/ILSVRC2012_val_00016224.bin 224 224 +22001 ./prep_dataset/ILSVRC2012_val_00012075.bin 224 224 +22002 ./prep_dataset/ILSVRC2012_val_00040315.bin 224 224 +22003 ./prep_dataset/ILSVRC2012_val_00008720.bin 224 224 +22004 ./prep_dataset/ILSVRC2012_val_00021222.bin 224 224 +22005 ./prep_dataset/ILSVRC2012_val_00025880.bin 224 224 +22006 ./prep_dataset/ILSVRC2012_val_00036916.bin 224 224 +22007 ./prep_dataset/ILSVRC2012_val_00019830.bin 224 224 +22008 ./prep_dataset/ILSVRC2012_val_00004620.bin 224 224 +22009 ./prep_dataset/ILSVRC2012_val_00042812.bin 224 224 +22010 ./prep_dataset/ILSVRC2012_val_00013752.bin 224 224 +22011 ./prep_dataset/ILSVRC2012_val_00047719.bin 224 224 +22012 ./prep_dataset/ILSVRC2012_val_00031998.bin 224 224 +22013 ./prep_dataset/ILSVRC2012_val_00046019.bin 224 224 +22014 ./prep_dataset/ILSVRC2012_val_00028260.bin 224 224 +22015 ./prep_dataset/ILSVRC2012_val_00030695.bin 224 224 +22016 ./prep_dataset/ILSVRC2012_val_00036052.bin 224 224 +22017 ./prep_dataset/ILSVRC2012_val_00037634.bin 224 224 +22018 ./prep_dataset/ILSVRC2012_val_00043327.bin 224 224 +22019 ./prep_dataset/ILSVRC2012_val_00008879.bin 224 224 +22020 ./prep_dataset/ILSVRC2012_val_00025023.bin 224 224 +22021 ./prep_dataset/ILSVRC2012_val_00027166.bin 224 224 +22022 ./prep_dataset/ILSVRC2012_val_00033834.bin 224 224 +22023 ./prep_dataset/ILSVRC2012_val_00032114.bin 224 224 +22024 ./prep_dataset/ILSVRC2012_val_00022431.bin 224 224 +22025 ./prep_dataset/ILSVRC2012_val_00038465.bin 224 224 +22026 ./prep_dataset/ILSVRC2012_val_00021146.bin 224 224 +22027 ./prep_dataset/ILSVRC2012_val_00028187.bin 224 224 +22028 ./prep_dataset/ILSVRC2012_val_00039902.bin 224 224 +22029 ./prep_dataset/ILSVRC2012_val_00044724.bin 224 224 +22030 ./prep_dataset/ILSVRC2012_val_00022891.bin 224 224 +22031 ./prep_dataset/ILSVRC2012_val_00024347.bin 224 224 +22032 ./prep_dataset/ILSVRC2012_val_00040609.bin 224 224 +22033 ./prep_dataset/ILSVRC2012_val_00049428.bin 224 224 +22034 ./prep_dataset/ILSVRC2012_val_00012204.bin 224 224 +22035 ./prep_dataset/ILSVRC2012_val_00021994.bin 224 224 +22036 ./prep_dataset/ILSVRC2012_val_00042008.bin 224 224 +22037 ./prep_dataset/ILSVRC2012_val_00021993.bin 224 224 +22038 ./prep_dataset/ILSVRC2012_val_00009270.bin 224 224 +22039 ./prep_dataset/ILSVRC2012_val_00013326.bin 224 224 +22040 ./prep_dataset/ILSVRC2012_val_00005274.bin 224 224 +22041 ./prep_dataset/ILSVRC2012_val_00033604.bin 224 224 +22042 ./prep_dataset/ILSVRC2012_val_00023424.bin 224 224 +22043 ./prep_dataset/ILSVRC2012_val_00024565.bin 224 224 +22044 ./prep_dataset/ILSVRC2012_val_00021251.bin 224 224 +22045 ./prep_dataset/ILSVRC2012_val_00046260.bin 224 224 +22046 ./prep_dataset/ILSVRC2012_val_00010640.bin 224 224 +22047 ./prep_dataset/ILSVRC2012_val_00011350.bin 224 224 +22048 ./prep_dataset/ILSVRC2012_val_00034004.bin 224 224 +22049 ./prep_dataset/ILSVRC2012_val_00049688.bin 224 224 +22050 ./prep_dataset/ILSVRC2012_val_00003374.bin 224 224 +22051 ./prep_dataset/ILSVRC2012_val_00026379.bin 224 224 +22052 ./prep_dataset/ILSVRC2012_val_00043449.bin 224 224 +22053 ./prep_dataset/ILSVRC2012_val_00035513.bin 224 224 +22054 ./prep_dataset/ILSVRC2012_val_00003155.bin 224 224 +22055 ./prep_dataset/ILSVRC2012_val_00044199.bin 224 224 +22056 ./prep_dataset/ILSVRC2012_val_00041501.bin 224 224 +22057 ./prep_dataset/ILSVRC2012_val_00023777.bin 224 224 +22058 ./prep_dataset/ILSVRC2012_val_00047093.bin 224 224 +22059 ./prep_dataset/ILSVRC2012_val_00029556.bin 224 224 +22060 ./prep_dataset/ILSVRC2012_val_00015790.bin 224 224 +22061 ./prep_dataset/ILSVRC2012_val_00025502.bin 224 224 +22062 ./prep_dataset/ILSVRC2012_val_00045135.bin 224 224 +22063 ./prep_dataset/ILSVRC2012_val_00048161.bin 224 224 +22064 ./prep_dataset/ILSVRC2012_val_00011499.bin 224 224 +22065 ./prep_dataset/ILSVRC2012_val_00038041.bin 224 224 +22066 ./prep_dataset/ILSVRC2012_val_00031306.bin 224 224 +22067 ./prep_dataset/ILSVRC2012_val_00025518.bin 224 224 +22068 ./prep_dataset/ILSVRC2012_val_00001808.bin 224 224 +22069 ./prep_dataset/ILSVRC2012_val_00038504.bin 224 224 +22070 ./prep_dataset/ILSVRC2012_val_00045896.bin 224 224 +22071 ./prep_dataset/ILSVRC2012_val_00016750.bin 224 224 +22072 ./prep_dataset/ILSVRC2012_val_00032967.bin 224 224 +22073 ./prep_dataset/ILSVRC2012_val_00030062.bin 224 224 +22074 ./prep_dataset/ILSVRC2012_val_00047463.bin 224 224 +22075 ./prep_dataset/ILSVRC2012_val_00009206.bin 224 224 +22076 ./prep_dataset/ILSVRC2012_val_00049846.bin 224 224 +22077 ./prep_dataset/ILSVRC2012_val_00023604.bin 224 224 +22078 ./prep_dataset/ILSVRC2012_val_00004932.bin 224 224 +22079 ./prep_dataset/ILSVRC2012_val_00013430.bin 224 224 +22080 ./prep_dataset/ILSVRC2012_val_00017802.bin 224 224 +22081 ./prep_dataset/ILSVRC2012_val_00021673.bin 224 224 +22082 ./prep_dataset/ILSVRC2012_val_00021238.bin 224 224 +22083 ./prep_dataset/ILSVRC2012_val_00018760.bin 224 224 +22084 ./prep_dataset/ILSVRC2012_val_00015994.bin 224 224 +22085 ./prep_dataset/ILSVRC2012_val_00009020.bin 224 224 +22086 ./prep_dataset/ILSVRC2012_val_00042021.bin 224 224 +22087 ./prep_dataset/ILSVRC2012_val_00020105.bin 224 224 +22088 ./prep_dataset/ILSVRC2012_val_00035615.bin 224 224 +22089 ./prep_dataset/ILSVRC2012_val_00012415.bin 224 224 +22090 ./prep_dataset/ILSVRC2012_val_00048057.bin 224 224 +22091 ./prep_dataset/ILSVRC2012_val_00006453.bin 224 224 +22092 ./prep_dataset/ILSVRC2012_val_00016878.bin 224 224 +22093 ./prep_dataset/ILSVRC2012_val_00037570.bin 224 224 +22094 ./prep_dataset/ILSVRC2012_val_00027474.bin 224 224 +22095 ./prep_dataset/ILSVRC2012_val_00026767.bin 224 224 +22096 ./prep_dataset/ILSVRC2012_val_00021454.bin 224 224 +22097 ./prep_dataset/ILSVRC2012_val_00028185.bin 224 224 +22098 ./prep_dataset/ILSVRC2012_val_00003104.bin 224 224 +22099 ./prep_dataset/ILSVRC2012_val_00005534.bin 224 224 +22100 ./prep_dataset/ILSVRC2012_val_00023070.bin 224 224 +22101 ./prep_dataset/ILSVRC2012_val_00007556.bin 224 224 +22102 ./prep_dataset/ILSVRC2012_val_00002273.bin 224 224 +22103 ./prep_dataset/ILSVRC2012_val_00001737.bin 224 224 +22104 ./prep_dataset/ILSVRC2012_val_00001207.bin 224 224 +22105 ./prep_dataset/ILSVRC2012_val_00032736.bin 224 224 +22106 ./prep_dataset/ILSVRC2012_val_00002239.bin 224 224 +22107 ./prep_dataset/ILSVRC2012_val_00037348.bin 224 224 +22108 ./prep_dataset/ILSVRC2012_val_00043004.bin 224 224 +22109 ./prep_dataset/ILSVRC2012_val_00047791.bin 224 224 +22110 ./prep_dataset/ILSVRC2012_val_00036332.bin 224 224 +22111 ./prep_dataset/ILSVRC2012_val_00009459.bin 224 224 +22112 ./prep_dataset/ILSVRC2012_val_00033599.bin 224 224 +22113 ./prep_dataset/ILSVRC2012_val_00008816.bin 224 224 +22114 ./prep_dataset/ILSVRC2012_val_00026968.bin 224 224 +22115 ./prep_dataset/ILSVRC2012_val_00001869.bin 224 224 +22116 ./prep_dataset/ILSVRC2012_val_00043903.bin 224 224 +22117 ./prep_dataset/ILSVRC2012_val_00013490.bin 224 224 +22118 ./prep_dataset/ILSVRC2012_val_00028370.bin 224 224 +22119 ./prep_dataset/ILSVRC2012_val_00044976.bin 224 224 +22120 ./prep_dataset/ILSVRC2012_val_00035966.bin 224 224 +22121 ./prep_dataset/ILSVRC2012_val_00002073.bin 224 224 +22122 ./prep_dataset/ILSVRC2012_val_00002048.bin 224 224 +22123 ./prep_dataset/ILSVRC2012_val_00030346.bin 224 224 +22124 ./prep_dataset/ILSVRC2012_val_00049237.bin 224 224 +22125 ./prep_dataset/ILSVRC2012_val_00013858.bin 224 224 +22126 ./prep_dataset/ILSVRC2012_val_00036531.bin 224 224 +22127 ./prep_dataset/ILSVRC2012_val_00044725.bin 224 224 +22128 ./prep_dataset/ILSVRC2012_val_00011696.bin 224 224 +22129 ./prep_dataset/ILSVRC2012_val_00041793.bin 224 224 +22130 ./prep_dataset/ILSVRC2012_val_00017482.bin 224 224 +22131 ./prep_dataset/ILSVRC2012_val_00008787.bin 224 224 +22132 ./prep_dataset/ILSVRC2012_val_00025202.bin 224 224 +22133 ./prep_dataset/ILSVRC2012_val_00014522.bin 224 224 +22134 ./prep_dataset/ILSVRC2012_val_00049562.bin 224 224 +22135 ./prep_dataset/ILSVRC2012_val_00010767.bin 224 224 +22136 ./prep_dataset/ILSVRC2012_val_00016582.bin 224 224 +22137 ./prep_dataset/ILSVRC2012_val_00026167.bin 224 224 +22138 ./prep_dataset/ILSVRC2012_val_00034305.bin 224 224 +22139 ./prep_dataset/ILSVRC2012_val_00026285.bin 224 224 +22140 ./prep_dataset/ILSVRC2012_val_00041350.bin 224 224 +22141 ./prep_dataset/ILSVRC2012_val_00019077.bin 224 224 +22142 ./prep_dataset/ILSVRC2012_val_00025581.bin 224 224 +22143 ./prep_dataset/ILSVRC2012_val_00036076.bin 224 224 +22144 ./prep_dataset/ILSVRC2012_val_00020937.bin 224 224 +22145 ./prep_dataset/ILSVRC2012_val_00008089.bin 224 224 +22146 ./prep_dataset/ILSVRC2012_val_00047676.bin 224 224 +22147 ./prep_dataset/ILSVRC2012_val_00022637.bin 224 224 +22148 ./prep_dataset/ILSVRC2012_val_00040439.bin 224 224 +22149 ./prep_dataset/ILSVRC2012_val_00008959.bin 224 224 +22150 ./prep_dataset/ILSVRC2012_val_00029601.bin 224 224 +22151 ./prep_dataset/ILSVRC2012_val_00022482.bin 224 224 +22152 ./prep_dataset/ILSVRC2012_val_00046369.bin 224 224 +22153 ./prep_dataset/ILSVRC2012_val_00010893.bin 224 224 +22154 ./prep_dataset/ILSVRC2012_val_00022013.bin 224 224 +22155 ./prep_dataset/ILSVRC2012_val_00001327.bin 224 224 +22156 ./prep_dataset/ILSVRC2012_val_00031520.bin 224 224 +22157 ./prep_dataset/ILSVRC2012_val_00035642.bin 224 224 +22158 ./prep_dataset/ILSVRC2012_val_00035862.bin 224 224 +22159 ./prep_dataset/ILSVRC2012_val_00006128.bin 224 224 +22160 ./prep_dataset/ILSVRC2012_val_00047919.bin 224 224 +22161 ./prep_dataset/ILSVRC2012_val_00006404.bin 224 224 +22162 ./prep_dataset/ILSVRC2012_val_00026797.bin 224 224 +22163 ./prep_dataset/ILSVRC2012_val_00046941.bin 224 224 +22164 ./prep_dataset/ILSVRC2012_val_00002582.bin 224 224 +22165 ./prep_dataset/ILSVRC2012_val_00031991.bin 224 224 +22166 ./prep_dataset/ILSVRC2012_val_00044457.bin 224 224 +22167 ./prep_dataset/ILSVRC2012_val_00014797.bin 224 224 +22168 ./prep_dataset/ILSVRC2012_val_00019219.bin 224 224 +22169 ./prep_dataset/ILSVRC2012_val_00014516.bin 224 224 +22170 ./prep_dataset/ILSVRC2012_val_00047715.bin 224 224 +22171 ./prep_dataset/ILSVRC2012_val_00031547.bin 224 224 +22172 ./prep_dataset/ILSVRC2012_val_00043061.bin 224 224 +22173 ./prep_dataset/ILSVRC2012_val_00034886.bin 224 224 +22174 ./prep_dataset/ILSVRC2012_val_00009874.bin 224 224 +22175 ./prep_dataset/ILSVRC2012_val_00008690.bin 224 224 +22176 ./prep_dataset/ILSVRC2012_val_00044155.bin 224 224 +22177 ./prep_dataset/ILSVRC2012_val_00047592.bin 224 224 +22178 ./prep_dataset/ILSVRC2012_val_00049166.bin 224 224 +22179 ./prep_dataset/ILSVRC2012_val_00005597.bin 224 224 +22180 ./prep_dataset/ILSVRC2012_val_00020691.bin 224 224 +22181 ./prep_dataset/ILSVRC2012_val_00040108.bin 224 224 +22182 ./prep_dataset/ILSVRC2012_val_00012098.bin 224 224 +22183 ./prep_dataset/ILSVRC2012_val_00039753.bin 224 224 +22184 ./prep_dataset/ILSVRC2012_val_00049203.bin 224 224 +22185 ./prep_dataset/ILSVRC2012_val_00022694.bin 224 224 +22186 ./prep_dataset/ILSVRC2012_val_00030452.bin 224 224 +22187 ./prep_dataset/ILSVRC2012_val_00007977.bin 224 224 +22188 ./prep_dataset/ILSVRC2012_val_00005979.bin 224 224 +22189 ./prep_dataset/ILSVRC2012_val_00025788.bin 224 224 +22190 ./prep_dataset/ILSVRC2012_val_00030568.bin 224 224 +22191 ./prep_dataset/ILSVRC2012_val_00030360.bin 224 224 +22192 ./prep_dataset/ILSVRC2012_val_00042247.bin 224 224 +22193 ./prep_dataset/ILSVRC2012_val_00047584.bin 224 224 +22194 ./prep_dataset/ILSVRC2012_val_00047703.bin 224 224 +22195 ./prep_dataset/ILSVRC2012_val_00016315.bin 224 224 +22196 ./prep_dataset/ILSVRC2012_val_00037969.bin 224 224 +22197 ./prep_dataset/ILSVRC2012_val_00027925.bin 224 224 +22198 ./prep_dataset/ILSVRC2012_val_00029757.bin 224 224 +22199 ./prep_dataset/ILSVRC2012_val_00022070.bin 224 224 +22200 ./prep_dataset/ILSVRC2012_val_00001826.bin 224 224 +22201 ./prep_dataset/ILSVRC2012_val_00007995.bin 224 224 +22202 ./prep_dataset/ILSVRC2012_val_00008241.bin 224 224 +22203 ./prep_dataset/ILSVRC2012_val_00044909.bin 224 224 +22204 ./prep_dataset/ILSVRC2012_val_00019574.bin 224 224 +22205 ./prep_dataset/ILSVRC2012_val_00013166.bin 224 224 +22206 ./prep_dataset/ILSVRC2012_val_00013510.bin 224 224 +22207 ./prep_dataset/ILSVRC2012_val_00049642.bin 224 224 +22208 ./prep_dataset/ILSVRC2012_val_00023788.bin 224 224 +22209 ./prep_dataset/ILSVRC2012_val_00024778.bin 224 224 +22210 ./prep_dataset/ILSVRC2012_val_00013517.bin 224 224 +22211 ./prep_dataset/ILSVRC2012_val_00024886.bin 224 224 +22212 ./prep_dataset/ILSVRC2012_val_00042007.bin 224 224 +22213 ./prep_dataset/ILSVRC2012_val_00027493.bin 224 224 +22214 ./prep_dataset/ILSVRC2012_val_00019775.bin 224 224 +22215 ./prep_dataset/ILSVRC2012_val_00002762.bin 224 224 +22216 ./prep_dataset/ILSVRC2012_val_00028779.bin 224 224 +22217 ./prep_dataset/ILSVRC2012_val_00040975.bin 224 224 +22218 ./prep_dataset/ILSVRC2012_val_00048808.bin 224 224 +22219 ./prep_dataset/ILSVRC2012_val_00019973.bin 224 224 +22220 ./prep_dataset/ILSVRC2012_val_00008335.bin 224 224 +22221 ./prep_dataset/ILSVRC2012_val_00030554.bin 224 224 +22222 ./prep_dataset/ILSVRC2012_val_00024505.bin 224 224 +22223 ./prep_dataset/ILSVRC2012_val_00044110.bin 224 224 +22224 ./prep_dataset/ILSVRC2012_val_00044876.bin 224 224 +22225 ./prep_dataset/ILSVRC2012_val_00016163.bin 224 224 +22226 ./prep_dataset/ILSVRC2012_val_00007911.bin 224 224 +22227 ./prep_dataset/ILSVRC2012_val_00009749.bin 224 224 +22228 ./prep_dataset/ILSVRC2012_val_00005379.bin 224 224 +22229 ./prep_dataset/ILSVRC2012_val_00046325.bin 224 224 +22230 ./prep_dataset/ILSVRC2012_val_00040208.bin 224 224 +22231 ./prep_dataset/ILSVRC2012_val_00000480.bin 224 224 +22232 ./prep_dataset/ILSVRC2012_val_00039840.bin 224 224 +22233 ./prep_dataset/ILSVRC2012_val_00003461.bin 224 224 +22234 ./prep_dataset/ILSVRC2012_val_00032556.bin 224 224 +22235 ./prep_dataset/ILSVRC2012_val_00017441.bin 224 224 +22236 ./prep_dataset/ILSVRC2012_val_00012190.bin 224 224 +22237 ./prep_dataset/ILSVRC2012_val_00026864.bin 224 224 +22238 ./prep_dataset/ILSVRC2012_val_00012189.bin 224 224 +22239 ./prep_dataset/ILSVRC2012_val_00017415.bin 224 224 +22240 ./prep_dataset/ILSVRC2012_val_00036424.bin 224 224 +22241 ./prep_dataset/ILSVRC2012_val_00014099.bin 224 224 +22242 ./prep_dataset/ILSVRC2012_val_00039251.bin 224 224 +22243 ./prep_dataset/ILSVRC2012_val_00008374.bin 224 224 +22244 ./prep_dataset/ILSVRC2012_val_00017281.bin 224 224 +22245 ./prep_dataset/ILSVRC2012_val_00048706.bin 224 224 +22246 ./prep_dataset/ILSVRC2012_val_00030535.bin 224 224 +22247 ./prep_dataset/ILSVRC2012_val_00012732.bin 224 224 +22248 ./prep_dataset/ILSVRC2012_val_00039035.bin 224 224 +22249 ./prep_dataset/ILSVRC2012_val_00004412.bin 224 224 +22250 ./prep_dataset/ILSVRC2012_val_00044106.bin 224 224 +22251 ./prep_dataset/ILSVRC2012_val_00029349.bin 224 224 +22252 ./prep_dataset/ILSVRC2012_val_00014617.bin 224 224 +22253 ./prep_dataset/ILSVRC2012_val_00025223.bin 224 224 +22254 ./prep_dataset/ILSVRC2012_val_00012955.bin 224 224 +22255 ./prep_dataset/ILSVRC2012_val_00006504.bin 224 224 +22256 ./prep_dataset/ILSVRC2012_val_00017567.bin 224 224 +22257 ./prep_dataset/ILSVRC2012_val_00028443.bin 224 224 +22258 ./prep_dataset/ILSVRC2012_val_00024508.bin 224 224 +22259 ./prep_dataset/ILSVRC2012_val_00043171.bin 224 224 +22260 ./prep_dataset/ILSVRC2012_val_00038767.bin 224 224 +22261 ./prep_dataset/ILSVRC2012_val_00029825.bin 224 224 +22262 ./prep_dataset/ILSVRC2012_val_00007871.bin 224 224 +22263 ./prep_dataset/ILSVRC2012_val_00020515.bin 224 224 +22264 ./prep_dataset/ILSVRC2012_val_00043440.bin 224 224 +22265 ./prep_dataset/ILSVRC2012_val_00045076.bin 224 224 +22266 ./prep_dataset/ILSVRC2012_val_00009534.bin 224 224 +22267 ./prep_dataset/ILSVRC2012_val_00041261.bin 224 224 +22268 ./prep_dataset/ILSVRC2012_val_00006195.bin 224 224 +22269 ./prep_dataset/ILSVRC2012_val_00009570.bin 224 224 +22270 ./prep_dataset/ILSVRC2012_val_00043042.bin 224 224 +22271 ./prep_dataset/ILSVRC2012_val_00017800.bin 224 224 +22272 ./prep_dataset/ILSVRC2012_val_00027804.bin 224 224 +22273 ./prep_dataset/ILSVRC2012_val_00042506.bin 224 224 +22274 ./prep_dataset/ILSVRC2012_val_00043289.bin 224 224 +22275 ./prep_dataset/ILSVRC2012_val_00044488.bin 224 224 +22276 ./prep_dataset/ILSVRC2012_val_00000404.bin 224 224 +22277 ./prep_dataset/ILSVRC2012_val_00016744.bin 224 224 +22278 ./prep_dataset/ILSVRC2012_val_00014728.bin 224 224 +22279 ./prep_dataset/ILSVRC2012_val_00014297.bin 224 224 +22280 ./prep_dataset/ILSVRC2012_val_00023936.bin 224 224 +22281 ./prep_dataset/ILSVRC2012_val_00019785.bin 224 224 +22282 ./prep_dataset/ILSVRC2012_val_00031267.bin 224 224 +22283 ./prep_dataset/ILSVRC2012_val_00046191.bin 224 224 +22284 ./prep_dataset/ILSVRC2012_val_00014268.bin 224 224 +22285 ./prep_dataset/ILSVRC2012_val_00009122.bin 224 224 +22286 ./prep_dataset/ILSVRC2012_val_00043940.bin 224 224 +22287 ./prep_dataset/ILSVRC2012_val_00014296.bin 224 224 +22288 ./prep_dataset/ILSVRC2012_val_00037574.bin 224 224 +22289 ./prep_dataset/ILSVRC2012_val_00025322.bin 224 224 +22290 ./prep_dataset/ILSVRC2012_val_00035094.bin 224 224 +22291 ./prep_dataset/ILSVRC2012_val_00035326.bin 224 224 +22292 ./prep_dataset/ILSVRC2012_val_00008989.bin 224 224 +22293 ./prep_dataset/ILSVRC2012_val_00025638.bin 224 224 +22294 ./prep_dataset/ILSVRC2012_val_00042950.bin 224 224 +22295 ./prep_dataset/ILSVRC2012_val_00040374.bin 224 224 +22296 ./prep_dataset/ILSVRC2012_val_00003302.bin 224 224 +22297 ./prep_dataset/ILSVRC2012_val_00025053.bin 224 224 +22298 ./prep_dataset/ILSVRC2012_val_00040765.bin 224 224 +22299 ./prep_dataset/ILSVRC2012_val_00039833.bin 224 224 +22300 ./prep_dataset/ILSVRC2012_val_00022662.bin 224 224 +22301 ./prep_dataset/ILSVRC2012_val_00003560.bin 224 224 +22302 ./prep_dataset/ILSVRC2012_val_00033744.bin 224 224 +22303 ./prep_dataset/ILSVRC2012_val_00015096.bin 224 224 +22304 ./prep_dataset/ILSVRC2012_val_00027229.bin 224 224 +22305 ./prep_dataset/ILSVRC2012_val_00035055.bin 224 224 +22306 ./prep_dataset/ILSVRC2012_val_00033247.bin 224 224 +22307 ./prep_dataset/ILSVRC2012_val_00004046.bin 224 224 +22308 ./prep_dataset/ILSVRC2012_val_00001943.bin 224 224 +22309 ./prep_dataset/ILSVRC2012_val_00042665.bin 224 224 +22310 ./prep_dataset/ILSVRC2012_val_00015131.bin 224 224 +22311 ./prep_dataset/ILSVRC2012_val_00000821.bin 224 224 +22312 ./prep_dataset/ILSVRC2012_val_00000270.bin 224 224 +22313 ./prep_dataset/ILSVRC2012_val_00022959.bin 224 224 +22314 ./prep_dataset/ILSVRC2012_val_00039228.bin 224 224 +22315 ./prep_dataset/ILSVRC2012_val_00007055.bin 224 224 +22316 ./prep_dataset/ILSVRC2012_val_00024963.bin 224 224 +22317 ./prep_dataset/ILSVRC2012_val_00010860.bin 224 224 +22318 ./prep_dataset/ILSVRC2012_val_00024697.bin 224 224 +22319 ./prep_dataset/ILSVRC2012_val_00000352.bin 224 224 +22320 ./prep_dataset/ILSVRC2012_val_00004164.bin 224 224 +22321 ./prep_dataset/ILSVRC2012_val_00007790.bin 224 224 +22322 ./prep_dataset/ILSVRC2012_val_00021908.bin 224 224 +22323 ./prep_dataset/ILSVRC2012_val_00013320.bin 224 224 +22324 ./prep_dataset/ILSVRC2012_val_00019022.bin 224 224 +22325 ./prep_dataset/ILSVRC2012_val_00015447.bin 224 224 +22326 ./prep_dataset/ILSVRC2012_val_00001021.bin 224 224 +22327 ./prep_dataset/ILSVRC2012_val_00032994.bin 224 224 +22328 ./prep_dataset/ILSVRC2012_val_00007591.bin 224 224 +22329 ./prep_dataset/ILSVRC2012_val_00035671.bin 224 224 +22330 ./prep_dataset/ILSVRC2012_val_00004078.bin 224 224 +22331 ./prep_dataset/ILSVRC2012_val_00011823.bin 224 224 +22332 ./prep_dataset/ILSVRC2012_val_00005664.bin 224 224 +22333 ./prep_dataset/ILSVRC2012_val_00039274.bin 224 224 +22334 ./prep_dataset/ILSVRC2012_val_00024665.bin 224 224 +22335 ./prep_dataset/ILSVRC2012_val_00049129.bin 224 224 +22336 ./prep_dataset/ILSVRC2012_val_00035476.bin 224 224 +22337 ./prep_dataset/ILSVRC2012_val_00048589.bin 224 224 +22338 ./prep_dataset/ILSVRC2012_val_00049870.bin 224 224 +22339 ./prep_dataset/ILSVRC2012_val_00027755.bin 224 224 +22340 ./prep_dataset/ILSVRC2012_val_00029129.bin 224 224 +22341 ./prep_dataset/ILSVRC2012_val_00045954.bin 224 224 +22342 ./prep_dataset/ILSVRC2012_val_00002659.bin 224 224 +22343 ./prep_dataset/ILSVRC2012_val_00021599.bin 224 224 +22344 ./prep_dataset/ILSVRC2012_val_00041630.bin 224 224 +22345 ./prep_dataset/ILSVRC2012_val_00013790.bin 224 224 +22346 ./prep_dataset/ILSVRC2012_val_00037096.bin 224 224 +22347 ./prep_dataset/ILSVRC2012_val_00030701.bin 224 224 +22348 ./prep_dataset/ILSVRC2012_val_00047624.bin 224 224 +22349 ./prep_dataset/ILSVRC2012_val_00018553.bin 224 224 +22350 ./prep_dataset/ILSVRC2012_val_00011756.bin 224 224 +22351 ./prep_dataset/ILSVRC2012_val_00012993.bin 224 224 +22352 ./prep_dataset/ILSVRC2012_val_00037114.bin 224 224 +22353 ./prep_dataset/ILSVRC2012_val_00004469.bin 224 224 +22354 ./prep_dataset/ILSVRC2012_val_00003743.bin 224 224 +22355 ./prep_dataset/ILSVRC2012_val_00011309.bin 224 224 +22356 ./prep_dataset/ILSVRC2012_val_00030096.bin 224 224 +22357 ./prep_dataset/ILSVRC2012_val_00007786.bin 224 224 +22358 ./prep_dataset/ILSVRC2012_val_00044589.bin 224 224 +22359 ./prep_dataset/ILSVRC2012_val_00033539.bin 224 224 +22360 ./prep_dataset/ILSVRC2012_val_00027055.bin 224 224 +22361 ./prep_dataset/ILSVRC2012_val_00019134.bin 224 224 +22362 ./prep_dataset/ILSVRC2012_val_00017755.bin 224 224 +22363 ./prep_dataset/ILSVRC2012_val_00020398.bin 224 224 +22364 ./prep_dataset/ILSVRC2012_val_00025596.bin 224 224 +22365 ./prep_dataset/ILSVRC2012_val_00007067.bin 224 224 +22366 ./prep_dataset/ILSVRC2012_val_00036682.bin 224 224 +22367 ./prep_dataset/ILSVRC2012_val_00002968.bin 224 224 +22368 ./prep_dataset/ILSVRC2012_val_00023464.bin 224 224 +22369 ./prep_dataset/ILSVRC2012_val_00028557.bin 224 224 +22370 ./prep_dataset/ILSVRC2012_val_00015301.bin 224 224 +22371 ./prep_dataset/ILSVRC2012_val_00004243.bin 224 224 +22372 ./prep_dataset/ILSVRC2012_val_00031987.bin 224 224 +22373 ./prep_dataset/ILSVRC2012_val_00031356.bin 224 224 +22374 ./prep_dataset/ILSVRC2012_val_00038757.bin 224 224 +22375 ./prep_dataset/ILSVRC2012_val_00006662.bin 224 224 +22376 ./prep_dataset/ILSVRC2012_val_00006327.bin 224 224 +22377 ./prep_dataset/ILSVRC2012_val_00020087.bin 224 224 +22378 ./prep_dataset/ILSVRC2012_val_00008573.bin 224 224 +22379 ./prep_dataset/ILSVRC2012_val_00021817.bin 224 224 +22380 ./prep_dataset/ILSVRC2012_val_00038446.bin 224 224 +22381 ./prep_dataset/ILSVRC2012_val_00028068.bin 224 224 +22382 ./prep_dataset/ILSVRC2012_val_00010103.bin 224 224 +22383 ./prep_dataset/ILSVRC2012_val_00024652.bin 224 224 +22384 ./prep_dataset/ILSVRC2012_val_00015893.bin 224 224 +22385 ./prep_dataset/ILSVRC2012_val_00004488.bin 224 224 +22386 ./prep_dataset/ILSVRC2012_val_00045861.bin 224 224 +22387 ./prep_dataset/ILSVRC2012_val_00035692.bin 224 224 +22388 ./prep_dataset/ILSVRC2012_val_00039636.bin 224 224 +22389 ./prep_dataset/ILSVRC2012_val_00020811.bin 224 224 +22390 ./prep_dataset/ILSVRC2012_val_00016255.bin 224 224 +22391 ./prep_dataset/ILSVRC2012_val_00032250.bin 224 224 +22392 ./prep_dataset/ILSVRC2012_val_00034393.bin 224 224 +22393 ./prep_dataset/ILSVRC2012_val_00046689.bin 224 224 +22394 ./prep_dataset/ILSVRC2012_val_00012078.bin 224 224 +22395 ./prep_dataset/ILSVRC2012_val_00025506.bin 224 224 +22396 ./prep_dataset/ILSVRC2012_val_00045651.bin 224 224 +22397 ./prep_dataset/ILSVRC2012_val_00011857.bin 224 224 +22398 ./prep_dataset/ILSVRC2012_val_00009374.bin 224 224 +22399 ./prep_dataset/ILSVRC2012_val_00031801.bin 224 224 +22400 ./prep_dataset/ILSVRC2012_val_00047690.bin 224 224 +22401 ./prep_dataset/ILSVRC2012_val_00045527.bin 224 224 +22402 ./prep_dataset/ILSVRC2012_val_00007410.bin 224 224 +22403 ./prep_dataset/ILSVRC2012_val_00034675.bin 224 224 +22404 ./prep_dataset/ILSVRC2012_val_00019659.bin 224 224 +22405 ./prep_dataset/ILSVRC2012_val_00034911.bin 224 224 +22406 ./prep_dataset/ILSVRC2012_val_00023192.bin 224 224 +22407 ./prep_dataset/ILSVRC2012_val_00031634.bin 224 224 +22408 ./prep_dataset/ILSVRC2012_val_00034433.bin 224 224 +22409 ./prep_dataset/ILSVRC2012_val_00025911.bin 224 224 +22410 ./prep_dataset/ILSVRC2012_val_00001023.bin 224 224 +22411 ./prep_dataset/ILSVRC2012_val_00040388.bin 224 224 +22412 ./prep_dataset/ILSVRC2012_val_00049385.bin 224 224 +22413 ./prep_dataset/ILSVRC2012_val_00042596.bin 224 224 +22414 ./prep_dataset/ILSVRC2012_val_00009999.bin 224 224 +22415 ./prep_dataset/ILSVRC2012_val_00039120.bin 224 224 +22416 ./prep_dataset/ILSVRC2012_val_00004241.bin 224 224 +22417 ./prep_dataset/ILSVRC2012_val_00044019.bin 224 224 +22418 ./prep_dataset/ILSVRC2012_val_00005072.bin 224 224 +22419 ./prep_dataset/ILSVRC2012_val_00002660.bin 224 224 +22420 ./prep_dataset/ILSVRC2012_val_00020242.bin 224 224 +22421 ./prep_dataset/ILSVRC2012_val_00049038.bin 224 224 +22422 ./prep_dataset/ILSVRC2012_val_00044580.bin 224 224 +22423 ./prep_dataset/ILSVRC2012_val_00018793.bin 224 224 +22424 ./prep_dataset/ILSVRC2012_val_00031552.bin 224 224 +22425 ./prep_dataset/ILSVRC2012_val_00005654.bin 224 224 +22426 ./prep_dataset/ILSVRC2012_val_00045606.bin 224 224 +22427 ./prep_dataset/ILSVRC2012_val_00029043.bin 224 224 +22428 ./prep_dataset/ILSVRC2012_val_00002472.bin 224 224 +22429 ./prep_dataset/ILSVRC2012_val_00042566.bin 224 224 +22430 ./prep_dataset/ILSVRC2012_val_00040515.bin 224 224 +22431 ./prep_dataset/ILSVRC2012_val_00040989.bin 224 224 +22432 ./prep_dataset/ILSVRC2012_val_00038165.bin 224 224 +22433 ./prep_dataset/ILSVRC2012_val_00047655.bin 224 224 +22434 ./prep_dataset/ILSVRC2012_val_00043326.bin 224 224 +22435 ./prep_dataset/ILSVRC2012_val_00001528.bin 224 224 +22436 ./prep_dataset/ILSVRC2012_val_00037711.bin 224 224 +22437 ./prep_dataset/ILSVRC2012_val_00021617.bin 224 224 +22438 ./prep_dataset/ILSVRC2012_val_00011224.bin 224 224 +22439 ./prep_dataset/ILSVRC2012_val_00004147.bin 224 224 +22440 ./prep_dataset/ILSVRC2012_val_00037490.bin 224 224 +22441 ./prep_dataset/ILSVRC2012_val_00006616.bin 224 224 +22442 ./prep_dataset/ILSVRC2012_val_00016601.bin 224 224 +22443 ./prep_dataset/ILSVRC2012_val_00007757.bin 224 224 +22444 ./prep_dataset/ILSVRC2012_val_00047432.bin 224 224 +22445 ./prep_dataset/ILSVRC2012_val_00025937.bin 224 224 +22446 ./prep_dataset/ILSVRC2012_val_00014111.bin 224 224 +22447 ./prep_dataset/ILSVRC2012_val_00018957.bin 224 224 +22448 ./prep_dataset/ILSVRC2012_val_00046723.bin 224 224 +22449 ./prep_dataset/ILSVRC2012_val_00019443.bin 224 224 +22450 ./prep_dataset/ILSVRC2012_val_00014903.bin 224 224 +22451 ./prep_dataset/ILSVRC2012_val_00048743.bin 224 224 +22452 ./prep_dataset/ILSVRC2012_val_00030968.bin 224 224 +22453 ./prep_dataset/ILSVRC2012_val_00041439.bin 224 224 +22454 ./prep_dataset/ILSVRC2012_val_00016034.bin 224 224 +22455 ./prep_dataset/ILSVRC2012_val_00039115.bin 224 224 +22456 ./prep_dataset/ILSVRC2012_val_00039507.bin 224 224 +22457 ./prep_dataset/ILSVRC2012_val_00049013.bin 224 224 +22458 ./prep_dataset/ILSVRC2012_val_00019774.bin 224 224 +22459 ./prep_dataset/ILSVRC2012_val_00049709.bin 224 224 +22460 ./prep_dataset/ILSVRC2012_val_00044120.bin 224 224 +22461 ./prep_dataset/ILSVRC2012_val_00020386.bin 224 224 +22462 ./prep_dataset/ILSVRC2012_val_00028639.bin 224 224 +22463 ./prep_dataset/ILSVRC2012_val_00047915.bin 224 224 +22464 ./prep_dataset/ILSVRC2012_val_00024568.bin 224 224 +22465 ./prep_dataset/ILSVRC2012_val_00008691.bin 224 224 +22466 ./prep_dataset/ILSVRC2012_val_00017543.bin 224 224 +22467 ./prep_dataset/ILSVRC2012_val_00041086.bin 224 224 +22468 ./prep_dataset/ILSVRC2012_val_00041516.bin 224 224 +22469 ./prep_dataset/ILSVRC2012_val_00008840.bin 224 224 +22470 ./prep_dataset/ILSVRC2012_val_00040489.bin 224 224 +22471 ./prep_dataset/ILSVRC2012_val_00035849.bin 224 224 +22472 ./prep_dataset/ILSVRC2012_val_00043570.bin 224 224 +22473 ./prep_dataset/ILSVRC2012_val_00049904.bin 224 224 +22474 ./prep_dataset/ILSVRC2012_val_00001597.bin 224 224 +22475 ./prep_dataset/ILSVRC2012_val_00033114.bin 224 224 +22476 ./prep_dataset/ILSVRC2012_val_00012447.bin 224 224 +22477 ./prep_dataset/ILSVRC2012_val_00005995.bin 224 224 +22478 ./prep_dataset/ILSVRC2012_val_00004080.bin 224 224 +22479 ./prep_dataset/ILSVRC2012_val_00028734.bin 224 224 +22480 ./prep_dataset/ILSVRC2012_val_00003909.bin 224 224 +22481 ./prep_dataset/ILSVRC2012_val_00005562.bin 224 224 +22482 ./prep_dataset/ILSVRC2012_val_00040863.bin 224 224 +22483 ./prep_dataset/ILSVRC2012_val_00047440.bin 224 224 +22484 ./prep_dataset/ILSVRC2012_val_00001132.bin 224 224 +22485 ./prep_dataset/ILSVRC2012_val_00021639.bin 224 224 +22486 ./prep_dataset/ILSVRC2012_val_00043089.bin 224 224 +22487 ./prep_dataset/ILSVRC2012_val_00041447.bin 224 224 +22488 ./prep_dataset/ILSVRC2012_val_00005727.bin 224 224 +22489 ./prep_dataset/ILSVRC2012_val_00026619.bin 224 224 +22490 ./prep_dataset/ILSVRC2012_val_00025714.bin 224 224 +22491 ./prep_dataset/ILSVRC2012_val_00015487.bin 224 224 +22492 ./prep_dataset/ILSVRC2012_val_00030104.bin 224 224 +22493 ./prep_dataset/ILSVRC2012_val_00028941.bin 224 224 +22494 ./prep_dataset/ILSVRC2012_val_00044429.bin 224 224 +22495 ./prep_dataset/ILSVRC2012_val_00028534.bin 224 224 +22496 ./prep_dataset/ILSVRC2012_val_00010999.bin 224 224 +22497 ./prep_dataset/ILSVRC2012_val_00044231.bin 224 224 +22498 ./prep_dataset/ILSVRC2012_val_00012628.bin 224 224 +22499 ./prep_dataset/ILSVRC2012_val_00019788.bin 224 224 +22500 ./prep_dataset/ILSVRC2012_val_00046313.bin 224 224 +22501 ./prep_dataset/ILSVRC2012_val_00006564.bin 224 224 +22502 ./prep_dataset/ILSVRC2012_val_00009980.bin 224 224 +22503 ./prep_dataset/ILSVRC2012_val_00007106.bin 224 224 +22504 ./prep_dataset/ILSVRC2012_val_00044062.bin 224 224 +22505 ./prep_dataset/ILSVRC2012_val_00012709.bin 224 224 +22506 ./prep_dataset/ILSVRC2012_val_00010269.bin 224 224 +22507 ./prep_dataset/ILSVRC2012_val_00012858.bin 224 224 +22508 ./prep_dataset/ILSVRC2012_val_00010633.bin 224 224 +22509 ./prep_dataset/ILSVRC2012_val_00006091.bin 224 224 +22510 ./prep_dataset/ILSVRC2012_val_00031258.bin 224 224 +22511 ./prep_dataset/ILSVRC2012_val_00010600.bin 224 224 +22512 ./prep_dataset/ILSVRC2012_val_00000525.bin 224 224 +22513 ./prep_dataset/ILSVRC2012_val_00038937.bin 224 224 +22514 ./prep_dataset/ILSVRC2012_val_00000817.bin 224 224 +22515 ./prep_dataset/ILSVRC2012_val_00004519.bin 224 224 +22516 ./prep_dataset/ILSVRC2012_val_00005085.bin 224 224 +22517 ./prep_dataset/ILSVRC2012_val_00042398.bin 224 224 +22518 ./prep_dataset/ILSVRC2012_val_00036476.bin 224 224 +22519 ./prep_dataset/ILSVRC2012_val_00039015.bin 224 224 +22520 ./prep_dataset/ILSVRC2012_val_00013689.bin 224 224 +22521 ./prep_dataset/ILSVRC2012_val_00006064.bin 224 224 +22522 ./prep_dataset/ILSVRC2012_val_00001529.bin 224 224 +22523 ./prep_dataset/ILSVRC2012_val_00043036.bin 224 224 +22524 ./prep_dataset/ILSVRC2012_val_00036331.bin 224 224 +22525 ./prep_dataset/ILSVRC2012_val_00046428.bin 224 224 +22526 ./prep_dataset/ILSVRC2012_val_00036195.bin 224 224 +22527 ./prep_dataset/ILSVRC2012_val_00022267.bin 224 224 +22528 ./prep_dataset/ILSVRC2012_val_00040445.bin 224 224 +22529 ./prep_dataset/ILSVRC2012_val_00043242.bin 224 224 +22530 ./prep_dataset/ILSVRC2012_val_00043265.bin 224 224 +22531 ./prep_dataset/ILSVRC2012_val_00035593.bin 224 224 +22532 ./prep_dataset/ILSVRC2012_val_00022223.bin 224 224 +22533 ./prep_dataset/ILSVRC2012_val_00005369.bin 224 224 +22534 ./prep_dataset/ILSVRC2012_val_00002416.bin 224 224 +22535 ./prep_dataset/ILSVRC2012_val_00003342.bin 224 224 +22536 ./prep_dataset/ILSVRC2012_val_00037185.bin 224 224 +22537 ./prep_dataset/ILSVRC2012_val_00041942.bin 224 224 +22538 ./prep_dataset/ILSVRC2012_val_00041273.bin 224 224 +22539 ./prep_dataset/ILSVRC2012_val_00015559.bin 224 224 +22540 ./prep_dataset/ILSVRC2012_val_00027320.bin 224 224 +22541 ./prep_dataset/ILSVRC2012_val_00001757.bin 224 224 +22542 ./prep_dataset/ILSVRC2012_val_00001632.bin 224 224 +22543 ./prep_dataset/ILSVRC2012_val_00007870.bin 224 224 +22544 ./prep_dataset/ILSVRC2012_val_00015973.bin 224 224 +22545 ./prep_dataset/ILSVRC2012_val_00047522.bin 224 224 +22546 ./prep_dataset/ILSVRC2012_val_00028616.bin 224 224 +22547 ./prep_dataset/ILSVRC2012_val_00006566.bin 224 224 +22548 ./prep_dataset/ILSVRC2012_val_00002977.bin 224 224 +22549 ./prep_dataset/ILSVRC2012_val_00037725.bin 224 224 +22550 ./prep_dataset/ILSVRC2012_val_00042298.bin 224 224 +22551 ./prep_dataset/ILSVRC2012_val_00019228.bin 224 224 +22552 ./prep_dataset/ILSVRC2012_val_00020626.bin 224 224 +22553 ./prep_dataset/ILSVRC2012_val_00047839.bin 224 224 +22554 ./prep_dataset/ILSVRC2012_val_00009009.bin 224 224 +22555 ./prep_dataset/ILSVRC2012_val_00008272.bin 224 224 +22556 ./prep_dataset/ILSVRC2012_val_00026236.bin 224 224 +22557 ./prep_dataset/ILSVRC2012_val_00044701.bin 224 224 +22558 ./prep_dataset/ILSVRC2012_val_00049297.bin 224 224 +22559 ./prep_dataset/ILSVRC2012_val_00049763.bin 224 224 +22560 ./prep_dataset/ILSVRC2012_val_00001829.bin 224 224 +22561 ./prep_dataset/ILSVRC2012_val_00009734.bin 224 224 +22562 ./prep_dataset/ILSVRC2012_val_00023427.bin 224 224 +22563 ./prep_dataset/ILSVRC2012_val_00036772.bin 224 224 +22564 ./prep_dataset/ILSVRC2012_val_00023132.bin 224 224 +22565 ./prep_dataset/ILSVRC2012_val_00008053.bin 224 224 +22566 ./prep_dataset/ILSVRC2012_val_00021805.bin 224 224 +22567 ./prep_dataset/ILSVRC2012_val_00002379.bin 224 224 +22568 ./prep_dataset/ILSVRC2012_val_00028765.bin 224 224 +22569 ./prep_dataset/ILSVRC2012_val_00010334.bin 224 224 +22570 ./prep_dataset/ILSVRC2012_val_00040440.bin 224 224 +22571 ./prep_dataset/ILSVRC2012_val_00019719.bin 224 224 +22572 ./prep_dataset/ILSVRC2012_val_00017159.bin 224 224 +22573 ./prep_dataset/ILSVRC2012_val_00024618.bin 224 224 +22574 ./prep_dataset/ILSVRC2012_val_00007770.bin 224 224 +22575 ./prep_dataset/ILSVRC2012_val_00004270.bin 224 224 +22576 ./prep_dataset/ILSVRC2012_val_00049811.bin 224 224 +22577 ./prep_dataset/ILSVRC2012_val_00047533.bin 224 224 +22578 ./prep_dataset/ILSVRC2012_val_00030896.bin 224 224 +22579 ./prep_dataset/ILSVRC2012_val_00041187.bin 224 224 +22580 ./prep_dataset/ILSVRC2012_val_00037041.bin 224 224 +22581 ./prep_dataset/ILSVRC2012_val_00007611.bin 224 224 +22582 ./prep_dataset/ILSVRC2012_val_00002573.bin 224 224 +22583 ./prep_dataset/ILSVRC2012_val_00004190.bin 224 224 +22584 ./prep_dataset/ILSVRC2012_val_00043560.bin 224 224 +22585 ./prep_dataset/ILSVRC2012_val_00013734.bin 224 224 +22586 ./prep_dataset/ILSVRC2012_val_00039307.bin 224 224 +22587 ./prep_dataset/ILSVRC2012_val_00015691.bin 224 224 +22588 ./prep_dataset/ILSVRC2012_val_00023345.bin 224 224 +22589 ./prep_dataset/ILSVRC2012_val_00040052.bin 224 224 +22590 ./prep_dataset/ILSVRC2012_val_00019924.bin 224 224 +22591 ./prep_dataset/ILSVRC2012_val_00020250.bin 224 224 +22592 ./prep_dataset/ILSVRC2012_val_00019338.bin 224 224 +22593 ./prep_dataset/ILSVRC2012_val_00047234.bin 224 224 +22594 ./prep_dataset/ILSVRC2012_val_00048229.bin 224 224 +22595 ./prep_dataset/ILSVRC2012_val_00015727.bin 224 224 +22596 ./prep_dataset/ILSVRC2012_val_00015300.bin 224 224 +22597 ./prep_dataset/ILSVRC2012_val_00019258.bin 224 224 +22598 ./prep_dataset/ILSVRC2012_val_00016431.bin 224 224 +22599 ./prep_dataset/ILSVRC2012_val_00009129.bin 224 224 +22600 ./prep_dataset/ILSVRC2012_val_00009234.bin 224 224 +22601 ./prep_dataset/ILSVRC2012_val_00020631.bin 224 224 +22602 ./prep_dataset/ILSVRC2012_val_00004134.bin 224 224 +22603 ./prep_dataset/ILSVRC2012_val_00040685.bin 224 224 +22604 ./prep_dataset/ILSVRC2012_val_00004859.bin 224 224 +22605 ./prep_dataset/ILSVRC2012_val_00003750.bin 224 224 +22606 ./prep_dataset/ILSVRC2012_val_00022137.bin 224 224 +22607 ./prep_dataset/ILSVRC2012_val_00028550.bin 224 224 +22608 ./prep_dataset/ILSVRC2012_val_00049933.bin 224 224 +22609 ./prep_dataset/ILSVRC2012_val_00027674.bin 224 224 +22610 ./prep_dataset/ILSVRC2012_val_00041481.bin 224 224 +22611 ./prep_dataset/ILSVRC2012_val_00015153.bin 224 224 +22612 ./prep_dataset/ILSVRC2012_val_00025521.bin 224 224 +22613 ./prep_dataset/ILSVRC2012_val_00030312.bin 224 224 +22614 ./prep_dataset/ILSVRC2012_val_00037920.bin 224 224 +22615 ./prep_dataset/ILSVRC2012_val_00029473.bin 224 224 +22616 ./prep_dataset/ILSVRC2012_val_00014983.bin 224 224 +22617 ./prep_dataset/ILSVRC2012_val_00023421.bin 224 224 +22618 ./prep_dataset/ILSVRC2012_val_00030628.bin 224 224 +22619 ./prep_dataset/ILSVRC2012_val_00025886.bin 224 224 +22620 ./prep_dataset/ILSVRC2012_val_00006452.bin 224 224 +22621 ./prep_dataset/ILSVRC2012_val_00044046.bin 224 224 +22622 ./prep_dataset/ILSVRC2012_val_00015048.bin 224 224 +22623 ./prep_dataset/ILSVRC2012_val_00041411.bin 224 224 +22624 ./prep_dataset/ILSVRC2012_val_00040654.bin 224 224 +22625 ./prep_dataset/ILSVRC2012_val_00021159.bin 224 224 +22626 ./prep_dataset/ILSVRC2012_val_00035158.bin 224 224 +22627 ./prep_dataset/ILSVRC2012_val_00032869.bin 224 224 +22628 ./prep_dataset/ILSVRC2012_val_00014435.bin 224 224 +22629 ./prep_dataset/ILSVRC2012_val_00005789.bin 224 224 +22630 ./prep_dataset/ILSVRC2012_val_00022870.bin 224 224 +22631 ./prep_dataset/ILSVRC2012_val_00022299.bin 224 224 +22632 ./prep_dataset/ILSVRC2012_val_00048162.bin 224 224 +22633 ./prep_dataset/ILSVRC2012_val_00004782.bin 224 224 +22634 ./prep_dataset/ILSVRC2012_val_00032605.bin 224 224 +22635 ./prep_dataset/ILSVRC2012_val_00008251.bin 224 224 +22636 ./prep_dataset/ILSVRC2012_val_00039089.bin 224 224 +22637 ./prep_dataset/ILSVRC2012_val_00028018.bin 224 224 +22638 ./prep_dataset/ILSVRC2012_val_00005905.bin 224 224 +22639 ./prep_dataset/ILSVRC2012_val_00028515.bin 224 224 +22640 ./prep_dataset/ILSVRC2012_val_00011500.bin 224 224 +22641 ./prep_dataset/ILSVRC2012_val_00034523.bin 224 224 +22642 ./prep_dataset/ILSVRC2012_val_00033055.bin 224 224 +22643 ./prep_dataset/ILSVRC2012_val_00030612.bin 224 224 +22644 ./prep_dataset/ILSVRC2012_val_00006633.bin 224 224 +22645 ./prep_dataset/ILSVRC2012_val_00000714.bin 224 224 +22646 ./prep_dataset/ILSVRC2012_val_00005372.bin 224 224 +22647 ./prep_dataset/ILSVRC2012_val_00007118.bin 224 224 +22648 ./prep_dataset/ILSVRC2012_val_00038635.bin 224 224 +22649 ./prep_dataset/ILSVRC2012_val_00004033.bin 224 224 +22650 ./prep_dataset/ILSVRC2012_val_00012567.bin 224 224 +22651 ./prep_dataset/ILSVRC2012_val_00011032.bin 224 224 +22652 ./prep_dataset/ILSVRC2012_val_00031357.bin 224 224 +22653 ./prep_dataset/ILSVRC2012_val_00048218.bin 224 224 +22654 ./prep_dataset/ILSVRC2012_val_00007714.bin 224 224 +22655 ./prep_dataset/ILSVRC2012_val_00035899.bin 224 224 +22656 ./prep_dataset/ILSVRC2012_val_00002892.bin 224 224 +22657 ./prep_dataset/ILSVRC2012_val_00047852.bin 224 224 +22658 ./prep_dataset/ILSVRC2012_val_00048317.bin 224 224 +22659 ./prep_dataset/ILSVRC2012_val_00012481.bin 224 224 +22660 ./prep_dataset/ILSVRC2012_val_00034724.bin 224 224 +22661 ./prep_dataset/ILSVRC2012_val_00040813.bin 224 224 +22662 ./prep_dataset/ILSVRC2012_val_00004587.bin 224 224 +22663 ./prep_dataset/ILSVRC2012_val_00016065.bin 224 224 +22664 ./prep_dataset/ILSVRC2012_val_00019882.bin 224 224 +22665 ./prep_dataset/ILSVRC2012_val_00008020.bin 224 224 +22666 ./prep_dataset/ILSVRC2012_val_00010908.bin 224 224 +22667 ./prep_dataset/ILSVRC2012_val_00047937.bin 224 224 +22668 ./prep_dataset/ILSVRC2012_val_00024503.bin 224 224 +22669 ./prep_dataset/ILSVRC2012_val_00023579.bin 224 224 +22670 ./prep_dataset/ILSVRC2012_val_00000384.bin 224 224 +22671 ./prep_dataset/ILSVRC2012_val_00023926.bin 224 224 +22672 ./prep_dataset/ILSVRC2012_val_00021014.bin 224 224 +22673 ./prep_dataset/ILSVRC2012_val_00026006.bin 224 224 +22674 ./prep_dataset/ILSVRC2012_val_00008604.bin 224 224 +22675 ./prep_dataset/ILSVRC2012_val_00009392.bin 224 224 +22676 ./prep_dataset/ILSVRC2012_val_00044027.bin 224 224 +22677 ./prep_dataset/ILSVRC2012_val_00025006.bin 224 224 +22678 ./prep_dataset/ILSVRC2012_val_00006379.bin 224 224 +22679 ./prep_dataset/ILSVRC2012_val_00046020.bin 224 224 +22680 ./prep_dataset/ILSVRC2012_val_00043598.bin 224 224 +22681 ./prep_dataset/ILSVRC2012_val_00018179.bin 224 224 +22682 ./prep_dataset/ILSVRC2012_val_00013937.bin 224 224 +22683 ./prep_dataset/ILSVRC2012_val_00008322.bin 224 224 +22684 ./prep_dataset/ILSVRC2012_val_00038142.bin 224 224 +22685 ./prep_dataset/ILSVRC2012_val_00048462.bin 224 224 +22686 ./prep_dataset/ILSVRC2012_val_00011054.bin 224 224 +22687 ./prep_dataset/ILSVRC2012_val_00013235.bin 224 224 +22688 ./prep_dataset/ILSVRC2012_val_00027821.bin 224 224 +22689 ./prep_dataset/ILSVRC2012_val_00035368.bin 224 224 +22690 ./prep_dataset/ILSVRC2012_val_00041250.bin 224 224 +22691 ./prep_dataset/ILSVRC2012_val_00047366.bin 224 224 +22692 ./prep_dataset/ILSVRC2012_val_00026241.bin 224 224 +22693 ./prep_dataset/ILSVRC2012_val_00025040.bin 224 224 +22694 ./prep_dataset/ILSVRC2012_val_00034347.bin 224 224 +22695 ./prep_dataset/ILSVRC2012_val_00019781.bin 224 224 +22696 ./prep_dataset/ILSVRC2012_val_00010371.bin 224 224 +22697 ./prep_dataset/ILSVRC2012_val_00035058.bin 224 224 +22698 ./prep_dataset/ILSVRC2012_val_00035576.bin 224 224 +22699 ./prep_dataset/ILSVRC2012_val_00004530.bin 224 224 +22700 ./prep_dataset/ILSVRC2012_val_00041709.bin 224 224 +22701 ./prep_dataset/ILSVRC2012_val_00024914.bin 224 224 +22702 ./prep_dataset/ILSVRC2012_val_00022973.bin 224 224 +22703 ./prep_dataset/ILSVRC2012_val_00019291.bin 224 224 +22704 ./prep_dataset/ILSVRC2012_val_00049032.bin 224 224 +22705 ./prep_dataset/ILSVRC2012_val_00011188.bin 224 224 +22706 ./prep_dataset/ILSVRC2012_val_00003414.bin 224 224 +22707 ./prep_dataset/ILSVRC2012_val_00038083.bin 224 224 +22708 ./prep_dataset/ILSVRC2012_val_00048483.bin 224 224 +22709 ./prep_dataset/ILSVRC2012_val_00007704.bin 224 224 +22710 ./prep_dataset/ILSVRC2012_val_00013351.bin 224 224 +22711 ./prep_dataset/ILSVRC2012_val_00019358.bin 224 224 +22712 ./prep_dataset/ILSVRC2012_val_00007273.bin 224 224 +22713 ./prep_dataset/ILSVRC2012_val_00014198.bin 224 224 +22714 ./prep_dataset/ILSVRC2012_val_00047713.bin 224 224 +22715 ./prep_dataset/ILSVRC2012_val_00032517.bin 224 224 +22716 ./prep_dataset/ILSVRC2012_val_00017590.bin 224 224 +22717 ./prep_dataset/ILSVRC2012_val_00042920.bin 224 224 +22718 ./prep_dataset/ILSVRC2012_val_00003052.bin 224 224 +22719 ./prep_dataset/ILSVRC2012_val_00049460.bin 224 224 +22720 ./prep_dataset/ILSVRC2012_val_00043835.bin 224 224 +22721 ./prep_dataset/ILSVRC2012_val_00023399.bin 224 224 +22722 ./prep_dataset/ILSVRC2012_val_00027901.bin 224 224 +22723 ./prep_dataset/ILSVRC2012_val_00046127.bin 224 224 +22724 ./prep_dataset/ILSVRC2012_val_00011421.bin 224 224 +22725 ./prep_dataset/ILSVRC2012_val_00008869.bin 224 224 +22726 ./prep_dataset/ILSVRC2012_val_00036782.bin 224 224 +22727 ./prep_dataset/ILSVRC2012_val_00027442.bin 224 224 +22728 ./prep_dataset/ILSVRC2012_val_00009190.bin 224 224 +22729 ./prep_dataset/ILSVRC2012_val_00019891.bin 224 224 +22730 ./prep_dataset/ILSVRC2012_val_00043407.bin 224 224 +22731 ./prep_dataset/ILSVRC2012_val_00015102.bin 224 224 +22732 ./prep_dataset/ILSVRC2012_val_00016740.bin 224 224 +22733 ./prep_dataset/ILSVRC2012_val_00029260.bin 224 224 +22734 ./prep_dataset/ILSVRC2012_val_00045630.bin 224 224 +22735 ./prep_dataset/ILSVRC2012_val_00041095.bin 224 224 +22736 ./prep_dataset/ILSVRC2012_val_00019054.bin 224 224 +22737 ./prep_dataset/ILSVRC2012_val_00026913.bin 224 224 +22738 ./prep_dataset/ILSVRC2012_val_00034762.bin 224 224 +22739 ./prep_dataset/ILSVRC2012_val_00035295.bin 224 224 +22740 ./prep_dataset/ILSVRC2012_val_00045831.bin 224 224 +22741 ./prep_dataset/ILSVRC2012_val_00027976.bin 224 224 +22742 ./prep_dataset/ILSVRC2012_val_00009257.bin 224 224 +22743 ./prep_dataset/ILSVRC2012_val_00017489.bin 224 224 +22744 ./prep_dataset/ILSVRC2012_val_00046724.bin 224 224 +22745 ./prep_dataset/ILSVRC2012_val_00026556.bin 224 224 +22746 ./prep_dataset/ILSVRC2012_val_00003689.bin 224 224 +22747 ./prep_dataset/ILSVRC2012_val_00036017.bin 224 224 +22748 ./prep_dataset/ILSVRC2012_val_00026894.bin 224 224 +22749 ./prep_dataset/ILSVRC2012_val_00029611.bin 224 224 +22750 ./prep_dataset/ILSVRC2012_val_00023396.bin 224 224 +22751 ./prep_dataset/ILSVRC2012_val_00035949.bin 224 224 +22752 ./prep_dataset/ILSVRC2012_val_00043542.bin 224 224 +22753 ./prep_dataset/ILSVRC2012_val_00018495.bin 224 224 +22754 ./prep_dataset/ILSVRC2012_val_00043282.bin 224 224 +22755 ./prep_dataset/ILSVRC2012_val_00021176.bin 224 224 +22756 ./prep_dataset/ILSVRC2012_val_00032231.bin 224 224 +22757 ./prep_dataset/ILSVRC2012_val_00033421.bin 224 224 +22758 ./prep_dataset/ILSVRC2012_val_00011165.bin 224 224 +22759 ./prep_dataset/ILSVRC2012_val_00022467.bin 224 224 +22760 ./prep_dataset/ILSVRC2012_val_00037532.bin 224 224 +22761 ./prep_dataset/ILSVRC2012_val_00000933.bin 224 224 +22762 ./prep_dataset/ILSVRC2012_val_00008200.bin 224 224 +22763 ./prep_dataset/ILSVRC2012_val_00047847.bin 224 224 +22764 ./prep_dataset/ILSVRC2012_val_00035726.bin 224 224 +22765 ./prep_dataset/ILSVRC2012_val_00016058.bin 224 224 +22766 ./prep_dataset/ILSVRC2012_val_00020274.bin 224 224 +22767 ./prep_dataset/ILSVRC2012_val_00017014.bin 224 224 +22768 ./prep_dataset/ILSVRC2012_val_00022623.bin 224 224 +22769 ./prep_dataset/ILSVRC2012_val_00005425.bin 224 224 +22770 ./prep_dataset/ILSVRC2012_val_00017340.bin 224 224 +22771 ./prep_dataset/ILSVRC2012_val_00002187.bin 224 224 +22772 ./prep_dataset/ILSVRC2012_val_00005860.bin 224 224 +22773 ./prep_dataset/ILSVRC2012_val_00006466.bin 224 224 +22774 ./prep_dataset/ILSVRC2012_val_00045799.bin 224 224 +22775 ./prep_dataset/ILSVRC2012_val_00029643.bin 224 224 +22776 ./prep_dataset/ILSVRC2012_val_00042898.bin 224 224 +22777 ./prep_dataset/ILSVRC2012_val_00016450.bin 224 224 +22778 ./prep_dataset/ILSVRC2012_val_00028290.bin 224 224 +22779 ./prep_dataset/ILSVRC2012_val_00015581.bin 224 224 +22780 ./prep_dataset/ILSVRC2012_val_00031892.bin 224 224 +22781 ./prep_dataset/ILSVRC2012_val_00007069.bin 224 224 +22782 ./prep_dataset/ILSVRC2012_val_00042771.bin 224 224 +22783 ./prep_dataset/ILSVRC2012_val_00008571.bin 224 224 +22784 ./prep_dataset/ILSVRC2012_val_00015223.bin 224 224 +22785 ./prep_dataset/ILSVRC2012_val_00003734.bin 224 224 +22786 ./prep_dataset/ILSVRC2012_val_00004808.bin 224 224 +22787 ./prep_dataset/ILSVRC2012_val_00016139.bin 224 224 +22788 ./prep_dataset/ILSVRC2012_val_00011853.bin 224 224 +22789 ./prep_dataset/ILSVRC2012_val_00013276.bin 224 224 +22790 ./prep_dataset/ILSVRC2012_val_00007348.bin 224 224 +22791 ./prep_dataset/ILSVRC2012_val_00036719.bin 224 224 +22792 ./prep_dataset/ILSVRC2012_val_00036971.bin 224 224 +22793 ./prep_dataset/ILSVRC2012_val_00016369.bin 224 224 +22794 ./prep_dataset/ILSVRC2012_val_00026130.bin 224 224 +22795 ./prep_dataset/ILSVRC2012_val_00047692.bin 224 224 +22796 ./prep_dataset/ILSVRC2012_val_00044012.bin 224 224 +22797 ./prep_dataset/ILSVRC2012_val_00049807.bin 224 224 +22798 ./prep_dataset/ILSVRC2012_val_00030774.bin 224 224 +22799 ./prep_dataset/ILSVRC2012_val_00038841.bin 224 224 +22800 ./prep_dataset/ILSVRC2012_val_00044635.bin 224 224 +22801 ./prep_dataset/ILSVRC2012_val_00044749.bin 224 224 +22802 ./prep_dataset/ILSVRC2012_val_00030736.bin 224 224 +22803 ./prep_dataset/ILSVRC2012_val_00007060.bin 224 224 +22804 ./prep_dataset/ILSVRC2012_val_00015209.bin 224 224 +22805 ./prep_dataset/ILSVRC2012_val_00028865.bin 224 224 +22806 ./prep_dataset/ILSVRC2012_val_00049161.bin 224 224 +22807 ./prep_dataset/ILSVRC2012_val_00008794.bin 224 224 +22808 ./prep_dataset/ILSVRC2012_val_00047476.bin 224 224 +22809 ./prep_dataset/ILSVRC2012_val_00034195.bin 224 224 +22810 ./prep_dataset/ILSVRC2012_val_00038794.bin 224 224 +22811 ./prep_dataset/ILSVRC2012_val_00032183.bin 224 224 +22812 ./prep_dataset/ILSVRC2012_val_00042249.bin 224 224 +22813 ./prep_dataset/ILSVRC2012_val_00006364.bin 224 224 +22814 ./prep_dataset/ILSVRC2012_val_00048684.bin 224 224 +22815 ./prep_dataset/ILSVRC2012_val_00033961.bin 224 224 +22816 ./prep_dataset/ILSVRC2012_val_00030583.bin 224 224 +22817 ./prep_dataset/ILSVRC2012_val_00031271.bin 224 224 +22818 ./prep_dataset/ILSVRC2012_val_00006255.bin 224 224 +22819 ./prep_dataset/ILSVRC2012_val_00010632.bin 224 224 +22820 ./prep_dataset/ILSVRC2012_val_00000203.bin 224 224 +22821 ./prep_dataset/ILSVRC2012_val_00022609.bin 224 224 +22822 ./prep_dataset/ILSVRC2012_val_00008431.bin 224 224 +22823 ./prep_dataset/ILSVRC2012_val_00034521.bin 224 224 +22824 ./prep_dataset/ILSVRC2012_val_00016570.bin 224 224 +22825 ./prep_dataset/ILSVRC2012_val_00035413.bin 224 224 +22826 ./prep_dataset/ILSVRC2012_val_00005377.bin 224 224 +22827 ./prep_dataset/ILSVRC2012_val_00004456.bin 224 224 +22828 ./prep_dataset/ILSVRC2012_val_00044751.bin 224 224 +22829 ./prep_dataset/ILSVRC2012_val_00036192.bin 224 224 +22830 ./prep_dataset/ILSVRC2012_val_00014381.bin 224 224 +22831 ./prep_dataset/ILSVRC2012_val_00008652.bin 224 224 +22832 ./prep_dataset/ILSVRC2012_val_00031207.bin 224 224 +22833 ./prep_dataset/ILSVRC2012_val_00019997.bin 224 224 +22834 ./prep_dataset/ILSVRC2012_val_00003928.bin 224 224 +22835 ./prep_dataset/ILSVRC2012_val_00049470.bin 224 224 +22836 ./prep_dataset/ILSVRC2012_val_00024735.bin 224 224 +22837 ./prep_dataset/ILSVRC2012_val_00037028.bin 224 224 +22838 ./prep_dataset/ILSVRC2012_val_00020268.bin 224 224 +22839 ./prep_dataset/ILSVRC2012_val_00044465.bin 224 224 +22840 ./prep_dataset/ILSVRC2012_val_00003800.bin 224 224 +22841 ./prep_dataset/ILSVRC2012_val_00002470.bin 224 224 +22842 ./prep_dataset/ILSVRC2012_val_00028060.bin 224 224 +22843 ./prep_dataset/ILSVRC2012_val_00020749.bin 224 224 +22844 ./prep_dataset/ILSVRC2012_val_00020554.bin 224 224 +22845 ./prep_dataset/ILSVRC2012_val_00003940.bin 224 224 +22846 ./prep_dataset/ILSVRC2012_val_00038343.bin 224 224 +22847 ./prep_dataset/ILSVRC2012_val_00046791.bin 224 224 +22848 ./prep_dataset/ILSVRC2012_val_00024046.bin 224 224 +22849 ./prep_dataset/ILSVRC2012_val_00048020.bin 224 224 +22850 ./prep_dataset/ILSVRC2012_val_00010293.bin 224 224 +22851 ./prep_dataset/ILSVRC2012_val_00010580.bin 224 224 +22852 ./prep_dataset/ILSVRC2012_val_00037676.bin 224 224 +22853 ./prep_dataset/ILSVRC2012_val_00005929.bin 224 224 +22854 ./prep_dataset/ILSVRC2012_val_00008561.bin 224 224 +22855 ./prep_dataset/ILSVRC2012_val_00033270.bin 224 224 +22856 ./prep_dataset/ILSVRC2012_val_00044158.bin 224 224 +22857 ./prep_dataset/ILSVRC2012_val_00042375.bin 224 224 +22858 ./prep_dataset/ILSVRC2012_val_00044365.bin 224 224 +22859 ./prep_dataset/ILSVRC2012_val_00011221.bin 224 224 +22860 ./prep_dataset/ILSVRC2012_val_00006455.bin 224 224 +22861 ./prep_dataset/ILSVRC2012_val_00004295.bin 224 224 +22862 ./prep_dataset/ILSVRC2012_val_00006005.bin 224 224 +22863 ./prep_dataset/ILSVRC2012_val_00030260.bin 224 224 +22864 ./prep_dataset/ILSVRC2012_val_00044521.bin 224 224 +22865 ./prep_dataset/ILSVRC2012_val_00032416.bin 224 224 +22866 ./prep_dataset/ILSVRC2012_val_00024553.bin 224 224 +22867 ./prep_dataset/ILSVRC2012_val_00007804.bin 224 224 +22868 ./prep_dataset/ILSVRC2012_val_00029428.bin 224 224 +22869 ./prep_dataset/ILSVRC2012_val_00029161.bin 224 224 +22870 ./prep_dataset/ILSVRC2012_val_00025914.bin 224 224 +22871 ./prep_dataset/ILSVRC2012_val_00016692.bin 224 224 +22872 ./prep_dataset/ILSVRC2012_val_00012949.bin 224 224 +22873 ./prep_dataset/ILSVRC2012_val_00035994.bin 224 224 +22874 ./prep_dataset/ILSVRC2012_val_00035781.bin 224 224 +22875 ./prep_dataset/ILSVRC2012_val_00039113.bin 224 224 +22876 ./prep_dataset/ILSVRC2012_val_00031541.bin 224 224 +22877 ./prep_dataset/ILSVRC2012_val_00005038.bin 224 224 +22878 ./prep_dataset/ILSVRC2012_val_00038833.bin 224 224 +22879 ./prep_dataset/ILSVRC2012_val_00008692.bin 224 224 +22880 ./prep_dataset/ILSVRC2012_val_00029700.bin 224 224 +22881 ./prep_dataset/ILSVRC2012_val_00033586.bin 224 224 +22882 ./prep_dataset/ILSVRC2012_val_00036252.bin 224 224 +22883 ./prep_dataset/ILSVRC2012_val_00036121.bin 224 224 +22884 ./prep_dataset/ILSVRC2012_val_00009667.bin 224 224 +22885 ./prep_dataset/ILSVRC2012_val_00023584.bin 224 224 +22886 ./prep_dataset/ILSVRC2012_val_00046164.bin 224 224 +22887 ./prep_dataset/ILSVRC2012_val_00014437.bin 224 224 +22888 ./prep_dataset/ILSVRC2012_val_00008395.bin 224 224 +22889 ./prep_dataset/ILSVRC2012_val_00015641.bin 224 224 +22890 ./prep_dataset/ILSVRC2012_val_00002753.bin 224 224 +22891 ./prep_dataset/ILSVRC2012_val_00013221.bin 224 224 +22892 ./prep_dataset/ILSVRC2012_val_00000843.bin 224 224 +22893 ./prep_dataset/ILSVRC2012_val_00012240.bin 224 224 +22894 ./prep_dataset/ILSVRC2012_val_00022506.bin 224 224 +22895 ./prep_dataset/ILSVRC2012_val_00028316.bin 224 224 +22896 ./prep_dataset/ILSVRC2012_val_00016327.bin 224 224 +22897 ./prep_dataset/ILSVRC2012_val_00041204.bin 224 224 +22898 ./prep_dataset/ILSVRC2012_val_00010135.bin 224 224 +22899 ./prep_dataset/ILSVRC2012_val_00011098.bin 224 224 +22900 ./prep_dataset/ILSVRC2012_val_00028346.bin 224 224 +22901 ./prep_dataset/ILSVRC2012_val_00005790.bin 224 224 +22902 ./prep_dataset/ILSVRC2012_val_00031344.bin 224 224 +22903 ./prep_dataset/ILSVRC2012_val_00005681.bin 224 224 +22904 ./prep_dataset/ILSVRC2012_val_00016442.bin 224 224 +22905 ./prep_dataset/ILSVRC2012_val_00021790.bin 224 224 +22906 ./prep_dataset/ILSVRC2012_val_00046064.bin 224 224 +22907 ./prep_dataset/ILSVRC2012_val_00006664.bin 224 224 +22908 ./prep_dataset/ILSVRC2012_val_00030258.bin 224 224 +22909 ./prep_dataset/ILSVRC2012_val_00041075.bin 224 224 +22910 ./prep_dataset/ILSVRC2012_val_00037892.bin 224 224 +22911 ./prep_dataset/ILSVRC2012_val_00001316.bin 224 224 +22912 ./prep_dataset/ILSVRC2012_val_00034226.bin 224 224 +22913 ./prep_dataset/ILSVRC2012_val_00039782.bin 224 224 +22914 ./prep_dataset/ILSVRC2012_val_00001834.bin 224 224 +22915 ./prep_dataset/ILSVRC2012_val_00030159.bin 224 224 +22916 ./prep_dataset/ILSVRC2012_val_00001136.bin 224 224 +22917 ./prep_dataset/ILSVRC2012_val_00030275.bin 224 224 +22918 ./prep_dataset/ILSVRC2012_val_00049617.bin 224 224 +22919 ./prep_dataset/ILSVRC2012_val_00031354.bin 224 224 +22920 ./prep_dataset/ILSVRC2012_val_00035046.bin 224 224 +22921 ./prep_dataset/ILSVRC2012_val_00010588.bin 224 224 +22922 ./prep_dataset/ILSVRC2012_val_00009586.bin 224 224 +22923 ./prep_dataset/ILSVRC2012_val_00002148.bin 224 224 +22924 ./prep_dataset/ILSVRC2012_val_00049353.bin 224 224 +22925 ./prep_dataset/ILSVRC2012_val_00016192.bin 224 224 +22926 ./prep_dataset/ILSVRC2012_val_00044735.bin 224 224 +22927 ./prep_dataset/ILSVRC2012_val_00047140.bin 224 224 +22928 ./prep_dataset/ILSVRC2012_val_00024504.bin 224 224 +22929 ./prep_dataset/ILSVRC2012_val_00043695.bin 224 224 +22930 ./prep_dataset/ILSVRC2012_val_00043585.bin 224 224 +22931 ./prep_dataset/ILSVRC2012_val_00024858.bin 224 224 +22932 ./prep_dataset/ILSVRC2012_val_00003288.bin 224 224 +22933 ./prep_dataset/ILSVRC2012_val_00036272.bin 224 224 +22934 ./prep_dataset/ILSVRC2012_val_00021211.bin 224 224 +22935 ./prep_dataset/ILSVRC2012_val_00025653.bin 224 224 +22936 ./prep_dataset/ILSVRC2012_val_00011254.bin 224 224 +22937 ./prep_dataset/ILSVRC2012_val_00028973.bin 224 224 +22938 ./prep_dataset/ILSVRC2012_val_00038882.bin 224 224 +22939 ./prep_dataset/ILSVRC2012_val_00009024.bin 224 224 +22940 ./prep_dataset/ILSVRC2012_val_00009134.bin 224 224 +22941 ./prep_dataset/ILSVRC2012_val_00024509.bin 224 224 +22942 ./prep_dataset/ILSVRC2012_val_00045434.bin 224 224 +22943 ./prep_dataset/ILSVRC2012_val_00012606.bin 224 224 +22944 ./prep_dataset/ILSVRC2012_val_00027700.bin 224 224 +22945 ./prep_dataset/ILSVRC2012_val_00018248.bin 224 224 +22946 ./prep_dataset/ILSVRC2012_val_00010430.bin 224 224 +22947 ./prep_dataset/ILSVRC2012_val_00016715.bin 224 224 +22948 ./prep_dataset/ILSVRC2012_val_00010100.bin 224 224 +22949 ./prep_dataset/ILSVRC2012_val_00035927.bin 224 224 +22950 ./prep_dataset/ILSVRC2012_val_00014677.bin 224 224 +22951 ./prep_dataset/ILSVRC2012_val_00048275.bin 224 224 +22952 ./prep_dataset/ILSVRC2012_val_00002895.bin 224 224 +22953 ./prep_dataset/ILSVRC2012_val_00043303.bin 224 224 +22954 ./prep_dataset/ILSVRC2012_val_00038320.bin 224 224 +22955 ./prep_dataset/ILSVRC2012_val_00015990.bin 224 224 +22956 ./prep_dataset/ILSVRC2012_val_00012142.bin 224 224 +22957 ./prep_dataset/ILSVRC2012_val_00035095.bin 224 224 +22958 ./prep_dataset/ILSVRC2012_val_00022391.bin 224 224 +22959 ./prep_dataset/ILSVRC2012_val_00039182.bin 224 224 +22960 ./prep_dataset/ILSVRC2012_val_00011651.bin 224 224 +22961 ./prep_dataset/ILSVRC2012_val_00043547.bin 224 224 +22962 ./prep_dataset/ILSVRC2012_val_00022120.bin 224 224 +22963 ./prep_dataset/ILSVRC2012_val_00000699.bin 224 224 +22964 ./prep_dataset/ILSVRC2012_val_00033736.bin 224 224 +22965 ./prep_dataset/ILSVRC2012_val_00020042.bin 224 224 +22966 ./prep_dataset/ILSVRC2012_val_00007873.bin 224 224 +22967 ./prep_dataset/ILSVRC2012_val_00040717.bin 224 224 +22968 ./prep_dataset/ILSVRC2012_val_00013366.bin 224 224 +22969 ./prep_dataset/ILSVRC2012_val_00007937.bin 224 224 +22970 ./prep_dataset/ILSVRC2012_val_00046966.bin 224 224 +22971 ./prep_dataset/ILSVRC2012_val_00042235.bin 224 224 +22972 ./prep_dataset/ILSVRC2012_val_00045906.bin 224 224 +22973 ./prep_dataset/ILSVRC2012_val_00017561.bin 224 224 +22974 ./prep_dataset/ILSVRC2012_val_00045025.bin 224 224 +22975 ./prep_dataset/ILSVRC2012_val_00019582.bin 224 224 +22976 ./prep_dataset/ILSVRC2012_val_00007179.bin 224 224 +22977 ./prep_dataset/ILSVRC2012_val_00002243.bin 224 224 +22978 ./prep_dataset/ILSVRC2012_val_00042721.bin 224 224 +22979 ./prep_dataset/ILSVRC2012_val_00007276.bin 224 224 +22980 ./prep_dataset/ILSVRC2012_val_00009676.bin 224 224 +22981 ./prep_dataset/ILSVRC2012_val_00012067.bin 224 224 +22982 ./prep_dataset/ILSVRC2012_val_00008858.bin 224 224 +22983 ./prep_dataset/ILSVRC2012_val_00030593.bin 224 224 +22984 ./prep_dataset/ILSVRC2012_val_00024178.bin 224 224 +22985 ./prep_dataset/ILSVRC2012_val_00016551.bin 224 224 +22986 ./prep_dataset/ILSVRC2012_val_00017191.bin 224 224 +22987 ./prep_dataset/ILSVRC2012_val_00033807.bin 224 224 +22988 ./prep_dataset/ILSVRC2012_val_00040147.bin 224 224 +22989 ./prep_dataset/ILSVRC2012_val_00023075.bin 224 224 +22990 ./prep_dataset/ILSVRC2012_val_00045891.bin 224 224 +22991 ./prep_dataset/ILSVRC2012_val_00027360.bin 224 224 +22992 ./prep_dataset/ILSVRC2012_val_00027714.bin 224 224 +22993 ./prep_dataset/ILSVRC2012_val_00031224.bin 224 224 +22994 ./prep_dataset/ILSVRC2012_val_00018773.bin 224 224 +22995 ./prep_dataset/ILSVRC2012_val_00003625.bin 224 224 +22996 ./prep_dataset/ILSVRC2012_val_00023066.bin 224 224 +22997 ./prep_dataset/ILSVRC2012_val_00022786.bin 224 224 +22998 ./prep_dataset/ILSVRC2012_val_00011173.bin 224 224 +22999 ./prep_dataset/ILSVRC2012_val_00039816.bin 224 224 +23000 ./prep_dataset/ILSVRC2012_val_00029816.bin 224 224 +23001 ./prep_dataset/ILSVRC2012_val_00009433.bin 224 224 +23002 ./prep_dataset/ILSVRC2012_val_00014545.bin 224 224 +23003 ./prep_dataset/ILSVRC2012_val_00043486.bin 224 224 +23004 ./prep_dataset/ILSVRC2012_val_00025250.bin 224 224 +23005 ./prep_dataset/ILSVRC2012_val_00027718.bin 224 224 +23006 ./prep_dataset/ILSVRC2012_val_00015475.bin 224 224 +23007 ./prep_dataset/ILSVRC2012_val_00037343.bin 224 224 +23008 ./prep_dataset/ILSVRC2012_val_00016404.bin 224 224 +23009 ./prep_dataset/ILSVRC2012_val_00037410.bin 224 224 +23010 ./prep_dataset/ILSVRC2012_val_00042575.bin 224 224 +23011 ./prep_dataset/ILSVRC2012_val_00037001.bin 224 224 +23012 ./prep_dataset/ILSVRC2012_val_00041806.bin 224 224 +23013 ./prep_dataset/ILSVRC2012_val_00002453.bin 224 224 +23014 ./prep_dataset/ILSVRC2012_val_00042504.bin 224 224 +23015 ./prep_dataset/ILSVRC2012_val_00040237.bin 224 224 +23016 ./prep_dataset/ILSVRC2012_val_00034376.bin 224 224 +23017 ./prep_dataset/ILSVRC2012_val_00039447.bin 224 224 +23018 ./prep_dataset/ILSVRC2012_val_00013418.bin 224 224 +23019 ./prep_dataset/ILSVRC2012_val_00029440.bin 224 224 +23020 ./prep_dataset/ILSVRC2012_val_00048369.bin 224 224 +23021 ./prep_dataset/ILSVRC2012_val_00023867.bin 224 224 +23022 ./prep_dataset/ILSVRC2012_val_00037540.bin 224 224 +23023 ./prep_dataset/ILSVRC2012_val_00023454.bin 224 224 +23024 ./prep_dataset/ILSVRC2012_val_00035362.bin 224 224 +23025 ./prep_dataset/ILSVRC2012_val_00001290.bin 224 224 +23026 ./prep_dataset/ILSVRC2012_val_00019624.bin 224 224 +23027 ./prep_dataset/ILSVRC2012_val_00016206.bin 224 224 +23028 ./prep_dataset/ILSVRC2012_val_00012853.bin 224 224 +23029 ./prep_dataset/ILSVRC2012_val_00036612.bin 224 224 +23030 ./prep_dataset/ILSVRC2012_val_00002429.bin 224 224 +23031 ./prep_dataset/ILSVRC2012_val_00021983.bin 224 224 +23032 ./prep_dataset/ILSVRC2012_val_00033205.bin 224 224 +23033 ./prep_dataset/ILSVRC2012_val_00033477.bin 224 224 +23034 ./prep_dataset/ILSVRC2012_val_00003373.bin 224 224 +23035 ./prep_dataset/ILSVRC2012_val_00043978.bin 224 224 +23036 ./prep_dataset/ILSVRC2012_val_00041479.bin 224 224 +23037 ./prep_dataset/ILSVRC2012_val_00031640.bin 224 224 +23038 ./prep_dataset/ILSVRC2012_val_00014708.bin 224 224 +23039 ./prep_dataset/ILSVRC2012_val_00044123.bin 224 224 +23040 ./prep_dataset/ILSVRC2012_val_00011311.bin 224 224 +23041 ./prep_dataset/ILSVRC2012_val_00010225.bin 224 224 +23042 ./prep_dataset/ILSVRC2012_val_00002851.bin 224 224 +23043 ./prep_dataset/ILSVRC2012_val_00027116.bin 224 224 +23044 ./prep_dataset/ILSVRC2012_val_00018842.bin 224 224 +23045 ./prep_dataset/ILSVRC2012_val_00026144.bin 224 224 +23046 ./prep_dataset/ILSVRC2012_val_00014796.bin 224 224 +23047 ./prep_dataset/ILSVRC2012_val_00006894.bin 224 224 +23048 ./prep_dataset/ILSVRC2012_val_00049430.bin 224 224 +23049 ./prep_dataset/ILSVRC2012_val_00041226.bin 224 224 +23050 ./prep_dataset/ILSVRC2012_val_00046041.bin 224 224 +23051 ./prep_dataset/ILSVRC2012_val_00010763.bin 224 224 +23052 ./prep_dataset/ILSVRC2012_val_00049631.bin 224 224 +23053 ./prep_dataset/ILSVRC2012_val_00026026.bin 224 224 +23054 ./prep_dataset/ILSVRC2012_val_00001995.bin 224 224 +23055 ./prep_dataset/ILSVRC2012_val_00001151.bin 224 224 +23056 ./prep_dataset/ILSVRC2012_val_00040791.bin 224 224 +23057 ./prep_dataset/ILSVRC2012_val_00023209.bin 224 224 +23058 ./prep_dataset/ILSVRC2012_val_00027059.bin 224 224 +23059 ./prep_dataset/ILSVRC2012_val_00020055.bin 224 224 +23060 ./prep_dataset/ILSVRC2012_val_00025037.bin 224 224 +23061 ./prep_dataset/ILSVRC2012_val_00033372.bin 224 224 +23062 ./prep_dataset/ILSVRC2012_val_00012129.bin 224 224 +23063 ./prep_dataset/ILSVRC2012_val_00006786.bin 224 224 +23064 ./prep_dataset/ILSVRC2012_val_00032566.bin 224 224 +23065 ./prep_dataset/ILSVRC2012_val_00024469.bin 224 224 +23066 ./prep_dataset/ILSVRC2012_val_00021293.bin 224 224 +23067 ./prep_dataset/ILSVRC2012_val_00011016.bin 224 224 +23068 ./prep_dataset/ILSVRC2012_val_00037120.bin 224 224 +23069 ./prep_dataset/ILSVRC2012_val_00012677.bin 224 224 +23070 ./prep_dataset/ILSVRC2012_val_00018562.bin 224 224 +23071 ./prep_dataset/ILSVRC2012_val_00004449.bin 224 224 +23072 ./prep_dataset/ILSVRC2012_val_00024659.bin 224 224 +23073 ./prep_dataset/ILSVRC2012_val_00027500.bin 224 224 +23074 ./prep_dataset/ILSVRC2012_val_00044140.bin 224 224 +23075 ./prep_dataset/ILSVRC2012_val_00033444.bin 224 224 +23076 ./prep_dataset/ILSVRC2012_val_00019979.bin 224 224 +23077 ./prep_dataset/ILSVRC2012_val_00020050.bin 224 224 +23078 ./prep_dataset/ILSVRC2012_val_00038524.bin 224 224 +23079 ./prep_dataset/ILSVRC2012_val_00016658.bin 224 224 +23080 ./prep_dataset/ILSVRC2012_val_00042225.bin 224 224 +23081 ./prep_dataset/ILSVRC2012_val_00025145.bin 224 224 +23082 ./prep_dataset/ILSVRC2012_val_00005157.bin 224 224 +23083 ./prep_dataset/ILSVRC2012_val_00022060.bin 224 224 +23084 ./prep_dataset/ILSVRC2012_val_00024956.bin 224 224 +23085 ./prep_dataset/ILSVRC2012_val_00022733.bin 224 224 +23086 ./prep_dataset/ILSVRC2012_val_00021859.bin 224 224 +23087 ./prep_dataset/ILSVRC2012_val_00012326.bin 224 224 +23088 ./prep_dataset/ILSVRC2012_val_00032936.bin 224 224 +23089 ./prep_dataset/ILSVRC2012_val_00020565.bin 224 224 +23090 ./prep_dataset/ILSVRC2012_val_00040203.bin 224 224 +23091 ./prep_dataset/ILSVRC2012_val_00049740.bin 224 224 +23092 ./prep_dataset/ILSVRC2012_val_00035900.bin 224 224 +23093 ./prep_dataset/ILSVRC2012_val_00023240.bin 224 224 +23094 ./prep_dataset/ILSVRC2012_val_00036450.bin 224 224 +23095 ./prep_dataset/ILSVRC2012_val_00018113.bin 224 224 +23096 ./prep_dataset/ILSVRC2012_val_00025684.bin 224 224 +23097 ./prep_dataset/ILSVRC2012_val_00040377.bin 224 224 +23098 ./prep_dataset/ILSVRC2012_val_00007993.bin 224 224 +23099 ./prep_dataset/ILSVRC2012_val_00002995.bin 224 224 +23100 ./prep_dataset/ILSVRC2012_val_00046257.bin 224 224 +23101 ./prep_dataset/ILSVRC2012_val_00032846.bin 224 224 +23102 ./prep_dataset/ILSVRC2012_val_00027159.bin 224 224 +23103 ./prep_dataset/ILSVRC2012_val_00032512.bin 224 224 +23104 ./prep_dataset/ILSVRC2012_val_00029376.bin 224 224 +23105 ./prep_dataset/ILSVRC2012_val_00020802.bin 224 224 +23106 ./prep_dataset/ILSVRC2012_val_00044980.bin 224 224 +23107 ./prep_dataset/ILSVRC2012_val_00033927.bin 224 224 +23108 ./prep_dataset/ILSVRC2012_val_00018457.bin 224 224 +23109 ./prep_dataset/ILSVRC2012_val_00014072.bin 224 224 +23110 ./prep_dataset/ILSVRC2012_val_00025692.bin 224 224 +23111 ./prep_dataset/ILSVRC2012_val_00028678.bin 224 224 +23112 ./prep_dataset/ILSVRC2012_val_00005346.bin 224 224 +23113 ./prep_dataset/ILSVRC2012_val_00012061.bin 224 224 +23114 ./prep_dataset/ILSVRC2012_val_00027035.bin 224 224 +23115 ./prep_dataset/ILSVRC2012_val_00016888.bin 224 224 +23116 ./prep_dataset/ILSVRC2012_val_00040423.bin 224 224 +23117 ./prep_dataset/ILSVRC2012_val_00033467.bin 224 224 +23118 ./prep_dataset/ILSVRC2012_val_00042315.bin 224 224 +23119 ./prep_dataset/ILSVRC2012_val_00013887.bin 224 224 +23120 ./prep_dataset/ILSVRC2012_val_00028157.bin 224 224 +23121 ./prep_dataset/ILSVRC2012_val_00026529.bin 224 224 +23122 ./prep_dataset/ILSVRC2012_val_00033758.bin 224 224 +23123 ./prep_dataset/ILSVRC2012_val_00013561.bin 224 224 +23124 ./prep_dataset/ILSVRC2012_val_00036359.bin 224 224 +23125 ./prep_dataset/ILSVRC2012_val_00003067.bin 224 224 +23126 ./prep_dataset/ILSVRC2012_val_00026482.bin 224 224 +23127 ./prep_dataset/ILSVRC2012_val_00035460.bin 224 224 +23128 ./prep_dataset/ILSVRC2012_val_00030557.bin 224 224 +23129 ./prep_dataset/ILSVRC2012_val_00038275.bin 224 224 +23130 ./prep_dataset/ILSVRC2012_val_00042066.bin 224 224 +23131 ./prep_dataset/ILSVRC2012_val_00010257.bin 224 224 +23132 ./prep_dataset/ILSVRC2012_val_00042271.bin 224 224 +23133 ./prep_dataset/ILSVRC2012_val_00006358.bin 224 224 +23134 ./prep_dataset/ILSVRC2012_val_00042784.bin 224 224 +23135 ./prep_dataset/ILSVRC2012_val_00043007.bin 224 224 +23136 ./prep_dataset/ILSVRC2012_val_00000785.bin 224 224 +23137 ./prep_dataset/ILSVRC2012_val_00018681.bin 224 224 +23138 ./prep_dataset/ILSVRC2012_val_00049355.bin 224 224 +23139 ./prep_dataset/ILSVRC2012_val_00012381.bin 224 224 +23140 ./prep_dataset/ILSVRC2012_val_00048433.bin 224 224 +23141 ./prep_dataset/ILSVRC2012_val_00039727.bin 224 224 +23142 ./prep_dataset/ILSVRC2012_val_00017385.bin 224 224 +23143 ./prep_dataset/ILSVRC2012_val_00009150.bin 224 224 +23144 ./prep_dataset/ILSVRC2012_val_00018804.bin 224 224 +23145 ./prep_dataset/ILSVRC2012_val_00004682.bin 224 224 +23146 ./prep_dataset/ILSVRC2012_val_00012581.bin 224 224 +23147 ./prep_dataset/ILSVRC2012_val_00035835.bin 224 224 +23148 ./prep_dataset/ILSVRC2012_val_00005892.bin 224 224 +23149 ./prep_dataset/ILSVRC2012_val_00005644.bin 224 224 +23150 ./prep_dataset/ILSVRC2012_val_00006232.bin 224 224 +23151 ./prep_dataset/ILSVRC2012_val_00001499.bin 224 224 +23152 ./prep_dataset/ILSVRC2012_val_00034445.bin 224 224 +23153 ./prep_dataset/ILSVRC2012_val_00049560.bin 224 224 +23154 ./prep_dataset/ILSVRC2012_val_00017493.bin 224 224 +23155 ./prep_dataset/ILSVRC2012_val_00012523.bin 224 224 +23156 ./prep_dataset/ILSVRC2012_val_00045774.bin 224 224 +23157 ./prep_dataset/ILSVRC2012_val_00020632.bin 224 224 +23158 ./prep_dataset/ILSVRC2012_val_00003687.bin 224 224 +23159 ./prep_dataset/ILSVRC2012_val_00047204.bin 224 224 +23160 ./prep_dataset/ILSVRC2012_val_00013872.bin 224 224 +23161 ./prep_dataset/ILSVRC2012_val_00016275.bin 224 224 +23162 ./prep_dataset/ILSVRC2012_val_00024805.bin 224 224 +23163 ./prep_dataset/ILSVRC2012_val_00022447.bin 224 224 +23164 ./prep_dataset/ILSVRC2012_val_00032204.bin 224 224 +23165 ./prep_dataset/ILSVRC2012_val_00029664.bin 224 224 +23166 ./prep_dataset/ILSVRC2012_val_00041611.bin 224 224 +23167 ./prep_dataset/ILSVRC2012_val_00027331.bin 224 224 +23168 ./prep_dataset/ILSVRC2012_val_00038195.bin 224 224 +23169 ./prep_dataset/ILSVRC2012_val_00039149.bin 224 224 +23170 ./prep_dataset/ILSVRC2012_val_00003187.bin 224 224 +23171 ./prep_dataset/ILSVRC2012_val_00039109.bin 224 224 +23172 ./prep_dataset/ILSVRC2012_val_00010811.bin 224 224 +23173 ./prep_dataset/ILSVRC2012_val_00022945.bin 224 224 +23174 ./prep_dataset/ILSVRC2012_val_00049201.bin 224 224 +23175 ./prep_dataset/ILSVRC2012_val_00014362.bin 224 224 +23176 ./prep_dataset/ILSVRC2012_val_00026041.bin 224 224 +23177 ./prep_dataset/ILSVRC2012_val_00024754.bin 224 224 +23178 ./prep_dataset/ILSVRC2012_val_00031605.bin 224 224 +23179 ./prep_dataset/ILSVRC2012_val_00008290.bin 224 224 +23180 ./prep_dataset/ILSVRC2012_val_00018832.bin 224 224 +23181 ./prep_dataset/ILSVRC2012_val_00010810.bin 224 224 +23182 ./prep_dataset/ILSVRC2012_val_00020343.bin 224 224 +23183 ./prep_dataset/ILSVRC2012_val_00049996.bin 224 224 +23184 ./prep_dataset/ILSVRC2012_val_00016257.bin 224 224 +23185 ./prep_dataset/ILSVRC2012_val_00039699.bin 224 224 +23186 ./prep_dataset/ILSVRC2012_val_00011290.bin 224 224 +23187 ./prep_dataset/ILSVRC2012_val_00047312.bin 224 224 +23188 ./prep_dataset/ILSVRC2012_val_00002245.bin 224 224 +23189 ./prep_dataset/ILSVRC2012_val_00001119.bin 224 224 +23190 ./prep_dataset/ILSVRC2012_val_00026822.bin 224 224 +23191 ./prep_dataset/ILSVRC2012_val_00028937.bin 224 224 +23192 ./prep_dataset/ILSVRC2012_val_00038198.bin 224 224 +23193 ./prep_dataset/ILSVRC2012_val_00025549.bin 224 224 +23194 ./prep_dataset/ILSVRC2012_val_00005701.bin 224 224 +23195 ./prep_dataset/ILSVRC2012_val_00046946.bin 224 224 +23196 ./prep_dataset/ILSVRC2012_val_00024760.bin 224 224 +23197 ./prep_dataset/ILSVRC2012_val_00024710.bin 224 224 +23198 ./prep_dataset/ILSVRC2012_val_00011038.bin 224 224 +23199 ./prep_dataset/ILSVRC2012_val_00008072.bin 224 224 +23200 ./prep_dataset/ILSVRC2012_val_00038325.bin 224 224 +23201 ./prep_dataset/ILSVRC2012_val_00049861.bin 224 224 +23202 ./prep_dataset/ILSVRC2012_val_00020665.bin 224 224 +23203 ./prep_dataset/ILSVRC2012_val_00016269.bin 224 224 +23204 ./prep_dataset/ILSVRC2012_val_00016807.bin 224 224 +23205 ./prep_dataset/ILSVRC2012_val_00024833.bin 224 224 +23206 ./prep_dataset/ILSVRC2012_val_00025700.bin 224 224 +23207 ./prep_dataset/ILSVRC2012_val_00038784.bin 224 224 +23208 ./prep_dataset/ILSVRC2012_val_00037456.bin 224 224 +23209 ./prep_dataset/ILSVRC2012_val_00036168.bin 224 224 +23210 ./prep_dataset/ILSVRC2012_val_00022558.bin 224 224 +23211 ./prep_dataset/ILSVRC2012_val_00005881.bin 224 224 +23212 ./prep_dataset/ILSVRC2012_val_00006732.bin 224 224 +23213 ./prep_dataset/ILSVRC2012_val_00049867.bin 224 224 +23214 ./prep_dataset/ILSVRC2012_val_00006410.bin 224 224 +23215 ./prep_dataset/ILSVRC2012_val_00000247.bin 224 224 +23216 ./prep_dataset/ILSVRC2012_val_00005336.bin 224 224 +23217 ./prep_dataset/ILSVRC2012_val_00045503.bin 224 224 +23218 ./prep_dataset/ILSVRC2012_val_00030285.bin 224 224 +23219 ./prep_dataset/ILSVRC2012_val_00005367.bin 224 224 +23220 ./prep_dataset/ILSVRC2012_val_00015864.bin 224 224 +23221 ./prep_dataset/ILSVRC2012_val_00043643.bin 224 224 +23222 ./prep_dataset/ILSVRC2012_val_00009806.bin 224 224 +23223 ./prep_dataset/ILSVRC2012_val_00047917.bin 224 224 +23224 ./prep_dataset/ILSVRC2012_val_00044359.bin 224 224 +23225 ./prep_dataset/ILSVRC2012_val_00025855.bin 224 224 +23226 ./prep_dataset/ILSVRC2012_val_00008536.bin 224 224 +23227 ./prep_dataset/ILSVRC2012_val_00029635.bin 224 224 +23228 ./prep_dataset/ILSVRC2012_val_00019543.bin 224 224 +23229 ./prep_dataset/ILSVRC2012_val_00049941.bin 224 224 +23230 ./prep_dataset/ILSVRC2012_val_00006582.bin 224 224 +23231 ./prep_dataset/ILSVRC2012_val_00028501.bin 224 224 +23232 ./prep_dataset/ILSVRC2012_val_00026150.bin 224 224 +23233 ./prep_dataset/ILSVRC2012_val_00047519.bin 224 224 +23234 ./prep_dataset/ILSVRC2012_val_00025299.bin 224 224 +23235 ./prep_dataset/ILSVRC2012_val_00003887.bin 224 224 +23236 ./prep_dataset/ILSVRC2012_val_00020531.bin 224 224 +23237 ./prep_dataset/ILSVRC2012_val_00027208.bin 224 224 +23238 ./prep_dataset/ILSVRC2012_val_00006668.bin 224 224 +23239 ./prep_dataset/ILSVRC2012_val_00038875.bin 224 224 +23240 ./prep_dataset/ILSVRC2012_val_00043867.bin 224 224 +23241 ./prep_dataset/ILSVRC2012_val_00027727.bin 224 224 +23242 ./prep_dataset/ILSVRC2012_val_00046210.bin 224 224 +23243 ./prep_dataset/ILSVRC2012_val_00017184.bin 224 224 +23244 ./prep_dataset/ILSVRC2012_val_00041037.bin 224 224 +23245 ./prep_dataset/ILSVRC2012_val_00026628.bin 224 224 +23246 ./prep_dataset/ILSVRC2012_val_00020730.bin 224 224 +23247 ./prep_dataset/ILSVRC2012_val_00007567.bin 224 224 +23248 ./prep_dataset/ILSVRC2012_val_00047586.bin 224 224 +23249 ./prep_dataset/ILSVRC2012_val_00040344.bin 224 224 +23250 ./prep_dataset/ILSVRC2012_val_00018692.bin 224 224 +23251 ./prep_dataset/ILSVRC2012_val_00025293.bin 224 224 +23252 ./prep_dataset/ILSVRC2012_val_00026614.bin 224 224 +23253 ./prep_dataset/ILSVRC2012_val_00018158.bin 224 224 +23254 ./prep_dataset/ILSVRC2012_val_00002806.bin 224 224 +23255 ./prep_dataset/ILSVRC2012_val_00003382.bin 224 224 +23256 ./prep_dataset/ILSVRC2012_val_00017389.bin 224 224 +23257 ./prep_dataset/ILSVRC2012_val_00022346.bin 224 224 +23258 ./prep_dataset/ILSVRC2012_val_00003792.bin 224 224 +23259 ./prep_dataset/ILSVRC2012_val_00015298.bin 224 224 +23260 ./prep_dataset/ILSVRC2012_val_00043850.bin 224 224 +23261 ./prep_dataset/ILSVRC2012_val_00046523.bin 224 224 +23262 ./prep_dataset/ILSVRC2012_val_00006605.bin 224 224 +23263 ./prep_dataset/ILSVRC2012_val_00025827.bin 224 224 +23264 ./prep_dataset/ILSVRC2012_val_00007203.bin 224 224 +23265 ./prep_dataset/ILSVRC2012_val_00048015.bin 224 224 +23266 ./prep_dataset/ILSVRC2012_val_00009677.bin 224 224 +23267 ./prep_dataset/ILSVRC2012_val_00029600.bin 224 224 +23268 ./prep_dataset/ILSVRC2012_val_00037833.bin 224 224 +23269 ./prep_dataset/ILSVRC2012_val_00019152.bin 224 224 +23270 ./prep_dataset/ILSVRC2012_val_00000502.bin 224 224 +23271 ./prep_dataset/ILSVRC2012_val_00009276.bin 224 224 +23272 ./prep_dataset/ILSVRC2012_val_00006468.bin 224 224 +23273 ./prep_dataset/ILSVRC2012_val_00033102.bin 224 224 +23274 ./prep_dataset/ILSVRC2012_val_00031611.bin 224 224 +23275 ./prep_dataset/ILSVRC2012_val_00027182.bin 224 224 +23276 ./prep_dataset/ILSVRC2012_val_00004875.bin 224 224 +23277 ./prep_dataset/ILSVRC2012_val_00008225.bin 224 224 +23278 ./prep_dataset/ILSVRC2012_val_00046907.bin 224 224 +23279 ./prep_dataset/ILSVRC2012_val_00027543.bin 224 224 +23280 ./prep_dataset/ILSVRC2012_val_00043657.bin 224 224 +23281 ./prep_dataset/ILSVRC2012_val_00014786.bin 224 224 +23282 ./prep_dataset/ILSVRC2012_val_00049644.bin 224 224 +23283 ./prep_dataset/ILSVRC2012_val_00022314.bin 224 224 +23284 ./prep_dataset/ILSVRC2012_val_00048708.bin 224 224 +23285 ./prep_dataset/ILSVRC2012_val_00014219.bin 224 224 +23286 ./prep_dataset/ILSVRC2012_val_00020078.bin 224 224 +23287 ./prep_dataset/ILSVRC2012_val_00013010.bin 224 224 +23288 ./prep_dataset/ILSVRC2012_val_00019736.bin 224 224 +23289 ./prep_dataset/ILSVRC2012_val_00020311.bin 224 224 +23290 ./prep_dataset/ILSVRC2012_val_00034155.bin 224 224 +23291 ./prep_dataset/ILSVRC2012_val_00009669.bin 224 224 +23292 ./prep_dataset/ILSVRC2012_val_00012505.bin 224 224 +23293 ./prep_dataset/ILSVRC2012_val_00014211.bin 224 224 +23294 ./prep_dataset/ILSVRC2012_val_00003571.bin 224 224 +23295 ./prep_dataset/ILSVRC2012_val_00030205.bin 224 224 +23296 ./prep_dataset/ILSVRC2012_val_00004617.bin 224 224 +23297 ./prep_dataset/ILSVRC2012_val_00026387.bin 224 224 +23298 ./prep_dataset/ILSVRC2012_val_00035632.bin 224 224 +23299 ./prep_dataset/ILSVRC2012_val_00005285.bin 224 224 +23300 ./prep_dataset/ILSVRC2012_val_00035643.bin 224 224 +23301 ./prep_dataset/ILSVRC2012_val_00034595.bin 224 224 +23302 ./prep_dataset/ILSVRC2012_val_00010528.bin 224 224 +23303 ./prep_dataset/ILSVRC2012_val_00011987.bin 224 224 +23304 ./prep_dataset/ILSVRC2012_val_00003586.bin 224 224 +23305 ./prep_dataset/ILSVRC2012_val_00027120.bin 224 224 +23306 ./prep_dataset/ILSVRC2012_val_00012861.bin 224 224 +23307 ./prep_dataset/ILSVRC2012_val_00000123.bin 224 224 +23308 ./prep_dataset/ILSVRC2012_val_00014360.bin 224 224 +23309 ./prep_dataset/ILSVRC2012_val_00009879.bin 224 224 +23310 ./prep_dataset/ILSVRC2012_val_00041417.bin 224 224 +23311 ./prep_dataset/ILSVRC2012_val_00016895.bin 224 224 +23312 ./prep_dataset/ILSVRC2012_val_00021429.bin 224 224 +23313 ./prep_dataset/ILSVRC2012_val_00017983.bin 224 224 +23314 ./prep_dataset/ILSVRC2012_val_00045074.bin 224 224 +23315 ./prep_dataset/ILSVRC2012_val_00015369.bin 224 224 +23316 ./prep_dataset/ILSVRC2012_val_00008884.bin 224 224 +23317 ./prep_dataset/ILSVRC2012_val_00041952.bin 224 224 +23318 ./prep_dataset/ILSVRC2012_val_00036101.bin 224 224 +23319 ./prep_dataset/ILSVRC2012_val_00010452.bin 224 224 +23320 ./prep_dataset/ILSVRC2012_val_00044225.bin 224 224 +23321 ./prep_dataset/ILSVRC2012_val_00041503.bin 224 224 +23322 ./prep_dataset/ILSVRC2012_val_00019455.bin 224 224 +23323 ./prep_dataset/ILSVRC2012_val_00019201.bin 224 224 +23324 ./prep_dataset/ILSVRC2012_val_00026399.bin 224 224 +23325 ./prep_dataset/ILSVRC2012_val_00023068.bin 224 224 +23326 ./prep_dataset/ILSVRC2012_val_00032785.bin 224 224 +23327 ./prep_dataset/ILSVRC2012_val_00011470.bin 224 224 +23328 ./prep_dataset/ILSVRC2012_val_00034705.bin 224 224 +23329 ./prep_dataset/ILSVRC2012_val_00011231.bin 224 224 +23330 ./prep_dataset/ILSVRC2012_val_00019909.bin 224 224 +23331 ./prep_dataset/ILSVRC2012_val_00039236.bin 224 224 +23332 ./prep_dataset/ILSVRC2012_val_00004159.bin 224 224 +23333 ./prep_dataset/ILSVRC2012_val_00019837.bin 224 224 +23334 ./prep_dataset/ILSVRC2012_val_00003955.bin 224 224 +23335 ./prep_dataset/ILSVRC2012_val_00048051.bin 224 224 +23336 ./prep_dataset/ILSVRC2012_val_00020663.bin 224 224 +23337 ./prep_dataset/ILSVRC2012_val_00036962.bin 224 224 +23338 ./prep_dataset/ILSVRC2012_val_00032184.bin 224 224 +23339 ./prep_dataset/ILSVRC2012_val_00033254.bin 224 224 +23340 ./prep_dataset/ILSVRC2012_val_00005873.bin 224 224 +23341 ./prep_dataset/ILSVRC2012_val_00008338.bin 224 224 +23342 ./prep_dataset/ILSVRC2012_val_00040461.bin 224 224 +23343 ./prep_dataset/ILSVRC2012_val_00043104.bin 224 224 +23344 ./prep_dataset/ILSVRC2012_val_00019999.bin 224 224 +23345 ./prep_dataset/ILSVRC2012_val_00036798.bin 224 224 +23346 ./prep_dataset/ILSVRC2012_val_00020142.bin 224 224 +23347 ./prep_dataset/ILSVRC2012_val_00035970.bin 224 224 +23348 ./prep_dataset/ILSVRC2012_val_00026328.bin 224 224 +23349 ./prep_dataset/ILSVRC2012_val_00023609.bin 224 224 +23350 ./prep_dataset/ILSVRC2012_val_00031319.bin 224 224 +23351 ./prep_dataset/ILSVRC2012_val_00042798.bin 224 224 +23352 ./prep_dataset/ILSVRC2012_val_00035062.bin 224 224 +23353 ./prep_dataset/ILSVRC2012_val_00020772.bin 224 224 +23354 ./prep_dataset/ILSVRC2012_val_00005810.bin 224 224 +23355 ./prep_dataset/ILSVRC2012_val_00028139.bin 224 224 +23356 ./prep_dataset/ILSVRC2012_val_00003726.bin 224 224 +23357 ./prep_dataset/ILSVRC2012_val_00035286.bin 224 224 +23358 ./prep_dataset/ILSVRC2012_val_00028502.bin 224 224 +23359 ./prep_dataset/ILSVRC2012_val_00023230.bin 224 224 +23360 ./prep_dataset/ILSVRC2012_val_00034219.bin 224 224 +23361 ./prep_dataset/ILSVRC2012_val_00038260.bin 224 224 +23362 ./prep_dataset/ILSVRC2012_val_00024311.bin 224 224 +23363 ./prep_dataset/ILSVRC2012_val_00015693.bin 224 224 +23364 ./prep_dataset/ILSVRC2012_val_00048491.bin 224 224 +23365 ./prep_dataset/ILSVRC2012_val_00003109.bin 224 224 +23366 ./prep_dataset/ILSVRC2012_val_00039617.bin 224 224 +23367 ./prep_dataset/ILSVRC2012_val_00039325.bin 224 224 +23368 ./prep_dataset/ILSVRC2012_val_00002674.bin 224 224 +23369 ./prep_dataset/ILSVRC2012_val_00040571.bin 224 224 +23370 ./prep_dataset/ILSVRC2012_val_00028788.bin 224 224 +23371 ./prep_dataset/ILSVRC2012_val_00013257.bin 224 224 +23372 ./prep_dataset/ILSVRC2012_val_00033245.bin 224 224 +23373 ./prep_dataset/ILSVRC2012_val_00024227.bin 224 224 +23374 ./prep_dataset/ILSVRC2012_val_00015411.bin 224 224 +23375 ./prep_dataset/ILSVRC2012_val_00025035.bin 224 224 +23376 ./prep_dataset/ILSVRC2012_val_00036547.bin 224 224 +23377 ./prep_dataset/ILSVRC2012_val_00038674.bin 224 224 +23378 ./prep_dataset/ILSVRC2012_val_00018369.bin 224 224 +23379 ./prep_dataset/ILSVRC2012_val_00031233.bin 224 224 +23380 ./prep_dataset/ILSVRC2012_val_00039667.bin 224 224 +23381 ./prep_dataset/ILSVRC2012_val_00016273.bin 224 224 +23382 ./prep_dataset/ILSVRC2012_val_00048970.bin 224 224 +23383 ./prep_dataset/ILSVRC2012_val_00033117.bin 224 224 +23384 ./prep_dataset/ILSVRC2012_val_00032578.bin 224 224 +23385 ./prep_dataset/ILSVRC2012_val_00030489.bin 224 224 +23386 ./prep_dataset/ILSVRC2012_val_00000580.bin 224 224 +23387 ./prep_dataset/ILSVRC2012_val_00032647.bin 224 224 +23388 ./prep_dataset/ILSVRC2012_val_00022524.bin 224 224 +23389 ./prep_dataset/ILSVRC2012_val_00047966.bin 224 224 +23390 ./prep_dataset/ILSVRC2012_val_00019463.bin 224 224 +23391 ./prep_dataset/ILSVRC2012_val_00005105.bin 224 224 +23392 ./prep_dataset/ILSVRC2012_val_00004853.bin 224 224 +23393 ./prep_dataset/ILSVRC2012_val_00027056.bin 224 224 +23394 ./prep_dataset/ILSVRC2012_val_00042593.bin 224 224 +23395 ./prep_dataset/ILSVRC2012_val_00032654.bin 224 224 +23396 ./prep_dataset/ILSVRC2012_val_00027537.bin 224 224 +23397 ./prep_dataset/ILSVRC2012_val_00002112.bin 224 224 +23398 ./prep_dataset/ILSVRC2012_val_00017490.bin 224 224 +23399 ./prep_dataset/ILSVRC2012_val_00015889.bin 224 224 +23400 ./prep_dataset/ILSVRC2012_val_00005330.bin 224 224 +23401 ./prep_dataset/ILSVRC2012_val_00049713.bin 224 224 +23402 ./prep_dataset/ILSVRC2012_val_00027386.bin 224 224 +23403 ./prep_dataset/ILSVRC2012_val_00013728.bin 224 224 +23404 ./prep_dataset/ILSVRC2012_val_00020612.bin 224 224 +23405 ./prep_dataset/ILSVRC2012_val_00020959.bin 224 224 +23406 ./prep_dataset/ILSVRC2012_val_00008519.bin 224 224 +23407 ./prep_dataset/ILSVRC2012_val_00018130.bin 224 224 +23408 ./prep_dataset/ILSVRC2012_val_00009843.bin 224 224 +23409 ./prep_dataset/ILSVRC2012_val_00021916.bin 224 224 +23410 ./prep_dataset/ILSVRC2012_val_00019813.bin 224 224 +23411 ./prep_dataset/ILSVRC2012_val_00019953.bin 224 224 +23412 ./prep_dataset/ILSVRC2012_val_00031057.bin 224 224 +23413 ./prep_dataset/ILSVRC2012_val_00043917.bin 224 224 +23414 ./prep_dataset/ILSVRC2012_val_00039711.bin 224 224 +23415 ./prep_dataset/ILSVRC2012_val_00012306.bin 224 224 +23416 ./prep_dataset/ILSVRC2012_val_00032372.bin 224 224 +23417 ./prep_dataset/ILSVRC2012_val_00002841.bin 224 224 +23418 ./prep_dataset/ILSVRC2012_val_00038830.bin 224 224 +23419 ./prep_dataset/ILSVRC2012_val_00034132.bin 224 224 +23420 ./prep_dataset/ILSVRC2012_val_00027667.bin 224 224 +23421 ./prep_dataset/ILSVRC2012_val_00031451.bin 224 224 +23422 ./prep_dataset/ILSVRC2012_val_00023186.bin 224 224 +23423 ./prep_dataset/ILSVRC2012_val_00031466.bin 224 224 +23424 ./prep_dataset/ILSVRC2012_val_00015178.bin 224 224 +23425 ./prep_dataset/ILSVRC2012_val_00044471.bin 224 224 +23426 ./prep_dataset/ILSVRC2012_val_00024945.bin 224 224 +23427 ./prep_dataset/ILSVRC2012_val_00040353.bin 224 224 +23428 ./prep_dataset/ILSVRC2012_val_00025228.bin 224 224 +23429 ./prep_dataset/ILSVRC2012_val_00045275.bin 224 224 +23430 ./prep_dataset/ILSVRC2012_val_00011004.bin 224 224 +23431 ./prep_dataset/ILSVRC2012_val_00028569.bin 224 224 +23432 ./prep_dataset/ILSVRC2012_val_00015740.bin 224 224 +23433 ./prep_dataset/ILSVRC2012_val_00047378.bin 224 224 +23434 ./prep_dataset/ILSVRC2012_val_00044147.bin 224 224 +23435 ./prep_dataset/ILSVRC2012_val_00024456.bin 224 224 +23436 ./prep_dataset/ILSVRC2012_val_00024581.bin 224 224 +23437 ./prep_dataset/ILSVRC2012_val_00045116.bin 224 224 +23438 ./prep_dataset/ILSVRC2012_val_00003119.bin 224 224 +23439 ./prep_dataset/ILSVRC2012_val_00043313.bin 224 224 +23440 ./prep_dataset/ILSVRC2012_val_00041970.bin 224 224 +23441 ./prep_dataset/ILSVRC2012_val_00007542.bin 224 224 +23442 ./prep_dataset/ILSVRC2012_val_00048853.bin 224 224 +23443 ./prep_dataset/ILSVRC2012_val_00027370.bin 224 224 +23444 ./prep_dataset/ILSVRC2012_val_00019555.bin 224 224 +23445 ./prep_dataset/ILSVRC2012_val_00020478.bin 224 224 +23446 ./prep_dataset/ILSVRC2012_val_00013664.bin 224 224 +23447 ./prep_dataset/ILSVRC2012_val_00044193.bin 224 224 +23448 ./prep_dataset/ILSVRC2012_val_00019886.bin 224 224 +23449 ./prep_dataset/ILSVRC2012_val_00041347.bin 224 224 +23450 ./prep_dataset/ILSVRC2012_val_00019444.bin 224 224 +23451 ./prep_dataset/ILSVRC2012_val_00036814.bin 224 224 +23452 ./prep_dataset/ILSVRC2012_val_00019802.bin 224 224 +23453 ./prep_dataset/ILSVRC2012_val_00041631.bin 224 224 +23454 ./prep_dataset/ILSVRC2012_val_00023834.bin 224 224 +23455 ./prep_dataset/ILSVRC2012_val_00007867.bin 224 224 +23456 ./prep_dataset/ILSVRC2012_val_00006419.bin 224 224 +23457 ./prep_dataset/ILSVRC2012_val_00003107.bin 224 224 +23458 ./prep_dataset/ILSVRC2012_val_00011437.bin 224 224 +23459 ./prep_dataset/ILSVRC2012_val_00034349.bin 224 224 +23460 ./prep_dataset/ILSVRC2012_val_00021793.bin 224 224 +23461 ./prep_dataset/ILSVRC2012_val_00029608.bin 224 224 +23462 ./prep_dataset/ILSVRC2012_val_00018704.bin 224 224 +23463 ./prep_dataset/ILSVRC2012_val_00001940.bin 224 224 +23464 ./prep_dataset/ILSVRC2012_val_00012751.bin 224 224 +23465 ./prep_dataset/ILSVRC2012_val_00029758.bin 224 224 +23466 ./prep_dataset/ILSVRC2012_val_00043829.bin 224 224 +23467 ./prep_dataset/ILSVRC2012_val_00036787.bin 224 224 +23468 ./prep_dataset/ILSVRC2012_val_00035531.bin 224 224 +23469 ./prep_dataset/ILSVRC2012_val_00018732.bin 224 224 +23470 ./prep_dataset/ILSVRC2012_val_00021463.bin 224 224 +23471 ./prep_dataset/ILSVRC2012_val_00021534.bin 224 224 +23472 ./prep_dataset/ILSVRC2012_val_00005341.bin 224 224 +23473 ./prep_dataset/ILSVRC2012_val_00028870.bin 224 224 +23474 ./prep_dataset/ILSVRC2012_val_00002863.bin 224 224 +23475 ./prep_dataset/ILSVRC2012_val_00025698.bin 224 224 +23476 ./prep_dataset/ILSVRC2012_val_00032659.bin 224 224 +23477 ./prep_dataset/ILSVRC2012_val_00047316.bin 224 224 +23478 ./prep_dataset/ILSVRC2012_val_00028000.bin 224 224 +23479 ./prep_dataset/ILSVRC2012_val_00048503.bin 224 224 +23480 ./prep_dataset/ILSVRC2012_val_00044769.bin 224 224 +23481 ./prep_dataset/ILSVRC2012_val_00033971.bin 224 224 +23482 ./prep_dataset/ILSVRC2012_val_00023407.bin 224 224 +23483 ./prep_dataset/ILSVRC2012_val_00004653.bin 224 224 +23484 ./prep_dataset/ILSVRC2012_val_00027701.bin 224 224 +23485 ./prep_dataset/ILSVRC2012_val_00045437.bin 224 224 +23486 ./prep_dataset/ILSVRC2012_val_00004410.bin 224 224 +23487 ./prep_dataset/ILSVRC2012_val_00007571.bin 224 224 +23488 ./prep_dataset/ILSVRC2012_val_00048737.bin 224 224 +23489 ./prep_dataset/ILSVRC2012_val_00014706.bin 224 224 +23490 ./prep_dataset/ILSVRC2012_val_00007210.bin 224 224 +23491 ./prep_dataset/ILSVRC2012_val_00039848.bin 224 224 +23492 ./prep_dataset/ILSVRC2012_val_00005058.bin 224 224 +23493 ./prep_dataset/ILSVRC2012_val_00000026.bin 224 224 +23494 ./prep_dataset/ILSVRC2012_val_00045873.bin 224 224 +23495 ./prep_dataset/ILSVRC2012_val_00025943.bin 224 224 +23496 ./prep_dataset/ILSVRC2012_val_00019635.bin 224 224 +23497 ./prep_dataset/ILSVRC2012_val_00019417.bin 224 224 +23498 ./prep_dataset/ILSVRC2012_val_00002264.bin 224 224 +23499 ./prep_dataset/ILSVRC2012_val_00020568.bin 224 224 +23500 ./prep_dataset/ILSVRC2012_val_00034243.bin 224 224 +23501 ./prep_dataset/ILSVRC2012_val_00047480.bin 224 224 +23502 ./prep_dataset/ILSVRC2012_val_00028001.bin 224 224 +23503 ./prep_dataset/ILSVRC2012_val_00043782.bin 224 224 +23504 ./prep_dataset/ILSVRC2012_val_00042778.bin 224 224 +23505 ./prep_dataset/ILSVRC2012_val_00024673.bin 224 224 +23506 ./prep_dataset/ILSVRC2012_val_00008161.bin 224 224 +23507 ./prep_dataset/ILSVRC2012_val_00012726.bin 224 224 +23508 ./prep_dataset/ILSVRC2012_val_00006147.bin 224 224 +23509 ./prep_dataset/ILSVRC2012_val_00043649.bin 224 224 +23510 ./prep_dataset/ILSVRC2012_val_00042855.bin 224 224 +23511 ./prep_dataset/ILSVRC2012_val_00032368.bin 224 224 +23512 ./prep_dataset/ILSVRC2012_val_00037683.bin 224 224 +23513 ./prep_dataset/ILSVRC2012_val_00033837.bin 224 224 +23514 ./prep_dataset/ILSVRC2012_val_00035627.bin 224 224 +23515 ./prep_dataset/ILSVRC2012_val_00009697.bin 224 224 +23516 ./prep_dataset/ILSVRC2012_val_00045932.bin 224 224 +23517 ./prep_dataset/ILSVRC2012_val_00033005.bin 224 224 +23518 ./prep_dataset/ILSVRC2012_val_00015261.bin 224 224 +23519 ./prep_dataset/ILSVRC2012_val_00036268.bin 224 224 +23520 ./prep_dataset/ILSVRC2012_val_00007269.bin 224 224 +23521 ./prep_dataset/ILSVRC2012_val_00027465.bin 224 224 +23522 ./prep_dataset/ILSVRC2012_val_00019256.bin 224 224 +23523 ./prep_dataset/ILSVRC2012_val_00002311.bin 224 224 +23524 ./prep_dataset/ILSVRC2012_val_00032312.bin 224 224 +23525 ./prep_dataset/ILSVRC2012_val_00029760.bin 224 224 +23526 ./prep_dataset/ILSVRC2012_val_00003361.bin 224 224 +23527 ./prep_dataset/ILSVRC2012_val_00004180.bin 224 224 +23528 ./prep_dataset/ILSVRC2012_val_00019685.bin 224 224 +23529 ./prep_dataset/ILSVRC2012_val_00027614.bin 224 224 +23530 ./prep_dataset/ILSVRC2012_val_00017929.bin 224 224 +23531 ./prep_dataset/ILSVRC2012_val_00035400.bin 224 224 +23532 ./prep_dataset/ILSVRC2012_val_00043390.bin 224 224 +23533 ./prep_dataset/ILSVRC2012_val_00005032.bin 224 224 +23534 ./prep_dataset/ILSVRC2012_val_00032488.bin 224 224 +23535 ./prep_dataset/ILSVRC2012_val_00035360.bin 224 224 +23536 ./prep_dataset/ILSVRC2012_val_00006648.bin 224 224 +23537 ./prep_dataset/ILSVRC2012_val_00026790.bin 224 224 +23538 ./prep_dataset/ILSVRC2012_val_00039160.bin 224 224 +23539 ./prep_dataset/ILSVRC2012_val_00020472.bin 224 224 +23540 ./prep_dataset/ILSVRC2012_val_00015714.bin 224 224 +23541 ./prep_dataset/ILSVRC2012_val_00035216.bin 224 224 +23542 ./prep_dataset/ILSVRC2012_val_00026685.bin 224 224 +23543 ./prep_dataset/ILSVRC2012_val_00036257.bin 224 224 +23544 ./prep_dataset/ILSVRC2012_val_00033213.bin 224 224 +23545 ./prep_dataset/ILSVRC2012_val_00017114.bin 224 224 +23546 ./prep_dataset/ILSVRC2012_val_00040854.bin 224 224 +23547 ./prep_dataset/ILSVRC2012_val_00027209.bin 224 224 +23548 ./prep_dataset/ILSVRC2012_val_00019108.bin 224 224 +23549 ./prep_dataset/ILSVRC2012_val_00013065.bin 224 224 +23550 ./prep_dataset/ILSVRC2012_val_00008704.bin 224 224 +23551 ./prep_dataset/ILSVRC2012_val_00019028.bin 224 224 +23552 ./prep_dataset/ILSVRC2012_val_00037543.bin 224 224 +23553 ./prep_dataset/ILSVRC2012_val_00001969.bin 224 224 +23554 ./prep_dataset/ILSVRC2012_val_00038414.bin 224 224 +23555 ./prep_dataset/ILSVRC2012_val_00037615.bin 224 224 +23556 ./prep_dataset/ILSVRC2012_val_00026625.bin 224 224 +23557 ./prep_dataset/ILSVRC2012_val_00009055.bin 224 224 +23558 ./prep_dataset/ILSVRC2012_val_00030025.bin 224 224 +23559 ./prep_dataset/ILSVRC2012_val_00028218.bin 224 224 +23560 ./prep_dataset/ILSVRC2012_val_00026965.bin 224 224 +23561 ./prep_dataset/ILSVRC2012_val_00001971.bin 224 224 +23562 ./prep_dataset/ILSVRC2012_val_00026896.bin 224 224 +23563 ./prep_dataset/ILSVRC2012_val_00001355.bin 224 224 +23564 ./prep_dataset/ILSVRC2012_val_00013313.bin 224 224 +23565 ./prep_dataset/ILSVRC2012_val_00006457.bin 224 224 +23566 ./prep_dataset/ILSVRC2012_val_00042308.bin 224 224 +23567 ./prep_dataset/ILSVRC2012_val_00045705.bin 224 224 +23568 ./prep_dataset/ILSVRC2012_val_00022688.bin 224 224 +23569 ./prep_dataset/ILSVRC2012_val_00027548.bin 224 224 +23570 ./prep_dataset/ILSVRC2012_val_00000339.bin 224 224 +23571 ./prep_dataset/ILSVRC2012_val_00010666.bin 224 224 +23572 ./prep_dataset/ILSVRC2012_val_00039309.bin 224 224 +23573 ./prep_dataset/ILSVRC2012_val_00024036.bin 224 224 +23574 ./prep_dataset/ILSVRC2012_val_00037959.bin 224 224 +23575 ./prep_dataset/ILSVRC2012_val_00020252.bin 224 224 +23576 ./prep_dataset/ILSVRC2012_val_00006803.bin 224 224 +23577 ./prep_dataset/ILSVRC2012_val_00039345.bin 224 224 +23578 ./prep_dataset/ILSVRC2012_val_00040025.bin 224 224 +23579 ./prep_dataset/ILSVRC2012_val_00020269.bin 224 224 +23580 ./prep_dataset/ILSVRC2012_val_00024943.bin 224 224 +23581 ./prep_dataset/ILSVRC2012_val_00020822.bin 224 224 +23582 ./prep_dataset/ILSVRC2012_val_00041161.bin 224 224 +23583 ./prep_dataset/ILSVRC2012_val_00044287.bin 224 224 +23584 ./prep_dataset/ILSVRC2012_val_00008271.bin 224 224 +23585 ./prep_dataset/ILSVRC2012_val_00040351.bin 224 224 +23586 ./prep_dataset/ILSVRC2012_val_00012510.bin 224 224 +23587 ./prep_dataset/ILSVRC2012_val_00004811.bin 224 224 +23588 ./prep_dataset/ILSVRC2012_val_00025610.bin 224 224 +23589 ./prep_dataset/ILSVRC2012_val_00009347.bin 224 224 +23590 ./prep_dataset/ILSVRC2012_val_00042421.bin 224 224 +23591 ./prep_dataset/ILSVRC2012_val_00023955.bin 224 224 +23592 ./prep_dataset/ILSVRC2012_val_00020271.bin 224 224 +23593 ./prep_dataset/ILSVRC2012_val_00033769.bin 224 224 +23594 ./prep_dataset/ILSVRC2012_val_00033231.bin 224 224 +23595 ./prep_dataset/ILSVRC2012_val_00005215.bin 224 224 +23596 ./prep_dataset/ILSVRC2012_val_00027889.bin 224 224 +23597 ./prep_dataset/ILSVRC2012_val_00037779.bin 224 224 +23598 ./prep_dataset/ILSVRC2012_val_00006368.bin 224 224 +23599 ./prep_dataset/ILSVRC2012_val_00020305.bin 224 224 +23600 ./prep_dataset/ILSVRC2012_val_00035728.bin 224 224 +23601 ./prep_dataset/ILSVRC2012_val_00048973.bin 224 224 +23602 ./prep_dataset/ILSVRC2012_val_00022681.bin 224 224 +23603 ./prep_dataset/ILSVRC2012_val_00007372.bin 224 224 +23604 ./prep_dataset/ILSVRC2012_val_00007822.bin 224 224 +23605 ./prep_dataset/ILSVRC2012_val_00001776.bin 224 224 +23606 ./prep_dataset/ILSVRC2012_val_00009014.bin 224 224 +23607 ./prep_dataset/ILSVRC2012_val_00036797.bin 224 224 +23608 ./prep_dataset/ILSVRC2012_val_00045914.bin 224 224 +23609 ./prep_dataset/ILSVRC2012_val_00030317.bin 224 224 +23610 ./prep_dataset/ILSVRC2012_val_00033592.bin 224 224 +23611 ./prep_dataset/ILSVRC2012_val_00030686.bin 224 224 +23612 ./prep_dataset/ILSVRC2012_val_00000217.bin 224 224 +23613 ./prep_dataset/ILSVRC2012_val_00046547.bin 224 224 +23614 ./prep_dataset/ILSVRC2012_val_00007345.bin 224 224 +23615 ./prep_dataset/ILSVRC2012_val_00027593.bin 224 224 +23616 ./prep_dataset/ILSVRC2012_val_00042190.bin 224 224 +23617 ./prep_dataset/ILSVRC2012_val_00023630.bin 224 224 +23618 ./prep_dataset/ILSVRC2012_val_00021354.bin 224 224 +23619 ./prep_dataset/ILSVRC2012_val_00017570.bin 224 224 +23620 ./prep_dataset/ILSVRC2012_val_00006395.bin 224 224 +23621 ./prep_dataset/ILSVRC2012_val_00045362.bin 224 224 +23622 ./prep_dataset/ILSVRC2012_val_00014574.bin 224 224 +23623 ./prep_dataset/ILSVRC2012_val_00049461.bin 224 224 +23624 ./prep_dataset/ILSVRC2012_val_00035412.bin 224 224 +23625 ./prep_dataset/ILSVRC2012_val_00044249.bin 224 224 +23626 ./prep_dataset/ILSVRC2012_val_00039991.bin 224 224 +23627 ./prep_dataset/ILSVRC2012_val_00030007.bin 224 224 +23628 ./prep_dataset/ILSVRC2012_val_00007127.bin 224 224 +23629 ./prep_dataset/ILSVRC2012_val_00008484.bin 224 224 +23630 ./prep_dataset/ILSVRC2012_val_00013437.bin 224 224 +23631 ./prep_dataset/ILSVRC2012_val_00042681.bin 224 224 +23632 ./prep_dataset/ILSVRC2012_val_00002885.bin 224 224 +23633 ./prep_dataset/ILSVRC2012_val_00010789.bin 224 224 +23634 ./prep_dataset/ILSVRC2012_val_00048821.bin 224 224 +23635 ./prep_dataset/ILSVRC2012_val_00011589.bin 224 224 +23636 ./prep_dataset/ILSVRC2012_val_00048563.bin 224 224 +23637 ./prep_dataset/ILSVRC2012_val_00047121.bin 224 224 +23638 ./prep_dataset/ILSVRC2012_val_00022522.bin 224 224 +23639 ./prep_dataset/ILSVRC2012_val_00017391.bin 224 224 +23640 ./prep_dataset/ILSVRC2012_val_00027068.bin 224 224 +23641 ./prep_dataset/ILSVRC2012_val_00048497.bin 224 224 +23642 ./prep_dataset/ILSVRC2012_val_00048981.bin 224 224 +23643 ./prep_dataset/ILSVRC2012_val_00049502.bin 224 224 +23644 ./prep_dataset/ILSVRC2012_val_00014239.bin 224 224 +23645 ./prep_dataset/ILSVRC2012_val_00019609.bin 224 224 +23646 ./prep_dataset/ILSVRC2012_val_00013739.bin 224 224 +23647 ./prep_dataset/ILSVRC2012_val_00020859.bin 224 224 +23648 ./prep_dataset/ILSVRC2012_val_00011996.bin 224 224 +23649 ./prep_dataset/ILSVRC2012_val_00047428.bin 224 224 +23650 ./prep_dataset/ILSVRC2012_val_00000731.bin 224 224 +23651 ./prep_dataset/ILSVRC2012_val_00040366.bin 224 224 +23652 ./prep_dataset/ILSVRC2012_val_00041650.bin 224 224 +23653 ./prep_dataset/ILSVRC2012_val_00000652.bin 224 224 +23654 ./prep_dataset/ILSVRC2012_val_00049616.bin 224 224 +23655 ./prep_dataset/ILSVRC2012_val_00000684.bin 224 224 +23656 ./prep_dataset/ILSVRC2012_val_00024096.bin 224 224 +23657 ./prep_dataset/ILSVRC2012_val_00041591.bin 224 224 +23658 ./prep_dataset/ILSVRC2012_val_00014391.bin 224 224 +23659 ./prep_dataset/ILSVRC2012_val_00008872.bin 224 224 +23660 ./prep_dataset/ILSVRC2012_val_00008396.bin 224 224 +23661 ./prep_dataset/ILSVRC2012_val_00001429.bin 224 224 +23662 ./prep_dataset/ILSVRC2012_val_00032120.bin 224 224 +23663 ./prep_dataset/ILSVRC2012_val_00048754.bin 224 224 +23664 ./prep_dataset/ILSVRC2012_val_00010267.bin 224 224 +23665 ./prep_dataset/ILSVRC2012_val_00013157.bin 224 224 +23666 ./prep_dataset/ILSVRC2012_val_00038417.bin 224 224 +23667 ./prep_dataset/ILSVRC2012_val_00017418.bin 224 224 +23668 ./prep_dataset/ILSVRC2012_val_00029181.bin 224 224 +23669 ./prep_dataset/ILSVRC2012_val_00016927.bin 224 224 +23670 ./prep_dataset/ILSVRC2012_val_00021949.bin 224 224 +23671 ./prep_dataset/ILSVRC2012_val_00001715.bin 224 224 +23672 ./prep_dataset/ILSVRC2012_val_00038257.bin 224 224 +23673 ./prep_dataset/ILSVRC2012_val_00011847.bin 224 224 +23674 ./prep_dataset/ILSVRC2012_val_00044661.bin 224 224 +23675 ./prep_dataset/ILSVRC2012_val_00022608.bin 224 224 +23676 ./prep_dataset/ILSVRC2012_val_00015585.bin 224 224 +23677 ./prep_dataset/ILSVRC2012_val_00018836.bin 224 224 +23678 ./prep_dataset/ILSVRC2012_val_00014305.bin 224 224 +23679 ./prep_dataset/ILSVRC2012_val_00045136.bin 224 224 +23680 ./prep_dataset/ILSVRC2012_val_00023847.bin 224 224 +23681 ./prep_dataset/ILSVRC2012_val_00037916.bin 224 224 +23682 ./prep_dataset/ILSVRC2012_val_00023450.bin 224 224 +23683 ./prep_dataset/ILSVRC2012_val_00003605.bin 224 224 +23684 ./prep_dataset/ILSVRC2012_val_00004804.bin 224 224 +23685 ./prep_dataset/ILSVRC2012_val_00030905.bin 224 224 +23686 ./prep_dataset/ILSVRC2012_val_00035028.bin 224 224 +23687 ./prep_dataset/ILSVRC2012_val_00014543.bin 224 224 +23688 ./prep_dataset/ILSVRC2012_val_00034677.bin 224 224 +23689 ./prep_dataset/ILSVRC2012_val_00034954.bin 224 224 +23690 ./prep_dataset/ILSVRC2012_val_00047862.bin 224 224 +23691 ./prep_dataset/ILSVRC2012_val_00006938.bin 224 224 +23692 ./prep_dataset/ILSVRC2012_val_00003970.bin 224 224 +23693 ./prep_dataset/ILSVRC2012_val_00004317.bin 224 224 +23694 ./prep_dataset/ILSVRC2012_val_00036140.bin 224 224 +23695 ./prep_dataset/ILSVRC2012_val_00012295.bin 224 224 +23696 ./prep_dataset/ILSVRC2012_val_00048466.bin 224 224 +23697 ./prep_dataset/ILSVRC2012_val_00032082.bin 224 224 +23698 ./prep_dataset/ILSVRC2012_val_00038342.bin 224 224 +23699 ./prep_dataset/ILSVRC2012_val_00005736.bin 224 224 +23700 ./prep_dataset/ILSVRC2012_val_00035491.bin 224 224 +23701 ./prep_dataset/ILSVRC2012_val_00034181.bin 224 224 +23702 ./prep_dataset/ILSVRC2012_val_00040307.bin 224 224 +23703 ./prep_dataset/ILSVRC2012_val_00008423.bin 224 224 +23704 ./prep_dataset/ILSVRC2012_val_00010234.bin 224 224 +23705 ./prep_dataset/ILSVRC2012_val_00048785.bin 224 224 +23706 ./prep_dataset/ILSVRC2012_val_00029687.bin 224 224 +23707 ./prep_dataset/ILSVRC2012_val_00008683.bin 224 224 +23708 ./prep_dataset/ILSVRC2012_val_00026945.bin 224 224 +23709 ./prep_dataset/ILSVRC2012_val_00030060.bin 224 224 +23710 ./prep_dataset/ILSVRC2012_val_00049263.bin 224 224 +23711 ./prep_dataset/ILSVRC2012_val_00023180.bin 224 224 +23712 ./prep_dataset/ILSVRC2012_val_00028585.bin 224 224 +23713 ./prep_dataset/ILSVRC2012_val_00033047.bin 224 224 +23714 ./prep_dataset/ILSVRC2012_val_00035534.bin 224 224 +23715 ./prep_dataset/ILSVRC2012_val_00041502.bin 224 224 +23716 ./prep_dataset/ILSVRC2012_val_00009154.bin 224 224 +23717 ./prep_dataset/ILSVRC2012_val_00022450.bin 224 224 +23718 ./prep_dataset/ILSVRC2012_val_00010656.bin 224 224 +23719 ./prep_dataset/ILSVRC2012_val_00031433.bin 224 224 +23720 ./prep_dataset/ILSVRC2012_val_00028413.bin 224 224 +23721 ./prep_dataset/ILSVRC2012_val_00047029.bin 224 224 +23722 ./prep_dataset/ILSVRC2012_val_00004910.bin 224 224 +23723 ./prep_dataset/ILSVRC2012_val_00038885.bin 224 224 +23724 ./prep_dataset/ILSVRC2012_val_00027962.bin 224 224 +23725 ./prep_dataset/ILSVRC2012_val_00007853.bin 224 224 +23726 ./prep_dataset/ILSVRC2012_val_00022777.bin 224 224 +23727 ./prep_dataset/ILSVRC2012_val_00023410.bin 224 224 +23728 ./prep_dataset/ILSVRC2012_val_00002750.bin 224 224 +23729 ./prep_dataset/ILSVRC2012_val_00036117.bin 224 224 +23730 ./prep_dataset/ILSVRC2012_val_00017146.bin 224 224 +23731 ./prep_dataset/ILSVRC2012_val_00045360.bin 224 224 +23732 ./prep_dataset/ILSVRC2012_val_00039383.bin 224 224 +23733 ./prep_dataset/ILSVRC2012_val_00032214.bin 224 224 +23734 ./prep_dataset/ILSVRC2012_val_00004416.bin 224 224 +23735 ./prep_dataset/ILSVRC2012_val_00022148.bin 224 224 +23736 ./prep_dataset/ILSVRC2012_val_00034743.bin 224 224 +23737 ./prep_dataset/ILSVRC2012_val_00040069.bin 224 224 +23738 ./prep_dataset/ILSVRC2012_val_00029031.bin 224 224 +23739 ./prep_dataset/ILSVRC2012_val_00020005.bin 224 224 +23740 ./prep_dataset/ILSVRC2012_val_00033155.bin 224 224 +23741 ./prep_dataset/ILSVRC2012_val_00000677.bin 224 224 +23742 ./prep_dataset/ILSVRC2012_val_00027581.bin 224 224 +23743 ./prep_dataset/ILSVRC2012_val_00043552.bin 224 224 +23744 ./prep_dataset/ILSVRC2012_val_00048046.bin 224 224 +23745 ./prep_dataset/ILSVRC2012_val_00017253.bin 224 224 +23746 ./prep_dataset/ILSVRC2012_val_00010112.bin 224 224 +23747 ./prep_dataset/ILSVRC2012_val_00042569.bin 224 224 +23748 ./prep_dataset/ILSVRC2012_val_00049989.bin 224 224 +23749 ./prep_dataset/ILSVRC2012_val_00045298.bin 224 224 +23750 ./prep_dataset/ILSVRC2012_val_00025830.bin 224 224 +23751 ./prep_dataset/ILSVRC2012_val_00047541.bin 224 224 +23752 ./prep_dataset/ILSVRC2012_val_00037441.bin 224 224 +23753 ./prep_dataset/ILSVRC2012_val_00005010.bin 224 224 +23754 ./prep_dataset/ILSVRC2012_val_00011936.bin 224 224 +23755 ./prep_dataset/ILSVRC2012_val_00027639.bin 224 224 +23756 ./prep_dataset/ILSVRC2012_val_00040625.bin 224 224 +23757 ./prep_dataset/ILSVRC2012_val_00041593.bin 224 224 +23758 ./prep_dataset/ILSVRC2012_val_00038279.bin 224 224 +23759 ./prep_dataset/ILSVRC2012_val_00034586.bin 224 224 +23760 ./prep_dataset/ILSVRC2012_val_00002381.bin 224 224 +23761 ./prep_dataset/ILSVRC2012_val_00034483.bin 224 224 +23762 ./prep_dataset/ILSVRC2012_val_00019831.bin 224 224 +23763 ./prep_dataset/ILSVRC2012_val_00017302.bin 224 224 +23764 ./prep_dataset/ILSVRC2012_val_00024005.bin 224 224 +23765 ./prep_dataset/ILSVRC2012_val_00045105.bin 224 224 +23766 ./prep_dataset/ILSVRC2012_val_00047718.bin 224 224 +23767 ./prep_dataset/ILSVRC2012_val_00038133.bin 224 224 +23768 ./prep_dataset/ILSVRC2012_val_00015123.bin 224 224 +23769 ./prep_dataset/ILSVRC2012_val_00006321.bin 224 224 +23770 ./prep_dataset/ILSVRC2012_val_00001050.bin 224 224 +23771 ./prep_dataset/ILSVRC2012_val_00001206.bin 224 224 +23772 ./prep_dataset/ILSVRC2012_val_00028233.bin 224 224 +23773 ./prep_dataset/ILSVRC2012_val_00016289.bin 224 224 +23774 ./prep_dataset/ILSVRC2012_val_00018757.bin 224 224 +23775 ./prep_dataset/ILSVRC2012_val_00042910.bin 224 224 +23776 ./prep_dataset/ILSVRC2012_val_00026889.bin 224 224 +23777 ./prep_dataset/ILSVRC2012_val_00009271.bin 224 224 +23778 ./prep_dataset/ILSVRC2012_val_00049834.bin 224 224 +23779 ./prep_dataset/ILSVRC2012_val_00048803.bin 224 224 +23780 ./prep_dataset/ILSVRC2012_val_00049721.bin 224 224 +23781 ./prep_dataset/ILSVRC2012_val_00046965.bin 224 224 +23782 ./prep_dataset/ILSVRC2012_val_00023669.bin 224 224 +23783 ./prep_dataset/ILSVRC2012_val_00015202.bin 224 224 +23784 ./prep_dataset/ILSVRC2012_val_00032641.bin 224 224 +23785 ./prep_dataset/ILSVRC2012_val_00017169.bin 224 224 +23786 ./prep_dataset/ILSVRC2012_val_00049695.bin 224 224 +23787 ./prep_dataset/ILSVRC2012_val_00044998.bin 224 224 +23788 ./prep_dataset/ILSVRC2012_val_00016616.bin 224 224 +23789 ./prep_dataset/ILSVRC2012_val_00005440.bin 224 224 +23790 ./prep_dataset/ILSVRC2012_val_00010068.bin 224 224 +23791 ./prep_dataset/ILSVRC2012_val_00026179.bin 224 224 +23792 ./prep_dataset/ILSVRC2012_val_00028367.bin 224 224 +23793 ./prep_dataset/ILSVRC2012_val_00038993.bin 224 224 +23794 ./prep_dataset/ILSVRC2012_val_00030869.bin 224 224 +23795 ./prep_dataset/ILSVRC2012_val_00042762.bin 224 224 +23796 ./prep_dataset/ILSVRC2012_val_00028976.bin 224 224 +23797 ./prep_dataset/ILSVRC2012_val_00040601.bin 224 224 +23798 ./prep_dataset/ILSVRC2012_val_00034270.bin 224 224 +23799 ./prep_dataset/ILSVRC2012_val_00018586.bin 224 224 +23800 ./prep_dataset/ILSVRC2012_val_00036781.bin 224 224 +23801 ./prep_dataset/ILSVRC2012_val_00006686.bin 224 224 +23802 ./prep_dataset/ILSVRC2012_val_00027630.bin 224 224 +23803 ./prep_dataset/ILSVRC2012_val_00032307.bin 224 224 +23804 ./prep_dataset/ILSVRC2012_val_00033654.bin 224 224 +23805 ./prep_dataset/ILSVRC2012_val_00038161.bin 224 224 +23806 ./prep_dataset/ILSVRC2012_val_00045875.bin 224 224 +23807 ./prep_dataset/ILSVRC2012_val_00017504.bin 224 224 +23808 ./prep_dataset/ILSVRC2012_val_00007798.bin 224 224 +23809 ./prep_dataset/ILSVRC2012_val_00011754.bin 224 224 +23810 ./prep_dataset/ILSVRC2012_val_00036552.bin 224 224 +23811 ./prep_dataset/ILSVRC2012_val_00004973.bin 224 224 +23812 ./prep_dataset/ILSVRC2012_val_00005629.bin 224 224 +23813 ./prep_dataset/ILSVRC2012_val_00048951.bin 224 224 +23814 ./prep_dataset/ILSVRC2012_val_00030011.bin 224 224 +23815 ./prep_dataset/ILSVRC2012_val_00037158.bin 224 224 +23816 ./prep_dataset/ILSVRC2012_val_00039154.bin 224 224 +23817 ./prep_dataset/ILSVRC2012_val_00009592.bin 224 224 +23818 ./prep_dataset/ILSVRC2012_val_00017596.bin 224 224 +23819 ./prep_dataset/ILSVRC2012_val_00014505.bin 224 224 +23820 ./prep_dataset/ILSVRC2012_val_00049779.bin 224 224 +23821 ./prep_dataset/ILSVRC2012_val_00031396.bin 224 224 +23822 ./prep_dataset/ILSVRC2012_val_00040013.bin 224 224 +23823 ./prep_dataset/ILSVRC2012_val_00022036.bin 224 224 +23824 ./prep_dataset/ILSVRC2012_val_00034662.bin 224 224 +23825 ./prep_dataset/ILSVRC2012_val_00019137.bin 224 224 +23826 ./prep_dataset/ILSVRC2012_val_00005524.bin 224 224 +23827 ./prep_dataset/ILSVRC2012_val_00049108.bin 224 224 +23828 ./prep_dataset/ILSVRC2012_val_00012468.bin 224 224 +23829 ./prep_dataset/ILSVRC2012_val_00005808.bin 224 224 +23830 ./prep_dataset/ILSVRC2012_val_00046124.bin 224 224 +23831 ./prep_dataset/ILSVRC2012_val_00033189.bin 224 224 +23832 ./prep_dataset/ILSVRC2012_val_00021857.bin 224 224 +23833 ./prep_dataset/ILSVRC2012_val_00008859.bin 224 224 +23834 ./prep_dataset/ILSVRC2012_val_00034554.bin 224 224 +23835 ./prep_dataset/ILSVRC2012_val_00021069.bin 224 224 +23836 ./prep_dataset/ILSVRC2012_val_00009010.bin 224 224 +23837 ./prep_dataset/ILSVRC2012_val_00035591.bin 224 224 +23838 ./prep_dataset/ILSVRC2012_val_00016884.bin 224 224 +23839 ./prep_dataset/ILSVRC2012_val_00000252.bin 224 224 +23840 ./prep_dataset/ILSVRC2012_val_00014228.bin 224 224 +23841 ./prep_dataset/ILSVRC2012_val_00015039.bin 224 224 +23842 ./prep_dataset/ILSVRC2012_val_00040860.bin 224 224 +23843 ./prep_dataset/ILSVRC2012_val_00038702.bin 224 224 +23844 ./prep_dataset/ILSVRC2012_val_00006341.bin 224 224 +23845 ./prep_dataset/ILSVRC2012_val_00023263.bin 224 224 +23846 ./prep_dataset/ILSVRC2012_val_00037207.bin 224 224 +23847 ./prep_dataset/ILSVRC2012_val_00044697.bin 224 224 +23848 ./prep_dataset/ILSVRC2012_val_00048516.bin 224 224 +23849 ./prep_dataset/ILSVRC2012_val_00044305.bin 224 224 +23850 ./prep_dataset/ILSVRC2012_val_00039945.bin 224 224 +23851 ./prep_dataset/ILSVRC2012_val_00042576.bin 224 224 +23852 ./prep_dataset/ILSVRC2012_val_00006416.bin 224 224 +23853 ./prep_dataset/ILSVRC2012_val_00001727.bin 224 224 +23854 ./prep_dataset/ILSVRC2012_val_00010246.bin 224 224 +23855 ./prep_dataset/ILSVRC2012_val_00035828.bin 224 224 +23856 ./prep_dataset/ILSVRC2012_val_00038805.bin 224 224 +23857 ./prep_dataset/ILSVRC2012_val_00012100.bin 224 224 +23858 ./prep_dataset/ILSVRC2012_val_00011949.bin 224 224 +23859 ./prep_dataset/ILSVRC2012_val_00020133.bin 224 224 +23860 ./prep_dataset/ILSVRC2012_val_00001599.bin 224 224 +23861 ./prep_dataset/ILSVRC2012_val_00048224.bin 224 224 +23862 ./prep_dataset/ILSVRC2012_val_00016869.bin 224 224 +23863 ./prep_dataset/ILSVRC2012_val_00014988.bin 224 224 +23864 ./prep_dataset/ILSVRC2012_val_00017609.bin 224 224 +23865 ./prep_dataset/ILSVRC2012_val_00013237.bin 224 224 +23866 ./prep_dataset/ILSVRC2012_val_00014169.bin 224 224 +23867 ./prep_dataset/ILSVRC2012_val_00000424.bin 224 224 +23868 ./prep_dataset/ILSVRC2012_val_00021406.bin 224 224 +23869 ./prep_dataset/ILSVRC2012_val_00018198.bin 224 224 +23870 ./prep_dataset/ILSVRC2012_val_00019712.bin 224 224 +23871 ./prep_dataset/ILSVRC2012_val_00034447.bin 224 224 +23872 ./prep_dataset/ILSVRC2012_val_00003027.bin 224 224 +23873 ./prep_dataset/ILSVRC2012_val_00027404.bin 224 224 +23874 ./prep_dataset/ILSVRC2012_val_00047182.bin 224 224 +23875 ./prep_dataset/ILSVRC2012_val_00042108.bin 224 224 +23876 ./prep_dataset/ILSVRC2012_val_00006693.bin 224 224 +23877 ./prep_dataset/ILSVRC2012_val_00010134.bin 224 224 +23878 ./prep_dataset/ILSVRC2012_val_00042471.bin 224 224 +23879 ./prep_dataset/ILSVRC2012_val_00038344.bin 224 224 +23880 ./prep_dataset/ILSVRC2012_val_00008906.bin 224 224 +23881 ./prep_dataset/ILSVRC2012_val_00045394.bin 224 224 +23882 ./prep_dataset/ILSVRC2012_val_00013961.bin 224 224 +23883 ./prep_dataset/ILSVRC2012_val_00023351.bin 224 224 +23884 ./prep_dataset/ILSVRC2012_val_00014519.bin 224 224 +23885 ./prep_dataset/ILSVRC2012_val_00022876.bin 224 224 +23886 ./prep_dataset/ILSVRC2012_val_00017171.bin 224 224 +23887 ./prep_dataset/ILSVRC2012_val_00009696.bin 224 224 +23888 ./prep_dataset/ILSVRC2012_val_00012566.bin 224 224 +23889 ./prep_dataset/ILSVRC2012_val_00003174.bin 224 224 +23890 ./prep_dataset/ILSVRC2012_val_00049982.bin 224 224 +23891 ./prep_dataset/ILSVRC2012_val_00034377.bin 224 224 +23892 ./prep_dataset/ILSVRC2012_val_00018960.bin 224 224 +23893 ./prep_dataset/ILSVRC2012_val_00007860.bin 224 224 +23894 ./prep_dataset/ILSVRC2012_val_00027663.bin 224 224 +23895 ./prep_dataset/ILSVRC2012_val_00021246.bin 224 224 +23896 ./prep_dataset/ILSVRC2012_val_00021140.bin 224 224 +23897 ./prep_dataset/ILSVRC2012_val_00041721.bin 224 224 +23898 ./prep_dataset/ILSVRC2012_val_00048688.bin 224 224 +23899 ./prep_dataset/ILSVRC2012_val_00046954.bin 224 224 +23900 ./prep_dataset/ILSVRC2012_val_00031566.bin 224 224 +23901 ./prep_dataset/ILSVRC2012_val_00037884.bin 224 224 +23902 ./prep_dataset/ILSVRC2012_val_00016842.bin 224 224 +23903 ./prep_dataset/ILSVRC2012_val_00011827.bin 224 224 +23904 ./prep_dataset/ILSVRC2012_val_00005851.bin 224 224 +23905 ./prep_dataset/ILSVRC2012_val_00039028.bin 224 224 +23906 ./prep_dataset/ILSVRC2012_val_00005501.bin 224 224 +23907 ./prep_dataset/ILSVRC2012_val_00034171.bin 224 224 +23908 ./prep_dataset/ILSVRC2012_val_00019500.bin 224 224 +23909 ./prep_dataset/ILSVRC2012_val_00035320.bin 224 224 +23910 ./prep_dataset/ILSVRC2012_val_00049259.bin 224 224 +23911 ./prep_dataset/ILSVRC2012_val_00030999.bin 224 224 +23912 ./prep_dataset/ILSVRC2012_val_00026222.bin 224 224 +23913 ./prep_dataset/ILSVRC2012_val_00045529.bin 224 224 +23914 ./prep_dataset/ILSVRC2012_val_00041540.bin 224 224 +23915 ./prep_dataset/ILSVRC2012_val_00008833.bin 224 224 +23916 ./prep_dataset/ILSVRC2012_val_00035560.bin 224 224 +23917 ./prep_dataset/ILSVRC2012_val_00042388.bin 224 224 +23918 ./prep_dataset/ILSVRC2012_val_00021364.bin 224 224 +23919 ./prep_dataset/ILSVRC2012_val_00011415.bin 224 224 +23920 ./prep_dataset/ILSVRC2012_val_00015257.bin 224 224 +23921 ./prep_dataset/ILSVRC2012_val_00025246.bin 224 224 +23922 ./prep_dataset/ILSVRC2012_val_00011074.bin 224 224 +23923 ./prep_dataset/ILSVRC2012_val_00046543.bin 224 224 +23924 ./prep_dataset/ILSVRC2012_val_00007381.bin 224 224 +23925 ./prep_dataset/ILSVRC2012_val_00024612.bin 224 224 +23926 ./prep_dataset/ILSVRC2012_val_00001051.bin 224 224 +23927 ./prep_dataset/ILSVRC2012_val_00039761.bin 224 224 +23928 ./prep_dataset/ILSVRC2012_val_00007923.bin 224 224 +23929 ./prep_dataset/ILSVRC2012_val_00004822.bin 224 224 +23930 ./prep_dataset/ILSVRC2012_val_00037513.bin 224 224 +23931 ./prep_dataset/ILSVRC2012_val_00004225.bin 224 224 +23932 ./prep_dataset/ILSVRC2012_val_00015410.bin 224 224 +23933 ./prep_dataset/ILSVRC2012_val_00013600.bin 224 224 +23934 ./prep_dataset/ILSVRC2012_val_00031331.bin 224 224 +23935 ./prep_dataset/ILSVRC2012_val_00010491.bin 224 224 +23936 ./prep_dataset/ILSVRC2012_val_00010878.bin 224 224 +23937 ./prep_dataset/ILSVRC2012_val_00015799.bin 224 224 +23938 ./prep_dataset/ILSVRC2012_val_00007073.bin 224 224 +23939 ./prep_dataset/ILSVRC2012_val_00023540.bin 224 224 +23940 ./prep_dataset/ILSVRC2012_val_00032657.bin 224 224 +23941 ./prep_dataset/ILSVRC2012_val_00042481.bin 224 224 +23942 ./prep_dataset/ILSVRC2012_val_00010446.bin 224 224 +23943 ./prep_dataset/ILSVRC2012_val_00031405.bin 224 224 +23944 ./prep_dataset/ILSVRC2012_val_00007404.bin 224 224 +23945 ./prep_dataset/ILSVRC2012_val_00030333.bin 224 224 +23946 ./prep_dataset/ILSVRC2012_val_00003120.bin 224 224 +23947 ./prep_dataset/ILSVRC2012_val_00048227.bin 224 224 +23948 ./prep_dataset/ILSVRC2012_val_00036139.bin 224 224 +23949 ./prep_dataset/ILSVRC2012_val_00007177.bin 224 224 +23950 ./prep_dataset/ILSVRC2012_val_00001813.bin 224 224 +23951 ./prep_dataset/ILSVRC2012_val_00037442.bin 224 224 +23952 ./prep_dataset/ILSVRC2012_val_00012551.bin 224 224 +23953 ./prep_dataset/ILSVRC2012_val_00014363.bin 224 224 +23954 ./prep_dataset/ILSVRC2012_val_00036045.bin 224 224 +23955 ./prep_dataset/ILSVRC2012_val_00031266.bin 224 224 +23956 ./prep_dataset/ILSVRC2012_val_00017007.bin 224 224 +23957 ./prep_dataset/ILSVRC2012_val_00044765.bin 224 224 +23958 ./prep_dataset/ILSVRC2012_val_00020909.bin 224 224 +23959 ./prep_dataset/ILSVRC2012_val_00021832.bin 224 224 +23960 ./prep_dataset/ILSVRC2012_val_00021757.bin 224 224 +23961 ./prep_dataset/ILSVRC2012_val_00043765.bin 224 224 +23962 ./prep_dataset/ILSVRC2012_val_00010815.bin 224 224 +23963 ./prep_dataset/ILSVRC2012_val_00026169.bin 224 224 +23964 ./prep_dataset/ILSVRC2012_val_00032538.bin 224 224 +23965 ./prep_dataset/ILSVRC2012_val_00032758.bin 224 224 +23966 ./prep_dataset/ILSVRC2012_val_00004174.bin 224 224 +23967 ./prep_dataset/ILSVRC2012_val_00022218.bin 224 224 +23968 ./prep_dataset/ILSVRC2012_val_00044446.bin 224 224 +23969 ./prep_dataset/ILSVRC2012_val_00022961.bin 224 224 +23970 ./prep_dataset/ILSVRC2012_val_00039361.bin 224 224 +23971 ./prep_dataset/ILSVRC2012_val_00023030.bin 224 224 +23972 ./prep_dataset/ILSVRC2012_val_00031581.bin 224 224 +23973 ./prep_dataset/ILSVRC2012_val_00039319.bin 224 224 +23974 ./prep_dataset/ILSVRC2012_val_00006629.bin 224 224 +23975 ./prep_dataset/ILSVRC2012_val_00044519.bin 224 224 +23976 ./prep_dataset/ILSVRC2012_val_00048124.bin 224 224 +23977 ./prep_dataset/ILSVRC2012_val_00019895.bin 224 224 +23978 ./prep_dataset/ILSVRC2012_val_00026425.bin 224 224 +23979 ./prep_dataset/ILSVRC2012_val_00007405.bin 224 224 +23980 ./prep_dataset/ILSVRC2012_val_00029268.bin 224 224 +23981 ./prep_dataset/ILSVRC2012_val_00039884.bin 224 224 +23982 ./prep_dataset/ILSVRC2012_val_00040157.bin 224 224 +23983 ./prep_dataset/ILSVRC2012_val_00033459.bin 224 224 +23984 ./prep_dataset/ILSVRC2012_val_00011951.bin 224 224 +23985 ./prep_dataset/ILSVRC2012_val_00048199.bin 224 224 +23986 ./prep_dataset/ILSVRC2012_val_00016070.bin 224 224 +23987 ./prep_dataset/ILSVRC2012_val_00012439.bin 224 224 +23988 ./prep_dataset/ILSVRC2012_val_00021570.bin 224 224 +23989 ./prep_dataset/ILSVRC2012_val_00012614.bin 224 224 +23990 ./prep_dataset/ILSVRC2012_val_00008915.bin 224 224 +23991 ./prep_dataset/ILSVRC2012_val_00034288.bin 224 224 +23992 ./prep_dataset/ILSVRC2012_val_00010326.bin 224 224 +23993 ./prep_dataset/ILSVRC2012_val_00022019.bin 224 224 +23994 ./prep_dataset/ILSVRC2012_val_00003369.bin 224 224 +23995 ./prep_dataset/ILSVRC2012_val_00002826.bin 224 224 +23996 ./prep_dataset/ILSVRC2012_val_00033297.bin 224 224 +23997 ./prep_dataset/ILSVRC2012_val_00044927.bin 224 224 +23998 ./prep_dataset/ILSVRC2012_val_00044410.bin 224 224 +23999 ./prep_dataset/ILSVRC2012_val_00017960.bin 224 224 +24000 ./prep_dataset/ILSVRC2012_val_00028327.bin 224 224 +24001 ./prep_dataset/ILSVRC2012_val_00016558.bin 224 224 +24002 ./prep_dataset/ILSVRC2012_val_00018355.bin 224 224 +24003 ./prep_dataset/ILSVRC2012_val_00001841.bin 224 224 +24004 ./prep_dataset/ILSVRC2012_val_00046078.bin 224 224 +24005 ./prep_dataset/ILSVRC2012_val_00021233.bin 224 224 +24006 ./prep_dataset/ILSVRC2012_val_00039484.bin 224 224 +24007 ./prep_dataset/ILSVRC2012_val_00010119.bin 224 224 +24008 ./prep_dataset/ILSVRC2012_val_00027168.bin 224 224 +24009 ./prep_dataset/ILSVRC2012_val_00038983.bin 224 224 +24010 ./prep_dataset/ILSVRC2012_val_00021621.bin 224 224 +24011 ./prep_dataset/ILSVRC2012_val_00029558.bin 224 224 +24012 ./prep_dataset/ILSVRC2012_val_00023800.bin 224 224 +24013 ./prep_dataset/ILSVRC2012_val_00007575.bin 224 224 +24014 ./prep_dataset/ILSVRC2012_val_00048792.bin 224 224 +24015 ./prep_dataset/ILSVRC2012_val_00000920.bin 224 224 +24016 ./prep_dataset/ILSVRC2012_val_00031447.bin 224 224 +24017 ./prep_dataset/ILSVRC2012_val_00006619.bin 224 224 +24018 ./prep_dataset/ILSVRC2012_val_00006159.bin 224 224 +24019 ./prep_dataset/ILSVRC2012_val_00045994.bin 224 224 +24020 ./prep_dataset/ILSVRC2012_val_00004627.bin 224 224 +24021 ./prep_dataset/ILSVRC2012_val_00032717.bin 224 224 +24022 ./prep_dataset/ILSVRC2012_val_00045236.bin 224 224 +24023 ./prep_dataset/ILSVRC2012_val_00001616.bin 224 224 +24024 ./prep_dataset/ILSVRC2012_val_00027180.bin 224 224 +24025 ./prep_dataset/ILSVRC2012_val_00015110.bin 224 224 +24026 ./prep_dataset/ILSVRC2012_val_00001427.bin 224 224 +24027 ./prep_dataset/ILSVRC2012_val_00047868.bin 224 224 +24028 ./prep_dataset/ILSVRC2012_val_00023683.bin 224 224 +24029 ./prep_dataset/ILSVRC2012_val_00015670.bin 224 224 +24030 ./prep_dataset/ILSVRC2012_val_00000394.bin 224 224 +24031 ./prep_dataset/ILSVRC2012_val_00037196.bin 224 224 +24032 ./prep_dataset/ILSVRC2012_val_00036368.bin 224 224 +24033 ./prep_dataset/ILSVRC2012_val_00033349.bin 224 224 +24034 ./prep_dataset/ILSVRC2012_val_00005073.bin 224 224 +24035 ./prep_dataset/ILSVRC2012_val_00011503.bin 224 224 +24036 ./prep_dataset/ILSVRC2012_val_00038693.bin 224 224 +24037 ./prep_dataset/ILSVRC2012_val_00048765.bin 224 224 +24038 ./prep_dataset/ILSVRC2012_val_00032524.bin 224 224 +24039 ./prep_dataset/ILSVRC2012_val_00029207.bin 224 224 +24040 ./prep_dataset/ILSVRC2012_val_00018547.bin 224 224 +24041 ./prep_dataset/ILSVRC2012_val_00047553.bin 224 224 +24042 ./prep_dataset/ILSVRC2012_val_00049704.bin 224 224 +24043 ./prep_dataset/ILSVRC2012_val_00018135.bin 224 224 +24044 ./prep_dataset/ILSVRC2012_val_00020944.bin 224 224 +24045 ./prep_dataset/ILSVRC2012_val_00038969.bin 224 224 +24046 ./prep_dataset/ILSVRC2012_val_00035090.bin 224 224 +24047 ./prep_dataset/ILSVRC2012_val_00042139.bin 224 224 +24048 ./prep_dataset/ILSVRC2012_val_00021288.bin 224 224 +24049 ./prep_dataset/ILSVRC2012_val_00048184.bin 224 224 +24050 ./prep_dataset/ILSVRC2012_val_00014468.bin 224 224 +24051 ./prep_dataset/ILSVRC2012_val_00012990.bin 224 224 +24052 ./prep_dataset/ILSVRC2012_val_00048136.bin 224 224 +24053 ./prep_dataset/ILSVRC2012_val_00012359.bin 224 224 +24054 ./prep_dataset/ILSVRC2012_val_00033066.bin 224 224 +24055 ./prep_dataset/ILSVRC2012_val_00007488.bin 224 224 +24056 ./prep_dataset/ILSVRC2012_val_00034478.bin 224 224 +24057 ./prep_dataset/ILSVRC2012_val_00044160.bin 224 224 +24058 ./prep_dataset/ILSVRC2012_val_00007877.bin 224 224 +24059 ./prep_dataset/ILSVRC2012_val_00031366.bin 224 224 +24060 ./prep_dataset/ILSVRC2012_val_00002590.bin 224 224 +24061 ./prep_dataset/ILSVRC2012_val_00009026.bin 224 224 +24062 ./prep_dataset/ILSVRC2012_val_00005649.bin 224 224 +24063 ./prep_dataset/ILSVRC2012_val_00036553.bin 224 224 +24064 ./prep_dataset/ILSVRC2012_val_00020825.bin 224 224 +24065 ./prep_dataset/ILSVRC2012_val_00009788.bin 224 224 +24066 ./prep_dataset/ILSVRC2012_val_00015196.bin 224 224 +24067 ./prep_dataset/ILSVRC2012_val_00003305.bin 224 224 +24068 ./prep_dataset/ILSVRC2012_val_00047590.bin 224 224 +24069 ./prep_dataset/ILSVRC2012_val_00014820.bin 224 224 +24070 ./prep_dataset/ILSVRC2012_val_00009637.bin 224 224 +24071 ./prep_dataset/ILSVRC2012_val_00002610.bin 224 224 +24072 ./prep_dataset/ILSVRC2012_val_00018908.bin 224 224 +24073 ./prep_dataset/ILSVRC2012_val_00022048.bin 224 224 +24074 ./prep_dataset/ILSVRC2012_val_00004148.bin 224 224 +24075 ./prep_dataset/ILSVRC2012_val_00036926.bin 224 224 +24076 ./prep_dataset/ILSVRC2012_val_00048399.bin 224 224 +24077 ./prep_dataset/ILSVRC2012_val_00001179.bin 224 224 +24078 ./prep_dataset/ILSVRC2012_val_00002641.bin 224 224 +24079 ./prep_dataset/ILSVRC2012_val_00045128.bin 224 224 +24080 ./prep_dataset/ILSVRC2012_val_00009485.bin 224 224 +24081 ./prep_dataset/ILSVRC2012_val_00000801.bin 224 224 +24082 ./prep_dataset/ILSVRC2012_val_00007944.bin 224 224 +24083 ./prep_dataset/ILSVRC2012_val_00039856.bin 224 224 +24084 ./prep_dataset/ILSVRC2012_val_00016858.bin 224 224 +24085 ./prep_dataset/ILSVRC2012_val_00016182.bin 224 224 +24086 ./prep_dataset/ILSVRC2012_val_00036069.bin 224 224 +24087 ./prep_dataset/ILSVRC2012_val_00008827.bin 224 224 +24088 ./prep_dataset/ILSVRC2012_val_00014283.bin 224 224 +24089 ./prep_dataset/ILSVRC2012_val_00022044.bin 224 224 +24090 ./prep_dataset/ILSVRC2012_val_00010804.bin 224 224 +24091 ./prep_dataset/ILSVRC2012_val_00010415.bin 224 224 +24092 ./prep_dataset/ILSVRC2012_val_00047646.bin 224 224 +24093 ./prep_dataset/ILSVRC2012_val_00039175.bin 224 224 +24094 ./prep_dataset/ILSVRC2012_val_00022374.bin 224 224 +24095 ./prep_dataset/ILSVRC2012_val_00049825.bin 224 224 +24096 ./prep_dataset/ILSVRC2012_val_00020040.bin 224 224 +24097 ./prep_dataset/ILSVRC2012_val_00000326.bin 224 224 +24098 ./prep_dataset/ILSVRC2012_val_00002111.bin 224 224 +24099 ./prep_dataset/ILSVRC2012_val_00017332.bin 224 224 +24100 ./prep_dataset/ILSVRC2012_val_00048897.bin 224 224 +24101 ./prep_dataset/ILSVRC2012_val_00001879.bin 224 224 +24102 ./prep_dataset/ILSVRC2012_val_00033326.bin 224 224 +24103 ./prep_dataset/ILSVRC2012_val_00013290.bin 224 224 +24104 ./prep_dataset/ILSVRC2012_val_00016689.bin 224 224 +24105 ./prep_dataset/ILSVRC2012_val_00005011.bin 224 224 +24106 ./prep_dataset/ILSVRC2012_val_00037598.bin 224 224 +24107 ./prep_dataset/ILSVRC2012_val_00017991.bin 224 224 +24108 ./prep_dataset/ILSVRC2012_val_00011479.bin 224 224 +24109 ./prep_dataset/ILSVRC2012_val_00012659.bin 224 224 +24110 ./prep_dataset/ILSVRC2012_val_00044730.bin 224 224 +24111 ./prep_dataset/ILSVRC2012_val_00039952.bin 224 224 +24112 ./prep_dataset/ILSVRC2012_val_00011039.bin 224 224 +24113 ./prep_dataset/ILSVRC2012_val_00040724.bin 224 224 +24114 ./prep_dataset/ILSVRC2012_val_00007706.bin 224 224 +24115 ./prep_dataset/ILSVRC2012_val_00036588.bin 224 224 +24116 ./prep_dataset/ILSVRC2012_val_00049963.bin 224 224 +24117 ./prep_dataset/ILSVRC2012_val_00014917.bin 224 224 +24118 ./prep_dataset/ILSVRC2012_val_00029607.bin 224 224 +24119 ./prep_dataset/ILSVRC2012_val_00045142.bin 224 224 +24120 ./prep_dataset/ILSVRC2012_val_00009554.bin 224 224 +24121 ./prep_dataset/ILSVRC2012_val_00045515.bin 224 224 +24122 ./prep_dataset/ILSVRC2012_val_00024835.bin 224 224 +24123 ./prep_dataset/ILSVRC2012_val_00010977.bin 224 224 +24124 ./prep_dataset/ILSVRC2012_val_00025201.bin 224 224 +24125 ./prep_dataset/ILSVRC2012_val_00008095.bin 224 224 +24126 ./prep_dataset/ILSVRC2012_val_00003390.bin 224 224 +24127 ./prep_dataset/ILSVRC2012_val_00012302.bin 224 224 +24128 ./prep_dataset/ILSVRC2012_val_00037018.bin 224 224 +24129 ./prep_dataset/ILSVRC2012_val_00021236.bin 224 224 +24130 ./prep_dataset/ILSVRC2012_val_00024416.bin 224 224 +24131 ./prep_dataset/ILSVRC2012_val_00017959.bin 224 224 +24132 ./prep_dataset/ILSVRC2012_val_00020952.bin 224 224 +24133 ./prep_dataset/ILSVRC2012_val_00044920.bin 224 224 +24134 ./prep_dataset/ILSVRC2012_val_00025096.bin 224 224 +24135 ./prep_dataset/ILSVRC2012_val_00042053.bin 224 224 +24136 ./prep_dataset/ILSVRC2012_val_00009995.bin 224 224 +24137 ./prep_dataset/ILSVRC2012_val_00036051.bin 224 224 +24138 ./prep_dataset/ILSVRC2012_val_00009362.bin 224 224 +24139 ./prep_dataset/ILSVRC2012_val_00032341.bin 224 224 +24140 ./prep_dataset/ILSVRC2012_val_00037089.bin 224 224 +24141 ./prep_dataset/ILSVRC2012_val_00031192.bin 224 224 +24142 ./prep_dataset/ILSVRC2012_val_00026871.bin 224 224 +24143 ./prep_dataset/ILSVRC2012_val_00004676.bin 224 224 +24144 ./prep_dataset/ILSVRC2012_val_00000334.bin 224 224 +24145 ./prep_dataset/ILSVRC2012_val_00019538.bin 224 224 +24146 ./prep_dataset/ILSVRC2012_val_00022414.bin 224 224 +24147 ./prep_dataset/ILSVRC2012_val_00038648.bin 224 224 +24148 ./prep_dataset/ILSVRC2012_val_00029054.bin 224 224 +24149 ./prep_dataset/ILSVRC2012_val_00001043.bin 224 224 +24150 ./prep_dataset/ILSVRC2012_val_00039751.bin 224 224 +24151 ./prep_dataset/ILSVRC2012_val_00026438.bin 224 224 +24152 ./prep_dataset/ILSVRC2012_val_00012145.bin 224 224 +24153 ./prep_dataset/ILSVRC2012_val_00006676.bin 224 224 +24154 ./prep_dataset/ILSVRC2012_val_00017465.bin 224 224 +24155 ./prep_dataset/ILSVRC2012_val_00023100.bin 224 224 +24156 ./prep_dataset/ILSVRC2012_val_00048681.bin 224 224 +24157 ./prep_dataset/ILSVRC2012_val_00011924.bin 224 224 +24158 ./prep_dataset/ILSVRC2012_val_00014179.bin 224 224 +24159 ./prep_dataset/ILSVRC2012_val_00049666.bin 224 224 +24160 ./prep_dataset/ILSVRC2012_val_00033710.bin 224 224 +24161 ./prep_dataset/ILSVRC2012_val_00004171.bin 224 224 +24162 ./prep_dataset/ILSVRC2012_val_00006401.bin 224 224 +24163 ./prep_dataset/ILSVRC2012_val_00024919.bin 224 224 +24164 ./prep_dataset/ILSVRC2012_val_00003762.bin 224 224 +24165 ./prep_dataset/ILSVRC2012_val_00017058.bin 224 224 +24166 ./prep_dataset/ILSVRC2012_val_00033571.bin 224 224 +24167 ./prep_dataset/ILSVRC2012_val_00027399.bin 224 224 +24168 ./prep_dataset/ILSVRC2012_val_00004194.bin 224 224 +24169 ./prep_dataset/ILSVRC2012_val_00049142.bin 224 224 +24170 ./prep_dataset/ILSVRC2012_val_00013223.bin 224 224 +24171 ./prep_dataset/ILSVRC2012_val_00008761.bin 224 224 +24172 ./prep_dataset/ILSVRC2012_val_00016118.bin 224 224 +24173 ./prep_dataset/ILSVRC2012_val_00041464.bin 224 224 +24174 ./prep_dataset/ILSVRC2012_val_00021194.bin 224 224 +24175 ./prep_dataset/ILSVRC2012_val_00015682.bin 224 224 +24176 ./prep_dataset/ILSVRC2012_val_00020938.bin 224 224 +24177 ./prep_dataset/ILSVRC2012_val_00016960.bin 224 224 +24178 ./prep_dataset/ILSVRC2012_val_00008614.bin 224 224 +24179 ./prep_dataset/ILSVRC2012_val_00016940.bin 224 224 +24180 ./prep_dataset/ILSVRC2012_val_00045907.bin 224 224 +24181 ./prep_dataset/ILSVRC2012_val_00010994.bin 224 224 +24182 ./prep_dataset/ILSVRC2012_val_00025840.bin 224 224 +24183 ./prep_dataset/ILSVRC2012_val_00006730.bin 224 224 +24184 ./prep_dataset/ILSVRC2012_val_00019579.bin 224 224 +24185 ./prep_dataset/ILSVRC2012_val_00002013.bin 224 224 +24186 ./prep_dataset/ILSVRC2012_val_00001876.bin 224 224 +24187 ./prep_dataset/ILSVRC2012_val_00022892.bin 224 224 +24188 ./prep_dataset/ILSVRC2012_val_00003570.bin 224 224 +24189 ./prep_dataset/ILSVRC2012_val_00031526.bin 224 224 +24190 ./prep_dataset/ILSVRC2012_val_00018165.bin 224 224 +24191 ./prep_dataset/ILSVRC2012_val_00034764.bin 224 224 +24192 ./prep_dataset/ILSVRC2012_val_00000811.bin 224 224 +24193 ./prep_dataset/ILSVRC2012_val_00026602.bin 224 224 +24194 ./prep_dataset/ILSVRC2012_val_00008747.bin 224 224 +24195 ./prep_dataset/ILSVRC2012_val_00026513.bin 224 224 +24196 ./prep_dataset/ILSVRC2012_val_00025020.bin 224 224 +24197 ./prep_dataset/ILSVRC2012_val_00020307.bin 224 224 +24198 ./prep_dataset/ILSVRC2012_val_00049826.bin 224 224 +24199 ./prep_dataset/ILSVRC2012_val_00020914.bin 224 224 +24200 ./prep_dataset/ILSVRC2012_val_00023032.bin 224 224 +24201 ./prep_dataset/ILSVRC2012_val_00030444.bin 224 224 +24202 ./prep_dataset/ILSVRC2012_val_00013805.bin 224 224 +24203 ./prep_dataset/ILSVRC2012_val_00001128.bin 224 224 +24204 ./prep_dataset/ILSVRC2012_val_00011073.bin 224 224 +24205 ./prep_dataset/ILSVRC2012_val_00019636.bin 224 224 +24206 ./prep_dataset/ILSVRC2012_val_00046296.bin 224 224 +24207 ./prep_dataset/ILSVRC2012_val_00010558.bin 224 224 +24208 ./prep_dataset/ILSVRC2012_val_00049687.bin 224 224 +24209 ./prep_dataset/ILSVRC2012_val_00012121.bin 224 224 +24210 ./prep_dataset/ILSVRC2012_val_00044764.bin 224 224 +24211 ./prep_dataset/ILSVRC2012_val_00017639.bin 224 224 +24212 ./prep_dataset/ILSVRC2012_val_00003536.bin 224 224 +24213 ./prep_dataset/ILSVRC2012_val_00030814.bin 224 224 +24214 ./prep_dataset/ILSVRC2012_val_00008567.bin 224 224 +24215 ./prep_dataset/ILSVRC2012_val_00009156.bin 224 224 +24216 ./prep_dataset/ILSVRC2012_val_00000518.bin 224 224 +24217 ./prep_dataset/ILSVRC2012_val_00028096.bin 224 224 +24218 ./prep_dataset/ILSVRC2012_val_00023283.bin 224 224 +24219 ./prep_dataset/ILSVRC2012_val_00011886.bin 224 224 +24220 ./prep_dataset/ILSVRC2012_val_00022333.bin 224 224 +24221 ./prep_dataset/ILSVRC2012_val_00039909.bin 224 224 +24222 ./prep_dataset/ILSVRC2012_val_00032483.bin 224 224 +24223 ./prep_dataset/ILSVRC2012_val_00001548.bin 224 224 +24224 ./prep_dataset/ILSVRC2012_val_00010752.bin 224 224 +24225 ./prep_dataset/ILSVRC2012_val_00045751.bin 224 224 +24226 ./prep_dataset/ILSVRC2012_val_00049762.bin 224 224 +24227 ./prep_dataset/ILSVRC2012_val_00009560.bin 224 224 +24228 ./prep_dataset/ILSVRC2012_val_00008577.bin 224 224 +24229 ./prep_dataset/ILSVRC2012_val_00035809.bin 224 224 +24230 ./prep_dataset/ILSVRC2012_val_00044776.bin 224 224 +24231 ./prep_dataset/ILSVRC2012_val_00042553.bin 224 224 +24232 ./prep_dataset/ILSVRC2012_val_00012673.bin 224 224 +24233 ./prep_dataset/ILSVRC2012_val_00028846.bin 224 224 +24234 ./prep_dataset/ILSVRC2012_val_00022281.bin 224 224 +24235 ./prep_dataset/ILSVRC2012_val_00014461.bin 224 224 +24236 ./prep_dataset/ILSVRC2012_val_00031560.bin 224 224 +24237 ./prep_dataset/ILSVRC2012_val_00042088.bin 224 224 +24238 ./prep_dataset/ILSVRC2012_val_00030110.bin 224 224 +24239 ./prep_dataset/ILSVRC2012_val_00011772.bin 224 224 +24240 ./prep_dataset/ILSVRC2012_val_00028936.bin 224 224 +24241 ./prep_dataset/ILSVRC2012_val_00001702.bin 224 224 +24242 ./prep_dataset/ILSVRC2012_val_00002666.bin 224 224 +24243 ./prep_dataset/ILSVRC2012_val_00038086.bin 224 224 +24244 ./prep_dataset/ILSVRC2012_val_00036156.bin 224 224 +24245 ./prep_dataset/ILSVRC2012_val_00036434.bin 224 224 +24246 ./prep_dataset/ILSVRC2012_val_00041236.bin 224 224 +24247 ./prep_dataset/ILSVRC2012_val_00047299.bin 224 224 +24248 ./prep_dataset/ILSVRC2012_val_00036630.bin 224 224 +24249 ./prep_dataset/ILSVRC2012_val_00027577.bin 224 224 +24250 ./prep_dataset/ILSVRC2012_val_00027023.bin 224 224 +24251 ./prep_dataset/ILSVRC2012_val_00002958.bin 224 224 +24252 ./prep_dataset/ILSVRC2012_val_00040535.bin 224 224 +24253 ./prep_dataset/ILSVRC2012_val_00016916.bin 224 224 +24254 ./prep_dataset/ILSVRC2012_val_00046927.bin 224 224 +24255 ./prep_dataset/ILSVRC2012_val_00043278.bin 224 224 +24256 ./prep_dataset/ILSVRC2012_val_00023742.bin 224 224 +24257 ./prep_dataset/ILSVRC2012_val_00029769.bin 224 224 +24258 ./prep_dataset/ILSVRC2012_val_00008448.bin 224 224 +24259 ./prep_dataset/ILSVRC2012_val_00022344.bin 224 224 +24260 ./prep_dataset/ILSVRC2012_val_00006374.bin 224 224 +24261 ./prep_dataset/ILSVRC2012_val_00038897.bin 224 224 +24262 ./prep_dataset/ILSVRC2012_val_00009249.bin 224 224 +24263 ./prep_dataset/ILSVRC2012_val_00016088.bin 224 224 +24264 ./prep_dataset/ILSVRC2012_val_00002270.bin 224 224 +24265 ./prep_dataset/ILSVRC2012_val_00035987.bin 224 224 +24266 ./prep_dataset/ILSVRC2012_val_00040773.bin 224 224 +24267 ./prep_dataset/ILSVRC2012_val_00034679.bin 224 224 +24268 ./prep_dataset/ILSVRC2012_val_00018726.bin 224 224 +24269 ./prep_dataset/ILSVRC2012_val_00017779.bin 224 224 +24270 ./prep_dataset/ILSVRC2012_val_00010941.bin 224 224 +24271 ./prep_dataset/ILSVRC2012_val_00025458.bin 224 224 +24272 ./prep_dataset/ILSVRC2012_val_00023003.bin 224 224 +24273 ./prep_dataset/ILSVRC2012_val_00013515.bin 224 224 +24274 ./prep_dataset/ILSVRC2012_val_00012130.bin 224 224 +24275 ./prep_dataset/ILSVRC2012_val_00009205.bin 224 224 +24276 ./prep_dataset/ILSVRC2012_val_00043260.bin 224 224 +24277 ./prep_dataset/ILSVRC2012_val_00036231.bin 224 224 +24278 ./prep_dataset/ILSVRC2012_val_00029022.bin 224 224 +24279 ./prep_dataset/ILSVRC2012_val_00015503.bin 224 224 +24280 ./prep_dataset/ILSVRC2012_val_00046505.bin 224 224 +24281 ./prep_dataset/ILSVRC2012_val_00008132.bin 224 224 +24282 ./prep_dataset/ILSVRC2012_val_00019721.bin 224 224 +24283 ./prep_dataset/ILSVRC2012_val_00030829.bin 224 224 +24284 ./prep_dataset/ILSVRC2012_val_00017735.bin 224 224 +24285 ./prep_dataset/ILSVRC2012_val_00027861.bin 224 224 +24286 ./prep_dataset/ILSVRC2012_val_00019481.bin 224 224 +24287 ./prep_dataset/ILSVRC2012_val_00013538.bin 224 224 +24288 ./prep_dataset/ILSVRC2012_val_00039818.bin 224 224 +24289 ./prep_dataset/ILSVRC2012_val_00039256.bin 224 224 +24290 ./prep_dataset/ILSVRC2012_val_00008546.bin 224 224 +24291 ./prep_dataset/ILSVRC2012_val_00036789.bin 224 224 +24292 ./prep_dataset/ILSVRC2012_val_00011917.bin 224 224 +24293 ./prep_dataset/ILSVRC2012_val_00006210.bin 224 224 +24294 ./prep_dataset/ILSVRC2012_val_00034638.bin 224 224 +24295 ./prep_dataset/ILSVRC2012_val_00036502.bin 224 224 +24296 ./prep_dataset/ILSVRC2012_val_00044553.bin 224 224 +24297 ./prep_dataset/ILSVRC2012_val_00035444.bin 224 224 +24298 ./prep_dataset/ILSVRC2012_val_00018595.bin 224 224 +24299 ./prep_dataset/ILSVRC2012_val_00029045.bin 224 224 +24300 ./prep_dataset/ILSVRC2012_val_00016096.bin 224 224 +24301 ./prep_dataset/ILSVRC2012_val_00008175.bin 224 224 +24302 ./prep_dataset/ILSVRC2012_val_00001443.bin 224 224 +24303 ./prep_dataset/ILSVRC2012_val_00037902.bin 224 224 +24304 ./prep_dataset/ILSVRC2012_val_00001483.bin 224 224 +24305 ./prep_dataset/ILSVRC2012_val_00012027.bin 224 224 +24306 ./prep_dataset/ILSVRC2012_val_00002372.bin 224 224 +24307 ./prep_dataset/ILSVRC2012_val_00030856.bin 224 224 +24308 ./prep_dataset/ILSVRC2012_val_00003404.bin 224 224 +24309 ./prep_dataset/ILSVRC2012_val_00034665.bin 224 224 +24310 ./prep_dataset/ILSVRC2012_val_00037721.bin 224 224 +24311 ./prep_dataset/ILSVRC2012_val_00000379.bin 224 224 +24312 ./prep_dataset/ILSVRC2012_val_00024888.bin 224 224 +24313 ./prep_dataset/ILSVRC2012_val_00002257.bin 224 224 +24314 ./prep_dataset/ILSVRC2012_val_00013404.bin 224 224 +24315 ./prep_dataset/ILSVRC2012_val_00041458.bin 224 224 +24316 ./prep_dataset/ILSVRC2012_val_00016362.bin 224 224 +24317 ./prep_dataset/ILSVRC2012_val_00044809.bin 224 224 +24318 ./prep_dataset/ILSVRC2012_val_00030709.bin 224 224 +24319 ./prep_dataset/ILSVRC2012_val_00003785.bin 224 224 +24320 ./prep_dataset/ILSVRC2012_val_00024342.bin 224 224 +24321 ./prep_dataset/ILSVRC2012_val_00037439.bin 224 224 +24322 ./prep_dataset/ILSVRC2012_val_00011926.bin 224 224 +24323 ./prep_dataset/ILSVRC2012_val_00044946.bin 224 224 +24324 ./prep_dataset/ILSVRC2012_val_00029114.bin 224 224 +24325 ./prep_dataset/ILSVRC2012_val_00028203.bin 224 224 +24326 ./prep_dataset/ILSVRC2012_val_00010785.bin 224 224 +24327 ./prep_dataset/ILSVRC2012_val_00029249.bin 224 224 +24328 ./prep_dataset/ILSVRC2012_val_00001378.bin 224 224 +24329 ./prep_dataset/ILSVRC2012_val_00027822.bin 224 224 +24330 ./prep_dataset/ILSVRC2012_val_00009621.bin 224 224 +24331 ./prep_dataset/ILSVRC2012_val_00025546.bin 224 224 +24332 ./prep_dataset/ILSVRC2012_val_00041029.bin 224 224 +24333 ./prep_dataset/ILSVRC2012_val_00036504.bin 224 224 +24334 ./prep_dataset/ILSVRC2012_val_00021872.bin 224 224 +24335 ./prep_dataset/ILSVRC2012_val_00031409.bin 224 224 +24336 ./prep_dataset/ILSVRC2012_val_00016231.bin 224 224 +24337 ./prep_dataset/ILSVRC2012_val_00048411.bin 224 224 +24338 ./prep_dataset/ILSVRC2012_val_00016538.bin 224 224 +24339 ./prep_dataset/ILSVRC2012_val_00019199.bin 224 224 +24340 ./prep_dataset/ILSVRC2012_val_00037695.bin 224 224 +24341 ./prep_dataset/ILSVRC2012_val_00011664.bin 224 224 +24342 ./prep_dataset/ILSVRC2012_val_00004030.bin 224 224 +24343 ./prep_dataset/ILSVRC2012_val_00006518.bin 224 224 +24344 ./prep_dataset/ILSVRC2012_val_00041690.bin 224 224 +24345 ./prep_dataset/ILSVRC2012_val_00014030.bin 224 224 +24346 ./prep_dataset/ILSVRC2012_val_00029739.bin 224 224 +24347 ./prep_dataset/ILSVRC2012_val_00008413.bin 224 224 +24348 ./prep_dataset/ILSVRC2012_val_00025915.bin 224 224 +24349 ./prep_dataset/ILSVRC2012_val_00038467.bin 224 224 +24350 ./prep_dataset/ILSVRC2012_val_00022278.bin 224 224 +24351 ./prep_dataset/ILSVRC2012_val_00029578.bin 224 224 +24352 ./prep_dataset/ILSVRC2012_val_00011262.bin 224 224 +24353 ./prep_dataset/ILSVRC2012_val_00005826.bin 224 224 +24354 ./prep_dataset/ILSVRC2012_val_00035909.bin 224 224 +24355 ./prep_dataset/ILSVRC2012_val_00038123.bin 224 224 +24356 ./prep_dataset/ILSVRC2012_val_00033281.bin 224 224 +24357 ./prep_dataset/ILSVRC2012_val_00022105.bin 224 224 +24358 ./prep_dataset/ILSVRC2012_val_00046847.bin 224 224 +24359 ./prep_dataset/ILSVRC2012_val_00006408.bin 224 224 +24360 ./prep_dataset/ILSVRC2012_val_00032255.bin 224 224 +24361 ./prep_dataset/ILSVRC2012_val_00028202.bin 224 224 +24362 ./prep_dataset/ILSVRC2012_val_00016102.bin 224 224 +24363 ./prep_dataset/ILSVRC2012_val_00011586.bin 224 224 +24364 ./prep_dataset/ILSVRC2012_val_00006636.bin 224 224 +24365 ./prep_dataset/ILSVRC2012_val_00045772.bin 224 224 +24366 ./prep_dataset/ILSVRC2012_val_00024941.bin 224 224 +24367 ./prep_dataset/ILSVRC2012_val_00042872.bin 224 224 +24368 ./prep_dataset/ILSVRC2012_val_00023782.bin 224 224 +24369 ./prep_dataset/ILSVRC2012_val_00004891.bin 224 224 +24370 ./prep_dataset/ILSVRC2012_val_00046812.bin 224 224 +24371 ./prep_dataset/ILSVRC2012_val_00009989.bin 224 224 +24372 ./prep_dataset/ILSVRC2012_val_00027491.bin 224 224 +24373 ./prep_dataset/ILSVRC2012_val_00047804.bin 224 224 +24374 ./prep_dataset/ILSVRC2012_val_00047426.bin 224 224 +24375 ./prep_dataset/ILSVRC2012_val_00005763.bin 224 224 +24376 ./prep_dataset/ILSVRC2012_val_00004219.bin 224 224 +24377 ./prep_dataset/ILSVRC2012_val_00030949.bin 224 224 +24378 ./prep_dataset/ILSVRC2012_val_00038290.bin 224 224 +24379 ./prep_dataset/ILSVRC2012_val_00044205.bin 224 224 +24380 ./prep_dataset/ILSVRC2012_val_00035276.bin 224 224 +24381 ./prep_dataset/ILSVRC2012_val_00044420.bin 224 224 +24382 ./prep_dataset/ILSVRC2012_val_00039795.bin 224 224 +24383 ./prep_dataset/ILSVRC2012_val_00005555.bin 224 224 +24384 ./prep_dataset/ILSVRC2012_val_00031572.bin 224 224 +24385 ./prep_dataset/ILSVRC2012_val_00032297.bin 224 224 +24386 ./prep_dataset/ILSVRC2012_val_00034867.bin 224 224 +24387 ./prep_dataset/ILSVRC2012_val_00015757.bin 224 224 +24388 ./prep_dataset/ILSVRC2012_val_00049649.bin 224 224 +24389 ./prep_dataset/ILSVRC2012_val_00035369.bin 224 224 +24390 ./prep_dataset/ILSVRC2012_val_00000289.bin 224 224 +24391 ./prep_dataset/ILSVRC2012_val_00024704.bin 224 224 +24392 ./prep_dataset/ILSVRC2012_val_00034154.bin 224 224 +24393 ./prep_dataset/ILSVRC2012_val_00037283.bin 224 224 +24394 ./prep_dataset/ILSVRC2012_val_00013814.bin 224 224 +24395 ./prep_dataset/ILSVRC2012_val_00016459.bin 224 224 +24396 ./prep_dataset/ILSVRC2012_val_00047218.bin 224 224 +24397 ./prep_dataset/ILSVRC2012_val_00017321.bin 224 224 +24398 ./prep_dataset/ILSVRC2012_val_00001216.bin 224 224 +24399 ./prep_dataset/ILSVRC2012_val_00026036.bin 224 224 +24400 ./prep_dataset/ILSVRC2012_val_00000637.bin 224 224 +24401 ./prep_dataset/ILSVRC2012_val_00035005.bin 224 224 +24402 ./prep_dataset/ILSVRC2012_val_00033860.bin 224 224 +24403 ./prep_dataset/ILSVRC2012_val_00028657.bin 224 224 +24404 ./prep_dataset/ILSVRC2012_val_00037021.bin 224 224 +24405 ./prep_dataset/ILSVRC2012_val_00032824.bin 224 224 +24406 ./prep_dataset/ILSVRC2012_val_00010952.bin 224 224 +24407 ./prep_dataset/ILSVRC2012_val_00041138.bin 224 224 +24408 ./prep_dataset/ILSVRC2012_val_00037685.bin 224 224 +24409 ./prep_dataset/ILSVRC2012_val_00042339.bin 224 224 +24410 ./prep_dataset/ILSVRC2012_val_00018147.bin 224 224 +24411 ./prep_dataset/ILSVRC2012_val_00012277.bin 224 224 +24412 ./prep_dataset/ILSVRC2012_val_00016427.bin 224 224 +24413 ./prep_dataset/ILSVRC2012_val_00031303.bin 224 224 +24414 ./prep_dataset/ILSVRC2012_val_00049398.bin 224 224 +24415 ./prep_dataset/ILSVRC2012_val_00001386.bin 224 224 +24416 ./prep_dataset/ILSVRC2012_val_00004489.bin 224 224 +24417 ./prep_dataset/ILSVRC2012_val_00033264.bin 224 224 +24418 ./prep_dataset/ILSVRC2012_val_00044035.bin 224 224 +24419 ./prep_dataset/ILSVRC2012_val_00000910.bin 224 224 +24420 ./prep_dataset/ILSVRC2012_val_00024730.bin 224 224 +24421 ./prep_dataset/ILSVRC2012_val_00038511.bin 224 224 +24422 ./prep_dataset/ILSVRC2012_val_00020369.bin 224 224 +24423 ./prep_dataset/ILSVRC2012_val_00011969.bin 224 224 +24424 ./prep_dataset/ILSVRC2012_val_00015894.bin 224 224 +24425 ./prep_dataset/ILSVRC2012_val_00020178.bin 224 224 +24426 ./prep_dataset/ILSVRC2012_val_00021781.bin 224 224 +24427 ./prep_dataset/ILSVRC2012_val_00031973.bin 224 224 +24428 ./prep_dataset/ILSVRC2012_val_00015661.bin 224 224 +24429 ./prep_dataset/ILSVRC2012_val_00040596.bin 224 224 +24430 ./prep_dataset/ILSVRC2012_val_00044626.bin 224 224 +24431 ./prep_dataset/ILSVRC2012_val_00047899.bin 224 224 +24432 ./prep_dataset/ILSVRC2012_val_00047408.bin 224 224 +24433 ./prep_dataset/ILSVRC2012_val_00008208.bin 224 224 +24434 ./prep_dataset/ILSVRC2012_val_00006537.bin 224 224 +24435 ./prep_dataset/ILSVRC2012_val_00035040.bin 224 224 +24436 ./prep_dataset/ILSVRC2012_val_00034235.bin 224 224 +24437 ./prep_dataset/ILSVRC2012_val_00030604.bin 224 224 +24438 ./prep_dataset/ILSVRC2012_val_00049418.bin 224 224 +24439 ./prep_dataset/ILSVRC2012_val_00034820.bin 224 224 +24440 ./prep_dataset/ILSVRC2012_val_00018433.bin 224 224 +24441 ./prep_dataset/ILSVRC2012_val_00005508.bin 224 224 +24442 ./prep_dataset/ILSVRC2012_val_00014795.bin 224 224 +24443 ./prep_dataset/ILSVRC2012_val_00006048.bin 224 224 +24444 ./prep_dataset/ILSVRC2012_val_00039646.bin 224 224 +24445 ./prep_dataset/ILSVRC2012_val_00021514.bin 224 224 +24446 ./prep_dataset/ILSVRC2012_val_00009071.bin 224 224 +24447 ./prep_dataset/ILSVRC2012_val_00001131.bin 224 224 +24448 ./prep_dataset/ILSVRC2012_val_00026728.bin 224 224 +24449 ./prep_dataset/ILSVRC2012_val_00025918.bin 224 224 +24450 ./prep_dataset/ILSVRC2012_val_00005060.bin 224 224 +24451 ./prep_dataset/ILSVRC2012_val_00018386.bin 224 224 +24452 ./prep_dataset/ILSVRC2012_val_00043806.bin 224 224 +24453 ./prep_dataset/ILSVRC2012_val_00049411.bin 224 224 +24454 ./prep_dataset/ILSVRC2012_val_00036173.bin 224 224 +24455 ./prep_dataset/ILSVRC2012_val_00026960.bin 224 224 +24456 ./prep_dataset/ILSVRC2012_val_00012519.bin 224 224 +24457 ./prep_dataset/ILSVRC2012_val_00034751.bin 224 224 +24458 ./prep_dataset/ILSVRC2012_val_00047684.bin 224 224 +24459 ./prep_dataset/ILSVRC2012_val_00018117.bin 224 224 +24460 ./prep_dataset/ILSVRC2012_val_00034739.bin 224 224 +24461 ./prep_dataset/ILSVRC2012_val_00025454.bin 224 224 +24462 ./prep_dataset/ILSVRC2012_val_00004940.bin 224 224 +24463 ./prep_dataset/ILSVRC2012_val_00033512.bin 224 224 +24464 ./prep_dataset/ILSVRC2012_val_00027192.bin 224 224 +24465 ./prep_dataset/ILSVRC2012_val_00011501.bin 224 224 +24466 ./prep_dataset/ILSVRC2012_val_00004334.bin 224 224 +24467 ./prep_dataset/ILSVRC2012_val_00019929.bin 224 224 +24468 ./prep_dataset/ILSVRC2012_val_00018069.bin 224 224 +24469 ./prep_dataset/ILSVRC2012_val_00041300.bin 224 224 +24470 ./prep_dataset/ILSVRC2012_val_00027414.bin 224 224 +24471 ./prep_dataset/ILSVRC2012_val_00029522.bin 224 224 +24472 ./prep_dataset/ILSVRC2012_val_00035291.bin 224 224 +24473 ./prep_dataset/ILSVRC2012_val_00029356.bin 224 224 +24474 ./prep_dataset/ILSVRC2012_val_00031055.bin 224 224 +24475 ./prep_dataset/ILSVRC2012_val_00029899.bin 224 224 +24476 ./prep_dataset/ILSVRC2012_val_00043711.bin 224 224 +24477 ./prep_dataset/ILSVRC2012_val_00008450.bin 224 224 +24478 ./prep_dataset/ILSVRC2012_val_00019617.bin 224 224 +24479 ./prep_dataset/ILSVRC2012_val_00024422.bin 224 224 +24480 ./prep_dataset/ILSVRC2012_val_00018046.bin 224 224 +24481 ./prep_dataset/ILSVRC2012_val_00040958.bin 224 224 +24482 ./prep_dataset/ILSVRC2012_val_00004150.bin 224 224 +24483 ./prep_dataset/ILSVRC2012_val_00015445.bin 224 224 +24484 ./prep_dataset/ILSVRC2012_val_00001814.bin 224 224 +24485 ./prep_dataset/ILSVRC2012_val_00034151.bin 224 224 +24486 ./prep_dataset/ILSVRC2012_val_00049239.bin 224 224 +24487 ./prep_dataset/ILSVRC2012_val_00026418.bin 224 224 +24488 ./prep_dataset/ILSVRC2012_val_00000029.bin 224 224 +24489 ./prep_dataset/ILSVRC2012_val_00014285.bin 224 224 +24490 ./prep_dataset/ILSVRC2012_val_00045544.bin 224 224 +24491 ./prep_dataset/ILSVRC2012_val_00007268.bin 224 224 +24492 ./prep_dataset/ILSVRC2012_val_00044320.bin 224 224 +24493 ./prep_dataset/ILSVRC2012_val_00004852.bin 224 224 +24494 ./prep_dataset/ILSVRC2012_val_00000638.bin 224 224 +24495 ./prep_dataset/ILSVRC2012_val_00038173.bin 224 224 +24496 ./prep_dataset/ILSVRC2012_val_00033717.bin 224 224 +24497 ./prep_dataset/ILSVRC2012_val_00038686.bin 224 224 +24498 ./prep_dataset/ILSVRC2012_val_00004955.bin 224 224 +24499 ./prep_dataset/ILSVRC2012_val_00028042.bin 224 224 +24500 ./prep_dataset/ILSVRC2012_val_00017479.bin 224 224 +24501 ./prep_dataset/ILSVRC2012_val_00006120.bin 224 224 +24502 ./prep_dataset/ILSVRC2012_val_00030713.bin 224 224 +24503 ./prep_dataset/ILSVRC2012_val_00022012.bin 224 224 +24504 ./prep_dataset/ILSVRC2012_val_00023662.bin 224 224 +24505 ./prep_dataset/ILSVRC2012_val_00012200.bin 224 224 +24506 ./prep_dataset/ILSVRC2012_val_00039201.bin 224 224 +24507 ./prep_dataset/ILSVRC2012_val_00045192.bin 224 224 +24508 ./prep_dataset/ILSVRC2012_val_00019147.bin 224 224 +24509 ./prep_dataset/ILSVRC2012_val_00044246.bin 224 224 +24510 ./prep_dataset/ILSVRC2012_val_00042685.bin 224 224 +24511 ./prep_dataset/ILSVRC2012_val_00027391.bin 224 224 +24512 ./prep_dataset/ILSVRC2012_val_00028265.bin 224 224 +24513 ./prep_dataset/ILSVRC2012_val_00025727.bin 224 224 +24514 ./prep_dataset/ILSVRC2012_val_00042951.bin 224 224 +24515 ./prep_dataset/ILSVRC2012_val_00007300.bin 224 224 +24516 ./prep_dataset/ILSVRC2012_val_00030656.bin 224 224 +24517 ./prep_dataset/ILSVRC2012_val_00042532.bin 224 224 +24518 ./prep_dataset/ILSVRC2012_val_00002433.bin 224 224 +24519 ./prep_dataset/ILSVRC2012_val_00046205.bin 224 224 +24520 ./prep_dataset/ILSVRC2012_val_00025034.bin 224 224 +24521 ./prep_dataset/ILSVRC2012_val_00038000.bin 224 224 +24522 ./prep_dataset/ILSVRC2012_val_00036112.bin 224 224 +24523 ./prep_dataset/ILSVRC2012_val_00037530.bin 224 224 +24524 ./prep_dataset/ILSVRC2012_val_00045918.bin 224 224 +24525 ./prep_dataset/ILSVRC2012_val_00013968.bin 224 224 +24526 ./prep_dataset/ILSVRC2012_val_00046756.bin 224 224 +24527 ./prep_dataset/ILSVRC2012_val_00047205.bin 224 224 +24528 ./prep_dataset/ILSVRC2012_val_00003708.bin 224 224 +24529 ./prep_dataset/ILSVRC2012_val_00004776.bin 224 224 +24530 ./prep_dataset/ILSVRC2012_val_00034949.bin 224 224 +24531 ./prep_dataset/ILSVRC2012_val_00046411.bin 224 224 +24532 ./prep_dataset/ILSVRC2012_val_00041883.bin 224 224 +24533 ./prep_dataset/ILSVRC2012_val_00046448.bin 224 224 +24534 ./prep_dataset/ILSVRC2012_val_00006816.bin 224 224 +24535 ./prep_dataset/ILSVRC2012_val_00048075.bin 224 224 +24536 ./prep_dataset/ILSVRC2012_val_00039415.bin 224 224 +24537 ./prep_dataset/ILSVRC2012_val_00036352.bin 224 224 +24538 ./prep_dataset/ILSVRC2012_val_00015161.bin 224 224 +24539 ./prep_dataset/ILSVRC2012_val_00020302.bin 224 224 +24540 ./prep_dataset/ILSVRC2012_val_00003537.bin 224 224 +24541 ./prep_dataset/ILSVRC2012_val_00047152.bin 224 224 +24542 ./prep_dataset/ILSVRC2012_val_00017669.bin 224 224 +24543 ./prep_dataset/ILSVRC2012_val_00026770.bin 224 224 +24544 ./prep_dataset/ILSVRC2012_val_00007307.bin 224 224 +24545 ./prep_dataset/ILSVRC2012_val_00033988.bin 224 224 +24546 ./prep_dataset/ILSVRC2012_val_00019849.bin 224 224 +24547 ./prep_dataset/ILSVRC2012_val_00012715.bin 224 224 +24548 ./prep_dataset/ILSVRC2012_val_00011434.bin 224 224 +24549 ./prep_dataset/ILSVRC2012_val_00017752.bin 224 224 +24550 ./prep_dataset/ILSVRC2012_val_00004570.bin 224 224 +24551 ./prep_dataset/ILSVRC2012_val_00044800.bin 224 224 +24552 ./prep_dataset/ILSVRC2012_val_00007047.bin 224 224 +24553 ./prep_dataset/ILSVRC2012_val_00002043.bin 224 224 +24554 ./prep_dataset/ILSVRC2012_val_00040922.bin 224 224 +24555 ./prep_dataset/ILSVRC2012_val_00006956.bin 224 224 +24556 ./prep_dataset/ILSVRC2012_val_00010011.bin 224 224 +24557 ./prep_dataset/ILSVRC2012_val_00022882.bin 224 224 +24558 ./prep_dataset/ILSVRC2012_val_00019777.bin 224 224 +24559 ./prep_dataset/ILSVRC2012_val_00016063.bin 224 224 +24560 ./prep_dataset/ILSVRC2012_val_00007262.bin 224 224 +24561 ./prep_dataset/ILSVRC2012_val_00003497.bin 224 224 +24562 ./prep_dataset/ILSVRC2012_val_00013215.bin 224 224 +24563 ./prep_dataset/ILSVRC2012_val_00044374.bin 224 224 +24564 ./prep_dataset/ILSVRC2012_val_00005547.bin 224 224 +24565 ./prep_dataset/ILSVRC2012_val_00012274.bin 224 224 +24566 ./prep_dataset/ILSVRC2012_val_00041144.bin 224 224 +24567 ./prep_dataset/ILSVRC2012_val_00006851.bin 224 224 +24568 ./prep_dataset/ILSVRC2012_val_00000709.bin 224 224 +24569 ./prep_dataset/ILSVRC2012_val_00023244.bin 224 224 +24570 ./prep_dataset/ILSVRC2012_val_00039705.bin 224 224 +24571 ./prep_dataset/ILSVRC2012_val_00030386.bin 224 224 +24572 ./prep_dataset/ILSVRC2012_val_00047716.bin 224 224 +24573 ./prep_dataset/ILSVRC2012_val_00048464.bin 224 224 +24574 ./prep_dataset/ILSVRC2012_val_00012769.bin 224 224 +24575 ./prep_dataset/ILSVRC2012_val_00005757.bin 224 224 +24576 ./prep_dataset/ILSVRC2012_val_00038498.bin 224 224 +24577 ./prep_dataset/ILSVRC2012_val_00007594.bin 224 224 +24578 ./prep_dataset/ILSVRC2012_val_00043371.bin 224 224 +24579 ./prep_dataset/ILSVRC2012_val_00004597.bin 224 224 +24580 ./prep_dataset/ILSVRC2012_val_00041984.bin 224 224 +24581 ./prep_dataset/ILSVRC2012_val_00008618.bin 224 224 +24582 ./prep_dataset/ILSVRC2012_val_00008977.bin 224 224 +24583 ./prep_dataset/ILSVRC2012_val_00021523.bin 224 224 +24584 ./prep_dataset/ILSVRC2012_val_00040356.bin 224 224 +24585 ./prep_dataset/ILSVRC2012_val_00043143.bin 224 224 +24586 ./prep_dataset/ILSVRC2012_val_00008685.bin 224 224 +24587 ./prep_dataset/ILSVRC2012_val_00010153.bin 224 224 +24588 ./prep_dataset/ILSVRC2012_val_00008727.bin 224 224 +24589 ./prep_dataset/ILSVRC2012_val_00021141.bin 224 224 +24590 ./prep_dataset/ILSVRC2012_val_00041054.bin 224 224 +24591 ./prep_dataset/ILSVRC2012_val_00002939.bin 224 224 +24592 ./prep_dataset/ILSVRC2012_val_00019030.bin 224 224 +24593 ./prep_dataset/ILSVRC2012_val_00040497.bin 224 224 +24594 ./prep_dataset/ILSVRC2012_val_00002019.bin 224 224 +24595 ./prep_dataset/ILSVRC2012_val_00026740.bin 224 224 +24596 ./prep_dataset/ILSVRC2012_val_00025369.bin 224 224 +24597 ./prep_dataset/ILSVRC2012_val_00018430.bin 224 224 +24598 ./prep_dataset/ILSVRC2012_val_00015291.bin 224 224 +24599 ./prep_dataset/ILSVRC2012_val_00041975.bin 224 224 +24600 ./prep_dataset/ILSVRC2012_val_00020504.bin 224 224 +24601 ./prep_dataset/ILSVRC2012_val_00015142.bin 224 224 +24602 ./prep_dataset/ILSVRC2012_val_00014687.bin 224 224 +24603 ./prep_dataset/ILSVRC2012_val_00038289.bin 224 224 +24604 ./prep_dataset/ILSVRC2012_val_00042374.bin 224 224 +24605 ./prep_dataset/ILSVRC2012_val_00012701.bin 224 224 +24606 ./prep_dataset/ILSVRC2012_val_00022568.bin 224 224 +24607 ./prep_dataset/ILSVRC2012_val_00027299.bin 224 224 +24608 ./prep_dataset/ILSVRC2012_val_00041569.bin 224 224 +24609 ./prep_dataset/ILSVRC2012_val_00031826.bin 224 224 +24610 ./prep_dataset/ILSVRC2012_val_00048953.bin 224 224 +24611 ./prep_dataset/ILSVRC2012_val_00009508.bin 224 224 +24612 ./prep_dataset/ILSVRC2012_val_00019714.bin 224 224 +24613 ./prep_dataset/ILSVRC2012_val_00046376.bin 224 224 +24614 ./prep_dataset/ILSVRC2012_val_00015428.bin 224 224 +24615 ./prep_dataset/ILSVRC2012_val_00008062.bin 224 224 +24616 ./prep_dataset/ILSVRC2012_val_00024700.bin 224 224 +24617 ./prep_dataset/ILSVRC2012_val_00044085.bin 224 224 +24618 ./prep_dataset/ILSVRC2012_val_00020318.bin 224 224 +24619 ./prep_dataset/ILSVRC2012_val_00020901.bin 224 224 +24620 ./prep_dataset/ILSVRC2012_val_00036108.bin 224 224 +24621 ./prep_dataset/ILSVRC2012_val_00004681.bin 224 224 +24622 ./prep_dataset/ILSVRC2012_val_00043237.bin 224 224 +24623 ./prep_dataset/ILSVRC2012_val_00007687.bin 224 224 +24624 ./prep_dataset/ILSVRC2012_val_00010106.bin 224 224 +24625 ./prep_dataset/ILSVRC2012_val_00039841.bin 224 224 +24626 ./prep_dataset/ILSVRC2012_val_00006072.bin 224 224 +24627 ./prep_dataset/ILSVRC2012_val_00015313.bin 224 224 +24628 ./prep_dataset/ILSVRC2012_val_00028925.bin 224 224 +24629 ./prep_dataset/ILSVRC2012_val_00009174.bin 224 224 +24630 ./prep_dataset/ILSVRC2012_val_00046866.bin 224 224 +24631 ./prep_dataset/ILSVRC2012_val_00039603.bin 224 224 +24632 ./prep_dataset/ILSVRC2012_val_00034275.bin 224 224 +24633 ./prep_dataset/ILSVRC2012_val_00021999.bin 224 224 +24634 ./prep_dataset/ILSVRC2012_val_00028792.bin 224 224 +24635 ./prep_dataset/ILSVRC2012_val_00007557.bin 224 224 +24636 ./prep_dataset/ILSVRC2012_val_00029406.bin 224 224 +24637 ./prep_dataset/ILSVRC2012_val_00021161.bin 224 224 +24638 ./prep_dataset/ILSVRC2012_val_00021378.bin 224 224 +24639 ./prep_dataset/ILSVRC2012_val_00037105.bin 224 224 +24640 ./prep_dataset/ILSVRC2012_val_00014647.bin 224 224 +24641 ./prep_dataset/ILSVRC2012_val_00022247.bin 224 224 +24642 ./prep_dataset/ILSVRC2012_val_00026606.bin 224 224 +24643 ./prep_dataset/ILSVRC2012_val_00021733.bin 224 224 +24644 ./prep_dataset/ILSVRC2012_val_00033514.bin 224 224 +24645 ./prep_dataset/ILSVRC2012_val_00036016.bin 224 224 +24646 ./prep_dataset/ILSVRC2012_val_00047038.bin 224 224 +24647 ./prep_dataset/ILSVRC2012_val_00039771.bin 224 224 +24648 ./prep_dataset/ILSVRC2012_val_00002364.bin 224 224 +24649 ./prep_dataset/ILSVRC2012_val_00030439.bin 224 224 +24650 ./prep_dataset/ILSVRC2012_val_00013830.bin 224 224 +24651 ./prep_dataset/ILSVRC2012_val_00010641.bin 224 224 +24652 ./prep_dataset/ILSVRC2012_val_00049983.bin 224 224 +24653 ./prep_dataset/ILSVRC2012_val_00038129.bin 224 224 +24654 ./prep_dataset/ILSVRC2012_val_00047763.bin 224 224 +24655 ./prep_dataset/ILSVRC2012_val_00025871.bin 224 224 +24656 ./prep_dataset/ILSVRC2012_val_00024806.bin 224 224 +24657 ./prep_dataset/ILSVRC2012_val_00034394.bin 224 224 +24658 ./prep_dataset/ILSVRC2012_val_00007334.bin 224 224 +24659 ./prep_dataset/ILSVRC2012_val_00017386.bin 224 224 +24660 ./prep_dataset/ILSVRC2012_val_00024166.bin 224 224 +24661 ./prep_dataset/ILSVRC2012_val_00030937.bin 224 224 +24662 ./prep_dataset/ILSVRC2012_val_00012496.bin 224 224 +24663 ./prep_dataset/ILSVRC2012_val_00034518.bin 224 224 +24664 ./prep_dataset/ILSVRC2012_val_00014612.bin 224 224 +24665 ./prep_dataset/ILSVRC2012_val_00016736.bin 224 224 +24666 ./prep_dataset/ILSVRC2012_val_00031072.bin 224 224 +24667 ./prep_dataset/ILSVRC2012_val_00044728.bin 224 224 +24668 ./prep_dataset/ILSVRC2012_val_00038701.bin 224 224 +24669 ./prep_dataset/ILSVRC2012_val_00028083.bin 224 224 +24670 ./prep_dataset/ILSVRC2012_val_00032960.bin 224 224 +24671 ./prep_dataset/ILSVRC2012_val_00045983.bin 224 224 +24672 ./prep_dataset/ILSVRC2012_val_00031384.bin 224 224 +24673 ./prep_dataset/ILSVRC2012_val_00030589.bin 224 224 +24674 ./prep_dataset/ILSVRC2012_val_00018099.bin 224 224 +24675 ./prep_dataset/ILSVRC2012_val_00040057.bin 224 224 +24676 ./prep_dataset/ILSVRC2012_val_00010828.bin 224 224 +24677 ./prep_dataset/ILSVRC2012_val_00001312.bin 224 224 +24678 ./prep_dataset/ILSVRC2012_val_00042555.bin 224 224 +24679 ./prep_dataset/ILSVRC2012_val_00027280.bin 224 224 +24680 ./prep_dataset/ILSVRC2012_val_00044940.bin 224 224 +24681 ./prep_dataset/ILSVRC2012_val_00045246.bin 224 224 +24682 ./prep_dataset/ILSVRC2012_val_00002996.bin 224 224 +24683 ./prep_dataset/ILSVRC2012_val_00039986.bin 224 224 +24684 ./prep_dataset/ILSVRC2012_val_00042842.bin 224 224 +24685 ./prep_dataset/ILSVRC2012_val_00035993.bin 224 224 +24686 ./prep_dataset/ILSVRC2012_val_00006940.bin 224 224 +24687 ./prep_dataset/ILSVRC2012_val_00037554.bin 224 224 +24688 ./prep_dataset/ILSVRC2012_val_00023363.bin 224 224 +24689 ./prep_dataset/ILSVRC2012_val_00022049.bin 224 224 +24690 ./prep_dataset/ILSVRC2012_val_00047102.bin 224 224 +24691 ./prep_dataset/ILSVRC2012_val_00001774.bin 224 224 +24692 ./prep_dataset/ILSVRC2012_val_00019029.bin 224 224 +24693 ./prep_dataset/ILSVRC2012_val_00005861.bin 224 224 +24694 ./prep_dataset/ILSVRC2012_val_00025662.bin 224 224 +24695 ./prep_dataset/ILSVRC2012_val_00038359.bin 224 224 +24696 ./prep_dataset/ILSVRC2012_val_00042132.bin 224 224 +24697 ./prep_dataset/ILSVRC2012_val_00041911.bin 224 224 +24698 ./prep_dataset/ILSVRC2012_val_00019392.bin 224 224 +24699 ./prep_dataset/ILSVRC2012_val_00049566.bin 224 224 +24700 ./prep_dataset/ILSVRC2012_val_00046993.bin 224 224 +24701 ./prep_dataset/ILSVRC2012_val_00032042.bin 224 224 +24702 ./prep_dataset/ILSVRC2012_val_00023402.bin 224 224 +24703 ./prep_dataset/ILSVRC2012_val_00046602.bin 224 224 +24704 ./prep_dataset/ILSVRC2012_val_00032843.bin 224 224 +24705 ./prep_dataset/ILSVRC2012_val_00017388.bin 224 224 +24706 ./prep_dataset/ILSVRC2012_val_00043678.bin 224 224 +24707 ./prep_dataset/ILSVRC2012_val_00028849.bin 224 224 +24708 ./prep_dataset/ILSVRC2012_val_00014837.bin 224 224 +24709 ./prep_dataset/ILSVRC2012_val_00029489.bin 224 224 +24710 ./prep_dataset/ILSVRC2012_val_00034048.bin 224 224 +24711 ./prep_dataset/ILSVRC2012_val_00025760.bin 224 224 +24712 ./prep_dataset/ILSVRC2012_val_00004276.bin 224 224 +24713 ./prep_dataset/ILSVRC2012_val_00017214.bin 224 224 +24714 ./prep_dataset/ILSVRC2012_val_00036449.bin 224 224 +24715 ./prep_dataset/ILSVRC2012_val_00024428.bin 224 224 +24716 ./prep_dataset/ILSVRC2012_val_00012761.bin 224 224 +24717 ./prep_dataset/ILSVRC2012_val_00027150.bin 224 224 +24718 ./prep_dataset/ILSVRC2012_val_00021468.bin 224 224 +24719 ./prep_dataset/ILSVRC2012_val_00004422.bin 224 224 +24720 ./prep_dataset/ILSVRC2012_val_00047216.bin 224 224 +24721 ./prep_dataset/ILSVRC2012_val_00004538.bin 224 224 +24722 ./prep_dataset/ILSVRC2012_val_00047680.bin 224 224 +24723 ./prep_dataset/ILSVRC2012_val_00030080.bin 224 224 +24724 ./prep_dataset/ILSVRC2012_val_00028511.bin 224 224 +24725 ./prep_dataset/ILSVRC2012_val_00014559.bin 224 224 +24726 ./prep_dataset/ILSVRC2012_val_00035954.bin 224 224 +24727 ./prep_dataset/ILSVRC2012_val_00022372.bin 224 224 +24728 ./prep_dataset/ILSVRC2012_val_00038687.bin 224 224 +24729 ./prep_dataset/ILSVRC2012_val_00009565.bin 224 224 +24730 ./prep_dataset/ILSVRC2012_val_00026314.bin 224 224 +24731 ./prep_dataset/ILSVRC2012_val_00048233.bin 224 224 +24732 ./prep_dataset/ILSVRC2012_val_00026514.bin 224 224 +24733 ./prep_dataset/ILSVRC2012_val_00018169.bin 224 224 +24734 ./prep_dataset/ILSVRC2012_val_00021923.bin 224 224 +24735 ./prep_dataset/ILSVRC2012_val_00008642.bin 224 224 +24736 ./prep_dataset/ILSVRC2012_val_00036973.bin 224 224 +24737 ./prep_dataset/ILSVRC2012_val_00019379.bin 224 224 +24738 ./prep_dataset/ILSVRC2012_val_00033703.bin 224 224 +24739 ./prep_dataset/ILSVRC2012_val_00004976.bin 224 224 +24740 ./prep_dataset/ILSVRC2012_val_00011666.bin 224 224 +24741 ./prep_dataset/ILSVRC2012_val_00009712.bin 224 224 +24742 ./prep_dataset/ILSVRC2012_val_00030710.bin 224 224 +24743 ./prep_dataset/ILSVRC2012_val_00039107.bin 224 224 +24744 ./prep_dataset/ILSVRC2012_val_00025041.bin 224 224 +24745 ./prep_dataset/ILSVRC2012_val_00037945.bin 224 224 +24746 ./prep_dataset/ILSVRC2012_val_00049230.bin 224 224 +24747 ./prep_dataset/ILSVRC2012_val_00042394.bin 224 224 +24748 ./prep_dataset/ILSVRC2012_val_00035122.bin 224 224 +24749 ./prep_dataset/ILSVRC2012_val_00049124.bin 224 224 +24750 ./prep_dataset/ILSVRC2012_val_00025903.bin 224 224 +24751 ./prep_dataset/ILSVRC2012_val_00042641.bin 224 224 +24752 ./prep_dataset/ILSVRC2012_val_00029214.bin 224 224 +24753 ./prep_dataset/ILSVRC2012_val_00043553.bin 224 224 +24754 ./prep_dataset/ILSVRC2012_val_00045070.bin 224 224 +24755 ./prep_dataset/ILSVRC2012_val_00023073.bin 224 224 +24756 ./prep_dataset/ILSVRC2012_val_00030654.bin 224 224 +24757 ./prep_dataset/ILSVRC2012_val_00022763.bin 224 224 +24758 ./prep_dataset/ILSVRC2012_val_00015875.bin 224 224 +24759 ./prep_dataset/ILSVRC2012_val_00033863.bin 224 224 +24760 ./prep_dataset/ILSVRC2012_val_00049076.bin 224 224 +24761 ./prep_dataset/ILSVRC2012_val_00000588.bin 224 224 +24762 ./prep_dataset/ILSVRC2012_val_00021710.bin 224 224 +24763 ./prep_dataset/ILSVRC2012_val_00004854.bin 224 224 +24764 ./prep_dataset/ILSVRC2012_val_00045775.bin 224 224 +24765 ./prep_dataset/ILSVRC2012_val_00014730.bin 224 224 +24766 ./prep_dataset/ILSVRC2012_val_00010023.bin 224 224 +24767 ./prep_dataset/ILSVRC2012_val_00019207.bin 224 224 +24768 ./prep_dataset/ILSVRC2012_val_00003612.bin 224 224 +24769 ./prep_dataset/ILSVRC2012_val_00013824.bin 224 224 +24770 ./prep_dataset/ILSVRC2012_val_00049512.bin 224 224 +24771 ./prep_dataset/ILSVRC2012_val_00014745.bin 224 224 +24772 ./prep_dataset/ILSVRC2012_val_00039671.bin 224 224 +24773 ./prep_dataset/ILSVRC2012_val_00022279.bin 224 224 +24774 ./prep_dataset/ILSVRC2012_val_00020879.bin 224 224 +24775 ./prep_dataset/ILSVRC2012_val_00049652.bin 224 224 +24776 ./prep_dataset/ILSVRC2012_val_00014128.bin 224 224 +24777 ./prep_dataset/ILSVRC2012_val_00029204.bin 224 224 +24778 ./prep_dataset/ILSVRC2012_val_00016992.bin 224 224 +24779 ./prep_dataset/ILSVRC2012_val_00046711.bin 224 224 +24780 ./prep_dataset/ILSVRC2012_val_00003727.bin 224 224 +24781 ./prep_dataset/ILSVRC2012_val_00040316.bin 224 224 +24782 ./prep_dataset/ILSVRC2012_val_00004913.bin 224 224 +24783 ./prep_dataset/ILSVRC2012_val_00002876.bin 224 224 +24784 ./prep_dataset/ILSVRC2012_val_00036492.bin 224 224 +24785 ./prep_dataset/ILSVRC2012_val_00020799.bin 224 224 +24786 ./prep_dataset/ILSVRC2012_val_00034149.bin 224 224 +24787 ./prep_dataset/ILSVRC2012_val_00047844.bin 224 224 +24788 ./prep_dataset/ILSVRC2012_val_00012869.bin 224 224 +24789 ./prep_dataset/ILSVRC2012_val_00014225.bin 224 224 +24790 ./prep_dataset/ILSVRC2012_val_00030696.bin 224 224 +24791 ./prep_dataset/ILSVRC2012_val_00008758.bin 224 224 +24792 ./prep_dataset/ILSVRC2012_val_00022265.bin 224 224 +24793 ./prep_dataset/ILSVRC2012_val_00008430.bin 224 224 +24794 ./prep_dataset/ILSVRC2012_val_00037142.bin 224 224 +24795 ./prep_dataset/ILSVRC2012_val_00034783.bin 224 224 +24796 ./prep_dataset/ILSVRC2012_val_00009803.bin 224 224 +24797 ./prep_dataset/ILSVRC2012_val_00039079.bin 224 224 +24798 ./prep_dataset/ILSVRC2012_val_00006162.bin 224 224 +24799 ./prep_dataset/ILSVRC2012_val_00036397.bin 224 224 +24800 ./prep_dataset/ILSVRC2012_val_00007508.bin 224 224 +24801 ./prep_dataset/ILSVRC2012_val_00013331.bin 224 224 +24802 ./prep_dataset/ILSVRC2012_val_00044835.bin 224 224 +24803 ./prep_dataset/ILSVRC2012_val_00012199.bin 224 224 +24804 ./prep_dataset/ILSVRC2012_val_00037409.bin 224 224 +24805 ./prep_dataset/ILSVRC2012_val_00022755.bin 224 224 +24806 ./prep_dataset/ILSVRC2012_val_00007998.bin 224 224 +24807 ./prep_dataset/ILSVRC2012_val_00016085.bin 224 224 +24808 ./prep_dataset/ILSVRC2012_val_00029182.bin 224 224 +24809 ./prep_dataset/ILSVRC2012_val_00010563.bin 224 224 +24810 ./prep_dataset/ILSVRC2012_val_00005322.bin 224 224 +24811 ./prep_dataset/ILSVRC2012_val_00023994.bin 224 224 +24812 ./prep_dataset/ILSVRC2012_val_00009108.bin 224 224 +24813 ./prep_dataset/ILSVRC2012_val_00028966.bin 224 224 +24814 ./prep_dataset/ILSVRC2012_val_00006574.bin 224 224 +24815 ./prep_dataset/ILSVRC2012_val_00026643.bin 224 224 +24816 ./prep_dataset/ILSVRC2012_val_00016209.bin 224 224 +24817 ./prep_dataset/ILSVRC2012_val_00049250.bin 224 224 +24818 ./prep_dataset/ILSVRC2012_val_00028448.bin 224 224 +24819 ./prep_dataset/ILSVRC2012_val_00024691.bin 224 224 +24820 ./prep_dataset/ILSVRC2012_val_00024973.bin 224 224 +24821 ./prep_dataset/ILSVRC2012_val_00026958.bin 224 224 +24822 ./prep_dataset/ILSVRC2012_val_00033044.bin 224 224 +24823 ./prep_dataset/ILSVRC2012_val_00026826.bin 224 224 +24824 ./prep_dataset/ILSVRC2012_val_00027480.bin 224 224 +24825 ./prep_dataset/ILSVRC2012_val_00014096.bin 224 224 +24826 ./prep_dataset/ILSVRC2012_val_00042781.bin 224 224 +24827 ./prep_dataset/ILSVRC2012_val_00036167.bin 224 224 +24828 ./prep_dataset/ILSVRC2012_val_00011940.bin 224 224 +24829 ./prep_dataset/ILSVRC2012_val_00033565.bin 224 224 +24830 ./prep_dataset/ILSVRC2012_val_00044083.bin 224 224 +24831 ./prep_dataset/ILSVRC2012_val_00031975.bin 224 224 +24832 ./prep_dataset/ILSVRC2012_val_00021574.bin 224 224 +24833 ./prep_dataset/ILSVRC2012_val_00043965.bin 224 224 +24834 ./prep_dataset/ILSVRC2012_val_00042908.bin 224 224 +24835 ./prep_dataset/ILSVRC2012_val_00019751.bin 224 224 +24836 ./prep_dataset/ILSVRC2012_val_00048591.bin 224 224 +24837 ./prep_dataset/ILSVRC2012_val_00007824.bin 224 224 +24838 ./prep_dataset/ILSVRC2012_val_00032021.bin 224 224 +24839 ./prep_dataset/ILSVRC2012_val_00047141.bin 224 224 +24840 ./prep_dataset/ILSVRC2012_val_00034294.bin 224 224 +24841 ./prep_dataset/ILSVRC2012_val_00015923.bin 224 224 +24842 ./prep_dataset/ILSVRC2012_val_00046998.bin 224 224 +24843 ./prep_dataset/ILSVRC2012_val_00006888.bin 224 224 +24844 ./prep_dataset/ILSVRC2012_val_00014474.bin 224 224 +24845 ./prep_dataset/ILSVRC2012_val_00018453.bin 224 224 +24846 ./prep_dataset/ILSVRC2012_val_00027252.bin 224 224 +24847 ./prep_dataset/ILSVRC2012_val_00015103.bin 224 224 +24848 ./prep_dataset/ILSVRC2012_val_00031392.bin 224 224 +24849 ./prep_dataset/ILSVRC2012_val_00023311.bin 224 224 +24850 ./prep_dataset/ILSVRC2012_val_00046884.bin 224 224 +24851 ./prep_dataset/ILSVRC2012_val_00042933.bin 224 224 +24852 ./prep_dataset/ILSVRC2012_val_00024942.bin 224 224 +24853 ./prep_dataset/ILSVRC2012_val_00021597.bin 224 224 +24854 ./prep_dataset/ILSVRC2012_val_00033150.bin 224 224 +24855 ./prep_dataset/ILSVRC2012_val_00010120.bin 224 224 +24856 ./prep_dataset/ILSVRC2012_val_00042990.bin 224 224 +24857 ./prep_dataset/ILSVRC2012_val_00003329.bin 224 224 +24858 ./prep_dataset/ILSVRC2012_val_00009821.bin 224 224 +24859 ./prep_dataset/ILSVRC2012_val_00019436.bin 224 224 +24860 ./prep_dataset/ILSVRC2012_val_00021807.bin 224 224 +24861 ./prep_dataset/ILSVRC2012_val_00010686.bin 224 224 +24862 ./prep_dataset/ILSVRC2012_val_00033808.bin 224 224 +24863 ./prep_dataset/ILSVRC2012_val_00037286.bin 224 224 +24864 ./prep_dataset/ILSVRC2012_val_00021359.bin 224 224 +24865 ./prep_dataset/ILSVRC2012_val_00031438.bin 224 224 +24866 ./prep_dataset/ILSVRC2012_val_00010825.bin 224 224 +24867 ./prep_dataset/ILSVRC2012_val_00019537.bin 224 224 +24868 ./prep_dataset/ILSVRC2012_val_00003859.bin 224 224 +24869 ./prep_dataset/ILSVRC2012_val_00047500.bin 224 224 +24870 ./prep_dataset/ILSVRC2012_val_00013299.bin 224 224 +24871 ./prep_dataset/ILSVRC2012_val_00011055.bin 224 224 +24872 ./prep_dataset/ILSVRC2012_val_00018548.bin 224 224 +24873 ./prep_dataset/ILSVRC2012_val_00028102.bin 224 224 +24874 ./prep_dataset/ILSVRC2012_val_00047446.bin 224 224 +24875 ./prep_dataset/ILSVRC2012_val_00039681.bin 224 224 +24876 ./prep_dataset/ILSVRC2012_val_00042128.bin 224 224 +24877 ./prep_dataset/ILSVRC2012_val_00011976.bin 224 224 +24878 ./prep_dataset/ILSVRC2012_val_00037414.bin 224 224 +24879 ./prep_dataset/ILSVRC2012_val_00020003.bin 224 224 +24880 ./prep_dataset/ILSVRC2012_val_00037614.bin 224 224 +24881 ./prep_dataset/ILSVRC2012_val_00021070.bin 224 224 +24882 ./prep_dataset/ILSVRC2012_val_00028956.bin 224 224 +24883 ./prep_dataset/ILSVRC2012_val_00037131.bin 224 224 +24884 ./prep_dataset/ILSVRC2012_val_00034761.bin 224 224 +24885 ./prep_dataset/ILSVRC2012_val_00028915.bin 224 224 +24886 ./prep_dataset/ILSVRC2012_val_00018644.bin 224 224 +24887 ./prep_dataset/ILSVRC2012_val_00008463.bin 224 224 +24888 ./prep_dataset/ILSVRC2012_val_00036996.bin 224 224 +24889 ./prep_dataset/ILSVRC2012_val_00033454.bin 224 224 +24890 ./prep_dataset/ILSVRC2012_val_00003861.bin 224 224 +24891 ./prep_dataset/ILSVRC2012_val_00039874.bin 224 224 +24892 ./prep_dataset/ILSVRC2012_val_00017650.bin 224 224 +24893 ./prep_dataset/ILSVRC2012_val_00028459.bin 224 224 +24894 ./prep_dataset/ILSVRC2012_val_00007053.bin 224 224 +24895 ./prep_dataset/ILSVRC2012_val_00022290.bin 224 224 +24896 ./prep_dataset/ILSVRC2012_val_00016659.bin 224 224 +24897 ./prep_dataset/ILSVRC2012_val_00046963.bin 224 224 +24898 ./prep_dataset/ILSVRC2012_val_00038741.bin 224 224 +24899 ./prep_dataset/ILSVRC2012_val_00045110.bin 224 224 +24900 ./prep_dataset/ILSVRC2012_val_00029837.bin 224 224 +24901 ./prep_dataset/ILSVRC2012_val_00017769.bin 224 224 +24902 ./prep_dataset/ILSVRC2012_val_00037445.bin 224 224 +24903 ./prep_dataset/ILSVRC2012_val_00045834.bin 224 224 +24904 ./prep_dataset/ILSVRC2012_val_00037122.bin 224 224 +24905 ./prep_dataset/ILSVRC2012_val_00033788.bin 224 224 +24906 ./prep_dataset/ILSVRC2012_val_00018294.bin 224 224 +24907 ./prep_dataset/ILSVRC2012_val_00002989.bin 224 224 +24908 ./prep_dataset/ILSVRC2012_val_00005421.bin 224 224 +24909 ./prep_dataset/ILSVRC2012_val_00018350.bin 224 224 +24910 ./prep_dataset/ILSVRC2012_val_00032151.bin 224 224 +24911 ./prep_dataset/ILSVRC2012_val_00000366.bin 224 224 +24912 ./prep_dataset/ILSVRC2012_val_00008188.bin 224 224 +24913 ./prep_dataset/ILSVRC2012_val_00027568.bin 224 224 +24914 ./prep_dataset/ILSVRC2012_val_00042836.bin 224 224 +24915 ./prep_dataset/ILSVRC2012_val_00045647.bin 224 224 +24916 ./prep_dataset/ILSVRC2012_val_00024636.bin 224 224 +24917 ./prep_dataset/ILSVRC2012_val_00022997.bin 224 224 +24918 ./prep_dataset/ILSVRC2012_val_00015396.bin 224 224 +24919 ./prep_dataset/ILSVRC2012_val_00044495.bin 224 224 +24920 ./prep_dataset/ILSVRC2012_val_00010634.bin 224 224 +24921 ./prep_dataset/ILSVRC2012_val_00042063.bin 224 224 +24922 ./prep_dataset/ILSVRC2012_val_00002704.bin 224 224 +24923 ./prep_dataset/ILSVRC2012_val_00021464.bin 224 224 +24924 ./prep_dataset/ILSVRC2012_val_00024235.bin 224 224 +24925 ./prep_dataset/ILSVRC2012_val_00037368.bin 224 224 +24926 ./prep_dataset/ILSVRC2012_val_00009596.bin 224 224 +24927 ./prep_dataset/ILSVRC2012_val_00028198.bin 224 224 +24928 ./prep_dataset/ILSVRC2012_val_00023820.bin 224 224 +24929 ./prep_dataset/ILSVRC2012_val_00045377.bin 224 224 +24930 ./prep_dataset/ILSVRC2012_val_00030924.bin 224 224 +24931 ./prep_dataset/ILSVRC2012_val_00020365.bin 224 224 +24932 ./prep_dataset/ILSVRC2012_val_00042336.bin 224 224 +24933 ./prep_dataset/ILSVRC2012_val_00040180.bin 224 224 +24934 ./prep_dataset/ILSVRC2012_val_00000095.bin 224 224 +24935 ./prep_dataset/ILSVRC2012_val_00011569.bin 224 224 +24936 ./prep_dataset/ILSVRC2012_val_00037888.bin 224 224 +24937 ./prep_dataset/ILSVRC2012_val_00042792.bin 224 224 +24938 ./prep_dataset/ILSVRC2012_val_00004349.bin 224 224 +24939 ./prep_dataset/ILSVRC2012_val_00007013.bin 224 224 +24940 ./prep_dataset/ILSVRC2012_val_00019518.bin 224 224 +24941 ./prep_dataset/ILSVRC2012_val_00014231.bin 224 224 +24942 ./prep_dataset/ILSVRC2012_val_00042507.bin 224 224 +24943 ./prep_dataset/ILSVRC2012_val_00031260.bin 224 224 +24944 ./prep_dataset/ILSVRC2012_val_00044042.bin 224 224 +24945 ./prep_dataset/ILSVRC2012_val_00045565.bin 224 224 +24946 ./prep_dataset/ILSVRC2012_val_00022017.bin 224 224 +24947 ./prep_dataset/ILSVRC2012_val_00011867.bin 224 224 +24948 ./prep_dataset/ILSVRC2012_val_00039785.bin 224 224 +24949 ./prep_dataset/ILSVRC2012_val_00009130.bin 224 224 +24950 ./prep_dataset/ILSVRC2012_val_00029997.bin 224 224 +24951 ./prep_dataset/ILSVRC2012_val_00006434.bin 224 224 +24952 ./prep_dataset/ILSVRC2012_val_00040175.bin 224 224 +24953 ./prep_dataset/ILSVRC2012_val_00022845.bin 224 224 +24954 ./prep_dataset/ILSVRC2012_val_00007975.bin 224 224 +24955 ./prep_dataset/ILSVRC2012_val_00000999.bin 224 224 +24956 ./prep_dataset/ILSVRC2012_val_00017367.bin 224 224 +24957 ./prep_dataset/ILSVRC2012_val_00012159.bin 224 224 +24958 ./prep_dataset/ILSVRC2012_val_00028612.bin 224 224 +24959 ./prep_dataset/ILSVRC2012_val_00014237.bin 224 224 +24960 ./prep_dataset/ILSVRC2012_val_00016020.bin 224 224 +24961 ./prep_dataset/ILSVRC2012_val_00002011.bin 224 224 +24962 ./prep_dataset/ILSVRC2012_val_00022894.bin 224 224 +24963 ./prep_dataset/ILSVRC2012_val_00009338.bin 224 224 +24964 ./prep_dataset/ILSVRC2012_val_00002808.bin 224 224 +24965 ./prep_dataset/ILSVRC2012_val_00002278.bin 224 224 +24966 ./prep_dataset/ILSVRC2012_val_00033658.bin 224 224 +24967 ./prep_dataset/ILSVRC2012_val_00004914.bin 224 224 +24968 ./prep_dataset/ILSVRC2012_val_00003345.bin 224 224 +24969 ./prep_dataset/ILSVRC2012_val_00007843.bin 224 224 +24970 ./prep_dataset/ILSVRC2012_val_00015476.bin 224 224 +24971 ./prep_dataset/ILSVRC2012_val_00043155.bin 224 224 +24972 ./prep_dataset/ILSVRC2012_val_00022737.bin 224 224 +24973 ./prep_dataset/ILSVRC2012_val_00017351.bin 224 224 +24974 ./prep_dataset/ILSVRC2012_val_00027428.bin 224 224 +24975 ./prep_dataset/ILSVRC2012_val_00006044.bin 224 224 +24976 ./prep_dataset/ILSVRC2012_val_00024357.bin 224 224 +24977 ./prep_dataset/ILSVRC2012_val_00011916.bin 224 224 +24978 ./prep_dataset/ILSVRC2012_val_00026488.bin 224 224 +24979 ./prep_dataset/ILSVRC2012_val_00028093.bin 224 224 +24980 ./prep_dataset/ILSVRC2012_val_00023052.bin 224 224 +24981 ./prep_dataset/ILSVRC2012_val_00012403.bin 224 224 +24982 ./prep_dataset/ILSVRC2012_val_00036830.bin 224 224 +24983 ./prep_dataset/ILSVRC2012_val_00021526.bin 224 224 +24984 ./prep_dataset/ILSVRC2012_val_00042364.bin 224 224 +24985 ./prep_dataset/ILSVRC2012_val_00014698.bin 224 224 +24986 ./prep_dataset/ILSVRC2012_val_00008228.bin 224 224 +24987 ./prep_dataset/ILSVRC2012_val_00004552.bin 224 224 +24988 ./prep_dataset/ILSVRC2012_val_00043269.bin 224 224 +24989 ./prep_dataset/ILSVRC2012_val_00021084.bin 224 224 +24990 ./prep_dataset/ILSVRC2012_val_00023832.bin 224 224 +24991 ./prep_dataset/ILSVRC2012_val_00002122.bin 224 224 +24992 ./prep_dataset/ILSVRC2012_val_00023154.bin 224 224 +24993 ./prep_dataset/ILSVRC2012_val_00013117.bin 224 224 +24994 ./prep_dataset/ILSVRC2012_val_00048024.bin 224 224 +24995 ./prep_dataset/ILSVRC2012_val_00027144.bin 224 224 +24996 ./prep_dataset/ILSVRC2012_val_00004253.bin 224 224 +24997 ./prep_dataset/ILSVRC2012_val_00049317.bin 224 224 +24998 ./prep_dataset/ILSVRC2012_val_00037418.bin 224 224 +24999 ./prep_dataset/ILSVRC2012_val_00031815.bin 224 224 +25000 ./prep_dataset/ILSVRC2012_val_00008310.bin 224 224 +25001 ./prep_dataset/ILSVRC2012_val_00026353.bin 224 224 +25002 ./prep_dataset/ILSVRC2012_val_00022132.bin 224 224 +25003 ./prep_dataset/ILSVRC2012_val_00045112.bin 224 224 +25004 ./prep_dataset/ILSVRC2012_val_00038924.bin 224 224 +25005 ./prep_dataset/ILSVRC2012_val_00048177.bin 224 224 +25006 ./prep_dataset/ILSVRC2012_val_00048893.bin 224 224 +25007 ./prep_dataset/ILSVRC2012_val_00013189.bin 224 224 +25008 ./prep_dataset/ILSVRC2012_val_00008818.bin 224 224 +25009 ./prep_dataset/ILSVRC2012_val_00040847.bin 224 224 +25010 ./prep_dataset/ILSVRC2012_val_00008256.bin 224 224 +25011 ./prep_dataset/ILSVRC2012_val_00037058.bin 224 224 +25012 ./prep_dataset/ILSVRC2012_val_00047103.bin 224 224 +25013 ./prep_dataset/ILSVRC2012_val_00003767.bin 224 224 +25014 ./prep_dataset/ILSVRC2012_val_00017860.bin 224 224 +25015 ./prep_dataset/ILSVRC2012_val_00014303.bin 224 224 +25016 ./prep_dataset/ILSVRC2012_val_00002482.bin 224 224 +25017 ./prep_dataset/ILSVRC2012_val_00048292.bin 224 224 +25018 ./prep_dataset/ILSVRC2012_val_00033551.bin 224 224 +25019 ./prep_dataset/ILSVRC2012_val_00044040.bin 224 224 +25020 ./prep_dataset/ILSVRC2012_val_00014590.bin 224 224 +25021 ./prep_dataset/ILSVRC2012_val_00019375.bin 224 224 +25022 ./prep_dataset/ILSVRC2012_val_00042378.bin 224 224 +25023 ./prep_dataset/ILSVRC2012_val_00001525.bin 224 224 +25024 ./prep_dataset/ILSVRC2012_val_00003151.bin 224 224 +25025 ./prep_dataset/ILSVRC2012_val_00043296.bin 224 224 +25026 ./prep_dataset/ILSVRC2012_val_00012198.bin 224 224 +25027 ./prep_dataset/ILSVRC2012_val_00027352.bin 224 224 +25028 ./prep_dataset/ILSVRC2012_val_00014143.bin 224 224 +25029 ./prep_dataset/ILSVRC2012_val_00048777.bin 224 224 +25030 ./prep_dataset/ILSVRC2012_val_00026500.bin 224 224 +25031 ./prep_dataset/ILSVRC2012_val_00024341.bin 224 224 +25032 ./prep_dataset/ILSVRC2012_val_00044460.bin 224 224 +25033 ./prep_dataset/ILSVRC2012_val_00031211.bin 224 224 +25034 ./prep_dataset/ILSVRC2012_val_00038791.bin 224 224 +25035 ./prep_dataset/ILSVRC2012_val_00025882.bin 224 224 +25036 ./prep_dataset/ILSVRC2012_val_00004269.bin 224 224 +25037 ./prep_dataset/ILSVRC2012_val_00035741.bin 224 224 +25038 ./prep_dataset/ILSVRC2012_val_00016926.bin 224 224 +25039 ./prep_dataset/ILSVRC2012_val_00028124.bin 224 224 +25040 ./prep_dataset/ILSVRC2012_val_00017080.bin 224 224 +25041 ./prep_dataset/ILSVRC2012_val_00020514.bin 224 224 +25042 ./prep_dataset/ILSVRC2012_val_00037681.bin 224 224 +25043 ./prep_dataset/ILSVRC2012_val_00011644.bin 224 224 +25044 ./prep_dataset/ILSVRC2012_val_00034209.bin 224 224 +25045 ./prep_dataset/ILSVRC2012_val_00049951.bin 224 224 +25046 ./prep_dataset/ILSVRC2012_val_00038550.bin 224 224 +25047 ./prep_dataset/ILSVRC2012_val_00020721.bin 224 224 +25048 ./prep_dataset/ILSVRC2012_val_00044597.bin 224 224 +25049 ./prep_dataset/ILSVRC2012_val_00039071.bin 224 224 +25050 ./prep_dataset/ILSVRC2012_val_00010782.bin 224 224 +25051 ./prep_dataset/ILSVRC2012_val_00028767.bin 224 224 +25052 ./prep_dataset/ILSVRC2012_val_00010575.bin 224 224 +25053 ./prep_dataset/ILSVRC2012_val_00008769.bin 224 224 +25054 ./prep_dataset/ILSVRC2012_val_00044672.bin 224 224 +25055 ./prep_dataset/ILSVRC2012_val_00006447.bin 224 224 +25056 ./prep_dataset/ILSVRC2012_val_00009061.bin 224 224 +25057 ./prep_dataset/ILSVRC2012_val_00020380.bin 224 224 +25058 ./prep_dataset/ILSVRC2012_val_00020043.bin 224 224 +25059 ./prep_dataset/ILSVRC2012_val_00034893.bin 224 224 +25060 ./prep_dataset/ILSVRC2012_val_00016145.bin 224 224 +25061 ./prep_dataset/ILSVRC2012_val_00031960.bin 224 224 +25062 ./prep_dataset/ILSVRC2012_val_00000980.bin 224 224 +25063 ./prep_dataset/ILSVRC2012_val_00008177.bin 224 224 +25064 ./prep_dataset/ILSVRC2012_val_00003507.bin 224 224 +25065 ./prep_dataset/ILSVRC2012_val_00037838.bin 224 224 +25066 ./prep_dataset/ILSVRC2012_val_00043533.bin 224 224 +25067 ./prep_dataset/ILSVRC2012_val_00037247.bin 224 224 +25068 ./prep_dataset/ILSVRC2012_val_00047870.bin 224 224 +25069 ./prep_dataset/ILSVRC2012_val_00031325.bin 224 224 +25070 ./prep_dataset/ILSVRC2012_val_00045736.bin 224 224 +25071 ./prep_dataset/ILSVRC2012_val_00026666.bin 224 224 +25072 ./prep_dataset/ILSVRC2012_val_00023425.bin 224 224 +25073 ./prep_dataset/ILSVRC2012_val_00032906.bin 224 224 +25074 ./prep_dataset/ILSVRC2012_val_00024763.bin 224 224 +25075 ./prep_dataset/ILSVRC2012_val_00034397.bin 224 224 +25076 ./prep_dataset/ILSVRC2012_val_00008380.bin 224 224 +25077 ./prep_dataset/ILSVRC2012_val_00013439.bin 224 224 +25078 ./prep_dataset/ILSVRC2012_val_00022436.bin 224 224 +25079 ./prep_dataset/ILSVRC2012_val_00048965.bin 224 224 +25080 ./prep_dataset/ILSVRC2012_val_00029547.bin 224 224 +25081 ./prep_dataset/ILSVRC2012_val_00036857.bin 224 224 +25082 ./prep_dataset/ILSVRC2012_val_00019546.bin 224 224 +25083 ./prep_dataset/ILSVRC2012_val_00002756.bin 224 224 +25084 ./prep_dataset/ILSVRC2012_val_00024252.bin 224 224 +25085 ./prep_dataset/ILSVRC2012_val_00001161.bin 224 224 +25086 ./prep_dataset/ILSVRC2012_val_00044926.bin 224 224 +25087 ./prep_dataset/ILSVRC2012_val_00019672.bin 224 224 +25088 ./prep_dataset/ILSVRC2012_val_00028618.bin 224 224 +25089 ./prep_dataset/ILSVRC2012_val_00019605.bin 224 224 +25090 ./prep_dataset/ILSVRC2012_val_00029388.bin 224 224 +25091 ./prep_dataset/ILSVRC2012_val_00022183.bin 224 224 +25092 ./prep_dataset/ILSVRC2012_val_00027835.bin 224 224 +25093 ./prep_dataset/ILSVRC2012_val_00011135.bin 224 224 +25094 ./prep_dataset/ILSVRC2012_val_00008078.bin 224 224 +25095 ./prep_dataset/ILSVRC2012_val_00014684.bin 224 224 +25096 ./prep_dataset/ILSVRC2012_val_00011602.bin 224 224 +25097 ./prep_dataset/ILSVRC2012_val_00012115.bin 224 224 +25098 ./prep_dataset/ILSVRC2012_val_00026131.bin 224 224 +25099 ./prep_dataset/ILSVRC2012_val_00014353.bin 224 224 +25100 ./prep_dataset/ILSVRC2012_val_00008376.bin 224 224 +25101 ./prep_dataset/ILSVRC2012_val_00011785.bin 224 224 +25102 ./prep_dataset/ILSVRC2012_val_00049818.bin 224 224 +25103 ./prep_dataset/ILSVRC2012_val_00004884.bin 224 224 +25104 ./prep_dataset/ILSVRC2012_val_00010149.bin 224 224 +25105 ./prep_dataset/ILSVRC2012_val_00008796.bin 224 224 +25106 ./prep_dataset/ILSVRC2012_val_00040209.bin 224 224 +25107 ./prep_dataset/ILSVRC2012_val_00033336.bin 224 224 +25108 ./prep_dataset/ILSVRC2012_val_00016856.bin 224 224 +25109 ./prep_dataset/ILSVRC2012_val_00042331.bin 224 224 +25110 ./prep_dataset/ILSVRC2012_val_00008998.bin 224 224 +25111 ./prep_dataset/ILSVRC2012_val_00005603.bin 224 224 +25112 ./prep_dataset/ILSVRC2012_val_00005595.bin 224 224 +25113 ./prep_dataset/ILSVRC2012_val_00022712.bin 224 224 +25114 ./prep_dataset/ILSVRC2012_val_00031370.bin 224 224 +25115 ./prep_dataset/ILSVRC2012_val_00002411.bin 224 224 +25116 ./prep_dataset/ILSVRC2012_val_00019056.bin 224 224 +25117 ./prep_dataset/ILSVRC2012_val_00001517.bin 224 224 +25118 ./prep_dataset/ILSVRC2012_val_00012224.bin 224 224 +25119 ./prep_dataset/ILSVRC2012_val_00005941.bin 224 224 +25120 ./prep_dataset/ILSVRC2012_val_00008367.bin 224 224 +25121 ./prep_dataset/ILSVRC2012_val_00002972.bin 224 224 +25122 ./prep_dataset/ILSVRC2012_val_00032087.bin 224 224 +25123 ./prep_dataset/ILSVRC2012_val_00042711.bin 224 224 +25124 ./prep_dataset/ILSVRC2012_val_00035243.bin 224 224 +25125 ./prep_dataset/ILSVRC2012_val_00027471.bin 224 224 +25126 ./prep_dataset/ILSVRC2012_val_00004672.bin 224 224 +25127 ./prep_dataset/ILSVRC2012_val_00023225.bin 224 224 +25128 ./prep_dataset/ILSVRC2012_val_00017839.bin 224 224 +25129 ./prep_dataset/ILSVRC2012_val_00040056.bin 224 224 +25130 ./prep_dataset/ILSVRC2012_val_00038476.bin 224 224 +25131 ./prep_dataset/ILSVRC2012_val_00009624.bin 224 224 +25132 ./prep_dataset/ILSVRC2012_val_00049784.bin 224 224 +25133 ./prep_dataset/ILSVRC2012_val_00007353.bin 224 224 +25134 ./prep_dataset/ILSVRC2012_val_00019834.bin 224 224 +25135 ./prep_dataset/ILSVRC2012_val_00037840.bin 224 224 +25136 ./prep_dataset/ILSVRC2012_val_00040422.bin 224 224 +25137 ./prep_dataset/ILSVRC2012_val_00049273.bin 224 224 +25138 ./prep_dataset/ILSVRC2012_val_00049151.bin 224 224 +25139 ./prep_dataset/ILSVRC2012_val_00004006.bin 224 224 +25140 ./prep_dataset/ILSVRC2012_val_00017067.bin 224 224 +25141 ./prep_dataset/ILSVRC2012_val_00018359.bin 224 224 +25142 ./prep_dataset/ILSVRC2012_val_00024901.bin 224 224 +25143 ./prep_dataset/ILSVRC2012_val_00021376.bin 224 224 +25144 ./prep_dataset/ILSVRC2012_val_00025411.bin 224 224 +25145 ./prep_dataset/ILSVRC2012_val_00018286.bin 224 224 +25146 ./prep_dataset/ILSVRC2012_val_00012001.bin 224 224 +25147 ./prep_dataset/ILSVRC2012_val_00043430.bin 224 224 +25148 ./prep_dataset/ILSVRC2012_val_00043605.bin 224 224 +25149 ./prep_dataset/ILSVRC2012_val_00012918.bin 224 224 +25150 ./prep_dataset/ILSVRC2012_val_00031008.bin 224 224 +25151 ./prep_dataset/ILSVRC2012_val_00029857.bin 224 224 +25152 ./prep_dataset/ILSVRC2012_val_00010323.bin 224 224 +25153 ./prep_dataset/ILSVRC2012_val_00020964.bin 224 224 +25154 ./prep_dataset/ILSVRC2012_val_00028200.bin 224 224 +25155 ./prep_dataset/ILSVRC2012_val_00017679.bin 224 224 +25156 ./prep_dataset/ILSVRC2012_val_00025104.bin 224 224 +25157 ./prep_dataset/ILSVRC2012_val_00022582.bin 224 224 +25158 ./prep_dataset/ILSVRC2012_val_00039275.bin 224 224 +25159 ./prep_dataset/ILSVRC2012_val_00038015.bin 224 224 +25160 ./prep_dataset/ILSVRC2012_val_00000869.bin 224 224 +25161 ./prep_dataset/ILSVRC2012_val_00018534.bin 224 224 +25162 ./prep_dataset/ILSVRC2012_val_00040759.bin 224 224 +25163 ./prep_dataset/ILSVRC2012_val_00023144.bin 224 224 +25164 ./prep_dataset/ILSVRC2012_val_00039937.bin 224 224 +25165 ./prep_dataset/ILSVRC2012_val_00016379.bin 224 224 +25166 ./prep_dataset/ILSVRC2012_val_00036979.bin 224 224 +25167 ./prep_dataset/ILSVRC2012_val_00032026.bin 224 224 +25168 ./prep_dataset/ILSVRC2012_val_00048183.bin 224 224 +25169 ./prep_dataset/ILSVRC2012_val_00030222.bin 224 224 +25170 ./prep_dataset/ILSVRC2012_val_00040331.bin 224 224 +25171 ./prep_dataset/ILSVRC2012_val_00016007.bin 224 224 +25172 ./prep_dataset/ILSVRC2012_val_00000859.bin 224 224 +25173 ./prep_dataset/ILSVRC2012_val_00007992.bin 224 224 +25174 ./prep_dataset/ILSVRC2012_val_00006570.bin 224 224 +25175 ./prep_dataset/ILSVRC2012_val_00047066.bin 224 224 +25176 ./prep_dataset/ILSVRC2012_val_00031723.bin 224 224 +25177 ./prep_dataset/ILSVRC2012_val_00029888.bin 224 224 +25178 ./prep_dataset/ILSVRC2012_val_00042452.bin 224 224 +25179 ./prep_dataset/ILSVRC2012_val_00036289.bin 224 224 +25180 ./prep_dataset/ILSVRC2012_val_00041759.bin 224 224 +25181 ./prep_dataset/ILSVRC2012_val_00040731.bin 224 224 +25182 ./prep_dataset/ILSVRC2012_val_00003832.bin 224 224 +25183 ./prep_dataset/ILSVRC2012_val_00031696.bin 224 224 +25184 ./prep_dataset/ILSVRC2012_val_00027704.bin 224 224 +25185 ./prep_dataset/ILSVRC2012_val_00005194.bin 224 224 +25186 ./prep_dataset/ILSVRC2012_val_00029990.bin 224 224 +25187 ./prep_dataset/ILSVRC2012_val_00042563.bin 224 224 +25188 ./prep_dataset/ILSVRC2012_val_00044925.bin 224 224 +25189 ./prep_dataset/ILSVRC2012_val_00033519.bin 224 224 +25190 ./prep_dataset/ILSVRC2012_val_00026939.bin 224 224 +25191 ./prep_dataset/ILSVRC2012_val_00034016.bin 224 224 +25192 ./prep_dataset/ILSVRC2012_val_00022050.bin 224 224 +25193 ./prep_dataset/ILSVRC2012_val_00003408.bin 224 224 +25194 ./prep_dataset/ILSVRC2012_val_00035803.bin 224 224 +25195 ./prep_dataset/ILSVRC2012_val_00007899.bin 224 224 +25196 ./prep_dataset/ILSVRC2012_val_00049484.bin 224 224 +25197 ./prep_dataset/ILSVRC2012_val_00025691.bin 224 224 +25198 ./prep_dataset/ILSVRC2012_val_00023864.bin 224 224 +25199 ./prep_dataset/ILSVRC2012_val_00049356.bin 224 224 +25200 ./prep_dataset/ILSVRC2012_val_00036617.bin 224 224 +25201 ./prep_dataset/ILSVRC2012_val_00046811.bin 224 224 +25202 ./prep_dataset/ILSVRC2012_val_00039752.bin 224 224 +25203 ./prep_dataset/ILSVRC2012_val_00023981.bin 224 224 +25204 ./prep_dataset/ILSVRC2012_val_00023243.bin 224 224 +25205 ./prep_dataset/ILSVRC2012_val_00046893.bin 224 224 +25206 ./prep_dataset/ILSVRC2012_val_00036961.bin 224 224 +25207 ./prep_dataset/ILSVRC2012_val_00000575.bin 224 224 +25208 ./prep_dataset/ILSVRC2012_val_00005152.bin 224 224 +25209 ./prep_dataset/ILSVRC2012_val_00041338.bin 224 224 +25210 ./prep_dataset/ILSVRC2012_val_00043650.bin 224 224 +25211 ./prep_dataset/ILSVRC2012_val_00004455.bin 224 224 +25212 ./prep_dataset/ILSVRC2012_val_00004856.bin 224 224 +25213 ./prep_dataset/ILSVRC2012_val_00027031.bin 224 224 +25214 ./prep_dataset/ILSVRC2012_val_00023301.bin 224 224 +25215 ./prep_dataset/ILSVRC2012_val_00039908.bin 224 224 +25216 ./prep_dataset/ILSVRC2012_val_00008229.bin 224 224 +25217 ./prep_dataset/ILSVRC2012_val_00017852.bin 224 224 +25218 ./prep_dataset/ILSVRC2012_val_00032834.bin 224 224 +25219 ./prep_dataset/ILSVRC2012_val_00026798.bin 224 224 +25220 ./prep_dataset/ILSVRC2012_val_00002085.bin 224 224 +25221 ./prep_dataset/ILSVRC2012_val_00039983.bin 224 224 +25222 ./prep_dataset/ILSVRC2012_val_00031719.bin 224 224 +25223 ./prep_dataset/ILSVRC2012_val_00012553.bin 224 224 +25224 ./prep_dataset/ILSVRC2012_val_00043524.bin 224 224 +25225 ./prep_dataset/ILSVRC2012_val_00045300.bin 224 224 +25226 ./prep_dataset/ILSVRC2012_val_00046272.bin 224 224 +25227 ./prep_dataset/ILSVRC2012_val_00028307.bin 224 224 +25228 ./prep_dataset/ILSVRC2012_val_00039356.bin 224 224 +25229 ./prep_dataset/ILSVRC2012_val_00005082.bin 224 224 +25230 ./prep_dataset/ILSVRC2012_val_00024058.bin 224 224 +25231 ./prep_dataset/ILSVRC2012_val_00038691.bin 224 224 +25232 ./prep_dataset/ILSVRC2012_val_00030957.bin 224 224 +25233 ./prep_dataset/ILSVRC2012_val_00038156.bin 224 224 +25234 ./prep_dataset/ILSVRC2012_val_00031501.bin 224 224 +25235 ./prep_dataset/ILSVRC2012_val_00036244.bin 224 224 +25236 ./prep_dataset/ILSVRC2012_val_00016813.bin 224 224 +25237 ./prep_dataset/ILSVRC2012_val_00014601.bin 224 224 +25238 ./prep_dataset/ILSVRC2012_val_00010070.bin 224 224 +25239 ./prep_dataset/ILSVRC2012_val_00001578.bin 224 224 +25240 ./prep_dataset/ILSVRC2012_val_00046872.bin 224 224 +25241 ./prep_dataset/ILSVRC2012_val_00036013.bin 224 224 +25242 ./prep_dataset/ILSVRC2012_val_00002060.bin 224 224 +25243 ./prep_dataset/ILSVRC2012_val_00026373.bin 224 224 +25244 ./prep_dataset/ILSVRC2012_val_00034417.bin 224 224 +25245 ./prep_dataset/ILSVRC2012_val_00024085.bin 224 224 +25246 ./prep_dataset/ILSVRC2012_val_00011154.bin 224 224 +25247 ./prep_dataset/ILSVRC2012_val_00007813.bin 224 224 +25248 ./prep_dataset/ILSVRC2012_val_00029030.bin 224 224 +25249 ./prep_dataset/ILSVRC2012_val_00045124.bin 224 224 +25250 ./prep_dataset/ILSVRC2012_val_00045488.bin 224 224 +25251 ./prep_dataset/ILSVRC2012_val_00011993.bin 224 224 +25252 ./prep_dataset/ILSVRC2012_val_00025741.bin 224 224 +25253 ./prep_dataset/ILSVRC2012_val_00025620.bin 224 224 +25254 ./prep_dataset/ILSVRC2012_val_00043301.bin 224 224 +25255 ./prep_dataset/ILSVRC2012_val_00006084.bin 224 224 +25256 ./prep_dataset/ILSVRC2012_val_00048479.bin 224 224 +25257 ./prep_dataset/ILSVRC2012_val_00004862.bin 224 224 +25258 ./prep_dataset/ILSVRC2012_val_00011547.bin 224 224 +25259 ./prep_dataset/ILSVRC2012_val_00006061.bin 224 224 +25260 ./prep_dataset/ILSVRC2012_val_00018991.bin 224 224 +25261 ./prep_dataset/ILSVRC2012_val_00003289.bin 224 224 +25262 ./prep_dataset/ILSVRC2012_val_00003899.bin 224 224 +25263 ./prep_dataset/ILSVRC2012_val_00048076.bin 224 224 +25264 ./prep_dataset/ILSVRC2012_val_00043515.bin 224 224 +25265 ./prep_dataset/ILSVRC2012_val_00005858.bin 224 224 +25266 ./prep_dataset/ILSVRC2012_val_00002779.bin 224 224 +25267 ./prep_dataset/ILSVRC2012_val_00039811.bin 224 224 +25268 ./prep_dataset/ILSVRC2012_val_00001076.bin 224 224 +25269 ./prep_dataset/ILSVRC2012_val_00028340.bin 224 224 +25270 ./prep_dataset/ILSVRC2012_val_00038954.bin 224 224 +25271 ./prep_dataset/ILSVRC2012_val_00034536.bin 224 224 +25272 ./prep_dataset/ILSVRC2012_val_00027763.bin 224 224 +25273 ./prep_dataset/ILSVRC2012_val_00026636.bin 224 224 +25274 ./prep_dataset/ILSVRC2012_val_00010127.bin 224 224 +25275 ./prep_dataset/ILSVRC2012_val_00014781.bin 224 224 +25276 ./prep_dataset/ILSVRC2012_val_00040772.bin 224 224 +25277 ./prep_dataset/ILSVRC2012_val_00032934.bin 224 224 +25278 ./prep_dataset/ILSVRC2012_val_00034137.bin 224 224 +25279 ./prep_dataset/ILSVRC2012_val_00045952.bin 224 224 +25280 ./prep_dataset/ILSVRC2012_val_00023699.bin 224 224 +25281 ./prep_dataset/ILSVRC2012_val_00009906.bin 224 224 +25282 ./prep_dataset/ILSVRC2012_val_00006953.bin 224 224 +25283 ./prep_dataset/ILSVRC2012_val_00003121.bin 224 224 +25284 ./prep_dataset/ILSVRC2012_val_00015722.bin 224 224 +25285 ./prep_dataset/ILSVRC2012_val_00023219.bin 224 224 +25286 ./prep_dataset/ILSVRC2012_val_00031180.bin 224 224 +25287 ./prep_dataset/ILSVRC2012_val_00032607.bin 224 224 +25288 ./prep_dataset/ILSVRC2012_val_00005624.bin 224 224 +25289 ./prep_dataset/ILSVRC2012_val_00016009.bin 224 224 +25290 ./prep_dataset/ILSVRC2012_val_00031992.bin 224 224 +25291 ./prep_dataset/ILSVRC2012_val_00044695.bin 224 224 +25292 ./prep_dataset/ILSVRC2012_val_00033497.bin 224 224 +25293 ./prep_dataset/ILSVRC2012_val_00016186.bin 224 224 +25294 ./prep_dataset/ILSVRC2012_val_00012399.bin 224 224 +25295 ./prep_dataset/ILSVRC2012_val_00019954.bin 224 224 +25296 ./prep_dataset/ILSVRC2012_val_00005449.bin 224 224 +25297 ./prep_dataset/ILSVRC2012_val_00033284.bin 224 224 +25298 ./prep_dataset/ILSVRC2012_val_00043151.bin 224 224 +25299 ./prep_dataset/ILSVRC2012_val_00021257.bin 224 224 +25300 ./prep_dataset/ILSVRC2012_val_00029660.bin 224 224 +25301 ./prep_dataset/ILSVRC2012_val_00003849.bin 224 224 +25302 ./prep_dataset/ILSVRC2012_val_00002960.bin 224 224 +25303 ./prep_dataset/ILSVRC2012_val_00041158.bin 224 224 +25304 ./prep_dataset/ILSVRC2012_val_00008378.bin 224 224 +25305 ./prep_dataset/ILSVRC2012_val_00024359.bin 224 224 +25306 ./prep_dataset/ILSVRC2012_val_00006240.bin 224 224 +25307 ./prep_dataset/ILSVRC2012_val_00022770.bin 224 224 +25308 ./prep_dataset/ILSVRC2012_val_00049837.bin 224 224 +25309 ./prep_dataset/ILSVRC2012_val_00010945.bin 224 224 +25310 ./prep_dataset/ILSVRC2012_val_00006158.bin 224 224 +25311 ./prep_dataset/ILSVRC2012_val_00000915.bin 224 224 +25312 ./prep_dataset/ILSVRC2012_val_00044938.bin 224 224 +25313 ./prep_dataset/ILSVRC2012_val_00022547.bin 224 224 +25314 ./prep_dataset/ILSVRC2012_val_00007500.bin 224 224 +25315 ./prep_dataset/ILSVRC2012_val_00038515.bin 224 224 +25316 ./prep_dataset/ILSVRC2012_val_00000773.bin 224 224 +25317 ./prep_dataset/ILSVRC2012_val_00016703.bin 224 224 +25318 ./prep_dataset/ILSVRC2012_val_00000483.bin 224 224 +25319 ./prep_dataset/ILSVRC2012_val_00042928.bin 224 224 +25320 ./prep_dataset/ILSVRC2012_val_00048753.bin 224 224 +25321 ./prep_dataset/ILSVRC2012_val_00046469.bin 224 224 +25322 ./prep_dataset/ILSVRC2012_val_00040251.bin 224 224 +25323 ./prep_dataset/ILSVRC2012_val_00028191.bin 224 224 +25324 ./prep_dataset/ILSVRC2012_val_00021724.bin 224 224 +25325 ./prep_dataset/ILSVRC2012_val_00033501.bin 224 224 +25326 ./prep_dataset/ILSVRC2012_val_00017445.bin 224 224 +25327 ./prep_dataset/ILSVRC2012_val_00027800.bin 224 224 +25328 ./prep_dataset/ILSVRC2012_val_00001289.bin 224 224 +25329 ./prep_dataset/ILSVRC2012_val_00018143.bin 224 224 +25330 ./prep_dataset/ILSVRC2012_val_00014361.bin 224 224 +25331 ./prep_dataset/ILSVRC2012_val_00030717.bin 224 224 +25332 ./prep_dataset/ILSVRC2012_val_00003112.bin 224 224 +25333 ./prep_dataset/ILSVRC2012_val_00040173.bin 224 224 +25334 ./prep_dataset/ILSVRC2012_val_00011314.bin 224 224 +25335 ./prep_dataset/ILSVRC2012_val_00046356.bin 224 224 +25336 ./prep_dataset/ILSVRC2012_val_00018377.bin 224 224 +25337 ./prep_dataset/ILSVRC2012_val_00020905.bin 224 224 +25338 ./prep_dataset/ILSVRC2012_val_00020814.bin 224 224 +25339 ./prep_dataset/ILSVRC2012_val_00049343.bin 224 224 +25340 ./prep_dataset/ILSVRC2012_val_00045513.bin 224 224 +25341 ./prep_dataset/ILSVRC2012_val_00026836.bin 224 224 +25342 ./prep_dataset/ILSVRC2012_val_00021684.bin 224 224 +25343 ./prep_dataset/ILSVRC2012_val_00001362.bin 224 224 +25344 ./prep_dataset/ILSVRC2012_val_00026480.bin 224 224 +25345 ./prep_dataset/ILSVRC2012_val_00017963.bin 224 224 +25346 ./prep_dataset/ILSVRC2012_val_00032014.bin 224 224 +25347 ./prep_dataset/ILSVRC2012_val_00036930.bin 224 224 +25348 ./prep_dataset/ILSVRC2012_val_00016743.bin 224 224 +25349 ./prep_dataset/ILSVRC2012_val_00006436.bin 224 224 +25350 ./prep_dataset/ILSVRC2012_val_00023047.bin 224 224 +25351 ./prep_dataset/ILSVRC2012_val_00049440.bin 224 224 +25352 ./prep_dataset/ILSVRC2012_val_00027979.bin 224 224 +25353 ./prep_dataset/ILSVRC2012_val_00025519.bin 224 224 +25354 ./prep_dataset/ILSVRC2012_val_00045233.bin 224 224 +25355 ./prep_dataset/ILSVRC2012_val_00003882.bin 224 224 +25356 ./prep_dataset/ILSVRC2012_val_00042724.bin 224 224 +25357 ./prep_dataset/ILSVRC2012_val_00024394.bin 224 224 +25358 ./prep_dataset/ILSVRC2012_val_00005970.bin 224 224 +25359 ./prep_dataset/ILSVRC2012_val_00020771.bin 224 224 +25360 ./prep_dataset/ILSVRC2012_val_00038652.bin 224 224 +25361 ./prep_dataset/ILSVRC2012_val_00043771.bin 224 224 +25362 ./prep_dataset/ILSVRC2012_val_00010513.bin 224 224 +25363 ./prep_dataset/ILSVRC2012_val_00034734.bin 224 224 +25364 ./prep_dataset/ILSVRC2012_val_00037841.bin 224 224 +25365 ./prep_dataset/ILSVRC2012_val_00027694.bin 224 224 +25366 ./prep_dataset/ILSVRC2012_val_00007901.bin 224 224 +25367 ./prep_dataset/ILSVRC2012_val_00008806.bin 224 224 +25368 ./prep_dataset/ILSVRC2012_val_00012194.bin 224 224 +25369 ./prep_dataset/ILSVRC2012_val_00002466.bin 224 224 +25370 ./prep_dataset/ILSVRC2012_val_00022546.bin 224 224 +25371 ./prep_dataset/ILSVRC2012_val_00031095.bin 224 224 +25372 ./prep_dataset/ILSVRC2012_val_00016098.bin 224 224 +25373 ./prep_dataset/ILSVRC2012_val_00007818.bin 224 224 +25374 ./prep_dataset/ILSVRC2012_val_00049754.bin 224 224 +25375 ./prep_dataset/ILSVRC2012_val_00022585.bin 224 224 +25376 ./prep_dataset/ILSVRC2012_val_00011143.bin 224 224 +25377 ./prep_dataset/ILSVRC2012_val_00015018.bin 224 224 +25378 ./prep_dataset/ILSVRC2012_val_00046328.bin 224 224 +25379 ./prep_dataset/ILSVRC2012_val_00021396.bin 224 224 +25380 ./prep_dataset/ILSVRC2012_val_00046815.bin 224 224 +25381 ./prep_dataset/ILSVRC2012_val_00016581.bin 224 224 +25382 ./prep_dataset/ILSVRC2012_val_00015947.bin 224 224 +25383 ./prep_dataset/ILSVRC2012_val_00038384.bin 224 224 +25384 ./prep_dataset/ILSVRC2012_val_00025239.bin 224 224 +25385 ./prep_dataset/ILSVRC2012_val_00004445.bin 224 224 +25386 ./prep_dataset/ILSVRC2012_val_00004991.bin 224 224 +25387 ./prep_dataset/ILSVRC2012_val_00019403.bin 224 224 +25388 ./prep_dataset/ILSVRC2012_val_00037237.bin 224 224 +25389 ./prep_dataset/ILSVRC2012_val_00024904.bin 224 224 +25390 ./prep_dataset/ILSVRC2012_val_00002340.bin 224 224 +25391 ./prep_dataset/ILSVRC2012_val_00018485.bin 224 224 +25392 ./prep_dataset/ILSVRC2012_val_00046350.bin 224 224 +25393 ./prep_dataset/ILSVRC2012_val_00037236.bin 224 224 +25394 ./prep_dataset/ILSVRC2012_val_00001919.bin 224 224 +25395 ./prep_dataset/ILSVRC2012_val_00016027.bin 224 224 +25396 ./prep_dataset/ILSVRC2012_val_00039102.bin 224 224 +25397 ./prep_dataset/ILSVRC2012_val_00042017.bin 224 224 +25398 ./prep_dataset/ILSVRC2012_val_00000696.bin 224 224 +25399 ./prep_dataset/ILSVRC2012_val_00034413.bin 224 224 +25400 ./prep_dataset/ILSVRC2012_val_00001445.bin 224 224 +25401 ./prep_dataset/ILSVRC2012_val_00022146.bin 224 224 +25402 ./prep_dataset/ILSVRC2012_val_00036815.bin 224 224 +25403 ./prep_dataset/ILSVRC2012_val_00038864.bin 224 224 +25404 ./prep_dataset/ILSVRC2012_val_00029588.bin 224 224 +25405 ./prep_dataset/ILSVRC2012_val_00044387.bin 224 224 +25406 ./prep_dataset/ILSVRC2012_val_00000312.bin 224 224 +25407 ./prep_dataset/ILSVRC2012_val_00011389.bin 224 224 +25408 ./prep_dataset/ILSVRC2012_val_00030041.bin 224 224 +25409 ./prep_dataset/ILSVRC2012_val_00029605.bin 224 224 +25410 ./prep_dataset/ILSVRC2012_val_00035819.bin 224 224 +25411 ./prep_dataset/ILSVRC2012_val_00008243.bin 224 224 +25412 ./prep_dataset/ILSVRC2012_val_00023161.bin 224 224 +25413 ./prep_dataset/ILSVRC2012_val_00043198.bin 224 224 +25414 ./prep_dataset/ILSVRC2012_val_00040395.bin 224 224 +25415 ./prep_dataset/ILSVRC2012_val_00018119.bin 224 224 +25416 ./prep_dataset/ILSVRC2012_val_00032956.bin 224 224 +25417 ./prep_dataset/ILSVRC2012_val_00002776.bin 224 224 +25418 ./prep_dataset/ILSVRC2012_val_00001688.bin 224 224 +25419 ./prep_dataset/ILSVRC2012_val_00027024.bin 224 224 +25420 ./prep_dataset/ILSVRC2012_val_00020732.bin 224 224 +25421 ./prep_dataset/ILSVRC2012_val_00020835.bin 224 224 +25422 ./prep_dataset/ILSVRC2012_val_00018814.bin 224 224 +25423 ./prep_dataset/ILSVRC2012_val_00032377.bin 224 224 +25424 ./prep_dataset/ILSVRC2012_val_00042761.bin 224 224 +25425 ./prep_dataset/ILSVRC2012_val_00026592.bin 224 224 +25426 ./prep_dataset/ILSVRC2012_val_00044179.bin 224 224 +25427 ./prep_dataset/ILSVRC2012_val_00027448.bin 224 224 +25428 ./prep_dataset/ILSVRC2012_val_00047699.bin 224 224 +25429 ./prep_dataset/ILSVRC2012_val_00029258.bin 224 224 +25430 ./prep_dataset/ILSVRC2012_val_00031063.bin 224 224 +25431 ./prep_dataset/ILSVRC2012_val_00044770.bin 224 224 +25432 ./prep_dataset/ILSVRC2012_val_00045161.bin 224 224 +25433 ./prep_dataset/ILSVRC2012_val_00006104.bin 224 224 +25434 ./prep_dataset/ILSVRC2012_val_00020559.bin 224 224 +25435 ./prep_dataset/ILSVRC2012_val_00020224.bin 224 224 +25436 ./prep_dataset/ILSVRC2012_val_00017644.bin 224 224 +25437 ./prep_dataset/ILSVRC2012_val_00036736.bin 224 224 +25438 ./prep_dataset/ILSVRC2012_val_00029891.bin 224 224 +25439 ./prep_dataset/ILSVRC2012_val_00031856.bin 224 224 +25440 ./prep_dataset/ILSVRC2012_val_00020593.bin 224 224 +25441 ./prep_dataset/ILSVRC2012_val_00016602.bin 224 224 +25442 ./prep_dataset/ILSVRC2012_val_00024661.bin 224 224 +25443 ./prep_dataset/ILSVRC2012_val_00005492.bin 224 224 +25444 ./prep_dataset/ILSVRC2012_val_00017861.bin 224 224 +25445 ./prep_dataset/ILSVRC2012_val_00040433.bin 224 224 +25446 ./prep_dataset/ILSVRC2012_val_00047490.bin 224 224 +25447 ./prep_dataset/ILSVRC2012_val_00004954.bin 224 224 +25448 ./prep_dataset/ILSVRC2012_val_00000666.bin 224 224 +25449 ./prep_dataset/ILSVRC2012_val_00027939.bin 224 224 +25450 ./prep_dataset/ILSVRC2012_val_00032415.bin 224 224 +25451 ./prep_dataset/ILSVRC2012_val_00010814.bin 224 224 +25452 ./prep_dataset/ILSVRC2012_val_00023479.bin 224 224 +25453 ./prep_dataset/ILSVRC2012_val_00033329.bin 224 224 +25454 ./prep_dataset/ILSVRC2012_val_00045159.bin 224 224 +25455 ./prep_dataset/ILSVRC2012_val_00005689.bin 224 224 +25456 ./prep_dataset/ILSVRC2012_val_00001710.bin 224 224 +25457 ./prep_dataset/ILSVRC2012_val_00044867.bin 224 224 +25458 ./prep_dataset/ILSVRC2012_val_00023389.bin 224 224 +25459 ./prep_dataset/ILSVRC2012_val_00041357.bin 224 224 +25460 ./prep_dataset/ILSVRC2012_val_00032903.bin 224 224 +25461 ./prep_dataset/ILSVRC2012_val_00019799.bin 224 224 +25462 ./prep_dataset/ILSVRC2012_val_00001037.bin 224 224 +25463 ./prep_dataset/ILSVRC2012_val_00007646.bin 224 224 +25464 ./prep_dataset/ILSVRC2012_val_00001049.bin 224 224 +25465 ./prep_dataset/ILSVRC2012_val_00047653.bin 224 224 +25466 ./prep_dataset/ILSVRC2012_val_00034993.bin 224 224 +25467 ./prep_dataset/ILSVRC2012_val_00022991.bin 224 224 +25468 ./prep_dataset/ILSVRC2012_val_00035107.bin 224 224 +25469 ./prep_dataset/ILSVRC2012_val_00010869.bin 224 224 +25470 ./prep_dataset/ILSVRC2012_val_00012228.bin 224 224 +25471 ./prep_dataset/ILSVRC2012_val_00036585.bin 224 224 +25472 ./prep_dataset/ILSVRC2012_val_00021590.bin 224 224 +25473 ./prep_dataset/ILSVRC2012_val_00043458.bin 224 224 +25474 ./prep_dataset/ILSVRC2012_val_00013361.bin 224 224 +25475 ./prep_dataset/ILSVRC2012_val_00006231.bin 224 224 +25476 ./prep_dataset/ILSVRC2012_val_00036242.bin 224 224 +25477 ./prep_dataset/ILSVRC2012_val_00008117.bin 224 224 +25478 ./prep_dataset/ILSVRC2012_val_00039772.bin 224 224 +25479 ./prep_dataset/ILSVRC2012_val_00037698.bin 224 224 +25480 ./prep_dataset/ILSVRC2012_val_00024088.bin 224 224 +25481 ./prep_dataset/ILSVRC2012_val_00022147.bin 224 224 +25482 ./prep_dataset/ILSVRC2012_val_00010284.bin 224 224 +25483 ./prep_dataset/ILSVRC2012_val_00045211.bin 224 224 +25484 ./prep_dataset/ILSVRC2012_val_00007750.bin 224 224 +25485 ./prep_dataset/ILSVRC2012_val_00004034.bin 224 224 +25486 ./prep_dataset/ILSVRC2012_val_00025550.bin 224 224 +25487 ./prep_dataset/ILSVRC2012_val_00016631.bin 224 224 +25488 ./prep_dataset/ILSVRC2012_val_00049741.bin 224 224 +25489 ./prep_dataset/ILSVRC2012_val_00044494.bin 224 224 +25490 ./prep_dataset/ILSVRC2012_val_00049550.bin 224 224 +25491 ./prep_dataset/ILSVRC2012_val_00039132.bin 224 224 +25492 ./prep_dataset/ILSVRC2012_val_00035458.bin 224 224 +25493 ./prep_dataset/ILSVRC2012_val_00013180.bin 224 224 +25494 ./prep_dataset/ILSVRC2012_val_00048429.bin 224 224 +25495 ./prep_dataset/ILSVRC2012_val_00032910.bin 224 224 +25496 ./prep_dataset/ILSVRC2012_val_00018432.bin 224 224 +25497 ./prep_dataset/ILSVRC2012_val_00045408.bin 224 224 +25498 ./prep_dataset/ILSVRC2012_val_00033955.bin 224 224 +25499 ./prep_dataset/ILSVRC2012_val_00006506.bin 224 224 +25500 ./prep_dataset/ILSVRC2012_val_00028693.bin 224 224 +25501 ./prep_dataset/ILSVRC2012_val_00042026.bin 224 224 +25502 ./prep_dataset/ILSVRC2012_val_00014400.bin 224 224 +25503 ./prep_dataset/ILSVRC2012_val_00002665.bin 224 224 +25504 ./prep_dataset/ILSVRC2012_val_00016640.bin 224 224 +25505 ./prep_dataset/ILSVRC2012_val_00037882.bin 224 224 +25506 ./prep_dataset/ILSVRC2012_val_00011304.bin 224 224 +25507 ./prep_dataset/ILSVRC2012_val_00014953.bin 224 224 +25508 ./prep_dataset/ILSVRC2012_val_00016980.bin 224 224 +25509 ./prep_dataset/ILSVRC2012_val_00032642.bin 224 224 +25510 ./prep_dataset/ILSVRC2012_val_00014248.bin 224 224 +25511 ./prep_dataset/ILSVRC2012_val_00017937.bin 224 224 +25512 ./prep_dataset/ILSVRC2012_val_00014255.bin 224 224 +25513 ./prep_dataset/ILSVRC2012_val_00018720.bin 224 224 +25514 ./prep_dataset/ILSVRC2012_val_00047577.bin 224 224 +25515 ./prep_dataset/ILSVRC2012_val_00049224.bin 224 224 +25516 ./prep_dataset/ILSVRC2012_val_00010556.bin 224 224 +25517 ./prep_dataset/ILSVRC2012_val_00039867.bin 224 224 +25518 ./prep_dataset/ILSVRC2012_val_00029135.bin 224 224 +25519 ./prep_dataset/ILSVRC2012_val_00023155.bin 224 224 +25520 ./prep_dataset/ILSVRC2012_val_00008899.bin 224 224 +25521 ./prep_dataset/ILSVRC2012_val_00023016.bin 224 224 +25522 ./prep_dataset/ILSVRC2012_val_00034102.bin 224 224 +25523 ./prep_dataset/ILSVRC2012_val_00033975.bin 224 224 +25524 ./prep_dataset/ILSVRC2012_val_00030338.bin 224 224 +25525 ./prep_dataset/ILSVRC2012_val_00027723.bin 224 224 +25526 ./prep_dataset/ILSVRC2012_val_00001091.bin 224 224 +25527 ./prep_dataset/ILSVRC2012_val_00003467.bin 224 224 +25528 ./prep_dataset/ILSVRC2012_val_00019987.bin 224 224 +25529 ./prep_dataset/ILSVRC2012_val_00038031.bin 224 224 +25530 ./prep_dataset/ILSVRC2012_val_00024332.bin 224 224 +25531 ./prep_dataset/ILSVRC2012_val_00014444.bin 224 224 +25532 ./prep_dataset/ILSVRC2012_val_00019244.bin 224 224 +25533 ./prep_dataset/ILSVRC2012_val_00039022.bin 224 224 +25534 ./prep_dataset/ILSVRC2012_val_00037965.bin 224 224 +25535 ./prep_dataset/ILSVRC2012_val_00032507.bin 224 224 +25536 ./prep_dataset/ILSVRC2012_val_00013666.bin 224 224 +25537 ./prep_dataset/ILSVRC2012_val_00014558.bin 224 224 +25538 ./prep_dataset/ILSVRC2012_val_00011881.bin 224 224 +25539 ./prep_dataset/ILSVRC2012_val_00024939.bin 224 224 +25540 ./prep_dataset/ILSVRC2012_val_00047896.bin 224 224 +25541 ./prep_dataset/ILSVRC2012_val_00013584.bin 224 224 +25542 ./prep_dataset/ILSVRC2012_val_00042218.bin 224 224 +25543 ./prep_dataset/ILSVRC2012_val_00045345.bin 224 224 +25544 ./prep_dataset/ILSVRC2012_val_00049845.bin 224 224 +25545 ./prep_dataset/ILSVRC2012_val_00025001.bin 224 224 +25546 ./prep_dataset/ILSVRC2012_val_00002095.bin 224 224 +25547 ./prep_dataset/ILSVRC2012_val_00019977.bin 224 224 +25548 ./prep_dataset/ILSVRC2012_val_00038500.bin 224 224 +25549 ./prep_dataset/ILSVRC2012_val_00026335.bin 224 224 +25550 ./prep_dataset/ILSVRC2012_val_00012874.bin 224 224 +25551 ./prep_dataset/ILSVRC2012_val_00018469.bin 224 224 +25552 ./prep_dataset/ILSVRC2012_val_00026071.bin 224 224 +25553 ./prep_dataset/ILSVRC2012_val_00018690.bin 224 224 +25554 ./prep_dataset/ILSVRC2012_val_00013813.bin 224 224 +25555 ./prep_dataset/ILSVRC2012_val_00010525.bin 224 224 +25556 ./prep_dataset/ILSVRC2012_val_00027617.bin 224 224 +25557 ./prep_dataset/ILSVRC2012_val_00003748.bin 224 224 +25558 ./prep_dataset/ILSVRC2012_val_00035474.bin 224 224 +25559 ./prep_dataset/ILSVRC2012_val_00002334.bin 224 224 +25560 ./prep_dataset/ILSVRC2012_val_00026195.bin 224 224 +25561 ./prep_dataset/ILSVRC2012_val_00039540.bin 224 224 +25562 ./prep_dataset/ILSVRC2012_val_00021397.bin 224 224 +25563 ./prep_dataset/ILSVRC2012_val_00007743.bin 224 224 +25564 ./prep_dataset/ILSVRC2012_val_00008563.bin 224 224 +25565 ./prep_dataset/ILSVRC2012_val_00049710.bin 224 224 +25566 ./prep_dataset/ILSVRC2012_val_00017130.bin 224 224 +25567 ./prep_dataset/ILSVRC2012_val_00006278.bin 224 224 +25568 ./prep_dataset/ILSVRC2012_val_00027322.bin 224 224 +25569 ./prep_dataset/ILSVRC2012_val_00044361.bin 224 224 +25570 ./prep_dataset/ILSVRC2012_val_00013081.bin 224 224 +25571 ./prep_dataset/ILSVRC2012_val_00006516.bin 224 224 +25572 ./prep_dataset/ILSVRC2012_val_00047112.bin 224 224 +25573 ./prep_dataset/ILSVRC2012_val_00012509.bin 224 224 +25574 ./prep_dataset/ILSVRC2012_val_00021773.bin 224 224 +25575 ./prep_dataset/ILSVRC2012_val_00022449.bin 224 224 +25576 ./prep_dataset/ILSVRC2012_val_00021846.bin 224 224 +25577 ./prep_dataset/ILSVRC2012_val_00018979.bin 224 224 +25578 ./prep_dataset/ILSVRC2012_val_00003662.bin 224 224 +25579 ./prep_dataset/ILSVRC2012_val_00049071.bin 224 224 +25580 ./prep_dataset/ILSVRC2012_val_00041033.bin 224 224 +25581 ./prep_dataset/ILSVRC2012_val_00043656.bin 224 224 +25582 ./prep_dataset/ILSVRC2012_val_00026489.bin 224 224 +25583 ./prep_dataset/ILSVRC2012_val_00024236.bin 224 224 +25584 ./prep_dataset/ILSVRC2012_val_00018668.bin 224 224 +25585 ./prep_dataset/ILSVRC2012_val_00038813.bin 224 224 +25586 ./prep_dataset/ILSVRC2012_val_00021097.bin 224 224 +25587 ./prep_dataset/ILSVRC2012_val_00035473.bin 224 224 +25588 ./prep_dataset/ILSVRC2012_val_00039376.bin 224 224 +25589 ./prep_dataset/ILSVRC2012_val_00007794.bin 224 224 +25590 ./prep_dataset/ILSVRC2012_val_00028358.bin 224 224 +25591 ./prep_dataset/ILSVRC2012_val_00029619.bin 224 224 +25592 ./prep_dataset/ILSVRC2012_val_00037786.bin 224 224 +25593 ./prep_dataset/ILSVRC2012_val_00044349.bin 224 224 +25594 ./prep_dataset/ILSVRC2012_val_00036220.bin 224 224 +25595 ./prep_dataset/ILSVRC2012_val_00040201.bin 224 224 +25596 ./prep_dataset/ILSVRC2012_val_00037872.bin 224 224 +25597 ./prep_dataset/ILSVRC2012_val_00033034.bin 224 224 +25598 ./prep_dataset/ILSVRC2012_val_00041455.bin 224 224 +25599 ./prep_dataset/ILSVRC2012_val_00021133.bin 224 224 +25600 ./prep_dataset/ILSVRC2012_val_00024920.bin 224 224 +25601 ./prep_dataset/ILSVRC2012_val_00043259.bin 224 224 +25602 ./prep_dataset/ILSVRC2012_val_00026093.bin 224 224 +25603 ./prep_dataset/ILSVRC2012_val_00037266.bin 224 224 +25604 ./prep_dataset/ILSVRC2012_val_00028175.bin 224 224 +25605 ./prep_dataset/ILSVRC2012_val_00032016.bin 224 224 +25606 ./prep_dataset/ILSVRC2012_val_00038679.bin 224 224 +25607 ./prep_dataset/ILSVRC2012_val_00049698.bin 224 224 +25608 ./prep_dataset/ILSVRC2012_val_00041353.bin 224 224 +25609 ./prep_dataset/ILSVRC2012_val_00043069.bin 224 224 +25610 ./prep_dataset/ILSVRC2012_val_00025065.bin 224 224 +25611 ./prep_dataset/ILSVRC2012_val_00016651.bin 224 224 +25612 ./prep_dataset/ILSVRC2012_val_00042717.bin 224 224 +25613 ./prep_dataset/ILSVRC2012_val_00034892.bin 224 224 +25614 ./prep_dataset/ILSVRC2012_val_00028410.bin 224 224 +25615 ./prep_dataset/ILSVRC2012_val_00000434.bin 224 224 +25616 ./prep_dataset/ILSVRC2012_val_00047649.bin 224 224 +25617 ./prep_dataset/ILSVRC2012_val_00017451.bin 224 224 +25618 ./prep_dataset/ILSVRC2012_val_00004131.bin 224 224 +25619 ./prep_dataset/ILSVRC2012_val_00042804.bin 224 224 +25620 ./prep_dataset/ILSVRC2012_val_00047075.bin 224 224 +25621 ./prep_dataset/ILSVRC2012_val_00032501.bin 224 224 +25622 ./prep_dataset/ILSVRC2012_val_00007602.bin 224 224 +25623 ./prep_dataset/ILSVRC2012_val_00047509.bin 224 224 +25624 ./prep_dataset/ILSVRC2012_val_00021699.bin 224 224 +25625 ./prep_dataset/ILSVRC2012_val_00007249.bin 224 224 +25626 ./prep_dataset/ILSVRC2012_val_00014194.bin 224 224 +25627 ./prep_dataset/ILSVRC2012_val_00043098.bin 224 224 +25628 ./prep_dataset/ILSVRC2012_val_00017945.bin 224 224 +25629 ./prep_dataset/ILSVRC2012_val_00027757.bin 224 224 +25630 ./prep_dataset/ILSVRC2012_val_00014036.bin 224 224 +25631 ./prep_dataset/ILSVRC2012_val_00028923.bin 224 224 +25632 ./prep_dataset/ILSVRC2012_val_00001072.bin 224 224 +25633 ./prep_dataset/ILSVRC2012_val_00018105.bin 224 224 +25634 ./prep_dataset/ILSVRC2012_val_00034900.bin 224 224 +25635 ./prep_dataset/ILSVRC2012_val_00047011.bin 224 224 +25636 ./prep_dataset/ILSVRC2012_val_00025231.bin 224 224 +25637 ./prep_dataset/ILSVRC2012_val_00019115.bin 224 224 +25638 ./prep_dataset/ILSVRC2012_val_00009795.bin 224 224 +25639 ./prep_dataset/ILSVRC2012_val_00020300.bin 224 224 +25640 ./prep_dataset/ILSVRC2012_val_00011894.bin 224 224 +25641 ./prep_dataset/ILSVRC2012_val_00014442.bin 224 224 +25642 ./prep_dataset/ILSVRC2012_val_00025134.bin 224 224 +25643 ./prep_dataset/ILSVRC2012_val_00010533.bin 224 224 +25644 ./prep_dataset/ILSVRC2012_val_00018077.bin 224 224 +25645 ./prep_dataset/ILSVRC2012_val_00002652.bin 224 224 +25646 ./prep_dataset/ILSVRC2012_val_00003445.bin 224 224 +25647 ./prep_dataset/ILSVRC2012_val_00021117.bin 224 224 +25648 ./prep_dataset/ILSVRC2012_val_00004762.bin 224 224 +25649 ./prep_dataset/ILSVRC2012_val_00047287.bin 224 224 +25650 ./prep_dataset/ILSVRC2012_val_00015901.bin 224 224 +25651 ./prep_dataset/ILSVRC2012_val_00020149.bin 224 224 +25652 ./prep_dataset/ILSVRC2012_val_00016812.bin 224 224 +25653 ./prep_dataset/ILSVRC2012_val_00030066.bin 224 224 +25654 ./prep_dataset/ILSVRC2012_val_00007982.bin 224 224 +25655 ./prep_dataset/ILSVRC2012_val_00024062.bin 224 224 +25656 ./prep_dataset/ILSVRC2012_val_00013449.bin 224 224 +25657 ./prep_dataset/ILSVRC2012_val_00028306.bin 224 224 +25658 ./prep_dataset/ILSVRC2012_val_00035087.bin 224 224 +25659 ./prep_dataset/ILSVRC2012_val_00038979.bin 224 224 +25660 ./prep_dataset/ILSVRC2012_val_00046781.bin 224 224 +25661 ./prep_dataset/ILSVRC2012_val_00033935.bin 224 224 +25662 ./prep_dataset/ILSVRC2012_val_00032054.bin 224 224 +25663 ./prep_dataset/ILSVRC2012_val_00043781.bin 224 224 +25664 ./prep_dataset/ILSVRC2012_val_00012839.bin 224 224 +25665 ./prep_dataset/ILSVRC2012_val_00028996.bin 224 224 +25666 ./prep_dataset/ILSVRC2012_val_00039448.bin 224 224 +25667 ./prep_dataset/ILSVRC2012_val_00033394.bin 224 224 +25668 ./prep_dataset/ILSVRC2012_val_00042113.bin 224 224 +25669 ./prep_dataset/ILSVRC2012_val_00001106.bin 224 224 +25670 ./prep_dataset/ILSVRC2012_val_00047136.bin 224 224 +25671 ./prep_dataset/ILSVRC2012_val_00027622.bin 224 224 +25672 ./prep_dataset/ILSVRC2012_val_00034455.bin 224 224 +25673 ./prep_dataset/ILSVRC2012_val_00036836.bin 224 224 +25674 ./prep_dataset/ILSVRC2012_val_00042039.bin 224 224 +25675 ./prep_dataset/ILSVRC2012_val_00035381.bin 224 224 +25676 ./prep_dataset/ILSVRC2012_val_00038340.bin 224 224 +25677 ./prep_dataset/ILSVRC2012_val_00036378.bin 224 224 +25678 ./prep_dataset/ILSVRC2012_val_00009567.bin 224 224 +25679 ./prep_dataset/ILSVRC2012_val_00003703.bin 224 224 +25680 ./prep_dataset/ILSVRC2012_val_00009288.bin 224 224 +25681 ./prep_dataset/ILSVRC2012_val_00040026.bin 224 224 +25682 ./prep_dataset/ILSVRC2012_val_00025833.bin 224 224 +25683 ./prep_dataset/ILSVRC2012_val_00023550.bin 224 224 +25684 ./prep_dataset/ILSVRC2012_val_00049553.bin 224 224 +25685 ./prep_dataset/ILSVRC2012_val_00046371.bin 224 224 +25686 ./prep_dataset/ILSVRC2012_val_00024884.bin 224 224 +25687 ./prep_dataset/ILSVRC2012_val_00039645.bin 224 224 +25688 ./prep_dataset/ILSVRC2012_val_00012107.bin 224 224 +25689 ./prep_dataset/ILSVRC2012_val_00038410.bin 224 224 +25690 ./prep_dataset/ILSVRC2012_val_00015828.bin 224 224 +25691 ./prep_dataset/ILSVRC2012_val_00015793.bin 224 224 +25692 ./prep_dataset/ILSVRC2012_val_00029070.bin 224 224 +25693 ./prep_dataset/ILSVRC2012_val_00038602.bin 224 224 +25694 ./prep_dataset/ILSVRC2012_val_00044911.bin 224 224 +25695 ./prep_dataset/ILSVRC2012_val_00044340.bin 224 224 +25696 ./prep_dataset/ILSVRC2012_val_00008568.bin 224 224 +25697 ./prep_dataset/ILSVRC2012_val_00002735.bin 224 224 +25698 ./prep_dataset/ILSVRC2012_val_00046097.bin 224 224 +25699 ./prep_dataset/ILSVRC2012_val_00036939.bin 224 224 +25700 ./prep_dataset/ILSVRC2012_val_00039087.bin 224 224 +25701 ./prep_dataset/ILSVRC2012_val_00003980.bin 224 224 +25702 ./prep_dataset/ILSVRC2012_val_00019898.bin 224 224 +25703 ./prep_dataset/ILSVRC2012_val_00000764.bin 224 224 +25704 ./prep_dataset/ILSVRC2012_val_00036010.bin 224 224 +25705 ./prep_dataset/ILSVRC2012_val_00020945.bin 224 224 +25706 ./prep_dataset/ILSVRC2012_val_00022006.bin 224 224 +25707 ./prep_dataset/ILSVRC2012_val_00047078.bin 224 224 +25708 ./prep_dataset/ILSVRC2012_val_00016460.bin 224 224 +25709 ./prep_dataset/ILSVRC2012_val_00002510.bin 224 224 +25710 ./prep_dataset/ILSVRC2012_val_00009940.bin 224 224 +25711 ./prep_dataset/ILSVRC2012_val_00041216.bin 224 224 +25712 ./prep_dataset/ILSVRC2012_val_00033776.bin 224 224 +25713 ./prep_dataset/ILSVRC2012_val_00003427.bin 224 224 +25714 ./prep_dataset/ILSVRC2012_val_00040696.bin 224 224 +25715 ./prep_dataset/ILSVRC2012_val_00049300.bin 224 224 +25716 ./prep_dataset/ILSVRC2012_val_00023724.bin 224 224 +25717 ./prep_dataset/ILSVRC2012_val_00016092.bin 224 224 +25718 ./prep_dataset/ILSVRC2012_val_00036329.bin 224 224 +25719 ./prep_dataset/ILSVRC2012_val_00021440.bin 224 224 +25720 ./prep_dataset/ILSVRC2012_val_00027177.bin 224 224 +25721 ./prep_dataset/ILSVRC2012_val_00031710.bin 224 224 +25722 ./prep_dataset/ILSVRC2012_val_00046720.bin 224 224 +25723 ./prep_dataset/ILSVRC2012_val_00001627.bin 224 224 +25724 ./prep_dataset/ILSVRC2012_val_00006509.bin 224 224 +25725 ./prep_dataset/ILSVRC2012_val_00032810.bin 224 224 +25726 ./prep_dataset/ILSVRC2012_val_00046890.bin 224 224 +25727 ./prep_dataset/ILSVRC2012_val_00023063.bin 224 224 +25728 ./prep_dataset/ILSVRC2012_val_00031097.bin 224 224 +25729 ./prep_dataset/ILSVRC2012_val_00014923.bin 224 224 +25730 ./prep_dataset/ILSVRC2012_val_00001920.bin 224 224 +25731 ./prep_dataset/ILSVRC2012_val_00013115.bin 224 224 +25732 ./prep_dataset/ILSVRC2012_val_00011419.bin 224 224 +25733 ./prep_dataset/ILSVRC2012_val_00036600.bin 224 224 +25734 ./prep_dataset/ILSVRC2012_val_00032309.bin 224 224 +25735 ./prep_dataset/ILSVRC2012_val_00023711.bin 224 224 +25736 ./prep_dataset/ILSVRC2012_val_00037699.bin 224 224 +25737 ./prep_dataset/ILSVRC2012_val_00033387.bin 224 224 +25738 ./prep_dataset/ILSVRC2012_val_00029706.bin 224 224 +25739 ./prep_dataset/ILSVRC2012_val_00023266.bin 224 224 +25740 ./prep_dataset/ILSVRC2012_val_00032192.bin 224 224 +25741 ./prep_dataset/ILSVRC2012_val_00038251.bin 224 224 +25742 ./prep_dataset/ILSVRC2012_val_00034909.bin 224 224 +25743 ./prep_dataset/ILSVRC2012_val_00031608.bin 224 224 +25744 ./prep_dataset/ILSVRC2012_val_00032397.bin 224 224 +25745 ./prep_dataset/ILSVRC2012_val_00006479.bin 224 224 +25746 ./prep_dataset/ILSVRC2012_val_00016629.bin 224 224 +25747 ./prep_dataset/ILSVRC2012_val_00037857.bin 224 224 +25748 ./prep_dataset/ILSVRC2012_val_00015737.bin 224 224 +25749 ./prep_dataset/ILSVRC2012_val_00017359.bin 224 224 +25750 ./prep_dataset/ILSVRC2012_val_00011584.bin 224 224 +25751 ./prep_dataset/ILSVRC2012_val_00025819.bin 224 224 +25752 ./prep_dataset/ILSVRC2012_val_00038203.bin 224 224 +25753 ./prep_dataset/ILSVRC2012_val_00038514.bin 224 224 +25754 ./prep_dataset/ILSVRC2012_val_00028168.bin 224 224 +25755 ./prep_dataset/ILSVRC2012_val_00048074.bin 224 224 +25756 ./prep_dataset/ILSVRC2012_val_00018517.bin 224 224 +25757 ./prep_dataset/ILSVRC2012_val_00036444.bin 224 224 +25758 ./prep_dataset/ILSVRC2012_val_00001941.bin 224 224 +25759 ./prep_dataset/ILSVRC2012_val_00010753.bin 224 224 +25760 ./prep_dataset/ILSVRC2012_val_00045432.bin 224 224 +25761 ./prep_dataset/ILSVRC2012_val_00025646.bin 224 224 +25762 ./prep_dataset/ILSVRC2012_val_00016666.bin 224 224 +25763 ./prep_dataset/ILSVRC2012_val_00029814.bin 224 224 +25764 ./prep_dataset/ILSVRC2012_val_00030120.bin 224 224 +25765 ./prep_dataset/ILSVRC2012_val_00017794.bin 224 224 +25766 ./prep_dataset/ILSVRC2012_val_00040608.bin 224 224 +25767 ./prep_dataset/ILSVRC2012_val_00038567.bin 224 224 +25768 ./prep_dataset/ILSVRC2012_val_00042776.bin 224 224 +25769 ./prep_dataset/ILSVRC2012_val_00009056.bin 224 224 +25770 ./prep_dataset/ILSVRC2012_val_00012730.bin 224 224 +25771 ./prep_dataset/ILSVRC2012_val_00000838.bin 224 224 +25772 ./prep_dataset/ILSVRC2012_val_00042288.bin 224 224 +25773 ./prep_dataset/ILSVRC2012_val_00047068.bin 224 224 +25774 ./prep_dataset/ILSVRC2012_val_00012741.bin 224 224 +25775 ./prep_dataset/ILSVRC2012_val_00034592.bin 224 224 +25776 ./prep_dataset/ILSVRC2012_val_00019488.bin 224 224 +25777 ./prep_dataset/ILSVRC2012_val_00039250.bin 224 224 +25778 ./prep_dataset/ILSVRC2012_val_00049453.bin 224 224 +25779 ./prep_dataset/ILSVRC2012_val_00018134.bin 224 224 +25780 ./prep_dataset/ILSVRC2012_val_00020580.bin 224 224 +25781 ./prep_dataset/ILSVRC2012_val_00011428.bin 224 224 +25782 ./prep_dataset/ILSVRC2012_val_00049333.bin 224 224 +25783 ./prep_dataset/ILSVRC2012_val_00004896.bin 224 224 +25784 ./prep_dataset/ILSVRC2012_val_00047305.bin 224 224 +25785 ./prep_dataset/ILSVRC2012_val_00040559.bin 224 224 +25786 ./prep_dataset/ILSVRC2012_val_00034660.bin 224 224 +25787 ./prep_dataset/ILSVRC2012_val_00027123.bin 224 224 +25788 ./prep_dataset/ILSVRC2012_val_00012908.bin 224 224 +25789 ./prep_dataset/ILSVRC2012_val_00011709.bin 224 224 +25790 ./prep_dataset/ILSVRC2012_val_00041706.bin 224 224 +25791 ./prep_dataset/ILSVRC2012_val_00024259.bin 224 224 +25792 ./prep_dataset/ILSVRC2012_val_00037029.bin 224 224 +25793 ./prep_dataset/ILSVRC2012_val_00003472.bin 224 224 +25794 ./prep_dataset/ILSVRC2012_val_00031573.bin 224 224 +25795 ./prep_dataset/ILSVRC2012_val_00042825.bin 224 224 +25796 ./prep_dataset/ILSVRC2012_val_00024810.bin 224 224 +25797 ./prep_dataset/ILSVRC2012_val_00043292.bin 224 224 +25798 ./prep_dataset/ILSVRC2012_val_00048593.bin 224 224 +25799 ./prep_dataset/ILSVRC2012_val_00020550.bin 224 224 +25800 ./prep_dataset/ILSVRC2012_val_00042712.bin 224 224 +25801 ./prep_dataset/ILSVRC2012_val_00023124.bin 224 224 +25802 ./prep_dataset/ILSVRC2012_val_00048380.bin 224 224 +25803 ./prep_dataset/ILSVRC2012_val_00008555.bin 224 224 +25804 ./prep_dataset/ILSVRC2012_val_00020767.bin 224 224 +25805 ./prep_dataset/ILSVRC2012_val_00030179.bin 224 224 +25806 ./prep_dataset/ILSVRC2012_val_00007330.bin 224 224 +25807 ./prep_dataset/ILSVRC2012_val_00020381.bin 224 224 +25808 ./prep_dataset/ILSVRC2012_val_00025156.bin 224 224 +25809 ./prep_dataset/ILSVRC2012_val_00029529.bin 224 224 +25810 ./prep_dataset/ILSVRC2012_val_00028648.bin 224 224 +25811 ./prep_dataset/ILSVRC2012_val_00013541.bin 224 224 +25812 ./prep_dataset/ILSVRC2012_val_00047498.bin 224 224 +25813 ./prep_dataset/ILSVRC2012_val_00017832.bin 224 224 +25814 ./prep_dataset/ILSVRC2012_val_00016701.bin 224 224 +25815 ./prep_dataset/ILSVRC2012_val_00043348.bin 224 224 +25816 ./prep_dataset/ILSVRC2012_val_00019212.bin 224 224 +25817 ./prep_dataset/ILSVRC2012_val_00020095.bin 224 224 +25818 ./prep_dataset/ILSVRC2012_val_00011955.bin 224 224 +25819 ./prep_dataset/ILSVRC2012_val_00047331.bin 224 224 +25820 ./prep_dataset/ILSVRC2012_val_00011576.bin 224 224 +25821 ./prep_dataset/ILSVRC2012_val_00042937.bin 224 224 +25822 ./prep_dataset/ILSVRC2012_val_00034063.bin 224 224 +25823 ./prep_dataset/ILSVRC2012_val_00044967.bin 224 224 +25824 ./prep_dataset/ILSVRC2012_val_00038199.bin 224 224 +25825 ./prep_dataset/ILSVRC2012_val_00045541.bin 224 224 +25826 ./prep_dataset/ILSVRC2012_val_00004572.bin 224 224 +25827 ./prep_dataset/ILSVRC2012_val_00015785.bin 224 224 +25828 ./prep_dataset/ILSVRC2012_val_00023431.bin 224 224 +25829 ./prep_dataset/ILSVRC2012_val_00018932.bin 224 224 +25830 ./prep_dataset/ILSVRC2012_val_00022484.bin 224 224 +25831 ./prep_dataset/ILSVRC2012_val_00021839.bin 224 224 +25832 ./prep_dataset/ILSVRC2012_val_00033307.bin 224 224 +25833 ./prep_dataset/ILSVRC2012_val_00000905.bin 224 224 +25834 ./prep_dataset/ILSVRC2012_val_00033017.bin 224 224 +25835 ./prep_dataset/ILSVRC2012_val_00036694.bin 224 224 +25836 ./prep_dataset/ILSVRC2012_val_00021031.bin 224 224 +25837 ./prep_dataset/ILSVRC2012_val_00047461.bin 224 224 +25838 ./prep_dataset/ILSVRC2012_val_00027732.bin 224 224 +25839 ./prep_dataset/ILSVRC2012_val_00036193.bin 224 224 +25840 ./prep_dataset/ILSVRC2012_val_00048284.bin 224 224 +25841 ./prep_dataset/ILSVRC2012_val_00022571.bin 224 224 +25842 ./prep_dataset/ILSVRC2012_val_00002201.bin 224 224 +25843 ./prep_dataset/ILSVRC2012_val_00016575.bin 224 224 +25844 ./prep_dataset/ILSVRC2012_val_00006371.bin 224 224 +25845 ./prep_dataset/ILSVRC2012_val_00045431.bin 224 224 +25846 ./prep_dataset/ILSVRC2012_val_00027198.bin 224 224 +25847 ./prep_dataset/ILSVRC2012_val_00047123.bin 224 224 +25848 ./prep_dataset/ILSVRC2012_val_00004464.bin 224 224 +25849 ./prep_dataset/ILSVRC2012_val_00030769.bin 224 224 +25850 ./prep_dataset/ILSVRC2012_val_00036613.bin 224 224 +25851 ./prep_dataset/ILSVRC2012_val_00025621.bin 224 224 +25852 ./prep_dataset/ILSVRC2012_val_00005527.bin 224 224 +25853 ./prep_dataset/ILSVRC2012_val_00007065.bin 224 224 +25854 ./prep_dataset/ILSVRC2012_val_00040275.bin 224 224 +25855 ./prep_dataset/ILSVRC2012_val_00010849.bin 224 224 +25856 ./prep_dataset/ILSVRC2012_val_00016267.bin 224 224 +25857 ./prep_dataset/ILSVRC2012_val_00005767.bin 224 224 +25858 ./prep_dataset/ILSVRC2012_val_00020508.bin 224 224 +25859 ./prep_dataset/ILSVRC2012_val_00002263.bin 224 224 +25860 ./prep_dataset/ILSVRC2012_val_00026155.bin 224 224 +25861 ./prep_dataset/ILSVRC2012_val_00008398.bin 224 224 +25862 ./prep_dataset/ILSVRC2012_val_00034774.bin 224 224 +25863 ./prep_dataset/ILSVRC2012_val_00003452.bin 224 224 +25864 ./prep_dataset/ILSVRC2012_val_00027197.bin 224 224 +25865 ./prep_dataset/ILSVRC2012_val_00041331.bin 224 224 +25866 ./prep_dataset/ILSVRC2012_val_00034040.bin 224 224 +25867 ./prep_dataset/ILSVRC2012_val_00027464.bin 224 224 +25868 ./prep_dataset/ILSVRC2012_val_00007209.bin 224 224 +25869 ./prep_dataset/ILSVRC2012_val_00036537.bin 224 224 +25870 ./prep_dataset/ILSVRC2012_val_00023181.bin 224 224 +25871 ./prep_dataset/ILSVRC2012_val_00031737.bin 224 224 +25872 ./prep_dataset/ILSVRC2012_val_00026359.bin 224 224 +25873 ./prep_dataset/ILSVRC2012_val_00016363.bin 224 224 +25874 ./prep_dataset/ILSVRC2012_val_00049804.bin 224 224 +25875 ./prep_dataset/ILSVRC2012_val_00035807.bin 224 224 +25876 ./prep_dataset/ILSVRC2012_val_00042869.bin 224 224 +25877 ./prep_dataset/ILSVRC2012_val_00043066.bin 224 224 +25878 ./prep_dataset/ILSVRC2012_val_00028746.bin 224 224 +25879 ./prep_dataset/ILSVRC2012_val_00000996.bin 224 224 +25880 ./prep_dataset/ILSVRC2012_val_00027425.bin 224 224 +25881 ./prep_dataset/ILSVRC2012_val_00036015.bin 224 224 +25882 ./prep_dataset/ILSVRC2012_val_00042941.bin 224 224 +25883 ./prep_dataset/ILSVRC2012_val_00042493.bin 224 224 +25884 ./prep_dataset/ILSVRC2012_val_00002769.bin 224 224 +25885 ./prep_dataset/ILSVRC2012_val_00007088.bin 224 224 +25886 ./prep_dataset/ILSVRC2012_val_00002653.bin 224 224 +25887 ./prep_dataset/ILSVRC2012_val_00031428.bin 224 224 +25888 ./prep_dataset/ILSVRC2012_val_00044073.bin 224 224 +25889 ./prep_dataset/ILSVRC2012_val_00043431.bin 224 224 +25890 ./prep_dataset/ILSVRC2012_val_00014041.bin 224 224 +25891 ./prep_dataset/ILSVRC2012_val_00014642.bin 224 224 +25892 ./prep_dataset/ILSVRC2012_val_00009605.bin 224 224 +25893 ./prep_dataset/ILSVRC2012_val_00023282.bin 224 224 +25894 ./prep_dataset/ILSVRC2012_val_00019675.bin 224 224 +25895 ./prep_dataset/ILSVRC2012_val_00043615.bin 224 224 +25896 ./prep_dataset/ILSVRC2012_val_00042365.bin 224 224 +25897 ./prep_dataset/ILSVRC2012_val_00002923.bin 224 224 +25898 ./prep_dataset/ILSVRC2012_val_00041655.bin 224 224 +25899 ./prep_dataset/ILSVRC2012_val_00048874.bin 224 224 +25900 ./prep_dataset/ILSVRC2012_val_00023860.bin 224 224 +25901 ./prep_dataset/ILSVRC2012_val_00032244.bin 224 224 +25902 ./prep_dataset/ILSVRC2012_val_00033035.bin 224 224 +25903 ./prep_dataset/ILSVRC2012_val_00047470.bin 224 224 +25904 ./prep_dataset/ILSVRC2012_val_00017708.bin 224 224 +25905 ./prep_dataset/ILSVRC2012_val_00007956.bin 224 224 +25906 ./prep_dataset/ILSVRC2012_val_00041905.bin 224 224 +25907 ./prep_dataset/ILSVRC2012_val_00015317.bin 224 224 +25908 ./prep_dataset/ILSVRC2012_val_00004331.bin 224 224 +25909 ./prep_dataset/ILSVRC2012_val_00028057.bin 224 224 +25910 ./prep_dataset/ILSVRC2012_val_00024417.bin 224 224 +25911 ./prep_dataset/ILSVRC2012_val_00035026.bin 224 224 +25912 ./prep_dataset/ILSVRC2012_val_00006696.bin 224 224 +25913 ./prep_dataset/ILSVRC2012_val_00003405.bin 224 224 +25914 ./prep_dataset/ILSVRC2012_val_00006902.bin 224 224 +25915 ./prep_dataset/ILSVRC2012_val_00038573.bin 224 224 +25916 ./prep_dataset/ILSVRC2012_val_00038409.bin 224 224 +25917 ./prep_dataset/ILSVRC2012_val_00006712.bin 224 224 +25918 ./prep_dataset/ILSVRC2012_val_00048160.bin 224 224 +25919 ./prep_dataset/ILSVRC2012_val_00047337.bin 224 224 +25920 ./prep_dataset/ILSVRC2012_val_00021721.bin 224 224 +25921 ./prep_dataset/ILSVRC2012_val_00027938.bin 224 224 +25922 ./prep_dataset/ILSVRC2012_val_00029026.bin 224 224 +25923 ./prep_dataset/ILSVRC2012_val_00014313.bin 224 224 +25924 ./prep_dataset/ILSVRC2012_val_00015360.bin 224 224 +25925 ./prep_dataset/ILSVRC2012_val_00014534.bin 224 224 +25926 ./prep_dataset/ILSVRC2012_val_00043450.bin 224 224 +25927 ./prep_dataset/ILSVRC2012_val_00023193.bin 224 224 +25928 ./prep_dataset/ILSVRC2012_val_00002141.bin 224 224 +25929 ./prep_dataset/ILSVRC2012_val_00034704.bin 224 224 +25930 ./prep_dataset/ILSVRC2012_val_00016114.bin 224 224 +25931 ./prep_dataset/ILSVRC2012_val_00021208.bin 224 224 +25932 ./prep_dataset/ILSVRC2012_val_00034280.bin 224 224 +25933 ./prep_dataset/ILSVRC2012_val_00030613.bin 224 224 +25934 ./prep_dataset/ILSVRC2012_val_00000998.bin 224 224 +25935 ./prep_dataset/ILSVRC2012_val_00012236.bin 224 224 +25936 ./prep_dataset/ILSVRC2012_val_00013530.bin 224 224 +25937 ./prep_dataset/ILSVRC2012_val_00031841.bin 224 224 +25938 ./prep_dataset/ILSVRC2012_val_00005541.bin 224 224 +25939 ./prep_dataset/ILSVRC2012_val_00017335.bin 224 224 +25940 ./prep_dataset/ILSVRC2012_val_00005745.bin 224 224 +25941 ./prep_dataset/ILSVRC2012_val_00032693.bin 224 224 +25942 ./prep_dataset/ILSVRC2012_val_00003953.bin 224 224 +25943 ./prep_dataset/ILSVRC2012_val_00049575.bin 224 224 +25944 ./prep_dataset/ILSVRC2012_val_00025821.bin 224 224 +25945 ./prep_dataset/ILSVRC2012_val_00010797.bin 224 224 +25946 ./prep_dataset/ILSVRC2012_val_00047335.bin 224 224 +25947 ./prep_dataset/ILSVRC2012_val_00014638.bin 224 224 +25948 ./prep_dataset/ILSVRC2012_val_00046213.bin 224 224 +25949 ./prep_dataset/ILSVRC2012_val_00046869.bin 224 224 +25950 ./prep_dataset/ILSVRC2012_val_00006886.bin 224 224 +25951 ./prep_dataset/ILSVRC2012_val_00042676.bin 224 224 +25952 ./prep_dataset/ILSVRC2012_val_00020754.bin 224 224 +25953 ./prep_dataset/ILSVRC2012_val_00009714.bin 224 224 +25954 ./prep_dataset/ILSVRC2012_val_00025108.bin 224 224 +25955 ./prep_dataset/ILSVRC2012_val_00024672.bin 224 224 +25956 ./prep_dataset/ILSVRC2012_val_00016542.bin 224 224 +25957 ./prep_dataset/ILSVRC2012_val_00048465.bin 224 224 +25958 ./prep_dataset/ILSVRC2012_val_00001397.bin 224 224 +25959 ./prep_dataset/ILSVRC2012_val_00041128.bin 224 224 +25960 ./prep_dataset/ILSVRC2012_val_00029291.bin 224 224 +25961 ./prep_dataset/ILSVRC2012_val_00030745.bin 224 224 +25962 ./prep_dataset/ILSVRC2012_val_00004543.bin 224 224 +25963 ./prep_dataset/ILSVRC2012_val_00028900.bin 224 224 +25964 ./prep_dataset/ILSVRC2012_val_00000420.bin 224 224 +25965 ./prep_dataset/ILSVRC2012_val_00021326.bin 224 224 +25966 ./prep_dataset/ILSVRC2012_val_00022135.bin 224 224 +25967 ./prep_dataset/ILSVRC2012_val_00041275.bin 224 224 +25968 ./prep_dataset/ILSVRC2012_val_00006778.bin 224 224 +25969 ./prep_dataset/ILSVRC2012_val_00018009.bin 224 224 +25970 ./prep_dataset/ILSVRC2012_val_00021623.bin 224 224 +25971 ./prep_dataset/ILSVRC2012_val_00013879.bin 224 224 +25972 ./prep_dataset/ILSVRC2012_val_00016610.bin 224 224 +25973 ./prep_dataset/ILSVRC2012_val_00025689.bin 224 224 +25974 ./prep_dataset/ILSVRC2012_val_00025042.bin 224 224 +25975 ./prep_dataset/ILSVRC2012_val_00044638.bin 224 224 +25976 ./prep_dataset/ILSVRC2012_val_00007430.bin 224 224 +25977 ./prep_dataset/ILSVRC2012_val_00038442.bin 224 224 +25978 ./prep_dataset/ILSVRC2012_val_00034760.bin 224 224 +25979 ./prep_dataset/ILSVRC2012_val_00045947.bin 224 224 +25980 ./prep_dataset/ILSVRC2012_val_00025954.bin 224 224 +25981 ./prep_dataset/ILSVRC2012_val_00021242.bin 224 224 +25982 ./prep_dataset/ILSVRC2012_val_00016763.bin 224 224 +25983 ./prep_dataset/ILSVRC2012_val_00005373.bin 224 224 +25984 ./prep_dataset/ILSVRC2012_val_00005193.bin 224 224 +25985 ./prep_dataset/ILSVRC2012_val_00047349.bin 224 224 +25986 ./prep_dataset/ILSVRC2012_val_00022729.bin 224 224 +25987 ./prep_dataset/ILSVRC2012_val_00023308.bin 224 224 +25988 ./prep_dataset/ILSVRC2012_val_00039707.bin 224 224 +25989 ./prep_dataset/ILSVRC2012_val_00028611.bin 224 224 +25990 ./prep_dataset/ILSVRC2012_val_00004638.bin 224 224 +25991 ./prep_dataset/ILSVRC2012_val_00031041.bin 224 224 +25992 ./prep_dataset/ILSVRC2012_val_00044763.bin 224 224 +25993 ./prep_dataset/ILSVRC2012_val_00022897.bin 224 224 +25994 ./prep_dataset/ILSVRC2012_val_00015989.bin 224 224 +25995 ./prep_dataset/ILSVRC2012_val_00035600.bin 224 224 +25996 ./prep_dataset/ILSVRC2012_val_00032897.bin 224 224 +25997 ./prep_dataset/ILSVRC2012_val_00016129.bin 224 224 +25998 ./prep_dataset/ILSVRC2012_val_00021375.bin 224 224 +25999 ./prep_dataset/ILSVRC2012_val_00025783.bin 224 224 +26000 ./prep_dataset/ILSVRC2012_val_00044703.bin 224 224 +26001 ./prep_dataset/ILSVRC2012_val_00020353.bin 224 224 +26002 ./prep_dataset/ILSVRC2012_val_00019148.bin 224 224 +26003 ./prep_dataset/ILSVRC2012_val_00034787.bin 224 224 +26004 ./prep_dataset/ILSVRC2012_val_00014887.bin 224 224 +26005 ./prep_dataset/ILSVRC2012_val_00008452.bin 224 224 +26006 ./prep_dataset/ILSVRC2012_val_00046474.bin 224 224 +26007 ./prep_dataset/ILSVRC2012_val_00023492.bin 224 224 +26008 ./prep_dataset/ILSVRC2012_val_00035033.bin 224 224 +26009 ./prep_dataset/ILSVRC2012_val_00032588.bin 224 224 +26010 ./prep_dataset/ILSVRC2012_val_00009063.bin 224 224 +26011 ./prep_dataset/ILSVRC2012_val_00016080.bin 224 224 +26012 ./prep_dataset/ILSVRC2012_val_00046732.bin 224 224 +26013 ./prep_dataset/ILSVRC2012_val_00049004.bin 224 224 +26014 ./prep_dataset/ILSVRC2012_val_00005878.bin 224 224 +26015 ./prep_dataset/ILSVRC2012_val_00038991.bin 224 224 +26016 ./prep_dataset/ILSVRC2012_val_00032828.bin 224 224 +26017 ./prep_dataset/ILSVRC2012_val_00023257.bin 224 224 +26018 ./prep_dataset/ILSVRC2012_val_00032709.bin 224 224 +26019 ./prep_dataset/ILSVRC2012_val_00035577.bin 224 224 +26020 ./prep_dataset/ILSVRC2012_val_00012568.bin 224 224 +26021 ./prep_dataset/ILSVRC2012_val_00011833.bin 224 224 +26022 ./prep_dataset/ILSVRC2012_val_00021555.bin 224 224 +26023 ./prep_dataset/ILSVRC2012_val_00021628.bin 224 224 +26024 ./prep_dataset/ILSVRC2012_val_00040740.bin 224 224 +26025 ./prep_dataset/ILSVRC2012_val_00016246.bin 224 224 +26026 ./prep_dataset/ILSVRC2012_val_00037618.bin 224 224 +26027 ./prep_dataset/ILSVRC2012_val_00030626.bin 224 224 +26028 ./prep_dataset/ILSVRC2012_val_00023116.bin 224 224 +26029 ./prep_dataset/ILSVRC2012_val_00020523.bin 224 224 +26030 ./prep_dataset/ILSVRC2012_val_00015293.bin 224 224 +26031 ./prep_dataset/ILSVRC2012_val_00004069.bin 224 224 +26032 ./prep_dataset/ILSVRC2012_val_00004641.bin 224 224 +26033 ./prep_dataset/ILSVRC2012_val_00025536.bin 224 224 +26034 ./prep_dataset/ILSVRC2012_val_00039253.bin 224 224 +26035 ./prep_dataset/ILSVRC2012_val_00015689.bin 224 224 +26036 ./prep_dataset/ILSVRC2012_val_00022963.bin 224 224 +26037 ./prep_dataset/ILSVRC2012_val_00005304.bin 224 224 +26038 ./prep_dataset/ILSVRC2012_val_00018280.bin 224 224 +26039 ./prep_dataset/ILSVRC2012_val_00001361.bin 224 224 +26040 ./prep_dataset/ILSVRC2012_val_00031995.bin 224 224 +26041 ./prep_dataset/ILSVRC2012_val_00006569.bin 224 224 +26042 ./prep_dataset/ILSVRC2012_val_00009506.bin 224 224 +26043 ./prep_dataset/ILSVRC2012_val_00016416.bin 224 224 +26044 ./prep_dataset/ILSVRC2012_val_00001432.bin 224 224 +26045 ./prep_dataset/ILSVRC2012_val_00024614.bin 224 224 +26046 ./prep_dataset/ILSVRC2012_val_00021171.bin 224 224 +26047 ./prep_dataset/ILSVRC2012_val_00044255.bin 224 224 +26048 ./prep_dataset/ILSVRC2012_val_00012630.bin 224 224 +26049 ./prep_dataset/ILSVRC2012_val_00018428.bin 224 224 +26050 ./prep_dataset/ILSVRC2012_val_00034180.bin 224 224 +26051 ./prep_dataset/ILSVRC2012_val_00031912.bin 224 224 +26052 ./prep_dataset/ILSVRC2012_val_00033883.bin 224 224 +26053 ./prep_dataset/ILSVRC2012_val_00008422.bin 224 224 +26054 ./prep_dataset/ILSVRC2012_val_00004849.bin 224 224 +26055 ./prep_dataset/ILSVRC2012_val_00001600.bin 224 224 +26056 ./prep_dataset/ILSVRC2012_val_00044629.bin 224 224 +26057 ./prep_dataset/ILSVRC2012_val_00006909.bin 224 224 +26058 ./prep_dataset/ILSVRC2012_val_00036343.bin 224 224 +26059 ./prep_dataset/ILSVRC2012_val_00004593.bin 224 224 +26060 ./prep_dataset/ILSVRC2012_val_00016717.bin 224 224 +26061 ./prep_dataset/ILSVRC2012_val_00006652.bin 224 224 +26062 ./prep_dataset/ILSVRC2012_val_00029239.bin 224 224 +26063 ./prep_dataset/ILSVRC2012_val_00021730.bin 224 224 +26064 ./prep_dataset/ILSVRC2012_val_00006904.bin 224 224 +26065 ./prep_dataset/ILSVRC2012_val_00046680.bin 224 224 +26066 ./prep_dataset/ILSVRC2012_val_00016483.bin 224 224 +26067 ./prep_dataset/ILSVRC2012_val_00030889.bin 224 224 +26068 ./prep_dataset/ILSVRC2012_val_00009317.bin 224 224 +26069 ./prep_dataset/ILSVRC2012_val_00012419.bin 224 224 +26070 ./prep_dataset/ILSVRC2012_val_00037517.bin 224 224 +26071 ./prep_dataset/ILSVRC2012_val_00020088.bin 224 224 +26072 ./prep_dataset/ILSVRC2012_val_00044715.bin 224 224 +26073 ./prep_dataset/ILSVRC2012_val_00030659.bin 224 224 +26074 ./prep_dataset/ILSVRC2012_val_00012786.bin 224 224 +26075 ./prep_dataset/ILSVRC2012_val_00002673.bin 224 224 +26076 ./prep_dataset/ILSVRC2012_val_00005598.bin 224 224 +26077 ./prep_dataset/ILSVRC2012_val_00031848.bin 224 224 +26078 ./prep_dataset/ILSVRC2012_val_00005445.bin 224 224 +26079 ./prep_dataset/ILSVRC2012_val_00033731.bin 224 224 +26080 ./prep_dataset/ILSVRC2012_val_00036367.bin 224 224 +26081 ./prep_dataset/ILSVRC2012_val_00031879.bin 224 224 +26082 ./prep_dataset/ILSVRC2012_val_00002559.bin 224 224 +26083 ./prep_dataset/ILSVRC2012_val_00007061.bin 224 224 +26084 ./prep_dataset/ILSVRC2012_val_00033521.bin 224 224 +26085 ./prep_dataset/ILSVRC2012_val_00039703.bin 224 224 +26086 ./prep_dataset/ILSVRC2012_val_00028364.bin 224 224 +26087 ./prep_dataset/ILSVRC2012_val_00036393.bin 224 224 +26088 ./prep_dataset/ILSVRC2012_val_00004224.bin 224 224 +26089 ./prep_dataset/ILSVRC2012_val_00015149.bin 224 224 +26090 ./prep_dataset/ILSVRC2012_val_00049281.bin 224 224 +26091 ./prep_dataset/ILSVRC2012_val_00048345.bin 224 224 +26092 ./prep_dataset/ILSVRC2012_val_00024090.bin 224 224 +26093 ./prep_dataset/ILSVRC2012_val_00039568.bin 224 224 +26094 ./prep_dataset/ILSVRC2012_val_00049200.bin 224 224 +26095 ./prep_dataset/ILSVRC2012_val_00023463.bin 224 224 +26096 ./prep_dataset/ILSVRC2012_val_00006412.bin 224 224 +26097 ./prep_dataset/ILSVRC2012_val_00039009.bin 224 224 +26098 ./prep_dataset/ILSVRC2012_val_00017971.bin 224 224 +26099 ./prep_dataset/ILSVRC2012_val_00020110.bin 224 224 +26100 ./prep_dataset/ILSVRC2012_val_00000351.bin 224 224 +26101 ./prep_dataset/ILSVRC2012_val_00049153.bin 224 224 +26102 ./prep_dataset/ILSVRC2012_val_00010372.bin 224 224 +26103 ./prep_dataset/ILSVRC2012_val_00025784.bin 224 224 +26104 ./prep_dataset/ILSVRC2012_val_00024219.bin 224 224 +26105 ./prep_dataset/ILSVRC2012_val_00048674.bin 224 224 +26106 ./prep_dataset/ILSVRC2012_val_00038407.bin 224 224 +26107 ./prep_dataset/ILSVRC2012_val_00033861.bin 224 224 +26108 ./prep_dataset/ILSVRC2012_val_00007732.bin 224 224 +26109 ./prep_dataset/ILSVRC2012_val_00039880.bin 224 224 +26110 ./prep_dataset/ILSVRC2012_val_00017021.bin 224 224 +26111 ./prep_dataset/ILSVRC2012_val_00041726.bin 224 224 +26112 ./prep_dataset/ILSVRC2012_val_00030763.bin 224 224 +26113 ./prep_dataset/ILSVRC2012_val_00029347.bin 224 224 +26114 ./prep_dataset/ILSVRC2012_val_00007642.bin 224 224 +26115 ./prep_dataset/ILSVRC2012_val_00025647.bin 224 224 +26116 ./prep_dataset/ILSVRC2012_val_00016903.bin 224 224 +26117 ./prep_dataset/ILSVRC2012_val_00033876.bin 224 224 +26118 ./prep_dataset/ILSVRC2012_val_00033373.bin 224 224 +26119 ./prep_dataset/ILSVRC2012_val_00031721.bin 224 224 +26120 ./prep_dataset/ILSVRC2012_val_00019894.bin 224 224 +26121 ./prep_dataset/ILSVRC2012_val_00012040.bin 224 224 +26122 ./prep_dataset/ILSVRC2012_val_00015609.bin 224 224 +26123 ./prep_dataset/ILSVRC2012_val_00026389.bin 224 224 +26124 ./prep_dataset/ILSVRC2012_val_00030183.bin 224 224 +26125 ./prep_dataset/ILSVRC2012_val_00034839.bin 224 224 +26126 ./prep_dataset/ILSVRC2012_val_00035484.bin 224 224 +26127 ./prep_dataset/ILSVRC2012_val_00035857.bin 224 224 +26128 ./prep_dataset/ILSVRC2012_val_00018863.bin 224 224 +26129 ./prep_dataset/ILSVRC2012_val_00021105.bin 224 224 +26130 ./prep_dataset/ILSVRC2012_val_00010679.bin 224 224 +26131 ./prep_dataset/ILSVRC2012_val_00016964.bin 224 224 +26132 ./prep_dataset/ILSVRC2012_val_00001401.bin 224 224 +26133 ./prep_dataset/ILSVRC2012_val_00010187.bin 224 224 +26134 ./prep_dataset/ILSVRC2012_val_00010715.bin 224 224 +26135 ./prep_dataset/ILSVRC2012_val_00001797.bin 224 224 +26136 ./prep_dataset/ILSVRC2012_val_00024051.bin 224 224 +26137 ./prep_dataset/ILSVRC2012_val_00034444.bin 224 224 +26138 ./prep_dataset/ILSVRC2012_val_00021797.bin 224 224 +26139 ./prep_dataset/ILSVRC2012_val_00044956.bin 224 224 +26140 ./prep_dataset/ILSVRC2012_val_00003935.bin 224 224 +26141 ./prep_dataset/ILSVRC2012_val_00027443.bin 224 224 +26142 ./prep_dataset/ILSVRC2012_val_00022241.bin 224 224 +26143 ./prep_dataset/ILSVRC2012_val_00041415.bin 224 224 +26144 ./prep_dataset/ILSVRC2012_val_00016478.bin 224 224 +26145 ./prep_dataset/ILSVRC2012_val_00001240.bin 224 224 +26146 ./prep_dataset/ILSVRC2012_val_00001618.bin 224 224 +26147 ./prep_dataset/ILSVRC2012_val_00004025.bin 224 224 +26148 ./prep_dataset/ILSVRC2012_val_00040218.bin 224 224 +26149 ./prep_dataset/ILSVRC2012_val_00031845.bin 224 224 +26150 ./prep_dataset/ILSVRC2012_val_00028227.bin 224 224 +26151 ./prep_dataset/ILSVRC2012_val_00019279.bin 224 224 +26152 ./prep_dataset/ILSVRC2012_val_00021022.bin 224 224 +26153 ./prep_dataset/ILSVRC2012_val_00035636.bin 224 224 +26154 ./prep_dataset/ILSVRC2012_val_00001185.bin 224 224 +26155 ./prep_dataset/ILSVRC2012_val_00042459.bin 224 224 +26156 ./prep_dataset/ILSVRC2012_val_00024044.bin 224 224 +26157 ./prep_dataset/ILSVRC2012_val_00048885.bin 224 224 +26158 ./prep_dataset/ILSVRC2012_val_00006948.bin 224 224 +26159 ./prep_dataset/ILSVRC2012_val_00046485.bin 224 224 +26160 ./prep_dataset/ILSVRC2012_val_00025892.bin 224 224 +26161 ./prep_dataset/ILSVRC2012_val_00029875.bin 224 224 +26162 ./prep_dataset/ILSVRC2012_val_00016300.bin 224 224 +26163 ./prep_dataset/ILSVRC2012_val_00048417.bin 224 224 +26164 ./prep_dataset/ILSVRC2012_val_00001018.bin 224 224 +26165 ./prep_dataset/ILSVRC2012_val_00023118.bin 224 224 +26166 ./prep_dataset/ILSVRC2012_val_00009072.bin 224 224 +26167 ./prep_dataset/ILSVRC2012_val_00031601.bin 224 224 +26168 ./prep_dataset/ILSVRC2012_val_00046487.bin 224 224 +26169 ./prep_dataset/ILSVRC2012_val_00031145.bin 224 224 +26170 ./prep_dataset/ILSVRC2012_val_00025624.bin 224 224 +26171 ./prep_dataset/ILSVRC2012_val_00033550.bin 224 224 +26172 ./prep_dataset/ILSVRC2012_val_00042750.bin 224 224 +26173 ./prep_dataset/ILSVRC2012_val_00038558.bin 224 224 +26174 ./prep_dataset/ILSVRC2012_val_00024138.bin 224 224 +26175 ./prep_dataset/ILSVRC2012_val_00023300.bin 224 224 +26176 ./prep_dataset/ILSVRC2012_val_00048750.bin 224 224 +26177 ./prep_dataset/ILSVRC2012_val_00038139.bin 224 224 +26178 ./prep_dataset/ILSVRC2012_val_00029306.bin 224 224 +26179 ./prep_dataset/ILSVRC2012_val_00035303.bin 224 224 +26180 ./prep_dataset/ILSVRC2012_val_00012086.bin 224 224 +26181 ./prep_dataset/ILSVRC2012_val_00021480.bin 224 224 +26182 ./prep_dataset/ILSVRC2012_val_00049665.bin 224 224 +26183 ./prep_dataset/ILSVRC2012_val_00026845.bin 224 224 +26184 ./prep_dataset/ILSVRC2012_val_00002386.bin 224 224 +26185 ./prep_dataset/ILSVRC2012_val_00023125.bin 224 224 +26186 ./prep_dataset/ILSVRC2012_val_00021518.bin 224 224 +26187 ./prep_dataset/ILSVRC2012_val_00011704.bin 224 224 +26188 ./prep_dataset/ILSVRC2012_val_00025786.bin 224 224 +26189 ./prep_dataset/ILSVRC2012_val_00038719.bin 224 224 +26190 ./prep_dataset/ILSVRC2012_val_00015318.bin 224 224 +26191 ./prep_dataset/ILSVRC2012_val_00021564.bin 224 224 +26192 ./prep_dataset/ILSVRC2012_val_00045426.bin 224 224 +26193 ./prep_dataset/ILSVRC2012_val_00049936.bin 224 224 +26194 ./prep_dataset/ILSVRC2012_val_00029761.bin 224 224 +26195 ./prep_dataset/ILSVRC2012_val_00020803.bin 224 224 +26196 ./prep_dataset/ILSVRC2012_val_00005902.bin 224 224 +26197 ./prep_dataset/ILSVRC2012_val_00018873.bin 224 224 +26198 ./prep_dataset/ILSVRC2012_val_00025791.bin 224 224 +26199 ./prep_dataset/ILSVRC2012_val_00004376.bin 224 224 +26200 ./prep_dataset/ILSVRC2012_val_00012423.bin 224 224 +26201 ./prep_dataset/ILSVRC2012_val_00027553.bin 224 224 +26202 ./prep_dataset/ILSVRC2012_val_00006846.bin 224 224 +26203 ./prep_dataset/ILSVRC2012_val_00032480.bin 224 224 +26204 ./prep_dataset/ILSVRC2012_val_00033151.bin 224 224 +26205 ./prep_dataset/ILSVRC2012_val_00020839.bin 224 224 +26206 ./prep_dataset/ILSVRC2012_val_00049229.bin 224 224 +26207 ./prep_dataset/ILSVRC2012_val_00008145.bin 224 224 +26208 ./prep_dataset/ILSVRC2012_val_00017234.bin 224 224 +26209 ./prep_dataset/ILSVRC2012_val_00011216.bin 224 224 +26210 ./prep_dataset/ILSVRC2012_val_00013368.bin 224 224 +26211 ./prep_dataset/ILSVRC2012_val_00014467.bin 224 224 +26212 ./prep_dataset/ILSVRC2012_val_00025876.bin 224 224 +26213 ./prep_dataset/ILSVRC2012_val_00012641.bin 224 224 +26214 ./prep_dataset/ILSVRC2012_val_00043874.bin 224 224 +26215 ./prep_dataset/ILSVRC2012_val_00036401.bin 224 224 +26216 ./prep_dataset/ILSVRC2012_val_00044053.bin 224 224 +26217 ./prep_dataset/ILSVRC2012_val_00015554.bin 224 224 +26218 ./prep_dataset/ILSVRC2012_val_00035933.bin 224 224 +26219 ./prep_dataset/ILSVRC2012_val_00042843.bin 224 224 +26220 ./prep_dataset/ILSVRC2012_val_00037647.bin 224 224 +26221 ./prep_dataset/ILSVRC2012_val_00048682.bin 224 224 +26222 ./prep_dataset/ILSVRC2012_val_00023935.bin 224 224 +26223 ./prep_dataset/ILSVRC2012_val_00001437.bin 224 224 +26224 ./prep_dataset/ILSVRC2012_val_00009529.bin 224 224 +26225 ./prep_dataset/ILSVRC2012_val_00012963.bin 224 224 +26226 ./prep_dataset/ILSVRC2012_val_00043824.bin 224 224 +26227 ./prep_dataset/ILSVRC2012_val_00046130.bin 224 224 +26228 ./prep_dataset/ILSVRC2012_val_00008911.bin 224 224 +26229 ./prep_dataset/ILSVRC2012_val_00000807.bin 224 224 +26230 ./prep_dataset/ILSVRC2012_val_00027234.bin 224 224 +26231 ./prep_dataset/ILSVRC2012_val_00009718.bin 224 224 +26232 ./prep_dataset/ILSVRC2012_val_00027021.bin 224 224 +26233 ./prep_dataset/ILSVRC2012_val_00003893.bin 224 224 +26234 ./prep_dataset/ILSVRC2012_val_00011524.bin 224 224 +26235 ./prep_dataset/ILSVRC2012_val_00035526.bin 224 224 +26236 ./prep_dataset/ILSVRC2012_val_00038796.bin 224 224 +26237 ./prep_dataset/ILSVRC2012_val_00047019.bin 224 224 +26238 ./prep_dataset/ILSVRC2012_val_00021139.bin 224 224 +26239 ./prep_dataset/ILSVRC2012_val_00016862.bin 224 224 +26240 ./prep_dataset/ILSVRC2012_val_00009414.bin 224 224 +26241 ./prep_dataset/ILSVRC2012_val_00020997.bin 224 224 +26242 ./prep_dataset/ILSVRC2012_val_00002029.bin 224 224 +26243 ./prep_dataset/ILSVRC2012_val_00018227.bin 224 224 +26244 ./prep_dataset/ILSVRC2012_val_00013043.bin 224 224 +26245 ./prep_dataset/ILSVRC2012_val_00041428.bin 224 224 +26246 ./prep_dataset/ILSVRC2012_val_00022134.bin 224 224 +26247 ./prep_dataset/ILSVRC2012_val_00027523.bin 224 224 +26248 ./prep_dataset/ILSVRC2012_val_00019795.bin 224 224 +26249 ./prep_dataset/ILSVRC2012_val_00017559.bin 224 224 +26250 ./prep_dataset/ILSVRC2012_val_00030771.bin 224 224 +26251 ./prep_dataset/ILSVRC2012_val_00011656.bin 224 224 +26252 ./prep_dataset/ILSVRC2012_val_00049155.bin 224 224 +26253 ./prep_dataset/ILSVRC2012_val_00036511.bin 224 224 +26254 ./prep_dataset/ILSVRC2012_val_00030839.bin 224 224 +26255 ./prep_dataset/ILSVRC2012_val_00046027.bin 224 224 +26256 ./prep_dataset/ILSVRC2012_val_00016811.bin 224 224 +26257 ./prep_dataset/ILSVRC2012_val_00039286.bin 224 224 +26258 ./prep_dataset/ILSVRC2012_val_00002676.bin 224 224 +26259 ./prep_dataset/ILSVRC2012_val_00009595.bin 224 224 +26260 ./prep_dataset/ILSVRC2012_val_00010562.bin 224 224 +26261 ./prep_dataset/ILSVRC2012_val_00001315.bin 224 224 +26262 ./prep_dataset/ILSVRC2012_val_00022417.bin 224 224 +26263 ./prep_dataset/ILSVRC2012_val_00039003.bin 224 224 +26264 ./prep_dataset/ILSVRC2012_val_00045235.bin 224 224 +26265 ./prep_dataset/ILSVRC2012_val_00013621.bin 224 224 +26266 ./prep_dataset/ILSVRC2012_val_00035838.bin 224 224 +26267 ./prep_dataset/ILSVRC2012_val_00006012.bin 224 224 +26268 ./prep_dataset/ILSVRC2012_val_00046348.bin 224 224 +26269 ./prep_dataset/ILSVRC2012_val_00007154.bin 224 224 +26270 ./prep_dataset/ILSVRC2012_val_00004544.bin 224 224 +26271 ./prep_dataset/ILSVRC2012_val_00029137.bin 224 224 +26272 ./prep_dataset/ILSVRC2012_val_00036433.bin 224 224 +26273 ./prep_dataset/ILSVRC2012_val_00025449.bin 224 224 +26274 ./prep_dataset/ILSVRC2012_val_00002591.bin 224 224 +26275 ./prep_dataset/ILSVRC2012_val_00036822.bin 224 224 +26276 ./prep_dataset/ILSVRC2012_val_00044094.bin 224 224 +26277 ./prep_dataset/ILSVRC2012_val_00031691.bin 224 224 +26278 ./prep_dataset/ILSVRC2012_val_00049906.bin 224 224 +26279 ./prep_dataset/ILSVRC2012_val_00006567.bin 224 224 +26280 ./prep_dataset/ILSVRC2012_val_00012799.bin 224 224 +26281 ./prep_dataset/ILSVRC2012_val_00014068.bin 224 224 +26282 ./prep_dataset/ILSVRC2012_val_00028077.bin 224 224 +26283 ./prep_dataset/ILSVRC2012_val_00034466.bin 224 224 +26284 ./prep_dataset/ILSVRC2012_val_00037559.bin 224 224 +26285 ./prep_dataset/ILSVRC2012_val_00047873.bin 224 224 +26286 ./prep_dataset/ILSVRC2012_val_00019532.bin 224 224 +26287 ./prep_dataset/ILSVRC2012_val_00042533.bin 224 224 +26288 ./prep_dataset/ILSVRC2012_val_00005412.bin 224 224 +26289 ./prep_dataset/ILSVRC2012_val_00019926.bin 224 224 +26290 ./prep_dataset/ILSVRC2012_val_00044966.bin 224 224 +26291 ./prep_dataset/ILSVRC2012_val_00032060.bin 224 224 +26292 ./prep_dataset/ILSVRC2012_val_00044490.bin 224 224 +26293 ./prep_dataset/ILSVRC2012_val_00048044.bin 224 224 +26294 ./prep_dataset/ILSVRC2012_val_00026996.bin 224 224 +26295 ./prep_dataset/ILSVRC2012_val_00000150.bin 224 224 +26296 ./prep_dataset/ILSVRC2012_val_00013496.bin 224 224 +26297 ./prep_dataset/ILSVRC2012_val_00046050.bin 224 224 +26298 ./prep_dataset/ILSVRC2012_val_00016008.bin 224 224 +26299 ./prep_dataset/ILSVRC2012_val_00002161.bin 224 224 +26300 ./prep_dataset/ILSVRC2012_val_00008646.bin 224 224 +26301 ./prep_dataset/ILSVRC2012_val_00049494.bin 224 224 +26302 ./prep_dataset/ILSVRC2012_val_00028953.bin 224 224 +26303 ./prep_dataset/ILSVRC2012_val_00006290.bin 224 224 +26304 ./prep_dataset/ILSVRC2012_val_00021042.bin 224 224 +26305 ./prep_dataset/ILSVRC2012_val_00027368.bin 224 224 +26306 ./prep_dataset/ILSVRC2012_val_00006304.bin 224 224 +26307 ./prep_dataset/ILSVRC2012_val_00002504.bin 224 224 +26308 ./prep_dataset/ILSVRC2012_val_00035386.bin 224 224 +26309 ./prep_dataset/ILSVRC2012_val_00008206.bin 224 224 +26310 ./prep_dataset/ILSVRC2012_val_00044304.bin 224 224 +26311 ./prep_dataset/ILSVRC2012_val_00039191.bin 224 224 +26312 ./prep_dataset/ILSVRC2012_val_00011661.bin 224 224 +26313 ./prep_dataset/ILSVRC2012_val_00003495.bin 224 224 +26314 ./prep_dataset/ILSVRC2012_val_00049890.bin 224 224 +26315 ./prep_dataset/ILSVRC2012_val_00006305.bin 224 224 +26316 ./prep_dataset/ILSVRC2012_val_00049169.bin 224 224 +26317 ./prep_dataset/ILSVRC2012_val_00023031.bin 224 224 +26318 ./prep_dataset/ILSVRC2012_val_00049770.bin 224 224 +26319 ./prep_dataset/ILSVRC2012_val_00035126.bin 224 224 +26320 ./prep_dataset/ILSVRC2012_val_00044185.bin 224 224 +26321 ./prep_dataset/ILSVRC2012_val_00035595.bin 224 224 +26322 ./prep_dataset/ILSVRC2012_val_00035771.bin 224 224 +26323 ./prep_dataset/ILSVRC2012_val_00028539.bin 224 224 +26324 ./prep_dataset/ILSVRC2012_val_00001094.bin 224 224 +26325 ./prep_dataset/ILSVRC2012_val_00036765.bin 224 224 +26326 ./prep_dataset/ILSVRC2012_val_00023395.bin 224 224 +26327 ./prep_dataset/ILSVRC2012_val_00012895.bin 224 224 +26328 ./prep_dataset/ILSVRC2012_val_00031722.bin 224 224 +26329 ./prep_dataset/ILSVRC2012_val_00003466.bin 224 224 +26330 ./prep_dataset/ILSVRC2012_val_00000542.bin 224 224 +26331 ./prep_dataset/ILSVRC2012_val_00006806.bin 224 224 +26332 ./prep_dataset/ILSVRC2012_val_00040816.bin 224 224 +26333 ./prep_dataset/ILSVRC2012_val_00009372.bin 224 224 +26334 ./prep_dataset/ILSVRC2012_val_00000769.bin 224 224 +26335 ./prep_dataset/ILSVRC2012_val_00025999.bin 224 224 +26336 ./prep_dataset/ILSVRC2012_val_00006343.bin 224 224 +26337 ./prep_dataset/ILSVRC2012_val_00044988.bin 224 224 +26338 ./prep_dataset/ILSVRC2012_val_00048297.bin 224 224 +26339 ./prep_dataset/ILSVRC2012_val_00009193.bin 224 224 +26340 ./prep_dataset/ILSVRC2012_val_00010207.bin 224 224 +26341 ./prep_dataset/ILSVRC2012_val_00006040.bin 224 224 +26342 ./prep_dataset/ILSVRC2012_val_00040226.bin 224 224 +26343 ./prep_dataset/ILSVRC2012_val_00044045.bin 224 224 +26344 ./prep_dataset/ILSVRC2012_val_00036416.bin 224 224 +26345 ./prep_dataset/ILSVRC2012_val_00004746.bin 224 224 +26346 ./prep_dataset/ILSVRC2012_val_00047582.bin 224 224 +26347 ./prep_dataset/ILSVRC2012_val_00049185.bin 224 224 +26348 ./prep_dataset/ILSVRC2012_val_00041774.bin 224 224 +26349 ./prep_dataset/ILSVRC2012_val_00014085.bin 224 224 +26350 ./prep_dataset/ILSVRC2012_val_00049242.bin 224 224 +26351 ./prep_dataset/ILSVRC2012_val_00042866.bin 224 224 +26352 ./prep_dataset/ILSVRC2012_val_00039001.bin 224 224 +26353 ./prep_dataset/ILSVRC2012_val_00048079.bin 224 224 +26354 ./prep_dataset/ILSVRC2012_val_00032690.bin 224 224 +26355 ./prep_dataset/ILSVRC2012_val_00013363.bin 224 224 +26356 ./prep_dataset/ILSVRC2012_val_00037193.bin 224 224 +26357 ./prep_dataset/ILSVRC2012_val_00035540.bin 224 224 +26358 ./prep_dataset/ILSVRC2012_val_00002458.bin 224 224 +26359 ./prep_dataset/ILSVRC2012_val_00039843.bin 224 224 +26360 ./prep_dataset/ILSVRC2012_val_00035516.bin 224 224 +26361 ./prep_dataset/ILSVRC2012_val_00031894.bin 224 224 +26362 ./prep_dataset/ILSVRC2012_val_00031209.bin 224 224 +26363 ./prep_dataset/ILSVRC2012_val_00048294.bin 224 224 +26364 ./prep_dataset/ILSVRC2012_val_00013393.bin 224 224 +26365 ./prep_dataset/ILSVRC2012_val_00010795.bin 224 224 +26366 ./prep_dataset/ILSVRC2012_val_00022588.bin 224 224 +26367 ./prep_dataset/ILSVRC2012_val_00046687.bin 224 224 +26368 ./prep_dataset/ILSVRC2012_val_00014262.bin 224 224 +26369 ./prep_dataset/ILSVRC2012_val_00041027.bin 224 224 +26370 ./prep_dataset/ILSVRC2012_val_00014401.bin 224 224 +26371 ./prep_dataset/ILSVRC2012_val_00031638.bin 224 224 +26372 ./prep_dataset/ILSVRC2012_val_00034119.bin 224 224 +26373 ./prep_dataset/ILSVRC2012_val_00007600.bin 224 224 +26374 ./prep_dataset/ILSVRC2012_val_00039929.bin 224 224 +26375 ./prep_dataset/ILSVRC2012_val_00027616.bin 224 224 +26376 ./prep_dataset/ILSVRC2012_val_00045605.bin 224 224 +26377 ./prep_dataset/ILSVRC2012_val_00028570.bin 224 224 +26378 ./prep_dataset/ILSVRC2012_val_00015526.bin 224 224 +26379 ./prep_dataset/ILSVRC2012_val_00000430.bin 224 224 +26380 ./prep_dataset/ILSVRC2012_val_00026817.bin 224 224 +26381 ./prep_dataset/ILSVRC2012_val_00013063.bin 224 224 +26382 ./prep_dataset/ILSVRC2012_val_00010577.bin 224 224 +26383 ./prep_dataset/ILSVRC2012_val_00046366.bin 224 224 +26384 ./prep_dataset/ILSVRC2012_val_00014910.bin 224 224 +26385 ./prep_dataset/ILSVRC2012_val_00004027.bin 224 224 +26386 ./prep_dataset/ILSVRC2012_val_00002054.bin 224 224 +26387 ./prep_dataset/ILSVRC2012_val_00043746.bin 224 224 +26388 ./prep_dataset/ILSVRC2012_val_00012502.bin 224 224 +26389 ./prep_dataset/ILSVRC2012_val_00040099.bin 224 224 +26390 ./prep_dataset/ILSVRC2012_val_00013330.bin 224 224 +26391 ./prep_dataset/ILSVRC2012_val_00004166.bin 224 224 +26392 ./prep_dataset/ILSVRC2012_val_00013004.bin 224 224 +26393 ./prep_dataset/ILSVRC2012_val_00033153.bin 224 224 +26394 ./prep_dataset/ILSVRC2012_val_00034083.bin 224 224 +26395 ./prep_dataset/ILSVRC2012_val_00009548.bin 224 224 +26396 ./prep_dataset/ILSVRC2012_val_00001725.bin 224 224 +26397 ./prep_dataset/ILSVRC2012_val_00016259.bin 224 224 +26398 ./prep_dataset/ILSVRC2012_val_00019475.bin 224 224 +26399 ./prep_dataset/ILSVRC2012_val_00027724.bin 224 224 +26400 ./prep_dataset/ILSVRC2012_val_00042301.bin 224 224 +26401 ./prep_dataset/ILSVRC2012_val_00019942.bin 224 224 +26402 ./prep_dataset/ILSVRC2012_val_00041210.bin 224 224 +26403 ./prep_dataset/ILSVRC2012_val_00024437.bin 224 224 +26404 ./prep_dataset/ILSVRC2012_val_00039394.bin 224 224 +26405 ./prep_dataset/ILSVRC2012_val_00002478.bin 224 224 +26406 ./prep_dataset/ILSVRC2012_val_00006735.bin 224 224 +26407 ./prep_dataset/ILSVRC2012_val_00012052.bin 224 224 +26408 ./prep_dataset/ILSVRC2012_val_00005474.bin 224 224 +26409 ./prep_dataset/ILSVRC2012_val_00030727.bin 224 224 +26410 ./prep_dataset/ILSVRC2012_val_00042698.bin 224 224 +26411 ./prep_dataset/ILSVRC2012_val_00039866.bin 224 224 +26412 ./prep_dataset/ILSVRC2012_val_00047177.bin 224 224 +26413 ./prep_dataset/ILSVRC2012_val_00043630.bin 224 224 +26414 ./prep_dataset/ILSVRC2012_val_00034794.bin 224 224 +26415 ./prep_dataset/ILSVRC2012_val_00038456.bin 224 224 +26416 ./prep_dataset/ILSVRC2012_val_00025341.bin 224 224 +26417 ./prep_dataset/ILSVRC2012_val_00009919.bin 224 224 +26418 ./prep_dataset/ILSVRC2012_val_00008237.bin 224 224 +26419 ./prep_dataset/ILSVRC2012_val_00004372.bin 224 224 +26420 ./prep_dataset/ILSVRC2012_val_00001331.bin 224 224 +26421 ./prep_dataset/ILSVRC2012_val_00049545.bin 224 224 +26422 ./prep_dataset/ILSVRC2012_val_00039875.bin 224 224 +26423 ./prep_dataset/ILSVRC2012_val_00032586.bin 224 224 +26424 ./prep_dataset/ILSVRC2012_val_00023828.bin 224 224 +26425 ./prep_dataset/ILSVRC2012_val_00010169.bin 224 224 +26426 ./prep_dataset/ILSVRC2012_val_00030735.bin 224 224 +26427 ./prep_dataset/ILSVRC2012_val_00035153.bin 224 224 +26428 ./prep_dataset/ILSVRC2012_val_00038201.bin 224 224 +26429 ./prep_dataset/ILSVRC2012_val_00048202.bin 224 224 +26430 ./prep_dataset/ILSVRC2012_val_00028357.bin 224 224 +26431 ./prep_dataset/ILSVRC2012_val_00008641.bin 224 224 +26432 ./prep_dataset/ILSVRC2012_val_00036407.bin 224 224 +26433 ./prep_dataset/ILSVRC2012_val_00041812.bin 224 224 +26434 ./prep_dataset/ILSVRC2012_val_00045465.bin 224 224 +26435 ./prep_dataset/ILSVRC2012_val_00013491.bin 224 224 +26436 ./prep_dataset/ILSVRC2012_val_00034497.bin 224 224 +26437 ./prep_dataset/ILSVRC2012_val_00026903.bin 224 224 +26438 ./prep_dataset/ILSVRC2012_val_00049778.bin 224 224 +26439 ./prep_dataset/ILSVRC2012_val_00022539.bin 224 224 +26440 ./prep_dataset/ILSVRC2012_val_00001305.bin 224 224 +26441 ./prep_dataset/ILSVRC2012_val_00032233.bin 224 224 +26442 ./prep_dataset/ILSVRC2012_val_00006559.bin 224 224 +26443 ./prep_dataset/ILSVRC2012_val_00027707.bin 224 224 +26444 ./prep_dataset/ILSVRC2012_val_00033332.bin 224 224 +26445 ./prep_dataset/ILSVRC2012_val_00033328.bin 224 224 +26446 ./prep_dataset/ILSVRC2012_val_00028322.bin 224 224 +26447 ./prep_dataset/ILSVRC2012_val_00005900.bin 224 224 +26448 ./prep_dataset/ILSVRC2012_val_00013683.bin 224 224 +26449 ./prep_dataset/ILSVRC2012_val_00036284.bin 224 224 +26450 ./prep_dataset/ILSVRC2012_val_00026768.bin 224 224 +26451 ./prep_dataset/ILSVRC2012_val_00033140.bin 224 224 +26452 ./prep_dataset/ILSVRC2012_val_00022394.bin 224 224 +26453 ./prep_dataset/ILSVRC2012_val_00041937.bin 224 224 +26454 ./prep_dataset/ILSVRC2012_val_00040329.bin 224 224 +26455 ./prep_dataset/ILSVRC2012_val_00040020.bin 224 224 +26456 ./prep_dataset/ILSVRC2012_val_00000263.bin 224 224 +26457 ./prep_dataset/ILSVRC2012_val_00039381.bin 224 224 +26458 ./prep_dataset/ILSVRC2012_val_00003010.bin 224 224 +26459 ./prep_dataset/ILSVRC2012_val_00015975.bin 224 224 +26460 ./prep_dataset/ILSVRC2012_val_00008596.bin 224 224 +26461 ./prep_dataset/ILSVRC2012_val_00038200.bin 224 224 +26462 ./prep_dataset/ILSVRC2012_val_00027801.bin 224 224 +26463 ./prep_dataset/ILSVRC2012_val_00042859.bin 224 224 +26464 ./prep_dataset/ILSVRC2012_val_00033273.bin 224 224 +26465 ./prep_dataset/ILSVRC2012_val_00002223.bin 224 224 +26466 ./prep_dataset/ILSVRC2012_val_00021436.bin 224 224 +26467 ./prep_dataset/ILSVRC2012_val_00043779.bin 224 224 +26468 ./prep_dataset/ILSVRC2012_val_00016173.bin 224 224 +26469 ./prep_dataset/ILSVRC2012_val_00034972.bin 224 224 +26470 ./prep_dataset/ILSVRC2012_val_00038390.bin 224 224 +26471 ./prep_dataset/ILSVRC2012_val_00017744.bin 224 224 +26472 ./prep_dataset/ILSVRC2012_val_00025811.bin 224 224 +26473 ./prep_dataset/ILSVRC2012_val_00016974.bin 224 224 +26474 ./prep_dataset/ILSVRC2012_val_00005671.bin 224 224 +26475 ./prep_dataset/ILSVRC2012_val_00013285.bin 224 224 +26476 ./prep_dataset/ILSVRC2012_val_00032533.bin 224 224 +26477 ./prep_dataset/ILSVRC2012_val_00042511.bin 224 224 +26478 ./prep_dataset/ILSVRC2012_val_00032382.bin 224 224 +26479 ./prep_dataset/ILSVRC2012_val_00015167.bin 224 224 +26480 ./prep_dataset/ILSVRC2012_val_00005899.bin 224 224 +26481 ./prep_dataset/ILSVRC2012_val_00027236.bin 224 224 +26482 ./prep_dataset/ILSVRC2012_val_00020969.bin 224 224 +26483 ./prep_dataset/ILSVRC2012_val_00015578.bin 224 224 +26484 ./prep_dataset/ILSVRC2012_val_00005184.bin 224 224 +26485 ./prep_dataset/ILSVRC2012_val_00006366.bin 224 224 +26486 ./prep_dataset/ILSVRC2012_val_00031369.bin 224 224 +26487 ./prep_dataset/ILSVRC2012_val_00030095.bin 224 224 +26488 ./prep_dataset/ILSVRC2012_val_00013306.bin 224 224 +26489 ./prep_dataset/ILSVRC2012_val_00017244.bin 224 224 +26490 ./prep_dataset/ILSVRC2012_val_00026113.bin 224 224 +26491 ./prep_dataset/ILSVRC2012_val_00036634.bin 224 224 +26492 ./prep_dataset/ILSVRC2012_val_00030625.bin 224 224 +26493 ./prep_dataset/ILSVRC2012_val_00031206.bin 224 224 +26494 ./prep_dataset/ILSVRC2012_val_00029594.bin 224 224 +26495 ./prep_dataset/ILSVRC2012_val_00001656.bin 224 224 +26496 ./prep_dataset/ILSVRC2012_val_00006573.bin 224 224 +26497 ./prep_dataset/ILSVRC2012_val_00039987.bin 224 224 +26498 ./prep_dataset/ILSVRC2012_val_00037670.bin 224 224 +26499 ./prep_dataset/ILSVRC2012_val_00049699.bin 224 224 +26500 ./prep_dataset/ILSVRC2012_val_00039183.bin 224 224 +26501 ./prep_dataset/ILSVRC2012_val_00020150.bin 224 224 +26502 ./prep_dataset/ILSVRC2012_val_00021248.bin 224 224 +26503 ./prep_dataset/ILSVRC2012_val_00017443.bin 224 224 +26504 ./prep_dataset/ILSVRC2012_val_00020977.bin 224 224 +26505 ./prep_dataset/ILSVRC2012_val_00030952.bin 224 224 +26506 ./prep_dataset/ILSVRC2012_val_00014028.bin 224 224 +26507 ./prep_dataset/ILSVRC2012_val_00024927.bin 224 224 +26508 ./prep_dataset/ILSVRC2012_val_00018774.bin 224 224 +26509 ./prep_dataset/ILSVRC2012_val_00008557.bin 224 224 +26510 ./prep_dataset/ILSVRC2012_val_00011110.bin 224 224 +26511 ./prep_dataset/ILSVRC2012_val_00033822.bin 224 224 +26512 ./prep_dataset/ILSVRC2012_val_00043943.bin 224 224 +26513 ./prep_dataset/ILSVRC2012_val_00030916.bin 224 224 +26514 ./prep_dataset/ILSVRC2012_val_00001090.bin 224 224 +26515 ./prep_dataset/ILSVRC2012_val_00035742.bin 224 224 +26516 ./prep_dataset/ILSVRC2012_val_00024911.bin 224 224 +26517 ./prep_dataset/ILSVRC2012_val_00048634.bin 224 224 +26518 ./prep_dataset/ILSVRC2012_val_00040065.bin 224 224 +26519 ./prep_dataset/ILSVRC2012_val_00000659.bin 224 224 +26520 ./prep_dataset/ILSVRC2012_val_00047883.bin 224 224 +26521 ./prep_dataset/ILSVRC2012_val_00009454.bin 224 224 +26522 ./prep_dataset/ILSVRC2012_val_00022051.bin 224 224 +26523 ./prep_dataset/ILSVRC2012_val_00048542.bin 224 224 +26524 ./prep_dataset/ILSVRC2012_val_00007930.bin 224 224 +26525 ./prep_dataset/ILSVRC2012_val_00022819.bin 224 224 +26526 ./prep_dataset/ILSVRC2012_val_00032904.bin 224 224 +26527 ./prep_dataset/ILSVRC2012_val_00020505.bin 224 224 +26528 ./prep_dataset/ILSVRC2012_val_00011042.bin 224 224 +26529 ./prep_dataset/ILSVRC2012_val_00007051.bin 224 224 +26530 ./prep_dataset/ILSVRC2012_val_00016157.bin 224 224 +26531 ./prep_dataset/ILSVRC2012_val_00008949.bin 224 224 +26532 ./prep_dataset/ILSVRC2012_val_00023706.bin 224 224 +26533 ./prep_dataset/ILSVRC2012_val_00028196.bin 224 224 +26534 ./prep_dataset/ILSVRC2012_val_00035093.bin 224 224 +26535 ./prep_dataset/ILSVRC2012_val_00042708.bin 224 224 +26536 ./prep_dataset/ILSVRC2012_val_00002764.bin 224 224 +26537 ./prep_dataset/ILSVRC2012_val_00035351.bin 224 224 +26538 ./prep_dataset/ILSVRC2012_val_00033504.bin 224 224 +26539 ./prep_dataset/ILSVRC2012_val_00042436.bin 224 224 +26540 ./prep_dataset/ILSVRC2012_val_00029019.bin 224 224 +26541 ./prep_dataset/ILSVRC2012_val_00026949.bin 224 224 +26542 ./prep_dataset/ILSVRC2012_val_00004341.bin 224 224 +26543 ./prep_dataset/ILSVRC2012_val_00011060.bin 224 224 +26544 ./prep_dataset/ILSVRC2012_val_00025483.bin 224 224 +26545 ./prep_dataset/ILSVRC2012_val_00000629.bin 224 224 +26546 ./prep_dataset/ILSVRC2012_val_00028749.bin 224 224 +26547 ./prep_dataset/ILSVRC2012_val_00024061.bin 224 224 +26548 ./prep_dataset/ILSVRC2012_val_00041310.bin 224 224 +26549 ./prep_dataset/ILSVRC2012_val_00047341.bin 224 224 +26550 ./prep_dataset/ILSVRC2012_val_00048276.bin 224 224 +26551 ./prep_dataset/ILSVRC2012_val_00000145.bin 224 224 +26552 ./prep_dataset/ILSVRC2012_val_00017697.bin 224 224 +26553 ./prep_dataset/ILSVRC2012_val_00047687.bin 224 224 +26554 ./prep_dataset/ILSVRC2012_val_00046144.bin 224 224 +26555 ./prep_dataset/ILSVRC2012_val_00005433.bin 224 224 +26556 ./prep_dataset/ILSVRC2012_val_00007539.bin 224 224 +26557 ./prep_dataset/ILSVRC2012_val_00041819.bin 224 224 +26558 ./prep_dataset/ILSVRC2012_val_00001526.bin 224 224 +26559 ./prep_dataset/ILSVRC2012_val_00045844.bin 224 224 +26560 ./prep_dataset/ILSVRC2012_val_00000858.bin 224 224 +26561 ./prep_dataset/ILSVRC2012_val_00039069.bin 224 224 +26562 ./prep_dataset/ILSVRC2012_val_00010436.bin 224 224 +26563 ./prep_dataset/ILSVRC2012_val_00043124.bin 224 224 +26564 ./prep_dataset/ILSVRC2012_val_00048257.bin 224 224 +26565 ./prep_dataset/ILSVRC2012_val_00031194.bin 224 224 +26566 ./prep_dataset/ILSVRC2012_val_00044294.bin 224 224 +26567 ./prep_dataset/ILSVRC2012_val_00013376.bin 224 224 +26568 ./prep_dataset/ILSVRC2012_val_00041498.bin 224 224 +26569 ./prep_dataset/ILSVRC2012_val_00034950.bin 224 224 +26570 ./prep_dataset/ILSVRC2012_val_00002061.bin 224 224 +26571 ./prep_dataset/ILSVRC2012_val_00002572.bin 224 224 +26572 ./prep_dataset/ILSVRC2012_val_00008393.bin 224 224 +26573 ./prep_dataset/ILSVRC2012_val_00048358.bin 224 224 +26574 ./prep_dataset/ILSVRC2012_val_00010922.bin 224 224 +26575 ./prep_dataset/ILSVRC2012_val_00040330.bin 224 224 +26576 ./prep_dataset/ILSVRC2012_val_00008009.bin 224 224 +26577 ./prep_dataset/ILSVRC2012_val_00017967.bin 224 224 +26578 ./prep_dataset/ILSVRC2012_val_00002177.bin 224 224 +26579 ./prep_dataset/ILSVRC2012_val_00043085.bin 224 224 +26580 ./prep_dataset/ILSVRC2012_val_00021965.bin 224 224 +26581 ./prep_dataset/ILSVRC2012_val_00027898.bin 224 224 +26582 ./prep_dataset/ILSVRC2012_val_00003506.bin 224 224 +26583 ./prep_dataset/ILSVRC2012_val_00039340.bin 224 224 +26584 ./prep_dataset/ILSVRC2012_val_00030292.bin 224 224 +26585 ./prep_dataset/ILSVRC2012_val_00039016.bin 224 224 +26586 ./prep_dataset/ILSVRC2012_val_00016971.bin 224 224 +26587 ./prep_dataset/ILSVRC2012_val_00030762.bin 224 224 +26588 ./prep_dataset/ILSVRC2012_val_00047920.bin 224 224 +26589 ./prep_dataset/ILSVRC2012_val_00033050.bin 224 224 +26590 ./prep_dataset/ILSVRC2012_val_00016905.bin 224 224 +26591 ./prep_dataset/ILSVRC2012_val_00019346.bin 224 224 +26592 ./prep_dataset/ILSVRC2012_val_00033046.bin 224 224 +26593 ./prep_dataset/ILSVRC2012_val_00011512.bin 224 224 +26594 ./prep_dataset/ILSVRC2012_val_00013746.bin 224 224 +26595 ./prep_dataset/ILSVRC2012_val_00037397.bin 224 224 +26596 ./prep_dataset/ILSVRC2012_val_00011001.bin 224 224 +26597 ./prep_dataset/ILSVRC2012_val_00002332.bin 224 224 +26598 ./prep_dataset/ILSVRC2012_val_00019980.bin 224 224 +26599 ./prep_dataset/ILSVRC2012_val_00004698.bin 224 224 +26600 ./prep_dataset/ILSVRC2012_val_00027225.bin 224 224 +26601 ./prep_dataset/ILSVRC2012_val_00000679.bin 224 224 +26602 ./prep_dataset/ILSVRC2012_val_00019789.bin 224 224 +26603 ./prep_dataset/ILSVRC2012_val_00033135.bin 224 224 +26604 ./prep_dataset/ILSVRC2012_val_00024658.bin 224 224 +26605 ./prep_dataset/ILSVRC2012_val_00030280.bin 224 224 +26606 ./prep_dataset/ILSVRC2012_val_00034081.bin 224 224 +26607 ./prep_dataset/ILSVRC2012_val_00009739.bin 224 224 +26608 ./prep_dataset/ILSVRC2012_val_00038534.bin 224 224 +26609 ./prep_dataset/ILSVRC2012_val_00018564.bin 224 224 +26610 ./prep_dataset/ILSVRC2012_val_00038513.bin 224 224 +26611 ./prep_dataset/ILSVRC2012_val_00043080.bin 224 224 +26612 ./prep_dataset/ILSVRC2012_val_00034615.bin 224 224 +26613 ./prep_dataset/ILSVRC2012_val_00027780.bin 224 224 +26614 ./prep_dataset/ILSVRC2012_val_00001333.bin 224 224 +26615 ./prep_dataset/ILSVRC2012_val_00037520.bin 224 224 +26616 ./prep_dataset/ILSVRC2012_val_00035832.bin 224 224 +26617 ./prep_dataset/ILSVRC2012_val_00026595.bin 224 224 +26618 ./prep_dataset/ILSVRC2012_val_00013128.bin 224 224 +26619 ./prep_dataset/ILSVRC2012_val_00047100.bin 224 224 +26620 ./prep_dataset/ILSVRC2012_val_00037125.bin 224 224 +26621 ./prep_dataset/ILSVRC2012_val_00035964.bin 224 224 +26622 ./prep_dataset/ILSVRC2012_val_00002959.bin 224 224 +26623 ./prep_dataset/ILSVRC2012_val_00039164.bin 224 224 +26624 ./prep_dataset/ILSVRC2012_val_00048042.bin 224 224 +26625 ./prep_dataset/ILSVRC2012_val_00044154.bin 224 224 +26626 ./prep_dataset/ILSVRC2012_val_00009230.bin 224 224 +26627 ./prep_dataset/ILSVRC2012_val_00040538.bin 224 224 +26628 ./prep_dataset/ILSVRC2012_val_00001620.bin 224 224 +26629 ./prep_dataset/ILSVRC2012_val_00020522.bin 224 224 +26630 ./prep_dataset/ILSVRC2012_val_00029373.bin 224 224 +26631 ./prep_dataset/ILSVRC2012_val_00041298.bin 224 224 +26632 ./prep_dataset/ILSVRC2012_val_00015988.bin 224 224 +26633 ./prep_dataset/ILSVRC2012_val_00037605.bin 224 224 +26634 ./prep_dataset/ILSVRC2012_val_00024465.bin 224 224 +26635 ./prep_dataset/ILSVRC2012_val_00045810.bin 224 224 +26636 ./prep_dataset/ILSVRC2012_val_00012817.bin 224 224 +26637 ./prep_dataset/ILSVRC2012_val_00036678.bin 224 224 +26638 ./prep_dataset/ILSVRC2012_val_00028050.bin 224 224 +26639 ./prep_dataset/ILSVRC2012_val_00031926.bin 224 224 +26640 ./prep_dataset/ILSVRC2012_val_00028297.bin 224 224 +26641 ./prep_dataset/ILSVRC2012_val_00029402.bin 224 224 +26642 ./prep_dataset/ILSVRC2012_val_00014652.bin 224 224 +26643 ./prep_dataset/ILSVRC2012_val_00013609.bin 224 224 +26644 ./prep_dataset/ILSVRC2012_val_00048393.bin 224 224 +26645 ./prep_dataset/ILSVRC2012_val_00040243.bin 224 224 +26646 ./prep_dataset/ILSVRC2012_val_00006138.bin 224 224 +26647 ./prep_dataset/ILSVRC2012_val_00038373.bin 224 224 +26648 ./prep_dataset/ILSVRC2012_val_00015606.bin 224 224 +26649 ./prep_dataset/ILSVRC2012_val_00012503.bin 224 224 +26650 ./prep_dataset/ILSVRC2012_val_00043868.bin 224 224 +26651 ./prep_dataset/ILSVRC2012_val_00037715.bin 224 224 +26652 ./prep_dataset/ILSVRC2012_val_00005963.bin 224 224 +26653 ./prep_dataset/ILSVRC2012_val_00020923.bin 224 224 +26654 ./prep_dataset/ILSVRC2012_val_00008777.bin 224 224 +26655 ./prep_dataset/ILSVRC2012_val_00005578.bin 224 224 +26656 ./prep_dataset/ILSVRC2012_val_00018191.bin 224 224 +26657 ./prep_dataset/ILSVRC2012_val_00027271.bin 224 224 +26658 ./prep_dataset/ILSVRC2012_val_00035408.bin 224 224 +26659 ./prep_dataset/ILSVRC2012_val_00044593.bin 224 224 +26660 ./prep_dataset/ILSVRC2012_val_00034049.bin 224 224 +26661 ./prep_dataset/ILSVRC2012_val_00035101.bin 224 224 +26662 ./prep_dataset/ILSVRC2012_val_00017473.bin 224 224 +26663 ./prep_dataset/ILSVRC2012_val_00032455.bin 224 224 +26664 ./prep_dataset/ILSVRC2012_val_00013383.bin 224 224 +26665 ./prep_dataset/ILSVRC2012_val_00025307.bin 224 224 +26666 ./prep_dataset/ILSVRC2012_val_00023830.bin 224 224 +26667 ./prep_dataset/ILSVRC2012_val_00016087.bin 224 224 +26668 ./prep_dataset/ILSVRC2012_val_00031823.bin 224 224 +26669 ./prep_dataset/ILSVRC2012_val_00025745.bin 224 224 +26670 ./prep_dataset/ILSVRC2012_val_00000871.bin 224 224 +26671 ./prep_dataset/ILSVRC2012_val_00015756.bin 224 224 +26672 ./prep_dataset/ILSVRC2012_val_00033803.bin 224 224 +26673 ./prep_dataset/ILSVRC2012_val_00043722.bin 224 224 +26674 ./prep_dataset/ILSVRC2012_val_00028486.bin 224 224 +26675 ./prep_dataset/ILSVRC2012_val_00007760.bin 224 224 +26676 ./prep_dataset/ILSVRC2012_val_00006875.bin 224 224 +26677 ./prep_dataset/ILSVRC2012_val_00042178.bin 224 224 +26678 ./prep_dataset/ILSVRC2012_val_00021942.bin 224 224 +26679 ./prep_dataset/ILSVRC2012_val_00017357.bin 224 224 +26680 ./prep_dataset/ILSVRC2012_val_00000675.bin 224 224 +26681 ./prep_dataset/ILSVRC2012_val_00001402.bin 224 224 +26682 ./prep_dataset/ILSVRC2012_val_00048078.bin 224 224 +26683 ./prep_dataset/ILSVRC2012_val_00015140.bin 224 224 +26684 ./prep_dataset/ILSVRC2012_val_00006797.bin 224 224 +26685 ./prep_dataset/ILSVRC2012_val_00005106.bin 224 224 +26686 ./prep_dataset/ILSVRC2012_val_00009573.bin 224 224 +26687 ./prep_dataset/ILSVRC2012_val_00019857.bin 224 224 +26688 ./prep_dataset/ILSVRC2012_val_00043872.bin 224 224 +26689 ./prep_dataset/ILSVRC2012_val_00021481.bin 224 224 +26690 ./prep_dataset/ILSVRC2012_val_00016495.bin 224 224 +26691 ./prep_dataset/ILSVRC2012_val_00007077.bin 224 224 +26692 ./prep_dataset/ILSVRC2012_val_00020189.bin 224 224 +26693 ./prep_dataset/ILSVRC2012_val_00047608.bin 224 224 +26694 ./prep_dataset/ILSVRC2012_val_00011647.bin 224 224 +26695 ./prep_dataset/ILSVRC2012_val_00003434.bin 224 224 +26696 ./prep_dataset/ILSVRC2012_val_00030194.bin 224 224 +26697 ./prep_dataset/ILSVRC2012_val_00042752.bin 224 224 +26698 ./prep_dataset/ILSVRC2012_val_00008346.bin 224 224 +26699 ./prep_dataset/ILSVRC2012_val_00043480.bin 224 224 +26700 ./prep_dataset/ILSVRC2012_val_00010997.bin 224 224 +26701 ./prep_dataset/ILSVRC2012_val_00011062.bin 224 224 +26702 ./prep_dataset/ILSVRC2012_val_00009407.bin 224 224 +26703 ./prep_dataset/ILSVRC2012_val_00033696.bin 224 224 +26704 ./prep_dataset/ILSVRC2012_val_00046816.bin 224 224 +26705 ./prep_dataset/ILSVRC2012_val_00009659.bin 224 224 +26706 ./prep_dataset/ILSVRC2012_val_00034121.bin 224 224 +26707 ./prep_dataset/ILSVRC2012_val_00044592.bin 224 224 +26708 ./prep_dataset/ILSVRC2012_val_00023036.bin 224 224 +26709 ./prep_dataset/ILSVRC2012_val_00037665.bin 224 224 +26710 ./prep_dataset/ILSVRC2012_val_00049684.bin 224 224 +26711 ./prep_dataset/ILSVRC2012_val_00014598.bin 224 224 +26712 ./prep_dataset/ILSVRC2012_val_00032885.bin 224 224 +26713 ./prep_dataset/ILSVRC2012_val_00034134.bin 224 224 +26714 ./prep_dataset/ILSVRC2012_val_00004217.bin 224 224 +26715 ./prep_dataset/ILSVRC2012_val_00020101.bin 224 224 +26716 ./prep_dataset/ILSVRC2012_val_00021198.bin 224 224 +26717 ./prep_dataset/ILSVRC2012_val_00005025.bin 224 224 +26718 ./prep_dataset/ILSVRC2012_val_00016394.bin 224 224 +26719 ./prep_dataset/ILSVRC2012_val_00004528.bin 224 224 +26720 ./prep_dataset/ILSVRC2012_val_00017627.bin 224 224 +26721 ./prep_dataset/ILSVRC2012_val_00003088.bin 224 224 +26722 ./prep_dataset/ILSVRC2012_val_00001672.bin 224 224 +26723 ./prep_dataset/ILSVRC2012_val_00024518.bin 224 224 +26724 ./prep_dataset/ILSVRC2012_val_00020561.bin 224 224 +26725 ./prep_dataset/ILSVRC2012_val_00024113.bin 224 224 +26726 ./prep_dataset/ILSVRC2012_val_00015080.bin 224 224 +26727 ./prep_dataset/ILSVRC2012_val_00002558.bin 224 224 +26728 ./prep_dataset/ILSVRC2012_val_00035582.bin 224 224 +26729 ./prep_dataset/ILSVRC2012_val_00025171.bin 224 224 +26730 ./prep_dataset/ILSVRC2012_val_00009477.bin 224 224 +26731 ./prep_dataset/ILSVRC2012_val_00021985.bin 224 224 +26732 ./prep_dataset/ILSVRC2012_val_00047023.bin 224 224 +26733 ./prep_dataset/ILSVRC2012_val_00007022.bin 224 224 +26734 ./prep_dataset/ILSVRC2012_val_00039432.bin 224 224 +26735 ./prep_dataset/ILSVRC2012_val_00033317.bin 224 224 +26736 ./prep_dataset/ILSVRC2012_val_00025923.bin 224 224 +26737 ./prep_dataset/ILSVRC2012_val_00011795.bin 224 224 +26738 ./prep_dataset/ILSVRC2012_val_00037617.bin 224 224 +26739 ./prep_dataset/ILSVRC2012_val_00026843.bin 224 224 +26740 ./prep_dataset/ILSVRC2012_val_00046291.bin 224 224 +26741 ./prep_dataset/ILSVRC2012_val_00020570.bin 224 224 +26742 ./prep_dataset/ILSVRC2012_val_00002498.bin 224 224 +26743 ./prep_dataset/ILSVRC2012_val_00049005.bin 224 224 +26744 ./prep_dataset/ILSVRC2012_val_00048769.bin 224 224 +26745 ./prep_dataset/ILSVRC2012_val_00022046.bin 224 224 +26746 ./prep_dataset/ILSVRC2012_val_00013996.bin 224 224 +26747 ./prep_dataset/ILSVRC2012_val_00035882.bin 224 224 +26748 ./prep_dataset/ILSVRC2012_val_00032121.bin 224 224 +26749 ./prep_dataset/ILSVRC2012_val_00005844.bin 224 224 +26750 ./prep_dataset/ILSVRC2012_val_00012369.bin 224 224 +26751 ./prep_dataset/ILSVRC2012_val_00030585.bin 224 224 +26752 ./prep_dataset/ILSVRC2012_val_00020109.bin 224 224 +26753 ./prep_dataset/ILSVRC2012_val_00005623.bin 224 224 +26754 ./prep_dataset/ILSVRC2012_val_00022179.bin 224 224 +26755 ./prep_dataset/ILSVRC2012_val_00033016.bin 224 224 +26756 ./prep_dataset/ILSVRC2012_val_00038451.bin 224 224 +26757 ./prep_dataset/ILSVRC2012_val_00026141.bin 224 224 +26758 ./prep_dataset/ILSVRC2012_val_00005615.bin 224 224 +26759 ./prep_dataset/ILSVRC2012_val_00019754.bin 224 224 +26760 ./prep_dataset/ILSVRC2012_val_00041307.bin 224 224 +26761 ./prep_dataset/ILSVRC2012_val_00036270.bin 224 224 +26762 ./prep_dataset/ILSVRC2012_val_00032429.bin 224 224 +26763 ./prep_dataset/ILSVRC2012_val_00047540.bin 224 224 +26764 ./prep_dataset/ILSVRC2012_val_00042434.bin 224 224 +26765 ./prep_dataset/ILSVRC2012_val_00024081.bin 224 224 +26766 ./prep_dataset/ILSVRC2012_val_00001819.bin 224 224 +26767 ./prep_dataset/ILSVRC2012_val_00025528.bin 224 224 +26768 ./prep_dataset/ILSVRC2012_val_00011759.bin 224 224 +26769 ./prep_dataset/ILSVRC2012_val_00016328.bin 224 224 +26770 ./prep_dataset/ILSVRC2012_val_00019531.bin 224 224 +26771 ./prep_dataset/ILSVRC2012_val_00014387.bin 224 224 +26772 ./prep_dataset/ILSVRC2012_val_00038265.bin 224 224 +26773 ./prep_dataset/ILSVRC2012_val_00026999.bin 224 224 +26774 ./prep_dataset/ILSVRC2012_val_00018710.bin 224 224 +26775 ./prep_dataset/ILSVRC2012_val_00042296.bin 224 224 +26776 ./prep_dataset/ILSVRC2012_val_00045274.bin 224 224 +26777 ./prep_dataset/ILSVRC2012_val_00033765.bin 224 224 +26778 ./prep_dataset/ILSVRC2012_val_00020747.bin 224 224 +26779 ./prep_dataset/ILSVRC2012_val_00026510.bin 224 224 +26780 ./prep_dataset/ILSVRC2012_val_00023931.bin 224 224 +26781 ./prep_dataset/ILSVRC2012_val_00013889.bin 224 224 +26782 ./prep_dataset/ILSVRC2012_val_00037434.bin 224 224 +26783 ./prep_dataset/ILSVRC2012_val_00029794.bin 224 224 +26784 ./prep_dataset/ILSVRC2012_val_00031014.bin 224 224 +26785 ./prep_dataset/ILSVRC2012_val_00006173.bin 224 224 +26786 ./prep_dataset/ILSVRC2012_val_00001650.bin 224 224 +26787 ./prep_dataset/ILSVRC2012_val_00005019.bin 224 224 +26788 ./prep_dataset/ILSVRC2012_val_00028906.bin 224 224 +26789 ./prep_dataset/ILSVRC2012_val_00028771.bin 224 224 +26790 ./prep_dataset/ILSVRC2012_val_00042253.bin 224 224 +26791 ./prep_dataset/ILSVRC2012_val_00016573.bin 224 224 +26792 ./prep_dataset/ILSVRC2012_val_00034849.bin 224 224 +26793 ./prep_dataset/ILSVRC2012_val_00022618.bin 224 224 +26794 ./prep_dataset/ILSVRC2012_val_00046870.bin 224 224 +26795 ./prep_dataset/ILSVRC2012_val_00018137.bin 224 224 +26796 ./prep_dataset/ILSVRC2012_val_00004758.bin 224 224 +26797 ./prep_dataset/ILSVRC2012_val_00022926.bin 224 224 +26798 ./prep_dataset/ILSVRC2012_val_00014767.bin 224 224 +26799 ./prep_dataset/ILSVRC2012_val_00043538.bin 224 224 +26800 ./prep_dataset/ILSVRC2012_val_00018330.bin 224 224 +26801 ./prep_dataset/ILSVRC2012_val_00022274.bin 224 224 +26802 ./prep_dataset/ILSVRC2012_val_00016713.bin 224 224 +26803 ./prep_dataset/ILSVRC2012_val_00020999.bin 224 224 +26804 ./prep_dataset/ILSVRC2012_val_00035759.bin 224 224 +26805 ./prep_dataset/ILSVRC2012_val_00018348.bin 224 224 +26806 ./prep_dataset/ILSVRC2012_val_00026031.bin 224 224 +26807 ./prep_dataset/ILSVRC2012_val_00012073.bin 224 224 +26808 ./prep_dataset/ILSVRC2012_val_00027344.bin 224 224 +26809 ./prep_dataset/ILSVRC2012_val_00014526.bin 224 224 +26810 ./prep_dataset/ILSVRC2012_val_00002549.bin 224 224 +26811 ./prep_dataset/ILSVRC2012_val_00034251.bin 224 224 +26812 ./prep_dataset/ILSVRC2012_val_00011517.bin 224 224 +26813 ./prep_dataset/ILSVRC2012_val_00023903.bin 224 224 +26814 ./prep_dataset/ILSVRC2012_val_00015611.bin 224 224 +26815 ./prep_dataset/ILSVRC2012_val_00035823.bin 224 224 +26816 ./prep_dataset/ILSVRC2012_val_00028169.bin 224 224 +26817 ./prep_dataset/ILSVRC2012_val_00025889.bin 224 224 +26818 ./prep_dataset/ILSVRC2012_val_00029191.bin 224 224 +26819 ./prep_dataset/ILSVRC2012_val_00008760.bin 224 224 +26820 ./prep_dataset/ILSVRC2012_val_00019247.bin 224 224 +26821 ./prep_dataset/ILSVRC2012_val_00012270.bin 224 224 +26822 ./prep_dataset/ILSVRC2012_val_00006651.bin 224 224 +26823 ./prep_dataset/ILSVRC2012_val_00031302.bin 224 224 +26824 ./prep_dataset/ILSVRC2012_val_00034745.bin 224 224 +26825 ./prep_dataset/ILSVRC2012_val_00030157.bin 224 224 +26826 ./prep_dataset/ILSVRC2012_val_00025806.bin 224 224 +26827 ./prep_dataset/ILSVRC2012_val_00035939.bin 224 224 +26828 ./prep_dataset/ILSVRC2012_val_00025487.bin 224 224 +26829 ./prep_dataset/ILSVRC2012_val_00008533.bin 224 224 +26830 ./prep_dataset/ILSVRC2012_val_00040767.bin 224 224 +26831 ./prep_dataset/ILSVRC2012_val_00019131.bin 224 224 +26832 ./prep_dataset/ILSVRC2012_val_00008443.bin 224 224 +26833 ./prep_dataset/ILSVRC2012_val_00004181.bin 224 224 +26834 ./prep_dataset/ILSVRC2012_val_00031390.bin 224 224 +26835 ./prep_dataset/ILSVRC2012_val_00018018.bin 224 224 +26836 ./prep_dataset/ILSVRC2012_val_00029478.bin 224 224 +26837 ./prep_dataset/ILSVRC2012_val_00009275.bin 224 224 +26838 ./prep_dataset/ILSVRC2012_val_00026579.bin 224 224 +26839 ./prep_dataset/ILSVRC2012_val_00020397.bin 224 224 +26840 ./prep_dataset/ILSVRC2012_val_00033562.bin 224 224 +26841 ./prep_dataset/ILSVRC2012_val_00002262.bin 224 224 +26842 ./prep_dataset/ILSVRC2012_val_00049530.bin 224 224 +26843 ./prep_dataset/ILSVRC2012_val_00017851.bin 224 224 +26844 ./prep_dataset/ILSVRC2012_val_00000275.bin 224 224 +26845 ./prep_dataset/ILSVRC2012_val_00004772.bin 224 224 +26846 ./prep_dataset/ILSVRC2012_val_00035896.bin 224 224 +26847 ./prep_dataset/ILSVRC2012_val_00012580.bin 224 224 +26848 ./prep_dataset/ILSVRC2012_val_00038136.bin 224 224 +26849 ./prep_dataset/ILSVRC2012_val_00036027.bin 224 224 +26850 ./prep_dataset/ILSVRC2012_val_00026665.bin 224 224 +26851 ./prep_dataset/ILSVRC2012_val_00035795.bin 224 224 +26852 ./prep_dataset/ILSVRC2012_val_00045189.bin 224 224 +26853 ./prep_dataset/ILSVRC2012_val_00039789.bin 224 224 +26854 ./prep_dataset/ILSVRC2012_val_00015104.bin 224 224 +26855 ./prep_dataset/ILSVRC2012_val_00041094.bin 224 224 +26856 ./prep_dataset/ILSVRC2012_val_00011690.bin 224 224 +26857 ./prep_dataset/ILSVRC2012_val_00042727.bin 224 224 +26858 ./prep_dataset/ILSVRC2012_val_00030070.bin 224 224 +26859 ./prep_dataset/ILSVRC2012_val_00045315.bin 224 224 +26860 ./prep_dataset/ILSVRC2012_val_00018894.bin 224 224 +26861 ./prep_dataset/ILSVRC2012_val_00007407.bin 224 224 +26862 ./prep_dataset/ILSVRC2012_val_00020870.bin 224 224 +26863 ./prep_dataset/ILSVRC2012_val_00047073.bin 224 224 +26864 ./prep_dataset/ILSVRC2012_val_00017025.bin 224 224 +26865 ./prep_dataset/ILSVRC2012_val_00014709.bin 224 224 +26866 ./prep_dataset/ILSVRC2012_val_00010111.bin 224 224 +26867 ./prep_dataset/ILSVRC2012_val_00010682.bin 224 224 +26868 ./prep_dataset/ILSVRC2012_val_00045922.bin 224 224 +26869 ./prep_dataset/ILSVRC2012_val_00002221.bin 224 224 +26870 ./prep_dataset/ILSVRC2012_val_00002744.bin 224 224 +26871 ./prep_dataset/ILSVRC2012_val_00034250.bin 224 224 +26872 ./prep_dataset/ILSVRC2012_val_00021601.bin 224 224 +26873 ./prep_dataset/ILSVRC2012_val_00005328.bin 224 224 +26874 ./prep_dataset/ILSVRC2012_val_00022587.bin 224 224 +26875 ./prep_dataset/ILSVRC2012_val_00001135.bin 224 224 +26876 ./prep_dataset/ILSVRC2012_val_00033363.bin 224 224 +26877 ./prep_dataset/ILSVRC2012_val_00038137.bin 224 224 +26878 ./prep_dataset/ILSVRC2012_val_00023012.bin 224 224 +26879 ./prep_dataset/ILSVRC2012_val_00020661.bin 224 224 +26880 ./prep_dataset/ILSVRC2012_val_00008416.bin 224 224 +26881 ./prep_dataset/ILSVRC2012_val_00048747.bin 224 224 +26882 ./prep_dataset/ILSVRC2012_val_00013779.bin 224 224 +26883 ./prep_dataset/ILSVRC2012_val_00019592.bin 224 224 +26884 ./prep_dataset/ILSVRC2012_val_00017120.bin 224 224 +26885 ./prep_dataset/ILSVRC2012_val_00043563.bin 224 224 +26886 ./prep_dataset/ILSVRC2012_val_00003409.bin 224 224 +26887 ./prep_dataset/ILSVRC2012_val_00034720.bin 224 224 +26888 ./prep_dataset/ILSVRC2012_val_00040518.bin 224 224 +26889 ./prep_dataset/ILSVRC2012_val_00000790.bin 224 224 +26890 ./prep_dataset/ILSVRC2012_val_00018593.bin 224 224 +26891 ./prep_dataset/ILSVRC2012_val_00014278.bin 224 224 +26892 ./prep_dataset/ILSVRC2012_val_00026620.bin 224 224 +26893 ./prep_dataset/ILSVRC2012_val_00008591.bin 224 224 +26894 ./prep_dataset/ILSVRC2012_val_00000474.bin 224 224 +26895 ./prep_dataset/ILSVRC2012_val_00031087.bin 224 224 +26896 ./prep_dataset/ILSVRC2012_val_00037210.bin 224 224 +26897 ./prep_dataset/ILSVRC2012_val_00042285.bin 224 224 +26898 ./prep_dataset/ILSVRC2012_val_00049210.bin 224 224 +26899 ./prep_dataset/ILSVRC2012_val_00040135.bin 224 224 +26900 ./prep_dataset/ILSVRC2012_val_00014834.bin 224 224 +26901 ./prep_dataset/ILSVRC2012_val_00048167.bin 224 224 +26902 ./prep_dataset/ILSVRC2012_val_00003430.bin 224 224 +26903 ./prep_dataset/ILSVRC2012_val_00025958.bin 224 224 +26904 ./prep_dataset/ILSVRC2012_val_00019365.bin 224 224 +26905 ./prep_dataset/ILSVRC2012_val_00000610.bin 224 224 +26906 ./prep_dataset/ILSVRC2012_val_00037631.bin 224 224 +26907 ./prep_dataset/ILSVRC2012_val_00031754.bin 224 224 +26908 ./prep_dataset/ILSVRC2012_val_00004607.bin 224 224 +26909 ./prep_dataset/ILSVRC2012_val_00039649.bin 224 224 +26910 ./prep_dataset/ILSVRC2012_val_00004516.bin 224 224 +26911 ./prep_dataset/ILSVRC2012_val_00040565.bin 224 224 +26912 ./prep_dataset/ILSVRC2012_val_00004443.bin 224 224 +26913 ./prep_dataset/ILSVRC2012_val_00038792.bin 224 224 +26914 ./prep_dataset/ILSVRC2012_val_00007595.bin 224 224 +26915 ./prep_dataset/ILSVRC2012_val_00049255.bin 224 224 +26916 ./prep_dataset/ILSVRC2012_val_00001126.bin 224 224 +26917 ./prep_dataset/ILSVRC2012_val_00045180.bin 224 224 +26918 ./prep_dataset/ILSVRC2012_val_00004504.bin 224 224 +26919 ./prep_dataset/ILSVRC2012_val_00026174.bin 224 224 +26920 ./prep_dataset/ILSVRC2012_val_00048703.bin 224 224 +26921 ./prep_dataset/ILSVRC2012_val_00017653.bin 224 224 +26922 ./prep_dataset/ILSVRC2012_val_00010613.bin 224 224 +26923 ./prep_dataset/ILSVRC2012_val_00019462.bin 224 224 +26924 ./prep_dataset/ILSVRC2012_val_00027660.bin 224 224 +26925 ./prep_dataset/ILSVRC2012_val_00020708.bin 224 224 +26926 ./prep_dataset/ILSVRC2012_val_00027328.bin 224 224 +26927 ./prep_dataset/ILSVRC2012_val_00025759.bin 224 224 +26928 ./prep_dataset/ILSVRC2012_val_00013002.bin 224 224 +26929 ./prep_dataset/ILSVRC2012_val_00004730.bin 224 224 +26930 ./prep_dataset/ILSVRC2012_val_00032466.bin 224 224 +26931 ./prep_dataset/ILSVRC2012_val_00017051.bin 224 224 +26932 ./prep_dataset/ILSVRC2012_val_00025613.bin 224 224 +26933 ./prep_dataset/ILSVRC2012_val_00034106.bin 224 224 +26934 ./prep_dataset/ILSVRC2012_val_00041060.bin 224 224 +26935 ./prep_dataset/ILSVRC2012_val_00040177.bin 224 224 +26936 ./prep_dataset/ILSVRC2012_val_00048811.bin 224 224 +26937 ./prep_dataset/ILSVRC2012_val_00048054.bin 224 224 +26938 ./prep_dataset/ILSVRC2012_val_00001342.bin 224 224 +26939 ./prep_dataset/ILSVRC2012_val_00035515.bin 224 224 +26940 ./prep_dataset/ILSVRC2012_val_00008487.bin 224 224 +26941 ./prep_dataset/ILSVRC2012_val_00029998.bin 224 224 +26942 ./prep_dataset/ILSVRC2012_val_00046916.bin 224 224 +26943 ./prep_dataset/ILSVRC2012_val_00000953.bin 224 224 +26944 ./prep_dataset/ILSVRC2012_val_00002530.bin 224 224 +26945 ./prep_dataset/ILSVRC2012_val_00011540.bin 224 224 +26946 ./prep_dataset/ILSVRC2012_val_00004404.bin 224 224 +26947 ./prep_dataset/ILSVRC2012_val_00049532.bin 224 224 +26948 ./prep_dataset/ILSVRC2012_val_00014144.bin 224 224 +26949 ./prep_dataset/ILSVRC2012_val_00036126.bin 224 224 +26950 ./prep_dataset/ILSVRC2012_val_00037296.bin 224 224 +26951 ./prep_dataset/ILSVRC2012_val_00036965.bin 224 224 +26952 ./prep_dataset/ILSVRC2012_val_00049262.bin 224 224 +26953 ./prep_dataset/ILSVRC2012_val_00013386.bin 224 224 +26954 ./prep_dataset/ILSVRC2012_val_00012307.bin 224 224 +26955 ./prep_dataset/ILSVRC2012_val_00015768.bin 224 224 +26956 ./prep_dataset/ILSVRC2012_val_00010717.bin 224 224 +26957 ./prep_dataset/ILSVRC2012_val_00043276.bin 224 224 +26958 ./prep_dataset/ILSVRC2012_val_00001867.bin 224 224 +26959 ./prep_dataset/ILSVRC2012_val_00042160.bin 224 224 +26960 ./prep_dataset/ILSVRC2012_val_00007158.bin 224 224 +26961 ./prep_dataset/ILSVRC2012_val_00025364.bin 224 224 +26962 ./prep_dataset/ILSVRC2012_val_00026045.bin 224 224 +26963 ./prep_dataset/ILSVRC2012_val_00035766.bin 224 224 +26964 ./prep_dataset/ILSVRC2012_val_00005292.bin 224 224 +26965 ./prep_dataset/ILSVRC2012_val_00009046.bin 224 224 +26966 ./prep_dataset/ILSVRC2012_val_00028895.bin 224 224 +26967 ./prep_dataset/ILSVRC2012_val_00033677.bin 224 224 +26968 ./prep_dataset/ILSVRC2012_val_00016939.bin 224 224 +26969 ./prep_dataset/ILSVRC2012_val_00031604.bin 224 224 +26970 ./prep_dataset/ILSVRC2012_val_00013566.bin 224 224 +26971 ./prep_dataset/ILSVRC2012_val_00029494.bin 224 224 +26972 ./prep_dataset/ILSVRC2012_val_00013534.bin 224 224 +26973 ./prep_dataset/ILSVRC2012_val_00046714.bin 224 224 +26974 ./prep_dataset/ILSVRC2012_val_00005039.bin 224 224 +26975 ./prep_dataset/ILSVRC2012_val_00036365.bin 224 224 +26976 ./prep_dataset/ILSVRC2012_val_00013596.bin 224 224 +26977 ./prep_dataset/ILSVRC2012_val_00012238.bin 224 224 +26978 ./prep_dataset/ILSVRC2012_val_00001203.bin 224 224 +26979 ./prep_dataset/ILSVRC2012_val_00044985.bin 224 224 +26980 ./prep_dataset/ILSVRC2012_val_00022426.bin 224 224 +26981 ./prep_dataset/ILSVRC2012_val_00018822.bin 224 224 +26982 ./prep_dataset/ILSVRC2012_val_00021858.bin 224 224 +26983 ./prep_dataset/ILSVRC2012_val_00011012.bin 224 224 +26984 ./prep_dataset/ILSVRC2012_val_00026257.bin 224 224 +26985 ./prep_dataset/ILSVRC2012_val_00001168.bin 224 224 +26986 ./prep_dataset/ILSVRC2012_val_00012045.bin 224 224 +26987 ./prep_dataset/ILSVRC2012_val_00049146.bin 224 224 +26988 ./prep_dataset/ILSVRC2012_val_00040970.bin 224 224 +26989 ./prep_dataset/ILSVRC2012_val_00045008.bin 224 224 +26990 ./prep_dataset/ILSVRC2012_val_00010981.bin 224 224 +26991 ./prep_dataset/ILSVRC2012_val_00032930.bin 224 224 +26992 ./prep_dataset/ILSVRC2012_val_00049238.bin 224 224 +26993 ./prep_dataset/ILSVRC2012_val_00044144.bin 224 224 +26994 ./prep_dataset/ILSVRC2012_val_00020526.bin 224 224 +26995 ./prep_dataset/ILSVRC2012_val_00031490.bin 224 224 +26996 ./prep_dataset/ILSVRC2012_val_00011323.bin 224 224 +26997 ./prep_dataset/ILSVRC2012_val_00040045.bin 224 224 +26998 ./prep_dataset/ILSVRC2012_val_00002007.bin 224 224 +26999 ./prep_dataset/ILSVRC2012_val_00011177.bin 224 224 +27000 ./prep_dataset/ILSVRC2012_val_00003814.bin 224 224 +27001 ./prep_dataset/ILSVRC2012_val_00034629.bin 224 224 +27002 ./prep_dataset/ILSVRC2012_val_00033142.bin 224 224 +27003 ./prep_dataset/ILSVRC2012_val_00032261.bin 224 224 +27004 ./prep_dataset/ILSVRC2012_val_00002204.bin 224 224 +27005 ./prep_dataset/ILSVRC2012_val_00045200.bin 224 224 +27006 ./prep_dataset/ILSVRC2012_val_00012185.bin 224 224 +27007 ./prep_dataset/ILSVRC2012_val_00044506.bin 224 224 +27008 ./prep_dataset/ILSVRC2012_val_00049942.bin 224 224 +27009 ./prep_dataset/ILSVRC2012_val_00015960.bin 224 224 +27010 ./prep_dataset/ILSVRC2012_val_00021713.bin 224 224 +27011 ./prep_dataset/ILSVRC2012_val_00048478.bin 224 224 +27012 ./prep_dataset/ILSVRC2012_val_00032786.bin 224 224 +27013 ./prep_dataset/ILSVRC2012_val_00009467.bin 224 224 +27014 ./prep_dataset/ILSVRC2012_val_00045485.bin 224 224 +27015 ./prep_dataset/ILSVRC2012_val_00002902.bin 224 224 +27016 ./prep_dataset/ILSVRC2012_val_00039317.bin 224 224 +27017 ./prep_dataset/ILSVRC2012_val_00032701.bin 224 224 +27018 ./prep_dataset/ILSVRC2012_val_00041818.bin 224 224 +27019 ./prep_dataset/ILSVRC2012_val_00023218.bin 224 224 +27020 ./prep_dataset/ILSVRC2012_val_00040079.bin 224 224 +27021 ./prep_dataset/ILSVRC2012_val_00009546.bin 224 224 +27022 ./prep_dataset/ILSVRC2012_val_00030289.bin 224 224 +27023 ./prep_dataset/ILSVRC2012_val_00036422.bin 224 224 +27024 ./prep_dataset/ILSVRC2012_val_00045601.bin 224 224 +27025 ./prep_dataset/ILSVRC2012_val_00042830.bin 224 224 +27026 ./prep_dataset/ILSVRC2012_val_00021417.bin 224 224 +27027 ./prep_dataset/ILSVRC2012_val_00028149.bin 224 224 +27028 ./prep_dataset/ILSVRC2012_val_00000862.bin 224 224 +27029 ./prep_dataset/ILSVRC2012_val_00046508.bin 224 224 +27030 ./prep_dataset/ILSVRC2012_val_00032281.bin 224 224 +27031 ./prep_dataset/ILSVRC2012_val_00021017.bin 224 224 +27032 ./prep_dataset/ILSVRC2012_val_00035689.bin 224 224 +27033 ./prep_dataset/ILSVRC2012_val_00014678.bin 224 224 +27034 ./prep_dataset/ILSVRC2012_val_00017471.bin 224 224 +27035 ./prep_dataset/ILSVRC2012_val_00025699.bin 224 224 +27036 ./prep_dataset/ILSVRC2012_val_00016805.bin 224 224 +27037 ./prep_dataset/ILSVRC2012_val_00033502.bin 224 224 +27038 ./prep_dataset/ILSVRC2012_val_00045993.bin 224 224 +27039 ./prep_dataset/ILSVRC2012_val_00029475.bin 224 224 +27040 ./prep_dataset/ILSVRC2012_val_00005954.bin 224 224 +27041 ./prep_dataset/ILSVRC2012_val_00003607.bin 224 224 +27042 ./prep_dataset/ILSVRC2012_val_00040563.bin 224 224 +27043 ./prep_dataset/ILSVRC2012_val_00038952.bin 224 224 +27044 ./prep_dataset/ILSVRC2012_val_00017239.bin 224 224 +27045 ./prep_dataset/ILSVRC2012_val_00010585.bin 224 224 +27046 ./prep_dataset/ILSVRC2012_val_00042795.bin 224 224 +27047 ./prep_dataset/ILSVRC2012_val_00018181.bin 224 224 +27048 ./prep_dataset/ILSVRC2012_val_00011168.bin 224 224 +27049 ./prep_dataset/ILSVRC2012_val_00026904.bin 224 224 +27050 ./prep_dataset/ILSVRC2012_val_00032634.bin 224 224 +27051 ./prep_dataset/ILSVRC2012_val_00022065.bin 224 224 +27052 ./prep_dataset/ILSVRC2012_val_00002767.bin 224 224 +27053 ./prep_dataset/ILSVRC2012_val_00049156.bin 224 224 +27054 ./prep_dataset/ILSVRC2012_val_00004020.bin 224 224 +27055 ./prep_dataset/ILSVRC2012_val_00031606.bin 224 224 +27056 ./prep_dataset/ILSVRC2012_val_00045845.bin 224 224 +27057 ./prep_dataset/ILSVRC2012_val_00043635.bin 224 224 +27058 ./prep_dataset/ILSVRC2012_val_00017820.bin 224 224 +27059 ./prep_dataset/ILSVRC2012_val_00048287.bin 224 224 +27060 ./prep_dataset/ILSVRC2012_val_00028977.bin 224 224 +27061 ./prep_dataset/ILSVRC2012_val_00010560.bin 224 224 +27062 ./prep_dataset/ILSVRC2012_val_00002377.bin 224 224 +27063 ./prep_dataset/ILSVRC2012_val_00024561.bin 224 224 +27064 ./prep_dataset/ILSVRC2012_val_00009210.bin 224 224 +27065 ./prep_dataset/ILSVRC2012_val_00047850.bin 224 224 +27066 ./prep_dataset/ILSVRC2012_val_00025971.bin 224 224 +27067 ./prep_dataset/ILSVRC2012_val_00003829.bin 224 224 +27068 ./prep_dataset/ILSVRC2012_val_00023440.bin 224 224 +27069 ./prep_dataset/ILSVRC2012_val_00031726.bin 224 224 +27070 ./prep_dataset/ILSVRC2012_val_00024383.bin 224 224 +27071 ./prep_dataset/ILSVRC2012_val_00023350.bin 224 224 +27072 ./prep_dataset/ILSVRC2012_val_00006245.bin 224 224 +27073 ./prep_dataset/ILSVRC2012_val_00029419.bin 224 224 +27074 ./prep_dataset/ILSVRC2012_val_00017663.bin 224 224 +27075 ./prep_dataset/ILSVRC2012_val_00010012.bin 224 224 +27076 ./prep_dataset/ILSVRC2012_val_00001645.bin 224 224 +27077 ./prep_dataset/ILSVRC2012_val_00027951.bin 224 224 +27078 ./prep_dataset/ILSVRC2012_val_00044276.bin 224 224 +27079 ./prep_dataset/ILSVRC2012_val_00020830.bin 224 224 +27080 ./prep_dataset/ILSVRC2012_val_00012757.bin 224 224 +27081 ./prep_dataset/ILSVRC2012_val_00042751.bin 224 224 +27082 ./prep_dataset/ILSVRC2012_val_00036495.bin 224 224 +27083 ./prep_dataset/ILSVRC2012_val_00025623.bin 224 224 +27084 ./prep_dataset/ILSVRC2012_val_00017671.bin 224 224 +27085 ./prep_dataset/ILSVRC2012_val_00043976.bin 224 224 +27086 ./prep_dataset/ILSVRC2012_val_00038220.bin 224 224 +27087 ./prep_dataset/ILSVRC2012_val_00049074.bin 224 224 +27088 ./prep_dataset/ILSVRC2012_val_00032645.bin 224 224 +27089 ./prep_dataset/ILSVRC2012_val_00001157.bin 224 224 +27090 ./prep_dataset/ILSVRC2012_val_00028800.bin 224 224 +27091 ./prep_dataset/ILSVRC2012_val_00025924.bin 224 224 +27092 ./prep_dataset/ILSVRC2012_val_00037355.bin 224 224 +27093 ./prep_dataset/ILSVRC2012_val_00039899.bin 224 224 +27094 ./prep_dataset/ILSVRC2012_val_00026453.bin 224 224 +27095 ./prep_dataset/ILSVRC2012_val_00000208.bin 224 224 +27096 ./prep_dataset/ILSVRC2012_val_00010707.bin 224 224 +27097 ./prep_dataset/ILSVRC2012_val_00038105.bin 224 224 +27098 ./prep_dataset/ILSVRC2012_val_00020907.bin 224 224 +27099 ./prep_dataset/ILSVRC2012_val_00004648.bin 224 224 +27100 ./prep_dataset/ILSVRC2012_val_00005850.bin 224 224 +27101 ./prep_dataset/ILSVRC2012_val_00014958.bin 224 224 +27102 ./prep_dataset/ILSVRC2012_val_00003465.bin 224 224 +27103 ./prep_dataset/ILSVRC2012_val_00006263.bin 224 224 +27104 ./prep_dataset/ILSVRC2012_val_00030658.bin 224 224 +27105 ./prep_dataset/ILSVRC2012_val_00030409.bin 224 224 +27106 ./prep_dataset/ILSVRC2012_val_00021546.bin 224 224 +27107 ./prep_dataset/ILSVRC2012_val_00047176.bin 224 224 +27108 ./prep_dataset/ILSVRC2012_val_00016456.bin 224 224 +27109 ./prep_dataset/ILSVRC2012_val_00022814.bin 224 224 +27110 ./prep_dataset/ILSVRC2012_val_00019374.bin 224 224 +27111 ./prep_dataset/ILSVRC2012_val_00037566.bin 224 224 +27112 ./prep_dataset/ILSVRC2012_val_00027808.bin 224 224 +27113 ./prep_dataset/ILSVRC2012_val_00033899.bin 224 224 +27114 ./prep_dataset/ILSVRC2012_val_00018329.bin 224 224 +27115 ./prep_dataset/ILSVRC2012_val_00007847.bin 224 224 +27116 ./prep_dataset/ILSVRC2012_val_00033433.bin 224 224 +27117 ./prep_dataset/ILSVRC2012_val_00044257.bin 224 224 +27118 ./prep_dataset/ILSVRC2012_val_00048907.bin 224 224 +27119 ./prep_dataset/ILSVRC2012_val_00033913.bin 224 224 +27120 ./prep_dataset/ILSVRC2012_val_00029806.bin 224 224 +27121 ./prep_dataset/ILSVRC2012_val_00018599.bin 224 224 +27122 ./prep_dataset/ILSVRC2012_val_00014418.bin 224 224 +27123 ./prep_dataset/ILSVRC2012_val_00032389.bin 224 224 +27124 ./prep_dataset/ILSVRC2012_val_00045520.bin 224 224 +27125 ./prep_dataset/ILSVRC2012_val_00007716.bin 224 224 +27126 ./prep_dataset/ILSVRC2012_val_00033271.bin 224 224 +27127 ./prep_dataset/ILSVRC2012_val_00043112.bin 224 224 +27128 ./prep_dataset/ILSVRC2012_val_00006011.bin 224 224 +27129 ./prep_dataset/ILSVRC2012_val_00012090.bin 224 224 +27130 ./prep_dataset/ILSVRC2012_val_00001729.bin 224 224 +27131 ./prep_dataset/ILSVRC2012_val_00041917.bin 224 224 +27132 ./prep_dataset/ILSVRC2012_val_00034278.bin 224 224 +27133 ./prep_dataset/ILSVRC2012_val_00030803.bin 224 224 +27134 ./prep_dataset/ILSVRC2012_val_00019494.bin 224 224 +27135 ./prep_dataset/ILSVRC2012_val_00007978.bin 224 224 +27136 ./prep_dataset/ILSVRC2012_val_00035443.bin 224 224 +27137 ./prep_dataset/ILSVRC2012_val_00013876.bin 224 224 +27138 ./prep_dataset/ILSVRC2012_val_00020253.bin 224 224 +27139 ./prep_dataset/ILSVRC2012_val_00041791.bin 224 224 +27140 ./prep_dataset/ILSVRC2012_val_00021388.bin 224 224 +27141 ./prep_dataset/ILSVRC2012_val_00012278.bin 224 224 +27142 ./prep_dataset/ILSVRC2012_val_00038070.bin 224 224 +27143 ./prep_dataset/ILSVRC2012_val_00003422.bin 224 224 +27144 ./prep_dataset/ILSVRC2012_val_00034612.bin 224 224 +27145 ./prep_dataset/ILSVRC2012_val_00011693.bin 224 224 +27146 ./prep_dataset/ILSVRC2012_val_00015721.bin 224 224 +27147 ./prep_dataset/ILSVRC2012_val_00009549.bin 224 224 +27148 ./prep_dataset/ILSVRC2012_val_00042402.bin 224 224 +27149 ./prep_dataset/ILSVRC2012_val_00009179.bin 224 224 +27150 ./prep_dataset/ILSVRC2012_val_00010395.bin 224 224 +27151 ./prep_dataset/ILSVRC2012_val_00007434.bin 224 224 +27152 ./prep_dataset/ILSVRC2012_val_00020861.bin 224 224 +27153 ./prep_dataset/ILSVRC2012_val_00003040.bin 224 224 +27154 ./prep_dataset/ILSVRC2012_val_00006919.bin 224 224 +27155 ./prep_dataset/ILSVRC2012_val_00035145.bin 224 224 +27156 ./prep_dataset/ILSVRC2012_val_00043807.bin 224 224 +27157 ./prep_dataset/ILSVRC2012_val_00047662.bin 224 224 +27158 ./prep_dataset/ILSVRC2012_val_00031182.bin 224 224 +27159 ./prep_dataset/ILSVRC2012_val_00005906.bin 224 224 +27160 ./prep_dataset/ILSVRC2012_val_00015366.bin 224 224 +27161 ./prep_dataset/ILSVRC2012_val_00041195.bin 224 224 +27162 ./prep_dataset/ILSVRC2012_val_00041878.bin 224 224 +27163 ./prep_dataset/ILSVRC2012_val_00031708.bin 224 224 +27164 ./prep_dataset/ILSVRC2012_val_00008372.bin 224 224 +27165 ./prep_dataset/ILSVRC2012_val_00011792.bin 224 224 +27166 ./prep_dataset/ILSVRC2012_val_00025184.bin 224 224 +27167 ./prep_dataset/ILSVRC2012_val_00024028.bin 224 224 +27168 ./prep_dataset/ILSVRC2012_val_00029665.bin 224 224 +27169 ./prep_dataset/ILSVRC2012_val_00036923.bin 224 224 +27170 ./prep_dataset/ILSVRC2012_val_00012892.bin 224 224 +27171 ./prep_dataset/ILSVRC2012_val_00035621.bin 224 224 +27172 ./prep_dataset/ILSVRC2012_val_00038445.bin 224 224 +27173 ./prep_dataset/ILSVRC2012_val_00039492.bin 224 224 +27174 ./prep_dataset/ILSVRC2012_val_00002444.bin 224 224 +27175 ./prep_dataset/ILSVRC2012_val_00017201.bin 224 224 +27176 ./prep_dataset/ILSVRC2012_val_00035203.bin 224 224 +27177 ./prep_dataset/ILSVRC2012_val_00025152.bin 224 224 +27178 ./prep_dataset/ILSVRC2012_val_00004830.bin 224 224 +27179 ./prep_dataset/ILSVRC2012_val_00045715.bin 224 224 +27180 ./prep_dataset/ILSVRC2012_val_00015547.bin 224 224 +27181 ./prep_dataset/ILSVRC2012_val_00012125.bin 224 224 +27182 ./prep_dataset/ILSVRC2012_val_00036777.bin 224 224 +27183 ./prep_dataset/ILSVRC2012_val_00042334.bin 224 224 +27184 ./prep_dataset/ILSVRC2012_val_00032773.bin 224 224 +27185 ./prep_dataset/ILSVRC2012_val_00041780.bin 224 224 +27186 ./prep_dataset/ILSVRC2012_val_00037782.bin 224 224 +27187 ./prep_dataset/ILSVRC2012_val_00039148.bin 224 224 +27188 ./prep_dataset/ILSVRC2012_val_00010693.bin 224 224 +27189 ./prep_dataset/ILSVRC2012_val_00028540.bin 224 224 +27190 ./prep_dataset/ILSVRC2012_val_00015844.bin 224 224 +27191 ./prep_dataset/ILSVRC2012_val_00039632.bin 224 224 +27192 ./prep_dataset/ILSVRC2012_val_00016104.bin 224 224 +27193 ./prep_dataset/ILSVRC2012_val_00016555.bin 224 224 +27194 ./prep_dataset/ILSVRC2012_val_00027874.bin 224 224 +27195 ./prep_dataset/ILSVRC2012_val_00046867.bin 224 224 +27196 ./prep_dataset/ILSVRC2012_val_00003286.bin 224 224 +27197 ./prep_dataset/ILSVRC2012_val_00027650.bin 224 224 +27198 ./prep_dataset/ILSVRC2012_val_00034578.bin 224 224 +27199 ./prep_dataset/ILSVRC2012_val_00036708.bin 224 224 +27200 ./prep_dataset/ILSVRC2012_val_00037783.bin 224 224 +27201 ./prep_dataset/ILSVRC2012_val_00039268.bin 224 224 +27202 ./prep_dataset/ILSVRC2012_val_00046039.bin 224 224 +27203 ./prep_dataset/ILSVRC2012_val_00034258.bin 224 224 +27204 ./prep_dataset/ILSVRC2012_val_00040874.bin 224 224 +27205 ./prep_dataset/ILSVRC2012_val_00034776.bin 224 224 +27206 ./prep_dataset/ILSVRC2012_val_00030382.bin 224 224 +27207 ./prep_dataset/ILSVRC2012_val_00032133.bin 224 224 +27208 ./prep_dataset/ILSVRC2012_val_00005574.bin 224 224 +27209 ./prep_dataset/ILSVRC2012_val_00031769.bin 224 224 +27210 ./prep_dataset/ILSVRC2012_val_00030105.bin 224 224 +27211 ./prep_dataset/ILSVRC2012_val_00033176.bin 224 224 +27212 ./prep_dataset/ILSVRC2012_val_00033904.bin 224 224 +27213 ./prep_dataset/ILSVRC2012_val_00033441.bin 224 224 +27214 ./prep_dataset/ILSVRC2012_val_00021299.bin 224 224 +27215 ./prep_dataset/ILSVRC2012_val_00044233.bin 224 224 +27216 ./prep_dataset/ILSVRC2012_val_00008541.bin 224 224 +27217 ./prep_dataset/ILSVRC2012_val_00005589.bin 224 224 +27218 ./prep_dataset/ILSVRC2012_val_00038276.bin 224 224 +27219 ./prep_dataset/ILSVRC2012_val_00014123.bin 224 224 +27220 ./prep_dataset/ILSVRC2012_val_00010358.bin 224 224 +27221 ./prep_dataset/ILSVRC2012_val_00045859.bin 224 224 +27222 ./prep_dataset/ILSVRC2012_val_00035195.bin 224 224 +27223 ./prep_dataset/ILSVRC2012_val_00009682.bin 224 224 +27224 ./prep_dataset/ILSVRC2012_val_00038622.bin 224 224 +27225 ./prep_dataset/ILSVRC2012_val_00001777.bin 224 224 +27226 ./prep_dataset/ILSVRC2012_val_00042381.bin 224 224 +27227 ./prep_dataset/ILSVRC2012_val_00034811.bin 224 224 +27228 ./prep_dataset/ILSVRC2012_val_00021124.bin 224 224 +27229 ./prep_dataset/ILSVRC2012_val_00042149.bin 224 224 +27230 ./prep_dataset/ILSVRC2012_val_00003260.bin 224 224 +27231 ./prep_dataset/ILSVRC2012_val_00016985.bin 224 224 +27232 ./prep_dataset/ILSVRC2012_val_00034291.bin 224 224 +27233 ./prep_dataset/ILSVRC2012_val_00004558.bin 224 224 +27234 ./prep_dataset/ILSVRC2012_val_00005559.bin 224 224 +27235 ./prep_dataset/ILSVRC2012_val_00040460.bin 224 224 +27236 ./prep_dataset/ILSVRC2012_val_00013825.bin 224 224 +27237 ./prep_dataset/ILSVRC2012_val_00020686.bin 224 224 +27238 ./prep_dataset/ILSVRC2012_val_00004939.bin 224 224 +27239 ./prep_dataset/ILSVRC2012_val_00025351.bin 224 224 +27240 ./prep_dataset/ILSVRC2012_val_00015058.bin 224 224 +27241 ./prep_dataset/ILSVRC2012_val_00044923.bin 224 224 +27242 ./prep_dataset/ILSVRC2012_val_00009218.bin 224 224 +27243 ./prep_dataset/ILSVRC2012_val_00047088.bin 224 224 +27244 ./prep_dataset/ILSVRC2012_val_00005083.bin 224 224 +27245 ./prep_dataset/ILSVRC2012_val_00041770.bin 224 224 +27246 ./prep_dataset/ILSVRC2012_val_00023005.bin 224 224 +27247 ./prep_dataset/ILSVRC2012_val_00025103.bin 224 224 +27248 ./prep_dataset/ILSVRC2012_val_00043340.bin 224 224 +27249 ./prep_dataset/ILSVRC2012_val_00046643.bin 224 224 +27250 ./prep_dataset/ILSVRC2012_val_00047321.bin 224 224 +27251 ./prep_dataset/ILSVRC2012_val_00016755.bin 224 224 +27252 ./prep_dataset/ILSVRC2012_val_00041586.bin 224 224 +27253 ./prep_dataset/ILSVRC2012_val_00024060.bin 224 224 +27254 ./prep_dataset/ILSVRC2012_val_00015006.bin 224 224 +27255 ./prep_dataset/ILSVRC2012_val_00036191.bin 224 224 +27256 ./prep_dataset/ILSVRC2012_val_00049135.bin 224 224 +27257 ./prep_dataset/ILSVRC2012_val_00019317.bin 224 224 +27258 ./prep_dataset/ILSVRC2012_val_00049528.bin 224 224 +27259 ./prep_dataset/ILSVRC2012_val_00014325.bin 224 224 +27260 ./prep_dataset/ILSVRC2012_val_00030201.bin 224 224 +27261 ./prep_dataset/ILSVRC2012_val_00048179.bin 224 224 +27262 ./prep_dataset/ILSVRC2012_val_00027565.bin 224 224 +27263 ./prep_dataset/ILSVRC2012_val_00041737.bin 224 224 +27264 ./prep_dataset/ILSVRC2012_val_00016900.bin 224 224 +27265 ./prep_dataset/ILSVRC2012_val_00028004.bin 224 224 +27266 ./prep_dataset/ILSVRC2012_val_00017175.bin 224 224 +27267 ./prep_dataset/ILSVRC2012_val_00031586.bin 224 224 +27268 ./prep_dataset/ILSVRC2012_val_00013199.bin 224 224 +27269 ./prep_dataset/ILSVRC2012_val_00019569.bin 224 224 +27270 ./prep_dataset/ILSVRC2012_val_00019520.bin 224 224 +27271 ./prep_dataset/ILSVRC2012_val_00000522.bin 224 224 +27272 ./prep_dataset/ILSVRC2012_val_00042058.bin 224 224 +27273 ./prep_dataset/ILSVRC2012_val_00027766.bin 224 224 +27274 ./prep_dataset/ILSVRC2012_val_00044723.bin 224 224 +27275 ./prep_dataset/ILSVRC2012_val_00017343.bin 224 224 +27276 ./prep_dataset/ILSVRC2012_val_00046110.bin 224 224 +27277 ./prep_dataset/ILSVRC2012_val_00013362.bin 224 224 +27278 ./prep_dataset/ILSVRC2012_val_00033949.bin 224 224 +27279 ./prep_dataset/ILSVRC2012_val_00036918.bin 224 224 +27280 ./prep_dataset/ILSVRC2012_val_00028831.bin 224 224 +27281 ./prep_dataset/ILSVRC2012_val_00026162.bin 224 224 +27282 ./prep_dataset/ILSVRC2012_val_00045325.bin 224 224 +27283 ./prep_dataset/ILSVRC2012_val_00001231.bin 224 224 +27284 ./prep_dataset/ILSVRC2012_val_00004752.bin 224 224 +27285 ./prep_dataset/ILSVRC2012_val_00022918.bin 224 224 +27286 ./prep_dataset/ILSVRC2012_val_00007666.bin 224 224 +27287 ./prep_dataset/ILSVRC2012_val_00034686.bin 224 224 +27288 ./prep_dataset/ILSVRC2012_val_00003133.bin 224 224 +27289 ./prep_dataset/ILSVRC2012_val_00040114.bin 224 224 +27290 ./prep_dataset/ILSVRC2012_val_00013993.bin 224 224 +27291 ./prep_dataset/ILSVRC2012_val_00012668.bin 224 224 +27292 ./prep_dataset/ILSVRC2012_val_00040323.bin 224 224 +27293 ./prep_dataset/ILSVRC2012_val_00021270.bin 224 224 +27294 ./prep_dataset/ILSVRC2012_val_00033208.bin 224 224 +27295 ./prep_dataset/ILSVRC2012_val_00031943.bin 224 224 +27296 ./prep_dataset/ILSVRC2012_val_00043739.bin 224 224 +27297 ./prep_dataset/ILSVRC2012_val_00049244.bin 224 224 +27298 ./prep_dataset/ILSVRC2012_val_00020701.bin 224 224 +27299 ./prep_dataset/ILSVRC2012_val_00033237.bin 224 224 +27300 ./prep_dataset/ILSVRC2012_val_00009409.bin 224 224 +27301 ./prep_dataset/ILSVRC2012_val_00023772.bin 224 224 +27302 ./prep_dataset/ILSVRC2012_val_00007274.bin 224 224 +27303 ./prep_dataset/ILSVRC2012_val_00042756.bin 224 224 +27304 ./prep_dataset/ILSVRC2012_val_00042243.bin 224 224 +27305 ./prep_dataset/ILSVRC2012_val_00000025.bin 224 224 +27306 ./prep_dataset/ILSVRC2012_val_00045119.bin 224 224 +27307 ./prep_dataset/ILSVRC2012_val_00030343.bin 224 224 +27308 ./prep_dataset/ILSVRC2012_val_00034511.bin 224 224 +27309 ./prep_dataset/ILSVRC2012_val_00014742.bin 224 224 +27310 ./prep_dataset/ILSVRC2012_val_00042873.bin 224 224 +27311 ./prep_dataset/ILSVRC2012_val_00033093.bin 224 224 +27312 ./prep_dataset/ILSVRC2012_val_00027886.bin 224 224 +27313 ./prep_dataset/ILSVRC2012_val_00001977.bin 224 224 +27314 ./prep_dataset/ILSVRC2012_val_00000561.bin 224 224 +27315 ./prep_dataset/ILSVRC2012_val_00030457.bin 224 224 +27316 ./prep_dataset/ILSVRC2012_val_00004264.bin 224 224 +27317 ./prep_dataset/ILSVRC2012_val_00042852.bin 224 224 +27318 ./prep_dataset/ILSVRC2012_val_00008064.bin 224 224 +27319 ./prep_dataset/ILSVRC2012_val_00010393.bin 224 224 +27320 ./prep_dataset/ILSVRC2012_val_00044118.bin 224 224 +27321 ./prep_dataset/ILSVRC2012_val_00024894.bin 224 224 +27322 ./prep_dataset/ILSVRC2012_val_00003233.bin 224 224 +27323 ./prep_dataset/ILSVRC2012_val_00000361.bin 224 224 +27324 ./prep_dataset/ILSVRC2012_val_00016705.bin 224 224 +27325 ./prep_dataset/ILSVRC2012_val_00041443.bin 224 224 +27326 ./prep_dataset/ILSVRC2012_val_00004440.bin 224 224 +27327 ./prep_dataset/ILSVRC2012_val_00013310.bin 224 224 +27328 ./prep_dataset/ILSVRC2012_val_00031886.bin 224 224 +27329 ./prep_dataset/ILSVRC2012_val_00044240.bin 224 224 +27330 ./prep_dataset/ILSVRC2012_val_00041272.bin 224 224 +27331 ./prep_dataset/ILSVRC2012_val_00038501.bin 224 224 +27332 ./prep_dataset/ILSVRC2012_val_00018573.bin 224 224 +27333 ./prep_dataset/ILSVRC2012_val_00027652.bin 224 224 +27334 ./prep_dataset/ILSVRC2012_val_00040041.bin 224 224 +27335 ./prep_dataset/ILSVRC2012_val_00047894.bin 224 224 +27336 ./prep_dataset/ILSVRC2012_val_00005932.bin 224 224 +27337 ./prep_dataset/ILSVRC2012_val_00048594.bin 224 224 +27338 ./prep_dataset/ILSVRC2012_val_00043727.bin 224 224 +27339 ./prep_dataset/ILSVRC2012_val_00019589.bin 224 224 +27340 ./prep_dataset/ILSVRC2012_val_00037894.bin 224 224 +27341 ./prep_dataset/ILSVRC2012_val_00017312.bin 224 224 +27342 ./prep_dataset/ILSVRC2012_val_00026828.bin 224 224 +27343 ./prep_dataset/ILSVRC2012_val_00012466.bin 224 224 +27344 ./prep_dataset/ILSVRC2012_val_00012951.bin 224 224 +27345 ./prep_dataset/ILSVRC2012_val_00022168.bin 224 224 +27346 ./prep_dataset/ILSVRC2012_val_00015617.bin 224 224 +27347 ./prep_dataset/ILSVRC2012_val_00029702.bin 224 224 +27348 ./prep_dataset/ILSVRC2012_val_00049383.bin 224 224 +27349 ./prep_dataset/ILSVRC2012_val_00041467.bin 224 224 +27350 ./prep_dataset/ILSVRC2012_val_00026460.bin 224 224 +27351 ./prep_dataset/ILSVRC2012_val_00009688.bin 224 224 +27352 ./prep_dataset/ILSVRC2012_val_00014509.bin 224 224 +27353 ./prep_dataset/ILSVRC2012_val_00009021.bin 224 224 +27354 ./prep_dataset/ILSVRC2012_val_00047627.bin 224 224 +27355 ./prep_dataset/ILSVRC2012_val_00025597.bin 224 224 +27356 ./prep_dataset/ILSVRC2012_val_00028461.bin 224 224 +27357 ./prep_dataset/ILSVRC2012_val_00000577.bin 224 224 +27358 ./prep_dataset/ILSVRC2012_val_00047603.bin 224 224 +27359 ./prep_dataset/ILSVRC2012_val_00043979.bin 224 224 +27360 ./prep_dataset/ILSVRC2012_val_00012218.bin 224 224 +27361 ./prep_dataset/ILSVRC2012_val_00016936.bin 224 224 +27362 ./prep_dataset/ILSVRC2012_val_00035441.bin 224 224 +27363 ./prep_dataset/ILSVRC2012_val_00008315.bin 224 224 +27364 ./prep_dataset/ILSVRC2012_val_00029312.bin 224 224 +27365 ./prep_dataset/ILSVRC2012_val_00001117.bin 224 224 +27366 ./prep_dataset/ILSVRC2012_val_00014004.bin 224 224 +27367 ./prep_dataset/ILSVRC2012_val_00043913.bin 224 224 +27368 ./prep_dataset/ILSVRC2012_val_00008986.bin 224 224 +27369 ./prep_dataset/ILSVRC2012_val_00018102.bin 224 224 +27370 ./prep_dataset/ILSVRC2012_val_00018204.bin 224 224 +27371 ./prep_dataset/ILSVRC2012_val_00011192.bin 224 224 +27372 ./prep_dataset/ILSVRC2012_val_00044648.bin 224 224 +27373 ./prep_dataset/ILSVRC2012_val_00018646.bin 224 224 +27374 ./prep_dataset/ILSVRC2012_val_00044146.bin 224 224 +27375 ./prep_dataset/ILSVRC2012_val_00015957.bin 224 224 +27376 ./prep_dataset/ILSVRC2012_val_00041410.bin 224 224 +27377 ./prep_dataset/ILSVRC2012_val_00043460.bin 224 224 +27378 ./prep_dataset/ILSVRC2012_val_00001522.bin 224 224 +27379 ./prep_dataset/ILSVRC2012_val_00042081.bin 224 224 +27380 ./prep_dataset/ILSVRC2012_val_00027152.bin 224 224 +27381 ./prep_dataset/ILSVRC2012_val_00018349.bin 224 224 +27382 ./prep_dataset/ILSVRC2012_val_00016028.bin 224 224 +27383 ./prep_dataset/ILSVRC2012_val_00017099.bin 224 224 +27384 ./prep_dataset/ILSVRC2012_val_00033670.bin 224 224 +27385 ./prep_dataset/ILSVRC2012_val_00034785.bin 224 224 +27386 ./prep_dataset/ILSVRC2012_val_00025155.bin 224 224 +27387 ./prep_dataset/ILSVRC2012_val_00010853.bin 224 224 +27388 ./prep_dataset/ILSVRC2012_val_00037170.bin 224 224 +27389 ./prep_dataset/ILSVRC2012_val_00028261.bin 224 224 +27390 ./prep_dataset/ILSVRC2012_val_00041429.bin 224 224 +27391 ./prep_dataset/ILSVRC2012_val_00042122.bin 224 224 +27392 ./prep_dataset/ILSVRC2012_val_00026229.bin 224 224 +27393 ./prep_dataset/ILSVRC2012_val_00039133.bin 224 224 +27394 ./prep_dataset/ILSVRC2012_val_00022206.bin 224 224 +27395 ./prep_dataset/ILSVRC2012_val_00013169.bin 224 224 +27396 ./prep_dataset/ILSVRC2012_val_00009287.bin 224 224 +27397 ./prep_dataset/ILSVRC2012_val_00001343.bin 224 224 +27398 ./prep_dataset/ILSVRC2012_val_00047032.bin 224 224 +27399 ./prep_dataset/ILSVRC2012_val_00023616.bin 224 224 +27400 ./prep_dataset/ILSVRC2012_val_00007931.bin 224 224 +27401 ./prep_dataset/ILSVRC2012_val_00033534.bin 224 224 +27402 ./prep_dataset/ILSVRC2012_val_00020605.bin 224 224 +27403 ./prep_dataset/ILSVRC2012_val_00018249.bin 224 224 +27404 ./prep_dataset/ILSVRC2012_val_00009863.bin 224 224 +27405 ./prep_dataset/ILSVRC2012_val_00012998.bin 224 224 +27406 ./prep_dataset/ILSVRC2012_val_00017491.bin 224 224 +27407 ./prep_dataset/ILSVRC2012_val_00010026.bin 224 224 +27408 ./prep_dataset/ILSVRC2012_val_00046982.bin 224 224 +27409 ./prep_dataset/ILSVRC2012_val_00021794.bin 224 224 +27410 ./prep_dataset/ILSVRC2012_val_00011812.bin 224 224 +27411 ./prep_dataset/ILSVRC2012_val_00037689.bin 224 224 +27412 ./prep_dataset/ILSVRC2012_val_00033415.bin 224 224 +27413 ./prep_dataset/ILSVRC2012_val_00003511.bin 224 224 +27414 ./prep_dataset/ILSVRC2012_val_00025432.bin 224 224 +27415 ./prep_dataset/ILSVRC2012_val_00035238.bin 224 224 +27416 ./prep_dataset/ILSVRC2012_val_00016774.bin 224 224 +27417 ./prep_dataset/ILSVRC2012_val_00016885.bin 224 224 +27418 ./prep_dataset/ILSVRC2012_val_00015586.bin 224 224 +27419 ./prep_dataset/ILSVRC2012_val_00029243.bin 224 224 +27420 ./prep_dataset/ILSVRC2012_val_00048890.bin 224 224 +27421 ./prep_dataset/ILSVRC2012_val_00027547.bin 224 224 +27422 ./prep_dataset/ILSVRC2012_val_00047796.bin 224 224 +27423 ./prep_dataset/ILSVRC2012_val_00046288.bin 224 224 +27424 ./prep_dataset/ILSVRC2012_val_00045665.bin 224 224 +27425 ./prep_dataset/ILSVRC2012_val_00047217.bin 224 224 +27426 ./prep_dataset/ILSVRC2012_val_00022772.bin 224 224 +27427 ./prep_dataset/ILSVRC2012_val_00035352.bin 224 224 +27428 ./prep_dataset/ILSVRC2012_val_00023886.bin 224 224 +27429 ./prep_dataset/ILSVRC2012_val_00045561.bin 224 224 +27430 ./prep_dataset/ILSVRC2012_val_00039939.bin 224 224 +27431 ./prep_dataset/ILSVRC2012_val_00006088.bin 224 224 +27432 ./prep_dataset/ILSVRC2012_val_00003090.bin 224 224 +27433 ./prep_dataset/ILSVRC2012_val_00020696.bin 224 224 +27434 ./prep_dataset/ILSVRC2012_val_00001990.bin 224 224 +27435 ./prep_dataset/ILSVRC2012_val_00002606.bin 224 224 +27436 ./prep_dataset/ILSVRC2012_val_00025044.bin 224 224 +27437 ./prep_dataset/ILSVRC2012_val_00018636.bin 224 224 +27438 ./prep_dataset/ILSVRC2012_val_00038700.bin 224 224 +27439 ./prep_dataset/ILSVRC2012_val_00013135.bin 224 224 +27440 ./prep_dataset/ILSVRC2012_val_00043667.bin 224 224 +27441 ./prep_dataset/ILSVRC2012_val_00007836.bin 224 224 +27442 ./prep_dataset/ILSVRC2012_val_00017584.bin 224 224 +27443 ./prep_dataset/ILSVRC2012_val_00005419.bin 224 224 +27444 ./prep_dataset/ILSVRC2012_val_00008215.bin 224 224 +27445 ./prep_dataset/ILSVRC2012_val_00042838.bin 224 224 +27446 ./prep_dataset/ILSVRC2012_val_00034244.bin 224 224 +27447 ./prep_dataset/ILSVRC2012_val_00010566.bin 224 224 +27448 ./prep_dataset/ILSVRC2012_val_00021336.bin 224 224 +27449 ./prep_dataset/ILSVRC2012_val_00016630.bin 224 224 +27450 ./prep_dataset/ILSVRC2012_val_00029917.bin 224 224 +27451 ./prep_dataset/ILSVRC2012_val_00037090.bin 224 224 +27452 ./prep_dataset/ILSVRC2012_val_00028107.bin 224 224 +27453 ./prep_dataset/ILSVRC2012_val_00033121.bin 224 224 +27454 ./prep_dataset/ILSVRC2012_val_00006119.bin 224 224 +27455 ./prep_dataset/ILSVRC2012_val_00030855.bin 224 224 +27456 ./prep_dataset/ILSVRC2012_val_00034976.bin 224 224 +27457 ./prep_dataset/ILSVRC2012_val_00040543.bin 224 224 +27458 ./prep_dataset/ILSVRC2012_val_00020617.bin 224 224 +27459 ./prep_dataset/ILSVRC2012_val_00008732.bin 224 224 +27460 ./prep_dataset/ILSVRC2012_val_00022455.bin 224 224 +27461 ./prep_dataset/ILSVRC2012_val_00028791.bin 224 224 +27462 ./prep_dataset/ILSVRC2012_val_00034980.bin 224 224 +27463 ./prep_dataset/ILSVRC2012_val_00048343.bin 224 224 +27464 ./prep_dataset/ILSVRC2012_val_00046354.bin 224 224 +27465 ./prep_dataset/ILSVRC2012_val_00034707.bin 224 224 +27466 ./prep_dataset/ILSVRC2012_val_00033465.bin 224 224 +27467 ./prep_dataset/ILSVRC2012_val_00039108.bin 224 224 +27468 ./prep_dataset/ILSVRC2012_val_00009391.bin 224 224 +27469 ./prep_dataset/ILSVRC2012_val_00003293.bin 224 224 +27470 ./prep_dataset/ILSVRC2012_val_00042720.bin 224 224 +27471 ./prep_dataset/ILSVRC2012_val_00018770.bin 224 224 +27472 ./prep_dataset/ILSVRC2012_val_00036360.bin 224 224 +27473 ./prep_dataset/ILSVRC2012_val_00041701.bin 224 224 +27474 ./prep_dataset/ILSVRC2012_val_00006087.bin 224 224 +27475 ./prep_dataset/ILSVRC2012_val_00029701.bin 224 224 +27476 ./prep_dataset/ILSVRC2012_val_00037130.bin 224 224 +27477 ./prep_dataset/ILSVRC2012_val_00037020.bin 224 224 +27478 ./prep_dataset/ILSVRC2012_val_00019310.bin 224 224 +27479 ./prep_dataset/ILSVRC2012_val_00034404.bin 224 224 +27480 ./prep_dataset/ILSVRC2012_val_00009781.bin 224 224 +27481 ./prep_dataset/ILSVRC2012_val_00037405.bin 224 224 +27482 ./prep_dataset/ILSVRC2012_val_00007261.bin 224 224 +27483 ./prep_dataset/ILSVRC2012_val_00033221.bin 224 224 +27484 ./prep_dataset/ILSVRC2012_val_00046223.bin 224 224 +27485 ./prep_dataset/ILSVRC2012_val_00022462.bin 224 224 +27486 ./prep_dataset/ILSVRC2012_val_00022018.bin 224 224 +27487 ./prep_dataset/ILSVRC2012_val_00037649.bin 224 224 +27488 ./prep_dataset/ILSVRC2012_val_00002032.bin 224 224 +27489 ./prep_dataset/ILSVRC2012_val_00030712.bin 224 224 +27490 ./prep_dataset/ILSVRC2012_val_00042529.bin 224 224 +27491 ./prep_dataset/ILSVRC2012_val_00043530.bin 224 224 +27492 ./prep_dataset/ILSVRC2012_val_00034122.bin 224 224 +27493 ./prep_dataset/ILSVRC2012_val_00049743.bin 224 224 +27494 ./prep_dataset/ILSVRC2012_val_00029766.bin 224 224 +27495 ./prep_dataset/ILSVRC2012_val_00027986.bin 224 224 +27496 ./prep_dataset/ILSVRC2012_val_00027263.bin 224 224 +27497 ./prep_dataset/ILSVRC2012_val_00039437.bin 224 224 +27498 ./prep_dataset/ILSVRC2012_val_00029609.bin 224 224 +27499 ./prep_dataset/ILSVRC2012_val_00047442.bin 224 224 +27500 ./prep_dataset/ILSVRC2012_val_00016646.bin 224 224 +27501 ./prep_dataset/ILSVRC2012_val_00019391.bin 224 224 +27502 ./prep_dataset/ILSVRC2012_val_00013537.bin 224 224 +27503 ./prep_dataset/ILSVRC2012_val_00016621.bin 224 224 +27504 ./prep_dataset/ILSVRC2012_val_00017803.bin 224 224 +27505 ./prep_dataset/ILSVRC2012_val_00042777.bin 224 224 +27506 ./prep_dataset/ILSVRC2012_val_00022385.bin 224 224 +27507 ./prep_dataset/ILSVRC2012_val_00025291.bin 224 224 +27508 ./prep_dataset/ILSVRC2012_val_00005855.bin 224 224 +27509 ./prep_dataset/ILSVRC2012_val_00024403.bin 224 224 +27510 ./prep_dataset/ILSVRC2012_val_00006013.bin 224 224 +27511 ./prep_dataset/ILSVRC2012_val_00006728.bin 224 224 +27512 ./prep_dataset/ILSVRC2012_val_00019854.bin 224 224 +27513 ./prep_dataset/ILSVRC2012_val_00006022.bin 224 224 +27514 ./prep_dataset/ILSVRC2012_val_00003114.bin 224 224 +27515 ./prep_dataset/ILSVRC2012_val_00017380.bin 224 224 +27516 ./prep_dataset/ILSVRC2012_val_00017748.bin 224 224 +27517 ./prep_dataset/ILSVRC2012_val_00011909.bin 224 224 +27518 ./prep_dataset/ILSVRC2012_val_00013481.bin 224 224 +27519 ./prep_dataset/ILSVRC2012_val_00025676.bin 224 224 +27520 ./prep_dataset/ILSVRC2012_val_00010094.bin 224 224 +27521 ./prep_dataset/ILSVRC2012_val_00043377.bin 224 224 +27522 ./prep_dataset/ILSVRC2012_val_00040802.bin 224 224 +27523 ./prep_dataset/ILSVRC2012_val_00034008.bin 224 224 +27524 ./prep_dataset/ILSVRC2012_val_00026847.bin 224 224 +27525 ./prep_dataset/ILSVRC2012_val_00006903.bin 224 224 +27526 ./prep_dataset/ILSVRC2012_val_00046649.bin 224 224 +27527 ./prep_dataset/ILSVRC2012_val_00009636.bin 224 224 +27528 ./prep_dataset/ILSVRC2012_val_00040216.bin 224 224 +27529 ./prep_dataset/ILSVRC2012_val_00002630.bin 224 224 +27530 ./prep_dataset/ILSVRC2012_val_00020618.bin 224 224 +27531 ./prep_dataset/ILSVRC2012_val_00011222.bin 224 224 +27532 ./prep_dataset/ILSVRC2012_val_00038921.bin 224 224 +27533 ./prep_dataset/ILSVRC2012_val_00020134.bin 224 224 +27534 ./prep_dataset/ILSVRC2012_val_00024349.bin 224 224 +27535 ./prep_dataset/ILSVRC2012_val_00011166.bin 224 224 +27536 ./prep_dataset/ILSVRC2012_val_00029282.bin 224 224 +27537 ./prep_dataset/ILSVRC2012_val_00049138.bin 224 224 +27538 ./prep_dataset/ILSVRC2012_val_00036222.bin 224 224 +27539 ./prep_dataset/ILSVRC2012_val_00036546.bin 224 224 +27540 ./prep_dataset/ILSVRC2012_val_00036224.bin 224 224 +27541 ./prep_dataset/ILSVRC2012_val_00024111.bin 224 224 +27542 ./prep_dataset/ILSVRC2012_val_00032443.bin 224 224 +27543 ./prep_dataset/ILSVRC2012_val_00016124.bin 224 224 +27544 ./prep_dataset/ILSVRC2012_val_00043194.bin 224 224 +27545 ./prep_dataset/ILSVRC2012_val_00009171.bin 224 224 +27546 ./prep_dataset/ILSVRC2012_val_00024467.bin 224 224 +27547 ./prep_dataset/ILSVRC2012_val_00022300.bin 224 224 +27548 ./prep_dataset/ILSVRC2012_val_00033438.bin 224 224 +27549 ./prep_dataset/ILSVRC2012_val_00014430.bin 224 224 +27550 ./prep_dataset/ILSVRC2012_val_00045753.bin 224 224 +27551 ./prep_dataset/ILSVRC2012_val_00047982.bin 224 224 +27552 ./prep_dataset/ILSVRC2012_val_00028206.bin 224 224 +27553 ./prep_dataset/ILSVRC2012_val_00044006.bin 224 224 +27554 ./prep_dataset/ILSVRC2012_val_00046122.bin 224 224 +27555 ./prep_dataset/ILSVRC2012_val_00017654.bin 224 224 +27556 ./prep_dataset/ILSVRC2012_val_00020132.bin 224 224 +27557 ./prep_dataset/ILSVRC2012_val_00049842.bin 224 224 +27558 ./prep_dataset/ILSVRC2012_val_00028889.bin 224 224 +27559 ./prep_dataset/ILSVRC2012_val_00035398.bin 224 224 +27560 ./prep_dataset/ILSVRC2012_val_00043777.bin 224 224 +27561 ./prep_dataset/ILSVRC2012_val_00031915.bin 224 224 +27562 ./prep_dataset/ILSVRC2012_val_00004496.bin 224 224 +27563 ./prep_dataset/ILSVRC2012_val_00034467.bin 224 224 +27564 ./prep_dataset/ILSVRC2012_val_00034484.bin 224 224 +27565 ./prep_dataset/ILSVRC2012_val_00037635.bin 224 224 +27566 ./prep_dataset/ILSVRC2012_val_00006588.bin 224 224 +27567 ./prep_dataset/ILSVRC2012_val_00025947.bin 224 224 +27568 ./prep_dataset/ILSVRC2012_val_00013797.bin 224 224 +27569 ./prep_dataset/ILSVRC2012_val_00024093.bin 224 224 +27570 ./prep_dataset/ILSVRC2012_val_00006765.bin 224 224 +27571 ./prep_dataset/ILSVRC2012_val_00005885.bin 224 224 +27572 ./prep_dataset/ILSVRC2012_val_00043463.bin 224 224 +27573 ./prep_dataset/ILSVRC2012_val_00005339.bin 224 224 +27574 ./prep_dataset/ILSVRC2012_val_00029536.bin 224 224 +27575 ./prep_dataset/ILSVRC2012_val_00011688.bin 224 224 +27576 ./prep_dataset/ILSVRC2012_val_00027999.bin 224 224 +27577 ./prep_dataset/ILSVRC2012_val_00043608.bin 224 224 +27578 ./prep_dataset/ILSVRC2012_val_00008943.bin 224 224 +27579 ./prep_dataset/ILSVRC2012_val_00007018.bin 224 224 +27580 ./prep_dataset/ILSVRC2012_val_00035154.bin 224 224 +27581 ./prep_dataset/ILSVRC2012_val_00012467.bin 224 224 +27582 ./prep_dataset/ILSVRC2012_val_00028891.bin 224 224 +27583 ./prep_dataset/ILSVRC2012_val_00003889.bin 224 224 +27584 ./prep_dataset/ILSVRC2012_val_00001299.bin 224 224 +27585 ./prep_dataset/ILSVRC2012_val_00045168.bin 224 224 +27586 ./prep_dataset/ILSVRC2012_val_00044594.bin 224 224 +27587 ./prep_dataset/ILSVRC2012_val_00040605.bin 224 224 +27588 ./prep_dataset/ILSVRC2012_val_00041743.bin 224 224 +27589 ./prep_dataset/ILSVRC2012_val_00002283.bin 224 224 +27590 ./prep_dataset/ILSVRC2012_val_00000663.bin 224 224 +27591 ./prep_dataset/ILSVRC2012_val_00006669.bin 224 224 +27592 ./prep_dataset/ILSVRC2012_val_00003933.bin 224 224 +27593 ./prep_dataset/ILSVRC2012_val_00025757.bin 224 224 +27594 ./prep_dataset/ILSVRC2012_val_00034931.bin 224 224 +27595 ./prep_dataset/ILSVRC2012_val_00038631.bin 224 224 +27596 ./prep_dataset/ILSVRC2012_val_00031760.bin 224 224 +27597 ./prep_dataset/ILSVRC2012_val_00011657.bin 224 224 +27598 ./prep_dataset/ILSVRC2012_val_00045045.bin 224 224 +27599 ./prep_dataset/ILSVRC2012_val_00037934.bin 224 224 +27600 ./prep_dataset/ILSVRC2012_val_00003834.bin 224 224 +27601 ./prep_dataset/ILSVRC2012_val_00014007.bin 224 224 +27602 ./prep_dataset/ILSVRC2012_val_00003722.bin 224 224 +27603 ./prep_dataset/ILSVRC2012_val_00002608.bin 224 224 +27604 ./prep_dataset/ILSVRC2012_val_00045991.bin 224 224 +27605 ./prep_dataset/ILSVRC2012_val_00027672.bin 224 224 +27606 ./prep_dataset/ILSVRC2012_val_00024812.bin 224 224 +27607 ./prep_dataset/ILSVRC2012_val_00021849.bin 224 224 +27608 ./prep_dataset/ILSVRC2012_val_00001508.bin 224 224 +27609 ./prep_dataset/ILSVRC2012_val_00009834.bin 224 224 +27610 ./prep_dataset/ILSVRC2012_val_00042124.bin 224 224 +27611 ./prep_dataset/ILSVRC2012_val_00032780.bin 224 224 +27612 ./prep_dataset/ILSVRC2012_val_00002839.bin 224 224 +27613 ./prep_dataset/ILSVRC2012_val_00011310.bin 224 224 +27614 ./prep_dataset/ILSVRC2012_val_00019277.bin 224 224 +27615 ./prep_dataset/ILSVRC2012_val_00038645.bin 224 224 +27616 ./prep_dataset/ILSVRC2012_val_00008460.bin 224 224 +27617 ./prep_dataset/ILSVRC2012_val_00029332.bin 224 224 +27618 ./prep_dataset/ILSVRC2012_val_00006164.bin 224 224 +27619 ./prep_dataset/ILSVRC2012_val_00026000.bin 224 224 +27620 ./prep_dataset/ILSVRC2012_val_00039763.bin 224 224 +27621 ./prep_dataset/ILSVRC2012_val_00037531.bin 224 224 +27622 ./prep_dataset/ILSVRC2012_val_00000720.bin 224 224 +27623 ./prep_dataset/ILSVRC2012_val_00046722.bin 224 224 +27624 ./prep_dataset/ILSVRC2012_val_00035164.bin 224 224 +27625 ./prep_dataset/ILSVRC2012_val_00034318.bin 224 224 +27626 ./prep_dataset/ILSVRC2012_val_00036400.bin 224 224 +27627 ./prep_dataset/ILSVRC2012_val_00012540.bin 224 224 +27628 ./prep_dataset/ILSVRC2012_val_00041118.bin 224 224 +27629 ./prep_dataset/ILSVRC2012_val_00033109.bin 224 224 +27630 ./prep_dataset/ILSVRC2012_val_00014372.bin 224 224 +27631 ./prep_dataset/ILSVRC2012_val_00020719.bin 224 224 +27632 ./prep_dataset/ILSVRC2012_val_00047477.bin 224 224 +27633 ./prep_dataset/ILSVRC2012_val_00034953.bin 224 224 +27634 ./prep_dataset/ILSVRC2012_val_00008364.bin 224 224 +27635 ./prep_dataset/ILSVRC2012_val_00007235.bin 224 224 +27636 ./prep_dataset/ILSVRC2012_val_00037506.bin 224 224 +27637 ./prep_dataset/ILSVRC2012_val_00005777.bin 224 224 +27638 ./prep_dataset/ILSVRC2012_val_00033832.bin 224 224 +27639 ./prep_dataset/ILSVRC2012_val_00032454.bin 224 224 +27640 ./prep_dataset/ILSVRC2012_val_00039293.bin 224 224 +27641 ./prep_dataset/ILSVRC2012_val_00006591.bin 224 224 +27642 ./prep_dataset/ILSVRC2012_val_00020445.bin 224 224 +27643 ./prep_dataset/ILSVRC2012_val_00042272.bin 224 224 +27644 ./prep_dataset/ILSVRC2012_val_00006877.bin 224 224 +27645 ./prep_dataset/ILSVRC2012_val_00023207.bin 224 224 +27646 ./prep_dataset/ILSVRC2012_val_00024131.bin 224 224 +27647 ./prep_dataset/ILSVRC2012_val_00039740.bin 224 224 +27648 ./prep_dataset/ILSVRC2012_val_00029921.bin 224 224 +27649 ./prep_dataset/ILSVRC2012_val_00020155.bin 224 224 +27650 ./prep_dataset/ILSVRC2012_val_00045092.bin 224 224 +27651 ./prep_dataset/ILSVRC2012_val_00013625.bin 224 224 +27652 ./prep_dataset/ILSVRC2012_val_00028670.bin 224 224 +27653 ./prep_dataset/ILSVRC2012_val_00030086.bin 224 224 +27654 ./prep_dataset/ILSVRC2012_val_00018168.bin 224 224 +27655 ./prep_dataset/ILSVRC2012_val_00025920.bin 224 224 +27656 ./prep_dataset/ILSVRC2012_val_00036507.bin 224 224 +27657 ./prep_dataset/ILSVRC2012_val_00028388.bin 224 224 +27658 ./prep_dataset/ILSVRC2012_val_00041160.bin 224 224 +27659 ./prep_dataset/ILSVRC2012_val_00033830.bin 224 224 +27660 ./prep_dataset/ILSVRC2012_val_00026925.bin 224 224 +27661 ./prep_dataset/ILSVRC2012_val_00026040.bin 224 224 +27662 ./prep_dataset/ILSVRC2012_val_00022313.bin 224 224 +27663 ./prep_dataset/ILSVRC2012_val_00049496.bin 224 224 +27664 ./prep_dataset/ILSVRC2012_val_00005112.bin 224 224 +27665 ./prep_dataset/ILSVRC2012_val_00015331.bin 224 224 +27666 ./prep_dataset/ILSVRC2012_val_00040787.bin 224 224 +27667 ./prep_dataset/ILSVRC2012_val_00014949.bin 224 224 +27668 ./prep_dataset/ILSVRC2012_val_00047626.bin 224 224 +27669 ./prep_dataset/ILSVRC2012_val_00022820.bin 224 224 +27670 ./prep_dataset/ILSVRC2012_val_00041660.bin 224 224 +27671 ./prep_dataset/ILSVRC2012_val_00000207.bin 224 224 +27672 ./prep_dataset/ILSVRC2012_val_00002157.bin 224 224 +27673 ./prep_dataset/ILSVRC2012_val_00037666.bin 224 224 +27674 ./prep_dataset/ILSVRC2012_val_00011919.bin 224 224 +27675 ./prep_dataset/ILSVRC2012_val_00043659.bin 224 224 +27676 ./prep_dataset/ILSVRC2012_val_00003238.bin 224 224 +27677 ./prep_dataset/ILSVRC2012_val_00030990.bin 224 224 +27678 ./prep_dataset/ILSVRC2012_val_00037156.bin 224 224 +27679 ./prep_dataset/ILSVRC2012_val_00016797.bin 224 224 +27680 ./prep_dataset/ILSVRC2012_val_00044625.bin 224 224 +27681 ./prep_dataset/ILSVRC2012_val_00024525.bin 224 224 +27682 ./prep_dataset/ILSVRC2012_val_00019129.bin 224 224 +27683 ./prep_dataset/ILSVRC2012_val_00029361.bin 224 224 +27684 ./prep_dataset/ILSVRC2012_val_00010652.bin 224 224 +27685 ./prep_dataset/ILSVRC2012_val_00003084.bin 224 224 +27686 ./prep_dataset/ILSVRC2012_val_00039607.bin 224 224 +27687 ./prep_dataset/ILSVRC2012_val_00033567.bin 224 224 +27688 ./prep_dataset/ILSVRC2012_val_00017041.bin 224 224 +27689 ./prep_dataset/ILSVRC2012_val_00007231.bin 224 224 +27690 ./prep_dataset/ILSVRC2012_val_00027954.bin 224 224 +27691 ./prep_dataset/ILSVRC2012_val_00022868.bin 224 224 +27692 ./prep_dataset/ILSVRC2012_val_00024684.bin 224 224 +27693 ./prep_dataset/ILSVRC2012_val_00042036.bin 224 224 +27694 ./prep_dataset/ILSVRC2012_val_00006961.bin 224 224 +27695 ./prep_dataset/ILSVRC2012_val_00034326.bin 224 224 +27696 ./prep_dataset/ILSVRC2012_val_00033902.bin 224 224 +27697 ./prep_dataset/ILSVRC2012_val_00000362.bin 224 224 +27698 ./prep_dataset/ILSVRC2012_val_00016524.bin 224 224 +27699 ./prep_dataset/ILSVRC2012_val_00036886.bin 224 224 +27700 ./prep_dataset/ILSVRC2012_val_00045770.bin 224 224 +27701 ./prep_dataset/ILSVRC2012_val_00024696.bin 224 224 +27702 ./prep_dataset/ILSVRC2012_val_00035619.bin 224 224 +27703 ./prep_dataset/ILSVRC2012_val_00009555.bin 224 224 +27704 ./prep_dataset/ILSVRC2012_val_00033244.bin 224 224 +27705 ./prep_dataset/ILSVRC2012_val_00016336.bin 224 224 +27706 ./prep_dataset/ILSVRC2012_val_00038270.bin 224 224 +27707 ./prep_dataset/ILSVRC2012_val_00029934.bin 224 224 +27708 ./prep_dataset/ILSVRC2012_val_00001751.bin 224 224 +27709 ./prep_dataset/ILSVRC2012_val_00016438.bin 224 224 +27710 ./prep_dataset/ILSVRC2012_val_00034622.bin 224 224 +27711 ./prep_dataset/ILSVRC2012_val_00036707.bin 224 224 +27712 ./prep_dataset/ILSVRC2012_val_00012705.bin 224 224 +27713 ./prep_dataset/ILSVRC2012_val_00012573.bin 224 224 +27714 ./prep_dataset/ILSVRC2012_val_00003396.bin 224 224 +27715 ./prep_dataset/ILSVRC2012_val_00013676.bin 224 224 +27716 ./prep_dataset/ILSVRC2012_val_00043420.bin 224 224 +27717 ./prep_dataset/ILSVRC2012_val_00005447.bin 224 224 +27718 ./prep_dataset/ILSVRC2012_val_00032564.bin 224 224 +27719 ./prep_dataset/ILSVRC2012_val_00039797.bin 224 224 +27720 ./prep_dataset/ILSVRC2012_val_00022363.bin 224 224 +27721 ./prep_dataset/ILSVRC2012_val_00033075.bin 224 224 +27722 ./prep_dataset/ILSVRC2012_val_00013062.bin 224 224 +27723 ./prep_dataset/ILSVRC2012_val_00032619.bin 224 224 +27724 ./prep_dataset/ILSVRC2012_val_00034781.bin 224 224 +27725 ./prep_dataset/ILSVRC2012_val_00027333.bin 224 224 +27726 ./prep_dataset/ILSVRC2012_val_00026124.bin 224 224 +27727 ./prep_dataset/ILSVRC2012_val_00023557.bin 224 224 +27728 ./prep_dataset/ILSVRC2012_val_00012261.bin 224 224 +27729 ./prep_dataset/ILSVRC2012_val_00029192.bin 224 224 +27730 ./prep_dataset/ILSVRC2012_val_00011545.bin 224 224 +27731 ./prep_dataset/ILSVRC2012_val_00015381.bin 224 224 +27732 ./prep_dataset/ILSVRC2012_val_00018310.bin 224 224 +27733 ./prep_dataset/ILSVRC2012_val_00042716.bin 224 224 +27734 ./prep_dataset/ILSVRC2012_val_00014794.bin 224 224 +27735 ./prep_dataset/ILSVRC2012_val_00045447.bin 224 224 +27736 ./prep_dataset/ILSVRC2012_val_00038849.bin 224 224 +27737 ./prep_dataset/ILSVRC2012_val_00028348.bin 224 224 +27738 ./prep_dataset/ILSVRC2012_val_00021393.bin 224 224 +27739 ./prep_dataset/ILSVRC2012_val_00038372.bin 224 224 +27740 ./prep_dataset/ILSVRC2012_val_00031840.bin 224 224 +27741 ./prep_dataset/ILSVRC2012_val_00029975.bin 224 224 +27742 ./prep_dataset/ILSVRC2012_val_00008957.bin 224 224 +27743 ./prep_dataset/ILSVRC2012_val_00002527.bin 224 224 +27744 ./prep_dataset/ILSVRC2012_val_00009713.bin 224 224 +27745 ./prep_dataset/ILSVRC2012_val_00045167.bin 224 224 +27746 ./prep_dataset/ILSVRC2012_val_00033049.bin 224 224 +27747 ./prep_dataset/ILSVRC2012_val_00011209.bin 224 224 +27748 ./prep_dataset/ILSVRC2012_val_00040473.bin 224 224 +27749 ./prep_dataset/ILSVRC2012_val_00048128.bin 224 224 +27750 ./prep_dataset/ILSVRC2012_val_00008781.bin 224 224 +27751 ./prep_dataset/ILSVRC2012_val_00039757.bin 224 224 +27752 ./prep_dataset/ILSVRC2012_val_00040417.bin 224 224 +27753 ./prep_dataset/ILSVRC2012_val_00018041.bin 224 224 +27754 ./prep_dataset/ILSVRC2012_val_00034451.bin 224 224 +27755 ./prep_dataset/ILSVRC2012_val_00009706.bin 224 224 +27756 ./prep_dataset/ILSVRC2012_val_00010968.bin 224 224 +27757 ./prep_dataset/ILSVRC2012_val_00008286.bin 224 224 +27758 ./prep_dataset/ILSVRC2012_val_00021333.bin 224 224 +27759 ./prep_dataset/ILSVRC2012_val_00032555.bin 224 224 +27760 ./prep_dataset/ILSVRC2012_val_00022079.bin 224 224 +27761 ./prep_dataset/ILSVRC2012_val_00037846.bin 224 224 +27762 ./prep_dataset/ILSVRC2012_val_00030488.bin 224 224 +27763 ./prep_dataset/ILSVRC2012_val_00045967.bin 224 224 +27764 ./prep_dataset/ILSVRC2012_val_00034895.bin 224 224 +27765 ./prep_dataset/ILSVRC2012_val_00026494.bin 224 224 +27766 ./prep_dataset/ILSVRC2012_val_00045553.bin 224 224 +27767 ./prep_dataset/ILSVRC2012_val_00019136.bin 224 224 +27768 ./prep_dataset/ILSVRC2012_val_00004092.bin 224 224 +27769 ./prep_dataset/ILSVRC2012_val_00027073.bin 224 224 +27770 ./prep_dataset/ILSVRC2012_val_00041010.bin 224 224 +27771 ./prep_dataset/ILSVRC2012_val_00009887.bin 224 224 +27772 ./prep_dataset/ILSVRC2012_val_00032496.bin 224 224 +27773 ./prep_dataset/ILSVRC2012_val_00037256.bin 224 224 +27774 ./prep_dataset/ILSVRC2012_val_00024771.bin 224 224 +27775 ./prep_dataset/ILSVRC2012_val_00011683.bin 224 224 +27776 ./prep_dataset/ILSVRC2012_val_00015530.bin 224 224 +27777 ./prep_dataset/ILSVRC2012_val_00013045.bin 224 224 +27778 ./prep_dataset/ILSVRC2012_val_00039567.bin 224 224 +27779 ./prep_dataset/ILSVRC2012_val_00009458.bin 224 224 +27780 ./prep_dataset/ILSVRC2012_val_00016359.bin 224 224 +27781 ./prep_dataset/ILSVRC2012_val_00027569.bin 224 224 +27782 ./prep_dataset/ILSVRC2012_val_00031397.bin 224 224 +27783 ./prep_dataset/ILSVRC2012_val_00039979.bin 224 224 +27784 ./prep_dataset/ILSVRC2012_val_00003818.bin 224 224 +27785 ./prep_dataset/ILSVRC2012_val_00038430.bin 224 224 +27786 ./prep_dataset/ILSVRC2012_val_00026844.bin 224 224 +27787 ./prep_dataset/ILSVRC2012_val_00043566.bin 224 224 +27788 ./prep_dataset/ILSVRC2012_val_00000715.bin 224 224 +27789 ./prep_dataset/ILSVRC2012_val_00035196.bin 224 224 +27790 ./prep_dataset/ILSVRC2012_val_00041908.bin 224 224 +27791 ./prep_dataset/ILSVRC2012_val_00004652.bin 224 224 +27792 ./prep_dataset/ILSVRC2012_val_00017251.bin 224 224 +27793 ./prep_dataset/ILSVRC2012_val_00026944.bin 224 224 +27794 ./prep_dataset/ILSVRC2012_val_00012841.bin 224 224 +27795 ./prep_dataset/ILSVRC2012_val_00015181.bin 224 224 +27796 ./prep_dataset/ILSVRC2012_val_00048713.bin 224 224 +27797 ./prep_dataset/ILSVRC2012_val_00008842.bin 224 224 +27798 ./prep_dataset/ILSVRC2012_val_00008980.bin 224 224 +27799 ./prep_dataset/ILSVRC2012_val_00045138.bin 224 224 +27800 ./prep_dataset/ILSVRC2012_val_00032285.bin 224 224 +27801 ./prep_dataset/ILSVRC2012_val_00012250.bin 224 224 +27802 ./prep_dataset/ILSVRC2012_val_00001554.bin 224 224 +27803 ./prep_dataset/ILSVRC2012_val_00001767.bin 224 224 +27804 ./prep_dataset/ILSVRC2012_val_00042456.bin 224 224 +27805 ./prep_dataset/ILSVRC2012_val_00039743.bin 224 224 +27806 ./prep_dataset/ILSVRC2012_val_00036287.bin 224 224 +27807 ./prep_dataset/ILSVRC2012_val_00034601.bin 224 224 +27808 ./prep_dataset/ILSVRC2012_val_00032731.bin 224 224 +27809 ./prep_dataset/ILSVRC2012_val_00030793.bin 224 224 +27810 ./prep_dataset/ILSVRC2012_val_00027706.bin 224 224 +27811 ./prep_dataset/ILSVRC2012_val_00033122.bin 224 224 +27812 ./prep_dataset/ILSVRC2012_val_00037808.bin 224 224 +27813 ./prep_dataset/ILSVRC2012_val_00000631.bin 224 224 +27814 ./prep_dataset/ILSVRC2012_val_00018328.bin 224 224 +27815 ./prep_dataset/ILSVRC2012_val_00012272.bin 224 224 +27816 ./prep_dataset/ILSVRC2012_val_00021346.bin 224 224 +27817 ./prep_dataset/ILSVRC2012_val_00019172.bin 224 224 +27818 ./prep_dataset/ILSVRC2012_val_00035829.bin 224 224 +27819 ./prep_dataset/ILSVRC2012_val_00048842.bin 224 224 +27820 ./prep_dataset/ILSVRC2012_val_00036872.bin 224 224 +27821 ./prep_dataset/ILSVRC2012_val_00047415.bin 224 224 +27822 ./prep_dataset/ILSVRC2012_val_00022927.bin 224 224 +27823 ./prep_dataset/ILSVRC2012_val_00042924.bin 224 224 +27824 ./prep_dataset/ILSVRC2012_val_00008688.bin 224 224 +27825 ./prep_dataset/ILSVRC2012_val_00006351.bin 224 224 +27826 ./prep_dataset/ILSVRC2012_val_00032870.bin 224 224 +27827 ./prep_dataset/ILSVRC2012_val_00004788.bin 224 224 +27828 ./prep_dataset/ILSVRC2012_val_00030438.bin 224 224 +27829 ./prep_dataset/ILSVRC2012_val_00033995.bin 224 224 +27830 ./prep_dataset/ILSVRC2012_val_00024420.bin 224 224 +27831 ./prep_dataset/ILSVRC2012_val_00021265.bin 224 224 +27832 ./prep_dataset/ILSVRC2012_val_00000032.bin 224 224 +27833 ./prep_dataset/ILSVRC2012_val_00007137.bin 224 224 +27834 ./prep_dataset/ILSVRC2012_val_00002834.bin 224 224 +27835 ./prep_dataset/ILSVRC2012_val_00008782.bin 224 224 +27836 ./prep_dataset/ILSVRC2012_val_00045354.bin 224 224 +27837 ./prep_dataset/ILSVRC2012_val_00042324.bin 224 224 +27838 ./prep_dataset/ILSVRC2012_val_00000414.bin 224 224 +27839 ./prep_dataset/ILSVRC2012_val_00040136.bin 224 224 +27840 ./prep_dataset/ILSVRC2012_val_00016109.bin 224 224 +27841 ./prep_dataset/ILSVRC2012_val_00038827.bin 224 224 +27842 ./prep_dataset/ILSVRC2012_val_00035999.bin 224 224 +27843 ./prep_dataset/ILSVRC2012_val_00033700.bin 224 224 +27844 ./prep_dataset/ILSVRC2012_val_00015605.bin 224 224 +27845 ./prep_dataset/ILSVRC2012_val_00033219.bin 224 224 +27846 ./prep_dataset/ILSVRC2012_val_00004346.bin 224 224 +27847 ./prep_dataset/ILSVRC2012_val_00027449.bin 224 224 +27848 ./prep_dataset/ILSVRC2012_val_00025347.bin 224 224 +27849 ./prep_dataset/ILSVRC2012_val_00004061.bin 224 224 +27850 ./prep_dataset/ILSVRC2012_val_00037774.bin 224 224 +27851 ./prep_dataset/ILSVRC2012_val_00041601.bin 224 224 +27852 ./prep_dataset/ILSVRC2012_val_00003113.bin 224 224 +27853 ./prep_dataset/ILSVRC2012_val_00009974.bin 224 224 +27854 ./prep_dataset/ILSVRC2012_val_00031423.bin 224 224 +27855 ./prep_dataset/ILSVRC2012_val_00034355.bin 224 224 +27856 ./prep_dataset/ILSVRC2012_val_00021686.bin 224 224 +27857 ./prep_dataset/ILSVRC2012_val_00046829.bin 224 224 +27858 ./prep_dataset/ILSVRC2012_val_00016353.bin 224 224 +27859 ./prep_dataset/ILSVRC2012_val_00018152.bin 224 224 +27860 ./prep_dataset/ILSVRC2012_val_00007071.bin 224 224 +27861 ./prep_dataset/ILSVRC2012_val_00010346.bin 224 224 +27862 ./prep_dataset/ILSVRC2012_val_00036162.bin 224 224 +27863 ./prep_dataset/ILSVRC2012_val_00029351.bin 224 224 +27864 ./prep_dataset/ILSVRC2012_val_00011138.bin 224 224 +27865 ./prep_dataset/ILSVRC2012_val_00036758.bin 224 224 +27866 ./prep_dataset/ILSVRC2012_val_00021774.bin 224 224 +27867 ./prep_dataset/ILSVRC2012_val_00043801.bin 224 224 +27868 ./prep_dataset/ILSVRC2012_val_00020038.bin 224 224 +27869 ./prep_dataset/ILSVRC2012_val_00026303.bin 224 224 +27870 ./prep_dataset/ILSVRC2012_val_00030061.bin 224 224 +27871 ./prep_dataset/ILSVRC2012_val_00022418.bin 224 224 +27872 ./prep_dataset/ILSVRC2012_val_00039563.bin 224 224 +27873 ./prep_dataset/ILSVRC2012_val_00005471.bin 224 224 +27874 ./prep_dataset/ILSVRC2012_val_00019533.bin 224 224 +27875 ./prep_dataset/ILSVRC2012_val_00040561.bin 224 224 +27876 ./prep_dataset/ILSVRC2012_val_00005732.bin 224 224 +27877 ./prep_dataset/ILSVRC2012_val_00007892.bin 224 224 +27878 ./prep_dataset/ILSVRC2012_val_00030414.bin 224 224 +27879 ./prep_dataset/ILSVRC2012_val_00034613.bin 224 224 +27880 ./prep_dataset/ILSVRC2012_val_00012854.bin 224 224 +27881 ./prep_dataset/ILSVRC2012_val_00019581.bin 224 224 +27882 ./prep_dataset/ILSVRC2012_val_00003686.bin 224 224 +27883 ./prep_dataset/ILSVRC2012_val_00049432.bin 224 224 +27884 ./prep_dataset/ILSVRC2012_val_00013181.bin 224 224 +27885 ./prep_dataset/ILSVRC2012_val_00029538.bin 224 224 +27886 ./prep_dataset/ILSVRC2012_val_00000945.bin 224 224 +27887 ./prep_dataset/ILSVRC2012_val_00021959.bin 224 224 +27888 ./prep_dataset/ILSVRC2012_val_00045351.bin 224 224 +27889 ./prep_dataset/ILSVRC2012_val_00036952.bin 224 224 +27890 ./prep_dataset/ILSVRC2012_val_00032186.bin 224 224 +27891 ./prep_dataset/ILSVRC2012_val_00039989.bin 224 224 +27892 ./prep_dataset/ILSVRC2012_val_00042936.bin 224 224 +27893 ./prep_dataset/ILSVRC2012_val_00019772.bin 224 224 +27894 ./prep_dataset/ILSVRC2012_val_00024555.bin 224 224 +27895 ./prep_dataset/ILSVRC2012_val_00043258.bin 224 224 +27896 ./prep_dataset/ILSVRC2012_val_00041293.bin 224 224 +27897 ./prep_dataset/ILSVRC2012_val_00022602.bin 224 224 +27898 ./prep_dataset/ILSVRC2012_val_00047016.bin 224 224 +27899 ./prep_dataset/ILSVRC2012_val_00012762.bin 224 224 +27900 ./prep_dataset/ILSVRC2012_val_00028391.bin 224 224 +27901 ./prep_dataset/ILSVRC2012_val_00017326.bin 224 224 +27902 ./prep_dataset/ILSVRC2012_val_00023444.bin 224 224 +27903 ./prep_dataset/ILSVRC2012_val_00002030.bin 224 224 +27904 ./prep_dataset/ILSVRC2012_val_00037639.bin 224 224 +27905 ./prep_dataset/ILSVRC2012_val_00045791.bin 224 224 +27906 ./prep_dataset/ILSVRC2012_val_00043416.bin 224 224 +27907 ./prep_dataset/ILSVRC2012_val_00009985.bin 224 224 +27908 ./prep_dataset/ILSVRC2012_val_00040210.bin 224 224 +27909 ./prep_dataset/ILSVRC2012_val_00007540.bin 224 224 +27910 ./prep_dataset/ILSVRC2012_val_00037062.bin 224 224 +27911 ./prep_dataset/ILSVRC2012_val_00011513.bin 224 224 +27912 ./prep_dataset/ILSVRC2012_val_00031393.bin 224 224 +27913 ./prep_dataset/ILSVRC2012_val_00046236.bin 224 224 +27914 ./prep_dataset/ILSVRC2012_val_00029728.bin 224 224 +27915 ./prep_dataset/ILSVRC2012_val_00005602.bin 224 224 +27916 ./prep_dataset/ILSVRC2012_val_00008056.bin 224 224 +27917 ./prep_dataset/ILSVRC2012_val_00048188.bin 224 224 +27918 ./prep_dataset/ILSVRC2012_val_00001979.bin 224 224 +27919 ./prep_dataset/ILSVRC2012_val_00023472.bin 224 224 +27920 ./prep_dataset/ILSVRC2012_val_00023040.bin 224 224 +27921 ./prep_dataset/ILSVRC2012_val_00010775.bin 224 224 +27922 ./prep_dataset/ILSVRC2012_val_00005459.bin 224 224 +27923 ./prep_dataset/ILSVRC2012_val_00026304.bin 224 224 +27924 ./prep_dataset/ILSVRC2012_val_00019521.bin 224 224 +27925 ./prep_dataset/ILSVRC2012_val_00000039.bin 224 224 +27926 ./prep_dataset/ILSVRC2012_val_00039702.bin 224 224 +27927 ./prep_dataset/ILSVRC2012_val_00035883.bin 224 224 +27928 ./prep_dataset/ILSVRC2012_val_00015346.bin 224 224 +27929 ./prep_dataset/ILSVRC2012_val_00022954.bin 224 224 +27930 ./prep_dataset/ILSVRC2012_val_00014416.bin 224 224 +27931 ./prep_dataset/ILSVRC2012_val_00043437.bin 224 224 +27932 ./prep_dataset/ILSVRC2012_val_00016831.bin 224 224 +27933 ./prep_dataset/ILSVRC2012_val_00013506.bin 224 224 +27934 ./prep_dataset/ILSVRC2012_val_00001937.bin 224 224 +27935 ./prep_dataset/ILSVRC2012_val_00011243.bin 224 224 +27936 ./prep_dataset/ILSVRC2012_val_00034907.bin 224 224 +27937 ./prep_dataset/ILSVRC2012_val_00012037.bin 224 224 +27938 ./prep_dataset/ILSVRC2012_val_00030046.bin 224 224 +27939 ./prep_dataset/ILSVRC2012_val_00005315.bin 224 224 +27940 ./prep_dataset/ILSVRC2012_val_00016748.bin 224 224 +27941 ./prep_dataset/ILSVRC2012_val_00041339.bin 224 224 +27942 ./prep_dataset/ILSVRC2012_val_00042865.bin 224 224 +27943 ./prep_dataset/ILSVRC2012_val_00007766.bin 224 224 +27944 ./prep_dataset/ILSVRC2012_val_00047452.bin 224 224 +27945 ./prep_dataset/ILSVRC2012_val_00016597.bin 224 224 +27946 ./prep_dataset/ILSVRC2012_val_00000608.bin 224 224 +27947 ./prep_dataset/ILSVRC2012_val_00039281.bin 224 224 +27948 ./prep_dataset/ILSVRC2012_val_00012796.bin 224 224 +27949 ./prep_dataset/ILSVRC2012_val_00015518.bin 224 224 +27950 ./prep_dataset/ILSVRC2012_val_00022895.bin 224 224 +27951 ./prep_dataset/ILSVRC2012_val_00004018.bin 224 224 +27952 ./prep_dataset/ILSVRC2012_val_00049416.bin 224 224 +27953 ./prep_dataset/ILSVRC2012_val_00006795.bin 224 224 +27954 ./prep_dataset/ILSVRC2012_val_00036549.bin 224 224 +27955 ./prep_dataset/ILSVRC2012_val_00014620.bin 224 224 +27956 ./prep_dataset/ILSVRC2012_val_00040604.bin 224 224 +27957 ./prep_dataset/ILSVRC2012_val_00000388.bin 224 224 +27958 ./prep_dataset/ILSVRC2012_val_00026456.bin 224 224 +27959 ./prep_dataset/ILSVRC2012_val_00043325.bin 224 224 +27960 ./prep_dataset/ILSVRC2012_val_00030992.bin 224 224 +27961 ./prep_dataset/ILSVRC2012_val_00020785.bin 224 224 +27962 ./prep_dataset/ILSVRC2012_val_00021178.bin 224 224 +27963 ./prep_dataset/ILSVRC2012_val_00021571.bin 224 224 +27964 ./prep_dataset/ILSVRC2012_val_00012598.bin 224 224 +27965 ./prep_dataset/ILSVRC2012_val_00038306.bin 224 224 +27966 ./prep_dataset/ILSVRC2012_val_00030776.bin 224 224 +27967 ./prep_dataset/ILSVRC2012_val_00027842.bin 224 224 +27968 ./prep_dataset/ILSVRC2012_val_00002860.bin 224 224 +27969 ./prep_dataset/ILSVRC2012_val_00045347.bin 224 224 +27970 ./prep_dataset/ILSVRC2012_val_00047465.bin 224 224 +27971 ./prep_dataset/ILSVRC2012_val_00023176.bin 224 224 +27972 ./prep_dataset/ILSVRC2012_val_00000500.bin 224 224 +27973 ./prep_dataset/ILSVRC2012_val_00047323.bin 224 224 +27974 ./prep_dataset/ILSVRC2012_val_00024223.bin 224 224 +27975 ./prep_dataset/ILSVRC2012_val_00029612.bin 224 224 +27976 ./prep_dataset/ILSVRC2012_val_00018397.bin 224 224 +27977 ./prep_dataset/ILSVRC2012_val_00023229.bin 224 224 +27978 ./prep_dataset/ILSVRC2012_val_00022100.bin 224 224 +27979 ./prep_dataset/ILSVRC2012_val_00041559.bin 224 224 +27980 ./prep_dataset/ILSVRC2012_val_00017880.bin 224 224 +27981 ./prep_dataset/ILSVRC2012_val_00049039.bin 224 224 +27982 ./prep_dataset/ILSVRC2012_val_00038829.bin 224 224 +27983 ./prep_dataset/ILSVRC2012_val_00040168.bin 224 224 +27984 ./prep_dataset/ILSVRC2012_val_00018830.bin 224 224 +27985 ./prep_dataset/ILSVRC2012_val_00034568.bin 224 224 +27986 ./prep_dataset/ILSVRC2012_val_00003562.bin 224 224 +27987 ./prep_dataset/ILSVRC2012_val_00018879.bin 224 224 +27988 ./prep_dataset/ILSVRC2012_val_00017288.bin 224 224 +27989 ./prep_dataset/ILSVRC2012_val_00035162.bin 224 224 +27990 ./prep_dataset/ILSVRC2012_val_00002693.bin 224 224 +27991 ./prep_dataset/ILSVRC2012_val_00006213.bin 224 224 +27992 ./prep_dataset/ILSVRC2012_val_00000654.bin 224 224 +27993 ./prep_dataset/ILSVRC2012_val_00011609.bin 224 224 +27994 ./prep_dataset/ILSVRC2012_val_00048628.bin 224 224 +27995 ./prep_dataset/ILSVRC2012_val_00001481.bin 224 224 +27996 ./prep_dataset/ILSVRC2012_val_00016037.bin 224 224 +27997 ./prep_dataset/ILSVRC2012_val_00009319.bin 224 224 +27998 ./prep_dataset/ILSVRC2012_val_00035707.bin 224 224 +27999 ./prep_dataset/ILSVRC2012_val_00022617.bin 224 224 +28000 ./prep_dataset/ILSVRC2012_val_00017548.bin 224 224 +28001 ./prep_dataset/ILSVRC2012_val_00003665.bin 224 224 +28002 ./prep_dataset/ILSVRC2012_val_00035763.bin 224 224 +28003 ./prep_dataset/ILSVRC2012_val_00019423.bin 224 224 +28004 ./prep_dataset/ILSVRC2012_val_00030440.bin 224 224 +28005 ./prep_dataset/ILSVRC2012_val_00013474.bin 224 224 +28006 ./prep_dataset/ILSVRC2012_val_00018207.bin 224 224 +28007 ./prep_dataset/ILSVRC2012_val_00016214.bin 224 224 +28008 ./prep_dataset/ILSVRC2012_val_00028237.bin 224 224 +28009 ./prep_dataset/ILSVRC2012_val_00034477.bin 224 224 +28010 ./prep_dataset/ILSVRC2012_val_00028801.bin 224 224 +28011 ./prep_dataset/ILSVRC2012_val_00005024.bin 224 224 +28012 ./prep_dataset/ILSVRC2012_val_00044054.bin 224 224 +28013 ./prep_dataset/ILSVRC2012_val_00021362.bin 224 224 +28014 ./prep_dataset/ILSVRC2012_val_00013018.bin 224 224 +28015 ./prep_dataset/ILSVRC2012_val_00001052.bin 224 224 +28016 ./prep_dataset/ILSVRC2012_val_00031174.bin 224 224 +28017 ./prep_dataset/ILSVRC2012_val_00025017.bin 224 224 +28018 ./prep_dataset/ILSVRC2012_val_00049624.bin 224 224 +28019 ./prep_dataset/ILSVRC2012_val_00047708.bin 224 224 +28020 ./prep_dataset/ILSVRC2012_val_00001903.bin 224 224 +28021 ./prep_dataset/ILSVRC2012_val_00007196.bin 224 224 +28022 ./prep_dataset/ILSVRC2012_val_00027266.bin 224 224 +28023 ./prep_dataset/ILSVRC2012_val_00029560.bin 224 224 +28024 ./prep_dataset/ILSVRC2012_val_00000106.bin 224 224 +28025 ./prep_dataset/ILSVRC2012_val_00000651.bin 224 224 +28026 ./prep_dataset/ILSVRC2012_val_00022067.bin 224 224 +28027 ./prep_dataset/ILSVRC2012_val_00039021.bin 224 224 +28028 ./prep_dataset/ILSVRC2012_val_00032414.bin 224 224 +28029 ./prep_dataset/ILSVRC2012_val_00035349.bin 224 224 +28030 ./prep_dataset/ILSVRC2012_val_00030734.bin 224 224 +28031 ./prep_dataset/ILSVRC2012_val_00015128.bin 224 224 +28032 ./prep_dataset/ILSVRC2012_val_00025101.bin 224 224 +28033 ./prep_dataset/ILSVRC2012_val_00026813.bin 224 224 +28034 ./prep_dataset/ILSVRC2012_val_00048928.bin 224 224 +28035 ./prep_dataset/ILSVRC2012_val_00040060.bin 224 224 +28036 ./prep_dataset/ILSVRC2012_val_00009295.bin 224 224 +28037 ./prep_dataset/ILSVRC2012_val_00013642.bin 224 224 +28038 ./prep_dataset/ILSVRC2012_val_00024340.bin 224 224 +28039 ./prep_dataset/ILSVRC2012_val_00023205.bin 224 224 +28040 ./prep_dataset/ILSVRC2012_val_00013808.bin 224 224 +28041 ./prep_dataset/ILSVRC2012_val_00026652.bin 224 224 +28042 ./prep_dataset/ILSVRC2012_val_00024486.bin 224 224 +28043 ./prep_dataset/ILSVRC2012_val_00042258.bin 224 224 +28044 ./prep_dataset/ILSVRC2012_val_00030520.bin 224 224 +28045 ./prep_dataset/ILSVRC2012_val_00034812.bin 224 224 +28046 ./prep_dataset/ILSVRC2012_val_00027863.bin 224 224 +28047 ./prep_dataset/ILSVRC2012_val_00030124.bin 224 224 +28048 ./prep_dataset/ILSVRC2012_val_00049397.bin 224 224 +28049 ./prep_dataset/ILSVRC2012_val_00025532.bin 224 224 +28050 ./prep_dataset/ILSVRC2012_val_00040871.bin 224 224 +28051 ./prep_dataset/ILSVRC2012_val_00044708.bin 224 224 +28052 ./prep_dataset/ILSVRC2012_val_00030279.bin 224 224 +28053 ./prep_dataset/ILSVRC2012_val_00042466.bin 224 224 +28054 ./prep_dataset/ILSVRC2012_val_00012525.bin 224 224 +28055 ./prep_dataset/ILSVRC2012_val_00006420.bin 224 224 +28056 ./prep_dataset/ILSVRC2012_val_00000834.bin 224 224 +28057 ./prep_dataset/ILSVRC2012_val_00006279.bin 224 224 +28058 ./prep_dataset/ILSVRC2012_val_00040548.bin 224 224 +28059 ./prep_dataset/ILSVRC2012_val_00000640.bin 224 224 +28060 ./prep_dataset/ILSVRC2012_val_00005677.bin 224 224 +28061 ./prep_dataset/ILSVRC2012_val_00036505.bin 224 224 +28062 ./prep_dataset/ILSVRC2012_val_00043998.bin 224 224 +28063 ./prep_dataset/ILSVRC2012_val_00032536.bin 224 224 +28064 ./prep_dataset/ILSVRC2012_val_00023949.bin 224 224 +28065 ./prep_dataset/ILSVRC2012_val_00047570.bin 224 224 +28066 ./prep_dataset/ILSVRC2012_val_00038840.bin 224 224 +28067 ./prep_dataset/ILSVRC2012_val_00039221.bin 224 224 +28068 ./prep_dataset/ILSVRC2012_val_00012938.bin 224 224 +28069 ./prep_dataset/ILSVRC2012_val_00035679.bin 224 224 +28070 ./prep_dataset/ILSVRC2012_val_00010657.bin 224 224 +28071 ./prep_dataset/ILSVRC2012_val_00029185.bin 224 224 +28072 ./prep_dataset/ILSVRC2012_val_00010766.bin 224 224 +28073 ./prep_dataset/ILSVRC2012_val_00043681.bin 224 224 +28074 ./prep_dataset/ILSVRC2012_val_00009910.bin 224 224 +28075 ./prep_dataset/ILSVRC2012_val_00049761.bin 224 224 +28076 ./prep_dataset/ILSVRC2012_val_00043909.bin 224 224 +28077 ./prep_dataset/ILSVRC2012_val_00000045.bin 224 224 +28078 ./prep_dataset/ILSVRC2012_val_00018091.bin 224 224 +28079 ./prep_dataset/ILSVRC2012_val_00027300.bin 224 224 +28080 ./prep_dataset/ILSVRC2012_val_00005912.bin 224 224 +28081 ./prep_dataset/ILSVRC2012_val_00035328.bin 224 224 +28082 ./prep_dataset/ILSVRC2012_val_00011642.bin 224 224 +28083 ./prep_dataset/ILSVRC2012_val_00009953.bin 224 224 +28084 ./prep_dataset/ILSVRC2012_val_00027276.bin 224 224 +28085 ./prep_dataset/ILSVRC2012_val_00014017.bin 224 224 +28086 ./prep_dataset/ILSVRC2012_val_00049095.bin 224 224 +28087 ./prep_dataset/ILSVRC2012_val_00028234.bin 224 224 +28088 ./prep_dataset/ILSVRC2012_val_00033919.bin 224 224 +28089 ./prep_dataset/ILSVRC2012_val_00013428.bin 224 224 +28090 ./prep_dataset/ILSVRC2012_val_00021374.bin 224 224 +28091 ./prep_dataset/ILSVRC2012_val_00031015.bin 224 224 +28092 ./prep_dataset/ILSVRC2012_val_00014865.bin 224 224 +28093 ./prep_dataset/ILSVRC2012_val_00042150.bin 224 224 +28094 ./prep_dataset/ILSVRC2012_val_00013047.bin 224 224 +28095 ./prep_dataset/ILSVRC2012_val_00044210.bin 224 224 +28096 ./prep_dataset/ILSVRC2012_val_00043226.bin 224 224 +28097 ./prep_dataset/ILSVRC2012_val_00035985.bin 224 224 +28098 ./prep_dataset/ILSVRC2012_val_00049027.bin 224 224 +28099 ./prep_dataset/ILSVRC2012_val_00004872.bin 224 224 +28100 ./prep_dataset/ILSVRC2012_val_00006228.bin 224 224 +28101 ./prep_dataset/ILSVRC2012_val_00041965.bin 224 224 +28102 ./prep_dataset/ILSVRC2012_val_00008510.bin 224 224 +28103 ./prep_dataset/ILSVRC2012_val_00023921.bin 224 224 +28104 ./prep_dataset/ILSVRC2012_val_00007771.bin 224 224 +28105 ./prep_dataset/ILSVRC2012_val_00023686.bin 224 224 +28106 ./prep_dataset/ILSVRC2012_val_00006714.bin 224 224 +28107 ./prep_dataset/ILSVRC2012_val_00022865.bin 224 224 +28108 ./prep_dataset/ILSVRC2012_val_00005811.bin 224 224 +28109 ./prep_dataset/ILSVRC2012_val_00016527.bin 224 224 +28110 ./prep_dataset/ILSVRC2012_val_00017331.bin 224 224 +28111 ./prep_dataset/ILSVRC2012_val_00021756.bin 224 224 +28112 ./prep_dataset/ILSVRC2012_val_00043366.bin 224 224 +28113 ./prep_dataset/ILSVRC2012_val_00033134.bin 224 224 +28114 ./prep_dataset/ILSVRC2012_val_00000975.bin 224 224 +28115 ./prep_dataset/ILSVRC2012_val_00008606.bin 224 224 +28116 ./prep_dataset/ILSVRC2012_val_00034147.bin 224 224 +28117 ./prep_dataset/ILSVRC2012_val_00033110.bin 224 224 +28118 ./prep_dataset/ILSVRC2012_val_00006672.bin 224 224 +28119 ./prep_dataset/ILSVRC2012_val_00042971.bin 224 224 +28120 ./prep_dataset/ILSVRC2012_val_00024680.bin 224 224 +28121 ./prep_dataset/ILSVRC2012_val_00042426.bin 224 224 +28122 ./prep_dataset/ILSVRC2012_val_00038626.bin 224 224 +28123 ./prep_dataset/ILSVRC2012_val_00028382.bin 224 224 +28124 ./prep_dataset/ILSVRC2012_val_00039630.bin 224 224 +28125 ./prep_dataset/ILSVRC2012_val_00032560.bin 224 224 +28126 ./prep_dataset/ILSVRC2012_val_00041573.bin 224 224 +28127 ./prep_dataset/ILSVRC2012_val_00015204.bin 224 224 +28128 ./prep_dataset/ILSVRC2012_val_00009397.bin 224 224 +28129 ./prep_dataset/ILSVRC2012_val_00029452.bin 224 224 +28130 ./prep_dataset/ILSVRC2012_val_00019467.bin 224 224 +28131 ./prep_dataset/ILSVRC2012_val_00009422.bin 224 224 +28132 ./prep_dataset/ILSVRC2012_val_00012530.bin 224 224 +28133 ./prep_dataset/ILSVRC2012_val_00015329.bin 224 224 +28134 ./prep_dataset/ILSVRC2012_val_00020853.bin 224 224 +28135 ./prep_dataset/ILSVRC2012_val_00044050.bin 224 224 +28136 ./prep_dataset/ILSVRC2012_val_00004647.bin 224 224 +28137 ./prep_dataset/ILSVRC2012_val_00022351.bin 224 224 +28138 ./prep_dataset/ILSVRC2012_val_00025510.bin 224 224 +28139 ./prep_dataset/ILSVRC2012_val_00001352.bin 224 224 +28140 ./prep_dataset/ILSVRC2012_val_00015564.bin 224 224 +28141 ./prep_dataset/ILSVRC2012_val_00033773.bin 224 224 +28142 ./prep_dataset/ILSVRC2012_val_00037288.bin 224 224 +28143 ./prep_dataset/ILSVRC2012_val_00046215.bin 224 224 +28144 ./prep_dataset/ILSVRC2012_val_00037671.bin 224 224 +28145 ./prep_dataset/ILSVRC2012_val_00024280.bin 224 224 +28146 ./prep_dataset/ILSVRC2012_val_00043968.bin 224 224 +28147 ./prep_dataset/ILSVRC2012_val_00007302.bin 224 224 +28148 ./prep_dataset/ILSVRC2012_val_00038132.bin 224 224 +28149 ./prep_dataset/ILSVRC2012_val_00001519.bin 224 224 +28150 ./prep_dataset/ILSVRC2012_val_00012706.bin 224 224 +28151 ./prep_dataset/ILSVRC2012_val_00017009.bin 224 224 +28152 ./prep_dataset/ILSVRC2012_val_00015125.bin 224 224 +28153 ./prep_dataset/ILSVRC2012_val_00005429.bin 224 224 +28154 ./prep_dataset/ILSVRC2012_val_00020957.bin 224 224 +28155 ./prep_dataset/ILSVRC2012_val_00027080.bin 224 224 +28156 ./prep_dataset/ILSVRC2012_val_00034513.bin 224 224 +28157 ./prep_dataset/ILSVRC2012_val_00003278.bin 224 224 +28158 ./prep_dataset/ILSVRC2012_val_00007169.bin 224 224 +28159 ./prep_dataset/ILSVRC2012_val_00018675.bin 224 224 +28160 ./prep_dataset/ILSVRC2012_val_00025238.bin 224 224 +28161 ./prep_dataset/ILSVRC2012_val_00036808.bin 224 224 +28162 ./prep_dataset/ILSVRC2012_val_00029580.bin 224 224 +28163 ./prep_dataset/ILSVRC2012_val_00023079.bin 224 224 +28164 ./prep_dataset/ILSVRC2012_val_00005004.bin 224 224 +28165 ./prep_dataset/ILSVRC2012_val_00042284.bin 224 224 +28166 ./prep_dataset/ILSVRC2012_val_00000641.bin 224 224 +28167 ./prep_dataset/ILSVRC2012_val_00003600.bin 224 224 +28168 ./prep_dataset/ILSVRC2012_val_00021368.bin 224 224 +28169 ./prep_dataset/ILSVRC2012_val_00011672.bin 224 224 +28170 ./prep_dataset/ILSVRC2012_val_00045860.bin 224 224 +28171 ./prep_dataset/ILSVRC2012_val_00004729.bin 224 224 +28172 ./prep_dataset/ILSVRC2012_val_00031262.bin 224 224 +28173 ./prep_dataset/ILSVRC2012_val_00025075.bin 224 224 +28174 ./prep_dataset/ILSVRC2012_val_00043459.bin 224 224 +28175 ./prep_dataset/ILSVRC2012_val_00038989.bin 224 224 +28176 ./prep_dataset/ILSVRC2012_val_00030314.bin 224 224 +28177 ./prep_dataset/ILSVRC2012_val_00000287.bin 224 224 +28178 ./prep_dataset/ILSVRC2012_val_00027141.bin 224 224 +28179 ./prep_dataset/ILSVRC2012_val_00040424.bin 224 224 +28180 ./prep_dataset/ILSVRC2012_val_00004521.bin 224 224 +28181 ./prep_dataset/ILSVRC2012_val_00007480.bin 224 224 +28182 ./prep_dataset/ILSVRC2012_val_00002537.bin 224 224 +28183 ./prep_dataset/ILSVRC2012_val_00009045.bin 224 224 +28184 ./prep_dataset/ILSVRC2012_val_00027905.bin 224 224 +28185 ./prep_dataset/ILSVRC2012_val_00035798.bin 224 224 +28186 ./prep_dataset/ILSVRC2012_val_00028647.bin 224 224 +28187 ./prep_dataset/ILSVRC2012_val_00015510.bin 224 224 +28188 ./prep_dataset/ILSVRC2012_val_00045767.bin 224 224 +28189 ./prep_dataset/ILSVRC2012_val_00009007.bin 224 224 +28190 ./prep_dataset/ILSVRC2012_val_00043288.bin 224 224 +28191 ./prep_dataset/ILSVRC2012_val_00036219.bin 224 224 +28192 ./prep_dataset/ILSVRC2012_val_00013467.bin 224 224 +28193 ./prep_dataset/ILSVRC2012_val_00043095.bin 224 224 +28194 ./prep_dataset/ILSVRC2012_val_00015162.bin 224 224 +28195 ./prep_dataset/ILSVRC2012_val_00034282.bin 224 224 +28196 ./prep_dataset/ILSVRC2012_val_00043056.bin 224 224 +28197 ./prep_dataset/ILSVRC2012_val_00003050.bin 224 224 +28198 ./prep_dataset/ILSVRC2012_val_00003892.bin 224 224 +28199 ./prep_dataset/ILSVRC2012_val_00012733.bin 224 224 +28200 ./prep_dataset/ILSVRC2012_val_00017623.bin 224 224 +28201 ./prep_dataset/ILSVRC2012_val_00043907.bin 224 224 +28202 ./prep_dataset/ILSVRC2012_val_00036190.bin 224 224 +28203 ./prep_dataset/ILSVRC2012_val_00012579.bin 224 224 +28204 ./prep_dataset/ILSVRC2012_val_00035487.bin 224 224 +28205 ./prep_dataset/ILSVRC2012_val_00049062.bin 224 224 +28206 ./prep_dataset/ILSVRC2012_val_00040681.bin 224 224 +28207 ./prep_dataset/ILSVRC2012_val_00016038.bin 224 224 +28208 ./prep_dataset/ILSVRC2012_val_00037736.bin 224 224 +28209 ./prep_dataset/ILSVRC2012_val_00000939.bin 224 224 +28210 ./prep_dataset/ILSVRC2012_val_00021259.bin 224 224 +28211 ./prep_dataset/ILSVRC2012_val_00007536.bin 224 224 +28212 ./prep_dataset/ILSVRC2012_val_00024155.bin 224 224 +28213 ./prep_dataset/ILSVRC2012_val_00046786.bin 224 224 +28214 ./prep_dataset/ILSVRC2012_val_00018064.bin 224 224 +28215 ./prep_dataset/ILSVRC2012_val_00047447.bin 224 224 +28216 ./prep_dataset/ILSVRC2012_val_00034574.bin 224 224 +28217 ./prep_dataset/ILSVRC2012_val_00041247.bin 224 224 +28218 ./prep_dataset/ILSVRC2012_val_00024230.bin 224 224 +28219 ./prep_dataset/ILSVRC2012_val_00019086.bin 224 224 +28220 ./prep_dataset/ILSVRC2012_val_00011348.bin 224 224 +28221 ./prep_dataset/ILSVRC2012_val_00016953.bin 224 224 +28222 ./prep_dataset/ILSVRC2012_val_00009828.bin 224 224 +28223 ./prep_dataset/ILSVRC2012_val_00036946.bin 224 224 +28224 ./prep_dataset/ILSVRC2012_val_00014152.bin 224 224 +28225 ./prep_dataset/ILSVRC2012_val_00007496.bin 224 224 +28226 ./prep_dataset/ILSVRC2012_val_00041038.bin 224 224 +28227 ./prep_dataset/ILSVRC2012_val_00011317.bin 224 224 +28228 ./prep_dataset/ILSVRC2012_val_00015221.bin 224 224 +28229 ./prep_dataset/ILSVRC2012_val_00016463.bin 224 224 +28230 ./prep_dataset/ILSVRC2012_val_00010407.bin 224 224 +28231 ./prep_dataset/ILSVRC2012_val_00036510.bin 224 224 +28232 ./prep_dataset/ILSVRC2012_val_00034292.bin 224 224 +28233 ./prep_dataset/ILSVRC2012_val_00026324.bin 224 224 +28234 ./prep_dataset/ILSVRC2012_val_00023849.bin 224 224 +28235 ./prep_dataset/ILSVRC2012_val_00013769.bin 224 224 +28236 ./prep_dataset/ILSVRC2012_val_00032080.bin 224 224 +28237 ./prep_dataset/ILSVRC2012_val_00048085.bin 224 224 +28238 ./prep_dataset/ILSVRC2012_val_00002955.bin 224 224 +28239 ./prep_dataset/ILSVRC2012_val_00038817.bin 224 224 +28240 ./prep_dataset/ILSVRC2012_val_00004997.bin 224 224 +28241 ./prep_dataset/ILSVRC2012_val_00006018.bin 224 224 +28242 ./prep_dataset/ILSVRC2012_val_00041520.bin 224 224 +28243 ./prep_dataset/ILSVRC2012_val_00000189.bin 224 224 +28244 ./prep_dataset/ILSVRC2012_val_00008822.bin 224 224 +28245 ./prep_dataset/ILSVRC2012_val_00024746.bin 224 224 +28246 ./prep_dataset/ILSVRC2012_val_00049079.bin 224 224 +28247 ./prep_dataset/ILSVRC2012_val_00040674.bin 224 224 +28248 ./prep_dataset/ILSVRC2012_val_00046080.bin 224 224 +28249 ./prep_dataset/ILSVRC2012_val_00027459.bin 224 224 +28250 ./prep_dataset/ILSVRC2012_val_00044630.bin 224 224 +28251 ./prep_dataset/ILSVRC2012_val_00019309.bin 224 224 +28252 ./prep_dataset/ILSVRC2012_val_00034113.bin 224 224 +28253 ./prep_dataset/ILSVRC2012_val_00044878.bin 224 224 +28254 ./prep_dataset/ILSVRC2012_val_00008721.bin 224 224 +28255 ./prep_dataset/ILSVRC2012_val_00015067.bin 224 224 +28256 ./prep_dataset/ILSVRC2012_val_00027974.bin 224 224 +28257 ./prep_dataset/ILSVRC2012_val_00035559.bin 224 224 +28258 ./prep_dataset/ILSVRC2012_val_00038469.bin 224 224 +28259 ./prep_dataset/ILSVRC2012_val_00047600.bin 224 224 +28260 ./prep_dataset/ILSVRC2012_val_00019907.bin 224 224 +28261 ./prep_dataset/ILSVRC2012_val_00008189.bin 224 224 +28262 ./prep_dataset/ILSVRC2012_val_00039316.bin 224 224 +28263 ./prep_dataset/ILSVRC2012_val_00006998.bin 224 224 +28264 ./prep_dataset/ILSVRC2012_val_00039230.bin 224 224 +28265 ./prep_dataset/ILSVRC2012_val_00010722.bin 224 224 +28266 ./prep_dataset/ILSVRC2012_val_00048752.bin 224 224 +28267 ./prep_dataset/ILSVRC2012_val_00034896.bin 224 224 +28268 ./prep_dataset/ILSVRC2012_val_00017883.bin 224 224 +28269 ./prep_dataset/ILSVRC2012_val_00044789.bin 224 224 +28270 ./prep_dataset/ILSVRC2012_val_00049962.bin 224 224 +28271 ./prep_dataset/ILSVRC2012_val_00029911.bin 224 224 +28272 ./prep_dataset/ILSVRC2012_val_00046704.bin 224 224 +28273 ./prep_dataset/ILSVRC2012_val_00023963.bin 224 224 +28274 ./prep_dataset/ILSVRC2012_val_00045670.bin 224 224 +28275 ./prep_dataset/ILSVRC2012_val_00002260.bin 224 224 +28276 ./prep_dataset/ILSVRC2012_val_00013866.bin 224 224 +28277 ./prep_dataset/ILSVRC2012_val_00019739.bin 224 224 +28278 ./prep_dataset/ILSVRC2012_val_00001629.bin 224 224 +28279 ./prep_dataset/ILSVRC2012_val_00028002.bin 224 224 +28280 ./prep_dataset/ILSVRC2012_val_00007596.bin 224 224 +28281 ./prep_dataset/ILSVRC2012_val_00007145.bin 224 224 +28282 ./prep_dataset/ILSVRC2012_val_00020443.bin 224 224 +28283 ./prep_dataset/ILSVRC2012_val_00006814.bin 224 224 +28284 ./prep_dataset/ILSVRC2012_val_00026541.bin 224 224 +28285 ./prep_dataset/ILSVRC2012_val_00043369.bin 224 224 +28286 ./prep_dataset/ILSVRC2012_val_00021766.bin 224 224 +28287 ./prep_dataset/ILSVRC2012_val_00037905.bin 224 224 +28288 ./prep_dataset/ILSVRC2012_val_00015059.bin 224 224 +28289 ./prep_dataset/ILSVRC2012_val_00017863.bin 224 224 +28290 ./prep_dataset/ILSVRC2012_val_00008554.bin 224 224 +28291 ./prep_dataset/ILSVRC2012_val_00002484.bin 224 224 +28292 ./prep_dataset/ILSVRC2012_val_00033623.bin 224 224 +28293 ./prep_dataset/ILSVRC2012_val_00021021.bin 224 224 +28294 ./prep_dataset/ILSVRC2012_val_00040748.bin 224 224 +28295 ./prep_dataset/ILSVRC2012_val_00006942.bin 224 224 +28296 ./prep_dataset/ILSVRC2012_val_00033545.bin 224 224 +28297 ./prep_dataset/ILSVRC2012_val_00033101.bin 224 224 +28298 ./prep_dataset/ILSVRC2012_val_00006326.bin 224 224 +28299 ./prep_dataset/ILSVRC2012_val_00015591.bin 224 224 +28300 ./prep_dataset/ILSVRC2012_val_00002859.bin 224 224 +28301 ./prep_dataset/ILSVRC2012_val_00039421.bin 224 224 +28302 ./prep_dataset/ILSVRC2012_val_00023979.bin 224 224 +28303 ./prep_dataset/ILSVRC2012_val_00009812.bin 224 224 +28304 ./prep_dataset/ILSVRC2012_val_00028024.bin 224 224 +28305 ./prep_dataset/ILSVRC2012_val_00009400.bin 224 224 +28306 ./prep_dataset/ILSVRC2012_val_00023835.bin 224 224 +28307 ./prep_dataset/ILSVRC2012_val_00045318.bin 224 224 +28308 ./prep_dataset/ILSVRC2012_val_00010056.bin 224 224 +28309 ./prep_dataset/ILSVRC2012_val_00013896.bin 224 224 +28310 ./prep_dataset/ILSVRC2012_val_00008924.bin 224 224 +28311 ./prep_dataset/ILSVRC2012_val_00009165.bin 224 224 +28312 ./prep_dataset/ILSVRC2012_val_00017955.bin 224 224 +28313 ./prep_dataset/ILSVRC2012_val_00020943.bin 224 224 +28314 ./prep_dataset/ILSVRC2012_val_00037051.bin 224 224 +28315 ./prep_dataset/ILSVRC2012_val_00010067.bin 224 224 +28316 ./prep_dataset/ILSVRC2012_val_00043079.bin 224 224 +28317 ./prep_dataset/ILSVRC2012_val_00013611.bin 224 224 +28318 ./prep_dataset/ILSVRC2012_val_00039608.bin 224 224 +28319 ./prep_dataset/ILSVRC2012_val_00028619.bin 224 224 +28320 ./prep_dataset/ILSVRC2012_val_00000014.bin 224 224 +28321 ./prep_dataset/ILSVRC2012_val_00021954.bin 224 224 +28322 ./prep_dataset/ILSVRC2012_val_00001403.bin 224 224 +28323 ./prep_dataset/ILSVRC2012_val_00012820.bin 224 224 +28324 ./prep_dataset/ILSVRC2012_val_00043025.bin 224 224 +28325 ./prep_dataset/ILSVRC2012_val_00029721.bin 224 224 +28326 ./prep_dataset/ILSVRC2012_val_00014226.bin 224 224 +28327 ./prep_dataset/ILSVRC2012_val_00004760.bin 224 224 +28328 ./prep_dataset/ILSVRC2012_val_00046835.bin 224 224 +28329 ./prep_dataset/ILSVRC2012_val_00018259.bin 224 224 +28330 ./prep_dataset/ILSVRC2012_val_00045031.bin 224 224 +28331 ./prep_dataset/ILSVRC2012_val_00038281.bin 224 224 +28332 ./prep_dataset/ILSVRC2012_val_00003003.bin 224 224 +28333 ./prep_dataset/ILSVRC2012_val_00045617.bin 224 224 +28334 ./prep_dataset/ILSVRC2012_val_00009996.bin 224 224 +28335 ./prep_dataset/ILSVRC2012_val_00001423.bin 224 224 +28336 ./prep_dataset/ILSVRC2012_val_00010378.bin 224 224 +28337 ./prep_dataset/ILSVRC2012_val_00011615.bin 224 224 +28338 ./prep_dataset/ILSVRC2012_val_00025076.bin 224 224 +28339 ./prep_dataset/ILSVRC2012_val_00019402.bin 224 224 +28340 ./prep_dataset/ILSVRC2012_val_00012020.bin 224 224 +28341 ./prep_dataset/ILSVRC2012_val_00029795.bin 224 224 +28342 ./prep_dataset/ILSVRC2012_val_00025547.bin 224 224 +28343 ./prep_dataset/ILSVRC2012_val_00014916.bin 224 224 +28344 ./prep_dataset/ILSVRC2012_val_00044538.bin 224 224 +28345 ./prep_dataset/ILSVRC2012_val_00032544.bin 224 224 +28346 ./prep_dataset/ILSVRC2012_val_00007592.bin 224 224 +28347 ./prep_dataset/ILSVRC2012_val_00014415.bin 224 224 +28348 ./prep_dataset/ILSVRC2012_val_00033649.bin 224 224 +28349 ./prep_dataset/ILSVRC2012_val_00027607.bin 224 224 +28350 ./prep_dataset/ILSVRC2012_val_00041719.bin 224 224 +28351 ./prep_dataset/ILSVRC2012_val_00027946.bin 224 224 +28352 ./prep_dataset/ILSVRC2012_val_00034174.bin 224 224 +28353 ./prep_dataset/ILSVRC2012_val_00032667.bin 224 224 +28354 ./prep_dataset/ILSVRC2012_val_00019159.bin 224 224 +28355 ./prep_dataset/ILSVRC2012_val_00022833.bin 224 224 +28356 ./prep_dataset/ILSVRC2012_val_00004361.bin 224 224 +28357 ./prep_dataset/ILSVRC2012_val_00013811.bin 224 224 +28358 ./prep_dataset/ILSVRC2012_val_00043447.bin 224 224 +28359 ./prep_dataset/ILSVRC2012_val_00006920.bin 224 224 +28360 ./prep_dataset/ILSVRC2012_val_00007711.bin 224 224 +28361 ./prep_dataset/ILSVRC2012_val_00003701.bin 224 224 +28362 ./prep_dataset/ILSVRC2012_val_00040990.bin 224 224 +28363 ./prep_dataset/ILSVRC2012_val_00046289.bin 224 224 +28364 ./prep_dataset/ILSVRC2012_val_00024382.bin 224 224 +28365 ./prep_dataset/ILSVRC2012_val_00026043.bin 224 224 +28366 ./prep_dataset/ILSVRC2012_val_00023918.bin 224 224 +28367 ./prep_dataset/ILSVRC2012_val_00033524.bin 224 224 +28368 ./prep_dataset/ILSVRC2012_val_00018271.bin 224 224 +28369 ./prep_dataset/ILSVRC2012_val_00005183.bin 224 224 +28370 ./prep_dataset/ILSVRC2012_val_00026629.bin 224 224 +28371 ./prep_dataset/ILSVRC2012_val_00034688.bin 224 224 +28372 ./prep_dataset/ILSVRC2012_val_00017188.bin 224 224 +28373 ./prep_dataset/ILSVRC2012_val_00048734.bin 224 224 +28374 ./prep_dataset/ILSVRC2012_val_00001586.bin 224 224 +28375 ./prep_dataset/ILSVRC2012_val_00004226.bin 224 224 +28376 ./prep_dataset/ILSVRC2012_val_00035029.bin 224 224 +28377 ./prep_dataset/ILSVRC2012_val_00028435.bin 224 224 +28378 ./prep_dataset/ILSVRC2012_val_00001533.bin 224 224 +28379 ./prep_dataset/ILSVRC2012_val_00043446.bin 224 224 +28380 ./prep_dataset/ILSVRC2012_val_00030236.bin 224 224 +28381 ./prep_dataset/ILSVRC2012_val_00038194.bin 224 224 +28382 ./prep_dataset/ILSVRC2012_val_00049725.bin 224 224 +28383 ./prep_dataset/ILSVRC2012_val_00037478.bin 224 224 +28384 ./prep_dataset/ILSVRC2012_val_00004591.bin 224 224 +28385 ./prep_dataset/ILSVRC2012_val_00008658.bin 224 224 +28386 ./prep_dataset/ILSVRC2012_val_00043409.bin 224 224 +28387 ./prep_dataset/ILSVRC2012_val_00037505.bin 224 224 +28388 ./prep_dataset/ILSVRC2012_val_00035451.bin 224 224 +28389 ./prep_dataset/ILSVRC2012_val_00030208.bin 224 224 +28390 ./prep_dataset/ILSVRC2012_val_00019677.bin 224 224 +28391 ./prep_dataset/ILSVRC2012_val_00008297.bin 224 224 +28392 ./prep_dataset/ILSVRC2012_val_00032238.bin 224 224 +28393 ./prep_dataset/ILSVRC2012_val_00024483.bin 224 224 +28394 ./prep_dataset/ILSVRC2012_val_00018444.bin 224 224 +28395 ./prep_dataset/ILSVRC2012_val_00049559.bin 224 224 +28396 ./prep_dataset/ILSVRC2012_val_00014537.bin 224 224 +28397 ./prep_dataset/ILSVRC2012_val_00018797.bin 224 224 +28398 ./prep_dataset/ILSVRC2012_val_00014926.bin 224 224 +28399 ./prep_dataset/ILSVRC2012_val_00000137.bin 224 224 +28400 ./prep_dataset/ILSVRC2012_val_00040429.bin 224 224 +28401 ./prep_dataset/ILSVRC2012_val_00004420.bin 224 224 +28402 ./prep_dataset/ILSVRC2012_val_00002319.bin 224 224 +28403 ./prep_dataset/ILSVRC2012_val_00024210.bin 224 224 +28404 ./prep_dataset/ILSVRC2012_val_00045597.bin 224 224 +28405 ./prep_dataset/ILSVRC2012_val_00023923.bin 224 224 +28406 ./prep_dataset/ILSVRC2012_val_00038352.bin 224 224 +28407 ./prep_dataset/ILSVRC2012_val_00042107.bin 224 224 +28408 ./prep_dataset/ILSVRC2012_val_00017028.bin 224 224 +28409 ./prep_dataset/ILSVRC2012_val_00046846.bin 224 224 +28410 ./prep_dataset/ILSVRC2012_val_00027377.bin 224 224 +28411 ./prep_dataset/ILSVRC2012_val_00043347.bin 224 224 +28412 ./prep_dataset/ILSVRC2012_val_00012800.bin 224 224 +28413 ./prep_dataset/ILSVRC2012_val_00042415.bin 224 224 +28414 ./prep_dataset/ILSVRC2012_val_00037172.bin 224 224 +28415 ./prep_dataset/ILSVRC2012_val_00000878.bin 224 224 +28416 ./prep_dataset/ILSVRC2012_val_00048316.bin 224 224 +28417 ./prep_dataset/ILSVRC2012_val_00049192.bin 224 224 +28418 ./prep_dataset/ILSVRC2012_val_00040859.bin 224 224 +28419 ./prep_dataset/ILSVRC2012_val_00032376.bin 224 224 +28420 ./prep_dataset/ILSVRC2012_val_00020036.bin 224 224 +28421 ./prep_dataset/ILSVRC2012_val_00017456.bin 224 224 +28422 ./prep_dataset/ILSVRC2012_val_00003916.bin 224 224 +28423 ./prep_dataset/ILSVRC2012_val_00017417.bin 224 224 +28424 ./prep_dataset/ILSVRC2012_val_00030039.bin 224 224 +28425 ./prep_dataset/ILSVRC2012_val_00006249.bin 224 224 +28426 ./prep_dataset/ILSVRC2012_val_00028525.bin 224 224 +28427 ./prep_dataset/ILSVRC2012_val_00048351.bin 224 224 +28428 ./prep_dataset/ILSVRC2012_val_00014429.bin 224 224 +28429 ./prep_dataset/ILSVRC2012_val_00003484.bin 224 224 +28430 ./prep_dataset/ILSVRC2012_val_00006703.bin 224 224 +28431 ./prep_dataset/ILSVRC2012_val_00006237.bin 224 224 +28432 ./prep_dataset/ILSVRC2012_val_00025802.bin 224 224 +28433 ./prep_dataset/ILSVRC2012_val_00047929.bin 224 224 +28434 ./prep_dataset/ILSVRC2012_val_00008763.bin 224 224 +28435 ./prep_dataset/ILSVRC2012_val_00002127.bin 224 224 +28436 ./prep_dataset/ILSVRC2012_val_00038214.bin 224 224 +28437 ./prep_dataset/ILSVRC2012_val_00000674.bin 224 224 +28438 ./prep_dataset/ILSVRC2012_val_00041957.bin 224 224 +28439 ./prep_dataset/ILSVRC2012_val_00022531.bin 224 224 +28440 ./prep_dataset/ILSVRC2012_val_00029090.bin 224 224 +28441 ./prep_dataset/ILSVRC2012_val_00001601.bin 224 224 +28442 ./prep_dataset/ILSVRC2012_val_00041386.bin 224 224 +28443 ./prep_dataset/ILSVRC2012_val_00047510.bin 224 224 +28444 ./prep_dataset/ILSVRC2012_val_00026405.bin 224 224 +28445 ./prep_dataset/ILSVRC2012_val_00007538.bin 224 224 +28446 ./prep_dataset/ILSVRC2012_val_00020414.bin 224 224 +28447 ./prep_dataset/ILSVRC2012_val_00016318.bin 224 224 +28448 ./prep_dataset/ILSVRC2012_val_00036714.bin 224 224 +28449 ./prep_dataset/ILSVRC2012_val_00034182.bin 224 224 +28450 ./prep_dataset/ILSVRC2012_val_00042359.bin 224 224 +28451 ./prep_dataset/ILSVRC2012_val_00043950.bin 224 224 +28452 ./prep_dataset/ILSVRC2012_val_00004789.bin 224 224 +28453 ./prep_dataset/ILSVRC2012_val_00011580.bin 224 224 +28454 ./prep_dataset/ILSVRC2012_val_00048030.bin 224 224 +28455 ./prep_dataset/ILSVRC2012_val_00011800.bin 224 224 +28456 ./prep_dataset/ILSVRC2012_val_00038148.bin 224 224 +28457 ./prep_dataset/ILSVRC2012_val_00023992.bin 224 224 +28458 ./prep_dataset/ILSVRC2012_val_00042831.bin 224 224 +28459 ./prep_dataset/ILSVRC2012_val_00016074.bin 224 224 +28460 ./prep_dataset/ILSVRC2012_val_00036895.bin 224 224 +28461 ./prep_dataset/ILSVRC2012_val_00048084.bin 224 224 +28462 ./prep_dataset/ILSVRC2012_val_00014611.bin 224 224 +28463 ./prep_dataset/ILSVRC2012_val_00009333.bin 224 224 +28464 ./prep_dataset/ILSVRC2012_val_00042242.bin 224 224 +28465 ./prep_dataset/ILSVRC2012_val_00035267.bin 224 224 +28466 ./prep_dataset/ILSVRC2012_val_00018686.bin 224 224 +28467 ./prep_dataset/ILSVRC2012_val_00029987.bin 224 224 +28468 ./prep_dataset/ILSVRC2012_val_00043580.bin 224 224 +28469 ./prep_dataset/ILSVRC2012_val_00025852.bin 224 224 +28470 ./prep_dataset/ILSVRC2012_val_00037488.bin 224 224 +28471 ./prep_dataset/ILSVRC2012_val_00012018.bin 224 224 +28472 ./prep_dataset/ILSVRC2012_val_00023344.bin 224 224 +28473 ./prep_dataset/ILSVRC2012_val_00041595.bin 224 224 +28474 ./prep_dataset/ILSVRC2012_val_00014875.bin 224 224 +28475 ./prep_dataset/ILSVRC2012_val_00034656.bin 224 224 +28476 ./prep_dataset/ILSVRC2012_val_00017396.bin 224 224 +28477 ./prep_dataset/ILSVRC2012_val_00017140.bin 224 224 +28478 ./prep_dataset/ILSVRC2012_val_00026577.bin 224 224 +28479 ./prep_dataset/ILSVRC2012_val_00045678.bin 224 224 +28480 ./prep_dataset/ILSVRC2012_val_00018843.bin 224 224 +28481 ./prep_dataset/ILSVRC2012_val_00009492.bin 224 224 +28482 ./prep_dataset/ILSVRC2012_val_00000753.bin 224 224 +28483 ./prep_dataset/ILSVRC2012_val_00045731.bin 224 224 +28484 ./prep_dataset/ILSVRC2012_val_00040412.bin 224 224 +28485 ./prep_dataset/ILSVRC2012_val_00048914.bin 224 224 +28486 ./prep_dataset/ILSVRC2012_val_00008445.bin 224 224 +28487 ./prep_dataset/ILSVRC2012_val_00026246.bin 224 224 +28488 ./prep_dataset/ILSVRC2012_val_00009216.bin 224 224 +28489 ./prep_dataset/ILSVRC2012_val_00012472.bin 224 224 +28490 ./prep_dataset/ILSVRC2012_val_00018768.bin 224 224 +28491 ./prep_dataset/ILSVRC2012_val_00034562.bin 224 224 +28492 ./prep_dataset/ILSVRC2012_val_00027297.bin 224 224 +28493 ./prep_dataset/ILSVRC2012_val_00000353.bin 224 224 +28494 ./prep_dataset/ILSVRC2012_val_00020272.bin 224 224 +28495 ./prep_dataset/ILSVRC2012_val_00019128.bin 224 224 +28496 ./prep_dataset/ILSVRC2012_val_00010155.bin 224 224 +28497 ./prep_dataset/ILSVRC2012_val_00001657.bin 224 224 +28498 ./prep_dataset/ILSVRC2012_val_00015344.bin 224 224 +28499 ./prep_dataset/ILSVRC2012_val_00009035.bin 224 224 +28500 ./prep_dataset/ILSVRC2012_val_00041724.bin 224 224 +28501 ./prep_dataset/ILSVRC2012_val_00048915.bin 224 224 +28502 ./prep_dataset/ILSVRC2012_val_00031283.bin 224 224 +28503 ./prep_dataset/ILSVRC2012_val_00006835.bin 224 224 +28504 ./prep_dataset/ILSVRC2012_val_00024498.bin 224 224 +28505 ./prep_dataset/ILSVRC2012_val_00032387.bin 224 224 +28506 ./prep_dataset/ILSVRC2012_val_00000780.bin 224 224 +28507 ./prep_dataset/ILSVRC2012_val_00009233.bin 224 224 +28508 ./prep_dataset/ILSVRC2012_val_00031102.bin 224 224 +28509 ./prep_dataset/ILSVRC2012_val_00015969.bin 224 224 +28510 ./prep_dataset/ILSVRC2012_val_00048282.bin 224 224 +28511 ./prep_dataset/ILSVRC2012_val_00043654.bin 224 224 +28512 ./prep_dataset/ILSVRC2012_val_00008553.bin 224 224 +28513 ./prep_dataset/ILSVRC2012_val_00042793.bin 224 224 +28514 ./prep_dataset/ILSVRC2012_val_00011593.bin 224 224 +28515 ./prep_dataset/ILSVRC2012_val_00048088.bin 224 224 +28516 ./prep_dataset/ILSVRC2012_val_00029874.bin 224 224 +28517 ./prep_dataset/ILSVRC2012_val_00048419.bin 224 224 +28518 ./prep_dataset/ILSVRC2012_val_00027643.bin 224 224 +28519 ./prep_dataset/ILSVRC2012_val_00023493.bin 224 224 +28520 ./prep_dataset/ILSVRC2012_val_00010220.bin 224 224 +28521 ./prep_dataset/ILSVRC2012_val_00019384.bin 224 224 +28522 ./prep_dataset/ILSVRC2012_val_00037214.bin 224 224 +28523 ./prep_dataset/ILSVRC2012_val_00034850.bin 224 224 +28524 ./prep_dataset/ILSVRC2012_val_00028268.bin 224 224 +28525 ./prep_dataset/ILSVRC2012_val_00028624.bin 224 224 +28526 ./prep_dataset/ILSVRC2012_val_00048699.bin 224 224 +28527 ./prep_dataset/ILSVRC2012_val_00031245.bin 224 224 +28528 ./prep_dataset/ILSVRC2012_val_00039285.bin 224 224 +28529 ./prep_dataset/ILSVRC2012_val_00022082.bin 224 224 +28530 ./prep_dataset/ILSVRC2012_val_00043920.bin 224 224 +28531 ./prep_dataset/ILSVRC2012_val_00033762.bin 224 224 +28532 ./prep_dataset/ILSVRC2012_val_00021614.bin 224 224 +28533 ./prep_dataset/ILSVRC2012_val_00001574.bin 224 224 +28534 ./prep_dataset/ILSVRC2012_val_00026135.bin 224 224 +28535 ./prep_dataset/ILSVRC2012_val_00040350.bin 224 224 +28536 ./prep_dataset/ILSVRC2012_val_00042302.bin 224 224 +28537 ./prep_dataset/ILSVRC2012_val_00000097.bin 224 224 +28538 ./prep_dataset/ILSVRC2012_val_00006817.bin 224 224 +28539 ./prep_dataset/ILSVRC2012_val_00005051.bin 224 224 +28540 ./prep_dataset/ILSVRC2012_val_00008975.bin 224 224 +28541 ./prep_dataset/ILSVRC2012_val_00043033.bin 224 224 +28542 ./prep_dataset/ILSVRC2012_val_00003245.bin 224 224 +28543 ./prep_dataset/ILSVRC2012_val_00039784.bin 224 224 +28544 ./prep_dataset/ILSVRC2012_val_00012780.bin 224 224 +28545 ./prep_dataset/ILSVRC2012_val_00006203.bin 224 224 +28546 ./prep_dataset/ILSVRC2012_val_00033652.bin 224 224 +28547 ./prep_dataset/ILSVRC2012_val_00023766.bin 224 224 +28548 ./prep_dataset/ILSVRC2012_val_00019693.bin 224 224 +28549 ./prep_dataset/ILSVRC2012_val_00024242.bin 224 224 +28550 ./prep_dataset/ILSVRC2012_val_00046930.bin 224 224 +28551 ./prep_dataset/ILSVRC2012_val_00033434.bin 224 224 +28552 ./prep_dataset/ILSVRC2012_val_00048586.bin 224 224 +28553 ./prep_dataset/ILSVRC2012_val_00019151.bin 224 224 +28554 ./prep_dataset/ILSVRC2012_val_00001029.bin 224 224 +28555 ./prep_dataset/ILSVRC2012_val_00000946.bin 224 224 +28556 ./prep_dataset/ILSVRC2012_val_00001788.bin 224 224 +28557 ./prep_dataset/ILSVRC2012_val_00009059.bin 224 224 +28558 ./prep_dataset/ILSVRC2012_val_00017793.bin 224 224 +28559 ./prep_dataset/ILSVRC2012_val_00023378.bin 224 224 +28560 ./prep_dataset/ILSVRC2012_val_00009517.bin 224 224 +28561 ./prep_dataset/ILSVRC2012_val_00021444.bin 224 224 +28562 ./prep_dataset/ILSVRC2012_val_00027262.bin 224 224 +28563 ./prep_dataset/ILSVRC2012_val_00019321.bin 224 224 +28564 ./prep_dataset/ILSVRC2012_val_00041775.bin 224 224 +28565 ./prep_dataset/ILSVRC2012_val_00019861.bin 224 224 +28566 ./prep_dataset/ILSVRC2012_val_00035230.bin 224 224 +28567 ./prep_dataset/ILSVRC2012_val_00029827.bin 224 224 +28568 ./prep_dataset/ILSVRC2012_val_00047098.bin 224 224 +28569 ./prep_dataset/ILSVRC2012_val_00018674.bin 224 224 +28570 ./prep_dataset/ILSVRC2012_val_00025222.bin 224 224 +28571 ./prep_dataset/ILSVRC2012_val_00020974.bin 224 224 +28572 ./prep_dataset/ILSVRC2012_val_00023588.bin 224 224 +28573 ./prep_dataset/ILSVRC2012_val_00048122.bin 224 224 +28574 ./prep_dataset/ILSVRC2012_val_00044825.bin 224 224 +28575 ./prep_dataset/ILSVRC2012_val_00027840.bin 224 224 +28576 ./prep_dataset/ILSVRC2012_val_00002927.bin 224 224 +28577 ./prep_dataset/ILSVRC2012_val_00009202.bin 224 224 +28578 ./prep_dataset/ILSVRC2012_val_00038026.bin 224 224 +28579 ./prep_dataset/ILSVRC2012_val_00047491.bin 224 224 +28580 ./prep_dataset/ILSVRC2012_val_00012081.bin 224 224 +28581 ./prep_dataset/ILSVRC2012_val_00011742.bin 224 224 +28582 ./prep_dataset/ILSVRC2012_val_00026307.bin 224 224 +28583 ./prep_dataset/ILSVRC2012_val_00007256.bin 224 224 +28584 ./prep_dataset/ILSVRC2012_val_00030225.bin 224 224 +28585 ./prep_dataset/ILSVRC2012_val_00049498.bin 224 224 +28586 ./prep_dataset/ILSVRC2012_val_00037055.bin 224 224 +28587 ./prep_dataset/ILSVRC2012_val_00024212.bin 224 224 +28588 ./prep_dataset/ILSVRC2012_val_00005230.bin 224 224 +28589 ./prep_dataset/ILSVRC2012_val_00025470.bin 224 224 +28590 ./prep_dataset/ILSVRC2012_val_00001262.bin 224 224 +28591 ./prep_dataset/ILSVRC2012_val_00045522.bin 224 224 +28592 ./prep_dataset/ILSVRC2012_val_00029591.bin 224 224 +28593 ./prep_dataset/ILSVRC2012_val_00009811.bin 224 224 +28594 ./prep_dataset/ILSVRC2012_val_00034128.bin 224 224 +28595 ./prep_dataset/ILSVRC2012_val_00034378.bin 224 224 +28596 ./prep_dataset/ILSVRC2012_val_00017560.bin 224 224 +28597 ./prep_dataset/ILSVRC2012_val_00020175.bin 224 224 +28598 ./prep_dataset/ILSVRC2012_val_00036342.bin 224 224 +28599 ./prep_dataset/ILSVRC2012_val_00018632.bin 224 224 +28600 ./prep_dataset/ILSVRC2012_val_00012967.bin 224 224 +28601 ./prep_dataset/ILSVRC2012_val_00019435.bin 224 224 +28602 ./prep_dataset/ILSVRC2012_val_00040807.bin 224 224 +28603 ./prep_dataset/ILSVRC2012_val_00034889.bin 224 224 +28604 ./prep_dataset/ILSVRC2012_val_00028549.bin 224 224 +28605 ./prep_dataset/ILSVRC2012_val_00036113.bin 224 224 +28606 ./prep_dataset/ILSVRC2012_val_00006989.bin 224 224 +28607 ./prep_dataset/ILSVRC2012_val_00016588.bin 224 224 +28608 ./prep_dataset/ILSVRC2012_val_00024892.bin 224 224 +28609 ./prep_dataset/ILSVRC2012_val_00032084.bin 224 224 +28610 ./prep_dataset/ILSVRC2012_val_00017988.bin 224 224 +28611 ./prep_dataset/ILSVRC2012_val_00022465.bin 224 224 +28612 ./prep_dataset/ILSVRC2012_val_00013184.bin 224 224 +28613 ./prep_dataset/ILSVRC2012_val_00036317.bin 224 224 +28614 ./prep_dataset/ILSVRC2012_val_00017705.bin 224 224 +28615 ./prep_dataset/ILSVRC2012_val_00031656.bin 224 224 +28616 ./prep_dataset/ILSVRC2012_val_00039612.bin 224 224 +28617 ./prep_dataset/ILSVRC2012_val_00042287.bin 224 224 +28618 ./prep_dataset/ILSVRC2012_val_00034076.bin 224 224 +28619 ./prep_dataset/ILSVRC2012_val_00009240.bin 224 224 +28620 ./prep_dataset/ILSVRC2012_val_00035435.bin 224 224 +28621 ./prep_dataset/ILSVRC2012_val_00037859.bin 224 224 +28622 ./prep_dataset/ILSVRC2012_val_00014932.bin 224 224 +28623 ./prep_dataset/ILSVRC2012_val_00027926.bin 224 224 +28624 ./prep_dataset/ILSVRC2012_val_00039455.bin 224 224 +28625 ./prep_dataset/ILSVRC2012_val_00003778.bin 224 224 +28626 ./prep_dataset/ILSVRC2012_val_00044523.bin 224 224 +28627 ./prep_dataset/ILSVRC2012_val_00009572.bin 224 224 +28628 ./prep_dataset/ILSVRC2012_val_00013759.bin 224 224 +28629 ./prep_dataset/ILSVRC2012_val_00003989.bin 224 224 +28630 ./prep_dataset/ILSVRC2012_val_00024634.bin 224 224 +28631 ./prep_dataset/ILSVRC2012_val_00040676.bin 224 224 +28632 ./prep_dataset/ILSVRC2012_val_00025063.bin 224 224 +28633 ./prep_dataset/ILSVRC2012_val_00021512.bin 224 224 +28634 ./prep_dataset/ILSVRC2012_val_00037812.bin 224 224 +28635 ./prep_dataset/ILSVRC2012_val_00026855.bin 224 224 +28636 ./prep_dataset/ILSVRC2012_val_00000332.bin 224 224 +28637 ./prep_dataset/ILSVRC2012_val_00024038.bin 224 224 +28638 ./prep_dataset/ILSVRC2012_val_00031049.bin 224 224 +28639 ./prep_dataset/ILSVRC2012_val_00011904.bin 224 224 +28640 ./prep_dataset/ILSVRC2012_val_00040418.bin 224 224 +28641 ./prep_dataset/ILSVRC2012_val_00038164.bin 224 224 +28642 ./prep_dataset/ILSVRC2012_val_00035308.bin 224 224 +28643 ./prep_dataset/ILSVRC2012_val_00000154.bin 224 224 +28644 ./prep_dataset/ILSVRC2012_val_00008436.bin 224 224 +28645 ./prep_dataset/ILSVRC2012_val_00043534.bin 224 224 +28646 ./prep_dataset/ILSVRC2012_val_00009934.bin 224 224 +28647 ./prep_dataset/ILSVRC2012_val_00025200.bin 224 224 +28648 ./prep_dataset/ILSVRC2012_val_00037654.bin 224 224 +28649 ./prep_dataset/ILSVRC2012_val_00049751.bin 224 224 +28650 ./prep_dataset/ILSVRC2012_val_00015857.bin 224 224 +28651 ./prep_dataset/ILSVRC2012_val_00021321.bin 224 224 +28652 ./prep_dataset/ILSVRC2012_val_00015118.bin 224 224 +28653 ./prep_dataset/ILSVRC2012_val_00002337.bin 224 224 +28654 ./prep_dataset/ILSVRC2012_val_00043284.bin 224 224 +28655 ./prep_dataset/ILSVRC2012_val_00010265.bin 224 224 +28656 ./prep_dataset/ILSVRC2012_val_00045249.bin 224 224 +28657 ./prep_dataset/ILSVRC2012_val_00047832.bin 224 224 +28658 ./prep_dataset/ILSVRC2012_val_00036093.bin 224 224 +28659 ./prep_dataset/ILSVRC2012_val_00036684.bin 224 224 +28660 ./prep_dataset/ILSVRC2012_val_00045682.bin 224 224 +28661 ./prep_dataset/ILSVRC2012_val_00001898.bin 224 224 +28662 ./prep_dataset/ILSVRC2012_val_00027832.bin 224 224 +28663 ./prep_dataset/ILSVRC2012_val_00013293.bin 224 224 +28664 ./prep_dataset/ILSVRC2012_val_00003234.bin 224 224 +28665 ./prep_dataset/ILSVRC2012_val_00019724.bin 224 224 +28666 ./prep_dataset/ILSVRC2012_val_00004628.bin 224 224 +28667 ./prep_dataset/ILSVRC2012_val_00016735.bin 224 224 +28668 ./prep_dataset/ILSVRC2012_val_00034473.bin 224 224 +28669 ./prep_dataset/ILSVRC2012_val_00037294.bin 224 224 +28670 ./prep_dataset/ILSVRC2012_val_00005493.bin 224 224 +28671 ./prep_dataset/ILSVRC2012_val_00029398.bin 224 224 +28672 ./prep_dataset/ILSVRC2012_val_00031637.bin 224 224 +28673 ./prep_dataset/ILSVRC2012_val_00011482.bin 224 224 +28674 ./prep_dataset/ILSVRC2012_val_00001772.bin 224 224 +28675 ./prep_dataset/ILSVRC2012_val_00023909.bin 224 224 +28676 ./prep_dataset/ILSVRC2012_val_00049107.bin 224 224 +28677 ./prep_dataset/ILSVRC2012_val_00043385.bin 224 224 +28678 ./prep_dataset/ILSVRC2012_val_00032274.bin 224 224 +28679 ./prep_dataset/ILSVRC2012_val_00018427.bin 224 224 +28680 ./prep_dataset/ILSVRC2012_val_00007674.bin 224 224 +28681 ./prep_dataset/ILSVRC2012_val_00026905.bin 224 224 +28682 ./prep_dataset/ILSVRC2012_val_00034200.bin 224 224 +28683 ./prep_dataset/ILSVRC2012_val_00011497.bin 224 224 +28684 ./prep_dataset/ILSVRC2012_val_00005280.bin 224 224 +28685 ./prep_dataset/ILSVRC2012_val_00016922.bin 224 224 +28686 ./prep_dataset/ILSVRC2012_val_00013742.bin 224 224 +28687 ./prep_dataset/ILSVRC2012_val_00042005.bin 224 224 +28688 ./prep_dataset/ILSVRC2012_val_00023893.bin 224 224 +28689 ./prep_dataset/ILSVRC2012_val_00000090.bin 224 224 +28690 ./prep_dataset/ILSVRC2012_val_00036019.bin 224 224 +28691 ./prep_dataset/ILSVRC2012_val_00041997.bin 224 224 +28692 ./prep_dataset/ILSVRC2012_val_00004116.bin 224 224 +28693 ./prep_dataset/ILSVRC2012_val_00016342.bin 224 224 +28694 ./prep_dataset/ILSVRC2012_val_00046864.bin 224 224 +28695 ./prep_dataset/ILSVRC2012_val_00046971.bin 224 224 +28696 ./prep_dataset/ILSVRC2012_val_00038973.bin 224 224 +28697 ./prep_dataset/ILSVRC2012_val_00048993.bin 224 224 +28698 ./prep_dataset/ILSVRC2012_val_00028384.bin 224 224 +28699 ./prep_dataset/ILSVRC2012_val_00044546.bin 224 224 +28700 ./prep_dataset/ILSVRC2012_val_00038024.bin 224 224 +28701 ./prep_dataset/ILSVRC2012_val_00014202.bin 224 224 +28702 ./prep_dataset/ILSVRC2012_val_00006223.bin 224 224 +28703 ./prep_dataset/ILSVRC2012_val_00020688.bin 224 224 +28704 ./prep_dataset/ILSVRC2012_val_00021099.bin 224 224 +28705 ./prep_dataset/ILSVRC2012_val_00013105.bin 224 224 +28706 ./prep_dataset/ILSVRC2012_val_00020726.bin 224 224 +28707 ./prep_dataset/ILSVRC2012_val_00028334.bin 224 224 +28708 ./prep_dataset/ILSVRC2012_val_00008216.bin 224 224 +28709 ./prep_dataset/ILSVRC2012_val_00017807.bin 224 224 +28710 ./prep_dataset/ILSVRC2012_val_00028805.bin 224 224 +28711 ./prep_dataset/ILSVRC2012_val_00015869.bin 224 224 +28712 ./prep_dataset/ILSVRC2012_val_00040820.bin 224 224 +28713 ./prep_dataset/ILSVRC2012_val_00031997.bin 224 224 +28714 ./prep_dataset/ILSVRC2012_val_00032253.bin 224 224 +28715 ./prep_dataset/ILSVRC2012_val_00048839.bin 224 224 +28716 ./prep_dataset/ILSVRC2012_val_00039888.bin 224 224 +28717 ./prep_dataset/ILSVRC2012_val_00038088.bin 224 224 +28718 ./prep_dataset/ILSVRC2012_val_00000152.bin 224 224 +28719 ./prep_dataset/ILSVRC2012_val_00021494.bin 224 224 +28720 ./prep_dataset/ILSVRC2012_val_00008707.bin 224 224 +28721 ./prep_dataset/ILSVRC2012_val_00022685.bin 224 224 +28722 ./prep_dataset/ILSVRC2012_val_00044773.bin 224 224 +28723 ./prep_dataset/ILSVRC2012_val_00003270.bin 224 224 +28724 ./prep_dataset/ILSVRC2012_val_00025779.bin 224 224 +28725 ./prep_dataset/ILSVRC2012_val_00007634.bin 224 224 +28726 ./prep_dataset/ILSVRC2012_val_00047302.bin 224 224 +28727 ./prep_dataset/ILSVRC2012_val_00044517.bin 224 224 +28728 ./prep_dataset/ILSVRC2012_val_00042474.bin 224 224 +28729 ./prep_dataset/ILSVRC2012_val_00038732.bin 224 224 +28730 ./prep_dataset/ILSVRC2012_val_00018826.bin 224 224 +28731 ./prep_dataset/ILSVRC2012_val_00006768.bin 224 224 +28732 ./prep_dataset/ILSVRC2012_val_00024211.bin 224 224 +28733 ./prep_dataset/ILSVRC2012_val_00011875.bin 224 224 +28734 ./prep_dataset/ILSVRC2012_val_00037656.bin 224 224 +28735 ./prep_dataset/ILSVRC2012_val_00006962.bin 224 224 +28736 ./prep_dataset/ILSVRC2012_val_00031639.bin 224 224 +28737 ./prep_dataset/ILSVRC2012_val_00009144.bin 224 224 +28738 ./prep_dataset/ILSVRC2012_val_00013855.bin 224 224 +28739 ./prep_dataset/ILSVRC2012_val_00031858.bin 224 224 +28740 ./prep_dataset/ILSVRC2012_val_00031657.bin 224 224 +28741 ./prep_dataset/ILSVRC2012_val_00003253.bin 224 224 +28742 ./prep_dataset/ILSVRC2012_val_00014232.bin 224 224 +28743 ./prep_dataset/ILSVRC2012_val_00048482.bin 224 224 +28744 ./prep_dataset/ILSVRC2012_val_00028935.bin 224 224 +28745 ./prep_dataset/ILSVRC2012_val_00002798.bin 224 224 +28746 ./prep_dataset/ILSVRC2012_val_00034123.bin 224 224 +28747 ./prep_dataset/ILSVRC2012_val_00025415.bin 224 224 +28748 ./prep_dataset/ILSVRC2012_val_00021809.bin 224 224 +28749 ./prep_dataset/ILSVRC2012_val_00031483.bin 224 224 +28750 ./prep_dataset/ILSVRC2012_val_00013371.bin 224 224 +28751 ./prep_dataset/ILSVRC2012_val_00035666.bin 224 224 +28752 ./prep_dataset/ILSVRC2012_val_00049058.bin 224 224 +28753 ./prep_dataset/ILSVRC2012_val_00006028.bin 224 224 +28754 ./prep_dataset/ILSVRC2012_val_00035405.bin 224 224 +28755 ./prep_dataset/ILSVRC2012_val_00020058.bin 224 224 +28756 ./prep_dataset/ILSVRC2012_val_00036480.bin 224 224 +28757 ./prep_dataset/ILSVRC2012_val_00033838.bin 224 224 +28758 ./prep_dataset/ILSVRC2012_val_00035064.bin 224 224 +28759 ./prep_dataset/ILSVRC2012_val_00034246.bin 224 224 +28760 ./prep_dataset/ILSVRC2012_val_00032696.bin 224 224 +28761 ./prep_dataset/ILSVRC2012_val_00044618.bin 224 224 +28762 ./prep_dataset/ILSVRC2012_val_00001987.bin 224 224 +28763 ./prep_dataset/ILSVRC2012_val_00008085.bin 224 224 +28764 ./prep_dataset/ILSVRC2012_val_00036373.bin 224 224 +28765 ./prep_dataset/ILSVRC2012_val_00033982.bin 224 224 +28766 ./prep_dataset/ILSVRC2012_val_00012162.bin 224 224 +28767 ./prep_dataset/ILSVRC2012_val_00035179.bin 224 224 +28768 ./prep_dataset/ILSVRC2012_val_00043571.bin 224 224 +28769 ./prep_dataset/ILSVRC2012_val_00036183.bin 224 224 +28770 ./prep_dataset/ILSVRC2012_val_00045686.bin 224 224 +28771 ./prep_dataset/ILSVRC2012_val_00017048.bin 224 224 +28772 ./prep_dataset/ILSVRC2012_val_00028142.bin 224 224 +28773 ./prep_dataset/ILSVRC2012_val_00038301.bin 224 224 +28774 ./prep_dataset/ILSVRC2012_val_00046280.bin 224 224 +28775 ./prep_dataset/ILSVRC2012_val_00018087.bin 224 224 +28776 ./prep_dataset/ILSVRC2012_val_00036867.bin 224 224 +28777 ./prep_dataset/ILSVRC2012_val_00049157.bin 224 224 +28778 ./prep_dataset/ILSVRC2012_val_00027291.bin 224 224 +28779 ./prep_dataset/ILSVRC2012_val_00044259.bin 224 224 +28780 ./prep_dataset/ILSVRC2012_val_00025664.bin 224 224 +28781 ./prep_dataset/ILSVRC2012_val_00015764.bin 224 224 +28782 ./prep_dataset/ILSVRC2012_val_00004669.bin 224 224 +28783 ./prep_dataset/ILSVRC2012_val_00025929.bin 224 224 +28784 ./prep_dataset/ILSVRC2012_val_00020001.bin 224 224 +28785 ./prep_dataset/ILSVRC2012_val_00018391.bin 224 224 +28786 ./prep_dataset/ILSVRC2012_val_00025177.bin 224 224 +28787 ./prep_dataset/ILSVRC2012_val_00044897.bin 224 224 +28788 ./prep_dataset/ILSVRC2012_val_00040181.bin 224 224 +28789 ./prep_dataset/ILSVRC2012_val_00009931.bin 224 224 +28790 ./prep_dataset/ILSVRC2012_val_00037493.bin 224 224 +28791 ./prep_dataset/ILSVRC2012_val_00013346.bin 224 224 +28792 ./prep_dataset/ILSVRC2012_val_00039838.bin 224 224 +28793 ./prep_dataset/ILSVRC2012_val_00016131.bin 224 224 +28794 ./prep_dataset/ILSVRC2012_val_00043575.bin 224 224 +28795 ./prep_dataset/ILSVRC2012_val_00033990.bin 224 224 +28796 ./prep_dataset/ILSVRC2012_val_00008880.bin 224 224 +28797 ./prep_dataset/ILSVRC2012_val_00039329.bin 224 224 +28798 ./prep_dataset/ILSVRC2012_val_00027864.bin 224 224 +28799 ./prep_dataset/ILSVRC2012_val_00002614.bin 224 224 +28800 ./prep_dataset/ILSVRC2012_val_00035556.bin 224 224 +28801 ./prep_dataset/ILSVRC2012_val_00040542.bin 224 224 +28802 ./prep_dataset/ILSVRC2012_val_00013681.bin 224 224 +28803 ./prep_dataset/ILSVRC2012_val_00004004.bin 224 224 +28804 ./prep_dataset/ILSVRC2012_val_00025336.bin 224 224 +28805 ./prep_dataset/ILSVRC2012_val_00003838.bin 224 224 +28806 ./prep_dataset/ILSVRC2012_val_00002258.bin 224 224 +28807 ./prep_dataset/ILSVRC2012_val_00038580.bin 224 224 +28808 ./prep_dataset/ILSVRC2012_val_00041408.bin 224 224 +28809 ./prep_dataset/ILSVRC2012_val_00036521.bin 224 224 +28810 ./prep_dataset/ILSVRC2012_val_00048439.bin 224 224 +28811 ./prep_dataset/ILSVRC2012_val_00030788.bin 224 224 +28812 ./prep_dataset/ILSVRC2012_val_00008491.bin 224 224 +28813 ./prep_dataset/ILSVRC2012_val_00025740.bin 224 224 +28814 ./prep_dataset/ILSVRC2012_val_00005668.bin 224 224 +28815 ./prep_dataset/ILSVRC2012_val_00037315.bin 224 224 +28816 ./prep_dataset/ILSVRC2012_val_00042993.bin 224 224 +28817 ./prep_dataset/ILSVRC2012_val_00009589.bin 224 224 +28818 ./prep_dataset/ILSVRC2012_val_00040178.bin 224 224 +28819 ./prep_dataset/ILSVRC2012_val_00030485.bin 224 224 +28820 ./prep_dataset/ILSVRC2012_val_00011560.bin 224 224 +28821 ./prep_dataset/ILSVRC2012_val_00048159.bin 224 224 +28822 ./prep_dataset/ILSVRC2012_val_00012316.bin 224 224 +28823 ./prep_dataset/ILSVRC2012_val_00030821.bin 224 224 +28824 ./prep_dataset/ILSVRC2012_val_00000890.bin 224 224 +28825 ./prep_dataset/ILSVRC2012_val_00013174.bin 224 224 +28826 ./prep_dataset/ILSVRC2012_val_00019214.bin 224 224 +28827 ./prep_dataset/ILSVRC2012_val_00006832.bin 224 224 +28828 ./prep_dataset/ILSVRC2012_val_00022086.bin 224 224 +28829 ./prep_dataset/ILSVRC2012_val_00003912.bin 224 224 +28830 ./prep_dataset/ILSVRC2012_val_00024880.bin 224 224 +28831 ./prep_dataset/ILSVRC2012_val_00008477.bin 224 224 +28832 ./prep_dataset/ILSVRC2012_val_00017046.bin 224 224 +28833 ./prep_dataset/ILSVRC2012_val_00040933.bin 224 224 +28834 ./prep_dataset/ILSVRC2012_val_00014344.bin 224 224 +28835 ./prep_dataset/ILSVRC2012_val_00044422.bin 224 224 +28836 ./prep_dataset/ILSVRC2012_val_00021898.bin 224 224 +28837 ./prep_dataset/ILSVRC2012_val_00031284.bin 224 224 +28838 ./prep_dataset/ILSVRC2012_val_00021443.bin 224 224 +28839 ./prep_dataset/ILSVRC2012_val_00004123.bin 224 224 +28840 ./prep_dataset/ILSVRC2012_val_00042455.bin 224 224 +28841 ./prep_dataset/ILSVRC2012_val_00010030.bin 224 224 +28842 ./prep_dataset/ILSVRC2012_val_00002749.bin 224 224 +28843 ./prep_dataset/ILSVRC2012_val_00019753.bin 224 224 +28844 ./prep_dataset/ILSVRC2012_val_00013675.bin 224 224 +28845 ./prep_dataset/ILSVRC2012_val_00047516.bin 224 224 +28846 ./prep_dataset/ILSVRC2012_val_00040978.bin 224 224 +28847 ./prep_dataset/ILSVRC2012_val_00046347.bin 224 224 +28848 ./prep_dataset/ILSVRC2012_val_00020934.bin 224 224 +28849 ./prep_dataset/ILSVRC2012_val_00049380.bin 224 224 +28850 ./prep_dataset/ILSVRC2012_val_00030116.bin 224 224 +28851 ./prep_dataset/ILSVRC2012_val_00017043.bin 224 224 +28852 ./prep_dataset/ILSVRC2012_val_00031437.bin 224 224 +28853 ./prep_dataset/ILSVRC2012_val_00009860.bin 224 224 +28854 ./prep_dataset/ILSVRC2012_val_00028005.bin 224 224 +28855 ./prep_dataset/ILSVRC2012_val_00005178.bin 224 224 +28856 ./prep_dataset/ILSVRC2012_val_00037933.bin 224 224 +28857 ./prep_dataset/ILSVRC2012_val_00046664.bin 224 224 +28858 ./prep_dataset/ILSVRC2012_val_00030341.bin 224 224 +28859 ./prep_dataset/ILSVRC2012_val_00042023.bin 224 224 +28860 ./prep_dataset/ILSVRC2012_val_00012565.bin 224 224 +28861 ./prep_dataset/ILSVRC2012_val_00000473.bin 224 224 +28862 ./prep_dataset/ILSVRC2012_val_00016642.bin 224 224 +28863 ./prep_dataset/ILSVRC2012_val_00023948.bin 224 224 +28864 ./prep_dataset/ILSVRC2012_val_00033014.bin 224 224 +28865 ./prep_dataset/ILSVRC2012_val_00039353.bin 224 224 +28866 ./prep_dataset/ILSVRC2012_val_00015546.bin 224 224 +28867 ./prep_dataset/ILSVRC2012_val_00003732.bin 224 224 +28868 ./prep_dataset/ILSVRC2012_val_00005451.bin 224 224 +28869 ./prep_dataset/ILSVRC2012_val_00000285.bin 224 224 +28870 ./prep_dataset/ILSVRC2012_val_00017499.bin 224 224 +28871 ./prep_dataset/ILSVRC2012_val_00011406.bin 224 224 +28872 ./prep_dataset/ILSVRC2012_val_00000713.bin 224 224 +28873 ./prep_dataset/ILSVRC2012_val_00015288.bin 224 224 +28874 ./prep_dataset/ILSVRC2012_val_00041769.bin 224 224 +28875 ./prep_dataset/ILSVRC2012_val_00029719.bin 224 224 +28876 ./prep_dataset/ILSVRC2012_val_00023289.bin 224 224 +28877 ./prep_dataset/ILSVRC2012_val_00024039.bin 224 224 +28878 ./prep_dataset/ILSVRC2012_val_00049251.bin 224 224 +28879 ./prep_dataset/ILSVRC2012_val_00028845.bin 224 224 +28880 ./prep_dataset/ILSVRC2012_val_00037050.bin 224 224 +28881 ./prep_dataset/ILSVRC2012_val_00001078.bin 224 224 +28882 ./prep_dataset/ILSVRC2012_val_00011320.bin 224 224 +28883 ./prep_dataset/ILSVRC2012_val_00002629.bin 224 224 +28884 ./prep_dataset/ILSVRC2012_val_00006275.bin 224 224 +28885 ./prep_dataset/ILSVRC2012_val_00040005.bin 224 224 +28886 ./prep_dataset/ILSVRC2012_val_00035908.bin 224 224 +28887 ./prep_dataset/ILSVRC2012_val_00001549.bin 224 224 +28888 ./prep_dataset/ILSVRC2012_val_00015953.bin 224 224 +28889 ./prep_dataset/ILSVRC2012_val_00003225.bin 224 224 +28890 ./prep_dataset/ILSVRC2012_val_00020421.bin 224 224 +28891 ./prep_dataset/ILSVRC2012_val_00030099.bin 224 224 +28892 ./prep_dataset/ILSVRC2012_val_00008733.bin 224 224 +28893 ./prep_dataset/ILSVRC2012_val_00039882.bin 224 224 +28894 ./prep_dataset/ILSVRC2012_val_00002625.bin 224 224 +28895 ./prep_dataset/ILSVRC2012_val_00025376.bin 224 224 +28896 ./prep_dataset/ILSVRC2012_val_00042335.bin 224 224 +28897 ./prep_dataset/ILSVRC2012_val_00042694.bin 224 224 +28898 ./prep_dataset/ILSVRC2012_val_00030532.bin 224 224 +28899 ./prep_dataset/ILSVRC2012_val_00022742.bin 224 224 +28900 ./prep_dataset/ILSVRC2012_val_00002159.bin 224 224 +28901 ./prep_dataset/ILSVRC2012_val_00049927.bin 224 224 +28902 ./prep_dataset/ILSVRC2012_val_00005910.bin 224 224 +28903 ./prep_dataset/ILSVRC2012_val_00044413.bin 224 224 +28904 ./prep_dataset/ILSVRC2012_val_00033400.bin 224 224 +28905 ./prep_dataset/ILSVRC2012_val_00032660.bin 224 224 +28906 ./prep_dataset/ILSVRC2012_val_00000190.bin 224 224 +28907 ./prep_dataset/ILSVRC2012_val_00023652.bin 224 224 +28908 ./prep_dataset/ILSVRC2012_val_00024962.bin 224 224 +28909 ./prep_dataset/ILSVRC2012_val_00007016.bin 224 224 +28910 ./prep_dataset/ILSVRC2012_val_00016919.bin 224 224 +28911 ./prep_dataset/ILSVRC2012_val_00037760.bin 224 224 +28912 ./prep_dataset/ILSVRC2012_val_00038729.bin 224 224 +28913 ./prep_dataset/ILSVRC2012_val_00025280.bin 224 224 +28914 ./prep_dataset/ILSVRC2012_val_00008267.bin 224 224 +28915 ./prep_dataset/ILSVRC2012_val_00010473.bin 224 224 +28916 ./prep_dataset/ILSVRC2012_val_00032434.bin 224 224 +28917 ./prep_dataset/ILSVRC2012_val_00022202.bin 224 224 +28918 ./prep_dataset/ILSVRC2012_val_00037202.bin 224 224 +28919 ./prep_dataset/ILSVRC2012_val_00017965.bin 224 224 +28920 ./prep_dataset/ILSVRC2012_val_00045220.bin 224 224 +28921 ./prep_dataset/ILSVRC2012_val_00017835.bin 224 224 +28922 ./prep_dataset/ILSVRC2012_val_00042337.bin 224 224 +28923 ./prep_dataset/ILSVRC2012_val_00030141.bin 224 224 +28924 ./prep_dataset/ILSVRC2012_val_00049686.bin 224 224 +28925 ./prep_dataset/ILSVRC2012_val_00023629.bin 224 224 +28926 ./prep_dataset/ILSVRC2012_val_00041657.bin 224 224 +28927 ./prep_dataset/ILSVRC2012_val_00011765.bin 224 224 +28928 ./prep_dataset/ILSVRC2012_val_00001641.bin 224 224 +28929 ./prep_dataset/ILSVRC2012_val_00018279.bin 224 224 +28930 ./prep_dataset/ILSVRC2012_val_00010741.bin 224 224 +28931 ./prep_dataset/ILSVRC2012_val_00034664.bin 224 224 +28932 ./prep_dataset/ILSVRC2012_val_00000171.bin 224 224 +28933 ./prep_dataset/ILSVRC2012_val_00011856.bin 224 224 +28934 ./prep_dataset/ILSVRC2012_val_00026684.bin 224 224 +28935 ./prep_dataset/ILSVRC2012_val_00035190.bin 224 224 +28936 ./prep_dataset/ILSVRC2012_val_00035446.bin 224 224 +28937 ./prep_dataset/ILSVRC2012_val_00030464.bin 224 224 +28938 ./prep_dataset/ILSVRC2012_val_00041830.bin 224 224 +28939 ./prep_dataset/ILSVRC2012_val_00000997.bin 224 224 +28940 ./prep_dataset/ILSVRC2012_val_00032124.bin 224 224 +28941 ./prep_dataset/ILSVRC2012_val_00049514.bin 224 224 +28942 ./prep_dataset/ILSVRC2012_val_00016391.bin 224 224 +28943 ./prep_dataset/ILSVRC2012_val_00041387.bin 224 224 +28944 ./prep_dataset/ILSVRC2012_val_00023163.bin 224 224 +28945 ./prep_dataset/ILSVRC2012_val_00013871.bin 224 224 +28946 ./prep_dataset/ILSVRC2012_val_00034341.bin 224 224 +28947 ./prep_dataset/ILSVRC2012_val_00001302.bin 224 224 +28948 ./prep_dataset/ILSVRC2012_val_00037394.bin 224 224 +28949 ./prep_dataset/ILSVRC2012_val_00029281.bin 224 224 +28950 ./prep_dataset/ILSVRC2012_val_00030153.bin 224 224 +28951 ./prep_dataset/ILSVRC2012_val_00045251.bin 224 224 +28952 ./prep_dataset/ILSVRC2012_val_00045490.bin 224 224 +28953 ./prep_dataset/ILSVRC2012_val_00033278.bin 224 224 +28954 ./prep_dataset/ILSVRC2012_val_00049602.bin 224 224 +28955 ./prep_dataset/ILSVRC2012_val_00041283.bin 224 224 +28956 ./prep_dataset/ILSVRC2012_val_00026853.bin 224 224 +28957 ./prep_dataset/ILSVRC2012_val_00002214.bin 224 224 +28958 ./prep_dataset/ILSVRC2012_val_00035054.bin 224 224 +28959 ./prep_dataset/ILSVRC2012_val_00031240.bin 224 224 +28960 ./prep_dataset/ILSVRC2012_val_00002712.bin 224 224 +28961 ./prep_dataset/ILSVRC2012_val_00025823.bin 224 224 +28962 ./prep_dataset/ILSVRC2012_val_00045392.bin 224 224 +28963 ./prep_dataset/ILSVRC2012_val_00004378.bin 224 224 +28964 ./prep_dataset/ILSVRC2012_val_00015352.bin 224 224 +28965 ./prep_dataset/ILSVRC2012_val_00010402.bin 224 224 +28966 ./prep_dataset/ILSVRC2012_val_00049445.bin 224 224 +28967 ./prep_dataset/ILSVRC2012_val_00009981.bin 224 224 +28968 ./prep_dataset/ILSVRC2012_val_00047382.bin 224 224 +28969 ./prep_dataset/ILSVRC2012_val_00022758.bin 224 224 +28970 ./prep_dataset/ILSVRC2012_val_00038689.bin 224 224 +28971 ./prep_dataset/ILSVRC2012_val_00042703.bin 224 224 +28972 ./prep_dataset/ILSVRC2012_val_00015341.bin 224 224 +28973 ./prep_dataset/ILSVRC2012_val_00038159.bin 224 224 +28974 ./prep_dataset/ILSVRC2012_val_00049820.bin 224 224 +28975 ./prep_dataset/ILSVRC2012_val_00012608.bin 224 224 +28976 ./prep_dataset/ILSVRC2012_val_00012699.bin 224 224 +28977 ./prep_dataset/ILSVRC2012_val_00021428.bin 224 224 +28978 ./prep_dataset/ILSVRC2012_val_00023987.bin 224 224 +28979 ./prep_dataset/ILSVRC2012_val_00009283.bin 224 224 +28980 ./prep_dataset/ILSVRC2012_val_00032777.bin 224 224 +28981 ./prep_dataset/ILSVRC2012_val_00039298.bin 224 224 +28982 ./prep_dataset/ILSVRC2012_val_00047908.bin 224 224 +28983 ./prep_dataset/ILSVRC2012_val_00030270.bin 224 224 +28984 ./prep_dataset/ILSVRC2012_val_00015996.bin 224 224 +28985 ./prep_dataset/ILSVRC2012_val_00000331.bin 224 224 +28986 ./prep_dataset/ILSVRC2012_val_00045309.bin 224 224 +28987 ./prep_dataset/ILSVRC2012_val_00016014.bin 224 224 +28988 ./prep_dataset/ILSVRC2012_val_00042807.bin 224 224 +28989 ./prep_dataset/ILSVRC2012_val_00001769.bin 224 224 +28990 ./prep_dataset/ILSVRC2012_val_00006741.bin 224 224 +28991 ./prep_dataset/ILSVRC2012_val_00044559.bin 224 224 +28992 ./prep_dataset/ILSVRC2012_val_00037136.bin 224 224 +28993 ./prep_dataset/ILSVRC2012_val_00006757.bin 224 224 +28994 ./prep_dataset/ILSVRC2012_val_00043941.bin 224 224 +28995 ./prep_dataset/ILSVRC2012_val_00023720.bin 224 224 +28996 ./prep_dataset/ILSVRC2012_val_00027786.bin 224 224 +28997 ./prep_dataset/ILSVRC2012_val_00047864.bin 224 224 +28998 ./prep_dataset/ILSVRC2012_val_00015524.bin 224 224 +28999 ./prep_dataset/ILSVRC2012_val_00030262.bin 224 224 +29000 ./prep_dataset/ILSVRC2012_val_00000283.bin 224 224 +29001 ./prep_dataset/ILSVRC2012_val_00042133.bin 224 224 +29002 ./prep_dataset/ILSVRC2012_val_00039926.bin 224 224 +29003 ./prep_dataset/ILSVRC2012_val_00008468.bin 224 224 +29004 ./prep_dataset/ILSVRC2012_val_00031479.bin 224 224 +29005 ./prep_dataset/ILSVRC2012_val_00016111.bin 224 224 +29006 ./prep_dataset/ILSVRC2012_val_00036564.bin 224 224 +29007 ./prep_dataset/ILSVRC2012_val_00035490.bin 224 224 +29008 ./prep_dataset/ILSVRC2012_val_00011890.bin 224 224 +29009 ./prep_dataset/ILSVRC2012_val_00032722.bin 224 224 +29010 ./prep_dataset/ILSVRC2012_val_00037533.bin 224 224 +29011 ./prep_dataset/ILSVRC2012_val_00022919.bin 224 224 +29012 ./prep_dataset/ILSVRC2012_val_00044997.bin 224 224 +29013 ./prep_dataset/ILSVRC2012_val_00031509.bin 224 224 +29014 ./prep_dataset/ILSVRC2012_val_00042968.bin 224 224 +29015 ./prep_dataset/ILSVRC2012_val_00014990.bin 224 224 +29016 ./prep_dataset/ILSVRC2012_val_00040347.bin 224 224 +29017 ./prep_dataset/ILSVRC2012_val_00010680.bin 224 224 +29018 ./prep_dataset/ILSVRC2012_val_00004529.bin 224 224 +29019 ./prep_dataset/ILSVRC2012_val_00017496.bin 224 224 +29020 ./prep_dataset/ILSVRC2012_val_00003924.bin 224 224 +29021 ./prep_dataset/ILSVRC2012_val_00021243.bin 224 224 +29022 ./prep_dataset/ILSVRC2012_val_00049023.bin 224 224 +29023 ./prep_dataset/ILSVRC2012_val_00040925.bin 224 224 +29024 ./prep_dataset/ILSVRC2012_val_00012102.bin 224 224 +29025 ./prep_dataset/ILSVRC2012_val_00036662.bin 224 224 +29026 ./prep_dataset/ILSVRC2012_val_00033032.bin 224 224 +29027 ./prep_dataset/ILSVRC2012_val_00007107.bin 224 224 +29028 ./prep_dataset/ILSVRC2012_val_00014234.bin 224 224 +29029 ./prep_dataset/ILSVRC2012_val_00016402.bin 224 224 +29030 ./prep_dataset/ILSVRC2012_val_00035661.bin 224 224 +29031 ./prep_dataset/ILSVRC2012_val_00001785.bin 224 224 +29032 ./prep_dataset/ILSVRC2012_val_00013607.bin 224 224 +29033 ./prep_dataset/ILSVRC2012_val_00015072.bin 224 224 +29034 ./prep_dataset/ILSVRC2012_val_00032467.bin 224 224 +29035 ./prep_dataset/ILSVRC2012_val_00005081.bin 224 224 +29036 ./prep_dataset/ILSVRC2012_val_00038788.bin 224 224 +29037 ./prep_dataset/ILSVRC2012_val_00036199.bin 224 224 +29038 ./prep_dataset/ILSVRC2012_val_00019451.bin 224 224 +29039 ./prep_dataset/ILSVRC2012_val_00041885.bin 224 224 +29040 ./prep_dataset/ILSVRC2012_val_00046189.bin 224 224 +29041 ./prep_dataset/ILSVRC2012_val_00028118.bin 224 224 +29042 ./prep_dataset/ILSVRC2012_val_00048526.bin 224 224 +29043 ./prep_dataset/ILSVRC2012_val_00011371.bin 224 224 +29044 ./prep_dataset/ILSVRC2012_val_00007238.bin 224 224 +29045 ./prep_dataset/ILSVRC2012_val_00022295.bin 224 224 +29046 ./prep_dataset/ILSVRC2012_val_00045898.bin 224 224 +29047 ./prep_dataset/ILSVRC2012_val_00048702.bin 224 224 +29048 ./prep_dataset/ILSVRC2012_val_00040367.bin 224 224 +29049 ./prep_dataset/ILSVRC2012_val_00040840.bin 224 224 +29050 ./prep_dataset/ILSVRC2012_val_00019297.bin 224 224 +29051 ./prep_dataset/ILSVRC2012_val_00042230.bin 224 224 +29052 ./prep_dataset/ILSVRC2012_val_00041811.bin 224 224 +29053 ./prep_dataset/ILSVRC2012_val_00009762.bin 224 224 +29054 ./prep_dataset/ILSVRC2012_val_00009096.bin 224 224 +29055 ./prep_dataset/ILSVRC2012_val_00022722.bin 224 224 +29056 ./prep_dataset/ILSVRC2012_val_00014977.bin 224 224 +29057 ./prep_dataset/ILSVRC2012_val_00018308.bin 224 224 +29058 ./prep_dataset/ILSVRC2012_val_00005698.bin 224 224 +29059 ./prep_dataset/ILSVRC2012_val_00048939.bin 224 224 +29060 ./prep_dataset/ILSVRC2012_val_00036369.bin 224 224 +29061 ./prep_dataset/ILSVRC2012_val_00036541.bin 224 224 +29062 ./prep_dataset/ILSVRC2012_val_00004959.bin 224 224 +29063 ./prep_dataset/ILSVRC2012_val_00005409.bin 224 224 +29064 ./prep_dataset/ILSVRC2012_val_00044778.bin 224 224 +29065 ./prep_dataset/ILSVRC2012_val_00021567.bin 224 224 +29066 ./prep_dataset/ILSVRC2012_val_00014243.bin 224 224 +29067 ./prep_dataset/ILSVRC2012_val_00004235.bin 224 224 +29068 ./prep_dataset/ILSVRC2012_val_00002516.bin 224 224 +29069 ./prep_dataset/ILSVRC2012_val_00036205.bin 224 224 +29070 ./prep_dataset/ILSVRC2012_val_00004058.bin 224 224 +29071 ./prep_dataset/ILSVRC2012_val_00029897.bin 224 224 +29072 ./prep_dataset/ILSVRC2012_val_00009932.bin 224 224 +29073 ./prep_dataset/ILSVRC2012_val_00000929.bin 224 224 +29074 ./prep_dataset/ILSVRC2012_val_00014703.bin 224 224 +29075 ./prep_dataset/ILSVRC2012_val_00015959.bin 224 224 +29076 ./prep_dataset/ILSVRC2012_val_00014717.bin 224 224 +29077 ./prep_dataset/ILSVRC2012_val_00011574.bin 224 224 +29078 ./prep_dataset/ILSVRC2012_val_00036346.bin 224 224 +29079 ./prep_dataset/ILSVRC2012_val_00017434.bin 224 224 +29080 ./prep_dataset/ILSVRC2012_val_00029573.bin 224 224 +29081 ./prep_dataset/ILSVRC2012_val_00034141.bin 224 224 +29082 ./prep_dataset/ILSVRC2012_val_00031961.bin 224 224 +29083 ./prep_dataset/ILSVRC2012_val_00043562.bin 224 224 +29084 ./prep_dataset/ILSVRC2012_val_00011489.bin 224 224 +29085 ./prep_dataset/ILSVRC2012_val_00042354.bin 224 224 +29086 ./prep_dataset/ILSVRC2012_val_00036648.bin 224 224 +29087 ./prep_dataset/ILSVRC2012_val_00023707.bin 224 224 +29088 ./prep_dataset/ILSVRC2012_val_00016696.bin 224 224 +29089 ./prep_dataset/ILSVRC2012_val_00049115.bin 224 224 +29090 ./prep_dataset/ILSVRC2012_val_00027424.bin 224 224 +29091 ./prep_dataset/ILSVRC2012_val_00041916.bin 224 224 +29092 ./prep_dataset/ILSVRC2012_val_00044842.bin 224 224 +29093 ./prep_dataset/ILSVRC2012_val_00021292.bin 224 224 +29094 ./prep_dataset/ILSVRC2012_val_00047033.bin 224 224 +29095 ./prep_dataset/ILSVRC2012_val_00019154.bin 224 224 +29096 ./prep_dataset/ILSVRC2012_val_00041579.bin 224 224 +29097 ./prep_dataset/ILSVRC2012_val_00033085.bin 224 224 +29098 ./prep_dataset/ILSVRC2012_val_00002869.bin 224 224 +29099 ./prep_dataset/ILSVRC2012_val_00030305.bin 224 224 +29100 ./prep_dataset/ILSVRC2012_val_00000485.bin 224 224 +29101 ./prep_dataset/ILSVRC2012_val_00043620.bin 224 224 +29102 ./prep_dataset/ILSVRC2012_val_00022113.bin 224 224 +29103 ./prep_dataset/ILSVRC2012_val_00003421.bin 224 224 +29104 ./prep_dataset/ILSVRC2012_val_00001603.bin 224 224 +29105 ./prep_dataset/ILSVRC2012_val_00020833.bin 224 224 +29106 ./prep_dataset/ILSVRC2012_val_00037976.bin 224 224 +29107 ./prep_dataset/ILSVRC2012_val_00028868.bin 224 224 +29108 ./prep_dataset/ILSVRC2012_val_00032862.bin 224 224 +29109 ./prep_dataset/ILSVRC2012_val_00047439.bin 224 224 +29110 ./prep_dataset/ILSVRC2012_val_00004280.bin 224 224 +29111 ./prep_dataset/ILSVRC2012_val_00000231.bin 224 224 +29112 ./prep_dataset/ILSVRC2012_val_00031385.bin 224 224 +29113 ./prep_dataset/ILSVRC2012_val_00009721.bin 224 224 +29114 ./prep_dataset/ILSVRC2012_val_00048902.bin 224 224 +29115 ./prep_dataset/ILSVRC2012_val_00025607.bin 224 224 +29116 ./prep_dataset/ILSVRC2012_val_00032226.bin 224 224 +29117 ./prep_dataset/ILSVRC2012_val_00004777.bin 224 224 +29118 ./prep_dataset/ILSVRC2012_val_00034012.bin 224 224 +29119 ./prep_dataset/ILSVRC2012_val_00003825.bin 224 224 +29120 ./prep_dataset/ILSVRC2012_val_00031229.bin 224 224 +29121 ./prep_dataset/ILSVRC2012_val_00008613.bin 224 224 +29122 ./prep_dataset/ILSVRC2012_val_00023329.bin 224 224 +29123 ./prep_dataset/ILSVRC2012_val_00033138.bin 224 224 +29124 ./prep_dataset/ILSVRC2012_val_00020180.bin 224 224 +29125 ./prep_dataset/ILSVRC2012_val_00029433.bin 224 224 +29126 ./prep_dataset/ILSVRC2012_val_00013370.bin 224 224 +29127 ./prep_dataset/ILSVRC2012_val_00043879.bin 224 224 +29128 ./prep_dataset/ILSVRC2012_val_00041076.bin 224 224 +29129 ./prep_dataset/ILSVRC2012_val_00046048.bin 224 224 +29130 ./prep_dataset/ILSVRC2012_val_00026663.bin 224 224 +29131 ./prep_dataset/ILSVRC2012_val_00022886.bin 224 224 +29132 ./prep_dataset/ILSVRC2012_val_00015708.bin 224 224 +29133 ./prep_dataset/ILSVRC2012_val_00037473.bin 224 224 +29134 ./prep_dataset/ILSVRC2012_val_00021544.bin 224 224 +29135 ./prep_dataset/ILSVRC2012_val_00005491.bin 224 224 +29136 ./prep_dataset/ILSVRC2012_val_00018283.bin 224 224 +29137 ./prep_dataset/ILSVRC2012_val_00025089.bin 224 224 +29138 ./prep_dataset/ILSVRC2012_val_00045307.bin 224 224 +29139 ./prep_dataset/ILSVRC2012_val_00001165.bin 224 224 +29140 ./prep_dataset/ILSVRC2012_val_00011692.bin 224 224 +29141 ./prep_dataset/ILSVRC2012_val_00025160.bin 224 224 +29142 ./prep_dataset/ILSVRC2012_val_00008010.bin 224 224 +29143 ./prep_dataset/ILSVRC2012_val_00032474.bin 224 224 +29144 ./prep_dataset/ILSVRC2012_val_00001491.bin 224 224 +29145 ./prep_dataset/ILSVRC2012_val_00037831.bin 224 224 +29146 ./prep_dataset/ILSVRC2012_val_00036363.bin 224 224 +29147 ./prep_dataset/ILSVRC2012_val_00033406.bin 224 224 +29148 ./prep_dataset/ILSVRC2012_val_00043064.bin 224 224 +29149 ./prep_dataset/ILSVRC2012_val_00029623.bin 224 224 +29150 ./prep_dataset/ILSVRC2012_val_00030223.bin 224 224 +29151 ./prep_dataset/ILSVRC2012_val_00043443.bin 224 224 +29152 ./prep_dataset/ILSVRC2012_val_00009141.bin 224 224 +29153 ./prep_dataset/ILSVRC2012_val_00047352.bin 224 224 +29154 ./prep_dataset/ILSVRC2012_val_00014769.bin 224 224 +29155 ./prep_dataset/ILSVRC2012_val_00025090.bin 224 224 +29156 ./prep_dataset/ILSVRC2012_val_00003005.bin 224 224 +29157 ./prep_dataset/ILSVRC2012_val_00047255.bin 224 224 +29158 ./prep_dataset/ILSVRC2012_val_00005482.bin 224 224 +29159 ./prep_dataset/ILSVRC2012_val_00008942.bin 224 224 +29160 ./prep_dataset/ILSVRC2012_val_00002914.bin 224 224 +29161 ./prep_dataset/ILSVRC2012_val_00032929.bin 224 224 +29162 ./prep_dataset/ILSVRC2012_val_00009320.bin 224 224 +29163 ./prep_dataset/ILSVRC2012_val_00021703.bin 224 224 +29164 ./prep_dataset/ILSVRC2012_val_00002493.bin 224 224 +29165 ./prep_dataset/ILSVRC2012_val_00041995.bin 224 224 +29166 ./prep_dataset/ILSVRC2012_val_00006985.bin 224 224 +29167 ./prep_dataset/ILSVRC2012_val_00047067.bin 224 224 +29168 ./prep_dataset/ILSVRC2012_val_00012109.bin 224 224 +29169 ./prep_dataset/ILSVRC2012_val_00019654.bin 224 224 +29170 ./prep_dataset/ILSVRC2012_val_00046962.bin 224 224 +29171 ./prep_dataset/ILSVRC2012_val_00003124.bin 224 224 +29172 ./prep_dataset/ILSVRC2012_val_00045424.bin 224 224 +29173 ./prep_dataset/ILSVRC2012_val_00039640.bin 224 224 +29174 ./prep_dataset/ILSVRC2012_val_00002034.bin 224 224 +29175 ./prep_dataset/ILSVRC2012_val_00035872.bin 224 224 +29176 ./prep_dataset/ILSVRC2012_val_00043349.bin 224 224 +29177 ./prep_dataset/ILSVRC2012_val_00005258.bin 224 224 +29178 ./prep_dataset/ILSVRC2012_val_00006184.bin 224 224 +29179 ./prep_dataset/ILSVRC2012_val_00037655.bin 224 224 +29180 ./prep_dataset/ILSVRC2012_val_00024530.bin 224 224 +29181 ./prep_dataset/ILSVRC2012_val_00049816.bin 224 224 +29182 ./prep_dataset/ILSVRC2012_val_00010031.bin 224 224 +29183 ./prep_dataset/ILSVRC2012_val_00036429.bin 224 224 +29184 ./prep_dataset/ILSVRC2012_val_00048413.bin 224 224 +29185 ./prep_dataset/ILSVRC2012_val_00010979.bin 224 224 +29186 ./prep_dataset/ILSVRC2012_val_00014188.bin 224 224 +29187 ./prep_dataset/ILSVRC2012_val_00000346.bin 224 224 +29188 ./prep_dataset/ILSVRC2012_val_00032545.bin 224 224 +29189 ./prep_dataset/ILSVRC2012_val_00045293.bin 224 224 +29190 ./prep_dataset/ILSVRC2012_val_00022647.bin 224 224 +29191 ./prep_dataset/ILSVRC2012_val_00039624.bin 224 224 +29192 ./prep_dataset/ILSVRC2012_val_00040796.bin 224 224 +29193 ./prep_dataset/ILSVRC2012_val_00026549.bin 224 224 +29194 ./prep_dataset/ILSVRC2012_val_00004554.bin 224 224 +29195 ./prep_dataset/ILSVRC2012_val_00016341.bin 224 224 +29196 ./prep_dataset/ILSVRC2012_val_00021866.bin 224 224 +29197 ./prep_dataset/ILSVRC2012_val_00001081.bin 224 224 +29198 ./prep_dataset/ILSVRC2012_val_00014603.bin 224 224 +29199 ./prep_dataset/ILSVRC2012_val_00026708.bin 224 224 +29200 ./prep_dataset/ILSVRC2012_val_00005550.bin 224 224 +29201 ./prep_dataset/ILSVRC2012_val_00033682.bin 224 224 +29202 ./prep_dataset/ILSVRC2012_val_00014523.bin 224 224 +29203 ./prep_dataset/ILSVRC2012_val_00033594.bin 224 224 +29204 ./prep_dataset/ILSVRC2012_val_00021048.bin 224 224 +29205 ./prep_dataset/ILSVRC2012_val_00022378.bin 224 224 +29206 ./prep_dataset/ILSVRC2012_val_00028091.bin 224 224 +29207 ./prep_dataset/ILSVRC2012_val_00044879.bin 224 224 +29208 ./prep_dataset/ILSVRC2012_val_00041034.bin 224 224 +29209 ./prep_dataset/ILSVRC2012_val_00049389.bin 224 224 +29210 ./prep_dataset/ILSVRC2012_val_00049993.bin 224 224 +29211 ./prep_dataset/ILSVRC2012_val_00025241.bin 224 224 +29212 ./prep_dataset/ILSVRC2012_val_00005864.bin 224 224 +29213 ./prep_dataset/ILSVRC2012_val_00027855.bin 224 224 +29214 ./prep_dataset/ILSVRC2012_val_00039137.bin 224 224 +29215 ./prep_dataset/ILSVRC2012_val_00019611.bin 224 224 +29216 ./prep_dataset/ILSVRC2012_val_00008483.bin 224 224 +29217 ./prep_dataset/ILSVRC2012_val_00011085.bin 224 224 +29218 ./prep_dataset/ILSVRC2012_val_00000432.bin 224 224 +29219 ./prep_dataset/ILSVRC2012_val_00042749.bin 224 224 +29220 ./prep_dataset/ILSVRC2012_val_00016120.bin 224 224 +29221 ./prep_dataset/ILSVRC2012_val_00018840.bin 224 224 +29222 ./prep_dataset/ILSVRC2012_val_00038256.bin 224 224 +29223 ./prep_dataset/ILSVRC2012_val_00008855.bin 224 224 +29224 ./prep_dataset/ILSVRC2012_val_00032679.bin 224 224 +29225 ./prep_dataset/ILSVRC2012_val_00019616.bin 224 224 +29226 ./prep_dataset/ILSVRC2012_val_00027384.bin 224 224 +29227 ./prep_dataset/ILSVRC2012_val_00003947.bin 224 224 +29228 ./prep_dataset/ILSVRC2012_val_00013076.bin 224 224 +29229 ./prep_dataset/ILSVRC2012_val_00017846.bin 224 224 +29230 ./prep_dataset/ILSVRC2012_val_00047720.bin 224 224 +29231 ./prep_dataset/ILSVRC2012_val_00014666.bin 224 224 +29232 ./prep_dataset/ILSVRC2012_val_00040152.bin 224 224 +29233 ./prep_dataset/ILSVRC2012_val_00017195.bin 224 224 +29234 ./prep_dataset/ILSVRC2012_val_00036313.bin 224 224 +29235 ./prep_dataset/ILSVRC2012_val_00018514.bin 224 224 +29236 ./prep_dataset/ILSVRC2012_val_00033003.bin 224 224 +29237 ./prep_dataset/ILSVRC2012_val_00020435.bin 224 224 +29238 ./prep_dataset/ILSVRC2012_val_00025154.bin 224 224 +29239 ./prep_dataset/ILSVRC2012_val_00016281.bin 224 224 +29240 ./prep_dataset/ILSVRC2012_val_00019158.bin 224 224 +29241 ./prep_dataset/ILSVRC2012_val_00003549.bin 224 224 +29242 ./prep_dataset/ILSVRC2012_val_00042487.bin 224 224 +29243 ./prep_dataset/ILSVRC2012_val_00040124.bin 224 224 +29244 ./prep_dataset/ILSVRC2012_val_00027856.bin 224 224 +29245 ./prep_dataset/ILSVRC2012_val_00041609.bin 224 224 +29246 ./prep_dataset/ILSVRC2012_val_00028625.bin 224 224 +29247 ./prep_dataset/ILSVRC2012_val_00043986.bin 224 224 +29248 ./prep_dataset/ILSVRC2012_val_00034285.bin 224 224 +29249 ./prep_dataset/ILSVRC2012_val_00001480.bin 224 224 +29250 ./prep_dataset/ILSVRC2012_val_00006931.bin 224 224 +29251 ./prep_dataset/ILSVRC2012_val_00005053.bin 224 224 +29252 ./prep_dataset/ILSVRC2012_val_00019597.bin 224 224 +29253 ./prep_dataset/ILSVRC2012_val_00017270.bin 224 224 +29254 ./prep_dataset/ILSVRC2012_val_00004457.bin 224 224 +29255 ./prep_dataset/ILSVRC2012_val_00020717.bin 224 224 +29256 ./prep_dataset/ILSVRC2012_val_00034077.bin 224 224 +29257 ./prep_dataset/ILSVRC2012_val_00045405.bin 224 224 +29258 ./prep_dataset/ILSVRC2012_val_00022752.bin 224 224 +29259 ./prep_dataset/ILSVRC2012_val_00008273.bin 224 224 +29260 ./prep_dataset/ILSVRC2012_val_00040311.bin 224 224 +29261 ./prep_dataset/ILSVRC2012_val_00045752.bin 224 224 +29262 ./prep_dataset/ILSVRC2012_val_00005107.bin 224 224 +29263 ./prep_dataset/ILSVRC2012_val_00042624.bin 224 224 +29264 ./prep_dataset/ILSVRC2012_val_00001474.bin 224 224 +29265 ./prep_dataset/ILSVRC2012_val_00037877.bin 224 224 +29266 ./prep_dataset/ILSVRC2012_val_00047027.bin 224 224 +29267 ./prep_dataset/ILSVRC2012_val_00039839.bin 224 224 +29268 ./prep_dataset/ILSVRC2012_val_00008976.bin 224 224 +29269 ./prep_dataset/ILSVRC2012_val_00024895.bin 224 224 +29270 ./prep_dataset/ILSVRC2012_val_00047802.bin 224 224 +29271 ./prep_dataset/ILSVRC2012_val_00039486.bin 224 224 +29272 ./prep_dataset/ILSVRC2012_val_00009949.bin 224 224 +29273 ./prep_dataset/ILSVRC2012_val_00000865.bin 224 224 +29274 ./prep_dataset/ILSVRC2012_val_00040297.bin 224 224 +29275 ./prep_dataset/ILSVRC2012_val_00031090.bin 224 224 +29276 ./prep_dataset/ILSVRC2012_val_00039290.bin 224 224 +29277 ./prep_dataset/ILSVRC2012_val_00001202.bin 224 224 +29278 ./prep_dataset/ILSVRC2012_val_00014422.bin 224 224 +29279 ./prep_dataset/ILSVRC2012_val_00024102.bin 224 224 +29280 ./prep_dataset/ILSVRC2012_val_00017977.bin 224 224 +29281 ./prep_dataset/ILSVRC2012_val_00019699.bin 224 224 +29282 ./prep_dataset/ILSVRC2012_val_00002216.bin 224 224 +29283 ./prep_dataset/ILSVRC2012_val_00020842.bin 224 224 +29284 ./prep_dataset/ILSVRC2012_val_00004292.bin 224 224 +29285 ./prep_dataset/ILSVRC2012_val_00045406.bin 224 224 +29286 ./prep_dataset/ILSVRC2012_val_00000624.bin 224 224 +29287 ./prep_dataset/ILSVRC2012_val_00020404.bin 224 224 +29288 ./prep_dataset/ILSVRC2012_val_00007359.bin 224 224 +29289 ./prep_dataset/ILSVRC2012_val_00030315.bin 224 224 +29290 ./prep_dataset/ILSVRC2012_val_00049569.bin 224 224 +29291 ./prep_dataset/ILSVRC2012_val_00012280.bin 224 224 +29292 ./prep_dataset/ILSVRC2012_val_00047659.bin 224 224 +29293 ./prep_dataset/ILSVRC2012_val_00012245.bin 224 224 +29294 ./prep_dataset/ILSVRC2012_val_00049978.bin 224 224 +29295 ./prep_dataset/ILSVRC2012_val_00019829.bin 224 224 +29296 ./prep_dataset/ILSVRC2012_val_00001224.bin 224 224 +29297 ./prep_dataset/ILSVRC2012_val_00007341.bin 224 224 +29298 ./prep_dataset/ILSVRC2012_val_00003519.bin 224 224 +29299 ./prep_dataset/ILSVRC2012_val_00043011.bin 224 224 +29300 ./prep_dataset/ILSVRC2012_val_00021997.bin 224 224 +29301 ./prep_dataset/ILSVRC2012_val_00047619.bin 224 224 +29302 ./prep_dataset/ILSVRC2012_val_00033824.bin 224 224 +29303 ./prep_dataset/ILSVRC2012_val_00028689.bin 224 224 +29304 ./prep_dataset/ILSVRC2012_val_00020536.bin 224 224 +29305 ./prep_dataset/ILSVRC2012_val_00024738.bin 224 224 +29306 ./prep_dataset/ILSVRC2012_val_00018870.bin 224 224 +29307 ./prep_dataset/ILSVRC2012_val_00030721.bin 224 224 +29308 ./prep_dataset/ILSVRC2012_val_00029098.bin 224 224 +29309 ./prep_dataset/ILSVRC2012_val_00009618.bin 224 224 +29310 ./prep_dataset/ILSVRC2012_val_00047678.bin 224 224 +29311 ./prep_dataset/ILSVRC2012_val_00023212.bin 224 224 +29312 ./prep_dataset/ILSVRC2012_val_00032577.bin 224 224 +29313 ./prep_dataset/ILSVRC2012_val_00024246.bin 224 224 +29314 ./prep_dataset/ILSVRC2012_val_00027113.bin 224 224 +29315 ./prep_dataset/ILSVRC2012_val_00017632.bin 224 224 +29316 ./prep_dataset/ILSVRC2012_val_00049987.bin 224 224 +29317 ./prep_dataset/ILSVRC2012_val_00008141.bin 224 224 +29318 ./prep_dataset/ILSVRC2012_val_00036928.bin 224 224 +29319 ./prep_dataset/ILSVRC2012_val_00041861.bin 224 224 +29320 ./prep_dataset/ILSVRC2012_val_00025043.bin 224 224 +29321 ./prep_dataset/ILSVRC2012_val_00019723.bin 224 224 +29322 ./prep_dataset/ILSVRC2012_val_00039861.bin 224 224 +29323 ./prep_dataset/ILSVRC2012_val_00007861.bin 224 224 +29324 ./prep_dataset/ILSVRC2012_val_00046979.bin 224 224 +29325 ./prep_dataset/ILSVRC2012_val_00025730.bin 224 224 +29326 ./prep_dataset/ILSVRC2012_val_00007431.bin 224 224 +29327 ./prep_dataset/ILSVRC2012_val_00038981.bin 224 224 +29328 ./prep_dataset/ILSVRC2012_val_00038298.bin 224 224 +29329 ./prep_dataset/ILSVRC2012_val_00041089.bin 224 224 +29330 ./prep_dataset/ILSVRC2012_val_00027064.bin 224 224 +29331 ./prep_dataset/ILSVRC2012_val_00005587.bin 224 224 +29332 ./prep_dataset/ILSVRC2012_val_00041178.bin 224 224 +29333 ./prep_dataset/ILSVRC2012_val_00017783.bin 224 224 +29334 ./prep_dataset/ILSVRC2012_val_00028426.bin 224 224 +29335 ./prep_dataset/ILSVRC2012_val_00039541.bin 224 224 +29336 ./prep_dataset/ILSVRC2012_val_00030306.bin 224 224 +29337 ./prep_dataset/ILSVRC2012_val_00026463.bin 224 224 +29338 ./prep_dataset/ILSVRC2012_val_00030524.bin 224 224 +29339 ./prep_dataset/ILSVRC2012_val_00022622.bin 224 224 +29340 ./prep_dataset/ILSVRC2012_val_00002715.bin 224 224 +29341 ./prep_dataset/ILSVRC2012_val_00000746.bin 224 224 +29342 ./prep_dataset/ILSVRC2012_val_00033319.bin 224 224 +29343 ./prep_dataset/ILSVRC2012_val_00016060.bin 224 224 +29344 ./prep_dataset/ILSVRC2012_val_00017786.bin 224 224 +29345 ./prep_dataset/ILSVRC2012_val_00046630.bin 224 224 +29346 ./prep_dataset/ILSVRC2012_val_00022759.bin 224 224 +29347 ./prep_dataset/ILSVRC2012_val_00011712.bin 224 224 +29348 ./prep_dataset/ILSVRC2012_val_00048891.bin 224 224 +29349 ./prep_dataset/ILSVRC2012_val_00008710.bin 224 224 +29350 ./prep_dataset/ILSVRC2012_val_00035764.bin 224 224 +29351 ./prep_dataset/ILSVRC2012_val_00046463.bin 224 224 +29352 ./prep_dataset/ILSVRC2012_val_00041896.bin 224 224 +29353 ./prep_dataset/ILSVRC2012_val_00018247.bin 224 224 +29354 ./prep_dataset/ILSVRC2012_val_00047264.bin 224 224 +29355 ./prep_dataset/ILSVRC2012_val_00040848.bin 224 224 +29356 ./prep_dataset/ILSVRC2012_val_00049786.bin 224 224 +29357 ./prep_dataset/ILSVRC2012_val_00018239.bin 224 224 +29358 ./prep_dataset/ILSVRC2012_val_00028095.bin 224 224 +29359 ./prep_dataset/ILSVRC2012_val_00041229.bin 224 224 +29360 ./prep_dataset/ILSVRC2012_val_00014394.bin 224 224 +29361 ./prep_dataset/ILSVRC2012_val_00040690.bin 224 224 +29362 ./prep_dataset/ILSVRC2012_val_00023455.bin 224 224 +29363 ./prep_dataset/ILSVRC2012_val_00045889.bin 224 224 +29364 ./prep_dataset/ILSVRC2012_val_00043478.bin 224 224 +29365 ./prep_dataset/ILSVRC2012_val_00034272.bin 224 224 +29366 ./prep_dataset/ILSVRC2012_val_00016853.bin 224 224 +29367 ./prep_dataset/ILSVRC2012_val_00039350.bin 224 224 +29368 ./prep_dataset/ILSVRC2012_val_00037529.bin 224 224 +29369 ./prep_dataset/ILSVRC2012_val_00008682.bin 224 224 +29370 ./prep_dataset/ILSVRC2012_val_00024667.bin 224 224 +29371 ./prep_dataset/ILSVRC2012_val_00047453.bin 224 224 +29372 ./prep_dataset/ILSVRC2012_val_00009582.bin 224 224 +29373 ./prep_dataset/ILSVRC2012_val_00014369.bin 224 224 +29374 ./prep_dataset/ILSVRC2012_val_00035715.bin 224 224 +29375 ./prep_dataset/ILSVRC2012_val_00010880.bin 224 224 +29376 ./prep_dataset/ILSVRC2012_val_00028711.bin 224 224 +29377 ./prep_dataset/ILSVRC2012_val_00004287.bin 224 224 +29378 ./prep_dataset/ILSVRC2012_val_00038976.bin 224 224 +29379 ./prep_dataset/ILSVRC2012_val_00003914.bin 224 224 +29380 ./prep_dataset/ILSVRC2012_val_00048187.bin 224 224 +29381 ./prep_dataset/ILSVRC2012_val_00006984.bin 224 224 +29382 ./prep_dataset/ILSVRC2012_val_00015504.bin 224 224 +29383 ./prep_dataset/ILSVRC2012_val_00032069.bin 224 224 +29384 ./prep_dataset/ILSVRC2012_val_00031131.bin 224 224 +29385 ./prep_dataset/ILSVRC2012_val_00013178.bin 224 224 +29386 ./prep_dataset/ILSVRC2012_val_00041363.bin 224 224 +29387 ./prep_dataset/ILSVRC2012_val_00025128.bin 224 224 +29388 ./prep_dataset/ILSVRC2012_val_00044030.bin 224 224 +29389 ./prep_dataset/ILSVRC2012_val_00013919.bin 224 224 +29390 ./prep_dataset/ILSVRC2012_val_00015129.bin 224 224 +29391 ./prep_dataset/ILSVRC2012_val_00014411.bin 224 224 +29392 ./prep_dataset/ILSVRC2012_val_00028974.bin 224 224 +29393 ./prep_dataset/ILSVRC2012_val_00005227.bin 224 224 +29394 ./prep_dataset/ILSVRC2012_val_00021386.bin 224 224 +29395 ./prep_dataset/ILSVRC2012_val_00023733.bin 224 224 +29396 ./prep_dataset/ILSVRC2012_val_00024619.bin 224 224 +29397 ./prep_dataset/ILSVRC2012_val_00019441.bin 224 224 +29398 ./prep_dataset/ILSVRC2012_val_00046776.bin 224 224 +29399 ./prep_dataset/ILSVRC2012_val_00037560.bin 224 224 +29400 ./prep_dataset/ILSVRC2012_val_00018390.bin 224 224 +29401 ./prep_dataset/ILSVRC2012_val_00028651.bin 224 224 +29402 ./prep_dataset/ILSVRC2012_val_00002006.bin 224 224 +29403 ./prep_dataset/ILSVRC2012_val_00004744.bin 224 224 +29404 ./prep_dataset/ILSVRC2012_val_00014563.bin 224 224 +29405 ./prep_dataset/ILSVRC2012_val_00024114.bin 224 224 +29406 ./prep_dataset/ILSVRC2012_val_00041065.bin 224 224 +29407 ./prep_dataset/ILSVRC2012_val_00007133.bin 224 224 +29408 ./prep_dataset/ILSVRC2012_val_00002789.bin 224 224 +29409 ./prep_dataset/ILSVRC2012_val_00044698.bin 224 224 +29410 ./prep_dataset/ILSVRC2012_val_00031033.bin 224 224 +29411 ./prep_dataset/ILSVRC2012_val_00031999.bin 224 224 +29412 ./prep_dataset/ILSVRC2012_val_00049415.bin 224 224 +29413 ./prep_dataset/ILSVRC2012_val_00007523.bin 224 224 +29414 ./prep_dataset/ILSVRC2012_val_00007852.bin 224 224 +29415 ./prep_dataset/ILSVRC2012_val_00012412.bin 224 224 +29416 ./prep_dataset/ILSVRC2012_val_00047634.bin 224 224 +29417 ./prep_dataset/ILSVRC2012_val_00018790.bin 224 224 +29418 ./prep_dataset/ILSVRC2012_val_00006654.bin 224 224 +29419 ./prep_dataset/ILSVRC2012_val_00005724.bin 224 224 +29420 ./prep_dataset/ILSVRC2012_val_00018201.bin 224 224 +29421 ./prep_dataset/ILSVRC2012_val_00039119.bin 224 224 +29422 ./prep_dataset/ILSVRC2012_val_00049449.bin 224 224 +29423 ./prep_dataset/ILSVRC2012_val_00011780.bin 224 224 +29424 ./prep_dataset/ILSVRC2012_val_00023110.bin 224 224 +29425 ./prep_dataset/ILSVRC2012_val_00042890.bin 224 224 +29426 ./prep_dataset/ILSVRC2012_val_00013567.bin 224 224 +29427 ./prep_dataset/ILSVRC2012_val_00034401.bin 224 224 +29428 ./prep_dataset/ILSVRC2012_val_00006513.bin 224 224 +29429 ./prep_dataset/ILSVRC2012_val_00001908.bin 224 224 +29430 ./prep_dataset/ILSVRC2012_val_00025382.bin 224 224 +29431 ./prep_dataset/ILSVRC2012_val_00046861.bin 224 224 +29432 ./prep_dataset/ILSVRC2012_val_00049866.bin 224 224 +29433 ./prep_dataset/ILSVRC2012_val_00030176.bin 224 224 +29434 ./prep_dataset/ILSVRC2012_val_00020315.bin 224 224 +29435 ./prep_dataset/ILSVRC2012_val_00033854.bin 224 224 +29436 ./prep_dataset/ILSVRC2012_val_00046603.bin 224 224 +29437 ./prep_dataset/ILSVRC2012_val_00046937.bin 224 224 +29438 ./prep_dataset/ILSVRC2012_val_00035805.bin 224 224 +29439 ./prep_dataset/ILSVRC2012_val_00039552.bin 224 224 +29440 ./prep_dataset/ILSVRC2012_val_00003488.bin 224 224 +29441 ./prep_dataset/ILSVRC2012_val_00042467.bin 224 224 +29442 ./prep_dataset/ILSVRC2012_val_00043803.bin 224 224 +29443 ./prep_dataset/ILSVRC2012_val_00003984.bin 224 224 +29444 ./prep_dataset/ILSVRC2012_val_00015392.bin 224 224 +29445 ./prep_dataset/ILSVRC2012_val_00002667.bin 224 224 +29446 ./prep_dataset/ILSVRC2012_val_00003406.bin 224 224 +29447 ./prep_dataset/ILSVRC2012_val_00012915.bin 224 224 +29448 ./prep_dataset/ILSVRC2012_val_00042050.bin 224 224 +29449 ./prep_dataset/ILSVRC2012_val_00008516.bin 224 224 +29450 ./prep_dataset/ILSVRC2012_val_00020489.bin 224 224 +29451 ./prep_dataset/ILSVRC2012_val_00011778.bin 224 224 +29452 ./prep_dataset/ILSVRC2012_val_00033127.bin 224 224 +29453 ./prep_dataset/ILSVRC2012_val_00002410.bin 224 224 +29454 ./prep_dataset/ILSVRC2012_val_00046312.bin 224 224 +29455 ./prep_dataset/ILSVRC2012_val_00031707.bin 224 224 +29456 ./prep_dataset/ILSVRC2012_val_00030196.bin 224 224 +29457 ./prep_dataset/ILSVRC2012_val_00030319.bin 224 224 +29458 ./prep_dataset/ILSVRC2012_val_00037870.bin 224 224 +29459 ./prep_dataset/ILSVRC2012_val_00017546.bin 224 224 +29460 ./prep_dataset/ILSVRC2012_val_00013832.bin 224 224 +29461 ./prep_dataset/ILSVRC2012_val_00006066.bin 224 224 +29462 ./prep_dataset/ILSVRC2012_val_00047778.bin 224 224 +29463 ./prep_dataset/ILSVRC2012_val_00017999.bin 224 224 +29464 ./prep_dataset/ILSVRC2012_val_00022745.bin 224 224 +29465 ./prep_dataset/ILSVRC2012_val_00003683.bin 224 224 +29466 ./prep_dataset/ILSVRC2012_val_00043823.bin 224 224 +29467 ./prep_dataset/ILSVRC2012_val_00048560.bin 224 224 +29468 ./prep_dataset/ILSVRC2012_val_00044977.bin 224 224 +29469 ./prep_dataset/ILSVRC2012_val_00028137.bin 224 224 +29470 ./prep_dataset/ILSVRC2012_val_00026696.bin 224 224 +29471 ./prep_dataset/ILSVRC2012_val_00039517.bin 224 224 +29472 ./prep_dataset/ILSVRC2012_val_00024281.bin 224 224 +29473 ./prep_dataset/ILSVRC2012_val_00003309.bin 224 224 +29474 ./prep_dataset/ILSVRC2012_val_00043709.bin 224 224 +29475 ./prep_dataset/ILSVRC2012_val_00006271.bin 224 224 +29476 ./prep_dataset/ILSVRC2012_val_00038654.bin 224 224 +29477 ./prep_dataset/ILSVRC2012_val_00041276.bin 224 224 +29478 ./prep_dataset/ILSVRC2012_val_00022583.bin 224 224 +29479 ./prep_dataset/ILSVRC2012_val_00020805.bin 224 224 +29480 ./prep_dataset/ILSVRC2012_val_00029471.bin 224 224 +29481 ./prep_dataset/ILSVRC2012_val_00017300.bin 224 224 +29482 ./prep_dataset/ILSVRC2012_val_00012122.bin 224 224 +29483 ./prep_dataset/ILSVRC2012_val_00005290.bin 224 224 +29484 ./prep_dataset/ILSVRC2012_val_00000391.bin 224 224 +29485 ./prep_dataset/ILSVRC2012_val_00002903.bin 224 224 +29486 ./prep_dataset/ILSVRC2012_val_00038842.bin 224 224 +29487 ./prep_dataset/ILSVRC2012_val_00014199.bin 224 224 +29488 ./prep_dataset/ILSVRC2012_val_00031833.bin 224 224 +29489 ./prep_dataset/ILSVRC2012_val_00049921.bin 224 224 +29490 ./prep_dataset/ILSVRC2012_val_00010274.bin 224 224 +29491 ./prep_dataset/ILSVRC2012_val_00043728.bin 224 224 +29492 ./prep_dataset/ILSVRC2012_val_00027148.bin 224 224 +29493 ./prep_dataset/ILSVRC2012_val_00040640.bin 224 224 +29494 ./prep_dataset/ILSVRC2012_val_00038207.bin 224 224 +29495 ./prep_dataset/ILSVRC2012_val_00041781.bin 224 224 +29496 ./prep_dataset/ILSVRC2012_val_00017563.bin 224 224 +29497 ./prep_dataset/ILSVRC2012_val_00028183.bin 224 224 +29498 ./prep_dataset/ILSVRC2012_val_00033531.bin 224 224 +29499 ./prep_dataset/ILSVRC2012_val_00033542.bin 224 224 +29500 ./prep_dataset/ILSVRC2012_val_00043076.bin 224 224 +29501 ./prep_dataset/ILSVRC2012_val_00049367.bin 224 224 +29502 ./prep_dataset/ILSVRC2012_val_00024116.bin 224 224 +29503 ./prep_dataset/ILSVRC2012_val_00031446.bin 224 224 +29504 ./prep_dataset/ILSVRC2012_val_00049542.bin 224 224 +29505 ./prep_dataset/ILSVRC2012_val_00008018.bin 224 224 +29506 ./prep_dataset/ILSVRC2012_val_00000971.bin 224 224 +29507 ./prep_dataset/ILSVRC2012_val_00006972.bin 224 224 +29508 ./prep_dataset/ILSVRC2012_val_00032928.bin 224 224 +29509 ./prep_dataset/ILSVRC2012_val_00033475.bin 224 224 +29510 ./prep_dataset/ILSVRC2012_val_00042577.bin 224 224 +29511 ./prep_dataset/ILSVRC2012_val_00008044.bin 224 224 +29512 ./prep_dataset/ILSVRC2012_val_00030921.bin 224 224 +29513 ./prep_dataset/ILSVRC2012_val_00033398.bin 224 224 +29514 ./prep_dataset/ILSVRC2012_val_00048056.bin 224 224 +29515 ./prep_dataset/ILSVRC2012_val_00037277.bin 224 224 +29516 ./prep_dataset/ILSVRC2012_val_00012339.bin 224 224 +29517 ./prep_dataset/ILSVRC2012_val_00043408.bin 224 224 +29518 ./prep_dataset/ILSVRC2012_val_00044267.bin 224 224 +29519 ./prep_dataset/ILSVRC2012_val_00032367.bin 224 224 +29520 ./prep_dataset/ILSVRC2012_val_00017282.bin 224 224 +29521 ./prep_dataset/ILSVRC2012_val_00005665.bin 224 224 +29522 ./prep_dataset/ILSVRC2012_val_00038475.bin 224 224 +29523 ./prep_dataset/ILSVRC2012_val_00039473.bin 224 224 +29524 ./prep_dataset/ILSVRC2012_val_00007150.bin 224 224 +29525 ./prep_dataset/ILSVRC2012_val_00028131.bin 224 224 +29526 ./prep_dataset/ILSVRC2012_val_00009727.bin 224 224 +29527 ./prep_dataset/ILSVRC2012_val_00024192.bin 224 224 +29528 ./prep_dataset/ILSVRC2012_val_00037192.bin 224 224 +29529 ./prep_dataset/ILSVRC2012_val_00043473.bin 224 224 +29530 ./prep_dataset/ILSVRC2012_val_00016004.bin 224 224 +29531 ./prep_dataset/ILSVRC2012_val_00040475.bin 224 224 +29532 ./prep_dataset/ILSVRC2012_val_00027327.bin 224 224 +29533 ./prep_dataset/ILSVRC2012_val_00006997.bin 224 224 +29534 ./prep_dataset/ILSVRC2012_val_00032523.bin 224 224 +29535 ./prep_dataset/ILSVRC2012_val_00032692.bin 224 224 +29536 ./prep_dataset/ILSVRC2012_val_00014300.bin 224 224 +29537 ./prep_dataset/ILSVRC2012_val_00042193.bin 224 224 +29538 ./prep_dataset/ILSVRC2012_val_00040486.bin 224 224 +29539 ./prep_dataset/ILSVRC2012_val_00007619.bin 224 224 +29540 ./prep_dataset/ILSVRC2012_val_00046859.bin 224 224 +29541 ./prep_dataset/ILSVRC2012_val_00019840.bin 224 224 +29542 ./prep_dataset/ILSVRC2012_val_00001180.bin 224 224 +29543 ./prep_dataset/ILSVRC2012_val_00003637.bin 224 224 +29544 ./prep_dataset/ILSVRC2012_val_00016417.bin 224 224 +29545 ./prep_dataset/ILSVRC2012_val_00005896.bin 224 224 +29546 ./prep_dataset/ILSVRC2012_val_00045987.bin 224 224 +29547 ./prep_dataset/ILSVRC2012_val_00033220.bin 224 224 +29548 ./prep_dataset/ILSVRC2012_val_00015813.bin 224 224 +29549 ./prep_dataset/ILSVRC2012_val_00011034.bin 224 224 +29550 ./prep_dataset/ILSVRC2012_val_00002091.bin 224 224 +29551 ./prep_dataset/ILSVRC2012_val_00001931.bin 224 224 +29552 ./prep_dataset/ILSVRC2012_val_00033699.bin 224 224 +29553 ./prep_dataset/ILSVRC2012_val_00015903.bin 224 224 +29554 ./prep_dataset/ILSVRC2012_val_00030463.bin 224 224 +29555 ./prep_dataset/ILSVRC2012_val_00018740.bin 224 224 +29556 ./prep_dataset/ILSVRC2012_val_00039535.bin 224 224 +29557 ./prep_dataset/ILSVRC2012_val_00024374.bin 224 224 +29558 ./prep_dataset/ILSVRC2012_val_00033549.bin 224 224 +29559 ./prep_dataset/ILSVRC2012_val_00002916.bin 224 224 +29560 ./prep_dataset/ILSVRC2012_val_00041400.bin 224 224 +29561 ./prep_dataset/ILSVRC2012_val_00016987.bin 224 224 +29562 ./prep_dataset/ILSVRC2012_val_00045436.bin 224 224 +29563 ./prep_dataset/ILSVRC2012_val_00017019.bin 224 224 +29564 ./prep_dataset/ILSVRC2012_val_00026080.bin 224 224 +29565 ./prep_dataset/ILSVRC2012_val_00004531.bin 224 224 +29566 ./prep_dataset/ILSVRC2012_val_00036198.bin 224 224 +29567 ./prep_dataset/ILSVRC2012_val_00001915.bin 224 224 +29568 ./prep_dataset/ILSVRC2012_val_00023854.bin 224 224 +29569 ./prep_dataset/ILSVRC2012_val_00012995.bin 224 224 +29570 ./prep_dataset/ILSVRC2012_val_00030631.bin 224 224 +29571 ./prep_dataset/ILSVRC2012_val_00012336.bin 224 224 +29572 ./prep_dataset/ILSVRC2012_val_00011552.bin 224 224 +29573 ./prep_dataset/ILSVRC2012_val_00037585.bin 224 224 +29574 ./prep_dataset/ILSVRC2012_val_00014178.bin 224 224 +29575 ./prep_dataset/ILSVRC2012_val_00045271.bin 224 224 +29576 ./prep_dataset/ILSVRC2012_val_00026479.bin 224 224 +29577 ./prep_dataset/ILSVRC2012_val_00033399.bin 224 224 +29578 ./prep_dataset/ILSVRC2012_val_00010973.bin 224 224 +29579 ./prep_dataset/ILSVRC2012_val_00047599.bin 224 224 +29580 ./prep_dataset/ILSVRC2012_val_00045724.bin 224 224 +29581 ./prep_dataset/ILSVRC2012_val_00021718.bin 224 224 +29582 ./prep_dataset/ILSVRC2012_val_00002721.bin 224 224 +29583 ./prep_dataset/ILSVRC2012_val_00000230.bin 224 224 +29584 ./prep_dataset/ILSVRC2012_val_00001335.bin 224 224 +29585 ./prep_dataset/ILSVRC2012_val_00030297.bin 224 224 +29586 ./prep_dataset/ILSVRC2012_val_00041514.bin 224 224 +29587 ./prep_dataset/ILSVRC2012_val_00049677.bin 224 224 +29588 ./prep_dataset/ILSVRC2012_val_00007221.bin 224 224 +29589 ./prep_dataset/ILSVRC2012_val_00027392.bin 224 224 +29590 ./prep_dataset/ILSVRC2012_val_00041803.bin 224 224 +29591 ./prep_dataset/ILSVRC2012_val_00028828.bin 224 224 +29592 ./prep_dataset/ILSVRC2012_val_00044081.bin 224 224 +29593 ./prep_dataset/ILSVRC2012_val_00041843.bin 224 224 +29594 ./prep_dataset/ILSVRC2012_val_00007001.bin 224 224 +29595 ./prep_dataset/ILSVRC2012_val_00018861.bin 224 224 +29596 ./prep_dataset/ILSVRC2012_val_00001830.bin 224 224 +29597 ./prep_dataset/ILSVRC2012_val_00007282.bin 224 224 +29598 ./prep_dataset/ILSVRC2012_val_00018758.bin 224 224 +29599 ./prep_dataset/ILSVRC2012_val_00042177.bin 224 224 +29600 ./prep_dataset/ILSVRC2012_val_00044544.bin 224 224 +29601 ./prep_dataset/ILSVRC2012_val_00021754.bin 224 224 +29602 ./prep_dataset/ILSVRC2012_val_00015782.bin 224 224 +29603 ./prep_dataset/ILSVRC2012_val_00022002.bin 224 224 +29604 ./prep_dataset/ILSVRC2012_val_00018245.bin 224 224 +29605 ./prep_dataset/ILSVRC2012_val_00014101.bin 224 224 +29606 ./prep_dataset/ILSVRC2012_val_00035496.bin 224 224 +29607 ./prep_dataset/ILSVRC2012_val_00020520.bin 224 224 +29608 ./prep_dataset/ILSVRC2012_val_00034939.bin 224 224 +29609 ./prep_dataset/ILSVRC2012_val_00021629.bin 224 224 +29610 ./prep_dataset/ILSVRC2012_val_00025384.bin 224 224 +29611 ./prep_dataset/ILSVRC2012_val_00005271.bin 224 224 +29612 ./prep_dataset/ILSVRC2012_val_00000271.bin 224 224 +29613 ./prep_dataset/ILSVRC2012_val_00028019.bin 224 224 +29614 ./prep_dataset/ILSVRC2012_val_00020620.bin 224 224 +29615 ./prep_dataset/ILSVRC2012_val_00047911.bin 224 224 +29616 ./prep_dataset/ILSVRC2012_val_00040545.bin 224 224 +29617 ./prep_dataset/ILSVRC2012_val_00029189.bin 224 224 +29618 ./prep_dataset/ILSVRC2012_val_00045917.bin 224 224 +29619 ./prep_dataset/ILSVRC2012_val_00004279.bin 224 224 +29620 ./prep_dataset/ILSVRC2012_val_00029459.bin 224 224 +29621 ./prep_dataset/ILSVRC2012_val_00009705.bin 224 224 +29622 ./prep_dataset/ILSVRC2012_val_00000541.bin 224 224 +29623 ./prep_dataset/ILSVRC2012_val_00030538.bin 224 224 +29624 ./prep_dataset/ILSVRC2012_val_00037110.bin 224 224 +29625 ./prep_dataset/ILSVRC2012_val_00037451.bin 224 224 +29626 ./prep_dataset/ILSVRC2012_val_00035459.bin 224 224 +29627 ./prep_dataset/ILSVRC2012_val_00025738.bin 224 224 +29628 ./prep_dataset/ILSVRC2012_val_00000333.bin 224 224 +29629 ./prep_dataset/ILSVRC2012_val_00000579.bin 224 224 +29630 ./prep_dataset/ILSVRC2012_val_00039258.bin 224 224 +29631 ./prep_dataset/ILSVRC2012_val_00026603.bin 224 224 +29632 ./prep_dataset/ILSVRC2012_val_00043926.bin 224 224 +29633 ./prep_dataset/ILSVRC2012_val_00041980.bin 224 224 +29634 ./prep_dataset/ILSVRC2012_val_00046120.bin 224 224 +29635 ./prep_dataset/ILSVRC2012_val_00030640.bin 224 224 +29636 ./prep_dataset/ILSVRC2012_val_00048665.bin 224 224 +29637 ./prep_dataset/ILSVRC2012_val_00008974.bin 224 224 +29638 ./prep_dataset/ILSVRC2012_val_00001301.bin 224 224 +29639 ./prep_dataset/ILSVRC2012_val_00002971.bin 224 224 +29640 ./prep_dataset/ILSVRC2012_val_00018864.bin 224 224 +29641 ./prep_dataset/ILSVRC2012_val_00030781.bin 224 224 +29642 ./prep_dataset/ILSVRC2012_val_00045473.bin 224 224 +29643 ./prep_dataset/ILSVRC2012_val_00034354.bin 224 224 +29644 ./prep_dataset/ILSVRC2012_val_00036748.bin 224 224 +29645 ./prep_dataset/ILSVRC2012_val_00049663.bin 224 224 +29646 ./prep_dataset/ILSVRC2012_val_00000536.bin 224 224 +29647 ./prep_dataset/ILSVRC2012_val_00025100.bin 224 224 +29648 ./prep_dataset/ILSVRC2012_val_00001535.bin 224 224 +29649 ./prep_dataset/ILSVRC2012_val_00013738.bin 224 224 +29650 ./prep_dataset/ILSVRC2012_val_00025904.bin 224 224 +29651 ./prep_dataset/ILSVRC2012_val_00001809.bin 224 224 +29652 ./prep_dataset/ILSVRC2012_val_00027249.bin 224 224 +29653 ./prep_dataset/ILSVRC2012_val_00033338.bin 224 224 +29654 ./prep_dataset/ILSVRC2012_val_00027618.bin 224 224 +29655 ./prep_dataset/ILSVRC2012_val_00049980.bin 224 224 +29656 ./prep_dataset/ILSVRC2012_val_00016367.bin 224 224 +29657 ./prep_dataset/ILSVRC2012_val_00014224.bin 224 224 +29658 ./prep_dataset/ILSVRC2012_val_00007773.bin 224 224 +29659 ./prep_dataset/ILSVRC2012_val_00006205.bin 224 224 +29660 ./prep_dataset/ILSVRC2012_val_00027715.bin 224 224 +29661 ./prep_dataset/ILSVRC2012_val_00018402.bin 224 224 +29662 ./prep_dataset/ILSVRC2012_val_00039269.bin 224 224 +29663 ./prep_dataset/ILSVRC2012_val_00031922.bin 224 224 +29664 ./prep_dataset/ILSVRC2012_val_00041057.bin 224 224 +29665 ./prep_dataset/ILSVRC2012_val_00008375.bin 224 224 +29666 ./prep_dataset/ILSVRC2012_val_00039252.bin 224 224 +29667 ./prep_dataset/ILSVRC2012_val_00036273.bin 224 224 +29668 ./prep_dataset/ILSVRC2012_val_00023334.bin 224 224 +29669 ./prep_dataset/ILSVRC2012_val_00000616.bin 224 224 +29670 ./prep_dataset/ILSVRC2012_val_00025192.bin 224 224 +29671 ./prep_dataset/ILSVRC2012_val_00032046.bin 224 224 +29672 ./prep_dataset/ILSVRC2012_val_00037932.bin 224 224 +29673 ./prep_dataset/ILSVRC2012_val_00032364.bin 224 224 +29674 ./prep_dataset/ILSVRC2012_val_00005966.bin 224 224 +29675 ./prep_dataset/ILSVRC2012_val_00028642.bin 224 224 +29676 ./prep_dataset/ILSVRC2012_val_00010463.bin 224 224 +29677 ./prep_dataset/ILSVRC2012_val_00002539.bin 224 224 +29678 ./prep_dataset/ILSVRC2012_val_00009784.bin 224 224 +29679 ./prep_dataset/ILSVRC2012_val_00035735.bin 224 224 +29680 ./prep_dataset/ILSVRC2012_val_00039117.bin 224 224 +29681 ./prep_dataset/ILSVRC2012_val_00015736.bin 224 224 +29682 ./prep_dataset/ILSVRC2012_val_00040078.bin 224 224 +29683 ./prep_dataset/ILSVRC2012_val_00034788.bin 224 224 +29684 ./prep_dataset/ILSVRC2012_val_00036267.bin 224 224 +29685 ./prep_dataset/ILSVRC2012_val_00025054.bin 224 224 +29686 ./prep_dataset/ILSVRC2012_val_00003002.bin 224 224 +29687 ./prep_dataset/ILSVRC2012_val_00037341.bin 224 224 +29688 ./prep_dataset/ILSVRC2012_val_00049938.bin 224 224 +29689 ./prep_dataset/ILSVRC2012_val_00031099.bin 224 224 +29690 ./prep_dataset/ILSVRC2012_val_00021837.bin 224 224 +29691 ./prep_dataset/ILSVRC2012_val_00035182.bin 224 224 +29692 ./prep_dataset/ILSVRC2012_val_00018098.bin 224 224 +29693 ./prep_dataset/ILSVRC2012_val_00021345.bin 224 224 +29694 ./prep_dataset/ILSVRC2012_val_00023672.bin 224 224 +29695 ./prep_dataset/ILSVRC2012_val_00031084.bin 224 224 +29696 ./prep_dataset/ILSVRC2012_val_00041022.bin 224 224 +29697 ./prep_dataset/ILSVRC2012_val_00013385.bin 224 224 +29698 ./prep_dataset/ILSVRC2012_val_00031986.bin 224 224 +29699 ./prep_dataset/ILSVRC2012_val_00043692.bin 224 224 +29700 ./prep_dataset/ILSVRC2012_val_00023726.bin 224 224 +29701 ./prep_dataset/ILSVRC2012_val_00009170.bin 224 224 +29702 ./prep_dataset/ILSVRC2012_val_00032505.bin 224 224 +29703 ./prep_dataset/ILSVRC2012_val_00008511.bin 224 224 +29704 ./prep_dataset/ILSVRC2012_val_00004576.bin 224 224 +29705 ./prep_dataset/ILSVRC2012_val_00021957.bin 224 224 +29706 ./prep_dataset/ILSVRC2012_val_00011133.bin 224 224 +29707 ./prep_dataset/ILSVRC2012_val_00024705.bin 224 224 +29708 ./prep_dataset/ILSVRC2012_val_00022514.bin 224 224 +29709 ./prep_dataset/ILSVRC2012_val_00043013.bin 224 224 +29710 ./prep_dataset/ILSVRC2012_val_00030934.bin 224 224 +29711 ./prep_dataset/ILSVRC2012_val_00025446.bin 224 224 +29712 ./prep_dataset/ILSVRC2012_val_00016188.bin 224 224 +29713 ./prep_dataset/ILSVRC2012_val_00024493.bin 224 224 +29714 ./prep_dataset/ILSVRC2012_val_00034013.bin 224 224 +29715 ./prep_dataset/ILSVRC2012_val_00035012.bin 224 224 +29716 ./prep_dataset/ILSVRC2012_val_00004054.bin 224 224 +29717 ./prep_dataset/ILSVRC2012_val_00018067.bin 224 224 +29718 ./prep_dataset/ILSVRC2012_val_00041675.bin 224 224 +29719 ./prep_dataset/ILSVRC2012_val_00026707.bin 224 224 +29720 ./prep_dataset/ILSVRC2012_val_00034486.bin 224 224 +29721 ./prep_dataset/ILSVRC2012_val_00049098.bin 224 224 +29722 ./prep_dataset/ILSVRC2012_val_00019237.bin 224 224 +29723 ./prep_dataset/ILSVRC2012_val_00014488.bin 224 224 +29724 ./prep_dataset/ILSVRC2012_val_00021838.bin 224 224 +29725 ./prep_dataset/ILSVRC2012_val_00001821.bin 224 224 +29726 ./prep_dataset/ILSVRC2012_val_00008006.bin 224 224 +29727 ./prep_dataset/ILSVRC2012_val_00029113.bin 224 224 +29728 ./prep_dataset/ILSVRC2012_val_00003966.bin 224 224 +29729 ./prep_dataset/ILSVRC2012_val_00046298.bin 224 224 +29730 ./prep_dataset/ILSVRC2012_val_00007796.bin 224 224 +29731 ./prep_dataset/ILSVRC2012_val_00008529.bin 224 224 +29732 ./prep_dataset/ILSVRC2012_val_00038040.bin 224 224 +29733 ./prep_dataset/ILSVRC2012_val_00027857.bin 224 224 +29734 ./prep_dataset/ILSVRC2012_val_00003303.bin 224 224 +29735 ./prep_dataset/ILSVRC2012_val_00026805.bin 224 224 +29736 ./prep_dataset/ILSVRC2012_val_00010049.bin 224 224 +29737 ./prep_dataset/ILSVRC2012_val_00001551.bin 224 224 +29738 ./prep_dataset/ILSVRC2012_val_00009481.bin 224 224 +29739 ./prep_dataset/ILSVRC2012_val_00023029.bin 224 224 +29740 ./prep_dataset/ILSVRC2012_val_00020094.bin 224 224 +29741 ./prep_dataset/ILSVRC2012_val_00009878.bin 224 224 +29742 ./prep_dataset/ILSVRC2012_val_00012559.bin 224 224 +29743 ./prep_dataset/ILSVRC2012_val_00010193.bin 224 224 +29744 ./prep_dataset/ILSVRC2012_val_00016956.bin 224 224 +29745 ./prep_dataset/ILSVRC2012_val_00017603.bin 224 224 +29746 ./prep_dataset/ILSVRC2012_val_00040889.bin 224 224 +29747 ./prep_dataset/ILSVRC2012_val_00043160.bin 224 224 +29748 ./prep_dataset/ILSVRC2012_val_00004916.bin 224 224 +29749 ./prep_dataset/ILSVRC2012_val_00006687.bin 224 224 +29750 ./prep_dataset/ILSVRC2012_val_00036037.bin 224 224 +29751 ./prep_dataset/ILSVRC2012_val_00000672.bin 224 224 +29752 ./prep_dataset/ILSVRC2012_val_00045658.bin 224 224 +29753 ./prep_dataset/ILSVRC2012_val_00029479.bin 224 224 +29754 ./prep_dataset/ILSVRC2012_val_00001820.bin 224 224 +29755 ./prep_dataset/ILSVRC2012_val_00000124.bin 224 224 +29756 ./prep_dataset/ILSVRC2012_val_00003365.bin 224 224 +29757 ./prep_dataset/ILSVRC2012_val_00013202.bin 224 224 +29758 ./prep_dataset/ILSVRC2012_val_00026443.bin 224 224 +29759 ./prep_dataset/ILSVRC2012_val_00039017.bin 224 224 +29760 ./prep_dataset/ILSVRC2012_val_00003424.bin 224 224 +29761 ./prep_dataset/ILSVRC2012_val_00026653.bin 224 224 +29762 ./prep_dataset/ILSVRC2012_val_00024024.bin 224 224 +29763 ./prep_dataset/ILSVRC2012_val_00013061.bin 224 224 +29764 ./prep_dataset/ILSVRC2012_val_00015077.bin 224 224 +29765 ./prep_dataset/ILSVRC2012_val_00025704.bin 224 224 +29766 ./prep_dataset/ILSVRC2012_val_00040965.bin 224 224 +29767 ./prep_dataset/ILSVRC2012_val_00025796.bin 224 224 +29768 ./prep_dataset/ILSVRC2012_val_00006642.bin 224 224 +29769 ./prep_dataset/ILSVRC2012_val_00015426.bin 224 224 +29770 ./prep_dataset/ILSVRC2012_val_00003372.bin 224 224 +29771 ./prep_dataset/ILSVRC2012_val_00024175.bin 224 224 +29772 ./prep_dataset/ILSVRC2012_val_00021206.bin 224 224 +29773 ./prep_dataset/ILSVRC2012_val_00022912.bin 224 224 +29774 ./prep_dataset/ILSVRC2012_val_00029710.bin 224 224 +29775 ./prep_dataset/ILSVRC2012_val_00033403.bin 224 224 +29776 ./prep_dataset/ILSVRC2012_val_00019282.bin 224 224 +29777 ./prep_dataset/ILSVRC2012_val_00034558.bin 224 224 +29778 ./prep_dataset/ILSVRC2012_val_00002800.bin 224 224 +29779 ./prep_dataset/ILSVRC2012_val_00002809.bin 224 224 +29780 ./prep_dataset/ILSVRC2012_val_00035433.bin 224 224 +29781 ./prep_dataset/ILSVRC2012_val_00015037.bin 224 224 +29782 ./prep_dataset/ILSVRC2012_val_00036606.bin 224 224 +29783 ./prep_dataset/ILSVRC2012_val_00007448.bin 224 224 +29784 ./prep_dataset/ILSVRC2012_val_00038278.bin 224 224 +29785 ./prep_dataset/ILSVRC2012_val_00010719.bin 224 224 +29786 ./prep_dataset/ILSVRC2012_val_00041727.bin 224 224 +29787 ./prep_dataset/ILSVRC2012_val_00023194.bin 224 224 +29788 ./prep_dataset/ILSVRC2012_val_00021192.bin 224 224 +29789 ./prep_dataset/ILSVRC2012_val_00018040.bin 224 224 +29790 ./prep_dataset/ILSVRC2012_val_00015674.bin 224 224 +29791 ./prep_dataset/ILSVRC2012_val_00038043.bin 224 224 +29792 ./prep_dataset/ILSVRC2012_val_00020660.bin 224 224 +29793 ./prep_dataset/ILSVRC2012_val_00015151.bin 224 224 +29794 ./prep_dataset/ILSVRC2012_val_00027620.bin 224 224 +29795 ./prep_dataset/ILSVRC2012_val_00040945.bin 224 224 +29796 ./prep_dataset/ILSVRC2012_val_00048481.bin 224 224 +29797 ./prep_dataset/ILSVRC2012_val_00049477.bin 224 224 +29798 ./prep_dataset/ILSVRC2012_val_00034908.bin 224 224 +29799 ./prep_dataset/ILSVRC2012_val_00042389.bin 224 224 +29800 ./prep_dataset/ILSVRC2012_val_00028022.bin 224 224 +29801 ./prep_dataset/ILSVRC2012_val_00025719.bin 224 224 +29802 ./prep_dataset/ILSVRC2012_val_00026050.bin 224 224 +29803 ./prep_dataset/ILSVRC2012_val_00016639.bin 224 224 +29804 ./prep_dataset/ILSVRC2012_val_00027078.bin 224 224 +29805 ./prep_dataset/ILSVRC2012_val_00007969.bin 224 224 +29806 ./prep_dataset/ILSVRC2012_val_00040533.bin 224 224 +29807 ./prep_dataset/ILSVRC2012_val_00031422.bin 224 224 +29808 ./prep_dataset/ILSVRC2012_val_00008973.bin 224 224 +29809 ./prep_dataset/ILSVRC2012_val_00015987.bin 224 224 +29810 ./prep_dataset/ILSVRC2012_val_00040810.bin 224 224 +29811 ./prep_dataset/ILSVRC2012_val_00015321.bin 224 224 +29812 ./prep_dataset/ILSVRC2012_val_00045466.bin 224 224 +29813 ./prep_dataset/ILSVRC2012_val_00012902.bin 224 224 +29814 ./prep_dataset/ILSVRC2012_val_00020071.bin 224 224 +29815 ./prep_dataset/ILSVRC2012_val_00014900.bin 224 224 +29816 ./prep_dataset/ILSVRC2012_val_00013998.bin 224 224 +29817 ./prep_dataset/ILSVRC2012_val_00011442.bin 224 224 +29818 ./prep_dataset/ILSVRC2012_val_00049860.bin 224 224 +29819 ./prep_dataset/ILSVRC2012_val_00023730.bin 224 224 +29820 ./prep_dataset/ILSVRC2012_val_00024657.bin 224 224 +29821 ./prep_dataset/ILSVRC2012_val_00000595.bin 224 224 +29822 ./prep_dataset/ILSVRC2012_val_00035888.bin 224 224 +29823 ./prep_dataset/ILSVRC2012_val_00028151.bin 224 224 +29824 ./prep_dataset/ILSVRC2012_val_00047466.bin 224 224 +29825 ./prep_dataset/ILSVRC2012_val_00048365.bin 224 224 +29826 ./prep_dataset/ILSVRC2012_val_00003728.bin 224 224 +29827 ./prep_dataset/ILSVRC2012_val_00029394.bin 224 224 +29828 ./prep_dataset/ILSVRC2012_val_00026856.bin 224 224 +29829 ./prep_dataset/ILSVRC2012_val_00005647.bin 224 224 +29830 ./prep_dataset/ILSVRC2012_val_00041140.bin 224 224 +29831 ./prep_dataset/ILSVRC2012_val_00035082.bin 224 224 +29832 ./prep_dataset/ILSVRC2012_val_00012432.bin 224 224 +29833 ./prep_dataset/ILSVRC2012_val_00024779.bin 224 224 +29834 ./prep_dataset/ILSVRC2012_val_00018875.bin 224 224 +29835 ./prep_dataset/ILSVRC2012_val_00007492.bin 224 224 +29836 ./prep_dataset/ILSVRC2012_val_00029062.bin 224 224 +29837 ./prep_dataset/ILSVRC2012_val_00021226.bin 224 224 +29838 ./prep_dataset/ILSVRC2012_val_00009112.bin 224 224 +29839 ./prep_dataset/ILSVRC2012_val_00033793.bin 224 224 +29840 ./prep_dataset/ILSVRC2012_val_00021956.bin 224 224 +29841 ./prep_dataset/ILSVRC2012_val_00013995.bin 224 224 +29842 ./prep_dataset/ILSVRC2012_val_00044816.bin 224 224 +29843 ./prep_dataset/ILSVRC2012_val_00042864.bin 224 224 +29844 ./prep_dataset/ILSVRC2012_val_00020118.bin 224 224 +29845 ./prep_dataset/ILSVRC2012_val_00000255.bin 224 224 +29846 ./prep_dataset/ILSVRC2012_val_00041535.bin 224 224 +29847 ./prep_dataset/ILSVRC2012_val_00037221.bin 224 224 +29848 ./prep_dataset/ILSVRC2012_val_00044414.bin 224 224 +29849 ./prep_dataset/ILSVRC2012_val_00030652.bin 224 224 +29850 ./prep_dataset/ILSVRC2012_val_00021449.bin 224 224 +29851 ./prep_dataset/ILSVRC2012_val_00037739.bin 224 224 +29852 ./prep_dataset/ILSVRC2012_val_00039024.bin 224 224 +29853 ./prep_dataset/ILSVRC2012_val_00010405.bin 224 224 +29854 ./prep_dataset/ILSVRC2012_val_00000337.bin 224 224 +29855 ./prep_dataset/ILSVRC2012_val_00037162.bin 224 224 +29856 ./prep_dataset/ILSVRC2012_val_00038277.bin 224 224 +29857 ./prep_dataset/ILSVRC2012_val_00040121.bin 224 224 +29858 ./prep_dataset/ILSVRC2012_val_00014459.bin 224 224 +29859 ./prep_dataset/ILSVRC2012_val_00023277.bin 224 224 +29860 ./prep_dataset/ILSVRC2012_val_00038264.bin 224 224 +29861 ./prep_dataset/ILSVRC2012_val_00002180.bin 224 224 +29862 ./prep_dataset/ILSVRC2012_val_00048783.bin 224 224 +29863 ./prep_dataset/ILSVRC2012_val_00042675.bin 224 224 +29864 ./prep_dataset/ILSVRC2012_val_00036207.bin 224 224 +29865 ./prep_dataset/ILSVRC2012_val_00015051.bin 224 224 +29866 ./prep_dataset/ILSVRC2012_val_00018649.bin 224 224 +29867 ./prep_dataset/ILSVRC2012_val_00022448.bin 224 224 +29868 ./prep_dataset/ILSVRC2012_val_00013245.bin 224 224 +29869 ./prep_dataset/ILSVRC2012_val_00020770.bin 224 224 +29870 ./prep_dataset/ILSVRC2012_val_00005279.bin 224 224 +29871 ./prep_dataset/ILSVRC2012_val_00028217.bin 224 224 +29872 ./prep_dataset/ILSVRC2012_val_00002807.bin 224 224 +29873 ./prep_dataset/ILSVRC2012_val_00049923.bin 224 224 +29874 ./prep_dataset/ILSVRC2012_val_00021081.bin 224 224 +29875 ./prep_dataset/ILSVRC2012_val_00042753.bin 224 224 +29876 ./prep_dataset/ILSVRC2012_val_00001192.bin 224 224 +29877 ./prep_dataset/ILSVRC2012_val_00045653.bin 224 224 +29878 ./prep_dataset/ILSVRC2012_val_00041373.bin 224 224 +29879 ./prep_dataset/ILSVRC2012_val_00006522.bin 224 224 +29880 ./prep_dataset/ILSVRC2012_val_00025777.bin 224 224 +29881 ./prep_dataset/ILSVRC2012_val_00049403.bin 224 224 +29882 ./prep_dataset/ILSVRC2012_val_00023352.bin 224 224 +29883 ./prep_dataset/ILSVRC2012_val_00049271.bin 224 224 +29884 ./prep_dataset/ILSVRC2012_val_00041176.bin 224 224 +29885 ./prep_dataset/ILSVRC2012_val_00036189.bin 224 224 +29886 ./prep_dataset/ILSVRC2012_val_00045359.bin 224 224 +29887 ./prep_dataset/ILSVRC2012_val_00021972.bin 224 224 +29888 ./prep_dataset/ILSVRC2012_val_00007769.bin 224 224 +29889 ./prep_dataset/ILSVRC2012_val_00011606.bin 224 224 +29890 ./prep_dataset/ILSVRC2012_val_00014867.bin 224 224 +29891 ./prep_dataset/ILSVRC2012_val_00047597.bin 224 224 +29892 ./prep_dataset/ILSVRC2012_val_00024158.bin 224 224 +29893 ./prep_dataset/ILSVRC2012_val_00042470.bin 224 224 +29894 ./prep_dataset/ILSVRC2012_val_00008803.bin 224 224 +29895 ./prep_dataset/ILSVRC2012_val_00022689.bin 224 224 +29896 ./prep_dataset/ILSVRC2012_val_00037203.bin 224 224 +29897 ./prep_dataset/ILSVRC2012_val_00007406.bin 224 224 +29898 ./prep_dataset/ILSVRC2012_val_00016309.bin 224 224 +29899 ./prep_dataset/ILSVRC2012_val_00019557.bin 224 224 +29900 ./prep_dataset/ILSVRC2012_val_00036900.bin 224 224 +29901 ./prep_dataset/ILSVRC2012_val_00014979.bin 224 224 +29902 ./prep_dataset/ILSVRC2012_val_00021001.bin 224 224 +29903 ./prep_dataset/ILSVRC2012_val_00005976.bin 224 224 +29904 ./prep_dataset/ILSVRC2012_val_00024031.bin 224 224 +29905 ./prep_dataset/ILSVRC2012_val_00026752.bin 224 224 +29906 ./prep_dataset/ILSVRC2012_val_00013465.bin 224 224 +29907 ./prep_dataset/ILSVRC2012_val_00005253.bin 224 224 +29908 ./prep_dataset/ILSVRC2012_val_00035391.bin 224 224 +29909 ./prep_dataset/ILSVRC2012_val_00023478.bin 224 224 +29910 ./prep_dataset/ILSVRC2012_val_00026633.bin 224 224 +29911 ./prep_dataset/ILSVRC2012_val_00045807.bin 224 224 +29912 ./prep_dataset/ILSVRC2012_val_00034427.bin 224 224 +29913 ./prep_dataset/ILSVRC2012_val_00034175.bin 224 224 +29914 ./prep_dataset/ILSVRC2012_val_00014969.bin 224 224 +29915 ./prep_dataset/ILSVRC2012_val_00027705.bin 224 224 +29916 ./prep_dataset/ILSVRC2012_val_00038241.bin 224 224 +29917 ./prep_dataset/ILSVRC2012_val_00039189.bin 224 224 +29918 ./prep_dataset/ILSVRC2012_val_00005383.bin 224 224 +29919 ./prep_dataset/ILSVRC2012_val_00040309.bin 224 224 +29920 ./prep_dataset/ILSVRC2012_val_00018618.bin 224 224 +29921 ./prep_dataset/ILSVRC2012_val_00036764.bin 224 224 +29922 ./prep_dataset/ILSVRC2012_val_00012945.bin 224 224 +29923 ./prep_dataset/ILSVRC2012_val_00046416.bin 224 224 +29924 ./prep_dataset/ILSVRC2012_val_00012093.bin 224 224 +29925 ./prep_dataset/ILSVRC2012_val_00040943.bin 224 224 +29926 ./prep_dataset/ILSVRC2012_val_00040322.bin 224 224 +29927 ./prep_dataset/ILSVRC2012_val_00045830.bin 224 224 +29928 ./prep_dataset/ILSVRC2012_val_00004000.bin 224 224 +29929 ./prep_dataset/ILSVRC2012_val_00011914.bin 224 224 +29930 ./prep_dataset/ILSVRC2012_val_00012725.bin 224 224 +29931 ./prep_dataset/ILSVRC2012_val_00041835.bin 224 224 +29932 ./prep_dataset/ILSVRC2012_val_00047385.bin 224 224 +29933 ./prep_dataset/ILSVRC2012_val_00002891.bin 224 224 +29934 ./prep_dataset/ILSVRC2012_val_00017249.bin 224 224 +29935 ./prep_dataset/ILSVRC2012_val_00033495.bin 224 224 +29936 ./prep_dataset/ILSVRC2012_val_00003323.bin 224 224 +29937 ./prep_dataset/ILSVRC2012_val_00036006.bin 224 224 +29938 ./prep_dataset/ILSVRC2012_val_00023057.bin 224 224 +29939 ./prep_dataset/ILSVRC2012_val_00007082.bin 224 224 +29940 ./prep_dataset/ILSVRC2012_val_00040252.bin 224 224 +29941 ./prep_dataset/ILSVRC2012_val_00011115.bin 224 224 +29942 ./prep_dataset/ILSVRC2012_val_00043181.bin 224 224 +29943 ./prep_dataset/ILSVRC2012_val_00015571.bin 224 224 +29944 ./prep_dataset/ILSVRC2012_val_00029484.bin 224 224 +29945 ./prep_dataset/ILSVRC2012_val_00018747.bin 224 224 +29946 ./prep_dataset/ILSVRC2012_val_00040490.bin 224 224 +29947 ./prep_dataset/ILSVRC2012_val_00000662.bin 224 224 +29948 ./prep_dataset/ILSVRC2012_val_00012834.bin 224 224 +29949 ./prep_dataset/ILSVRC2012_val_00048052.bin 224 224 +29950 ./prep_dataset/ILSVRC2012_val_00002105.bin 224 224 +29951 ./prep_dataset/ILSVRC2012_val_00016355.bin 224 224 +29952 ./prep_dataset/ILSVRC2012_val_00031971.bin 224 224 +29953 ./prep_dataset/ILSVRC2012_val_00009747.bin 224 224 +29954 ./prep_dataset/ILSVRC2012_val_00028766.bin 224 224 +29955 ./prep_dataset/ILSVRC2012_val_00045181.bin 224 224 +29956 ./prep_dataset/ILSVRC2012_val_00028442.bin 224 224 +29957 ./prep_dataset/ILSVRC2012_val_00019343.bin 224 224 +29958 ./prep_dataset/ILSVRC2012_val_00015874.bin 224 224 +29959 ./prep_dataset/ILSVRC2012_val_00006781.bin 224 224 +29960 ./prep_dataset/ILSVRC2012_val_00008039.bin 224 224 +29961 ./prep_dataset/ILSVRC2012_val_00008296.bin 224 224 +29962 ./prep_dataset/ILSVRC2012_val_00031594.bin 224 224 +29963 ./prep_dataset/ILSVRC2012_val_00002649.bin 224 224 +29964 ./prep_dataset/ILSVRC2012_val_00012367.bin 224 224 +29965 ./prep_dataset/ILSVRC2012_val_00045966.bin 224 224 +29966 ./prep_dataset/ILSVRC2012_val_00017906.bin 224 224 +29967 ./prep_dataset/ILSVRC2012_val_00006952.bin 224 224 +29968 ./prep_dataset/ILSVRC2012_val_00039686.bin 224 224 +29969 ./prep_dataset/ILSVRC2012_val_00042903.bin 224 224 +29970 ./prep_dataset/ILSVRC2012_val_00018202.bin 224 224 +29971 ./prep_dataset/ILSVRC2012_val_00002331.bin 224 224 +29972 ./prep_dataset/ILSVRC2012_val_00026562.bin 224 224 +29973 ./prep_dataset/ILSVRC2012_val_00000982.bin 224 224 +29974 ./prep_dataset/ILSVRC2012_val_00011440.bin 224 224 +29975 ./prep_dataset/ILSVRC2012_val_00041025.bin 224 224 +29976 ./prep_dataset/ILSVRC2012_val_00034742.bin 224 224 +29977 ./prep_dataset/ILSVRC2012_val_00036697.bin 224 224 +29978 ./prep_dataset/ILSVRC2012_val_00001720.bin 224 224 +29979 ./prep_dataset/ILSVRC2012_val_00025835.bin 224 224 +29980 ./prep_dataset/ILSVRC2012_val_00009489.bin 224 224 +29981 ./prep_dataset/ILSVRC2012_val_00012937.bin 224 224 +29982 ./prep_dataset/ILSVRC2012_val_00021729.bin 224 224 +29983 ./prep_dataset/ILSVRC2012_val_00041890.bin 224 224 +29984 ./prep_dataset/ILSVRC2012_val_00005830.bin 224 224 +29985 ./prep_dataset/ILSVRC2012_val_00041566.bin 224 224 +29986 ./prep_dataset/ILSVRC2012_val_00036133.bin 224 224 +29987 ./prep_dataset/ILSVRC2012_val_00017004.bin 224 224 +29988 ./prep_dataset/ILSVRC2012_val_00030381.bin 224 224 +29989 ./prep_dataset/ILSVRC2012_val_00002732.bin 224 224 +29990 ./prep_dataset/ILSVRC2012_val_00037485.bin 224 224 +29991 ./prep_dataset/ILSVRC2012_val_00021327.bin 224 224 +29992 ./prep_dataset/ILSVRC2012_val_00001176.bin 224 224 +29993 ./prep_dataset/ILSVRC2012_val_00019083.bin 224 224 +29994 ./prep_dataset/ILSVRC2012_val_00012342.bin 224 224 +29995 ./prep_dataset/ILSVRC2012_val_00010198.bin 224 224 +29996 ./prep_dataset/ILSVRC2012_val_00003324.bin 224 224 +29997 ./prep_dataset/ILSVRC2012_val_00041698.bin 224 224 +29998 ./prep_dataset/ILSVRC2012_val_00023232.bin 224 224 +29999 ./prep_dataset/ILSVRC2012_val_00034563.bin 224 224 +30000 ./prep_dataset/ILSVRC2012_val_00049231.bin 224 224 +30001 ./prep_dataset/ILSVRC2012_val_00000063.bin 224 224 +30002 ./prep_dataset/ILSVRC2012_val_00023098.bin 224 224 +30003 ./prep_dataset/ILSVRC2012_val_00009711.bin 224 224 +30004 ./prep_dataset/ILSVRC2012_val_00043020.bin 224 224 +30005 ./prep_dataset/ILSVRC2012_val_00040067.bin 224 224 +30006 ./prep_dataset/ILSVRC2012_val_00013840.bin 224 224 +30007 ./prep_dataset/ILSVRC2012_val_00000619.bin 224 224 +30008 ./prep_dataset/ILSVRC2012_val_00007056.bin 224 224 +30009 ./prep_dataset/ILSVRC2012_val_00014641.bin 224 224 +30010 ./prep_dataset/ILSVRC2012_val_00034756.bin 224 224 +30011 ./prep_dataset/ILSVRC2012_val_00038710.bin 224 224 +30012 ./prep_dataset/ILSVRC2012_val_00036852.bin 224 224 +30013 ./prep_dataset/ILSVRC2012_val_00000084.bin 224 224 +30014 ./prep_dataset/ILSVRC2012_val_00039956.bin 224 224 +30015 ./prep_dataset/ILSVRC2012_val_00005706.bin 224 224 +30016 ./prep_dataset/ILSVRC2012_val_00003339.bin 224 224 +30017 ./prep_dataset/ILSVRC2012_val_00015520.bin 224 224 +30018 ./prep_dataset/ILSVRC2012_val_00019892.bin 224 224 +30019 ./prep_dataset/ILSVRC2012_val_00027316.bin 224 224 +30020 ./prep_dataset/ILSVRC2012_val_00047885.bin 224 224 +30021 ./prep_dataset/ILSVRC2012_val_00029278.bin 224 224 +30022 ./prep_dataset/ILSVRC2012_val_00010470.bin 224 224 +30023 ./prep_dataset/ILSVRC2012_val_00017910.bin 224 224 +30024 ./prep_dataset/ILSVRC2012_val_00005964.bin 224 224 +30025 ./prep_dataset/ILSVRC2012_val_00049202.bin 224 224 +30026 ./prep_dataset/ILSVRC2012_val_00016881.bin 224 224 +30027 ./prep_dataset/ILSVRC2012_val_00036403.bin 224 224 +30028 ./prep_dataset/ILSVRC2012_val_00043465.bin 224 224 +30029 ./prep_dataset/ILSVRC2012_val_00041330.bin 224 224 +30030 ./prep_dataset/ILSVRC2012_val_00006933.bin 224 224 +30031 ./prep_dataset/ILSVRC2012_val_00022867.bin 224 224 +30032 ./prep_dataset/ILSVRC2012_val_00043193.bin 224 224 +30033 ./prep_dataset/ILSVRC2012_val_00001405.bin 224 224 +30034 ./prep_dataset/ILSVRC2012_val_00023827.bin 224 224 +30035 ./prep_dataset/ILSVRC2012_val_00025817.bin 224 224 +30036 ./prep_dataset/ILSVRC2012_val_00027476.bin 224 224 +30037 ./prep_dataset/ILSVRC2012_val_00008288.bin 224 224 +30038 ./prep_dataset/ILSVRC2012_val_00015928.bin 224 224 +30039 ./prep_dataset/ILSVRC2012_val_00028797.bin 224 224 +30040 ./prep_dataset/ILSVRC2012_val_00028285.bin 224 224 +30041 ./prep_dataset/ILSVRC2012_val_00027382.bin 224 224 +30042 ./prep_dataset/ILSVRC2012_val_00012290.bin 224 224 +30043 ./prep_dataset/ILSVRC2012_val_00020973.bin 224 224 +30044 ./prep_dataset/ILSVRC2012_val_00037073.bin 224 224 +30045 ./prep_dataset/ILSVRC2012_val_00018307.bin 224 224 +30046 ./prep_dataset/ILSVRC2012_val_00017939.bin 224 224 +30047 ./prep_dataset/ILSVRC2012_val_00046832.bin 224 224 +30048 ./prep_dataset/ILSVRC2012_val_00013287.bin 224 224 +30049 ./prep_dataset/ILSVRC2012_val_00041256.bin 224 224 +30050 ./prep_dataset/ILSVRC2012_val_00025775.bin 224 224 +30051 ./prep_dataset/ILSVRC2012_val_00049988.bin 224 224 +30052 ./prep_dataset/ILSVRC2012_val_00010370.bin 224 224 +30053 ./prep_dataset/ILSVRC2012_val_00039958.bin 224 224 +30054 ./prep_dataset/ILSVRC2012_val_00017342.bin 224 224 +30055 ./prep_dataset/ILSVRC2012_val_00033732.bin 224 224 +30056 ./prep_dataset/ILSVRC2012_val_00001811.bin 224 224 +30057 ./prep_dataset/ILSVRC2012_val_00038393.bin 224 224 +30058 ./prep_dataset/ILSVRC2012_val_00024092.bin 224 224 +30059 ./prep_dataset/ILSVRC2012_val_00024499.bin 224 224 +30060 ./prep_dataset/ILSVRC2012_val_00005153.bin 224 224 +30061 ./prep_dataset/ILSVRC2012_val_00016894.bin 224 224 +30062 ./prep_dataset/ILSVRC2012_val_00030551.bin 224 224 +30063 ./prep_dataset/ILSVRC2012_val_00049567.bin 224 224 +30064 ./prep_dataset/ILSVRC2012_val_00035380.bin 224 224 +30065 ./prep_dataset/ILSVRC2012_val_00029383.bin 224 224 +30066 ./prep_dataset/ILSVRC2012_val_00004598.bin 224 224 +30067 ./prep_dataset/ILSVRC2012_val_00006438.bin 224 224 +30068 ./prep_dataset/ILSVRC2012_val_00038909.bin 224 224 +30069 ./prep_dataset/ILSVRC2012_val_00019009.bin 224 224 +30070 ./prep_dataset/ILSVRC2012_val_00013942.bin 224 224 +30071 ./prep_dataset/ILSVRC2012_val_00017329.bin 224 224 +30072 ./prep_dataset/ILSVRC2012_val_00017467.bin 224 224 +30073 ./prep_dataset/ILSVRC2012_val_00020080.bin 224 224 +30074 ./prep_dataset/ILSVRC2012_val_00011268.bin 224 224 +30075 ./prep_dataset/ILSVRC2012_val_00014914.bin 224 224 +30076 ./prep_dataset/ILSVRC2012_val_00033300.bin 224 224 +30077 ./prep_dataset/ILSVRC2012_val_00024964.bin 224 224 +30078 ./prep_dataset/ILSVRC2012_val_00028495.bin 224 224 +30079 ./prep_dataset/ILSVRC2012_val_00042626.bin 224 224 +30080 ./prep_dataset/ILSVRC2012_val_00048797.bin 224 224 +30081 ./prep_dataset/ILSVRC2012_val_00043490.bin 224 224 +30082 ./prep_dataset/ILSVRC2012_val_00014851.bin 224 224 +30083 ./prep_dataset/ILSVRC2012_val_00032992.bin 224 224 +30084 ./prep_dataset/ILSVRC2012_val_00008102.bin 224 224 +30085 ./prep_dataset/ILSVRC2012_val_00026660.bin 224 224 +30086 ./prep_dataset/ILSVRC2012_val_00038614.bin 224 224 +30087 ./prep_dataset/ILSVRC2012_val_00005255.bin 224 224 +30088 ./prep_dataset/ILSVRC2012_val_00011480.bin 224 224 +30089 ./prep_dataset/ILSVRC2012_val_00042573.bin 224 224 +30090 ./prep_dataset/ILSVRC2012_val_00038908.bin 224 224 +30091 ./prep_dataset/ILSVRC2012_val_00001356.bin 224 224 +30092 ./prep_dataset/ILSVRC2012_val_00001509.bin 224 224 +30093 ./prep_dataset/ILSVRC2012_val_00028893.bin 224 224 +30094 ./prep_dataset/ILSVRC2012_val_00032013.bin 224 224 +30095 ./prep_dataset/ILSVRC2012_val_00034160.bin 224 224 +30096 ./prep_dataset/ILSVRC2012_val_00030228.bin 224 224 +30097 ./prep_dataset/ILSVRC2012_val_00031452.bin 224 224 +30098 ./prep_dataset/ILSVRC2012_val_00034065.bin 224 224 +30099 ./prep_dataset/ILSVRC2012_val_00029725.bin 224 224 +30100 ./prep_dataset/ILSVRC2012_val_00042851.bin 224 224 +30101 ./prep_dataset/ILSVRC2012_val_00030415.bin 224 224 +30102 ./prep_dataset/ILSVRC2012_val_00041562.bin 224 224 +30103 ./prep_dataset/ILSVRC2012_val_00043716.bin 224 224 +30104 ./prep_dataset/ILSVRC2012_val_00027530.bin 224 224 +30105 ./prep_dataset/ILSVRC2012_val_00016105.bin 224 224 +30106 ./prep_dataset/ILSVRC2012_val_00013957.bin 224 224 +30107 ./prep_dataset/ILSVRC2012_val_00012522.bin 224 224 +30108 ./prep_dataset/ILSVRC2012_val_00032803.bin 224 224 +30109 ./prep_dataset/ILSVRC2012_val_00002694.bin 224 224 +30110 ./prep_dataset/ILSVRC2012_val_00036544.bin 224 224 +30111 ./prep_dataset/ILSVRC2012_val_00044405.bin 224 224 +30112 ./prep_dataset/ILSVRC2012_val_00002207.bin 224 224 +30113 ./prep_dataset/ILSVRC2012_val_00046443.bin 224 224 +30114 ./prep_dataset/ILSVRC2012_val_00026993.bin 224 224 +30115 ./prep_dataset/ILSVRC2012_val_00028479.bin 224 224 +30116 ./prep_dataset/ILSVRC2012_val_00028659.bin 224 224 +30117 ./prep_dataset/ILSVRC2012_val_00022483.bin 224 224 +30118 ./prep_dataset/ILSVRC2012_val_00013799.bin 224 224 +30119 ./prep_dataset/ILSVRC2012_val_00025717.bin 224 224 +30120 ./prep_dataset/ILSVRC2012_val_00012680.bin 224 224 +30121 ./prep_dataset/ILSVRC2012_val_00042745.bin 224 224 +30122 ./prep_dataset/ILSVRC2012_val_00025203.bin 224 224 +30123 ./prep_dataset/ILSVRC2012_val_00028496.bin 224 224 +30124 ./prep_dataset/ILSVRC2012_val_00043758.bin 224 224 +30125 ./prep_dataset/ILSVRC2012_val_00032837.bin 224 224 +30126 ./prep_dataset/ILSVRC2012_val_00010174.bin 224 224 +30127 ./prep_dataset/ILSVRC2012_val_00023844.bin 224 224 +30128 ./prep_dataset/ILSVRC2012_val_00030092.bin 224 224 +30129 ./prep_dataset/ILSVRC2012_val_00020675.bin 224 224 +30130 ./prep_dataset/ILSVRC2012_val_00027147.bin 224 224 +30131 ./prep_dataset/ILSVRC2012_val_00023770.bin 224 224 +30132 ./prep_dataset/ILSVRC2012_val_00026476.bin 224 224 +30133 ./prep_dataset/ILSVRC2012_val_00041102.bin 224 224 +30134 ./prep_dataset/ILSVRC2012_val_00029253.bin 224 224 +30135 ./prep_dataset/ILSVRC2012_val_00003220.bin 224 224 +30136 ./prep_dataset/ILSVRC2012_val_00010217.bin 224 224 +30137 ./prep_dataset/ILSVRC2012_val_00033301.bin 224 224 +30138 ./prep_dataset/ILSVRC2012_val_00012449.bin 224 224 +30139 ./prep_dataset/ILSVRC2012_val_00004546.bin 224 224 +30140 ./prep_dataset/ILSVRC2012_val_00040929.bin 224 224 +30141 ./prep_dataset/ILSVRC2012_val_00033510.bin 224 224 +30142 ./prep_dataset/ILSVRC2012_val_00014758.bin 224 224 +30143 ./prep_dataset/ILSVRC2012_val_00043152.bin 224 224 +30144 ./prep_dataset/ILSVRC2012_val_00027748.bin 224 224 +30145 ./prep_dataset/ILSVRC2012_val_00013932.bin 224 224 +30146 ./prep_dataset/ILSVRC2012_val_00046879.bin 224 224 +30147 ./prep_dataset/ILSVRC2012_val_00028747.bin 224 224 +30148 ./prep_dataset/ILSVRC2012_val_00001270.bin 224 224 +30149 ./prep_dataset/ILSVRC2012_val_00040273.bin 224 224 +30150 ./prep_dataset/ILSVRC2012_val_00041477.bin 224 224 +30151 ./prep_dataset/ILSVRC2012_val_00037534.bin 224 224 +30152 ./prep_dataset/ILSVRC2012_val_00019032.bin 224 224 +30153 ./prep_dataset/ILSVRC2012_val_00019763.bin 224 224 +30154 ./prep_dataset/ILSVRC2012_val_00025109.bin 224 224 +30155 ./prep_dataset/ILSVRC2012_val_00024726.bin 224 224 +30156 ./prep_dataset/ILSVRC2012_val_00010099.bin 224 224 +30157 ./prep_dataset/ILSVRC2012_val_00036469.bin 224 224 +30158 ./prep_dataset/ILSVRC2012_val_00003616.bin 224 224 +30159 ./prep_dataset/ILSVRC2012_val_00025843.bin 224 224 +30160 ./prep_dataset/ILSVRC2012_val_00013153.bin 224 224 +30161 ./prep_dataset/ILSVRC2012_val_00001913.bin 224 224 +30162 ./prep_dataset/ILSVRC2012_val_00020097.bin 224 224 +30163 ./prep_dataset/ILSVRC2012_val_00032495.bin 224 224 +30164 ./prep_dataset/ILSVRC2012_val_00018193.bin 224 224 +30165 ./prep_dataset/ILSVRC2012_val_00040622.bin 224 224 +30166 ./prep_dataset/ILSVRC2012_val_00021813.bin 224 224 +30167 ./prep_dataset/ILSVRC2012_val_00040256.bin 224 224 +30168 ./prep_dataset/ILSVRC2012_val_00017655.bin 224 224 +30169 ./prep_dataset/ILSVRC2012_val_00015950.bin 224 224 +30170 ./prep_dataset/ILSVRC2012_val_00027050.bin 224 224 +30171 ./prep_dataset/ILSVRC2012_val_00045517.bin 224 224 +30172 ./prep_dataset/ILSVRC2012_val_00020857.bin 224 224 +30173 ./prep_dataset/ILSVRC2012_val_00002987.bin 224 224 +30174 ./prep_dataset/ILSVRC2012_val_00030064.bin 224 224 +30175 ./prep_dataset/ILSVRC2012_val_00020316.bin 224 224 +30176 ./prep_dataset/ILSVRC2012_val_00034169.bin 224 224 +30177 ./prep_dataset/ILSVRC2012_val_00042649.bin 224 224 +30178 ./prep_dataset/ILSVRC2012_val_00045663.bin 224 224 +30179 ./prep_dataset/ILSVRC2012_val_00041654.bin 224 224 +30180 ./prep_dataset/ILSVRC2012_val_00002743.bin 224 224 +30181 ./prep_dataset/ILSVRC2012_val_00013598.bin 224 224 +30182 ./prep_dataset/ILSVRC2012_val_00004374.bin 224 224 +30183 ./prep_dataset/ILSVRC2012_val_00035580.bin 224 224 +30184 ./prep_dataset/ILSVRC2012_val_00040827.bin 224 224 +30185 ./prep_dataset/ILSVRC2012_val_00012868.bin 224 224 +30186 ./prep_dataset/ILSVRC2012_val_00015982.bin 224 224 +30187 ./prep_dataset/ILSVRC2012_val_00015832.bin 224 224 +30188 ./prep_dataset/ILSVRC2012_val_00041433.bin 224 224 +30189 ./prep_dataset/ILSVRC2012_val_00030974.bin 224 224 +30190 ./prep_dataset/ILSVRC2012_val_00012524.bin 224 224 +30191 ./prep_dataset/ILSVRC2012_val_00029465.bin 224 224 +30192 ./prep_dataset/ILSVRC2012_val_00013136.bin 224 224 +30193 ./prep_dataset/ILSVRC2012_val_00034538.bin 224 224 +30194 ./prep_dataset/ILSVRC2012_val_00027746.bin 224 224 +30195 ./prep_dataset/ILSVRC2012_val_00000830.bin 224 224 +30196 ./prep_dataset/ILSVRC2012_val_00021505.bin 224 224 +30197 ./prep_dataset/ILSVRC2012_val_00049850.bin 224 224 +30198 ./prep_dataset/ILSVRC2012_val_00009559.bin 224 224 +30199 ./prep_dataset/ILSVRC2012_val_00011033.bin 224 224 +30200 ./prep_dataset/ILSVRC2012_val_00002212.bin 224 224 +30201 ./prep_dataset/ILSVRC2012_val_00019717.bin 224 224 +30202 ./prep_dataset/ILSVRC2012_val_00039034.bin 224 224 +30203 ./prep_dataset/ILSVRC2012_val_00030171.bin 224 224 +30204 ./prep_dataset/ILSVRC2012_val_00044363.bin 224 224 +30205 ./prep_dataset/ILSVRC2012_val_00025353.bin 224 224 +30206 ./prep_dataset/ILSVRC2012_val_00008185.bin 224 224 +30207 ./prep_dataset/ILSVRC2012_val_00048011.bin 224 224 +30208 ./prep_dataset/ILSVRC2012_val_00041543.bin 224 224 +30209 ./prep_dataset/ILSVRC2012_val_00011645.bin 224 224 +30210 ./prep_dataset/ILSVRC2012_val_00022556.bin 224 224 +30211 ./prep_dataset/ILSVRC2012_val_00047061.bin 224 224 +30212 ./prep_dataset/ILSVRC2012_val_00012873.bin 224 224 +30213 ./prep_dataset/ILSVRC2012_val_00037880.bin 224 224 +30214 ./prep_dataset/ILSVRC2012_val_00005298.bin 224 224 +30215 ./prep_dataset/ILSVRC2012_val_00021779.bin 224 224 +30216 ./prep_dataset/ILSVRC2012_val_00035522.bin 224 224 +30217 ./prep_dataset/ILSVRC2012_val_00028271.bin 224 224 +30218 ./prep_dataset/ILSVRC2012_val_00032927.bin 224 224 +30219 ./prep_dataset/ILSVRC2012_val_00044549.bin 224 224 +30220 ./prep_dataset/ILSVRC2012_val_00028498.bin 224 224 +30221 ./prep_dataset/ILSVRC2012_val_00031694.bin 224 224 +30222 ./prep_dataset/ILSVRC2012_val_00021902.bin 224 224 +30223 ./prep_dataset/ILSVRC2012_val_00029534.bin 224 224 +30224 ./prep_dataset/ILSVRC2012_val_00010165.bin 224 224 +30225 ./prep_dataset/ILSVRC2012_val_00035614.bin 224 224 +30226 ./prep_dataset/ILSVRC2012_val_00012784.bin 224 224 +30227 ./prep_dataset/ILSVRC2012_val_00016727.bin 224 224 +30228 ./prep_dataset/ILSVRC2012_val_00029509.bin 224 224 +30229 ./prep_dataset/ILSVRC2012_val_00037452.bin 224 224 +30230 ./prep_dataset/ILSVRC2012_val_00004668.bin 224 224 +30231 ./prep_dataset/ILSVRC2012_val_00031040.bin 224 224 +30232 ./prep_dataset/ILSVRC2012_val_00005822.bin 224 224 +30233 ./prep_dataset/ILSVRC2012_val_00015992.bin 224 224 +30234 ./prep_dataset/ILSVRC2012_val_00049580.bin 224 224 +30235 ./prep_dataset/ILSVRC2012_val_00031322.bin 224 224 +30236 ./prep_dataset/ILSVRC2012_val_00029071.bin 224 224 +30237 ./prep_dataset/ILSVRC2012_val_00001238.bin 224 224 +30238 ./prep_dataset/ILSVRC2012_val_00039181.bin 224 224 +30239 ./prep_dataset/ILSVRC2012_val_00028929.bin 224 224 +30240 ./prep_dataset/ILSVRC2012_val_00022324.bin 224 224 +30241 ./prep_dataset/ILSVRC2012_val_00035168.bin 224 224 +30242 ./prep_dataset/ILSVRC2012_val_00033676.bin 224 224 +30243 ./prep_dataset/ILSVRC2012_val_00014377.bin 224 224 +30244 ./prep_dataset/ILSVRC2012_val_00045383.bin 224 224 +30245 ./prep_dataset/ILSVRC2012_val_00004454.bin 224 224 +30246 ./prep_dataset/ILSVRC2012_val_00016474.bin 224 224 +30247 ./prep_dataset/ILSVRC2012_val_00048383.bin 224 224 +30248 ./prep_dataset/ILSVRC2012_val_00033252.bin 224 224 +30249 ./prep_dataset/ILSVRC2012_val_00008608.bin 224 224 +30250 ./prep_dataset/ILSVRC2012_val_00013964.bin 224 224 +30251 ./prep_dataset/ILSVRC2012_val_00001709.bin 224 224 +30252 ./prep_dataset/ILSVRC2012_val_00028219.bin 224 224 +30253 ./prep_dataset/ILSVRC2012_val_00025441.bin 224 224 +30254 ./prep_dataset/ILSVRC2012_val_00011400.bin 224 224 +30255 ./prep_dataset/ILSVRC2012_val_00022654.bin 224 224 +30256 ./prep_dataset/ILSVRC2012_val_00040669.bin 224 224 +30257 ./prep_dataset/ILSVRC2012_val_00046068.bin 224 224 +30258 ./prep_dataset/ILSVRC2012_val_00009456.bin 224 224 +30259 ./prep_dataset/ILSVRC2012_val_00002579.bin 224 224 +30260 ./prep_dataset/ILSVRC2012_val_00028738.bin 224 224 +30261 ./prep_dataset/ILSVRC2012_val_00005225.bin 224 224 +30262 ./prep_dataset/ILSVRC2012_val_00049444.bin 224 224 +30263 ./prep_dataset/ILSVRC2012_val_00028720.bin 224 224 +30264 ./prep_dataset/ILSVRC2012_val_00014208.bin 224 224 +30265 ./prep_dataset/ILSVRC2012_val_00040407.bin 224 224 +30266 ./prep_dataset/ILSVRC2012_val_00048992.bin 224 224 +30267 ./prep_dataset/ILSVRC2012_val_00049377.bin 224 224 +30268 ./prep_dataset/ILSVRC2012_val_00032561.bin 224 224 +30269 ./prep_dataset/ILSVRC2012_val_00035703.bin 224 224 +30270 ./prep_dataset/ILSVRC2012_val_00027584.bin 224 224 +30271 ./prep_dataset/ILSVRC2012_val_00003622.bin 224 224 +30272 ./prep_dataset/ILSVRC2012_val_00017486.bin 224 224 +30273 ./prep_dataset/ILSVRC2012_val_00002812.bin 224 224 +30274 ./prep_dataset/ILSVRC2012_val_00045268.bin 224 224 +30275 ./prep_dataset/ILSVRC2012_val_00013525.bin 224 224 +30276 ./prep_dataset/ILSVRC2012_val_00042883.bin 224 224 +30277 ./prep_dataset/ILSVRC2012_val_00029929.bin 224 224 +30278 ./prep_dataset/ILSVRC2012_val_00015335.bin 224 224 +30279 ./prep_dataset/ILSVRC2012_val_00013633.bin 224 224 +30280 ./prep_dataset/ILSVRC2012_val_00048310.bin 224 224 +30281 ./prep_dataset/ILSVRC2012_val_00000733.bin 224 224 +30282 ./prep_dataset/ILSVRC2012_val_00020282.bin 224 224 +30283 ./prep_dataset/ILSVRC2012_val_00027514.bin 224 224 +30284 ./prep_dataset/ILSVRC2012_val_00008728.bin 224 224 +30285 ./prep_dataset/ILSVRC2012_val_00036988.bin 224 224 +30286 ./prep_dataset/ILSVRC2012_val_00006999.bin 224 224 +30287 ./prep_dataset/ILSVRC2012_val_00005957.bin 224 224 +30288 ./prep_dataset/ILSVRC2012_val_00008389.bin 224 224 +30289 ./prep_dataset/ILSVRC2012_val_00025428.bin 224 224 +30290 ./prep_dataset/ILSVRC2012_val_00009120.bin 224 224 +30291 ./prep_dataset/ILSVRC2012_val_00045501.bin 224 224 +30292 ./prep_dataset/ILSVRC2012_val_00000166.bin 224 224 +30293 ./prep_dataset/ILSVRC2012_val_00042071.bin 224 224 +30294 ./prep_dataset/ILSVRC2012_val_00036472.bin 224 224 +30295 ./prep_dataset/ILSVRC2012_val_00020139.bin 224 224 +30296 ./prep_dataset/ILSVRC2012_val_00024532.bin 224 224 +30297 ./prep_dataset/ILSVRC2012_val_00005643.bin 224 224 +30298 ./prep_dataset/ILSVRC2012_val_00048815.bin 224 224 +30299 ./prep_dataset/ILSVRC2012_val_00026991.bin 224 224 +30300 ./prep_dataset/ILSVRC2012_val_00007002.bin 224 224 +30301 ./prep_dataset/ILSVRC2012_val_00004145.bin 224 224 +30302 ./prep_dataset/ILSVRC2012_val_00004140.bin 224 224 +30303 ./prep_dataset/ILSVRC2012_val_00040133.bin 224 224 +30304 ./prep_dataset/ILSVRC2012_val_00038944.bin 224 224 +30305 ./prep_dataset/ILSVRC2012_val_00006583.bin 224 224 +30306 ./prep_dataset/ILSVRC2012_val_00044135.bin 224 224 +30307 ./prep_dataset/ILSVRC2012_val_00004509.bin 224 224 +30308 ./prep_dataset/ILSVRC2012_val_00017853.bin 224 224 +30309 ./prep_dataset/ILSVRC2012_val_00041437.bin 224 224 +30310 ./prep_dataset/ILSVRC2012_val_00034107.bin 224 224 +30311 ./prep_dataset/ILSVRC2012_val_00013191.bin 224 224 +30312 ./prep_dataset/ILSVRC2012_val_00018304.bin 224 224 +30313 ./prep_dataset/ILSVRC2012_val_00016428.bin 224 224 +30314 ./prep_dataset/ILSVRC2012_val_00041864.bin 224 224 +30315 ./prep_dataset/ILSVRC2012_val_00048105.bin 224 224 +30316 ./prep_dataset/ILSVRC2012_val_00000754.bin 224 224 +30317 ./prep_dataset/ILSVRC2012_val_00009540.bin 224 224 +30318 ./prep_dataset/ILSVRC2012_val_00042233.bin 224 224 +30319 ./prep_dataset/ILSVRC2012_val_00011549.bin 224 224 +30320 ./prep_dataset/ILSVRC2012_val_00042513.bin 224 224 +30321 ./prep_dataset/ILSVRC2012_val_00003312.bin 224 224 +30322 ./prep_dataset/ILSVRC2012_val_00046763.bin 224 224 +30323 ./prep_dataset/ILSVRC2012_val_00026421.bin 224 224 +30324 ./prep_dataset/ILSVRC2012_val_00049134.bin 224 224 +30325 ./prep_dataset/ILSVRC2012_val_00043504.bin 224 224 +30326 ./prep_dataset/ILSVRC2012_val_00034869.bin 224 224 +30327 ./prep_dataset/ILSVRC2012_val_00025608.bin 224 224 +30328 ./prep_dataset/ILSVRC2012_val_00003795.bin 224 224 +30329 ./prep_dataset/ILSVRC2012_val_00017594.bin 224 224 +30330 ./prep_dataset/ILSVRC2012_val_00038776.bin 224 224 +30331 ./prep_dataset/ILSVRC2012_val_00036039.bin 224 224 +30332 ./prep_dataset/ILSVRC2012_val_00036366.bin 224 224 +30333 ./prep_dataset/ILSVRC2012_val_00027671.bin 224 224 +30334 ./prep_dataset/ILSVRC2012_val_00004222.bin 224 224 +30335 ./prep_dataset/ILSVRC2012_val_00024151.bin 224 224 +30336 ./prep_dataset/ILSVRC2012_val_00000215.bin 224 224 +30337 ./prep_dataset/ILSVRC2012_val_00018906.bin 224 224 +30338 ./prep_dataset/ILSVRC2012_val_00035950.bin 224 224 +30339 ./prep_dataset/ILSVRC2012_val_00045205.bin 224 224 +30340 ./prep_dataset/ILSVRC2012_val_00032893.bin 224 224 +30341 ./prep_dataset/ILSVRC2012_val_00025224.bin 224 224 +30342 ./prep_dataset/ILSVRC2012_val_00005825.bin 224 224 +30343 ./prep_dataset/ILSVRC2012_val_00026415.bin 224 224 +30344 ./prep_dataset/ILSVRC2012_val_00005888.bin 224 224 +30345 ./prep_dataset/ILSVRC2012_val_00009490.bin 224 224 +30346 ./prep_dataset/ILSVRC2012_val_00020259.bin 224 224 +30347 ./prep_dataset/ILSVRC2012_val_00035140.bin 224 224 +30348 ./prep_dataset/ILSVRC2012_val_00036265.bin 224 224 +30349 ./prep_dataset/ILSVRC2012_val_00037250.bin 224 224 +30350 ./prep_dataset/ILSVRC2012_val_00037301.bin 224 224 +30351 ./prep_dataset/ILSVRC2012_val_00014185.bin 224 224 +30352 ./prep_dataset/ILSVRC2012_val_00029512.bin 224 224 +30353 ./prep_dataset/ILSVRC2012_val_00040156.bin 224 224 +30354 ./prep_dataset/ILSVRC2012_val_00024381.bin 224 224 +30355 ./prep_dataset/ILSVRC2012_val_00007490.bin 224 224 +30356 ./prep_dataset/ILSVRC2012_val_00015890.bin 224 224 +30357 ./prep_dataset/ILSVRC2012_val_00013555.bin 224 224 +30358 ./prep_dataset/ILSVRC2012_val_00046757.bin 224 224 +30359 ./prep_dataset/ILSVRC2012_val_00020793.bin 224 224 +30360 ./prep_dataset/ILSVRC2012_val_00032344.bin 224 224 +30361 ./prep_dataset/ILSVRC2012_val_00026690.bin 224 224 +30362 ./prep_dataset/ILSVRC2012_val_00034120.bin 224 224 +30363 ./prep_dataset/ILSVRC2012_val_00036598.bin 224 224 +30364 ./prep_dataset/ILSVRC2012_val_00041480.bin 224 224 +30365 ./prep_dataset/ILSVRC2012_val_00032963.bin 224 224 +30366 ./prep_dataset/ILSVRC2012_val_00012886.bin 224 224 +30367 ./prep_dataset/ILSVRC2012_val_00003896.bin 224 224 +30368 ./prep_dataset/ILSVRC2012_val_00031597.bin 224 224 +30369 ./prep_dataset/ILSVRC2012_val_00006134.bin 224 224 +30370 ./prep_dataset/ILSVRC2012_val_00028353.bin 224 224 +30371 ./prep_dataset/ILSVRC2012_val_00045972.bin 224 224 +30372 ./prep_dataset/ILSVRC2012_val_00034650.bin 224 224 +30373 ./prep_dataset/ILSVRC2012_val_00035864.bin 224 224 +30374 ./prep_dataset/ILSVRC2012_val_00031688.bin 224 224 +30375 ./prep_dataset/ILSVRC2012_val_00024946.bin 224 224 +30376 ./prep_dataset/ILSVRC2012_val_00019226.bin 224 224 +30377 ./prep_dataset/ILSVRC2012_val_00000318.bin 224 224 +30378 ./prep_dataset/ILSVRC2012_val_00044834.bin 224 224 +30379 ./prep_dataset/ILSVRC2012_val_00010337.bin 224 224 +30380 ./prep_dataset/ILSVRC2012_val_00026184.bin 224 224 +30381 ./prep_dataset/ILSVRC2012_val_00037330.bin 224 224 +30382 ./prep_dataset/ILSVRC2012_val_00009479.bin 224 224 +30383 ./prep_dataset/ILSVRC2012_val_00026347.bin 224 224 +30384 ./prep_dataset/ILSVRC2012_val_00017940.bin 224 224 +30385 ./prep_dataset/ILSVRC2012_val_00004697.bin 224 224 +30386 ./prep_dataset/ILSVRC2012_val_00044784.bin 224 224 +30387 ./prep_dataset/ILSVRC2012_val_00040398.bin 224 224 +30388 ./prep_dataset/ILSVRC2012_val_00032178.bin 224 224 +30389 ./prep_dataset/ILSVRC2012_val_00015203.bin 224 224 +30390 ./prep_dataset/ILSVRC2012_val_00031247.bin 224 224 +30391 ./prep_dataset/ILSVRC2012_val_00004343.bin 224 224 +30392 ./prep_dataset/ILSVRC2012_val_00013233.bin 224 224 +30393 ./prep_dataset/ILSVRC2012_val_00039033.bin 224 224 +30394 ./prep_dataset/ILSVRC2012_val_00004656.bin 224 224 +30395 ./prep_dataset/ILSVRC2012_val_00001073.bin 224 224 +30396 ./prep_dataset/ILSVRC2012_val_00024694.bin 224 224 +30397 ./prep_dataset/ILSVRC2012_val_00022071.bin 224 224 +30398 ./prep_dataset/ILSVRC2012_val_00039207.bin 224 224 +30399 ./prep_dataset/ILSVRC2012_val_00014835.bin 224 224 +30400 ./prep_dataset/ILSVRC2012_val_00009970.bin 224 224 +30401 ./prep_dataset/ILSVRC2012_val_00046040.bin 224 224 +30402 ./prep_dataset/ILSVRC2012_val_00034412.bin 224 224 +30403 ./prep_dataset/ILSVRC2012_val_00000722.bin 224 224 +30404 ./prep_dataset/ILSVRC2012_val_00015619.bin 224 224 +30405 ./prep_dataset/ILSVRC2012_val_00001871.bin 224 224 +30406 ./prep_dataset/ILSVRC2012_val_00025991.bin 224 224 +30407 ./prep_dataset/ILSVRC2012_val_00032871.bin 224 224 +30408 ./prep_dataset/ILSVRC2012_val_00018338.bin 224 224 +30409 ./prep_dataset/ILSVRC2012_val_00000685.bin 224 224 +30410 ./prep_dataset/ILSVRC2012_val_00026238.bin 224 224 +30411 ./prep_dataset/ILSVRC2012_val_00030670.bin 224 224 +30412 ./prep_dataset/ILSVRC2012_val_00025269.bin 224 224 +30413 ./prep_dataset/ILSVRC2012_val_00028978.bin 224 224 +30414 ./prep_dataset/ILSVRC2012_val_00042663.bin 224 224 +30415 ./prep_dataset/ILSVRC2012_val_00002220.bin 224 224 +30416 ./prep_dataset/ILSVRC2012_val_00020690.bin 224 224 +30417 ./prep_dataset/ILSVRC2012_val_00022323.bin 224 224 +30418 ./prep_dataset/ILSVRC2012_val_00043866.bin 224 224 +30419 ./prep_dataset/ILSVRC2012_val_00011409.bin 224 224 +30420 ./prep_dataset/ILSVRC2012_val_00023077.bin 224 224 +30421 ./prep_dataset/ILSVRC2012_val_00005018.bin 224 224 +30422 ./prep_dataset/ILSVRC2012_val_00022541.bin 224 224 +30423 ./prep_dataset/ILSVRC2012_val_00036570.bin 224 224 +30424 ./prep_dataset/ILSVRC2012_val_00014324.bin 224 224 +30425 ./prep_dataset/ILSVRC2012_val_00045916.bin 224 224 +30426 ./prep_dataset/ILSVRC2012_val_00044449.bin 224 224 +30427 ./prep_dataset/ILSVRC2012_val_00020458.bin 224 224 +30428 ./prep_dataset/ILSVRC2012_val_00016745.bin 224 224 +30429 ./prep_dataset/ILSVRC2012_val_00023384.bin 224 224 +30430 ./prep_dataset/ILSVRC2012_val_00002677.bin 224 224 +30431 ./prep_dataset/ILSVRC2012_val_00023418.bin 224 224 +30432 ./prep_dataset/ILSVRC2012_val_00029722.bin 224 224 +30433 ./prep_dataset/ILSVRC2012_val_00026662.bin 224 224 +30434 ./prep_dataset/ILSVRC2012_val_00029867.bin 224 224 +30435 ./prep_dataset/ILSVRC2012_val_00040900.bin 224 224 +30436 ./prep_dataset/ILSVRC2012_val_00020710.bin 224 224 +30437 ./prep_dataset/ILSVRC2012_val_00039528.bin 224 224 +30438 ./prep_dataset/ILSVRC2012_val_00038308.bin 224 224 +30439 ./prep_dataset/ILSVRC2012_val_00017966.bin 224 224 +30440 ./prep_dataset/ILSVRC2012_val_00028752.bin 224 224 +30441 ./prep_dataset/ILSVRC2012_val_00015492.bin 224 224 +30442 ./prep_dataset/ILSVRC2012_val_00046729.bin 224 224 +30443 ./prep_dataset/ILSVRC2012_val_00032420.bin 224 224 +30444 ./prep_dataset/ILSVRC2012_val_00001626.bin 224 224 +30445 ./prep_dataset/ILSVRC2012_val_00024107.bin 224 224 +30446 ./prep_dataset/ILSVRC2012_val_00026255.bin 224 224 +30447 ./prep_dataset/ILSVRC2012_val_00033064.bin 224 224 +30448 ./prep_dataset/ILSVRC2012_val_00002889.bin 224 224 +30449 ./prep_dataset/ILSVRC2012_val_00034584.bin 224 224 +30450 ./prep_dataset/ILSVRC2012_val_00020247.bin 224 224 +30451 ./prep_dataset/ILSVRC2012_val_00032175.bin 224 224 +30452 ./prep_dataset/ILSVRC2012_val_00026395.bin 224 224 +30453 ./prep_dataset/ILSVRC2012_val_00022939.bin 224 224 +30454 ./prep_dataset/ILSVRC2012_val_00030826.bin 224 224 +30455 ./prep_dataset/ILSVRC2012_val_00026869.bin 224 224 +30456 ./prep_dataset/ILSVRC2012_val_00006311.bin 224 224 +30457 ./prep_dataset/ILSVRC2012_val_00011356.bin 224 224 +30458 ./prep_dataset/ILSVRC2012_val_00036955.bin 224 224 +30459 ./prep_dataset/ILSVRC2012_val_00001384.bin 224 224 +30460 ./prep_dataset/ILSVRC2012_val_00019633.bin 224 224 +30461 ./prep_dataset/ILSVRC2012_val_00026017.bin 224 224 +30462 ./prep_dataset/ILSVRC2012_val_00028231.bin 224 224 +30463 ./prep_dataset/ILSVRC2012_val_00012825.bin 224 224 +30464 ./prep_dataset/ILSVRC2012_val_00040463.bin 224 224 +30465 ./prep_dataset/ILSVRC2012_val_00041526.bin 224 224 +30466 ./prep_dataset/ILSVRC2012_val_00043384.bin 224 224 +30467 ./prep_dataset/ILSVRC2012_val_00036350.bin 224 224 +30468 ./prep_dataset/ILSVRC2012_val_00009763.bin 224 224 +30469 ./prep_dataset/ILSVRC2012_val_00038316.bin 224 224 +30470 ./prep_dataset/ILSVRC2012_val_00016577.bin 224 224 +30471 ./prep_dataset/ILSVRC2012_val_00012767.bin 224 224 +30472 ./prep_dataset/ILSVRC2012_val_00035978.bin 224 224 +30473 ./prep_dataset/ILSVRC2012_val_00036582.bin 224 224 +30474 ./prep_dataset/ILSVRC2012_val_00016000.bin 224 224 +30475 ./prep_dataset/ILSVRC2012_val_00000098.bin 224 224 +30476 ./prep_dataset/ILSVRC2012_val_00043158.bin 224 224 +30477 ./prep_dataset/ILSVRC2012_val_00025242.bin 224 224 +30478 ./prep_dataset/ILSVRC2012_val_00047958.bin 224 224 +30479 ./prep_dataset/ILSVRC2012_val_00037324.bin 224 224 +30480 ./prep_dataset/ILSVRC2012_val_00030779.bin 224 224 +30481 ./prep_dataset/ILSVRC2012_val_00044603.bin 224 224 +30482 ./prep_dataset/ILSVRC2012_val_00017035.bin 224 224 +30483 ./prep_dataset/ILSVRC2012_val_00008205.bin 224 224 +30484 ./prep_dataset/ILSVRC2012_val_00048766.bin 224 224 +30485 ./prep_dataset/ILSVRC2012_val_00000972.bin 224 224 +30486 ./prep_dataset/ILSVRC2012_val_00039323.bin 224 224 +30487 ./prep_dataset/ILSVRC2012_val_00012815.bin 224 224 +30488 ./prep_dataset/ILSVRC2012_val_00042476.bin 224 224 +30489 ./prep_dataset/ILSVRC2012_val_00037690.bin 224 224 +30490 ./prep_dataset/ILSVRC2012_val_00010092.bin 224 224 +30491 ./prep_dataset/ILSVRC2012_val_00023515.bin 224 224 +30492 ./prep_dataset/ILSVRC2012_val_00049390.bin 224 224 +30493 ./prep_dataset/ILSVRC2012_val_00019407.bin 224 224 +30494 ./prep_dataset/ILSVRC2012_val_00041768.bin 224 224 +30495 ./prep_dataset/ILSVRC2012_val_00001344.bin 224 224 +30496 ./prep_dataset/ILSVRC2012_val_00006680.bin 224 224 +30497 ./prep_dataset/ILSVRC2012_val_00046598.bin 224 224 +30498 ./prep_dataset/ILSVRC2012_val_00044503.bin 224 224 +30499 ./prep_dataset/ILSVRC2012_val_00016083.bin 224 224 +30500 ./prep_dataset/ILSVRC2012_val_00041784.bin 224 224 +30501 ./prep_dataset/ILSVRC2012_val_00019057.bin 224 224 +30502 ./prep_dataset/ILSVRC2012_val_00041018.bin 224 224 +30503 ./prep_dataset/ILSVRC2012_val_00037832.bin 224 224 +30504 ./prep_dataset/ILSVRC2012_val_00014892.bin 224 224 +30505 ./prep_dataset/ILSVRC2012_val_00035388.bin 224 224 +30506 ./prep_dataset/ILSVRC2012_val_00015812.bin 224 224 +30507 ./prep_dataset/ILSVRC2012_val_00043277.bin 224 224 +30508 ./prep_dataset/ILSVRC2012_val_00045926.bin 224 224 +30509 ./prep_dataset/ILSVRC2012_val_00022520.bin 224 224 +30510 ./prep_dataset/ILSVRC2012_val_00036725.bin 224 224 +30511 ./prep_dataset/ILSVRC2012_val_00035191.bin 224 224 +30512 ./prep_dataset/ILSVRC2012_val_00002450.bin 224 224 +30513 ./prep_dataset/ILSVRC2012_val_00003210.bin 224 224 +30514 ./prep_dataset/ILSVRC2012_val_00011771.bin 224 224 +30515 ./prep_dataset/ILSVRC2012_val_00047530.bin 224 224 +30516 ./prep_dataset/ILSVRC2012_val_00025277.bin 224 224 +30517 ./prep_dataset/ILSVRC2012_val_00024683.bin 224 224 +30518 ./prep_dataset/ILSVRC2012_val_00028386.bin 224 224 +30519 ./prep_dataset/ILSVRC2012_val_00038611.bin 224 224 +30520 ./prep_dataset/ILSVRC2012_val_00009954.bin 224 224 +30521 ./prep_dataset/ILSVRC2012_val_00014886.bin 224 224 +30522 ./prep_dataset/ILSVRC2012_val_00014370.bin 224 224 +30523 ./prep_dataset/ILSVRC2012_val_00014582.bin 224 224 +30524 ./prep_dataset/ILSVRC2012_val_00028644.bin 224 224 +30525 ./prep_dataset/ILSVRC2012_val_00000159.bin 224 224 +30526 ./prep_dataset/ILSVRC2012_val_00037033.bin 224 224 +30527 ./prep_dataset/ILSVRC2012_val_00045570.bin 224 224 +30528 ./prep_dataset/ILSVRC2012_val_00022923.bin 224 224 +30529 ./prep_dataset/ILSVRC2012_val_00047444.bin 224 224 +30530 ./prep_dataset/ILSVRC2012_val_00000218.bin 224 224 +30531 ./prep_dataset/ILSVRC2012_val_00022246.bin 224 224 +30532 ./prep_dataset/ILSVRC2012_val_00046868.bin 224 224 +30533 ./prep_dataset/ILSVRC2012_val_00034998.bin 224 224 +30534 ./prep_dataset/ILSVRC2012_val_00049175.bin 224 224 +30535 ./prep_dataset/ILSVRC2012_val_00017874.bin 224 224 +30536 ./prep_dataset/ILSVRC2012_val_00025765.bin 224 224 +30537 ./prep_dataset/ILSVRC2012_val_00017123.bin 224 224 +30538 ./prep_dataset/ILSVRC2012_val_00007825.bin 224 224 +30539 ./prep_dataset/ILSVRC2012_val_00002993.bin 224 224 +30540 ./prep_dataset/ILSVRC2012_val_00011217.bin 224 224 +30541 ./prep_dataset/ILSVRC2012_val_00005750.bin 224 224 +30542 ./prep_dataset/ILSVRC2012_val_00037935.bin 224 224 +30543 ./prep_dataset/ILSVRC2012_val_00037015.bin 224 224 +30544 ./prep_dataset/ILSVRC2012_val_00048472.bin 224 224 +30545 ./prep_dataset/ILSVRC2012_val_00025371.bin 224 224 +30546 ./prep_dataset/ILSVRC2012_val_00024552.bin 224 224 +30547 ./prep_dataset/ILSVRC2012_val_00004369.bin 224 224 +30548 ./prep_dataset/ILSVRC2012_val_00011502.bin 224 224 +30549 ./prep_dataset/ILSVRC2012_val_00044916.bin 224 224 +30550 ./prep_dataset/ILSVRC2012_val_00033850.bin 224 224 +30551 ./prep_dataset/ILSVRC2012_val_00043043.bin 224 224 +30552 ./prep_dataset/ILSVRC2012_val_00006413.bin 224 224 +30553 ./prep_dataset/ILSVRC2012_val_00024318.bin 224 224 +30554 ./prep_dataset/ILSVRC2012_val_00019059.bin 224 224 +30555 ./prep_dataset/ILSVRC2012_val_00016448.bin 224 224 +30556 ./prep_dataset/ILSVRC2012_val_00026095.bin 224 224 +30557 ./prep_dataset/ILSVRC2012_val_00034779.bin 224 224 +30558 ./prep_dataset/ILSVRC2012_val_00018029.bin 224 224 +30559 ./prep_dataset/ILSVRC2012_val_00029953.bin 224 224 +30560 ./prep_dataset/ILSVRC2012_val_00020320.bin 224 224 +30561 ./prep_dataset/ILSVRC2012_val_00041508.bin 224 224 +30562 ./prep_dataset/ILSVRC2012_val_00003712.bin 224 224 +30563 ./prep_dataset/ILSVRC2012_val_00012697.bin 224 224 +30564 ./prep_dataset/ILSVRC2012_val_00045562.bin 224 224 +30565 ./prep_dataset/ILSVRC2012_val_00014177.bin 224 224 +30566 ./prep_dataset/ILSVRC2012_val_00004459.bin 224 224 +30567 ./prep_dataset/ILSVRC2012_val_00044309.bin 224 224 +30568 ./prep_dataset/ILSVRC2012_val_00042428.bin 224 224 +30569 ./prep_dataset/ILSVRC2012_val_00012152.bin 224 224 +30570 ./prep_dataset/ILSVRC2012_val_00030754.bin 224 224 +30571 ./prep_dataset/ILSVRC2012_val_00013472.bin 224 224 +30572 ./prep_dataset/ILSVRC2012_val_00010291.bin 224 224 +30573 ./prep_dataset/ILSVRC2012_val_00019409.bin 224 224 +30574 ./prep_dataset/ILSVRC2012_val_00021827.bin 224 224 +30575 ./prep_dataset/ILSVRC2012_val_00031241.bin 224 224 +30576 ./prep_dataset/ILSVRC2012_val_00032373.bin 224 224 +30577 ./prep_dataset/ILSVRC2012_val_00039935.bin 224 224 +30578 ./prep_dataset/ILSVRC2012_val_00047149.bin 224 224 +30579 ./prep_dataset/ILSVRC2012_val_00007755.bin 224 224 +30580 ./prep_dataset/ILSVRC2012_val_00010118.bin 224 224 +30581 ./prep_dataset/ILSVRC2012_val_00014918.bin 224 224 +30582 ./prep_dataset/ILSVRC2012_val_00023524.bin 224 224 +30583 ./prep_dataset/ILSVRC2012_val_00030621.bin 224 224 +30584 ./prep_dataset/ILSVRC2012_val_00014075.bin 224 224 +30585 ./prep_dataset/ILSVRC2012_val_00023680.bin 224 224 +30586 ./prep_dataset/ILSVRC2012_val_00020288.bin 224 224 +30587 ./prep_dataset/ILSVRC2012_val_00019986.bin 224 224 +30588 ./prep_dataset/ILSVRC2012_val_00027972.bin 224 224 +30589 ./prep_dataset/ILSVRC2012_val_00038149.bin 224 224 +30590 ./prep_dataset/ILSVRC2012_val_00039375.bin 224 224 +30591 ./prep_dataset/ILSVRC2012_val_00048544.bin 224 224 +30592 ./prep_dataset/ILSVRC2012_val_00049977.bin 224 224 +30593 ./prep_dataset/ILSVRC2012_val_00019097.bin 224 224 +30594 ./prep_dataset/ILSVRC2012_val_00013603.bin 224 224 +30595 ./prep_dataset/ILSVRC2012_val_00030904.bin 224 224 +30596 ./prep_dataset/ILSVRC2012_val_00007722.bin 224 224 +30597 ./prep_dataset/ILSVRC2012_val_00049503.bin 224 224 +30598 ./prep_dataset/ILSVRC2012_val_00037567.bin 224 224 +30599 ./prep_dataset/ILSVRC2012_val_00017231.bin 224 224 +30600 ./prep_dataset/ILSVRC2012_val_00029878.bin 224 224 +30601 ./prep_dataset/ILSVRC2012_val_00034325.bin 224 224 +30602 ./prep_dataset/ILSVRC2012_val_00027274.bin 224 224 +30603 ./prep_dataset/ILSVRC2012_val_00002602.bin 224 224 +30604 ./prep_dataset/ILSVRC2012_val_00011860.bin 224 224 +30605 ./prep_dataset/ILSVRC2012_val_00031160.bin 224 224 +30606 ./prep_dataset/ILSVRC2012_val_00041232.bin 224 224 +30607 ./prep_dataset/ILSVRC2012_val_00017421.bin 224 224 +30608 ./prep_dataset/ILSVRC2012_val_00047266.bin 224 224 +30609 ./prep_dataset/ILSVRC2012_val_00003156.bin 224 224 +30610 ./prep_dataset/ILSVRC2012_val_00036466.bin 224 224 +30611 ./prep_dataset/ILSVRC2012_val_00009310.bin 224 224 +30612 ./prep_dataset/ILSVRC2012_val_00001303.bin 224 224 +30613 ./prep_dataset/ILSVRC2012_val_00048532.bin 224 224 +30614 ./prep_dataset/ILSVRC2012_val_00014852.bin 224 224 +30615 ./prep_dataset/ILSVRC2012_val_00023676.bin 224 224 +30616 ./prep_dataset/ILSVRC2012_val_00049586.bin 224 224 +30617 ./prep_dataset/ILSVRC2012_val_00007174.bin 224 224 +30618 ./prep_dataset/ILSVRC2012_val_00003360.bin 224 224 +30619 ./prep_dataset/ILSVRC2012_val_00018455.bin 224 224 +30620 ./prep_dataset/ILSVRC2012_val_00049589.bin 224 224 +30621 ./prep_dataset/ILSVRC2012_val_00002746.bin 224 224 +30622 ./prep_dataset/ILSVRC2012_val_00048509.bin 224 224 +30623 ./prep_dataset/ILSVRC2012_val_00000338.bin 224 224 +30624 ./prep_dataset/ILSVRC2012_val_00005997.bin 224 224 +30625 ./prep_dataset/ILSVRC2012_val_00043877.bin 224 224 +30626 ./prep_dataset/ILSVRC2012_val_00033391.bin 224 224 +30627 ./prep_dataset/ILSVRC2012_val_00047962.bin 224 224 +30628 ./prep_dataset/ILSVRC2012_val_00047875.bin 224 224 +30629 ./prep_dataset/ILSVRC2012_val_00013883.bin 224 224 +30630 ./prep_dataset/ILSVRC2012_val_00029302.bin 224 224 +30631 ./prep_dataset/ILSVRC2012_val_00011432.bin 224 224 +30632 ./prep_dataset/ILSVRC2012_val_00043272.bin 224 224 +30633 ./prep_dataset/ILSVRC2012_val_00031126.bin 224 224 +30634 ./prep_dataset/ILSVRC2012_val_00039872.bin 224 224 +30635 ./prep_dataset/ILSVRC2012_val_00015719.bin 224 224 +30636 ./prep_dataset/ILSVRC2012_val_00038383.bin 224 224 +30637 ./prep_dataset/ILSVRC2012_val_00023728.bin 224 224 +30638 ./prep_dataset/ILSVRC2012_val_00045069.bin 224 224 +30639 ./prep_dataset/ILSVRC2012_val_00015324.bin 224 224 +30640 ./prep_dataset/ILSVRC2012_val_00049800.bin 224 224 +30641 ./prep_dataset/ILSVRC2012_val_00042521.bin 224 224 +30642 ./prep_dataset/ILSVRC2012_val_00023511.bin 224 224 +30643 ./prep_dataset/ILSVRC2012_val_00009896.bin 224 224 +30644 ./prep_dataset/ILSVRC2012_val_00047080.bin 224 224 +30645 ./prep_dataset/ILSVRC2012_val_00023765.bin 224 224 +30646 ./prep_dataset/ILSVRC2012_val_00041635.bin 224 224 +30647 ./prep_dataset/ILSVRC2012_val_00012637.bin 224 224 +30648 ./prep_dataset/ILSVRC2012_val_00019572.bin 224 224 +30649 ./prep_dataset/ILSVRC2012_val_00016563.bin 224 224 +30650 ./prep_dataset/ILSVRC2012_val_00004500.bin 224 224 +30651 ./prep_dataset/ILSVRC2012_val_00030835.bin 224 224 +30652 ./prep_dataset/ILSVRC2012_val_00006620.bin 224 224 +30653 ./prep_dataset/ILSVRC2012_val_00010258.bin 224 224 +30654 ./prep_dataset/ILSVRC2012_val_00032779.bin 224 224 +30655 ./prep_dataset/ILSVRC2012_val_00024788.bin 224 224 +30656 ./prep_dataset/ILSVRC2012_val_00047248.bin 224 224 +30657 ./prep_dataset/ILSVRC2012_val_00018325.bin 224 224 +30658 ./prep_dataset/ILSVRC2012_val_00003572.bin 224 224 +30659 ./prep_dataset/ILSVRC2012_val_00036621.bin 224 224 +30660 ./prep_dataset/ILSVRC2012_val_00045216.bin 224 224 +30661 ./prep_dataset/ILSVRC2012_val_00046569.bin 224 224 +30662 ./prep_dataset/ILSVRC2012_val_00043441.bin 224 224 +30663 ./prep_dataset/ILSVRC2012_val_00030939.bin 224 224 +30664 ./prep_dataset/ILSVRC2012_val_00016749.bin 224 224 +30665 ./prep_dataset/ILSVRC2012_val_00018725.bin 224 224 +30666 ./prep_dataset/ILSVRC2012_val_00017476.bin 224 224 +30667 ./prep_dataset/ILSVRC2012_val_00007208.bin 224 224 +30668 ./prep_dataset/ILSVRC2012_val_00010486.bin 224 224 +30669 ./prep_dataset/ILSVRC2012_val_00027067.bin 224 224 +30670 ./prep_dataset/ILSVRC2012_val_00003007.bin 224 224 +30671 ./prep_dataset/ILSVRC2012_val_00043404.bin 224 224 +30672 ./prep_dataset/ILSVRC2012_val_00017152.bin 224 224 +30673 ./prep_dataset/ILSVRC2012_val_00033054.bin 224 224 +30674 ./prep_dataset/ILSVRC2012_val_00010209.bin 224 224 +30675 ./prep_dataset/ILSVRC2012_val_00036235.bin 224 224 +30676 ./prep_dataset/ILSVRC2012_val_00043054.bin 224 224 +30677 ./prep_dataset/ILSVRC2012_val_00029341.bin 224 224 +30678 ./prep_dataset/ILSVRC2012_val_00004231.bin 224 224 +30679 ./prep_dataset/ILSVRC2012_val_00028030.bin 224 224 +30680 ./prep_dataset/ILSVRC2012_val_00030156.bin 224 224 +30681 ./prep_dataset/ILSVRC2012_val_00002282.bin 224 224 +30682 ./prep_dataset/ILSVRC2012_val_00013647.bin 224 224 +30683 ./prep_dataset/ILSVRC2012_val_00022172.bin 224 224 +30684 ./prep_dataset/ILSVRC2012_val_00029568.bin 224 224 +30685 ./prep_dataset/ILSVRC2012_val_00004728.bin 224 224 +30686 ./prep_dataset/ILSVRC2012_val_00038657.bin 224 224 +30687 ./prep_dataset/ILSVRC2012_val_00034642.bin 224 224 +30688 ./prep_dataset/ILSVRC2012_val_00005599.bin 224 224 +30689 ./prep_dataset/ILSVRC2012_val_00006742.bin 224 224 +30690 ./prep_dataset/ILSVRC2012_val_00029853.bin 224 224 +30691 ./prep_dataset/ILSVRC2012_val_00015706.bin 224 224 +30692 ./prep_dataset/ILSVRC2012_val_00049369.bin 224 224 +30693 ./prep_dataset/ILSVRC2012_val_00010543.bin 224 224 +30694 ./prep_dataset/ILSVRC2012_val_00032848.bin 224 224 +30695 ./prep_dataset/ILSVRC2012_val_00007842.bin 224 224 +30696 ./prep_dataset/ILSVRC2012_val_00013956.bin 224 224 +30697 ./prep_dataset/ILSVRC2012_val_00021833.bin 224 224 +30698 ./prep_dataset/ILSVRC2012_val_00029445.bin 224 224 +30699 ./prep_dataset/ILSVRC2012_val_00024431.bin 224 224 +30700 ./prep_dataset/ILSVRC2012_val_00014080.bin 224 224 +30701 ./prep_dataset/ILSVRC2012_val_00023317.bin 224 224 +30702 ./prep_dataset/ILSVRC2012_val_00029838.bin 224 224 +30703 ./prep_dataset/ILSVRC2012_val_00013379.bin 224 224 +30704 ./prep_dataset/ILSVRC2012_val_00022268.bin 224 224 +30705 ./prep_dataset/ILSVRC2012_val_00022828.bin 224 224 +30706 ./prep_dataset/ILSVRC2012_val_00030857.bin 224 224 +30707 ./prep_dataset/ILSVRC2012_val_00034448.bin 224 224 +30708 ./prep_dataset/ILSVRC2012_val_00038915.bin 224 224 +30709 ./prep_dataset/ILSVRC2012_val_00027435.bin 224 224 +30710 ./prep_dataset/ILSVRC2012_val_00030034.bin 224 224 +30711 ./prep_dataset/ILSVRC2012_val_00042325.bin 224 224 +30712 ./prep_dataset/ILSVRC2012_val_00021089.bin 224 224 +30713 ./prep_dataset/ILSVRC2012_val_00043521.bin 224 224 +30714 ./prep_dataset/ILSVRC2012_val_00041323.bin 224 224 +30715 ./prep_dataset/ILSVRC2012_val_00043582.bin 224 224 +30716 ./prep_dataset/ILSVRC2012_val_00021151.bin 224 224 +30717 ./prep_dataset/ILSVRC2012_val_00044558.bin 224 224 +30718 ./prep_dataset/ILSVRC2012_val_00028377.bin 224 224 +30719 ./prep_dataset/ILSVRC2012_val_00036497.bin 224 224 +30720 ./prep_dataset/ILSVRC2012_val_00046115.bin 224 224 +30721 ./prep_dataset/ILSVRC2012_val_00020579.bin 224 224 +30722 ./prep_dataset/ILSVRC2012_val_00049668.bin 224 224 +30723 ./prep_dataset/ILSVRC2012_val_00004742.bin 224 224 +30724 ./prep_dataset/ILSVRC2012_val_00029208.bin 224 224 +30725 ./prep_dataset/ILSVRC2012_val_00031350.bin 224 224 +30726 ./prep_dataset/ILSVRC2012_val_00038516.bin 224 224 +30727 ./prep_dataset/ILSVRC2012_val_00008136.bin 224 224 +30728 ./prep_dataset/ILSVRC2012_val_00012695.bin 224 224 +30729 ./prep_dataset/ILSVRC2012_val_00003596.bin 224 224 +30730 ./prep_dataset/ILSVRC2012_val_00016775.bin 224 224 +30731 ./prep_dataset/ILSVRC2012_val_00022116.bin 224 224 +30732 ./prep_dataset/ILSVRC2012_val_00039710.bin 224 224 +30733 ./prep_dataset/ILSVRC2012_val_00006047.bin 224 224 +30734 ./prep_dataset/ILSVRC2012_val_00034653.bin 224 224 +30735 ./prep_dataset/ILSVRC2012_val_00002548.bin 224 224 +30736 ./prep_dataset/ILSVRC2012_val_00039662.bin 224 224 +30737 ./prep_dataset/ILSVRC2012_val_00048207.bin 224 224 +30738 ./prep_dataset/ILSVRC2012_val_00040029.bin 224 224 +30739 ./prep_dataset/ILSVRC2012_val_00014473.bin 224 224 +30740 ./prep_dataset/ILSVRC2012_val_00005806.bin 224 224 +30741 ./prep_dataset/ILSVRC2012_val_00002422.bin 224 224 +30742 ./prep_dataset/ILSVRC2012_val_00034499.bin 224 224 +30743 ./prep_dataset/ILSVRC2012_val_00014561.bin 224 224 +30744 ./prep_dataset/ILSVRC2012_val_00030539.bin 224 224 +30745 ./prep_dataset/ILSVRC2012_val_00034545.bin 224 224 +30746 ./prep_dataset/ILSVRC2012_val_00005923.bin 224 224 +30747 ./prep_dataset/ILSVRC2012_val_00012529.bin 224 224 +30748 ./prep_dataset/ILSVRC2012_val_00029401.bin 224 224 +30749 ./prep_dataset/ILSVRC2012_val_00035605.bin 224 224 +30750 ./prep_dataset/ILSVRC2012_val_00002237.bin 224 224 +30751 ./prep_dataset/ILSVRC2012_val_00000016.bin 224 224 +30752 ./prep_dataset/ILSVRC2012_val_00033287.bin 224 224 +30753 ./prep_dataset/ILSVRC2012_val_00012511.bin 224 224 +30754 ./prep_dataset/ILSVRC2012_val_00046432.bin 224 224 +30755 ./prep_dataset/ILSVRC2012_val_00026928.bin 224 224 +30756 ./prep_dataset/ILSVRC2012_val_00035394.bin 224 224 +30757 ./prep_dataset/ILSVRC2012_val_00026771.bin 224 224 +30758 ./prep_dataset/ILSVRC2012_val_00025340.bin 224 224 +30759 ./prep_dataset/ILSVRC2012_val_00039576.bin 224 224 +30760 ./prep_dataset/ILSVRC2012_val_00025398.bin 224 224 +30761 ./prep_dataset/ILSVRC2012_val_00022593.bin 224 224 +30762 ./prep_dataset/ILSVRC2012_val_00008918.bin 224 224 +30763 ./prep_dataset/ILSVRC2012_val_00029617.bin 224 224 +30764 ./prep_dataset/ILSVRC2012_val_00030380.bin 224 224 +30765 ./prep_dataset/ILSVRC2012_val_00038183.bin 224 224 +30766 ./prep_dataset/ILSVRC2012_val_00000012.bin 224 224 +30767 ./prep_dataset/ILSVRC2012_val_00045281.bin 224 224 +30768 ./prep_dataset/ILSVRC2012_val_00045243.bin 224 224 +30769 ./prep_dataset/ILSVRC2012_val_00010336.bin 224 224 +30770 ./prep_dataset/ILSVRC2012_val_00046159.bin 224 224 +30771 ./prep_dataset/ILSVRC2012_val_00031693.bin 224 224 +30772 ./prep_dataset/ILSVRC2012_val_00004902.bin 224 224 +30773 ./prep_dataset/ILSVRC2012_val_00045629.bin 224 224 +30774 ./prep_dataset/ILSVRC2012_val_00025295.bin 224 224 +30775 ./prep_dataset/ILSVRC2012_val_00025804.bin 224 224 +30776 ./prep_dataset/ILSVRC2012_val_00016112.bin 224 224 +30777 ./prep_dataset/ILSVRC2012_val_00007248.bin 224 224 +30778 ./prep_dataset/ILSVRC2012_val_00047877.bin 224 224 +30779 ./prep_dataset/ILSVRC2012_val_00028821.bin 224 224 +30780 ./prep_dataset/ILSVRC2012_val_00025214.bin 224 224 +30781 ./prep_dataset/ILSVRC2012_val_00046679.bin 224 224 +30782 ./prep_dataset/ILSVRC2012_val_00036811.bin 224 224 +30783 ./prep_dataset/ILSVRC2012_val_00019153.bin 224 224 +30784 ./prep_dataset/ILSVRC2012_val_00015134.bin 224 224 +30785 ./prep_dataset/ILSVRC2012_val_00002083.bin 224 224 +30786 ./prep_dataset/ILSVRC2012_val_00042965.bin 224 224 +30787 ./prep_dataset/ILSVRC2012_val_00042216.bin 224 224 +30788 ./prep_dataset/ILSVRC2012_val_00045697.bin 224 224 +30789 ./prep_dataset/ILSVRC2012_val_00038141.bin 224 224 +30790 ./prep_dataset/ILSVRC2012_val_00049716.bin 224 224 +30791 ./prep_dataset/ILSVRC2012_val_00035815.bin 224 224 +30792 ./prep_dataset/ILSVRC2012_val_00048069.bin 224 224 +30793 ./prep_dataset/ILSVRC2012_val_00048741.bin 224 224 +30794 ./prep_dataset/ILSVRC2012_val_00003521.bin 224 224 +30795 ./prep_dataset/ILSVRC2012_val_00014661.bin 224 224 +30796 ./prep_dataset/ILSVRC2012_val_00019274.bin 224 224 +30797 ./prep_dataset/ILSVRC2012_val_00004655.bin 224 224 +30798 ./prep_dataset/ILSVRC2012_val_00016638.bin 224 224 +30799 ./prep_dataset/ILSVRC2012_val_00018479.bin 224 224 +30800 ./prep_dataset/ILSVRC2012_val_00037365.bin 224 224 +30801 ./prep_dataset/ILSVRC2012_val_00012497.bin 224 224 +30802 ./prep_dataset/ILSVRC2012_val_00042200.bin 224 224 +30803 ./prep_dataset/ILSVRC2012_val_00005365.bin 224 224 +30804 ./prep_dataset/ILSVRC2012_val_00013092.bin 224 224 +30805 ./prep_dataset/ILSVRC2012_val_00035998.bin 224 224 +30806 ./prep_dataset/ILSVRC2012_val_00015778.bin 224 224 +30807 ./prep_dataset/ILSVRC2012_val_00016193.bin 224 224 +30808 ./prep_dataset/ILSVRC2012_val_00035753.bin 224 224 +30809 ./prep_dataset/ILSVRC2012_val_00018347.bin 224 224 +30810 ./prep_dataset/ILSVRC2012_val_00016018.bin 224 224 +30811 ./prep_dataset/ILSVRC2012_val_00046788.bin 224 224 +30812 ./prep_dataset/ILSVRC2012_val_00038994.bin 224 224 +30813 ./prep_dataset/ILSVRC2012_val_00015576.bin 224 224 +30814 ./prep_dataset/ILSVRC2012_val_00029658.bin 224 224 +30815 ./prep_dataset/ILSVRC2012_val_00029021.bin 224 224 +30816 ./prep_dataset/ILSVRC2012_val_00001458.bin 224 224 +30817 ./prep_dataset/ILSVRC2012_val_00000340.bin 224 224 +30818 ./prep_dataset/ILSVRC2012_val_00007502.bin 224 224 +30819 ./prep_dataset/ILSVRC2012_val_00002761.bin 224 224 +30820 ./prep_dataset/ILSVRC2012_val_00030784.bin 224 224 +30821 ./prep_dataset/ILSVRC2012_val_00022207.bin 224 224 +30822 ./prep_dataset/ILSVRC2012_val_00018953.bin 224 224 +30823 ./prep_dataset/ILSVRC2012_val_00023072.bin 224 224 +30824 ./prep_dataset/ILSVRC2012_val_00011646.bin 224 224 +30825 ./prep_dataset/ILSVRC2012_val_00044044.bin 224 224 +30826 ./prep_dataset/ILSVRC2012_val_00008636.bin 224 224 +30827 ./prep_dataset/ILSVRC2012_val_00019798.bin 224 224 +30828 ./prep_dataset/ILSVRC2012_val_00027572.bin 224 224 +30829 ./prep_dataset/ILSVRC2012_val_00007237.bin 224 224 +30830 ./prep_dataset/ILSVRC2012_val_00013141.bin 224 224 +30831 ./prep_dataset/ILSVRC2012_val_00016215.bin 224 224 +30832 ./prep_dataset/ILSVRC2012_val_00048220.bin 224 224 +30833 ./prep_dataset/ILSVRC2012_val_00002907.bin 224 224 +30834 ./prep_dataset/ILSVRC2012_val_00024595.bin 224 224 +30835 ./prep_dataset/ILSVRC2012_val_00021369.bin 224 224 +30836 ./prep_dataset/ILSVRC2012_val_00008508.bin 224 224 +30837 ./prep_dataset/ILSVRC2012_val_00032444.bin 224 224 +30838 ./prep_dataset/ILSVRC2012_val_00002056.bin 224 224 +30839 ./prep_dataset/ILSVRC2012_val_00040783.bin 224 224 +30840 ./prep_dataset/ILSVRC2012_val_00045263.bin 224 224 +30841 ./prep_dataset/ILSVRC2012_val_00021115.bin 224 224 +30842 ./prep_dataset/ILSVRC2012_val_00048347.bin 224 224 +30843 ./prep_dataset/ILSVRC2012_val_00012117.bin 224 224 +30844 ./prep_dataset/ILSVRC2012_val_00018094.bin 224 224 +30845 ./prep_dataset/ILSVRC2012_val_00005141.bin 224 224 +30846 ./prep_dataset/ILSVRC2012_val_00026296.bin 224 224 +30847 ./prep_dataset/ILSVRC2012_val_00043236.bin 224 224 +30848 ./prep_dataset/ILSVRC2012_val_00022977.bin 224 224 +30849 ./prep_dataset/ILSVRC2012_val_00010917.bin 224 224 +30850 ./prep_dataset/ILSVRC2012_val_00016414.bin 224 224 +30851 ./prep_dataset/ILSVRC2012_val_00048357.bin 224 224 +30852 ./prep_dataset/ILSVRC2012_val_00018723.bin 224 224 +30853 ./prep_dataset/ILSVRC2012_val_00029095.bin 224 224 +30854 ./prep_dataset/ILSVRC2012_val_00021024.bin 224 224 +30855 ./prep_dataset/ILSVRC2012_val_00026360.bin 224 224 +30856 ./prep_dataset/ILSVRC2012_val_00019514.bin 224 224 +30857 ./prep_dataset/ILSVRC2012_val_00033345.bin 224 224 +30858 ./prep_dataset/ILSVRC2012_val_00046082.bin 224 224 +30859 ./prep_dataset/ILSVRC2012_val_00014190.bin 224 224 +30860 ./prep_dataset/ILSVRC2012_val_00043830.bin 224 224 +30861 ./prep_dataset/ILSVRC2012_val_00034415.bin 224 224 +30862 ./prep_dataset/ILSVRC2012_val_00012491.bin 224 224 +30863 ./prep_dataset/ILSVRC2012_val_00034746.bin 224 224 +30864 ./prep_dataset/ILSVRC2012_val_00016372.bin 224 224 +30865 ./prep_dataset/ILSVRC2012_val_00018557.bin 224 224 +30866 ./prep_dataset/ILSVRC2012_val_00020988.bin 224 224 +30867 ./prep_dataset/ILSVRC2012_val_00025780.bin 224 224 +30868 ./prep_dataset/ILSVRC2012_val_00039200.bin 224 224 +30869 ./prep_dataset/ILSVRC2012_val_00035174.bin 224 224 +30870 ./prep_dataset/ILSVRC2012_val_00028560.bin 224 224 +30871 ./prep_dataset/ILSVRC2012_val_00001716.bin 224 224 +30872 ./prep_dataset/ILSVRC2012_val_00021649.bin 224 224 +30873 ./prep_dataset/ILSVRC2012_val_00008075.bin 224 224 +30874 ./prep_dataset/ILSVRC2012_val_00000085.bin 224 224 +30875 ./prep_dataset/ILSVRC2012_val_00002786.bin 224 224 +30876 ./prep_dataset/ILSVRC2012_val_00026122.bin 224 224 +30877 ./prep_dataset/ILSVRC2012_val_00040624.bin 224 224 +30878 ./prep_dataset/ILSVRC2012_val_00007734.bin 224 224 +30879 ./prep_dataset/ILSVRC2012_val_00014307.bin 224 224 +30880 ./prep_dataset/ILSVRC2012_val_00018282.bin 224 224 +30881 ./prep_dataset/ILSVRC2012_val_00046819.bin 224 224 +30882 ./prep_dataset/ILSVRC2012_val_00006826.bin 224 224 +30883 ./prep_dataset/ILSVRC2012_val_00034271.bin 224 224 +30884 ./prep_dataset/ILSVRC2012_val_00025591.bin 224 224 +30885 ./prep_dataset/ILSVRC2012_val_00042977.bin 224 224 +30886 ./prep_dataset/ILSVRC2012_val_00049336.bin 224 224 +30887 ./prep_dataset/ILSVRC2012_val_00000426.bin 224 224 +30888 ./prep_dataset/ILSVRC2012_val_00009745.bin 224 224 +30889 ./prep_dataset/ILSVRC2012_val_00002178.bin 224 224 +30890 ./prep_dataset/ILSVRC2012_val_00041927.bin 224 224 +30891 ./prep_dataset/ILSVRC2012_val_00046530.bin 224 224 +30892 ./prep_dataset/ILSVRC2012_val_00025966.bin 224 224 +30893 ./prep_dataset/ILSVRC2012_val_00039845.bin 224 224 +30894 ./prep_dataset/ILSVRC2012_val_00009185.bin 224 224 +30895 ./prep_dataset/ILSVRC2012_val_00032290.bin 224 224 +30896 ./prep_dataset/ILSVRC2012_val_00047968.bin 224 224 +30897 ./prep_dataset/ILSVRC2012_val_00041212.bin 224 224 +30898 ./prep_dataset/ILSVRC2012_val_00022355.bin 224 224 +30899 ./prep_dataset/ILSVRC2012_val_00013958.bin 224 224 +30900 ./prep_dataset/ILSVRC2012_val_00026083.bin 224 224 +30901 ./prep_dataset/ILSVRC2012_val_00007175.bin 224 224 +30902 ./prep_dataset/ILSVRC2012_val_00023732.bin 224 224 +30903 ./prep_dataset/ILSVRC2012_val_00007652.bin 224 224 +30904 ./prep_dataset/ILSVRC2012_val_00033435.bin 224 224 +30905 ./prep_dataset/ILSVRC2012_val_00025138.bin 224 224 +30906 ./prep_dataset/ILSVRC2012_val_00036345.bin 224 224 +30907 ./prep_dataset/ILSVRC2012_val_00040655.bin 224 224 +30908 ./prep_dataset/ILSVRC2012_val_00025792.bin 224 224 +30909 ./prep_dataset/ILSVRC2012_val_00031412.bin 224 224 +30910 ./prep_dataset/ILSVRC2012_val_00003496.bin 224 224 +30911 ./prep_dataset/ILSVRC2012_val_00022704.bin 224 224 +30912 ./prep_dataset/ILSVRC2012_val_00034458.bin 224 224 +30913 ./prep_dataset/ILSVRC2012_val_00021411.bin 224 224 +30914 ./prep_dataset/ILSVRC2012_val_00018927.bin 224 224 +30915 ./prep_dataset/ILSVRC2012_val_00001271.bin 224 224 +30916 ./prep_dataset/ILSVRC2012_val_00033076.bin 224 224 +30917 ./prep_dataset/ILSVRC2012_val_00001025.bin 224 224 +30918 ./prep_dataset/ILSVRC2012_val_00001087.bin 224 224 +30919 ./prep_dataset/ILSVRC2012_val_00023281.bin 224 224 +30920 ./prep_dataset/ILSVRC2012_val_00034689.bin 224 224 +30921 ./prep_dataset/ILSVRC2012_val_00035037.bin 224 224 +30922 ./prep_dataset/ILSVRC2012_val_00034441.bin 224 224 +30923 ./prep_dataset/ILSVRC2012_val_00004513.bin 224 224 +30924 ./prep_dataset/ILSVRC2012_val_00020494.bin 224 224 +30925 ./prep_dataset/ILSVRC2012_val_00031568.bin 224 224 +30926 ./prep_dataset/ILSVRC2012_val_00038186.bin 224 224 +30927 ./prep_dataset/ILSVRC2012_val_00024573.bin 224 224 +30928 ./prep_dataset/ILSVRC2012_val_00010858.bin 224 224 +30929 ./prep_dataset/ILSVRC2012_val_00037263.bin 224 224 +30930 ./prep_dataset/ILSVRC2012_val_00014289.bin 224 224 +30931 ./prep_dataset/ILSVRC2012_val_00045373.bin 224 224 +30932 ./prep_dataset/ILSVRC2012_val_00030267.bin 224 224 +30933 ./prep_dataset/ILSVRC2012_val_00031165.bin 224 224 +30934 ./prep_dataset/ILSVRC2012_val_00043102.bin 224 224 +30935 ./prep_dataset/ILSVRC2012_val_00045016.bin 224 224 +30936 ./prep_dataset/ILSVRC2012_val_00017838.bin 224 224 +30937 ./prep_dataset/ILSVRC2012_val_00023044.bin 224 224 +30938 ./prep_dataset/ILSVRC2012_val_00012212.bin 224 224 +30939 ./prep_dataset/ILSVRC2012_val_00012670.bin 224 224 +30940 ./prep_dataset/ILSVRC2012_val_00001410.bin 224 224 +30941 ./prep_dataset/ILSVRC2012_val_00044270.bin 224 224 +30942 ./prep_dataset/ILSVRC2012_val_00043756.bin 224 224 +30943 ./prep_dataset/ILSVRC2012_val_00002476.bin 224 224 +30944 ./prep_dataset/ILSVRC2012_val_00016413.bin 224 224 +30945 ./prep_dataset/ILSVRC2012_val_00049137.bin 224 224 +30946 ./prep_dataset/ILSVRC2012_val_00048286.bin 224 224 +30947 ./prep_dataset/ILSVRC2012_val_00020351.bin 224 224 +30948 ./prep_dataset/ILSVRC2012_val_00009162.bin 224 224 +30949 ./prep_dataset/ILSVRC2012_val_00044461.bin 224 224 +30950 ./prep_dataset/ILSVRC2012_val_00017229.bin 224 224 +30951 ./prep_dataset/ILSVRC2012_val_00049708.bin 224 224 +30952 ./prep_dataset/ILSVRC2012_val_00001329.bin 224 224 +30953 ./prep_dataset/ILSVRC2012_val_00023793.bin 224 224 +30954 ./prep_dataset/ILSVRC2012_val_00003379.bin 224 224 +30955 ./prep_dataset/ILSVRC2012_val_00029044.bin 224 224 +30956 ./prep_dataset/ILSVRC2012_val_00019503.bin 224 224 +30957 ./prep_dataset/ILSVRC2012_val_00017177.bin 224 224 +30958 ./prep_dataset/ILSVRC2012_val_00001311.bin 224 224 +30959 ./prep_dataset/ILSVRC2012_val_00001498.bin 224 224 +30960 ./prep_dataset/ILSVRC2012_val_00028470.bin 224 224 +30961 ./prep_dataset/ILSVRC2012_val_00004397.bin 224 224 +30962 ./prep_dataset/ILSVRC2012_val_00000748.bin 224 224 +30963 ./prep_dataset/ILSVRC2012_val_00034457.bin 224 224 +30964 ./prep_dataset/ILSVRC2012_val_00046319.bin 224 224 +30965 ./prep_dataset/ILSVRC2012_val_00004674.bin 224 224 +30966 ./prep_dataset/ILSVRC2012_val_00003282.bin 224 224 +30967 ./prep_dataset/ILSVRC2012_val_00018395.bin 224 224 +30968 ./prep_dataset/ILSVRC2012_val_00016857.bin 224 224 +30969 ./prep_dataset/ILSVRC2012_val_00028381.bin 224 224 +30970 ./prep_dataset/ILSVRC2012_val_00025707.bin 224 224 +30971 ./prep_dataset/ILSVRC2012_val_00001083.bin 224 224 +30972 ./prep_dataset/ILSVRC2012_val_00032348.bin 224 224 +30973 ./prep_dataset/ILSVRC2012_val_00039781.bin 224 224 +30974 ./prep_dataset/ILSVRC2012_val_00041328.bin 224 224 +30975 ./prep_dataset/ILSVRC2012_val_00032224.bin 224 224 +30976 ./prep_dataset/ILSVRC2012_val_00009972.bin 224 224 +30977 ./prep_dataset/ILSVRC2012_val_00021136.bin 224 224 +30978 ./prep_dataset/ILSVRC2012_val_00025131.bin 224 224 +30979 ./prep_dataset/ILSVRC2012_val_00028755.bin 224 224 +30980 ./prep_dataset/ILSVRC2012_val_00046900.bin 224 224 +30981 ./prep_dataset/ILSVRC2012_val_00039312.bin 224 224 +30982 ./prep_dataset/ILSVRC2012_val_00008745.bin 224 224 +30983 ./prep_dataset/ILSVRC2012_val_00042589.bin 224 224 +30984 ./prep_dataset/ILSVRC2012_val_00043623.bin 224 224 +30985 ./prep_dataset/ILSVRC2012_val_00032550.bin 224 224 +30986 ./prep_dataset/ILSVRC2012_val_00023519.bin 224 224 +30987 ./prep_dataset/ILSVRC2012_val_00018048.bin 224 224 +30988 ./prep_dataset/ILSVRC2012_val_00026401.bin 224 224 +30989 ./prep_dataset/ILSVRC2012_val_00037436.bin 224 224 +30990 ./prep_dataset/ILSVRC2012_val_00040470.bin 224 224 +30991 ./prep_dataset/ILSVRC2012_val_00017572.bin 224 224 +30992 ./prep_dataset/ILSVRC2012_val_00007200.bin 224 224 +30993 ./prep_dataset/ILSVRC2012_val_00037979.bin 224 224 +30994 ./prep_dataset/ILSVRC2012_val_00048329.bin 224 224 +30995 ./prep_dataset/ILSVRC2012_val_00026018.bin 224 224 +30996 ./prep_dataset/ILSVRC2012_val_00021633.bin 224 224 +30997 ./prep_dataset/ILSVRC2012_val_00014302.bin 224 224 +30998 ./prep_dataset/ILSVRC2012_val_00039923.bin 224 224 +30999 ./prep_dataset/ILSVRC2012_val_00023179.bin 224 224 +31000 ./prep_dataset/ILSVRC2012_val_00039496.bin 224 224 +31001 ./prep_dataset/ILSVRC2012_val_00021300.bin 224 224 +31002 ./prep_dataset/ILSVRC2012_val_00020059.bin 224 224 +31003 ./prep_dataset/ILSVRC2012_val_00042543.bin 224 224 +31004 ./prep_dataset/ILSVRC2012_val_00018335.bin 224 224 +31005 ./prep_dataset/ILSVRC2012_val_00001201.bin 224 224 +31006 ./prep_dataset/ILSVRC2012_val_00025466.bin 224 224 +31007 ./prep_dataset/ILSVRC2012_val_00013123.bin 224 224 +31008 ./prep_dataset/ILSVRC2012_val_00001046.bin 224 224 +31009 ./prep_dataset/ILSVRC2012_val_00048908.bin 224 224 +31010 ./prep_dataset/ILSVRC2012_val_00014585.bin 224 224 +31011 ./prep_dataset/ILSVRC2012_val_00010017.bin 224 224 +31012 ./prep_dataset/ILSVRC2012_val_00003598.bin 224 224 +31013 ./prep_dataset/ILSVRC2012_val_00010915.bin 224 224 +31014 ./prep_dataset/ILSVRC2012_val_00007475.bin 224 224 +31015 ./prep_dataset/ILSVRC2012_val_00008330.bin 224 224 +31016 ./prep_dataset/ILSVRC2012_val_00003426.bin 224 224 +31017 ./prep_dataset/ILSVRC2012_val_00034211.bin 224 224 +31018 ./prep_dataset/ILSVRC2012_val_00009402.bin 224 224 +31019 ./prep_dataset/ILSVRC2012_val_00047230.bin 224 224 +31020 ./prep_dataset/ILSVRC2012_val_00031297.bin 224 224 +31021 ./prep_dataset/ILSVRC2012_val_00008343.bin 224 224 +31022 ./prep_dataset/ILSVRC2012_val_00044181.bin 224 224 +31023 ./prep_dataset/ILSVRC2012_val_00032201.bin 224 224 +31024 ./prep_dataset/ILSVRC2012_val_00033343.bin 224 224 +31025 ./prep_dataset/ILSVRC2012_val_00028794.bin 224 224 +31026 ./prep_dataset/ILSVRC2012_val_00028775.bin 224 224 +31027 ./prep_dataset/ILSVRC2012_val_00006987.bin 224 224 +31028 ./prep_dataset/ILSVRC2012_val_00024006.bin 224 224 +31029 ./prep_dataset/ILSVRC2012_val_00013674.bin 224 224 +31030 ./prep_dataset/ILSVRC2012_val_00007176.bin 224 224 +31031 ./prep_dataset/ILSVRC2012_val_00035952.bin 224 224 +31032 ./prep_dataset/ILSVRC2012_val_00022393.bin 224 224 +31033 ./prep_dataset/ILSVRC2012_val_00042754.bin 224 224 +31034 ./prep_dataset/ILSVRC2012_val_00025176.bin 224 224 +31035 ./prep_dataset/ILSVRC2012_val_00007141.bin 224 224 +31036 ./prep_dataset/ILSVRC2012_val_00013514.bin 224 224 +31037 ./prep_dataset/ILSVRC2012_val_00048216.bin 224 224 +31038 ./prep_dataset/ILSVRC2012_val_00009768.bin 224 224 +31039 ./prep_dataset/ILSVRC2012_val_00014927.bin 224 224 +31040 ./prep_dataset/ILSVRC2012_val_00046795.bin 224 224 +31041 ./prep_dataset/ILSVRC2012_val_00038822.bin 224 224 +31042 ./prep_dataset/ILSVRC2012_val_00037691.bin 224 224 +31043 ./prep_dataset/ILSVRC2012_val_00010485.bin 224 224 +31044 ./prep_dataset/ILSVRC2012_val_00009360.bin 224 224 +31045 ./prep_dataset/ILSVRC2012_val_00042516.bin 224 224 +31046 ./prep_dataset/ILSVRC2012_val_00038192.bin 224 224 +31047 ./prep_dataset/ILSVRC2012_val_00046129.bin 224 224 +31048 ./prep_dataset/ILSVRC2012_val_00001077.bin 224 224 +31049 ./prep_dataset/ILSVRC2012_val_00024580.bin 224 224 +31050 ./prep_dataset/ILSVRC2012_val_00007447.bin 224 224 +31051 ./prep_dataset/ILSVRC2012_val_00040712.bin 224 224 +31052 ./prep_dataset/ILSVRC2012_val_00007838.bin 224 224 +31053 ./prep_dataset/ILSVRC2012_val_00023695.bin 224 224 +31054 ./prep_dataset/ILSVRC2012_val_00046753.bin 224 224 +31055 ./prep_dataset/ILSVRC2012_val_00030111.bin 224 224 +31056 ./prep_dataset/ILSVRC2012_val_00015942.bin 224 224 +31057 ./prep_dataset/ILSVRC2012_val_00027407.bin 224 224 +31058 ./prep_dataset/ILSVRC2012_val_00047813.bin 224 224 +31059 ./prep_dataset/ILSVRC2012_val_00008971.bin 224 224 +31060 ./prep_dataset/ILSVRC2012_val_00013339.bin 224 224 +31061 ./prep_dataset/ILSVRC2012_val_00000148.bin 224 224 +31062 ./prep_dataset/ILSVRC2012_val_00048457.bin 224 224 +31063 ./prep_dataset/ILSVRC2012_val_00024890.bin 224 224 +31064 ./prep_dataset/ILSVRC2012_val_00022430.bin 224 224 +31065 ./prep_dataset/ILSVRC2012_val_00009509.bin 224 224 +31066 ./prep_dataset/ILSVRC2012_val_00027546.bin 224 224 +31067 ./prep_dataset/ILSVRC2012_val_00043448.bin 224 224 +31068 ./prep_dataset/ILSVRC2012_val_00008355.bin 224 224 +31069 ./prep_dataset/ILSVRC2012_val_00008202.bin 224 224 +31070 ./prep_dataset/ILSVRC2012_val_00024967.bin 224 224 +31071 ./prep_dataset/ILSVRC2012_val_00019896.bin 224 224 +31072 ./prep_dataset/ILSVRC2012_val_00006821.bin 224 224 +31073 ./prep_dataset/ILSVRC2012_val_00038102.bin 224 224 +31074 ./prep_dataset/ILSVRC2012_val_00027237.bin 224 224 +31075 ./prep_dataset/ILSVRC2012_val_00001860.bin 224 224 +31076 ./prep_dataset/ILSVRC2012_val_00010591.bin 224 224 +31077 ./prep_dataset/ILSVRC2012_val_00004415.bin 224 224 +31078 ./prep_dataset/ILSVRC2012_val_00018142.bin 224 224 +31079 ./prep_dataset/ILSVRC2012_val_00012356.bin 224 224 +31080 ./prep_dataset/ILSVRC2012_val_00032007.bin 224 224 +31081 ./prep_dataset/ILSVRC2012_val_00014807.bin 224 224 +31082 ./prep_dataset/ILSVRC2012_val_00041078.bin 224 224 +31083 ./prep_dataset/ILSVRC2012_val_00046834.bin 224 224 +31084 ./prep_dataset/ILSVRC2012_val_00019005.bin 224 224 +31085 ./prep_dataset/ILSVRC2012_val_00023504.bin 224 224 +31086 ./prep_dataset/ILSVRC2012_val_00001750.bin 224 224 +31087 ./prep_dataset/ILSVRC2012_val_00037102.bin 224 224 +31088 ./prep_dataset/ILSVRC2012_val_00034471.bin 224 224 +31089 ./prep_dataset/ILSVRC2012_val_00030661.bin 224 224 +31090 ./prep_dataset/ILSVRC2012_val_00015015.bin 224 224 +31091 ./prep_dataset/ILSVRC2012_val_00034190.bin 224 224 +31092 ./prep_dataset/ILSVRC2012_val_00044230.bin 224 224 +31093 ./prep_dataset/ILSVRC2012_val_00043890.bin 224 224 +31094 ./prep_dataset/ILSVRC2012_val_00028105.bin 224 224 +31095 ./prep_dataset/ILSVRC2012_val_00033487.bin 224 224 +31096 ./prep_dataset/ILSVRC2012_val_00010561.bin 224 224 +31097 ./prep_dataset/ILSVRC2012_val_00028133.bin 224 224 +31098 ./prep_dataset/ILSVRC2012_val_00007495.bin 224 224 +31099 ./prep_dataset/ILSVRC2012_val_00046437.bin 224 224 +31100 ./prep_dataset/ILSVRC2012_val_00032513.bin 224 224 +31101 ./prep_dataset/ILSVRC2012_val_00031018.bin 224 224 +31102 ./prep_dataset/ILSVRC2012_val_00006974.bin 224 224 +31103 ./prep_dataset/ILSVRC2012_val_00001268.bin 224 224 +31104 ./prep_dataset/ILSVRC2012_val_00012114.bin 224 224 +31105 ./prep_dataset/ILSVRC2012_val_00044432.bin 224 224 +31106 ./prep_dataset/ILSVRC2012_val_00041105.bin 224 224 +31107 ./prep_dataset/ILSVRC2012_val_00000330.bin 224 224 +31108 ./prep_dataset/ILSVRC2012_val_00033166.bin 224 224 +31109 ./prep_dataset/ILSVRC2012_val_00034375.bin 224 224 +31110 ./prep_dataset/ILSVRC2012_val_00024163.bin 224 224 +31111 ./prep_dataset/ILSVRC2012_val_00033875.bin 224 224 +31112 ./prep_dataset/ILSVRC2012_val_00021240.bin 224 224 +31113 ./prep_dataset/ILSVRC2012_val_00004395.bin 224 224 +31114 ./prep_dataset/ILSVRC2012_val_00038874.bin 224 224 +31115 ./prep_dataset/ILSVRC2012_val_00033334.bin 224 224 +31116 ./prep_dataset/ILSVRC2012_val_00028090.bin 224 224 +31117 ./prep_dataset/ILSVRC2012_val_00010025.bin 224 224 +31118 ./prep_dataset/ILSVRC2012_val_00020120.bin 224 224 +31119 ./prep_dataset/ILSVRC2012_val_00004483.bin 224 224 +31120 ./prep_dataset/ILSVRC2012_val_00037419.bin 224 224 +31121 ./prep_dataset/ILSVRC2012_val_00023539.bin 224 224 +31122 ./prep_dataset/ILSVRC2012_val_00021349.bin 224 224 +31123 ./prep_dataset/ILSVRC2012_val_00043502.bin 224 224 +31124 ./prep_dataset/ILSVRC2012_val_00045370.bin 224 224 +31125 ./prep_dataset/ILSVRC2012_val_00042656.bin 224 224 +31126 ./prep_dataset/ILSVRC2012_val_00023347.bin 224 224 +31127 ./prep_dataset/ILSVRC2012_val_00010826.bin 224 224 +31128 ./prep_dataset/ILSVRC2012_val_00006009.bin 224 224 +31129 ./prep_dataset/ILSVRC2012_val_00035616.bin 224 224 +31130 ./prep_dataset/ILSVRC2012_val_00023332.bin 224 224 +31131 ./prep_dataset/ILSVRC2012_val_00045862.bin 224 224 +31132 ./prep_dataset/ILSVRC2012_val_00010304.bin 224 224 +31133 ./prep_dataset/ILSVRC2012_val_00012141.bin 224 224 +31134 ./prep_dataset/ILSVRC2012_val_00041875.bin 224 224 +31135 ./prep_dataset/ILSVRC2012_val_00035669.bin 224 224 +31136 ./prep_dataset/ILSVRC2012_val_00001263.bin 224 224 +31137 ./prep_dataset/ILSVRC2012_val_00034757.bin 224 224 +31138 ./prep_dataset/ILSVRC2012_val_00042824.bin 224 224 +31139 ./prep_dataset/ILSVRC2012_val_00030909.bin 224 224 +31140 ./prep_dataset/ILSVRC2012_val_00048418.bin 224 224 +31141 ./prep_dataset/ILSVRC2012_val_00010347.bin 224 224 +31142 ./prep_dataset/ILSVRC2012_val_00041695.bin 224 224 +31143 ./prep_dataset/ILSVRC2012_val_00007468.bin 224 224 +31144 ./prep_dataset/ILSVRC2012_val_00046462.bin 224 224 +31145 ./prep_dataset/ILSVRC2012_val_00013736.bin 224 224 +31146 ./prep_dataset/ILSVRC2012_val_00005239.bin 224 224 +31147 ./prep_dataset/ILSVRC2012_val_00028654.bin 224 224 +31148 ./prep_dataset/ILSVRC2012_val_00042174.bin 224 224 +31149 ./prep_dataset/ILSVRC2012_val_00028656.bin 224 224 +31150 ./prep_dataset/ILSVRC2012_val_00025979.bin 224 224 +31151 ./prep_dataset/ILSVRC2012_val_00035118.bin 224 224 +31152 ./prep_dataset/ILSVRC2012_val_00008566.bin 224 224 +31153 ./prep_dataset/ILSVRC2012_val_00034044.bin 224 224 +31154 ./prep_dataset/ILSVRC2012_val_00036182.bin 224 224 +31155 ./prep_dataset/ILSVRC2012_val_00007103.bin 224 224 +31156 ./prep_dataset/ILSVRC2012_val_00024144.bin 224 224 +31157 ./prep_dataset/ILSVRC2012_val_00046577.bin 224 224 +31158 ./prep_dataset/ILSVRC2012_val_00041453.bin 224 224 +31159 ./prep_dataset/ILSVRC2012_val_00037273.bin 224 224 +31160 ./prep_dataset/ILSVRC2012_val_00025712.bin 224 224 +31161 ./prep_dataset/ILSVRC2012_val_00010298.bin 224 224 +31162 ./prep_dataset/ILSVRC2012_val_00037621.bin 224 224 +31163 ./prep_dataset/ILSVRC2012_val_00036427.bin 224 224 +31164 ./prep_dataset/ILSVRC2012_val_00006689.bin 224 224 +31165 ./prep_dataset/ILSVRC2012_val_00030453.bin 224 224 +31166 ./prep_dataset/ILSVRC2012_val_00005754.bin 224 224 +31167 ./prep_dataset/ILSVRC2012_val_00012347.bin 224 224 +31168 ./prep_dataset/ILSVRC2012_val_00010868.bin 224 224 +31169 ./prep_dataset/ILSVRC2012_val_00024345.bin 224 224 +31170 ./prep_dataset/ILSVRC2012_val_00013162.bin 224 224 +31171 ./prep_dataset/ILSVRC2012_val_00040364.bin 224 224 +31172 ./prep_dataset/ILSVRC2012_val_00031875.bin 224 224 +31173 ./prep_dataset/ILSVRC2012_val_00047293.bin 224 224 +31174 ./prep_dataset/ILSVRC2012_val_00039042.bin 224 224 +31175 ./prep_dataset/ILSVRC2012_val_00037971.bin 224 224 +31176 ./prep_dataset/ILSVRC2012_val_00011144.bin 224 224 +31177 ./prep_dataset/ILSVRC2012_val_00005165.bin 224 224 +31178 ./prep_dataset/ILSVRC2012_val_00045079.bin 224 224 +31179 ./prep_dataset/ILSVRC2012_val_00013017.bin 224 224 +31180 ./prep_dataset/ILSVRC2012_val_00042001.bin 224 224 +31181 ./prep_dataset/ILSVRC2012_val_00019843.bin 224 224 +31182 ./prep_dataset/ILSVRC2012_val_00016709.bin 224 224 +31183 ./prep_dataset/ILSVRC2012_val_00001732.bin 224 224 +31184 ./prep_dataset/ILSVRC2012_val_00038764.bin 224 224 +31185 ./prep_dataset/ILSVRC2012_val_00030143.bin 224 224 +31186 ./prep_dataset/ILSVRC2012_val_00024772.bin 224 224 +31187 ./prep_dataset/ILSVRC2012_val_00000682.bin 224 224 +31188 ./prep_dataset/ILSVRC2012_val_00046702.bin 224 224 +31189 ./prep_dataset/ILSVRC2012_val_00005324.bin 224 224 +31190 ./prep_dataset/ILSVRC2012_val_00009916.bin 224 224 +31191 ./prep_dataset/ILSVRC2012_val_00036792.bin 224 224 +31192 ./prep_dataset/ILSVRC2012_val_00043309.bin 224 224 +31193 ./prep_dataset/ILSVRC2012_val_00017437.bin 224 224 +31194 ./prep_dataset/ILSVRC2012_val_00028194.bin 224 224 +31195 ./prep_dataset/ILSVRC2012_val_00016924.bin 224 224 +31196 ./prep_dataset/ILSVRC2012_val_00004575.bin 224 224 +31197 ./prep_dataset/ILSVRC2012_val_00034719.bin 224 224 +31198 ./prep_dataset/ILSVRC2012_val_00032808.bin 224 224 +31199 ./prep_dataset/ILSVRC2012_val_00031470.bin 224 224 +31200 ./prep_dataset/ILSVRC2012_val_00007610.bin 224 224 +31201 ./prep_dataset/ILSVRC2012_val_00016595.bin 224 224 +31202 ./prep_dataset/ILSVRC2012_val_00005246.bin 224 224 +31203 ./prep_dataset/ILSVRC2012_val_00046231.bin 224 224 +31204 ./prep_dataset/ILSVRC2012_val_00045194.bin 224 224 +31205 ./prep_dataset/ILSVRC2012_val_00022150.bin 224 224 +31206 ./prep_dataset/ILSVRC2012_val_00016553.bin 224 224 +31207 ./prep_dataset/ILSVRC2012_val_00040735.bin 224 224 +31208 ./prep_dataset/ILSVRC2012_val_00007563.bin 224 224 +31209 ./prep_dataset/ILSVRC2012_val_00048107.bin 224 224 +31210 ./prep_dataset/ILSVRC2012_val_00008873.bin 224 224 +31211 ./prep_dataset/ILSVRC2012_val_00026721.bin 224 224 +31212 ./prep_dataset/ILSVRC2012_val_00040809.bin 224 224 +31213 ./prep_dataset/ILSVRC2012_val_00011687.bin 224 224 +31214 ./prep_dataset/ILSVRC2012_val_00017068.bin 224 224 +31215 ./prep_dataset/ILSVRC2012_val_00008357.bin 224 224 +31216 ./prep_dataset/ILSVRC2012_val_00022421.bin 224 224 +31217 ./prep_dataset/ILSVRC2012_val_00039520.bin 224 224 +31218 ./prep_dataset/ILSVRC2012_val_00035794.bin 224 224 +31219 ./prep_dataset/ILSVRC2012_val_00017017.bin 224 224 +31220 ./prep_dataset/ILSVRC2012_val_00027222.bin 224 224 +31221 ./prep_dataset/ILSVRC2012_val_00021676.bin 224 224 +31222 ./prep_dataset/ILSVRC2012_val_00012539.bin 224 224 +31223 ./prep_dataset/ILSVRC2012_val_00015502.bin 224 224 +31224 ./prep_dataset/ILSVRC2012_val_00037881.bin 224 224 +31225 ./prep_dataset/ILSVRC2012_val_00001436.bin 224 224 +31226 ./prep_dataset/ILSVRC2012_val_00040408.bin 224 224 +31227 ./prep_dataset/ILSVRC2012_val_00031945.bin 224 224 +31228 ./prep_dataset/ILSVRC2012_val_00038196.bin 224 224 +31229 ./prep_dataset/ILSVRC2012_val_00037300.bin 224 224 +31230 ./prep_dataset/ILSVRC2012_val_00013581.bin 224 224 +31231 ./prep_dataset/ILSVRC2012_val_00039008.bin 224 224 +31232 ./prep_dataset/ILSVRC2012_val_00009992.bin 224 224 +31233 ./prep_dataset/ILSVRC2012_val_00015765.bin 224 224 +31234 ./prep_dataset/ILSVRC2012_val_00041545.bin 224 224 +31235 ./prep_dataset/ILSVRC2012_val_00015720.bin 224 224 +31236 ./prep_dataset/ILSVRC2012_val_00010559.bin 224 224 +31237 ./prep_dataset/ILSVRC2012_val_00045443.bin 224 224 +31238 ./prep_dataset/ILSVRC2012_val_00035543.bin 224 224 +31239 ./prep_dataset/ILSVRC2012_val_00017104.bin 224 224 +31240 ./prep_dataset/ILSVRC2012_val_00041689.bin 224 224 +31241 ./prep_dataset/ILSVRC2012_val_00018558.bin 224 224 +31242 ./prep_dataset/ILSVRC2012_val_00015025.bin 224 224 +31243 ./prep_dataset/ILSVRC2012_val_00021877.bin 224 224 +31244 ./prep_dataset/ILSVRC2012_val_00048468.bin 224 224 +31245 ./prep_dataset/ILSVRC2012_val_00011766.bin 224 224 +31246 ./prep_dataset/ILSVRC2012_val_00007938.bin 224 224 +31247 ./prep_dataset/ILSVRC2012_val_00042214.bin 224 224 +31248 ./prep_dataset/ILSVRC2012_val_00029279.bin 224 224 +31249 ./prep_dataset/ILSVRC2012_val_00020108.bin 224 224 +31250 ./prep_dataset/ILSVRC2012_val_00005797.bin 224 224 +31251 ./prep_dataset/ILSVRC2012_val_00019850.bin 224 224 +31252 ./prep_dataset/ILSVRC2012_val_00003438.bin 224 224 +31253 ./prep_dataset/ILSVRC2012_val_00047018.bin 224 224 +31254 ./prep_dataset/ILSVRC2012_val_00018170.bin 224 224 +31255 ./prep_dataset/ILSVRC2012_val_00026969.bin 224 224 +31256 ./prep_dataset/ILSVRC2012_val_00017666.bin 224 224 +31257 ./prep_dataset/ILSVRC2012_val_00033538.bin 224 224 +31258 ./prep_dataset/ILSVRC2012_val_00046402.bin 224 224 +31259 ./prep_dataset/ILSVRC2012_val_00018698.bin 224 224 +31260 ./prep_dataset/ILSVRC2012_val_00027321.bin 224 224 +31261 ./prep_dataset/ILSVRC2012_val_00011272.bin 224 224 +31262 ./prep_dataset/ILSVRC2012_val_00022221.bin 224 224 +31263 ./prep_dataset/ILSVRC2012_val_00045684.bin 224 224 +31264 ./prep_dataset/ILSVRC2012_val_00041337.bin 224 224 +31265 ./prep_dataset/ILSVRC2012_val_00018337.bin 224 224 +31266 ./prep_dataset/ILSVRC2012_val_00031186.bin 224 224 +31267 ./prep_dataset/ILSVRC2012_val_00024254.bin 224 224 +31268 ./prep_dataset/ILSVRC2012_val_00004787.bin 224 224 +31269 ./prep_dataset/ILSVRC2012_val_00046637.bin 224 224 +31270 ./prep_dataset/ILSVRC2012_val_00045002.bin 224 224 +31271 ./prep_dataset/ILSVRC2012_val_00042617.bin 224 224 +31272 ./prep_dataset/ILSVRC2012_val_00037393.bin 224 224 +31273 ./prep_dataset/ILSVRC2012_val_00021982.bin 224 224 +31274 ./prep_dataset/ILSVRC2012_val_00022174.bin 224 224 +31275 ./prep_dataset/ILSVRC2012_val_00028888.bin 224 224 +31276 ./prep_dataset/ILSVRC2012_val_00044299.bin 224 224 +31277 ./prep_dataset/ILSVRC2012_val_00018296.bin 224 224 +31278 ./prep_dataset/ILSVRC2012_val_00009256.bin 224 224 +31279 ./prep_dataset/ILSVRC2012_val_00005836.bin 224 224 +31280 ./prep_dataset/ILSVRC2012_val_00016421.bin 224 224 +31281 ./prep_dataset/ILSVRC2012_val_00035133.bin 224 224 +31282 ./prep_dataset/ILSVRC2012_val_00006685.bin 224 224 +31283 ./prep_dataset/ILSVRC2012_val_00000277.bin 224 224 +31284 ./prep_dataset/ILSVRC2012_val_00048728.bin 224 224 +31285 ./prep_dataset/ILSVRC2012_val_00047120.bin 224 224 +31286 ./prep_dataset/ILSVRC2012_val_00020096.bin 224 224 +31287 ./prep_dataset/ILSVRC2012_val_00009499.bin 224 224 +31288 ./prep_dataset/ILSVRC2012_val_00025733.bin 224 224 +31289 ./prep_dataset/ILSVRC2012_val_00024574.bin 224 224 +31290 ./prep_dataset/ILSVRC2012_val_00024124.bin 224 224 +31291 ./prep_dataset/ILSVRC2012_val_00043991.bin 224 224 +31292 ./prep_dataset/ILSVRC2012_val_00019070.bin 224 224 +31293 ./prep_dataset/ILSVRC2012_val_00018978.bin 224 224 +31294 ./prep_dataset/ILSVRC2012_val_00022649.bin 224 224 +31295 ./prep_dataset/ILSVRC2012_val_00028132.bin 224 224 +31296 ./prep_dataset/ILSVRC2012_val_00026573.bin 224 224 +31297 ./prep_dataset/ILSVRC2012_val_00044057.bin 224 224 +31298 ./prep_dataset/ILSVRC2012_val_00047319.bin 224 224 +31299 ./prep_dataset/ILSVRC2012_val_00046032.bin 224 224 +31300 ./prep_dataset/ILSVRC2012_val_00014702.bin 224 224 +31301 ./prep_dataset/ILSVRC2012_val_00028556.bin 224 224 +31302 ./prep_dataset/ILSVRC2012_val_00023397.bin 224 224 +31303 ./prep_dataset/ILSVRC2012_val_00004016.bin 224 224 +31304 ./prep_dataset/ILSVRC2012_val_00048793.bin 224 224 +31305 ./prep_dataset/ILSVRC2012_val_00010459.bin 224 224 +31306 ./prep_dataset/ILSVRC2012_val_00017836.bin 224 224 +31307 ./prep_dataset/ILSVRC2012_val_00012838.bin 224 224 +31308 ./prep_dataset/ILSVRC2012_val_00016187.bin 224 224 +31309 ./prep_dataset/ILSVRC2012_val_00026780.bin 224 224 +31310 ./prep_dataset/ILSVRC2012_val_00025994.bin 224 224 +31311 ./prep_dataset/ILSVRC2012_val_00035664.bin 224 224 +31312 ./prep_dataset/ILSVRC2012_val_00012354.bin 224 224 +31313 ./prep_dataset/ILSVRC2012_val_00011223.bin 224 224 +31314 ./prep_dataset/ILSVRC2012_val_00032157.bin 224 224 +31315 ./prep_dataset/ILSVRC2012_val_00015490.bin 224 224 +31316 ./prep_dataset/ILSVRC2012_val_00002068.bin 224 224 +31317 ./prep_dataset/ILSVRC2012_val_00037094.bin 224 224 +31318 ./prep_dataset/ILSVRC2012_val_00008399.bin 224 224 +31319 ./prep_dataset/ILSVRC2012_val_00038846.bin 224 224 +31320 ./prep_dataset/ILSVRC2012_val_00028125.bin 224 224 +31321 ./prep_dataset/ILSVRC2012_val_00009175.bin 224 224 +31322 ./prep_dataset/ILSVRC2012_val_00039264.bin 224 224 +31323 ./prep_dataset/ILSVRC2012_val_00046397.bin 224 224 +31324 ./prep_dataset/ILSVRC2012_val_00004401.bin 224 224 +31325 ./prep_dataset/ILSVRC2012_val_00032526.bin 224 224 +31326 ./prep_dataset/ILSVRC2012_val_00030768.bin 224 224 +31327 ./prep_dataset/ILSVRC2012_val_00000669.bin 224 224 +31328 ./prep_dataset/ILSVRC2012_val_00010105.bin 224 224 +31329 ./prep_dataset/ILSVRC2012_val_00002607.bin 224 224 +31330 ./prep_dataset/ILSVRC2012_val_00024384.bin 224 224 +31331 ./prep_dataset/ILSVRC2012_val_00046137.bin 224 224 +31332 ./prep_dataset/ILSVRC2012_val_00033647.bin 224 224 +31333 ./prep_dataset/ILSVRC2012_val_00013024.bin 224 224 +31334 ./prep_dataset/ILSVRC2012_val_00043393.bin 224 224 +31335 ./prep_dataset/ILSVRC2012_val_00002255.bin 224 224 +31336 ./prep_dataset/ILSVRC2012_val_00049910.bin 224 224 +31337 ./prep_dataset/ILSVRC2012_val_00029110.bin 224 224 +31338 ./prep_dataset/ILSVRC2012_val_00011548.bin 224 224 +31339 ./prep_dataset/ILSVRC2012_val_00026650.bin 224 224 +31340 ./prep_dataset/ILSVRC2012_val_00025530.bin 224 224 +31341 ./prep_dataset/ILSVRC2012_val_00034432.bin 224 224 +31342 ./prep_dataset/ILSVRC2012_val_00004970.bin 224 224 +31343 ./prep_dataset/ILSVRC2012_val_00048776.bin 224 224 +31344 ./prep_dataset/ILSVRC2012_val_00033939.bin 224 224 +31345 ./prep_dataset/ILSVRC2012_val_00034302.bin 224 224 +31346 ./prep_dataset/ILSVRC2012_val_00005939.bin 224 224 +31347 ./prep_dataset/ILSVRC2012_val_00011072.bin 224 224 +31348 ./prep_dataset/ILSVRC2012_val_00007812.bin 224 224 +31349 ./prep_dataset/ILSVRC2012_val_00023358.bin 224 224 +31350 ./prep_dataset/ILSVRC2012_val_00017828.bin 224 224 +31351 ./prep_dataset/ILSVRC2012_val_00018876.bin 224 224 +31352 ./prep_dataset/ILSVRC2012_val_00037274.bin 224 224 +31353 ./prep_dataset/ILSVRC2012_val_00018197.bin 224 224 +31354 ./prep_dataset/ILSVRC2012_val_00015648.bin 224 224 +31355 ./prep_dataset/ILSVRC2012_val_00005879.bin 224 224 +31356 ./prep_dataset/ILSVRC2012_val_00033169.bin 224 224 +31357 ./prep_dataset/ILSVRC2012_val_00003358.bin 224 224 +31358 ./prep_dataset/ILSVRC2012_val_00036655.bin 224 224 +31359 ./prep_dataset/ILSVRC2012_val_00011404.bin 224 224 +31360 ./prep_dataset/ILSVRC2012_val_00046773.bin 224 224 +31361 ./prep_dataset/ILSVRC2012_val_00003062.bin 224 224 +31362 ./prep_dataset/ILSVRC2012_val_00043401.bin 224 224 +31363 ./prep_dataset/ILSVRC2012_val_00016541.bin 224 224 +31364 ./prep_dataset/ILSVRC2012_val_00003175.bin 224 224 +31365 ./prep_dataset/ILSVRC2012_val_00037878.bin 224 224 +31366 ./prep_dataset/ILSVRC2012_val_00037571.bin 224 224 +31367 ./prep_dataset/ILSVRC2012_val_00019119.bin 224 224 +31368 ./prep_dataset/ILSVRC2012_val_00046054.bin 224 224 +31369 ./prep_dataset/ILSVRC2012_val_00020828.bin 224 224 +31370 ./prep_dataset/ILSVRC2012_val_00005753.bin 224 224 +31371 ./prep_dataset/ILSVRC2012_val_00043762.bin 224 224 +31372 ./prep_dataset/ILSVRC2012_val_00045739.bin 224 224 +31373 ./prep_dataset/ILSVRC2012_val_00008960.bin 224 224 +31374 ./prep_dataset/ILSVRC2012_val_00002004.bin 224 224 +31375 ./prep_dataset/ILSVRC2012_val_00048247.bin 224 224 +31376 ./prep_dataset/ILSVRC2012_val_00048152.bin 224 224 +31377 ./prep_dataset/ILSVRC2012_val_00041761.bin 224 224 +31378 ./prep_dataset/ILSVRC2012_val_00025818.bin 224 224 +31379 ./prep_dataset/ILSVRC2012_val_00002893.bin 224 224 +31380 ./prep_dataset/ILSVRC2012_val_00004289.bin 224 224 +31381 ./prep_dataset/ILSVRC2012_val_00019804.bin 224 224 +31382 ./prep_dataset/ILSVRC2012_val_00024399.bin 224 224 +31383 ./prep_dataset/ILSVRC2012_val_00018161.bin 224 224 +31384 ./prep_dataset/ILSVRC2012_val_00002791.bin 224 224 +31385 ./prep_dataset/ILSVRC2012_val_00004663.bin 224 224 +31386 ./prep_dataset/ILSVRC2012_val_00042782.bin 224 224 +31387 ./prep_dataset/ILSVRC2012_val_00028586.bin 224 224 +31388 ./prep_dataset/ILSVRC2012_val_00046539.bin 224 224 +31389 ./prep_dataset/ILSVRC2012_val_00034571.bin 224 224 +31390 ./prep_dataset/ILSVRC2012_val_00028017.bin 224 224 +31391 ./prep_dataset/ILSVRC2012_val_00028674.bin 224 224 +31392 ./prep_dataset/ILSVRC2012_val_00042850.bin 224 224 +31393 ./prep_dataset/ILSVRC2012_val_00023978.bin 224 224 +31394 ./prep_dataset/ILSVRC2012_val_00006967.bin 224 224 +31395 ./prep_dataset/ILSVRC2012_val_00007512.bin 224 224 +31396 ./prep_dataset/ILSVRC2012_val_00048097.bin 224 224 +31397 ./prep_dataset/ILSVRC2012_val_00023841.bin 224 224 +31398 ./prep_dataset/ILSVRC2012_val_00018561.bin 224 224 +31399 ./prep_dataset/ILSVRC2012_val_00008897.bin 224 224 +31400 ./prep_dataset/ILSVRC2012_val_00001857.bin 224 224 +31401 ./prep_dataset/ILSVRC2012_val_00014195.bin 224 224 +31402 ./prep_dataset/ILSVRC2012_val_00011494.bin 224 224 +31403 ./prep_dataset/ILSVRC2012_val_00015675.bin 224 224 +31404 ./prep_dataset/ILSVRC2012_val_00015260.bin 224 224 +31405 ./prep_dataset/ILSVRC2012_val_00035869.bin 224 224 +31406 ./prep_dataset/ILSVRC2012_val_00014161.bin 224 224 +31407 ./prep_dataset/ILSVRC2012_val_00021697.bin 224 224 +31408 ./prep_dataset/ILSVRC2012_val_00039494.bin 224 224 +31409 ./prep_dataset/ILSVRC2012_val_00028931.bin 224 224 +31410 ./prep_dataset/ILSVRC2012_val_00021630.bin 224 224 +31411 ./prep_dataset/ILSVRC2012_val_00031750.bin 224 224 +31412 ./prep_dataset/ILSVRC2012_val_00003392.bin 224 224 +31413 ./prep_dataset/ILSVRC2012_val_00042263.bin 224 224 +31414 ./prep_dataset/ILSVRC2012_val_00039697.bin 224 224 +31415 ./prep_dataset/ILSVRC2012_val_00005403.bin 224 224 +31416 ./prep_dataset/ILSVRC2012_val_00037220.bin 224 224 +31417 ./prep_dataset/ILSVRC2012_val_00007985.bin 224 224 +31418 ./prep_dataset/ILSVRC2012_val_00032675.bin 224 224 +31419 ./prep_dataset/ILSVRC2012_val_00044785.bin 224 224 +31420 ./prep_dataset/ILSVRC2012_val_00011387.bin 224 224 +31421 ./prep_dataset/ILSVRC2012_val_00046095.bin 224 224 +31422 ./prep_dataset/ILSVRC2012_val_00001144.bin 224 224 +31423 ./prep_dataset/ILSVRC2012_val_00046634.bin 224 224 +31424 ./prep_dataset/ILSVRC2012_val_00010172.bin 224 224 +31425 ./prep_dataset/ILSVRC2012_val_00036304.bin 224 224 +31426 ./prep_dataset/ILSVRC2012_val_00019848.bin 224 224 +31427 ./prep_dataset/ILSVRC2012_val_00047235.bin 224 224 +31428 ./prep_dataset/ILSVRC2012_val_00024354.bin 224 224 +31429 ./prep_dataset/ILSVRC2012_val_00003059.bin 224 224 +31430 ./prep_dataset/ILSVRC2012_val_00039198.bin 224 224 +31431 ./prep_dataset/ILSVRC2012_val_00029123.bin 224 224 +31432 ./prep_dataset/ILSVRC2012_val_00044095.bin 224 224 +31433 ./prep_dataset/ILSVRC2012_val_00049961.bin 224 224 +31434 ./prep_dataset/ILSVRC2012_val_00038651.bin 224 224 +31435 ./prep_dataset/ILSVRC2012_val_00036105.bin 224 224 +31436 ./prep_dataset/ILSVRC2012_val_00032143.bin 224 224 +31437 ./prep_dataset/ILSVRC2012_val_00021111.bin 224 224 +31438 ./prep_dataset/ILSVRC2012_val_00034921.bin 224 224 +31439 ./prep_dataset/ILSVRC2012_val_00019806.bin 224 224 +31440 ./prep_dataset/ILSVRC2012_val_00008016.bin 224 224 +31441 ./prep_dataset/ILSVRC2012_val_00045525.bin 224 224 +31442 ./prep_dataset/ILSVRC2012_val_00026589.bin 224 224 +31443 ./prep_dataset/ILSVRC2012_val_00012170.bin 224 224 +31444 ./prep_dataset/ILSVRC2012_val_00029107.bin 224 224 +31445 ./prep_dataset/ILSVRC2012_val_00039521.bin 224 224 +31446 ./prep_dataset/ILSVRC2012_val_00041440.bin 224 224 +31447 ./prep_dataset/ILSVRC2012_val_00025342.bin 224 224 +31448 ./prep_dataset/ILSVRC2012_val_00026777.bin 224 224 +31449 ./prep_dataset/ILSVRC2012_val_00034054.bin 224 224 +31450 ./prep_dataset/ILSVRC2012_val_00012320.bin 224 224 +31451 ./prep_dataset/ILSVRC2012_val_00026180.bin 224 224 +31452 ./prep_dataset/ILSVRC2012_val_00040007.bin 224 224 +31453 ./prep_dataset/ILSVRC2012_val_00038571.bin 224 224 +31454 ./prep_dataset/ILSVRC2012_val_00045038.bin 224 224 +31455 ./prep_dataset/ILSVRC2012_val_00008738.bin 224 224 +31456 ./prep_dataset/ILSVRC2012_val_00022311.bin 224 224 +31457 ./prep_dataset/ILSVRC2012_val_00019021.bin 224 224 +31458 ./prep_dataset/ILSVRC2012_val_00043636.bin 224 224 +31459 ./prep_dataset/ILSVRC2012_val_00041554.bin 224 224 +31460 ./prep_dataset/ILSVRC2012_val_00015060.bin 224 224 +31461 ./prep_dataset/ILSVRC2012_val_00049930.bin 224 224 +31462 ./prep_dataset/ILSVRC2012_val_00044973.bin 224 224 +31463 ./prep_dataset/ILSVRC2012_val_00037309.bin 224 224 +31464 ./prep_dataset/ILSVRC2012_val_00020263.bin 224 224 +31465 ./prep_dataset/ILSVRC2012_val_00027456.bin 224 224 +31466 ./prep_dataset/ILSVRC2012_val_00006068.bin 224 224 +31467 ./prep_dataset/ILSVRC2012_val_00030650.bin 224 224 +31468 ./prep_dataset/ILSVRC2012_val_00049848.bin 224 224 +31469 ./prep_dataset/ILSVRC2012_val_00047617.bin 224 224 +31470 ./prep_dataset/ILSVRC2012_val_00025419.bin 224 224 +31471 ./prep_dataset/ILSVRC2012_val_00002232.bin 224 224 +31472 ./prep_dataset/ILSVRC2012_val_00033144.bin 224 224 +31473 ./prep_dataset/ILSVRC2012_val_00016902.bin 224 224 +31474 ./prep_dataset/ILSVRC2012_val_00025677.bin 224 224 +31475 ./prep_dataset/ILSVRC2012_val_00015420.bin 224 224 +31476 ./prep_dataset/ILSVRC2012_val_00000336.bin 224 224 +31477 ./prep_dataset/ILSVRC2012_val_00012385.bin 224 224 +31478 ./prep_dataset/ILSVRC2012_val_00040328.bin 224 224 +31479 ./prep_dataset/ILSVRC2012_val_00023027.bin 224 224 +31480 ./prep_dataset/ILSVRC2012_val_00009265.bin 224 224 +31481 ./prep_dataset/ILSVRC2012_val_00038076.bin 224 224 +31482 ./prep_dataset/ILSVRC2012_val_00021602.bin 224 224 +31483 ./prep_dataset/ILSVRC2012_val_00027811.bin 224 224 +31484 ./prep_dataset/ILSVRC2012_val_00011708.bin 224 224 +31485 ./prep_dataset/ILSVRC2012_val_00024856.bin 224 224 +31486 ./prep_dataset/ILSVRC2012_val_00043921.bin 224 224 +31487 ./prep_dataset/ILSVRC2012_val_00001038.bin 224 224 +31488 ./prep_dataset/ILSVRC2012_val_00019508.bin 224 224 +31489 ./prep_dataset/ILSVRC2012_val_00023122.bin 224 224 +31490 ./prep_dataset/ILSVRC2012_val_00007817.bin 224 224 +31491 ./prep_dataset/ILSVRC2012_val_00034284.bin 224 224 +31492 ./prep_dataset/ILSVRC2012_val_00038064.bin 224 224 +31493 ./prep_dataset/ILSVRC2012_val_00004773.bin 224 224 +31494 ./prep_dataset/ILSVRC2012_val_00016875.bin 224 224 +31495 ./prep_dataset/ILSVRC2012_val_00037332.bin 224 224 +31496 ./prep_dataset/ILSVRC2012_val_00014581.bin 224 224 +31497 ./prep_dataset/ILSVRC2012_val_00011957.bin 224 224 +31498 ./prep_dataset/ILSVRC2012_val_00037547.bin 224 224 +31499 ./prep_dataset/ILSVRC2012_val_00009292.bin 224 224 +31500 ./prep_dataset/ILSVRC2012_val_00003746.bin 224 224 +31501 ./prep_dataset/ILSVRC2012_val_00031940.bin 224 224 +31502 ./prep_dataset/ILSVRC2012_val_00005831.bin 224 224 +31503 ./prep_dataset/ILSVRC2012_val_00012561.bin 224 224 +31504 ./prep_dataset/ILSVRC2012_val_00016921.bin 224 224 +31505 ./prep_dataset/ILSVRC2012_val_00014529.bin 224 224 +31506 ./prep_dataset/ILSVRC2012_val_00027484.bin 224 224 +31507 ./prep_dataset/ILSVRC2012_val_00018606.bin 224 224 +31508 ./prep_dataset/ILSVRC2012_val_00003123.bin 224 224 +31509 ./prep_dataset/ILSVRC2012_val_00041175.bin 224 224 +31510 ./prep_dataset/ILSVRC2012_val_00018565.bin 224 224 +31511 ./prep_dataset/ILSVRC2012_val_00014692.bin 224 224 +31512 ./prep_dataset/ILSVRC2012_val_00023691.bin 224 224 +31513 ./prep_dataset/ILSVRC2012_val_00034239.bin 224 224 +31514 ./prep_dataset/ILSVRC2012_val_00039006.bin 224 224 +31515 ./prep_dataset/ILSVRC2012_val_00047566.bin 224 224 +31516 ./prep_dataset/ILSVRC2012_val_00042925.bin 224 224 +31517 ./prep_dataset/ILSVRC2012_val_00010887.bin 224 224 +31518 ./prep_dataset/ILSVRC2012_val_00016815.bin 224 224 +31519 ./prep_dataset/ILSVRC2012_val_00030265.bin 224 224 +31520 ./prep_dataset/ILSVRC2012_val_00040491.bin 224 224 +31521 ./prep_dataset/ILSVRC2012_val_00012952.bin 224 224 +31522 ./prep_dataset/ILSVRC2012_val_00036671.bin 224 224 +31523 ./prep_dataset/ILSVRC2012_val_00007669.bin 224 224 +31524 ./prep_dataset/ILSVRC2012_val_00028408.bin 224 224 +31525 ./prep_dataset/ILSVRC2012_val_00000219.bin 224 224 +31526 ./prep_dataset/ILSVRC2012_val_00023313.bin 224 224 +31527 ./prep_dataset/ILSVRC2012_val_00038389.bin 224 224 +31528 ./prep_dataset/ILSVRC2012_val_00046876.bin 224 224 +31529 ./prep_dataset/ILSVRC2012_val_00035972.bin 224 224 +31530 ./prep_dataset/ILSVRC2012_val_00014618.bin 224 224 +31531 ./prep_dataset/ILSVRC2012_val_00021683.bin 224 224 +31532 ./prep_dataset/ILSVRC2012_val_00033615.bin 224 224 +31533 ./prep_dataset/ILSVRC2012_val_00036271.bin 224 224 +31534 ./prep_dataset/ILSVRC2012_val_00006896.bin 224 224 +31535 ./prep_dataset/ILSVRC2012_val_00014939.bin 224 224 +31536 ./prep_dataset/ILSVRC2012_val_00014282.bin 224 224 +31537 ./prep_dataset/ILSVRC2012_val_00038706.bin 224 224 +31538 ./prep_dataset/ILSVRC2012_val_00039210.bin 224 224 +31539 ./prep_dataset/ILSVRC2012_val_00048823.bin 224 224 +31540 ./prep_dataset/ILSVRC2012_val_00018326.bin 224 224 +31541 ./prep_dataset/ILSVRC2012_val_00016490.bin 224 224 +31542 ./prep_dataset/ILSVRC2012_val_00012126.bin 224 224 +31543 ./prep_dataset/ILSVRC2012_val_00006906.bin 224 224 +31544 ./prep_dataset/ILSVRC2012_val_00040008.bin 224 224 +31545 ./prep_dataset/ILSVRC2012_val_00018037.bin 224 224 +31546 ./prep_dataset/ILSVRC2012_val_00034306.bin 224 224 +31547 ./prep_dataset/ILSVRC2012_val_00009818.bin 224 224 +31548 ./prep_dataset/ILSVRC2012_val_00033248.bin 224 224 +31549 ./prep_dataset/ILSVRC2012_val_00048038.bin 224 224 +31550 ./prep_dataset/ILSVRC2012_val_00047799.bin 224 224 +31551 ./prep_dataset/ILSVRC2012_val_00029629.bin 224 224 +31552 ./prep_dataset/ILSVRC2012_val_00014635.bin 224 224 +31553 ./prep_dataset/ILSVRC2012_val_00009571.bin 224 224 +31554 ./prep_dataset/ILSVRC2012_val_00039684.bin 224 224 +31555 ./prep_dataset/ILSVRC2012_val_00037636.bin 224 224 +31556 ./prep_dataset/ILSVRC2012_val_00022669.bin 224 224 +31557 ./prep_dataset/ILSVRC2012_val_00009787.bin 224 224 +31558 ./prep_dataset/ILSVRC2012_val_00018118.bin 224 224 +31559 ./prep_dataset/ILSVRC2012_val_00040452.bin 224 224 +31560 ./prep_dataset/ILSVRC2012_val_00008866.bin 224 224 +31561 ./prep_dataset/ILSVRC2012_val_00036880.bin 224 224 +31562 ./prep_dataset/ILSVRC2012_val_00038080.bin 224 224 +31563 ./prep_dataset/ILSVRC2012_val_00034912.bin 224 224 +31564 ./prep_dataset/ILSVRC2012_val_00015107.bin 224 224 +31565 ./prep_dataset/ILSVRC2012_val_00020112.bin 224 224 +31566 ./prep_dataset/ILSVRC2012_val_00013820.bin 224 224 +31567 ./prep_dataset/ILSVRC2012_val_00034559.bin 224 224 +31568 ./prep_dataset/ILSVRC2012_val_00023717.bin 224 224 +31569 ./prep_dataset/ILSVRC2012_val_00025990.bin 224 224 +31570 ./prep_dataset/ILSVRC2012_val_00015250.bin 224 224 +31571 ./prep_dataset/ILSVRC2012_val_00003376.bin 224 224 +31572 ./prep_dataset/ILSVRC2012_val_00020740.bin 224 224 +31573 ./prep_dataset/ILSVRC2012_val_00004298.bin 224 224 +31574 ./prep_dataset/ILSVRC2012_val_00015872.bin 224 224 +31575 ./prep_dataset/ILSVRC2012_val_00038180.bin 224 224 +31576 ./prep_dataset/ILSVRC2012_val_00001439.bin 224 224 +31577 ./prep_dataset/ILSVRC2012_val_00026971.bin 224 224 +31578 ./prep_dataset/ILSVRC2012_val_00004330.bin 224 224 +31579 ./prep_dataset/ILSVRC2012_val_00039850.bin 224 224 +31580 ./prep_dataset/ILSVRC2012_val_00044196.bin 224 224 +31581 ./prep_dataset/ILSVRC2012_val_00026754.bin 224 224 +31582 ./prep_dataset/ILSVRC2012_val_00038463.bin 224 224 +31583 ./prep_dataset/ILSVRC2012_val_00048675.bin 224 224 +31584 ./prep_dataset/ILSVRC2012_val_00025559.bin 224 224 +31585 ./prep_dataset/ILSVRC2012_val_00008930.bin 224 224 +31586 ./prep_dataset/ILSVRC2012_val_00009841.bin 224 224 +31587 ./prep_dataset/ILSVRC2012_val_00002827.bin 224 224 +31588 ./prep_dataset/ILSVRC2012_val_00028904.bin 224 224 +31589 ./prep_dataset/ILSVRC2012_val_00004152.bin 224 224 +31590 ./prep_dataset/ILSVRC2012_val_00034423.bin 224 224 +31591 ./prep_dataset/ILSVRC2012_val_00046758.bin 224 224 +31592 ./prep_dataset/ILSVRC2012_val_00036893.bin 224 224 +31593 ./prep_dataset/ILSVRC2012_val_00016780.bin 224 224 +31594 ./prep_dataset/ILSVRC2012_val_00038958.bin 224 224 +31595 ./prep_dataset/ILSVRC2012_val_00034505.bin 224 224 +31596 ./prep_dataset/ILSVRC2012_val_00031185.bin 224 224 +31597 ./prep_dataset/ILSVRC2012_val_00020638.bin 224 224 +31598 ./prep_dataset/ILSVRC2012_val_00029455.bin 224 224 +31599 ./prep_dataset/ILSVRC2012_val_00025300.bin 224 224 +31600 ./prep_dataset/ILSVRC2012_val_00040231.bin 224 224 +31601 ./prep_dataset/ILSVRC2012_val_00026047.bin 224 224 +31602 ./prep_dataset/ILSVRC2012_val_00046340.bin 224 224 +31603 ./prep_dataset/ILSVRC2012_val_00023254.bin 224 224 +31604 ./prep_dataset/ILSVRC2012_val_00015704.bin 224 224 +31605 ./prep_dataset/ILSVRC2012_val_00050000.bin 224 224 +31606 ./prep_dataset/ILSVRC2012_val_00009710.bin 224 224 +31607 ./prep_dataset/ILSVRC2012_val_00037756.bin 224 224 +31608 ./prep_dataset/ILSVRC2012_val_00003072.bin 224 224 +31609 ./prep_dataset/ILSVRC2012_val_00025286.bin 224 224 +31610 ./prep_dataset/ILSVRC2012_val_00026700.bin 224 224 +31611 ./prep_dataset/ILSVRC2012_val_00028166.bin 224 224 +31612 ./prep_dataset/ILSVRC2012_val_00031517.bin 224 224 +31613 ./prep_dataset/ILSVRC2012_val_00039981.bin 224 224 +31614 ./prep_dataset/ILSVRC2012_val_00001803.bin 224 224 +31615 ./prep_dataset/ILSVRC2012_val_00034420.bin 224 224 +31616 ./prep_dataset/ILSVRC2012_val_00005358.bin 224 224 +31617 ./prep_dataset/ILSVRC2012_val_00034880.bin 224 224 +31618 ./prep_dataset/ILSVRC2012_val_00038157.bin 224 224 +31619 ./prep_dataset/ILSVRC2012_val_00022149.bin 224 224 +31620 ./prep_dataset/ILSVRC2012_val_00008444.bin 224 224 +31621 ./prep_dataset/ILSVRC2012_val_00044804.bin 224 224 +31622 ./prep_dataset/ILSVRC2012_val_00043387.bin 224 224 +31623 ./prep_dataset/ILSVRC2012_val_00011558.bin 224 224 +31624 ./prep_dataset/ILSVRC2012_val_00045499.bin 224 224 +31625 ./prep_dataset/ILSVRC2012_val_00047775.bin 224 224 +31626 ./prep_dataset/ILSVRC2012_val_00011732.bin 224 224 +31627 ./prep_dataset/ILSVRC2012_val_00033644.bin 224 224 +31628 ./prep_dataset/ILSVRC2012_val_00014135.bin 224 224 +31629 ./prep_dataset/ILSVRC2012_val_00030185.bin 224 224 +31630 ./prep_dataset/ILSVRC2012_val_00033858.bin 224 224 +31631 ./prep_dataset/ILSVRC2012_val_00043285.bin 224 224 +31632 ./prep_dataset/ILSVRC2012_val_00033308.bin 224 224 +31633 ./prep_dataset/ILSVRC2012_val_00028930.bin 224 224 +31634 ./prep_dataset/ILSVRC2012_val_00035478.bin 224 224 +31635 ./prep_dataset/ILSVRC2012_val_00025769.bin 224 224 +31636 ./prep_dataset/ILSVRC2012_val_00015717.bin 224 224 +31637 ./prep_dataset/ILSVRC2012_val_00014866.bin 224 224 +31638 ./prep_dataset/ILSVRC2012_val_00035417.bin 224 224 +31639 ./prep_dataset/ILSVRC2012_val_00021606.bin 224 224 +31640 ./prep_dataset/ILSVRC2012_val_00011145.bin 224 224 +31641 ./prep_dataset/ILSVRC2012_val_00031380.bin 224 224 +31642 ./prep_dataset/ILSVRC2012_val_00047171.bin 224 224 +31643 ./prep_dataset/ILSVRC2012_val_00008940.bin 224 224 +31644 ./prep_dataset/ILSVRC2012_val_00014265.bin 224 224 +31645 ./prep_dataset/ILSVRC2012_val_00033792.bin 224 224 +31646 ./prep_dataset/ILSVRC2012_val_00039922.bin 224 224 +31647 ./prep_dataset/ILSVRC2012_val_00033112.bin 224 224 +31648 ./prep_dataset/ILSVRC2012_val_00008437.bin 224 224 +31649 ./prep_dataset/ILSVRC2012_val_00023045.bin 224 224 +31650 ./prep_dataset/ILSVRC2012_val_00010376.bin 224 224 +31651 ./prep_dataset/ILSVRC2012_val_00040455.bin 224 224 +31652 ./prep_dataset/ILSVRC2012_val_00049209.bin 224 224 +31653 ./prep_dataset/ILSVRC2012_val_00048846.bin 224 224 +31654 ./prep_dataset/ILSVRC2012_val_00016466.bin 224 224 +31655 ./prep_dataset/ILSVRC2012_val_00020355.bin 224 224 +31656 ./prep_dataset/ILSVRC2012_val_00027866.bin 224 224 +31657 ./prep_dataset/ILSVRC2012_val_00022562.bin 224 224 +31658 ./prep_dataset/ILSVRC2012_val_00041983.bin 224 224 +31659 ./prep_dataset/ILSVRC2012_val_00042545.bin 224 224 +31660 ./prep_dataset/ILSVRC2012_val_00009480.bin 224 224 +31661 ./prep_dataset/ILSVRC2012_val_00047451.bin 224 224 +31662 ./prep_dataset/ILSVRC2012_val_00018980.bin 224 224 +31663 ./prep_dataset/ILSVRC2012_val_00000403.bin 224 224 +31664 ./prep_dataset/ILSVRC2012_val_00011443.bin 224 224 +31665 ./prep_dataset/ILSVRC2012_val_00027789.bin 224 224 +31666 ./prep_dataset/ILSVRC2012_val_00037430.bin 224 224 +31667 ./prep_dataset/ILSVRC2012_val_00020965.bin 224 224 +31668 ./prep_dataset/ILSVRC2012_val_00014656.bin 224 224 +31669 ./prep_dataset/ILSVRC2012_val_00031328.bin 224 224 +31670 ./prep_dataset/ILSVRC2012_val_00040756.bin 224 224 +31671 ./prep_dataset/ILSVRC2012_val_00033160.bin 224 224 +31672 ./prep_dataset/ILSVRC2012_val_00002021.bin 224 224 +31673 ./prep_dataset/ILSVRC2012_val_00037625.bin 224 224 +31674 ./prep_dataset/ILSVRC2012_val_00049788.bin 224 224 +31675 ./prep_dataset/ILSVRC2012_val_00039863.bin 224 224 +31676 ./prep_dataset/ILSVRC2012_val_00045088.bin 224 224 +31677 ./prep_dataset/ILSVRC2012_val_00019955.bin 224 224 +31678 ./prep_dataset/ILSVRC2012_val_00049026.bin 224 224 +31679 ./prep_dataset/ILSVRC2012_val_00043555.bin 224 224 +31680 ./prep_dataset/ILSVRC2012_val_00036729.bin 224 224 +31681 ./prep_dataset/ILSVRC2012_val_00049346.bin 224 224 +31682 ./prep_dataset/ILSVRC2012_val_00036457.bin 224 224 +31683 ./prep_dataset/ILSVRC2012_val_00035612.bin 224 224 +31684 ./prep_dataset/ILSVRC2012_val_00018969.bin 224 224 +31685 ./prep_dataset/ILSVRC2012_val_00046638.bin 224 224 +31686 ./prep_dataset/ILSVRC2012_val_00013877.bin 224 224 +31687 ./prep_dataset/ILSVRC2012_val_00039582.bin 224 224 +31688 ./prep_dataset/ILSVRC2012_val_00040636.bin 224 224 +31689 ./prep_dataset/ILSVRC2012_val_00028772.bin 224 224 +31690 ./prep_dataset/ILSVRC2012_val_00003016.bin 224 224 +31691 ./prep_dataset/ILSVRC2012_val_00026542.bin 224 224 +31692 ./prep_dataset/ILSVRC2012_val_00023459.bin 224 224 +31693 ./prep_dataset/ILSVRC2012_val_00037317.bin 224 224 +31694 ./prep_dataset/ILSVRC2012_val_00004189.bin 224 224 +31695 ./prep_dataset/ILSVRC2012_val_00010482.bin 224 224 +31696 ./prep_dataset/ILSVRC2012_val_00007159.bin 224 224 +31697 ./prep_dataset/ILSVRC2012_val_00006370.bin 224 224 +31698 ./prep_dataset/ILSVRC2012_val_00010096.bin 224 224 +31699 ./prep_dataset/ILSVRC2012_val_00005269.bin 224 224 +31700 ./prep_dataset/ILSVRC2012_val_00030504.bin 224 224 +31701 ./prep_dataset/ILSVRC2012_val_00019359.bin 224 224 +31702 ./prep_dataset/ILSVRC2012_val_00017243.bin 224 224 +31703 ./prep_dataset/ILSVRC2012_val_00015762.bin 224 224 +31704 ./prep_dataset/ILSVRC2012_val_00008730.bin 224 224 +31705 ./prep_dataset/ILSVRC2012_val_00021150.bin 224 224 +31706 ./prep_dataset/ILSVRC2012_val_00038517.bin 224 224 +31707 ./prep_dataset/ILSVRC2012_val_00033964.bin 224 224 +31708 ./prep_dataset/ILSVRC2012_val_00020124.bin 224 224 +31709 ./prep_dataset/ILSVRC2012_val_00048546.bin 224 224 +31710 ./prep_dataset/ILSVRC2012_val_00021314.bin 224 224 +31711 ./prep_dataset/ILSVRC2012_val_00032100.bin 224 224 +31712 ./prep_dataset/ILSVRC2012_val_00005784.bin 224 224 +31713 ./prep_dataset/ILSVRC2012_val_00048126.bin 224 224 +31714 ./prep_dataset/ILSVRC2012_val_00036573.bin 224 224 +31715 ./prep_dataset/ILSVRC2012_val_00027372.bin 224 224 +31716 ./prep_dataset/ILSVRC2012_val_00010996.bin 224 224 +31717 ./prep_dataset/ILSVRC2012_val_00005356.bin 224 224 +31718 ./prep_dataset/ILSVRC2012_val_00040352.bin 224 224 +31719 ./prep_dataset/ILSVRC2012_val_00046426.bin 224 224 +31720 ./prep_dataset/ILSVRC2012_val_00028804.bin 224 224 +31721 ./prep_dataset/ILSVRC2012_val_00037174.bin 224 224 +31722 ./prep_dataset/ILSVRC2012_val_00015355.bin 224 224 +31723 ./prep_dataset/ILSVRC2012_val_00023380.bin 224 224 +31724 ./prep_dataset/ILSVRC2012_val_00042361.bin 224 224 +31725 ./prep_dataset/ILSVRC2012_val_00049746.bin 224 224 +31726 ./prep_dataset/ILSVRC2012_val_00029360.bin 224 224 +31727 ./prep_dataset/ILSVRC2012_val_00002252.bin 224 224 +31728 ./prep_dataset/ILSVRC2012_val_00003643.bin 224 224 +31729 ./prep_dataset/ILSVRC2012_val_00028698.bin 224 224 +31730 ./prep_dataset/ILSVRC2012_val_00046028.bin 224 224 +31731 ./prep_dataset/ILSVRC2012_val_00026555.bin 224 224 +31732 ./prep_dataset/ILSVRC2012_val_00033279.bin 224 224 +31733 ./prep_dataset/ILSVRC2012_val_00018090.bin 224 224 +31734 ./prep_dataset/ILSVRC2012_val_00035696.bin 224 224 +31735 ./prep_dataset/ILSVRC2012_val_00014968.bin 224 224 +31736 ./prep_dataset/ILSVRC2012_val_00031988.bin 224 224 +31737 ./prep_dataset/ILSVRC2012_val_00014846.bin 224 224 +31738 ./prep_dataset/ILSVRC2012_val_00041824.bin 224 224 +31739 ./prep_dataset/ILSVRC2012_val_00030596.bin 224 224 +31740 ./prep_dataset/ILSVRC2012_val_00012187.bin 224 224 +31741 ./prep_dataset/ILSVRC2012_val_00039039.bin 224 224 +31742 ./prep_dataset/ILSVRC2012_val_00005765.bin 224 224 +31743 ./prep_dataset/ILSVRC2012_val_00018662.bin 224 224 +31744 ./prep_dataset/ILSVRC2012_val_00023268.bin 224 224 +31745 ./prep_dataset/ILSVRC2012_val_00018265.bin 224 224 +31746 ./prep_dataset/ILSVRC2012_val_00028562.bin 224 224 +31747 ./prep_dataset/ILSVRC2012_val_00040105.bin 224 224 +31748 ./prep_dataset/ILSVRC2012_val_00037804.bin 224 224 +31749 ./prep_dataset/ILSVRC2012_val_00036516.bin 224 224 +31750 ./prep_dataset/ILSVRC2012_val_00035130.bin 224 224 +31751 ./prep_dataset/ILSVRC2012_val_00026626.bin 224 224 +31752 ./prep_dataset/ILSVRC2012_val_00011412.bin 224 224 +31753 ./prep_dataset/ILSVRC2012_val_00037325.bin 224 224 +31754 ./prep_dataset/ILSVRC2012_val_00046558.bin 224 224 +31755 ./prep_dataset/ILSVRC2012_val_00019786.bin 224 224 +31756 ./prep_dataset/ILSVRC2012_val_00030830.bin 224 224 +31757 ./prep_dataset/ILSVRC2012_val_00029781.bin 224 224 +31758 ./prep_dataset/ILSVRC2012_val_00016453.bin 224 224 +31759 ./prep_dataset/ILSVRC2012_val_00004183.bin 224 224 +31760 ./prep_dataset/ILSVRC2012_val_00032152.bin 224 224 +31761 ./prep_dataset/ILSVRC2012_val_00038948.bin 224 224 +31762 ./prep_dataset/ILSVRC2012_val_00031347.bin 224 224 +31763 ./prep_dataset/ILSVRC2012_val_00028111.bin 224 224 +31764 ./prep_dataset/ILSVRC2012_val_00045822.bin 224 224 +31765 ./prep_dataset/ILSVRC2012_val_00002230.bin 224 224 +31766 ./prep_dataset/ILSVRC2012_val_00030364.bin 224 224 +31767 ./prep_dataset/ILSVRC2012_val_00044582.bin 224 224 +31768 ./prep_dataset/ILSVRC2012_val_00014539.bin 224 224 +31769 ./prep_dataset/ILSVRC2012_val_00027733.bin 224 224 +31770 ./prep_dataset/ILSVRC2012_val_00028964.bin 224 224 +31771 ./prep_dataset/ILSVRC2012_val_00039229.bin 224 224 +31772 ./prep_dataset/ILSVRC2012_val_00035507.bin 224 224 +31773 ./prep_dataset/ILSVRC2012_val_00040714.bin 224 224 +31774 ./prep_dataset/ILSVRC2012_val_00015253.bin 224 224 +31775 ./prep_dataset/ILSVRC2012_val_00029920.bin 224 224 +31776 ./prep_dataset/ILSVRC2012_val_00032750.bin 224 224 +31777 ./prep_dataset/ILSVRC2012_val_00011337.bin 224 224 +31778 ./prep_dataset/ILSVRC2012_val_00021862.bin 224 224 +31779 ./prep_dataset/ILSVRC2012_val_00041961.bin 224 224 +31780 ./prep_dataset/ILSVRC2012_val_00040834.bin 224 224 +31781 ./prep_dataset/ILSVRC2012_val_00017618.bin 224 224 +31782 ./prep_dataset/ILSVRC2012_val_00037297.bin 224 224 +31783 ./prep_dataset/ILSVRC2012_val_00039472.bin 224 224 +31784 ./prep_dataset/ILSVRC2012_val_00008077.bin 224 224 +31785 ./prep_dataset/ILSVRC2012_val_00005033.bin 224 224 +31786 ./prep_dataset/ILSVRC2012_val_00020429.bin 224 224 +31787 ./prep_dataset/ILSVRC2012_val_00001782.bin 224 224 +31788 ./prep_dataset/ILSVRC2012_val_00024177.bin 224 224 +31789 ./prep_dataset/ILSVRC2012_val_00009903.bin 224 224 +31790 ./prep_dataset/ILSVRC2012_val_00004567.bin 224 224 +31791 ./prep_dataset/ILSVRC2012_val_00018341.bin 224 224 +31792 ./prep_dataset/ILSVRC2012_val_00026951.bin 224 224 +31793 ./prep_dataset/ILSVRC2012_val_00002565.bin 224 224 +31794 ./prep_dataset/ILSVRC2012_val_00018426.bin 224 224 +31795 ./prep_dataset/ILSVRC2012_val_00047744.bin 224 224 +31796 ./prep_dataset/ILSVRC2012_val_00045147.bin 224 224 +31797 ./prep_dataset/ILSVRC2012_val_00014423.bin 224 224 +31798 ./prep_dataset/ILSVRC2012_val_00036718.bin 224 224 +31799 ./prep_dataset/ILSVRC2012_val_00031650.bin 224 224 +31800 ./prep_dataset/ILSVRC2012_val_00038455.bin 224 224 +31801 ./prep_dataset/ILSVRC2012_val_00029378.bin 224 224 +31802 ./prep_dataset/ILSVRC2012_val_00037472.bin 224 224 +31803 ./prep_dataset/ILSVRC2012_val_00029350.bin 224 224 +31804 ./prep_dataset/ILSVRC2012_val_00009430.bin 224 224 +31805 ./prep_dataset/ILSVRC2012_val_00023507.bin 224 224 +31806 ./prep_dataset/ILSVRC2012_val_00001107.bin 224 224 +31807 ./prep_dataset/ILSVRC2012_val_00028389.bin 224 224 +31808 ./prep_dataset/ILSVRC2012_val_00021848.bin 224 224 +31809 ./prep_dataset/ILSVRC2012_val_00009963.bin 224 224 +31810 ./prep_dataset/ILSVRC2012_val_00030075.bin 224 224 +31811 ./prep_dataset/ILSVRC2012_val_00027559.bin 224 224 +31812 ./prep_dataset/ILSVRC2012_val_00022075.bin 224 224 +31813 ./prep_dataset/ILSVRC2012_val_00010638.bin 224 224 +31814 ./prep_dataset/ILSVRC2012_val_00014312.bin 224 224 +31815 ./prep_dataset/ILSVRC2012_val_00003455.bin 224 224 +31816 ./prep_dataset/ILSVRC2012_val_00023890.bin 224 224 +31817 ./prep_dataset/ILSVRC2012_val_00028830.bin 224 224 +31818 ./prep_dataset/ILSVRC2012_val_00003255.bin 224 224 +31819 ./prep_dataset/ILSVRC2012_val_00025561.bin 224 224 +31820 ./prep_dataset/ILSVRC2012_val_00001704.bin 224 224 +31821 ./prep_dataset/ILSVRC2012_val_00048854.bin 224 224 +31822 ./prep_dataset/ILSVRC2012_val_00027335.bin 224 224 +31823 ./prep_dataset/ILSVRC2012_val_00030956.bin 224 224 +31824 ./prep_dataset/ILSVRC2012_val_00003552.bin 224 224 +31825 ./prep_dataset/ILSVRC2012_val_00010399.bin 224 224 +31826 ./prep_dataset/ILSVRC2012_val_00041954.bin 224 224 +31827 ./prep_dataset/ILSVRC2012_val_00033192.bin 224 224 +31828 ./prep_dataset/ILSVRC2012_val_00002719.bin 224 224 +31829 ./prep_dataset/ILSVRC2012_val_00029572.bin 224 224 +31830 ./prep_dataset/ILSVRC2012_val_00027003.bin 224 224 +31831 ./prep_dataset/ILSVRC2012_val_00022312.bin 224 224 +31832 ./prep_dataset/ILSVRC2012_val_00003631.bin 224 224 +31833 ./prep_dataset/ILSVRC2012_val_00035640.bin 224 224 +31834 ./prep_dataset/ILSVRC2012_val_00035420.bin 224 224 +31835 ./prep_dataset/ILSVRC2012_val_00006932.bin 224 224 +31836 ./prep_dataset/ILSVRC2012_val_00032863.bin 224 224 +31837 ./prep_dataset/ILSVRC2012_val_00005841.bin 224 224 +31838 ./prep_dataset/ILSVRC2012_val_00030481.bin 224 224 +31839 ./prep_dataset/ILSVRC2012_val_00049160.bin 224 224 +31840 ./prep_dataset/ILSVRC2012_val_00004480.bin 224 224 +31841 ./prep_dataset/ILSVRC2012_val_00009326.bin 224 224 +31842 ./prep_dataset/ILSVRC2012_val_00025211.bin 224 224 +31843 ./prep_dataset/ILSVRC2012_val_00036148.bin 224 224 +31844 ./prep_dataset/ILSVRC2012_val_00039914.bin 224 224 +31845 ./prep_dataset/ILSVRC2012_val_00008669.bin 224 224 +31846 ./prep_dataset/ILSVRC2012_val_00043972.bin 224 224 +31847 ./prep_dataset/ILSVRC2012_val_00028465.bin 224 224 +31848 ./prep_dataset/ILSVRC2012_val_00017186.bin 224 224 +31849 ./prep_dataset/ILSVRC2012_val_00033852.bin 224 224 +31850 ./prep_dataset/ILSVRC2012_val_00008249.bin 224 224 +31851 ./prep_dataset/ILSVRC2012_val_00045762.bin 224 224 +31852 ./prep_dataset/ILSVRC2012_val_00043488.bin 224 224 +31853 ./prep_dataset/ILSVRC2012_val_00003874.bin 224 224 +31854 ./prep_dataset/ILSVRC2012_val_00021228.bin 224 224 +31855 ./prep_dataset/ILSVRC2012_val_00015030.bin 224 224 +31856 ./prep_dataset/ILSVRC2012_val_00021932.bin 224 224 +31857 ./prep_dataset/ILSVRC2012_val_00015724.bin 224 224 +31858 ./prep_dataset/ILSVRC2012_val_00021061.bin 224 224 +31859 ./prep_dataset/ILSVRC2012_val_00041042.bin 224 224 +31860 ./prep_dataset/ILSVRC2012_val_00043507.bin 224 224 +31861 ./prep_dataset/ILSVRC2012_val_00001325.bin 224 224 +31862 ./prep_dataset/ILSVRC2012_val_00045600.bin 224 224 +31863 ./prep_dataset/ILSVRC2012_val_00044194.bin 224 224 +31864 ./prep_dataset/ILSVRC2012_val_00030741.bin 224 224 +31865 ./prep_dataset/ILSVRC2012_val_00032361.bin 224 224 +31866 ./prep_dataset/ILSVRC2012_val_00045968.bin 224 224 +31867 ./prep_dataset/ILSVRC2012_val_00048852.bin 224 224 +31868 ./prep_dataset/ILSVRC2012_val_00041079.bin 224 224 +31869 ./prep_dataset/ILSVRC2012_val_00035148.bin 224 224 +31870 ./prep_dataset/ILSVRC2012_val_00037216.bin 224 224 +31871 ./prep_dataset/ILSVRC2012_val_00020998.bin 224 224 +31872 ./prep_dataset/ILSVRC2012_val_00014335.bin 224 224 +31873 ./prep_dataset/ILSVRC2012_val_00028614.bin 224 224 +31874 ./prep_dataset/ILSVRC2012_val_00007647.bin 224 224 +31875 ./prep_dataset/ILSVRC2012_val_00020061.bin 224 224 +31876 ./prep_dataset/ILSVRC2012_val_00043245.bin 224 224 +31877 ./prep_dataset/ILSVRC2012_val_00022110.bin 224 224 +31878 ./prep_dataset/ILSVRC2012_val_00005438.bin 224 224 +31879 ./prep_dataset/ILSVRC2012_val_00043572.bin 224 224 +31880 ./prep_dataset/ILSVRC2012_val_00000195.bin 224 224 +31881 ./prep_dataset/ILSVRC2012_val_00037398.bin 224 224 +31882 ./prep_dataset/ILSVRC2012_val_00013410.bin 224 224 +31883 ./prep_dataset/ILSVRC2012_val_00028264.bin 224 224 +31884 ./prep_dataset/ILSVRC2012_val_00030071.bin 224 224 +31885 ./prep_dataset/ILSVRC2012_val_00011570.bin 224 224 +31886 ./prep_dataset/ILSVRC2012_val_00008969.bin 224 224 +31887 ./prep_dataset/ILSVRC2012_val_00000729.bin 224 224 +31888 ./prep_dataset/ILSVRC2012_val_00033503.bin 224 224 +31889 ./prep_dataset/ILSVRC2012_val_00013139.bin 224 224 +31890 ./prep_dataset/ILSVRC2012_val_00044201.bin 224 224 +31891 ./prep_dataset/ILSVRC2012_val_00046727.bin 224 224 +31892 ./prep_dataset/ILSVRC2012_val_00022117.bin 224 224 +31893 ./prep_dataset/ILSVRC2012_val_00037998.bin 224 224 +31894 ./prep_dataset/ILSVRC2012_val_00038302.bin 224 224 +31895 ./prep_dataset/ILSVRC2012_val_00022915.bin 224 224 +31896 ./prep_dataset/ILSVRC2012_val_00001359.bin 224 224 +31897 ./prep_dataset/ILSVRC2012_val_00035053.bin 224 224 +31898 ./prep_dataset/ILSVRC2012_val_00021541.bin 224 224 +31899 ./prep_dataset/ILSVRC2012_val_00006854.bin 224 224 +31900 ./prep_dataset/ILSVRC2012_val_00034882.bin 224 224 +31901 ./prep_dataset/ILSVRC2012_val_00015262.bin 224 224 +31902 ./prep_dataset/ILSVRC2012_val_00014386.bin 224 224 +31903 ./prep_dataset/ILSVRC2012_val_00005110.bin 224 224 +31904 ./prep_dataset/ILSVRC2012_val_00013241.bin 224 224 +31905 ./prep_dataset/ILSVRC2012_val_00004634.bin 224 224 +31906 ./prep_dataset/ILSVRC2012_val_00035370.bin 224 224 +31907 ./prep_dataset/ILSVRC2012_val_00049854.bin 224 224 +31908 ./prep_dataset/ILSVRC2012_val_00037587.bin 224 224 +31909 ./prep_dataset/ILSVRC2012_val_00048613.bin 224 224 +31910 ./prep_dataset/ILSVRC2012_val_00038460.bin 224 224 +31911 ./prep_dataset/ILSVRC2012_val_00014122.bin 224 224 +31912 ./prep_dataset/ILSVRC2012_val_00035366.bin 224 224 +31913 ./prep_dataset/ILSVRC2012_val_00043642.bin 224 224 +31914 ./prep_dataset/ILSVRC2012_val_00012486.bin 224 224 +31915 ./prep_dataset/ILSVRC2012_val_00023709.bin 224 224 +31916 ./prep_dataset/ILSVRC2012_val_00049510.bin 224 224 +31917 ./prep_dataset/ILSVRC2012_val_00013328.bin 224 224 +31918 ./prep_dataset/ILSVRC2012_val_00032452.bin 224 224 +31919 ./prep_dataset/ILSVRC2012_val_00031129.bin 224 224 +31920 ./prep_dataset/ILSVRC2012_val_00048410.bin 224 224 +31921 ./prep_dataset/ILSVRC2012_val_00037350.bin 224 224 +31922 ./prep_dataset/ILSVRC2012_val_00039449.bin 224 224 +31923 ./prep_dataset/ILSVRC2012_val_00041612.bin 224 224 +31924 ./prep_dataset/ILSVRC2012_val_00041190.bin 224 224 +31925 ./prep_dataset/ILSVRC2012_val_00028653.bin 224 224 +31926 ./prep_dataset/ILSVRC2012_val_00029252.bin 224 224 +31927 ./prep_dataset/ILSVRC2012_val_00008657.bin 224 224 +31928 ./prep_dataset/ILSVRC2012_val_00032019.bin 224 224 +31929 ./prep_dataset/ILSVRC2012_val_00009266.bin 224 224 +31930 ./prep_dataset/ILSVRC2012_val_00001859.bin 224 224 +31931 ./prep_dataset/ILSVRC2012_val_00010964.bin 224 224 +31932 ./prep_dataset/ILSVRC2012_val_00026439.bin 224 224 +31933 ./prep_dataset/ILSVRC2012_val_00042539.bin 224 224 +31934 ./prep_dataset/ILSVRC2012_val_00015535.bin 224 224 +31935 ./prep_dataset/ILSVRC2012_val_00026503.bin 224 224 +31936 ./prep_dataset/ILSVRC2012_val_00038836.bin 224 224 +31937 ./prep_dataset/ILSVRC2012_val_00018454.bin 224 224 +31938 ./prep_dataset/ILSVRC2012_val_00033890.bin 224 224 +31939 ./prep_dataset/ILSVRC2012_val_00014124.bin 224 224 +31940 ./prep_dataset/ILSVRC2012_val_00030079.bin 224 224 +31941 ./prep_dataset/ILSVRC2012_val_00024263.bin 224 224 +31942 ./prep_dataset/ILSVRC2012_val_00018785.bin 224 224 +31943 ./prep_dataset/ILSVRC2012_val_00005163.bin 224 224 +31944 ./prep_dataset/ILSVRC2012_val_00013356.bin 224 224 +31945 ./prep_dataset/ILSVRC2012_val_00011215.bin 224 224 +31946 ./prep_dataset/ILSVRC2012_val_00028063.bin 224 224 +31947 ./prep_dataset/ILSVRC2012_val_00024150.bin 224 224 +31948 ./prep_dataset/ILSVRC2012_val_00036646.bin 224 224 +31949 ./prep_dataset/ILSVRC2012_val_00018210.bin 224 224 +31950 ./prep_dataset/ILSVRC2012_val_00016753.bin 224 224 +31951 ./prep_dataset/ILSVRC2012_val_00040749.bin 224 224 +31952 ./prep_dataset/ILSVRC2012_val_00038204.bin 224 224 +31953 ./prep_dataset/ILSVRC2012_val_00042220.bin 224 224 +31954 ./prep_dataset/ILSVRC2012_val_00008383.bin 224 224 +31955 ./prep_dataset/ILSVRC2012_val_00029264.bin 224 224 +31956 ./prep_dataset/ILSVRC2012_val_00002015.bin 224 224 +31957 ./prep_dataset/ILSVRC2012_val_00033574.bin 224 224 +31958 ./prep_dataset/ILSVRC2012_val_00028599.bin 224 224 +31959 ./prep_dataset/ILSVRC2012_val_00019426.bin 224 224 +31960 ./prep_dataset/ILSVRC2012_val_00045940.bin 224 224 +31961 ./prep_dataset/ILSVRC2012_val_00017920.bin 224 224 +31962 ./prep_dataset/ILSVRC2012_val_00049975.bin 224 224 +31963 ./prep_dataset/ILSVRC2012_val_00024814.bin 224 224 +31964 ./prep_dataset/ILSVRC2012_val_00049797.bin 224 224 +31965 ./prep_dataset/ILSVRC2012_val_00019757.bin 224 224 +31966 ./prep_dataset/ILSVRC2012_val_00009308.bin 224 224 +31967 ./prep_dataset/ILSVRC2012_val_00043225.bin 224 224 +31968 ./prep_dataset/ILSVRC2012_val_00002494.bin 224 224 +31969 ./prep_dataset/ILSVRC2012_val_00005915.bin 224 224 +31970 ./prep_dataset/ILSVRC2012_val_00017233.bin 224 224 +31971 ./prep_dataset/ILSVRC2012_val_00023109.bin 224 224 +31972 ./prep_dataset/ILSVRC2012_val_00043192.bin 224 224 +31973 ./prep_dataset/ILSVRC2012_val_00010027.bin 224 224 +31974 ./prep_dataset/ILSVRC2012_val_00034648.bin 224 224 +31975 ./prep_dataset/ILSVRC2012_val_00038453.bin 224 224 +31976 ./prep_dataset/ILSVRC2012_val_00048062.bin 224 224 +31977 ./prep_dataset/ILSVRC2012_val_00018988.bin 224 224 +31978 ./prep_dataset/ILSVRC2012_val_00004465.bin 224 224 +31979 ./prep_dataset/ILSVRC2012_val_00041303.bin 224 224 +31980 ./prep_dataset/ILSVRC2012_val_00023086.bin 224 224 +31981 ./prep_dataset/ILSVRC2012_val_00031527.bin 224 224 +31982 ./prep_dataset/ILSVRC2012_val_00040101.bin 224 224 +31983 ./prep_dataset/ILSVRC2012_val_00046233.bin 224 224 +31984 ./prep_dataset/ILSVRC2012_val_00019122.bin 224 224 +31985 ./prep_dataset/ILSVRC2012_val_00004293.bin 224 224 +31986 ./prep_dataset/ILSVRC2012_val_00045740.bin 224 224 +31987 ./prep_dataset/ILSVRC2012_val_00048408.bin 224 224 +31988 ./prep_dataset/ILSVRC2012_val_00014701.bin 224 224 +31989 ./prep_dataset/ILSVRC2012_val_00006034.bin 224 224 +31990 ./prep_dataset/ILSVRC2012_val_00049525.bin 224 224 +31991 ./prep_dataset/ILSVRC2012_val_00027083.bin 224 224 +31992 ./prep_dataset/ILSVRC2012_val_00016599.bin 224 224 +31993 ./prep_dataset/ILSVRC2012_val_00043038.bin 224 224 +31994 ./prep_dataset/ILSVRC2012_val_00044354.bin 224 224 +31995 ./prep_dataset/ILSVRC2012_val_00038596.bin 224 224 +31996 ./prep_dataset/ILSVRC2012_val_00019748.bin 224 224 +31997 ./prep_dataset/ILSVRC2012_val_00008931.bin 224 224 +31998 ./prep_dataset/ILSVRC2012_val_00007293.bin 224 224 +31999 ./prep_dataset/ILSVRC2012_val_00008714.bin 224 224 +32000 ./prep_dataset/ILSVRC2012_val_00047225.bin 224 224 +32001 ./prep_dataset/ILSVRC2012_val_00022816.bin 224 224 +32002 ./prep_dataset/ILSVRC2012_val_00020090.bin 224 224 +32003 ./prep_dataset/ILSVRC2012_val_00023433.bin 224 224 +32004 ./prep_dataset/ILSVRC2012_val_00039465.bin 224 224 +32005 ./prep_dataset/ILSVRC2012_val_00013129.bin 224 224 +32006 ./prep_dataset/ILSVRC2012_val_00021102.bin 224 224 +32007 ./prep_dataset/ILSVRC2012_val_00000755.bin 224 224 +32008 ./prep_dataset/ILSVRC2012_val_00031478.bin 224 224 +32009 ./prep_dataset/ILSVRC2012_val_00007443.bin 224 224 +32010 ./prep_dataset/ILSVRC2012_val_00012629.bin 224 224 +32011 ./prep_dataset/ILSVRC2012_val_00023998.bin 224 224 +32012 ./prep_dataset/ILSVRC2012_val_00011577.bin 224 224 +32013 ./prep_dataset/ILSVRC2012_val_00004754.bin 224 224 +32014 ./prep_dataset/ILSVRC2012_val_00041873.bin 224 224 +32015 ./prep_dataset/ILSVRC2012_val_00019486.bin 224 224 +32016 ./prep_dataset/ILSVRC2012_val_00037140.bin 224 224 +32017 ./prep_dataset/ILSVRC2012_val_00020187.bin 224 224 +32018 ./prep_dataset/ILSVRC2012_val_00026234.bin 224 224 +32019 ./prep_dataset/ILSVRC2012_val_00007586.bin 224 224 +32020 ./prep_dataset/ILSVRC2012_val_00036669.bin 224 224 +32021 ./prep_dataset/ILSVRC2012_val_00049458.bin 224 224 +32022 ./prep_dataset/ILSVRC2012_val_00029087.bin 224 224 +32023 ./prep_dataset/ILSVRC2012_val_00030186.bin 224 224 +32024 ./prep_dataset/ILSVRC2012_val_00007110.bin 224 224 +32025 ./prep_dataset/ILSVRC2012_val_00020777.bin 224 224 +32026 ./prep_dataset/ILSVRC2012_val_00037836.bin 224 224 +32027 ./prep_dataset/ILSVRC2012_val_00026371.bin 224 224 +32028 ./prep_dataset/ILSVRC2012_val_00013513.bin 224 224 +32029 ./prep_dataset/ILSVRC2012_val_00044795.bin 224 224 +32030 ./prep_dataset/ILSVRC2012_val_00017932.bin 224 224 +32031 ./prep_dataset/ILSVRC2012_val_00031540.bin 224 224 +32032 ./prep_dataset/ILSVRC2012_val_00029288.bin 224 224 +32033 ./prep_dataset/ILSVRC2012_val_00010211.bin 224 224 +32034 ./prep_dataset/ILSVRC2012_val_00046511.bin 224 224 +32035 ./prep_dataset/ILSVRC2012_val_00006146.bin 224 224 +32036 ./prep_dataset/ILSVRC2012_val_00033909.bin 224 224 +32037 ./prep_dataset/ILSVRC2012_val_00014200.bin 224 224 +32038 ./prep_dataset/ILSVRC2012_val_00046978.bin 224 224 +32039 ./prep_dataset/ILSVRC2012_val_00023907.bin 224 224 +32040 ./prep_dataset/ILSVRC2012_val_00020480.bin 224 224 +32041 ./prep_dataset/ILSVRC2012_val_00018231.bin 224 224 +32042 ./prep_dataset/ILSVRC2012_val_00018173.bin 224 224 +32043 ./prep_dataset/ILSVRC2012_val_00016487.bin 224 224 +32044 ./prep_dataset/ILSVRC2012_val_00031887.bin 224 224 +32045 ./prep_dataset/ILSVRC2012_val_00019570.bin 224 224 +32046 ./prep_dataset/ILSVRC2012_val_00022864.bin 224 224 +32047 ./prep_dataset/ILSVRC2012_val_00039890.bin 224 224 +32048 ./prep_dataset/ILSVRC2012_val_00037303.bin 224 224 +32049 ./prep_dataset/ILSVRC2012_val_00048956.bin 224 224 +32050 ./prep_dataset/ILSVRC2012_val_00028531.bin 224 224 +32051 ./prep_dataset/ILSVRC2012_val_00032582.bin 224 224 +32052 ./prep_dataset/ILSVRC2012_val_00042435.bin 224 224 +32053 ./prep_dataset/ILSVRC2012_val_00009956.bin 224 224 +32054 ./prep_dataset/ILSVRC2012_val_00004980.bin 224 224 +32055 ./prep_dataset/ILSVRC2012_val_00022677.bin 224 224 +32056 ./prep_dataset/ILSVRC2012_val_00038914.bin 224 224 +32057 ./prep_dataset/ILSVRC2012_val_00014669.bin 224 224 +32058 ./prep_dataset/ILSVRC2012_val_00043075.bin 224 224 +32059 ./prep_dataset/ILSVRC2012_val_00017953.bin 224 224 +32060 ./prep_dataset/ILSVRC2012_val_00037843.bin 224 224 +32061 ./prep_dataset/ILSVRC2012_val_00018298.bin 224 224 +32062 ./prep_dataset/ILSVRC2012_val_00007284.bin 224 224 +32063 ./prep_dataset/ILSVRC2012_val_00038507.bin 224 224 +32064 ./prep_dataset/ILSVRC2012_val_00003030.bin 224 224 +32065 ./prep_dataset/ILSVRC2012_val_00044221.bin 224 224 +32066 ./prep_dataset/ILSVRC2012_val_00038722.bin 224 224 +32067 ./prep_dataset/ILSVRC2012_val_00023824.bin 224 224 +32068 ./prep_dataset/ILSVRC2012_val_00038708.bin 224 224 +32069 ./prep_dataset/ILSVRC2012_val_00022089.bin 224 224 +32070 ./prep_dataset/ILSVRC2012_val_00000681.bin 224 224 +32071 ./prep_dataset/ILSVRC2012_val_00011246.bin 224 224 +32072 ./prep_dataset/ILSVRC2012_val_00042328.bin 224 224 +32073 ./prep_dataset/ILSVRC2012_val_00048475.bin 224 224 +32074 ./prep_dataset/ILSVRC2012_val_00017059.bin 224 224 +32075 ./prep_dataset/ILSVRC2012_val_00034765.bin 224 224 +32076 ./prep_dataset/ILSVRC2012_val_00001220.bin 224 224 +32077 ./prep_dataset/ILSVRC2012_val_00008549.bin 224 224 +32078 ./prep_dataset/ILSVRC2012_val_00042342.bin 224 224 +32079 ./prep_dataset/ILSVRC2012_val_00017842.bin 224 224 +32080 ./prep_dataset/ILSVRC2012_val_00042710.bin 224 224 +32081 ./prep_dataset/ILSVRC2012_val_00045242.bin 224 224 +32082 ./prep_dataset/ILSVRC2012_val_00015256.bin 224 224 +32083 ./prep_dataset/ILSVRC2012_val_00045367.bin 224 224 +32084 ./prep_dataset/ILSVRC2012_val_00025563.bin 224 224 +32085 ./prep_dataset/ILSVRC2012_val_00017845.bin 224 224 +32086 ./prep_dataset/ILSVRC2012_val_00006081.bin 224 224 +32087 ./prep_dataset/ILSVRC2012_val_00035906.bin 224 224 +32088 ./prep_dataset/ILSVRC2012_val_00019819.bin 224 224 +32089 ./prep_dataset/ILSVRC2012_val_00045096.bin 224 224 +32090 ./prep_dataset/ILSVRC2012_val_00041935.bin 224 224 +32091 ./prep_dataset/ILSVRC2012_val_00016670.bin 224 224 +32092 ./prep_dataset/ILSVRC2012_val_00031755.bin 224 224 +32093 ./prep_dataset/ILSVRC2012_val_00036149.bin 224 224 +32094 ./prep_dataset/ILSVRC2012_val_00012059.bin 224 224 +32095 ./prep_dataset/ILSVRC2012_val_00025826.bin 224 224 +32096 ./prep_dataset/ILSVRC2012_val_00005389.bin 224 224 +32097 ./prep_dataset/ILSVRC2012_val_00047630.bin 224 224 +32098 ./prep_dataset/ILSVRC2012_val_00035316.bin 224 224 +32099 ./prep_dataset/ILSVRC2012_val_00036747.bin 224 224 +32100 ./prep_dataset/ILSVRC2012_val_00035016.bin 224 224 +32101 ./prep_dataset/ILSVRC2012_val_00007364.bin 224 224 +32102 ./prep_dataset/ILSVRC2012_val_00019552.bin 224 224 +32103 ./prep_dataset/ILSVRC2012_val_00021191.bin 224 224 +32104 ./prep_dataset/ILSVRC2012_val_00040858.bin 224 224 +32105 ./prep_dataset/ILSVRC2012_val_00014021.bin 224 224 +32106 ./prep_dataset/ILSVRC2012_val_00025491.bin 224 224 +32107 ./prep_dataset/ILSVRC2012_val_00009576.bin 224 224 +32108 ./prep_dataset/ILSVRC2012_val_00027625.bin 224 224 +32109 ./prep_dataset/ILSVRC2012_val_00037119.bin 224 224 +32110 ./prep_dataset/ILSVRC2012_val_00013822.bin 224 224 +32111 ./prep_dataset/ILSVRC2012_val_00000298.bin 224 224 +32112 ./prep_dataset/ILSVRC2012_val_00017150.bin 224 224 +32113 ./prep_dataset/ILSVRC2012_val_00041636.bin 224 224 +32114 ./prep_dataset/ILSVRC2012_val_00035656.bin 224 224 +32115 ./prep_dataset/ILSVRC2012_val_00025433.bin 224 224 +32116 ./prep_dataset/ILSVRC2012_val_00027621.bin 224 224 +32117 ./prep_dataset/ILSVRC2012_val_00006037.bin 224 224 +32118 ./prep_dataset/ILSVRC2012_val_00037357.bin 224 224 +32119 ./prep_dataset/ILSVRC2012_val_00039886.bin 224 224 +32120 ./prep_dataset/ILSVRC2012_val_00033589.bin 224 224 +32121 ./prep_dataset/ILSVRC2012_val_00014348.bin 224 224 +32122 ./prep_dataset/ILSVRC2012_val_00034350.bin 224 224 +32123 ./prep_dataset/ILSVRC2012_val_00008919.bin 224 224 +32124 ./prep_dataset/ILSVRC2012_val_00034436.bin 224 224 +32125 ./prep_dataset/ILSVRC2012_val_00008999.bin 224 224 +32126 ./prep_dataset/ILSVRC2012_val_00047505.bin 224 224 +32127 ./prep_dataset/ILSVRC2012_val_00025673.bin 224 224 +32128 ./prep_dataset/ILSVRC2012_val_00025643.bin 224 224 +32129 ./prep_dataset/ILSVRC2012_val_00017589.bin 224 224 +32130 ./prep_dataset/ILSVRC2012_val_00046892.bin 224 224 +32131 ./prep_dataset/ILSVRC2012_val_00034822.bin 224 224 +32132 ./prep_dataset/ILSVRC2012_val_00003336.bin 224 224 +32133 ./prep_dataset/ILSVRC2012_val_00038770.bin 224 224 +32134 ./prep_dataset/ILSVRC2012_val_00021036.bin 224 224 +32135 ./prep_dataset/ILSVRC2012_val_00017487.bin 224 224 +32136 ./prep_dataset/ILSVRC2012_val_00011179.bin 224 224 +32137 ./prep_dataset/ILSVRC2012_val_00006663.bin 224 224 +32138 ./prep_dataset/ILSVRC2012_val_00049912.bin 224 224 +32139 ./prep_dataset/ILSVRC2012_val_00034544.bin 224 224 +32140 ./prep_dataset/ILSVRC2012_val_00000157.bin 224 224 +32141 ./prep_dataset/ILSVRC2012_val_00045196.bin 224 224 +32142 ./prep_dataset/ILSVRC2012_val_00035752.bin 224 224 +32143 ./prep_dataset/ILSVRC2012_val_00025810.bin 224 224 +32144 ./prep_dataset/ILSVRC2012_val_00014648.bin 224 224 +32145 ./prep_dataset/ILSVRC2012_val_00024319.bin 224 224 +32146 ./prep_dataset/ILSVRC2012_val_00037923.bin 224 224 +32147 ./prep_dataset/ILSVRC2012_val_00011681.bin 224 224 +32148 ./prep_dataset/ILSVRC2012_val_00027058.bin 224 224 +32149 ./prep_dataset/ILSVRC2012_val_00045358.bin 224 224 +32150 ./prep_dataset/ILSVRC2012_val_00006739.bin 224 224 +32151 ./prep_dataset/ILSVRC2012_val_00020388.bin 224 224 +32152 ./prep_dataset/ILSVRC2012_val_00037481.bin 224 224 +32153 ./prep_dataset/ILSVRC2012_val_00047825.bin 224 224 +32154 ./prep_dataset/ILSVRC2012_val_00022181.bin 224 224 +32155 ./prep_dataset/ILSVRC2012_val_00002702.bin 224 224 +32156 ./prep_dataset/ILSVRC2012_val_00030824.bin 224 224 +32157 ./prep_dataset/ILSVRC2012_val_00023591.bin 224 224 +32158 ./prep_dataset/ILSVRC2012_val_00014929.bin 224 224 +32159 ./prep_dataset/ILSVRC2012_val_00024063.bin 224 224 +32160 ./prep_dataset/ILSVRC2012_val_00039881.bin 224 224 +32161 ./prep_dataset/ILSVRC2012_val_00049635.bin 224 224 +32162 ./prep_dataset/ILSVRC2012_val_00044113.bin 224 224 +32163 ./prep_dataset/ILSVRC2012_val_00021506.bin 224 224 +32164 ./prep_dataset/ILSVRC2012_val_00007083.bin 224 224 +32165 ./prep_dataset/ILSVRC2012_val_00043256.bin 224 224 +32166 ./prep_dataset/ILSVRC2012_val_00038482.bin 224 224 +32167 ./prep_dataset/ILSVRC2012_val_00009103.bin 224 224 +32168 ./prep_dataset/ILSVRC2012_val_00003870.bin 224 224 +32169 ./prep_dataset/ILSVRC2012_val_00028269.bin 224 224 +32170 ./prep_dataset/ILSVRC2012_val_00007337.bin 224 224 +32171 ./prep_dataset/ILSVRC2012_val_00016546.bin 224 224 +32172 ./prep_dataset/ILSVRC2012_val_00013079.bin 224 224 +32173 ./prep_dataset/ILSVRC2012_val_00017108.bin 224 224 +32174 ./prep_dataset/ILSVRC2012_val_00007810.bin 224 224 +32175 ./prep_dataset/ILSVRC2012_val_00048016.bin 224 224 +32176 ./prep_dataset/ILSVRC2012_val_00044389.bin 224 224 +32177 ./prep_dataset/ILSVRC2012_val_00026066.bin 224 224 +32178 ./prep_dataset/ILSVRC2012_val_00003608.bin 224 224 +32179 ./prep_dataset/ILSVRC2012_val_00022396.bin 224 224 +32180 ./prep_dataset/ILSVRC2012_val_00040081.bin 224 224 +32181 ./prep_dataset/ILSVRC2012_val_00028036.bin 224 224 +32182 ./prep_dataset/ILSVRC2012_val_00044433.bin 224 224 +32183 ./prep_dataset/ILSVRC2012_val_00007280.bin 224 224 +32184 ./prep_dataset/ILSVRC2012_val_00009142.bin 224 224 +32185 ./prep_dataset/ILSVRC2012_val_00018242.bin 224 224 +32186 ./prep_dataset/ILSVRC2012_val_00022698.bin 224 224 +32187 ./prep_dataset/ILSVRC2012_val_00000307.bin 224 224 +32188 ./prep_dataset/ILSVRC2012_val_00026764.bin 224 224 +32189 ./prep_dataset/ILSVRC2012_val_00012526.bin 224 224 +32190 ./prep_dataset/ILSVRC2012_val_00031292.bin 224 224 +32191 ./prep_dataset/ILSVRC2012_val_00009893.bin 224 224 +32192 ./prep_dataset/ILSVRC2012_val_00017972.bin 224 224 +32193 ./prep_dataset/ILSVRC2012_val_00033320.bin 224 224 +32194 ./prep_dataset/ILSVRC2012_val_00035905.bin 224 224 +32195 ./prep_dataset/ILSVRC2012_val_00003070.bin 224 224 +32196 ./prep_dataset/ILSVRC2012_val_00026749.bin 224 224 +32197 ./prep_dataset/ILSVRC2012_val_00046920.bin 224 224 +32198 ./prep_dataset/ILSVRC2012_val_00032923.bin 224 224 +32199 ./prep_dataset/ILSVRC2012_val_00009891.bin 224 224 +32200 ./prep_dataset/ILSVRC2012_val_00014872.bin 224 224 +32201 ./prep_dataset/ILSVRC2012_val_00035785.bin 224 224 +32202 ./prep_dataset/ILSVRC2012_val_00027997.bin 224 224 +32203 ./prep_dataset/ILSVRC2012_val_00029354.bin 224 224 +32204 ./prep_dataset/ILSVRC2012_val_00048894.bin 224 224 +32205 ./prep_dataset/ILSVRC2012_val_00020524.bin 224 224 +32206 ./prep_dataset/ILSVRC2012_val_00033607.bin 224 224 +32207 ./prep_dataset/ILSVRC2012_val_00017889.bin 224 224 +32208 ./prep_dataset/ILSVRC2012_val_00041222.bin 224 224 +32209 ./prep_dataset/ILSVRC2012_val_00013870.bin 224 224 +32210 ./prep_dataset/ILSVRC2012_val_00021475.bin 224 224 +32211 ./prep_dataset/ILSVRC2012_val_00034051.bin 224 224 +32212 ./prep_dataset/ILSVRC2012_val_00036602.bin 224 224 +32213 ./prep_dataset/ILSVRC2012_val_00043352.bin 224 224 +32214 ./prep_dataset/ILSVRC2012_val_00035020.bin 224 224 +32215 ./prep_dataset/ILSVRC2012_val_00044692.bin 224 224 +32216 ./prep_dataset/ILSVRC2012_val_00039060.bin 224 224 +32217 ./prep_dataset/ILSVRC2012_val_00001738.bin 224 224 +32218 ./prep_dataset/ILSVRC2012_val_00008798.bin 224 224 +32219 ./prep_dataset/ILSVRC2012_val_00010794.bin 224 224 +32220 ./prep_dataset/ILSVRC2012_val_00011583.bin 224 224 +32221 ./prep_dataset/ILSVRC2012_val_00024839.bin 224 224 +32222 ./prep_dataset/ILSVRC2012_val_00043375.bin 224 224 +32223 ./prep_dataset/ILSVRC2012_val_00011424.bin 224 224 +32224 ./prep_dataset/ILSVRC2012_val_00044617.bin 224 224 +32225 ./prep_dataset/ILSVRC2012_val_00034997.bin 224 224 +32226 ./prep_dataset/ILSVRC2012_val_00033131.bin 224 224 +32227 ./prep_dataset/ILSVRC2012_val_00028602.bin 224 224 +32228 ./prep_dataset/ILSVRC2012_val_00009848.bin 224 224 +32229 ./prep_dataset/ILSVRC2012_val_00024716.bin 224 224 +32230 ./prep_dataset/ILSVRC2012_val_00027915.bin 224 224 +32231 ./prep_dataset/ILSVRC2012_val_00003855.bin 224 224 +32232 ./prep_dataset/ILSVRC2012_val_00013556.bin 224 224 +32233 ./prep_dataset/ILSVRC2012_val_00035447.bin 224 224 +32234 ./prep_dataset/ILSVRC2012_val_00044566.bin 224 224 +32235 ./prep_dataset/ILSVRC2012_val_00010069.bin 224 224 +32236 ./prep_dataset/ILSVRC2012_val_00012890.bin 224 224 +32237 ./prep_dataset/ILSVRC2012_val_00017545.bin 224 224 +32238 ./prep_dataset/ILSVRC2012_val_00043376.bin 224 224 +32239 ./prep_dataset/ILSVRC2012_val_00046639.bin 224 224 +32240 ./prep_dataset/ILSVRC2012_val_00011386.bin 224 224 +32241 ./prep_dataset/ILSVRC2012_val_00033426.bin 224 224 +32242 ./prep_dataset/ILSVRC2012_val_00028660.bin 224 224 +32243 ./prep_dataset/ILSVRC2012_val_00034693.bin 224 224 +32244 ./prep_dataset/ILSVRC2012_val_00025287.bin 224 224 +32245 ./prep_dataset/ILSVRC2012_val_00030230.bin 224 224 +32246 ./prep_dataset/ILSVRC2012_val_00022573.bin 224 224 +32247 ./prep_dataset/ILSVRC2012_val_00031391.bin 224 224 +32248 ./prep_dataset/ILSVRC2012_val_00029943.bin 224 224 +32249 ./prep_dataset/ILSVRC2012_val_00010190.bin 224 224 +32250 ./prep_dataset/ILSVRC2012_val_00021655.bin 224 224 +32251 ./prep_dataset/ILSVRC2012_val_00046176.bin 224 224 +32252 ./prep_dataset/ILSVRC2012_val_00011100.bin 224 224 +32253 ./prep_dataset/ILSVRC2012_val_00041677.bin 224 224 +32254 ./prep_dataset/ILSVRC2012_val_00036385.bin 224 224 +32255 ./prep_dataset/ILSVRC2012_val_00030379.bin 224 224 +32256 ./prep_dataset/ILSVRC2012_val_00046672.bin 224 224 +32257 ./prep_dataset/ILSVRC2012_val_00036859.bin 224 224 +32258 ./prep_dataset/ILSVRC2012_val_00039466.bin 224 224 +32259 ./prep_dataset/ILSVRC2012_val_00003522.bin 224 224 +32260 ./prep_dataset/ILSVRC2012_val_00018713.bin 224 224 +32261 ./prep_dataset/ILSVRC2012_val_00018525.bin 224 224 +32262 ./prep_dataset/ILSVRC2012_val_00038986.bin 224 224 +32263 ./prep_dataset/ILSVRC2012_val_00023884.bin 224 224 +32264 ./prep_dataset/ILSVRC2012_val_00039538.bin 224 224 +32265 ./prep_dataset/ILSVRC2012_val_00039619.bin 224 224 +32266 ./prep_dataset/ILSVRC2012_val_00032030.bin 224 224 +32267 ./prep_dataset/ILSVRC2012_val_00002521.bin 224 224 +32268 ./prep_dataset/ILSVRC2012_val_00028431.bin 224 224 +32269 ./prep_dataset/ILSVRC2012_val_00006227.bin 224 224 +32270 ./prep_dataset/ILSVRC2012_val_00027698.bin 224 224 +32271 ./prep_dataset/ILSVRC2012_val_00006418.bin 224 224 +32272 ./prep_dataset/ILSVRC2012_val_00022412.bin 224 224 +32273 ./prep_dataset/ILSVRC2012_val_00013643.bin 224 224 +32274 ./prep_dataset/ILSVRC2012_val_00046696.bin 224 224 +32275 ./prep_dataset/ILSVRC2012_val_00007329.bin 224 224 +32276 ./prep_dataset/ILSVRC2012_val_00014970.bin 224 224 +32277 ./prep_dataset/ILSVRC2012_val_00036644.bin 224 224 +32278 ./prep_dataset/ILSVRC2012_val_00040386.bin 224 224 +32279 ./prep_dataset/ILSVRC2012_val_00025687.bin 224 224 +32280 ./prep_dataset/ILSVRC2012_val_00037399.bin 224 224 +32281 ./prep_dataset/ILSVRC2012_val_00028740.bin 224 224 +32282 ./prep_dataset/ILSVRC2012_val_00006155.bin 224 224 +32283 ./prep_dataset/ILSVRC2012_val_00023606.bin 224 224 +32284 ./prep_dataset/ILSVRC2012_val_00033025.bin 224 224 +32285 ./prep_dataset/ILSVRC2012_val_00003897.bin 224 224 +32286 ./prep_dataset/ILSVRC2012_val_00012168.bin 224 224 +32287 ./prep_dataset/ILSVRC2012_val_00022734.bin 224 224 +32288 ./prep_dataset/ILSVRC2012_val_00046771.bin 224 224 +32289 ./prep_dataset/ILSVRC2012_val_00026791.bin 224 224 +32290 ./prep_dataset/ILSVRC2012_val_00046488.bin 224 224 +32291 ./prep_dataset/ILSVRC2012_val_00010929.bin 224 224 +32292 ./prep_dataset/ILSVRC2012_val_00039534.bin 224 224 +32293 ./prep_dataset/ILSVRC2012_val_00032311.bin 224 224 +32294 ./prep_dataset/ILSVRC2012_val_00035733.bin 224 224 +32295 ./prep_dataset/ILSVRC2012_val_00006285.bin 224 224 +32296 ./prep_dataset/ILSVRC2012_val_00008390.bin 224 224 +32297 ./prep_dataset/ILSVRC2012_val_00004900.bin 224 224 +32298 ./prep_dataset/ILSVRC2012_val_00012009.bin 224 224 +32299 ./prep_dataset/ILSVRC2012_val_00028818.bin 224 224 +32300 ./prep_dataset/ILSVRC2012_val_00030765.bin 224 224 +32301 ./prep_dataset/ILSVRC2012_val_00035169.bin 224 224 +32302 ./prep_dataset/ILSVRC2012_val_00030975.bin 224 224 +32303 ./prep_dataset/ILSVRC2012_val_00022485.bin 224 224 +32304 ./prep_dataset/ILSVRC2012_val_00018900.bin 224 224 +32305 ./prep_dataset/ILSVRC2012_val_00019910.bin 224 224 +32306 ./prep_dataset/ILSVRC2012_val_00040649.bin 224 224 +32307 ./prep_dataset/ILSVRC2012_val_00045313.bin 224 224 +32308 ./prep_dataset/ILSVRC2012_val_00009694.bin 224 224 +32309 ./prep_dataset/ILSVRC2012_val_00010919.bin 224 224 +32310 ./prep_dataset/ILSVRC2012_val_00000530.bin 224 224 +32311 ./prep_dataset/ILSVRC2012_val_00000691.bin 224 224 +32312 ./prep_dataset/ILSVRC2012_val_00027356.bin 224 224 +32313 ./prep_dataset/ILSVRC2012_val_00033968.bin 224 224 +32314 ./prep_dataset/ILSVRC2012_val_00008035.bin 224 224 +32315 ./prep_dataset/ILSVRC2012_val_00032104.bin 224 224 +32316 ./prep_dataset/ILSVRC2012_val_00036704.bin 224 224 +32317 ./prep_dataset/ILSVRC2012_val_00049392.bin 224 224 +32318 ./prep_dataset/ILSVRC2012_val_00014894.bin 224 224 +32319 ./prep_dataset/ILSVRC2012_val_00024689.bin 224 224 +32320 ./prep_dataset/ILSVRC2012_val_00025888.bin 224 224 +32321 ./prep_dataset/ILSVRC2012_val_00022460.bin 224 224 +32322 ./prep_dataset/ILSVRC2012_val_00009975.bin 224 224 +32323 ./prep_dataset/ILSVRC2012_val_00003437.bin 224 224 +32324 ./prep_dataset/ILSVRC2012_val_00039083.bin 224 224 +32325 ./prep_dataset/ILSVRC2012_val_00011275.bin 224 224 +32326 ./prep_dataset/ILSVRC2012_val_00020581.bin 224 224 +32327 ./prep_dataset/ILSVRC2012_val_00029078.bin 224 224 +32328 ./prep_dataset/ILSVRC2012_val_00030354.bin 224 224 +32329 ./prep_dataset/ILSVRC2012_val_00035722.bin 224 224 +32330 ./prep_dataset/ILSVRC2012_val_00002020.bin 224 224 +32331 ./prep_dataset/ILSVRC2012_val_00038128.bin 224 224 +32332 ./prep_dataset/ILSVRC2012_val_00041191.bin 224 224 +32333 ./prep_dataset/ILSVRC2012_val_00018702.bin 224 224 +32334 ./prep_dataset/ILSVRC2012_val_00018943.bin 224 224 +32335 ./prep_dataset/ILSVRC2012_val_00017525.bin 224 224 +32336 ./prep_dataset/ILSVRC2012_val_00035048.bin 224 224 +32337 ./prep_dataset/ILSVRC2012_val_00008028.bin 224 224 +32338 ./prep_dataset/ILSVRC2012_val_00000441.bin 224 224 +32339 ./prep_dataset/ILSVRC2012_val_00049012.bin 224 224 +32340 ./prep_dataset/ILSVRC2012_val_00024316.bin 224 224 +32341 ./prep_dataset/ILSVRC2012_val_00039631.bin 224 224 +32342 ./prep_dataset/ILSVRC2012_val_00003868.bin 224 224 +32343 ./prep_dataset/ILSVRC2012_val_00019383.bin 224 224 +32344 ./prep_dataset/ILSVRC2012_val_00017703.bin 224 224 +32345 ./prep_dataset/ILSVRC2012_val_00019437.bin 224 224 +32346 ./prep_dataset/ILSVRC2012_val_00032252.bin 224 224 +32347 ./prep_dataset/ILSVRC2012_val_00004972.bin 224 224 +32348 ./prep_dataset/ILSVRC2012_val_00033006.bin 224 224 +32349 ./prep_dataset/ILSVRC2012_val_00008159.bin 224 224 +32350 ./prep_dataset/ILSVRC2012_val_00032966.bin 224 224 +32351 ./prep_dataset/ILSVRC2012_val_00015114.bin 224 224 +32352 ./prep_dataset/ILSVRC2012_val_00029272.bin 224 224 +32353 ./prep_dataset/ILSVRC2012_val_00006794.bin 224 224 +32354 ./prep_dataset/ILSVRC2012_val_00001254.bin 224 224 +32355 ./prep_dataset/ILSVRC2012_val_00019233.bin 224 224 +32356 ./prep_dataset/ILSVRC2012_val_00017766.bin 224 224 +32357 ./prep_dataset/ILSVRC2012_val_00011663.bin 224 224 +32358 ./prep_dataset/ILSVRC2012_val_00022409.bin 224 224 +32359 ./prep_dataset/ILSVRC2012_val_00029009.bin 224 224 +32360 ./prep_dataset/ILSVRC2012_val_00008712.bin 224 224 +32361 ./prep_dataset/ILSVRC2012_val_00010385.bin 224 224 +32362 ./prep_dataset/ILSVRC2012_val_00002000.bin 224 224 +32363 ./prep_dataset/ILSVRC2012_val_00007830.bin 224 224 +32364 ./prep_dataset/ILSVRC2012_val_00020678.bin 224 224 +32365 ./prep_dataset/ILSVRC2012_val_00007125.bin 224 224 +32366 ./prep_dataset/ILSVRC2012_val_00005120.bin 224 224 +32367 ./prep_dataset/ILSVRC2012_val_00027405.bin 224 224 +32368 ./prep_dataset/ILSVRC2012_val_00002442.bin 224 224 +32369 ./prep_dataset/ILSVRC2012_val_00019376.bin 224 224 +32370 ./prep_dataset/ILSVRC2012_val_00039593.bin 224 224 +32371 ./prep_dataset/ILSVRC2012_val_00049299.bin 224 224 +32372 ./prep_dataset/ILSVRC2012_val_00000676.bin 224 224 +32373 ./prep_dataset/ILSVRC2012_val_00006153.bin 224 224 +32374 ./prep_dataset/ILSVRC2012_val_00020961.bin 224 224 +32375 ./prep_dataset/ILSVRC2012_val_00010108.bin 224 224 +32376 ./prep_dataset/ILSVRC2012_val_00018431.bin 224 224 +32377 ./prep_dataset/ILSVRC2012_val_00027270.bin 224 224 +32378 ./prep_dataset/ILSVRC2012_val_00000742.bin 224 224 +32379 ./prep_dataset/ILSVRC2012_val_00044679.bin 224 224 +32380 ./prep_dataset/ILSVRC2012_val_00023375.bin 224 224 +32381 ./prep_dataset/ILSVRC2012_val_00018722.bin 224 224 +32382 ./prep_dataset/ILSVRC2012_val_00020231.bin 224 224 +32383 ./prep_dataset/ILSVRC2012_val_00037999.bin 224 224 +32384 ./prep_dataset/ILSVRC2012_val_00017516.bin 224 224 +32385 ./prep_dataset/ILSVRC2012_val_00031790.bin 224 224 +32386 ./prep_dataset/ILSVRC2012_val_00026546.bin 224 224 +32387 ./prep_dataset/ILSVRC2012_val_00048927.bin 224 224 +32388 ./prep_dataset/ILSVRC2012_val_00016999.bin 224 224 +32389 ./prep_dataset/ILSVRC2012_val_00030731.bin 224 224 +32390 ./prep_dataset/ILSVRC2012_val_00024409.bin 224 224 +32391 ./prep_dataset/ILSVRC2012_val_00007566.bin 224 224 +32392 ./prep_dataset/ILSVRC2012_val_00014049.bin 224 224 +32393 ./prep_dataset/ILSVRC2012_val_00010890.bin 224 224 +32394 ./prep_dataset/ILSVRC2012_val_00002868.bin 224 224 +32395 ./prep_dataset/ILSVRC2012_val_00044025.bin 224 224 +32396 ./prep_dataset/ILSVRC2012_val_00009635.bin 224 224 +32397 ./prep_dataset/ILSVRC2012_val_00011697.bin 224 224 +32398 ./prep_dataset/ILSVRC2012_val_00048600.bin 224 224 +32399 ./prep_dataset/ILSVRC2012_val_00023678.bin 224 224 +32400 ./prep_dataset/ILSVRC2012_val_00001421.bin 224 224 +32401 ./prep_dataset/ILSVRC2012_val_00024385.bin 224 224 +32402 ./prep_dataset/ILSVRC2012_val_00016948.bin 224 224 +32403 ./prep_dataset/ILSVRC2012_val_00002682.bin 224 224 +32404 ./prep_dataset/ILSVRC2012_val_00037458.bin 224 224 +32405 ./prep_dataset/ILSVRC2012_val_00033999.bin 224 224 +32406 ./prep_dataset/ILSVRC2012_val_00023451.bin 224 224 +32407 ./prep_dataset/ILSVRC2012_val_00026032.bin 224 224 +32408 ./prep_dataset/ILSVRC2012_val_00035922.bin 224 224 +32409 ./prep_dataset/ILSVRC2012_val_00014777.bin 224 224 +32410 ./prep_dataset/ILSVRC2012_val_00044568.bin 224 224 +32411 ./prep_dataset/ILSVRC2012_val_00007279.bin 224 224 +32412 ./prep_dataset/ILSVRC2012_val_00000521.bin 224 224 +32413 ./prep_dataset/ILSVRC2012_val_00003813.bin 224 224 +32414 ./prep_dataset/ILSVRC2012_val_00040399.bin 224 224 +32415 ./prep_dataset/ILSVRC2012_val_00013628.bin 224 224 +32416 ./prep_dataset/ILSVRC2012_val_00043491.bin 224 224 +32417 ./prep_dataset/ILSVRC2012_val_00044334.bin 224 224 +32418 ./prep_dataset/ILSVRC2012_val_00033889.bin 224 224 +32419 ./prep_dataset/ILSVRC2012_val_00047880.bin 224 224 +32420 ./prep_dataset/ILSVRC2012_val_00002966.bin 224 224 +32421 ./prep_dataset/ILSVRC2012_val_00002733.bin 224 224 +32422 ./prep_dataset/ILSVRC2012_val_00029441.bin 224 224 +32423 ./prep_dataset/ILSVRC2012_val_00001638.bin 224 224 +32424 ./prep_dataset/ILSVRC2012_val_00032200.bin 224 224 +32425 ./prep_dataset/ILSVRC2012_val_00041456.bin 224 224 +32426 ./prep_dataset/ILSVRC2012_val_00009732.bin 224 224 +32427 ./prep_dataset/ILSVRC2012_val_00034873.bin 224 224 +32428 ./prep_dataset/ILSVRC2012_val_00036817.bin 224 224 +32429 ./prep_dataset/ILSVRC2012_val_00019255.bin 224 224 +32430 ./prep_dataset/ILSVRC2012_val_00007462.bin 224 224 +32431 ./prep_dataset/ILSVRC2012_val_00032391.bin 224 224 +32432 ./prep_dataset/ILSVRC2012_val_00014145.bin 224 224 +32433 ./prep_dataset/ILSVRC2012_val_00023430.bin 224 224 +32434 ./prep_dataset/ILSVRC2012_val_00005185.bin 224 224 +32435 ./prep_dataset/ILSVRC2012_val_00004733.bin 224 224 +32436 ./prep_dataset/ILSVRC2012_val_00023988.bin 224 224 +32437 ./prep_dataset/ILSVRC2012_val_00001680.bin 224 224 +32438 ./prep_dataset/ILSVRC2012_val_00018254.bin 224 224 +32439 ./prep_dataset/ILSVRC2012_val_00030125.bin 224 224 +32440 ./prep_dataset/ILSVRC2012_val_00044385.bin 224 224 +32441 ./prep_dataset/ILSVRC2012_val_00044688.bin 224 224 +32442 ./prep_dataset/ILSVRC2012_val_00028178.bin 224 224 +32443 ./prep_dataset/ILSVRC2012_val_00015734.bin 224 224 +32444 ./prep_dataset/ILSVRC2012_val_00002211.bin 224 224 +32445 ./prep_dataset/ILSVRC2012_val_00021702.bin 224 224 +32446 ./prep_dataset/ILSVRC2012_val_00026738.bin 224 224 +32447 ./prep_dataset/ILSVRC2012_val_00018881.bin 224 224 +32448 ./prep_dataset/ILSVRC2012_val_00005971.bin 224 224 +32449 ./prep_dataset/ILSVRC2012_val_00023166.bin 224 224 +32450 ./prep_dataset/ILSVRC2012_val_00042168.bin 224 224 +32451 ./prep_dataset/ILSVRC2012_val_00001678.bin 224 224 +32452 ./prep_dataset/ILSVRC2012_val_00031636.bin 224 224 +32453 ./prep_dataset/ILSVRC2012_val_00002953.bin 224 224 +32454 ./prep_dataset/ILSVRC2012_val_00024304.bin 224 224 +32455 ./prep_dataset/ILSVRC2012_val_00022604.bin 224 224 +32456 ./prep_dataset/ILSVRC2012_val_00017825.bin 224 224 +32457 ./prep_dataset/ILSVRC2012_val_00005731.bin 224 224 +32458 ./prep_dataset/ILSVRC2012_val_00040593.bin 224 224 +32459 ./prep_dataset/ILSVRC2012_val_00040248.bin 224 224 +32460 ./prep_dataset/ILSVRC2012_val_00006818.bin 224 224 +32461 ./prep_dataset/ILSVRC2012_val_00022239.bin 224 224 +32462 ./prep_dataset/ILSVRC2012_val_00007684.bin 224 224 +32463 ./prep_dataset/ILSVRC2012_val_00000259.bin 224 224 +32464 ./prep_dataset/ILSVRC2012_val_00014384.bin 224 224 +32465 ./prep_dataset/ILSVRC2012_val_00027936.bin 224 224 +32466 ./prep_dataset/ILSVRC2012_val_00025298.bin 224 224 +32467 ./prep_dataset/ILSVRC2012_val_00013416.bin 224 224 +32468 ./prep_dataset/ILSVRC2012_val_00002833.bin 224 224 +32469 ./prep_dataset/ILSVRC2012_val_00041375.bin 224 224 +32470 ./prep_dataset/ILSVRC2012_val_00016731.bin 224 224 +32471 ./prep_dataset/ILSVRC2012_val_00034099.bin 224 224 +32472 ./prep_dataset/ILSVRC2012_val_00031010.bin 224 224 +32473 ./prep_dataset/ILSVRC2012_val_00016429.bin 224 224 +32474 ./prep_dataset/ILSVRC2012_val_00004889.bin 224 224 +32475 ./prep_dataset/ILSVRC2012_val_00023062.bin 224 224 +32476 ./prep_dataset/ILSVRC2012_val_00022710.bin 224 224 +32477 ./prep_dataset/ILSVRC2012_val_00016950.bin 224 224 +32478 ./prep_dataset/ILSVRC2012_val_00039441.bin 224 224 +32479 ./prep_dataset/ILSVRC2012_val_00041588.bin 224 224 +32480 ./prep_dataset/ILSVRC2012_val_00028834.bin 224 224 +32481 ./prep_dataset/ILSVRC2012_val_00005660.bin 224 224 +32482 ./prep_dataset/ILSVRC2012_val_00044093.bin 224 224 +32483 ./prep_dataset/ILSVRC2012_val_00000908.bin 224 224 +32484 ./prep_dataset/ILSVRC2012_val_00012604.bin 224 224 +32485 ./prep_dataset/ILSVRC2012_val_00001450.bin 224 224 +32486 ./prep_dataset/ILSVRC2012_val_00043683.bin 224 224 +32487 ./prep_dataset/ILSVRC2012_val_00047059.bin 224 224 +32488 ./prep_dataset/ILSVRC2012_val_00021182.bin 224 224 +32489 ./prep_dataset/ILSVRC2012_val_00019504.bin 224 224 +32490 ./prep_dataset/ILSVRC2012_val_00004347.bin 224 224 +32491 ./prep_dataset/ILSVRC2012_val_00041548.bin 224 224 +32492 ./prep_dataset/ILSVRC2012_val_00025850.bin 224 224 +32493 ./prep_dataset/ILSVRC2012_val_00037974.bin 224 224 +32494 ./prep_dataset/ILSVRC2012_val_00000901.bin 224 224 +32495 ./prep_dataset/ILSVRC2012_val_00005585.bin 224 224 +32496 ./prep_dataset/ILSVRC2012_val_00032071.bin 224 224 +32497 ./prep_dataset/ILSVRC2012_val_00031199.bin 224 224 +32498 ./prep_dataset/ILSVRC2012_val_00012563.bin 224 224 +32499 ./prep_dataset/ILSVRC2012_val_00049675.bin 224 224 +32500 ./prep_dataset/ILSVRC2012_val_00048045.bin 224 224 +32501 ./prep_dataset/ILSVRC2012_val_00024412.bin 224 224 +32502 ./prep_dataset/ILSVRC2012_val_00013350.bin 224 224 +32503 ./prep_dataset/ILSVRC2012_val_00038763.bin 224 224 +32504 ./prep_dataset/ILSVRC2012_val_00016049.bin 224 224 +32505 ./prep_dataset/ILSVRC2012_val_00023535.bin 224 224 +32506 ./prep_dataset/ILSVRC2012_val_00044017.bin 224 224 +32507 ./prep_dataset/ILSVRC2012_val_00016654.bin 224 224 +32508 ./prep_dataset/ILSVRC2012_val_00008807.bin 224 224 +32509 ./prep_dataset/ILSVRC2012_val_00023545.bin 224 224 +32510 ./prep_dataset/ILSVRC2012_val_00034172.bin 224 224 +32511 ./prep_dataset/ILSVRC2012_val_00041165.bin 224 224 +32512 ./prep_dataset/ILSVRC2012_val_00047774.bin 224 224 +32513 ./prep_dataset/ILSVRC2012_val_00046495.bin 224 224 +32514 ./prep_dataset/ILSVRC2012_val_00016699.bin 224 224 +32515 ./prep_dataset/ILSVRC2012_val_00046185.bin 224 224 +32516 ./prep_dataset/ILSVRC2012_val_00003448.bin 224 224 +32517 ./prep_dataset/ILSVRC2012_val_00025572.bin 224 224 +32518 ./prep_dataset/ILSVRC2012_val_00011205.bin 224 224 +32519 ./prep_dataset/ILSVRC2012_val_00034938.bin 224 224 +32520 ./prep_dataset/ILSVRC2012_val_00044860.bin 224 224 +32521 ./prep_dataset/ILSVRC2012_val_00024363.bin 224 224 +32522 ./prep_dataset/ILSVRC2012_val_00003658.bin 224 224 +32523 ./prep_dataset/ILSVRC2012_val_00048590.bin 224 224 +32524 ./prep_dataset/ILSVRC2012_val_00028635.bin 224 224 +32525 ./prep_dataset/ILSVRC2012_val_00029132.bin 224 224 +32526 ./prep_dataset/ILSVRC2012_val_00043836.bin 224 224 +32527 ./prep_dataset/ILSVRC2012_val_00020855.bin 224 224 +32528 ./prep_dataset/ILSVRC2012_val_00038063.bin 224 224 +32529 ./prep_dataset/ILSVRC2012_val_00026829.bin 224 224 +32530 ./prep_dataset/ILSVRC2012_val_00003539.bin 224 224 +32531 ./prep_dataset/ILSVRC2012_val_00041317.bin 224 224 +32532 ./prep_dataset/ILSVRC2012_val_00039186.bin 224 224 +32533 ./prep_dataset/ILSVRC2012_val_00048070.bin 224 224 +32534 ./prep_dataset/ILSVRC2012_val_00047020.bin 224 224 +32535 ./prep_dataset/ILSVRC2012_val_00036448.bin 224 224 +32536 ./prep_dataset/ILSVRC2012_val_00026979.bin 224 224 +32537 ./prep_dataset/ILSVRC2012_val_00019422.bin 224 224 +32538 ./prep_dataset/ILSVRC2012_val_00012941.bin 224 224 +32539 ./prep_dataset/ILSVRC2012_val_00040476.bin 224 224 +32540 ./prep_dataset/ILSVRC2012_val_00032223.bin 224 224 +32541 ./prep_dataset/ILSVRC2012_val_00045010.bin 224 224 +32542 ./prep_dataset/ILSVRC2012_val_00046227.bin 224 224 +32543 ./prep_dataset/ILSVRC2012_val_00011456.bin 224 224 +32544 ./prep_dataset/ILSVRC2012_val_00033978.bin 224 224 +32545 ./prep_dataset/ILSVRC2012_val_00000292.bin 224 224 +32546 ./prep_dataset/ILSVRC2012_val_00022158.bin 224 224 +32547 ./prep_dataset/ILSVRC2012_val_00029692.bin 224 224 +32548 ./prep_dataset/ILSVRC2012_val_00037215.bin 224 224 +32549 ./prep_dataset/ILSVRC2012_val_00019638.bin 224 224 +32550 ./prep_dataset/ILSVRC2012_val_00042615.bin 224 224 +32551 ./prep_dataset/ILSVRC2012_val_00017183.bin 224 224 +32552 ./prep_dataset/ILSVRC2012_val_00020882.bin 224 224 +32553 ./prep_dataset/ILSVRC2012_val_00047474.bin 224 224 +32554 ./prep_dataset/ILSVRC2012_val_00011252.bin 224 224 +32555 ./prep_dataset/ILSVRC2012_val_00028014.bin 224 224 +32556 ./prep_dataset/ILSVRC2012_val_00041646.bin 224 224 +32557 ./prep_dataset/ILSVRC2012_val_00032180.bin 224 224 +32558 ./prep_dataset/ILSVRC2012_val_00020654.bin 224 224 +32559 ./prep_dataset/ILSVRC2012_val_00023986.bin 224 224 +32560 ./prep_dataset/ILSVRC2012_val_00020902.bin 224 224 +32561 ./prep_dataset/ILSVRC2012_val_00022345.bin 224 224 +32562 ./prep_dataset/ILSVRC2012_val_00018151.bin 224 224 +32563 ./prep_dataset/ILSVRC2012_val_00026656.bin 224 224 +32564 ./prep_dataset/ILSVRC2012_val_00044522.bin 224 224 +32565 ./prep_dataset/ILSVRC2012_val_00037390.bin 224 224 +32566 ./prep_dataset/ILSVRC2012_val_00021026.bin 224 224 +32567 ./prep_dataset/ILSVRC2012_val_00026079.bin 224 224 +32568 ./prep_dataset/ILSVRC2012_val_00019674.bin 224 224 +32569 ./prep_dataset/ILSVRC2012_val_00033013.bin 224 224 +32570 ./prep_dataset/ILSVRC2012_val_00024506.bin 224 224 +32571 ./prep_dataset/ILSVRC2012_val_00039516.bin 224 224 +32572 ./prep_dataset/ILSVRC2012_val_00048049.bin 224 224 +32573 ./prep_dataset/ILSVRC2012_val_00040932.bin 224 224 +32574 ./prep_dataset/ILSVRC2012_val_00041390.bin 224 224 +32575 ./prep_dataset/ILSVRC2012_val_00025356.bin 224 224 +32576 ./prep_dataset/ILSVRC2012_val_00013146.bin 224 224 +32577 ./prep_dataset/ILSVRC2012_val_00043353.bin 224 224 +32578 ./prep_dataset/ILSVRC2012_val_00048972.bin 224 224 +32579 ./prep_dataset/ILSVRC2012_val_00007858.bin 224 224 +32580 ./prep_dataset/ILSVRC2012_val_00011671.bin 224 224 +32581 ./prep_dataset/ILSVRC2012_val_00011633.bin 224 224 +32582 ./prep_dataset/ILSVRC2012_val_00026698.bin 224 224 +32583 ./prep_dataset/ILSVRC2012_val_00042080.bin 224 224 +32584 ./prep_dataset/ILSVRC2012_val_00035680.bin 224 224 +32585 ./prep_dataset/ILSVRC2012_val_00015055.bin 224 224 +32586 ./prep_dataset/ILSVRC2012_val_00047130.bin 224 224 +32587 ./prep_dataset/ILSVRC2012_val_00035790.bin 224 224 +32588 ./prep_dataset/ILSVRC2012_val_00000960.bin 224 224 +32589 ./prep_dataset/ILSVRC2012_val_00046572.bin 224 224 +32590 ./prep_dataset/ILSVRC2012_val_00032169.bin 224 224 +32591 ./prep_dataset/ILSVRC2012_val_00040004.bin 224 224 +32592 ./prep_dataset/ILSVRC2012_val_00030259.bin 224 224 +32593 ./prep_dataset/ILSVRC2012_val_00005417.bin 224 224 +32594 ./prep_dataset/ILSVRC2012_val_00041999.bin 224 224 +32595 ./prep_dataset/ILSVRC2012_val_00025489.bin 224 224 +32596 ./prep_dataset/ILSVRC2012_val_00025310.bin 224 224 +32597 ./prep_dataset/ILSVRC2012_val_00047884.bin 224 224 +32598 ./prep_dataset/ILSVRC2012_val_00001799.bin 224 224 +32599 ./prep_dataset/ILSVRC2012_val_00011710.bin 224 224 +32600 ./prep_dataset/ILSVRC2012_val_00015695.bin 224 224 +32601 ./prep_dataset/ILSVRC2012_val_00048936.bin 224 224 +32602 ./prep_dataset/ILSVRC2012_val_00023758.bin 224 224 +32603 ./prep_dataset/ILSVRC2012_val_00036999.bin 224 224 +32604 ./prep_dataset/ILSVRC2012_val_00017734.bin 224 224 +32605 ./prep_dataset/ILSVRC2012_val_00016712.bin 224 224 +32606 ./prep_dataset/ILSVRC2012_val_00015289.bin 224 224 +32607 ./prep_dataset/ILSVRC2012_val_00010574.bin 224 224 +32608 ./prep_dataset/ILSVRC2012_val_00042079.bin 224 224 +32609 ./prep_dataset/ILSVRC2012_val_00019690.bin 224 224 +32610 ./prep_dataset/ILSVRC2012_val_00036737.bin 224 224 +32611 ./prep_dataset/ILSVRC2012_val_00040992.bin 224 224 +32612 ./prep_dataset/ILSVRC2012_val_00044894.bin 224 224 +32613 ./prep_dataset/ILSVRC2012_val_00028309.bin 224 224 +32614 ./prep_dataset/ILSVRC2012_val_00031628.bin 224 224 +32615 ./prep_dataset/ILSVRC2012_val_00033007.bin 224 224 +32616 ./prep_dataset/ILSVRC2012_val_00013431.bin 224 224 +32617 ./prep_dataset/ILSVRC2012_val_00023248.bin 224 224 +32618 ./prep_dataset/ILSVRC2012_val_00032962.bin 224 224 +32619 ./prep_dataset/ILSVRC2012_val_00037726.bin 224 224 +32620 ./prep_dataset/ILSVRC2012_val_00009131.bin 224 224 +32621 ./prep_dataset/ILSVRC2012_val_00030435.bin 224 224 +32622 ./prep_dataset/ILSVRC2012_val_00019408.bin 224 224 +32623 ./prep_dataset/ILSVRC2012_val_00030428.bin 224 224 +32624 ./prep_dataset/ILSVRC2012_val_00031981.bin 224 224 +32625 ./prep_dataset/ILSVRC2012_val_00022364.bin 224 224 +32626 ./prep_dataset/ILSVRC2012_val_00030615.bin 224 224 +32627 ./prep_dataset/ILSVRC2012_val_00023249.bin 224 224 +32628 ./prep_dataset/ILSVRC2012_val_00033557.bin 224 224 +32629 ./prep_dataset/ILSVRC2012_val_00009936.bin 224 224 +32630 ./prep_dataset/ILSVRC2012_val_00017867.bin 224 224 +32631 ./prep_dataset/ILSVRC2012_val_00030985.bin 224 224 +32632 ./prep_dataset/ILSVRC2012_val_00046822.bin 224 224 +32633 ./prep_dataset/ILSVRC2012_val_00007690.bin 224 224 +32634 ./prep_dataset/ILSVRC2012_val_00034823.bin 224 224 +32635 ./prep_dataset/ILSVRC2012_val_00043071.bin 224 224 +32636 ./prep_dataset/ILSVRC2012_val_00014170.bin 224 224 +32637 ./prep_dataset/ILSVRC2012_val_00003013.bin 224 224 +32638 ./prep_dataset/ILSVRC2012_val_00023201.bin 224 224 +32639 ./prep_dataset/ILSVRC2012_val_00034469.bin 224 224 +32640 ./prep_dataset/ILSVRC2012_val_00042691.bin 224 224 +32641 ./prep_dataset/ILSVRC2012_val_00046346.bin 224 224 +32642 ./prep_dataset/ILSVRC2012_val_00014925.bin 224 224 +32643 ./prep_dataset/ILSVRC2012_val_00012361.bin 224 224 +32644 ./prep_dataset/ILSVRC2012_val_00012790.bin 224 224 +32645 ./prep_dataset/ILSVRC2012_val_00010535.bin 224 224 +32646 ./prep_dataset/ILSVRC2012_val_00027931.bin 224 224 +32647 ./prep_dataset/ILSVRC2012_val_00049547.bin 224 224 +32648 ./prep_dataset/ILSVRC2012_val_00009124.bin 224 224 +32649 ./prep_dataset/ILSVRC2012_val_00010524.bin 224 224 +32650 ./prep_dataset/ILSVRC2012_val_00040659.bin 224 224 +32651 ./prep_dataset/ILSVRC2012_val_00044327.bin 224 224 +32652 ./prep_dataset/ILSVRC2012_val_00005504.bin 224 224 +32653 ./prep_dataset/ILSVRC2012_val_00049759.bin 224 224 +32654 ./prep_dataset/ILSVRC2012_val_00012328.bin 224 224 +32655 ./prep_dataset/ILSVRC2012_val_00000228.bin 224 224 +32656 ./prep_dataset/ILSVRC2012_val_00046793.bin 224 224 +32657 ./prep_dataset/ILSVRC2012_val_00046975.bin 224 224 +32658 ./prep_dataset/ILSVRC2012_val_00049691.bin 224 224 +32659 ./prep_dataset/ILSVRC2012_val_00024122.bin 224 224 +32660 ./prep_dataset/ILSVRC2012_val_00046134.bin 224 224 +32661 ./prep_dataset/ILSVRC2012_val_00008386.bin 224 224 +32662 ./prep_dataset/ILSVRC2012_val_00038153.bin 224 224 +32663 ./prep_dataset/ILSVRC2012_val_00027713.bin 224 224 +32664 ./prep_dataset/ILSVRC2012_val_00044747.bin 224 224 +32665 ./prep_dataset/ILSVRC2012_val_00009673.bin 224 224 +32666 ./prep_dataset/ILSVRC2012_val_00044298.bin 224 224 +32667 ./prep_dataset/ILSVRC2012_val_00030016.bin 224 224 +32668 ./prep_dataset/ILSVRC2012_val_00048387.bin 224 224 +32669 ./prep_dataset/ILSVRC2012_val_00043006.bin 224 224 +32670 ./prep_dataset/ILSVRC2012_val_00008493.bin 224 224 +32671 ./prep_dataset/ILSVRC2012_val_00045496.bin 224 224 +32672 ./prep_dataset/ILSVRC2012_val_00022066.bin 224 224 +32673 ./prep_dataset/ILSVRC2012_val_00002492.bin 224 224 +32674 ./prep_dataset/ILSVRC2012_val_00020234.bin 224 224 +32675 ./prep_dataset/ILSVRC2012_val_00003089.bin 224 224 +32676 ./prep_dataset/ILSVRC2012_val_00013519.bin 224 224 +32677 ./prep_dataset/ILSVRC2012_val_00018110.bin 224 224 +32678 ./prep_dataset/ILSVRC2012_val_00029908.bin 224 224 +32679 ./prep_dataset/ILSVRC2012_val_00034095.bin 224 224 +32680 ./prep_dataset/ILSVRC2012_val_00016403.bin 224 224 +32681 ./prep_dataset/ILSVRC2012_val_00025302.bin 224 224 +32682 ./prep_dataset/ILSVRC2012_val_00038239.bin 224 224 +32683 ./prep_dataset/ILSVRC2012_val_00040462.bin 224 224 +32684 ./prep_dataset/ILSVRC2012_val_00038060.bin 224 224 +32685 ./prep_dataset/ILSVRC2012_val_00023099.bin 224 224 +32686 ./prep_dataset/ILSVRC2012_val_00004926.bin 224 224 +32687 ./prep_dataset/ILSVRC2012_val_00012380.bin 224 224 +32688 ./prep_dataset/ILSVRC2012_val_00023685.bin 224 224 +32689 ./prep_dataset/ILSVRC2012_val_00045549.bin 224 224 +32690 ./prep_dataset/ILSVRC2012_val_00032894.bin 224 224 +32691 ./prep_dataset/ILSVRC2012_val_00048715.bin 224 224 +32692 ./prep_dataset/ILSVRC2012_val_00044254.bin 224 224 +32693 ./prep_dataset/ILSVRC2012_val_00027094.bin 224 224 +32694 ./prep_dataset/ILSVRC2012_val_00011005.bin 224 224 +32695 ./prep_dataset/ILSVRC2012_val_00011757.bin 224 224 +32696 ./prep_dataset/ILSVRC2012_val_00027839.bin 224 224 +32697 ./prep_dataset/ILSVRC2012_val_00003154.bin 224 224 +32698 ./prep_dataset/ILSVRC2012_val_00012898.bin 224 224 +32699 ./prep_dataset/ILSVRC2012_val_00044452.bin 224 224 +32700 ./prep_dataset/ILSVRC2012_val_00036262.bin 224 224 +32701 ./prep_dataset/ILSVRC2012_val_00048649.bin 224 224 +32702 ./prep_dataset/ILSVRC2012_val_00005894.bin 224 224 +32703 ./prep_dataset/ILSVRC2012_val_00003159.bin 224 224 +32704 ./prep_dataset/ILSVRC2012_val_00047317.bin 224 224 +32705 ./prep_dataset/ILSVRC2012_val_00000816.bin 224 224 +32706 ./prep_dataset/ILSVRC2012_val_00015219.bin 224 224 +32707 ./prep_dataset/ILSVRC2012_val_00046207.bin 224 224 +32708 ./prep_dataset/ILSVRC2012_val_00029173.bin 224 224 +32709 ./prep_dataset/ILSVRC2012_val_00026230.bin 224 224 +32710 ./prep_dataset/ILSVRC2012_val_00016600.bin 224 224 +32711 ./prep_dataset/ILSVRC2012_val_00012813.bin 224 224 +32712 ./prep_dataset/ILSVRC2012_val_00041032.bin 224 224 +32713 ./prep_dataset/ILSVRC2012_val_00001684.bin 224 224 +32714 ./prep_dataset/ILSVRC2012_val_00015948.bin 224 224 +32715 ./prep_dataset/ILSVRC2012_val_00024078.bin 224 224 +32716 ./prep_dataset/ILSVRC2012_val_00006309.bin 224 224 +32717 ./prep_dataset/ILSVRC2012_val_00041183.bin 224 224 +32718 ./prep_dataset/ILSVRC2012_val_00026821.bin 224 224 +32719 ./prep_dataset/ILSVRC2012_val_00029926.bin 224 224 +32720 ./prep_dataset/ILSVRC2012_val_00037065.bin 224 224 +32721 ./prep_dataset/ILSVRC2012_val_00028551.bin 224 224 +32722 ./prep_dataset/ILSVRC2012_val_00004842.bin 224 224 +32723 ./prep_dataset/ILSVRC2012_val_00010062.bin 224 224 +32724 ./prep_dataset/ILSVRC2012_val_00009856.bin 224 224 +32725 ./prep_dataset/ILSVRC2012_val_00020948.bin 224 224 +32726 ./prep_dataset/ILSVRC2012_val_00049323.bin 224 224 +32727 ./prep_dataset/ILSVRC2012_val_00010956.bin 224 224 +32728 ./prep_dataset/ILSVRC2012_val_00028286.bin 224 224 +32729 ./prep_dataset/ILSVRC2012_val_00005791.bin 224 224 +32730 ./prep_dataset/ILSVRC2012_val_00031104.bin 224 224 +32731 ./prep_dataset/ILSVRC2012_val_00009785.bin 224 224 +32732 ./prep_dataset/ILSVRC2012_val_00031821.bin 224 224 +32733 ./prep_dataset/ILSVRC2012_val_00004163.bin 224 224 +32734 ./prep_dataset/ILSVRC2012_val_00016614.bin 224 224 +32735 ./prep_dataset/ILSVRC2012_val_00007903.bin 224 224 +32736 ./prep_dataset/ILSVRC2012_val_00046992.bin 224 224 +32737 ./prep_dataset/ILSVRC2012_val_00022479.bin 224 224 +32738 ./prep_dataset/ILSVRC2012_val_00000585.bin 224 224 +32739 ./prep_dataset/ILSVRC2012_val_00000036.bin 224 224 +32740 ./prep_dataset/ILSVRC2012_val_00026392.bin 224 224 +32741 ./prep_dataset/ILSVRC2012_val_00000046.bin 224 224 +32742 ./prep_dataset/ILSVRC2012_val_00044642.bin 224 224 +32743 ./prep_dataset/ILSVRC2012_val_00008377.bin 224 224 +32744 ./prep_dataset/ILSVRC2012_val_00029864.bin 224 224 +32745 ./prep_dataset/ILSVRC2012_val_00033754.bin 224 224 +32746 ./prep_dataset/ILSVRC2012_val_00047284.bin 224 224 +32747 ./prep_dataset/ILSVRC2012_val_00015429.bin 224 224 +32748 ./prep_dataset/ILSVRC2012_val_00035767.bin 224 224 +32749 ./prep_dataset/ILSVRC2012_val_00002956.bin 224 224 +32750 ./prep_dataset/ILSVRC2012_val_00046377.bin 224 224 +32751 ./prep_dataset/ILSVRC2012_val_00025314.bin 224 224 +32752 ./prep_dataset/ILSVRC2012_val_00005886.bin 224 224 +32753 ./prep_dataset/ILSVRC2012_val_00009617.bin 224 224 +32754 ./prep_dataset/ILSVRC2012_val_00035359.bin 224 224 +32755 ./prep_dataset/ILSVRC2012_val_00009445.bin 224 224 +32756 ./prep_dataset/ILSVRC2012_val_00023566.bin 224 224 +32757 ./prep_dataset/ILSVRC2012_val_00038600.bin 224 224 +32758 ./prep_dataset/ILSVRC2012_val_00026089.bin 224 224 +32759 ./prep_dataset/ILSVRC2012_val_00038399.bin 224 224 +32760 ./prep_dataset/ILSVRC2012_val_00017740.bin 224 224 +32761 ./prep_dataset/ILSVRC2012_val_00045661.bin 224 224 +32762 ./prep_dataset/ILSVRC2012_val_00049077.bin 224 224 +32763 ./prep_dataset/ILSVRC2012_val_00026495.bin 224 224 +32764 ./prep_dataset/ILSVRC2012_val_00031797.bin 224 224 +32765 ./prep_dataset/ILSVRC2012_val_00031404.bin 224 224 +32766 ./prep_dataset/ILSVRC2012_val_00039026.bin 224 224 +32767 ./prep_dataset/ILSVRC2012_val_00030094.bin 224 224 +32768 ./prep_dataset/ILSVRC2012_val_00037791.bin 224 224 +32769 ./prep_dataset/ILSVRC2012_val_00036957.bin 224 224 +32770 ./prep_dataset/ILSVRC2012_val_00008820.bin 224 224 +32771 ./prep_dataset/ILSVRC2012_val_00036327.bin 224 224 +32772 ./prep_dataset/ILSVRC2012_val_00021273.bin 224 224 +32773 ./prep_dataset/ILSVRC2012_val_00039574.bin 224 224 +32774 ./prep_dataset/ILSVRC2012_val_00026884.bin 224 224 +32775 ./prep_dataset/ILSVRC2012_val_00019361.bin 224 224 +32776 ./prep_dataset/ILSVRC2012_val_00007603.bin 224 224 +32777 ./prep_dataset/ILSVRC2012_val_00019923.bin 224 224 +32778 ./prep_dataset/ILSVRC2012_val_00003682.bin 224 224 +32779 ./prep_dataset/ILSVRC2012_val_00010835.bin 224 224 +32780 ./prep_dataset/ILSVRC2012_val_00031828.bin 224 224 +32781 ./prep_dataset/ILSVRC2012_val_00028795.bin 224 224 +32782 ./prep_dataset/ILSVRC2012_val_00001571.bin 224 224 +32783 ./prep_dataset/ILSVRC2012_val_00014074.bin 224 224 +32784 ./prep_dataset/ILSVRC2012_val_00012634.bin 224 224 +32785 ./prep_dataset/ILSVRC2012_val_00029276.bin 224 224 +32786 ./prep_dataset/ILSVRC2012_val_00021380.bin 224 224 +32787 ./prep_dataset/ILSVRC2012_val_00034755.bin 224 224 +32788 ./prep_dataset/ILSVRC2012_val_00040670.bin 224 224 +32789 ./prep_dataset/ILSVRC2012_val_00002642.bin 224 224 +32790 ./prep_dataset/ILSVRC2012_val_00015481.bin 224 224 +32791 ./prep_dataset/ILSVRC2012_val_00045487.bin 224 224 +32792 ./prep_dataset/ILSVRC2012_val_00047053.bin 224 224 +32793 ./prep_dataset/ILSVRC2012_val_00000003.bin 224 224 +32794 ./prep_dataset/ILSVRC2012_val_00019177.bin 224 224 +32795 ./prep_dataset/ILSVRC2012_val_00021404.bin 224 224 +32796 ./prep_dataset/ILSVRC2012_val_00031759.bin 224 224 +32797 ./prep_dataset/ILSVRC2012_val_00007550.bin 224 224 +32798 ./prep_dataset/ILSVRC2012_val_00035189.bin 224 224 +32799 ./prep_dataset/ILSVRC2012_val_00022316.bin 224 224 +32800 ./prep_dataset/ILSVRC2012_val_00043892.bin 224 224 +32801 ./prep_dataset/ILSVRC2012_val_00033702.bin 224 224 +32802 ./prep_dataset/ILSVRC2012_val_00012729.bin 224 224 +32803 ./prep_dataset/ILSVRC2012_val_00007397.bin 224 224 +32804 ./prep_dataset/ILSVRC2012_val_00034657.bin 224 224 +32805 ./prep_dataset/ILSVRC2012_val_00015656.bin 224 224 +32806 ./prep_dataset/ILSVRC2012_val_00031110.bin 224 224 +32807 ./prep_dataset/ILSVRC2012_val_00027189.bin 224 224 +32808 ./prep_dataset/ILSVRC2012_val_00044398.bin 224 224 +32809 ./prep_dataset/ILSVRC2012_val_00044481.bin 224 224 +32810 ./prep_dataset/ILSVRC2012_val_00034370.bin 224 224 +32811 ./prep_dataset/ILSVRC2012_val_00047437.bin 224 224 +32812 ./prep_dataset/ILSVRC2012_val_00007063.bin 224 224 +32813 ./prep_dataset/ILSVRC2012_val_00015972.bin 224 224 +32814 ./prep_dataset/ILSVRC2012_val_00034784.bin 224 224 +32815 ./prep_dataset/ILSVRC2012_val_00009689.bin 224 224 +32816 ./prep_dataset/ILSVRC2012_val_00049186.bin 224 224 +32817 ./prep_dataset/ILSVRC2012_val_00041899.bin 224 224 +32818 ./prep_dataset/ILSVRC2012_val_00021003.bin 224 224 +32819 ./prep_dataset/ILSVRC2012_val_00020743.bin 224 224 +32820 ./prep_dataset/ILSVRC2012_val_00038752.bin 224 224 +32821 ./prep_dataset/ILSVRC2012_val_00048266.bin 224 224 +32822 ./prep_dataset/ILSVRC2012_val_00024407.bin 224 224 +32823 ./prep_dataset/ILSVRC2012_val_00008104.bin 224 224 +32824 ./prep_dataset/ILSVRC2012_val_00013025.bin 224 224 +32825 ./prep_dataset/ILSVRC2012_val_00010961.bin 224 224 +32826 ./prep_dataset/ILSVRC2012_val_00023592.bin 224 224 +32827 ./prep_dataset/ILSVRC2012_val_00008779.bin 224 224 +32828 ./prep_dataset/ILSVRC2012_val_00006492.bin 224 224 +32829 ./prep_dataset/ILSVRC2012_val_00023620.bin 224 224 +32830 ./prep_dataset/ILSVRC2012_val_00032630.bin 224 224 +32831 ./prep_dataset/ILSVRC2012_val_00040551.bin 224 224 +32832 ./prep_dataset/ILSVRC2012_val_00043531.bin 224 224 +32833 ./prep_dataset/ILSVRC2012_val_00014506.bin 224 224 +32834 ./prep_dataset/ILSVRC2012_val_00044483.bin 224 224 +32835 ./prep_dataset/ILSVRC2012_val_00010759.bin 224 224 +32836 ./prep_dataset/ILSVRC2012_val_00035873.bin 224 224 +32837 ./prep_dataset/ILSVRC2012_val_00034088.bin 224 224 +32838 ./prep_dataset/ILSVRC2012_val_00027526.bin 224 224 +32839 ./prep_dataset/ILSVRC2012_val_00025842.bin 224 224 +32840 ./prep_dataset/ILSVRC2012_val_00046538.bin 224 224 +32841 ./prep_dataset/ILSVRC2012_val_00017569.bin 224 224 +32842 ./prep_dataset/ILSVRC2012_val_00001115.bin 224 224 +32843 ./prep_dataset/ILSVRC2012_val_00003824.bin 224 224 +32844 ./prep_dataset/ILSVRC2012_val_00015884.bin 224 224 +32845 ./prep_dataset/ILSVRC2012_val_00046494.bin 224 224 +32846 ./prep_dataset/ILSVRC2012_val_00013669.bin 224 224 +32847 ./prep_dataset/ILSVRC2012_val_00006949.bin 224 224 +32848 ./prep_dataset/ILSVRC2012_val_00020022.bin 224 224 +32849 ./prep_dataset/ILSVRC2012_val_00014001.bin 224 224 +32850 ./prep_dataset/ILSVRC2012_val_00024295.bin 224 224 +32851 ./prep_dataset/ILSVRC2012_val_00011487.bin 224 224 +32852 ./prep_dataset/ILSVRC2012_val_00022827.bin 224 224 +32853 ./prep_dataset/ILSVRC2012_val_00018208.bin 224 224 +32854 ./prep_dataset/ILSVRC2012_val_00027570.bin 224 224 +32855 ./prep_dataset/ILSVRC2012_val_00021552.bin 224 224 +32856 ./prep_dataset/ILSVRC2012_val_00045409.bin 224 224 +32857 ./prep_dataset/ILSVRC2012_val_00014409.bin 224 224 +32858 ./prep_dataset/ILSVRC2012_val_00014912.bin 224 224 +32859 ./prep_dataset/ILSVRC2012_val_00019783.bin 224 224 +32860 ./prep_dataset/ILSVRC2012_val_00043705.bin 224 224 +32861 ./prep_dataset/ILSVRC2012_val_00011719.bin 224 224 +32862 ./prep_dataset/ILSVRC2012_val_00028863.bin 224 224 +32863 ./prep_dataset/ILSVRC2012_val_00039212.bin 224 224 +32864 ./prep_dataset/ILSVRC2012_val_00041931.bin 224 224 +32865 ./prep_dataset/ILSVRC2012_val_00012773.bin 224 224 +32866 ./prep_dataset/ILSVRC2012_val_00002116.bin 224 224 +32867 ./prep_dataset/ILSVRC2012_val_00021318.bin 224 224 +32868 ./prep_dataset/ILSVRC2012_val_00041424.bin 224 224 +32869 ./prep_dataset/ILSVRC2012_val_00027196.bin 224 224 +32870 ./prep_dataset/ILSVRC2012_val_00027900.bin 224 224 +32871 ./prep_dataset/ILSVRC2012_val_00001592.bin 224 224 +32872 ./prep_dataset/ILSVRC2012_val_00014682.bin 224 224 +32873 ./prep_dataset/ILSVRC2012_val_00033772.bin 224 224 +32874 ./prep_dataset/ILSVRC2012_val_00014812.bin 224 224 +32875 ./prep_dataset/ILSVRC2012_val_00027912.bin 224 224 +32876 ./prep_dataset/ILSVRC2012_val_00043246.bin 224 224 +32877 ./prep_dataset/ILSVRC2012_val_00013015.bin 224 224 +32878 ./prep_dataset/ILSVRC2012_val_00041438.bin 224 224 +32879 ./prep_dataset/ILSVRC2012_val_00025394.bin 224 224 +32880 ./prep_dataset/ILSVRC2012_val_00039713.bin 224 224 +32881 ./prep_dataset/ILSVRC2012_val_00013839.bin 224 224 +32882 ./prep_dataset/ILSVRC2012_val_00016125.bin 224 224 +32883 ./prep_dataset/ILSVRC2012_val_00026325.bin 224 224 +32884 ./prep_dataset/ILSVRC2012_val_00012620.bin 224 224 +32885 ./prep_dataset/ILSVRC2012_val_00024380.bin 224 224 +32886 ./prep_dataset/ILSVRC2012_val_00035850.bin 224 224 +32887 ./prep_dataset/ILSVRC2012_val_00028564.bin 224 224 +32888 ./prep_dataset/ILSVRC2012_val_00004111.bin 224 224 +32889 ./prep_dataset/ILSVRC2012_val_00016770.bin 224 224 +32890 ./prep_dataset/ILSVRC2012_val_00024902.bin 224 224 +32891 ./prep_dataset/ILSVRC2012_val_00023404.bin 224 224 +32892 ./prep_dataset/ILSVRC2012_val_00020195.bin 224 224 +32893 ./prep_dataset/ILSVRC2012_val_00011627.bin 224 224 +32894 ./prep_dataset/ILSVRC2012_val_00002118.bin 224 224 +32895 ./prep_dataset/ILSVRC2012_val_00010008.bin 224 224 +32896 ./prep_dataset/ILSVRC2012_val_00004841.bin 224 224 +32897 ./prep_dataset/ILSVRC2012_val_00026714.bin 224 224 +32898 ./prep_dataset/ILSVRC2012_val_00040117.bin 224 224 +32899 ./prep_dataset/ILSVRC2012_val_00007661.bin 224 224 +32900 ./prep_dataset/ILSVRC2012_val_00047945.bin 224 224 +32901 ./prep_dataset/ILSVRC2012_val_00015054.bin 224 224 +32902 ./prep_dataset/ILSVRC2012_val_00046094.bin 224 224 +32903 ./prep_dataset/ILSVRC2012_val_00035268.bin 224 224 +32904 ./prep_dataset/ILSVRC2012_val_00041670.bin 224 224 +32905 ./prep_dataset/ILSVRC2012_val_00016688.bin 224 224 +32906 ./prep_dataset/ILSVRC2012_val_00049366.bin 224 224 +32907 ./prep_dataset/ILSVRC2012_val_00027232.bin 224 224 +32908 ./prep_dataset/ILSVRC2012_val_00042551.bin 224 224 +32909 ./prep_dataset/ILSVRC2012_val_00016108.bin 224 224 +32910 ./prep_dataset/ILSVRC2012_val_00026309.bin 224 224 +32911 ./prep_dataset/ILSVRC2012_val_00005181.bin 224 224 +32912 ./prep_dataset/ILSVRC2012_val_00000872.bin 224 224 +32913 ./prep_dataset/ILSVRC2012_val_00025576.bin 224 224 +32914 ./prep_dataset/ILSVRC2012_val_00001628.bin 224 224 +32915 ./prep_dataset/ILSVRC2012_val_00017624.bin 224 224 +32916 ./prep_dataset/ILSVRC2012_val_00020122.bin 224 224 +32917 ./prep_dataset/ILSVRC2012_val_00006772.bin 224 224 +32918 ./prep_dataset/ILSVRC2012_val_00010969.bin 224 224 +32919 ./prep_dataset/ILSVRC2012_val_00042940.bin 224 224 +32920 ./prep_dataset/ILSVRC2012_val_00004696.bin 224 224 +32921 ./prep_dataset/ILSVRC2012_val_00046808.bin 224 224 +32922 ./prep_dataset/ILSVRC2012_val_00021586.bin 224 224 +32923 ./prep_dataset/ILSVRC2012_val_00032460.bin 224 224 +32924 ./prep_dataset/ILSVRC2012_val_00007965.bin 224 224 +32925 ./prep_dataset/ILSVRC2012_val_00002419.bin 224 224 +32926 ./prep_dataset/ILSVRC2012_val_00049212.bin 224 224 +32927 ./prep_dataset/ILSVRC2012_val_00014108.bin 224 224 +32928 ./prep_dataset/ILSVRC2012_val_00035214.bin 224 224 +32929 ./prep_dataset/ILSVRC2012_val_00023639.bin 224 224 +32930 ./prep_dataset/ILSVRC2012_val_00046814.bin 224 224 +32931 ./prep_dataset/ILSVRC2012_val_00032553.bin 224 224 +32932 ./prep_dataset/ILSVRC2012_val_00018497.bin 224 224 +32933 ./prep_dataset/ILSVRC2012_val_00010643.bin 224 224 +32934 ./prep_dataset/ILSVRC2012_val_00000348.bin 224 224 +32935 ./prep_dataset/ILSVRC2012_val_00016335.bin 224 224 +32936 ./prep_dataset/ILSVRC2012_val_00001338.bin 224 224 +32937 ./prep_dataset/ILSVRC2012_val_00033789.bin 224 224 +32938 ./prep_dataset/ILSVRC2012_val_00034995.bin 224 224 +32939 ./prep_dataset/ILSVRC2012_val_00038572.bin 224 224 +32940 ./prep_dataset/ILSVRC2012_val_00024998.bin 224 224 +32941 ./prep_dataset/ILSVRC2012_val_00008063.bin 224 224 +32942 ./prep_dataset/ILSVRC2012_val_00018394.bin 224 224 +32943 ./prep_dataset/ILSVRC2012_val_00006202.bin 224 224 +32944 ./prep_dataset/ILSVRC2012_val_00048933.bin 224 224 +32945 ./prep_dataset/ILSVRC2012_val_00018343.bin 224 224 +32946 ./prep_dataset/ILSVRC2012_val_00020908.bin 224 224 +32947 ./prep_dataset/ILSVRC2012_val_00049459.bin 224 224 +32948 ./prep_dataset/ILSVRC2012_val_00003639.bin 224 224 +32949 ./prep_dataset/ILSVRC2012_val_00024567.bin 224 224 +32950 ./prep_dataset/ILSVRC2012_val_00035525.bin 224 224 +32951 ./prep_dataset/ILSVRC2012_val_00049789.bin 224 224 +32952 ./prep_dataset/ILSVRC2012_val_00040995.bin 224 224 +32953 ./prep_dataset/ILSVRC2012_val_00048146.bin 224 224 +32954 ./prep_dataset/ILSVRC2012_val_00008649.bin 224 224 +32955 ./prep_dataset/ILSVRC2012_val_00021160.bin 224 224 +32956 ./prep_dataset/ILSVRC2012_val_00045423.bin 224 224 +32957 ./prep_dataset/ILSVRC2012_val_00038692.bin 224 224 +32958 ./prep_dataset/ILSVRC2012_val_00038396.bin 224 224 +32959 ./prep_dataset/ILSVRC2012_val_00008253.bin 224 224 +32960 ./prep_dataset/ILSVRC2012_val_00031300.bin 224 224 +32961 ./prep_dataset/ILSVRC2012_val_00043167.bin 224 224 +32962 ./prep_dataset/ILSVRC2012_val_00033587.bin 224 224 +32963 ./prep_dataset/ILSVRC2012_val_00007066.bin 224 224 +32964 ./prep_dataset/ILSVRC2012_val_00019527.bin 224 224 +32965 ./prep_dataset/ILSVRC2012_val_00027167.bin 224 224 +32966 ./prep_dataset/ILSVRC2012_val_00046693.bin 224 224 +32967 ./prep_dataset/ILSVRC2012_val_00017811.bin 224 224 +32968 ./prep_dataset/ILSVRC2012_val_00038630.bin 224 224 +32969 ./prep_dataset/ILSVRC2012_val_00001846.bin 224 224 +32970 ./prep_dataset/ILSVRC2012_val_00004925.bin 224 224 +32971 ./prep_dataset/ILSVRC2012_val_00042608.bin 224 224 +32972 ./prep_dataset/ILSVRC2012_val_00044884.bin 224 224 +32973 ./prep_dataset/ILSVRC2012_val_00011811.bin 224 224 +32974 ./prep_dataset/ILSVRC2012_val_00039105.bin 224 224 +32975 ./prep_dataset/ILSVRC2012_val_00048403.bin 224 224 +32976 ./prep_dataset/ILSVRC2012_val_00002486.bin 224 224 +32977 ./prep_dataset/ILSVRC2012_val_00011592.bin 224 224 +32978 ./prep_dataset/ILSVRC2012_val_00049815.bin 224 224 +32979 ./prep_dataset/ILSVRC2012_val_00015263.bin 224 224 +32980 ./prep_dataset/ILSVRC2012_val_00029408.bin 224 224 +32981 ./prep_dataset/ILSVRC2012_val_00013078.bin 224 224 +32982 ./prep_dataset/ILSVRC2012_val_00001471.bin 224 224 +32983 ./prep_dataset/ILSVRC2012_val_00048865.bin 224 224 +32984 ./prep_dataset/ILSVRC2012_val_00034391.bin 224 224 +32985 ./prep_dataset/ILSVRC2012_val_00003545.bin 224 224 +32986 ./prep_dataset/ILSVRC2012_val_00020930.bin 224 224 +32987 ./prep_dataset/ILSVRC2012_val_00022805.bin 224 224 +32988 ./prep_dataset/ILSVRC2012_val_00012527.bin 224 224 +32989 ./prep_dataset/ILSVRC2012_val_00019348.bin 224 224 +32990 ./prep_dataset/ILSVRC2012_val_00009483.bin 224 224 +32991 ./prep_dataset/ILSVRC2012_val_00017232.bin 224 224 +32992 ./prep_dataset/ILSVRC2012_val_00024937.bin 224 224 +32993 ./prep_dataset/ILSVRC2012_val_00000053.bin 224 224 +32994 ./prep_dataset/ILSVRC2012_val_00004809.bin 224 224 +32995 ./prep_dataset/ILSVRC2012_val_00012794.bin 224 224 +32996 ./prep_dataset/ILSVRC2012_val_00048209.bin 224 224 +32997 ./prep_dataset/ILSVRC2012_val_00007876.bin 224 224 +32998 ./prep_dataset/ILSVRC2012_val_00010605.bin 224 224 +32999 ./prep_dataset/ILSVRC2012_val_00042559.bin 224 224 +33000 ./prep_dataset/ILSVRC2012_val_00001452.bin 224 224 +33001 ./prep_dataset/ILSVRC2012_val_00019790.bin 224 224 +33002 ./prep_dataset/ILSVRC2012_val_00028667.bin 224 224 +33003 ./prep_dataset/ILSVRC2012_val_00042684.bin 224 224 +33004 ./prep_dataset/ILSVRC2012_val_00030083.bin 224 224 +33005 ./prep_dataset/ILSVRC2012_val_00026647.bin 224 224 +33006 ./prep_dataset/ILSVRC2012_val_00030873.bin 224 224 +33007 ./prep_dataset/ILSVRC2012_val_00039363.bin 224 224 +33008 ./prep_dataset/ILSVRC2012_val_00029951.bin 224 224 +33009 ./prep_dataset/ILSVRC2012_val_00035792.bin 224 224 +33010 ./prep_dataset/ILSVRC2012_val_00039680.bin 224 224 +33011 ./prep_dataset/ILSVRC2012_val_00000048.bin 224 224 +33012 ./prep_dataset/ILSVRC2012_val_00039156.bin 224 224 +33013 ./prep_dataset/ILSVRC2012_val_00045203.bin 224 224 +33014 ./prep_dataset/ILSVRC2012_val_00013448.bin 224 224 +33015 ./prep_dataset/ILSVRC2012_val_00029153.bin 224 224 +33016 ./prep_dataset/ILSVRC2012_val_00048932.bin 224 224 +33017 ./prep_dataset/ILSVRC2012_val_00033157.bin 224 224 +33018 ./prep_dataset/ILSVRC2012_val_00010424.bin 224 224 +33019 ./prep_dataset/ILSVRC2012_val_00020597.bin 224 224 +33020 ./prep_dataset/ILSVRC2012_val_00021389.bin 224 224 +33021 ./prep_dataset/ILSVRC2012_val_00027256.bin 224 224 +33022 ./prep_dataset/ILSVRC2012_val_00012541.bin 224 224 +33023 ./prep_dataset/ILSVRC2012_val_00031829.bin 224 224 +33024 ./prep_dataset/ILSVRC2012_val_00038920.bin 224 224 +33025 ./prep_dataset/ILSVRC2012_val_00010870.bin 224 224 +33026 ./prep_dataset/ILSVRC2012_val_00008948.bin 224 224 +33027 ./prep_dataset/ILSVRC2012_val_00037925.bin 224 224 +33028 ./prep_dataset/ILSVRC2012_val_00000125.bin 224 224 +33029 ./prep_dataset/ILSVRC2012_val_00033688.bin 224 224 +33030 ./prep_dataset/ILSVRC2012_val_00004246.bin 224 224 +33031 ./prep_dataset/ILSVRC2012_val_00029511.bin 224 224 +33032 ./prep_dataset/ILSVRC2012_val_00047099.bin 224 224 +33033 ./prep_dataset/ILSVRC2012_val_00021143.bin 224 224 +33034 ./prep_dataset/ILSVRC2012_val_00019318.bin 224 224 +33035 ./prep_dataset/ILSVRC2012_val_00013809.bin 224 224 +33036 ./prep_dataset/ILSVRC2012_val_00023503.bin 224 224 +33037 ./prep_dataset/ILSVRC2012_val_00004892.bin 224 224 +33038 ./prep_dataset/ILSVRC2012_val_00049833.bin 224 224 +33039 ./prep_dataset/ILSVRC2012_val_00010740.bin 224 224 +33040 ./prep_dataset/ILSVRC2012_val_00028833.bin 224 224 +33041 ./prep_dataset/ILSVRC2012_val_00009656.bin 224 224 +33042 ./prep_dataset/ILSVRC2012_val_00003768.bin 224 224 +33043 ./prep_dataset/ILSVRC2012_val_00028292.bin 224 224 +33044 ./prep_dataset/ILSVRC2012_val_00042197.bin 224 224 +33045 ./prep_dataset/ILSVRC2012_val_00048824.bin 224 224 +33046 ./prep_dataset/ILSVRC2012_val_00014811.bin 224 224 +33047 ./prep_dataset/ILSVRC2012_val_00008122.bin 224 224 +33048 ./prep_dataset/ILSVRC2012_val_00049177.bin 224 224 +33049 ./prep_dataset/ILSVRC2012_val_00019133.bin 224 224 +33050 ./prep_dataset/ILSVRC2012_val_00047888.bin 224 224 +33051 ./prep_dataset/ILSVRC2012_val_00021285.bin 224 224 +33052 ./prep_dataset/ILSVRC2012_val_00002370.bin 224 224 +33053 ./prep_dataset/ILSVRC2012_val_00020121.bin 224 224 +33054 ./prep_dataset/ILSVRC2012_val_00021823.bin 224 224 +33055 ./prep_dataset/ILSVRC2012_val_00017268.bin 224 224 +33056 ./prep_dataset/ILSVRC2012_val_00001731.bin 224 224 +33057 ./prep_dataset/ILSVRC2012_val_00045877.bin 224 224 +33058 ./prep_dataset/ILSVRC2012_val_00024707.bin 224 224 +33059 ./prep_dataset/ILSVRC2012_val_00015981.bin 224 224 +33060 ./prep_dataset/ILSVRC2012_val_00039379.bin 224 224 +33061 ./prep_dataset/ILSVRC2012_val_00044318.bin 224 224 +33062 ./prep_dataset/ILSVRC2012_val_00010589.bin 224 224 +33063 ./prep_dataset/ILSVRC2012_val_00016841.bin 224 224 +33064 ./prep_dataset/ILSVRC2012_val_00037537.bin 224 224 +33065 ./prep_dataset/ILSVRC2012_val_00031159.bin 224 224 +33066 ./prep_dataset/ILSVRC2012_val_00012147.bin 224 224 +33067 ./prep_dataset/ILSVRC2012_val_00041280.bin 224 224 +33068 ./prep_dataset/ILSVRC2012_val_00025541.bin 224 224 +33069 ./prep_dataset/ILSVRC2012_val_00037219.bin 224 224 +33070 ./prep_dataset/ILSVRC2012_val_00000761.bin 224 224 +33071 ./prep_dataset/ILSVRC2012_val_00000664.bin 224 224 +33072 ./prep_dataset/ILSVRC2012_val_00040095.bin 224 224 +33073 ./prep_dataset/ILSVRC2012_val_00006936.bin 224 224 +33074 ./prep_dataset/ILSVRC2012_val_00033416.bin 224 224 +33075 ./prep_dataset/ILSVRC2012_val_00024257.bin 224 224 +33076 ./prep_dataset/ILSVRC2012_val_00034162.bin 224 224 +33077 ./prep_dataset/ILSVRC2012_val_00022388.bin 224 224 +33078 ./prep_dataset/ILSVRC2012_val_00029453.bin 224 224 +33079 ./prep_dataset/ILSVRC2012_val_00030632.bin 224 224 +33080 ./prep_dataset/ILSVRC2012_val_00045029.bin 224 224 +33081 ./prep_dataset/ILSVRC2012_val_00048979.bin 224 224 +33082 ./prep_dataset/ILSVRC2012_val_00007188.bin 224 224 +33083 ./prep_dataset/ILSVRC2012_val_00010540.bin 224 224 +33084 ./prep_dataset/ILSVRC2012_val_00045564.bin 224 224 +33085 ./prep_dataset/ILSVRC2012_val_00004990.bin 224 224 +33086 ./prep_dataset/ILSVRC2012_val_00001108.bin 224 224 +33087 ./prep_dataset/ILSVRC2012_val_00014693.bin 224 224 +33088 ./prep_dataset/ILSVRC2012_val_00041112.bin 224 224 +33089 ./prep_dataset/ILSVRC2012_val_00012460.bin 224 224 +33090 ./prep_dataset/ILSVRC2012_val_00022010.bin 224 224 +33091 ./prep_dataset/ILSVRC2012_val_00019734.bin 224 224 +33092 ./prep_dataset/ILSVRC2012_val_00040468.bin 224 224 +33093 ./prep_dataset/ILSVRC2012_val_00011366.bin 224 224 +33094 ./prep_dataset/ILSVRC2012_val_00000017.bin 224 224 +33095 ./prep_dataset/ILSVRC2012_val_00043172.bin 224 224 +33096 ./prep_dataset/ILSVRC2012_val_00023357.bin 224 224 +33097 ./prep_dataset/ILSVRC2012_val_00038009.bin 224 224 +33098 ./prep_dataset/ILSVRC2012_val_00035434.bin 224 224 +33099 ./prep_dataset/ILSVRC2012_val_00000278.bin 224 224 +33100 ./prep_dataset/ILSVRC2012_val_00031016.bin 224 224 +33101 ./prep_dataset/ILSVRC2012_val_00021547.bin 224 224 +33102 ./prep_dataset/ILSVRC2012_val_00036899.bin 224 224 +33103 ./prep_dataset/ILSVRC2012_val_00049949.bin 224 224 +33104 ./prep_dataset/ILSVRC2012_val_00030933.bin 224 224 +33105 ./prep_dataset/ILSVRC2012_val_00039975.bin 224 224 +33106 ./prep_dataset/ILSVRC2012_val_00032009.bin 224 224 +33107 ./prep_dataset/ILSVRC2012_val_00009255.bin 224 224 +33108 ./prep_dataset/ILSVRC2012_val_00002218.bin 224 224 +33109 ./prep_dataset/ILSVRC2012_val_00043322.bin 224 224 +33110 ./prep_dataset/ILSVRC2012_val_00000488.bin 224 224 +33111 ./prep_dataset/ILSVRC2012_val_00007229.bin 224 224 +33112 ./prep_dataset/ILSVRC2012_val_00023376.bin 224 224 +33113 ./prep_dataset/ILSVRC2012_val_00023438.bin 224 224 +33114 ./prep_dataset/ILSVRC2012_val_00020070.bin 224 224 +33115 ./prep_dataset/ILSVRC2012_val_00047420.bin 224 224 +33116 ./prep_dataset/ILSVRC2012_val_00045401.bin 224 224 +33117 ./prep_dataset/ILSVRC2012_val_00023328.bin 224 224 +33118 ./prep_dataset/ILSVRC2012_val_00044819.bin 224 224 +33119 ./prep_dataset/ILSVRC2012_val_00001318.bin 224 224 +33120 ./prep_dataset/ILSVRC2012_val_00037420.bin 224 224 +33121 ./prep_dataset/ILSVRC2012_val_00000027.bin 224 224 +33122 ./prep_dataset/ILSVRC2012_val_00049207.bin 224 224 +33123 ./prep_dataset/ILSVRC2012_val_00049066.bin 224 224 +33124 ./prep_dataset/ILSVRC2012_val_00041979.bin 224 224 +33125 ./prep_dataset/ILSVRC2012_val_00040856.bin 224 224 +33126 ./prep_dataset/ILSVRC2012_val_00040361.bin 224 224 +33127 ./prep_dataset/ILSVRC2012_val_00034333.bin 224 224 +33128 ./prep_dataset/ILSVRC2012_val_00003520.bin 224 224 +33129 ./prep_dataset/ILSVRC2012_val_00019519.bin 224 224 +33130 ./prep_dataset/ILSVRC2012_val_00031046.bin 224 224 +33131 ./prep_dataset/ILSVRC2012_val_00001669.bin 224 224 +33132 ./prep_dataset/ILSVRC2012_val_00027737.bin 224 224 +33133 ./prep_dataset/ILSVRC2012_val_00004998.bin 224 224 +33134 ./prep_dataset/ILSVRC2012_val_00002050.bin 224 224 +33135 ./prep_dataset/ILSVRC2012_val_00031025.bin 224 224 +33136 ./prep_dataset/ILSVRC2012_val_00010836.bin 224 224 +33137 ./prep_dataset/ILSVRC2012_val_00044297.bin 224 224 +33138 ./prep_dataset/ILSVRC2012_val_00020047.bin 224 224 +33139 ./prep_dataset/ILSVRC2012_val_00036551.bin 224 224 +33140 ./prep_dataset/ILSVRC2012_val_00047947.bin 224 224 +33141 ./prep_dataset/ILSVRC2012_val_00008471.bin 224 224 +33142 ./prep_dataset/ILSVRC2012_val_00033799.bin 224 224 +33143 ./prep_dataset/ILSVRC2012_val_00030639.bin 224 224 +33144 ./prep_dataset/ILSVRC2012_val_00045369.bin 224 224 +33145 ./prep_dataset/ILSVRC2012_val_00013707.bin 224 224 +33146 ./prep_dataset/ILSVRC2012_val_00010063.bin 224 224 +33147 ./prep_dataset/ILSVRC2012_val_00039422.bin 224 224 +33148 ./prep_dataset/ILSVRC2012_val_00047652.bin 224 224 +33149 ./prep_dataset/ILSVRC2012_val_00046435.bin 224 224 +33150 ./prep_dataset/ILSVRC2012_val_00019641.bin 224 224 +33151 ./prep_dataset/ILSVRC2012_val_00028697.bin 224 224 +33152 ./prep_dataset/ILSVRC2012_val_00031294.bin 224 224 +33153 ./prep_dataset/ILSVRC2012_val_00046563.bin 224 224 +33154 ./prep_dataset/ILSVRC2012_val_00005149.bin 224 224 +33155 ./prep_dataset/ILSVRC2012_val_00006840.bin 224 224 +33156 ./prep_dataset/ILSVRC2012_val_00038677.bin 224 224 +33157 ./prep_dataset/ILSVRC2012_val_00044091.bin 224 224 +33158 ./prep_dataset/ILSVRC2012_val_00005758.bin 224 224 +33159 ./prep_dataset/ILSVRC2012_val_00003541.bin 224 224 +33160 ./prep_dataset/ILSVRC2012_val_00013423.bin 224 224 +33161 ./prep_dataset/ILSVRC2012_val_00043209.bin 224 224 +33162 ./prep_dataset/ILSVRC2012_val_00029174.bin 224 224 +33163 ./prep_dataset/ILSVRC2012_val_00027028.bin 224 224 +33164 ./prep_dataset/ILSVRC2012_val_00036068.bin 224 224 +33165 ./prep_dataset/ILSVRC2012_val_00035549.bin 224 224 +33166 ./prep_dataset/ILSVRC2012_val_00023808.bin 224 224 +33167 ./prep_dataset/ILSVRC2012_val_00021241.bin 224 224 +33168 ./prep_dataset/ILSVRC2012_val_00029079.bin 224 224 +33169 ./prep_dataset/ILSVRC2012_val_00028809.bin 224 224 +33170 ./prep_dataset/ILSVRC2012_val_00030430.bin 224 224 +33171 ./prep_dataset/ILSVRC2012_val_00033365.bin 224 224 +33172 ./prep_dataset/ILSVRC2012_val_00020703.bin 224 224 +33173 ./prep_dataset/ILSVRC2012_val_00029448.bin 224 224 +33174 ./prep_dataset/ILSVRC2012_val_00031622.bin 224 224 +33175 ./prep_dataset/ILSVRC2012_val_00012405.bin 224 224 +33176 ./prep_dataset/ILSVRC2012_val_00029671.bin 224 224 +33177 ./prep_dataset/ILSVRC2012_val_00020711.bin 224 224 +33178 ./prep_dataset/ILSVRC2012_val_00009351.bin 224 224 +33179 ./prep_dataset/ILSVRC2012_val_00033427.bin 224 224 +33180 ./prep_dataset/ILSVRC2012_val_00029783.bin 224 224 +33181 ./prep_dataset/ILSVRC2012_val_00048176.bin 224 224 +33182 ./prep_dataset/ILSVRC2012_val_00030399.bin 224 224 +33183 ./prep_dataset/ILSVRC2012_val_00006649.bin 224 224 +33184 ./prep_dataset/ILSVRC2012_val_00039969.bin 224 224 +33185 ./prep_dataset/ILSVRC2012_val_00041442.bin 224 224 +33186 ./prep_dataset/ILSVRC2012_val_00047354.bin 224 224 +33187 ./prep_dataset/ILSVRC2012_val_00042570.bin 224 224 +33188 ./prep_dataset/ILSVRC2012_val_00012738.bin 224 224 +33189 ./prep_dataset/ILSVRC2012_val_00045327.bin 224 224 +33190 ./prep_dataset/ILSVRC2012_val_00029570.bin 224 224 +33191 ./prep_dataset/ILSVRC2012_val_00008366.bin 224 224 +33192 ./prep_dataset/ILSVRC2012_val_00001964.bin 224 224 +33193 ./prep_dataset/ILSVRC2012_val_00008790.bin 224 224 +33194 ./prep_dataset/ILSVRC2012_val_00001500.bin 224 224 +33195 ./prep_dataset/ILSVRC2012_val_00031425.bin 224 224 +33196 ./prep_dataset/ILSVRC2012_val_00041299.bin 224 224 +33197 ./prep_dataset/ILSVRC2012_val_00011902.bin 224 224 +33198 ./prep_dataset/ILSVRC2012_val_00030730.bin 224 224 +33199 ./prep_dataset/ILSVRC2012_val_00039666.bin 224 224 +33200 ./prep_dataset/ILSVRC2012_val_00034198.bin 224 224 +33201 ./prep_dataset/ILSVRC2012_val_00034637.bin 224 224 +33202 ./prep_dataset/ILSVRC2012_val_00023408.bin 224 224 +33203 ./prep_dataset/ILSVRC2012_val_00013007.bin 224 224 +33204 ./prep_dataset/ILSVRC2012_val_00035996.bin 224 224 +33205 ./prep_dataset/ILSVRC2012_val_00035974.bin 224 224 +33206 ./prep_dataset/ILSVRC2012_val_00006016.bin 224 224 +33207 ./prep_dataset/ILSVRC2012_val_00017976.bin 224 224 +33208 ./prep_dataset/ILSVRC2012_val_00044441.bin 224 224 +33209 ./prep_dataset/ILSVRC2012_val_00010698.bin 224 224 +33210 ./prep_dataset/ILSVRC2012_val_00026475.bin 224 224 +33211 ./prep_dataset/ILSVRC2012_val_00004654.bin 224 224 +33212 ./prep_dataset/ILSVRC2012_val_00005935.bin 224 224 +33213 ./prep_dataset/ILSVRC2012_val_00007948.bin 224 224 +33214 ./prep_dataset/ILSVRC2012_val_00019737.bin 224 224 +33215 ./prep_dataset/ILSVRC2012_val_00010927.bin 224 224 +33216 ./prep_dataset/ILSVRC2012_val_00007426.bin 224 224 +33217 ./prep_dataset/ILSVRC2012_val_00033008.bin 224 224 +33218 ./prep_dataset/ILSVRC2012_val_00012158.bin 224 224 +33219 ./prep_dataset/ILSVRC2012_val_00010912.bin 224 224 +33220 ./prep_dataset/ILSVRC2012_val_00006845.bin 224 224 +33221 ./prep_dataset/ILSVRC2012_val_00041062.bin 224 224 +33222 ./prep_dataset/ILSVRC2012_val_00010957.bin 224 224 +33223 ./prep_dataset/ILSVRC2012_val_00005876.bin 224 224 +33224 ./prep_dataset/ILSVRC2012_val_00048434.bin 224 224 +33225 ./prep_dataset/ILSVRC2012_val_00013185.bin 224 224 +33226 ./prep_dataset/ILSVRC2012_val_00029472.bin 224 224 +33227 ./prep_dataset/ILSVRC2012_val_00030288.bin 224 224 +33228 ./prep_dataset/ILSVRC2012_val_00006946.bin 224 224 +33229 ./prep_dataset/ILSVRC2012_val_00036096.bin 224 224 +33230 ./prep_dataset/ILSVRC2012_val_00039898.bin 224 224 +33231 ./prep_dataset/ILSVRC2012_val_00049633.bin 224 224 +33232 ./prep_dataset/ILSVRC2012_val_00007694.bin 224 224 +33233 ./prep_dataset/ILSVRC2012_val_00048115.bin 224 224 +33234 ./prep_dataset/ILSVRC2012_val_00032363.bin 224 224 +33235 ./prep_dataset/ILSVRC2012_val_00019078.bin 224 224 +33236 ./prep_dataset/ILSVRC2012_val_00047507.bin 224 224 +33237 ./prep_dataset/ILSVRC2012_val_00020396.bin 224 224 +33238 ./prep_dataset/ILSVRC2012_val_00030591.bin 224 224 +33239 ./prep_dataset/ILSVRC2012_val_00009684.bin 224 224 +33240 ./prep_dataset/ILSVRC2012_val_00010626.bin 224 224 +33241 ./prep_dataset/ILSVRC2012_val_00011809.bin 224 224 +33242 ./prep_dataset/ILSVRC2012_val_00039854.bin 224 224 +33243 ./prep_dataset/ILSVRC2012_val_00035180.bin 224 224 +33244 ./prep_dataset/ILSVRC2012_val_00002930.bin 224 224 +33245 ./prep_dataset/ILSVRC2012_val_00010271.bin 224 224 +33246 ./prep_dataset/ILSVRC2012_val_00011358.bin 224 224 +33247 ./prep_dataset/ILSVRC2012_val_00022933.bin 224 224 +33248 ./prep_dataset/ILSVRC2012_val_00022203.bin 224 224 +33249 ./prep_dataset/ILSVRC2012_val_00000911.bin 224 224 +33250 ./prep_dataset/ILSVRC2012_val_00047179.bin 224 224 +33251 ./prep_dataset/ILSVRC2012_val_00016117.bin 224 224 +33252 ./prep_dataset/ILSVRC2012_val_00000419.bin 224 224 +33253 ./prep_dataset/ILSVRC2012_val_00023902.bin 224 224 +33254 ./prep_dataset/ILSVRC2012_val_00030303.bin 224 224 +33255 ./prep_dataset/ILSVRC2012_val_00036241.bin 224 224 +33256 ./prep_dataset/ILSVRC2012_val_00047555.bin 224 224 +33257 ./prep_dataset/ILSVRC2012_val_00049683.bin 224 224 +33258 ./prep_dataset/ILSVRC2012_val_00044137.bin 224 224 +33259 ./prep_dataset/ILSVRC2012_val_00020016.bin 224 224 +33260 ./prep_dataset/ILSVRC2012_val_00031523.bin 224 224 +33261 ./prep_dataset/ILSVRC2012_val_00025520.bin 224 224 +33262 ./prep_dataset/ILSVRC2012_val_00000533.bin 224 224 +33263 ./prep_dataset/ILSVRC2012_val_00004999.bin 224 224 +33264 ./prep_dataset/ILSVRC2012_val_00041708.bin 224 224 +33265 ./prep_dataset/ILSVRC2012_val_00045881.bin 224 224 +33266 ./prep_dataset/ILSVRC2012_val_00007703.bin 224 224 +33267 ./prep_dataset/ILSVRC2012_val_00040711.bin 224 224 +33268 ./prep_dataset/ILSVRC2012_val_00016352.bin 224 224 +33269 ./prep_dataset/ILSVRC2012_val_00029928.bin 224 224 +33270 ./prep_dataset/ILSVRC2012_val_00045635.bin 224 224 +33271 ./prep_dataset/ILSVRC2012_val_00031472.bin 224 224 +33272 ./prep_dataset/ILSVRC2012_val_00008327.bin 224 224 +33273 ./prep_dataset/ILSVRC2012_val_00045754.bin 224 224 +33274 ./prep_dataset/ILSVRC2012_val_00001390.bin 224 224 +33275 ./prep_dataset/ILSVRC2012_val_00018544.bin 224 224 +33276 ./prep_dataset/ILSVRC2012_val_00008168.bin 224 224 +33277 ./prep_dataset/ILSVRC2012_val_00013477.bin 224 224 +33278 ./prep_dataset/ILSVRC2012_val_00015308.bin 224 224 +33279 ./prep_dataset/ILSVRC2012_val_00021917.bin 224 224 +33280 ./prep_dataset/ILSVRC2012_val_00036968.bin 224 224 +33281 ./prep_dataset/ILSVRC2012_val_00036356.bin 224 224 +33282 ./prep_dataset/ILSVRC2012_val_00001385.bin 224 224 +33283 ./prep_dataset/ILSVRC2012_val_00038895.bin 224 224 +33284 ./prep_dataset/ILSVRC2012_val_00025651.bin 224 224 +33285 ./prep_dataset/ILSVRC2012_val_00045342.bin 224 224 +33286 ./prep_dataset/ILSVRC2012_val_00006830.bin 224 224 +33287 ./prep_dataset/ILSVRC2012_val_00046581.bin 224 224 +33288 ./prep_dataset/ILSVRC2012_val_00045324.bin 224 224 +33289 ./prep_dataset/ILSVRC2012_val_00045188.bin 224 224 +33290 ./prep_dataset/ILSVRC2012_val_00032163.bin 224 224 +33291 ./prep_dataset/ILSVRC2012_val_00047671.bin 224 224 +33292 ./prep_dataset/ILSVRC2012_val_00013967.bin 224 224 +33293 ./prep_dataset/ILSVRC2012_val_00022315.bin 224 224 +33294 ./prep_dataset/ILSVRC2012_val_00040949.bin 224 224 +33295 ./prep_dataset/ILSVRC2012_val_00043170.bin 224 224 +33296 ./prep_dataset/ILSVRC2012_val_00035770.bin 224 224 +33297 ./prep_dataset/ILSVRC2012_val_00043453.bin 224 224 +33298 ./prep_dataset/ILSVRC2012_val_00005735.bin 224 224 +33299 ./prep_dataset/ILSVRC2012_val_00041463.bin 224 224 +33300 ./prep_dataset/ILSVRC2012_val_00040988.bin 224 224 +33301 ./prep_dataset/ILSVRC2012_val_00011181.bin 224 224 +33302 ./prep_dataset/ILSVRC2012_val_00010156.bin 224 224 +33303 ./prep_dataset/ILSVRC2012_val_00019733.bin 224 224 +33304 ./prep_dataset/ILSVRC2012_val_00039728.bin 224 224 +33305 ./prep_dataset/ILSVRC2012_val_00002425.bin 224 224 +33306 ./prep_dataset/ILSVRC2012_val_00016103.bin 224 224 +33307 ./prep_dataset/ILSVRC2012_val_00012337.bin 224 224 +33308 ./prep_dataset/ILSVRC2012_val_00025993.bin 224 224 +33309 ./prep_dataset/ILSVRC2012_val_00005428.bin 224 224 +33310 ./prep_dataset/ILSVRC2012_val_00025771.bin 224 224 +33311 ./prep_dataset/ILSVRC2012_val_00031204.bin 224 224 +33312 ./prep_dataset/ILSVRC2012_val_00044096.bin 224 224 +33313 ./prep_dataset/ILSVRC2012_val_00044758.bin 224 224 +33314 ./prep_dataset/ILSVRC2012_val_00007192.bin 224 224 +33315 ./prep_dataset/ILSVRC2012_val_00019143.bin 224 224 +33316 ./prep_dataset/ILSVRC2012_val_00027253.bin 224 224 +33317 ./prep_dataset/ILSVRC2012_val_00017895.bin 224 224 +33318 ./prep_dataset/ILSVRC2012_val_00022645.bin 224 224 +33319 ./prep_dataset/ILSVRC2012_val_00047700.bin 224 224 +33320 ./prep_dataset/ILSVRC2012_val_00018375.bin 224 224 +33321 ./prep_dataset/ILSVRC2012_val_00026727.bin 224 224 +33322 ./prep_dataset/ILSVRC2012_val_00048843.bin 224 224 +33323 ./prep_dataset/ILSVRC2012_val_00024344.bin 224 224 +33324 ./prep_dataset/ILSVRC2012_val_00035486.bin 224 224 +33325 ./prep_dataset/ILSVRC2012_val_00000965.bin 224 224 +33326 ./prep_dataset/ILSVRC2012_val_00024978.bin 224 224 +33327 ./prep_dataset/ILSVRC2012_val_00018703.bin 224 224 +33328 ./prep_dataset/ILSVRC2012_val_00035510.bin 224 224 +33329 ./prep_dataset/ILSVRC2012_val_00048494.bin 224 224 +33330 ./prep_dataset/ILSVRC2012_val_00029118.bin 224 224 +33331 ./prep_dataset/ILSVRC2012_val_00007366.bin 224 224 +33332 ./prep_dataset/ILSVRC2012_val_00043604.bin 224 224 +33333 ./prep_dataset/ILSVRC2012_val_00045177.bin 224 224 +33334 ./prep_dataset/ILSVRC2012_val_00038715.bin 224 224 +33335 ./prep_dataset/ILSVRC2012_val_00040721.bin 224 224 +33336 ./prep_dataset/ILSVRC2012_val_00018641.bin 224 224 +33337 ./prep_dataset/ILSVRC2012_val_00044528.bin 224 224 +33338 ./prep_dataset/ILSVRC2012_val_00007201.bin 224 224 +33339 ./prep_dataset/ILSVRC2012_val_00048621.bin 224 224 +33340 ./prep_dataset/ILSVRC2012_val_00034952.bin 224 224 +33341 ./prep_dataset/ILSVRC2012_val_00015742.bin 224 224 +33342 ./prep_dataset/ILSVRC2012_val_00007028.bin 224 224 +33343 ./prep_dataset/ILSVRC2012_val_00032832.bin 224 224 +33344 ./prep_dataset/ILSVRC2012_val_00046921.bin 224 224 +33345 ./prep_dataset/ILSVRC2012_val_00026334.bin 224 224 +33346 ./prep_dataset/ILSVRC2012_val_00002012.bin 224 224 +33347 ./prep_dataset/ILSVRC2012_val_00021752.bin 224 224 +33348 ./prep_dataset/ILSVRC2012_val_00004679.bin 224 224 +33349 ./prep_dataset/ILSVRC2012_val_00047106.bin 224 224 +33350 ./prep_dataset/ILSVRC2012_val_00039254.bin 224 224 +33351 ./prep_dataset/ILSVRC2012_val_00006076.bin 224 224 +33352 ./prep_dataset/ILSVRC2012_val_00030660.bin 224 224 +33353 ./prep_dataset/ILSVRC2012_val_00017993.bin 224 224 +33354 ./prep_dataset/ILSVRC2012_val_00016849.bin 224 224 +33355 ./prep_dataset/ILSVRC2012_val_00028518.bin 224 224 +33356 ./prep_dataset/ILSVRC2012_val_00047143.bin 224 224 +33357 ./prep_dataset/ILSVRC2012_val_00028864.bin 224 224 +33358 ./prep_dataset/ILSVRC2012_val_00014189.bin 224 224 +33359 ./prep_dataset/ILSVRC2012_val_00004869.bin 224 224 +33360 ./prep_dataset/ILSVRC2012_val_00020333.bin 224 224 +33361 ./prep_dataset/ILSVRC2012_val_00011686.bin 224 224 +33362 ./prep_dataset/ILSVRC2012_val_00031407.bin 224 224 +33363 ./prep_dataset/ILSVRC2012_val_00019646.bin 224 224 +33364 ./prep_dataset/ILSVRC2012_val_00009752.bin 224 224 +33365 ./prep_dataset/ILSVRC2012_val_00031664.bin 224 224 +33366 ./prep_dataset/ILSVRC2012_val_00002601.bin 224 224 +33367 ./prep_dataset/ILSVRC2012_val_00002259.bin 224 224 +33368 ./prep_dataset/ILSVRC2012_val_00032933.bin 224 224 +33369 ./prep_dataset/ILSVRC2012_val_00028249.bin 224 224 +33370 ./prep_dataset/ILSVRC2012_val_00027239.bin 224 224 +33371 ./prep_dataset/ILSVRC2012_val_00020722.bin 224 224 +33372 ./prep_dataset/ILSVRC2012_val_00041255.bin 224 224 +33373 ./prep_dataset/ILSVRC2012_val_00025016.bin 224 224 +33374 ./prep_dataset/ILSVRC2012_val_00007398.bin 224 224 +33375 ./prep_dataset/ILSVRC2012_val_00045140.bin 224 224 +33376 ./prep_dataset/ILSVRC2012_val_00010743.bin 224 224 +33377 ./prep_dataset/ILSVRC2012_val_00017812.bin 224 224 +33378 ./prep_dataset/ILSVRC2012_val_00046562.bin 224 224 +33379 ./prep_dataset/ILSVRC2012_val_00015323.bin 224 224 +33380 ./prep_dataset/ILSVRC2012_val_00041892.bin 224 224 +33381 ./prep_dataset/ILSVRC2012_val_00043382.bin 224 224 +33382 ./prep_dataset/ILSVRC2012_val_00003638.bin 224 224 +33383 ./prep_dataset/ILSVRC2012_val_00028773.bin 224 224 +33384 ./prep_dataset/ILSVRC2012_val_00027008.bin 224 224 +33385 ./prep_dataset/ILSVRC2012_val_00027805.bin 224 224 +33386 ./prep_dataset/ILSVRC2012_val_00002969.bin 224 224 +33387 ./prep_dataset/ILSVRC2012_val_00036513.bin 224 224 +33388 ./prep_dataset/ILSVRC2012_val_00046889.bin 224 224 +33389 ./prep_dataset/ILSVRC2012_val_00025459.bin 224 224 +33390 ./prep_dataset/ILSVRC2012_val_00006199.bin 224 224 +33391 ./prep_dataset/ILSVRC2012_val_00028421.bin 224 224 +33392 ./prep_dataset/ILSVRC2012_val_00002997.bin 224 224 +33393 ./prep_dataset/ILSVRC2012_val_00014821.bin 224 224 +33394 ./prep_dataset/ILSVRC2012_val_00034158.bin 224 224 +33395 ./prep_dataset/ILSVRC2012_val_00033697.bin 224 224 +33396 ./prep_dataset/ILSVRC2012_val_00038361.bin 224 224 +33397 ./prep_dataset/ILSVRC2012_val_00018463.bin 224 224 +33398 ./prep_dataset/ILSVRC2012_val_00007172.bin 224 224 +33399 ./prep_dataset/ILSVRC2012_val_00043793.bin 224 224 +33400 ./prep_dataset/ILSVRC2012_val_00003066.bin 224 224 +33401 ./prep_dataset/ILSVRC2012_val_00035845.bin 224 224 +33402 ./prep_dataset/ILSVRC2012_val_00007265.bin 224 224 +33403 ./prep_dataset/ILSVRC2012_val_00041617.bin 224 224 +33404 ./prep_dataset/ILSVRC2012_val_00041372.bin 224 224 +33405 ./prep_dataset/ILSVRC2012_val_00000919.bin 224 224 +33406 ./prep_dataset/ILSVRC2012_val_00018627.bin 224 224 +33407 ./prep_dataset/ILSVRC2012_val_00013387.bin 224 224 +33408 ./prep_dataset/ILSVRC2012_val_00005922.bin 224 224 +33409 ./prep_dataset/ILSVRC2012_val_00022941.bin 224 224 +33410 ./prep_dataset/ILSVRC2012_val_00038242.bin 224 224 +33411 ./prep_dataset/ILSVRC2012_val_00035863.bin 224 224 +33412 ./prep_dataset/ILSVRC2012_val_00034643.bin 224 224 +33413 ./prep_dataset/ILSVRC2012_val_00038388.bin 224 224 +33414 ./prep_dataset/ILSVRC2012_val_00047688.bin 224 224 +33415 ./prep_dataset/ILSVRC2012_val_00018107.bin 224 224 +33416 ./prep_dataset/ILSVRC2012_val_00013195.bin 224 224 +33417 ./prep_dataset/ILSVRC2012_val_00047814.bin 224 224 +33418 ./prep_dataset/ILSVRC2012_val_00030362.bin 224 224 +33419 ./prep_dataset/ILSVRC2012_val_00042297.bin 224 224 +33420 ./prep_dataset/ILSVRC2012_val_00030173.bin 224 224 +33421 ./prep_dataset/ILSVRC2012_val_00022142.bin 224 224 +33422 ./prep_dataset/ILSVRC2012_val_00029386.bin 224 224 +33423 ./prep_dataset/ILSVRC2012_val_00021867.bin 224 224 +33424 ./prep_dataset/ILSVRC2012_val_00036336.bin 224 224 +33425 ./prep_dataset/ILSVRC2012_val_00045126.bin 224 224 +33426 ./prep_dataset/ILSVRC2012_val_00016909.bin 224 224 +33427 ./prep_dataset/ILSVRC2012_val_00009476.bin 224 224 +33428 ./prep_dataset/ILSVRC2012_val_00033043.bin 224 224 +33429 ./prep_dataset/ILSVRC2012_val_00038350.bin 224 224 +33430 ./prep_dataset/ILSVRC2012_val_00046655.bin 224 224 +33431 ./prep_dataset/ILSVRC2012_val_00007400.bin 224 224 +33432 ./prep_dataset/ILSVRC2012_val_00025122.bin 224 224 +33433 ./prep_dataset/ILSVRC2012_val_00012054.bin 224 224 +33434 ./prep_dataset/ILSVRC2012_val_00026027.bin 224 224 +33435 ./prep_dataset/ILSVRC2012_val_00005413.bin 224 224 +33436 ./prep_dataset/ILSVRC2012_val_00004097.bin 224 224 +33437 ./prep_dataset/ILSVRC2012_val_00040406.bin 224 224 +33438 ./prep_dataset/ILSVRC2012_val_00048050.bin 224 224 +33439 ./prep_dataset/ILSVRC2012_val_00048934.bin 224 224 +33440 ./prep_dataset/ILSVRC2012_val_00024330.bin 224 224 +33441 ./prep_dataset/ILSVRC2012_val_00035315.bin 224 224 +33442 ./prep_dataset/ILSVRC2012_val_00043426.bin 224 224 +33443 ./prep_dataset/ILSVRC2012_val_00018371.bin 224 224 +33444 ./prep_dataset/ILSVRC2012_val_00022621.bin 224 224 +33445 ./prep_dataset/ILSVRC2012_val_00011101.bin 224 224 +33446 ./prep_dataset/ILSVRC2012_val_00010604.bin 224 224 +33447 ./prep_dataset/ILSVRC2012_val_00024202.bin 224 224 +33448 ./prep_dataset/ILSVRC2012_val_00008965.bin 224 224 +33449 ./prep_dataset/ILSVRC2012_val_00011477.bin 224 224 +33450 ./prep_dataset/ILSVRC2012_val_00006318.bin 224 224 +33451 ./prep_dataset/ILSVRC2012_val_00021578.bin 224 224 +33452 ./prep_dataset/ILSVRC2012_val_00006658.bin 224 224 +33453 ./prep_dataset/ILSVRC2012_val_00041414.bin 224 224 +33454 ./prep_dataset/ILSVRC2012_val_00029056.bin 224 224 +33455 ./prep_dataset/ILSVRC2012_val_00015316.bin 224 224 +33456 ./prep_dataset/ILSVRC2012_val_00017664.bin 224 224 +33457 ./prep_dataset/ILSVRC2012_val_00049548.bin 224 224 +33458 ./prep_dataset/ILSVRC2012_val_00025497.bin 224 224 +33459 ./prep_dataset/ILSVRC2012_val_00037461.bin 224 224 +33460 ./prep_dataset/ILSVRC2012_val_00023379.bin 224 224 +33461 ./prep_dataset/ILSVRC2012_val_00019478.bin 224 224 +33462 ./prep_dataset/ILSVRC2012_val_00000193.bin 224 224 +33463 ./prep_dataset/ILSVRC2012_val_00042494.bin 224 224 +33464 ./prep_dataset/ILSVRC2012_val_00043963.bin 224 224 +33465 ./prep_dataset/ILSVRC2012_val_00030978.bin 224 224 +33466 ./prep_dataset/ILSVRC2012_val_00042147.bin 224 224 +33467 ./prep_dataset/ILSVRC2012_val_00013973.bin 224 224 +33468 ./prep_dataset/ILSVRC2012_val_00010622.bin 224 224 +33469 ./prep_dataset/ILSVRC2012_val_00015076.bin 224 224 +33470 ./prep_dataset/ILSVRC2012_val_00039068.bin 224 224 +33471 ./prep_dataset/ILSVRC2012_val_00042963.bin 224 224 +33472 ./prep_dataset/ILSVRC2012_val_00049187.bin 224 224 +33473 ./prep_dataset/ILSVRC2012_val_00006450.bin 224 224 +33474 ./prep_dataset/ILSVRC2012_val_00002403.bin 224 224 +33475 ./prep_dataset/ILSVRC2012_val_00027366.bin 224 224 +33476 ./prep_dataset/ILSVRC2012_val_00019301.bin 224 224 +33477 ./prep_dataset/ILSVRC2012_val_00022890.bin 224 224 +33478 ./prep_dataset/ILSVRC2012_val_00047707.bin 224 224 +33479 ./prep_dataset/ILSVRC2012_val_00049094.bin 224 224 +33480 ./prep_dataset/ILSVRC2012_val_00040638.bin 224 224 +33481 ./prep_dataset/ILSVRC2012_val_00012865.bin 224 224 +33482 ./prep_dataset/ILSVRC2012_val_00002462.bin 224 224 +33483 ./prep_dataset/ILSVRC2012_val_00033983.bin 224 224 +33484 ./prep_dataset/ILSVRC2012_val_00026221.bin 224 224 +33485 ./prep_dataset/ILSVRC2012_val_00023115.bin 224 224 +33486 ./prep_dataset/ILSVRC2012_val_00037113.bin 224 224 +33487 ./prep_dataset/ILSVRC2012_val_00012099.bin 224 224 +33488 ./prep_dataset/ILSVRC2012_val_00033268.bin 224 224 +33489 ./prep_dataset/ILSVRC2012_val_00036800.bin 224 224 +33490 ./prep_dataset/ILSVRC2012_val_00029199.bin 224 224 +33491 ./prep_dataset/ILSVRC2012_val_00008026.bin 224 224 +33492 ./prep_dataset/ILSVRC2012_val_00017463.bin 224 224 +33493 ./prep_dataset/ILSVRC2012_val_00005314.bin 224 224 +33494 ./prep_dataset/ILSVRC2012_val_00042902.bin 224 224 +33495 ./prep_dataset/ILSVRC2012_val_00023385.bin 224 224 +33496 ./prep_dataset/ILSVRC2012_val_00008127.bin 224 224 +33497 ./prep_dataset/ILSVRC2012_val_00029590.bin 224 224 +33498 ./prep_dataset/ILSVRC2012_val_00002133.bin 224 224 +33499 ./prep_dataset/ILSVRC2012_val_00005679.bin 224 224 +33500 ./prep_dataset/ILSVRC2012_val_00010498.bin 224 224 +33501 ./prep_dataset/ILSVRC2012_val_00037412.bin 224 224 +33502 ./prep_dataset/ILSVRC2012_val_00017206.bin 224 224 +33503 ./prep_dataset/ILSVRC2012_val_00039185.bin 224 224 +33504 ./prep_dataset/ILSVRC2012_val_00000448.bin 224 224 +33505 ./prep_dataset/ILSVRC2012_val_00000642.bin 224 224 +33506 ./prep_dataset/ILSVRC2012_val_00040873.bin 224 224 +33507 ./prep_dataset/ILSVRC2012_val_00038869.bin 224 224 +33508 ./prep_dataset/ILSVRC2012_val_00028919.bin 224 224 +33509 ./prep_dataset/ILSVRC2012_val_00037166.bin 224 224 +33510 ./prep_dataset/ILSVRC2012_val_00007074.bin 224 224 +33511 ./prep_dataset/ILSVRC2012_val_00040644.bin 224 224 +33512 ./prep_dataset/ILSVRC2012_val_00033096.bin 224 224 +33513 ./prep_dataset/ILSVRC2012_val_00019017.bin 224 224 +33514 ./prep_dataset/ILSVRC2012_val_00004169.bin 224 224 +33515 ./prep_dataset/ILSVRC2012_val_00041988.bin 224 224 +33516 ./prep_dataset/ILSVRC2012_val_00032601.bin 224 224 +33517 ./prep_dataset/ILSVRC2012_val_00000309.bin 224 224 +33518 ./prep_dataset/ILSVRC2012_val_00042904.bin 224 224 +33519 ./prep_dataset/ILSVRC2012_val_00003828.bin 224 224 +33520 ./prep_dataset/ILSVRC2012_val_00046754.bin 224 224 +33521 ./prep_dataset/ILSVRC2012_val_00016560.bin 224 224 +33522 ./prep_dataset/ILSVRC2012_val_00037257.bin 224 224 +33523 ./prep_dataset/ILSVRC2012_val_00044768.bin 224 224 +33524 ./prep_dataset/ILSVRC2012_val_00029049.bin 224 224 +33525 ./prep_dataset/ILSVRC2012_val_00036633.bin 224 224 +33526 ./prep_dataset/ILSVRC2012_val_00047097.bin 224 224 +33527 ./prep_dataset/ILSVRC2012_val_00016603.bin 224 224 +33528 ./prep_dataset/ILSVRC2012_val_00009679.bin 224 224 +33529 ./prep_dataset/ILSVRC2012_val_00031301.bin 224 224 +33530 ./prep_dataset/ILSVRC2012_val_00028279.bin 224 224 +33531 ./prep_dataset/ILSVRC2012_val_00009816.bin 224 224 +33532 ./prep_dataset/ILSVRC2012_val_00022298.bin 224 224 +33533 ./prep_dataset/ILSVRC2012_val_00034526.bin 224 224 +33534 ./prep_dataset/ILSVRC2012_val_00019194.bin 224 224 +33535 ./prep_dataset/ILSVRC2012_val_00037187.bin 224 224 +33536 ./prep_dataset/ILSVRC2012_val_00029089.bin 224 224 +33537 ./prep_dataset/ILSVRC2012_val_00002378.bin 224 224 +33538 ./prep_dataset/ILSVRC2012_val_00009294.bin 224 224 +33539 ./prep_dataset/ILSVRC2012_val_00049775.bin 224 224 +33540 ./prep_dataset/ILSVRC2012_val_00017429.bin 224 224 +33541 ./prep_dataset/ILSVRC2012_val_00026655.bin 224 224 +33542 ./prep_dataset/ILSVRC2012_val_00023325.bin 224 224 +33543 ./prep_dataset/ILSVRC2012_val_00041613.bin 224 224 +33544 ./prep_dataset/ILSVRC2012_val_00043994.bin 224 224 +33545 ./prep_dataset/ILSVRC2012_val_00034317.bin 224 224 +33546 ./prep_dataset/ILSVRC2012_val_00024365.bin 224 224 +33547 ./prep_dataset/ILSVRC2012_val_00013740.bin 224 224 +33548 ./prep_dataset/ILSVRC2012_val_00030995.bin 224 224 +33549 ./prep_dataset/ILSVRC2012_val_00035960.bin 224 224 +33550 ./prep_dataset/ILSVRC2012_val_00043334.bin 224 224 +33551 ./prep_dataset/ILSVRC2012_val_00004495.bin 224 224 +33552 ./prep_dataset/ILSVRC2012_val_00002632.bin 224 224 +33553 ./prep_dataset/ILSVRC2012_val_00002300.bin 224 224 +33554 ./prep_dataset/ILSVRC2012_val_00034801.bin 224 224 +33555 ./prep_dataset/ILSVRC2012_val_00025977.bin 224 224 +33556 ./prep_dataset/ILSVRC2012_val_00002461.bin 224 224 +33557 ./prep_dataset/ILSVRC2012_val_00038134.bin 224 224 +33558 ./prep_dataset/ILSVRC2012_val_00012613.bin 224 224 +33559 ./prep_dataset/ILSVRC2012_val_00017192.bin 224 224 +33560 ./prep_dataset/ILSVRC2012_val_00015115.bin 224 224 +33561 ./prep_dataset/ILSVRC2012_val_00032772.bin 224 224 +33562 ./prep_dataset/ILSVRC2012_val_00035141.bin 224 224 +33563 ./prep_dataset/ILSVRC2012_val_00009161.bin 224 224 +33564 ./prep_dataset/ILSVRC2012_val_00043248.bin 224 224 +33565 ./prep_dataset/ILSVRC2012_val_00035608.bin 224 224 +33566 ./prep_dataset/ILSVRC2012_val_00014616.bin 224 224 +33567 ./prep_dataset/ILSVRC2012_val_00026269.bin 224 224 +33568 ./prep_dataset/ILSVRC2012_val_00009783.bin 224 224 +33569 ./prep_dataset/ILSVRC2012_val_00040428.bin 224 224 +33570 ./prep_dataset/ILSVRC2012_val_00035718.bin 224 224 +33571 ./prep_dataset/ILSVRC2012_val_00029099.bin 224 224 +33572 ./prep_dataset/ILSVRC2012_val_00027272.bin 224 224 +33573 ./prep_dataset/ILSVRC2012_val_00038997.bin 224 224 +33574 ./prep_dataset/ILSVRC2012_val_00034047.bin 224 224 +33575 ./prep_dataset/ILSVRC2012_val_00010168.bin 224 224 +33576 ./prep_dataset/ILSVRC2012_val_00006820.bin 224 224 +33577 ./prep_dataset/ILSVRC2012_val_00038902.bin 224 224 +33578 ./prep_dataset/ILSVRC2012_val_00026915.bin 224 224 +33579 ./prep_dataset/ILSVRC2012_val_00002935.bin 224 224 +33580 ./prep_dataset/ILSVRC2012_val_00028943.bin 224 224 +33581 ./prep_dataset/ILSVRC2012_val_00005388.bin 224 224 +33582 ./prep_dataset/ILSVRC2012_val_00004467.bin 224 224 +33583 ./prep_dataset/ILSVRC2012_val_00034381.bin 224 224 +33584 ./prep_dataset/ILSVRC2012_val_00047682.bin 224 224 +33585 ./prep_dataset/ILSVRC2012_val_00004671.bin 224 224 +33586 ./prep_dataset/ILSVRC2012_val_00013382.bin 224 224 +33587 ./prep_dataset/ILSVRC2012_val_00030559.bin 224 224 +33588 ./prep_dataset/ILSVRC2012_val_00014831.bin 224 224 +33589 ./prep_dataset/ILSVRC2012_val_00015338.bin 224 224 +33590 ./prep_dataset/ILSVRC2012_val_00033984.bin 224 224 +33591 ./prep_dataset/ILSVRC2012_val_00037333.bin 224 224 +33592 ./prep_dataset/ILSVRC2012_val_00000800.bin 224 224 +33593 ./prep_dataset/ILSVRC2012_val_00023779.bin 224 224 +33594 ./prep_dataset/ILSVRC2012_val_00013394.bin 224 224 +33595 ./prep_dataset/ILSVRC2012_val_00016382.bin 224 224 +33596 ./prep_dataset/ILSVRC2012_val_00006356.bin 224 224 +33597 ./prep_dataset/ILSVRC2012_val_00019176.bin 224 224 +33598 ./prep_dataset/ILSVRC2012_val_00036566.bin 224 224 +33599 ./prep_dataset/ILSVRC2012_val_00002978.bin 224 224 +33600 ./prep_dataset/ILSVRC2012_val_00032412.bin 224 224 +33601 ./prep_dataset/ILSVRC2012_val_00037854.bin 224 224 +33602 ./prep_dataset/ILSVRC2012_val_00001760.bin 224 224 +33603 ./prep_dataset/ILSVRC2012_val_00026185.bin 224 224 +33604 ./prep_dataset/ILSVRC2012_val_00011430.bin 224 224 +33605 ./prep_dataset/ILSVRC2012_val_00037034.bin 224 224 +33606 ./prep_dataset/ILSVRC2012_val_00000005.bin 224 224 +33607 ./prep_dataset/ILSVRC2012_val_00032926.bin 224 224 +33608 ./prep_dataset/ILSVRC2012_val_00025589.bin 224 224 +33609 ./prep_dataset/ILSVRC2012_val_00010364.bin 224 224 +33610 ./prep_dataset/ILSVRC2012_val_00021517.bin 224 224 +33611 ./prep_dataset/ILSVRC2012_val_00044890.bin 224 224 +33612 ./prep_dataset/ILSVRC2012_val_00015279.bin 224 224 +33613 ./prep_dataset/ILSVRC2012_val_00026668.bin 224 224 +33614 ./prep_dataset/ILSVRC2012_val_00020527.bin 224 224 +33615 ./prep_dataset/ILSVRC2012_val_00035149.bin 224 224 +33616 ./prep_dataset/ILSVRC2012_val_00046267.bin 224 224 +33617 ./prep_dataset/ILSVRC2012_val_00004979.bin 224 224 +33618 ./prep_dataset/ILSVRC2012_val_00028652.bin 224 224 +33619 ./prep_dataset/ILSVRC2012_val_00025018.bin 224 224 +33620 ./prep_dataset/ILSVRC2012_val_00000702.bin 224 224 +33621 ./prep_dataset/ILSVRC2012_val_00016800.bin 224 224 +33622 ./prep_dataset/ILSVRC2012_val_00024271.bin 224 224 +33623 ./prep_dataset/ILSVRC2012_val_00014801.bin 224 224 +33624 ./prep_dataset/ILSVRC2012_val_00011095.bin 224 224 +33625 ./prep_dataset/ILSVRC2012_val_00018042.bin 224 224 +33626 ./prep_dataset/ILSVRC2012_val_00018163.bin 224 224 +33627 ./prep_dataset/ILSVRC2012_val_00028819.bin 224 224 +33628 ./prep_dataset/ILSVRC2012_val_00036094.bin 224 224 +33629 ./prep_dataset/ILSVRC2012_val_00016522.bin 224 224 +33630 ./prep_dataset/ILSVRC2012_val_00030417.bin 224 224 +33631 ./prep_dataset/ILSVRC2012_val_00016211.bin 224 224 +33632 ./prep_dataset/ILSVRC2012_val_00043518.bin 224 224 +33633 ./prep_dataset/ILSVRC2012_val_00031173.bin 224 224 +33634 ./prep_dataset/ILSVRC2012_val_00033119.bin 224 224 +33635 ./prep_dataset/ILSVRC2012_val_00000988.bin 224 224 +33636 ./prep_dataset/ILSVRC2012_val_00027799.bin 224 224 +33637 ./prep_dataset/ILSVRC2012_val_00037293.bin 224 224 +33638 ./prep_dataset/ILSVRC2012_val_00043564.bin 224 224 +33639 ./prep_dataset/ILSVRC2012_val_00038834.bin 224 224 +33640 ./prep_dataset/ILSVRC2012_val_00030188.bin 224 224 +33641 ./prep_dataset/ILSVRC2012_val_00020415.bin 224 224 +33642 ./prep_dataset/ILSVRC2012_val_00032428.bin 224 224 +33643 ./prep_dataset/ILSVRC2012_val_00021806.bin 224 224 +33644 ./prep_dataset/ILSVRC2012_val_00029551.bin 224 224 +33645 ./prep_dataset/ILSVRC2012_val_00017401.bin 224 224 +33646 ./prep_dataset/ILSVRC2012_val_00016285.bin 224 224 +33647 ./prep_dataset/ILSVRC2012_val_00018187.bin 224 224 +33648 ./prep_dataset/ILSVRC2012_val_00009824.bin 224 224 +33649 ./prep_dataset/ILSVRC2012_val_00001178.bin 224 224 +33650 ./prep_dataset/ILSVRC2012_val_00012448.bin 224 224 +33651 ./prep_dataset/ILSVRC2012_val_00001160.bin 224 224 +33652 ./prep_dataset/ILSVRC2012_val_00034970.bin 224 224 +33653 ./prep_dataset/ILSVRC2012_val_00032686.bin 224 224 +33654 ./prep_dataset/ILSVRC2012_val_00035134.bin 224 224 +33655 ./prep_dataset/ILSVRC2012_val_00011958.bin 224 224 +33656 ./prep_dataset/ILSVRC2012_val_00001924.bin 224 224 +33657 ./prep_dataset/ILSVRC2012_val_00047309.bin 224 224 +33658 ./prep_dataset/ILSVRC2012_val_00026002.bin 224 224 +33659 ./prep_dataset/ILSVRC2012_val_00015911.bin 224 224 +33660 ./prep_dataset/ILSVRC2012_val_00034530.bin 224 224 +33661 ./prep_dataset/ILSVRC2012_val_00012445.bin 224 224 +33662 ./prep_dataset/ILSVRC2012_val_00000234.bin 224 224 +33663 ./prep_dataset/ILSVRC2012_val_00046751.bin 224 224 +33664 ./prep_dataset/ILSVRC2012_val_00025797.bin 224 224 +33665 ./prep_dataset/ILSVRC2012_val_00040745.bin 224 224 +33666 ./prep_dataset/ILSVRC2012_val_00044003.bin 224 224 +33667 ./prep_dataset/ILSVRC2012_val_00007217.bin 224 224 +33668 ./prep_dataset/ILSVRC2012_val_00041634.bin 224 224 +33669 ./prep_dataset/ILSVRC2012_val_00049524.bin 224 224 +33670 ./prep_dataset/ILSVRC2012_val_00009111.bin 224 224 +33671 ./prep_dataset/ILSVRC2012_val_00000135.bin 224 224 +33672 ./prep_dataset/ILSVRC2012_val_00036481.bin 224 224 +33673 ./prep_dataset/ILSVRC2012_val_00014412.bin 224 224 +33674 ./prep_dataset/ILSVRC2012_val_00035748.bin 224 224 +33675 ./prep_dataset/ILSVRC2012_val_00010697.bin 224 224 +33676 ./prep_dataset/ILSVRC2012_val_00008950.bin 224 224 +33677 ./prep_dataset/ILSVRC2012_val_00025068.bin 224 224 +33678 ./prep_dataset/ILSVRC2012_val_00040931.bin 224 224 +33679 ./prep_dataset/ILSVRC2012_val_00038245.bin 224 224 +33680 ./prep_dataset/ILSVRC2012_val_00014164.bin 224 224 +33681 ./prep_dataset/ILSVRC2012_val_00018902.bin 224 224 +33682 ./prep_dataset/ILSVRC2012_val_00044554.bin 224 224 +33683 ./prep_dataset/ILSVRC2012_val_00023888.bin 224 224 +33684 ./prep_dataset/ILSVRC2012_val_00010488.bin 224 224 +33685 ./prep_dataset/ILSVRC2012_val_00033037.bin 224 224 +33686 ./prep_dataset/ILSVRC2012_val_00039413.bin 224 224 +33687 ./prep_dataset/ILSVRC2012_val_00029782.bin 224 224 +33688 ./prep_dataset/ILSVRC2012_val_00031066.bin 224 224 +33689 ./prep_dataset/ILSVRC2012_val_00021968.bin 224 224 +33690 ./prep_dataset/ILSVRC2012_val_00001133.bin 224 224 +33691 ./prep_dataset/ILSVRC2012_val_00034727.bin 224 224 +33692 ./prep_dataset/ILSVRC2012_val_00024181.bin 224 224 +33693 ./prep_dataset/ILSVRC2012_val_00016540.bin 224 224 +33694 ./prep_dataset/ILSVRC2012_val_00008459.bin 224 224 +33695 ./prep_dataset/ILSVRC2012_val_00014134.bin 224 224 +33696 ./prep_dataset/ILSVRC2012_val_00031288.bin 224 224 +33697 ./prep_dataset/ILSVRC2012_val_00048356.bin 224 224 +33698 ./prep_dataset/ILSVRC2012_val_00038231.bin 224 224 +33699 ./prep_dataset/ILSVRC2012_val_00038665.bin 224 224 +33700 ./prep_dataset/ILSVRC2012_val_00019506.bin 224 224 +33701 ./prep_dataset/ILSVRC2012_val_00006656.bin 224 224 +33702 ./prep_dataset/ILSVRC2012_val_00021915.bin 224 224 +33703 ./prep_dataset/ILSVRC2012_val_00003599.bin 224 224 +33704 ./prep_dataset/ILSVRC2012_val_00000288.bin 224 224 +33705 ./prep_dataset/ILSVRC2012_val_00039004.bin 224 224 +33706 ./prep_dataset/ILSVRC2012_val_00036088.bin 224 224 +33707 ./prep_dataset/ILSVRC2012_val_00048283.bin 224 224 +33708 ./prep_dataset/ILSVRC2012_val_00020651.bin 224 224 +33709 ./prep_dataset/ILSVRC2012_val_00032405.bin 224 224 +33710 ./prep_dataset/ILSVRC2012_val_00018724.bin 224 224 +33711 ./prep_dataset/ILSVRC2012_val_00045556.bin 224 224 +33712 ./prep_dataset/ILSVRC2012_val_00047315.bin 224 224 +33713 ./prep_dataset/ILSVRC2012_val_00033048.bin 224 224 +33714 ./prep_dataset/ILSVRC2012_val_00016488.bin 224 224 +33715 ./prep_dataset/ILSVRC2012_val_00044806.bin 224 224 +33716 ./prep_dataset/ILSVRC2012_val_00046647.bin 224 224 +33717 ./prep_dataset/ILSVRC2012_val_00002578.bin 224 224 +33718 ./prep_dataset/ILSVRC2012_val_00016840.bin 224 224 +33719 ./prep_dataset/ILSVRC2012_val_00032222.bin 224 224 +33720 ./prep_dataset/ILSVRC2012_val_00019124.bin 224 224 +33721 ./prep_dataset/ILSVRC2012_val_00035730.bin 224 224 +33722 ./prep_dataset/ILSVRC2012_val_00014665.bin 224 224 +33723 ./prep_dataset/ILSVRC2012_val_00022844.bin 224 224 +33724 ./prep_dataset/ILSVRC2012_val_00013867.bin 224 224 +33725 ./prep_dataset/ILSVRC2012_val_00009054.bin 224 224 +33726 ./prep_dataset/ILSVRC2012_val_00007529.bin 224 224 +33727 ./prep_dataset/ILSVRC2012_val_00018331.bin 224 224 +33728 ./prep_dataset/ILSVRC2012_val_00013270.bin 224 224 +33729 ./prep_dataset/ILSVRC2012_val_00012310.bin 224 224 +33730 ./prep_dataset/ILSVRC2012_val_00041368.bin 224 224 +33731 ./prep_dataset/ILSVRC2012_val_00005625.bin 224 224 +33732 ./prep_dataset/ILSVRC2012_val_00005006.bin 224 224 +33733 ./prep_dataset/ILSVRC2012_val_00010166.bin 224 224 +33734 ./prep_dataset/ILSVRC2012_val_00033456.bin 224 224 +33735 ./prep_dataset/ILSVRC2012_val_00043364.bin 224 224 +33736 ./prep_dataset/ILSVRC2012_val_00035498.bin 224 224 +33737 ./prep_dataset/ILSVRC2012_val_00039731.bin 224 224 +33738 ./prep_dataset/ILSVRC2012_val_00013479.bin 224 224 +33739 ./prep_dataset/ILSVRC2012_val_00047041.bin 224 224 +33740 ./prep_dataset/ILSVRC2012_val_00007415.bin 224 224 +33741 ./prep_dataset/ILSVRC2012_val_00017809.bin 224 224 +33742 ./prep_dataset/ILSVRC2012_val_00048850.bin 224 224 +33743 ./prep_dataset/ILSVRC2012_val_00006215.bin 224 224 +33744 ./prep_dataset/ILSVRC2012_val_00006804.bin 224 224 +33745 ./prep_dataset/ILSVRC2012_val_00038597.bin 224 224 +33746 ./prep_dataset/ILSVRC2012_val_00029859.bin 224 224 +33747 ./prep_dataset/ILSVRC2012_val_00049873.bin 224 224 +33748 ./prep_dataset/ILSVRC2012_val_00026297.bin 224 224 +33749 ./prep_dataset/ILSVRC2012_val_00025240.bin 224 224 +33750 ./prep_dataset/ILSVRC2012_val_00016852.bin 224 224 +33751 ./prep_dataset/ILSVRC2012_val_00040828.bin 224 224 +33752 ./prep_dataset/ILSVRC2012_val_00044675.bin 224 224 +33753 ./prep_dataset/ILSVRC2012_val_00014014.bin 224 224 +33754 ./prep_dataset/ILSVRC2012_val_00046246.bin 224 224 +33755 ./prep_dataset/ILSVRC2012_val_00011169.bin 224 224 +33756 ./prep_dataset/ILSVRC2012_val_00027174.bin 224 224 +33757 ./prep_dataset/ILSVRC2012_val_00030720.bin 224 224 +33758 ./prep_dataset/ILSVRC2012_val_00014217.bin 224 224 +33759 ./prep_dataset/ILSVRC2012_val_00044574.bin 224 224 +33760 ./prep_dataset/ILSVRC2012_val_00030132.bin 224 224 +33761 ./prep_dataset/ILSVRC2012_val_00002362.bin 224 224 +33762 ./prep_dataset/ILSVRC2012_val_00008586.bin 224 224 +33763 ./prep_dataset/ILSVRC2012_val_00044541.bin 224 224 +33764 ./prep_dataset/ILSVRC2012_val_00040411.bin 224 224 +33765 ./prep_dataset/ILSVRC2012_val_00008248.bin 224 224 +33766 ./prep_dataset/ILSVRC2012_val_00017032.bin 224 224 +33767 ./prep_dataset/ILSVRC2012_val_00020081.bin 224 224 +33768 ./prep_dataset/ILSVRC2012_val_00005351.bin 224 224 +33769 ./prep_dataset/ILSVRC2012_val_00039025.bin 224 224 +33770 ./prep_dataset/ILSVRC2012_val_00012166.bin 224 224 +33771 ./prep_dataset/ILSVRC2012_val_00044316.bin 224 224 +33772 ./prep_dataset/ILSVRC2012_val_00009473.bin 224 224 +33773 ./prep_dataset/ILSVRC2012_val_00021485.bin 224 224 +33774 ./prep_dataset/ILSVRC2012_val_00015541.bin 224 224 +33775 ./prep_dataset/ILSVRC2012_val_00032300.bin 224 224 +33776 ./prep_dataset/ILSVRC2012_val_00016310.bin 224 224 +33777 ./prep_dataset/ILSVRC2012_val_00042899.bin 224 224 +33778 ./prep_dataset/ILSVRC2012_val_00026719.bin 224 224 +33779 ./prep_dataset/ILSVRC2012_val_00048181.bin 224 224 +33780 ./prep_dataset/ILSVRC2012_val_00000519.bin 224 224 +33781 ./prep_dataset/ILSVRC2012_val_00016889.bin 224 224 +33782 ./prep_dataset/ILSVRC2012_val_00039450.bin 224 224 +33783 ./prep_dataset/ILSVRC2012_val_00042341.bin 224 224 +33784 ./prep_dataset/ILSVRC2012_val_00018968.bin 224 224 +33785 ./prep_dataset/ILSVRC2012_val_00022437.bin 224 224 +33786 ./prep_dataset/ILSVRC2012_val_00011788.bin 224 224 +33787 ./prep_dataset/ILSVRC2012_val_00015074.bin 224 224 +33788 ./prep_dataset/ILSVRC2012_val_00009945.bin 224 224 +33789 ./prep_dataset/ILSVRC2012_val_00001424.bin 224 224 +33790 ./prep_dataset/ILSVRC2012_val_00021483.bin 224 224 +33791 ./prep_dataset/ILSVRC2012_val_00008870.bin 224 224 +33792 ./prep_dataset/ILSVRC2012_val_00043084.bin 224 224 +33793 ./prep_dataset/ILSVRC2012_val_00013316.bin 224 224 +33794 ./prep_dataset/ILSVRC2012_val_00018961.bin 224 224 +33795 ./prep_dataset/ILSVRC2012_val_00033309.bin 224 224 +33796 ./prep_dataset/ILSVRC2012_val_00026523.bin 224 224 +33797 ./prep_dataset/ILSVRC2012_val_00044782.bin 224 224 +33798 ./prep_dataset/ILSVRC2012_val_00018533.bin 224 224 +33799 ./prep_dataset/ILSVRC2012_val_00022981.bin 224 224 +33800 ./prep_dataset/ILSVRC2012_val_00017464.bin 224 224 +33801 ./prep_dataset/ILSVRC2012_val_00042224.bin 224 224 +33802 ./prep_dataset/ILSVRC2012_val_00020788.bin 224 224 +33803 ./prep_dataset/ILSVRC2012_val_00022747.bin 224 224 +33804 ./prep_dataset/ILSVRC2012_val_00016159.bin 224 224 +33805 ./prep_dataset/ILSVRC2012_val_00047167.bin 224 224 +33806 ./prep_dataset/ILSVRC2012_val_00025731.bin 224 224 +33807 ./prep_dataset/ILSVRC2012_val_00046977.bin 224 224 +33808 ./prep_dataset/ILSVRC2012_val_00011171.bin 224 224 +33809 ./prep_dataset/ILSVRC2012_val_00017792.bin 224 224 +33810 ./prep_dataset/ILSVRC2012_val_00033024.bin 224 224 +33811 ./prep_dataset/ILSVRC2012_val_00017428.bin 224 224 +33812 ./prep_dataset/ILSVRC2012_val_00008881.bin 224 224 +33813 ./prep_dataset/ILSVRC2012_val_00044587.bin 224 224 +33814 ./prep_dataset/ILSVRC2012_val_00002206.bin 224 224 +33815 ./prep_dataset/ILSVRC2012_val_00031147.bin 224 224 +33816 ./prep_dataset/ILSVRC2012_val_00036160.bin 224 224 +33817 ./prep_dataset/ILSVRC2012_val_00047838.bin 224 224 +33818 ./prep_dataset/ILSVRC2012_val_00026393.bin 224 224 +33819 ./prep_dataset/ILSVRC2012_val_00004562.bin 224 224 +33820 ./prep_dataset/ILSVRC2012_val_00007485.bin 224 224 +33821 ./prep_dataset/ILSVRC2012_val_00030764.bin 224 224 +33822 ./prep_dataset/ILSVRC2012_val_00047010.bin 224 224 +33823 ./prep_dataset/ILSVRC2012_val_00007104.bin 224 224 +33824 ./prep_dataset/ILSVRC2012_val_00024915.bin 224 224 +33825 ./prep_dataset/ILSVRC2012_val_00023506.bin 224 224 +33826 ./prep_dataset/ILSVRC2012_val_00020074.bin 224 224 +33827 ./prep_dataset/ILSVRC2012_val_00025469.bin 224 224 +33828 ./prep_dataset/ILSVRC2012_val_00029188.bin 224 224 +33829 ./prep_dataset/ILSVRC2012_val_00000461.bin 224 224 +33830 ./prep_dataset/ILSVRC2012_val_00042491.bin 224 224 +33831 ./prep_dataset/ILSVRC2012_val_00010879.bin 224 224 +33832 ./prep_dataset/ILSVRC2012_val_00011021.bin 224 224 +33833 ./prep_dataset/ILSVRC2012_val_00004660.bin 224 224 +33834 ./prep_dataset/ILSVRC2012_val_00023239.bin 224 224 +33835 ./prep_dataset/ILSVRC2012_val_00030988.bin 224 224 +33836 ./prep_dataset/ILSVRC2012_val_00031156.bin 224 224 +33837 ./prep_dataset/ILSVRC2012_val_00010555.bin 224 224 +33838 ./prep_dataset/ILSVRC2012_val_00009782.bin 224 224 +33839 ./prep_dataset/ILSVRC2012_val_00031118.bin 224 224 +33840 ./prep_dataset/ILSVRC2012_val_00000185.bin 224 224 +33841 ./prep_dataset/ILSVRC2012_val_00001110.bin 224 224 +33842 ./prep_dataset/ILSVRC2012_val_00007161.bin 224 224 +33843 ./prep_dataset/ILSVRC2012_val_00015062.bin 224 224 +33844 ./prep_dataset/ILSVRC2012_val_00037487.bin 224 224 +33845 ./prep_dataset/ILSVRC2012_val_00017203.bin 224 224 +33846 ./prep_dataset/ILSVRC2012_val_00005360.bin 224 224 +33847 ./prep_dataset/ILSVRC2012_val_00025039.bin 224 224 +33848 ./prep_dataset/ILSVRC2012_val_00017897.bin 224 224 +33849 ./prep_dataset/ILSVRC2012_val_00004985.bin 224 224 +33850 ./prep_dataset/ILSVRC2012_val_00006433.bin 224 224 +33851 ./prep_dataset/ILSVRC2012_val_00038672.bin 224 224 +33852 ./prep_dataset/ILSVRC2012_val_00011354.bin 224 224 +33853 ./prep_dataset/ILSVRC2012_val_00020432.bin 224 224 +33854 ./prep_dataset/ILSVRC2012_val_00035904.bin 224 224 +33855 ./prep_dataset/ILSVRC2012_val_00028814.bin 224 224 +33856 ./prep_dataset/ILSVRC2012_val_00044251.bin 224 224 +33857 ./prep_dataset/ILSVRC2012_val_00029180.bin 224 224 +33858 ./prep_dataset/ILSVRC2012_val_00010404.bin 224 224 +33859 ./prep_dataset/ILSVRC2012_val_00012575.bin 224 224 +33860 ./prep_dataset/ILSVRC2012_val_00028716.bin 224 224 +33861 ./prep_dataset/ILSVRC2012_val_00048307.bin 224 224 +33862 ./prep_dataset/ILSVRC2012_val_00009309.bin 224 224 +33863 ./prep_dataset/ILSVRC2012_val_00045779.bin 224 224 +33864 ./prep_dataset/ILSVRC2012_val_00030732.bin 224 224 +33865 ./prep_dataset/ILSVRC2012_val_00010846.bin 224 224 +33866 ./prep_dataset/ILSVRC2012_val_00020363.bin 224 224 +33867 ./prep_dataset/ILSVRC2012_val_00022245.bin 224 224 +33868 ./prep_dataset/ILSVRC2012_val_00000088.bin 224 224 +33869 ./prep_dataset/ILSVRC2012_val_00002855.bin 224 224 +33870 ./prep_dataset/ILSVRC2012_val_00016864.bin 224 224 +33871 ./prep_dataset/ILSVRC2012_val_00014720.bin 224 224 +33872 ./prep_dataset/ILSVRC2012_val_00041024.bin 224 224 +33873 ./prep_dataset/ILSVRC2012_val_00013413.bin 224 224 +33874 ./prep_dataset/ILSVRC2012_val_00032403.bin 224 224 +33875 ./prep_dataset/ILSVRC2012_val_00029846.bin 224 224 +33876 ./prep_dataset/ILSVRC2012_val_00014566.bin 224 224 +33877 ./prep_dataset/ILSVRC2012_val_00001066.bin 224 224 +33878 ./prep_dataset/ILSVRC2012_val_00023089.bin 224 224 +33879 ./prep_dataset/ILSVRC2012_val_00006981.bin 224 224 +33880 ./prep_dataset/ILSVRC2012_val_00028110.bin 224 224 +33881 ./prep_dataset/ILSVRC2012_val_00011137.bin 224 224 +33882 ./prep_dataset/ILSVRC2012_val_00029528.bin 224 224 +33883 ./prep_dataset/ILSVRC2012_val_00037607.bin 224 224 +33884 ./prep_dataset/ILSVRC2012_val_00027383.bin 224 224 +33885 ./prep_dataset/ILSVRC2012_val_00044527.bin 224 224 +33886 ./prep_dataset/ILSVRC2012_val_00044366.bin 224 224 +33887 ./prep_dataset/ILSVRC2012_val_00025088.bin 224 224 +33888 ./prep_dataset/ILSVRC2012_val_00003844.bin 224 224 +33889 ./prep_dataset/ILSVRC2012_val_00012842.bin 224 224 +33890 ./prep_dataset/ILSVRC2012_val_00028786.bin 224 224 +33891 ./prep_dataset/ILSVRC2012_val_00011628.bin 224 224 +33892 ./prep_dataset/ILSVRC2012_val_00040033.bin 224 224 +33893 ./prep_dataset/ILSVRC2012_val_00013788.bin 224 224 +33894 ./prep_dataset/ILSVRC2012_val_00038108.bin 224 224 +33895 ./prep_dataset/ILSVRC2012_val_00010660.bin 224 224 +33896 ./prep_dataset/ILSVRC2012_val_00005031.bin 224 224 +33897 ./prep_dataset/ILSVRC2012_val_00039402.bin 224 224 +33898 ./prep_dataset/ILSVRC2012_val_00009017.bin 224 224 +33899 ./prep_dataset/ILSVRC2012_val_00023982.bin 224 224 +33900 ./prep_dataset/ILSVRC2012_val_00039214.bin 224 224 +33901 ./prep_dataset/ILSVRC2012_val_00018554.bin 224 224 +33902 ./prep_dataset/ILSVRC2012_val_00003194.bin 224 224 +33903 ./prep_dataset/ILSVRC2012_val_00048409.bin 224 224 +33904 ./prep_dataset/ILSVRC2012_val_00010158.bin 224 224 +33905 ./prep_dataset/ILSVRC2012_val_00035709.bin 224 224 +33906 ./prep_dataset/ILSVRC2012_val_00018566.bin 224 224 +33907 ./prep_dataset/ILSVRC2012_val_00015718.bin 224 224 +33908 ./prep_dataset/ILSVRC2012_val_00022563.bin 224 224 +33909 ./prep_dataset/ILSVRC2012_val_00024644.bin 224 224 +33910 ./prep_dataset/ILSVRC2012_val_00031125.bin 224 224 +33911 ./prep_dataset/ILSVRC2012_val_00018423.bin 224 224 +33912 ./prep_dataset/ILSVRC2012_val_00020862.bin 224 224 +33913 ./prep_dataset/ILSVRC2012_val_00004688.bin 224 224 +33914 ./prep_dataset/ILSVRC2012_val_00009246.bin 224 224 +33915 ./prep_dataset/ILSVRC2012_val_00000041.bin 224 224 +33916 ./prep_dataset/ILSVRC2012_val_00006392.bin 224 224 +33917 ./prep_dataset/ILSVRC2012_val_00038477.bin 224 224 +33918 ./prep_dataset/ILSVRC2012_val_00025988.bin 224 224 +33919 ./prep_dataset/ILSVRC2012_val_00029029.bin 224 224 +33920 ./prep_dataset/ILSVRC2012_val_00034769.bin 224 224 +33921 ./prep_dataset/ILSVRC2012_val_00042252.bin 224 224 +33922 ./prep_dataset/ILSVRC2012_val_00041340.bin 224 224 +33923 ./prep_dataset/ILSVRC2012_val_00045657.bin 224 224 +33924 ./prep_dataset/ILSVRC2012_val_00017661.bin 224 224 +33925 ./prep_dataset/ILSVRC2012_val_00024629.bin 224 224 +33926 ./prep_dataset/ILSVRC2012_val_00026526.bin 224 224 +33927 ./prep_dataset/ILSVRC2012_val_00042151.bin 224 224 +33928 ./prep_dataset/ILSVRC2012_val_00038246.bin 224 224 +33929 ./prep_dataset/ILSVRC2012_val_00039320.bin 224 224 +33930 ./prep_dataset/ILSVRC2012_val_00040942.bin 224 224 +33931 ./prep_dataset/ILSVRC2012_val_00001818.bin 224 224 +33932 ./prep_dataset/ILSVRC2012_val_00003416.bin 224 224 +33933 ./prep_dataset/ILSVRC2012_val_00005250.bin 224 224 +33934 ./prep_dataset/ILSVRC2012_val_00006170.bin 224 224 +33935 ./prep_dataset/ILSVRC2012_val_00017457.bin 224 224 +33936 ./prep_dataset/ILSVRC2012_val_00035235.bin 224 224 +33937 ./prep_dataset/ILSVRC2012_val_00042380.bin 224 224 +33938 ./prep_dataset/ILSVRC2012_val_00008051.bin 224 224 +33939 ./prep_dataset/ILSVRC2012_val_00022650.bin 224 224 +33940 ./prep_dataset/ILSVRC2012_val_00016652.bin 224 224 +33941 ./prep_dataset/ILSVRC2012_val_00027292.bin 224 224 +33942 ./prep_dataset/ILSVRC2012_val_00001796.bin 224 224 +33943 ./prep_dataset/ILSVRC2012_val_00000450.bin 224 224 +33944 ./prep_dataset/ILSVRC2012_val_00049088.bin 224 224 +33945 ./prep_dataset/ILSVRC2012_val_00045027.bin 224 224 +33946 ./prep_dataset/ILSVRC2012_val_00032162.bin 224 224 +33947 ./prep_dataset/ILSVRC2012_val_00031778.bin 224 224 +33948 ./prep_dataset/ILSVRC2012_val_00040419.bin 224 224 +33949 ./prep_dataset/ILSVRC2012_val_00043211.bin 224 224 +33950 ./prep_dataset/ILSVRC2012_val_00037165.bin 224 224 +33951 ./prep_dataset/ILSVRC2012_val_00049216.bin 224 224 +33952 ./prep_dataset/ILSVRC2012_val_00010699.bin 224 224 +33953 ./prep_dataset/ILSVRC2012_val_00015712.bin 224 224 +33954 ./prep_dataset/ILSVRC2012_val_00045414.bin 224 224 +33955 ./prep_dataset/ILSVRC2012_val_00011481.bin 224 224 +33956 ./prep_dataset/ILSVRC2012_val_00042959.bin 224 224 +33957 ./prep_dataset/ILSVRC2012_val_00014784.bin 224 224 +33958 ./prep_dataset/ILSVRC2012_val_00016152.bin 224 224 +33959 ./prep_dataset/ILSVRC2012_val_00001975.bin 224 224 +33960 ./prep_dataset/ILSVRC2012_val_00036723.bin 224 224 +33961 ./prep_dataset/ILSVRC2012_val_00027453.bin 224 224 +33962 ./prep_dataset/ILSVRC2012_val_00017275.bin 224 224 +33963 ./prep_dataset/ILSVRC2012_val_00025271.bin 224 224 +33964 ./prep_dataset/ILSVRC2012_val_00045956.bin 224 224 +33965 ./prep_dataset/ILSVRC2012_val_00014752.bin 224 224 +33966 ./prep_dataset/ILSVRC2012_val_00014379.bin 224 224 +33967 ./prep_dataset/ILSVRC2012_val_00007151.bin 224 224 +33968 ./prep_dataset/ILSVRC2012_val_00048661.bin 224 224 +33969 ./prep_dataset/ILSVRC2012_val_00031660.bin 224 224 +33970 ./prep_dataset/ILSVRC2012_val_00023919.bin 224 224 +33971 ./prep_dataset/ILSVRC2012_val_00025853.bin 224 224 +33972 ./prep_dataset/ILSVRC2012_val_00039741.bin 224 224 +33973 ./prep_dataset/ILSVRC2012_val_00030509.bin 224 224 +33974 ./prep_dataset/ILSVRC2012_val_00013854.bin 224 224 +33975 ./prep_dataset/ILSVRC2012_val_00000535.bin 224 224 +33976 ./prep_dataset/ILSVRC2012_val_00030715.bin 224 224 +33977 ./prep_dataset/ILSVRC2012_val_00048545.bin 224 224 +33978 ./prep_dataset/ILSVRC2012_val_00009226.bin 224 224 +33979 ./prep_dataset/ILSVRC2012_val_00007664.bin 224 224 +33980 ./prep_dataset/ILSVRC2012_val_00049592.bin 224 224 +33981 ./prep_dataset/ILSVRC2012_val_00031476.bin 224 224 +33982 ./prep_dataset/ILSVRC2012_val_00026987.bin 224 224 +33983 ./prep_dataset/ILSVRC2012_val_00007157.bin 224 224 +33984 ./prep_dataset/ILSVRC2012_val_00032920.bin 224 224 +33985 ./prep_dataset/ILSVRC2012_val_00008759.bin 224 224 +33986 ./prep_dataset/ILSVRC2012_val_00010567.bin 224 224 +33987 ./prep_dataset/ILSVRC2012_val_00039628.bin 224 224 +33988 ./prep_dataset/ILSVRC2012_val_00040977.bin 224 224 +33989 ./prep_dataset/ILSVRC2012_val_00046838.bin 224 224 +33990 ./prep_dataset/ILSVRC2012_val_00004706.bin 224 224 +33991 ./prep_dataset/ILSVRC2012_val_00032572.bin 224 224 +33992 ./prep_dataset/ILSVRC2012_val_00031911.bin 224 224 +33993 ./prep_dataset/ILSVRC2012_val_00007272.bin 224 224 +33994 ./prep_dataset/ILSVRC2012_val_00038588.bin 224 224 +33995 ./prep_dataset/ILSVRC2012_val_00043865.bin 224 224 +33996 ./prep_dataset/ILSVRC2012_val_00010080.bin 224 224 +33997 ./prep_dataset/ILSVRC2012_val_00041206.bin 224 224 +33998 ./prep_dataset/ILSVRC2012_val_00036291.bin 224 224 +33999 ./prep_dataset/ILSVRC2012_val_00045531.bin 224 224 +34000 ./prep_dataset/ILSVRC2012_val_00002663.bin 224 224 +34001 ./prep_dataset/ILSVRC2012_val_00017495.bin 224 224 +34002 ./prep_dataset/ILSVRC2012_val_00031556.bin 224 224 +34003 ./prep_dataset/ILSVRC2012_val_00033620.bin 224 224 +34004 ./prep_dataset/ILSVRC2012_val_00027970.bin 224 224 +34005 ./prep_dataset/ILSVRC2012_val_00031756.bin 224 224 +34006 ./prep_dataset/ILSVRC2012_val_00026181.bin 224 224 +34007 ./prep_dataset/ILSVRC2012_val_00002404.bin 224 224 +34008 ./prep_dataset/ILSVRC2012_val_00020890.bin 224 224 +34009 ./prep_dataset/ILSVRC2012_val_00027477.bin 224 224 +34010 ./prep_dataset/ILSVRC2012_val_00011568.bin 224 224 +34011 ./prep_dataset/ILSVRC2012_val_00013582.bin 224 224 +34012 ./prep_dataset/ILSVRC2012_val_00013164.bin 224 224 +34013 ./prep_dataset/ILSVRC2012_val_00030879.bin 224 224 +34014 ./prep_dataset/ILSVRC2012_val_00040728.bin 224 224 +34015 ./prep_dataset/ILSVRC2012_val_00025669.bin 224 224 +34016 ./prep_dataset/ILSVRC2012_val_00047374.bin 224 224 +34017 ./prep_dataset/ILSVRC2012_val_00031242.bin 224 224 +34018 ./prep_dataset/ILSVRC2012_val_00028878.bin 224 224 +34019 ./prep_dataset/ILSVRC2012_val_00014569.bin 224 224 +34020 ./prep_dataset/ILSVRC2012_val_00027615.bin 224 224 +34021 ./prep_dataset/ILSVRC2012_val_00013580.bin 224 224 +34022 ./prep_dataset/ILSVRC2012_val_00032700.bin 224 224 +34023 ./prep_dataset/ILSVRC2012_val_00006190.bin 224 224 +34024 ./prep_dataset/ILSVRC2012_val_00014747.bin 224 224 +34025 ./prep_dataset/ILSVRC2012_val_00032970.bin 224 224 +34026 ./prep_dataset/ILSVRC2012_val_00046136.bin 224 224 +34027 ./prep_dataset/ILSVRC2012_val_00017435.bin 224 224 +34028 ./prep_dataset/ILSVRC2012_val_00036616.bin 224 224 +34029 ./prep_dataset/ILSVRC2012_val_00012957.bin 224 224 +34030 ./prep_dataset/ILSVRC2012_val_00000365.bin 224 224 +34031 ./prep_dataset/ILSVRC2012_val_00048603.bin 224 224 +34032 ./prep_dataset/ILSVRC2012_val_00045542.bin 224 224 +34033 ./prep_dataset/ILSVRC2012_val_00032694.bin 224 224 +34034 ./prep_dataset/ILSVRC2012_val_00038434.bin 224 224 +34035 ./prep_dataset/ILSVRC2012_val_00036239.bin 224 224 +34036 ./prep_dataset/ILSVRC2012_val_00005064.bin 224 224 +34037 ./prep_dataset/ILSVRC2012_val_00045176.bin 224 224 +34038 ./prep_dataset/ILSVRC2012_val_00025538.bin 224 224 +34039 ./prep_dataset/ILSVRC2012_val_00005520.bin 224 224 +34040 ./prep_dataset/ILSVRC2012_val_00027038.bin 224 224 +34041 ./prep_dataset/ILSVRC2012_val_00022176.bin 224 224 +34042 ./prep_dataset/ILSVRC2012_val_00033895.bin 224 224 +34043 ./prep_dataset/ILSVRC2012_val_00004271.bin 224 224 +34044 ./prep_dataset/ILSVRC2012_val_00045580.bin 224 224 +34045 ./prep_dataset/ILSVRC2012_val_00044882.bin 224 224 +34046 ./prep_dataset/ILSVRC2012_val_00042399.bin 224 224 +34047 ./prep_dataset/ILSVRC2012_val_00024850.bin 224 224 +34048 ./prep_dataset/ILSVRC2012_val_00039407.bin 224 224 +34049 ./prep_dataset/ILSVRC2012_val_00045198.bin 224 224 +34050 ./prep_dataset/ILSVRC2012_val_00000496.bin 224 224 +34051 ./prep_dataset/ILSVRC2012_val_00020217.bin 224 224 +34052 ./prep_dataset/ILSVRC2012_val_00010074.bin 224 224 +34053 ./prep_dataset/ILSVRC2012_val_00044263.bin 224 224 +34054 ./prep_dataset/ILSVRC2012_val_00023661.bin 224 224 +34055 ./prep_dataset/ILSVRC2012_val_00041539.bin 224 224 +34056 ./prep_dataset/ILSVRC2012_val_00004286.bin 224 224 +34057 ./prep_dataset/ILSVRC2012_val_00002441.bin 224 224 +34058 ./prep_dataset/ILSVRC2012_val_00046453.bin 224 224 +34059 ./prep_dataset/ILSVRC2012_val_00019627.bin 224 224 +34060 ./prep_dataset/ILSVRC2012_val_00035784.bin 224 224 +34061 ./prep_dataset/ILSVRC2012_val_00030941.bin 224 224 +34062 ./prep_dataset/ILSVRC2012_val_00014768.bin 224 224 +34063 ./prep_dataset/ILSVRC2012_val_00034767.bin 224 224 +34064 ./prep_dataset/ILSVRC2012_val_00036795.bin 224 224 +34065 ./prep_dataset/ILSVRC2012_val_00025180.bin 224 224 +34066 ./prep_dataset/ILSVRC2012_val_00033720.bin 224 224 +34067 ./prep_dataset/ILSVRC2012_val_00021339.bin 224 224 +34068 ./prep_dataset/ILSVRC2012_val_00035609.bin 224 224 +34069 ./prep_dataset/ILSVRC2012_val_00023113.bin 224 224 +34070 ./prep_dataset/ILSVRC2012_val_00026011.bin 224 224 +34071 ./prep_dataset/ILSVRC2012_val_00001381.bin 224 224 +34072 ./prep_dataset/ILSVRC2012_val_00027885.bin 224 224 +34073 ./prep_dataset/ILSVRC2012_val_00026680.bin 224 224 +34074 ./prep_dataset/ILSVRC2012_val_00011764.bin 224 224 +34075 ./prep_dataset/ILSVRC2012_val_00030742.bin 224 224 +34076 ./prep_dataset/ILSVRC2012_val_00030021.bin 224 224 +34077 ./prep_dataset/ILSVRC2012_val_00004827.bin 224 224 +34078 ./prep_dataset/ILSVRC2012_val_00000310.bin 224 224 +34079 ./prep_dataset/ILSVRC2012_val_00038263.bin 224 224 +34080 ./prep_dataset/ILSVRC2012_val_00008725.bin 224 224 +34081 ./prep_dataset/ILSVRC2012_val_00011253.bin 224 224 +34082 ./prep_dataset/ILSVRC2012_val_00007628.bin 224 224 +34083 ./prep_dataset/ILSVRC2012_val_00029370.bin 224 224 +34084 ./prep_dataset/ILSVRC2012_val_00046608.bin 224 224 +34085 ./prep_dataset/ILSVRC2012_val_00043271.bin 224 224 +34086 ./prep_dataset/ILSVRC2012_val_00035772.bin 224 224 +34087 ./prep_dataset/ILSVRC2012_val_00034937.bin 224 224 +34088 ./prep_dataset/ILSVRC2012_val_00016768.bin 224 224 +34089 ./prep_dataset/ILSVRC2012_val_00005467.bin 224 224 +34090 ./prep_dataset/ILSVRC2012_val_00031162.bin 224 224 +34091 ./prep_dataset/ILSVRC2012_val_00007449.bin 224 224 +34092 ./prep_dataset/ILSVRC2012_val_00049258.bin 224 224 +34093 ./prep_dataset/ILSVRC2012_val_00021446.bin 224 224 +34094 ./prep_dataset/ILSVRC2012_val_00007189.bin 224 224 +34095 ./prep_dataset/ILSVRC2012_val_00024182.bin 224 224 +34096 ./prep_dataset/ILSVRC2012_val_00028533.bin 224 224 +34097 ./prep_dataset/ILSVRC2012_val_00040843.bin 224 224 +34098 ./prep_dataset/ILSVRC2012_val_00042785.bin 224 224 +34099 ./prep_dataset/ILSVRC2012_val_00036780.bin 224 224 +34100 ./prep_dataset/ILSVRC2012_val_00038661.bin 224 224 +34101 ./prep_dataset/ILSVRC2012_val_00036020.bin 224 224 +34102 ./prep_dataset/ILSVRC2012_val_00033730.bin 224 224 +34103 ./prep_dataset/ILSVRC2012_val_00005572.bin 224 224 +34104 ./prep_dataset/ILSVRC2012_val_00002310.bin 224 224 +34105 ./prep_dataset/ILSVRC2012_val_00034609.bin 224 224 +34106 ./prep_dataset/ILSVRC2012_val_00009979.bin 224 224 +34107 ./prep_dataset/ILSVRC2012_val_00013182.bin 224 224 +34108 ./prep_dataset/ILSVRC2012_val_00008394.bin 224 224 +34109 ./prep_dataset/ILSVRC2012_val_00032684.bin 224 224 +34110 ./prep_dataset/ILSVRC2012_val_00033214.bin 224 224 +34111 ./prep_dataset/ILSVRC2012_val_00016737.bin 224 224 +34112 ./prep_dataset/ILSVRC2012_val_00035822.bin 224 224 +34113 ./prep_dataset/ILSVRC2012_val_00024097.bin 224 224 +34114 ./prep_dataset/ILSVRC2012_val_00035674.bin 224 224 +34115 ./prep_dataset/ILSVRC2012_val_00001228.bin 224 224 +34116 ./prep_dataset/ILSVRC2012_val_00029130.bin 224 224 +34117 ./prep_dataset/ILSVRC2012_val_00039503.bin 224 224 +34118 ./prep_dataset/ILSVRC2012_val_00002215.bin 224 224 +34119 ./prep_dataset/ILSVRC2012_val_00038362.bin 224 224 +34120 ./prep_dataset/ILSVRC2012_val_00031623.bin 224 224 +34121 ./prep_dataset/ILSVRC2012_val_00030423.bin 224 224 +34122 ./prep_dataset/ILSVRC2012_val_00010980.bin 224 224 +34123 ./prep_dataset/ILSVRC2012_val_00033692.bin 224 224 +34124 ./prep_dataset/ILSVRC2012_val_00032263.bin 224 224 +34125 ./prep_dataset/ILSVRC2012_val_00005948.bin 224 224 +34126 ./prep_dataset/ILSVRC2012_val_00014625.bin 224 224 +34127 ./prep_dataset/ILSVRC2012_val_00035021.bin 224 224 +34128 ./prep_dataset/ILSVRC2012_val_00043583.bin 224 224 +34129 ./prep_dataset/ILSVRC2012_val_00024610.bin 224 224 +34130 ./prep_dataset/ILSVRC2012_val_00049745.bin 224 224 +34131 ./prep_dataset/ILSVRC2012_val_00007898.bin 224 224 +34132 ./prep_dataset/ILSVRC2012_val_00014093.bin 224 224 +34133 ./prep_dataset/ILSVRC2012_val_00022276.bin 224 224 +34134 ./prep_dataset/ILSVRC2012_val_00022773.bin 224 224 +34135 ./prep_dataset/ILSVRC2012_val_00008191.bin 224 224 +34136 ./prep_dataset/ILSVRC2012_val_00049893.bin 224 224 +34137 ./prep_dataset/ILSVRC2012_val_00040159.bin 224 224 +34138 ./prep_dataset/ILSVRC2012_val_00020538.bin 224 224 +34139 ./prep_dataset/ILSVRC2012_val_00002894.bin 224 224 +34140 ./prep_dataset/ILSVRC2012_val_00039836.bin 224 224 +34141 ./prep_dataset/ILSVRC2012_val_00003626.bin 224 224 +34142 ./prep_dataset/ILSVRC2012_val_00041124.bin 224 224 +34143 ./prep_dataset/ILSVRC2012_val_00034361.bin 224 224 +34144 ./prep_dataset/ILSVRC2012_val_00038925.bin 224 224 +34145 ./prep_dataset/ILSVRC2012_val_00049527.bin 224 224 +34146 ./prep_dataset/ILSVRC2012_val_00000425.bin 224 224 +34147 ./prep_dataset/ILSVRC2012_val_00030421.bin 224 224 +34148 ./prep_dataset/ILSVRC2012_val_00013540.bin 224 224 +34149 ./prep_dataset/ILSVRC2012_val_00027224.bin 224 224 +34150 ./prep_dataset/ILSVRC2012_val_00040238.bin 224 224 +34151 ./prep_dataset/ILSVRC2012_val_00006039.bin 224 224 +34152 ./prep_dataset/ILSVRC2012_val_00045145.bin 224 224 +34153 ./prep_dataset/ILSVRC2012_val_00039620.bin 224 224 +34154 ./prep_dataset/ILSVRC2012_val_00031256.bin 224 224 +34155 ./prep_dataset/ILSVRC2012_val_00023872.bin 224 224 +34156 ./prep_dataset/ILSVRC2012_val_00022362.bin 224 224 +34157 ./prep_dataset/ILSVRC2012_val_00026168.bin 224 224 +34158 ./prep_dataset/ILSVRC2012_val_00038718.bin 224 224 +34159 ./prep_dataset/ILSVRC2012_val_00021063.bin 224 224 +34160 ./prep_dataset/ILSVRC2012_val_00016644.bin 224 224 +34161 ./prep_dataset/ILSVRC2012_val_00044903.bin 224 224 +34162 ./prep_dataset/ILSVRC2012_val_00013644.bin 224 224 +34163 ./prep_dataset/ILSVRC2012_val_00016694.bin 224 224 +34164 ./prep_dataset/ILSVRC2012_val_00039434.bin 224 224 +34165 ./prep_dataset/ILSVRC2012_val_00047267.bin 224 224 +34166 ./prep_dataset/ILSVRC2012_val_00019469.bin 224 224 +34167 ./prep_dataset/ILSVRC2012_val_00045540.bin 224 224 +34168 ./prep_dataset/ILSVRC2012_val_00037658.bin 224 224 +34169 ./prep_dataset/ILSVRC2012_val_00041840.bin 224 224 +34170 ./prep_dataset/ILSVRC2012_val_00039864.bin 224 224 +34171 ./prep_dataset/ILSVRC2012_val_00008076.bin 224 224 +34172 ./prep_dataset/ILSVRC2012_val_00031518.bin 224 224 +34173 ./prep_dataset/ILSVRC2012_val_00020488.bin 224 224 +34174 ./prep_dataset/ILSVRC2012_val_00028645.bin 224 224 +34175 ./prep_dataset/ILSVRC2012_val_00044922.bin 224 224 +34176 ./prep_dataset/ILSVRC2012_val_00021402.bin 224 224 +34177 ./prep_dataset/ILSVRC2012_val_00032768.bin 224 224 +34178 ./prep_dataset/ILSVRC2012_val_00015970.bin 224 224 +34179 ./prep_dataset/ILSVRC2012_val_00037336.bin 224 224 +34180 ./prep_dataset/ILSVRC2012_val_00023048.bin 224 224 +34181 ./prep_dataset/ILSVRC2012_val_00027648.bin 224 224 +34182 ./prep_dataset/ILSVRC2012_val_00026312.bin 224 224 +34183 ./prep_dataset/ILSVRC2012_val_00003257.bin 224 224 +34184 ./prep_dataset/ILSVRC2012_val_00026308.bin 224 224 +34185 ./prep_dataset/ILSVRC2012_val_00032911.bin 224 224 +34186 ./prep_dataset/ILSVRC2012_val_00023764.bin 224 224 +34187 ./prep_dataset/ILSVRC2012_val_00013309.bin 224 224 +34188 ./prep_dataset/ILSVRC2012_val_00009217.bin 224 224 +34189 ./prep_dataset/ILSVRC2012_val_00026870.bin 224 224 +34190 ./prep_dataset/ILSVRC2012_val_00037704.bin 224 224 +34191 ./prep_dataset/ILSVRC2012_val_00046026.bin 224 224 +34192 ./prep_dataset/ILSVRC2012_val_00046035.bin 224 224 +34193 ./prep_dataset/ILSVRC2012_val_00022184.bin 224 224 +34194 ./prep_dataset/ILSVRC2012_val_00033857.bin 224 224 +34195 ./prep_dataset/ILSVRC2012_val_00038330.bin 224 224 +34196 ./prep_dataset/ILSVRC2012_val_00046691.bin 224 224 +34197 ./prep_dataset/ILSVRC2012_val_00009195.bin 224 224 +34198 ./prep_dataset/ILSVRC2012_val_00006340.bin 224 224 +34199 ./prep_dataset/ILSVRC2012_val_00009067.bin 224 224 +34200 ./prep_dataset/ILSVRC2012_val_00022434.bin 224 224 +34201 ./prep_dataset/ILSVRC2012_val_00000966.bin 224 224 +34202 ./prep_dataset/ILSVRC2012_val_00024821.bin 224 224 +34203 ./prep_dataset/ILSVRC2012_val_00023432.bin 224 224 +34204 ./prep_dataset/ILSVRC2012_val_00005696.bin 224 224 +34205 ./prep_dataset/ILSVRC2012_val_00036460.bin 224 224 +34206 ./prep_dataset/ILSVRC2012_val_00019984.bin 224 224 +34207 ./prep_dataset/ILSVRC2012_val_00035827.bin 224 224 +34208 ./prep_dataset/ILSVRC2012_val_00028896.bin 224 224 +34209 ./prep_dataset/ILSVRC2012_val_00035218.bin 224 224 +34210 ./prep_dataset/ILSVRC2012_val_00004533.bin 224 224 +34211 ./prep_dataset/ILSVRC2012_val_00041518.bin 224 224 +34212 ./prep_dataset/ILSVRC2012_val_00018261.bin 224 224 +34213 ./prep_dataset/ILSVRC2012_val_00034580.bin 224 224 +34214 ./prep_dataset/ILSVRC2012_val_00037097.bin 224 224 +34215 ./prep_dataset/ILSVRC2012_val_00027590.bin 224 224 +34216 ./prep_dataset/ILSVRC2012_val_00023874.bin 224 224 +34217 ./prep_dataset/ILSVRC2012_val_00038351.bin 224 224 +34218 ./prep_dataset/ILSVRC2012_val_00022271.bin 224 224 +34219 ./prep_dataset/ILSVRC2012_val_00043527.bin 224 224 +34220 ./prep_dataset/ILSVRC2012_val_00019217.bin 224 224 +34221 ./prep_dataset/ILSVRC2012_val_00025752.bin 224 224 +34222 ./prep_dataset/ILSVRC2012_val_00027995.bin 224 224 +34223 ./prep_dataset/ILSVRC2012_val_00033882.bin 224 224 +34224 ./prep_dataset/ILSVRC2012_val_00038745.bin 224 224 +34225 ./prep_dataset/ILSVRC2012_val_00042373.bin 224 224 +34226 ./prep_dataset/ILSVRC2012_val_00018665.bin 224 224 +34227 ./prep_dataset/ILSVRC2012_val_00007246.bin 224 224 +34228 ./prep_dataset/ILSVRC2012_val_00047973.bin 224 224 +34229 ./prep_dataset/ILSVRC2012_val_00043713.bin 224 224 +34230 ./prep_dataset/ILSVRC2012_val_00025206.bin 224 224 +34231 ./prep_dataset/ILSVRC2012_val_00008810.bin 224 224 +34232 ./prep_dataset/ILSVRC2012_val_00034389.bin 224 224 +34233 ./prep_dataset/ILSVRC2012_val_00024079.bin 224 224 +34234 ./prep_dataset/ILSVRC2012_val_00008848.bin 224 224 +34235 ./prep_dataset/ILSVRC2012_val_00036316.bin 224 224 +34236 ./prep_dataset/ILSVRC2012_val_00002714.bin 224 224 +34237 ./prep_dataset/ILSVRC2012_val_00043363.bin 224 224 +34238 ./prep_dataset/ILSVRC2012_val_00004326.bin 224 224 +34239 ./prep_dataset/ILSVRC2012_val_00004071.bin 224 224 +34240 ./prep_dataset/ILSVRC2012_val_00023972.bin 224 224 +34241 ./prep_dataset/ILSVRC2012_val_00034525.bin 224 224 +34242 ./prep_dataset/ILSVRC2012_val_00020177.bin 224 224 +34243 ./prep_dataset/ILSVRC2012_val_00025571.bin 224 224 +34244 ./prep_dataset/ILSVRC2012_val_00013411.bin 224 224 +34245 ./prep_dataset/ILSVRC2012_val_00046555.bin 224 224 +34246 ./prep_dataset/ILSVRC2012_val_00015743.bin 224 224 +34247 ./prep_dataset/ILSVRC2012_val_00001899.bin 224 224 +34248 ./prep_dataset/ILSVRC2012_val_00010375.bin 224 224 +34249 ./prep_dataset/ILSVRC2012_val_00005188.bin 224 224 +34250 ./prep_dataset/ILSVRC2012_val_00006867.bin 224 224 +34251 ./prep_dataset/ILSVRC2012_val_00035421.bin 224 224 +34252 ./prep_dataset/ILSVRC2012_val_00035091.bin 224 224 +34253 ./prep_dataset/ILSVRC2012_val_00045185.bin 224 224 +34254 ./prep_dataset/ILSVRC2012_val_00020918.bin 224 224 +34255 ./prep_dataset/ILSVRC2012_val_00009277.bin 224 224 +34256 ./prep_dataset/ILSVRC2012_val_00016094.bin 224 224 +34257 ./prep_dataset/ILSVRC2012_val_00019844.bin 224 224 +34258 ./prep_dataset/ILSVRC2012_val_00031298.bin 224 224 +34259 ./prep_dataset/ILSVRC2012_val_00047549.bin 224 224 +34260 ./prep_dataset/ILSVRC2012_val_00011109.bin 224 224 +34261 ./prep_dataset/ILSVRC2012_val_00031465.bin 224 224 +34262 ./prep_dataset/ILSVRC2012_val_00006254.bin 224 224 +34263 ./prep_dataset/ILSVRC2012_val_00019964.bin 224 224 +34264 ./prep_dataset/ILSVRC2012_val_00044469.bin 224 224 +34265 ./prep_dataset/ILSVRC2012_val_00038728.bin 224 224 +34266 ./prep_dataset/ILSVRC2012_val_00008341.bin 224 224 +34267 ./prep_dataset/ILSVRC2012_val_00024608.bin 224 224 +34268 ./prep_dataset/ILSVRC2012_val_00034023.bin 224 224 +34269 ./prep_dataset/ILSVRC2012_val_00039072.bin 224 224 +34270 ./prep_dataset/ILSVRC2012_val_00027907.bin 224 224 +34271 ./prep_dataset/ILSVRC2012_val_00034722.bin 224 224 +34272 ./prep_dataset/ILSVRC2012_val_00033241.bin 224 224 +34273 ./prep_dataset/ILSVRC2012_val_00040089.bin 224 224 +34274 ./prep_dataset/ILSVRC2012_val_00036575.bin 224 224 +34275 ./prep_dataset/ILSVRC2012_val_00015625.bin 224 224 +34276 ./prep_dataset/ILSVRC2012_val_00032919.bin 224 224 +34277 ./prep_dataset/ILSVRC2012_val_00015887.bin 224 224 +34278 ./prep_dataset/ILSVRC2012_val_00033407.bin 224 224 +34279 ./prep_dataset/ILSVRC2012_val_00025758.bin 224 224 +34280 ./prep_dataset/ILSVRC2012_val_00037427.bin 224 224 +34281 ./prep_dataset/ILSVRC2012_val_00025679.bin 224 224 +34282 ./prep_dataset/ILSVRC2012_val_00014084.bin 224 224 +34283 ./prep_dataset/ILSVRC2012_val_00033179.bin 224 224 +34284 ./prep_dataset/ILSVRC2012_val_00022852.bin 224 224 +34285 ./prep_dataset/ILSVRC2012_val_00019250.bin 224 224 +34286 ./prep_dataset/ILSVRC2012_val_00041868.bin 224 224 +34287 ./prep_dataset/ILSVRC2012_val_00005543.bin 224 224 +34288 ./prep_dataset/ILSVRC2012_val_00009794.bin 224 224 +34289 ./prep_dataset/ILSVRC2012_val_00046151.bin 224 224 +34290 ./prep_dataset/ILSVRC2012_val_00010750.bin 224 224 +34291 ./prep_dataset/ILSVRC2012_val_00039162.bin 224 224 +34292 ./prep_dataset/ILSVRC2012_val_00030936.bin 224 224 +34293 ./prep_dataset/ILSVRC2012_val_00026511.bin 224 224 +34294 ./prep_dataset/ILSVRC2012_val_00015255.bin 224 224 +34295 ./prep_dataset/ILSVRC2012_val_00027133.bin 224 224 +34296 ./prep_dataset/ILSVRC2012_val_00033777.bin 224 224 +34297 ./prep_dataset/ILSVRC2012_val_00005748.bin 224 224 +34298 ./prep_dataset/ILSVRC2012_val_00003235.bin 224 224 +34299 ./prep_dataset/ILSVRC2012_val_00018983.bin 224 224 +34300 ./prep_dataset/ILSVRC2012_val_00044015.bin 224 224 +34301 ./prep_dataset/ILSVRC2012_val_00011859.bin 224 224 +34302 ./prep_dataset/ILSVRC2012_val_00037596.bin 224 224 +34303 ./prep_dataset/ILSVRC2012_val_00033276.bin 224 224 +34304 ./prep_dataset/ILSVRC2012_val_00013592.bin 224 224 +34305 ./prep_dataset/ILSVRC2012_val_00001496.bin 224 224 +34306 ./prep_dataset/ILSVRC2012_val_00047390.bin 224 224 +34307 ./prep_dataset/ILSVRC2012_val_00049194.bin 224 224 +34308 ./prep_dataset/ILSVRC2012_val_00039029.bin 224 224 +34309 ./prep_dataset/ILSVRC2012_val_00025694.bin 224 224 +34310 ./prep_dataset/ILSVRC2012_val_00016672.bin 224 224 +34311 ./prep_dataset/ILSVRC2012_val_00033045.bin 224 224 +34312 ./prep_dataset/ILSVRC2012_val_00037107.bin 224 224 +34313 ./prep_dataset/ILSVRC2012_val_00005382.bin 224 224 +34314 ./prep_dataset/ILSVRC2012_val_00021370.bin 224 224 +34315 ./prep_dataset/ILSVRC2012_val_00022399.bin 224 224 +34316 ./prep_dataset/ILSVRC2012_val_00022237.bin 224 224 +34317 ./prep_dataset/ILSVRC2012_val_00005134.bin 224 224 +34318 ./prep_dataset/ILSVRC2012_val_00040908.bin 224 224 +34319 ./prep_dataset/ILSVRC2012_val_00013360.bin 224 224 +34320 ./prep_dataset/ILSVRC2012_val_00025713.bin 224 224 +34321 ./prep_dataset/ILSVRC2012_val_00020378.bin 224 224 +34322 ./prep_dataset/ILSVRC2012_val_00004946.bin 224 224 +34323 ./prep_dataset/ILSVRC2012_val_00043812.bin 224 224 +34324 ./prep_dataset/ILSVRC2012_val_00002803.bin 224 224 +34325 ./prep_dataset/ILSVRC2012_val_00038418.bin 224 224 +34326 ./prep_dataset/ILSVRC2012_val_00033800.bin 224 224 +34327 ./prep_dataset/ILSVRC2012_val_00037139.bin 224 224 +34328 ./prep_dataset/ILSVRC2012_val_00001212.bin 224 224 +34329 ./prep_dataset/ILSVRC2012_val_00034566.bin 224 224 +34330 ./prep_dataset/ILSVRC2012_val_00042267.bin 224 224 +34331 ./prep_dataset/ILSVRC2012_val_00024713.bin 224 224 +34332 ./prep_dataset/ILSVRC2012_val_00046653.bin 224 224 +34333 ./prep_dataset/ILSVRC2012_val_00026033.bin 224 224 +34334 ./prep_dataset/ILSVRC2012_val_00038634.bin 224 224 +34335 ./prep_dataset/ILSVRC2012_val_00034453.bin 224 224 +34336 ./prep_dataset/ILSVRC2012_val_00012050.bin 224 224 +34337 ./prep_dataset/ILSVRC2012_val_00047493.bin 224 224 +34338 ./prep_dataset/ILSVRC2012_val_00031386.bin 224 224 +34339 ./prep_dataset/ILSVRC2012_val_00012292.bin 224 224 +34340 ./prep_dataset/ILSVRC2012_val_00039101.bin 224 224 +34341 ./prep_dataset/ILSVRC2012_val_00003440.bin 224 224 +34342 ./prep_dataset/ILSVRC2012_val_00044948.bin 224 224 +34343 ./prep_dataset/ILSVRC2012_val_00032477.bin 224 224 +34344 ./prep_dataset/ILSVRC2012_val_00024171.bin 224 224 +34345 ./prep_dataset/ILSVRC2012_val_00019602.bin 224 224 +34346 ./prep_dataset/ILSVRC2012_val_00045832.bin 224 224 +34347 ./prep_dataset/ILSVRC2012_val_00026936.bin 224 224 +34348 ./prep_dataset/ILSVRC2012_val_00027600.bin 224 224 +34349 ./prep_dataset/ILSVRC2012_val_00039776.bin 224 224 +34350 ./prep_dataset/ILSVRC2012_val_00003721.bin 224 224 +34351 ./prep_dataset/ILSVRC2012_val_00025934.bin 224 224 +34352 ./prep_dataset/ILSVRC2012_val_00039747.bin 224 224 +34353 ./prep_dataset/ILSVRC2012_val_00037734.bin 224 224 +34354 ./prep_dataset/ILSVRC2012_val_00019934.bin 224 224 +34355 ./prep_dataset/ILSVRC2012_val_00032945.bin 224 224 +34356 ./prep_dataset/ILSVRC2012_val_00036686.bin 224 224 +34357 ./prep_dataset/ILSVRC2012_val_00048244.bin 224 224 +34358 ./prep_dataset/ILSVRC2012_val_00044827.bin 224 224 +34359 ./prep_dataset/ILSVRC2012_val_00048144.bin 224 224 +34360 ./prep_dataset/ILSVRC2012_val_00014034.bin 224 224 +34361 ./prep_dataset/ILSVRC2012_val_00007805.bin 224 224 +34362 ./prep_dataset/ILSVRC2012_val_00004311.bin 224 224 +34363 ./prep_dataset/ILSVRC2012_val_00042262.bin 224 224 +34364 ./prep_dataset/ILSVRC2012_val_00004497.bin 224 224 +34365 ./prep_dataset/ILSVRC2012_val_00014310.bin 224 224 +34366 ./prep_dataset/ILSVRC2012_val_00026049.bin 224 224 +34367 ./prep_dataset/ILSVRC2012_val_00032278.bin 224 224 +34368 ./prep_dataset/ILSVRC2012_val_00049564.bin 224 224 +34369 ./prep_dataset/ILSVRC2012_val_00025052.bin 224 224 +34370 ./prep_dataset/ILSVRC2012_val_00021013.bin 224 224 +34371 ./prep_dataset/ILSVRC2012_val_00046093.bin 224 224 +34372 ./prep_dataset/ILSVRC2012_val_00027235.bin 224 224 +34373 ./prep_dataset/ILSVRC2012_val_00017790.bin 224 224 +34374 ./prep_dataset/ILSVRC2012_val_00034547.bin 224 224 +34375 ./prep_dataset/ILSVRC2012_val_00018097.bin 224 224 +34376 ./prep_dataset/ILSVRC2012_val_00024541.bin 224 224 +34377 ./prep_dataset/ILSVRC2012_val_00024256.bin 224 224 +34378 ./prep_dataset/ILSVRC2012_val_00029681.bin 224 224 +34379 ./prep_dataset/ILSVRC2012_val_00015781.bin 224 224 +34380 ./prep_dataset/ILSVRC2012_val_00022986.bin 224 224 +34381 ./prep_dataset/ILSVRC2012_val_00009638.bin 224 224 +34382 ./prep_dataset/ILSVRC2012_val_00002637.bin 224 224 +34383 ./prep_dataset/ILSVRC2012_val_00013042.bin 224 224 +34384 ./prep_dataset/ILSVRC2012_val_00032494.bin 224 224 +34385 ./prep_dataset/ILSVRC2012_val_00025569.bin 224 224 +34386 ./prep_dataset/ILSVRC2012_val_00017198.bin 224 224 +34387 ./prep_dataset/ILSVRC2012_val_00047589.bin 224 224 +34388 ./prep_dataset/ILSVRC2012_val_00020084.bin 224 224 +34389 ./prep_dataset/ILSVRC2012_val_00020845.bin 224 224 +34390 ./prep_dataset/ILSVRC2012_val_00040534.bin 224 224 +34391 ./prep_dataset/ILSVRC2012_val_00000313.bin 224 224 +34392 ./prep_dataset/ILSVRC2012_val_00029418.bin 224 224 +34393 ./prep_dataset/ILSVRC2012_val_00001952.bin 224 224 +34394 ./prep_dataset/ILSVRC2012_val_00048299.bin 224 224 +34395 ./prep_dataset/ILSVRC2012_val_00007218.bin 224 224 +34396 ./prep_dataset/ILSVRC2012_val_00007438.bin 224 224 +34397 ./prep_dataset/ILSVRC2012_val_00006756.bin 224 224 +34398 ./prep_dataset/ILSVRC2012_val_00007401.bin 224 224 +34399 ./prep_dataset/ILSVRC2012_val_00008829.bin 224 224 +34400 ./prep_dataset/ILSVRC2012_val_00012120.bin 224 224 +34401 ./prep_dataset/ILSVRC2012_val_00043813.bin 224 224 +34402 ./prep_dataset/ILSVRC2012_val_00048940.bin 224 224 +34403 ./prep_dataset/ILSVRC2012_val_00030290.bin 224 224 +34404 ./prep_dataset/ILSVRC2012_val_00028417.bin 224 224 +34405 ./prep_dataset/ILSVRC2012_val_00006784.bin 224 224 +34406 ./prep_dataset/ILSVRC2012_val_00020387.bin 224 224 +34407 ./prep_dataset/ILSVRC2012_val_00041711.bin 224 224 +34408 ./prep_dataset/ILSVRC2012_val_00042300.bin 224 224 +34409 ./prep_dataset/ILSVRC2012_val_00035622.bin 224 224 +34410 ./prep_dataset/ILSVRC2012_val_00019106.bin 224 224 +34411 ./prep_dataset/ILSVRC2012_val_00016406.bin 224 224 +34412 ./prep_dataset/ILSVRC2012_val_00042609.bin 224 224 +34413 ./prep_dataset/ILSVRC2012_val_00043219.bin 224 224 +34414 ./prep_dataset/ILSVRC2012_val_00015567.bin 224 224 +34415 ./prep_dataset/ILSVRC2012_val_00031317.bin 224 224 +34416 ./prep_dataset/ILSVRC2012_val_00025276.bin 224 224 +34417 ./prep_dataset/ILSVRC2012_val_00017992.bin 224 224 +34418 ./prep_dataset/ILSVRC2012_val_00040369.bin 224 224 +34419 ./prep_dataset/ILSVRC2012_val_00040335.bin 224 224 +34420 ./prep_dataset/ILSVRC2012_val_00004128.bin 224 224 +34421 ./prep_dataset/ILSVRC2012_val_00039459.bin 224 224 +34422 ./prep_dataset/ILSVRC2012_val_00021296.bin 224 224 +34423 ./prep_dataset/ILSVRC2012_val_00047206.bin 224 224 +34424 ./prep_dataset/ILSVRC2012_val_00028914.bin 224 224 +34425 ./prep_dataset/ILSVRC2012_val_00013239.bin 224 224 +34426 ./prep_dataset/ILSVRC2012_val_00048203.bin 224 224 +34427 ./prep_dataset/ILSVRC2012_val_00029002.bin 224 224 +34428 ./prep_dataset/ILSVRC2012_val_00009804.bin 224 224 +34429 ./prep_dataset/ILSVRC2012_val_00042607.bin 224 224 +34430 ./prep_dataset/ILSVRC2012_val_00035477.bin 224 224 +34431 ./prep_dataset/ILSVRC2012_val_00015667.bin 224 224 +34432 ./prep_dataset/ILSVRC2012_val_00040186.bin 224 224 +34433 ./prep_dataset/ILSVRC2012_val_00040968.bin 224 224 +34434 ./prep_dataset/ILSVRC2012_val_00024390.bin 224 224 +34435 ./prep_dataset/ILSVRC2012_val_00025002.bin 224 224 +34436 ./prep_dataset/ILSVRC2012_val_00036874.bin 224 224 +34437 ./prep_dataset/ILSVRC2012_val_00019251.bin 224 224 +34438 ./prep_dataset/ILSVRC2012_val_00044971.bin 224 224 +34439 ./prep_dataset/ILSVRC2012_val_00043949.bin 224 224 +34440 ./prep_dataset/ILSVRC2012_val_00021984.bin 224 224 +34441 ./prep_dataset/ILSVRC2012_val_00016418.bin 224 224 +34442 ./prep_dataset/ILSVRC2012_val_00026744.bin 224 224 +34443 ./prep_dataset/ILSVRC2012_val_00034409.bin 224 224 +34444 ./prep_dataset/ILSVRC2012_val_00012351.bin 224 224 +34445 ./prep_dataset/ILSVRC2012_val_00028910.bin 224 224 +34446 ./prep_dataset/ILSVRC2012_val_00047055.bin 224 224 +34447 ./prep_dataset/ILSVRC2012_val_00037805.bin 224 224 +34448 ./prep_dataset/ILSVRC2012_val_00021305.bin 224 224 +34449 ./prep_dataset/ILSVRC2012_val_00025056.bin 224 224 +34450 ./prep_dataset/ILSVRC2012_val_00026566.bin 224 224 +34451 ./prep_dataset/ILSVRC2012_val_00040924.bin 224 224 +34452 ./prep_dataset/ILSVRC2012_val_00001353.bin 224 224 +34453 ./prep_dataset/ILSVRC2012_val_00031440.bin 224 224 +34454 ./prep_dataset/ILSVRC2012_val_00023293.bin 224 224 +34455 ./prep_dataset/ILSVRC2012_val_00039197.bin 224 224 +34456 ./prep_dataset/ILSVRC2012_val_00023577.bin 224 224 +34457 ./prep_dataset/ILSVRC2012_val_00028506.bin 224 224 +34458 ./prep_dataset/ILSVRC2012_val_00031761.bin 224 224 +34459 ./prep_dataset/ILSVRC2012_val_00046071.bin 224 224 +34460 ./prep_dataset/ILSVRC2012_val_00027323.bin 224 224 +34461 ./prep_dataset/ILSVRC2012_val_00006983.bin 224 224 +34462 ./prep_dataset/ILSVRC2012_val_00046086.bin 224 224 +34463 ./prep_dataset/ILSVRC2012_val_00001807.bin 224 224 +34464 ./prep_dataset/ILSVRC2012_val_00004354.bin 224 224 +34465 ./prep_dataset/ILSVRC2012_val_00029151.bin 224 224 +34466 ./prep_dataset/ILSVRC2012_val_00047119.bin 224 224 +34467 ./prep_dataset/ILSVRC2012_val_00038978.bin 224 224 +34468 ./prep_dataset/ILSVRC2012_val_00044288.bin 224 224 +34469 ./prep_dataset/ILSVRC2012_val_00047534.bin 224 224 +34470 ./prep_dataset/ILSVRC2012_val_00030616.bin 224 224 +34471 ./prep_dataset/ILSVRC2012_val_00024313.bin 224 224 +34472 ./prep_dataset/ILSVRC2012_val_00048028.bin 224 224 +34473 ./prep_dataset/ILSVRC2012_val_00032830.bin 224 224 +34474 ./prep_dataset/ILSVRC2012_val_00022842.bin 224 224 +34475 ./prep_dataset/ILSVRC2012_val_00048098.bin 224 224 +34476 ./prep_dataset/ILSVRC2012_val_00043214.bin 224 224 +34477 ./prep_dataset/ILSVRC2012_val_00027683.bin 224 224 +34478 ./prep_dataset/ILSVRC2012_val_00017248.bin 224 224 +34479 ./prep_dataset/ILSVRC2012_val_00016656.bin 224 224 +34480 ./prep_dataset/ILSVRC2012_val_00003857.bin 224 224 +34481 ./prep_dataset/ILSVRC2012_val_00022909.bin 224 224 +34482 ./prep_dataset/ILSVRC2012_val_00021383.bin 224 224 +34483 ./prep_dataset/ILSVRC2012_val_00007617.bin 224 224 +34484 ./prep_dataset/ILSVRC2012_val_00007534.bin 224 224 +34485 ./prep_dataset/ILSVRC2012_val_00013836.bin 224 224 +34486 ./prep_dataset/ILSVRC2012_val_00033853.bin 224 224 +34487 ./prep_dataset/ILSVRC2012_val_00005683.bin 224 224 +34488 ./prep_dataset/ILSVRC2012_val_00021266.bin 224 224 +34489 ./prep_dataset/ILSVRC2012_val_00017713.bin 224 224 +34490 ./prep_dataset/ILSVRC2012_val_00006172.bin 224 224 +34491 ./prep_dataset/ILSVRC2012_val_00022094.bin 224 224 +34492 ./prep_dataset/ILSVRC2012_val_00015101.bin 224 224 +34493 ./prep_dataset/ILSVRC2012_val_00024405.bin 224 224 +34494 ./prep_dataset/ILSVRC2012_val_00038868.bin 224 224 +34495 ./prep_dataset/ILSVRC2012_val_00016400.bin 224 224 +34496 ./prep_dataset/ILSVRC2012_val_00040409.bin 224 224 +34497 ./prep_dataset/ILSVRC2012_val_00011390.bin 224 224 +34498 ./prep_dataset/ILSVRC2012_val_00028993.bin 224 224 +34499 ./prep_dataset/ILSVRC2012_val_00033572.bin 224 224 +34500 ./prep_dataset/ILSVRC2012_val_00033922.bin 224 224 +34501 ./prep_dataset/ILSVRC2012_val_00014436.bin 224 224 +34502 ./prep_dataset/ILSVRC2012_val_00039837.bin 224 224 +34503 ./prep_dataset/ILSVRC2012_val_00040308.bin 224 224 +34504 ./prep_dataset/ILSVRC2012_val_00018666.bin 224 224 +34505 ./prep_dataset/ILSVRC2012_val_00049308.bin 224 224 +34506 ./prep_dataset/ILSVRC2012_val_00025936.bin 224 224 +34507 ./prep_dataset/ILSVRC2012_val_00048860.bin 224 224 +34508 ./prep_dataset/ILSVRC2012_val_00043323.bin 224 224 +34509 ./prep_dataset/ILSVRC2012_val_00018288.bin 224 224 +34510 ./prep_dataset/ILSVRC2012_val_00004112.bin 224 224 +34511 ./prep_dataset/ILSVRC2012_val_00044746.bin 224 224 +34512 ./prep_dataset/ILSVRC2012_val_00041956.bin 224 224 +34513 ./prep_dataset/ILSVRC2012_val_00042642.bin 224 224 +34514 ./prep_dataset/ILSVRC2012_val_00000828.bin 224 224 +34515 ./prep_dataset/ILSVRC2012_val_00039928.bin 224 224 +34516 ./prep_dataset/ILSVRC2012_val_00007872.bin 224 224 +34517 ./prep_dataset/ILSVRC2012_val_00027466.bin 224 224 +34518 ./prep_dataset/ILSVRC2012_val_00003166.bin 224 224 +34519 ./prep_dataset/ILSVRC2012_val_00032900.bin 224 224 +34520 ./prep_dataset/ILSVRC2012_val_00023641.bin 224 224 +34521 ./prep_dataset/ILSVRC2012_val_00013651.bin 224 224 +34522 ./prep_dataset/ILSVRC2012_val_00008245.bin 224 224 +34523 ./prep_dataset/ILSVRC2012_val_00040035.bin 224 224 +34524 ./prep_dataset/ILSVRC2012_val_00011117.bin 224 224 +34525 ./prep_dataset/ILSVRC2012_val_00007149.bin 224 224 +34526 ./prep_dataset/ILSVRC2012_val_00012036.bin 224 224 +34527 ./prep_dataset/ILSVRC2012_val_00009330.bin 224 224 +34528 ./prep_dataset/ILSVRC2012_val_00047391.bin 224 224 +34529 ./prep_dataset/ILSVRC2012_val_00022947.bin 224 224 +34530 ./prep_dataset/ILSVRC2012_val_00046335.bin 224 224 +34531 ./prep_dataset/ILSVRC2012_val_00024449.bin 224 224 +34532 ./prep_dataset/ILSVRC2012_val_00044808.bin 224 224 +34533 ./prep_dataset/ILSVRC2012_val_00003590.bin 224 224 +34534 ./prep_dataset/ILSVRC2012_val_00027217.bin 224 224 +34535 ./prep_dataset/ILSVRC2012_val_00043923.bin 224 224 +34536 ./prep_dataset/ILSVRC2012_val_00023721.bin 224 224 +34537 ./prep_dataset/ILSVRC2012_val_00039170.bin 224 224 +34538 ./prep_dataset/ILSVRC2012_val_00019809.bin 224 224 +34539 ./prep_dataset/ILSVRC2012_val_00017601.bin 224 224 +34540 ./prep_dataset/ILSVRC2012_val_00043142.bin 224 224 +34541 ./prep_dataset/ILSVRC2012_val_00040511.bin 224 224 +34542 ./prep_dataset/ILSVRC2012_val_00038130.bin 224 224 +34543 ./prep_dataset/ILSVRC2012_val_00025072.bin 224 224 +34544 ./prep_dataset/ILSVRC2012_val_00030420.bin 224 224 +34545 ./prep_dataset/ILSVRC2012_val_00035851.bin 224 224 +34546 ./prep_dataset/ILSVRC2012_val_00013219.bin 224 224 +34547 ./prep_dataset/ILSVRC2012_val_00015716.bin 224 224 +34548 ./prep_dataset/ILSVRC2012_val_00008058.bin 224 224 +34549 ./prep_dataset/ILSVRC2012_val_00011226.bin 224 224 +34550 ./prep_dataset/ILSVRC2012_val_00044780.bin 224 224 +34551 ./prep_dataset/ILSVRC2012_val_00017419.bin 224 224 +34552 ./prep_dataset/ILSVRC2012_val_00005240.bin 224 224 +34553 ./prep_dataset/ILSVRC2012_val_00036132.bin 224 224 +34554 ./prep_dataset/ILSVRC2012_val_00009461.bin 224 224 +34555 ./prep_dataset/ILSVRC2012_val_00014802.bin 224 224 +34556 ./prep_dataset/ILSVRC2012_val_00045737.bin 224 224 +34557 ./prep_dataset/ILSVRC2012_val_00006352.bin 224 224 +34558 ./prep_dataset/ILSVRC2012_val_00033952.bin 224 224 +34559 ./prep_dataset/ILSVRC2012_val_00028432.bin 224 224 +34560 ./prep_dataset/ILSVRC2012_val_00026672.bin 224 224 +34561 ./prep_dataset/ILSVRC2012_val_00022258.bin 224 224 +34562 ./prep_dataset/ILSVRC2012_val_00035086.bin 224 224 +34563 ./prep_dataset/ILSVRC2012_val_00000184.bin 224 224 +34564 ./prep_dataset/ILSVRC2012_val_00018934.bin 224 224 +34565 ./prep_dataset/ILSVRC2012_val_00025234.bin 224 224 +34566 ./prep_dataset/ILSVRC2012_val_00007989.bin 224 224 +34567 ./prep_dataset/ILSVRC2012_val_00008579.bin 224 224 +34568 ./prep_dataset/ILSVRC2012_val_00004177.bin 224 224 +34569 ./prep_dataset/ILSVRC2012_val_00032949.bin 224 224 +34570 ./prep_dataset/ILSVRC2012_val_00047429.bin 224 224 +34571 ./prep_dataset/ILSVRC2012_val_00029164.bin 224 224 +34572 ./prep_dataset/ILSVRC2012_val_00040632.bin 224 224 +34573 ./prep_dataset/ILSVRC2012_val_00041266.bin 224 224 +34574 ./prep_dataset/ILSVRC2012_val_00002008.bin 224 224 +34575 ./prep_dataset/ILSVRC2012_val_00022881.bin 224 224 +34576 ./prep_dataset/ILSVRC2012_val_00011565.bin 224 224 +34577 ./prep_dataset/ILSVRC2012_val_00034977.bin 224 224 +34578 ./prep_dataset/ILSVRC2012_val_00047953.bin 224 224 +34579 ./prep_dataset/ILSVRC2012_val_00048916.bin 224 224 +34580 ./prep_dataset/ILSVRC2012_val_00032637.bin 224 224 +34581 ./prep_dataset/ILSVRC2012_val_00031037.bin 224 224 +34582 ./prep_dataset/ILSVRC2012_val_00034984.bin 224 224 +34583 ./prep_dataset/ILSVRC2012_val_00020871.bin 224 224 +34584 ./prep_dataset/ILSVRC2012_val_00006055.bin 224 224 +34585 ./prep_dataset/ILSVRC2012_val_00002438.bin 224 224 +34586 ./prep_dataset/ILSVRC2012_val_00026723.bin 224 224 +34587 ./prep_dataset/ILSVRC2012_val_00045018.bin 224 224 +34588 ./prep_dataset/ILSVRC2012_val_00030606.bin 224 224 +34589 ./prep_dataset/ILSVRC2012_val_00006968.bin 224 224 +34590 ./prep_dataset/ILSVRC2012_val_00033136.bin 224 224 +34591 ./prep_dataset/ILSVRC2012_val_00012877.bin 224 224 +34592 ./prep_dataset/ILSVRC2012_val_00010176.bin 224 224 +34593 ./prep_dataset/ILSVRC2012_val_00010603.bin 224 224 +34594 ./prep_dataset/ILSVRC2012_val_00041472.bin 224 224 +34595 ./prep_dataset/ILSVRC2012_val_00039073.bin 224 224 +34596 ./prep_dataset/ILSVRC2012_val_00038939.bin 224 224 +34597 ./prep_dataset/ILSVRC2012_val_00018937.bin 224 224 +34598 ./prep_dataset/ILSVRC2012_val_00009496.bin 224 224 +34599 ./prep_dataset/ILSVRC2012_val_00001538.bin 224 224 +34600 ./prep_dataset/ILSVRC2012_val_00033779.bin 224 224 +34601 ./prep_dataset/ILSVRC2012_val_00006476.bin 224 224 +34602 ./prep_dataset/ILSVRC2012_val_00014119.bin 224 224 +34603 ./prep_dataset/ILSVRC2012_val_00011377.bin 224 224 +34604 ./prep_dataset/ILSVRC2012_val_00045357.bin 224 224 +34605 ./prep_dataset/ILSVRC2012_val_00040845.bin 224 224 +34606 ./prep_dataset/ILSVRC2012_val_00003173.bin 224 224 +34607 ./prep_dataset/ILSVRC2012_val_00046344.bin 224 224 +34608 ./prep_dataset/ILSVRC2012_val_00005749.bin 224 224 +34609 ./prep_dataset/ILSVRC2012_val_00041500.bin 224 224 +34610 ./prep_dataset/ILSVRC2012_val_00000452.bin 224 224 +34611 ./prep_dataset/ILSVRC2012_val_00024004.bin 224 224 +34612 ./prep_dataset/ILSVRC2012_val_00014174.bin 224 224 +34613 ./prep_dataset/ILSVRC2012_val_00011063.bin 224 224 +34614 ./prep_dataset/ILSVRC2012_val_00029669.bin 224 224 +34615 ./prep_dataset/ILSVRC2012_val_00027143.bin 224 224 +34616 ./prep_dataset/ILSVRC2012_val_00009513.bin 224 224 +34617 ./prep_dataset/ILSVRC2012_val_00013533.bin 224 224 +34618 ./prep_dataset/ILSVRC2012_val_00012215.bin 224 224 +34619 ./prep_dataset/ILSVRC2012_val_00047244.bin 224 224 +34620 ./prep_dataset/ILSVRC2012_val_00009350.bin 224 224 +34621 ./prep_dataset/ILSVRC2012_val_00013553.bin 224 224 +34622 ./prep_dataset/ILSVRC2012_val_00045664.bin 224 224 +34623 ./prep_dataset/ILSVRC2012_val_00046364.bin 224 224 +34624 ./prep_dataset/ILSVRC2012_val_00029823.bin 224 224 +34625 ./prep_dataset/ILSVRC2012_val_00039504.bin 224 224 +34626 ./prep_dataset/ILSVRC2012_val_00037712.bin 224 224 +34627 ./prep_dataset/ILSVRC2012_val_00042121.bin 224 224 +34628 ./prep_dataset/ILSVRC2012_val_00032393.bin 224 224 +34629 ./prep_dataset/ILSVRC2012_val_00006508.bin 224 224 +34630 ./prep_dataset/ILSVRC2012_val_00019773.bin 224 224 +34631 ./prep_dataset/ILSVRC2012_val_00036976.bin 224 224 +34632 ./prep_dataset/ILSVRC2012_val_00047084.bin 224 224 +34633 ./prep_dataset/ILSVRC2012_val_00029967.bin 224 224 +34634 ./prep_dataset/ILSVRC2012_val_00019824.bin 224 224 +34635 ./prep_dataset/ILSVRC2012_val_00006586.bin 224 224 +34636 ./prep_dataset/ILSVRC2012_val_00029633.bin 224 224 +34637 ./prep_dataset/ILSVRC2012_val_00036984.bin 224 224 +34638 ./prep_dataset/ILSVRC2012_val_00004308.bin 224 224 +34639 ./prep_dataset/ILSVRC2012_val_00025137.bin 224 224 +34640 ./prep_dataset/ILSVRC2012_val_00002276.bin 224 224 +34641 ./prep_dataset/ILSVRC2012_val_00004304.bin 224 224 +34642 ./prep_dataset/ILSVRC2012_val_00032370.bin 224 224 +34643 ./prep_dataset/ILSVRC2012_val_00014832.bin 224 224 +34644 ./prep_dataset/ILSVRC2012_val_00023416.bin 224 224 +34645 ./prep_dataset/ILSVRC2012_val_00044560.bin 224 224 +34646 ./prep_dataset/ILSVRC2012_val_00037577.bin 224 224 +34647 ./prep_dataset/ILSVRC2012_val_00012221.bin 224 224 +34648 ./prep_dataset/ILSVRC2012_val_00009346.bin 224 224 +34649 ./prep_dataset/ILSVRC2012_val_00002529.bin 224 224 +34650 ./prep_dataset/ILSVRC2012_val_00042952.bin 224 224 +34651 ./prep_dataset/ILSVRC2012_val_00036508.bin 224 224 +34652 ./prep_dataset/ILSVRC2012_val_00028412.bin 224 224 +34653 ./prep_dataset/ILSVRC2012_val_00039239.bin 224 224 +34654 ./prep_dataset/ILSVRC2012_val_00008670.bin 224 224 +34655 ./prep_dataset/ILSVRC2012_val_00032371.bin 224 224 +34656 ./prep_dataset/ILSVRC2012_val_00046769.bin 224 224 +34657 ./prep_dataset/ILSVRC2012_val_00016821.bin 224 224 +34658 ./prep_dataset/ILSVRC2012_val_00019302.bin 224 224 +34659 ./prep_dataset/ILSVRC2012_val_00003502.bin 224 224 +34660 ./prep_dataset/ILSVRC2012_val_00010309.bin 224 224 +34661 ./prep_dataset/ILSVRC2012_val_00015651.bin 224 224 +34662 ./prep_dataset/ILSVRC2012_val_00000686.bin 224 224 +34663 ./prep_dataset/ILSVRC2012_val_00014331.bin 224 224 +34664 ./prep_dataset/ILSVRC2012_val_00001765.bin 224 224 +34665 ./prep_dataset/ILSVRC2012_val_00022836.bin 224 224 +34666 ./prep_dataset/ILSVRC2012_val_00007885.bin 224 224 +34667 ./prep_dataset/ILSVRC2012_val_00011492.bin 224 224 +34668 ./prep_dataset/ILSVRC2012_val_00047693.bin 224 224 +34669 ./prep_dataset/ILSVRC2012_val_00033420.bin 224 224 +34670 ./prep_dataset/ILSVRC2012_val_00009127.bin 224 224 +34671 ./prep_dataset/ILSVRC2012_val_00015234.bin 224 224 +34672 ./prep_dataset/ILSVRC2012_val_00015049.bin 224 224 +34673 ./prep_dataset/ILSVRC2012_val_00042631.bin 224 224 +34674 ./prep_dataset/ILSVRC2012_val_00009008.bin 224 224 +34675 ./prep_dataset/ILSVRC2012_val_00000400.bin 224 224 +34676 ./prep_dataset/ILSVRC2012_val_00001034.bin 224 224 +34677 ./prep_dataset/ILSVRC2012_val_00048312.bin 224 224 +34678 ./prep_dataset/ILSVRC2012_val_00008821.bin 224 224 +34679 ./prep_dataset/ILSVRC2012_val_00021641.bin 224 224 +34680 ./prep_dataset/ILSVRC2012_val_00008824.bin 224 224 +34681 ./prep_dataset/ILSVRC2012_val_00015523.bin 224 224 +34682 ./prep_dataset/ILSVRC2012_val_00047399.bin 224 224 +34683 ./prep_dataset/ILSVRC2012_val_00032322.bin 224 224 +34684 ./prep_dataset/ILSVRC2012_val_00016944.bin 224 224 +34685 ./prep_dataset/ILSVRC2012_val_00045012.bin 224 224 +34686 ./prep_dataset/ILSVRC2012_val_00040592.bin 224 224 +34687 ./prep_dataset/ILSVRC2012_val_00012421.bin 224 224 +34688 ./prep_dataset/ILSVRC2012_val_00009030.bin 224 224 +34689 ./prep_dataset/ILSVRC2012_val_00049600.bin 224 224 +34690 ./prep_dataset/ILSVRC2012_val_00020831.bin 224 224 +34691 ./prep_dataset/ILSVRC2012_val_00027009.bin 224 224 +34692 ./prep_dataset/ILSVRC2012_val_00000943.bin 224 224 +34693 ./prep_dataset/ILSVRC2012_val_00043606.bin 224 224 +34694 ./prep_dataset/ILSVRC2012_val_00016866.bin 224 224 +34695 ./prep_dataset/ILSVRC2012_val_00027488.bin 224 224 +34696 ./prep_dataset/ILSVRC2012_val_00004952.bin 224 224 +34697 ./prep_dataset/ILSVRC2012_val_00030175.bin 224 224 +34698 ./prep_dataset/ILSVRC2012_val_00038695.bin 224 224 +34699 ./prep_dataset/ILSVRC2012_val_00010465.bin 224 224 +34700 ./prep_dataset/ILSVRC2012_val_00028955.bin 224 224 +34701 ./prep_dataset/ILSVRC2012_val_00041828.bin 224 224 +34702 ./prep_dataset/ILSVRC2012_val_00044934.bin 224 224 +34703 ./prep_dataset/ILSVRC2012_val_00032301.bin 224 224 +34704 ./prep_dataset/ILSVRC2012_val_00010163.bin 224 224 +34705 ./prep_dataset/ILSVRC2012_val_00028468.bin 224 224 +34706 ./prep_dataset/ILSVRC2012_val_00024861.bin 224 224 +34707 ./prep_dataset/ILSVRC2012_val_00025158.bin 224 224 +34708 ./prep_dataset/ILSVRC2012_val_00026900.bin 224 224 +34709 ./prep_dataset/ILSVRC2012_val_00020075.bin 224 224 +34710 ./prep_dataset/ILSVRC2012_val_00034188.bin 224 224 +34711 ./prep_dataset/ILSVRC2012_val_00000690.bin 224 224 +34712 ./prep_dataset/ILSVRC2012_val_00006812.bin 224 224 +34713 ./prep_dataset/ILSVRC2012_val_00013009.bin 224 224 +34714 ./prep_dataset/ILSVRC2012_val_00004734.bin 224 224 +34715 ./prep_dataset/ILSVRC2012_val_00035945.bin 224 224 +34716 ./prep_dataset/ILSVRC2012_val_00025092.bin 224 224 +34717 ./prep_dataset/ILSVRC2012_val_00019703.bin 224 224 +34718 ./prep_dataset/ILSVRC2012_val_00027505.bin 224 224 +34719 ./prep_dataset/ILSVRC2012_val_00012289.bin 224 224 +34720 ./prep_dataset/ILSVRC2012_val_00045106.bin 224 224 +34721 ./prep_dataset/ILSVRC2012_val_00006027.bin 224 224 +34722 ./prep_dataset/ILSVRC2012_val_00003987.bin 224 224 +34723 ./prep_dataset/ILSVRC2012_val_00003965.bin 224 224 +34724 ./prep_dataset/ILSVRC2012_val_00015655.bin 224 224 +34725 ./prep_dataset/ILSVRC2012_val_00016136.bin 224 224 +34726 ./prep_dataset/ILSVRC2012_val_00002047.bin 224 224 +34727 ./prep_dataset/ILSVRC2012_val_00040277.bin 224 224 +34728 ./prep_dataset/ILSVRC2012_val_00046636.bin 224 224 +34729 ./prep_dataset/ILSVRC2012_val_00035705.bin 224 224 +34730 ./prep_dataset/ILSVRC2012_val_00021237.bin 224 224 +34731 ./prep_dataset/ILSVRC2012_val_00019862.bin 224 224 +34732 ./prep_dataset/ILSVRC2012_val_00030200.bin 224 224 +34733 ./prep_dataset/ILSVRC2012_val_00040680.bin 224 224 +34734 ./prep_dataset/ILSVRC2012_val_00012657.bin 224 224 +34735 ./prep_dataset/ILSVRC2012_val_00046535.bin 224 224 +34736 ./prep_dataset/ILSVRC2012_val_00027817.bin 224 224 +34737 ./prep_dataset/ILSVRC2012_val_00008961.bin 224 224 +34738 ./prep_dataset/ILSVRC2012_val_00030530.bin 224 224 +34739 ./prep_dataset/ILSVRC2012_val_00028503.bin 224 224 +34740 ./prep_dataset/ILSVRC2012_val_00045741.bin 224 224 +34741 ./prep_dataset/ILSVRC2012_val_00005515.bin 224 224 +34742 ./prep_dataset/ILSVRC2012_val_00015590.bin 224 224 +34743 ./prep_dataset/ILSVRC2012_val_00005483.bin 224 224 +34744 ./prep_dataset/ILSVRC2012_val_00031052.bin 224 224 +34745 ./prep_dataset/ILSVRC2012_val_00034230.bin 224 224 +34746 ./prep_dataset/ILSVRC2012_val_00013915.bin 224 224 +34747 ./prep_dataset/ILSVRC2012_val_00004091.bin 224 224 +34748 ./prep_dataset/ILSVRC2012_val_00008926.bin 224 224 +34749 ./prep_dataset/ILSVRC2012_val_00016306.bin 224 224 +34750 ./prep_dataset/ILSVRC2012_val_00017444.bin 224 224 +34751 ./prep_dataset/ILSVRC2012_val_00043904.bin 224 224 +34752 ./prep_dataset/ILSVRC2012_val_00009136.bin 224 224 +34753 ./prep_dataset/ILSVRC2012_val_00038678.bin 224 224 +34754 ./prep_dataset/ILSVRC2012_val_00026209.bin 224 224 +34755 ./prep_dataset/ILSVRC2012_val_00000918.bin 224 224 +34756 ./prep_dataset/ILSVRC2012_val_00047350.bin 224 224 +34757 ./prep_dataset/ILSVRC2012_val_00025087.bin 224 224 +34758 ./prep_dataset/ILSVRC2012_val_00024602.bin 224 224 +34759 ./prep_dataset/ILSVRC2012_val_00025455.bin 224 224 +34760 ./prep_dataset/ILSVRC2012_val_00025127.bin 224 224 +34761 ./prep_dataset/ILSVRC2012_val_00007317.bin 224 224 +34762 ./prep_dataset/ILSVRC2012_val_00029541.bin 224 224 +34763 ./prep_dataset/ILSVRC2012_val_00013892.bin 224 224 +34764 ./prep_dataset/ILSVRC2012_val_00024542.bin 224 224 +34765 ./prep_dataset/ILSVRC2012_val_00001998.bin 224 224 +34766 ./prep_dataset/ILSVRC2012_val_00020391.bin 224 224 +34767 ./prep_dataset/ILSVRC2012_val_00012297.bin 224 224 +34768 ./prep_dataset/ILSVRC2012_val_00010506.bin 224 224 +34769 ./prep_dataset/ILSVRC2012_val_00011180.bin 224 224 +34770 ./prep_dataset/ILSVRC2012_val_00011333.bin 224 224 +34771 ./prep_dataset/ILSVRC2012_val_00041061.bin 224 224 +34772 ./prep_dataset/ILSVRC2012_val_00000516.bin 224 224 +34773 ./prep_dataset/ILSVRC2012_val_00002919.bin 224 224 +34774 ./prep_dataset/ILSVRC2012_val_00022920.bin 224 224 +34775 ./prep_dataset/ILSVRC2012_val_00043776.bin 224 224 +34776 ./prep_dataset/ILSVRC2012_val_00022016.bin 224 224 +34777 ./prep_dataset/ILSVRC2012_val_00002917.bin 224 224 +34778 ./prep_dataset/ILSVRC2012_val_00044722.bin 224 224 +34779 ./prep_dataset/ILSVRC2012_val_00042645.bin 224 224 +34780 ./prep_dataset/ILSVRC2012_val_00009642.bin 224 224 +34781 ./prep_dataset/ILSVRC2012_val_00003717.bin 224 224 +34782 ./prep_dataset/ILSVRC2012_val_00018987.bin 224 224 +34783 ./prep_dataset/ILSVRC2012_val_00041355.bin 224 224 +34784 ./prep_dataset/ILSVRC2012_val_00012409.bin 224 224 +34785 ./prep_dataset/ILSVRC2012_val_00010971.bin 224 224 +34786 ./prep_dataset/ILSVRC2012_val_00014524.bin 224 224 +34787 ./prep_dataset/ILSVRC2012_val_00024873.bin 224 224 +34788 ./prep_dataset/ILSVRC2012_val_00033573.bin 224 224 +34789 ./prep_dataset/ILSVRC2012_val_00033653.bin 224 224 +34790 ./prep_dataset/ILSVRC2012_val_00008800.bin 224 224 +34791 ./prep_dataset/ILSVRC2012_val_00030401.bin 224 224 +34792 ./prep_dataset/ILSVRC2012_val_00026534.bin 224 224 +34793 ./prep_dataset/ILSVRC2012_val_00040313.bin 224 224 +34794 ./prep_dataset/ILSVRC2012_val_00004220.bin 224 224 +34795 ./prep_dataset/ILSVRC2012_val_00010241.bin 224 224 +34796 ./prep_dataset/ILSVRC2012_val_00002736.bin 224 224 +34797 ./prep_dataset/ILSVRC2012_val_00034080.bin 224 224 +34798 ./prep_dataset/ILSVRC2012_val_00046719.bin 224 224 +34799 ./prep_dataset/ILSVRC2012_val_00006462.bin 224 224 +34800 ./prep_dataset/ILSVRC2012_val_00015017.bin 224 224 +34801 ./prep_dataset/ILSVRC2012_val_00036862.bin 224 224 +34802 ./prep_dataset/ILSVRC2012_val_00008302.bin 224 224 +34803 ./prep_dataset/ILSVRC2012_val_00042682.bin 224 224 +34804 ./prep_dataset/ILSVRC2012_val_00042499.bin 224 224 +34805 ./prep_dataset/ILSVRC2012_val_00008342.bin 224 224 +34806 ./prep_dataset/ILSVRC2012_val_00036004.bin 224 224 +34807 ./prep_dataset/ILSVRC2012_val_00032535.bin 224 224 +34808 ./prep_dataset/ILSVRC2012_val_00010057.bin 224 224 +34809 ./prep_dataset/ILSVRC2012_val_00022007.bin 224 224 +34810 ./prep_dataset/ILSVRC2012_val_00029407.bin 224 224 +34811 ./prep_dataset/ILSVRC2012_val_00020344.bin 224 224 +34812 ./prep_dataset/ILSVRC2012_val_00048130.bin 224 224 +34813 ./prep_dataset/ILSVRC2012_val_00048784.bin 224 224 +34814 ./prep_dataset/ILSVRC2012_val_00033528.bin 224 224 +34815 ./prep_dataset/ILSVRC2012_val_00025785.bin 224 224 +34816 ./prep_dataset/ILSVRC2012_val_00010279.bin 224 224 +34817 ./prep_dataset/ILSVRC2012_val_00017607.bin 224 224 +34818 ./prep_dataset/ILSVRC2012_val_00027588.bin 224 224 +34819 ./prep_dataset/ILSVRC2012_val_00049809.bin 224 224 +34820 ./prep_dataset/ILSVRC2012_val_00013249.bin 224 224 +34821 ./prep_dataset/ILSVRC2012_val_00031116.bin 224 224 +34822 ./prep_dataset/ILSVRC2012_val_00042451.bin 224 224 +34823 ./prep_dataset/ILSVRC2012_val_00026078.bin 224 224 +34824 ./prep_dataset/ILSVRC2012_val_00006589.bin 224 224 +34825 ./prep_dataset/ILSVRC2012_val_00021027.bin 224 224 +34826 ./prep_dataset/ILSVRC2012_val_00022190.bin 224 224 +34827 ./prep_dataset/ILSVRC2012_val_00044805.bin 224 224 +34828 ./prep_dataset/ILSVRC2012_val_00031435.bin 224 224 +34829 ./prep_dataset/ILSVRC2012_val_00009041.bin 224 224 +34830 ./prep_dataset/ILSVRC2012_val_00004256.bin 224 224 +34831 ./prep_dataset/ILSVRC2012_val_00003317.bin 224 224 +34832 ./prep_dataset/ILSVRC2012_val_00016077.bin 224 224 +34833 ./prep_dataset/ILSVRC2012_val_00019025.bin 224 224 +34834 ./prep_dataset/ILSVRC2012_val_00037068.bin 224 224 +34835 ./prep_dataset/ILSVRC2012_val_00047252.bin 224 224 +34836 ./prep_dataset/ILSVRC2012_val_00034152.bin 224 224 +34837 ./prep_dataset/ILSVRC2012_val_00014952.bin 224 224 +34838 ./prep_dataset/ILSVRC2012_val_00010314.bin 224 224 +34839 ./prep_dataset/ILSVRC2012_val_00042105.bin 224 224 +34840 ./prep_dataset/ILSVRC2012_val_00013766.bin 224 224 +34841 ./prep_dataset/ILSVRC2012_val_00013660.bin 224 224 +34842 ./prep_dataset/ILSVRC2012_val_00037824.bin 224 224 +34843 ./prep_dataset/ILSVRC2012_val_00043737.bin 224 224 +34844 ./prep_dataset/ILSVRC2012_val_00019094.bin 224 224 +34845 ./prep_dataset/ILSVRC2012_val_00041217.bin 224 224 +34846 ./prep_dataset/ILSVRC2012_val_00003101.bin 224 224 +34847 ./prep_dataset/ILSVRC2012_val_00023133.bin 224 224 +34848 ./prep_dataset/ILSVRC2012_val_00005309.bin 224 224 +34849 ./prep_dataset/ILSVRC2012_val_00043227.bin 224 224 +34850 ./prep_dataset/ILSVRC2012_val_00028197.bin 224 224 +34851 ./prep_dataset/ILSVRC2012_val_00044269.bin 224 224 +34852 ./prep_dataset/ILSVRC2012_val_00001191.bin 224 224 +34853 ./prep_dataset/ILSVRC2012_val_00012069.bin 224 224 +34854 ./prep_dataset/ILSVRC2012_val_00024325.bin 224 224 +34855 ./prep_dataset/ILSVRC2012_val_00010807.bin 224 224 +34856 ./prep_dataset/ILSVRC2012_val_00024117.bin 224 224 +34857 ./prep_dataset/ILSVRC2012_val_00047886.bin 224 224 +34858 ./prep_dataset/ILSVRC2012_val_00034683.bin 224 224 +34859 ./prep_dataset/ILSVRC2012_val_00032270.bin 224 224 +34860 ./prep_dataset/ILSVRC2012_val_00006349.bin 224 224 +34861 ./prep_dataset/ILSVRC2012_val_00018211.bin 224 224 +34862 ./prep_dataset/ILSVRC2012_val_00044360.bin 224 224 +34863 ./prep_dataset/ILSVRC2012_val_00031506.bin 224 224 +34864 ./prep_dataset/ILSVRC2012_val_00038956.bin 224 224 +34865 ./prep_dataset/ILSVRC2012_val_00018819.bin 224 224 +34866 ./prep_dataset/ILSVRC2012_val_00028972.bin 224 224 +34867 ./prep_dataset/ILSVRC2012_val_00005972.bin 224 224 +34868 ./prep_dataset/ILSVRC2012_val_00040930.bin 224 224 +34869 ./prep_dataset/ILSVRC2012_val_00019345.bin 224 224 +34870 ./prep_dataset/ILSVRC2012_val_00031181.bin 224 224 +34871 ./prep_dataset/ILSVRC2012_val_00000399.bin 224 224 +34872 ./prep_dataset/ILSVRC2012_val_00031924.bin 224 224 +34873 ./prep_dataset/ILSVRC2012_val_00031791.bin 224 224 +34874 ./prep_dataset/ILSVRC2012_val_00025844.bin 224 224 +34875 ./prep_dataset/ILSVRC2012_val_00021587.bin 224 224 +34876 ./prep_dataset/ILSVRC2012_val_00008898.bin 224 224 +34877 ./prep_dataset/ILSVRC2012_val_00027411.bin 224 224 +34878 ./prep_dataset/ILSVRC2012_val_00012911.bin 224 224 +34879 ./prep_dataset/ILSVRC2012_val_00002864.bin 224 224 +34880 ./prep_dataset/ILSVRC2012_val_00045317.bin 224 224 +34881 ./prep_dataset/ILSVRC2012_val_00004144.bin 224 224 +34882 ./prep_dataset/ILSVRC2012_val_00000057.bin 224 224 +34883 ./prep_dataset/ILSVRC2012_val_00047231.bin 224 224 +34884 ./prep_dataset/ILSVRC2012_val_00000671.bin 224 224 +34885 ./prep_dataset/ILSVRC2012_val_00049664.bin 224 224 +34886 ./prep_dataset/ILSVRC2012_val_00022578.bin 224 224 +34887 ./prep_dataset/ILSVRC2012_val_00041816.bin 224 224 +34888 ./prep_dataset/ILSVRC2012_val_00001832.bin 224 224 +34889 ./prep_dataset/ILSVRC2012_val_00024089.bin 224 224 +34890 ./prep_dataset/ILSVRC2012_val_00016095.bin 224 224 +34891 ./prep_dataset/ILSVRC2012_val_00049947.bin 224 224 +34892 ./prep_dataset/ILSVRC2012_val_00029145.bin 224 224 +34893 ./prep_dataset/ILSVRC2012_val_00039497.bin 224 224 +34894 ./prep_dataset/ILSVRC2012_val_00040401.bin 224 224 +34895 ./prep_dataset/ILSVRC2012_val_00025812.bin 224 224 +34896 ./prep_dataset/ILSVRC2012_val_00030664.bin 224 224 +34897 ./prep_dataset/ILSVRC2012_val_00043253.bin 224 224 +34898 ./prep_dataset/ILSVRC2012_val_00038486.bin 224 224 +34899 ./prep_dataset/ILSVRC2012_val_00010357.bin 224 224 +34900 ./prep_dataset/ILSVRC2012_val_00009888.bin 224 224 +34901 ./prep_dataset/ILSVRC2012_val_00032409.bin 224 224 +34902 ./prep_dataset/ILSVRC2012_val_00019033.bin 224 224 +34903 ./prep_dataset/ILSVRC2012_val_00032351.bin 224 224 +34904 ./prep_dataset/ILSVRC2012_val_00025721.bin 224 224 +34905 ./prep_dataset/ILSVRC2012_val_00006167.bin 224 224 +34906 ./prep_dataset/ILSVRC2012_val_00034101.bin 224 224 +34907 ./prep_dataset/ILSVRC2012_val_00011455.bin 224 224 +34908 ./prep_dataset/ILSVRC2012_val_00008411.bin 224 224 +34909 ./prep_dataset/ILSVRC2012_val_00011678.bin 224 224 +34910 ./prep_dataset/ILSVRC2012_val_00019615.bin 224 224 +34911 ./prep_dataset/ILSVRC2012_val_00018016.bin 224 224 +34912 ./prep_dataset/ILSVRC2012_val_00022859.bin 224 224 +34913 ./prep_dataset/ILSVRC2012_val_00028347.bin 224 224 +34914 ./prep_dataset/ILSVRC2012_val_00010447.bin 224 224 +34915 ./prep_dataset/ILSVRC2012_val_00006970.bin 224 224 +34916 ./prep_dataset/ILSVRC2012_val_00001307.bin 224 224 +34917 ./prep_dataset/ILSVRC2012_val_00045536.bin 224 224 +34918 ./prep_dataset/ILSVRC2012_val_00044761.bin 224 224 +34919 ./prep_dataset/ILSVRC2012_val_00026567.bin 224 224 +34920 ./prep_dataset/ILSVRC2012_val_00039122.bin 224 224 +34921 ./prep_dataset/ILSVRC2012_val_00024500.bin 224 224 +34922 ./prep_dataset/ILSVRC2012_val_00025007.bin 224 224 +34923 ./prep_dataset/ILSVRC2012_val_00000688.bin 224 224 +34924 ./prep_dataset/ILSVRC2012_val_00025305.bin 224 224 +34925 ./prep_dataset/ILSVRC2012_val_00012925.bin 224 224 +34926 ./prep_dataset/ILSVRC2012_val_00022369.bin 224 224 +34927 ./prep_dataset/ILSVRC2012_val_00017677.bin 224 224 +34928 ./prep_dataset/ILSVRC2012_val_00003037.bin 224 224 +34929 ./prep_dataset/ILSVRC2012_val_00032955.bin 224 224 +34930 ./prep_dataset/ILSVRC2012_val_00012473.bin 224 224 +34931 ./prep_dataset/ILSVRC2012_val_00024531.bin 224 224 +34932 ./prep_dataset/ILSVRC2012_val_00030282.bin 224 224 +34933 ./prep_dataset/ILSVRC2012_val_00000930.bin 224 224 +34934 ./prep_dataset/ILSVRC2012_val_00026010.bin 224 224 +34935 ./prep_dataset/ILSVRC2012_val_00039611.bin 224 224 +34936 ./prep_dataset/ILSVRC2012_val_00008795.bin 224 224 +34937 ./prep_dataset/ILSVRC2012_val_00035765.bin 224 224 +34938 ./prep_dataset/ILSVRC2012_val_00015808.bin 224 224 +34939 ./prep_dataset/ILSVRC2012_val_00044859.bin 224 224 +34940 ./prep_dataset/ILSVRC2012_val_00030578.bin 224 224 +34941 ./prep_dataset/ILSVRC2012_val_00044293.bin 224 224 +34942 ./prep_dataset/ILSVRC2012_val_00027792.bin 224 224 +34943 ./prep_dataset/ILSVRC2012_val_00021148.bin 224 224 +34944 ./prep_dataset/ILSVRC2012_val_00004350.bin 224 224 +34945 ./prep_dataset/ILSVRC2012_val_00026762.bin 224 224 +34946 ./prep_dataset/ILSVRC2012_val_00041296.bin 224 224 +34947 ./prep_dataset/ILSVRC2012_val_00040434.bin 224 224 +34948 ./prep_dataset/ILSVRC2012_val_00021580.bin 224 224 +34949 ./prep_dataset/ILSVRC2012_val_00014876.bin 224 224 +34950 ./prep_dataset/ILSVRC2012_val_00009998.bin 224 224 +34951 ./prep_dataset/ILSVRC2012_val_00045716.bin 224 224 +34952 ./prep_dataset/ILSVRC2012_val_00004338.bin 224 224 +34953 ./prep_dataset/ILSVRC2012_val_00021995.bin 224 224 +34954 ./prep_dataset/ILSVRC2012_val_00039633.bin 224 224 +34955 ./prep_dataset/ILSVRC2012_val_00006673.bin 224 224 +34956 ./prep_dataset/ILSVRC2012_val_00006868.bin 224 224 +34957 ./prep_dataset/ILSVRC2012_val_00033795.bin 224 224 +34958 ./prep_dataset/ILSVRC2012_val_00046959.bin 224 224 +34959 ./prep_dataset/ILSVRC2012_val_00047240.bin 224 224 +34960 ./prep_dataset/ILSVRC2012_val_00039195.bin 224 224 +34961 ./prep_dataset/ILSVRC2012_val_00004886.bin 224 224 +34962 ./prep_dataset/ILSVRC2012_val_00034529.bin 224 224 +34963 ./prep_dataset/ILSVRC2012_val_00032999.bin 224 224 +34964 ./prep_dataset/ILSVRC2012_val_00014993.bin 224 224 +34965 ./prep_dataset/ILSVRC2012_val_00025437.bin 224 224 +34966 ./prep_dataset/ILSVRC2012_val_00036382.bin 224 224 +34967 ./prep_dataset/ILSVRC2012_val_00046238.bin 224 224 +34968 ./prep_dataset/ILSVRC2012_val_00024084.bin 224 224 +34969 ./prep_dataset/ILSVRC2012_val_00008111.bin 224 224 +34970 ./prep_dataset/ILSVRC2012_val_00047941.bin 224 224 +34971 ./prep_dataset/ILSVRC2012_val_00031771.bin 224 224 +34972 ./prep_dataset/ILSVRC2012_val_00032287.bin 224 224 +34973 ./prep_dataset/ILSVRC2012_val_00001886.bin 224 224 +34974 ./prep_dataset/ILSVRC2012_val_00017020.bin 224 224 +34975 ./prep_dataset/ILSVRC2012_val_00007839.bin 224 224 +34976 ./prep_dataset/ILSVRC2012_val_00012973.bin 224 224 +34977 ./prep_dataset/ILSVRC2012_val_00030820.bin 224 224 +34978 ./prep_dataset/ILSVRC2012_val_00024947.bin 224 224 +34979 ./prep_dataset/ILSVRC2012_val_00022061.bin 224 224 +34980 ./prep_dataset/ILSVRC2012_val_00047370.bin 224 224 +34981 ./prep_dataset/ILSVRC2012_val_00047155.bin 224 224 +34982 ./prep_dataset/ILSVRC2012_val_00017914.bin 224 224 +34983 ./prep_dataset/ILSVRC2012_val_00021592.bin 224 224 +34984 ./prep_dataset/ILSVRC2012_val_00005092.bin 224 224 +34985 ./prep_dataset/ILSVRC2012_val_00032958.bin 224 224 +34986 ./prep_dataset/ILSVRC2012_val_00019875.bin 224 224 +34987 ./prep_dataset/ILSVRC2012_val_00002748.bin 224 224 +34988 ./prep_dataset/ILSVRC2012_val_00037669.bin 224 224 +34989 ./prep_dataset/ILSVRC2012_val_00000139.bin 224 224 +34990 ./prep_dataset/ILSVRC2012_val_00047914.bin 224 224 +34991 ./prep_dataset/ILSVRC2012_val_00045692.bin 224 224 +34992 ./prep_dataset/ILSVRC2012_val_00024569.bin 224 224 +34993 ./prep_dataset/ILSVRC2012_val_00045961.bin 224 224 +34994 ./prep_dataset/ILSVRC2012_val_00043712.bin 224 224 +34995 ./prep_dataset/ILSVRC2012_val_00042222.bin 224 224 +34996 ./prep_dataset/ILSVRC2012_val_00007574.bin 224 224 +34997 ./prep_dataset/ILSVRC2012_val_00015056.bin 224 224 +34998 ./prep_dataset/ILSVRC2012_val_00008867.bin 224 224 +34999 ./prep_dataset/ILSVRC2012_val_00004414.bin 224 224 +35000 ./prep_dataset/ILSVRC2012_val_00040496.bin 224 224 +35001 ./prep_dataset/ILSVRC2012_val_00012675.bin 224 224 +35002 ./prep_dataset/ILSVRC2012_val_00021317.bin 224 224 +35003 ./prep_dataset/ILSVRC2012_val_00015084.bin 224 224 +35004 ./prep_dataset/ILSVRC2012_val_00020940.bin 224 224 +35005 ./prep_dataset/ILSVRC2012_val_00028324.bin 224 224 +35006 ./prep_dataset/ILSVRC2012_val_00022538.bin 224 224 +35007 ./prep_dataset/ILSVRC2012_val_00020864.bin 224 224 +35008 ./prep_dataset/ILSVRC2012_val_00009717.bin 224 224 +35009 ./prep_dataset/ILSVRC2012_val_00041831.bin 224 224 +35010 ./prep_dataset/ILSVRC2012_val_00046766.bin 224 224 +35011 ./prep_dataset/ILSVRC2012_val_00014389.bin 224 224 +35012 ./prep_dataset/ILSVRC2012_val_00049464.bin 224 224 +35013 ./prep_dataset/ILSVRC2012_val_00001674.bin 224 224 +35014 ./prep_dataset/ILSVRC2012_val_00021705.bin 224 224 +35015 ./prep_dataset/ILSVRC2012_val_00030881.bin 224 224 +35016 ./prep_dataset/ILSVRC2012_val_00023162.bin 224 224 +35017 ./prep_dataset/ILSVRC2012_val_00026848.bin 224 224 +35018 ./prep_dataset/ILSVRC2012_val_00011582.bin 224 224 +35019 ./prep_dataset/ILSVRC2012_val_00004049.bin 224 224 +35020 ./prep_dataset/ILSVRC2012_val_00026219.bin 224 224 +35021 ./prep_dataset/ILSVRC2012_val_00011590.bin 224 224 +35022 ./prep_dataset/ILSVRC2012_val_00015685.bin 224 224 +35023 ./prep_dataset/ILSVRC2012_val_00025504.bin 224 224 +35024 ./prep_dataset/ILSVRC2012_val_00014568.bin 224 224 +35025 ./prep_dataset/ILSVRC2012_val_00007318.bin 224 224 +35026 ./prep_dataset/ILSVRC2012_val_00003418.bin 224 224 +35027 ./prep_dataset/ILSVRC2012_val_00032985.bin 224 224 +35028 ./prep_dataset/ILSVRC2012_val_00025408.bin 224 224 +35029 ./prep_dataset/ILSVRC2012_val_00040789.bin 224 224 +35030 ./prep_dataset/ILSVRC2012_val_00025281.bin 224 224 +35031 ./prep_dataset/ILSVRC2012_val_00015092.bin 224 224 +35032 ./prep_dataset/ILSVRC2012_val_00047848.bin 224 224 +35033 ./prep_dataset/ILSVRC2012_val_00009801.bin 224 224 +35034 ./prep_dataset/ILSVRC2012_val_00042055.bin 224 224 +35035 ./prep_dataset/ILSVRC2012_val_00035782.bin 224 224 +35036 ./prep_dataset/ILSVRC2012_val_00035818.bin 224 224 +35037 ./prep_dataset/ILSVRC2012_val_00030257.bin 224 224 +35038 ./prep_dataset/ILSVRC2012_val_00047228.bin 224 224 +35039 ./prep_dataset/ILSVRC2012_val_00046480.bin 224 224 +35040 ./prep_dataset/ILSVRC2012_val_00001253.bin 224 224 +35041 ./prep_dataset/ILSVRC2012_val_00026108.bin 224 224 +35042 ./prep_dataset/ILSVRC2012_val_00041510.bin 224 224 +35043 ./prep_dataset/ILSVRC2012_val_00043787.bin 224 224 +35044 ./prep_dataset/ILSVRC2012_val_00023700.bin 224 224 +35045 ./prep_dataset/ILSVRC2012_val_00045428.bin 224 224 +35046 ./prep_dataset/ILSVRC2012_val_00007833.bin 224 224 +35047 ./prep_dataset/ILSVRC2012_val_00012517.bin 224 224 +35048 ./prep_dataset/ILSVRC2012_val_00013494.bin 224 224 +35049 ./prep_dataset/ILSVRC2012_val_00027784.bin 224 224 +35050 ./prep_dataset/ILSVRC2012_val_00006925.bin 224 224 +35051 ./prep_dataset/ILSVRC2012_val_00045930.bin 224 224 +35052 ./prep_dataset/ILSVRC2012_val_00014039.bin 224 224 +35053 ./prep_dataset/ILSVRC2012_val_00029847.bin 224 224 +35054 ./prep_dataset/ILSVRC2012_val_00024613.bin 224 224 +35055 ./prep_dataset/ILSVRC2012_val_00047394.bin 224 224 +35056 ./prep_dataset/ILSVRC2012_val_00020123.bin 224 224 +35057 ./prep_dataset/ILSVRC2012_val_00032249.bin 224 224 +35058 ./prep_dataset/ILSVRC2012_val_00034626.bin 224 224 +35059 ./prep_dataset/ILSVRC2012_val_00009186.bin 224 224 +35060 ./prep_dataset/ILSVRC2012_val_00025427.bin 224 224 +35061 ./prep_dataset/ILSVRC2012_val_00014125.bin 224 224 +35062 ./prep_dataset/ILSVRC2012_val_00028266.bin 224 224 +35063 ./prep_dataset/ILSVRC2012_val_00036970.bin 224 224 +35064 ./prep_dataset/ILSVRC2012_val_00011639.bin 224 224 +35065 ./prep_dataset/ILSVRC2012_val_00006409.bin 224 224 +35066 ./prep_dataset/ILSVRC2012_val_00000909.bin 224 224 +35067 ./prep_dataset/ILSVRC2012_val_00000814.bin 224 224 +35068 ./prep_dataset/ILSVRC2012_val_00040125.bin 224 224 +35069 ./prep_dataset/ILSVRC2012_val_00021659.bin 224 224 +35070 ./prep_dataset/ILSVRC2012_val_00047734.bin 224 224 +35071 ./prep_dataset/ILSVRC2012_val_00006975.bin 224 224 +35072 ./prep_dataset/ILSVRC2012_val_00034515.bin 224 224 +35073 ./prep_dataset/ILSVRC2012_val_00007823.bin 224 224 +35074 ./prep_dataset/ILSVRC2012_val_00021668.bin 224 224 +35075 ./prep_dataset/ILSVRC2012_val_00028963.bin 224 224 +35076 ./prep_dataset/ILSVRC2012_val_00016637.bin 224 224 +35077 ./prep_dataset/ILSVRC2012_val_00038318.bin 224 224 +35078 ./prep_dataset/ILSVRC2012_val_00021403.bin 224 224 +35079 ./prep_dataset/ILSVRC2012_val_00046797.bin 224 224 +35080 ./prep_dataset/ILSVRC2012_val_00040249.bin 224 224 +35081 ./prep_dataset/ILSVRC2012_val_00029969.bin 224 224 +35082 ./prep_dataset/ILSVRC2012_val_00044965.bin 224 224 +35083 ./prep_dataset/ILSVRC2012_val_00007029.bin 224 224 +35084 ./prep_dataset/ILSVRC2012_val_00007850.bin 224 224 +35085 ./prep_dataset/ILSVRC2012_val_00003978.bin 224 224 +35086 ./prep_dataset/ILSVRC2012_val_00033569.bin 224 224 +35087 ./prep_dataset/ILSVRC2012_val_00015815.bin 224 224 +35088 ./prep_dataset/ILSVRC2012_val_00038658.bin 224 224 +35089 ./prep_dataset/ILSVRC2012_val_00024015.bin 224 224 +35090 ./prep_dataset/ILSVRC2012_val_00037772.bin 224 224 +35091 ./prep_dataset/ILSVRC2012_val_00024891.bin 224 224 +35092 ./prep_dataset/ILSVRC2012_val_00001722.bin 224 224 +35093 ./prep_dataset/ILSVRC2012_val_00046163.bin 224 224 +35094 ./prep_dataset/ILSVRC2012_val_00023646.bin 224 224 +35095 ./prep_dataset/ILSVRC2012_val_00023851.bin 224 224 +35096 ./prep_dataset/ILSVRC2012_val_00025639.bin 224 224 +35097 ./prep_dataset/ILSVRC2012_val_00003182.bin 224 224 +35098 ./prep_dataset/ILSVRC2012_val_00008164.bin 224 224 +35099 ./prep_dataset/ILSVRC2012_val_00038816.bin 224 224 +35100 ./prep_dataset/ILSVRC2012_val_00019061.bin 224 224 +35101 ./prep_dataset/ILSVRC2012_val_00037389.bin 224 224 +35102 ./prep_dataset/ILSVRC2012_val_00018661.bin 224 224 +35103 ./prep_dataset/ILSVRC2012_val_00029889.bin 224 224 +35104 ./prep_dataset/ILSVRC2012_val_00018931.bin 224 224 +35105 ./prep_dataset/ILSVRC2012_val_00001608.bin 224 224 +35106 ./prep_dataset/ILSVRC2012_val_00041746.bin 224 224 +35107 ./prep_dataset/ILSVRC2012_val_00049650.bin 224 224 +35108 ./prep_dataset/ILSVRC2012_val_00013990.bin 224 224 +35109 ./prep_dataset/ILSVRC2012_val_00019876.bin 224 224 +35110 ./prep_dataset/ILSVRC2012_val_00020270.bin 224 224 +35111 ./prep_dataset/ILSVRC2012_val_00000707.bin 224 224 +35112 ./prep_dataset/ILSVRC2012_val_00021312.bin 224 224 +35113 ./prep_dataset/ILSVRC2012_val_00043651.bin 224 224 +35114 ./prep_dataset/ILSVRC2012_val_00024042.bin 224 224 +35115 ./prep_dataset/ILSVRC2012_val_00041580.bin 224 224 +35116 ./prep_dataset/ILSVRC2012_val_00006671.bin 224 224 +35117 ./prep_dataset/ILSVRC2012_val_00010833.bin 224 224 +35118 ./prep_dataset/ILSVRC2012_val_00037776.bin 224 224 +35119 ./prep_dataset/ILSVRC2012_val_00021950.bin 224 224 +35120 ./prep_dataset/ILSVRC2012_val_00032385.bin 224 224 +35121 ./prep_dataset/ILSVRC2012_val_00041416.bin 224 224 +35122 ./prep_dataset/ILSVRC2012_val_00012594.bin 224 224 +35123 ./prep_dataset/ILSVRC2012_val_00007227.bin 224 224 +35124 ./prep_dataset/ILSVRC2012_val_00048174.bin 224 224 +35125 ./prep_dataset/ILSVRC2012_val_00042275.bin 224 224 +35126 ./prep_dataset/ILSVRC2012_val_00001377.bin 224 224 +35127 ./prep_dataset/ILSVRC2012_val_00033256.bin 224 224 +35128 ./prep_dataset/ILSVRC2012_val_00012014.bin 224 224 +35129 ./prep_dataset/ILSVRC2012_val_00019513.bin 224 224 +35130 ./prep_dataset/ILSVRC2012_val_00017442.bin 224 224 +35131 ./prep_dataset/ILSVRC2012_val_00018292.bin 224 224 +35132 ./prep_dataset/ILSVRC2012_val_00003054.bin 224 224 +35133 ./prep_dataset/ILSVRC2012_val_00037387.bin 224 224 +35134 ./prep_dataset/ILSVRC2012_val_00014270.bin 224 224 +35135 ./prep_dataset/ILSVRC2012_val_00042171.bin 224 224 +35136 ./prep_dataset/ILSVRC2012_val_00037583.bin 224 224 +35137 ./prep_dataset/ILSVRC2012_val_00016029.bin 224 224 +35138 ./prep_dataset/ILSVRC2012_val_00015436.bin 224 224 +35139 ./prep_dataset/ILSVRC2012_val_00019190.bin 224 224 +35140 ./prep_dataset/ILSVRC2012_val_00039654.bin 224 224 +35141 ./prep_dataset/ILSVRC2012_val_00007618.bin 224 224 +35142 ./prep_dataset/ILSVRC2012_val_00043040.bin 224 224 +35143 ./prep_dataset/ILSVRC2012_val_00045144.bin 224 224 +35144 ./prep_dataset/ILSVRC2012_val_00035706.bin 224 224 +35145 ./prep_dataset/ILSVRC2012_val_00040521.bin 224 224 +35146 ./prep_dataset/ILSVRC2012_val_00020493.bin 224 224 +35147 ./prep_dataset/ILSVRC2012_val_00038441.bin 224 224 +35148 ./prep_dataset/ILSVRC2012_val_00036696.bin 224 224 +35149 ./prep_dataset/ILSVRC2012_val_00031491.bin 224 224 +35150 ./prep_dataset/ILSVRC2012_val_00047431.bin 224 224 +35151 ./prep_dataset/ILSVRC2012_val_00041608.bin 224 224 +35152 ./prep_dataset/ILSVRC2012_val_00021652.bin 224 224 +35153 ./prep_dataset/ILSVRC2012_val_00041049.bin 224 224 +35154 ./prep_dataset/ILSVRC2012_val_00042875.bin 224 224 +35155 ./prep_dataset/ILSVRC2012_val_00031794.bin 224 224 +35156 ./prep_dataset/ILSVRC2012_val_00033339.bin 224 224 +35157 ./prep_dataset/ILSVRC2012_val_00037528.bin 224 224 +35158 ./prep_dataset/ILSVRC2012_val_00003474.bin 224 224 +35159 ./prep_dataset/ILSVRC2012_val_00017072.bin 224 224 +35160 ./prep_dataset/ILSVRC2012_val_00042116.bin 224 224 +35161 ./prep_dataset/ILSVRC2012_val_00021207.bin 224 224 +35162 ./prep_dataset/ILSVRC2012_val_00047043.bin 224 224 +35163 ./prep_dataset/ILSVRC2012_val_00046663.bin 224 224 +35164 ./prep_dataset/ILSVRC2012_val_00041096.bin 224 224 +35165 ./prep_dataset/ILSVRC2012_val_00041193.bin 224 224 +35166 ./prep_dataset/ILSVRC2012_val_00005981.bin 224 224 +35167 ./prep_dataset/ILSVRC2012_val_00016385.bin 224 224 +35168 ./prep_dataset/ILSVRC2012_val_00005820.bin 224 224 +35169 ./prep_dataset/ILSVRC2012_val_00027633.bin 224 224 +35170 ./prep_dataset/ILSVRC2012_val_00017749.bin 224 224 +35171 ./prep_dataset/ILSVRC2012_val_00025237.bin 224 224 +35172 ./prep_dataset/ILSVRC2012_val_00040325.bin 224 224 +35173 ./prep_dataset/ILSVRC2012_val_00033432.bin 224 224 +35174 ./prep_dataset/ILSVRC2012_val_00012225.bin 224 224 +35175 ./prep_dataset/ILSVRC2012_val_00027793.bin 224 224 +35176 ./prep_dataset/ILSVRC2012_val_00037829.bin 224 224 +35177 ./prep_dataset/ILSVRC2012_val_00019553.bin 224 224 +35178 ./prep_dataset/ILSVRC2012_val_00045272.bin 224 224 +35179 ./prep_dataset/ILSVRC2012_val_00019727.bin 224 224 +35180 ./prep_dataset/ILSVRC2012_val_00004118.bin 224 224 +35181 ./prep_dataset/ILSVRC2012_val_00037375.bin 224 224 +35182 ./prep_dataset/ILSVRC2012_val_00001183.bin 224 224 +35183 ./prep_dataset/ILSVRC2012_val_00043603.bin 224 224 +35184 ./prep_dataset/ILSVRC2012_val_00042786.bin 224 224 +35185 ./prep_dataset/ILSVRC2012_val_00018571.bin 224 224 +35186 ./prep_dataset/ILSVRC2012_val_00026995.bin 224 224 +35187 ./prep_dataset/ILSVRC2012_val_00030743.bin 224 224 +35188 ./prep_dataset/ILSVRC2012_val_00035853.bin 224 224 +35189 ./prep_dataset/ILSVRC2012_val_00032043.bin 224 224 +35190 ./prep_dataset/ILSVRC2012_val_00045720.bin 224 224 +35191 ./prep_dataset/ILSVRC2012_val_00036609.bin 224 224 +35192 ./prep_dataset/ILSVRC2012_val_00027156.bin 224 224 +35193 ./prep_dataset/ILSVRC2012_val_00018452.bin 224 224 +35194 ./prep_dataset/ILSVRC2012_val_00048364.bin 224 224 +35195 ./prep_dataset/ILSVRC2012_val_00046154.bin 224 224 +35196 ./prep_dataset/ILSVRC2012_val_00040998.bin 224 224 +35197 ./prep_dataset/ILSVRC2012_val_00002497.bin 224 224 +35198 ./prep_dataset/ILSVRC2012_val_00037523.bin 224 224 +35199 ./prep_dataset/ILSVRC2012_val_00038532.bin 224 224 +35200 ./prep_dataset/ILSVRC2012_val_00009817.bin 224 224 +35201 ./prep_dataset/ILSVRC2012_val_00003827.bin 224 224 +35202 ./prep_dataset/ILSVRC2012_val_00030460.bin 224 224 +35203 ./prep_dataset/ILSVRC2012_val_00038293.bin 224 224 +35204 ./prep_dataset/ILSVRC2012_val_00012682.bin 224 224 +35205 ./prep_dataset/ILSVRC2012_val_00006993.bin 224 224 +35206 ./prep_dataset/ILSVRC2012_val_00048994.bin 224 224 +35207 ./prep_dataset/ILSVRC2012_val_00047269.bin 224 224 +35208 ./prep_dataset/ILSVRC2012_val_00000537.bin 224 224 +35209 ./prep_dataset/ILSVRC2012_val_00026911.bin 224 224 +35210 ./prep_dataset/ILSVRC2012_val_00020046.bin 224 224 +35211 ./prep_dataset/ILSVRC2012_val_00012689.bin 224 224 +35212 ./prep_dataset/ILSVRC2012_val_00048512.bin 224 224 +35213 ./prep_dataset/ILSVRC2012_val_00020009.bin 224 224 +35214 ./prep_dataset/ILSVRC2012_val_00003564.bin 224 224 +35215 ./prep_dataset/ILSVRC2012_val_00038721.bin 224 224 +35216 ./prep_dataset/ILSVRC2012_val_00044345.bin 224 224 +35217 ./prep_dataset/ILSVRC2012_val_00039665.bin 224 224 +35218 ./prep_dataset/ILSVRC2012_val_00028245.bin 224 224 +35219 ./prep_dataset/ILSVRC2012_val_00017238.bin 224 224 +35220 ./prep_dataset/ILSVRC2012_val_00026581.bin 224 224 +35221 ./prep_dataset/ILSVRC2012_val_00035758.bin 224 224 +35222 ./prep_dataset/ILSVRC2012_val_00011099.bin 224 224 +35223 ./prep_dataset/ILSVRC2012_val_00006546.bin 224 224 +35224 ./prep_dataset/ILSVRC2012_val_00008029.bin 224 224 +35225 ./prep_dataset/ILSVRC2012_val_00020994.bin 224 224 +35226 ./prep_dataset/ILSVRC2012_val_00004196.bin 224 224 +35227 ./prep_dataset/ILSVRC2012_val_00042176.bin 224 224 +35228 ./prep_dataset/ILSVRC2012_val_00026866.bin 224 224 +35229 ./prep_dataset/ILSVRC2012_val_00048242.bin 224 224 +35230 ./prep_dataset/ILSVRC2012_val_00000894.bin 224 224 +35231 ./prep_dataset/ILSVRC2012_val_00003657.bin 224 224 +35232 ./prep_dataset/ILSVRC2012_val_00009840.bin 224 224 +35233 ./prep_dataset/ILSVRC2012_val_00019761.bin 224 224 +35234 ./prep_dataset/ILSVRC2012_val_00026302.bin 224 224 +35235 ./prep_dataset/ILSVRC2012_val_00032125.bin 224 224 +35236 ./prep_dataset/ILSVRC2012_val_00015206.bin 224 224 +35237 ./prep_dataset/ILSVRC2012_val_00009701.bin 224 224 +35238 ./prep_dataset/ILSVRC2012_val_00010921.bin 224 224 +35239 ./prep_dataset/ILSVRC2012_val_00020744.bin 224 224 +35240 ./prep_dataset/ILSVRC2012_val_00006640.bin 224 224 +35241 ./prep_dataset/ILSVRC2012_val_00030195.bin 224 224 +35242 ./prep_dataset/ILSVRC2012_val_00044674.bin 224 224 +35243 ./prep_dataset/ILSVRC2012_val_00006133.bin 224 224 +35244 ./prep_dataset/ILSVRC2012_val_00045680.bin 224 224 +35245 ./prep_dataset/ILSVRC2012_val_00024049.bin 224 224 +35246 ./prep_dataset/ILSVRC2012_val_00036056.bin 224 224 +35247 ./prep_dataset/ILSVRC2012_val_00020026.bin 224 224 +35248 ./prep_dataset/ILSVRC2012_val_00049660.bin 224 224 +35249 ./prep_dataset/ILSVRC2012_val_00041122.bin 224 224 +35250 ./prep_dataset/ILSVRC2012_val_00006661.bin 224 224 +35251 ./prep_dataset/ILSVRC2012_val_00022301.bin 224 224 +35252 ./prep_dataset/ILSVRC2012_val_00030264.bin 224 224 +35253 ./prep_dataset/ILSVRC2012_val_00017855.bin 224 224 +35254 ./prep_dataset/ILSVRC2012_val_00010998.bin 224 224 +35255 ./prep_dataset/ILSVRC2012_val_00015550.bin 224 224 +35256 ./prep_dataset/ILSVRC2012_val_00031220.bin 224 224 +35257 ./prep_dataset/ILSVRC2012_val_00034941.bin 224 224 +35258 ./prep_dataset/ILSVRC2012_val_00043602.bin 224 224 +35259 ./prep_dataset/ILSVRC2012_val_00034838.bin 224 224 +35260 ./prep_dataset/ILSVRC2012_val_00022657.bin 224 224 +35261 ./prep_dataset/ILSVRC2012_val_00041805.bin 224 224 +35262 ./prep_dataset/ILSVRC2012_val_00007519.bin 224 224 +35263 ./prep_dataset/ILSVRC2012_val_00014718.bin 224 224 +35264 ./prep_dataset/ILSVRC2012_val_00036214.bin 224 224 +35265 ./prep_dataset/ILSVRC2012_val_00026575.bin 224 224 +35266 ./prep_dataset/ILSVRC2012_val_00035830.bin 224 224 +35267 ./prep_dataset/ILSVRC2012_val_00045068.bin 224 224 +35268 ./prep_dataset/ILSVRC2012_val_00029981.bin 224 224 +35269 ./prep_dataset/ILSVRC2012_val_00001756.bin 224 224 +35270 ./prep_dataset/ILSVRC2012_val_00040619.bin 224 224 +35271 ./prep_dataset/ILSVRC2012_val_00035780.bin 224 224 +35272 ./prep_dataset/ILSVRC2012_val_00044172.bin 224 224 +35273 ./prep_dataset/ILSVRC2012_val_00006748.bin 224 224 +35274 ./prep_dataset/ILSVRC2012_val_00034534.bin 224 224 +35275 ./prep_dataset/ILSVRC2012_val_00025770.bin 224 224 +35276 ./prep_dataset/ILSVRC2012_val_00047912.bin 224 224 +35277 ./prep_dataset/ILSVRC2012_val_00002758.bin 224 224 +35278 ./prep_dataset/ILSVRC2012_val_00042586.bin 224 224 +35279 ./prep_dataset/ILSVRC2012_val_00008693.bin 224 224 +35280 ./prep_dataset/ILSVRC2012_val_00012262.bin 224 224 +35281 ./prep_dataset/ILSVRC2012_val_00022826.bin 224 224 +35282 ./prep_dataset/ILSVRC2012_val_00039030.bin 224 224 +35283 ./prep_dataset/ILSVRC2012_val_00002728.bin 224 224 +35284 ./prep_dataset/ILSVRC2012_val_00044669.bin 224 224 +35285 ./prep_dataset/ILSVRC2012_val_00046452.bin 224 224 +35286 ./prep_dataset/ILSVRC2012_val_00046468.bin 224 224 +35287 ./prep_dataset/ILSVRC2012_val_00006908.bin 224 224 +35288 ./prep_dataset/ILSVRC2012_val_00022519.bin 224 224 +35289 ./prep_dataset/ILSVRC2012_val_00016515.bin 224 224 +35290 ./prep_dataset/ILSVRC2012_val_00000102.bin 224 224 +35291 ./prep_dataset/ILSVRC2012_val_00013945.bin 224 224 +35292 ./prep_dataset/ILSVRC2012_val_00005340.bin 224 224 +35293 ./prep_dataset/ILSVRC2012_val_00048856.bin 224 224 +35294 ./prep_dataset/ILSVRC2012_val_00049847.bin 224 224 +35295 ./prep_dataset/ILSVRC2012_val_00028084.bin 224 224 +35296 ./prep_dataset/ILSVRC2012_val_00043729.bin 224 224 +35297 ./prep_dataset/ILSVRC2012_val_00034118.bin 224 224 +35298 ./prep_dataset/ILSVRC2012_val_00014477.bin 224 224 +35299 ./prep_dataset/ILSVRC2012_val_00037486.bin 224 224 +35300 ./prep_dataset/ILSVRC2012_val_00029839.bin 224 224 +35301 ./prep_dataset/ILSVRC2012_val_00022175.bin 224 224 +35302 ./prep_dataset/ILSVRC2012_val_00039779.bin 224 224 +35303 ./prep_dataset/ILSVRC2012_val_00029756.bin 224 224 +35304 ./prep_dataset/ILSVRC2012_val_00045583.bin 224 224 +35305 ./prep_dataset/ILSVRC2012_val_00020624.bin 224 224 +35306 ./prep_dataset/ILSVRC2012_val_00007532.bin 224 224 +35307 ./prep_dataset/ILSVRC2012_val_00028836.bin 224 224 +35308 ./prep_dataset/ILSVRC2012_val_00012797.bin 224 224 +35309 ./prep_dataset/ILSVRC2012_val_00007886.bin 224 224 +35310 ./prep_dataset/ILSVRC2012_val_00011805.bin 224 224 +35311 ./prep_dataset/ILSVRC2012_val_00040140.bin 224 224 +35312 ./prep_dataset/ILSVRC2012_val_00038922.bin 224 224 +35313 ./prep_dataset/ILSVRC2012_val_00042888.bin 224 224 +35314 ./prep_dataset/ILSVRC2012_val_00047058.bin 224 224 +35315 ./prep_dataset/ILSVRC2012_val_00023643.bin 224 224 +35316 ./prep_dataset/ILSVRC2012_val_00034442.bin 224 224 +35317 ./prep_dataset/ILSVRC2012_val_00045420.bin 224 224 +35318 ./prep_dataset/ILSVRC2012_val_00033756.bin 224 224 +35319 ./prep_dataset/ILSVRC2012_val_00041394.bin 224 224 +35320 ./prep_dataset/ILSVRC2012_val_00007264.bin 224 224 +35321 ./prep_dataset/ILSVRC2012_val_00024638.bin 224 224 +35322 ./prep_dataset/ILSVRC2012_val_00043063.bin 224 224 +35323 ./prep_dataset/ILSVRC2012_val_00015398.bin 224 224 +35324 ./prep_dataset/ILSVRC2012_val_00007712.bin 224 224 +35325 ./prep_dataset/ILSVRC2012_val_00039371.bin 224 224 +35326 ./prep_dataset/ILSVRC2012_val_00022309.bin 224 224 +35327 ./prep_dataset/ILSVRC2012_val_00014298.bin 224 224 +35328 ./prep_dataset/ILSVRC2012_val_00031365.bin 224 224 +35329 ./prep_dataset/ILSVRC2012_val_00013171.bin 224 224 +35330 ./prep_dataset/ILSVRC2012_val_00001080.bin 224 224 +35331 ./prep_dataset/ILSVRC2012_val_00005150.bin 224 224 +35332 ./prep_dataset/ILSVRC2012_val_00040558.bin 224 224 +35333 ./prep_dataset/ILSVRC2012_val_00045153.bin 224 224 +35334 ./prep_dataset/ILSVRC2012_val_00045444.bin 224 224 +35335 ./prep_dataset/ILSVRC2012_val_00014738.bin 224 224 +35336 ./prep_dataset/ILSVRC2012_val_00036090.bin 224 224 +35337 ./prep_dataset/ILSVRC2012_val_00018563.bin 224 224 +35338 ./prep_dataset/ILSVRC2012_val_00045206.bin 224 224 +35339 ./prep_dataset/ILSVRC2012_val_00039055.bin 224 224 +35340 ./prep_dataset/ILSVRC2012_val_00042688.bin 224 224 +35341 ./prep_dataset/ILSVRC2012_val_00017327.bin 224 224 +35342 ./prep_dataset/ILSVRC2012_val_00047128.bin 224 224 +35343 ./prep_dataset/ILSVRC2012_val_00014753.bin 224 224 +35344 ./prep_dataset/ILSVRC2012_val_00008192.bin 224 224 +35345 ./prep_dataset/ILSVRC2012_val_00019439.bin 224 224 +35346 ./prep_dataset/ILSVRC2012_val_00022815.bin 224 224 +35347 ./prep_dataset/ILSVRC2012_val_00022076.bin 224 224 +35348 ./prep_dataset/ILSVRC2012_val_00030118.bin 224 224 +35349 ./prep_dataset/ILSVRC2012_val_00008793.bin 224 224 +35350 ./prep_dataset/ILSVRC2012_val_00018400.bin 224 224 +35351 ./prep_dataset/ILSVRC2012_val_00018844.bin 224 224 +35352 ./prep_dataset/ILSVRC2012_val_00032849.bin 224 224 +35353 ./prep_dataset/ILSVRC2012_val_00048374.bin 224 224 +35354 ./prep_dataset/ILSVRC2012_val_00038996.bin 224 224 +35355 ./prep_dataset/ILSVRC2012_val_00021714.bin 224 224 +35356 ./prep_dataset/ILSVRC2012_val_00002062.bin 224 224 +35357 ./prep_dataset/ILSVRC2012_val_00000111.bin 224 224 +35358 ./prep_dataset/ILSVRC2012_val_00010932.bin 224 224 +35359 ./prep_dataset/ILSVRC2012_val_00034647.bin 224 224 +35360 ./prep_dataset/ILSVRC2012_val_00032593.bin 224 224 +35361 ./prep_dataset/ILSVRC2012_val_00031903.bin 224 224 +35362 ./prep_dataset/ILSVRC2012_val_00045769.bin 224 224 +35363 ./prep_dataset/ILSVRC2012_val_00022234.bin 224 224 +35364 ./prep_dataset/ILSVRC2012_val_00044975.bin 224 224 +35365 ./prep_dataset/ILSVRC2012_val_00013890.bin 224 224 +35366 ./prep_dataset/ILSVRC2012_val_00018218.bin 224 224 +35367 ./prep_dataset/ILSVRC2012_val_00004964.bin 224 224 +35368 ./prep_dataset/ILSVRC2012_val_00014589.bin 224 224 +35369 ./prep_dataset/ILSVRC2012_val_00006069.bin 224 224 +35370 ./prep_dataset/ILSVRC2012_val_00029514.bin 224 224 +35371 ./prep_dataset/ILSVRC2012_val_00042669.bin 224 224 +35372 ./prep_dataset/ILSVRC2012_val_00016348.bin 224 224 +35373 ./prep_dataset/ILSVRC2012_val_00046146.bin 224 224 +35374 ./prep_dataset/ILSVRC2012_val_00039431.bin 224 224 +35375 ./prep_dataset/ILSVRC2012_val_00017284.bin 224 224 +35376 ./prep_dataset/ILSVRC2012_val_00022762.bin 224 224 +35377 ./prep_dataset/ILSVRC2012_val_00027906.bin 224 224 +35378 ./prep_dataset/ILSVRC2012_val_00001838.bin 224 224 +35379 ./prep_dataset/ILSVRC2012_val_00021210.bin 224 224 +35380 ./prep_dataset/ILSVRC2012_val_00000479.bin 224 224 +35381 ./prep_dataset/ILSVRC2012_val_00004963.bin 224 224 +35382 ./prep_dataset/ILSVRC2012_val_00001233.bin 224 224 +35383 ./prep_dataset/ILSVRC2012_val_00045960.bin 224 224 +35384 ./prep_dataset/ILSVRC2012_val_00035327.bin 224 224 +35385 ./prep_dataset/ILSVRC2012_val_00049105.bin 224 224 +35386 ./prep_dataset/ILSVRC2012_val_00039384.bin 224 224 +35387 ./prep_dataset/ILSVRC2012_val_00010665.bin 224 224 +35388 ./prep_dataset/ILSVRC2012_val_00016568.bin 224 224 +35389 ./prep_dataset/ILSVRC2012_val_00033041.bin 224 224 +35390 ./prep_dataset/ILSVRC2012_val_00036361.bin 224 224 +35391 ./prep_dataset/ILSVRC2012_val_00010233.bin 224 224 +35392 ./prep_dataset/ILSVRC2012_val_00010475.bin 224 224 +35393 ./prep_dataset/ILSVRC2012_val_00035298.bin 224 224 +35394 ./prep_dataset/ILSVRC2012_val_00040741.bin 224 224 +35395 ./prep_dataset/ILSVRC2012_val_00035953.bin 224 224 +35396 ./prep_dataset/ILSVRC2012_val_00041333.bin 224 224 +35397 ./prep_dataset/ILSVRC2012_val_00020214.bin 224 224 +35398 ./prep_dataset/ILSVRC2012_val_00037074.bin 224 224 +35399 ./prep_dataset/ILSVRC2012_val_00009104.bin 224 224 +35400 ./prep_dataset/ILSVRC2012_val_00011851.bin 224 224 +35401 ./prep_dataset/ILSVRC2012_val_00006815.bin 224 224 +35402 ./prep_dataset/ILSVRC2012_val_00019225.bin 224 224 +35403 ./prep_dataset/ILSVRC2012_val_00020239.bin 224 224 +35404 ./prep_dataset/ILSVRC2012_val_00025529.bin 224 224 +35405 ./prep_dataset/ILSVRC2012_val_00026568.bin 224 224 +35406 ./prep_dataset/ILSVRC2012_val_00026516.bin 224 224 +35407 ./prep_dataset/ILSVRC2012_val_00015555.bin 224 224 +35408 ./prep_dataset/ILSVRC2012_val_00022900.bin 224 224 +35409 ./prep_dataset/ILSVRC2012_val_00000701.bin 224 224 +35410 ./prep_dataset/ILSVRC2012_val_00026413.bin 224 224 +35411 ./prep_dataset/ILSVRC2012_val_00030392.bin 224 224 +35412 ./prep_dataset/ILSVRC2012_val_00014383.bin 224 224 +35413 ./prep_dataset/ILSVRC2012_val_00016358.bin 224 224 +35414 ./prep_dataset/ILSVRC2012_val_00040911.bin 224 224 +35415 ./prep_dataset/ILSVRC2012_val_00036842.bin 224 224 +35416 ./prep_dataset/ILSVRC2012_val_00045009.bin 224 224 +35417 ./prep_dataset/ILSVRC2012_val_00037903.bin 224 224 +35418 ./prep_dataset/ILSVRC2012_val_00026064.bin 224 224 +35419 ./prep_dataset/ILSVRC2012_val_00013478.bin 224 224 +35420 ./prep_dataset/ILSVRC2012_val_00012352.bin 224 224 +35421 ./prep_dataset/ILSVRC2012_val_00025388.bin 224 224 +35422 ./prep_dataset/ILSVRC2012_val_00020011.bin 224 224 +35423 ./prep_dataset/ILSVRC2012_val_00036409.bin 224 224 +35424 ./prep_dataset/ILSVRC2012_val_00042614.bin 224 224 +35425 ./prep_dataset/ILSVRC2012_val_00001447.bin 224 224 +35426 ./prep_dataset/ILSVRC2012_val_00030339.bin 224 224 +35427 ./prep_dataset/ILSVRC2012_val_00048178.bin 224 224 +35428 ./prep_dataset/ILSVRC2012_val_00016160.bin 224 224 +35429 ./prep_dataset/ILSVRC2012_val_00037032.bin 224 224 +35430 ./prep_dataset/ILSVRC2012_val_00000428.bin 224 224 +35431 ./prep_dataset/ILSVRC2012_val_00018236.bin 224 224 +35432 ./prep_dataset/ILSVRC2012_val_00013784.bin 224 224 +35433 ./prep_dataset/ILSVRC2012_val_00014275.bin 224 224 +35434 ./prep_dataset/ILSVRC2012_val_00039327.bin 224 224 +35435 ./prep_dataset/ILSVRC2012_val_00028451.bin 224 224 +35436 ./prep_dataset/ILSVRC2012_val_00020840.bin 224 224 +35437 ./prep_dataset/ILSVRC2012_val_00038398.bin 224 224 +35438 ./prep_dataset/ILSVRC2012_val_00022424.bin 224 224 +35439 ./prep_dataset/ILSVRC2012_val_00045863.bin 224 224 +35440 ./prep_dataset/ILSVRC2012_val_00014544.bin 224 224 +35441 ./prep_dataset/ILSVRC2012_val_00028703.bin 224 224 +35442 ./prep_dataset/ILSVRC2012_val_00010991.bin 224 224 +35443 ./prep_dataset/ILSVRC2012_val_00023039.bin 224 224 +35444 ./prep_dataset/ILSVRC2012_val_00018039.bin 224 224 +35445 ./prep_dataset/ILSVRC2012_val_00008928.bin 224 224 +35446 ./prep_dataset/ILSVRC2012_val_00034461.bin 224 224 +35447 ./prep_dataset/ILSVRC2012_val_00031462.bin 224 224 +35448 ./prep_dataset/ILSVRC2012_val_00047104.bin 224 224 +35449 ./prep_dataset/ILSVRC2012_val_00006941.bin 224 224 +35450 ./prep_dataset/ILSVRC2012_val_00027172.bin 224 224 +35451 ./prep_dataset/ILSVRC2012_val_00010736.bin 224 224 +35452 ./prep_dataset/ILSVRC2012_val_00001624.bin 224 224 +35453 ./prep_dataset/ILSVRC2012_val_00039135.bin 224 224 +35454 ./prep_dataset/ILSVRC2012_val_00030499.bin 224 224 +35455 ./prep_dataset/ILSVRC2012_val_00040271.bin 224 224 +35456 ./prep_dataset/ILSVRC2012_val_00032676.bin 224 224 +35457 ./prep_dataset/ILSVRC2012_val_00036532.bin 224 224 +35458 ./prep_dataset/ILSVRC2012_val_00037515.bin 224 224 +35459 ./prep_dataset/ILSVRC2012_val_00039199.bin 224 224 +35460 ./prep_dataset/ILSVRC2012_val_00032422.bin 224 224 +35461 ./prep_dataset/ILSVRC2012_val_00003051.bin 224 224 +35462 ./prep_dataset/ILSVRC2012_val_00009520.bin 224 224 +35463 ./prep_dataset/ILSVRC2012_val_00043120.bin 224 224 +35464 ./prep_dataset/ILSVRC2012_val_00024882.bin 224 224 +35465 ./prep_dataset/ILSVRC2012_val_00026839.bin 224 224 +35466 ./prep_dataset/ILSVRC2012_val_00040389.bin 224 224 +35467 ./prep_dataset/ILSVRC2012_val_00027433.bin 224 224 +35468 ./prep_dataset/ILSVRC2012_val_00030473.bin 224 224 +35469 ./prep_dataset/ILSVRC2012_val_00001870.bin 224 224 +35470 ./prep_dataset/ILSVRC2012_val_00016423.bin 224 224 +35471 ./prep_dataset/ILSVRC2012_val_00049472.bin 224 224 +35472 ./prep_dataset/ILSVRC2012_val_00045066.bin 224 224 +35473 ./prep_dataset/ILSVRC2012_val_00021250.bin 224 224 +35474 ./prep_dataset/ILSVRC2012_val_00021588.bin 224 224 +35475 ./prep_dataset/ILSVRC2012_val_00049021.bin 224 224 +35476 ./prep_dataset/ILSVRC2012_val_00044377.bin 224 224 +35477 ./prep_dataset/ILSVRC2012_val_00038386.bin 224 224 +35478 ./prep_dataset/ILSVRC2012_val_00041757.bin 224 224 +35479 ./prep_dataset/ILSVRC2012_val_00003078.bin 224 224 +35480 ./prep_dataset/ILSVRC2012_val_00001983.bin 224 224 +35481 ./prep_dataset/ILSVRC2012_val_00014284.bin 224 224 +35482 ./prep_dataset/ILSVRC2012_val_00018604.bin 224 224 +35483 ./prep_dataset/ILSVRC2012_val_00029255.bin 224 224 +35484 ./prep_dataset/ILSVRC2012_val_00012478.bin 224 224 +35485 ./prep_dataset/ILSVRC2012_val_00040303.bin 224 224 +35486 ./prep_dataset/ILSVRC2012_val_00003968.bin 224 224 +35487 ./prep_dataset/ILSVRC2012_val_00024522.bin 224 224 +35488 ./prep_dataset/ILSVRC2012_val_00049627.bin 224 224 +35489 ./prep_dataset/ILSVRC2012_val_00012625.bin 224 224 +35490 ./prep_dataset/ILSVRC2012_val_00009224.bin 224 224 +35491 ./prep_dataset/ILSVRC2012_val_00029855.bin 224 224 +35492 ./prep_dataset/ILSVRC2012_val_00000617.bin 224 224 +35493 ./prep_dataset/ILSVRC2012_val_00047812.bin 224 224 +35494 ./prep_dataset/ILSVRC2012_val_00009221.bin 224 224 +35495 ./prep_dataset/ILSVRC2012_val_00031085.bin 224 224 +35496 ./prep_dataset/ILSVRC2012_val_00001663.bin 224 224 +35497 ./prep_dataset/ILSVRC2012_val_00017237.bin 224 224 +35498 ./prep_dataset/ILSVRC2012_val_00025082.bin 224 224 +35499 ./prep_dataset/ILSVRC2012_val_00027004.bin 224 224 +35500 ./prep_dataset/ILSVRC2012_val_00010505.bin 224 224 +35501 ./prep_dataset/ILSVRC2012_val_00015278.bin 224 224 +35502 ./prep_dataset/ILSVRC2012_val_00014810.bin 224 224 +35503 ./prep_dataset/ILSVRC2012_val_00011186.bin 224 224 +35504 ./prep_dataset/ILSVRC2012_val_00017196.bin 224 224 +35505 ./prep_dataset/ILSVRC2012_val_00048064.bin 224 224 +35506 ./prep_dataset/ILSVRC2012_val_00003674.bin 224 224 +35507 ./prep_dataset/ILSVRC2012_val_00035911.bin 224 224 +35508 ./prep_dataset/ILSVRC2012_val_00049731.bin 224 224 +35509 ./prep_dataset/ILSVRC2012_val_00045063.bin 224 224 +35510 ./prep_dataset/ILSVRC2012_val_00020255.bin 224 224 +35511 ./prep_dataset/ILSVRC2012_val_00028015.bin 224 224 +35512 ./prep_dataset/ILSVRC2012_val_00013176.bin 224 224 +35513 ./prep_dataset/ILSVRC2012_val_00019266.bin 224 224 +35514 ./prep_dataset/ILSVRC2012_val_00025854.bin 224 224 +35515 ./prep_dataset/ILSVRC2012_val_00032138.bin 224 224 +35516 ./prep_dataset/ILSVRC2012_val_00021401.bin 224 224 +35517 ./prep_dataset/ILSVRC2012_val_00027109.bin 224 224 +35518 ./prep_dataset/ILSVRC2012_val_00026558.bin 224 224 +35519 ./prep_dataset/ILSVRC2012_val_00040415.bin 224 224 +35520 ./prep_dataset/ILSVRC2012_val_00040084.bin 224 224 +35521 ./prep_dataset/ILSVRC2012_val_00000229.bin 224 224 +35522 ./prep_dataset/ILSVRC2012_val_00031373.bin 224 224 +35523 ./prep_dataset/ILSVRC2012_val_00011878.bin 224 224 +35524 ./prep_dataset/ILSVRC2012_val_00048330.bin 224 224 +35525 ./prep_dataset/ILSVRC2012_val_00038621.bin 224 224 +35526 ./prep_dataset/ILSVRC2012_val_00031112.bin 224 224 +35527 ./prep_dataset/ILSVRC2012_val_00044315.bin 224 224 +35528 ./prep_dataset/ILSVRC2012_val_00012644.bin 224 224 +35529 ./prep_dataset/ILSVRC2012_val_00005418.bin 224 224 +35530 ./prep_dataset/ILSVRC2012_val_00047622.bin 224 224 +35531 ./prep_dataset/ILSVRC2012_val_00048656.bin 224 224 +35532 ./prep_dataset/ILSVRC2012_val_00034216.bin 224 224 +35533 ./prep_dataset/ILSVRC2012_val_00004237.bin 224 224 +35534 ./prep_dataset/ILSVRC2012_val_00040831.bin 224 224 +35535 ./prep_dataset/ILSVRC2012_val_00029727.bin 224 224 +35536 ./prep_dataset/ILSVRC2012_val_00029944.bin 224 224 +35537 ./prep_dataset/ILSVRC2012_val_00012333.bin 224 224 +35538 ./prep_dataset/ILSVRC2012_val_00028379.bin 224 224 +35539 ./prep_dataset/ILSVRC2012_val_00019363.bin 224 224 +35540 ./prep_dataset/ILSVRC2012_val_00046331.bin 224 224 +35541 ./prep_dataset/ILSVRC2012_val_00047365.bin 224 224 +35542 ./prep_dataset/ILSVRC2012_val_00005867.bin 224 224 +35543 ./prep_dataset/ILSVRC2012_val_00044654.bin 224 224 +35544 ./prep_dataset/ILSVRC2012_val_00041534.bin 224 224 +35545 ./prep_dataset/ILSVRC2012_val_00003977.bin 224 224 +35546 ./prep_dataset/ILSVRC2012_val_00002348.bin 224 224 +35547 ./prep_dataset/ILSVRC2012_val_00031332.bin 224 224 +35548 ./prep_dataset/ILSVRC2012_val_00000967.bin 224 224 +35549 ./prep_dataset/ILSVRC2012_val_00017896.bin 224 224 +35550 ./prep_dataset/ILSVRC2012_val_00024529.bin 224 224 +35551 ./prep_dataset/ILSVRC2012_val_00043946.bin 224 224 +35552 ./prep_dataset/ILSVRC2012_val_00023533.bin 224 224 +35553 ./prep_dataset/ILSVRC2012_val_00025795.bin 224 224 +35554 ./prep_dataset/ILSVRC2012_val_00008284.bin 224 224 +35555 ./prep_dataset/ILSVRC2012_val_00015968.bin 224 224 +35556 ./prep_dataset/ILSVRC2012_val_00044686.bin 224 224 +35557 ./prep_dataset/ILSVRC2012_val_00021737.bin 224 224 +35558 ./prep_dataset/ILSVRC2012_val_00008050.bin 224 224 +35559 ./prep_dataset/ILSVRC2012_val_00034035.bin 224 224 +35560 ./prep_dataset/ILSVRC2012_val_00005359.bin 224 224 +35561 ./prep_dataset/ILSVRC2012_val_00027494.bin 224 224 +35562 ./prep_dataset/ILSVRC2012_val_00038856.bin 224 224 +35563 ./prep_dataset/ILSVRC2012_val_00007979.bin 224 224 +35564 ./prep_dataset/ILSVRC2012_val_00026604.bin 224 224 +35565 ./prep_dataset/ILSVRC2012_val_00040015.bin 224 224 +35566 ./prep_dataset/ILSVRC2012_val_00009044.bin 224 224 +35567 ./prep_dataset/ILSVRC2012_val_00002921.bin 224 224 +35568 ./prep_dataset/ILSVRC2012_val_00021808.bin 224 224 +35569 ./prep_dataset/ILSVRC2012_val_00030950.bin 224 224 +35570 ./prep_dataset/ILSVRC2012_val_00045083.bin 224 224 +35571 ./prep_dataset/ILSVRC2012_val_00033734.bin 224 224 +35572 ./prep_dataset/ILSVRC2012_val_00015726.bin 224 224 +35573 ./prep_dataset/ILSVRC2012_val_00032695.bin 224 224 +35574 ./prep_dataset/ILSVRC2012_val_00040381.bin 224 224 +35575 ./prep_dataset/ILSVRC2012_val_00003218.bin 224 224 +35576 ./prep_dataset/ILSVRC2012_val_00022697.bin 224 224 +35577 ./prep_dataset/ILSVRC2012_val_00020119.bin 224 224 +35578 ./prep_dataset/ILSVRC2012_val_00040703.bin 224 224 +35579 ./prep_dataset/ILSVRC2012_val_00004409.bin 224 224 +35580 ./prep_dataset/ILSVRC2012_val_00038333.bin 224 224 +35581 ./prep_dataset/ILSVRC2012_val_00007102.bin 224 224 +35582 ./prep_dataset/ILSVRC2012_val_00019749.bin 224 224 +35583 ./prep_dataset/ILSVRC2012_val_00014861.bin 224 224 +35584 ./prep_dataset/ILSVRC2012_val_00027100.bin 224 224 +35585 ./prep_dataset/ILSVRC2012_val_00005282.bin 224 224 +35586 ./prep_dataset/ILSVRC2012_val_00005131.bin 224 224 +35587 ./prep_dataset/ILSVRC2012_val_00037087.bin 224 224 +35588 ./prep_dataset/ILSVRC2012_val_00006107.bin 224 224 +35589 ./prep_dataset/ILSVRC2012_val_00021203.bin 224 224 +35590 ./prep_dataset/ILSVRC2012_val_00032426.bin 224 224 +35591 ./prep_dataset/ILSVRC2012_val_00043609.bin 224 224 +35592 ./prep_dataset/ILSVRC2012_val_00042880.bin 224 224 +35593 ./prep_dataset/ILSVRC2012_val_00048788.bin 224 224 +35594 ./prep_dataset/ILSVRC2012_val_00005217.bin 224 224 +35595 ./prep_dataset/ILSVRC2012_val_00024866.bin 224 224 +35596 ./prep_dataset/ILSVRC2012_val_00037954.bin 224 224 +35597 ./prep_dataset/ILSVRC2012_val_00033723.bin 224 224 +35598 ./prep_dataset/ILSVRC2012_val_00028538.bin 224 224 +35599 ./prep_dataset/ILSVRC2012_val_00043414.bin 224 224 +35600 ./prep_dataset/ILSVRC2012_val_00049764.bin 224 224 +35601 ./prep_dataset/ILSVRC2012_val_00049334.bin 224 224 +35602 ./prep_dataset/ILSVRC2012_val_00044253.bin 224 224 +35603 ./prep_dataset/ILSVRC2012_val_00041198.bin 224 224 +35604 ./prep_dataset/ILSVRC2012_val_00032358.bin 224 224 +35605 ./prep_dataset/ILSVRC2012_val_00042265.bin 224 224 +35606 ./prep_dataset/ILSVRC2012_val_00049693.bin 224 224 +35607 ./prep_dataset/ILSVRC2012_val_00022040.bin 224 224 +35608 ./prep_dataset/ILSVRC2012_val_00046074.bin 224 224 +35609 ./prep_dataset/ILSVRC2012_val_00014479.bin 224 224 +35610 ./prep_dataset/ILSVRC2012_val_00030169.bin 224 224 +35611 ./prep_dataset/ILSVRC2012_val_00004612.bin 224 224 +35612 ./prep_dataset/ILSVRC2012_val_00005312.bin 224 224 +35613 ./prep_dataset/ILSVRC2012_val_00018122.bin 224 224 +35614 ./prep_dataset/ILSVRC2012_val_00031567.bin 224 224 +35615 ./prep_dataset/ILSVRC2012_val_00021491.bin 224 224 +35616 ./prep_dataset/ILSVRC2012_val_00042277.bin 224 224 +35617 ./prep_dataset/ILSVRC2012_val_00015309.bin 224 224 +35618 ./prep_dataset/ILSVRC2012_val_00040782.bin 224 224 +35619 ./prep_dataset/ILSVRC2012_val_00000555.bin 224 224 +35620 ./prep_dataset/ILSVRC2012_val_00032986.bin 224 224 +35621 ./prep_dataset/ILSVRC2012_val_00001275.bin 224 224 +35622 ./prep_dataset/ILSVRC2012_val_00030310.bin 224 224 +35623 ./prep_dataset/ILSVRC2012_val_00005143.bin 224 224 +35624 ./prep_dataset/ILSVRC2012_val_00042897.bin 224 224 +35625 ./prep_dataset/ILSVRC2012_val_00044407.bin 224 224 +35626 ./prep_dataset/ILSVRC2012_val_00023826.bin 224 224 +35627 ./prep_dataset/ILSVRC2012_val_00041615.bin 224 224 +35628 ./prep_dataset/ILSVRC2012_val_00039468.bin 224 224 +35629 ./prep_dataset/ILSVRC2012_val_00046475.bin 224 224 +35630 ./prep_dataset/ILSVRC2012_val_00013303.bin 224 224 +35631 ./prep_dataset/ILSVRC2012_val_00023274.bin 224 224 +35632 ./prep_dataset/ILSVRC2012_val_00048641.bin 224 224 +35633 ./prep_dataset/ILSVRC2012_val_00025047.bin 224 224 +35634 ./prep_dataset/ILSVRC2012_val_00034620.bin 224 224 +35635 ./prep_dataset/ILSVRC2012_val_00034414.bin 224 224 +35636 ./prep_dataset/ILSVRC2012_val_00003839.bin 224 224 +35637 ./prep_dataset/ILSVRC2012_val_00028263.bin 224 224 +35638 ./prep_dataset/ILSVRC2012_val_00004592.bin 224 224 +35639 ./prep_dataset/ILSVRC2012_val_00041344.bin 224 224 +35640 ./prep_dataset/ILSVRC2012_val_00030777.bin 224 224 +35641 ./prep_dataset/ILSVRC2012_val_00019741.bin 224 224 +35642 ./prep_dataset/ILSVRC2012_val_00016093.bin 224 224 +35643 ./prep_dataset/ILSVRC2012_val_00007962.bin 224 224 +35644 ./prep_dataset/ILSVRC2012_val_00046358.bin 224 224 +35645 ./prep_dataset/ILSVRC2012_val_00046503.bin 224 224 +35646 ./prep_dataset/ILSVRC2012_val_00022717.bin 224 224 +35647 ./prep_dataset/ILSVRC2012_val_00018792.bin 224 224 +35648 ./prep_dataset/ILSVRC2012_val_00009574.bin 224 224 +35649 ./prep_dataset/ILSVRC2012_val_00029841.bin 224 224 +35650 ./prep_dataset/ILSVRC2012_val_00041304.bin 224 224 +35651 ./prep_dataset/ILSVRC2012_val_00039059.bin 224 224 +35652 ./prep_dataset/ILSVRC2012_val_00017622.bin 224 224 +35653 ./prep_dataset/ILSVRC2012_val_00008675.bin 224 224 +35654 ./prep_dataset/ILSVRC2012_val_00042245.bin 224 224 +35655 ./prep_dataset/ILSVRC2012_val_00005484.bin 224 224 +35656 ./prep_dataset/ILSVRC2012_val_00002228.bin 224 224 +35657 ./prep_dataset/ILSVRC2012_val_00012173.bin 224 224 +35658 ./prep_dataset/ILSVRC2012_val_00001284.bin 224 224 +35659 ./prep_dataset/ILSVRC2012_val_00023204.bin 224 224 +35660 ./prep_dataset/ILSVRC2012_val_00039014.bin 224 224 +35661 ./prep_dataset/ILSVRC2012_val_00007505.bin 224 224 +35662 ./prep_dataset/ILSVRC2012_val_00018047.bin 224 224 +35663 ./prep_dataset/ILSVRC2012_val_00019261.bin 224 224 +35664 ./prep_dataset/ILSVRC2012_val_00013072.bin 224 224 +35665 ./prep_dataset/ILSVRC2012_val_00049363.bin 224 224 +35666 ./prep_dataset/ILSVRC2012_val_00025848.bin 224 224 +35667 ./prep_dataset/ILSVRC2012_val_00000481.bin 224 224 +35668 ./prep_dataset/ILSVRC2012_val_00021447.bin 224 224 +35669 ./prep_dataset/ILSVRC2012_val_00035139.bin 224 224 +35670 ./prep_dataset/ILSVRC2012_val_00017651.bin 224 224 +35671 ./prep_dataset/ILSVRC2012_val_00006624.bin 224 224 +35672 ./prep_dataset/ILSVRC2012_val_00005076.bin 224 224 +35673 ./prep_dataset/ILSVRC2012_val_00039427.bin 224 224 +35674 ./prep_dataset/ILSVRC2012_val_00008740.bin 224 224 +35675 ./prep_dataset/ILSVRC2012_val_00043511.bin 224 224 +35676 ./prep_dataset/ILSVRC2012_val_00000692.bin 224 224 +35677 ./prep_dataset/ILSVRC2012_val_00010871.bin 224 224 +35678 ./prep_dataset/ILSVRC2012_val_00049376.bin 224 224 +35679 ./prep_dataset/ILSVRC2012_val_00027478.bin 224 224 +35680 ./prep_dataset/ILSVRC2012_val_00021604.bin 224 224 +35681 ./prep_dataset/ILSVRC2012_val_00001057.bin 224 224 +35682 ./prep_dataset/ILSVRC2012_val_00025540.bin 224 224 +35683 ./prep_dataset/ILSVRC2012_val_00039913.bin 224 224 +35684 ./prep_dataset/ILSVRC2012_val_00028288.bin 224 224 +35685 ./prep_dataset/ILSVRC2012_val_00048260.bin 224 224 +35686 ./prep_dataset/ILSVRC2012_val_00044244.bin 224 224 +35687 ./prep_dataset/ILSVRC2012_val_00047090.bin 224 224 +35688 ./prep_dataset/ILSVRC2012_val_00021936.bin 224 224 +35689 ./prep_dataset/ILSVRC2012_val_00000070.bin 224 224 +35690 ./prep_dataset/ILSVRC2012_val_00022487.bin 224 224 +35691 ./prep_dataset/ILSVRC2012_val_00048623.bin 224 224 +35692 ./prep_dataset/ILSVRC2012_val_00037238.bin 224 224 +35693 ./prep_dataset/ILSVRC2012_val_00018559.bin 224 224 +35694 ./prep_dataset/ILSVRC2012_val_00007089.bin 224 224 +35695 ./prep_dataset/ILSVRC2012_val_00014120.bin 224 224 +35696 ./prep_dataset/ILSVRC2012_val_00042082.bin 224 224 +35697 ./prep_dataset/ILSVRC2012_val_00011124.bin 224 224 +35698 ./prep_dataset/ILSVRC2012_val_00041728.bin 224 224 +35699 ./prep_dataset/ILSVRC2012_val_00040115.bin 224 224 +35700 ./prep_dataset/ILSVRC2012_val_00044458.bin 224 224 +35701 ./prep_dataset/ILSVRC2012_val_00019535.bin 224 224 +35702 ./prep_dataset/ILSVRC2012_val_00030702.bin 224 224 +35703 ./prep_dataset/ILSVRC2012_val_00044684.bin 224 224 +35704 ./prep_dataset/ILSVRC2012_val_00020243.bin 224 224 +35705 ./prep_dataset/ILSVRC2012_val_00010597.bin 224 224 +35706 ./prep_dataset/ILSVRC2012_val_00024533.bin 224 224 +35707 ./prep_dataset/ILSVRC2012_val_00020319.bin 224 224 +35708 ./prep_dataset/ILSVRC2012_val_00014584.bin 224 224 +35709 ./prep_dataset/ILSVRC2012_val_00006252.bin 224 224 +35710 ./prep_dataset/ILSVRC2012_val_00048223.bin 224 224 +35711 ./prep_dataset/ILSVRC2012_val_00024193.bin 224 224 +35712 ./prep_dataset/ILSVRC2012_val_00023910.bin 224 224 +35713 ./prep_dataset/ILSVRC2012_val_00013593.bin 224 224 +35714 ./prep_dataset/ILSVRC2012_val_00020099.bin 224 224 +35715 ./prep_dataset/ILSVRC2012_val_00036269.bin 224 224 +35716 ./prep_dataset/ILSVRC2012_val_00005984.bin 224 224 +35717 ./prep_dataset/ILSVRC2012_val_00040104.bin 224 224 +35718 ./prep_dataset/ILSVRC2012_val_00034914.bin 224 224 +35719 ./prep_dataset/ILSVRC2012_val_00036232.bin 224 224 +35720 ./prep_dataset/ILSVRC2012_val_00041902.bin 224 224 +35721 ./prep_dataset/ILSVRC2012_val_00036679.bin 224 224 +35722 ./prep_dataset/ILSVRC2012_val_00005699.bin 224 224 +35723 ./prep_dataset/ILSVRC2012_val_00045868.bin 224 224 +35724 ./prep_dataset/ILSVRC2012_val_00040997.bin 224 224 +35725 ./prep_dataset/ILSVRC2012_val_00026278.bin 224 224 +35726 ./prep_dataset/ILSVRC2012_val_00009468.bin 224 224 +35727 ./prep_dataset/ILSVRC2012_val_00022521.bin 224 224 +35728 ./prep_dataset/ILSVRC2012_val_00013959.bin 224 224 +35729 ./prep_dataset/ILSVRC2012_val_00008981.bin 224 224 +35730 ./prep_dataset/ILSVRC2012_val_00029317.bin 224 224 +35731 ./prep_dataset/ILSVRC2012_val_00000538.bin 224 224 +35732 ./prep_dataset/ILSVRC2012_val_00001489.bin 224 224 +35733 ./prep_dataset/ILSVRC2012_val_00027881.bin 224 224 +35734 ./prep_dataset/ILSVRC2012_val_00005945.bin 224 224 +35735 ./prep_dataset/ILSVRC2012_val_00042495.bin 224 224 +35736 ./prep_dataset/ILSVRC2012_val_00037413.bin 224 224 +35737 ./prep_dataset/ILSVRC2012_val_00028241.bin 224 224 +35738 ./prep_dataset/ILSVRC2012_val_00012160.bin 224 224 +35739 ./prep_dataset/ILSVRC2012_val_00017503.bin 224 224 +35740 ./prep_dataset/ILSVRC2012_val_00042647.bin 224 224 +35741 ./prep_dataset/ILSVRC2012_val_00049937.bin 224 224 +35742 ./prep_dataset/ILSVRC2012_val_00010319.bin 224 224 +35743 ./prep_dataset/ILSVRC2012_val_00013522.bin 224 224 +35744 ./prep_dataset/ILSVRC2012_val_00013452.bin 224 224 +35745 ./prep_dataset/ILSVRC2012_val_00007849.bin 224 224 +35746 ./prep_dataset/ILSVRC2012_val_00011037.bin 224 224 +35747 ./prep_dataset/ILSVRC2012_val_00020648.bin 224 224 +35748 ./prep_dataset/ILSVRC2012_val_00040702.bin 224 224 +35749 ./prep_dataset/ILSVRC2012_val_00015078.bin 224 224 +35750 ./prep_dataset/ILSVRC2012_val_00043905.bin 224 224 +35751 ./prep_dataset/ILSVRC2012_val_00040786.bin 224 224 +35752 ./prep_dataset/ILSVRC2012_val_00028488.bin 224 224 +35753 ./prep_dataset/ILSVRC2012_val_00017524.bin 224 224 +35754 ./prep_dataset/ILSVRC2012_val_00048541.bin 224 224 +35755 ./prep_dataset/ILSVRC2012_val_00012960.bin 224 224 +35756 ./prep_dataset/ILSVRC2012_val_00032781.bin 224 224 +35757 ./prep_dataset/ILSVRC2012_val_00023305.bin 224 224 +35758 ./prep_dataset/ILSVRC2012_val_00021083.bin 224 224 +35759 ./prep_dataset/ILSVRC2012_val_00009355.bin 224 224 +35760 ./prep_dataset/ILSVRC2012_val_00041789.bin 224 224 +35761 ./prep_dataset/ILSVRC2012_val_00043698.bin 224 224 +35762 ./prep_dataset/ILSVRC2012_val_00022420.bin 224 224 +35763 ./prep_dataset/ILSVRC2012_val_00007676.bin 224 224 +35764 ./prep_dataset/ILSVRC2012_val_00004512.bin 224 224 +35765 ./prep_dataset/ILSVRC2012_val_00015117.bin 224 224 +35766 ./prep_dataset/ILSVRC2012_val_00045224.bin 224 224 +35767 ./prep_dataset/ILSVRC2012_val_00033478.bin 224 224 +35768 ./prep_dataset/ILSVRC2012_val_00029711.bin 224 224 +35769 ./prep_dataset/ILSVRC2012_val_00005661.bin 224 224 +35770 ./prep_dataset/ILSVRC2012_val_00049222.bin 224 224 +35771 ./prep_dataset/ILSVRC2012_val_00044873.bin 224 224 +35772 ./prep_dataset/ILSVRC2012_val_00005238.bin 224 224 +35773 ./prep_dataset/ILSVRC2012_val_00019476.bin 224 224 +35774 ./prep_dataset/ILSVRC2012_val_00001726.bin 224 224 +35775 ./prep_dataset/ILSVRC2012_val_00034685.bin 224 224 +35776 ./prep_dataset/ILSVRC2012_val_00008153.bin 224 224 +35777 ./prep_dataset/ILSVRC2012_val_00005726.bin 224 224 +35778 ./prep_dataset/ILSVRC2012_val_00005260.bin 224 224 +35779 ./prep_dataset/ILSVRC2012_val_00028512.bin 224 224 +35780 ./prep_dataset/ILSVRC2012_val_00049402.bin 224 224 +35781 ./prep_dataset/ILSVRC2012_val_00034548.bin 224 224 +35782 ./prep_dataset/ILSVRC2012_val_00008590.bin 224 224 +35783 ./prep_dataset/ILSVRC2012_val_00023688.bin 224 224 +35784 ./prep_dataset/ILSVRC2012_val_00048440.bin 224 224 +35785 ./prep_dataset/ILSVRC2012_val_00023803.bin 224 224 +35786 ./prep_dataset/ILSVRC2012_val_00017964.bin 224 224 +35787 ./prep_dataset/ILSVRC2012_val_00025452.bin 224 224 +35788 ./prep_dataset/ILSVRC2012_val_00000146.bin 224 224 +35789 ./prep_dataset/ILSVRC2012_val_00016148.bin 224 224 +35790 ./prep_dataset/ILSVRC2012_val_00005090.bin 224 224 +35791 ./prep_dataset/ILSVRC2012_val_00032471.bin 224 224 +35792 ./prep_dataset/ILSVRC2012_val_00046726.bin 224 224 +35793 ./prep_dataset/ILSVRC2012_val_00020518.bin 224 224 +35794 ./prep_dataset/ILSVRC2012_val_00003723.bin 224 224 +35795 ./prep_dataset/ILSVRC2012_val_00016617.bin 224 224 +35796 ./prep_dataset/ILSVRC2012_val_00023776.bin 224 224 +35797 ./prep_dataset/ILSVRC2012_val_00048971.bin 224 224 +35798 ./prep_dataset/ILSVRC2012_val_00012619.bin 224 224 +35799 ./prep_dataset/ILSVRC2012_val_00021204.bin 224 224 +35800 ./prep_dataset/ILSVRC2012_val_00030805.bin 224 224 +35801 ./prep_dataset/ILSVRC2012_val_00038782.bin 224 224 +35802 ./prep_dataset/ILSVRC2012_val_00042446.bin 224 224 +35803 ./prep_dataset/ILSVRC2012_val_00032264.bin 224 224 +35804 ./prep_dataset/ILSVRC2012_val_00046796.bin 224 224 +35805 ./prep_dataset/ILSVRC2012_val_00049865.bin 224 224 +35806 ./prep_dataset/ILSVRC2012_val_00039161.bin 224 224 +35807 ./prep_dataset/ILSVRC2012_val_00047456.bin 224 224 +35808 ./prep_dataset/ILSVRC2012_val_00029058.bin 224 224 +35809 ./prep_dataset/ILSVRC2012_val_00006286.bin 224 224 +35810 ./prep_dataset/ILSVRC2012_val_00015460.bin 224 224 +35811 ./prep_dataset/ILSVRC2012_val_00035035.bin 224 224 +35812 ./prep_dataset/ILSVRC2012_val_00027490.bin 224 224 +35813 ./prep_dataset/ILSVRC2012_val_00022851.bin 224 224 +35814 ./prep_dataset/ILSVRC2012_val_00016433.bin 224 224 +35815 ./prep_dataset/ILSVRC2012_val_00017522.bin 224 224 +35816 ./prep_dataset/ILSVRC2012_val_00018691.bin 224 224 +35817 ./prep_dataset/ILSVRC2012_val_00038208.bin 224 224 +35818 ./prep_dataset/ILSVRC2012_val_00037575.bin 224 224 +35819 ./prep_dataset/ILSVRC2012_val_00020680.bin 224 224 +35820 ./prep_dataset/ILSVRC2012_val_00024675.bin 224 224 +35821 ./prep_dataset/ILSVRC2012_val_00015220.bin 224 224 +35822 ./prep_dataset/ILSVRC2012_val_00012756.bin 224 224 +35823 ./prep_dataset/ILSVRC2012_val_00015121.bin 224 224 +35824 ./prep_dataset/ILSVRC2012_val_00026376.bin 224 224 +35825 ./prep_dataset/ILSVRC2012_val_00044235.bin 224 224 +35826 ./prep_dataset/ILSVRC2012_val_00023990.bin 224 224 +35827 ./prep_dataset/ILSVRC2012_val_00042179.bin 224 224 +35828 ./prep_dataset/ILSVRC2012_val_00009660.bin 224 224 +35829 ./prep_dataset/ILSVRC2012_val_00015477.bin 224 224 +35830 ./prep_dataset/ILSVRC2012_val_00006169.bin 224 224 +35831 ./prep_dataset/ILSVRC2012_val_00006515.bin 224 224 +35832 ./prep_dataset/ILSVRC2012_val_00047547.bin 224 224 +35833 ./prep_dataset/ILSVRC2012_val_00049475.bin 224 224 +35834 ./prep_dataset/ILSVRC2012_val_00031827.bin 224 224 +35835 ./prep_dataset/ILSVRC2012_val_00046400.bin 224 224 +35836 ./prep_dataset/ILSVRC2012_val_00035416.bin 224 224 +35837 ./prep_dataset/ILSVRC2012_val_00006302.bin 224 224 +35838 ./prep_dataset/ILSVRC2012_val_00040974.bin 224 224 +35839 ./prep_dataset/ILSVRC2012_val_00005751.bin 224 224 +35840 ./prep_dataset/ILSVRC2012_val_00027457.bin 224 224 +35841 ./prep_dataset/ILSVRC2012_val_00003274.bin 224 224 +35842 ./prep_dataset/ILSVRC2012_val_00002524.bin 224 224 +35843 ./prep_dataset/ILSVRC2012_val_00018092.bin 224 224 +35844 ./prep_dataset/ILSVRC2012_val_00026059.bin 224 224 +35845 ./prep_dataset/ILSVRC2012_val_00039125.bin 224 224 +35846 ./prep_dataset/ILSVRC2012_val_00026786.bin 224 224 +35847 ./prep_dataset/ILSVRC2012_val_00020465.bin 224 224 +35848 ./prep_dataset/ILSVRC2012_val_00014841.bin 224 224 +35849 ./prep_dataset/ILSVRC2012_val_00002947.bin 224 224 +35850 ./prep_dataset/ILSVRC2012_val_00034728.bin 224 224 +35851 ./prep_dataset/ILSVRC2012_val_00039064.bin 224 224 +35852 ./prep_dataset/ILSVRC2012_val_00032614.bin 224 224 +35853 ./prep_dataset/ILSVRC2012_val_00044306.bin 224 224 +35854 ./prep_dataset/ILSVRC2012_val_00005129.bin 224 224 +35855 ./prep_dataset/ILSVRC2012_val_00010674.bin 224 224 +35856 ./prep_dataset/ILSVRC2012_val_00041084.bin 224 224 +35857 ./prep_dataset/ILSVRC2012_val_00047777.bin 224 224 +35858 ./prep_dataset/ILSVRC2012_val_00036699.bin 224 224 +35859 ./prep_dataset/ILSVRC2012_val_00010182.bin 224 224 +35860 ./prep_dataset/ILSVRC2012_val_00045842.bin 224 224 +35861 ./prep_dataset/ILSVRC2012_val_00010341.bin 224 224 +35862 ./prep_dataset/ILSVRC2012_val_00001466.bin 224 224 +35863 ./prep_dataset/ILSVRC2012_val_00013775.bin 224 224 +35864 ./prep_dataset/ILSVRC2012_val_00015238.bin 224 224 +35865 ./prep_dataset/ILSVRC2012_val_00011986.bin 224 224 +35866 ./prep_dataset/ILSVRC2012_val_00044236.bin 224 224 +35867 ./prep_dataset/ILSVRC2012_val_00021450.bin 224 224 +35868 ./prep_dataset/ILSVRC2012_val_00020054.bin 224 224 +35869 ./prep_dataset/ILSVRC2012_val_00047637.bin 224 224 +35870 ./prep_dataset/ILSVRC2012_val_00012335.bin 224 224 +35871 ./prep_dataset/ILSVRC2012_val_00022085.bin 224 224 +35872 ./prep_dataset/ILSVRC2012_val_00014162.bin 224 224 +35873 ./prep_dataset/ILSVRC2012_val_00016943.bin 224 224 +35874 ./prep_dataset/ILSVRC2012_val_00029343.bin 224 224 +35875 ./prep_dataset/ILSVRC2012_val_00021589.bin 224 224 +35876 ./prep_dataset/ILSVRC2012_val_00002188.bin 224 224 +35877 ./prep_dataset/ILSVRC2012_val_00008165.bin 224 224 +35878 ./prep_dataset/ILSVRC2012_val_00041223.bin 224 224 +35879 ./prep_dataset/ILSVRC2012_val_00001696.bin 224 224 +35880 ./prep_dataset/ILSVRC2012_val_00035116.bin 224 224 +35881 ./prep_dataset/ILSVRC2012_val_00035302.bin 224 224 +35882 ./prep_dataset/ILSVRC2012_val_00028456.bin 224 224 +35883 ./prep_dataset/ILSVRC2012_val_00029530.bin 224 224 +35884 ./prep_dataset/ILSVRC2012_val_00049018.bin 224 224 +35885 ./prep_dataset/ILSVRC2012_val_00008360.bin 224 224 +35886 ./prep_dataset/ILSVRC2012_val_00007213.bin 224 224 +35887 ./prep_dataset/ILSVRC2012_val_00002408.bin 224 224 +35888 ./prep_dataset/ILSVRC2012_val_00045109.bin 224 224 +35889 ./prep_dataset/ILSVRC2012_val_00018967.bin 224 224 +35890 ./prep_dataset/ILSVRC2012_val_00002883.bin 224 224 +35891 ./prep_dataset/ILSVRC2012_val_00013851.bin 224 224 +35892 ./prep_dataset/ILSVRC2012_val_00023377.bin 224 224 +35893 ./prep_dataset/ILSVRC2012_val_00020712.bin 224 224 +35894 ./prep_dataset/ILSVRC2012_val_00009898.bin 224 224 +35895 ./prep_dataset/ILSVRC2012_val_00045958.bin 224 224 +35896 ./prep_dataset/ILSVRC2012_val_00045039.bin 224 224 +35897 ./prep_dataset/ILSVRC2012_val_00014723.bin 224 224 +35898 ./prep_dataset/ILSVRC2012_val_00032243.bin 224 224 +35899 ./prep_dataset/ILSVRC2012_val_00012076.bin 224 224 +35900 ./prep_dataset/ILSVRC2012_val_00037648.bin 224 224 +35901 ./prep_dataset/ILSVRC2012_val_00004721.bin 224 224 +35902 ./prep_dataset/ILSVRC2012_val_00037546.bin 224 224 +35903 ./prep_dataset/ILSVRC2012_val_00011269.bin 224 224 +35904 ./prep_dataset/ILSVRC2012_val_00043821.bin 224 224 +35905 ./prep_dataset/ILSVRC2012_val_00038876.bin 224 224 +35906 ./prep_dataset/ILSVRC2012_val_00024370.bin 224 224 +35907 ./prep_dataset/ILSVRC2012_val_00048147.bin 224 224 +35908 ./prep_dataset/ILSVRC2012_val_00002200.bin 224 224 +35909 ./prep_dataset/ILSVRC2012_val_00015899.bin 224 224 +35910 ./prep_dataset/ILSVRC2012_val_00007020.bin 224 224 +35911 ./prep_dataset/ILSVRC2012_val_00002067.bin 224 224 +35912 ./prep_dataset/ILSVRC2012_val_00003118.bin 224 224 +35913 ./prep_dataset/ILSVRC2012_val_00008673.bin 224 224 +35914 ./prep_dataset/ILSVRC2012_val_00001467.bin 224 224 +35915 ./prep_dataset/ILSVRC2012_val_00015073.bin 224 224 +35916 ./prep_dataset/ILSVRC2012_val_00040265.bin 224 224 +35917 ./prep_dataset/ILSVRC2012_val_00025167.bin 224 224 +35918 ./prep_dataset/ILSVRC2012_val_00001272.bin 224 224 +35919 ./prep_dataset/ILSVRC2012_val_00033094.bin 224 224 +35920 ./prep_dataset/ILSVRC2012_val_00012140.bin 224 224 +35921 ./prep_dataset/ILSVRC2012_val_00031809.bin 224 224 +35922 ./prep_dataset/ILSVRC2012_val_00000315.bin 224 224 +35923 ./prep_dataset/ILSVRC2012_val_00007204.bin 224 224 +35924 ./prep_dataset/ILSVRC2012_val_00044041.bin 224 224 +35925 ./prep_dataset/ILSVRC2012_val_00029171.bin 224 224 +35926 ./prep_dataset/ILSVRC2012_val_00015943.bin 224 224 +35927 ./prep_dataset/ILSVRC2012_val_00025221.bin 224 224 +35928 ./prep_dataset/ILSVRC2012_val_00038287.bin 224 224 +35929 ./prep_dataset/ILSVRC2012_val_00012161.bin 224 224 +35930 ./prep_dataset/ILSVRC2012_val_00034658.bin 224 224 +35931 ./prep_dataset/ILSVRC2012_val_00000194.bin 224 224 +35932 ./prep_dataset/ILSVRC2012_val_00011587.bin 224 224 +35933 ./prep_dataset/ILSVRC2012_val_00013294.bin 224 224 +35934 ./prep_dataset/ILSVRC2012_val_00046385.bin 224 224 +35935 ./prep_dataset/ILSVRC2012_val_00039990.bin 224 224 +35936 ./prep_dataset/ILSVRC2012_val_00039996.bin 224 224 +35937 ./prep_dataset/ILSVRC2012_val_00037421.bin 224 224 +35938 ./prep_dataset/ILSVRC2012_val_00028335.bin 224 224 +35939 ./prep_dataset/ILSVRC2012_val_00046184.bin 224 224 +35940 ./prep_dataset/ILSVRC2012_val_00038809.bin 224 224 +35941 ./prep_dataset/ILSVRC2012_val_00028911.bin 224 224 +35942 ./prep_dataset/ILSVRC2012_val_00031654.bin 224 224 +35943 ./prep_dataset/ILSVRC2012_val_00025838.bin 224 224 +35944 ./prep_dataset/ILSVRC2012_val_00013952.bin 224 224 +35945 ./prep_dataset/ILSVRC2012_val_00020782.bin 224 224 +35946 ./prep_dataset/ILSVRC2012_val_00034199.bin 224 224 +35947 ./prep_dataset/ILSVRC2012_val_00036785.bin 224 224 +35948 ./prep_dataset/ILSVRC2012_val_00049733.bin 224 224 +35949 ./prep_dataset/ILSVRC2012_val_00029436.bin 224 224 +35950 ./prep_dataset/ILSVRC2012_val_00002882.bin 224 224 +35951 ./prep_dataset/ILSVRC2012_val_00049350.bin 224 224 +35952 ./prep_dataset/ILSVRC2012_val_00017921.bin 224 224 +35953 ./prep_dataset/ILSVRC2012_val_00026015.bin 224 224 +35954 ./prep_dataset/ILSVRC2012_val_00044008.bin 224 224 +35955 ./prep_dataset/ILSVRC2012_val_00012223.bin 224 224 +35956 ./prep_dataset/ILSVRC2012_val_00037482.bin 224 224 +35957 ./prep_dataset/ILSVRC2012_val_00004022.bin 224 224 +35958 ./prep_dataset/ILSVRC2012_val_00014674.bin 224 224 +35959 ./prep_dataset/ILSVRC2012_val_00032174.bin 224 224 +35960 ./prep_dataset/ILSVRC2012_val_00045902.bin 224 224 +35961 ./prep_dataset/ILSVRC2012_val_00033780.bin 224 224 +35962 ./prep_dataset/ILSVRC2012_val_00041335.bin 224 224 +35963 ./prep_dataset/ILSVRC2012_val_00013173.bin 224 224 +35964 ./prep_dataset/ILSVRC2012_val_00042517.bin 224 224 +35965 ./prep_dataset/ILSVRC2012_val_00021451.bin 224 224 +35966 ./prep_dataset/ILSVRC2012_val_00027254.bin 224 224 +35967 ./prep_dataset/ILSVRC2012_val_00016150.bin 224 224 +35968 ./prep_dataset/ILSVRC2012_val_00024237.bin 224 224 +35969 ./prep_dataset/ILSVRC2012_val_00008498.bin 224 224 +35970 ./prep_dataset/ILSVRC2012_val_00011496.bin 224 224 +35971 ./prep_dataset/ILSVRC2012_val_00040574.bin 224 224 +35972 ./prep_dataset/ILSVRC2012_val_00005880.bin 224 224 +35973 ./prep_dataset/ILSVRC2012_val_00027153.bin 224 224 +35974 ./prep_dataset/ILSVRC2012_val_00045880.bin 224 224 +35975 ./prep_dataset/ILSVRC2012_val_00007577.bin 224 224 +35976 ./prep_dataset/ILSVRC2012_val_00019109.bin 224 224 +35977 ./prep_dataset/ILSVRC2012_val_00026689.bin 224 224 +35978 ./prep_dataset/ILSVRC2012_val_00037474.bin 224 224 +35979 ./prep_dataset/ILSVRC2012_val_00039157.bin 224 224 +35980 ./prep_dataset/ILSVRC2012_val_00023484.bin 224 224 +35981 ./prep_dataset/ILSVRC2012_val_00021188.bin 224 224 +35982 ./prep_dataset/ILSVRC2012_val_00011210.bin 224 224 +35983 ./prep_dataset/ILSVRC2012_val_00029476.bin 224 224 +35984 ./prep_dataset/ILSVRC2012_val_00028748.bin 224 224 +35985 ./prep_dataset/ILSVRC2012_val_00001395.bin 224 224 +35986 ./prep_dataset/ILSVRC2012_val_00038848.bin 224 224 +35987 ./prep_dataset/ILSVRC2012_val_00016216.bin 224 224 +35988 ./prep_dataset/ILSVRC2012_val_00020354.bin 224 224 +35989 ./prep_dataset/ILSVRC2012_val_00033195.bin 224 224 +35990 ./prep_dataset/ILSVRC2012_val_00049501.bin 224 224 +35991 ./prep_dataset/ILSVRC2012_val_00000906.bin 224 224 +35992 ./prep_dataset/ILSVRC2012_val_00020232.bin 224 224 +35993 ./prep_dataset/ILSVRC2012_val_00039257.bin 224 224 +35994 ./prep_dataset/ILSVRC2012_val_00024761.bin 224 224 +35995 ./prep_dataset/ILSVRC2012_val_00017372.bin 224 224 +35996 ./prep_dataset/ILSVRC2012_val_00033216.bin 224 224 +35997 ./prep_dataset/ILSVRC2012_val_00005856.bin 224 224 +35998 ./prep_dataset/ILSVRC2012_val_00014779.bin 224 224 +35999 ./prep_dataset/ILSVRC2012_val_00043137.bin 224 224 +36000 ./prep_dataset/ILSVRC2012_val_00018621.bin 224 224 +36001 ./prep_dataset/ILSVRC2012_val_00021835.bin 224 224 +36002 ./prep_dataset/ILSVRC2012_val_00048113.bin 224 224 +36003 ./prep_dataset/ILSVRC2012_val_00011368.bin 224 224 +36004 ./prep_dataset/ILSVRC2012_val_00040635.bin 224 224 +36005 ./prep_dataset/ILSVRC2012_val_00047942.bin 224 224 +36006 ./prep_dataset/ILSVRC2012_val_00043469.bin 224 224 +36007 ./prep_dataset/ILSVRC2012_val_00048958.bin 224 224 +36008 ./prep_dataset/ILSVRC2012_val_00043703.bin 224 224 +36009 ./prep_dataset/ILSVRC2012_val_00014257.bin 224 224 +36010 ./prep_dataset/ILSVRC2012_val_00031551.bin 224 224 +36011 ./prep_dataset/ILSVRC2012_val_00026702.bin 224 224 +36012 ./prep_dataset/ILSVRC2012_val_00029138.bin 224 224 +36013 ./prep_dataset/ILSVRC2012_val_00011536.bin 224 224 +36014 ./prep_dataset/ILSVRC2012_val_00020935.bin 224 224 +36015 ./prep_dataset/ILSVRC2012_val_00013283.bin 224 224 +36016 ./prep_dataset/ILSVRC2012_val_00018251.bin 224 224 +36017 ./prep_dataset/ILSVRC2012_val_00046317.bin 224 224 +36018 ./prep_dataset/ILSVRC2012_val_00007546.bin 224 224 +36019 ./prep_dataset/ILSVRC2012_val_00017575.bin 224 224 +36020 ./prep_dataset/ILSVRC2012_val_00032050.bin 224 224 +36021 ./prep_dataset/ILSVRC2012_val_00005050.bin 224 224 +36022 ./prep_dataset/ILSVRC2012_val_00017361.bin 224 224 +36023 ./prep_dataset/ILSVRC2012_val_00049974.bin 224 224 +36024 ./prep_dataset/ILSVRC2012_val_00045928.bin 224 224 +36025 ./prep_dataset/ILSVRC2012_val_00021091.bin 224 224 +36026 ./prep_dataset/ILSVRC2012_val_00003034.bin 224 224 +36027 ./prep_dataset/ILSVRC2012_val_00022136.bin 224 224 +36028 ./prep_dataset/ILSVRC2012_val_00010547.bin 224 224 +36029 ./prep_dataset/ILSVRC2012_val_00046168.bin 224 224 +36030 ./prep_dataset/ILSVRC2012_val_00018475.bin 224 224 +36031 ./prep_dataset/ILSVRC2012_val_00025318.bin 224 224 +36032 ./prep_dataset/ILSVRC2012_val_00022512.bin 224 224 +36033 ./prep_dataset/ILSVRC2012_val_00018186.bin 224 224 +36034 ./prep_dataset/ILSVRC2012_val_00043733.bin 224 224 +36035 ./prep_dataset/ILSVRC2012_val_00043068.bin 224 224 +36036 ./prep_dataset/ILSVRC2012_val_00031803.bin 224 224 +36037 ./prep_dataset/ILSVRC2012_val_00044564.bin 224 224 +36038 ./prep_dataset/ILSVRC2012_val_00010033.bin 224 224 +36039 ./prep_dataset/ILSVRC2012_val_00010612.bin 224 224 +36040 ./prep_dataset/ILSVRC2012_val_00013524.bin 224 224 +36041 ./prep_dataset/ILSVRC2012_val_00011748.bin 224 224 +36042 ./prep_dataset/ILSVRC2012_val_00006465.bin 224 224 +36043 ./prep_dataset/ILSVRC2012_val_00002942.bin 224 224 +36044 ./prep_dataset/ILSVRC2012_val_00014798.bin 224 224 +36045 ./prep_dataset/ILSVRC2012_val_00001748.bin 224 224 +36046 ./prep_dataset/ILSVRC2012_val_00039097.bin 224 224 +36047 ./prep_dataset/ILSVRC2012_val_00020968.bin 224 224 +36048 ./prep_dataset/ILSVRC2012_val_00033518.bin 224 224 +36049 ./prep_dataset/ILSVRC2012_val_00006750.bin 224 224 +36050 ./prep_dataset/ILSVRC2012_val_00027422.bin 224 224 +36051 ./prep_dataset/ILSVRC2012_val_00036026.bin 224 224 +36052 ./prep_dataset/ILSVRC2012_val_00040448.bin 224 224 +36053 ./prep_dataset/ILSVRC2012_val_00003500.bin 224 224 +36054 ./prep_dataset/ILSVRC2012_val_00019614.bin 224 224 +36055 ./prep_dataset/ILSVRC2012_val_00017731.bin 224 224 +36056 ./prep_dataset/ILSVRC2012_val_00047054.bin 224 224 +36057 ./prep_dataset/ILSVRC2012_val_00023406.bin 224 224 +36058 ./prep_dataset/ILSVRC2012_val_00041419.bin 224 224 +36059 ./prep_dataset/ILSVRC2012_val_00001134.bin 224 224 +36060 ./prep_dataset/ILSVRC2012_val_00021232.bin 224 224 +36061 ./prep_dataset/ILSVRC2012_val_00045550.bin 224 224 +36062 ./prep_dataset/ILSVRC2012_val_00024957.bin 224 224 +36063 ./prep_dataset/ILSVRC2012_val_00046931.bin 224 224 +36064 ./prep_dataset/ILSVRC2012_val_00007041.bin 224 224 +36065 ./prep_dataset/ILSVRC2012_val_00021005.bin 224 224 +36066 ./prep_dataset/ILSVRC2012_val_00004820.bin 224 224 +36067 ./prep_dataset/ILSVRC2012_val_00046783.bin 224 224 +36068 ./prep_dataset/ILSVRC2012_val_00021128.bin 224 224 +36069 ./prep_dataset/ILSVRC2012_val_00027221.bin 224 224 +36070 ./prep_dataset/ILSVRC2012_val_00027054.bin 224 224 +36071 ./prep_dataset/ILSVRC2012_val_00024662.bin 224 224 +36072 ./prep_dataset/ILSVRC2012_val_00027583.bin 224 224 +36073 ./prep_dataset/ILSVRC2012_val_00010051.bin 224 224 +36074 ./prep_dataset/ILSVRC2012_val_00018600.bin 224 224 +36075 ./prep_dataset/ILSVRC2012_val_00017102.bin 224 224 +36076 ./prep_dataset/ILSVRC2012_val_00021545.bin 224 224 +36077 ./prep_dataset/ILSVRC2012_val_00045107.bin 224 224 +36078 ./prep_dataset/ILSVRC2012_val_00029828.bin 224 224 +36079 ./prep_dataset/ILSVRC2012_val_00005691.bin 224 224 +36080 ./prep_dataset/ILSVRC2012_val_00046352.bin 224 224 +36081 ./prep_dataset/ILSVRC2012_val_00013204.bin 224 224 +36082 ./prep_dataset/ILSVRC2012_val_00003880.bin 224 224 +36083 ./prep_dataset/ILSVRC2012_val_00024933.bin 224 224 +36084 ./prep_dataset/ILSVRC2012_val_00014562.bin 224 224 +36085 ./prep_dataset/ILSVRC2012_val_00024950.bin 224 224 +36086 ./prep_dataset/ILSVRC2012_val_00034021.bin 224 224 +36087 ./prep_dataset/ILSVRC2012_val_00049628.bin 224 224 +36088 ./prep_dataset/ILSVRC2012_val_00049302.bin 224 224 +36089 ./prep_dataset/ILSVRC2012_val_00019099.bin 224 224 +36090 ./prep_dataset/ILSVRC2012_val_00009095.bin 224 224 +36091 ./prep_dataset/ILSVRC2012_val_00011044.bin 224 224 +36092 ./prep_dataset/ILSVRC2012_val_00039734.bin 224 224 +36093 ./prep_dataset/ILSVRC2012_val_00036354.bin 224 224 +36094 ./prep_dataset/ILSVRC2012_val_00013144.bin 224 224 +36095 ./prep_dataset/ILSVRC2012_val_00026301.bin 224 224 +36096 ./prep_dataset/ILSVRC2012_val_00016803.bin 224 224 +36097 ./prep_dataset/ILSVRC2012_val_00030325.bin 224 224 +36098 ./prep_dataset/ILSVRC2012_val_00010472.bin 224 224 +36099 ./prep_dataset/ILSVRC2012_val_00001036.bin 224 224 +36100 ./prep_dataset/ILSVRC2012_val_00046188.bin 224 224 +36101 ./prep_dataset/ILSVRC2012_val_00024976.bin 224 224 +36102 ./prep_dataset/ILSVRC2012_val_00021271.bin 224 224 +36103 ./prep_dataset/ILSVRC2012_val_00033625.bin 224 224 +36104 ./prep_dataset/ILSVRC2012_val_00010235.bin 224 224 +36105 ./prep_dataset/ILSVRC2012_val_00024844.bin 224 224 +36106 ./prep_dataset/ILSVRC2012_val_00043774.bin 224 224 +36107 ./prep_dataset/ILSVRC2012_val_00041281.bin 224 224 +36108 ./prep_dataset/ILSVRC2012_val_00000841.bin 224 224 +36109 ./prep_dataset/ILSVRC2012_val_00013381.bin 224 224 +36110 ./prep_dataset/ILSVRC2012_val_00020085.bin 224 224 +36111 ./prep_dataset/ILSVRC2012_val_00006645.bin 224 224 +36112 ./prep_dataset/ILSVRC2012_val_00026226.bin 224 224 +36113 ./prep_dataset/ILSVRC2012_val_00009858.bin 224 224 +36114 ./prep_dataset/ILSVRC2012_val_00005840.bin 224 224 +36115 ./prep_dataset/ILSVRC2012_val_00007883.bin 224 224 +36116 ./prep_dataset/ILSVRC2012_val_00023973.bin 224 224 +36117 ./prep_dataset/ILSVRC2012_val_00004011.bin 224 224 +36118 ./prep_dataset/ILSVRC2012_val_00012929.bin 224 224 +36119 ./prep_dataset/ILSVRC2012_val_00022785.bin 224 224 +36120 ./prep_dataset/ILSVRC2012_val_00001196.bin 224 224 +36121 ./prep_dataset/ILSVRC2012_val_00038271.bin 224 224 +36122 ./prep_dataset/ILSVRC2012_val_00020401.bin 224 224 +36123 ./prep_dataset/ILSVRC2012_val_00044424.bin 224 224 +36124 ./prep_dataset/ILSVRC2012_val_00024034.bin 224 224 +36125 ./prep_dataset/ILSVRC2012_val_00036866.bin 224 224 +36126 ./prep_dataset/ILSVRC2012_val_00024982.bin 224 224 +36127 ./prep_dataset/ILSVRC2012_val_00040562.bin 224 224 +36128 ./prep_dataset/ILSVRC2012_val_00036381.bin 224 224 +36129 ./prep_dataset/ILSVRC2012_val_00039315.bin 224 224 +36130 ./prep_dataset/ILSVRC2012_val_00000775.bin 224 224 +36131 ./prep_dataset/ILSVRC2012_val_00018901.bin 224 224 +36132 ./prep_dataset/ILSVRC2012_val_00020834.bin 224 224 +36133 ./prep_dataset/ILSVRC2012_val_00021938.bin 224 224 +36134 ./prep_dataset/ILSVRC2012_val_00001113.bin 224 224 +36135 ./prep_dataset/ILSVRC2012_val_00023906.bin 224 224 +36136 ./prep_dataset/ILSVRC2012_val_00029280.bin 224 224 +36137 ./prep_dataset/ILSVRC2012_val_00024045.bin 224 224 +36138 ./prep_dataset/ILSVRC2012_val_00010410.bin 224 224 +36139 ./prep_dataset/ILSVRC2012_val_00044066.bin 224 224 +36140 ./prep_dataset/ILSVRC2012_val_00021177.bin 224 224 +36141 ./prep_dataset/ILSVRC2012_val_00004673.bin 224 224 +36142 ./prep_dataset/ILSVRC2012_val_00000282.bin 224 224 +36143 ./prep_dataset/ILSVRC2012_val_00033377.bin 224 224 +36144 ./prep_dataset/ILSVRC2012_val_00021870.bin 224 224 +36145 ./prep_dataset/ILSVRC2012_val_00019052.bin 224 224 +36146 ./prep_dataset/ILSVRC2012_val_00004130.bin 224 224 +36147 ./prep_dataset/ILSVRC2012_val_00012835.bin 224 224 +36148 ./prep_dataset/ILSVRC2012_val_00031029.bin 224 224 +36149 ./prep_dataset/ILSVRC2012_val_00030040.bin 224 224 +36150 ./prep_dataset/ILSVRC2012_val_00019073.bin 224 224 +36151 ./prep_dataset/ILSVRC2012_val_00041715.bin 224 224 +36152 ./prep_dataset/ILSVRC2012_val_00046014.bin 224 224 +36153 ./prep_dataset/ILSVRC2012_val_00013225.bin 224 224 +36154 ./prep_dataset/ILSVRC2012_val_00035778.bin 224 224 +36155 ./prep_dataset/ILSVRC2012_val_00026430.bin 224 224 +36156 ./prep_dataset/ILSVRC2012_val_00029940.bin 224 224 +36157 ./prep_dataset/ILSVRC2012_val_00001887.bin 224 224 +36158 ./prep_dataset/ILSVRC2012_val_00027751.bin 224 224 +36159 ./prep_dataset/ILSVRC2012_val_00026292.bin 224 224 +36160 ./prep_dataset/ILSVRC2012_val_00018015.bin 224 224 +36161 ./prep_dataset/ILSVRC2012_val_00017409.bin 224 224 +36162 ./prep_dataset/ILSVRC2012_val_00027309.bin 224 224 +36163 ./prep_dataset/ILSVRC2012_val_00030923.bin 224 224 +36164 ./prep_dataset/ILSVRC2012_val_00030136.bin 224 224 +36165 ./prep_dataset/ILSVRC2012_val_00027644.bin 224 224 +36166 ./prep_dataset/ILSVRC2012_val_00049040.bin 224 224 +36167 ./prep_dataset/ILSVRC2012_val_00023644.bin 224 224 +36168 ./prep_dataset/ILSVRC2012_val_00001198.bin 224 224 +36169 ./prep_dataset/ILSVRC2012_val_00005962.bin 224 224 +36170 ./prep_dataset/ILSVRC2012_val_00030299.bin 224 224 +36171 ./prep_dataset/ILSVRC2012_val_00036991.bin 224 224 +36172 ./prep_dataset/ILSVRC2012_val_00000582.bin 224 224 +36173 ./prep_dataset/ILSVRC2012_val_00039693.bin 224 224 +36174 ./prep_dataset/ILSVRC2012_val_00032446.bin 224 224 +36175 ./prep_dataset/ILSVRC2012_val_00026427.bin 224 224 +36176 ./prep_dataset/ILSVRC2012_val_00017529.bin 224 224 +36177 ./prep_dataset/ILSVRC2012_val_00034440.bin 224 224 +36178 ./prep_dataset/ILSVRC2012_val_00011702.bin 224 224 +36179 ./prep_dataset/ILSVRC2012_val_00006090.bin 224 224 +36180 ./prep_dataset/ILSVRC2012_val_00045024.bin 224 224 +36181 ./prep_dataset/ILSVRC2012_val_00037713.bin 224 224 +36182 ./prep_dataset/ILSVRC2012_val_00016826.bin 224 224 +36183 ./prep_dataset/ILSVRC2012_val_00041844.bin 224 224 +36184 ./prep_dataset/ILSVRC2012_val_00026729.bin 224 224 +36185 ./prep_dataset/ILSVRC2012_val_00029712.bin 224 224 +36186 ./prep_dataset/ILSVRC2012_val_00006322.bin 224 224 +36187 ./prep_dataset/ILSVRC2012_val_00023933.bin 224 224 +36188 ./prep_dataset/ILSVRC2012_val_00045118.bin 224 224 +36189 ./prep_dataset/ILSVRC2012_val_00020039.bin 224 224 +36190 ./prep_dataset/ILSVRC2012_val_00043333.bin 224 224 +36191 ./prep_dataset/ILSVRC2012_val_00011106.bin 224 224 +36192 ./prep_dataset/ILSVRC2012_val_00036488.bin 224 224 +36193 ./prep_dataset/ILSVRC2012_val_00015654.bin 224 224 +36194 ./prep_dataset/ILSVRC2012_val_00001088.bin 224 224 +36195 ./prep_dataset/ILSVRC2012_val_00020145.bin 224 224 +36196 ./prep_dataset/ILSVRC2012_val_00036759.bin 224 224 +36197 ./prep_dataset/ILSVRC2012_val_00006390.bin 224 224 +36198 ./prep_dataset/ILSVRC2012_val_00020314.bin 224 224 +36199 ./prep_dataset/ILSVRC2012_val_00036604.bin 224 224 +36200 ./prep_dataset/ILSVRC2012_val_00047695.bin 224 224 +36201 ./prep_dataset/ILSVRC2012_val_00013114.bin 224 224 +36202 ./prep_dataset/ILSVRC2012_val_00034030.bin 224 224 +36203 ./prep_dataset/ILSVRC2012_val_00036040.bin 224 224 +36204 ./prep_dataset/ILSVRC2012_val_00001836.bin 224 224 +36205 ./prep_dataset/ILSVRC2012_val_00002086.bin 224 224 +36206 ./prep_dataset/ILSVRC2012_val_00044168.bin 224 224 +36207 ./prep_dataset/ILSVRC2012_val_00007058.bin 224 224 +36208 ./prep_dataset/ILSVRC2012_val_00016116.bin 224 224 +36209 ./prep_dataset/ILSVRC2012_val_00028982.bin 224 224 +36210 ./prep_dataset/ILSVRC2012_val_00042313.bin 224 224 +36211 ./prep_dataset/ILSVRC2012_val_00049499.bin 224 224 +36212 ./prep_dataset/ILSVRC2012_val_00001334.bin 224 224 +36213 ./prep_dataset/ILSVRC2012_val_00034340.bin 224 224 +36214 ./prep_dataset/ILSVRC2012_val_00007470.bin 224 224 +36215 ./prep_dataset/ILSVRC2012_val_00022667.bin 224 224 +36216 ./prep_dataset/ILSVRC2012_val_00033173.bin 224 224 +36217 ./prep_dataset/ILSVRC2012_val_00012124.bin 224 224 +36218 ./prep_dataset/ILSVRC2012_val_00015271.bin 224 224 +36219 ./prep_dataset/ILSVRC2012_val_00003239.bin 224 224 +36220 ./prep_dataset/ILSVRC2012_val_00002884.bin 224 224 +36221 ./prep_dataset/ILSVRC2012_val_00046285.bin 224 224 +36222 ./prep_dataset/ILSVRC2012_val_00004525.bin 224 224 +36223 ./prep_dataset/ILSVRC2012_val_00013055.bin 224 224 +36224 ./prep_dataset/ILSVRC2012_val_00013468.bin 224 224 +36225 ./prep_dataset/ILSVRC2012_val_00034572.bin 224 224 +36226 ./prep_dataset/ILSVRC2012_val_00020573.bin 224 224 +36227 ./prep_dataset/ILSVRC2012_val_00023769.bin 224 224 +36228 ./prep_dataset/ILSVRC2012_val_00007511.bin 224 224 +36229 ./prep_dataset/ILSVRC2012_val_00039196.bin 224 224 +36230 ./prep_dataset/ILSVRC2012_val_00020348.bin 224 224 +36231 ./prep_dataset/ILSVRC2012_val_00011353.bin 224 224 +36232 ./prep_dataset/ILSVRC2012_val_00023157.bin 224 224 +36233 ./prep_dataset/ILSVRC2012_val_00007332.bin 224 224 +36234 ./prep_dataset/ILSVRC2012_val_00025829.bin 224 224 +36235 ./prep_dataset/ILSVRC2012_val_00019138.bin 224 224 +36236 ./prep_dataset/ILSVRC2012_val_00037651.bin 224 224 +36237 ./prep_dataset/ILSVRC2012_val_00007350.bin 224 224 +36238 ./prep_dataset/ILSVRC2012_val_00029912.bin 224 224 +36239 ./prep_dataset/ILSVRC2012_val_00022635.bin 224 224 +36240 ./prep_dataset/ILSVRC2012_val_00042714.bin 224 224 +36241 ./prep_dataset/ILSVRC2012_val_00005847.bin 224 224 +36242 ./prep_dataset/ILSVRC2012_val_00006599.bin 224 224 +36243 ./prep_dataset/ILSVRC2012_val_00015453.bin 224 224 +36244 ./prep_dataset/ILSVRC2012_val_00010047.bin 224 224 +36245 ./prep_dataset/ILSVRC2012_val_00026772.bin 224 224 +36246 ./prep_dataset/ILSVRC2012_val_00037733.bin 224 224 +36247 ./prep_dataset/ILSVRC2012_val_00012823.bin 224 224 +36248 ./prep_dataset/ILSVRC2012_val_00020476.bin 224 224 +36249 ./prep_dataset/ILSVRC2012_val_00017368.bin 224 224 +36250 ./prep_dataset/ILSVRC2012_val_00030637.bin 224 224 +36251 ./prep_dataset/ILSVRC2012_val_00032058.bin 224 224 +36252 ./prep_dataset/ILSVRC2012_val_00011263.bin 224 224 +36253 ./prep_dataset/ILSVRC2012_val_00021384.bin 224 224 +36254 ./prep_dataset/ILSVRC2012_val_00009533.bin 224 224 +36255 ./prep_dataset/ILSVRC2012_val_00018289.bin 224 224 +36256 ./prep_dataset/ILSVRC2012_val_00041682.bin 224 224 +36257 ./prep_dataset/ILSVRC2012_val_00044644.bin 224 224 +36258 ./prep_dataset/ILSVRC2012_val_00014420.bin 224 224 +36259 ./prep_dataset/ILSVRC2012_val_00015870.bin 224 224 +36260 ./prep_dataset/ILSVRC2012_val_00003049.bin 224 224 +36261 ./prep_dataset/ILSVRC2012_val_00032236.bin 224 224 +36262 ./prep_dataset/ILSVRC2012_val_00025439.bin 224 224 +36263 ./prep_dataset/ILSVRC2012_val_00041664.bin 224 224 +36264 ./prep_dataset/ILSVRC2012_val_00004678.bin 224 224 +36265 ./prep_dataset/ILSVRC2012_val_00007565.bin 224 224 +36266 ./prep_dataset/ILSVRC2012_val_00003699.bin 224 224 +36267 ./prep_dataset/ILSVRC2012_val_00016870.bin 224 224 +36268 ./prep_dataset/ILSVRC2012_val_00004379.bin 224 224 +36269 ./prep_dataset/ILSVRC2012_val_00032088.bin 224 224 +36270 ./prep_dataset/ILSVRC2012_val_00039127.bin 224 224 +36271 ./prep_dataset/ILSVRC2012_val_00017404.bin 224 224 +36272 ./prep_dataset/ILSVRC2012_val_00021819.bin 224 224 +36273 ./prep_dataset/ILSVRC2012_val_00026286.bin 224 224 +36274 ./prep_dataset/ILSVRC2012_val_00022960.bin 224 224 +36275 ./prep_dataset/ILSVRC2012_val_00040687.bin 224 224 +36276 ./prep_dataset/ILSVRC2012_val_00047195.bin 224 224 +36277 ./prep_dataset/ILSVRC2012_val_00024186.bin 224 224 +36278 ./prep_dataset/ILSVRC2012_val_00031337.bin 224 224 +36279 ./prep_dataset/ILSVRC2012_val_00036873.bin 224 224 +36280 ./prep_dataset/ILSVRC2012_val_00025766.bin 224 224 +36281 ./prep_dataset/ILSVRC2012_val_00032608.bin 224 224 +36282 ./prep_dataset/ILSVRC2012_val_00036722.bin 224 224 +36283 ./prep_dataset/ILSVRC2012_val_00010758.bin 224 224 +36284 ./prep_dataset/ILSVRC2012_val_00047975.bin 224 224 +36285 ./prep_dataset/ILSVRC2012_val_00038174.bin 224 224 +36286 ./prep_dataset/ILSVRC2012_val_00001407.bin 224 224 +36287 ./prep_dataset/ILSVRC2012_val_00031554.bin 224 224 +36288 ./prep_dataset/ILSVRC2012_val_00007746.bin 224 224 +36289 ./prep_dataset/ILSVRC2012_val_00011392.bin 224 224 +36290 ./prep_dataset/ILSVRC2012_val_00028810.bin 224 224 +36291 ./prep_dataset/ILSVRC2012_val_00021158.bin 224 224 +36292 ./prep_dataset/ILSVRC2012_val_00039529.bin 224 224 +36293 ./prep_dataset/ILSVRC2012_val_00043086.bin 224 224 +36294 ./prep_dataset/ILSVRC2012_val_00043267.bin 224 224 +36295 ./prep_dataset/ILSVRC2012_val_00008027.bin 224 224 +36296 ./prep_dataset/ILSVRC2012_val_00012766.bin 224 224 +36297 ./prep_dataset/ILSVRC2012_val_00040870.bin 224 224 +36298 ./prep_dataset/ILSVRC2012_val_00027508.bin 224 224 +36299 ./prep_dataset/ILSVRC2012_val_00000280.bin 224 224 +36300 ./prep_dataset/ILSVRC2012_val_00027699.bin 224 224 +36301 ./prep_dataset/ILSVRC2012_val_00006644.bin 224 224 +36302 ./prep_dataset/ILSVRC2012_val_00034379.bin 224 224 +36303 ./prep_dataset/ILSVRC2012_val_00015349.bin 224 224 +36304 ./prep_dataset/ILSVRC2012_val_00042673.bin 224 224 +36305 ./prep_dataset/ILSVRC2012_val_00038084.bin 224 224 +36306 ./prep_dataset/ILSVRC2012_val_00027850.bin 224 224 +36307 ./prep_dataset/ILSVRC2012_val_00044660.bin 224 224 +36308 ./prep_dataset/ILSVRC2012_val_00016596.bin 224 224 +36309 ./prep_dataset/ILSVRC2012_val_00042704.bin 224 224 +36310 ./prep_dataset/ILSVRC2012_val_00036897.bin 224 224 +36311 ./prep_dataset/ILSVRC2012_val_00023660.bin 224 224 +36312 ./prep_dataset/ILSVRC2012_val_00003783.bin 224 224 +36313 ./prep_dataset/ILSVRC2012_val_00030638.bin 224 224 +36314 ./prep_dataset/ILSVRC2012_val_00004640.bin 224 224 +36315 ./prep_dataset/ILSVRC2012_val_00040914.bin 224 224 +36316 ./prep_dataset/ILSVRC2012_val_00033225.bin 224 224 +36317 ./prep_dataset/ILSVRC2012_val_00036690.bin 224 224 +36318 ./prep_dataset/ILSVRC2012_val_00033530.bin 224 224 +36319 ./prep_dataset/ILSVRC2012_val_00047236.bin 224 224 +36320 ./prep_dataset/ILSVRC2012_val_00043863.bin 224 224 +36321 ./prep_dataset/ILSVRC2012_val_00049863.bin 224 224 +36322 ./prep_dataset/ILSVRC2012_val_00045425.bin 224 224 +36323 ./prep_dataset/ILSVRC2012_val_00035314.bin 224 224 +36324 ./prep_dataset/ILSVRC2012_val_00004185.bin 224 224 +36325 ./prep_dataset/ILSVRC2012_val_00041366.bin 224 224 +36326 ./prep_dataset/ILSVRC2012_val_00009850.bin 224 224 +36327 ./prep_dataset/ILSVRC2012_val_00027636.bin 224 224 +36328 ./prep_dataset/ILSVRC2012_val_00047336.bin 224 224 +36329 ./prep_dataset/ILSVRC2012_val_00041376.bin 224 224 +36330 ./prep_dataset/ILSVRC2012_val_00023754.bin 224 224 +36331 ./prep_dataset/ILSVRC2012_val_00031718.bin 224 224 +36332 ./prep_dataset/ILSVRC2012_val_00033591.bin 224 224 +36333 ./prep_dataset/ILSVRC2012_val_00019313.bin 224 224 +36334 ./prep_dataset/ILSVRC2012_val_00010409.bin 224 224 +36335 ./prep_dataset/ILSVRC2012_val_00034815.bin 224 224 +36336 ./prep_dataset/ILSVRC2012_val_00028341.bin 224 224 +36337 ./prep_dataset/ILSVRC2012_val_00010709.bin 224 224 +36338 ./prep_dataset/ILSVRC2012_val_00030647.bin 224 224 +36339 ./prep_dataset/ILSVRC2012_val_00043159.bin 224 224 +36340 ./prep_dataset/ILSVRC2012_val_00019239.bin 224 224 +36341 ./prep_dataset/ILSVRC2012_val_00030718.bin 224 224 +36342 ./prep_dataset/ILSVRC2012_val_00002533.bin 224 224 +36343 ./prep_dataset/ILSVRC2012_val_00009907.bin 224 224 +36344 ./prep_dataset/ILSVRC2012_val_00039602.bin 224 224 +36345 ./prep_dataset/ILSVRC2012_val_00020436.bin 224 224 +36346 ./prep_dataset/ILSVRC2012_val_00034825.bin 224 224 +36347 ./prep_dataset/ILSVRC2012_val_00011472.bin 224 224 +36348 ./prep_dataset/ILSVRC2012_val_00033228.bin 224 224 +36349 ./prep_dataset/ILSVRC2012_val_00004119.bin 224 224 +36350 ./prep_dataset/ILSVRC2012_val_00037059.bin 224 224 +36351 ./prep_dataset/ILSVRC2012_val_00033610.bin 224 224 +36352 ./prep_dataset/ILSVRC2012_val_00034380.bin 224 224 +36353 ./prep_dataset/ILSVRC2012_val_00003760.bin 224 224 +36354 ./prep_dataset/ILSVRC2012_val_00033526.bin 224 224 +36355 ./prep_dataset/ILSVRC2012_val_00013646.bin 224 224 +36356 ./prep_dataset/ILSVRC2012_val_00001999.bin 224 224 +36357 ./prep_dataset/ILSVRC2012_val_00024647.bin 224 224 +36358 ./prep_dataset/ILSVRC2012_val_00024106.bin 224 224 +36359 ./prep_dataset/ILSVRC2012_val_00043841.bin 224 224 +36360 ./prep_dataset/ILSVRC2012_val_00038965.bin 224 224 +36361 ./prep_dataset/ILSVRC2012_val_00011928.bin 224 224 +36362 ./prep_dataset/ILSVRC2012_val_00000220.bin 224 224 +36363 ./prep_dataset/ILSVRC2012_val_00016899.bin 224 224 +36364 ./prep_dataset/ILSVRC2012_val_00045971.bin 224 224 +36365 ./prep_dataset/ILSVRC2012_val_00041341.bin 224 224 +36366 ./prep_dataset/ILSVRC2012_val_00037507.bin 224 224 +36367 ./prep_dataset/ILSVRC2012_val_00047259.bin 224 224 +36368 ./prep_dataset/ILSVRC2012_val_00001404.bin 224 224 +36369 ./prep_dataset/ILSVRC2012_val_00018854.bin 224 224 +36370 ./prep_dataset/ILSVRC2012_val_00048955.bin 224 224 +36371 ./prep_dataset/ILSVRC2012_val_00038020.bin 224 224 +36372 ./prep_dataset/ILSVRC2012_val_00009113.bin 224 224 +36373 ./prep_dataset/ILSVRC2012_val_00008813.bin 224 224 +36374 ./prep_dataset/ILSVRC2012_val_00034017.bin 224 224 +36375 ./prep_dataset/ILSVRC2012_val_00019223.bin 224 224 +36376 ./prep_dataset/ILSVRC2012_val_00035528.bin 224 224 +36377 ./prep_dataset/ILSVRC2012_val_00047246.bin 224 224 +36378 ./prep_dataset/ILSVRC2012_val_00013250.bin 224 224 +36379 ./prep_dataset/ILSVRC2012_val_00048324.bin 224 224 +36380 ./prep_dataset/ILSVRC2012_val_00012781.bin 224 224 +36381 ./prep_dataset/ILSVRC2012_val_00002460.bin 224 224 +36382 ./prep_dataset/ILSVRC2012_val_00045676.bin 224 224 +36383 ./prep_dataset/ILSVRC2012_val_00045783.bin 224 224 +36384 ./prep_dataset/ILSVRC2012_val_00019859.bin 224 224 +36385 ./prep_dataset/ILSVRC2012_val_00005338.bin 224 224 +36386 ./prep_dataset/ILSVRC2012_val_00022492.bin 224 224 +36387 ./prep_dataset/ILSVRC2012_val_00045355.bin 224 224 +36388 ./prep_dataset/ILSVRC2012_val_00008970.bin 224 224 +36389 ./prep_dataset/ILSVRC2012_val_00007129.bin 224 224 +36390 ./prep_dataset/ILSVRC2012_val_00035431.bin 224 224 +36391 ./prep_dataset/ILSVRC2012_val_00047602.bin 224 224 +36392 ./prep_dataset/ILSVRC2012_val_00015483.bin 224 224 +36393 ./prep_dataset/ILSVRC2012_val_00007012.bin 224 224 +36394 ./prep_dataset/ILSVRC2012_val_00001506.bin 224 224 +36395 ./prep_dataset/ILSVRC2012_val_00041465.bin 224 224 +36396 ./prep_dataset/ILSVRC2012_val_00027542.bin 224 224 +36397 ./prep_dataset/ILSVRC2012_val_00032587.bin 224 224 +36398 ./prep_dataset/ILSVRC2012_val_00046502.bin 224 224 +36399 ./prep_dataset/ILSVRC2012_val_00002670.bin 224 224 +36400 ./prep_dataset/ILSVRC2012_val_00022569.bin 224 224 +36401 ./prep_dataset/ILSVRC2012_val_00043461.bin 224 224 +36402 ./prep_dataset/ILSVRC2012_val_00020256.bin 224 224 +36403 ./prep_dataset/ILSVRC2012_val_00011359.bin 224 224 +36404 ./prep_dataset/ILSVRC2012_val_00035500.bin 224 224 +36405 ./prep_dataset/ILSVRC2012_val_00044351.bin 224 224 +36406 ./prep_dataset/ILSVRC2012_val_00019095.bin 224 224 +36407 ./prep_dataset/ILSVRC2012_val_00046860.bin 224 224 +36408 ./prep_dataset/ILSVRC2012_val_00013527.bin 224 224 +36409 ./prep_dataset/ILSVRC2012_val_00028287.bin 224 224 +36410 ./prep_dataset/ILSVRC2012_val_00030700.bin 224 224 +36411 ./prep_dataset/ILSVRC2012_val_00032702.bin 224 224 +36412 ./prep_dataset/ILSVRC2012_val_00014056.bin 224 224 +36413 ./prep_dataset/ILSVRC2012_val_00007112.bin 224 224 +36414 ./prep_dataset/ILSVRC2012_val_00012024.bin 224 224 +36415 ./prep_dataset/ILSVRC2012_val_00035814.bin 224 224 +36416 ./prep_dataset/ILSVRC2012_val_00040919.bin 224 224 +36417 ./prep_dataset/ILSVRC2012_val_00016213.bin 224 224 +36418 ./prep_dataset/ILSVRC2012_val_00029429.bin 224 224 +36419 ./prep_dataset/ILSVRC2012_val_00017687.bin 224 224 +36420 ./prep_dataset/ILSVRC2012_val_00042942.bin 224 224 +36421 ./prep_dataset/ILSVRC2012_val_00002957.bin 224 224 +36422 ./prep_dataset/ILSVRC2012_val_00046198.bin 224 224 +36423 ./prep_dataset/ILSVRC2012_val_00004406.bin 224 224 +36424 ./prep_dataset/ILSVRC2012_val_00028158.bin 224 224 +36425 ./prep_dataset/ILSVRC2012_val_00040935.bin 224 224 +36426 ./prep_dataset/ILSVRC2012_val_00045218.bin 224 224 +36427 ./prep_dataset/ILSVRC2012_val_00049000.bin 224 224 +36428 ./prep_dataset/ILSVRC2012_val_00029224.bin 224 224 +36429 ./prep_dataset/ILSVRC2012_val_00003881.bin 224 224 +36430 ./prep_dataset/ILSVRC2012_val_00028803.bin 224 224 +36431 ./prep_dataset/ILSVRC2012_val_00049516.bin 224 224 +36432 ./prep_dataset/ILSVRC2012_val_00010648.bin 224 224 +36433 ./prep_dataset/ILSVRC2012_val_00025711.bin 224 224 +36434 ./prep_dataset/ILSVRC2012_val_00001947.bin 224 224 +36435 ./prep_dataset/ILSVRC2012_val_00015213.bin 224 224 +36436 ./prep_dataset/ILSVRC2012_val_00044682.bin 224 224 +36437 ./prep_dataset/ILSVRC2012_val_00031265.bin 224 224 +36438 ./prep_dataset/ILSVRC2012_val_00042773.bin 224 224 +36439 ./prep_dataset/ILSVRC2012_val_00005207.bin 224 224 +36440 ./prep_dataset/ILSVRC2012_val_00041197.bin 224 224 +36441 ./prep_dataset/ILSVRC2012_val_00007493.bin 224 224 +36442 ./prep_dataset/ILSVRC2012_val_00003901.bin 224 224 +36443 ./prep_dataset/ILSVRC2012_val_00015568.bin 224 224 +36444 ./prep_dataset/ILSVRC2012_val_00030029.bin 224 224 +36445 ./prep_dataset/ILSVRC2012_val_00024251.bin 224 224 +36446 ./prep_dataset/ILSVRC2012_val_00033522.bin 224 224 +36447 ./prep_dataset/ILSVRC2012_val_00017919.bin 224 224 +36448 ./prep_dataset/ILSVRC2012_val_00032746.bin 224 224 +36449 ./prep_dataset/ILSVRC2012_val_00043809.bin 224 224 +36450 ./prep_dataset/ILSVRC2012_val_00036509.bin 224 224 +36451 ./prep_dataset/ILSVRC2012_val_00046840.bin 224 224 +36452 ./prep_dataset/ILSVRC2012_val_00041083.bin 224 224 +36453 ./prep_dataset/ILSVRC2012_val_00003603.bin 224 224 +36454 ./prep_dataset/ILSVRC2012_val_00006024.bin 224 224 +36455 ./prep_dataset/ILSVRC2012_val_00036848.bin 224 224 +36456 ./prep_dataset/ILSVRC2012_val_00001970.bin 224 224 +36457 ./prep_dataset/ILSVRC2012_val_00003177.bin 224 224 +36458 ./prep_dataset/ILSVRC2012_val_00045923.bin 224 224 +36459 ./prep_dataset/ILSVRC2012_val_00016444.bin 224 224 +36460 ./prep_dataset/ILSVRC2012_val_00047607.bin 224 224 +36461 ./prep_dataset/ILSVRC2012_val_00036913.bin 224 224 +36462 ./prep_dataset/ILSVRC2012_val_00008129.bin 224 224 +36463 ./prep_dataset/ILSVRC2012_val_00043145.bin 224 224 +36464 ./prep_dataset/ILSVRC2012_val_00006593.bin 224 224 +36465 ./prep_dataset/ILSVRC2012_val_00043244.bin 224 224 +36466 ./prep_dataset/ILSVRC2012_val_00012202.bin 224 224 +36467 ./prep_dataset/ILSVRC2012_val_00002038.bin 224 224 +36468 ./prep_dataset/ILSVRC2012_val_00038533.bin 224 224 +36469 ./prep_dataset/ILSVRC2012_val_00040938.bin 224 224 +36470 ./prep_dataset/ILSVRC2012_val_00006006.bin 224 224 +36471 ./prep_dataset/ILSVRC2012_val_00001392.bin 224 224 +36472 ./prep_dataset/ILSVRC2012_val_00000451.bin 224 224 +36473 ./prep_dataset/ILSVRC2012_val_00047434.bin 224 224 +36474 ./prep_dataset/ILSVRC2012_val_00017885.bin 224 224 +36475 ./prep_dataset/ILSVRC2012_val_00017271.bin 224 224 +36476 ./prep_dataset/ILSVRC2012_val_00045744.bin 224 224 +36477 ./prep_dataset/ILSVRC2012_val_00032884.bin 224 224 +36478 ./prep_dataset/ILSVRC2012_val_00010587.bin 224 224 +36479 ./prep_dataset/ILSVRC2012_val_00043150.bin 224 224 +36480 ./prep_dataset/ILSVRC2012_val_00042033.bin 224 224 +36481 ./prep_dataset/ILSVRC2012_val_00009633.bin 224 224 +36482 ./prep_dataset/ILSVRC2012_val_00022254.bin 224 224 +36483 ./prep_dataset/ILSVRC2012_val_00047330.bin 224 224 +36484 ./prep_dataset/ILSVRC2012_val_00006799.bin 224 224 +36485 ./prep_dataset/ILSVRC2012_val_00043509.bin 224 224 +36486 ./prep_dataset/ILSVRC2012_val_00010275.bin 224 224 +36487 ./prep_dataset/ILSVRC2012_val_00046483.bin 224 224 +36488 ./prep_dataset/ILSVRC2012_val_00015897.bin 224 224 +36489 ./prep_dataset/ILSVRC2012_val_00004581.bin 224 224 +36490 ./prep_dataset/ILSVRC2012_val_00027684.bin 224 224 +36491 ./prep_dataset/ILSVRC2012_val_00047557.bin 224 224 +36492 ./prep_dataset/ILSVRC2012_val_00001244.bin 224 224 +36493 ./prep_dataset/ILSVRC2012_val_00021828.bin 224 224 +36494 ./prep_dataset/ILSVRC2012_val_00031121.bin 224 224 +36495 ./prep_dataset/ILSVRC2012_val_00030316.bin 224 224 +36496 ./prep_dataset/ILSVRC2012_val_00039942.bin 224 224 +36497 ./prep_dataset/ILSVRC2012_val_00023314.bin 224 224 +36498 ./prep_dataset/ILSVRC2012_val_00023279.bin 224 224 +36499 ./prep_dataset/ILSVRC2012_val_00048952.bin 224 224 +36500 ./prep_dataset/ILSVRC2012_val_00042719.bin 224 224 +36501 ./prep_dataset/ILSVRC2012_val_00017179.bin 224 224 +36502 ./prep_dataset/ILSVRC2012_val_00012406.bin 224 224 +36503 ./prep_dataset/ILSVRC2012_val_00029225.bin 224 224 +36504 ./prep_dataset/ILSVRC2012_val_00002327.bin 224 224 +36505 ./prep_dataset/ILSVRC2012_val_00033840.bin 224 224 +36506 ./prep_dataset/ILSVRC2012_val_00013531.bin 224 224 +36507 ./prep_dataset/ILSVRC2012_val_00032229.bin 224 224 +36508 ./prep_dataset/ILSVRC2012_val_00018940.bin 224 224 +36509 ./prep_dataset/ILSVRC2012_val_00047036.bin 224 224 +36510 ./prep_dataset/ILSVRC2012_val_00035660.bin 224 224 +36511 ./prep_dataset/ILSVRC2012_val_00025908.bin 224 224 +36512 ./prep_dataset/ILSVRC2012_val_00036783.bin 224 224 +36513 ./prep_dataset/ILSVRC2012_val_00031279.bin 224 224 +36514 ./prep_dataset/ILSVRC2012_val_00005444.bin 224 224 +36515 ./prep_dataset/ILSVRC2012_val_00029119.bin 224 224 +36516 ./prep_dataset/ILSVRC2012_val_00007437.bin 224 224 +36517 ./prep_dataset/ILSVRC2012_val_00006646.bin 224 224 +36518 ./prep_dataset/ILSVRC2012_val_00001485.bin 224 224 +36519 ./prep_dataset/ILSVRC2012_val_00031709.bin 224 224 +36520 ./prep_dataset/ILSVRC2012_val_00023383.bin 224 224 +36521 ./prep_dataset/ILSVRC2012_val_00046826.bin 224 224 +36522 ./prep_dataset/ILSVRC2012_val_00020194.bin 224 224 +36523 ./prep_dataset/ILSVRC2012_val_00028025.bin 224 224 +36524 ./prep_dataset/ILSVRC2012_val_00010002.bin 224 224 +36525 ./prep_dataset/ILSVRC2012_val_00008449.bin 224 224 +36526 ./prep_dataset/ILSVRC2012_val_00004120.bin 224 224 +36527 ./prep_dataset/ILSVRC2012_val_00040062.bin 224 224 +36528 ./prep_dataset/ILSVRC2012_val_00025057.bin 224 224 +36529 ./prep_dataset/ILSVRC2012_val_00022003.bin 224 224 +36530 ./prep_dataset/ILSVRC2012_val_00032726.bin 224 224 +36531 ./prep_dataset/ILSVRC2012_val_00017069.bin 224 224 +36532 ./prep_dataset/ILSVRC2012_val_00018555.bin 224 224 +36533 ./prep_dataset/ILSVRC2012_val_00030502.bin 224 224 +36534 ./prep_dataset/ILSVRC2012_val_00010519.bin 224 224 +36535 ./prep_dataset/ILSVRC2012_val_00038244.bin 224 224 +36536 ./prep_dataset/ILSVRC2012_val_00044984.bin 224 224 +36537 ./prep_dataset/ILSVRC2012_val_00044150.bin 224 224 +36538 ./prep_dataset/ILSVRC2012_val_00012455.bin 224 224 +36539 ./prep_dataset/ILSVRC2012_val_00000993.bin 224 224 +36540 ./prep_dataset/ILSVRC2012_val_00012174.bin 224 224 +36541 ./prep_dataset/ILSVRC2012_val_00005637.bin 224 224 +36542 ./prep_dataset/ILSVRC2012_val_00003162.bin 224 224 +36543 ./prep_dataset/ILSVRC2012_val_00012062.bin 224 224 +36544 ./prep_dataset/ILSVRC2012_val_00009867.bin 224 224 +36545 ./prep_dataset/ILSVRC2012_val_00048488.bin 224 224 +36546 ./prep_dataset/ILSVRC2012_val_00004523.bin 224 224 +36547 ./prep_dataset/ILSVRC2012_val_00000131.bin 224 224 +36548 ./prep_dataset/ILSVRC2012_val_00044645.bin 224 224 +36549 ./prep_dataset/ILSVRC2012_val_00045306.bin 224 224 +36550 ./prep_dataset/ILSVRC2012_val_00033337.bin 224 224 +36551 ./prep_dataset/ILSVRC2012_val_00026084.bin 224 224 +36552 ./prep_dataset/ILSVRC2012_val_00006511.bin 224 224 +36553 ./prep_dataset/ILSVRC2012_val_00010445.bin 224 224 +36554 ./prep_dataset/ILSVRC2012_val_00046284.bin 224 224 +36555 ./prep_dataset/ILSVRC2012_val_00016320.bin 224 224 +36556 ./prep_dataset/ILSVRC2012_val_00021342.bin 224 224 +36557 ./prep_dataset/ILSVRC2012_val_00013226.bin 224 224 +36558 ./prep_dataset/ILSVRC2012_val_00040126.bin 224 224 +36559 ./prep_dataset/ILSVRC2012_val_00004258.bin 224 224 +36560 ./prep_dataset/ILSVRC2012_val_00023861.bin 224 224 +36561 ./prep_dataset/ILSVRC2012_val_00040001.bin 224 224 +36562 ./prep_dataset/ILSVRC2012_val_00033967.bin 224 224 +36563 ./prep_dataset/ILSVRC2012_val_00006470.bin 224 224 +36564 ./prep_dataset/ILSVRC2012_val_00023831.bin 224 224 +36565 ./prep_dataset/ILSVRC2012_val_00003544.bin 224 224 +36566 ./prep_dataset/ILSVRC2012_val_00041891.bin 224 224 +36567 ./prep_dataset/ILSVRC2012_val_00030692.bin 224 224 +36568 ./prep_dataset/ILSVRC2012_val_00041091.bin 224 224 +36569 ./prep_dataset/ILSVRC2012_val_00043457.bin 224 224 +36570 ./prep_dataset/ILSVRC2012_val_00036950.bin 224 224 +36571 ./prep_dataset/ILSVRC2012_val_00011541.bin 224 224 +36572 ./prep_dataset/ILSVRC2012_val_00003841.bin 224 224 +36573 ./prep_dataset/ILSVRC2012_val_00041950.bin 224 224 +36574 ./prep_dataset/ILSVRC2012_val_00024874.bin 224 224 +36575 ./prep_dataset/ILSVRC2012_val_00001585.bin 224 224 +36576 ./prep_dataset/ILSVRC2012_val_00046545.bin 224 224 +36577 ./prep_dataset/ILSVRC2012_val_00013145.bin 224 224 +36578 ./prep_dataset/ILSVRC2012_val_00002014.bin 224 224 +36579 ./prep_dataset/ILSVRC2012_val_00001217.bin 224 224 +36580 ./prep_dataset/ILSVRC2012_val_00032386.bin 224 224 +36581 ./prep_dataset/ILSVRC2012_val_00008753.bin 224 224 +36582 ./prep_dataset/ILSVRC2012_val_00027026.bin 224 224 +36583 ./prep_dataset/ILSVRC2012_val_00032932.bin 224 224 +36584 ./prep_dataset/ILSVRC2012_val_00043817.bin 224 224 +36585 ./prep_dataset/ILSVRC2012_val_00017645.bin 224 224 +36586 ./prep_dataset/ILSVRC2012_val_00019612.bin 224 224 +36587 ./prep_dataset/ILSVRC2012_val_00034087.bin 224 224 +36588 ./prep_dataset/ILSVRC2012_val_00030204.bin 224 224 +36589 ./prep_dataset/ILSVRC2012_val_00022015.bin 224 224 +36590 ./prep_dataset/ILSVRC2012_val_00012534.bin 224 224 +36591 ./prep_dataset/ILSVRC2012_val_00015488.bin 224 224 +36592 ./prep_dataset/ILSVRC2012_val_00003296.bin 224 224 +36593 ./prep_dataset/ILSVRC2012_val_00037177.bin 224 224 +36594 ./prep_dataset/ILSVRC2012_val_00024274.bin 224 224 +36595 ./prep_dataset/ILSVRC2012_val_00000532.bin 224 224 +36596 ./prep_dataset/ILSVRC2012_val_00003489.bin 224 224 +36597 ./prep_dataset/ILSVRC2012_val_00005199.bin 224 224 +36598 ./prep_dataset/ILSVRC2012_val_00033023.bin 224 224 +36599 ./prep_dataset/ILSVRC2012_val_00031680.bin 224 224 +36600 ./prep_dataset/ILSVRC2012_val_00015432.bin 224 224 +36601 ./prep_dataset/ILSVRC2012_val_00027736.bin 224 224 +36602 ./prep_dataset/ILSVRC2012_val_00022433.bin 224 224 +36603 ./prep_dataset/ILSVRC2012_val_00043951.bin 224 224 +36604 ./prep_dataset/ILSVRC2012_val_00024871.bin 224 224 +36605 ./prep_dataset/ILSVRC2012_val_00046610.bin 224 224 +36606 ./prep_dataset/ILSVRC2012_val_00033759.bin 224 224 +36607 ./prep_dataset/ILSVRC2012_val_00025942.bin 224 224 +36608 ./prep_dataset/ILSVRC2012_val_00035024.bin 224 224 +36609 ./prep_dataset/ILSVRC2012_val_00034177.bin 224 224 +36610 ./prep_dataset/ILSVRC2012_val_00026766.bin 224 224 +36611 ./prep_dataset/ILSVRC2012_val_00014218.bin 224 224 +36612 ./prep_dataset/ILSVRC2012_val_00040048.bin 224 224 +36613 ./prep_dataset/ILSVRC2012_val_00026865.bin 224 224 +36614 ./prep_dataset/ILSVRC2012_val_00002191.bin 224 224 +36615 ./prep_dataset/ILSVRC2012_val_00038968.bin 224 224 +36616 ./prep_dataset/ILSVRC2012_val_00004832.bin 224 224 +36617 ./prep_dataset/ILSVRC2012_val_00031132.bin 224 224 +36618 ./prep_dataset/ILSVRC2012_val_00028576.bin 224 224 +36619 ./prep_dataset/ILSVRC2012_val_00011336.bin 224 224 +36620 ./prep_dataset/ILSVRC2012_val_00035229.bin 224 224 +36621 ./prep_dataset/ILSVRC2012_val_00028293.bin 224 224 +36622 ./prep_dataset/ILSVRC2012_val_00046881.bin 224 224 +36623 ./prep_dataset/ILSVRC2012_val_00010676.bin 224 224 +36624 ./prep_dataset/ILSVRC2012_val_00022194.bin 224 224 +36625 ./prep_dataset/ILSVRC2012_val_00045279.bin 224 224 +36626 ./prep_dataset/ILSVRC2012_val_00031142.bin 224 224 +36627 ./prep_dataset/ILSVRC2012_val_00004684.bin 224 224 +36628 ./prep_dataset/ILSVRC2012_val_00036072.bin 224 224 +36629 ./prep_dataset/ILSVRC2012_val_00020164.bin 224 224 +36630 ./prep_dataset/ILSVRC2012_val_00015224.bin 224 224 +36631 ./prep_dataset/ILSVRC2012_val_00015437.bin 224 224 +36632 ./prep_dataset/ILSVRC2012_val_00037213.bin 224 224 +36633 ./prep_dataset/ILSVRC2012_val_00006753.bin 224 224 +36634 ./prep_dataset/ILSVRC2012_val_00008605.bin 224 224 +36635 ./prep_dataset/ILSVRC2012_val_00040892.bin 224 224 +36636 ./prep_dataset/ILSVRC2012_val_00042984.bin 224 224 +36637 ./prep_dataset/ILSVRC2012_val_00034669.bin 224 224 +36638 ./prep_dataset/ILSVRC2012_val_00003733.bin 224 224 +36639 ./prep_dataset/ILSVRC2012_val_00041767.bin 224 224 +36640 ./prep_dataset/ILSVRC2012_val_00045850.bin 224 224 +36641 ./prep_dataset/ILSVRC2012_val_00030844.bin 224 224 +36642 ./prep_dataset/ILSVRC2012_val_00028832.bin 224 224 +36643 ./prep_dataset/ILSVRC2012_val_00021377.bin 224 224 +36644 ./prep_dataset/ILSVRC2012_val_00035240.bin 224 224 +36645 ./prep_dataset/ILSVRC2012_val_00015029.bin 224 224 +36646 ./prep_dataset/ILSVRC2012_val_00014005.bin 224 224 +36647 ./prep_dataset/ILSVRC2012_val_00041668.bin 224 224 +36648 ./prep_dataset/ILSVRC2012_val_00029091.bin 224 224 +36649 ./prep_dataset/ILSVRC2012_val_00046333.bin 224 224 +36650 ./prep_dataset/ILSVRC2012_val_00035044.bin 224 224 +36651 ./prep_dataset/ILSVRC2012_val_00029498.bin 224 224 +36652 ./prep_dataset/ILSVRC2012_val_00045014.bin 224 224 +36653 ./prep_dataset/ILSVRC2012_val_00036637.bin 224 224 +36654 ./prep_dataset/ILSVRC2012_val_00044477.bin 224 224 +36655 ./prep_dataset/ILSVRC2012_val_00013466.bin 224 224 +36656 ./prep_dataset/ILSVRC2012_val_00023275.bin 224 224 +36657 ./prep_dataset/ILSVRC2012_val_00037550.bin 224 224 +36658 ./prep_dataset/ILSVRC2012_val_00031375.bin 224 224 +36659 ./prep_dataset/ILSVRC2012_val_00008116.bin 224 224 +36660 ./prep_dataset/ILSVRC2012_val_00035227.bin 224 224 +36661 ./prep_dataset/ILSVRC2012_val_00033965.bin 224 224 +36662 ./prep_dataset/ILSVRC2012_val_00028148.bin 224 224 +36663 ./prep_dataset/ILSVRC2012_val_00020183.bin 224 224 +36664 ./prep_dataset/ILSVRC2012_val_00047028.bin 224 224 +36665 ./prep_dataset/ILSVRC2012_val_00004389.bin 224 224 +36666 ./prep_dataset/ILSVRC2012_val_00035517.bin 224 224 +36667 ./prep_dataset/ILSVRC2012_val_00010252.bin 224 224 +36668 ./prep_dataset/ILSVRC2012_val_00019464.bin 224 224 +36669 ./prep_dataset/ILSVRC2012_val_00042571.bin 224 224 +36670 ./prep_dataset/ILSVRC2012_val_00026382.bin 224 224 +36671 ./prep_dataset/ILSVRC2012_val_00005127.bin 224 224 +36672 ./prep_dataset/ILSVRC2012_val_00012685.bin 224 224 +36673 ./prep_dataset/ILSVRC2012_val_00019905.bin 224 224 +36674 ./prep_dataset/ILSVRC2012_val_00015236.bin 224 224 +36675 ./prep_dataset/ILSVRC2012_val_00037604.bin 224 224 +36676 ./prep_dataset/ILSVRC2012_val_00020863.bin 224 224 +36677 ./prep_dataset/ILSVRC2012_val_00034621.bin 224 224 +36678 ./prep_dataset/ILSVRC2012_val_00025921.bin 224 224 +36679 ./prep_dataset/ILSVRC2012_val_00000127.bin 224 224 +36680 ./prep_dataset/ILSVRC2012_val_00018078.bin 224 224 +36681 ./prep_dataset/ILSVRC2012_val_00016212.bin 224 224 +36682 ./prep_dataset/ILSVRC2012_val_00021610.bin 224 224 +36683 ./prep_dataset/ILSVRC2012_val_00023262.bin 224 224 +36684 ./prep_dataset/ILSVRC2012_val_00029544.bin 224 224 +36685 ./prep_dataset/ILSVRC2012_val_00045374.bin 224 224 +36686 ./prep_dataset/ILSVRC2012_val_00006637.bin 224 224 +36687 ./prep_dataset/ILSVRC2012_val_00046721.bin 224 224 +36688 ./prep_dataset/ILSVRC2012_val_00038913.bin 224 224 +36689 ./prep_dataset/ILSVRC2012_val_00014067.bin 224 224 +36690 ./prep_dataset/ILSVRC2012_val_00021986.bin 224 224 +36691 ./prep_dataset/ILSVRC2012_val_00045559.bin 224 224 +36692 ./prep_dataset/ILSVRC2012_val_00000885.bin 224 224 +36693 ./prep_dataset/ILSVRC2012_val_00023169.bin 224 224 +36694 ./prep_dataset/ILSVRC2012_val_00016636.bin 224 224 +36695 ./prep_dataset/ILSVRC2012_val_00042972.bin 224 224 +36696 ./prep_dataset/ILSVRC2012_val_00043047.bin 224 224 +36697 ./prep_dataset/ILSVRC2012_val_00032267.bin 224 224 +36698 ./prep_dataset/ILSVRC2012_val_00005410.bin 224 224 +36699 ./prep_dataset/ILSVRC2012_val_00015322.bin 224 224 +36700 ./prep_dataset/ILSVRC2012_val_00030813.bin 224 224 +36701 ./prep_dataset/ILSVRC2012_val_00032793.bin 224 224 +36702 ./prep_dataset/ILSVRC2012_val_00037898.bin 224 224 +36703 ./prep_dataset/ILSVRC2012_val_00028762.bin 224 224 +36704 ./prep_dataset/ILSVRC2012_val_00002636.bin 224 224 +36705 ./prep_dataset/ILSVRC2012_val_00001900.bin 224 224 +36706 ./prep_dataset/ILSVRC2012_val_00016443.bin 224 224 +36707 ./prep_dataset/ILSVRC2012_val_00016146.bin 224 224 +36708 ./prep_dataset/ILSVRC2012_val_00041574.bin 224 224 +36709 ./prep_dataset/ILSVRC2012_val_00015314.bin 224 224 +36710 ./prep_dataset/ILSVRC2012_val_00027580.bin 224 224 +36711 ./prep_dataset/ILSVRC2012_val_00001121.bin 224 224 +36712 ./prep_dataset/ILSVRC2012_val_00047308.bin 224 224 +36713 ./prep_dataset/ILSVRC2012_val_00048459.bin 224 224 +36714 ./prep_dataset/ILSVRC2012_val_00019630.bin 224 224 +36715 ./prep_dataset/ILSVRC2012_val_00033062.bin 224 224 +36716 ./prep_dataset/ILSVRC2012_val_00047203.bin 224 224 +36717 ./prep_dataset/ILSVRC2012_val_00032907.bin 224 224 +36718 ./prep_dataset/ILSVRC2012_val_00022665.bin 224 224 +36719 ./prep_dataset/ILSVRC2012_val_00037962.bin 224 224 +36720 ./prep_dataset/ILSVRC2012_val_00000410.bin 224 224 +36721 ./prep_dataset/ILSVRC2012_val_00016286.bin 224 224 +36722 ./prep_dataset/ILSVRC2012_val_00047007.bin 224 224 +36723 ./prep_dataset/ILSVRC2012_val_00042420.bin 224 224 +36724 ./prep_dataset/ILSVRC2012_val_00041778.bin 224 224 +36725 ./prep_dataset/ILSVRC2012_val_00023637.bin 224 224 +36726 ./prep_dataset/ILSVRC2012_val_00032490.bin 224 224 +36727 ./prep_dataset/ILSVRC2012_val_00009004.bin 224 224 +36728 ./prep_dataset/ILSVRC2012_val_00003280.bin 224 224 +36729 ./prep_dataset/ILSVRC2012_val_00046200.bin 224 224 +36730 ./prep_dataset/ILSVRC2012_val_00045675.bin 224 224 +36731 ./prep_dataset/ILSVRC2012_val_00023303.bin 224 224 +36732 ./prep_dataset/ILSVRC2012_val_00008780.bin 224 224 +36733 ./prep_dataset/ILSVRC2012_val_00028031.bin 224 224 +36734 ./prep_dataset/ILSVRC2012_val_00026137.bin 224 224 +36735 ./prep_dataset/ILSVRC2012_val_00017272.bin 224 224 +36736 ./prep_dataset/ILSVRC2012_val_00014086.bin 224 224 +36737 ./prep_dataset/ILSVRC2012_val_00005266.bin 224 224 +36738 ./prep_dataset/ILSVRC2012_val_00030861.bin 224 224 +36739 ./prep_dataset/ILSVRC2012_val_00009757.bin 224 224 +36740 ./prep_dataset/ILSVRC2012_val_00033201.bin 224 224 +36741 ./prep_dataset/ILSVRC2012_val_00012821.bin 224 224 +36742 ./prep_dataset/ILSVRC2012_val_00046301.bin 224 224 +36743 ./prep_dataset/ILSVRC2012_val_00025232.bin 224 224 +36744 ./prep_dataset/ILSVRC2012_val_00048738.bin 224 224 +36745 ./prep_dataset/ILSVRC2012_val_00043740.bin 224 224 +36746 ./prep_dataset/ILSVRC2012_val_00048601.bin 224 224 +36747 ./prep_dataset/ILSVRC2012_val_00026263.bin 224 224 +36748 ./prep_dataset/ILSVRC2012_val_00041939.bin 224 224 +36749 ./prep_dataset/ILSVRC2012_val_00024232.bin 224 224 +36750 ./prep_dataset/ILSVRC2012_val_00019872.bin 224 224 +36751 ./prep_dataset/ILSVRC2012_val_00026804.bin 224 224 +36752 ./prep_dataset/ILSVRC2012_val_00016149.bin 224 224 +36753 ./prep_dataset/ILSVRC2012_val_00021110.bin 224 224 +36754 ./prep_dataset/ILSVRC2012_val_00002496.bin 224 224 +36755 ./prep_dataset/ILSVRC2012_val_00000114.bin 224 224 +36756 ./prep_dataset/ILSVRC2012_val_00038647.bin 224 224 +36757 ./prep_dataset/ILSVRC2012_val_00014251.bin 224 224 +36758 ./prep_dataset/ILSVRC2012_val_00021020.bin 224 224 +36759 ./prep_dataset/ILSVRC2012_val_00016693.bin 224 224 +36760 ./prep_dataset/ILSVRC2012_val_00027844.bin 224 224 +36761 ./prep_dataset/ILSVRC2012_val_00031473.bin 224 224 +36762 ./prep_dataset/ILSVRC2012_val_00041077.bin 224 224 +36763 ./prep_dataset/ILSVRC2012_val_00006683.bin 224 224 +36764 ./prep_dataset/ILSVRC2012_val_00034845.bin 224 224 +36765 ./prep_dataset/ILSVRC2012_val_00027921.bin 224 224 +36766 ./prep_dataset/ILSVRC2012_val_00037290.bin 224 224 +36767 ./prep_dataset/ILSVRC2012_val_00019140.bin 224 224 +36768 ./prep_dataset/ILSVRC2012_val_00048460.bin 224 224 +36769 ./prep_dataset/ILSVRC2012_val_00026106.bin 224 224 +36770 ./prep_dataset/ILSVRC2012_val_00004982.bin 224 224 +36771 ./prep_dataset/ILSVRC2012_val_00009776.bin 224 224 +36772 ./prep_dataset/ILSVRC2012_val_00018200.bin 224 224 +36773 ./prep_dataset/ILSVRC2012_val_00038437.bin 224 224 +36774 ./prep_dataset/ILSVRC2012_val_00021006.bin 224 224 +36775 ./prep_dataset/ILSVRC2012_val_00026107.bin 224 224 +36776 ./prep_dataset/ILSVRC2012_val_00041969.bin 224 224 +36777 ./prep_dataset/ILSVRC2012_val_00044295.bin 224 224 +36778 ./prep_dataset/ILSVRC2012_val_00023913.bin 224 224 +36779 ./prep_dataset/ILSVRC2012_val_00008507.bin 224 224 +36780 ./prep_dataset/ILSVRC2012_val_00002124.bin 224 224 +36781 ./prep_dataset/ILSVRC2012_val_00025013.bin 224 224 +36782 ./prep_dataset/ILSVRC2012_val_00037769.bin 224 224 +36783 ./prep_dataset/ILSVRC2012_val_00042523.bin 224 224 +36784 ./prep_dataset/ILSVRC2012_val_00027521.bin 224 224 +36785 ./prep_dataset/ILSVRC2012_val_00003096.bin 224 224 +36786 ./prep_dataset/ILSVRC2012_val_00026576.bin 224 224 +36787 ./prep_dataset/ILSVRC2012_val_00021796.bin 224 224 +36788 ./prep_dataset/ILSVRC2012_val_00022072.bin 224 224 +36789 ./prep_dataset/ILSVRC2012_val_00015179.bin 224 224 +36790 ./prep_dataset/ILSVRC2012_val_00024540.bin 224 224 +36791 ./prep_dataset/ILSVRC2012_val_00016951.bin 224 224 +36792 ./prep_dataset/ILSVRC2012_val_00041388.bin 224 224 +36793 ./prep_dataset/ILSVRC2012_val_00035988.bin 224 224 +36794 ./prep_dataset/ILSVRC2012_val_00032094.bin 224 224 +36795 ./prep_dataset/ILSVRC2012_val_00001573.bin 224 224 +36796 ./prep_dataset/ILSVRC2012_val_00042623.bin 224 224 +36797 ./prep_dataset/ILSVRC2012_val_00021831.bin 224 224 +36798 ./prep_dataset/ILSVRC2012_val_00009693.bin 224 224 +36799 ./prep_dataset/ILSVRC2012_val_00041888.bin 224 224 +36800 ./prep_dataset/ILSVRC2012_val_00015397.bin 224 224 +36801 ./prep_dataset/ILSVRC2012_val_00040348.bin 224 224 +36802 ./prep_dataset/ILSVRC2012_val_00036963.bin 224 224 +36803 ./prep_dataset/ILSVRC2012_val_00000344.bin 224 224 +36804 ./prep_dataset/ILSVRC2012_val_00014393.bin 224 224 +36805 ./prep_dataset/ILSVRC2012_val_00000494.bin 224 224 +36806 ./prep_dataset/ILSVRC2012_val_00010400.bin 224 224 +36807 ./prep_dataset/ILSVRC2012_val_00046580.bin 224 224 +36808 ./prep_dataset/ILSVRC2012_val_00010285.bin 224 224 +36809 ./prep_dataset/ILSVRC2012_val_00046650.bin 224 224 +36810 ./prep_dataset/ILSVRC2012_val_00020328.bin 224 224 +36811 ./prep_dataset/ILSVRC2012_val_00012092.bin 224 224 +36812 ./prep_dataset/ILSVRC2012_val_00037514.bin 224 224 +36813 ./prep_dataset/ILSVRC2012_val_00046828.bin 224 224 +36814 ./prep_dataset/ILSVRC2012_val_00047064.bin 224 224 +36815 ./prep_dataset/ILSVRC2012_val_00034966.bin 224 224 +36816 ./prep_dataset/ILSVRC2012_val_00039352.bin 224 224 +36817 ./prep_dataset/ILSVRC2012_val_00037168.bin 224 224 +36818 ./prep_dataset/ILSVRC2012_val_00014711.bin 224 224 +36819 ./prep_dataset/ILSVRC2012_val_00007640.bin 224 224 +36820 ./prep_dataset/ILSVRC2012_val_00024857.bin 224 224 +36821 ./prep_dataset/ILSVRC2012_val_00026819.bin 224 224 +36822 ./prep_dataset/ILSVRC2012_val_00009868.bin 224 224 +36823 ./prep_dataset/ILSVRC2012_val_00044498.bin 224 224 +36824 ./prep_dataset/ILSVRC2012_val_00045631.bin 224 224 +36825 ./prep_dataset/ILSVRC2012_val_00037914.bin 224 224 +36826 ./prep_dataset/ILSVRC2012_val_00046066.bin 224 224 +36827 ./prep_dataset/ILSVRC2012_val_00028315.bin 224 224 +36828 ./prep_dataset/ILSVRC2012_val_00045592.bin 224 224 +36829 ./prep_dataset/ILSVRC2012_val_00005666.bin 224 224 +36830 ./prep_dataset/ILSVRC2012_val_00024780.bin 224 224 +36831 ./prep_dataset/ILSVRC2012_val_00010151.bin 224 224 +36832 ./prep_dataset/ILSVRC2012_val_00004394.bin 224 224 +36833 ./prep_dataset/ILSVRC2012_val_00005539.bin 224 224 +36834 ./prep_dataset/ILSVRC2012_val_00011189.bin 224 224 +36835 ./prep_dataset/ILSVRC2012_val_00030126.bin 224 224 +36836 ./prep_dataset/ILSVRC2012_val_00009274.bin 224 224 +36837 ./prep_dataset/ILSVRC2012_val_00034661.bin 224 224 +36838 ./prep_dataset/ILSVRC2012_val_00047172.bin 224 224 +36839 ./prep_dataset/ILSVRC2012_val_00011731.bin 224 224 +36840 ./prep_dataset/ILSVRC2012_val_00032213.bin 224 224 +36841 ./prep_dataset/ILSVRC2012_val_00029743.bin 224 224 +36842 ./prep_dataset/ILSVRC2012_val_00004618.bin 224 224 +36843 ./prep_dataset/ILSVRC2012_val_00025147.bin 224 224 +36844 ./prep_dataset/ILSVRC2012_val_00039048.bin 224 224 +36845 ./prep_dataset/ILSVRC2012_val_00047405.bin 224 224 +36846 ./prep_dataset/ILSVRC2012_val_00028020.bin 224 224 +36847 ./prep_dataset/ILSVRC2012_val_00012243.bin 224 224 +36848 ./prep_dataset/ILSVRC2012_val_00012180.bin 224 224 +36849 ./prep_dataset/ILSVRC2012_val_00048780.bin 224 224 +36850 ./prep_dataset/ILSVRC2012_val_00005570.bin 224 224 +36851 ./prep_dataset/ILSVRC2012_val_00039233.bin 224 224 +36852 ./prep_dataset/ILSVRC2012_val_00048690.bin 224 224 +36853 ./prep_dataset/ILSVRC2012_val_00008674.bin 224 224 +36854 ./prep_dataset/ILSVRC2012_val_00038576.bin 224 224 +36855 ./prep_dataset/ILSVRC2012_val_00030891.bin 224 224 +36856 ./prep_dataset/ILSVRC2012_val_00029873.bin 224 224 +36857 ./prep_dataset/ILSVRC2012_val_00035943.bin 224 224 +36858 ./prep_dataset/ILSVRC2012_val_00016473.bin 224 224 +36859 ./prep_dataset/ILSVRC2012_val_00031028.bin 224 224 +36860 ./prep_dataset/ILSVRC2012_val_00024834.bin 224 224 +36861 ./prep_dataset/ILSVRC2012_val_00049199.bin 224 224 +36862 ./prep_dataset/ILSVRC2012_val_00023013.bin 224 224 +36863 ./prep_dataset/ILSVRC2012_val_00033272.bin 224 224 +36864 ./prep_dataset/ILSVRC2012_val_00015363.bin 224 224 +36865 ./prep_dataset/ILSVRC2012_val_00031669.bin 224 224 +36866 ./prep_dataset/ILSVRC2012_val_00042502.bin 224 224 +36867 ./prep_dataset/ILSVRC2012_val_00037206.bin 224 224 +36868 ./prep_dataset/ILSVRC2012_val_00040222.bin 224 224 +36869 ./prep_dataset/ILSVRC2012_val_00008896.bin 224 224 +36870 ./prep_dataset/ILSVRC2012_val_00036562.bin 224 224 +36871 ./prep_dataset/ILSVRC2012_val_00003269.bin 224 224 +36872 ./prep_dataset/ILSVRC2012_val_00045103.bin 224 224 +36873 ./prep_dataset/ILSVRC2012_val_00022633.bin 224 224 +36874 ./prep_dataset/ILSVRC2012_val_00036129.bin 224 224 +36875 ./prep_dataset/ILSVRC2012_val_00038288.bin 224 224 +36876 ./prep_dataset/ILSVRC2012_val_00019450.bin 224 224 +36877 ./prep_dataset/ILSVRC2012_val_00026659.bin 224 224 +36878 ./prep_dataset/ILSVRC2012_val_00040239.bin 224 224 +36879 ./prep_dataset/ILSVRC2012_val_00041092.bin 224 224 +36880 ./prep_dataset/ILSVRC2012_val_00001039.bin 224 224 +36881 ./prep_dataset/ILSVRC2012_val_00013520.bin 224 224 +36882 ./prep_dataset/ILSVRC2012_val_00041991.bin 224 224 +36883 ./prep_dataset/ILSVRC2012_val_00006483.bin 224 224 +36884 ./prep_dataset/ILSVRC2012_val_00001653.bin 224 224 +36885 ./prep_dataset/ILSVRC2012_val_00021792.bin 224 224 +36886 ./prep_dataset/ILSVRC2012_val_00025599.bin 224 224 +36887 ./prep_dataset/ILSVRC2012_val_00044378.bin 224 224 +36888 ./prep_dataset/ILSVRC2012_val_00006861.bin 224 224 +36889 ./prep_dataset/ILSVRC2012_val_00003976.bin 224 224 +36890 ./prep_dataset/ILSVRC2012_val_00001666.bin 224 224 +36891 ./prep_dataset/ILSVRC2012_val_00021990.bin 224 224 +36892 ./prep_dataset/ILSVRC2012_val_00004451.bin 224 224 +36893 ./prep_dataset/ILSVRC2012_val_00028155.bin 224 224 +36894 ./prep_dataset/ILSVRC2012_val_00004035.bin 224 224 +36895 ./prep_dataset/ILSVRC2012_val_00016262.bin 224 224 +36896 ./prep_dataset/ILSVRC2012_val_00046092.bin 224 224 +36897 ./prep_dataset/ILSVRC2012_val_00025028.bin 224 224 +36898 ./prep_dataset/ILSVRC2012_val_00029187.bin 224 224 +36899 ./prep_dataset/ILSVRC2012_val_00043916.bin 224 224 +36900 ./prep_dataset/ILSVRC2012_val_00029909.bin 224 224 +36901 ./prep_dataset/ILSVRC2012_val_00049840.bin 224 224 +36902 ./prep_dataset/ILSVRC2012_val_00023092.bin 224 224 +36903 ./prep_dataset/ILSVRC2012_val_00000470.bin 224 224 +36904 ./prep_dataset/ILSVRC2012_val_00009331.bin 224 224 +36905 ./prep_dataset/ILSVRC2012_val_00041174.bin 224 224 +36906 ./prep_dataset/ILSVRC2012_val_00037847.bin 224 224 +36907 ./prep_dataset/ILSVRC2012_val_00017501.bin 224 224 +36908 ./prep_dataset/ILSVRC2012_val_00026878.bin 224 224 +36909 ./prep_dataset/ILSVRC2012_val_00009281.bin 224 224 +36910 ./prep_dataset/ILSVRC2012_val_00011880.bin 224 224 +36911 ./prep_dataset/ILSVRC2012_val_00014538.bin 224 224 +36912 ./prep_dataset/ILSVRC2012_val_00002190.bin 224 224 +36913 ./prep_dataset/ILSVRC2012_val_00035918.bin 224 224 +36914 ./prep_dataset/ILSVRC2012_val_00028823.bin 224 224 +36915 ./prep_dataset/ILSVRC2012_val_00012299.bin 224 224 +36916 ./prep_dataset/ILSVRC2012_val_00046149.bin 224 224 +36917 ./prep_dataset/ILSVRC2012_val_00016787.bin 224 224 +36918 ./prep_dataset/ILSVRC2012_val_00011103.bin 224 224 +36919 ./prep_dataset/ILSVRC2012_val_00012031.bin 224 224 +36920 ./prep_dataset/ILSVRC2012_val_00018346.bin 224 224 +36921 ./prep_dataset/ILSVRC2012_val_00047698.bin 224 224 +36922 ./prep_dataset/ILSVRC2012_val_00037376.bin 224 224 +36923 ./prep_dataset/ILSVRC2012_val_00023371.bin 224 224 +36924 ./prep_dataset/ILSVRC2012_val_00010128.bin 224 224 +36925 ./prep_dataset/ILSVRC2012_val_00021961.bin 224 224 +36926 ./prep_dataset/ILSVRC2012_val_00020521.bin 224 224 +36927 ./prep_dataset/ILSVRC2012_val_00004272.bin 224 224 +36928 ./prep_dataset/ILSVRC2012_val_00004690.bin 224 224 +36929 ./prep_dataset/ILSVRC2012_val_00041171.bin 224 224 +36930 ./prep_dataset/ILSVRC2012_val_00001159.bin 224 224 +36931 ./prep_dataset/ILSVRC2012_val_00013482.bin 224 224 +36932 ./prep_dataset/ILSVRC2012_val_00002003.bin 224 224 +36933 ./prep_dataset/ILSVRC2012_val_00008913.bin 224 224 +36934 ./prep_dataset/ILSVRC2012_val_00003332.bin 224 224 +36935 ./prep_dataset/ILSVRC2012_val_00020818.bin 224 224 +36936 ./prep_dataset/ILSVRC2012_val_00025116.bin 224 224 +36937 ./prep_dataset/ILSVRC2012_val_00032719.bin 224 224 +36938 ./prep_dataset/ILSVRC2012_val_00037347.bin 224 224 +36939 ./prep_dataset/ILSVRC2012_val_00021782.bin 224 224 +36940 ./prep_dataset/ILSVRC2012_val_00032216.bin 224 224 +36941 ./prep_dataset/ILSVRC2012_val_00049964.bin 224 224 +36942 ./prep_dataset/ILSVRC2012_val_00016249.bin 224 224 +36943 ./prep_dataset/ILSVRC2012_val_00003592.bin 224 224 +36944 ./prep_dataset/ILSVRC2012_val_00004481.bin 224 224 +36945 ./prep_dataset/ILSVRC2012_val_00031966.bin 224 224 +36946 ./prep_dataset/ILSVRC2012_val_00004645.bin 224 224 +36947 ./prep_dataset/ILSVRC2012_val_00036283.bin 224 224 +36948 ./prep_dataset/ILSVRC2012_val_00012016.bin 224 224 +36949 ./prep_dataset/ILSVRC2012_val_00028756.bin 224 224 +36950 ./prep_dataset/ILSVRC2012_val_00021970.bin 224 224 +36951 ./prep_dataset/ILSVRC2012_val_00030899.bin 224 224 +36952 ./prep_dataset/ILSVRC2012_val_00032502.bin 224 224 +36953 ./prep_dataset/ILSVRC2012_val_00039834.bin 224 224 +36954 ./prep_dataset/ILSVRC2012_val_00043436.bin 224 224 +36955 ./prep_dataset/ILSVRC2012_val_00012663.bin 224 224 +36956 ./prep_dataset/ILSVRC2012_val_00000314.bin 224 224 +36957 ./prep_dataset/ILSVRC2012_val_00011151.bin 224 224 +36958 ./prep_dataset/ILSVRC2012_val_00023527.bin 224 224 +36959 ./prep_dataset/ILSVRC2012_val_00031410.bin 224 224 +36960 ./prep_dataset/ILSVRC2012_val_00038819.bin 224 224 +36961 ./prep_dataset/ILSVRC2012_val_00003742.bin 224 224 +36962 ./prep_dataset/ILSVRC2012_val_00018989.bin 224 224 +36963 ./prep_dataset/ILSVRC2012_val_00006239.bin 224 224 +36964 ./prep_dataset/ILSVRC2012_val_00013212.bin 224 224 +36965 ./prep_dataset/ILSVRC2012_val_00002840.bin 224 224 +36966 ./prep_dataset/ILSVRC2012_val_00000201.bin 224 224 +36967 ./prep_dataset/ILSVRC2012_val_00039706.bin 224 224 +36968 ./prep_dataset/ILSVRC2012_val_00027018.bin 224 224 +36969 ./prep_dataset/ILSVRC2012_val_00004794.bin 224 224 +36970 ./prep_dataset/ILSVRC2012_val_00033707.bin 224 224 +36971 ./prep_dataset/ILSVRC2012_val_00028622.bin 224 224 +36972 ./prep_dataset/ILSVRC2012_val_00023663.bin 224 224 +36973 ./prep_dataset/ILSVRC2012_val_00042996.bin 224 224 +36974 ./prep_dataset/ILSVRC2012_val_00034894.bin 224 224 +36975 ./prep_dataset/ILSVRC2012_val_00041189.bin 224 224 +36976 ./prep_dataset/ILSVRC2012_val_00017484.bin 224 224 +36977 ./prep_dataset/ILSVRC2012_val_00018445.bin 224 224 +36978 ./prep_dataset/ILSVRC2012_val_00009836.bin 224 224 +36979 ./prep_dataset/ILSVRC2012_val_00028276.bin 224 224 +36980 ./prep_dataset/ILSVRC2012_val_00013850.bin 224 224 +36981 ./prep_dataset/ILSVRC2012_val_00026044.bin 224 224 +36982 ./prep_dataset/ILSVRC2012_val_00031005.bin 224 224 +36983 ./prep_dataset/ILSVRC2012_val_00025940.bin 224 224 +36984 ./prep_dataset/ILSVRC2012_val_00033430.bin 224 224 +36985 ./prep_dataset/ILSVRC2012_val_00021272.bin 224 224 +36986 ./prep_dataset/ILSVRC2012_val_00001150.bin 224 224 +36987 ./prep_dataset/ILSVRC2012_val_00036306.bin 224 224 +36988 ./prep_dataset/ILSVRC2012_val_00043631.bin 224 224 +36989 ./prep_dataset/ILSVRC2012_val_00009314.bin 224 224 +36990 ./prep_dataset/ILSVRC2012_val_00025296.bin 224 224 +36991 ./prep_dataset/ILSVRC2012_val_00019995.bin 224 224 +36992 ./prep_dataset/ILSVRC2012_val_00043919.bin 224 224 +36993 ./prep_dataset/ILSVRC2012_val_00021504.bin 224 224 +36994 ./prep_dataset/ILSVRC2012_val_00009443.bin 224 224 +36995 ./prep_dataset/ILSVRC2012_val_00004568.bin 224 224 +36996 ./prep_dataset/ILSVRC2012_val_00009001.bin 224 224 +36997 ./prep_dataset/ILSVRC2012_val_00010440.bin 224 224 +36998 ./prep_dataset/ILSVRC2012_val_00036854.bin 224 224 +36999 ./prep_dataset/ILSVRC2012_val_00011634.bin 224 224 +37000 ./prep_dataset/ILSVRC2012_val_00025448.bin 224 224 +37001 ./prep_dataset/ILSVRC2012_val_00029490.bin 224 224 +37002 ./prep_dataset/ILSVRC2012_val_00043633.bin 224 224 +37003 ./prep_dataset/ILSVRC2012_val_00013862.bin 224 224 +37004 ./prep_dataset/ILSVRC2012_val_00003926.bin 224 224 +37005 ./prep_dataset/ILSVRC2012_val_00021844.bin 224 224 +37006 ./prep_dataset/ILSVRC2012_val_00003641.bin 224 224 +37007 ./prep_dataset/ILSVRC2012_val_00041947.bin 224 224 +37008 ./prep_dataset/ILSVRC2012_val_00025094.bin 224 224 +37009 ./prep_dataset/ILSVRC2012_val_00049482.bin 224 224 +37010 ./prep_dataset/ILSVRC2012_val_00020892.bin 224 224 +37011 ./prep_dataset/ILSVRC2012_val_00039860.bin 224 224 +37012 ./prep_dataset/ILSVRC2012_val_00017462.bin 224 224 +37013 ./prep_dataset/ILSVRC2012_val_00012547.bin 224 224 +37014 ./prep_dataset/ILSVRC2012_val_00015913.bin 224 224 +37015 ./prep_dataset/ILSVRC2012_val_00048804.bin 224 224 +37016 ./prep_dataset/ILSVRC2012_val_00025284.bin 224 224 +37017 ./prep_dataset/ILSVRC2012_val_00042905.bin 224 224 +37018 ./prep_dataset/ILSVRC2012_val_00003493.bin 224 224 +37019 ./prep_dataset/ILSVRC2012_val_00049388.bin 224 224 +37020 ./prep_dataset/ILSVRC2012_val_00020795.bin 224 224 +37021 ./prep_dataset/ILSVRC2012_val_00004208.bin 224 224 +37022 ./prep_dataset/ILSVRC2012_val_00024733.bin 224 224 +37023 ./prep_dataset/ILSVRC2012_val_00036459.bin 224 224 +37024 ./prep_dataset/ILSVRC2012_val_00038831.bin 224 224 +37025 ./prep_dataset/ILSVRC2012_val_00019206.bin 224 224 +37026 ./prep_dataset/ILSVRC2012_val_00002858.bin 224 224 +37027 ./prep_dataset/ILSVRC2012_val_00037703.bin 224 224 +37028 ./prep_dataset/ILSVRC2012_val_00011685.bin 224 224 +37029 ./prep_dataset/ILSVRC2012_val_00020694.bin 224 224 +37030 ./prep_dataset/ILSVRC2012_val_00035542.bin 224 224 +37031 ./prep_dataset/ILSVRC2012_val_00039179.bin 224 224 +37032 ./prep_dataset/ILSVRC2012_val_00003770.bin 224 224 +37033 ./prep_dataset/ILSVRC2012_val_00047338.bin 224 224 +37034 ./prep_dataset/ILSVRC2012_val_00021414.bin 224 224 +37035 ./prep_dataset/ILSVRC2012_val_00027495.bin 224 224 +37036 ./prep_dataset/ILSVRC2012_val_00045534.bin 224 224 +37037 ./prep_dataset/ILSVRC2012_val_00025133.bin 224 224 +37038 ./prep_dataset/ILSVRC2012_val_00005043.bin 224 224 +37039 ./prep_dataset/ILSVRC2012_val_00005891.bin 224 224 +37040 ./prep_dataset/ILSVRC2012_val_00027241.bin 224 224 +37041 ./prep_dataset/ILSVRC2012_val_00040587.bin 224 224 +37042 ./prep_dataset/ILSVRC2012_val_00031278.bin 224 224 +37043 ./prep_dataset/ILSVRC2012_val_00000089.bin 224 224 +37044 ./prep_dataset/ILSVRC2012_val_00005205.bin 224 224 +37045 ./prep_dataset/ILSVRC2012_val_00035097.bin 224 224 +37046 ./prep_dataset/ILSVRC2012_val_00015795.bin 224 224 +37047 ./prep_dataset/ILSVRC2012_val_00002367.bin 224 224 +37048 ./prep_dataset/ILSVRC2012_val_00025212.bin 224 224 +37049 ./prep_dataset/ILSVRC2012_val_00007739.bin 224 224 +37050 ./prep_dataset/ILSVRC2012_val_00036949.bin 224 224 +37051 ./prep_dataset/ILSVRC2012_val_00013498.bin 224 224 +37052 ./prep_dataset/ILSVRC2012_val_00046259.bin 224 224 +37053 ./prep_dataset/ILSVRC2012_val_00001946.bin 224 224 +37054 ./prep_dataset/ILSVRC2012_val_00048778.bin 224 224 +37055 ./prep_dataset/ILSVRC2012_val_00038837.bin 224 224 +37056 ./prep_dataset/ILSVRC2012_val_00010066.bin 224 224 +37057 ./prep_dataset/ILSVRC2012_val_00029624.bin 224 224 +37058 ./prep_dataset/ILSVRC2012_val_00012071.bin 224 224 +37059 ./prep_dataset/ILSVRC2012_val_00046258.bin 224 224 +37060 ./prep_dataset/ILSVRC2012_val_00043961.bin 224 224 +37061 ./prep_dataset/ILSVRC2012_val_00021530.bin 224 224 +37062 ./prep_dataset/ILSVRC2012_val_00025552.bin 224 224 +37063 ./prep_dataset/ILSVRC2012_val_00032836.bin 224 224 +37064 ./prep_dataset/ILSVRC2012_val_00022687.bin 224 224 +37065 ./prep_dataset/ILSVRC2012_val_00008084.bin 224 224 +37066 ./prep_dataset/ILSVRC2012_val_00041125.bin 224 224 +37067 ./prep_dataset/ILSVRC2012_val_00026358.bin 224 224 +37068 ./prep_dataset/ILSVRC2012_val_00030602.bin 224 224 +37069 ./prep_dataset/ILSVRC2012_val_00014858.bin 224 224 +37070 ./prep_dataset/ILSVRC2012_val_00037503.bin 224 224 +37071 ./prep_dataset/ILSVRC2012_val_00025513.bin 224 224 +37072 ./prep_dataset/ILSVRC2012_val_00016508.bin 224 224 +37073 ./prep_dataset/ILSVRC2012_val_00037292.bin 224 224 +37074 ./prep_dataset/ILSVRC2012_val_00001014.bin 224 224 +37075 ./prep_dataset/ILSVRC2012_val_00013121.bin 224 224 +37076 ./prep_dataset/ILSVRC2012_val_00032331.bin 224 224 +37077 ./prep_dataset/ILSVRC2012_val_00021371.bin 224 224 +37078 ./prep_dataset/ILSVRC2012_val_00047158.bin 224 224 +37079 ./prep_dataset/ILSVRC2012_val_00004260.bin 224 224 +37080 ./prep_dataset/ILSVRC2012_val_00036692.bin 224 224 +37081 ./prep_dataset/ILSVRC2012_val_00004380.bin 224 224 +37082 ./prep_dataset/ILSVRC2012_val_00017515.bin 224 224 +37083 ./prep_dataset/ILSVRC2012_val_00046482.bin 224 224 +37084 ./prep_dataset/ILSVRC2012_val_00029404.bin 224 224 +37085 ./prep_dataset/ILSVRC2012_val_00039683.bin 224 224 +37086 ./prep_dataset/ILSVRC2012_val_00028123.bin 224 224 +37087 ./prep_dataset/ILSVRC2012_val_00019468.bin 224 224 +37088 ./prep_dataset/ILSVRC2012_val_00028326.bin 224 224 +37089 ./prep_dataset/ILSVRC2012_val_00035658.bin 224 224 +37090 ./prep_dataset/ILSVRC2012_val_00005946.bin 224 224 +37091 ./prep_dataset/ILSVRC2012_val_00045356.bin 224 224 +37092 ./prep_dataset/ILSVRC2012_val_00020495.bin 224 224 +37093 ./prep_dataset/ILSVRC2012_val_00030843.bin 224 224 +37094 ./prep_dataset/ILSVRC2012_val_00036538.bin 224 224 +37095 ./prep_dataset/ILSVRC2012_val_00028455.bin 224 224 +37096 ./prep_dataset/ILSVRC2012_val_00001295.bin 224 224 +37097 ./prep_dataset/ILSVRC2012_val_00027388.bin 224 224 +37098 ./prep_dataset/ILSVRC2012_val_00005656.bin 224 224 +37099 ./prep_dataset/ILSVRC2012_val_00000015.bin 224 224 +37100 ./prep_dataset/ILSVRC2012_val_00040832.bin 224 224 +37101 ./prep_dataset/ILSVRC2012_val_00043742.bin 224 224 +37102 ./prep_dataset/ILSVRC2012_val_00033354.bin 224 224 +37103 ./prep_dataset/ILSVRC2012_val_00018089.bin 224 224 +37104 ./prep_dataset/ILSVRC2012_val_00033260.bin 224 224 +37105 ./prep_dataset/ILSVRC2012_val_00025872.bin 224 224 +37106 ./prep_dataset/ILSVRC2012_val_00048944.bin 224 224 +37107 ./prep_dataset/ILSVRC2012_val_00033918.bin 224 224 +37108 ./prep_dataset/ILSVRC2012_val_00016330.bin 224 224 +37109 ./prep_dataset/ILSVRC2012_val_00031076.bin 224 224 +37110 ./prep_dataset/ILSVRC2012_val_00019320.bin 224 224 +37111 ./prep_dataset/ILSVRC2012_val_00014855.bin 224 224 +37112 ./prep_dataset/ILSVRC2012_val_00008163.bin 224 224 +37113 ./prep_dataset/ILSVRC2012_val_00002434.bin 224 224 +37114 ./prep_dataset/ILSVRC2012_val_00031080.bin 224 224 +37115 ./prep_dataset/ILSVRC2012_val_00023664.bin 224 224 +37116 ./prep_dataset/ILSVRC2012_val_00048982.bin 224 224 +37117 ./prep_dataset/ILSVRC2012_val_00000822.bin 224 224 +37118 ./prep_dataset/ILSVRC2012_val_00009237.bin 224 224 +37119 ./prep_dataset/ILSVRC2012_val_00015474.bin 224 224 +37120 ./prep_dataset/ILSVRC2012_val_00045671.bin 224 224 +37121 ./prep_dataset/ILSVRC2012_val_00012900.bin 224 224 +37122 ./prep_dataset/ILSVRC2012_val_00019760.bin 224 224 +37123 ./prep_dataset/ILSVRC2012_val_00029946.bin 224 224 +37124 ./prep_dataset/ILSVRC2012_val_00049370.bin 224 224 +37125 ./prep_dataset/ILSVRC2012_val_00015806.bin 224 224 +37126 ./prep_dataset/ILSVRC2012_val_00012487.bin 224 224 +37127 ./prep_dataset/ILSVRC2012_val_00023974.bin 224 224 +37128 ./prep_dataset/ILSVRC2012_val_00002399.bin 224 224 +37129 ./prep_dataset/ILSVRC2012_val_00027255.bin 224 224 +37130 ./prep_dataset/ILSVRC2012_val_00049083.bin 224 224 +37131 ./prep_dataset/ILSVRC2012_val_00001017.bin 224 224 +37132 ./prep_dataset/ILSVRC2012_val_00032540.bin 224 224 +37133 ./prep_dataset/ILSVRC2012_val_00001393.bin 224 224 +37134 ./prep_dataset/ILSVRC2012_val_00017315.bin 224 224 +37135 ./prep_dataset/ILSVRC2012_val_00004888.bin 224 224 +37136 ./prep_dataset/ILSVRC2012_val_00014660.bin 224 224 +37137 ./prep_dataset/ILSVRC2012_val_00006771.bin 224 224 +37138 ./prep_dataset/ILSVRC2012_val_00049168.bin 224 224 +37139 ./prep_dataset/ILSVRC2012_val_00000891.bin 224 224 +37140 ./prep_dataset/ILSVRC2012_val_00010261.bin 224 224 +37141 ./prep_dataset/ILSVRC2012_val_00018051.bin 224 224 +37142 ./prep_dataset/ILSVRC2012_val_00017247.bin 224 224 +37143 ./prep_dataset/ILSVRC2012_val_00002436.bin 224 224 +37144 ./prep_dataset/ILSVRC2012_val_00038085.bin 224 224 +37145 ./prep_dataset/ILSVRC2012_val_00014460.bin 224 224 +37146 ./prep_dataset/ILSVRC2012_val_00043537.bin 224 224 +37147 ./prep_dataset/ILSVRC2012_val_00017433.bin 224 224 +37148 ./prep_dataset/ILSVRC2012_val_00044982.bin 224 224 +37149 ./prep_dataset/ILSVRC2012_val_00014750.bin 224 224 +37150 ./prep_dataset/ILSVRC2012_val_00032323.bin 224 224 +37151 ./prep_dataset/ILSVRC2012_val_00023738.bin 224 224 +37152 ./prep_dataset/ILSVRC2012_val_00049322.bin 224 224 +37153 ./prep_dataset/ILSVRC2012_val_00003610.bin 224 224 +37154 ./prep_dataset/ILSVRC2012_val_00048071.bin 224 224 +37155 ./prep_dataset/ILSVRC2012_val_00030648.bin 224 224 +37156 ./prep_dataset/ILSVRC2012_val_00027749.bin 224 224 +37157 ./prep_dataset/ILSVRC2012_val_00026954.bin 224 224 +37158 ./prep_dataset/ILSVRC2012_val_00020792.bin 224 224 +37159 ./prep_dataset/ILSVRC2012_val_00005537.bin 224 224 +37160 ./prep_dataset/ILSVRC2012_val_00007182.bin 224 224 +37161 ./prep_dataset/ILSVRC2012_val_00026630.bin 224 224 +37162 ./prep_dataset/ILSVRC2012_val_00016475.bin 224 224 +37163 ./prep_dataset/ILSVRC2012_val_00036153.bin 224 224 +37164 ./prep_dataset/ILSVRC2012_val_00023517.bin 224 224 +37165 ./prep_dataset/ILSVRC2012_val_00010955.bin 224 224 +37166 ./prep_dataset/ILSVRC2012_val_00022289.bin 224 224 +37167 ./prep_dataset/ILSVRC2012_val_00010724.bin 224 224 +37168 ./prep_dataset/ILSVRC2012_val_00032737.bin 224 224 +37169 ./prep_dataset/ILSVRC2012_val_00017636.bin 224 224 +37170 ./prep_dataset/ILSVRC2012_val_00026873.bin 224 224 +37171 ./prep_dataset/ILSVRC2012_val_00004426.bin 224 224 +37172 ./prep_dataset/ILSVRC2012_val_00006393.bin 224 224 +37173 ./prep_dataset/ILSVRC2012_val_00015809.bin 224 224 +37174 ./prep_dataset/ILSVRC2012_val_00048935.bin 224 224 +37175 ./prep_dataset/ILSVRC2012_val_00010947.bin 224 224 +37176 ./prep_dataset/ILSVRC2012_val_00027750.bin 224 224 +37177 ./prep_dataset/ILSVRC2012_val_00005636.bin 224 224 +37178 ./prep_dataset/ILSVRC2012_val_00021934.bin 224 224 +37179 ./prep_dataset/ILSVRC2012_val_00034262.bin 224 224 +37180 ./prep_dataset/ILSVRC2012_val_00030600.bin 224 224 +37181 ./prep_dataset/ILSVRC2012_val_00045026.bin 224 224 +37182 ./prep_dataset/ILSVRC2012_val_00021920.bin 224 224 +37183 ./prep_dataset/ILSVRC2012_val_00010476.bin 224 224 +37184 ./prep_dataset/ILSVRC2012_val_00020334.bin 224 224 +37185 ./prep_dataset/ILSVRC2012_val_00027033.bin 224 224 +37186 ./prep_dataset/ILSVRC2012_val_00018779.bin 224 224 +37187 ./prep_dataset/ILSVRC2012_val_00047127.bin 224 224 +37188 ./prep_dataset/ILSVRC2012_val_00015558.bin 224 224 +37189 ./prep_dataset/ILSVRC2012_val_00002279.bin 224 224 +37190 ./prep_dataset/ILSVRC2012_val_00018918.bin 224 224 +37191 ./prep_dataset/ILSVRC2012_val_00004824.bin 224 224 +37192 ./prep_dataset/ILSVRC2012_val_00035150.bin 224 224 +37193 ./prep_dataset/ILSVRC2012_val_00040744.bin 224 224 +37194 ./prep_dataset/ILSVRC2012_val_00020865.bin 224 224 +37195 ./prep_dataset/ILSVRC2012_val_00012101.bin 224 224 +37196 ./prep_dataset/ILSVRC2012_val_00001363.bin 224 224 +37197 ./prep_dataset/ILSVRC2012_val_00012477.bin 224 224 +37198 ./prep_dataset/ILSVRC2012_val_00049442.bin 224 224 +37199 ./prep_dataset/ILSVRC2012_val_00025285.bin 224 224 +37200 ./prep_dataset/ILSVRC2012_val_00027430.bin 224 224 +37201 ./prep_dataset/ILSVRC2012_val_00020637.bin 224 224 +37202 ./prep_dataset/ILSVRC2012_val_00004621.bin 224 224 +37203 ./prep_dataset/ILSVRC2012_val_00038581.bin 224 224 +37204 ./prep_dataset/ILSVRC2012_val_00020757.bin 224 224 +37205 ./prep_dataset/ILSVRC2012_val_00000737.bin 224 224 +37206 ./prep_dataset/ILSVRC2012_val_00038299.bin 224 224 +37207 ./prep_dataset/ILSVRC2012_val_00015961.bin 224 224 +37208 ./prep_dataset/ILSVRC2012_val_00038889.bin 224 224 +37209 ./prep_dataset/ILSVRC2012_val_00024824.bin 224 224 +37210 ./prep_dataset/ILSVRC2012_val_00037549.bin 224 224 +37211 ./prep_dataset/ILSVRC2012_val_00018975.bin 224 224 +37212 ./prep_dataset/ILSVRC2012_val_00041986.bin 224 224 +37213 ./prep_dataset/ILSVRC2012_val_00031732.bin 224 224 +37214 ./prep_dataset/ILSVRC2012_val_00005201.bin 224 224 +37215 ./prep_dataset/ILSVRC2012_val_00002908.bin 224 224 +37216 ./prep_dataset/ILSVRC2012_val_00037358.bin 224 224 +37217 ./prep_dataset/ILSVRC2012_val_00049119.bin 224 224 +37218 ./prep_dataset/ILSVRC2012_val_00033469.bin 224 224 +37219 ./prep_dataset/ILSVRC2012_val_00015837.bin 224 224 +37220 ./prep_dataset/ILSVRC2012_val_00020413.bin 224 224 +37221 ./prep_dataset/ILSVRC2012_val_00004355.bin 224 224 +37222 ./prep_dataset/ILSVRC2012_val_00049240.bin 224 224 +37223 ./prep_dataset/ILSVRC2012_val_00003999.bin 224 224 +37224 ./prep_dataset/ILSVRC2012_val_00039489.bin 224 224 +37225 ./prep_dataset/ILSVRC2012_val_00046125.bin 224 224 +37226 ./prep_dataset/ILSVRC2012_val_00049433.bin 224 224 +37227 ./prep_dataset/ILSVRC2012_val_00043506.bin 224 224 +37228 ./prep_dataset/ILSVRC2012_val_00030806.bin 224 224 +37229 ./prep_dataset/ILSVRC2012_val_00041141.bin 224 224 +37230 ./prep_dataset/ILSVRC2012_val_00029561.bin 224 224 +37231 ./prep_dataset/ILSVRC2012_val_00022489.bin 224 224 +37232 ./prep_dataset/ILSVRC2012_val_00007891.bin 224 224 +37233 ./prep_dataset/ILSVRC2012_val_00011111.bin 224 224 +37234 ./prep_dataset/ILSVRC2012_val_00039621.bin 224 224 +37235 ./prep_dataset/ILSVRC2012_val_00002344.bin 224 224 +37236 ./prep_dataset/ILSVRC2012_val_00038099.bin 224 224 +37237 ./prep_dataset/ILSVRC2012_val_00012459.bin 224 224 +37238 ./prep_dataset/ILSVRC2012_val_00047344.bin 224 224 +37239 ./prep_dataset/ILSVRC2012_val_00008420.bin 224 224 +37240 ./prep_dataset/ILSVRC2012_val_00022989.bin 224 224 +37241 ./prep_dataset/ILSVRC2012_val_00030943.bin 224 224 +37242 ./prep_dataset/ILSVRC2012_val_00024583.bin 224 224 +37243 ./prep_dataset/ILSVRC2012_val_00026214.bin 224 224 +37244 ./prep_dataset/ILSVRC2012_val_00018945.bin 224 224 +37245 ./prep_dataset/ILSVRC2012_val_00004691.bin 224 224 +37246 ./prep_dataset/ILSVRC2012_val_00027877.bin 224 224 +37247 ./prep_dataset/ILSVRC2012_val_00004527.bin 224 224 +37248 ./prep_dataset/ILSVRC2012_val_00001199.bin 224 224 +37249 ./prep_dataset/ILSVRC2012_val_00045988.bin 224 224 +37250 ./prep_dataset/ILSVRC2012_val_00014737.bin 224 224 +37251 ./prep_dataset/ILSVRC2012_val_00020848.bin 224 224 +37252 ./prep_dataset/ILSVRC2012_val_00017286.bin 224 224 +37253 ./prep_dataset/ILSVRC2012_val_00041785.bin 224 224 +37254 ./prep_dataset/ILSVRC2012_val_00007605.bin 224 224 +37255 ./prep_dataset/ILSVRC2012_val_00030965.bin 224 224 +37256 ./prep_dataset/ILSVRC2012_val_00048911.bin 224 224 +37257 ./prep_dataset/ILSVRC2012_val_00026806.bin 224 224 +37258 ./prep_dataset/ILSVRC2012_val_00031443.bin 224 224 +37259 ./prep_dataset/ILSVRC2012_val_00001694.bin 224 224 +37260 ./prep_dataset/ILSVRC2012_val_00045149.bin 224 224 +37261 ./prep_dataset/ILSVRC2012_val_00014236.bin 224 224 +37262 ./prep_dataset/ILSVRC2012_val_00028296.bin 224 224 +37263 ./prep_dataset/ILSVRC2012_val_00046131.bin 224 224 +37264 ./prep_dataset/ILSVRC2012_val_00026587.bin 224 224 +37265 ./prep_dataset/ILSVRC2012_val_00025825.bin 224 224 +37266 ./prep_dataset/ILSVRC2012_val_00043314.bin 224 224 +37267 ./prep_dataset/ILSVRC2012_val_00044981.bin 224 224 +37268 ./prep_dataset/ILSVRC2012_val_00042518.bin 224 224 +37269 ./prep_dataset/ILSVRC2012_val_00041713.bin 224 224 +37270 ./prep_dataset/ILSVRC2012_val_00036049.bin 224 224 +37271 ./prep_dataset/ILSVRC2012_val_00036653.bin 224 224 +37272 ./prep_dataset/ILSVRC2012_val_00046088.bin 224 224 +37273 ./prep_dataset/ILSVRC2012_val_00031914.bin 224 224 +37274 ./prep_dataset/ILSVRC2012_val_00000151.bin 224 224 +37275 ./prep_dataset/ILSVRC2012_val_00021088.bin 224 224 +37276 ./prep_dataset/ILSVRC2012_val_00014493.bin 224 224 +37277 ./prep_dataset/ILSVRC2012_val_00026327.bin 224 224 +37278 ./prep_dataset/ILSVRC2012_val_00013083.bin 224 224 +37279 ./prep_dataset/ILSVRC2012_val_00011251.bin 224 224 +37280 ./prep_dataset/ILSVRC2012_val_00017136.bin 224 224 +37281 ./prep_dataset/ILSVRC2012_val_00002210.bin 224 224 +37282 ./prep_dataset/ILSVRC2012_val_00031333.bin 224 224 +37283 ./prep_dataset/ILSVRC2012_val_00034357.bin 224 224 +37284 ./prep_dataset/ILSVRC2012_val_00001633.bin 224 224 +37285 ./prep_dataset/ILSVRC2012_val_00040046.bin 224 224 +37286 ./prep_dataset/ILSVRC2012_val_00023120.bin 224 224 +37287 ./prep_dataset/ILSVRC2012_val_00014948.bin 224 224 +37288 ./prep_dataset/ILSVRC2012_val_00042931.bin 224 224 +37289 ./prep_dataset/ILSVRC2012_val_00003646.bin 224 224 +37290 ./prep_dataset/ILSVRC2012_val_00001850.bin 224 224 +37291 ./prep_dataset/ILSVRC2012_val_00019459.bin 224 224 +37292 ./prep_dataset/ILSVRC2012_val_00039100.bin 224 224 +37293 ./prep_dataset/ILSVRC2012_val_00000216.bin 224 224 +37294 ./prep_dataset/ILSVRC2012_val_00044428.bin 224 224 +37295 ./prep_dataset/ILSVRC2012_val_00016134.bin 224 224 +37296 ./prep_dataset/ILSVRC2012_val_00005551.bin 224 224 +37297 ./prep_dataset/ILSVRC2012_val_00019175.bin 224 224 +37298 ./prep_dataset/ILSVRC2012_val_00038334.bin 224 224 +37299 ./prep_dataset/ILSVRC2012_val_00043584.bin 224 224 +37300 ./prep_dataset/ILSVRC2012_val_00001902.bin 224 224 +37301 ./prep_dataset/ILSVRC2012_val_00011306.bin 224 224 +37302 ./prep_dataset/ILSVRC2012_val_00028100.bin 224 224 +37303 ./prep_dataset/ILSVRC2012_val_00005930.bin 224 224 +37304 ./prep_dataset/ILSVRC2012_val_00021302.bin 224 224 +37305 ./prep_dataset/ILSVRC2012_val_00013657.bin 224 224 +37306 ./prep_dataset/ILSVRC2012_val_00046778.bin 224 224 +37307 ./prep_dataset/ILSVRC2012_val_00047898.bin 224 224 +37308 ./prep_dataset/ILSVRC2012_val_00008154.bin 224 224 +37309 ./prep_dataset/ILSVRC2012_val_00025178.bin 224 224 +37310 ./prep_dataset/ILSVRC2012_val_00016901.bin 224 224 +37311 ./prep_dataset/ILSVRC2012_val_00049116.bin 224 224 +37312 ./prep_dataset/ILSVRC2012_val_00007379.bin 224 224 +37313 ./prep_dataset/ILSVRC2012_val_00019665.bin 224 224 +37314 ./prep_dataset/ILSVRC2012_val_00013110.bin 224 224 +37315 ./prep_dataset/ILSVRC2012_val_00029540.bin 224 224 +37316 ./prep_dataset/ILSVRC2012_val_00020037.bin 224 224 +37317 ./prep_dataset/ILSVRC2012_val_00032365.bin 224 224 +37318 ./prep_dataset/ILSVRC2012_val_00001910.bin 224 224 +37319 ./prep_dataset/ILSVRC2012_val_00019782.bin 224 224 +37320 ./prep_dataset/ILSVRC2012_val_00007999.bin 224 224 +37321 ./prep_dataset/ILSVRC2012_val_00016141.bin 224 224 +37322 ./prep_dataset/ILSVRC2012_val_00029338.bin 224 224 +37323 ./prep_dataset/ILSVRC2012_val_00003991.bin 224 224 +37324 ./prep_dataset/ILSVRC2012_val_00018523.bin 224 224 +37325 ./prep_dataset/ILSVRC2012_val_00003817.bin 224 224 +37326 ./prep_dataset/ILSVRC2012_val_00012836.bin 224 224 +37327 ./prep_dataset/ILSVRC2012_val_00025443.bin 224 224 +37328 ./prep_dataset/ILSVRC2012_val_00019583.bin 224 224 +37329 ./prep_dataset/ILSVRC2012_val_00015494.bin 224 224 +37330 ./prep_dataset/ILSVRC2012_val_00048819.bin 224 224 +37331 ./prep_dataset/ILSVRC2012_val_00012585.bin 224 224 +37332 ./prep_dataset/ILSVRC2012_val_00029655.bin 224 224 +37333 ./prep_dataset/ILSVRC2012_val_00024245.bin 224 224 +37334 ./prep_dataset/ILSVRC2012_val_00003009.bin 224 224 +37335 ./prep_dataset/ILSVRC2012_val_00037133.bin 224 224 +37336 ./prep_dataset/ILSVRC2012_val_00048313.bin 224 224 +37337 ./prep_dataset/ILSVRC2012_val_00045702.bin 224 224 +37338 ./prep_dataset/ILSVRC2012_val_00039027.bin 224 224 +37339 ./prep_dataset/ILSVRC2012_val_00043548.bin 224 224 +37340 ./prep_dataset/ILSVRC2012_val_00002689.bin 224 224 +37341 ./prep_dataset/ILSVRC2012_val_00045294.bin 224 224 +37342 ./prep_dataset/ILSVRC2012_val_00013949.bin 224 224 +37343 ./prep_dataset/ILSVRC2012_val_00049396.bin 224 224 +37344 ./prep_dataset/ILSVRC2012_val_00003747.bin 224 224 +37345 ./prep_dataset/ILSVRC2012_val_00024706.bin 224 224 +37346 ./prep_dataset/ILSVRC2012_val_00028643.bin 224 224 +37347 ./prep_dataset/ILSVRC2012_val_00028715.bin 224 224 +37348 ./prep_dataset/ILSVRC2012_val_00025014.bin 224 224 +37349 ./prep_dataset/ILSVRC2012_val_00044264.bin 224 224 +37350 ./prep_dataset/ILSVRC2012_val_00000408.bin 224 224 +37351 ./prep_dataset/ILSVRC2012_val_00001582.bin 224 224 +37352 ./prep_dataset/ILSVRC2012_val_00042338.bin 224 224 +37353 ./prep_dataset/ILSVRC2012_val_00047542.bin 224 224 +37354 ./prep_dataset/ILSVRC2012_val_00016873.bin 224 224 +37355 ./prep_dataset/ILSVRC2012_val_00026202.bin 224 224 +37356 ./prep_dataset/ILSVRC2012_val_00006898.bin 224 224 +37357 ./prep_dataset/ILSVRC2012_val_00015184.bin 224 224 +37358 ./prep_dataset/ILSVRC2012_val_00019242.bin 224 224 +37359 ./prep_dataset/ILSVRC2012_val_00017530.bin 224 224 +37360 ./prep_dataset/ILSVRC2012_val_00046104.bin 224 224 +37361 ./prep_dataset/ILSVRC2012_val_00007096.bin 224 224 +37362 ./prep_dataset/ILSVRC2012_val_00004951.bin 224 224 +37363 ./prep_dataset/ILSVRC2012_val_00006563.bin 224 224 +37364 ./prep_dataset/ILSVRC2012_val_00030811.bin 224 224 +37365 ./prep_dataset/ILSVRC2012_val_00022212.bin 224 224 +37366 ./prep_dataset/ILSVRC2012_val_00012368.bin 224 224 +37367 ./prep_dataset/ILSVRC2012_val_00035986.bin 224 224 +37368 ./prep_dataset/ILSVRC2012_val_00003384.bin 224 224 +37369 ./prep_dataset/ILSVRC2012_val_00018333.bin 224 224 +37370 ./prep_dataset/ILSVRC2012_val_00027610.bin 224 224 +37371 ./prep_dataset/ILSVRC2012_val_00047135.bin 224 224 +37372 ./prep_dataset/ILSVRC2012_val_00038273.bin 224 224 +37373 ./prep_dataset/ILSVRC2012_val_00023760.bin 224 224 +37374 ./prep_dataset/ILSVRC2012_val_00014261.bin 224 224 +37375 ./prep_dataset/ILSVRC2012_val_00014392.bin 224 224 +37376 ./prep_dataset/ILSVRC2012_val_00021040.bin 224 224 +37377 ./prep_dataset/ILSVRC2012_val_00047215.bin 224 224 +37378 ./prep_dataset/ILSVRC2012_val_00015610.bin 224 224 +37379 ./prep_dataset/ILSVRC2012_val_00047681.bin 224 224 +37380 ./prep_dataset/ILSVRC2012_val_00046618.bin 224 224 +37381 ./prep_dataset/ILSVRC2012_val_00044149.bin 224 224 +37382 ./prep_dataset/ILSVRC2012_val_00021921.bin 224 224 +37383 ./prep_dataset/ILSVRC2012_val_00045613.bin 224 224 +37384 ./prep_dataset/ILSVRC2012_val_00033215.bin 224 224 +37385 ./prep_dataset/ILSVRC2012_val_00014180.bin 224 224 +37386 ./prep_dataset/ILSVRC2012_val_00012305.bin 224 224 +37387 ./prep_dataset/ILSVRC2012_val_00042087.bin 224 224 +37388 ./prep_dataset/ILSVRC2012_val_00048651.bin 224 224 +37389 ./prep_dataset/ILSVRC2012_val_00031166.bin 224 224 +37390 ./prep_dataset/ILSVRC2012_val_00045340.bin 224 224 +37391 ./prep_dataset/ILSVRC2012_val_00035375.bin 224 224 +37392 ./prep_dataset/ILSVRC2012_val_00008936.bin 224 224 +37393 ./prep_dataset/ILSVRC2012_val_00030619.bin 224 224 +37394 ./prep_dataset/ILSVRC2012_val_00006100.bin 224 224 +37395 ./prep_dataset/ILSVRC2012_val_00025595.bin 224 224 +37396 ./prep_dataset/ILSVRC2012_val_00001264.bin 224 224 +37397 ./prep_dataset/ILSVRC2012_val_00020464.bin 224 224 +37398 ./prep_dataset/ILSVRC2012_val_00015551.bin 224 224 +37399 ./prep_dataset/ILSVRC2012_val_00024725.bin 224 224 +37400 ./prep_dataset/ILSVRC2012_val_00040192.bin 224 224 +37401 ./prep_dataset/ILSVRC2012_val_00022155.bin 224 224 +37402 ./prep_dataset/ILSVRC2012_val_00022283.bin 224 224 +37403 ./prep_dataset/ILSVRC2012_val_00017122.bin 224 224 +37404 ./prep_dataset/ILSVRC2012_val_00011908.bin 224 224 +37405 ./prep_dataset/ILSVRC2012_val_00022731.bin 224 224 +37406 ./prep_dataset/ILSVRC2012_val_00023202.bin 224 224 +37407 ./prep_dataset/ILSVRC2012_val_00022809.bin 224 224 +37408 ./prep_dataset/ILSVRC2012_val_00002631.bin 224 224 +37409 ./prep_dataset/ILSVRC2012_val_00022579.bin 224 224 +37410 ./prep_dataset/ILSVRC2012_val_00048976.bin 224 224 +37411 ./prep_dataset/ILSVRC2012_val_00030426.bin 224 224 +37412 ./prep_dataset/ILSVRC2012_val_00049144.bin 224 224 +37413 ./prep_dataset/ILSVRC2012_val_00041130.bin 224 224 +37414 ./prep_dataset/ILSVRC2012_val_00046964.bin 224 224 +37415 ./prep_dataset/ILSVRC2012_val_00034692.bin 224 224 +37416 ./prep_dataset/ILSVRC2012_val_00016687.bin 224 224 +37417 ./prep_dataset/ILSVRC2012_val_00014683.bin 224 224 +37418 ./prep_dataset/ILSVRC2012_val_00047841.bin 224 224 +37419 ./prep_dataset/ILSVRC2012_val_00007357.bin 224 224 +37420 ./prep_dataset/ILSVRC2012_val_00019012.bin 224 224 +37421 ./prep_dataset/ILSVRC2012_val_00020869.bin 224 224 +37422 ./prep_dataset/ILSVRC2012_val_00039919.bin 224 224 +37423 ./prep_dataset/ILSVRC2012_val_00004713.bin 224 224 +37424 ./prep_dataset/ILSVRC2012_val_00006482.bin 224 224 +37425 ./prep_dataset/ILSVRC2012_val_00040354.bin 224 224 +37426 ./prep_dataset/ILSVRC2012_val_00008643.bin 224 224 +37427 ./prep_dataset/ILSVRC2012_val_00007239.bin 224 224 +37428 ./prep_dataset/ILSVRC2012_val_00016233.bin 224 224 +37429 ./prep_dataset/ILSVRC2012_val_00001822.bin 224 224 +37430 ./prep_dataset/ILSVRC2012_val_00041262.bin 224 224 +37431 ./prep_dataset/ILSVRC2012_val_00033836.bin 224 224 +37432 ./prep_dataset/ILSVRC2012_val_00028566.bin 224 224 +37433 ./prep_dataset/ILSVRC2012_val_00030043.bin 224 224 +37434 ./prep_dataset/ILSVRC2012_val_00019828.bin 224 224 +37435 ./prep_dataset/ILSVRC2012_val_00021168.bin 224 224 +37436 ./prep_dataset/ILSVRC2012_val_00045638.bin 224 224 +37437 ./prep_dataset/ILSVRC2012_val_00016657.bin 224 224 +37438 ./prep_dataset/ILSVRC2012_val_00012968.bin 224 224 +37439 ./prep_dataset/ILSVRC2012_val_00003146.bin 224 224 +37440 ./prep_dataset/ILSVRC2012_val_00002289.bin 224 224 +37441 ./prep_dataset/ILSVRC2012_val_00031445.bin 224 224 +37442 ./prep_dataset/ILSVRC2012_val_00039222.bin 224 224 +37443 ./prep_dataset/ILSVRC2012_val_00005999.bin 224 224 +37444 ./prep_dataset/ILSVRC2012_val_00007815.bin 224 224 +37445 ./prep_dataset/ILSVRC2012_val_00036632.bin 224 224 +37446 ./prep_dataset/ILSVRC2012_val_00011088.bin 224 224 +37447 ./prep_dataset/ILSVRC2012_val_00001502.bin 224 224 +37448 ./prep_dataset/ILSVRC2012_val_00002412.bin 224 224 +37449 ./prep_dataset/ILSVRC2012_val_00014223.bin 224 224 +37450 ./prep_dataset/ILSVRC2012_val_00039140.bin 224 224 +37451 ./prep_dataset/ILSVRC2012_val_00049064.bin 224 224 +37452 ./prep_dataset/ILSVRC2012_val_00037312.bin 224 224 +37453 ./prep_dataset/ILSVRC2012_val_00011930.bin 224 224 +37454 ./prep_dataset/ILSVRC2012_val_00036940.bin 224 224 +37455 ./prep_dataset/ILSVRC2012_val_00040198.bin 224 224 +37456 ./prep_dataset/ILSVRC2012_val_00035886.bin 224 224 +37457 ./prep_dataset/ILSVRC2012_val_00000431.bin 224 224 +37458 ./prep_dataset/ILSVRC2012_val_00029548.bin 224 224 +37459 ./prep_dataset/ILSVRC2012_val_00019246.bin 224 224 +37460 ./prep_dataset/ILSVRC2012_val_00015435.bin 224 224 +37461 ./prep_dataset/ILSVRC2012_val_00000665.bin 224 224 +37462 ./prep_dataset/ILSVRC2012_val_00002165.bin 224 224 +37463 ./prep_dataset/ILSVRC2012_val_00035161.bin 224 224 +37464 ./prep_dataset/ILSVRC2012_val_00043398.bin 224 224 +37465 ./prep_dataset/ILSVRC2012_val_00015286.bin 224 224 +37466 ./prep_dataset/ILSVRC2012_val_00026380.bin 224 224 +37467 ./prep_dataset/ILSVRC2012_val_00040835.bin 224 224 +37468 ./prep_dataset/ILSVRC2012_val_00020007.bin 224 224 +37469 ./prep_dataset/ILSVRC2012_val_00034130.bin 224 224 +37470 ./prep_dataset/ILSVRC2012_val_00039879.bin 224 224 +37471 ./prep_dataset/ILSVRC2012_val_00018973.bin 224 224 +37472 ./prep_dataset/ILSVRC2012_val_00015148.bin 224 224 +37473 ./prep_dataset/ILSVRC2012_val_00044291.bin 224 224 +37474 ./prep_dataset/ILSVRC2012_val_00018743.bin 224 224 +37475 ./prep_dataset/ILSVRC2012_val_00041904.bin 224 224 +37476 ./prep_dataset/ILSVRC2012_val_00033263.bin 224 224 +37477 ./prep_dataset/ILSVRC2012_val_00029010.bin 224 224 +37478 ./prep_dataset/ILSVRC2012_val_00011768.bin 224 224 +37479 ./prep_dataset/ILSVRC2012_val_00021107.bin 224 224 +37480 ./prep_dataset/ILSVRC2012_val_00019562.bin 224 224 +37481 ./prep_dataset/ILSVRC2012_val_00047192.bin 224 224 +37482 ./prep_dataset/ILSVRC2012_val_00034410.bin 224 224 +37483 ./prep_dataset/ILSVRC2012_val_00016580.bin 224 224 +37484 ./prep_dataset/ILSVRC2012_val_00048618.bin 224 224 +37485 ./prep_dataset/ILSVRC2012_val_00007862.bin 224 224 +37486 ./prep_dataset/ILSVRC2012_val_00008945.bin 224 224 +37487 ./prep_dataset/ILSVRC2012_val_00007973.bin 224 224 +37488 ./prep_dataset/ILSVRC2012_val_00021800.bin 224 224 +37489 ./prep_dataset/ILSVRC2012_val_00039103.bin 224 224 +37490 ./prep_dataset/ILSVRC2012_val_00029694.bin 224 224 +37491 ./prep_dataset/ILSVRC2012_val_00015189.bin 224 224 +37492 ./prep_dataset/ILSVRC2012_val_00021338.bin 224 224 +37493 ./prep_dataset/ILSVRC2012_val_00030977.bin 224 224 +37494 ./prep_dataset/ILSVRC2012_val_00025064.bin 224 224 +37495 ./prep_dataset/ILSVRC2012_val_00035564.bin 224 224 +37496 ./prep_dataset/ILSVRC2012_val_00038337.bin 224 224 +37497 ./prep_dataset/ILSVRC2012_val_00005306.bin 224 224 +37498 ./prep_dataset/ILSVRC2012_val_00027251.bin 224 224 +37499 ./prep_dataset/ILSVRC2012_val_00017822.bin 224 224 +37500 ./prep_dataset/ILSVRC2012_val_00011197.bin 224 224 +37501 ./prep_dataset/ILSVRC2012_val_00049122.bin 224 224 +37502 ./prep_dataset/ILSVRC2012_val_00004751.bin 224 224 +37503 ./prep_dataset/ILSVRC2012_val_00013626.bin 224 224 +37504 ./prep_dataset/ILSVRC2012_val_00022037.bin 224 224 +37505 ./prep_dataset/ILSVRC2012_val_00042056.bin 224 224 +37506 ./prep_dataset/ILSVRC2012_val_00041696.bin 224 224 +37507 ./prep_dataset/ILSVRC2012_val_00037248.bin 224 224 +37508 ./prep_dataset/ILSVRC2012_val_00037895.bin 224 224 +37509 ./prep_dataset/ILSVRC2012_val_00034438.bin 224 224 +37510 ./prep_dataset/ILSVRC2012_val_00037310.bin 224 224 +37511 ./prep_dataset/ILSVRC2012_val_00041486.bin 224 224 +37512 ./prep_dataset/ILSVRC2012_val_00019191.bin 224 224 +37513 ./prep_dataset/ILSVRC2012_val_00041449.bin 224 224 +37514 ./prep_dataset/ILSVRC2012_val_00009100.bin 224 224 +37515 ./prep_dataset/ILSVRC2012_val_00049145.bin 224 224 +37516 ./prep_dataset/ILSVRC2012_val_00045554.bin 224 224 +37517 ./prep_dataset/ILSVRC2012_val_00048059.bin 224 224 +37518 ./prep_dataset/ILSVRC2012_val_00031191.bin 224 224 +37519 ./prep_dataset/ILSVRC2012_val_00029653.bin 224 224 +37520 ./prep_dataset/ILSVRC2012_val_00003883.bin 224 224 +37521 ./prep_dataset/ILSVRC2012_val_00042845.bin 224 224 +37522 ./prep_dataset/ILSVRC2012_val_00048646.bin 224 224 +37523 ./prep_dataset/ILSVRC2012_val_00047313.bin 224 224 +37524 ./prep_dataset/ILSVRC2012_val_00039410.bin 224 224 +37525 ./prep_dataset/ILSVRC2012_val_00005987.bin 224 224 +37526 ./prep_dataset/ILSVRC2012_val_00000489.bin 224 224 +37527 ./prep_dataset/ILSVRC2012_val_00019805.bin 224 224 +37528 ./prep_dataset/ILSVRC2012_val_00011725.bin 224 224 +37529 ./prep_dataset/ILSVRC2012_val_00042423.bin 224 224 +37530 ./prep_dataset/ILSVRC2012_val_00008123.bin 224 224 +37531 ./prep_dataset/ILSVRC2012_val_00014762.bin 224 224 +37532 ./prep_dataset/ILSVRC2012_val_00047667.bin 224 224 +37533 ./prep_dataset/ILSVRC2012_val_00016082.bin 224 224 +37534 ./prep_dataset/ILSVRC2012_val_00004175.bin 224 224 +37535 ./prep_dataset/ILSVRC2012_val_00041329.bin 224 224 +37536 ./prep_dataset/ILSVRC2012_val_00000892.bin 224 224 +37537 ./prep_dataset/ILSVRC2012_val_00012214.bin 224 224 +37538 ./prep_dataset/ILSVRC2012_val_00004221.bin 224 224 +37539 ./prep_dataset/ILSVRC2012_val_00049748.bin 224 224 +37540 ./prep_dataset/ILSVRC2012_val_00002335.bin 224 224 +37541 ./prep_dataset/ILSVRC2012_val_00011011.bin 224 224 +37542 ./prep_dataset/ILSVRC2012_val_00017117.bin 224 224 +37543 ./prep_dataset/ILSVRC2012_val_00032751.bin 224 224 +37544 ./prep_dataset/ILSVRC2012_val_00017814.bin 224 224 +37545 ./prep_dataset/ILSVRC2012_val_00017626.bin 224 224 +37546 ./prep_dataset/ILSVRC2012_val_00044872.bin 224 224 +37547 ./prep_dataset/ILSVRC2012_val_00001948.bin 224 224 +37548 ./prep_dataset/ILSVRC2012_val_00001806.bin 224 224 +37549 ./prep_dataset/ILSVRC2012_val_00030880.bin 224 224 +37550 ./prep_dataset/ILSVRC2012_val_00027958.bin 224 224 +37551 ./prep_dataset/ILSVRC2012_val_00026194.bin 224 224 +37552 ./prep_dataset/ILSVRC2012_val_00044078.bin 224 224 +37553 ./prep_dataset/ILSVRC2012_val_00036011.bin 224 224 +37554 ./prep_dataset/ILSVRC2012_val_00028482.bin 224 224 +37555 ./prep_dataset/ILSVRC2012_val_00049339.bin 224 224 +37556 ./prep_dataset/ILSVRC2012_val_00045028.bin 224 224 +37557 ./prep_dataset/ILSVRC2012_val_00035066.bin 224 224 +37558 ./prep_dataset/ILSVRC2012_val_00034073.bin 224 224 +37559 ./prep_dataset/ILSVRC2012_val_00022031.bin 224 224 +37560 ./prep_dataset/ILSVRC2012_val_00038420.bin 224 224 +37561 ./prep_dataset/ILSVRC2012_val_00010502.bin 224 224 +37562 ./prep_dataset/ILSVRC2012_val_00017829.bin 224 224 +37563 ./prep_dataset/ILSVRC2012_val_00004234.bin 224 224 +37564 ./prep_dataset/ILSVRC2012_val_00017675.bin 224 224 +37565 ./prep_dataset/ILSVRC2012_val_00004731.bin 224 224 +37566 ./prep_dataset/ILSVRC2012_val_00042386.bin 224 224 +37567 ./prep_dataset/ILSVRC2012_val_00012377.bin 224 224 +37568 ./prep_dataset/ILSVRC2012_val_00016532.bin 224 224 +37569 ./prep_dataset/ILSVRC2012_val_00034165.bin 224 224 +37570 ./prep_dataset/ILSVRC2012_val_00008584.bin 224 224 +37571 ./prep_dataset/ILSVRC2012_val_00005114.bin 224 224 +37572 ./prep_dataset/ILSVRC2012_val_00000164.bin 224 224 +37573 ./prep_dataset/ILSVRC2012_val_00016904.bin 224 224 +37574 ./prep_dataset/ILSVRC2012_val_00048206.bin 224 224 +37575 ./prep_dataset/ILSVRC2012_val_00049294.bin 224 224 +37576 ./prep_dataset/ILSVRC2012_val_00012051.bin 224 224 +37577 ./prep_dataset/ILSVRC2012_val_00022716.bin 224 224 +37578 ./prep_dataset/ILSVRC2012_val_00003523.bin 224 224 +37579 ./prep_dataset/ILSVRC2012_val_00009318.bin 224 224 +37580 ./prep_dataset/ILSVRC2012_val_00032032.bin 224 224 +37581 ./prep_dataset/ILSVRC2012_val_00005719.bin 224 224 +37582 ./prep_dataset/ILSVRC2012_val_00017909.bin 224 224 +37583 ./prep_dataset/ILSVRC2012_val_00043619.bin 224 224 +37584 ./prep_dataset/ILSVRC2012_val_00018947.bin 224 224 +37585 ./prep_dataset/ILSVRC2012_val_00006217.bin 224 224 +37586 ./prep_dataset/ILSVRC2012_val_00049069.bin 224 224 +37587 ./prep_dataset/ILSVRC2012_val_00046433.bin 224 224 +37588 ./prep_dataset/ILSVRC2012_val_00024677.bin 224 224 +37589 ./prep_dataset/ILSVRC2012_val_00006291.bin 224 224 +37590 ./prep_dataset/ILSVRC2012_val_00022331.bin 224 224 +37591 ./prep_dataset/ILSVRC2012_val_00024910.bin 224 224 +37592 ./prep_dataset/ILSVRC2012_val_00036769.bin 224 224 +37593 ./prep_dataset/ILSVRC2012_val_00037943.bin 224 224 +37594 ./prep_dataset/ILSVRC2012_val_00046588.bin 224 224 +37595 ./prep_dataset/ILSVRC2012_val_00038346.bin 224 224 +37596 ./prep_dataset/ILSVRC2012_val_00016373.bin 224 224 +37597 ./prep_dataset/ILSVRC2012_val_00044011.bin 224 224 +37598 ./prep_dataset/ILSVRC2012_val_00040253.bin 224 224 +37599 ./prep_dataset/ILSVRC2012_val_00033708.bin 224 224 +37600 ./prep_dataset/ILSVRC2012_val_00012308.bin 224 224 +37601 ./prep_dataset/ILSVRC2012_val_00049511.bin 224 224 +37602 ./prep_dataset/ILSVRC2012_val_00022898.bin 224 224 +37603 ./prep_dataset/ILSVRC2012_val_00046896.bin 224 224 +37604 ./prep_dataset/ILSVRC2012_val_00039188.bin 224 224 +37605 ./prep_dataset/ILSVRC2012_val_00038065.bin 224 224 +37606 ./prep_dataset/ILSVRC2012_val_00018044.bin 224 224 +37607 ./prep_dataset/ILSVRC2012_val_00016503.bin 224 224 +37608 ./prep_dataset/ILSVRC2012_val_00045981.bin 224 224 +37609 ./prep_dataset/ILSVRC2012_val_00010032.bin 224 224 +37610 ./prep_dataset/ILSVRC2012_val_00021231.bin 224 224 +37611 ./prep_dataset/ILSVRC2012_val_00026985.bin 224 224 +37612 ./prep_dataset/ILSVRC2012_val_00016023.bin 224 224 +37613 ./prep_dataset/ILSVRC2012_val_00045683.bin 224 224 +37614 ./prep_dataset/ILSVRC2012_val_00044664.bin 224 224 +37615 ./prep_dataset/ILSVRC2012_val_00032887.bin 224 224 +37616 ./prep_dataset/ILSVRC2012_val_00038586.bin 224 224 +37617 ./prep_dataset/ILSVRC2012_val_00013051.bin 224 224 +37618 ./prep_dataset/ILSVRC2012_val_00025891.bin 224 224 +37619 ./prep_dataset/ILSVRC2012_val_00030459.bin 224 224 +37620 ./prep_dataset/ILSVRC2012_val_00034919.bin 224 224 +37621 ./prep_dataset/ILSVRC2012_val_00002643.bin 224 224 +37622 ./prep_dataset/ILSVRC2012_val_00027846.bin 224 224 +37623 ./prep_dataset/ILSVRC2012_val_00032666.bin 224 224 +37624 ./prep_dataset/ILSVRC2012_val_00045743.bin 224 224 +37625 ./prep_dataset/ILSVRC2012_val_00017886.bin 224 224 +37626 ./prep_dataset/ILSVRC2012_val_00041839.bin 224 224 +37627 ./prep_dataset/ILSVRC2012_val_00024119.bin 224 224 +37628 ./prep_dataset/ILSVRC2012_val_00044279.bin 224 224 +37629 ./prep_dataset/ILSVRC2012_val_00013019.bin 224 224 +37630 ./prep_dataset/ILSVRC2012_val_00036574.bin 224 224 +37631 ./prep_dataset/ILSVRC2012_val_00016368.bin 224 224 +37632 ./prep_dataset/ILSVRC2012_val_00044989.bin 224 224 +37633 ./prep_dataset/ILSVRC2012_val_00000565.bin 224 224 +37634 ./prep_dataset/ILSVRC2012_val_00022726.bin 224 224 +37635 ./prep_dataset/ILSVRC2012_val_00014848.bin 224 224 +37636 ./prep_dataset/ILSVRC2012_val_00037386.bin 224 224 +37637 ./prep_dataset/ILSVRC2012_val_00016458.bin 224 224 +37638 ./prep_dataset/ILSVRC2012_val_00013521.bin 224 224 +37639 ./prep_dataset/ILSVRC2012_val_00035384.bin 224 224 +37640 ./prep_dataset/ILSVRC2012_val_00021295.bin 224 224 +37641 ./prep_dataset/ILSVRC2012_val_00038284.bin 224 224 +37642 ./prep_dataset/ILSVRC2012_val_00018439.bin 224 224 +37643 ./prep_dataset/ILSVRC2012_val_00005415.bin 224 224 +37644 ./prep_dataset/ILSVRC2012_val_00006609.bin 224 224 +37645 ./prep_dataset/ILSVRC2012_val_00000567.bin 224 224 +37646 ./prep_dataset/ILSVRC2012_val_00047320.bin 224 224 +37647 ./prep_dataset/ILSVRC2012_val_00001812.bin 224 224 +37648 ./prep_dataset/ILSVRC2012_val_00009773.bin 224 224 +37649 ./prep_dataset/ILSVRC2012_val_00004930.bin 224 224 +37650 ./prep_dataset/ILSVRC2012_val_00042957.bin 224 224 +37651 ./prep_dataset/ILSVRC2012_val_00045127.bin 224 224 +37652 ./prep_dataset/ILSVRC2012_val_00020501.bin 224 224 +37653 ./prep_dataset/ILSVRC2012_val_00046739.bin 224 224 +37654 ./prep_dataset/ILSVRC2012_val_00007656.bin 224 224 +37655 ./prep_dataset/ILSVRC2012_val_00023355.bin 224 224 +37656 ./prep_dataset/ILSVRC2012_val_00001435.bin 224 224 +37657 ./prep_dataset/ILSVRC2012_val_00021484.bin 224 224 +37658 ./prep_dataset/ILSVRC2012_val_00002944.bin 224 224 +37659 ./prep_dataset/ILSVRC2012_val_00032677.bin 224 224 +37660 ./prep_dataset/ILSVRC2012_val_00003021.bin 224 224 +37661 ./prep_dataset/ILSVRC2012_val_00026235.bin 224 224 +37662 ./prep_dataset/ILSVRC2012_val_00028824.bin 224 224 +37663 ./prep_dataset/ILSVRC2012_val_00020440.bin 224 224 +37664 ./prep_dataset/ILSVRC2012_val_00004764.bin 224 224 +37665 ./prep_dataset/ILSVRC2012_val_00039487.bin 224 224 +37666 ./prep_dataset/ILSVRC2012_val_00026580.bin 224 224 +37667 ./prep_dataset/ILSVRC2012_val_00040294.bin 224 224 +37668 ./prep_dataset/ILSVRC2012_val_00038853.bin 224 224 +37669 ./prep_dataset/ILSVRC2012_val_00033595.bin 224 224 +37670 ./prep_dataset/ILSVRC2012_val_00018670.bin 224 224 +37671 ./prep_dataset/ILSVRC2012_val_00023613.bin 224 224 +37672 ./prep_dataset/ILSVRC2012_val_00033613.bin 224 224 +37673 ./prep_dataset/ILSVRC2012_val_00016100.bin 224 224 +37674 ./prep_dataset/ILSVRC2012_val_00032581.bin 224 224 +37675 ./prep_dataset/ILSVRC2012_val_00000766.bin 224 224 +37676 ./prep_dataset/ILSVRC2012_val_00039155.bin 224 224 +37677 ./prep_dataset/ILSVRC2012_val_00031285.bin 224 224 +37678 ./prep_dataset/ILSVRC2012_val_00023235.bin 224 224 +37679 ./prep_dataset/ILSVRC2012_val_00035341.bin 224 224 +37680 ./prep_dataset/ILSVRC2012_val_00002581.bin 224 224 +37681 ./prep_dataset/ILSVRC2012_val_00008538.bin 224 224 +37682 ./prep_dataset/ILSVRC2012_val_00000776.bin 224 224 +37683 ./prep_dataset/ILSVRC2012_val_00013325.bin 224 224 +37684 ./prep_dataset/ILSVRC2012_val_00011530.bin 224 224 +37685 ./prep_dataset/ILSVRC2012_val_00033492.bin 224 224 +37686 ./prep_dataset/ILSVRC2012_val_00041292.bin 224 224 +37687 ./prep_dataset/ILSVRC2012_val_00019893.bin 224 224 +37688 ./prep_dataset/ILSVRC2012_val_00032017.bin 224 224 +37689 ./prep_dataset/ILSVRC2012_val_00033431.bin 224 224 +37690 ./prep_dataset/ILSVRC2012_val_00010421.bin 224 224 +37691 ./prep_dataset/ILSVRC2012_val_00032077.bin 224 224 +37692 ./prep_dataset/ILSVRC2012_val_00039439.bin 224 224 +37693 ./prep_dataset/ILSVRC2012_val_00019101.bin 224 224 +37694 ./prep_dataset/ILSVRC2012_val_00019940.bin 224 224 +37695 ./prep_dataset/ILSVRC2012_val_00013138.bin 224 224 +37696 ./prep_dataset/ILSVRC2012_val_00043405.bin 224 224 +37697 ./prep_dataset/ILSVRC2012_val_00023035.bin 224 224 +37698 ./prep_dataset/ILSVRC2012_val_00034111.bin 224 224 +37699 ./prep_dataset/ILSVRC2012_val_00034932.bin 224 224 +37700 ./prep_dataset/ILSVRC2012_val_00013463.bin 224 224 +37701 ./prep_dataset/ILSVRC2012_val_00038468.bin 224 224 +37702 ./prep_dataset/ILSVRC2012_val_00038447.bin 224 224 +37703 ./prep_dataset/ILSVRC2012_val_00024737.bin 224 224 +37704 ./prep_dataset/ILSVRC2012_val_00044607.bin 224 224 +37705 ./prep_dataset/ILSVRC2012_val_00046337.bin 224 224 +37706 ./prep_dataset/ILSVRC2012_val_00022683.bin 224 224 +37707 ./prep_dataset/ILSVRC2012_val_00021664.bin 224 224 +37708 ./prep_dataset/ILSVRC2012_val_00023107.bin 224 224 +37709 ./prep_dataset/ILSVRC2012_val_00012752.bin 224 224 +37710 ./prep_dataset/ILSVRC2012_val_00047795.bin 224 224 +37711 ./prep_dataset/ILSVRC2012_val_00036054.bin 224 224 +37712 ./prep_dataset/ILSVRC2012_val_00044130.bin 224 224 +37713 ./prep_dataset/ILSVRC2012_val_00004405.bin 224 224 +37714 ./prep_dataset/ILSVRC2012_val_00042100.bin 224 224 +37715 ./prep_dataset/ILSVRC2012_val_00004922.bin 224 224 +37716 ./prep_dataset/ILSVRC2012_val_00026096.bin 224 224 +37717 ./prep_dataset/ILSVRC2012_val_00044551.bin 224 224 +37718 ./prep_dataset/ILSVRC2012_val_00017858.bin 224 224 +37719 ./prep_dataset/ILSVRC2012_val_00027691.bin 224 224 +37720 ./prep_dataset/ILSVRC2012_val_00028690.bin 224 224 +37721 ./prep_dataset/ILSVRC2012_val_00039580.bin 224 224 +37722 ./prep_dataset/ILSVRC2012_val_00005299.bin 224 224 +37723 ./prep_dataset/ILSVRC2012_val_00036059.bin 224 224 +37724 ./prep_dataset/ILSVRC2012_val_00034295.bin 224 224 +37725 ./prep_dataset/ILSVRC2012_val_00042827.bin 224 224 +37726 ./prep_dataset/ILSVRC2012_val_00048101.bin 224 224 +37727 ./prep_dataset/ILSVRC2012_val_00045100.bin 224 224 +37728 ./prep_dataset/ILSVRC2012_val_00029576.bin 224 224 +37729 ./prep_dataset/ILSVRC2012_val_00013532.bin 224 224 +37730 ./prep_dataset/ILSVRC2012_val_00017339.bin 224 224 +37731 ./prep_dataset/ILSVRC2012_val_00035509.bin 224 224 +37732 ./prep_dataset/ILSVRC2012_val_00025440.bin 224 224 +37733 ./prep_dataset/ILSVRC2012_val_00002009.bin 224 224 +37734 ./prep_dataset/ILSVRC2012_val_00022164.bin 224 224 +37735 ./prep_dataset/ILSVRC2012_val_00042889.bin 224 224 +37736 ./prep_dataset/ILSVRC2012_val_00044599.bin 224 224 +37737 ./prep_dataset/ILSVRC2012_val_00047574.bin 224 224 +37738 ./prep_dataset/ILSVRC2012_val_00020616.bin 224 224 +37739 ./prep_dataset/ILSVRC2012_val_00037941.bin 224 224 +37740 ./prep_dataset/ILSVRC2012_val_00044125.bin 224 224 +37741 ./prep_dataset/ILSVRC2012_val_00041201.bin 224 224 +37742 ./prep_dataset/ILSVRC2012_val_00034185.bin 224 224 +37743 ./prep_dataset/ILSVRC2012_val_00044088.bin 224 224 +37744 ./prep_dataset/ILSVRC2012_val_00023590.bin 224 224 +37745 ./prep_dataset/ILSVRC2012_val_00013971.bin 224 224 +37746 ./prep_dataset/ILSVRC2012_val_00005973.bin 224 224 +37747 ./prep_dataset/ILSVRC2012_val_00018422.bin 224 224 +37748 ./prep_dataset/ILSVRC2012_val_00010493.bin 224 224 +37749 ./prep_dataset/ILSVRC2012_val_00021469.bin 224 224 +37750 ./prep_dataset/ILSVRC2012_val_00043045.bin 224 224 +37751 ./prep_dataset/ILSVRC2012_val_00049999.bin 224 224 +37752 ./prep_dataset/ILSVRC2012_val_00037016.bin 224 224 +37753 ./prep_dataset/ILSVRC2012_val_00039471.bin 224 224 +37754 ./prep_dataset/ILSVRC2012_val_00004766.bin 224 224 +37755 ./prep_dataset/ILSVRC2012_val_00017093.bin 224 224 +37756 ./prep_dataset/ILSVRC2012_val_00033798.bin 224 224 +37757 ./prep_dataset/ILSVRC2012_val_00007844.bin 224 224 +37758 ./prep_dataset/ILSVRC2012_val_00014943.bin 224 224 +37759 ./prep_dataset/ILSVRC2012_val_00027070.bin 224 224 +37760 ./prep_dataset/ILSVRC2012_val_00041639.bin 224 224 +37761 ./prep_dataset/ILSVRC2012_val_00020742.bin 224 224 +37762 ./prep_dataset/ILSVRC2012_val_00005380.bin 224 224 +37763 ./prep_dataset/ILSVRC2012_val_00028728.bin 224 224 +37764 ./prep_dataset/ILSVRC2012_val_00030422.bin 224 224 +37765 ./prep_dataset/ILSVRC2012_val_00011322.bin 224 224 +37766 ./prep_dataset/ILSVRC2012_val_00016806.bin 224 224 +37767 ./prep_dataset/ILSVRC2012_val_00031257.bin 224 224 +37768 ./prep_dataset/ILSVRC2012_val_00010239.bin 224 224 +37769 ./prep_dataset/ILSVRC2012_val_00003932.bin 224 224 +37770 ./prep_dataset/ILSVRC2012_val_00041093.bin 224 224 +37771 ./prep_dataset/ILSVRC2012_val_00014332.bin 224 224 +37772 ./prep_dataset/ILSVRC2012_val_00038250.bin 224 224 +37773 ./prep_dataset/ILSVRC2012_val_00034248.bin 224 224 +37774 ./prep_dataset/ILSVRC2012_val_00033673.bin 224 224 +37775 ./prep_dataset/ILSVRC2012_val_00035146.bin 224 224 +37776 ./prep_dataset/ILSVRC2012_val_00046780.bin 224 224 +37777 ./prep_dataset/ILSVRC2012_val_00029220.bin 224 224 +37778 ./prep_dataset/ILSVRC2012_val_00047132.bin 224 224 +37779 ./prep_dataset/ILSVRC2012_val_00045915.bin 224 224 +37780 ./prep_dataset/ILSVRC2012_val_00037918.bin 224 224 +37781 ./prep_dataset/ILSVRC2012_val_00043082.bin 224 224 +37782 ./prep_dataset/ILSVRC2012_val_00040472.bin 224 224 +37783 ./prep_dataset/ILSVRC2012_val_00049007.bin 224 224 +37784 ./prep_dataset/ILSVRC2012_val_00041597.bin 224 224 +37785 ./prep_dataset/ILSVRC2012_val_00039744.bin 224 224 +37786 ./prep_dataset/ILSVRC2012_val_00044739.bin 224 224 +37787 ./prep_dataset/ILSVRC2012_val_00044332.bin 224 224 +37788 ./prep_dataset/ILSVRC2012_val_00034157.bin 224 224 +37789 ./prep_dataset/ILSVRC2012_val_00041889.bin 224 224 +37790 ./prep_dataset/ILSVRC2012_val_00030572.bin 224 224 +37791 ./prep_dataset/ILSVRC2012_val_00043176.bin 224 224 +37792 ./prep_dataset/ILSVRC2012_val_00036396.bin 224 224 +37793 ./prep_dataset/ILSVRC2012_val_00035557.bin 224 224 +37794 ./prep_dataset/ILSVRC2012_val_00004695.bin 224 224 +37795 ./prep_dataset/ILSVRC2012_val_00045855.bin 224 224 +37796 ./prep_dataset/ILSVRC2012_val_00018506.bin 224 224 +37797 ./prep_dataset/ILSVRC2012_val_00029925.bin 224 224 +37798 ./prep_dataset/ILSVRC2012_val_00007725.bin 224 224 +37799 ./prep_dataset/ILSVRC2012_val_00037842.bin 224 224 +37800 ./prep_dataset/ILSVRC2012_val_00000942.bin 224 224 +37801 ./prep_dataset/ILSVRC2012_val_00016381.bin 224 224 +37802 ./prep_dataset/ILSVRC2012_val_00030109.bin 224 224 +37803 ./prep_dataset/ILSVRC2012_val_00001706.bin 224 224 +37804 ./prep_dataset/ILSVRC2012_val_00025531.bin 224 224 +37805 ./prep_dataset/ILSVRC2012_val_00041912.bin 224 224 +37806 ./prep_dataset/ILSVRC2012_val_00039918.bin 224 224 +37807 ./prep_dataset/ILSVRC2012_val_00022406.bin 224 224 +37808 ./prep_dataset/ILSVRC2012_val_00003095.bin 224 224 +37809 ./prep_dataset/ILSVRC2012_val_00030683.bin 224 224 +37810 ./prep_dataset/ILSVRC2012_val_00023423.bin 224 224 +37811 ./prep_dataset/ILSVRC2012_val_00036144.bin 224 224 +37812 ./prep_dataset/ILSVRC2012_val_00026814.bin 224 224 +37813 ./prep_dataset/ILSVRC2012_val_00041374.bin 224 224 +37814 ./prep_dataset/ILSVRC2012_val_00000062.bin 224 224 +37815 ./prep_dataset/ILSVRC2012_val_00001028.bin 224 224 +37816 ./prep_dataset/ILSVRC2012_val_00020600.bin 224 224 +37817 ./prep_dataset/ILSVRC2012_val_00033352.bin 224 224 +37818 ./prep_dataset/ILSVRC2012_val_00000165.bin 224 224 +37819 ./prep_dataset/ILSVRC2012_val_00009209.bin 224 224 +37820 ./prep_dataset/ILSVRC2012_val_00030636.bin 224 224 +37821 ./prep_dataset/ILSVRC2012_val_00036919.bin 224 224 +37822 ./prep_dataset/ILSVRC2012_val_00023505.bin 224 224 +37823 ./prep_dataset/ILSVRC2012_val_00043228.bin 224 224 +37824 ./prep_dataset/ILSVRC2012_val_00005548.bin 224 224 +37825 ./prep_dataset/ILSVRC2012_val_00032262.bin 224 224 +37826 ./prep_dataset/ILSVRC2012_val_00046372.bin 224 224 +37827 ./prep_dataset/ILSVRC2012_val_00001890.bin 224 224 +37828 ./prep_dataset/ILSVRC2012_val_00028751.bin 224 224 +37829 ./prep_dataset/ILSVRC2012_val_00014772.bin 224 224 +37830 ./prep_dataset/ILSVRC2012_val_00036740.bin 224 224 +37831 ./prep_dataset/ILSVRC2012_val_00027473.bin 224 224 +37832 ./prep_dataset/ILSVRC2012_val_00033353.bin 224 224 +37833 ./prep_dataset/ILSVRC2012_val_00011408.bin 224 224 +37834 ./prep_dataset/ILSVRC2012_val_00044964.bin 224 224 +37835 ./prep_dataset/ILSVRC2012_val_00038615.bin 224 224 +37836 ./prep_dataset/ILSVRC2012_val_00024655.bin 224 224 +37837 ./prep_dataset/ILSVRC2012_val_00048806.bin 224 224 +37838 ./prep_dataset/ILSVRC2012_val_00002852.bin 224 224 +37839 ./prep_dataset/ILSVRC2012_val_00029074.bin 224 224 +37840 ./prep_dataset/ILSVRC2012_val_00031094.bin 224 224 +37841 ./prep_dataset/ILSVRC2012_val_00007461.bin 224 224 +37842 ./prep_dataset/ILSVRC2012_val_00029018.bin 224 224 +37843 ./prep_dataset/ILSVRC2012_val_00013016.bin 224 224 +37844 ./prep_dataset/ILSVRC2012_val_00014059.bin 224 224 +37845 ./prep_dataset/ILSVRC2012_val_00016590.bin 224 224 +37846 ./prep_dataset/ILSVRC2012_val_00009646.bin 224 224 +37847 ./prep_dataset/ILSVRC2012_val_00040648.bin 224 224 +37848 ./prep_dataset/ILSVRC2012_val_00013691.bin 224 224 +37849 ./prep_dataset/ILSVRC2012_val_00038305.bin 224 224 +37850 ./prep_dataset/ILSVRC2012_val_00013933.bin 224 224 +37851 ./prep_dataset/ILSVRC2012_val_00040205.bin 224 224 +37852 ./prep_dataset/ILSVRC2012_val_00008837.bin 224 224 +37853 ./prep_dataset/ILSVRC2012_val_00046744.bin 224 224 +37854 ./prep_dataset/ILSVRC2012_val_00048336.bin 224 224 +37855 ./prep_dataset/ILSVRC2012_val_00017024.bin 224 224 +37856 ./prep_dataset/ILSVRC2012_val_00026372.bin 224 224 +37857 ./prep_dataset/ILSVRC2012_val_00023147.bin 224 224 +37858 ./prep_dataset/ILSVRC2012_val_00011086.bin 224 224 +37859 ./prep_dataset/ILSVRC2012_val_00031140.bin 224 224 +37860 ./prep_dataset/ILSVRC2012_val_00043140.bin 224 224 +37861 ./prep_dataset/ILSVRC2012_val_00042635.bin 224 224 +37862 ./prep_dataset/ILSVRC2012_val_00004510.bin 224 224 +37863 ./prep_dataset/ILSVRC2012_val_00007292.bin 224 224 +37864 ./prep_dataset/ILSVRC2012_val_00044913.bin 224 224 +37865 ./prep_dataset/ILSVRC2012_val_00026243.bin 224 224 +37866 ./prep_dataset/ILSVRC2012_val_00043520.bin 224 224 +37867 ./prep_dataset/ILSVRC2012_val_00002633.bin 224 224 +37868 ./prep_dataset/ILSVRC2012_val_00034066.bin 224 224 +37869 ./prep_dataset/ILSVRC2012_val_00028037.bin 224 224 +37870 ./prep_dataset/ILSVRC2012_val_00009198.bin 224 224 +37871 ./prep_dataset/ILSVRC2012_val_00035390.bin 224 224 +37872 ./prep_dataset/ILSVRC2012_val_00036263.bin 224 224 +37873 ./prep_dataset/ILSVRC2012_val_00037374.bin 224 224 +37874 ./prep_dataset/ILSVRC2012_val_00013726.bin 224 224 +37875 ./prep_dataset/ILSVRC2012_val_00001426.bin 224 224 +37876 ./prep_dataset/ILSVRC2012_val_00042919.bin 224 224 +37877 ./prep_dataset/ILSVRC2012_val_00016331.bin 224 224 +37878 ./prep_dataset/ILSVRC2012_val_00048847.bin 224 224 +37879 ./prep_dataset/ILSVRC2012_val_00011825.bin 224 224 +37880 ./prep_dataset/ILSVRC2012_val_00047220.bin 224 224 +37881 ./prep_dataset/ILSVRC2012_val_00022813.bin 224 224 +37882 ./prep_dataset/ILSVRC2012_val_00027892.bin 224 224 +37883 ./prep_dataset/ILSVRC2012_val_00025194.bin 224 224 +37884 ./prep_dataset/ILSVRC2012_val_00000071.bin 224 224 +37885 ./prep_dataset/ILSVRC2012_val_00028561.bin 224 224 +37886 ./prep_dataset/ILSVRC2012_val_00000411.bin 224 224 +37887 ./prep_dataset/ILSVRC2012_val_00018997.bin 224 224 +37888 ./prep_dataset/ILSVRC2012_val_00035566.bin 224 224 +37889 ./prep_dataset/ILSVRC2012_val_00014680.bin 224 224 +37890 ./prep_dataset/ILSVRC2012_val_00032644.bin 224 224 +37891 ./prep_dataset/ILSVRC2012_val_00047809.bin 224 224 +37892 ./prep_dataset/ILSVRC2012_val_00017245.bin 224 224 +37893 ./prep_dataset/ILSVRC2012_val_00000093.bin 224 224 +37894 ./prep_dataset/ILSVRC2012_val_00000860.bin 224 224 +37895 ./prep_dataset/ILSVRC2012_val_00018384.bin 224 224 +37896 ./prep_dataset/ILSVRC2012_val_00037275.bin 224 224 +37897 ./prep_dataset/ILSVRC2012_val_00044159.bin 224 224 +37898 ./prep_dataset/ILSVRC2012_val_00032757.bin 224 224 +37899 ./prep_dataset/ILSVRC2012_val_00029978.bin 224 224 +37900 ./prep_dataset/ILSVRC2012_val_00040450.bin 224 224 +37901 ./prep_dataset/ILSVRC2012_val_00019846.bin 224 224 +37902 ./prep_dataset/ILSVRC2012_val_00039677.bin 224 224 +37903 ./prep_dataset/ILSVRC2012_val_00039429.bin 224 224 +37904 ./prep_dataset/ILSVRC2012_val_00044148.bin 224 224 +37905 ./prep_dataset/ILSVRC2012_val_00040102.bin 224 224 +37906 ./prep_dataset/ILSVRC2012_val_00038967.bin 224 224 +37907 ./prep_dataset/ILSVRC2012_val_00007316.bin 224 224 +37908 ./prep_dataset/ILSVRC2012_val_00002836.bin 224 224 +37909 ./prep_dataset/ILSVRC2012_val_00042946.bin 224 224 +37910 ./prep_dataset/ILSVRC2012_val_00002469.bin 224 224 +37911 ./prep_dataset/ILSVRC2012_val_00038092.bin 224 224 +37912 ./prep_dataset/ILSVRC2012_val_00028706.bin 224 224 +37913 ./prep_dataset/ILSVRC2012_val_00005657.bin 224 224 +37914 ./prep_dataset/ILSVRC2012_val_00032770.bin 224 224 +37915 ./prep_dataset/ILSVRC2012_val_00005319.bin 224 224 +37916 ./prep_dataset/ILSVRC2012_val_00025927.bin 224 224 +37917 ./prep_dataset/ILSVRC2012_val_00047189.bin 224 224 +37918 ./prep_dataset/ILSVRC2012_val_00008230.bin 224 224 +37919 ./prep_dataset/ILSVRC2012_val_00046510.bin 224 224 +37920 ./prep_dataset/ILSVRC2012_val_00036590.bin 224 224 +37921 ./prep_dataset/ILSVRC2012_val_00032126.bin 224 224 +37922 ./prep_dataset/ILSVRC2012_val_00043240.bin 224 224 +37923 ./prep_dataset/ILSVRC2012_val_00013574.bin 224 224 +37924 ./prep_dataset/ILSVRC2012_val_00035125.bin 224 224 +37925 ./prep_dataset/ILSVRC2012_val_00006819.bin 224 224 +37926 ./prep_dataset/ILSVRC2012_val_00009025.bin 224 224 +37927 ./prep_dataset/ILSVRC2012_val_00022470.bin 224 224 +37928 ./prep_dataset/ILSVRC2012_val_00046654.bin 224 224 +37929 ./prep_dataset/ILSVRC2012_val_00024047.bin 224 224 +37930 ./prep_dataset/ILSVRC2012_val_00039114.bin 224 224 +37931 ./prep_dataset/ILSVRC2012_val_00034581.bin 224 224 +37932 ./prep_dataset/ILSVRC2012_val_00029198.bin 224 224 +37933 ./prep_dataset/ILSVRC2012_val_00027930.bin 224 224 +37934 ./prep_dataset/ILSVRC2012_val_00045589.bin 224 224 +37935 ./prep_dataset/ILSVRC2012_val_00040127.bin 224 224 +37936 ./prep_dataset/ILSVRC2012_val_00025456.bin 224 224 +37937 ./prep_dataset/ILSVRC2012_val_00012533.bin 224 224 +37938 ./prep_dataset/ILSVRC2012_val_00016277.bin 224 224 +37939 ./prep_dataset/ILSVRC2012_val_00006323.bin 224 224 +37940 ./prep_dataset/ILSVRC2012_val_00034236.bin 224 224 +37941 ./prep_dataset/ILSVRC2012_val_00047242.bin 224 224 +37942 ./prep_dataset/ILSVRC2012_val_00015374.bin 224 224 +37943 ./prep_dataset/ILSVRC2012_val_00044086.bin 224 224 +37944 ./prep_dataset/ILSVRC2012_val_00038616.bin 224 224 +37945 ./prep_dataset/ILSVRC2012_val_00037008.bin 224 224 +37946 ./prep_dataset/ILSVRC2012_val_00038368.bin 224 224 +37947 ./prep_dataset/ILSVRC2012_val_00046109.bin 224 224 +37948 ./prep_dataset/ILSVRC2012_val_00003675.bin 224 224 +37949 ./prep_dataset/ILSVRC2012_val_00017018.bin 224 224 +37950 ./prep_dataset/ILSVRC2012_val_00017943.bin 224 224 +37951 ./prep_dataset/ILSVRC2012_val_00020737.bin 224 224 +37952 ./prep_dataset/ILSVRC2012_val_00047307.bin 224 224 +37953 ./prep_dataset/ILSVRC2012_val_00008572.bin 224 224 +37954 ./prep_dataset/ILSVRC2012_val_00048876.bin 224 224 +37955 ./prep_dataset/ILSVRC2012_val_00021889.bin 224 224 +37956 ./prep_dataset/ILSVRC2012_val_00024194.bin 224 224 +37957 ./prep_dataset/ILSVRC2012_val_00023801.bin 224 224 +37958 ./prep_dataset/ILSVRC2012_val_00032304.bin 224 224 +37959 ./prep_dataset/ILSVRC2012_val_00009191.bin 224 224 +37960 ./prep_dataset/ILSVRC2012_val_00021080.bin 224 224 +37961 ./prep_dataset/ILSVRC2012_val_00022591.bin 224 224 +37962 ./prep_dataset/ILSVRC2012_val_00025933.bin 224 224 +37963 ./prep_dataset/ILSVRC2012_val_00021736.bin 224 224 +37964 ./prep_dataset/ILSVRC2012_val_00035602.bin 224 224 +37965 ./prep_dataset/ILSVRC2012_val_00045897.bin 224 224 +37966 ./prep_dataset/ILSVRC2012_val_00006700.bin 224 224 +37967 ./prep_dataset/ILSVRC2012_val_00014100.bin 224 224 +37968 ./prep_dataset/ILSVRC2012_val_00030134.bin 224 224 +37969 ./prep_dataset/ILSVRC2012_val_00049734.bin 224 224 +37970 ./prep_dataset/ILSVRC2012_val_00009777.bin 224 224 +37971 ./prep_dataset/ILSVRC2012_val_00003207.bin 224 224 +37972 ./prep_dataset/ILSVRC2012_val_00031416.bin 224 224 +37973 ./prep_dataset/ILSVRC2012_val_00014975.bin 224 224 +37974 ./prep_dataset/ILSVRC2012_val_00014192.bin 224 224 +37975 ./prep_dataset/ILSVRC2012_val_00041945.bin 224 224 +37976 ./prep_dataset/ILSVRC2012_val_00029598.bin 224 224 +37977 ./prep_dataset/ILSVRC2012_val_00038625.bin 224 224 +37978 ./prep_dataset/ILSVRC2012_val_00031058.bin 224 224 +37979 ./prep_dataset/ILSVRC2012_val_00040804.bin 224 224 +37980 ./prep_dataset/ILSVRC2012_val_00047279.bin 224 224 +37981 ./prep_dataset/ILSVRC2012_val_00035127.bin 224 224 +37982 ./prep_dataset/ILSVRC2012_val_00039524.bin 224 224 +37983 ./prep_dataset/ILSVRC2012_val_00039398.bin 224 224 +37984 ./prep_dataset/ILSVRC2012_val_00022124.bin 224 224 +37985 ./prep_dataset/ILSVRC2012_val_00008265.bin 224 224 +37986 ./prep_dataset/ILSVRC2012_val_00024174.bin 224 224 +37987 ./prep_dataset/ILSVRC2012_val_00045528.bin 224 224 +37988 ./prep_dataset/ILSVRC2012_val_00044944.bin 224 224 +37989 ./prep_dataset/ILSVRC2012_val_00004371.bin 224 224 +37990 ./prep_dataset/ILSVRC2012_val_00039801.bin 224 224 +37991 ./prep_dataset/ILSVRC2012_val_00041700.bin 224 224 +37992 ./prep_dataset/ILSVRC2012_val_00049622.bin 224 224 +37993 ./prep_dataset/ILSVRC2012_val_00003790.bin 224 224 +37994 ./prep_dataset/ILSVRC2012_val_00034569.bin 224 224 +37995 ./prep_dataset/ILSVRC2012_val_00013853.bin 224 224 +37996 ./prep_dataset/ILSVRC2012_val_00027460.bin 224 224 +37997 ./prep_dataset/ILSVRC2012_val_00025073.bin 224 224 +37998 ./prep_dataset/ILSVRC2012_val_00043319.bin 224 224 +37999 ./prep_dataset/ILSVRC2012_val_00025849.bin 224 224 +38000 ./prep_dataset/ILSVRC2012_val_00048155.bin 224 224 +38001 ./prep_dataset/ILSVRC2012_val_00002589.bin 224 224 +38002 ./prep_dataset/ILSVRC2012_val_00013575.bin 224 224 +38003 ./prep_dataset/ILSVRC2012_val_00011974.bin 224 224 +38004 ./prep_dataset/ILSVRC2012_val_00035802.bin 224 224 +38005 ./prep_dataset/ILSVRC2012_val_00028844.bin 224 224 +38006 ./prep_dataset/ILSVRC2012_val_00018684.bin 224 224 +38007 ./prep_dataset/ILSVRC2012_val_00026063.bin 224 224 +38008 ./prep_dataset/ILSVRC2012_val_00002842.bin 224 224 +38009 ./prep_dataset/ILSVRC2012_val_00015147.bin 224 224 +38010 ./prep_dataset/ILSVRC2012_val_00047978.bin 224 224 +38011 ./prep_dataset/ILSVRC2012_val_00005531.bin 224 224 +38012 ./prep_dataset/ILSVRC2012_val_00048458.bin 224 224 +38013 ./prep_dataset/ILSVRC2012_val_00020220.bin 224 224 +38014 ./prep_dataset/ILSVRC2012_val_00021421.bin 224 224 +38015 ./prep_dataset/ILSVRC2012_val_00046851.bin 224 224 +38016 ./prep_dataset/ILSVRC2012_val_00022357.bin 224 224 +38017 ./prep_dataset/ILSVRC2012_val_00027961.bin 224 224 +38018 ./prep_dataset/ILSVRC2012_val_00034947.bin 224 224 +38019 ./prep_dataset/ILSVRC2012_val_00022889.bin 224 224 +38020 ./prep_dataset/ILSVRC2012_val_00007450.bin 224 224 +38021 ./prep_dataset/ILSVRC2012_val_00005332.bin 224 224 +38022 ./prep_dataset/ILSVRC2012_val_00045247.bin 224 224 +38023 ./prep_dataset/ILSVRC2012_val_00042560.bin 224 224 +38024 ./prep_dataset/ILSVRC2012_val_00047765.bin 224 224 +38025 ./prep_dataset/ILSVRC2012_val_00014592.bin 224 224 +38026 ./prep_dataset/ILSVRC2012_val_00046542.bin 224 224 +38027 ./prep_dataset/ILSVRC2012_val_00040939.bin 224 224 +38028 ./prep_dataset/ILSVRC2012_val_00043954.bin 224 224 +38029 ./prep_dataset/ILSVRC2012_val_00004757.bin 224 224 +38030 ./prep_dataset/ILSVRC2012_val_00033029.bin 224 224 +38031 ./prep_dataset/ILSVRC2012_val_00021619.bin 224 224 +38032 ./prep_dataset/ILSVRC2012_val_00044729.bin 224 224 +38033 ./prep_dataset/ILSVRC2012_val_00042145.bin 224 224 +38034 ./prep_dataset/ILSVRC2012_val_00041628.bin 224 224 +38035 ./prep_dataset/ILSVRC2012_val_00013396.bin 224 224 +38036 ./prep_dataset/ILSVRC2012_val_00048158.bin 224 224 +38037 ./prep_dataset/ILSVRC2012_val_00033675.bin 224 224 +38038 ./prep_dataset/ILSVRC2012_val_00009872.bin 224 224 +38039 ./prep_dataset/ILSVRC2012_val_00008774.bin 224 224 +38040 ./prep_dataset/ILSVRC2012_val_00011804.bin 224 224 +38041 ./prep_dataset/ILSVRC2012_val_00045453.bin 224 224 +38042 ./prep_dataset/ILSVRC2012_val_00022326.bin 224 224 +38043 ./prep_dataset/ILSVRC2012_val_00000770.bin 224 224 +38044 ./prep_dataset/ILSVRC2012_val_00001718.bin 224 224 +38045 ./prep_dataset/ILSVRC2012_val_00004036.bin 224 224 +38046 ./prep_dataset/ILSVRC2012_val_00001433.bin 224 224 +38047 ./prep_dataset/ILSVRC2012_val_00031163.bin 224 224 +38048 ./prep_dataset/ILSVRC2012_val_00030056.bin 224 224 +38049 ./prep_dataset/ILSVRC2012_val_00008995.bin 224 224 +38050 ./prep_dataset/ILSVRC2012_val_00049041.bin 224 224 +38051 ./prep_dataset/ILSVRC2012_val_00006777.bin 224 224 +38052 ./prep_dataset/ILSVRC2012_val_00040808.bin 224 224 +38053 ./prep_dataset/ILSVRC2012_val_00018888.bin 224 224 +38054 ./prep_dataset/ILSVRC2012_val_00049324.bin 224 224 +38055 ./prep_dataset/ILSVRC2012_val_00025683.bin 224 224 +38056 ./prep_dataset/ILSVRC2012_val_00014406.bin 224 224 +38057 ./prep_dataset/ILSVRC2012_val_00021278.bin 224 224 +38058 ./prep_dataset/ILSVRC2012_val_00049270.bin 224 224 +38059 ./prep_dataset/ILSVRC2012_val_00030069.bin 224 224 +38060 ./prep_dataset/ILSVRC2012_val_00031078.bin 224 224 +38061 ./prep_dataset/ILSVRC2012_val_00045530.bin 224 224 +38062 ./prep_dataset/ILSVRC2012_val_00006141.bin 224 224 +38063 ./prep_dataset/ILSVRC2012_val_00045872.bin 224 224 +38064 ./prep_dataset/ILSVRC2012_val_00036749.bin 224 224 +38065 ./prep_dataset/ILSVRC2012_val_00024514.bin 224 224 +38066 ./prep_dataset/ILSVRC2012_val_00043627.bin 224 224 +38067 ./prep_dataset/ILSVRC2012_val_00028006.bin 224 224 +38068 ./prep_dataset/ILSVRC2012_val_00040837.bin 224 224 +38069 ./prep_dataset/ILSVRC2012_val_00028027.bin 224 224 +38070 ./prep_dataset/ILSVRC2012_val_00014623.bin 224 224 +38071 ./prep_dataset/ILSVRC2012_val_00019651.bin 224 224 +38072 ./prep_dataset/ILSVRC2012_val_00030500.bin 224 224 +38073 ./prep_dataset/ILSVRC2012_val_00034320.bin 224 224 +38074 ./prep_dataset/ILSVRC2012_val_00047159.bin 224 224 +38075 ./prep_dataset/ILSVRC2012_val_00006407.bin 224 224 +38076 ./prep_dataset/ILSVRC2012_val_00012578.bin 224 224 +38077 ./prep_dataset/ILSVRC2012_val_00034591.bin 224 224 +38078 ./prep_dataset/ILSVRC2012_val_00039791.bin 224 224 +38079 ./prep_dataset/ILSVRC2012_val_00001221.bin 224 224 +38080 ./prep_dataset/ILSVRC2012_val_00041085.bin 224 224 +38081 ./prep_dataset/ILSVRC2012_val_00000304.bin 224 224 +38082 ./prep_dataset/ILSVRC2012_val_00035061.bin 224 224 +38083 ./prep_dataset/ILSVRC2012_val_00040582.bin 224 224 +38084 ./prep_dataset/ILSVRC2012_val_00035708.bin 224 224 +38085 ./prep_dataset/ILSVRC2012_val_00047356.bin 224 224 +38086 ./prep_dataset/ILSVRC2012_val_00015416.bin 224 224 +38087 ./prep_dataset/ILSVRC2012_val_00038932.bin 224 224 +38088 ./prep_dataset/ILSVRC2012_val_00036664.bin 224 224 +38089 ./prep_dataset/ILSVRC2012_val_00047913.bin 224 224 +38090 ./prep_dataset/ILSVRC2012_val_00001752.bin 224 224 +38091 ./prep_dataset/ILSVRC2012_val_00031342.bin 224 224 +38092 ./prep_dataset/ILSVRC2012_val_00042706.bin 224 224 +38093 ./prep_dataset/ILSVRC2012_val_00036041.bin 224 224 +38094 ./prep_dataset/ILSVRC2012_val_00025869.bin 224 224 +38095 ./prep_dataset/ILSVRC2012_val_00044342.bin 224 224 +38096 ./prep_dataset/ILSVRC2012_val_00025631.bin 224 224 +38097 ./prep_dataset/ILSVRC2012_val_00035324.bin 224 224 +38098 ./prep_dataset/ILSVRC2012_val_00001287.bin 224 224 +38099 ./prep_dataset/ILSVRC2012_val_00016828.bin 224 224 +38100 ./prep_dataset/ILSVRC2012_val_00008358.bin 224 224 +38101 ./prep_dataset/ILSVRC2012_val_00048474.bin 224 224 +38102 ./prep_dataset/ILSVRC2012_val_00014754.bin 224 224 +38103 ./prep_dataset/ILSVRC2012_val_00008562.bin 224 224 +38104 ./prep_dataset/ILSVRC2012_val_00015532.bin 224 224 +38105 ./prep_dataset/ILSVRC2012_val_00016174.bin 224 224 +38106 ./prep_dataset/ILSVRC2012_val_00043444.bin 224 224 +38107 ./prep_dataset/ILSVRC2012_val_00011201.bin 224 224 +38108 ./prep_dataset/ILSVRC2012_val_00013925.bin 224 224 +38109 ./prep_dataset/ILSVRC2012_val_00011291.bin 224 224 +38110 ./prep_dataset/ILSVRC2012_val_00001011.bin 224 224 +38111 ./prep_dataset/ILSVRC2012_val_00017520.bin 224 224 +38112 ./prep_dataset/ILSVRC2012_val_00005947.bin 224 224 +38113 ./prep_dataset/ILSVRC2012_val_00039765.bin 224 224 +38114 ./prep_dataset/ILSVRC2012_val_00002615.bin 224 224 +38115 ./prep_dataset/ILSVRC2012_val_00019085.bin 224 224 +38116 ./prep_dataset/ILSVRC2012_val_00020330.bin 224 224 +38117 ./prep_dataset/ILSVRC2012_val_00036211.bin 224 224 +38118 ./prep_dataset/ILSVRC2012_val_00012298.bin 224 224 +38119 ./prep_dataset/ILSVRC2012_val_00018470.bin 224 224 +38120 ./prep_dataset/ILSVRC2012_val_00047095.bin 224 224 +38121 ./prep_dataset/ILSVRC2012_val_00003487.bin 224 224 +38122 ./prep_dataset/ILSVRC2012_val_00001416.bin 224 224 +38123 ./prep_dataset/ILSVRC2012_val_00009486.bin 224 224 +38124 ./prep_dataset/ILSVRC2012_val_00033931.bin 224 224 +38125 ./prep_dataset/ILSVRC2012_val_00017042.bin 224 224 +38126 ./prep_dataset/ILSVRC2012_val_00042913.bin 224 224 +38127 ./prep_dataset/ILSVRC2012_val_00046398.bin 224 224 +38128 ./prep_dataset/ILSVRC2012_val_00007650.bin 224 224 +38129 ./prep_dataset/ILSVRC2012_val_00013357.bin 224 224 +38130 ./prep_dataset/ILSVRC2012_val_00042974.bin 224 224 +38131 ./prep_dataset/ILSVRC2012_val_00039411.bin 224 224 +38132 ./prep_dataset/ILSVRC2012_val_00047417.bin 224 224 +38133 ./prep_dataset/ILSVRC2012_val_00006485.bin 224 224 +38134 ./prep_dataset/ILSVRC2012_val_00000225.bin 224 224 +38135 ./prep_dataset/ILSVRC2012_val_00017056.bin 224 224 +38136 ./prep_dataset/ILSVRC2012_val_00030780.bin 224 224 +38137 ./prep_dataset/ILSVRC2012_val_00043220.bin 224 224 +38138 ./prep_dataset/ILSVRC2012_val_00002740.bin 224 224 +38139 ./prep_dataset/ILSVRC2012_val_00026022.bin 224 224 +38140 ./prep_dataset/ILSVRC2012_val_00015248.bin 224 224 +38141 ./prep_dataset/ILSVRC2012_val_00032012.bin 224 224 +38142 ./prep_dataset/ILSVRC2012_val_00029510.bin 224 224 +38143 ./prep_dataset/ILSVRC2012_val_00013812.bin 224 224 +38144 ./prep_dataset/ILSVRC2012_val_00028362.bin 224 224 +38145 ./prep_dataset/ILSVRC2012_val_00047504.bin 224 224 +38146 ./prep_dataset/ILSVRC2012_val_00024748.bin 224 224 +38147 ./prep_dataset/ILSVRC2012_val_00039443.bin 224 224 +38148 ./prep_dataset/ILSVRC2012_val_00019349.bin 224 224 +38149 ./prep_dataset/ILSVRC2012_val_00035234.bin 224 224 +38150 ./prep_dataset/ILSVRC2012_val_00011250.bin 224 224 +38151 ./prep_dataset/ILSVRC2012_val_00034256.bin 224 224 +38152 ./prep_dataset/ILSVRC2012_val_00036071.bin 224 224 +38153 ./prep_dataset/ILSVRC2012_val_00000486.bin 224 224 +38154 ./prep_dataset/ILSVRC2012_val_00016177.bin 224 224 +38155 ./prep_dataset/ILSVRC2012_val_00035442.bin 224 224 +38156 ./prep_dataset/ILSVRC2012_val_00017685.bin 224 224 +38157 ./prep_dataset/ILSVRC2012_val_00027007.bin 224 224 +38158 ./prep_dataset/ILSVRC2012_val_00031953.bin 224 224 +38159 ./prep_dataset/ILSVRC2012_val_00018926.bin 224 224 +38160 ./prep_dataset/ILSVRC2012_val_00022501.bin 224 224 +38161 ./prep_dataset/ILSVRC2012_val_00044312.bin 224 224 +38162 ./prep_dataset/ILSVRC2012_val_00005794.bin 224 224 +38163 ./prep_dataset/ILSVRC2012_val_00003036.bin 224 224 +38164 ./prep_dataset/ILSVRC2012_val_00003014.bin 224 224 +38165 ./prep_dataset/ILSVRC2012_val_00025451.bin 224 224 +38166 ./prep_dataset/ILSVRC2012_val_00005220.bin 224 224 +38167 ./prep_dataset/ILSVRC2012_val_00033052.bin 224 224 +38168 ./prep_dataset/ILSVRC2012_val_00046611.bin 224 224 +38169 ./prep_dataset/ILSVRC2012_val_00006046.bin 224 224 +38170 ./prep_dataset/ILSVRC2012_val_00008287.bin 224 224 +38171 ./prep_dataset/ILSVRC2012_val_00023145.bin 224 224 +38172 ./prep_dataset/ILSVRC2012_val_00028099.bin 224 224 +38173 ./prep_dataset/ILSVRC2012_val_00017095.bin 224 224 +38174 ./prep_dataset/ILSVRC2012_val_00009590.bin 224 224 +38175 ./prep_dataset/ILSVRC2012_val_00019881.bin 224 224 +38176 ./prep_dataset/ILSVRC2012_val_00047776.bin 224 224 +38177 ./prep_dataset/ILSVRC2012_val_00025323.bin 224 224 +38178 ./prep_dataset/ILSVRC2012_val_00030831.bin 224 224 +38179 ./prep_dataset/ILSVRC2012_val_00008719.bin 224 224 +38180 ./prep_dataset/ILSVRC2012_val_00014492.bin 224 224 +38181 ./prep_dataset/ILSVRC2012_val_00006625.bin 224 224 +38182 ./prep_dataset/ILSVRC2012_val_00008892.bin 224 224 +38183 ./prep_dataset/ILSVRC2012_val_00011149.bin 224 224 +38184 ./prep_dataset/ILSVRC2012_val_00012867.bin 224 224 +38185 ./prep_dataset/ILSVRC2012_val_00022368.bin 224 224 +38186 ./prep_dataset/ILSVRC2012_val_00003097.bin 224 224 +38187 ./prep_dataset/ILSVRC2012_val_00023627.bin 224 224 +38188 ./prep_dataset/ILSVRC2012_val_00041185.bin 224 224 +38189 ./prep_dataset/ILSVRC2012_val_00039420.bin 224 224 +38190 ./prep_dataset/ILSVRC2012_val_00000515.bin 224 224 +38191 ./prep_dataset/ILSVRC2012_val_00029496.bin 224 224 +38192 ./prep_dataset/ILSVRC2012_val_00010230.bin 224 224 +38193 ./prep_dataset/ILSVRC2012_val_00031056.bin 224 224 +38194 ./prep_dataset/ILSVRC2012_val_00049855.bin 224 224 +38195 ./prep_dataset/ILSVRC2012_val_00038775.bin 224 224 +38196 ./prep_dataset/ILSVRC2012_val_00043671.bin 224 224 +38197 ./prep_dataset/ILSVRC2012_val_00003022.bin 224 224 +38198 ./prep_dataset/ILSVRC2012_val_00023483.bin 224 224 +38199 ./prep_dataset/ILSVRC2012_val_00038366.bin 224 224 +38200 ./prep_dataset/ILSVRC2012_val_00004176.bin 224 224 +38201 ./prep_dataset/ILSVRC2012_val_00008157.bin 224 224 +38202 ./prep_dataset/ILSVRC2012_val_00004974.bin 224 224 +38203 ./prep_dataset/ILSVRC2012_val_00045901.bin 224 224 +38204 ./prep_dataset/ILSVRC2012_val_00041741.bin 224 224 +38205 ./prep_dataset/ILSVRC2012_val_00036341.bin 224 224 +38206 ./prep_dataset/ILSVRC2012_val_00021701.bin 224 224 +38207 ./prep_dataset/ILSVRC2012_val_00004418.bin 224 224 +38208 ./prep_dataset/ILSVRC2012_val_00036310.bin 224 224 +38209 ./prep_dataset/ILSVRC2012_val_00041127.bin 224 224 +38210 ./prep_dataset/ILSVRC2012_val_00044942.bin 224 224 +38211 ./prep_dataset/ILSVRC2012_val_00042221.bin 224 224 +38212 ./prep_dataset/ILSVRC2012_val_00020582.bin 224 224 +38213 ./prep_dataset/ILSVRC2012_val_00018736.bin 224 224 +38214 ./prep_dataset/ILSVRC2012_val_00008601.bin 224 224 +38215 ./prep_dataset/ILSVRC2012_val_00000644.bin 224 224 +38216 ./prep_dataset/ILSVRC2012_val_00029216.bin 224 224 +38217 ./prep_dataset/ILSVRC2012_val_00029952.bin 224 224 +38218 ./prep_dataset/ILSVRC2012_val_00034014.bin 224 224 +38219 ./prep_dataset/ILSVRC2012_val_00015542.bin 224 224 +38220 ./prep_dataset/ILSVRC2012_val_00048033.bin 224 224 +38221 ./prep_dataset/ILSVRC2012_val_00048473.bin 224 224 +38222 ./prep_dataset/ILSVRC2012_val_00039870.bin 224 224 +38223 ./prep_dataset/ILSVRC2012_val_00033306.bin 224 224 +38224 ./prep_dataset/ILSVRC2012_val_00030177.bin 224 224 +38225 ./prep_dataset/ILSVRC2012_val_00042118.bin 224 224 +38226 ./prep_dataset/ILSVRC2012_val_00009425.bin 224 224 +38227 ./prep_dataset/ILSVRC2012_val_00027703.bin 224 224 +38228 ./prep_dataset/ILSVRC2012_val_00010651.bin 224 224 +38229 ./prep_dataset/ILSVRC2012_val_00023747.bin 224 224 +38230 ./prep_dataset/ILSVRC2012_val_00030253.bin 224 224 +38231 ./prep_dataset/ILSVRC2012_val_00012930.bin 224 224 +38232 ./prep_dataset/ILSVRC2012_val_00017738.bin 224 224 +38233 ./prep_dataset/ILSVRC2012_val_00007947.bin 224 224 +38234 ./prep_dataset/ILSVRC2012_val_00025297.bin 224 224 +38235 ./prep_dataset/ILSVRC2012_val_00032918.bin 224 224 +38236 ./prep_dataset/ILSVRC2012_val_00017309.bin 224 224 +38237 ./prep_dataset/ILSVRC2012_val_00035465.bin 224 224 +38238 ./prep_dataset/ILSVRC2012_val_00028480.bin 224 224 +38239 ./prep_dataset/ILSVRC2012_val_00048798.bin 224 224 +38240 ./prep_dataset/ILSVRC2012_val_00008521.bin 224 224 +38241 ./prep_dataset/ILSVRC2012_val_00045380.bin 224 224 +38242 ./prep_dataset/ILSVRC2012_val_00016168.bin 224 224 +38243 ./prep_dataset/ILSVRC2012_val_00028162.bin 224 224 +38244 ./prep_dataset/ILSVRC2012_val_00045387.bin 224 224 +38245 ./prep_dataset/ILSVRC2012_val_00046593.bin 224 224 +38246 ./prep_dataset/ILSVRC2012_val_00016547.bin 224 224 +38247 ./prep_dataset/ILSVRC2012_val_00049070.bin 224 224 +38248 ./prep_dataset/ILSVRC2012_val_00026455.bin 224 224 +38249 ./prep_dataset/ILSVRC2012_val_00043861.bin 224 224 +38250 ./prep_dataset/ILSVRC2012_val_00037499.bin 224 224 +38251 ./prep_dataset/ILSVRC2012_val_00013254.bin 224 224 +38252 ./prep_dataset/ILSVRC2012_val_00000316.bin 224 224 +38253 ./prep_dataset/ILSVRC2012_val_00013906.bin 224 224 +38254 ./prep_dataset/ILSVRC2012_val_00008739.bin 224 224 +38255 ./prep_dataset/ILSVRC2012_val_00018846.bin 224 224 +38256 ./prep_dataset/ILSVRC2012_val_00042009.bin 224 224 +38257 ./prep_dataset/ILSVRC2012_val_00027606.bin 224 224 +38258 ./prep_dataset/ILSVRC2012_val_00025612.bin 224 224 +38259 ./prep_dataset/ILSVRC2012_val_00009324.bin 224 224 +38260 ./prep_dataset/ILSVRC2012_val_00021052.bin 224 224 +38261 ./prep_dataset/ILSVRC2012_val_00049290.bin 224 224 +38262 ./prep_dataset/ILSVRC2012_val_00018284.bin 224 224 +38263 ./prep_dataset/ILSVRC2012_val_00039865.bin 224 224 +38264 ./prep_dataset/ILSVRC2012_val_00046439.bin 224 224 +38265 ./prep_dataset/ILSVRC2012_val_00040682.bin 224 224 +38266 ./prep_dataset/ILSVRC2012_val_00033784.bin 224 224 +38267 ./prep_dataset/ILSVRC2012_val_00031503.bin 224 224 +38268 ./prep_dataset/ILSVRC2012_val_00020594.bin 224 224 +38269 ./prep_dataset/ILSVRC2012_val_00007742.bin 224 224 +38270 ./prep_dataset/ILSVRC2012_val_00009881.bin 224 224 +38271 ./prep_dataset/ILSVRC2012_val_00010564.bin 224 224 +38272 ./prep_dataset/ILSVRC2012_val_00010339.bin 224 224 +38273 ./prep_dataset/ILSVRC2012_val_00017536.bin 224 224 +38274 ./prep_dataset/ILSVRC2012_val_00015938.bin 224 224 +38275 ./prep_dataset/ILSVRC2012_val_00040332.bin 224 224 +38276 ./prep_dataset/ILSVRC2012_val_00030927.bin 224 224 +38277 ./prep_dataset/ILSVRC2012_val_00047750.bin 224 224 +38278 ./prep_dataset/ILSVRC2012_val_00035011.bin 224 224 +38279 ./prep_dataset/ILSVRC2012_val_00011729.bin 224 224 +38280 ./prep_dataset/ILSVRC2012_val_00002974.bin 224 224 +38281 ./prep_dataset/ILSVRC2012_val_00027638.bin 224 224 +38282 ./prep_dataset/ILSVRC2012_val_00045721.bin 224 224 +38283 ./prep_dataset/ILSVRC2012_val_00001013.bin 224 224 +38284 ./prep_dataset/ILSVRC2012_val_00041649.bin 224 224 +38285 ./prep_dataset/ILSVRC2012_val_00022831.bin 224 224 +38286 ./prep_dataset/ILSVRC2012_val_00029320.bin 224 224 +38287 ./prep_dataset/ILSVRC2012_val_00013183.bin 224 224 +38288 ./prep_dataset/ILSVRC2012_val_00004632.bin 224 224 +38289 ./prep_dataset/ILSVRC2012_val_00018002.bin 224 224 +38290 ./prep_dataset/ILSVRC2012_val_00002805.bin 224 224 +38291 ./prep_dataset/ILSVRC2012_val_00034617.bin 224 224 +38292 ./prep_dataset/ILSVRC2012_val_00002224.bin 224 224 +38293 ./prep_dataset/ILSVRC2012_val_00003531.bin 224 224 +38294 ./prep_dataset/ILSVRC2012_val_00042630.bin 224 224 +38295 ./prep_dataset/ILSVRC2012_val_00003719.bin 224 224 +38296 ./prep_dataset/ILSVRC2012_val_00019573.bin 224 224 +38297 ./prep_dataset/ILSVRC2012_val_00009074.bin 224 224 +38298 ./prep_dataset/ILSVRC2012_val_00040441.bin 224 224 +38299 ./prep_dataset/ILSVRC2012_val_00014064.bin 224 224 +38300 ./prep_dataset/ILSVRC2012_val_00020431.bin 224 224 +38301 ./prep_dataset/ILSVRC2012_val_00005203.bin 224 224 +38302 ./prep_dataset/ILSVRC2012_val_00006921.bin 224 224 +38303 ./prep_dataset/ILSVRC2012_val_00030138.bin 224 224 +38304 ./prep_dataset/ILSVRC2012_val_00007111.bin 224 224 +38305 ./prep_dataset/ILSVRC2012_val_00045980.bin 224 224 +38306 ./prep_dataset/ILSVRC2012_val_00040758.bin 224 224 +38307 ./prep_dataset/ILSVRC2012_val_00047213.bin 224 224 +38308 ./prep_dataset/ILSVRC2012_val_00046279.bin 224 224 +38309 ./prep_dataset/ILSVRC2012_val_00031351.bin 224 224 +38310 ./prep_dataset/ILSVRC2012_val_00034883.bin 224 224 +38311 ./prep_dataset/ILSVRC2012_val_00046029.bin 224 224 +38312 ./prep_dataset/ILSVRC2012_val_00044762.bin 224 224 +38313 ./prep_dataset/ILSVRC2012_val_00007481.bin 224 224 +38314 ./prep_dataset/ILSVRC2012_val_00024146.bin 224 224 +38315 ./prep_dataset/ILSVRC2012_val_00046229.bin 224 224 +38316 ./prep_dataset/ILSVRC2012_val_00001265.bin 224 224 +38317 ./prep_dataset/ILSVRC2012_val_00044737.bin 224 224 +38318 ./prep_dataset/ILSVRC2012_val_00025274.bin 224 224 +38319 ./prep_dataset/ILSVRC2012_val_00005651.bin 224 224 +38320 ./prep_dataset/ILSVRC2012_val_00012046.bin 224 224 +38321 ./prep_dataset/ILSVRC2012_val_00006180.bin 224 224 +38322 ./prep_dataset/ILSVRC2012_val_00035646.bin 224 224 +38323 ./prep_dataset/ILSVRC2012_val_00024578.bin 224 224 +38324 ./prep_dataset/ILSVRC2012_val_00020604.bin 224 224 +38325 ./prep_dataset/ILSVRC2012_val_00008274.bin 224 224 +38326 ./prep_dataset/ILSVRC2012_val_00042646.bin 224 224 +38327 ./prep_dataset/ILSVRC2012_val_00014833.bin 224 224 +38328 ./prep_dataset/ILSVRC2012_val_00049399.bin 224 224 +38329 ./prep_dataset/ILSVRC2012_val_00022741.bin 224 224 +38330 ./prep_dataset/ILSVRC2012_val_00025533.bin 224 224 +38331 ./prep_dataset/ILSVRC2012_val_00038172.bin 224 224 +38332 ./prep_dataset/ILSVRC2012_val_00008632.bin 224 224 +38333 ./prep_dataset/ILSVRC2012_val_00021717.bin 224 224 +38334 ./prep_dataset/ILSVRC2012_val_00028741.bin 224 224 +38335 ./prep_dataset/ILSVRC2012_val_00031641.bin 224 224 +38336 ./prep_dataset/ILSVRC2012_val_00004165.bin 224 224 +38337 ./prep_dataset/ILSVRC2012_val_00037245.bin 224 224 +38338 ./prep_dataset/ILSVRC2012_val_00002398.bin 224 224 +38339 ./prep_dataset/ILSVRC2012_val_00033175.bin 224 224 +38340 ./prep_dataset/ILSVRC2012_val_00049420.bin 224 224 +38341 ./prep_dataset/ILSVRC2012_val_00012806.bin 224 224 +38342 ./prep_dataset/ILSVRC2012_val_00022993.bin 224 224 +38343 ./prep_dataset/ILSVRC2012_val_00010859.bin 224 224 +38344 ./prep_dataset/ILSVRC2012_val_00022691.bin 224 224 +38345 ./prep_dataset/ILSVRC2012_val_00013064.bin 224 224 +38346 ./prep_dataset/ILSVRC2012_val_00001761.bin 224 224 +38347 ./prep_dataset/ILSVRC2012_val_00038028.bin 224 224 +38348 ./prep_dataset/ILSVRC2012_val_00027574.bin 224 224 +38349 ./prep_dataset/ILSVRC2012_val_00024142.bin 224 224 +38350 ./prep_dataset/ILSVRC2012_val_00046394.bin 224 224 +38351 ./prep_dataset/ILSVRC2012_val_00041074.bin 224 224 +38352 ./prep_dataset/ILSVRC2012_val_00049305.bin 224 224 +38353 ./prep_dataset/ILSVRC2012_val_00045848.bin 224 224 +38354 ./prep_dataset/ILSVRC2012_val_00038852.bin 224 224 +38355 ./prep_dataset/ILSVRC2012_val_00013179.bin 224 224 +38356 ./prep_dataset/ILSVRC2012_val_00044280.bin 224 224 +38357 ./prep_dataset/ILSVRC2012_val_00003349.bin 224 224 +38358 ./prep_dataset/ILSVRC2012_val_00049332.bin 224 224 +38359 ./prep_dataset/ILSVRC2012_val_00024023.bin 224 224 +38360 ./prep_dataset/ILSVRC2012_val_00028188.bin 224 224 +38361 ./prep_dataset/ILSVRC2012_val_00019668.bin 224 224 +38362 ./prep_dataset/ILSVRC2012_val_00031739.bin 224 224 +38363 ./prep_dataset/ILSVRC2012_val_00044643.bin 224 224 +38364 ./prep_dataset/ILSVRC2012_val_00003019.bin 224 224 +38365 ./prep_dataset/ILSVRC2012_val_00009076.bin 224 224 +38366 ./prep_dataset/ILSVRC2012_val_00046277.bin 224 224 +38367 ./prep_dataset/ILSVRC2012_val_00042246.bin 224 224 +38368 ./prep_dataset/ILSVRC2012_val_00025959.bin 224 224 +38369 ./prep_dataset/ILSVRC2012_val_00034085.bin 224 224 +38370 ./prep_dataset/ILSVRC2012_val_00042437.bin 224 224 +38371 ./prep_dataset/ILSVRC2012_val_00011682.bin 224 224 +38372 ./prep_dataset/ILSVRC2012_val_00022966.bin 224 224 +38373 ./prep_dataset/ILSVRC2012_val_00003371.bin 224 224 +38374 ./prep_dataset/ILSVRC2012_val_00038457.bin 224 224 +38375 ./prep_dataset/ILSVRC2012_val_00001739.bin 224 224 +38376 ./prep_dataset/ILSVRC2012_val_00003972.bin 224 224 +38377 ./prep_dataset/ILSVRC2012_val_00002134.bin 224 224 +38378 ./prep_dataset/ILSVRC2012_val_00013884.bin 224 224 +38379 ./prep_dataset/ILSVRC2012_val_00031073.bin 224 224 +38380 ./prep_dataset/ILSVRC2012_val_00002137.bin 224 224 +38381 ./prep_dataset/ILSVRC2012_val_00041224.bin 224 224 +38382 ./prep_dataset/ILSVRC2012_val_00005766.bin 224 224 +38383 ./prep_dataset/ILSVRC2012_val_00020072.bin 224 224 +38384 ./prep_dataset/ILSVRC2012_val_00040801.bin 224 224 +38385 ./prep_dataset/ILSVRC2012_val_00031138.bin 224 224 +38386 ./prep_dataset/ILSVRC2012_val_00000264.bin 224 224 +38387 ./prep_dataset/ILSVRC2012_val_00000805.bin 224 224 +38388 ./prep_dataset/ILSVRC2012_val_00049035.bin 224 224 +38389 ./prep_dataset/ILSVRC2012_val_00014571.bin 224 224 +38390 ./prep_dataset/ILSVRC2012_val_00000808.bin 224 224 +38391 ./prep_dataset/ILSVRC2012_val_00013588.bin 224 224 +38392 ./prep_dataset/ILSVRC2012_val_00040657.bin 224 224 +38393 ./prep_dataset/ILSVRC2012_val_00035968.bin 224 224 +38394 ./prep_dataset/ILSVRC2012_val_00020972.bin 224 224 +38395 ./prep_dataset/ILSVRC2012_val_00049072.bin 224 224 +38396 ./prep_dataset/ILSVRC2012_val_00040305.bin 224 224 +38397 ./prep_dataset/ILSVRC2012_val_00042561.bin 224 224 +38398 ./prep_dataset/ILSVRC2012_val_00011229.bin 224 224 +38399 ./prep_dataset/ILSVRC2012_val_00024623.bin 224 224 +38400 ./prep_dataset/ILSVRC2012_val_00028250.bin 224 224 +38401 ./prep_dataset/ILSVRC2012_val_00014622.bin 224 224 +38402 ./prep_dataset/ILSVRC2012_val_00035773.bin 224 224 +38403 ./prep_dataset/ILSVRC2012_val_00045856.bin 224 224 +38404 ./prep_dataset/ILSVRC2012_val_00018543.bin 224 224 +38405 ./prep_dataset/ILSVRC2012_val_00030868.bin 224 224 +38406 ./prep_dataset/ILSVRC2012_val_00009353.bin 224 224 +38407 ./prep_dataset/ILSVRC2012_val_00041064.bin 224 224 +38408 ./prep_dataset/ILSVRC2012_val_00003872.bin 224 224 +38409 ./prep_dataset/ILSVRC2012_val_00027619.bin 224 224 +38410 ./prep_dataset/ILSVRC2012_val_00043184.bin 224 224 +38411 ./prep_dataset/ILSVRC2012_val_00046674.bin 224 224 +38412 ./prep_dataset/ILSVRC2012_val_00008505.bin 224 224 +38413 ./prep_dataset/ILSVRC2012_val_00039066.bin 224 224 +38414 ./prep_dataset/ILSVRC2012_val_00041852.bin 224 224 +38415 ./prep_dataset/ILSVRC2012_val_00028882.bin 224 224 +38416 ./prep_dataset/ILSVRC2012_val_00048767.bin 224 224 +38417 ./prep_dataset/ILSVRC2012_val_00002992.bin 224 224 +38418 ./prep_dataset/ILSVRC2012_val_00001015.bin 224 224 +38419 ./prep_dataset/ILSVRC2012_val_00012273.bin 224 224 +38420 ./prep_dataset/ILSVRC2012_val_00028603.bin 224 224 +38421 ./prep_dataset/ILSVRC2012_val_00032283.bin 224 224 +38422 ./prep_dataset/ILSVRC2012_val_00034668.bin 224 224 +38423 ./prep_dataset/ILSVRC2012_val_00015269.bin 224 224 +38424 ./prep_dataset/ILSVRC2012_val_00003664.bin 224 224 +38425 ./prep_dataset/ILSVRC2012_val_00044803.bin 224 224 +38426 ./prep_dataset/ILSVRC2012_val_00004604.bin 224 224 +38427 ./prep_dataset/ILSVRC2012_val_00039433.bin 224 224 +38428 ./prep_dataset/ILSVRC2012_val_00002994.bin 224 224 +38429 ./prep_dataset/ILSVRC2012_val_00013963.bin 224 224 +38430 ./prep_dataset/ILSVRC2012_val_00000133.bin 224 224 +38431 ./prep_dataset/ILSVRC2012_val_00020411.bin 224 224 +38432 ./prep_dataset/ILSVRC2012_val_00032294.bin 224 224 +38433 ./prep_dataset/ILSVRC2012_val_00049213.bin 224 224 +38434 ./prep_dataset/ILSVRC2012_val_00040214.bin 224 224 +38435 ./prep_dataset/ILSVRC2012_val_00014301.bin 224 224 +38436 ./prep_dataset/ILSVRC2012_val_00031496.bin 224 224 +38437 ./prep_dataset/ILSVRC2012_val_00018816.bin 224 224 +38438 ./prep_dataset/ILSVRC2012_val_00007816.bin 224 224 +38439 ./prep_dataset/ILSVRC2012_val_00027112.bin 224 224 +38440 ./prep_dataset/ILSVRC2012_val_00029270.bin 224 224 +38441 ./prep_dataset/ILSVRC2012_val_00024425.bin 224 224 +38442 ./prep_dataset/ILSVRC2012_val_00038424.bin 224 224 +38443 ./prep_dataset/ILSVRC2012_val_00032599.bin 224 224 +38444 ./prep_dataset/ILSVRC2012_val_00041906.bin 224 224 +38445 ./prep_dataset/ILSVRC2012_val_00042709.bin 224 224 +38446 ./prep_dataset/ILSVRC2012_val_00049183.bin 224 224 +38447 ./prep_dataset/ILSVRC2012_val_00036691.bin 224 224 +38448 ./prep_dataset/ILSVRC2012_val_00003554.bin 224 224 +38449 ./prep_dataset/ILSVRC2012_val_00048295.bin 224 224 +38450 ./prep_dataset/ILSVRC2012_val_00033785.bin 224 224 +38451 ./prep_dataset/ILSVRC2012_val_00017768.bin 224 224 +38452 ./prep_dataset/ILSVRC2012_val_00031378.bin 224 224 +38453 ./prep_dataset/ILSVRC2012_val_00022204.bin 224 224 +38454 ./prep_dataset/ILSVRC2012_val_00000765.bin 224 224 +38455 ./prep_dataset/ILSVRC2012_val_00035426.bin 224 224 +38456 ./prep_dataset/ILSVRC2012_val_00033261.bin 224 224 +38457 ./prep_dataset/ILSVRC2012_val_00002551.bin 224 224 +38458 ./prep_dataset/ILSVRC2012_val_00042458.bin 224 224 +38459 ./prep_dataset/ILSVRC2012_val_00015136.bin 224 224 +38460 ./prep_dataset/ILSVRC2012_val_00035981.bin 224 224 +38461 ./prep_dataset/ILSVRC2012_val_00014018.bin 224 224 +38462 ./prep_dataset/ILSVRC2012_val_00014434.bin 224 224 +38463 ./prep_dataset/ILSVRC2012_val_00013761.bin 224 224 +38464 ./prep_dataset/ILSVRC2012_val_00020466.bin 224 224 +38465 ./prep_dataset/ILSVRC2012_val_00040838.bin 224 224 +38466 ./prep_dataset/ILSVRC2012_val_00016110.bin 224 224 +38467 ./prep_dataset/ILSVRC2012_val_00017823.bin 224 224 +38468 ./prep_dataset/ILSVRC2012_val_00020779.bin 224 224 +38469 ./prep_dataset/ILSVRC2012_val_00010611.bin 224 224 +38470 ./prep_dataset/ILSVRC2012_val_00012747.bin 224 224 +38471 ./prep_dataset/ILSVRC2012_val_00048454.bin 224 224 +38472 ./prep_dataset/ILSVRC2012_val_00021116.bin 224 224 +38473 ./prep_dataset/ILSVRC2012_val_00002853.bin 224 224 +38474 ./prep_dataset/ILSVRC2012_val_00037225.bin 224 224 +38475 ./prep_dataset/ILSVRC2012_val_00004866.bin 224 224 +38476 ./prep_dataset/ILSVRC2012_val_00032704.bin 224 224 +38477 ./prep_dataset/ILSVRC2012_val_00000783.bin 224 224 +38478 ./prep_dataset/ILSVRC2012_val_00015788.bin 224 224 +38479 ./prep_dataset/ILSVRC2012_val_00047367.bin 224 224 +38480 ./prep_dataset/ILSVRC2012_val_00042109.bin 224 224 +38481 ./prep_dataset/ILSVRC2012_val_00017242.bin 224 224 +38482 ./prep_dataset/ILSVRC2012_val_00043156.bin 224 224 +38483 ./prep_dataset/ILSVRC2012_val_00022971.bin 224 224 +38484 ./prep_dataset/ILSVRC2012_val_00009558.bin 224 224 +38485 ./prep_dataset/ILSVRC2012_val_00019483.bin 224 224 +38486 ./prep_dataset/ILSVRC2012_val_00029936.bin 224 224 +38487 ./prep_dataset/ILSVRC2012_val_00011429.bin 224 224 +38488 ./prep_dataset/ILSVRC2012_val_00024641.bin 224 224 +38489 ./prep_dataset/ILSVRC2012_val_00005730.bin 224 224 +38490 ./prep_dataset/ILSVRC2012_val_00040672.bin 224 224 +38491 ./prep_dataset/ILSVRC2012_val_00032827.bin 224 224 +38492 ./prep_dataset/ILSVRC2012_val_00008494.bin 224 224 +38493 ./prep_dataset/ILSVRC2012_val_00008034.bin 224 224 +38494 ./prep_dataset/ILSVRC2012_val_00039365.bin 224 224 +38495 ./prep_dataset/ILSVRC2012_val_00023593.bin 224 224 +38496 ./prep_dataset/ILSVRC2012_val_00009279.bin 224 224 +38497 ./prep_dataset/ILSVRC2012_val_00003802.bin 224 224 +38498 ./prep_dataset/ILSVRC2012_val_00042524.bin 224 224 +38499 ./prep_dataset/ILSVRC2012_val_00017236.bin 224 224 +38500 ./prep_dataset/ILSVRC2012_val_00020331.bin 224 224 +38501 ./prep_dataset/ILSVRC2012_val_00044919.bin 224 224 +38502 ./prep_dataset/ILSVRC2012_val_00031221.bin 224 224 +38503 ./prep_dataset/ILSVRC2012_val_00040236.bin 224 224 +38504 ./prep_dataset/ILSVRC2012_val_00007233.bin 224 224 +38505 ./prep_dataset/ILSVRC2012_val_00047436.bin 224 224 +38506 ./prep_dataset/ILSVRC2012_val_00037524.bin 224 224 +38507 ./prep_dataset/ILSVRC2012_val_00012661.bin 224 224 +38508 ./prep_dataset/ILSVRC2012_val_00026612.bin 224 224 +38509 ./prep_dataset/ILSVRC2012_val_00015954.bin 224 224 +38510 ./prep_dataset/ILSVRC2012_val_00027173.bin 224 224 +38511 ./prep_dataset/ILSVRC2012_val_00022652.bin 224 224 +38512 ./prep_dataset/ILSVRC2012_val_00041622.bin 224 224 +38513 ./prep_dataset/ILSVRC2012_val_00016243.bin 224 224 +38514 ./prep_dataset/ILSVRC2012_val_00047131.bin 224 224 +38515 ./prep_dataset/ILSVRC2012_val_00015823.bin 224 224 +38516 ./prep_dataset/ILSVRC2012_val_00046677.bin 224 224 +38517 ./prep_dataset/ILSVRC2012_val_00018035.bin 224 224 +38518 ./prep_dataset/ILSVRC2012_val_00042321.bin 224 224 +38519 ./prep_dataset/ILSVRC2012_val_00028555.bin 224 224 +38520 ./prep_dataset/ILSVRC2012_val_00030747.bin 224 224 +38521 ./prep_dataset/ILSVRC2012_val_00003985.bin 224 224 +38522 ./prep_dataset/ILSVRC2012_val_00044386.bin 224 224 +38523 ./prep_dataset/ILSVRC2012_val_00033165.bin 224 224 +38524 ./prep_dataset/ILSVRC2012_val_00025805.bin 224 224 +38525 ./prep_dataset/ILSVRC2012_val_00008875.bin 224 224 +38526 ./prep_dataset/ILSVRC2012_val_00027904.bin 224 224 +38527 ./prep_dataset/ILSVRC2012_val_00006029.bin 224 224 +38528 ./prep_dataset/ILSVRC2012_val_00048006.bin 224 224 +38529 ./prep_dataset/ILSVRC2012_val_00040165.bin 224 224 +38530 ./prep_dataset/ILSVRC2012_val_00015009.bin 224 224 +38531 ./prep_dataset/ILSVRC2012_val_00019744.bin 224 224 +38532 ./prep_dataset/ILSVRC2012_val_00034843.bin 224 224 +38533 ./prep_dataset/ILSVRC2012_val_00035128.bin 224 224 +38534 ./prep_dataset/ILSVRC2012_val_00002648.bin 224 224 +38535 ./prep_dataset/ILSVRC2012_val_00038812.bin 224 224 +38536 ./prep_dataset/ILSVRC2012_val_00048456.bin 224 224 +38537 ./prep_dataset/ILSVRC2012_val_00009591.bin 224 224 +38538 ./prep_dataset/ILSVRC2012_val_00006017.bin 224 224 +38539 ./prep_dataset/ILSVRC2012_val_00032481.bin 224 224 +38540 ./prep_dataset/ILSVRC2012_val_00023697.bin 224 224 +38541 ./prep_dataset/ILSVRC2012_val_00049606.bin 224 224 +38542 ./prep_dataset/ILSVRC2012_val_00026978.bin 224 224 +38543 ./prep_dataset/ILSVRC2012_val_00048691.bin 224 224 +38544 ./prep_dataset/ILSVRC2012_val_00034862.bin 224 224 +38545 ./prep_dataset/ILSVRC2012_val_00004897.bin 224 224 +38546 ./prep_dataset/ILSVRC2012_val_00048273.bin 224 224 +38547 ./prep_dataset/ILSVRC2012_val_00031006.bin 224 224 +38548 ./prep_dataset/ILSVRC2012_val_00032612.bin 224 224 +38549 ./prep_dataset/ILSVRC2012_val_00025590.bin 224 224 +38550 ./prep_dataset/ILSVRC2012_val_00025051.bin 224 224 +38551 ./prep_dataset/ILSVRC2012_val_00020671.bin 224 224 +38552 ./prep_dataset/ILSVRC2012_val_00000558.bin 224 224 +38553 ./prep_dataset/ILSVRC2012_val_00017255.bin 224 224 +38554 ./prep_dataset/ILSVRC2012_val_00038323.bin 224 224 +38555 ./prep_dataset/ILSVRC2012_val_00004064.bin 224 224 +38556 ./prep_dataset/ILSVRC2012_val_00002603.bin 224 224 +38557 ./prep_dataset/ILSVRC2012_val_00027576.bin 224 224 +38558 ./prep_dataset/ILSVRC2012_val_00034072.bin 224 224 +38559 ./prep_dataset/ILSVRC2012_val_00024408.bin 224 224 +38560 ./prep_dataset/ILSVRC2012_val_00023568.bin 224 224 +38561 ./prep_dataset/ILSVRC2012_val_00034809.bin 224 224 +38562 ./prep_dataset/ILSVRC2012_val_00044752.bin 224 224 +38563 ./prep_dataset/ILSVRC2012_val_00033897.bin 224 224 +38564 ./prep_dataset/ILSVRC2012_val_00044848.bin 224 224 +38565 ./prep_dataset/ILSVRC2012_val_00041764.bin 224 224 +38566 ./prep_dataset/ILSVRC2012_val_00017542.bin 224 224 +38567 ./prep_dataset/ILSVRC2012_val_00016914.bin 224 224 +38568 ./prep_dataset/ILSVRC2012_val_00035880.bin 224 224 +38569 ./prep_dataset/ILSVRC2012_val_00046098.bin 224 224 +38570 ./prep_dataset/ILSVRC2012_val_00047867.bin 224 224 +38571 ./prep_dataset/ILSVRC2012_val_00001520.bin 224 224 +38572 ./prep_dataset/ILSVRC2012_val_00044356.bin 224 224 +38573 ./prep_dataset/ILSVRC2012_val_00041399.bin 224 224 +38574 ./prep_dataset/ILSVRC2012_val_00046544.bin 224 224 +38575 ./prep_dataset/ILSVRC2012_val_00029667.bin 224 224 +38576 ./prep_dataset/ILSVRC2012_val_00007326.bin 224 224 +38577 ./prep_dataset/ILSVRC2012_val_00038151.bin 224 224 +38578 ./prep_dataset/ILSVRC2012_val_00037501.bin 224 224 +38579 ./prep_dataset/ILSVRC2012_val_00032896.bin 224 224 +38580 ./prep_dataset/ILSVRC2012_val_00032388.bin 224 224 +38581 ./prep_dataset/ILSVRC2012_val_00009013.bin 224 224 +38582 ./prep_dataset/ILSVRC2012_val_00015348.bin 224 224 +38583 ./prep_dataset/ILSVRC2012_val_00044906.bin 224 224 +38584 ./prep_dataset/ILSVRC2012_val_00006103.bin 224 224 +38585 ./prep_dataset/ILSVRC2012_val_00037126.bin 224 224 +38586 ./prep_dataset/ILSVRC2012_val_00021575.bin 224 224 +38587 ./prep_dataset/ILSVRC2012_val_00023968.bin 224 224 +38588 ./prep_dataset/ILSVRC2012_val_00010041.bin 224 224 +38589 ./prep_dataset/ILSVRC2012_val_00030547.bin 224 224 +38590 ./prep_dataset/ILSVRC2012_val_00003791.bin 224 224 +38591 ./prep_dataset/ILSVRC2012_val_00006043.bin 224 224 +38592 ./prep_dataset/ILSVRC2012_val_00018825.bin 224 224 +38593 ./prep_dataset/ILSVRC2012_val_00029310.bin 224 224 +38594 ./prep_dataset/ILSVRC2012_val_00049785.bin 224 224 +38595 ./prep_dataset/ILSVRC2012_val_00048580.bin 224 224 +38596 ./prep_dataset/ILSVRC2012_val_00031738.bin 224 224 +38597 ./prep_dataset/ILSVRC2012_val_00041870.bin 224 224 +38598 ./prep_dataset/ILSVRC2012_val_00007568.bin 224 224 +38599 ./prep_dataset/ILSVRC2012_val_00048983.bin 224 224 +38600 ./prep_dataset/ILSVRC2012_val_00037230.bin 224 224 +38601 ./prep_dataset/ILSVRC2012_val_00034797.bin 224 224 +38602 ./prep_dataset/ILSVRC2012_val_00030461.bin 224 224 +38603 ./prep_dataset/ILSVRC2012_val_00044623.bin 224 224 +38604 ./prep_dataset/ILSVRC2012_val_00015784.bin 224 224 +38605 ./prep_dataset/ILSVRC2012_val_00009802.bin 224 224 +38606 ./prep_dataset/ILSVRC2012_val_00018115.bin 224 224 +38607 ./prep_dataset/ILSVRC2012_val_00027528.bin 224 224 +38608 ./prep_dataset/ILSVRC2012_val_00018676.bin 224 224 +38609 ./prep_dataset/ILSVRC2012_val_00008663.bin 224 224 +38610 ./prep_dataset/ILSVRC2012_val_00049612.bin 224 224 +38611 ./prep_dataset/ILSVRC2012_val_00040224.bin 224 224 +38612 ./prep_dataset/ILSVRC2012_val_00004983.bin 224 224 +38613 ./prep_dataset/ILSVRC2012_val_00002306.bin 224 224 +38614 ./prep_dataset/ILSVRC2012_val_00027496.bin 224 224 +38615 ./prep_dataset/ILSVRC2012_val_00016865.bin 224 224 +38616 ./prep_dataset/ILSVRC2012_val_00042992.bin 224 224 +38617 ./prep_dataset/ILSVRC2012_val_00018081.bin 224 224 +38618 ./prep_dataset/ILSVRC2012_val_00047669.bin 224 224 +38619 ./prep_dataset/ILSVRC2012_val_00023976.bin 224 224 +38620 ./prep_dataset/ILSVRC2012_val_00041026.bin 224 224 +38621 ./prep_dataset/ILSVRC2012_val_00022584.bin 224 224 +38622 ./prep_dataset/ILSVRC2012_val_00029579.bin 224 224 +38623 ./prep_dataset/ILSVRC2012_val_00043955.bin 224 224 +38624 ./prep_dataset/ILSVRC2012_val_00022975.bin 224 224 +38625 ./prep_dataset/ILSVRC2012_val_00007497.bin 224 224 +38626 ./prep_dataset/ILSVRC2012_val_00028628.bin 224 224 +38627 ./prep_dataset/ILSVRC2012_val_00000824.bin 224 224 +38628 ./prep_dataset/ILSVRC2012_val_00016491.bin 224 224 +38629 ./prep_dataset/ILSVRC2012_val_00019163.bin 224 224 +38630 ./prep_dataset/ILSVRC2012_val_00047831.bin 224 224 +38631 ./prep_dataset/ILSVRC2012_val_00019968.bin 224 224 +38632 ./prep_dataset/ILSVRC2012_val_00043885.bin 224 224 +38633 ./prep_dataset/ILSVRC2012_val_00002866.bin 224 224 +38634 ./prep_dataset/ILSVRC2012_val_00024859.bin 224 224 +38635 ./prep_dataset/ILSVRC2012_val_00020606.bin 224 224 +38636 ./prep_dataset/ILSVRC2012_val_00008746.bin 224 224 +38637 ./prep_dataset/ILSVRC2012_val_00043110.bin 224 224 +38638 ./prep_dataset/ILSVRC2012_val_00034392.bin 224 224 +38639 ./prep_dataset/ILSVRC2012_val_00039932.bin 224 224 +38640 ./prep_dataset/ILSVRC2012_val_00028559.bin 224 224 +38641 ./prep_dataset/ILSVRC2012_val_00041308.bin 224 224 +38642 ./prep_dataset/ILSVRC2012_val_00021648.bin 224 224 +38643 ./prep_dataset/ILSVRC2012_val_00016565.bin 224 224 +38644 ./prep_dataset/ILSVRC2012_val_00032451.bin 224 224 +38645 ./prep_dataset/ILSVRC2012_val_00040691.bin 224 224 +38646 ./prep_dataset/ILSVRC2012_val_00049539.bin 224 224 +38647 ./prep_dataset/ILSVRC2012_val_00017142.bin 224 224 +38648 ./prep_dataset/ILSVRC2012_val_00000705.bin 224 224 +38649 ./prep_dataset/ILSVRC2012_val_00045843.bin 224 224 +38650 ./prep_dataset/ILSVRC2012_val_00012357.bin 224 224 +38651 ./prep_dataset/ILSVRC2012_val_00016133.bin 224 224 +38652 ./prep_dataset/ILSVRC2012_val_00008408.bin 224 224 +38653 ./prep_dataset/ILSVRC2012_val_00035181.bin 224 224 +38654 ./prep_dataset/ILSVRC2012_val_00000167.bin 224 224 +38655 ./prep_dataset/ILSVRC2012_val_00044885.bin 224 224 +38656 ./prep_dataset/ILSVRC2012_val_00045179.bin 224 224 +38657 ./prep_dataset/ILSVRC2012_val_00009584.bin 224 224 +38658 ./prep_dataset/ILSVRC2012_val_00047794.bin 224 224 +38659 ./prep_dataset/ILSVRC2012_val_00037217.bin 224 224 +38660 ./prep_dataset/ILSVRC2012_val_00015629.bin 224 224 +38661 ./prep_dataset/ILSVRC2012_val_00033063.bin 224 224 +38662 ./prep_dataset/ILSVRC2012_val_00030198.bin 224 224 +38663 ./prep_dataset/ILSVRC2012_val_00046008.bin 224 224 +38664 ./prep_dataset/ILSVRC2012_val_00044740.bin 224 224 +38665 ./prep_dataset/ILSVRC2012_val_00028371.bin 224 224 +38666 ./prep_dataset/ILSVRC2012_val_00039732.bin 224 224 +38667 ./prep_dataset/ILSVRC2012_val_00024461.bin 224 224 +38668 ./prep_dataset/ILSVRC2012_val_00038595.bin 224 224 +38669 ./prep_dataset/ILSVRC2012_val_00028970.bin 224 224 +38670 ./prep_dataset/ILSVRC2012_val_00013868.bin 224 224 +38671 ./prep_dataset/ILSVRC2012_val_00013039.bin 224 224 +38672 ./prep_dataset/ILSVRC2012_val_00039343.bin 224 224 +38673 ./prep_dataset/ILSVRC2012_val_00048150.bin 224 224 +38674 ./prep_dataset/ILSVRC2012_val_00010144.bin 224 224 +38675 ./prep_dataset/ILSVRC2012_val_00002075.bin 224 224 +38676 ./prep_dataset/ILSVRC2012_val_00025425.bin 224 224 +38677 ./prep_dataset/ILSVRC2012_val_00023862.bin 224 224 +38678 ./prep_dataset/ILSVRC2012_val_00045909.bin 224 224 +38679 ./prep_dataset/ILSVRC2012_val_00044750.bin 224 224 +38680 ./prep_dataset/ILSVRC2012_val_00038249.bin 224 224 +38681 ./prep_dataset/ILSVRC2012_val_00027376.bin 224 224 +38682 ./prep_dataset/ILSVRC2012_val_00049253.bin 224 224 +38683 ./prep_dataset/ILSVRC2012_val_00008653.bin 224 224 +38684 ./prep_dataset/ILSVRC2012_val_00029308.bin 224 224 +38685 ./prep_dataset/ILSVRC2012_val_00010133.bin 224 224 +38686 ./prep_dataset/ILSVRC2012_val_00020669.bin 224 224 +38687 ./prep_dataset/ILSVRC2012_val_00042881.bin 224 224 +38688 ./prep_dataset/ILSVRC2012_val_00005159.bin 224 224 +38689 ./prep_dataset/ILSVRC2012_val_00006944.bin 224 224 +38690 ./prep_dataset/ILSVRC2012_val_00046013.bin 224 224 +38691 ./prep_dataset/ILSVRC2012_val_00028282.bin 224 224 +38692 ./prep_dataset/ILSVRC2012_val_00003048.bin 224 224 +38693 ./prep_dataset/ILSVRC2012_val_00025555.bin 224 224 +38694 ./prep_dataset/ILSVRC2012_val_00021090.bin 224 224 +38695 ./prep_dataset/ILSVRC2012_val_00012493.bin 224 224 +38696 ./prep_dataset/ILSVRC2012_val_00039457.bin 224 224 +38697 ./prep_dataset/ILSVRC2012_val_00026149.bin 224 224 +38698 ./prep_dataset/ILSVRC2012_val_00032797.bin 224 224 +38699 ./prep_dataset/ILSVRC2012_val_00008497.bin 224 224 +38700 ./prep_dataset/ILSVRC2012_val_00003905.bin 224 224 +38701 ./prep_dataset/ILSVRC2012_val_00045576.bin 224 224 +38702 ./prep_dataset/ILSVRC2012_val_00024188.bin 224 224 +38703 ./prep_dataset/ILSVRC2012_val_00004614.bin 224 224 +38704 ./prep_dataset/ILSVRC2012_val_00022435.bin 224 224 +38705 ./prep_dataset/ILSVRC2012_val_00043318.bin 224 224 +38706 ./prep_dataset/ILSVRC2012_val_00005349.bin 224 224 +38707 ./prep_dataset/ILSVRC2012_val_00006490.bin 224 224 +38708 ./prep_dataset/ILSVRC2012_val_00014176.bin 224 224 +38709 ./prep_dataset/ILSVRC2012_val_00045851.bin 224 224 +38710 ./prep_dataset/ILSVRC2012_val_00003786.bin 224 224 +38711 ./prep_dataset/ILSVRC2012_val_00002349.bin 224 224 +38712 ./prep_dataset/ILSVRC2012_val_00043497.bin 224 224 +38713 ./prep_dataset/ILSVRC2012_val_00023755.bin 224 224 +38714 ./prep_dataset/ILSVRC2012_val_00035030.bin 224 224 +38715 ./prep_dataset/ILSVRC2012_val_00017455.bin 224 224 +38716 ./prep_dataset/ILSVRC2012_val_00030588.bin 224 224 +38717 ./prep_dataset/ILSVRC2012_val_00040189.bin 224 224 +38718 ./prep_dataset/ILSVRC2012_val_00011923.bin 224 224 +38719 ./prep_dataset/ILSVRC2012_val_00024816.bin 224 224 +38720 ./prep_dataset/ILSVRC2012_val_00029894.bin 224 224 +38721 ./prep_dataset/ILSVRC2012_val_00032090.bin 224 224 +38722 ./prep_dataset/ILSVRC2012_val_00049739.bin 224 224 +38723 ./prep_dataset/ILSVRC2012_val_00002879.bin 224 224 +38724 ./prep_dataset/ILSVRC2012_val_00008991.bin 224 224 +38725 ./prep_dataset/ILSVRC2012_val_00040282.bin 224 224 +38726 ./prep_dataset/ILSVRC2012_val_00046302.bin 224 224 +38727 ./prep_dataset/ILSVRC2012_val_00027158.bin 224 224 +38728 ./prep_dataset/ILSVRC2012_val_00027562.bin 224 224 +38729 ./prep_dataset/ILSVRC2012_val_00037875.bin 224 224 +38730 ./prep_dataset/ILSVRC2012_val_00027998.bin 224 224 +38731 ./prep_dataset/ILSVRC2012_val_00009805.bin 224 224 +38732 ./prep_dataset/ILSVRC2012_val_00042266.bin 224 224 +38733 ./prep_dataset/ILSVRC2012_val_00014104.bin 224 224 +38734 ./prep_dataset/ILSVRC2012_val_00034654.bin 224 224 +38735 ./prep_dataset/ILSVRC2012_val_00041989.bin 224 224 +38736 ./prep_dataset/ILSVRC2012_val_00025637.bin 224 224 +38737 ./prep_dataset/ILSVRC2012_val_00030728.bin 224 224 +38738 ./prep_dataset/ILSVRC2012_val_00006863.bin 224 224 +38739 ./prep_dataset/ILSVRC2012_val_00022682.bin 224 224 +38740 ./prep_dataset/ILSVRC2012_val_00027740.bin 224 224 +38741 ./prep_dataset/ILSVRC2012_val_00042073.bin 224 224 +38742 ./prep_dataset/ILSVRC2012_val_00036128.bin 224 224 +38743 ./prep_dataset/ILSVRC2012_val_00031481.bin 224 224 +38744 ./prep_dataset/ILSVRC2012_val_00034313.bin 224 224 +38745 ./prep_dataset/ILSVRC2012_val_00040723.bin 224 224 +38746 ./prep_dataset/ILSVRC2012_val_00023487.bin 224 224 +38747 ./prep_dataset/ILSVRC2012_val_00007425.bin 224 224 +38748 ./prep_dataset/ILSVRC2012_val_00047726.bin 224 224 +38749 ./prep_dataset/ILSVRC2012_val_00034400.bin 224 224 +38750 ./prep_dataset/ILSVRC2012_val_00044009.bin 224 224 +38751 ./prep_dataset/ILSVRC2012_val_00016439.bin 224 224 +38752 ./prep_dataset/ILSVRC2012_val_00012034.bin 224 224 +38753 ./prep_dataset/ILSVRC2012_val_00005156.bin 224 224 +38754 ./prep_dataset/ILSVRC2012_val_00001778.bin 224 224 +38755 ./prep_dataset/ILSVRC2012_val_00043613.bin 224 224 +38756 ./prep_dataset/ILSVRC2012_val_00033401.bin 224 224 +38757 ./prep_dataset/ILSVRC2012_val_00029562.bin 224 224 +38758 ./prep_dataset/ILSVRC2012_val_00029772.bin 224 224 +38759 ./prep_dataset/ILSVRC2012_val_00036921.bin 224 224 +38760 ./prep_dataset/ILSVRC2012_val_00047430.bin 224 224 +38761 ./prep_dataset/ILSVRC2012_val_00038404.bin 224 224 +38762 ./prep_dataset/ILSVRC2012_val_00044702.bin 224 224 +38763 ./prep_dataset/ILSVRC2012_val_00049476.bin 224 224 +38764 ./prep_dataset/ILSVRC2012_val_00000912.bin 224 224 +38765 ./prep_dataset/ILSVRC2012_val_00039301.bin 224 224 +38766 ./prep_dataset/ILSVRC2012_val_00041070.bin 224 224 +38767 ./prep_dataset/ILSVRC2012_val_00003716.bin 224 224 +38768 ./prep_dataset/ILSVRC2012_val_00008923.bin 224 224 +38769 ./prep_dataset/ILSVRC2012_val_00039814.bin 224 224 +38770 ./prep_dataset/ILSVRC2012_val_00016798.bin 224 224 +38771 ./prep_dataset/ILSVRC2012_val_00027091.bin 224 224 +38772 ./prep_dataset/ILSVRC2012_val_00006175.bin 224 224 +38773 ./prep_dataset/ILSVRC2012_val_00023562.bin 224 224 +38774 ./prep_dataset/ILSVRC2012_val_00019209.bin 224 224 +38775 ./prep_dataset/ILSVRC2012_val_00011607.bin 224 224 +38776 ./prep_dataset/ILSVRC2012_val_00038479.bin 224 224 +38777 ./prep_dataset/ILSVRC2012_val_00033764.bin 224 224 +38778 ./prep_dataset/ILSVRC2012_val_00019089.bin 224 224 +38779 ./prep_dataset/ILSVRC2012_val_00012284.bin 224 224 +38780 ./prep_dataset/ILSVRC2012_val_00005485.bin 224 224 +38781 ./prep_dataset/ILSVRC2012_val_00040092.bin 224 224 +38782 ./prep_dataset/ILSVRC2012_val_00001516.bin 224 224 +38783 ./prep_dataset/ILSVRC2012_val_00001109.bin 224 224 +38784 ./prep_dataset/ILSVRC2012_val_00006523.bin 224 224 +38785 ./prep_dataset/ILSVRC2012_val_00046057.bin 224 224 +38786 ./prep_dataset/ILSVRC2012_val_00038962.bin 224 224 +38787 ./prep_dataset/ILSVRC2012_val_00003551.bin 224 224 +38788 ./prep_dataset/ILSVRC2012_val_00006746.bin 224 224 +38789 ./prep_dataset/ILSVRC2012_val_00005154.bin 224 224 +38790 ./prep_dataset/ILSVRC2012_val_00019563.bin 224 224 +38791 ./prep_dataset/ILSVRC2012_val_00019841.bin 224 224 +38792 ./prep_dataset/ILSVRC2012_val_00035039.bin 224 224 +38793 ./prep_dataset/ILSVRC2012_val_00005411.bin 224 224 +38794 ./prep_dataset/ILSVRC2012_val_00029821.bin 224 224 +38795 ./prep_dataset/ILSVRC2012_val_00015258.bin 224 224 +38796 ./prep_dataset/ILSVRC2012_val_00039599.bin 224 224 +38797 ./prep_dataset/ILSVRC2012_val_00044871.bin 224 224 +38798 ./prep_dataset/ILSVRC2012_val_00022106.bin 224 224 +38799 ./prep_dataset/ILSVRC2012_val_00000611.bin 224 224 +38800 ./prep_dataset/ILSVRC2012_val_00028552.bin 224 224 +38801 ./prep_dataset/ILSVRC2012_val_00025143.bin 224 224 +38802 ./prep_dataset/ILSVRC2012_val_00014602.bin 224 224 +38803 ./prep_dataset/ILSVRC2012_val_00046988.bin 224 224 +38804 ./prep_dataset/ILSVRC2012_val_00032814.bin 224 224 +38805 ./prep_dataset/ILSVRC2012_val_00011703.bin 224 224 +38806 ./prep_dataset/ILSVRC2012_val_00025478.bin 224 224 +38807 ./prep_dataset/ILSVRC2012_val_00044400.bin 224 224 +38808 ./prep_dataset/ILSVRC2012_val_00042618.bin 224 224 +38809 ./prep_dataset/ILSVRC2012_val_00023580.bin 224 224 +38810 ./prep_dataset/ILSVRC2012_val_00034870.bin 224 224 +38811 ./prep_dataset/ILSVRC2012_val_00035913.bin 224 224 +38812 ./prep_dataset/ILSVRC2012_val_00027010.bin 224 224 +38813 ./prep_dataset/ILSVRC2012_val_00010253.bin 224 224 +38814 ./prep_dataset/ILSVRC2012_val_00013631.bin 224 224 +38815 ./prep_dataset/ILSVRC2012_val_00030846.bin 224 224 +38816 ./prep_dataset/ILSVRC2012_val_00017276.bin 224 224 +38817 ./prep_dataset/ILSVRC2012_val_00013262.bin 224 224 +38818 ./prep_dataset/ILSVRC2012_val_00013579.bin 224 224 +38819 ./prep_dataset/ILSVRC2012_val_00027721.bin 224 224 +38820 ./prep_dataset/ILSVRC2012_val_00022476.bin 224 224 +38821 ./prep_dataset/ILSVRC2012_val_00014633.bin 224 224 +38822 ./prep_dataset/ILSVRC2012_val_00009736.bin 224 224 +38823 ./prep_dataset/ILSVRC2012_val_00028790.bin 224 224 +38824 ./prep_dataset/ILSVRC2012_val_00019607.bin 224 224 +38825 ./prep_dataset/ILSVRC2012_val_00047154.bin 224 224 +38826 ./prep_dataset/ILSVRC2012_val_00027670.bin 224 224 +38827 ./prep_dataset/ILSVRC2012_val_00010126.bin 224 224 +38828 ./prep_dataset/ILSVRC2012_val_00033980.bin 224 224 +38829 ./prep_dataset/ILSVRC2012_val_00031346.bin 224 224 +38830 ./prep_dataset/ILSVRC2012_val_00008345.bin 224 224 +38831 ./prep_dataset/ILSVRC2012_val_00002066.bin 224 224 +38832 ./prep_dataset/ILSVRC2012_val_00027075.bin 224 224 +38833 ./prep_dataset/ILSVRC2012_val_00010124.bin 224 224 +38834 ./prep_dataset/ILSVRC2012_val_00004435.bin 224 224 +38835 ./prep_dataset/ILSVRC2012_val_00021452.bin 224 224 +38836 ./prep_dataset/ILSVRC2012_val_00022029.bin 224 224 +38837 ./prep_dataset/ILSVRC2012_val_00022846.bin 224 224 +38838 ./prep_dataset/ILSVRC2012_val_00028787.bin 224 224 +38839 ./prep_dataset/ILSVRC2012_val_00015859.bin 224 224 +38840 ./prep_dataset/ILSVRC2012_val_00035504.bin 224 224 +38841 ./prep_dataset/ILSVRC2012_val_00042896.bin 224 224 +38842 ./prep_dataset/ILSVRC2012_val_00006406.bin 224 224 +38843 ./prep_dataset/ILSVRC2012_val_00009648.bin 224 224 +38844 ./prep_dataset/ILSVRC2012_val_00001074.bin 224 224 +38845 ./prep_dataset/ILSVRC2012_val_00020941.bin 224 224 +38846 ./prep_dataset/ILSVRC2012_val_00013192.bin 224 224 +38847 ./prep_dataset/ILSVRC2012_val_00036938.bin 224 224 +38848 ./prep_dataset/ILSVRC2012_val_00036743.bin 224 224 +38849 ./prep_dataset/ILSVRC2012_val_00046880.bin 224 224 +38850 ./prep_dataset/ILSVRC2012_val_00029962.bin 224 224 +38851 ./prep_dataset/ILSVRC2012_val_00015052.bin 224 224 +38852 ./prep_dataset/ILSVRC2012_val_00016604.bin 224 224 +38853 ./prep_dataset/ILSVRC2012_val_00014501.bin 224 224 +38854 ./prep_dataset/ILSVRC2012_val_00029396.bin 224 224 +38855 ./prep_dataset/ILSVRC2012_val_00016997.bin 224 224 +38856 ./prep_dataset/ILSVRC2012_val_00047145.bin 224 224 +38857 ./prep_dataset/ILSVRC2012_val_00028613.bin 224 224 +38858 ./prep_dataset/ILSVRC2012_val_00029284.bin 224 224 +38859 ./prep_dataset/ILSVRC2012_val_00043229.bin 224 224 +38860 ./prep_dataset/ILSVRC2012_val_00022303.bin 224 224 +38861 ./prep_dataset/ILSVRC2012_val_00026831.bin 224 224 +38862 ./prep_dataset/ILSVRC2012_val_00046586.bin 224 224 +38863 ./prep_dataset/ILSVRC2012_val_00015305.bin 224 224 +38864 ./prep_dataset/ILSVRC2012_val_00041320.bin 224 224 +38865 ./prep_dataset/ILSVRC2012_val_00039659.bin 224 224 +38866 ./prep_dataset/ILSVRC2012_val_00001332.bin 224 224 +38867 ./prep_dataset/ILSVRC2012_val_00018515.bin 224 224 +38868 ./prep_dataset/ILSVRC2012_val_00013205.bin 224 224 +38869 ./prep_dataset/ILSVRC2012_val_00048608.bin 224 224 +38870 ./prep_dataset/ILSVRC2012_val_00006082.bin 224 224 +38871 ./prep_dataset/ILSVRC2012_val_00022088.bin 224 224 +38872 ./prep_dataset/ILSVRC2012_val_00028399.bin 224 224 +38873 ./prep_dataset/ILSVRC2012_val_00016176.bin 224 224 +38874 ./prep_dataset/ILSVRC2012_val_00043208.bin 224 224 +38875 ./prep_dataset/ILSVRC2012_val_00037814.bin 224 224 +38876 ./prep_dataset/ILSVRC2012_val_00035121.bin 224 224 +38877 ./prep_dataset/ILSVRC2012_val_00034804.bin 224 224 +38878 ./prep_dataset/ILSVRC2012_val_00034408.bin 224 224 +38879 ./prep_dataset/ILSVRC2012_val_00012589.bin 224 224 +38880 ./prep_dataset/ILSVRC2012_val_00047448.bin 224 224 +38881 ./prep_dataset/ILSVRC2012_val_00039581.bin 224 224 +38882 ./prep_dataset/ILSVRC2012_val_00011641.bin 224 224 +38883 ./prep_dataset/ILSVRC2012_val_00010843.bin 224 224 +38884 ./prep_dataset/ILSVRC2012_val_00031314.bin 224 224 +38885 ./prep_dataset/ILSVRC2012_val_00018540.bin 224 224 +38886 ./prep_dataset/ILSVRC2012_val_00046882.bin 224 224 +38887 ./prep_dataset/ILSVRC2012_val_00029852.bin 224 224 +38888 ./prep_dataset/ILSVRC2012_val_00044742.bin 224 224 +38889 ./prep_dataset/ILSVRC2012_val_00023595.bin 224 224 +38890 ./prep_dataset/ILSVRC2012_val_00019908.bin 224 224 +38891 ./prep_dataset/ILSVRC2012_val_00031891.bin 224 224 +38892 ./prep_dataset/ILSVRC2012_val_00029007.bin 224 224 +38893 ./prep_dataset/ILSVRC2012_val_00046061.bin 224 224 +38894 ./prep_dataset/ILSVRC2012_val_00004817.bin 224 224 +38895 ./prep_dataset/ILSVRC2012_val_00002479.bin 224 224 +38896 ./prep_dataset/ILSVRC2012_val_00041007.bin 224 224 +38897 ./prep_dataset/ILSVRC2012_val_00010254.bin 224 224 +38898 ./prep_dataset/ILSVRC2012_val_00038193.bin 224 224 +38899 ./prep_dataset/ILSVRC2012_val_00012128.bin 224 224 +38900 ./prep_dataset/ILSVRC2012_val_00020668.bin 224 224 +38901 ./prep_dataset/ILSVRC2012_val_00025444.bin 224 224 +38902 ./prep_dataset/ILSVRC2012_val_00027596.bin 224 224 +38903 ./prep_dataset/ILSVRC2012_val_00013834.bin 224 224 +38904 ./prep_dataset/ILSVRC2012_val_00037267.bin 224 224 +38905 ./prep_dataset/ILSVRC2012_val_00022213.bin 224 224 +38906 ./prep_dataset/ILSVRC2012_val_00048724.bin 224 224 +38907 ./prep_dataset/ILSVRC2012_val_00020500.bin 224 224 +38908 ./prep_dataset/ILSVRC2012_val_00001949.bin 224 224 +38909 ./prep_dataset/ILSVRC2012_val_00049543.bin 224 224 +38910 ./prep_dataset/ILSVRC2012_val_00034474.bin 224 224 +38911 ./prep_dataset/ILSVRC2012_val_00018011.bin 224 224 +38912 ./prep_dataset/ILSVRC2012_val_00026809.bin 224 224 +38913 ./prep_dataset/ILSVRC2012_val_00041854.bin 224 224 +38914 ./prep_dataset/ILSVRC2012_val_00036778.bin 224 224 +38915 ./prep_dataset/ILSVRC2012_val_00020424.bin 224 224 +38916 ./prep_dataset/ILSVRC2012_val_00013946.bin 224 224 +38917 ./prep_dataset/ILSVRC2012_val_00048912.bin 224 224 +38918 ./prep_dataset/ILSVRC2012_val_00040223.bin 224 224 +38919 ./prep_dataset/ILSVRC2012_val_00010892.bin 224 224 +38920 ./prep_dataset/ILSVRC2012_val_00034711.bin 224 224 +38921 ./prep_dataset/ILSVRC2012_val_00029729.bin 224 224 +38922 ./prep_dataset/ILSVRC2012_val_00022047.bin 224 224 +38923 ./prep_dataset/ILSVRC2012_val_00015649.bin 224 224 +38924 ./prep_dataset/ILSVRC2012_val_00018013.bin 224 224 +38925 ./prep_dataset/ILSVRC2012_val_00045458.bin 224 224 +38926 ./prep_dataset/ILSVRC2012_val_00043843.bin 224 224 +38927 ./prep_dataset/ILSVRC2012_val_00030455.bin 224 224 +38928 ./prep_dataset/ILSVRC2012_val_00006745.bin 224 224 +38929 ./prep_dataset/ILSVRC2012_val_00004683.bin 224 224 +38930 ./prep_dataset/ILSVRC2012_val_00024734.bin 224 224 +38931 ./prep_dataset/ILSVRC2012_val_00026350.bin 224 224 +38932 ./prep_dataset/ILSVRC2012_val_00028141.bin 224 224 +38933 ./prep_dataset/ILSVRC2012_val_00006117.bin 224 224 +38934 ./prep_dataset/ILSVRC2012_val_00036846.bin 224 224 +38935 ./prep_dataset/ILSVRC2012_val_00000987.bin 224 224 +38936 ./prep_dataset/ILSVRC2012_val_00027194.bin 224 224 +38937 ./prep_dataset/ILSVRC2012_val_00037811.bin 224 224 +38938 ./prep_dataset/ILSVRC2012_val_00030565.bin 224 224 +38939 ./prep_dataset/ILSVRC2012_val_00026776.bin 224 224 +38940 ./prep_dataset/ILSVRC2012_val_00010208.bin 224 224 +38941 ./prep_dataset/ILSVRC2012_val_00033564.bin 224 224 +38942 ./prep_dataset/ILSVRC2012_val_00034583.bin 224 224 +38943 ./prep_dataset/ILSVRC2012_val_00009965.bin 224 224 +38944 ./prep_dataset/ILSVRC2012_val_00004867.bin 224 224 +38945 ./prep_dataset/ILSVRC2012_val_00038124.bin 224 224 +38946 ./prep_dataset/ILSVRC2012_val_00007879.bin 224 224 +38947 ./prep_dataset/ILSVRC2012_val_00024776.bin 224 224 +38948 ./prep_dataset/ILSVRC2012_val_00019399.bin 224 224 +38949 ./prep_dataset/ILSVRC2012_val_00015703.bin 224 224 +38950 ./prep_dataset/ILSVRC2012_val_00024497.bin 224 224 +38951 ./prep_dataset/ILSVRC2012_val_00046239.bin 224 224 +38952 ./prep_dataset/ILSVRC2012_val_00043312.bin 224 224 +38953 ./prep_dataset/ILSVRC2012_val_00009926.bin 224 224 +38954 ./prep_dataset/ILSVRC2012_val_00025355.bin 224 224 +38955 ./prep_dataset/ILSVRC2012_val_00046905.bin 224 224 +38956 ./prep_dataset/ILSVRC2012_val_00007997.bin 224 224 +38957 ./prep_dataset/ILSVRC2012_val_00003209.bin 224 224 +38958 ./prep_dataset/ILSVRC2012_val_00028304.bin 224 224 +38959 ./prep_dataset/ILSVRC2012_val_00013741.bin 224 224 +38960 ./prep_dataset/ILSVRC2012_val_00012991.bin 224 224 +38961 ./prep_dataset/ILSVRC2012_val_00030611.bin 224 224 +38962 ./prep_dataset/ILSVRC2012_val_00029907.bin 224 224 +38963 ./prep_dataset/ILSVRC2012_val_00009376.bin 224 224 +38964 ./prep_dataset/ILSVRC2012_val_00024205.bin 224 224 +38965 ./prep_dataset/ILSVRC2012_val_00009924.bin 224 224 +38966 ./prep_dataset/ILSVRC2012_val_00026147.bin 224 224 +38967 ./prep_dataset/ILSVRC2012_val_00027504.bin 224 224 +38968 ./prep_dataset/ILSVRC2012_val_00041016.bin 224 224 +38969 ./prep_dataset/ILSVRC2012_val_00049065.bin 224 224 +38970 ./prep_dataset/ILSVRC2012_val_00048208.bin 224 224 +38971 ./prep_dataset/ILSVRC2012_val_00024482.bin 224 224 +38972 ./prep_dataset/ILSVRC2012_val_00008465.bin 224 224 +38973 ./prep_dataset/ILSVRC2012_val_00044955.bin 224 224 +38974 ./prep_dataset/ILSVRC2012_val_00045865.bin 224 224 +38975 ./prep_dataset/ILSVRC2012_val_00003946.bin 224 224 +38976 ./prep_dataset/ILSVRC2012_val_00003515.bin 224 224 +38977 ./prep_dataset/ILSVRC2012_val_00025808.bin 224 224 +38978 ./prep_dataset/ILSVRC2012_val_00035453.bin 224 224 +38979 ./prep_dataset/ILSVRC2012_val_00032628.bin 224 224 +38980 ./prep_dataset/ILSVRC2012_val_00001736.bin 224 224 +38981 ./prep_dataset/ILSVRC2012_val_00045518.bin 224 224 +38982 ./prep_dataset/ILSVRC2012_val_00037251.bin 224 224 +38983 ./prep_dataset/ILSVRC2012_val_00024510.bin 224 224 +38984 ./prep_dataset/ILSVRC2012_val_00018278.bin 224 224 +38985 ./prep_dataset/ILSVRC2012_val_00030971.bin 224 224 +38986 ./prep_dataset/ILSVRC2012_val_00024026.bin 224 224 +38987 ./prep_dataset/ILSVRC2012_val_00040274.bin 224 224 +38988 ./prep_dataset/ILSVRC2012_val_00030853.bin 224 224 +38989 ./prep_dataset/ILSVRC2012_val_00045173.bin 224 224 +38990 ./prep_dataset/ILSVRC2012_val_00011027.bin 224 224 +38991 ./prep_dataset/ILSVRC2012_val_00032788.bin 224 224 +38992 ./prep_dataset/ILSVRC2012_val_00015977.bin 224 224 +38993 ./prep_dataset/ILSVRC2012_val_00047060.bin 224 224 +38994 ./prep_dataset/ILSVRC2012_val_00022614.bin 224 224 +38995 ./prep_dataset/ILSVRC2012_val_00024622.bin 224 224 +38996 ./prep_dataset/ILSVRC2012_val_00002594.bin 224 224 +38997 ./prep_dataset/ILSVRC2012_val_00030000.bin 224 224 +38998 ./prep_dataset/ILSVRC2012_val_00044281.bin 224 224 +38999 ./prep_dataset/ILSVRC2012_val_00034332.bin 224 224 +39000 ./prep_dataset/ILSVRC2012_val_00003284.bin 224 224 +39001 ./prep_dataset/ILSVRC2012_val_00009177.bin 224 224 +39002 ./prep_dataset/ILSVRC2012_val_00026712.bin 224 224 +39003 ./prep_dataset/ILSVRC2012_val_00017363.bin 224 224 +39004 ./prep_dataset/ILSVRC2012_val_00047492.bin 224 224 +39005 ./prep_dataset/ILSVRC2012_val_00037095.bin 224 224 +39006 ./prep_dataset/ILSVRC2012_val_00038439.bin 224 224 +39007 ./prep_dataset/ILSVRC2012_val_00035936.bin 224 224 +39008 ./prep_dataset/ILSVRC2012_val_00013338.bin 224 224 +39009 ./prep_dataset/ILSVRC2012_val_00001577.bin 224 224 +39010 ./prep_dataset/ILSVRC2012_val_00004073.bin 224 224 +39011 ./prep_dataset/ILSVRC2012_val_00008275.bin 224 224 +39012 ./prep_dataset/ILSVRC2012_val_00004938.bin 224 224 +39013 ./prep_dataset/ILSVRC2012_val_00018642.bin 224 224 +39014 ./prep_dataset/ILSVRC2012_val_00041398.bin 224 224 +39015 ./prep_dataset/ILSVRC2012_val_00047811.bin 224 224 +39016 ./prep_dataset/ILSVRC2012_val_00011720.bin 224 224 +39017 ./prep_dataset/ILSVRC2012_val_00003731.bin 224 224 +39018 ./prep_dataset/ILSVRC2012_val_00033791.bin 224 224 +39019 ./prep_dataset/ILSVRC2012_val_00037794.bin 224 224 +39020 ./prep_dataset/ILSVRC2012_val_00041365.bin 224 224 +39021 ./prep_dataset/ILSVRC2012_val_00036904.bin 224 224 +39022 ./prep_dataset/ILSVRC2012_val_00018196.bin 224 224 +39023 ./prep_dataset/ILSVRC2012_val_00008744.bin 224 224 +39024 ./prep_dataset/ILSVRC2012_val_00028257.bin 224 224 +39025 ./prep_dataset/ILSVRC2012_val_00038641.bin 224 224 +39026 ./prep_dataset/ILSVRC2012_val_00046877.bin 224 224 +39027 ./prep_dataset/ILSVRC2012_val_00021646.bin 224 224 +39028 ./prep_dataset/ILSVRC2012_val_00023869.bin 224 224 +39029 ./prep_dataset/ILSVRC2012_val_00013649.bin 224 224 +39030 ./prep_dataset/ILSVRC2012_val_00015711.bin 224 224 +39031 ./prep_dataset/ILSVRC2012_val_00038311.bin 224 224 +39032 ./prep_dataset/ILSVRC2012_val_00040546.bin 224 224 +39033 ./prep_dataset/ILSVRC2012_val_00001700.bin 224 224 +39034 ./prep_dataset/ILSVRC2012_val_00006428.bin 224 224 +39035 ./prep_dataset/ILSVRC2012_val_00019989.bin 224 224 +39036 ./prep_dataset/ILSVRC2012_val_00031667.bin 224 224 +39037 ./prep_dataset/ILSVRC2012_val_00026386.bin 224 224 +39038 ./prep_dataset/ILSVRC2012_val_00026440.bin 224 224 +39039 ./prep_dataset/ILSVRC2012_val_00029247.bin 224 224 +39040 ./prep_dataset/ILSVRC2012_val_00016627.bin 224 224 +39041 ./prep_dataset/ILSVRC2012_val_00027247.bin 224 224 +39042 ./prep_dataset/ILSVRC2012_val_00005582.bin 224 224 +39043 ./prep_dataset/ILSVRC2012_val_00034279.bin 224 224 +39044 ./prep_dataset/ILSVRC2012_val_00033601.bin 224 224 +39045 ./prep_dataset/ILSVRC2012_val_00047301.bin 224 224 +39046 ./prep_dataset/ILSVRC2012_val_00000520.bin 224 224 +39047 ./prep_dataset/ILSVRC2012_val_00013526.bin 224 224 +39048 ./prep_dataset/ILSVRC2012_val_00009151.bin 224 224 +39049 ./prep_dataset/ILSVRC2012_val_00016232.bin 224 224 +39050 ./prep_dataset/ILSVRC2012_val_00005645.bin 224 224 +39051 ./prep_dataset/ILSVRC2012_val_00026838.bin 224 224 +39052 ./prep_dataset/ILSVRC2012_val_00001855.bin 224 224 +39053 ./prep_dataset/ILSVRC2012_val_00040414.bin 224 224 +39054 ./prep_dataset/ILSVRC2012_val_00048510.bin 224 224 +39055 ./prep_dataset/ILSVRC2012_val_00030607.bin 224 224 +39056 ./prep_dataset/ILSVRC2012_val_00030003.bin 224 224 +39057 ./prep_dataset/ILSVRC2012_val_00013305.bin 224 224 +39058 ./prep_dataset/ILSVRC2012_val_00003142.bin 224 224 +39059 ./prep_dataset/ILSVRC2012_val_00001350.bin 224 224 +39060 ./prep_dataset/ILSVRC2012_val_00002999.bin 224 224 +39061 ./prep_dataset/ILSVRC2012_val_00021515.bin 224 224 +39062 ./prep_dataset/ILSVRC2012_val_00040261.bin 224 224 +39063 ./prep_dataset/ILSVRC2012_val_00009212.bin 224 224 +39064 ./prep_dataset/ILSVRC2012_val_00038160.bin 224 224 +39065 ./prep_dataset/ILSVRC2012_val_00044952.bin 224 224 +39066 ./prep_dataset/ILSVRC2012_val_00038786.bin 224 224 +39067 ./prep_dataset/ILSVRC2012_val_00045546.bin 224 224 +39068 ./prep_dataset/ILSVRC2012_val_00016612.bin 224 224 +39069 ./prep_dataset/ILSVRC2012_val_00007919.bin 224 224 +39070 ./prep_dataset/ILSVRC2012_val_00002949.bin 224 224 +39071 ./prep_dataset/ILSVRC2012_val_00005951.bin 224 224 +39072 ./prep_dataset/ILSVRC2012_val_00039213.bin 224 224 +39073 ./prep_dataset/ILSVRC2012_val_00002219.bin 224 224 +39074 ./prep_dataset/ILSVRC2012_val_00035206.bin 224 224 +39075 ./prep_dataset/ILSVRC2012_val_00016850.bin 224 224 +39076 ./prep_dataset/ILSVRC2012_val_00019438.bin 224 224 +39077 ./prep_dataset/ILSVRC2012_val_00011464.bin 224 224 +39078 ./prep_dataset/ILSVRC2012_val_00030800.bin 224 224 +39079 ./prep_dataset/ILSVRC2012_val_00019852.bin 224 224 +39080 ./prep_dataset/ILSVRC2012_val_00017930.bin 224 224 +39081 ./prep_dataset/ILSVRC2012_val_00006694.bin 224 224 +39082 ./prep_dataset/ILSVRC2012_val_00043204.bin 224 224 +39083 ./prep_dataset/ILSVRC2012_val_00010777.bin 224 224 +39084 ./prep_dataset/ILSVRC2012_val_00049803.bin 224 224 +39085 ./prep_dataset/ILSVRC2012_val_00006505.bin 224 224 +39086 ./prep_dataset/ILSVRC2012_val_00047902.bin 224 224 +39087 ./prep_dataset/ILSVRC2012_val_00023160.bin 224 224 +39088 ./prep_dataset/ILSVRC2012_val_00025636.bin 224 224 +39089 ./prep_dataset/ILSVRC2012_val_00019093.bin 224 224 +39090 ./prep_dataset/ILSVRC2012_val_00009405.bin 224 224 +39091 ./prep_dataset/ILSVRC2012_val_00018784.bin 224 224 +39092 ./prep_dataset/ILSVRC2012_val_00008831.bin 224 224 +39093 ./prep_dataset/ILSVRC2012_val_00043661.bin 224 224 +39094 ./prep_dataset/ILSVRC2012_val_00020556.bin 224 224 +39095 ./prep_dataset/ILSVRC2012_val_00036608.bin 224 224 +39096 ./prep_dataset/ILSVRC2012_val_00046806.bin 224 224 +39097 ./prep_dataset/ILSVRC2012_val_00004223.bin 224 224 +39098 ./prep_dataset/ILSVRC2012_val_00001510.bin 224 224 +39099 ./prep_dataset/ILSVRC2012_val_00025534.bin 224 224 +39100 ./prep_dataset/ILSVRC2012_val_00011925.bin 224 224 +39101 ./prep_dataset/ILSVRC2012_val_00015613.bin 224 224 +39102 ./prep_dataset/ILSVRC2012_val_00026885.bin 224 224 +39103 ./prep_dataset/ILSVRC2012_val_00017127.bin 224 224 +39104 ./prep_dataset/ILSVRC2012_val_00015731.bin 224 224 +39105 ./prep_dataset/ILSVRC2012_val_00016742.bin 224 224 +39106 ./prep_dataset/ILSVRC2012_val_00003285.bin 224 224 +39107 ./prep_dataset/ILSVRC2012_val_00017420.bin 224 224 +39108 ./prep_dataset/ILSVRC2012_val_00005849.bin 224 224 +39109 ./prep_dataset/ILSVRC2012_val_00022371.bin 224 224 +39110 ./prep_dataset/ILSVRC2012_val_00029986.bin 224 224 +39111 ./prep_dataset/ILSVRC2012_val_00029776.bin 224 224 +39112 ./prep_dataset/ILSVRC2012_val_00002751.bin 224 224 +39113 ./prep_dataset/ILSVRC2012_val_00005530.bin 224 224 +39114 ./prep_dataset/ILSVRC2012_val_00030617.bin 224 224 +39115 ./prep_dataset/ILSVRC2012_val_00008770.bin 224 224 +39116 ./prep_dataset/ILSVRC2012_val_00026186.bin 224 224 +39117 ./prep_dataset/ILSVRC2012_val_00004883.bin 224 224 +39118 ./prep_dataset/ILSVRC2012_val_00048301.bin 224 224 +39119 ./prep_dataset/ILSVRC2012_val_00035232.bin 224 224 +39120 ./prep_dataset/ILSVRC2012_val_00038120.bin 224 224 +39121 ./prep_dataset/ILSVRC2012_val_00032150.bin 224 224 +39122 ./prep_dataset/ILSVRC2012_val_00027071.bin 224 224 +39123 ./prep_dataset/ILSVRC2012_val_00029830.bin 224 224 +39124 ./prep_dataset/ILSVRC2012_val_00044693.bin 224 224 +39125 ./prep_dataset/ILSVRC2012_val_00003927.bin 224 224 +39126 ./prep_dataset/ILSVRC2012_val_00029610.bin 224 224 +39127 ./prep_dataset/ILSVRC2012_val_00006035.bin 224 224 +39128 ./prep_dataset/ILSVRC2012_val_00034962.bin 224 224 +39129 ./prep_dataset/ILSVRC2012_val_00044757.bin 224 224 +39130 ./prep_dataset/ILSVRC2012_val_00027989.bin 224 224 +39131 ./prep_dataset/ILSVRC2012_val_00000508.bin 224 224 +39132 ./prep_dataset/ILSVRC2012_val_00004381.bin 224 224 +39133 ./prep_dataset/ILSVRC2012_val_00046036.bin 224 224 +39134 ./prep_dataset/ILSVRC2012_val_00013755.bin 224 224 +39135 ./prep_dataset/ILSVRC2012_val_00031263.bin 224 224 +39136 ./prep_dataset/ILSVRC2012_val_00005278.bin 224 224 +39137 ./prep_dataset/ILSVRC2012_val_00020975.bin 224 224 +39138 ./prep_dataset/ILSVRC2012_val_00009251.bin 224 224 +39139 ./prep_dataset/ILSVRC2012_val_00049245.bin 224 224 +39140 ./prep_dataset/ILSVRC2012_val_00000914.bin 224 224 +39141 ./prep_dataset/ILSVRC2012_val_00048272.bin 224 224 +39142 ./prep_dataset/ILSVRC2012_val_00016716.bin 224 224 +39143 ./prep_dataset/ILSVRC2012_val_00012304.bin 224 224 +39144 ./prep_dataset/ILSVRC2012_val_00017941.bin 224 224 +39145 ./prep_dataset/ILSVRC2012_val_00040993.bin 224 224 +39146 ./prep_dataset/ILSVRC2012_val_00028685.bin 224 224 +39147 ./prep_dataset/ILSVRC2012_val_00031001.bin 224 224 +39148 ./prep_dataset/ILSVRC2012_val_00005903.bin 224 224 +39149 ./prep_dataset/ILSVRC2012_val_00049211.bin 224 224 +39150 ./prep_dataset/ILSVRC2012_val_00041253.bin 224 224 +39151 ./prep_dataset/ILSVRC2012_val_00042826.bin 224 224 +39152 ./prep_dataset/ILSVRC2012_val_00008804.bin 224 224 +39153 ./prep_dataset/ILSVRC2012_val_00032282.bin 224 224 +39154 ./prep_dataset/ILSVRC2012_val_00013716.bin 224 224 +39155 ./prep_dataset/ILSVRC2012_val_00023572.bin 224 224 +39156 ./prep_dataset/ILSVRC2012_val_00010967.bin 224 224 +39157 ./prep_dataset/ILSVRC2012_val_00011623.bin 224 224 +39158 ./prep_dataset/ILSVRC2012_val_00038561.bin 224 224 +39159 ./prep_dataset/ILSVRC2012_val_00041109.bin 224 224 +39160 ./prep_dataset/ILSVRC2012_val_00029730.bin 224 224 +39161 ./prep_dataset/ILSVRC2012_val_00004356.bin 224 224 +39162 ./prep_dataset/ILSVRC2012_val_00025303.bin 224 224 +39163 ./prep_dataset/ILSVRC2012_val_00016892.bin 224 224 +39164 ./prep_dataset/ILSVRC2012_val_00016938.bin 224 224 +39165 ./prep_dataset/ILSVRC2012_val_00009322.bin 224 224 +39166 ./prep_dataset/ILSVRC2012_val_00042858.bin 224 224 +39167 ./prep_dataset/ILSVRC2012_val_00014755.bin 224 224 +39168 ./prep_dataset/ILSVRC2012_val_00032661.bin 224 224 +39169 ./prep_dataset/ILSVRC2012_val_00040378.bin 224 224 +39170 ./prep_dataset/ILSVRC2012_val_00044851.bin 224 224 +39171 ./prep_dataset/ILSVRC2012_val_00030442.bin 224 224 +39172 ./prep_dataset/ILSVRC2012_val_00022628.bin 224 224 +39173 ./prep_dataset/ILSVRC2012_val_00031459.bin 224 224 +39174 ./prep_dataset/ILSVRC2012_val_00019517.bin 224 224 +39175 ./prep_dataset/ILSVRC2012_val_00037915.bin 224 224 +39176 ./prep_dataset/ILSVRC2012_val_00035977.bin 224 224 +39177 ./prep_dataset/ILSVRC2012_val_00023528.bin 224 224 +39178 ./prep_dataset/ILSVRC2012_val_00025774.bin 224 224 +39179 ./prep_dataset/ILSVRC2012_val_00028909.bin 224 224 +39180 ./prep_dataset/ILSVRC2012_val_00042273.bin 224 224 +39181 ./prep_dataset/ILSVRC2012_val_00012832.bin 224 224 +39182 ./prep_dataset/ILSVRC2012_val_00022441.bin 224 224 +39183 ./prep_dataset/ILSVRC2012_val_00036035.bin 224 224 +39184 ./prep_dataset/ILSVRC2012_val_00011793.bin 224 224 +39185 ./prep_dataset/ILSVRC2012_val_00002536.bin 224 224 +39186 ./prep_dataset/ILSVRC2012_val_00049808.bin 224 224 +39187 ./prep_dataset/ILSVRC2012_val_00011013.bin 224 224 +39188 ./prep_dataset/ILSVRC2012_val_00040646.bin 224 224 +39189 ./prep_dataset/ILSVRC2012_val_00046043.bin 224 224 +39190 ./prep_dataset/ILSVRC2012_val_00010177.bin 224 224 +39191 ./prep_dataset/ILSVRC2012_val_00035858.bin 224 224 +39192 ./prep_dataset/ILSVRC2012_val_00003346.bin 224 224 +39193 ./prep_dataset/ILSVRC2012_val_00034402.bin 224 224 +39194 ./prep_dataset/ILSVRC2012_val_00042369.bin 224 224 +39195 ./prep_dataset/ILSVRC2012_val_00047573.bin 224 224 +39196 ./prep_dataset/ILSVRC2012_val_00049084.bin 224 224 +39197 ./prep_dataset/ILSVRC2012_val_00028460.bin 224 224 +39198 ./prep_dataset/ILSVRC2012_val_00031712.bin 224 224 +39199 ./prep_dataset/ILSVRC2012_val_00028126.bin 224 224 +39200 ./prep_dataset/ILSVRC2012_val_00009050.bin 224 224 +39201 ./prep_dataset/ILSVRC2012_val_00020241.bin 224 224 +39202 ./prep_dataset/ILSVRC2012_val_00019726.bin 224 224 +39203 ./prep_dataset/ILSVRC2012_val_00008209.bin 224 224 +39204 ./prep_dataset/ILSVRC2012_val_00003547.bin 224 224 +39205 ./prep_dataset/ILSVRC2012_val_00007195.bin 224 224 +39206 ./prep_dataset/ILSVRC2012_val_00011929.bin 224 224 +39207 ./prep_dataset/ILSVRC2012_val_00006432.bin 224 224 +39208 ./prep_dataset/ILSVRC2012_val_00032096.bin 224 224 +39209 ./prep_dataset/ILSVRC2012_val_00003478.bin 224 224 +39210 ./prep_dataset/ILSVRC2012_val_00011653.bin 224 224 +39211 ./prep_dataset/ILSVRC2012_val_00025375.bin 224 224 +39212 ./prep_dataset/ILSVRC2012_val_00029016.bin 224 224 +39213 ./prep_dataset/ILSVRC2012_val_00005345.bin 224 224 +39214 ./prep_dataset/ILSVRC2012_val_00040397.bin 224 224 +39215 ./prep_dataset/ILSVRC2012_val_00021595.bin 224 224 +39216 ./prep_dataset/ILSVRC2012_val_00008451.bin 224 224 +39217 ./prep_dataset/ILSVRC2012_val_00027689.bin 224 224 +39218 ./prep_dataset/ILSVRC2012_val_00020912.bin 224 224 +39219 ./prep_dataset/ILSVRC2012_val_00033622.bin 224 224 +39220 ./prep_dataset/ILSVRC2012_val_00030427.bin 224 224 +39221 ./prep_dataset/ILSVRC2012_val_00006192.bin 224 224 +39222 ./prep_dataset/ILSVRC2012_val_00004031.bin 224 224 +39223 ./prep_dataset/ILSVRC2012_val_00002669.bin 224 224 +39224 ./prep_dataset/ILSVRC2012_val_00031065.bin 224 224 +39225 ./prep_dataset/ILSVRC2012_val_00037556.bin 224 224 +39226 ./prep_dataset/ILSVRC2012_val_00028554.bin 224 224 +39227 ./prep_dataset/ILSVRC2012_val_00022951.bin 224 224 +39228 ./prep_dataset/ILSVRC2012_val_00023480.bin 224 224 +39229 ./prep_dataset/ILSVRC2012_val_00015164.bin 224 224 +39230 ./prep_dataset/ILSVRC2012_val_00028945.bin 224 224 +39231 ./prep_dataset/ILSVRC2012_val_00020209.bin 224 224 +39232 ./prep_dataset/ILSVRC2012_val_00016975.bin 224 224 +39233 ./prep_dataset/ILSVRC2012_val_00033370.bin 224 224 +39234 ./prep_dataset/ILSVRC2012_val_00048694.bin 224 224 +39235 ./prep_dataset/ILSVRC2012_val_00000763.bin 224 224 +39236 ./prep_dataset/ILSVRC2012_val_00013528.bin 224 224 +39237 ./prep_dataset/ILSVRC2012_val_00028239.bin 224 224 +39238 ./prep_dataset/ILSVRC2012_val_00009960.bin 224 224 +39239 ./prep_dataset/ILSVRC2012_val_00015796.bin 224 224 +39240 ./prep_dataset/ILSVRC2012_val_00010490.bin 224 224 +39241 ./prep_dataset/ILSVRC2012_val_00015493.bin 224 224 +39242 ./prep_dataset/ILSVRC2012_val_00048929.bin 224 224 +39243 ./prep_dataset/ILSVRC2012_val_00005252.bin 224 224 +39244 ./prep_dataset/ILSVRC2012_val_00004075.bin 224 224 +39245 ./prep_dataset/ILSVRC2012_val_00034456.bin 224 224 +39246 ./prep_dataset/ILSVRC2012_val_00013377.bin 224 224 +39247 ./prep_dataset/ILSVRC2012_val_00043153.bin 224 224 +39248 ./prep_dataset/ILSVRC2012_val_00013093.bin 224 224 +39249 ./prep_dataset/ILSVRC2012_val_00010281.bin 224 224 +39250 ./prep_dataset/ILSVRC2012_val_00010723.bin 224 224 +39251 ./prep_dataset/ILSVRC2012_val_00006478.bin 224 224 +39252 ./prep_dataset/ILSVRC2012_val_00002139.bin 224 224 +39253 ./prep_dataset/ILSVRC2012_val_00010418.bin 224 224 +39254 ./prep_dataset/ILSVRC2012_val_00020808.bin 224 224 +39255 ./prep_dataset/ILSVRC2012_val_00014613.bin 224 224 +39256 ./prep_dataset/ILSVRC2012_val_00041274.bin 224 224 +39257 ./prep_dataset/ILSVRC2012_val_00008022.bin 224 224 +39258 ./prep_dataset/ILSVRC2012_val_00032620.bin 224 224 +39259 ./prep_dataset/ILSVRC2012_val_00049269.bin 224 224 +39260 ./prep_dataset/ILSVRC2012_val_00046175.bin 224 224 +39261 ./prep_dataset/ILSVRC2012_val_00027445.bin 224 224 +39262 ./prep_dataset/ILSVRC2012_val_00027720.bin 224 224 +39263 ./prep_dataset/ILSVRC2012_val_00000921.bin 224 224 +39264 ./prep_dataset/ILSVRC2012_val_00032439.bin 224 224 +39265 ./prep_dataset/ILSVRC2012_val_00028726.bin 224 224 +39266 ./prep_dataset/ILSVRC2012_val_00008207.bin 224 224 +39267 ./prep_dataset/ILSVRC2012_val_00044596.bin 224 224 +39268 ./prep_dataset/ILSVRC2012_val_00013125.bin 224 224 +39269 ./prep_dataset/ILSVRC2012_val_00001741.bin 224 224 +39270 ./prep_dataset/ILSVRC2012_val_00003020.bin 224 224 +39271 ./prep_dataset/ILSVRC2012_val_00011056.bin 224 224 +39272 ./prep_dataset/ILSVRC2012_val_00027341.bin 224 224 +39273 ./prep_dataset/ILSVRC2012_val_00035482.bin 224 224 +39274 ./prep_dataset/ILSVRC2012_val_00010140.bin 224 224 +39275 ./prep_dataset/ILSVRC2012_val_00009431.bin 224 224 +39276 ./prep_dataset/ILSVRC2012_val_00031524.bin 224 224 +39277 ./prep_dataset/ILSVRC2012_val_00011068.bin 224 224 +39278 ./prep_dataset/ILSVRC2012_val_00008008.bin 224 224 +39279 ./prep_dataset/ILSVRC2012_val_00042743.bin 224 224 +39280 ./prep_dataset/ILSVRC2012_val_00000590.bin 224 224 +39281 ./prep_dataset/ILSVRC2012_val_00040018.bin 224 224 +39282 ./prep_dataset/ILSVRC2012_val_00020571.bin 224 224 +39283 ./prep_dataset/ILSVRC2012_val_00033125.bin 224 224 +39284 ./prep_dataset/ILSVRC2012_val_00015449.bin 224 224 +39285 ./prep_dataset/ILSVRC2012_val_00043701.bin 224 224 +39286 ./prep_dataset/ILSVRC2012_val_00035365.bin 224 224 +39287 ./prep_dataset/ILSVRC2012_val_00025254.bin 224 224 +39288 ./prep_dataset/ILSVRC2012_val_00038294.bin 224 224 +39289 ./prep_dataset/ILSVRC2012_val_00047895.bin 224 224 +39290 ./prep_dataset/ILSVRC2012_val_00022001.bin 224 224 +39291 ./prep_dataset/ILSVRC2012_val_00028180.bin 224 224 +39292 ./prep_dataset/ILSVRC2012_val_00034385.bin 224 224 +39293 ./prep_dataset/ILSVRC2012_val_00042409.bin 224 224 +39294 ./prep_dataset/ILSVRC2012_val_00016649.bin 224 224 +39295 ./prep_dataset/ILSVRC2012_val_00026906.bin 224 224 +39296 ./prep_dataset/ILSVRC2012_val_00028339.bin 224 224 +39297 ./prep_dataset/ILSVRC2012_val_00036587.bin 224 224 +39298 ./prep_dataset/ILSVRC2012_val_00046005.bin 224 224 +39299 ./prep_dataset/ILSVRC2012_val_00020021.bin 224 224 +39300 ./prep_dataset/ILSVRC2012_val_00047855.bin 224 224 +39301 ./prep_dataset/ILSVRC2012_val_00046420.bin 224 224 +39302 ./prep_dataset/ILSVRC2012_val_00031059.bin 224 224 +39303 ./prep_dataset/ILSVRC2012_val_00010544.bin 224 224 +39304 ./prep_dataset/ILSVRC2012_val_00043050.bin 224 224 +39305 ./prep_dataset/ILSVRC2012_val_00013156.bin 224 224 +39306 ./prep_dataset/ILSVRC2012_val_00027107.bin 224 224 +39307 ./prep_dataset/ILSVRC2012_val_00018976.bin 224 224 +39308 ./prep_dataset/ILSVRC2012_val_00046434.bin 224 224 +39309 ./prep_dataset/ILSVRC2012_val_00033930.bin 224 224 +39310 ./prep_dataset/ILSVRC2012_val_00048975.bin 224 224 +39311 ./prep_dataset/ILSVRC2012_val_00030523.bin 224 224 +39312 ./prep_dataset/ILSVRC2012_val_00002575.bin 224 224 +39313 ./prep_dataset/ILSVRC2012_val_00007988.bin 224 224 +39314 ./prep_dataset/ILSVRC2012_val_00048302.bin 224 224 +39315 ./prep_dataset/ILSVRC2012_val_00030184.bin 224 224 +39316 ./prep_dataset/ILSVRC2012_val_00004245.bin 224 224 +39317 ./prep_dataset/ILSVRC2012_val_00022510.bin 224 224 +39318 ./prep_dataset/ILSVRC2012_val_00043368.bin 224 224 +39319 ./prep_dataset/ILSVRC2012_val_00013982.bin 224 224 +39320 ./prep_dataset/ILSVRC2012_val_00036165.bin 224 224 +39321 ./prep_dataset/ILSVRC2012_val_00048963.bin 224 224 +39322 ./prep_dataset/ILSVRC2012_val_00030512.bin 224 224 +39323 ./prep_dataset/ILSVRC2012_val_00038169.bin 224 224 +39324 ./prep_dataset/ILSVRC2012_val_00005427.bin 224 224 +39325 ./prep_dataset/ILSVRC2012_val_00038772.bin 224 224 +39326 ./prep_dataset/ILSVRC2012_val_00027788.bin 224 224 +39327 ./prep_dataset/ILSVRC2012_val_00018238.bin 224 224 +39328 ./prep_dataset/ILSVRC2012_val_00000188.bin 224 224 +39329 ./prep_dataset/ILSVRC2012_val_00035894.bin 224 224 +39330 ./prep_dataset/ILSVRC2012_val_00006631.bin 224 224 +39331 ./prep_dataset/ILSVRC2012_val_00021147.bin 224 224 +39332 ./prep_dataset/ILSVRC2012_val_00020942.bin 224 224 +39333 ./prep_dataset/ILSVRC2012_val_00022540.bin 224 224 +39334 ./prep_dataset/ILSVRC2012_val_00007191.bin 224 224 +39335 ./prep_dataset/ILSVRC2012_val_00043834.bin 224 224 +39336 ./prep_dataset/ILSVRC2012_val_00019914.bin 224 224 +39337 ./prep_dataset/ILSVRC2012_val_00020513.bin 224 224 +39338 ./prep_dataset/ILSVRC2012_val_00016415.bin 224 224 +39339 ./prep_dataset/ILSVRC2012_val_00036647.bin 224 224 +39340 ./prep_dataset/ILSVRC2012_val_00007240.bin 224 224 +39341 ./prep_dataset/ILSVRC2012_val_00013134.bin 224 224 +39342 ./prep_dataset/ILSVRC2012_val_00047743.bin 224 224 +39343 ./prep_dataset/ILSVRC2012_val_00016454.bin 224 224 +39344 ./prep_dataset/ILSVRC2012_val_00033057.bin 224 224 +39345 ./prep_dataset/ILSVRC2012_val_00033706.bin 224 224 +39346 ./prep_dataset/ILSVRC2012_val_00043419.bin 224 224 +39347 ./prep_dataset/ILSVRC2012_val_00020226.bin 224 224 +39348 ./prep_dataset/ILSVRC2012_val_00038884.bin 224 224 +39349 ./prep_dataset/ILSVRC2012_val_00013327.bin 224 224 +39350 ./prep_dataset/ILSVRC2012_val_00033662.bin 224 224 +39351 ./prep_dataset/ILSVRC2012_val_00013236.bin 224 224 +39352 ./prep_dataset/ILSVRC2012_val_00028450.bin 224 224 +39353 ./prep_dataset/ILSVRC2012_val_00001561.bin 224 224 +39354 ./prep_dataset/ILSVRC2012_val_00007030.bin 224 224 +39355 ./prep_dataset/ILSVRC2012_val_00024444.bin 224 224 +39356 ./prep_dataset/ILSVRC2012_val_00041598.bin 224 224 +39357 ./prep_dataset/ILSVRC2012_val_00013403.bin 224 224 +39358 ./prep_dataset/ILSVRC2012_val_00048985.bin 224 224 +39359 ./prep_dataset/ILSVRC2012_val_00036134.bin 224 224 +39360 ./prep_dataset/ILSVRC2012_val_00002635.bin 224 224 +39361 ./prep_dataset/ILSVRC2012_val_00015533.bin 224 224 +39362 ./prep_dataset/ILSVRC2012_val_00031620.bin 224 224 +39363 ./prep_dataset/ILSVRC2012_val_00037887.bin 224 224 +39364 ./prep_dataset/ILSVRC2012_val_00027524.bin 224 224 +39365 ./prep_dataset/ILSVRC2012_val_00011674.bin 224 224 +39366 ./prep_dataset/ILSVRC2012_val_00038663.bin 224 224 +39367 ./prep_dataset/ILSVRC2012_val_00046645.bin 224 224 +39368 ./prep_dataset/ILSVRC2012_val_00007299.bin 224 224 +39369 ./prep_dataset/ILSVRC2012_val_00024527.bin 224 224 +39370 ./prep_dataset/ILSVRC2012_val_00043689.bin 224 224 +39371 ./prep_dataset/ILSVRC2012_val_00028429.bin 224 224 +39372 ./prep_dataset/ILSVRC2012_val_00041763.bin 224 224 +39373 ./prep_dataset/ILSVRC2012_val_00008219.bin 224 224 +39374 ./prep_dataset/ILSVRC2012_val_00018715.bin 224 224 +39375 ./prep_dataset/ILSVRC2012_val_00032038.bin 224 224 +39376 ./prep_dataset/ILSVRC2012_val_00043590.bin 224 224 +39377 ./prep_dataset/ILSVRC2012_val_00046984.bin 224 224 +39378 ./prep_dataset/ILSVRC2012_val_00012645.bin 224 224 +39379 ./prep_dataset/ILSVRC2012_val_00014704.bin 224 224 +39380 ./prep_dataset/ILSVRC2012_val_00018545.bin 224 224 +39381 ./prep_dataset/ILSVRC2012_val_00039116.bin 224 224 +39382 ./prep_dataset/ILSVRC2012_val_00035318.bin 224 224 +39383 ./prep_dataset/ILSVRC2012_val_00006262.bin 224 224 +39384 ./prep_dataset/ILSVRC2012_val_00045523.bin 224 224 +39385 ./prep_dataset/ILSVRC2012_val_00024443.bin 224 224 +39386 ./prep_dataset/ILSVRC2012_val_00020727.bin 224 224 +39387 ./prep_dataset/ILSVRC2012_val_00019743.bin 224 224 +39388 ./prep_dataset/ILSVRC2012_val_00021955.bin 224 224 +39389 ./prep_dataset/ILSVRC2012_val_00032724.bin 224 224 +39390 ./prep_dataset/ILSVRC2012_val_00021969.bin 224 224 +39391 ./prep_dataset/ILSVRC2012_val_00016834.bin 224 224 +39392 ./prep_dataset/ILSVRC2012_val_00025866.bin 224 224 +39393 ./prep_dataset/ILSVRC2012_val_00021933.bin 224 224 +39394 ./prep_dataset/ILSVRC2012_val_00026732.bin 224 224 +39395 ./prep_dataset/ILSVRC2012_val_00037082.bin 224 224 +39396 ./prep_dataset/ILSVRC2012_val_00026891.bin 224 224 +39397 ./prep_dataset/ILSVRC2012_val_00033103.bin 224 224 +39398 ./prep_dataset/ILSVRC2012_val_00045364.bin 224 224 +39399 ./prep_dataset/ILSVRC2012_val_00038353.bin 224 224 +39400 ./prep_dataset/ILSVRC2012_val_00008348.bin 224 224 +39401 ./prep_dataset/ILSVRC2012_val_00026607.bin 224 224 +39402 ./prep_dataset/ILSVRC2012_val_00023415.bin 224 224 +39403 ./prep_dataset/ILSVRC2012_val_00036119.bin 224 224 +39404 ./prep_dataset/ILSVRC2012_val_00017990.bin 224 224 +39405 ./prep_dataset/ILSVRC2012_val_00011745.bin 224 224 +39406 ./prep_dataset/ILSVRC2012_val_00012686.bin 224 224 +39407 ./prep_dataset/ILSVRC2012_val_00030093.bin 224 224 +39408 ./prep_dataset/ILSVRC2012_val_00013349.bin 224 224 +39409 ./prep_dataset/ILSVRC2012_val_00040805.bin 224 224 +39410 ./prep_dataset/ILSVRC2012_val_00030192.bin 224 224 +39411 ./prep_dataset/ILSVRC2012_val_00008559.bin 224 224 +39412 ./prep_dataset/ILSVRC2012_val_00018220.bin 224 224 +39413 ./prep_dataset/ILSVRC2012_val_00018322.bin 224 224 +39414 ./prep_dataset/ILSVRC2012_val_00026528.bin 224 224 +39415 ./prep_dataset/ILSVRC2012_val_00013447.bin 224 224 +39416 ./prep_dataset/ILSVRC2012_val_00040365.bin 224 224 +39417 ./prep_dataset/ILSVRC2012_val_00025359.bin 224 224 +39418 ./prep_dataset/ILSVRC2012_val_00032076.bin 224 224 +39419 ./prep_dataset/ILSVRC2012_val_00012718.bin 224 224 +39420 ./prep_dataset/ILSVRC2012_val_00046934.bin 224 224 +39421 ./prep_dataset/ILSVRC2012_val_00044180.bin 224 224 +39422 ./prep_dataset/ILSVRC2012_val_00021960.bin 224 224 +39423 ./prep_dataset/ILSVRC2012_val_00038415.bin 224 224 +39424 ./prep_dataset/ILSVRC2012_val_00033371.bin 224 224 +39425 ./prep_dataset/ILSVRC2012_val_00011869.bin 224 224 +39426 ./prep_dataset/ILSVRC2012_val_00023143.bin 224 224 +39427 ./prep_dataset/ILSVRC2012_val_00032257.bin 224 224 +39428 ./prep_dataset/ILSVRC2012_val_00035695.bin 224 224 +39429 ./prep_dataset/ILSVRC2012_val_00048810.bin 224 224 +39430 ./prep_dataset/ILSVRC2012_val_00032028.bin 224 224 +39431 ./prep_dataset/ILSVRC2012_val_00026340.bin 224 224 +39432 ./prep_dataset/ILSVRC2012_val_00019944.bin 224 224 +39433 ./prep_dataset/ILSVRC2012_val_00015690.bin 224 224 +39434 ./prep_dataset/ILSVRC2012_val_00003103.bin 224 224 +39435 ./prep_dataset/ILSVRC2012_val_00036087.bin 224 224 +39436 ./prep_dataset/ILSVRC2012_val_00027657.bin 224 224 +39437 ./prep_dataset/ILSVRC2012_val_00010942.bin 224 224 +39438 ./prep_dataset/ILSVRC2012_val_00033629.bin 224 224 +39439 ./prep_dataset/ILSVRC2012_val_00039474.bin 224 224 +39440 ./prep_dataset/ILSVRC2012_val_00029366.bin 224 224 +39441 ./prep_dataset/ILSVRC2012_val_00009651.bin 224 224 +39442 ./prep_dataset/ILSVRC2012_val_00046587.bin 224 224 +39443 ./prep_dataset/ILSVRC2012_val_00044409.bin 224 224 +39444 ./prep_dataset/ILSVRC2012_val_00011779.bin 224 224 +39445 ./prep_dataset/ILSVRC2012_val_00002452.bin 224 224 +39446 ./prep_dataset/ILSVRC2012_val_00015228.bin 224 224 +39447 ./prep_dataset/ILSVRC2012_val_00027604.bin 224 224 +39448 ./prep_dataset/ILSVRC2012_val_00018729.bin 224 224 +39449 ./prep_dataset/ILSVRC2012_val_00034946.bin 224 224 +39450 ./prep_dataset/ILSVRC2012_val_00014464.bin 224 224 +39451 ./prep_dataset/ILSVRC2012_val_00006883.bin 224 224 +39452 ./prep_dataset/ILSVRC2012_val_00025210.bin 224 224 +39453 ./prep_dataset/ILSVRC2012_val_00010670.bin 224 224 +39454 ./prep_dataset/ILSVRC2012_val_00046989.bin 224 224 +39455 ./prep_dataset/ILSVRC2012_val_00035774.bin 224 224 +39456 ./prep_dataset/ILSVRC2012_val_00043411.bin 224 224 +39457 ./prep_dataset/ILSVRC2012_val_00032317.bin 224 224 +39458 ./prep_dataset/ILSVRC2012_val_00028458.bin 224 224 +39459 ./prep_dataset/ILSVRC2012_val_00049794.bin 224 224 +39460 ./prep_dataset/ILSVRC2012_val_00022528.bin 224 224 +39461 ./prep_dataset/ILSVRC2012_val_00004665.bin 224 224 +39462 ./prep_dataset/ILSVRC2012_val_00039984.bin 224 224 +39463 ./prep_dataset/ILSVRC2012_val_00006695.bin 224 224 +39464 ./prep_dataset/ILSVRC2012_val_00015294.bin 224 224 +39465 ./prep_dataset/ILSVRC2012_val_00015999.bin 224 224 +39466 ./prep_dataset/ILSVRC2012_val_00043188.bin 224 224 +39467 ./prep_dataset/ILSVRC2012_val_00007889.bin 224 224 +39468 ./prep_dataset/ILSVRC2012_val_00007819.bin 224 224 +39469 ./prep_dataset/ILSVRC2012_val_00007399.bin 224 224 +39470 ./prep_dataset/ILSVRC2012_val_00039205.bin 224 224 +39471 ./prep_dataset/ILSVRC2012_val_00009561.bin 224 224 +39472 ./prep_dataset/ILSVRC2012_val_00002225.bin 224 224 +39473 ./prep_dataset/ILSVRC2012_val_00016685.bin 224 224 +39474 ./prep_dataset/ILSVRC2012_val_00046351.bin 224 224 +39475 ./prep_dataset/ILSVRC2012_val_00049766.bin 224 224 +39476 ./prep_dataset/ILSVRC2012_val_00027575.bin 224 224 +39477 ./prep_dataset/ILSVRC2012_val_00046878.bin 224 224 +39478 ./prep_dataset/ILSVRC2012_val_00049973.bin 224 224 +39479 ./prep_dataset/ILSVRC2012_val_00007940.bin 224 224 +39480 ./prep_dataset/ILSVRC2012_val_00032347.bin 224 224 +39481 ./prep_dataset/ILSVRC2012_val_00038185.bin 224 224 +39482 ./prep_dataset/ILSVRC2012_val_00015540.bin 224 224 +39483 ./prep_dataset/ILSVRC2012_val_00043222.bin 224 224 +39484 ./prep_dataset/ILSVRC2012_val_00027307.bin 224 224 +39485 ./prep_dataset/ILSVRC2012_val_00021249.bin 224 224 +39486 ./prep_dataset/ILSVRC2012_val_00013247.bin 224 224 +39487 ./prep_dataset/ILSVRC2012_val_00026429.bin 224 224 +39488 ./prep_dataset/ILSVRC2012_val_00047202.bin 224 224 +39489 ./prep_dataset/ILSVRC2012_val_00009643.bin 224 224 +39490 ./prep_dataset/ILSVRC2012_val_00005601.bin 224 224 +39491 ./prep_dataset/ILSVRC2012_val_00006827.bin 224 224 +39492 ./prep_dataset/ILSVRC2012_val_00028478.bin 224 224 +39493 ./prep_dataset/ILSVRC2012_val_00036171.bin 224 224 +39494 ./prep_dataset/ILSVRC2012_val_00015270.bin 224 224 +39495 ./prep_dataset/ILSVRC2012_val_00024269.bin 224 224 +39496 ./prep_dataset/ILSVRC2012_val_00004768.bin 224 224 +39497 ./prep_dataset/ILSVRC2012_val_00011839.bin 224 224 +39498 ./prep_dataset/ILSVRC2012_val_00041756.bin 224 224 +39499 ./prep_dataset/ILSVRC2012_val_00047260.bin 224 224 +39500 ./prep_dataset/ILSVRC2012_val_00048795.bin 224 224 +39501 ./prep_dataset/ILSVRC2012_val_00014771.bin 224 224 +39502 ./prep_dataset/ILSVRC2012_val_00000913.bin 224 224 +39503 ./prep_dataset/ILSVRC2012_val_00030705.bin 224 224 +39504 ./prep_dataset/ILSVRC2012_val_00031232.bin 224 224 +39505 ./prep_dataset/ILSVRC2012_val_00014274.bin 224 224 +39506 ./prep_dataset/ILSVRC2012_val_00011669.bin 224 224 +39507 ./prep_dataset/ILSVRC2012_val_00029523.bin 224 224 +39508 ./prep_dataset/ILSVRC2012_val_00024393.bin 224 224 +39509 ./prep_dataset/ILSVRC2012_val_00048047.bin 224 224 +39510 ./prep_dataset/ILSVRC2012_val_00024551.bin 224 224 +39511 ./prep_dataset/ILSVRC2012_val_00047935.bin 224 224 +39512 ./prep_dataset/ILSVRC2012_val_00034330.bin 224 224 +39513 ./prep_dataset/ILSVRC2012_val_00043932.bin 224 224 +39514 ./prep_dataset/ILSVRC2012_val_00025537.bin 224 224 +39515 ./prep_dataset/ILSVRC2012_val_00033855.bin 224 224 +39516 ./prep_dataset/ILSVRC2012_val_00034678.bin 224 224 +39517 ./prep_dataset/ILSVRC2012_val_00046237.bin 224 224 +39518 ./prep_dataset/ILSVRC2012_val_00027594.bin 224 224 +39519 ./prep_dataset/ILSVRC2012_val_00007298.bin 224 224 +39520 ./prep_dataset/ILSVRC2012_val_00015574.bin 224 224 +39521 ./prep_dataset/ILSVRC2012_val_00024373.bin 224 224 +39522 ./prep_dataset/ILSVRC2012_val_00049049.bin 224 224 +39523 ./prep_dataset/ILSVRC2012_val_00011790.bin 224 224 +39524 ./prep_dataset/ILSVRC2012_val_00035336.bin 224 224 +39525 ./prep_dataset/ILSVRC2012_val_00044533.bin 224 224 +39526 ./prep_dataset/ILSVRC2012_val_00022122.bin 224 224 +39527 ./prep_dataset/ILSVRC2012_val_00047298.bin 224 224 +39528 ./prep_dataset/ILSVRC2012_val_00019144.bin 224 224 +39529 ./prep_dataset/ILSVRC2012_val_00044232.bin 224 224 +39530 ./prep_dataset/ILSVRC2012_val_00033001.bin 224 224 +39531 ./prep_dataset/ILSVRC2012_val_00023497.bin 224 224 +39532 ./prep_dataset/ILSVRC2012_val_00039778.bin 224 224 +39533 ./prep_dataset/ILSVRC2012_val_00022318.bin 224 224 +39534 ./prep_dataset/ILSVRC2012_val_00033181.bin 224 224 +39535 ./prep_dataset/ILSVRC2012_val_00049895.bin 224 224 +39536 ./prep_dataset/ILSVRC2012_val_00020420.bin 224 224 +39537 ./prep_dataset/ILSVRC2012_val_00046384.bin 224 224 +39538 ./prep_dataset/ILSVRC2012_val_00038959.bin 224 224 +39539 ./prep_dataset/ILSVRC2012_val_00013875.bin 224 224 +39540 ./prep_dataset/ILSVRC2012_val_00018339.bin 224 224 +39541 ./prep_dataset/ILSVRC2012_val_00021322.bin 224 224 +39542 ./prep_dataset/ILSVRC2012_val_00044381.bin 224 224 +39543 ./prep_dataset/ILSVRC2012_val_00045729.bin 224 224 +39544 ./prep_dataset/ILSVRC2012_val_00020171.bin 224 224 +39545 ./prep_dataset/ILSVRC2012_val_00007466.bin 224 224 +39546 ./prep_dataset/ILSVRC2012_val_00044621.bin 224 224 +39547 ./prep_dataset/ILSVRC2012_val_00025199.bin 224 224 +39548 ./prep_dataset/ILSVRC2012_val_00020729.bin 224 224 +39549 ./prep_dataset/ILSVRC2012_val_00030348.bin 224 224 +39550 ./prep_dataset/ILSVRC2012_val_00042047.bin 224 224 +39551 ./prep_dataset/ILSVRC2012_val_00029883.bin 224 224 +39552 ./prep_dataset/ILSVRC2012_val_00037289.bin 224 224 +39553 ./prep_dataset/ILSVRC2012_val_00024993.bin 224 224 +39554 ./prep_dataset/ILSVRC2012_val_00011879.bin 224 224 +39555 ./prep_dataset/ILSVRC2012_val_00045137.bin 224 224 +39556 ./prep_dataset/ILSVRC2012_val_00030172.bin 224 224 +39557 ./prep_dataset/ILSVRC2012_val_00004247.bin 224 224 +39558 ./prep_dataset/ILSVRC2012_val_00012442.bin 224 224 +39559 ./prep_dataset/ILSVRC2012_val_00033129.bin 224 224 +39560 ./prep_dataset/ILSVRC2012_val_00006979.bin 224 224 +39561 ./prep_dataset/ILSVRC2012_val_00025374.bin 224 224 +39562 ./prep_dataset/ILSVRC2012_val_00010834.bin 224 224 +39563 ./prep_dataset/ILSVRC2012_val_00029032.bin 224 224 +39564 ./prep_dataset/ILSVRC2012_val_00046533.bin 224 224 +39565 ./prep_dataset/ILSVRC2012_val_00049802.bin 224 224 +39566 ./prep_dataset/ILSVRC2012_val_00043338.bin 224 224 +39567 ./prep_dataset/ILSVRC2012_val_00049858.bin 224 224 +39568 ./prep_dataset/ILSVRC2012_val_00002585.bin 224 224 +39569 ./prep_dataset/ILSVRC2012_val_00037218.bin 224 224 +39570 ./prep_dataset/ILSVRC2012_val_00031474.bin 224 224 +39571 ./prep_dataset/ILSVRC2012_val_00000743.bin 224 224 +39572 ./prep_dataset/ILSVRC2012_val_00047057.bin 224 224 +39573 ./prep_dataset/ILSVRC2012_val_00001675.bin 224 224 +39574 ./prep_dataset/ILSVRC2012_val_00011826.bin 224 224 +39575 ./prep_dataset/ILSVRC2012_val_00033473.bin 224 224 +39576 ./prep_dataset/ILSVRC2012_val_00026170.bin 224 224 +39577 ./prep_dataset/ILSVRC2012_val_00014318.bin 224 224 +39578 ./prep_dataset/ILSVRC2012_val_00010014.bin 224 224 +39579 ./prep_dataset/ILSVRC2012_val_00039382.bin 224 224 +39580 ./prep_dataset/ILSVRC2012_val_00007589.bin 224 224 +39581 ./prep_dataset/ILSVRC2012_val_00030882.bin 224 224 +39582 ./prep_dataset/ILSVRC2012_val_00014321.bin 224 224 +39583 ./prep_dataset/ILSVRC2012_val_00024222.bin 224 224 +39584 ./prep_dataset/ILSVRC2012_val_00002587.bin 224 224 +39585 ./prep_dataset/ILSVRC2012_val_00003386.bin 224 224 +39586 ./prep_dataset/ILSVRC2012_val_00032738.bin 224 224 +39587 ./prep_dataset/ILSVRC2012_val_00009203.bin 224 224 +39588 ./prep_dataset/ILSVRC2012_val_00010800.bin 224 224 +39589 ./prep_dataset/ILSVRC2012_val_00004471.bin 224 224 +39590 ./prep_dataset/ILSVRC2012_val_00004992.bin 224 224 +39591 ./prep_dataset/ILSVRC2012_val_00020586.bin 224 224 +39592 ./prep_dataset/ILSVRC2012_val_00005357.bin 224 224 +39593 ./prep_dataset/ILSVRC2012_val_00028491.bin 224 224 +39594 ./prep_dataset/ILSVRC2012_val_00023321.bin 224 224 +39595 ./prep_dataset/ILSVRC2012_val_00028949.bin 224 224 +39596 ./prep_dataset/ILSVRC2012_val_00015621.bin 224 224 +39597 ./prep_dataset/ILSVRC2012_val_00030269.bin 224 224 +39598 ./prep_dataset/ILSVRC2012_val_00028343.bin 224 224 +39599 ./prep_dataset/ILSVRC2012_val_00040280.bin 224 224 +39600 ./prep_dataset/ILSVRC2012_val_00025875.bin 224 224 +39601 ./prep_dataset/ILSVRC2012_val_00039718.bin 224 224 +39602 ./prep_dataset/ILSVRC2012_val_00027346.bin 224 224 +39603 ./prep_dataset/ILSVRC2012_val_00024876.bin 224 224 +39604 ./prep_dataset/ILSVRC2012_val_00045695.bin 224 224 +39605 ./prep_dataset/ILSVRC2012_val_00010145.bin 224 224 +39606 ./prep_dataset/ILSVRC2012_val_00024076.bin 224 224 +39607 ./prep_dataset/ILSVRC2012_val_00025050.bin 224 224 +39608 ./prep_dataset/ILSVRC2012_val_00002967.bin 224 224 +39609 ./prep_dataset/ILSVRC2012_val_00015842.bin 224 224 +39610 ./prep_dataset/ILSVRC2012_val_00027942.bin 224 224 +39611 ./prep_dataset/ILSVRC2012_val_00005378.bin 224 224 +39612 ./prep_dataset/ILSVRC2012_val_00046244.bin 224 224 +39613 ./prep_dataset/ILSVRC2012_val_00011053.bin 224 224 +39614 ./prep_dataset/ILSVRC2012_val_00002037.bin 224 224 +39615 ./prep_dataset/ILSVRC2012_val_00019071.bin 224 224 +39616 ./prep_dataset/ILSVRC2012_val_00006869.bin 224 224 +39617 ./prep_dataset/ILSVRC2012_val_00019680.bin 224 224 +39618 ./prep_dataset/ILSVRC2012_val_00044836.bin 224 224 +39619 ./prep_dataset/ILSVRC2012_val_00037137.bin 224 224 +39620 ./prep_dataset/ILSVRC2012_val_00009415.bin 224 224 +39621 ./prep_dataset/ILSVRC2012_val_00002440.bin 224 224 +39622 ./prep_dataset/ILSVRC2012_val_00032103.bin 224 224 +39623 ./prep_dataset/ILSVRC2012_val_00019591.bin 224 224 +39624 ./prep_dataset/ILSVRC2012_val_00038799.bin 224 224 +39625 ./prep_dataset/ILSVRC2012_val_00013672.bin 224 224 +39626 ./prep_dataset/ILSVRC2012_val_00023531.bin 224 224 +39627 ./prep_dataset/ILSVRC2012_val_00045033.bin 224 224 +39628 ./prep_dataset/ILSVRC2012_val_00027498.bin 224 224 +39629 ./prep_dataset/ILSVRC2012_val_00029589.bin 224 224 +39630 ./prep_dataset/ILSVRC2012_val_00041225.bin 224 224 +39631 ./prep_dataset/ILSVRC2012_val_00028582.bin 224 224 +39632 ./prep_dataset/ILSVRC2012_val_00035192.bin 224 224 +39633 ./prep_dataset/ILSVRC2012_val_00003243.bin 224 224 +39634 ./prep_dataset/ILSVRC2012_val_00027108.bin 224 224 +39635 ./prep_dataset/ILSVRC2012_val_00028007.bin 224 224 +39636 ./prep_dataset/ILSVRC2012_val_00045563.bin 224 224 +39637 ./prep_dataset/ILSVRC2012_val_00044507.bin 224 224 +39638 ./prep_dataset/ILSVRC2012_val_00032971.bin 224 224 +39639 ./prep_dataset/ILSVRC2012_val_00016238.bin 224 224 +39640 ./prep_dataset/ILSVRC2012_val_00029005.bin 224 224 +39641 ./prep_dataset/ILSVRC2012_val_00004712.bin 224 224 +39642 ./prep_dataset/ILSVRC2012_val_00049149.bin 224 224 +39643 ./prep_dataset/ILSVRC2012_val_00037272.bin 224 224 +39644 ./prep_dataset/ILSVRC2012_val_00049001.bin 224 224 +39645 ./prep_dataset/ILSVRC2012_val_00001465.bin 224 224 +39646 ./prep_dataset/ILSVRC2012_val_00002647.bin 224 224 +39647 ./prep_dataset/ILSVRC2012_val_00049057.bin 224 224 +39648 ./prep_dataset/ILSVRC2012_val_00023880.bin 224 224 +39649 ./prep_dataset/ILSVRC2012_val_00039208.bin 224 224 +39650 ./prep_dataset/ILSVRC2012_val_00011281.bin 224 224 +39651 ./prep_dataset/ILSVRC2012_val_00032767.bin 224 224 +39652 ./prep_dataset/ILSVRC2012_val_00023925.bin 224 224 +39653 ./prep_dataset/ILSVRC2012_val_00033962.bin 224 224 +39654 ./prep_dataset/ILSVRC2012_val_00020341.bin 224 224 +39655 ./prep_dataset/ILSVRC2012_val_00038867.bin 224 224 +39656 ./prep_dataset/ILSVRC2012_val_00019740.bin 224 224 +39657 ./prep_dataset/ILSVRC2012_val_00018418.bin 224 224 +39658 ./prep_dataset/ILSVRC2012_val_00043332.bin 224 224 +39659 ./prep_dataset/ILSVRC2012_val_00015705.bin 224 224 +39660 ./prep_dataset/ILSVRC2012_val_00027955.bin 224 224 +39661 ./prep_dataset/ILSVRC2012_val_00011594.bin 224 224 +39662 ./prep_dataset/ILSVRC2012_val_00002175.bin 224 224 +39663 ./prep_dataset/ILSVRC2012_val_00037768.bin 224 224 +39664 ./prep_dataset/ILSVRC2012_val_00039053.bin 224 224 +39665 ./prep_dataset/ILSVRC2012_val_00027233.bin 224 224 +39666 ./prep_dataset/ILSVRC2012_val_00023319.bin 224 224 +39667 ./prep_dataset/ILSVRC2012_val_00000884.bin 224 224 +39668 ./prep_dataset/ILSVRC2012_val_00044455.bin 224 224 +39669 ./prep_dataset/ILSVRC2012_val_00025693.bin 224 224 +39670 ./prep_dataset/ILSVRC2012_val_00012488.bin 224 224 +39671 ./prep_dataset/ILSVRC2012_val_00038369.bin 224 224 +39672 ./prep_dataset/ILSVRC2012_val_00028732.bin 224 224 +39673 ./prep_dataset/ILSVRC2012_val_00033864.bin 224 224 +39674 ./prep_dataset/ILSVRC2012_val_00018370.bin 224 224 +39675 ./prep_dataset/ILSVRC2012_val_00035652.bin 224 224 +39676 ./prep_dataset/ILSVRC2012_val_00019449.bin 224 224 +39677 ./prep_dataset/ILSVRC2012_val_00049022.bin 224 224 +39678 ./prep_dataset/ILSVRC2012_val_00013615.bin 224 224 +39679 ./prep_dataset/ILSVRC2012_val_00046084.bin 224 224 +39680 ./prep_dataset/ILSVRC2012_val_00047063.bin 224 224 +39681 ./prep_dataset/ILSVRC2012_val_00042861.bin 224 224 +39682 ./prep_dataset/ILSVRC2012_val_00001147.bin 224 224 +39683 ./prep_dataset/ILSVRC2012_val_00005219.bin 224 224 +39684 ./prep_dataset/ILSVRC2012_val_00026950.bin 224 224 +39685 ./prep_dataset/ILSVRC2012_val_00019511.bin 224 224 +39686 ./prep_dataset/ILSVRC2012_val_00047808.bin 224 224 +39687 ./prep_dataset/ILSVRC2012_val_00046629.bin 224 224 +39688 ./prep_dataset/ILSVRC2012_val_00010806.bin 224 224 +39689 ./prep_dataset/ILSVRC2012_val_00022291.bin 224 224 +39690 ./prep_dataset/ILSVRC2012_val_00042734.bin 224 224 +39691 ./prep_dataset/ILSVRC2012_val_00006445.bin 224 224 +39692 ./prep_dataset/ILSVRC2012_val_00026527.bin 224 224 +39693 ./prep_dataset/ILSVRC2012_val_00005883.bin 224 224 +39694 ./prep_dataset/ILSVRC2012_val_00049504.bin 224 224 +39695 ./prep_dataset/ILSVRC2012_val_00032617.bin 224 224 +39696 ./prep_dataset/ILSVRC2012_val_00044726.bin 224 224 +39697 ./prep_dataset/ILSVRC2012_val_00006421.bin 224 224 +39698 ./prep_dataset/ILSVRC2012_val_00010501.bin 224 224 +39699 ./prep_dataset/ILSVRC2012_val_00041129.bin 224 224 +39700 ./prep_dataset/ILSVRC2012_val_00015008.bin 224 224 +39701 ./prep_dataset/ILSVRC2012_val_00029482.bin 224 224 +39702 ./prep_dataset/ILSVRC2012_val_00017172.bin 224 224 +39703 ./prep_dataset/ILSVRC2012_val_00008279.bin 224 224 +39704 ./prep_dataset/ILSVRC2012_val_00046441.bin 224 224 +39705 ./prep_dataset/ILSVRC2012_val_00006242.bin 224 224 +39706 ./prep_dataset/ILSVRC2012_val_00035307.bin 224 224 +39707 ./prep_dataset/ILSVRC2012_val_00004948.bin 224 224 +39708 ./prep_dataset/ILSVRC2012_val_00010305.bin 224 224 +39709 ./prep_dataset/ILSVRC2012_val_00027306.bin 224 224 +39710 ./prep_dataset/ILSVRC2012_val_00005990.bin 224 224 +39711 ./prep_dataset/ILSVRC2012_val_00023538.bin 224 224 +39712 ./prep_dataset/ILSVRC2012_val_00006143.bin 224 224 +39713 ./prep_dataset/ILSVRC2012_val_00020296.bin 224 224 +39714 ./prep_dataset/ILSVRC2012_val_00024997.bin 224 224 +39715 ./prep_dataset/ILSVRC2012_val_00048740.bin 224 224 +39716 ./prep_dataset/ILSVRC2012_val_00012042.bin 224 224 +39717 ./prep_dataset/ILSVRC2012_val_00005518.bin 224 224 +39718 ./prep_dataset/ILSVRC2012_val_00003008.bin 224 224 +39719 ./prep_dataset/ILSVRC2012_val_00032001.bin 224 224 +39720 ./prep_dataset/ILSVRC2012_val_00043512.bin 224 224 +39721 ./prep_dataset/ILSVRC2012_val_00012940.bin 224 224 +39722 ./prep_dataset/ILSVRC2012_val_00039917.bin 224 224 +39723 ./prep_dataset/ILSVRC2012_val_00006688.bin 224 224 +39724 ./prep_dataset/ILSVRC2012_val_00031530.bin 224 224 +39725 ./prep_dataset/ILSVRC2012_val_00022182.bin 224 224 +39726 ./prep_dataset/ILSVRC2012_val_00047661.bin 224 224 +39727 ./prep_dataset/ILSVRC2012_val_00044111.bin 224 224 +39728 ./prep_dataset/ILSVRC2012_val_00022093.bin 224 224 +39729 ./prep_dataset/ILSVRC2012_val_00025763.bin 224 224 +39730 ./prep_dataset/ILSVRC2012_val_00037327.bin 224 224 +39731 ./prep_dataset/ILSVRC2012_val_00012935.bin 224 224 +39732 ./prep_dataset/ILSVRC2012_val_00017407.bin 224 224 +39733 ./prep_dataset/ILSVRC2012_val_00039780.bin 224 224 +39734 ./prep_dataset/ILSVRC2012_val_00045455.bin 224 224 +39735 ./prep_dataset/ILSVRC2012_val_00025313.bin 224 224 +39736 ./prep_dataset/ILSVRC2012_val_00008385.bin 224 224 +39737 ./prep_dataset/ILSVRC2012_val_00015239.bin 224 224 +39738 ./prep_dataset/ILSVRC2012_val_00027890.bin 224 224 +39739 ./prep_dataset/ILSVRC2012_val_00029163.bin 224 224 +39740 ./prep_dataset/ILSVRC2012_val_00045679.bin 224 224 +39741 ./prep_dataset/ILSVRC2012_val_00010629.bin 224 224 +39742 ./prep_dataset/ILSVRC2012_val_00006561.bin 224 224 +39743 ./prep_dataset/ILSVRC2012_val_00016967.bin 224 224 +39744 ./prep_dataset/ILSVRC2012_val_00032075.bin 224 224 +39745 ./prep_dataset/ILSVRC2012_val_00038077.bin 224 224 +39746 ./prep_dataset/ILSVRC2012_val_00023807.bin 224 224 +39747 ./prep_dataset/ILSVRC2012_val_00024110.bin 224 224 +39748 ./prep_dataset/ILSVRC2012_val_00028776.bin 224 224 +39749 ./prep_dataset/ILSVRC2012_val_00034460.bin 224 224 +39750 ./prep_dataset/ILSVRC2012_val_00003116.bin 224 224 +39751 ./prep_dataset/ILSVRC2012_val_00011648.bin 224 224 +39752 ./prep_dataset/ILSVRC2012_val_00010214.bin 224 224 +39753 ./prep_dataset/ILSVRC2012_val_00032068.bin 224 224 +39754 ./prep_dataset/ILSVRC2012_val_00038857.bin 224 224 +39755 ./prep_dataset/ILSVRC2012_val_00019817.bin 224 224 +39756 ./prep_dataset/ILSVRC2012_val_00024030.bin 224 224 +39757 ./prep_dataset/ILSVRC2012_val_00046550.bin 224 224 +39758 ./prep_dataset/ILSVRC2012_val_00035439.bin 224 224 +39759 ./prep_dataset/ILSVRC2012_val_00038109.bin 224 224 +39760 ./prep_dataset/ILSVRC2012_val_00038814.bin 224 224 +39761 ./prep_dataset/ILSVRC2012_val_00001004.bin 224 224 +39762 ./prep_dataset/ILSVRC2012_val_00039326.bin 224 224 +39763 ./prep_dataset/ILSVRC2012_val_00042457.bin 224 224 +39764 ./prep_dataset/ILSVRC2012_val_00019068.bin 224 224 +39765 ./prep_dataset/ILSVRC2012_val_00037054.bin 224 224 +39766 ./prep_dataset/ILSVRC2012_val_00049922.bin 224 224 +39767 ./prep_dataset/ILSVRC2012_val_00036607.bin 224 224 +39768 ./prep_dataset/ILSVRC2012_val_00010316.bin 224 224 +39769 ./prep_dataset/ILSVRC2012_val_00027367.bin 224 224 +39770 ./prep_dataset/ILSVRC2012_val_00011934.bin 224 224 +39771 ./prep_dataset/ILSVRC2012_val_00047015.bin 224 224 +39772 ./prep_dataset/ILSVRC2012_val_00020575.bin 224 224 +39773 ./prep_dataset/ILSVRC2012_val_00013743.bin 224 224 +39774 ./prep_dataset/ILSVRC2012_val_00039739.bin 224 224 +39775 ./prep_dataset/ILSVRC2012_val_00020153.bin 224 224 +39776 ./prep_dataset/ILSVRC2012_val_00014279.bin 224 224 +39777 ./prep_dataset/ILSVRC2012_val_00041496.bin 224 224 +39778 ./prep_dataset/ILSVRC2012_val_00032123.bin 224 224 +39779 ./prep_dataset/ILSVRC2012_val_00011058.bin 224 224 +39780 ./prep_dataset/ILSVRC2012_val_00038771.bin 224 224 +39781 ./prep_dataset/ILSVRC2012_val_00033679.bin 224 224 +39782 ./prep_dataset/ILSVRC2012_val_00048905.bin 224 224 +39783 ./prep_dataset/ILSVRC2012_val_00017403.bin 224 224 +39784 ./prep_dataset/ILSVRC2012_val_00022304.bin 224 224 +39785 ./prep_dataset/ILSVRC2012_val_00006220.bin 224 224 +39786 ./prep_dataset/ILSVRC2012_val_00040839.bin 224 224 +39787 ./prep_dataset/ILSVRC2012_val_00037816.bin 224 224 +39788 ./prep_dataset/ILSVRC2012_val_00025737.bin 224 224 +39789 ./prep_dataset/ILSVRC2012_val_00024448.bin 224 224 +39790 ./prep_dataset/ILSVRC2012_val_00040785.bin 224 224 +39791 ./prep_dataset/ILSVRC2012_val_00008480.bin 224 224 +39792 ./prep_dataset/ILSVRC2012_val_00026803.bin 224 224 +39793 ./prep_dataset/ILSVRC2012_val_00014727.bin 224 224 +39794 ./prep_dataset/ILSVRC2012_val_00039130.bin 224 224 +39795 ./prep_dataset/ILSVRC2012_val_00028631.bin 224 224 +39796 ./prep_dataset/ILSVRC2012_val_00010732.bin 224 224 +39797 ./prep_dataset/ILSVRC2012_val_00027919.bin 224 224 +39798 ./prep_dataset/ILSVRC2012_val_00004540.bin 224 224 +39799 ./prep_dataset/ILSVRC2012_val_00005617.bin 224 224 +39800 ./prep_dataset/ILSVRC2012_val_00048264.bin 224 224 +39801 ./prep_dataset/ILSVRC2012_val_00010282.bin 224 224 +39802 ./prep_dataset/ILSVRC2012_val_00003254.bin 224 224 +39803 ./prep_dataset/ILSVRC2012_val_00044183.bin 224 224 +39804 ./prep_dataset/ILSVRC2012_val_00019865.bin 224 224 +39805 ./prep_dataset/ILSVRC2012_val_00020544.bin 224 224 +39806 ./prep_dataset/ILSVRC2012_val_00004514.bin 224 224 +39807 ./prep_dataset/ILSVRC2012_val_00005898.bin 224 224 +39808 ./prep_dataset/ILSVRC2012_val_00021945.bin 224 224 +39809 ./prep_dataset/ILSVRC2012_val_00031408.bin 224 224 +39810 ./prep_dataset/ILSVRC2012_val_00039826.bin 224 224 +39811 ./prep_dataset/ILSVRC2012_val_00018313.bin 224 224 +39812 ./prep_dataset/ILSVRC2012_val_00033796.bin 224 224 +39813 ./prep_dataset/ILSVRC2012_val_00006611.bin 224 224 +39814 ./prep_dataset/ILSVRC2012_val_00046862.bin 224 224 +39815 ./prep_dataset/ILSVRC2012_val_00033246.bin 224 224 +39816 ./prep_dataset/ILSVRC2012_val_00033030.bin 224 224 +39817 ./prep_dataset/ILSVRC2012_val_00033693.bin 224 224 +39818 ./prep_dataset/ILSVRC2012_val_00034231.bin 224 224 +39819 ./prep_dataset/ILSVRC2012_val_00003482.bin 224 224 +39820 ./prep_dataset/ILSVRC2012_val_00011431.bin 224 224 +39821 ./prep_dataset/ILSVRC2012_val_00022405.bin 224 224 +39822 ./prep_dataset/ILSVRC2012_val_00012379.bin 224 224 +39823 ./prep_dataset/ILSVRC2012_val_00031543.bin 224 224 +39824 ./prep_dataset/ILSVRC2012_val_00024169.bin 224 224 +39825 ./prep_dataset/ILSVRC2012_val_00032277.bin 224 224 +39826 ./prep_dataset/ILSVRC2012_val_00043163.bin 224 224 +39827 ./prep_dataset/ILSVRC2012_val_00046678.bin 224 224 +39828 ./prep_dataset/ILSVRC2012_val_00031436.bin 224 224 +39829 ./prep_dataset/ILSVRC2012_val_00010960.bin 224 224 +39830 ./prep_dataset/ILSVRC2012_val_00032235.bin 224 224 +39831 ./prep_dataset/ILSVRC2012_val_00039726.bin 224 224 +39832 ./prep_dataset/ILSVRC2012_val_00031151.bin 224 224 +39833 ./prep_dataset/ILSVRC2012_val_00020051.bin 224 224 +39834 ./prep_dataset/ILSVRC2012_val_00035072.bin 224 224 +39835 ./prep_dataset/ILSVRC2012_val_00004024.bin 224 224 +39836 ./prep_dataset/ILSVRC2012_val_00044511.bin 224 224 +39837 ./prep_dataset/ILSVRC2012_val_00041729.bin 224 224 +39838 ./prep_dataset/ILSVRC2012_val_00025524.bin 224 224 +39839 ./prep_dataset/ILSVRC2012_val_00047532.bin 224 224 +39840 ./prep_dataset/ILSVRC2012_val_00036937.bin 224 224 +39841 ./prep_dataset/ILSVRC2012_val_00030682.bin 224 224 +39842 ./prep_dataset/ILSVRC2012_val_00041492.bin 224 224 +39843 ./prep_dataset/ILSVRC2012_val_00021130.bin 224 224 +39844 ./prep_dataset/ILSVRC2012_val_00044918.bin 224 224 +39845 ./prep_dataset/ILSVRC2012_val_00015479.bin 224 224 +39846 ./prep_dataset/ILSVRC2012_val_00005809.bin 224 224 +39847 ./prep_dataset/ILSVRC2012_val_00017044.bin 224 224 +39848 ./prep_dataset/ILSVRC2012_val_00027097.bin 224 224 +39849 ./prep_dataset/ILSVRC2012_val_00035382.bin 224 224 +39850 ./prep_dataset/ILSVRC2012_val_00006858.bin 224 224 +39851 ./prep_dataset/ILSVRC2012_val_00034555.bin 224 224 +39852 ./prep_dataset/ILSVRC2012_val_00015127.bin 224 224 +39853 ./prep_dataset/ILSVRC2012_val_00044598.bin 224 224 +39854 ./prep_dataset/ILSVRC2012_val_00014089.bin 224 224 +39855 ./prep_dataset/ILSVRC2012_val_00047876.bin 224 224 +39856 ./prep_dataset/ILSVRC2012_val_00040376.bin 224 224 +39857 ./prep_dataset/ILSVRC2012_val_00021064.bin 224 224 +39858 ./prep_dataset/ILSVRC2012_val_00025996.bin 224 224 +39859 ./prep_dataset/ILSVRC2012_val_00001232.bin 224 224 +39860 ./prep_dataset/ILSVRC2012_val_00002499.bin 224 224 +39861 ./prep_dataset/ILSVRC2012_val_00040146.bin 224 224 +39862 ./prep_dataset/ILSVRC2012_val_00027111.bin 224 224 +39863 ./prep_dataset/ILSVRC2012_val_00045569.bin 224 224 +39864 ./prep_dataset/ILSVRC2012_val_00039400.bin 224 224 +39865 ./prep_dataset/ILSVRC2012_val_00015361.bin 224 224 +39866 ./prep_dataset/ILSVRC2012_val_00023474.bin 224 224 +39867 ./prep_dataset/ILSVRC2012_val_00021163.bin 224 224 +39868 ./prep_dataset/ILSVRC2012_val_00023802.bin 224 224 +39869 ./prep_dataset/ILSVRC2012_val_00036977.bin 224 224 +39870 ./prep_dataset/ILSVRC2012_val_00038928.bin 224 224 +39871 ./prep_dataset/ILSVRC2012_val_00011488.bin 224 224 +39872 ./prep_dataset/ILSVRC2012_val_00027005.bin 224 224 +39873 ./prep_dataset/ILSVRC2012_val_00046171.bin 224 224 +39874 ./prep_dataset/ILSVRC2012_val_00021502.bin 224 224 +39875 ./prep_dataset/ILSVRC2012_val_00005817.bin 224 224 +39876 ./prep_dataset/ILSVRC2012_val_00022505.bin 224 224 +39877 ./prep_dataset/ILSVRC2012_val_00003850.bin 224 224 +39878 ./prep_dataset/ILSVRC2012_val_00026046.bin 224 224 +39879 ./prep_dataset/ILSVRC2012_val_00003402.bin 224 224 +39880 ./prep_dataset/ILSVRC2012_val_00046403.bin 224 224 +39881 ./prep_dataset/ILSVRC2012_val_00007968.bin 224 224 +39882 ./prep_dataset/ILSVRC2012_val_00041903.bin 224 224 +39883 ./prep_dataset/ILSVRC2012_val_00033916.bin 224 224 +39884 ./prep_dataset/ILSVRC2012_val_00040139.bin 224 224 +39885 ./prep_dataset/ILSVRC2012_val_00045738.bin 224 224 +39886 ./prep_dataset/ILSVRC2012_val_00031948.bin 224 224 +39887 ./prep_dataset/ILSVRC2012_val_00018693.bin 224 224 +39888 ./prep_dataset/ILSVRC2012_val_00030214.bin 224 224 +39889 ./prep_dataset/ILSVRC2012_val_00037906.bin 224 224 +39890 ./prep_dataset/ILSVRC2012_val_00018742.bin 224 224 +39891 ./prep_dataset/ILSVRC2012_val_00047268.bin 224 224 +39892 ./prep_dataset/ILSVRC2012_val_00011944.bin 224 224 +39893 ./prep_dataset/ILSVRC2012_val_00021894.bin 224 224 +39894 ./prep_dataset/ILSVRC2012_val_00046406.bin 224 224 +39895 ./prep_dataset/ILSVRC2012_val_00023439.bin 224 224 +39896 ./prep_dataset/ILSVRC2012_val_00032771.bin 224 224 +39897 ./prep_dataset/ILSVRC2012_val_00007052.bin 224 224 +39898 ./prep_dataset/ILSVRC2012_val_00003624.bin 224 224 +39899 ./prep_dataset/ILSVRC2012_val_00021925.bin 224 224 +39900 ./prep_dataset/ILSVRC2012_val_00028103.bin 224 224 +39901 ./prep_dataset/ILSVRC2012_val_00009260.bin 224 224 +39902 ./prep_dataset/ILSVRC2012_val_00000226.bin 224 224 +39903 ./prep_dataset/ILSVRC2012_val_00022914.bin 224 224 +39904 ./prep_dataset/ILSVRC2012_val_00042358.bin 224 224 +39905 ./prep_dataset/ILSVRC2012_val_00032055.bin 224 224 +39906 ./prep_dataset/ILSVRC2012_val_00031456.bin 224 224 +39907 ./prep_dataset/ILSVRC2012_val_00017961.bin 224 224 +39908 ./prep_dataset/ILSVRC2012_val_00024970.bin 224 224 +39909 ./prep_dataset/ILSVRC2012_val_00031993.bin 224 224 +39910 ./prep_dataset/ILSVRC2012_val_00036556.bin 224 224 +39911 ./prep_dataset/ILSVRC2012_val_00004920.bin 224 224 +39912 ./prep_dataset/ILSVRC2012_val_00041865.bin 224 224 +39913 ./prep_dataset/ILSVRC2012_val_00016196.bin 224 224 +39914 ./prep_dataset/ILSVRC2012_val_00029457.bin 224 224 +39915 ./prep_dataset/ILSVRC2012_val_00029391.bin 224 224 +39916 ./prep_dataset/ILSVRC2012_val_00027772.bin 224 224 +39917 ./prep_dataset/ILSVRC2012_val_00038297.bin 224 224 +39918 ./prep_dataset/ILSVRC2012_val_00010162.bin 224 224 +39919 ./prep_dataset/ILSVRC2012_val_00017553.bin 224 224 +39920 ./prep_dataset/ILSVRC2012_val_00012552.bin 224 224 +39921 ./prep_dataset/ILSVRC2012_val_00016207.bin 224 224 +39922 ./prep_dataset/ILSVRC2012_val_00043569.bin 224 224 +39923 ./prep_dataset/ILSVRC2012_val_00035372.bin 224 224 +39924 ./prep_dataset/ILSVRC2012_val_00027806.bin 224 224 +39925 ./prep_dataset/ILSVRC2012_val_00017958.bin 224 224 +39926 ./prep_dataset/ILSVRC2012_val_00004158.bin 224 224 +39927 ./prep_dataset/ILSVRC2012_val_00032276.bin 224 224 +39928 ./prep_dataset/ILSVRC2012_val_00040312.bin 224 224 +39929 ./prep_dataset/ILSVRC2012_val_00043528.bin 224 224 +39930 ./prep_dataset/ILSVRC2012_val_00006991.bin 224 224 +39931 ./prep_dataset/ILSVRC2012_val_00020135.bin 224 224 +39932 ./prep_dataset/ILSVRC2012_val_00006824.bin 224 224 +39933 ./prep_dataset/ILSVRC2012_val_00017226.bin 224 224 +39934 ./prep_dataset/ILSVRC2012_val_00034791.bin 224 224 +39935 ./prep_dataset/ILSVRC2012_val_00024960.bin 224 224 +39936 ./prep_dataset/ILSVRC2012_val_00031461.bin 224 224 +39937 ./prep_dataset/ILSVRC2012_val_00013159.bin 224 224 +39938 ./prep_dataset/ILSVRC2012_val_00048040.bin 224 224 +39939 ./prep_dataset/ILSVRC2012_val_00027794.bin 224 224 +39940 ./prep_dataset/ILSVRC2012_val_00032456.bin 224 224 +39941 ./prep_dataset/ILSVRC2012_val_00008500.bin 224 224 +39942 ./prep_dataset/ILSVRC2012_val_00008722.bin 224 224 +39943 ./prep_dataset/ILSVRC2012_val_00036905.bin 224 224 +39944 ./prep_dataset/ILSVRC2012_val_00037115.bin 224 224 +39945 ./prep_dataset/ILSVRC2012_val_00030100.bin 224 224 +39946 ./prep_dataset/ILSVRC2012_val_00046392.bin 224 224 +39947 ./prep_dataset/ILSVRC2012_val_00034564.bin 224 224 +39948 ./prep_dataset/ILSVRC2012_val_00038329.bin 224 224 +39949 ./prep_dataset/ILSVRC2012_val_00020889.bin 224 224 +39950 ./prep_dataset/ILSVRC2012_val_00035452.bin 224 224 +39951 ./prep_dataset/ILSVRC2012_val_00026039.bin 224 224 +39952 ./prep_dataset/ILSVRC2012_val_00024589.bin 224 224 +39953 ./prep_dataset/ILSVRC2012_val_00009756.bin 224 224 +39954 ./prep_dataset/ILSVRC2012_val_00032841.bin 224 224 +39955 ./prep_dataset/ILSVRC2012_val_00041426.bin 224 224 +39956 ./prep_dataset/ILSVRC2012_val_00043032.bin 224 224 +39957 ./prep_dataset/ILSVRC2012_val_00049043.bin 224 224 +39958 ./prep_dataset/ILSVRC2012_val_00000818.bin 224 224 +39959 ./prep_dataset/ILSVRC2012_val_00028636.bin 224 224 +39960 ./prep_dataset/ILSVRC2012_val_00017394.bin 224 224 +39961 ./prep_dataset/ILSVRC2012_val_00035070.bin 224 224 +39962 ./prep_dataset/ILSVRC2012_val_00000887.bin 224 224 +39963 ./prep_dataset/ILSVRC2012_val_00042318.bin 224 224 +39964 ./prep_dataset/ILSVRC2012_val_00032489.bin 224 224 +39965 ./prep_dataset/ILSVRC2012_val_00003679.bin 224 224 +39966 ./prep_dataset/ILSVRC2012_val_00022366.bin 224 224 +39967 ./prep_dataset/ILSVRC2012_val_00022996.bin 224 224 +39968 ./prep_dataset/ILSVRC2012_val_00013102.bin 224 224 +39969 ./prep_dataset/ILSVRC2012_val_00001213.bin 224 224 +39970 ./prep_dataset/ILSVRC2012_val_00002240.bin 224 224 +39971 ./prep_dataset/ILSVRC2012_val_00003543.bin 224 224 +39972 ./prep_dataset/ILSVRC2012_val_00047635.bin 224 224 +39973 ./prep_dataset/ILSVRC2012_val_00041031.bin 224 224 +39974 ./prep_dataset/ILSVRC2012_val_00029817.bin 224 224 +39975 ./prep_dataset/ILSVRC2012_val_00029677.bin 224 224 +39976 ./prep_dataset/ILSVRC2012_val_00044652.bin 224 224 +39977 ./prep_dataset/ILSVRC2012_val_00006080.bin 224 224 +39978 ./prep_dataset/ILSVRC2012_val_00000061.bin 224 224 +39979 ./prep_dataset/ILSVRC2012_val_00026145.bin 224 224 +39980 ./prep_dataset/ILSVRC2012_val_00003110.bin 224 224 +39981 ./prep_dataset/ILSVRC2012_val_00030525.bin 224 224 +39982 ./prep_dataset/ILSVRC2012_val_00033491.bin 224 224 +39983 ./prep_dataset/ILSVRC2012_val_00033661.bin 224 224 +39984 ./prep_dataset/ILSVRC2012_val_00017382.bin 224 224 +39985 ./prep_dataset/ILSVRC2012_val_00045240.bin 224 224 +39986 ./prep_dataset/ILSVRC2012_val_00043023.bin 224 224 +39987 ./prep_dataset/ILSVRC2012_val_00007484.bin 224 224 +39988 ./prep_dataset/ILSVRC2012_val_00026357.bin 224 224 +39989 ./prep_dataset/ILSVRC2012_val_00025000.bin 224 224 +39990 ./prep_dataset/ILSVRC2012_val_00041932.bin 224 224 +39991 ./prep_dataset/ILSVRC2012_val_00013571.bin 224 224 +39992 ./prep_dataset/ILSVRC2012_val_00003591.bin 224 224 +39993 ./prep_dataset/ILSVRC2012_val_00020745.bin 224 224 +39994 ./prep_dataset/ILSVRC2012_val_00022830.bin 224 224 +39995 ./prep_dataset/ILSVRC2012_val_00031743.bin 224 224 +39996 ./prep_dataset/ILSVRC2012_val_00029116.bin 224 224 +39997 ./prep_dataset/ILSVRC2012_val_00029184.bin 224 224 +39998 ./prep_dataset/ILSVRC2012_val_00007552.bin 224 224 +39999 ./prep_dataset/ILSVRC2012_val_00038739.bin 224 224 +40000 ./prep_dataset/ILSVRC2012_val_00003774.bin 224 224 +40001 ./prep_dataset/ILSVRC2012_val_00022004.bin 224 224 +40002 ./prep_dataset/ILSVRC2012_val_00019548.bin 224 224 +40003 ./prep_dataset/ILSVRC2012_val_00027444.bin 224 224 +40004 ./prep_dataset/ILSVRC2012_val_00029993.bin 224 224 +40005 ./prep_dataset/ILSVRC2012_val_00027416.bin 224 224 +40006 ./prep_dataset/ILSVRC2012_val_00011457.bin 224 224 +40007 ./prep_dataset/ILSVRC2012_val_00015311.bin 224 224 +40008 ./prep_dataset/ILSVRC2012_val_00015881.bin 224 224 +40009 ./prep_dataset/ILSVRC2012_val_00049452.bin 224 224 +40010 ./prep_dataset/ILSVRC2012_val_00004599.bin 224 224 +40011 ./prep_dataset/ILSVRC2012_val_00033322.bin 224 224 +40012 ./prep_dataset/ILSVRC2012_val_00005236.bin 224 224 +40013 ./prep_dataset/ILSVRC2012_val_00035231.bin 224 224 +40014 ./prep_dataset/ILSVRC2012_val_00048529.bin 224 224 +40015 ./prep_dataset/ILSVRC2012_val_00025348.bin 224 224 +40016 ./prep_dataset/ILSVRC2012_val_00041967.bin 224 224 +40017 ./prep_dataset/ILSVRC2012_val_00037313.bin 224 224 +40018 ./prep_dataset/ILSVRC2012_val_00007533.bin 224 224 +40019 ./prep_dataset/ILSVRC2012_val_00041607.bin 224 224 +40020 ./prep_dataset/ILSVRC2012_val_00024364.bin 224 224 +40021 ./prep_dataset/ILSVRC2012_val_00015439.bin 224 224 +40022 ./prep_dataset/ILSVRC2012_val_00001058.bin 224 224 +40023 ./prep_dataset/ILSVRC2012_val_00027403.bin 224 224 +40024 ./prep_dataset/ILSVRC2012_val_00045946.bin 224 224 +40025 ./prep_dataset/ILSVRC2012_val_00027284.bin 224 224 +40026 ./prep_dataset/ILSVRC2012_val_00008966.bin 224 224 +40027 ./prep_dataset/ILSVRC2012_val_00030330.bin 224 224 +40028 ./prep_dataset/ILSVRC2012_val_00018971.bin 224 224 +40029 ./prep_dataset/ILSVRC2012_val_00025309.bin 224 224 +40030 ./prep_dataset/ILSVRC2012_val_00043126.bin 224 224 +40031 ./prep_dataset/ILSVRC2012_val_00004890.bin 224 224 +40032 ./prep_dataset/ILSVRC2012_val_00030226.bin 224 224 +40033 ./prep_dataset/ILSVRC2012_val_00028420.bin 224 224 +40034 ./prep_dataset/ILSVRC2012_val_00019664.bin 224 224 +40035 ./prep_dataset/ILSVRC2012_val_00014890.bin 224 224 +40036 ./prep_dataset/ILSVRC2012_val_00028722.bin 224 224 +40037 ./prep_dataset/ILSVRC2012_val_00035737.bin 224 224 +40038 ./prep_dataset/ILSVRC2012_val_00034086.bin 224 224 +40039 ./prep_dataset/ILSVRC2012_val_00037322.bin 224 224 +40040 ./prep_dataset/ILSVRC2012_val_00044500.bin 224 224 +40041 ./prep_dataset/ILSVRC2012_val_00029372.bin 224 224 +40042 ./prep_dataset/ILSVRC2012_val_00023056.bin 224 224 +40043 ./prep_dataset/ILSVRC2012_val_00000257.bin 224 224 +40044 ./prep_dataset/ILSVRC2012_val_00039190.bin 224 224 +40045 ./prep_dataset/ILSVRC2012_val_00035607.bin 224 224 +40046 ./prep_dataset/ILSVRC2012_val_00013165.bin 224 224 +40047 ./prep_dataset/ILSVRC2012_val_00013096.bin 224 224 +40048 ./prep_dataset/ILSVRC2012_val_00040629.bin 224 224 +40049 ./prep_dataset/ILSVRC2012_val_00003714.bin 224 224 +40050 ./prep_dataset/ILSVRC2012_val_00044353.bin 224 224 +40051 ./prep_dataset/ILSVRC2012_val_00020303.bin 224 224 +40052 ./prep_dataset/ILSVRC2012_val_00033891.bin 224 224 +40053 ./prep_dataset/ILSVRC2012_val_00001623.bin 224 224 +40054 ./prep_dataset/ILSVRC2012_val_00003505.bin 224 224 +40055 ./prep_dataset/ILSVRC2012_val_00023536.bin 224 224 +40056 ./prep_dataset/ILSVRC2012_val_00019551.bin 224 224 +40057 ./prep_dataset/ILSVRC2012_val_00031360.bin 224 224 +40058 ./prep_dataset/ILSVRC2012_val_00013279.bin 224 224 +40059 ./prep_dataset/ILSVRC2012_val_00045446.bin 224 224 +40060 ./prep_dataset/ILSVRC2012_val_00019807.bin 224 224 +40061 ./prep_dataset/ILSVRC2012_val_00003934.bin 224 224 +40062 ./prep_dataset/ILSVRC2012_val_00003749.bin 224 224 +40063 ./prep_dataset/ILSVRC2012_val_00020866.bin 224 224 +40064 ./prep_dataset/ILSVRC2012_val_00037723.bin 224 224 +40065 ./prep_dataset/ILSVRC2012_val_00041117.bin 224 224 +40066 ./prep_dataset/ILSVRC2012_val_00007421.bin 224 224 +40067 ./prep_dataset/ILSVRC2012_val_00004429.bin 224 224 +40068 ./prep_dataset/ILSVRC2012_val_00011398.bin 224 224 +40069 ./prep_dataset/ILSVRC2012_val_00027186.bin 224 224 +40070 ./prep_dataset/ILSVRC2012_val_00011662.bin 224 224 +40071 ./prep_dataset/ILSVRC2012_val_00013057.bin 224 224 +40072 ./prep_dataset/ILSVRC2012_val_00028300.bin 224 224 +40073 ./prep_dataset/ILSVRC2012_val_00001842.bin 224 224 +40074 ./prep_dataset/ILSVRC2012_val_00004059.bin 224 224 +40075 ./prep_dataset/ILSVRC2012_val_00010223.bin 224 224 +40076 ./prep_dataset/ILSVRC2012_val_00016235.bin 224 224 +40077 ./prep_dataset/ILSVRC2012_val_00019869.bin 224 224 +40078 ./prep_dataset/ILSVRC2012_val_00015946.bin 224 224 +40079 ./prep_dataset/ILSVRC2012_val_00045078.bin 224 224 +40080 ./prep_dataset/ILSVRC2012_val_00024557.bin 224 224 +40081 ./prep_dataset/ILSVRC2012_val_00003275.bin 224 224 +40082 ./prep_dataset/ILSVRC2012_val_00022715.bin 224 224 +40083 ./prep_dataset/ILSVRC2012_val_00046367.bin 224 224 +40084 ./prep_dataset/ILSVRC2012_val_00046300.bin 224 224 +40085 ./prep_dataset/ILSVRC2012_val_00028989.bin 224 224 +40086 ./prep_dataset/ILSVRC2012_val_00039234.bin 224 224 +40087 ./prep_dataset/ILSVRC2012_val_00010668.bin 224 224 +40088 ./prep_dataset/ILSVRC2012_val_00017891.bin 224 224 +40089 ./prep_dataset/ILSVRC2012_val_00017599.bin 224 224 +40090 ./prep_dataset/ILSVRC2012_val_00027136.bin 224 224 +40091 ./prep_dataset/ILSVRC2012_val_00047866.bin 224 224 +40092 ./prep_dataset/ILSVRC2012_val_00023625.bin 224 224 +40093 ./prep_dataset/ILSVRC2012_val_00044615.bin 224 224 +40094 ./prep_dataset/ILSVRC2012_val_00006716.bin 224 224 +40095 ./prep_dataset/ILSVRC2012_val_00020029.bin 224 224 +40096 ./prep_dataset/ILSVRC2012_val_00010137.bin 224 224 +40097 ./prep_dataset/ILSVRC2012_val_00041782.bin 224 224 +40098 ./prep_dataset/ILSVRC2012_val_00036248.bin 224 224 +40099 ./prep_dataset/ILSVRC2012_val_00048163.bin 224 224 +40100 ./prep_dataset/ILSVRC2012_val_00001591.bin 224 224 +40101 ./prep_dataset/ILSVRC2012_val_00030962.bin 224 224 +40102 ./prep_dataset/ILSVRC2012_val_00002077.bin 224 224 +40103 ./prep_dataset/ILSVRC2012_val_00034567.bin 224 224 +40104 ./prep_dataset/ILSVRC2012_val_00009321.bin 224 224 +40105 ./prep_dataset/ILSVRC2012_val_00048119.bin 224 224 +40106 ./prep_dataset/ILSVRC2012_val_00015106.bin 224 224 +40107 ./prep_dataset/ILSVRC2012_val_00031949.bin 224 224 +40108 ./prep_dataset/ILSVRC2012_val_00023095.bin 224 224 +40109 ./prep_dataset/ILSVRC2012_val_00029955.bin 224 224 +40110 ./prep_dataset/ILSVRC2012_val_00021186.bin 224 224 +40111 ./prep_dataset/ILSVRC2012_val_00039773.bin 224 224 +40112 ./prep_dataset/ILSVRC2012_val_00013260.bin 224 224 +40113 ./prep_dataset/ILSVRC2012_val_00025084.bin 224 224 +40114 ./prep_dataset/ILSVRC2012_val_00001309.bin 224 224 +40115 ./prep_dataset/ILSVRC2012_val_00006915.bin 224 224 +40116 ./prep_dataset/ILSVRC2012_val_00018609.bin 224 224 +40117 ./prep_dataset/ILSVRC2012_val_00003347.bin 224 224 +40118 ./prep_dataset/ILSVRC2012_val_00030657.bin 224 224 +40119 ./prep_dataset/ILSVRC2012_val_00006873.bin 224 224 +40120 ./prep_dataset/ILSVRC2012_val_00014884.bin 224 224 +40121 ./prep_dataset/ILSVRC2012_val_00042319.bin 224 224 +40122 ./prep_dataset/ILSVRC2012_val_00047990.bin 224 224 +40123 ./prep_dataset/ILSVRC2012_val_00001214.bin 224 224 +40124 ./prep_dataset/ILSVRC2012_val_00046249.bin 224 224 +40125 ./prep_dataset/ILSVRC2012_val_00034041.bin 224 224 +40126 ./prep_dataset/ILSVRC2012_val_00014628.bin 224 224 +40127 ./prep_dataset/ILSVRC2012_val_00027313.bin 224 224 +40128 ./prep_dataset/ILSVRC2012_val_00021184.bin 224 224 +40129 ./prep_dataset/ILSVRC2012_val_00037569.bin 224 224 +40130 ./prep_dataset/ILSVRC2012_val_00029128.bin 224 224 +40131 ./prep_dataset/ILSVRC2012_val_00032908.bin 224 224 +40132 ./prep_dataset/ILSVRC2012_val_00029793.bin 224 224 +40133 ./prep_dataset/ILSVRC2012_val_00037280.bin 224 224 +40134 ./prep_dataset/ILSVRC2012_val_00042445.bin 224 224 +40135 ./prep_dataset/ILSVRC2012_val_00006971.bin 224 224 +40136 ./prep_dataset/ILSVRC2012_val_00008756.bin 224 224 +40137 ./prep_dataset/ILSVRC2012_val_00006330.bin 224 224 +40138 ./prep_dataset/ILSVRC2012_val_00006346.bin 224 224 +40139 ./prep_dataset/ILSVRC2012_val_00030901.bin 224 224 +40140 ./prep_dataset/ILSVRC2012_val_00039982.bin 224 224 +40141 ./prep_dataset/ILSVRC2012_val_00011575.bin 224 224 +40142 ./prep_dataset/ILSVRC2012_val_00047769.bin 224 224 +40143 ./prep_dataset/ILSVRC2012_val_00003178.bin 224 224 +40144 ./prep_dataset/ILSVRC2012_val_00015053.bin 224 224 +40145 ./prep_dataset/ILSVRC2012_val_00024159.bin 224 224 +40146 ./prep_dataset/ILSVRC2012_val_00040254.bin 224 224 +40147 ./prep_dataset/ILSVRC2012_val_00000383.bin 224 224 +40148 ./prep_dataset/ILSVRC2012_val_00034266.bin 224 224 +40149 ./prep_dataset/ILSVRC2012_val_00044864.bin 224 224 +40150 ./prep_dataset/ILSVRC2012_val_00032504.bin 224 224 +40151 ./prep_dataset/ILSVRC2012_val_00011626.bin 224 224 +40152 ./prep_dataset/ILSVRC2012_val_00004677.bin 224 224 +40153 ./prep_dataset/ILSVRC2012_val_00003666.bin 224 224 +40154 ./prep_dataset/ILSVRC2012_val_00048484.bin 224 224 +40155 ./prep_dataset/ILSVRC2012_val_00047856.bin 224 224 +40156 ./prep_dataset/ILSVRC2012_val_00029676.bin 224 224 +40157 ./prep_dataset/ILSVRC2012_val_00044347.bin 224 224 +40158 ./prep_dataset/ILSVRC2012_val_00042119.bin 224 224 +40159 ./prep_dataset/ILSVRC2012_val_00006996.bin 224 224 +40160 ./prep_dataset/ILSVRC2012_val_00040941.bin 224 224 +40161 ./prep_dataset/ILSVRC2012_val_00013729.bin 224 224 +40162 ./prep_dataset/ILSVRC2012_val_00023065.bin 224 224 +40163 ./prep_dataset/ILSVRC2012_val_00027062.bin 224 224 +40164 ./prep_dataset/ILSVRC2012_val_00049492.bin 224 224 +40165 ./prep_dataset/ILSVRC2012_val_00007801.bin 224 224 +40166 ./prep_dataset/ILSVRC2012_val_00020304.bin 224 224 +40167 ./prep_dataset/ILSVRC2012_val_00026545.bin 224 224 +40168 ./prep_dataset/ILSVRC2012_val_00034590.bin 224 224 +40169 ./prep_dataset/ILSVRC2012_val_00032610.bin 224 224 +40170 ./prep_dataset/ILSVRC2012_val_00048288.bin 224 224 +40171 ./prep_dataset/ILSVRC2012_val_00036776.bin 224 224 +40172 ./prep_dataset/ILSVRC2012_val_00042472.bin 224 224 +40173 ./prep_dataset/ILSVRC2012_val_00040430.bin 224 224 +40174 ./prep_dataset/ILSVRC2012_val_00033115.bin 224 224 +40175 ./prep_dataset/ILSVRC2012_val_00015588.bin 224 224 +40176 ./prep_dataset/ILSVRC2012_val_00004550.bin 224 224 +40177 ./prep_dataset/ILSVRC2012_val_00028704.bin 224 224 +40178 ./prep_dataset/ILSVRC2012_val_00008242.bin 224 224 +40179 ./prep_dataset/ILSVRC2012_val_00049292.bin 224 224 +40180 ./prep_dataset/ILSVRC2012_val_00034624.bin 224 224 +40181 ./prep_dataset/ILSVRC2012_val_00035931.bin 224 224 +40182 ./prep_dataset/ILSVRC2012_val_00041522.bin 224 224 +40183 ./prep_dataset/ILSVRC2012_val_00030047.bin 224 224 +40184 ./prep_dataset/ILSVRC2012_val_00022415.bin 224 224 +40185 ./prep_dataset/ILSVRC2012_val_00043058.bin 224 224 +40186 ./prep_dataset/ILSVRC2012_val_00017040.bin 224 224 +40187 ./prep_dataset/ILSVRC2012_val_00019767.bin 224 224 +40188 ./prep_dataset/ILSVRC2012_val_00011946.bin 224 224 +40189 ./prep_dataset/ILSVRC2012_val_00028822.bin 224 224 +40190 ./prep_dataset/ILSVRC2012_val_00008737.bin 224 224 +40191 ./prep_dataset/ILSVRC2012_val_00022837.bin 224 224 +40192 ./prep_dataset/ILSVRC2012_val_00031103.bin 224 224 +40193 ./prep_dataset/ILSVRC2012_val_00033669.bin 224 224 +40194 ./prep_dataset/ILSVRC2012_val_00003129.bin 224 224 +40195 ./prep_dataset/ILSVRC2012_val_00045097.bin 224 224 +40196 ./prep_dataset/ILSVRC2012_val_00041531.bin 224 224 +40197 ./prep_dataset/ILSVRC2012_val_00040926.bin 224 224 +40198 ./prep_dataset/ILSVRC2012_val_00023151.bin 224 224 +40199 ./prep_dataset/ILSVRC2012_val_00006841.bin 224 224 +40200 ./prep_dataset/ILSVRC2012_val_00000794.bin 224 224 +40201 ./prep_dataset/ILSVRC2012_val_00048959.bin 224 224 +40202 ./prep_dataset/ILSVRC2012_val_00015920.bin 224 224 +40203 ./prep_dataset/ILSVRC2012_val_00027677.bin 224 224 +40204 ./prep_dataset/ILSVRC2012_val_00041393.bin 224 224 +40205 ./prep_dataset/ILSVRC2012_val_00012932.bin 224 224 +40206 ./prep_dataset/ILSVRC2012_val_00024793.bin 224 224 +40207 ./prep_dataset/ILSVRC2012_val_00036710.bin 224 224 +40208 ./prep_dataset/ILSVRC2012_val_00032921.bin 224 224 +40209 ./prep_dataset/ILSVRC2012_val_00002785.bin 224 224 +40210 ./prep_dataset/ILSVRC2012_val_00021563.bin 224 224 +40211 ./prep_dataset/ILSVRC2012_val_00041996.bin 224 224 +40212 ./prep_dataset/ILSVRC2012_val_00000398.bin 224 224 +40213 ./prep_dataset/ILSVRC2012_val_00043638.bin 224 224 +40214 ./prep_dataset/ILSVRC2012_val_00037819.bin 224 224 +40215 ./prep_dataset/ILSVRC2012_val_00044157.bin 224 224 +40216 ./prep_dataset/ILSVRC2012_val_00021108.bin 224 224 +40217 ./prep_dataset/ILSVRC2012_val_00016346.bin 224 224 +40218 ./prep_dataset/ILSVRC2012_val_00034747.bin 224 224 +40219 ./prep_dataset/ILSVRC2012_val_00035367.bin 224 224 +40220 ./prep_dataset/ILSVRC2012_val_00038821.bin 224 224 +40221 ./prep_dataset/ILSVRC2012_val_00015798.bin 224 224 +40222 ./prep_dataset/ILSVRC2012_val_00027492.bin 224 224 +40223 ./prep_dataset/ILSVRC2012_val_00016089.bin 224 224 +40224 ./prep_dataset/ILSVRC2012_val_00046842.bin 224 224 +40225 ./prep_dataset/ILSVRC2012_val_00003259.bin 224 224 +40226 ./prep_dataset/ILSVRC2012_val_00045649.bin 224 224 +40227 ./prep_dataset/ILSVRC2012_val_00006077.bin 224 224 +40228 ./prep_dataset/ILSVRC2012_val_00000047.bin 224 224 +40229 ./prep_dataset/ILSVRC2012_val_00008851.bin 224 224 +40230 ./prep_dataset/ILSVRC2012_val_00045166.bin 224 224 +40231 ./prep_dataset/ILSVRC2012_val_00004305.bin 224 224 +40232 ./prep_dataset/ILSVRC2012_val_00023878.bin 224 224 +40233 ./prep_dataset/ILSVRC2012_val_00020379.bin 224 224 +40234 ./prep_dataset/ILSVRC2012_val_00049463.bin 224 224 +40235 ./prep_dataset/ILSVRC2012_val_00028375.bin 224 224 +40236 ./prep_dataset/ILSVRC2012_val_00001210.bin 224 224 +40237 ./prep_dataset/ILSVRC2012_val_00002512.bin 224 224 +40238 ./prep_dataset/ILSVRC2012_val_00007252.bin 224 224 +40239 ./prep_dataset/ILSVRC2012_val_00027461.bin 224 224 +40240 ./prep_dataset/ILSVRC2012_val_00031215.bin 224 224 +40241 ./prep_dataset/ILSVRC2012_val_00000752.bin 224 224 +40242 ./prep_dataset/ILSVRC2012_val_00045295.bin 224 224 +40243 ./prep_dataset/ILSVRC2012_val_00026446.bin 224 224 +40244 ./prep_dataset/ILSVRC2012_val_00018939.bin 224 224 +40245 ./prep_dataset/ILSVRC2012_val_00004041.bin 224 224 +40246 ./prep_dataset/ILSVRC2012_val_00011579.bin 224 224 +40247 ./prep_dataset/ILSVRC2012_val_00009417.bin 224 224 +40248 ./prep_dataset/ILSVRC2012_val_00026452.bin 224 224 +40249 ./prep_dataset/ILSVRC2012_val_00030867.bin 224 224 +40250 ./prep_dataset/ILSVRC2012_val_00042797.bin 224 224 +40251 ./prep_dataset/ILSVRC2012_val_00037164.bin 224 224 +40252 ./prep_dataset/ILSVRC2012_val_00019380.bin 224 224 +40253 ./prep_dataset/ILSVRC2012_val_00031974.bin 224 224 +40254 ./prep_dataset/ILSVRC2012_val_00030456.bin 224 224 +40255 ./prep_dataset/ILSVRC2012_val_00028675.bin 224 224 +40256 ./prep_dataset/ILSVRC2012_val_00005109.bin 224 224 +40257 ./prep_dataset/ILSVRC2012_val_00036625.bin 224 224 +40258 ./prep_dataset/ILSVRC2012_val_00019306.bin 224 224 +40259 ./prep_dataset/ILSVRC2012_val_00031528.bin 224 224 +40260 ./prep_dataset/ILSVRC2012_val_00001805.bin 224 224 +40261 ./prep_dataset/ILSVRC2012_val_00023850.bin 224 224 +40262 ./prep_dataset/ILSVRC2012_val_00011873.bin 224 224 +40263 ./prep_dataset/ILSVRC2012_val_00044142.bin 224 224 +40264 ./prep_dataset/ILSVRC2012_val_00020422.bin 224 224 +40265 ./prep_dataset/ILSVRC2012_val_00030015.bin 224 224 +40266 ./prep_dataset/ILSVRC2012_val_00043977.bin 224 224 +40267 ./prep_dataset/ILSVRC2012_val_00043297.bin 224 224 +40268 ./prep_dataset/ILSVRC2012_val_00025705.bin 224 224 +40269 ./prep_dataset/ILSVRC2012_val_00046904.bin 224 224 +40270 ./prep_dataset/ILSVRC2012_val_00047909.bin 224 224 +40271 ./prep_dataset/ILSVRC2012_val_00010738.bin 224 224 +40272 ./prep_dataset/ILSVRC2012_val_00018111.bin 224 224 +40273 ./prep_dataset/ILSVRC2012_val_00042486.bin 224 224 +40274 ./prep_dataset/ILSVRC2012_val_00010021.bin 224 224 +40275 ./prep_dataset/ILSVRC2012_val_00042686.bin 224 224 +40276 ./prep_dataset/ILSVRC2012_val_00014291.bin 224 224 +40277 ./prep_dataset/ILSVRC2012_val_00039249.bin 224 224 +40278 ./prep_dataset/ILSVRC2012_val_00010197.bin 224 224 +40279 ./prep_dataset/ILSVRC2012_val_00037775.bin 224 224 +40280 ./prep_dataset/ILSVRC2012_val_00044974.bin 224 224 +40281 ./prep_dataset/ILSVRC2012_val_00006111.bin 224 224 +40282 ./prep_dataset/ILSVRC2012_val_00019832.bin 224 224 +40283 ./prep_dataset/ILSVRC2012_val_00023434.bin 224 224 +40284 ./prep_dataset/ILSVRC2012_val_00021650.bin 224 224 +40285 ./prep_dataset/ILSVRC2012_val_00003249.bin 224 224 +40286 ./prep_dataset/ILSVRC2012_val_00027294.bin 224 224 +40287 ./prep_dataset/ILSVRC2012_val_00024893.bin 224 224 +40288 ./prep_dataset/ILSVRC2012_val_00012765.bin 224 224 +40289 ./prep_dataset/ILSVRC2012_val_00044905.bin 224 224 +40290 ./prep_dataset/ILSVRC2012_val_00036399.bin 224 224 +40291 ./prep_dataset/ILSVRC2012_val_00011730.bin 224 224 +40292 ./prep_dataset/ILSVRC2012_val_00018030.bin 224 224 +40293 ./prep_dataset/ILSVRC2012_val_00049723.bin 224 224 +40294 ./prep_dataset/ILSVRC2012_val_00019637.bin 224 224 +40295 ./prep_dataset/ILSVRC2012_val_00014382.bin 224 224 +40296 ./prep_dataset/ILSVRC2012_val_00013861.bin 224 224 +40297 ./prep_dataset/ILSVRC2012_val_00045558.bin 224 224 +40298 ./prep_dataset/ILSVRC2012_val_00046415.bin 224 224 +40299 ./prep_dataset/ILSVRC2012_val_00003873.bin 224 224 +40300 ./prep_dataset/ILSVRC2012_val_00021142.bin 224 224 +40301 ./prep_dataset/ILSVRC2012_val_00030655.bin 224 224 +40302 ./prep_dataset/ILSVRC2012_val_00030513.bin 224 224 +40303 ./prep_dataset/ILSVRC2012_val_00039461.bin 224 224 +40304 ./prep_dataset/ILSVRC2012_val_00029041.bin 224 224 +40305 ./prep_dataset/ILSVRC2012_val_00006598.bin 224 224 +40306 ./prep_dataset/ILSVRC2012_val_00001659.bin 224 224 +40307 ./prep_dataset/ILSVRC2012_val_00012374.bin 224 224 +40308 ./prep_dataset/ILSVRC2012_val_00018767.bin 224 224 +40309 ./prep_dataset/ILSVRC2012_val_00007091.bin 224 224 +40310 ./prep_dataset/ILSVRC2012_val_00014974.bin 224 224 +40311 ./prep_dataset/ILSVRC2012_val_00038452.bin 224 224 +40312 ./prep_dataset/ILSVRC2012_val_00014961.bin 224 224 +40313 ./prep_dataset/ILSVRC2012_val_00011828.bin 224 224 +40314 ./prep_dataset/ILSVRC2012_val_00007626.bin 224 224 +40315 ./prep_dataset/ILSVRC2012_val_00011316.bin 224 224 +40316 ./prep_dataset/ILSVRC2012_val_00009882.bin 224 224 +40317 ./prep_dataset/ILSVRC2012_val_00029147.bin 224 224 +40318 ./prep_dataset/ILSVRC2012_val_00002229.bin 224 224 +40319 ./prep_dataset/ILSVRC2012_val_00030845.bin 224 224 +40320 ./prep_dataset/ILSVRC2012_val_00022144.bin 224 224 +40321 ./prep_dataset/ILSVRC2012_val_00031954.bin 224 224 +40322 ./prep_dataset/ILSVRC2012_val_00002253.bin 224 224 +40323 ./prep_dataset/ILSVRC2012_val_00048485.bin 224 224 +40324 ./prep_dataset/ILSVRC2012_val_00014572.bin 224 224 +40325 ./prep_dataset/ILSVRC2012_val_00013671.bin 224 224 +40326 ./prep_dataset/ILSVRC2012_val_00004796.bin 224 224 +40327 ./prep_dataset/ILSVRC2012_val_00026785.bin 224 224 +40328 ./prep_dataset/ILSVRC2012_val_00019319.bin 224 224 +40329 ./prep_dataset/ILSVRC2012_val_00016086.bin 224 224 +40330 ./prep_dataset/ILSVRC2012_val_00045472.bin 224 224 +40331 ./prep_dataset/ILSVRC2012_val_00003429.bin 224 224 +40332 ./prep_dataset/ILSVRC2012_val_00025275.bin 224 224 +40333 ./prep_dataset/ILSVRC2012_val_00049500.bin 224 224 +40334 ./prep_dataset/ILSVRC2012_val_00038107.bin 224 224 +40335 ./prep_dataset/ILSVRC2012_val_00021669.bin 224 224 +40336 ./prep_dataset/ILSVRC2012_val_00008527.bin 224 224 +40337 ./prep_dataset/ILSVRC2012_val_00022475.bin 224 224 +40338 ./prep_dataset/ILSVRC2012_val_00041841.bin 224 224 +40339 ./prep_dataset/ILSVRC2012_val_00031382.bin 224 224 +40340 ./prep_dataset/ILSVRC2012_val_00020053.bin 224 224 +40341 ./prep_dataset/ILSVRC2012_val_00031075.bin 224 224 +40342 ./prep_dataset/ILSVRC2012_val_00006451.bin 224 224 +40343 ./prep_dataset/ILSVRC2012_val_00003773.bin 224 224 +40344 ./prep_dataset/ILSVRC2012_val_00003413.bin 224 224 +40345 ./prep_dataset/ILSVRC2012_val_00018734.bin 224 224 +40346 ./prep_dataset/ILSVRC2012_val_00014964.bin 224 224 +40347 ./prep_dataset/ILSVRC2012_val_00031868.bin 224 224 +40348 ./prep_dataset/ILSVRC2012_val_00038891.bin 224 224 +40349 ./prep_dataset/ILSVRC2012_val_00034855.bin 224 224 +40350 ./prep_dataset/ILSVRC2012_val_00005158.bin 224 224 +40351 ./prep_dataset/ILSVRC2012_val_00012163.bin 224 224 +40352 ./prep_dataset/ILSVRC2012_val_00014413.bin 224 224 +40353 ./prep_dataset/ILSVRC2012_val_00049535.bin 224 224 +40354 ./prep_dataset/ILSVRC2012_val_00011148.bin 224 224 +40355 ./prep_dataset/ILSVRC2012_val_00039067.bin 224 224 +40356 ./prep_dataset/ILSVRC2012_val_00045493.bin 224 224 +40357 ./prep_dataset/ILSVRC2012_val_00030951.bin 224 224 +40358 ./prep_dataset/ILSVRC2012_val_00017207.bin 224 224 +40359 ./prep_dataset/ILSVRC2012_val_00023250.bin 224 224 +40360 ./prep_dataset/ILSVRC2012_val_00030792.bin 224 224 +40361 ./prep_dataset/ILSVRC2012_val_00000855.bin 224 224 +40362 ./prep_dataset/ILSVRC2012_val_00039813.bin 224 224 +40363 ./prep_dataset/ILSVRC2012_val_00039370.bin 224 224 +40364 ./prep_dataset/ILSVRC2012_val_00015042.bin 224 224 +40365 ./prep_dataset/ILSVRC2012_val_00023897.bin 224 224 +40366 ./prep_dataset/ILSVRC2012_val_00002696.bin 224 224 +40367 ./prep_dataset/ILSVRC2012_val_00040999.bin 224 224 +40368 ./prep_dataset/ILSVRC2012_val_00043886.bin 224 224 +40369 ./prep_dataset/ILSVRC2012_val_00023810.bin 224 224 +40370 ./prep_dataset/ILSVRC2012_val_00047137.bin 224 224 +40371 ./prep_dataset/ILSVRC2012_val_00028817.bin 224 224 +40372 ./prep_dataset/ILSVRC2012_val_00032941.bin 224 224 +40373 ./prep_dataset/ILSVRC2012_val_00041401.bin 224 224 +40374 ./prep_dataset/ILSVRC2012_val_00011961.bin 224 224 +40375 ./prep_dataset/ILSVRC2012_val_00033040.bin 224 224 +40376 ./prep_dataset/ILSVRC2012_val_00027816.bin 224 224 +40377 ./prep_dataset/ILSVRC2012_val_00000407.bin 224 224 +40378 ./prep_dataset/ILSVRC2012_val_00043551.bin 224 224 +40379 ./prep_dataset/ILSVRC2012_val_00036584.bin 224 224 +40380 ./prep_dataset/ILSVRC2012_val_00016528.bin 224 224 +40381 ./prep_dataset/ILSVRC2012_val_00005125.bin 224 224 +40382 ./prep_dataset/ILSVRC2012_val_00011303.bin 224 224 +40383 ./prep_dataset/ILSVRC2012_val_00044799.bin 224 224 +40384 ./prep_dataset/ILSVRC2012_val_00043725.bin 224 224 +40385 ./prep_dataset/ILSVRC2012_val_00007476.bin 224 224 +40386 ./prep_dataset/ILSVRC2012_val_00009373.bin 224 224 +40387 ./prep_dataset/ILSVRC2012_val_00036003.bin 224 224 +40388 ./prep_dataset/ILSVRC2012_val_00030669.bin 224 224 +40389 ./prep_dataset/ILSVRC2012_val_00027245.bin 224 224 +40390 ./prep_dataset/ILSVRC2012_val_00046266.bin 224 224 +40391 ./prep_dataset/ILSVRC2012_val_00048549.bin 224 224 +40392 ./prep_dataset/ILSVRC2012_val_00033290.bin 224 224 +40393 ./prep_dataset/ILSVRC2012_val_00007113.bin 224 224 +40394 ./prep_dataset/ILSVRC2012_val_00046599.bin 224 224 +40395 ./prep_dataset/ILSVRC2012_val_00014714.bin 224 224 +40396 ./prep_dataset/ILSVRC2012_val_00016585.bin 224 224 +40397 ./prep_dataset/ILSVRC2012_val_00004899.bin 224 224 +40398 ./prep_dataset/ILSVRC2012_val_00029504.bin 224 224 +40399 ./prep_dataset/ILSVRC2012_val_00006384.bin 224 224 +40400 ./prep_dataset/ILSVRC2012_val_00030243.bin 224 224 +40401 ./prep_dataset/ILSVRC2012_val_00035096.bin 224 224 +40402 ./prep_dataset/ILSVRC2012_val_00041575.bin 224 224 +40403 ./prep_dataset/ILSVRC2012_val_00017235.bin 224 224 +40404 ./prep_dataset/ILSVRC2012_val_00005048.bin 224 224 +40405 ./prep_dataset/ILSVRC2012_val_00009678.bin 224 224 +40406 ./prep_dataset/ILSVRC2012_val_00032127.bin 224 224 +40407 ./prep_dataset/ILSVRC2012_val_00043354.bin 224 224 +40408 ./prep_dataset/ILSVRC2012_val_00048880.bin 224 224 +40409 ./prep_dataset/ILSVRC2012_val_00014187.bin 224 224 +40410 ./prep_dataset/ILSVRC2012_val_00006096.bin 224 224 +40411 ./prep_dataset/ILSVRC2012_val_00028094.bin 224 224 +40412 ./prep_dataset/ILSVRC2012_val_00044612.bin 224 224 +40413 ./prep_dataset/ILSVRC2012_val_00044222.bin 224 224 +40414 ./prep_dataset/ILSVRC2012_val_00018882.bin 224 224 +40415 ./prep_dataset/ILSVRC2012_val_00016957.bin 224 224 +40416 ./prep_dataset/ILSVRC2012_val_00044547.bin 224 224 +40417 ./prep_dataset/ILSVRC2012_val_00046516.bin 224 224 +40418 ./prep_dataset/ILSVRC2012_val_00006740.bin 224 224 +40419 ./prep_dataset/ILSVRC2012_val_00037178.bin 224 224 +40420 ./prep_dataset/ILSVRC2012_val_00044248.bin 224 224 +40421 ./prep_dataset/ILSVRC2012_val_00014763.bin 224 224 +40422 ./prep_dataset/ILSVRC2012_val_00008850.bin 224 224 +40423 ./prep_dataset/ILSVRC2012_val_00025969.bin 224 224 +40424 ./prep_dataset/ILSVRC2012_val_00040560.bin 224 224 +40425 ./prep_dataset/ILSVRC2012_val_00021678.bin 224 224 +40426 ./prep_dataset/ILSVRC2012_val_00025159.bin 224 224 +40427 ./prep_dataset/ILSVRC2012_val_00003918.bin 224 224 +40428 ./prep_dataset/ILSVRC2012_val_00002547.bin 224 224 +40429 ./prep_dataset/ILSVRC2012_val_00019015.bin 224 224 +40430 ./prep_dataset/ILSVRC2012_val_00011308.bin 224 224 +40431 ./prep_dataset/ILSVRC2012_val_00002688.bin 224 224 +40432 ./prep_dataset/ILSVRC2012_val_00001687.bin 224 224 +40433 ./prep_dataset/ILSVRC2012_val_00032085.bin 224 224 +40434 ./prep_dataset/ILSVRC2012_val_00025204.bin 224 224 +40435 ./prep_dataset/ILSVRC2012_val_00033152.bin 224 224 +40436 ./prep_dataset/ILSVRC2012_val_00006897.bin 224 224 +40437 ./prep_dataset/ILSVRC2012_val_00036176.bin 224 224 +40438 ./prep_dataset/ILSVRC2012_val_00015446.bin 224 224 +40439 ./prep_dataset/ILSVRC2012_val_00027434.bin 224 224 +40440 ./prep_dataset/ILSVRC2012_val_00013815.bin 224 224 +40441 ./prep_dataset/ILSVRC2012_val_00024836.bin 224 224 +40442 ./prep_dataset/ILSVRC2012_val_00003534.bin 224 224 +40443 ./prep_dataset/ILSVRC2012_val_00040784.bin 224 224 +40444 ./prep_dataset/ILSVRC2012_val_00004993.bin 224 224 +40445 ./prep_dataset/ILSVRC2012_val_00024285.bin 224 224 +40446 ./prep_dataset/ILSVRC2012_val_00019339.bin 224 224 +40447 ./prep_dataset/ILSVRC2012_val_00042395.bin 224 224 +40448 ./prep_dataset/ILSVRC2012_val_00024756.bin 224 224 +40449 ./prep_dataset/ILSVRC2012_val_00026984.bin 224 224 +40450 ./prep_dataset/ILSVRC2012_val_00033257.bin 224 224 +40451 ./prep_dataset/ILSVRC2012_val_00029159.bin 224 224 +40452 ./prep_dataset/ILSVRC2012_val_00002592.bin 224 224 +40453 ./prep_dataset/ILSVRC2012_val_00024032.bin 224 224 +40454 ./prep_dataset/ILSVRC2012_val_00008703.bin 224 224 +40455 ./prep_dataset/ILSVRC2012_val_00000134.bin 224 224 +40456 ./prep_dataset/ILSVRC2012_val_00028397.bin 224 224 +40457 ./prep_dataset/ILSVRC2012_val_00031150.bin 224 224 +40458 ./prep_dataset/ILSVRC2012_val_00031512.bin 224 224 +40459 ./prep_dataset/ILSVRC2012_val_00026756.bin 224 224 +40460 ./prep_dataset/ILSVRC2012_val_00029849.bin 224 224 +40461 ./prep_dataset/ILSVRC2012_val_00002119.bin 224 224 +40462 ./prep_dataset/ILSVRC2012_val_00004868.bin 224 224 +40463 ./prep_dataset/ILSVRC2012_val_00012538.bin 224 224 +40464 ./prep_dataset/ILSVRC2012_val_00002980.bin 224 224 +40465 ./prep_dataset/ILSVRC2012_val_00003081.bin 224 224 +40466 ./prep_dataset/ILSVRC2012_val_00004802.bin 224 224 +40467 ./prep_dataset/ILSVRC2012_val_00026338.bin 224 224 +40468 ./prep_dataset/ILSVRC2012_val_00046945.bin 224 224 +40469 ./prep_dataset/ILSVRC2012_val_00042874.bin 224 224 +40470 ./prep_dataset/ILSVRC2012_val_00025389.bin 224 224 +40471 ./prep_dataset/ILSVRC2012_val_00040279.bin 224 224 +40472 ./prep_dataset/ILSVRC2012_val_00019833.bin 224 224 +40473 ./prep_dataset/ILSVRC2012_val_00035725.bin 224 224 +40474 ./prep_dataset/ILSVRC2012_val_00013940.bin 224 224 +40475 ./prep_dataset/ILSVRC2012_val_00040302.bin 224 224 +40476 ./prep_dataset/ILSVRC2012_val_00011352.bin 224 224 +40477 ./prep_dataset/ILSVRC2012_val_00003363.bin 224 224 +40478 ./prep_dataset/ILSVRC2012_val_00045390.bin 224 224 +40479 ./prep_dataset/ILSVRC2012_val_00006010.bin 224 224 +40480 ./prep_dataset/ILSVRC2012_val_00042584.bin 224 224 +40481 ./prep_dataset/ILSVRC2012_val_00003272.bin 224 224 +40482 ./prep_dataset/ILSVRC2012_val_00047040.bin 224 224 +40483 ./prep_dataset/ILSVRC2012_val_00013542.bin 224 224 +40484 ./prep_dataset/ILSVRC2012_val_00045999.bin 224 224 +40485 ./prep_dataset/ILSVRC2012_val_00040443.bin 224 224 +40486 ./prep_dataset/ILSVRC2012_val_00015088.bin 224 224 +40487 ./prep_dataset/ILSVRC2012_val_00040400.bin 224 224 +40488 ./prep_dataset/ILSVRC2012_val_00000258.bin 224 224 +40489 ./prep_dataset/ILSVRC2012_val_00023294.bin 224 224 +40490 ./prep_dataset/ILSVRC2012_val_00045579.bin 224 224 +40491 ./prep_dataset/ILSVRC2012_val_00036745.bin 224 224 +40492 ./prep_dataset/ILSVRC2012_val_00042501.bin 224 224 +40493 ./prep_dataset/ILSVRC2012_val_00008799.bin 224 224 +40494 ./prep_dataset/ILSVRC2012_val_00029531.bin 224 224 +40495 ./prep_dataset/ILSVRC2012_val_00020375.bin 224 224 +40496 ./prep_dataset/ILSVRC2012_val_00042215.bin 224 224 +40497 ./prep_dataset/ILSVRC2012_val_00041976.bin 224 224 +40498 ./prep_dataset/ILSVRC2012_val_00011777.bin 224 224 +40499 ./prep_dataset/ILSVRC2012_val_00026378.bin 224 224 +40500 ./prep_dataset/ILSVRC2012_val_00028256.bin 224 224 +40501 ./prep_dataset/ILSVRC2012_val_00031646.bin 224 224 +40502 ./prep_dataset/ILSVRC2012_val_00008472.bin 224 224 +40503 ./prep_dataset/ILSVRC2012_val_00018493.bin 224 224 +40504 ./prep_dataset/ILSVRC2012_val_00024228.bin 224 224 +40505 ./prep_dataset/ILSVRC2012_val_00009552.bin 224 224 +40506 ./prep_dataset/ILSVRC2012_val_00040761.bin 224 224 +40507 ./prep_dataset/ILSVRC2012_val_00015079.bin 224 224 +40508 ./prep_dataset/ILSVRC2012_val_00036503.bin 224 224 +40509 ./prep_dataset/ILSVRC2012_val_00016653.bin 224 224 +40510 ./prep_dataset/ILSVRC2012_val_00026120.bin 224 224 +40511 ./prep_dataset/ILSVRC2012_val_00013401.bin 224 224 +40512 ./prep_dataset/ILSVRC2012_val_00031399.bin 224 224 +40513 ./prep_dataset/ILSVRC2012_val_00044243.bin 224 224 +40514 ./prep_dataset/ILSVRC2012_val_00046183.bin 224 224 +40515 ./prep_dataset/ILSVRC2012_val_00012485.bin 224 224 +40516 ./prep_dataset/ILSVRC2012_val_00048570.bin 224 224 +40517 ./prep_dataset/ILSVRC2012_val_00027922.bin 224 224 +40518 ./prep_dataset/ILSVRC2012_val_00009983.bin 224 224 +40519 ./prep_dataset/ILSVRC2012_val_00020257.bin 224 224 +40520 ./prep_dataset/ILSVRC2012_val_00016930.bin 224 224 +40521 ./prep_dataset/ILSVRC2012_val_00028940.bin 224 224 +40522 ./prep_dataset/ILSVRC2012_val_00042497.bin 224 224 +40523 ./prep_dataset/ILSVRC2012_val_00029640.bin 224 224 +40524 ./prep_dataset/ILSVRC2012_val_00013828.bin 224 224 +40525 ./prep_dataset/ILSVRC2012_val_00002025.bin 224 224 +40526 ./prep_dataset/ILSVRC2012_val_00019110.bin 224 224 +40527 ./prep_dataset/ILSVRC2012_val_00002819.bin 224 224 +40528 ./prep_dataset/ILSVRC2012_val_00037978.bin 224 224 +40529 ./prep_dataset/ILSVRC2012_val_00004894.bin 224 224 +40530 ./prep_dataset/ILSVRC2012_val_00026859.bin 224 224 +40531 ./prep_dataset/ILSVRC2012_val_00025748.bin 224 224 +40532 ./prep_dataset/ILSVRC2012_val_00032097.bin 224 224 +40533 ./prep_dataset/ILSVRC2012_val_00016963.bin 224 224 +40534 ./prep_dataset/ILSVRC2012_val_00042018.bin 224 224 +40535 ./prep_dataset/ILSVRC2012_val_00036197.bin 224 224 +40536 ./prep_dataset/ILSVRC2012_val_00021531.bin 224 224 +40537 ./prep_dataset/ILSVRC2012_val_00017715.bin 224 224 +40538 ./prep_dataset/ILSVRC2012_val_00005099.bin 224 224 +40539 ./prep_dataset/ILSVRC2012_val_00015697.bin 224 224 +40540 ./prep_dataset/ILSVRC2012_val_00019956.bin 224 224 +40541 ./prep_dataset/ILSVRC2012_val_00048921.bin 224 224 +40542 ./prep_dataset/ILSVRC2012_val_00013880.bin 224 224 +40543 ./prep_dataset/ILSVRC2012_val_00014845.bin 224 224 +40544 ./prep_dataset/ILSVRC2012_val_00013692.bin 224 224 +40545 ./prep_dataset/ILSVRC2012_val_00046224.bin 224 224 +40546 ./prep_dataset/ILSVRC2012_val_00035497.bin 224 224 +40547 ./prep_dataset/ILSVRC2012_val_00027374.bin 224 224 +40548 ./prep_dataset/ILSVRC2012_val_00012348.bin 224 224 +40549 ./prep_dataset/ILSVRC2012_val_00035081.bin 224 224 +40550 ./prep_dataset/ILSVRC2012_val_00033823.bin 224 224 +40551 ./prep_dataset/ILSVRC2012_val_00030582.bin 224 224 +40552 ./prep_dataset/ILSVRC2012_val_00019988.bin 224 224 +40553 ./prep_dataset/ILSVRC2012_val_00005226.bin 224 224 +40554 ./prep_dataset/ILSVRC2012_val_00048999.bin 224 224 +40555 ./prep_dataset/ILSVRC2012_val_00039336.bin 224 224 +40556 ./prep_dataset/ILSVRC2012_val_00039438.bin 224 224 +40557 ./prep_dataset/ILSVRC2012_val_00004541.bin 224 224 +40558 ./prep_dataset/ILSVRC2012_val_00024153.bin 224 224 +40559 ./prep_dataset/ILSVRC2012_val_00005884.bin 224 224 +40560 ./prep_dataset/ILSVRC2012_val_00003017.bin 224 224 +40561 ./prep_dataset/ILSVRC2012_val_00009892.bin 224 224 +40562 ./prep_dataset/ILSVRC2012_val_00027566.bin 224 224 +40563 ./prep_dataset/ILSVRC2012_val_00016605.bin 224 224 +40564 ./prep_dataset/ILSVRC2012_val_00046710.bin 224 224 +40565 ./prep_dataset/ILSVRC2012_val_00044032.bin 224 224 +40566 ./prep_dataset/ILSVRC2012_val_00007915.bin 224 224 +40567 ./prep_dataset/ILSVRC2012_val_00025395.bin 224 224 +40568 ./prep_dataset/ILSVRC2012_val_00039569.bin 224 224 +40569 ./prep_dataset/ILSVRC2012_val_00036078.bin 224 224 +40570 ./prep_dataset/ILSVRC2012_val_00032984.bin 224 224 +40571 ./prep_dataset/ILSVRC2012_val_00010461.bin 224 224 +40572 ./prep_dataset/ILSVRC2012_val_00032668.bin 224 224 +40573 ./prep_dataset/ILSVRC2012_val_00015403.bin 224 224 +40574 ./prep_dataset/ILSVRC2012_val_00041962.bin 224 224 +40575 ./prep_dataset/ILSVRC2012_val_00033482.bin 224 224 +40576 ./prep_dataset/ILSVRC2012_val_00045849.bin 224 224 +40577 ./prep_dataset/ILSVRC2012_val_00005228.bin 224 224 +40578 ./prep_dataset/ILSVRC2012_val_00011257.bin 224 224 +40579 ./prep_dataset/ILSVRC2012_val_00009311.bin 224 224 +40580 ./prep_dataset/ILSVRC2012_val_00030187.bin 224 224 +40581 ./prep_dataset/ILSVRC2012_val_00017148.bin 224 224 +40582 ./prep_dataset/ILSVRC2012_val_00045260.bin 224 224 +40583 ./prep_dataset/ILSVRC2012_val_00027826.bin 224 224 +40584 ./prep_dataset/ILSVRC2012_val_00027219.bin 224 224 +40585 ./prep_dataset/ILSVRC2012_val_00039855.bin 224 224 +40586 ./prep_dataset/ILSVRC2012_val_00007363.bin 224 224 +40587 ./prep_dataset/ILSVRC2012_val_00009524.bin 224 224 +40588 ./prep_dataset/ILSVRC2012_val_00030796.bin 224 224 +40589 ./prep_dataset/ILSVRC2012_val_00016323.bin 224 224 +40590 ./prep_dataset/ILSVRC2012_val_00017023.bin 224 224 +40591 ./prep_dataset/ILSVRC2012_val_00042450.bin 224 224 +40592 ./prep_dataset/ILSVRC2012_val_00044203.bin 224 224 +40593 ./prep_dataset/ILSVRC2012_val_00047984.bin 224 224 +40594 ./prep_dataset/ILSVRC2012_val_00032291.bin 224 224 +40595 ./prep_dataset/ILSVRC2012_val_00043147.bin 224 224 +40596 ./prep_dataset/ILSVRC2012_val_00032950.bin 224 224 +40597 ./prep_dataset/ILSVRC2012_val_00030042.bin 224 224 +40598 ./prep_dataset/ILSVRC2012_val_00036178.bin 224 224 +40599 ./prep_dataset/ILSVRC2012_val_00023222.bin 224 224 +40600 ./prep_dataset/ILSVRC2012_val_00036312.bin 224 224 +40601 ./prep_dataset/ILSVRC2012_val_00043230.bin 224 224 +40602 ./prep_dataset/ILSVRC2012_val_00024762.bin 224 224 +40603 ./prep_dataset/ILSVRC2012_val_00016425.bin 224 224 +40604 ./prep_dataset/ILSVRC2012_val_00043474.bin 224 224 +40605 ./prep_dataset/ILSVRC2012_val_00031599.bin 224 224 +40606 ./prep_dataset/ILSVRC2012_val_00023532.bin 224 224 +40607 ./prep_dataset/ILSVRC2012_val_00035342.bin 224 224 +40608 ./prep_dataset/ILSVRC2012_val_00000001.bin 224 224 +40609 ./prep_dataset/ILSVRC2012_val_00045319.bin 224 224 +40610 ./prep_dataset/ILSVRC2012_val_00012235.bin 224 224 +40611 ./prep_dataset/ILSVRC2012_val_00020174.bin 224 224 +40612 ./prep_dataset/ILSVRC2012_val_00023696.bin 224 224 +40613 ./prep_dataset/ILSVRC2012_val_00041080.bin 224 224 +40614 ./prep_dataset/ILSVRC2012_val_00022163.bin 224 224 +40615 ./prep_dataset/ILSVRC2012_val_00014264.bin 224 224 +40616 ./prep_dataset/ILSVRC2012_val_00040257.bin 224 224 +40617 ./prep_dataset/ILSVRC2012_val_00006221.bin 224 224 +40618 ./prep_dataset/ILSVRC2012_val_00017395.bin 224 224 +40619 ./prep_dataset/ILSVRC2012_val_00003086.bin 224 224 +40620 ./prep_dataset/ILSVRC2012_val_00025978.bin 224 224 +40621 ./prep_dataset/ILSVRC2012_val_00038166.bin 224 224 +40622 ./prep_dataset/ILSVRC2012_val_00033597.bin 224 224 +40623 ./prep_dataset/ILSVRC2012_val_00013562.bin 224 224 +40624 ./prep_dataset/ILSVRC2012_val_00033464.bin 224 224 +40625 ./prep_dataset/ILSVRC2012_val_00016307.bin 224 224 +40626 ./prep_dataset/ILSVRC2012_val_00047754.bin 224 224 +40627 ./prep_dataset/ILSVRC2012_val_00013244.bin 224 224 +40628 ./prep_dataset/ILSVRC2012_val_00044578.bin 224 224 +40629 ./prep_dataset/ILSVRC2012_val_00042653.bin 224 224 +40630 ./prep_dataset/ILSVRC2012_val_00033331.bin 224 224 +40631 ./prep_dataset/ILSVRC2012_val_00038742.bin 224 224 +40632 ./prep_dataset/ILSVRC2012_val_00007471.bin 224 224 +40633 ./prep_dataset/ILSVRC2012_val_00048643.bin 224 224 +40634 ./prep_dataset/ILSVRC2012_val_00006958.bin 224 224 +40635 ./prep_dataset/ILSVRC2012_val_00017065.bin 224 224 +40636 ./prep_dataset/ILSVRC2012_val_00009048.bin 224 224 +40637 ./prep_dataset/ILSVRC2012_val_00012088.bin 224 224 +40638 ./prep_dataset/ILSVRC2012_val_00048145.bin 224 224 +40639 ./prep_dataset/ILSVRC2012_val_00003948.bin 224 224 +40640 ./prep_dataset/ILSVRC2012_val_00008211.bin 224 224 +40641 ./prep_dataset/ILSVRC2012_val_00001138.bin 224 224 +40642 ./prep_dataset/ILSVRC2012_val_00047739.bin 224 224 +40643 ./prep_dataset/ILSVRC2012_val_00034667.bin 224 224 +40644 ./prep_dataset/ILSVRC2012_val_00028650.bin 224 224 +40645 ./prep_dataset/ILSVRC2012_val_00047107.bin 224 224 +40646 ./prep_dataset/ILSVRC2012_val_00000717.bin 224 224 +40647 ./prep_dataset/ILSVRC2012_val_00001261.bin 224 224 +40648 ./prep_dataset/ILSVRC2012_val_00034922.bin 224 224 +40649 ./prep_dataset/ILSVRC2012_val_00020837.bin 224 224 +40650 ./prep_dataset/ILSVRC2012_val_00021153.bin 224 224 +40651 ./prep_dataset/ILSVRC2012_val_00011471.bin 224 224 +40652 ./prep_dataset/ILSVRC2012_val_00005992.bin 224 224 +40653 ./prep_dataset/ILSVRC2012_val_00015615.bin 224 224 +40654 ./prep_dataset/ILSVRC2012_val_00025879.bin 224 224 +40655 ./prep_dataset/ILSVRC2012_val_00026012.bin 224 224 +40656 ./prep_dataset/ILSVRC2012_val_00005931.bin 224 224 +40657 ./prep_dataset/ILSVRC2012_val_00006834.bin 224 224 +40658 ./prep_dataset/ILSVRC2012_val_00037491.bin 224 224 +40659 ./prep_dataset/ILSVRC2012_val_00037260.bin 224 224 +40660 ./prep_dataset/ILSVRC2012_val_00021763.bin 224 224 +40661 ./prep_dataset/ILSVRC2012_val_00007613.bin 224 224 +40662 ./prep_dataset/ILSVRC2012_val_00002169.bin 224 224 +40663 ./prep_dataset/ILSVRC2012_val_00042835.bin 224 224 +40664 ./prep_dataset/ILSVRC2012_val_00043197.bin 224 224 +40665 ./prep_dataset/ILSVRC2012_val_00018625.bin 224 224 +40666 ./prep_dataset/ILSVRC2012_val_00043207.bin 224 224 +40667 ./prep_dataset/ILSVRC2012_val_00010894.bin 224 224 +40668 ./prep_dataset/ILSVRC2012_val_00031454.bin 224 224 +40669 ./prep_dataset/ILSVRC2012_val_00019625.bin 224 224 +40670 ./prep_dataset/ILSVRC2012_val_00047082.bin 224 224 +40671 ./prep_dataset/ILSVRC2012_val_00030791.bin 224 224 +40672 ./prep_dataset/ILSVRC2012_val_00027629.bin 224 224 +40673 ./prep_dataset/ILSVRC2012_val_00030302.bin 224 224 +40674 ./prep_dataset/ILSVRC2012_val_00033238.bin 224 224 +40675 ./prep_dataset/ILSVRC2012_val_00037040.bin 224 224 +40676 ./prep_dataset/ILSVRC2012_val_00037629.bin 224 224 +40677 ./prep_dataset/ILSVRC2012_val_00047724.bin 224 224 +40678 ./prep_dataset/ILSVRC2012_val_00028968.bin 224 224 +40679 ./prep_dataset/ILSVRC2012_val_00024545.bin 224 224 +40680 ./prep_dataset/ILSVRC2012_val_00019173.bin 224 224 +40681 ./prep_dataset/ILSVRC2012_val_00034754.bin 224 224 +40682 ./prep_dataset/ILSVRC2012_val_00031701.bin 224 224 +40683 ./prep_dataset/ILSVRC2012_val_00039852.bin 224 224 +40684 ./prep_dataset/ILSVRC2012_val_00040626.bin 224 224 +40685 ./prep_dataset/ILSVRC2012_val_00004520.bin 224 224 +40686 ./prep_dataset/ILSVRC2012_val_00012179.bin 224 224 +40687 ./prep_dataset/ILSVRC2012_val_00004010.bin 224 224 +40688 ./prep_dataset/ILSVRC2012_val_00038987.bin 224 224 +40689 ./prep_dataset/ILSVRC2012_val_00029497.bin 224 224 +40690 ./prep_dataset/ILSVRC2012_val_00011997.bin 224 224 +40691 ./prep_dataset/ILSVRC2012_val_00024777.bin 224 224 +40692 ./prep_dataset/ILSVRC2012_val_00039543.bin 224 224 +40693 ./prep_dataset/ILSVRC2012_val_00041624.bin 224 224 +40694 ./prep_dataset/ILSVRC2012_val_00029115.bin 224 224 +40695 ./prep_dataset/ILSVRC2012_val_00016730.bin 224 224 +40696 ./prep_dataset/ILSVRC2012_val_00034096.bin 224 224 +40697 ./prep_dataset/ILSVRC2012_val_00002389.bin 224 224 +40698 ./prep_dataset/ILSVRC2012_val_00006822.bin 224 224 +40699 ./prep_dataset/ILSVRC2012_val_00000639.bin 224 224 +40700 ./prep_dataset/ILSVRC2012_val_00007777.bin 224 224 +40701 ./prep_dataset/ILSVRC2012_val_00025963.bin 224 224 +40702 ./prep_dataset/ILSVRC2012_val_00047834.bin 224 224 +40703 ./prep_dataset/ILSVRC2012_val_00042181.bin 224 224 +40704 ./prep_dataset/ILSVRC2012_val_00013655.bin 224 224 +40705 ./prep_dataset/ILSVRC2012_val_00002323.bin 224 224 +40706 ./prep_dataset/ILSVRC2012_val_00020245.bin 224 224 +40707 ./prep_dataset/ILSVRC2012_val_00040824.bin 224 224 +40708 ./prep_dataset/ILSVRC2012_val_00037645.bin 224 224 +40709 ./prep_dataset/ILSVRC2012_val_00030480.bin 224 224 +40710 ./prep_dataset/ILSVRC2012_val_00009530.bin 224 224 +40711 ./prep_dataset/ILSVRC2012_val_00027956.bin 224 224 +40712 ./prep_dataset/ILSVRC2012_val_00037224.bin 224 224 +40713 ./prep_dataset/ILSVRC2012_val_00009859.bin 224 224 +40714 ./prep_dataset/ILSVRC2012_val_00046264.bin 224 224 +40715 ./prep_dataset/ILSVRC2012_val_00048241.bin 224 224 +40716 ./prep_dataset/ILSVRC2012_val_00010303.bin 224 224 +40717 ./prep_dataset/ILSVRC2012_val_00048252.bin 224 224 +40718 ./prep_dataset/ILSVRC2012_val_00021980.bin 224 224 +40719 ./prep_dataset/ILSVRC2012_val_00045019.bin 224 224 +40720 ./prep_dataset/ILSVRC2012_val_00032844.bin 224 224 +40721 ./prep_dataset/ILSVRC2012_val_00017157.bin 224 224 +40722 ./prep_dataset/ILSVRC2012_val_00010548.bin 224 224 +40723 ./prep_dataset/ILSVRC2012_val_00037707.bin 224 224 +40724 ./prep_dataset/ILSVRC2012_val_00041685.bin 224 224 +40725 ./prep_dataset/ILSVRC2012_val_00007344.bin 224 224 +40726 ./prep_dataset/ILSVRC2012_val_00035305.bin 224 224 +40727 ./prep_dataset/ILSVRC2012_val_00008042.bin 224 224 +40728 ./prep_dataset/ILSVRC2012_val_00042528.bin 224 224 +40729 ./prep_dataset/ILSVRC2012_val_00041421.bin 224 224 +40730 ./prep_dataset/ILSVRC2012_val_00013224.bin 224 224 +40731 ./prep_dataset/ILSVRC2012_val_00013793.bin 224 224 +40732 ./prep_dataset/ILSVRC2012_val_00011910.bin 224 224 +40733 ./prep_dataset/ILSVRC2012_val_00006749.bin 224 224 +40734 ./prep_dataset/ILSVRC2012_val_00014560.bin 224 224 +40735 ./prep_dataset/ILSVRC2012_val_00019082.bin 224 224 +40736 ./prep_dataset/ILSVRC2012_val_00032166.bin 224 224 +40737 ./prep_dataset/ILSVRC2012_val_00034009.bin 224 224 +40738 ./prep_dataset/ILSVRC2012_val_00042037.bin 224 224 +40739 ./prep_dataset/ILSVRC2012_val_00008513.bin 224 224 +40740 ./prep_dataset/ILSVRC2012_val_00038054.bin 224 224 +40741 ./prep_dataset/ILSVRC2012_val_00035022.bin 224 224 +40742 ./prep_dataset/ILSVRC2012_val_00029714.bin 224 224 +40743 ./prep_dataset/ILSVRC2012_val_00006855.bin 224 224 +40744 ./prep_dataset/ILSVRC2012_val_00029380.bin 224 224 +40745 ./prep_dataset/ILSVRC2012_val_00018659.bin 224 224 +40746 ./prep_dataset/ILSVRC2012_val_00043796.bin 224 224 +40747 ./prep_dataset/ILSVRC2012_val_00022567.bin 224 224 +40748 ./prep_dataset/ILSVRC2012_val_00024072.bin 224 224 +40749 ./prep_dataset/ILSVRC2012_val_00031889.bin 224 224 +40750 ./prep_dataset/ILSVRC2012_val_00014322.bin 224 224 +40751 ./prep_dataset/ILSVRC2012_val_00015240.bin 224 224 +40752 ./prep_dataset/ILSVRC2012_val_00035967.bin 224 224 +40753 ./prep_dataset/ILSVRC2012_val_00016012.bin 224 224 +40754 ./prep_dataset/ILSVRC2012_val_00021856.bin 224 224 +40755 ./prep_dataset/ILSVRC2012_val_00005969.bin 224 224 +40756 ./prep_dataset/ILSVRC2012_val_00039912.bin 224 224 +40757 ./prep_dataset/ILSVRC2012_val_00014103.bin 224 224 +40758 ./prep_dataset/ILSVRC2012_val_00016236.bin 224 224 +40759 ./prep_dataset/ILSVRC2012_val_00047736.bin 224 224 +40760 ./prep_dataset/ILSVRC2012_val_00027121.bin 224 224 +40761 ./prep_dataset/ILSVRC2012_val_00038536.bin 224 224 +40762 ./prep_dataset/ILSVRC2012_val_00022287.bin 224 224 +40763 ./prep_dataset/ILSVRC2012_val_00021783.bin 224 224 +40764 ./prep_dataset/ILSVRC2012_val_00045908.bin 224 224 +40765 ./prep_dataset/ILSVRC2012_val_00036731.bin 224 224 +40766 ./prep_dataset/ILSVRC2012_val_00034504.bin 224 224 +40767 ./prep_dataset/ILSVRC2012_val_00019178.bin 224 224 +40768 ./prep_dataset/ILSVRC2012_val_00008041.bin 224 224 +40769 ./prep_dataset/ILSVRC2012_val_00010055.bin 224 224 +40770 ./prep_dataset/ILSVRC2012_val_00011613.bin 224 224 +40771 ./prep_dataset/ILSVRC2012_val_00017215.bin 224 224 +40772 ./prep_dataset/ILSVRC2012_val_00005998.bin 224 224 +40773 ./prep_dataset/ILSVRC2012_val_00042841.bin 224 224 +40774 ./prep_dataset/ILSVRC2012_val_00023306.bin 224 224 +40775 ./prep_dataset/ILSVRC2012_val_00007454.bin 224 224 +40776 ./prep_dataset/ILSVRC2012_val_00032681.bin 224 224 +40777 ./prep_dataset/ILSVRC2012_val_00013475.bin 224 224 +40778 ./prep_dataset/ILSVRC2012_val_00009371.bin 224 224 +40779 ./prep_dataset/ILSVRC2012_val_00008203.bin 224 224 +40780 ./prep_dataset/ILSVRC2012_val_00038328.bin 224 224 +40781 ./prep_dataset/ILSVRC2012_val_00019235.bin 224 224 +40782 ./prep_dataset/ILSVRC2012_val_00028709.bin 224 224 +40783 ./prep_dataset/ILSVRC2012_val_00009002.bin 224 224 +40784 ./prep_dataset/ILSVRC2012_val_00029851.bin 224 224 +40785 ./prep_dataset/ILSVRC2012_val_00009369.bin 224 224 +40786 ./prep_dataset/ILSVRC2012_val_00007349.bin 224 224 +40787 ./prep_dataset/ILSVRC2012_val_00040402.bin 224 224 +40788 ./prep_dataset/ILSVRC2012_val_00034847.bin 224 224 +40789 ./prep_dataset/ILSVRC2012_val_00030567.bin 224 224 +40790 ./prep_dataset/ILSVRC2012_val_00041475.bin 224 224 +40791 ./prep_dataset/ILSVRC2012_val_00001994.bin 224 224 +40792 ./prep_dataset/ILSVRC2012_val_00013336.bin 224 224 +40793 ./prep_dataset/ILSVRC2012_val_00042448.bin 224 224 +40794 ./prep_dataset/ILSVRC2012_val_00028866.bin 224 224 +40795 ./prep_dataset/ILSVRC2012_val_00022376.bin 224 224 +40796 ./prep_dataset/ILSVRC2012_val_00043908.bin 224 224 +40797 ./prep_dataset/ILSVRC2012_val_00037591.bin 224 224 +40798 ./prep_dataset/ILSVRC2012_val_00002877.bin 224 224 +40799 ./prep_dataset/ILSVRC2012_val_00033222.bin 224 224 +40800 ./prep_dataset/ILSVRC2012_val_00043791.bin 224 224 +40801 ./prep_dataset/ILSVRC2012_val_00045634.bin 224 224 +40802 ./prep_dataset/ILSVRC2012_val_00031441.bin 224 224 +40803 ./prep_dataset/ILSVRC2012_val_00045229.bin 224 224 +40804 ./prep_dataset/ILSVRC2012_val_00047770.bin 224 224 +40805 ./prep_dataset/ILSVRC2012_val_00001120.bin 224 224 +40806 ./prep_dataset/ILSVRC2012_val_00025227.bin 224 224 +40807 ./prep_dataset/ILSVRC2012_val_00028813.bin 224 224 +40808 ./prep_dataset/ILSVRC2012_val_00020790.bin 224 224 +40809 ./prep_dataset/ILSVRC2012_val_00041348.bin 224 224 +40810 ./prep_dataset/ILSVRC2012_val_00021276.bin 224 224 +40811 ./prep_dataset/ILSVRC2012_val_00009235.bin 224 224 +40812 ./prep_dataset/ILSVRC2012_val_00023521.bin 224 224 +40813 ./prep_dataset/ILSVRC2012_val_00033227.bin 224 224 +40814 ./prep_dataset/ILSVRC2012_val_00029698.bin 224 224 +40815 ./prep_dataset/ILSVRC2012_val_00046519.bin 224 224 +40816 ./prep_dataset/ILSVRC2012_val_00035569.bin 224 224 +40817 ./prep_dataset/ILSVRC2012_val_00021135.bin 224 224 +40818 ./prep_dataset/ILSVRC2012_val_00016370.bin 224 224 +40819 ./prep_dataset/ILSVRC2012_val_00022624.bin 224 224 +40820 ./prep_dataset/ILSVRC2012_val_00005326.bin 224 224 +40821 ./prep_dataset/ILSVRC2012_val_00043674.bin 224 224 +40822 ./prep_dataset/ILSVRC2012_val_00016477.bin 224 224 +40823 ./prep_dataset/ILSVRC2012_val_00020856.bin 224 224 +40824 ./prep_dataset/ILSVRC2012_val_00005592.bin 224 224 +40825 ./prep_dataset/ILSVRC2012_val_00003597.bin 224 224 +40826 ./prep_dataset/ILSVRC2012_val_00010728.bin 224 224 +40827 ./prep_dataset/ILSVRC2012_val_00014253.bin 224 224 +40828 ./prep_dataset/ILSVRC2012_val_00009085.bin 224 224 +40829 ./prep_dataset/ILSVRC2012_val_00044610.bin 224 224 +40830 ./prep_dataset/ILSVRC2012_val_00022603.bin 224 224 +40831 ./prep_dataset/ILSVRC2012_val_00017780.bin 224 224 +40832 ./prep_dataset/ILSVRC2012_val_00034695.bin 224 224 +40833 ./prep_dataset/ILSVRC2012_val_00001105.bin 224 224 +40834 ./prep_dataset/ILSVRC2012_val_00022446.bin 224 224 +40835 ./prep_dataset/ILSVRC2012_val_00033948.bin 224 224 +40836 ./prep_dataset/ILSVRC2012_val_00034346.bin 224 224 +40837 ./prep_dataset/ILSVRC2012_val_00048663.bin 224 224 +40838 ./prep_dataset/ILSVRC2012_val_00042767.bin 224 224 +40839 ./prep_dataset/ILSVRC2012_val_00033973.bin 224 224 +40840 ./prep_dataset/ILSVRC2012_val_00024922.bin 224 224 +40841 ./prep_dataset/ILSVRC2012_val_00030307.bin 224 224 +40842 ./prep_dataset/ILSVRC2012_val_00028967.bin 224 224 +40843 ./prep_dataset/ILSVRC2012_val_00040798.bin 224 224 +40844 ./prep_dataset/ILSVRC2012_val_00046389.bin 224 224 +40845 ./prep_dataset/ILSVRC2012_val_00011638.bin 224 224 +40846 ./prep_dataset/ILSVRC2012_val_00032209.bin 224 224 +40847 ./prep_dataset/ILSVRC2012_val_00019092.bin 224 224 +40848 ./prep_dataset/ILSVRC2012_val_00018149.bin 224 224 +40849 ./prep_dataset/ILSVRC2012_val_00025357.bin 224 224 +40850 ./prep_dataset/ILSVRC2012_val_00021924.bin 224 224 +40851 ./prep_dataset/ILSVRC2012_val_00039853.bin 224 224 +40852 ./prep_dataset/ILSVRC2012_val_00015930.bin 224 224 +40853 ./prep_dataset/ILSVRC2012_val_00033766.bin 224 224 +40854 ./prep_dataset/ILSVRC2012_val_00018650.bin 224 224 +40855 ./prep_dataset/ILSVRC2012_val_00010790.bin 224 224 +40856 ./prep_dataset/ILSVRC2012_val_00028901.bin 224 224 +40857 ./prep_dataset/ILSVRC2012_val_00039957.bin 224 224 +40858 ./prep_dataset/ILSVRC2012_val_00011518.bin 224 224 +40859 ./prep_dataset/ILSVRC2012_val_00007548.bin 224 224 +40860 ./prep_dataset/ILSVRC2012_val_00006785.bin 224 224 +40861 ./prep_dataset/ILSVRC2012_val_00001692.bin 224 224 +40862 ./prep_dataset/ILSVRC2012_val_00015561.bin 224 224 +40863 ./prep_dataset/ILSVRC2012_val_00039231.bin 224 224 +40864 ./prep_dataset/ILSVRC2012_val_00011911.bin 224 224 +40865 ./prep_dataset/ILSVRC2012_val_00038101.bin 224 224 +40866 ./prep_dataset/ILSVRC2012_val_00037314.bin 224 224 +40867 ./prep_dataset/ILSVRC2012_val_00020992.bin 224 224 +40868 ./prep_dataset/ILSVRC2012_val_00017532.bin 224 224 +40869 ./prep_dataset/ILSVRC2012_val_00002820.bin 224 224 +40870 ./prep_dataset/ILSVRC2012_val_00006547.bin 224 224 +40871 ./prep_dataset/ILSVRC2012_val_00001712.bin 224 224 +40872 ./prep_dataset/ILSVRC2012_val_00038673.bin 224 224 +40873 ./prep_dataset/ILSVRC2012_val_00005291.bin 224 224 +40874 ./prep_dataset/ILSVRC2012_val_00007875.bin 224 224 +40875 ./prep_dataset/ILSVRC2012_val_00039176.bin 224 224 +40876 ./prep_dataset/ILSVRC2012_val_00016932.bin 224 224 +40877 ./prep_dataset/ILSVRC2012_val_00021077.bin 224 224 +40878 ./prep_dataset/ILSVRC2012_val_00012068.bin 224 224 +40879 ./prep_dataset/ILSVRC2012_val_00018852.bin 224 224 +40880 ./prep_dataset/ILSVRC2012_val_00048945.bin 224 224 +40881 ./prep_dataset/ILSVRC2012_val_00046304.bin 224 224 +40882 ./prep_dataset/ILSVRC2012_val_00037813.bin 224 224 +40883 ./prep_dataset/ILSVRC2012_val_00017762.bin 224 224 +40884 ./prep_dataset/ILSVRC2012_val_00038808.bin 224 224 +40885 ./prep_dataset/ILSVRC2012_val_00003458.bin 224 224 +40886 ./prep_dataset/ILSVRC2012_val_00007905.bin 224 224 +40887 ./prep_dataset/ILSVRC2012_val_00047227.bin 224 224 +40888 ./prep_dataset/ILSVRC2012_val_00035731.bin 224 224 +40889 ./prep_dataset/ILSVRC2012_val_00017711.bin 224 224 +40890 ./prep_dataset/ILSVRC2012_val_00042440.bin 224 224 +40891 ./prep_dataset/ILSVRC2012_val_00019945.bin 224 224 +40892 ./prep_dataset/ILSVRC2012_val_00033928.bin 224 224 +40893 ./prep_dataset/ILSVRC2012_val_00004532.bin 224 224 +40894 ./prep_dataset/ILSVRC2012_val_00027326.bin 224 224 +40895 ./prep_dataset/ILSVRC2012_val_00005234.bin 224 224 +40896 ./prep_dataset/ILSVRC2012_val_00005166.bin 224 224 +40897 ./prep_dataset/ILSVRC2012_val_00032778.bin 224 224 +40898 ./prep_dataset/ILSVRC2012_val_00035635.bin 224 224 +40899 ./prep_dataset/ILSVRC2012_val_00014629.bin 224 224 +40900 ./prep_dataset/ILSVRC2012_val_00001062.bin 224 224 +40901 ./prep_dataset/ILSVRC2012_val_00017426.bin 224 224 +40902 ./prep_dataset/ILSVRC2012_val_00019671.bin 224 224 +40903 ./prep_dataset/ILSVRC2012_val_00003680.bin 224 224 +40904 ./prep_dataset/ILSVRC2012_val_00044317.bin 224 224 +40905 ./prep_dataset/ILSVRC2012_val_00041697.bin 224 224 +40906 ./prep_dataset/ILSVRC2012_val_00042427.bin 224 224 +40907 ./prep_dataset/ILSVRC2012_val_00032436.bin 224 224 +40908 ./prep_dataset/ILSVRC2012_val_00005549.bin 224 224 +40909 ./prep_dataset/ILSVRC2012_val_00007477.bin 224 224 +40910 ./prep_dataset/ILSVRC2012_val_00017775.bin 224 224 +40911 ./prep_dataset/ILSVRC2012_val_00046852.bin 224 224 +40912 ./prep_dataset/ILSVRC2012_val_00003922.bin 224 224 +40913 ./prep_dataset/ILSVRC2012_val_00037291.bin 224 224 +40914 ./prep_dataset/ILSVRC2012_val_00022515.bin 224 224 +40915 ./prep_dataset/ILSVRC2012_val_00043688.bin 224 224 +40916 ./prep_dataset/ILSVRC2012_val_00005167.bin 224 224 +40917 ./prep_dataset/ILSVRC2012_val_00036060.bin 224 224 +40918 ./prep_dataset/ILSVRC2012_val_00044907.bin 224 224 +40919 ./prep_dataset/ILSVRC2012_val_00029316.bin 224 224 +40920 ./prep_dataset/ILSVRC2012_val_00047187.bin 224 224 +40921 ./prep_dataset/ILSVRC2012_val_00028504.bin 224 224 +40922 ./prep_dataset/ILSVRC2012_val_00032098.bin 224 224 +40923 ./prep_dataset/ILSVRC2012_val_00024201.bin 224 224 +40924 ./prep_dataset/ILSVRC2012_val_00027165.bin 224 224 +40925 ./prep_dataset/ILSVRC2012_val_00039220.bin 224 224 +40926 ./prep_dataset/ILSVRC2012_val_00001245.bin 224 224 +40927 ./prep_dataset/ILSVRC2012_val_00003509.bin 224 224 +40928 ./prep_dataset/ILSVRC2012_val_00047030.bin 224 224 +40929 ./prep_dataset/ILSVRC2012_val_00016204.bin 224 224 +40930 ./prep_dataset/ILSVRC2012_val_00018524.bin 224 224 +40931 ./prep_dataset/ILSVRC2012_val_00045708.bin 224 224 +40932 ./prep_dataset/ILSVRC2012_val_00003492.bin 224 224 +40933 ./prep_dataset/ILSVRC2012_val_00027924.bin 224 224 +40934 ./prep_dataset/ILSVRC2012_val_00012633.bin 224 224 +40935 ./prep_dataset/ILSVRC2012_val_00018252.bin 224 224 +40936 ./prep_dataset/ILSVRC2012_val_00037845.bin 224 224 +40937 ./prep_dataset/ILSVRC2012_val_00008621.bin 224 224 +40938 ./prep_dataset/ILSVRC2012_val_00014033.bin 224 224 +40939 ./prep_dataset/ILSVRC2012_val_00006899.bin 224 224 +40940 ./prep_dataset/ILSVRC2012_val_00044753.bin 224 224 +40941 ./prep_dataset/ILSVRC2012_val_00028134.bin 224 224 +40942 ./prep_dataset/ILSVRC2012_val_00027869.bin 224 224 +40943 ./prep_dataset/ILSVRC2012_val_00047148.bin 224 224 +40944 ./prep_dataset/ILSVRC2012_val_00021651.bin 224 224 +40945 ./prep_dataset/ILSVRC2012_val_00018521.bin 224 224 +40946 ./prep_dataset/ILSVRC2012_val_00001008.bin 224 224 +40947 ./prep_dataset/ILSVRC2012_val_00023054.bin 224 224 +40948 ./prep_dataset/ILSVRC2012_val_00009505.bin 224 224 +40949 ./prep_dataset/ILSVRC2012_val_00015598.bin 224 224 +40950 ./prep_dataset/ILSVRC2012_val_00035523.bin 224 224 +40951 ./prep_dataset/ILSVRC2012_val_00028404.bin 224 224 +40952 ./prep_dataset/ILSVRC2012_val_00033296.bin 224 224 +40953 ./prep_dataset/ILSVRC2012_val_00004055.bin 224 224 +40954 ./prep_dataset/ILSVRC2012_val_00015274.bin 224 224 +40955 ./prep_dataset/ILSVRC2012_val_00047639.bin 224 224 +40956 ./prep_dataset/ILSVRC2012_val_00014748.bin 224 224 +40957 ./prep_dataset/ILSVRC2012_val_00045586.bin 224 224 +40958 ./prep_dataset/ILSVRC2012_val_00014513.bin 224 224 +40959 ./prep_dataset/ILSVRC2012_val_00034570.bin 224 224 +40960 ./prep_dataset/ILSVRC2012_val_00036539.bin 224 224 +40961 ./prep_dataset/ILSVRC2012_val_00014688.bin 224 224 +40962 ./prep_dataset/ILSVRC2012_val_00037460.bin 224 224 +40963 ./prep_dataset/ILSVRC2012_val_00041922.bin 224 224 +40964 ./prep_dataset/ILSVRC2012_val_00019372.bin 224 224 +40965 ./prep_dataset/ILSVRC2012_val_00021558.bin 224 224 +40966 ./prep_dataset/ILSVRC2012_val_00028665.bin 224 224 +40967 ./prep_dataset/ILSVRC2012_val_00015652.bin 224 224 +40968 ./prep_dataset/ILSVRC2012_val_00013082.bin 224 224 +40969 ./prep_dataset/ILSVRC2012_val_00042282.bin 224 224 +40970 ./prep_dataset/ILSVRC2012_val_00037279.bin 224 224 +40971 ./prep_dataset/ILSVRC2012_val_00039959.bin 224 224 +40972 ./prep_dataset/ILSVRC2012_val_00037103.bin 224 224 +40973 ./prep_dataset/ILSVRC2012_val_00012576.bin 224 224 +40974 ./prep_dataset/ILSVRC2012_val_00020773.bin 224 224 +40975 ./prep_dataset/ILSVRC2012_val_00019031.bin 224 224 +40976 ./prep_dataset/ILSVRC2012_val_00005174.bin 224 224 +40977 ./prep_dataset/ILSVRC2012_val_00012703.bin 224 224 +40978 ./prep_dataset/ILSVRC2012_val_00044932.bin 224 224 +40979 ./prep_dataset/ILSVRC2012_val_00048120.bin 224 224 +40980 ./prep_dataset/ILSVRC2012_val_00035588.bin 224 224 +40981 ./prep_dataset/ILSVRC2012_val_00010449.bin 224 224 +40982 ./prep_dataset/ILSVRC2012_val_00018733.bin 224 224 +40983 ./prep_dataset/ILSVRC2012_val_00017985.bin 224 224 +40984 ./prep_dataset/ILSVRC2012_val_00007967.bin 224 224 +40985 ./prep_dataset/ILSVRC2012_val_00042084.bin 224 224 +40986 ./prep_dataset/ILSVRC2012_val_00024208.bin 224 224 +40987 ./prep_dataset/ILSVRC2012_val_00016845.bin 224 224 +40988 ./prep_dataset/ILSVRC2012_val_00046938.bin 224 224 +40989 ./prep_dataset/ILSVRC2012_val_00029194.bin 224 224 +40990 ./prep_dataset/ILSVRC2012_val_00023956.bin 224 224 +40991 ./prep_dataset/ILSVRC2012_val_00018031.bin 224 224 +40992 ./prep_dataset/ILSVRC2012_val_00047971.bin 224 224 +40993 ./prep_dataset/ILSVRC2012_val_00021645.bin 224 224 +40994 ./prep_dataset/ILSVRC2012_val_00013585.bin 224 224 +40995 ./prep_dataset/ILSVRC2012_val_00013882.bin 224 224 +40996 ./prep_dataset/ILSVRC2012_val_00035938.bin 224 224 +40997 ./prep_dataset/ILSVRC2012_val_00049613.bin 224 224 +40998 ./prep_dataset/ILSVRC2012_val_00049588.bin 224 224 +40999 ./prep_dataset/ILSVRC2012_val_00031237.bin 224 224 +41000 ./prep_dataset/ILSVRC2012_val_00049940.bin 224 224 +41001 ./prep_dataset/ILSVRC2012_val_00016825.bin 224 224 +41002 ./prep_dataset/ILSVRC2012_val_00045289.bin 224 224 +41003 ./prep_dataset/ILSVRC2012_val_00045727.bin 224 224 +41004 ./prep_dataset/ILSVRC2012_val_00001882.bin 224 224 +41005 ./prep_dataset/ILSVRC2012_val_00022806.bin 224 224 +41006 ./prep_dataset/ILSVRC2012_val_00043074.bin 224 224 +41007 ./prep_dataset/ILSVRC2012_val_00043675.bin 224 224 +41008 ./prep_dataset/ILSVRC2012_val_00031098.bin 224 224 +41009 ./prep_dataset/ILSVRC2012_val_00001064.bin 224 224 +41010 ./prep_dataset/ILSVRC2012_val_00017747.bin 224 224 +41011 ./prep_dataset/ILSVRC2012_val_00020212.bin 224 224 +41012 ./prep_dataset/ILSVRC2012_val_00014071.bin 224 224 +41013 ./prep_dataset/ILSVRC2012_val_00034430.bin 224 224 +41014 ./prep_dataset/ILSVRC2012_val_00017751.bin 224 224 +41015 ./prep_dataset/ILSVRC2012_val_00025019.bin 224 224 +41016 ./prep_dataset/ILSVRC2012_val_00029166.bin 224 224 +41017 ./prep_dataset/ILSVRC2012_val_00046423.bin 224 224 +41018 ./prep_dataset/ILSVRC2012_val_00040024.bin 224 224 +41019 ./prep_dataset/ILSVRC2012_val_00006699.bin 224 224 +41020 ./prep_dataset/ILSVRC2012_val_00002039.bin 224 224 +41021 ./prep_dataset/ILSVRC2012_val_00040387.bin 224 224 +41022 ./prep_dataset/ILSVRC2012_val_00042203.bin 224 224 +41023 ./prep_dataset/ILSVRC2012_val_00000386.bin 224 224 +41024 ./prep_dataset/ILSVRC2012_val_00047168.bin 224 224 +41025 ./prep_dataset/ILSVRC2012_val_00010243.bin 224 224 +41026 ./prep_dataset/ILSVRC2012_val_00049780.bin 224 224 +41027 ./prep_dataset/ILSVRC2012_val_00008067.bin 224 224 +41028 ./prep_dataset/ILSVRC2012_val_00012974.bin 224 224 +41029 ./prep_dataset/ILSVRC2012_val_00009247.bin 224 224 +41030 ./prep_dataset/ILSVRC2012_val_00039032.bin 224 224 +41031 ./prep_dataset/ILSVRC2012_val_00015385.bin 224 224 +41032 ./prep_dataset/ILSVRC2012_val_00021085.bin 224 224 +41033 ./prep_dataset/ILSVRC2012_val_00015991.bin 224 224 +41034 ./prep_dataset/ILSVRC2012_val_00029937.bin 224 224 +41035 ./prep_dataset/ILSVRC2012_val_00035826.bin 224 224 +41036 ./prep_dataset/ILSVRC2012_val_00028368.bin 224 224 +41037 ./prep_dataset/ILSVRC2012_val_00016635.bin 224 224 +41038 ./prep_dataset/ILSVRC2012_val_00034917.bin 224 224 +41039 ./prep_dataset/ILSVRC2012_val_00021361.bin 224 224 +41040 ./prep_dataset/ILSVRC2012_val_00016122.bin 224 224 +41041 ./prep_dataset/ILSVRC2012_val_00035415.bin 224 224 +41042 ./prep_dataset/ILSVRC2012_val_00001230.bin 224 224 +41043 ./prep_dataset/ILSVRC2012_val_00007686.bin 224 224 +41044 ./prep_dataset/ILSVRC2012_val_00007473.bin 224 224 +41045 ./prep_dataset/ILSVRC2012_val_00044143.bin 224 224 +41046 ./prep_dataset/ILSVRC2012_val_00033726.bin 224 224 +41047 ./prep_dataset/ILSVRC2012_val_00044033.bin 224 224 +41048 ./prep_dataset/ILSVRC2012_val_00003574.bin 224 224 +41049 ./prep_dataset/ILSVRC2012_val_00032219.bin 224 224 +41050 ./prep_dataset/ILSVRC2012_val_00004855.bin 224 224 +41051 ./prep_dataset/ILSVRC2012_val_00030546.bin 224 224 +41052 ./prep_dataset/ILSVRC2012_val_00017264.bin 224 224 +41053 ./prep_dataset/ILSVRC2012_val_00027550.bin 224 224 +41054 ./prep_dataset/ILSVRC2012_val_00016520.bin 224 224 +41055 ./prep_dataset/ILSVRC2012_val_00043898.bin 224 224 +41056 ./prep_dataset/ILSVRC2012_val_00045584.bin 224 224 +41057 ./prep_dataset/ILSVRC2012_val_00003645.bin 224 224 +41058 ./prep_dataset/ILSVRC2012_val_00020628.bin 224 224 +41059 ./prep_dataset/ILSVRC2012_val_00014893.bin 224 224 +41060 ./prep_dataset/ILSVRC2012_val_00014295.bin 224 224 +41061 ./prep_dataset/ILSVRC2012_val_00017956.bin 224 224 +41062 ./prep_dataset/ILSVRC2012_val_00006102.bin 224 224 +41063 ./prep_dataset/ILSVRC2012_val_00014260.bin 224 224 +41064 ./prep_dataset/ILSVRC2012_val_00020172.bin 224 224 +41065 ./prep_dataset/ILSVRC2012_val_00001733.bin 224 224 +41066 ./prep_dataset/ILSVRC2012_val_00034454.bin 224 224 +41067 ./prep_dataset/ILSVRC2012_val_00003568.bin 224 224 +41068 ./prep_dataset/ILSVRC2012_val_00033814.bin 224 224 +41069 ./prep_dataset/ILSVRC2012_val_00013795.bin 224 224 +41070 ./prep_dataset/ILSVRC2012_val_00025370.bin 224 224 +41071 ./prep_dataset/ILSVRC2012_val_00046903.bin 224 224 +41072 ./prep_dataset/ILSVRC2012_val_00044875.bin 224 224 +41073 ./prep_dataset/ILSVRC2012_val_00047169.bin 224 224 +41074 ./prep_dataset/ILSVRC2012_val_00041837.bin 224 224 +41075 ./prep_dataset/ILSVRC2012_val_00031334.bin 224 224 +41076 ./prep_dataset/ILSVRC2012_val_00027790.bin 224 224 +41077 ./prep_dataset/ILSVRC2012_val_00014627.bin 224 224 +41078 ./prep_dataset/ILSVRC2012_val_00017129.bin 224 224 +41079 ./prep_dataset/ILSVRC2012_val_00026490.bin 224 224 +41080 ./prep_dataset/ILSVRC2012_val_00009895.bin 224 224 +41081 ./prep_dataset/ILSVRC2012_val_00026188.bin 224 224 +41082 ./prep_dataset/ILSVRC2012_val_00019293.bin 224 224 +41083 ./prep_dataset/ILSVRC2012_val_00027343.bin 224 224 +41084 ./prep_dataset/ILSVRC2012_val_00046248.bin 224 224 +41085 ./prep_dataset/ILSVRC2012_val_00023366.bin 224 224 +41086 ./prep_dataset/ILSVRC2012_val_00019938.bin 224 224 +41087 ./prep_dataset/ILSVRC2012_val_00014938.bin 224 224 +41088 ./prep_dataset/ILSVRC2012_val_00044261.bin 224 224 +41089 ./prep_dataset/ILSVRC2012_val_00014578.bin 224 224 +41090 ./prep_dataset/ILSVRC2012_val_00026540.bin 224 224 +41091 ./prep_dataset/ILSVRC2012_val_00016479.bin 224 224 +41092 ./prep_dataset/ILSVRC2012_val_00022935.bin 224 224 +41093 ./prep_dataset/ILSVRC2012_val_00030216.bin 224 224 +41094 ./prep_dataset/ILSVRC2012_val_00002113.bin 224 224 +41095 ./prep_dataset/ILSVRC2012_val_00039488.bin 224 224 +41096 ./prep_dataset/ILSVRC2012_val_00037246.bin 224 224 +41097 ./prep_dataset/ILSVRC2012_val_00011030.bin 224 224 +41098 ./prep_dataset/ILSVRC2012_val_00006885.bin 224 224 +41099 ./prep_dataset/ILSVRC2012_val_00033232.bin 224 224 +41100 ./prep_dataset/ILSVRC2012_val_00017317.bin 224 224 +41101 ./prep_dataset/ILSVRC2012_val_00044555.bin 224 224 +41102 ./prep_dataset/ILSVRC2012_val_00035332.bin 224 224 +41103 ./prep_dataset/ILSVRC2012_val_00025162.bin 224 224 +41104 ./prep_dataset/ILSVRC2012_val_00004635.bin 224 224 +41105 ./prep_dataset/ILSVRC2012_val_00012933.bin 224 224 +41106 ./prep_dataset/ILSVRC2012_val_00021820.bin 224 224 +41107 ./prep_dataset/ILSVRC2012_val_00049357.bin 224 224 +41108 ./prep_dataset/ILSVRC2012_val_00011364.bin 224 224 +41109 ./prep_dataset/ILSVRC2012_val_00038923.bin 224 224 +41110 ./prep_dataset/ILSVRC2012_val_00013147.bin 224 224 +41111 ./prep_dataset/ILSVRC2012_val_00017449.bin 224 224 +41112 ./prep_dataset/ILSVRC2012_val_00012393.bin 224 224 +41113 ./prep_dataset/ILSVRC2012_val_00029628.bin 224 224 +41114 ./prep_dataset/ILSVRC2012_val_00002248.bin 224 224 +41115 ./prep_dataset/ILSVRC2012_val_00000983.bin 224 224 +41116 ./prep_dataset/ILSVRC2012_val_00003185.bin 224 224 +41117 ./prep_dataset/ILSVRC2012_val_00045114.bin 224 224 +41118 ./prep_dataset/ILSVRC2012_val_00019420.bin 224 224 +41119 ./prep_dataset/ILSVRC2012_val_00012345.bin 224 224 +41120 ./prep_dataset/ILSVRC2012_val_00005096.bin 224 224 +41121 ./prep_dataset/ILSVRC2012_val_00048143.bin 224 224 +41122 ./prep_dataset/ILSVRC2012_val_00035402.bin 224 224 +41123 ./prep_dataset/ILSVRC2012_val_00038801.bin 224 224 +41124 ./prep_dataset/ILSVRC2012_val_00003910.bin 224 224 +41125 ./prep_dataset/ILSVRC2012_val_00008425.bin 224 224 +41126 ./prep_dataset/ILSVRC2012_val_00003186.bin 224 224 +41127 ./prep_dataset/ILSVRC2012_val_00008429.bin 224 224 +41128 ./prep_dataset/ILSVRC2012_val_00032286.bin 224 224 +41129 ./prep_dataset/ILSVRC2012_val_00040677.bin 224 224 +41130 ./prep_dataset/ILSVRC2012_val_00035868.bin 224 224 +41131 ./prep_dataset/ILSVRC2012_val_00027259.bin 224 224 +41132 ./prep_dataset/ILSVRC2012_val_00012508.bin 224 224 +41133 ./prep_dataset/ILSVRC2012_val_00042565.bin 224 224 +41134 ./prep_dataset/ILSVRC2012_val_00010520.bin 224 224 +41135 ./prep_dataset/ILSVRC2012_val_00014271.bin 224 224 +41136 ./prep_dataset/ILSVRC2012_val_00002933.bin 224 224 +41137 ./prep_dataset/ILSVRC2012_val_00001856.bin 224 224 +41138 ./prep_dataset/ILSVRC2012_val_00047070.bin 224 224 +41139 ./prep_dataset/ILSVRC2012_val_00030925.bin 224 224 +41140 ./prep_dataset/ILSVRC2012_val_00006532.bin 224 224 +41141 ./prep_dataset/ILSVRC2012_val_00014130.bin 224 224 +41142 ./prep_dataset/ILSVRC2012_val_00023337.bin 224 224 +41143 ./prep_dataset/ILSVRC2012_val_00047580.bin 224 224 +41144 ./prep_dataset/ILSVRC2012_val_00003105.bin 224 224 +41145 ./prep_dataset/ILSVRC2012_val_00022494.bin 224 224 +41146 ./prep_dataset/ILSVRC2012_val_00000917.bin 224 224 +41147 ./prep_dataset/ILSVRC2012_val_00004468.bin 224 224 +41148 ./prep_dataset/ILSVRC2012_val_00044092.bin 224 224 +41149 ./prep_dataset/ILSVRC2012_val_00041750.bin 224 224 +41150 ./prep_dataset/ILSVRC2012_val_00045913.bin 224 224 +41151 ./prep_dataset/ILSVRC2012_val_00013645.bin 224 224 +41152 ./prep_dataset/ILSVRC2012_val_00030321.bin 224 224 +41153 ./prep_dataset/ILSVRC2012_val_00035047.bin 224 224 +41154 ./prep_dataset/ILSVRC2012_val_00040825.bin 224 224 +41155 ./prep_dataset/ILSVRC2012_val_00046202.bin 224 224 +41156 ./prep_dataset/ILSVRC2012_val_00029690.bin 224 224 +41157 ./prep_dataset/ILSVRC2012_val_00010631.bin 224 224 +41158 ./prep_dataset/ILSVRC2012_val_00005210.bin 224 224 +41159 ./prep_dataset/ILSVRC2012_val_00015802.bin 224 224 +41160 ./prep_dataset/ILSVRC2012_val_00044881.bin 224 224 +41161 ./prep_dataset/ILSVRC2012_val_00028986.bin 224 224 +41162 ./prep_dataset/ILSVRC2012_val_00011285.bin 224 224 +41163 ./prep_dataset/ILSVRC2012_val_00032470.bin 224 224 +41164 ./prep_dataset/ILSVRC2012_val_00014604.bin 224 224 +41165 ./prep_dataset/ILSVRC2012_val_00005596.bin 224 224 +41166 ./prep_dataset/ILSVRC2012_val_00040803.bin 224 224 +41167 ./prep_dataset/ILSVRC2012_val_00026811.bin 224 224 +41168 ./prep_dataset/ILSVRC2012_val_00015356.bin 224 224 +41169 ./prep_dataset/ILSVRC2012_val_00010390.bin 224 224 +41170 ./prep_dataset/ILSVRC2012_val_00010705.bin 224 224 +41171 ./prep_dataset/ILSVRC2012_val_00008786.bin 224 224 +41172 ./prep_dataset/ILSVRC2012_val_00047513.bin 224 224 +41173 ./prep_dataset/ILSVRC2012_val_00029675.bin 224 224 +41174 ./prep_dataset/ILSVRC2012_val_00014671.bin 224 224 +41175 ./prep_dataset/ILSVRC2012_val_00017942.bin 224 224 +41176 ./prep_dataset/ILSVRC2012_val_00049025.bin 224 224 +41177 ./prep_dataset/ILSVRC2012_val_00022840.bin 224 224 +41178 ./prep_dataset/ILSVRC2012_val_00019043.bin 224 224 +41179 ./prep_dataset/ILSVRC2012_val_00048133.bin 224 224 +41180 ./prep_dataset/ILSVRC2012_val_00003871.bin 224 224 +41181 ./prep_dataset/ILSVRC2012_val_00007516.bin 224 224 +41182 ./prep_dataset/ILSVRC2012_val_00032653.bin 224 224 +41183 ./prep_dataset/ILSVRC2012_val_00029754.bin 224 224 +41184 ./prep_dataset/ILSVRC2012_val_00025311.bin 224 224 +41185 ./prep_dataset/ILSVRC2012_val_00026265.bin 224 224 +41186 ./prep_dataset/ILSVRC2012_val_00041813.bin 224 224 +41187 ./prep_dataset/ILSVRC2012_val_00022555.bin 224 224 +41188 ./prep_dataset/ILSVRC2012_val_00049379.bin 224 224 +41189 ./prep_dataset/ILSVRC2012_val_00021883.bin 224 224 +41190 ./prep_dataset/ILSVRC2012_val_00049929.bin 224 224 +41191 ./prep_dataset/ILSVRC2012_val_00045637.bin 224 224 +41192 ./prep_dataset/ILSVRC2012_val_00043002.bin 224 224 +41193 ./prep_dataset/ILSVRC2012_val_00007526.bin 224 224 +41194 ./prep_dataset/ILSVRC2012_val_00049773.bin 224 224 +41195 ./prep_dataset/ILSVRC2012_val_00006026.bin 224 224 +41196 ./prep_dataset/ILSVRC2012_val_00044608.bin 224 224 +41197 ./prep_dataset/ILSVRC2012_val_00024670.bin 224 224 +41198 ./prep_dataset/ILSVRC2012_val_00004582.bin 224 224 +41199 ./prep_dataset/ILSVRC2012_val_00020640.bin 224 224 +41200 ./prep_dataset/ILSVRC2012_val_00040442.bin 224 224 +41201 ./prep_dataset/ILSVRC2012_val_00029048.bin 224 224 +41202 ./prep_dataset/ILSVRC2012_val_00021510.bin 224 224 +41203 ./prep_dataset/ILSVRC2012_val_00041284.bin 224 224 +41204 ./prep_dataset/ILSVRC2012_val_00029815.bin 224 224 +41205 ./prep_dataset/ILSVRC2012_val_00015779.bin 224 224 +41206 ./prep_dataset/ILSVRC2012_val_00011066.bin 224 224 +41207 ./prep_dataset/ILSVRC2012_val_00027810.bin 224 224 +41208 ./prep_dataset/ILSVRC2012_val_00045174.bin 224 224 +41209 ./prep_dataset/ILSVRC2012_val_00049303.bin 224 224 +41210 ./prep_dataset/ILSVRC2012_val_00035031.bin 224 224 +41211 ./prep_dataset/ILSVRC2012_val_00032479.bin 224 224 +41212 ./prep_dataset/ILSVRC2012_val_00015382.bin 224 224 +41213 ./prep_dataset/ILSVRC2012_val_00026035.bin 224 224 +41214 ./prep_dataset/ILSVRC2012_val_00013901.bin 224 224 +41215 ./prep_dataset/ILSVRC2012_val_00020847.bin 224 224 +41216 ./prep_dataset/ILSVRC2012_val_00048531.bin 224 224 +41217 ./prep_dataset/ILSVRC2012_val_00026921.bin 224 224 +41218 ./prep_dataset/ILSVRC2012_val_00037049.bin 224 224 +41219 ./prep_dataset/ILSVRC2012_val_00012863.bin 224 224 +41220 ./prep_dataset/ILSVRC2012_val_00012386.bin 224 224 +41221 ./prep_dataset/ILSVRC2012_val_00048073.bin 224 224 +41222 ./prep_dataset/ILSVRC2012_val_00023335.bin 224 224 +41223 ./prep_dataset/ILSVRC2012_val_00029779.bin 224 224 +41224 ./prep_dataset/ILSVRC2012_val_00031873.bin 224 224 +41225 ./prep_dataset/ILSVRC2012_val_00032889.bin 224 224 +41226 ./prep_dataset/ILSVRC2012_val_00009823.bin 224 224 +41227 ./prep_dataset/ILSVRC2012_val_00019913.bin 224 224 +41228 ./prep_dataset/ILSVRC2012_val_00009367.bin 224 224 +41229 ./prep_dataset/ILSVRC2012_val_00012420.bin 224 224 +41230 ./prep_dataset/ILSVRC2012_val_00016786.bin 224 224 +41231 ./prep_dataset/ILSVRC2012_val_00021476.bin 224 224 +41232 ./prep_dataset/ILSVRC2012_val_00007637.bin 224 224 +41233 ./prep_dataset/ILSVRC2012_val_00027992.bin 224 224 +41234 ./prep_dataset/ILSVRC2012_val_00014186.bin 224 224 +41235 ./prep_dataset/ILSVRC2012_val_00015534.bin 224 224 +41236 ./prep_dataset/ILSVRC2012_val_00028035.bin 224 224 +41237 ./prep_dataset/ILSVRC2012_val_00010839.bin 224 224 +41238 ./prep_dataset/ILSVRC2012_val_00044889.bin 224 224 +41239 ./prep_dataset/ILSVRC2012_val_00028108.bin 224 224 +41240 ./prep_dataset/ILSVRC2012_val_00036245.bin 224 224 +41241 ./prep_dataset/ILSVRC2012_val_00007638.bin 224 224 +41242 ./prep_dataset/ILSVRC2012_val_00016071.bin 224 224 +41243 ./prep_dataset/ILSVRC2012_val_00040663.bin 224 224 +41244 ./prep_dataset/ILSVRC2012_val_00020929.bin 224 224 +41245 ./prep_dataset/ILSVRC2012_val_00034217.bin 224 224 +41246 ./prep_dataset/ILSVRC2012_val_00048290.bin 224 224 +41247 ./prep_dataset/ILSVRC2012_val_00008264.bin 224 224 +41248 ./prep_dataset/ILSVRC2012_val_00044540.bin 224 224 +41249 ./prep_dataset/ILSVRC2012_val_00005008.bin 224 224 +41250 ./prep_dataset/ILSVRC2012_val_00018928.bin 224 224 +41251 ./prep_dataset/ILSVRC2012_val_00013570.bin 224 224 +41252 ./prep_dataset/ILSVRC2012_val_00018068.bin 224 224 +41253 ./prep_dataset/ILSVRC2012_val_00009632.bin 224 224 +41254 ./prep_dataset/ILSVRC2012_val_00042332.bin 224 224 +41255 ./prep_dataset/ILSVRC2012_val_00032316.bin 224 224 +41256 ./prep_dataset/ILSVRC2012_val_00007814.bin 224 224 +41257 ./prep_dataset/ILSVRC2012_val_00044628.bin 224 224 +41258 ./prep_dataset/ILSVRC2012_val_00047400.bin 224 224 +41259 ./prep_dataset/ILSVRC2012_val_00046597.bin 224 224 +41260 ./prep_dataset/ILSVRC2012_val_00021709.bin 224 224 +41261 ./prep_dataset/ILSVRC2012_val_00042525.bin 224 224 +41262 ./prep_dataset/ILSVRC2012_val_00041430.bin 224 224 +41263 ./prep_dataset/ILSVRC2012_val_00043958.bin 224 224 +41264 ./prep_dataset/ILSVRC2012_val_00043849.bin 224 224 +41265 ./prep_dataset/ILSVRC2012_val_00003961.bin 224 224 +41266 ./prep_dataset/ILSVRC2012_val_00028615.bin 224 224 +41267 ./prep_dataset/ILSVRC2012_val_00000250.bin 224 224 +41268 ./prep_dataset/ILSVRC2012_val_00031965.bin 224 224 +41269 ./prep_dataset/ILSVRC2012_val_00003247.bin 224 224 +41270 ./prep_dataset/ILSVRC2012_val_00042294.bin 224 224 +41271 ./prep_dataset/ILSVRC2012_val_00012777.bin 224 224 +41272 ./prep_dataset/ILSVRC2012_val_00005307.bin 224 224 +41273 ./prep_dataset/ILSVRC2012_val_00024741.bin 224 224 +41274 ./prep_dataset/ILSVRC2012_val_00033378.bin 224 224 +41275 ./prep_dataset/ILSVRC2012_val_00008588.bin 224 224 +41276 ./prep_dataset/ILSVRC2012_val_00034775.bin 224 224 +41277 ./prep_dataset/ILSVRC2012_val_00016202.bin 224 224 +41278 ./prep_dataset/ILSVRC2012_val_00030697.bin 224 224 +41279 ./prep_dataset/ILSVRC2012_val_00012268.bin 224 224 +41280 ./prep_dataset/ILSVRC2012_val_00041287.bin 224 224 +41281 ./prep_dataset/ILSVRC2012_val_00009991.bin 224 224 +41282 ./prep_dataset/ILSVRC2012_val_00009243.bin 224 224 +41283 ./prep_dataset/ILSVRC2012_val_00012217.bin 224 224 +41284 ./prep_dataset/ILSVRC2012_val_00036388.bin 224 224 +41285 ./prep_dataset/ILSVRC2012_val_00006127.bin 224 224 +41286 ./prep_dataset/ILSVRC2012_val_00000043.bin 224 224 +41287 ./prep_dataset/ILSVRC2012_val_00016609.bin 224 224 +41288 ./prep_dataset/ILSVRC2012_val_00013632.bin 224 224 +41289 ./prep_dataset/ILSVRC2012_val_00023798.bin 224 224 +41290 ./prep_dataset/ILSVRC2012_val_00002393.bin 224 224 +41291 ./prep_dataset/ILSVRC2012_val_00037885.bin 224 224 +41292 ./prep_dataset/ILSVRC2012_val_00028510.bin 224 224 +41293 ./prep_dataset/ILSVRC2012_val_00042490.bin 224 224 +41294 ./prep_dataset/ILSVRC2012_val_00022811.bin 224 224 +41295 ./prep_dataset/ILSVRC2012_val_00046525.bin 224 224 +41296 ./prep_dataset/ILSVRC2012_val_00012116.bin 224 224 +41297 ./prep_dataset/ILSVRC2012_val_00013193.bin 224 224 +41298 ./prep_dataset/ILSVRC2012_val_00023818.bin 224 224 +41299 ./prep_dataset/ILSVRC2012_val_00005956.bin 224 224 +41300 ./prep_dataset/ILSVRC2012_val_00018403.bin 224 224 +41301 ./prep_dataset/ILSVRC2012_val_00011069.bin 224 224 +41302 ./prep_dataset/ILSVRC2012_val_00004828.bin 224 224 +41303 ./prep_dataset/ILSVRC2012_val_00020636.bin 224 224 +41304 ./prep_dataset/ILSVRC2012_val_00028076.bin 224 224 +41305 ./prep_dataset/ILSVRC2012_val_00008427.bin 224 224 +41306 ./prep_dataset/ILSVRC2012_val_00001256.bin 224 224 +41307 ./prep_dataset/ILSVRC2012_val_00031023.bin 224 224 +41308 ./prep_dataset/ILSVRC2012_val_00026159.bin 224 224 +41309 ./prep_dataset/ILSVRC2012_val_00013798.bin 224 224 +41310 ./prep_dataset/ILSVRC2012_val_00020819.bin 224 224 +41311 ./prep_dataset/ILSVRC2012_val_00019260.bin 224 224 +41312 ./prep_dataset/ILSVRC2012_val_00017439.bin 224 224 +41313 ./prep_dataset/ILSVRC2012_val_00005286.bin 224 224 +41314 ./prep_dataset/ILSVRC2012_val_00041343.bin 224 224 +41315 ./prep_dataset/ILSVRC2012_val_00043070.bin 224 224 +41316 ./prep_dataset/ILSVRC2012_val_00008700.bin 224 224 +41317 ./prep_dataset/ILSVRC2012_val_00042791.bin 224 224 +41318 ./prep_dataset/ILSVRC2012_val_00013436.bin 224 224 +41319 ./prep_dataset/ILSVRC2012_val_00017078.bin 224 224 +41320 ./prep_dataset/ILSVRC2012_val_00044464.bin 224 224 +41321 ./prep_dataset/ILSVRC2012_val_00007021.bin 224 224 +41322 ./prep_dataset/ILSVRC2012_val_00000022.bin 224 224 +41323 ./prep_dataset/ILSVRC2012_val_00040569.bin 224 224 +41324 ./prep_dataset/ILSVRC2012_val_00020647.bin 224 224 +41325 ./prep_dataset/ILSVRC2012_val_00027179.bin 224 224 +41326 ./prep_dataset/ILSVRC2012_val_00011094.bin 224 224 +41327 ./prep_dataset/ILSVRC2012_val_00017002.bin 224 224 +41328 ./prep_dataset/ILSVRC2012_val_00031930.bin 224 224 +41329 ./prep_dataset/ILSVRC2012_val_00042510.bin 224 224 +41330 ./prep_dataset/ILSVRC2012_val_00030242.bin 224 224 +41331 ./prep_dataset/ILSVRC2012_val_00022970.bin 224 224 +41332 ./prep_dataset/ILSVRC2012_val_00009313.bin 224 224 +41333 ./prep_dataset/ILSVRC2012_val_00032190.bin 224 224 +41334 ./prep_dataset/ILSVRC2012_val_00031959.bin 224 224 +41335 ./prep_dataset/ILSVRC2012_val_00017665.bin 224 224 +41336 ./prep_dataset/ILSVRC2012_val_00020530.bin 224 224 +41337 ./prep_dataset/ILSVRC2012_val_00007499.bin 224 224 +41338 ./prep_dataset/ILSVRC2012_val_00043748.bin 224 224 +41339 ./prep_dataset/ILSVRC2012_val_00034406.bin 224 224 +41340 ./prep_dataset/ILSVRC2012_val_00027193.bin 224 224 +41341 ./prep_dataset/ILSVRC2012_val_00022456.bin 224 224 +41342 ./prep_dataset/ILSVRC2012_val_00023043.bin 224 224 +41343 ./prep_dataset/ILSVRC2012_val_00035592.bin 224 224 +41344 ./prep_dataset/ILSVRC2012_val_00029552.bin 224 224 +41345 ./prep_dataset/ILSVRC2012_val_00001459.bin 224 224 +41346 ./prep_dataset/ILSVRC2012_val_00023320.bin 224 224 +41347 ./prep_dataset/ILSVRC2012_val_00036542.bin 224 224 +41348 ./prep_dataset/ILSVRC2012_val_00045283.bin 224 224 +41349 ./prep_dataset/ILSVRC2012_val_00027102.bin 224 224 +41350 ./prep_dataset/ILSVRC2012_val_00004699.bin 224 224 +41351 ./prep_dataset/ILSVRC2012_val_00008113.bin 224 224 +41352 ./prep_dataset/ILSVRC2012_val_00017915.bin 224 224 +41353 ./prep_dataset/ILSVRC2012_val_00005953.bin 224 224 +41354 ./prep_dataset/ILSVRC2012_val_00041254.bin 224 224 +41355 ./prep_dataset/ILSVRC2012_val_00022310.bin 224 224 +41356 ./prep_dataset/ILSVRC2012_val_00001172.bin 224 224 +41357 ./prep_dataset/ILSVRC2012_val_00005041.bin 224 224 +41358 ./prep_dataset/ILSVRC2012_val_00047828.bin 224 224 +41359 ./prep_dataset/ILSVRC2012_val_00011301.bin 224 224 +41360 ./prep_dataset/ILSVRC2012_val_00007156.bin 224 224 +41361 ./prep_dataset/ILSVRC2012_val_00028411.bin 224 224 +41362 ./prep_dataset/ILSVRC2012_val_00004156.bin 224 224 +41363 ./prep_dataset/ILSVRC2012_val_00042424.bin 224 224 +41364 ./prep_dataset/ILSVRC2012_val_00014026.bin 224 224 +41365 ./prep_dataset/ILSVRC2012_val_00016221.bin 224 224 +41366 ./prep_dataset/ILSVRC2012_val_00039397.bin 224 224 +41367 ./prep_dataset/ILSVRC2012_val_00018895.bin 224 224 +41368 ./prep_dataset/ILSVRC2012_val_00010713.bin 224 224 +41369 ./prep_dataset/ILSVRC2012_val_00019126.bin 224 224 +41370 ./prep_dataset/ILSVRC2012_val_00038326.bin 224 224 +41371 ./prep_dataset/ILSVRC2012_val_00030106.bin 224 224 +41372 ./prep_dataset/ILSVRC2012_val_00037184.bin 224 224 +41373 ./prep_dataset/ILSVRC2012_val_00004708.bin 224 224 +41374 ./prep_dataset/ILSVRC2012_val_00042135.bin 224 224 +41375 ./prep_dataset/ILSVRC2012_val_00044195.bin 224 224 +41376 ./prep_dataset/ILSVRC2012_val_00030620.bin 224 224 +41377 ./prep_dataset/ILSVRC2012_val_00021258.bin 224 224 +41378 ./prep_dataset/ILSVRC2012_val_00026414.bin 224 224 +41379 ./prep_dataset/ILSVRC2012_val_00038506.bin 224 224 +41380 ./prep_dataset/ILSVRC2012_val_00038069.bin 224 224 +41381 ./prep_dataset/ILSVRC2012_val_00029066.bin 224 224 +41382 ./prep_dataset/ILSVRC2012_val_00001784.bin 224 224 +41383 ./prep_dataset/ILSVRC2012_val_00011578.bin 224 224 +41384 ./prep_dataset/ILSVRC2012_val_00001967.bin 224 224 +41385 ./prep_dataset/ILSVRC2012_val_00019112.bin 224 224 +41386 ./prep_dataset/ILSVRC2012_val_00014945.bin 224 224 +41387 ./prep_dataset/ILSVRC2012_val_00026110.bin 224 224 +41388 ./prep_dataset/ILSVRC2012_val_00012015.bin 224 224 +41389 ./prep_dataset/ILSVRC2012_val_00010043.bin 224 224 +41390 ./prep_dataset/ILSVRC2012_val_00013616.bin 224 224 +41391 ./prep_dataset/ILSVRC2012_val_00002874.bin 224 224 +41392 ./prep_dataset/ILSVRC2012_val_00046887.bin 224 224 +41393 ./prep_dataset/ILSVRC2012_val_00040498.bin 224 224 +41394 ./prep_dataset/ILSVRC2012_val_00013006.bin 224 224 +41395 ./prep_dataset/ILSVRC2012_val_00040174.bin 224 224 +41396 ./prep_dataset/ILSVRC2012_val_00024121.bin 224 224 +41397 ./prep_dataset/ILSVRC2012_val_00010930.bin 224 224 +41398 ./prep_dataset/ILSVRC2012_val_00016179.bin 224 224 +41399 ./prep_dataset/ILSVRC2012_val_00002984.bin 224 224 +41400 ./prep_dataset/ILSVRC2012_val_00029209.bin 224 224 +41401 ./prep_dataset/ILSVRC2012_val_00036260.bin 224 224 +41402 ./prep_dataset/ILSVRC2012_val_00017139.bin 224 224 +41403 ./prep_dataset/ILSVRC2012_val_00005545.bin 224 224 +41404 ./prep_dataset/ILSVRC2012_val_00006577.bin 224 224 +41405 ./prep_dataset/ILSVRC2012_val_00016338.bin 224 224 +41406 ./prep_dataset/ILSVRC2012_val_00005407.bin 224 224 +41407 ./prep_dataset/ILSVRC2012_val_00006847.bin 224 224 +41408 ./prep_dataset/ILSVRC2012_val_00004806.bin 224 224 +41409 ./prep_dataset/ILSVRC2012_val_00035578.bin 224 224 +41410 ./prep_dataset/ILSVRC2012_val_00006357.bin 224 224 +41411 ./prep_dataset/ILSVRC2012_val_00000767.bin 224 224 +41412 ./prep_dataset/ILSVRC2012_val_00008301.bin 224 224 +41413 ./prep_dataset/ILSVRC2012_val_00041825.bin 224 224 +41414 ./prep_dataset/ILSVRC2012_val_00029627.bin 224 224 +41415 ./prep_dataset/ILSVRC2012_val_00038042.bin 224 224 +41416 ./prep_dataset/ILSVRC2012_val_00011015.bin 224 224 +41417 ./prep_dataset/ILSVRC2012_val_00011899.bin 224 224 +41418 ./prep_dataset/ILSVRC2012_val_00043168.bin 224 224 +41419 ./prep_dataset/ILSVRC2012_val_00030972.bin 224 224 +41420 ./prep_dataset/ILSVRC2012_val_00015377.bin 224 224 +41421 ./prep_dataset/ILSVRC2012_val_00013486.bin 224 224 +41422 ./prep_dataset/ILSVRC2012_val_00045857.bin 224 224 +41423 ./prep_dataset/ILSVRC2012_val_00044131.bin 224 224 +41424 ./prep_dataset/ILSVRC2012_val_00016048.bin 224 224 +41425 ./prep_dataset/ILSVRC2012_val_00010097.bin 224 224 +41426 ./prep_dataset/ILSVRC2012_val_00027082.bin 224 224 +41427 ./prep_dataset/ILSVRC2012_val_00049522.bin 224 224 +41428 ./prep_dataset/ILSVRC2012_val_00006050.bin 224 224 +41429 ./prep_dataset/ILSVRC2012_val_00011893.bin 224 224 +41430 ./prep_dataset/ILSVRC2012_val_00026918.bin 224 224 +41431 ./prep_dataset/ILSVRC2012_val_00038779.bin 224 224 +41432 ./prep_dataset/ILSVRC2012_val_00040276.bin 224 224 +41433 ./prep_dataset/ILSVRC2012_val_00018272.bin 224 224 +41434 ./prep_dataset/ILSVRC2012_val_00028782.bin 224 224 +41435 ./prep_dataset/ILSVRC2012_val_00013406.bin 224 224 +41436 ./prep_dataset/ILSVRC2012_val_00042326.bin 224 224 +41437 ./prep_dataset/ILSVRC2012_val_00040484.bin 224 224 +41438 ./prep_dataset/ILSVRC2012_val_00005814.bin 224 224 +41439 ./prep_dataset/ILSVRC2012_val_00008934.bin 224 224 +41440 ./prep_dataset/ILSVRC2012_val_00011047.bin 224 224 +41441 ./prep_dataset/ILSVRC2012_val_00008060.bin 224 224 +41442 ./prep_dataset/ILSVRC2012_val_00018302.bin 224 224 +41443 ./prep_dataset/ILSVRC2012_val_00047157.bin 224 224 +41444 ./prep_dataset/ILSVRC2012_val_00040145.bin 224 224 +41445 ./prep_dataset/ILSVRC2012_val_00008742.bin 224 224 +41446 ./prep_dataset/ILSVRC2012_val_00017267.bin 224 224 +41447 ./prep_dataset/ILSVRC2012_val_00001187.bin 224 224 +41448 ./prep_dataset/ILSVRC2012_val_00007037.bin 224 224 +41449 ./prep_dataset/ILSVRC2012_val_00030592.bin 224 224 +41450 ./prep_dataset/ILSVRC2012_val_00023349.bin 224 224 +41451 ./prep_dataset/ILSVRC2012_val_00021708.bin 224 224 +41452 ./prep_dataset/ILSVRC2012_val_00031882.bin 224 224 +41453 ./prep_dataset/ILSVRC2012_val_00031172.bin 224 224 +41454 ./prep_dataset/ILSVRC2012_val_00004439.bin 224 224 +41455 ./prep_dataset/ILSVRC2012_val_00026288.bin 224 224 +41456 ./prep_dataset/ILSVRC2012_val_00048325.bin 224 224 +41457 ./prep_dataset/ILSVRC2012_val_00022425.bin 224 224 +41458 ./prep_dataset/ILSVRC2012_val_00030529.bin 224 224 +41459 ./prep_dataset/ILSVRC2012_val_00017440.bin 224 224 +41460 ./prep_dataset/ILSVRC2012_val_00028638.bin 224 224 +41461 ./prep_dataset/ILSVRC2012_val_00031782.bin 224 224 +41462 ./prep_dataset/ILSVRC2012_val_00049591.bin 224 224 +41463 ./prep_dataset/ILSVRC2012_val_00008520.bin 224 224 +41464 ./prep_dataset/ILSVRC2012_val_00034276.bin 224 224 +41465 ./prep_dataset/ILSVRC2012_val_00000076.bin 224 224 +41466 ./prep_dataset/ILSVRC2012_val_00004424.bin 224 224 +41467 ./prep_dataset/ILSVRC2012_val_00017355.bin 224 224 +41468 ./prep_dataset/ILSVRC2012_val_00045156.bin 224 224 +41469 ./prep_dataset/ILSVRC2012_val_00016728.bin 224 224 +41470 ./prep_dataset/ILSVRC2012_val_00018687.bin 224 224 +41471 ./prep_dataset/ILSVRC2012_val_00018316.bin 224 224 +41472 ./prep_dataset/ILSVRC2012_val_00049944.bin 224 224 +41473 ./prep_dataset/ILSVRC2012_val_00017155.bin 224 224 +41474 ./prep_dataset/ILSVRC2012_val_00030108.bin 224 224 +41475 ./prep_dataset/ILSVRC2012_val_00007560.bin 224 224 +41476 ./prep_dataset/ILSVRC2012_val_00042500.bin 224 224 +41477 ./prep_dataset/ILSVRC2012_val_00024817.bin 224 224 +41478 ./prep_dataset/ILSVRC2012_val_00004584.bin 224 224 +41479 ./prep_dataset/ILSVRC2012_val_00022288.bin 224 224 +41480 ./prep_dataset/ILSVRC2012_val_00042552.bin 224 224 +41481 ./prep_dataset/ILSVRC2012_val_00029165.bin 224 224 +41482 ./prep_dataset/ILSVRC2012_val_00048344.bin 224 224 +41483 ./prep_dataset/ILSVRC2012_val_00001016.bin 224 224 +41484 ./prep_dataset/ILSVRC2012_val_00035499.bin 224 224 +41485 ./prep_dataset/ILSVRC2012_val_00006377.bin 224 224 +41486 ./prep_dataset/ILSVRC2012_val_00045888.bin 224 224 +41487 ./prep_dataset/ILSVRC2012_val_00029004.bin 224 224 +41488 ./prep_dataset/ILSVRC2012_val_00046220.bin 224 224 +41489 ./prep_dataset/ILSVRC2012_val_00010300.bin 224 224 +41490 ./prep_dataset/ILSVRC2012_val_00024480.bin 224 224 +41491 ./prep_dataset/ILSVRC2012_val_00005593.bin 224 224 +41492 ./prep_dataset/ILSVRC2012_val_00043873.bin 224 224 +41493 ./prep_dataset/ILSVRC2012_val_00031485.bin 224 224 +41494 ./prep_dataset/ILSVRC2012_val_00022477.bin 224 224 +41495 ./prep_dataset/ILSVRC2012_val_00049728.bin 224 224 +41496 ./prep_dataset/ILSVRC2012_val_00028363.bin 224 224 +41497 ./prep_dataset/ILSVRC2012_val_00024818.bin 224 224 +41498 ./prep_dataset/ILSVRC2012_val_00029193.bin 224 224 +41499 ./prep_dataset/ILSVRC2012_val_00035579.bin 224 224 +41500 ./prep_dataset/ILSVRC2012_val_00010143.bin 224 224 +41501 ./prep_dataset/ILSVRC2012_val_00035720.bin 224 224 +41502 ./prep_dataset/ILSVRC2012_val_00024870.bin 224 224 +41503 ./prep_dataset/ILSVRC2012_val_00041422.bin 224 224 +41504 ./prep_dataset/ILSVRC2012_val_00044840.bin 224 224 +41505 ./prep_dataset/ILSVRC2012_val_00004643.bin 224 224 +41506 ./prep_dataset/ILSVRC2012_val_00045894.bin 224 224 +41507 ./prep_dataset/ILSVRC2012_val_00006787.bin 224 224 +41508 ./prep_dataset/ILSVRC2012_val_00015603.bin 224 224 +41509 ./prep_dataset/ILSVRC2012_val_00044550.bin 224 224 +41510 ./prep_dataset/ILSVRC2012_val_00030629.bin 224 224 +41511 ./prep_dataset/ILSVRC2012_val_00013966.bin 224 224 +41512 ./prep_dataset/ILSVRC2012_val_00017050.bin 224 224 +41513 ./prep_dataset/ILSVRC2012_val_00021351.bin 224 224 +41514 ./prep_dataset/ILSVRC2012_val_00029065.bin 224 224 +41515 ./prep_dataset/ILSVRC2012_val_00005198.bin 224 224 +41516 ./prep_dataset/ILSVRC2012_val_00017692.bin 224 224 +41517 ./prep_dataset/ILSVRC2012_val_00007101.bin 224 224 +41518 ./prep_dataset/ILSVRC2012_val_00040544.bin 224 224 +41519 ./prep_dataset/ILSVRC2012_val_00011694.bin 224 224 +41520 ./prep_dataset/ILSVRC2012_val_00023304.bin 224 224 +41521 ./prep_dataset/ILSVRC2012_val_00033099.bin 224 224 +41522 ./prep_dataset/ILSVRC2012_val_00001449.bin 224 224 +41523 ./prep_dataset/ILSVRC2012_val_00017173.bin 224 224 +41524 ./prep_dataset/ILSVRC2012_val_00001966.bin 224 224 +41525 ./prep_dataset/ILSVRC2012_val_00007604.bin 224 224 +41526 ./prep_dataset/ILSVRC2012_val_00016863.bin 224 224 +41527 ./prep_dataset/ILSVRC2012_val_00014695.bin 224 224 +41528 ./prep_dataset/ILSVRC2012_val_00033771.bin 224 224 +41529 ./prep_dataset/ILSVRC2012_val_00034143.bin 224 224 +41530 ./prep_dataset/ILSVRC2012_val_00011787.bin 224 224 +41531 ./prep_dataset/ILSVRC2012_val_00037731.bin 224 224 +41532 ./prep_dataset/ILSVRC2012_val_00045919.bin 224 224 +41533 ./prep_dataset/ILSVRC2012_val_00043499.bin 224 224 +41534 ./prep_dataset/ILSVRC2012_val_00008814.bin 224 224 +41535 ./prep_dataset/ILSVRC2012_val_00035210.bin 224 224 +41536 ./prep_dataset/ILSVRC2012_val_00032381.bin 224 224 +41537 ./prep_dataset/ILSVRC2012_val_00034103.bin 224 224 +41538 ./prep_dataset/ILSVRC2012_val_00021608.bin 224 224 +41539 ./prep_dataset/ILSVRC2012_val_00013412.bin 224 224 +41540 ./prep_dataset/ILSVRC2012_val_00031548.bin 224 224 +41541 ./prep_dataset/ILSVRC2012_val_00046004.bin 224 224 +41542 ./prep_dataset/ILSVRC2012_val_00026521.bin 224 224 +41543 ./prep_dataset/ILSVRC2012_val_00004816.bin 224 224 +41544 ./prep_dataset/ILSVRC2012_val_00018572.bin 224 224 +41545 ./prep_dataset/ILSVRC2012_val_00043310.bin 224 224 +41546 ./prep_dataset/ILSVRC2012_val_00031368.bin 224 224 +41547 ./prep_dataset/ILSVRC2012_val_00013753.bin 224 224 +41548 ./prep_dataset/ILSVRC2012_val_00012876.bin 224 224 +41549 ./prep_dataset/ILSVRC2012_val_00033801.bin 224 224 +41550 ./prep_dataset/ILSVRC2012_val_00018082.bin 224 224 +41551 ./prep_dataset/ILSVRC2012_val_00037961.bin 224 224 +41552 ./prep_dataset/ILSVRC2012_val_00017005.bin 224 224 +41553 ./prep_dataset/ILSVRC2012_val_00004411.bin 224 224 +41554 ./prep_dataset/ILSVRC2012_val_00021855.bin 224 224 +41555 ./prep_dataset/ILSVRC2012_val_00017683.bin 224 224 +41556 ./prep_dataset/ILSVRC2012_val_00028146.bin 224 224 +41557 ./prep_dataset/ILSVRC2012_val_00006706.bin 224 224 +41558 ./prep_dataset/ILSVRC2012_val_00041045.bin 224 224 +41559 ./prep_dataset/ILSVRC2012_val_00048401.bin 224 224 +41560 ./prep_dataset/ILSVRC2012_val_00003661.bin 224 224 +41561 ./prep_dataset/ILSVRC2012_val_00049288.bin 224 224 +41562 ./prep_dataset/ILSVRC2012_val_00035948.bin 224 224 +41563 ./prep_dataset/ILSVRC2012_val_00044371.bin 224 224 +41564 ./prep_dataset/ILSVRC2012_val_00021507.bin 224 224 +41565 ./prep_dataset/ILSVRC2012_val_00045532.bin 224 224 +41566 ./prep_dataset/ILSVRC2012_val_00035750.bin 224 224 +41567 ./prep_dataset/ILSVRC2012_val_00018834.bin 224 224 +41568 ./prep_dataset/ILSVRC2012_val_00010503.bin 224 224 +41569 ./prep_dataset/ILSVRC2012_val_00021431.bin 224 224 +41570 ./prep_dataset/ILSVRC2012_val_00046509.bin 224 224 +41571 ./prep_dataset/ILSVRC2012_val_00008040.bin 224 224 +41572 ./prep_dataset/ILSVRC2012_val_00020860.bin 224 224 +41573 ./prep_dataset/ILSVRC2012_val_00039467.bin 224 224 +41574 ./prep_dataset/ILSVRC2012_val_00038431.bin 224 224 +41575 ./prep_dataset/ILSVRC2012_val_00024284.bin 224 224 +41576 ./prep_dataset/ILSVRC2012_val_00027243.bin 224 224 +41577 ./prep_dataset/ILSVRC2012_val_00005693.bin 224 224 +41578 ./prep_dataset/ILSVRC2012_val_00004263.bin 224 224 +41579 ./prep_dataset/ILSVRC2012_val_00028088.bin 224 224 +41580 ./prep_dataset/ILSVRC2012_val_00003627.bin 224 224 +41581 ./prep_dataset/ILSVRC2012_val_00006715.bin 224 224 +41582 ./prep_dataset/ILSVRC2012_val_00032025.bin 224 224 +41583 ./prep_dataset/ILSVRC2012_val_00003252.bin 224 224 +41584 ./prep_dataset/ILSVRC2012_val_00000653.bin 224 224 +41585 ./prep_dataset/ILSVRC2012_val_00047991.bin 224 224 +41586 ./prep_dataset/ILSVRC2012_val_00005540.bin 224 224 +41587 ./prep_dataset/ILSVRC2012_val_00040037.bin 224 224 +41588 ./prep_dataset/ILSVRC2012_val_00001251.bin 224 224 +41589 ./prep_dataset/ILSVRC2012_val_00033360.bin 224 224 +41590 ./prep_dataset/ILSVRC2012_val_00043136.bin 224 224 +41591 ./prep_dataset/ILSVRC2012_val_00030841.bin 224 224 +41592 ./prep_dataset/ILSVRC2012_val_00031231.bin 224 224 +41593 ./prep_dataset/ILSVRC2012_val_00017085.bin 224 224 +41594 ./prep_dataset/ILSVRC2012_val_00011905.bin 224 224 +41595 ./prep_dataset/ILSVRC2012_val_00018513.bin 224 224 +41596 ./prep_dataset/ILSVRC2012_val_00016647.bin 224 224 +41597 ./prep_dataset/ILSVRC2012_val_00003938.bin 224 224 +41598 ./prep_dataset/ILSVRC2012_val_00023388.bin 224 224 +41599 ./prep_dataset/ILSVRC2012_val_00046383.bin 224 224 +41600 ./prep_dataset/ILSVRC2012_val_00043876.bin 224 224 +41601 ./prep_dataset/ILSVRC2012_val_00019952.bin 224 224 +41602 ./prep_dataset/ILSVRC2012_val_00007408.bin 224 224 +41603 ./prep_dataset/ILSVRC2012_val_00030248.bin 224 224 +41604 ./prep_dataset/ILSVRC2012_val_00010718.bin 224 224 +41605 ./prep_dataset/ILSVRC2012_val_00011992.bin 224 224 +41606 ./prep_dataset/ILSVRC2012_val_00040456.bin 224 224 +41607 ./prep_dataset/ILSVRC2012_val_00002577.bin 224 224 +41608 ./prep_dataset/ILSVRC2012_val_00005316.bin 224 224 +41609 ./prep_dataset/ILSVRC2012_val_00031230.bin 224 224 +41610 ./prep_dataset/ILSVRC2012_val_00004505.bin 224 224 +41611 ./prep_dataset/ILSVRC2012_val_00013071.bin 224 224 +41612 ./prep_dataset/ILSVRC2012_val_00015252.bin 224 224 +41613 ./prep_dataset/ILSVRC2012_val_00001075.bin 224 224 +41614 ./prep_dataset/ILSVRC2012_val_00048230.bin 224 224 +41615 ./prep_dataset/ILSVRC2012_val_00038502.bin 224 224 +41616 ./prep_dataset/ILSVRC2012_val_00024918.bin 224 224 +41617 ./prep_dataset/ILSVRC2012_val_00041068.bin 224 224 +41618 ./prep_dataset/ILSVRC2012_val_00049301.bin 224 224 +41619 ./prep_dataset/ILSVRC2012_val_00046874.bin 224 224 +41620 ./prep_dataset/ILSVRC2012_val_00003011.bin 224 224 +41621 ./prep_dataset/ILSVRC2012_val_00031007.bin 224 224 +41622 ./prep_dataset/ILSVRC2012_val_00023846.bin 224 224 +41623 ./prep_dataset/ILSVRC2012_val_00008313.bin 224 224 +41624 ./prep_dataset/ILSVRC2012_val_00017154.bin 224 224 +41625 ./prep_dataset/ILSVRC2012_val_00002681.bin 224 224 +41626 ./prep_dataset/ILSVRC2012_val_00002131.bin 224 224 +41627 ./prep_dataset/ILSVRC2012_val_00004821.bin 224 224 +41628 ./prep_dataset/ILSVRC2012_val_00002583.bin 224 224 +41629 ./prep_dataset/ILSVRC2012_val_00001089.bin 224 224 +41630 ./prep_dataset/ILSVRC2012_val_00024631.bin 224 224 +41631 ./prep_dataset/ILSVRC2012_val_00016923.bin 224 224 +41632 ./prep_dataset/ILSVRC2012_val_00046070.bin 224 224 +41633 ./prep_dataset/ILSVRC2012_val_00038314.bin 224 224 +41634 ./prep_dataset/ILSVRC2012_val_00036870.bin 224 224 +41635 ./prep_dataset/ILSVRC2012_val_00041874.bin 224 224 +41636 ./prep_dataset/ILSVRC2012_val_00048461.bin 224 224 +41637 ./prep_dataset/ILSVRC2012_val_00029960.bin 224 224 +41638 ./prep_dataset/ILSVRC2012_val_00039248.bin 224 224 +41639 ./prep_dataset/ILSVRC2012_val_00026676.bin 224 224 +41640 ./prep_dataset/ILSVRC2012_val_00018936.bin 224 224 +41641 ./prep_dataset/ILSVRC2012_val_00045997.bin 224 224 +41642 ./prep_dataset/ILSVRC2012_val_00048732.bin 224 224 +41643 ./prep_dataset/ILSVRC2012_val_00009354.bin 224 224 +41644 ./prep_dataset/ILSVRC2012_val_00022497.bin 224 224 +41645 ./prep_dataset/ILSVRC2012_val_00009396.bin 224 224 +41646 ./prep_dataset/ILSVRC2012_val_00048534.bin 224 224 +41647 ./prep_dataset/ILSVRC2012_val_00028232.bin 224 224 +41648 ./prep_dataset/ILSVRC2012_val_00002076.bin 224 224 +41649 ./prep_dataset/ILSVRC2012_val_00034043.bin 224 224 +41650 ./prep_dataset/ILSVRC2012_val_00013258.bin 224 224 +41651 ./prep_dataset/ILSVRC2012_val_00017101.bin 224 224 +41652 ./prep_dataset/ILSVRC2012_val_00015822.bin 224 224 +41653 ./prep_dataset/ILSVRC2012_val_00026642.bin 224 224 +41654 ./prep_dataset/ILSVRC2012_val_00019496.bin 224 224 +41655 ./prep_dataset/ILSVRC2012_val_00020553.bin 224 224 +41656 ./prep_dataset/ILSVRC2012_val_00036517.bin 224 224 +41657 ./prep_dataset/ILSVRC2012_val_00018291.bin 224 224 +41658 ./prep_dataset/ILSVRC2012_val_00005652.bin 224 224 +41659 ./prep_dataset/ILSVRC2012_val_00001670.bin 224 224 +41660 ./prep_dataset/ILSVRC2012_val_00040706.bin 224 224 +41661 ./prep_dataset/ILSVRC2012_val_00034636.bin 224 224 +41662 ./prep_dataset/ILSVRC2012_val_00009568.bin 224 224 +41663 ./prep_dataset/ILSVRC2012_val_00025961.bin 224 224 +41664 ./prep_dataset/ILSVRC2012_val_00038331.bin 224 224 +41665 ./prep_dataset/ILSVRC2012_val_00002586.bin 224 224 +41666 ./prep_dataset/ILSVRC2012_val_00030368.bin 224 224 +41667 ./prep_dataset/ILSVRC2012_val_00017973.bin 224 224 +41668 ./prep_dataset/ILSVRC2012_val_00036489.bin 224 224 +41669 ./prep_dataset/ILSVRC2012_val_00040194.bin 224 224 +41670 ./prep_dataset/ILSVRC2012_val_00013826.bin 224 224 +41671 ./prep_dataset/ILSVRC2012_val_00019640.bin 224 224 +41672 ./prep_dataset/ILSVRC2012_val_00037601.bin 224 224 +41673 ./prep_dataset/ILSVRC2012_val_00002115.bin 224 224 +41674 ./prep_dataset/ILSVRC2012_val_00009484.bin 224 224 +41675 ./prep_dataset/ILSVRC2012_val_00000011.bin 224 224 +41676 ./prep_dataset/ILSVRC2012_val_00039227.bin 224 224 +41677 ./prep_dataset/ILSVRC2012_val_00037282.bin 224 224 +41678 ./prep_dataset/ILSVRC2012_val_00038604.bin 224 224 +41679 ./prep_dataset/ILSVRC2012_val_00010078.bin 224 224 +41680 ./prep_dataset/ILSVRC2012_val_00036659.bin 224 224 +41681 ./prep_dataset/ILSVRC2012_val_00019308.bin 224 224 +41682 ./prep_dataset/ILSVRC2012_val_00004072.bin 224 224 +41683 ./prep_dataset/ILSVRC2012_val_00049246.bin 224 224 +41684 ./prep_dataset/ILSVRC2012_val_00000557.bin 224 224 +41685 ./prep_dataset/ILSVRC2012_val_00049596.bin 224 224 +41686 ./prep_dataset/ILSVRC2012_val_00029215.bin 224 224 +41687 ./prep_dataset/ILSVRC2012_val_00035445.bin 224 224 +41688 ./prep_dataset/ILSVRC2012_val_00008032.bin 224 224 +41689 ./prep_dataset/ILSVRC2012_val_00033243.bin 224 224 +41690 ./prep_dataset/ILSVRC2012_val_00003649.bin 224 224 +41691 ./prep_dataset/ILSVRC2012_val_00017336.bin 224 224 +41692 ./prep_dataset/ILSVRC2012_val_00018124.bin 224 224 +41693 ./prep_dataset/ILSVRC2012_val_00004296.bin 224 224 +41694 ./prep_dataset/ILSVRC2012_val_00047611.bin 224 224 +41695 ./prep_dataset/ILSVRC2012_val_00022998.bin 224 224 +41696 ./prep_dataset/ILSVRC2012_val_00020689.bin 224 224 +41697 ./prep_dataset/ILSVRC2012_val_00020659.bin 224 224 +41698 ./prep_dataset/ILSVRC2012_val_00024086.bin 224 224 +41699 ./prep_dataset/ILSVRC2012_val_00022708.bin 224 224 +41700 ./prep_dataset/ILSVRC2012_val_00042306.bin 224 224 +41701 ./prep_dataset/ILSVRC2012_val_00009057.bin 224 224 +41702 ./prep_dataset/ILSVRC2012_val_00007741.bin 224 224 +41703 ./prep_dataset/ILSVRC2012_val_00042480.bin 224 224 +41704 ./prep_dataset/ILSVRC2012_val_00024377.bin 224 224 +41705 ./prep_dataset/ILSVRC2012_val_00042439.bin 224 224 +41706 ./prep_dataset/ILSVRC2012_val_00049349.bin 224 224 +41707 ./prep_dataset/ILSVRC2012_val_00019456.bin 224 224 +41708 ./prep_dataset/ILSVRC2012_val_00016376.bin 224 224 +41709 ./prep_dataset/ILSVRC2012_val_00041898.bin 224 224 +41710 ./prep_dataset/ILSVRC2012_val_00010104.bin 224 224 +41711 ./prep_dataset/ILSVRC2012_val_00046824.bin 224 224 +41712 ./prep_dataset/ILSVRC2012_val_00044064.bin 224 224 +41713 ./prep_dataset/ILSVRC2012_val_00024402.bin 224 224 +41714 ./prep_dataset/ILSVRC2012_val_00007197.bin 224 224 +41715 ./prep_dataset/ILSVRC2012_val_00005385.bin 224 224 +41716 ./prep_dataset/ILSVRC2012_val_00028275.bin 224 224 +41717 ./prep_dataset/ILSVRC2012_val_00048305.bin 224 224 +41718 ./prep_dataset/ILSVRC2012_val_00017147.bin 224 224 +41719 ./prep_dataset/ILSVRC2012_val_00013442.bin 224 224 +41720 ./prep_dataset/ILSVRC2012_val_00046138.bin 224 224 +41721 ./prep_dataset/ILSVRC2012_val_00043925.bin 224 224 +41722 ./prep_dataset/ILSVRC2012_val_00024301.bin 224 224 +41723 ./prep_dataset/ILSVRC2012_val_00046431.bin 224 224 +41724 ./prep_dataset/ILSVRC2012_val_00036628.bin 224 224 +41725 ./prep_dataset/ILSVRC2012_val_00021181.bin 224 224 +41726 ./prep_dataset/ILSVRC2012_val_00003227.bin 224 224 +41727 ./prep_dataset/ILSVRC2012_val_00021784.bin 224 224 +41728 ./prep_dataset/ILSVRC2012_val_00006446.bin 224 224 +41729 ./prep_dataset/ILSVRC2012_val_00024727.bin 224 224 +41730 ./prep_dataset/ILSVRC2012_val_00007609.bin 224 224 +41731 ./prep_dataset/ILSVRC2012_val_00007259.bin 224 224 +41732 ./prep_dataset/ILSVRC2012_val_00046713.bin 224 224 +41733 ./prep_dataset/ILSVRC2012_val_00034875.bin 224 224 +41734 ./prep_dataset/ILSVRC2012_val_00038666.bin 224 224 +41735 ./prep_dataset/ILSVRC2012_val_00003042.bin 224 224 +41736 ./prep_dataset/ILSVRC2012_val_00014878.bin 224 224 +41737 ./prep_dataset/ILSVRC2012_val_00023583.bin 224 224 +41738 ./prep_dataset/ILSVRC2012_val_00010780.bin 224 224 +41739 ./prep_dataset/ILSVRC2012_val_00035860.bin 224 224 +41740 ./prep_dataset/ILSVRC2012_val_00046725.bin 224 224 +41741 ./prep_dataset/ILSVRC2012_val_00039232.bin 224 224 +41742 ./prep_dataset/ILSVRC2012_val_00003579.bin 224 224 +41743 ./prep_dataset/ILSVRC2012_val_00048607.bin 224 224 +41744 ./prep_dataset/ILSVRC2012_val_00008226.bin 224 224 +41745 ./prep_dataset/ILSVRC2012_val_00043870.bin 224 224 +41746 ./prep_dataset/ILSVRC2012_val_00002234.bin 224 224 +41747 ./prep_dataset/ILSVRC2012_val_00034060.bin 224 224 +41748 ./prep_dataset/ILSVRC2012_val_00013974.bin 224 224 +41749 ./prep_dataset/ILSVRC2012_val_00044874.bin 224 224 +41750 ./prep_dataset/ILSVRC2012_val_00021890.bin 224 224 +41751 ./prep_dataset/ILSVRC2012_val_00005796.bin 224 224 +41752 ./prep_dataset/ILSVRC2012_val_00047421.bin 224 224 +41753 ./prep_dataset/ILSVRC2012_val_00028536.bin 224 224 +41754 ./prep_dataset/ILSVRC2012_val_00048058.bin 224 224 +41755 ./prep_dataset/ILSVRC2012_val_00026477.bin 224 224 +41756 ./prep_dataset/ILSVRC2012_val_00011176.bin 224 224 +41757 ./prep_dataset/ILSVRC2012_val_00042239.bin 224 224 +41758 ./prep_dataset/ILSVRC2012_val_00049393.bin 224 224 +41759 ./prep_dataset/ILSVRC2012_val_00034343.bin 224 224 +41760 ./prep_dataset/ILSVRC2012_val_00003513.bin 224 224 +41761 ./prep_dataset/ILSVRC2012_val_00025718.bin 224 224 +41762 ./prep_dataset/ILSVRC2012_val_00018803.bin 224 224 +41763 ./prep_dataset/ILSVRC2012_val_00003956.bin 224 224 +41764 ./prep_dataset/ILSVRC2012_val_00019430.bin 224 224 +41765 ./prep_dataset/ILSVRC2012_val_00015405.bin 224 224 +41766 ./prep_dataset/ILSVRC2012_val_00008886.bin 224 224 +41767 ./prep_dataset/ILSVRC2012_val_00034056.bin 224 224 +41768 ./prep_dataset/ILSVRC2012_val_00007386.bin 224 224 +41769 ./prep_dataset/ILSVRC2012_val_00004657.bin 224 224 +41770 ./prep_dataset/ILSVRC2012_val_00045813.bin 224 224 +41771 ./prep_dataset/ILSVRC2012_val_00004433.bin 224 224 +41772 ./prep_dataset/ILSVRC2012_val_00036494.bin 224 224 +41773 ./prep_dataset/ILSVRC2012_val_00012654.bin 224 224 +41774 ./prep_dataset/ILSVRC2012_val_00021638.bin 224 224 +41775 ./prep_dataset/ILSVRC2012_val_00006575.bin 224 224 +41776 ./prep_dataset/ILSVRC2012_val_00001446.bin 224 224 +41777 ./prep_dataset/ILSVRC2012_val_00033974.bin 224 224 +41778 ./prep_dataset/ILSVRC2012_val_00023836.bin 224 224 +41779 ./prep_dataset/ILSVRC2012_val_00042465.bin 224 224 +41780 ./prep_dataset/ILSVRC2012_val_00049082.bin 224 224 +41781 ./prep_dataset/ILSVRC2012_val_00040246.bin 224 224 +41782 ./prep_dataset/ILSVRC2012_val_00035313.bin 224 224 +41783 ./prep_dataset/ILSVRC2012_val_00049594.bin 224 224 +41784 ./prep_dataset/ILSVRC2012_val_00025259.bin 224 224 +41785 ./prep_dataset/ILSVRC2012_val_00034940.bin 224 224 +41786 ./prep_dataset/ILSVRC2012_val_00022906.bin 224 224 +41787 ./prep_dataset/ILSVRC2012_val_00018777.bin 224 224 +41788 ./prep_dataset/ILSVRC2012_val_00002624.bin 224 224 +41789 ./prep_dataset/ILSVRC2012_val_00031235.bin 224 224 +41790 ./prep_dataset/ILSVRC2012_val_00035284.bin 224 224 +41791 ./prep_dataset/ILSVRC2012_val_00022210.bin 224 224 +41792 ./prep_dataset/ILSVRC2012_val_00031853.bin 224 224 +41793 ./prep_dataset/ILSVRC2012_val_00018007.bin 224 224 +41794 ./prep_dataset/ILSVRC2012_val_00013558.bin 224 224 +41795 ./prep_dataset/ILSVRC2012_val_00002730.bin 224 224 +41796 ./prep_dataset/ILSVRC2012_val_00022220.bin 224 224 +41797 ./prep_dataset/ILSVRC2012_val_00002415.bin 224 224 +41798 ./prep_dataset/ILSVRC2012_val_00001794.bin 224 224 +41799 ./prep_dataset/ILSVRC2012_val_00009922.bin 224 224 +41800 ./prep_dataset/ILSVRC2012_val_00033517.bin 224 224 +41801 ./prep_dataset/ILSVRC2012_val_00009674.bin 224 224 +41802 ./prep_dataset/ILSVRC2012_val_00037994.bin 224 224 +41803 ./prep_dataset/ILSVRC2012_val_00041629.bin 224 224 +41804 ./prep_dataset/ILSVRC2012_val_00036698.bin 224 224 +41805 ./prep_dataset/ILSVRC2012_val_00044994.bin 224 224 +41806 ./prep_dataset/ILSVRC2012_val_00008535.bin 224 224 +41807 ./prep_dataset/ILSVRC2012_val_00033639.bin 224 224 +41808 ./prep_dataset/ILSVRC2012_val_00016910.bin 224 224 +41809 ./prep_dataset/ILSVRC2012_val_00030643.bin 224 224 +41810 ./prep_dataset/ILSVRC2012_val_00028939.bin 224 224 +41811 ./prep_dataset/ILSVRC2012_val_00020244.bin 224 224 +41812 ./prep_dataset/ILSVRC2012_val_00035552.bin 224 224 +41813 ./prep_dataset/ILSVRC2012_val_00030250.bin 224 224 +41814 ./prep_dataset/ILSVRC2012_val_00002352.bin 224 224 +41815 ./prep_dataset/ILSVRC2012_val_00036246.bin 224 224 +41816 ./prep_dataset/ILSVRC2012_val_00028046.bin 224 224 +41817 ./prep_dataset/ILSVRC2012_val_00019333.bin 224 224 +41818 ./prep_dataset/ILSVRC2012_val_00018464.bin 224 224 +41819 ./prep_dataset/ILSVRC2012_val_00023182.bin 224 224 +41820 ./prep_dataset/ILSVRC2012_val_00049164.bin 224 224 +41821 ./prep_dataset/ILSVRC2012_val_00039177.bin 224 224 +41822 ./prep_dataset/ILSVRC2012_val_00025710.bin 224 224 +41823 ./prep_dataset/ILSVRC2012_val_00009833.bin 224 224 +41824 ./prep_dataset/ILSVRC2012_val_00009723.bin 224 224 +41825 ./prep_dataset/ILSVRC2012_val_00011735.bin 224 224 +41826 ./prep_dataset/ILSVRC2012_val_00012627.bin 224 224 +41827 ./prep_dataset/ILSVRC2012_val_00044453.bin 224 224 +41828 ./prep_dataset/ILSVRC2012_val_00017158.bin 224 224 +41829 ./prep_dataset/ILSVRC2012_val_00024244.bin 224 224 +41830 ./prep_dataset/ILSVRC2012_val_00032210.bin 224 224 +41831 ./prep_dataset/ILSVRC2012_val_00014097.bin 224 224 +41832 ./prep_dataset/ILSVRC2012_val_00026497.bin 224 224 +41833 ./prep_dataset/ILSVRC2012_val_00034881.bin 224 224 +41834 ./prep_dataset/ILSVRC2012_val_00029843.bin 224 224 +41835 ./prep_dataset/ILSVRC2012_val_00046464.bin 224 224 +41836 ./prep_dataset/ILSVRC2012_val_00042733.bin 224 224 +41837 ./prep_dataset/ILSVRC2012_val_00020692.bin 224 224 +41838 ./prep_dataset/ILSVRC2012_val_00022238.bin 224 224 +41839 ./prep_dataset/ILSVRC2012_val_00048066.bin 224 224 +41840 ./prep_dataset/ILSVRC2012_val_00045596.bin 224 224 +41841 ./prep_dataset/ILSVRC2012_val_00043012.bin 224 224 +41842 ./prep_dataset/ILSVRC2012_val_00025430.bin 224 224 +41843 ./prep_dataset/ILSVRC2012_val_00016777.bin 224 224 +41844 ./prep_dataset/ILSVRC2012_val_00028718.bin 224 224 +41845 ./prep_dataset/ILSVRC2012_val_00019457.bin 224 224 +41846 ./prep_dataset/ILSVRC2012_val_00043308.bin 224 224 +41847 ./prep_dataset/ILSVRC2012_val_00024322.bin 224 224 +41848 ./prep_dataset/ILSVRC2012_val_00048986.bin 224 224 +41849 ./prep_dataset/ILSVRC2012_val_00037070.bin 224 224 +41850 ./prep_dataset/ILSVRC2012_val_00023911.bin 224 224 +41851 ./prep_dataset/ILSVRC2012_val_00048731.bin 224 224 +41852 ./prep_dataset/ILSVRC2012_val_00027681.bin 224 224 +41853 ./prep_dataset/ILSVRC2012_val_00020469.bin 224 224 +41854 ./prep_dataset/ILSVRC2012_val_00003454.bin 224 224 +41855 ./prep_dataset/ILSVRC2012_val_00015245.bin 224 224 +41856 ./prep_dataset/ILSVRC2012_val_00033104.bin 224 224 +41857 ./prep_dataset/ILSVRC2012_val_00031336.bin 224 224 +41858 ./prep_dataset/ILSVRC2012_val_00002709.bin 224 224 +41859 ./prep_dataset/ILSVRC2012_val_00006597.bin 224 224 +41860 ./prep_dataset/ILSVRC2012_val_00036993.bin 224 224 +41861 ./prep_dataset/ILSVRC2012_val_00004709.bin 224 224 +41862 ./prep_dataset/ILSVRC2012_val_00013253.bin 224 224 +41863 ./prep_dataset/ILSVRC2012_val_00006623.bin 224 224 +41864 ./prep_dataset/ILSVRC2012_val_00011870.bin 224 224 +41865 ./prep_dataset/ILSVRC2012_val_00028209.bin 224 224 +41866 ./prep_dataset/ILSVRC2012_val_00041925.bin 224 224 +41867 ./prep_dataset/ILSVRC2012_val_00020293.bin 224 224 +41868 ./prep_dataset/ILSVRC2012_val_00014741.bin 224 224 +41869 ./prep_dataset/ILSVRC2012_val_00037186.bin 224 224 +41870 ./prep_dataset/ILSVRC2012_val_00008978.bin 224 224 +41871 ./prep_dataset/ILSVRC2012_val_00034842.bin 224 224 +41872 ./prep_dataset/ILSVRC2012_val_00046172.bin 224 224 +41873 ./prep_dataset/ILSVRC2012_val_00016982.bin 224 224 +41874 ./prep_dataset/ILSVRC2012_val_00005257.bin 224 224 +41875 ./prep_dataset/ILSVRC2012_val_00007144.bin 224 224 +41876 ./prep_dataset/ILSVRC2012_val_00040375.bin 224 224 +41877 ./prep_dataset/ILSVRC2012_val_00004015.bin 224 224 +41878 ./prep_dataset/ILSVRC2012_val_00036558.bin 224 224 +41879 ./prep_dataset/ILSVRC2012_val_00004577.bin 224 224 +41880 ./prep_dataset/ILSVRC2012_val_00031779.bin 224 224 +41881 ./prep_dataset/ILSVRC2012_val_00011515.bin 224 224 +41882 ./prep_dataset/ILSVRC2012_val_00047178.bin 224 224 +41883 ./prep_dataset/ILSVRC2012_val_00035264.bin 224 224 +41884 ./prep_dataset/ILSVRC2012_val_00025315.bin 224 224 +41885 ./prep_dataset/ILSVRC2012_val_00016484.bin 224 224 +41886 ./prep_dataset/ILSVRC2012_val_00021145.bin 224 224 +41887 ./prep_dataset/ILSVRC2012_val_00017008.bin 224 224 +41888 ./prep_dataset/ILSVRC2012_val_00025560.bin 224 224 +41889 ./prep_dataset/ILSVRC2012_val_00005893.bin 224 224 +41890 ./prep_dataset/ILSVRC2012_val_00034943.bin 224 224 +41891 ./prep_dataset/ILSVRC2012_val_00047733.bin 224 224 +41892 ./prep_dataset/ILSVRC2012_val_00033460.bin 224 224 +41893 ./prep_dataset/ILSVRC2012_val_00036524.bin 224 224 +41894 ./prep_dataset/ILSVRC2012_val_00032865.bin 224 224 +41895 ./prep_dataset/ILSVRC2012_val_00016137.bin 224 224 +41896 ./prep_dataset/ILSVRC2012_val_00000873.bin 224 224 +41897 ./prep_dataset/ILSVRC2012_val_00037484.bin 224 224 +41898 ./prep_dataset/ILSVRC2012_val_00045594.bin 224 224 +41899 ./prep_dataset/ILSVRC2012_val_00049338.bin 224 224 +41900 ./prep_dataset/ILSVRC2012_val_00031978.bin 224 224 +41901 ./prep_dataset/ILSVRC2012_val_00043116.bin 224 224 +41902 ./prep_dataset/ILSVRC2012_val_00022714.bin 224 224 +41903 ./prep_dataset/ILSVRC2012_val_00034918.bin 224 224 +41904 ./prep_dataset/ILSVRC2012_val_00023567.bin 224 224 +41905 ./prep_dataset/ILSVRC2012_val_00046307.bin 224 224 +41906 ./prep_dataset/ILSVRC2012_val_00005209.bin 224 224 +41907 ./prep_dataset/ILSVRC2012_val_00020235.bin 224 224 +41908 ./prep_dataset/ILSVRC2012_val_00015496.bin 224 224 +41909 ./prep_dataset/ILSVRC2012_val_00036347.bin 224 224 +41910 ./prep_dataset/ILSVRC2012_val_00018791.bin 224 224 +41911 ./prep_dataset/ILSVRC2012_val_00003311.bin 224 224 +41912 ./prep_dataset/ILSVRC2012_val_00047117.bin 224 224 +41913 ./prep_dataset/ILSVRC2012_val_00023665.bin 224 224 +41914 ./prep_dataset/ILSVRC2012_val_00039501.bin 224 224 +41915 ./prep_dataset/ILSVRC2012_val_00010251.bin 224 224 +41916 ./prep_dataset/ILSVRC2012_val_00043738.bin 224 224 +41917 ./prep_dataset/ILSVRC2012_val_00038268.bin 224 224 +41918 ./prep_dataset/ILSVRC2012_val_00038781.bin 224 224 +41919 ./prep_dataset/ILSVRC2012_val_00031806.bin 224 224 +41920 ./prep_dataset/ILSVRC2012_val_00018070.bin 224 224 +41921 ./prep_dataset/ILSVRC2012_val_00015868.bin 224 224 +41922 ./prep_dataset/ILSVRC2012_val_00000169.bin 224 224 +41923 ./prep_dataset/ILSVRC2012_val_00026156.bin 224 224 +41924 ./prep_dataset/ILSVRC2012_val_00031972.bin 224 224 +41925 ./prep_dataset/ILSVRC2012_val_00040232.bin 224 224 +41926 ./prep_dataset/ILSVRC2012_val_00000877.bin 224 224 +41927 ./prep_dataset/ILSVRC2012_val_00035876.bin 224 224 +41928 ./prep_dataset/ILSVRC2012_val_00028383.bin 224 224 +41929 ./prep_dataset/ILSVRC2012_val_00031663.bin 224 224 +41930 ./prep_dataset/ILSVRC2012_val_00011349.bin 224 224 +41931 ./prep_dataset/ILSVRC2012_val_00003796.bin 224 224 +41932 ./prep_dataset/ILSVRC2012_val_00049509.bin 224 224 +41933 ./prep_dataset/ILSVRC2012_val_00020196.bin 224 224 +41934 ./prep_dataset/ILSVRC2012_val_00019836.bin 224 224 +41935 ./prep_dataset/ILSVRC2012_val_00003098.bin 224 224 +41936 ./prep_dataset/ILSVRC2012_val_00033648.bin 224 224 +41937 ./prep_dataset/ILSVRC2012_val_00037518.bin 224 224 +41938 ./prep_dataset/ILSVRC2012_val_00023743.bin 224 224 +41939 ./prep_dataset/ILSVRC2012_val_00015739.bin 224 224 +41940 ./prep_dataset/ILSVRC2012_val_00013860.bin 224 224 +41941 ./prep_dataset/ILSVRC2012_val_00024070.bin 224 224 +41942 ./prep_dataset/ILSVRC2012_val_00010331.bin 224 224 +41943 ./prep_dataset/ILSVRC2012_val_00038866.bin 224 224 +41944 ./prep_dataset/ILSVRC2012_val_00010228.bin 224 224 +41945 ./prep_dataset/ILSVRC2012_val_00013300.bin 224 224 +41946 ./prep_dataset/ILSVRC2012_val_00042352.bin 224 224 +41947 ./prep_dataset/ILSVRC2012_val_00033987.bin 224 224 +41948 ./prep_dataset/ILSVRC2012_val_00008402.bin 224 224 +41949 ./prep_dataset/ILSVRC2012_val_00046399.bin 224 224 +41950 ./prep_dataset/ILSVRC2012_val_00015847.bin 224 224 +41951 ./prep_dataset/ILSVRC2012_val_00018062.bin 224 224 +41952 ./prep_dataset/ILSVRC2012_val_00002058.bin 224 224 +41953 ./prep_dataset/ILSVRC2012_val_00028992.bin 224 224 +41954 ./prep_dataset/ILSVRC2012_val_00040053.bin 224 224 +41955 ./prep_dataset/ILSVRC2012_val_00016521.bin 224 224 +41956 ./prep_dataset/ILSVRC2012_val_00041801.bin 224 224 +41957 ./prep_dataset/ILSVRC2012_val_00019877.bin 224 224 +41958 ./prep_dataset/ILSVRC2012_val_00002268.bin 224 224 +41959 ./prep_dataset/ILSVRC2012_val_00034038.bin 224 224 +41960 ./prep_dataset/ILSVRC2012_val_00026218.bin 224 224 +41961 ./prep_dataset/ILSVRC2012_val_00033240.bin 224 224 +41962 ./prep_dataset/ILSVRC2012_val_00004476.bin 224 224 +41963 ./prep_dataset/ILSVRC2012_val_00011379.bin 224 224 +41964 ./prep_dataset/ILSVRC2012_val_00038044.bin 224 224 +41965 ./prep_dataset/ILSVRC2012_val_00046079.bin 224 224 +41966 ./prep_dataset/ILSVRC2012_val_00047281.bin 224 224 +41967 ./prep_dataset/ILSVRC2012_val_00018622.bin 224 224 +41968 ./prep_dataset/ILSVRC2012_val_00044921.bin 224 224 +41969 ./prep_dataset/ILSVRC2012_val_00020065.bin 224 224 +41970 ./prep_dataset/ILSVRC2012_val_00007121.bin 224 224 +41971 ./prep_dataset/ILSVRC2012_val_00042687.bin 224 224 +41972 ./prep_dataset/ILSVRC2012_val_00012230.bin 224 224 +41973 ./prep_dataset/ILSVRC2012_val_00035971.bin 224 224 +41974 ./prep_dataset/ILSVRC2012_val_00006929.bin 224 224 +41975 ./prep_dataset/ILSVRC2012_val_00020887.bin 224 224 +41976 ./prep_dataset/ILSVRC2012_val_00039948.bin 224 224 +41977 ./prep_dataset/ILSVRC2012_val_00014062.bin 224 224 +41978 ./prep_dataset/ILSVRC2012_val_00021424.bin 224 224 +41979 ./prep_dataset/ILSVRC2012_val_00014808.bin 224 224 +41980 ./prep_dataset/ILSVRC2012_val_00009770.bin 224 224 +41981 ./prep_dataset/ILSVRC2012_val_00030931.bin 224 224 +41982 ./prep_dataset/ILSVRC2012_val_00019901.bin 224 224 +41983 ./prep_dataset/ILSVRC2012_val_00007457.bin 224 224 +41984 ./prep_dataset/ILSVRC2012_val_00016673.bin 224 224 +41985 ./prep_dataset/ILSVRC2012_val_00049972.bin 224 224 +41986 ./prep_dataset/ILSVRC2012_val_00010823.bin 224 224 +41987 ./prep_dataset/ILSVRC2012_val_00039304.bin 224 224 +41988 ./prep_dataset/ILSVRC2012_val_00005622.bin 224 224 +41989 ./prep_dataset/ILSVRC2012_val_00011981.bin 224 224 +41990 ./prep_dataset/ILSVRC2012_val_00031730.bin 224 224 +41991 ./prep_dataset/ILSVRC2012_val_00016626.bin 224 224 +41992 ./prep_dataset/ILSVRC2012_val_00043536.bin 224 224 +41993 ./prep_dataset/ILSVRC2012_val_00013656.bin 224 224 +41994 ./prep_dataset/ILSVRC2012_val_00034598.bin 224 224 +41995 ./prep_dataset/ILSVRC2012_val_00030753.bin 224 224 +41996 ./prep_dataset/ILSVRC2012_val_00005147.bin 224 224 +41997 ./prep_dataset/ILSVRC2012_val_00010432.bin 224 224 +41998 ./prep_dataset/ILSVRC2012_val_00025283.bin 224 224 +41999 ./prep_dataset/ILSVRC2012_val_00006126.bin 224 224 +42000 ./prep_dataset/ILSVRC2012_val_00004769.bin 224 224 +42001 ./prep_dataset/ILSVRC2012_val_00023658.bin 224 224 +42002 ./prep_dataset/ILSVRC2012_val_00044529.bin 224 224 +42003 ./prep_dataset/ILSVRC2012_val_00004727.bin 224 224 +42004 ./prep_dataset/ILSVRC2012_val_00037595.bin 224 224 +42005 ./prep_dataset/ILSVRC2012_val_00011361.bin 224 224 +42006 ./prep_dataset/ILSVRC2012_val_00019755.bin 224 224 +42007 ./prep_dataset/ILSVRC2012_val_00045267.bin 224 224 +42008 ./prep_dataset/ILSVRC2012_val_00046925.bin 224 224 +42009 ./prep_dataset/ILSVRC2012_val_00030912.bin 224 224 +42010 ./prep_dataset/ILSVRC2012_val_00036934.bin 224 224 +42011 ./prep_dataset/ILSVRC2012_val_00036298.bin 224 224 +42012 ./prep_dataset/ILSVRC2012_val_00044743.bin 224 224 +42013 ./prep_dataset/ILSVRC2012_val_00030797.bin 224 224 +42014 ./prep_dataset/ILSVRC2012_val_00039202.bin 224 224 +42015 ./prep_dataset/ILSVRC2012_val_00009364.bin 224 224 +42016 ./prep_dataset/ILSVRC2012_val_00002183.bin 224 224 +42017 ./prep_dataset/ILSVRC2012_val_00029777.bin 224 224 +42018 ./prep_dataset/ILSVRC2012_val_00034435.bin 224 224 +42019 ./prep_dataset/ILSVRC2012_val_00032059.bin 224 224 +42020 ./prep_dataset/ILSVRC2012_val_00008734.bin 224 224 +42021 ./prep_dataset/ILSVRC2012_val_00011635.bin 224 224 +42022 ./prep_dataset/ILSVRC2012_val_00041044.bin 224 224 +42023 ./prep_dataset/ILSVRC2012_val_00005705.bin 224 224 +42024 ./prep_dataset/ILSVRC2012_val_00011637.bin 224 224 +42025 ./prep_dataset/ILSVRC2012_val_00029689.bin 224 224 +42026 ./prep_dataset/ILSVRC2012_val_00021582.bin 224 224 +42027 ./prep_dataset/ILSVRC2012_val_00005775.bin 224 224 +42028 ./prep_dataset/ILSVRC2012_val_00015935.bin 224 224 +42029 ./prep_dataset/ILSVRC2012_val_00037926.bin 224 224 +42030 ./prep_dataset/ILSVRC2012_val_00021166.bin 224 224 +42031 ./prep_dataset/ILSVRC2012_val_00011170.bin 224 224 +42032 ./prep_dataset/ILSVRC2012_val_00000360.bin 224 224 +42033 ./prep_dataset/ILSVRC2012_val_00006545.bin 224 224 +42034 ./prep_dataset/ILSVRC2012_val_00005423.bin 224 224 +42035 ./prep_dataset/ILSVRC2012_val_00014142.bin 224 224 +42036 ./prep_dataset/ILSVRC2012_val_00034676.bin 224 224 +42037 ./prep_dataset/ILSVRC2012_val_00004675.bin 224 224 +42038 ./prep_dataset/ILSVRC2012_val_00016832.bin 224 224 +42039 ./prep_dataset/ILSVRC2012_val_00048692.bin 224 224 +42040 ./prep_dataset/ILSVRC2012_val_00013505.bin 224 224 +42041 ./prep_dataset/ILSVRC2012_val_00040187.bin 224 224 +42042 ./prep_dataset/ILSVRC2012_val_00041565.bin 224 224 +42043 ./prep_dataset/ILSVRC2012_val_00015141.bin 224 224 +42044 ./prep_dataset/ILSVRC2012_val_00016995.bin 224 224 +42045 ./prep_dataset/ILSVRC2012_val_00042817.bin 224 224 +42046 ./prep_dataset/ILSVRC2012_val_00038562.bin 224 224 +42047 ./prep_dataset/ILSVRC2012_val_00002638.bin 224 224 +42048 ./prep_dataset/ILSVRC2012_val_00015528.bin 224 224 +42049 ./prep_dataset/ILSVRC2012_val_00043875.bin 224 224 +42050 ./prep_dataset/ILSVRC2012_val_00024187.bin 224 224 +42051 ./prep_dataset/ILSVRC2012_val_00036490.bin 224 224 +42052 ./prep_dataset/ILSVRC2012_val_00015159.bin 224 224 +42053 ./prep_dataset/ILSVRC2012_val_00035213.bin 224 224 +42054 ./prep_dataset/ILSVRC2012_val_00025778.bin 224 224 +42055 ./prep_dataset/ILSVRC2012_val_00000454.bin 224 224 +42056 ./prep_dataset/ILSVRC2012_val_00015840.bin 224 224 +42057 ./prep_dataset/ILSVRC2012_val_00012095.bin 224 224 +42058 ./prep_dataset/ILSVRC2012_val_00027941.bin 224 224 +42059 ./prep_dataset/ILSVRC2012_val_00039481.bin 224 224 +42060 ./prep_dataset/ILSVRC2012_val_00008160.bin 224 224 +42061 ./prep_dataset/ILSVRC2012_val_00029458.bin 224 224 +42062 ./prep_dataset/ILSVRC2012_val_00049295.bin 224 224 +42063 ./prep_dataset/ILSVRC2012_val_00012429.bin 224 224 +42064 ./prep_dataset/ILSVRC2012_val_00001022.bin 224 224 +42065 ./prep_dataset/ILSVRC2012_val_00014266.bin 224 224 +42066 ./prep_dataset/ILSVRC2012_val_00044161.bin 224 224 +42067 ./prep_dataset/ILSVRC2012_val_00008826.bin 224 224 +42068 ./prep_dataset/ILSVRC2012_val_00027785.bin 224 224 +42069 ./prep_dataset/ILSVRC2012_val_00014713.bin 224 224 +42070 ./prep_dataset/ILSVRC2012_val_00015393.bin 224 224 +42071 ./prep_dataset/ILSVRC2012_val_00024686.bin 224 224 +42072 ./prep_dataset/ILSVRC2012_val_00019100.bin 224 224 +42073 ./prep_dataset/ILSVRC2012_val_00017547.bin 224 224 +42074 ./prep_dataset/ILSVRC2012_val_00001124.bin 224 224 +42075 ./prep_dataset/ILSVRC2012_val_00038338.bin 224 224 +42076 ./prep_dataset/ILSVRC2012_val_00003758.bin 224 224 +42077 ./prep_dataset/ILSVRC2012_val_00048989.bin 224 224 +42078 ./prep_dataset/ILSVRC2012_val_00020813.bin 224 224 +42079 ./prep_dataset/ILSVRC2012_val_00040594.bin 224 224 +42080 ./prep_dataset/ILSVRC2012_val_00048909.bin 224 224 +42081 ./prep_dataset/ILSVRC2012_val_00049997.bin 224 224 +42082 ./prep_dataset/ILSVRC2012_val_00014959.bin 224 224 +42083 ./prep_dataset/ILSVRC2012_val_00033761.bin 224 224 +42084 ./prep_dataset/ILSVRC2012_val_00023481.bin 224 224 +42085 ./prep_dataset/ILSVRC2012_val_00002617.bin 224 224 +42086 ./prep_dataset/ILSVRC2012_val_00015620.bin 224 224 +42087 ./prep_dataset/ILSVRC2012_val_00005295.bin 224 224 +42088 ./prep_dataset/ILSVRC2012_val_00048701.bin 224 224 +42089 ./prep_dataset/ILSVRC2012_val_00040603.bin 224 224 +42090 ./prep_dataset/ILSVRC2012_val_00045399.bin 224 224 +42091 ./prep_dataset/ILSVRC2012_val_00029577.bin 224 224 +42092 ./prep_dataset/ILSVRC2012_val_00007039.bin 224 224 +42093 ./prep_dataset/ILSVRC2012_val_00006333.bin 224 224 +42094 ./prep_dataset/ILSVRC2012_val_00005323.bin 224 224 +42095 ./prep_dataset/ILSVRC2012_val_00000928.bin 224 224 +42096 ./prep_dataset/ILSVRC2012_val_00006501.bin 224 224 +42097 ./prep_dataset/ILSVRC2012_val_00026082.bin 224 224 +42098 ./prep_dataset/ILSVRC2012_val_00041499.bin 224 224 +42099 ./prep_dataset/ILSVRC2012_val_00029513.bin 224 224 +42100 ./prep_dataset/ILSVRC2012_val_00004847.bin 224 224 +42101 ./prep_dataset/ILSVRC2012_val_00023791.bin 224 224 +42102 ./prep_dataset/ILSVRC2012_val_00006707.bin 224 224 +42103 ./prep_dataset/ILSVRC2012_val_00018450.bin 224 224 +42104 ./prep_dataset/ILSVRC2012_val_00015794.bin 224 224 +42105 ./prep_dataset/ILSVRC2012_val_00036975.bin 224 224 +42106 ./prep_dataset/ILSVRC2012_val_00021308.bin 224 224 +42107 ./prep_dataset/ILSVRC2012_val_00034740.bin 224 224 +42108 ./prep_dataset/ILSVRC2012_val_00040530.bin 224 224 +42109 ./prep_dataset/ILSVRC2012_val_00012754.bin 224 224 +42110 ./prep_dataset/ILSVRC2012_val_00012985.bin 224 224 +42111 ./prep_dataset/ILSVRC2012_val_00008031.bin 224 224 +42112 ./prep_dataset/ILSVRC2012_val_00001817.bin 224 224 +42113 ./prep_dataset/ILSVRC2012_val_00039367.bin 224 224 +42114 ./prep_dataset/ILSVRC2012_val_00045439.bin 224 224 +42115 ./prep_dataset/ILSVRC2012_val_00032543.bin 224 224 +42116 ./prep_dataset/ILSVRC2012_val_00030898.bin 224 224 +42117 ./prep_dataset/ILSVRC2012_val_00037745.bin 224 224 +42118 ./prep_dataset/ILSVRC2012_val_00020395.bin 224 224 +42119 ./prep_dataset/ILSVRC2012_val_00045182.bin 224 224 +42120 ./prep_dataset/ILSVRC2012_val_00007832.bin 224 224 +42121 ./prep_dataset/ILSVRC2012_val_00034964.bin 224 224 +42122 ./prep_dataset/ILSVRC2012_val_00034990.bin 224 224 +42123 ./prep_dataset/ILSVRC2012_val_00024406.bin 224 224 +42124 ./prep_dataset/ILSVRC2012_val_00045607.bin 224 224 +42125 ./prep_dataset/ILSVRC2012_val_00009883.bin 224 224 +42126 ./prep_dataset/ILSVRC2012_val_00039081.bin 224 224 +42127 ./prep_dataset/ILSVRC2012_val_00037444.bin 224 224 +42128 ./prep_dataset/ILSVRC2012_val_00020517.bin 224 224 +42129 ./prep_dataset/ILSVRC2012_val_00023840.bin 224 224 +42130 ./prep_dataset/ILSVRC2012_val_00013124.bin 224 224 +42131 ./prep_dataset/ILSVRC2012_val_00039536.bin 224 224 +42132 ./prep_dataset/ILSVRC2012_val_00033303.bin 224 224 +42133 ./prep_dataset/ILSVRC2012_val_00043311.bin 224 224 +42134 ./prep_dataset/ILSVRC2012_val_00029516.bin 224 224 +42135 ./prep_dataset/ILSVRC2012_val_00039031.bin 224 224 +42136 ./prep_dataset/ILSVRC2012_val_00015758.bin 224 224 +42137 ./prep_dataset/ILSVRC2012_val_00004093.bin 224 224 +42138 ./prep_dataset/ILSVRC2012_val_00013978.bin 224 224 +42139 ./prep_dataset/ILSVRC2012_val_00022995.bin 224 224 +42140 ./prep_dataset/ILSVRC2012_val_00032762.bin 224 224 +42141 ./prep_dataset/ILSVRC2012_val_00026941.bin 224 224 +42142 ./prep_dataset/ILSVRC2012_val_00022511.bin 224 224 +42143 ./prep_dataset/ILSVRC2012_val_00041035.bin 224 224 +42144 ./prep_dataset/ILSVRC2012_val_00011918.bin 224 224 +42145 ./prep_dataset/ILSVRC2012_val_00033255.bin 224 224 +42146 ./prep_dataset/ILSVRC2012_val_00033341.bin 224 224 +42147 ./prep_dataset/ILSVRC2012_val_00021560.bin 224 224 +42148 ./prep_dataset/ILSVRC2012_val_00031962.bin 224 224 +42149 ./prep_dataset/ILSVRC2012_val_00038321.bin 224 224 +42150 ./prep_dataset/ILSVRC2012_val_00014047.bin 224 224 +42151 ./prep_dataset/ILSVRC2012_val_00032206.bin 224 224 +42152 ./prep_dataset/ILSVRC2012_val_00004088.bin 224 224 +42153 ./prep_dataset/ILSVRC2012_val_00019107.bin 224 224 +42154 ./prep_dataset/ILSVRC2012_val_00024277.bin 224 224 +42155 ./prep_dataset/ILSVRC2012_val_00010448.bin 224 224 +42156 ./prep_dataset/ILSVRC2012_val_00040327.bin 224 224 +42157 ./prep_dataset/ILSVRC2012_val_00037152.bin 224 224 +42158 ./prep_dataset/ILSVRC2012_val_00031050.bin 224 224 +42159 ./prep_dataset/ILSVRC2012_val_00014496.bin 224 224 +42160 ./prep_dataset/ILSVRC2012_val_00047017.bin 224 224 +42161 ./prep_dataset/ILSVRC2012_val_00039045.bin 224 224 +42162 ./prep_dataset/ILSVRC2012_val_00029275.bin 224 224 +42163 ./prep_dataset/ILSVRC2012_val_00045115.bin 224 224 +42164 ./prep_dataset/ILSVRC2012_val_00041123.bin 224 224 +42165 ./prep_dataset/ILSVRC2012_val_00034619.bin 224 224 +42166 ./prep_dataset/ILSVRC2012_val_00039679.bin 224 224 +42167 ./prep_dataset/ILSVRC2012_val_00045829.bin 224 224 +42168 ./prep_dataset/ILSVRC2012_val_00000109.bin 224 224 +42169 ./prep_dataset/ILSVRC2012_val_00039546.bin 224 224 +42170 ./prep_dataset/ILSVRC2012_val_00046063.bin 224 224 +42171 ./prep_dataset/ILSVRC2012_val_00038367.bin 224 224 +42172 ./prep_dataset/ILSVRC2012_val_00031673.bin 224 224 +42173 ./prep_dataset/ILSVRC2012_val_00005416.bin 224 224 +42174 ./prep_dataset/ILSVRC2012_val_00015964.bin 224 224 +42175 ./prep_dataset/ILSVRC2012_val_00009245.bin 224 224 +42176 ./prep_dataset/ILSVRC2012_val_00043094.bin 224 224 +42177 ./prep_dataset/ILSVRC2012_val_00011465.bin 224 224 +42178 ./prep_dataset/ILSVRC2012_val_00045073.bin 224 224 +42179 ./prep_dataset/ILSVRC2012_val_00048360.bin 224 224 +42180 ./prep_dataset/ILSVRC2012_val_00024064.bin 224 224 +42181 ./prep_dataset/ILSVRC2012_val_00024240.bin 224 224 +42182 ./prep_dataset/ILSVRC2012_val_00014478.bin 224 224 +42183 ./prep_dataset/ILSVRC2012_val_00045433.bin 224 224 +42184 ./prep_dataset/ILSVRC2012_val_00031901.bin 224 224 +42185 ./prep_dataset/ILSVRC2012_val_00014294.bin 224 224 +42186 ./prep_dataset/ILSVRC2012_val_00001746.bin 224 224 +42187 ./prep_dataset/ILSVRC2012_val_00020979.bin 224 224 +42188 ./prep_dataset/ILSVRC2012_val_00028336.bin 224 224 +42189 ./prep_dataset/ILSVRC2012_val_00033681.bin 224 224 +42190 ./prep_dataset/ILSVRC2012_val_00009208.bin 224 224 +42191 ./prep_dataset/ILSVRC2012_val_00025950.bin 224 224 +42192 ./prep_dataset/ILSVRC2012_val_00035723.bin 224 224 +42193 ./prep_dataset/ILSVRC2012_val_00010406.bin 224 224 +42194 ./prep_dataset/ILSVRC2012_val_00028201.bin 224 224 +42195 ./prep_dataset/ILSVRC2012_val_00015993.bin 224 224 +42196 ./prep_dataset/ILSVRC2012_val_00012039.bin 224 224 +42197 ./prep_dataset/ILSVRC2012_val_00001412.bin 224 224 +42198 ./prep_dataset/ILSVRC2012_val_00043933.bin 224 224 +42199 ./prep_dataset/ILSVRC2012_val_00012105.bin 224 224 +42200 ./prep_dataset/ILSVRC2012_val_00023905.bin 224 224 +42201 ./prep_dataset/ILSVRC2012_val_00039091.bin 224 224 +42202 ./prep_dataset/ILSVRC2012_val_00039674.bin 224 224 +42203 ./prep_dataset/ILSVRC2012_val_00006805.bin 224 224 +42204 ./prep_dataset/ILSVRC2012_val_00037638.bin 224 224 +42205 ./prep_dataset/ILSVRC2012_val_00002692.bin 224 224 +42206 ./prep_dataset/ILSVRC2012_val_00013421.bin 224 224 +42207 ./prep_dataset/ILSVRC2012_val_00041008.bin 224 224 +42208 ./prep_dataset/ILSVRC2012_val_00016814.bin 224 224 +42209 ./prep_dataset/ILSVRC2012_val_00026538.bin 224 224 +42210 ./prep_dataset/ILSVRC2012_val_00031011.bin 224 224 +42211 ./prep_dataset/ILSVRC2012_val_00013697.bin 224 224 +42212 ./prep_dataset/ILSVRC2012_val_00038381.bin 224 224 +42213 ./prep_dataset/ILSVRC2012_val_00010761.bin 224 224 +42214 ./prep_dataset/ILSVRC2012_val_00012133.bin 224 224 +42215 ./prep_dataset/ILSVRC2012_val_00044504.bin 224 224 +42216 ./prep_dataset/ILSVRC2012_val_00029480.bin 224 224 +42217 ./prep_dataset/ILSVRC2012_val_00007180.bin 224 224 +42218 ./prep_dataset/ILSVRC2012_val_00032549.bin 224 224 +42219 ./prep_dataset/ILSVRC2012_val_00023813.bin 224 224 +42220 ./prep_dataset/ILSVRC2012_val_00030645.bin 224 224 +42221 ./prep_dataset/ILSVRC2012_val_00034334.bin 224 224 +42222 ./prep_dataset/ILSVRC2012_val_00035637.bin 224 224 +42223 ./prep_dataset/ILSVRC2012_val_00025605.bin 224 224 +42224 ./prep_dataset/ILSVRC2012_val_00022570.bin 224 224 +42225 ./prep_dataset/ILSVRC2012_val_00000086.bin 224 224 +42226 ./prep_dataset/ILSVRC2012_val_00036143.bin 224 224 +42227 ./prep_dataset/ILSVRC2012_val_00017646.bin 224 224 +42228 ./prep_dataset/ILSVRC2012_val_00003816.bin 224 224 +42229 ./prep_dataset/ILSVRC2012_val_00047256.bin 224 224 +42230 ./prep_dataset/ILSVRC2012_val_00028777.bin 224 224 +42231 ./prep_dataset/ILSVRC2012_val_00027910.bin 224 224 +42232 ./prep_dataset/ILSVRC2012_val_00001945.bin 224 224 +42233 ./prep_dataset/ILSVRC2012_val_00016106.bin 224 224 +42234 ./prep_dataset/ILSVRC2012_val_00024127.bin 224 224 +42235 ./prep_dataset/ILSVRC2012_val_00007726.bin 224 224 +42236 ./prep_dataset/ILSVRC2012_val_00035800.bin 224 224 +42237 ./prep_dataset/ILSVRC2012_val_00014113.bin 224 224 +42238 ./prep_dataset/ILSVRC2012_val_00035155.bin 224 224 +42239 ./prep_dataset/ILSVRC2012_val_00018904.bin 224 224 +42240 ./prep_dataset/ILSVRC2012_val_00049351.bin 224 224 +42241 ./prep_dataset/ILSVRC2012_val_00037879.bin 224 224 +42242 ./prep_dataset/ILSVRC2012_val_00000936.bin 224 224 +42243 ./prep_dataset/ILSVRC2012_val_00012809.bin 224 224 +42244 ./prep_dataset/ILSVRC2012_val_00030144.bin 224 224 +42245 ./prep_dataset/ILSVRC2012_val_00017938.bin 224 224 +42246 ./prep_dataset/ILSVRC2012_val_00042406.bin 224 224 +42247 ./prep_dataset/ILSVRC2012_val_00041450.bin 224 224 +42248 ./prep_dataset/ILSVRC2012_val_00031374.bin 224 224 +42249 ./prep_dataset/ILSVRC2012_val_00042590.bin 224 224 +42250 ./prep_dataset/ILSVRC2012_val_00008677.bin 224 224 +42251 ./prep_dataset/ILSVRC2012_val_00012977.bin 224 224 +42252 ./prep_dataset/ILSVRC2012_val_00047949.bin 224 224 +42253 ./prep_dataset/ILSVRC2012_val_00006966.bin 224 224 +42254 ./prep_dataset/ILSVRC2012_val_00002920.bin 224 224 +42255 ./prep_dataset/ILSVRC2012_val_00049911.bin 224 224 +42256 ./prep_dataset/ILSVRC2012_val_00022257.bin 224 224 +42257 ./prep_dataset/ILSVRC2012_val_00001790.bin 224 224 +42258 ./prep_dataset/ILSVRC2012_val_00033350.bin 224 224 +42259 ./prep_dataset/ILSVRC2012_val_00046179.bin 224 224 +42260 ./prep_dataset/ILSVRC2012_val_00037035.bin 224 224 +42261 ./prep_dataset/ILSVRC2012_val_00021473.bin 224 224 +42262 ./prep_dataset/ILSVRC2012_val_00026065.bin 224 224 +42263 ./prep_dataset/ILSVRC2012_val_00005337.bin 224 224 +42264 ./prep_dataset/ILSVRC2012_val_00009593.bin 224 224 +42265 ./prep_dataset/ILSVRC2012_val_00037100.bin 224 224 +42266 ./prep_dataset/ILSVRC2012_val_00026669.bin 224 224 +42267 ./prep_dataset/ILSVRC2012_val_00011829.bin 224 224 +42268 ./prep_dataset/ILSVRC2012_val_00035907.bin 224 224 +42269 ./prep_dataset/ILSVRC2012_val_00049959.bin 224 224 +42270 ./prep_dataset/ILSVRC2012_val_00049447.bin 224 224 +42271 ./prep_dataset/ILSVRC2012_val_00024329.bin 224 224 +42272 ./prep_dataset/ILSVRC2012_val_00003111.bin 224 224 +42273 ./prep_dataset/ILSVRC2012_val_00041563.bin 224 224 +42274 ./prep_dataset/ILSVRC2012_val_00022592.bin 224 224 +42275 ./prep_dataset/ILSVRC2012_val_00045521.bin 224 224 +42276 ./prep_dataset/ILSVRC2012_val_00040370.bin 224 224 +42277 ./prep_dataset/ILSVRC2012_val_00048791.bin 224 224 +42278 ./prep_dataset/ILSVRC2012_val_00007059.bin 224 224 +42279 ./prep_dataset/ILSVRC2012_val_00049165.bin 224 224 +42280 ./prep_dataset/ILSVRC2012_val_00036216.bin 224 224 +42281 ./prep_dataset/ILSVRC2012_val_00030123.bin 224 224 +42282 ./prep_dataset/ILSVRC2012_val_00013874.bin 224 224 +42283 ./prep_dataset/ILSVRC2012_val_00026597.bin 224 224 +42284 ./prep_dataset/ILSVRC2012_val_00046694.bin 224 224 +42285 ./prep_dataset/ILSVRC2012_val_00026569.bin 224 224 +42286 ./prep_dataset/ILSVRC2012_val_00008660.bin 224 224 +42287 ./prep_dataset/ILSVRC2012_val_00048111.bin 224 224 +42288 ./prep_dataset/ILSVRC2012_val_00026956.bin 224 224 +42289 ./prep_dataset/ILSVRC2012_val_00041914.bin 224 224 +42290 ./prep_dataset/ILSVRC2012_val_00007003.bin 224 224 +42291 ./prep_dataset/ILSVRC2012_val_00013367.bin 224 224 +42292 ./prep_dataset/ILSVRC2012_val_00034339.bin 224 224 +42293 ./prep_dataset/ILSVRC2012_val_00026778.bin 224 224 +42294 ./prep_dataset/ILSVRC2012_val_00047398.bin 224 224 +42295 ./prep_dataset/ILSVRC2012_val_00042735.bin 224 224 +42296 ./prep_dataset/ILSVRC2012_val_00043535.bin 224 224 +42297 ./prep_dataset/ILSVRC2012_val_00042405.bin 224 224 +42298 ./prep_dataset/ILSVRC2012_val_00000467.bin 224 224 +42299 ./prep_dataset/ILSVRC2012_val_00026329.bin 224 224 +42300 ./prep_dataset/ILSVRC2012_val_00017704.bin 224 224 +42301 ./prep_dataset/ILSVRC2012_val_00004814.bin 224 224 +42302 ./prep_dataset/ILSVRC2012_val_00037766.bin 224 224 +42303 ./prep_dataset/ILSVRC2012_val_00033724.bin 224 224 +42304 ./prep_dataset/ILSVRC2012_val_00038222.bin 224 224 +42305 ./prep_dataset/ILSVRC2012_val_00042879.bin 224 224 +42306 ./prep_dataset/ILSVRC2012_val_00038934.bin 224 224 +42307 ./prep_dataset/ILSVRC2012_val_00035575.bin 224 224 +42308 ./prep_dataset/ILSVRC2012_val_00005619.bin 224 224 +42309 ./prep_dataset/ILSVRC2012_val_00020987.bin 224 224 +42310 ./prep_dataset/ILSVRC2012_val_00039768.bin 224 224 +42311 ./prep_dataset/ILSVRC2012_val_00005000.bin 224 224 +42312 ./prep_dataset/ILSVRC2012_val_00022699.bin 224 224 +42313 ./prep_dataset/ILSVRC2012_val_00017518.bin 224 224 +42314 ./prep_dataset/ILSVRC2012_val_00011747.bin 224 224 +42315 ./prep_dataset/ILSVRC2012_val_00015686.bin 224 224 +42316 ./prep_dataset/ILSVRC2012_val_00038668.bin 224 224 +42317 ./prep_dataset/ILSVRC2012_val_00045460.bin 224 224 +42318 ./prep_dataset/ILSVRC2012_val_00003273.bin 224 224 +42319 ./prep_dataset/ILSVRC2012_val_00019683.bin 224 224 +42320 ./prep_dataset/ILSVRC2012_val_00030760.bin 224 224 +42321 ./prep_dataset/ILSVRC2012_val_00049093.bin 224 224 +42322 ./prep_dataset/ILSVRC2012_val_00048048.bin 224 224 +42323 ./prep_dataset/ILSVRC2012_val_00000922.bin 224 224 +42324 ./prep_dataset/ILSVRC2012_val_00013188.bin 224 224 +42325 ./prep_dataset/ILSVRC2012_val_00003241.bin 224 224 +42326 ./prep_dataset/ILSVRC2012_val_00039859.bin 224 224 +42327 ./prep_dataset/ILSVRC2012_val_00015856.bin 224 224 +42328 ./prep_dataset/ILSVRC2012_val_00015451.bin 224 224 +42329 ./prep_dataset/ILSVRC2012_val_00048950.bin 224 224 +42330 ./prep_dataset/ILSVRC2012_val_00034425.bin 224 224 +42331 ./prep_dataset/ILSVRC2012_val_00046141.bin 224 224 +42332 ./prep_dataset/ILSVRC2012_val_00007954.bin 224 224 +42333 ./prep_dataset/ILSVRC2012_val_00030091.bin 224 224 +42334 ./prep_dataset/ILSVRC2012_val_00029017.bin 224 224 +42335 ./prep_dataset/ILSVRC2012_val_00011067.bin 224 224 +42336 ./prep_dataset/ILSVRC2012_val_00043804.bin 224 224 +42337 ./prep_dataset/ILSVRC2012_val_00037052.bin 224 224 +42338 ./prep_dataset/ILSVRC2012_val_00039153.bin 224 224 +42339 ./prep_dataset/ILSVRC2012_val_00038640.bin 224 224 +42340 ./prep_dataset/ILSVRC2012_val_00026730.bin 224 224 +42341 ./prep_dataset/ILSVRC2012_val_00028541.bin 224 224 +42342 ./prep_dataset/ILSVRC2012_val_00001982.bin 224 224 +42343 ./prep_dataset/ILSVRC2012_val_00046730.bin 224 224 +42344 ./prep_dataset/ILSVRC2012_val_00031725.bin 224 224 +42345 ./prep_dataset/ILSVRC2012_val_00046107.bin 224 224 +42346 ./prep_dataset/ILSVRC2012_val_00022823.bin 224 224 +42347 ./prep_dataset/ILSVRC2012_val_00024599.bin 224 224 +42348 ./prep_dataset/ILSVRC2012_val_00033659.bin 224 224 +42349 ./prep_dataset/ILSVRC2012_val_00041946.bin 224 224 +42350 ./prep_dataset/ILSVRC2012_val_00044440.bin 224 224 +42351 ./prep_dataset/ILSVRC2012_val_00049466.bin 224 224 +42352 ./prep_dataset/ILSVRC2012_val_00011130.bin 224 224 +42353 ./prep_dataset/ILSVRC2012_val_00029196.bin 224 224 +42354 ./prep_dataset/ILSVRC2012_val_00047397.bin 224 224 +42355 ./prep_dataset/ILSVRC2012_val_00036236.bin 224 224 +42356 ./prep_dataset/ILSVRC2012_val_00023106.bin 224 224 +42357 ./prep_dataset/ILSVRC2012_val_00038405.bin 224 224 +42358 ./prep_dataset/ILSVRC2012_val_00017178.bin 224 224 +42359 ./prep_dataset/ILSVRC2012_val_00017352.bin 224 224 +42360 ./prep_dataset/ILSVRC2012_val_00045622.bin 224 224 +42361 ./prep_dataset/ILSVRC2012_val_00043924.bin 224 224 +42362 ./prep_dataset/ILSVRC2012_val_00013622.bin 224 224 +42363 ./prep_dataset/ILSVRC2012_val_00031542.bin 224 224 +42364 ./prep_dataset/ILSVRC2012_val_00042204.bin 224 224 +42365 ./prep_dataset/ILSVRC2012_val_00026893.bin 224 224 +42366 ./prep_dataset/ILSVRC2012_val_00024451.bin 224 224 +42367 ./prep_dataset/ILSVRC2012_val_00023729.bin 224 224 +42368 ./prep_dataset/ILSVRC2012_val_00025578.bin 224 224 +42369 ./prep_dataset/ILSVRC2012_val_00038847.bin 224 224 +42370 ./prep_dataset/ILSVRC2012_val_00004871.bin 224 224 +42371 ./prep_dataset/ILSVRC2012_val_00033458.bin 224 224 +42372 ./prep_dataset/ILSVRC2012_val_00047581.bin 224 224 +42373 ./prep_dataset/ILSVRC2012_val_00035079.bin 224 224 +42374 ./prep_dataset/ILSVRC2012_val_00005594.bin 224 224 +42375 ./prep_dataset/ILSVRC2012_val_00047853.bin 224 224 +42376 ./prep_dataset/ILSVRC2012_val_00015033.bin 224 224 +42377 ./prep_dataset/ILSVRC2012_val_00045429.bin 224 224 +42378 ./prep_dataset/ILSVRC2012_val_00010396.bin 224 224 +42379 ./prep_dataset/ILSVRC2012_val_00022440.bin 224 224 +42380 ./prep_dataset/ILSVRC2012_val_00049884.bin 224 224 +42381 ./prep_dataset/ILSVRC2012_val_00040283.bin 224 224 +42382 ./prep_dataset/ILSVRC2012_val_00031607.bin 224 224 +42383 ./prep_dataset/ILSVRC2012_val_00012019.bin 224 224 +42384 ./prep_dataset/ILSVRC2012_val_00037411.bin 224 224 +42385 ./prep_dataset/ILSVRC2012_val_00022869.bin 224 224 +42386 ./prep_dataset/ILSVRC2012_val_00012880.bin 224 224 +42387 ./prep_dataset/ILSVRC2012_val_00024598.bin 224 224 +42388 ./prep_dataset/ILSVRC2012_val_00004259.bin 224 224 +42389 ./prep_dataset/ILSVRC2012_val_00045934.bin 224 224 +42390 ./prep_dataset/ILSVRC2012_val_00025682.bin 224 224 +42391 ./prep_dataset/ILSVRC2012_val_00024249.bin 224 224 +42392 ./prep_dataset/ILSVRC2012_val_00011490.bin 224 224 +42393 ./prep_dataset/ILSVRC2012_val_00035423.bin 224 224 +42394 ./prep_dataset/ILSVRC2012_val_00010827.bin 224 224 +42395 ./prep_dataset/ILSVRC2012_val_00023522.bin 224 224 +42396 ./prep_dataset/ILSVRC2012_val_00049118.bin 224 224 +42397 ./prep_dataset/ILSVRC2012_val_00014342.bin 224 224 +42398 ./prep_dataset/ILSVRC2012_val_00042228.bin 224 224 +42399 ./prep_dataset/ILSVRC2012_val_00023710.bin 224 224 +42400 ./prep_dataset/ILSVRC2012_val_00034283.bin 224 224 +42401 ./prep_dataset/ILSVRC2012_val_00015601.bin 224 224 +42402 ./prep_dataset/ILSVRC2012_val_00012118.bin 224 224 +42403 ./prep_dataset/ILSVRC2012_val_00000459.bin 224 224 +42404 ./prep_dataset/ILSVRC2012_val_00046912.bin 224 224 +42405 ./prep_dataset/ILSVRC2012_val_00042234.bin 224 224 +42406 ./prep_dataset/ILSVRC2012_val_00029259.bin 224 224 +42407 ./prep_dataset/ILSVRC2012_val_00014785.bin 224 224 +42408 ./prep_dataset/ILSVRC2012_val_00034331.bin 224 224 +42409 ./prep_dataset/ILSVRC2012_val_00042269.bin 224 224 +42410 ./prep_dataset/ILSVRC2012_val_00034075.bin 224 224 +42411 ./prep_dataset/ILSVRC2012_val_00049172.bin 224 224 +42412 ./prep_dataset/ILSVRC2012_val_00002773.bin 224 224 +42413 ./prep_dataset/ILSVRC2012_val_00044100.bin 224 224 +42414 ./prep_dataset/ILSVRC2012_val_00029880.bin 224 224 +42415 ./prep_dataset/ILSVRC2012_val_00043205.bin 224 224 +42416 ./prep_dataset/ILSVRC2012_val_00038589.bin 224 224 +42417 ./prep_dataset/ILSVRC2012_val_00046839.bin 224 224 +42418 ./prep_dataset/ILSVRC2012_val_00019648.bin 224 224 +42419 ./prep_dataset/ILSVRC2012_val_00016557.bin 224 224 +42420 ./prep_dataset/ILSVRC2012_val_00029236.bin 224 224 +42421 ./prep_dataset/ILSVRC2012_val_00032107.bin 224 224 +42422 ./prep_dataset/ILSVRC2012_val_00047969.bin 224 224 +42423 ./prep_dataset/ILSVRC2012_val_00039596.bin 224 224 +42424 ./prep_dataset/ILSVRC2012_val_00039204.bin 224 224 +42425 ./prep_dataset/ILSVRC2012_val_00005798.bin 224 224 +42426 ./prep_dataset/ILSVRC2012_val_00001735.bin 224 224 +42427 ./prep_dataset/ILSVRC2012_val_00043966.bin 224 224 +42428 ./prep_dataset/ILSVRC2012_val_00046540.bin 224 224 +42429 ./prep_dataset/ILSVRC2012_val_00034407.bin 224 224 +42430 ./prep_dataset/ILSVRC2012_val_00027226.bin 224 224 +42431 ./prep_dataset/ILSVRC2012_val_00020441.bin 224 224 +42432 ./prep_dataset/ILSVRC2012_val_00030131.bin 224 224 +42433 ./prep_dataset/ILSVRC2012_val_00043664.bin 224 224 +42434 ./prep_dataset/ILSVRC2012_val_00020993.bin 224 224 +42435 ./prep_dataset/ILSVRC2012_val_00025485.bin 224 224 +42436 ./prep_dataset/ILSVRC2012_val_00004213.bin 224 224 +42437 ./prep_dataset/ILSVRC2012_val_00018808.bin 224 224 +42438 ./prep_dataset/ILSVRC2012_val_00041173.bin 224 224 +42439 ./prep_dataset/ILSVRC2012_val_00016576.bin 224 224 +42440 ./prep_dataset/ILSVRC2012_val_00033266.bin 224 224 +42441 ./prep_dataset/ILSVRC2012_val_00018250.bin 224 224 +42442 ./prep_dataset/ILSVRC2012_val_00042167.bin 224 224 +42443 ./prep_dataset/ILSVRC2012_val_00023649.bin 224 224 +42444 ./prep_dataset/ILSVRC2012_val_00028273.bin 224 224 +42445 ./prep_dataset/ILSVRC2012_val_00021172.bin 224 224 +42446 ./prep_dataset/ILSVRC2012_val_00028161.bin 224 224 +42447 ./prep_dataset/ILSVRC2012_val_00003906.bin 224 224 +42448 ./prep_dataset/ILSVRC2012_val_00044590.bin 224 224 +42449 ./prep_dataset/ILSVRC2012_val_00002784.bin 224 224 +42450 ./prep_dataset/ILSVRC2012_val_00033019.bin 224 224 +42451 ./prep_dataset/ILSVRC2012_val_00038606.bin 224 224 +42452 ./prep_dataset/ILSVRC2012_val_00022976.bin 224 224 +42453 ./prep_dataset/ILSVRC2012_val_00033888.bin 224 224 +42454 ./prep_dataset/ILSVRC2012_val_00010487.bin 224 224 +42455 ./prep_dataset/ILSVRC2012_val_00043216.bin 224 224 +42456 ./prep_dataset/ILSVRC2012_val_00035273.bin 224 224 +42457 ./prep_dataset/ILSVRC2012_val_00040503.bin 224 224 +42458 ./prep_dataset/ILSVRC2012_val_00029666.bin 224 224 +42459 ./prep_dataset/ILSVRC2012_val_00042059.bin 224 224 +42460 ./prep_dataset/ILSVRC2012_val_00017691.bin 224 224 +42461 ./prep_dataset/ILSVRC2012_val_00015180.bin 224 224 +42462 ./prep_dataset/ILSVRC2012_val_00044434.bin 224 224 +42463 ./prep_dataset/ILSVRC2012_val_00039966.bin 224 224 +42464 ./prep_dataset/ILSVRC2012_val_00037104.bin 224 224 +42465 ./prep_dataset/ILSVRC2012_val_00042821.bin 224 224 +42466 ./prep_dataset/ILSVRC2012_val_00042849.bin 224 224 +42467 ./prep_dataset/ILSVRC2012_val_00047900.bin 224 224 +42468 ./prep_dataset/ILSVRC2012_val_00020225.bin 224 224 +42469 ./prep_dataset/ILSVRC2012_val_00031869.bin 224 224 +42470 ./prep_dataset/ILSVRC2012_val_00002831.bin 224 224 +42471 ./prep_dataset/ILSVRC2012_val_00019935.bin 224 224 +42472 ./prep_dataset/ILSVRC2012_val_00018624.bin 224 224 +42473 ./prep_dataset/ILSVRC2012_val_00010186.bin 224 224 +42474 ./prep_dataset/ILSVRC2012_val_00028424.bin 224 224 +42475 ./prep_dataset/ILSVRC2012_val_00028702.bin 224 224 +42476 ./prep_dataset/ILSVRC2012_val_00040755.bin 224 224 +42477 ./prep_dataset/ILSVRC2012_val_00049736.bin 224 224 +42478 ./prep_dataset/ILSVRC2012_val_00027134.bin 224 224 +42479 ./prep_dataset/ILSVRC2012_val_00018408.bin 224 224 +42480 ./prep_dataset/ILSVRC2012_val_00033626.bin 224 224 +42481 ./prep_dataset/ILSVRC2012_val_00041485.bin 224 224 +42482 ./prep_dataset/ILSVRC2012_val_00009428.bin 224 224 +42483 ./prep_dataset/ILSVRC2012_val_00021391.bin 224 224 +42484 ./prep_dataset/ILSVRC2012_val_00023199.bin 224 224 +42485 ./prep_dataset/ILSVRC2012_val_00009119.bin 224 224 +42486 ./prep_dataset/ILSVRC2012_val_00021195.bin 224 224 +42487 ./prep_dataset/ILSVRC2012_val_00019354.bin 224 224 +42488 ./prep_dataset/ILSVRC2012_val_00032802.bin 224 224 +42489 ./prep_dataset/ILSVRC2012_val_00018357.bin 224 224 +42490 ./prep_dataset/ILSVRC2012_val_00016677.bin 224 224 +42491 ./prep_dataset/ILSVRC2012_val_00031918.bin 224 224 +42492 ./prep_dataset/ILSVRC2012_val_00049768.bin 224 224 +42493 ./prep_dataset/ILSVRC2012_val_00016430.bin 224 224 +42494 ./prep_dataset/ILSVRC2012_val_00015166.bin 224 224 +42495 ./prep_dataset/ILSVRC2012_val_00002235.bin 224 224 +42496 ./prep_dataset/ILSVRC2012_val_00020372.bin 224 224 +42497 ./prep_dataset/ILSVRC2012_val_00031486.bin 224 224 +42498 ./prep_dataset/ILSVRC2012_val_00024879.bin 224 224 +42499 ./prep_dataset/ILSVRC2012_val_00013829.bin 224 224 +42500 ./prep_dataset/ILSVRC2012_val_00011006.bin 224 224 +42501 ./prep_dataset/ILSVRC2012_val_00046830.bin 224 224 +42502 ./prep_dataset/ILSVRC2012_val_00001507.bin 224 224 +42503 ./prep_dataset/ILSVRC2012_val_00022390.bin 224 224 +42504 ./prep_dataset/ILSVRC2012_val_00013163.bin 224 224 +42505 ./prep_dataset/ILSVRC2012_val_00031013.bin 224 224 +42506 ./prep_dataset/ILSVRC2012_val_00035371.bin 224 224 +42507 ./prep_dataset/ILSVRC2012_val_00047508.bin 224 224 +42508 ./prep_dataset/ILSVRC2012_val_00034092.bin 224 224 +42509 ./prep_dataset/ILSVRC2012_val_00046642.bin 224 224 +42510 ./prep_dataset/ILSVRC2012_val_00023901.bin 224 224 +42511 ./prep_dataset/ILSVRC2012_val_00014667.bin 224 224 +42512 ./prep_dataset/ILSVRC2012_val_00008841.bin 224 224 +42513 ./prep_dataset/ILSVRC2012_val_00031983.bin 224 224 +42514 ./prep_dataset/ILSVRC2012_val_00023587.bin 224 224 +42515 ./prep_dataset/ILSVRC2012_val_00000900.bin 224 224 +42516 ./prep_dataset/ILSVRC2012_val_00041461.bin 224 224 +42517 ./prep_dataset/ILSVRC2012_val_00005563.bin 224 224 +42518 ./prep_dataset/ILSVRC2012_val_00035551.bin 224 224 +42519 ./prep_dataset/ILSVRC2012_val_00000613.bin 224 224 +42520 ./prep_dataset/ILSVRC2012_val_00035596.bin 224 224 +42521 ./prep_dataset/ILSVRC2012_val_00025083.bin 224 224 +42522 ./prep_dataset/ILSVRC2012_val_00007864.bin 224 224 +42523 ./prep_dataset/ILSVRC2012_val_00026502.bin 224 224 +42524 ./prep_dataset/ILSVRC2012_val_00021119.bin 224 224 +42525 ./prep_dataset/ILSVRC2012_val_00033906.bin 224 224 +42526 ./prep_dataset/ILSVRC2012_val_00025820.bin 224 224 +42527 ./prep_dataset/ILSVRC2012_val_00022639.bin 224 224 +42528 ./prep_dataset/ILSVRC2012_val_00002189.bin 224 224 +42529 ./prep_dataset/ILSVRC2012_val_00023159.bin 224 224 +42530 ./prep_dataset/ILSVRC2012_val_00000849.bin 224 224 +42531 ./prep_dataset/ILSVRC2012_val_00031957.bin 224 224 +42532 ./prep_dataset/ILSVRC2012_val_00046216.bin 224 224 +42533 ./prep_dataset/ILSVRC2012_val_00046684.bin 224 224 +42534 ./prep_dataset/ILSVRC2012_val_00046566.bin 224 224 +42535 ./prep_dataset/ILSVRC2012_val_00020301.bin 224 224 +42536 ./prep_dataset/ILSVRC2012_val_00028184.bin 224 224 +42537 ./prep_dataset/ILSVRC2012_val_00023364.bin 224 224 +42538 ./prep_dataset/ILSVRC2012_val_00016220.bin 224 224 +42539 ./prep_dataset/ILSVRC2012_val_00012074.bin 224 224 +42540 ./prep_dataset/ILSVRC2012_val_00026533.bin 224 224 +42541 ./prep_dataset/ILSVRC2012_val_00043306.bin 224 224 +42542 ./prep_dataset/ILSVRC2012_val_00013930.bin 224 224 +42543 ./prep_dataset/ILSVRC2012_val_00030038.bin 224 224 +42544 ./prep_dataset/ILSVRC2012_val_00046789.bin 224 224 +42545 ./prep_dataset/ILSVRC2012_val_00036680.bin 224 224 +42546 ./prep_dataset/ILSVRC2012_val_00017294.bin 224 224 +42547 ./prep_dataset/ILSVRC2012_val_00044526.bin 224 224 +42548 ./prep_dataset/ILSVRC2012_val_00027646.bin 224 224 +42549 ./prep_dataset/ILSVRC2012_val_00029749.bin 224 224 +42550 ./prep_dataset/ILSVRC2012_val_00025868.bin 224 224 +42551 ./prep_dataset/ILSVRC2012_val_00024421.bin 224 224 +42552 ./prep_dataset/ILSVRC2012_val_00002550.bin 224 224 +42553 ./prep_dataset/ILSVRC2012_val_00009082.bin 224 224 +42554 ./prep_dataset/ILSVRC2012_val_00024682.bin 224 224 +42555 ./prep_dataset/ILSVRC2012_val_00022925.bin 224 224 +42556 ./prep_dataset/ILSVRC2012_val_00016115.bin 224 224 +42557 ./prep_dataset/ILSVRC2012_val_00010283.bin 224 224 +42558 ./prep_dataset/ILSVRC2012_val_00037450.bin 224 224 +42559 ./prep_dataset/ILSVRC2012_val_00014780.bin 224 224 +42560 ./prep_dataset/ILSVRC2012_val_00044268.bin 224 224 +42561 ./prep_dataset/ILSVRC2012_val_00019048.bin 224 224 +42562 ./prep_dataset/ILSVRC2012_val_00002729.bin 224 224 +42563 ./prep_dataset/ILSVRC2012_val_00032325.bin 224 224 +42564 ./prep_dataset/ILSVRC2012_val_00003784.bin 224 224 +42565 ./prep_dataset/ILSVRC2012_val_00013492.bin 224 224 +42566 ./prep_dataset/ILSVRC2012_val_00048871.bin 224 224 +42567 ./prep_dataset/ILSVRC2012_val_00033137.bin 224 224 +42568 ./prep_dataset/ILSVRC2012_val_00039700.bin 224 224 +42569 ./prep_dataset/ILSVRC2012_val_00044271.bin 224 224 +42570 ./prep_dataset/ILSVRC2012_val_00033709.bin 224 224 +42571 ./prep_dataset/ILSVRC2012_val_00030294.bin 224 224 +42572 ./prep_dataset/ILSVRC2012_val_00044489.bin 224 224 +42573 ./prep_dataset/ILSVRC2012_val_00038233.bin 224 224 +42574 ./prep_dataset/ILSVRC2012_val_00016225.bin 224 224 +42575 ./prep_dataset/ILSVRC2012_val_00011025.bin 224 224 +42576 ./prep_dataset/ILSVRC2012_val_00031627.bin 224 224 +42577 ./prep_dataset/ILSVRC2012_val_00015383.bin 224 224 +42578 ./prep_dataset/ILSVRC2012_val_00025010.bin 224 224 +42579 ./prep_dataset/ILSVRC2012_val_00037385.bin 224 224 +42580 ./prep_dataset/ILSVRC2012_val_00026867.bin 224 224 +42581 ./prep_dataset/ILSVRC2012_val_00030979.bin 224 224 +42582 ./prep_dataset/ILSVRC2012_val_00008090.bin 224 224 +42583 ./prep_dataset/ILSVRC2012_val_00018225.bin 224 224 +42584 ./prep_dataset/ILSVRC2012_val_00014038.bin 224 224 +42585 ./prep_dataset/ILSVRC2012_val_00016954.bin 224 224 +42586 ./prep_dataset/ILSVRC2012_val_00046541.bin 224 224 +42587 ./prep_dataset/ILSVRC2012_val_00016097.bin 224 224 +42588 ./prep_dataset/ILSVRC2012_val_00016704.bin 224 224 +42589 ./prep_dataset/ILSVRC2012_val_00027355.bin 224 224 +42590 ./prep_dataset/ILSVRC2012_val_00012702.bin 224 224 +42591 ./prep_dataset/ILSVRC2012_val_00023267.bin 224 224 +42592 ./prep_dataset/ILSVRC2012_val_00044655.bin 224 224 +42593 ./prep_dataset/ILSVRC2012_val_00049583.bin 224 224 +42594 ./prep_dataset/ILSVRC2012_val_00046386.bin 224 224 +42595 ./prep_dataset/ILSVRC2012_val_00027532.bin 224 224 +42596 ./prep_dataset/ILSVRC2012_val_00029564.bin 224 224 +42597 ./prep_dataset/ILSVRC2012_val_00026681.bin 224 224 +42598 ./prep_dataset/ILSVRC2012_val_00034777.bin 224 224 +42599 ./prep_dataset/ILSVRC2012_val_00008101.bin 224 224 +42600 ./prep_dataset/ILSVRC2012_val_00017228.bin 224 224 +42601 ./prep_dataset/ILSVRC2012_val_00008276.bin 224 224 +42602 ./prep_dataset/ILSVRC2012_val_00015668.bin 224 224 +42603 ./prep_dataset/ILSVRC2012_val_00017485.bin 224 224 +42604 ./prep_dataset/ILSVRC2012_val_00015984.bin 224 224 +42605 ./prep_dataset/ILSVRC2012_val_00016036.bin 224 224 +42606 ./prep_dataset/ILSVRC2012_val_00035209.bin 224 224 +42607 ./prep_dataset/ILSVRC2012_val_00047683.bin 224 224 +42608 ./prep_dataset/ILSVRC2012_val_00011791.bin 224 224 +42609 ./prep_dataset/ILSVRC2012_val_00009920.bin 224 224 +42610 ./prep_dataset/ILSVRC2012_val_00015268.bin 224 224 +42611 ./prep_dataset/ILSVRC2012_val_00007136.bin 224 224 +42612 ./prep_dataset/ILSVRC2012_val_00028965.bin 224 224 +42613 ./prep_dataset/ILSVRC2012_val_00046477.bin 224 224 +42614 ./prep_dataset/ILSVRC2012_val_00007528.bin 224 224 +42615 ./prep_dataset/ILSVRC2012_val_00035812.bin 224 224 +42616 ./prep_dataset/ILSVRC2012_val_00012023.bin 224 224 +42617 ./prep_dataset/ILSVRC2012_val_00015012.bin 224 224 +42618 ./prep_dataset/ILSVRC2012_val_00002701.bin 224 224 +42619 ./prep_dataset/ILSVRC2012_val_00027019.bin 224 224 +42620 ./prep_dataset/ILSVRC2012_val_00041162.bin 224 224 +42621 ./prep_dataset/ILSVRC2012_val_00013943.bin 224 224 +42622 ./prep_dataset/ILSVRC2012_val_00041431.bin 224 224 +42623 ./prep_dataset/ILSVRC2012_val_00037944.bin 224 224 +42624 ./prep_dataset/ILSVRC2012_val_00041672.bin 224 224 +42625 ./prep_dataset/ILSVRC2012_val_00024819.bin 224 224 +42626 ./prep_dataset/ILSVRC2012_val_00005494.bin 224 224 +42627 ./prep_dataset/ILSVRC2012_val_00037950.bin 224 224 +42628 ./prep_dataset/ILSVRC2012_val_00030367.bin 224 224 +42629 ./prep_dataset/ILSVRC2012_val_00010379.bin 224 224 +42630 ./prep_dataset/ILSVRC2012_val_00021627.bin 224 224 +42631 ./prep_dataset/ILSVRC2012_val_00047517.bin 224 224 +42632 ./prep_dataset/ILSVRC2012_val_00001425.bin 224 224 +42633 ./prep_dataset/ILSVRC2012_val_00002209.bin 224 224 +42634 ./prep_dataset/ILSVRC2012_val_00013497.bin 224 224 +42635 ./prep_dataset/ILSVRC2012_val_00032652.bin 224 224 +42636 ./prep_dataset/ILSVRC2012_val_00012258.bin 224 224 +42637 ./prep_dataset/ILSVRC2012_val_00043081.bin 224 224 +42638 ./prep_dataset/ILSVRC2012_val_00000990.bin 224 224 +42639 ./prep_dataset/ILSVRC2012_val_00037610.bin 224 224 +42640 ./prep_dataset/ILSVRC2012_val_00041019.bin 224 224 +42641 ./prep_dataset/ILSVRC2012_val_00008475.bin 224 224 +42642 ./prep_dataset/ILSVRC2012_val_00013629.bin 224 224 +42643 ./prep_dataset/ILSVRC2012_val_00021613.bin 224 224 +42644 ./prep_dataset/ILSVRC2012_val_00001933.bin 224 224 +42645 ./prep_dataset/ILSVRC2012_val_00001492.bin 224 224 +42646 ./prep_dataset/ILSVRC2012_val_00011597.bin 224 224 +42647 ./prep_dataset/ILSVRC2012_val_00014955.bin 224 224 +42648 ./prep_dataset/ILSVRC2012_val_00019936.bin 224 224 +42649 ./prep_dataset/ILSVRC2012_val_00037652.bin 224 224 +42650 ./prep_dataset/ILSVRC2012_val_00021734.bin 224 224 +42651 ./prep_dataset/ILSVRC2012_val_00013432.bin 224 224 +42652 ./prep_dataset/ILSVRC2012_val_00039007.bin 224 224 +42653 ./prep_dataset/ILSVRC2012_val_00006078.bin 224 224 +42654 ./prep_dataset/ILSVRC2012_val_00021689.bin 224 224 +42655 ./prep_dataset/ILSVRC2012_val_00045155.bin 224 224 +42656 ./prep_dataset/ILSVRC2012_val_00034763.bin 224 224 +42657 ./prep_dataset/ILSVRC2012_val_00044323.bin 224 224 +42658 ./prep_dataset/ILSVRC2012_val_00035535.bin 224 224 +42659 ./prep_dataset/ILSVRC2012_val_00020846.bin 224 224 +42660 ./prep_dataset/ILSVRC2012_val_00048550.bin 224 224 +42661 ./prep_dataset/ILSVRC2012_val_00008598.bin 224 224 +42662 ./prep_dataset/ILSVRC2012_val_00029697.bin 224 224 +42663 ./prep_dataset/ILSVRC2012_val_00000373.bin 224 224 +42664 ./prep_dataset/ILSVRC2012_val_00011874.bin 224 224 +42665 ./prep_dataset/ILSVRC2012_val_00011049.bin 224 224 +42666 ./prep_dataset/ILSVRC2012_val_00044343.bin 224 224 +42667 ./prep_dataset/ILSVRC2012_val_00010863.bin 224 224 +42668 ./prep_dataset/ILSVRC2012_val_00031106.bin 224 224 +42669 ./prep_dataset/ILSVRC2012_val_00049368.bin 224 224 +42670 ./prep_dataset/ILSVRC2012_val_00026926.bin 224 224 +42671 ./prep_dataset/ILSVRC2012_val_00030534.bin 224 224 +42672 ./prep_dataset/ILSVRC2012_val_00039138.bin 224 224 +42673 ./prep_dataset/ILSVRC2012_val_00005783.bin 224 224 +42674 ./prep_dataset/ILSVRC2012_val_00001853.bin 224 224 +42675 ./prep_dataset/ILSVRC2012_val_00006099.bin 224 224 +42676 ./prep_dataset/ILSVRC2012_val_00029879.bin 224 224 +42677 ./prep_dataset/ILSVRC2012_val_00002129.bin 224 224 +42678 ./prep_dataset/ILSVRC2012_val_00010428.bin 224 224 +42679 ./prep_dataset/ILSVRC2012_val_00042834.bin 224 224 +42680 ./prep_dataset/ILSVRC2012_val_00025579.bin 224 224 +42681 ./prep_dataset/ILSVRC2012_val_00046153.bin 224 224 +42682 ./prep_dataset/ILSVRC2012_val_00010730.bin 224 224 +42683 ./prep_dataset/ILSVRC2012_val_00032208.bin 224 224 +42684 ./prep_dataset/ILSVRC2012_val_00033218.bin 224 224 +42685 ./prep_dataset/ILSVRC2012_val_00005095.bin 224 224 +42686 ./prep_dataset/ILSVRC2012_val_00043132.bin 224 224 +42687 ./prep_dataset/ILSVRC2012_val_00018434.bin 224 224 +42688 ./prep_dataset/ILSVRC2012_val_00039218.bin 224 224 +42689 ./prep_dataset/ILSVRC2012_val_00030566.bin 224 224 +42690 ./prep_dataset/ILSVRC2012_val_00024826.bin 224 224 +42691 ./prep_dataset/ILSVRC2012_val_00047069.bin 224 224 +42692 ./prep_dataset/ILSVRC2012_val_00005187.bin 224 224 +42693 ./prep_dataset/ILSVRC2012_val_00039084.bin 224 224 +42694 ./prep_dataset/ILSVRC2012_val_00037075.bin 224 224 +42695 ./prep_dataset/ILSVRC2012_val_00011241.bin 224 224 +42696 ./prep_dataset/ILSVRC2012_val_00010687.bin 224 224 +42697 ./prep_dataset/ILSVRC2012_val_00004555.bin 224 224 +42698 ./prep_dataset/ILSVRC2012_val_00034715.bin 224 224 +42699 ./prep_dataset/ILSVRC2012_val_00000899.bin 224 224 +42700 ./prep_dataset/ILSVRC2012_val_00010944.bin 224 224 +42701 ./prep_dataset/ILSVRC2012_val_00010792.bin 224 224 +42702 ./prep_dataset/ILSVRC2012_val_00007820.bin 224 224 +42703 ./prep_dataset/ILSVRC2012_val_00002222.bin 224 224 +42704 ./prep_dataset/ILSVRC2012_val_00010816.bin 224 224 +42705 ./prep_dataset/ILSVRC2012_val_00036832.bin 224 224 +42706 ./prep_dataset/ILSVRC2012_val_00005487.bin 224 224 +42707 ./prep_dataset/ILSVRC2012_val_00009743.bin 224 224 +42708 ./prep_dataset/ILSVRC2012_val_00026311.bin 224 224 +42709 ./prep_dataset/ILSVRC2012_val_00015774.bin 224 224 +42710 ./prep_dataset/ILSVRC2012_val_00036877.bin 224 224 +42711 ./prep_dataset/ILSVRC2012_val_00017936.bin 224 224 +42712 ./prep_dataset/ILSVRC2012_val_00034104.bin 224 224 +42713 ./prep_dataset/ILSVRC2012_val_00043721.bin 224 224 +42714 ./prep_dataset/ILSVRC2012_val_00036861.bin 224 224 +42715 ./prep_dataset/ILSVRC2012_val_00011279.bin 224 224 +42716 ./prep_dataset/ILSVRC2012_val_00022334.bin 224 224 +42717 ./prep_dataset/ILSVRC2012_val_00037890.bin 224 224 +42718 ./prep_dataset/ILSVRC2012_val_00026198.bin 224 224 +42719 ./prep_dataset/ILSVRC2012_val_00021434.bin 224 224 +42720 ./prep_dataset/ILSVRC2012_val_00041529.bin 224 224 +42721 ./prep_dataset/ILSVRC2012_val_00013458.bin 224 224 +42722 ./prep_dataset/ILSVRC2012_val_00009880.bin 224 224 +42723 ./prep_dataset/ILSVRC2012_val_00049920.bin 224 224 +42724 ./prep_dataset/ILSVRC2012_val_00045427.bin 224 224 +42725 ./prep_dataset/ILSVRC2012_val_00026578.bin 224 224 +42726 ./prep_dataset/ILSVRC2012_val_00047543.bin 224 224 +42727 ./prep_dataset/ILSVRC2012_val_00034821.bin 224 224 +42728 ./prep_dataset/ILSVRC2012_val_00017410.bin 224 224 +42729 ./prep_dataset/ILSVRC2012_val_00036295.bin 224 224 +42730 ./prep_dataset/ILSVRC2012_val_00034550.bin 224 224 +42731 ./prep_dataset/ILSVRC2012_val_00003456.bin 224 224 +42732 ./prep_dataset/ILSVRC2012_val_00043190.bin 224 224 +42733 ./prep_dataset/ILSVRC2012_val_00020434.bin 224 224 +42734 ./prep_dataset/ILSVRC2012_val_00010677.bin 224 224 +42735 ./prep_dataset/ILSVRC2012_val_00049188.bin 224 224 +42736 ./prep_dataset/ILSVRC2012_val_00029415.bin 224 224 +42737 ./prep_dataset/ILSVRC2012_val_00001475.bin 224 224 +42738 ./prep_dataset/ILSVRC2012_val_00031653.bin 224 224 +42739 ./prep_dataset/ILSVRC2012_val_00030940.bin 224 224 +42740 ./prep_dataset/ILSVRC2012_val_00043704.bin 224 224 +42741 ./prep_dataset/ILSVRC2012_val_00013021.bin 224 224 +42742 ./prep_dataset/ILSVRC2012_val_00042370.bin 224 224 +42743 ./prep_dataset/ILSVRC2012_val_00041556.bin 224 224 +42744 ./prep_dataset/ILSVRC2012_val_00025460.bin 224 224 +42745 ./prep_dataset/ILSVRC2012_val_00034201.bin 224 224 +42746 ./prep_dataset/ILSVRC2012_val_00009042.bin 224 224 +42747 ./prep_dataset/ILSVRC2012_val_00015803.bin 224 224 +42748 ./prep_dataset/ILSVRC2012_val_00042935.bin 224 224 +42749 ./prep_dataset/ILSVRC2012_val_00021622.bin 224 224 +42750 ./prep_dataset/ILSVRC2012_val_00009820.bin 224 224 +42751 ./prep_dataset/ILSVRC2012_val_00035002.bin 224 224 +42752 ./prep_dataset/ILSVRC2012_val_00036589.bin 224 224 +42753 ./prep_dataset/ILSVRC2012_val_00007541.bin 224 224 +42754 ./prep_dataset/ILSVRC2012_val_00031714.bin 224 224 +42755 ./prep_dataset/ILSVRC2012_val_00016072.bin 224 224 +42756 ./prep_dataset/ILSVRC2012_val_00028869.bin 224 224 +42757 ./prep_dataset/ILSVRC2012_val_00045833.bin 224 224 +42758 ./prep_dataset/ILSVRC2012_val_00031614.bin 224 224 +42759 ./prep_dataset/ILSVRC2012_val_00032193.bin 224 224 +42760 ./prep_dataset/ILSVRC2012_val_00026570.bin 224 224 +42761 ./prep_dataset/ILSVRC2012_val_00027771.bin 224 224 +42762 ./prep_dataset/ILSVRC2012_val_00030249.bin 224 224 +42763 ./prep_dataset/ILSVRC2012_val_00019649.bin 224 224 +42764 ./prep_dataset/ILSVRC2012_val_00028414.bin 224 224 +42765 ./prep_dataset/ILSVRC2012_val_00010420.bin 224 224 +42766 ./prep_dataset/ILSVRC2012_val_00024129.bin 224 224 +42767 ./prep_dataset/ILSVRC2012_val_00010003.bin 224 224 +42768 ./prep_dataset/ILSVRC2012_val_00041645.bin 224 224 +42769 ./prep_dataset/ILSVRC2012_val_00017974.bin 224 224 +42770 ./prep_dataset/ILSVRC2012_val_00027092.bin 224 224 +42771 ./prep_dataset/ILSVRC2012_val_00044718.bin 224 224 +42772 ./prep_dataset/ILSVRC2012_val_00034684.bin 224 224 +42773 ./prep_dataset/ILSVRC2012_val_00037371.bin 224 224 +42774 ./prep_dataset/ILSVRC2012_val_00003268.bin 224 224 +42775 ./prep_dataset/ILSVRC2012_val_00037053.bin 224 224 +42776 ./prep_dataset/ILSVRC2012_val_00037746.bin 224 224 +42777 ./prep_dataset/ILSVRC2012_val_00033198.bin 224 224 +42778 ./prep_dataset/ILSVRC2012_val_00022191.bin 224 224 +42779 ./prep_dataset/ILSVRC2012_val_00005486.bin 224 224 +42780 ./prep_dataset/ILSVRC2012_val_00032500.bin 224 224 +42781 ./prep_dataset/ILSVRC2012_val_00042295.bin 224 224 +42782 ./prep_dataset/ILSVRC2012_val_00031361.bin 224 224 +42783 ./prep_dataset/ILSVRC2012_val_00018159.bin 224 224 +42784 ./prep_dataset/ILSVRC2012_val_00010746.bin 224 224 +42785 ./prep_dataset/ILSVRC2012_val_00028971.bin 224 224 +42786 ./prep_dataset/ILSVRC2012_val_00046681.bin 224 224 +42787 ./prep_dataset/ILSVRC2012_val_00012401.bin 224 224 +42788 ./prep_dataset/ILSVRC2012_val_00039759.bin 224 224 +42789 ./prep_dataset/ILSVRC2012_val_00024165.bin 224 224 +42790 ./prep_dataset/ILSVRC2012_val_00024476.bin 224 224 +42791 ./prep_dataset/ILSVRC2012_val_00034233.bin 224 224 +42792 ./prep_dataset/ILSVRC2012_val_00035562.bin 224 224 +42793 ./prep_dataset/ILSVRC2012_val_00016796.bin 224 224 +42794 ./prep_dataset/ILSVRC2012_val_00010653.bin 224 224 +42795 ./prep_dataset/ILSVRC2012_val_00032340.bin 224 224 +42796 ./prep_dataset/ILSVRC2012_val_00028351.bin 224 224 +42797 ./prep_dataset/ILSVRC2012_val_00035879.bin 224 224 +42798 ./prep_dataset/ILSVRC2012_val_00040003.bin 224 224 +42799 ./prep_dataset/ILSVRC2012_val_00001681.bin 224 224 +42800 ./prep_dataset/ILSVRC2012_val_00044456.bin 224 224 +42801 ./prep_dataset/ILSVRC2012_val_00007453.bin 224 224 +42802 ./prep_dataset/ILSVRC2012_val_00005229.bin 224 224 +42803 ./prep_dataset/ILSVRC2012_val_00014997.bin 224 224 +42804 ./prep_dataset/ILSVRC2012_val_00022802.bin 224 224 +42805 ./prep_dataset/ILSVRC2012_val_00031539.bin 224 224 +42806 ./prep_dataset/ILSVRC2012_val_00049653.bin 224 224 +42807 ./prep_dataset/ILSVRC2012_val_00008868.bin 224 224 +42808 ./prep_dataset/ILSVRC2012_val_00031865.bin 224 224 +42809 ./prep_dataset/ILSVRC2012_val_00043083.bin 224 224 +42810 ./prep_dataset/ILSVRC2012_val_00008731.bin 224 224 +42811 ./prep_dataset/ILSVRC2012_val_00016554.bin 224 224 +42812 ./prep_dataset/ILSVRC2012_val_00044169.bin 224 224 +42813 ./prep_dataset/ILSVRC2012_val_00013907.bin 224 224 +42814 ./prep_dataset/ILSVRC2012_val_00004393.bin 224 224 +42815 ./prep_dataset/ILSVRC2012_val_00015276.bin 224 224 +42816 ./prep_dataset/ILSVRC2012_val_00037623.bin 224 224 +42817 ./prep_dataset/ILSVRC2012_val_00027043.bin 224 224 +42818 ./prep_dataset/ILSVRC2012_val_00002528.bin 224 224 +42819 ./prep_dataset/ILSVRC2012_val_00029073.bin 224 224 +42820 ./prep_dataset/ILSVRC2012_val_00011561.bin 224 224 +42821 ./prep_dataset/ILSVRC2012_val_00000378.bin 224 224 +42822 ./prep_dataset/ILSVRC2012_val_00036596.bin 224 224 +42823 ./prep_dataset/ILSVRC2012_val_00015527.bin 224 224 +42824 ./prep_dataset/ILSVRC2012_val_00037388.bin 224 224 +42825 ./prep_dataset/ILSVRC2012_val_00046886.bin 224 224 +42826 ./prep_dataset/ILSVRC2012_val_00019170.bin 224 224 +42827 ./prep_dataset/ILSVRC2012_val_00016471.bin 224 224 +42828 ./prep_dataset/ILSVRC2012_val_00041528.bin 224 224 +42829 ./prep_dataset/ILSVRC2012_val_00038221.bin 224 224 +42830 ./prep_dataset/ILSVRC2012_val_00037492.bin 224 224 +42831 ./prep_dataset/ILSVRC2012_val_00016893.bin 224 224 +42832 ./prep_dataset/ILSVRC2012_val_00006667.bin 224 224 +42833 ./prep_dataset/ILSVRC2012_val_00016011.bin 224 224 +42834 ./prep_dataset/ILSVRC2012_val_00026164.bin 224 224 +42835 ./prep_dataset/ILSVRC2012_val_00014575.bin 224 224 +42836 ./prep_dataset/ILSVRC2012_val_00045034.bin 224 224 +42837 ./prep_dataset/ILSVRC2012_val_00046321.bin 224 224 +42838 ./prep_dataset/ILSVRC2012_val_00019816.bin 224 224 +42839 ./prep_dataset/ILSVRC2012_val_00006160.bin 224 224 +42840 ./prep_dataset/ILSVRC2012_val_00043199.bin 224 224 +42841 ./prep_dataset/ILSVRC2012_val_00009875.bin 224 224 +42842 ./prep_dataset/ILSVRC2012_val_00012259.bin 224 224 +42843 ./prep_dataset/ILSVRC2012_val_00021387.bin 224 224 +42844 ./prep_dataset/ILSVRC2012_val_00024996.bin 224 224 +42845 ./prep_dataset/ILSVRC2012_val_00009448.bin 224 224 +42846 ./prep_dataset/ILSVRC2012_val_00004579.bin 224 224 +42847 ./prep_dataset/ILSVRC2012_val_00000068.bin 224 224 +42848 ./prep_dataset/ILSVRC2012_val_00013048.bin 224 224 +42849 ./prep_dataset/ILSVRC2012_val_00017291.bin 224 224 +42850 ./prep_dataset/ILSVRC2012_val_00012891.bin 224 224 +42851 ./prep_dataset/ILSVRC2012_val_00043130.bin 224 224 +42852 ./prep_dataset/ILSVRC2012_val_00001007.bin 224 224 +42853 ./prep_dataset/ILSVRC2012_val_00027634.bin 224 224 +42854 ./prep_dataset/ILSVRC2012_val_00023842.bin 224 224 +42855 ./prep_dataset/ILSVRC2012_val_00032633.bin 224 224 +42856 ./prep_dataset/ILSVRC2012_val_00001575.bin 224 224 +42857 ./prep_dataset/ILSVRC2012_val_00027000.bin 224 224 +42858 ./prep_dataset/ILSVRC2012_val_00017030.bin 224 224 +42859 ./prep_dataset/ILSVRC2012_val_00031515.bin 224 224 +42860 ./prep_dataset/ILSVRC2012_val_00004864.bin 224 224 +42861 ./prep_dataset/ILSVRC2012_val_00027656.bin 224 224 +42862 ./prep_dataset/ILSVRC2012_val_00009545.bin 224 224 +42863 ./prep_dataset/ILSVRC2012_val_00020451.bin 224 224 +42864 ./prep_dataset/ILSVRC2012_val_00002040.bin 224 224 +42865 ./prep_dataset/ILSVRC2012_val_00046800.bin 224 224 +42866 ./prep_dataset/ILSVRC2012_val_00020131.bin 224 224 +42867 ./prep_dataset/ILSVRC2012_val_00034991.bin 224 224 +42868 ./prep_dataset/ILSVRC2012_val_00027151.bin 224 224 +42869 ./prep_dataset/ILSVRC2012_val_00024198.bin 224 224 +42870 ./prep_dataset/ILSVRC2012_val_00046929.bin 224 224 +42871 ./prep_dataset/ILSVRC2012_val_00022967.bin 224 224 +42872 ./prep_dataset/ILSVRC2012_val_00034552.bin 224 224 +42873 ./prep_dataset/ILSVRC2012_val_00010147.bin 224 224 +42874 ./prep_dataset/ILSVRC2012_val_00043948.bin 224 224 +42875 ./prep_dataset/ILSVRC2012_val_00027345.bin 224 224 +42876 ./prep_dataset/ILSVRC2012_val_00038881.bin 224 224 +42877 ./prep_dataset/ILSVRC2012_val_00048673.bin 224 224 +42878 ./prep_dataset/ILSVRC2012_val_00049106.bin 224 224 +42879 ./prep_dataset/ILSVRC2012_val_00026924.bin 224 224 +42880 ./prep_dataset/ILSVRC2012_val_00008788.bin 224 224 +42881 ./prep_dataset/ILSVRC2012_val_00041469.bin 224 224 +42882 ./prep_dataset/ILSVRC2012_val_00025029.bin 224 224 +42883 ./prep_dataset/ILSVRC2012_val_00049637.bin 224 224 +42884 ./prep_dataset/ILSVRC2012_val_00032468.bin 224 224 +42885 ./prep_dataset/ILSVRC2012_val_00008531.bin 224 224 +42886 ./prep_dataset/ILSVRC2012_val_00045876.bin 224 224 +42887 ./prep_dataset/ILSVRC2012_val_00016356.bin 224 224 +42888 ./prep_dataset/ILSVRC2012_val_00043579.bin 224 224 +42889 ./prep_dataset/ILSVRC2012_val_00025074.bin 224 224 +42890 ./prep_dataset/ILSVRC2012_val_00032671.bin 224 224 +42891 ./prep_dataset/ILSVRC2012_val_00012827.bin 224 224 +42892 ./prep_dataset/ILSVRC2012_val_00026588.bin 224 224 +42893 ./prep_dataset/ILSVRC2012_val_00043557.bin 224 224 +42894 ./prep_dataset/ILSVRC2012_val_00039724.bin 224 224 +42895 ./prep_dataset/ILSVRC2012_val_00035000.bin 224 224 +42896 ./prep_dataset/ILSVRC2012_val_00039614.bin 224 224 +42897 ./prep_dataset/ILSVRC2012_val_00002361.bin 224 224 +42898 ./prep_dataset/ILSVRC2012_val_00015814.bin 224 224 +42899 ./prep_dataset/ILSVRC2012_val_00019470.bin 224 224 +42900 ./prep_dataset/ILSVRC2012_val_00045388.bin 224 224 +42901 ./prep_dataset/ILSVRC2012_val_00047689.bin 224 224 +42902 ./prep_dataset/ILSVRC2012_val_00049898.bin 224 224 +42903 ./prep_dataset/ILSVRC2012_val_00024768.bin 224 224 +42904 ./prep_dataset/ILSVRC2012_val_00043761.bin 224 224 +42905 ./prep_dataset/ILSVRC2012_val_00046162.bin 224 224 +42906 ./prep_dataset/ILSVRC2012_val_00016270.bin 224 224 +42907 ./prep_dataset/ILSVRC2012_val_00023553.bin 224 224 +42908 ./prep_dataset/ILSVRC2012_val_00003845.bin 224 224 +42909 ./prep_dataset/ILSVRC2012_val_00046292.bin 224 224 +42910 ./prep_dataset/ILSVRC2012_val_00008319.bin 224 224 +42911 ./prep_dataset/ILSVRC2012_val_00005568.bin 224 224 +42912 ./prep_dataset/ILSVRC2012_val_00028152.bin 224 224 +42913 ./prep_dataset/ILSVRC2012_val_00036983.bin 224 224 +42914 ./prep_dataset/ILSVRC2012_val_00022401.bin 224 224 +42915 ./prep_dataset/ILSVRC2012_val_00006002.bin 224 224 +42916 ./prep_dataset/ILSVRC2012_val_00034589.bin 224 224 +42917 ./prep_dataset/ILSVRC2012_val_00021881.bin 224 224 +42918 ./prep_dataset/ILSVRC2012_val_00042815.bin 224 224 +42919 ./prep_dataset/ILSVRC2012_val_00036292.bin 224 224 +42920 ./prep_dataset/ILSVRC2012_val_00010412.bin 224 224 +42921 ./prep_dataset/ILSVRC2012_val_00043677.bin 224 224 +42922 ./prep_dataset/ILSVRC2012_val_00012267.bin 224 224 +42923 ./prep_dataset/ILSVRC2012_val_00000514.bin 224 224 +42924 ./prep_dataset/ILSVRC2012_val_00048800.bin 224 224 +42925 ./prep_dataset/ILSVRC2012_val_00004957.bin 224 224 +42926 ./prep_dataset/ILSVRC2012_val_00030102.bin 224 224 +42927 ./prep_dataset/ILSVRC2012_val_00008603.bin 224 224 +42928 ./prep_dataset/ILSVRC2012_val_00031733.bin 224 224 +42929 ./prep_dataset/ILSVRC2012_val_00017591.bin 224 224 +42930 ./prep_dataset/ILSVRC2012_val_00032199.bin 224 224 +42931 ./prep_dataset/ILSVRC2012_val_00000355.bin 224 224 +42932 ./prep_dataset/ILSVRC2012_val_00032379.bin 224 224 +42933 ./prep_dataset/ILSVRC2012_val_00019442.bin 224 224 +42934 ./prep_dataset/ILSVRC2012_val_00043169.bin 224 224 +42935 ./prep_dataset/ILSVRC2012_val_00014276.bin 224 224 +42936 ./prep_dataset/ILSVRC2012_val_00020048.bin 224 224 +42937 ./prep_dataset/ILSVRC2012_val_00026713.bin 224 224 +42938 ./prep_dataset/ILSVRC2012_val_00007972.bin 224 224 +42939 ./prep_dataset/ILSVRC2012_val_00044208.bin 224 224 +42940 ./prep_dataset/ILSVRC2012_val_00024350.bin 224 224 +42941 ./prep_dataset/ILSVRC2012_val_00020578.bin 224 224 +42942 ./prep_dataset/ILSVRC2012_val_00004154.bin 224 224 +42943 ./prep_dataset/ILSVRC2012_val_00047026.bin 224 224 +42944 ./prep_dataset/ILSVRC2012_val_00043749.bin 224 224 +42945 ./prep_dataset/ILSVRC2012_val_00037479.bin 224 224 +42946 ./prep_dataset/ILSVRC2012_val_00001283.bin 224 224 +42947 ./prep_dataset/ILSVRC2012_val_00042853.bin 224 224 +42948 ./prep_dataset/ILSVRC2012_val_00024699.bin 224 224 +42949 ./prep_dataset/ILSVRC2012_val_00046281.bin 224 224 +42950 ./prep_dataset/ILSVRC2012_val_00014137.bin 224 224 +42951 ./prep_dataset/ILSVRC2012_val_00038478.bin 224 224 +42952 ./prep_dataset/ILSVRC2012_val_00045955.bin 224 224 +42953 ./prep_dataset/ILSVRC2012_val_00043131.bin 224 224 +42954 ./prep_dataset/ILSVRC2012_val_00034472.bin 224 224 +42955 ./prep_dataset/ILSVRC2012_val_00015038.bin 224 224 +42956 ./prep_dataset/ILSVRC2012_val_00009902.bin 224 224 +42957 ./prep_dataset/ILSVRC2012_val_00024837.bin 224 224 +42958 ./prep_dataset/ILSVRC2012_val_00009569.bin 224 224 +42959 ./prep_dataset/ILSVRC2012_val_00035820.bin 224 224 +42960 ./prep_dataset/ILSVRC2012_val_00037702.bin 224 224 +42961 ./prep_dataset/ILSVRC2012_val_00030959.bin 224 224 +42962 ./prep_dataset/ILSVRC2012_val_00014813.bin 224 224 +42963 ./prep_dataset/ILSVRC2012_val_00012249.bin 224 224 +42964 ./prep_dataset/ILSVRC2012_val_00006206.bin 224 224 +42965 ./prep_dataset/ILSVRC2012_val_00015333.bin 224 224 +42966 ./prep_dataset/ILSVRC2012_val_00026143.bin 224 224 +42967 ./prep_dataset/ILSVRC2012_val_00040893.bin 224 224 +42968 ./prep_dataset/ILSVRC2012_val_00041067.bin 224 224 +42969 ./prep_dataset/ILSVRC2012_val_00010637.bin 224 224 +42970 ./prep_dataset/ILSVRC2012_val_00010582.bin 224 224 +42971 ./prep_dataset/ILSVRC2012_val_00015871.bin 224 224 +42972 ./prep_dataset/ILSVRC2012_val_00037253.bin 224 224 +42973 ./prep_dataset/ILSVRC2012_val_00011573.bin 224 224 +42974 ./prep_dataset/ILSVRC2012_val_00049354.bin 224 224 +42975 ./prep_dataset/ILSVRC2012_val_00006592.bin 224 224 +42976 ./prep_dataset/ILSVRC2012_val_00035142.bin 224 224 +42977 ./prep_dataset/ILSVRC2012_val_00010294.bin 224 224 +42978 ./prep_dataset/ILSVRC2012_val_00003504.bin 224 224 +42979 ./prep_dataset/ILSVRC2012_val_00008933.bin 224 224 +42980 ./prep_dataset/ILSVRC2012_val_00043386.bin 224 224 +42981 ./prep_dataset/ILSVRC2012_val_00003157.bin 224 224 +42982 ./prep_dataset/ILSVRC2012_val_00015636.bin 224 224 +42983 ./prep_dataset/ILSVRC2012_val_00048922.bin 224 224 +42984 ./prep_dataset/ILSVRC2012_val_00011652.bin 224 224 +42985 ./prep_dataset/ILSVRC2012_val_00040154.bin 224 224 +42986 ./prep_dataset/ILSVRC2012_val_00007758.bin 224 224 +42987 ./prep_dataset/ILSVRC2012_val_00004353.bin 224 224 +42988 ./prep_dataset/ILSVRC2012_val_00014556.bin 224 224 +42989 ./prep_dataset/ILSVRC2012_val_00049468.bin 224 224 +42990 ./prep_dataset/ILSVRC2012_val_00029979.bin 224 224 +42991 ./prep_dataset/ILSVRC2012_val_00049655.bin 224 224 +42992 ./prep_dataset/ILSVRC2012_val_00047562.bin 224 224 +42993 ./prep_dataset/ILSVRC2012_val_00049513.bin 224 224 +42994 ./prep_dataset/ILSVRC2012_val_00036888.bin 224 224 +42995 ./prep_dataset/ILSVRC2012_val_00030618.bin 224 224 +42996 ./prep_dataset/ILSVRC2012_val_00016536.bin 224 224 +42997 ./prep_dataset/ILSVRC2012_val_00041153.bin 224 224 +42998 ./prep_dataset/ILSVRC2012_val_00020650.bin 224 224 +42999 ./prep_dataset/ILSVRC2012_val_00011858.bin 224 224 +43000 ./prep_dataset/ILSVRC2012_val_00048326.bin 224 224 +43001 ./prep_dataset/ILSVRC2012_val_00034411.bin 224 224 +43002 ./prep_dataset/ILSVRC2012_val_00026266.bin 224 224 +43003 ./prep_dataset/ILSVRC2012_val_00022180.bin 224 224 +43004 ./prep_dataset/ILSVRC2012_val_00033161.bin 224 224 +43005 ./prep_dataset/ILSVRC2012_val_00000328.bin 224 224 +43006 ./prep_dataset/ILSVRC2012_val_00034197.bin 224 224 +43007 ./prep_dataset/ILSVRC2012_val_00031269.bin 224 224 +43008 ./prep_dataset/ILSVRC2012_val_00011598.bin 224 224 +43009 ./prep_dataset/ILSVRC2012_val_00012318.bin 224 224 +43010 ./prep_dataset/ILSVRC2012_val_00006914.bin 224 224 +43011 ./prep_dataset/ILSVRC2012_val_00006186.bin 224 224 +43012 ./prep_dataset/ILSVRC2012_val_00007444.bin 224 224 +43013 ./prep_dataset/ILSVRC2012_val_00010450.bin 224 224 +43014 ./prep_dataset/ILSVRC2012_val_00022651.bin 224 224 +43015 ./prep_dataset/ILSVRC2012_val_00034532.bin 224 224 +43016 ./prep_dataset/ILSVRC2012_val_00013027.bin 224 224 +43017 ./prep_dataset/ILSVRC2012_val_00017408.bin 224 224 +43018 ./prep_dataset/ILSVRC2012_val_00015137.bin 224 224 +43019 ./prep_dataset/ILSVRC2012_val_00028130.bin 224 224 +43020 ./prep_dataset/ILSVRC2012_val_00039490.bin 224 224 +43021 ./prep_dataset/ILSVRC2012_val_00040169.bin 224 224 +43022 ./prep_dataset/ILSVRC2012_val_00016593.bin 224 224 +43023 ./prep_dataset/ILSVRC2012_val_00014873.bin 224 224 +43024 ./prep_dataset/ILSVRC2012_val_00029995.bin 224 224 +43025 ./prep_dataset/ILSVRC2012_val_00016847.bin 224 224 +43026 ./prep_dataset/ILSVRC2012_val_00008291.bin 224 224 +43027 ./prep_dataset/ILSVRC2012_val_00004337.bin 224 224 +43028 ./prep_dataset/ILSVRC2012_val_00040611.bin 224 224 +43029 ./prep_dataset/ILSVRC2012_val_00013845.bin 224 224 +43030 ./prep_dataset/ILSVRC2012_val_00016681.bin 224 224 +43031 ./prep_dataset/ILSVRC2012_val_00017782.bin 224 224 +43032 ./prep_dataset/ILSVRC2012_val_00027042.bin 224 224 +43033 ./prep_dataset/ILSVRC2012_val_00035165.bin 224 224 +43034 ./prep_dataset/ILSVRC2012_val_00018919.bin 224 224 +43035 ./prep_dataset/ILSVRC2012_val_00010141.bin 224 224 +43036 ./prep_dataset/ILSVRC2012_val_00012666.bin 224 224 +43037 ./prep_dataset/ILSVRC2012_val_00042154.bin 224 224 +43038 ./prep_dataset/ILSVRC2012_val_00018336.bin 224 224 +43039 ./prep_dataset/ILSVRC2012_val_00041002.bin 224 224 +43040 ./prep_dataset/ILSVRC2012_val_00006270.bin 224 224 +43041 ./prep_dataset/ILSVRC2012_val_00003216.bin 224 224 +43042 ./prep_dataset/ILSVRC2012_val_00004823.bin 224 224 +43043 ./prep_dataset/ILSVRC2012_val_00044061.bin 224 224 +43044 ./prep_dataset/ILSVRC2012_val_00016655.bin 224 224 +43045 ./prep_dataset/ILSVRC2012_val_00030586.bin 224 224 +43046 ./prep_dataset/ILSVRC2012_val_00034356.bin 224 224 +43047 ./prep_dataset/ILSVRC2012_val_00032715.bin 224 224 +43048 ./prep_dataset/ILSVRC2012_val_00045208.bin 224 224 +43049 ./prep_dataset/ILSVRC2012_val_00014980.bin 224 224 +43050 ./prep_dataset/ILSVRC2012_val_00014281.bin 224 224 +43051 ./prep_dataset/ILSVRC2012_val_00005318.bin 224 224 +43052 ./prep_dataset/ILSVRC2012_val_00006405.bin 224 224 +43053 ./prep_dataset/ILSVRC2012_val_00040382.bin 224 224 +43054 ./prep_dataset/ILSVRC2012_val_00027959.bin 224 224 +43055 ./prep_dataset/ILSVRC2012_val_00004907.bin 224 224 +43056 ./prep_dataset/ILSVRC2012_val_00018869.bin 224 224 +43057 ./prep_dataset/ILSVRC2012_val_00008823.bin 224 224 +43058 ./prep_dataset/ILSVRC2012_val_00048519.bin 224 224 +43059 ./prep_dataset/ILSVRC2012_val_00009666.bin 224 224 +43060 ./prep_dataset/ILSVRC2012_val_00030220.bin 224 224 +43061 ./prep_dataset/ILSVRC2012_val_00003606.bin 224 224 +43062 ./prep_dataset/ILSVRC2012_val_00016898.bin 224 224 +43063 ./prep_dataset/ILSVRC2012_val_00010016.bin 224 224 +43064 ./prep_dataset/ILSVRC2012_val_00038960.bin 224 224 +43065 ./prep_dataset/ILSVRC2012_val_00004725.bin 224 224 +43066 ./prep_dataset/ILSVRC2012_val_00048838.bin 224 224 +43067 ./prep_dataset/ILSVRC2012_val_00046113.bin 224 224 +43068 ./prep_dataset/ILSVRC2012_val_00038106.bin 224 224 +43069 ./prep_dataset/ILSVRC2012_val_00016127.bin 224 224 +43070 ./prep_dataset/ILSVRC2012_val_00031843.bin 224 224 +43071 ./prep_dataset/ILSVRC2012_val_00007601.bin 224 224 +43072 ./prep_dataset/ILSVRC2012_val_00030365.bin 224 224 +43073 ./prep_dataset/ILSVRC2012_val_00027664.bin 224 224 +43074 ./prep_dataset/ILSVRC2012_val_00022104.bin 224 224 +43075 ./prep_dataset/ILSVRC2012_val_00038508.bin 224 224 +43076 ./prep_dataset/ILSVRC2012_val_00022812.bin 224 224 +43077 ./prep_dataset/ILSVRC2012_val_00041977.bin 224 224 +43078 ./prep_dataset/ILSVRC2012_val_00007295.bin 224 224 +43079 ./prep_dataset/ILSVRC2012_val_00008885.bin 224 224 +43080 ./prep_dataset/ILSVRC2012_val_00031308.bin 224 224 +43081 ./prep_dataset/ILSVRC2012_val_00001889.bin 224 224 +43082 ./prep_dataset/ILSVRC2012_val_00044396.bin 224 224 +43083 ./prep_dataset/ILSVRC2012_val_00017257.bin 224 224 +43084 ./prep_dataset/ILSVRC2012_val_00040743.bin 224 224 +43085 ./prep_dataset/ILSVRC2012_val_00043496.bin 224 224 +43086 ./prep_dataset/ILSVRC2012_val_00011724.bin 224 224 +43087 ./prep_dataset/ILSVRC2012_val_00004236.bin 224 224 +43088 ./prep_dataset/ILSVRC2012_val_00037830.bin 224 224 +43089 ./prep_dataset/ILSVRC2012_val_00021260.bin 224 224 +43090 ./prep_dataset/ILSVRC2012_val_00032346.bin 224 224 +43091 ./prep_dataset/ILSVRC2012_val_00002152.bin 224 224 +43092 ./prep_dataset/ILSVRC2012_val_00022059.bin 224 224 +43093 ./prep_dataset/ILSVRC2012_val_00011937.bin 224 224 +43094 ./prep_dataset/ILSVRC2012_val_00039296.bin 224 224 +43095 ./prep_dataset/ILSVRC2012_val_00019311.bin 224 224 +43096 ./prep_dataset/ILSVRC2012_val_00028301.bin 224 224 +43097 ./prep_dataset/ILSVRC2012_val_00037463.bin 224 224 +43098 ./prep_dataset/ILSVRC2012_val_00004522.bin 224 224 +43099 ./prep_dataset/ILSVRC2012_val_00048592.bin 224 224 +43100 ./prep_dataset/ILSVRC2012_val_00001054.bin 224 224 +43101 ./prep_dataset/ILSVRC2012_val_00028887.bin 224 224 +43102 ./prep_dataset/ILSVRC2012_val_00027717.bin 224 224 +43103 ./prep_dataset/ILSVRC2012_val_00032072.bin 224 224 +43104 ./prep_dataset/ILSVRC2012_val_00032171.bin 224 224 +43105 ./prep_dataset/ILSVRC2012_val_00030894.bin 224 224 +43106 ./prep_dataset/ILSVRC2012_val_00028880.bin 224 224 +43107 ./prep_dataset/ILSVRC2012_val_00037835.bin 224 224 +43108 ./prep_dataset/ILSVRC2012_val_00008281.bin 224 224 +43109 ./prep_dataset/ILSVRC2012_val_00007460.bin 224 224 +43110 ./prep_dataset/ILSVRC2012_val_00044704.bin 224 224 +43111 ./prep_dataset/ILSVRC2012_val_00015191.bin 224 224 +43112 ./prep_dataset/ILSVRC2012_val_00001861.bin 224 224 +43113 ./prep_dataset/ILSVRC2012_val_00020585.bin 224 224 +43114 ./prep_dataset/ILSVRC2012_val_00028174.bin 224 224 +43115 ./prep_dataset/ILSVRC2012_val_00012227.bin 224 224 +43116 ./prep_dataset/ILSVRC2012_val_00029745.bin 224 224 +43117 ./prep_dataset/ILSVRC2012_val_00002401.bin 224 224 +43118 ./prep_dataset/ILSVRC2012_val_00002782.bin 224 224 +43119 ./prep_dataset/ILSVRC2012_val_00044204.bin 224 224 +43120 ./prep_dataset/ILSVRC2012_val_00020883.bin 224 224 +43121 ./prep_dataset/ILSVRC2012_val_00003195.bin 224 224 +43122 ./prep_dataset/ILSVRC2012_val_00043508.bin 224 224 +43123 ./prep_dataset/ILSVRC2012_val_00031379.bin 224 224 +43124 ./prep_dataset/ILSVRC2012_val_00045051.bin 224 224 +43125 ./prep_dataset/ILSVRC2012_val_00020699.bin 224 224 +43126 ./prep_dataset/ILSVRC2012_val_00032853.bin 224 224 +43127 ./prep_dataset/ILSVRC2012_val_00038095.bin 224 224 +43128 ./prep_dataset/ILSVRC2012_val_00008648.bin 224 224 +43129 ./prep_dataset/ILSVRC2012_val_00009774.bin 224 224 +43130 ./prep_dataset/ILSVRC2012_val_00030298.bin 224 224 +43131 ./prep_dataset/ILSVRC2012_val_00001162.bin 224 224 +43132 ./prep_dataset/ILSVRC2012_val_00015233.bin 224 224 +43133 ./prep_dataset/ILSVRC2012_val_00042041.bin 224 224 +43134 ./prep_dataset/ILSVRC2012_val_00030798.bin 224 224 +43135 ./prep_dataset/ILSVRC2012_val_00013029.bin 224 224 +43136 ./prep_dataset/ILSVRC2012_val_00007667.bin 224 224 +43137 ./prep_dataset/ILSVRC2012_val_00013787.bin 224 224 +43138 ./prep_dataset/ILSVRC2012_val_00022500.bin 224 224 +43139 ./prep_dataset/ILSVRC2012_val_00028610.bin 224 224 +43140 ./prep_dataset/ILSVRC2012_val_00047854.bin 224 224 +43141 ./prep_dataset/ILSVRC2012_val_00010678.bin 224 224 +43142 ./prep_dataset/ILSVRC2012_val_00024593.bin 224 224 +43143 ./prep_dataset/ILSVRC2012_val_00016907.bin 224 224 +43144 ./prep_dataset/ILSVRC2012_val_00001140.bin 224 224 +43145 ./prep_dataset/ILSVRC2012_val_00040338.bin 224 224 +43146 ./prep_dataset/ILSVRC2012_val_00047114.bin 224 224 +43147 ./prep_dataset/ILSVRC2012_val_00046081.bin 224 224 +43148 ./prep_dataset/ILSVRC2012_val_00007675.bin 224 224 +43149 ./prep_dataset/ILSVRC2012_val_00041604.bin 224 224 +43150 ./prep_dataset/ILSVRC2012_val_00041244.bin 224 224 +43151 ./prep_dataset/ILSVRC2012_val_00021358.bin 224 224 +43152 ./prep_dataset/ILSVRC2012_val_00013291.bin 224 224 +43153 ./prep_dataset/ILSVRC2012_val_00025492.bin 224 224 +43154 ./prep_dataset/ILSVRC2012_val_00046268.bin 224 224 +43155 ./prep_dataset/ILSVRC2012_val_00030161.bin 224 224 +43156 ./prep_dataset/ILSVRC2012_val_00030479.bin 224 224 +43157 ./prep_dataset/ILSVRC2012_val_00039570.bin 224 224 +43158 ./prep_dataset/ILSVRC2012_val_00024433.bin 224 224 +43159 ./prep_dataset/ILSVRC2012_val_00019243.bin 224 224 +43160 ./prep_dataset/ILSVRC2012_val_00024538.bin 224 224 +43161 ./prep_dataset/ILSVRC2012_val_00047613.bin 224 224 +43162 ./prep_dataset/ILSVRC2012_val_00036023.bin 224 224 +43163 ./prep_dataset/ILSVRC2012_val_00012131.bin 224 224 +43164 ./prep_dataset/ILSVRC2012_val_00017377.bin 224 224 +43165 ./prep_dataset/ILSVRC2012_val_00003343.bin 224 224 +43166 ./prep_dataset/ILSVRC2012_val_00021802.bin 224 224 +43167 ./prep_dataset/ILSVRC2012_val_00029201.bin 224 224 +43168 ./prep_dataset/ILSVRC2012_val_00036670.bin 224 224 +43169 ./prep_dataset/ILSVRC2012_val_00043370.bin 224 224 +43170 ./prep_dataset/ILSVRC2012_val_00011714.bin 224 224 +43171 ./prep_dataset/ILSVRC2012_val_00011113.bin 224 224 +43172 ./prep_dataset/ILSVRC2012_val_00031122.bin 224 224 +43173 ./prep_dataset/ILSVRC2012_val_00018920.bin 224 224 +43174 ./prep_dataset/ILSVRC2012_val_00042958.bin 224 224 +43175 ./prep_dataset/ILSVRC2012_val_00042731.bin 224 224 +43176 ./prep_dataset/ILSVRC2012_val_00019534.bin 224 224 +43177 ./prep_dataset/ILSVRC2012_val_00049758.bin 224 224 +43178 ./prep_dataset/ILSVRC2012_val_00000698.bin 224 224 +43179 ./prep_dataset/ILSVRC2012_val_00023071.bin 224 224 +43180 ./prep_dataset/ILSVRC2012_val_00028087.bin 224 224 +43181 ./prep_dataset/ILSVRC2012_val_00004924.bin 224 224 +43182 ./prep_dataset/ILSVRC2012_val_00009049.bin 224 224 +43183 ./prep_dataset/ILSVRC2012_val_00035813.bin 224 224 +43184 ./prep_dataset/ILSVRC2012_val_00019823.bin 224 224 +43185 ./prep_dataset/ILSVRC2012_val_00014735.bin 224 224 +43186 ./prep_dataset/ILSVRC2012_val_00022853.bin 224 224 +43187 ./prep_dataset/ILSVRC2012_val_00012456.bin 224 224 +43188 ./prep_dataset/ILSVRC2012_val_00025188.bin 224 224 +43189 ./prep_dataset/ILSVRC2012_val_00039658.bin 224 224 +43190 ./prep_dataset/ILSVRC2012_val_00045886.bin 224 224 +43191 ./prep_dataset/ILSVRC2012_val_00045366.bin 224 224 +43192 ./prep_dataset/ILSVRC2012_val_00011658.bin 224 224 +43193 ./prep_dataset/ILSVRC2012_val_00017948.bin 224 224 +43194 ./prep_dataset/ILSVRC2012_val_00030357.bin 224 224 +43195 ./prep_dataset/ILSVRC2012_val_00027531.bin 224 224 +43196 ./prep_dataset/ILSVRC2012_val_00013914.bin 224 224 +43197 ./prep_dataset/ILSVRC2012_val_00027314.bin 224 224 +43198 ./prep_dataset/ILSVRC2012_val_00038400.bin 224 224 +43199 ./prep_dataset/ILSVRC2012_val_00048037.bin 224 224 +43200 ./prep_dataset/ILSVRC2012_val_00008585.bin 224 224 +43201 ./prep_dataset/ILSVRC2012_val_00026005.bin 224 224 +43202 ./prep_dataset/ILSVRC2012_val_00025142.bin 224 224 +43203 ./prep_dataset/ILSVRC2012_val_00042848.bin 224 224 +43204 ./prep_dataset/ILSVRC2012_val_00026081.bin 224 224 +43205 ./prep_dataset/ILSVRC2012_val_00048412.bin 224 224 +43206 ./prep_dataset/ILSVRC2012_val_00038216.bin 224 224 +43207 ./prep_dataset/ILSVRC2012_val_00035871.bin 224 224 +43208 ./prep_dataset/ILSVRC2012_val_00030244.bin 224 224 +43209 ./prep_dataset/ILSVRC2012_val_00028244.bin 224 224 +43210 ./prep_dataset/ILSVRC2012_val_00040170.bin 224 224 +43211 ./prep_dataset/ILSVRC2012_val_00037448.bin 224 224 +43212 ./prep_dataset/ILSVRC2012_val_00001061.bin 224 224 +43213 ./prep_dataset/ILSVRC2012_val_00019860.bin 224 224 +43214 ./prep_dataset/ILSVRC2012_val_00003842.bin 224 224 +43215 ./prep_dataset/ILSVRC2012_val_00019477.bin 224 224 +43216 ./prep_dataset/ILSVRC2012_val_00025442.bin 224 224 +43217 ./prep_dataset/ILSVRC2012_val_00027311.bin 224 224 +43218 ./prep_dataset/ILSVRC2012_val_00047175.bin 224 224 +43219 ./prep_dataset/ILSVRC2012_val_00020165.bin 224 224 +43220 ./prep_dataset/ILSVRC2012_val_00043139.bin 224 224 +43221 ./prep_dataset/ILSVRC2012_val_00029900.bin 224 224 +43222 ./prep_dataset/ILSVRC2012_val_00049971.bin 224 224 +43223 ./prep_dataset/ILSVRC2012_val_00007946.bin 224 224 +43224 ./prep_dataset/ILSVRC2012_val_00041435.bin 224 224 +43225 ./prep_dataset/ILSVRC2012_val_00030411.bin 224 224 +43226 ./prep_dataset/ILSVRC2012_val_00023123.bin 224 224 +43227 ./prep_dataset/ILSVRC2012_val_00001594.bin 224 224 +43228 ./prep_dataset/ILSVRC2012_val_00020927.bin 224 224 +43229 ./prep_dataset/ILSVRC2012_val_00033866.bin 224 224 +43230 ./prep_dataset/ILSVRC2012_val_00041858.bin 224 224 +43231 ./prep_dataset/ILSVRC2012_val_00021093.bin 224 224 +43232 ./prep_dataset/ILSVRC2012_val_00042612.bin 224 224 +43233 ./prep_dataset/ILSVRC2012_val_00000359.bin 224 224 +43234 ./prep_dataset/ILSVRC2012_val_00030373.bin 224 224 +43235 ./prep_dataset/ILSVRC2012_val_00018560.bin 224 224 +43236 ./prep_dataset/ILSVRC2012_val_00031785.bin 224 224 +43237 ./prep_dataset/ILSVRC2012_val_00031135.bin 224 224 +43238 ./prep_dataset/ILSVRC2012_val_00004285.bin 224 224 +43239 ./prep_dataset/ILSVRC2012_val_00007116.bin 224 224 +43240 ./prep_dataset/ILSVRC2012_val_00022765.bin 224 224 +43241 ./prep_dataset/ILSVRC2012_val_00033123.bin 224 224 +43242 ./prep_dataset/ILSVRC2012_val_00023794.bin 224 224 +43243 ./prep_dataset/ILSVRC2012_val_00040006.bin 224 224 +43244 ./prep_dataset/ILSVRC2012_val_00007178.bin 224 224 +43245 ./prep_dataset/ILSVRC2012_val_00030895.bin 224 224 +43246 ./prep_dataset/ILSVRC2012_val_00028210.bin 224 224 +43247 ./prep_dataset/ILSVRC2012_val_00026103.bin 224 224 +43248 ./prep_dataset/ILSVRC2012_val_00023645.bin 224 224 +43249 ./prep_dataset/ILSVRC2012_val_00044031.bin 224 224 +43250 ./prep_dataset/ILSVRC2012_val_00003326.bin 224 224 +43251 ./prep_dataset/ILSVRC2012_val_00042091.bin 224 224 +43252 ./prep_dataset/ILSVRC2012_val_00033657.bin 224 224 +43253 ./prep_dataset/ILSVRC2012_val_00029505.bin 224 224 +43254 ./prep_dataset/ILSVRC2012_val_00005055.bin 224 224 +43255 ./prep_dataset/ILSVRC2012_val_00004001.bin 224 224 +43256 ./prep_dataset/ILSVRC2012_val_00049852.bin 224 224 +43257 ./prep_dataset/ILSVRC2012_val_00035117.bin 224 224 +43258 ./prep_dataset/ILSVRC2012_val_00009323.bin 224 224 +43259 ./prep_dataset/ILSVRC2012_val_00024685.bin 224 224 +43260 ./prep_dataset/ILSVRC2012_val_00024900.bin 224 224 +43261 ./prep_dataset/ILSVRC2012_val_00034001.bin 224 224 +43262 ./prep_dataset/ILSVRC2012_val_00031603.bin 224 224 +43263 ./prep_dataset/ILSVRC2012_val_00007396.bin 224 224 +43264 ./prep_dataset/ILSVRC2012_val_00000273.bin 224 224 +43265 ./prep_dataset/ILSVRC2012_val_00009687.bin 224 224 +43266 ./prep_dataset/ILSVRC2012_val_00041111.bin 224 224 +43267 ./prep_dataset/ILSVRC2012_val_00027823.bin 224 224 +43268 ./prep_dataset/ILSVRC2012_val_00023759.bin 224 224 +43269 ./prep_dataset/ILSVRC2012_val_00025464.bin 224 224 +43270 ./prep_dataset/ILSVRC2012_val_00033924.bin 224 224 +43271 ./prep_dataset/ILSVRC2012_val_00044829.bin 224 224 +43272 ./prep_dataset/ILSVRC2012_val_00005854.bin 224 224 +43273 ./prep_dataset/ILSVRC2012_val_00040096.bin 224 224 +43274 ./prep_dataset/ILSVRC2012_val_00023104.bin 224 224 +43275 ./prep_dataset/ILSVRC2012_val_00001976.bin 224 224 +43276 ./prep_dataset/ILSVRC2012_val_00030353.bin 224 224 +43277 ./prep_dataset/ILSVRC2012_val_00043304.bin 224 224 +43278 ./prep_dataset/ILSVRC2012_val_00043794.bin 224 224 +43279 ./prep_dataset/ILSVRC2012_val_00018404.bin 224 224 +43280 ./prep_dataset/ILSVRC2012_val_00043395.bin 224 224 +43281 ./prep_dataset/ILSVRC2012_val_00038519.bin 224 224 +43282 ./prep_dataset/ILSVRC2012_val_00004651.bin 224 224 +43283 ./prep_dataset/ILSVRC2012_val_00009853.bin 224 224 +43284 ./prep_dataset/ILSVRC2012_val_00048089.bin 224 224 +43285 ./prep_dataset/ILSVRC2012_val_00022133.bin 224 224 +43286 ./prep_dataset/ILSVRC2012_val_00009341.bin 224 224 +43287 ./prep_dataset/ILSVRC2012_val_00049799.bin 224 224 +43288 ./prep_dataset/ILSVRC2012_val_00040250.bin 224 224 +43289 ./prep_dataset/ILSVRC2012_val_00023460.bin 224 224 +43290 ./prep_dataset/ILSVRC2012_val_00047674.bin 224 224 +43291 ./prep_dataset/ILSVRC2012_val_00007720.bin 224 224 +43292 ./prep_dataset/ILSVRC2012_val_00005176.bin 224 224 +43293 ./prep_dataset/ILSVRC2012_val_00016107.bin 224 224 +43294 ./prep_dataset/ILSVRC2012_val_00013284.bin 224 224 +43295 ./prep_dataset/ILSVRC2012_val_00039609.bin 224 224 +43296 ./prep_dataset/ILSVRC2012_val_00003602.bin 224 224 +43297 ./prep_dataset/ILSVRC2012_val_00045582.bin 224 224 +43298 ./prep_dataset/ILSVRC2012_val_00013271.bin 224 224 +43299 ./prep_dataset/ILSVRC2012_val_00000447.bin 224 224 +43300 ./prep_dataset/ILSVRC2012_val_00045343.bin 224 224 +43301 ./prep_dataset/ILSVRC2012_val_00019041.bin 224 224 +43302 ./prep_dataset/ILSVRC2012_val_00035926.bin 224 224 +43303 ./prep_dataset/ILSVRC2012_val_00031341.bin 224 224 +43304 ./prep_dataset/ILSVRC2012_val_00026674.bin 224 224 +43305 ./prep_dataset/ILSVRC2012_val_00009798.bin 224 224 +43306 ./prep_dataset/ILSVRC2012_val_00001568.bin 224 224 +43307 ./prep_dataset/ILSVRC2012_val_00045081.bin 224 224 +43308 ./prep_dataset/ILSVRC2012_val_00002156.bin 224 224 +43309 ./prep_dataset/ILSVRC2012_val_00022347.bin 224 224 +43310 ./prep_dataset/ILSVRC2012_val_00016441.bin 224 224 +43311 ./prep_dataset/ILSVRC2012_val_00044591.bin 224 224 +43312 ./prep_dataset/ILSVRC2012_val_00024571.bin 224 224 +43313 ./prep_dataset/ILSVRC2012_val_00033159.bin 224 224 +43314 ./prep_dataset/ILSVRC2012_val_00000870.bin 224 224 +43315 ./prep_dataset/ILSVRC2012_val_00045492.bin 224 224 +43316 ./prep_dataset/ILSVRC2012_val_00033051.bin 224 224 +43317 ./prep_dataset/ILSVRC2012_val_00021025.bin 224 224 +43318 ./prep_dataset/ILSVRC2012_val_00020163.bin 224 224 +43319 ./prep_dataset/ILSVRC2012_val_00029985.bin 224 224 +43320 ./prep_dataset/ILSVRC2012_val_00007598.bin 224 224 +43321 ./prep_dataset/ILSVRC2012_val_00043894.bin 224 224 +43322 ./prep_dataset/ILSVRC2012_val_00024157.bin 224 224 +43323 ./prep_dataset/ILSVRC2012_val_00013444.bin 224 224 +43324 ./prep_dataset/ILSVRC2012_val_00037182.bin 224 224 +43325 ./prep_dataset/ILSVRC2012_val_00020734.bin 224 224 +43326 ./prep_dataset/ILSVRC2012_val_00019764.bin 224 224 +43327 ./prep_dataset/ILSVRC2012_val_00014597.bin 224 224 +43328 ./prep_dataset/ILSVRC2012_val_00006502.bin 224 224 +43329 ./prep_dataset/ILSVRC2012_val_00018712.bin 224 224 +43330 ./prep_dataset/ILSVRC2012_val_00000932.bin 224 224 +43331 ./prep_dataset/ILSVRC2012_val_00021719.bin 224 224 +43332 ./prep_dataset/ILSVRC2012_val_00031643.bin 224 224 +43333 ./prep_dataset/ILSVRC2012_val_00014793.bin 224 224 +43334 ./prep_dataset/ILSVRC2012_val_00013022.bin 224 224 +43335 ./prep_dataset/ILSVRC2012_val_00031687.bin 224 224 +43336 ./prep_dataset/ILSVRC2012_val_00001453.bin 224 224 +43337 ./prep_dataset/ILSVRC2012_val_00040668.bin 224 224 +43338 ./prep_dataset/ILSVRC2012_val_00035003.bin 224 224 +43339 ./prep_dataset/ILSVRC2012_val_00038528.bin 224 224 +43340 ./prep_dataset/ILSVRC2012_val_00007166.bin 224 224 +43341 ./prep_dataset/ILSVRC2012_val_00007573.bin 224 224 +43342 ./prep_dataset/ILSVRC2012_val_00041720.bin 224 224 +43343 ./prep_dataset/ILSVRC2012_val_00024798.bin 224 224 +43344 ./prep_dataset/ILSVRC2012_val_00023227.bin 224 224 +43345 ./prep_dataset/ILSVRC2012_val_00014487.bin 224 224 +43346 ./prep_dataset/ILSVRC2012_val_00010380.bin 224 224 +43347 ./prep_dataset/ILSVRC2012_val_00019373.bin 224 224 +43348 ./prep_dataset/ILSVRC2012_val_00029286.bin 224 224 +43349 ./prep_dataset/ILSVRC2012_val_00036110.bin 224 224 +43350 ./prep_dataset/ILSVRC2012_val_00004748.bin 224 224 +43351 ./prep_dataset/ILSVRC2012_val_00002170.bin 224 224 +43352 ./prep_dataset/ILSVRC2012_val_00027734.bin 224 224 +43353 ./prep_dataset/ILSVRC2012_val_00043736.bin 224 224 +43354 ./prep_dataset/ILSVRC2012_val_00041848.bin 224 224 +43355 ./prep_dataset/ILSVRC2012_val_00004986.bin 224 224 +43356 ./prep_dataset/ILSVRC2012_val_00026058.bin 224 224 +43357 ./prep_dataset/ILSVRC2012_val_00012808.bin 224 224 +43358 ./prep_dataset/ILSVRC2012_val_00049473.bin 224 224 +43359 ./prep_dataset/ILSVRC2012_val_00040866.bin 224 224 +43360 ./prep_dataset/ILSVRC2012_val_00044075.bin 224 224 +43361 ./prep_dataset/ILSVRC2012_val_00038774.bin 224 224 +43362 ./prep_dataset/ILSVRC2012_val_00005261.bin 224 224 +43363 ./prep_dataset/ILSVRC2012_val_00029393.bin 224 224 +43364 ./prep_dataset/ILSVRC2012_val_00025944.bin 224 224 +43365 ./prep_dataset/ILSVRC2012_val_00016732.bin 224 224 +43366 ./prep_dataset/ILSVRC2012_val_00045623.bin 224 224 +43367 ./prep_dataset/ILSVRC2012_val_00038493.bin 224 224 +43368 ./prep_dataset/ILSVRC2012_val_00039416.bin 224 224 +43369 ./prep_dataset/ILSVRC2012_val_00043250.bin 224 224 +43370 ./prep_dataset/ILSVRC2012_val_00012544.bin 224 224 +43371 ./prep_dataset/ILSVRC2012_val_00014827.bin 224 224 +43372 ./prep_dataset/ILSVRC2012_val_00035411.bin 224 224 +43373 ./prep_dataset/ILSVRC2012_val_00014819.bin 224 224 +43374 ./prep_dataset/ILSVRC2012_val_00033204.bin 224 224 +43375 ./prep_dataset/ILSVRC2012_val_00018297.bin 224 224 +43376 ./prep_dataset/ILSVRC2012_val_00009474.bin 224 224 +43377 ./prep_dataset/ILSVRC2012_val_00044573.bin 224 224 +43378 ./prep_dataset/ILSVRC2012_val_00007310.bin 224 224 +43379 ./prep_dataset/ILSVRC2012_val_00018412.bin 224 224 +43380 ./prep_dataset/ILSVRC2012_val_00007138.bin 224 224 +43381 ./prep_dataset/ILSVRC2012_val_00047863.bin 224 224 +43382 ./prep_dataset/ILSVRC2012_val_00008929.bin 224 224 +43383 ./prep_dataset/ILSVRC2012_val_00002079.bin 224 224 +43384 ./prep_dataset/ILSVRC2012_val_00013951.bin 224 224 +43385 ./prep_dataset/ILSVRC2012_val_00049913.bin 224 224 +43386 ./prep_dataset/ILSVRC2012_val_00041513.bin 224 224 +43387 ./prep_dataset/ILSVRC2012_val_00022328.bin 224 224 +43388 ./prep_dataset/ILSVRC2012_val_00003176.bin 224 224 +43389 ./prep_dataset/ILSVRC2012_val_00001494.bin 224 224 +43390 ./prep_dataset/ILSVRC2012_val_00046330.bin 224 224 +43391 ./prep_dataset/ILSVRC2012_val_00014799.bin 224 224 +43392 ./prep_dataset/ILSVRC2012_val_00037641.bin 224 224 +43393 ./prep_dataset/ILSVRC2012_val_00029991.bin 224 224 +43394 ./prep_dataset/ILSVRC2012_val_00022750.bin 224 224 +43395 ./prep_dataset/ILSVRC2012_val_00009336.bin 224 224 +43396 ./prep_dataset/ILSVRC2012_val_00039395.bin 224 224 +43397 ./prep_dataset/ILSVRC2012_val_00024702.bin 224 224 +43398 ./prep_dataset/ILSVRC2012_val_00036554.bin 224 224 +43399 ./prep_dataset/ILSVRC2012_val_00042932.bin 224 224 +43400 ./prep_dataset/ILSVRC2012_val_00011544.bin 224 224 +43401 ./prep_dataset/ILSVRC2012_val_00006441.bin 224 224 +43402 ./prep_dataset/ILSVRC2012_val_00020203.bin 224 224 +43403 ./prep_dataset/ILSVRC2012_val_00013050.bin 224 224 +43404 ./prep_dataset/ILSVRC2012_val_00013559.bin 224 224 +43405 ./prep_dataset/ILSVRC2012_val_00012966.bin 224 224 +43406 ./prep_dataset/ILSVRC2012_val_00010882.bin 224 224 +43407 ./prep_dataset/ILSVRC2012_val_00013699.bin 224 224 +43408 ./prep_dataset/ILSVRC2012_val_00000099.bin 224 224 +43409 ./prep_dataset/ILSVRC2012_val_00019778.bin 224 224 +43410 ./prep_dataset/ILSVRC2012_val_00034925.bin 224 224 +43411 ./prep_dataset/ILSVRC2012_val_00006109.bin 224 224 +43412 ./prep_dataset/ILSVRC2012_val_00036594.bin 224 224 +43413 ./prep_dataset/ILSVRC2012_val_00013756.bin 224 224 +43414 ./prep_dataset/ILSVRC2012_val_00049878.bin 224 224 +43415 ./prep_dataset/ILSVRC2012_val_00048471.bin 224 224 +43416 ./prep_dataset/ILSVRC2012_val_00040880.bin 224 224 +43417 ./prep_dataset/ILSVRC2012_val_00043820.bin 224 224 +43418 ./prep_dataset/ILSVRC2012_val_00035201.bin 224 224 +43419 ./prep_dataset/ILSVRC2012_val_00039475.bin 224 224 +43420 ./prep_dataset/ILSVRC2012_val_00039046.bin 224 224 +43421 ./prep_dataset/ILSVRC2012_val_00015577.bin 224 224 +43422 ./prep_dataset/ILSVRC2012_val_00015926.bin 224 224 +43423 ./prep_dataset/ILSVRC2012_val_00008486.bin 224 224 +43424 ./prep_dataset/ILSVRC2012_val_00037826.bin 224 224 +43425 ./prep_dataset/ILSVRC2012_val_00002616.bin 224 224 +43426 ./prep_dataset/ILSVRC2012_val_00002376.bin 224 224 +43427 ./prep_dataset/ILSVRC2012_val_00033665.bin 224 224 +43428 ./prep_dataset/ILSVRC2012_val_00018258.bin 224 224 +43429 ./prep_dataset/ILSVRC2012_val_00036786.bin 224 224 +43430 ./prep_dataset/ILSVRC2012_val_00029973.bin 224 224 +43431 ./prep_dataset/ILSVRC2012_val_00009267.bin 224 224 +43432 ./prep_dataset/ILSVRC2012_val_00025197.bin 224 224 +43433 ./prep_dataset/ILSVRC2012_val_00008749.bin 224 224 +43434 ./prep_dataset/ILSVRC2012_val_00034887.bin 224 224 +43435 ./prep_dataset/ILSVRC2012_val_00030920.bin 224 224 +43436 ./prep_dataset/ILSVRC2012_val_00030363.bin 224 224 +43437 ./prep_dataset/ILSVRC2012_val_00013926.bin 224 224 +43438 ./prep_dataset/ILSVRC2012_val_00033826.bin 224 224 +43439 ./prep_dataset/ILSVRC2012_val_00017706.bin 224 224 +43440 ./prep_dataset/ILSVRC2012_val_00023549.bin 224 224 +43441 ./prep_dataset/ILSVRC2012_val_00047922.bin 224 224 +43442 ./prep_dataset/ILSVRC2012_val_00023541.bin 224 224 +43443 ./prep_dataset/ILSVRC2012_val_00026464.bin 224 224 +43444 ./prep_dataset/ILSVRC2012_val_00029125.bin 224 224 +43445 ./prep_dataset/ILSVRC2012_val_00029160.bin 224 224 +43446 ./prep_dataset/ILSVRC2012_val_00026337.bin 224 224 +43447 ./prep_dataset/ILSVRC2012_val_00018878.bin 224 224 +43448 ./prep_dataset/ILSVRC2012_val_00033499.bin 224 224 +43449 ./prep_dataset/ILSVRC2012_val_00030053.bin 224 224 +43450 ./prep_dataset/ILSVRC2012_val_00039594.bin 224 224 +43451 ./prep_dataset/ILSVRC2012_val_00023513.bin 224 224 +43452 ./prep_dataset/ILSVRC2012_val_00046626.bin 224 224 +43453 ./prep_dataset/ILSVRC2012_val_00042628.bin 224 224 +43454 ./prep_dataset/ILSVRC2012_val_00030560.bin 224 224 +43455 ./prep_dataset/ILSVRC2012_val_00015412.bin 224 224 +43456 ./prep_dataset/ILSVRC2012_val_00017608.bin 224 224 +43457 ./prep_dataset/ILSVRC2012_val_00037212.bin 224 224 +43458 ./prep_dataset/ILSVRC2012_val_00038255.bin 224 224 +43459 ./prep_dataset/ILSVRC2012_val_00027063.bin 224 224 +43460 ./prep_dataset/ILSVRC2012_val_00043438.bin 224 224 +43461 ./prep_dataset/ILSVRC2012_val_00021395.bin 224 224 +43462 ./prep_dataset/ILSVRC2012_val_00038488.bin 224 224 +43463 ./prep_dataset/ILSVRC2012_val_00040459.bin 224 224 +43464 ./prep_dataset/ILSVRC2012_val_00047956.bin 224 224 +43465 ./prep_dataset/ILSVRC2012_val_00027095.bin 224 224 +43466 ./prep_dataset/ILSVRC2012_val_00002423.bin 224 224 +43467 ./prep_dataset/ILSVRC2012_val_00009328.bin 224 224 +43468 ./prep_dataset/ILSVRC2012_val_00016583.bin 224 224 +43469 ./prep_dataset/ILSVRC2012_val_00046261.bin 224 224 +43470 ./prep_dataset/ILSVRC2012_val_00019590.bin 224 224 +43471 ./prep_dataset/ILSVRC2012_val_00013008.bin 224 224 +43472 ./prep_dataset/ILSVRC2012_val_00036536.bin 224 224 +43473 ./prep_dataset/ILSVRC2012_val_00006182.bin 224 224 +43474 ./prep_dataset/ILSVRC2012_val_00011896.bin 224 224 +43475 ./prep_dataset/ILSVRC2012_val_00008548.bin 224 224 +43476 ./prep_dataset/ILSVRC2012_val_00021556.bin 224 224 +43477 ./prep_dataset/ILSVRC2012_val_00010691.bin 224 224 +43478 ./prep_dataset/ILSVRC2012_val_00013668.bin 224 224 +43479 ./prep_dataset/ILSVRC2012_val_00005468.bin 224 224 +43480 ./prep_dataset/ILSVRC2012_val_00041710.bin 224 224 +43481 ./prep_dataset/ILSVRC2012_val_00031109.bin 224 224 +43482 ./prep_dataset/ILSVRC2012_val_00048394.bin 224 224 +43483 ./prep_dataset/ILSVRC2012_val_00038984.bin 224 224 +43484 ./prep_dataset/ILSVRC2012_val_00035524.bin 224 224 +43485 ./prep_dataset/ILSVRC2012_val_00046396.bin 224 224 +43486 ./prep_dataset/ILSVRC2012_val_00015843.bin 224 224 +43487 ./prep_dataset/ILSVRC2012_val_00040879.bin 224 224 +43488 ./prep_dataset/ILSVRC2012_val_00033579.bin 224 224 +43489 ./prep_dataset/ILSVRC2012_val_00048654.bin 224 224 +43490 ./prep_dataset/ILSVRC2012_val_00040519.bin 224 224 +43491 ./prep_dataset/ILSVRC2012_val_00023656.bin 224 224 +43492 ./prep_dataset/ILSVRC2012_val_00008962.bin 224 224 +43493 ./prep_dataset/ILSVRC2012_val_00003383.bin 224 224 +43494 ./prep_dataset/ILSVRC2012_val_00027770.bin 224 224 +43495 ./prep_dataset/ILSVRC2012_val_00038154.bin 224 224 +43496 ./prep_dataset/ILSVRC2012_val_00026671.bin 224 224 +43497 ./prep_dataset/ILSVRC2012_val_00005812.bin 224 224 +43498 ./prep_dataset/ILSVRC2012_val_00006118.bin 224 224 +43499 ./prep_dataset/ILSVRC2012_val_00023082.bin 224 224 +43500 ./prep_dataset/ILSVRC2012_val_00013735.bin 224 224 +43501 ./prep_dataset/ILSVRC2012_val_00034503.bin 224 224 +43502 ./prep_dataset/ILSVRC2012_val_00014269.bin 224 224 +43503 ./prep_dataset/ILSVRC2012_val_00025263.bin 224 224 +43504 ./prep_dataset/ILSVRC2012_val_00041944.bin 224 224 +43505 ./prep_dataset/ILSVRC2012_val_00011872.bin 224 224 +43506 ./prep_dataset/ILSVRC2012_val_00003265.bin 224 224 +43507 ./prep_dataset/ILSVRC2012_val_00000293.bin 224 224 +43508 ./prep_dataset/ILSVRC2012_val_00042199.bin 224 224 +43509 ./prep_dataset/ILSVRC2012_val_00048166.bin 224 224 +43510 ./prep_dataset/ILSVRC2012_val_00015775.bin 224 224 +43511 ./prep_dataset/ILSVRC2012_val_00010311.bin 224 224 +43512 ./prep_dataset/ILSVRC2012_val_00000141.bin 224 224 +43513 ./prep_dataset/ILSVRC2012_val_00043798.bin 224 224 +43514 ./prep_dataset/ILSVRC2012_val_00020807.bin 224 224 +43515 ./prep_dataset/ILSVRC2012_val_00049448.bin 224 224 +43516 ./prep_dataset/ILSVRC2012_val_00036603.bin 224 224 +43517 ./prep_dataset/ILSVRC2012_val_00036738.bin 224 224 +43518 ./prep_dataset/ILSVRC2012_val_00044586.bin 224 224 +43519 ./prep_dataset/ILSVRC2012_val_00009339.bin 224 224 +43520 ./prep_dataset/ILSVRC2012_val_00032296.bin 224 224 +43521 ./prep_dataset/ILSVRC2012_val_00009577.bin 224 224 +43522 ./prep_dataset/ILSVRC2012_val_00037004.bin 224 224 +43523 ./prep_dataset/ILSVRC2012_val_00039755.bin 224 224 +43524 ./prep_dataset/ILSVRC2012_val_00038537.bin 224 224 +43525 ./prep_dataset/ILSVRC2012_val_00035253.bin 224 224 +43526 ./prep_dataset/ILSVRC2012_val_00033553.bin 224 224 +43527 ./prep_dataset/ILSVRC2012_val_00044013.bin 224 224 +43528 ./prep_dataset/ILSVRC2012_val_00029651.bin 224 224 +43529 ./prep_dataset/ILSVRC2012_val_00037594.bin 224 224 +43530 ./prep_dataset/ILSVRC2012_val_00024200.bin 224 224 +43531 ./prep_dataset/ILSVRC2012_val_00005211.bin 224 224 +43532 ./prep_dataset/ILSVRC2012_val_00006995.bin 224 224 +43533 ./prep_dataset/ILSVRC2012_val_00037098.bin 224 224 +43534 ./prep_dataset/ILSVRC2012_val_00047712.bin 224 224 +43535 ./prep_dataset/ILSVRC2012_val_00006437.bin 224 224 +43536 ./prep_dataset/ILSVRC2012_val_00042379.bin 224 224 +43537 ./prep_dataset/ILSVRC2012_val_00031030.bin 224 224 +43538 ./prep_dataset/ILSVRC2012_val_00017083.bin 224 224 +43539 ./prep_dataset/ILSVRC2012_val_00020662.bin 224 224 +43540 ./prep_dataset/ILSVRC2012_val_00034342.bin 224 224 +43541 ./prep_dataset/ILSVRC2012_val_00036253.bin 224 224 +43542 ./prep_dataset/ILSVRC2012_val_00002374.bin 224 224 +43543 ./prep_dataset/ILSVRC2012_val_00027838.bin 224 224 +43544 ./prep_dataset/ILSVRC2012_val_00011966.bin 224 224 +43545 ./prep_dataset/ILSVRC2012_val_00021577.bin 224 224 +43546 ./prep_dataset/ILSVRC2012_val_00035399.bin 224 224 +43547 ./prep_dataset/ILSVRC2012_val_00038620.bin 224 224 +43548 ./prep_dataset/ILSVRC2012_val_00006887.bin 224 224 +43549 ./prep_dataset/ILSVRC2012_val_00031813.bin 224 224 +43550 ./prep_dataset/ILSVRC2012_val_00029901.bin 224 224 +43551 ./prep_dataset/ILSVRC2012_val_00021777.bin 224 224 +43552 ./prep_dataset/ILSVRC2012_val_00029884.bin 224 224 +43553 ./prep_dataset/ILSVRC2012_val_00026305.bin 224 224 +43554 ./prep_dataset/ILSVRC2012_val_00015004.bin 224 224 +43555 ./prep_dataset/ILSVRC2012_val_00041910.bin 224 224 +43556 ./prep_dataset/ILSVRC2012_val_00003718.bin 224 224 +43557 ./prep_dataset/ILSVRC2012_val_00004915.bin 224 224 +43558 ./prep_dataset/ILSVRC2012_val_00037469.bin 224 224 +43559 ./prep_dataset/ILSVRC2012_val_00046883.bin 224 224 +43560 ./prep_dataset/ILSVRC2012_val_00008369.bin 224 224 +43561 ./prep_dataset/ILSVRC2012_val_00013823.bin 224 224 +43562 ./prep_dataset/ILSVRC2012_val_00044810.bin 224 224 +43563 ./prep_dataset/ILSVRC2012_val_00047596.bin 224 224 +43564 ./prep_dataset/ILSVRC2012_val_00018631.bin 224 224 +43565 ./prep_dataset/ILSVRC2012_val_00046011.bin 224 224 +43566 ./prep_dataset/ILSVRC2012_val_00047591.bin 224 224 +43567 ./prep_dataset/ILSVRC2012_val_00014008.bin 224 224 +43568 ./prep_dataset/ILSVRC2012_val_00034494.bin 224 224 +43569 ./prep_dataset/ILSVRC2012_val_00000115.bin 224 224 +43570 ./prep_dataset/ILSVRC2012_val_00007731.bin 224 224 +43571 ./prep_dataset/ILSVRC2012_val_00045652.bin 224 224 +43572 ./prep_dataset/ILSVRC2012_val_00044029.bin 224 224 +43573 ./prep_dataset/ILSVRC2012_val_00000301.bin 224 224 +43574 ./prep_dataset/ILSVRC2012_val_00023608.bin 224 224 +43575 ./prep_dataset/ILSVRC2012_val_00017283.bin 224 224 +43576 ./prep_dataset/ILSVRC2012_val_00044176.bin 224 224 +43577 ./prep_dataset/ILSVRC2012_val_00014915.bin 224 224 +43578 ./prep_dataset/ILSVRC2012_val_00008255.bin 224 224 +43579 ./prep_dataset/ILSVRC2012_val_00003064.bin 224 224 +43580 ./prep_dataset/ILSVRC2012_val_00039436.bin 224 224 +43581 ./prep_dataset/ILSVRC2012_val_00011449.bin 224 224 +43582 ./prep_dataset/ILSVRC2012_val_00025334.bin 224 224 +43583 ./prep_dataset/ILSVRC2012_val_00037431.bin 224 224 +43584 ./prep_dataset/ILSVRC2012_val_00026356.bin 224 224 +43585 ./prep_dataset/ILSVRC2012_val_00025114.bin 224 224 +43586 ./prep_dataset/ILSVRC2012_val_00046332.bin 224 224 +43587 ./prep_dataset/ILSVRC2012_val_00007315.bin 224 224 +43588 ./prep_dataset/ILSVRC2012_val_00042407.bin 224 224 +43589 ./prep_dataset/ILSVRC2012_val_00001219.bin 224 224 +43590 ./prep_dataset/ILSVRC2012_val_00041619.bin 224 224 +43591 ./prep_dataset/ILSVRC2012_val_00048141.bin 224 224 +43592 ./prep_dataset/ILSVRC2012_val_00023081.bin 224 224 +43593 ./prep_dataset/ILSVRC2012_val_00019227.bin 224 224 +43594 ./prep_dataset/ILSVRC2012_val_00029232.bin 224 224 +43595 ./prep_dataset/ILSVRC2012_val_00026872.bin 224 224 +43596 ./prep_dataset/ILSVRC2012_val_00019019.bin 224 224 +43597 ./prep_dataset/ILSVRC2012_val_00045598.bin 224 224 +43598 ./prep_dataset/ILSVRC2012_val_00019448.bin 224 224 +43599 ./prep_dataset/ILSVRC2012_val_00030211.bin 224 224 +43600 ./prep_dataset/ILSVRC2012_val_00018575.bin 224 224 +43601 ./prep_dataset/ILSVRC2012_val_00013673.bin 224 224 +43602 ./prep_dataset/ILSVRC2012_val_00039689.bin 224 224 +43603 ./prep_dataset/ILSVRC2012_val_00032867.bin 224 224 +43604 ./prep_dataset/ILSVRC2012_val_00034597.bin 224 224 +43605 ./prep_dataset/ILSVRC2012_val_00030398.bin 224 224 +43606 ./prep_dataset/ILSVRC2012_val_00031982.bin 224 224 +43607 ./prep_dataset/ILSVRC2012_val_00007319.bin 224 224 +43608 ./prep_dataset/ILSVRC2012_val_00004135.bin 224 224 +43609 ./prep_dataset/ILSVRC2012_val_00026204.bin 224 224 +43610 ./prep_dataset/ILSVRC2012_val_00044346.bin 224 224 +43611 ./prep_dataset/ILSVRC2012_val_00038495.bin 224 224 +43612 ./prep_dataset/ILSVRC2012_val_00018138.bin 224 224 +43613 ./prep_dataset/ILSVRC2012_val_00006843.bin 224 224 +43614 ./prep_dataset/ILSVRC2012_val_00013911.bin 224 224 +43615 ./prep_dataset/ILSVRC2012_val_00034388.bin 224 224 +43616 ./prep_dataset/ILSVRC2012_val_00000876.bin 224 224 +43617 ./prep_dataset/ILSVRC2012_val_00001495.bin 224 224 +43618 ./prep_dataset/ILSVRC2012_val_00004063.bin 224 224 +43619 ./prep_dataset/ILSVRC2012_val_00018717.bin 224 224 +43620 ./prep_dataset/ILSVRC2012_val_00013918.bin 224 224 +43621 ./prep_dataset/ILSVRC2012_val_00010191.bin 224 224 +43622 ./prep_dataset/ILSVRC2012_val_00020873.bin 224 224 +43623 ./prep_dataset/ILSVRC2012_val_00000730.bin 224 224 +43624 ./prep_dataset/ILSVRC2012_val_00028676.bin 224 224 +43625 ./prep_dataset/ILSVRC2012_val_00034028.bin 224 224 +43626 ./prep_dataset/ILSVRC2012_val_00024959.bin 224 224 +43627 ./prep_dataset/ILSVRC2012_val_00024225.bin 224 224 +43628 ./prep_dataset/ILSVRC2012_val_00020560.bin 224 224 +43629 ./prep_dataset/ILSVRC2012_val_00019305.bin 224 224 +43630 ./prep_dataset/ILSVRC2012_val_00025059.bin 224 224 +43631 ./prep_dataset/ILSVRC2012_val_00016299.bin 224 224 +43632 ./prep_dataset/ILSVRC2012_val_00037318.bin 224 224 +43633 ./prep_dataset/ILSVRC2012_val_00024663.bin 224 224 +43634 ./prep_dataset/ILSVRC2012_val_00018578.bin 224 224 +43635 ./prep_dataset/ILSVRC2012_val_00020815.bin 224 224 +43636 ./prep_dataset/ILSVRC2012_val_00025885.bin 224 224 +43637 ./prep_dataset/ILSVRC2012_val_00019928.bin 224 224 +43638 ./prep_dataset/ILSVRC2012_val_00039954.bin 224 224 +43639 ./prep_dataset/ILSVRC2012_val_00026593.bin 224 224 +43640 ./prep_dataset/ILSVRC2012_val_00017754.bin 224 224 +43641 ./prep_dataset/ILSVRC2012_val_00015506.bin 224 224 +43642 ./prep_dataset/ILSVRC2012_val_00000529.bin 224 224 +43643 ./prep_dataset/ILSVRC2012_val_00031429.bin 224 224 +43644 ./prep_dataset/ILSVRC2012_val_00041773.bin 224 224 +43645 ./prep_dataset/ILSVRC2012_val_00016078.bin 224 224 +43646 ./prep_dataset/ILSVRC2012_val_00012532.bin 224 224 +43647 ./prep_dataset/ILSVRC2012_val_00024335.bin 224 224 +43648 ./prep_dataset/ILSVRC2012_val_00039637.bin 224 224 +43649 ./prep_dataset/ILSVRC2012_val_00017483.bin 224 224 +43650 ./prep_dataset/ILSVRC2012_val_00027409.bin 224 224 +43651 ./prep_dataset/ILSVRC2012_val_00027773.bin 224 224 +43652 ./prep_dataset/ILSVRC2012_val_00030162.bin 224 224 +43653 ./prep_dataset/ILSVRC2012_val_00029463.bin 224 224 +43654 ./prep_dataset/ILSVRC2012_val_00008515.bin 224 224 +43655 ./prep_dataset/ILSVRC2012_val_00000886.bin 224 224 +43656 ./prep_dataset/ILSVRC2012_val_00030384.bin 224 224 +43657 ./prep_dataset/ILSVRC2012_val_00016410.bin 224 224 +43658 ./prep_dataset/ILSVRC2012_val_00033253.bin 224 224 +43659 ./prep_dataset/ILSVRC2012_val_00025896.bin 224 224 +43660 ./prep_dataset/ILSVRC2012_val_00013807.bin 224 224 +43661 ./prep_dataset/ILSVRC2012_val_00027813.bin 224 224 +43662 ./prep_dataset/ILSVRC2012_val_00009986.bin 224 224 +43663 ./prep_dataset/ILSVRC2012_val_00000591.bin 224 224 +43664 ./prep_dataset/ILSVRC2012_val_00016165.bin 224 224 +43665 ./prep_dataset/ILSVRC2012_val_00039831.bin 224 224 +43666 ./prep_dataset/ILSVRC2012_val_00036275.bin 224 224 +43667 ./prep_dataset/ILSVRC2012_val_00046077.bin 224 224 +43668 ./prep_dataset/ILSVRC2012_val_00046585.bin 224 224 +43669 ./prep_dataset/ILSVRC2012_val_00015792.bin 224 224 +43670 ./prep_dataset/ILSVRC2012_val_00015836.bin 224 224 +43671 ./prep_dataset/ILSVRC2012_val_00027747.bin 224 224 +43672 ./prep_dataset/ILSVRC2012_val_00005408.bin 224 224 +43673 ./prep_dataset/ILSVRC2012_val_00022201.bin 224 224 +43674 ./prep_dataset/ILSVRC2012_val_00014909.bin 224 224 +43675 ./prep_dataset/ILSVRC2012_val_00000505.bin 224 224 +43676 ./prep_dataset/ILSVRC2012_val_00004344.bin 224 224 +43677 ./prep_dataset/ILSVRC2012_val_00014908.bin 224 224 +43678 ./prep_dataset/ILSVRC2012_val_00012343.bin 224 224 +43679 ./prep_dataset/ILSVRC2012_val_00007483.bin 224 224 +43680 ./prep_dataset/ILSVRC2012_val_00031590.bin 224 224 +43681 ./prep_dataset/ILSVRC2012_val_00016906.bin 224 224 +43682 ./prep_dataset/ILSVRC2012_val_00040666.bin 224 224 +43683 ./prep_dataset/ILSVRC2012_val_00016311.bin 224 224 +43684 ./prep_dataset/ILSVRC2012_val_00021169.bin 224 224 +43685 ./prep_dataset/ILSVRC2012_val_00038593.bin 224 224 +43686 ./prep_dataset/ILSVRC2012_val_00037459.bin 224 224 +43687 ./prep_dataset/ILSVRC2012_val_00001991.bin 224 224 +43688 ./prep_dataset/ILSVRC2012_val_00044310.bin 224 224 +43689 ./prep_dataset/ILSVRC2012_val_00006062.bin 224 224 +43690 ./prep_dataset/ILSVRC2012_val_00042411.bin 224 224 +43691 ./prep_dataset/ILSVRC2012_val_00033716.bin 224 224 +43692 ./prep_dataset/ILSVRC2012_val_00049488.bin 224 224 +43693 ./prep_dataset/ILSVRC2012_val_00000416.bin 224 224 +43694 ./prep_dataset/ILSVRC2012_val_00008347.bin 224 224 +43695 ./prep_dataset/ILSVRC2012_val_00037802.bin 224 224 +43696 ./prep_dataset/ILSVRC2012_val_00045806.bin 224 224 +43697 ./prep_dataset/ILSVRC2012_val_00042449.bin 224 224 +43698 ./prep_dataset/ILSVRC2012_val_00035901.bin 224 224 +43699 ./prep_dataset/ILSVRC2012_val_00013158.bin 224 224 +43700 ./prep_dataset/ILSVRC2012_val_00036645.bin 224 224 +43701 ./prep_dataset/ILSVRC2012_val_00015922.bin 224 224 +43702 ./prep_dataset/ILSVRC2012_val_00007535.bin 224 224 +43703 ./prep_dataset/ILSVRC2012_val_00036717.bin 224 224 +43704 ./prep_dataset/ILSVRC2012_val_00028596.bin 224 224 +43705 ./prep_dataset/ILSVRC2012_val_00009418.bin 224 224 +43706 ./prep_dataset/ILSVRC2012_val_00008312.bin 224 224 +43707 ./prep_dataset/ILSVRC2012_val_00047039.bin 224 224 +43708 ./prep_dataset/ILSVRC2012_val_00046818.bin 224 224 +43709 ./prep_dataset/ILSVRC2012_val_00022192.bin 224 224 +43710 ./prep_dataset/ILSVRC2012_val_00044685.bin 224 224 +43711 ./prep_dataset/ILSVRC2012_val_00020127.bin 224 224 +43712 ./prep_dataset/ILSVRC2012_val_00011343.bin 224 224 +43713 ./prep_dataset/ILSVRC2012_val_00017261.bin 224 224 +43714 ./prep_dataset/ILSVRC2012_val_00000442.bin 224 224 +43715 ./prep_dataset/ILSVRC2012_val_00002771.bin 224 224 +43716 ./prep_dataset/ILSVRC2012_val_00029892.bin 224 224 +43717 ./prep_dataset/ILSVRC2012_val_00022140.bin 224 224 +43718 ./prep_dataset/ILSVRC2012_val_00030419.bin 224 224 +43719 ./prep_dataset/ILSVRC2012_val_00020888.bin 224 224 +43720 ./prep_dataset/ILSVRC2012_val_00037433.bin 224 224 +43721 ./prep_dataset/ILSVRC2012_val_00014954.bin 224 224 +43722 ./prep_dataset/ILSVRC2012_val_00008708.bin 224 224 +43723 ./prep_dataset/ILSVRC2012_val_00043202.bin 224 224 +43724 ./prep_dataset/ILSVRC2012_val_00045310.bin 224 224 +43725 ./prep_dataset/ILSVRC2012_val_00013450.bin 224 224 +43726 ./prep_dataset/ILSVRC2012_val_00048443.bin 224 224 +43727 ./prep_dataset/ILSVRC2012_val_00010579.bin 224 224 +43728 ./prep_dataset/ILSVRC2012_val_00029364.bin 224 224 +43729 ./prep_dataset/ILSVRC2012_val_00008107.bin 224 224 +43730 ./prep_dataset/ILSVRC2012_val_00035547.bin 224 224 +43731 ./prep_dataset/ILSVRC2012_val_00004921.bin 224 224 +43732 ./prep_dataset/ILSVRC2012_val_00039815.bin 224 224 +43733 ./prep_dataset/ILSVRC2012_val_00013264.bin 224 224 +43734 ./prep_dataset/ILSVRC2012_val_00015046.bin 224 224 +43735 ./prep_dataset/ILSVRC2012_val_00029226.bin 224 224 +43736 ./prep_dataset/ILSVRC2012_val_00038559.bin 224 224 +43737 ./prep_dataset/ILSVRC2012_val_00025568.bin 224 224 +43738 ./prep_dataset/ILSVRC2012_val_00007737.bin 224 224 +43739 ./prep_dataset/ILSVRC2012_val_00006095.bin 224 224 +43740 ./prep_dataset/ILSVRC2012_val_00040002.bin 224 224 +43741 ./prep_dataset/ILSVRC2012_val_00048104.bin 224 224 +43742 ./prep_dataset/ILSVRC2012_val_00002420.bin 224 224 +43743 ./prep_dataset/ILSVRC2012_val_00026735.bin 224 224 +43744 ./prep_dataset/ILSVRC2012_val_00049278.bin 224 224 +43745 ./prep_dataset/ILSVRC2012_val_00047709.bin 224 224 +43746 ./prep_dataset/ILSVRC2012_val_00003476.bin 224 224 +43747 ./prep_dataset/ILSVRC2012_val_00026473.bin 224 224 +43748 ./prep_dataset/ILSVRC2012_val_00030935.bin 224 224 +43749 ./prep_dataset/ILSVRC2012_val_00001280.bin 224 224 +43750 ./prep_dataset/ILSVRC2012_val_00021155.bin 224 224 +43751 ./prep_dataset/ILSVRC2012_val_00002580.bin 224 224 +43752 ./prep_dataset/ILSVRC2012_val_00018240.bin 224 224 +43753 ./prep_dataset/ILSVRC2012_val_00009662.bin 224 224 +43754 ./prep_dataset/ILSVRC2012_val_00033461.bin 224 224 +43755 ./prep_dataset/ILSVRC2012_val_00046408.bin 224 224 +43756 ./prep_dataset/ILSVRC2012_val_00032396.bin 224 224 +43757 ./prep_dataset/ILSVRC2012_val_00046007.bin 224 224 +43758 ./prep_dataset/ILSVRC2012_val_00009780.bin 224 224 +43759 ./prep_dataset/ILSVRC2012_val_00043055.bin 224 224 +43760 ./prep_dataset/ILSVRC2012_val_00035001.bin 224 224 +43761 ./prep_dataset/ILSVRC2012_val_00035185.bin 224 224 +43762 ./prep_dataset/ILSVRC2012_val_00048835.bin 224 224 +43763 ./prep_dataset/ILSVRC2012_val_00035870.bin 224 224 +43764 ./prep_dataset/ILSVRC2012_val_00021239.bin 224 224 +43765 ./prep_dataset/ILSVRC2012_val_00044515.bin 224 224 +43766 ./prep_dataset/ILSVRC2012_val_00023256.bin 224 224 +43767 ./prep_dataset/ILSVRC2012_val_00012789.bin 224 224 +43768 ./prep_dataset/ILSVRC2012_val_00008169.bin 224 224 +43769 ./prep_dataset/ILSVRC2012_val_00030694.bin 224 224 +43770 ./prep_dataset/ILSVRC2012_val_00022679.bin 224 224 +43771 ./prep_dataset/ILSVRC2012_val_00043731.bin 224 224 +43772 ./prep_dataset/ILSVRC2012_val_00013897.bin 224 224 +43773 ./prep_dataset/ILSVRC2012_val_00022349.bin 224 224 +43774 ./prep_dataset/ILSVRC2012_val_00014814.bin 224 224 +43775 ./prep_dataset/ILSVRC2012_val_00027497.bin 224 224 +43776 ./prep_dataset/ILSVRC2012_val_00044790.bin 224 224 +43777 ./prep_dataset/ILSVRC2012_val_00029842.bin 224 224 +43778 ./prep_dataset/ILSVRC2012_val_00048564.bin 224 224 +43779 ./prep_dataset/ILSVRC2012_val_00010819.bin 224 224 +43780 ./prep_dataset/ILSVRC2012_val_00044567.bin 224 224 +43781 ./prep_dataset/ILSVRC2012_val_00002569.bin 224 224 +43782 ./prep_dataset/ILSVRC2012_val_00014272.bin 224 224 +43783 ./prep_dataset/ILSVRC2012_val_00018053.bin 224 224 +43784 ./prep_dataset/ILSVRC2012_val_00040653.bin 224 224 +43785 ./prep_dataset/ILSVRC2012_val_00003385.bin 224 224 +43786 ./prep_dataset/ILSVRC2012_val_00032101.bin 224 224 +43787 ./prep_dataset/ILSVRC2012_val_00013665.bin 224 224 +43788 ./prep_dataset/ILSVRC2012_val_00041618.bin 224 224 +43789 ./prep_dataset/ILSVRC2012_val_00011360.bin 224 224 +43790 ./prep_dataset/ILSVRC2012_val_00028489.bin 224 224 +43791 ./prep_dataset/ILSVRC2012_val_00008283.bin 224 224 +43792 ./prep_dataset/ILSVRC2012_val_00041313.bin 224 224 +43793 ./prep_dataset/ILSVRC2012_val_00027357.bin 224 224 +43794 ./prep_dataset/ILSVRC2012_val_00047567.bin 224 224 +43795 ./prep_dataset/ILSVRC2012_val_00015295.bin 224 224 +43796 ./prep_dataset/ILSVRC2012_val_00014542.bin 224 224 +43797 ./prep_dataset/ILSVRC2012_val_00031115.bin 224 224 +43798 ./prep_dataset/ILSVRC2012_val_00009470.bin 224 224 +43799 ./prep_dataset/ILSVRC2012_val_00029641.bin 224 224 +43800 ./prep_dataset/ILSVRC2012_val_00023792.bin 224 224 +43801 ./prep_dataset/ILSVRC2012_val_00037705.bin 224 224 +43802 ./prep_dataset/ILSVRC2012_val_00023996.bin 224 224 +43803 ./prep_dataset/ILSVRC2012_val_00003192.bin 224 224 +43804 ./prep_dataset/ILSVRC2012_val_00034789.bin 224 224 +43805 ./prep_dataset/ILSVRC2012_val_00026679.bin 224 224 +43806 ./prep_dataset/ILSVRC2012_val_00003314.bin 224 224 +43807 ./prep_dataset/ILSVRC2012_val_00001845.bin 224 224 +43808 ./prep_dataset/ILSVRC2012_val_00018765.bin 224 224 +43809 ./prep_dataset/ILSVRC2012_val_00047499.bin 224 224 +43810 ./prep_dataset/ILSVRC2012_val_00001047.bin 224 224 +43811 ./prep_dataset/ILSVRC2012_val_00028696.bin 224 224 +43812 ./prep_dataset/ILSVRC2012_val_00047156.bin 224 224 +43813 ./prep_dataset/ILSVRC2012_val_00021716.bin 224 224 +43814 ./prep_dataset/ILSVRC2012_val_00013248.bin 224 224 +43815 ./prep_dataset/ILSVRC2012_val_00023242.bin 224 224 +43816 ./prep_dataset/ILSVRC2012_val_00036902.bin 224 224 +43817 ./prep_dataset/ILSVRC2012_val_00021559.bin 224 224 +43818 ./prep_dataset/ILSVRC2012_val_00024681.bin 224 224 +43819 ./prep_dataset/ILSVRC2012_val_00037383.bin 224 224 +43820 ./prep_dataset/ILSVRC2012_val_00046627.bin 224 224 +43821 ./prep_dataset/ILSVRC2012_val_00043221.bin 224 224 +43822 ./prep_dataset/ILSVRC2012_val_00032993.bin 224 224 +43823 ./prep_dataset/ILSVRC2012_val_00024143.bin 224 224 +43824 ./prep_dataset/ILSVRC2012_val_00004680.bin 224 224 +43825 ./prep_dataset/ILSVRC2012_val_00003501.bin 224 224 +43826 ./prep_dataset/ILSVRC2012_val_00009829.bin 224 224 +43827 ./prep_dataset/ILSVRC2012_val_00046497.bin 224 224 +43828 ./prep_dataset/ILSVRC2012_val_00019452.bin 224 224 +43829 ./prep_dataset/ILSVRC2012_val_00003463.bin 224 224 +43830 ./prep_dataset/ILSVRC2012_val_00010188.bin 224 224 +43831 ./prep_dataset/ILSVRC2012_val_00046584.bin 224 224 +43832 ./prep_dataset/ILSVRC2012_val_00007632.bin 224 224 +43833 ./prep_dataset/ILSVRC2012_val_00011052.bin 224 224 +43834 ./prep_dataset/ILSVRC2012_val_00049154.bin 224 224 +43835 ./prep_dataset/ILSVRC2012_val_00028373.bin 224 224 +43836 ./prep_dataset/ILSVRC2012_val_00004494.bin 224 224 +43837 ./prep_dataset/ILSVRC2012_val_00015457.bin 224 224 +43838 ./prep_dataset/ILSVRC2012_val_00014548.bin 224 224 +43839 ./prep_dataset/ILSVRC2012_val_00019904.bin 224 224 +43840 ./prep_dataset/ILSVRC2012_val_00027045.bin 224 224 +43841 ./prep_dataset/ILSVRC2012_val_00001211.bin 224 224 +43842 ./prep_dataset/ILSVRC2012_val_00049485.bin 224 224 +43843 ./prep_dataset/ILSVRC2012_val_00030552.bin 224 224 +43844 ./prep_dataset/ILSVRC2012_val_00016526.bin 224 224 +43845 ./prep_dataset/ILSVRC2012_val_00037871.bin 224 224 +43846 ./prep_dataset/ILSVRC2012_val_00018103.bin 224 224 +43847 ./prep_dataset/ILSVRC2012_val_00027827.bin 224 224 +43848 ./prep_dataset/ILSVRC2012_val_00031689.bin 224 224 +43849 ./prep_dataset/ILSVRC2012_val_00003367.bin 224 224 +43850 ./prep_dataset/ILSVRC2012_val_00016378.bin 224 224 +43851 ./prep_dataset/ILSVRC2012_val_00049293.bin 224 224 +43852 ./prep_dataset/ILSVRC2012_val_00028223.bin 224 224 +43853 ./prep_dataset/ILSVRC2012_val_00005363.bin 224 224 +43854 ./prep_dataset/ILSVRC2012_val_00001961.bin 224 224 +43855 ./prep_dataset/ILSVRC2012_val_00004831.bin 224 224 +43856 ./prep_dataset/ILSVRC2012_val_00029775.bin 224 224 +43857 ./prep_dataset/ILSVRC2012_val_00025166.bin 224 224 +43858 ./prep_dataset/ILSVRC2012_val_00046208.bin 224 224 +43859 ./prep_dataset/ILSVRC2012_val_00017934.bin 224 224 +43860 ./prep_dataset/ILSVRC2012_val_00027427.bin 224 224 +43861 ./prep_dataset/ILSVRC2012_val_00032299.bin 224 224 +43862 ./prep_dataset/ILSVRC2012_val_00011952.bin 224 224 +43863 ./prep_dataset/ILSVRC2012_val_00047188.bin 224 224 +43864 ./prep_dataset/ILSVRC2012_val_00034205.bin 224 224 +43865 ./prep_dataset/ILSVRC2012_val_00014396.bin 224 224 +43866 ./prep_dataset/ILSVRC2012_val_00022817.bin 224 224 +43867 ./prep_dataset/ILSVRC2012_val_00004879.bin 224 224 +43868 ./prep_dataset/ILSVRC2012_val_00019702.bin 224 224 +43869 ./prep_dataset/ILSVRC2012_val_00049735.bin 224 224 +43870 ./prep_dataset/ILSVRC2012_val_00018360.bin 224 224 +43871 ./prep_dataset/ILSVRC2012_val_00004438.bin 224 224 +43872 ./prep_dataset/ILSVRC2012_val_00044687.bin 224 224 +43873 ./prep_dataset/ILSVRC2012_val_00005169.bin 224 224 +43874 ./prep_dataset/ILSVRC2012_val_00003678.bin 224 224 +43875 ./prep_dataset/ILSVRC2012_val_00026223.bin 224 224 +43876 ./prep_dataset/ILSVRC2012_val_00047538.bin 224 224 +43877 ./prep_dataset/ILSVRC2012_val_00030154.bin 224 224 +43878 ./prep_dataset/ILSVRC2012_val_00042377.bin 224 224 +43879 ./prep_dataset/ILSVRC2012_val_00049223.bin 224 224 +43880 ./prep_dataset/ILSVRC2012_val_00012422.bin 224 224 +43881 ./prep_dataset/ILSVRC2012_val_00008575.bin 224 224 +43882 ./prep_dataset/ILSVRC2012_val_00012651.bin 224 224 +43883 ./prep_dataset/ILSVRC2012_val_00032529.bin 224 224 +43884 ./prep_dataset/ILSVRC2012_val_00036086.bin 224 224 +43885 ./prep_dataset/ILSVRC2012_val_00011376.bin 224 224 +43886 ./prep_dataset/ILSVRC2012_val_00033141.bin 224 224 +43887 ./prep_dataset/ILSVRC2012_val_00039063.bin 224 224 +43888 ./prep_dataset/ILSVRC2012_val_00015112.bin 224 224 +43889 ./prep_dataset/ILSVRC2012_val_00026586.bin 224 224 +43890 ./prep_dataset/ILSVRC2012_val_00015931.bin 224 224 +43891 ./prep_dataset/ILSVRC2012_val_00034699.bin 224 224 +43892 ./prep_dataset/ILSVRC2012_val_00034975.bin 224 224 +43893 ./prep_dataset/ILSVRC2012_val_00027135.bin 224 224 +43894 ./prep_dataset/ILSVRC2012_val_00027206.bin 224 224 +43895 ./prep_dataset/ILSVRC2012_val_00022480.bin 224 224 +43896 ./prep_dataset/ILSVRC2012_val_00014512.bin 224 224 +43897 ./prep_dataset/ILSVRC2012_val_00040913.bin 224 224 +43898 ./prep_dataset/ILSVRC2012_val_00023412.bin 224 224 +43899 ./prep_dataset/ILSVRC2012_val_00008220.bin 224 224 +43900 ./prep_dataset/ILSVRC2012_val_00033552.bin 224 224 +43901 ./prep_dataset/ILSVRC2012_val_00025260.bin 224 224 +43902 ./prep_dataset/ILSVRC2012_val_00034462.bin 224 224 +43903 ./prep_dataset/ILSVRC2012_val_00018411.bin 224 224 +43904 ./prep_dataset/ILSVRC2012_val_00006108.bin 224 224 +43905 ./prep_dataset/ILSVRC2012_val_00014670.bin 224 224 +43906 ./prep_dataset/ILSVRC2012_val_00003751.bin 224 224 +43907 ./prep_dataset/ILSVRC2012_val_00036325.bin 224 224 +43908 ./prep_dataset/ILSVRC2012_val_00022768.bin 224 224 +43909 ./prep_dataset/ILSVRC2012_val_00045644.bin 224 224 +43910 ./prep_dataset/ILSVRC2012_val_00048068.bin 224 224 +43911 ./prep_dataset/ILSVRC2012_val_00001194.bin 224 224 +43912 ./prep_dataset/ILSVRC2012_val_00008180.bin 224 224 +43913 ./prep_dataset/ILSVRC2012_val_00022629.bin 224 224 +43914 ./prep_dataset/ILSVRC2012_val_00040494.bin 224 224 +43915 ./prep_dataset/ILSVRC2012_val_00011525.bin 224 224 +43916 ./prep_dataset/ILSVRC2012_val_00020922.bin 224 224 +43917 ./prep_dataset/ILSVRC2012_val_00028047.bin 224 224 +43918 ./prep_dataset/ILSVRC2012_val_00020630.bin 224 224 +43919 ./prep_dataset/ILSVRC2012_val_00047981.bin 224 224 +43920 ./prep_dataset/ILSVRC2012_val_00036334.bin 224 224 +43921 ./prep_dataset/ILSVRC2012_val_00049340.bin 224 224 +43922 ./prep_dataset/ILSVRC2012_val_00027242.bin 224 224 +43923 ./prep_dataset/ILSVRC2012_val_00039332.bin 224 224 +43924 ./prep_dataset/ILSVRC2012_val_00026810.bin 224 224 +43925 ./prep_dataset/ILSVRC2012_val_00010384.bin 224 224 +43926 ./prep_dataset/ILSVRC2012_val_00044082.bin 224 224 +43927 ./prep_dataset/ILSVRC2012_val_00031455.bin 224 224 +43928 ./prep_dataset/ILSVRC2012_val_00006219.bin 224 224 +43929 ./prep_dataset/ILSVRC2012_val_00002288.bin 224 224 +43930 ./prep_dataset/ILSVRC2012_val_00012065.bin 224 224 +43931 ./prep_dataset/ILSVRC2012_val_00049537.bin 224 224 +43932 ./prep_dataset/ILSVRC2012_val_00010489.bin 224 224 +43933 ./prep_dataset/ILSVRC2012_val_00040886.bin 224 224 +43934 ./prep_dataset/ILSVRC2012_val_00022340.bin 224 224 +43935 ./prep_dataset/ILSVRC2012_val_00035288.bin 224 224 +43936 ./prep_dataset/ILSVRC2012_val_00037455.bin 224 224 +43937 ./prep_dataset/ILSVRC2012_val_00001697.bin 224 224 +43938 ./prep_dataset/ILSVRC2012_val_00012186.bin 224 224 +43939 ./prep_dataset/ILSVRC2012_val_00012875.bin 224 224 +43940 ./prep_dataset/ILSVRC2012_val_00032202.bin 224 224 +43941 ./prep_dataset/ILSVRC2012_val_00049483.bin 224 224 +43942 ./prep_dataset/ILSVRC2012_val_00019610.bin 224 224 +43943 ./prep_dataset/ILSVRC2012_val_00039820.bin 224 224 +43944 ./prep_dataset/ILSVRC2012_val_00043103.bin 224 224 +43945 ./prep_dataset/ILSVRC2012_val_00031120.bin 224 224 +43946 ./prep_dataset/ILSVRC2012_val_00007894.bin 224 224 +43947 ./prep_dataset/ILSVRC2012_val_00039078.bin 224 224 +43948 ./prep_dataset/ILSVRC2012_val_00047881.bin 224 224 +43949 ./prep_dataset/ILSVRC2012_val_00038138.bin 224 224 +43950 ./prep_dataset/ILSVRC2012_val_00006372.bin 224 224 +43951 ./prep_dataset/ILSVRC2012_val_00044563.bin 224 224 +43952 ./prep_dataset/ILSVRC2012_val_00024460.bin 224 224 +43953 ./prep_dataset/ILSVRC2012_val_00022284.bin 224 224 +43954 ./prep_dataset/ILSVRC2012_val_00018753.bin 224 224 +43955 ./prep_dataset/ILSVRC2012_val_00023093.bin 224 224 +43956 ./prep_dataset/ILSVRC2012_val_00025426.bin 224 224 +43957 ./prep_dataset/ILSVRC2012_val_00017996.bin 224 224 +43958 ./prep_dataset/ILSVRC2012_val_00028212.bin 224 224 +43959 ./prep_dataset/ILSVRC2012_val_00004094.bin 224 224 +43960 ./prep_dataset/ILSVRC2012_val_00041693.bin 224 224 +43961 ./prep_dataset/ILSVRC2012_val_00004141.bin 224 224 +43962 ./prep_dataset/ILSVRC2012_val_00048342.bin 224 224 +43963 ./prep_dataset/ILSVRC2012_val_00048518.bin 224 224 +43964 ./prep_dataset/ILSVRC2012_val_00002710.bin 224 224 +43965 ./prep_dataset/ILSVRC2012_val_00045703.bin 224 224 +43966 ./prep_dataset/ILSVRC2012_val_00002217.bin 224 224 +43967 ./prep_dataset/ILSVRC2012_val_00000477.bin 224 224 +43968 ./prep_dataset/ILSVRC2012_val_00035565.bin 224 224 +43969 ./prep_dataset/ILSVRC2012_val_00037522.bin 224 224 +43970 ./prep_dataset/ILSVRC2012_val_00002990.bin 224 224 +43971 ./prep_dataset/ILSVRC2012_val_00006097.bin 224 224 +43972 ./prep_dataset/ILSVRC2012_val_00045254.bin 224 224 +43973 ./prep_dataset/ILSVRC2012_val_00006065.bin 224 224 +43974 ./prep_dataset/ILSVRC2012_val_00013965.bin 224 224 +43975 ./prep_dataset/ILSVRC2012_val_00020843.bin 224 224 +43976 ./prep_dataset/ILSVRC2012_val_00035193.bin 224 224 +43977 ./prep_dataset/ILSVRC2012_val_00008410.bin 224 224 +43978 ./prep_dataset/ILSVRC2012_val_00037243.bin 224 224 +43979 ./prep_dataset/ILSVRC2012_val_00041662.bin 224 224 +43980 ./prep_dataset/ILSVRC2012_val_00028855.bin 224 224 +43981 ./prep_dataset/ILSVRC2012_val_00003490.bin 224 224 +43982 ./prep_dataset/ILSVRC2012_val_00027110.bin 224 224 +43983 ./prep_dataset/ILSVRC2012_val_00015741.bin 224 224 +43984 ./prep_dataset/ILSVRC2012_val_00040819.bin 224 224 +43985 ./prep_dataset/ILSVRC2012_val_00035290.bin 224 224 +43986 ./prep_dataset/ILSVRC2012_val_00038175.bin 224 224 +43987 ./prep_dataset/ILSVRC2012_val_00026343.bin 224 224 +43988 ./prep_dataset/ILSVRC2012_val_00021170.bin 224 224 +43989 ./prep_dataset/ILSVRC2012_val_00024721.bin 224 224 +43990 ./prep_dataset/ILSVRC2012_val_00020117.bin 224 224 +43991 ./prep_dataset/ILSVRC2012_val_00005093.bin 224 224 +43992 ./prep_dataset/ILSVRC2012_val_00045353.bin 224 224 +43993 ./prep_dataset/ILSVRC2012_val_00000825.bin 224 224 +43994 ./prep_dataset/ILSVRC2012_val_00015464.bin 224 224 +43995 ./prep_dataset/ILSVRC2012_val_00024324.bin 224 224 +43996 ./prep_dataset/ILSVRC2012_val_00022242.bin 224 224 +43997 ./prep_dataset/ILSVRC2012_val_00022655.bin 224 224 +43998 ./prep_dataset/ILSVRC2012_val_00004895.bin 224 224 +43999 ./prep_dataset/ILSVRC2012_val_00006042.bin 224 224 +44000 ./prep_dataset/ILSVRC2012_val_00037002.bin 224 224 +44001 ./prep_dataset/ILSVRC2012_val_00033588.bin 224 224 +44002 ./prep_dataset/ILSVRC2012_val_00035010.bin 224 224 +44003 ./prep_dataset/ILSVRC2012_val_00018312.bin 224 224 +44004 ./prep_dataset/ILSVRC2012_val_00009034.bin 224 224 +44005 ./prep_dataset/ILSVRC2012_val_00021501.bin 224 224 +44006 ./prep_dataset/ILSVRC2012_val_00045238.bin 224 224 +44007 ./prep_dataset/ILSVRC2012_val_00019732.bin 224 224 +44008 ./prep_dataset/ILSVRC2012_val_00044620.bin 224 224 +44009 ./prep_dataset/ILSVRC2012_val_00044525.bin 224 224 +44010 ./prep_dataset/ILSVRC2012_val_00027884.bin 224 224 +44011 ./prep_dataset/ILSVRC2012_val_00024801.bin 224 224 +44012 ./prep_dataset/ILSVRC2012_val_00048723.bin 224 224 +44013 ./prep_dataset/ILSVRC2012_val_00046990.bin 224 224 +44014 ./prep_dataset/ILSVRC2012_val_00027538.bin 224 224 +44015 ./prep_dataset/ILSVRC2012_val_00034117.bin 224 224 +44016 ./prep_dataset/ILSVRC2012_val_00043587.bin 224 224 +44017 ./prep_dataset/ILSVRC2012_val_00042479.bin 224 224 +44018 ./prep_dataset/ILSVRC2012_val_00018417.bin 224 224 +44019 ./prep_dataset/ILSVRC2012_val_00010737.bin 224 224 +44020 ./prep_dataset/ILSVRC2012_val_00025642.bin 224 224 +44021 ./prep_dataset/ILSVRC2012_val_00011265.bin 224 224 +44022 ./prep_dataset/ILSVRC2012_val_00024068.bin 224 224 +44023 ./prep_dataset/ILSVRC2012_val_00037627.bin 224 224 +44024 ./prep_dataset/ILSVRC2012_val_00036256.bin 224 224 +44025 ./prep_dataset/ILSVRC2012_val_00049926.bin 224 224 +44026 ./prep_dataset/ILSVRC2012_val_00005695.bin 224 224 +44027 ./prep_dataset/ILSVRC2012_val_00026863.bin 224 224 +44028 ./prep_dataset/ILSVRC2012_val_00012028.bin 224 224 +44029 ./prep_dataset/ILSVRC2012_val_00011261.bin 224 224 +44030 ./prep_dataset/ILSVRC2012_val_00036527.bin 224 224 +44031 ./prep_dataset/ILSVRC2012_val_00049645.bin 224 224 +44032 ./prep_dataset/ILSVRC2012_val_00020557.bin 224 224 +44033 ./prep_dataset/ILSVRC2012_val_00036311.bin 224 224 +44034 ./prep_dataset/ILSVRC2012_val_00006791.bin 224 224 +44035 ./prep_dataset/ILSVRC2012_val_00042808.bin 224 224 +44036 ./prep_dataset/ILSVRC2012_val_00003060.bin 224 224 +44037 ./prep_dataset/ILSVRC2012_val_00035712.bin 224 224 +44038 ./prep_dataset/ILSVRC2012_val_00015249.bin 224 224 +44039 ./prep_dataset/ILSVRC2012_val_00045869.bin 224 224 +44040 ./prep_dataset/ILSVRC2012_val_00038292.bin 224 224 +44041 ./prep_dataset/ILSVRC2012_val_00032047.bin 224 224 +44042 ./prep_dataset/ILSVRC2012_val_00030160.bin 224 224 +44043 ./prep_dataset/ILSVRC2012_val_00018807.bin 224 224 +44044 ./prep_dataset/ILSVRC2012_val_00021594.bin 224 224 +44045 ./prep_dataset/ILSVRC2012_val_00008678.bin 224 224 +44046 ./prep_dataset/ILSVRC2012_val_00029762.bin 224 224 +44047 ./prep_dataset/ILSVRC2012_val_00039663.bin 224 224 +44048 ./prep_dataset/ILSVRC2012_val_00033128.bin 224 224 +44049 ./prep_dataset/ILSVRC2012_val_00027983.bin 224 224 +44050 ./prep_dataset/ILSVRC2012_val_00034625.bin 224 224 +44051 ./prep_dataset/ILSVRC2012_val_00016773.bin 224 224 +44052 ./prep_dataset/ILSVRC2012_val_00015560.bin 224 224 +44053 ./prep_dataset/ILSVRC2012_val_00009228.bin 224 224 +44054 ./prep_dataset/ILSVRC2012_val_00030044.bin 224 224 +44055 ./prep_dataset/ILSVRC2012_val_00028571.bin 224 224 +44056 ./prep_dataset/ILSVRC2012_val_00005567.bin 224 224 +44057 ./prep_dataset/ILSVRC2012_val_00025484.bin 224 224 +44058 ./prep_dataset/ILSVRC2012_val_00013335.bin 224 224 +44059 ./prep_dataset/ILSVRC2012_val_00004942.bin 224 224 +44060 ./prep_dataset/ILSVRC2012_val_00039405.bin 224 224 +44061 ./prep_dataset/ILSVRC2012_val_00026564.bin 224 224 +44062 ./prep_dataset/ILSVRC2012_val_00029329.bin 224 224 +44063 ./prep_dataset/ILSVRC2012_val_00024742.bin 224 224 +44064 ./prep_dataset/ILSVRC2012_val_00026028.bin 224 224 +44065 ./prep_dataset/ILSVRC2012_val_00018456.bin 224 224 +44066 ./prep_dataset/ILSVRC2012_val_00007086.bin 224 224 +44067 ./prep_dataset/ILSVRC2012_val_00048575.bin 224 224 +44068 ./prep_dataset/ILSVRC2012_val_00048196.bin 224 224 +44069 ./prep_dataset/ILSVRC2012_val_00024825.bin 224 224 +44070 ./prep_dataset/ILSVRC2012_val_00041459.bin 224 224 +44071 ./prep_dataset/ILSVRC2012_val_00010037.bin 224 224 +44072 ./prep_dataset/ILSVRC2012_val_00003804.bin 224 224 +44073 ./prep_dataset/ILSVRC2012_val_00009383.bin 224 224 +44074 ./prep_dataset/ILSVRC2012_val_00033340.bin 224 224 +44075 ./prep_dataset/ILSVRC2012_val_00019479.bin 224 224 +44076 ./prep_dataset/ILSVRC2012_val_00030501.bin 224 224 +44077 ./prep_dataset/ILSVRC2012_val_00029149.bin 224 224 +44078 ./prep_dataset/ILSVRC2012_val_00030446.bin 224 224 +44079 ./prep_dataset/ILSVRC2012_val_00018183.bin 224 224 +44080 ./prep_dataset/ILSVRC2012_val_00013678.bin 224 224 +44081 ./prep_dataset/ILSVRC2012_val_00023612.bin 224 224 +44082 ./prep_dataset/ILSVRC2012_val_00021887.bin 224 224 +44083 ./prep_dataset/ILSVRC2012_val_00021465.bin 224 224 +44084 ./prep_dataset/ILSVRC2012_val_00032326.bin 224 224 +44085 ./prep_dataset/ILSVRC2012_val_00040540.bin 224 224 +44086 ./prep_dataset/ILSVRC2012_val_00045688.bin 224 224 +44087 ./prep_dataset/ILSVRC2012_val_00016498.bin 224 224 +44088 ./prep_dataset/ILSVRC2012_val_00048013.bin 224 224 +44089 ./prep_dataset/ILSVRC2012_val_00048132.bin 224 224 +44090 ./prep_dataset/ILSVRC2012_val_00020646.bin 224 224 +44091 ./prep_dataset/ILSVRC2012_val_00012736.bin 224 224 +44092 ./prep_dataset/ILSVRC2012_val_00024971.bin 224 224 +44093 ./prep_dataset/ILSVRC2012_val_00005785.bin 224 224 +44094 ./prep_dataset/ILSVRC2012_val_00005088.bin 224 224 +44095 ./prep_dataset/ILSVRC2012_val_00025354.bin 224 224 +44096 ./prep_dataset/ILSVRC2012_val_00033725.bin 224 224 +44097 ./prep_dataset/ILSVRC2012_val_00021861.bin 224 224 +44098 ./prep_dataset/ILSVRC2012_val_00024440.bin 224 224 +44099 ./prep_dataset/ILSVRC2012_val_00010039.bin 224 224 +44100 ./prep_dataset/ILSVRC2012_val_00003316.bin 224 224 +44101 ./prep_dataset/ILSVRC2012_val_00029965.bin 224 224 +44102 ./prep_dataset/ILSVRC2012_val_00012811.bin 224 224 +44103 ./prep_dataset/ILSVRC2012_val_00031670.bin 224 224 +44104 ./prep_dataset/ILSVRC2012_val_00047201.bin 224 224 +44105 ./prep_dataset/ILSVRC2012_val_00027069.bin 224 224 +44106 ./prep_dataset/ILSVRC2012_val_00044671.bin 224 224 +44107 ./prep_dataset/ILSVRC2012_val_00009851.bin 224 224 +44108 ./prep_dataset/ILSVRC2012_val_00015646.bin 224 224 +44109 ./prep_dataset/ILSVRC2012_val_00043337.bin 224 224 +44110 ./prep_dataset/ILSVRC2012_val_00019104.bin 224 224 +44111 ./prep_dataset/ILSVRC2012_val_00023784.bin 224 224 +44112 ./prep_dataset/ILSVRC2012_val_00008388.bin 224 224 +44113 ./prep_dataset/ILSVRC2012_val_00007126.bin 224 224 +44114 ./prep_dataset/ILSVRC2012_val_00034906.bin 224 224 +44115 ./prep_dataset/ILSVRC2012_val_00013409.bin 224 224 +44116 ./prep_dataset/ILSVRC2012_val_00029942.bin 224 224 +44117 ./prep_dataset/ILSVRC2012_val_00032705.bin 224 224 +44118 ./prep_dataset/ILSVRC2012_val_00049378.bin 224 224 +44119 ./prep_dataset/ILSVRC2012_val_00017310.bin 224 224 +44120 ./prep_dataset/ILSVRC2012_val_00029670.bin 224 224 +44121 ./prep_dataset/ILSVRC2012_val_00007920.bin 224 224 +44122 ./prep_dataset/ILSVRC2012_val_00000358.bin 224 224 +44123 ./prep_dataset/ILSVRC2012_val_00021520.bin 224 224 +44124 ./prep_dataset/ILSVRC2012_val_00039184.bin 224 224 +44125 ./prep_dataset/ILSVRC2012_val_00045742.bin 224 224 +44126 ./prep_dataset/ILSVRC2012_val_00015156.bin 224 224 +44127 ./prep_dataset/ILSVRC2012_val_00013149.bin 224 224 +44128 ./prep_dataset/ILSVRC2012_val_00023763.bin 224 224 +44129 ./prep_dataset/ILSVRC2012_val_00023930.bin 224 224 +44130 ./prep_dataset/ILSVRC2012_val_00025928.bin 224 224 +44131 ./prep_dataset/ILSVRC2012_val_00034628.bin 224 224 +44132 ./prep_dataset/ILSVRC2012_val_00019440.bin 224 224 +44133 ./prep_dataset/ILSVRC2012_val_00016409.bin 224 224 +44134 ./prep_dataset/ILSVRC2012_val_00026882.bin 224 224 +44135 ./prep_dataset/ILSVRC2012_val_00036474.bin 224 224 +44136 ./prep_dataset/ILSVRC2012_val_00049427.bin 224 224 +44137 ./prep_dataset/ILSVRC2012_val_00025630.bin 224 224 +44138 ./prep_dataset/ILSVRC2012_val_00039786.bin 224 224 +44139 ./prep_dataset/ILSVRC2012_val_00043360.bin 224 224 +44140 ./prep_dataset/ILSVRC2012_val_00014842.bin 224 224 +44141 ./prep_dataset/ILSVRC2012_val_00006590.bin 224 224 +44142 ./prep_dataset/ILSVRC2012_val_00042997.bin 224 224 +44143 ./prep_dataset/ILSVRC2012_val_00021028.bin 224 224 +44144 ./prep_dataset/ILSVRC2012_val_00032878.bin 224 224 +44145 ./prep_dataset/ILSVRC2012_val_00046573.bin 224 224 +44146 ./prep_dataset/ILSVRC2012_val_00035450.bin 224 224 +44147 ./prep_dataset/ILSVRC2012_val_00039600.bin 224 224 +44148 ./prep_dataset/ILSVRC2012_val_00002153.bin 224 224 +44149 ./prep_dataset/ILSVRC2012_val_00036941.bin 224 224 +44150 ./prep_dataset/ILSVRC2012_val_00032198.bin 224 224 +44151 ./prep_dataset/ILSVRC2012_val_00041987.bin 224 224 +44152 ./prep_dataset/ILSVRC2012_val_00010935.bin 224 224 +44153 ./prep_dataset/ILSVRC2012_val_00038087.bin 224 224 +44154 ./prep_dataset/ILSVRC2012_val_00006494.bin 224 224 +44155 ./prep_dataset/ILSVRC2012_val_00042498.bin 224 224 +44156 ./prep_dataset/ILSVRC2012_val_00032063.bin 224 224 +44157 ./prep_dataset/ILSVRC2012_val_00020963.bin 224 224 +44158 ./prep_dataset/ILSVRC2012_val_00047501.bin 224 224 +44159 ./prep_dataset/ILSVRC2012_val_00034495.bin 224 224 +44160 ./prep_dataset/ILSVRC2012_val_00006259.bin 224 224 +44161 ./prep_dataset/ILSVRC2012_val_00004160.bin 224 224 +44162 ./prep_dataset/ILSVRC2012_val_00032766.bin 224 224 +44163 ./prep_dataset/ILSVRC2012_val_00000552.bin 224 224 +44164 ./prep_dataset/ILSVRC2012_val_00041643.bin 224 224 +44165 ./prep_dataset/ILSVRC2012_val_00028055.bin 224 224 +44166 ./prep_dataset/ILSVRC2012_val_00026907.bin 224 224 +44167 ./prep_dataset/ILSVRC2012_val_00042634.bin 224 224 +44168 ./prep_dataset/ILSVRC2012_val_00012321.bin 224 224 +44169 ./prep_dataset/ILSVRC2012_val_00024250.bin 224 224 +44170 ./prep_dataset/ILSVRC2012_val_00012936.bin 224 224 +44171 ./prep_dataset/ILSVRC2012_val_00015937.bin 224 224 +44172 ./prep_dataset/ILSVRC2012_val_00004461.bin 224 224 +44173 ./prep_dataset/ILSVRC2012_val_00043906.bin 224 224 +44174 ./prep_dataset/ILSVRC2012_val_00041014.bin 224 224 +44175 ./prep_dataset/ILSVRC2012_val_00017153.bin 224 224 +44176 ./prep_dataset/ILSVRC2012_val_00007829.bin 224 224 +44177 ./prep_dataset/ILSVRC2012_val_00014254.bin 224 224 +44178 ./prep_dataset/ILSVRC2012_val_00019825.bin 224 224 +44179 ./prep_dataset/ILSVRC2012_val_00011339.bin 224 224 +44180 ./prep_dataset/ILSVRC2012_val_00027549.bin 224 224 +44181 ./prep_dataset/ILSVRC2012_val_00003230.bin 224 224 +44182 ./prep_dataset/ILSVRC2012_val_00041637.bin 224 224 +44183 ./prep_dataset/ILSVRC2012_val_00023571.bin 224 224 +44184 ./prep_dataset/ILSVRC2012_val_00047003.bin 224 224 +44185 ./prep_dataset/ILSVRC2012_val_00033018.bin 224 224 +44186 ./prep_dataset/ILSVRC2012_val_00040948.bin 224 224 +44187 ./prep_dataset/ILSVRC2012_val_00024336.bin 224 224 +44188 ./prep_dataset/ILSVRC2012_val_00009847.bin 224 224 +44189 ./prep_dataset/ILSVRC2012_val_00034510.bin 224 224 +44190 ./prep_dataset/ILSVRC2012_val_00039938.bin 224 224 +44191 ./prep_dataset/ILSVRC2012_val_00048427.bin 224 224 +44192 ./prep_dataset/ILSVRC2012_val_00003201.bin 224 224 +44193 ./prep_dataset/ILSVRC2012_val_00005457.bin 224 224 +44194 ./prep_dataset/ILSVRC2012_val_00043956.bin 224 224 +44195 ./prep_dataset/ILSVRC2012_val_00015320.bin 224 224 +44196 ./prep_dataset/ILSVRC2012_val_00008894.bin 224 224 +44197 ./prep_dataset/ILSVRC2012_val_00016534.bin 224 224 +44198 ./prep_dataset/ILSVRC2012_val_00016387.bin 224 224 +44199 ./prep_dataset/ILSVRC2012_val_00009172.bin 224 224 +44200 ./prep_dataset/ILSVRC2012_val_00027611.bin 224 224 +44201 ./prep_dataset/ILSVRC2012_val_00046705.bin 224 224 +44202 ./prep_dataset/ILSVRC2012_val_00009158.bin 224 224 +44203 ./prep_dataset/ILSVRC2012_val_00044348.bin 224 224 +44204 ./prep_dataset/ILSVRC2012_val_00005613.bin 224 224 +44205 ./prep_dataset/ILSVRC2012_val_00011264.bin 224 224 +44206 ./prep_dataset/ILSVRC2012_val_00047824.bin 224 224 +44207 ./prep_dataset/ILSVRC2012_val_00037080.bin 224 224 +44208 ./prep_dataset/ILSVRC2012_val_00039146.bin 224 224 +44209 ./prep_dataset/ILSVRC2012_val_00039237.bin 224 224 +44210 ./prep_dataset/ILSVRC2012_val_00036102.bin 224 224 +44211 ./prep_dataset/ILSVRC2012_val_00008424.bin 224 224 +44212 ./prep_dataset/ILSVRC2012_val_00047861.bin 224 224 +44213 ./prep_dataset/ILSVRC2012_val_00034959.bin 224 224 +44214 ./prep_dataset/ILSVRC2012_val_00042129.bin 224 224 +44215 ./prep_dataset/ILSVRC2012_val_00018415.bin 224 224 +44216 ./prep_dataset/ILSVRC2012_val_00035717.bin 224 224 +44217 ./prep_dataset/ILSVRC2012_val_00045348.bin 224 224 +44218 ./prep_dataset/ILSVRC2012_val_00026025.bin 224 224 +44219 ./prep_dataset/ILSVRC2012_val_00006389.bin 224 224 +44220 ./prep_dataset/ILSVRC2012_val_00026055.bin 224 224 +44221 ./prep_dataset/ILSVRC2012_val_00004126.bin 224 224 +44222 ./prep_dataset/ILSVRC2012_val_00034168.bin 224 224 +44223 ./prep_dataset/ILSVRC2012_val_00038412.bin 224 224 +44224 ./prep_dataset/ILSVRC2012_val_00015330.bin 224 224 +44225 ./prep_dataset/ILSVRC2012_val_00030402.bin 224 224 +44226 ./prep_dataset/ILSVRC2012_val_00000548.bin 224 224 +44227 ./prep_dataset/ILSVRC2012_val_00032708.bin 224 224 +44228 ./prep_dataset/ILSVRC2012_val_00003306.bin 224 224 +44229 ./prep_dataset/ILSVRC2012_val_00016833.bin 224 224 +44230 ./prep_dataset/ILSVRC2012_val_00005950.bin 224 224 +44231 ./prep_dataset/ILSVRC2012_val_00003417.bin 224 224 +44232 ./prep_dataset/ILSVRC2012_val_00036053.bin 224 224 +44233 ./prep_dataset/ILSVRC2012_val_00020619.bin 224 224 +44234 ./prep_dataset/ILSVRC2012_val_00002424.bin 224 224 +44235 ./prep_dataset/ILSVRC2012_val_00042097.bin 224 224 +44236 ./prep_dataset/ILSVRC2012_val_00017764.bin 224 224 +44237 ./prep_dataset/ILSVRC2012_val_00034770.bin 224 224 +44238 ./prep_dataset/ILSVRC2012_val_00048620.bin 224 224 +44239 ./prep_dataset/ILSVRC2012_val_00043477.bin 224 224 +44240 ./prep_dataset/ILSVRC2012_val_00002459.bin 224 224 +44241 ./prep_dataset/ILSVRC2012_val_00031800.bin 224 224 +44242 ./prep_dataset/ILSVRC2012_val_00007098.bin 224 224 +44243 ./prep_dataset/ILSVRC2012_val_00030548.bin 224 224 +44244 ./prep_dataset/ILSVRC2012_val_00001698.bin 224 224 +44245 ./prep_dataset/ILSVRC2012_val_00035989.bin 224 224 +44246 ./prep_dataset/ILSVRC2012_val_00047740.bin 224 224 +44247 ./prep_dataset/ILSVRC2012_val_00025301.bin 224 224 +44248 ./prep_dataset/ILSVRC2012_val_00032093.bin 224 224 +44249 ./prep_dataset/ILSVRC2012_val_00049406.bin 224 224 +44250 ./prep_dataset/ILSVRC2012_val_00042202.bin 224 224 +44251 ./prep_dataset/ILSVRC2012_val_00047035.bin 224 224 +44252 ./prep_dataset/ILSVRC2012_val_00030698.bin 224 224 +44253 ./prep_dataset/ILSVRC2012_val_00033108.bin 224 224 +44254 ./prep_dataset/ILSVRC2012_val_00043953.bin 224 224 +44255 ./prep_dataset/ILSVRC2012_val_00049979.bin 224 224 +44256 ./prep_dataset/ILSVRC2012_val_00034133.bin 224 224 +44257 ./prep_dataset/ILSVRC2012_val_00011174.bin 224 224 +44258 ./prep_dataset/ILSVRC2012_val_00044412.bin 224 224 +44259 ./prep_dataset/ILSVRC2012_val_00030536.bin 224 224 +44260 ./prep_dataset/ILSVRC2012_val_00049998.bin 224 224 +44261 ./prep_dataset/ILSVRC2012_val_00030416.bin 224 224 +44262 ./prep_dataset/ILSVRC2012_val_00004431.bin 224 224 +44263 ./prep_dataset/ILSVRC2012_val_00004475.bin 224 224 +44264 ./prep_dataset/ILSVRC2012_val_00005422.bin 224 224 +44265 ./prep_dataset/ILSVRC2012_val_00046922.bin 224 224 +44266 ./prep_dataset/ILSVRC2012_val_00000847.bin 224 224 +44267 ./prep_dataset/ILSVRC2012_val_00018838.bin 224 224 +44268 ./prep_dataset/ILSVRC2012_val_00045912.bin 224 224 +44269 ./prep_dataset/ILSVRC2012_val_00037048.bin 224 224 +44270 ./prep_dataset/ILSVRC2012_val_00023958.bin 224 224 +44271 ./prep_dataset/ILSVRC2012_val_00025383.bin 224 224 +44272 ./prep_dataset/ILSVRC2012_val_00012026.bin 224 224 +44273 ./prep_dataset/ILSVRC2012_val_00021583.bin 224 224 +44274 ./prep_dataset/ILSVRC2012_val_00009491.bin 224 224 +44275 ./prep_dataset/ILSVRC2012_val_00020297.bin 224 224 +44276 ./prep_dataset/ILSVRC2012_val_00026658.bin 224 224 +44277 ./prep_dataset/ILSVRC2012_val_00020427.bin 224 224 +44278 ./prep_dataset/ILSVRC2012_val_00015965.bin 224 224 +44279 ./prep_dataset/ILSVRC2012_val_00002970.bin 224 224 +44280 ./prep_dataset/ILSVRC2012_val_00019758.bin 224 224 +44281 ./prep_dataset/ILSVRC2012_val_00047631.bin 224 224 +44282 ./prep_dataset/ILSVRC2012_val_00007976.bin 224 224 +44283 ./prep_dataset/ILSVRC2012_val_00044771.bin 224 224 +44284 ./prep_dataset/ILSVRC2012_val_00007713.bin 224 224 +44285 ./prep_dataset/ILSVRC2012_val_00029283.bin 224 224 +44286 ./prep_dataset/ILSVRC2012_val_00021053.bin 224 224 +44287 ./prep_dataset/ILSVRC2012_val_00044417.bin 224 224 +44288 ./prep_dataset/ILSVRC2012_val_00026024.bin 224 224 +44289 ./prep_dataset/ILSVRC2012_val_00018527.bin 224 224 +44290 ./prep_dataset/ILSVRC2012_val_00010586.bin 224 224 +44291 ./prep_dataset/ILSVRC2012_val_00036657.bin 224 224 +44292 ./prep_dataset/ILSVRC2012_val_00043210.bin 224 224 +44293 ./prep_dataset/ILSVRC2012_val_00041990.bin 224 224 +44294 ./prep_dataset/ILSVRC2012_val_00015906.bin 224 224 +44295 ./prep_dataset/ILSVRC2012_val_00030860.bin 224 224 +44296 ./prep_dataset/ILSVRC2012_val_00036525.bin 224 224 +44297 ./prep_dataset/ILSVRC2012_val_00043367.bin 224 224 +44298 ./prep_dataset/ILSVRC2012_val_00009799.bin 224 224 +44299 ./prep_dataset/ILSVRC2012_val_00010288.bin 224 224 +44300 ./prep_dataset/ILSVRC2012_val_00024471.bin 224 224 +44301 ./prep_dataset/ILSVRC2012_val_00044242.bin 224 224 +44302 ./prep_dataset/ILSVRC2012_val_00028150.bin 224 224 +44303 ./prep_dataset/ILSVRC2012_val_00012044.bin 224 224 +44304 ./prep_dataset/ILSVRC2012_val_00037611.bin 224 224 +44305 ./prep_dataset/ILSVRC2012_val_00013508.bin 224 224 +44306 ./prep_dataset/ILSVRC2012_val_00035289.bin 224 224 +44307 ./prep_dataset/ILSVRC2012_val_00028662.bin 224 224 +44308 ./prep_dataset/ILSVRC2012_val_00025317.bin 224 224 +44309 ./prep_dataset/ILSVRC2012_val_00017698.bin 224 224 +44310 ./prep_dataset/ILSVRC2012_val_00005191.bin 224 224 +44311 ./prep_dataset/ILSVRC2012_val_00029807.bin 224 224 +44312 ./prep_dataset/ILSVRC2012_val_00001122.bin 224 224 +44313 ./prep_dataset/ILSVRC2012_val_00014936.bin 224 224 +44314 ./prep_dataset/ILSVRC2012_val_00030051.bin 224 224 +44315 ./prep_dataset/ILSVRC2012_val_00038309.bin 224 224 +44316 ./prep_dataset/ILSVRC2012_val_00036878.bin 224 224 +44317 ./prep_dataset/ILSVRC2012_val_00023403.bin 224 224 +44318 ./prep_dataset/ILSVRC2012_val_00043380.bin 224 224 +44319 ./prep_dataset/ILSVRC2012_val_00021742.bin 224 224 +44320 ./prep_dataset/ILSVRC2012_val_00009913.bin 224 224 +44321 ./prep_dataset/ILSVRC2012_val_00028995.bin 224 224 +44322 ./prep_dataset/ILSVRC2012_val_00028181.bin 224 224 +44323 ./prep_dataset/ILSVRC2012_val_00025807.bin 224 224 +44324 ./prep_dataset/ILSVRC2012_val_00030644.bin 224 224 +44325 ./prep_dataset/ILSVRC2012_val_00037146.bin 224 224 +44326 ./prep_dataset/ILSVRC2012_val_00007207.bin 224 224 +44327 ./prep_dataset/ILSVRC2012_val_00013721.bin 224 224 +44328 ./prep_dataset/ILSVRC2012_val_00002286.bin 224 224 +44329 ./prep_dataset/ILSVRC2012_val_00008048.bin 224 224 +44330 ./prep_dataset/ILSVRC2012_val_00006865.bin 224 224 +44331 ./prep_dataset/ILSVRC2012_val_00019890.bin 224 224 +44332 ./prep_dataset/ILSVRC2012_val_00028812.bin 224 224 +44333 ./prep_dataset/ILSVRC2012_val_00041219.bin 224 224 +44334 ./prep_dataset/ILSVRC2012_val_00001686.bin 224 224 +44335 ./prep_dataset/ILSVRC2012_val_00040109.bin 224 224 +44336 ./prep_dataset/ILSVRC2012_val_00006766.bin 224 224 +44337 ./prep_dataset/ILSVRC2012_val_00049159.bin 224 224 +44338 ./prep_dataset/ILSVRC2012_val_00043784.bin 224 224 +44339 ./prep_dataset/ILSVRC2012_val_00043588.bin 224 224 +44340 ./prep_dataset/ILSVRC2012_val_00014051.bin 224 224 +44341 ./prep_dataset/ILSVRC2012_val_00023865.bin 224 224 +44342 ./prep_dataset/ILSVRC2012_val_00004548.bin 224 224 +44343 ./prep_dataset/ILSVRC2012_val_00031720.bin 224 224 +44344 ./prep_dataset/ILSVRC2012_val_00049918.bin 224 224 +44345 ./prep_dataset/ILSVRC2012_val_00018871.bin 224 224 +44346 ./prep_dataset/ILSVRC2012_val_00030449.bin 224 224 +44347 ./prep_dataset/ILSVRC2012_val_00017908.bin 224 224 +44348 ./prep_dataset/ILSVRC2012_val_00034830.bin 224 224 +44349 ./prep_dataset/ILSVRC2012_val_00018498.bin 224 224 +44350 ./prep_dataset/ILSVRC2012_val_00033330.bin 224 224 +44351 ./prep_dataset/ILSVRC2012_val_00021948.bin 224 224 +44352 ./prep_dataset/ILSVRC2012_val_00047342.bin 224 224 +44353 ./prep_dataset/ILSVRC2012_val_00002502.bin 224 224 +44354 ./prep_dataset/ILSVRC2012_val_00032615.bin 224 224 +44355 ./prep_dataset/ILSVRC2012_val_00024479.bin 224 224 +44356 ./prep_dataset/ILSVRC2012_val_00010048.bin 224 224 +44357 ./prep_dataset/ILSVRC2012_val_00032508.bin 224 224 +44358 ./prep_dataset/ILSVRC2012_val_00010620.bin 224 224 +44359 ./prep_dataset/ILSVRC2012_val_00002838.bin 224 224 +44360 ./prep_dataset/ILSVRC2012_val_00020148.bin 224 224 +44361 ./prep_dataset/ILSVRC2012_val_00036960.bin 224 224 +44362 ./prep_dataset/ILSVRC2012_val_00012550.bin 224 224 +44363 ./prep_dataset/ILSVRC2012_val_00026172.bin 224 224 +44364 ./prep_dataset/ILSVRC2012_val_00022720.bin 224 224 +44365 ./prep_dataset/ILSVRC2012_val_00049990.bin 224 224 +44366 ./prep_dataset/ILSVRC2012_val_00044733.bin 224 224 +44367 ./prep_dataset/ILSVRC2012_val_00009914.bin 224 224 +44368 ./prep_dataset/ILSVRC2012_val_00005734.bin 224 224 +44369 ./prep_dataset/ILSVRC2012_val_00002046.bin 224 224 +44370 ./prep_dataset/ILSVRC2012_val_00014347.bin 224 224 +44371 ./prep_dataset/ILSVRC2012_val_00039123.bin 224 224 +44372 ./prep_dataset/ILSVRC2012_val_00036419.bin 224 224 +44373 ./prep_dataset/ILSVRC2012_val_00032854.bin 224 224 +44374 ./prep_dataset/ILSVRC2012_val_00040128.bin 224 224 +44375 ./prep_dataset/ILSVRC2012_val_00029999.bin 224 224 +44376 ./prep_dataset/ILSVRC2012_val_00033513.bin 224 224 +44377 ./prep_dataset/ILSVRC2012_val_00019632.bin 224 224 +44378 ./prep_dataset/ILSVRC2012_val_00046578.bin 224 224 +44379 ./prep_dataset/ILSVRC2012_val_00019784.bin 224 224 +44380 ./prep_dataset/ILSVRC2012_val_00013947.bin 224 224 +44381 ./prep_dataset/ILSVRC2012_val_00018492.bin 224 224 +44382 ./prep_dataset/ILSVRC2012_val_00014011.bin 224 224 +44383 ./prep_dataset/ILSVRC2012_val_00005035.bin 224 224 +44384 ./prep_dataset/ILSVRC2012_val_00018104.bin 224 224 +44385 ./prep_dataset/ILSVRC2012_val_00046449.bin 224 224 +44386 ./prep_dataset/ILSVRC2012_val_00022634.bin 224 224 +44387 ./prep_dataset/ILSVRC2012_val_00001149.bin 224 224 +44388 ./prep_dataset/ILSVRC2012_val_00045232.bin 224 224 +44389 ./prep_dataset/ILSVRC2012_val_00034978.bin 224 224 +44390 ./prep_dataset/ILSVRC2012_val_00007335.bin 224 224 +44391 ./prep_dataset/ILSVRC2012_val_00013035.bin 224 224 +44392 ./prep_dataset/ILSVRC2012_val_00025045.bin 224 224 +44393 ./prep_dataset/ILSVRC2012_val_00006825.bin 224 224 +44394 ./prep_dataset/ILSVRC2012_val_00020683.bin 224 224 +44395 ./prep_dataset/ILSVRC2012_val_00006007.bin 224 224 +44396 ./prep_dataset/ILSVRC2012_val_00003041.bin 224 224 +44397 ./prep_dataset/ILSVRC2012_val_00015222.bin 224 224 +44398 ./prep_dataset/ILSVRC2012_val_00036639.bin 224 224 +44399 ./prep_dataset/ILSVRC2012_val_00036458.bin 224 224 +44400 ./prep_dataset/ILSVRC2012_val_00015347.bin 224 224 +44401 ./prep_dataset/ILSVRC2012_val_00017519.bin 224 224 +44402 ./prep_dataset/ILSVRC2012_val_00031238.bin 224 224 +44403 ./prep_dataset/ILSVRC2012_val_00044999.bin 224 224 +44404 ./prep_dataset/ILSVRC2012_val_00046836.bin 224 224 +44405 ./prep_dataset/ILSVRC2012_val_00013319.bin 224 224 +44406 ./prep_dataset/ILSVRC2012_val_00039110.bin 224 224 +44407 ./prep_dataset/ILSVRC2012_val_00006542.bin 224 224 +44408 ./prep_dataset/ILSVRC2012_val_00015068.bin 224 224 +44409 ./prep_dataset/ILSVRC2012_val_00016788.bin 224 224 +44410 ./prep_dataset/ILSVRC2012_val_00030271.bin 224 224 +44411 ./prep_dataset/ILSVRC2012_val_00032627.bin 224 224 +44412 ./prep_dataset/ILSVRC2012_val_00020810.bin 224 224 +44413 ./prep_dataset/ILSVRC2012_val_00031420.bin 224 224 +44414 ./prep_dataset/ILSVRC2012_val_00004315.bin 224 224 +44415 ./prep_dataset/ILSVRC2012_val_00005843.bin 224 224 +44416 ./prep_dataset/ILSVRC2012_val_00002023.bin 224 224 +44417 ./prep_dataset/ILSVRC2012_val_00039270.bin 224 224 +44418 ./prep_dataset/ILSVRC2012_val_00006531.bin 224 224 +44419 ./prep_dataset/ILSVRC2012_val_00038807.bin 224 224 +44420 ./prep_dataset/ILSVRC2012_val_00049605.bin 224 224 +44421 ./prep_dataset/ILSVRC2012_val_00044480.bin 224 224 +44422 ./prep_dataset/ILSVRC2012_val_00001487.bin 224 224 +44423 ./prep_dataset/ILSVRC2012_val_00003387.bin 224 224 +44424 ./prep_dataset/ILSVRC2012_val_00030938.bin 224 224 +44425 ./prep_dataset/ILSVRC2012_val_00048611.bin 224 224 +44426 ./prep_dataset/ILSVRC2012_val_00003967.bin 224 224 +44427 ./prep_dataset/ILSVRC2012_val_00029292.bin 224 224 +44428 ./prep_dataset/ILSVRC2012_val_00039900.bin 224 224 +44429 ./prep_dataset/ILSVRC2012_val_00025112.bin 224 224 +44430 ./prep_dataset/ILSVRC2012_val_00033993.bin 224 224 +44431 ./prep_dataset/ILSVRC2012_val_00033316.bin 224 224 +44432 ./prep_dataset/ILSVRC2012_val_00014668.bin 224 224 +44433 ./prep_dataset/ILSVRC2012_val_00029353.bin 224 224 +44434 ./prep_dataset/ILSVRC2012_val_00017115.bin 224 224 +44435 ./prep_dataset/ILSVRC2012_val_00016064.bin 224 224 +44436 ./prep_dataset/ILSVRC2012_val_00015343.bin 224 224 +44437 ./prep_dataset/ILSVRC2012_val_00026244.bin 224 224 +44438 ./prep_dataset/ILSVRC2012_val_00040910.bin 224 224 +44439 ./prep_dataset/ILSVRC2012_val_00010783.bin 224 224 +44440 ./prep_dataset/ILSVRC2012_val_00038610.bin 224 224 +44441 ./prep_dataset/ILSVRC2012_val_00031740.bin 224 224 +44442 ./prep_dataset/ILSVRC2012_val_00012717.bin 224 224 +44443 ./prep_dataset/ILSVRC2012_val_00008094.bin 224 224 +44444 ./prep_dataset/ILSVRC2012_val_00017384.bin 224 224 +44445 ./prep_dataset/ILSVRC2012_val_00028594.bin 224 224 +44446 ./prep_dataset/ILSVRC2012_val_00042251.bin 224 224 +44447 ./prep_dataset/ILSVRC2012_val_00013909.bin 224 224 +44448 ./prep_dataset/ILSVRC2012_val_00025881.bin 224 224 +44449 ./prep_dataset/ILSVRC2012_val_00045835.bin 224 224 +44450 ./prep_dataset/ILSVRC2012_val_00000248.bin 224 224 +44451 ./prep_dataset/ILSVRC2012_val_00028686.bin 224 224 +44452 ./prep_dataset/ILSVRC2012_val_00020114.bin 224 224 +44453 ./prep_dataset/ILSVRC2012_val_00021425.bin 224 224 +44454 ./prep_dataset/ILSVRC2012_val_00047384.bin 224 224 +44455 ./prep_dataset/ILSVRC2012_val_00015358.bin 224 224 +44456 ./prep_dataset/ILSVRC2012_val_00000534.bin 224 224 +44457 ./prep_dataset/ILSVRC2012_val_00025592.bin 224 224 +44458 ./prep_dataset/ILSVRC2012_val_00036203.bin 224 224 +44459 ./prep_dataset/ILSVRC2012_val_00035008.bin 224 224 +44460 ./prep_dataset/ILSVRC2012_val_00021865.bin 224 224 +44461 ./prep_dataset/ILSVRC2012_val_00047392.bin 224 224 +44462 ./prep_dataset/ILSVRC2012_val_00017202.bin 224 224 +44463 ./prep_dataset/ILSVRC2012_val_00005500.bin 224 224 +44464 ./prep_dataset/ILSVRC2012_val_00032289.bin 224 224 +44465 ./prep_dataset/ILSVRC2012_val_00018683.bin 224 224 +44466 ./prep_dataset/ILSVRC2012_val_00009261.bin 224 224 +44467 ./prep_dataset/ILSVRC2012_val_00037939.bin 224 224 +44468 ./prep_dataset/ILSVRC2012_val_00047150.bin 224 224 +44469 ./prep_dataset/ILSVRC2012_val_00038419.bin 224 224 +44470 ./prep_dataset/ILSVRC2012_val_00030324.bin 224 224 +44471 ./prep_dataset/ILSVRC2012_val_00015254.bin 224 224 +44472 ./prep_dataset/ILSVRC2012_val_00048524.bin 224 224 +44473 ./prep_dataset/ILSVRC2012_val_00029792.bin 224 224 +44474 ./prep_dataset/ILSVRC2012_val_00030158.bin 224 224 +44475 ./prep_dataset/ILSVRC2012_val_00041665.bin 224 224 +44476 ./prep_dataset/ILSVRC2012_val_00018887.bin 224 224 +44477 ./prep_dataset/ILSVRC2012_val_00040207.bin 224 224 +44478 ./prep_dataset/ILSVRC2012_val_00017892.bin 224 224 +44479 ./prep_dataset/ILSVRC2012_val_00033786.bin 224 224 +44480 ./prep_dataset/ILSVRC2012_val_00026345.bin 224 224 +44481 ./prep_dataset/ILSVRC2012_val_00027122.bin 224 224 +44482 ./prep_dataset/ILSVRC2012_val_00048829.bin 224 224 +44483 ./prep_dataset/ILSVRC2012_val_00015372.bin 224 224 +44484 ./prep_dataset/ILSVRC2012_val_00026917.bin 224 224 +44485 ./prep_dataset/ILSVRC2012_val_00016040.bin 224 224 +44486 ./prep_dataset/ILSVRC2012_val_00013471.bin 224 224 +44487 ./prep_dataset/ILSVRC2012_val_00004693.bin 224 224 +44488 ./prep_dataset/ILSVRC2012_val_00030725.bin 224 224 +44489 ./prep_dataset/ILSVRC2012_val_00019900.bin 224 224 +44490 ./prep_dataset/ILSVRC2012_val_00007900.bin 224 224 +44491 ./prep_dataset/ILSVRC2012_val_00023394.bin 224 224 +44492 ./prep_dataset/ILSVRC2012_val_00028270.bin 224 224 +44493 ./prep_dataset/ILSVRC2012_val_00026641.bin 224 224 +44494 ./prep_dataset/ILSVRC2012_val_00035102.bin 224 224 +44495 ./prep_dataset/ILSVRC2012_val_00011116.bin 224 224 +44496 ./prep_dataset/ILSVRC2012_val_00015122.bin 224 224 +44497 ./prep_dataset/ILSVRC2012_val_00019950.bin 224 224 +44498 ./prep_dataset/ILSVRC2012_val_00031796.bin 224 224 +44499 ./prep_dataset/ILSVRC2012_val_00039701.bin 224 224 +44500 ./prep_dataset/ILSVRC2012_val_00017006.bin 224 224 +44501 ./prep_dataset/ILSVRC2012_val_00049405.bin 224 224 +44502 ./prep_dataset/ILSVRC2012_val_00019981.bin 224 224 +44503 ./prep_dataset/ILSVRC2012_val_00013323.bin 224 224 +44504 ./prep_dataset/ILSVRC2012_val_00043770.bin 224 224 +44505 ./prep_dataset/ILSVRC2012_val_00043235.bin 224 224 +44506 ./prep_dataset/ILSVRC2012_val_00007896.bin 224 224 +44507 ./prep_dataset/ILSVRC2012_val_00036067.bin 224 224 +44508 ./prep_dataset/ILSVRC2012_val_00019431.bin 224 224 +44509 ./prep_dataset/ILSVRC2012_val_00036436.bin 224 224 +44510 ./prep_dataset/ILSVRC2012_val_00049375.bin 224 224 +44511 ./prep_dataset/ILSVRC2012_val_00020173.bin 224 224 +44512 ./prep_dataset/ILSVRC2012_val_00036989.bin 224 224 +44513 ./prep_dataset/ILSVRC2012_val_00013837.bin 224 224 +44514 ./prep_dataset/ILSVRC2012_val_00029426.bin 224 224 +44515 ./prep_dataset/ILSVRC2012_val_00037147.bin 224 224 +44516 ./prep_dataset/ILSVRC2012_val_00018935.bin 224 224 +44517 ./prep_dataset/ILSVRC2012_val_00043851.bin 224 224 +44518 ./prep_dataset/ILSVRC2012_val_00004038.bin 224 224 +44519 ./prep_dataset/ILSVRC2012_val_00006838.bin 224 224 +44520 ./prep_dataset/ILSVRC2012_val_00018850.bin 224 224 +44521 ./prep_dataset/ILSVRC2012_val_00019079.bin 224 224 +44522 ./prep_dataset/ILSVRC2012_val_00049551.bin 224 224 +44523 ./prep_dataset/ILSVRC2012_val_00036791.bin 224 224 +44524 ./prep_dataset/ILSVRC2012_val_00045866.bin 224 224 +44525 ./prep_dataset/ILSVRC2012_val_00034238.bin 224 224 +44526 ./prep_dataset/ILSVRC2012_val_00012742.bin 224 224 +44527 ./prep_dataset/ILSVRC2012_val_00034587.bin 224 224 +44528 ./prep_dataset/ILSVRC2012_val_00014971.bin 224 224 +44529 ./prep_dataset/ILSVRC2012_val_00030231.bin 224 224 +44530 ./prep_dataset/ILSVRC2012_val_00022095.bin 224 224 +44531 ./prep_dataset/ILSVRC2012_val_00035889.bin 224 224 +44532 ./prep_dataset/ILSVRC2012_val_00043970.bin 224 224 +44533 ./prep_dataset/ILSVRC2012_val_00028546.bin 224 224 +44534 ./prep_dataset/ILSVRC2012_val_00005335.bin 224 224 +44535 ./prep_dataset/ILSVRC2012_val_00037234.bin 224 224 +44536 ./prep_dataset/ILSVRC2012_val_00018447.bin 224 224 +44537 ./prep_dataset/ILSVRC2012_val_00045497.bin 224 224 +44538 ./prep_dataset/ILSVRC2012_val_00028052.bin 224 224 +44539 ./prep_dataset/ILSVRC2012_val_00049497.bin 224 224 +44540 ./prep_dataset/ILSVRC2012_val_00039968.bin 224 224 +44541 ./prep_dataset/ILSVRC2012_val_00013817.bin 224 224 +44542 ./prep_dataset/ILSVRC2012_val_00045062.bin 224 224 +44543 ./prep_dataset/ILSVRC2012_val_00005542.bin 224 224 +44544 ./prep_dataset/ILSVRC2012_val_00023859.bin 224 224 +44545 ./prep_dataset/ILSVRC2012_val_00019460.bin 224 224 +44546 ./prep_dataset/ILSVRC2012_val_00017505.bin 224 224 +44547 ./prep_dataset/ILSVRC2012_val_00025586.bin 224 224 +44548 ./prep_dataset/ILSVRC2012_val_00005334.bin 224 224 +44549 ./prep_dataset/ILSVRC2012_val_00041504.bin 224 224 +44550 ./prep_dataset/ILSVRC2012_val_00000750.bin 224 224 +44551 ./prep_dataset/ILSVRC2012_val_00038011.bin 224 224 +44552 ./prep_dataset/ILSVRC2012_val_00009349.bin 224 224 +44553 ./prep_dataset/ILSVRC2012_val_00042860.bin 224 224 +44554 ./prep_dataset/ILSVRC2012_val_00001896.bin 224 224 +44555 ./prep_dataset/ILSVRC2012_val_00047194.bin 224 224 +44556 ./prep_dataset/ILSVRC2012_val_00015306.bin 224 224 +44557 ./prep_dataset/ILSVRC2012_val_00039460.bin 224 224 +44558 ./prep_dataset/ILSVRC2012_val_00029417.bin 224 224 +44559 ./prep_dataset/ILSVRC2012_val_00020492.bin 224 224 +44560 ./prep_dataset/ILSVRC2012_val_00032697.bin 224 224 +44561 ./prep_dataset/ILSVRC2012_val_00042540.bin 224 224 +44562 ./prep_dataset/ILSVRC2012_val_00016868.bin 224 224 +44563 ./prep_dataset/ILSVRC2012_val_00032486.bin 224 224 +44564 ./prep_dataset/ILSVRC2012_val_00031022.bin 224 224 +44565 ./prep_dataset/ILSVRC2012_val_00010286.bin 224 224 +44566 ./prep_dataset/ILSVRC2012_val_00030009.bin 224 224 +44567 ./prep_dataset/ILSVRC2012_val_00020971.bin 224 224 +44568 ./prep_dataset/ILSVRC2012_val_00011968.bin 224 224 +44569 ./prep_dataset/ILSVRC2012_val_00024315.bin 224 224 +44570 ./prep_dataset/ILSVRC2012_val_00034790.bin 224 224 +44571 ./prep_dataset/ILSVRC2012_val_00020144.bin 224 224 +44572 ./prep_dataset/ILSVRC2012_val_00012360.bin 224 224 +44573 ./prep_dataset/ILSVRC2012_val_00044198.bin 224 224 +44574 ./prep_dataset/ILSVRC2012_val_00026346.bin 224 224 +44575 ./prep_dataset/ILSVRC2012_val_00014547.bin 224 224 +44576 ./prep_dataset/ILSVRC2012_val_00049874.bin 224 224 +44577 ./prep_dataset/ILSVRC2012_val_00035321.bin 224 224 +44578 ./prep_dataset/ILSVRC2012_val_00049218.bin 224 224 +44579 ./prep_dataset/ILSVRC2012_val_00048213.bin 224 224 +44580 ./prep_dataset/ILSVRC2012_val_00027802.bin 224 224 +44581 ./prep_dataset/ILSVRC2012_val_00041799.bin 224 224 +44582 ./prep_dataset/ILSVRC2012_val_00029736.bin 224 224 +44583 ./prep_dataset/ILSVRC2012_val_00047089.bin 224 224 +44584 ./prep_dataset/ILSVRC2012_val_00033541.bin 224 224 +44585 ./prep_dataset/ILSVRC2012_val_00019484.bin 224 224 +44586 ./prep_dataset/ILSVRC2012_val_00047386.bin 224 224 +44587 ./prep_dataset/ILSVRC2012_val_00001300.bin 224 224 +44588 ./prep_dataset/ILSVRC2012_val_00006211.bin 224 224 +44589 ./prep_dataset/ILSVRC2012_val_00032951.bin 224 224 +44590 ./prep_dataset/ILSVRC2012_val_00040270.bin 224 224 +44591 ./prep_dataset/ILSVRC2012_val_00014390.bin 224 224 +44592 ./prep_dataset/ILSVRC2012_val_00011522.bin 224 224 +44593 ./prep_dataset/ILSVRC2012_val_00014046.bin 224 224 +44594 ./prep_dataset/ILSVRC2012_val_00031852.bin 224 224 +44595 ./prep_dataset/ILSVRC2012_val_00009043.bin 224 224 +44596 ./prep_dataset/ILSVRC2012_val_00045385.bin 224 224 +44597 ./prep_dataset/ILSVRC2012_val_00021903.bin 224 224 +44598 ./prep_dataset/ILSVRC2012_val_00022161.bin 224 224 +44599 ./prep_dataset/ILSVRC2012_val_00037148.bin 224 224 +44600 ./prep_dataset/ILSVRC2012_val_00008391.bin 224 224 +44601 ./prep_dataset/ILSVRC2012_val_00008311.bin 224 224 +44602 ./prep_dataset/ILSVRC2012_val_00012463.bin 224 224 +44603 ./prep_dataset/ILSVRC2012_val_00024985.bin 224 224 +44604 ./prep_dataset/ILSVRC2012_val_00041235.bin 224 224 +44605 ./prep_dataset/ILSVRC2012_val_00001606.bin 224 224 +44606 ./prep_dataset/ILSVRC2012_val_00033097.bin 224 224 +44607 ./prep_dataset/ILSVRC2012_val_00007099.bin 224 224 +44608 ./prep_dataset/ILSVRC2012_val_00011347.bin 224 224 +44609 ./prep_dataset/ILSVRC2012_val_00007354.bin 224 224 +44610 ./prep_dataset/ILSVRC2012_val_00031672.bin 224 224 +44611 ./prep_dataset/ILSVRC2012_val_00021528.bin 224 224 +44612 ./prep_dataset/ILSVRC2012_val_00034968.bin 224 224 +44613 ./prep_dataset/ILSVRC2012_val_00018856.bin 224 224 +44614 ./prep_dataset/ILSVRC2012_val_00030036.bin 224 224 +44615 ./prep_dataset/ILSVRC2012_val_00012737.bin 224 224 +44616 ./prep_dataset/ILSVRC2012_val_00009759.bin 224 224 +44617 ./prep_dataset/ILSVRC2012_val_00018407.bin 224 224 +44618 ./prep_dataset/ILSVRC2012_val_00029410.bin 224 224 +44619 ./prep_dataset/ILSVRC2012_val_00033130.bin 224 224 +44620 ./prep_dataset/ILSVRC2012_val_00025570.bin 224 224 +44621 ./prep_dataset/ILSVRC2012_val_00044709.bin 224 224 +44622 ./prep_dataset/ILSVRC2012_val_00028463.bin 224 224 +44623 ./prep_dataset/ILSVRC2012_val_00001358.bin 224 224 +44624 ./prep_dataset/ILSVRC2012_val_00029834.bin 224 224 +44625 ./prep_dataset/ILSVRC2012_val_00008852.bin 224 224 +44626 ./prep_dataset/ILSVRC2012_val_00031060.bin 224 224 +44627 ./prep_dataset/ILSVRC2012_val_00006990.bin 224 224 +44628 ./prep_dataset/ILSVRC2012_val_00011511.bin 224 224 +44629 ./prep_dataset/ILSVRC2012_val_00012650.bin 224 224 +44630 ./prep_dataset/ILSVRC2012_val_00040627.bin 224 224 +44631 ./prep_dataset/ILSVRC2012_val_00003694.bin 224 224 +44632 ./prep_dataset/ILSVRC2012_val_00035233.bin 224 224 +44633 ./prep_dataset/ILSVRC2012_val_00029656.bin 224 224 +44634 ./prep_dataset/ILSVRC2012_val_00020895.bin 224 224 +44635 ./prep_dataset/ILSVRC2012_val_00030327.bin 224 224 +44636 ./prep_dataset/ILSVRC2012_val_00017541.bin 224 224 +44637 ./prep_dataset/ILSVRC2012_val_00035874.bin 224 224 +44638 ./prep_dataset/ILSVRC2012_val_00043315.bin 224 224 +44639 ./prep_dataset/ILSVRC2012_val_00044274.bin 224 224 +44640 ./prep_dataset/ILSVRC2012_val_00035103.bin 224 224 +44641 ./prep_dataset/ILSVRC2012_val_00032616.bin 224 224 +44642 ./prep_dataset/ILSVRC2012_val_00048624.bin 224 224 +44643 ./prep_dataset/ILSVRC2012_val_00044338.bin 224 224 +44644 ./prep_dataset/ILSVRC2012_val_00028553.bin 224 224 +44645 ./prep_dataset/ILSVRC2012_val_00002176.bin 224 224 +44646 ./prep_dataset/ILSVRC2012_val_00021829.bin 224 224 +44647 ./prep_dataset/ILSVRC2012_val_00004255.bin 224 224 +44648 ./prep_dataset/ILSVRC2012_val_00013688.bin 224 224 +44649 ./prep_dataset/ILSVRC2012_val_00020004.bin 224 224 +44650 ./prep_dataset/ILSVRC2012_val_00023097.bin 224 224 +44651 ./prep_dataset/ILSVRC2012_val_00011369.bin 224 224 +44652 ./prep_dataset/ILSVRC2012_val_00006890.bin 224 224 +44653 ./prep_dataset/ILSVRC2012_val_00016530.bin 224 224 +44654 ./prep_dataset/ILSVRC2012_val_00040966.bin 224 224 +44655 ./prep_dataset/ILSVRC2012_val_00021525.bin 224 224 +44656 ./prep_dataset/ILSVRC2012_val_00024041.bin 224 224 +44657 ./prep_dataset/ILSVRC2012_val_00012801.bin 224 224 +44658 ./prep_dataset/ILSVRC2012_val_00008865.bin 224 224 +44659 ./prep_dataset/ILSVRC2012_val_00008013.bin 224 224 +44660 ./prep_dataset/ILSVRC2012_val_00041955.bin 224 224 +44661 ./prep_dataset/ILSVRC2012_val_00037364.bin 224 224 +44662 ./prep_dataset/ILSVRC2012_val_00013118.bin 224 224 +44663 ./prep_dataset/ILSVRC2012_val_00006431.bin 224 224 +44664 ./prep_dataset/ILSVRC2012_val_00049814.bin 224 224 +44665 ./prep_dataset/ILSVRC2012_val_00046843.bin 224 224 +44666 ./prep_dataset/ILSVRC2012_val_00022199.bin 224 224 +44667 ./prep_dataset/ILSVRC2012_val_00017470.bin 224 224 +44668 ./prep_dataset/ILSVRC2012_val_00033116.bin 224 224 +44669 ./prep_dataset/ILSVRC2012_val_00011146.bin 224 224 +44670 ./prep_dataset/ILSVRC2012_val_00002242.bin 224 224 +44671 ./prep_dataset/ILSVRC2012_val_00032424.bin 224 224 +44672 ./prep_dataset/ILSVRC2012_val_00045108.bin 224 224 +44673 ./prep_dataset/ILSVRC2012_val_00001956.bin 224 224 +44674 ./prep_dataset/ILSVRC2012_val_00029885.bin 224 224 +44675 ./prep_dataset/ILSVRC2012_val_00019620.bin 224 224 +44676 ./prep_dataset/ILSVRC2012_val_00043882.bin 224 224 +44677 ./prep_dataset/ILSVRC2012_val_00021767.bin 224 224 +44678 ./prep_dataset/ILSVRC2012_val_00040285.bin 224 224 +44679 ./prep_dataset/ILSVRC2012_val_00037510.bin 224 224 +44680 ./prep_dataset/ILSVRC2012_val_00045273.bin 224 224 +44681 ./prep_dataset/ILSVRC2012_val_00046446.bin 224 224 +44682 ./prep_dataset/ILSVRC2012_val_00039625.bin 224 224 +44683 ./prep_dataset/ILSVRC2012_val_00034936.bin 224 224 +44684 ./prep_dataset/ILSVRC2012_val_00013014.bin 224 224 +44685 ./prep_dataset/ILSVRC2012_val_00026522.bin 224 224 +44686 ./prep_dataset/ILSVRC2012_val_00023405.bin 224 224 +44687 ./prep_dataset/ILSVRC2012_val_00024209.bin 224 224 +44688 ./prep_dataset/ILSVRC2012_val_00019203.bin 224 224 +44689 ./prep_dataset/ILSVRC2012_val_00048602.bin 224 224 +44690 ./prep_dataset/ILSVRC2012_val_00004387.bin 224 224 +44691 ./prep_dataset/ILSVRC2012_val_00043053.bin 224 224 +44692 ./prep_dataset/ILSVRC2012_val_00048614.bin 224 224 +44693 ./prep_dataset/ILSVRC2012_val_00030001.bin 224 224 +44694 ./prep_dataset/ILSVRC2012_val_00016497.bin 224 224 +44695 ./prep_dataset/ILSVRC2012_val_00045838.bin 224 224 +44696 ./prep_dataset/ILSVRC2012_val_00042683.bin 224 224 +44697 ./prep_dataset/ILSVRC2012_val_00013670.bin 224 224 +44698 ./prep_dataset/ILSVRC2012_val_00031061.bin 224 224 +44699 ./prep_dataset/ILSVRC2012_val_00000266.bin 224 224 +44700 ./prep_dataset/ILSVRC2012_val_00037124.bin 224 224 +44701 ./prep_dataset/ILSVRC2012_val_00032989.bin 224 224 +44702 ./prep_dataset/ILSVRC2012_val_00024488.bin 224 224 +44703 ./prep_dataset/ILSVRC2012_val_00017528.bin 224 224 +44704 ./prep_dataset/ILSVRC2012_val_00047651.bin 224 224 +44705 ./prep_dataset/ILSVRC2012_val_00018223.bin 224 224 +44706 ./prep_dataset/ILSVRC2012_val_00027911.bin 224 224 +44707 ./prep_dataset/ILSVRC2012_val_00019947.bin 224 224 +44708 ./prep_dataset/ILSVRC2012_val_00002421.bin 224 224 +44709 ./prep_dataset/ILSVRC2012_val_00008098.bin 224 224 +44710 ./prep_dataset/ILSVRC2012_val_00016010.bin 224 224 +44711 ./prep_dataset/ILSVRC2012_val_00001145.bin 224 224 +44712 ./prep_dataset/ILSVRC2012_val_00049097.bin 224 224 +44713 ./prep_dataset/ILSVRC2012_val_00040686.bin 224 224 +44714 ./prep_dataset/ILSVRC2012_val_00014457.bin 224 224 +44715 ./prep_dataset/ILSVRC2012_val_00009516.bin 224 224 +44716 ./prep_dataset/ILSVRC2012_val_00028066.bin 224 224 +44717 ./prep_dataset/ILSVRC2012_val_00015036.bin 224 224 +44718 ./prep_dataset/ILSVRC2012_val_00045854.bin 224 224 +44719 ./prep_dataset/ILSVRC2012_val_00041495.bin 224 224 +44720 ./prep_dataset/ILSVRC2012_val_00015831.bin 224 224 +44721 ./prep_dataset/ILSVRC2012_val_00005565.bin 224 224 +44722 ./prep_dataset/ILSVRC2012_val_00017879.bin 224 224 +44723 ./prep_dataset/ILSVRC2012_val_00023561.bin 224 224 +44724 ./prep_dataset/ILSVRC2012_val_00035300.bin 224 224 +44725 ./prep_dataset/ILSVRC2012_val_00023739.bin 224 224 +44726 ./prep_dataset/ILSVRC2012_val_00022243.bin 224 224 +44727 ./prep_dataset/ILSVRC2012_val_00024447.bin 224 224 +44728 ./prep_dataset/ILSVRC2012_val_00031904.bin 224 224 +44729 ./prep_dataset/ILSVRC2012_val_00030642.bin 224 224 +44730 ./prep_dataset/ILSVRC2012_val_00011187.bin 224 224 +44731 ./prep_dataset/ILSVRC2012_val_00019027.bin 224 224 +44732 ./prep_dataset/ILSVRC2012_val_00042195.bin 224 224 +44733 ./prep_dataset/ILSVRC2012_val_00046759.bin 224 224 +44734 ./prep_dataset/ILSVRC2012_val_00008318.bin 224 224 +44735 ./prep_dataset/ILSVRC2012_val_00025583.bin 224 224 +44736 ./prep_dataset/ILSVRC2012_val_00047907.bin 224 224 +44737 ./prep_dataset/ILSVRC2012_val_00000156.bin 224 224 +44738 ./prep_dataset/ILSVRC2012_val_00002121.bin 224 224 +44739 ./prep_dataset/ILSVRC2012_val_00022027.bin 224 224 +44740 ./prep_dataset/ILSVRC2012_val_00046306.bin 224 224 +44741 ./prep_dataset/ILSVRC2012_val_00007181.bin 224 224 +44742 ./prep_dataset/ILSVRC2012_val_00024003.bin 224 224 +44743 ./prep_dataset/ILSVRC2012_val_00004322.bin 224 224 +44744 ./prep_dataset/ILSVRC2012_val_00001368.bin 224 224 +44745 ./prep_dataset/ILSVRC2012_val_00016690.bin 224 224 +44746 ./prep_dataset/ILSVRC2012_val_00038416.bin 224 224 +44747 ./prep_dataset/ILSVRC2012_val_00010277.bin 224 224 +44748 ./prep_dataset/ILSVRC2012_val_00022736.bin 224 224 +44749 ./prep_dataset/ILSVRC2012_val_00043952.bin 224 224 +44750 ./prep_dataset/ILSVRC2012_val_00048875.bin 224 224 +44751 ./prep_dataset/ILSVRC2012_val_00022490.bin 224 224 +44752 ./prep_dataset/ILSVRC2012_val_00009153.bin 224 224 +44753 ./prep_dataset/ILSVRC2012_val_00039825.bin 224 224 +44754 ./prep_dataset/ILSVRC2012_val_00019272.bin 224 224 +44755 ./prep_dataset/ILSVRC2012_val_00008656.bin 224 224 +44756 ./prep_dataset/ILSVRC2012_val_00023309.bin 224 224 +44757 ./prep_dataset/ILSVRC2012_val_00048714.bin 224 224 +44758 ./prep_dataset/ILSVRC2012_val_00042155.bin 224 224 +44759 ./prep_dataset/ILSVRC2012_val_00049407.bin 224 224 +44760 ./prep_dataset/ILSVRC2012_val_00013155.bin 224 224 +44761 ./prep_dataset/ILSVRC2012_val_00013275.bin 224 224 +44762 ./prep_dataset/ILSVRC2012_val_00010787.bin 224 224 +44763 ./prep_dataset/ILSVRC2012_val_00012872.bin 224 224 +44764 ./prep_dataset/ILSVRC2012_val_00011232.bin 224 224 +44765 ./prep_dataset/ILSVRC2012_val_00000368.bin 224 224 +44766 ./prep_dataset/ILSVRC2012_val_00043984.bin 224 224 +44767 ./prep_dataset/ILSVRC2012_val_00002500.bin 224 224 +44768 ./prep_dataset/ILSVRC2012_val_00045756.bin 224 224 +44769 ./prep_dataset/ILSVRC2012_val_00003026.bin 224 224 +44770 ./prep_dataset/ILSVRC2012_val_00015933.bin 224 224 +44771 ./prep_dataset/ILSVRC2012_val_00028490.bin 224 224 +44772 ./prep_dataset/ILSVRC2012_val_00000636.bin 224 224 +44773 ./prep_dataset/ILSVRC2012_val_00029713.bin 224 224 +44774 ./prep_dataset/ILSVRC2012_val_00029868.bin 224 224 +44775 ./prep_dataset/ILSVRC2012_val_00041823.bin 224 224 +44776 ./prep_dataset/ILSVRC2012_val_00008556.bin 224 224 +44777 ./prep_dataset/ILSVRC2012_val_00047261.bin 224 224 +44778 ./prep_dataset/ILSVRC2012_val_00032899.bin 224 224 +44779 ./prep_dataset/ILSVRC2012_val_00006880.bin 224 224 +44780 ./prep_dataset/ILSVRC2012_val_00011717.bin 224 224 +44781 ./prep_dataset/ILSVRC2012_val_00022141.bin 224 224 +44782 ./prep_dataset/ILSVRC2012_val_00015600.bin 224 224 +44783 ./prep_dataset/ILSVRC2012_val_00012231.bin 224 224 +44784 ./prep_dataset/ILSVRC2012_val_00041427.bin 224 224 +44785 ./prep_dataset/ILSVRC2012_val_00037573.bin 224 224 +44786 ./prep_dataset/ILSVRC2012_val_00044826.bin 224 224 +44787 ./prep_dataset/ILSVRC2012_val_00049348.bin 224 224 +44788 ./prep_dataset/ILSVRC2012_val_00020137.bin 224 224 +44789 ./prep_dataset/ILSVRC2012_val_00004893.bin 224 224 +44790 ./prep_dataset/ILSVRC2012_val_00006913.bin 224 224 +44791 ./prep_dataset/ILSVRC2012_val_00017334.bin 224 224 +44792 ./prep_dataset/ILSVRC2012_val_00044134.bin 224 224 +44793 ./prep_dataset/ILSVRC2012_val_00014651.bin 224 224 +44794 ./prep_dataset/ILSVRC2012_val_00024073.bin 224 224 +44795 ./prep_dataset/ILSVRC2012_val_00030663.bin 224 224 +44796 ./prep_dataset/ILSVRC2012_val_00039793.bin 224 224 +44797 ./prep_dataset/ILSVRC2012_val_00024016.bin 224 224 +44798 ./prep_dataset/ILSVRC2012_val_00020067.bin 224 224 +44799 ./prep_dataset/ILSVRC2012_val_00018516.bin 224 224 +44800 ./prep_dataset/ILSVRC2012_val_00041752.bin 224 224 +44801 ./prep_dataset/ILSVRC2012_val_00039147.bin 224 224 +44802 ./prep_dataset/ILSVRC2012_val_00000951.bin 224 224 +44803 ./prep_dataset/ILSVRC2012_val_00028267.bin 224 224 +44804 ./prep_dataset/ILSVRC2012_val_00007934.bin 224 224 +44805 ./prep_dataset/ILSVRC2012_val_00037720.bin 224 224 +44806 ./prep_dataset/ILSVRC2012_val_00003378.bin 224 224 +44807 ./prep_dataset/ILSVRC2012_val_00003613.bin 224 224 +44808 ./prep_dataset/ILSVRC2012_val_00029989.bin 224 224 +44809 ./prep_dataset/ILSVRC2012_val_00028735.bin 224 224 +44810 ./prep_dataset/ILSVRC2012_val_00037349.bin 224 224 +44811 ./prep_dataset/ILSVRC2012_val_00018909.bin 224 224 +44812 ./prep_dataset/ILSVRC2012_val_00036936.bin 224 224 +44813 ./prep_dataset/ILSVRC2012_val_00019731.bin 224 224 +44814 ./prep_dataset/ILSVRC2012_val_00028920.bin 224 224 +44815 ./prep_dataset/ILSVRC2012_val_00028881.bin 224 224 +44816 ./prep_dataset/ILSVRC2012_val_00006165.bin 224 224 +44817 ./prep_dataset/ILSVRC2012_val_00029954.bin 224 224 +44818 ./prep_dataset/ILSVRC2012_val_00039139.bin 224 224 +44819 ./prep_dataset/ILSVRC2012_val_00026697.bin 224 224 +44820 ./prep_dataset/ILSVRC2012_val_00038547.bin 224 224 +44821 ./prep_dataset/ILSVRC2012_val_00045469.bin 224 224 +44822 ./prep_dataset/ILSVRC2012_val_00012378.bin 224 224 +44823 ./prep_dataset/ILSVRC2012_val_00007728.bin 224 224 +44824 ./prep_dataset/ILSVRC2012_val_00020976.bin 224 224 +44825 ./prep_dataset/ILSVRC2012_val_00049573.bin 224 224 +44826 ./prep_dataset/ILSVRC2012_val_00018898.bin 224 224 +44827 ./prep_dataset/ILSVRC2012_val_00004848.bin 224 224 +44828 ./prep_dataset/ILSVRC2012_val_00029093.bin 224 224 +44829 ./prep_dataset/ILSVRC2012_val_00006297.bin 224 224 +44830 ./prep_dataset/ILSVRC2012_val_00030323.bin 224 224 +44831 ./prep_dataset/ILSVRC2012_val_00028793.bin 224 224 +44832 ./prep_dataset/ILSVRC2012_val_00007615.bin 224 224 +44833 ./prep_dataset/ILSVRC2012_val_00023904.bin 224 224 +44834 ./prep_dataset/ILSVRC2012_val_00041066.bin 224 224 +44835 ./prep_dataset/ILSVRC2012_val_00023924.bin 224 224 +44836 ./prep_dataset/ILSVRC2012_val_00001844.bin 224 224 +44837 ./prep_dataset/ILSVRC2012_val_00023771.bin 224 224 +44838 ./prep_dataset/ILSVRC2012_val_00008184.bin 224 224 +44839 ./prep_dataset/ILSVRC2012_val_00040291.bin 224 224 +44840 ./prep_dataset/ILSVRC2012_val_00011695.bin 224 224 +44841 ./prep_dataset/ILSVRC2012_val_00016539.bin 224 224 +44842 ./prep_dataset/ILSVRC2012_val_00017789.bin 224 224 +44843 ./prep_dataset/ILSVRC2012_val_00041647.bin 224 224 +44844 ./prep_dataset/ILSVRC2012_val_00039851.bin 224 224 +44845 ./prep_dataset/ILSVRC2012_val_00049614.bin 224 224 +44846 ./prep_dataset/ILSVRC2012_val_00037047.bin 224 224 +44847 ./prep_dataset/ILSVRC2012_val_00048298.bin 224 224 +44848 ./prep_dataset/ILSVRC2012_val_00033691.bin 224 224 +44849 ./prep_dataset/ILSVRC2012_val_00013060.bin 224 224 +44850 ./prep_dataset/ILSVRC2012_val_00020880.bin 224 224 +44851 ./prep_dataset/ILSVRC2012_val_00035898.bin 224 224 +44852 ./prep_dataset/ILSVRC2012_val_00009381.bin 224 224 +44853 ./prep_dataset/ILSVRC2012_val_00023187.bin 224 224 +44854 ./prep_dataset/ILSVRC2012_val_00017620.bin 224 224 +44855 ./prep_dataset/ILSVRC2012_val_00040987.bin 224 224 +44856 ./prep_dataset/ILSVRC2012_val_00001182.bin 224 224 +44857 ./prep_dataset/ILSVRC2012_val_00020184.bin 224 224 +44858 ./prep_dataset/ILSVRC2012_val_00043665.bin 224 224 +44859 ./prep_dataset/ILSVRC2012_val_00001002.bin 224 224 +44860 ./prep_dataset/ILSVRC2012_val_00010675.bin 224 224 +44861 ./prep_dataset/ILSVRC2012_val_00027841.bin 224 224 +44862 ./prep_dataset/ILSVRC2012_val_00035587.bin 224 224 +44863 ./prep_dataset/ILSVRC2012_val_00042969.bin 224 224 +44864 ./prep_dataset/ILSVRC2012_val_00001566.bin 224 224 +44865 ./prep_dataset/ILSVRC2012_val_00047759.bin 224 224 +44866 ./prep_dataset/ILSVRC2012_val_00021301.bin 224 224 +44867 ./prep_dataset/ILSVRC2012_val_00021947.bin 224 224 +44868 ./prep_dataset/ILSVRC2012_val_00024627.bin 224 224 +44869 ./prep_dataset/ILSVRC2012_val_00031475.bin 224 224 +44870 ./prep_dataset/ILSVRC2012_val_00045707.bin 224 224 +44871 ./prep_dataset/ILSVRC2012_val_00049518.bin 224 224 +44872 ./prep_dataset/ILSVRC2012_val_00026881.bin 224 224 +44873 ./prep_dataset/ILSVRC2012_val_00032795.bin 224 224 +44874 ./prep_dataset/ILSVRC2012_val_00000991.bin 224 224 +44875 ./prep_dataset/ILSVRC2012_val_00043983.bin 224 224 +44876 ./prep_dataset/ILSVRC2012_val_00040357.bin 224 224 +44877 ./prep_dataset/ILSVRC2012_val_00042604.bin 224 224 +44878 ./prep_dataset/ILSVRC2012_val_00034039.bin 224 224 +44879 ./prep_dataset/ILSVRC2012_val_00031768.bin 224 224 +44880 ./prep_dataset/ILSVRC2012_val_00019871.bin 224 224 +44881 ./prep_dataset/ILSVRC2012_val_00031189.bin 224 224 +44882 ./prep_dataset/ILSVRC2012_val_00028172.bin 224 224 +44883 ./prep_dataset/ILSVRC2012_val_00003548.bin 224 224 +44884 ./prep_dataset/ILSVRC2012_val_00041482.bin 224 224 +44885 ./prep_dataset/ILSVRC2012_val_00026459.bin 224 224 +44886 ./prep_dataset/ILSVRC2012_val_00043328.bin 224 224 +44887 ./prep_dataset/ILSVRC2012_val_00020826.bin 224 224 +44888 ./prep_dataset/ILSVRC2012_val_00006067.bin 224 224 +44889 ./prep_dataset/ILSVRC2012_val_00043468.bin 224 224 +44890 ./prep_dataset/ILSVRC2012_val_00038252.bin 224 224 +44891 ./prep_dataset/ILSVRC2012_val_00031705.bin 224 224 +44892 ./prep_dataset/ILSVRC2012_val_00048913.bin 224 224 +44893 ./prep_dataset/ILSVRC2012_val_00017841.bin 224 224 +44894 ./prep_dataset/ILSVRC2012_val_00049478.bin 224 224 +44895 ./prep_dataset/ILSVRC2012_val_00040391.bin 224 224 +44896 ./prep_dataset/ILSVRC2012_val_00023295.bin 224 224 +44897 ./prep_dataset/ILSVRC2012_val_00035921.bin 224 224 +44898 ./prep_dataset/ILSVRC2012_val_00014105.bin 224 224 +44899 ./prep_dataset/ILSVRC2012_val_00044218.bin 224 224 +44900 ./prep_dataset/ILSVRC2012_val_00020528.bin 224 224 +44901 ./prep_dataset/ILSVRC2012_val_00006499.bin 224 224 +44902 ./prep_dataset/ILSVRC2012_val_00005196.bin 224 224 +44903 ./prep_dataset/ILSVRC2012_val_00006924.bin 224 224 +44904 ./prep_dataset/ILSVRC2012_val_00009703.bin 224 224 +44905 ./prep_dataset/ILSVRC2012_val_00031218.bin 224 224 +44906 ./prep_dataset/ILSVRC2012_val_00046436.bin 224 224 +44907 ./prep_dataset/ILSVRC2012_val_00003528.bin 224 224 +44908 ./prep_dataset/ILSVRC2012_val_00006417.bin 224 224 +44909 ./prep_dataset/ILSVRC2012_val_00003204.bin 224 224 +44910 ./prep_dataset/ILSVRC2012_val_00024809.bin 224 224 +44911 ./prep_dataset/ILSVRC2012_val_00028577.bin 224 224 +44912 ./prep_dataset/ILSVRC2012_val_00010299.bin 224 224 +44913 ./prep_dataset/ILSVRC2012_val_00021753.bin 224 224 +44914 ./prep_dataset/ILSVRC2012_val_00027825.bin 224 224 +44915 ./prep_dataset/ILSVRC2012_val_00008454.bin 224 224 +44916 ./prep_dataset/ILSVRC2012_val_00046126.bin 224 224 +44917 ./prep_dataset/ILSVRC2012_val_00014414.bin 224 224 +44918 ./prep_dataset/ILSVRC2012_val_00024369.bin 224 224 +44919 ./prep_dataset/ILSVRC2012_val_00009211.bin 224 224 +44920 ./prep_dataset/ILSVRC2012_val_00036909.bin 224 224 +44921 ./prep_dataset/ILSVRC2012_val_00039387.bin 224 224 +44922 ./prep_dataset/ILSVRC2012_val_00032324.bin 224 224 +44923 ./prep_dataset/ILSVRC2012_val_00011341.bin 224 224 +44924 ./prep_dataset/ILSVRC2012_val_00035333.bin 224 224 +44925 ./prep_dataset/ILSVRC2012_val_00012545.bin 224 224 +44926 ./prep_dataset/ILSVRC2012_val_00008843.bin 224 224 +44927 ./prep_dataset/ILSVRC2012_val_00004861.bin 224 224 +44928 ./prep_dataset/ILSVRC2012_val_00020602.bin 224 224 +44929 ./prep_dataset/ILSVRC2012_val_00047237.bin 224 224 +44930 ./prep_dataset/ILSVRC2012_val_00017539.bin 224 224 +44931 ./prep_dataset/ILSVRC2012_val_00000854.bin 224 224 +44932 ./prep_dataset/ILSVRC2012_val_00015539.bin 224 224 +44933 ./prep_dataset/ILSVRC2012_val_00014995.bin 224 224 +44934 ./prep_dataset/ILSVRC2012_val_00003744.bin 224 224 +44935 ./prep_dataset/ILSVRC2012_val_00006041.bin 224 224 +44936 ./prep_dataset/ILSVRC2012_val_00018721.bin 224 224 +44937 ./prep_dataset/ILSVRC2012_val_00008582.bin 224 224 +44938 ./prep_dataset/ILSVRC2012_val_00032168.bin 224 224 +44939 ./prep_dataset/ILSVRC2012_val_00025965.bin 224 224 +44940 ./prep_dataset/ILSVRC2012_val_00001881.bin 224 224 +44941 ./prep_dataset/ILSVRC2012_val_00020433.bin 224 224 +44942 ./prep_dataset/ILSVRC2012_val_00018813.bin 224 224 +44943 ./prep_dataset/ILSVRC2012_val_00021785.bin 224 224 +44944 ./prep_dataset/ILSVRC2012_val_00020562.bin 224 224 +44945 ./prep_dataset/ILSVRC2012_val_00004726.bin 224 224 +44946 ./prep_dataset/ILSVRC2012_val_00045256.bin 224 224 +44947 ./prep_dataset/ILSVRC2012_val_00006960.bin 224 224 +44948 ./prep_dataset/ILSVRC2012_val_00001617.bin 224 224 +44949 ./prep_dataset/ILSVRC2012_val_00043374.bin 224 224 +44950 ./prep_dataset/ILSVRC2012_val_00041052.bin 224 224 +44951 ./prep_dataset/ILSVRC2012_val_00029869.bin 224 224 +44952 ./prep_dataset/ILSVRC2012_val_00020484.bin 224 224 +44953 ./prep_dataset/ILSVRC2012_val_00007026.bin 224 224 +44954 ./prep_dataset/ILSVRC2012_val_00016608.bin 224 224 +44955 ./prep_dataset/ILSVRC2012_val_00001413.bin 224 224 +44956 ./prep_dataset/ILSVRC2012_val_00026352.bin 224 224 +44957 ./prep_dataset/ILSVRC2012_val_00016401.bin 224 224 +44958 ./prep_dataset/ILSVRC2012_val_00011417.bin 224 224 +44959 ./prep_dataset/ILSVRC2012_val_00027795.bin 224 224 +44960 ./prep_dataset/ILSVRC2012_val_00014213.bin 224 224 +44961 ./prep_dataset/ILSVRC2012_val_00032609.bin 224 224 +44962 ./prep_dataset/ILSVRC2012_val_00026815.bin 224 224 +44963 ./prep_dataset/ILSVRC2012_val_00030276.bin 224 224 +44964 ./prep_dataset/ILSVRC2012_val_00010417.bin 224 224 +44965 ./prep_dataset/ILSVRC2012_val_00002042.bin 224 224 +44966 ./prep_dataset/ILSVRC2012_val_00045618.bin 224 224 +44967 ./prep_dataset/ILSVRC2012_val_00048941.bin 224 224 +44968 ./prep_dataset/ILSVRC2012_val_00042064.bin 224 224 +44969 ./prep_dataset/ILSVRC2012_val_00003328.bin 224 224 +44970 ./prep_dataset/ILSVRC2012_val_00035754.bin 224 224 +44971 ./prep_dataset/ILSVRC2012_val_00049520.bin 224 224 +44972 ./prep_dataset/ILSVRC2012_val_00030145.bin 224 224 +44973 ./prep_dataset/ILSVRC2012_val_00027517.bin 224 224 +44974 ./prep_dataset/ILSVRC2012_val_00021939.bin 224 224 +44975 ./prep_dataset/ILSVRC2012_val_00030622.bin 224 224 +44976 ./prep_dataset/ILSVRC2012_val_00026977.bin 224 224 +44977 ./prep_dataset/ILSVRC2012_val_00009377.bin 224 224 +44978 ./prep_dataset/ILSVRC2012_val_00045507.bin 224 224 +44979 ./prep_dataset/ILSVRC2012_val_00003313.bin 224 224 +44980 ./prep_dataset/ILSVRC2012_val_00021548.bin 224 224 +44981 ./prep_dataset/ILSVRC2012_val_00044470.bin 224 224 +44982 ./prep_dataset/ILSVRC2012_val_00019352.bin 224 224 +44983 ./prep_dataset/ILSVRC2012_val_00044731.bin 224 224 +44984 ./prep_dataset/ILSVRC2012_val_00046787.bin 224 224 +44985 ./prep_dataset/ILSVRC2012_val_00036917.bin 224 224 +44986 ./prep_dataset/ILSVRC2012_val_00029067.bin 224 224 +44987 ./prep_dataset/ILSVRC2012_val_00042357.bin 224 224 +44988 ./prep_dataset/ILSVRC2012_val_00014334.bin 224 224 +44989 ./prep_dataset/ILSVRC2012_val_00016240.bin 224 224 +44990 ./prep_dataset/ILSVRC2012_val_00023339.bin 224 224 +44991 ./prep_dataset/ILSVRC2012_val_00015401.bin 224 224 +44992 ./prep_dataset/ILSVRC2012_val_00034210.bin 224 224 +44993 ./prep_dataset/ILSVRC2012_val_00005123.bin 224 224 +44994 ./prep_dataset/ILSVRC2012_val_00009077.bin 224 224 +44995 ./prep_dataset/ILSVRC2012_val_00019576.bin 224 224 +44996 ./prep_dataset/ILSVRC2012_val_00020702.bin 224 224 +44997 ./prep_dataset/ILSVRC2012_val_00033555.bin 224 224 +44998 ./prep_dataset/ILSVRC2012_val_00023067.bin 224 224 +44999 ./prep_dataset/ILSVRC2012_val_00009272.bin 224 224 +45000 ./prep_dataset/ILSVRC2012_val_00002114.bin 224 224 +45001 ./prep_dataset/ILSVRC2012_val_00029379.bin 224 224 +45002 ./prep_dataset/ILSVRC2012_val_00028170.bin 224 224 +45003 ./prep_dataset/ILSVRC2012_val_00047272.bin 224 224 +45004 ./prep_dataset/ILSVRC2012_val_00019229.bin 224 224 +45005 ./prep_dataset/ILSVRC2012_val_00010934.bin 224 224 +45006 ./prep_dataset/ILSVRC2012_val_00029557.bin 224 224 +45007 ./prep_dataset/ILSVRC2012_val_00030770.bin 224 224 +45008 ./prep_dataset/ILSVRC2012_val_00005591.bin 224 224 +45009 ./prep_dataset/ILSVRC2012_val_00044936.bin 224 224 +45010 ./prep_dataset/ILSVRC2012_val_00033484.bin 224 224 +45011 ./prep_dataset/ILSVRC2012_val_00016660.bin 224 224 +45012 ./prep_dataset/ILSVRC2012_val_00005967.bin 224 224 +45013 ./prep_dataset/ILSVRC2012_val_00003362.bin 224 224 +45014 ./prep_dataset/ILSVRC2012_val_00011836.bin 224 224 +45015 ./prep_dataset/ILSVRC2012_val_00046554.bin 224 224 +45016 ./prep_dataset/ILSVRC2012_val_00001944.bin 224 224 +45017 ./prep_dataset/ILSVRC2012_val_00016507.bin 224 224 +45018 ./prep_dataset/ILSVRC2012_val_00044636.bin 224 224 +45019 ./prep_dataset/ILSVRC2012_val_00012698.bin 224 224 +45020 ./prep_dataset/ILSVRC2012_val_00013723.bin 224 224 +45021 ./prep_dataset/ILSVRC2012_val_00003710.bin 224 224 +45022 ./prep_dataset/ILSVRC2012_val_00036543.bin 224 224 +45023 ./prep_dataset/ILSVRC2012_val_00042020.bin 224 224 +45024 ./prep_dataset/ILSVRC2012_val_00031444.bin 224 224 +45025 ./prep_dataset/ILSVRC2012_val_00021937.bin 224 224 +45026 ./prep_dataset/ILSVRC2012_val_00005802.bin 224 224 +45027 ./prep_dataset/ILSVRC2012_val_00043934.bin 224 224 +45028 ./prep_dataset/ILSVRC2012_val_00038269.bin 224 224 +45029 ./prep_dataset/ILSVRC2012_val_00046529.bin 224 224 +45030 ./prep_dataset/ILSVRC2012_val_00034213.bin 224 224 +45031 ./prep_dataset/ILSVRC2012_val_00047253.bin 224 224 +45032 ./prep_dataset/ILSVRC2012_val_00011381.bin 224 224 +45033 ./prep_dataset/ILSVRC2012_val_00020200.bin 224 224 +45034 ./prep_dataset/ILSVRC2012_val_00005626.bin 224 224 +45035 ./prep_dataset/ILSVRC2012_val_00031401.bin 224 224 +45036 ./prep_dataset/ILSVRC2012_val_00021868.bin 224 224 +45037 ./prep_dataset/ILSVRC2012_val_00014941.bin 224 224 +45038 ./prep_dataset/ILSVRC2012_val_00030708.bin 224 224 +45039 ./prep_dataset/ILSVRC2012_val_00040384.bin 224 224 +45040 ./prep_dataset/ILSVRC2012_val_00027020.bin 224 224 +45041 ./prep_dataset/ILSVRC2012_val_00014203.bin 224 224 +45042 ./prep_dataset/ILSVRC2012_val_00043317.bin 224 224 +45043 ./prep_dataset/ILSVRC2012_val_00037061.bin 224 224 +45044 ./prep_dataset/ILSVRC2012_val_00014760.bin 224 224 +45045 ./prep_dataset/ILSVRC2012_val_00026207.bin 224 224 +45046 ./prep_dataset/ILSVRC2012_val_00004201.bin 224 224 +45047 ./prep_dataset/ILSVRC2012_val_00040405.bin 224 224 +45048 ./prep_dataset/ILSVRC2012_val_00015395.bin 224 224 +45049 ./prep_dataset/ILSVRC2012_val_00031105.bin 224 224 +45050 ./prep_dataset/ILSVRC2012_val_00010529.bin 224 224 +45051 ./prep_dataset/ILSVRC2012_val_00046117.bin 224 224 +45052 ./prep_dataset/ILSVRC2012_val_00007456.bin 224 224 +45053 ./prep_dataset/ILSVRC2012_val_00023985.bin 224 224 +45054 ./prep_dataset/ILSVRC2012_val_00026498.bin 224 224 +45055 ./prep_dataset/ILSVRC2012_val_00040432.bin 224 224 +45056 ./prep_dataset/ILSVRC2012_val_00035688.bin 224 224 +45057 ./prep_dataset/ILSVRC2012_val_00013375.bin 224 224 +45058 ./prep_dataset/ILSVRC2012_val_00043808.bin 224 224 +45059 ./prep_dataset/ILSVRC2012_val_00046565.bin 224 224 +45060 ./prep_dataset/ILSVRC2012_val_00000221.bin 224 224 +45061 ./prep_dataset/ILSVRC2012_val_00025161.bin 224 224 +45062 ./prep_dataset/ILSVRC2012_val_00005168.bin 224 224 +45063 ./prep_dataset/ILSVRC2012_val_00046456.bin 224 224 +45064 ./prep_dataset/ILSVRC2012_val_00043148.bin 224 224 +45065 ./prep_dataset/ILSVRC2012_val_00022990.bin 224 224 +45066 ./prep_dataset/ILSVRC2012_val_00027408.bin 224 224 +45067 ./prep_dataset/ILSVRC2012_val_00001152.bin 224 224 +45068 ./prep_dataset/ILSVRC2012_val_00030906.bin 224 224 +45069 ./prep_dataset/ILSVRC2012_val_00023537.bin 224 224 +45070 ./prep_dataset/ILSVRC2012_val_00000267.bin 224 224 +45071 ./prep_dataset/ILSVRC2012_val_00049176.bin 224 224 +45072 ./prep_dataset/ILSVRC2012_val_00034533.bin 224 224 +45073 ./prep_dataset/ILSVRC2012_val_00020947.bin 224 224 +45074 ./prep_dataset/ILSVRC2012_val_00005988.bin 224 224 +45075 ./prep_dataset/ILSVRC2012_val_00045046.bin 224 224 +45076 ./prep_dataset/ILSVRC2012_val_00034312.bin 224 224 +45077 ./prep_dataset/ILSVRC2012_val_00008068.bin 224 224 +45078 ./prep_dataset/ILSVRC2012_val_00011913.bin 224 224 +45079 ./prep_dataset/ILSVRC2012_val_00043880.bin 224 224 +45080 ./prep_dataset/ILSVRC2012_val_00039692.bin 224 224 +45081 ./prep_dataset/ILSVRC2012_val_00016566.bin 224 224 +45082 ./prep_dataset/ILSVRC2012_val_00031053.bin 224 224 +45083 ./prep_dataset/ILSVRC2012_val_00021723.bin 224 224 +45084 ./prep_dataset/ILSVRC2012_val_00030219.bin 224 224 +45085 ./prep_dataset/ILSVRC2012_val_00024635.bin 224 224 +45086 ./prep_dataset/ILSVRC2012_val_00028944.bin 224 224 +45087 ./prep_dataset/ILSVRC2012_val_00004639.bin 224 224 +45088 ./prep_dataset/ILSVRC2012_val_00013650.bin 224 224 +45089 ./prep_dataset/ILSVRC2012_val_00039605.bin 224 224 +45090 ./prep_dataset/ILSVRC2012_val_00042863.bin 224 224 +45091 ./prep_dataset/ILSVRC2012_val_00031872.bin 224 224 +45092 ./prep_dataset/ILSVRC2012_val_00001590.bin 224 224 +45093 ./prep_dataset/ILSVRC2012_val_00031307.bin 224 224 +45094 ./prep_dataset/ILSVRC2012_val_00044350.bin 224 224 +45095 ./prep_dataset/ILSVRC2012_val_00018837.bin 224 224 +45096 ./prep_dataset/ILSVRC2012_val_00042823.bin 224 224 +45097 ./prep_dataset/ILSVRC2012_val_00024896.bin 224 224 +45098 ./prep_dataset/ILSVRC2012_val_00023390.bin 224 224 +45099 ./prep_dataset/ILSVRC2012_val_00024744.bin 224 224 +45100 ./prep_dataset/ILSVRC2012_val_00027849.bin 224 224 +45101 ./prep_dataset/ILSVRC2012_val_00003117.bin 224 224 +45102 ./prep_dataset/ILSVRC2012_val_00018984.bin 224 224 +45103 ./prep_dataset/ILSVRC2012_val_00035176.bin 224 224 +45104 ./prep_dataset/ILSVRC2012_val_00008222.bin 224 224 +45105 ./prep_dataset/ILSVRC2012_val_00043896.bin 224 224 +45106 ./prep_dataset/ILSVRC2012_val_00020849.bin 224 224 +45107 ./prep_dataset/ILSVRC2012_val_00002531.bin 224 224 +45108 ./prep_dataset/ILSVRC2012_val_00014286.bin 224 224 +45109 ./prep_dataset/ILSVRC2012_val_00019650.bin 224 224 +45110 ./prep_dataset/ILSVRC2012_val_00041592.bin 224 224 +45111 ./prep_dataset/ILSVRC2012_val_00028838.bin 224 224 +45112 ./prep_dataset/ILSVRC2012_val_00011388.bin 224 224 +45113 ./prep_dataset/ILSVRC2012_val_00034798.bin 224 224 +45114 ./prep_dataset/ILSVRC2012_val_00003183.bin 224 224 +45115 ./prep_dataset/ILSVRC2012_val_00021778.bin 224 224 +45116 ./prep_dataset/ILSVRC2012_val_00000482.bin 224 224 +45117 ./prep_dataset/ILSVRC2012_val_00020893.bin 224 224 +45118 ./prep_dataset/ILSVRC2012_val_00036578.bin 224 224 +45119 ./prep_dataset/ILSVRC2012_val_00003435.bin 224 224 +45120 ./prep_dataset/ILSVRC2012_val_00028700.bin 224 224 +45121 ./prep_dataset/ILSVRC2012_val_00009453.bin 224 224 +45122 ./prep_dataset/ILSVRC2012_val_00007097.bin 224 224 +45123 ./prep_dataset/ILSVRC2012_val_00031728.bin 224 224 +45124 ./prep_dataset/ILSVRC2012_val_00012924.bin 224 224 +45125 ./prep_dataset/ILSVRC2012_val_00031217.bin 224 224 +45126 ./prep_dataset/ILSVRC2012_val_00010939.bin 224 224 +45127 ./prep_dataset/ILSVRC2012_val_00010206.bin 224 224 +45128 ./prep_dataset/ILSVRC2012_val_00011475.bin 224 224 +45129 ./prep_dataset/ILSVRC2012_val_00014707.bin 224 224 +45130 ./prep_dataset/ILSVRC2012_val_00031499.bin 224 224 +45131 ./prep_dataset/ILSVRC2012_val_00029038.bin 224 224 +45132 ./prep_dataset/ILSVRC2012_val_00026827.bin 224 224 +45133 ./prep_dataset/ILSVRC2012_val_00021979.bin 224 224 +45134 ./prep_dataset/ILSVRC2012_val_00046718.bin 224 224 +45135 ./prep_dataset/ILSVRC2012_val_00025268.bin 224 224 +45136 ./prep_dataset/ILSVRC2012_val_00030782.bin 224 224 +45137 ./prep_dataset/ILSVRC2012_val_00008128.bin 224 224 +45138 ./prep_dataset/ILSVRC2012_val_00047435.bin 224 224 +45139 ./prep_dataset/ILSVRC2012_val_00036326.bin 224 224 +45140 ./prep_dataset/ILSVRC2012_val_00001079.bin 224 224 +45141 ./prep_dataset/ILSVRC2012_val_00043591.bin 224 224 +45142 ./prep_dataset/ILSVRC2012_val_00007553.bin 224 224 +45143 ./prep_dataset/ILSVRC2012_val_00032073.bin 224 224 +45144 ./prep_dataset/ILSVRC2012_val_00016245.bin 224 224 +45145 ./prep_dataset/ILSVRC2012_val_00005958.bin 224 224 +45146 ./prep_dataset/ILSVRC2012_val_00016698.bin 224 224 +45147 ./prep_dataset/ILSVRC2012_val_00018299.bin 224 224 +45148 ./prep_dataset/ILSVRC2012_val_00018709.bin 224 224 +45149 ./prep_dataset/ILSVRC2012_val_00005532.bin 224 224 +45150 ./prep_dataset/ILSVRC2012_val_00010851.bin 224 224 +45151 ./prep_dataset/ILSVRC2012_val_00018669.bin 224 224 +45152 ./prep_dataset/ILSVRC2012_val_00033740.bin 224 224 +45153 ./prep_dataset/ILSVRC2012_val_00009631.bin 224 224 +45154 ./prep_dataset/ILSVRC2012_val_00004307.bin 224 224 +45155 ./prep_dataset/ILSVRC2012_val_00013127.bin 224 224 +45156 ./prep_dataset/ILSVRC2012_val_00003453.bin 224 224 +45157 ./prep_dataset/ILSVRC2012_val_00013679.bin 224 224 +45158 ./prep_dataset/ILSVRC2012_val_00012981.bin 224 224 +45159 ./prep_dataset/ILSVRC2012_val_00043410.bin 224 224 +45160 ./prep_dataset/ILSVRC2012_val_00007627.bin 224 224 +45161 ./prep_dataset/ILSVRC2012_val_00034853.bin 224 224 +45162 ./prep_dataset/ILSVRC2012_val_00007014.bin 224 224 +45163 ./prep_dataset/ILSVRC2012_val_00030966.bin 224 224 +45164 ./prep_dataset/ILSVRC2012_val_00044838.bin 224 224 +45165 ./prep_dataset/ILSVRC2012_val_00009157.bin 224 224 +45166 ./prep_dataset/ILSVRC2012_val_00017672.bin 224 224 +45167 ./prep_dataset/ILSVRC2012_val_00037345.bin 224 224 +45168 ./prep_dataset/ILSVRC2012_val_00032402.bin 224 224 +45169 ./prep_dataset/ILSVRC2012_val_00047445.bin 224 224 +45170 ./prep_dataset/ILSVRC2012_val_00026691.bin 224 224 +45171 ./prep_dataset/ILSVRC2012_val_00003822.bin 224 224 +45172 ./prep_dataset/ILSVRC2012_val_00046534.bin 224 224 +45173 ./prep_dataset/ILSVRC2012_val_00013425.bin 224 224 +45174 ./prep_dataset/ILSVRC2012_val_00006691.bin 224 224 +45175 ./prep_dataset/ILSVRC2012_val_00007478.bin 224 224 +45176 ./prep_dataset/ILSVRC2012_val_00012631.bin 224 224 +45177 ./prep_dataset/ILSVRC2012_val_00016778.bin 224 224 +45178 ./prep_dataset/ILSVRC2012_val_00016625.bin 224 224 +45179 ./prep_dataset/ILSVRC2012_val_00025173.bin 224 224 +45180 ./prep_dataset/ILSVRC2012_val_00040290.bin 224 224 +45181 ./prep_dataset/ILSVRC2012_val_00012082.bin 224 224 +45182 ./prep_dataset/ILSVRC2012_val_00024524.bin 224 224 +45183 ./prep_dataset/ILSVRC2012_val_00041678.bin 224 224 +45184 ./prep_dataset/ILSVRC2012_val_00047927.bin 224 224 +45185 ./prep_dataset/ILSVRC2012_val_00022157.bin 224 224 +45186 ./prep_dataset/ILSVRC2012_val_00012691.bin 224 224 +45187 ./prep_dataset/ILSVRC2012_val_00024231.bin 224 224 +45188 ./prep_dataset/ILSVRC2012_val_00002854.bin 224 224 +45189 ./prep_dataset/ILSVRC2012_val_00001705.bin 224 224 +45190 ./prep_dataset/ILSVRC2012_val_00021474.bin 224 224 +45191 ./prep_dataset/ILSVRC2012_val_00020894.bin 224 224 +45192 ./prep_dataset/ILSVRC2012_val_00009600.bin 224 224 +45193 ./prep_dataset/ILSVRC2012_val_00043858.bin 224 224 +45194 ./prep_dataset/ILSVRC2012_val_00031198.bin 224 224 +45195 ./prep_dataset/ILSVRC2012_val_00009894.bin 224 224 +45196 ./prep_dataset/ILSVRC2012_val_00026801.bin 224 224 +45197 ./prep_dataset/ILSVRC2012_val_00007708.bin 224 224 +45198 ./prep_dataset/ILSVRC2012_val_00007692.bin 224 224 +45199 ./prep_dataset/ILSVRC2012_val_00032240.bin 224 224 +45200 ./prep_dataset/ILSVRC2012_val_00013252.bin 224 224 +45201 ./prep_dataset/ILSVRC2012_val_00006258.bin 224 224 +45202 ./prep_dataset/ILSVRC2012_val_00023252.bin 224 224 +45203 ./prep_dataset/ILSVRC2012_val_00003858.bin 224 224 +45204 ./prep_dataset/ILSVRC2012_val_00045221.bin 224 224 +45205 ./prep_dataset/ILSVRC2012_val_00009690.bin 224 224 +45206 ./prep_dataset/ILSVRC2012_val_00042034.bin 224 224 +45207 ./prep_dataset/ILSVRC2012_val_00025962.bin 224 224 +45208 ./prep_dataset/ILSVRC2012_val_00043516.bin 224 224 +45209 ./prep_dataset/ILSVRC2012_val_00044060.bin 224 224 +45210 ./prep_dataset/ILSVRC2012_val_00042967.bin 224 224 +45211 ./prep_dataset/ILSVRC2012_val_00034204.bin 224 224 +45212 ./prep_dataset/ILSVRC2012_val_00005200.bin 224 224 +45213 ./prep_dataset/ILSVRC2012_val_00031525.bin 224 224 +45214 ./prep_dataset/ILSVRC2012_val_00014116.bin 224 224 +45215 ./prep_dataset/ILSVRC2012_val_00046096.bin 224 224 +45216 ./prep_dataset/ILSVRC2012_val_00033507.bin 224 224 +45217 ./prep_dataset/ILSVRC2012_val_00042772.bin 224 224 +45218 ./prep_dataset/ILSVRC2012_val_00036741.bin 224 224 +45219 ./prep_dataset/ILSVRC2012_val_00009950.bin 224 224 +45220 ./prep_dataset/ILSVRC2012_val_00020529.bin 224 224 +45221 ./prep_dataset/ILSVRC2012_val_00026052.bin 224 224 +45222 ./prep_dataset/ILSVRC2012_val_00014244.bin 224 224 +45223 ./prep_dataset/ILSVRC2012_val_00040373.bin 224 224 +45224 ./prep_dataset/ILSVRC2012_val_00014565.bin 224 224 +45225 ./prep_dataset/ILSVRC2012_val_00009827.bin 224 224 +45226 ./prep_dataset/ILSVRC2012_val_00045548.bin 224 224 +45227 ./prep_dataset/ILSVRC2012_val_00037342.bin 224 224 +45228 ./prep_dataset/ILSVRC2012_val_00015536.bin 224 224 +45229 ./prep_dataset/ILSVRC2012_val_00023975.bin 224 224 +45230 ./prep_dataset/ILSVRC2012_val_00011818.bin 224 224 +45231 ./prep_dataset/ILSVRC2012_val_00024932.bin 224 224 +45232 ./prep_dataset/ILSVRC2012_val_00013950.bin 224 224 +45233 ./prep_dataset/ILSVRC2012_val_00020985.bin 224 224 +45234 ./prep_dataset/ILSVRC2012_val_00037897.bin 224 224 +45235 ./prep_dataset/ILSVRC2012_val_00028516.bin 224 224 +45236 ./prep_dataset/ILSVRC2012_val_00049737.bin 224 224 +45237 ./prep_dataset/ILSVRC2012_val_00012728.bin 224 224 +45238 ./prep_dataset/ILSVRC2012_val_00031951.bin 224 224 +45239 ./prep_dataset/ILSVRC2012_val_00003065.bin 224 224 +45240 ./prep_dataset/ILSVRC2012_val_00046105.bin 224 224 +45241 ./prep_dataset/ILSVRC2012_val_00023019.bin 224 224 +45242 ./prep_dataset/ILSVRC2012_val_00002965.bin 224 224 +45243 ./prep_dataset/ILSVRC2012_val_00030221.bin 224 224 +45244 ./prep_dataset/ILSVRC2012_val_00021616.bin 224 224 +45245 ./prep_dataset/ILSVRC2012_val_00011774.bin 224 224 +45246 ./prep_dataset/ILSVRC2012_val_00045840.bin 224 224 +45247 ./prep_dataset/ILSVRC2012_val_00040736.bin 224 224 +45248 ./prep_dataset/ILSVRC2012_val_00001184.bin 224 224 +45249 ./prep_dataset/ILSVRC2012_val_00002449.bin 224 224 +45250 ./prep_dataset/ILSVRC2012_val_00035299.bin 224 224 +45251 ./prep_dataset/ILSVRC2012_val_00016198.bin 224 224 +45252 ./prep_dataset/ILSVRC2012_val_00041585.bin 224 224 +45253 ./prep_dataset/ILSVRC2012_val_00023158.bin 224 224 +45254 ./prep_dataset/ILSVRC2012_val_00036042.bin 224 224 +45255 ./prep_dataset/ILSVRC2012_val_00011071.bin 224 224 +45256 ./prep_dataset/ILSVRC2012_val_00002557.bin 224 224 +45257 ./prep_dataset/ILSVRC2012_val_00045673.bin 224 224 +45258 ./prep_dataset/ILSVRC2012_val_00004052.bin 224 224 +45259 ./prep_dataset/ILSVRC2012_val_00043672.bin 224 224 +45260 ./prep_dataset/ILSVRC2012_val_00045449.bin 224 224 +45261 ./prep_dataset/ILSVRC2012_val_00025404.bin 224 224 +45262 ./prep_dataset/ILSVRC2012_val_00024021.bin 224 224 +45263 ./prep_dataset/ILSVRC2012_val_00018050.bin 224 224 +45264 ./prep_dataset/ILSVRC2012_val_00012112.bin 224 224 +45265 ./prep_dataset/ILSVRC2012_val_00010542.bin 224 224 +45266 ./prep_dataset/ILSVRC2012_val_00049555.bin 224 224 +45267 ./prep_dataset/ILSVRC2012_val_00017527.bin 224 224 +45268 ./prep_dataset/ILSVRC2012_val_00006189.bin 224 224 +45269 ./prep_dataset/ILSVRC2012_val_00011556.bin 224 224 +45270 ./prep_dataset/ILSVRC2012_val_00049206.bin 224 224 +45271 ./prep_dataset/ILSVRC2012_val_00046085.bin 224 224 +45272 ./prep_dataset/ILSVRC2012_val_00042051.bin 224 224 +45273 ./prep_dataset/ILSVRC2012_val_00014117.bin 224 224 +45274 ./prep_dataset/ILSVRC2012_val_00042980.bin 224 224 +45275 ./prep_dataset/ILSVRC2012_val_00023417.bin 224 224 +45276 ./prep_dataset/ILSVRC2012_val_00042678.bin 224 224 +45277 ./prep_dataset/ILSVRC2012_val_00040506.bin 224 224 +45278 ./prep_dataset/ILSVRC2012_val_00010801.bin 224 224 +45279 ./prep_dataset/ILSVRC2012_val_00022078.bin 224 224 +45280 ./prep_dataset/ILSVRC2012_val_00002937.bin 224 224 +45281 ./prep_dataset/ILSVRC2012_val_00023993.bin 224 224 +45282 ./prep_dataset/ILSVRC2012_val_00043962.bin 224 224 +45283 ./prep_dataset/ILSVRC2012_val_00020801.bin 224 224 +45284 ./prep_dataset/ILSVRC2012_val_00008405.bin 224 224 +45285 ./prep_dataset/ILSVRC2012_val_00006731.bin 224 224 +45286 ./prep_dataset/ILSVRC2012_val_00041383.bin 224 224 +45287 ./prep_dataset/ILSVRC2012_val_00013852.bin 224 224 +45288 ./prep_dataset/ILSVRC2012_val_00040072.bin 224 224 +45289 ./prep_dataset/ILSVRC2012_val_00008003.bin 224 224 +45290 ./prep_dataset/ILSVRC2012_val_00045037.bin 224 224 +45291 ./prep_dataset/ILSVRC2012_val_00038985.bin 224 224 +45292 ./prep_dataset/ILSVRC2012_val_00015208.bin 224 224 +45293 ./prep_dataset/ILSVRC2012_val_00039310.bin 224 224 +45294 ./prep_dataset/ILSVRC2012_val_00002941.bin 224 224 +45295 ./prep_dataset/ILSVRC2012_val_00002880.bin 224 224 +45296 ./prep_dataset/ILSVRC2012_val_00004565.bin 224 224 +45297 ./prep_dataset/ILSVRC2012_val_00039389.bin 224 224 +45298 ./prep_dataset/ILSVRC2012_val_00021760.bin 224 224 +45299 ./prep_dataset/ILSVRC2012_val_00004865.bin 224 224 +45300 ./prep_dataset/ILSVRC2012_val_00023881.bin 224 224 +45301 ./prep_dataset/ILSVRC2012_val_00027685.bin 224 224 +45302 ./prep_dataset/ILSVRC2012_val_00001003.bin 224 224 +45303 ./prep_dataset/ILSVRC2012_val_00010467.bin 224 224 +45304 ./prep_dataset/ILSVRC2012_val_00026173.bin 224 224 +45305 ./prep_dataset/ILSVRC2012_val_00038224.bin 224 224 +45306 ./prep_dataset/ILSVRC2012_val_00032158.bin 224 224 +45307 ./prep_dataset/ILSVRC2012_val_00023838.bin 224 224 +45308 ./prep_dataset/ILSVRC2012_val_00024671.bin 224 224 +45309 ./prep_dataset/ILSVRC2012_val_00024000.bin 224 224 +45310 ./prep_dataset/ILSVRC2012_val_00017767.bin 224 224 +45311 ./prep_dataset/ILSVRC2012_val_00040031.bin 224 224 +45312 ./prep_dataset/ILSVRC2012_val_00019707.bin 224 224 +45313 ./prep_dataset/ILSVRC2012_val_00049260.bin 224 224 +45314 ./prep_dataset/ILSVRC2012_val_00041211.bin 224 224 +45315 ./prep_dataset/ILSVRC2012_val_00028121.bin 224 224 +45316 ./prep_dataset/ILSVRC2012_val_00047551.bin 224 224 +45317 ./prep_dataset/ILSVRC2012_val_00040416.bin 224 224 +45318 ./prep_dataset/ILSVRC2012_val_00043298.bin 224 224 +45319 ./prep_dataset/ILSVRC2012_val_00030930.bin 224 224 +45320 ./prep_dataset/ILSVRC2012_val_00025878.bin 224 224 +45321 ./prep_dataset/ILSVRC2012_val_00049249.bin 224 224 +45322 ./prep_dataset/ILSVRC2012_val_00027971.bin 224 224 +45323 ./prep_dataset/ILSVRC2012_val_00033690.bin 224 224 +45324 ./prep_dataset/ILSVRC2012_val_00026182.bin 224 224 +45325 ./prep_dataset/ILSVRC2012_val_00021540.bin 224 224 +45326 ./prep_dataset/ILSVRC2012_val_00040499.bin 224 224 +45327 ./prep_dataset/ILSVRC2012_val_00044650.bin 224 224 +45328 ./prep_dataset/ILSVRC2012_val_00003024.bin 224 224 +45329 ./prep_dataset/ILSVRC2012_val_00000074.bin 224 224 +45330 ./prep_dataset/ILSVRC2012_val_00036228.bin 224 224 +45331 ./prep_dataset/ILSVRC2012_val_00047280.bin 224 224 +45332 ./prep_dataset/ILSVRC2012_val_00017857.bin 224 224 +45333 ./prep_dataset/ILSVRC2012_val_00016676.bin 224 224 +45334 ./prep_dataset/ILSVRC2012_val_00026742.bin 224 224 +45335 ./prep_dataset/ILSVRC2012_val_00020079.bin 224 224 +45336 ./prep_dataset/ILSVRC2012_val_00013617.bin 224 224 +45337 ./prep_dataset/ILSVRC2012_val_00042911.bin 224 224 +45338 ./prep_dataset/ILSVRC2012_val_00049034.bin 224 224 +45339 ./prep_dataset/ILSVRC2012_val_00045230.bin 224 224 +45340 ./prep_dataset/ILSVRC2012_val_00018354.bin 224 224 +45341 ./prep_dataset/ILSVRC2012_val_00020129.bin 224 224 +45342 ./prep_dataset/ILSVRC2012_val_00025475.bin 224 224 +45343 ./prep_dataset/ILSVRC2012_val_00046667.bin 224 224 +45344 ./prep_dataset/ILSVRC2012_val_00000586.bin 224 224 +45345 ./prep_dataset/ILSVRC2012_val_00045953.bin 224 224 +45346 ./prep_dataset/ILSVRC2012_val_00023049.bin 224 224 +45347 ./prep_dataset/ILSVRC2012_val_00031264.bin 224 224 +45348 ./prep_dataset/ILSVRC2012_val_00011045.bin 224 224 +45349 ./prep_dataset/ILSVRC2012_val_00003092.bin 224 224 +45350 ./prep_dataset/ILSVRC2012_val_00027417.bin 224 224 +45351 ./prep_dataset/ILSVRC2012_val_00037013.bin 224 224 +45352 ./prep_dataset/ILSVRC2012_val_00022338.bin 224 224 +45353 ./prep_dataset/ILSVRC2012_val_00025111.bin 224 224 +45354 ./prep_dataset/ILSVRC2012_val_00028856.bin 224 224 +45355 ./prep_dataset/ILSVRC2012_val_00015183.bin 224 224 +45356 ./prep_dataset/ILSVRC2012_val_00017981.bin 224 224 +45357 ./prep_dataset/ILSVRC2012_val_00047781.bin 224 224 +45358 ./prep_dataset/ILSVRC2012_val_00032369.bin 224 224 +45359 ./prep_dataset/ILSVRC2012_val_00030740.bin 224 224 +45360 ./prep_dataset/ILSVRC2012_val_00005122.bin 224 224 +45361 ./prep_dataset/ILSVRC2012_val_00022341.bin 224 224 +45362 ./prep_dataset/ILSVRC2012_val_00036496.bin 224 224 +45363 ./prep_dataset/ILSVRC2012_val_00021162.bin 224 224 +45364 ./prep_dataset/ILSVRC2012_val_00027843.bin 224 224 +45365 ./prep_dataset/ILSVRC2012_val_00001546.bin 224 224 +45366 ./prep_dataset/ILSVRC2012_val_00003735.bin 224 224 +45367 ./prep_dataset/ILSVRC2012_val_00035027.bin 224 224 +45368 ./prep_dataset/ILSVRC2012_val_00018780.bin 224 224 +45369 ./prep_dataset/ILSVRC2012_val_00041001.bin 224 224 +45370 ./prep_dataset/ILSVRC2012_val_00039829.bin 224 224 +45371 ./prep_dataset/ILSVRC2012_val_00001607.bin 224 224 +45372 ./prep_dataset/ILSVRC2012_val_00002297.bin 224 224 +45373 ./prep_dataset/ILSVRC2012_val_00019155.bin 224 224 +45374 ./prep_dataset/ILSVRC2012_val_00047527.bin 224 224 +45375 ./prep_dataset/ILSVRC2012_val_00038566.bin 224 224 +45376 ./prep_dataset/ILSVRC2012_val_00000815.bin 224 224 +45377 ./prep_dataset/ILSVRC2012_val_00048243.bin 224 224 +45378 ./prep_dataset/ILSVRC2012_val_00038254.bin 224 224 +45379 ./prep_dataset/ILSVRC2012_val_00032811.bin 224 224 +45380 ./prep_dataset/ILSVRC2012_val_00038248.bin 224 224 +45381 ./prep_dataset/ILSVRC2012_val_00028462.bin 224 224 +45382 ./prep_dataset/ILSVRC2012_val_00045761.bin 224 224 +45383 ./prep_dataset/ILSVRC2012_val_00004199.bin 224 224 +45384 ./prep_dataset/ILSVRC2012_val_00045005.bin 224 224 +45385 ./prep_dataset/ILSVRC2012_val_00007753.bin 224 224 +45386 ./prep_dataset/ILSVRC2012_val_00039809.bin 224 224 +45387 ./prep_dataset/ILSVRC2012_val_00013791.bin 224 224 +45388 ./prep_dataset/ILSVRC2012_val_00015394.bin 224 224 +45389 ./prep_dataset/ILSVRC2012_val_00031458.bin 224 224 +45390 ./prep_dataset/ILSVRC2012_val_00012683.bin 224 224 +45391 ./prep_dataset/ILSVRC2012_val_00029938.bin 224 224 +45392 ./prep_dataset/ILSVRC2012_val_00025661.bin 224 224 +45393 ./prep_dataset/ILSVRC2012_val_00040811.bin 224 224 +45394 ./prep_dataset/ILSVRC2012_val_00030917.bin 224 224 +45395 ./prep_dataset/ILSVRC2012_val_00011313.bin 224 224 +45396 ./prep_dataset/ILSVRC2012_val_00043607.bin 224 224 +45397 ./prep_dataset/ILSVRC2012_val_00046262.bin 224 224 +45398 ./prep_dataset/ILSVRC2012_val_00008628.bin 224 224 +45399 ./prep_dataset/ILSVRC2012_val_00039849.bin 224 224 +45400 ./prep_dataset/ILSVRC2012_val_00030281.bin 224 224 +45401 ./prep_dataset/ILSVRC2012_val_00013457.bin 224 224 +45402 ./prep_dataset/ILSVRC2012_val_00035976.bin 224 224 +45403 ./prep_dataset/ILSVRC2012_val_00009444.bin 224 224 +45404 ./prep_dataset/ILSVRC2012_val_00001745.bin 224 224 +45405 ./prep_dataset/ILSVRC2012_val_00021122.bin 224 224 +45406 ./prep_dataset/ILSVRC2012_val_00026504.bin 224 224 +45407 ./prep_dataset/ILSVRC2012_val_00012055.bin 224 224 +45408 ./prep_dataset/ILSVRC2012_val_00025828.bin 224 224 +45409 ./prep_dataset/ILSVRC2012_val_00003115.bin 224 224 +45410 ./prep_dataset/ILSVRC2012_val_00010095.bin 224 224 +45411 ./prep_dataset/ILSVRC2012_val_00037019.bin 224 224 +45412 ./prep_dataset/ILSVRC2012_val_00036266.bin 224 224 +45413 ./prep_dataset/ILSVRC2012_val_00037942.bin 224 224 +45414 ./prep_dataset/ILSVRC2012_val_00010627.bin 224 224 +45415 ./prep_dataset/ILSVRC2012_val_00020130.bin 224 224 +45416 ./prep_dataset/ILSVRC2012_val_00035456.bin 224 224 +45417 ./prep_dataset/ILSVRC2012_val_00032591.bin 224 224 +45418 ./prep_dataset/ILSVRC2012_val_00026086.bin 224 224 +45419 ./prep_dataset/ILSVRC2012_val_00044604.bin 224 224 +45420 ./prep_dataset/ILSVRC2012_val_00025582.bin 224 224 +45421 ./prep_dataset/ILSVRC2012_val_00034218.bin 224 224 +45422 ./prep_dataset/ILSVRC2012_val_00022615.bin 224 224 +45423 ./prep_dataset/ILSVRC2012_val_00045011.bin 224 224 +45424 ./prep_dataset/ILSVRC2012_val_00026377.bin 224 224 +45425 ./prep_dataset/ILSVRC2012_val_00018021.bin 224 224 +45426 ./prep_dataset/ILSVRC2012_val_00016550.bin 224 224 +45427 ./prep_dataset/ILSVRC2012_val_00017121.bin 224 224 +45428 ./prep_dataset/ILSVRC2012_val_00011588.bin 224 224 +45429 ./prep_dataset/ILSVRC2012_val_00028215.bin 224 224 +45430 ./prep_dataset/ILSVRC2012_val_00034398.bin 224 224 +45431 ./prep_dataset/ILSVRC2012_val_00047965.bin 224 224 +45432 ./prep_dataset/ILSVRC2012_val_00047960.bin 224 224 +45433 ./prep_dataset/ILSVRC2012_val_00025873.bin 224 224 +45434 ./prep_dataset/ILSVRC2012_val_00016287.bin 224 224 +45435 ./prep_dataset/ILSVRC2012_val_00024925.bin 224 224 +45436 ./prep_dataset/ILSVRC2012_val_00003163.bin 224 224 +45437 ./prep_dataset/ILSVRC2012_val_00022074.bin 224 224 +45438 ./prep_dataset/ILSVRC2012_val_00047959.bin 224 224 +45439 ./prep_dataset/ILSVRC2012_val_00010900.bin 224 224 +45440 ./prep_dataset/ILSVRC2012_val_00017995.bin 224 224 +45441 ./prep_dataset/ILSVRC2012_val_00032534.bin 224 224 +45442 ./prep_dataset/ILSVRC2012_val_00027525.bin 224 224 +45443 ./prep_dataset/ILSVRC2012_val_00012662.bin 224 224 +45444 ./prep_dataset/ILSVRC2012_val_00041182.bin 224 224 +45445 ./prep_dataset/ILSVRC2012_val_00011401.bin 224 224 +45446 ./prep_dataset/ILSVRC2012_val_00042730.bin 224 224 +45447 ./prep_dataset/ILSVRC2012_val_00015789.bin 224 224 +45448 ./prep_dataset/ILSVRC2012_val_00016405.bin 224 224 +45449 ./prep_dataset/ILSVRC2012_val_00048157.bin 224 224 +45450 ./prep_dataset/ILSVRC2012_val_00001532.bin 224 224 +45451 ./prep_dataset/ILSVRC2012_val_00013031.bin 224 224 +45452 ./prep_dataset/ILSVRC2012_val_00034829.bin 224 224 +45453 ./prep_dataset/ILSVRC2012_val_00043238.bin 224 224 +45454 ./prep_dataset/ILSVRC2012_val_00024261.bin 224 224 +45455 ./prep_dataset/ILSVRC2012_val_00033934.bin 224 224 +45456 ./prep_dataset/ILSVRC2012_val_00039037.bin 224 224 +45457 ./prep_dataset/ILSVRC2012_val_00003962.bin 224 224 +45458 ./prep_dataset/ILSVRC2012_val_00004975.bin 224 224 +45459 ./prep_dataset/ILSVRC2012_val_00013341.bin 224 224 +45460 ./prep_dataset/ILSVRC2012_val_00025688.bin 224 224 +45461 ./prep_dataset/ILSVRC2012_val_00036391.bin 224 224 +45462 ./prep_dataset/ILSVRC2012_val_00028165.bin 224 224 +45463 ./prep_dataset/ILSVRC2012_val_00008354.bin 224 224 +45464 ./prep_dataset/ILSVRC2012_val_00044781.bin 224 224 +45465 ./prep_dataset/ILSVRC2012_val_00022107.bin 224 224 +45466 ./prep_dataset/ILSVRC2012_val_00029738.bin 224 224 +45467 ./prep_dataset/ILSVRC2012_val_00029411.bin 224 224 +45468 ./prep_dataset/ILSVRC2012_val_00000587.bin 224 224 +45469 ./prep_dataset/ILSVRC2012_val_00015497.bin 224 224 +45470 ./prep_dataset/ILSVRC2012_val_00028033.bin 224 224 +45471 ./prep_dataset/ILSVRC2012_val_00038955.bin 224 224 +45472 ./prep_dataset/ILSVRC2012_val_00015850.bin 224 224 +45473 ./prep_dataset/ILSVRC2012_val_00010423.bin 224 224 +45474 ./prep_dataset/ILSVRC2012_val_00009250.bin 224 224 +45475 ./prep_dataset/ILSVRC2012_val_00005702.bin 224 224 +45476 ./prep_dataset/ILSVRC2012_val_00049843.bin 224 224 +45477 ./prep_dataset/ILSVRC2012_val_00026868.bin 224 224 +45478 ./prep_dataset/ILSVRC2012_val_00047111.bin 224 224 +45479 ./prep_dataset/ILSVRC2012_val_00025580.bin 224 224 +45480 ./prep_dataset/ILSVRC2012_val_00038824.bin 224 224 +45481 ./prep_dataset/ILSVRC2012_val_00046652.bin 224 224 +45482 ./prep_dataset/ILSVRC2012_val_00036964.bin 224 224 +45483 ./prep_dataset/ILSVRC2012_val_00007323.bin 224 224 +45484 ./prep_dataset/ILSVRC2012_val_00005869.bin 224 224 +45485 ./prep_dataset/ILSVRC2012_val_00014749.bin 224 224 +45486 ./prep_dataset/ILSVRC2012_val_00010924.bin 224 224 +45487 ./prep_dataset/ILSVRC2012_val_00036763.bin 224 224 +45488 ./prep_dataset/ILSVRC2012_val_00042783.bin 224 224 +45489 ./prep_dataset/ILSVRC2012_val_00007338.bin 224 224 +45490 ./prep_dataset/ILSVRC2012_val_00045801.bin 224 224 +45491 ./prep_dataset/ILSVRC2012_val_00046473.bin 224 224 +45492 ./prep_dataset/ILSVRC2012_val_00027987.bin 224 224 +45493 ./prep_dataset/ILSVRC2012_val_00011458.bin 224 224 +45494 ./prep_dataset/ILSVRC2012_val_00014697.bin 224 224 +45495 ./prep_dataset/ILSVRC2012_val_00037123.bin 224 224 +45496 ./prep_dataset/ILSVRC2012_val_00033680.bin 224 224 +45497 ./prep_dataset/ILSVRC2012_val_00023585.bin 224 224 +45498 ./prep_dataset/ILSVRC2012_val_00011798.bin 224 224 +45499 ./prep_dataset/ILSVRC2012_val_00017137.bin 224 224 +45500 ./prep_dataset/ILSVRC2012_val_00020027.bin 224 224 +45501 ./prep_dataset/ILSVRC2012_val_00005481.bin 224 224 +45502 ./prep_dataset/ILSVRC2012_val_00039271.bin 224 224 +45503 ./prep_dataset/ILSVRC2012_val_00005496.bin 224 224 +45504 ./prep_dataset/ILSVRC2012_val_00049102.bin 224 224 +45505 ./prep_dataset/ILSVRC2012_val_00011803.bin 224 224 +45506 ./prep_dataset/ILSVRC2012_val_00046935.bin 224 224 +45507 ./prep_dataset/ILSVRC2012_val_00032977.bin 224 224 +45508 ./prep_dataset/ILSVRC2012_val_00009715.bin 224 224 +45509 ./prep_dataset/ILSVRC2012_val_00036548.bin 224 224 +45510 ./prep_dataset/ILSVRC2012_val_00001671.bin 224 224 +45511 ./prep_dataset/ILSVRC2012_val_00010630.bin 224 224 +45512 ./prep_dataset/ILSVRC2012_val_00019142.bin 224 224 +45513 ./prep_dataset/ILSVRC2012_val_00042693.bin 224 224 +45514 ./prep_dataset/ILSVRC2012_val_00038972.bin 224 224 +45515 ./prep_dataset/ILSVRC2012_val_00046997.bin 224 224 +45516 ./prep_dataset/ILSVRC2012_val_00032733.bin 224 224 +45517 ./prep_dataset/ILSVRC2012_val_00026341.bin 224 224 +45518 ./prep_dataset/ILSVRC2012_val_00020019.bin 224 224 +45519 ./prep_dataset/ILSVRC2012_val_00009259.bin 224 224 +45520 ./prep_dataset/ILSVRC2012_val_00048721.bin 224 224 +45521 ./prep_dataset/ILSVRC2012_val_00015612.bin 224 224 +45522 ./prep_dataset/ILSVRC2012_val_00033767.bin 224 224 +45523 ./prep_dataset/ILSVRC2012_val_00047979.bin 224 224 +45524 ./prep_dataset/ILSVRC2012_val_00014705.bin 224 224 +45525 ./prep_dataset/ILSVRC2012_val_00043464.bin 224 224 +45526 ./prep_dataset/ILSVRC2012_val_00002088.bin 224 224 +45527 ./prep_dataset/ILSVRC2012_val_00044403.bin 224 224 +45528 ./prep_dataset/ILSVRC2012_val_00027429.bin 224 224 +45529 ./prep_dataset/ILSVRC2012_val_00016440.bin 224 224 +45530 ./prep_dataset/ILSVRC2012_val_00041159.bin 224 224 +45531 ./prep_dataset/ILSVRC2012_val_00005676.bin 224 224 +45532 ./prep_dataset/ILSVRC2012_val_00045965.bin 224 224 +45533 ./prep_dataset/ILSVRC2012_val_00011427.bin 224 224 +45534 ./prep_dataset/ILSVRC2012_val_00020295.bin 224 224 +45535 ./prep_dataset/ILSVRC2012_val_00028719.bin 224 224 +45536 ./prep_dataset/ILSVRC2012_val_00014789.bin 224 224 +45537 ./prep_dataset/ILSVRC2012_val_00045286.bin 224 224 +45538 ./prep_dataset/ILSVRC2012_val_00012587.bin 224 224 +45539 ./prep_dataset/ILSVRC2012_val_00003944.bin 224 224 +45540 ./prep_dataset/ILSVRC2012_val_00039575.bin 224 224 +45541 ./prep_dataset/ILSVRC2012_val_00034005.bin 224 224 +45542 ./prep_dataset/ILSVRC2012_val_00032925.bin 224 224 +45543 ./prep_dataset/ILSVRC2012_val_00042016.bin 224 224 +45544 ./prep_dataset/ILSVRC2012_val_00017033.bin 224 224 +45545 ./prep_dataset/ILSVRC2012_val_00010578.bin 224 224 +45546 ./prep_dataset/ILSVRC2012_val_00016164.bin 224 224 +45547 ./prep_dataset/ILSVRC2012_val_00010671.bin 224 224 +45548 ./prep_dataset/ILSVRC2012_val_00016966.bin 224 224 +45549 ./prep_dataset/ILSVRC2012_val_00013560.bin 224 224 +45550 ./prep_dataset/ILSVRC2012_val_00017642.bin 224 224 +45551 ./prep_dataset/ILSVRC2012_val_00023369.bin 224 224 +45552 ./prep_dataset/ILSVRC2012_val_00016451.bin 224 224 +45553 ./prep_dataset/ILSVRC2012_val_00048493.bin 224 224 +45554 ./prep_dataset/ILSVRC2012_val_00017307.bin 224 224 +45555 ./prep_dataset/ILSVRC2012_val_00023051.bin 224 224 +45556 ./prep_dataset/ILSVRC2012_val_00044787.bin 224 224 +45557 ./prep_dataset/ILSVRC2012_val_00011542.bin 224 224 +45558 ./prep_dataset/ILSVRC2012_val_00019718.bin 224 224 +45559 ./prep_dataset/ILSVRC2012_val_00015231.bin 224 224 +45560 ./prep_dataset/ILSVRC2012_val_00033737.bin 224 224 +45561 ./prep_dataset/ILSVRC2012_val_00020755.bin 224 224 +45562 ./prep_dataset/ILSVRC2012_val_00017924.bin 224 224 +45563 ./prep_dataset/ILSVRC2012_val_00044238.bin 224 224 +45564 ./prep_dataset/ILSVRC2012_val_00017606.bin 224 224 +45565 ./prep_dataset/ILSVRC2012_val_00036230.bin 224 224 +45566 ./prep_dataset/ILSVRC2012_val_00033887.bin 224 224 +45567 ./prep_dataset/ILSVRC2012_val_00034055.bin 224 224 +45568 ./prep_dataset/ILSVRC2012_val_00030515.bin 224 224 +45569 ./prep_dataset/ILSVRC2012_val_00023946.bin 224 224 +45570 ./prep_dataset/ILSVRC2012_val_00036443.bin 224 224 +45571 ./prep_dataset/ILSVRC2012_val_00022058.bin 224 224 +45572 ./prep_dataset/ILSVRC2012_val_00021220.bin 224 224 +45573 ./prep_dataset/ILSVRC2012_val_00037907.bin 224 224 +45574 ./prep_dataset/ILSVRC2012_val_00008110.bin 224 224 +45575 ./prep_dataset/ILSVRC2012_val_00016697.bin 224 224 +45576 ./prep_dataset/ILSVRC2012_val_00000941.bin 224 224 +45577 ./prep_dataset/ILSVRC2012_val_00032753.bin 224 224 +45578 ./prep_dataset/ILSVRC2012_val_00046943.bin 224 224 +45579 ./prep_dataset/ILSVRC2012_val_00006391.bin 224 224 +45580 ./prep_dataset/ILSVRC2012_val_00043792.bin 224 224 +45581 ./prep_dataset/ILSVRC2012_val_00008490.bin 224 224 +45582 ./prep_dataset/ILSVRC2012_val_00012597.bin 224 224 +45583 ./prep_dataset/ILSVRC2012_val_00012035.bin 224 224 +45584 ./prep_dataset/ILSVRC2012_val_00039566.bin 224 224 +45585 ./prep_dataset/ILSVRC2012_val_00003334.bin 224 224 +45586 ./prep_dataset/ILSVRC2012_val_00023017.bin 224 224 +45587 ./prep_dataset/ILSVRC2012_val_00002174.bin 224 224 +45588 ./prep_dataset/ILSVRC2012_val_00037316.bin 224 224 +45589 ./prep_dataset/ILSVRC2012_val_00003508.bin 224 224 +45590 ./prep_dataset/ILSVRC2012_val_00031947.bin 224 224 +45591 ./prep_dataset/ILSVRC2012_val_00042268.bin 224 224 +45592 ./prep_dataset/ILSVRC2012_val_00041847.bin 224 224 +45593 ./prep_dataset/ILSVRC2012_val_00001320.bin 224 224 +45594 ./prep_dataset/ILSVRC2012_val_00043503.bin 224 224 +45595 ./prep_dataset/ILSVRC2012_val_00024587.bin 224 224 +45596 ./prep_dataset/ILSVRC2012_val_00031685.bin 224 224 +45597 ./prep_dataset/ILSVRC2012_val_00000377.bin 224 224 +45598 ./prep_dataset/ILSVRC2012_val_00005552.bin 224 224 +45599 ./prep_dataset/ILSVRC2012_val_00029896.bin 224 224 +45600 ./prep_dataset/ILSVRC2012_val_00040509.bin 224 224 +45601 ./prep_dataset/ILSVRC2012_val_00028542.bin 224 224 +45602 ./prep_dataset/ILSVRC2012_val_00005569.bin 224 224 +45603 ./prep_dataset/ILSVRC2012_val_00040482.bin 224 224 +45604 ./prep_dataset/ILSVRC2012_val_00038964.bin 224 224 +45605 ./prep_dataset/ILSVRC2012_val_00023141.bin 224 224 +45606 ./prep_dataset/ILSVRC2012_val_00019492.bin 224 224 +45607 ./prep_dataset/ILSVRC2012_val_00022738.bin 224 224 +45608 ./prep_dataset/ILSVRC2012_val_00035059.bin 224 224 +45609 ./prep_dataset/ILSVRC2012_val_00004574.bin 224 224 +45610 ./prep_dataset/ILSVRC2012_val_00003077.bin 224 224 +45611 ./prep_dataset/ILSVRC2012_val_00008914.bin 224 224 +45612 ./prep_dataset/ILSVRC2012_val_00010203.bin 224 224 +45613 ./prep_dataset/ILSVRC2012_val_00048930.bin 224 224 +45614 ./prep_dataset/ILSVRC2012_val_00017266.bin 224 224 +45615 ./prep_dataset/ILSVRC2012_val_00042572.bin 224 224 +45616 ./prep_dataset/ILSVRC2012_val_00041558.bin 224 224 +45617 ./prep_dataset/ILSVRC2012_val_00046419.bin 224 224 +45618 ./prep_dataset/ILSVRC2012_val_00022305.bin 224 224 +45619 ./prep_dataset/ILSVRC2012_val_00013196.bin 224 224 +45620 ./prep_dataset/ILSVRC2012_val_00047014.bin 224 224 +45621 ./prep_dataset/ILSVRC2012_val_00014273.bin 224 224 +45622 ./prep_dataset/ILSVRC2012_val_00019351.bin 224 224 +45623 ./prep_dataset/ILSVRC2012_val_00012774.bin 224 224 +45624 ./prep_dataset/ILSVRC2012_val_00037989.bin 224 224 +45625 ./prep_dataset/ILSVRC2012_val_00031839.bin 224 224 +45626 ./prep_dataset/ILSVRC2012_val_00030147.bin 224 224 +45627 ./prep_dataset/ILSVRC2012_val_00030407.bin 224 224 +45628 ./prep_dataset/ILSVRC2012_val_00043707.bin 224 224 +45629 ./prep_dataset/ILSVRC2012_val_00043754.bin 224 224 +45630 ./prep_dataset/ILSVRC2012_val_00000851.bin 224 224 +45631 ./prep_dataset/ILSVRC2012_val_00031513.bin 224 224 +45632 ./prep_dataset/ILSVRC2012_val_00005942.bin 224 224 +45633 ./prep_dataset/ILSVRC2012_val_00045595.bin 224 224 +45634 ./prep_dataset/ILSVRC2012_val_00033084.bin 224 224 +45635 ./prep_dataset/ILSVRC2012_val_00003915.bin 224 224 +45636 ./prep_dataset/ILSVRC2012_val_00004547.bin 224 224 +45637 ./prep_dataset/ILSVRC2012_val_00003973.bin 224 224 +45638 ./prep_dataset/ILSVRC2012_val_00017927.bin 224 224 +45639 ./prep_dataset/ILSVRC2012_val_00003755.bin 224 224 +45640 ./prep_dataset/ILSVRC2012_val_00011559.bin 224 224 +45641 ./prep_dataset/ILSVRC2012_val_00041460.bin 224 224 +45642 ./prep_dataset/ILSVRC2012_val_00019796.bin 224 224 +45643 ./prep_dataset/ILSVRC2012_val_00021104.bin 224 224 +45644 ./prep_dataset/ILSVRC2012_val_00009225.bin 224 224 +45645 ./prep_dataset/ILSVRC2012_val_00014553.bin 224 224 +45646 ./prep_dataset/ILSVRC2012_val_00041166.bin 224 224 +45647 ./prep_dataset/ILSVRC2012_val_00048729.bin 224 224 +45648 ./prep_dataset/ILSVRC2012_val_00031835.bin 224 224 +45649 ./prep_dataset/ILSVRC2012_val_00001642.bin 224 224 +45650 ./prep_dataset/ILSVRC2012_val_00046898.bin 224 224 +45651 ./prep_dataset/ILSVRC2012_val_00042973.bin 224 224 +45652 ./prep_dataset/ILSVRC2012_val_00015748.bin 224 224 +45653 ./prep_dataset/ILSVRC2012_val_00002534.bin 224 224 +45654 ./prep_dataset/ILSVRC2012_val_00025652.bin 224 224 +45655 ./prep_dataset/ILSVRC2012_val_00045290.bin 224 224 +45656 ./prep_dataset/ILSVRC2012_val_00049685.bin 224 224 +45657 ./prep_dataset/ILSVRC2012_val_00029170.bin 224 224 +45658 ./prep_dataset/ILSVRC2012_val_00011009.bin 224 224 +45659 ./prep_dataset/ILSVRC2012_val_00027060.bin 224 224 +45660 ./prep_dataset/ILSVRC2012_val_00027686.bin 224 224 +45661 ./prep_dataset/ILSVRC2012_val_00029001.bin 224 224 +45662 ./prep_dataset/ILSVRC2012_val_00001795.bin 224 224 +45663 ./prep_dataset/ILSVRC2012_val_00020896.bin 224 224 +45664 ./prep_dataset/ILSVRC2012_val_00015786.bin 224 224 +45665 ./prep_dataset/ILSVRC2012_val_00033616.bin 224 224 +45666 ./prep_dataset/ILSVRC2012_val_00013280.bin 224 224 +45667 ./prep_dataset/ILSVRC2012_val_00046373.bin 224 224 +45668 ./prep_dataset/ILSVRC2012_val_00006347.bin 224 224 +45669 ./prep_dataset/ILSVRC2012_val_00034904.bin 224 224 +45670 ./prep_dataset/ILSVRC2012_val_00008935.bin 224 224 +45671 ./prep_dataset/ILSVRC2012_val_00036188.bin 224 224 +45672 ./prep_dataset/ILSVRC2012_val_00032083.bin 224 224 +45673 ./prep_dataset/ILSVRC2012_val_00038607.bin 224 224 +45674 ./prep_dataset/ILSVRC2012_val_00016272.bin 224 224 +45675 ./prep_dataset/ILSVRC2012_val_00028876.bin 224 224 +45676 ./prep_dataset/ILSVRC2012_val_00013869.bin 224 224 +45677 ./prep_dataset/ILSVRC2012_val_00025012.bin 224 224 +45678 ./prep_dataset/ILSVRC2012_val_00003811.bin 224 224 +45679 ./prep_dataset/ILSVRC2012_val_00041047.bin 224 224 +45680 ./prep_dataset/ILSVRC2012_val_00041938.bin 224 224 +45681 ./prep_dataset/ILSVRC2012_val_00007198.bin 224 224 +45682 ./prep_dataset/ILSVRC2012_val_00038802.bin 224 224 +45683 ./prep_dataset/ILSVRC2012_val_00010708.bin 224 224 +45684 ./prep_dataset/ILSVRC2012_val_00026092.bin 224 224 +45685 ./prep_dataset/ILSVRC2012_val_00041981.bin 224 224 +45686 ./prep_dataset/ILSVRC2012_val_00007612.bin 224 224 +45687 ./prep_dataset/ILSVRC2012_val_00003569.bin 224 224 +45688 ./prep_dataset/ILSVRC2012_val_00020509.bin 224 224 +45689 ./prep_dataset/ILSVRC2012_val_00042161.bin 224 224 +45690 ./prep_dataset/ILSVRC2012_val_00037730.bin 224 224 +45691 ./prep_dataset/ILSVRC2012_val_00035527.bin 224 224 +45692 ./prep_dataset/ILSVRC2012_val_00035639.bin 224 224 +45693 ./prep_dataset/ILSVRC2012_val_00042077.bin 224 224 +45694 ./prep_dataset/ILSVRC2012_val_00029961.bin 224 224 +45695 ./prep_dataset/ILSVRC2012_val_00005497.bin 224 224 +45696 ./prep_dataset/ILSVRC2012_val_00047604.bin 224 224 +45697 ./prep_dataset/ILSVRC2012_val_00000198.bin 224 224 +45698 ./prep_dataset/ILSVRC2012_val_00021350.bin 224 224 +45699 ./prep_dataset/ILSVRC2012_val_00049659.bin 224 224 +45700 ./prep_dataset/ILSVRC2012_val_00048748.bin 224 224 +45701 ./prep_dataset/ILSVRC2012_val_00048861.bin 224 224 +45702 ./prep_dataset/ILSVRC2012_val_00012288.bin 224 224 +45703 ./prep_dataset/ILSVRC2012_val_00033443.bin 224 224 +45704 ./prep_dataset/ILSVRC2012_val_00018083.bin 224 224 +45705 ./prep_dataset/ILSVRC2012_val_00032189.bin 224 224 +45706 ./prep_dataset/ILSVRC2012_val_00026624.bin 224 224 +45707 ./prep_dataset/ILSVRC2012_val_00026898.bin 224 224 +45708 ./prep_dataset/ILSVRC2012_val_00032106.bin 224 224 +45709 ./prep_dataset/ILSVRC2012_val_00002100.bin 224 224 +45710 ./prep_dataset/ILSVRC2012_val_00003865.bin 224 224 +45711 ./prep_dataset/ILSVRC2012_val_00035178.bin 224 224 +45712 ./prep_dataset/ILSVRC2012_val_00039955.bin 224 224 +45713 ./prep_dataset/ILSVRC2012_val_00048712.bin 224 224 +45714 ./prep_dataset/ILSVRC2012_val_00019593.bin 224 224 +45715 ./prep_dataset/ILSVRC2012_val_00016228.bin 224 224 +45716 ./prep_dataset/ILSVRC2012_val_00029881.bin 224 224 +45717 ./prep_dataset/ILSVRC2012_val_00037694.bin 224 224 +45718 ./prep_dataset/ILSVRC2012_val_00008964.bin 224 224 +45719 ./prep_dataset/ILSVRC2012_val_00030883.bin 224 224 +45720 ./prep_dataset/ILSVRC2012_val_00005222.bin 224 224 +45721 ./prep_dataset/ILSVRC2012_val_00029906.bin 224 224 +45722 ./prep_dataset/ILSVRC2012_val_00027302.bin 224 224 +45723 ./prep_dataset/ILSVRC2012_val_00033310.bin 224 224 +45724 ./prep_dataset/ILSVRC2012_val_00010818.bin 224 224 +45725 ./prep_dataset/ILSVRC2012_val_00030448.bin 224 224 +45726 ./prep_dataset/ILSVRC2012_val_00029845.bin 224 224 +45727 ./prep_dataset/ILSVRC2012_val_00021816.bin 224 224 +45728 ./prep_dataset/ILSVRC2012_val_00040063.bin 224 224 +45729 ./prep_dataset/ILSVRC2012_val_00042659.bin 224 224 +45730 ./prep_dataset/ILSVRC2012_val_00037912.bin 224 224 +45731 ./prep_dataset/ILSVRC2012_val_00031557.bin 224 224 +45732 ./prep_dataset/ILSVRC2012_val_00010242.bin 224 224 +45733 ./prep_dataset/ILSVRC2012_val_00024287.bin 224 224 +45734 ./prep_dataset/ILSVRC2012_val_00039412.bin 224 224 +45735 ./prep_dataset/ILSVRC2012_val_00017210.bin 224 224 +45736 ./prep_dataset/ILSVRC2012_val_00004778.bin 224 224 +45737 ./prep_dataset/ILSVRC2012_val_00024534.bin 224 224 +45738 ./prep_dataset/ILSVRC2012_val_00005402.bin 224 224 +45739 ./prep_dataset/ILSVRC2012_val_00037351.bin 224 224 +45740 ./prep_dataset/ILSVRC2012_val_00001243.bin 224 224 +45741 ./prep_dataset/ILSVRC2012_val_00006246.bin 224 224 +45742 ./prep_dataset/ILSVRC2012_val_00003775.bin 224 224 +45743 ./prep_dataset/ILSVRC2012_val_00030494.bin 224 224 +45744 ./prep_dataset/ILSVRC2012_val_00035684.bin 224 224 +45745 ./prep_dataset/ILSVRC2012_val_00047045.bin 224 224 +45746 ./prep_dataset/ILSVRC2012_val_00005863.bin 224 224 +45747 ./prep_dataset/ILSVRC2012_val_00023078.bin 224 224 +45748 ./prep_dataset/ILSVRC2012_val_00018500.bin 224 224 +45749 ./prep_dataset/ILSVRC2012_val_00048000.bin 224 224 +45750 ./prep_dataset/ILSVRC2012_val_00023164.bin 224 224 +45751 ./prep_dataset/ILSVRC2012_val_00018465.bin 224 224 +45752 ./prep_dataset/ILSVRC2012_val_00014410.bin 224 224 +45753 ./prep_dataset/ILSVRC2012_val_00031933.bin 224 224 +45754 ./prep_dataset/ILSVRC2012_val_00013913.bin 224 224 +45755 ./prep_dataset/ILSVRC2012_val_00032689.bin 224 224 +45756 ./prep_dataset/ILSVRC2012_val_00005197.bin 224 224 +45757 ./prep_dataset/ILSVRC2012_val_00022453.bin 224 224 +45758 ./prep_dataset/ILSVRC2012_val_00011493.bin 224 224 +45759 ./prep_dataset/ILSVRC2012_val_00015633.bin 224 224 +45760 ./prep_dataset/ILSVRC2012_val_00000233.bin 224 224 +45761 ./prep_dataset/ILSVRC2012_val_00001612.bin 224 224 +45762 ./prep_dataset/ILSVRC2012_val_00020449.bin 224 224 +45763 ./prep_dataset/ILSVRC2012_val_00017585.bin 224 224 +45764 ./prep_dataset/ILSVRC2012_val_00041358.bin 224 224 +45765 ./prep_dataset/ILSVRC2012_val_00032916.bin 224 224 +45766 ./prep_dataset/ILSVRC2012_val_00023783.bin 224 224 +45767 ./prep_dataset/ILSVRC2012_val_00042690.bin 224 224 +45768 ./prep_dataset/ILSVRC2012_val_00026193.bin 224 224 +45769 ./prep_dataset/ILSVRC2012_val_00016891.bin 224 224 +45770 ./prep_dataset/ILSVRC2012_val_00008633.bin 224 224 +45771 ./prep_dataset/ILSVRC2012_val_00002976.bin 224 224 +45772 ./prep_dataset/ILSVRC2012_val_00015287.bin 224 224 +45773 ./prep_dataset/ILSVRC2012_val_00019932.bin 224 224 +45774 ./prep_dataset/ILSVRC2012_val_00008994.bin 224 224 +45775 ./prep_dataset/ILSVRC2012_val_00030017.bin 224 224 +45776 ./prep_dataset/ILSVRC2012_val_00013885.bin 224 224 +45777 ./prep_dataset/ILSVRC2012_val_00012862.bin 224 224 +45778 ./prep_dataset/ILSVRC2012_val_00045870.bin 224 224 +45779 ./prep_dataset/ILSVRC2012_val_00025659.bin 224 224 +45780 ./prep_dataset/ILSVRC2012_val_00026268.bin 224 224 +45781 ./prep_dataset/ILSVRC2012_val_00036441.bin 224 224 +45782 ./prep_dataset/ILSVRC2012_val_00034019.bin 224 224 +45783 ./prep_dataset/ILSVRC2012_val_00014857.bin 224 224 +45784 ./prep_dataset/ILSVRC2012_val_00043275.bin 224 224 +45785 ./prep_dataset/ILSVRC2012_val_00016947.bin 224 224 +45786 ./prep_dataset/ILSVRC2012_val_00011242.bin 224 224 +45787 ./prep_dataset/ILSVRC2012_val_00028427.bin 224 224 +45788 ./prep_dataset/ILSVRC2012_val_00025350.bin 224 224 +45789 ./prep_dataset/ILSVRC2012_val_00041918.bin 224 224 +45790 ./prep_dataset/ILSVRC2012_val_00027385.bin 224 224 +45791 ./prep_dataset/ILSVRC2012_val_00049630.bin 224 224 +45792 ./prep_dataset/ILSVRC2012_val_00008968.bin 224 224 +45793 ./prep_dataset/ILSVRC2012_val_00023882.bin 224 224 +45794 ./prep_dataset/ILSVRC2012_val_00029996.bin 224 224 +45795 ./prep_dataset/ILSVRC2012_val_00025645.bin 224 224 +45796 ./prep_dataset/ILSVRC2012_val_00041834.bin 224 224 +45797 ./prep_dataset/ILSVRC2012_val_00047615.bin 224 224 +45798 ./prep_dataset/ILSVRC2012_val_00022980.bin 224 224 +45799 ./prep_dataset/ILSVRC2012_val_00034841.bin 224 224 +45800 ./prep_dataset/ILSVRC2012_val_00035881.bin 224 224 +45801 ./prep_dataset/ILSVRC2012_val_00017119.bin 224 224 +45802 ./prep_dataset/ILSVRC2012_val_00030928.bin 224 224 +45803 ./prep_dataset/ILSVRC2012_val_00046265.bin 224 224 +45804 ./prep_dataset/ILSVRC2012_val_00049110.bin 224 224 +45805 ./prep_dataset/ILSVRC2012_val_00013659.bin 224 224 +45806 ./prep_dataset/ILSVRC2012_val_00049319.bin 224 224 +45807 ./prep_dataset/ILSVRC2012_val_00049436.bin 224 224 +45808 ./prep_dataset/ILSVRC2012_val_00044552.bin 224 224 +45809 ./prep_dataset/ILSVRC2012_val_00018257.bin 224 224 +45810 ./prep_dataset/ILSVRC2012_val_00038285.bin 224 224 +45811 ./prep_dataset/ILSVRC2012_val_00020780.bin 224 224 +45812 ./prep_dataset/ILSVRC2012_val_00034710.bin 224 224 +45813 ./prep_dataset/ILSVRC2012_val_00010377.bin 224 224 +45814 ./prep_dataset/ILSVRC2012_val_00027296.bin 224 224 +45815 ./prep_dataset/ILSVRC2012_val_00030834.bin 224 224 +45816 ./prep_dataset/ILSVRC2012_val_00041515.bin 224 224 +45817 ./prep_dataset/ILSVRC2012_val_00004200.bin 224 224 +45818 ./prep_dataset/ILSVRC2012_val_00006216.bin 224 224 +45819 ./prep_dataset/ILSVRC2012_val_00038851.bin 224 224 +45820 ./prep_dataset/ILSVRC2012_val_00012239.bin 224 224 +45821 ./prep_dataset/ILSVRC2012_val_00039226.bin 224 224 +45822 ./prep_dataset/ILSVRC2012_val_00048881.bin 224 224 +45823 ./prep_dataset/ILSVRC2012_val_00004637.bin 224 224 +45824 ./prep_dataset/ILSVRC2012_val_00033060.bin 224 224 +45825 ./prep_dataset/ILSVRC2012_val_00041850.bin 224 224 +45826 ./prep_dataset/ILSVRC2012_val_00016208.bin 224 224 +45827 ./prep_dataset/ILSVRC2012_val_00004717.bin 224 224 +45828 ./prep_dataset/ILSVRC2012_val_00006856.bin 224 224 +45829 ./prep_dataset/ILSVRC2012_val_00006630.bin 224 224 +45830 ./prep_dataset/ILSVRC2012_val_00010976.bin 224 224 +45831 ./prep_dataset/ILSVRC2012_val_00023944.bin 224 224 +45832 ./prep_dataset/ILSVRC2012_val_00025984.bin 224 224 +45833 ./prep_dataset/ILSVRC2012_val_00029502.bin 224 224 +45834 ./prep_dataset/ILSVRC2012_val_00036997.bin 224 224 +45835 ./prep_dataset/ILSVRC2012_val_00003106.bin 224 224 +45836 ./prep_dataset/ILSVRC2012_val_00047296.bin 224 224 +45837 ./prep_dataset/ILSVRC2012_val_00010876.bin 224 224 +45838 ./prep_dataset/ILSVRC2012_val_00002654.bin 224 224 +45839 ./prep_dataset/ILSVRC2012_val_00040071.bin 224 224 +45840 ./prep_dataset/ILSVRC2012_val_00003153.bin 224 224 +45841 ./prep_dataset/ILSVRC2012_val_00015160.bin 224 224 +45842 ./prep_dataset/ILSVRC2012_val_00046817.bin 224 224 +45843 ./prep_dataset/ILSVRC2012_val_00035099.bin 224 224 +45844 ./prep_dataset/ILSVRC2012_val_00022523.bin 224 224 +45845 ./prep_dataset/ILSVRC2012_val_00003633.bin 224 224 +45846 ./prep_dataset/ILSVRC2012_val_00003432.bin 224 224 +45847 ./prep_dataset/ILSVRC2012_val_00001755.bin 224 224 +45848 ./prep_dataset/ILSVRC2012_val_00044910.bin 224 224 +45849 ./prep_dataset/ILSVRC2012_val_00034818.bin 224 224 +45850 ./prep_dataset/ILSVRC2012_val_00037154.bin 224 224 +45851 ./prep_dataset/ILSVRC2012_val_00026211.bin 224 224 +45852 ./prep_dataset/ILSVRC2012_val_00013916.bin 224 224 +45853 ./prep_dataset/ILSVRC2012_val_00023945.bin 224 224 +45854 ./prep_dataset/ILSVRC2012_val_00022724.bin 224 224 +45855 ./prep_dataset/ILSVRC2012_val_00017413.bin 224 224 +45856 ./prep_dataset/ILSVRC2012_val_00012912.bin 224 224 +45857 ./prep_dataset/ILSVRC2012_val_00023812.bin 224 224 +45858 ./prep_dataset/ILSVRC2012_val_00000110.bin 224 224 +45859 ./prep_dataset/ILSVRC2012_val_00005283.bin 224 224 +45860 ./prep_dataset/ILSVRC2012_val_00016648.bin 224 224 +45861 ./prep_dataset/ILSVRC2012_val_00033053.bin 224 224 +45862 ./prep_dataset/ILSVRC2012_val_00005059.bin 224 224 +45863 ./prep_dataset/ILSVRC2012_val_00005866.bin 224 224 +45864 ./prep_dataset/ILSVRC2012_val_00002686.bin 224 224 +45865 ./prep_dataset/ILSVRC2012_val_00018385.bin 224 224 +45866 ./prep_dataset/ILSVRC2012_val_00003913.bin 224 224 +45867 ./prep_dataset/ILSVRC2012_val_00022228.bin 224 224 +45868 ./prep_dataset/ILSVRC2012_val_00027952.bin 224 224 +45869 ./prep_dataset/ILSVRC2012_val_00034858.bin 224 224 +45870 ./prep_dataset/ILSVRC2012_val_00013687.bin 224 224 +45871 ./prep_dataset/ILSVRC2012_val_00003763.bin 224 224 +45872 ./prep_dataset/ILSVRC2012_val_00049217.bin 224 224 +45873 ./prep_dataset/ILSVRC2012_val_00034390.bin 224 224 +45874 ./prep_dataset/ILSVRC2012_val_00017346.bin 224 224 +45875 ./prep_dataset/ILSVRC2012_val_00036286.bin 224 224 +45876 ./prep_dataset/ILSVRC2012_val_00041478.bin 224 224 +45877 ./prep_dataset/ILSVRC2012_val_00011195.bin 224 224 +45878 ./prep_dataset/ILSVRC2012_val_00006171.bin 224 224 +45879 ./prep_dataset/ILSVRC2012_val_00042314.bin 224 224 +45880 ./prep_dataset/ILSVRC2012_val_00038392.bin 224 224 +45881 ./prep_dataset/ILSVRC2012_val_00013627.bin 224 224 +45882 ./prep_dataset/ILSVRC2012_val_00035533.bin 224 224 +45883 ./prep_dataset/ILSVRC2012_val_00045384.bin 224 224 +45884 ./prep_dataset/ILSVRC2012_val_00014022.bin 224 224 +45885 ./prep_dataset/ILSVRC2012_val_00043009.bin 224 224 +45886 ./prep_dataset/ILSVRC2012_val_00026090.bin 224 224 +45887 ./prep_dataset/ILSVRC2012_val_00045979.bin 224 224 +45888 ./prep_dataset/ILSVRC2012_val_00032583.bin 224 224 +45889 ./prep_dataset/ILSVRC2012_val_00012954.bin 224 224 +45890 ./prep_dataset/ILSVRC2012_val_00007031.bin 224 224 +45891 ./prep_dataset/ILSVRC2012_val_00003170.bin 224 224 +45892 ./prep_dataset/ILSVRC2012_val_00048467.bin 224 224 +45893 ./prep_dataset/ILSVRC2012_val_00014576.bin 224 224 +45894 ./prep_dataset/ILSVRC2012_val_00005499.bin 224 224 +45895 ./prep_dataset/ILSVRC2012_val_00049120.bin 224 224 +45896 ./prep_dataset/ILSVRC2012_val_00020298.bin 224 224 +45897 ./prep_dataset/ILSVRC2012_val_00033289.bin 224 224 +45898 ./prep_dataset/ILSVRC2012_val_00014691.bin 224 224 +45899 ./prep_dataset/ILSVRC2012_val_00043041.bin 224 224 +45900 ./prep_dataset/ILSVRC2012_val_00015645.bin 224 224 +45901 ./prep_dataset/ILSVRC2012_val_00028521.bin 224 224 +45902 ./prep_dataset/ILSVRC2012_val_00043428.bin 224 224 +45903 ./prep_dataset/ILSVRC2012_val_00045674.bin 224 224 +45904 ./prep_dataset/ILSVRC2012_val_00022532.bin 224 224 +45905 ./prep_dataset/ILSVRC2012_val_00019471.bin 224 224 +45906 ./prep_dataset/ILSVRC2012_val_00019759.bin 224 224 +45907 ./prep_dataset/ILSVRC2012_val_00036702.bin 224 224 +45908 ./prep_dataset/ILSVRC2012_val_00039601.bin 224 224 +45909 ./prep_dataset/ILSVRC2012_val_00013886.bin 224 224 +45910 ./prep_dataset/ILSVRC2012_val_00031558.bin 224 224 +45911 ./prep_dataset/ILSVRC2012_val_00030550.bin 224 224 +45912 ./prep_dataset/ILSVRC2012_val_00003921.bin 224 224 +45913 ./prep_dataset/ILSVRC2012_val_00029980.bin 224 224 +45914 ./prep_dataset/ILSVRC2012_val_00049526.bin 224 224 +45915 ./prep_dataset/ILSVRC2012_val_00035783.bin 224 224 +45916 ./prep_dataset/ILSVRC2012_val_00032579.bin 224 224 +45917 ./prep_dataset/ILSVRC2012_val_00034396.bin 224 224 +45918 ./prep_dataset/ILSVRC2012_val_00030751.bin 224 224 +45919 ./prep_dataset/ILSVRC2012_val_00025401.bin 224 224 +45920 ./prep_dataset/ILSVRC2012_val_00031662.bin 224 224 +45921 ./prep_dataset/ILSVRC2012_val_00040447.bin 224 224 +45922 ./prep_dataset/ILSVRC2012_val_00019868.bin 224 224 +45923 ./prep_dataset/ILSVRC2012_val_00013745.bin 224 224 +45924 ./prep_dataset/ILSVRC2012_val_00039807.bin 224 224 +45925 ./prep_dataset/ILSVRC2012_val_00026404.bin 224 224 +45926 ./prep_dataset/ILSVRC2012_val_00022535.bin 224 224 +45927 ./prep_dataset/ILSVRC2012_val_00048693.bin 224 224 +45928 ./prep_dataset/ILSVRC2012_val_00025755.bin 224 224 +45929 ./prep_dataset/ILSVRC2012_val_00009628.bin 224 224 +45930 ./prep_dataset/ILSVRC2012_val_00019922.bin 224 224 +45931 ./prep_dataset/ILSVRC2012_val_00030761.bin 224 224 +45932 ./prep_dataset/ILSVRC2012_val_00001209.bin 224 224 +45933 ./prep_dataset/ILSVRC2012_val_00007236.bin 224 224 +45934 ./prep_dataset/ILSVRC2012_val_00046023.bin 224 224 +45935 ./prep_dataset/ILSVRC2012_val_00029488.bin 224 224 +45936 ./prep_dataset/ILSVRC2012_val_00029525.bin 224 224 +45937 ./prep_dataset/ILSVRC2012_val_00047037.bin 224 224 +45938 ./prep_dataset/ILSVRC2012_val_00015442.bin 224 224 +45939 ./prep_dataset/ILSVRC2012_val_00029559.bin 224 224 +45940 ./prep_dataset/ILSVRC2012_val_00040075.bin 224 224 +45941 ./prep_dataset/ILSVRC2012_val_00021331.bin 224 224 +45942 ./prep_dataset/ILSVRC2012_val_00047951.bin 224 224 +45943 ./prep_dataset/ILSVRC2012_val_00048888.bin 224 224 +45944 ./prep_dataset/ILSVRC2012_val_00017865.bin 224 224 +45945 ./prep_dataset/ILSVRC2012_val_00014721.bin 224 224 +45946 ./prep_dataset/ILSVRC2012_val_00023657.bin 224 224 +45947 ./prep_dataset/ILSVRC2012_val_00036995.bin 224 224 +45948 ./prep_dataset/ILSVRC2012_val_00000947.bin 224 224 +45949 ./prep_dataset/ILSVRC2012_val_00003618.bin 224 224 +45950 ./prep_dataset/ILSVRC2012_val_00010662.bin 224 224 +45951 ./prep_dataset/ILSVRC2012_val_00014554.bin 224 224 +45952 ./prep_dataset/ILSVRC2012_val_00012282.bin 224 224 +45953 ./prep_dataset/ILSVRC2012_val_00013589.bin 224 224 +45954 ./prep_dataset/ILSVRC2012_val_00015514.bin 224 224 +45955 ./prep_dataset/ILSVRC2012_val_00002316.bin 224 224 +45956 ./prep_dataset/ILSVRC2012_val_00038472.bin 224 224 +45957 ./prep_dataset/ILSVRC2012_val_00038050.bin 224 224 +45958 ./prep_dataset/ILSVRC2012_val_00042999.bin 224 224 +45959 ./prep_dataset/ILSVRC2012_val_00021978.bin 224 224 +45960 ./prep_dataset/ILSVRC2012_val_00013831.bin 224 224 +45961 ./prep_dataset/ILSVRC2012_val_00030849.bin 224 224 +45962 ./prep_dataset/ILSVRC2012_val_00013552.bin 224 224 +45963 ./prep_dataset/ILSVRC2012_val_00019334.bin 224 224 +45964 ./prep_dataset/ILSVRC2012_val_00045350.bin 224 224 +45965 ./prep_dataset/ILSVRC2012_val_00012610.bin 224 224 +45966 ./prep_dataset/ILSVRC2012_val_00023236.bin 224 224 +45967 ./prep_dataset/ILSVRC2012_val_00034901.bin 224 224 +45968 ./prep_dataset/ILSVRC2012_val_00001802.bin 224 224 +45969 ./prep_dataset/ILSVRC2012_val_00019221.bin 224 224 +45970 ./prep_dataset/ILSVRC2012_val_00013969.bin 224 224 +45971 ./prep_dataset/ILSVRC2012_val_00021134.bin 224 224 +45972 ./prep_dataset/ILSVRC2012_val_00015918.bin 224 224 +45973 ./prep_dataset/ILSVRC2012_val_00013701.bin 224 224 +45974 ./prep_dataset/ILSVRC2012_val_00002925.bin 224 224 +45975 ./prep_dataset/ILSVRC2012_val_00026060.bin 224 224 +45976 ./prep_dataset/ILSVRC2012_val_00001584.bin 224 224 +45977 ./prep_dataset/ILSVRC2012_val_00012906.bin 224 224 +45978 ./prep_dataset/ILSVRC2012_val_00005208.bin 224 224 +45979 ./prep_dataset/ILSVRC2012_val_00027742.bin 224 224 +45980 ./prep_dataset/ILSVRC2012_val_00019268.bin 224 224 +45981 ./prep_dataset/ILSVRC2012_val_00026942.bin 224 224 +45982 ./prep_dataset/ILSVRC2012_val_00023170.bin 224 224 +45983 ./prep_dataset/ILSVRC2012_val_00032980.bin 224 224 +45984 ./prep_dataset/ILSVRC2012_val_00005480.bin 224 224 +45985 ./prep_dataset/ILSVRC2012_val_00042478.bin 224 224 +45986 ./prep_dataset/ILSVRC2012_val_00011082.bin 224 224 +45987 ./prep_dataset/ILSVRC2012_val_00018014.bin 224 224 +45988 ./prep_dataset/ILSVRC2012_val_00021550.bin 224 224 +45989 ./prep_dataset/ILSVRC2012_val_00034731.bin 224 224 +45990 ./prep_dataset/ILSVRC2012_val_00049031.bin 224 224 +45991 ./prep_dataset/ILSVRC2012_val_00020201.bin 224 224 +45992 ./prep_dataset/ILSVRC2012_val_00010673.bin 224 224 +45993 ./prep_dataset/ILSVRC2012_val_00009716.bin 224 224 +45994 ./prep_dataset/ILSVRC2012_val_00032912.bin 224 224 +45995 ./prep_dataset/ILSVRC2012_val_00035077.bin 224 224 +45996 ./prep_dataset/ILSVRC2012_val_00049587.bin 224 224 +45997 ./prep_dataset/ILSVRC2012_val_00005667.bin 224 224 +45998 ./prep_dataset/ILSVRC2012_val_00002231.bin 224 224 +45999 ./prep_dataset/ILSVRC2012_val_00011022.bin 224 224 +46000 ./prep_dataset/ILSVRC2012_val_00018004.bin 224 224 +46001 ./prep_dataset/ILSVRC2012_val_00008951.bin 224 224 +46002 ./prep_dataset/ILSVRC2012_val_00016739.bin 224 224 +46003 ./prep_dataset/ILSVRC2012_val_00010531.bin 224 224 +46004 ./prep_dataset/ILSVRC2012_val_00018217.bin 224 224 +46005 ./prep_dataset/ILSVRC2012_val_00030908.bin 224 224 +46006 ./prep_dataset/ILSVRC2012_val_00004363.bin 224 224 +46007 ./prep_dataset/ILSVRC2012_val_00044779.bin 224 224 +46008 ./prep_dataset/ILSVRC2012_val_00007983.bin 224 224 +46009 ./prep_dataset/ILSVRC2012_val_00014644.bin 224 224 +46010 ./prep_dataset/ILSVRC2012_val_00035603.bin 224 224 +46011 ./prep_dataset/ILSVRC2012_val_00029217.bin 224 224 +46012 ./prep_dataset/ILSVRC2012_val_00031744.bin 224 224 +46013 ./prep_dataset/ILSVRC2012_val_00044514.bin 224 224 +46014 ./prep_dataset/ILSVRC2012_val_00021282.bin 224 224 +46015 ./prep_dataset/ILSVRC2012_val_00016937.bin 224 224 +46016 ./prep_dataset/ILSVRC2012_val_00027909.bin 224 224 +46017 ./prep_dataset/ILSVRC2012_val_00018281.bin 224 224 +46018 ./prep_dataset/ILSVRC2012_val_00045091.bin 224 224 +46019 ./prep_dataset/ILSVRC2012_val_00007738.bin 224 224 +46020 ./prep_dataset/ILSVRC2012_val_00007907.bin 224 224 +46021 ./prep_dataset/ILSVRC2012_val_00016835.bin 224 224 +46022 ./prep_dataset/ILSVRC2012_val_00031666.bin 224 224 +46023 ./prep_dataset/ILSVRC2012_val_00001027.bin 224 224 +46024 ./prep_dataset/ILSVRC2012_val_00000179.bin 224 224 +46025 ./prep_dataset/ILSVRC2012_val_00020746.bin 224 224 +46026 ./prep_dataset/ILSVRC2012_val_00044392.bin 224 224 +46027 ./prep_dataset/ILSVRC2012_val_00035662.bin 224 224 +46028 ./prep_dataset/ILSVRC2012_val_00024302.bin 224 224 +46029 ./prep_dataset/ILSVRC2012_val_00011380.bin 224 224 +46030 ./prep_dataset/ILSVRC2012_val_00038365.bin 224 224 +46031 ./prep_dataset/ILSVRC2012_val_00001044.bin 224 224 +46032 ./prep_dataset/ILSVRC2012_val_00017393.bin 224 224 +46033 ./prep_dataset/ILSVRC2012_val_00006926.bin 224 224 +46034 ./prep_dataset/ILSVRC2012_val_00026247.bin 224 224 +46035 ./prep_dataset/ILSVRC2012_val_00016941.bin 224 224 +46036 ./prep_dataset/ILSVRC2012_val_00039478.bin 224 224 +46037 ./prep_dataset/ILSVRC2012_val_00015639.bin 224 224 +46038 ./prep_dataset/ILSVRC2012_val_00023087.bin 224 224 +46039 ./prep_dataset/ILSVRC2012_val_00022329.bin 224 224 +46040 ./prep_dataset/ILSVRC2012_val_00004178.bin 224 224 +46041 ./prep_dataset/ILSVRC2012_val_00017311.bin 224 224 +46042 ./prep_dataset/ILSVRC2012_val_00032707.bin 224 224 +46043 ./prep_dataset/ILSVRC2012_val_00039374.bin 224 224 +46044 ./prep_dataset/ILSVRC2012_val_00023178.bin 224 224 +46045 ./prep_dataset/ILSVRC2012_val_00038001.bin 224 224 +46046 ./prep_dataset/ILSVRC2012_val_00014864.bin 224 224 +46047 ./prep_dataset/ILSVRC2012_val_00044531.bin 224 224 +46048 ./prep_dataset/ILSVRC2012_val_00032749.bin 224 224 +46049 ./prep_dataset/ILSVRC2012_val_00003085.bin 224 224 +46050 ./prep_dataset/ILSVRC2012_val_00004805.bin 224 224 +46051 ./prep_dataset/ILSVRC2012_val_00036994.bin 224 224 +46052 ./prep_dataset/ILSVRC2012_val_00035861.bin 224 224 +46053 ./prep_dataset/ILSVRC2012_val_00004124.bin 224 224 +46054 ./prep_dataset/ILSVRC2012_val_00014398.bin 224 224 +46055 ./prep_dataset/ILSVRC2012_val_00039585.bin 224 224 +46056 ./prep_dataset/ILSVRC2012_val_00002055.bin 224 224 +46057 ./prep_dataset/ILSVRC2012_val_00020181.bin 224 224 +46058 ./prep_dataset/ILSVRC2012_val_00021612.bin 224 224 +46059 ./prep_dataset/ILSVRC2012_val_00023401.bin 224 224 +46060 ./prep_dataset/ILSVRC2012_val_00028946.bin 224 224 +46061 ./prep_dataset/ILSVRC2012_val_00033821.bin 224 224 +46062 ./prep_dataset/ILSVRC2012_val_00044576.bin 224 224 +46063 ./prep_dataset/ILSVRC2012_val_00022244.bin 224 224 +46064 ./prep_dataset/ILSVRC2012_val_00010781.bin 224 224 +46065 ./prep_dataset/ILSVRC2012_val_00003431.bin 224 224 +46066 ./prep_dataset/ILSVRC2012_val_00014060.bin 224 224 +46067 ./prep_dataset/ILSVRC2012_val_00039561.bin 224 224 +46068 ./prep_dataset/ILSVRC2012_val_00022695.bin 224 224 +46069 ./prep_dataset/ILSVRC2012_val_00035511.bin 224 224 +46070 ./prep_dataset/ILSVRC2012_val_00009000.bin 224 224 +46071 ./prep_dataset/ILSVRC2012_val_00043263.bin 224 224 +46072 ./prep_dataset/ILSVRC2012_val_00008280.bin 224 224 +46073 ./prep_dataset/ILSVRC2012_val_00011711.bin 224 224 +46074 ./prep_dataset/ILSVRC2012_val_00025038.bin 224 224 +46075 ./prep_dataset/ILSVRC2012_val_00009961.bin 224 224 +46076 ./prep_dataset/ILSVRC2012_val_00037626.bin 224 224 +46077 ./prep_dataset/ILSVRC2012_val_00004407.bin 224 224 +46078 ./prep_dataset/ILSVRC2012_val_00018076.bin 224 224 +46079 ./prep_dataset/ILSVRC2012_val_00044184.bin 224 224 +46080 ./prep_dataset/ILSVRC2012_val_00011305.bin 224 224 +46081 ./prep_dataset/ILSVRC2012_val_00046910.bin 224 224 +46082 ./prep_dataset/ILSVRC2012_val_00020486.bin 224 224 +46083 ./prep_dataset/ILSVRC2012_val_00046349.bin 224 224 +46084 ./prep_dataset/ILSVRC2012_val_00040202.bin 224 224 +46085 ./prep_dataset/ILSVRC2012_val_00048917.bin 224 224 +46086 ./prep_dataset/ILSVRC2012_val_00035644.bin 224 224 +46087 ./prep_dataset/ILSVRC2012_val_00033413.bin 224 224 +46088 ./prep_dataset/ILSVRC2012_val_00046365.bin 224 224 +46089 ./prep_dataset/ILSVRC2012_val_00009404.bin 224 224 +46090 ./prep_dataset/ILSVRC2012_val_00035358.bin 224 224 +46091 ./prep_dataset/ILSVRC2012_val_00044250.bin 224 224 +46092 ./prep_dataset/ILSVRC2012_val_00033847.bin 224 224 +46093 ./prep_dataset/ILSVRC2012_val_00009384.bin 224 224 +46094 ./prep_dataset/ILSVRC2012_val_00012430.bin 224 224 +46095 ./prep_dataset/ILSVRC2012_val_00020679.bin 224 224 +46096 ./prep_dataset/ILSVRC2012_val_00016035.bin 224 224 +46097 ./prep_dataset/ILSVRC2012_val_00022230.bin 224 224 +46098 ./prep_dataset/ILSVRC2012_val_00014443.bin 224 224 +46099 ./prep_dataset/ILSVRC2012_val_00045884.bin 224 224 +46100 ./prep_dataset/ILSVRC2012_val_00007346.bin 224 224 +46101 ./prep_dataset/ILSVRC2012_val_00017817.bin 224 224 +46102 ./prep_dataset/ILSVRC2012_val_00037750.bin 224 224 +46103 ./prep_dataset/ILSVRC2012_val_00035867.bin 224 224 +46104 ./prep_dataset/ILSVRC2012_val_00023952.bin 224 224 +46105 ./prep_dataset/ILSVRC2012_val_00020069.bin 224 224 +46106 ./prep_dataset/ILSVRC2012_val_00007382.bin 224 224 +46107 ./prep_dataset/ILSVRC2012_val_00041506.bin 224 224 +46108 ./prep_dataset/ILSVRC2012_val_00035786.bin 224 224 +46109 ./prep_dataset/ILSVRC2012_val_00038057.bin 224 224 +46110 ./prep_dataset/ILSVRC2012_val_00042366.bin 224 224 +46111 ./prep_dataset/ILSVRC2012_val_00028272.bin 224 224 +46112 ./prep_dataset/ILSVRC2012_val_00003076.bin 224 224 +46113 ./prep_dataset/ILSVRC2012_val_00009531.bin 224 224 +46114 ./prep_dataset/ILSVRC2012_val_00003650.bin 224 224 +46115 ./prep_dataset/ILSVRC2012_val_00048362.bin 224 224 +46116 ./prep_dataset/ILSVRC2012_val_00017714.bin 224 224 +46117 ./prep_dataset/ILSVRC2012_val_00020967.bin 224 224 +46118 ./prep_dataset/ILSVRC2012_val_00007228.bin 224 224 +46119 ./prep_dataset/ILSVRC2012_val_00029527.bin 224 224 +46120 ./prep_dataset/ILSVRC2012_val_00031763.bin 224 224 +46121 ./prep_dataset/ILSVRC2012_val_00019512.bin 224 224 +46122 ./prep_dataset/ILSVRC2012_val_00015388.bin 224 224 +46123 ./prep_dataset/ILSVRC2012_val_00003931.bin 224 224 +46124 ./prep_dataset/ILSVRC2012_val_00031980.bin 224 224 +46125 ./prep_dataset/ILSVRC2012_val_00028471.bin 224 224 +46126 ./prep_dataset/ILSVRC2012_val_00046546.bin 224 224 +46127 ./prep_dataset/ILSVRC2012_val_00023922.bin 224 224 +46128 ./prep_dataset/ILSVRC2012_val_00014782.bin 224 224 +46129 ./prep_dataset/ILSVRC2012_val_00039406.bin 224 224 +46130 ./prep_dataset/ILSVRC2012_val_00012188.bin 224 224 +46131 ./prep_dataset/ILSVRC2012_val_00044943.bin 224 224 +46132 ./prep_dataset/ILSVRC2012_val_00029013.bin 224 224 +46133 ./prep_dataset/ILSVRC2012_val_00048537.bin 224 224 +46134 ./prep_dataset/ILSVRC2012_val_00018324.bin 224 224 +46135 ./prep_dataset/ILSVRC2012_val_00010335.bin 224 224 +46136 ./prep_dataset/ILSVRC2012_val_00008723.bin 224 224 +46137 ./prep_dataset/ILSVRC2012_val_00035597.bin 224 224 +46138 ./prep_dataset/ILSVRC2012_val_00031259.bin 224 224 +46139 ./prep_dataset/ILSVRC2012_val_00046596.bin 224 224 +46140 ./prep_dataset/ILSVRC2012_val_00035419.bin 224 224 +46141 ./prep_dataset/ILSVRC2012_val_00037496.bin 224 224 +46142 ./prep_dataset/ILSVRC2012_val_00045422.bin 224 224 +46143 ./prep_dataset/ILSVRC2012_val_00048117.bin 224 224 +46144 ./prep_dataset/ILSVRC2012_val_00018860.bin 224 224 +46145 ./prep_dataset/ILSVRC2012_val_00035563.bin 224 224 +46146 ./prep_dataset/ILSVRC2012_val_00028677.bin 224 224 +46147 ./prep_dataset/ILSVRC2012_val_00049036.bin 224 224 +46148 ./prep_dataset/ILSVRC2012_val_00044055.bin 224 224 +46149 ./prep_dataset/ILSVRC2012_val_00016329.bin 224 224 +46150 ./prep_dataset/ILSVRC2012_val_00041291.bin 224 224 +46151 ./prep_dataset/ILSVRC2012_val_00018761.bin 224 224 +46152 ./prep_dataset/ILSVRC2012_val_00027651.bin 224 224 +46153 ./prep_dataset/ILSVRC2012_val_00035651.bin 224 224 +46154 ./prep_dataset/ILSVRC2012_val_00044344.bin 224 224 +46155 ./prep_dataset/ILSVRC2012_val_00034585.bin 224 224 +46156 ./prep_dataset/ILSVRC2012_val_00015350.bin 224 224 +46157 ./prep_dataset/ILSVRC2012_val_00003846.bin 224 224 +46158 ./prep_dataset/ILSVRC2012_val_00018954.bin 224 224 +46159 ./prep_dataset/ILSVRC2012_val_00029813.bin 224 224 +46160 ./prep_dataset/ILSVRC2012_val_00027482.bin 224 224 +46161 ./prep_dataset/ILSVRC2012_val_00032066.bin 224 224 +46162 ./prep_dataset/ILSVRC2012_val_00006264.bin 224 224 +46163 ./prep_dataset/ILSVRC2012_val_00029603.bin 224 224 +46164 ./prep_dataset/ILSVRC2012_val_00017197.bin 224 224 +46165 ./prep_dataset/ILSVRC2012_val_00025005.bin 224 224 +46166 ./prep_dataset/ILSVRC2012_val_00013268.bin 224 224 +46167 ./prep_dataset/ILSVRC2012_val_00038744.bin 224 224 +46168 ./prep_dataset/ILSVRC2012_val_00010848.bin 224 224 +46169 ./prep_dataset/ILSVRC2012_val_00044058.bin 224 224 +46170 ./prep_dataset/ILSVRC2012_val_00002059.bin 224 224 +46171 ./prep_dataset/ILSVRC2012_val_00024523.bin 224 224 +46172 ./prep_dataset/ILSVRC2012_val_00023983.bin 224 224 +46173 ./prep_dataset/ILSVRC2012_val_00017578.bin 224 224 +46174 ./prep_dataset/ILSVRC2012_val_00018685.bin 224 224 +46175 ./prep_dataset/ILSVRC2012_val_00002679.bin 224 224 +46176 ./prep_dataset/ILSVRC2012_val_00037551.bin 224 224 +46177 ./prep_dataset/ILSVRC2012_val_00022910.bin 224 224 +46178 ./prep_dataset/ILSVRC2012_val_00022057.bin 224 224 +46179 ./prep_dataset/ILSVRC2012_val_00006849.bin 224 224 +46180 ./prep_dataset/ILSVRC2012_val_00029245.bin 224 224 +46181 ./prep_dataset/ILSVRC2012_val_00043010.bin 224 224 +46182 ./prep_dataset/ILSVRC2012_val_00040527.bin 224 224 +46183 ./prep_dataset/ILSVRC2012_val_00006602.bin 224 224 +46184 ./prep_dataset/ILSVRC2012_val_00001454.bin 224 224 +46185 ./prep_dataset/ILSVRC2012_val_00015459.bin 224 224 +46186 ./prep_dataset/ILSVRC2012_val_00027015.bin 224 224 +46187 ./prep_dataset/ILSVRC2012_val_00033563.bin 224 224 +46188 ./prep_dataset/ILSVRC2012_val_00035462.bin 224 224 +46189 ./prep_dataset/ILSVRC2012_val_00014636.bin 224 224 +46190 ./prep_dataset/ILSVRC2012_val_00026842.bin 224 224 +46191 ./prep_dataset/ILSVRC2012_val_00031950.bin 224 224 +46192 ./prep_dataset/ILSVRC2012_val_00003524.bin 224 224 +46193 ./prep_dataset/ILSVRC2012_val_00036080.bin 224 224 +46194 ./prep_dataset/ILSVRC2012_val_00027984.bin 224 224 +46195 ./prep_dataset/ILSVRC2012_val_00022972.bin 224 224 +46196 ./prep_dataset/ILSVRC2012_val_00047705.bin 224 224 +46197 ./prep_dataset/ILSVRC2012_val_00043802.bin 224 224 +46198 ./prep_dataset/ILSVRC2012_val_00006747.bin 224 224 +46199 ./prep_dataset/ILSVRC2012_val_00012148.bin 224 224 +46200 ./prep_dataset/ILSVRC2012_val_00043128.bin 224 224 +46201 ./prep_dataset/ILSVRC2012_val_00023999.bin 224 224 +46202 ./prep_dataset/ILSVRC2012_val_00021255.bin 224 224 +46203 ./prep_dataset/ILSVRC2012_val_00049643.bin 224 224 +46204 ./prep_dataset/ILSVRC2012_val_00006319.bin 224 224 +46205 ./prep_dataset/ILSVRC2012_val_00049345.bin 224 224 +46206 ./prep_dataset/ILSVRC2012_val_00045893.bin 224 224 +46207 ./prep_dataset/ILSVRC2012_val_00002044.bin 224 224 +46208 ./prep_dataset/ILSVRC2012_val_00048822.bin 224 224 +46209 ./prep_dataset/ILSVRC2012_val_00025033.bin 224 224 +46210 ./prep_dataset/ILSVRC2012_val_00019181.bin 224 224 +46211 ./prep_dataset/ILSVRC2012_val_00019919.bin 224 224 +46212 ./prep_dataset/ILSVRC2012_val_00017371.bin 224 224 +46213 ./prep_dataset/ILSVRC2012_val_00000852.bin 224 224 +46214 ./prep_dataset/ILSVRC2012_val_00022493.bin 224 224 +46215 ./prep_dataset/ILSVRC2012_val_00044265.bin 224 224 +46216 ./prep_dataset/ILSVRC2012_val_00008768.bin 224 224 +46217 ./prep_dataset/ILSVRC2012_val_00001553.bin 224 224 +46218 ./prep_dataset/ILSVRC2012_val_00032061.bin 224 224 +46219 ./prep_dataset/ILSVRC2012_val_00025055.bin 224 224 +46220 ./prep_dataset/ILSVRC2012_val_00042182.bin 224 224 +46221 ./prep_dataset/ILSVRC2012_val_00026097.bin 224 224 +46222 ./prep_dataset/ILSVRC2012_val_00003165.bin 224 224 +46223 ./prep_dataset/ILSVRC2012_val_00013400.bin 224 224 +46224 ./prep_dataset/ILSVRC2012_val_00032557.bin 224 224 +46225 ./prep_dataset/ILSVRC2012_val_00037997.bin 224 224 +46226 ./prep_dataset/ILSVRC2012_val_00015907.bin 224 224 +46227 ./prep_dataset/ILSVRC2012_val_00016166.bin 224 224 +46228 ./prep_dataset/ILSVRC2012_val_00009909.bin 224 224 +46229 ./prep_dataset/ILSVRC2012_val_00003693.bin 224 224 +46230 ./prep_dataset/ILSVRC2012_val_00046609.bin 224 224 +46231 ./prep_dataset/ILSVRC2012_val_00008260.bin 224 224 +46232 ./prep_dataset/ILSVRC2012_val_00017969.bin 224 224 +46233 ./prep_dataset/ILSVRC2012_val_00002620.bin 224 224 +46234 ./prep_dataset/ILSVRC2012_val_00035098.bin 224 224 +46235 ./prep_dataset/ILSVRC2012_val_00014029.bin 224 224 +46236 ./prep_dataset/ILSVRC2012_val_00043744.bin 224 224 +46237 ./prep_dataset/ILSVRC2012_val_00038643.bin 224 224 +46238 ./prep_dataset/ILSVRC2012_val_00014624.bin 224 224 +46239 ./prep_dataset/ILSVRC2012_val_00031881.bin 224 224 +46240 ./prep_dataset/ILSVRC2012_val_00047835.bin 224 224 +46241 ./prep_dataset/ILSVRC2012_val_00010847.bin 224 224 +46242 ./prep_dataset/ILSVRC2012_val_00040650.bin 224 224 +46243 ./prep_dataset/ILSVRC2012_val_00048711.bin 224 224 +46244 ./prep_dataset/ILSVRC2012_val_00047772.bin 224 224 +46245 ./prep_dataset/ILSVRC2012_val_00046001.bin 224 224 +46246 ./prep_dataset/ILSVRC2012_val_00020382.bin 224 224 +46247 ./prep_dataset/ILSVRC2012_val_00041021.bin 224 224 +46248 ./prep_dataset/ILSVRC2012_val_00017721.bin 224 224 +46249 ./prep_dataset/ILSVRC2012_val_00006367.bin 224 224 +46250 ./prep_dataset/ILSVRC2012_val_00042166.bin 224 224 +46251 ./prep_dataset/ILSVRC2012_val_00015070.bin 224 224 +46252 ./prep_dataset/ILSVRC2012_val_00006525.bin 224 224 +46253 ./prep_dataset/ILSVRC2012_val_00049128.bin 224 224 +46254 ./prep_dataset/ILSVRC2012_val_00046017.bin 224 224 +46255 ./prep_dataset/ILSVRC2012_val_00024921.bin 224 224 +46256 ./prep_dataset/ILSVRC2012_val_00004382.bin 224 224 +46257 ./prep_dataset/ILSVRC2012_val_00047423.bin 224 224 +46258 ./prep_dataset/ILSVRC2012_val_00013263.bin 224 224 +46259 ./prep_dataset/ILSVRC2012_val_00042274.bin 224 224 +46260 ./prep_dataset/ILSVRC2012_val_00035594.bin 224 224 +46261 ./prep_dataset/ILSVRC2012_val_00029759.bin 224 224 +46262 ./prep_dataset/ILSVRC2012_val_00000792.bin 224 224 +46263 ./prep_dataset/ILSVRC2012_val_00003629.bin 224 224 +46264 ./prep_dataset/ILSVRC2012_val_00040750.bin 224 224 +46265 ./prep_dataset/ILSVRC2012_val_00019647.bin 224 224 +46266 ./prep_dataset/ILSVRC2012_val_00009018.bin 224 224 +46267 ./prep_dataset/ILSVRC2012_val_00043800.bin 224 224 +46268 ./prep_dataset/ILSVRC2012_val_00024008.bin 224 224 +46269 ./prep_dataset/ILSVRC2012_val_00021488.bin 224 224 +46270 ./prep_dataset/ILSVRC2012_val_00014746.bin 224 224 +46271 ./prep_dataset/ILSVRC2012_val_00003704.bin 224 224 +46272 ./prep_dataset/ILSVRC2012_val_00048617.bin 224 224 +46273 ./prep_dataset/ILSVRC2012_val_00018436.bin 224 224 +46274 ./prep_dataset/ILSVRC2012_val_00036567.bin 224 224 +46275 ./prep_dataset/ILSVRC2012_val_00023785.bin 224 224 +46276 ./prep_dataset/ILSVRC2012_val_00014280.bin 224 224 +46277 ./prep_dataset/ILSVRC2012_val_00026916.bin 224 224 +46278 ./prep_dataset/ILSVRC2012_val_00049008.bin 224 224 +46279 ./prep_dataset/ILSVRC2012_val_00028695.bin 224 224 +46280 ./prep_dataset/ILSVRC2012_val_00024640.bin 224 224 +46281 ./prep_dataset/ILSVRC2012_val_00044545.bin 224 224 +46282 ./prep_dataset/ILSVRC2012_val_00037422.bin 224 224 +46283 ./prep_dataset/ILSVRC2012_val_00049599.bin 224 224 +46284 ./prep_dataset/ILSVRC2012_val_00028580.bin 224 224 +46285 ./prep_dataset/ILSVRC2012_val_00011445.bin 224 224 +46286 ./prep_dataset/ILSVRC2012_val_00011784.bin 224 224 +46287 ./prep_dataset/ILSVRC2012_val_00045335.bin 224 224 +46288 ./prep_dataset/ILSVRC2012_val_00034782.bin 224 224 +46289 ./prep_dataset/ILSVRC2012_val_00020060.bin 224 224 +46290 ./prep_dataset/ILSVRC2012_val_00033940.bin 224 224 +46291 ./prep_dataset/ILSVRC2012_val_00007393.bin 224 224 +46292 ./prep_dataset/ILSVRC2012_val_00004771.bin 224 224 +46293 ./prep_dataset/ILSVRC2012_val_00040850.bin 224 224 +46294 ./prep_dataset/ILSVRC2012_val_00046551.bin 224 224 +46295 ./prep_dataset/ILSVRC2012_val_00031318.bin 224 224 +46296 ./prep_dataset/ILSVRC2012_val_00031026.bin 224 224 +46297 ./prep_dataset/ILSVRC2012_val_00040195.bin 224 224 +46298 ./prep_dataset/ILSVRC2012_val_00032135.bin 224 224 +46299 ./prep_dataset/ILSVRC2012_val_00026276.bin 224 224 +46300 ./prep_dataset/ILSVRC2012_val_00037366.bin 224 224 +46301 ./prep_dataset/ILSVRC2012_val_00024759.bin 224 224 +46302 ./prep_dataset/ILSVRC2012_val_00029385.bin 224 224 +46303 ./prep_dataset/ILSVRC2012_val_00005375.bin 224 224 +46304 ./prep_dataset/ILSVRC2012_val_00011755.bin 224 224 +46305 ./prep_dataset/ILSVRC2012_val_00043618.bin 224 224 +46306 ./prep_dataset/ILSVRC2012_val_00001677.bin 224 224 +46307 ./prep_dataset/ILSVRC2012_val_00015663.bin 224 224 +46308 ./prep_dataset/ILSVRC2012_val_00028737.bin 224 224 +46309 ./prep_dataset/ILSVRC2012_val_00017375.bin 224 224 +46310 ./prep_dataset/ILSVRC2012_val_00012079.bin 224 224 +46311 ./prep_dataset/ILSVRC2012_val_00025120.bin 224 224 +46312 ./prep_dataset/ILSVRC2012_val_00012426.bin 224 224 +46313 ./prep_dataset/ILSVRC2012_val_00000182.bin 224 224 +46314 ./prep_dataset/ILSVRC2012_val_00010458.bin 224 224 +46315 ./prep_dataset/ILSVRC2012_val_00023409.bin 224 224 +46316 ./prep_dataset/ILSVRC2012_val_00018567.bin 224 224 +46317 ./prep_dataset/ILSVRC2012_val_00010905.bin 224 224 +46318 ./prep_dataset/ILSVRC2012_val_00003242.bin 224 224 +46319 ./prep_dataset/ILSVRC2012_val_00006918.bin 224 224 +46320 ./prep_dataset/ILSVRC2012_val_00033884.bin 224 224 +46321 ./prep_dataset/ILSVRC2012_val_00048555.bin 224 224 +46322 ./prep_dataset/ILSVRC2012_val_00026009.bin 224 224 +46323 ./prep_dataset/ILSVRC2012_val_00027347.bin 224 224 +46324 ./prep_dataset/ILSVRC2012_val_00018580.bin 224 224 +46325 ./prep_dataset/ILSVRC2012_val_00028112.bin 224 224 +46326 ./prep_dataset/ILSVRC2012_val_00005989.bin 224 224 +46327 ./prep_dataset/ILSVRC2012_val_00043456.bin 224 224 +46328 ./prep_dataset/ILSVRC2012_val_00015370.bin 224 224 +46329 ./prep_dataset/ILSVRC2012_val_00005458.bin 224 224 +46330 ./prep_dataset/ILSVRC2012_val_00039495.bin 224 224 +46331 ./prep_dataset/ILSVRC2012_val_00020405.bin 224 224 +46332 ./prep_dataset/ILSVRC2012_val_00029444.bin 224 224 +46333 ./prep_dataset/ILSVRC2012_val_00042307.bin 224 224 +46334 ./prep_dataset/ILSVRC2012_val_00017166.bin 224 224 +46335 ./prep_dataset/ILSVRC2012_val_00040955.bin 224 224 +46336 ./prep_dataset/ILSVRC2012_val_00005741.bin 224 224 +46337 ./prep_dataset/ILSVRC2012_val_00047618.bin 224 224 +46338 ./prep_dataset/ILSVRC2012_val_00036154.bin 224 224 +46339 ./prep_dataset/ILSVRC2012_val_00037737.bin 224 224 +46340 ./prep_dataset/ILSVRC2012_val_00023795.bin 224 224 +46341 ./prep_dataset/ILSVRC2012_val_00044945.bin 224 224 +46342 ./prep_dataset/ILSVRC2012_val_00032898.bin 224 224 +46343 ./prep_dataset/ILSVRC2012_val_00013318.bin 224 224 +46344 ./prep_dataset/ILSVRC2012_val_00017466.bin 224 224 +46345 ./prep_dataset/ILSVRC2012_val_00044732.bin 224 224 +46346 ./prep_dataset/ILSVRC2012_val_00000104.bin 224 224 +46347 ./prep_dataset/ILSVRC2012_val_00020446.bin 224 224 +46348 ./prep_dataset/ILSVRC2012_val_00016254.bin 224 224 +46349 ./prep_dataset/ILSVRC2012_val_00022917.bin 224 224 +46350 ./prep_dataset/ILSVRC2012_val_00020706.bin 224 224 +46351 ./prep_dataset/ILSVRC2012_val_00042948.bin 224 224 +46352 ./prep_dataset/ILSVRC2012_val_00047406.bin 224 224 +46353 ./prep_dataset/ILSVRC2012_val_00009197.bin 224 224 +46354 ./prep_dataset/ILSVRC2012_val_00021489.bin 224 224 +46355 ./prep_dataset/ILSVRC2012_val_00022727.bin 224 224 +46356 ./prep_dataset/ILSVRC2012_val_00032337.bin 224 224 +46357 ./prep_dataset/ILSVRC2012_val_00046140.bin 224 224 +46358 ./prep_dataset/ILSVRC2012_val_00037535.bin 224 224 +46359 ./prep_dataset/ILSVRC2012_val_00035897.bin 224 224 +46360 ./prep_dataset/ILSVRC2012_val_00039800.bin 224 224 +46361 ./prep_dataset/ILSVRC2012_val_00010226.bin 224 224 +46362 ./prep_dataset/ILSVRC2012_val_00028917.bin 224 224 +46363 ./prep_dataset/ILSVRC2012_val_00016494.bin 224 224 +46364 ./prep_dataset/ILSVRC2012_val_00020836.bin 224 224 +46365 ./prep_dataset/ILSVRC2012_val_00036677.bin 224 224 +46366 ./prep_dataset/ILSVRC2012_val_00015273.bin 224 224 +46367 ./prep_dataset/ILSVRC2012_val_00039690.bin 224 224 +46368 ./prep_dataset/ILSVRC2012_val_00017986.bin 224 224 +46369 ./prep_dataset/ILSVRC2012_val_00042416.bin 224 224 +46370 ./prep_dataset/ILSVRC2012_val_00046197.bin 224 224 +46371 ./prep_dataset/ILSVRC2012_val_00004928.bin 224 224 +46372 ./prep_dataset/ILSVRC2012_val_00038638.bin 224 224 +46373 ./prep_dataset/ILSVRC2012_val_00026240.bin 224 224 +46374 ./prep_dataset/ILSVRC2012_val_00014699.bin 224 224 +46375 ./prep_dataset/ILSVRC2012_val_00034024.bin 224 224 +46376 ./prep_dataset/ILSVRC2012_val_00029202.bin 224 224 +46377 ./prep_dataset/ILSVRC2012_val_00020487.bin 224 224 +46378 ./prep_dataset/ILSVRC2012_val_00034575.bin 224 224 +46379 ./prep_dataset/ILSVRC2012_val_00000501.bin 224 224 +46380 ./prep_dataset/ILSVRC2012_val_00007423.bin 224 224 +46381 ./prep_dataset/ILSVRC2012_val_00049481.bin 224 224 +46382 ./prep_dataset/ILSVRC2012_val_00005102.bin 224 224 +46383 ./prep_dataset/ILSVRC2012_val_00031359.bin 224 224 +46384 ./prep_dataset/ILSVRC2012_val_00025723.bin 224 224 +46385 ./prep_dataset/ILSVRC2012_val_00049900.bin 224 224 +46386 ./prep_dataset/ILSVRC2012_val_00002343.bin 224 224 +46387 ./prep_dataset/ILSVRC2012_val_00037678.bin 224 224 +46388 ./prep_dataset/ILSVRC2012_val_00014818.bin 224 224 +46389 ./prep_dataset/ILSVRC2012_val_00003443.bin 224 224 +46390 ./prep_dataset/ILSVRC2012_val_00018518.bin 224 224 +46391 ./prep_dataset/ILSVRC2012_val_00031430.bin 224 224 +46392 ./prep_dataset/ILSVRC2012_val_00027118.bin 224 224 +46393 ./prep_dataset/ILSVRC2012_val_00040885.bin 224 224 +46394 ./prep_dataset/ILSVRC2012_val_00006862.bin 224 224 +46395 ./prep_dataset/ILSVRC2012_val_00014621.bin 224 224 +46396 ./prep_dataset/ILSVRC2012_val_00008412.bin 224 224 +46397 ./prep_dataset/ILSVRC2012_val_00027085.bin 224 224 +46398 ./prep_dataset/ILSVRC2012_val_00047654.bin 224 224 +46399 ./prep_dataset/ILSVRC2012_val_00028847.bin 224 224 +46400 ./prep_dataset/ILSVRC2012_val_00026763.bin 224 224 +46401 ./prep_dataset/ILSVRC2012_val_00029833.bin 224 224 +46402 ./prep_dataset/ILSVRC2012_val_00009685.bin 224 224 +46403 ./prep_dataset/ILSVRC2012_val_00000052.bin 224 224 +46404 ./prep_dataset/ILSVRC2012_val_00006229.bin 224 224 +46405 ./prep_dataset/ILSVRC2012_val_00035255.bin 224 224 +46406 ./prep_dataset/ILSVRC2012_val_00027812.bin 224 224 +46407 ./prep_dataset/ILSVRC2012_val_00044406.bin 224 224 +46408 ./prep_dataset/ILSVRC2012_val_00000634.bin 224 224 +46409 ./prep_dataset/ILSVRC2012_val_00024690.bin 224 224 +46410 ./prep_dataset/ILSVRC2012_val_00013036.bin 224 224 +46411 ./prep_dataset/ILSVRC2012_val_00014676.bin 224 224 +46412 ./prep_dataset/ILSVRC2012_val_00018587.bin 224 224 +46413 ./prep_dataset/ILSVRC2012_val_00011238.bin 224 224 +46414 ./prep_dataset/ILSVRC2012_val_00038247.bin 224 224 +46415 ./prep_dataset/ILSVRC2012_val_00006315.bin 224 224 +46416 ./prep_dataset/ILSVRC2012_val_00004188.bin 224 224 +46417 ./prep_dataset/ILSVRC2012_val_00022296.bin 224 224 +46418 ./prep_dataset/ILSVRC2012_val_00005801.bin 224 224 +46419 ./prep_dataset/ILSVRC2012_val_00002513.bin 224 224 +46420 ./prep_dataset/ILSVRC2012_val_00026001.bin 224 224 +46421 ./prep_dataset/ILSVRC2012_val_00037780.bin 224 224 +46422 ./prep_dataset/ILSVRC2012_val_00015019.bin 224 224 +46423 ./prep_dataset/ILSVRC2012_val_00031004.bin 224 224 +46424 ./prep_dataset/ILSVRC2012_val_00012469.bin 224 224 +46425 ./prep_dataset/ILSVRC2012_val_00021019.bin 224 224 +46426 ./prep_dataset/ILSVRC2012_val_00000140.bin 224 224 +46427 ./prep_dataset/ILSVRC2012_val_00005007.bin 224 224 +46428 ./prep_dataset/ILSVRC2012_val_00040658.bin 224 224 +46429 ./prep_dataset/ILSVRC2012_val_00043755.bin 224 224 +46430 ./prep_dataset/ILSVRC2012_val_00038112.bin 224 224 +46431 ./prep_dataset/ILSVRC2012_val_00049435.bin 224 224 +46432 ./prep_dataset/ILSVRC2012_val_00019797.bin 224 224 +46433 ./prep_dataset/ILSVRC2012_val_00034261.bin 224 224 +46434 ./prep_dataset/ILSVRC2012_val_00007105.bin 224 224 +46435 ./prep_dataset/ILSVRC2012_val_00048335.bin 224 224 +46436 ./prep_dataset/ILSVRC2012_val_00032959.bin 224 224 +46437 ./prep_dataset/ILSVRC2012_val_00031000.bin 224 224 +46438 ./prep_dataset/ILSVRC2012_val_00033938.bin 224 224 +46439 ./prep_dataset/ILSVRC2012_val_00037763.bin 224 224 +46440 ./prep_dataset/ILSVRC2012_val_00009011.bin 224 224 +46441 ./prep_dataset/ILSVRC2012_val_00001259.bin 224 224 +46442 ./prep_dataset/ILSVRC2012_val_00002766.bin 224 224 +46443 ./prep_dataset/ILSVRC2012_val_00022858.bin 224 224 +46444 ./prep_dataset/ILSVRC2012_val_00023126.bin 224 224 +46445 ./prep_dataset/ILSVRC2012_val_00046012.bin 224 224 +46446 ./prep_dataset/ILSVRC2012_val_00005872.bin 224 224 +46447 ./prep_dataset/ILSVRC2012_val_00010462.bin 224 224 +46448 ./prep_dataset/ILSVRC2012_val_00038503.bin 224 224 +46449 ./prep_dataset/ILSVRC2012_val_00032476.bin 224 224 +46450 ./prep_dataset/ILSVRC2012_val_00016081.bin 224 224 +46451 ./prep_dataset/ILSVRC2012_val_00025479.bin 224 224 +46452 ./prep_dataset/ILSVRC2012_val_00046417.bin 224 224 +46453 ./prep_dataset/ILSVRC2012_val_00041170.bin 224 224 +46454 ./prep_dataset/ILSVRC2012_val_00049552.bin 224 224 +46455 ./prep_dataset/ILSVRC2012_val_00039372.bin 224 224 +46456 ./prep_dataset/ILSVRC2012_val_00018970.bin 224 224 +46457 ./prep_dataset/ILSVRC2012_val_00035006.bin 224 224 +46458 ./prep_dataset/ILSVRC2012_val_00007263.bin 224 224 +46459 ./prep_dataset/ILSVRC2012_val_00042250.bin 224 224 +46460 ./prep_dataset/ILSVRC2012_val_00049828.bin 224 224 +46461 ./prep_dataset/ILSVRC2012_val_00016969.bin 224 224 +46462 ./prep_dataset/ILSVRC2012_val_00007219.bin 224 224 +46463 ./prep_dataset/ILSVRC2012_val_00025257.bin 224 224 +46464 ./prep_dataset/ILSVRC2012_val_00011505.bin 224 224 +46465 ./prep_dataset/ILSVRC2012_val_00004534.bin 224 224 +46466 ./prep_dataset/ILSVRC2012_val_00014765.bin 224 224 +46467 ./prep_dataset/ILSVRC2012_val_00045215.bin 224 224 +46468 ./prep_dataset/ILSVRC2012_val_00011871.bin 224 224 +46469 ./prep_dataset/ILSVRC2012_val_00020454.bin 224 224 +46470 ./prep_dataset/ILSVRC2012_val_00048562.bin 224 224 +46471 ./prep_dataset/ILSVRC2012_val_00023096.bin 224 224 +46472 ./prep_dataset/ILSVRC2012_val_00046531.bin 224 224 +46473 ./prep_dataset/ILSVRC2012_val_00010664.bin 224 224 +46474 ./prep_dataset/ILSVRC2012_val_00023203.bin 224 224 +46475 ./prep_dataset/ILSVRC2012_val_00034827.bin 224 224 +46476 ./prep_dataset/ILSVRC2012_val_00010619.bin 224 224 +46477 ./prep_dataset/ILSVRC2012_val_00041334.bin 224 224 +46478 ./prep_dataset/ILSVRC2012_val_00007772.bin 224 224 +46479 ./prep_dataset/ILSVRC2012_val_00003911.bin 224 224 +46480 ./prep_dataset/ILSVRC2012_val_00036663.bin 224 224 +46481 ./prep_dataset/ILSVRC2012_val_00016033.bin 224 224 +46482 ./prep_dataset/ILSVRC2012_val_00022964.bin 224 224 +46483 ./prep_dataset/ILSVRC2012_val_00044023.bin 224 224 +46484 ./prep_dataset/ILSVRC2012_val_00030008.bin 224 224 +46485 ./prep_dataset/ILSVRC2012_val_00030495.bin 224 224 +46486 ./prep_dataset/ILSVRC2012_val_00036009.bin 224 224 +46487 ./prep_dataset/ILSVRC2012_val_00019327.bin 224 224 +46488 ./prep_dataset/ILSVRC2012_val_00047628.bin 224 224 +46489 ./prep_dataset/ILSVRC2012_val_00044759.bin 224 224 +46490 ./prep_dataset/ILSVRC2012_val_00020279.bin 224 224 +46491 ./prep_dataset/ILSVRC2012_val_00025093.bin 224 224 +46492 ./prep_dataset/ILSVRC2012_val_00003292.bin 224 224 +46493 ./prep_dataset/ILSVRC2012_val_00010038.bin 224 224 +46494 ./prep_dataset/ILSVRC2012_val_00000689.bin 224 224 +46495 ./prep_dataset/ILSVRC2012_val_00006600.bin 224 224 +46496 ./prep_dataset/ILSVRC2012_val_00048571.bin 224 224 +46497 ./prep_dataset/ILSVRC2012_val_00026544.bin 224 224 +46498 ./prep_dataset/ILSVRC2012_val_00012350.bin 224 224 +46499 ./prep_dataset/ILSVRC2012_val_00048859.bin 224 224 +46500 ./prep_dataset/ILSVRC2012_val_00018075.bin 224 224 +46501 ./prep_dataset/ILSVRC2012_val_00038977.bin 224 224 +46502 ./prep_dataset/ILSVRC2012_val_00022162.bin 224 224 +46503 ./prep_dataset/ILSVRC2012_val_00000700.bin 224 224 +46504 ./prep_dataset/ILSVRC2012_val_00039857.bin 224 224 +46505 ./prep_dataset/ILSVRC2012_val_00000468.bin 224 224 +46506 ./prep_dataset/ILSVRC2012_val_00008817.bin 224 224 +46507 ./prep_dataset/ILSVRC2012_val_00005977.bin 224 224 +46508 ./prep_dataset/ILSVRC2012_val_00006744.bin 224 224 +46509 ./prep_dataset/ILSVRC2012_val_00029238.bin 224 224 +46510 ./prep_dataset/ILSVRC2012_val_00026976.bin 224 224 +46511 ./prep_dataset/ILSVRC2012_val_00025856.bin 224 224 +46512 ./prep_dataset/ILSVRC2012_val_00033841.bin 224 224 +46513 ./prep_dataset/ILSVRC2012_val_00004268.bin 224 224 +46514 ./prep_dataset/ILSVRC2012_val_00026383.bin 224 224 +46515 ./prep_dataset/ILSVRC2012_val_00018243.bin 224 224 +46516 ./prep_dataset/ILSVRC2012_val_00048319.bin 224 224 +46517 ./prep_dataset/ILSVRC2012_val_00020457.bin 224 224 +46518 ./prep_dataset/ILSVRC2012_val_00013398.bin 224 224 +46519 ./prep_dataset/ILSVRC2012_val_00035204.bin 224 224 +46520 ./prep_dataset/ILSVRC2012_val_00036364.bin 224 224 +46521 ./prep_dataset/ILSVRC2012_val_00030744.bin 224 224 +46522 ./prep_dataset/ILSVRC2012_val_00041620.bin 224 224 +46523 ./prep_dataset/ILSVRC2012_val_00012281.bin 224 224 +46524 ./prep_dataset/ILSVRC2012_val_00007427.bin 224 224 +46525 ./prep_dataset/ILSVRC2012_val_00037555.bin 224 224 +46526 ./prep_dataset/ILSVRC2012_val_00024048.bin 224 224 +46527 ./prep_dataset/ILSVRC2012_val_00029585.bin 224 224 +46528 ./prep_dataset/ILSVRC2012_val_00036318.bin 224 224 +46529 ./prep_dataset/ILSVRC2012_val_00048751.bin 224 224 +46530 ./prep_dataset/ILSVRC2012_val_00032774.bin 224 224 +46531 ./prep_dataset/ILSVRC2012_val_00047614.bin 224 224 +46532 ./prep_dataset/ILSVRC2012_val_00000455.bin 224 224 +46533 ./prep_dataset/ILSVRC2012_val_00011059.bin 224 224 +46534 ./prep_dataset/ILSVRC2012_val_00010749.bin 224 224 +46535 ./prep_dataset/ILSVRC2012_val_00032147.bin 224 224 +46536 ./prep_dataset/ILSVRC2012_val_00004502.bin 224 224 +46537 ./prep_dataset/ILSVRC2012_val_00038051.bin 224 224 +46538 ./prep_dataset/ILSVRC2012_val_00018365.bin 224 224 +46539 ./prep_dataset/ILSVRC2012_val_00005111.bin 224 224 +46540 ./prep_dataset/ILSVRC2012_val_00000206.bin 224 224 +46541 ./prep_dataset/ILSVRC2012_val_00008344.bin 224 224 +46542 ./prep_dataset/ILSVRC2012_val_00025800.bin 224 224 +46543 ./prep_dataset/ILSVRC2012_val_00006400.bin 224 224 +46544 ./prep_dataset/ILSVRC2012_val_00036896.bin 224 224 +46545 ./prep_dataset/ILSVRC2012_val_00010492.bin 224 224 +46546 ./prep_dataset/ILSVRC2012_val_00037708.bin 224 224 +46547 ./prep_dataset/ILSVRC2012_val_00000119.bin 224 224 +46548 ./prep_dataset/ILSVRC2012_val_00013000.bin 224 224 +46549 ./prep_dataset/ILSVRC2012_val_00037542.bin 224 224 +46550 ./prep_dataset/ILSVRC2012_val_00012591.bin 224 224 +46551 ./prep_dataset/ILSVRC2012_val_00012443.bin 224 224 +46552 ./prep_dataset/ILSVRC2012_val_00017370.bin 224 224 +46553 ./prep_dataset/ILSVRC2012_val_00049760.bin 224 224 +46554 ./prep_dataset/ILSVRC2012_val_00039502.bin 224 224 +46555 ./prep_dataset/ILSVRC2012_val_00019692.bin 224 224 +46556 ./prep_dataset/ILSVRC2012_val_00029887.bin 224 224 +46557 ./prep_dataset/ILSVRC2012_val_00023914.bin 224 224 +46558 ./prep_dataset/ILSVRC2012_val_00047083.bin 224 224 +46559 ./prep_dataset/ILSVRC2012_val_00028422.bin 224 224 +46560 ./prep_dataset/ILSVRC2012_val_00003415.bin 224 224 +46561 ./prep_dataset/ILSVRC2012_val_00021740.bin 224 224 +46562 ./prep_dataset/ILSVRC2012_val_00017011.bin 224 224 +46563 ./prep_dataset/ILSVRC2012_val_00013308.bin 224 224 +46564 ./prep_dataset/ILSVRC2012_val_00047587.bin 224 224 +46565 ./prep_dataset/ILSVRC2012_val_00049286.bin 224 224 +46566 ./prep_dataset/ILSVRC2012_val_00031647.bin 224 224 +46567 ./prep_dataset/ILSVRC2012_val_00038072.bin 224 224 +46568 ./prep_dataset/ILSVRC2012_val_00024297.bin 224 224 +46569 ./prep_dataset/ILSVRC2012_val_00048271.bin 224 224 +46570 ./prep_dataset/ILSVRC2012_val_00005646.bin 224 224 +46571 ./prep_dataset/ILSVRC2012_val_00034364.bin 224 224 +46572 ./prep_dataset/ILSVRC2012_val_00002308.bin 224 224 +46573 ./prep_dataset/ILSVRC2012_val_00036412.bin 224 224 +46574 ./prep_dataset/ILSVRC2012_val_00034345.bin 224 224 +46575 ./prep_dataset/ILSVRC2012_val_00044624.bin 224 224 +46576 ./prep_dataset/ILSVRC2012_val_00012831.bin 224 224 +46577 ./prep_dataset/ILSVRC2012_val_00005057.bin 224 224 +46578 ./prep_dataset/ILSVRC2012_val_00041959.bin 224 224 +46579 ./prep_dataset/ILSVRC2012_val_00036142.bin 224 224 +46580 ./prep_dataset/ILSVRC2012_val_00020558.bin 224 224 +46581 ./prep_dataset/ILSVRC2012_val_00049404.bin 224 224 +46582 ./prep_dataset/ILSVRC2012_val_00010988.bin 224 224 +46583 ./prep_dataset/ILSVRC2012_val_00032953.bin 224 224 +46584 ./prep_dataset/ILSVRC2012_val_00011329.bin 224 224 +46585 ./prep_dataset/ILSVRC2012_val_00048406.bin 224 224 +46586 ./prep_dataset/ILSVRC2012_val_00030649.bin 224 224 +46587 ./prep_dataset/ILSVRC2012_val_00027240.bin 224 224 +46588 ./prep_dataset/ILSVRC2012_val_00043029.bin 224 224 +46589 ./prep_dataset/ILSVRC2012_val_00043294.bin 224 224 +46590 ./prep_dataset/ILSVRC2012_val_00017182.bin 224 224 +46591 ./prep_dataset/ILSVRC2012_val_00042907.bin 224 224 +46592 ./prep_dataset/ILSVRC2012_val_00009091.bin 224 224 +46593 ./prep_dataset/ILSVRC2012_val_00035241.bin 224 224 +46594 ./prep_dataset/ILSVRC2012_val_00039454.bin 224 224 +46595 ./prep_dataset/ILSVRC2012_val_00030543.bin 224 224 +46596 ./prep_dataset/ILSVRC2012_val_00004898.bin 224 224 +46597 ./prep_dataset/ILSVRC2012_val_00002326.bin 224 224 +46598 ./prep_dataset/ILSVRC2012_val_00000978.bin 224 224 +46599 ./prep_dataset/ILSVRC2012_val_00043889.bin 224 224 +46600 ./prep_dataset/ILSVRC2012_val_00012664.bin 224 224 +46601 ./prep_dataset/ILSVRC2012_val_00007458.bin 224 224 +46602 ./prep_dataset/ILSVRC2012_val_00012652.bin 224 224 +46603 ./prep_dataset/ILSVRC2012_val_00018985.bin 224 224 +46604 ./prep_dataset/ILSVRC2012_val_00016142.bin 224 224 +46605 ./prep_dataset/ILSVRC2012_val_00017299.bin 224 224 +46606 ./prep_dataset/ILSVRC2012_val_00039308.bin 224 224 +46607 ./prep_dataset/ILSVRC2012_val_00001456.bin 224 224 +46608 ./prep_dataset/ILSVRC2012_val_00022616.bin 224 224 +46609 ./prep_dataset/ILSVRC2012_val_00042661.bin 224 224 +46610 ./prep_dataset/ILSVRC2012_val_00013927.bin 224 224 +46611 ./prep_dataset/ILSVRC2012_val_00029984.bin 224 224 +46612 ./prep_dataset/ILSVRC2012_val_00040478.bin 224 224 +46613 ./prep_dataset/ILSVRC2012_val_00021876.bin 224 224 +46614 ./prep_dataset/ILSVRC2012_val_00009155.bin 224 224 +46615 ./prep_dataset/ILSVRC2012_val_00029368.bin 224 224 +46616 ./prep_dataset/ILSVRC2012_val_00046825.bin 224 224 +46617 ./prep_dataset/ILSVRC2012_val_00008954.bin 224 224 +46618 ./prep_dataset/ILSVRC2012_val_00034335.bin 224 224 +46619 ./prep_dataset/ILSVRC2012_val_00026741.bin 224 224 +46620 ./prep_dataset/ILSVRC2012_val_00002847.bin 224 224 +46621 ./prep_dataset/ILSVRC2012_val_00049248.bin 224 224 +46622 ./prep_dataset/ILSVRC2012_val_00017452.bin 224 224 +46623 ./prep_dataset/ILSVRC2012_val_00044383.bin 224 224 +46624 ./prep_dataset/ILSVRC2012_val_00001321.bin 224 224 +46625 ./prep_dataset/ILSVRC2012_val_00007305.bin 224 224 +46626 ./prep_dataset/ILSVRC2012_val_00015995.bin 224 224 +46627 ./prep_dataset/ILSVRC2012_val_00041269.bin 224 224 +46628 ./prep_dataset/ILSVRC2012_val_00010439.bin 224 224 +46629 ./prep_dataset/ILSVRC2012_val_00031582.bin 224 224 +46630 ./prep_dataset/ILSVRC2012_val_00037475.bin 224 224 +46631 ./prep_dataset/ILSVRC2012_val_00022676.bin 224 224 +46632 ./prep_dataset/ILSVRC2012_val_00041589.bin 224 224 +46633 ./prep_dataset/ILSVRC2012_val_00016779.bin 224 224 +46634 ./prep_dataset/ILSVRC2012_val_00042304.bin 224 224 +46635 ./prep_dataset/ILSVRC2012_val_00045201.bin 224 224 +46636 ./prep_dataset/ILSVRC2012_val_00025399.bin 224 224 +46637 ./prep_dataset/ILSVRC2012_val_00028997.bin 224 224 +46638 ./prep_dataset/ILSVRC2012_val_00015433.bin 224 224 +46639 ./prep_dataset/ILSVRC2012_val_00040815.bin 224 224 +46640 ./prep_dataset/ILSVRC2012_val_00025859.bin 224 224 +46641 ./prep_dataset/ILSVRC2012_val_00022916.bin 224 224 +46642 ./prep_dataset/ILSVRC2012_val_00010822.bin 224 224 +46643 ./prep_dataset/ILSVRC2012_val_00027275.bin 224 224 +46644 ./prep_dataset/ILSVRC2012_val_00015672.bin 224 224 +46645 ./prep_dataset/ILSVRC2012_val_00032510.bin 224 224 +46646 ./prep_dataset/ILSVRC2012_val_00045789.bin 224 224 +46647 ./prep_dataset/ILSVRC2012_val_00017526.bin 224 224 +46648 ./prep_dataset/ILSVRC2012_val_00013499.bin 224 224 +46649 ./prep_dataset/ILSVRC2012_val_00037060.bin 224 224 +46650 ./prep_dataset/ILSVRC2012_val_00039193.bin 224 224 +46651 ./prep_dataset/ILSVRC2012_val_00033423.bin 224 224 +46652 ./prep_dataset/ILSVRC2012_val_00018738.bin 224 224 +46653 ./prep_dataset/ILSVRC2012_val_00031212.bin 224 224 +46654 ./prep_dataset/ILSVRC2012_val_00008441.bin 224 224 +46655 ./prep_dataset/ILSVRC2012_val_00035887.bin 224 224 +46656 ./prep_dataset/ILSVRC2012_val_00032604.bin 224 224 +46657 ./prep_dataset/ILSVRC2012_val_00019623.bin 224 224 +46658 ./prep_dataset/ILSVRC2012_val_00034859.bin 224 224 +46659 ./prep_dataset/ILSVRC2012_val_00043912.bin 224 224 +46660 ./prep_dataset/ILSVRC2012_val_00008432.bin 224 224 +46661 ./prep_dataset/ILSVRC2012_val_00003636.bin 224 224 +46662 ./prep_dataset/ILSVRC2012_val_00014140.bin 224 224 +46663 ./prep_dataset/ILSVRC2012_val_00043702.bin 224 224 +46664 ./prep_dataset/ILSVRC2012_val_00016979.bin 224 224 +46665 ./prep_dataset/ILSVRC2012_val_00042141.bin 224 224 +46666 ./prep_dataset/ILSVRC2012_val_00029335.bin 224 224 +46667 ./prep_dataset/ILSVRC2012_val_00023757.bin 224 224 +46668 ./prep_dataset/ILSVRC2012_val_00025140.bin 224 224 +46669 ./prep_dataset/ILSVRC2012_val_00042024.bin 224 224 +46670 ./prep_dataset/ILSVRC2012_val_00041116.bin 224 224 +46671 ./prep_dataset/ILSVRC2012_val_00000846.bin 224 224 +46672 ./prep_dataset/ILSVRC2012_val_00012084.bin 224 224 +46673 ./prep_dataset/ILSVRC2012_val_00013152.bin 224 224 +46674 ./prep_dataset/ILSVRC2012_val_00034371.bin 224 224 +46675 ./prep_dataset/ILSVRC2012_val_00047497.bin 224 224 +46676 ./prep_dataset/ILSVRC2012_val_00015061.bin 224 224 +46677 ./prep_dataset/ILSVRC2012_val_00035991.bin 224 224 +46678 ./prep_dataset/ILSVRC2012_val_00035177.bin 224 224 +46679 ./prep_dataset/ILSVRC2012_val_00049749.bin 224 224 +46680 ./prep_dataset/ILSVRC2012_val_00040956.bin 224 224 +46681 ./prep_dataset/ILSVRC2012_val_00000443.bin 224 224 +46682 ./prep_dataset/ILSVRC2012_val_00045793.bin 224 224 +46683 ./prep_dataset/ILSVRC2012_val_00009088.bin 224 224 +46684 ./prep_dataset/ILSVRC2012_val_00004994.bin 224 224 +46685 ./prep_dataset/ILSVRC2012_val_00007859.bin 224 224 +46686 ./prep_dataset/ILSVRC2012_val_00042655.bin 224 224 +46687 ./prep_dataset/ILSVRC2012_val_00035479.bin 224 224 +46688 ./prep_dataset/ILSVRC2012_val_00025331.bin 224 224 +46689 ./prep_dataset/ILSVRC2012_val_00043262.bin 224 224 +46690 ./prep_dataset/ILSVRC2012_val_00012172.bin 224 224 +46691 ./prep_dataset/ILSVRC2012_val_00043185.bin 224 224 +46692 ./prep_dataset/ILSVRC2012_val_00041704.bin 224 224 +46693 ./prep_dataset/ILSVRC2012_val_00036152.bin 224 224 +46694 ./prep_dataset/ILSVRC2012_val_00038950.bin 224 224 +46695 ./prep_dataset/ILSVRC2012_val_00046270.bin 224 224 +46696 ./prep_dataset/ILSVRC2012_val_00010110.bin 224 224 +46697 ./prep_dataset/ILSVRC2012_val_00027001.bin 224 224 +46698 ./prep_dataset/ILSVRC2012_val_00017304.bin 224 224 +46699 ./prep_dataset/ILSVRC2012_val_00006755.bin 224 224 +46700 ./prep_dataset/ILSVRC2012_val_00033468.bin 224 224 +46701 ./prep_dataset/ILSVRC2012_val_00022189.bin 224 224 +46702 ./prep_dataset/ILSVRC2012_val_00009942.bin 224 224 +46703 ./prep_dataset/ILSVRC2012_val_00041228.bin 224 224 +46704 ./prep_dataset/ILSVRC2012_val_00017450.bin 224 224 +46705 ./prep_dataset/ILSVRC2012_val_00016239.bin 224 224 +46706 ./prep_dataset/ILSVRC2012_val_00007046.bin 224 224 +46707 ./prep_dataset/ILSVRC2012_val_00009098.bin 224 224 +46708 ./prep_dataset/ILSVRC2012_val_00044052.bin 224 224 +46709 ./prep_dataset/ILSVRC2012_val_00046792.bin 224 224 +46710 ./prep_dataset/ILSVRC2012_val_00004149.bin 224 224 +46711 ./prep_dataset/ILSVRC2012_val_00014376.bin 224 224 +46712 ./prep_dataset/ILSVRC2012_val_00048043.bin 224 224 +46713 ./prep_dataset/ILSVRC2012_val_00013849.bin 224 224 +46714 ./prep_dataset/ILSVRC2012_val_00004478.bin 224 224 +46715 ./prep_dataset/ILSVRC2012_val_00002328.bin 224 224 +46716 ./prep_dataset/ILSVRC2012_val_00024101.bin 224 224 +46717 ./prep_dataset/ILSVRC2012_val_00042329.bin 224 224 +46718 ./prep_dataset/ILSVRC2012_val_00040737.bin 224 224 +46719 ./prep_dataset/ILSVRC2012_val_00032600.bin 224 224 +46720 ./prep_dataset/ILSVRC2012_val_00025099.bin 224 224 +46721 ./prep_dataset/ILSVRC2012_val_00017637.bin 224 224 +46722 ./prep_dataset/ILSVRC2012_val_00003211.bin 224 224 +46723 ./prep_dataset/ILSVRC2012_val_00023719.bin 224 224 +46724 ./prep_dataset/ILSVRC2012_val_00021394.bin 224 224 +46725 ./prep_dataset/ILSVRC2012_val_00017862.bin 224 224 +46726 ./prep_dataset/ILSVRC2012_val_00027467.bin 224 224 +46727 ./prep_dataset/ILSVRC2012_val_00010072.bin 224 224 +46728 ./prep_dataset/ILSVRC2012_val_00000741.bin 224 224 +46729 ./prep_dataset/ILSVRC2012_val_00033816.bin 224 224 +46730 ./prep_dataset/ILSVRC2012_val_00019472.bin 224 224 +46731 ./prep_dataset/ILSVRC2012_val_00040151.bin 224 224 +46732 ./prep_dataset/ILSVRC2012_val_00015860.bin 224 224 +46733 ./prep_dataset/ILSVRC2012_val_00028069.bin 224 224 +46734 ./prep_dataset/ILSVRC2012_val_00017474.bin 224 224 +46735 ./prep_dataset/ILSVRC2012_val_00039712.bin 224 224 +46736 ./prep_dataset/ILSVRC2012_val_00035425.bin 224 224 +46737 ./prep_dataset/ILSVRC2012_val_00041550.bin 224 224 +46738 ./prep_dataset/ILSVRC2012_val_00023353.bin 224 224 +46739 ./prep_dataset/ILSVRC2012_val_00033903.bin 224 224 +46740 ./prep_dataset/ILSVRC2012_val_00012184.bin 224 224 +46741 ./prep_dataset/ILSVRC2012_val_00043501.bin 224 224 +46742 ./prep_dataset/ILSVRC2012_val_00039694.bin 224 224 +46743 ./prep_dataset/ILSVRC2012_val_00014828.bin 224 224 +46744 ./prep_dataset/ILSVRC2012_val_00021324.bin 224 224 +46745 ./prep_dataset/ILSVRC2012_val_00011964.bin 224 224 +46746 ./prep_dataset/ILSVRC2012_val_00033835.bin 224 224 +46747 ./prep_dataset/ILSVRC2012_val_00024362.bin 224 224 +46748 ./prep_dataset/ILSVRC2012_val_00008552.bin 224 224 +46749 ./prep_dataset/ILSVRC2012_val_00025079.bin 224 224 +46750 ./prep_dataset/ILSVRC2012_val_00003833.bin 224 224 +46751 ./prep_dataset/ILSVRC2012_val_00048685.bin 224 224 +46752 ./prep_dataset/ILSVRC2012_val_00024007.bin 224 224 +46753 ./prep_dataset/ILSVRC2012_val_00031187.bin 224 224 +46754 ./prep_dataset/ILSVRC2012_val_00019211.bin 224 224 +46755 ./prep_dataset/ILSVRC2012_val_00043567.bin 224 224 +46756 ./prep_dataset/ILSVRC2012_val_00036855.bin 224 224 +46757 ./prep_dataset/ILSVRC2012_val_00015020.bin 224 224 +46758 ./prep_dataset/ILSVRC2012_val_00028453.bin 224 224 +46759 ./prep_dataset/ILSVRC2012_val_00000371.bin 224 224 +46760 ./prep_dataset/ILSVRC2012_val_00017278.bin 224 224 +46761 ./prep_dataset/ILSVRC2012_val_00014942.bin 224 224 +46762 ./prep_dataset/ILSVRC2012_val_00017240.bin 224 224 +46763 ./prep_dataset/ILSVRC2012_val_00038820.bin 224 224 +46764 ./prep_dataset/ILSVRC2012_val_00025169.bin 224 224 +46765 ./prep_dataset/ILSVRC2012_val_00049257.bin 224 224 +46766 ./prep_dataset/ILSVRC2012_val_00029257.bin 224 224 +46767 ./prep_dataset/ILSVRC2012_val_00045245.bin 224 224 +46768 ./prep_dataset/ILSVRC2012_val_00017477.bin 224 224 +46769 ./prep_dataset/ILSVRC2012_val_00041361.bin 224 224 +46770 ./prep_dataset/ILSVRC2012_val_00002849.bin 224 224 +46771 ./prep_dataset/ILSVRC2012_val_00013863.bin 224 224 +46772 ./prep_dataset/ILSVRC2012_val_00016594.bin 224 224 +46773 ./prep_dataset/ILSVRC2012_val_00001171.bin 224 224 +46774 ./prep_dataset/ILSVRC2012_val_00046527.bin 224 224 +46775 ./prep_dataset/ILSVRC2012_val_00013991.bin 224 224 +46776 ./prep_dataset/ILSVRC2012_val_00009022.bin 224 224 +46777 ./prep_dataset/ILSVRC2012_val_00025951.bin 224 224 +46778 ./prep_dataset/ILSVRC2012_val_00027037.bin 224 224 +46779 ./prep_dataset/ILSVRC2012_val_00017732.bin 224 224 +46780 ./prep_dataset/ILSVRC2012_val_00010350.bin 224 224 +46781 ./prep_dataset/ILSVRC2012_val_00001960.bin 224 224 +46782 ./prep_dataset/ILSVRC2012_val_00030467.bin 224 224 +46783 ./prep_dataset/ILSVRC2012_val_00017777.bin 224 224 +46784 ./prep_dataset/ILSVRC2012_val_00044321.bin 224 224 +46785 ./prep_dataset/ILSVRC2012_val_00021769.bin 224 224 +46786 ./prep_dataset/ILSVRC2012_val_00013888.bin 224 224 +46787 ./prep_dataset/ILSVRC2012_val_00017804.bin 224 224 +46788 ./prep_dataset/ILSVRC2012_val_00022601.bin 224 224 +46789 ./prep_dataset/ILSVRC2012_val_00009927.bin 224 224 +46790 ./prep_dataset/ILSVRC2012_val_00035649.bin 224 224 +46791 ./prep_dataset/ILSVRC2012_val_00027803.bin 224 224 +46792 ./prep_dataset/ILSVRC2012_val_00040637.bin 224 224 +46793 ./prep_dataset/ILSVRC2012_val_00017097.bin 224 224 +46794 ./prep_dataset/ILSVRC2012_val_00016836.bin 224 224 +46795 ./prep_dataset/ILSVRC2012_val_00030215.bin 224 224 +46796 ./prep_dataset/ILSVRC2012_val_00028409.bin 224 224 +46797 ./prep_dataset/ILSVRC2012_val_00014933.bin 224 224 +46798 ./prep_dataset/ILSVRC2012_val_00013056.bin 224 224 +46799 ./prep_dataset/ILSVRC2012_val_00015811.bin 224 224 +46800 ./prep_dataset/ILSVRC2012_val_00005983.bin 224 224 +46801 ./prep_dataset/ILSVRC2012_val_00040557.bin 224 224 +46802 ./prep_dataset/ILSVRC2012_val_00013551.bin 224 224 +46803 ./prep_dataset/ILSVRC2012_val_00011140.bin 224 224 +46804 ./prep_dataset/ILSVRC2012_val_00033566.bin 224 224 +46805 ./prep_dataset/ILSVRC2012_val_00039722.bin 224 224 +46806 ./prep_dataset/ILSVRC2012_val_00027623.bin 224 224 +46807 ./prep_dataset/ILSVRC2012_val_00007153.bin 224 224 +46808 ./prep_dataset/ILSVRC2012_val_00048237.bin 224 224 +46809 ./prep_dataset/ILSVRC2012_val_00044001.bin 224 224 +46810 ./prep_dataset/ILSVRC2012_val_00049409.bin 224 224 +46811 ./prep_dataset/ILSVRC2012_val_00046731.bin 224 224 +46812 ./prep_dataset/ILSVRC2012_val_00011092.bin 224 224 +46813 ./prep_dataset/ILSVRC2012_val_00019366.bin 224 224 +46814 ./prep_dataset/ILSVRC2012_val_00038213.bin 224 224 +46815 ./prep_dataset/ILSVRC2012_val_00020032.bin 224 224 +46816 ./prep_dataset/ILSVRC2012_val_00004390.bin 224 224 +46817 ./prep_dataset/ILSVRC2012_val_00002626.bin 224 224 +46818 ./prep_dataset/ILSVRC2012_val_00022875.bin 224 224 +46819 ./prep_dataset/ILSVRC2012_val_00014965.bin 224 224 +46820 ./prep_dataset/ILSVRC2012_val_00020533.bin 224 224 +46821 ./prep_dataset/ILSVRC2012_val_00014824.bin 224 224 +46822 ./prep_dataset/ILSVRC2012_val_00006698.bin 224 224 +46823 ./prep_dataset/ILSVRC2012_val_00045248.bin 224 224 +46824 ./prep_dataset/ILSVRC2012_val_00047186.bin 224 224 +46825 ./prep_dataset/ILSVRC2012_val_00049335.bin 224 224 +46826 ./prep_dataset/ILSVRC2012_val_00034933.bin 224 224 +46827 ./prep_dataset/ILSVRC2012_val_00011450.bin 224 224 +46828 ./prep_dataset/ILSVRC2012_val_00008442.bin 224 224 +46829 ./prep_dataset/ILSVRC2012_val_00026982.bin 224 224 +46830 ./prep_dataset/ILSVRC2012_val_00003848.bin 224 224 +46831 ./prep_dataset/ILSVRC2012_val_00043487.bin 224 224 +46832 ./prep_dataset/ILSVRC2012_val_00014241.bin 224 224 +46833 ./prep_dataset/ILSVRC2012_val_00019245.bin 224 224 +46834 ./prep_dataset/ILSVRC2012_val_00041869.bin 224 224 +46835 ./prep_dataset/ILSVRC2012_val_00001419.bin 224 224 +46836 ./prep_dataset/ILSVRC2012_val_00020761.bin 224 224 +46837 ./prep_dataset/ILSVRC2012_val_00022774.bin 224 224 +46838 ./prep_dataset/ILSVRC2012_val_00012611.bin 224 224 +46839 ./prep_dataset/ILSVRC2012_val_00009939.bin 224 224 +46840 ./prep_dataset/ILSVRC2012_val_00012313.bin 224 224 +46841 ./prep_dataset/ILSVRC2012_val_00025048.bin 224 224 +46842 ./prep_dataset/ILSVRC2012_val_00046799.bin 224 224 +46843 ./prep_dataset/ILSVRC2012_val_00022171.bin 224 224 +46844 ./prep_dataset/ILSVRC2012_val_00044228.bin 224 224 +46845 ./prep_dataset/ILSVRC2012_val_00049822.bin 224 224 +46846 ./prep_dataset/ILSVRC2012_val_00031536.bin 224 224 +46847 ./prep_dataset/ILSVRC2012_val_00033070.bin 224 224 +46848 ./prep_dataset/ILSVRC2012_val_00036784.bin 224 224 +46849 ./prep_dataset/ILSVRC2012_val_00036380.bin 224 224 +46850 ./prep_dataset/ILSVRC2012_val_00015187.bin 224 224 +46851 ./prep_dataset/ILSVRC2012_val_00005792.bin 224 224 +46852 ./prep_dataset/ILSVRC2012_val_00039057.bin 224 224 +46853 ./prep_dataset/ILSVRC2012_val_00009604.bin 224 224 +46854 ./prep_dataset/ILSVRC2012_val_00034741.bin 224 224 +46855 ./prep_dataset/ILSVRC2012_val_00022605.bin 224 224 +46856 ./prep_dataset/ILSVRC2012_val_00027908.bin 224 224 +46857 ./prep_dataset/ILSVRC2012_val_00028310.bin 224 224 +46858 ./prep_dataset/ILSVRC2012_val_00001923.bin 224 224 +46859 ./prep_dataset/ILSVRC2012_val_00036155.bin 224 224 +46860 ./prep_dataset/ILSVRC2012_val_00013962.bin 224 224 +46861 ./prep_dataset/ILSVRC2012_val_00047665.bin 224 224 +46862 ./prep_dataset/ILSVRC2012_val_00041610.bin 224 224 +46863 ./prep_dataset/ILSVRC2012_val_00026166.bin 224 224 +46864 ./prep_dataset/ILSVRC2012_val_00045003.bin 224 224 +46865 ./prep_dataset/ILSVRC2012_val_00023128.bin 224 224 +46866 ./prep_dataset/ILSVRC2012_val_00018862.bin 224 224 +46867 ./prep_dataset/ILSVRC2012_val_00040051.bin 224 224 +46868 ./prep_dataset/ILSVRC2012_val_00020913.bin 224 224 +46869 ./prep_dataset/ILSVRC2012_val_00049557.bin 224 224 +46870 ./prep_dataset/ILSVRC2012_val_00040300.bin 224 224 +46871 ./prep_dataset/ILSVRC2012_val_00018471.bin 224 224 +46872 ./prep_dataset/ILSVRC2012_val_00038696.bin 224 224 +46873 ./prep_dataset/ILSVRC2012_val_00040336.bin 224 224 +46874 ./prep_dataset/ILSVRC2012_val_00012907.bin 224 224 +46875 ./prep_dataset/ILSVRC2012_val_00046517.bin 224 224 +46876 ./prep_dataset/ILSVRC2012_val_00019619.bin 224 224 +46877 ./prep_dataset/ILSVRC2012_val_00026537.bin 224 224 +46878 ./prep_dataset/ILSVRC2012_val_00034655.bin 224 224 +46879 ./prep_dataset/ILSVRC2012_val_00022261.bin 224 224 +46880 ./prep_dataset/ILSVRC2012_val_00007635.bin 224 224 +46881 ./prep_dataset/ILSVRC2012_val_00048350.bin 224 224 +46882 ./prep_dataset/ILSVRC2012_val_00039530.bin 224 224 +46883 ./prep_dataset/ILSVRC2012_val_00016123.bin 224 224 +46884 ./prep_dataset/ILSVRC2012_val_00029014.bin 224 224 +46885 ./prep_dataset/ILSVRC2012_val_00011834.bin 224 224 +46886 ./prep_dataset/ILSVRC2012_val_00011203.bin 224 224 +46887 ./prep_dataset/ILSVRC2012_val_00049287.bin 224 224 +46888 ./prep_dataset/ILSVRC2012_val_00012812.bin 224 224 +46889 ./prep_dataset/ILSVRC2012_val_00024624.bin 224 224 +46890 ./prep_dataset/ILSVRC2012_val_00024339.bin 224 224 +46891 ./prep_dataset/ILSVRC2012_val_00015763.bin 224 224 +46892 ./prep_dataset/ILSVRC2012_val_00000607.bin 224 224 +46893 ./prep_dataset/ILSVRC2012_val_00031596.bin 224 224 +46894 ./prep_dataset/ILSVRC2012_val_00022285.bin 224 224 +46895 ./prep_dataset/ILSVRC2012_val_00047277.bin 224 224 +46896 ./prep_dataset/ILSVRC2012_val_00011933.bin 224 224 +46897 ./prep_dataset/ILSVRC2012_val_00040028.bin 224 224 +46898 ./prep_dataset/ILSVRC2012_val_00039263.bin 224 224 +46899 ./prep_dataset/ILSVRC2012_val_00033333.bin 224 224 +46900 ./prep_dataset/ILSVRC2012_val_00039769.bin 224 224 +46901 ./prep_dataset/ILSVRC2012_val_00046683.bin 224 224 +46902 ./prep_dataset/ILSVRC2012_val_00041103.bin 224 224 +46903 ./prep_dataset/ILSVRC2012_val_00017595.bin 224 224 +46904 ./prep_dataset/ILSVRC2012_val_00018634.bin 224 224 +46905 ./prep_dataset/ILSVRC2012_val_00000970.bin 224 224 +46906 ./prep_dataset/ILSVRC2012_val_00024502.bin 224 224 +46907 ./prep_dataset/ILSVRC2012_val_00033581.bin 224 224 +46908 ./prep_dataset/ILSVRC2012_val_00017297.bin 224 224 +46909 ./prep_dataset/ILSVRC2012_val_00023059.bin 224 224 +46910 ./prep_dataset/ILSVRC2012_val_00001059.bin 224 224 +46911 ./prep_dataset/ILSVRC2012_val_00023525.bin 224 224 +46912 ./prep_dataset/ILSVRC2012_val_00002495.bin 224 224 +46913 ./prep_dataset/ILSVRC2012_val_00039510.bin 224 224 +46914 ./prep_dataset/ILSVRC2012_val_00042067.bin 224 224 +46915 ./prep_dataset/ILSVRC2012_val_00037118.bin 224 224 +46916 ./prep_dataset/ILSVRC2012_val_00026160.bin 224 224 +46917 ./prep_dataset/ILSVRC2012_val_00002321.bin 224 224 +46918 ./prep_dataset/ILSVRC2012_val_00045146.bin 224 224 +46919 ./prep_dataset/ILSVRC2012_val_00028699.bin 224 224 +46920 ./prep_dataset/ILSVRC2012_val_00016470.bin 224 224 +46921 ./prep_dataset/ILSVRC2012_val_00039085.bin 224 224 +46922 ./prep_dataset/ILSVRC2012_val_00047164.bin 224 224 +46923 ./prep_dataset/ILSVRC2012_val_00008741.bin 224 224 +46924 ./prep_dataset/ILSVRC2012_val_00049519.bin 224 224 +46925 ./prep_dataset/ILSVRC2012_val_00027895.bin 224 224 +46926 ./prep_dataset/ILSVRC2012_val_00021952.bin 224 224 +46927 ./prep_dataset/ILSVRC2012_val_00029331.bin 224 224 +46928 ./prep_dataset/ILSVRC2012_val_00042317.bin 224 224 +46929 ./prep_dataset/ILSVRC2012_val_00004085.bin 224 224 +46930 ./prep_dataset/ILSVRC2012_val_00039664.bin 224 224 +46931 ./prep_dataset/ILSVRC2012_val_00048818.bin 224 224 +46932 ./prep_dataset/ILSVRC2012_val_00008542.bin 224 224 +46933 ./prep_dataset/ILSVRC2012_val_00048106.bin 224 224 +46934 ./prep_dataset/ILSVRC2012_val_00037003.bin 224 224 +46935 ./prep_dataset/ILSVRC2012_val_00044996.bin 224 224 +46936 ./prep_dataset/ILSVRC2012_val_00046515.bin 224 224 +46937 ./prep_dataset/ILSVRC2012_val_00019224.bin 224 224 +46938 ./prep_dataset/ILSVRC2012_val_00016988.bin 224 224 +46939 ./prep_dataset/ILSVRC2012_val_00046810.bin 224 224 +46940 ./prep_dataset/ILSVRC2012_val_00043622.bin 224 224 +46941 ./prep_dataset/ILSVRC2012_val_00012077.bin 224 224 +46942 ./prep_dataset/ILSVRC2012_val_00005740.bin 224 224 +46943 ./prep_dataset/ILSVRC2012_val_00003091.bin 224 224 +46944 ./prep_dataset/ILSVRC2012_val_00028858.bin 224 224 +46945 ./prep_dataset/ILSVRC2012_val_00002562.bin 224 224 +46946 ./prep_dataset/ILSVRC2012_val_00021611.bin 224 224 +46947 ./prep_dataset/ILSVRC2012_val_00006889.bin 224 224 +46948 ./prep_dataset/ILSVRC2012_val_00039891.bin 224 224 +46949 ./prep_dataset/ILSVRC2012_val_00047479.bin 224 224 +46950 ./prep_dataset/ILSVRC2012_val_00002333.bin 224 224 +46951 ./prep_dataset/ILSVRC2012_val_00005859.bin 224 224 +46952 ./prep_dataset/ILSVRC2012_val_00015094.bin 224 224 +46953 ./prep_dataset/ILSVRC2012_val_00048775.bin 224 224 +46954 ./prep_dataset/ILSVRC2012_val_00048587.bin 224 224 +46955 ./prep_dataset/ILSVRC2012_val_00017571.bin 224 224 +46956 ./prep_dataset/ILSVRC2012_val_00018320.bin 224 224 +46957 ./prep_dataset/ILSVRC2012_val_00022978.bin 224 224 +46958 ./prep_dataset/ILSVRC2012_val_00003032.bin 224 224 +46959 ./prep_dataset/ILSVRC2012_val_00023200.bin 224 224 +46960 ./prep_dataset/ILSVRC2012_val_00028097.bin 224 224 +46961 ./prep_dataset/ILSVRC2012_val_00014806.bin 224 224 +46962 ./prep_dataset/ILSVRC2012_val_00040118.bin 224 224 +46963 ./prep_dataset/ILSVRC2012_val_00006086.bin 224 224 +46964 ./prep_dataset/ILSVRC2012_val_00044478.bin 224 224 +46965 ./prep_dataset/ILSVRC2012_val_00025482.bin 224 224 +46966 ./prep_dataset/ILSVRC2012_val_00032974.bin 224 224 +46967 ./prep_dataset/ILSVRC2012_val_00013618.bin 224 224 +46968 ./prep_dataset/ILSVRC2012_val_00024792.bin 224 224 +46969 ./prep_dataset/ILSVRC2012_val_00032509.bin 224 224 +46970 ./prep_dataset/ILSVRC2012_val_00010494.bin 224 224 +46971 ./prep_dataset/ILSVRC2012_val_00007691.bin 224 224 +46972 ./prep_dataset/ILSVRC2012_val_00036812.bin 224 224 +46973 ./prep_dataset/ILSVRC2012_val_00028247.bin 224 224 +46974 ./prep_dataset/ILSVRC2012_val_00011351.bin 224 224 +46975 ./prep_dataset/ILSVRC2012_val_00048278.bin 224 224 +46976 ./prep_dataset/ILSVRC2012_val_00019941.bin 224 224 +46977 ./prep_dataset/ILSVRC2012_val_00033556.bin 224 224 +46978 ./prep_dataset/ILSVRC2012_val_00037630.bin 224 224 +46979 ./prep_dataset/ILSVRC2012_val_00038539.bin 224 224 +46980 ./prep_dataset/ILSVRC2012_val_00004436.bin 224 224 +46981 ./prep_dataset/ILSVRC2012_val_00044241.bin 224 224 +46982 ./prep_dataset/ILSVRC2012_val_00024650.bin 224 224 +46983 ./prep_dataset/ILSVRC2012_val_00047389.bin 224 224 +46984 ./prep_dataset/ILSVRC2012_val_00032611.bin 224 224 +46985 ./prep_dataset/ILSVRC2012_val_00037395.bin 224 224 +46986 ./prep_dataset/ILSVRC2012_val_00044572.bin 224 224 +46987 ./prep_dataset/ILSVRC2012_val_00046567.bin 224 224 +46988 ./prep_dataset/ILSVRC2012_val_00047092.bin 224 224 +46989 ./prep_dataset/ILSVRC2012_val_00006828.bin 224 224 +46990 ./prep_dataset/ILSVRC2012_val_00020366.bin 224 224 +46991 ./prep_dataset/ILSVRC2012_val_00001523.bin 224 224 +46992 ./prep_dataset/ILSVRC2012_val_00013895.bin 224 224 +46993 ./prep_dataset/ILSVRC2012_val_00011508.bin 224 224 +46994 ./prep_dataset/ILSVRC2012_val_00049425.bin 224 224 +46995 ./prep_dataset/ILSVRC2012_val_00022847.bin 224 224 +46996 ./prep_dataset/ILSVRC2012_val_00012247.bin 224 224 +46997 ./prep_dataset/ILSVRC2012_val_00037632.bin 224 224 +46998 ./prep_dataset/ILSVRC2012_val_00042311.bin 224 224 +46999 ./prep_dataset/ILSVRC2012_val_00007715.bin 224 224 +47000 ./prep_dataset/ILSVRC2012_val_00040525.bin 224 224 +47001 ./prep_dataset/ILSVRC2012_val_00020551.bin 224 224 +47002 ./prep_dataset/ILSVRC2012_val_00040617.bin 224 224 +47003 ./prep_dataset/ILSVRC2012_val_00019958.bin 224 224 +47004 ./prep_dataset/ILSVRC2012_val_00009871.bin 224 224 +47005 ./prep_dataset/ILSVRC2012_val_00008071.bin 224 224 +47006 ./prep_dataset/ILSVRC2012_val_00023941.bin 224 224 +47007 ./prep_dataset/ILSVRC2012_val_00040362.bin 224 224 +47008 ./prep_dataset/ILSVRC2012_val_00020644.bin 224 224 +47009 ./prep_dataset/ILSVRC2012_val_00000882.bin 224 224 +47010 ./prep_dataset/ILSVRC2012_val_00014081.bin 224 224 +47011 ./prep_dataset/ILSVRC2012_val_00023392.bin 224 224 +47012 ./prep_dataset/ILSVRC2012_val_00042241.bin 224 224 +47013 ./prep_dataset/ILSVRC2012_val_00007698.bin 224 224 +47014 ./prep_dataset/ILSVRC2012_val_00010397.bin 224 224 +47015 ./prep_dataset/ILSVRC2012_val_00008560.bin 224 224 +47016 ./prep_dataset/ILSVRC2012_val_00039446.bin 224 224 +47017 ./prep_dataset/ILSVRC2012_val_00026470.bin 224 224 +47018 ./prep_dataset/ILSVRC2012_val_00014172.bin 224 224 +47019 ./prep_dataset/ILSVRC2012_val_00032118.bin 224 224 +47020 ./prep_dataset/ILSVRC2012_val_00041425.bin 224 224 +47021 ./prep_dataset/ILSVRC2012_val_00025187.bin 224 224 +47022 ./prep_dataset/ILSVRC2012_val_00001236.bin 224 224 +47023 ./prep_dataset/ILSVRC2012_val_00028578.bin 224 224 +47024 ./prep_dataset/ILSVRC2012_val_00047996.bin 224 224 +47025 ./prep_dataset/ILSVRC2012_val_00030527.bin 224 224 +47026 ./prep_dataset/ILSVRC2012_val_00041833.bin 224 224 +47027 ./prep_dataset/ILSVRC2012_val_00016620.bin 224 224 +47028 ./prep_dataset/ILSVRC2012_val_00046622.bin 224 224 +47029 ./prep_dataset/ILSVRC2012_val_00022486.bin 224 224 +47030 ./prep_dataset/ILSVRC2012_val_00047906.bin 224 224 +47031 ./prep_dataset/ILSVRC2012_val_00003298.bin 224 224 +47032 ./prep_dataset/ILSVRC2012_val_00018446.bin 224 224 +47033 ./prep_dataset/ILSVRC2012_val_00012021.bin 224 224 +47034 ./prep_dataset/ILSVRC2012_val_00003322.bin 224 224 +47035 ./prep_dataset/ILSVRC2012_val_00012191.bin 224 224 +47036 ./prep_dataset/ILSVRC2012_val_00012372.bin 224 224 +47037 ./prep_dataset/ILSVRC2012_val_00006859.bin 224 224 +47038 ./prep_dataset/ILSVRC2012_val_00020254.bin 224 224 +47039 ./prep_dataset/ILSVRC2012_val_00002886.bin 224 224 +47040 ./prep_dataset/ILSVRC2012_val_00023548.bin 224 224 +47041 ./prep_dataset/ILSVRC2012_val_00028508.bin 224 224 +47042 ./prep_dataset/ILSVRC2012_val_00033106.bin 224 224 +47043 ./prep_dataset/ILSVRC2012_val_00003134.bin 224 224 +47044 ./prep_dataset/ILSVRC2012_val_00010266.bin 224 224 +47045 ./prep_dataset/ILSVRC2012_val_00037432.bin 224 224 +47046 ./prep_dataset/ILSVRC2012_val_00006608.bin 224 224 +47047 ./prep_dataset/ILSVRC2012_val_00020447.bin 224 224 +47048 ./prep_dataset/ILSVRC2012_val_00019870.bin 224 224 +47049 ./prep_dataset/ILSVRC2012_val_00023512.bin 224 224 +47050 ./prep_dataset/ILSVRC2012_val_00030746.bin 224 224 +47051 ./prep_dataset/ILSVRC2012_val_00011802.bin 224 224 +47052 ./prep_dataset/ILSVRC2012_val_00038034.bin 224 224 +47053 ./prep_dataset/ILSVRC2012_val_00007719.bin 224 224 +47054 ./prep_dataset/ILSVRC2012_val_00001308.bin 224 224 +47055 ./prep_dataset/ILSVRC2012_val_00049139.bin 224 224 +47056 ./prep_dataset/ILSVRC2012_val_00000117.bin 224 224 +47057 ./prep_dataset/ILSVRC2012_val_00033383.bin 224 224 +47058 ./prep_dataset/ILSVRC2012_val_00014083.bin 224 224 +47059 ./prep_dataset/ILSVRC2012_val_00044766.bin 224 224 +47060 ./prep_dataset/ILSVRC2012_val_00005507.bin 224 224 +47061 ./prep_dataset/ILSVRC2012_val_00036315.bin 224 224 +47062 ./prep_dataset/ILSVRC2012_val_00026020.bin 224 224 +47063 ./prep_dataset/ILSVRC2012_val_00016518.bin 224 224 +47064 ./prep_dataset/ILSVRC2012_val_00040372.bin 224 224 +47065 ./prep_dataset/ILSVRC2012_val_00012958.bin 224 224 +47066 ./prep_dataset/ILSVRC2012_val_00038787.bin 224 224 +47067 ./prep_dataset/ILSVRC2012_val_00043432.bin 224 224 +47068 ./prep_dataset/ILSVRC2012_val_00032447.bin 224 224 +47069 ./prep_dataset/ILSVRC2012_val_00000491.bin 224 224 +47070 ./prep_dataset/ILSVRC2012_val_00014470.bin 224 224 +47071 ./prep_dataset/ILSVRC2012_val_00030955.bin 224 224 +47072 ./prep_dataset/ILSVRC2012_val_00036058.bin 224 224 +47073 ./prep_dataset/ILSVRC2012_val_00024288.bin 224 224 +47074 ./prep_dataset/ILSVRC2012_val_00010874.bin 224 224 +47075 ./prep_dataset/ILSVRC2012_val_00006253.bin 224 224 +47076 ./prep_dataset/ILSVRC2012_val_00017778.bin 224 224 +47077 ./prep_dataset/ILSVRC2012_val_00029657.bin 224 224 +47078 ./prep_dataset/ILSVRC2012_val_00030574.bin 224 224 +47079 ./prep_dataset/ILSVRC2012_val_00041652.bin 224 224 +47080 ./prep_dataset/ILSVRC2012_val_00040227.bin 224 224 +47081 ./prep_dataset/ILSVRC2012_val_00031128.bin 224 224 +47082 ./prep_dataset/ILSVRC2012_val_00009101.bin 224 224 +47083 ./prep_dataset/ILSVRC2012_val_00012913.bin 224 224 +47084 ./prep_dataset/ILSVRC2012_val_00040652.bin 224 224 +47085 ./prep_dataset/ILSVRC2012_val_00024767.bin 224 224 +47086 ./prep_dataset/ILSVRC2012_val_00042530.bin 224 224 +47087 ./prep_dataset/ILSVRC2012_val_00045169.bin 224 224 +47088 ./prep_dataset/ILSVRC2012_val_00003231.bin 224 224 +47089 ./prep_dataset/ILSVRC2012_val_00031213.bin 224 224 +47090 ./prep_dataset/ILSVRC2012_val_00031299.bin 224 224 +47091 ./prep_dataset/ILSVRC2012_val_00019634.bin 224 224 +47092 ./prep_dataset/ILSVRC2012_val_00027647.bin 224 224 +47093 ./prep_dataset/ILSVRC2012_val_00049563.bin 224 224 +47094 ./prep_dataset/ILSVRC2012_val_00007442.bin 224 224 +47095 ./prep_dataset/ILSVRC2012_val_00028003.bin 224 224 +47096 ./prep_dataset/ILSVRC2012_val_00043381.bin 224 224 +47097 ./prep_dataset/ILSVRC2012_val_00013243.bin 224 224 +47098 ./prep_dataset/ILSVRC2012_val_00007422.bin 224 224 +47099 ./prep_dataset/ILSVRC2012_val_00000796.bin 224 224 +47100 ./prep_dataset/ILSVRC2012_val_00023264.bin 224 224 +47101 ./prep_dataset/ILSVRC2012_val_00021453.bin 224 224 +47102 ./prep_dataset/ILSVRC2012_val_00015100.bin 224 224 +47103 ./prep_dataset/ILSVRC2012_val_00028113.bin 224 224 +47104 ./prep_dataset/ILSVRC2012_val_00018700.bin 224 224 +47105 ./prep_dataset/ILSVRC2012_val_00035629.bin 224 224 +47106 ./prep_dataset/ILSVRC2012_val_00048149.bin 224 224 +47107 ./prep_dataset/ILSVRC2012_val_00007243.bin 224 224 +47108 ./prep_dataset/ILSVRC2012_val_00032783.bin 224 224 +47109 ./prep_dataset/ILSVRC2012_val_00025501.bin 224 224 +47110 ./prep_dataset/ILSVRC2012_val_00026271.bin 224 224 +47111 ./prep_dataset/ILSVRC2012_val_00008916.bin 224 224 +47112 ./prep_dataset/ILSVRC2012_val_00025515.bin 224 224 +47113 ./prep_dataset/ILSVRC2012_val_00040042.bin 224 224 +47114 ./prep_dataset/ILSVRC2012_val_00008238.bin 224 224 +47115 ./prep_dataset/ILSVRC2012_val_00010526.bin 224 224 +47116 ./prep_dataset/ILSVRC2012_val_00029545.bin 224 224 +47117 ./prep_dataset/ILSVRC2012_val_00005895.bin 224 224 +47118 ./prep_dataset/ILSVRC2012_val_00021818.bin 224 224 +47119 ./prep_dataset/ILSVRC2012_val_00003886.bin 224 224 +47120 ./prep_dataset/ILSVRC2012_val_00027567.bin 224 224 +47121 ./prep_dataset/ILSVRC2012_val_00040446.bin 224 224 +47122 ./prep_dataset/ILSVRC2012_val_00024851.bin 224 224 +47123 ./prep_dataset/ILSVRC2012_val_00001340.bin 224 224 +47124 ./prep_dataset/ILSVRC2012_val_00022432.bin 224 224 +47125 ./prep_dataset/ILSVRC2012_val_00019042.bin 224 224 +47126 ./prep_dataset/ILSVRC2012_val_00048619.bin 224 224 +47127 ./prep_dataset/ILSVRC2012_val_00010114.bin 224 224 +47128 ./prep_dataset/ILSVRC2012_val_00036024.bin 224 224 +47129 ./prep_dataset/ILSVRC2012_val_00029467.bin 224 224 +47130 ./prep_dataset/ILSVRC2012_val_00021152.bin 224 224 +47131 ./prep_dataset/ILSVRC2012_val_00006149.bin 224 224 +47132 ./prep_dataset/ILSVRC2012_val_00020823.bin 224 224 +47133 ./prep_dataset/ILSVRC2012_val_00004228.bin 224 224 +47134 ./prep_dataset/ILSVRC2012_val_00024842.bin 224 224 +47135 ./prep_dataset/ILSVRC2012_val_00004205.bin 224 224 +47136 ./prep_dataset/ILSVRC2012_val_00022253.bin 224 224 +47137 ./prep_dataset/ILSVRC2012_val_00013910.bin 224 224 +47138 ./prep_dataset/ILSVRC2012_val_00013038.bin 224 224 +47139 ./prep_dataset/ILSVRC2012_val_00031295.bin 224 224 +47140 ./prep_dataset/ILSVRC2012_val_00041800.bin 224 224 +47141 ./prep_dataset/ILSVRC2012_val_00027029.bin 224 224 +47142 ./prep_dataset/ILSVRC2012_val_00003993.bin 224 224 +47143 ./prep_dataset/ILSVRC2012_val_00030052.bin 224 224 +47144 ./prep_dataset/ILSVRC2012_val_00049193.bin 224 224 +47145 ./prep_dataset/ILSVRC2012_val_00013903.bin 224 224 +47146 ./prep_dataset/ILSVRC2012_val_00012461.bin 224 224 +47147 ./prep_dataset/ILSVRC2012_val_00042625.bin 224 224 +47148 ./prep_dataset/ILSVRC2012_val_00012596.bin 224 224 +47149 ./prep_dataset/ILSVRC2012_val_00016505.bin 224 224 +47150 ./prep_dataset/ILSVRC2012_val_00029178.bin 224 224 +47151 ./prep_dataset/ILSVRC2012_val_00003518.bin 224 224 +47152 ./prep_dataset/ILSVRC2012_val_00034229.bin 224 224 +47153 ./prep_dataset/ILSVRC2012_val_00034773.bin 224 224 +47154 ./prep_dataset/ILSVRC2012_val_00049882.bin 224 224 +47155 ./prep_dataset/ILSVRC2012_val_00019603.bin 224 224 +47156 ./prep_dataset/ILSVRC2012_val_00039092.bin 224 224 +47157 ./prep_dataset/ILSVRC2012_val_00036611.bin 224 224 +47158 ./prep_dataset/ILSVRC2012_val_00010131.bin 224 224 +47159 ./prep_dataset/ILSVRC2012_val_00018899.bin 224 224 +47160 ./prep_dataset/ILSVRC2012_val_00046461.bin 224 224 +47161 ./prep_dataset/ILSVRC2012_val_00035078.bin 224 224 +47162 ./prep_dataset/ILSVRC2012_val_00000066.bin 224 224 +47163 ./prep_dataset/ILSVRC2012_val_00028332.bin 224 224 +47164 ./prep_dataset/ILSVRC2012_val_00011675.bin 224 224 +47165 ./prep_dataset/ILSVRC2012_val_00022944.bin 224 224 +47166 ./prep_dataset/ILSVRC2012_val_00002144.bin 224 224 +47167 ./prep_dataset/ILSVRC2012_val_00009564.bin 224 224 +47168 ./prep_dataset/ILSVRC2012_val_00019502.bin 224 224 +47169 ./prep_dataset/ILSVRC2012_val_00027501.bin 224 224 +47170 ./prep_dataset/ILSVRC2012_val_00044534.bin 224 224 +47171 ./prep_dataset/ILSVRC2012_val_00011629.bin 224 224 +47172 ./prep_dataset/ILSVRC2012_val_00007806.bin 224 224 +47173 ./prep_dataset/ILSVRC2012_val_00002716.bin 224 224 +47174 ./prep_dataset/ILSVRC2012_val_00037086.bin 224 224 +47175 ./prep_dataset/ILSVRC2012_val_00040742.bin 224 224 +47176 ./prep_dataset/ILSVRC2012_val_00004601.bin 224 224 +47177 ./prep_dataset/ILSVRC2012_val_00042031.bin 224 224 +47178 ./prep_dataset/ILSVRC2012_val_00031043.bin 224 224 +47179 ./prep_dataset/ILSVRC2012_val_00005370.bin 224 224 +47180 ./prep_dataset/ILSVRC2012_val_00038266.bin 224 224 +47181 ./prep_dataset/ILSVRC2012_val_00000297.bin 224 224 +47182 ./prep_dataset/ILSVRC2012_val_00039396.bin 224 224 +47183 ./prep_dataset/ILSVRC2012_val_00035756.bin 224 224 +47184 ./prep_dataset/ILSVRC2012_val_00035092.bin 224 224 +47185 ./prep_dataset/ILSVRC2012_val_00046170.bin 224 224 +47186 ./prep_dataset/ILSVRC2012_val_00015275.bin 224 224 +47187 ./prep_dataset/ILSVRC2012_val_00011650.bin 224 224 +47188 ./prep_dataset/ILSVRC2012_val_00010901.bin 224 224 +47189 ./prep_dataset/ILSVRC2012_val_00016302.bin 224 224 +47190 ./prep_dataset/ILSVRC2012_val_00019639.bin 224 224 +47191 ./prep_dataset/ILSVRC2012_val_00007593.bin 224 224 +47192 ./prep_dataset/ILSVRC2012_val_00017211.bin 224 224 +47193 ./prep_dataset/ILSVRC2012_val_00035346.bin 224 224 +47194 ./prep_dataset/ILSVRC2012_val_00017720.bin 224 224 +47195 ./prep_dataset/ILSVRC2012_val_00043494.bin 224 224 +47196 ./prep_dataset/ILSVRC2012_val_00049880.bin 224 224 +47197 ./prep_dataset/ILSVRC2012_val_00001701.bin 224 224 +47198 ./prep_dataset/ILSVRC2012_val_00022517.bin 224 224 +47199 ./prep_dataset/ILSVRC2012_val_00039070.bin 224 224 +47200 ./prep_dataset/ILSVRC2012_val_00012658.bin 224 224 +47201 ./prep_dataset/ILSVRC2012_val_00049132.bin 224 224 +47202 ./prep_dataset/ILSVRC2012_val_00001294.bin 224 224 +47203 ./prep_dataset/ILSVRC2012_val_00008616.bin 224 224 +47204 ./prep_dataset/ILSVRC2012_val_00034651.bin 224 224 +47205 ./prep_dataset/ILSVRC2012_val_00011636.bin 224 224 +47206 ./prep_dataset/ILSVRC2012_val_00009649.bin 224 224 +47207 ./prep_dataset/ILSVRC2012_val_00003126.bin 224 224 +47208 ./prep_dataset/ILSVRC2012_val_00022045.bin 224 224 +47209 ./prep_dataset/ILSVRC2012_val_00017208.bin 224 224 +47210 ./prep_dataset/ILSVRC2012_val_00039300.bin 224 224 +47211 ./prep_dataset/ILSVRC2012_val_00015952.bin 224 224 +47212 ./prep_dataset/ILSVRC2012_val_00026468.bin 224 224 +47213 ./prep_dataset/ILSVRC2012_val_00014555.bin 224 224 +47214 ./prep_dataset/ILSVRC2012_val_00038929.bin 224 224 +47215 ./prep_dataset/ILSVRC2012_val_00040093.bin 224 224 +47216 ./prep_dataset/ILSVRC2012_val_00028807.bin 224 224 +47217 ./prep_dataset/ILSVRC2012_val_00039470.bin 224 224 +47218 ./prep_dataset/ILSVRC2012_val_00049234.bin 224 224 +47219 ./prep_dataset/ILSVRC2012_val_00015553.bin 224 224 +47220 ./prep_dataset/ILSVRC2012_val_00023939.bin 224 224 +47221 ./prep_dataset/ILSVRC2012_val_00016397.bin 224 224 +47222 ./prep_dataset/ILSVRC2012_val_00038639.bin 224 224 +47223 ./prep_dataset/ILSVRC2012_val_00004960.bin 224 224 +47224 ./prep_dataset/ILSVRC2012_val_00025279.bin 224 224 +47225 ./prep_dataset/ILSVRC2012_val_00031976.bin 224 224 +47226 ./prep_dataset/ILSVRC2012_val_00030088.bin 224 224 +47227 ./prep_dataset/ILSVRC2012_val_00022101.bin 224 224 +47228 ./prep_dataset/ILSVRC2012_val_00036512.bin 224 224 +47229 ./prep_dataset/ILSVRC2012_val_00021334.bin 224 224 +47230 ./prep_dataset/ILSVRC2012_val_00006550.bin 224 224 +47231 ./prep_dataset/ILSVRC2012_val_00017057.bin 224 224 +47232 ./prep_dataset/ILSVRC2012_val_00004551.bin 224 224 +47233 ./prep_dataset/ILSVRC2012_val_00025600.bin 224 224 +47234 ./prep_dataset/ILSVRC2012_val_00035884.bin 224 224 +47235 ./prep_dataset/ILSVRC2012_val_00040855.bin 224 224 +47236 ./prep_dataset/ILSVRC2012_val_00010044.bin 224 224 +47237 ./prep_dataset/ILSVRC2012_val_00011862.bin 224 224 +47238 ./prep_dataset/ILSVRC2012_val_00015404.bin 224 224 +47239 ./prep_dataset/ILSVRC2012_val_00028305.bin 224 224 +47240 ./prep_dataset/ILSVRC2012_val_00014209.bin 224 224 +47241 ./prep_dataset/ILSVRC2012_val_00020750.bin 224 224 +47242 ./prep_dataset/ILSVRC2012_val_00008698.bin 224 224 +47243 ./prep_dataset/ILSVRC2012_val_00026883.bin 224 224 +47244 ./prep_dataset/ILSVRC2012_val_00001914.bin 224 224 +47245 ./prep_dataset/ILSVRC2012_val_00037211.bin 224 224 +47246 ./prep_dataset/ILSVRC2012_val_00012788.bin 224 224 +47247 ./prep_dataset/ILSVRC2012_val_00020563.bin 224 224 +47248 ./prep_dataset/ILSVRC2012_val_00049042.bin 224 224 +47249 ./prep_dataset/ILSVRC2012_val_00009647.bin 224 224 +47250 ./prep_dataset/ILSVRC2012_val_00040683.bin 224 224 +47251 ./prep_dataset/ILSVRC2012_val_00039134.bin 224 224 +47252 ./prep_dataset/ILSVRC2012_val_00030410.bin 224 224 +47253 ./prep_dataset/ILSVRC2012_val_00036858.bin 224 224 +47254 ./prep_dataset/ILSVRC2012_val_00001200.bin 224 224 +47255 ./prep_dataset/ILSVRC2012_val_00003279.bin 224 224 +47256 ./prep_dataset/ILSVRC2012_val_00020012.bin 224 224 +47257 ./prep_dataset/ILSVRC2012_val_00040697.bin 224 224 +47258 ./prep_dataset/ILSVRC2012_val_00015688.bin 224 224 +47259 ./prep_dataset/ILSVRC2012_val_00013898.bin 224 224 +47260 ./prep_dataset/ILSVRC2012_val_00006857.bin 224 224 +47261 ./prep_dataset/ILSVRC2012_val_00025463.bin 224 224 +47262 ./prep_dataset/ILSVRC2012_val_00009598.bin 224 224 +47263 ./prep_dataset/ILSVRC2012_val_00001367.bin 224 224 +47264 ./prep_dataset/ILSVRC2012_val_00015003.bin 224 224 +47265 ./prep_dataset/ILSVRC2012_val_00016201.bin 224 224 +47266 ./prep_dataset/ILSVRC2012_val_00032155.bin 224 224 +47267 ./prep_dataset/ILSVRC2012_val_00032039.bin 224 224 +47268 ./prep_dataset/ILSVRC2012_val_00020103.bin 224 224 +47269 ./prep_dataset/ILSVRC2012_val_00028712.bin 224 224 +47270 ./prep_dataset/ILSVRC2012_val_00012450.bin 224 224 +47271 ./prep_dataset/ILSVRC2012_val_00005047.bin 224 224 +47272 ./prep_dataset/ILSVRC2012_val_00030255.bin 224 224 +47273 ./prep_dataset/ILSVRC2012_val_00040425.bin 224 224 +47274 ./prep_dataset/ILSVRC2012_val_00041227.bin 224 224 +47275 ./prep_dataset/ILSVRC2012_val_00034596.bin 224 224 +47276 ./prep_dataset/ILSVRC2012_val_00048943.bin 224 224 +47277 ./prep_dataset/ILSVRC2012_val_00046848.bin 224 224 +47278 ./prep_dataset/ILSVRC2012_val_00023217.bin 224 224 +47279 ./prep_dataset/ILSVRC2012_val_00001804.bin 224 224 +47280 ./prep_dataset/ILSVRC2012_val_00009948.bin 224 224 +47281 ./prep_dataset/ILSVRC2012_val_00010218.bin 224 224 +47282 ./prep_dataset/ILSVRC2012_val_00020266.bin 224 224 +47283 ./prep_dataset/ILSVRC2012_val_00046760.bin 224 224 +47284 ./prep_dataset/ILSVRC2012_val_00039142.bin 224 224 +47285 ./prep_dataset/ILSVRC2012_val_00016493.bin 224 224 +47286 ./prep_dataset/ILSVRC2012_val_00016194.bin 224 224 +47287 ./prep_dataset/ILSVRC2012_val_00008232.bin 224 224 +47288 ./prep_dataset/ILSVRC2012_val_00017833.bin 224 224 +47289 ./prep_dataset/ILSVRC2012_val_00048096.bin 224 224 +47290 ./prep_dataset/ILSVRC2012_val_00034890.bin 224 224 +47291 ./prep_dataset/ILSVRC2012_val_00023544.bin 224 224 +47292 ./prep_dataset/ILSVRC2012_val_00023131.bin 224 224 +47293 ./prep_dataset/ILSVRC2012_val_00015297.bin 224 224 +47294 ./prep_dataset/ILSVRC2012_val_00041327.bin 224 224 +47295 ./prep_dataset/ILSVRC2012_val_00048002.bin 224 224 +47296 ./prep_dataset/ILSVRC2012_val_00044565.bin 224 224 +47297 ./prep_dataset/ILSVRC2012_val_00013111.bin 224 224 +47298 ./prep_dataset/ILSVRC2012_val_00012251.bin 224 224 +47299 ./prep_dataset/ILSVRC2012_val_00014836.bin 224 224 +47300 ./prep_dataset/ILSVRC2012_val_00031081.bin 224 224 +47301 ./prep_dataset/ILSVRC2012_val_00036201.bin 224 224 +47302 ./prep_dataset/ILSVRC2012_val_00013833.bin 224 224 +47303 ./prep_dataset/ILSVRC2012_val_00011553.bin 224 224 +47304 ./prep_dataset/ILSVRC2012_val_00004068.bin 224 224 +47305 ./prep_dataset/ILSVRC2012_val_00006123.bin 224 224 +47306 ./prep_dataset/ILSVRC2012_val_00018671.bin 224 224 +47307 ./prep_dataset/ILSVRC2012_val_00002824.bin 224 224 +47308 ./prep_dataset/ILSVRC2012_val_00030311.bin 224 224 +47309 ./prep_dataset/ILSVRC2012_val_00014031.bin 224 224 +47310 ./prep_dataset/ILSVRC2012_val_00025289.bin 224 224 +47311 ./prep_dataset/ILSVRC2012_val_00038839.bin 224 224 +47312 ./prep_dataset/ILSVRC2012_val_00046635.bin 224 224 +47313 ./prep_dataset/ILSVRC2012_val_00031690.bin 224 224 +47314 ./prep_dataset/ILSVRC2012_val_00009231.bin 224 224 +47315 ./prep_dataset/ILSVRC2012_val_00026981.bin 224 224 +47316 ./prep_dataset/ILSVRC2012_val_00010256.bin 224 224 +47317 ./prep_dataset/ILSVRC2012_val_00020614.bin 224 224 +47318 ./prep_dataset/ILSVRC2012_val_00041389.bin 224 224 +47319 ./prep_dataset/ILSVRC2012_val_00026716.bin 224 224 +47320 ./prep_dataset/ILSVRC2012_val_00026830.bin 224 224 +47321 ./prep_dataset/ILSVRC2012_val_00025066.bin 224 224 +47322 ./prep_dataset/ILSVRC2012_val_00002309.bin 224 224 +47323 ./prep_dataset/ILSVRC2012_val_00011139.bin 224 224 +47324 ./prep_dataset/ILSVRC2012_val_00010872.bin 224 224 +47325 ./prep_dataset/ILSVRC2012_val_00015525.bin 224 224 +47326 ./prep_dataset/ILSVRC2012_val_00034468.bin 224 224 +47327 ./prep_dataset/ILSVRC2012_val_00035131.bin 224 224 +47328 ./prep_dataset/ILSVRC2012_val_00000571.bin 224 224 +47329 ./prep_dataset/ILSVRC2012_val_00012667.bin 224 224 +47330 ./prep_dataset/ILSVRC2012_val_00048239.bin 224 224 +47331 ./prep_dataset/ILSVRC2012_val_00015653.bin 224 224 +47332 ./prep_dataset/ILSVRC2012_val_00044322.bin 224 224 +47333 ./prep_dataset/ILSVRC2012_val_00046111.bin 224 224 +47334 ./prep_dataset/ILSVRC2012_val_00028284.bin 224 224 +47335 ./prep_dataset/ILSVRC2012_val_00000019.bin 224 224 +47336 ./prep_dataset/ILSVRC2012_val_00000138.bin 224 224 +47337 ./prep_dataset/ILSVRC2012_val_00035892.bin 224 224 +47338 ./prep_dataset/ILSVRC2012_val_00001431.bin 224 224 +47339 ./prep_dataset/ILSVRC2012_val_00038347.bin 224 224 +47340 ./prep_dataset/ILSVRC2012_val_00047190.bin 224 224 +47341 ./prep_dataset/ILSVRC2012_val_00018146.bin 224 224 +47342 ./prep_dataset/ILSVRC2012_val_00042187.bin 224 224 +47343 ./prep_dataset/ILSVRC2012_val_00009923.bin 224 224 +47344 ./prep_dataset/ILSVRC2012_val_00031941.bin 224 224 +47345 ./prep_dataset/ILSVRC2012_val_00000879.bin 224 224 +47346 ./prep_dataset/ILSVRC2012_val_00012322.bin 224 224 +47347 ./prep_dataset/ILSVRC2012_val_00036674.bin 224 224 +47348 ./prep_dataset/ILSVRC2012_val_00035085.bin 224 224 +47349 ./prep_dataset/ILSVRC2012_val_00013630.bin 224 224 +47350 ./prep_dataset/ILSVRC2012_val_00049143.bin 224 224 +47351 ./prep_dataset/ILSVRC2012_val_00004170.bin 224 224 +47352 ./prep_dataset/ILSVRC2012_val_00015735.bin 224 224 +47353 ./prep_dataset/ILSVRC2012_val_00028903.bin 224 224 +47354 ./prep_dataset/ILSVRC2012_val_00029474.bin 224 224 +47355 ./prep_dataset/ILSVRC2012_val_00021190.bin 224 224 +47356 ./prep_dataset/ILSVRC2012_val_00012483.bin 224 224 +47357 ./prep_dataset/ILSVRC2012_val_00044595.bin 224 224 +47358 ./prep_dataset/ILSVRC2012_val_00004840.bin 224 224 +47359 ./prep_dataset/ILSVRC2012_val_00005432.bin 224 224 +47360 ./prep_dataset/ILSVRC2012_val_00048328.bin 224 224 +47361 ./prep_dataset/ILSVRC2012_val_00039953.bin 224 224 +47362 ./prep_dataset/ILSVRC2012_val_00006536.bin 224 224 +47363 ./prep_dataset/ILSVRC2012_val_00039721.bin 224 224 +47364 ./prep_dataset/ILSVRC2012_val_00033712.bin 224 224 +47365 ./prep_dataset/ILSVRC2012_val_00017509.bin 224 224 +47366 ./prep_dataset/ILSVRC2012_val_00027469.bin 224 224 +47367 ./prep_dataset/ILSVRC2012_val_00024366.bin 224 224 +47368 ./prep_dataset/ILSVRC2012_val_00037344.bin 224 224 +47369 ./prep_dataset/ILSVRC2012_val_00044492.bin 224 224 +47370 ./prep_dataset/ILSVRC2012_val_00029146.bin 224 224 +47371 ./prep_dataset/ILSVRC2012_val_00049767.bin 224 224 +47372 ./prep_dataset/ILSVRC2012_val_00031168.bin 224 224 +47373 ./prep_dataset/ILSVRC2012_val_00007559.bin 224 224 +47374 ./prep_dataset/ILSVRC2012_val_00011382.bin 224 224 +47375 ./prep_dataset/ILSVRC2012_val_00009487.bin 224 224 +47376 ./prep_dataset/ILSVRC2012_val_00039802.bin 224 224 +47377 ./prep_dataset/ILSVRC2012_val_00028604.bin 224 224 +47378 ./prep_dataset/ILSVRC2012_val_00029508.bin 224 224 +47379 ./prep_dataset/ILSVRC2012_val_00005694.bin 224 224 +47380 ./prep_dataset/ILSVRC2012_val_00043862.bin 224 224 +47381 ./prep_dataset/ILSVRC2012_val_00031811.bin 224 224 +47382 ./prep_dataset/ILSVRC2012_val_00043217.bin 224 224 +47383 ./prep_dataset/ILSVRC2012_val_00028733.bin 224 224 +47384 ./prep_dataset/ILSVRC2012_val_00000429.bin 224 224 +47385 ./prep_dataset/ILSVRC2012_val_00009394.bin 224 224 +47386 ./prep_dataset/ILSVRC2012_val_00022325.bin 224 224 +47387 ./prep_dataset/ILSVRC2012_val_00004009.bin 224 224 +47388 ./prep_dataset/ILSVRC2012_val_00004646.bin 224 224 +47389 ./prep_dataset/ILSVRC2012_val_00005544.bin 224 224 +47390 ./prep_dataset/ILSVRC2012_val_00026361.bin 224 224 +47391 ./prep_dataset/ILSVRC2012_val_00027072.bin 224 224 +47392 ./prep_dataset/ILSVRC2012_val_00021538.bin 224 224 +47393 ./prep_dataset/ILSVRC2012_val_00019689.bin 224 224 +47394 ./prep_dataset/ILSVRC2012_val_00031222.bin 224 224 +47395 ./prep_dataset/ILSVRC2012_val_00031038.bin 224 224 +47396 ./prep_dataset/ILSVRC2012_val_00011995.bin 224 224 +47397 ./prep_dataset/ILSVRC2012_val_00015505.bin 224 224 +47398 ./prep_dataset/ILSVRC2012_val_00018946.bin 224 224 +47399 ./prep_dataset/ILSVRC2012_val_00001296.bin 224 224 +47400 ./prep_dataset/ILSVRC2012_val_00011220.bin 224 224 +47401 ./prep_dataset/ILSVRC2012_val_00006481.bin 224 224 +47402 ./prep_dataset/ILSVRC2012_val_00032888.bin 224 224 +47403 ./prep_dataset/ILSVRC2012_val_00018922.bin 224 224 +47404 ./prep_dataset/ILSVRC2012_val_00041305.bin 224 224 +47405 ./prep_dataset/ILSVRC2012_val_00025481.bin 224 224 +47406 ./prep_dataset/ILSVRC2012_val_00028317.bin 224 224 +47407 ./prep_dataset/ILSVRC2012_val_00024715.bin 224 224 +47408 ./prep_dataset/ILSVRC2012_val_00026563.bin 224 224 +47409 ./prep_dataset/ILSVRC2012_val_00013485.bin 224 224 +47410 ./prep_dataset/ILSVRC2012_val_00049247.bin 224 224 +47411 ./prep_dataset/ILSVRC2012_val_00029941.bin 224 224 +47412 ./prep_dataset/ILSVRC2012_val_00039511.bin 224 224 +47413 ./prep_dataset/ILSVRC2012_val_00002238.bin 224 224 +47414 ./prep_dataset/ILSVRC2012_val_00000276.bin 224 224 +47415 ./prep_dataset/ILSVRC2012_val_00017602.bin 224 224 +47416 ./prep_dataset/ILSVRC2012_val_00031434.bin 224 224 +47417 ./prep_dataset/ILSVRC2012_val_00033921.bin 224 224 +47418 ./prep_dataset/ILSVRC2012_val_00009937.bin 224 224 +47419 ./prep_dataset/ILSVRC2012_val_00027421.bin 224 224 +47420 ./prep_dataset/ILSVRC2012_val_00040853.bin 224 224 +47421 ./prep_dataset/ILSVRC2012_val_00036307.bin 224 224 +47422 ./prep_dataset/ILSVRC2012_val_00026191.bin 224 224 +47423 ./prep_dataset/ILSVRC2012_val_00039545.bin 224 224 +47424 ./prep_dataset/ILSVRC2012_val_00017674.bin 224 224 +47425 ./prep_dataset/ILSVRC2012_val_00045746.bin 224 224 +47426 ./prep_dataset/ILSVRC2012_val_00049205.bin 224 224 +47427 ./prep_dataset/ILSVRC2012_val_00030903.bin 224 224 +47428 ./prep_dataset/ILSVRC2012_val_00027257.bin 224 224 +47429 ./prep_dataset/ILSVRC2012_val_00020211.bin 224 224 +47430 ./prep_dataset/ILSVRC2012_val_00048869.bin 224 224 +47431 ./prep_dataset/ILSVRC2012_val_00018949.bin 224 224 +47432 ./prep_dataset/ILSVRC2012_val_00017167.bin 224 224 +47433 ./prep_dataset/ILSVRC2012_val_00036843.bin 224 224 +47434 ./prep_dataset/ILSVRC2012_val_00037609.bin 224 224 +47435 ./prep_dataset/ILSVRC2012_val_00017200.bin 224 224 +47436 ./prep_dataset/ILSVRC2012_val_00049024.bin 224 224 +47437 ./prep_dataset/ILSVRC2012_val_00008212.bin 224 224 +47438 ./prep_dataset/ILSVRC2012_val_00012471.bin 224 224 +47439 ./prep_dataset/ILSVRC2012_val_00017918.bin 224 224 +47440 ./prep_dataset/ILSVRC2012_val_00017306.bin 224 224 +47441 ./prep_dataset/ILSVRC2012_val_00025551.bin 224 224 +47442 ./prep_dataset/ILSVRC2012_val_00044167.bin 224 224 +47443 ./prep_dataset/ILSVRC2012_val_00029542.bin 224 224 +47444 ./prep_dataset/ILSVRC2012_val_00034109.bin 224 224 +47445 ./prep_dataset/ILSVRC2012_val_00013653.bin 224 224 +47446 ./prep_dataset/ILSVRC2012_val_00026743.bin 224 224 +47447 ./prep_dataset/ILSVRC2012_val_00046360.bin 224 224 +47448 ./prep_dataset/ILSVRC2012_val_00040876.bin 224 224 +47449 ./prep_dataset/ILSVRC2012_val_00003193.bin 224 224 +47450 ./prep_dataset/ILSVRC2012_val_00029678.bin 224 224 +47451 ./prep_dataset/ILSVRC2012_val_00015826.bin 224 224 +47452 ./prep_dataset/ILSVRC2012_val_00018522.bin 224 224 +47453 ./prep_dataset/ILSVRC2012_val_00045709.bin 224 224 +47454 ./prep_dataset/ILSVRC2012_val_00044651.bin 224 224 +47455 ./prep_dataset/ILSVRC2012_val_00004014.bin 224 224 +47456 ./prep_dataset/ILSVRC2012_val_00022169.bin 224 224 +47457 ./prep_dataset/ILSVRC2012_val_00011844.bin 224 224 +47458 ./prep_dataset/ILSVRC2012_val_00000749.bin 224 224 +47459 ./prep_dataset/ILSVRC2012_val_00006520.bin 224 224 +47460 ./prep_dataset/ILSVRC2012_val_00014247.bin 224 224 +47461 ./prep_dataset/ILSVRC2012_val_00026930.bin 224 224 +47462 ./prep_dataset/ILSVRC2012_val_00017690.bin 224 224 +47463 ./prep_dataset/ILSVRC2012_val_00011202.bin 224 224 +47464 ./prep_dataset/ILSVRC2012_val_00000804.bin 224 224 +47465 ./prep_dataset/ILSVRC2012_val_00031048.bin 224 224 +47466 ./prep_dataset/ILSVRC2012_val_00004211.bin 224 224 +47467 ./prep_dataset/ILSVRC2012_val_00036394.bin 224 224 +47468 ./prep_dataset/ILSVRC2012_val_00033608.bin 224 224 +47469 ./prep_dataset/ILSVRC2012_val_00002480.bin 224 224 +47470 ./prep_dataset/ILSVRC2012_val_00011416.bin 224 224 +47471 ./prep_dataset/ILSVRC2012_val_00018930.bin 224 224 +47472 ./prep_dataset/ILSVRC2012_val_00017837.bin 224 224 +47473 ./prep_dataset/ILSVRC2012_val_00034178.bin 224 224 +47474 ./prep_dataset/ILSVRC2012_val_00043122.bin 224 224 +47475 ./prep_dataset/ILSVRC2012_val_00022471.bin 224 224 +47476 ./prep_dataset/ILSVRC2012_val_00037710.bin 224 224 +47477 ./prep_dataset/ILSVRC2012_val_00048014.bin 224 224 +47478 ./prep_dataset/ILSVRC2012_val_00040920.bin 224 224 +47479 ./prep_dataset/ILSVRC2012_val_00033234.bin 224 224 +47480 ./prep_dataset/ILSVRC2012_val_00009087.bin 224 224 +47481 ./prep_dataset/ILSVRC2012_val_00024719.bin 224 224 +47482 ./prep_dataset/ILSVRC2012_val_00006722.bin 224 224 +47483 ./prep_dataset/ILSVRC2012_val_00033450.bin 224 224 +47484 ./prep_dataset/ILSVRC2012_val_00034793.bin 224 224 +47485 ./prep_dataset/ILSVRC2012_val_00020207.bin 224 224 +47486 ./prep_dataset/ILSVRC2012_val_00010873.bin 224 224 +47487 ./prep_dataset/ILSVRC2012_val_00028820.bin 224 224 +47488 ./prep_dataset/ILSVRC2012_val_00045040.bin 224 224 +47489 ./prep_dataset/ILSVRC2012_val_00006382.bin 224 224 +47490 ./prep_dataset/ILSVRC2012_val_00030443.bin 224 224 +47491 ./prep_dataset/ILSVRC2012_val_00036098.bin 224 224 +47492 ./prep_dataset/ILSVRC2012_val_00006708.bin 224 224 +47493 ./prep_dataset/ILSVRC2012_val_00041594.bin 224 224 +47494 ./prep_dataset/ILSVRC2012_val_00010122.bin 224 224 +47495 ./prep_dataset/ILSVRC2012_val_00019336.bin 224 224 +47496 ./prep_dataset/ILSVRC2012_val_00028988.bin 224 224 +47497 ./prep_dataset/ILSVRC2012_val_00022508.bin 224 224 +47498 ./prep_dataset/ILSVRC2012_val_00029133.bin 224 224 +47499 ./prep_dataset/ILSVRC2012_val_00017773.bin 224 224 +47500 ./prep_dataset/ILSVRC2012_val_00037966.bin 224 224 +47501 ./prep_dataset/ILSVRC2012_val_00036137.bin 224 224 +47502 ./prep_dataset/ILSVRC2012_val_00006713.bin 224 224 +47503 ./prep_dataset/ILSVRC2012_val_00004956.bin 224 224 +47504 ./prep_dataset/ILSVRC2012_val_00011903.bin 224 224 +47505 ./prep_dataset/ILSVRC2012_val_00014395.bin 224 224 +47506 ./prep_dataset/ILSVRC2012_val_00028763.bin 224 224 +47507 ./prep_dataset/ILSVRC2012_val_00049489.bin 224 224 +47508 ./prep_dataset/ILSVRC2012_val_00046604.bin 224 224 +47509 ./prep_dataset/ILSVRC2012_val_00006710.bin 224 224 +47510 ./prep_dataset/ILSVRC2012_val_00029500.bin 224 224 +47511 ./prep_dataset/ILSVRC2012_val_00043108.bin 224 224 +47512 ./prep_dataset/ILSVRC2012_val_00031467.bin 224 224 +47513 ./prep_dataset/ILSVRC2012_val_00002734.bin 224 224 +47514 ./prep_dataset/ILSVRC2012_val_00006287.bin 224 224 +47515 ./prep_dataset/ILSVRC2012_val_00019490.bin 224 224 +47516 ./prep_dataset/ILSVRC2012_val_00041015.bin 224 224 +47517 ./prep_dataset/ILSVRC2012_val_00033203.bin 224 224 +47518 ./prep_dataset/ILSVRC2012_val_00042092.bin 224 224 +47519 ./prep_dataset/ILSVRC2012_val_00017112.bin 224 224 +47520 ./prep_dataset/ILSVRC2012_val_00011403.bin 224 224 +47521 ./prep_dataset/ILSVRC2012_val_00014869.bin 224 224 +47522 ./prep_dataset/ILSVRC2012_val_00046309.bin 224 224 +47523 ./prep_dataset/ILSVRC2012_val_00025790.bin 224 224 +47524 ./prep_dataset/ILSVRC2012_val_00005023.bin 224 224 +47525 ./prep_dataset/ILSVRC2012_val_00046193.bin 224 224 +47526 ./prep_dataset/ILSVRC2012_val_00039244.bin 224 224 +47527 ./prep_dataset/ILSVRC2012_val_00029485.bin 224 224 +47528 ./prep_dataset/ILSVRC2012_val_00020361.bin 224 224 +47529 ./prep_dataset/ILSVRC2012_val_00036683.bin 224 224 +47530 ./prep_dataset/ILSVRC2012_val_00004115.bin 224 224 +47531 ./prep_dataset/ILSVRC2012_val_00021217.bin 224 224 +47532 ./prep_dataset/ILSVRC2012_val_00032067.bin 224 224 +47533 ./prep_dataset/ILSVRC2012_val_00033015.bin 224 224 +47534 ./prep_dataset/ILSVRC2012_val_00039243.bin 224 224 +47535 ./prep_dataset/ILSVRC2012_val_00038473.bin 224 224 +47536 ./prep_dataset/ILSVRC2012_val_00014940.bin 224 224 +47537 ./prep_dataset/ILSVRC2012_val_00001927.bin 224 224 +47538 ./prep_dataset/ILSVRC2012_val_00018342.bin 224 224 +47539 ./prep_dataset/ILSVRC2012_val_00029230.bin 224 224 +47540 ./prep_dataset/ILSVRC2012_val_00034424.bin 224 224 +47541 ./prep_dataset/ILSVRC2012_val_00043864.bin 224 224 +47542 ./prep_dataset/ILSVRC2012_val_00036204.bin 224 224 +47543 ./prep_dataset/ILSVRC2012_val_00027200.bin 224 224 +47544 ./prep_dataset/ILSVRC2012_val_00003301.bin 224 224 +47545 ./prep_dataset/ILSVRC2012_val_00029096.bin 224 224 +47546 ./prep_dataset/ILSVRC2012_val_00042418.bin 224 224 +47547 ./prep_dataset/ILSVRC2012_val_00035337.bin 224 224 +47548 ./prep_dataset/ILSVRC2012_val_00008709.bin 224 224 +47549 ./prep_dataset/ILSVRC2012_val_00011407.bin 224 224 +47550 ./prep_dataset/ILSVRC2012_val_00011824.bin 224 224 +47551 ./prep_dataset/ILSVRC2012_val_00008987.bin 224 224 +47552 ./prep_dataset/ILSVRC2012_val_00038624.bin 224 224 +47553 ./prep_dataset/ILSVRC2012_val_00011572.bin 224 224 +47554 ./prep_dataset/ILSVRC2012_val_00038560.bin 224 224 +47555 ./prep_dataset/ILSVRC2012_val_00024233.bin 224 224 +47556 ./prep_dataset/ILSVRC2012_val_00021682.bin 224 224 +47557 ./prep_dataset/ILSVRC2012_val_00046695.bin 224 224 +47558 ./prep_dataset/ILSVRC2012_val_00030666.bin 224 224 +47559 ./prep_dataset/ILSVRC2012_val_00047422.bin 224 224 +47560 ./prep_dataset/ILSVRC2012_val_00047742.bin 224 224 +47561 ./prep_dataset/ILSVRC2012_val_00019688.bin 224 224 +47562 ./prep_dataset/ILSVRC2012_val_00040014.bin 224 224 +47563 ./prep_dataset/ILSVRC2012_val_00023372.bin 224 224 +47564 ./prep_dataset/ILSVRC2012_val_00016598.bin 224 224 +47565 ./prep_dataset/ILSVRC2012_val_00036601.bin 224 224 +47566 ./prep_dataset/ILSVRC2012_val_00009441.bin 224 224 +47567 ./prep_dataset/ILSVRC2012_val_00042723.bin 224 224 +47568 ./prep_dataset/ILSVRC2012_val_00024037.bin 224 224 +47569 ./prep_dataset/ILSVRC2012_val_00013684.bin 224 224 +47570 ./prep_dataset/ILSVRC2012_val_00021640.bin 224 224 +47571 ./prep_dataset/ILSVRC2012_val_00002053.bin 224 224 +47572 ./prep_dataset/ILSVRC2012_val_00040928.bin 224 224 +47573 ./prep_dataset/ILSVRC2012_val_00007643.bin 224 224 +47574 ./prep_dataset/ILSVRC2012_val_00003271.bin 224 224 +47575 ./prep_dataset/ILSVRC2012_val_00001418.bin 224 224 +47576 ./prep_dataset/ILSVRC2012_val_00001326.bin 224 224 +47577 ./prep_dataset/ILSVRC2012_val_00049968.bin 224 224 +47578 ./prep_dataset/ILSVRC2012_val_00031157.bin 224 224 +47579 ./prep_dataset/ILSVRC2012_val_00023285.bin 224 224 +47580 ./prep_dataset/ILSVRC2012_val_00033385.bin 224 224 +47581 ./prep_dataset/ILSVRC2012_val_00027852.bin 224 224 +47582 ./prep_dataset/ILSVRC2012_val_00004102.bin 224 224 +47583 ./prep_dataset/ILSVRC2012_val_00044947.bin 224 224 +47584 ./prep_dataset/ILSVRC2012_val_00000781.bin 224 224 +47585 ./prep_dataset/ILSVRC2012_val_00045321.bin 224 224 +47586 ./prep_dataset/ILSVRC2012_val_00005089.bin 224 224 +47587 ./prep_dataset/ILSVRC2012_val_00008849.bin 224 224 +47588 ./prep_dataset/ILSVRC2012_val_00037793.bin 224 224 +47589 ./prep_dataset/ILSVRC2012_val_00032662.bin 224 224 +47590 ./prep_dataset/ILSVRC2012_val_00012569.bin 224 224 +47591 ./prep_dataset/ILSVRC2012_val_00039847.bin 224 224 +47592 ./prep_dataset/ILSVRC2012_val_00033568.bin 224 224 +47593 ./prep_dataset/ILSVRC2012_val_00016970.bin 224 224 +47594 ./prep_dataset/ILSVRC2012_val_00010923.bin 224 224 +47595 ./prep_dataset/ILSVRC2012_val_00042152.bin 224 224 +47596 ./prep_dataset/ILSVRC2012_val_00005506.bin 224 224 +47597 ./prep_dataset/ILSVRC2012_val_00039194.bin 224 224 +47598 ./prep_dataset/ILSVRC2012_val_00018821.bin 224 224 +47599 ./prep_dataset/ILSVRC2012_val_00014091.bin 224 224 +47600 ./prep_dataset/ILSVRC2012_val_00035224.bin 224 224 +47601 ./prep_dataset/ILSVRC2012_val_00013259.bin 224 224 +47602 ./prep_dataset/ILSVRC2012_val_00047810.bin 224 224 +47603 ./prep_dataset/ILSVRC2012_val_00008699.bin 224 224 +47604 ./prep_dataset/ILSVRC2012_val_00006267.bin 224 224 +47605 ./prep_dataset/ILSVRC2012_val_00003223.bin 224 224 +47606 ./prep_dataset/ILSVRC2012_val_00000463.bin 224 224 +47607 ./prep_dataset/ILSVRC2012_val_00021123.bin 224 224 +47608 ./prep_dataset/ILSVRC2012_val_00028592.bin 224 224 +47609 ./prep_dataset/ILSVRC2012_val_00013587.bin 224 224 +47610 ./prep_dataset/ILSVRC2012_val_00033347.bin 224 224 +47611 ./prep_dataset/ILSVRC2012_val_00014685.bin 224 224 +47612 ./prep_dataset/ILSVRC2012_val_00041512.bin 224 224 +47613 ./prep_dataset/ILSVRC2012_val_00029882.bin 224 224 +47614 ./prep_dataset/ILSVRC2012_val_00022536.bin 224 224 +47615 ./prep_dataset/ILSVRC2012_val_00037335.bin 224 224 +47616 ./prep_dataset/ILSVRC2012_val_00009102.bin 224 224 +47617 ./prep_dataset/ILSVRC2012_val_00021269.bin 224 224 +47618 ./prep_dataset/ILSVRC2012_val_00047925.bin 224 224 +47619 ./prep_dataset/ILSVRC2012_val_00036355.bin 224 224 +47620 ./prep_dataset/ILSVRC2012_val_00017733.bin 224 224 +47621 ./prep_dataset/ILSVRC2012_val_00006139.bin 224 224 +47622 ./prep_dataset/ILSVRC2012_val_00037031.bin 224 224 +47623 ./prep_dataset/ILSVRC2012_val_00006647.bin 224 224 +47624 ./prep_dataset/ILSVRC2012_val_00021847.bin 224 224 +47625 ./prep_dataset/ILSVRC2012_val_00025557.bin 224 224 +47626 ./prep_dataset/ILSVRC2012_val_00013794.bin 224 224 +47627 ./prep_dataset/ILSVRC2012_val_00031630.bin 224 224 +47628 ./prep_dataset/ILSVRC2012_val_00008775.bin 224 224 +47629 ./prep_dataset/ILSVRC2012_val_00036048.bin 224 224 +47630 ./prep_dataset/ILSVRC2012_val_00036649.bin 224 224 +47631 ./prep_dataset/ILSVRC2012_val_00021511.bin 224 224 +47632 ./prep_dataset/ILSVRC2012_val_00034716.bin 224 224 +47633 ./prep_dataset/ILSVRC2012_val_00004207.bin 224 224 +47634 ./prep_dataset/ILSVRC2012_val_00027949.bin 224 224 +47635 ./prep_dataset/ILSVRC2012_val_00038152.bin 224 224 +47636 ./prep_dataset/ILSVRC2012_val_00001916.bin 224 224 +47637 ./prep_dataset/ILSVRC2012_val_00035847.bin 224 224 +47638 ./prep_dataset/ILSVRC2012_val_00038912.bin 224 224 +47639 ./prep_dataset/ILSVRC2012_val_00017162.bin 224 224 +47640 ./prep_dataset/ILSVRC2012_val_00009675.bin 224 224 +47641 ./prep_dataset/ILSVRC2012_val_00000081.bin 224 224 +47642 ./prep_dataset/ILSVRC2012_val_00027049.bin 224 224 +47643 ./prep_dataset/ILSVRC2012_val_00015509.bin 224 224 +47644 ./prep_dataset/ILSVRC2012_val_00048980.bin 224 224 +47645 ./prep_dataset/ILSVRC2012_val_00032520.bin 224 224 +47646 ./prep_dataset/ILSVRC2012_val_00037995.bin 224 224 +47647 ./prep_dataset/ILSVRC2012_val_00047310.bin 224 224 +47648 ./prep_dataset/ILSVRC2012_val_00031742.bin 224 224 +47649 ./prep_dataset/ILSVRC2012_val_00035089.bin 224 224 +47650 ./prep_dataset/ILSVRC2012_val_00022599.bin 224 224 +47651 ./prep_dataset/ILSVRC2012_val_00031169.bin 224 224 +47652 ./prep_dataset/ILSVRC2012_val_00023667.bin 224 224 +47653 ./prep_dataset/ILSVRC2012_val_00039729.bin 224 224 +47654 ./prep_dataset/ILSVRC2012_val_00024838.bin 224 224 +47655 ./prep_dataset/ILSVRC2012_val_00013987.bin 224 224 +47656 ./prep_dataset/ILSVRC2012_val_00041971.bin 224 224 +47657 ./prep_dataset/ILSVRC2012_val_00013546.bin 224 224 +47658 ./prep_dataset/ILSVRC2012_val_00017010.bin 224 224 +47659 ./prep_dataset/ILSVRC2012_val_00004937.bin 224 224 +47660 ./prep_dataset/ILSVRC2012_val_00017856.bin 224 224 +47661 ./prep_dataset/ILSVRC2012_val_00012612.bin 224 224 +47662 ./prep_dataset/ILSVRC2012_val_00040857.bin 224 224 +47663 ./prep_dataset/ILSVRC2012_val_00046570.bin 224 224 +47664 ./prep_dataset/ILSVRC2012_val_00030217.bin 224 224 +47665 ./prep_dataset/ILSVRC2012_val_00046099.bin 224 224 +47666 ./prep_dataset/ILSVRC2012_val_00038253.bin 224 224 +47667 ./prep_dataset/ILSVRC2012_val_00043543.bin 224 224 +47668 ./prep_dataset/ILSVRC2012_val_00040730.bin 224 224 +47669 ./prep_dataset/ILSVRC2012_val_00038750.bin 224 224 +47670 ./prep_dataset/ILSVRC2012_val_00049871.bin 224 224 +47671 ./prep_dataset/ILSVRC2012_val_00019991.bin 224 224 +47672 ./prep_dataset/ILSVRC2012_val_00015596.bin 224 224 +47673 ./prep_dataset/ILSVRC2012_val_00033168.bin 224 224 +47674 ./prep_dataset/ILSVRC2012_val_00018073.bin 224 224 +47675 ./prep_dataset/ILSVRC2012_val_00047524.bin 224 224 +47676 ./prep_dataset/ILSVRC2012_val_00009861.bin 224 224 +47677 ./prep_dataset/ILSVRC2012_val_00039634.bin 224 224 +47678 ./prep_dataset/ILSVRC2012_val_00013307.bin 224 224 +47679 ./prep_dataset/ILSVRC2012_val_00036012.bin 224 224 +47680 ./prep_dataset/ILSVRC2012_val_00015531.bin 224 224 +47681 ./prep_dataset/ILSVRC2012_val_00017430.bin 224 224 +47682 ./prep_dataset/ILSVRC2012_val_00010867.bin 224 224 +47683 ./prep_dataset/ILSVRC2012_val_00007890.bin 224 224 +47684 ./prep_dataset/ILSVRC2012_val_00020156.bin 224 224 +47685 ./prep_dataset/ILSVRC2012_val_00037801.bin 224 224 +47686 ./prep_dataset/ILSVRC2012_val_00018520.bin 224 224 +47687 ./prep_dataset/ILSVRC2012_val_00003923.bin 224 224 +47688 ./prep_dataset/ILSVRC2012_val_00042680.bin 224 224 +47689 ./prep_dataset/ILSVRC2012_val_00029290.bin 224 224 +47690 ./prep_dataset/ILSVRC2012_val_00049235.bin 224 224 +47691 ./prep_dataset/ILSVRC2012_val_00030437.bin 224 224 +47692 ./prep_dataset/ILSVRC2012_val_00032472.bin 224 224 +47693 ./prep_dataset/ILSVRC2012_val_00029072.bin 224 224 +47694 ./prep_dataset/ILSVRC2012_val_00029374.bin 224 224 +47695 ./prep_dataset/ILSVRC2012_val_00022115.bin 224 224 +47696 ./prep_dataset/ILSVRC2012_val_00047932.bin 224 224 +47697 ./prep_dataset/ILSVRC2012_val_00000456.bin 224 224 +47698 ./prep_dataset/ILSVRC2012_val_00047223.bin 224 224 +47699 ./prep_dataset/ILSVRC2012_val_00013601.bin 224 224 +47700 ./prep_dataset/ILSVRC2012_val_00049450.bin 224 224 +47701 ./prep_dataset/ILSVRC2012_val_00023962.bin 224 224 +47702 ./prep_dataset/ILSVRC2012_val_00034191.bin 224 224 +47703 ./prep_dataset/ILSVRC2012_val_00036410.bin 224 224 +47704 ./prep_dataset/ILSVRC2012_val_00047711.bin 224 224 +47705 ./prep_dataset/ILSVRC2012_val_00036754.bin 224 224 +47706 ./prep_dataset/ILSVRC2012_val_00048402.bin 224 224 +47707 ./prep_dataset/ILSVRC2012_val_00026318.bin 224 224 +47708 ./prep_dataset/ILSVRC2012_val_00024782.bin 224 224 +47709 ./prep_dataset/ILSVRC2012_val_00017165.bin 224 224 +47710 ./prep_dataset/ILSVRC2012_val_00007436.bin 224 224 +47711 ./prep_dataset/ILSVRC2012_val_00007183.bin 224 224 +47712 ./prep_dataset/ILSVRC2012_val_00005949.bin 224 224 +47713 ./prep_dataset/ILSVRC2012_val_00033933.bin 224 224 +47714 ./prep_dataset/ILSVRC2012_val_00038209.bin 224 224 +47715 ./prep_dataset/ILSVRC2012_val_00017758.bin 224 224 +47716 ./prep_dataset/ILSVRC2012_val_00032091.bin 224 224 +47717 ./prep_dataset/ILSVRC2012_val_00023575.bin 224 224 +47718 ./prep_dataset/ILSVRC2012_val_00014259.bin 224 224 +47719 ./prep_dataset/ILSVRC2012_val_00032037.bin 224 224 +47720 ./prep_dataset/ILSVRC2012_val_00048277.bin 224 224 +47721 ./prep_dataset/ILSVRC2012_val_00016724.bin 224 224 +47722 ./prep_dataset/ILSVRC2012_val_00018645.bin 224 224 +47723 ./prep_dataset/ILSVRC2012_val_00017425.bin 224 224 +47724 ./prep_dataset/ILSVRC2012_val_00037046.bin 224 224 +47725 ./prep_dataset/ILSVRC2012_val_00019822.bin 224 224 +47726 ./prep_dataset/ILSVRC2012_val_00018424.bin 224 224 +47727 ./prep_dataset/ILSVRC2012_val_00010663.bin 224 224 +47728 ./prep_dataset/ILSVRC2012_val_00007114.bin 224 224 +47729 ./prep_dataset/ILSVRC2012_val_00006197.bin 224 224 +47730 ./prep_dataset/ILSVRC2012_val_00040775.bin 224 224 +47731 ./prep_dataset/ILSVRC2012_val_00025680.bin 224 224 +47732 ./prep_dataset/ILSVRC2012_val_00047306.bin 224 224 +47733 ./prep_dataset/ILSVRC2012_val_00004284.bin 224 224 +47734 ./prep_dataset/ILSVRC2012_val_00048502.bin 224 224 +47735 ./prep_dataset/ILSVRC2012_val_00049140.bin 224 224 +47736 ./prep_dataset/ILSVRC2012_val_00035891.bin 224 224 +47737 ./prep_dataset/ILSVRC2012_val_00002277.bin 224 224 +47738 ./prep_dataset/ILSVRC2012_val_00039246.bin 224 224 +47739 ./prep_dataset/ILSVRC2012_val_00006414.bin 224 224 +47740 ./prep_dataset/ILSVRC2012_val_00016843.bin 224 224 +47741 ./prep_dataset/ILSVRC2012_val_00005729.bin 224 224 +47742 ./prep_dataset/ILSVRC2012_val_00029491.bin 224 224 +47743 ./prep_dataset/ILSVRC2012_val_00047857.bin 224 224 +47744 ./prep_dataset/ILSVRC2012_val_00019801.bin 224 224 +47745 ./prep_dataset/ILSVRC2012_val_00043324.bin 224 224 +47746 ./prep_dataset/ILSVRC2012_val_00007767.bin 224 224 +47747 ./prep_dataset/ILSVRC2012_val_00027918.bin 224 224 +47748 ./prep_dataset/ILSVRC2012_val_00002098.bin 224 224 +47749 ./prep_dataset/ILSVRC2012_val_00021412.bin 224 224 +47750 ./prep_dataset/ILSVRC2012_val_00039590.bin 224 224 +47751 ./prep_dataset/ILSVRC2012_val_00019121.bin 224 224 +47752 ./prep_dataset/ILSVRC2012_val_00034475.bin 224 224 +47753 ./prep_dataset/ILSVRC2012_val_00000539.bin 224 224 +47754 ./prep_dataset/ILSVRC2012_val_00042758.bin 224 224 +47755 ./prep_dataset/ILSVRC2012_val_00024413.bin 224 224 +47756 ./prep_dataset/ILSVRC2012_val_00006381.bin 224 224 +47757 ./prep_dataset/ILSVRC2012_val_00028630.bin 224 224 +47758 ./prep_dataset/ILSVRC2012_val_00038713.bin 224 224 +47759 ./prep_dataset/ILSVRC2012_val_00039143.bin 224 224 +47760 ./prep_dataset/ILSVRC2012_val_00024419.bin 224 224 +47761 ./prep_dataset/ILSVRC2012_val_00000380.bin 224 224 +47762 ./prep_dataset/ILSVRC2012_val_00027837.bin 224 224 +47763 ./prep_dataset/ILSVRC2012_val_00037022.bin 224 224 +47764 ./prep_dataset/ILSVRC2012_val_00043396.bin 224 224 +47765 ./prep_dataset/ILSVRC2012_val_00047254.bin 224 224 +47766 ./prep_dataset/ILSVRC2012_val_00028425.bin 224 224 +47767 ./prep_dataset/ILSVRC2012_val_00030506.bin 224 224 +47768 ./prep_dataset/ILSVRC2012_val_00010427.bin 224 224 +47769 ./prep_dataset/ILSVRC2012_val_00008476.bin 224 224 +47770 ./prep_dataset/ILSVRC2012_val_00015626.bin 224 224 +47771 ./prep_dataset/ILSVRC2012_val_00015241.bin 224 224 +47772 ./prep_dataset/ILSVRC2012_val_00027873.bin 224 224 +47773 ./prep_dataset/ILSVRC2012_val_00019930.bin 224 224 +47774 ./prep_dataset/ILSVRC2012_val_00033376.bin 224 224 +47775 ./prep_dataset/ILSVRC2012_val_00040119.bin 224 224 +47776 ./prep_dataset/ILSVRC2012_val_00011452.bin 224 224 +47777 ./prep_dataset/ILSVRC2012_val_00018311.bin 224 224 +47778 ./prep_dataset/ILSVRC2012_val_00042432.bin 224 224 +47779 ./prep_dataset/ILSVRC2012_val_00042567.bin 224 224 +47780 ./prep_dataset/ILSVRC2012_val_00005472.bin 224 224 +47781 ./prep_dataset/ILSVRC2012_val_00024789.bin 224 224 +47782 ./prep_dataset/ILSVRC2012_val_00049003.bin 224 224 +47783 ./prep_dataset/ILSVRC2012_val_00040567.bin 224 224 +47784 ./prep_dataset/ILSVRC2012_val_00008152.bin 224 224 +47785 ./prep_dataset/ILSVRC2012_val_00023136.bin 224 224 +47786 ./prep_dataset/ILSVRC2012_val_00030711.bin 224 224 +47787 ./prep_dataset/ILSVRC2012_val_00044689.bin 224 224 +47788 ./prep_dataset/ILSVRC2012_val_00035007.bin 224 224 +47789 ./prep_dataset/ILSVRC2012_val_00037751.bin 224 224 +47790 ./prep_dataset/ILSVRC2012_val_00011630.bin 224 224 +47791 ./prep_dataset/ILSVRC2012_val_00037987.bin 224 224 +47792 ./prep_dataset/ILSVRC2012_val_00047610.bin 224 224 +47793 ./prep_dataset/ILSVRC2012_val_00004206.bin 224 224 +47794 ./prep_dataset/ILSVRC2012_val_00004903.bin 224 224 +47795 ./prep_dataset/ILSVRC2012_val_00022041.bin 224 224 +47796 ./prep_dataset/ILSVRC2012_val_00036075.bin 224 224 +47797 ./prep_dataset/ILSVRC2012_val_00014877.bin 224 224 +47798 ./prep_dataset/ILSVRC2012_val_00042775.bin 224 224 +47799 ./prep_dataset/ILSVRC2012_val_00041568.bin 224 224 +47800 ./prep_dataset/ILSVRC2012_val_00045468.bin 224 224 +47801 ./prep_dataset/ILSVRC2012_val_00034969.bin 224 224 +47802 ./prep_dataset/ILSVRC2012_val_00030687.bin 224 224 +47803 ./prep_dataset/ILSVRC2012_val_00007827.bin 224 224 +47804 ./prep_dataset/ILSVRC2012_val_00040891.bin 224 224 +47805 ./prep_dataset/ILSVRC2012_val_00026264.bin 224 224 +47806 ./prep_dataset/ILSVRC2012_val_00014610.bin 224 224 +47807 ./prep_dataset/ILSVRC2012_val_00025397.bin 224 224 +47808 ./prep_dataset/ILSVRC2012_val_00017507.bin 224 224 +47809 ./prep_dataset/ILSVRC2012_val_00007584.bin 224 224 +47810 ./prep_dataset/ILSVRC2012_val_00011245.bin 224 224 +47811 ./prep_dataset/ILSVRC2012_val_00015364.bin 224 224 +47812 ./prep_dataset/ILSVRC2012_val_00021082.bin 224 224 +47813 ./prep_dataset/ILSVRC2012_val_00008754.bin 224 224 +47814 ./prep_dataset/ILSVRC2012_val_00030801.bin 224 224 +47815 ./prep_dataset/ILSVRC2012_val_00002489.bin 224 224 +47816 ./prep_dataset/ILSVRC2012_val_00003907.bin 224 224 +47817 ./prep_dataset/ILSVRC2012_val_00044037.bin 224 224 +47818 ./prep_dataset/ILSVRC2012_val_00012300.bin 224 224 +47819 ./prep_dataset/ILSVRC2012_val_00027544.bin 224 224 +47820 ./prep_dataset/ILSVRC2012_val_00048717.bin 224 224 +47821 ./prep_dataset/ILSVRC2012_val_00032321.bin 224 224 +47822 ./prep_dataset/ILSVRC2012_val_00030203.bin 224 224 +47823 ./prep_dataset/ILSVRC2012_val_00009911.bin 224 224 +47824 ./prep_dataset/ILSVRC2012_val_00032245.bin 224 224 +47825 ./prep_dataset/ILSVRC2012_val_00043100.bin 224 224 +47826 ./prep_dataset/ILSVRC2012_val_00021519.bin 224 224 +47827 ./prep_dataset/ILSVRC2012_val_00027645.bin 224 224 +47828 ./prep_dataset/ILSVRC2012_val_00022672.bin 224 224 +47829 ./prep_dataset/ILSVRC2012_val_00042422.bin 224 224 +47830 ./prep_dataset/ILSVRC2012_val_00036408.bin 224 224 +47831 ./prep_dataset/ILSVRC2012_val_00043639.bin 224 224 +47832 ./prep_dataset/ILSVRC2012_val_00019049.bin 224 224 +47833 ./prep_dataset/ILSVRC2012_val_00015679.bin 224 224 +47834 ./prep_dataset/ILSVRC2012_val_00031316.bin 224 224 +47835 ./prep_dataset/ILSVRC2012_val_00025106.bin 224 224 +47836 ./prep_dataset/ILSVRC2012_val_00002540.bin 224 224 +47837 ./prep_dataset/ILSVRC2012_val_00046748.bin 224 224 +47838 ./prep_dataset/ILSVRC2012_val_00009126.bin 224 224 +47839 ./prep_dataset/ILSVRC2012_val_00014032.bin 224 224 +47840 ./prep_dataset/ILSVRC2012_val_00046187.bin 224 224 +47841 ./prep_dataset/ILSVRC2012_val_00041895.bin 224 224 +47842 ./prep_dataset/ILSVRC2012_val_00035817.bin 224 224 +47843 ./prep_dataset/ILSVRC2012_val_00006937.bin 224 224 +47844 ./prep_dataset/ILSVRC2012_val_00000596.bin 224 224 +47845 ./prep_dataset/ILSVRC2012_val_00031942.bin 224 224 +47846 ./prep_dataset/ILSVRC2012_val_00043723.bin 224 224 +47847 ./prep_dataset/ILSVRC2012_val_00033811.bin 224 224 +47848 ./prep_dataset/ILSVRC2012_val_00024327.bin 224 224 +47849 ./prep_dataset/ILSVRC2012_val_00048065.bin 224 224 +47850 ./prep_dataset/ILSVRC2012_val_00044548.bin 224 224 +47851 ./prep_dataset/ILSVRC2012_val_00044986.bin 224 224 +47852 ./prep_dataset/ILSVRC2012_val_00042764.bin 224 224 +47853 ./prep_dataset/ILSVRC2012_val_00048949.bin 224 224 +47854 ./prep_dataset/ILSVRC2012_val_00003377.bin 224 224 +47855 ./prep_dataset/ILSVRC2012_val_00044357.bin 224 224 +47856 ./prep_dataset/ILSVRC2012_val_00028415.bin 224 224 +47857 ./prep_dataset/ILSVRC2012_val_00041564.bin 224 224 +47858 ./prep_dataset/ILSVRC2012_val_00038520.bin 224 224 +47859 ./prep_dataset/ILSVRC2012_val_00036523.bin 224 224 +47860 ./prep_dataset/ILSVRC2012_val_00025985.bin 224 224 +47861 ./prep_dataset/ILSVRC2012_val_00012157.bin 224 224 +47862 ./prep_dataset/ILSVRC2012_val_00000475.bin 224 224 +47863 ./prep_dataset/ILSVRC2012_val_00023061.bin 224 224 +47864 ./prep_dataset/ILSVRC2012_val_00010725.bin 224 224 +47865 ./prep_dataset/ILSVRC2012_val_00007707.bin 224 224 +47866 ./prep_dataset/ILSVRC2012_val_00016754.bin 224 224 +47867 ./prep_dataset/ILSVRC2012_val_00037970.bin 224 224 +47868 ./prep_dataset/ILSVRC2012_val_00012371.bin 224 224 +47869 ./prep_dataset/ILSVRC2012_val_00036898.bin 224 224 +47870 ./prep_dataset/ILSVRC2012_val_00011235.bin 224 224 +47871 ./prep_dataset/ILSVRC2012_val_00012554.bin 224 224 +47872 ./prep_dataset/ILSVRC2012_val_00015891.bin 224 224 +47873 ./prep_dataset/ILSVRC2012_val_00011299.bin 224 224 +47874 ./prep_dataset/ILSVRC2012_val_00042796.bin 224 224 +47875 ./prep_dataset/ILSVRC2012_val_00000803.bin 224 224 +47876 ./prep_dataset/ILSVRC2012_val_00009006.bin 224 224 +47877 ./prep_dataset/ILSVRC2012_val_00001448.bin 224 224 +47878 ./prep_dataset/ILSVRC2012_val_00022042.bin 224 224 +47879 ./prep_dataset/ILSVRC2012_val_00027696.bin 224 224 +47880 ./prep_dataset/ILSVRC2012_val_00016661.bin 224 224 +47881 ./prep_dataset/ILSVRC2012_val_00024770.bin 224 224 +47882 ./prep_dataset/ILSVRC2012_val_00004448.bin 224 224 +47883 ./prep_dataset/ILSVRC2012_val_00033449.bin 224 224 +47884 ./prep_dataset/ILSVRC2012_val_00002196.bin 224 224 +47885 ./prep_dataset/ILSVRC2012_val_00011535.bin 224 224 +47886 ./prep_dataset/ILSVRC2012_val_00028547.bin 224 224 +47887 ./prep_dataset/ILSVRC2012_val_00031200.bin 224 224 +47888 ./prep_dataset/ILSVRC2012_val_00025141.bin 224 224 +47889 ./prep_dataset/ILSVRC2012_val_00029144.bin 224 224 +47890 ./prep_dataset/ILSVRC2012_val_00002618.bin 224 224 +47891 ./prep_dataset/ILSVRC2012_val_00006580.bin 224 224 +47892 ./prep_dataset/ILSVRC2012_val_00014957.bin 224 224 +47893 ./prep_dataset/ILSVRC2012_val_00007321.bin 224 224 +47894 ./prep_dataset/ILSVRC2012_val_00006440.bin 224 224 +47895 ./prep_dataset/ILSVRC2012_val_00034328.bin 224 224 +47896 ./prep_dataset/ILSVRC2012_val_00039409.bin 224 224 +47897 ./prep_dataset/ILSVRC2012_val_00046980.bin 224 224 +47898 ./prep_dataset/ILSVRC2012_val_00047362.bin 224 224 +47899 ./prep_dataset/ILSVRC2012_val_00021196.bin 224 224 +47900 ./prep_dataset/ILSVRC2012_val_00028764.bin 224 224 +47901 ./prep_dataset/ILSVRC2012_val_00007636.bin 224 224 +47902 ./prep_dataset/ILSVRC2012_val_00015939.bin 224 224 +47903 ./prep_dataset/ILSVRC2012_val_00003992.bin 224 224 +47904 ./prep_dataset/ILSVRC2012_val_00010884.bin 224 224 +47905 ./prep_dataset/ILSVRC2012_val_00047749.bin 224 224 +47906 ./prep_dataset/ILSVRC2012_val_00015873.bin 224 224 +47907 ./prep_dataset/ILSVRC2012_val_00007440.bin 224 224 +47908 ./prep_dataset/ILSVRC2012_val_00022529.bin 224 224 +47909 ./prep_dataset/ILSVRC2012_val_00028608.bin 224 224 +47910 ./prep_dataset/ILSVRC2012_val_00013292.bin 224 224 +47911 ./prep_dataset/ILSVRC2012_val_00009808.bin 224 224 +47912 ./prep_dataset/ILSVRC2012_val_00002285.bin 224 224 +47913 ./prep_dataset/ILSVRC2012_val_00027017.bin 224 224 +47914 ./prep_dataset/ILSVRC2012_val_00022186.bin 224 224 +47915 ./prep_dataset/ILSVRC2012_val_00005495.bin 224 224 +47916 ./prep_dataset/ILSVRC2012_val_00024989.bin 224 224 +47917 ./prep_dataset/ILSVRC2012_val_00032842.bin 224 224 +47918 ./prep_dataset/ILSVRC2012_val_00044815.bin 224 224 +47919 ./prep_dataset/ILSVRC2012_val_00049806.bin 224 224 +47920 ./prep_dataset/ILSVRC2012_val_00002775.bin 224 224 +47921 ./prep_dataset/ILSVRC2012_val_00038758.bin 224 224 +47922 ./prep_dataset/ILSVRC2012_val_00036209.bin 224 224 +47923 ./prep_dataset/ILSVRC2012_val_00031304.bin 224 224 +47924 ./prep_dataset/ILSVRC2012_val_00040103.bin 224 224 +47925 ./prep_dataset/ILSVRC2012_val_00008015.bin 224 224 +47926 ./prep_dataset/ILSVRC2012_val_00032049.bin 224 224 +47927 ./prep_dataset/ILSVRC2012_val_00008808.bin 224 224 +47928 ./prep_dataset/ILSVRC2012_val_00012739.bin 224 224 +47929 ./prep_dataset/ILSVRC2012_val_00027824.bin 224 224 +47930 ./prep_dataset/ILSVRC2012_val_00046287.bin 224 224 +47931 ./prep_dataset/ILSVRC2012_val_00018199.bin 224 224 +47932 ./prep_dataset/ILSVRC2012_val_00023642.bin 224 224 +47933 ./prep_dataset/ILSVRC2012_val_00013652.bin 224 224 +47934 ./prep_dataset/ILSVRC2012_val_00002090.bin 224 224 +47935 ./prep_dataset/ILSVRC2012_val_00020419.bin 224 224 +47936 ./prep_dataset/ILSVRC2012_val_00047988.bin 224 224 +47937 ./prep_dataset/ILSVRC2012_val_00041315.bin 224 224 +47938 ./prep_dataset/ILSVRC2012_val_00023853.bin 224 224 +47939 ./prep_dataset/ILSVRC2012_val_00008199.bin 224 224 +47940 ./prep_dataset/ILSVRC2012_val_00044542.bin 224 224 +47941 ./prep_dataset/ILSVRC2012_val_00040158.bin 224 224 +47942 ./prep_dataset/ILSVRC2012_val_00036945.bin 224 224 +47943 ./prep_dataset/ILSVRC2012_val_00025136.bin 224 224 +47944 ./prep_dataset/ILSVRC2012_val_00004328.bin 224 224 +47945 ./prep_dataset/ILSVRC2012_val_00027719.bin 224 224 +47946 ./prep_dataset/ILSVRC2012_val_00022640.bin 224 224 +47947 ./prep_dataset/ILSVRC2012_val_00004417.bin 224 224 +47948 ./prep_dataset/ILSVRC2012_val_00032745.bin 224 224 +47949 ./prep_dataset/ILSVRC2012_val_00014148.bin 224 224 +47950 ./prep_dataset/ILSVRC2012_val_00041319.bin 224 224 +47951 ./prep_dataset/ILSVRC2012_val_00005245.bin 224 224 +47952 ./prep_dataset/ILSVRC2012_val_00043790.bin 224 224 +47953 ./prep_dataset/ILSVRC2012_val_00015640.bin 224 224 +47954 ./prep_dataset/ILSVRC2012_val_00002307.bin 224 224 +47955 ./prep_dataset/ILSVRC2012_val_00035280.bin 224 224 +47956 ./prep_dataset/ILSVRC2012_val_00014690.bin 224 224 +47957 ./prep_dataset/ILSVRC2012_val_00048386.bin 224 224 +47958 ./prep_dataset/ILSVRC2012_val_00033981.bin 224 224 +47959 ./prep_dataset/ILSVRC2012_val_00046072.bin 224 224 +47960 ./prep_dataset/ILSVRC2012_val_00044122.bin 224 224 +47961 ./prep_dataset/ILSVRC2012_val_00022386.bin 224 224 +47962 ./prep_dataset/ILSVRC2012_val_00001744.bin 224 224 +47963 ./prep_dataset/ILSVRC2012_val_00022576.bin 224 224 +47964 ./prep_dataset/ILSVRC2012_val_00007510.bin 224 224 +47965 ./prep_dataset/ILSVRC2012_val_00034981.bin 224 224 +47966 ./prep_dataset/ILSVRC2012_val_00027178.bin 224 224 +47967 ./prep_dataset/ILSVRC2012_val_00002325.bin 224 224 +47968 ./prep_dataset/ILSVRC2012_val_00044290.bin 224 224 +47969 ./prep_dataset/ILSVRC2012_val_00004086.bin 224 224 +47970 ./prep_dataset/ILSVRC2012_val_00022308.bin 224 224 +47971 ./prep_dataset/ILSVRC2012_val_00029705.bin 224 224 +47972 ./prep_dataset/ILSVRC2012_val_00022143.bin 224 224 +47973 ./prep_dataset/ILSVRC2012_val_00016738.bin 224 224 +47974 ./prep_dataset/ILSVRC2012_val_00045828.bin 224 224 +47975 ./prep_dataset/ILSVRC2012_val_00031764.bin 224 224 +47976 ./prep_dataset/ILSVRC2012_val_00015766.bin 224 224 +47977 ./prep_dataset/ILSVRC2012_val_00046865.bin 224 224 +47978 ./prep_dataset/ILSVRC2012_val_00022457.bin 224 224 +47979 ./prep_dataset/ILSVRC2012_val_00022648.bin 224 224 +47980 ./prep_dataset/ILSVRC2012_val_00007549.bin 224 224 +47981 ./prep_dataset/ILSVRC2012_val_00033951.bin 224 224 +47982 ./prep_dataset/ILSVRC2012_val_00003172.bin 224 224 +47983 ./prep_dataset/ILSVRC2012_val_00033463.bin 224 224 +47984 ./prep_dataset/ILSVRC2012_val_00017901.bin 224 224 +47985 ./prep_dataset/ILSVRC2012_val_00049700.bin 224 224 +47986 ./prep_dataset/ILSVRC2012_val_00005430.bin 224 224 +47987 ./prep_dataset/ILSVRC2012_val_00005100.bin 224 224 +47988 ./prep_dataset/ILSVRC2012_val_00006266.bin 224 224 +47989 ./prep_dataset/ILSVRC2012_val_00012053.bin 224 224 +47990 ./prep_dataset/ILSVRC2012_val_00023386.bin 224 224 +47991 ./prep_dataset/ILSVRC2012_val_00031449.bin 224 224 +47992 ./prep_dataset/ILSVRC2012_val_00017893.bin 224 224 +47993 ./prep_dataset/ILSVRC2012_val_00012271.bin 224 224 +47994 ./prep_dataset/ILSVRC2012_val_00002742.bin 224 224 +47995 ./prep_dataset/ILSVRC2012_val_00002828.bin 224 224 +47996 ./prep_dataset/ILSVRC2012_val_00011075.bin 224 224 +47997 ./prep_dataset/ILSVRC2012_val_00029294.bin 224 224 +47998 ./prep_dataset/ILSVRC2012_val_00017728.bin 224 224 +47999 ./prep_dataset/ILSVRC2012_val_00041135.bin 224 224 +48000 ./prep_dataset/ILSVRC2012_val_00047556.bin 224 224 +48001 ./prep_dataset/ILSVRC2012_val_00047258.bin 224 224 +48002 ./prep_dataset/ILSVRC2012_val_00035329.bin 224 224 +48003 ./prep_dataset/ILSVRC2012_val_00032847.bin 224 224 +48004 ./prep_dataset/ILSVRC2012_val_00012771.bin 224 224 +48005 ./prep_dataset/ILSVRC2012_val_00048022.bin 224 224 +48006 ./prep_dataset/ILSVRC2012_val_00016952.bin 224 224 +48007 ./prep_dataset/ILSVRC2012_val_00008349.bin 224 224 +48008 ./prep_dataset/ILSVRC2012_val_00036626.bin 224 224 +48009 ./prep_dataset/ILSVRC2012_val_00023960.bin 224 224 +48010 ./prep_dataset/ILSVRC2012_val_00022379.bin 224 224 +48011 ./prep_dataset/ILSVRC2012_val_00021643.bin 224 224 +48012 ./prep_dataset/ILSVRC2012_val_00000902.bin 224 224 +48013 ./prep_dataset/ILSVRC2012_val_00026695.bin 224 224 +48014 ./prep_dataset/ILSVRC2012_val_00033846.bin 224 224 +48015 ./prep_dataset/ILSVRC2012_val_00022339.bin 224 224 +48016 ./prep_dataset/ILSVRC2012_val_00014052.bin 224 224 +48017 ./prep_dataset/ILSVRC2012_val_00031183.bin 224 224 +48018 ./prep_dataset/ILSVRC2012_val_00008466.bin 224 224 +48019 ./prep_dataset/ILSVRC2012_val_00038826.bin 224 224 +48020 ./prep_dataset/ILSVRC2012_val_00004835.bin 224 224 +48021 ./prep_dataset/ILSVRC2012_val_00020336.bin 224 224 +48022 ./prep_dataset/ILSVRC2012_val_00037179.bin 224 224 +48023 ./prep_dataset/ILSVRC2012_val_00049629.bin 224 224 +48024 ./prep_dataset/ILSVRC2012_val_00001963.bin 224 224 +48025 ./prep_dataset/ILSVRC2012_val_00041738.bin 224 224 +48026 ./prep_dataset/ILSVRC2012_val_00029082.bin 224 224 +48027 ./prep_dataset/ILSVRC2012_val_00016167.bin 224 224 +48028 ./prep_dataset/ILSVRC2012_val_00024253.bin 224 224 +48029 ./prep_dataset/ILSVRC2012_val_00022661.bin 224 224 +48030 ./prep_dataset/ILSVRC2012_val_00009537.bin 224 224 +48031 ./prep_dataset/ILSVRC2012_val_00043060.bin 224 224 +48032 ./prep_dataset/ILSVRC2012_val_00033295.bin 224 224 +48033 ./prep_dataset/ILSVRC2012_val_00008365.bin 224 224 +48034 ./prep_dataset/ILSVRC2012_val_00039643.bin 224 224 +48035 ./prep_dataset/ILSVRC2012_val_00039330.bin 224 224 +48036 ./prep_dataset/ILSVRC2012_val_00038029.bin 224 224 +48037 ./prep_dataset/ILSVRC2012_val_00020939.bin 224 224 +48038 ./prep_dataset/ILSVRC2012_val_00036799.bin 224 224 +48039 ./prep_dataset/ILSVRC2012_val_00036308.bin 224 224 +48040 ./prep_dataset/ILSVRC2012_val_00007296.bin 224 224 +48041 ./prep_dataset/ILSVRC2012_val_00047322.bin 224 224 +48042 ./prep_dataset/ILSVRC2012_val_00049341.bin 224 224 +48043 ./prep_dataset/ILSVRC2012_val_00033992.bin 224 224 +48044 ./prep_dataset/ILSVRC2012_val_00023134.bin 224 224 +48045 ./prep_dataset/ILSVRC2012_val_00000034.bin 224 224 +48046 ./prep_dataset/ILSVRC2012_val_00031864.bin 224 224 +48047 ./prep_dataset/ILSVRC2012_val_00014856.bin 224 224 +48048 ./prep_dataset/ILSVRC2012_val_00026151.bin 224 224 +48049 ./prep_dataset/ILSVRC2012_val_00044788.bin 224 224 +48050 ./prep_dataset/ILSVRC2012_val_00024642.bin 224 224 +48051 ./prep_dataset/ILSVRC2012_val_00008595.bin 224 224 +48052 ./prep_dataset/ILSVRC2012_val_00032742.bin 224 224 +48053 ./prep_dataset/ILSVRC2012_val_00019661.bin 224 224 +48054 ./prep_dataset/ILSVRC2012_val_00005029.bin 224 224 +48055 ./prep_dataset/ILSVRC2012_val_00004795.bin 224 224 +48056 ./prep_dataset/ILSVRC2012_val_00034799.bin 224 224 +48057 ./prep_dataset/ILSVRC2012_val_00007392.bin 224 224 +48058 ./prep_dataset/ILSVRC2012_val_00013040.bin 224 224 +48059 ./prep_dataset/ILSVRC2012_val_00025267.bin 224 224 +48060 ./prep_dataset/ILSVRC2012_val_00013321.bin 224 224 +48061 ./prep_dataset/ILSVRC2012_val_00040120.bin 224 224 +48062 ./prep_dataset/ILSVRC2012_val_00038184.bin 224 224 +48063 ./prep_dataset/ILSVRC2012_val_00032172.bin 224 224 +48064 ./prep_dataset/ILSVRC2012_val_00009735.bin 224 224 +48065 ./prep_dataset/ILSVRC2012_val_00029400.bin 224 224 +48066 ./prep_dataset/ILSVRC2012_val_00012011.bin 224 224 +48067 ./prep_dataset/ILSVRC2012_val_00043016.bin 224 224 +48068 ./prep_dataset/ILSVRC2012_val_00008055.bin 224 224 +48069 ./prep_dataset/ILSVRC2012_val_00003262.bin 224 224 +48070 ./prep_dataset/ILSVRC2012_val_00001637.bin 224 224 +48071 ./prep_dataset/ILSVRC2012_val_00005475.bin 224 224 +48072 ./prep_dataset/ILSVRC2012_val_00047181.bin 224 224 +48073 ./prep_dataset/ILSVRC2012_val_00046418.bin 224 224 +48074 ./prep_dataset/ILSVRC2012_val_00009825.bin 224 224 +48075 ./prep_dataset/ILSVRC2012_val_00040085.bin 224 224 +48076 ./prep_dataset/ILSVRC2012_val_00008308.bin 224 224 +48077 ./prep_dataset/ILSVRC2012_val_00010809.bin 224 224 +48078 ./prep_dataset/ILSVRC2012_val_00019874.bin 224 224 +48079 ./prep_dataset/ILSVRC2012_val_00019585.bin 224 224 +48080 ./prep_dataset/ILSVRC2012_val_00017143.bin 224 224 +48081 ./prep_dataset/ILSVRC2012_val_00000438.bin 224 224 +48082 ./prep_dataset/ILSVRC2012_val_00002481.bin 224 224 +48083 ./prep_dataset/ILSVRC2012_val_00048090.bin 224 224 +48084 ./prep_dataset/ILSVRC2012_val_00025230.bin 224 224 +48085 ./prep_dataset/ILSVRC2012_val_00017052.bin 224 224 +48086 ./prep_dataset/ILSVRC2012_val_00047450.bin 224 224 +48087 ./prep_dataset/ILSVRC2012_val_00004087.bin 224 224 +48088 ./prep_dataset/ILSVRC2012_val_00022548.bin 224 224 +48089 ./prep_dataset/ILSVRC2012_val_00016265.bin 224 224 +48090 ./prep_dataset/ILSVRC2012_val_00046583.bin 224 224 +48091 ./prep_dataset/ILSVRC2012_val_00043359.bin 224 224 +48092 ./prep_dataset/ILSVRC2012_val_00019780.bin 224 224 +48093 ./prep_dataset/ILSVRC2012_val_00009252.bin 224 224 +48094 ./prep_dataset/ILSVRC2012_val_00021094.bin 224 224 +48095 ./prep_dataset/ILSVRC2012_val_00044119.bin 224 224 +48096 ./prep_dataset/ILSVRC2012_val_00017322.bin 224 224 +48097 ./prep_dataset/ILSVRC2012_val_00003401.bin 224 224 +48098 ./prep_dataset/ILSVRC2012_val_00048507.bin 224 224 +48099 ./prep_dataset/ILSVRC2012_val_00044960.bin 224 224 +48100 ./prep_dataset/ILSVRC2012_val_00021791.bin 224 224 +48101 ./prep_dataset/ILSVRC2012_val_00048331.bin 224 224 +48102 ./prep_dataset/ILSVRC2012_val_00013827.bin 224 224 +48103 ./prep_dataset/ILSVRC2012_val_00046914.bin 224 224 +48104 ./prep_dataset/ILSVRC2012_val_00025865.bin 224 224 +48105 ./prep_dataset/ILSVRC2012_val_00026140.bin 224 224 +48106 ./prep_dataset/ILSVRC2012_val_00028769.bin 224 224 +48107 ./prep_dataset/ILSVRC2012_val_00033907.bin 224 224 +48108 ./prep_dataset/ILSVRC2012_val_00041487.bin 224 224 +48109 ./prep_dataset/ILSVRC2012_val_00044447.bin 224 224 +48110 ./prep_dataset/ILSVRC2012_val_00048061.bin 224 224 +48111 ./prep_dataset/ILSVRC2012_val_00018496.bin 224 224 +48112 ./prep_dataset/ILSVRC2012_val_00026988.bin 224 224 +48113 ./prep_dataset/ILSVRC2012_val_00032987.bin 224 224 +48114 ./prep_dataset/ILSVRC2012_val_00027099.bin 224 224 +48115 ./prep_dataset/ILSVRC2012_val_00029764.bin 224 224 +48116 ./prep_dataset/ILSVRC2012_val_00032475.bin 224 224 +48117 ./prep_dataset/ILSVRC2012_val_00041252.bin 224 224 +48118 ./prep_dataset/ILSVRC2012_val_00030580.bin 224 224 +48119 ./prep_dataset/ILSVRC2012_val_00018184.bin 224 224 +48120 ./prep_dataset/ILSVRC2012_val_00010982.bin 224 224 +48121 ./prep_dataset/ILSVRC2012_val_00024262.bin 224 224 +48122 ./prep_dataset/ILSVRC2012_val_00010453.bin 224 224 +48123 ./prep_dataset/ILSVRC2012_val_00048844.bin 224 224 +48124 ./prep_dataset/ILSVRC2012_val_00034663.bin 224 224 +48125 ./prep_dataset/ILSVRC2012_val_00041088.bin 224 224 +48126 ./prep_dataset/ILSVRC2012_val_00006558.bin 224 224 +48127 ./prep_dataset/ILSVRC2012_val_00017513.bin 224 224 +48128 ./prep_dataset/ILSVRC2012_val_00025925.bin 224 224 +48129 ./prep_dataset/ILSVRC2012_val_00000867.bin 224 224 +48130 ./prep_dataset/ILSVRC2012_val_00002251.bin 224 224 +48131 ./prep_dataset/ILSVRC2012_val_00040705.bin 224 224 +48132 ./prep_dataset/ILSVRC2012_val_00004800.bin 224 224 +48133 ./prep_dataset/ILSVRC2012_val_00030808.bin 224 224 +48134 ./prep_dataset/ILSVRC2012_val_00048234.bin 224 224 +48135 ./prep_dataset/ILSVRC2012_val_00031510.bin 224 224 +48136 ./prep_dataset/ILSVRC2012_val_00017190.bin 224 224 +48137 ./prep_dataset/ILSVRC2012_val_00040474.bin 224 224 +48138 ./prep_dataset/ILSVRC2012_val_00025360.bin 224 224 +48139 ./prep_dataset/ILSVRC2012_val_00014417.bin 224 224 +48140 ./prep_dataset/ILSVRC2012_val_00000605.bin 224 224 +48141 ./prep_dataset/ILSVRC2012_val_00042473.bin 224 224 +48142 ./prep_dataset/ILSVRC2012_val_00020950.bin 224 224 +48143 ./prep_dataset/ILSVRC2012_val_00044886.bin 224 224 +48144 ./prep_dataset/ILSVRC2012_val_00046046.bin 224 224 +48145 ./prep_dataset/ILSVRC2012_val_00046226.bin 224 224 +48146 ./prep_dataset/ILSVRC2012_val_00018212.bin 224 224 +48147 ./prep_dataset/ILSVRC2012_val_00012396.bin 224 224 +48148 ./prep_dataset/ILSVRC2012_val_00038855.bin 224 224 +48149 ./prep_dataset/ILSVRC2012_val_00012411.bin 224 224 +48150 ./prep_dataset/ILSVRC2012_val_00032335.bin 224 224 +48151 ./prep_dataset/ILSVRC2012_val_00032559.bin 224 224 +48152 ./prep_dataset/ILSVRC2012_val_00022008.bin 224 224 +48153 ./prep_dataset/ILSVRC2012_val_00036806.bin 224 224 +48154 ./prep_dataset/ILSVRC2012_val_00014154.bin 224 224 +48155 ./prep_dataset/ILSVRC2012_val_00007785.bin 224 224 +48156 ./prep_dataset/ILSVRC2012_val_00004971.bin 224 224 +48157 ./prep_dataset/ILSVRC2012_val_00039508.bin 224 224 +48158 ./prep_dataset/ILSVRC2012_val_00016579.bin 224 224 +48159 ./prep_dataset/ILSVRC2012_val_00025801.bin 224 224 +48160 ./prep_dataset/ILSVRC2012_val_00025696.bin 224 224 +48161 ./prep_dataset/ILSVRC2012_val_00039980.bin 224 224 +48162 ./prep_dataset/ILSVRC2012_val_00010962.bin 224 224 +48163 ./prep_dataset/ILSVRC2012_val_00027051.bin 224 224 +48164 ./prep_dataset/ILSVRC2012_val_00024626.bin 224 224 +48165 ./prep_dataset/ILSVRC2012_val_00034614.bin 224 224 +48166 ./prep_dataset/ILSVRC2012_val_00016480.bin 224 224 +48167 ./prep_dataset/ILSVRC2012_val_00017549.bin 224 224 +48168 ./prep_dataset/ILSVRC2012_val_00031816.bin 224 224 +48169 ./prep_dataset/ILSVRC2012_val_00013222.bin 224 224 +48170 ./prep_dataset/ILSVRC2012_val_00046633.bin 224 224 +48171 ./prep_dataset/ILSVRC2012_val_00007784.bin 224 224 +48172 ./prep_dataset/ILSVRC2012_val_00020583.bin 224 224 +48173 ./prep_dataset/ILSVRC2012_val_00024172.bin 224 224 +48174 ./prep_dataset/ILSVRC2012_val_00018996.bin 224 224 +48175 ./prep_dataset/ILSVRC2012_val_00003031.bin 224 224 +48176 ./prep_dataset/ILSVRC2012_val_00003517.bin 224 224 +48177 ./prep_dataset/ILSVRC2012_val_00036375.bin 224 224 +48178 ./prep_dataset/ILSVRC2012_val_00006677.bin 224 224 +48179 ./prep_dataset/ILSVRC2012_val_00020258.bin 224 224 +48180 ./prep_dataset/ILSVRC2012_val_00011155.bin 224 224 +48181 ./prep_dataset/ILSVRC2012_val_00019567.bin 224 224 +48182 ./prep_dataset/ILSVRC2012_val_00040288.bin 224 224 +48183 ./prep_dataset/ILSVRC2012_val_00000697.bin 224 224 +48184 ./prep_dataset/ILSVRC2012_val_00022038.bin 224 224 +48185 ./prep_dataset/ILSVRC2012_val_00028333.bin 224 224 +48186 ./prep_dataset/ILSVRC2012_val_00009432.bin 224 224 +48187 ./prep_dataset/ILSVRC2012_val_00017877.bin 224 224 +48188 ./prep_dataset/ILSVRC2012_val_00007504.bin 224 224 +48189 ./prep_dataset/ILSVRC2012_val_00028825.bin 224 224 +48190 ./prep_dataset/ILSVRC2012_val_00021325.bin 224 224 +48191 ./prep_dataset/ILSVRC2012_val_00023437.bin 224 224 +48192 ./prep_dataset/ILSVRC2012_val_00012008.bin 224 224 +48193 ./prep_dataset/ILSVRC2012_val_00005934.bin 224 224 +48194 ./prep_dataset/ILSVRC2012_val_00029086.bin 224 224 +48195 ./prep_dataset/ILSVRC2012_val_00038045.bin 224 224 +48196 ./prep_dataset/ILSVRC2012_val_00008587.bin 224 224 +48197 ./prep_dataset/ILSVRC2012_val_00007040.bin 224 224 +48198 ./prep_dataset/ILSVRC2012_val_00044448.bin 224 224 +48199 ./prep_dataset/ILSVRC2012_val_00013098.bin 224 224 +48200 ./prep_dataset/ILSVRC2012_val_00005213.bin 224 224 +48201 ./prep_dataset/ILSVRC2012_val_00002345.bin 224 224 +48202 ./prep_dataset/ILSVRC2012_val_00022530.bin 224 224 +48203 ./prep_dataset/ILSVRC2012_val_00049651.bin 224 224 +48204 ./prep_dataset/ILSVRC2012_val_00024845.bin 224 224 +48205 ./prep_dataset/ILSVRC2012_val_00026042.bin 224 224 +48206 ./prep_dataset/ILSVRC2012_val_00011057.bin 224 224 +48207 ./prep_dataset/ILSVRC2012_val_00036100.bin 224 224 +48208 ./prep_dataset/ILSVRC2012_val_00017746.bin 224 224 +48209 ./prep_dataset/ILSVRC2012_val_00010744.bin 224 224 +48210 ./prep_dataset/ILSVRC2012_val_00013435.bin 224 224 +48211 ./prep_dataset/ILSVRC2012_val_00004029.bin 224 224 +48212 ./prep_dataset/ILSVRC2012_val_00021836.bin 224 224 +48213 ./prep_dataset/ILSVRC2012_val_00038554.bin 224 224 +48214 ./prep_dataset/ILSVRC2012_val_00026608.bin 224 224 +48215 ./prep_dataset/ILSVRC2012_val_00013058.bin 224 224 +48216 ./prep_dataset/ILSVRC2012_val_00029307.bin 224 224 +48217 ./prep_dataset/ILSVRC2012_val_00035306.bin 224 224 +48218 ./prep_dataset/ILSVRC2012_val_00019412.bin 224 224 +48219 ./prep_dataset/ILSVRC2012_val_00038356.bin 224 224 +48220 ./prep_dataset/ILSVRC2012_val_00012012.bin 224 224 +48221 ./prep_dataset/ILSVRC2012_val_00020796.bin 224 224 +48222 ./prep_dataset/ILSVRC2012_val_00039583.bin 224 224 +48223 ./prep_dataset/ILSVRC2012_val_00049508.bin 224 224 +48224 ./prep_dataset/ILSVRC2012_val_00010139.bin 224 224 +48225 ./prep_dataset/ILSVRC2012_val_00013939.bin 224 224 +48226 ./prep_dataset/ILSVRC2012_val_00045560.bin 224 224 +48227 ./prep_dataset/ILSVRC2012_val_00048018.bin 224 224 +48228 ./prep_dataset/ILSVRC2012_val_00040296.bin 224 224 +48229 ./prep_dataset/ILSVRC2012_val_00048786.bin 224 224 +48230 ./prep_dataset/ILSVRC2012_val_00039557.bin 224 224 +48231 ./prep_dataset/ILSVRC2012_val_00024356.bin 224 224 +48232 ./prep_dataset/ILSVRC2012_val_00047012.bin 224 224 +48233 ./prep_dataset/ILSVRC2012_val_00047531.bin 224 224 +48234 ./prep_dataset/ILSVRC2012_val_00002690.bin 224 224 +48235 ./prep_dataset/ILSVRC2012_val_00013160.bin 224 224 +48236 ./prep_dataset/ILSVRC2012_val_00016079.bin 224 224 +48237 ./prep_dataset/ILSVRC2012_val_00036519.bin 224 224 +48238 ./prep_dataset/ILSVRC2012_val_00004309.bin 224 224 +48239 ./prep_dataset/ILSVRC2012_val_00039648.bin 224 224 +48240 ./prep_dataset/ILSVRC2012_val_00027096.bin 224 224 +48241 ./prep_dataset/ILSVRC2012_val_00011121.bin 224 224 +48242 ./prep_dataset/ILSVRC2012_val_00024794.bin 224 224 +48243 ./prep_dataset/ILSVRC2012_val_00002490.bin 224 224 +48244 ./prep_dataset/ILSVRC2012_val_00033090.bin 224 224 +48245 ./prep_dataset/ILSVRC2012_val_00046955.bin 224 224 +48246 ./prep_dataset/ILSVRC2012_val_00007856.bin 224 224 +48247 ./prep_dataset/ILSVRC2012_val_00018823.bin 224 224 +48248 ./prep_dataset/ILSVRC2012_val_00006284.bin 224 224 +48249 ./prep_dataset/ILSVRC2012_val_00027308.bin 224 224 +48250 ./prep_dataset/ILSVRC2012_val_00000382.bin 224 224 +48251 ./prep_dataset/ILSVRC2012_val_00034426.bin 224 224 +48252 ./prep_dataset/ILSVRC2012_val_00025233.bin 224 224 +48253 ./prep_dataset/ILSVRC2012_val_00009613.bin 224 224 +48254 ./prep_dataset/ILSVRC2012_val_00016931.bin 224 224 +48255 ./prep_dataset/ILSVRC2012_val_00019215.bin 224 224 +48256 ./prep_dataset/ILSVRC2012_val_00032265.bin 224 224 +48257 ./prep_dataset/ILSVRC2012_val_00039523.bin 224 224 +48258 ./prep_dataset/ILSVRC2012_val_00037709.bin 224 224 +48259 ./prep_dataset/ILSVRC2012_val_00015904.bin 224 224 +48260 ./prep_dataset/ILSVRC2012_val_00046518.bin 224 224 +48261 ./prep_dataset/ILSVRC2012_val_00026932.bin 224 224 +48262 ./prep_dataset/ILSVRC2012_val_00008967.bin 224 224 +48263 ./prep_dataset/ILSVRC2012_val_00029057.bin 224 224 +48264 ./prep_dataset/ILSVRC2012_val_00008109.bin 224 224 +48265 ./prep_dataset/ILSVRC2012_val_00049133.bin 224 224 +48266 ./prep_dataset/ILSVRC2012_val_00047241.bin 224 224 +48267 ./prep_dataset/ILSVRC2012_val_00006151.bin 224 224 +48268 ./prep_dataset/ILSVRC2012_val_00023191.bin 224 224 +48269 ./prep_dataset/ILSVRC2012_val_00043708.bin 224 224 +48270 ./prep_dataset/ILSVRC2012_val_00000560.bin 224 224 +48271 ./prep_dataset/ILSVRC2012_val_00041349.bin 224 224 +48272 ./prep_dataset/ILSVRC2012_val_00041923.bin 224 224 +48273 ./prep_dataset/ILSVRC2012_val_00015854.bin 224 224 +48274 ./prep_dataset/ILSVRC2012_val_00017076.bin 224 224 +48275 ./prep_dataset/ILSVRC2012_val_00047823.bin 224 224 +48276 ./prep_dataset/ILSVRC2012_val_00047373.bin 224 224 +48277 ./prep_dataset/ILSVRC2012_val_00032790.bin 224 224 +48278 ./prep_dataset/ILSVRC2012_val_00004486.bin 224 224 +48279 ./prep_dataset/ILSVRC2012_val_00013476.bin 224 224 +48280 ./prep_dataset/ILSVRC2012_val_00023381.bin 224 224 +48281 ./prep_dataset/ILSVRC2012_val_00009316.bin 224 224 +48282 ./prep_dataset/ILSVRC2012_val_00006992.bin 224 224 +48283 ./prep_dataset/ILSVRC2012_val_00039318.bin 224 224 +48284 ./prep_dataset/ILSVRC2012_val_00024969.bin 224 224 +48285 ./prep_dataset/ILSVRC2012_val_00033506.bin 224 224 +48286 ./prep_dataset/ILSVRC2012_val_00040633.bin 224 224 +48287 ./prep_dataset/ILSVRC2012_val_00046404.bin 224 224 +48288 ./prep_dataset/ILSVRC2012_val_00016203.bin 224 224 +48289 ./prep_dataset/ILSVRC2012_val_00034641.bin 224 224 +48290 ./prep_dataset/ILSVRC2012_val_00012711.bin 224 224 +48291 ./prep_dataset/ILSVRC2012_val_00039337.bin 224 224 +48292 ./prep_dataset/ILSVRC2012_val_00040318.bin 224 224 +48293 ./prep_dataset/ILSVRC2012_val_00012971.bin 224 224 +48294 ./prep_dataset/ILSVRC2012_val_00019992.bin 224 224 +48295 ./prep_dataset/ILSVRC2012_val_00005675.bin 224 224 +48296 ./prep_dataset/ILSVRC2012_val_00036062.bin 224 224 +48297 ./prep_dataset/ILSVRC2012_val_00047904.bin 224 224 +48298 ./prep_dataset/ILSVRC2012_val_00001226.bin 224 224 +48299 ./prep_dataset/ILSVRC2012_val_00042212.bin 224 224 +48300 ./prep_dataset/ILSVRC2012_val_00040528.bin 224 224 +48301 ./prep_dataset/ILSVRC2012_val_00012233.bin 224 224 +48302 ./prep_dataset/ILSVRC2012_val_00009027.bin 224 224 +48303 ./prep_dataset/ILSVRC2012_val_00009329.bin 224 224 +48304 ./prep_dataset/ILSVRC2012_val_00019183.bin 224 224 +48305 ./prep_dataset/ILSVRC2012_val_00010219.bin 224 224 +48306 ./prep_dataset/ILSVRC2012_val_00024275.bin 224 224 +48307 ./prep_dataset/ILSVRC2012_val_00029416.bin 224 224 +48308 ./prep_dataset/ILSVRC2012_val_00032458.bin 224 224 +48309 ./prep_dataset/ILSVRC2012_val_00034698.bin 224 224 +48310 ./prep_dataset/ILSVRC2012_val_00002155.bin 224 224 +48311 ./prep_dataset/ILSVRC2012_val_00000241.bin 224 224 +48312 ./prep_dataset/ILSVRC2012_val_00038375.bin 224 224 +48313 ./prep_dataset/ILSVRC2012_val_00021058.bin 224 224 +48314 ./prep_dataset/ILSVRC2012_val_00041807.bin 224 224 +48315 ./prep_dataset/ILSVRC2012_val_00026609.bin 224 224 +48316 ./prep_dataset/ILSVRC2012_val_00010437.bin 224 224 +48317 ./prep_dataset/ILSVRC2012_val_00017274.bin 224 224 +48318 ./prep_dataset/ILSVRC2012_val_00043715.bin 224 224 +48319 ./prep_dataset/ILSVRC2012_val_00025516.bin 224 224 +48320 ./prep_dataset/ILSVRC2012_val_00020444.bin 224 224 +48321 ./prep_dataset/ILSVRC2012_val_00045305.bin 224 224 +48322 ./prep_dataset/ILSVRC2012_val_00032336.bin 224 224 +48323 ./prep_dataset/ILSVRC2012_val_00029442.bin 224 224 +48324 ./prep_dataset/ILSVRC2012_val_00006063.bin 224 224 +48325 ./prep_dataset/ILSVRC2012_val_00032188.bin 224 224 +48326 ./prep_dataset/ILSVRC2012_val_00025149.bin 224 224 +48327 ./prep_dataset/ILSVRC2012_val_00043897.bin 224 224 +48328 ./prep_dataset/ILSVRC2012_val_00018542.bin 224 224 +48329 ./prep_dataset/ILSVRC2012_val_00045814.bin 224 224 +48330 ./prep_dataset/ILSVRC2012_val_00032663.bin 224 224 +48331 ./prep_dataset/ILSVRC2012_val_00038780.bin 224 224 +48332 ./prep_dataset/ILSVRC2012_val_00011670.bin 224 224 +48333 ./prep_dataset/ILSVRC2012_val_00024439.bin 224 224 +48334 ./prep_dataset/ILSVRC2012_val_00010796.bin 224 224 +48335 ./prep_dataset/ILSVRC2012_val_00013037.bin 224 224 +48336 ./prep_dataset/ILSVRC2012_val_00003780.bin 224 224 +48337 ./prep_dataset/ILSVRC2012_val_00045193.bin 224 224 +48338 ./prep_dataset/ILSVRC2012_val_00008503.bin 224 224 +48339 ./prep_dataset/ILSVRC2012_val_00007909.bin 224 224 +48340 ./prep_dataset/ILSVRC2012_val_00048841.bin 224 224 +48341 ./prep_dataset/ILSVRC2012_val_00009434.bin 224 224 +48342 ./prep_dataset/ILSVRC2012_val_00027288.bin 224 224 +48343 ./prep_dataset/ILSVRC2012_val_00017951.bin 224 224 +48344 ./prep_dataset/ILSVRC2012_val_00040504.bin 224 224 +48345 ./prep_dataset/ILSVRC2012_val_00012264.bin 224 224 +48346 ./prep_dataset/ILSVRC2012_val_00003248.bin 224 224 +48347 ./prep_dataset/ILSVRC2012_val_00044128.bin 224 224 +48348 ./prep_dataset/ILSVRC2012_val_00031154.bin 224 224 +48349 ./prep_dataset/ILSVRC2012_val_00038946.bin 224 224 +48350 ./prep_dataset/ILSVRC2012_val_00018956.bin 224 224 +48351 ./prep_dataset/ILSVRC2012_val_00008417.bin 224 224 +48352 ./prep_dataset/ILSVRC2012_val_00042343.bin 224 224 +48353 ./prep_dataset/ILSVRC2012_val_00046646.bin 224 224 +48354 ./prep_dataset/ILSVRC2012_val_00032775.bin 224 224 +48355 ./prep_dataset/ILSVRC2012_val_00046345.bin 224 224 +48356 ./prep_dataset/ILSVRC2012_val_00038135.bin 224 224 +48357 ./prep_dataset/ILSVRC2012_val_00048444.bin 224 224 +48358 ./prep_dataset/ILSVRC2012_val_00041736.bin 224 224 +48359 ./prep_dataset/ILSVRC2012_val_00013944.bin 224 224 +48360 ./prep_dataset/ILSVRC2012_val_00010710.bin 224 224 +48361 ./prep_dataset/ILSVRC2012_val_00034577.bin 224 224 +48362 ./prep_dataset/ILSVRC2012_val_00041352.bin 224 224 +48363 ./prep_dataset/ILSVRC2012_val_00039247.bin 224 224 +48364 ./prep_dataset/ILSVRC2012_val_00001048.bin 224 224 +48365 ./prep_dataset/ILSVRC2012_val_00034694.bin 224 224 +48366 ./prep_dataset/ILSVRC2012_val_00026217.bin 224 224 +48367 ./prep_dataset/ILSVRC2012_val_00027897.bin 224 224 +48368 ./prep_dataset/ILSVRC2012_val_00042163.bin 224 224 +48369 ./prep_dataset/ILSVRC2012_val_00017694.bin 224 224 +48370 ./prep_dataset/ILSVRC2012_val_00027230.bin 224 224 +48371 ./prep_dataset/ILSVRC2012_val_00000440.bin 224 224 +48372 ./prep_dataset/ILSVRC2012_val_00007517.bin 224 224 +48373 ./prep_dataset/ILSVRC2012_val_00040000.bin 224 224 +48374 ./prep_dataset/ILSVRC2012_val_00037677.bin 224 224 +48375 ./prep_dataset/ILSVRC2012_val_00020327.bin 224 224 +48376 ./prep_dataset/ILSVRC2012_val_00030140.bin 224 224 +48377 ./prep_dataset/ILSVRC2012_val_00007791.bin 224 224 +48378 ./prep_dataset/ILSVRC2012_val_00036395.bin 224 224 +48379 ./prep_dataset/ILSVRC2012_val_00020897.bin 224 224 +48380 ./prep_dataset/ILSVRC2012_val_00020970.bin 224 224 +48381 ./prep_dataset/ILSVRC2012_val_00018977.bin 224 224 +48382 ./prep_dataset/ILSVRC2012_val_00047616.bin 224 224 +48383 ./prep_dataset/ILSVRC2012_val_00033083.bin 224 224 +48384 ./prep_dataset/ILSVRC2012_val_00027654.bin 224 224 +48385 ./prep_dataset/ILSVRC2012_val_00000476.bin 224 224 +48386 ./prep_dataset/ILSVRC2012_val_00000581.bin 224 224 +48387 ./prep_dataset/ILSVRC2012_val_00018509.bin 224 224 +48388 ./prep_dataset/ILSVRC2012_val_00023551.bin 224 224 +48389 ./prep_dataset/ILSVRC2012_val_00015529.bin 224 224 +48390 ./prep_dataset/ILSVRC2012_val_00025179.bin 224 224 +48391 ./prep_dataset/ILSVRC2012_val_00035112.bin 224 224 +48392 ./prep_dataset/ILSVRC2012_val_00043640.bin 224 224 +48393 ./prep_dataset/ILSVRC2012_val_00049391.bin 224 224 +48394 ./prep_dataset/ILSVRC2012_val_00044970.bin 224 224 +48395 ./prep_dataset/ILSVRC2012_val_00034691.bin 224 224 +48396 ./prep_dataset/ILSVRC2012_val_00009406.bin 224 224 +48397 ./prep_dataset/ILSVRC2012_val_00028073.bin 224 224 +48398 ./prep_dataset/ILSVRC2012_val_00014484.bin 224 224 +48399 ./prep_dataset/ILSVRC2012_val_00029389.bin 224 224 +48400 ./prep_dataset/ILSVRC2012_val_00041218.bin 224 224 +48401 ./prep_dataset/ILSVRC2012_val_00016929.bin 224 224 +48402 ./prep_dataset/ILSVRC2012_val_00015462.bin 224 224 +48403 ./prep_dataset/ILSVRC2012_val_00033630.bin 224 224 +48404 ./prep_dataset/ILSVRC2012_val_00017682.bin 224 224 +48405 ./prep_dataset/ILSVRC2012_val_00010388.bin 224 224 +48406 ./prep_dataset/ILSVRC2012_val_00021487.bin 224 224 +48407 ./prep_dataset/ILSVRC2012_val_00021826.bin 224 224 +48408 ./prep_dataset/ILSVRC2012_val_00013997.bin 224 224 +48409 ./prep_dataset/ILSVRC2012_val_00040917.bin 224 224 +48410 ./prep_dataset/ILSVRC2012_val_00015296.bin 224 224 +48411 ./prep_dataset/ILSVRC2012_val_00024104.bin 224 224 +48412 ./prep_dataset/ILSVRC2012_val_00018295.bin 224 224 +48413 ./prep_dataset/ILSVRC2012_val_00023074.bin 224 224 +48414 ./prep_dataset/ILSVRC2012_val_00011680.bin 224 224 +48415 ./prep_dataset/ILSVRC2012_val_00009282.bin 224 224 +48416 ./prep_dataset/ILSVRC2012_val_00047901.bin 224 224 +48417 ./prep_dataset/ILSVRC2012_val_00028633.bin 224 224 +48418 ./prep_dataset/ILSVRC2012_val_00042236.bin 224 224 +48419 ./prep_dataset/ILSVRC2012_val_00020838.bin 224 224 +48420 ./prep_dataset/ILSVRC2012_val_00009047.bin 224 224 +48421 ./prep_dataset/ILSVRC2012_val_00031495.bin 224 224 +48422 ./prep_dataset/ILSVRC2012_val_00032823.bin 224 224 +48423 ./prep_dataset/ILSVRC2012_val_00041691.bin 224 224 +48424 ./prep_dataset/ILSVRC2012_val_00008254.bin 224 224 +48425 ./prep_dataset/ILSVRC2012_val_00032720.bin 224 224 +48426 ./prep_dataset/ILSVRC2012_val_00024544.bin 224 224 +48427 ./prep_dataset/ILSVRC2012_val_00015749.bin 224 224 +48428 ./prep_dataset/ILSVRC2012_val_00001654.bin 224 224 +48429 ./prep_dataset/ILSVRC2012_val_00048001.bin 224 224 +48430 ./prep_dataset/ILSVRC2012_val_00010576.bin 224 224 +48431 ./prep_dataset/ILSVRC2012_val_00009352.bin 224 224 +48432 ./prep_dataset/ILSVRC2012_val_00026433.bin 224 224 +48433 ./prep_dataset/ILSVRC2012_val_00047560.bin 224 224 +48434 ./prep_dataset/ILSVRC2012_val_00006415.bin 224 224 +48435 ./prep_dataset/ILSVRC2012_val_00006362.bin 224 224 +48436 ./prep_dataset/ILSVRC2012_val_00020360.bin 224 224 +48437 ./prep_dataset/ILSVRC2012_val_00017864.bin 224 224 +48438 ./prep_dataset/ILSVRC2012_val_00023491.bin 224 224 +48439 ./prep_dataset/ILSVRC2012_val_00003937.bin 224 224 +48440 ./prep_dataset/ILSVRC2012_val_00013104.bin 224 224 +48441 ./prep_dataset/ILSVRC2012_val_00015997.bin 224 224 +48442 ./prep_dataset/ILSVRC2012_val_00028115.bin 224 224 +48443 ./prep_dataset/ILSVRC2012_val_00006585.bin 224 224 +48444 ./prep_dataset/ILSVRC2012_val_00043900.bin 224 224 +48445 ./prep_dataset/ILSVRC2012_val_00025666.bin 224 224 +48446 ./prep_dataset/ILSVRC2012_val_00027591.bin 224 224 +48447 ./prep_dataset/ILSVRC2012_val_00033156.bin 224 224 +48448 ./prep_dataset/ILSVRC2012_val_00027966.bin 224 224 +48449 ./prep_dataset/ILSVRC2012_val_00043479.bin 224 224 +48450 ./prep_dataset/ILSVRC2012_val_00033196.bin 224 224 +48451 ./prep_dataset/ILSVRC2012_val_00024077.bin 224 224 +48452 ./prep_dataset/ILSVRC2012_val_00039876.bin 224 224 +48453 ./prep_dataset/ILSVRC2012_val_00006426.bin 224 224 +48454 ./prep_dataset/ILSVRC2012_val_00034373.bin 224 224 +48455 ./prep_dataset/ILSVRC2012_val_00035287.bin 224 224 +48456 ./prep_dataset/ILSVRC2012_val_00032040.bin 224 224 +48457 ./prep_dataset/ILSVRC2012_val_00004203.bin 224 224 +48458 ./prep_dataset/ILSVRC2012_val_00032957.bin 224 224 +48459 ./prep_dataset/ILSVRC2012_val_00011418.bin 224 224 +48460 ./prep_dataset/ILSVRC2012_val_00014452.bin 224 224 +48461 ./prep_dataset/ILSVRC2012_val_00018448.bin 224 224 +48462 ./prep_dataset/ILSVRC2012_val_00047416.bin 224 224 +48463 ./prep_dataset/ILSVRC2012_val_00025110.bin 224 224 +48464 ./prep_dataset/ILSVRC2012_val_00027398.bin 224 224 +48465 ./prep_dataset/ILSVRC2012_val_00035626.bin 224 224 +48466 ./prep_dataset/ILSVRC2012_val_00042464.bin 224 224 +48467 ./prep_dataset/ILSVRC2012_val_00020623.bin 224 224 +48468 ./prep_dataset/ILSVRC2012_val_00020850.bin 224 224 +48469 ./prep_dataset/ILSVRC2012_val_00005788.bin 224 224 +48470 ./prep_dataset/ILSVRC2012_val_00047488.bin 224 224 +48471 ./prep_dataset/ILSVRC2012_val_00005680.bin 224 224 +48472 ./prep_dataset/ILSVRC2012_val_00037822.bin 224 224 +48473 ./prep_dataset/ILSVRC2012_val_00022367.bin 224 224 +48474 ./prep_dataset/ILSVRC2012_val_00028049.bin 224 224 +48475 ./prep_dataset/ILSVRC2012_val_00036240.bin 224 224 +48476 ./prep_dataset/ILSVRC2012_val_00018373.bin 224 224 +48477 ./prep_dataset/ILSVRC2012_val_00046245.bin 224 224 +48478 ./prep_dataset/ILSVRC2012_val_00032585.bin 224 224 +48479 ./prep_dataset/ILSVRC2012_val_00010343.bin 224 224 +48480 ./prep_dataset/ILSVRC2012_val_00025026.bin 224 224 +48481 ./prep_dataset/ILSVRC2012_val_00040959.bin 224 224 +48482 ./prep_dataset/ILSVRC2012_val_00038341.bin 224 224 +48483 ./prep_dataset/ILSVRC2012_val_00009807.bin 224 224 +48484 ./prep_dataset/ILSVRC2012_val_00045543.bin 224 224 +48485 ./prep_dataset/ILSVRC2012_val_00010798.bin 224 224 +48486 ./prep_dataset/ILSVRC2012_val_00045725.bin 224 224 +48487 ./prep_dataset/ILSVRC2012_val_00003337.bin 224 224 +48488 ./prep_dataset/ILSVRC2012_val_00019965.bin 224 224 +48489 ./prep_dataset/ILSVRC2012_val_00048697.bin 224 224 +48490 ./prep_dataset/ILSVRC2012_val_00026953.bin 224 224 +48491 ./prep_dataset/ILSVRC2012_val_00020337.bin 224 224 +48492 ./prep_dataset/ILSVRC2012_val_00023102.bin 224 224 +48493 ./prep_dataset/ILSVRC2012_val_00014019.bin 224 224 +48494 ./prep_dataset/ILSVRC2012_val_00002269.bin 224 224 +48495 ./prep_dataset/ILSVRC2012_val_00016816.bin 224 224 +48496 ./prep_dataset/ILSVRC2012_val_00038982.bin 224 224 +48497 ./prep_dataset/ILSVRC2012_val_00028514.bin 224 224 +48498 ./prep_dataset/ILSVRC2012_val_00006295.bin 224 224 +48499 ./prep_dataset/ILSVRC2012_val_00013500.bin 224 224 +48500 ./prep_dataset/ILSVRC2012_val_00039430.bin 224 224 +48501 ./prep_dataset/ILSVRC2012_val_00006156.bin 224 224 +48502 ./prep_dataset/ILSVRC2012_val_00010369.bin 224 224 +48503 ./prep_dataset/ILSVRC2012_val_00017320.bin 224 224 +48504 ./prep_dataset/ILSVRC2012_val_00025641.bin 224 224 +48505 ./prep_dataset/ILSVRC2012_val_00035797.bin 224 224 +48506 ./prep_dataset/ILSVRC2012_val_00021230.bin 224 224 +48507 ./prep_dataset/ILSVRC2012_val_00010363.bin 224 224 +48508 ./prep_dataset/ILSVRC2012_val_00016361.bin 224 224 +48509 ./prep_dataset/ILSVRC2012_val_00048736.bin 224 224 +48510 ./prep_dataset/ILSVRC2012_val_00043135.bin 224 224 +48511 ./prep_dataset/ILSVRC2012_val_00025870.bin 224 224 +48512 ./prep_dataset/ILSVRC2012_val_00043987.bin 224 224 +48513 ./prep_dataset/ILSVRC2012_val_00017399.bin 224 224 +48514 ./prep_dataset/ILSVRC2012_val_00018144.bin 224 224 +48515 ./prep_dataset/ILSVRC2012_val_00024536.bin 224 224 +48516 ./prep_dataset/ILSVRC2012_val_00022631.bin 224 224 +48517 ./prep_dataset/ILSVRC2012_val_00024459.bin 224 224 +48518 ./prep_dataset/ILSVRC2012_val_00045864.bin 224 224 +48519 ./prep_dataset/ILSVRC2012_val_00021415.bin 224 224 +48520 ./prep_dataset/ILSVRC2012_val_00011673.bin 224 224 +48521 ./prep_dataset/ILSVRC2012_val_00017265.bin 224 224 +48522 ./prep_dataset/ILSVRC2012_val_00037891.bin 224 224 +48523 ./prep_dataset/ILSVRC2012_val_00026807.bin 224 224 +48524 ./prep_dataset/ILSVRC2012_val_00016978.bin 224 224 +48525 ./prep_dataset/ILSVRC2012_val_00035396.bin 224 224 +48526 ./prep_dataset/ILSVRC2012_val_00001440.bin 224 224 +48527 ./prep_dataset/ILSVRC2012_val_00028848.bin 224 224 +48528 ./prep_dataset/ILSVRC2012_val_00000554.bin 224 224 +48529 ./prep_dataset/ILSVRC2012_val_00043101.bin 224 224 +48530 ./prep_dataset/ILSVRC2012_val_00002560.bin 224 224 +48531 ./prep_dataset/ILSVRC2012_val_00039638.bin 224 224 +48532 ./prep_dataset/ILSVRC2012_val_00047469.bin 224 224 +48533 ./prep_dataset/ILSVRC2012_val_00008196.bin 224 224 +48534 ./prep_dataset/ILSVRC2012_val_00049284.bin 224 224 +48535 ./prep_dataset/ILSVRC2012_val_00046849.bin 224 224 +48536 ./prep_dataset/ILSVRC2012_val_00024995.bin 224 224 +48537 ./prep_dataset/ILSVRC2012_val_00025030.bin 224 224 +48538 ./prep_dataset/ILSVRC2012_val_00023009.bin 224 224 +48539 ./prep_dataset/ILSVRC2012_val_00009495.bin 224 224 +48540 ./prep_dataset/ILSVRC2012_val_00046051.bin 224 224 +48541 ./prep_dataset/ILSVRC2012_val_00018034.bin 224 224 +48542 ./prep_dataset/ILSVRC2012_val_00016324.bin 224 224 +48543 ./prep_dataset/ILSVRC2012_val_00045636.bin 224 224 +48544 ./prep_dataset/ILSVRC2012_val_00039661.bin 224 224 +48545 ./prep_dataset/ILSVRC2012_val_00007045.bin 224 224 +48546 ./prep_dataset/ILSVRC2012_val_00022779.bin 224 224 +48547 ./prep_dataset/ILSVRC2012_val_00026171.bin 224 224 +48548 ./prep_dataset/ILSVRC2012_val_00029297.bin 224 224 +48549 ./prep_dataset/ILSVRC2012_val_00018701.bin 224 224 +48550 ./prep_dataset/ILSVRC2012_val_00021340.bin 224 224 +48551 ./prep_dataset/ILSVRC2012_val_00040393.bin 224 224 +48552 ./prep_dataset/ILSVRC2012_val_00043549.bin 224 224 +48553 ./prep_dataset/ILSVRC2012_val_00048381.bin 224 224 +48554 ./prep_dataset/ILSVRC2012_val_00043815.bin 224 224 +48555 ./prep_dataset/ILSVRC2012_val_00035775.bin 224 224 +48556 ./prep_dataset/ILSVRC2012_val_00049408.bin 224 224 +48557 ./prep_dataset/ILSVRC2012_val_00000832.bin 224 224 +48558 ./prep_dataset/ILSVRC2012_val_00037588.bin 224 224 +48559 ./prep_dataset/ILSVRC2012_val_00015307.bin 224 224 +48560 ./prep_dataset/ILSVRC2012_val_00028874.bin 224 224 +48561 ./prep_dataset/ILSVRC2012_val_00048923.bin 224 224 +48562 ./prep_dataset/ILSVRC2012_val_00011446.bin 224 224 +48563 ./prep_dataset/ILSVRC2012_val_00009115.bin 224 224 +48564 ./prep_dataset/ILSVRC2012_val_00013503.bin 224 224 +48565 ./prep_dataset/ILSVRC2012_val_00005317.bin 224 224 +48566 ./prep_dataset/ILSVRC2012_val_00044814.bin 224 224 +48567 ./prep_dataset/ILSVRC2012_val_00022319.bin 224 224 +48568 ./prep_dataset/ILSVRC2012_val_00035144.bin 224 224 +48569 ./prep_dataset/ILSVRC2012_val_00031651.bin 224 224 +48570 ./prep_dataset/ILSVRC2012_val_00028224.bin 224 224 +48571 ./prep_dataset/ILSVRC2012_val_00000174.bin 224 224 +48572 ./prep_dataset/ILSVRC2012_val_00004348.bin 224 224 +48573 ./prep_dataset/ILSVRC2012_val_00046083.bin 224 224 +48574 ./prep_dataset/ILSVRC2012_val_00034363.bin 224 224 +48575 ./prep_dataset/ILSVRC2012_val_00027527.bin 224 224 +48576 ./prep_dataset/ILSVRC2012_val_00047326.bin 224 224 +48577 ./prep_dataset/ILSVRC2012_val_00021438.bin 224 224 +48578 ./prep_dataset/ILSVRC2012_val_00009579.bin 224 224 +48579 ./prep_dataset/ILSVRC2012_val_00001197.bin 224 224 +48580 ./prep_dataset/ILSVRC2012_val_00033229.bin 224 224 +48581 ./prep_dataset/ILSVRC2012_val_00046821.bin 224 224 +48582 ./prep_dataset/ILSVRC2012_val_00044084.bin 224 224 +48583 ./prep_dataset/ILSVRC2012_val_00031789.bin 224 224 +48584 ./prep_dataset/ILSVRC2012_val_00034915.bin 224 224 +48585 ./prep_dataset/ILSVRC2012_val_00026126.bin 224 224 +48586 ./prep_dataset/ILSVRC2012_val_00036320.bin 224 224 +48587 ./prep_dataset/ILSVRC2012_val_00021011.bin 224 224 +48588 ./prep_dataset/ILSVRC2012_val_00043378.bin 224 224 +48589 ./prep_dataset/ILSVRC2012_val_00028385.bin 224 224 +48590 ./prep_dataset/ILSVRC2012_val_00002542.bin 224 224 +48591 ./prep_dataset/ILSVRC2012_val_00011163.bin 224 224 +48592 ./prep_dataset/ILSVRC2012_val_00021801.bin 224 224 +48593 ./prep_dataset/ILSVRC2012_val_00038636.bin 224 224 +48594 ./prep_dataset/ILSVRC2012_val_00025251.bin 224 224 +48595 ./prep_dataset/ILSVRC2012_val_00042728.bin 224 224 +48596 ./prep_dataset/ILSVRC2012_val_00037975.bin 224 224 +48597 ./prep_dataset/ILSVRC2012_val_00047387.bin 224 224 +48598 ./prep_dataset/ILSVRC2012_val_00014511.bin 224 224 +48599 ./prep_dataset/ILSVRC2012_val_00021687.bin 224 224 +48600 ./prep_dataset/ILSVRC2012_val_00026331.bin 224 224 +48601 ./prep_dataset/ILSVRC2012_val_00014658.bin 224 224 +48602 ./prep_dataset/ILSVRC2012_val_00023391.bin 224 224 +48603 ./prep_dataset/ILSVRC2012_val_00014594.bin 224 224 +48604 ./prep_dataset/ILSVRC2012_val_00013518.bin 224 224 +48605 ./prep_dataset/ILSVRC2012_val_00048349.bin 224 224 +48606 ./prep_dataset/ILSVRC2012_val_00048610.bin 224 224 +48607 ./prep_dataset/ILSVRC2012_val_00009686.bin 224 224 +48608 ./prep_dataset/ILSVRC2012_val_00015095.bin 224 224 +48609 ./prep_dataset/ILSVRC2012_val_00028710.bin 224 224 +48610 ./prep_dataset/ILSVRC2012_val_00017873.bin 224 224 +48611 ./prep_dataset/ILSVRC2012_val_00013923.bin 224 224 +48612 ./prep_dataset/ILSVRC2012_val_00032366.bin 224 224 +48613 ./prep_dataset/ILSVRC2012_val_00007855.bin 224 224 +48614 ./prep_dataset/ILSVRC2012_val_00043287.bin 224 224 +48615 ./prep_dataset/ILSVRC2012_val_00020764.bin 224 224 +48616 ./prep_dataset/ILSVRC2012_val_00031871.bin 224 224 +48617 ./prep_dataset/ILSVRC2012_val_00008496.bin 224 224 +48618 ./prep_dataset/ILSVRC2012_val_00001828.bin 224 224 +48619 ./prep_dataset/ILSVRC2012_val_00010658.bin 224 224 +48620 ./prep_dataset/ILSVRC2012_val_00017230.bin 224 224 +48621 ./prep_dataset/ILSVRC2012_val_00009790.bin 224 224 +48622 ./prep_dataset/ILSVRC2012_val_00017898.bin 224 224 +48623 ./prep_dataset/ILSVRC2012_val_00024485.bin 224 224 +48624 ./prep_dataset/ILSVRC2012_val_00040795.bin 224 224 +48625 ./prep_dataset/ILSVRC2012_val_00016005.bin 224 224 +48626 ./prep_dataset/ILSVRC2012_val_00005713.bin 224 224 +48627 ./prep_dataset/ILSVRC2012_val_00036141.bin 224 224 +48628 ./prep_dataset/ILSVRC2012_val_00028238.bin 224 224 +48629 ./prep_dataset/ILSVRC2012_val_00037030.bin 224 224 +48630 ./prep_dataset/ILSVRC2012_val_00048175.bin 224 224 +48631 ./prep_dataset/ILSVRC2012_val_00011486.bin 224 224 +48632 ./prep_dataset/ILSVRC2012_val_00046412.bin 224 224 +48633 ./prep_dataset/ILSVRC2012_val_00019706.bin 224 224 +48634 ./prep_dataset/ILSVRC2012_val_00022702.bin 224 224 +48635 ./prep_dataset/ILSVRC2012_val_00006411.bin 224 224 +48636 ./prep_dataset/ILSVRC2012_val_00010644.bin 224 224 +48637 ./prep_dataset/ILSVRC2012_val_00010272.bin 224 224 +48638 ./prep_dataset/ILSVRC2012_val_00023614.bin 224 224 +48639 ./prep_dataset/ILSVRC2012_val_00018577.bin 224 224 +48640 ./prep_dataset/ILSVRC2012_val_00015692.bin 224 224 +48641 ./prep_dataset/ILSVRC2012_val_00018763.bin 224 224 +48642 ./prep_dataset/ILSVRC2012_val_00009943.bin 224 224 +48643 ./prep_dataset/ILSVRC2012_val_00003647.bin 224 224 +48644 ./prep_dataset/ILSVRC2012_val_00045514.bin 224 224 +48645 ./prep_dataset/ILSVRC2012_val_00019210.bin 224 224 +48646 ./prep_dataset/ILSVRC2012_val_00020470.bin 224 224 +48647 ./prep_dataset/ILSVRC2012_val_00020292.bin 224 224 +48648 ./prep_dataset/ILSVRC2012_val_00025930.bin 224 224 +48649 ./prep_dataset/ILSVRC2012_val_00016339.bin 224 224 +48650 ./prep_dataset/ILSVRC2012_val_00035438.bin 224 224 +48651 ./prep_dataset/ILSVRC2012_val_00003740.bin 224 224 +48652 ./prep_dataset/ILSVRC2012_val_00035624.bin 224 224 +48653 ./prep_dataset/ILSVRC2012_val_00004458.bin 224 224 +48654 ./prep_dataset/ILSVRC2012_val_00005672.bin 224 224 +48655 ./prep_dataset/ILSVRC2012_val_00038336.bin 224 224 +48656 ./prep_dataset/ILSVRC2012_val_00034033.bin 224 224 +48657 ./prep_dataset/ILSVRC2012_val_00038394.bin 224 224 +48658 ./prep_dataset/ILSVRC2012_val_00045477.bin 224 224 +48659 ./prep_dataset/ILSVRC2012_val_00003297.bin 224 224 +48660 ./prep_dataset/ILSVRC2012_val_00045732.bin 224 224 +48661 ./prep_dataset/ILSVRC2012_val_00005353.bin 224 224 +48662 ./prep_dataset/ILSVRC2012_val_00048103.bin 224 224 +48663 ./prep_dataset/ILSVRC2012_val_00018106.bin 224 224 +48664 ./prep_dataset/ILSVRC2012_val_00041974.bin 224 224 +48665 ./prep_dataset/ILSVRC2012_val_00019018.bin 224 224 +48666 ./prep_dataset/ILSVRC2012_val_00042991.bin 224 224 +48667 ./prep_dataset/ILSVRC2012_val_00026129.bin 224 224 +48668 ./prep_dataset/ILSVRC2012_val_00002517.bin 224 224 +48669 ./prep_dataset/ILSVRC2012_val_00004173.bin 224 224 +48670 ./prep_dataset/ILSVRC2012_val_00007583.bin 224 224 +48671 ./prep_dataset/ILSVRC2012_val_00045939.bin 224 224 +48672 ./prep_dataset/ILSVRC2012_val_00035283.bin 224 224 +48673 ./prep_dataset/ILSVRC2012_val_00032141.bin 224 224 +48674 ./prep_dataset/ILSVRC2012_val_00008547.bin 224 224 +48675 ./prep_dataset/ILSVRC2012_val_00017511.bin 224 224 +48676 ./prep_dataset/ILSVRC2012_val_00000265.bin 224 224 +48677 ./prep_dataset/ILSVRC2012_val_00013864.bin 224 224 +48678 ./prep_dataset/ILSVRC2012_val_00006493.bin 224 224 +48679 ./prep_dataset/ILSVRC2012_val_00036688.bin 224 224 +48680 ./prep_dataset/ILSVRC2012_val_00041633.bin 224 224 +48681 ./prep_dataset/ILSVRC2012_val_00029046.bin 224 224 +48682 ./prep_dataset/ILSVRC2012_val_00005716.bin 224 224 +48683 ./prep_dataset/ILSVRC2012_val_00030349.bin 224 224 +48684 ./prep_dataset/ILSVRC2012_val_00046669.bin 224 224 +48685 ./prep_dataset/ILSVRC2012_val_00017634.bin 224 224 +48686 ./prep_dataset/ILSVRC2012_val_00014210.bin 224 224 +48687 ./prep_dataset/ILSVRC2012_val_00015676.bin 224 224 +48688 ./prep_dataset/ILSVRC2012_val_00011781.bin 224 224 +48689 ./prep_dataset/ILSVRC2012_val_00038066.bin 224 224 +48690 ./prep_dataset/ILSVRC2012_val_00041560.bin 224 224 +48691 ./prep_dataset/ILSVRC2012_val_00036147.bin 224 224 +48692 ./prep_dataset/ILSVRC2012_val_00043035.bin 224 224 +48693 ./prep_dataset/ILSVRC2012_val_00003604.bin 224 224 +48694 ./prep_dataset/ILSVRC2012_val_00021360.bin 224 224 +48695 ./prep_dataset/ILSVRC2012_val_00032872.bin 224 224 +48696 ./prep_dataset/ILSVRC2012_val_00022596.bin 224 224 +48697 ./prep_dataset/ILSVRC2012_val_00004944.bin 224 224 +48698 ./prep_dataset/ILSVRC2012_val_00049774.bin 224 224 +48699 ./prep_dataset/ILSVRC2012_val_00037981.bin 224 224 +48700 ./prep_dataset/ILSVRC2012_val_00045284.bin 224 224 +48701 ./prep_dataset/ILSVRC2012_val_00034203.bin 224 224 +48702 ./prep_dataset/ILSVRC2012_val_00019578.bin 224 224 +48703 ./prep_dataset/ILSVRC2012_val_00018824.bin 224 224 +48704 ./prep_dataset/ILSVRC2012_val_00013640.bin 224 224 +48705 ./prep_dataset/ILSVRC2012_val_00032493.bin 224 224 +48706 ./prep_dataset/ILSVRC2012_val_00012980.bin 224 224 +48707 ./prep_dataset/ILSVRC2012_val_00015022.bin 224 224 +48708 ./prep_dataset/ILSVRC2012_val_00045677.bin 224 224 +48709 ./prep_dataset/ILSVRC2012_val_00016747.bin 224 224 +48710 ./prep_dataset/ILSVRC2012_val_00027436.bin 224 224 +48711 ./prep_dataset/ILSVRC2012_val_00041380.bin 224 224 +48712 ./prep_dataset/ILSVRC2012_val_00018589.bin 224 224 +48713 ./prep_dataset/ILSVRC2012_val_00045131.bin 224 224 +48714 ./prep_dataset/ILSVRC2012_val_00017064.bin 224 224 +48715 ./prep_dataset/ILSVRC2012_val_00025244.bin 224 224 +48716 ./prep_dataset/ILSVRC2012_val_00032965.bin 224 224 +48717 ./prep_dataset/ILSVRC2012_val_00001713.bin 224 224 +48718 ./prep_dataset/ILSVRC2012_val_00046263.bin 224 224 +48719 ./prep_dataset/ILSVRC2012_val_00047537.bin 224 224 +48720 ./prep_dataset/ILSVRC2012_val_00038509.bin 224 224 +48721 ./prep_dataset/ILSVRC2012_val_00007371.bin 224 224 +48722 ./prep_dataset/ILSVRC2012_val_00012515.bin 224 224 +48723 ./prep_dataset/ILSVRC2012_val_00043255.bin 224 224 +48724 ./prep_dataset/ILSVRC2012_val_00038587.bin 224 224 +48725 ./prep_dataset/ILSVRC2012_val_00043937.bin 224 224 +48726 ./prep_dataset/ILSVRC2012_val_00032432.bin 224 224 +48727 ./prep_dataset/ILSVRC2012_val_00016364.bin 224 224 +48728 ./prep_dataset/ILSVRC2012_val_00029269.bin 224 224 +48729 ./prep_dataset/ILSVRC2012_val_00044262.bin 224 224 +48730 ./prep_dataset/ILSVRC2012_val_00041120.bin 224 224 +48731 ./prep_dataset/ILSVRC2012_val_00032445.bin 224 224 +48732 ./prep_dataset/ILSVRC2012_val_00008654.bin 224 224 +48733 ./prep_dataset/ILSVRC2012_val_00016244.bin 224 224 +48734 ./prep_dataset/ILSVRC2012_val_00045712.bin 224 224 +48735 ./prep_dataset/ILSVRC2012_val_00027334.bin 224 224 +48736 ./prep_dataset/ILSVRC2012_val_00003400.bin 224 224 +48737 ./prep_dataset/ILSVRC2012_val_00028816.bin 224 224 +48738 ./prep_dataset/ILSVRC2012_val_00019400.bin 224 224 +48739 ./prep_dataset/ILSVRC2012_val_00004988.bin 224 224 +48740 ./prep_dataset/ILSVRC2012_val_00004560.bin 224 224 +48741 ./prep_dataset/ILSVRC2012_val_00031593.bin 224 224 +48742 ./prep_dataset/ILSVRC2012_val_00016991.bin 224 224 +48743 ./prep_dataset/ILSVRC2012_val_00036803.bin 224 224 +48744 ./prep_dataset/ILSVRC2012_val_00012499.bin 224 224 +48745 ./prep_dataset/ILSVRC2012_val_00047022.bin 224 224 +48746 ./prep_dataset/ILSVRC2012_val_00018380.bin 224 224 +48747 ./prep_dataset/ILSVRC2012_val_00043989.bin 224 224 +48748 ./prep_dataset/ILSVRC2012_val_00048437.bin 224 224 +48749 ./prep_dataset/ILSVRC2012_val_00022575.bin 224 224 +48750 ./prep_dataset/ILSVRC2012_val_00023689.bin 224 224 +48751 ./prep_dataset/ILSVRC2012_val_00048718.bin 224 224 +48752 ./prep_dataset/ILSVRC2012_val_00011172.bin 224 224 +48753 ./prep_dataset/ILSVRC2012_val_00039965.bin 224 224 +48754 ./prep_dataset/ILSVRC2012_val_00001463.bin 224 224 +48755 ./prep_dataset/ILSVRC2012_val_00000857.bin 224 224 +48756 ./prep_dataset/ILSVRC2012_val_00006260.bin 224 224 +48757 ./prep_dataset/ILSVRC2012_val_00009857.bin 224 224 +48758 ./prep_dataset/ILSVRC2012_val_00005718.bin 224 224 +48759 ./prep_dataset/ILSVRC2012_val_00007747.bin 224 224 +48760 ./prep_dataset/ILSVRC2012_val_00025500.bin 224 224 +48761 ./prep_dataset/ILSVRC2012_val_00019111.bin 224 224 +48762 ./prep_dataset/ILSVRC2012_val_00025193.bin 224 224 +48763 ./prep_dataset/ILSVRC2012_val_00036701.bin 224 224 +48764 ./prep_dataset/ILSVRC2012_val_00038619.bin 224 224 +48765 ./prep_dataset/ILSVRC2012_val_00023495.bin 224 224 +48766 ./prep_dataset/ILSVRC2012_val_00047031.bin 224 224 +48767 ./prep_dataset/ILSVRC2012_val_00039388.bin 224 224 +48768 ./prep_dataset/ILSVRC2012_val_00028051.bin 224 224 +48769 ./prep_dataset/ILSVRC2012_val_00010830.bin 224 224 +48770 ./prep_dataset/ILSVRC2012_val_00010608.bin 224 224 +48771 ./prep_dataset/ILSVRC2012_val_00034877.bin 224 224 +48772 ./prep_dataset/ILSVRC2012_val_00049832.bin 224 224 +48773 ./prep_dataset/ILSVRC2012_val_00049657.bin 224 224 +48774 ./prep_dataset/ILSVRC2012_val_00006348.bin 224 224 +48775 ./prep_dataset/ILSVRC2012_val_00014791.bin 224 224 +48776 ./prep_dataset/ILSVRC2012_val_00045938.bin 224 224 +48777 ./prep_dataset/ILSVRC2012_val_00035969.bin 224 224 +48778 ./prep_dataset/ILSVRC2012_val_00017345.bin 224 224 +48779 ./prep_dataset/ILSVRC2012_val_00047110.bin 224 224 +48780 ./prep_dataset/ILSVRC2012_val_00016050.bin 224 224 +48781 ./prep_dataset/ILSVRC2012_val_00019389.bin 224 224 +48782 ./prep_dataset/ILSVRC2012_val_00047052.bin 224 224 +48783 ./prep_dataset/ILSVRC2012_val_00037557.bin 224 224 +48784 ./prep_dataset/ILSVRC2012_val_00009761.bin 224 224 +48785 ./prep_dataset/ILSVRC2012_val_00003222.bin 224 224 +48786 ./prep_dataset/ILSVRC2012_val_00011654.bin 224 224 +48787 ./prep_dataset/ILSVRC2012_val_00049051.bin 224 224 +48788 ./prep_dataset/ILSVRC2012_val_00022620.bin 224 224 +48789 ./prep_dataset/ILSVRC2012_val_00010965.bin 224 224 +48790 ./prep_dataset/ILSVRC2012_val_00039821.bin 224 224 +48791 ./prep_dataset/ILSVRC2012_val_00030641.bin 224 224 +48792 ./prep_dataset/ILSVRC2012_val_00036535.bin 224 224 +48793 ./prep_dataset/ILSVRC2012_val_00023916.bin 224 224 +48794 ./prep_dataset/ILSVRC2012_val_00024080.bin 224 224 +48795 ./prep_dataset/ILSVRC2012_val_00002797.bin 224 224 +48796 ./prep_dataset/ILSVRC2012_val_00023868.bin 224 224 +48797 ./prep_dataset/ILSVRC2012_val_00039453.bin 224 224 +48798 ./prep_dataset/ILSVRC2012_val_00005426.bin 224 224 +48799 ./prep_dataset/ILSVRC2012_val_00002031.bin 224 224 +48800 ./prep_dataset/ILSVRC2012_val_00040230.bin 224 224 +48801 ./prep_dataset/ILSVRC2012_val_00039462.bin 224 224 +48802 ./prep_dataset/ILSVRC2012_val_00021244.bin 224 224 +48803 ./prep_dataset/ILSVRC2012_val_00000673.bin 224 224 +48804 ./prep_dataset/ILSVRC2012_val_00049578.bin 224 224 +48805 ./prep_dataset/ILSVRC2012_val_00009866.bin 224 224 +48806 ./prep_dataset/ILSVRC2012_val_00032288.bin 224 224 +48807 ./prep_dataset/ILSVRC2012_val_00002005.bin 224 224 +48808 ./prep_dataset/ILSVRC2012_val_00049462.bin 224 224 +48809 ./prep_dataset/ILSVRC2012_val_00016486.bin 224 224 +48810 ./prep_dataset/ILSVRC2012_val_00009634.bin 224 224 +48811 ./prep_dataset/ILSVRC2012_val_00002291.bin 224 224 +48812 ./prep_dataset/ILSVRC2012_val_00004127.bin 224 224 +48813 ./prep_dataset/ILSVRC2012_val_00047454.bin 224 224 +48814 ./prep_dataset/ILSVRC2012_val_00033936.bin 224 224 +48815 ./prep_dataset/ILSVRC2012_val_00012087.bin 224 224 +48816 ./prep_dataset/ILSVRC2012_val_00041237.bin 224 224 +48817 ./prep_dataset/ILSVRC2012_val_00035175.bin 224 224 +48818 ./prep_dataset/ILSVRC2012_val_00023140.bin 224 224 +48819 ./prep_dataset/ILSVRC2012_val_00003764.bin 224 224 +48820 ./prep_dataset/ILSVRC2012_val_00003160.bin 224 224 +48821 ./prep_dataset/ILSVRC2012_val_00024550.bin 224 224 +48822 ./prep_dataset/ILSVRC2012_val_00044454.bin 224 224 +48823 ./prep_dataset/ILSVRC2012_val_00033911.bin 224 224 +48824 ./prep_dataset/ILSVRC2012_val_00025168.bin 224 224 +48825 ./prep_dataset/ILSVRC2012_val_00042112.bin 224 224 +48826 ./prep_dataset/ILSVRC2012_val_00003529.bin 224 224 +48827 ./prep_dataset/ILSVRC2012_val_00010050.bin 224 224 +48828 ./prep_dataset/ILSVRC2012_val_00041530.bin 224 224 +48829 ./prep_dataset/ILSVRC2012_val_00047658.bin 224 224 +48830 ./prep_dataset/ILSVRC2012_val_00034257.bin 224 224 +48831 ./prep_dataset/ILSVRC2012_val_00041699.bin 224 224 +48832 ./prep_dataset/ILSVRC2012_val_00002522.bin 224 224 +48833 ./prep_dataset/ILSVRC2012_val_00025218.bin 224 224 +48834 ./prep_dataset/ILSVRC2012_val_00023343.bin 224 224 +48835 ./prep_dataset/ILSVRC2012_val_00015647.bin 224 224 +48836 ./prep_dataset/ILSVRC2012_val_00024958.bin 224 224 +48837 ./prep_dataset/ILSVRC2012_val_00009639.bin 224 224 +48838 ./prep_dataset/ILSVRC2012_val_00006177.bin 224 224 +48839 ./prep_dataset/ILSVRC2012_val_00034807.bin 224 224 +48840 ./prep_dataset/ILSVRC2012_val_00044537.bin 224 224 +48841 ./prep_dataset/ILSVRC2012_val_00025887.bin 224 224 +48842 ./prep_dataset/ILSVRC2012_val_00015337.bin 224 224 +48843 ./prep_dataset/ILSVRC2012_val_00039822.bin 224 224 +48844 ./prep_dataset/ILSVRC2012_val_00021761.bin 224 224 +48845 ./prep_dataset/ILSVRC2012_val_00043421.bin 224 224 +48846 ./prep_dataset/ILSVRC2012_val_00017199.bin 224 224 +48847 ./prep_dataset/ILSVRC2012_val_00034796.bin 224 224 +48848 ./prep_dataset/ILSVRC2012_val_00045237.bin 224 224 +48849 ./prep_dataset/ILSVRC2012_val_00000401.bin 224 224 +48850 ./prep_dataset/ILSVRC2012_val_00033262.bin 224 224 +48851 ./prep_dataset/ILSVRC2012_val_00046501.bin 224 224 +48852 ./prep_dataset/ILSVRC2012_val_00024639.bin 224 224 +48853 ./prep_dataset/ILSVRC2012_val_00027993.bin 224 224 +48854 ./prep_dataset/ILSVRC2012_val_00025577.bin 224 224 +48855 ./prep_dataset/ILSVRC2012_val_00026256.bin 224 224 +48856 ./prep_dataset/ILSVRC2012_val_00041582.bin 224 224 +48857 ./prep_dataset/ILSVRC2012_val_00041683.bin 224 224 +48858 ./prep_dataset/ILSVRC2012_val_00039565.bin 224 224 +48859 ./prep_dataset/ILSVRC2012_val_00043046.bin 224 224 +48860 ./prep_dataset/ILSVRC2012_val_00046135.bin 224 224 +48861 ./prep_dataset/ILSVRC2012_val_00023226.bin 224 224 +48862 ./prep_dataset/ILSVRC2012_val_00022260.bin 224 224 +48863 ./prep_dataset/ILSVRC2012_val_00030969.bin 224 224 +48864 ./prep_dataset/ILSVRC2012_val_00009835.bin 224 224 +48865 ./prep_dataset/ILSVRC2012_val_00026239.bin 224 224 +48866 ./prep_dataset/ILSVRC2012_val_00016321.bin 224 224 +48867 ./prep_dataset/ILSVRC2012_val_00014287.bin 224 224 +48868 ./prep_dataset/ILSVRC2012_val_00037544.bin 224 224 +48869 ./prep_dataset/ILSVRC2012_val_00033092.bin 224 224 +48870 ./prep_dataset/ILSVRC2012_val_00029080.bin 224 224 +48871 ./prep_dataset/ILSVRC2012_val_00023677.bin 224 224 +48872 ./prep_dataset/ILSVRC2012_val_00006429.bin 224 224 +48873 ./prep_dataset/ILSVRC2012_val_00047993.bin 224 224 +48874 ./prep_dataset/ILSVRC2012_val_00002801.bin 224 224 +48875 ./prep_dataset/ILSVRC2012_val_00014214.bin 224 224 +48876 ./prep_dataset/ILSVRC2012_val_00036721.bin 224 224 +48877 ./prep_dataset/ILSVRC2012_val_00007869.bin 224 224 +48878 ./prep_dataset/ILSVRC2012_val_00034222.bin 224 224 +48879 ./prep_dataset/ILSVRC2012_val_00020278.bin 224 224 +48880 ./prep_dataset/ILSVRC2012_val_00048807.bin 224 224 +48881 ./prep_dataset/ILSVRC2012_val_00006905.bin 224 224 +48882 ./prep_dataset/ILSVRC2012_val_00002846.bin 224 224 +48883 ./prep_dataset/ILSVRC2012_val_00040829.bin 224 224 +48884 ./prep_dataset/ILSVRC2012_val_00032487.bin 224 224 +48885 ./prep_dataset/ILSVRC2012_val_00046199.bin 224 224 +48886 ./prep_dataset/ILSVRC2012_val_00042982.bin 224 224 +48887 ./prep_dataset/ILSVRC2012_val_00027533.bin 224 224 +48888 ./prep_dataset/ILSVRC2012_val_00028070.bin 224 224 +48889 ./prep_dataset/ILSVRC2012_val_00018234.bin 224 224 +48890 ./prep_dataset/ILSVRC2012_val_00021199.bin 224 224 +48891 ./prep_dataset/ILSVRC2012_val_00011278.bin 224 224 +48892 ./prep_dataset/ILSVRC2012_val_00034183.bin 224 224 +48893 ./prep_dataset/ILSVRC2012_val_00005835.bin 224 224 +48894 ./prep_dataset/ILSVRC2012_val_00006014.bin 224 224 +48895 ./prep_dataset/ILSVRC2012_val_00031529.bin 224 224 +48896 ./prep_dataset/ILSVRC2012_val_00015264.bin 224 224 +48897 ./prep_dataset/ILSVRC2012_val_00022032.bin 224 224 +48898 ./prep_dataset/ILSVRC2012_val_00020158.bin 224 224 +48899 ./prep_dataset/ILSVRC2012_val_00027317.bin 224 224 +48900 ./prep_dataset/ILSVRC2012_val_00003237.bin 224 224 +48901 ./prep_dataset/ILSVRC2012_val_00011282.bin 224 224 +48902 ./prep_dataset/ILSVRC2012_val_00033671.bin 224 224 +48903 ./prep_dataset/ILSVRC2012_val_00036890.bin 224 224 +48904 ./prep_dataset/ILSVRC2012_val_00038119.bin 224 224 +48905 ./prep_dataset/ILSVRC2012_val_00016887.bin 224 224 +48906 ./prep_dataset/ILSVRC2012_val_00046147.bin 224 224 +48907 ./prep_dataset/ILSVRC2012_val_00013177.bin 224 224 +48908 ./prep_dataset/ILSVRC2012_val_00027361.bin 224 224 +48909 ./prep_dataset/ILSVRC2012_val_00040137.bin 224 224 +48910 ./prep_dataset/ILSVRC2012_val_00018707.bin 224 224 +48911 ./prep_dataset/ILSVRC2012_val_00031658.bin 224 224 +48912 ./prep_dataset/ILSVRC2012_val_00031621.bin 224 224 +48913 ./prep_dataset/ILSVRC2012_val_00045526.bin 224 224 +48914 ./prep_dataset/ILSVRC2012_val_00048851.bin 224 224 +48915 ./prep_dataset/ILSVRC2012_val_00008932.bin 224 224 +48916 ./prep_dataset/ILSVRC2012_val_00045885.bin 224 224 +48917 ./prep_dataset/ILSVRC2012_val_00016026.bin 224 224 +48918 ./prep_dataset/ILSVRC2012_val_00036762.bin 224 224 +48919 ./prep_dataset/ILSVRC2012_val_00018206.bin 224 224 +48920 ./prep_dataset/ILSVRC2012_val_00018012.bin 224 224 +48921 ./prep_dataset/ILSVRC2012_val_00029420.bin 224 224 +48922 ./prep_dataset/ILSVRC2012_val_00016252.bin 224 224 +48923 ./prep_dataset/ILSVRC2012_val_00020280.bin 224 224 +48924 ./prep_dataset/ILSVRC2012_val_00042412.bin 224 224 +48925 ./prep_dataset/ILSVRC2012_val_00013941.bin 224 224 +48926 ./prep_dataset/ILSVRC2012_val_00009421.bin 224 224 +48927 ./prep_dataset/ILSVRC2012_val_00031793.bin 224 224 +48928 ./prep_dataset/ILSVRC2012_val_00049781.bin 224 224 +48929 ./prep_dataset/ILSVRC2012_val_00013091.bin 224 224 +48930 ./prep_dataset/ILSVRC2012_val_00039647.bin 224 224 +48931 ./prep_dataset/ILSVRC2012_val_00006613.bin 224 224 +48932 ./prep_dataset/ILSVRC2012_val_00003690.bin 224 224 +48933 ./prep_dataset/ILSVRC2012_val_00034315.bin 224 224 +48934 ./prep_dataset/ILSVRC2012_val_00041005.bin 224 224 +48935 ./prep_dataset/ILSVRC2012_val_00031070.bin 224 224 +48936 ./prep_dataset/ILSVRC2012_val_00038459.bin 224 224 +48937 ./prep_dataset/ILSVRC2012_val_00033348.bin 224 224 +48938 ./prep_dataset/ILSVRC2012_val_00049121.bin 224 224 +48939 ./prep_dataset/ILSVRC2012_val_00026769.bin 224 224 +48940 ./prep_dataset/ILSVRC2012_val_00021092.bin 224 224 +48941 ./prep_dataset/ILSVRC2012_val_00017849.bin 224 224 +48942 ./prep_dataset/ILSVRC2012_val_00017882.bin 224 224 +48943 ./prep_dataset/ILSVRC2012_val_00029870.bin 224 224 +48944 ./prep_dataset/ILSVRC2012_val_00039011.bin 224 224 +48945 ./prep_dataset/ILSVRC2012_val_00013089.bin 224 224 +48946 ./prep_dataset/ILSVRC2012_val_00011947.bin 224 224 +48947 ./prep_dataset/ILSVRC2012_val_00048470.bin 224 224 +48948 ./prep_dataset/ILSVRC2012_val_00021788.bin 224 224 +48949 ./prep_dataset/ILSVRC2012_val_00027891.bin 224 224 +48950 ./prep_dataset/ILSVRC2012_val_00013214.bin 224 224 +48951 ./prep_dataset/ILSVRC2012_val_00030076.bin 224 224 +48952 ./prep_dataset/ILSVRC2012_val_00027401.bin 224 224 +48953 ./prep_dataset/ILSVRC2012_val_00006923.bin 224 224 +48954 ./prep_dataset/ILSVRC2012_val_00019776.bin 224 224 +48955 ./prep_dataset/ILSVRC2012_val_00014570.bin 224 224 +48956 ./prep_dataset/ILSVRC2012_val_00015105.bin 224 224 +48957 ./prep_dataset/ILSVRC2012_val_00022365.bin 224 224 +48958 ./prep_dataset/ILSVRC2012_val_00033445.bin 224 224 +48959 ./prep_dataset/ILSVRC2012_val_00010013.bin 224 224 +48960 ./prep_dataset/ILSVRC2012_val_00038234.bin 224 224 +48961 ./prep_dataset/ILSVRC2012_val_00041131.bin 224 224 +48962 ./prep_dataset/ILSVRC2012_val_00033442.bin 224 224 +48963 ./prep_dataset/ILSVRC2012_val_00048118.bin 224 224 +48964 ./prep_dataset/ILSVRC2012_val_00036376.bin 224 224 +48965 ./prep_dataset/ILSVRC2012_val_00011405.bin 224 224 +48966 ./prep_dataset/ILSVRC2012_val_00018719.bin 224 224 +48967 ./prep_dataset/ILSVRC2012_val_00039036.bin 224 224 +48968 ./prep_dataset/ILSVRC2012_val_00000695.bin 224 224 +48969 ./prep_dataset/ILSVRC2012_val_00048845.bin 224 224 +48970 ./prep_dataset/ILSVRC2012_val_00011807.bin 224 224 +48971 ./prep_dataset/ILSVRC2012_val_00027191.bin 224 224 +48972 ./prep_dataset/ILSVRC2012_val_00014168.bin 224 224 +48973 ./prep_dataset/ILSVRC2012_val_00002844.bin 224 224 +48974 ./prep_dataset/ILSVRC2012_val_00001069.bin 224 224 +48975 ./prep_dataset/ILSVRC2012_val_00040661.bin 224 224 +48976 ./prep_dataset/ILSVRC2012_val_00012976.bin 224 224 +48977 ./prep_dataset/ILSVRC2012_val_00004077.bin 224 224 +48978 ./prep_dataset/ILSVRC2012_val_00048021.bin 224 224 +48979 ./prep_dataset/ILSVRC2012_val_00026091.bin 224 224 +48980 ./prep_dataset/ILSVRC2012_val_00036951.bin 224 224 +48981 ./prep_dataset/ILSVRC2012_val_00049152.bin 224 224 +48982 ./prep_dataset/ILSVRC2012_val_00029638.bin 224 224 +48983 ./prep_dataset/ILSVRC2012_val_00033628.bin 224 224 +48984 ./prep_dataset/ILSVRC2012_val_00016827.bin 224 224 +48985 ./prep_dataset/ILSVRC2012_val_00039131.bin 224 224 +48986 ./prep_dataset/ILSVRC2012_val_00049016.bin 224 224 +48987 ./prep_dataset/ILSVRC2012_val_00024054.bin 224 224 +48988 ./prep_dataset/ILSVRC2012_val_00003805.bin 224 224 +48989 ./prep_dataset/ILSVRC2012_val_00021963.bin 224 224 +48990 ./prep_dataset/ILSVRC2012_val_00014349.bin 224 224 +48991 ./prep_dataset/ILSVRC2012_val_00044647.bin 224 224 +48992 ./prep_dataset/ILSVRC2012_val_00034942.bin 224 224 +48993 ./prep_dataset/ILSVRC2012_val_00043090.bin 224 224 +48994 ./prep_dataset/ILSVRC2012_val_00013295.bin 224 224 +48995 ./prep_dataset/ILSVRC2012_val_00042748.bin 224 224 +48996 ./prep_dataset/ILSVRC2012_val_00032596.bin 224 224 +48997 ./prep_dataset/ILSVRC2012_val_00035279.bin 224 224 +48998 ./prep_dataset/ILSVRC2012_val_00012776.bin 224 224 +48999 ./prep_dataset/ILSVRC2012_val_00009725.bin 224 224 +49000 ./prep_dataset/ILSVRC2012_val_00006145.bin 224 224 +49001 ./prep_dataset/ILSVRC2012_val_00025107.bin 224 224 +49002 ./prep_dataset/ILSVRC2012_val_00007445.bin 224 224 +49003 ./prep_dataset/ILSVRC2012_val_00029266.bin 224 224 +49004 ./prep_dataset/ILSVRC2012_val_00022552.bin 224 224 +49005 ./prep_dataset/ILSVRC2012_val_00021180.bin 224 224 +49006 ./prep_dataset/ILSVRC2012_val_00007306.bin 224 224 +49007 ./prep_dataset/ILSVRC2012_val_00012745.bin 224 224 +49008 ./prep_dataset/ILSVRC2012_val_00002431.bin 224 224 +49009 ./prep_dataset/ILSVRC2012_val_00003283.bin 224 224 +49010 ./prep_dataset/ILSVRC2012_val_00004238.bin 224 224 +49011 ./prep_dataset/ILSVRC2012_val_00021367.bin 224 224 +49012 ./prep_dataset/ILSVRC2012_val_00006601.bin 224 224 +49013 ./prep_dataset/ILSVRC2012_val_00042900.bin 224 224 +49014 ./prep_dataset/ILSVRC2012_val_00001354.bin 224 224 +49015 ./prep_dataset/ILSVRC2012_val_00044995.bin 224 224 +49016 ./prep_dataset/ILSVRC2012_val_00032437.bin 224 224 +49017 ./prep_dataset/ILSVRC2012_val_00011799.bin 224 224 +49018 ./prep_dataset/ILSVRC2012_val_00011819.bin 224 224 +49019 ./prep_dataset/ILSVRC2012_val_00010093.bin 224 224 +49020 ./prep_dataset/ILSVRC2012_val_00049326.bin 224 224 +49021 ./prep_dataset/ILSVRC2012_val_00037497.bin 224 224 +49022 ./prep_dataset/ILSVRC2012_val_00038522.bin 224 224 +49023 ./prep_dataset/ILSVRC2012_val_00022069.bin 224 224 +49024 ./prep_dataset/ILSVRC2012_val_00046478.bin 224 224 +49025 ./prep_dataset/ILSVRC2012_val_00025324.bin 224 224 +49026 ./prep_dataset/ILSVRC2012_val_00038006.bin 224 224 +49027 ./prep_dataset/ILSVRC2012_val_00001895.bin 224 224 +49028 ./prep_dataset/ILSVRC2012_val_00047142.bin 224 224 +49029 ./prep_dataset/ILSVRC2012_val_00041239.bin 224 224 +49030 ./prep_dataset/ILSVRC2012_val_00047372.bin 224 224 +49031 ./prep_dataset/ILSVRC2012_val_00011362.bin 224 224 +49032 ./prep_dataset/ILSVRC2012_val_00018028.bin 224 224 +49033 ./prep_dataset/ILSVRC2012_val_00027815.bin 224 224 +49034 ./prep_dataset/ILSVRC2012_val_00028581.bin 224 224 +49035 ./prep_dataset/ILSVRC2012_val_00038899.bin 224 224 +49036 ./prep_dataset/ILSVRC2012_val_00013347.bin 224 224 +49037 ./prep_dataset/ILSVRC2012_val_00016319.bin 224 224 +49038 ./prep_dataset/ILSVRC2012_val_00004290.bin 224 224 +49039 ./prep_dataset/ILSVRC2012_val_00025674.bin 224 224 +49040 ./prep_dataset/ILSVRC2012_val_00018088.bin 224 224 +49041 ./prep_dataset/ILSVRC2012_val_00024289.bin 224 224 +49042 ./prep_dataset/ILSVRC2012_val_00009846.bin 224 224 +49043 ./prep_dataset/ILSVRC2012_val_00038637.bin 224 224 +49044 ./prep_dataset/ILSVRC2012_val_00024279.bin 224 224 +49045 ./prep_dataset/ILSVRC2012_val_00032964.bin 224 224 +49046 ./prep_dataset/ILSVRC2012_val_00025690.bin 224 224 +49047 ./prep_dataset/ILSVRC2012_val_00022839.bin 224 224 +49048 ./prep_dataset/ILSVRC2012_val_00043884.bin 224 224 +49049 ./prep_dataset/ILSVRC2012_val_00028668.bin 224 224 +49050 ./prep_dataset/ILSVRC2012_val_00017902.bin 224 224 +49051 ./prep_dataset/ILSVRC2012_val_00007288.bin 224 224 +49052 ./prep_dataset/ILSVRC2012_val_00021353.bin 224 224 +49053 ./prep_dataset/ILSVRC2012_val_00027475.bin 224 224 +49054 ./prep_dataset/ILSVRC2012_val_00027047.bin 224 224 +49055 ./prep_dataset/ILSVRC2012_val_00042766.bin 224 224 +49056 ./prep_dataset/ILSVRC2012_val_00021727.bin 224 224 +49057 ./prep_dataset/ILSVRC2012_val_00023175.bin 224 224 +49058 ./prep_dataset/ILSVRC2012_val_00017946.bin 224 224 +49059 ./prep_dataset/ILSVRC2012_val_00042955.bin 224 224 +49060 ./prep_dataset/ILSVRC2012_val_00027967.bin 224 224 +49061 ./prep_dataset/ILSVRC2012_val_00031832.bin 224 224 +49062 ./prep_dataset/ILSVRC2012_val_00044791.bin 224 224 +49063 ./prep_dataset/ILSVRC2012_val_00049831.bin 224 224 +49064 ./prep_dataset/ILSVRC2012_val_00036734.bin 224 224 +49065 ./prep_dataset/ILSVRC2012_val_00035623.bin 224 224 +49066 ./prep_dataset/ILSVRC2012_val_00010138.bin 224 224 +49067 ./prep_dataset/ILSVRC2012_val_00015908.bin 224 224 +49068 ./prep_dataset/ILSVRC2012_val_00047773.bin 224 224 +49069 ./prep_dataset/ILSVRC2012_val_00042444.bin 224 224 +49070 ./prep_dataset/ILSVRC2012_val_00040167.bin 224 224 +49071 ./prep_dataset/ILSVRC2012_val_00026206.bin 224 224 +49072 ./prep_dataset/ILSVRC2012_val_00014385.bin 224 224 +49073 ./prep_dataset/ILSVRC2012_val_00026245.bin 224 224 +49074 ./prep_dataset/ILSVRC2012_val_00012724.bin 224 224 +49075 ./prep_dataset/ILSVRC2012_val_00047833.bin 224 224 +49076 ./prep_dataset/ILSVRC2012_val_00005890.bin 224 224 +49077 ./prep_dataset/ILSVRC2012_val_00048677.bin 224 224 +49078 ./prep_dataset/ILSVRC2012_val_00015441.bin 224 224 +49079 ./prep_dataset/ILSVRC2012_val_00036471.bin 224 224 +49080 ./prep_dataset/ILSVRC2012_val_00035088.bin 224 224 +49081 ./prep_dataset/ILSVRC2012_val_00048501.bin 224 224 +49082 ./prep_dataset/ILSVRC2012_val_00009535.bin 224 224 +49083 ./prep_dataset/ILSVRC2012_val_00015998.bin 224 224 +49084 ./prep_dataset/ILSVRC2012_val_00023420.bin 224 224 +49085 ./prep_dataset/ILSVRC2012_val_00009652.bin 224 224 +49086 ./prep_dataset/ILSVRC2012_val_00048522.bin 224 224 +49087 ./prep_dataset/ILSVRC2012_val_00023477.bin 224 224 +49088 ./prep_dataset/ILSVRC2012_val_00008581.bin 224 224 +49089 ./prep_dataset/ILSVRC2012_val_00002843.bin 224 224 +49090 ./prep_dataset/ILSVRC2012_val_00010386.bin 224 224 +49091 ./prep_dataset/ILSVRC2012_val_00027223.bin 224 224 +49092 ./prep_dataset/ILSVRC2012_val_00047758.bin 224 224 +49093 ./prep_dataset/ILSVRC2012_val_00004739.bin 224 224 +49094 ./prep_dataset/ILSVRC2012_val_00024823.bin 224 224 +49095 ./prep_dataset/ILSVRC2012_val_00011127.bin 224 224 +49096 ./prep_dataset/ILSVRC2012_val_00005142.bin 224 224 +49097 ./prep_dataset/ILSVRC2012_val_00022266.bin 224 224 +49098 ./prep_dataset/ILSVRC2012_val_00011105.bin 224 224 +49099 ./prep_dataset/ILSVRC2012_val_00031675.bin 224 224 +49100 ./prep_dataset/ILSVRC2012_val_00047694.bin 224 224 +49101 ./prep_dataset/ILSVRC2012_val_00015516.bin 224 224 +49102 ./prep_dataset/ILSVRC2012_val_00025912.bin 224 224 +49103 ./prep_dataset/ILSVRC2012_val_00018267.bin 224 224 +49104 ./prep_dataset/ILSVRC2012_val_00047289.bin 224 224 +49105 ./prep_dataset/ILSVRC2012_val_00022957.bin 224 224 +49106 ./prep_dataset/ILSVRC2012_val_00016472.bin 224 224 +49107 ./prep_dataset/ILSVRC2012_val_00001227.bin 224 224 +49108 ./prep_dataset/ILSVRC2012_val_00001486.bin 224 224 +49109 ./prep_dataset/ILSVRC2012_val_00024075.bin 224 224 +49110 ./prep_dataset/ILSVRC2012_val_00015882.bin 224 224 +49111 ./prep_dataset/ILSVRC2012_val_00049198.bin 224 224 +49112 ./prep_dataset/ILSVRC2012_val_00037157.bin 224 224 +49113 ./prep_dataset/ILSVRC2012_val_00009403.bin 224 224 +49114 ./prep_dataset/ILSVRC2012_val_00015880.bin 224 224 +49115 ./prep_dataset/ILSVRC2012_val_00015244.bin 224 224 +49116 ./prep_dataset/ILSVRC2012_val_00018270.bin 224 224 +49117 ./prep_dataset/ILSVRC2012_val_00041059.bin 224 224 +49118 ./prep_dataset/ILSVRC2012_val_00044258.bin 224 224 +49119 ./prep_dataset/ILSVRC2012_val_00031464.bin 224 224 +49120 ./prep_dataset/ILSVRC2012_val_00041082.bin 224 224 +49121 ./prep_dataset/ILSVRC2012_val_00005634.bin 224 224 +49122 ./prep_dataset/ILSVRC2012_val_00019921.bin 224 224 +49123 ./prep_dataset/ILSVRC2012_val_00004442.bin 224 224 +49124 ./prep_dataset/ILSVRC2012_val_00045847.bin 224 224 +49125 ./prep_dataset/ILSVRC2012_val_00043344.bin 224 224 +49126 ./prep_dataset/ILSVRC2012_val_00002697.bin 224 224 +49127 ./prep_dataset/ILSVRC2012_val_00041951.bin 224 224 +49128 ./prep_dataset/ILSVRC2012_val_00007955.bin 224 224 +49129 ./prep_dataset/ILSVRC2012_val_00010499.bin 224 224 +49130 ./prep_dataset/ILSVRC2012_val_00016411.bin 224 224 +49131 ./prep_dataset/ILSVRC2012_val_00020107.bin 224 224 +49132 ./prep_dataset/ILSVRC2012_val_00004198.bin 224 224 +49133 ./prep_dataset/ILSVRC2012_val_00024135.bin 224 224 +49134 ./prep_dataset/ILSVRC2012_val_00048827.bin 224 224 +49135 ./prep_dataset/ILSVRC2012_val_00016468.bin 224 224 +49136 ./prep_dataset/ILSVRC2012_val_00009471.bin 224 224 +49137 ./prep_dataset/ILSVRC2012_val_00037101.bin 224 224 +49138 ./prep_dataset/ILSVRC2012_val_00024423.bin 224 224 +49139 ./prep_dataset/ILSVRC2012_val_00047174.bin 224 224 +49140 ./prep_dataset/ILSVRC2012_val_00045545.bin 224 224 +49141 ./prep_dataset/ILSVRC2012_val_00027365.bin 224 224 +49142 ./prep_dataset/ILSVRC2012_val_00043839.bin 224 224 +49143 ./prep_dataset/ILSVRC2012_val_00007380.bin 224 224 +49144 ./prep_dataset/ILSVRC2012_val_00011288.bin 224 224 +49145 ./prep_dataset/ILSVRC2012_val_00009192.bin 224 224 +49146 ./prep_dataset/ILSVRC2012_val_00036824.bin 224 224 +49147 ./prep_dataset/ILSVRC2012_val_00033721.bin 224 224 +49148 ./prep_dataset/ILSVRC2012_val_00010292.bin 224 224 +49149 ./prep_dataset/ILSVRC2012_val_00033286.bin 224 224 +49150 ./prep_dataset/ILSVRC2012_val_00028500.bin 224 224 +49151 ./prep_dataset/ILSVRC2012_val_00046908.bin 224 224 +49152 ./prep_dataset/ILSVRC2012_val_00009796.bin 224 224 +49153 ./prep_dataset/ILSVRC2012_val_00018019.bin 224 224 +49154 ./prep_dataset/ILSVRC2012_val_00012590.bin 224 224 +49155 ./prep_dataset/ILSVRC2012_val_00037416.bin 224 224 +49156 ./prep_dataset/ILSVRC2012_val_00027834.bin 224 224 +49157 ./prep_dataset/ILSVRC2012_val_00008836.bin 224 224 +49158 ./prep_dataset/ILSVRC2012_val_00048123.bin 224 224 +49159 ./prep_dataset/ILSVRC2012_val_00009182.bin 224 224 +49160 ./prep_dataset/ILSVRC2012_val_00034097.bin 224 224 +49161 ./prep_dataset/ILSVRC2012_val_00024087.bin 224 224 +49162 ./prep_dataset/ILSVRC2012_val_00047468.bin 224 224 +49163 ./prep_dataset/ILSVRC2012_val_00037519.bin 224 224 +49164 ./prep_dataset/ILSVRC2012_val_00005040.bin 224 224 +49165 ./prep_dataset/ILSVRC2012_val_00012275.bin 224 224 +49166 ./prep_dataset/ILSVRC2012_val_00011448.bin 224 224 +49167 ./prep_dataset/ILSVRC2012_val_00030332.bin 224 224 +49168 ./prep_dataset/ILSVRC2012_val_00002778.bin 224 224 +49169 ./prep_dataset/ILSVRC2012_val_00001267.bin 224 224 +49170 ./prep_dataset/ILSVRC2012_val_00034630.bin 224 224 +49171 ./prep_dataset/ILSVRC2012_val_00003068.bin 224 224 +49172 ./prep_dataset/ILSVRC2012_val_00042949.bin 224 224 +49173 ./prep_dataset/ILSVRC2012_val_00030914.bin 224 224 +49174 ./prep_dataset/ILSVRC2012_val_00043249.bin 224 224 +49175 ./prep_dataset/ILSVRC2012_val_00047664.bin 224 224 +49176 ./prep_dataset/ILSVRC2012_val_00044127.bin 224 224 +49177 ./prep_dataset/ILSVRC2012_val_00001010.bin 224 224 +49178 ./prep_dataset/ILSVRC2012_val_00005737.bin 224 224 +49179 ./prep_dataset/ILSVRC2012_val_00048878.bin 224 224 +49180 ./prep_dataset/ILSVRC2012_val_00032165.bin 224 224 +49181 ./prep_dataset/ILSVRC2012_val_00004300.bin 224 224 +49182 ./prep_dataset/ILSVRC2012_val_00028439.bin 224 224 +49183 ./prep_dataset/ILSVRC2012_val_00009551.bin 224 224 +49184 ./prep_dataset/ILSVRC2012_val_00027988.bin 224 224 +49185 ./prep_dataset/ILSVRC2012_val_00035275.bin 224 224 +49186 ./prep_dataset/ILSVRC2012_val_00020406.bin 224 224 +49187 ./prep_dataset/ILSVRC2012_val_00030888.bin 224 224 +49188 ./prep_dataset/ILSVRC2012_val_00037254.bin 224 224 +49189 ./prep_dataset/ILSVRC2012_val_00019458.bin 224 224 +49190 ./prep_dataset/ILSVRC2012_val_00022725.bin 224 224 +49191 ./prep_dataset/ILSVRC2012_val_00030691.bin 224 224 +49192 ./prep_dataset/ILSVRC2012_val_00031677.bin 224 224 +49193 ./prep_dataset/ILSVRC2012_val_00011815.bin 224 224 +49194 ./prep_dataset/ILSVRC2012_val_00005078.bin 224 224 +49195 ./prep_dataset/ILSVRC2012_val_00035928.bin 224 224 +49196 ./prep_dataset/ILSVRC2012_val_00048527.bin 224 224 +49197 ./prep_dataset/ILSVRC2012_val_00030345.bin 224 224 +49198 ./prep_dataset/ILSVRC2012_val_00015458.bin 224 224 +49199 ./prep_dataset/ILSVRC2012_val_00037378.bin 224 224 +49200 ./prep_dataset/ILSVRC2012_val_00010414.bin 224 224 +49201 ./prep_dataset/ILSVRC2012_val_00027819.bin 224 224 +49202 ./prep_dataset/ILSVRC2012_val_00032516.bin 224 224 +49203 ./prep_dataset/ILSVRC2012_val_00044901.bin 224 224 +49204 ./prep_dataset/ILSVRC2012_val_00026552.bin 224 224 +49205 ./prep_dataset/ILSVRC2012_val_00009626.bin 224 224 +49206 ./prep_dataset/ILSVRC2012_val_00030235.bin 224 224 +49207 ./prep_dataset/ILSVRC2012_val_00024797.bin 224 224 +49208 ./prep_dataset/ILSVRC2012_val_00033548.bin 224 224 +49209 ./prep_dataset/ILSVRC2012_val_00014013.bin 224 224 +49210 ./prep_dataset/ILSVRC2012_val_00039526.bin 224 224 +49211 ./prep_dataset/ILSVRC2012_val_00018511.bin 224 224 +49212 ./prep_dataset/ILSVRC2012_val_00042102.bin 224 224 +49213 ./prep_dataset/ILSVRC2012_val_00013352.bin 224 224 +49214 ./prep_dataset/ILSVRC2012_val_00035834.bin 224 224 +49215 ./prep_dataset/ILSVRC2012_val_00036557.bin 224 224 +49216 ./prep_dataset/ILSVRC2012_val_00017054.bin 224 224 +49217 ./prep_dataset/ILSVRC2012_val_00003035.bin 224 224 +49218 ./prep_dataset/ILSVRC2012_val_00012779.bin 224 224 +49219 ./prep_dataset/ILSVRC2012_val_00044539.bin 224 224 +49220 ./prep_dataset/ILSVRC2012_val_00012814.bin 224 224 +49221 ./prep_dataset/ILSVRC2012_val_00045402.bin 224 224 +49222 ./prep_dataset/ILSVRC2012_val_00038296.bin 224 224 +49223 ./prep_dataset/ILSVRC2012_val_00040404.bin 224 224 +49224 ./prep_dataset/ILSVRC2012_val_00031927.bin 224 224 +49225 ./prep_dataset/ILSVRC2012_val_00045419.bin 224 224 +49226 ./prep_dataset/ILSVRC2012_val_00020374.bin 224 224 +49227 ./prep_dataset/ILSVRC2012_val_00010484.bin 224 224 +49228 ./prep_dataset/ILSVRC2012_val_00031616.bin 224 224 +49229 ./prep_dataset/ILSVRC2012_val_00042759.bin 224 224 +49230 ./prep_dataset/ILSVRC2012_val_00020598.bin 224 224 +49231 ./prep_dataset/ILSVRC2012_val_00047820.bin 224 224 +49232 ./prep_dataset/ILSVRC2012_val_00047878.bin 224 224 +49233 ./prep_dataset/ILSVRC2012_val_00028548.bin 224 224 +49234 ./prep_dataset/ILSVRC2012_val_00039344.bin 224 224 +49235 ./prep_dataset/ILSVRC2012_val_00025115.bin 224 224 +49236 ./prep_dataset/ILSVRC2012_val_00003047.bin 224 224 +49237 ./prep_dataset/ILSVRC2012_val_00003903.bin 224 224 +49238 ./prep_dataset/ILSVRC2012_val_00040986.bin 224 224 +49239 ./prep_dataset/ILSVRC2012_val_00008681.bin 224 224 +49240 ./prep_dataset/ILSVRC2012_val_00005305.bin 224 224 +49241 ./prep_dataset/ILSVRC2012_val_00049233.bin 224 224 +49242 ./prep_dataset/ILSVRC2012_val_00007709.bin 224 224 +49243 ./prep_dataset/ILSVRC2012_val_00010263.bin 224 224 +49244 ./prep_dataset/ILSVRC2012_val_00012440.bin 224 224 +49245 ./prep_dataset/ILSVRC2012_val_00014497.bin 224 224 +49246 ./prep_dataset/ILSVRC2012_val_00008857.bin 224 224 +49247 ./prep_dataset/ILSVRC2012_val_00017737.bin 224 224 +49248 ./prep_dataset/ILSVRC2012_val_00033941.bin 224 224 +49249 ./prep_dataset/ILSVRC2012_val_00024400.bin 224 224 +49250 ./prep_dataset/ILSVRC2012_val_00032752.bin 224 224 +49251 ./prep_dataset/ILSVRC2012_val_00017029.bin 224 224 +49252 ./prep_dataset/ILSVRC2012_val_00021311.bin 224 224 +49253 ./prep_dataset/ILSVRC2012_val_00021437.bin 224 224 +49254 ./prep_dataset/ILSVRC2012_val_00006443.bin 224 224 +49255 ./prep_dataset/ILSVRC2012_val_00012091.bin 224 224 +49256 ./prep_dataset/ILSVRC2012_val_00006056.bin 224 224 +49257 ./prep_dataset/ILSVRC2012_val_00011414.bin 224 224 +49258 ./prep_dataset/ILSVRC2012_val_00002817.bin 224 224 +49259 ./prep_dataset/ILSVRC2012_val_00002437.bin 224 224 +49260 ./prep_dataset/ILSVRC2012_val_00017427.bin 224 224 +49261 ./prep_dataset/ILSVRC2012_val_00042956.bin 224 224 +49262 ./prep_dataset/ILSVRC2012_val_00049707.bin 224 224 +49263 ./prep_dataset/ILSVRC2012_val_00035570.bin 224 224 +49264 ./prep_dataset/ILSVRC2012_val_00010042.bin 224 224 +49265 ./prep_dataset/ILSVRC2012_val_00008917.bin 224 224 +49266 ./prep_dataset/ILSVRC2012_val_00037189.bin 224 224 +49267 ./prep_dataset/ILSVRC2012_val_00008079.bin 224 224 +49268 ./prep_dataset/ILSVRC2012_val_00045098.bin 224 224 +49269 ./prep_dataset/ILSVRC2012_val_00011621.bin 224 224 +49270 ./prep_dataset/ILSVRC2012_val_00032935.bin 224 224 +49271 ./prep_dataset/ILSVRC2012_val_00021032.bin 224 224 +49272 ./prep_dataset/ILSVRC2012_val_00005002.bin 224 224 +49273 ./prep_dataset/ILSVRC2012_val_00021002.bin 224 224 +49274 ./prep_dataset/ILSVRC2012_val_00024549.bin 224 224 +49275 ./prep_dataset/ILSVRC2012_val_00045765.bin 224 224 +49276 ./prep_dataset/ILSVRC2012_val_00012106.bin 224 224 +49277 ./prep_dataset/ILSVRC2012_val_00047113.bin 224 224 +49278 ./prep_dataset/ILSVRC2012_val_00021261.bin 224 224 +49279 ./prep_dataset/ILSVRC2012_val_00021758.bin 224 224 +49280 ./prep_dataset/ILSVRC2012_val_00008074.bin 224 224 +49281 ./prep_dataset/ILSVRC2012_val_00024213.bin 224 224 +49282 ./prep_dataset/ILSVRC2012_val_00008522.bin 224 224 +49283 ./prep_dataset/ILSVRC2012_val_00008270.bin 224 224 +49284 ./prep_dataset/ILSVRC2012_val_00002952.bin 224 224 +49285 ./prep_dataset/ILSVRC2012_val_00005514.bin 224 224 +49286 ./prep_dataset/ILSVRC2012_val_00039963.bin 224 224 +49287 ./prep_dataset/ILSVRC2012_val_00034982.bin 224 224 +49288 ./prep_dataset/ILSVRC2012_val_00024799.bin 224 224 +49289 ./prep_dataset/ILSVRC2012_val_00020653.bin 224 224 +49290 ./prep_dataset/ILSVRC2012_val_00034502.bin 224 224 +49291 ./prep_dataset/ILSVRC2012_val_00043685.bin 224 224 +49292 ./prep_dataset/ILSVRC2012_val_00031424.bin 224 224 +49293 ./prep_dataset/ILSVRC2012_val_00034582.bin 224 224 +49294 ./prep_dataset/ILSVRC2012_val_00002314.bin 224 224 +49295 ./prep_dataset/ILSVRC2012_val_00005561.bin 224 224 +49296 ./prep_dataset/ILSVRC2012_val_00029699.bin 224 224 +49297 ./prep_dataset/ILSVRC2012_val_00025753.bin 224 224 +49298 ./prep_dataset/ILSVRC2012_val_00027188.bin 224 224 +49299 ./prep_dataset/ILSVRC2012_val_00036643.bin 224 224 +49300 ./prep_dataset/ILSVRC2012_val_00040044.bin 224 224 +49301 ./prep_dataset/ILSVRC2012_val_00015285.bin 224 224 +49302 ./prep_dataset/ILSVRC2012_val_00027836.bin 224 224 +49303 ./prep_dataset/ILSVRC2012_val_00019770.bin 224 224 +49304 ./prep_dataset/ILSVRC2012_val_00008705.bin 224 224 +49305 ./prep_dataset/ILSVRC2012_val_00048645.bin 224 224 +49306 ./prep_dataset/ILSVRC2012_val_00026992.bin 224 224 +49307 ./prep_dataset/ILSVRC2012_val_00028725.bin 224 224 +49308 ./prep_dataset/ILSVRC2012_val_00015956.bin 224 224 +49309 ./prep_dataset/ILSVRC2012_val_00025867.bin 224 224 +49310 ./prep_dataset/ILSVRC2012_val_00013246.bin 224 224 +49311 ./prep_dataset/ILSVRC2012_val_00025941.bin 224 224 +49312 ./prep_dataset/ILSVRC2012_val_00046956.bin 224 224 +49313 ./prep_dataset/ILSVRC2012_val_00034449.bin 224 224 +49314 ./prep_dataset/ILSVRC2012_val_00007064.bin 224 224 +49315 ./prep_dataset/ILSVRC2012_val_00046290.bin 224 224 +49316 ./prep_dataset/ILSVRC2012_val_00048954.bin 224 224 +49317 ./prep_dataset/ILSVRC2012_val_00010770.bin 224 224 +49318 ./prep_dataset/ILSVRC2012_val_00013548.bin 224 224 +49319 ./prep_dataset/ILSVRC2012_val_00004873.bin 224 224 +49320 ./prep_dataset/ILSVRC2012_val_00047334.bin 224 224 +49321 ./prep_dataset/ILSVRC2012_val_00039043.bin 224 224 +49322 ./prep_dataset/ILSVRC2012_val_00040550.bin 224 224 +49323 ./prep_dataset/ILSVRC2012_val_00007835.bin 224 224 +49324 ./prep_dataset/ILSVRC2012_val_00027977.bin 224 224 +49325 ./prep_dataset/ILSVRC2012_val_00024351.bin 224 224 +49326 ./prep_dataset/ILSVRC2012_val_00041097.bin 224 224 +49327 ./prep_dataset/ILSVRC2012_val_00044275.bin 224 224 +49328 ./prep_dataset/ILSVRC2012_val_00004400.bin 224 224 +49329 ./prep_dataset/ILSVRC2012_val_00033886.bin 224 224 +49330 ./prep_dataset/ILSVRC2012_val_00020248.bin 224 224 +49331 ./prep_dataset/ILSVRC2012_val_00028879.bin 224 224 +49332 ./prep_dataset/ILSVRC2012_val_00045125.bin 224 224 +49333 ./prep_dataset/ILSVRC2012_val_00027105.bin 224 224 +49334 ./prep_dataset/ILSVRC2012_val_00012435.bin 224 224 +49335 ./prep_dataset/ILSVRC2012_val_00035297.bin 224 224 +49336 ./prep_dataset/ILSVRC2012_val_00029102.bin 224 224 +49337 ./prep_dataset/ILSVRC2012_val_00026734.bin 224 224 +49338 ./prep_dataset/ILSVRC2012_val_00036358.bin 224 224 +49339 ./prep_dataset/ILSVRC2012_val_00002136.bin 224 224 +49340 ./prep_dataset/ILSVRC2012_val_00005608.bin 224 224 +49341 ./prep_dataset/ILSVRC2012_val_00002341.bin 224 224 +49342 ./prep_dataset/ILSVRC2012_val_00012325.bin 224 224 +49343 ./prep_dataset/ILSVRC2012_val_00047381.bin 224 224 +49344 ./prep_dataset/ILSVRC2012_val_00024191.bin 224 224 +49345 ./prep_dataset/ILSVRC2012_val_00046853.bin 224 224 +49346 ./prep_dataset/ILSVRC2012_val_00044038.bin 224 224 +49347 ./prep_dataset/ILSVRC2012_val_00000540.bin 224 224 +49348 ./prep_dataset/ILSVRC2012_val_00029499.bin 224 224 +49349 ./prep_dataset/ILSVRC2012_val_00030026.bin 224 224 +49350 ./prep_dataset/ILSVRC2012_val_00022549.bin 224 224 +49351 ./prep_dataset/ILSVRC2012_val_00001417.bin 224 224 +49352 ./prep_dataset/ILSVRC2012_val_00004917.bin 224 224 +49353 ./prep_dataset/ILSVRC2012_val_00046102.bin 224 224 +49354 ./prep_dataset/ILSVRC2012_val_00016867.bin 224 224 +49355 ./prep_dataset/ILSVRC2012_val_00015829.bin 224 224 +49356 ./prep_dataset/ILSVRC2012_val_00008891.bin 224 224 +49357 ./prep_dataset/ILSVRC2012_val_00005607.bin 224 224 +49358 ./prep_dataset/ILSVRC2012_val_00004195.bin 224 224 +49359 ./prep_dataset/ILSVRC2012_val_00038225.bin 224 224 +49360 ./prep_dataset/ILSVRC2012_val_00020202.bin 224 224 +49361 ./prep_dataset/ILSVRC2012_val_00037208.bin 224 224 +49362 ./prep_dataset/ILSVRC2012_val_00035347.bin 224 224 +49363 ./prep_dataset/ILSVRC2012_val_00045375.bin 224 224 +49364 ./prep_dataset/ILSVRC2012_val_00026737.bin 224 224 +49365 ./prep_dataset/ILSVRC2012_val_00044373.bin 224 224 +49366 ./prep_dataset/ILSVRC2012_val_00029977.bin 224 224 +49367 ./prep_dataset/ILSVRC2012_val_00027483.bin 224 224 +49368 ./prep_dataset/ILSVRC2012_val_00032308.bin 224 224 +49369 ./prep_dataset/ILSVRC2012_val_00003656.bin 224 224 +49370 ./prep_dataset/ILSVRC2012_val_00043581.bin 224 224 +49371 ./prep_dataset/ILSVRC2012_val_00006272.bin 224 224 +49372 ./prep_dataset/ILSVRC2012_val_00007710.bin 224 224 +49373 ./prep_dataset/ILSVRC2012_val_00027040.bin 224 224 +49374 ./prep_dataset/ILSVRC2012_val_00026616.bin 224 224 +49375 ./prep_dataset/ILSVRC2012_val_00009664.bin 224 224 +49376 ./prep_dataset/ILSVRC2012_val_00023482.bin 224 224 +49377 ./prep_dataset/ILSVRC2012_val_00020906.bin 224 224 +49378 ./prep_dataset/ILSVRC2012_val_00023790.bin 224 224 +49379 ./prep_dataset/ILSVRC2012_val_00041265.bin 224 224 +49380 ./prep_dataset/ILSVRC2012_val_00041776.bin 224 224 +49381 ./prep_dataset/ILSVRC2012_val_00035567.bin 224 224 +49382 ./prep_dataset/ILSVRC2012_val_00011797.bin 224 224 +49383 ./prep_dataset/ILSVRC2012_val_00015116.bin 224 224 +49384 ./prep_dataset/ILSVRC2012_val_00009254.bin 224 224 +49385 ./prep_dataset/ILSVRC2012_val_00023457.bin 224 224 +49386 ./prep_dataset/ILSVRC2012_val_00017962.bin 224 224 +49387 ./prep_dataset/ILSVRC2012_val_00046341.bin 224 224 +49388 ./prep_dataset/ILSVRC2012_val_00036349.bin 224 224 +49389 ./prep_dataset/ILSVRC2012_val_00039950.bin 224 224 +49390 ./prep_dataset/ILSVRC2012_val_00009935.bin 224 224 +49391 ./prep_dataset/ILSVRC2012_val_00034814.bin 224 224 +49392 ./prep_dataset/ILSVRC2012_val_00046388.bin 224 224 +49393 ./prep_dataset/ILSVRC2012_val_00010495.bin 224 224 +49394 ./prep_dataset/ILSVRC2012_val_00033970.bin 224 224 +49395 ./prep_dataset/ILSVRC2012_val_00015434.bin 224 224 +49396 ./prep_dataset/ILSVRC2012_val_00033230.bin 224 224 +49397 ./prep_dataset/ILSVRC2012_val_00033299.bin 224 224 +49398 ./prep_dataset/ILSVRC2012_val_00012653.bin 224 224 +49399 ./prep_dataset/ILSVRC2012_val_00021224.bin 224 224 +49400 ./prep_dataset/ILSVRC2012_val_00038803.bin 224 224 +49401 ./prep_dataset/ILSVRC2012_val_00040738.bin 224 224 +49402 ./prep_dataset/ILSVRC2012_val_00041632.bin 224 224 +49403 ./prep_dataset/ILSVRC2012_val_00017502.bin 224 224 +49404 ./prep_dataset/ILSVRC2012_val_00017110.bin 224 224 +49405 ./prep_dataset/ILSVRC2012_val_00020587.bin 224 224 +49406 ./prep_dataset/ILSVRC2012_val_00019586.bin 224 224 +49407 ./prep_dataset/ILSVRC2012_val_00040776.bin 224 224 +49408 ./prep_dataset/ILSVRC2012_val_00046854.bin 224 224 +49409 ./prep_dataset/ILSVRC2012_val_00016263.bin 224 224 +49410 ./prep_dataset/ILSVRC2012_val_00008499.bin 224 224 +49411 ./prep_dataset/ILSVRC2012_val_00021121.bin 224 224 +49412 ./prep_dataset/ILSVRC2012_val_00024430.bin 224 224 +49413 ./prep_dataset/ILSVRC2012_val_00018275.bin 224 224 +49414 ./prep_dataset/ILSVRC2012_val_00041557.bin 224 224 +49415 ./prep_dataset/ILSVRC2012_val_00033870.bin 224 224 +49416 ./prep_dataset/ILSVRC2012_val_00026557.bin 224 224 +49417 ./prep_dataset/ILSVRC2012_val_00049859.bin 224 224 +49418 ./prep_dataset/ILSVRC2012_val_00039276.bin 224 224 +49419 ./prep_dataset/ILSVRC2012_val_00044214.bin 224 224 +49420 ./prep_dataset/ILSVRC2012_val_00015425.bin 224 224 +49421 ./prep_dataset/ILSVRC2012_val_00025036.bin 224 224 +49422 ./prep_dataset/ILSVRC2012_val_00013639.bin 224 224 +49423 ./prep_dataset/ILSVRC2012_val_00012257.bin 224 224 +49424 ./prep_dataset/ILSVRC2012_val_00027529.bin 224 224 +49425 ./prep_dataset/ILSVRC2012_val_00023428.bin 224 224 +49426 ./prep_dataset/ILSVRC2012_val_00013891.bin 224 224 +49427 ./prep_dataset/ILSVRC2012_val_00004274.bin 224 224 +49428 ./prep_dataset/ILSVRC2012_val_00002064.bin 224 224 +49429 ./prep_dataset/ILSVRC2012_val_00023053.bin 224 224 +49430 ./prep_dataset/ILSVRC2012_val_00046670.bin 224 224 +49431 ./prep_dataset/ILSVRC2012_val_00022612.bin 224 224 +49432 ./prep_dataset/ILSVRC2012_val_00042909.bin 224 224 +49433 ./prep_dataset/ILSVRC2012_val_00027948.bin 224 224 +49434 ./prep_dataset/ILSVRC2012_val_00025545.bin 224 224 +49435 ./prep_dataset/ILSVRC2012_val_00039058.bin 224 224 +49436 ./prep_dataset/ILSVRC2012_val_00014006.bin 224 224 +49437 ./prep_dataset/ILSVRC2012_val_00009424.bin 224 224 +49438 ./prep_dataset/ILSVRC2012_val_00038215.bin 224 224 +49439 ./prep_dataset/ILSVRC2012_val_00000246.bin 224 224 +49440 ./prep_dataset/ILSVRC2012_val_00007482.bin 224 224 +49441 ./prep_dataset/ILSVRC2012_val_00045696.bin 224 224 +49442 ./prep_dataset/ILSVRC2012_val_00043182.bin 224 224 +49443 ./prep_dataset/ILSVRC2012_val_00026618.bin 224 224 +49444 ./prep_dataset/ILSVRC2012_val_00001035.bin 224 224 +49445 ./prep_dataset/ILSVRC2012_val_00011413.bin 224 224 +49446 ./prep_dataset/ILSVRC2012_val_00030202.bin 224 224 +49447 ./prep_dataset/ILSVRC2012_val_00034828.bin 224 224 +49448 ./prep_dataset/ILSVRC2012_val_00042677.bin 224 224 +49449 ./prep_dataset/ILSVRC2012_val_00047464.bin 224 224 +49450 ./prep_dataset/ILSVRC2012_val_00003920.bin 224 224 +49451 ./prep_dataset/ILSVRC2012_val_00001042.bin 224 224 +49452 ./prep_dataset/ILSVRC2012_val_00001455.bin 224 224 +49453 ./prep_dataset/ILSVRC2012_val_00047388.bin 224 224 +49454 ./prep_dataset/ILSVRC2012_val_00044866.bin 224 224 +49455 ./prep_dataset/ILSVRC2012_val_00046489.bin 224 224 +49456 ./prep_dataset/ILSVRC2012_val_00009194.bin 224 224 +49457 ./prep_dataset/ILSVRC2012_val_00000406.bin 224 224 +49458 ./prep_dataset/ILSVRC2012_val_00037552.bin 224 224 +49459 ./prep_dataset/ILSVRC2012_val_00039571.bin 224 224 +49460 ./prep_dataset/ILSVRC2012_val_00047369.bin 224 224 +49461 ./prep_dataset/ILSVRC2012_val_00044811.bin 224 224 +49462 ./prep_dataset/ILSVRC2012_val_00041209.bin 224 224 +49463 ./prep_dataset/ILSVRC2012_val_00044571.bin 224 224 +49464 ./prep_dataset/ILSVRC2012_val_00005386.bin 224 224 +49465 ./prep_dataset/ILSVRC2012_val_00012242.bin 224 224 +49466 ./prep_dataset/ILSVRC2012_val_00011775.bin 224 224 +49467 ./prep_dataset/ILSVRC2012_val_00001556.bin 224 224 +49468 ./prep_dataset/ILSVRC2012_val_00045786.bin 224 224 +49469 ./prep_dataset/ILSVRC2012_val_00031874.bin 224 224 +49470 ./prep_dataset/ILSVRC2012_val_00047232.bin 224 224 +49471 ./prep_dataset/ILSVRC2012_val_00011158.bin 224 224 +49472 ./prep_dataset/ILSVRC2012_val_00041006.bin 224 224 +49473 ./prep_dataset/ILSVRC2012_val_00015579.bin 224 224 +49474 ./prep_dataset/ILSVRC2012_val_00048511.bin 224 224 +49475 ./prep_dataset/ILSVRC2012_val_00048055.bin 224 224 +49476 ./prep_dataset/ILSVRC2012_val_00041436.bin 224 224 +49477 ./prep_dataset/ILSVRC2012_val_00017730.bin 224 224 +49478 ./prep_dataset/ILSVRC2012_val_00026718.bin 224 224 +49479 ./prep_dataset/ILSVRC2012_val_00041572.bin 224 224 +49480 ./prep_dataset/ILSVRC2012_val_00043694.bin 224 224 +49481 ./prep_dataset/ILSVRC2012_val_00016046.bin 224 224 +49482 ./prep_dataset/ILSVRC2012_val_00000096.bin 224 224 +49483 ./prep_dataset/ILSVRC2012_val_00012134.bin 224 224 +49484 ./prep_dataset/ILSVRC2012_val_00020309.bin 224 224 +49485 ./prep_dataset/ILSVRC2012_val_00035197.bin 224 224 +49486 ./prep_dataset/ILSVRC2012_val_00003399.bin 224 224 +49487 ./prep_dataset/ILSVRC2012_val_00035537.bin 224 224 +49488 ./prep_dataset/ILSVRC2012_val_00008504.bin 224 224 +49489 ./prep_dataset/ILSVRC2012_val_00024543.bin 224 224 +49490 ./prep_dataset/ILSVRC2012_val_00026051.bin 224 224 +49491 ./prep_dataset/ILSVRC2012_val_00000073.bin 224 224 +49492 ./prep_dataset/ILSVRC2012_val_00024912.bin 224 224 +49493 ./prep_dataset/ILSVRC2012_val_00032449.bin 224 224 +49494 ./prep_dataset/ILSVRC2012_val_00047641.bin 224 224 +49495 ./prep_dataset/ILSVRC2012_val_00048919.bin 224 224 +49496 ./prep_dataset/ILSVRC2012_val_00015168.bin 224 224 +49497 ./prep_dataset/ILSVRC2012_val_00040537.bin 224 224 +49498 ./prep_dataset/ILSVRC2012_val_00004967.bin 224 224 +49499 ./prep_dataset/ILSVRC2012_val_00024649.bin 224 224 +49500 ./prep_dataset/ILSVRC2012_val_00031734.bin 224 224 +49501 ./prep_dataset/ILSVRC2012_val_00006839.bin 224 224 +49502 ./prep_dataset/ILSVRC2012_val_00035187.bin 224 224 +49503 ./prep_dataset/ILSVRC2012_val_00020995.bin 224 224 +49504 ./prep_dataset/ILSVRC2012_val_00009303.bin 224 224 +49505 ./prep_dataset/ILSVRC2012_val_00029212.bin 224 224 +49506 ./prep_dataset/ILSVRC2012_val_00030117.bin 224 224 +49507 ./prep_dataset/ILSVRC2012_val_00038068.bin 224 224 +49508 ./prep_dataset/ILSVRC2012_val_00048420.bin 224 224 +49509 ./prep_dataset/ILSVRC2012_val_00018866.bin 224 224 +49510 ./prep_dataset/ILSVRC2012_val_00029974.bin 224 224 +49511 ./prep_dataset/ILSVRC2012_val_00048035.bin 224 224 +49512 ./prep_dataset/ILSVRC2012_val_00005350.bin 224 224 +49513 ./prep_dataset/ILSVRC2012_val_00027199.bin 224 224 +49514 ./prep_dataset/ILSVRC2012_val_00016986.bin 224 224 +49515 ./prep_dataset/ILSVRC2012_val_00025407.bin 224 224 +49516 ./prep_dataset/ILSVRC2012_val_00013780.bin 224 224 +49517 ./prep_dataset/ILSVRC2012_val_00043051.bin 224 224 +49518 ./prep_dataset/ILSVRC2012_val_00005786.bin 224 224 +49519 ./prep_dataset/ILSVRC2012_val_00002506.bin 224 224 +49520 ./prep_dataset/ILSVRC2012_val_00030441.bin 224 224 +49521 ./prep_dataset/ILSVRC2012_val_00018706.bin 224 224 +49522 ./prep_dataset/ILSVRC2012_val_00025900.bin 224 224 +49523 ./prep_dataset/ILSVRC2012_val_00046712.bin 224 224 +49524 ./prep_dataset/ILSVRC2012_val_00046038.bin 224 224 +49525 ./prep_dataset/ILSVRC2012_val_00019414.bin 224 224 +49526 ./prep_dataset/ILSVRC2012_val_00033819.bin 224 224 +49527 ./prep_dataset/ILSVRC2012_val_00044849.bin 224 224 +49528 ./prep_dataset/ILSVRC2012_val_00040131.bin 224 224 +49529 ./prep_dataset/ILSVRC2012_val_00011786.bin 224 224 +49530 ./prep_dataset/ILSVRC2012_val_00032293.bin 224 224 +49531 ./prep_dataset/ILSVRC2012_val_00019613.bin 224 224 +49532 ./prep_dataset/ILSVRC2012_val_00004357.bin 224 224 +49533 ./prep_dataset/ILSVRC2012_val_00029285.bin 224 224 +49534 ./prep_dataset/ILSVRC2012_val_00014550.bin 224 224 +49535 ./prep_dataset/ILSVRC2012_val_00009814.bin 224 224 +49536 ./prep_dataset/ILSVRC2012_val_00007554.bin 224 224 +49537 ./prep_dataset/ILSVRC2012_val_00005130.bin 224 224 +49538 ./prep_dataset/ILSVRC2012_val_00002236.bin 224 224 +49539 ./prep_dataset/ILSVRC2012_val_00000121.bin 224 224 +49540 ./prep_dataset/ILSVRC2012_val_00036467.bin 224 224 +49541 ./prep_dataset/ILSVRC2012_val_00019599.bin 224 224 +49542 ./prep_dataset/ILSVRC2012_val_00020511.bin 224 224 +49543 ./prep_dataset/ILSVRC2012_val_00003594.bin 224 224 +49544 ./prep_dataset/ILSVRC2012_val_00031195.bin 224 224 +49545 ./prep_dataset/ILSVRC2012_val_00010189.bin 224 224 +49546 ./prep_dataset/ILSVRC2012_val_00035804.bin 224 224 +49547 ./prep_dataset/ILSVRC2012_val_00016316.bin 224 224 +49548 ./prep_dataset/ILSVRC2012_val_00012025.bin 224 224 +49549 ./prep_dataset/ILSVRC2012_val_00049661.bin 224 224 +49550 ./prep_dataset/ILSVRC2012_val_00015900.bin 224 224 +49551 ./prep_dataset/ILSVRC2012_val_00022240.bin 224 224 +49552 ./prep_dataset/ILSVRC2012_val_00047910.bin 224 224 +49553 ./prep_dataset/ILSVRC2012_val_00028041.bin 224 224 +49554 ./prep_dataset/ILSVRC2012_val_00005179.bin 224 224 +49555 ./prep_dataset/ILSVRC2012_val_00034539.bin 224 224 +49556 ./prep_dataset/ILSVRC2012_val_00009793.bin 224 224 +49557 ./prep_dataset/ILSVRC2012_val_00048565.bin 224 224 +49558 ./prep_dataset/ILSVRC2012_val_00031358.bin 224 224 +49559 ./prep_dataset/ILSVRC2012_val_00009176.bin 224 224 +49560 ./prep_dataset/ILSVRC2012_val_00025573.bin 224 224 +49561 ./prep_dataset/ILSVRC2012_val_00012211.bin 224 224 +49562 ./prep_dataset/ILSVRC2012_val_00008236.bin 224 224 +49563 ./prep_dataset/ILSVRC2012_val_00042305.bin 224 224 +49564 ./prep_dataset/ILSVRC2012_val_00023443.bin 224 224 +49565 ./prep_dataset/ILSVRC2012_val_00028583.bin 224 224 +49566 ./prep_dataset/ILSVRC2012_val_00032756.bin 224 224 +49567 ./prep_dataset/ILSVRC2012_val_00014114.bin 224 224 +49568 ./prep_dataset/ILSVRC2012_val_00011460.bin 224 224 +49569 ./prep_dataset/ILSVRC2012_val_00014734.bin 224 224 +49570 ./prep_dataset/ILSVRC2012_val_00007340.bin 224 224 +49571 ./prep_dataset/ILSVRC2012_val_00030391.bin 224 224 +49572 ./prep_dataset/ILSVRC2012_val_00036881.bin 224 224 +49573 ./prep_dataset/ILSVRC2012_val_00046427.bin 224 224 +49574 ./prep_dataset/ILSVRC2012_val_00039178.bin 224 224 +49575 ./prep_dataset/ILSVRC2012_val_00023091.bin 224 224 +49576 ./prep_dataset/ILSVRC2012_val_00003908.bin 224 224 +49577 ./prep_dataset/ILSVRC2012_val_00004351.bin 224 224 +49578 ./prep_dataset/ILSVRC2012_val_00012626.bin 224 224 +49579 ./prep_dataset/ILSVRC2012_val_00043162.bin 224 224 +49580 ./prep_dataset/ILSVRC2012_val_00011318.bin 224 224 +49581 ./prep_dataset/ILSVRC2012_val_00018986.bin 224 224 +49582 ./prep_dataset/ILSVRC2012_val_00001095.bin 224 224 +49583 ./prep_dataset/ILSVRC2012_val_00003338.bin 224 224 +49584 ./prep_dataset/ILSVRC2012_val_00005020.bin 224 224 +49585 ./prep_dataset/ILSVRC2012_val_00015380.bin 224 224 +49586 ./prep_dataset/ILSVRC2012_val_00032105.bin 224 224 +49587 ./prep_dataset/ILSVRC2012_val_00032665.bin 224 224 +49588 ./prep_dataset/ILSVRC2012_val_00026646.bin 224 224 +49589 ./prep_dataset/ILSVRC2012_val_00032036.bin 224 224 +49590 ./prep_dataset/ILSVRC2012_val_00014896.bin 224 224 +49591 ./prep_dataset/ILSVRC2012_val_00009837.bin 224 224 +49592 ./prep_dataset/ILSVRC2012_val_00017094.bin 224 224 +49593 ./prep_dataset/ILSVRC2012_val_00020933.bin 224 224 +49594 ./prep_dataset/ILSVRC2012_val_00035714.bin 224 224 +49595 ./prep_dataset/ILSVRC2012_val_00020216.bin 224 224 +49596 ./prep_dataset/ILSVRC2012_val_00034955.bin 224 224 +49597 ./prep_dataset/ILSVRC2012_val_00015132.bin 224 224 +49598 ./prep_dataset/ILSVRC2012_val_00025756.bin 224 224 +49599 ./prep_dataset/ILSVRC2012_val_00040153.bin 224 224 +49600 ./prep_dataset/ILSVRC2012_val_00018180.bin 224 224 +49601 ./prep_dataset/ILSVRC2012_val_00011325.bin 224 224 +49602 ./prep_dataset/ILSVRC2012_val_00041378.bin 224 224 +49603 ./prep_dataset/ILSVRC2012_val_00035676.bin 224 224 +49604 ./prep_dataset/ILSVRC2012_val_00030964.bin 224 224 +49605 ./prep_dataset/ILSVRC2012_val_00028681.bin 224 224 +49606 ./prep_dataset/ILSVRC2012_val_00033242.bin 224 224 +49607 ./prep_dataset/ILSVRC2012_val_00041648.bin 224 224 +49608 ./prep_dataset/ILSVRC2012_val_00029802.bin 224 224 +49609 ./prep_dataset/ILSVRC2012_val_00003471.bin 224 224 +49610 ./prep_dataset/ILSVRC2012_val_00013865.bin 224 224 +49611 ./prep_dataset/ILSVRC2012_val_00015783.bin 224 224 +49612 ./prep_dataset/ILSVRC2012_val_00007748.bin 224 224 +49613 ./prep_dataset/ILSVRC2012_val_00018748.bin 224 224 +49614 ./prep_dataset/ILSVRC2012_val_00007322.bin 224 224 +49615 ./prep_dataset/ILSVRC2012_val_00042038.bin 224 224 +49616 ./prep_dataset/ILSVRC2012_val_00043247.bin 224 224 +49617 ./prep_dataset/ILSVRC2012_val_00009873.bin 224 224 +49618 ./prep_dataset/ILSVRC2012_val_00012721.bin 224 224 +49619 ./prep_dataset/ILSVRC2012_val_00000612.bin 224 224 +49620 ./prep_dataset/ILSVRC2012_val_00034489.bin 224 224 +49621 ./prep_dataset/ILSVRC2012_val_00023033.bin 224 224 +49622 ./prep_dataset/ILSVRC2012_val_00035779.bin 224 224 +49623 ./prep_dataset/ILSVRC2012_val_00007506.bin 224 224 +49624 ./prep_dataset/ILSVRC2012_val_00019252.bin 224 224 +49625 ./prep_dataset/ILSVRC2012_val_00016455.bin 224 224 +49626 ./prep_dataset/ILSVRC2012_val_00044438.bin 224 224 +49627 ./prep_dataset/ILSVRC2012_val_00036166.bin 224 224 +49628 ./prep_dataset/ILSVRC2012_val_00019234.bin 224 224 +49629 ./prep_dataset/ILSVRC2012_val_00038378.bin 224 224 +49630 ./prep_dataset/ILSVRC2012_val_00026983.bin 224 224 +49631 ./prep_dataset/ILSVRC2012_val_00005221.bin 224 224 +49632 ./prep_dataset/ILSVRC2012_val_00010593.bin 224 224 +49633 ./prep_dataset/ILSVRC2012_val_00028623.bin 224 224 +49634 ./prep_dataset/ILSVRC2012_val_00025648.bin 224 224 +49635 ./prep_dataset/ILSVRC2012_val_00035641.bin 224 224 +49636 ./prep_dataset/ILSVRC2012_val_00041949.bin 224 224 +49637 ./prep_dataset/ILSVRC2012_val_00042074.bin 224 224 +49638 ./prep_dataset/ILSVRC2012_val_00029831.bin 224 224 +49639 ./prep_dataset/ILSVRC2012_val_00003197.bin 224 224 +49640 ./prep_dataset/ILSVRC2012_val_00030002.bin 224 224 +49641 ./prep_dataset/ILSVRC2012_val_00009797.bin 224 224 +49642 ./prep_dataset/ILSVRC2012_val_00014489.bin 224 224 +49643 ./prep_dataset/ILSVRC2012_val_00003863.bin 224 224 +49644 ./prep_dataset/ILSVRC2012_val_00035376.bin 224 224 +49645 ./prep_dataset/ILSVRC2012_val_00032056.bin 224 224 +49646 ./prep_dataset/ILSVRC2012_val_00000439.bin 224 224 +49647 ./prep_dataset/ILSVRC2012_val_00043595.bin 224 224 +49648 ./prep_dataset/ILSVRC2012_val_00040321.bin 224 224 +49649 ./prep_dataset/ILSVRC2012_val_00041872.bin 224 224 +49650 ./prep_dataset/ILSVRC2012_val_00027554.bin 224 224 +49651 ./prep_dataset/ILSVRC2012_val_00010362.bin 224 224 +49652 ./prep_dataset/ILSVRC2012_val_00026710.bin 224 224 +49653 ./prep_dataset/ILSVRC2012_val_00048870.bin 224 224 +49654 ./prep_dataset/ILSVRC2012_val_00018614.bin 224 224 +49655 ./prep_dataset/ILSVRC2012_val_00037852.bin 224 224 +49656 ./prep_dataset/ILSVRC2012_val_00045616.bin 224 224 +49657 ./prep_dataset/ILSVRC2012_val_00039798.bin 224 224 +49658 ./prep_dataset/ILSVRC2012_val_00002171.bin 224 224 +49659 ./prep_dataset/ILSVRC2012_val_00001587.bin 224 224 +49660 ./prep_dataset/ILSVRC2012_val_00047571.bin 224 224 +49661 ./prep_dataset/ILSVRC2012_val_00032089.bin 224 224 +49662 ./prep_dataset/ILSVRC2012_val_00023251.bin 224 224 +49663 ./prep_dataset/ILSVRC2012_val_00004373.bin 224 224 +49664 ./prep_dataset/ILSVRC2012_val_00045883.bin 224 224 +49665 ./prep_dataset/ILSVRC2012_val_00007797.bin 224 224 +49666 ./prep_dataset/ILSVRC2012_val_00027545.bin 224 224 +49667 ./prep_dataset/ILSVRC2012_val_00026998.bin 224 224 +49668 ./prep_dataset/ILSVRC2012_val_00009578.bin 224 224 +49669 ./prep_dataset/ILSVRC2012_val_00042901.bin 224 224 +49670 ./prep_dataset/ILSVRC2012_val_00044202.bin 224 224 +49671 ./prep_dataset/ILSVRC2012_val_00029109.bin 224 224 +49672 ./prep_dataset/ILSVRC2012_val_00022829.bin 224 224 +49673 ./prep_dataset/ILSVRC2012_val_00040286.bin 224 224 +49674 ./prep_dataset/ILSVRC2012_val_00036421.bin 224 224 +49675 ./prep_dataset/ILSVRC2012_val_00037851.bin 224 224 +49676 ./prep_dataset/ILSVRC2012_val_00010557.bin 224 224 +49677 ./prep_dataset/ILSVRC2012_val_00029824.bin 224 224 +49678 ./prep_dataset/ILSVRC2012_val_00044229.bin 224 224 +49679 ./prep_dataset/ILSVRC2012_val_00032149.bin 224 224 +49680 ./prep_dataset/ILSVRC2012_val_00036473.bin 224 224 +49681 ./prep_dataset/ILSVRC2012_val_00047455.bin 224 224 +49682 ./prep_dataset/ILSVRC2012_val_00012946.bin 224 224 +49683 ./prep_dataset/ILSVRC2012_val_00030334.bin 224 224 +49684 ./prep_dataset/ILSVRC2012_val_00045323.bin 224 224 +49685 ./prep_dataset/ILSVRC2012_val_00040454.bin 224 224 +49686 ./prep_dataset/ILSVRC2012_val_00007543.bin 224 224 +49687 ./prep_dataset/ILSVRC2012_val_00010327.bin 224 224 +49688 ./prep_dataset/ILSVRC2012_val_00038046.bin 224 224 +49689 ./prep_dataset/ILSVRC2012_val_00015089.bin 224 224 +49690 ./prep_dataset/ILSVRC2012_val_00027487.bin 224 224 +49691 ./prep_dataset/ILSVRC2012_val_00018449.bin 224 224 +49692 ./prep_dataset/ILSVRC2012_val_00026280.bin 224 224 +49693 ./prep_dataset/ILSVRC2012_val_00009977.bin 224 224 +49694 ./prep_dataset/ILSVRC2012_val_00049556.bin 224 224 +49695 ./prep_dataset/ILSVRC2012_val_00000256.bin 224 224 +49696 ./prep_dataset/ILSVRC2012_val_00006230.bin 224 224 +49697 ./prep_dataset/ILSVRC2012_val_00000710.bin 224 224 +49698 ./prep_dataset/ILSVRC2012_val_00009619.bin 224 224 +49699 ./prep_dataset/ILSVRC2012_val_00033856.bin 224 224 +49700 ./prep_dataset/ILSVRC2012_val_00021303.bin 224 224 +49701 ./prep_dataset/ILSVRC2012_val_00023942.bin 224 224 +49702 ./prep_dataset/ILSVRC2012_val_00016218.bin 224 224 +49703 ./prep_dataset/ILSVRC2012_val_00033674.bin 224 224 +49704 ./prep_dataset/ILSVRC2012_val_00040760.bin 224 224 +49705 ./prep_dataset/ILSVRC2012_val_00020392.bin 224 224 +49706 ./prep_dataset/ILSVRC2012_val_00034979.bin 224 224 +49707 ./prep_dataset/ILSVRC2012_val_00021275.bin 224 224 +49708 ./prep_dataset/ILSVRC2012_val_00008963.bin 224 224 +49709 ./prep_dataset/ILSVRC2012_val_00046484.bin 224 224 +49710 ./prep_dataset/ILSVRC2012_val_00044182.bin 224 224 +49711 ./prep_dataset/ILSVRC2012_val_00042667.bin 224 224 +49712 ./prep_dataset/ILSVRC2012_val_00021323.bin 224 224 +49713 ./prep_dataset/ILSVRC2012_val_00017640.bin 224 224 +49714 ./prep_dataset/ILSVRC2012_val_00025997.bin 224 224 +49715 ./prep_dataset/ILSVRC2012_val_00013080.bin 224 224 +49716 ./prep_dataset/ILSVRC2012_val_00049103.bin 224 224 +49717 ./prep_dataset/ILSVRC2012_val_00014850.bin 224 224 +49718 ./prep_dataset/ILSVRC2012_val_00024299.bin 224 224 +49719 ./prep_dataset/ILSVRC2012_val_00034506.bin 224 224 +49720 ./prep_dataset/ILSVRC2012_val_00024154.bin 224 224 +49721 ./prep_dataset/ILSVRC2012_val_00048901.bin 224 224 +49722 ./prep_dataset/ILSVRC2012_val_00038210.bin 224 224 +49723 ./prep_dataset/ILSVRC2012_val_00036751.bin 224 224 +49724 ./prep_dataset/ILSVRC2012_val_00004472.bin 224 224 +49725 ./prep_dataset/ILSVRC2012_val_00000197.bin 224 224 +49726 ./prep_dataset/ILSVRC2012_val_00010302.bin 224 224 +49727 ./prep_dataset/ILSVRC2012_val_00037953.bin 224 224 +49728 ./prep_dataset/ILSVRC2012_val_00022849.bin 224 224 +49729 ./prep_dataset/ILSVRC2012_val_00014963.bin 224 224 +49730 ./prep_dataset/ILSVRC2012_val_00031395.bin 224 224 +49731 ./prep_dataset/ILSVRC2012_val_00017617.bin 224 224 +49732 ./prep_dataset/ILSVRC2012_val_00048376.bin 224 224 +49733 ./prep_dataset/ILSVRC2012_val_00040211.bin 224 224 +49734 ./prep_dataset/ILSVRC2012_val_00028320.bin 224 224 +49735 ./prep_dataset/ILSVRC2012_val_00016153.bin 224 224 +49736 ./prep_dataset/ILSVRC2012_val_00048431.bin 224 224 +49737 ./prep_dataset/ILSVRC2012_val_00022337.bin 224 224 +49738 ./prep_dataset/ILSVRC2012_val_00027682.bin 224 224 +49739 ./prep_dataset/ILSVRC2012_val_00031977.bin 224 224 +49740 ./prep_dataset/ILSVRC2012_val_00011810.bin 224 224 +49741 ./prep_dataset/ILSVRC2012_val_00045717.bin 224 224 +49742 ./prep_dataset/ILSVRC2012_val_00045421.bin 224 224 +49743 ./prep_dataset/ILSVRC2012_val_00017568.bin 224 224 +49744 ./prep_dataset/ILSVRC2012_val_00009188.bin 224 224 +49745 ./prep_dataset/ILSVRC2012_val_00018008.bin 224 224 +49746 ./prep_dataset/ILSVRC2012_val_00046813.bin 224 224 +49747 ./prep_dataset/ILSVRC2012_val_00022581.bin 224 224 +49748 ./prep_dataset/ILSVRC2012_val_00037362.bin 224 224 +49749 ./prep_dataset/ILSVRC2012_val_00047125.bin 224 224 +49750 ./prep_dataset/ILSVRC2012_val_00017224.bin 224 224 +49751 ./prep_dataset/ILSVRC2012_val_00047166.bin 224 224 +49752 ./prep_dataset/ILSVRC2012_val_00028758.bin 224 224 +49753 ./prep_dataset/ILSVRC2012_val_00039925.bin 224 224 +49754 ./prep_dataset/ILSVRC2012_val_00032769.bin 224 224 +49755 ./prep_dataset/ILSVRC2012_val_00016303.bin 224 224 +49756 ./prep_dataset/ILSVRC2012_val_00018829.bin 224 224 +49757 ./prep_dataset/ILSVRC2012_val_00034045.bin 224 224 +49758 ./prep_dataset/ILSVRC2012_val_00002405.bin 224 224 +49759 ./prep_dataset/ILSVRC2012_val_00041546.bin 224 224 +49760 ./prep_dataset/ILSVRC2012_val_00019867.bin 224 224 +49761 ./prep_dataset/ILSVRC2012_val_00039480.bin 224 224 +49762 ./prep_dataset/ILSVRC2012_val_00045430.bin 224 224 +49763 ./prep_dataset/ILSVRC2012_val_00013099.bin 224 224 +49764 ./prep_dataset/ILSVRC2012_val_00042702.bin 224 224 +49765 ./prep_dataset/ILSVRC2012_val_00032547.bin 224 224 +49766 ./prep_dataset/ILSVRC2012_val_00031579.bin 224 224 +49767 ./prep_dataset/ILSVRC2012_val_00002383.bin 224 224 +49768 ./prep_dataset/ILSVRC2012_val_00004630.bin 224 224 +49769 ./prep_dataset/ILSVRC2012_val_00014121.bin 224 224 +49770 ./prep_dataset/ILSVRC2012_val_00032787.bin 224 224 +49771 ./prep_dataset/ILSVRC2012_val_00040590.bin 224 224 +49772 ./prep_dataset/ILSVRC2012_val_00010354.bin 224 224 +49773 ./prep_dataset/ILSVRC2012_val_00029680.bin 224 224 +49774 ./prep_dataset/ILSVRC2012_val_00011843.bin 224 224 +49775 ./prep_dataset/ILSVRC2012_val_00008938.bin 224 224 +49776 ./prep_dataset/ILSVRC2012_val_00006031.bin 224 224 +49777 ./prep_dataset/ILSVRC2012_val_00017859.bin 224 224 +49778 ./prep_dataset/ILSVRC2012_val_00028208.bin 224 224 +49779 ./prep_dataset/ILSVRC2012_val_00025656.bin 224 224 +49780 ./prep_dataset/ILSVRC2012_val_00028798.bin 224 224 +49781 ./prep_dataset/ILSVRC2012_val_00005838.bin 224 224 +49782 ./prep_dataset/ILSVRC2012_val_00008179.bin 224 224 +49783 ./prep_dataset/ILSVRC2012_val_00000100.bin 224 224 +49784 ./prep_dataset/ILSVRC2012_val_00044510.bin 224 224 +49785 ./prep_dataset/ILSVRC2012_val_00022407.bin 224 224 +49786 ./prep_dataset/ILSVRC2012_val_00008488.bin 224 224 +49787 ./prep_dataset/ILSVRC2012_val_00019842.bin 224 224 +49788 ./prep_dataset/ILSVRC2012_val_00001954.bin 224 224 +49789 ./prep_dataset/ILSVRC2012_val_00019564.bin 224 224 +49790 ./prep_dataset/ILSVRC2012_val_00012846.bin 224 224 +49791 ./prep_dataset/ILSVRC2012_val_00001277.bin 224 224 +49792 ./prep_dataset/ILSVRC2012_val_00015978.bin 224 224 +49793 ./prep_dataset/ILSVRC2012_val_00043939.bin 224 224 +49794 ./prep_dataset/ILSVRC2012_val_00010129.bin 224 224 +49795 ./prep_dataset/ILSVRC2012_val_00040032.bin 224 224 +49796 ./prep_dataset/ILSVRC2012_val_00027325.bin 224 224 +49797 ./prep_dataset/ILSVRC2012_val_00041473.bin 224 224 +49798 ./prep_dataset/ILSVRC2012_val_00036982.bin 224 224 +49799 ./prep_dataset/ILSVRC2012_val_00033362.bin 224 224 +49800 ./prep_dataset/ILSVRC2012_val_00031766.bin 224 224 +49801 ./prep_dataset/ILSVRC2012_val_00017881.bin 224 224 +49802 ./prep_dataset/ILSVRC2012_val_00029298.bin 224 224 +49803 ./prep_dataset/ILSVRC2012_val_00039522.bin 224 224 +49804 ./prep_dataset/ILSVRC2012_val_00019323.bin 224 224 +49805 ./prep_dataset/ILSVRC2012_val_00047482.bin 224 224 +49806 ./prep_dataset/ILSVRC2012_val_00018216.bin 224 224 +49807 ./prep_dataset/ILSVRC2012_val_00013841.bin 224 224 +49808 ./prep_dataset/ILSVRC2012_val_00043561.bin 224 224 +49809 ./prep_dataset/ILSVRC2012_val_00038730.bin 224 224 +49810 ./prep_dataset/ILSVRC2012_val_00023690.bin 224 224 +49811 ./prep_dataset/ILSVRC2012_val_00013638.bin 224 224 +49812 ./prep_dataset/ILSVRC2012_val_00002018.bin 224 224 +49813 ./prep_dataset/ILSVRC2012_val_00003831.bin 224 224 +49814 ./prep_dataset/ILSVRC2012_val_00019666.bin 224 224 +49815 ./prep_dataset/ILSVRC2012_val_00012684.bin 224 224 +49816 ./prep_dataset/ILSVRC2012_val_00048926.bin 224 224 +49817 ./prep_dataset/ILSVRC2012_val_00021573.bin 224 224 +49818 ./prep_dataset/ILSVRC2012_val_00013709.bin 224 224 +49819 ./prep_dataset/ILSVRC2012_val_00025174.bin 224 224 +49820 ./prep_dataset/ILSVRC2012_val_00044325.bin 224 224 +49821 ./prep_dataset/ILSVRC2012_val_00027210.bin 224 224 +49822 ./prep_dataset/ILSVRC2012_val_00039359.bin 224 224 +49823 ./prep_dataset/ILSVRC2012_val_00034116.bin 224 224 +49824 ./prep_dataset/ILSVRC2012_val_00035237.bin 224 224 +49825 ./prep_dataset/ILSVRC2012_val_00020625.bin 224 224 +49826 ./prep_dataset/ILSVRC2012_val_00037582.bin 224 224 +49827 ./prep_dataset/ILSVRC2012_val_00010545.bin 224 224 +49828 ./prep_dataset/ILSVRC2012_val_00018532.bin 224 224 +49829 ./prep_dataset/ILSVRC2012_val_00002140.bin 224 224 +49830 ./prep_dataset/ILSVRC2012_val_00032706.bin 224 224 +49831 ./prep_dataset/ILSVRC2012_val_00020643.bin 224 224 +49832 ./prep_dataset/ILSVRC2012_val_00037521.bin 224 224 +49833 ./prep_dataset/ILSVRC2012_val_00006945.bin 224 224 +49834 ./prep_dataset/ILSVRC2012_val_00013332.bin 224 224 +49835 ./prep_dataset/ILSVRC2012_val_00044633.bin 224 224 +49836 ./prep_dataset/ILSVRC2012_val_00048538.bin 224 224 +49837 ./prep_dataset/ILSVRC2012_val_00026262.bin 224 224 +49838 ./prep_dataset/ILSVRC2012_val_00020340.bin 224 224 +49839 ./prep_dataset/ILSVRC2012_val_00042629.bin 224 224 +49840 ./prep_dataset/ILSVRC2012_val_00048392.bin 224 224 +49841 ./prep_dataset/ILSVRC2012_val_00032961.bin 224 224 +49842 ./prep_dataset/ILSVRC2012_val_00024141.bin 224 224 +49843 ./prep_dataset/ILSVRC2012_val_00033575.bin 224 224 +49844 ./prep_dataset/ILSVRC2012_val_00013905.bin 224 224 +49845 ./prep_dataset/ILSVRC2012_val_00048540.bin 224 224 +49846 ./prep_dataset/ILSVRC2012_val_00013075.bin 224 224 +49847 ./prep_dataset/ILSVRC2012_val_00016390.bin 224 224 +49848 ./prep_dataset/ILSVRC2012_val_00035017.bin 224 224 +49849 ./prep_dataset/ILSVRC2012_val_00042000.bin 224 224 +49850 ./prep_dataset/ILSVRC2012_val_00017785.bin 224 224 +49851 ./prep_dataset/ILSVRC2012_val_00021280.bin 224 224 +49852 ./prep_dataset/ILSVRC2012_val_00022719.bin 224 224 +49853 ./prep_dataset/ILSVRC2012_val_00049621.bin 224 224 +49854 ./prep_dataset/ILSVRC2012_val_00028437.bin 224 224 +49855 ./prep_dataset/ILSVRC2012_val_00035132.bin 224 224 +49856 ./prep_dataset/ILSVRC2012_val_00027778.bin 224 224 +49857 ./prep_dataset/ILSVRC2012_val_00020851.bin 224 224 +49858 ./prep_dataset/ILSVRC2012_val_00004774.bin 224 224 +49859 ./prep_dataset/ILSVRC2012_val_00015538.bin 224 224 +49860 ./prep_dataset/ILSVRC2012_val_00041600.bin 224 224 +49861 ./prep_dataset/ILSVRC2012_val_00000322.bin 224 224 +49862 ./prep_dataset/ILSVRC2012_val_00022744.bin 224 224 +49863 ./prep_dataset/ILSVRC2012_val_00003904.bin 224 224 +49864 ./prep_dataset/ILSVRC2012_val_00030035.bin 224 224 +49865 ./prep_dataset/ILSVRC2012_val_00003553.bin 224 224 +49866 ./prep_dataset/ILSVRC2012_val_00043399.bin 224 224 +49867 ./prep_dataset/ILSVRC2012_val_00038688.bin 224 224 +49868 ./prep_dataset/ILSVRC2012_val_00000158.bin 224 224 +49869 ./prep_dataset/ILSVRC2012_val_00035068.bin 224 224 +49870 ./prep_dataset/ILSVRC2012_val_00029409.bin 224 224 +49871 ./prep_dataset/ILSVRC2012_val_00003055.bin 224 224 +49872 ./prep_dataset/ILSVRC2012_val_00009528.bin 224 224 +49873 ./prep_dataset/ILSVRC2012_val_00047578.bin 224 224 +49874 ./prep_dataset/ILSVRC2012_val_00036299.bin 224 224 +49875 ./prep_dataset/ILSVRC2012_val_00030005.bin 224 224 +49876 ./prep_dataset/ILSVRC2012_val_00006085.bin 224 224 +49877 ./prep_dataset/ILSVRC2012_val_00016045.bin 224 224 +49878 ./prep_dataset/ILSVRC2012_val_00016817.bin 224 224 +49879 ./prep_dataset/ILSVRC2012_val_00023129.bin 224 224 +49880 ./prep_dataset/ILSVRC2012_val_00013395.bin 224 224 +49881 ./prep_dataset/ILSVRC2012_val_00006901.bin 224 224 +49882 ./prep_dataset/ILSVRC2012_val_00036453.bin 224 224 +49883 ./prep_dataset/ILSVRC2012_val_00031119.bin 224 224 +49884 ./prep_dataset/ILSVRC2012_val_00011204.bin 224 224 +49885 ./prep_dataset/ILSVRC2012_val_00026224.bin 224 224 +49886 ./prep_dataset/ILSVRC2012_val_00023954.bin 224 224 +49887 ./prep_dataset/ILSVRC2012_val_00039828.bin 224 224 +49888 ./prep_dataset/ILSVRC2012_val_00019960.bin 224 224 +49889 ./prep_dataset/ILSVRC2012_val_00035545.bin 224 224 +49890 ./prep_dataset/ILSVRC2012_val_00026892.bin 224 224 +49891 ./prep_dataset/ILSVRC2012_val_00033617.bin 224 224 +49892 ./prep_dataset/ILSVRC2012_val_00010700.bin 224 224 +49893 ./prep_dataset/ILSVRC2012_val_00010931.bin 224 224 +49894 ./prep_dataset/ILSVRC2012_val_00002142.bin 224 224 +49895 ./prep_dataset/ILSVRC2012_val_00045209.bin 224 224 +49896 ./prep_dataset/ILSVRC2012_val_00034010.bin 224 224 +49897 ./prep_dataset/ILSVRC2012_val_00012878.bin 224 224 +49898 ./prep_dataset/ILSVRC2012_val_00021433.bin 224 224 +49899 ./prep_dataset/ILSVRC2012_val_00031553.bin 224 224 +49900 ./prep_dataset/ILSVRC2012_val_00027779.bin 224 224 +49901 ./prep_dataset/ILSVRC2012_val_00001479.bin 224 224 +49902 ./prep_dataset/ILSVRC2012_val_00015225.bin 224 224 +49903 ./prep_dataset/ILSVRC2012_val_00006498.bin 224 224 +49904 ./prep_dataset/ILSVRC2012_val_00017145.bin 224 224 +49905 ./prep_dataset/ILSVRC2012_val_00029854.bin 224 224 +49906 ./prep_dataset/ILSVRC2012_val_00049986.bin 224 224 +49907 ./prep_dataset/ILSVRC2012_val_00029565.bin 224 224 +49908 ./prep_dataset/ILSVRC2012_val_00009080.bin 224 224 +49909 ./prep_dataset/ILSVRC2012_val_00012303.bin 224 224 +49910 ./prep_dataset/ILSVRC2012_val_00015657.bin 224 224 +49911 ./prep_dataset/ILSVRC2012_val_00048837.bin 224 224 +49912 ./prep_dataset/ILSVRC2012_val_00031153.bin 224 224 +49913 ./prep_dataset/ILSVRC2012_val_00040244.bin 224 224 +49914 ./prep_dataset/ILSVRC2012_val_00049853.bin 224 224 +49915 ./prep_dataset/ILSVRC2012_val_00015146.bin 224 224 +49916 ./prep_dataset/ILSVRC2012_val_00031460.bin 224 224 +49917 ./prep_dataset/ILSVRC2012_val_00004446.bin 224 224 +49918 ./prep_dataset/ILSVRC2012_val_00018550.bin 224 224 +49919 ./prep_dataset/ILSVRC2012_val_00030624.bin 224 224 +49920 ./prep_dataset/ILSVRC2012_val_00025387.bin 224 224 +49921 ./prep_dataset/ILSVRC2012_val_00029642.bin 224 224 +49922 ./prep_dataset/ILSVRC2012_val_00015580.bin 224 224 +49923 ./prep_dataset/ILSVRC2012_val_00008694.bin 224 224 +49924 ./prep_dataset/ILSVRC2012_val_00046621.bin 224 224 +49925 ./prep_dataset/ILSVRC2012_val_00003671.bin 224 224 +49926 ./prep_dataset/ILSVRC2012_val_00016734.bin 224 224 +49927 ./prep_dataset/ILSVRC2012_val_00027552.bin 224 224 +49928 ./prep_dataset/ILSVRC2012_val_00045669.bin 224 224 +49929 ./prep_dataset/ILSVRC2012_val_00000284.bin 224 224 +49930 ./prep_dataset/ILSVRC2012_val_00020858.bin 224 224 +49931 ./prep_dataset/ILSVRC2012_val_00026118.bin 224 224 +49932 ./prep_dataset/ILSVRC2012_val_00041381.bin 224 224 +49933 ./prep_dataset/ILSVRC2012_val_00033147.bin 224 224 +49934 ./prep_dataset/ILSVRC2012_val_00032718.bin 224 224 +49935 ./prep_dataset/ILSVRC2012_val_00040944.bin 224 224 +49936 ./prep_dataset/ILSVRC2012_val_00010301.bin 224 224 +49937 ./prep_dataset/ILSVRC2012_val_00037462.bin 224 224 +49938 ./prep_dataset/ILSVRC2012_val_00014854.bin 224 224 +49939 ./prep_dataset/ILSVRC2012_val_00027052.bin 224 224 +49940 ./prep_dataset/ILSVRC2012_val_00024554.bin 224 224 +49941 ./prep_dataset/ILSVRC2012_val_00026249.bin 224 224 +49942 ./prep_dataset/ILSVRC2012_val_00044063.bin 224 224 +49943 ./prep_dataset/ILSVRC2012_val_00046506.bin 224 224 +49944 ./prep_dataset/ILSVRC2012_val_00047696.bin 224 224 +49945 ./prep_dataset/ILSVRC2012_val_00019716.bin 224 224 +49946 ./prep_dataset/ILSVRC2012_val_00025278.bin 224 224 +49947 ./prep_dataset/ILSVRC2012_val_00035586.bin 224 224 +49948 ./prep_dataset/ILSVRC2012_val_00033815.bin 224 224 +49949 ./prep_dataset/ILSVRC2012_val_00001906.bin 224 224 +49950 ./prep_dataset/ILSVRC2012_val_00002147.bin 224 224 +49951 ./prep_dataset/ILSVRC2012_val_00025027.bin 224 224 +49952 ./prep_dataset/ILSVRC2012_val_00027369.bin 224 224 +49953 ./prep_dataset/ILSVRC2012_val_00044339.bin 224 224 +49954 ./prep_dataset/ILSVRC2012_val_00000802.bin 224 224 +49955 ./prep_dataset/ILSVRC2012_val_00004028.bin 224 224 +49956 ./prep_dataset/ILSVRC2012_val_00024765.bin 224 224 +49957 ./prep_dataset/ILSVRC2012_val_00008325.bin 224 224 +49958 ./prep_dataset/ILSVRC2012_val_00042803.bin 224 224 +49959 ./prep_dataset/ILSVRC2012_val_00035225.bin 224 224 +49960 ./prep_dataset/ILSVRC2012_val_00043268.bin 224 224 +49961 ./prep_dataset/ILSVRC2012_val_00022526.bin 224 224 +49962 ./prep_dataset/ILSVRC2012_val_00031668.bin 224 224 +49963 ./prep_dataset/ILSVRC2012_val_00046299.bin 224 224 +49964 ./prep_dataset/ILSVRC2012_val_00046641.bin 224 224 +49965 ./prep_dataset/ILSVRC2012_val_00038646.bin 224 224 +49966 ./prep_dataset/ILSVRC2012_val_00028032.bin 224 224 +49967 ./prep_dataset/ILSVRC2012_val_00013694.bin 224 224 +49968 ./prep_dataset/ILSVRC2012_val_00020911.bin 224 224 +49969 ./prep_dataset/ILSVRC2012_val_00031272.bin 224 224 +49970 ./prep_dataset/ILSVRC2012_val_00016764.bin 224 224 +49971 ./prep_dataset/ILSVRC2012_val_00006767.bin 224 224 +49972 ./prep_dataset/ILSVRC2012_val_00029968.bin 224 224 +49973 ./prep_dataset/ILSVRC2012_val_00028403.bin 224 224 +49974 ./prep_dataset/ILSVRC2012_val_00019051.bin 224 224 +49975 ./prep_dataset/ILSVRC2012_val_00046195.bin 224 224 +49976 ./prep_dataset/ILSVRC2012_val_00037067.bin 224 224 +49977 ./prep_dataset/ILSVRC2012_val_00023879.bin 224 224 +49978 ./prep_dataset/ILSVRC2012_val_00008183.bin 224 224 +49979 ./prep_dataset/ILSVRC2012_val_00020076.bin 224 224 +49980 ./prep_dataset/ILSVRC2012_val_00009729.bin 224 224 +49981 ./prep_dataset/ILSVRC2012_val_00027089.bin 224 224 +49982 ./prep_dataset/ILSVRC2012_val_00014131.bin 224 224 +49983 ./prep_dataset/ILSVRC2012_val_00043057.bin 224 224 +49984 ./prep_dataset/ILSVRC2012_val_00029344.bin 224 224 +49985 ./prep_dataset/ILSVRC2012_val_00008922.bin 224 224 +49986 ./prep_dataset/ILSVRC2012_val_00018597.bin 224 224 +49987 ./prep_dataset/ILSVRC2012_val_00018109.bin 224 224 +49988 ./prep_dataset/ILSVRC2012_val_00023083.bin 224 224 +49989 ./prep_dataset/ILSVRC2012_val_00043234.bin 224 224 +49990 ./prep_dataset/ILSVRC2012_val_00012237.bin 224 224 +49991 ./prep_dataset/ILSVRC2012_val_00023594.bin 224 224 +49992 ./prep_dataset/ILSVRC2012_val_00044402.bin 224 224 +49993 ./prep_dataset/ILSVRC2012_val_00028311.bin 224 224 +49994 ./prep_dataset/ILSVRC2012_val_00025326.bin 224 224 +49995 ./prep_dataset/ILSVRC2012_val_00030232.bin 224 224 +49996 ./prep_dataset/ILSVRC2012_val_00049347.bin 224 224 +49997 ./prep_dataset/ILSVRC2012_val_00015934.bin 224 224 +49998 ./prep_dataset/ILSVRC2012_val_00032497.bin 224 224 +49999 ./prep_dataset/ILSVRC2012_val_00005669.bin 224 224 diff --git a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/wrn101_2_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/wrn101_2_pth2onnx.py index 41e36408ff8e1ddaa5ea63fa5f3f6a0d85773799..6395fdddcff23086f117883aaa9b01cf035cb424 100644 --- a/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/wrn101_2_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2/wrn101_2_pth2onnx.py @@ -1,35 +1,35 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import torch -import torch.onnx -import torchvision.models as models - -def pth2onnx(input_file, output_file): - model = models.wide_resnet101_2(pretrained=False) - checkpoint = torch.load(input_file, map_location=None) - model.load_state_dict(checkpoint) - - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) - -if __name__ == "__main__": - input_file = sys.argv[1] - output_file = sys.argv[2] +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import torch +import torch.onnx +import torchvision.models as models + +def pth2onnx(input_file, output_file): + model = models.wide_resnet101_2(pretrained=False) + checkpoint = torch.load(input_file, map_location=None) + model.load_state_dict(checkpoint) + + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) + +if __name__ == "__main__": + input_file = sys.argv[1] + output_file = sys.argv[2] pth2onnx(input_file, output_file) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/X3D/LICENSE b/ACL_PyTorch/contrib/cv/classfication/X3D/LICENSE index df2c2f2c3e55bfbad1aebe53321a94ee5a3854bc..c8ec075d5b892f823d0b485ad4fdd01355c57b3e 100644 --- a/ACL_PyTorch/contrib/cv/classfication/X3D/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/X3D/LICENSE @@ -1,203 +1,203 @@ -Copyright 2018-2019 Open-MMLab. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2018-2019 Open-MMLab. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and +Copyright 2018-2019 Open-MMLab. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2019 Open-MMLab. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/X3D/README.md b/ACL_PyTorch/contrib/cv/classfication/X3D/README.md index 6453cc151a97a97ce0076e772e23bb9f9e6981b6..7a9e3338e24264e4e0ecd093873a851f952c6244 100644 --- a/ACL_PyTorch/contrib/cv/classfication/X3D/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/X3D/README.md @@ -1,69 +1,69 @@ -# X3D模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - -``` -pip3 install -r requirements.txt -``` -2.获取,修改与安装开源模型代码 -``` -git clone https://github.com/facebookresearch/detectron2 detectron2_repo -pip3 install -e detectron2_repo - -git clone https://github.com/facebookresearch/SlowFast -b master -cd SlowFast - -git reset 9839d1318c0ae17bd82c6a121e5640aebc67f126 --hard -patch -p1 < x3d.patch -python3.7 setup.py build develop - -cd .. - -``` -3.[获取权重文件 x3d_s.pyth](https://github.com/facebookresearch/SlowFast/blob/master/MODEL_ZOO.md) - - 将权重文件x3d_s.pyth放在当前目录。 - -4.获取数据集Knetics-400 - -脚本下载: -获取验证集列表文件[val_link.list](https://ai-rank.bj.bcebos.com/Kinetics400/val_link.list)与验证集标签文件[val.list](https://videotag.bj.bcebos.com/PaddleVideo/Data/Kinetic400/val.list),并将val.list重命名为test.csv -下载验证集: -``` -download.sh: -file=$1 - -while read line -do - wget "$line" -done <$file - -download.sh val_link.list -``` -将下载的val_part1,val_part2,val_part3里的400个文件夹放到/root/datasets/Knetics-400/val,将test.csv放到/root/datasets/Knetics-400。 - -5.获取 [msame工具](https://gitee.com/ascend/tools/tree/master/msame) -和 -[benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) - -将msame和benchmark.x86_64(或benchmark.aarch64)放到当前目录 - - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 - -``` -bash test/pth2om.sh -bash test/evl_acc_pref.sh --datasets_path=/root/datasets/Knetics-400 -``` -备注:存在fp16算子溢出,精度不达标,因此atc模型转换需要添加--precision_mode allow_mix_precision - -**评测结果:** - -| 模型 | 官网pth精度 | 310精度 | 基准性能| 310性能 | -| ---- | ------------------------------------------------------------ | --------------- | -------- | ------- | -| X3d bs1 | [Top1:73.1%](https://github.com/facebookresearch/SlowFast/blob/master/MODEL_ZOO.md) | Top1:72.86% Top5:89.45% | 95.07fps | 158.57fps | +# X3D模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + +``` +pip3 install -r requirements.txt +``` +2.获取,修改与安装开源模型代码 +``` +git clone https://github.com/facebookresearch/detectron2 detectron2_repo +pip3 install -e detectron2_repo + +git clone https://github.com/facebookresearch/SlowFast -b master +cd SlowFast + +git reset 9839d1318c0ae17bd82c6a121e5640aebc67f126 --hard +patch -p1 < x3d.patch +python3.7 setup.py build develop + +cd .. + +``` +3.[获取权重文件 x3d_s.pyth](https://github.com/facebookresearch/SlowFast/blob/master/MODEL_ZOO.md) + + 将权重文件x3d_s.pyth放在当前目录。 + +4.获取数据集Knetics-400 + +脚本下载: +获取验证集列表文件[val_link.list](https://ai-rank.bj.bcebos.com/Kinetics400/val_link.list)与验证集标签文件[val.list](https://videotag.bj.bcebos.com/PaddleVideo/Data/Kinetic400/val.list),并将val.list重命名为test.csv +下载验证集: +``` +download.sh: +file=$1 + +while read line +do + wget "$line" +done <$file + +download.sh val_link.list +``` +将下载的val_part1,val_part2,val_part3里的400个文件夹放到/root/datasets/Knetics-400/val,将test.csv放到/root/datasets/Knetics-400。 + +5.获取 [msame工具](https://gitee.com/ascend/tools/tree/master/msame) +和 +[benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) + +将msame和benchmark.x86_64(或benchmark.aarch64)放到当前目录 + + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 + +``` +bash test/pth2om.sh +bash test/evl_acc_pref.sh --datasets_path=/root/datasets/Knetics-400 +``` +备注:存在fp16算子溢出,精度不达标,因此atc模型转换需要添加--precision_mode allow_mix_precision + +**评测结果:** + +| 模型 | 官网pth精度 | 310精度 | 基准性能| 310性能 | +| ---- | ------------------------------------------------------------ | --------------- | -------- | ------- | +| X3d bs1 | [Top1:73.1%](https://github.com/facebookresearch/SlowFast/blob/master/MODEL_ZOO.md) | Top1:72.86% Top5:89.45% | 95.07fps | 158.57fps | | X3d bs16| [Top1:73.1%](https://github.com/facebookresearch/SlowFast/blob/master/MODEL_ZOO.md) | Top1:72.86% Top5:89.45% | 103.82fps | 115.34fps | \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/LICENSE b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/README.md b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/README.md index 340b66fc5d532e4a8b0627c190fe6c3e73d83cfb..952c95a9166bbff3e702dc2d4de8f01141583253 100644 --- a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/README.md @@ -1,46 +1,46 @@ -# Dino_Resnet50模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -``` -pip3.7 install -r requirements.txt -``` - - -2.获取开源模型代码 -``` -git clone https://github.com/facebooksearch/dino -``` - -3.获取权重文件 - - [获取权重文件](https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/DINO/dino_resnet50_linearweights.pth) - [获取权重文件](https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/DINO/dino_resnet50_pretrain.pth) - -4.数据集 -自行获取LSVRC2012验证集和标签文本 - -5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) -将benchmark.x86_64放到当前工作目录 - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest -bash test/pth2om.sh -bash test/eval_acc_perf.sh -``` -pth2om.sh文件第1到6行是转onnx,第8到20行是转om -eval_acc_perf.sh文件第24到54行是精度,第55到66行是性能 - **评测结果:** -| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| :------: | :------: | :------: | :------: | :------: | -| dino_resnet50_bs1 | [top1: 75.3%](https://github.com/facebookresearch/dino#evaluation-linear-classification-on-imagenet) | top1: 75.27% | 891.845fps | 1521.508fps | +# Dino_Resnet50模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip3.7 install -r requirements.txt +``` + + +2.获取开源模型代码 +``` +git clone https://github.com/facebooksearch/dino +``` + +3.获取权重文件 + + [获取权重文件](https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/DINO/dino_resnet50_linearweights.pth) + [获取权重文件](https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/DINO/dino_resnet50_pretrain.pth) + +4.数据集 +自行获取LSVRC2012验证集和标签文本 + +5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) +将benchmark.x86_64放到当前工作目录 + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest +bash test/pth2om.sh +bash test/eval_acc_perf.sh +``` +pth2om.sh文件第1到6行是转onnx,第8到20行是转om +eval_acc_perf.sh文件第24到54行是精度,第55到66行是性能 + **评测结果:** +| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| :------: | :------: | :------: | :------: | :------: | +| dino_resnet50_bs1 | [top1: 75.3%](https://github.com/facebookresearch/dino#evaluation-linear-classification-on-imagenet) | top1: 75.27% | 891.845fps | 1521.508fps | | dino_resnet50_bs16 | [top1: 75.3%](https://github.com/facebookresearch/dino#evaluation-linear-classification-on-imagenet) | top1: 75.27% | 2003.345fps | 2406.68fps | \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/dino_resnet50_postprocess.py b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/dino_resnet50_postprocess.py index 4b5b462ff781b676f9cd89f247467e7f623fd0cb..2b0acb41e561d0c148840ef8430f08a423af09d6 100644 --- a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/dino_resnet50_postprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/dino_resnet50_postprocess.py @@ -1,169 +1,169 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import argparse - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - if data == '': - n_label = 0 - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_file, img_gt_dict, - topn=5): - """ - :param prediction_file_path: - :param result_file: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(result_file, 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -def check_args(args): - if not (os.path.exists(args.anno_file)): - print("annotation file:{} does not exist.".format(args.anno_file)) - exit() - if not (os.path.exists(args.benchmark_out)): - print("benchmark output:{} does not exist.".format(args.benchmark_out)) - exit() - return args - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Precision statistics of Vision model') - parser.add_argument("--anno_file", default="./HiAI_label.json", help='annotation file') - parser.add_argument("--benchmark_out", default="result/dumpOutput_device0", help='Benchmark output directory') - parser.add_argument("--result_file", default="./result.json", help='Output json file') - args = parser.parse_args() - args = check_args(args) - if args.anno_file.endswith('txt'): - img_label_dict = cre_groundtruth_dict_fromtxt(args.anno_file) - else: - img_label_dict = cre_groundtruth_dict(args.anno_file) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import argparse + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_file, img_gt_dict, + topn=5): + """ + :param prediction_file_path: + :param result_file: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(result_file, 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +def check_args(args): + if not (os.path.exists(args.anno_file)): + print("annotation file:{} does not exist.".format(args.anno_file)) + exit() + if not (os.path.exists(args.benchmark_out)): + print("benchmark output:{} does not exist.".format(args.benchmark_out)) + exit() + return args + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Precision statistics of Vision model') + parser.add_argument("--anno_file", default="./HiAI_label.json", help='annotation file') + parser.add_argument("--benchmark_out", default="result/dumpOutput_device0", help='Benchmark output directory') + parser.add_argument("--result_file", default="./result.json", help='Output json file') + args = parser.parse_args() + args = check_args(args) + if args.anno_file.endswith('txt'): + img_label_dict = cre_groundtruth_dict_fromtxt(args.anno_file) + else: + img_label_dict = cre_groundtruth_dict(args.anno_file) create_visualization_statistical_result(args.benchmark_out, args.result_file, img_label_dict, topn=5) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/dino_resnet50_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/dino_resnet50_preprocess.py index a8c182f3cbebf46aa09111c03b8c836ec400166b..30f60993ce1433ce9600e69fb7637581c396fdc5 100644 --- a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/dino_resnet50_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/dino_resnet50_preprocess.py @@ -1,115 +1,115 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from PIL import Image -import numpy as np -import multiprocessing - - -model_config = { - 'resnet': { - 'resize': 256, - 'centercrop': 224, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv3': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.485, 0.456, 0.406], - 'std': [0.229, 0.224, 0.225], - }, - 'inceptionv4': { - 'resize': 342, - 'centercrop': 299, - 'mean': [0.5, 0.5, 0.5], - 'std': [0.5, 0.5, 0.5], - }, -} - - -def center_crop(img, output_size): - if isinstance(output_size, int): - output_size = (int(output_size), int(output_size)) - image_width, image_height = img.size - crop_height, crop_width = output_size - crop_top = int(round((image_height - crop_height) / 2.)) - crop_left = int(round((image_width - crop_width) / 2.)) - return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) - - -def resize(img, size, interpolation=Image.BILINEAR): - if isinstance(size, int): - w, h = img.size - if (w <= h and w == size) or (h <= w and h == size): - return img - if w < h: - ow = size - oh = int(size * h / w) - return img.resize((ow, oh), interpolation) - else: - oh = size - ow = int(size * w / h) - return img.resize((ow, oh), interpolation) - else: - return img.resize(size[::-1], interpolation) - - -def gen_input_bin(mode_type, file_batches, batch): - i = 0 - for file in file_batches[batch]: - i =i + 1 - print("batch", batch, file, "===", i) - - # RGBA to RGB - image = Image.open(os.path.join(src_path, file)).convert('RGB') - image = resize(image, model_config[mode_type]['resize']) # Resize - image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop - img = np.array(image, dtype=np.float32) - img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW - img = img / 255. # ToTensor: div 255 - img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean - img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - - -def preprocess(mode_type, src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) - thread_pool.close() - thread_pool.join() - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") - mode_type = sys.argv[1] - src_path = sys.argv[2] - save_path = sys.argv[3] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - if mode_type not in model_config: - model_type_help = "model type: " - for key in model_config.keys(): - model_type_help += key - model_type_help += ' ' - raise Exception(model_type_help) - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - preprocess(mode_type, src_path, save_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from PIL import Image +import numpy as np +import multiprocessing + + +model_config = { + 'resnet': { + 'resize': 256, + 'centercrop': 224, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv3': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.485, 0.456, 0.406], + 'std': [0.229, 0.224, 0.225], + }, + 'inceptionv4': { + 'resize': 342, + 'centercrop': 299, + 'mean': [0.5, 0.5, 0.5], + 'std': [0.5, 0.5, 0.5], + }, +} + + +def center_crop(img, output_size): + if isinstance(output_size, int): + output_size = (int(output_size), int(output_size)) + image_width, image_height = img.size + crop_height, crop_width = output_size + crop_top = int(round((image_height - crop_height) / 2.)) + crop_left = int(round((image_width - crop_width) / 2.)) + return img.crop((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height)) + + +def resize(img, size, interpolation=Image.BILINEAR): + if isinstance(size, int): + w, h = img.size + if (w <= h and w == size) or (h <= w and h == size): + return img + if w < h: + ow = size + oh = int(size * h / w) + return img.resize((ow, oh), interpolation) + else: + oh = size + ow = int(size * w / h) + return img.resize((ow, oh), interpolation) + else: + return img.resize(size[::-1], interpolation) + + +def gen_input_bin(mode_type, file_batches, batch): + i = 0 + for file in file_batches[batch]: + i =i + 1 + print("batch", batch, file, "===", i) + + # RGBA to RGB + image = Image.open(os.path.join(src_path, file)).convert('RGB') + image = resize(image, model_config[mode_type]['resize']) # Resize + image = center_crop(image, model_config[mode_type]['centercrop']) # CenterCrop + img = np.array(image, dtype=np.float32) + img = img.transpose(2, 0, 1) # ToTensor: HWC -> CHW + img = img / 255. # ToTensor: div 255 + img -= np.array(model_config[mode_type]['mean'], dtype=np.float32)[:, None, None] # Normalize: mean + img /= np.array(model_config[mode_type]['std'], dtype=np.float32)[:, None, None] # Normalize: std + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +def preprocess(mode_type, src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 500] for i in range(0, 50000, 500) if files[i:i + 500] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(mode_type, file_batches, batch)) + thread_pool.close() + thread_pool.join() + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [model_type] [src_path] [save_path]") + mode_type = sys.argv[1] + src_path = sys.argv[2] + save_path = sys.argv[3] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + if mode_type not in model_config: + model_type_help = "model type: " + for key in model_config.keys(): + model_type_help += key + model_type_help += ' ' + raise Exception(model_type_help) + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess(mode_type, src_path, save_path) diff --git a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/dino_resnet50_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/dino_resnet50_pth2onnx.py index 2ad540e8caa9572cfe7eae3d8df8d1fe2e555f0a..e6554df3833637c8af9cdb418aacd6fdacc46f53 100644 --- a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/dino_resnet50_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/dino_resnet50_pth2onnx.py @@ -1,46 +1,46 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import torch -import torchvision.models as models -import torch.nn as nn - - -model=models.resnet50(pretrained=True) -embed_dim = model.fc.weight.shape[1] -model.fc = nn.Identity() - -state_dict = torch.load('dino_resnet50_pretrain.pth', map_location='cpu') -temp=nn.Linear(2048,1000) -state_dict2 = torch.load('dino_resnet50_linearweights.pth', map_location='cpu')["state_dict"] -temp.weight.data = state_dict2['module.linear.weight'] -temp.bias.data = state_dict2['module.linear.bias'] -model.load_state_dict(state_dict, strict=True) - -model.fc=temp -model.eval() -x = torch.randn(1, 3, 224, 224, requires_grad=True) -model.to(device='cpu') -torch_out = model(x.to(device="cpu")) - -# Export the model -torch.onnx.export(model, # model being run - x, # model input (or a tuple for multiple inputs) - "dino_resnet50.onnx", # where to save the model (can be a file or file-like object) - export_params=True, # store the trained parameter weights inside the model file - opset_version=10, # the ONNX version to export the model to - do_constant_folding=True, # whether to execute constant folding for optimization - input_names = ['input'], # the model's input names - output_names = ['output'], # the model's output names - dynamic_axes={'input' : {0 : 'batch_size'}, # variable length axes +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import torch +import torchvision.models as models +import torch.nn as nn + + +model=models.resnet50(pretrained=True) +embed_dim = model.fc.weight.shape[1] +model.fc = nn.Identity() + +state_dict = torch.load('dino_resnet50_pretrain.pth', map_location='cpu') +temp=nn.Linear(2048,1000) +state_dict2 = torch.load('dino_resnet50_linearweights.pth', map_location='cpu')["state_dict"] +temp.weight.data = state_dict2['module.linear.weight'] +temp.bias.data = state_dict2['module.linear.bias'] +model.load_state_dict(state_dict, strict=True) + +model.fc=temp +model.eval() +x = torch.randn(1, 3, 224, 224, requires_grad=True) +model.to(device='cpu') +torch_out = model(x.to(device="cpu")) + +# Export the model +torch.onnx.export(model, # model being run + x, # model input (or a tuple for multiple inputs) + "dino_resnet50.onnx", # where to save the model (can be a file or file-like object) + export_params=True, # store the trained parameter weights inside the model file + opset_version=10, # the ONNX version to export the model to + do_constant_folding=True, # whether to execute constant folding for optimization + input_names = ['input'], # the model's input names + output_names = ['output'], # the model's output names + dynamic_axes={'input' : {0 : 'batch_size'}, # variable length axes 'output' : {0 : 'batch_size'}}) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/get_info.py b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/get_info.py index 8bd92616fcc3b327ca19322d8106d2b2be237d51..89b89cf20ad8e6e9ae784413914079d4f851e6a6 100644 --- a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/get_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/get_info.py @@ -1,59 +1,59 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/modelzoo_level.txt index 9e95396651cc4382fe60ee1ee053674f527a448c..27e6c78b37535fe4f5a17029546fe257ad164d34 100644 --- a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:POK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/test/parse.py b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/test/parse.py index 54fe38f45876316aa483f626e7512830f289a2e1..7922b1d1643fdec070c5dbbc1100ed83f8273922 100644 --- a/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/test/parse.py +++ b/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50/test/parse.py @@ -1,31 +1,31 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - - print(content) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + + print(content) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/LICENSE b/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/README.md b/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/README.md index 6caf0b8617ef1bea6f1c9f9dae4054441c3c02d5..6e08c3eda9b96b21a4bface41196f7d31ab563af 100644 --- a/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/README.md @@ -1,167 +1,167 @@ -# convmixer ONNX模型端到端推理指导 -- [1. 模型概述](#1) - - [论文地址](#11) - - [代码地址](#12) -- [2. 环境说明](#2) - - [深度学习框架](#21) - - [python第三方库](#22) -- [3. 模型转换](#3) - - [pth转onnx模型](#31) - - [onnx转om模型](#32) -- [4. 数据预处理](#4) - - [数据处理](#41) -- [5. 离线推理](#5) - - [msame工具概述](#51) - - [离线推理](#52) - - [精度和性能比较](#53) - -## 1. 模型概述 -### 1.1 论文地址 -[convmixer论文](https://openreview.net/forum?id=TVHS5Y4dNvM) -### 1.2 代码地址 -[convmixer代码](https://github.com/locuslab/convmixer) - -修改源码中的convmixer.py并移至本项目中重命名为convmixer_net.py: -``` -git clone https://github.com/locuslab/convmixer.git -mv convmixer_patch.patch convmixer -cd convmixer -git apply convmixer_patch.patch -scp convmixer.py ../convmixer_net.py -cd .. -``` -> **说明:** -> 本离线推理项目中convmixer模型对应论文中convmixer_1536_20,以下说明中将convmixer_1536_20简称为convmixer - -## 2. 环境说明 -### 2.1 深度学习框架 -``` -CANN 5.1.RC1 -torch==1.5.0 -torchvision==0.6.0 -onnx==1.10.2 -``` - -### 2.2 python第三方库 -``` -numpy -Pillow==9.0.1 -``` -> **说明:** -> pytorch,torchvision和onnx:(X86架构)可以通过pip方式安装或官方下载whl包安装; (Arm架构)可以通过源码编译安装 -> 其他第三方库: 可以通过 pip3.7 install -r requirements.txt 进行安装 - -## 3. 模型转换 -一步式从pth.tar权重文件转om模型的脚本,能够由pth.tar权重文件生成bacth为1的om模型: -```bash -bash ./test/pth2om.sh --batch_size=1 --not_skip_onnx=true -``` -运行后会生成如下文件: -```bash -├── convmixer_1536_20.onnx -├── convmixer_1536_20_bs1.om -``` - -### 3.1 pth转onnx模型 -1. 设置环境变量 -```bash -source /usr/local/Ascend/ascend-toolkit/set_env.sh -``` - -2. 下载convmixer_1536_20的权重文件: -[convmixer_1536_20_ks9_p7.pth.tar](https://github.com/tmp-iclr/convmixer/releases/download/v1.0/convmixer_1536_20_ks9_p7.pth.tar) - -3. 执行convmixer_pth2onnx.py脚本,生成onnx模型文件 -```bash -python3.7 convmixer_pth2onnx.py --source "./convmixer_1536_20_ks9_p7.pth.tar" --target "./convmixer_1536_20.onnx" -``` -其中"source"表示模型加载权重的地址和名称,"target"表示转换后生成的onnx模型的存储地址和名称 - -### 3.2 onnx转om模型 -1. 使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/51RC2alpha002/infacldevg/atctool) - -```bash -atc --framework=5 --model=./convmixer_1536_20.onnx --output=./convmixer_1536_20_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=error --soc_version=Ascend710 --op_select_implmode=high_performance --optypelist_for_implmode="Gelu" -``` - -## 4. 数据预处理 -数据预处理过程包含在 test/eval_acc_perf.sh 的脚本中 -### 4.1 数据处理 -1. 设置环境变量 -```bash -source /usr/local/Ascend/ascend-toolkit/set_env.sh -``` - -2. convmixer模型使用ImageNet2012中的5万张验证集数据进行测试,具体来说参考convmixer的源码仓中的测试过程对验证集图像进行缩放,中心裁剪以及归一化,并将图像数据转换为二进制文件(.bin) -> **说明:** -> 本项目使用的推理工具为msame,需要针对不同的batch size生成不同的输入数据 - -3. 执行输入数据的生成脚本,生成模型输入的bin文件 -```bash -python3.7 convmixer_preprocess.py --image-path /opt/npu/imageNet/val --prep-image ./prep_image_bs1 --batch-size 1 -``` -其中"image-path"表示处理前原数据集的地址,"prep-image"表示生成数据集的文件夹名称(将在文件夹名称后会自动标识对应batch size),"batch-size"表示生成数据集对应的batch size -运行后,将会得到如下形式的文件夹: -``` -├── prep_image_bs1 -│ ├──input_00000.bin -│ ├──...... -``` - -## 5. 离线推理 -执行一步式推理前,请先按照5.1节准备msame离线推理工具 -一步式进行输入数据的准备,模型离线推理和NPU性能数据的获取: -```bash -bash ./test/eval_acc_perf.sh --batch_size=1 --datasets_path=/opt/npu/imageNet -``` -运行后会生成如下文件/文件夹: -```bash -├── prep_image_bs1 # 模型的标签输入(文件夹) -├── msame_bs1.txt # msame推理过程的输出 -├── result -│ ├── outputs_bs1_om # 模型的输出(文件夹) -│ ├── result_bs1.json # 模型的精度输出 -``` - -### 5.1 msame工具概述 -msame模型推理工具,其输入是om模型以及模型所需要的输入bin文件,其输出是模型根据相应输入产生的输出文件。获取工具及使用方法可以参考[msame模型推理工具指南](https://gitee.com/ascend/tools/tree/master/msame) -### 5.2 离线推理 -1. 设置环境变量 -```bash -source /usr/local/Ascend/ascend-toolkit/set_env.sh -``` - -2. 执行离线推理 -运行如下命令进行离线推理: -```bash -./msame --model ./convmixer_1536_20_bs1.om --output ./result/outputs_bs1_om --outfmt TXT --input ./prep_image_bs1 > msame_bs1.txt -``` -模型输出格式是txt,输出保存在"output"参数指定的文件夹中,同时会生成推理的日志文件msame_bs1.txt - -### 5.3 精度和性能比较 -1. 性能数据的获取 -通过给test/parser.py指定推理后的日志文件,可以得到离线推理的性能数据 -```bash -python3.7 test/parse.py --result-file ./msame_bs1.txt --batch-size 1 -``` -其中"result-file"表示性能数据的地址和名称,"batch-size"表示性能测试时模型对应的batch size - -2. 精度数据的计算 -精度计算利用convmixer_eval_acc.py脚本 -``` -python3.7 convmixer_eval_acc.py --folder-davinci-target ./result/outputs_bs1_om/ --annotation-file-path /opt/npu/imageNet/val_label.txt --result-json-path ./result --json-file-name result_bs1.json --batch-size 1 -``` -其中"folder-davinci-target"表示离线推理输出所在的文件夹,"annotation-file-path"表示ImageNet2012验证集标签的地址和名称,"result-json-path"输出精度数据所在的文件夹,"json-file-name"表示输出精度数据所在的文件名,"batch-size"表示精度测试时模型对应的batch size - -3. 精度数据的获取 -通过给test/parser.py指定推理后的日志文件,可以得到离线推理的性能数据 -```bash -python3.7 test/parse.py --result-file ./result/result_bs1.json -``` -| 模型 | 参考精度 | 310P精度 | 性能基准 | 310P性能 | -| :------: | :------: | :------: | :------: | :------: | -| convmixer_1536_20 bs1 | top1:81.37% | top1:81.35% | 44.445fps | 115.790fps | -| convmixer_1536_20 bs4 | top1:81.37% | top1:81.35% |59.353fps | 117.252fps | - -> **说明:** +# convmixer ONNX模型端到端推理指导 +- [1. 模型概述](#1) + - [论文地址](#11) + - [代码地址](#12) +- [2. 环境说明](#2) + - [深度学习框架](#21) + - [python第三方库](#22) +- [3. 模型转换](#3) + - [pth转onnx模型](#31) + - [onnx转om模型](#32) +- [4. 数据预处理](#4) + - [数据处理](#41) +- [5. 离线推理](#5) + - [msame工具概述](#51) + - [离线推理](#52) + - [精度和性能比较](#53) + +## 1. 模型概述 +### 1.1 论文地址 +[convmixer论文](https://openreview.net/forum?id=TVHS5Y4dNvM) +### 1.2 代码地址 +[convmixer代码](https://github.com/locuslab/convmixer) + +修改源码中的convmixer.py并移至本项目中重命名为convmixer_net.py: +``` +git clone https://github.com/locuslab/convmixer.git +mv convmixer_patch.patch convmixer +cd convmixer +git apply convmixer_patch.patch +scp convmixer.py ../convmixer_net.py +cd .. +``` +> **说明:** +> 本离线推理项目中convmixer模型对应论文中convmixer_1536_20,以下说明中将convmixer_1536_20简称为convmixer + +## 2. 环境说明 +### 2.1 深度学习框架 +``` +CANN 5.1.RC1 +torch==1.5.0 +torchvision==0.6.0 +onnx==1.10.2 +``` + +### 2.2 python第三方库 +``` +numpy +Pillow==9.0.1 +``` +> **说明:** +> pytorch,torchvision和onnx:(X86架构)可以通过pip方式安装或官方下载whl包安装; (Arm架构)可以通过源码编译安装 +> 其他第三方库: 可以通过 pip3.7 install -r requirements.txt 进行安装 + +## 3. 模型转换 +一步式从pth.tar权重文件转om模型的脚本,能够由pth.tar权重文件生成bacth为1的om模型: +```bash +bash ./test/pth2om.sh --batch_size=1 --not_skip_onnx=true +``` +运行后会生成如下文件: +```bash +├── convmixer_1536_20.onnx +├── convmixer_1536_20_bs1.om +``` + +### 3.1 pth转onnx模型 +1. 设置环境变量 +```bash +source /usr/local/Ascend/ascend-toolkit/set_env.sh +``` + +2. 下载convmixer_1536_20的权重文件: +[convmixer_1536_20_ks9_p7.pth.tar](https://github.com/tmp-iclr/convmixer/releases/download/v1.0/convmixer_1536_20_ks9_p7.pth.tar) + +3. 执行convmixer_pth2onnx.py脚本,生成onnx模型文件 +```bash +python3.7 convmixer_pth2onnx.py --source "./convmixer_1536_20_ks9_p7.pth.tar" --target "./convmixer_1536_20.onnx" +``` +其中"source"表示模型加载权重的地址和名称,"target"表示转换后生成的onnx模型的存储地址和名称 + +### 3.2 onnx转om模型 +1. 使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/51RC2alpha002/infacldevg/atctool) + +```bash +atc --framework=5 --model=./convmixer_1536_20.onnx --output=./convmixer_1536_20_bs1 --input_format=NCHW --input_shape="image:1,3,224,224" --log=error --soc_version=Ascend710 --op_select_implmode=high_performance --optypelist_for_implmode="Gelu" +``` + +## 4. 数据预处理 +数据预处理过程包含在 test/eval_acc_perf.sh 的脚本中 +### 4.1 数据处理 +1. 设置环境变量 +```bash +source /usr/local/Ascend/ascend-toolkit/set_env.sh +``` + +2. convmixer模型使用ImageNet2012中的5万张验证集数据进行测试,具体来说参考convmixer的源码仓中的测试过程对验证集图像进行缩放,中心裁剪以及归一化,并将图像数据转换为二进制文件(.bin) +> **说明:** +> 本项目使用的推理工具为msame,需要针对不同的batch size生成不同的输入数据 + +3. 执行输入数据的生成脚本,生成模型输入的bin文件 +```bash +python3.7 convmixer_preprocess.py --image-path /opt/npu/imageNet/val --prep-image ./prep_image_bs1 --batch-size 1 +``` +其中"image-path"表示处理前原数据集的地址,"prep-image"表示生成数据集的文件夹名称(将在文件夹名称后会自动标识对应batch size),"batch-size"表示生成数据集对应的batch size +运行后,将会得到如下形式的文件夹: +``` +├── prep_image_bs1 +│ ├──input_00000.bin +│ ├──...... +``` + +## 5. 离线推理 +执行一步式推理前,请先按照5.1节准备msame离线推理工具 +一步式进行输入数据的准备,模型离线推理和NPU性能数据的获取: +```bash +bash ./test/eval_acc_perf.sh --batch_size=1 --datasets_path=/opt/npu/imageNet +``` +运行后会生成如下文件/文件夹: +```bash +├── prep_image_bs1 # 模型的标签输入(文件夹) +├── msame_bs1.txt # msame推理过程的输出 +├── result +│ ├── outputs_bs1_om # 模型的输出(文件夹) +│ ├── result_bs1.json # 模型的精度输出 +``` + +### 5.1 msame工具概述 +msame模型推理工具,其输入是om模型以及模型所需要的输入bin文件,其输出是模型根据相应输入产生的输出文件。获取工具及使用方法可以参考[msame模型推理工具指南](https://gitee.com/ascend/tools/tree/master/msame) +### 5.2 离线推理 +1. 设置环境变量 +```bash +source /usr/local/Ascend/ascend-toolkit/set_env.sh +``` + +2. 执行离线推理 +运行如下命令进行离线推理: +```bash +./msame --model ./convmixer_1536_20_bs1.om --output ./result/outputs_bs1_om --outfmt TXT --input ./prep_image_bs1 > msame_bs1.txt +``` +模型输出格式是txt,输出保存在"output"参数指定的文件夹中,同时会生成推理的日志文件msame_bs1.txt + +### 5.3 精度和性能比较 +1. 性能数据的获取 +通过给test/parser.py指定推理后的日志文件,可以得到离线推理的性能数据 +```bash +python3.7 test/parse.py --result-file ./msame_bs1.txt --batch-size 1 +``` +其中"result-file"表示性能数据的地址和名称,"batch-size"表示性能测试时模型对应的batch size + +2. 精度数据的计算 +精度计算利用convmixer_eval_acc.py脚本 +``` +python3.7 convmixer_eval_acc.py --folder-davinci-target ./result/outputs_bs1_om/ --annotation-file-path /opt/npu/imageNet/val_label.txt --result-json-path ./result --json-file-name result_bs1.json --batch-size 1 +``` +其中"folder-davinci-target"表示离线推理输出所在的文件夹,"annotation-file-path"表示ImageNet2012验证集标签的地址和名称,"result-json-path"输出精度数据所在的文件夹,"json-file-name"表示输出精度数据所在的文件名,"batch-size"表示精度测试时模型对应的batch size + +3. 精度数据的获取 +通过给test/parser.py指定推理后的日志文件,可以得到离线推理的性能数据 +```bash +python3.7 test/parse.py --result-file ./result/result_bs1.json +``` +| 模型 | 参考精度 | 310P精度 | 性能基准 | 310P性能 | +| :------: | :------: | :------: | :------: | :------: | +| convmixer_1536_20 bs1 | top1:81.37% | top1:81.35% | 44.445fps | 115.790fps | +| convmixer_1536_20 bs4 | top1:81.37% | top1:81.35% |59.353fps | 117.252fps | + +> **说明:** > Top1表示预测结果中概率最大的类别与真实类别一致的概率,其值越大说明分类模型的效果越优 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/requirements.txt index 08359656b02a38373278ac403e76f0d476db04f4..56bff866ae34ba66ea8deec5363769fddd717f7b 100644 --- a/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/requirements.txt @@ -1,2 +1,2 @@ -numpy +numpy Pillow==9.0.1 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/test/parse.py b/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/test/parse.py index 4ee338f7c0f91de6125fe039f104a0fc3b1c0816..b592265b6461d1aa212433dd5cee5df5334d0e62 100644 --- a/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/test/parse.py +++ b/ACL_PyTorch/contrib/cv/classfication/convmixer_1536_20/test/parse.py @@ -1,40 +1,40 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import re -import sys -import json -import argparse - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--result-file', type=str, default="./msame_bs1.txt") - parser.add_argument('--batch-size', type=int, default=1) - args = parser.parse_args() - - if args.result_file.endswith('.json'): - result_json = args.result_file - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{}'.format(result_json.split('_')[1].split('.')[0], tops[0])) - elif args.result_file.endswith('.txt'): - result_txt = args.result_file - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = re.findall(r'Inference average time without first time:.*ms', content.replace('\n', ',') + ',')[-1] - avg_time = txt_data_list.split(' ')[-2] - fps = args.batch_size * 1000 / float(avg_time) - print('310P bs{} fps:{:.3f}'.format(args.batch_size, fps)) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import re +import sys +import json +import argparse + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--result-file', type=str, default="./msame_bs1.txt") + parser.add_argument('--batch-size', type=int, default=1) + args = parser.parse_args() + + if args.result_file.endswith('.json'): + result_json = args.result_file + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{}'.format(result_json.split('_')[1].split('.')[0], tops[0])) + elif args.result_file.endswith('.txt'): + result_txt = args.result_file + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = re.findall(r'Inference average time without first time:.*ms', content.replace('\n', ',') + ',')[-1] + avg_time = txt_data_list.split(' ')[-2] + fps = args.batch_size * 1000 / float(avg_time) + print('310P bs{} fps:{:.3f}'.format(args.batch_size, fps)) diff --git a/ACL_PyTorch/contrib/cv/classfication/pnasnet5large/LICENSE b/ACL_PyTorch/contrib/cv/classfication/pnasnet5large/LICENSE index 753842b6720f7980d411ecf2c78eb4ef220b9df8..f49a4e16e68b128803cc2dcea614603632b04eac 100644 --- a/ACL_PyTorch/contrib/cv/classfication/pnasnet5large/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/pnasnet5large/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/pnasnet5large/get_info.py b/ACL_PyTorch/contrib/cv/classfication/pnasnet5large/get_info.py index 16bebcfc75fa5903434d2fbcee780e2e7ac4bd84..70e007ac5c49dc1ddc85fcbeb33ba54018f56b06 100644 --- a/ACL_PyTorch/contrib/cv/classfication/pnasnet5large/get_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/pnasnet5large/get_info.py @@ -1,62 +1,62 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - print(index,'done') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - print(index,'done') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + print(index,'done') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + print(index,'done') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/pnasnet5large/vision_metric_ImageNet.py b/ACL_PyTorch/contrib/cv/classfication/pnasnet5large/vision_metric_ImageNet.py index 362f2484e8288dd3df6fa212678dc9449dbbed29..583340a19f2fc6e99faed85526c906f8bd12d7ba 100644 --- a/ACL_PyTorch/contrib/cv/classfication/pnasnet5large/vision_metric_ImageNet.py +++ b/ACL_PyTorch/contrib/cv/classfication/pnasnet5large/vision_metric_ImageNet.py @@ -1,184 +1,184 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - imgName = temp[0].split(".")[0] - imgLab = temp[1] - img_gt_dict[imgName] = imgLab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - if data == '': - n_label = 0 - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, prob in enumerate(temp): - data_vec[ind] = np.float32(prob) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - resCnt = 0 - n_labels = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - n_labels = ret[1] - sort_index = np.argsort(-prediction) - gt = img_gt_dict[img_name] - if (n_labels == 1000): - realLabel = int(gt) - elif (n_labels == 1001): - realLabel = int(gt) + 1 - else: - realLabel = int(gt) - - resCnt = min(len(sort_index), topn) - for i in range(resCnt): - if (str(realLabel) == str(sort_index[i])): - count_hit[i] += 1 - break - - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(resCnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - - if not (os.path.exists(annotation_file_path)): - print("Ground truth file does not exist.") - - if not (os.path.exists(result_json_path)): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) - print("Time used:", elapsed) - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + imgName = temp[0].split(".")[0] + imgLab = temp[1] + img_gt_dict[imgName] = imgLab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + if data == '': + n_label = 0 + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, prob in enumerate(temp): + data_vec[ind] = np.float32(prob) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + resCnt = 0 + n_labels = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + n_labels = ret[1] + sort_index = np.argsort(-prediction) + gt = img_gt_dict[img_name] + if (n_labels == 1000): + realLabel = int(gt) + elif (n_labels == 1001): + realLabel = int(gt) + 1 + else: + realLabel = int(gt) + + resCnt = min(len(sort_index), topn) + for i in range(resCnt): + if (str(realLabel) == str(sort_index[i])): + count_hit[i] += 1 + break + + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(resCnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + + if not (os.path.exists(annotation_file_path)): + print("Ground truth file does not exist.") + + if not (os.path.exists(result_json_path)): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) + print("Time used:", elapsed) + diff --git a/ACL_PyTorch/contrib/cv/classfication/vit-small/README.md b/ACL_PyTorch/contrib/cv/classfication/vit-small/README.md index ff71f12feee2abb5a7df40da65300d2d64fb2354..54a20b8c4562f2533af284fa621e7023a7c070ed 100644 --- a/ACL_PyTorch/contrib/cv/classfication/vit-small/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/vit-small/README.md @@ -1,70 +1,70 @@ -# vit-small 模型PyTorch离线推理指导 - -## 1. 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - -~~~shell -pip3.7 install -r requirements.txt -~~~ - -2.获取,修改与安装开源模型代码 - -~~~shell -git clone https://github.com/rwightman/pytorch-image-models.git -b master -cd pytorch-image-models/ -patch -p1 < ../vit_small_patch16_224.patch -cd .. -~~~ - -3.获取权重文件 - -将权重文件放到当前工作目录,可以通过以下命令下载: - -~~~shell -wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/vit-small/S_16-i21k-300ep-lr_0.001-aug_light1-wd_0.03-do_0.0-sd_0.0--imagenet2012-steps_20k-lr_0.03-res_224.npz -~~~ - -4.数据集 - -该模型使用 `ImageNet` 官网的5万张验证集进行测试,可从 [ImageNet官网](http://www.image-net.org/) 获取 `val` 数据集与标签,分别存放在 `/home/datasets/imagenet/val` 与 `/home/datasets/imagenet/val_label.txt` - -最终目录结构应为 - -~~~txt -imagenet/ -|-- val/ -|-- val_label.txt -~~~ - -5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) - -将 `benchmark.x86_64` 或 `benchmark.aarch64` 放到当前工作目录 - -## 2. 离线推理 - -t4上执行,确保卡空闲时执行测试 - -~~~shell -bash perf_g.sh -# 脚本3-11行是对gpu bs1性能测试, 13-21行是对gpu bs16性能测试 -~~~ - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 - -~~~shell -bash ./test/pth2om.sh -# 脚本中2-7行是pth2onnx,9-16行是对onnx进行onnxsim优化, 18-27行是利用onnxsim优化后的onnx转om - -bash ./test/eval_acc_perf.sh --datasets_path=real_data_path -# 如不指定--datasets_path,则采用默认数据集路径:/home/datasets/imagenet/ -# 脚本中12-19行为数据集前处理,同时生成bin文件信息,20-30行是推理过程,32-44行获取精度数据,45-56行获取性能数据 -~~~ - -**评测结果** - -| 模型 | 仓库pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| -------------- | ----------- | --------------- | -------- | -------- | -| vit-small bs1 | top1:81.388 | top1:81.1 | 222.4976 | 200.9196 | -| vit-small bs16 | top1:81.388 | top1:81.1 | 657.9001 | 204.0776 | - +# vit-small 模型PyTorch离线推理指导 + +## 1. 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + +~~~shell +pip3.7 install -r requirements.txt +~~~ + +2.获取,修改与安装开源模型代码 + +~~~shell +git clone https://github.com/rwightman/pytorch-image-models.git -b master +cd pytorch-image-models/ +patch -p1 < ../vit_small_patch16_224.patch +cd .. +~~~ + +3.获取权重文件 + +将权重文件放到当前工作目录,可以通过以下命令下载: + +~~~shell +wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/vit-small/S_16-i21k-300ep-lr_0.001-aug_light1-wd_0.03-do_0.0-sd_0.0--imagenet2012-steps_20k-lr_0.03-res_224.npz +~~~ + +4.数据集 + +该模型使用 `ImageNet` 官网的5万张验证集进行测试,可从 [ImageNet官网](http://www.image-net.org/) 获取 `val` 数据集与标签,分别存放在 `/home/datasets/imagenet/val` 与 `/home/datasets/imagenet/val_label.txt` + +最终目录结构应为 + +~~~txt +imagenet/ +|-- val/ +|-- val_label.txt +~~~ + +5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) + +将 `benchmark.x86_64` 或 `benchmark.aarch64` 放到当前工作目录 + +## 2. 离线推理 + +t4上执行,确保卡空闲时执行测试 + +~~~shell +bash perf_g.sh +# 脚本3-11行是对gpu bs1性能测试, 13-21行是对gpu bs16性能测试 +~~~ + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 + +~~~shell +bash ./test/pth2om.sh +# 脚本中2-7行是pth2onnx,9-16行是对onnx进行onnxsim优化, 18-27行是利用onnxsim优化后的onnx转om + +bash ./test/eval_acc_perf.sh --datasets_path=real_data_path +# 如不指定--datasets_path,则采用默认数据集路径:/home/datasets/imagenet/ +# 脚本中12-19行为数据集前处理,同时生成bin文件信息,20-30行是推理过程,32-44行获取精度数据,45-56行获取性能数据 +~~~ + +**评测结果** + +| 模型 | 仓库pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| -------------- | ----------- | --------------- | -------- | -------- | +| vit-small bs1 | top1:81.388 | top1:81.1 | 222.4976 | 200.9196 | +| vit-small bs16 | top1:81.388 | top1:81.1 | 657.9001 | 204.0776 | + diff --git a/ACL_PyTorch/contrib/cv/classfication/vit-small/env.sh b/ACL_PyTorch/contrib/cv/classfication/vit-small/env.sh old mode 100755 new mode 100644 diff --git a/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/LICENSE b/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/LICENSE index b1fac45f02e2f98395fd96a7e4f4a39e257ac0bc..989e2c59e973a05cfbfe9de678b7f2af777b0713 100644 --- a/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/LICENSE @@ -1,201 +1,201 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/gen_dataset_info.py index 6a69d4d17ff7b9c2f1b7a030b8601a743228f541..3fbb7d84620be98432b0740eaa9c07cdb6d85fe4 100644 --- a/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/gen_dataset_info.py @@ -1,64 +1,64 @@ -""" -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) - +""" +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) + diff --git a/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/modelzoo_level.txt index 32dd0521ece8acac5fffdaf2413f6d17a51b2e3c..7e460da1913cc3d023396644aea19b219b8597a3 100644 --- a/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/modelzoo_level.txt @@ -1,6 +1,6 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:POK -PerfStatus:NOK -ModelConvert:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:POK +PerfStatus:NOK +ModelConvert:OK QuantStatus:POK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/requirements.txt index 2200a3704d12785f84b570c5187a14334602120f..c7e8af10a50c05b4312266b0162a55407bd10fa8 100644 --- a/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/requirements.txt @@ -1,5 +1,5 @@ -onnx -torch=1.5.0 -torchvision>=0.5.0 -pyyaml +onnx +torch=1.5.0 +torchvision>=0.5.0 +pyyaml timm \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/vit_base_patch32_224_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/vit_base_patch32_224_preprocess.py index 390c38b4f67ed64231315210907322d3696d7da4..7afcd7bef332827eff13c78a5d1a22534743bdee 100644 --- a/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/vit_base_patch32_224_preprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/vit_base_patch32_224_preprocess.py @@ -1,53 +1,53 @@ -""" -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - - -import os -from PIL import Image -import numpy as np -import timm -from timm.data import resolve_data_config -from timm.data.transforms_factory import create_transform -import argparse - - -parser = argparse.ArgumentParser(description='Path', add_help=False) -parser.add_argument('--data-path', metavar='DIR', - help='path to dataset') -parser.add_argument('--store-path', metavar='DIR', - help='path to store') - - -def preprocess(src_path, save_path): - os.mkdir(save_path) - model = timm.create_model('vit_base_patch32_224') - model.eval() - config = resolve_data_config({},model=model) - transform = create_transform(**config) - i = 0 - in_files = os.listdir(src_path) - for file in in_files: - i = i + 1 - print(file, "===", i) - input_image = Image.open(src_path+'/'+file).convert('RGB') - input_tensor = transform(input_image) - img = np.array(input_tensor).astype(np.float32) - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - - -if __name__ == "__main__": - args = parser.parse_args() +""" +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + + +import os +from PIL import Image +import numpy as np +import timm +from timm.data import resolve_data_config +from timm.data.transforms_factory import create_transform +import argparse + + +parser = argparse.ArgumentParser(description='Path', add_help=False) +parser.add_argument('--data-path', metavar='DIR', + help='path to dataset') +parser.add_argument('--store-path', metavar='DIR', + help='path to store') + + +def preprocess(src_path, save_path): + os.mkdir(save_path) + model = timm.create_model('vit_base_patch32_224') + model.eval() + config = resolve_data_config({},model=model) + transform = create_transform(**config) + i = 0 + in_files = os.listdir(src_path) + for file in in_files: + i = i + 1 + print(file, "===", i) + input_image = Image.open(src_path+'/'+file).convert('RGB') + input_tensor = transform(input_image) + img = np.array(input_tensor).astype(np.float32) + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +if __name__ == "__main__": + args = parser.parse_args() preprocess(args.data_path,args.store_path) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/vit_base_patch32_224_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/vit_base_patch32_224_pth2onnx.py index d64775b88a01b169f2b6d3c18075e74552f01a10..a52537b0c1b41a4bcd99542d5be8fa8dee3bbd39 100644 --- a/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/vit_base_patch32_224_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224/vit_base_patch32_224_pth2onnx.py @@ -1,41 +1,41 @@ -""" -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - - -import torch -import timm -import argparse - - -parser = argparse.ArgumentParser(description='Path', add_help=False) -parser.add_argument('--model-path', default="B_32-i21k-300ep-lr_0.001-aug_medium1-wd_0.03-do_0.0-sd_0.0--imagenet2012-steps_20k-lr_0.03-res_224.npz", metavar='DIR', - help='path to model') -parser.add_argument('--batch-size',default="1", type=int, - help='batch size') - - -def main(): - args = parser.parse_args() - model = timm.create_model('vit_base_patch32_224') - model.load_pretrained(args.model_path) - model.eval() - tensor = torch.zeros(args.batch_size,3,224,224) - torch.onnx.export(model, tensor, "vit_bs"+str(args.batch_size)+".onnx", opset_version=11, - do_constant_folding=True, input_names=["input"], output_names=["output"]) - - -if __name__ == "__main__": +""" +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + + +import torch +import timm +import argparse + + +parser = argparse.ArgumentParser(description='Path', add_help=False) +parser.add_argument('--model-path', default="B_32-i21k-300ep-lr_0.001-aug_medium1-wd_0.03-do_0.0-sd_0.0--imagenet2012-steps_20k-lr_0.03-res_224.npz", metavar='DIR', + help='path to model') +parser.add_argument('--batch-size',default="1", type=int, + help='batch size') + + +def main(): + args = parser.parse_args() + model = timm.create_model('vit_base_patch32_224') + model.load_pretrained(args.model_path) + model.eval() + tensor = torch.zeros(args.batch_size,3,224,224) + torch.onnx.export(model, tensor, "vit_bs"+str(args.batch_size)+".onnx", opset_version=11, + do_constant_folding=True, input_names=["input"], output_names=["output"]) + + +if __name__ == "__main__": main() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/volo/env.sh b/ACL_PyTorch/contrib/cv/classfication/volo/env.sh old mode 100755 new mode 100644 diff --git a/ACL_PyTorch/contrib/cv/classfication/volo/modify.py b/ACL_PyTorch/contrib/cv/classfication/volo/modify.py index 9cbe1452943bd50a85dd8660380bc54312c3bd4c..a5485aedf17a622a3a305033410e098d91e0fefb 100644 --- a/ACL_PyTorch/contrib/cv/classfication/volo/modify.py +++ b/ACL_PyTorch/contrib/cv/classfication/volo/modify.py @@ -1,29 +1,29 @@ -import numpy as np -from MagicONNX.magiconnx import OnnxGraph -import argparse - -INT32_MAX = 2147483647 -INT32_MIN = -2147483648 - -def modify(path, output): - graph = OnnxGraph(path) - col2ims = graph.get_nodes("Col2im") - for idx, node in enumerate(col2ims): - attr = node['output_size'] - node.attrs.pop("output_size") - new_init = graph.add_initializer(f'output_size_{node.name}', np.array(attr).astype(np.int32)) - node.inputs = [node.inputs[0], f'output_size_{node.name}'] - - graph.save(output) - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='modify the onnx node') - parser.add_argument('--src', type=str, default='./d1_224_84.2.pth.tar', - help='weights of pytorch dir') - parser.add_argument('--des', type=str, default='./volo_d1_224_Col2im.onnx', - help='weights of onnx dir') - args = parser.parse_args() - modify(args.src, args.des) - print("modify the onnx successfully!") - - +import numpy as np +from MagicONNX.magiconnx import OnnxGraph +import argparse + +INT32_MAX = 2147483647 +INT32_MIN = -2147483648 + +def modify(path, output): + graph = OnnxGraph(path) + col2ims = graph.get_nodes("Col2im") + for idx, node in enumerate(col2ims): + attr = node['output_size'] + node.attrs.pop("output_size") + new_init = graph.add_initializer(f'output_size_{node.name}', np.array(attr).astype(np.int32)) + node.inputs = [node.inputs[0], f'output_size_{node.name}'] + + graph.save(output) + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='modify the onnx node') + parser.add_argument('--src', type=str, default='./d1_224_84.2.pth.tar', + help='weights of pytorch dir') + parser.add_argument('--des', type=str, default='./volo_d1_224_Col2im.onnx', + help='weights of onnx dir') + args = parser.parse_args() + modify(args.src, args.des) + print("modify the onnx successfully!") + + diff --git a/ACL_PyTorch/contrib/cv/classfication/volo/readme.md b/ACL_PyTorch/contrib/cv/classfication/volo/readme.md index f553e3bee1566ed089f6c4ebab60b357122c7dc9..3e440378b387f478eaa367ac7483b5c76a5906a8 100644 --- a/ACL_PyTorch/contrib/cv/classfication/volo/readme.md +++ b/ACL_PyTorch/contrib/cv/classfication/volo/readme.md @@ -1,80 +1,80 @@ -# VOLO - -This implements training of volo_d1 on the ImageNet-2012 dataset and token labeling, mainly modified from [sail-sg/volo](https://github.com/sail-sg/volo). - -## VOLO Detail - -There is an error of Col2im operator on pth2onnx, define the OP in volo.py. -- The check of onnx should be commented out. -Example: -File "python3.8/site-packages/torch/onnx/utils.py", line 785, in _export -```bash -#if (operator_export_type is OperatorExportTypes.ONNX) and (not val_use_external_data_format): - #try: - #_check_onnx_proto(proto) - #except RuntimeError as e: - #raise CheckerError(e) -``` -## Requirements - -- Prepare the checkpoint of pytorch -- `pip install -r requirements.txt` -- Download the Imagenet-2012 dataset. Refer to the original repository https://github.com/rwightman/pytorch-image-models -- install MagicONNX - ```bash - git clone https://gitee.com/Ronnie_zheng/MagicONNX.git - cd MagicONNX - pip install . - ``` -- compile msame - reference from https://gitee.com/ascend/tools/tree/master/msame -```bash - git clone https://gitee.com/ascend/tools.git - #如下为设置环境变量的示例,请将/home/HwHiAiUser/Ascend/ascend-toolkit/latest替换为Ascend 的ACLlib安装包的实际安装路径。 - export DDK_PATH=/home/HwHiAiUser/Ascend/ascend-toolkit/latest - export NPU_HOST_LIB=/home/HwHiAiUser/Ascend/ascend-toolkit/latest/acllib/lib64/stub - - cd $HOME/AscendProjects/tools/msame/ - ./build.sh g++ $HOME/AscendProjects/tools/msame/out -``` - -## preprocess the dataset - -Because we use msame to inference, so we should preprocess origin dataset to `.bin` file. -And different batchsize should be different binary file. The command is below: - -```bash -python volo_preprocess.py --src /opt/npu/val --des /opt/npu/data_bs1 --batchsize 1 -python volo_preprocess.py --src /opt/npu/val --des /opt/npu/data_bs16 --batchsize 16 -``` -Then we get the binary dataset in `/opt/npu/data_bs1` or `/opt/npu/data_bs16` and also the label txt.The file named `volo_val_bs1.txt` or `volo_val_bs16.txt` - -## Inference -```bash -# pth2om for batchsize 1 -bash test/pth2om.sh d1_224_84.pth.tar volo_bs1.onnx volo_modify_bs1.onnx volo_bs1 1 "input:1,3,224,224" -# pth2om for batchsize 16 -bash test/pth2om.sh d1_224_84.pth.tar volo_bs16.onnx volo_modify_bs16.onnx volo_bs16 16 "input:16,3,224,224" - -# inference with batchsize 1 with performance -./msame --model "volo_bs1.om" --input "/opt/npu/data_bs1" --output "./" --outfmt TXT - -# inference with batchsize 16 with performance -./msame --model "volo_bs16.om" --input "/opt/npu/data_bs16" --output "./" --outfmt TXT - -# compute the val accuracy, modify the batchsize, result dir and label dir -bash eval_acc_perf.sh 1 /path/to/result /path/to/label.txt -``` - -## Volo inference result -| accuracy | top1 | -| :------: | :--------: | -| bs1 | 80.619 | -| bs16 | 82.275 | - -|batchsize| performance | average time | average time without first | -| :-----: | :---------: | :-----------: | :-------------------------: | -| bs1 | 10.08fps | 396.46ms | 396.46ms | -| bs16 | 17.6fps | 3635.25ms | 3635.25ms | - - +# VOLO + +This implements training of volo_d1 on the ImageNet-2012 dataset and token labeling, mainly modified from [sail-sg/volo](https://github.com/sail-sg/volo). + +## VOLO Detail + +There is an error of Col2im operator on pth2onnx, define the OP in volo.py. +- The check of onnx should be commented out. +Example: +File "python3.8/site-packages/torch/onnx/utils.py", line 785, in _export +```bash +#if (operator_export_type is OperatorExportTypes.ONNX) and (not val_use_external_data_format): + #try: + #_check_onnx_proto(proto) + #except RuntimeError as e: + #raise CheckerError(e) +``` +## Requirements + +- Prepare the checkpoint of pytorch +- `pip install -r requirements.txt` +- Download the Imagenet-2012 dataset. Refer to the original repository https://github.com/rwightman/pytorch-image-models +- install MagicONNX + ```bash + git clone https://gitee.com/Ronnie_zheng/MagicONNX.git + cd MagicONNX + pip install . + ``` +- compile msame + reference from https://gitee.com/ascend/tools/tree/master/msame +```bash + git clone https://gitee.com/ascend/tools.git + #如下为设置环境变量的示例,请将/home/HwHiAiUser/Ascend/ascend-toolkit/latest替换为Ascend 的ACLlib安装包的实际安装路径。 + export DDK_PATH=/home/HwHiAiUser/Ascend/ascend-toolkit/latest + export NPU_HOST_LIB=/home/HwHiAiUser/Ascend/ascend-toolkit/latest/acllib/lib64/stub + + cd $HOME/AscendProjects/tools/msame/ + ./build.sh g++ $HOME/AscendProjects/tools/msame/out +``` + +## preprocess the dataset + +Because we use msame to inference, so we should preprocess origin dataset to `.bin` file. +And different batchsize should be different binary file. The command is below: + +```bash +python volo_preprocess.py --src /opt/npu/val --des /opt/npu/data_bs1 --batchsize 1 +python volo_preprocess.py --src /opt/npu/val --des /opt/npu/data_bs16 --batchsize 16 +``` +Then we get the binary dataset in `/opt/npu/data_bs1` or `/opt/npu/data_bs16` and also the label txt.The file named `volo_val_bs1.txt` or `volo_val_bs16.txt` + +## Inference +```bash +# pth2om for batchsize 1 +bash test/pth2om.sh d1_224_84.pth.tar volo_bs1.onnx volo_modify_bs1.onnx volo_bs1 1 "input:1,3,224,224" +# pth2om for batchsize 16 +bash test/pth2om.sh d1_224_84.pth.tar volo_bs16.onnx volo_modify_bs16.onnx volo_bs16 16 "input:16,3,224,224" + +# inference with batchsize 1 with performance +./msame --model "volo_bs1.om" --input "/opt/npu/data_bs1" --output "./" --outfmt TXT + +# inference with batchsize 16 with performance +./msame --model "volo_bs16.om" --input "/opt/npu/data_bs16" --output "./" --outfmt TXT + +# compute the val accuracy, modify the batchsize, result dir and label dir +bash eval_acc_perf.sh 1 /path/to/result /path/to/label.txt +``` + +## Volo inference result +| accuracy | top1 | +| :------: | :--------: | +| bs1 | 80.619 | +| bs16 | 82.275 | + +|batchsize| performance | average time | average time without first | +| :-----: | :---------: | :-----------: | :-------------------------: | +| bs1 | 10.08fps | 396.46ms | 396.46ms | +| bs16 | 17.6fps | 3635.25ms | 3635.25ms | + + diff --git a/ACL_PyTorch/contrib/cv/classfication/volo/volo.py b/ACL_PyTorch/contrib/cv/classfication/volo/volo.py old mode 100755 new mode 100644 diff --git a/ACL_PyTorch/contrib/cv/classfication/volo/volo_postprocess.py b/ACL_PyTorch/contrib/cv/classfication/volo/volo_postprocess.py old mode 100755 new mode 100644 index 1eae6503ed93c2409c7282edbae319ac33616c10..39509905fffd4b5388199d249ba74f89178de909 --- a/ACL_PyTorch/contrib/cv/classfication/volo/volo_postprocess.py +++ b/ACL_PyTorch/contrib/cv/classfication/volo/volo_postprocess.py @@ -1,83 +1,83 @@ -import os -import numpy as np -import argparse - -def read_txt_data(path): - line = "" - with open(path, 'r') as f: - line = f.read() - if line != "": - return np.array([float(s) for s in line.split(" ") if s != "" and s != "\n"]) - return None - -def read_label(path, bs): - with open(path, 'r') as f: - content = f.read() - lines = [line for line in content.split('\n')] - if lines[-1] == "": - lines = lines[:-1] - if bs == 1: - labels = [int(line.split(' ')[-2]) for line in lines] - labels = np.array(labels) - labels = np.expand_dims(labels, 1) - return labels - else: - total_label = np.zeros((len(files) * bs)) - base = 0 - for line in lines: - labels = line.split(' ')[1:-1] - labels = [int(label) for label in labels] - for i in range(len(labels)): - total_label[base * bs + i] = labels[i] - base = base + 1 - total_label = np.expand_dims(total_label, 1) - return total_label - -def get_topK(files, topk, bs): - if bs == 1: - matrix = np.zeros((len(files), topk)) - else: - matrix = np.zeros((len(files) * bs, topk)) - for file in files: - data = read_txt_data(root + file) - if bs == 1: - line = np.argsort(data)[-topk:][::-1] - index = int(file.split('_')[1]) - matrix[index-1, :] = line[:topk] - else: - base_index = int(file.split('_')[1]) - newdata = data.reshape(bs, 1000) - for i in range(bs): - line = np.argsort(newdata[i,:])[-topk:][::-1] - matrix[base_index * bs + i, :] = line[:topk] - return matrix.astype(np.int64) - -def get_topK_acc(matrix, labels, k): - matrix_tmp = matrix[:, :k] - match_array = np.logical_or.reduce(matrix_tmp==labels, axis=1) - topk_acc = match_array.sum() / match_array.shape[0] - return topk_acc - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='VOLO validation') - parser.add_argument('--batchsize', type=int, default='1', - help='batchsize.') - parser.add_argument('--result', type=str, default='./', - help='output dir of msame') - parser.add_argument('--label', type=str, default='./volo_val_bs1.txt', - help='label txt dir') - args = parser.parse_args() - root = args.result - bs = args.batchsize - label_dir = args.label - files = None - if os.path.exists(root): - files=os.listdir(root) - else: - print('this path not exist') - exit(0) - matrix = get_topK(files, 6, bs) - labels = read_label(label_dir, bs) - for i in range(1, 6): - acc = get_topK_acc(matrix, labels, i) - print("acc@top{}: {:.3f}%".format(i, 100*acc)) +import os +import numpy as np +import argparse + +def read_txt_data(path): + line = "" + with open(path, 'r') as f: + line = f.read() + if line != "": + return np.array([float(s) for s in line.split(" ") if s != "" and s != "\n"]) + return None + +def read_label(path, bs): + with open(path, 'r') as f: + content = f.read() + lines = [line for line in content.split('\n')] + if lines[-1] == "": + lines = lines[:-1] + if bs == 1: + labels = [int(line.split(' ')[-2]) for line in lines] + labels = np.array(labels) + labels = np.expand_dims(labels, 1) + return labels + else: + total_label = np.zeros((len(files) * bs)) + base = 0 + for line in lines: + labels = line.split(' ')[1:-1] + labels = [int(label) for label in labels] + for i in range(len(labels)): + total_label[base * bs + i] = labels[i] + base = base + 1 + total_label = np.expand_dims(total_label, 1) + return total_label + +def get_topK(files, topk, bs): + if bs == 1: + matrix = np.zeros((len(files), topk)) + else: + matrix = np.zeros((len(files) * bs, topk)) + for file in files: + data = read_txt_data(root + file) + if bs == 1: + line = np.argsort(data)[-topk:][::-1] + index = int(file.split('_')[1]) + matrix[index-1, :] = line[:topk] + else: + base_index = int(file.split('_')[1]) + newdata = data.reshape(bs, 1000) + for i in range(bs): + line = np.argsort(newdata[i,:])[-topk:][::-1] + matrix[base_index * bs + i, :] = line[:topk] + return matrix.astype(np.int64) + +def get_topK_acc(matrix, labels, k): + matrix_tmp = matrix[:, :k] + match_array = np.logical_or.reduce(matrix_tmp==labels, axis=1) + topk_acc = match_array.sum() / match_array.shape[0] + return topk_acc + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='VOLO validation') + parser.add_argument('--batchsize', type=int, default='1', + help='batchsize.') + parser.add_argument('--result', type=str, default='./', + help='output dir of msame') + parser.add_argument('--label', type=str, default='./volo_val_bs1.txt', + help='label txt dir') + args = parser.parse_args() + root = args.result + bs = args.batchsize + label_dir = args.label + files = None + if os.path.exists(root): + files=os.listdir(root) + else: + print('this path not exist') + exit(0) + matrix = get_topK(files, 6, bs) + labels = read_label(label_dir, bs) + for i in range(1, 6): + acc = get_topK_acc(matrix, labels, i) + print("acc@top{}: {:.3f}%".format(i, 100*acc)) diff --git a/ACL_PyTorch/contrib/cv/classfication/volo/volo_preprocess.py b/ACL_PyTorch/contrib/cv/classfication/volo/volo_preprocess.py old mode 100755 new mode 100644 diff --git a/ACL_PyTorch/contrib/cv/classfication/volo/volo_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/volo/volo_pth2onnx.py old mode 100755 new mode 100644 diff --git a/ACL_PyTorch/contrib/cv/classfication/vovnet39/LICENSE b/ACL_PyTorch/contrib/cv/classfication/vovnet39/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/classfication/vovnet39/LICENSE +++ b/ACL_PyTorch/contrib/cv/classfication/vovnet39/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/vovnet39/README.md b/ACL_PyTorch/contrib/cv/classfication/vovnet39/README.md index 5211e9cebaba06c706dc5e35c79b701097bab276..ed1c41a8080623c253bec528068be62593ef9417 100644 --- a/ACL_PyTorch/contrib/cv/classfication/vovnet39/README.md +++ b/ACL_PyTorch/contrib/cv/classfication/vovnet39/README.md @@ -1,255 +1,255 @@ -vovnet39 Onnx模型端到端推理指导 - -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) - - [6.2 开源TopN精度](#62-开源TopN精度) - - [6.3 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[vovnet39论文](https://arxiv.org/abs/1904.09730) - -### 1.2 代码地址 -[vovnet39代码](https://github.com/AlexanderBurkhart/cnn_train/tree/505637bcd08021e144c94e81401af6bc71fd46c6/VoVNet.pytorch/models_vovnet) -branch:master -commit_id:505637bcd08021e144c94e81401af6bc71fd46c6 - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 -``` -CANN 5.0.1 -pytorch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.7.0 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.18.5 -Pillow == 7.2.0 -opencv-python == 4.5.1.48 -``` - -**说明:** -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 - -1.下载pth权重文件 -[vovnet39预训练pth权重文件](https://www.dropbox.com/s/1lnzsgnixd8gjra/vovnet39_torchvision.pth) -文件md5sum: 23717a6cadd9729a704f894381444237 - -``` -http://www.dropbox.com/s/1lnzsgnixd8gjra/vovnet39_torchvision.pth -``` -2.vovnet39模型代码在代码仓里 - -``` -github上vovnet39没有安装脚本,在pth2onnx脚本中引用代码仓定义的vovnet39: - -git clone https://github.com/AlexanderBurkhart/cnn_train.git -``` - -3.编写pth2onnx脚本vovnet39_pth2onnx.py - - **说明:** ->注意目前ATC支持的onnx算子版本为11 - -4.执行pth2onnx脚本,生成onnx模型文件 -``` -python3.7 vovnet39_pth2onnx.py vovnet39_torchvision.pth vovnet39.onnx -``` - **模型转换要点:** ->此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 -### 3.2 onnx转om模型 - -1.设置环境变量 -``` -source env.sh -``` -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 -``` -atc --framework=5 --model=./vovnet39.onnx --input_format=NCHW --input_shape="image:1,3,224,224" --output=vovnet39_bs1 --log=debug --soc_version=Ascend310 -``` - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/opt/npu/imagenet/val与/root/datasets/imagenet/val_label.txt。 - -### 4.2 数据集预处理 -1.预处理脚本vovnet_torch_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 -``` -python3.7 vovnet_torch_preprocess.py /opt/npu/imagenet/val ./prep_dataset -``` -### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本get_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 - -``` -python3.7 get_info.py bin ./prep_dataset ./vovnet_prep_bin.info 224 224 -``` -第一个参数为生成的数据集文件格式,第二个为预处理后的数据文件路径,第三个参数为生成的数据集文件保存的路径,第四个和第五个参数分别为模型输入的宽度和高度 -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.1 推理benchmark工具用户指南 01 -### 5.2 离线推理 -1.设置环境变量 -``` -source env.sh -``` -2.执行离线推理 - -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=vovnet39_bs1.om -input_text_path=./vovnet_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False -``` -输出结果默认保存在当前目录result/dumpOutput_devicex,模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 - -## 6 精度对比 - -- **[离线推理TopN精度](#61-离线推理TopN精度)** -- **[开源TopN精度](#62-开源TopN精度)** -- **[精度对比](#63-精度对比)** - -### 6.1 离线推理TopN精度统计 - -后处理统计TopN精度 - -调用vision_metric_ImageNet.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 -``` -python3.7 vision_metric_ImageNet.py result/dumpOutput_device0/ /opt/npu/imagenet/val_label.txt ./ result.json -``` -第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 -查看输出结果: -``` -{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value -": "76.78%"}, {"key": "Top2 accuracy", "value": "86.6%"}, {"key": "Top3 accuracy", "value": "90.23%"}, {"key": "Top4 accuracy", "value": "92.22%"}, {"key": "Top5 accuracy", "value": "93.43%"}]} -``` -经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 - -### 6.2 开源TopN精度 -[开源代码仓精度](https://github.com/AlexanderBurkhart/cnn_train/tree/505637bcd08021e144c94e81401af6bc71fd46c6/VoVNet.pytorch) - -``` -Model Acc@1 Acc@5 -vovnet39 76.77 93.43 -``` -### 6.3 精度对比 -将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 - **精度调试:** ->没有遇到精度不达标的问题,故不需要进行精度调试 - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** - -### 7.1 npu性能数据 -benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device。为快速获取性能数据,也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准。这里给出两种方式,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 -1.benchmark工具在整个数据集上推理获得性能数据 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: -``` -[e2e] throughputRate: 190.286, latency: 262762 -[data read] throughputRate: 201.42, moduleLatency: 4.96474 -[preprocess] throughputRate: 201.059, moduleLatency: 4.97367 -[infer] throughputRate: 190.829, Interface throughputRate: 281.608, moduleLatency: 4.54289 -[post] throughputRate: 190.829, moduleLatency: 5.2403 -``` -Interface throughputRate: 281.608,281.608x4=1126.432既是batch1 310单卡吞吐率 -batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: - -``` -[e2e] throughputRate: 132.399, latency: 377646 -[data read] throughputRate: 132.922, moduleLatency: 7.5232 -[preprocess] throughputRate: 132.751, moduleLatency: 7.53292 -[infer] throughputRate: 132.746, Interface throughputRate: 382.566, moduleLatency: 4.0689 -[post] throughputRate: 8.2965, moduleLatency: 120.533 -``` -Interface throughputRate: 382.566,382.566x4=1530.264既是batch16 310单卡吞吐率 -batch4性能: - -``` -[e2e] throughputRate: 194.167, latency: 257510 -[data read] throughputRate: 206.005, moduleLatency: 4.85426 -[preprocess] throughputRate: 205.807, moduleLatency: 4.85891 -[infer] throughputRate: 194.685, Interface throughputRate: 354.792, moduleLatency: 4.2876 -[post] throughputRate: 48.6709, moduleLatency: 20.5462 -``` -batch4 310单卡吞吐率:354.792x4=1419.168fps -batch8性能: - -``` -[e2e] throughputRate: 143.83, latency: 347633 -[data read] throughputRate: 144.354, moduleLatency: 6.92743 -[preprocess] throughputRate: 144.186, moduleLatency: 6.93549 -[infer] throughputRate: 144.246, Interface throughputRate: 364.129, moduleLatency: 4.20264 -[post] throughputRate: 18.0306, moduleLatency: 55.4613 -``` -batch8 310单卡吞吐率:364.129x4=1456.516fps -batch32性能: - -``` -[e2e] throughputRate: 122.051, latency: 409664 -[data read] throughputRate: 122.581, moduleLatency: 8.15788 -[preprocess] throughputRate: 122.445, moduleLatency: 8.16691 -[infer] throughputRate: 122.448, Interface throughputRate: 382.396, moduleLatency: 4.07549 -[post] throughputRate: 3.82767, moduleLatency: 261.256 -``` -batch32 310单卡吞吐率:382.396x4=1529.584fps - - **性能优化:** - +vovnet39 Onnx模型端到端推理指导 + +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) + - [6.2 开源TopN精度](#62-开源TopN精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[vovnet39论文](https://arxiv.org/abs/1904.09730) + +### 1.2 代码地址 +[vovnet39代码](https://github.com/AlexanderBurkhart/cnn_train/tree/505637bcd08021e144c94e81401af6bc71fd46c6/VoVNet.pytorch/models_vovnet) +branch:master +commit_id:505637bcd08021e144c94e81401af6bc71fd46c6 + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +CANN 5.0.1 +pytorch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.7.0 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.18.5 +Pillow == 7.2.0 +opencv-python == 4.5.1.48 +``` + +**说明:** +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 + +1.下载pth权重文件 +[vovnet39预训练pth权重文件](https://www.dropbox.com/s/1lnzsgnixd8gjra/vovnet39_torchvision.pth) +文件md5sum: 23717a6cadd9729a704f894381444237 + +``` +http://www.dropbox.com/s/1lnzsgnixd8gjra/vovnet39_torchvision.pth +``` +2.vovnet39模型代码在代码仓里 + +``` +github上vovnet39没有安装脚本,在pth2onnx脚本中引用代码仓定义的vovnet39: + +git clone https://github.com/AlexanderBurkhart/cnn_train.git +``` + +3.编写pth2onnx脚本vovnet39_pth2onnx.py + + **说明:** +>注意目前ATC支持的onnx算子版本为11 + +4.执行pth2onnx脚本,生成onnx模型文件 +``` +python3.7 vovnet39_pth2onnx.py vovnet39_torchvision.pth vovnet39.onnx +``` + **模型转换要点:** +>此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 +### 3.2 onnx转om模型 + +1.设置环境变量 +``` +source env.sh +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 +``` +atc --framework=5 --model=./vovnet39.onnx --input_format=NCHW --input_shape="image:1,3,224,224" --output=vovnet39_bs1 --log=debug --soc_version=Ascend310 +``` + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用[ImageNet官网](http://www.image-net.org)的5万张验证集进行测试,图片与标签分别存放在/opt/npu/imagenet/val与/root/datasets/imagenet/val_label.txt。 + +### 4.2 数据集预处理 +1.预处理脚本vovnet_torch_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 +``` +python3.7 vovnet_torch_preprocess.py /opt/npu/imagenet/val ./prep_dataset +``` +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本get_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 + +``` +python3.7 get_info.py bin ./prep_dataset ./vovnet_prep_bin.info 224 224 +``` +第一个参数为生成的数据集文件格式,第二个为预处理后的数据文件路径,第三个参数为生成的数据集文件保存的路径,第四个和第五个参数分别为模型输入的宽度和高度 +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.1 推理benchmark工具用户指南 01 +### 5.2 离线推理 +1.设置环境变量 +``` +source env.sh +``` +2.执行离线推理 + +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=vovnet39_bs1.om -input_text_path=./vovnet_prep_bin.info -input_width=224 -input_height=224 -output_binary=False -useDvpp=False +``` +输出结果默认保存在当前目录result/dumpOutput_devicex,模型只有一个名为class的输出,shape为bs * 1000,数据类型为FP32,对应1000个分类的预测结果,每个输入对应的输出对应一个_x.bin文件。 + +## 6 精度对比 + +- **[离线推理TopN精度](#61-离线推理TopN精度)** +- **[开源TopN精度](#62-开源TopN精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理TopN精度统计 + +后处理统计TopN精度 + +调用vision_metric_ImageNet.py脚本推理结果与label比对,可以获得Accuracy Top5数据,结果保存在result.json中。 +``` +python3.7 vision_metric_ImageNet.py result/dumpOutput_device0/ /opt/npu/imagenet/val_label.txt ./ result.json +``` +第一个为benchmark输出目录,第二个为数据集配套标签,第三个是生成文件的保存目录,第四个是生成的文件名。 +查看输出结果: +``` +{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "50000"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value +": "76.78%"}, {"key": "Top2 accuracy", "value": "86.6%"}, {"key": "Top3 accuracy", "value": "90.23%"}, {"key": "Top4 accuracy", "value": "92.22%"}, {"key": "Top5 accuracy", "value": "93.43%"}]} +``` +经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 + +### 6.2 开源TopN精度 +[开源代码仓精度](https://github.com/AlexanderBurkhart/cnn_train/tree/505637bcd08021e144c94e81401af6bc71fd46c6/VoVNet.pytorch) + +``` +Model Acc@1 Acc@5 +vovnet39 76.77 93.43 +``` +### 6.3 精度对比 +将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + **精度调试:** +>没有遇到精度不达标的问题,故不需要进行精度调试 + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** + +### 7.1 npu性能数据 +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device。为快速获取性能数据,也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准。这里给出两种方式,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 +1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: +``` +[e2e] throughputRate: 190.286, latency: 262762 +[data read] throughputRate: 201.42, moduleLatency: 4.96474 +[preprocess] throughputRate: 201.059, moduleLatency: 4.97367 +[infer] throughputRate: 190.829, Interface throughputRate: 281.608, moduleLatency: 4.54289 +[post] throughputRate: 190.829, moduleLatency: 5.2403 +``` +Interface throughputRate: 281.608,281.608x4=1126.432既是batch1 310单卡吞吐率 +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: + +``` +[e2e] throughputRate: 132.399, latency: 377646 +[data read] throughputRate: 132.922, moduleLatency: 7.5232 +[preprocess] throughputRate: 132.751, moduleLatency: 7.53292 +[infer] throughputRate: 132.746, Interface throughputRate: 382.566, moduleLatency: 4.0689 +[post] throughputRate: 8.2965, moduleLatency: 120.533 +``` +Interface throughputRate: 382.566,382.566x4=1530.264既是batch16 310单卡吞吐率 +batch4性能: + +``` +[e2e] throughputRate: 194.167, latency: 257510 +[data read] throughputRate: 206.005, moduleLatency: 4.85426 +[preprocess] throughputRate: 205.807, moduleLatency: 4.85891 +[infer] throughputRate: 194.685, Interface throughputRate: 354.792, moduleLatency: 4.2876 +[post] throughputRate: 48.6709, moduleLatency: 20.5462 +``` +batch4 310单卡吞吐率:354.792x4=1419.168fps +batch8性能: + +``` +[e2e] throughputRate: 143.83, latency: 347633 +[data read] throughputRate: 144.354, moduleLatency: 6.92743 +[preprocess] throughputRate: 144.186, moduleLatency: 6.93549 +[infer] throughputRate: 144.246, Interface throughputRate: 364.129, moduleLatency: 4.20264 +[post] throughputRate: 18.0306, moduleLatency: 55.4613 +``` +batch8 310单卡吞吐率:364.129x4=1456.516fps +batch32性能: + +``` +[e2e] throughputRate: 122.051, latency: 409664 +[data read] throughputRate: 122.581, moduleLatency: 8.15788 +[preprocess] throughputRate: 122.445, moduleLatency: 8.16691 +[infer] throughputRate: 122.448, Interface throughputRate: 382.396, moduleLatency: 4.07549 +[post] throughputRate: 3.82767, moduleLatency: 261.256 +``` +batch32 310单卡吞吐率:382.396x4=1529.584fps + + **性能优化:** + >没有遇到性能不达标的问题,故不需要进行性能优化 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/vovnet39/requirements.txt b/ACL_PyTorch/contrib/cv/classfication/vovnet39/requirements.txt index 19bf0c33da4a5c3990a53fb79d681b2804a6df47..59f8a711bf24972d8af91f0ba668c3fc5d91a1bb 100644 --- a/ACL_PyTorch/contrib/cv/classfication/vovnet39/requirements.txt +++ b/ACL_PyTorch/contrib/cv/classfication/vovnet39/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.7.0 -numpy == 1.18.5 -Pillow == 7.2.0 +torch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.7.0 +numpy == 1.18.5 +Pillow == 7.2.0 opencv-python == 4.5.1.48 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/classfication/vovnet39/test/readme.md b/ACL_PyTorch/contrib/cv/classfication/vovnet39/test/readme.md index bb87e712e838ab85d566959c9ebcf9c615a2009f..9237a2ae4b6f047fde9be01913d14b2242df470e 100644 --- a/ACL_PyTorch/contrib/cv/classfication/vovnet39/test/readme.md +++ b/ACL_PyTorch/contrib/cv/classfication/vovnet39/test/readme.md @@ -1,24 +1,24 @@ -环境准备: - -1.数据集路径 -通用的数据集统一放在/root/datasets/或/opt/npu/ -本模型数据集放在/opt/npu/ - -2.进入工作目录 -cd vovnet39 - -3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -pip3.7 install -r requirements.txt - -4.获取模型代码 -git clone https://github.com/AlexanderBurkhart/cnn_train.git - -6.获取权重文件 -wget http://www.dropbox.com/s/1lnzsgnixd8gjra/vovnet39_torchvision.pth - -7.获取benchmark工具 -将benchmark.x86_64 benchmark.aarch64放在当前目录 - -8.310上执行,执行时确保device空闲 -bash test/pth2om.sh -bash test/eval_acc_perf.sh +环境准备: + +1.数据集路径 +通用的数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集放在/opt/npu/ + +2.进入工作目录 +cd vovnet39 + +3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +pip3.7 install -r requirements.txt + +4.获取模型代码 +git clone https://github.com/AlexanderBurkhart/cnn_train.git + +6.获取权重文件 +wget http://www.dropbox.com/s/1lnzsgnixd8gjra/vovnet39_torchvision.pth + +7.获取benchmark工具 +将benchmark.x86_64 benchmark.aarch64放在当前目录 + +8.310上执行,执行时确保device空闲 +bash test/pth2om.sh +bash test/eval_acc_perf.sh diff --git a/ACL_PyTorch/contrib/cv/classfication/vovnet39/vovnet39_pth2onnx.py b/ACL_PyTorch/contrib/cv/classfication/vovnet39/vovnet39_pth2onnx.py index cf2e2190b3aecc2a357300cbc3a24cc85a63ce56..b8fbbf27a2aa9586b4cb943280ce70764eb77259 100644 --- a/ACL_PyTorch/contrib/cv/classfication/vovnet39/vovnet39_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/classfication/vovnet39/vovnet39_pth2onnx.py @@ -1,36 +1,36 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import torch -import sys -import torch.onnx -sys.path.append(r"./cnn_train/VoVNet.pytorch") -from collections import OrderedDict -import models_vovnet - -def pth2onnx(input_file, output_file): - model = models_vovnet.vovnet39(pretrained=False) - device_ids = [0] - model = torch.nn.DataParallel(model , device_ids=device_ids) - checkpoint = torch.load(input_file, map_location='cpu') - model.load_state_dict(checkpoint) - model=model.module - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.rand(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, opset_version=11, verbose=True) - -if __name__=="__main__": - pth2onnx(sys.argv[1],sys.argv[2]) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import torch +import sys +import torch.onnx +sys.path.append(r"./cnn_train/VoVNet.pytorch") +from collections import OrderedDict +import models_vovnet + +def pth2onnx(input_file, output_file): + model = models_vovnet.vovnet39(pretrained=False) + device_ids = [0] + model = torch.nn.DataParallel(model , device_ids=device_ids) + checkpoint = torch.load(input_file, map_location='cpu') + model.load_state_dict(checkpoint) + model=model.module + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.rand(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, opset_version=11, verbose=True) + +if __name__=="__main__": + pth2onnx(sys.argv[1],sys.argv[2]) diff --git a/ACL_PyTorch/contrib/cv/classfication/xcit/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/classfication/xcit/modelzoo_level.txt index 624f885ed6c21f5d36232fec82f622547cfc6470..2e7cc57906a28cb6152073257cc7b211d6979f7d 100644 --- a/ACL_PyTorch/contrib/cv/classfication/xcit/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/classfication/xcit/modelzoo_level.txt @@ -1,6 +1,6 @@ -FuncStatus:OK -PrecisionStatus:OK -ModelConvert:OK -PerfStatus=NOK -AutoTune:POK - +FuncStatus:OK +PrecisionStatus:OK +ModelConvert:OK +PerfStatus=NOK +AutoTune:POK + diff --git a/ACL_PyTorch/contrib/cv/detection/3DUnet/LISCENSE b/ACL_PyTorch/contrib/cv/detection/3DUnet/LISCENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/detection/3DUnet/LISCENSE +++ b/ACL_PyTorch/contrib/cv/detection/3DUnet/LISCENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/3DUnet/UNet3D_pth2onnx.py b/ACL_PyTorch/contrib/cv/detection/3DUnet/UNet3D_pth2onnx.py index ca9db19e96e4c6ab6731b60260ad32dd2c1ccffc..5a18441c828c58fb92e8efab7a2b102daf654600 100644 --- a/ACL_PyTorch/contrib/cv/detection/3DUnet/UNet3D_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/3DUnet/UNet3D_pth2onnx.py @@ -1,49 +1,49 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import torch -import lib.medzoo as medzoo - -def pth2onnx(): - args = get_arguments() - input_file = args.input - output_file = args.output - model, optimizer = medzoo.create_model(args) - checkpoint = torch.load(input_file, map_location="cpu") - model.load_state_dict(checkpoint, False) - - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(1, 4, 64, 64, 64) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=False, - opset_version=11) - - -def get_arguments(): - parser = argparse.ArgumentParser() - parser.add_argument('--classes', type=int, default=4) - parser.add_argument('--inChannels', type=int, default=4) - parser.add_argument('--model', type=str, default='UNET3D', - choices=('VNET', 'VNET2', 'UNET3D', 'DENSENET1', 'DENSENET2', 'DENSENET3', 'HYPERDENSENET')) - parser.add_argument('--input', type=str, default='none') - parser.add_argument('--output', type=str, default='none') - args = parser.parse_args() - return args - - -if __name__ == '__main__': +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import torch +import lib.medzoo as medzoo + +def pth2onnx(): + args = get_arguments() + input_file = args.input + output_file = args.output + model, optimizer = medzoo.create_model(args) + checkpoint = torch.load(input_file, map_location="cpu") + model.load_state_dict(checkpoint, False) + + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 4, 64, 64, 64) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=False, + opset_version=11) + + +def get_arguments(): + parser = argparse.ArgumentParser() + parser.add_argument('--classes', type=int, default=4) + parser.add_argument('--inChannels', type=int, default=4) + parser.add_argument('--model', type=str, default='UNET3D', + choices=('VNET', 'VNET2', 'UNET3D', 'DENSENET1', 'DENSENET2', 'DENSENET3', 'HYPERDENSENET')) + parser.add_argument('--input', type=str, default='none') + parser.add_argument('--output', type=str, default='none') + args = parser.parse_args() + return args + + +if __name__ == '__main__': pth2onnx() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/3DUnet/modify.py b/ACL_PyTorch/contrib/cv/detection/3DUnet/modify.py index ffac9320981c3933b4187b8e58629a9152768c86..75d5144dc2e8598dcb71a87417b4890780d06c1b 100644 --- a/ACL_PyTorch/contrib/cv/detection/3DUnet/modify.py +++ b/ACL_PyTorch/contrib/cv/detection/3DUnet/modify.py @@ -1,113 +1,113 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import numpy as np -from magiconnx import OnnxGraph -import sys - -def modify(path, batchsize): - graph = OnnxGraph(path) - resizes = graph.get_nodes("Resize") - #1 128 4 4 4 -> 1 128*4 4 4 -> 1 128*4 8 8 -> 1 128 4 8*8 -> 1 128 8 8*8 -> 1 128 8 8 8 - shapes1 = [[[1, 128*4, 4, 4], [1,1,2,2], [1, 128, 4, 8*8], [1, 128, 8, 8*8], [1, 128, 8, 8, 8]], - [[1, 64*8, 8, 8], [1,1,2,2], [1, 64, 8, 16*16], [1, 64, 16, 16*16], [1, 64, 16, 16, 16]], - [[1, 32*16, 16, 16], [1,1,2,2], [1, 32, 16, 32*32], [1, 32, 32, 32*32], [1, 32, 32, 32, 32]], - [[1, 16*32, 32, 32], [1,1,2,2], [1, 16, 32, 64*64], [1, 16, 64, 64*64], [1, 16, 64, 64, 64]], - [[1, 4*16, 16, 16], [1,1,2,2], [1, 4, 16, 32*32], [1, 4, 32, 32*32], [1, 4, 32, 32, 32]], - [[1, 4*32, 32, 32], [1,1,2,2], [1, 4, 32, 64*64], [1, 4, 64, 64*64], [1, 4, 64, 64, 64]]] - - #4 128 4 4 4 - shapes4 = [[[4, 128*4, 4, 4], [1,1,2,2], [4, 128, 4, 8*8], [4, 128, 8, 8*8], [4, 128, 8, 8, 8]], - [[4, 64*8, 8, 8], [1,1,2,2], [4, 64, 8, 16*16], [4, 64, 16, 16*16], [4, 64, 16, 16, 16]], - [[4, 32*16, 16, 16], [1,1,2,2], [4, 32, 16, 32*32], [4, 32, 32, 32*32], [4, 32, 32, 32, 32]], - [[4, 16*32, 32, 32], [1,1,2,2], [4, 16, 32, 64*64], [4, 16, 64, 64*64], [4, 16, 64, 64, 64]], - [[4, 4*16, 16, 16], [1,1,2,2], [4, 4, 16, 32*32], [4, 4, 32, 32*32], [4, 4, 32, 32, 32]], - [[4, 4*32, 32, 32], [1,1,2,2], [4, 4, 32, 64*64], [4, 4, 64, 64*64], [4, 4, 64, 64, 64]]] - - #8 128 4 4 4 -> 8 128*4 4 4 -> 8 128*4 8 8 -> 8 128 4 8*8 -> 8 128 8 8*8 -> 8 128 8 8 8 - shapes8 = [[[8, 128*4, 4, 4], [1,1,2,2], [8, 128, 4, 8*8], [8, 128, 8, 8*8], [8, 128, 8, 8, 8]], - [[8, 64*8, 8, 8], [1,1,2,2], [8, 64, 8, 16*16], [8, 64, 16, 16*16], [8, 64, 16, 16, 16]], - [[8, 32*16, 16, 16], [1,1,2,2], [8, 32, 16, 32*32], [8, 32, 32, 32*32], [8, 32, 32, 32, 32]], - [[8, 16*32, 32, 32], [1,1,2,2], [8, 16, 32, 64*64], [8, 16, 64, 64*64], [8, 16, 64, 64, 64]], - [[8, 4*16, 16, 16], [1,1,2,2], [8, 4, 16, 32*32], [8, 4, 32, 32*32], [8, 4, 32, 32, 32]], - [[8, 4*32, 32, 32], [1,1,2,2], [8, 4, 32, 64*64], [8, 4, 64, 64*64], [8, 4, 64, 64, 64]]] - - #16 128 4 4 4 -> 16 128*4 4 4 -> 16 128*4 8 8 -> 16 128 4 8*8 -> 16 128 8 8*8 -> 16 128 8 8 8 - shapes16 = [[[16, 128*4, 4, 4], [1,1,2,2], [16, 128, 4, 8*8], [16, 128, 8, 8*8], [16, 128, 8, 8, 8]], - [[16, 64*8, 8, 8], [1,1,2,2], [16, 64, 8, 16*16], [16, 64, 16, 16*16], [16, 64, 16, 16, 16]], - [[16, 32*16, 16, 16], [1,1,2,2], [16, 32, 16, 32*32], [16, 32, 32, 32*32], [16, 32, 32, 32, 32]], - [[16, 16*32, 32, 32], [1,1,2,2], [16, 16, 32, 64*64], [16, 16, 64, 64*64], [16, 16, 64, 64, 64]], - [[16, 4*16, 16, 16], [1,1,2,2], [16, 4, 16, 32*32], [16, 4, 32, 32*32], [16, 4, 32, 32, 32]], - [[16, 4*32, 32, 32], [1,1,2,2], [16, 4, 32, 64*64], [16, 4, 64, 64*64], [16, 4, 64, 64, 64]]] - - #32 128 4 4 4 -> 32 128*4 4 4 -> 32 128*4 8 8 -> 32 128 4 8*8 -> 32 128 8 8*8 -> 32 128 8 8 8 - shapes32 = [[[32, 128*4, 4, 4], [1,1,2,2], [32, 128, 4, 8*8], [32, 128, 8, 8*8], [32, 128, 8, 8, 8]], - [[32, 64*8, 8, 8], [1,1,2,2], [32, 64, 8, 16*16], [32, 64, 16, 16*16], [32, 64, 16, 16, 16]], - [[32, 32*16, 16, 16], [1,1,2,2], [32, 32, 16, 32*32], [32, 32, 32, 32*32], [32, 32, 32, 32, 32]], - [[32, 16*32, 32, 32], [1,1,2,2], [32, 16, 32, 64*64], [32, 16, 64, 64*64], [32, 16, 64, 64, 64]], - [[32, 4*16, 16, 16], [1,1,2,2], [32, 4, 16, 32*32], [32, 4, 32, 32*32], [32, 4, 32, 32, 32]], - [[32, 4*32, 32, 32], [1,1,2,2], [32, 4, 32, 64*64], [32, 4, 64, 64*64], [32, 4, 64, 64, 64]]] - - if batchsize == "1": - shapes = shapes1 - - elif batchsize == "4": - shapes = shapes4 - - elif batchsize == "8": - shapes = shapes8 - - elif batchsize == "16": - shapes = shapes16 - - elif batchsize == "32": - shapes = shapes32 - else: - print("batchsize输入错误") - - for idx, node in enumerate(resizes): - print("idx: node.name", idx, node.name) - reshape1 = graph.add_node(f'Reshape_{node.name}', 'Reshape') - graph.add_initializer(f'shape_{node.name}', np.array(shapes[idx][0])) - reshape1.inputs = [node.inputs[0], f'shape_{node.name}'] - reshape1.outputs = [f'Reshape_{node.name}'] - - graph[node.inputs[-1]].value = np.array(shapes[idx][1]).astype(np.float32) - out_name = node.outputs[0] - node.set_input(0, f'Reshape_{node.name}') - node.set_output(0, f'{node.name}_reshape') - - reshape2 = graph.add_node(f'Reshape2_{node.name}', 'Reshape') - graph.add_initializer(f'shape2_{node.name}', np.array(shapes[idx][2])) - reshape2.inputs = [f'{node.name}_reshape', f'shape2_{node.name}'] - reshape2.outputs = [f'Reshape2_{node.name}_out'] - - resize2 = graph.add_node(f'Resize2_{node.name}', 'Resize') - graph.add_initializer(f'size_{node.name}', np.array(shapes[idx][3])) - resize2.inputs = [f'Reshape2_{node.name}_out', node.inputs[1], node.inputs[1], f'size_{node.name}'] - resize2.outputs = [f'Resize2_{node.name}'] - - reshape3 = graph.add_node(f'Reshape3_{node.name}', 'Reshape') - graph.add_initializer(f'shape3_{node.name}', np.array(shapes[idx][4])) - reshape3.inputs = [f'Resize2_{node.name}', f'shape3_{node.name}'] - reshape3.outputs = [out_name] - - graph.save(output_file) - -if __name__ == "__main__": - #input_file是输入的简化后的onnx路径,output_file是输出的onnx名称,batchsize是要转的onnx对应的batchsize大小 - input_file = sys.argv[1] - output_file = sys.argv[2] - batch = sys.argv[3] - modify(input_file, batch) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +from magiconnx import OnnxGraph +import sys + +def modify(path, batchsize): + graph = OnnxGraph(path) + resizes = graph.get_nodes("Resize") + #1 128 4 4 4 -> 1 128*4 4 4 -> 1 128*4 8 8 -> 1 128 4 8*8 -> 1 128 8 8*8 -> 1 128 8 8 8 + shapes1 = [[[1, 128*4, 4, 4], [1,1,2,2], [1, 128, 4, 8*8], [1, 128, 8, 8*8], [1, 128, 8, 8, 8]], + [[1, 64*8, 8, 8], [1,1,2,2], [1, 64, 8, 16*16], [1, 64, 16, 16*16], [1, 64, 16, 16, 16]], + [[1, 32*16, 16, 16], [1,1,2,2], [1, 32, 16, 32*32], [1, 32, 32, 32*32], [1, 32, 32, 32, 32]], + [[1, 16*32, 32, 32], [1,1,2,2], [1, 16, 32, 64*64], [1, 16, 64, 64*64], [1, 16, 64, 64, 64]], + [[1, 4*16, 16, 16], [1,1,2,2], [1, 4, 16, 32*32], [1, 4, 32, 32*32], [1, 4, 32, 32, 32]], + [[1, 4*32, 32, 32], [1,1,2,2], [1, 4, 32, 64*64], [1, 4, 64, 64*64], [1, 4, 64, 64, 64]]] + + #4 128 4 4 4 + shapes4 = [[[4, 128*4, 4, 4], [1,1,2,2], [4, 128, 4, 8*8], [4, 128, 8, 8*8], [4, 128, 8, 8, 8]], + [[4, 64*8, 8, 8], [1,1,2,2], [4, 64, 8, 16*16], [4, 64, 16, 16*16], [4, 64, 16, 16, 16]], + [[4, 32*16, 16, 16], [1,1,2,2], [4, 32, 16, 32*32], [4, 32, 32, 32*32], [4, 32, 32, 32, 32]], + [[4, 16*32, 32, 32], [1,1,2,2], [4, 16, 32, 64*64], [4, 16, 64, 64*64], [4, 16, 64, 64, 64]], + [[4, 4*16, 16, 16], [1,1,2,2], [4, 4, 16, 32*32], [4, 4, 32, 32*32], [4, 4, 32, 32, 32]], + [[4, 4*32, 32, 32], [1,1,2,2], [4, 4, 32, 64*64], [4, 4, 64, 64*64], [4, 4, 64, 64, 64]]] + + #8 128 4 4 4 -> 8 128*4 4 4 -> 8 128*4 8 8 -> 8 128 4 8*8 -> 8 128 8 8*8 -> 8 128 8 8 8 + shapes8 = [[[8, 128*4, 4, 4], [1,1,2,2], [8, 128, 4, 8*8], [8, 128, 8, 8*8], [8, 128, 8, 8, 8]], + [[8, 64*8, 8, 8], [1,1,2,2], [8, 64, 8, 16*16], [8, 64, 16, 16*16], [8, 64, 16, 16, 16]], + [[8, 32*16, 16, 16], [1,1,2,2], [8, 32, 16, 32*32], [8, 32, 32, 32*32], [8, 32, 32, 32, 32]], + [[8, 16*32, 32, 32], [1,1,2,2], [8, 16, 32, 64*64], [8, 16, 64, 64*64], [8, 16, 64, 64, 64]], + [[8, 4*16, 16, 16], [1,1,2,2], [8, 4, 16, 32*32], [8, 4, 32, 32*32], [8, 4, 32, 32, 32]], + [[8, 4*32, 32, 32], [1,1,2,2], [8, 4, 32, 64*64], [8, 4, 64, 64*64], [8, 4, 64, 64, 64]]] + + #16 128 4 4 4 -> 16 128*4 4 4 -> 16 128*4 8 8 -> 16 128 4 8*8 -> 16 128 8 8*8 -> 16 128 8 8 8 + shapes16 = [[[16, 128*4, 4, 4], [1,1,2,2], [16, 128, 4, 8*8], [16, 128, 8, 8*8], [16, 128, 8, 8, 8]], + [[16, 64*8, 8, 8], [1,1,2,2], [16, 64, 8, 16*16], [16, 64, 16, 16*16], [16, 64, 16, 16, 16]], + [[16, 32*16, 16, 16], [1,1,2,2], [16, 32, 16, 32*32], [16, 32, 32, 32*32], [16, 32, 32, 32, 32]], + [[16, 16*32, 32, 32], [1,1,2,2], [16, 16, 32, 64*64], [16, 16, 64, 64*64], [16, 16, 64, 64, 64]], + [[16, 4*16, 16, 16], [1,1,2,2], [16, 4, 16, 32*32], [16, 4, 32, 32*32], [16, 4, 32, 32, 32]], + [[16, 4*32, 32, 32], [1,1,2,2], [16, 4, 32, 64*64], [16, 4, 64, 64*64], [16, 4, 64, 64, 64]]] + + #32 128 4 4 4 -> 32 128*4 4 4 -> 32 128*4 8 8 -> 32 128 4 8*8 -> 32 128 8 8*8 -> 32 128 8 8 8 + shapes32 = [[[32, 128*4, 4, 4], [1,1,2,2], [32, 128, 4, 8*8], [32, 128, 8, 8*8], [32, 128, 8, 8, 8]], + [[32, 64*8, 8, 8], [1,1,2,2], [32, 64, 8, 16*16], [32, 64, 16, 16*16], [32, 64, 16, 16, 16]], + [[32, 32*16, 16, 16], [1,1,2,2], [32, 32, 16, 32*32], [32, 32, 32, 32*32], [32, 32, 32, 32, 32]], + [[32, 16*32, 32, 32], [1,1,2,2], [32, 16, 32, 64*64], [32, 16, 64, 64*64], [32, 16, 64, 64, 64]], + [[32, 4*16, 16, 16], [1,1,2,2], [32, 4, 16, 32*32], [32, 4, 32, 32*32], [32, 4, 32, 32, 32]], + [[32, 4*32, 32, 32], [1,1,2,2], [32, 4, 32, 64*64], [32, 4, 64, 64*64], [32, 4, 64, 64, 64]]] + + if batchsize == "1": + shapes = shapes1 + + elif batchsize == "4": + shapes = shapes4 + + elif batchsize == "8": + shapes = shapes8 + + elif batchsize == "16": + shapes = shapes16 + + elif batchsize == "32": + shapes = shapes32 + else: + print("batchsize输入错误") + + for idx, node in enumerate(resizes): + print("idx: node.name", idx, node.name) + reshape1 = graph.add_node(f'Reshape_{node.name}', 'Reshape') + graph.add_initializer(f'shape_{node.name}', np.array(shapes[idx][0])) + reshape1.inputs = [node.inputs[0], f'shape_{node.name}'] + reshape1.outputs = [f'Reshape_{node.name}'] + + graph[node.inputs[-1]].value = np.array(shapes[idx][1]).astype(np.float32) + out_name = node.outputs[0] + node.set_input(0, f'Reshape_{node.name}') + node.set_output(0, f'{node.name}_reshape') + + reshape2 = graph.add_node(f'Reshape2_{node.name}', 'Reshape') + graph.add_initializer(f'shape2_{node.name}', np.array(shapes[idx][2])) + reshape2.inputs = [f'{node.name}_reshape', f'shape2_{node.name}'] + reshape2.outputs = [f'Reshape2_{node.name}_out'] + + resize2 = graph.add_node(f'Resize2_{node.name}', 'Resize') + graph.add_initializer(f'size_{node.name}', np.array(shapes[idx][3])) + resize2.inputs = [f'Reshape2_{node.name}_out', node.inputs[1], node.inputs[1], f'size_{node.name}'] + resize2.outputs = [f'Resize2_{node.name}'] + + reshape3 = graph.add_node(f'Reshape3_{node.name}', 'Reshape') + graph.add_initializer(f'shape3_{node.name}', np.array(shapes[idx][4])) + reshape3.inputs = [f'Resize2_{node.name}', f'shape3_{node.name}'] + reshape3.outputs = [out_name] + + graph.save(output_file) + +if __name__ == "__main__": + #input_file是输入的简化后的onnx路径,output_file是输出的onnx名称,batchsize是要转的onnx对应的batchsize大小 + input_file = sys.argv[1] + output_file = sys.argv[2] + batch = sys.argv[3] + modify(input_file, batch) diff --git a/ACL_PyTorch/contrib/cv/detection/3DUnet/postprocess.py b/ACL_PyTorch/contrib/cv/detection/3DUnet/postprocess.py index 811c649ef39a87bb2cd021cb7ae4d86568015ccf..de0ce74cd8191115fa262621229fe1bac97f208d 100644 --- a/ACL_PyTorch/contrib/cv/detection/3DUnet/postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/3DUnet/postprocess.py @@ -1,131 +1,131 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import argparse -import os - -import torch -import torch.nn.functional as F - -# Lib files -import numpy as np -from torch.utils.data import dataset -import lib.utils as utils -import lib.medloaders as medical_loaders -import lib.medzoo as medzoo -from lib.visual3D_temp import non_overlap_padding,test_padding -from lib.losses3D import DiceLoss -from lib.utils.general import prepare_input - - -from lib.medloaders.brats2018 import MICCAIBraTS2018 - -from glob import glob - - - -def main(): - args = get_arguments() - model, optimizer = medzoo.create_model(args) - batchSz = args.batchSz - score = 0 - model.eval() - bin_file_path = args.input_bin - pth_file_path = args.input_label - - length = glob(bin_file_path + '/*.bin') - length1 = glob(pth_file_path + '/*.pth') - - criterion = DiceLoss(classes=args.classes) - - for s in range(0, len(length)): - binfile = os.path.join(bin_file_path, str(s) + '_output_0' + ".bin") - output = np.fromfile(binfile, dtype=np.float32) - output = np.reshape(output, (batchSz, 4, 64, 64, 64)) - output = torch.from_numpy(output) - - pthfile = os.path.join(pth_file_path, str(s) + ".pth") - target = torch.load(pthfile) - target = torch.from_numpy(target) - - loss_dice, per_ch_score = criterion(output, target) - avg = np.mean(per_ch_score) - score += avg - print("--------score.avg------------", score / len(length)) - return score / len(length) - - - -def get_arguments(): - parser = argparse.ArgumentParser() - parser.add_argument('--batchSz', type=int, default=1) - parser.add_argument('--dataset_name', type=str, default="brats2018") - parser.add_argument('--dim', nargs="+", type=int, default=(64, 64, 64)) - parser.add_argument('--nEpochs', type=int, default=100) - parser.add_argument('--classes', type=int, default=4) - parser.add_argument('--samples_train', type=int, default=1024) - parser.add_argument('--samples_val', type=int, default=128) - parser.add_argument('--inChannels', type=int, default=4) - parser.add_argument('--inModalities', type=int, default=4) - parser.add_argument('--threshold', default=0.00000000001, type=float) - parser.add_argument('--terminal_show_freq', default=50) - parser.add_argument('--augmentation', action='store_true', default=True) - parser.add_argument('--normalization', default='full_volume_mean', type=str, - help='Tensor normalization: options ,max_min,', - choices=('max_min', 'full_volume_mean', 'brats', 'max', 'mean')) - parser.add_argument('--split', default=0.8, type=float, help='Select percentage of training data(default: 0.8)') - parser.add_argument('--lr', default=5e-3, type=float, - help='learning rate (default: 5e-3)') - parser.add_argument('--cuda', action='store_true', default=False) - - parser.add_argument('--loadData', default=True) - parser.add_argument('--resume', default='', type=str, metavar='PATH', - help='path to latest checkpoint (default: none)') - parser.add_argument('--model', type=str, default='UNET3D', - choices=('VNET', 'VNET2', 'UNET3D', 'DENSENET1', 'DENSENET2', 'DENSENET3', 'HYPERDENSENET')) - parser.add_argument('--opt', type=str, default='sgd', - choices=('sgd', 'adam', 'rmsprop')) - parser.add_argument('--log_dir', type=str, - default='./runs/') - parser.add_argument('--prof', default=False, action='store_true', - help='use profiling to evaluate the performance of model') - - parser.add_argument('--world_size', type=int, default=1) - parser.add_argument('--rank', type=int, default=0) - - - parser.add_argument('--amp', action='store_true', default=False) - - parser.add_argument('--workers', type=int, default=8) - - - parser.add_argument('--device', default='npu', type=str, help='npu or gpu') - parser.add_argument('--pretrained', - default="none", - type=str, metavar='PATH', - help='path to pretrained model') - parser.add_argument('--input_bin', default='none', type=str) - parser.add_argument('--input_label', default='none', type=str) - - - args = parser.parse_args() - - args.save = '../inference_checkpoints/' + args.model + '_checkpoints/' + args.model + '_{}_{}_'.format( - utils.datestr(), args.dataset_name) - args.tb_log_dir = '../runs/' - return args - - - -if __name__ == '__main__': +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import argparse +import os + +import torch +import torch.nn.functional as F + +# Lib files +import numpy as np +from torch.utils.data import dataset +import lib.utils as utils +import lib.medloaders as medical_loaders +import lib.medzoo as medzoo +from lib.visual3D_temp import non_overlap_padding,test_padding +from lib.losses3D import DiceLoss +from lib.utils.general import prepare_input + + +from lib.medloaders.brats2018 import MICCAIBraTS2018 + +from glob import glob + + + +def main(): + args = get_arguments() + model, optimizer = medzoo.create_model(args) + batchSz = args.batchSz + score = 0 + model.eval() + bin_file_path = args.input_bin + pth_file_path = args.input_label + + length = glob(bin_file_path + '/*.bin') + length1 = glob(pth_file_path + '/*.pth') + + criterion = DiceLoss(classes=args.classes) + + for s in range(0, len(length)): + binfile = os.path.join(bin_file_path, str(s) + '_output_0' + ".bin") + output = np.fromfile(binfile, dtype=np.float32) + output = np.reshape(output, (batchSz, 4, 64, 64, 64)) + output = torch.from_numpy(output) + + pthfile = os.path.join(pth_file_path, str(s) + ".pth") + target = torch.load(pthfile) + target = torch.from_numpy(target) + + loss_dice, per_ch_score = criterion(output, target) + avg = np.mean(per_ch_score) + score += avg + print("--------score.avg------------", score / len(length)) + return score / len(length) + + + +def get_arguments(): + parser = argparse.ArgumentParser() + parser.add_argument('--batchSz', type=int, default=1) + parser.add_argument('--dataset_name', type=str, default="brats2018") + parser.add_argument('--dim', nargs="+", type=int, default=(64, 64, 64)) + parser.add_argument('--nEpochs', type=int, default=100) + parser.add_argument('--classes', type=int, default=4) + parser.add_argument('--samples_train', type=int, default=1024) + parser.add_argument('--samples_val', type=int, default=128) + parser.add_argument('--inChannels', type=int, default=4) + parser.add_argument('--inModalities', type=int, default=4) + parser.add_argument('--threshold', default=0.00000000001, type=float) + parser.add_argument('--terminal_show_freq', default=50) + parser.add_argument('--augmentation', action='store_true', default=True) + parser.add_argument('--normalization', default='full_volume_mean', type=str, + help='Tensor normalization: options ,max_min,', + choices=('max_min', 'full_volume_mean', 'brats', 'max', 'mean')) + parser.add_argument('--split', default=0.8, type=float, help='Select percentage of training data(default: 0.8)') + parser.add_argument('--lr', default=5e-3, type=float, + help='learning rate (default: 5e-3)') + parser.add_argument('--cuda', action='store_true', default=False) + + parser.add_argument('--loadData', default=True) + parser.add_argument('--resume', default='', type=str, metavar='PATH', + help='path to latest checkpoint (default: none)') + parser.add_argument('--model', type=str, default='UNET3D', + choices=('VNET', 'VNET2', 'UNET3D', 'DENSENET1', 'DENSENET2', 'DENSENET3', 'HYPERDENSENET')) + parser.add_argument('--opt', type=str, default='sgd', + choices=('sgd', 'adam', 'rmsprop')) + parser.add_argument('--log_dir', type=str, + default='./runs/') + parser.add_argument('--prof', default=False, action='store_true', + help='use profiling to evaluate the performance of model') + + parser.add_argument('--world_size', type=int, default=1) + parser.add_argument('--rank', type=int, default=0) + + + parser.add_argument('--amp', action='store_true', default=False) + + parser.add_argument('--workers', type=int, default=8) + + + parser.add_argument('--device', default='npu', type=str, help='npu or gpu') + parser.add_argument('--pretrained', + default="none", + type=str, metavar='PATH', + help='path to pretrained model') + parser.add_argument('--input_bin', default='none', type=str) + parser.add_argument('--input_label', default='none', type=str) + + + args = parser.parse_args() + + args.save = '../inference_checkpoints/' + args.model + '_checkpoints/' + args.model + '_{}_{}_'.format( + utils.datestr(), args.dataset_name) + args.tb_log_dir = '../runs/' + return args + + + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/AlphaPose/AlphaPose.patch b/ACL_PyTorch/contrib/cv/detection/AlphaPose/AlphaPose.patch index 6cde848c510d66325bef132d431d08a6c0482a6f..99caa0d26ecd1ecb53507a7c28584f27f829c5b3 100644 --- a/ACL_PyTorch/contrib/cv/detection/AlphaPose/AlphaPose.patch +++ b/ACL_PyTorch/contrib/cv/detection/AlphaPose/AlphaPose.patch @@ -209,16 +209,16 @@ index 8a755c9..b8e4c57 100644 --- a/detector/yolo_cfg.py +++ b/detector/yolo_cfg.py @@ -1,8 +1,8 @@ - from easydict import EasyDict as edict - - cfg = edict() --cfg.CONFIG = 'detector/yolo/cfg/yolov3-spp.cfg' --cfg.WEIGHTS = 'detector/yolo/data/yolov3-spp.weights' -+cfg.CONFIG = 'AlphaPose/detector/yolo/cfg/yolov3-spp.cfg' -+cfg.WEIGHTS = 'AlphaPose/detector/yolo/data/yolov3-spp.weights' - cfg.INP_DIM = 608 - cfg.NMS_THRES = 0.6 - cfg.CONFIDENCE = 0.1 + from easydict import EasyDict as edict + + cfg = edict() +-cfg.CONFIG = 'detector/yolo/cfg/yolov3-spp.cfg' +-cfg.WEIGHTS = 'detector/yolo/data/yolov3-spp.weights' ++cfg.CONFIG = 'AlphaPose/detector/yolo/cfg/yolov3-spp.cfg' ++cfg.WEIGHTS = 'AlphaPose/detector/yolo/data/yolov3-spp.weights' + cfg.INP_DIM = 608 + cfg.NMS_THRES = 0.6 + cfg.CONFIDENCE = 0.1 diff --git a/setup.py b/setup.py index d1e397d..4ad65f8 100644 --- a/setup.py diff --git a/ACL_PyTorch/contrib/cv/detection/AlphaPose/LICENSE b/ACL_PyTorch/contrib/cv/detection/AlphaPose/LICENSE index 8904c8516082056802ee732a4213ceab8c4a93af..5f7aa69fea22dade3f519868400025de434ae8ca 100644 --- a/ACL_PyTorch/contrib/cv/detection/AlphaPose/LICENSE +++ b/ACL_PyTorch/contrib/cv/detection/AlphaPose/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/AlphaPose/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/detection/AlphaPose/gen_dataset_info.py index efe82aef071e229c2f3212e1ec5a8531ad4d3e53..3656966b4cd924e11ac53b6449cdec237c0c64f7 100644 --- a/ACL_PyTorch/contrib/cv/detection/AlphaPose/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/detection/AlphaPose/gen_dataset_info.py @@ -1,65 +1,65 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(fpath, info_n, width, height): - ''' - Describe - ''' - bin_images = glob(os.path.join(fpath, '*.bin')) - with open(info_n, 'w') as f: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - f.write(content) - f.write('\n') - - -def get_jpg_info(fpath, info_n): - ''' - Describe - ''' - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(fpath, '*.' + extension))) - with open(info_n, 'w') as f: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - f.write(content) - f.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - Width = sys.argv[4] - Height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, Width, Height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(fpath, info_n, width, height): + ''' + Describe + ''' + bin_images = glob(os.path.join(fpath, '*.bin')) + with open(info_n, 'w') as f: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + f.write(content) + f.write('\n') + + +def get_jpg_info(fpath, info_n): + ''' + Describe + ''' + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(fpath, '*.' + extension))) + with open(info_n, 'w') as f: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + f.write(content) + f.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + Width = sys.argv[4] + Height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, Width, Height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) diff --git a/ACL_PyTorch/contrib/cv/detection/AlphaPose/test/parse.py b/ACL_PyTorch/contrib/cv/detection/AlphaPose/test/parse.py index a0f253b055047b199b33d4b65cdc79177b6b250b..27eae0d0acf98687edd95f1f024cf77c49cd4dc4 100644 --- a/ACL_PyTorch/contrib/cv/detection/AlphaPose/test/parse.py +++ b/ACL_PyTorch/contrib/cv/detection/AlphaPose/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/BSN/BSN_eval.py b/ACL_PyTorch/contrib/cv/detection/BSN/BSN_eval.py index 0976dab05c6fe15ab49f21f7dcc7f506576d8eb9..0624523f6ff987edd53bdb4114ccf0595eacb54d 100644 --- a/ACL_PyTorch/contrib/cv/detection/BSN/BSN_eval.py +++ b/ACL_PyTorch/contrib/cv/detection/BSN/BSN_eval.py @@ -1,85 +1,85 @@ -# -*- coding: utf-8 -*- -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import sys -sys.path.append('./BSN-boundary-sensitive-network.pytorch/Evaluation') -from eval_proposal import ANETproposal -import matplotlib.pyplot as plt -import numpy as np - -def run_evaluation(ground_truth_filename, proposal_filename, - max_avg_nr_proposals=100, - tiou_thresholds=np.linspace(0.5, 0.95, 10), - subset='validation'): - - anet_proposal = ANETproposal(ground_truth_filename, proposal_filename, - tiou_thresholds=tiou_thresholds, - max_avg_nr_proposals=max_avg_nr_proposals, - subset=subset, verbose=True, check_status=False) - anet_proposal.evaluate() - - recall = anet_proposal.recall - average_recall = anet_proposal.avg_recall - average_nr_proposals = anet_proposal.proposals_per_video - - return (average_nr_proposals, average_recall, recall) - -def plot_metric(average_nr_proposals, average_recall, recall, tiou_thresholds=np.linspace(0.5, 0.95, 10)): - - fn_size = 14 - plt.figure(num=None, figsize=(12, 8)) - ax = plt.subplot(1,1,1) - - colors = ['k', 'r', 'yellow', 'b', 'c', 'm', 'b', 'pink', 'lawngreen', 'indigo'] - area_under_curve = np.zeros_like(tiou_thresholds) - for i in range(recall.shape[0]): - area_under_curve[i] = np.trapz(recall[i], average_nr_proposals) - - for idx, tiou in enumerate(tiou_thresholds[::2]): - ax.plot(average_nr_proposals, recall[2*idx,:], color=colors[idx+1], - label="tiou=[" + str(tiou) + "], area=" + str(int(area_under_curve[2*idx]*100)/100.), - linewidth=4, linestyle='--', marker=None) - # Plots Average Recall vs Average number of proposals. - ax.plot(average_nr_proposals, average_recall, color=colors[0], - label="tiou = 0.5:0.05:0.95," + " area=" + str(int(np.trapz(average_recall, average_nr_proposals)*100)/100.), - linewidth=4, linestyle='-', marker=None) - - handles, labels = ax.get_legend_handles_labels() - ax.legend([handles[-1]] + handles[:-1], [labels[-1]] + labels[:-1], loc='best') - - plt.ylabel('Average Recall', fontsize=fn_size) - plt.xlabel('Average Number of Proposals per Video', fontsize=fn_size) - plt.grid(b=True, which="both") - plt.ylim([0, 1.0]) - plt.setp(plt.axes().get_xticklabels(), fontsize=fn_size) - plt.setp(plt.axes().get_yticklabels(), fontsize=fn_size) - #plt.show() - plt.savefig("./output/evaluation_result.jpg") - -def evaluation_proposal(): - - uniform_average_nr_proposals_valid, uniform_average_recall_valid, uniform_recall_valid = run_evaluation( - "./BSN-boundary-sensitive-network.pytorch/Evaluation/data/activity_net_1_3_new.json", - "./output/result_proposal.json", - max_avg_nr_proposals=100, - tiou_thresholds=np.linspace(0.5, 0.95, 10), - subset='validation') - - plot_metric(uniform_average_nr_proposals_valid, uniform_average_recall_valid, uniform_recall_valid) - print('AR@1 is \t{}'.format(np.mean(uniform_recall_valid[:,0]))) - print('AR@5 is \t{}'.format(np.mean(uniform_recall_valid[:,4]))) - print('AR@10 is \t{}'.format(np.mean(uniform_recall_valid[:,9]))) - print('AR@100 is \t{}'.format(np.mean(uniform_recall_valid[:,-1]))) -if __name__ =="__main__": +# -*- coding: utf-8 -*- +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +sys.path.append('./BSN-boundary-sensitive-network.pytorch/Evaluation') +from eval_proposal import ANETproposal +import matplotlib.pyplot as plt +import numpy as np + +def run_evaluation(ground_truth_filename, proposal_filename, + max_avg_nr_proposals=100, + tiou_thresholds=np.linspace(0.5, 0.95, 10), + subset='validation'): + + anet_proposal = ANETproposal(ground_truth_filename, proposal_filename, + tiou_thresholds=tiou_thresholds, + max_avg_nr_proposals=max_avg_nr_proposals, + subset=subset, verbose=True, check_status=False) + anet_proposal.evaluate() + + recall = anet_proposal.recall + average_recall = anet_proposal.avg_recall + average_nr_proposals = anet_proposal.proposals_per_video + + return (average_nr_proposals, average_recall, recall) + +def plot_metric(average_nr_proposals, average_recall, recall, tiou_thresholds=np.linspace(0.5, 0.95, 10)): + + fn_size = 14 + plt.figure(num=None, figsize=(12, 8)) + ax = plt.subplot(1,1,1) + + colors = ['k', 'r', 'yellow', 'b', 'c', 'm', 'b', 'pink', 'lawngreen', 'indigo'] + area_under_curve = np.zeros_like(tiou_thresholds) + for i in range(recall.shape[0]): + area_under_curve[i] = np.trapz(recall[i], average_nr_proposals) + + for idx, tiou in enumerate(tiou_thresholds[::2]): + ax.plot(average_nr_proposals, recall[2*idx,:], color=colors[idx+1], + label="tiou=[" + str(tiou) + "], area=" + str(int(area_under_curve[2*idx]*100)/100.), + linewidth=4, linestyle='--', marker=None) + # Plots Average Recall vs Average number of proposals. + ax.plot(average_nr_proposals, average_recall, color=colors[0], + label="tiou = 0.5:0.05:0.95," + " area=" + str(int(np.trapz(average_recall, average_nr_proposals)*100)/100.), + linewidth=4, linestyle='-', marker=None) + + handles, labels = ax.get_legend_handles_labels() + ax.legend([handles[-1]] + handles[:-1], [labels[-1]] + labels[:-1], loc='best') + + plt.ylabel('Average Recall', fontsize=fn_size) + plt.xlabel('Average Number of Proposals per Video', fontsize=fn_size) + plt.grid(b=True, which="both") + plt.ylim([0, 1.0]) + plt.setp(plt.axes().get_xticklabels(), fontsize=fn_size) + plt.setp(plt.axes().get_yticklabels(), fontsize=fn_size) + #plt.show() + plt.savefig("./output/evaluation_result.jpg") + +def evaluation_proposal(): + + uniform_average_nr_proposals_valid, uniform_average_recall_valid, uniform_recall_valid = run_evaluation( + "./BSN-boundary-sensitive-network.pytorch/Evaluation/data/activity_net_1_3_new.json", + "./output/result_proposal.json", + max_avg_nr_proposals=100, + tiou_thresholds=np.linspace(0.5, 0.95, 10), + subset='validation') + + plot_metric(uniform_average_nr_proposals_valid, uniform_average_recall_valid, uniform_recall_valid) + print('AR@1 is \t{}'.format(np.mean(uniform_recall_valid[:,0]))) + print('AR@5 is \t{}'.format(np.mean(uniform_recall_valid[:,4]))) + print('AR@10 is \t{}'.format(np.mean(uniform_recall_valid[:,9]))) + print('AR@100 is \t{}'.format(np.mean(uniform_recall_valid[:,-1]))) +if __name__ =="__main__": evaluation_proposal() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/BSN/BSN_pem_postprocess.py b/ACL_PyTorch/contrib/cv/detection/BSN/BSN_pem_postprocess.py index ed9b16d775028f3017a309bde789d14d031b6cc7..f37f5a8236132d62524d813503a28d91f38b323d 100644 --- a/ACL_PyTorch/contrib/cv/detection/BSN/BSN_pem_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/BSN/BSN_pem_postprocess.py @@ -1,190 +1,190 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import json -import torch -import argparse -import os -import numpy as np -import pandas as pd -import multiprocessing as mp - -parser = argparse.ArgumentParser(description='BSN') - -parser.add_argument('--result_path',default='output/PEM_results', type=str, help='Dir to save txt results') -parser.add_argument('--PEM_out_path', default='result/dumpOutput_device1', type=str, help='infer out path') -parser.add_argument('--PEM_video_xmin_path', default='output/BSN-PEM-preprocess/xmin', type=str, help='infer info path') -parser.add_argument('--PEM_video_xmax_path', default='output/BSN-PEM-preprocess/xmax', type=str, help='infer info path') -parser.add_argument('--PEM_video_xmin_score_path', default='output/BSN-PEM-preprocess/xmin_score', type=str, help='infer info path') -parser.add_argument('--PEM_video_xmax_score_path', default='output/BSN-PEM-preprocess/xmax_score', type=str, help='infer info path') -# parser.add_argument('--info_name', default='./deepspeech_om_bin.info', type=str, help='input info path') -# parser.add_argument('--confidence_threshold', default=0.02, type=float, help='confidence_threshold') -args = parser.parse_args() - -def load_json(file): - with open(file) as json_file: - data = json.load(json_file) - return data - -def getDatasetDict(): - df=pd.read_csv("BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/video_info_new.csv") - json_data= load_json("BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/anet_anno_action.json") - database=json_data - video_dict={} - for i in range(len(df)): - video_name=df.video.values[i] - video_info=database[video_name] - video_new_info={} - video_new_info['duration_frame']=video_info['duration_frame'] - video_new_info['duration_second']=video_info['duration_second'] - video_new_info["feature_frame"]=video_info['feature_frame'] - video_subset=df.subset.values[i] - video_new_info['annotations']=video_info['annotations'] - if video_subset=="validation": - video_dict[video_name]=video_new_info - return video_dict - -def iou_with_anchors(anchors_min,anchors_max,len_anchors,box_min,box_max): - """Compute jaccard score between a box and the anchors. - """ - int_xmin = np.maximum(anchors_min, box_min) - int_xmax = np.minimum(anchors_max, box_max) - inter_len = np.maximum(int_xmax - int_xmin, 0.) - union_len = len_anchors - inter_len +box_max-box_min - #print inter_len,union_len - jaccard = np.divide(inter_len, union_len) - return jaccard - -def Soft_NMS(df): - df=df.sort_values(by="score",ascending=False) - - tstart=list(df.xmin.values[:]) - tend=list(df.xmax.values[:]) - tscore=list(df.score.values[:]) - rstart=[] - rend=[] - rscore=[] - - while len(tscore)>0 and len(rscore)<=100: - max_index=np.argmax(tscore) - tmp_width = tend[max_index] -tstart[max_index] - iou_list = iou_with_anchors(tstart[max_index],tend[max_index],tmp_width,np.array(tstart),np.array(tend)) - iou_exp_list = np.exp(-np.square(iou_list)/0.75) - for idx in range(0,len(tscore)): - if idx!=max_index: - tmp_iou = iou_list[idx] - if tmp_iou>0.65 + (0.9 - 0.65) * tmp_width: - tscore[idx]=tscore[idx]*iou_exp_list[idx] - - rstart.append(tstart[max_index]) - rend.append(tend[max_index]) - rscore.append(tscore[max_index]) - tstart.pop(max_index) - tend.pop(max_index) - tscore.pop(max_index) - - newDf=pd.DataFrame() - newDf['score']=rscore - newDf['xmin']=rstart - newDf['xmax']=rend - return newDf - -def video_post_process(video_list,video_dict): - - for video_name in video_list: - df=pd.read_csv("./output/PEM_results/"+video_name+".csv") - - df['score']=df.iou_score.values[:]*df.xmin_score.values[:]*df.xmax_score.values[:] - if len(df)>1: - df=Soft_NMS(df) - - df=df.sort_values(by="score",ascending=False) - video_info=video_dict[video_name] - video_duration=float(video_info["duration_frame"]/16*16)/video_info["duration_frame"]*video_info["duration_second"] - proposal_list=[] - - for j in range(min(100,len(df))): - tmp_proposal={} - tmp_proposal["score"]=df.score.values[j] - tmp_proposal["segment"]=[max(0,df.xmin.values[j])*video_duration,min(1,df.xmax.values[j])*video_duration] - proposal_list.append(tmp_proposal) - result_dict[video_name[2:]]=proposal_list - - -def BSN_post_processing(): - video_dict=getDatasetDict() - video_list=video_dict.keys()#[:100] - video_list = list(video_list) - global result_dict - result_dict=mp.Manager().dict() - - num_videos = len(video_list) - num_videos_per_thread = num_videos/8 - processes = [] - for tid in range(7): - tmp_video_list = video_list[int(tid*num_videos_per_thread):int((tid+1)*num_videos_per_thread)] - p = mp.Process(target = video_post_process,args =(tmp_video_list,video_dict,)) - p.start() - processes.append(p) - tmp_video_list = video_list[int(7*num_videos_per_thread):] - p = mp.Process(target = video_post_process,args =(tmp_video_list,video_dict,)) - p.start() - processes.append(p) - for p in processes: - p.join() - - result_dict = dict(result_dict) - output_dict={"version":"VERSION 1.3","results":result_dict,"external_data":{}} - outfile=open("./output/result_proposal.json","w") - json.dump(output_dict,outfile) - outfile.close() - -if __name__ == '__main__': - if not os.path.exists("output/PEM_results"): - os.makedirs("output/PEM_results") - out_files = os.listdir(args.PEM_out_path) - print("processing...") - for i in range(len(out_files)): - video_name = str(out_files[i]) - video_name = video_name[0:int(len(video_name)-6)] - video_data = np.fromfile(args.PEM_out_path+'/'+out_files[i],dtype=np.float32) - - video_xmin = np.fromfile(args.PEM_video_xmin_path+'/'+video_name+'.bin',dtype=np.float64) - video_xmax = np.fromfile(args.PEM_video_xmax_path+'/'+video_name+'.bin',dtype=np.float64) - video_xmin_score = np.fromfile(args.PEM_video_xmin_score_path+'/'+video_name+'.bin',dtype=np.float64) - video_xmax_score = np.fromfile(args.PEM_video_xmax_score_path+'/'+video_name+'.bin',dtype=np.float64) - - video_data = torch.tensor(video_data) - video_xmin = torch.tensor(video_xmin) - video_xmax = torch.tensor(video_xmax) - video_xmin_score = torch.tensor(video_xmin_score) - video_xmax_score = torch.tensor(video_xmax_score) - data_num = int(video_xmin.shape[0]) - video_data = video_data[:data_num] - - video_data = video_data.view(-1).detach().cpu().numpy() - video_xmin = video_xmin.view(-1).cpu().numpy() - video_xmax = video_xmax.view(-1).cpu().numpy() - video_xmin_score = video_xmin_score.view(-1).cpu().numpy() - video_xmax_score = video_xmax_score.view(-1).cpu().numpy() - - df=pd.DataFrame() - df["xmin"]=video_xmin - df["xmax"]=video_xmax - df["xmin_score"]=video_xmin_score - df["xmax_score"]=video_xmax_score - df["iou_score"]=video_data - df.to_csv(args.result_path+'/'+video_name+".csv",index=False) - print("PGM: start generating BSN_post feature") - BSN_post_processing() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import json +import torch +import argparse +import os +import numpy as np +import pandas as pd +import multiprocessing as mp + +parser = argparse.ArgumentParser(description='BSN') + +parser.add_argument('--result_path',default='output/PEM_results', type=str, help='Dir to save txt results') +parser.add_argument('--PEM_out_path', default='result/dumpOutput_device1', type=str, help='infer out path') +parser.add_argument('--PEM_video_xmin_path', default='output/BSN-PEM-preprocess/xmin', type=str, help='infer info path') +parser.add_argument('--PEM_video_xmax_path', default='output/BSN-PEM-preprocess/xmax', type=str, help='infer info path') +parser.add_argument('--PEM_video_xmin_score_path', default='output/BSN-PEM-preprocess/xmin_score', type=str, help='infer info path') +parser.add_argument('--PEM_video_xmax_score_path', default='output/BSN-PEM-preprocess/xmax_score', type=str, help='infer info path') +# parser.add_argument('--info_name', default='./deepspeech_om_bin.info', type=str, help='input info path') +# parser.add_argument('--confidence_threshold', default=0.02, type=float, help='confidence_threshold') +args = parser.parse_args() + +def load_json(file): + with open(file) as json_file: + data = json.load(json_file) + return data + +def getDatasetDict(): + df=pd.read_csv("BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/video_info_new.csv") + json_data= load_json("BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/anet_anno_action.json") + database=json_data + video_dict={} + for i in range(len(df)): + video_name=df.video.values[i] + video_info=database[video_name] + video_new_info={} + video_new_info['duration_frame']=video_info['duration_frame'] + video_new_info['duration_second']=video_info['duration_second'] + video_new_info["feature_frame"]=video_info['feature_frame'] + video_subset=df.subset.values[i] + video_new_info['annotations']=video_info['annotations'] + if video_subset=="validation": + video_dict[video_name]=video_new_info + return video_dict + +def iou_with_anchors(anchors_min,anchors_max,len_anchors,box_min,box_max): + """Compute jaccard score between a box and the anchors. + """ + int_xmin = np.maximum(anchors_min, box_min) + int_xmax = np.minimum(anchors_max, box_max) + inter_len = np.maximum(int_xmax - int_xmin, 0.) + union_len = len_anchors - inter_len +box_max-box_min + #print inter_len,union_len + jaccard = np.divide(inter_len, union_len) + return jaccard + +def Soft_NMS(df): + df=df.sort_values(by="score",ascending=False) + + tstart=list(df.xmin.values[:]) + tend=list(df.xmax.values[:]) + tscore=list(df.score.values[:]) + rstart=[] + rend=[] + rscore=[] + + while len(tscore)>0 and len(rscore)<=100: + max_index=np.argmax(tscore) + tmp_width = tend[max_index] -tstart[max_index] + iou_list = iou_with_anchors(tstart[max_index],tend[max_index],tmp_width,np.array(tstart),np.array(tend)) + iou_exp_list = np.exp(-np.square(iou_list)/0.75) + for idx in range(0,len(tscore)): + if idx!=max_index: + tmp_iou = iou_list[idx] + if tmp_iou>0.65 + (0.9 - 0.65) * tmp_width: + tscore[idx]=tscore[idx]*iou_exp_list[idx] + + rstart.append(tstart[max_index]) + rend.append(tend[max_index]) + rscore.append(tscore[max_index]) + tstart.pop(max_index) + tend.pop(max_index) + tscore.pop(max_index) + + newDf=pd.DataFrame() + newDf['score']=rscore + newDf['xmin']=rstart + newDf['xmax']=rend + return newDf + +def video_post_process(video_list,video_dict): + + for video_name in video_list: + df=pd.read_csv("./output/PEM_results/"+video_name+".csv") + + df['score']=df.iou_score.values[:]*df.xmin_score.values[:]*df.xmax_score.values[:] + if len(df)>1: + df=Soft_NMS(df) + + df=df.sort_values(by="score",ascending=False) + video_info=video_dict[video_name] + video_duration=float(video_info["duration_frame"]/16*16)/video_info["duration_frame"]*video_info["duration_second"] + proposal_list=[] + + for j in range(min(100,len(df))): + tmp_proposal={} + tmp_proposal["score"]=df.score.values[j] + tmp_proposal["segment"]=[max(0,df.xmin.values[j])*video_duration,min(1,df.xmax.values[j])*video_duration] + proposal_list.append(tmp_proposal) + result_dict[video_name[2:]]=proposal_list + + +def BSN_post_processing(): + video_dict=getDatasetDict() + video_list=video_dict.keys()#[:100] + video_list = list(video_list) + global result_dict + result_dict=mp.Manager().dict() + + num_videos = len(video_list) + num_videos_per_thread = num_videos/8 + processes = [] + for tid in range(7): + tmp_video_list = video_list[int(tid*num_videos_per_thread):int((tid+1)*num_videos_per_thread)] + p = mp.Process(target = video_post_process,args =(tmp_video_list,video_dict,)) + p.start() + processes.append(p) + tmp_video_list = video_list[int(7*num_videos_per_thread):] + p = mp.Process(target = video_post_process,args =(tmp_video_list,video_dict,)) + p.start() + processes.append(p) + for p in processes: + p.join() + + result_dict = dict(result_dict) + output_dict={"version":"VERSION 1.3","results":result_dict,"external_data":{}} + outfile=open("./output/result_proposal.json","w") + json.dump(output_dict,outfile) + outfile.close() + +if __name__ == '__main__': + if not os.path.exists("output/PEM_results"): + os.makedirs("output/PEM_results") + out_files = os.listdir(args.PEM_out_path) + print("processing...") + for i in range(len(out_files)): + video_name = str(out_files[i]) + video_name = video_name[0:int(len(video_name)-6)] + video_data = np.fromfile(args.PEM_out_path+'/'+out_files[i],dtype=np.float32) + + video_xmin = np.fromfile(args.PEM_video_xmin_path+'/'+video_name+'.bin',dtype=np.float64) + video_xmax = np.fromfile(args.PEM_video_xmax_path+'/'+video_name+'.bin',dtype=np.float64) + video_xmin_score = np.fromfile(args.PEM_video_xmin_score_path+'/'+video_name+'.bin',dtype=np.float64) + video_xmax_score = np.fromfile(args.PEM_video_xmax_score_path+'/'+video_name+'.bin',dtype=np.float64) + + video_data = torch.tensor(video_data) + video_xmin = torch.tensor(video_xmin) + video_xmax = torch.tensor(video_xmax) + video_xmin_score = torch.tensor(video_xmin_score) + video_xmax_score = torch.tensor(video_xmax_score) + data_num = int(video_xmin.shape[0]) + video_data = video_data[:data_num] + + video_data = video_data.view(-1).detach().cpu().numpy() + video_xmin = video_xmin.view(-1).cpu().numpy() + video_xmax = video_xmax.view(-1).cpu().numpy() + video_xmin_score = video_xmin_score.view(-1).cpu().numpy() + video_xmax_score = video_xmax_score.view(-1).cpu().numpy() + + df=pd.DataFrame() + df["xmin"]=video_xmin + df["xmax"]=video_xmax + df["xmin_score"]=video_xmin_score + df["xmax_score"]=video_xmax_score + df["iou_score"]=video_data + df.to_csv(args.result_path+'/'+video_name+".csv",index=False) + print("PGM: start generating BSN_post feature") + BSN_post_processing() print("PGM: finish generate BSN_post feature") \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/BSN/BSN_pem_preprocess.py b/ACL_PyTorch/contrib/cv/detection/BSN/BSN_pem_preprocess.py index 04d12cd6ad285a4aa95b8a388c980ee2161dfeea..575e1737fa7c78b3418dd9fb0750bb549d15ffce 100644 --- a/ACL_PyTorch/contrib/cv/detection/BSN/BSN_pem_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/BSN/BSN_pem_preprocess.py @@ -1,106 +1,106 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import numpy as np -import pandas as pd -import pandas -import numpy -import json -import torch.utils.data as data -import os -import torch -import os -#import opts -import sys - -#opt = opts.parse_opt() -#opt = vars(opt) -def load_json(file): - with open(file) as json_file: - data = json.load(json_file) - return data - -if __name__ == '__main__': - if not os.path.exists("output/BSN-PEM-preprocess/feature"): - os.makedirs("output/BSN-PEM-preprocess/feature") - if not os.path.exists("output/BSN-PEM-preprocess/xmin"): - os.makedirs("output/BSN-PEM-preprocess/xmin") - if not os.path.exists("output/BSN-PEM-preprocess/xmax"): - os.makedirs("output/BSN-PEM-preprocess/xmax") - if not os.path.exists("output/BSN-PEM-preprocess/xmin_score"): - os.makedirs("output/BSN-PEM-preprocess/xmin_score") - if not os.path.exists("output/BSN-PEM-preprocess/xmax_score"): - os.makedirs("output/BSN-PEM-preprocess/xmax_score") - subset = "validation" - top_K = 1000 - video_info_path = "BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/video_info_new.csv" - video_anno_path = "BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/anet_anno_action.json" - #video_info_path = opt["video_info"] - #video_anno_path = opt["video_anno"] - pgm_proposals_path = "output/PGM_proposals/" - pgm_feature_path = "output/PGM_feature/" - pem_feature_path ="output/BSN-PEM-preprocess/feature" - pem_xmin_path ="output/BSN-PEM-preprocess/xmin" - pem_xmax_path ="output/BSN-PEM-preprocess/xmax" - pem_xmin_score_path ="output/BSN-PEM-preprocess/xmin_score" - pem_xmax_score_path ="output/BSN-PEM-preprocess/xmax_score" - anno_df = pd.read_csv(video_info_path) - anno_database= load_json(video_anno_path) - video_dict = {} - for i in range(len(anno_df)): - video_name=anno_df.video.values[i] - video_info=anno_database[video_name] - video_subset=anno_df.subset.values[i] - #if subset == "full": - # video_dict[video_name] = video_info - if subset in video_subset: - video_dict[video_name] = video_info - video_list = list(video_dict.keys()) - print("%s subset video numbers: %d" %(subset,len(video_list))) - - print("processing...") - for i in range(len(video_list)): - video_name = video_list[i] - pdf=pandas.read_csv(pgm_proposals_path+video_name+".csv") - pdf=pdf[:top_K] - video_feature = numpy.load(pgm_feature_path + video_name+".npy") - video_feature = video_feature[:top_K,:] - video_feature = torch.Tensor(video_feature) - video_xmin =pdf.xmin.values[:] - video_xmax =pdf.xmax.values[:] - video_xmin_score = pdf.xmin_score.values[:] - video_xmax_score = pdf.xmax_score.values[:] - - #video_feature = np.array(video_feature).astype(np.float32) - #if not [1000,32] expend to [1000.32] - expend_num = 1000 - int(video_feature.shape[0]) - if expend_num != 0: - video_expend = torch.zeros(expend_num,32) - video_feature = torch.cat((video_feature,video_expend),0) - video_feature = np.array(video_feature).astype(np.float32) - video_feature.tofile(os.path.join(pem_feature_path, video_name + ".bin")) - - video_xmin = np.array(video_xmin) - video_xmax = np.array(video_xmax) - video_xmin_score = np.array(video_xmin_score) - video_xmax_score = np.array(video_xmax_score) - - video_xmin.tofile(os.path.join(pem_xmin_path, video_name + ".bin")) - video_xmax.tofile(os.path.join(pem_xmax_path, video_name + ".bin")) - video_xmin_score.tofile(os.path.join(pem_xmin_score_path, video_name + ".bin")) - video_xmax_score.tofile(os.path.join(pem_xmax_score_path, video_name + ".bin")) - - - - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import numpy as np +import pandas as pd +import pandas +import numpy +import json +import torch.utils.data as data +import os +import torch +import os +#import opts +import sys + +#opt = opts.parse_opt() +#opt = vars(opt) +def load_json(file): + with open(file) as json_file: + data = json.load(json_file) + return data + +if __name__ == '__main__': + if not os.path.exists("output/BSN-PEM-preprocess/feature"): + os.makedirs("output/BSN-PEM-preprocess/feature") + if not os.path.exists("output/BSN-PEM-preprocess/xmin"): + os.makedirs("output/BSN-PEM-preprocess/xmin") + if not os.path.exists("output/BSN-PEM-preprocess/xmax"): + os.makedirs("output/BSN-PEM-preprocess/xmax") + if not os.path.exists("output/BSN-PEM-preprocess/xmin_score"): + os.makedirs("output/BSN-PEM-preprocess/xmin_score") + if not os.path.exists("output/BSN-PEM-preprocess/xmax_score"): + os.makedirs("output/BSN-PEM-preprocess/xmax_score") + subset = "validation" + top_K = 1000 + video_info_path = "BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/video_info_new.csv" + video_anno_path = "BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/anet_anno_action.json" + #video_info_path = opt["video_info"] + #video_anno_path = opt["video_anno"] + pgm_proposals_path = "output/PGM_proposals/" + pgm_feature_path = "output/PGM_feature/" + pem_feature_path ="output/BSN-PEM-preprocess/feature" + pem_xmin_path ="output/BSN-PEM-preprocess/xmin" + pem_xmax_path ="output/BSN-PEM-preprocess/xmax" + pem_xmin_score_path ="output/BSN-PEM-preprocess/xmin_score" + pem_xmax_score_path ="output/BSN-PEM-preprocess/xmax_score" + anno_df = pd.read_csv(video_info_path) + anno_database= load_json(video_anno_path) + video_dict = {} + for i in range(len(anno_df)): + video_name=anno_df.video.values[i] + video_info=anno_database[video_name] + video_subset=anno_df.subset.values[i] + #if subset == "full": + # video_dict[video_name] = video_info + if subset in video_subset: + video_dict[video_name] = video_info + video_list = list(video_dict.keys()) + print("%s subset video numbers: %d" %(subset,len(video_list))) + + print("processing...") + for i in range(len(video_list)): + video_name = video_list[i] + pdf=pandas.read_csv(pgm_proposals_path+video_name+".csv") + pdf=pdf[:top_K] + video_feature = numpy.load(pgm_feature_path + video_name+".npy") + video_feature = video_feature[:top_K,:] + video_feature = torch.Tensor(video_feature) + video_xmin =pdf.xmin.values[:] + video_xmax =pdf.xmax.values[:] + video_xmin_score = pdf.xmin_score.values[:] + video_xmax_score = pdf.xmax_score.values[:] + + #video_feature = np.array(video_feature).astype(np.float32) + #if not [1000,32] expend to [1000.32] + expend_num = 1000 - int(video_feature.shape[0]) + if expend_num != 0: + video_expend = torch.zeros(expend_num,32) + video_feature = torch.cat((video_feature,video_expend),0) + video_feature = np.array(video_feature).astype(np.float32) + video_feature.tofile(os.path.join(pem_feature_path, video_name + ".bin")) + + video_xmin = np.array(video_xmin) + video_xmax = np.array(video_xmax) + video_xmin_score = np.array(video_xmin_score) + video_xmax_score = np.array(video_xmax_score) + + video_xmin.tofile(os.path.join(pem_xmin_path, video_name + ".bin")) + video_xmax.tofile(os.path.join(pem_xmax_path, video_name + ".bin")) + video_xmin_score.tofile(os.path.join(pem_xmin_score_path, video_name + ".bin")) + video_xmax_score.tofile(os.path.join(pem_xmax_score_path, video_name + ".bin")) + + + + + diff --git a/ACL_PyTorch/contrib/cv/detection/BSN/BSN_pem_pth2onnx.py b/ACL_PyTorch/contrib/cv/detection/BSN/BSN_pem_pth2onnx.py index 3b9f6d64330e6f6c08dc73a51c74b6b7d1ac2952..838b4c8868a276c9890f9a22a3d9b056b5660462 100644 --- a/ACL_PyTorch/contrib/cv/detection/BSN/BSN_pem_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/BSN/BSN_pem_pth2onnx.py @@ -1,66 +1,66 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import torch -import argparse -import sys -sys.path.append(r"./BSN-boundary-sensitive-network.pytorch") - -from models import PEM - -parser = argparse.ArgumentParser( - description='pem2onnx') -parser.add_argument('--pth_path', - default='./pem_best.pth.tar', - help='pth path') -parser.add_argument('--onnx_path', - default='./BSN_pem.onnx', - help='onnx path') -parser.add_argument( - '--pem_feat_dim', - type=int, - default=32) -parser.add_argument( - '--pem_hidden_dim', - type=int, - default=256) -parser.add_argument( - '--pem_batch_size', - type=int, - default=16) -parser.add_argument( - '--pem_u_ratio_m', - type=float, - default=1) -parser.add_argument( - '--pem_u_ratio_l', - type=float, - default=2) - - -def pem_onnx(opt): - opt = vars(opt) - pth_path = opt['pth_path'] - onnx_path = opt['onnx_path'] - model = PEM(opt) - checkpoint = torch.load(pth_path,map_location='cpu') - base_dict = {'.'.join(k.split('.')[1:]): v for k,v in list(checkpoint['state_dict'].items())} - model.load_state_dict(base_dict) - input_names=["video_feature"] - output_names = ["output"] - model.eval() - dummy_input = torch.randn(1,1000,32) - torch.onnx.export(model,dummy_input,onnx_path,input_names = input_names,output_names=output_names,verbose=True,opset_version=11) -if __name__ =="__main__": - opt = parser.parse_args() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import torch +import argparse +import sys +sys.path.append(r"./BSN-boundary-sensitive-network.pytorch") + +from models import PEM + +parser = argparse.ArgumentParser( + description='pem2onnx') +parser.add_argument('--pth_path', + default='./pem_best.pth.tar', + help='pth path') +parser.add_argument('--onnx_path', + default='./BSN_pem.onnx', + help='onnx path') +parser.add_argument( + '--pem_feat_dim', + type=int, + default=32) +parser.add_argument( + '--pem_hidden_dim', + type=int, + default=256) +parser.add_argument( + '--pem_batch_size', + type=int, + default=16) +parser.add_argument( + '--pem_u_ratio_m', + type=float, + default=1) +parser.add_argument( + '--pem_u_ratio_l', + type=float, + default=2) + + +def pem_onnx(opt): + opt = vars(opt) + pth_path = opt['pth_path'] + onnx_path = opt['onnx_path'] + model = PEM(opt) + checkpoint = torch.load(pth_path,map_location='cpu') + base_dict = {'.'.join(k.split('.')[1:]): v for k,v in list(checkpoint['state_dict'].items())} + model.load_state_dict(base_dict) + input_names=["video_feature"] + output_names = ["output"] + model.eval() + dummy_input = torch.randn(1,1000,32) + torch.onnx.export(model,dummy_input,onnx_path,input_names = input_names,output_names=output_names,verbose=True,opset_version=11) +if __name__ =="__main__": + opt = parser.parse_args() pem_onnx(opt) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/BSN/BSN_tem_postprocess.py b/ACL_PyTorch/contrib/cv/detection/BSN/BSN_tem_postprocess.py index 0c4eb2b17719f79eb02a5239f72212c4d625a0fc..de6f33cc8f065cfd957e935638bad3bdbef11e95 100644 --- a/ACL_PyTorch/contrib/cv/detection/BSN/BSN_tem_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/BSN/BSN_tem_postprocess.py @@ -1,313 +1,313 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import json -import torch -import hydra -import argparse -import os -import numpy as np -import pandas as pd -import numpy -import pandas -import torch.multiprocessing as mp -from scipy.interpolate import interp1d - - -parser = argparse.ArgumentParser(description='BSN') - -parser.add_argument('--result_path',default='./output/TEM_results', type=str, help='Dir to save txt results') -parser.add_argument('--TEM_out_path', default='./result/dumpOutput_device0', type=str, help='infer out path') -parser.add_argument('--TEM_anchor_xmin_path', default='./output/BSN-TEM-preprocess/anchor_min', type=str, help='infer info path') -parser.add_argument('--TEM_anchor_xmax_path', default='./output/BSN-TEM-preprocess/anchor_max', type=str, help='infer info path') - -args = parser.parse_args() - -columns=["action","start","end","xmin","xmax"] - -def load_json(file): - with open(file) as json_file: - data = json.load(json_file) - return data - -def iou_with_anchors(anchors_min,anchors_max,box_min,box_max): - """Compute jaccard score between a box and the anchors. - """ - len_anchors=anchors_max-anchors_min - int_xmin = numpy.maximum(anchors_min, box_min) - int_xmax = numpy.minimum(anchors_max, box_max) - inter_len = numpy.maximum(int_xmax - int_xmin, 0.) - union_len = len_anchors - inter_len +box_max-box_min - jaccard = numpy.divide(inter_len, union_len) - return jaccard - -def ioa_with_anchors(anchors_min,anchors_max,box_min,box_max): - """Compute intersection between score a box and the anchors. - """ - len_anchors=anchors_max-anchors_min - int_xmin = numpy.maximum(anchors_min, box_min) - int_xmax = numpy.minimum(anchors_max, box_max) - inter_len = numpy.maximum(int_xmax - int_xmin, 0.) - scores = numpy.divide(inter_len, len_anchors) - return scores - -def generateProposals(video_list,video_dict): - tscale = 100 - tgap = 1./tscale - peak_thres= 0.5 - - for video_name in video_list: - tdf=pandas.read_csv("./output/TEM_results/"+video_name+".csv") - start_scores=tdf.start.values[:] - end_scores=tdf.end.values[:] - - max_start = max(start_scores) - max_end = max(end_scores) - - start_bins=numpy.zeros(len(start_scores)) - start_bins[[0,-1]]=1 - for idx in range(1,tscale-1): - if start_scores[idx]>start_scores[idx+1] and start_scores[idx]>start_scores[idx-1]: - start_bins[idx]=1 - elif start_scores[idx]>(peak_thres*max_start): - start_bins[idx]=1 - - end_bins=numpy.zeros(len(end_scores)) - end_bins[[0,-1]]=1 - for idx in range(1,tscale-1): - if end_scores[idx]>end_scores[idx+1] and end_scores[idx]>end_scores[idx-1]: - end_bins[idx]=1 - elif end_scores[idx]>(peak_thres*max_end): - end_bins[idx]=1 - - xmin_list=[] - xmin_score_list=[] - xmax_list=[] - xmax_score_list=[] - for j in range(tscale): - if start_bins[j]==1: - xmin_list.append(tgap/2+tgap*j) - xmin_score_list.append(start_scores[j]) - if end_bins[j]==1: - xmax_list.append(tgap/2+tgap*j) - xmax_score_list.append(end_scores[j]) - - new_props=[] - for ii in range(len(xmax_list)): - tmp_xmax=xmax_list[ii] - tmp_xmax_score=xmax_score_list[ii] - - for ij in range(len(xmin_list)): - tmp_xmin=xmin_list[ij] - tmp_xmin_score=xmin_score_list[ij] - if tmp_xmin>=tmp_xmax: - break - new_props.append([tmp_xmin,tmp_xmax,tmp_xmin_score,tmp_xmax_score]) - new_props=numpy.stack(new_props) - - col_name=["xmin","xmax","xmin_score","xmax_score"] - new_df=pandas.DataFrame(new_props,columns=col_name) - new_df["score"]=new_df.xmin_score*new_df.xmax_score - - new_df=new_df.sort_values(by="score",ascending=False) - - video_info=video_dict[video_name] - video_frame=video_info['duration_frame'] - video_second=video_info['duration_second'] - feature_frame=video_info['feature_frame'] - corrected_second=float(feature_frame)/video_frame*video_second - - try: - gt_xmins=[] - gt_xmaxs=[] - for idx in range(len(video_info["annotations"])): - gt_xmins.append(video_info["annotations"][idx]["segment"][0]/corrected_second) - gt_xmaxs.append(video_info["annotations"][idx]["segment"][1]/corrected_second) - new_iou_list=[] - for j in range(len(new_df)): - tmp_new_iou=max(iou_with_anchors(new_df.xmin.values[j],new_df.xmax.values[j],gt_xmins,gt_xmaxs)) - new_iou_list.append(tmp_new_iou) - - new_ioa_list=[] - for j in range(len(new_df)): - tmp_new_ioa=max(ioa_with_anchors(new_df.xmin.values[j],new_df.xmax.values[j],gt_xmins,gt_xmaxs)) - new_ioa_list.append(tmp_new_ioa) - new_df["match_iou"]=new_iou_list - new_df["match_ioa"]=new_ioa_list - except: - pass - new_df.to_csv("./output/PGM_proposals/"+video_name+".csv",index=False) - - -def getDatasetDict(): - df=pandas.read_csv("./BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/video_info_new.csv") - json_data= load_json("./BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/anet_anno_action.json") - database=json_data - video_dict = {} - for i in range(len(df)): - video_name=df.video.values[i] - video_info=database[video_name] - video_new_info={} - video_new_info['duration_frame']=video_info['duration_frame'] - video_new_info['duration_second']=video_info['duration_second'] - video_new_info["feature_frame"]=video_info['feature_frame'] - video_new_info['annotations']=video_info['annotations'] - video_new_info['subset'] = df.subset.values[i] - video_dict[video_name]=video_new_info - return video_dict - -def generateFeature(video_list,video_dict): - - num_sample_start=8 - num_sample_end=8 - num_sample_action=16 - num_sample_interpld = 3 - - for video_name in video_list: - adf=pandas.read_csv("./output/TEM_results/"+video_name+".csv") - score_action=adf.action.values[:] - seg_xmins = adf.xmin.values[:] - seg_xmaxs = adf.xmax.values[:] - video_scale = len(adf) - video_gap = seg_xmaxs[0] - seg_xmins[0] - video_extend = video_scale / 4 + 10 - pdf=pandas.read_csv("./output/PGM_proposals/"+video_name+".csv") - video_subset = video_dict[video_name]['subset'] - if video_subset == "training": - pdf=pdf[:500] - else: - pdf=pdf[:1000] - tmp_zeros=numpy.zeros([int(video_extend)]) - score_action=numpy.concatenate((tmp_zeros,score_action,tmp_zeros)) - tmp_cell = video_gap - #print('video_extend:{}'.format(video_extend)) - tmp_x = [-tmp_cell/2-(video_extend-1-ii)*tmp_cell for ii in range(int(video_extend))] + \ - [tmp_cell/2+ii*tmp_cell for ii in range(int(video_scale))] + \ - [tmp_cell/2+seg_xmaxs[-1] +ii*tmp_cell for ii in range(int(video_extend))] - f_action=interp1d(tmp_x,score_action,axis=0) - feature_bsp=[] - - for idx in range(len(pdf)): - xmin=pdf.xmin.values[idx] - xmax=pdf.xmax.values[idx] - xlen=xmax-xmin - xmin_0=xmin-xlen * 0.2 - xmin_1=xmin+xlen * 0.2 - xmax_0=xmax-xlen * 0.2 - xmax_1=xmax+xlen * 0.2 - #start - plen_start= (xmin_1-xmin_0)/(num_sample_start-1) - plen_sample = plen_start / num_sample_interpld - tmp_x_new = [ xmin_0 - plen_start/2 + plen_sample * ii for ii in range(num_sample_start*num_sample_interpld +1 )] - tmp_y_new_start_action=f_action(tmp_x_new) - tmp_y_new_start = [numpy.mean(tmp_y_new_start_action[ii*num_sample_interpld:(ii+1)*num_sample_interpld+1]) for ii in range(num_sample_start) ] - #end - plen_end= (xmax_1-xmax_0)/(num_sample_end-1) - plen_sample = plen_end / num_sample_interpld - tmp_x_new = [ xmax_0 - plen_end/2 + plen_sample * ii for ii in range(num_sample_end*num_sample_interpld +1 )] - tmp_y_new_end_action=f_action(tmp_x_new) - tmp_y_new_end = [numpy.mean(tmp_y_new_end_action[ii*num_sample_interpld:(ii+1)*num_sample_interpld+1]) for ii in range(num_sample_end) ] - #action - plen_action= (xmax-xmin)/(num_sample_action-1) - plen_sample = plen_action / num_sample_interpld - tmp_x_new = [ xmin - plen_action/2 + plen_sample * ii for ii in range(num_sample_action*num_sample_interpld +1 )] - tmp_y_new_action=f_action(tmp_x_new) - tmp_y_new_action = [numpy.mean(tmp_y_new_action[ii*num_sample_interpld:(ii+1)*num_sample_interpld+1]) for ii in range(num_sample_action) ] - tmp_feature = numpy.concatenate([tmp_y_new_action,tmp_y_new_start,tmp_y_new_end]) - feature_bsp.append(tmp_feature) - feature_bsp = numpy.array(feature_bsp) - numpy.save("./output/PGM_feature/"+video_name,feature_bsp) - - - -def PGM_proposal_generation(): - video_dict= load_json("./BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/anet_anno_action.json") - video_list=video_dict.keys()#[:199] - video_list = list(video_list) - num_videos = len(video_list) - num_videos_per_thread = num_videos/8 - processes = [] - for tid in range(7): - tmp_video_list = video_list[int(tid*num_videos_per_thread):int((tid+1)*num_videos_per_thread)] - p = mp.Process(target = generateProposals,args =(tmp_video_list,video_dict,)) - p.start() - processes.append(p) - - tmp_video_list = video_list[int(7*num_videos_per_thread):] - p = mp.Process(target = generateProposals,args =(tmp_video_list,video_dict,)) - p.start() - processes.append(p) - - for p in processes: - p.join() -def PGM_feature_generation(): - video_dict=getDatasetDict() - video_list=video_dict.keys() - video_list = list(video_list) - num_videos = len(video_list) - num_videos_per_thread = num_videos/8 - processes = [] - for tid in range(7): - tmp_video_list = video_list[int(tid*num_videos_per_thread):int((tid+1)*num_videos_per_thread)] - p = mp.Process(target = generateFeature,args =(tmp_video_list,video_dict,)) - p.start() - processes.append(p) - - tmp_video_list = video_list[int(7*num_videos_per_thread):] - p = mp.Process(target = generateFeature,args =(tmp_video_list,video_dict,)) - p.start() - processes.append(p) - - for p in processes: - p.join() - -if __name__ == '__main__': - out_files = os.listdir(args.TEM_out_path) - if not os.path.exists("output/TEM_results"): - os.makedirs("output/TEM_results") - print("processing...") - for i in range(len(out_files)): - video_name = str(out_files[i]) - video_name = video_name[0:int(len(video_name)-6)] - video_data = np.fromfile(args.TEM_out_path+'/'+out_files[i],dtype=np.float32) - #print(video_data) - video_data = torch.tensor(video_data.reshape(1,3,100)) - #video_data.reshape(1,3,1000) - video_data = video_data.detach().cpu().numpy() - - anchor_xmin = np.fromfile(args.TEM_anchor_xmin_path+'/'+video_name+'.bin',dtype=np.float64) - anchor_xmax = np.fromfile(args.TEM_anchor_xmax_path+'/'+video_name+'.bin',dtype=np.float64) - - anchor_xmin = torch.tensor(anchor_xmin) - anchor_xmax = torch.tensor(anchor_xmax) - video_action = video_data[:,0,:] - video_start = video_data[:,1,:] - video_end = video_data[:,2,:] - - video_result = np.stack((video_action[0],video_start[0],video_end[0],anchor_xmin,anchor_xmax),axis=1) - - video_df = pd.DataFrame(video_result,columns=columns) - video_df.to_csv(args.result_path+"/"+video_name+".csv",index=False) - - if not os.path.exists("output/PGM_proposals"): - os.makedirs("output/PGM_proposals") - print("PGM: start generating proposals") - PGM_proposal_generation() - print("PGM: finish generate proposals") - - if not os.path.exists("output/PGM_feature"): - os.makedirs("output/PGM_feature") - print("PGM: start generating BSP feature") - PGM_feature_generation() - print("PGM: finish generate BSP feature") +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import json +import torch +import hydra +import argparse +import os +import numpy as np +import pandas as pd +import numpy +import pandas +import torch.multiprocessing as mp +from scipy.interpolate import interp1d + + +parser = argparse.ArgumentParser(description='BSN') + +parser.add_argument('--result_path',default='./output/TEM_results', type=str, help='Dir to save txt results') +parser.add_argument('--TEM_out_path', default='./result/dumpOutput_device0', type=str, help='infer out path') +parser.add_argument('--TEM_anchor_xmin_path', default='./output/BSN-TEM-preprocess/anchor_min', type=str, help='infer info path') +parser.add_argument('--TEM_anchor_xmax_path', default='./output/BSN-TEM-preprocess/anchor_max', type=str, help='infer info path') + +args = parser.parse_args() + +columns=["action","start","end","xmin","xmax"] + +def load_json(file): + with open(file) as json_file: + data = json.load(json_file) + return data + +def iou_with_anchors(anchors_min,anchors_max,box_min,box_max): + """Compute jaccard score between a box and the anchors. + """ + len_anchors=anchors_max-anchors_min + int_xmin = numpy.maximum(anchors_min, box_min) + int_xmax = numpy.minimum(anchors_max, box_max) + inter_len = numpy.maximum(int_xmax - int_xmin, 0.) + union_len = len_anchors - inter_len +box_max-box_min + jaccard = numpy.divide(inter_len, union_len) + return jaccard + +def ioa_with_anchors(anchors_min,anchors_max,box_min,box_max): + """Compute intersection between score a box and the anchors. + """ + len_anchors=anchors_max-anchors_min + int_xmin = numpy.maximum(anchors_min, box_min) + int_xmax = numpy.minimum(anchors_max, box_max) + inter_len = numpy.maximum(int_xmax - int_xmin, 0.) + scores = numpy.divide(inter_len, len_anchors) + return scores + +def generateProposals(video_list,video_dict): + tscale = 100 + tgap = 1./tscale + peak_thres= 0.5 + + for video_name in video_list: + tdf=pandas.read_csv("./output/TEM_results/"+video_name+".csv") + start_scores=tdf.start.values[:] + end_scores=tdf.end.values[:] + + max_start = max(start_scores) + max_end = max(end_scores) + + start_bins=numpy.zeros(len(start_scores)) + start_bins[[0,-1]]=1 + for idx in range(1,tscale-1): + if start_scores[idx]>start_scores[idx+1] and start_scores[idx]>start_scores[idx-1]: + start_bins[idx]=1 + elif start_scores[idx]>(peak_thres*max_start): + start_bins[idx]=1 + + end_bins=numpy.zeros(len(end_scores)) + end_bins[[0,-1]]=1 + for idx in range(1,tscale-1): + if end_scores[idx]>end_scores[idx+1] and end_scores[idx]>end_scores[idx-1]: + end_bins[idx]=1 + elif end_scores[idx]>(peak_thres*max_end): + end_bins[idx]=1 + + xmin_list=[] + xmin_score_list=[] + xmax_list=[] + xmax_score_list=[] + for j in range(tscale): + if start_bins[j]==1: + xmin_list.append(tgap/2+tgap*j) + xmin_score_list.append(start_scores[j]) + if end_bins[j]==1: + xmax_list.append(tgap/2+tgap*j) + xmax_score_list.append(end_scores[j]) + + new_props=[] + for ii in range(len(xmax_list)): + tmp_xmax=xmax_list[ii] + tmp_xmax_score=xmax_score_list[ii] + + for ij in range(len(xmin_list)): + tmp_xmin=xmin_list[ij] + tmp_xmin_score=xmin_score_list[ij] + if tmp_xmin>=tmp_xmax: + break + new_props.append([tmp_xmin,tmp_xmax,tmp_xmin_score,tmp_xmax_score]) + new_props=numpy.stack(new_props) + + col_name=["xmin","xmax","xmin_score","xmax_score"] + new_df=pandas.DataFrame(new_props,columns=col_name) + new_df["score"]=new_df.xmin_score*new_df.xmax_score + + new_df=new_df.sort_values(by="score",ascending=False) + + video_info=video_dict[video_name] + video_frame=video_info['duration_frame'] + video_second=video_info['duration_second'] + feature_frame=video_info['feature_frame'] + corrected_second=float(feature_frame)/video_frame*video_second + + try: + gt_xmins=[] + gt_xmaxs=[] + for idx in range(len(video_info["annotations"])): + gt_xmins.append(video_info["annotations"][idx]["segment"][0]/corrected_second) + gt_xmaxs.append(video_info["annotations"][idx]["segment"][1]/corrected_second) + new_iou_list=[] + for j in range(len(new_df)): + tmp_new_iou=max(iou_with_anchors(new_df.xmin.values[j],new_df.xmax.values[j],gt_xmins,gt_xmaxs)) + new_iou_list.append(tmp_new_iou) + + new_ioa_list=[] + for j in range(len(new_df)): + tmp_new_ioa=max(ioa_with_anchors(new_df.xmin.values[j],new_df.xmax.values[j],gt_xmins,gt_xmaxs)) + new_ioa_list.append(tmp_new_ioa) + new_df["match_iou"]=new_iou_list + new_df["match_ioa"]=new_ioa_list + except: + pass + new_df.to_csv("./output/PGM_proposals/"+video_name+".csv",index=False) + + +def getDatasetDict(): + df=pandas.read_csv("./BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/video_info_new.csv") + json_data= load_json("./BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/anet_anno_action.json") + database=json_data + video_dict = {} + for i in range(len(df)): + video_name=df.video.values[i] + video_info=database[video_name] + video_new_info={} + video_new_info['duration_frame']=video_info['duration_frame'] + video_new_info['duration_second']=video_info['duration_second'] + video_new_info["feature_frame"]=video_info['feature_frame'] + video_new_info['annotations']=video_info['annotations'] + video_new_info['subset'] = df.subset.values[i] + video_dict[video_name]=video_new_info + return video_dict + +def generateFeature(video_list,video_dict): + + num_sample_start=8 + num_sample_end=8 + num_sample_action=16 + num_sample_interpld = 3 + + for video_name in video_list: + adf=pandas.read_csv("./output/TEM_results/"+video_name+".csv") + score_action=adf.action.values[:] + seg_xmins = adf.xmin.values[:] + seg_xmaxs = adf.xmax.values[:] + video_scale = len(adf) + video_gap = seg_xmaxs[0] - seg_xmins[0] + video_extend = video_scale / 4 + 10 + pdf=pandas.read_csv("./output/PGM_proposals/"+video_name+".csv") + video_subset = video_dict[video_name]['subset'] + if video_subset == "training": + pdf=pdf[:500] + else: + pdf=pdf[:1000] + tmp_zeros=numpy.zeros([int(video_extend)]) + score_action=numpy.concatenate((tmp_zeros,score_action,tmp_zeros)) + tmp_cell = video_gap + #print('video_extend:{}'.format(video_extend)) + tmp_x = [-tmp_cell/2-(video_extend-1-ii)*tmp_cell for ii in range(int(video_extend))] + \ + [tmp_cell/2+ii*tmp_cell for ii in range(int(video_scale))] + \ + [tmp_cell/2+seg_xmaxs[-1] +ii*tmp_cell for ii in range(int(video_extend))] + f_action=interp1d(tmp_x,score_action,axis=0) + feature_bsp=[] + + for idx in range(len(pdf)): + xmin=pdf.xmin.values[idx] + xmax=pdf.xmax.values[idx] + xlen=xmax-xmin + xmin_0=xmin-xlen * 0.2 + xmin_1=xmin+xlen * 0.2 + xmax_0=xmax-xlen * 0.2 + xmax_1=xmax+xlen * 0.2 + #start + plen_start= (xmin_1-xmin_0)/(num_sample_start-1) + plen_sample = plen_start / num_sample_interpld + tmp_x_new = [ xmin_0 - plen_start/2 + plen_sample * ii for ii in range(num_sample_start*num_sample_interpld +1 )] + tmp_y_new_start_action=f_action(tmp_x_new) + tmp_y_new_start = [numpy.mean(tmp_y_new_start_action[ii*num_sample_interpld:(ii+1)*num_sample_interpld+1]) for ii in range(num_sample_start) ] + #end + plen_end= (xmax_1-xmax_0)/(num_sample_end-1) + plen_sample = plen_end / num_sample_interpld + tmp_x_new = [ xmax_0 - plen_end/2 + plen_sample * ii for ii in range(num_sample_end*num_sample_interpld +1 )] + tmp_y_new_end_action=f_action(tmp_x_new) + tmp_y_new_end = [numpy.mean(tmp_y_new_end_action[ii*num_sample_interpld:(ii+1)*num_sample_interpld+1]) for ii in range(num_sample_end) ] + #action + plen_action= (xmax-xmin)/(num_sample_action-1) + plen_sample = plen_action / num_sample_interpld + tmp_x_new = [ xmin - plen_action/2 + plen_sample * ii for ii in range(num_sample_action*num_sample_interpld +1 )] + tmp_y_new_action=f_action(tmp_x_new) + tmp_y_new_action = [numpy.mean(tmp_y_new_action[ii*num_sample_interpld:(ii+1)*num_sample_interpld+1]) for ii in range(num_sample_action) ] + tmp_feature = numpy.concatenate([tmp_y_new_action,tmp_y_new_start,tmp_y_new_end]) + feature_bsp.append(tmp_feature) + feature_bsp = numpy.array(feature_bsp) + numpy.save("./output/PGM_feature/"+video_name,feature_bsp) + + + +def PGM_proposal_generation(): + video_dict= load_json("./BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/anet_anno_action.json") + video_list=video_dict.keys()#[:199] + video_list = list(video_list) + num_videos = len(video_list) + num_videos_per_thread = num_videos/8 + processes = [] + for tid in range(7): + tmp_video_list = video_list[int(tid*num_videos_per_thread):int((tid+1)*num_videos_per_thread)] + p = mp.Process(target = generateProposals,args =(tmp_video_list,video_dict,)) + p.start() + processes.append(p) + + tmp_video_list = video_list[int(7*num_videos_per_thread):] + p = mp.Process(target = generateProposals,args =(tmp_video_list,video_dict,)) + p.start() + processes.append(p) + + for p in processes: + p.join() +def PGM_feature_generation(): + video_dict=getDatasetDict() + video_list=video_dict.keys() + video_list = list(video_list) + num_videos = len(video_list) + num_videos_per_thread = num_videos/8 + processes = [] + for tid in range(7): + tmp_video_list = video_list[int(tid*num_videos_per_thread):int((tid+1)*num_videos_per_thread)] + p = mp.Process(target = generateFeature,args =(tmp_video_list,video_dict,)) + p.start() + processes.append(p) + + tmp_video_list = video_list[int(7*num_videos_per_thread):] + p = mp.Process(target = generateFeature,args =(tmp_video_list,video_dict,)) + p.start() + processes.append(p) + + for p in processes: + p.join() + +if __name__ == '__main__': + out_files = os.listdir(args.TEM_out_path) + if not os.path.exists("output/TEM_results"): + os.makedirs("output/TEM_results") + print("processing...") + for i in range(len(out_files)): + video_name = str(out_files[i]) + video_name = video_name[0:int(len(video_name)-6)] + video_data = np.fromfile(args.TEM_out_path+'/'+out_files[i],dtype=np.float32) + #print(video_data) + video_data = torch.tensor(video_data.reshape(1,3,100)) + #video_data.reshape(1,3,1000) + video_data = video_data.detach().cpu().numpy() + + anchor_xmin = np.fromfile(args.TEM_anchor_xmin_path+'/'+video_name+'.bin',dtype=np.float64) + anchor_xmax = np.fromfile(args.TEM_anchor_xmax_path+'/'+video_name+'.bin',dtype=np.float64) + + anchor_xmin = torch.tensor(anchor_xmin) + anchor_xmax = torch.tensor(anchor_xmax) + video_action = video_data[:,0,:] + video_start = video_data[:,1,:] + video_end = video_data[:,2,:] + + video_result = np.stack((video_action[0],video_start[0],video_end[0],anchor_xmin,anchor_xmax),axis=1) + + video_df = pd.DataFrame(video_result,columns=columns) + video_df.to_csv(args.result_path+"/"+video_name+".csv",index=False) + + if not os.path.exists("output/PGM_proposals"): + os.makedirs("output/PGM_proposals") + print("PGM: start generating proposals") + PGM_proposal_generation() + print("PGM: finish generate proposals") + + if not os.path.exists("output/PGM_feature"): + os.makedirs("output/PGM_feature") + print("PGM: start generating BSP feature") + PGM_feature_generation() + print("PGM: finish generate BSP feature") \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/BSN/BSN_tem_preprocess.py b/ACL_PyTorch/contrib/cv/detection/BSN/BSN_tem_preprocess.py index b6639216bfd21201bdb0ceb2cef1d6acdd68467b..328411466dbbb98beebeea4fa626228359f2fb76 100644 --- a/ACL_PyTorch/contrib/cv/detection/BSN/BSN_tem_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/BSN/BSN_tem_preprocess.py @@ -1,75 +1,75 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import numpy as np -import pandas as pd -import pandas -import numpy -import json -import torch.utils.data as data -import os -import torch -import sys - -def load_json(file): - with open(file) as json_file: - data = json.load(json_file) - return data -if __name__ == '__main__': - if not os.path.exists("output/BSN-TEM-preprocess/anchor_min"): - os.makedirs("output/BSN-TEM-preprocess/anchor_min") - if not os.path.exists("output/BSN-TEM-preprocess/anchor_max"): - os.makedirs("output/BSN-TEM-preprocess/anchor_max") - if not os.path.exists("output/BSN-TEM-preprocess/feature"): - os.makedirs("output/BSN-TEM-preprocess/feature") - feature_path = "BSN-boundary-sensitive-network.pytorch/data/activitynet_feature_cuhk/" - video_info_path = "BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/video_info_new.csv" - video_anno_path = "BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/anet_anno_action.json" - temporal_scale = 100 - temporal_gap = 1. / temporal_scale - subset = "full" - boundary_ratio = 0.1 - anno_df = pd.read_csv(video_info_path) - anno_database= load_json(video_anno_path) - video_dict = {} - for i in range(len(anno_df)): - video_name=anno_df.video.values[i] - video_info=anno_database[video_name] - video_subset=anno_df.subset.values[i] - if subset == "full": - video_dict[video_name] = video_info - if subset in video_subset: - video_dict[video_name] = video_info - video_list = list(video_dict.keys()) - print("%s subset video numbers: %d" %(subset,len(video_list))) - - print("processing...") - for i in range(len(video_list)): - video_name=video_list[i] - anchor_xmin=[temporal_gap*i for i in range(temporal_scale)] - anchor_xmax=[temporal_gap*i for i in range(1,temporal_scale+1)] - video_df=pd.read_csv(feature_path+ "csv_mean_"+str(temporal_scale)+"/"+video_name+".csv") - video_data = video_df.values[:,:] - video_data = torch.Tensor(video_data) - video_data = torch.transpose(video_data,0,1) - video_data.float() - video_data = np.array(video_data).astype(np.float32) - video_data.tofile(os.path.join('./output/BSN-TEM-preprocess/feature/', video_name + ".bin")) - - anchor_xmin = np.array(anchor_xmin) - anchor_xmax = np.array(anchor_xmax) - anchor_xmin.tofile(os.path.join('./output/BSN-TEM-preprocess/anchor_min/', video_name + ".bin")) - anchor_xmax.tofile(os.path.join('./output/BSN-TEM-preprocess/anchor_max/', video_name + ".bin")) - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import numpy as np +import pandas as pd +import pandas +import numpy +import json +import torch.utils.data as data +import os +import torch +import sys + +def load_json(file): + with open(file) as json_file: + data = json.load(json_file) + return data +if __name__ == '__main__': + if not os.path.exists("output/BSN-TEM-preprocess/anchor_min"): + os.makedirs("output/BSN-TEM-preprocess/anchor_min") + if not os.path.exists("output/BSN-TEM-preprocess/anchor_max"): + os.makedirs("output/BSN-TEM-preprocess/anchor_max") + if not os.path.exists("output/BSN-TEM-preprocess/feature"): + os.makedirs("output/BSN-TEM-preprocess/feature") + feature_path = "BSN-boundary-sensitive-network.pytorch/data/activitynet_feature_cuhk/" + video_info_path = "BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/video_info_new.csv" + video_anno_path = "BSN-boundary-sensitive-network.pytorch/data/activitynet_annotations/anet_anno_action.json" + temporal_scale = 100 + temporal_gap = 1. / temporal_scale + subset = "full" + boundary_ratio = 0.1 + anno_df = pd.read_csv(video_info_path) + anno_database= load_json(video_anno_path) + video_dict = {} + for i in range(len(anno_df)): + video_name=anno_df.video.values[i] + video_info=anno_database[video_name] + video_subset=anno_df.subset.values[i] + if subset == "full": + video_dict[video_name] = video_info + if subset in video_subset: + video_dict[video_name] = video_info + video_list = list(video_dict.keys()) + print("%s subset video numbers: %d" %(subset,len(video_list))) + + print("processing...") + for i in range(len(video_list)): + video_name=video_list[i] + anchor_xmin=[temporal_gap*i for i in range(temporal_scale)] + anchor_xmax=[temporal_gap*i for i in range(1,temporal_scale+1)] + video_df=pd.read_csv(feature_path+ "csv_mean_"+str(temporal_scale)+"/"+video_name+".csv") + video_data = video_df.values[:,:] + video_data = torch.Tensor(video_data) + video_data = torch.transpose(video_data,0,1) + video_data.float() + video_data = np.array(video_data).astype(np.float32) + video_data.tofile(os.path.join('./output/BSN-TEM-preprocess/feature/', video_name + ".bin")) + + anchor_xmin = np.array(anchor_xmin) + anchor_xmax = np.array(anchor_xmax) + anchor_xmin.tofile(os.path.join('./output/BSN-TEM-preprocess/anchor_min/', video_name + ".bin")) + anchor_xmax.tofile(os.path.join('./output/BSN-TEM-preprocess/anchor_max/', video_name + ".bin")) + + \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/BSN/BSN_tem_pth2onnx.py b/ACL_PyTorch/contrib/cv/detection/BSN/BSN_tem_pth2onnx.py index fbb5247a8a20a171d6af0f5cc22990607014b313..3b9bd12c35b43238e533b9725d89fca02e3dabd0 100644 --- a/ACL_PyTorch/contrib/cv/detection/BSN/BSN_tem_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/BSN/BSN_tem_pth2onnx.py @@ -1,64 +1,64 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import argparse -import torch -import sys -sys.path.append(r"./BSN-boundary-sensitive-network.pytorch") - -from models import TEM - -parser = argparse.ArgumentParser( - description='tem2onnx') -parser.add_argument('--pth_path', - default='./tem_best.pth.tar', - help='pth path') -parser.add_argument('--onnx_path', - default='./BSN_tem.onnx', - help='onnx path') -parser.add_argument( - '--tem_feat_dim', - type=int, - default=400) -parser.add_argument( - '--tem_hidden_dim', - type=int, - default=512) -parser.add_argument( - '--tem_batch_size', - type=int, - default=16) -parser.add_argument( - '--temporal_scale', - type=int, - default=100) -opt = parser.parse_args() - -def pth_onnx(opt): - - - opt = vars(opt) - pth_path = opt['pth_path'] - onnx_path = opt['onnx_path'] - model = TEM(opt) - checkpoint = torch.load(pth_path,map_location='cpu') - base_dict = {'.'.join(k.split('.')[1:]): v for k,v in list(checkpoint['state_dict'].items())} - model.load_state_dict(base_dict) - input_names=["video"] - output_names = ["output"] - model.eval() - dummy_input = torch.randn(1,400,100) - torch.onnx.export(model,dummy_input,onnx_path,input_names = input_names,output_names=output_names,verbose=True,opset_version=11) -if __name__ =="__main__": - opt = parser.parse_args() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import argparse +import torch +import sys +sys.path.append(r"./BSN-boundary-sensitive-network.pytorch") + +from models import TEM + +parser = argparse.ArgumentParser( + description='tem2onnx') +parser.add_argument('--pth_path', + default='./tem_best.pth.tar', + help='pth path') +parser.add_argument('--onnx_path', + default='./BSN_tem.onnx', + help='onnx path') +parser.add_argument( + '--tem_feat_dim', + type=int, + default=400) +parser.add_argument( + '--tem_hidden_dim', + type=int, + default=512) +parser.add_argument( + '--tem_batch_size', + type=int, + default=16) +parser.add_argument( + '--temporal_scale', + type=int, + default=100) +opt = parser.parse_args() + +def pth_onnx(opt): + + + opt = vars(opt) + pth_path = opt['pth_path'] + onnx_path = opt['onnx_path'] + model = TEM(opt) + checkpoint = torch.load(pth_path,map_location='cpu') + base_dict = {'.'.join(k.split('.')[1:]): v for k,v in list(checkpoint['state_dict'].items())} + model.load_state_dict(base_dict) + input_names=["video"] + output_names = ["output"] + model.eval() + dummy_input = torch.randn(1,400,100) + torch.onnx.export(model,dummy_input,onnx_path,input_names = input_names,output_names=output_names,verbose=True,opset_version=11) +if __name__ =="__main__": + opt = parser.parse_args() pth_onnx(opt) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/BSN/README.md b/ACL_PyTorch/contrib/cv/detection/BSN/README.md index 66ee1c7705d2d51a3542015f126bd6ed6f982786..7892ad2b7e86fe2c48285ffaa995213f04bd32da 100644 --- a/ACL_PyTorch/contrib/cv/detection/BSN/README.md +++ b/ACL_PyTorch/contrib/cv/detection/BSN/README.md @@ -1,450 +1,450 @@ -# BSN推理说明 - - - -## 1、 环境说明 - -1、安装必要的依赖 - -``` -apex 0.1+ascend.20210930 -certifi 2021.10.8 -cycler 0.11.0 -decorator 5.1.0 -docutils 0.18 -flatbuffers 2.0 -future 0.18.2 -Geohash 1.0 -Hydra 2.5 -kiwisolver 1.3.2 -matplotlib 3.4.3 -mpmath 1.2.1 -numpy 1.21.0 -onnx 1.10.2 -onnxruntime 1.9.0 -pandas 1.3.4 -Pillow 8.4.0 -pip 21.3.1 -protobuf 3.19.1 -pyparsing 3.0.6 -python-dateutil 2.8.2 -pytz 2021.3 -scipy 1.7.2 -setuptools 58.0.4 -six 1.16.0 -sympy 1.9 -torch 1.5.0+ascend.post3.20210930 -typing-extensions 3.10.0.2 -wheel 0.37.0 -``` - -2、获取开源代码 - -直接从githup上git clone 可能无法clone成功,建议先把githup上的仓先导入到git,再clone - -``` -git clone https://github.com/wzmsltw/BSN-boundary-sensitive-network.pytorch -``` - - - -3、获取onnx_tools,优化TEM的onnx模型 - -``` -git clone https://gitee.com/zheng-wengang1/onnx_tools -``` - - - -4、下载视频特征数据集 - -请参考源代码仓 - -5、代码目录 - -``` -BSN #模型名称命名的文件夹 -├── BSN-boundary-sensitive-network.pytorch #BSN开源代码 - └── data - ├── activitynet_feature_cuhk - ├── csv_mean_100 #下载数据特征集 -├── env.sh #环境变量 -├── BSN_tem_pth2onnx.py #tem模型转换脚本 -├── BSN_pem_pth2onnx.py #pem模型转换脚本 -├── BSN_tem_preprocess.py #tem模型前处理脚本 -├── BSN_pem_preprocess.py #pem模型前处理脚本 -├── gen_dataset_info.py #生成数据集info文件 -├── BSN_tem_postprocess.py #tem模型后处理脚本 -├── BSN_pem_postprocess.py #pem模型后处理脚本 -├── BSN_eval.py #测试精度脚本 -├── TEM_onnx_conv1d2conv2d.py #tem模型onnx,conv1d算子转conv2d算子优化脚本 -├── requirements.txt #模型离线推理用到的所有且必要的依赖库 -├── README.md #模型离线推理说明README -├── modelzoo_level.txt #模型精度性能结果 -└── test - ├── pth2om.sh - ├── eval_acc_perf.sh - ├── parse.py -``` - - - -## 2、离线推理 - -1、pth权重转onnx - - - -TEM的pth权重转onnx,参数pth_path为TEM模型权重文件所在位置,onnx_path为输出的onnx模型位置 - -``` -python BSN_tem_pth2onnx.py --pth_path './tem_best.pth.tar' --onnx_path './BSN_tem.onnx' -``` - -tem-onnx模型优化,第一个参数为原本onnx模型位置,第二个参数为输出onnx模型 - -``` -python TEM_onnx_conv1d2conv2d.py './BSN_tem.onnx' './BSN_tem1.onnx' -``` - -PEM的pth权重转onnx,参数pth_path为PEM模型权重文件所在位置,onnx_path为输出的onnx模型位置 - -``` -python BSN_pem_pth2onnx.py --pth_path './pem_best.pth.tar' --onnx_path './BSN_pem.onnx' -``` - - - -2、onnx模型转om - -使用atc工具将onnx模型转为om模型,注意应当先设置环境变量 - -``` -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest - -atc --framework=5 --model=BSN_tem1.onnx --output=BSN_tem_bs1 --input_format=ND --input_shape="video:1,400,100" --log=debug --soc_version=Ascend310 - -atc --framework=5 --model=BSN_pem.onnx --output=BSN_pem_bs1 --input_format=ND --input_shape="video_feature:1,1000,32" --log=debug --soc_version=Ascend310 -``` - - - -3、TEM推理 - -运行预处理脚本,运行前确保你已经clone了开源代码,并下载数据特征集 - -``` -python BSN_tem_preprocess.py -``` - -获取处理数据集信息,第一个参数为模型类型,第二个参数为特征文件位置,第三个参数为输出文件名,第四、五个参数为特征形状(400*100) - -``` -python gen_dataset_info.py tem /home/wch/BSN/BSN-TEM-preprocess/feature TEM-video-feature 400 100 -``` - -使用benchmark工具进行推理,生成的数据文件会放在当前路径的result/dumpOutput_device0目录下 - -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=BSN_tem_bs1.om -input_text_path=./TEM-video-feature.info -input_width=400 -input_height=100 -output_binary=True -useDvpp=False -``` - -使用BSN_tem_postprocess.py进行tem后处理(tem的后处理与pem的前处理有关请按照顺序执行) - -``` -python BSN_tem_postprocess.py --TEM_out_path ./result/dumpOutput_device0 -``` - - - -4、PEM推理 - -运行pem预处理脚本(pem的前处理与tem的后处理有关请按照顺序执行) - -``` -python BSN_pem_preprocess.py -``` - -获取处理数据集信息,第一个参数为模型类型,第二个参数为特征文件位置,第三个参数为输出文件名,第四、五个参数为特征形状(1000*32) - -``` -python get_info.py pem output/BSN-PEM-preprocess/feature PEM-video-feature 1000 32 -``` - -使用benchmark工具进行推理,生成的数据文件会放在当前路径的result/dumpOutput_device1目录下 - -``` -./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=1 -om_path=BSN_pem_bs1.om -input_text_path=./PEM-video-feature.info -input_width=1000 -input_height=32 -output_binary=True -useDvpp=False -``` - -运行后处理脚本,会在output目录下生成结果文件 - -``` -python BSN_pem_postprocess.py --PEM_out_path result/dumpOutput_device1 -``` - - - -5、精度测试 - -原本代码仓的代码是python2的代码,在在使用前需要转为python3 - -``` -2to3 -w ./BSN-boundary-sensitive-network.pytorch/Evaluation/eval_proposal.py - -``` - -精度测试 - -``` -python BSN_eval.py -``` - - - -6、整体测试 - -运行脚本,直接转om模型 - -``` -bash ./test/pth2om.sh -``` - -运行脚本,进行离线推理,运行脚本前,请确保已经将源代码中使用的文件,转为python3 - -``` -bash ./test/eval_acc_perf.sh -``` - - - -## 3 精度性能对比 - -### 1、精度对比 - -​ pth精度 - -``` -Model 论文 开源pth文件 离线推理精度 -BSN AR100:72.42 74.34 74.34 -``` - -### 2、性能对比 - -#### 2.1 npu性能数据 - -tem bs1性能数据 - -``` ------------------Performance Summary------------------ -[e2e] throughputRate: 180.879, latency: 106303 -[data read] throughputRate: 182.039, moduleLatency: 5.49332 -[preprocess] throughputRate: 181.865, moduleLatency: 5.49859 -[inference] throughputRate: 182, Interface throughputRate: 3275.55, moduleLatency: 0.561457 -[postprocess] throughputRate: 182.009, moduleLatency: 5.49425 - ------------------------------------------------------------ -``` - -pem bs1性能数据 - -``` ------------------Performance Summary------------------ -[e2e] throughputRate: 616.804, latency: 7665.32 -[data read] throughputRate: 1840.06, moduleLatency: 0.54346 -[preprocess] throughputRate: 1817.62, moduleLatency: 0.550169 -[inference] throughputRate: 1839.62, Interface throughputRate: 3874.46, moduleLatency: 0.469866 -[postprocess] throughputRate: 1839.86, moduleLatency: 0.543521 - ------------------------------------------------------------ -``` - -tem单卡吞吐率:3275.55x4=13102.2 - -pem单卡吞吐率:3874.46x4=15497.84 - -BSN整体吞吐率为:1/(1/13102.2+1/15497.84)=7099.87 - - - -tem bs16性能数据 - -``` ------------------Performance Summary------------------ -[e2e] throughputRate: 143.161, latency: 134310 -[data read] throughputRate: 144.544, moduleLatency: 6.91832 -[preprocess] throughputRate: 144.393, moduleLatency: 6.92554 -[inference] throughputRate: 144.476, Interface throughputRate: 12277.9, moduleLatency: 0.570148 -[postprocess] throughputRate: 9.03906, moduleLatency: 110.631 - ------------------------------------------------------------ -``` - -pem bs16性能数据 - -``` ------------------Performance Summary------------------ -[e2e] throughputRate: 141.751, latency: 33354.2 -[data read] throughputRate: 145.216, moduleLatency: 6.88627 -[preprocess] throughputRate: 144.936, moduleLatency: 6.89961 -[inference] throughputRate: 145.023, Interface throughputRate: 18564.9, moduleLatency: 0.483157 -[postprocess] throughputRate: 9.10977, moduleLatency: 109.772 - ------------------------------------------------------------ -``` - -tem单卡吞吐率:12277.9x4=49111.6 - -pem单卡吞吐率:18564.9x4=74259.6 - -BSN整体吞吐率为:1/(1/49111.6+1/74259.6)=29560.95 - -#### 2.2 T4性能数据 - -在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2 - -batch1性能: - -tem: - -``` -trtexec --onnx=BSN_tem.onnx --fp16 --shapes=video:1*400*100 --threads -``` - - - -``` -[11/23/2021-06:45:38] [I] GPU Compute -[11/23/2021-06:45:38] [I] min: 0.045166 ms -[11/23/2021-06:45:38] [I] max: 2.00708 ms -[11/23/2021-06:45:38] [I] mean: 0.0565804 ms -[11/23/2021-06:45:38] [I] median: 0.0568848 ms -[11/23/2021-06:45:38] [I] percentile: 0.0620117 ms at 99% -[11/23/2021-06:45:38] [I] total compute time: 2.47115 s -``` - -pem: - -``` -trtexec --onnx=BSN_pem.onnx --fp16 --shapes=video:1*1000*32 --threads -``` - - - -``` -[11/19/2021-06:40:06] [I] GPU Compute -[11/19/2021-06:40:06] [I] min: 0.0185547 ms -[11/19/2021-06:40:06] [I] max: 1.26123 ms -[11/19/2021-06:40:06] [I] mean: 0.0205523 ms -[11/19/2021-06:40:06] [I] median: 0.0201416 ms -[11/19/2021-06:40:06] [I] percentile: 0.0458527 ms at 99% -[11/19/2021-06:40:06] [I] total compute time: 0.793032 s -``` - - - -tem单卡吞吐率:1000/0.215458=17674 - -pem单卡吞吐率:1000/0.0205523=48656 - -BSN单卡吞吐率:1000/(0.215458+0.0205523)=12965 - - - - - -batch16性能: - -tem: - -``` -trtexec --onnx=BSN_tem.onnx --fp16 --shapes=video:16*400*100 --threads -``` - - - -``` -[11/19/2021-06:37:12] [I] GPU Compute -[11/19/2021-06:37:12] [I] min: 0.182129 ms -[11/19/2021-06:37:12] [I] max: 0.252548 ms -[11/19/2021-06:37:12] [I] mean: 0.219561 ms -[11/19/2021-06:37:12] [I] median: 0.218262 ms -[11/19/2021-06:37:12] [I] percentile: 0.245422 ms at 99% -[11/19/2021-06:37:12] [I] total compute time: 1.5714 s -``` - -pem: - -``` -trtexec --onnx=BSN_pem.onnx --fp16 --shapes=video:16*1000*32 --threads -``` - - - -``` -[11/23/2021-06:51:29] [I] GPU Compute -[11/23/2021-06:51:29] [I] min: 0.21167 ms -[11/23/2021-06:51:29] [I] max: 2.40039 ms -[11/23/2021-06:51:29] [I] mean: 0.24159 ms -[11/23/2021-06:51:29] [I] median: 0.240479 ms -[11/23/2021-06:51:29] [I] percentile: 0.25769 ms at 99% -[11/23/2021-06:51:29] [I] total compute time: 2.08734 s -``` - -tem单卡吞吐率:1000/(0.219561/16)=72872 - -pem单卡吞吐率:1000/(0.24159/16)=66228 - -BSN单卡吞吐率:1000/((0.219561+0.0210533)/16)=34696 - - - -#### 2.3 性能对比 - -batch1 : - -​ TEM - -​ 310:13102 - -​ T4:17674 - -​ PEM: - -​ 310:15498 - -​ T4:48656 - -​ BSN: - -​ 7099.87<12965 - -​ 7099.87/12965=0.548 - -batch16: - -​ TEM: - -​ 310: 49111.6 - -​ t4: 72872 - -​ PEM: - -​ 310: 74259.6 - -​ T4: 66228 - -​ BSN: - -​ 29560.95<34696 - -​ 29560.95/34696=0.85 - -在batch1,310性能是0.548倍T4性能;在batch16,310性能是0.85倍T4性能。 - +# BSN推理说明 + + + +## 1、 环境说明 + +1、安装必要的依赖 + +``` +apex 0.1+ascend.20210930 +certifi 2021.10.8 +cycler 0.11.0 +decorator 5.1.0 +docutils 0.18 +flatbuffers 2.0 +future 0.18.2 +Geohash 1.0 +Hydra 2.5 +kiwisolver 1.3.2 +matplotlib 3.4.3 +mpmath 1.2.1 +numpy 1.21.0 +onnx 1.10.2 +onnxruntime 1.9.0 +pandas 1.3.4 +Pillow 8.4.0 +pip 21.3.1 +protobuf 3.19.1 +pyparsing 3.0.6 +python-dateutil 2.8.2 +pytz 2021.3 +scipy 1.7.2 +setuptools 58.0.4 +six 1.16.0 +sympy 1.9 +torch 1.5.0+ascend.post3.20210930 +typing-extensions 3.10.0.2 +wheel 0.37.0 +``` + +2、获取开源代码 + +直接从githup上git clone 可能无法clone成功,建议先把githup上的仓先导入到git,再clone + +``` +git clone https://github.com/wzmsltw/BSN-boundary-sensitive-network.pytorch +``` + + + +3、获取onnx_tools,优化TEM的onnx模型 + +``` +git clone https://gitee.com/zheng-wengang1/onnx_tools +``` + + + +4、下载视频特征数据集 + +请参考源代码仓 + +5、代码目录 + +``` +BSN #模型名称命名的文件夹 +├── BSN-boundary-sensitive-network.pytorch #BSN开源代码 + └── data + ├── activitynet_feature_cuhk + ├── csv_mean_100 #下载数据特征集 +├── env.sh #环境变量 +├── BSN_tem_pth2onnx.py #tem模型转换脚本 +├── BSN_pem_pth2onnx.py #pem模型转换脚本 +├── BSN_tem_preprocess.py #tem模型前处理脚本 +├── BSN_pem_preprocess.py #pem模型前处理脚本 +├── gen_dataset_info.py #生成数据集info文件 +├── BSN_tem_postprocess.py #tem模型后处理脚本 +├── BSN_pem_postprocess.py #pem模型后处理脚本 +├── BSN_eval.py #测试精度脚本 +├── TEM_onnx_conv1d2conv2d.py #tem模型onnx,conv1d算子转conv2d算子优化脚本 +├── requirements.txt #模型离线推理用到的所有且必要的依赖库 +├── README.md #模型离线推理说明README +├── modelzoo_level.txt #模型精度性能结果 +└── test + ├── pth2om.sh + ├── eval_acc_perf.sh + ├── parse.py +``` + + + +## 2、离线推理 + +1、pth权重转onnx + + + +TEM的pth权重转onnx,参数pth_path为TEM模型权重文件所在位置,onnx_path为输出的onnx模型位置 + +``` +python BSN_tem_pth2onnx.py --pth_path './tem_best.pth.tar' --onnx_path './BSN_tem.onnx' +``` + +tem-onnx模型优化,第一个参数为原本onnx模型位置,第二个参数为输出onnx模型 + +``` +python TEM_onnx_conv1d2conv2d.py './BSN_tem.onnx' './BSN_tem1.onnx' +``` + +PEM的pth权重转onnx,参数pth_path为PEM模型权重文件所在位置,onnx_path为输出的onnx模型位置 + +``` +python BSN_pem_pth2onnx.py --pth_path './pem_best.pth.tar' --onnx_path './BSN_pem.onnx' +``` + + + +2、onnx模型转om + +使用atc工具将onnx模型转为om模型,注意应当先设置环境变量 + +``` +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest + +atc --framework=5 --model=BSN_tem1.onnx --output=BSN_tem_bs1 --input_format=ND --input_shape="video:1,400,100" --log=debug --soc_version=Ascend310 + +atc --framework=5 --model=BSN_pem.onnx --output=BSN_pem_bs1 --input_format=ND --input_shape="video_feature:1,1000,32" --log=debug --soc_version=Ascend310 +``` + + + +3、TEM推理 + +运行预处理脚本,运行前确保你已经clone了开源代码,并下载数据特征集 + +``` +python BSN_tem_preprocess.py +``` + +获取处理数据集信息,第一个参数为模型类型,第二个参数为特征文件位置,第三个参数为输出文件名,第四、五个参数为特征形状(400*100) + +``` +python gen_dataset_info.py tem /home/wch/BSN/BSN-TEM-preprocess/feature TEM-video-feature 400 100 +``` + +使用benchmark工具进行推理,生成的数据文件会放在当前路径的result/dumpOutput_device0目录下 + +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=BSN_tem_bs1.om -input_text_path=./TEM-video-feature.info -input_width=400 -input_height=100 -output_binary=True -useDvpp=False +``` + +使用BSN_tem_postprocess.py进行tem后处理(tem的后处理与pem的前处理有关请按照顺序执行) + +``` +python BSN_tem_postprocess.py --TEM_out_path ./result/dumpOutput_device0 +``` + + + +4、PEM推理 + +运行pem预处理脚本(pem的前处理与tem的后处理有关请按照顺序执行) + +``` +python BSN_pem_preprocess.py +``` + +获取处理数据集信息,第一个参数为模型类型,第二个参数为特征文件位置,第三个参数为输出文件名,第四、五个参数为特征形状(1000*32) + +``` +python get_info.py pem output/BSN-PEM-preprocess/feature PEM-video-feature 1000 32 +``` + +使用benchmark工具进行推理,生成的数据文件会放在当前路径的result/dumpOutput_device1目录下 + +``` +./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=1 -om_path=BSN_pem_bs1.om -input_text_path=./PEM-video-feature.info -input_width=1000 -input_height=32 -output_binary=True -useDvpp=False +``` + +运行后处理脚本,会在output目录下生成结果文件 + +``` +python BSN_pem_postprocess.py --PEM_out_path result/dumpOutput_device1 +``` + + + +5、精度测试 + +原本代码仓的代码是python2的代码,在在使用前需要转为python3 + +``` +2to3 -w ./BSN-boundary-sensitive-network.pytorch/Evaluation/eval_proposal.py + +``` + +精度测试 + +``` +python BSN_eval.py +``` + + + +6、整体测试 + +运行脚本,直接转om模型 + +``` +bash ./test/pth2om.sh +``` + +运行脚本,进行离线推理,运行脚本前,请确保已经将源代码中使用的文件,转为python3 + +``` +bash ./test/eval_acc_perf.sh +``` + + + +## 3 精度性能对比 + +### 1、精度对比 + +​ pth精度 + +``` +Model 论文 开源pth文件 离线推理精度 +BSN AR100:72.42 74.34 74.34 +``` + +### 2、性能对比 + +#### 2.1 npu性能数据 + +tem bs1性能数据 + +``` +-----------------Performance Summary------------------ +[e2e] throughputRate: 180.879, latency: 106303 +[data read] throughputRate: 182.039, moduleLatency: 5.49332 +[preprocess] throughputRate: 181.865, moduleLatency: 5.49859 +[inference] throughputRate: 182, Interface throughputRate: 3275.55, moduleLatency: 0.561457 +[postprocess] throughputRate: 182.009, moduleLatency: 5.49425 + +----------------------------------------------------------- +``` + +pem bs1性能数据 + +``` +-----------------Performance Summary------------------ +[e2e] throughputRate: 616.804, latency: 7665.32 +[data read] throughputRate: 1840.06, moduleLatency: 0.54346 +[preprocess] throughputRate: 1817.62, moduleLatency: 0.550169 +[inference] throughputRate: 1839.62, Interface throughputRate: 3874.46, moduleLatency: 0.469866 +[postprocess] throughputRate: 1839.86, moduleLatency: 0.543521 + +----------------------------------------------------------- +``` + +tem单卡吞吐率:3275.55x4=13102.2 + +pem单卡吞吐率:3874.46x4=15497.84 + +BSN整体吞吐率为:1/(1/13102.2+1/15497.84)=7099.87 + + + +tem bs16性能数据 + +``` +-----------------Performance Summary------------------ +[e2e] throughputRate: 143.161, latency: 134310 +[data read] throughputRate: 144.544, moduleLatency: 6.91832 +[preprocess] throughputRate: 144.393, moduleLatency: 6.92554 +[inference] throughputRate: 144.476, Interface throughputRate: 12277.9, moduleLatency: 0.570148 +[postprocess] throughputRate: 9.03906, moduleLatency: 110.631 + +----------------------------------------------------------- +``` + +pem bs16性能数据 + +``` +-----------------Performance Summary------------------ +[e2e] throughputRate: 141.751, latency: 33354.2 +[data read] throughputRate: 145.216, moduleLatency: 6.88627 +[preprocess] throughputRate: 144.936, moduleLatency: 6.89961 +[inference] throughputRate: 145.023, Interface throughputRate: 18564.9, moduleLatency: 0.483157 +[postprocess] throughputRate: 9.10977, moduleLatency: 109.772 + +----------------------------------------------------------- +``` + +tem单卡吞吐率:12277.9x4=49111.6 + +pem单卡吞吐率:18564.9x4=74259.6 + +BSN整体吞吐率为:1/(1/49111.6+1/74259.6)=29560.95 + +#### 2.2 T4性能数据 + +在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2 + +batch1性能: + +tem: + +``` +trtexec --onnx=BSN_tem.onnx --fp16 --shapes=video:1*400*100 --threads +``` + + + +``` +[11/23/2021-06:45:38] [I] GPU Compute +[11/23/2021-06:45:38] [I] min: 0.045166 ms +[11/23/2021-06:45:38] [I] max: 2.00708 ms +[11/23/2021-06:45:38] [I] mean: 0.0565804 ms +[11/23/2021-06:45:38] [I] median: 0.0568848 ms +[11/23/2021-06:45:38] [I] percentile: 0.0620117 ms at 99% +[11/23/2021-06:45:38] [I] total compute time: 2.47115 s +``` + +pem: + +``` +trtexec --onnx=BSN_pem.onnx --fp16 --shapes=video:1*1000*32 --threads +``` + + + +``` +[11/19/2021-06:40:06] [I] GPU Compute +[11/19/2021-06:40:06] [I] min: 0.0185547 ms +[11/19/2021-06:40:06] [I] max: 1.26123 ms +[11/19/2021-06:40:06] [I] mean: 0.0205523 ms +[11/19/2021-06:40:06] [I] median: 0.0201416 ms +[11/19/2021-06:40:06] [I] percentile: 0.0458527 ms at 99% +[11/19/2021-06:40:06] [I] total compute time: 0.793032 s +``` + + + +tem单卡吞吐率:1000/0.215458=17674 + +pem单卡吞吐率:1000/0.0205523=48656 + +BSN单卡吞吐率:1000/(0.215458+0.0205523)=12965 + + + + + +batch16性能: + +tem: + +``` +trtexec --onnx=BSN_tem.onnx --fp16 --shapes=video:16*400*100 --threads +``` + + + +``` +[11/19/2021-06:37:12] [I] GPU Compute +[11/19/2021-06:37:12] [I] min: 0.182129 ms +[11/19/2021-06:37:12] [I] max: 0.252548 ms +[11/19/2021-06:37:12] [I] mean: 0.219561 ms +[11/19/2021-06:37:12] [I] median: 0.218262 ms +[11/19/2021-06:37:12] [I] percentile: 0.245422 ms at 99% +[11/19/2021-06:37:12] [I] total compute time: 1.5714 s +``` + +pem: + +``` +trtexec --onnx=BSN_pem.onnx --fp16 --shapes=video:16*1000*32 --threads +``` + + + +``` +[11/23/2021-06:51:29] [I] GPU Compute +[11/23/2021-06:51:29] [I] min: 0.21167 ms +[11/23/2021-06:51:29] [I] max: 2.40039 ms +[11/23/2021-06:51:29] [I] mean: 0.24159 ms +[11/23/2021-06:51:29] [I] median: 0.240479 ms +[11/23/2021-06:51:29] [I] percentile: 0.25769 ms at 99% +[11/23/2021-06:51:29] [I] total compute time: 2.08734 s +``` + +tem单卡吞吐率:1000/(0.219561/16)=72872 + +pem单卡吞吐率:1000/(0.24159/16)=66228 + +BSN单卡吞吐率:1000/((0.219561+0.0210533)/16)=34696 + + + +#### 2.3 性能对比 + +batch1 : + +​ TEM + +​ 310:13102 + +​ T4:17674 + +​ PEM: + +​ 310:15498 + +​ T4:48656 + +​ BSN: + +​ 7099.87<12965 + +​ 7099.87/12965=0.548 + +batch16: + +​ TEM: + +​ 310: 49111.6 + +​ t4: 72872 + +​ PEM: + +​ 310: 74259.6 + +​ T4: 66228 + +​ BSN: + +​ 29560.95<34696 + +​ 29560.95/34696=0.85 + +在batch1,310性能是0.548倍T4性能;在batch16,310性能是0.85倍T4性能。 + diff --git a/ACL_PyTorch/contrib/cv/detection/BSN/TEM_onnx_conv1d2conv2d.py b/ACL_PyTorch/contrib/cv/detection/BSN/TEM_onnx_conv1d2conv2d.py index 151d48492471f03df30b4163cd912900743d9976..5e3110052763715578379ec104d964ec41678c5e 100644 --- a/ACL_PyTorch/contrib/cv/detection/BSN/TEM_onnx_conv1d2conv2d.py +++ b/ACL_PyTorch/contrib/cv/detection/BSN/TEM_onnx_conv1d2conv2d.py @@ -1,110 +1,110 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import sys -import numpy as np -from onnx_tools.OXInterface.OXInterface import OXGraph - - -INPUT_NODE = 'video' - -def conv1d2conv2d(oxgraph, node_conv): - """ - transfer conv1d parameters to conv2d - :param oxgraph: input onnx graph - :param node_conv: conv1d node to be transfered - """ - if node_conv.get_op_type() != 'Conv': - return - if node_conv.get_name() == 'Conv_0': - node_conv.set_attribute(attr_name='dilations', attr_value=[1,1]) - node_conv.set_attribute(attr_name='kernel_shape', attr_value=[1,3]) - node_conv.set_attribute(attr_name='pads', attr_value=[0, 1, 0, 1]) - node_conv.set_attribute(attr_name='strides', attr_value=[1,1]) - if node_conv.get_name() == 'Conv_2': - node_conv.set_attribute(attr_name='dilations', attr_value=[1,1]) - node_conv.set_attribute(attr_name='kernel_shape', attr_value=[1,3]) - node_conv.set_attribute(attr_name='pads', attr_value=[0, 1, 0, 1]) - node_conv.set_attribute(attr_name='strides', attr_value=[1,1]) - if node_conv.get_name() == 'Conv_4': - node_conv.set_attribute(attr_name='dilations', attr_value=[1,1]) - node_conv.set_attribute(attr_name='kernel_shape', attr_value=[1,1]) - node_conv.set_attribute(attr_name='pads', attr_value=[0, 0, 0, 0]) - node_conv.set_attribute(attr_name='strides', attr_value=[1,1]) - - init_conv_w = oxgraph.get_oxinitializer_by_name(node_conv.input[1]) - init_conv_w.set_data(np.expand_dims(init_conv_w.get_data(), axis=2)) - -def transfer_structure(oxgraph, beg_node, end_node): - """ - transfer process: - 1. insert unsqueeze node before beg node - 2. insert squeeze node after end node - 3. transfer conv1d paramters for conv2d - :param oxgraph: input onnx graph - :param beg_node: beg node name for searched structure - :param end_node: end node name for searched structure - """ - previous_beg_node = oxgraph.get_previous_oxnode(oxnode_name=beg_node) - if not previous_beg_node: - previous_beg_node = INPUT_NODE - else: - previous_beg_node = previous_beg_node[0].get_name() - next_end_node = oxgraph.get_next_oxnode(oxnode_name=end_node) - unsqueeze_node_name = 'Unsqueeze_before_{}'.format(beg_node) - squeeze_node_name = 'Squeeze_after_{}'.format(end_node) - next_end_node = next_end_node[0].get_name() - - oxgraph.insert_node(bef_node_info_list=[previous_beg_node], - aft_node_info_list=[beg_node], - op_type='Unsqueeze', - op_name=unsqueeze_node_name) - oxgraph.insert_node(bef_node_info_list=[end_node], - aft_node_info_list=[next_end_node], - op_type='Squeeze', - op_name=squeeze_node_name) - node_unsqueeze = oxgraph.get_oxnode_by_name(unsqueeze_node_name) - node_unsqueeze.set_attribute(attr_name='axes', attr_value=[2]) - node_squeeze = oxgraph.get_oxnode_by_name(squeeze_node_name) - node_squeeze.set_attribute(attr_name='axes', attr_value=[2]) - - next_beg_node = oxgraph.get_oxnode_by_name(oxnode_name=beg_node) - while next_beg_node.get_name() != end_node: - conv1d2conv2d(oxgraph, next_beg_node) - next_beg_node = oxgraph.get_next_oxnode(oxnode_name=next_beg_node.get_name()) - next_beg_node = next_beg_node[0] - conv1d2conv2d(oxgraph, next_beg_node) - - -def fix_conv1d(model_path, out_path, beg_list, end_list): - """ - main process for fixing conv1d - :param model_path: input onnx model path - :param out_path: out fixed onnx model path - :param beg_list: beg node names for searched structure - :param end_list: end node names for searched structure - """ - oxgraph = OXGraph(model_path) - for idx, beg_node in enumerate(beg_list): - end_node = end_list[idx] - transfer_structure(oxgraph, beg_node, end_node) - oxgraph.save_new_model(out_path) - - -if __name__ == '__main__': - input_path = sys.argv[1] - save_path = sys.argv[2] - beg_nodes = ['Conv_0'] - end_nodes = ['Conv_4'] - fix_conv1d(input_path, save_path, beg_nodes, end_nodes) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +import numpy as np +from onnx_tools.OXInterface.OXInterface import OXGraph + + +INPUT_NODE = 'video' + +def conv1d2conv2d(oxgraph, node_conv): + """ + transfer conv1d parameters to conv2d + :param oxgraph: input onnx graph + :param node_conv: conv1d node to be transfered + """ + if node_conv.get_op_type() != 'Conv': + return + if node_conv.get_name() == 'Conv_0': + node_conv.set_attribute(attr_name='dilations', attr_value=[1,1]) + node_conv.set_attribute(attr_name='kernel_shape', attr_value=[1,3]) + node_conv.set_attribute(attr_name='pads', attr_value=[0, 1, 0, 1]) + node_conv.set_attribute(attr_name='strides', attr_value=[1,1]) + if node_conv.get_name() == 'Conv_2': + node_conv.set_attribute(attr_name='dilations', attr_value=[1,1]) + node_conv.set_attribute(attr_name='kernel_shape', attr_value=[1,3]) + node_conv.set_attribute(attr_name='pads', attr_value=[0, 1, 0, 1]) + node_conv.set_attribute(attr_name='strides', attr_value=[1,1]) + if node_conv.get_name() == 'Conv_4': + node_conv.set_attribute(attr_name='dilations', attr_value=[1,1]) + node_conv.set_attribute(attr_name='kernel_shape', attr_value=[1,1]) + node_conv.set_attribute(attr_name='pads', attr_value=[0, 0, 0, 0]) + node_conv.set_attribute(attr_name='strides', attr_value=[1,1]) + + init_conv_w = oxgraph.get_oxinitializer_by_name(node_conv.input[1]) + init_conv_w.set_data(np.expand_dims(init_conv_w.get_data(), axis=2)) + +def transfer_structure(oxgraph, beg_node, end_node): + """ + transfer process: + 1. insert unsqueeze node before beg node + 2. insert squeeze node after end node + 3. transfer conv1d paramters for conv2d + :param oxgraph: input onnx graph + :param beg_node: beg node name for searched structure + :param end_node: end node name for searched structure + """ + previous_beg_node = oxgraph.get_previous_oxnode(oxnode_name=beg_node) + if not previous_beg_node: + previous_beg_node = INPUT_NODE + else: + previous_beg_node = previous_beg_node[0].get_name() + next_end_node = oxgraph.get_next_oxnode(oxnode_name=end_node) + unsqueeze_node_name = 'Unsqueeze_before_{}'.format(beg_node) + squeeze_node_name = 'Squeeze_after_{}'.format(end_node) + next_end_node = next_end_node[0].get_name() + + oxgraph.insert_node(bef_node_info_list=[previous_beg_node], + aft_node_info_list=[beg_node], + op_type='Unsqueeze', + op_name=unsqueeze_node_name) + oxgraph.insert_node(bef_node_info_list=[end_node], + aft_node_info_list=[next_end_node], + op_type='Squeeze', + op_name=squeeze_node_name) + node_unsqueeze = oxgraph.get_oxnode_by_name(unsqueeze_node_name) + node_unsqueeze.set_attribute(attr_name='axes', attr_value=[2]) + node_squeeze = oxgraph.get_oxnode_by_name(squeeze_node_name) + node_squeeze.set_attribute(attr_name='axes', attr_value=[2]) + + next_beg_node = oxgraph.get_oxnode_by_name(oxnode_name=beg_node) + while next_beg_node.get_name() != end_node: + conv1d2conv2d(oxgraph, next_beg_node) + next_beg_node = oxgraph.get_next_oxnode(oxnode_name=next_beg_node.get_name()) + next_beg_node = next_beg_node[0] + conv1d2conv2d(oxgraph, next_beg_node) + + +def fix_conv1d(model_path, out_path, beg_list, end_list): + """ + main process for fixing conv1d + :param model_path: input onnx model path + :param out_path: out fixed onnx model path + :param beg_list: beg node names for searched structure + :param end_list: end node names for searched structure + """ + oxgraph = OXGraph(model_path) + for idx, beg_node in enumerate(beg_list): + end_node = end_list[idx] + transfer_structure(oxgraph, beg_node, end_node) + oxgraph.save_new_model(out_path) + + +if __name__ == '__main__': + input_path = sys.argv[1] + save_path = sys.argv[2] + beg_nodes = ['Conv_0'] + end_nodes = ['Conv_4'] + fix_conv1d(input_path, save_path, beg_nodes, end_nodes) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/BSN/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/detection/BSN/gen_dataset_info.py index 7d55019ee88a193789691f80808e4e2facbcf4d3..bb435699d8e549877f8a2000641fd8fa303e3f28 100644 --- a/ACL_PyTorch/contrib/cv/detection/BSN/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/detection/BSN/gen_dataset_info.py @@ -1,39 +1,39 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import sys - - -def get_bin_info(file_type, file_path, info_name, width, height): - bin_files = sorted(os.listdir(file_path)) - - with open(info_name+'.info', 'w') as file: - i = 0 - for bin_file in bin_files: - if bin_file.endswith('.bin'): - if file_type == 'tem': - content = ' '.join([str(i), 'output/BSN-TEM-preprocess/feature'+'/'+bin_file, width, height]) - if file_type == 'pem': - content = ' '.join([str(i), 'output/BSN-PEM-preprocess/feature'+'/'+bin_file, width, height]) - file.write(content) - file.write('\n') - i = i+1 - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - line = sys.argv[4] - col = sys.argv[5] +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import sys + + +def get_bin_info(file_type, file_path, info_name, width, height): + bin_files = sorted(os.listdir(file_path)) + + with open(info_name+'.info', 'w') as file: + i = 0 + for bin_file in bin_files: + if bin_file.endswith('.bin'): + if file_type == 'tem': + content = ' '.join([str(i), 'output/BSN-TEM-preprocess/feature'+'/'+bin_file, width, height]) + if file_type == 'pem': + content = ' '.join([str(i), 'output/BSN-PEM-preprocess/feature'+'/'+bin_file, width, height]) + file.write(content) + file.write('\n') + i = i+1 + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + line = sys.argv[4] + col = sys.argv[5] get_bin_info(file_type,file_path, info_name, line, col) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/BSN/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/detection/BSN/modelzoo_level.txt index c021e5b6ccd79796c6c89fffb78c3ac7cf956f20..29569dfe38675049737d3c1d06941057f6aea472 100644 --- a/ACL_PyTorch/contrib/cv/detection/BSN/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/detection/BSN/modelzoo_level.txt @@ -1,5 +1,5 @@ -acc: -74.34 OK -perf: -bs1:6148 OK +acc: +74.34 OK +perf: +bs1:6148 OK bs16: 19172 False \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/BSN/parse.py b/ACL_PyTorch/contrib/cv/detection/BSN/parse.py index 1841a9747c1da500ef5f9e0e0368ec324be08595..e071d8fecf850996e9527d39d0e7d0f4d83ad14e 100644 --- a/ACL_PyTorch/contrib/cv/detection/BSN/parse.py +++ b/ACL_PyTorch/contrib/cv/detection/BSN/parse.py @@ -1,39 +1,39 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import sys -import re - -def get_acc(filename): - with open(filename, 'r') as f: - lines = f.readlines() - last_line = lines[-1] - psnr = last_line.split(" ")[2] - print(filename.split('.')[0],"Average PSNR:", psnr) - - -def get_perf(filename): - with open(filename, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 - print('310 bs{} fps:{}'.format(filename.split('_')[3], fps)) - -if __name__ == "__main__": - - filename = sys.argv[1] - - if filename.endswith(".log"): - get_acc(filename) - elif filename.endswith(".txt"): +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +import re + +def get_acc(filename): + with open(filename, 'r') as f: + lines = f.readlines() + last_line = lines[-1] + psnr = last_line.split(" ")[2] + print(filename.split('.')[0],"Average PSNR:", psnr) + + +def get_perf(filename): + with open(filename, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 + print('310 bs{} fps:{}'.format(filename.split('_')[3], fps)) + +if __name__ == "__main__": + + filename = sys.argv[1] + + if filename.endswith(".log"): + get_acc(filename) + elif filename.endswith(".txt"): get_perf(filename) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/BSN/requirements.txt b/ACL_PyTorch/contrib/cv/detection/BSN/requirements.txt index bfc65830ffe767e72f7588d0eebe3f2e775bd145..796da27d2df6a0f6741ff104b8e14ec936e95f53 100644 --- a/ACL_PyTorch/contrib/cv/detection/BSN/requirements.txt +++ b/ACL_PyTorch/contrib/cv/detection/BSN/requirements.txt @@ -1,26 +1,26 @@ -cycler -decorator -docutils -flatbuffers -future -Geohash -Hydra -kiwisolver -matplotlib -mpmath -numpy -onnx -onnxruntime -pandas -Pillow -pip -protobuf -pyparsing -python-dateutil -pytz -scipy -setuptools -six -sympy -typing-extensions +cycler +decorator +docutils +flatbuffers +future +Geohash +Hydra +kiwisolver +matplotlib +mpmath +numpy +onnx +onnxruntime +pandas +Pillow +pip +protobuf +pyparsing +python-dateutil +pytz +scipy +setuptools +six +sympy +typing-extensions skl2onnx \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/BSN/test/parse.py b/ACL_PyTorch/contrib/cv/detection/BSN/test/parse.py index 1841a9747c1da500ef5f9e0e0368ec324be08595..e071d8fecf850996e9527d39d0e7d0f4d83ad14e 100644 --- a/ACL_PyTorch/contrib/cv/detection/BSN/test/parse.py +++ b/ACL_PyTorch/contrib/cv/detection/BSN/test/parse.py @@ -1,39 +1,39 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import sys -import re - -def get_acc(filename): - with open(filename, 'r') as f: - lines = f.readlines() - last_line = lines[-1] - psnr = last_line.split(" ")[2] - print(filename.split('.')[0],"Average PSNR:", psnr) - - -def get_perf(filename): - with open(filename, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 - print('310 bs{} fps:{}'.format(filename.split('_')[3], fps)) - -if __name__ == "__main__": - - filename = sys.argv[1] - - if filename.endswith(".log"): - get_acc(filename) - elif filename.endswith(".txt"): +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +import re + +def get_acc(filename): + with open(filename, 'r') as f: + lines = f.readlines() + last_line = lines[-1] + psnr = last_line.split(" ")[2] + print(filename.split('.')[0],"Average PSNR:", psnr) + + +def get_perf(filename): + with open(filename, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 + print('310 bs{} fps:{}'.format(filename.split('_')[3], fps)) + +if __name__ == "__main__": + + filename = sys.argv[1] + + if filename.endswith(".log"): + get_acc(filename) + elif filename.endswith(".txt"): get_perf(filename) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/README.md b/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/README.md index a49732889f846add0877a7d339fd481429de9c4e..b7eef1f4c876dac1579bf327bb71b7bc0f183a2b 100644 --- a/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/README.md +++ b/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/README.md @@ -1,156 +1,156 @@ -# Cascade-RCNN-Resnet101-FPN-DCN模型PyTorch离线推理指导 - -## 1 环境准备 - -1. 安装必要的依赖 - - 在文件夹中处理。 - - 测试环境可能已经安装其中的一些不同版本的库了,故手动测试时建议创建虚拟环境后自己安装,参考开源仓代码的获取方式: - -``` -conda create -n dcn python=3.7 -conda activate dcn -pip install onnx==1.7.0 -pip install onnxruntime==1.9.0 -conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cpuonly -c pytorch -pip install mmcv-full==1.2.4 -``` - -2. 获取,修改与安装开源模型代码,参考开源仓代码的获取方式: - -``` -git clone https://github.com/open-mmlab/mmdetection.git -cd mmdetection -git reset a21eb25535f31634cef332b09fc27d28956fb24b --hard -pip install -v -e . -cd .. -``` - -将提供的**pytorch_code_change**文件夹中的文件替换原文件。 - -``` -cp ./pytorch_code_change/bbox_nms.py ./mmdetection/mmdet/core//post_processing/bbox_nms.py -cp ./pytorch_code_change/rpn_head.py ./mmdetection/mmdet/models/dense_heads/rpn_head.py -cp ./pytorch_code_change/single_level_roi_extractor.py ./mmdetection/mmdet/models/roi_heads/roi_extractors/single_level_roi_extractor.py -cp ./pytorch_code_change/delta_xywh_bbox_coder.py ./mmdetection/mmdet/core/bbox/coder/delta_xywh_bbox_coder.py -cp ./pytorch_code_change/pytorch2onnx.py ./mmdetection/tools/pytorch2onnx.py -cp ./pytorch_code_change/cascade_rcnn_r50_fpn.py ./mmdetection/configs/_base_/models/cascade_rcnn_r50_fpn.py -cp ./pytorch_code_change/deform_conv.py /root/anaconda3/envs/dcn/lib/python3.7/site-packages/mmcv/ops/deform_conv.py -#注意这里要根据实际情况下的安装路径来修改 -``` - -3. 获取权重文件 - -参考源码仓的方式获取,可以通过obs方法获取,下载对应的权重文件。 - -``` -wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/detection/Cascade%20RCNN-Resnet101-FPN-DCN/cascade_rcnn_r101_fpn_dconv_c3-c5_1x_coco_20200203-3b2f0594.pth -``` - -4. 数据集 - 本模型使用coco2017的验证集(val2017)验证,将服务器上的数据集复制到本文件下固定位置:data/coco/annotation/instances_val2017.json以及data/coco/val2017 - - ``` - mkdir -p data/coco - cp -r /opt/npu/datasets/coco/* /home/tyjf/data/coco - - ``` - -5. 导出onnx - - 使用mmdet框架自带的脚本导出onnx即可,这里指定shape为1216。 - - 由于当前框架限制,仅支持batchsize=1的场景。 - -``` -python mmdetection/tools/pytorch2onnx.py mmdetection/configs/dcn/cascade_rcnn_r101_fpn_dconv_c3-c5_1x_coco.py ./cascade_rcnn_r101_fpn_dconv_c3-c5_1x_coco_20200203-3b2f0594.pth --output-file=cascadeR101dcn.onnx --shape=1216 --verify --show -``` - -6. 导出om - - 运行atc.sh脚本,完成onnx到om模型的转换,注意输出节点可能需要根据实际的onnx修改。 - -``` -bash atc.sh cascadeR101dcn.onnx cascadeR101dcn -``` - - -## 2 离线推理 - -在310上执行,执行时使npu-smi info查看设备状态,确保device空闲。 - -1. 数据预处理 - -``` -python mmdetection_coco_preprocess.py --image_folder_path ./data/coco/val2017 --bin_folder_path val2017_bin -python get_info.py bin ./val2017_bin coco2017.info 1216 1216 -python get_info.py jpg ./data/coco/val2017 coco2017_jpg.info -``` - -2. 使用benchmark工具进行推理 - -``` -chmod u+x benchmark.x86_64 -./benchmark.x86_64 -model_type=vision -batch_size=1 -device_id=0 -input_text_path=./coco2017.info -input_width=1216 -input_height=1216 -useDvpp=False -output_binary=true -om_path=cascadeR101dcn.om -``` - -3. 推理结果展示 - -本模型提供后处理脚本,将二进制数据转化为txt文件,同时生成画出检测框后的图片。执行脚本 - -``` -python mmdetection_coco_postprocess.py --bin_data_path=result/dumpOutput_device0 --prob_thres=0.05 --ifShowDetObj --det_results_path=detection-results --test_annotation=coco2017_jpg.info -``` - -4. 精度验证 - -``` -python txt_to_json.py -python coco_eval.py --ground_truth ./data/coco/annotation/instances_val2017.json -``` -可以看到NPU精度:'bbox_mAP': 0.452 - -5. 性能验证 - -查看NPU性能 - -``` -bash test/perf_npu.sh -#或者运行 ./benchmark.x86_64 -round=50 -om_path=cascadeR101dcn.om --device_id=2 -batch_size=1 -``` - -可以看到NPU性能: - -[INFO] ave_throughputRate: 0.620627samples/s, ave_latency: 1593.71ms - -0.65281*4=2.61fps - -6. GPU性能与精度验证 - -由于模型算子的原因采取在线推理的方式检测GPU性能: - -在GPU上搭建好环境,并进行预处理: - -``` -mkdir -p data/coco/val2017 -cp -r /root/coco/val2017/* /home/dcnv0/data/coco/val2017 -mkdir -p data/coco/annotations -cp -r /root/coco/annotations/* /home/dcnv0/data/coco/annotations -``` - -测试性能与精度: - -``` -cd /home/dcnv0 -conda activate cascade -python ./mmdetection/tools/test.py ./mmdetection/configs/dcn/cascade_rcnn_r101_fpn_dconv_c3-c5_1x_coco.py ./cascade_rcnn_r101_fpn_dconv_c3-c5_1x_coco_20200203-3b2f0594.pth --eval=bbox -``` - -可以算出GPU性能为4.06fps左右。 - -**评测结果:** - -| 模型 | 官网pth精度 | 310离线推理精度 | gpu性能 | 310性能 | -| :--------------------------------: | :---------: | :-------------: | :-----: | :-----: | -| Cascade-RCNN-Resnet101-FPN-DCN | mAP:0.45 | mAP:0.452 | 4.06fps | 2.64fps | +# Cascade-RCNN-Resnet101-FPN-DCN模型PyTorch离线推理指导 + +## 1 环境准备 + +1. 安装必要的依赖 + + 在文件夹中处理。 + + 测试环境可能已经安装其中的一些不同版本的库了,故手动测试时建议创建虚拟环境后自己安装,参考开源仓代码的获取方式: + +``` +conda create -n dcn python=3.7 +conda activate dcn +pip install onnx==1.7.0 +pip install onnxruntime==1.9.0 +conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cpuonly -c pytorch +pip install mmcv-full==1.2.4 +``` + +2. 获取,修改与安装开源模型代码,参考开源仓代码的获取方式: + +``` +git clone https://github.com/open-mmlab/mmdetection.git +cd mmdetection +git reset a21eb25535f31634cef332b09fc27d28956fb24b --hard +pip install -v -e . +cd .. +``` + +将提供的**pytorch_code_change**文件夹中的文件替换原文件。 + +``` +cp ./pytorch_code_change/bbox_nms.py ./mmdetection/mmdet/core//post_processing/bbox_nms.py +cp ./pytorch_code_change/rpn_head.py ./mmdetection/mmdet/models/dense_heads/rpn_head.py +cp ./pytorch_code_change/single_level_roi_extractor.py ./mmdetection/mmdet/models/roi_heads/roi_extractors/single_level_roi_extractor.py +cp ./pytorch_code_change/delta_xywh_bbox_coder.py ./mmdetection/mmdet/core/bbox/coder/delta_xywh_bbox_coder.py +cp ./pytorch_code_change/pytorch2onnx.py ./mmdetection/tools/pytorch2onnx.py +cp ./pytorch_code_change/cascade_rcnn_r50_fpn.py ./mmdetection/configs/_base_/models/cascade_rcnn_r50_fpn.py +cp ./pytorch_code_change/deform_conv.py /root/anaconda3/envs/dcn/lib/python3.7/site-packages/mmcv/ops/deform_conv.py +#注意这里要根据实际情况下的安装路径来修改 +``` + +3. 获取权重文件 + +参考源码仓的方式获取,可以通过obs方法获取,下载对应的权重文件。 + +``` +wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/detection/Cascade%20RCNN-Resnet101-FPN-DCN/cascade_rcnn_r101_fpn_dconv_c3-c5_1x_coco_20200203-3b2f0594.pth +``` + +4. 数据集 + 本模型使用coco2017的验证集(val2017)验证,将服务器上的数据集复制到本文件下固定位置:data/coco/annotation/instances_val2017.json以及data/coco/val2017 + + ``` + mkdir -p data/coco + cp -r /opt/npu/datasets/coco/* /home/tyjf/data/coco + + ``` + +5. 导出onnx + + 使用mmdet框架自带的脚本导出onnx即可,这里指定shape为1216。 + + 由于当前框架限制,仅支持batchsize=1的场景。 + +``` +python mmdetection/tools/pytorch2onnx.py mmdetection/configs/dcn/cascade_rcnn_r101_fpn_dconv_c3-c5_1x_coco.py ./cascade_rcnn_r101_fpn_dconv_c3-c5_1x_coco_20200203-3b2f0594.pth --output-file=cascadeR101dcn.onnx --shape=1216 --verify --show +``` + +6. 导出om + + 运行atc.sh脚本,完成onnx到om模型的转换,注意输出节点可能需要根据实际的onnx修改。 + +``` +bash atc.sh cascadeR101dcn.onnx cascadeR101dcn +``` + + +## 2 离线推理 + +在310上执行,执行时使npu-smi info查看设备状态,确保device空闲。 + +1. 数据预处理 + +``` +python mmdetection_coco_preprocess.py --image_folder_path ./data/coco/val2017 --bin_folder_path val2017_bin +python get_info.py bin ./val2017_bin coco2017.info 1216 1216 +python get_info.py jpg ./data/coco/val2017 coco2017_jpg.info +``` + +2. 使用benchmark工具进行推理 + +``` +chmod u+x benchmark.x86_64 +./benchmark.x86_64 -model_type=vision -batch_size=1 -device_id=0 -input_text_path=./coco2017.info -input_width=1216 -input_height=1216 -useDvpp=False -output_binary=true -om_path=cascadeR101dcn.om +``` + +3. 推理结果展示 + +本模型提供后处理脚本,将二进制数据转化为txt文件,同时生成画出检测框后的图片。执行脚本 + +``` +python mmdetection_coco_postprocess.py --bin_data_path=result/dumpOutput_device0 --prob_thres=0.05 --ifShowDetObj --det_results_path=detection-results --test_annotation=coco2017_jpg.info +``` + +4. 精度验证 + +``` +python txt_to_json.py +python coco_eval.py --ground_truth ./data/coco/annotation/instances_val2017.json +``` +可以看到NPU精度:'bbox_mAP': 0.452 + +5. 性能验证 + +查看NPU性能 + +``` +bash test/perf_npu.sh +#或者运行 ./benchmark.x86_64 -round=50 -om_path=cascadeR101dcn.om --device_id=2 -batch_size=1 +``` + +可以看到NPU性能: + +[INFO] ave_throughputRate: 0.620627samples/s, ave_latency: 1593.71ms + +0.65281*4=2.61fps + +6. GPU性能与精度验证 + +由于模型算子的原因采取在线推理的方式检测GPU性能: + +在GPU上搭建好环境,并进行预处理: + +``` +mkdir -p data/coco/val2017 +cp -r /root/coco/val2017/* /home/dcnv0/data/coco/val2017 +mkdir -p data/coco/annotations +cp -r /root/coco/annotations/* /home/dcnv0/data/coco/annotations +``` + +测试性能与精度: + +``` +cd /home/dcnv0 +conda activate cascade +python ./mmdetection/tools/test.py ./mmdetection/configs/dcn/cascade_rcnn_r101_fpn_dconv_c3-c5_1x_coco.py ./cascade_rcnn_r101_fpn_dconv_c3-c5_1x_coco_20200203-3b2f0594.pth --eval=bbox +``` + +可以算出GPU性能为4.06fps左右。 + +**评测结果:** + +| 模型 | 官网pth精度 | 310离线推理精度 | gpu性能 | 310性能 | +| :--------------------------------: | :---------: | :-------------: | :-----: | :-----: | +| Cascade-RCNN-Resnet101-FPN-DCN | mAP:0.45 | mAP:0.452 | 4.06fps | 2.64fps | diff --git a/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/coco_eval.py b/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/coco_eval.py index 628e5fc8a81f437159ac8c2cf0fef176a73c66e8..18c4fcdb6bb6ad1fbc3b41c88c8f26921843b78e 100644 --- a/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/coco_eval.py +++ b/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/coco_eval.py @@ -1,91 +1,91 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import argparse -import numpy as np -from pycocotools.coco import COCO -from pycocotools.cocoeval import COCOeval - -CLASSES = ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', - 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', - 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', - 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', - 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', - 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', - 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', - 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', - 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', - 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', - 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', - 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush') - -def coco_evaluation(annotation_json, result_json): - cocoGt = COCO(annotation_json) - cocoDt = cocoGt.loadRes(result_json) - iou_thrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True) - iou_type = 'bbox' - - cocoEval = COCOeval(cocoGt, cocoDt, iou_type) - cocoEval.params.catIds = cocoGt.get_cat_ids(cat_names=CLASSES) - cocoEval.params.imgIds = cocoGt.get_img_ids() - cocoEval.params.maxDets = [100, 300, 1000] # proposal number for evaluating recalls/mAPs. - cocoEval.params.iouThrs = iou_thrs - - cocoEval.evaluate() - cocoEval.accumulate() - cocoEval.summarize() - - # mapping of cocoEval.stats - coco_metric_names = { - 'mAP': 0, - 'mAP_50': 1, - 'mAP_75': 2, - 'mAP_s': 3, - 'mAP_m': 4, - 'mAP_l': 5, - 'AR@100': 6, - 'AR@300': 7, - 'AR@1000': 8, - 'AR_s@1000': 9, - 'AR_m@1000': 10, - 'AR_l@1000': 11 - } - - metric_items = ['mAP', 'mAP_50', 'mAP_75', 'mAP_s', 'mAP_m', 'mAP_l'] - eval_results = {} - - for metric_item in metric_items: - key = f'bbox_{metric_item}' - val = float( - f'{cocoEval.stats[coco_metric_names[metric_item]]:.3f}' - ) - eval_results[key] = val - ap = cocoEval.stats[:6] - eval_results['bbox_mAP_copypaste'] = ( - f'{ap[0]:.3f} {ap[1]:.3f} {ap[2]:.3f} {ap[3]:.3f} ' - f'{ap[4]:.3f} {ap[5]:.3f}') - - return eval_results - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--ground_truth", default="instances_val2017.json") - parser.add_argument("--detection_result", default="coco_detection_result.json") - args = parser.parse_args() - result = coco_evaluation(args.ground_truth, args.detection_result) - print(result) - with open('./coco_detection_result.txt', 'w') as f: - for key, value in result.items(): +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import argparse +import numpy as np +from pycocotools.coco import COCO +from pycocotools.cocoeval import COCOeval + +CLASSES = ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', + 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', + 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', + 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', + 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', + 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', + 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', + 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', + 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', + 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', + 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', + 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush') + +def coco_evaluation(annotation_json, result_json): + cocoGt = COCO(annotation_json) + cocoDt = cocoGt.loadRes(result_json) + iou_thrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True) + iou_type = 'bbox' + + cocoEval = COCOeval(cocoGt, cocoDt, iou_type) + cocoEval.params.catIds = cocoGt.get_cat_ids(cat_names=CLASSES) + cocoEval.params.imgIds = cocoGt.get_img_ids() + cocoEval.params.maxDets = [100, 300, 1000] # proposal number for evaluating recalls/mAPs. + cocoEval.params.iouThrs = iou_thrs + + cocoEval.evaluate() + cocoEval.accumulate() + cocoEval.summarize() + + # mapping of cocoEval.stats + coco_metric_names = { + 'mAP': 0, + 'mAP_50': 1, + 'mAP_75': 2, + 'mAP_s': 3, + 'mAP_m': 4, + 'mAP_l': 5, + 'AR@100': 6, + 'AR@300': 7, + 'AR@1000': 8, + 'AR_s@1000': 9, + 'AR_m@1000': 10, + 'AR_l@1000': 11 + } + + metric_items = ['mAP', 'mAP_50', 'mAP_75', 'mAP_s', 'mAP_m', 'mAP_l'] + eval_results = {} + + for metric_item in metric_items: + key = f'bbox_{metric_item}' + val = float( + f'{cocoEval.stats[coco_metric_names[metric_item]]:.3f}' + ) + eval_results[key] = val + ap = cocoEval.stats[:6] + eval_results['bbox_mAP_copypaste'] = ( + f'{ap[0]:.3f} {ap[1]:.3f} {ap[2]:.3f} {ap[3]:.3f} ' + f'{ap[4]:.3f} {ap[5]:.3f}') + + return eval_results + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--ground_truth", default="instances_val2017.json") + parser.add_argument("--detection_result", default="coco_detection_result.json") + args = parser.parse_args() + result = coco_evaluation(args.ground_truth, args.detection_result) + print(result) + with open('./coco_detection_result.txt', 'w') as f: + for key, value in result.items(): f.write(key + ': ' + str(value) + '\n') \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/get_info.py b/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/get_info.py index 5af675c6b0ae3f28a6f191d139ebb44e775e6c1c..fc6cdebb5b4417a3651c1e6e9663d8d1299a0ef5 100644 --- a/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/get_info.py +++ b/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/get_info.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/mmdetection_coco_postprocess.py b/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/mmdetection_coco_postprocess.py index a40fbc9bfc9624e2423765e39e55026ca437f815..bcad902c276bca7b80057ce2144f0c3cf11ba749 100644 --- a/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/mmdetection_coco_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/mmdetection_coco_postprocess.py @@ -1,148 +1,148 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import numpy as np -import argparse -import cv2 - -CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', - 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', - 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', - 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', - 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', - 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', - 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', - 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', - 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', - 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', - 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', - 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] - -def coco_postprocess(bbox: np.ndarray, image_size, - net_input_width, net_input_height): - """ - This function is postprocessing for FasterRCNN output. - - Before calling this function, reshape the raw output of FasterRCNN to - following form - numpy.ndarray: - [x, y, width, height, confidence, probability of 80 classes] - shape: (100,) - The postprocessing restore the bounding rectangles of FasterRCNN output - to origin scale and filter with non-maximum suppression. - - :param bbox: a numpy array of the FasterRCNN output - :param image_path: a string of image path - :return: three list for best bound, class and score - """ - w = image_size[0] - h = image_size[1] - scale = min(net_input_width / w, net_input_height / h) - - pad_w = net_input_width - w * scale - pad_h = net_input_height - h * scale - pad_left = pad_w // 2 - pad_top = pad_h // 2 - - # cal predict box on the image src - pbox = bbox - pbox[:, 0] = (bbox[:, 0] - pad_left) / scale - pbox[:, 1] = (bbox[:, 1] - pad_top) / scale - pbox[:, 2] = (bbox[:, 2] - pad_left) / scale - pbox[:, 3] = (bbox[:, 3] - pad_top) / scale - return pbox - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0") - parser.add_argument("--test_annotation", default="./coco2017_jpg.info") - parser.add_argument("--det_results_path", default="./detection-results/") - parser.add_argument("--net_out_num", default=2) - parser.add_argument("--net_input_width", default=1216) - parser.add_argument("--net_input_height", default=1216) - parser.add_argument("--prob_thres", default=0.05) - parser.add_argument("--ifShowDetObj", action="store_true", help="if input the para means True, neither False.") - flags = parser.parse_args() - print(flags.ifShowDetObj, type(flags.ifShowDetObj)) - # generate dict according to annotation file for query resolution - # load width and height of input images - img_size_dict = dict() - with open(flags.test_annotation)as f: - for line in f.readlines(): - temp = line.split(" ") - img_file_path = temp[1] - img_name = temp[1].split("/")[-1].split(".")[0] - img_width = int(temp[2]) - img_height = int(temp[3]) - img_size_dict[img_name] = (img_width, img_height, img_file_path) - - # read bin file for generate predict result - bin_path = flags.bin_data_path - det_results_path = flags.det_results_path - os.makedirs(det_results_path, exist_ok=True) - total_img = set([name[:name.rfind('_')] - for name in os.listdir(bin_path) if "bin" in name]) - for bin_file in sorted(total_img): - path_base = os.path.join(bin_path, bin_file) - # load all detected output tensor - res_buff = [] - for num in range(1, flags.net_out_num + 1): - if os.path.exists(path_base + "_" + str(num) + ".bin"): - if num == 1: - buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="float32") - buf = np.reshape(buf, [100, 5]) - elif num == 2: - buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="int64") - buf = np.reshape(buf, [100, 1]) - res_buff.append(buf) - else: - print("[ERROR] file not exist", path_base + "_" + str(num) + ".bin") - res_tensor = np.concatenate(res_buff, axis=1) - current_img_size = img_size_dict[bin_file] - print("[TEST]---------------------------concat{} imgsize{}".format(len(res_tensor), current_img_size)) - predbox = coco_postprocess(res_tensor, current_img_size, flags.net_input_width, flags.net_input_height) - - if flags.ifShowDetObj == True: - imgCur = cv2.imread(current_img_size[2]) - - det_results_str = '' - for idx, class_ind in enumerate(predbox[:,5]): - if float(predbox[idx][4]) < float(flags.prob_thres): - continue - # skip negative class index - if class_ind < 0 or class_ind > 80: - continue - - class_name = CLASSES[int(class_ind)] - det_results_str += "{} {} {} {} {} {}\n".format(class_name, str(predbox[idx][4]), predbox[idx][0], - predbox[idx][1], predbox[idx][2], predbox[idx][3]) - if flags.ifShowDetObj == True: - imgCur=cv2.rectangle(imgCur, (int(predbox[idx][0]), int(predbox[idx][1])), - (int(predbox[idx][2]), int(predbox[idx][3])), (0,255,0), 1) - imgCur = cv2.putText(imgCur, class_name+'|'+str(predbox[idx][4]), - (int(predbox[idx][0]), int(predbox[idx][1])), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1) - # 图像,文字内容, 坐标 ,字体,大小,颜色,字体厚度 - - if flags.ifShowDetObj == True: - print(os.path.join(det_results_path, bin_file +'.jpg')) - cv2.imwrite(os.path.join(det_results_path, bin_file +'.jpg'), imgCur, [int(cv2.IMWRITE_JPEG_QUALITY),70]) - - det_results_file = os.path.join(det_results_path, bin_file + ".txt") - with open(det_results_file, "w") as detf: - detf.write(det_results_str) - print(det_results_str) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import numpy as np +import argparse +import cv2 + +CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', + 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', + 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', + 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', + 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', + 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', + 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', + 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', + 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', + 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', + 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', + 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] + +def coco_postprocess(bbox: np.ndarray, image_size, + net_input_width, net_input_height): + """ + This function is postprocessing for FasterRCNN output. + + Before calling this function, reshape the raw output of FasterRCNN to + following form + numpy.ndarray: + [x, y, width, height, confidence, probability of 80 classes] + shape: (100,) + The postprocessing restore the bounding rectangles of FasterRCNN output + to origin scale and filter with non-maximum suppression. + + :param bbox: a numpy array of the FasterRCNN output + :param image_path: a string of image path + :return: three list for best bound, class and score + """ + w = image_size[0] + h = image_size[1] + scale = min(net_input_width / w, net_input_height / h) + + pad_w = net_input_width - w * scale + pad_h = net_input_height - h * scale + pad_left = pad_w // 2 + pad_top = pad_h // 2 + + # cal predict box on the image src + pbox = bbox + pbox[:, 0] = (bbox[:, 0] - pad_left) / scale + pbox[:, 1] = (bbox[:, 1] - pad_top) / scale + pbox[:, 2] = (bbox[:, 2] - pad_left) / scale + pbox[:, 3] = (bbox[:, 3] - pad_top) / scale + return pbox + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0") + parser.add_argument("--test_annotation", default="./coco2017_jpg.info") + parser.add_argument("--det_results_path", default="./detection-results/") + parser.add_argument("--net_out_num", default=2) + parser.add_argument("--net_input_width", default=1216) + parser.add_argument("--net_input_height", default=1216) + parser.add_argument("--prob_thres", default=0.05) + parser.add_argument("--ifShowDetObj", action="store_true", help="if input the para means True, neither False.") + flags = parser.parse_args() + print(flags.ifShowDetObj, type(flags.ifShowDetObj)) + # generate dict according to annotation file for query resolution + # load width and height of input images + img_size_dict = dict() + with open(flags.test_annotation)as f: + for line in f.readlines(): + temp = line.split(" ") + img_file_path = temp[1] + img_name = temp[1].split("/")[-1].split(".")[0] + img_width = int(temp[2]) + img_height = int(temp[3]) + img_size_dict[img_name] = (img_width, img_height, img_file_path) + + # read bin file for generate predict result + bin_path = flags.bin_data_path + det_results_path = flags.det_results_path + os.makedirs(det_results_path, exist_ok=True) + total_img = set([name[:name.rfind('_')] + for name in os.listdir(bin_path) if "bin" in name]) + for bin_file in sorted(total_img): + path_base = os.path.join(bin_path, bin_file) + # load all detected output tensor + res_buff = [] + for num in range(1, flags.net_out_num + 1): + if os.path.exists(path_base + "_" + str(num) + ".bin"): + if num == 1: + buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="float32") + buf = np.reshape(buf, [100, 5]) + elif num == 2: + buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="int64") + buf = np.reshape(buf, [100, 1]) + res_buff.append(buf) + else: + print("[ERROR] file not exist", path_base + "_" + str(num) + ".bin") + res_tensor = np.concatenate(res_buff, axis=1) + current_img_size = img_size_dict[bin_file] + print("[TEST]---------------------------concat{} imgsize{}".format(len(res_tensor), current_img_size)) + predbox = coco_postprocess(res_tensor, current_img_size, flags.net_input_width, flags.net_input_height) + + if flags.ifShowDetObj == True: + imgCur = cv2.imread(current_img_size[2]) + + det_results_str = '' + for idx, class_ind in enumerate(predbox[:,5]): + if float(predbox[idx][4]) < float(flags.prob_thres): + continue + # skip negative class index + if class_ind < 0 or class_ind > 80: + continue + + class_name = CLASSES[int(class_ind)] + det_results_str += "{} {} {} {} {} {}\n".format(class_name, str(predbox[idx][4]), predbox[idx][0], + predbox[idx][1], predbox[idx][2], predbox[idx][3]) + if flags.ifShowDetObj == True: + imgCur=cv2.rectangle(imgCur, (int(predbox[idx][0]), int(predbox[idx][1])), + (int(predbox[idx][2]), int(predbox[idx][3])), (0,255,0), 1) + imgCur = cv2.putText(imgCur, class_name+'|'+str(predbox[idx][4]), + (int(predbox[idx][0]), int(predbox[idx][1])), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1) + # 图像,文字内容, 坐标 ,字体,大小,颜色,字体厚度 + + if flags.ifShowDetObj == True: + print(os.path.join(det_results_path, bin_file +'.jpg')) + cv2.imwrite(os.path.join(det_results_path, bin_file +'.jpg'), imgCur, [int(cv2.IMWRITE_JPEG_QUALITY),70]) + + det_results_file = os.path.join(det_results_path, bin_file + ".txt") + with open(det_results_file, "w") as detf: + detf.write(det_results_str) + print(det_results_str) diff --git a/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/mmdetection_coco_preprocess.py b/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/mmdetection_coco_preprocess.py index 4a6cd14f9329be81e615212af1140b6f662b27ab..fc8c2c5293a0029a5ac97c48996931f4c6a99820 100644 --- a/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/mmdetection_coco_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/mmdetection_coco_preprocess.py @@ -1,68 +1,68 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import numpy as np -import os -import cv2 -import argparse -import mmcv -import torch - -dataset_config = { - 'resize': (1216, 1216), - 'mean': [123.675, 116.28, 103.53], - 'std': [58.395, 57.12, 57.375], -} - -tensor_height = 1216 -tensor_width = 1216 - -def coco_preprocess(input_image, output_bin_path): - #define the output file name - img_name = input_image.split('/')[-1] - bin_name = img_name.split('.')[0] + ".bin" - bin_fl = os.path.join(output_bin_path, bin_name) - - one_img = mmcv.imread(os.path.join(input_image), backend='cv2') - one_img = mmcv.imrescale(one_img, (tensor_height, tensor_width)) - # calculate padding - h = one_img.shape[0] - w = one_img.shape[1] - pad_left = (tensor_width - w) // 2 - pad_top = (tensor_height - h) // 2 - pad_right = tensor_width - pad_left - w - pad_bottom = tensor_height - pad_top - h - - mean = np.array(dataset_config['mean'], dtype=np.float32) - std = np.array(dataset_config['std'], dtype=np.float32) - one_img = mmcv.imnormalize(one_img, mean, std) - one_img = mmcv.impad(one_img, padding=(pad_left, pad_top, pad_right, pad_bottom), pad_val=0) - one_img = one_img.transpose(2, 0, 1) - one_img.tofile(bin_fl) - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='preprocess of FasterRCNN pytorch model') - parser.add_argument("--image_folder_path", default="./coco2014/", help='image of dataset') - parser.add_argument("--bin_folder_path", default="./coco2014_bin/", help='Preprocessed image buffer') - flags = parser.parse_args() - - if not os.path.exists(flags.bin_folder_path): - os.makedirs(flags.bin_folder_path) - images = os.listdir(flags.image_folder_path) - for image_name in images: - if not (image_name.endswith(".jpeg") or image_name.endswith(".JPEG") or image_name.endswith(".jpg")): - continue - print("start to process image {}....".format(image_name)) - path_image = os.path.join(flags.image_folder_path, image_name) - coco_preprocess(path_image, flags.bin_folder_path) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +import os +import cv2 +import argparse +import mmcv +import torch + +dataset_config = { + 'resize': (1216, 1216), + 'mean': [123.675, 116.28, 103.53], + 'std': [58.395, 57.12, 57.375], +} + +tensor_height = 1216 +tensor_width = 1216 + +def coco_preprocess(input_image, output_bin_path): + #define the output file name + img_name = input_image.split('/')[-1] + bin_name = img_name.split('.')[0] + ".bin" + bin_fl = os.path.join(output_bin_path, bin_name) + + one_img = mmcv.imread(os.path.join(input_image), backend='cv2') + one_img = mmcv.imrescale(one_img, (tensor_height, tensor_width)) + # calculate padding + h = one_img.shape[0] + w = one_img.shape[1] + pad_left = (tensor_width - w) // 2 + pad_top = (tensor_height - h) // 2 + pad_right = tensor_width - pad_left - w + pad_bottom = tensor_height - pad_top - h + + mean = np.array(dataset_config['mean'], dtype=np.float32) + std = np.array(dataset_config['std'], dtype=np.float32) + one_img = mmcv.imnormalize(one_img, mean, std) + one_img = mmcv.impad(one_img, padding=(pad_left, pad_top, pad_right, pad_bottom), pad_val=0) + one_img = one_img.transpose(2, 0, 1) + one_img.tofile(bin_fl) + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='preprocess of FasterRCNN pytorch model') + parser.add_argument("--image_folder_path", default="./coco2014/", help='image of dataset') + parser.add_argument("--bin_folder_path", default="./coco2014_bin/", help='Preprocessed image buffer') + flags = parser.parse_args() + + if not os.path.exists(flags.bin_folder_path): + os.makedirs(flags.bin_folder_path) + images = os.listdir(flags.image_folder_path) + for image_name in images: + if not (image_name.endswith(".jpeg") or image_name.endswith(".JPEG") or image_name.endswith(".jpg")): + continue + print("start to process image {}....".format(image_name)) + path_image = os.path.join(flags.image_folder_path, image_name) + coco_preprocess(path_image, flags.bin_folder_path) diff --git a/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/requirements.txt b/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/requirements.txt index fcabf40ea57e03ae306ddb75476c08e25e73bd84..3dfcf9563e211857c3b68c55591852f0e43b8f2e 100644 --- a/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/requirements.txt +++ b/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/requirements.txt @@ -1,6 +1,6 @@ -torch==1.7.0 -torchvision==0.8.0 -onnx==1.8.0 -mmdet==2.8.0 -mmcv-full==1.2.4 +torch==1.7.0 +torchvision==0.8.0 +onnx==1.8.0 +mmdet==2.8.0 +mmcv-full==1.2.4 onnxruntime==1.9.0 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/txt_to_json.py b/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/txt_to_json.py index a2346a773d0aff8587ff5c2904aead9624e6fa2e..9f479da6a0b3ef156b57c415fab48801ee5f69cd 100644 --- a/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/txt_to_json.py +++ b/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN/txt_to_json.py @@ -1,114 +1,114 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import glob -import os -import sys -import argparse -import mmcv - -CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', - 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', - 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', - 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', - 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', - 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', - 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', - 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', - 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', - 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', - 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', - 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] - -cat_ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, -24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, -48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, -72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90] - -''' - 0,0 ------> x (width) - | - | (Left,Top) - | *_________ - | | | - | | - y |_________| - (height) * - (Right,Bottom) -''' - -def file_lines_to_list(path): - # open txt file lines to a list - with open(path) as f: - content = f.readlines() - # remove whitespace characters like `\n` at the end of each line - content = [x.strip() for x in content] - return content - - -def error(msg): - print(msg) - sys.exit(0) - - -def get_predict_list(file_path, gt_classes): - dr_files_list = glob.glob(file_path + '/*.txt') - dr_files_list.sort() - - bounding_boxes = [] - for txt_file in dr_files_list: - file_id = txt_file.split(".txt", 1)[0] - file_id = os.path.basename(os.path.normpath(file_id)) - lines = file_lines_to_list(txt_file) - for line in lines: - try: - sl = line.split() - if len(sl) > 6: - class_name = sl[0] + ' ' + sl[1] - scores, left, top, right, bottom = sl[2:] - else: - class_name, scores, left, top, right, bottom = sl - if float(scores) < 0.05: - continue - except ValueError: - error_msg = "Error: File " + txt_file + " wrong format.\n" - error_msg += " Expected: \n" - error_msg += " Received: " + line - error(error_msg) - - # bbox = left + " " + top + " " + right + " " + bottom - left = float(left) - right = float(right) - top = float(top) - bottom = float(bottom) - bbox = [left, top, right-left, bottom-top] - bounding_boxes.append({"image_id": int(file_id), "bbox": bbox, - "score": float(scores), "category_id": cat_ids[CLASSES.index(class_name)]}) - # sort detection-results by decreasing scores - # bounding_boxes.sort(key=lambda x: float(x['score']), reverse=True) - return bounding_boxes - - - -if __name__ == '__main__': - parser = argparse.ArgumentParser('mAp calculate') - parser.add_argument('--npu_txt_path', default="detection-results", - help='the path of the predict result') - parser.add_argument("--json_output_file", default="coco_detection_result") - args = parser.parse_args() - - res_bbox = get_predict_list(args.npu_txt_path, CLASSES) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import glob +import os +import sys +import argparse +import mmcv + +CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', + 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', + 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', + 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', + 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', + 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', + 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', + 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', + 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', + 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', + 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', + 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] + +cat_ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, +24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, +48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, +72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90] + +''' + 0,0 ------> x (width) + | + | (Left,Top) + | *_________ + | | | + | | + y |_________| + (height) * + (Right,Bottom) +''' + +def file_lines_to_list(path): + # open txt file lines to a list + with open(path) as f: + content = f.readlines() + # remove whitespace characters like `\n` at the end of each line + content = [x.strip() for x in content] + return content + + +def error(msg): + print(msg) + sys.exit(0) + + +def get_predict_list(file_path, gt_classes): + dr_files_list = glob.glob(file_path + '/*.txt') + dr_files_list.sort() + + bounding_boxes = [] + for txt_file in dr_files_list: + file_id = txt_file.split(".txt", 1)[0] + file_id = os.path.basename(os.path.normpath(file_id)) + lines = file_lines_to_list(txt_file) + for line in lines: + try: + sl = line.split() + if len(sl) > 6: + class_name = sl[0] + ' ' + sl[1] + scores, left, top, right, bottom = sl[2:] + else: + class_name, scores, left, top, right, bottom = sl + if float(scores) < 0.05: + continue + except ValueError: + error_msg = "Error: File " + txt_file + " wrong format.\n" + error_msg += " Expected: \n" + error_msg += " Received: " + line + error(error_msg) + + # bbox = left + " " + top + " " + right + " " + bottom + left = float(left) + right = float(right) + top = float(top) + bottom = float(bottom) + bbox = [left, top, right-left, bottom-top] + bounding_boxes.append({"image_id": int(file_id), "bbox": bbox, + "score": float(scores), "category_id": cat_ids[CLASSES.index(class_name)]}) + # sort detection-results by decreasing scores + # bounding_boxes.sort(key=lambda x: float(x['score']), reverse=True) + return bounding_boxes + + + +if __name__ == '__main__': + parser = argparse.ArgumentParser('mAp calculate') + parser.add_argument('--npu_txt_path', default="detection-results", + help='the path of the predict result') + parser.add_argument("--json_output_file", default="coco_detection_result") + args = parser.parse_args() + + res_bbox = get_predict_list(args.npu_txt_path, CLASSES) mmcv.dump(res_bbox, args.json_output_file + '.json') \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/README.md b/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/README.md index 085891be0df48d6e7d3afb6df61119a67c216e8f..d76158104c6fed3e4738b379356c70cf431200a6 100644 --- a/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/README.md +++ b/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/README.md @@ -1,57 +1,57 @@ -# Casacde_RCNN_R101模型PyTorch离线推理指导 - -## 1 环境准备 - -1. 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - -``` -pip3.7 install -r requirements.txt -``` - -2. 获取,修改与安装开源模型代码 - -``` -git clone https://github.com/open-mmlab/mmdetection.git -cd mmdetection -git reset a21eb25535f31634cef332b09fc27d28956fb24b --hard -pip3.7 install -v -e . -patch -p1 < ../Cascade_RCNN_R101.patch -cd .. -``` - -利用提供的change文件夹中的patch文件,完成补丁操作,命令参考如下示例,请用户根据安装包位置自行修改: -``` -cd change -patch -p0 /usr/local/python3.7.5/lib/python3.7/site-packages/mmcv/ops/deform_conv.py deform_conv.patch -cd ../ -``` - - -3. 获取权重文件 - - 从[LINK](https://github.com/open-mmlab/mmdetection/tree/master/configs/cascade_rcnn)下载cascade_rcnn模型权重文件 - -4. 数据集 - 本模型使用coco2017的验证集验证 - -5. [获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) -将benchmark.x86_64或benchmark.aarch64放到当前目录 - - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=./ -``` - - -**评测结果:** - -| 模型 | 官网pth精度 | 310离线推理精度 | gpu性能 | 310性能 | -| :---------------: | :---------: | :-------------: | :-----: | :------: | -| Cascade_RCNN_R101 bs1 | map:0.42 | map:0.42 | 4.8task/s | 5.667fps | - - - +# Casacde_RCNN_R101模型PyTorch离线推理指导 + +## 1 环境准备 + +1. 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + +``` +pip3.7 install -r requirements.txt +``` + +2. 获取,修改与安装开源模型代码 + +``` +git clone https://github.com/open-mmlab/mmdetection.git +cd mmdetection +git reset a21eb25535f31634cef332b09fc27d28956fb24b --hard +pip3.7 install -v -e . +patch -p1 < ../Cascade_RCNN_R101.patch +cd .. +``` + +利用提供的change文件夹中的patch文件,完成补丁操作,命令参考如下示例,请用户根据安装包位置自行修改: +``` +cd change +patch -p0 /usr/local/python3.7.5/lib/python3.7/site-packages/mmcv/ops/deform_conv.py deform_conv.patch +cd ../ +``` + + +3. 获取权重文件 + + 从[LINK](https://github.com/open-mmlab/mmdetection/tree/master/configs/cascade_rcnn)下载cascade_rcnn模型权重文件 + +4. 数据集 + 本模型使用coco2017的验证集验证 + +5. [获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) +将benchmark.x86_64或benchmark.aarch64放到当前目录 + + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=./ +``` + + +**评测结果:** + +| 模型 | 官网pth精度 | 310离线推理精度 | gpu性能 | 310性能 | +| :---------------: | :---------: | :-------------: | :-----: | :------: | +| Cascade_RCNN_R101 bs1 | map:0.42 | map:0.42 | 4.8task/s | 5.667fps | + + + diff --git a/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/get_info.py b/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/get_info.py index 5af675c6b0ae3f28a6f191d139ebb44e775e6c1c..fc6cdebb5b4417a3651c1e6e9663d8d1299a0ef5 100644 --- a/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/get_info.py +++ b/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/get_info.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/mmdetection_coco_postprocess.py b/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/mmdetection_coco_postprocess.py index 5ca79ff17fe6ecb89a9aa72740147e599eb62dba..a4bcab73b951c2cf4af9cced603f2e009ee58763 100644 --- a/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/mmdetection_coco_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/mmdetection_coco_postprocess.py @@ -1,276 +1,276 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import numpy as np -import cv2 -import glob -import sys -import argparse -import mmcv -from pycocotools.coco import COCO -from pycocotools.cocoeval import COCOeval - -CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', - 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', - 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', - 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', - 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', - 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', - 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', - 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', - 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', - 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', - 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', - 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] - -cat_ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, -24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, -48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, -72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90] - -def coco_postprocess(bbox: np.ndarray, image_size, - net_input_width, net_input_height): - """ - This function is postprocessing for FasterRCNN output. - - Before calling this function, reshape the raw output of FasterRCNN to - following form - numpy.ndarray: - [x, y, width, height, confidence, probability of 80 classes] - shape: (100,) - The postprocessing restore the bounding rectangles of FasterRCNN output - to origin scale and filter with non-maximum suppression. - - :param bbox: a numpy array of the FasterRCNN output - :param image_path: a string of image path - :return: three list for best bound, class and score - """ - w = image_size[0] - h = image_size[1] - scale = min(net_input_width / w, net_input_height / h) - - pad_w = net_input_width - w * scale - pad_h = net_input_height - h * scale - pad_left = pad_w // 2 - pad_top = pad_h // 2 - - # cal predict box on the image src - pbox = bbox - pbox[:, 0] = (bbox[:, 0] - pad_left) / scale - pbox[:, 1] = (bbox[:, 1] - pad_top) / scale - pbox[:, 2] = (bbox[:, 2] - pad_left) / scale - pbox[:, 3] = (bbox[:, 3] - pad_top) / scale - - # make pbboxes value in valid range - pbox[:, 0] = np.maximum(pbox[:, 0], 0) - pbox[:, 1] = np.maximum(pbox[:, 1], 0) - pbox[:, 2] = np.minimum(pbox[:, 2], w) - pbox[:, 3] = np.minimum(pbox[:, 3], h) - return pbox -def file_lines_to_list(path): - # open txt file lines to a list - with open(path) as f: - content = f.readlines() - # remove whitespace characters like `\n` at the end of each line - content = [x.strip() for x in content] - return content - - -def error(msg): - print(msg) - sys.exit(0) - - -def get_predict_list(file_path, gt_classes): - dr_files_list = glob.glob(file_path + '/*.txt') - dr_files_list.sort() - - bounding_boxes = [] - for txt_file in dr_files_list: - file_id = txt_file.split(".txt", 1)[0] - file_id = os.path.basename(os.path.normpath(file_id)) - lines = file_lines_to_list(txt_file) - for line in lines: - try: - sl = line.split() - if len(sl) > 6: - class_name = sl[0] + ' ' + sl[1] - scores, left, top, right, bottom = sl[2:] - else: - class_name, scores, left, top, right, bottom = sl - if float(scores) < 0.05: - continue - except ValueError: - error_msg = "Error: File " + txt_file + " wrong format.\n" - error_msg += " Expected: \n" - error_msg += " Received: " + line - error(error_msg) - - # bbox = left + " " + top + " " + right + " " + bottom - left = float(left) - right = float(right) - top = float(top) - bottom = float(bottom) - bbox = [left, top, right-left, bottom-top] - bounding_boxes.append({"image_id": int(file_id), "bbox": bbox, - "score": float(scores), "category_id": cat_ids[CLASSES.index(class_name)]}) - # sort detection-results by decreasing scores - # bounding_boxes.sort(key=lambda x: float(x['score']), reverse=True) - return bounding_boxes -def coco_evaluation(annotation_json, result_json): - cocoGt = COCO(annotation_json) - cocoDt = cocoGt.loadRes(result_json) - iou_thrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True) - iou_type = 'bbox' - - cocoEval = COCOeval(cocoGt, cocoDt, iou_type) - cocoEval.params.catIds = cocoGt.get_cat_ids(cat_names=CLASSES) - cocoEval.params.imgIds = cocoGt.get_img_ids() - cocoEval.params.maxDets = [100, 300, 1000] # proposal number for evaluating recalls/mAPs. - cocoEval.params.iouThrs = iou_thrs - - cocoEval.evaluate() - cocoEval.accumulate() - cocoEval.summarize() - - # mapping of cocoEval.stats - coco_metric_names = { - 'mAP': 0, - 'mAP_50': 1, - 'mAP_75': 2, - 'mAP_s': 3, - 'mAP_m': 4, - 'mAP_l': 5, - 'AR@100': 6, - 'AR@300': 7, - 'AR@1000': 8, - 'AR_s@1000': 9, - 'AR_m@1000': 10, - 'AR_l@1000': 11 - } - - metric_items = ['mAP', 'mAP_50', 'mAP_75', 'mAP_s', 'mAP_m', 'mAP_l'] - eval_results = {} - - for metric_item in metric_items: - key = f'bbox_{metric_item}' - val = float( - f'{cocoEval.stats[coco_metric_names[metric_item]]:.3f}' - ) - eval_results[key] = val - ap = cocoEval.stats[:6] - eval_results['bbox_mAP_copypaste'] = ( - f'{ap[0]:.3f} {ap[1]:.3f} {ap[2]:.3f} {ap[3]:.3f} ' - f'{ap[4]:.3f} {ap[5]:.3f}') - - return eval_results - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0") - parser.add_argument("--test_annotation", default="./coco2017_jpg.info") - parser.add_argument("--det_results_path", default="./detection-results") - parser.add_argument("--img_path", default="./val2017/") - parser.add_argument("--net_out_num", default=2) - parser.add_argument("--net_input_width", default=1216) - parser.add_argument("--net_input_height", default=1216) - parser.add_argument("--prob_thres", default=0.05) - parser.add_argument("--ifShowDetObj", action="store_true", help="if input the para means True, neither False.") - parser.add_argument('--npu_txt_path', default="detection-results", - help='the path of the predict result') - parser.add_argument("--json_output_file", default="coco_detection_result") - parser.add_argument("--ground_truth", default="instances_val2017.json") - parser.add_argument("--detection_result", default="coco_detection_result.json") - flags = parser.parse_args() - print(flags.ifShowDetObj, type(flags.ifShowDetObj)) - # generate dict according to annotation file for query resolution - # load width and height of input images - img_size_dict = dict() - with open(flags.test_annotation)as f: - for line in f.readlines(): - temp = line.split(" ") - img_file_path = temp[1] - img_name = temp[1].split("/")[-1].split(".")[0] - img_width = int(temp[2]) - img_height = int(temp[3]) - img_size_dict[img_name] = (img_width, img_height, img_file_path) - - # read bin file for generate predict result - bin_path = flags.bin_data_path - det_results_path = flags.det_results_path - img_path = flags.img_path - os.makedirs(det_results_path, exist_ok=True) - total_img = set([name[:name.rfind('_')] - for name in os.listdir(bin_path) if "bin" in name]) - for bin_file in sorted(total_img): - path_base = os.path.join(bin_path, bin_file) - # load all detected output tensor - res_buff = [] - for num in range(1, flags.net_out_num + 1): - if os.path.exists(path_base + "_" + str(num) + ".bin"): - if num == 1: - buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="float32") - buf = np.reshape(buf, [100, 5]) - elif num == 2: - buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="int64") - buf = np.reshape(buf, [100, 1]) - res_buff.append(buf) - else: - print("[ERROR] file not exist", path_base + "_" + str(num) + ".bin") - res_tensor = np.concatenate(res_buff, axis=1) - current_img_size = img_size_dict[bin_file] - print("[TEST]---------------------------concat{} imgsize{}".format(len(res_tensor), current_img_size)) - predbox = coco_postprocess(res_tensor, current_img_size, flags.net_input_width, flags.net_input_height) - - if flags.ifShowDetObj == True: - pic = os.path.join(img_path, bin_file +'.jpg') - imgCur = cv2.imread(pic) - - det_results_str = '' - for idx, class_ind in enumerate(predbox[:,5]): - if float(predbox[idx][4]) < float(flags.prob_thres): - continue - # skip negative class index - if class_ind < 0 or class_ind > 80: - continue - - class_name = CLASSES[int(class_ind)] - det_results_str += "{} {} {} {} {} {}\n".format(class_name, str(predbox[idx][4]), predbox[idx][0], - predbox[idx][1], predbox[idx][2], predbox[idx][3]) - if flags.ifShowDetObj == True: - imgCur=cv2.rectangle(imgCur, (int(predbox[idx][0]), int(predbox[idx][1])), - (int(predbox[idx][2]), int(predbox[idx][3])), (0,255,0), 1) - imgCur = cv2.putText(imgCur, class_name+'|'+str(predbox[idx][4]), - (int(predbox[idx][0]), int(predbox[idx][1])), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1) - # 图像,文字内容, 坐标 ,字体,大小,颜色,字体厚度 - - if flags.ifShowDetObj == True: - print(os.path.join(det_results_path, bin_file +'.jpg')) - cv2.imwrite(os.path.join(det_results_path, bin_file +'.jpg'), imgCur, [int(cv2.IMWRITE_JPEG_QUALITY),70]) - - det_results_file = os.path.join(det_results_path, bin_file + ".txt") - with open(det_results_file, "w") as detf: - detf.write(det_results_str) - print(det_results_str) - - res_bbox = get_predict_list(flags.npu_txt_path, CLASSES) - mmcv.dump(res_bbox, flags.json_output_file + '.json') - result = coco_evaluation(flags.ground_truth, flags.detection_result) - print(result) - with open('./coco_detection_result.txt', 'w') as f: - for key, value in result.items(): +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import numpy as np +import cv2 +import glob +import sys +import argparse +import mmcv +from pycocotools.coco import COCO +from pycocotools.cocoeval import COCOeval + +CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', + 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', + 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', + 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', + 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', + 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', + 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', + 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', + 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', + 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', + 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', + 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] + +cat_ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, +24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, +48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, +72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90] + +def coco_postprocess(bbox: np.ndarray, image_size, + net_input_width, net_input_height): + """ + This function is postprocessing for FasterRCNN output. + + Before calling this function, reshape the raw output of FasterRCNN to + following form + numpy.ndarray: + [x, y, width, height, confidence, probability of 80 classes] + shape: (100,) + The postprocessing restore the bounding rectangles of FasterRCNN output + to origin scale and filter with non-maximum suppression. + + :param bbox: a numpy array of the FasterRCNN output + :param image_path: a string of image path + :return: three list for best bound, class and score + """ + w = image_size[0] + h = image_size[1] + scale = min(net_input_width / w, net_input_height / h) + + pad_w = net_input_width - w * scale + pad_h = net_input_height - h * scale + pad_left = pad_w // 2 + pad_top = pad_h // 2 + + # cal predict box on the image src + pbox = bbox + pbox[:, 0] = (bbox[:, 0] - pad_left) / scale + pbox[:, 1] = (bbox[:, 1] - pad_top) / scale + pbox[:, 2] = (bbox[:, 2] - pad_left) / scale + pbox[:, 3] = (bbox[:, 3] - pad_top) / scale + + # make pbboxes value in valid range + pbox[:, 0] = np.maximum(pbox[:, 0], 0) + pbox[:, 1] = np.maximum(pbox[:, 1], 0) + pbox[:, 2] = np.minimum(pbox[:, 2], w) + pbox[:, 3] = np.minimum(pbox[:, 3], h) + return pbox +def file_lines_to_list(path): + # open txt file lines to a list + with open(path) as f: + content = f.readlines() + # remove whitespace characters like `\n` at the end of each line + content = [x.strip() for x in content] + return content + + +def error(msg): + print(msg) + sys.exit(0) + + +def get_predict_list(file_path, gt_classes): + dr_files_list = glob.glob(file_path + '/*.txt') + dr_files_list.sort() + + bounding_boxes = [] + for txt_file in dr_files_list: + file_id = txt_file.split(".txt", 1)[0] + file_id = os.path.basename(os.path.normpath(file_id)) + lines = file_lines_to_list(txt_file) + for line in lines: + try: + sl = line.split() + if len(sl) > 6: + class_name = sl[0] + ' ' + sl[1] + scores, left, top, right, bottom = sl[2:] + else: + class_name, scores, left, top, right, bottom = sl + if float(scores) < 0.05: + continue + except ValueError: + error_msg = "Error: File " + txt_file + " wrong format.\n" + error_msg += " Expected: \n" + error_msg += " Received: " + line + error(error_msg) + + # bbox = left + " " + top + " " + right + " " + bottom + left = float(left) + right = float(right) + top = float(top) + bottom = float(bottom) + bbox = [left, top, right-left, bottom-top] + bounding_boxes.append({"image_id": int(file_id), "bbox": bbox, + "score": float(scores), "category_id": cat_ids[CLASSES.index(class_name)]}) + # sort detection-results by decreasing scores + # bounding_boxes.sort(key=lambda x: float(x['score']), reverse=True) + return bounding_boxes +def coco_evaluation(annotation_json, result_json): + cocoGt = COCO(annotation_json) + cocoDt = cocoGt.loadRes(result_json) + iou_thrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True) + iou_type = 'bbox' + + cocoEval = COCOeval(cocoGt, cocoDt, iou_type) + cocoEval.params.catIds = cocoGt.get_cat_ids(cat_names=CLASSES) + cocoEval.params.imgIds = cocoGt.get_img_ids() + cocoEval.params.maxDets = [100, 300, 1000] # proposal number for evaluating recalls/mAPs. + cocoEval.params.iouThrs = iou_thrs + + cocoEval.evaluate() + cocoEval.accumulate() + cocoEval.summarize() + + # mapping of cocoEval.stats + coco_metric_names = { + 'mAP': 0, + 'mAP_50': 1, + 'mAP_75': 2, + 'mAP_s': 3, + 'mAP_m': 4, + 'mAP_l': 5, + 'AR@100': 6, + 'AR@300': 7, + 'AR@1000': 8, + 'AR_s@1000': 9, + 'AR_m@1000': 10, + 'AR_l@1000': 11 + } + + metric_items = ['mAP', 'mAP_50', 'mAP_75', 'mAP_s', 'mAP_m', 'mAP_l'] + eval_results = {} + + for metric_item in metric_items: + key = f'bbox_{metric_item}' + val = float( + f'{cocoEval.stats[coco_metric_names[metric_item]]:.3f}' + ) + eval_results[key] = val + ap = cocoEval.stats[:6] + eval_results['bbox_mAP_copypaste'] = ( + f'{ap[0]:.3f} {ap[1]:.3f} {ap[2]:.3f} {ap[3]:.3f} ' + f'{ap[4]:.3f} {ap[5]:.3f}') + + return eval_results + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0") + parser.add_argument("--test_annotation", default="./coco2017_jpg.info") + parser.add_argument("--det_results_path", default="./detection-results") + parser.add_argument("--img_path", default="./val2017/") + parser.add_argument("--net_out_num", default=2) + parser.add_argument("--net_input_width", default=1216) + parser.add_argument("--net_input_height", default=1216) + parser.add_argument("--prob_thres", default=0.05) + parser.add_argument("--ifShowDetObj", action="store_true", help="if input the para means True, neither False.") + parser.add_argument('--npu_txt_path', default="detection-results", + help='the path of the predict result') + parser.add_argument("--json_output_file", default="coco_detection_result") + parser.add_argument("--ground_truth", default="instances_val2017.json") + parser.add_argument("--detection_result", default="coco_detection_result.json") + flags = parser.parse_args() + print(flags.ifShowDetObj, type(flags.ifShowDetObj)) + # generate dict according to annotation file for query resolution + # load width and height of input images + img_size_dict = dict() + with open(flags.test_annotation)as f: + for line in f.readlines(): + temp = line.split(" ") + img_file_path = temp[1] + img_name = temp[1].split("/")[-1].split(".")[0] + img_width = int(temp[2]) + img_height = int(temp[3]) + img_size_dict[img_name] = (img_width, img_height, img_file_path) + + # read bin file for generate predict result + bin_path = flags.bin_data_path + det_results_path = flags.det_results_path + img_path = flags.img_path + os.makedirs(det_results_path, exist_ok=True) + total_img = set([name[:name.rfind('_')] + for name in os.listdir(bin_path) if "bin" in name]) + for bin_file in sorted(total_img): + path_base = os.path.join(bin_path, bin_file) + # load all detected output tensor + res_buff = [] + for num in range(1, flags.net_out_num + 1): + if os.path.exists(path_base + "_" + str(num) + ".bin"): + if num == 1: + buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="float32") + buf = np.reshape(buf, [100, 5]) + elif num == 2: + buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="int64") + buf = np.reshape(buf, [100, 1]) + res_buff.append(buf) + else: + print("[ERROR] file not exist", path_base + "_" + str(num) + ".bin") + res_tensor = np.concatenate(res_buff, axis=1) + current_img_size = img_size_dict[bin_file] + print("[TEST]---------------------------concat{} imgsize{}".format(len(res_tensor), current_img_size)) + predbox = coco_postprocess(res_tensor, current_img_size, flags.net_input_width, flags.net_input_height) + + if flags.ifShowDetObj == True: + pic = os.path.join(img_path, bin_file +'.jpg') + imgCur = cv2.imread(pic) + + det_results_str = '' + for idx, class_ind in enumerate(predbox[:,5]): + if float(predbox[idx][4]) < float(flags.prob_thres): + continue + # skip negative class index + if class_ind < 0 or class_ind > 80: + continue + + class_name = CLASSES[int(class_ind)] + det_results_str += "{} {} {} {} {} {}\n".format(class_name, str(predbox[idx][4]), predbox[idx][0], + predbox[idx][1], predbox[idx][2], predbox[idx][3]) + if flags.ifShowDetObj == True: + imgCur=cv2.rectangle(imgCur, (int(predbox[idx][0]), int(predbox[idx][1])), + (int(predbox[idx][2]), int(predbox[idx][3])), (0,255,0), 1) + imgCur = cv2.putText(imgCur, class_name+'|'+str(predbox[idx][4]), + (int(predbox[idx][0]), int(predbox[idx][1])), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1) + # 图像,文字内容, 坐标 ,字体,大小,颜色,字体厚度 + + if flags.ifShowDetObj == True: + print(os.path.join(det_results_path, bin_file +'.jpg')) + cv2.imwrite(os.path.join(det_results_path, bin_file +'.jpg'), imgCur, [int(cv2.IMWRITE_JPEG_QUALITY),70]) + + det_results_file = os.path.join(det_results_path, bin_file + ".txt") + with open(det_results_file, "w") as detf: + detf.write(det_results_str) + print(det_results_str) + + res_bbox = get_predict_list(flags.npu_txt_path, CLASSES) + mmcv.dump(res_bbox, flags.json_output_file + '.json') + result = coco_evaluation(flags.ground_truth, flags.detection_result) + print(result) + with open('./coco_detection_result.txt', 'w') as f: + for key, value in result.items(): f.write(key + ': ' + str(value) + '\n') \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/mmdetection_coco_preprocess.py b/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/mmdetection_coco_preprocess.py index c6f3b7429ec1a447a6c320ab6a84bff1cd6923ad..f7fc5568a9ca2fd4109f8c4c1a060fb7fc2e24d3 100644 --- a/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/mmdetection_coco_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/mmdetection_coco_preprocess.py @@ -1,68 +1,68 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import numpy as np -import os -import cv2 -import argparse -import mmcv -import torch - -dataset_config = { - 'resize': (1216, 1216), - 'mean': [123.675, 116.28, 103.53], - 'std': [58.395, 57.12, 57.375], -} - -tensor_height = 1216 -tensor_width = 1216 - -def coco_preprocess(input_image, output_bin_path): - #define the output file name - img_name = input_image.split('/')[-1] - bin_name = img_name.split('.')[0] + ".bin" - bin_fl = os.path.join(output_bin_path, bin_name) - - one_img = mmcv.imread(os.path.join(input_image), backend='cv2') - one_img = mmcv.imrescale(one_img, (tensor_height, tensor_width)) - # calculate padding - h = one_img.shape[0] - w = one_img.shape[1] - pad_left = (tensor_width - w) // 2 - pad_top = (tensor_height - h) // 2 - pad_right = tensor_width - pad_left - w - pad_bottom = tensor_height - pad_top - h - - mean = np.array(dataset_config['mean'], dtype=np.float32) - std = np.array(dataset_config['std'], dtype=np.float32) - one_img = mmcv.imnormalize(one_img, mean, std) - one_img = mmcv.impad(one_img, padding=(pad_left, pad_top, pad_right, pad_bottom), pad_val=0) - one_img = one_img.transpose(2, 0, 1) - one_img.tofile(bin_fl) - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='preprocess of NAS-FPN pytorch model') - parser.add_argument("--image_folder_path", default="./coco2017/", help='image of dataset') - parser.add_argument("--bin_folder_path", default="./coco2017_bin/", help='Preprocessed image buffer') - flags = parser.parse_args() - - if not os.path.exists(flags.bin_folder_path): - os.makedirs(flags.bin_folder_path) - images = os.listdir(flags.image_folder_path) - for image_name in images: - if not (image_name.endswith(".jpeg") or image_name.endswith(".JPEG") or image_name.endswith(".jpg")): - continue - print("start to process image {}....".format(image_name)) - path_image = os.path.join(flags.image_folder_path, image_name) - coco_preprocess(path_image, flags.bin_folder_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +import os +import cv2 +import argparse +import mmcv +import torch + +dataset_config = { + 'resize': (1216, 1216), + 'mean': [123.675, 116.28, 103.53], + 'std': [58.395, 57.12, 57.375], +} + +tensor_height = 1216 +tensor_width = 1216 + +def coco_preprocess(input_image, output_bin_path): + #define the output file name + img_name = input_image.split('/')[-1] + bin_name = img_name.split('.')[0] + ".bin" + bin_fl = os.path.join(output_bin_path, bin_name) + + one_img = mmcv.imread(os.path.join(input_image), backend='cv2') + one_img = mmcv.imrescale(one_img, (tensor_height, tensor_width)) + # calculate padding + h = one_img.shape[0] + w = one_img.shape[1] + pad_left = (tensor_width - w) // 2 + pad_top = (tensor_height - h) // 2 + pad_right = tensor_width - pad_left - w + pad_bottom = tensor_height - pad_top - h + + mean = np.array(dataset_config['mean'], dtype=np.float32) + std = np.array(dataset_config['std'], dtype=np.float32) + one_img = mmcv.imnormalize(one_img, mean, std) + one_img = mmcv.impad(one_img, padding=(pad_left, pad_top, pad_right, pad_bottom), pad_val=0) + one_img = one_img.transpose(2, 0, 1) + one_img.tofile(bin_fl) + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='preprocess of NAS-FPN pytorch model') + parser.add_argument("--image_folder_path", default="./coco2017/", help='image of dataset') + parser.add_argument("--bin_folder_path", default="./coco2017_bin/", help='Preprocessed image buffer') + flags = parser.parse_args() + + if not os.path.exists(flags.bin_folder_path): + os.makedirs(flags.bin_folder_path) + images = os.listdir(flags.image_folder_path) + for image_name in images: + if not (image_name.endswith(".jpeg") or image_name.endswith(".JPEG") or image_name.endswith(".jpg")): + continue + print("start to process image {}....".format(image_name)) + path_image = os.path.join(flags.image_folder_path, image_name) + coco_preprocess(path_image, flags.bin_folder_path) diff --git a/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/requirements.txt b/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/requirements.txt index a9b2aff748d181f465deadd5f1eb2cef543efb5d..bbcf70abd1d45bdd4747a59f08891e33df32c837 100644 --- a/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/requirements.txt +++ b/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101/requirements.txt @@ -1,10 +1,10 @@ -torch==1.7.0 -torchvision==0.8.0 -onnx==1.8.0 -numpy==1.20.0 -mmdet==2.8.0 -mmcv-full==1.2.4 -opencv-python==4.4.0.46 -mmpycocotools==12.0.3 -onnxruntime==1.9.0 - +torch==1.7.0 +torchvision==0.8.0 +onnx==1.8.0 +numpy==1.20.0 +mmdet==2.8.0 +mmcv-full==1.2.4 +opencv-python==4.4.0.46 +mmpycocotools==12.0.3 +onnxruntime==1.9.0 + diff --git a/ACL_PyTorch/contrib/cv/detection/CenterFace/README.md b/ACL_PyTorch/contrib/cv/detection/CenterFace/README.md index db88ee778c56508e8f8c111427c67dc754cb261e..7d456ee6fbd43b41bd39b5fbacd153c6ae159dc4 100644 --- a/ACL_PyTorch/contrib/cv/detection/CenterFace/README.md +++ b/ACL_PyTorch/contrib/cv/detection/CenterFace/README.md @@ -1,300 +1,300 @@ -# CenterFace Onnx模型端到端推理指导 - -- 1 模型概述 - - [1.1 论文地址](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#11-论文地址) - - [1.2 代码地址](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#12-代码地址) -- 2 环境说明 - - [2.1 深度学习框架](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#21-深度学习框架) - - [2.2 python第三方库](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#22-python第三方库) -- 3 模型转换 - - [3.1 pth转onnx模型](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#31-pth转onnx模型) - - [3.2 onnx转om模型](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#32-onnx转om模型) -- 4 数据集预处理 - - [4.1 数据集获取](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#41-数据集获取) - - [4.2 数据集预处理](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#42-数据集预处理) - - [4.3 生成数据集信息文件](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#43-生成数据集信息文件) -- 5 离线推理 - - [5.1 benchmark工具概述](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#51-benchmark工具概述) - - [5.2 离线推理](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#52-离线推理) -- 6 精度对比 - - [6.1 离线推理精度统计](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#61-离线推理精度统计) - - [6.2 开源精度](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#62-开源精度) - - [6.3 精度对比](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#63-精度对比) -- 7 性能对比 - - [7.1 npu性能数据](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#71-npu性能数据) - - [7.2 T4性能数据](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#72-T4性能数据) - - [7.3 性能对比](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#73-性能对比) -- 8 710增加文件介绍 - -## 1 模型概述 - -- **论文地址** -- **代码地址** - -### 1.1 论文地址 - -[CenterFace论文](https://arxiv.org/abs/1911.03599) - -### 1.2 代码地址 - -[CenterFace代码](https://github.com/chenjun2hao/CenterFace.pytorch) - -## 2 环境说明 - -- **深度学习框架** -- **python第三方库** - -### 2.1 深度学习框架 - -``` -python3.7.5 -CANN 5.0.1 - -pytorch >= 1.5.0 -torchvision >= 0.6.0 -onnx >= 1.7.0 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.20.3 -Pillow == 8.2.0 -opencv-python == 4.5.2.54 -``` - -## 3 模型转换 - -- **pth转onnx模型** -- **onnx转om模型** - -### 3.1 pth转onnx模型 - -1.下载pth权重文件 -权重文件从百度网盘上获取:https://pan.baidu.com/s/1sU3pRBTFebbsMDac-1HsQA 密码:etdi - -2.使用pth2onnx.py进行onnx的转换 - -``` -mv ./CenterFace/center-face/src/pth2onnx.py ./CenterFace/center-face/src/lib -cd ./CenterFace/center-face/src/lib -python3 pth2onnx.py -``` - -### 3.2 onnx转om模型 - -1.设置环境变量 - -``` -source env.sh -``` - -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 - -``` -cd ./CenterFace/center-face/src/test -bash onnxToom.sh -``` - -## 4 数据集预处理 - -- **数据集获取** -- **数据集预处理** -- **生成数据集信息文件** - -### 4.1 数据集获取 - -拉取代码仓库 (因为使用了开源代码模块,所以需要git clone一下) - -```shell -git clone https://gitee.com/Levi990223/center-face.git -``` - -整理代码结构 - -```shell -mv -r test center-face/src -mv benchmark.x86_64 centerface_pth_preprocess.py centerface_pth_postprocess.py convert.py env.sh CenterFace.onnx pth2onnx.py get_info.py model_best.pth move.sh npu_set_env.sh README.md ./center-face/src -``` - -下载WIDER_FACE数据集,将图片上在这个目录下: - -下载地址:https://www.graviti.cn/open-datasets/WIDER_FACE - -``` -$CenterFace_ROOT/center-face/data/{eval_dataset} -``` - -### 4.2 数据集预处理 - -1.预处理脚本centerface_pth_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 - -``` -cd ./CenterFace/center-face/src/test -bash start.sh -``` - -### 4.3 生成数据集信息文件 - -1.生成数据集信息文件脚本get_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 - -``` -cd ./CenterFace/center-face/src/test -bash to_info.sh -``` - -to_info.sh里,第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 - -## 5 离线推理 - -- **benchmark工具概述** -- **离线推理** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.1 推理benchmark工具用户指南 01 - -### 5.2 离线推理 - -1.设置环境变量 - -``` -source env.sh -source npu_set_env.sh -``` - -2.执行离线推理 - -执行前需要将benchmark.x86_64移动到执行目录下 - -(注:执行目录是/center-face/src) - -然后运行如下命令: - -``` -cd ./CenterFace/center-face/src/test -bash infer.sh -``` - -输出结果默认保存在当前目录result/dumpOutput_device{0},每个输入对应的输出对应四个_x.bin文件。 - -3.处理目录result/dumpOutput_device{0}下的bin文件 - -将该目录下的文件分类别存放,以便于后处理 - -``` -cd ./CenterFace/center-face/src/ -python3 convert.py ./result/dumpOutput_device1/ ./result/result -``` - -第一个参数是benchmark得到的bin文件目录,第二个参数是保存路径 - -## 6 精度对比 - -- **离线推理精度** -- **开源精度** -- **精度对比** - -### 6.1 离线推理精度统计 - -1.后处理 - -注:这里需要使用wide_face_val.mat文件,在center-face/evaluate/ground_truth/可以找到,然后将其移动到center-face/src目录下,然后执行下面命令 - -``` -cd ./CenterFace/center-face/src -python3 centerface_pth_postprocess.py -``` - -2.进行Ascend310上精度评估 - -``` -cd ./CenterFace/center-face/evaluate -python3 evaluation.py -``` - -### 6.2 开源精度 - -[CenterFace官网精度]([chenjun2hao/CenterFace.pytorch: unofficial version of centerface, which achieves the best balance between speed and accuracy at face detection (github.com)](https://github.com/chenjun2hao/CenterFace.pytorch)) - -``` -Easy Val AP: 0.9257383419951156 -Medium Val AP: 0.9131308732465665 -Hard Val AP: 0.7717305552550734 -``` - -### 6.3 精度对比 - -``` -Easy Val AP: 0.9190736484158941 -Medium Val AP: 0.9067769085346155 -Hard Val AP: 0.7425807072008017 -``` - -### 6.3 精度对比 - -实际上官网的hard精度达不到77%,最高74%左右,所以对比下来精度是达标的。 - -## 7 性能对比 - -- **npu性能数据** -- **T4性能数据** -- **性能对比** - -### 7.1 npu性能数据 - -1.benchmark工具在整个数据集上推理获得性能数据 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: - -``` -[e2e] throughputRate: 33.1307, latency: 97372 -[data read] throughputRate: 36.336, moduleLatency: 27.5209 -[preprocess] throughputRate: 35.6065, moduleLatency: 28.0847 -[infer] throughputRate: 33.4556, Interface throughputRate: 91.86, moduleLatency: 29.2697 -[post] throughputRate: 33.4544, moduleLatency: 29.8915 -``` - -Interface throughputRate: 91.86,91.86x4=367.44既是batch1 310单卡吞吐率 -batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: - -``` -[e2e] throughputRate: 31.7581, latency: 101580 -[data read] throughputRate: 35.0206, moduleLatency: 28.5547 -[preprocess] throughputRate: 33.9534, moduleLatency: 29.4521 -[infer] throughputRate: 32.022, Interface throughputRate: 80.3537, moduleLatency: 30.4381 -[post] throughputRate: 2.00424, moduleLatency: 498.943 - -``` - -Interface throughputRate: 80.3537,80.3537x4=321.4148既是batch16 310单卡吞吐率 - -### 7.2 T4性能数据 - -``` -[W] [TRT] TensorRT was linked against cuBLAS/cuBLAS LT 11.2.0 but loaded cuBLAS/cuBLAS LT 11.1.0 -[W] [TRT] TensorRT was linked against cuBLAS/cuBLAS LT 11.2.0 but loaded cuBLAS/cuBLAS LT 11.1.0 -[W] [TRT] TensorRT was linked against cuBLAS/cuBLAS LT 11.2.0 but loaded cuBLAS/cuBLAS LT 11.1.0 -t4 bs1 fps:337.544 -[W] [TRT] TensorRT was linked against cuBLAS/cuBLAS LT 11.2.0 but loaded cuBLAS/cuBLAS LT 11.1.0 -[W] [TRT] TensorRT was linked against cuBLAS/cuBLAS LT 11.2.0 but loaded cuBLAS/cuBLAS LT 11.1.0 -[W] [TRT] TensorRT was linked against cuBLAS/cuBLAS LT 11.2.0 but loaded cuBLAS/cuBLAS LT 11.1.0 -t4 bs16 fps:359.999 -``` - -batch1 t4单卡吞吐率:337.544 - -batch16 t4单卡吞吐率:359.999 - -### 7.3 性能对比 - -batch1:91.86x4=367.44 > 337.544 -batch16:80.3537x4=321.4148 < 359.999 - -## 8 710增加文件介绍 - -1.aipp_centerface.aippconfig ONNX模型转OM模型时所配置aipp -2.calibration_bin.py 量化模型时输入真实数据的组件脚本 +# CenterFace Onnx模型端到端推理指导 + +- 1 模型概述 + - [1.1 论文地址](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#11-论文地址) + - [1.2 代码地址](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#12-代码地址) +- 2 环境说明 + - [2.1 深度学习框架](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#21-深度学习框架) + - [2.2 python第三方库](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#22-python第三方库) +- 3 模型转换 + - [3.1 pth转onnx模型](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#31-pth转onnx模型) + - [3.2 onnx转om模型](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#32-onnx转om模型) +- 4 数据集预处理 + - [4.1 数据集获取](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#41-数据集获取) + - [4.2 数据集预处理](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#42-数据集预处理) + - [4.3 生成数据集信息文件](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#43-生成数据集信息文件) +- 5 离线推理 + - [5.1 benchmark工具概述](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#51-benchmark工具概述) + - [5.2 离线推理](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#52-离线推理) +- 6 精度对比 + - [6.1 离线推理精度统计](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#61-离线推理精度统计) + - [6.2 开源精度](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#62-开源精度) + - [6.3 精度对比](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#63-精度对比) +- 7 性能对比 + - [7.1 npu性能数据](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#71-npu性能数据) + - [7.2 T4性能数据](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#72-T4性能数据) + - [7.3 性能对比](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#73-性能对比) +- 8 710增加文件介绍 + +## 1 模型概述 + +- **论文地址** +- **代码地址** + +### 1.1 论文地址 + +[CenterFace论文](https://arxiv.org/abs/1911.03599) + +### 1.2 代码地址 + +[CenterFace代码](https://github.com/chenjun2hao/CenterFace.pytorch) + +## 2 环境说明 + +- **深度学习框架** +- **python第三方库** + +### 2.1 深度学习框架 + +``` +python3.7.5 +CANN 5.0.1 + +pytorch >= 1.5.0 +torchvision >= 0.6.0 +onnx >= 1.7.0 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.20.3 +Pillow == 8.2.0 +opencv-python == 4.5.2.54 +``` + +## 3 模型转换 + +- **pth转onnx模型** +- **onnx转om模型** + +### 3.1 pth转onnx模型 + +1.下载pth权重文件 +权重文件从百度网盘上获取:https://pan.baidu.com/s/1sU3pRBTFebbsMDac-1HsQA 密码:etdi + +2.使用pth2onnx.py进行onnx的转换 + +``` +mv ./CenterFace/center-face/src/pth2onnx.py ./CenterFace/center-face/src/lib +cd ./CenterFace/center-face/src/lib +python3 pth2onnx.py +``` + +### 3.2 onnx转om模型 + +1.设置环境变量 + +``` +source env.sh +``` + +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 + +``` +cd ./CenterFace/center-face/src/test +bash onnxToom.sh +``` + +## 4 数据集预处理 + +- **数据集获取** +- **数据集预处理** +- **生成数据集信息文件** + +### 4.1 数据集获取 + +拉取代码仓库 (因为使用了开源代码模块,所以需要git clone一下) + +```shell +git clone https://gitee.com/Levi990223/center-face.git +``` + +整理代码结构 + +```shell +mv -r test center-face/src +mv benchmark.x86_64 centerface_pth_preprocess.py centerface_pth_postprocess.py convert.py env.sh CenterFace.onnx pth2onnx.py get_info.py model_best.pth move.sh npu_set_env.sh README.md ./center-face/src +``` + +下载WIDER_FACE数据集,将图片上在这个目录下: + +下载地址:https://www.graviti.cn/open-datasets/WIDER_FACE + +``` +$CenterFace_ROOT/center-face/data/{eval_dataset} +``` + +### 4.2 数据集预处理 + +1.预处理脚本centerface_pth_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 + +``` +cd ./CenterFace/center-face/src/test +bash start.sh +``` + +### 4.3 生成数据集信息文件 + +1.生成数据集信息文件脚本get_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 + +``` +cd ./CenterFace/center-face/src/test +bash to_info.sh +``` + +to_info.sh里,第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 + +## 5 离线推理 + +- **benchmark工具概述** +- **离线推理** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.1 推理benchmark工具用户指南 01 + +### 5.2 离线推理 + +1.设置环境变量 + +``` +source env.sh +source npu_set_env.sh +``` + +2.执行离线推理 + +执行前需要将benchmark.x86_64移动到执行目录下 + +(注:执行目录是/center-face/src) + +然后运行如下命令: + +``` +cd ./CenterFace/center-face/src/test +bash infer.sh +``` + +输出结果默认保存在当前目录result/dumpOutput_device{0},每个输入对应的输出对应四个_x.bin文件。 + +3.处理目录result/dumpOutput_device{0}下的bin文件 + +将该目录下的文件分类别存放,以便于后处理 + +``` +cd ./CenterFace/center-face/src/ +python3 convert.py ./result/dumpOutput_device1/ ./result/result +``` + +第一个参数是benchmark得到的bin文件目录,第二个参数是保存路径 + +## 6 精度对比 + +- **离线推理精度** +- **开源精度** +- **精度对比** + +### 6.1 离线推理精度统计 + +1.后处理 + +注:这里需要使用wide_face_val.mat文件,在center-face/evaluate/ground_truth/可以找到,然后将其移动到center-face/src目录下,然后执行下面命令 + +``` +cd ./CenterFace/center-face/src +python3 centerface_pth_postprocess.py +``` + +2.进行Ascend310上精度评估 + +``` +cd ./CenterFace/center-face/evaluate +python3 evaluation.py +``` + +### 6.2 开源精度 + +[CenterFace官网精度]([chenjun2hao/CenterFace.pytorch: unofficial version of centerface, which achieves the best balance between speed and accuracy at face detection (github.com)](https://github.com/chenjun2hao/CenterFace.pytorch)) + +``` +Easy Val AP: 0.9257383419951156 +Medium Val AP: 0.9131308732465665 +Hard Val AP: 0.7717305552550734 +``` + +### 6.3 精度对比 + +``` +Easy Val AP: 0.9190736484158941 +Medium Val AP: 0.9067769085346155 +Hard Val AP: 0.7425807072008017 +``` + +### 6.3 精度对比 + +实际上官网的hard精度达不到77%,最高74%左右,所以对比下来精度是达标的。 + +## 7 性能对比 + +- **npu性能数据** +- **T4性能数据** +- **性能对比** + +### 7.1 npu性能数据 + +1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: + +``` +[e2e] throughputRate: 33.1307, latency: 97372 +[data read] throughputRate: 36.336, moduleLatency: 27.5209 +[preprocess] throughputRate: 35.6065, moduleLatency: 28.0847 +[infer] throughputRate: 33.4556, Interface throughputRate: 91.86, moduleLatency: 29.2697 +[post] throughputRate: 33.4544, moduleLatency: 29.8915 +``` + +Interface throughputRate: 91.86,91.86x4=367.44既是batch1 310单卡吞吐率 +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: + +``` +[e2e] throughputRate: 31.7581, latency: 101580 +[data read] throughputRate: 35.0206, moduleLatency: 28.5547 +[preprocess] throughputRate: 33.9534, moduleLatency: 29.4521 +[infer] throughputRate: 32.022, Interface throughputRate: 80.3537, moduleLatency: 30.4381 +[post] throughputRate: 2.00424, moduleLatency: 498.943 + +``` + +Interface throughputRate: 80.3537,80.3537x4=321.4148既是batch16 310单卡吞吐率 + +### 7.2 T4性能数据 + +``` +[W] [TRT] TensorRT was linked against cuBLAS/cuBLAS LT 11.2.0 but loaded cuBLAS/cuBLAS LT 11.1.0 +[W] [TRT] TensorRT was linked against cuBLAS/cuBLAS LT 11.2.0 but loaded cuBLAS/cuBLAS LT 11.1.0 +[W] [TRT] TensorRT was linked against cuBLAS/cuBLAS LT 11.2.0 but loaded cuBLAS/cuBLAS LT 11.1.0 +t4 bs1 fps:337.544 +[W] [TRT] TensorRT was linked against cuBLAS/cuBLAS LT 11.2.0 but loaded cuBLAS/cuBLAS LT 11.1.0 +[W] [TRT] TensorRT was linked against cuBLAS/cuBLAS LT 11.2.0 but loaded cuBLAS/cuBLAS LT 11.1.0 +[W] [TRT] TensorRT was linked against cuBLAS/cuBLAS LT 11.2.0 but loaded cuBLAS/cuBLAS LT 11.1.0 +t4 bs16 fps:359.999 +``` + +batch1 t4单卡吞吐率:337.544 + +batch16 t4单卡吞吐率:359.999 + +### 7.3 性能对比 + +batch1:91.86x4=367.44 > 337.544 +batch16:80.3537x4=321.4148 < 359.999 + +## 8 710增加文件介绍 + +1.aipp_centerface.aippconfig ONNX模型转OM模型时所配置aipp +2.calibration_bin.py 量化模型时输入真实数据的组件脚本 diff --git a/ACL_PyTorch/contrib/cv/detection/CenterFace/aipp_centerface.aippconfig b/ACL_PyTorch/contrib/cv/detection/CenterFace/aipp_centerface.aippconfig index 3d0b228c6beb9bd218de96c0dee1f491956f6392..3d5d1a7120d951b1f55b2790818769a90b249a6d 100644 --- a/ACL_PyTorch/contrib/cv/detection/CenterFace/aipp_centerface.aippconfig +++ b/ACL_PyTorch/contrib/cv/detection/CenterFace/aipp_centerface.aippconfig @@ -1,15 +1,15 @@ -aipp_op{ - aipp_mode:static - input_format : RGB888_U8 - - src_image_size_w : 800 - src_image_size_h : 800 - crop:false - - min_chn_0 : 104 - min_chn_1 : 114 - min_chn_2 : 120 - var_reci_chn_0: 0.0135864 - var_reci_chn_1: 0.0143080 - var_reci_chn_2: 0.0141014 -} +aipp_op{ + aipp_mode:static + input_format : RGB888_U8 + + src_image_size_w : 800 + src_image_size_h : 800 + crop:false + + min_chn_0 : 104 + min_chn_1 : 114 + min_chn_2 : 120 + var_reci_chn_0: 0.0135864 + var_reci_chn_1: 0.0143080 + var_reci_chn_2: 0.0141014 +} diff --git a/ACL_PyTorch/contrib/cv/detection/CenterFace/calibration_bin.py b/ACL_PyTorch/contrib/cv/detection/CenterFace/calibration_bin.py index af13f3593f95019d0f90567bc014aa05bd9a7708..c72d0c6fbc85fe3e5608325eb698828d38880fce 100644 --- a/ACL_PyTorch/contrib/cv/detection/CenterFace/calibration_bin.py +++ b/ACL_PyTorch/contrib/cv/detection/CenterFace/calibration_bin.py @@ -1,56 +1,56 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import numpy as np -import multiprocessing - -max_bin=10 -def preprocess(src_path, save_path, batch_size): - files = os.listdir(src_path) - - output_data = [0] - for i, file in enumerate(files): - input_data = np.fromfile(os.path.join(src_path, file), dtype=np.float32) - input_data = input_data.reshape(1, 3, 800, 800) - - if i % batch_size == 0: - output_data = input_data - else: - output_data = np.concatenate((output_data, input_data), axis=0) - - # only save 10 bin files - loop_id = (i + 1) // batch_size - if loop_id > max_bin: - break - - if (i + 1) % batch_size == 0: - output_data.tofile("{}/img_{}_bs{}.bin".format(save_path, loop_id, batch_size)) - output_data = [0] - - -if __name__ == '__main__': - if len(sys.argv) < 4: - raise Exception("usage: python3 xxx.py [src_path] [save_path] [batch_size]") - src_path = sys.argv[1] - save_path = sys.argv[2] - batch_size = int(sys.argv[3]) - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - - if not os.path.isdir(save_path): - os.makedirs(os.path.realpath(save_path)) - preprocess(src_path, save_path, batch_size) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import numpy as np +import multiprocessing + +max_bin=10 +def preprocess(src_path, save_path, batch_size): + files = os.listdir(src_path) + + output_data = [0] + for i, file in enumerate(files): + input_data = np.fromfile(os.path.join(src_path, file), dtype=np.float32) + input_data = input_data.reshape(1, 3, 800, 800) + + if i % batch_size == 0: + output_data = input_data + else: + output_data = np.concatenate((output_data, input_data), axis=0) + + # only save 10 bin files + loop_id = (i + 1) // batch_size + if loop_id > max_bin: + break + + if (i + 1) % batch_size == 0: + output_data.tofile("{}/img_{}_bs{}.bin".format(save_path, loop_id, batch_size)) + output_data = [0] + + +if __name__ == '__main__': + if len(sys.argv) < 4: + raise Exception("usage: python3 xxx.py [src_path] [save_path] [batch_size]") + src_path = sys.argv[1] + save_path = sys.argv[2] + batch_size = int(sys.argv[3]) + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + + if not os.path.isdir(save_path): + os.makedirs(os.path.realpath(save_path)) + preprocess(src_path, save_path, batch_size) + diff --git a/ACL_PyTorch/contrib/cv/detection/CenterFace/centerface_pth_postprocess.py b/ACL_PyTorch/contrib/cv/detection/CenterFace/centerface_pth_postprocess.py index e598550ebba111ee28954020d70141735adfe821..9e825c29e87d67d3adf25da82ef4f7478312c8fb 100644 --- a/ACL_PyTorch/contrib/cv/detection/CenterFace/centerface_pth_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/CenterFace/centerface_pth_postprocess.py @@ -1,153 +1,153 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -*- coding:utf-8 -*- -from __future__ import absolute_import -from __future__ import division - -import numpy as np -import torch -import os -import sys -import cv2 -import scipy.io as sio - -from lib.models import decode as dc -from lib.models.utils import _gather_feat, _tranpose_and_gather_feat -from lib.utils import image as img -from lib.utils.post_process import multi_pose_post_process -from lib.opts_pose import opts -from lib.detectors.detector_factory import detector_factory -from lib.datasets.dataset_factory import get_dataset - -def preprocess(): - root_path = os.getcwd() - opt = opts().parse('--task {} --load_model {}'.format('multi_pose', os.path.join(root_path, 'model_best.pth')).split(' ')) - Dataset = get_dataset(opt.dataset, opt.task) - opt = opts().update_dataset_info_and_set_heads(opt, Dataset) - os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpus_str - Detector = detector_factory[opt.task] - detector = Detector(opt) - file_path = os.path.join(root_path,'../data') - in_files = os.listdir(file_path) - Meta = [] - for file in sorted(in_files): - os.chdir(os.path.join(file_path, file)) - cur_path = os.getcwd() - doc = os.listdir(cur_path) - for document in sorted(doc): - image = cv2.imread(os.path.join(cur_path, document)) - if document=='output': - break - for scale in opt.test_scales: - images,meta = detector.pre_process(image, scale, meta=None) - Meta.append(meta) - return Meta - -def post_process(dets, meta, scale=1): - dets = dets.detach().cpu().numpy().reshape(1, -1, dets.shape[2]) - dets = multi_pose_post_process( - dets.copy(), [meta['c']], [meta['s']], - meta['out_height'], meta['out_width']) - for j in range(1, 2): - dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 15) # 关键点数+5=15 - dets[0][j][:, :4] /= scale - dets[0][j][:, 5:] /= scale - return dets[0] - -def merge_outputs(detections): - results = {} - results[1] = np.concatenate( - [detection[1] for detection in detections], axis=0).astype(np.float32) - results[1] = results[1].tolist() - return results - -def pre_postprocess(): - List = [] - root_path = os.getcwd() - path=os.path.join(root_path,'./result/result') - File = os.listdir(path) - for file in sorted(File): - Doc = [] #save no-repeated file name - os.chdir(os.path.join(path, file)) - cur_path = os.getcwd() - doc = os.listdir(cur_path) - for document in sorted(doc): - Doc.append(document[0:-6]) #grip end - Doc = list(set(Doc)) #grip repeated element - for ff in sorted(Doc): #deal after sorting - dist={} - if ff=='kerne': - break - for i in range(1, 5): #one image ----->four bin - txt_file = np.fromfile(f'../../../result/result/{file}/{ff}_{i}.bin', dtype=np.float32) - if i==1: - dist['hm']=torch.tensor(txt_file.reshape(-1,1,200,200)) - if i==2: - dist['wh']=torch.tensor(txt_file.reshape(-1,2,200,200)) - if i==3: - dist['hm_offset']=torch.tensor(txt_file.reshape(-1,2,200,200)) - if i==4: - dist['landmarks']=torch.tensor(txt_file.reshape(-1,10,200,200)) - List.append(dist) - os.chdir(root_path) - return List - -def run(): - List = pre_postprocess() - Meta = preprocess() - print('List:',len(List)) - print('Meta:',len(Meta)) - Results=[] - from tqdm import tqdm - for i in tqdm(range(len(List))): - detections = [] - reg = List[i]['hm_offset'] - dets = dc.centerface_decode( - List[i]['hm'], List[i]['wh'], List[i]['landmarks'], - reg=reg, K=200) - dets = post_process(dets,Meta[i]) - detections.append(dets) - results = merge_outputs(detections) - Results.append(results) - return Results - -if __name__ == "__main__": - root_path = os.getcwd() - Path = os.path.join(root_path,'../data') - wider_face_mat = sio.loadmat(root_path+'/wider_face_val.mat') - event_list = wider_face_mat['event_list'] #directory - file_list = wider_face_mat['file_list'] #file - save_path = root_path+'/output/widerface/' - results = run() #all data - i=0 #iteration - for index, event in enumerate(sorted(event_list)): - file_list_item = file_list[index][0] - im_dir = event[0][0] - if not os.path.exists(save_path + im_dir): - os.makedirs(save_path + im_dir) - for num, file in enumerate(sorted(file_list_item)): - im_name = file[0][0] - zip_name = '%s/%s.jpg' % (im_dir, im_name) - img_path = os.path.join(Path, zip_name) - dets = results[i] - f = open(save_path + im_dir + '/' + im_name + '.txt', 'w') - f.write('{:s}\n'.format('%s/%s.jpg' % (im_dir, im_name))) - f.write('{:d}\n'.format(len(dets))) - for b in dets[1]: - x1, y1, x2, y2, s = b[0], b[1], b[2], b[3], b[4] - f.write('{:.1f} {:.1f} {:.1f} {:.1f} {:.3f}\n'.format(x1, y1, (x2 - x1 + 1), (y2 - y1 + 1), s)) - f.close() - print(i) - i=i+1 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -*- coding:utf-8 -*- +from __future__ import absolute_import +from __future__ import division + +import numpy as np +import torch +import os +import sys +import cv2 +import scipy.io as sio + +from lib.models import decode as dc +from lib.models.utils import _gather_feat, _tranpose_and_gather_feat +from lib.utils import image as img +from lib.utils.post_process import multi_pose_post_process +from lib.opts_pose import opts +from lib.detectors.detector_factory import detector_factory +from lib.datasets.dataset_factory import get_dataset + +def preprocess(): + root_path = os.getcwd() + opt = opts().parse('--task {} --load_model {}'.format('multi_pose', os.path.join(root_path, 'model_best.pth')).split(' ')) + Dataset = get_dataset(opt.dataset, opt.task) + opt = opts().update_dataset_info_and_set_heads(opt, Dataset) + os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpus_str + Detector = detector_factory[opt.task] + detector = Detector(opt) + file_path = os.path.join(root_path,'../data') + in_files = os.listdir(file_path) + Meta = [] + for file in sorted(in_files): + os.chdir(os.path.join(file_path, file)) + cur_path = os.getcwd() + doc = os.listdir(cur_path) + for document in sorted(doc): + image = cv2.imread(os.path.join(cur_path, document)) + if document=='output': + break + for scale in opt.test_scales: + images,meta = detector.pre_process(image, scale, meta=None) + Meta.append(meta) + return Meta + +def post_process(dets, meta, scale=1): + dets = dets.detach().cpu().numpy().reshape(1, -1, dets.shape[2]) + dets = multi_pose_post_process( + dets.copy(), [meta['c']], [meta['s']], + meta['out_height'], meta['out_width']) + for j in range(1, 2): + dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 15) # 关键点数+5=15 + dets[0][j][:, :4] /= scale + dets[0][j][:, 5:] /= scale + return dets[0] + +def merge_outputs(detections): + results = {} + results[1] = np.concatenate( + [detection[1] for detection in detections], axis=0).astype(np.float32) + results[1] = results[1].tolist() + return results + +def pre_postprocess(): + List = [] + root_path = os.getcwd() + path=os.path.join(root_path,'./result/result') + File = os.listdir(path) + for file in sorted(File): + Doc = [] #save no-repeated file name + os.chdir(os.path.join(path, file)) + cur_path = os.getcwd() + doc = os.listdir(cur_path) + for document in sorted(doc): + Doc.append(document[0:-6]) #grip end + Doc = list(set(Doc)) #grip repeated element + for ff in sorted(Doc): #deal after sorting + dist={} + if ff=='kerne': + break + for i in range(1, 5): #one image ----->four bin + txt_file = np.fromfile(f'../../../result/result/{file}/{ff}_{i}.bin', dtype=np.float32) + if i==1: + dist['hm']=torch.tensor(txt_file.reshape(-1,1,200,200)) + if i==2: + dist['wh']=torch.tensor(txt_file.reshape(-1,2,200,200)) + if i==3: + dist['hm_offset']=torch.tensor(txt_file.reshape(-1,2,200,200)) + if i==4: + dist['landmarks']=torch.tensor(txt_file.reshape(-1,10,200,200)) + List.append(dist) + os.chdir(root_path) + return List + +def run(): + List = pre_postprocess() + Meta = preprocess() + print('List:',len(List)) + print('Meta:',len(Meta)) + Results=[] + from tqdm import tqdm + for i in tqdm(range(len(List))): + detections = [] + reg = List[i]['hm_offset'] + dets = dc.centerface_decode( + List[i]['hm'], List[i]['wh'], List[i]['landmarks'], + reg=reg, K=200) + dets = post_process(dets,Meta[i]) + detections.append(dets) + results = merge_outputs(detections) + Results.append(results) + return Results + +if __name__ == "__main__": + root_path = os.getcwd() + Path = os.path.join(root_path,'../data') + wider_face_mat = sio.loadmat(root_path+'/wider_face_val.mat') + event_list = wider_face_mat['event_list'] #directory + file_list = wider_face_mat['file_list'] #file + save_path = root_path+'/output/widerface/' + results = run() #all data + i=0 #iteration + for index, event in enumerate(sorted(event_list)): + file_list_item = file_list[index][0] + im_dir = event[0][0] + if not os.path.exists(save_path + im_dir): + os.makedirs(save_path + im_dir) + for num, file in enumerate(sorted(file_list_item)): + im_name = file[0][0] + zip_name = '%s/%s.jpg' % (im_dir, im_name) + img_path = os.path.join(Path, zip_name) + dets = results[i] + f = open(save_path + im_dir + '/' + im_name + '.txt', 'w') + f.write('{:s}\n'.format('%s/%s.jpg' % (im_dir, im_name))) + f.write('{:d}\n'.format(len(dets))) + for b in dets[1]: + x1, y1, x2, y2, s = b[0], b[1], b[2], b[3], b[4] + f.write('{:.1f} {:.1f} {:.1f} {:.1f} {:.3f}\n'.format(x1, y1, (x2 - x1 + 1), (y2 - y1 + 1), s)) + f.close() + print(i) + i=i+1 diff --git a/ACL_PyTorch/contrib/cv/detection/CenterFace/centerface_pth_preprocess.py b/ACL_PyTorch/contrib/cv/detection/CenterFace/centerface_pth_preprocess.py index cb3bfae74c0b296b33714f35434440115942d9ac..c8642403b4e52cff311a7e7948805e4f9509c5ca 100644 --- a/ACL_PyTorch/contrib/cv/detection/CenterFace/centerface_pth_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/CenterFace/centerface_pth_preprocess.py @@ -1,58 +1,58 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -*- coding:GB2312 -*- - -from __future__ import absolute_import -from __future__ import division - -import sys -import os -import cv2 -import torch - -from lib.opts_pose import opts -from lib.detectors.detector_factory import detector_factory -from datasets.dataset_factory import get_dataset - -def preprocess(file_path, bin_path): - opt = opts().parse('--task {} --load_model {}'.format('multi_pose', 'model_best.pth').split(' ')) - Dataset = get_dataset(opt.dataset, opt.task) - opt = opts().update_dataset_info_and_set_heads(opt, Dataset) - os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpus_str - Detector = detector_factory[opt.task] - detector = Detector(opt) - in_files = os.listdir(file_path) - - if not os.path.exists(bin_path): - os.makedirs(bin_path) - for file in sorted(in_files): - os.chdir(os.path.join(file_path, file)) - cur_path = os.getcwd() - doc = os.listdir(cur_path) - for document in doc: - if document=='output': - break - image = cv2.imread(os.path.join(cur_path, document)) - for scale in opt.test_scales: - images, meta = detector.pre_process(image, scale, meta=None) - if not os.path.exists(os.path.join(bin_path,file)): - os.makedirs(os.path.join(bin_path,file)) - des_path = os.path.join(bin_path,file) - images.numpy().tofile(os.path.join(des_path,document.split('.')[0] +'.bin')) - -if __name__ == "__main__": - file_path = os.path.abspath(sys.argv[1]) - bin_path = os.path.abspath(sys.argv[2]) - preprocess(file_path, bin_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -*- coding:GB2312 -*- + +from __future__ import absolute_import +from __future__ import division + +import sys +import os +import cv2 +import torch + +from lib.opts_pose import opts +from lib.detectors.detector_factory import detector_factory +from datasets.dataset_factory import get_dataset + +def preprocess(file_path, bin_path): + opt = opts().parse('--task {} --load_model {}'.format('multi_pose', 'model_best.pth').split(' ')) + Dataset = get_dataset(opt.dataset, opt.task) + opt = opts().update_dataset_info_and_set_heads(opt, Dataset) + os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpus_str + Detector = detector_factory[opt.task] + detector = Detector(opt) + in_files = os.listdir(file_path) + + if not os.path.exists(bin_path): + os.makedirs(bin_path) + for file in sorted(in_files): + os.chdir(os.path.join(file_path, file)) + cur_path = os.getcwd() + doc = os.listdir(cur_path) + for document in doc: + if document=='output': + break + image = cv2.imread(os.path.join(cur_path, document)) + for scale in opt.test_scales: + images, meta = detector.pre_process(image, scale, meta=None) + if not os.path.exists(os.path.join(bin_path,file)): + os.makedirs(os.path.join(bin_path,file)) + des_path = os.path.join(bin_path,file) + images.numpy().tofile(os.path.join(des_path,document.split('.')[0] +'.bin')) + +if __name__ == "__main__": + file_path = os.path.abspath(sys.argv[1]) + bin_path = os.path.abspath(sys.argv[2]) + preprocess(file_path, bin_path) diff --git a/ACL_PyTorch/contrib/cv/detection/CenterFace/convert.py b/ACL_PyTorch/contrib/cv/detection/CenterFace/convert.py index b5436a7049f912d991888b10c39d89f49316392d..56f2d5d0363c1c84ba880f85da19e691f9f389de 100644 --- a/ACL_PyTorch/contrib/cv/detection/CenterFace/convert.py +++ b/ACL_PyTorch/contrib/cv/detection/CenterFace/convert.py @@ -1,40 +1,40 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import shutil - - -if __name__ == '__main__': - bin_path = sys.argv[1] - resule_path = sys.argv[2] - if not os.path.exists(resule_path): - os.mkdir(resule_path) - f = os.listdir(bin_path) - for data in f: - data = data.strip('\n') - dir_name = data.split('_')[0] + '--' + data.split('_')[1] - dir_path = os.path.join(resule_path, dir_name) - if not os.path.exists(dir_path): - os.mkdir(dir_path) - file_list = os.listdir(resule_path) - for dir in file_list: - dir = dir.strip('\n') - cur_path = os.path.join(resule_path, dir) - for data in f: - data = data.strip('\n') - if data.split('_')[0] == dir.split('--')[0]: - shutil.copy(os.path.join(bin_path, data), - os.path.join(cur_path, data)) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import shutil + + +if __name__ == '__main__': + bin_path = sys.argv[1] + resule_path = sys.argv[2] + if not os.path.exists(resule_path): + os.mkdir(resule_path) + f = os.listdir(bin_path) + for data in f: + data = data.strip('\n') + dir_name = data.split('_')[0] + '--' + data.split('_')[1] + dir_path = os.path.join(resule_path, dir_name) + if not os.path.exists(dir_path): + os.mkdir(dir_path) + file_list = os.listdir(resule_path) + for dir in file_list: + dir = dir.strip('\n') + cur_path = os.path.join(resule_path, dir) + for data in f: + data = data.strip('\n') + if data.split('_')[0] == dir.split('--')[0]: + shutil.copy(os.path.join(bin_path, data), + os.path.join(cur_path, data)) diff --git a/ACL_PyTorch/contrib/cv/detection/CenterFace/pth2onnx.py b/ACL_PyTorch/contrib/cv/detection/CenterFace/pth2onnx.py index f58e87f45a6ada06593ee9073d64665c2aff40fa..32ec152f35d1741de53a81f8ab276f844f3738b9 100644 --- a/ACL_PyTorch/contrib/cv/detection/CenterFace/pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/CenterFace/pth2onnx.py @@ -1,35 +1,35 @@ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import os -import sys -import torch -import torch.utils.data -from opts_pose import opts -from models.model import create_model, load_model, save_model -from models.data_parallel import DataParallel -from logger import Logger -from datasets.dataset_factory import get_dataset -from trains.train_factory import train_factory -from datasets.sample.multi_pose import Multiposebatch - -def main(onnx_path,path): - opt = opts().parse() - input_names=["image"] - output_names = ["output1","output2","output3","output4"] - Dataset = get_dataset(opt.dataset, opt.task) - opt = opts().update_dataset_info_and_set_heads(opt, Dataset) - model = create_model(opt.arch, opt.heads, opt.head_conv) - model = load_model(model , path, None, opt.resume, opt.lr, opt.lr_step) - dynamic_axes = {'image': {0: '-1'}, 'output1': {0: '-1'},'output2': {0: '-1'},'output3': {0: '-1'},'output4': {0: '-1'}} - model.eval() - dummy_input = torch.randn(1,3,800,800) - torch.onnx.export(model,dummy_input,onnx_path,export_params=True,dynamic_axes = dynamic_axes,input_names = input_names,output_names = output_names,verbose=True) - -if __name__ =="__main__": - #onnx_path = sys.argv[1] - #path = sys.argv[2] - onnx_path = '../CenterFace.onnx' - path = '../model_best.pth' - main(onnx_path,path) +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import os +import sys +import torch +import torch.utils.data +from opts_pose import opts +from models.model import create_model, load_model, save_model +from models.data_parallel import DataParallel +from logger import Logger +from datasets.dataset_factory import get_dataset +from trains.train_factory import train_factory +from datasets.sample.multi_pose import Multiposebatch + +def main(onnx_path,path): + opt = opts().parse() + input_names=["image"] + output_names = ["output1","output2","output3","output4"] + Dataset = get_dataset(opt.dataset, opt.task) + opt = opts().update_dataset_info_and_set_heads(opt, Dataset) + model = create_model(opt.arch, opt.heads, opt.head_conv) + model = load_model(model , path, None, opt.resume, opt.lr, opt.lr_step) + dynamic_axes = {'image': {0: '-1'}, 'output1': {0: '-1'},'output2': {0: '-1'},'output3': {0: '-1'},'output4': {0: '-1'}} + model.eval() + dummy_input = torch.randn(1,3,800,800) + torch.onnx.export(model,dummy_input,onnx_path,export_params=True,dynamic_axes = dynamic_axes,input_names = input_names,output_names = output_names,verbose=True) + +if __name__ =="__main__": + #onnx_path = sys.argv[1] + #path = sys.argv[2] + onnx_path = '../CenterFace.onnx' + path = '../model_best.pth' + main(onnx_path,path) diff --git a/ACL_PyTorch/contrib/cv/detection/CenterFace/test/README.md b/ACL_PyTorch/contrib/cv/detection/CenterFace/test/README.md index fd47bfc4bc55179514534465c8e90e86eaabceb2..1652e1d70d0eebcdc0ac0d57b50cb024092ab0da 100644 --- a/ACL_PyTorch/contrib/cv/detection/CenterFace/test/README.md +++ b/ACL_PyTorch/contrib/cv/detection/CenterFace/test/README.md @@ -1,28 +1,28 @@ -环境准备: - -1.数据集路径 通用的数据集统一放在/CenterFace/center-face/data - -2.进入工作目录 cd CenterFace/center-face/src - -3.安装模型代码之前要执行下面命令: - - git clone https://gitee.com/Levi990223/center-face.git - -4.获取权重文件 -权重文件从百度网盘上获取:https://pan.baidu.com/s/1sU3pRBTFebbsMDac-1HsQA 密码:etdi - -5.获取数据集:https://www.graviti.cn/open-datasets/WIDER_FACE - -6.获取benchmark工具 将benchmark.x86_64 放在CenterFace/src目录下 - -推理步骤: - -7.调用/CenterFace/src/lib下面得pth2onnx生成onnx放在/src下面 - -运行python3 pth2onnx命令,在src文件夹下生成CenterFace.onnx文件 - -8.脚本转换om模型 bash test/onnxToom.sh - -9.310上执行,执行时确保device空闲: bash test/infer.sh - +环境准备: + +1.数据集路径 通用的数据集统一放在/CenterFace/center-face/data + +2.进入工作目录 cd CenterFace/center-face/src + +3.安装模型代码之前要执行下面命令: + + git clone https://gitee.com/Levi990223/center-face.git + +4.获取权重文件 +权重文件从百度网盘上获取:https://pan.baidu.com/s/1sU3pRBTFebbsMDac-1HsQA 密码:etdi + +5.获取数据集:https://www.graviti.cn/open-datasets/WIDER_FACE + +6.获取benchmark工具 将benchmark.x86_64 放在CenterFace/src目录下 + +推理步骤: + +7.调用/CenterFace/src/lib下面得pth2onnx生成onnx放在/src下面 + +运行python3 pth2onnx命令,在src文件夹下生成CenterFace.onnx文件 + +8.脚本转换om模型 bash test/onnxToom.sh + +9.310上执行,执行时确保device空闲: bash test/infer.sh + 10.在T4环境上将onnx文件放在/root/lsj目录下,执行perf_t4.sh时确保gpu空闲,执行命令 bash perf_t4.sh \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/CenterNet/CenterNet_postprocess.py b/ACL_PyTorch/contrib/cv/detection/CenterNet/CenterNet_postprocess.py index bf2a91f00f3fca5a0fcaadf5e0b4e09da6c28a5b..8547afc57dcc47a0e0319d49799c0b7241e91b92 100644 --- a/ACL_PyTorch/contrib/cv/detection/CenterNet/CenterNet_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/CenterNet/CenterNet_postprocess.py @@ -1,104 +1,104 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -import argparse -import torch -import numpy as np -import os -from glob import glob -import sys -CENTERNET_PATH = './CenterNet/src' -sys.path.insert(0, CENTERNET_PATH) -import cv2 -from lib.opts import opts -from lib.detectors.detector_factory import detector_factory -from lib.datasets.dataset_factory import get_dataset -from lib.models.decode import ctdet_decode -from lib.utils.post_process import ctdet_post_process -from lib.models.model import create_model, load_model -import lib.datasets.dataset.coco - -def post_process(dets, meta, scale=1): - print(meta) - num_classes=80 - dets = dets.detach().cpu().numpy() - dets = dets.reshape(1, -1, dets.shape[2]) - dets = ctdet_post_process( - dets.copy(), [meta['c']], [meta['s']], - meta['out_height'], meta['out_width'], 80) - for j in range(1, 81): - dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 5) - dets[0][j][:, :4] /= scale - return dets[0] - -def merge_outputs(detections): - results = {} - for j in range(1, 80 + 1):#coco numclasses=80 - results[j] = np.concatenate( - [detection[j] for detection in detections], axis=0).astype(np.float32) - return results - -def run(result_list, index, meta, dataset, filename): - output={} - for i in range(1, 4): - buf = np.fromfile(f'{result_list}/{filename[0:-4]}_{i}.bin', dtype="float32") - if i == 1: - output['hm'] = torch.tensor(buf.reshape(1, 80, 128, 128)) - if i == 2: - output['wh'] = torch.tensor(buf.reshape(1, 2, 128, 128)) - if i == 3: - output['reg'] = torch.tensor(buf.reshape(1, 2, 128, 128)) - detections = [] - hm = output['hm'].sigmoid_() - wh = output['wh'] - reg = output['reg'] - dets = ctdet_decode(hm, wh, reg) - dets = post_process(dets,meta) - detections.append(dets) - results = merge_outputs(detections) - return results - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='CenterNet') - parser.add_argument('--bin_data_path', default='./result/dumpOutput_device0', type=str, help='infer out path') - parser.add_argument('--resultfolder', default='./run_eval_result', type=str, help='Dir to save results') - args = parser.parse_args() - if not os.path.exists(args.resultfolder): - os.makedirs(args.resultfolder) - - opt = opts().parse('{} --load_model {}'.format('ctdet', './ctdet_coco_dla_2x.pth').split(' ')) - Dataset = get_dataset(opt.dataset, opt.task) - opt = opts().update_dataset_info_and_set_heads(opt, Dataset) - Detector = detector_factory[opt.task] - dataset = Dataset(opt, 'val') - opt.gpus[0] = -1 - detector = Detector(opt) - Meta = [] - filename = [] - results = {} - num_iters = len(dataset) - for ind in range(num_iters): - img_id = dataset.images[ind] - img_info = dataset.coco.loadImgs(ids=[img_id])[0] - img_path = os.path.join(dataset.img_dir, img_info['file_name']) - print(img_info['file_name'], "===", ind) - image = cv2.imread(img_path) - images, meta = detector.pre_process(image, 1.0, meta=None) - ret = run(args.bin_data_path, ind, meta, dataset, img_info['file_name']) - results[img_id] = ret - dataset.run_eval(results, args.resultfolder) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +import argparse +import torch +import numpy as np +import os +from glob import glob +import sys +CENTERNET_PATH = './CenterNet/src' +sys.path.insert(0, CENTERNET_PATH) +import cv2 +from lib.opts import opts +from lib.detectors.detector_factory import detector_factory +from lib.datasets.dataset_factory import get_dataset +from lib.models.decode import ctdet_decode +from lib.utils.post_process import ctdet_post_process +from lib.models.model import create_model, load_model +import lib.datasets.dataset.coco + +def post_process(dets, meta, scale=1): + print(meta) + num_classes=80 + dets = dets.detach().cpu().numpy() + dets = dets.reshape(1, -1, dets.shape[2]) + dets = ctdet_post_process( + dets.copy(), [meta['c']], [meta['s']], + meta['out_height'], meta['out_width'], 80) + for j in range(1, 81): + dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 5) + dets[0][j][:, :4] /= scale + return dets[0] + +def merge_outputs(detections): + results = {} + for j in range(1, 80 + 1):#coco numclasses=80 + results[j] = np.concatenate( + [detection[j] for detection in detections], axis=0).astype(np.float32) + return results + +def run(result_list, index, meta, dataset, filename): + output={} + for i in range(1, 4): + buf = np.fromfile(f'{result_list}/{filename[0:-4]}_{i}.bin', dtype="float32") + if i == 1: + output['hm'] = torch.tensor(buf.reshape(1, 80, 128, 128)) + if i == 2: + output['wh'] = torch.tensor(buf.reshape(1, 2, 128, 128)) + if i == 3: + output['reg'] = torch.tensor(buf.reshape(1, 2, 128, 128)) + detections = [] + hm = output['hm'].sigmoid_() + wh = output['wh'] + reg = output['reg'] + dets = ctdet_decode(hm, wh, reg) + dets = post_process(dets,meta) + detections.append(dets) + results = merge_outputs(detections) + return results + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='CenterNet') + parser.add_argument('--bin_data_path', default='./result/dumpOutput_device0', type=str, help='infer out path') + parser.add_argument('--resultfolder', default='./run_eval_result', type=str, help='Dir to save results') + args = parser.parse_args() + if not os.path.exists(args.resultfolder): + os.makedirs(args.resultfolder) + + opt = opts().parse('{} --load_model {}'.format('ctdet', './ctdet_coco_dla_2x.pth').split(' ')) + Dataset = get_dataset(opt.dataset, opt.task) + opt = opts().update_dataset_info_and_set_heads(opt, Dataset) + Detector = detector_factory[opt.task] + dataset = Dataset(opt, 'val') + opt.gpus[0] = -1 + detector = Detector(opt) + Meta = [] + filename = [] + results = {} + num_iters = len(dataset) + for ind in range(num_iters): + img_id = dataset.images[ind] + img_info = dataset.coco.loadImgs(ids=[img_id])[0] + img_path = os.path.join(dataset.img_dir, img_info['file_name']) + print(img_info['file_name'], "===", ind) + image = cv2.imread(img_path) + images, meta = detector.pre_process(image, 1.0, meta=None) + ret = run(args.bin_data_path, ind, meta, dataset, img_info['file_name']) + results[img_id] = ret + dataset.run_eval(results, args.resultfolder) + diff --git a/ACL_PyTorch/contrib/cv/detection/CenterNet/CenterNet_preprocess.py b/ACL_PyTorch/contrib/cv/detection/CenterNet/CenterNet_preprocess.py index 6400bc3f6aab474517dc17ea1d657e8bde687eaf..0c271cf04568075560b99465de7f92a929c4c7be 100644 --- a/ACL_PyTorch/contrib/cv/detection/CenterNet/CenterNet_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/CenterNet/CenterNet_preprocess.py @@ -1,98 +1,98 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import os -import cv2 -import numpy as np -import torch - -def preprocess(file_path, bin_path): - in_files = os.listdir(file_path) - if not os.path.exists(bin_path): - os.makedirs(bin_path) - i = 0 - for file in sorted(in_files): - i = i + 1 - print(file, "===", i) - image = cv2.imread(os.path.join(file_path, file)) - height, width = image.shape[0:2] - new_height = int(height) - new_width = int(width) - #Fix size testing - inp_height, inp_width = 512, 512 - c = np.array([new_width / 2., new_height / 2.], dtype=np.float32) - s = max(height, width) * 1.0 - trans_input = get_affine_transform(c, s, 0, [inp_width, inp_height]) - resized_image = cv2.resize(image, (new_width, new_height)) - inp_image = cv2.warpAffine( - resized_image, trans_input, (inp_width, inp_height),flags=cv2.INTER_LINEAR) - - inp_image = ((inp_image / 255. - [[[0.40789655,0.44719303,0.47026116]]]) / [[[0.2886383,0.27408165,0.27809834]]]).astype(np.float32) - images = inp_image.transpose(2, 0, 1).reshape(1, 3, inp_height, inp_width) - images = torch.from_numpy(images) - img = np.array(images).astype(np.float32) - img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) - -def get_affine_transform(center, - scale, - rot, - output_size, - shift=np.array([0, 0], dtype=np.float32), - inv=0): - if not isinstance(scale, np.ndarray) and not isinstance(scale, list): - scale = np.array([scale, scale], dtype=np.float32) - - scale_tmp = scale - src_w = scale_tmp[0] - dst_w = output_size[0] - dst_h = output_size[1] - - rot_rad = np.pi * rot / 180 - src_dir = get_dir([0, src_w * -0.5], rot_rad) - dst_dir = np.array([0, dst_w * -0.5], np.float32) - - src = np.zeros((3, 2), dtype=np.float32) - dst = np.zeros((3, 2), dtype=np.float32) - src[0, :] = center + scale_tmp * shift - src[1, :] = center + src_dir + scale_tmp * shift - dst[0, :] = [dst_w * 0.5, dst_h * 0.5] - dst[1, :] = np.array([dst_w * 0.5, dst_h * 0.5], np.float32) + dst_dir - - src[2:, :] = get_3rd_point(src[0, :], src[1, :]) - dst[2:, :] = get_3rd_point(dst[0, :], dst[1, :]) - - if inv: - trans = cv2.getAffineTransform(np.float32(dst), np.float32(src)) - else: - trans = cv2.getAffineTransform(np.float32(src), np.float32(dst)) - - return trans - -def get_3rd_point(a, b): - direct = a - b - return b + np.array([-direct[1], direct[0]], dtype=np.float32) - -def get_dir(src_point, rot_rad): - sn, cs = np.sin(rot_rad), np.cos(rot_rad) - - src_result = [0, 0] - src_result[0] = src_point[0] * cs - src_point[1] * sn - src_result[1] = src_point[0] * sn + src_point[1] * cs - - return src_result -if __name__ == "__main__": - file_path = os.path.abspath(sys.argv[1]) - bin_path = os.path.abspath(sys.argv[2]) - preprocess(file_path, bin_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import os +import cv2 +import numpy as np +import torch + +def preprocess(file_path, bin_path): + in_files = os.listdir(file_path) + if not os.path.exists(bin_path): + os.makedirs(bin_path) + i = 0 + for file in sorted(in_files): + i = i + 1 + print(file, "===", i) + image = cv2.imread(os.path.join(file_path, file)) + height, width = image.shape[0:2] + new_height = int(height) + new_width = int(width) + #Fix size testing + inp_height, inp_width = 512, 512 + c = np.array([new_width / 2., new_height / 2.], dtype=np.float32) + s = max(height, width) * 1.0 + trans_input = get_affine_transform(c, s, 0, [inp_width, inp_height]) + resized_image = cv2.resize(image, (new_width, new_height)) + inp_image = cv2.warpAffine( + resized_image, trans_input, (inp_width, inp_height),flags=cv2.INTER_LINEAR) + + inp_image = ((inp_image / 255. - [[[0.40789655,0.44719303,0.47026116]]]) / [[[0.2886383,0.27408165,0.27809834]]]).astype(np.float32) + images = inp_image.transpose(2, 0, 1).reshape(1, 3, inp_height, inp_width) + images = torch.from_numpy(images) + img = np.array(images).astype(np.float32) + img.tofile(os.path.join(bin_path, file.split('.')[0] + '.bin')) + +def get_affine_transform(center, + scale, + rot, + output_size, + shift=np.array([0, 0], dtype=np.float32), + inv=0): + if not isinstance(scale, np.ndarray) and not isinstance(scale, list): + scale = np.array([scale, scale], dtype=np.float32) + + scale_tmp = scale + src_w = scale_tmp[0] + dst_w = output_size[0] + dst_h = output_size[1] + + rot_rad = np.pi * rot / 180 + src_dir = get_dir([0, src_w * -0.5], rot_rad) + dst_dir = np.array([0, dst_w * -0.5], np.float32) + + src = np.zeros((3, 2), dtype=np.float32) + dst = np.zeros((3, 2), dtype=np.float32) + src[0, :] = center + scale_tmp * shift + src[1, :] = center + src_dir + scale_tmp * shift + dst[0, :] = [dst_w * 0.5, dst_h * 0.5] + dst[1, :] = np.array([dst_w * 0.5, dst_h * 0.5], np.float32) + dst_dir + + src[2:, :] = get_3rd_point(src[0, :], src[1, :]) + dst[2:, :] = get_3rd_point(dst[0, :], dst[1, :]) + + if inv: + trans = cv2.getAffineTransform(np.float32(dst), np.float32(src)) + else: + trans = cv2.getAffineTransform(np.float32(src), np.float32(dst)) + + return trans + +def get_3rd_point(a, b): + direct = a - b + return b + np.array([-direct[1], direct[0]], dtype=np.float32) + +def get_dir(src_point, rot_rad): + sn, cs = np.sin(rot_rad), np.cos(rot_rad) + + src_result = [0, 0] + src_result[0] = src_point[0] * cs - src_point[1] * sn + src_result[1] = src_point[0] * sn + src_point[1] * cs + + return src_result +if __name__ == "__main__": + file_path = os.path.abspath(sys.argv[1]) + bin_path = os.path.abspath(sys.argv[2]) + preprocess(file_path, bin_path) diff --git a/ACL_PyTorch/contrib/cv/detection/CenterNet/CenterNet_pth2onnx.py b/ACL_PyTorch/contrib/cv/detection/CenterNet/CenterNet_pth2onnx.py index 3fcd485e9208259c3a495488b450f8fb13a17821..e5ccee5b9e831486f887f027677fcd82636fdf54 100644 --- a/ACL_PyTorch/contrib/cv/detection/CenterNet/CenterNet_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/CenterNet/CenterNet_pth2onnx.py @@ -1,54 +1,54 @@ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -CENTERNET_PATH = '../src' -sys.path.insert(0, CENTERNET_PATH) -MODEL_PATH = '../models/ctdet_coco_dla_2x.pth' -import os -import _init_paths -import torch -import torch.utils.data -from opts import opts -from models.model import create_model, load_model, save_model -from models.data_parallel import DataParallel -from logger import Logger -from datasets.dataset_factory import get_dataset - - -def convert(): - #device = torch.device("cpu") - device = torch.device("cuda") - torch.set_default_tensor_type(torch.cuda.FloatTensor) - TASK = 'ctdet' - opt = opts().parse('{} --load_model {}'.format(TASK, MODEL_PATH).split(' ')) - Dataset = get_dataset(opt.dataset, opt.task) - opt = opts().update_dataset_info_and_set_heads(opt, Dataset) - model = create_model(opt.arch, opt.heads, opt.head_conv) - model = load_model(model, input_file, None, opt.resume, opt.lr, opt.lr_step) - model.eval() - - input_names = ["actual_input"] - output_names = ["output1","output2","output3"] - dynamic_axes = {'actual_input': {0: '-1'}, 'output1': {0: '-1'}, 'output2': {0: '-1'}, 'output3': {0: '-1'}} - dummy_input = torch.randn(1, 3, 512, 512) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, opset_version=11, verbose=True) - -if __name__ == "__main__": - input_file = sys.argv[1] - output_file = sys.argv[2] - convert() +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +CENTERNET_PATH = '../src' +sys.path.insert(0, CENTERNET_PATH) +MODEL_PATH = '../models/ctdet_coco_dla_2x.pth' +import os +import _init_paths +import torch +import torch.utils.data +from opts import opts +from models.model import create_model, load_model, save_model +from models.data_parallel import DataParallel +from logger import Logger +from datasets.dataset_factory import get_dataset + + +def convert(): + #device = torch.device("cpu") + device = torch.device("cuda") + torch.set_default_tensor_type(torch.cuda.FloatTensor) + TASK = 'ctdet' + opt = opts().parse('{} --load_model {}'.format(TASK, MODEL_PATH).split(' ')) + Dataset = get_dataset(opt.dataset, opt.task) + opt = opts().update_dataset_info_and_set_heads(opt, Dataset) + model = create_model(opt.arch, opt.heads, opt.head_conv) + model = load_model(model, input_file, None, opt.resume, opt.lr, opt.lr_step) + model.eval() + + input_names = ["actual_input"] + output_names = ["output1","output2","output3"] + dynamic_axes = {'actual_input': {0: '-1'}, 'output1': {0: '-1'}, 'output2': {0: '-1'}, 'output3': {0: '-1'}} + dummy_input = torch.randn(1, 3, 512, 512) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, opset_version=11, verbose=True) + +if __name__ == "__main__": + input_file = sys.argv[1] + output_file = sys.argv[2] + convert() diff --git a/ACL_PyTorch/contrib/cv/detection/CenterNet/README.md b/ACL_PyTorch/contrib/cv/detection/CenterNet/README.md index 7a92a8f542707820f89f1c28687ecc068580bf68..9f7e243935466461ad7a9253a7035ef6b7f14014 100644 --- a/ACL_PyTorch/contrib/cv/detection/CenterNet/README.md +++ b/ACL_PyTorch/contrib/cv/detection/CenterNet/README.md @@ -1,103 +1,103 @@ -# CenterNet模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,建议手动安装 - -``` -pip3 install -r requirements.txt -``` - -2.获取,修改与安装开源模型代码 - -安装CenterNet - -``` -source env.sh -git clone https://github.com/xingyizhou/CenterNet -cd CenterNet/src/lib/models/networks -rm -r DCNv2 -rm -r pose_dla_dcn.py -git clone https://github.com/jinfagang/DCNv2_latest.git -mv DCNv2_latest DCNv2 -cd DCNv2 -rm -r dcn_v2.py -cd ../../../../../../ -mv dcn_v2.py CenterNet/src/lib/models/networks/DCNv2 -mv pose_dla_dcn.py CenterNet/src/lib/models/networks - -cd CenterNet/src/lib/external -make -cd ../models/networks/DCNv2 -python3 setup.py build develop -cd ../../../../../../ -``` - -备注:将源码中DCNv2算子更新到DCNv2_latest,以支持pytorch1.5;按照上述步骤替换pose_dcn_dla.py文件与dcn_v2.py文件,以修改自定义算子,实现onnx的推理过程 - -另外,需要单独修改python环境中的utils.py文件,不同环境下具体路径有一定差异。手动将/usr/local/python3.7.5/lib/python3.7/site-packages/torch/onnx/utils.py下述部分做相应更改: - -```python - not val_use_external_data_format: - # Only run checker if enabled and we are not using ATEN fallback and - # large model format export in not enabled. -- _check_onnx_proto(proto) -+ pass -``` -3.获取权重文件 - -[ctdet_coco_dla_2x.pth](https://drive.google.com/open?id=1pl_-ael8wERdUREEnaIfqOV_VF2bEVRT),放在当前目录下 - -4.数据集 -获取COCO数据集:[coco2017](https://cocodataset.org/#download),下载其中val2017图片及其标注文件([2017 Val images](http://images.cocodataset.org/zips/val2017.zip),[2017 Train/Val annotations](http://images.cocodataset.org/annotations/annotations_trainval2017.zip)),解压后放入/opt/npu/datasets/coco以及CenterNet/data/coco/路径下,其中val2017目录存放coco数据集的验证集图片,annotations目录存放coco数据集的instances_val2017.json,文件目录结构如下: - -``` -CenterNet -├── data -│ ├── coco -│ │ ├── annotations -│ │ ├── val2017 -``` - -5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) -将benchmark.x86_64放到当前目录 - -## 2 离线推理 - -CenterNet模型pth2onnx脚本由于算子暂不支持cpu,故只能在gpu运行,故将pth2om.sh拆为pth2onnx.sh和onnx2om.sh - -**在gpu上:** - -``` -bash test/pth2onnx.sh -``` - -并将生成的CenterNet.onnx移到310上,路径为:{当前目录}/test - -**在310上:** - -**test目录下已经打包了一个正确的onnx,可解压后直接使用** - -``` -unzip test/onnx.zip -``` - -``` -bash test/onnx2om.sh -bash test/eval_acc_perf.sh --datasets_path=/opt/npu/datasets/coco -``` - -**评测结果:** - -| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| ------------- | ----------- | --------------- | -------- | -------- | -| CenterNet_bs1 | AP : 36.6 | AP : 36.4 | 23.25fps | 17.25fps | - -备注: - -1.原官网pth精度 AP : 37.4 是在线推理时keep_res(保持分辨率)的结果,但由于离线推理需要固定shape,故需要去掉keep_res(保持分辨率)。去掉keep_res(保持分辨率)后,跑在线推理精度评估得到 AP : 36.6 ,故以 AP : 36.6 作为精度基准 - -2.onnx因包含npu自定义算子dcnv2而不能推理,故使用在线推理测试性能 - -3.原模型在线推理中仅实现batchsize=1的精度测试和性能测试 - +# CenterNet模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,建议手动安装 + +``` +pip3 install -r requirements.txt +``` + +2.获取,修改与安装开源模型代码 + +安装CenterNet + +``` +source env.sh +git clone https://github.com/xingyizhou/CenterNet +cd CenterNet/src/lib/models/networks +rm -r DCNv2 +rm -r pose_dla_dcn.py +git clone https://github.com/jinfagang/DCNv2_latest.git +mv DCNv2_latest DCNv2 +cd DCNv2 +rm -r dcn_v2.py +cd ../../../../../../ +mv dcn_v2.py CenterNet/src/lib/models/networks/DCNv2 +mv pose_dla_dcn.py CenterNet/src/lib/models/networks + +cd CenterNet/src/lib/external +make +cd ../models/networks/DCNv2 +python3 setup.py build develop +cd ../../../../../../ +``` + +备注:将源码中DCNv2算子更新到DCNv2_latest,以支持pytorch1.5;按照上述步骤替换pose_dcn_dla.py文件与dcn_v2.py文件,以修改自定义算子,实现onnx的推理过程 + +另外,需要单独修改python环境中的utils.py文件,不同环境下具体路径有一定差异。手动将/usr/local/python3.7.5/lib/python3.7/site-packages/torch/onnx/utils.py下述部分做相应更改: + +```python + not val_use_external_data_format: + # Only run checker if enabled and we are not using ATEN fallback and + # large model format export in not enabled. +- _check_onnx_proto(proto) ++ pass +``` +3.获取权重文件 + +[ctdet_coco_dla_2x.pth](https://drive.google.com/open?id=1pl_-ael8wERdUREEnaIfqOV_VF2bEVRT),放在当前目录下 + +4.数据集 +获取COCO数据集:[coco2017](https://cocodataset.org/#download),下载其中val2017图片及其标注文件([2017 Val images](http://images.cocodataset.org/zips/val2017.zip),[2017 Train/Val annotations](http://images.cocodataset.org/annotations/annotations_trainval2017.zip)),解压后放入/opt/npu/datasets/coco以及CenterNet/data/coco/路径下,其中val2017目录存放coco数据集的验证集图片,annotations目录存放coco数据集的instances_val2017.json,文件目录结构如下: + +``` +CenterNet +├── data +│ ├── coco +│ │ ├── annotations +│ │ ├── val2017 +``` + +5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) +将benchmark.x86_64放到当前目录 + +## 2 离线推理 + +CenterNet模型pth2onnx脚本由于算子暂不支持cpu,故只能在gpu运行,故将pth2om.sh拆为pth2onnx.sh和onnx2om.sh + +**在gpu上:** + +``` +bash test/pth2onnx.sh +``` + +并将生成的CenterNet.onnx移到310上,路径为:{当前目录}/test + +**在310上:** + +**test目录下已经打包了一个正确的onnx,可解压后直接使用** + +``` +unzip test/onnx.zip +``` + +``` +bash test/onnx2om.sh +bash test/eval_acc_perf.sh --datasets_path=/opt/npu/datasets/coco +``` + +**评测结果:** + +| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| ------------- | ----------- | --------------- | -------- | -------- | +| CenterNet_bs1 | AP : 36.6 | AP : 36.4 | 23.25fps | 17.25fps | + +备注: + +1.原官网pth精度 AP : 37.4 是在线推理时keep_res(保持分辨率)的结果,但由于离线推理需要固定shape,故需要去掉keep_res(保持分辨率)。去掉keep_res(保持分辨率)后,跑在线推理精度评估得到 AP : 36.6 ,故以 AP : 36.6 作为精度基准 + +2.onnx因包含npu自定义算子dcnv2而不能推理,故使用在线推理测试性能 + +3.原模型在线推理中仅实现batchsize=1的精度测试和性能测试 + diff --git a/ACL_PyTorch/contrib/cv/detection/DSFD/DSFD.patch b/ACL_PyTorch/contrib/cv/detection/DSFD/DSFD.patch index ad7be24d19dfc758bd7a649efb191fdfaaf1dd2c..6cbd178cb9f75d1c8e235cdf6bd21d48cc799769 100644 --- a/ACL_PyTorch/contrib/cv/detection/DSFD/DSFD.patch +++ b/ACL_PyTorch/contrib/cv/detection/DSFD/DSFD.patch @@ -6693,60 +6693,60 @@ index 8c41037111..0000000000 --- a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/eval_tools/box_overlaps.pyx +++ /dev/null @@ -1,55 +0,0 @@ --# -------------------------------------------------------- --# Fast R-CNN --# Copyright (c) 2015 Microsoft --# Licensed under The MIT License [see LICENSE for details] --# Written by Sergey Karayev --# -------------------------------------------------------- -- --cimport cython --import numpy as np --cimport numpy as np -- --DTYPE = np.float --ctypedef np.float_t DTYPE_t -- --def bbox_overlaps( -- np.ndarray[DTYPE_t, ndim=2] boxes, -- np.ndarray[DTYPE_t, ndim=2] query_boxes): -- """ -- Parameters -- ---------- -- boxes: (N, 4) ndarray of float -- query_boxes: (K, 4) ndarray of float -- Returns -- ------- -- overlaps: (N, K) ndarray of overlap between boxes and query_boxes -- """ -- cdef unsigned int N = boxes.shape[0] -- cdef unsigned int K = query_boxes.shape[0] -- cdef np.ndarray[DTYPE_t, ndim=2] overlaps = np.zeros((N, K), dtype=DTYPE) -- cdef DTYPE_t iw, ih, box_area -- cdef DTYPE_t ua -- cdef unsigned int k, n -- for k in range(K): -- box_area = ( -- (query_boxes[k, 2] - query_boxes[k, 0] + 1) * -- (query_boxes[k, 3] - query_boxes[k, 1] + 1) -- ) -- for n in range(N): -- iw = ( -- min(boxes[n, 2], query_boxes[k, 2]) - -- max(boxes[n, 0], query_boxes[k, 0]) + 1 -- ) -- if iw > 0: -- ih = ( -- min(boxes[n, 3], query_boxes[k, 3]) - -- max(boxes[n, 1], query_boxes[k, 1]) + 1 -- ) -- if ih > 0: -- ua = float( -- (boxes[n, 2] - boxes[n, 0] + 1) * -- (boxes[n, 3] - boxes[n, 1] + 1) + -- box_area - iw * ih -- ) -- overlaps[n, k] = iw * ih / ua +-# -------------------------------------------------------- +-# Fast R-CNN +-# Copyright (c) 2015 Microsoft +-# Licensed under The MIT License [see LICENSE for details] +-# Written by Sergey Karayev +-# -------------------------------------------------------- +- +-cimport cython +-import numpy as np +-cimport numpy as np +- +-DTYPE = np.float +-ctypedef np.float_t DTYPE_t +- +-def bbox_overlaps( +- np.ndarray[DTYPE_t, ndim=2] boxes, +- np.ndarray[DTYPE_t, ndim=2] query_boxes): +- """ +- Parameters +- ---------- +- boxes: (N, 4) ndarray of float +- query_boxes: (K, 4) ndarray of float +- Returns +- ------- +- overlaps: (N, K) ndarray of overlap between boxes and query_boxes +- """ +- cdef unsigned int N = boxes.shape[0] +- cdef unsigned int K = query_boxes.shape[0] +- cdef np.ndarray[DTYPE_t, ndim=2] overlaps = np.zeros((N, K), dtype=DTYPE) +- cdef DTYPE_t iw, ih, box_area +- cdef DTYPE_t ua +- cdef unsigned int k, n +- for k in range(K): +- box_area = ( +- (query_boxes[k, 2] - query_boxes[k, 0] + 1) * +- (query_boxes[k, 3] - query_boxes[k, 1] + 1) +- ) +- for n in range(N): +- iw = ( +- min(boxes[n, 2], query_boxes[k, 2]) - +- max(boxes[n, 0], query_boxes[k, 0]) + 1 +- ) +- if iw > 0: +- ih = ( +- min(boxes[n, 3], query_boxes[k, 3]) - +- max(boxes[n, 1], query_boxes[k, 1]) + 1 +- ) +- if ih > 0: +- ua = float( +- (boxes[n, 2] - boxes[n, 0] + 1) * +- (boxes[n, 3] - boxes[n, 1] + 1) + +- box_area - iw * ih +- ) +- overlaps[n, k] = iw * ih / ua - return overlaps \ No newline at end of file diff --git a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/eval_tools/setup.py b/contrib/ACL_PyTorch/Research/cv/detection/DSFD/eval_tools/setup.py @@ -6755,676 +6755,676 @@ index 53f56150a9..0000000000 --- a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/eval_tools/setup.py +++ /dev/null @@ -1,22 +0,0 @@ --# Copyright 2021 Huawei Technologies Co., Ltd --# --# Licensed under the Apache License, Version 2.0 (the "License"); --# you may not use this file except in compliance with the License. --# You may obtain a copy of the License at --# --# http://www.apache.org/licenses/LICENSE-2.0 --# --# Unless required by applicable law or agreed to in writing, software --# distributed under the License is distributed on an "AS IS" BASIS, --# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --# See the License for the specific language governing permissions and --# limitations under the License. -- --#coding=utf-8 -- --from distutils.core import setup, Extension --from Cython.Build import cythonize --import numpy -- --package = Extension('bbox', ['box_overlaps.pyx'], include_dirs=[numpy.get_include()]) --setup(ext_modules=cythonize([package])) +-# Copyright 2021 Huawei Technologies Co., Ltd +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +- +-#coding=utf-8 +- +-from distutils.core import setup, Extension +-from Cython.Build import cythonize +-import numpy +- +-package = Extension('bbox', ['box_overlaps.pyx'], include_dirs=[numpy.get_include()]) +-setup(ext_modules=cythonize([package])) diff --git a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/__init__.py b/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/__init__.py deleted file mode 100644 index e3b3268753..0000000000 --- a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/__init__.py +++ /dev/null @@ -1,23 +0,0 @@ --# Copyright 2021 Huawei Technologies Co., Ltd --# --# Licensed under the Apache License, Version 2.0 (the "License"); --# you may not use this file except in compliance with the License. --# You may obtain a copy of the License at --# --# http://www.apache.org/licenses/LICENSE-2.0 --# --# Unless required by applicable law or agreed to in writing, software --# distributed under the License is distributed on an "AS IS" BASIS, --# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --# See the License for the specific language governing permissions and --# limitations under the License. -- --#-*- coding:utf-8 -*- -- --from __future__ import division --from __future__ import absolute_import --from __future__ import print_function -- -- --from .functions import * --from .modules import * +-# Copyright 2021 Huawei Technologies Co., Ltd +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +- +-#-*- coding:utf-8 -*- +- +-from __future__ import division +-from __future__ import absolute_import +-from __future__ import print_function +- +- +-from .functions import * +-from .modules import * diff --git a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/bbox_utils.py b/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/bbox_utils.py deleted file mode 100644 index 71766a3145..0000000000 --- a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/bbox_utils.py +++ /dev/null @@ -1,324 +0,0 @@ --# Copyright 2021 Huawei Technologies Co., Ltd --# --# Licensed under the Apache License, Version 2.0 (the "License"); --# you may not use this file except in compliance with the License. --# You may obtain a copy of the License at --# --# http://www.apache.org/licenses/LICENSE-2.0 --# --# Unless required by applicable law or agreed to in writing, software --# distributed under the License is distributed on an "AS IS" BASIS, --# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --# See the License for the specific language governing permissions and --# limitations under the License. -- --#coding=utf-8 -- --from __future__ import division --from __future__ import absolute_import --from __future__ import print_function -- -- --import torch -- -- --def point_form(boxes): -- """ Convert prior_boxes to (xmin, ymin, xmax, ymax) -- representation for comparison to point form ground truth data. -- Args: -- boxes: (tensor) center-size default boxes from priorbox layers. -- Return: -- boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes. -- """ -- return torch.cat((boxes[:, :2] - boxes[:, 2:] / 2, # xmin, ymin -- boxes[:, :2] + boxes[:, 2:] / 2), 1) # xmax, ymax -- -- --def center_size(boxes): -- """ Convert prior_boxes to (cx, cy, w, h) -- representation for comparison to center-size form ground truth data. -- Args: -- boxes: (tensor) point_form boxes -- Return: -- boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes. -- """ -- return torch.cat([(boxes[:, 2:] + boxes[:, :2]) / 2, # cx, cy -- boxes[:, 2:] - boxes[:, :2]], 1) # w, h -- -- --def intersect(box_a, box_b): -- """ We resize both tensors to [A,B,2] without new malloc: -- [A,2] -> [A,1,2] -> [A,B,2] -- [B,2] -> [1,B,2] -> [A,B,2] -- Then we compute the area of intersect between box_a and box_b. -- Args: -- box_a: (tensor) bounding boxes, Shape: [A,4]. -- box_b: (tensor) bounding boxes, Shape: [B,4]. -- Return: -- (tensor) intersection area, Shape: [A,B]. -- """ -- A = box_a.size(0) -- B = box_b.size(0) -- max_xy = torch.min(box_a[:, 2:].unsqueeze(1).expand(A, B, 2), -- box_b[:, 2:].unsqueeze(0).expand(A, B, 2)) -- min_xy = torch.max(box_a[:, :2].unsqueeze(1).expand(A, B, 2), -- box_b[:, :2].unsqueeze(0).expand(A, B, 2)) -- inter = torch.clamp((max_xy - min_xy), min=0) -- return inter[:, :, 0] * inter[:, :, 1] -- -- --def jaccard(box_a, box_b): -- """Compute the jaccard overlap of two sets of boxes. The jaccard overlap -- is simply the intersection over union of two boxes. Here we operate on -- ground truth boxes and default boxes. -- E.g.: -- A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) -- Args: -- box_a: (tensor) Ground truth bounding boxes, Shape: [num_objects,4] -- box_b: (tensor) Prior boxes from priorbox layers, Shape: [num_priors,4] -- Return: -- jaccard overlap: (tensor) Shape: [box_a.size(0), box_b.size(0)] -- """ -- inter = intersect(box_a, box_b) -- area_a = ((box_a[:, 2] - box_a[:, 0]) * -- (box_a[:, 3] - box_a[:, 1])).unsqueeze(1).expand_as(inter) # [A,B] -- area_b = ((box_b[:, 2] - box_b[:, 0]) * -- (box_b[:, 3] - box_b[:, 1])).unsqueeze(0).expand_as(inter) # [A,B] -- union = area_a + area_b - inter -- return inter / union # [A,B] -- -- --def match(threshold, truths, priors, variances, labels, loc_t, conf_t, idx): -- """Match each prior box with the ground truth box of the highest jaccard -- overlap, encode the bounding boxes, then return the matched indices -- corresponding to both confidence and location preds. -- Args: -- threshold: (float) The overlap threshold used when mathing boxes. -- truths: (tensor) Ground truth boxes, Shape: [num_obj, num_priors]. -- priors: (tensor) Prior boxes from priorbox layers, Shape: [n_priors,4]. -- variances: (tensor) Variances corresponding to each prior coord, -- Shape: [num_priors, 4]. -- labels: (tensor) All the class labels for the image, Shape: [num_obj]. -- loc_t: (tensor) Tensor to be filled w/ endcoded location targets. -- conf_t: (tensor) Tensor to be filled w/ matched indices for conf preds. -- idx: (int) current batch index -- Return: -- The matched indices corresponding to 1)location and 2)confidence preds. -- """ -- # jaccard index -- overlaps = jaccard( -- truths, -- point_form(priors) -- ) -- # (Bipartite Matching) -- # [1,num_objects] best prior for each ground truth -- best_prior_overlap, best_prior_idx = overlaps.max(1, keepdim=True) -- # [1,num_priors] best ground truth for each prior -- best_truth_overlap, best_truth_idx = overlaps.max( -- 0, keepdim=True) # 0-2000 -- best_truth_idx.squeeze_(0) -- best_truth_overlap.squeeze_(0) -- best_prior_idx.squeeze_(1) -- best_prior_overlap.squeeze_(1) -- best_truth_overlap.index_fill_(0, best_prior_idx, 2) # ensure best prior -- # TODO refactor: index best_prior_idx with long tensor -- # ensure every gt matches with its prior of max overlap -- for j in range(best_prior_idx.size(0)): -- best_truth_idx[best_prior_idx[j]] = j -- _th1, _th2, _th3 = threshold # _th1 = 0.1 ,_th2 = 0.35,_th3 = 0.5 -- -- N = (torch.sum(best_prior_overlap >= _th2) + -- torch.sum(best_prior_overlap >= _th3)) // 2 -- matches = truths[best_truth_idx] # Shape: [num_priors,4] -- conf = labels[best_truth_idx] # Shape: [num_priors] -- conf[best_truth_overlap < _th2] = 0 # label as background -- -- best_truth_overlap_clone = best_truth_overlap.clone() -- add_idx = best_truth_overlap_clone.gt( -- _th1).eq(best_truth_overlap_clone.lt(_th2)) -- best_truth_overlap_clone[1 - add_idx] = 0 -- stage2_overlap, stage2_idx = best_truth_overlap_clone.sort(descending=True) -- -- stage2_overlap = stage2_overlap.gt(_th1) -- -- if N > 0: -- N = torch.sum(stage2_overlap[:N]) if torch.sum( -- stage2_overlap[:N]) < N else N -- conf[stage2_idx[:N]] += 1 -- -- loc = encode(matches, priors, variances) -- loc_t[idx] = loc # [num_priors,4] encoded offsets to learn -- conf_t[idx] = conf # [num_priors] top class label for each prior -- -- --def match_ssd(threshold, truths, priors, variances, labels, loc_t, conf_t, idx): -- """Match each prior box with the ground truth box of the highest jaccard -- overlap, encode the bounding boxes, then return the matched indices -- corresponding to both confidence and location preds. -- Args: -- threshold: (float) The overlap threshold used when mathing boxes. -- truths: (tensor) Ground truth boxes, Shape: [num_obj, num_priors]. -- priors: (tensor) Prior boxes from priorbox layers, Shape: [n_priors,4]. -- variances: (tensor) Variances corresponding to each prior coord, -- Shape: [num_priors, 4]. -- labels: (tensor) All the class labels for the image, Shape: [num_obj]. -- loc_t: (tensor) Tensor to be filled w/ endcoded location targets. -- conf_t: (tensor) Tensor to be filled w/ matched indices for conf preds. -- idx: (int) current batch index -- Return: -- The matched indices corresponding to 1)location and 2)confidence preds. -- """ -- # jaccard index -- overlaps = jaccard( -- truths, -- point_form(priors) -- ) -- # (Bipartite Matching) -- # [1,num_objects] best prior for each ground truth -- best_prior_overlap, best_prior_idx = overlaps.max(1, keepdim=True) -- # [1,num_priors] best ground truth for each prior -- best_truth_overlap, best_truth_idx = overlaps.max( -- 0, keepdim=True) # 0-2000 -- best_truth_idx.squeeze_(0) -- best_truth_overlap.squeeze_(0) -- best_prior_idx.squeeze_(1) -- best_prior_overlap.squeeze_(1) -- best_truth_overlap.index_fill_(0, best_prior_idx, 2) # ensure best prior -- # TODO refactor: index best_prior_idx with long tensor -- # ensure every gt matches with its prior of max overlap -- for j in range(best_prior_idx.size(0)): -- best_truth_idx[best_prior_idx[j]] = j -- matches = truths[best_truth_idx] # Shape: [num_priors,4] -- conf = labels[best_truth_idx] # Shape: [num_priors] -- conf[best_truth_overlap < threshold] = 0 # label as background -- loc = encode(matches, priors, variances) -- loc_t[idx] = loc # [num_priors,4] encoded offsets to learn -- conf_t[idx] = conf # [num_priors] top class label for each prior -- -- --def encode(matched, priors, variances): -- """Encode the variances from the priorbox layers into the ground truth boxes -- we have matched (based on jaccard overlap) with the prior boxes. -- Args: -- matched: (tensor) Coords of ground truth for each prior in point-form -- Shape: [num_priors, 4]. -- priors: (tensor) Prior boxes in center-offset form -- Shape: [num_priors,4]. -- variances: (list[float]) Variances of priorboxes -- Return: -- encoded boxes (tensor), Shape: [num_priors, 4] -- """ -- -- # dist b/t match center and prior's center -- g_cxcy = (matched[:, :2] + matched[:, 2:]) / 2 - priors[:, :2] -- # encode variance -- g_cxcy /= (variances[0] * priors[:, 2:]) -- # match wh / prior wh -- g_wh = (matched[:, 2:] - matched[:, :2]) / priors[:, 2:] -- #g_wh = torch.log(g_wh) / variances[1] -- g_wh = torch.log(g_wh) / variances[1] -- # return target for smooth_l1_loss -- return torch.cat([g_cxcy, g_wh], 1) # [num_priors,4] -- -- --# Adapted from https://github.com/Hakuyume/chainer-ssd --def decode(loc, priors, variances): -- """Decode locations from predictions using priors to undo -- the encoding we did for offset regression at train time. -- Args: -- loc (tensor): location predictions for loc layers, -- Shape: [num_priors,4] -- priors (tensor): Prior boxes in center-offset form. -- Shape: [num_priors,4]. -- variances: (list[float]) Variances of priorboxes -- Return: -- decoded bounding box predictions -- """ -- -- boxes = torch.cat(( -- priors[:, :2] + loc[:, :2] * variances[0] * priors[:, 2:], -- priors[:, 2:] * torch.exp(loc[:, 2:] * variances[1])), 1) -- boxes[:, :2] -= boxes[:, 2:] / 2 -- boxes[:, 2:] += boxes[:, :2] -- return boxes -- -- --def log_sum_exp(x): -- """Utility function for computing log_sum_exp while determining -- This will be used to determine unaveraged confidence loss across -- all examples in a batch. -- Args: -- x (Variable(tensor)): conf_preds from conf layers -- """ -- x_max = x.data.max() -- return torch.log(torch.sum(torch.exp(x - x_max), 1, keepdim=True)) + x_max -- -- --# Original author: Francisco Massa: --# https://github.com/fmassa/object-detection.torch --# Ported to PyTorch by Max deGroot (02/01/2017) --def nms(boxes, scores, overlap=0.5, top_k=200): -- """Apply non-maximum suppression at test time to avoid detecting too many -- overlapping bounding boxes for a given object. -- Args: -- boxes: (tensor) The location preds for the img, Shape: [num_priors,4]. -- scores: (tensor) The class predscores for the img, Shape:[num_priors]. -- overlap: (float) The overlap thresh for suppressing unnecessary boxes. -- top_k: (int) The Maximum number of box preds to consider. -- Return: -- The indices of the kept boxes with respect to num_priors. -- """ -- -- keep = scores.new(scores.size(0)).zero_().long() -- if boxes.numel() == 0: -- return keep -- x1 = boxes[:, 0] -- y1 = boxes[:, 1] -- x2 = boxes[:, 2] -- y2 = boxes[:, 3] -- area = torch.mul(x2 - x1, y2 - y1) -- v, idx = scores.sort(0) # sort in ascending order -- # I = I[v >= 0.01] -- idx = idx[-top_k:] # indices of the top-k largest vals -- xx1 = boxes.new() -- yy1 = boxes.new() -- xx2 = boxes.new() -- yy2 = boxes.new() -- w = boxes.new() -- h = boxes.new() -- -- # keep = torch.Tensor() -- count = 0 -- while idx.numel() > 0: -- i = idx[-1] # index of current largest val -- # keep.append(i) -- keep[count] = i -- count += 1 -- if idx.size(0) == 1: -- break -- idx = idx[:-1] # remove kept element from view -- # load bboxes of next highest vals -- torch.index_select(x1, 0, idx, out=xx1) -- torch.index_select(y1, 0, idx, out=yy1) -- torch.index_select(x2, 0, idx, out=xx2) -- torch.index_select(y2, 0, idx, out=yy2) -- # store element-wise max with next highest score -- xx1 = torch.clamp(xx1, min=x1[i]) -- yy1 = torch.clamp(yy1, min=y1[i]) -- xx2 = torch.clamp(xx2, max=x2[i]) -- yy2 = torch.clamp(yy2, max=y2[i]) -- w.resize_as_(xx2) -- h.resize_as_(yy2) -- w = xx2 - xx1 -- h = yy2 - yy1 -- # check sizes of xx1 and xx2.. after each iteration -- w = torch.clamp(w, min=0.0) -- h = torch.clamp(h, min=0.0) -- inter = w * h -- # IoU = i / (area(a) + area(b) - i) -- rem_areas = torch.index_select(area, 0, idx) # load remaining areas) -- union = (rem_areas - inter) + area[i] -- IoU = inter / union # store result in iou -- # keep only elements with an IoU <= overlap -- idx = idx[IoU.le(overlap)] -- return keep, count +-# Copyright 2021 Huawei Technologies Co., Ltd +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +- +-#coding=utf-8 +- +-from __future__ import division +-from __future__ import absolute_import +-from __future__ import print_function +- +- +-import torch +- +- +-def point_form(boxes): +- """ Convert prior_boxes to (xmin, ymin, xmax, ymax) +- representation for comparison to point form ground truth data. +- Args: +- boxes: (tensor) center-size default boxes from priorbox layers. +- Return: +- boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes. +- """ +- return torch.cat((boxes[:, :2] - boxes[:, 2:] / 2, # xmin, ymin +- boxes[:, :2] + boxes[:, 2:] / 2), 1) # xmax, ymax +- +- +-def center_size(boxes): +- """ Convert prior_boxes to (cx, cy, w, h) +- representation for comparison to center-size form ground truth data. +- Args: +- boxes: (tensor) point_form boxes +- Return: +- boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes. +- """ +- return torch.cat([(boxes[:, 2:] + boxes[:, :2]) / 2, # cx, cy +- boxes[:, 2:] - boxes[:, :2]], 1) # w, h +- +- +-def intersect(box_a, box_b): +- """ We resize both tensors to [A,B,2] without new malloc: +- [A,2] -> [A,1,2] -> [A,B,2] +- [B,2] -> [1,B,2] -> [A,B,2] +- Then we compute the area of intersect between box_a and box_b. +- Args: +- box_a: (tensor) bounding boxes, Shape: [A,4]. +- box_b: (tensor) bounding boxes, Shape: [B,4]. +- Return: +- (tensor) intersection area, Shape: [A,B]. +- """ +- A = box_a.size(0) +- B = box_b.size(0) +- max_xy = torch.min(box_a[:, 2:].unsqueeze(1).expand(A, B, 2), +- box_b[:, 2:].unsqueeze(0).expand(A, B, 2)) +- min_xy = torch.max(box_a[:, :2].unsqueeze(1).expand(A, B, 2), +- box_b[:, :2].unsqueeze(0).expand(A, B, 2)) +- inter = torch.clamp((max_xy - min_xy), min=0) +- return inter[:, :, 0] * inter[:, :, 1] +- +- +-def jaccard(box_a, box_b): +- """Compute the jaccard overlap of two sets of boxes. The jaccard overlap +- is simply the intersection over union of two boxes. Here we operate on +- ground truth boxes and default boxes. +- E.g.: +- A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) +- Args: +- box_a: (tensor) Ground truth bounding boxes, Shape: [num_objects,4] +- box_b: (tensor) Prior boxes from priorbox layers, Shape: [num_priors,4] +- Return: +- jaccard overlap: (tensor) Shape: [box_a.size(0), box_b.size(0)] +- """ +- inter = intersect(box_a, box_b) +- area_a = ((box_a[:, 2] - box_a[:, 0]) * +- (box_a[:, 3] - box_a[:, 1])).unsqueeze(1).expand_as(inter) # [A,B] +- area_b = ((box_b[:, 2] - box_b[:, 0]) * +- (box_b[:, 3] - box_b[:, 1])).unsqueeze(0).expand_as(inter) # [A,B] +- union = area_a + area_b - inter +- return inter / union # [A,B] +- +- +-def match(threshold, truths, priors, variances, labels, loc_t, conf_t, idx): +- """Match each prior box with the ground truth box of the highest jaccard +- overlap, encode the bounding boxes, then return the matched indices +- corresponding to both confidence and location preds. +- Args: +- threshold: (float) The overlap threshold used when mathing boxes. +- truths: (tensor) Ground truth boxes, Shape: [num_obj, num_priors]. +- priors: (tensor) Prior boxes from priorbox layers, Shape: [n_priors,4]. +- variances: (tensor) Variances corresponding to each prior coord, +- Shape: [num_priors, 4]. +- labels: (tensor) All the class labels for the image, Shape: [num_obj]. +- loc_t: (tensor) Tensor to be filled w/ endcoded location targets. +- conf_t: (tensor) Tensor to be filled w/ matched indices for conf preds. +- idx: (int) current batch index +- Return: +- The matched indices corresponding to 1)location and 2)confidence preds. +- """ +- # jaccard index +- overlaps = jaccard( +- truths, +- point_form(priors) +- ) +- # (Bipartite Matching) +- # [1,num_objects] best prior for each ground truth +- best_prior_overlap, best_prior_idx = overlaps.max(1, keepdim=True) +- # [1,num_priors] best ground truth for each prior +- best_truth_overlap, best_truth_idx = overlaps.max( +- 0, keepdim=True) # 0-2000 +- best_truth_idx.squeeze_(0) +- best_truth_overlap.squeeze_(0) +- best_prior_idx.squeeze_(1) +- best_prior_overlap.squeeze_(1) +- best_truth_overlap.index_fill_(0, best_prior_idx, 2) # ensure best prior +- # TODO refactor: index best_prior_idx with long tensor +- # ensure every gt matches with its prior of max overlap +- for j in range(best_prior_idx.size(0)): +- best_truth_idx[best_prior_idx[j]] = j +- _th1, _th2, _th3 = threshold # _th1 = 0.1 ,_th2 = 0.35,_th3 = 0.5 +- +- N = (torch.sum(best_prior_overlap >= _th2) + +- torch.sum(best_prior_overlap >= _th3)) // 2 +- matches = truths[best_truth_idx] # Shape: [num_priors,4] +- conf = labels[best_truth_idx] # Shape: [num_priors] +- conf[best_truth_overlap < _th2] = 0 # label as background +- +- best_truth_overlap_clone = best_truth_overlap.clone() +- add_idx = best_truth_overlap_clone.gt( +- _th1).eq(best_truth_overlap_clone.lt(_th2)) +- best_truth_overlap_clone[1 - add_idx] = 0 +- stage2_overlap, stage2_idx = best_truth_overlap_clone.sort(descending=True) +- +- stage2_overlap = stage2_overlap.gt(_th1) +- +- if N > 0: +- N = torch.sum(stage2_overlap[:N]) if torch.sum( +- stage2_overlap[:N]) < N else N +- conf[stage2_idx[:N]] += 1 +- +- loc = encode(matches, priors, variances) +- loc_t[idx] = loc # [num_priors,4] encoded offsets to learn +- conf_t[idx] = conf # [num_priors] top class label for each prior +- +- +-def match_ssd(threshold, truths, priors, variances, labels, loc_t, conf_t, idx): +- """Match each prior box with the ground truth box of the highest jaccard +- overlap, encode the bounding boxes, then return the matched indices +- corresponding to both confidence and location preds. +- Args: +- threshold: (float) The overlap threshold used when mathing boxes. +- truths: (tensor) Ground truth boxes, Shape: [num_obj, num_priors]. +- priors: (tensor) Prior boxes from priorbox layers, Shape: [n_priors,4]. +- variances: (tensor) Variances corresponding to each prior coord, +- Shape: [num_priors, 4]. +- labels: (tensor) All the class labels for the image, Shape: [num_obj]. +- loc_t: (tensor) Tensor to be filled w/ endcoded location targets. +- conf_t: (tensor) Tensor to be filled w/ matched indices for conf preds. +- idx: (int) current batch index +- Return: +- The matched indices corresponding to 1)location and 2)confidence preds. +- """ +- # jaccard index +- overlaps = jaccard( +- truths, +- point_form(priors) +- ) +- # (Bipartite Matching) +- # [1,num_objects] best prior for each ground truth +- best_prior_overlap, best_prior_idx = overlaps.max(1, keepdim=True) +- # [1,num_priors] best ground truth for each prior +- best_truth_overlap, best_truth_idx = overlaps.max( +- 0, keepdim=True) # 0-2000 +- best_truth_idx.squeeze_(0) +- best_truth_overlap.squeeze_(0) +- best_prior_idx.squeeze_(1) +- best_prior_overlap.squeeze_(1) +- best_truth_overlap.index_fill_(0, best_prior_idx, 2) # ensure best prior +- # TODO refactor: index best_prior_idx with long tensor +- # ensure every gt matches with its prior of max overlap +- for j in range(best_prior_idx.size(0)): +- best_truth_idx[best_prior_idx[j]] = j +- matches = truths[best_truth_idx] # Shape: [num_priors,4] +- conf = labels[best_truth_idx] # Shape: [num_priors] +- conf[best_truth_overlap < threshold] = 0 # label as background +- loc = encode(matches, priors, variances) +- loc_t[idx] = loc # [num_priors,4] encoded offsets to learn +- conf_t[idx] = conf # [num_priors] top class label for each prior +- +- +-def encode(matched, priors, variances): +- """Encode the variances from the priorbox layers into the ground truth boxes +- we have matched (based on jaccard overlap) with the prior boxes. +- Args: +- matched: (tensor) Coords of ground truth for each prior in point-form +- Shape: [num_priors, 4]. +- priors: (tensor) Prior boxes in center-offset form +- Shape: [num_priors,4]. +- variances: (list[float]) Variances of priorboxes +- Return: +- encoded boxes (tensor), Shape: [num_priors, 4] +- """ +- +- # dist b/t match center and prior's center +- g_cxcy = (matched[:, :2] + matched[:, 2:]) / 2 - priors[:, :2] +- # encode variance +- g_cxcy /= (variances[0] * priors[:, 2:]) +- # match wh / prior wh +- g_wh = (matched[:, 2:] - matched[:, :2]) / priors[:, 2:] +- #g_wh = torch.log(g_wh) / variances[1] +- g_wh = torch.log(g_wh) / variances[1] +- # return target for smooth_l1_loss +- return torch.cat([g_cxcy, g_wh], 1) # [num_priors,4] +- +- +-# Adapted from https://github.com/Hakuyume/chainer-ssd +-def decode(loc, priors, variances): +- """Decode locations from predictions using priors to undo +- the encoding we did for offset regression at train time. +- Args: +- loc (tensor): location predictions for loc layers, +- Shape: [num_priors,4] +- priors (tensor): Prior boxes in center-offset form. +- Shape: [num_priors,4]. +- variances: (list[float]) Variances of priorboxes +- Return: +- decoded bounding box predictions +- """ +- +- boxes = torch.cat(( +- priors[:, :2] + loc[:, :2] * variances[0] * priors[:, 2:], +- priors[:, 2:] * torch.exp(loc[:, 2:] * variances[1])), 1) +- boxes[:, :2] -= boxes[:, 2:] / 2 +- boxes[:, 2:] += boxes[:, :2] +- return boxes +- +- +-def log_sum_exp(x): +- """Utility function for computing log_sum_exp while determining +- This will be used to determine unaveraged confidence loss across +- all examples in a batch. +- Args: +- x (Variable(tensor)): conf_preds from conf layers +- """ +- x_max = x.data.max() +- return torch.log(torch.sum(torch.exp(x - x_max), 1, keepdim=True)) + x_max +- +- +-# Original author: Francisco Massa: +-# https://github.com/fmassa/object-detection.torch +-# Ported to PyTorch by Max deGroot (02/01/2017) +-def nms(boxes, scores, overlap=0.5, top_k=200): +- """Apply non-maximum suppression at test time to avoid detecting too many +- overlapping bounding boxes for a given object. +- Args: +- boxes: (tensor) The location preds for the img, Shape: [num_priors,4]. +- scores: (tensor) The class predscores for the img, Shape:[num_priors]. +- overlap: (float) The overlap thresh for suppressing unnecessary boxes. +- top_k: (int) The Maximum number of box preds to consider. +- Return: +- The indices of the kept boxes with respect to num_priors. +- """ +- +- keep = scores.new(scores.size(0)).zero_().long() +- if boxes.numel() == 0: +- return keep +- x1 = boxes[:, 0] +- y1 = boxes[:, 1] +- x2 = boxes[:, 2] +- y2 = boxes[:, 3] +- area = torch.mul(x2 - x1, y2 - y1) +- v, idx = scores.sort(0) # sort in ascending order +- # I = I[v >= 0.01] +- idx = idx[-top_k:] # indices of the top-k largest vals +- xx1 = boxes.new() +- yy1 = boxes.new() +- xx2 = boxes.new() +- yy2 = boxes.new() +- w = boxes.new() +- h = boxes.new() +- +- # keep = torch.Tensor() +- count = 0 +- while idx.numel() > 0: +- i = idx[-1] # index of current largest val +- # keep.append(i) +- keep[count] = i +- count += 1 +- if idx.size(0) == 1: +- break +- idx = idx[:-1] # remove kept element from view +- # load bboxes of next highest vals +- torch.index_select(x1, 0, idx, out=xx1) +- torch.index_select(y1, 0, idx, out=yy1) +- torch.index_select(x2, 0, idx, out=xx2) +- torch.index_select(y2, 0, idx, out=yy2) +- # store element-wise max with next highest score +- xx1 = torch.clamp(xx1, min=x1[i]) +- yy1 = torch.clamp(yy1, min=y1[i]) +- xx2 = torch.clamp(xx2, max=x2[i]) +- yy2 = torch.clamp(yy2, max=y2[i]) +- w.resize_as_(xx2) +- h.resize_as_(yy2) +- w = xx2 - xx1 +- h = yy2 - yy1 +- # check sizes of xx1 and xx2.. after each iteration +- w = torch.clamp(w, min=0.0) +- h = torch.clamp(h, min=0.0) +- inter = w * h +- # IoU = i / (area(a) + area(b) - i) +- rem_areas = torch.index_select(area, 0, idx) # load remaining areas) +- union = (rem_areas - inter) + area[i] +- IoU = inter / union # store result in iou +- # keep only elements with an IoU <= overlap +- idx = idx[IoU.le(overlap)] +- return keep, count diff --git a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/functions/__init__.py b/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/functions/__init__.py deleted file mode 100644 index 9bc5349934..0000000000 --- a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/functions/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ --# Copyright 2021 Huawei Technologies Co., Ltd --# --# Licensed under the Apache License, Version 2.0 (the "License"); --# you may not use this file except in compliance with the License. --# You may obtain a copy of the License at --# --# http://www.apache.org/licenses/LICENSE-2.0 --# --# Unless required by applicable law or agreed to in writing, software --# distributed under the License is distributed on an "AS IS" BASIS, --# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --# See the License for the specific language governing permissions and --# limitations under the License. -- --from .prior_box import PriorBox --from .detection import Detect -- --__all__=['Detect','PriorBox'] -- +-# Copyright 2021 Huawei Technologies Co., Ltd +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +- +-from .prior_box import PriorBox +-from .detection import Detect +- +-__all__=['Detect','PriorBox'] +- diff --git a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/functions/detection.py b/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/functions/detection.py deleted file mode 100644 index 94b23f9410..0000000000 --- a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/functions/detection.py +++ /dev/null @@ -1,87 +0,0 @@ --# Copyright 2021 Huawei Technologies Co., Ltd --# --# Licensed under the Apache License, Version 2.0 (the "License"); --# you may not use this file except in compliance with the License. --# You may obtain a copy of the License at --# --# http://www.apache.org/licenses/LICENSE-2.0 --# --# Unless required by applicable law or agreed to in writing, software --# distributed under the License is distributed on an "AS IS" BASIS, --# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --# See the License for the specific language governing permissions and --# limitations under the License. -- --# coding=utf-8 -- --from __future__ import division --from __future__ import absolute_import --from __future__ import print_function -- --import torch -- --from ..bbox_utils import decode, nms --from torch.autograd import Function -- -- --class Detect(Function): -- """At test time, Detect is the final layer of SSD. Decode location preds, -- apply non-maximum suppression to location predictions based on conf -- scores and threshold to a top_k number of output predictions for both -- confidence score and locations. -- """ -- -- def __init__(self, cfg): -- self.num_classes = cfg.NUM_CLASSES -- self.top_k = cfg.TOP_K -- self.nms_thresh = cfg.NMS_THRESH -- self.conf_thresh = cfg.CONF_THRESH -- self.variance = cfg.VARIANCE -- self.nms_top_k = cfg.NMS_TOP_K -- -- def forward(self, loc_data, conf_data, prior_data): -- """ -- Args: -- loc_data: (tensor) Loc preds from loc layers -- Shape: [batch,num_priors*4] -- conf_data: (tensor) Shape: Conf preds from conf layers -- Shape: [batch*num_priors,num_classes] -- prior_data: (tensor) Prior boxes and variances from priorbox layers -- Shape: [1,num_priors,4] -- """ -- num = loc_data.size(0) -- num_priors = prior_data.size(0) -- -- conf_preds = conf_data.view( -- num, num_priors, self.num_classes).transpose(2, 1) -- batch_priors = prior_data.view(-1, num_priors, -- 4).expand(num, num_priors, 4) -- batch_priors = batch_priors.contiguous().view(-1, 4) -- -- decoded_boxes = decode(loc_data.view(-1, 4), -- batch_priors, self.variance) -- decoded_boxes = decoded_boxes.view(num, num_priors, 4) -- -- output = torch.zeros(num, self.num_classes, self.top_k, 5) -- -- for i in range(num): -- boxes = decoded_boxes[i].clone() -- conf_scores = conf_preds[i].clone() -- -- for cl in range(1, self.num_classes): -- c_mask = conf_scores[cl].gt(self.conf_thresh) -- scores = conf_scores[cl][c_mask] -- -- #VIVID -- if scores.size(0) == 0: -- continue -- l_mask = c_mask.unsqueeze(1).expand_as(boxes) -- boxes_ = boxes[l_mask].view(-1, 4) -- ids, count = nms(boxes_, scores, self.nms_thresh, self.nms_top_k) -- count = count if count < self.top_k else self.top_k -- -- output[i, cl, :count] = torch.cat((scores[ids[:count]].unsqueeze(1), -- boxes_[ids[:count]]), 1) -- print("get test detect res:", output) -- -- return output +-# Copyright 2021 Huawei Technologies Co., Ltd +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +- +-# coding=utf-8 +- +-from __future__ import division +-from __future__ import absolute_import +-from __future__ import print_function +- +-import torch +- +-from ..bbox_utils import decode, nms +-from torch.autograd import Function +- +- +-class Detect(Function): +- """At test time, Detect is the final layer of SSD. Decode location preds, +- apply non-maximum suppression to location predictions based on conf +- scores and threshold to a top_k number of output predictions for both +- confidence score and locations. +- """ +- +- def __init__(self, cfg): +- self.num_classes = cfg.NUM_CLASSES +- self.top_k = cfg.TOP_K +- self.nms_thresh = cfg.NMS_THRESH +- self.conf_thresh = cfg.CONF_THRESH +- self.variance = cfg.VARIANCE +- self.nms_top_k = cfg.NMS_TOP_K +- +- def forward(self, loc_data, conf_data, prior_data): +- """ +- Args: +- loc_data: (tensor) Loc preds from loc layers +- Shape: [batch,num_priors*4] +- conf_data: (tensor) Shape: Conf preds from conf layers +- Shape: [batch*num_priors,num_classes] +- prior_data: (tensor) Prior boxes and variances from priorbox layers +- Shape: [1,num_priors,4] +- """ +- num = loc_data.size(0) +- num_priors = prior_data.size(0) +- +- conf_preds = conf_data.view( +- num, num_priors, self.num_classes).transpose(2, 1) +- batch_priors = prior_data.view(-1, num_priors, +- 4).expand(num, num_priors, 4) +- batch_priors = batch_priors.contiguous().view(-1, 4) +- +- decoded_boxes = decode(loc_data.view(-1, 4), +- batch_priors, self.variance) +- decoded_boxes = decoded_boxes.view(num, num_priors, 4) +- +- output = torch.zeros(num, self.num_classes, self.top_k, 5) +- +- for i in range(num): +- boxes = decoded_boxes[i].clone() +- conf_scores = conf_preds[i].clone() +- +- for cl in range(1, self.num_classes): +- c_mask = conf_scores[cl].gt(self.conf_thresh) +- scores = conf_scores[cl][c_mask] +- +- #VIVID +- if scores.size(0) == 0: +- continue +- l_mask = c_mask.unsqueeze(1).expand_as(boxes) +- boxes_ = boxes[l_mask].view(-1, 4) +- ids, count = nms(boxes_, scores, self.nms_thresh, self.nms_top_k) +- count = count if count < self.top_k else self.top_k +- +- output[i, cl, :count] = torch.cat((scores[ids[:count]].unsqueeze(1), +- boxes_[ids[:count]]), 1) +- print("get test detect res:", output) +- +- return output diff --git a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/functions/prior_box.py b/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/functions/prior_box.py deleted file mode 100644 index b49b348072..0000000000 --- a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/functions/prior_box.py +++ /dev/null @@ -1,78 +0,0 @@ --# Copyright 2021 Huawei Technologies Co., Ltd --# --# Licensed under the Apache License, Version 2.0 (the "License"); --# you may not use this file except in compliance with the License. --# You may obtain a copy of the License at --# --# http://www.apache.org/licenses/LICENSE-2.0 --# --# Unless required by applicable law or agreed to in writing, software --# distributed under the License is distributed on an "AS IS" BASIS, --# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --# See the License for the specific language governing permissions and --# limitations under the License. -- --#-*- coding:utf-8 -*- -- --from __future__ import division --from __future__ import absolute_import --from __future__ import print_function -- --import torch --from itertools import product as product --import math -- -- --class PriorBox(object): -- """Compute priorbox coordinates in center-offset form for each source -- feature map. -- """ -- -- def __init__(self, input_size, feature_maps,cfg,pal=2): -- super(PriorBox, self).__init__() -- self.imh = input_size[0] -- self.imw = input_size[1] -- # number of priors for feature map location (either 4 or 6) -- self.variance = cfg.VARIANCE or [0.1] -- #self.feature_maps = cfg.FEATURE_MAPS -- if pal==1: -- self.min_sizes = cfg.ANCHOR_SIZES1 -- elif pal==2: -- self.min_sizes = cfg.ANCHOR_SIZES2 -- self.aspect_ratio = cfg.ASPECT_RATIO -- self.steps = cfg.STEPS -- self.clip = cfg.CLIP -- for v in self.variance: -- if v <= 0: -- raise ValueError('Variances must be greater than 0') -- self.feature_maps = feature_maps -- -- -- def forward(self): -- mean = [] -- for k in range(len(self.feature_maps)): -- feath = self.feature_maps[k][0] -- featw = self.feature_maps[k][1] -- for i, j in product(range(feath), range(featw)): -- f_kw = self.imw / self.steps[k] -- f_kh = self.imh / self.steps[k] -- -- cx = (j + 0.5) / f_kw -- cy = (i + 0.5) / f_kh -- -- s_kw = self.min_sizes[k] / self.imw -- s_kh = self.min_sizes[k] / self.imh -- for ar in self.aspect_ratio: -- mean += [cx, cy, s_kw/math.sqrt(ar), s_kh*math.sqrt(ar)] -- -- output = torch.Tensor(mean).view(-1, 4) -- if self.clip: -- output.clamp_(max=1, min=0) -- return output -- -- --if __name__ == '__main__': -- from data.config import cfg -- p = PriorBox([640, 640], cfg) -- out = p.forward() -- print(out.size()) +-# Copyright 2021 Huawei Technologies Co., Ltd +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +- +-#-*- coding:utf-8 -*- +- +-from __future__ import division +-from __future__ import absolute_import +-from __future__ import print_function +- +-import torch +-from itertools import product as product +-import math +- +- +-class PriorBox(object): +- """Compute priorbox coordinates in center-offset form for each source +- feature map. +- """ +- +- def __init__(self, input_size, feature_maps,cfg,pal=2): +- super(PriorBox, self).__init__() +- self.imh = input_size[0] +- self.imw = input_size[1] +- # number of priors for feature map location (either 4 or 6) +- self.variance = cfg.VARIANCE or [0.1] +- #self.feature_maps = cfg.FEATURE_MAPS +- if pal==1: +- self.min_sizes = cfg.ANCHOR_SIZES1 +- elif pal==2: +- self.min_sizes = cfg.ANCHOR_SIZES2 +- self.aspect_ratio = cfg.ASPECT_RATIO +- self.steps = cfg.STEPS +- self.clip = cfg.CLIP +- for v in self.variance: +- if v <= 0: +- raise ValueError('Variances must be greater than 0') +- self.feature_maps = feature_maps +- +- +- def forward(self): +- mean = [] +- for k in range(len(self.feature_maps)): +- feath = self.feature_maps[k][0] +- featw = self.feature_maps[k][1] +- for i, j in product(range(feath), range(featw)): +- f_kw = self.imw / self.steps[k] +- f_kh = self.imh / self.steps[k] +- +- cx = (j + 0.5) / f_kw +- cy = (i + 0.5) / f_kh +- +- s_kw = self.min_sizes[k] / self.imw +- s_kh = self.min_sizes[k] / self.imh +- for ar in self.aspect_ratio: +- mean += [cx, cy, s_kw/math.sqrt(ar), s_kh*math.sqrt(ar)] +- +- output = torch.Tensor(mean).view(-1, 4) +- if self.clip: +- output.clamp_(max=1, min=0) +- return output +- +- +-if __name__ == '__main__': +- from data.config import cfg +- p = PriorBox([640, 640], cfg) +- out = p.forward() +- print(out.size()) diff --git a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/modules/__init__.py b/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/modules/__init__.py deleted file mode 100644 index 1ee0f9eb05..0000000000 --- a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/modules/__init__.py +++ /dev/null @@ -1,26 +0,0 @@ --# Copyright 2021 Huawei Technologies Co., Ltd --# --# Licensed under the Apache License, Version 2.0 (the "License"); --# you may not use this file except in compliance with the License. --# You may obtain a copy of the License at --# --# http://www.apache.org/licenses/LICENSE-2.0 --# --# Unless required by applicable law or agreed to in writing, software --# distributed under the License is distributed on an "AS IS" BASIS, --# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --# See the License for the specific language governing permissions and --# limitations under the License. -- --#-*- coding:utf-8 -*- -- --from __future__ import division --from __future__ import absolute_import --from __future__ import print_function -- -- --from .l2norm import L2Norm --from .multibox_loss import MultiBoxLoss -- --__all__ = ['L2Norm', 'MultiBoxLoss'] -- +-# Copyright 2021 Huawei Technologies Co., Ltd +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +- +-#-*- coding:utf-8 -*- +- +-from __future__ import division +-from __future__ import absolute_import +-from __future__ import print_function +- +- +-from .l2norm import L2Norm +-from .multibox_loss import MultiBoxLoss +- +-__all__ = ['L2Norm', 'MultiBoxLoss'] +- diff --git a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/modules/l2norm.py b/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/modules/l2norm.py deleted file mode 100644 index 009890b8dd..0000000000 --- a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/modules/l2norm.py +++ /dev/null @@ -1,50 +0,0 @@ --# Copyright 2021 Huawei Technologies Co., Ltd --# --# Licensed under the Apache License, Version 2.0 (the "License"); --# you may not use this file except in compliance with the License. --# You may obtain a copy of the License at --# --# http://www.apache.org/licenses/LICENSE-2.0 --# --# Unless required by applicable law or agreed to in writing, software --# distributed under the License is distributed on an "AS IS" BASIS, --# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --# See the License for the specific language governing permissions and --# limitations under the License. -- --#-*- coding:utf-8 -*- -- --from __future__ import division --from __future__ import absolute_import --from __future__ import print_function -- -- --import torch --import torch.nn as nn --import torch.nn.init as init --from torch.autograd import Function --from torch.autograd import Variable -- -- -- --class L2Norm(nn.Module): -- def __init__(self,n_channels, scale): -- super(L2Norm,self).__init__() -- self.n_channels = n_channels -- self.gamma = scale or None -- self.eps = 1e-10 -- self.weight = nn.Parameter(torch.Tensor(self.n_channels)) -- self.reset_parameters() -- -- def reset_parameters(self): -- init.constant(self.weight,self.gamma) -- -- def forward(self, x): -- norm = x.pow(2).sum(dim=1, keepdim=True).sqrt()+self.eps -- #x /= norm -- x = torch.div(x,norm) -- out = self.weight.unsqueeze(0).unsqueeze(2).unsqueeze(3).expand_as(x) * x -- return out -- -- +-# Copyright 2021 Huawei Technologies Co., Ltd +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +- +-#-*- coding:utf-8 -*- +- +-from __future__ import division +-from __future__ import absolute_import +-from __future__ import print_function +- +- +-import torch +-import torch.nn as nn +-import torch.nn.init as init +-from torch.autograd import Function +-from torch.autograd import Variable +- +- +- +-class L2Norm(nn.Module): +- def __init__(self,n_channels, scale): +- super(L2Norm,self).__init__() +- self.n_channels = n_channels +- self.gamma = scale or None +- self.eps = 1e-10 +- self.weight = nn.Parameter(torch.Tensor(self.n_channels)) +- self.reset_parameters() +- +- def reset_parameters(self): +- init.constant(self.weight,self.gamma) +- +- def forward(self, x): +- norm = x.pow(2).sum(dim=1, keepdim=True).sqrt()+self.eps +- #x /= norm +- x = torch.div(x,norm) +- out = self.weight.unsqueeze(0).unsqueeze(2).unsqueeze(3).expand_as(x) * x +- return out +- +- - \ No newline at end of file diff --git a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/modules/multibox_loss.py b/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/modules/multibox_loss.py @@ -7433,964 +7433,964 @@ index 0f938211d3..0000000000 --- a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/layers/modules/multibox_loss.py +++ /dev/null @@ -1,134 +0,0 @@ --# Copyright 2021 Huawei Technologies Co., Ltd --# --# Licensed under the Apache License, Version 2.0 (the "License"); --# you may not use this file except in compliance with the License. --# You may obtain a copy of the License at --# --# http://www.apache.org/licenses/LICENSE-2.0 --# --# Unless required by applicable law or agreed to in writing, software --# distributed under the License is distributed on an "AS IS" BASIS, --# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --# See the License for the specific language governing permissions and --# limitations under the License. -- --#-*- coding:utf-8 -*- -- --from __future__ import division --from __future__ import absolute_import --from __future__ import print_function -- --import math --import torch --import torch.nn as nn --import torch.nn.functional as F --from torch.autograd import Variable -- -- --from ..bbox_utils import match, log_sum_exp, match_ssd -- -- --class MultiBoxLoss(nn.Module): -- """SSD Weighted Loss Function -- Compute Targets: -- 1) Produce Confidence Target Indices by matching ground truth boxes -- with (default) 'priorboxes' that have jaccard index > threshold parameter -- (default threshold: 0.5). -- 2) Produce localization target by 'encoding' variance into offsets of ground -- truth boxes and their matched 'priorboxes'. -- 3) Hard negative mining to filter the excessive number of negative examples -- that comes with using a large number of default bounding boxes. -- (default negative:positive ratio 3:1) -- Objective Loss: -- L(x,c,l,g) = (Lconf(x, c) + αLloc(x,l,g)) / N -- Where, Lconf is the CrossEntropy Loss and Lloc is the SmoothL1 Loss -- weighted by α which is set to 1 by cross val. -- Args: -- c: class confidences, -- l: predicted boxes, -- g: ground truth boxes -- N: number of matched default boxes -- See: https://arxiv.org/pdf/1512.02325.pdf for more details. -- """ -- -- def __init__(self, cfg, use_gpu=True): -- super(MultiBoxLoss, self).__init__() -- self.use_gpu = use_gpu -- self.num_classes = cfg.NUM_CLASSES -- self.negpos_ratio = cfg.NEG_POS_RATIOS -- self.variance = cfg.VARIANCE -- -- self.threshold = cfg.FACE.OVERLAP_THRESH -- self.match = match_ssd -- -- def forward(self, predictions, targets): -- """Multibox Loss -- Args: -- predictions (tuple): A tuple containing loc preds, conf preds, -- and prior boxes from SSD net. -- conf shape: torch.size(batch_size,num_priors,num_classes) -- loc shape: torch.size(batch_size,num_priors,4) -- priors shape: torch.size(num_priors,4) -- -- targets (tensor): Ground truth boxes and labels for a batch, -- shape: [batch_size,num_objs,5] (last idx is the label). -- """ -- loc_data, conf_data, priors = predictions -- num = loc_data.size(0) -- priors = priors[:loc_data.size(1), :] -- num_priors = (priors.size(0)) -- num_classes = self.num_classes -- -- # match priors (default boxes) and ground truth boxes -- loc_t = torch.Tensor(num, num_priors, 4) -- conf_t = torch.LongTensor(num, num_priors) -- for idx in range(num): -- truths = targets[idx][:, :-1].data -- labels = targets[idx][:, -1].data -- defaults = priors.data -- self.match(self.threshold, truths, defaults, self.variance, labels, -- loc_t, conf_t, idx) -- if self.use_gpu: -- loc_t = loc_t.cuda() -- conf_t = conf_t.cuda() -- # wrap targets -- loc_t = Variable(loc_t, requires_grad=False) -- conf_t = Variable(conf_t, requires_grad=False) -- -- pos = conf_t > 0 -- num_pos = pos.sum(dim=1, keepdim=True) -- # Localization Loss (Smooth L1) -- # Shape: [batch,num_priors,4] -- pos_idx = pos.unsqueeze(pos.dim()).expand_as(loc_data) -- loc_p = loc_data[pos_idx].view(-1, 4) -- loc_t = loc_t[pos_idx].view(-1, 4) -- loss_l = F.smooth_l1_loss(loc_p, loc_t, size_average=False) -- # print(loc_p) -- # Compute max conf across batch for hard negative mining -- batch_conf = conf_data.view(-1, self.num_classes) -- loss_c = log_sum_exp(batch_conf) - \ -- batch_conf.gather(1, conf_t.view(-1, 1)) -- -- # Hard Negative Mining -- loss_c[pos.view(-1, 1)] = 0 # filter out pos boxes for now -- loss_c = loss_c.view(num, -1) -- _, loss_idx = loss_c.sort(1, descending=True) -- _, idx_rank = loss_idx.sort(1) -- num_pos = pos.long().sum(1, keepdim=True) -- num_neg = torch.clamp(self.negpos_ratio * -- num_pos, max=pos.size(1) - 1) -- neg = idx_rank < num_neg.expand_as(idx_rank) -- -- # Confidence Loss Including Positive and Negative Examples -- pos_idx = pos.unsqueeze(2).expand_as(conf_data) -- neg_idx = neg.unsqueeze(2).expand_as(conf_data) -- conf_p = conf_data[(pos_idx + neg_idx).gt(0) -- ].view(-1, self.num_classes) -- targets_weighted = conf_t[(pos + neg).gt(0)] -- loss_c = F.cross_entropy(conf_p, targets_weighted, size_average=False) -- -- # Sum of losses: L(x,c,l,g) = (Lconf(x, c) + αLloc(x,l,g)) / N -- N = num_pos.data.sum() if num_pos.data.sum() > 0 else num -- loss_l /= N -- loss_c /= N -- return loss_l, loss_c +-# Copyright 2021 Huawei Technologies Co., Ltd +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +- +-#-*- coding:utf-8 -*- +- +-from __future__ import division +-from __future__ import absolute_import +-from __future__ import print_function +- +-import math +-import torch +-import torch.nn as nn +-import torch.nn.functional as F +-from torch.autograd import Variable +- +- +-from ..bbox_utils import match, log_sum_exp, match_ssd +- +- +-class MultiBoxLoss(nn.Module): +- """SSD Weighted Loss Function +- Compute Targets: +- 1) Produce Confidence Target Indices by matching ground truth boxes +- with (default) 'priorboxes' that have jaccard index > threshold parameter +- (default threshold: 0.5). +- 2) Produce localization target by 'encoding' variance into offsets of ground +- truth boxes and their matched 'priorboxes'. +- 3) Hard negative mining to filter the excessive number of negative examples +- that comes with using a large number of default bounding boxes. +- (default negative:positive ratio 3:1) +- Objective Loss: +- L(x,c,l,g) = (Lconf(x, c) + αLloc(x,l,g)) / N +- Where, Lconf is the CrossEntropy Loss and Lloc is the SmoothL1 Loss +- weighted by α which is set to 1 by cross val. +- Args: +- c: class confidences, +- l: predicted boxes, +- g: ground truth boxes +- N: number of matched default boxes +- See: https://arxiv.org/pdf/1512.02325.pdf for more details. +- """ +- +- def __init__(self, cfg, use_gpu=True): +- super(MultiBoxLoss, self).__init__() +- self.use_gpu = use_gpu +- self.num_classes = cfg.NUM_CLASSES +- self.negpos_ratio = cfg.NEG_POS_RATIOS +- self.variance = cfg.VARIANCE +- +- self.threshold = cfg.FACE.OVERLAP_THRESH +- self.match = match_ssd +- +- def forward(self, predictions, targets): +- """Multibox Loss +- Args: +- predictions (tuple): A tuple containing loc preds, conf preds, +- and prior boxes from SSD net. +- conf shape: torch.size(batch_size,num_priors,num_classes) +- loc shape: torch.size(batch_size,num_priors,4) +- priors shape: torch.size(num_priors,4) +- +- targets (tensor): Ground truth boxes and labels for a batch, +- shape: [batch_size,num_objs,5] (last idx is the label). +- """ +- loc_data, conf_data, priors = predictions +- num = loc_data.size(0) +- priors = priors[:loc_data.size(1), :] +- num_priors = (priors.size(0)) +- num_classes = self.num_classes +- +- # match priors (default boxes) and ground truth boxes +- loc_t = torch.Tensor(num, num_priors, 4) +- conf_t = torch.LongTensor(num, num_priors) +- for idx in range(num): +- truths = targets[idx][:, :-1].data +- labels = targets[idx][:, -1].data +- defaults = priors.data +- self.match(self.threshold, truths, defaults, self.variance, labels, +- loc_t, conf_t, idx) +- if self.use_gpu: +- loc_t = loc_t.cuda() +- conf_t = conf_t.cuda() +- # wrap targets +- loc_t = Variable(loc_t, requires_grad=False) +- conf_t = Variable(conf_t, requires_grad=False) +- +- pos = conf_t > 0 +- num_pos = pos.sum(dim=1, keepdim=True) +- # Localization Loss (Smooth L1) +- # Shape: [batch,num_priors,4] +- pos_idx = pos.unsqueeze(pos.dim()).expand_as(loc_data) +- loc_p = loc_data[pos_idx].view(-1, 4) +- loc_t = loc_t[pos_idx].view(-1, 4) +- loss_l = F.smooth_l1_loss(loc_p, loc_t, size_average=False) +- # print(loc_p) +- # Compute max conf across batch for hard negative mining +- batch_conf = conf_data.view(-1, self.num_classes) +- loss_c = log_sum_exp(batch_conf) - \ +- batch_conf.gather(1, conf_t.view(-1, 1)) +- +- # Hard Negative Mining +- loss_c[pos.view(-1, 1)] = 0 # filter out pos boxes for now +- loss_c = loss_c.view(num, -1) +- _, loss_idx = loss_c.sort(1, descending=True) +- _, idx_rank = loss_idx.sort(1) +- num_pos = pos.long().sum(1, keepdim=True) +- num_neg = torch.clamp(self.negpos_ratio * +- num_pos, max=pos.size(1) - 1) +- neg = idx_rank < num_neg.expand_as(idx_rank) +- +- # Confidence Loss Including Positive and Negative Examples +- pos_idx = pos.unsqueeze(2).expand_as(conf_data) +- neg_idx = neg.unsqueeze(2).expand_as(conf_data) +- conf_p = conf_data[(pos_idx + neg_idx).gt(0) +- ].view(-1, self.num_classes) +- targets_weighted = conf_t[(pos + neg).gt(0)] +- loss_c = F.cross_entropy(conf_p, targets_weighted, size_average=False) +- +- # Sum of losses: L(x,c,l,g) = (Lconf(x, c) + αLloc(x,l,g)) / N +- N = num_pos.data.sum() if num_pos.data.sum() > 0 else num +- loss_l /= N +- loss_c /= N +- return loss_l, loss_c diff --git a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/models/DSFD_resnet.py b/contrib/ACL_PyTorch/Research/cv/detection/DSFD/models/DSFD_resnet.py deleted file mode 100644 index 22e005a5c2..0000000000 --- a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/models/DSFD_resnet.py +++ /dev/null @@ -1,438 +0,0 @@ --# Copyright 2021 Huawei Technologies Co., Ltd --# --# Licensed under the Apache License, Version 2.0 (the "License"); --# you may not use this file except in compliance with the License. --# You may obtain a copy of the License at --# --# http://www.apache.org/licenses/LICENSE-2.0 --# --# Unless required by applicable law or agreed to in writing, software --# distributed under the License is distributed on an "AS IS" BASIS, --# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --# See the License for the specific language governing permissions and --# limitations under the License. -- --#coding=utf-8 --from __future__ import division --from __future__ import print_function --from __future__ import absolute_import -- --import torch --import torch.nn as nn --import torch.nn.functional as F --import torch.nn.init as init -- --from torch.autograd import Variable -- --from layers import * --from data.config import cur_config as cfg -- --def conv3x3(in_planes, out_planes, stride=1, bias=False): -- """3x3 convolution with padding""" -- return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, -- padding=1, bias=bias) -- -- --def conv1x1(in_planes, out_planes, stride=1): -- """1x1 convolution""" -- return nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride, bias=False) -- -- --class BasicBlock(nn.Module): -- expansion = 1 -- -- def __init__(self, inplanes, planes, stride=1, downsample=None): -- super(BasicBlock, self).__init__() -- self.conv1 = conv3x3(inplanes, planes, stride) -- self.bn1 = nn.BatchNorm2d(planes) -- self.relu = nn.ReLU(inplace=True) -- self.conv2 = conv3x3(planes, planes) -- self.bn2 = nn.BatchNorm2d(planes) -- self.downsample = downsample -- self.stride = stride -- -- def forward(self, x): -- residual = x -- -- out = self.conv1(x) -- out = self.bn1(out) -- out = self.relu(out) -- -- out = self.conv2(out) -- out = self.bn2(out) -- -- if self.downsample is not None: -- residual = self.downsample(x) -- -- out += residual -- out = self.relu(out) -- -- return out -- -- --class Bottleneck(nn.Module): -- expansion = 4 -- -- def __init__(self, inplanes, planes, stride=1, downsample=None): -- super(Bottleneck, self).__init__() -- self.conv1 = conv1x1(inplanes, planes) -- self.bn1 = nn.BatchNorm2d(planes) -- self.conv2 = conv3x3(planes, planes, stride) -- self.bn2 = nn.BatchNorm2d(planes) -- self.conv3 = conv1x1(planes, planes * self.expansion) -- self.bn3 = nn.BatchNorm2d(planes * self.expansion) -- self.relu = nn.ReLU(inplace=True) -- self.downsample = downsample -- self.stride = stride -- -- def forward(self, x): -- residual = x -- -- out = self.conv1(x) -- out = self.bn1(out) -- out = self.relu(out) -- -- out = self.conv2(out) -- out = self.bn2(out) -- out = self.relu(out) -- -- out = self.conv3(out) -- out = self.bn3(out) -- -- if self.downsample is not None: -- residual = self.downsample(x) -- -- out += residual -- out = self.relu(out) -- -- return out -- -- --class ResNet(nn.Module): -- -- def __init__(self, block, layers): -- super(ResNet, self).__init__() -- self.inplanes = 64 -- self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, -- bias=False) -- self.bn1 = nn.BatchNorm2d(64) -- self.relu = nn.ReLU(inplace=True) -- self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) -- self.layer1 = self._make_layer(block, 64, layers[0]) -- self.layer2 = self._make_layer(block, 128, layers[1], stride=2) -- self.layer3 = self._make_layer(block, 256, layers[2], stride=2) -- self.layer4 = self._make_layer(block, 512, layers[3], stride=2) -- -- def _make_layer(self, block, planes, blocks, stride=1): -- downsample = None -- if stride != 1 or self.inplanes != planes * block.expansion: -- downsample = nn.Sequential( -- conv1x1(self.inplanes, planes * block.expansion, stride), -- nn.BatchNorm2d(planes * block.expansion), -- ) -- -- layers = [] -- layers.append(block(self.inplanes, planes, stride, downsample)) -- self.inplanes = planes * block.expansion -- for _ in range(1, blocks): -- layers.append(block(self.inplanes, planes)) -- -- return nn.Sequential(*layers) -- -- def forward(self, x): -- sources = [] -- -- x = self.conv1(x) -- x = self.bn1(x) -- x = self.relu(x) -- x = self.maxpool(x) -- -- x = self.layer1(x) -- sources += [x] -- -- x = self.layer2(x) -- sources += [x] -- -- x = self.layer3(x) -- sources += [x] -- -- x = self.layer4(x) -- sources += [x] -- -- return sources -- -- --class FEM(nn.Module): -- """docstring for FEM""" -- -- def __init__(self, in_planes): -- super(FEM, self).__init__() -- inter_planes = in_planes // 3 -- inter_planes1 = in_planes - 2 * inter_planes -- self.branch1 = nn.Conv2d( -- in_planes, inter_planes, kernel_size=3, stride=1, padding=3, dilation=3) -- -- self.branch2 = nn.Sequential( -- nn.Conv2d(in_planes, inter_planes, kernel_size=3, -- stride=1, padding=3, dilation=3), -- nn.ReLU(inplace=True), -- nn.Conv2d(inter_planes, inter_planes, kernel_size=3, -- stride=1, padding=3, dilation=3) -- ) -- self.branch3 = nn.Sequential( -- nn.Conv2d(in_planes, inter_planes1, kernel_size=3, -- stride=1, padding=3, dilation=3), -- nn.ReLU(inplace=True), -- nn.Conv2d(inter_planes1, inter_planes1, kernel_size=3, -- stride=1, padding=3, dilation=3), -- nn.ReLU(inplace=True), -- nn.Conv2d(inter_planes1, inter_planes1, kernel_size=3, -- stride=1, padding=3, dilation=3) -- ) -- -- def forward(self, x): -- x1 = self.branch1(x) -- x2 = self.branch2(x) -- x3 = self.branch3(x) -- out = torch.cat((x1, x2, x3), dim=1) -- out = F.relu(out, inplace=True) -- return out -- -- --class DSFD(nn.Module): -- """docstring for SRN""" -- -- def __init__(self, phase, base, extras, fem_modules, head1, head2, num_classes=2): -- super(DSFD, self).__init__() -- self.resnet = base -- self.phase = phase -- self.num_classes = num_classes -- self.extras = nn.ModuleList(extras) -- -- self.fpn_topdown = nn.ModuleList(fem_modules[0]) -- self.fpn_latlayer = nn.ModuleList(fem_modules[1]) -- self.fpn_fem = nn.ModuleList(fem_modules[2]) -- -- self.loc_pal1 = nn.ModuleList(head1[0]) -- self.conf_pal1 = nn.ModuleList(head1[1]) -- self.loc_pal2 = nn.ModuleList(head2[0]) -- self.conf_pal2 = nn.ModuleList(head2[1]) -- -- if self.phase == 'test': -- self.softmax = nn.Softmax(dim=-1) -- self.detect = Detect(cfg) -- -- def _upsample_prod(self, x, y): -- _, _, H, W = y.size() -- return F.upsample(x, size=(H, W), mode='bilinear') * y -- -- def forward(self, x): -- size = x.size()[2:] -- of1, of2, of3, of4 = self.resnet(x) -- -- x = of4 -- for i in range(2): -- x = F.relu(self.extras[i](x), inplace=True) -- of5 = x -- -- for i in range(2, len(self.extras)): -- x = F.relu(self.extras[i](x), inplace=True) -- of6 = x -- -- conv7 = F.relu(self.fpn_topdown[0](of6), inplace=True) -- -- x = F.relu(self.fpn_topdown[1](conv7), inplace=True) -- conv6 = F.relu(self._upsample_prod( -- x, self.fpn_latlayer[0](of5)), inplace=True) -- -- x = F.relu(self.fpn_topdown[2](conv6), inplace=True) -- conv5 = F.relu(self._upsample_prod( -- x, self.fpn_latlayer[1](of4)), inplace=True) -- -- x = F.relu(self.fpn_topdown[3](conv5), inplace=True) -- conv4 = F.relu(self._upsample_prod( -- x, self.fpn_latlayer[2](of3)), inplace=True) -- -- x = F.relu(self.fpn_topdown[4](conv4), inplace=True) -- conv3 = F.relu(self._upsample_prod( -- x, self.fpn_latlayer[3](of2)), inplace=True) -- -- x = F.relu(self.fpn_topdown[5](conv3), inplace=True) -- conv2 = F.relu(self._upsample_prod( -- x, self.fpn_latlayer[4](of1)), inplace=True) -- -- ef1 = self.fpn_fem[0](conv2) -- ef2 = self.fpn_fem[1](conv3) -- ef3 = self.fpn_fem[2](conv4) -- ef4 = self.fpn_fem[3](conv5) -- ef5 = self.fpn_fem[4](conv6) -- ef6 = self.fpn_fem[5](conv7) -- -- sources_pal1 = [of1, of2, of3, of4, of5, of6] -- sources_pal2 = [ef1, ef2, ef3, ef4, ef5, ef6] -- loc_pal1, conf_pal1 = list(), list() -- loc_pal2, conf_pal2 = list(), list() -- -- for (x, l, c) in zip(sources_pal1, self.loc_pal1, self.conf_pal1): -- loc_pal1.append(l(x).permute(0, 2, 3, 1).contiguous()) -- conf_pal1.append(c(x).permute(0, 2, 3, 1).contiguous()) -- -- for (x, l, c) in zip(sources_pal2, self.loc_pal2, self.conf_pal2): -- loc_pal2.append(l(x).permute(0, 2, 3, 1).contiguous()) -- conf_pal2.append(c(x).permute(0, 2, 3, 1).contiguous()) -- -- features_maps = [] -- for i in range(len(loc_pal1)): -- feat = [] -- feat += [loc_pal1[i].size(1), loc_pal1[i].size(2)] -- features_maps += [feat] -- -- loc_pal1 = torch.cat([o.view(o.size(0), -1) for o in loc_pal1], 1) -- conf_pal1 = torch.cat([o.view(o.size(0), -1) for o in conf_pal1], 1) -- -- loc_pal2 = torch.cat([o.view(o.size(0), -1) for o in loc_pal2], 1) -- conf_pal2 = torch.cat([o.view(o.size(0), -1) for o in conf_pal2], 1) -- -- priorbox = PriorBox(size, features_maps, cfg, pal=1) -- self.priors_pal1 = Variable(priorbox.forward(), volatile=True) -- -- priorbox = PriorBox(size, features_maps, cfg, pal=2) -- self.priors_pal2 = Variable(priorbox.forward(), volatile=True) -- -- if self.phase == 'test': -- output = self.detect( -- loc_pal2.view(loc_pal2.size(0), -1, 4), -- self.softmax(conf_pal2.view(conf_pal2.size(0), -1, -- self.num_classes)), # conf preds -- self.priors_pal2.type(type(x.data)) -- ) -- -- else: -- output = ( -- loc_pal1.view(loc_pal1.size(0), -1, 4), -- conf_pal1.view(conf_pal1.size(0), -1, self.num_classes), -- self.priors_pal1, -- loc_pal2.view(loc_pal2.size(0), -1, 4), -- conf_pal2.view(conf_pal2.size(0), -1, self.num_classes), -- self.priors_pal2) -- return output -- -- def load_weights(self, base_file): -- other, ext = os.path.splitext(base_file) -- if ext == '.pkl' or '.pth': -- print('Loading weights into state dict...') -- mdata = torch.load(base_file, -- map_location=lambda storage, loc: storage) -- weights = mdata['weight'] -- epoch = mdata['epoch'] -- self.load_state_dict(weights) -- print('Finished!') -- else: -- print('Sorry only .pth and .pkl files supported.') -- return epoch -- -- def xavier(self, param): -- init.xavier_uniform(param) -- -- def weights_init(self, m): -- if isinstance(m, nn.Conv2d): -- self.xavier(m.weight.data) -- m.bias.data.zero_() -- -- if isinstance(m, nn.ConvTranspose2d): -- self.xavier(m.weight.data) -- if 'bias' in m.state_dict().keys(): -- m.bias.data.zero_() -- -- if isinstance(m, nn.BatchNorm2d): -- m.weight.data[...] = 1 -- m.bias.data.zero_() -- --extras_cfg = [256, 'S', 512, 128, 'S', 256] -- --net_cfg = [256, 512, 1024, 2048, 512, 256] -- -- --def add_extras(cfg, i): -- layers = [] -- in_channels = i -- flag = False -- for k, v in enumerate(cfg): -- if in_channels != 'S': -- if v == 'S': -- layers += [nn.Conv2d(in_channels, cfg[k + 1], -- kernel_size=(1, 3)[flag], stride=2, padding=1)] -- else: -- layers += [nn.Conv2d(in_channels, v, kernel_size=(1, 3)[flag])] -- flag = not flag -- in_channels = v -- return layers -- -- --def multibox(cfg, num_classes=2): -- conf_layers = [] -- loc_layers = [] -- for k, v in enumerate(cfg): -- loc_layers += [nn.Conv2d(v, 4, kernel_size=3, padding=1)] -- conf_layers += [nn.Conv2d(v, num_classes, kernel_size=3, padding=1)] -- return (loc_layers, conf_layers) -- -- --def fem_module(cfg): -- topdown_layers = [] -- lat_layers = [] -- fem_layers = [] -- -- topdown_layers += [nn.Conv2d(cfg[-1], cfg[-1], -- kernel_size=1, stride=1, padding=0)] -- for k, v in enumerate(cfg): -- fem_layers += [FEM(v)] -- cur_channel = cfg[len(cfg) - 1 - k] -- if len(cfg) - 1 - k > 0: -- last_channel = cfg[len(cfg) - 2 - k] -- topdown_layers += [nn.Conv2d(cur_channel, last_channel, -- kernel_size=1, stride=1, padding=0)] -- lat_layers += [nn.Conv2d(last_channel, last_channel, -- kernel_size=1, stride=1, padding=0)] -- return (topdown_layers, lat_layers, fem_layers) -- -- --def resnet50(): -- """Constructs a ResNet-50 model. -- Args: -- pretrained (bool): If True, returns a model pre-trained on ImageNet -- """ -- model = ResNet(Bottleneck, [3, 4, 6, 3]) -- return model -- -- --def resnet101(): -- model = ResNet(Bottleneck, [3, 4, 23, 3]) -- return model -- -- --def resnet152(): -- model = ResNet(Bottleneck, [3, 8, 36, 3]) -- return model -- -- --def model_map(net_name='resnet50'): -- _dicts = {'resnet50': resnet50, -- 'resnet101': resnet101, 'resnet152': resnet152} -- return _dicts[net_name]() -- -- --def build_net_resnet(phase, num_classes=2, net_name='resnet50'): -- resnet = model_map(net_name) -- extras = add_extras(extras_cfg, 2048) -- head_pal1 = multibox(net_cfg, num_classes) -- head_pal2 = multibox(net_cfg, num_classes) -- fem_modules = fem_module(net_cfg) -- model = DSFD(phase, resnet, extras, fem_modules, -- head_pal1, head_pal2, num_classes) -- return model -- --if __name__ == '__main__': -- inputs = Variable(torch.randn(1, 3, 640, 640)) -- net = build_net('train', 2, 101) -- out = net(inputs) +-# Copyright 2021 Huawei Technologies Co., Ltd +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +- +-#coding=utf-8 +-from __future__ import division +-from __future__ import print_function +-from __future__ import absolute_import +- +-import torch +-import torch.nn as nn +-import torch.nn.functional as F +-import torch.nn.init as init +- +-from torch.autograd import Variable +- +-from layers import * +-from data.config import cur_config as cfg +- +-def conv3x3(in_planes, out_planes, stride=1, bias=False): +- """3x3 convolution with padding""" +- return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, +- padding=1, bias=bias) +- +- +-def conv1x1(in_planes, out_planes, stride=1): +- """1x1 convolution""" +- return nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride, bias=False) +- +- +-class BasicBlock(nn.Module): +- expansion = 1 +- +- def __init__(self, inplanes, planes, stride=1, downsample=None): +- super(BasicBlock, self).__init__() +- self.conv1 = conv3x3(inplanes, planes, stride) +- self.bn1 = nn.BatchNorm2d(planes) +- self.relu = nn.ReLU(inplace=True) +- self.conv2 = conv3x3(planes, planes) +- self.bn2 = nn.BatchNorm2d(planes) +- self.downsample = downsample +- self.stride = stride +- +- def forward(self, x): +- residual = x +- +- out = self.conv1(x) +- out = self.bn1(out) +- out = self.relu(out) +- +- out = self.conv2(out) +- out = self.bn2(out) +- +- if self.downsample is not None: +- residual = self.downsample(x) +- +- out += residual +- out = self.relu(out) +- +- return out +- +- +-class Bottleneck(nn.Module): +- expansion = 4 +- +- def __init__(self, inplanes, planes, stride=1, downsample=None): +- super(Bottleneck, self).__init__() +- self.conv1 = conv1x1(inplanes, planes) +- self.bn1 = nn.BatchNorm2d(planes) +- self.conv2 = conv3x3(planes, planes, stride) +- self.bn2 = nn.BatchNorm2d(planes) +- self.conv3 = conv1x1(planes, planes * self.expansion) +- self.bn3 = nn.BatchNorm2d(planes * self.expansion) +- self.relu = nn.ReLU(inplace=True) +- self.downsample = downsample +- self.stride = stride +- +- def forward(self, x): +- residual = x +- +- out = self.conv1(x) +- out = self.bn1(out) +- out = self.relu(out) +- +- out = self.conv2(out) +- out = self.bn2(out) +- out = self.relu(out) +- +- out = self.conv3(out) +- out = self.bn3(out) +- +- if self.downsample is not None: +- residual = self.downsample(x) +- +- out += residual +- out = self.relu(out) +- +- return out +- +- +-class ResNet(nn.Module): +- +- def __init__(self, block, layers): +- super(ResNet, self).__init__() +- self.inplanes = 64 +- self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, +- bias=False) +- self.bn1 = nn.BatchNorm2d(64) +- self.relu = nn.ReLU(inplace=True) +- self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) +- self.layer1 = self._make_layer(block, 64, layers[0]) +- self.layer2 = self._make_layer(block, 128, layers[1], stride=2) +- self.layer3 = self._make_layer(block, 256, layers[2], stride=2) +- self.layer4 = self._make_layer(block, 512, layers[3], stride=2) +- +- def _make_layer(self, block, planes, blocks, stride=1): +- downsample = None +- if stride != 1 or self.inplanes != planes * block.expansion: +- downsample = nn.Sequential( +- conv1x1(self.inplanes, planes * block.expansion, stride), +- nn.BatchNorm2d(planes * block.expansion), +- ) +- +- layers = [] +- layers.append(block(self.inplanes, planes, stride, downsample)) +- self.inplanes = planes * block.expansion +- for _ in range(1, blocks): +- layers.append(block(self.inplanes, planes)) +- +- return nn.Sequential(*layers) +- +- def forward(self, x): +- sources = [] +- +- x = self.conv1(x) +- x = self.bn1(x) +- x = self.relu(x) +- x = self.maxpool(x) +- +- x = self.layer1(x) +- sources += [x] +- +- x = self.layer2(x) +- sources += [x] +- +- x = self.layer3(x) +- sources += [x] +- +- x = self.layer4(x) +- sources += [x] +- +- return sources +- +- +-class FEM(nn.Module): +- """docstring for FEM""" +- +- def __init__(self, in_planes): +- super(FEM, self).__init__() +- inter_planes = in_planes // 3 +- inter_planes1 = in_planes - 2 * inter_planes +- self.branch1 = nn.Conv2d( +- in_planes, inter_planes, kernel_size=3, stride=1, padding=3, dilation=3) +- +- self.branch2 = nn.Sequential( +- nn.Conv2d(in_planes, inter_planes, kernel_size=3, +- stride=1, padding=3, dilation=3), +- nn.ReLU(inplace=True), +- nn.Conv2d(inter_planes, inter_planes, kernel_size=3, +- stride=1, padding=3, dilation=3) +- ) +- self.branch3 = nn.Sequential( +- nn.Conv2d(in_planes, inter_planes1, kernel_size=3, +- stride=1, padding=3, dilation=3), +- nn.ReLU(inplace=True), +- nn.Conv2d(inter_planes1, inter_planes1, kernel_size=3, +- stride=1, padding=3, dilation=3), +- nn.ReLU(inplace=True), +- nn.Conv2d(inter_planes1, inter_planes1, kernel_size=3, +- stride=1, padding=3, dilation=3) +- ) +- +- def forward(self, x): +- x1 = self.branch1(x) +- x2 = self.branch2(x) +- x3 = self.branch3(x) +- out = torch.cat((x1, x2, x3), dim=1) +- out = F.relu(out, inplace=True) +- return out +- +- +-class DSFD(nn.Module): +- """docstring for SRN""" +- +- def __init__(self, phase, base, extras, fem_modules, head1, head2, num_classes=2): +- super(DSFD, self).__init__() +- self.resnet = base +- self.phase = phase +- self.num_classes = num_classes +- self.extras = nn.ModuleList(extras) +- +- self.fpn_topdown = nn.ModuleList(fem_modules[0]) +- self.fpn_latlayer = nn.ModuleList(fem_modules[1]) +- self.fpn_fem = nn.ModuleList(fem_modules[2]) +- +- self.loc_pal1 = nn.ModuleList(head1[0]) +- self.conf_pal1 = nn.ModuleList(head1[1]) +- self.loc_pal2 = nn.ModuleList(head2[0]) +- self.conf_pal2 = nn.ModuleList(head2[1]) +- +- if self.phase == 'test': +- self.softmax = nn.Softmax(dim=-1) +- self.detect = Detect(cfg) +- +- def _upsample_prod(self, x, y): +- _, _, H, W = y.size() +- return F.upsample(x, size=(H, W), mode='bilinear') * y +- +- def forward(self, x): +- size = x.size()[2:] +- of1, of2, of3, of4 = self.resnet(x) +- +- x = of4 +- for i in range(2): +- x = F.relu(self.extras[i](x), inplace=True) +- of5 = x +- +- for i in range(2, len(self.extras)): +- x = F.relu(self.extras[i](x), inplace=True) +- of6 = x +- +- conv7 = F.relu(self.fpn_topdown[0](of6), inplace=True) +- +- x = F.relu(self.fpn_topdown[1](conv7), inplace=True) +- conv6 = F.relu(self._upsample_prod( +- x, self.fpn_latlayer[0](of5)), inplace=True) +- +- x = F.relu(self.fpn_topdown[2](conv6), inplace=True) +- conv5 = F.relu(self._upsample_prod( +- x, self.fpn_latlayer[1](of4)), inplace=True) +- +- x = F.relu(self.fpn_topdown[3](conv5), inplace=True) +- conv4 = F.relu(self._upsample_prod( +- x, self.fpn_latlayer[2](of3)), inplace=True) +- +- x = F.relu(self.fpn_topdown[4](conv4), inplace=True) +- conv3 = F.relu(self._upsample_prod( +- x, self.fpn_latlayer[3](of2)), inplace=True) +- +- x = F.relu(self.fpn_topdown[5](conv3), inplace=True) +- conv2 = F.relu(self._upsample_prod( +- x, self.fpn_latlayer[4](of1)), inplace=True) +- +- ef1 = self.fpn_fem[0](conv2) +- ef2 = self.fpn_fem[1](conv3) +- ef3 = self.fpn_fem[2](conv4) +- ef4 = self.fpn_fem[3](conv5) +- ef5 = self.fpn_fem[4](conv6) +- ef6 = self.fpn_fem[5](conv7) +- +- sources_pal1 = [of1, of2, of3, of4, of5, of6] +- sources_pal2 = [ef1, ef2, ef3, ef4, ef5, ef6] +- loc_pal1, conf_pal1 = list(), list() +- loc_pal2, conf_pal2 = list(), list() +- +- for (x, l, c) in zip(sources_pal1, self.loc_pal1, self.conf_pal1): +- loc_pal1.append(l(x).permute(0, 2, 3, 1).contiguous()) +- conf_pal1.append(c(x).permute(0, 2, 3, 1).contiguous()) +- +- for (x, l, c) in zip(sources_pal2, self.loc_pal2, self.conf_pal2): +- loc_pal2.append(l(x).permute(0, 2, 3, 1).contiguous()) +- conf_pal2.append(c(x).permute(0, 2, 3, 1).contiguous()) +- +- features_maps = [] +- for i in range(len(loc_pal1)): +- feat = [] +- feat += [loc_pal1[i].size(1), loc_pal1[i].size(2)] +- features_maps += [feat] +- +- loc_pal1 = torch.cat([o.view(o.size(0), -1) for o in loc_pal1], 1) +- conf_pal1 = torch.cat([o.view(o.size(0), -1) for o in conf_pal1], 1) +- +- loc_pal2 = torch.cat([o.view(o.size(0), -1) for o in loc_pal2], 1) +- conf_pal2 = torch.cat([o.view(o.size(0), -1) for o in conf_pal2], 1) +- +- priorbox = PriorBox(size, features_maps, cfg, pal=1) +- self.priors_pal1 = Variable(priorbox.forward(), volatile=True) +- +- priorbox = PriorBox(size, features_maps, cfg, pal=2) +- self.priors_pal2 = Variable(priorbox.forward(), volatile=True) +- +- if self.phase == 'test': +- output = self.detect( +- loc_pal2.view(loc_pal2.size(0), -1, 4), +- self.softmax(conf_pal2.view(conf_pal2.size(0), -1, +- self.num_classes)), # conf preds +- self.priors_pal2.type(type(x.data)) +- ) +- +- else: +- output = ( +- loc_pal1.view(loc_pal1.size(0), -1, 4), +- conf_pal1.view(conf_pal1.size(0), -1, self.num_classes), +- self.priors_pal1, +- loc_pal2.view(loc_pal2.size(0), -1, 4), +- conf_pal2.view(conf_pal2.size(0), -1, self.num_classes), +- self.priors_pal2) +- return output +- +- def load_weights(self, base_file): +- other, ext = os.path.splitext(base_file) +- if ext == '.pkl' or '.pth': +- print('Loading weights into state dict...') +- mdata = torch.load(base_file, +- map_location=lambda storage, loc: storage) +- weights = mdata['weight'] +- epoch = mdata['epoch'] +- self.load_state_dict(weights) +- print('Finished!') +- else: +- print('Sorry only .pth and .pkl files supported.') +- return epoch +- +- def xavier(self, param): +- init.xavier_uniform(param) +- +- def weights_init(self, m): +- if isinstance(m, nn.Conv2d): +- self.xavier(m.weight.data) +- m.bias.data.zero_() +- +- if isinstance(m, nn.ConvTranspose2d): +- self.xavier(m.weight.data) +- if 'bias' in m.state_dict().keys(): +- m.bias.data.zero_() +- +- if isinstance(m, nn.BatchNorm2d): +- m.weight.data[...] = 1 +- m.bias.data.zero_() +- +-extras_cfg = [256, 'S', 512, 128, 'S', 256] +- +-net_cfg = [256, 512, 1024, 2048, 512, 256] +- +- +-def add_extras(cfg, i): +- layers = [] +- in_channels = i +- flag = False +- for k, v in enumerate(cfg): +- if in_channels != 'S': +- if v == 'S': +- layers += [nn.Conv2d(in_channels, cfg[k + 1], +- kernel_size=(1, 3)[flag], stride=2, padding=1)] +- else: +- layers += [nn.Conv2d(in_channels, v, kernel_size=(1, 3)[flag])] +- flag = not flag +- in_channels = v +- return layers +- +- +-def multibox(cfg, num_classes=2): +- conf_layers = [] +- loc_layers = [] +- for k, v in enumerate(cfg): +- loc_layers += [nn.Conv2d(v, 4, kernel_size=3, padding=1)] +- conf_layers += [nn.Conv2d(v, num_classes, kernel_size=3, padding=1)] +- return (loc_layers, conf_layers) +- +- +-def fem_module(cfg): +- topdown_layers = [] +- lat_layers = [] +- fem_layers = [] +- +- topdown_layers += [nn.Conv2d(cfg[-1], cfg[-1], +- kernel_size=1, stride=1, padding=0)] +- for k, v in enumerate(cfg): +- fem_layers += [FEM(v)] +- cur_channel = cfg[len(cfg) - 1 - k] +- if len(cfg) - 1 - k > 0: +- last_channel = cfg[len(cfg) - 2 - k] +- topdown_layers += [nn.Conv2d(cur_channel, last_channel, +- kernel_size=1, stride=1, padding=0)] +- lat_layers += [nn.Conv2d(last_channel, last_channel, +- kernel_size=1, stride=1, padding=0)] +- return (topdown_layers, lat_layers, fem_layers) +- +- +-def resnet50(): +- """Constructs a ResNet-50 model. +- Args: +- pretrained (bool): If True, returns a model pre-trained on ImageNet +- """ +- model = ResNet(Bottleneck, [3, 4, 6, 3]) +- return model +- +- +-def resnet101(): +- model = ResNet(Bottleneck, [3, 4, 23, 3]) +- return model +- +- +-def resnet152(): +- model = ResNet(Bottleneck, [3, 8, 36, 3]) +- return model +- +- +-def model_map(net_name='resnet50'): +- _dicts = {'resnet50': resnet50, +- 'resnet101': resnet101, 'resnet152': resnet152} +- return _dicts[net_name]() +- +- +-def build_net_resnet(phase, num_classes=2, net_name='resnet50'): +- resnet = model_map(net_name) +- extras = add_extras(extras_cfg, 2048) +- head_pal1 = multibox(net_cfg, num_classes) +- head_pal2 = multibox(net_cfg, num_classes) +- fem_modules = fem_module(net_cfg) +- model = DSFD(phase, resnet, extras, fem_modules, +- head_pal1, head_pal2, num_classes) +- return model +- +-if __name__ == '__main__': +- inputs = Variable(torch.randn(1, 3, 640, 640)) +- net = build_net('train', 2, 101) +- out = net(inputs) diff --git a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/models/DSFD_vgg.py b/contrib/ACL_PyTorch/Research/cv/detection/DSFD/models/DSFD_vgg.py deleted file mode 100644 index 8a842e593a..0000000000 --- a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/models/DSFD_vgg.py +++ /dev/null @@ -1,374 +0,0 @@ --# Copyright 2021 Huawei Technologies Co., Ltd --# --# Licensed under the Apache License, Version 2.0 (the "License"); --# you may not use this file except in compliance with the License. --# You may obtain a copy of the License at --# --# http://www.apache.org/licenses/LICENSE-2.0 --# --# Unless required by applicable law or agreed to in writing, software --# distributed under the License is distributed on an "AS IS" BASIS, --# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --# See the License for the specific language governing permissions and --# limitations under the License. -- --#coding=utf-8 -- --from __future__ import division --from __future__ import absolute_import --from __future__ import print_function -- --import os --import numpy as np -- --import torch --import torch.nn as nn --import torch.nn.init as init --import torch.nn.functional as F --from torch.autograd import Variable -- --from layers import * --from data.config import cur_config as cfg -- -- --class FEM(nn.Module): -- """docstring for FEM""" -- -- def __init__(self, in_planes): -- super(FEM, self).__init__() -- inter_planes = in_planes // 3 -- inter_planes1 = in_planes - 2 * inter_planes -- self.branch1 = nn.Conv2d( -- in_planes, inter_planes, kernel_size=3, stride=1, padding=3, dilation=3) -- -- self.branch2 = nn.Sequential( -- nn.Conv2d(in_planes, inter_planes, kernel_size=3, -- stride=1, padding=3, dilation=3), -- nn.ReLU(inplace=True), -- nn.Conv2d(inter_planes, inter_planes, kernel_size=3, -- stride=1, padding=3, dilation=3) -- ) -- self.branch3 = nn.Sequential( -- nn.Conv2d(in_planes, inter_planes1, kernel_size=3, -- stride=1, padding=3, dilation=3), -- nn.ReLU(inplace=True), -- nn.Conv2d(inter_planes1, inter_planes1, kernel_size=3, -- stride=1, padding=3, dilation=3), -- nn.ReLU(inplace=True), -- nn.Conv2d(inter_planes1, inter_planes1, kernel_size=3, -- stride=1, padding=3, dilation=3) -- ) -- -- def forward(self, x): -- x1 = self.branch1(x) -- x2 = self.branch2(x) -- x3 = self.branch3(x) -- out = torch.cat((x1, x2, x3), dim=1) -- out = F.relu(out, inplace=True) -- return out -- -- --class DSFD(nn.Module): -- """Single Shot Multibox Architecture -- The network is composed of a base VGG network followed by the -- added multibox conv layers. Each multibox layer branches into -- 1) conv2d for class conf scores -- 2) conv2d for localization predictions -- 3) associated priorbox layer to produce default bounding -- boxes specific to the layer's feature map size. -- See: https://arxiv.org/pdf/1512.02325.pdf for more details. -- -- Args: -- phase: (string) Can be "test" or "train" -- size: input image size -- base: VGG16 layers for input, size of either 300 or 500 -- extras: extra layers that feed to multibox loc and conf layers -- head: "multibox head" consists of loc and conf conv layers -- """ -- -- def __init__(self, phase, base, extras, fem, head1, head2, num_classes): -- super(DSFD, self).__init__() -- self.phase = phase -- self.num_classes = num_classes -- self.vgg = nn.ModuleList(base) -- -- self.L2Normof1 = L2Norm(256, 10) -- self.L2Normof2 = L2Norm(512, 8) -- self.L2Normof3 = L2Norm(512, 5) -- -- self.extras = nn.ModuleList(extras) -- self.fpn_topdown = nn.ModuleList(fem[0]) -- self.fpn_latlayer = nn.ModuleList(fem[1]) -- -- self.fpn_fem = nn.ModuleList(fem[2]) -- -- self.L2Normef1 = L2Norm(256, 10) -- self.L2Normef2 = L2Norm(512, 8) -- self.L2Normef3 = L2Norm(512, 5) -- -- self.loc_pal1 = nn.ModuleList(head1[0]) -- self.conf_pal1 = nn.ModuleList(head1[1]) -- -- self.loc_pal2 = nn.ModuleList(head2[0]) -- self.conf_pal2 = nn.ModuleList(head2[1]) -- -- if self.phase=='test': -- self.softmax = nn.Softmax(dim=-1) -- self.detect = Detect(cfg) -- -- def _upsample_prod(self, x, y): -- _, _, H, W = y.size() -- return F.upsample(x, size=(H, W), mode='bilinear') * y -- -- def forward(self, x): -- size = x.size()[2:] -- pal1_sources = list() -- pal2_sources = list() -- loc_pal1 = list() -- conf_pal1 = list() -- loc_pal2 = list() -- conf_pal2 = list() -- -- # apply vgg up to conv4_3 relu -- for k in range(16): -- x = self.vgg[k](x) -- of1 = x -- s = self.L2Normof1(of1) -- pal1_sources.append(s) -- # apply vgg up to fc7 -- for k in range(16, 23): -- x = self.vgg[k](x) -- of2 = x -- s = self.L2Normof2(of2) -- pal1_sources.append(s) -- -- for k in range(23, 30): -- x = self.vgg[k](x) -- of3 = x -- s = self.L2Normof3(of3) -- pal1_sources.append(s) -- -- for k in range(30, len(self.vgg)): -- x = self.vgg[k](x) -- of4 = x -- pal1_sources.append(of4) -- # apply extra layers and cache source layer outputs -- -- for k in range(2): -- x = F.relu(self.extras[k](x), inplace=True) -- of5 = x -- pal1_sources.append(of5) -- for k in range(2, 4): -- x = F.relu(self.extras[k](x), inplace=True) -- of6 = x -- pal1_sources.append(of6) -- -- conv7 = F.relu(self.fpn_topdown[0](of6), inplace=True) -- -- x = F.relu(self.fpn_topdown[1](conv7), inplace=True) -- conv6 = F.relu(self._upsample_prod( -- x, self.fpn_latlayer[0](of5)), inplace=True) -- -- x = F.relu(self.fpn_topdown[2](conv6), inplace=True) -- convfc7_2 = F.relu(self._upsample_prod( -- x, self.fpn_latlayer[1](of4)), inplace=True) -- -- x = F.relu(self.fpn_topdown[3](convfc7_2), inplace=True) -- conv5 = F.relu(self._upsample_prod( -- x, self.fpn_latlayer[2](of3)), inplace=True) -- -- x = F.relu(self.fpn_topdown[4](conv5), inplace=True) -- conv4 = F.relu(self._upsample_prod( -- x, self.fpn_latlayer[3](of2)), inplace=True) -- -- x = F.relu(self.fpn_topdown[5](conv4), inplace=True) -- conv3 = F.relu(self._upsample_prod( -- x, self.fpn_latlayer[4](of1)), inplace=True) -- -- ef1 = self.fpn_fem[0](conv3) -- ef1 = self.L2Normef1(ef1) -- ef2 = self.fpn_fem[1](conv4) -- ef2 = self.L2Normef2(ef2) -- ef3 = self.fpn_fem[2](conv5) -- ef3 = self.L2Normef3(ef3) -- ef4 = self.fpn_fem[3](convfc7_2) -- ef5 = self.fpn_fem[4](conv6) -- ef6 = self.fpn_fem[5](conv7) -- -- pal2_sources = (ef1, ef2, ef3, ef4, ef5, ef6) -- for (x, l, c) in zip(pal1_sources, self.loc_pal1, self.conf_pal1): -- loc_pal1.append(l(x).permute(0, 2, 3, 1).contiguous()) -- conf_pal1.append(c(x).permute(0, 2, 3, 1).contiguous()) -- -- for (x, l, c) in zip(pal2_sources, self.loc_pal2, self.conf_pal2): -- loc_pal2.append(l(x).permute(0, 2, 3, 1).contiguous()) -- conf_pal2.append(c(x).permute(0, 2, 3, 1).contiguous()) -- -- features_maps = [] -- for i in range(len(loc_pal1)): -- feat = [] -- feat += [loc_pal1[i].size(1), loc_pal1[i].size(2)] -- features_maps += [feat] -- -- loc_pal1 = torch.cat([o.view(o.size(0), -1) -- for o in loc_pal1], 1) -- conf_pal1 = torch.cat([o.view(o.size(0), -1) -- for o in conf_pal1], 1) -- -- loc_pal2 = torch.cat([o.view(o.size(0), -1) -- for o in loc_pal2], 1) -- conf_pal2 = torch.cat([o.view(o.size(0), -1) -- for o in conf_pal2], 1) -- -- priorbox = PriorBox(size, features_maps, cfg, pal=1) -- self.priors_pal1 = Variable(priorbox.forward(), volatile=True) -- -- priorbox = PriorBox(size, features_maps, cfg, pal=2) -- self.priors_pal2 = Variable(priorbox.forward(), volatile=True) -- -- if self.phase == 'test': -- output = self.detect( -- loc_pal2.view(loc_pal2.size(0), -1, 4), -- self.softmax(conf_pal2.view(conf_pal2.size(0), -1, -- self.num_classes)), # conf preds -- self.priors_pal2.type(type(x.data)) -- ) -- -- else: -- output = ( -- loc_pal1.view(loc_pal1.size(0), -1, 4), -- conf_pal1.view(conf_pal1.size(0), -1, self.num_classes), -- self.priors_pal1, -- loc_pal2.view(loc_pal2.size(0), -1, 4), -- conf_pal2.view(conf_pal2.size(0), -1, self.num_classes), -- self.priors_pal2) -- return output -- -- def load_weights(self, base_file): -- other, ext = os.path.splitext(base_file) -- if ext == '.pkl' or '.pth': -- print('Loading weights into state dict...') -- mdata = torch.load(base_file, -- map_location=lambda storage, loc: storage) -- weights = mdata['weight'] -- epoch = mdata['epoch'] -- self.load_state_dict(weights) -- print('Finished!') -- else: -- print('Sorry only .pth and .pkl files supported.') -- return epoch -- -- def xavier(self, param): -- init.xavier_uniform(param) -- -- def weights_init(self, m): -- if isinstance(m, nn.Conv2d): -- self.xavier(m.weight.data) -- m.bias.data.zero_() -- -- if isinstance(m,nn.ConvTranspose2d): -- self.xavier(m.weight.data) -- if 'bias' in m.state_dict().keys(): -- m.bias.data.zero_() -- -- if isinstance(m,nn.BatchNorm2d): -- m.weight.data[...] = 1 -- m.bias.data.zero_() -- -- --vgg_cfg = [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 'C', 512, 512, 512, 'M', -- 512, 512, 512, 'M'] -- --extras_cfg = [256, 'S', 512, 128, 'S', 256] -- --fem_cfg = [256, 512, 512, 1024, 512, 256] -- -- --def fem_module(cfg): -- topdown_layers = [] -- lat_layers = [] -- fem_layers = [] -- -- topdown_layers += [nn.Conv2d(cfg[-1], cfg[-1], -- kernel_size=1, stride=1, padding=0)] -- for k, v in enumerate(cfg): -- fem_layers += [FEM(v)] -- cur_channel = cfg[len(cfg) - 1 - k] -- if len(cfg) - 1 - k > 0: -- last_channel = cfg[len(cfg) - 2 - k] -- topdown_layers += [nn.Conv2d(cur_channel, last_channel, -- kernel_size=1, stride=1, padding=0)] -- lat_layers += [nn.Conv2d(last_channel, last_channel, -- kernel_size=1, stride=1, padding=0)] -- return (topdown_layers, lat_layers, fem_layers) -- -- --def vgg(cfg, i, batch_norm=False): -- layers = [] -- in_channels = i -- for v in cfg: -- if v == 'M': -- layers += [nn.MaxPool2d(kernel_size=2, stride=2)] -- elif v == 'C': -- layers += [nn.MaxPool2d(kernel_size=2, stride=2, ceil_mode=True)] -- else: -- conv2d = nn.Conv2d(in_channels, v, kernel_size=3, padding=1) -- if batch_norm: -- layers += [conv2d, nn.BatchNorm2d(v), nn.ReLU(inplace=True)] -- else: -- layers += [conv2d, nn.ReLU(inplace=True)] -- in_channels = v -- conv6 = nn.Conv2d(512, 1024, kernel_size=3, padding=3, dilation=3) -- conv7 = nn.Conv2d(1024, 1024, kernel_size=1) -- layers += [conv6, -- nn.ReLU(inplace=True), conv7, nn.ReLU(inplace=True)] -- return layers -- -- --def add_extras(cfg, i, batch_norm=False): -- # Extra layers added to VGG for feature scaling -- layers = [] -- in_channels = i -- flag = False -- for k, v in enumerate(cfg): -- if in_channels != 'S': -- if v == 'S': -- layers += [nn.Conv2d(in_channels, cfg[k + 1], -- kernel_size=(1, 3)[flag], stride=2, padding=1)] -- else: -- layers += [nn.Conv2d(in_channels, v, kernel_size=(1, 3)[flag])] -- flag = not flag -- in_channels = v -- return layers -- -- --def multibox(vgg, extra_layers, num_classes): -- loc_layers = [] -- conf_layers = [] -- vgg_source = [14, 21, 28, -2] -- -- for k, v in enumerate(vgg_source): -- loc_layers += [nn.Conv2d(vgg[v].out_channels, -- 4, kernel_size=3, padding=1)] -- conf_layers += [nn.Conv2d(vgg[v].out_channels, -- num_classes, kernel_size=3, padding=1)] -- for k, v in enumerate(extra_layers[1::2], 2): -- loc_layers += [nn.Conv2d(v.out_channels, -- 4, kernel_size=3, padding=1)] -- conf_layers += [nn.Conv2d(v.out_channels, -- num_classes, kernel_size=3, padding=1)] -- return (loc_layers, conf_layers) -- -- --def build_net_vgg(phase, num_classes=2): -- base = vgg(vgg_cfg, 3) -- extras = add_extras(extras_cfg, 1024) -- head1 = multibox(base, extras, num_classes) -- head2 = multibox(base, extras, num_classes) -- fem = fem_module(fem_cfg) -- return DSFD(phase, base, extras, fem, head1, head2, num_classes) -- --if __name__ == '__main__': -- inputs = Variable(torch.randn(1, 3, 640, 640)) -- net = build_net('train', 2) -- out = net(inputs) +-# Copyright 2021 Huawei Technologies Co., Ltd +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +- +-#coding=utf-8 +- +-from __future__ import division +-from __future__ import absolute_import +-from __future__ import print_function +- +-import os +-import numpy as np +- +-import torch +-import torch.nn as nn +-import torch.nn.init as init +-import torch.nn.functional as F +-from torch.autograd import Variable +- +-from layers import * +-from data.config import cur_config as cfg +- +- +-class FEM(nn.Module): +- """docstring for FEM""" +- +- def __init__(self, in_planes): +- super(FEM, self).__init__() +- inter_planes = in_planes // 3 +- inter_planes1 = in_planes - 2 * inter_planes +- self.branch1 = nn.Conv2d( +- in_planes, inter_planes, kernel_size=3, stride=1, padding=3, dilation=3) +- +- self.branch2 = nn.Sequential( +- nn.Conv2d(in_planes, inter_planes, kernel_size=3, +- stride=1, padding=3, dilation=3), +- nn.ReLU(inplace=True), +- nn.Conv2d(inter_planes, inter_planes, kernel_size=3, +- stride=1, padding=3, dilation=3) +- ) +- self.branch3 = nn.Sequential( +- nn.Conv2d(in_planes, inter_planes1, kernel_size=3, +- stride=1, padding=3, dilation=3), +- nn.ReLU(inplace=True), +- nn.Conv2d(inter_planes1, inter_planes1, kernel_size=3, +- stride=1, padding=3, dilation=3), +- nn.ReLU(inplace=True), +- nn.Conv2d(inter_planes1, inter_planes1, kernel_size=3, +- stride=1, padding=3, dilation=3) +- ) +- +- def forward(self, x): +- x1 = self.branch1(x) +- x2 = self.branch2(x) +- x3 = self.branch3(x) +- out = torch.cat((x1, x2, x3), dim=1) +- out = F.relu(out, inplace=True) +- return out +- +- +-class DSFD(nn.Module): +- """Single Shot Multibox Architecture +- The network is composed of a base VGG network followed by the +- added multibox conv layers. Each multibox layer branches into +- 1) conv2d for class conf scores +- 2) conv2d for localization predictions +- 3) associated priorbox layer to produce default bounding +- boxes specific to the layer's feature map size. +- See: https://arxiv.org/pdf/1512.02325.pdf for more details. +- +- Args: +- phase: (string) Can be "test" or "train" +- size: input image size +- base: VGG16 layers for input, size of either 300 or 500 +- extras: extra layers that feed to multibox loc and conf layers +- head: "multibox head" consists of loc and conf conv layers +- """ +- +- def __init__(self, phase, base, extras, fem, head1, head2, num_classes): +- super(DSFD, self).__init__() +- self.phase = phase +- self.num_classes = num_classes +- self.vgg = nn.ModuleList(base) +- +- self.L2Normof1 = L2Norm(256, 10) +- self.L2Normof2 = L2Norm(512, 8) +- self.L2Normof3 = L2Norm(512, 5) +- +- self.extras = nn.ModuleList(extras) +- self.fpn_topdown = nn.ModuleList(fem[0]) +- self.fpn_latlayer = nn.ModuleList(fem[1]) +- +- self.fpn_fem = nn.ModuleList(fem[2]) +- +- self.L2Normef1 = L2Norm(256, 10) +- self.L2Normef2 = L2Norm(512, 8) +- self.L2Normef3 = L2Norm(512, 5) +- +- self.loc_pal1 = nn.ModuleList(head1[0]) +- self.conf_pal1 = nn.ModuleList(head1[1]) +- +- self.loc_pal2 = nn.ModuleList(head2[0]) +- self.conf_pal2 = nn.ModuleList(head2[1]) +- +- if self.phase=='test': +- self.softmax = nn.Softmax(dim=-1) +- self.detect = Detect(cfg) +- +- def _upsample_prod(self, x, y): +- _, _, H, W = y.size() +- return F.upsample(x, size=(H, W), mode='bilinear') * y +- +- def forward(self, x): +- size = x.size()[2:] +- pal1_sources = list() +- pal2_sources = list() +- loc_pal1 = list() +- conf_pal1 = list() +- loc_pal2 = list() +- conf_pal2 = list() +- +- # apply vgg up to conv4_3 relu +- for k in range(16): +- x = self.vgg[k](x) +- of1 = x +- s = self.L2Normof1(of1) +- pal1_sources.append(s) +- # apply vgg up to fc7 +- for k in range(16, 23): +- x = self.vgg[k](x) +- of2 = x +- s = self.L2Normof2(of2) +- pal1_sources.append(s) +- +- for k in range(23, 30): +- x = self.vgg[k](x) +- of3 = x +- s = self.L2Normof3(of3) +- pal1_sources.append(s) +- +- for k in range(30, len(self.vgg)): +- x = self.vgg[k](x) +- of4 = x +- pal1_sources.append(of4) +- # apply extra layers and cache source layer outputs +- +- for k in range(2): +- x = F.relu(self.extras[k](x), inplace=True) +- of5 = x +- pal1_sources.append(of5) +- for k in range(2, 4): +- x = F.relu(self.extras[k](x), inplace=True) +- of6 = x +- pal1_sources.append(of6) +- +- conv7 = F.relu(self.fpn_topdown[0](of6), inplace=True) +- +- x = F.relu(self.fpn_topdown[1](conv7), inplace=True) +- conv6 = F.relu(self._upsample_prod( +- x, self.fpn_latlayer[0](of5)), inplace=True) +- +- x = F.relu(self.fpn_topdown[2](conv6), inplace=True) +- convfc7_2 = F.relu(self._upsample_prod( +- x, self.fpn_latlayer[1](of4)), inplace=True) +- +- x = F.relu(self.fpn_topdown[3](convfc7_2), inplace=True) +- conv5 = F.relu(self._upsample_prod( +- x, self.fpn_latlayer[2](of3)), inplace=True) +- +- x = F.relu(self.fpn_topdown[4](conv5), inplace=True) +- conv4 = F.relu(self._upsample_prod( +- x, self.fpn_latlayer[3](of2)), inplace=True) +- +- x = F.relu(self.fpn_topdown[5](conv4), inplace=True) +- conv3 = F.relu(self._upsample_prod( +- x, self.fpn_latlayer[4](of1)), inplace=True) +- +- ef1 = self.fpn_fem[0](conv3) +- ef1 = self.L2Normef1(ef1) +- ef2 = self.fpn_fem[1](conv4) +- ef2 = self.L2Normef2(ef2) +- ef3 = self.fpn_fem[2](conv5) +- ef3 = self.L2Normef3(ef3) +- ef4 = self.fpn_fem[3](convfc7_2) +- ef5 = self.fpn_fem[4](conv6) +- ef6 = self.fpn_fem[5](conv7) +- +- pal2_sources = (ef1, ef2, ef3, ef4, ef5, ef6) +- for (x, l, c) in zip(pal1_sources, self.loc_pal1, self.conf_pal1): +- loc_pal1.append(l(x).permute(0, 2, 3, 1).contiguous()) +- conf_pal1.append(c(x).permute(0, 2, 3, 1).contiguous()) +- +- for (x, l, c) in zip(pal2_sources, self.loc_pal2, self.conf_pal2): +- loc_pal2.append(l(x).permute(0, 2, 3, 1).contiguous()) +- conf_pal2.append(c(x).permute(0, 2, 3, 1).contiguous()) +- +- features_maps = [] +- for i in range(len(loc_pal1)): +- feat = [] +- feat += [loc_pal1[i].size(1), loc_pal1[i].size(2)] +- features_maps += [feat] +- +- loc_pal1 = torch.cat([o.view(o.size(0), -1) +- for o in loc_pal1], 1) +- conf_pal1 = torch.cat([o.view(o.size(0), -1) +- for o in conf_pal1], 1) +- +- loc_pal2 = torch.cat([o.view(o.size(0), -1) +- for o in loc_pal2], 1) +- conf_pal2 = torch.cat([o.view(o.size(0), -1) +- for o in conf_pal2], 1) +- +- priorbox = PriorBox(size, features_maps, cfg, pal=1) +- self.priors_pal1 = Variable(priorbox.forward(), volatile=True) +- +- priorbox = PriorBox(size, features_maps, cfg, pal=2) +- self.priors_pal2 = Variable(priorbox.forward(), volatile=True) +- +- if self.phase == 'test': +- output = self.detect( +- loc_pal2.view(loc_pal2.size(0), -1, 4), +- self.softmax(conf_pal2.view(conf_pal2.size(0), -1, +- self.num_classes)), # conf preds +- self.priors_pal2.type(type(x.data)) +- ) +- +- else: +- output = ( +- loc_pal1.view(loc_pal1.size(0), -1, 4), +- conf_pal1.view(conf_pal1.size(0), -1, self.num_classes), +- self.priors_pal1, +- loc_pal2.view(loc_pal2.size(0), -1, 4), +- conf_pal2.view(conf_pal2.size(0), -1, self.num_classes), +- self.priors_pal2) +- return output +- +- def load_weights(self, base_file): +- other, ext = os.path.splitext(base_file) +- if ext == '.pkl' or '.pth': +- print('Loading weights into state dict...') +- mdata = torch.load(base_file, +- map_location=lambda storage, loc: storage) +- weights = mdata['weight'] +- epoch = mdata['epoch'] +- self.load_state_dict(weights) +- print('Finished!') +- else: +- print('Sorry only .pth and .pkl files supported.') +- return epoch +- +- def xavier(self, param): +- init.xavier_uniform(param) +- +- def weights_init(self, m): +- if isinstance(m, nn.Conv2d): +- self.xavier(m.weight.data) +- m.bias.data.zero_() +- +- if isinstance(m,nn.ConvTranspose2d): +- self.xavier(m.weight.data) +- if 'bias' in m.state_dict().keys(): +- m.bias.data.zero_() +- +- if isinstance(m,nn.BatchNorm2d): +- m.weight.data[...] = 1 +- m.bias.data.zero_() +- +- +-vgg_cfg = [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 'C', 512, 512, 512, 'M', +- 512, 512, 512, 'M'] +- +-extras_cfg = [256, 'S', 512, 128, 'S', 256] +- +-fem_cfg = [256, 512, 512, 1024, 512, 256] +- +- +-def fem_module(cfg): +- topdown_layers = [] +- lat_layers = [] +- fem_layers = [] +- +- topdown_layers += [nn.Conv2d(cfg[-1], cfg[-1], +- kernel_size=1, stride=1, padding=0)] +- for k, v in enumerate(cfg): +- fem_layers += [FEM(v)] +- cur_channel = cfg[len(cfg) - 1 - k] +- if len(cfg) - 1 - k > 0: +- last_channel = cfg[len(cfg) - 2 - k] +- topdown_layers += [nn.Conv2d(cur_channel, last_channel, +- kernel_size=1, stride=1, padding=0)] +- lat_layers += [nn.Conv2d(last_channel, last_channel, +- kernel_size=1, stride=1, padding=0)] +- return (topdown_layers, lat_layers, fem_layers) +- +- +-def vgg(cfg, i, batch_norm=False): +- layers = [] +- in_channels = i +- for v in cfg: +- if v == 'M': +- layers += [nn.MaxPool2d(kernel_size=2, stride=2)] +- elif v == 'C': +- layers += [nn.MaxPool2d(kernel_size=2, stride=2, ceil_mode=True)] +- else: +- conv2d = nn.Conv2d(in_channels, v, kernel_size=3, padding=1) +- if batch_norm: +- layers += [conv2d, nn.BatchNorm2d(v), nn.ReLU(inplace=True)] +- else: +- layers += [conv2d, nn.ReLU(inplace=True)] +- in_channels = v +- conv6 = nn.Conv2d(512, 1024, kernel_size=3, padding=3, dilation=3) +- conv7 = nn.Conv2d(1024, 1024, kernel_size=1) +- layers += [conv6, +- nn.ReLU(inplace=True), conv7, nn.ReLU(inplace=True)] +- return layers +- +- +-def add_extras(cfg, i, batch_norm=False): +- # Extra layers added to VGG for feature scaling +- layers = [] +- in_channels = i +- flag = False +- for k, v in enumerate(cfg): +- if in_channels != 'S': +- if v == 'S': +- layers += [nn.Conv2d(in_channels, cfg[k + 1], +- kernel_size=(1, 3)[flag], stride=2, padding=1)] +- else: +- layers += [nn.Conv2d(in_channels, v, kernel_size=(1, 3)[flag])] +- flag = not flag +- in_channels = v +- return layers +- +- +-def multibox(vgg, extra_layers, num_classes): +- loc_layers = [] +- conf_layers = [] +- vgg_source = [14, 21, 28, -2] +- +- for k, v in enumerate(vgg_source): +- loc_layers += [nn.Conv2d(vgg[v].out_channels, +- 4, kernel_size=3, padding=1)] +- conf_layers += [nn.Conv2d(vgg[v].out_channels, +- num_classes, kernel_size=3, padding=1)] +- for k, v in enumerate(extra_layers[1::2], 2): +- loc_layers += [nn.Conv2d(v.out_channels, +- 4, kernel_size=3, padding=1)] +- conf_layers += [nn.Conv2d(v.out_channels, +- num_classes, kernel_size=3, padding=1)] +- return (loc_layers, conf_layers) +- +- +-def build_net_vgg(phase, num_classes=2): +- base = vgg(vgg_cfg, 3) +- extras = add_extras(extras_cfg, 1024) +- head1 = multibox(base, extras, num_classes) +- head2 = multibox(base, extras, num_classes) +- fem = fem_module(fem_cfg) +- return DSFD(phase, base, extras, fem, head1, head2, num_classes) +- +-if __name__ == '__main__': +- inputs = Variable(torch.randn(1, 3, 640, 640)) +- net = build_net('train', 2) +- out = net(inputs) diff --git a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/models/__init__.py b/contrib/ACL_PyTorch/Research/cv/detection/DSFD/models/__init__.py deleted file mode 100644 index 89552b1d3f..0000000000 @@ -8417,53 +8417,53 @@ index b42d14b830..0000000000 --- a/contrib/ACL_PyTorch/Research/cv/detection/DSFD/models/factory.py +++ /dev/null @@ -1,50 +0,0 @@ --# Copyright 2021 Huawei Technologies Co., Ltd --# --# Licensed under the Apache License, Version 2.0 (the "License"); --# you may not use this file except in compliance with the License. --# You may obtain a copy of the License at --# --# http://www.apache.org/licenses/LICENSE-2.0 --# --# Unless required by applicable law or agreed to in writing, software --# distributed under the License is distributed on an "AS IS" BASIS, --# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --# See the License for the specific language governing permissions and --# limitations under the License. -- --# -*- coding: utf-8 -*- --from __future__ import division --from __future__ import print_function --from __future__ import absolute_import -- --import torch --import torch.backends.cudnn as cudnn -- --#from .DSFD_vgg import build_net_vgg --from .DSFD_resnet import build_net_resnet -- -- --def build_net(phase, num_classes=2, model='vgg'): -- if phase != "test" and phase != "train": -- print("ERROR: Phase: " + phase + " not recognized") -- return -- -- if model != 'vgg' and 'resnet' not in model: -- print("ERROR: model:" + model + " not recognized") -- return -- -- if model == 'vgg': -- return build_net_vgg(phase, num_classes) -- else: -- return build_net_resnet(phase, num_classes, model) -- -- -- --def basenet_factory(model='vgg'): -- if model=='vgg': -- basenet = 'vgg16_reducedfc.pth' -- -- elif 'resnet' in model: -- basenet = '{}.pth'.format(model) -- return basenet -- +-# Copyright 2021 Huawei Technologies Co., Ltd +-# +-# Licensed under the Apache License, Version 2.0 (the "License"); +-# you may not use this file except in compliance with the License. +-# You may obtain a copy of the License at +-# +-# http://www.apache.org/licenses/LICENSE-2.0 +-# +-# Unless required by applicable law or agreed to in writing, software +-# distributed under the License is distributed on an "AS IS" BASIS, +-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-# See the License for the specific language governing permissions and +-# limitations under the License. +- +-# -*- coding: utf-8 -*- +-from __future__ import division +-from __future__ import print_function +-from __future__ import absolute_import +- +-import torch +-import torch.backends.cudnn as cudnn +- +-#from .DSFD_vgg import build_net_vgg +-from .DSFD_resnet import build_net_resnet +- +- +-def build_net(phase, num_classes=2, model='vgg'): +- if phase != "test" and phase != "train": +- print("ERROR: Phase: " + phase + " not recognized") +- return +- +- if model != 'vgg' and 'resnet' not in model: +- print("ERROR: model:" + model + " not recognized") +- return +- +- if model == 'vgg': +- return build_net_vgg(phase, num_classes) +- else: +- return build_net_resnet(phase, num_classes, model) +- +- +- +-def basenet_factory(model='vgg'): +- if model=='vgg': +- basenet = 'vgg16_reducedfc.pth' +- +- elif 'resnet' in model: +- basenet = '{}.pth'.format(model) +- return basenet +- diff --git a/ACL_PyTorch/contrib/cv/detection/DSFD/README.md b/ACL_PyTorch/contrib/cv/detection/DSFD/README.md index eec06e18abe7c8999d4e7c500b7e757972e245e3..b9e504b8425e0a15fdad9b823d5877b9f86fcfe5 100644 --- a/ACL_PyTorch/contrib/cv/detection/DSFD/README.md +++ b/ACL_PyTorch/contrib/cv/detection/DSFD/README.md @@ -1,104 +1,104 @@ - - - - -# 概述 - -FaceDetection-DSFD是通用场景下的人脸检测模型,采用FSSD+Resnet的网络结构,加入FEM 模块进一步增强不同感受野的目标特征,实现高准确率的人脸检测 - -## 1.环境准备 - - - -1.安装必要的依赖 - -```python -pip install -r requirements.txt -source env.sh -``` - -2.执行 eval_tols/dsfd_acc_eval.py 之前先执行以下命令 - -``` -cd eval_tools -python setup.py build_ext --inplace -``` - -3.获取权重文件 - -[pth模型链接](链接:https://pan.baidu.com/s/1DKNAKusuSh8O_91xvpCtWw 提取码:i468) 下载后放在根目录下 - -4.获取推理图像集 放在 opt/npu/目录下 - -[推理图像数据集](链接:https://pan.baidu.com/s/1KvpfjR0U8KUJnY7Gw5vLnQ 提取码:e3lu) - -5.获取benchmark工具 - -将benchmark.x86_64或benchmark.aarch64放到主目录下 - -``` -chmod a+x benchmark.x86_64 -``` - -6.进行数据预处理 - -```python -python dsfd_preprocess.py --src_path '/opt/npu/WIDERFace/WIDER_val/images/' #主目录下产生info_result.info文件 -``` - - - -## 2.模型转换 - -1.进行pth转onnx模型 - -``` -cd test -python dsfd_pth2onnx.py --model_path '../dsfd.pth' -``` - -[onnx文件链接](链接:https://pan.baidu.com/s/1HR5Ur5-KjNYlVJnJ6JOdVg 提取码:yqep) 生成的onnx模型文件在test文件夹下 - -2.进行onnx模型转om模型 - -cd到test目录下执行以下命令 - -``` -bash onnx2om.sh -``` - -生成的om模型在上一层 onnx2om 文件夹下 - -## 3.离线推理 - -1.将得到om模型后进行模型性能推理,在310上运行,先执行npu-smi info查看设备状态,确保device空闲 - -``` -cd test -bsah om_inference.sh #产生文件在 result/dumpOutput_device0 -``` - -2.进行模型精度统计 - -eval_tools文件夹内要含有 ground_truth相关文件 - -``` -cd eval_tools -python dsfd_acc_eval.py -p '../result/dumpOutput_device0/' -g './ground_truth/' -``` - -3.模型推理性能及精度 - -| Model | Batch Size | 310 (FPS/Card) | T4 (FPS/Card) | 310/T4 | -| ----- | ---------- | -------------- | ------------- | --------- | -| DSFD | 1 | *206* | *168* | *206/168* | -| DSFD | 4 | *262* | *314* | *262/314* | -| DSFD | 8 | *286* | *380* | *286/380* | -| DSFD | 16 | *306* | *425* | *306/425* | -| DSFD | 32 | *305* | *427* | *305/427* | - - - -| Framework | Atlas NPU Model | Server | Container | Precision | Dataset | Accuracy | Ascend AI Processor | NPU Version | -| --------- | ---------------- | --------------- | --------- | --------- | ---------- | ------------------------------------------------------------ | -------------------- | -------------------- | + + + + +# 概述 + +FaceDetection-DSFD是通用场景下的人脸检测模型,采用FSSD+Resnet的网络结构,加入FEM 模块进一步增强不同感受野的目标特征,实现高准确率的人脸检测 + +## 1.环境准备 + + + +1.安装必要的依赖 + +```python +pip install -r requirements.txt +source env.sh +``` + +2.执行 eval_tols/dsfd_acc_eval.py 之前先执行以下命令 + +``` +cd eval_tools +python setup.py build_ext --inplace +``` + +3.获取权重文件 + +[pth模型链接](链接:https://pan.baidu.com/s/1DKNAKusuSh8O_91xvpCtWw 提取码:i468) 下载后放在根目录下 + +4.获取推理图像集 放在 opt/npu/目录下 + +[推理图像数据集](链接:https://pan.baidu.com/s/1KvpfjR0U8KUJnY7Gw5vLnQ 提取码:e3lu) + +5.获取benchmark工具 + +将benchmark.x86_64或benchmark.aarch64放到主目录下 + +``` +chmod a+x benchmark.x86_64 +``` + +6.进行数据预处理 + +```python +python dsfd_preprocess.py --src_path '/opt/npu/WIDERFace/WIDER_val/images/' #主目录下产生info_result.info文件 +``` + + + +## 2.模型转换 + +1.进行pth转onnx模型 + +``` +cd test +python dsfd_pth2onnx.py --model_path '../dsfd.pth' +``` + +[onnx文件链接](链接:https://pan.baidu.com/s/1HR5Ur5-KjNYlVJnJ6JOdVg 提取码:yqep) 生成的onnx模型文件在test文件夹下 + +2.进行onnx模型转om模型 + +cd到test目录下执行以下命令 + +``` +bash onnx2om.sh +``` + +生成的om模型在上一层 onnx2om 文件夹下 + +## 3.离线推理 + +1.将得到om模型后进行模型性能推理,在310上运行,先执行npu-smi info查看设备状态,确保device空闲 + +``` +cd test +bsah om_inference.sh #产生文件在 result/dumpOutput_device0 +``` + +2.进行模型精度统计 + +eval_tools文件夹内要含有 ground_truth相关文件 + +``` +cd eval_tools +python dsfd_acc_eval.py -p '../result/dumpOutput_device0/' -g './ground_truth/' +``` + +3.模型推理性能及精度 + +| Model | Batch Size | 310 (FPS/Card) | T4 (FPS/Card) | 310/T4 | +| ----- | ---------- | -------------- | ------------- | --------- | +| DSFD | 1 | *206* | *168* | *206/168* | +| DSFD | 4 | *262* | *314* | *262/314* | +| DSFD | 8 | *286* | *380* | *286/380* | +| DSFD | 16 | *306* | *425* | *306/425* | +| DSFD | 32 | *305* | *427* | *305/427* | + + + +| Framework | Atlas NPU Model | Server | Container | Precision | Dataset | Accuracy | Ascend AI Processor | NPU Version | +| --------- | ---------------- | --------------- | --------- | --------- | ---------- | ------------------------------------------------------------ | -------------------- | -------------------- | | PyTorch | Atlas 300-3010 | Atlas 800-3010 | NA | fp16 | WIDER FACE | Easy Val AP: 0.9443 Medium Val AP: 0.9347 Hard Val AP: 0.8645 | Ascend 310 | Atlas 300-3010-32GB | \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/DSFD/data/config.py b/ACL_PyTorch/contrib/cv/detection/DSFD/data/config.py index 07097d89e4bc726098f35a0e85244fe004cdd9e9..55f151623b05aca0734ecd3eea527a9f7caf27fd 100644 --- a/ACL_PyTorch/contrib/cv/detection/DSFD/data/config.py +++ b/ACL_PyTorch/contrib/cv/detection/DSFD/data/config.py @@ -1,91 +1,91 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#coding=utf-8 - -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - -import os -from easydict import EasyDict -import numpy as np - - -class Config(object): - # data augument config - expand_prob = 0.5 - expand_max_ratio = 4 - hue_prob = 0.5 - hue_delta = 18 - contrast_prob = 0.5 - contrast_delta = 0.5 - saturation_prob = 0.5 - saturation_delta = 0.5 - brightness_prob = 0.5 - brightness_delta = 0.125 - data_anchor_sampling_prob = 0.5 - min_face_size = 6.0 - apply_distort = True - apply_expand = False - img_mean = np.array([104., 117., 123.])[:, np.newaxis, np.newaxis].astype( - 'float32') - resize_width = 640 - resize_height = 640 - scale = 1 / 127.0 - anchor_sampling = True - filter_min_face = True - - # train config - LR_STEPS = (80000,100000,120000) - MAX_STEPS = 150000 - EPOCHES = 100 - - # anchor config - FEATURE_MAPS = [160, 80, 40, 20, 10, 5] - INPUT_SIZE = 640 - STEPS = [4, 8, 16, 32, 64, 128] - ANCHOR_SIZES1 = [8, 16, 32, 64, 128, 256] - ANCHOR_SIZES2 = [16, 32, 64, 128, 256, 512] - ASPECT_RATIO = [1.0] - CLIP = False - VARIANCE = [0.1, 0.2] - - # detection config - NMS_THRESH = 0.3 - NMS_TOP_K = 5000 - TOP_K = 750 - CONF_THRESH = 0.05 - - # loss config - NEG_POS_RATIOS = 3 - NUM_CLASSES = 2 - - #multigpu - MultiGPU_ID =[0, 1] - - # dataset config - HOME = '/data/deling/DSFD/Data/' - - # face config - FACE = EasyDict() - FACE_TRAIN_FILE = '/data/deling/DSFD/FaceDetection-DSFD_Full/val_data/face_train.txt' #进行训练图片集合,由 prepare_wide_data.pyd得到 - FACE_VAL_FILE = '/data/deling/DSFD/FaceDetection-DSFD_Full/val_data/face_val.txt' #进行验证图片集合 - FACE_FDDB_DIR = '' - FACE_WIDER_DIR = '/data/deling/DSFD/Data' - FACE_AFW_DIR = '' - FACE_PASCAL_DIR = '' - FACE.OVERLAP_THRESH = 0.35 - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#coding=utf-8 + +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + +import os +from easydict import EasyDict +import numpy as np + + +class Config(object): + # data augument config + expand_prob = 0.5 + expand_max_ratio = 4 + hue_prob = 0.5 + hue_delta = 18 + contrast_prob = 0.5 + contrast_delta = 0.5 + saturation_prob = 0.5 + saturation_delta = 0.5 + brightness_prob = 0.5 + brightness_delta = 0.125 + data_anchor_sampling_prob = 0.5 + min_face_size = 6.0 + apply_distort = True + apply_expand = False + img_mean = np.array([104., 117., 123.])[:, np.newaxis, np.newaxis].astype( + 'float32') + resize_width = 640 + resize_height = 640 + scale = 1 / 127.0 + anchor_sampling = True + filter_min_face = True + + # train config + LR_STEPS = (80000,100000,120000) + MAX_STEPS = 150000 + EPOCHES = 100 + + # anchor config + FEATURE_MAPS = [160, 80, 40, 20, 10, 5] + INPUT_SIZE = 640 + STEPS = [4, 8, 16, 32, 64, 128] + ANCHOR_SIZES1 = [8, 16, 32, 64, 128, 256] + ANCHOR_SIZES2 = [16, 32, 64, 128, 256, 512] + ASPECT_RATIO = [1.0] + CLIP = False + VARIANCE = [0.1, 0.2] + + # detection config + NMS_THRESH = 0.3 + NMS_TOP_K = 5000 + TOP_K = 750 + CONF_THRESH = 0.05 + + # loss config + NEG_POS_RATIOS = 3 + NUM_CLASSES = 2 + + #multigpu + MultiGPU_ID =[0, 1] + + # dataset config + HOME = '/data/deling/DSFD/Data/' + + # face config + FACE = EasyDict() + FACE_TRAIN_FILE = '/data/deling/DSFD/FaceDetection-DSFD_Full/val_data/face_train.txt' #进行训练图片集合,由 prepare_wide_data.pyd得到 + FACE_VAL_FILE = '/data/deling/DSFD/FaceDetection-DSFD_Full/val_data/face_val.txt' #进行验证图片集合 + FACE_FDDB_DIR = '' + FACE_WIDER_DIR = '/data/deling/DSFD/Data' + FACE_AFW_DIR = '' + FACE_PASCAL_DIR = '' + FACE.OVERLAP_THRESH = 0.35 + cur_config = Config() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/DSFD/data/widerface.py b/ACL_PyTorch/contrib/cv/detection/DSFD/data/widerface.py index 02ec1019014b899aecce1dd0d3c0ac33ac717d50..56523c88a62f8b4cb5c3bc43dd5fee5fe2106c89 100644 --- a/ACL_PyTorch/contrib/cv/detection/DSFD/data/widerface.py +++ b/ACL_PyTorch/contrib/cv/detection/DSFD/data/widerface.py @@ -1,132 +1,132 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#coding=utf-8 - -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import cv2 -import torch -from PIL import Image, ImageDraw -import torch.utils.data as data -import numpy as np -import random -from utils.augmentations import preprocess - - -class WIDERDetection(data.Dataset): - """docstring for WIDERDetection""" - - def __init__(self, list_file, mode='train'): - super(WIDERDetection, self).__init__() - self.mode = mode - self.fnames = [] - self.boxes = [] - self.labels = [] - - with open(list_file) as f: - lines = f.readlines() - - for line in lines: - line = line.strip().split() - num_faces = int(line[1]) - box = [] - label = [] - for i in range(num_faces): - x = float(line[2 + 5 * i]) - y = float(line[3 + 5 * i]) - w = float(line[4 + 5 * i]) - h = float(line[5 + 5 * i]) - c = int(line[6 + 5 * i]) - if w <= 0 or h <= 0: - continue - box.append([x, y, x + w, y + h]) - label.append(c) - if len(box) > 0: - self.fnames.append(line[0]) - self.boxes.append(box) - self.labels.append(label) - - self.num_samples = len(self.boxes) - - def __len__(self): - return self.num_samples - - def __getitem__(self, index): - img, target, h, w = self.pull_item(index) - return img, target - - def pull_item(self, index): - while True: - image_path = self.fnames[index] - img = Image.open(image_path) - #img = cv2.imread(image_path) - - img = img.convert('RGB') - im_width, im_height = img.size - #im_width, im_height = img.shape[0],img.shape[1] - boxes = self.annotransform( - np.array(self.boxes[index]), im_width, im_height) - label = np.array(self.labels[index]) - bbox_labels = np.hstack((label[:, np.newaxis], boxes)).tolist() - img, sample_labels = preprocess( - img, bbox_labels, self.mode, image_path) - sample_labels = np.array(sample_labels) - if len(sample_labels) > 0: - target = np.hstack( - (sample_labels[:, 1:], sample_labels[:, 0][:, np.newaxis])) - - assert (target[:, 2] > target[:, 0]).any() - assert (target[:, 3] > target[:, 1]).any() - break - else: - index = random.randrange(0, self.num_samples) - return torch.from_numpy(img), target, im_height, im_width - - - def annotransform(self, boxes, im_width, im_height): - boxes[:, 0] /= im_width - boxes[:, 1] /= im_height - boxes[:, 2] /= im_width - boxes[:, 3] /= im_height - return boxes - - -def detection_collate(batch): - """Custom collate fn for dealing with batches of images that have a different - number of associated object annotations (bounding boxes). - - Arguments: - batch: (tuple) A tuple of tensor images and lists of annotations - - Return: - A tuple containing: - 1) (tensor) batch of images stacked on their 0 dim - 2) (list of tensors) annotations for a given image are stacked on - 0 dim - """ - targets = [] - imgs = [] - for sample in batch: - imgs.append(sample[0]) - targets.append(torch.FloatTensor(sample[1])) - return torch.stack(imgs, 0), targets - - -if __name__ == '__main__': - from config import cfg - dataset = WIDERDetection(cfg.FACE_TRAIN_FILE) - dataset.pull_item(14) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#coding=utf-8 + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import cv2 +import torch +from PIL import Image, ImageDraw +import torch.utils.data as data +import numpy as np +import random +from utils.augmentations import preprocess + + +class WIDERDetection(data.Dataset): + """docstring for WIDERDetection""" + + def __init__(self, list_file, mode='train'): + super(WIDERDetection, self).__init__() + self.mode = mode + self.fnames = [] + self.boxes = [] + self.labels = [] + + with open(list_file) as f: + lines = f.readlines() + + for line in lines: + line = line.strip().split() + num_faces = int(line[1]) + box = [] + label = [] + for i in range(num_faces): + x = float(line[2 + 5 * i]) + y = float(line[3 + 5 * i]) + w = float(line[4 + 5 * i]) + h = float(line[5 + 5 * i]) + c = int(line[6 + 5 * i]) + if w <= 0 or h <= 0: + continue + box.append([x, y, x + w, y + h]) + label.append(c) + if len(box) > 0: + self.fnames.append(line[0]) + self.boxes.append(box) + self.labels.append(label) + + self.num_samples = len(self.boxes) + + def __len__(self): + return self.num_samples + + def __getitem__(self, index): + img, target, h, w = self.pull_item(index) + return img, target + + def pull_item(self, index): + while True: + image_path = self.fnames[index] + img = Image.open(image_path) + #img = cv2.imread(image_path) + + img = img.convert('RGB') + im_width, im_height = img.size + #im_width, im_height = img.shape[0],img.shape[1] + boxes = self.annotransform( + np.array(self.boxes[index]), im_width, im_height) + label = np.array(self.labels[index]) + bbox_labels = np.hstack((label[:, np.newaxis], boxes)).tolist() + img, sample_labels = preprocess( + img, bbox_labels, self.mode, image_path) + sample_labels = np.array(sample_labels) + if len(sample_labels) > 0: + target = np.hstack( + (sample_labels[:, 1:], sample_labels[:, 0][:, np.newaxis])) + + assert (target[:, 2] > target[:, 0]).any() + assert (target[:, 3] > target[:, 1]).any() + break + else: + index = random.randrange(0, self.num_samples) + return torch.from_numpy(img), target, im_height, im_width + + + def annotransform(self, boxes, im_width, im_height): + boxes[:, 0] /= im_width + boxes[:, 1] /= im_height + boxes[:, 2] /= im_width + boxes[:, 3] /= im_height + return boxes + + +def detection_collate(batch): + """Custom collate fn for dealing with batches of images that have a different + number of associated object annotations (bounding boxes). + + Arguments: + batch: (tuple) A tuple of tensor images and lists of annotations + + Return: + A tuple containing: + 1) (tensor) batch of images stacked on their 0 dim + 2) (list of tensors) annotations for a given image are stacked on + 0 dim + """ + targets = [] + imgs = [] + for sample in batch: + imgs.append(sample[0]) + targets.append(torch.FloatTensor(sample[1])) + return torch.stack(imgs, 0), targets + + +if __name__ == '__main__': + from config import cfg + dataset = WIDERDetection(cfg.FACE_TRAIN_FILE) + dataset.pull_item(14) diff --git a/ACL_PyTorch/contrib/cv/detection/DSFD/dsfd_preprocess.py b/ACL_PyTorch/contrib/cv/detection/DSFD/dsfd_preprocess.py index 2bf581b94001abfc491972850eef3bc0cd494dcd..78a886cbf4ef129e75ed8ab2ed8761c965c9c4d8 100644 --- a/ACL_PyTorch/contrib/cv/detection/DSFD/dsfd_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/DSFD/dsfd_preprocess.py @@ -1,64 +1,64 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#coding=utf-8 - -import os -from PIL import Image -import numpy as np -from glob import glob -from torchvision import datasets, transforms -import argparse - -parser = argparse.ArgumentParser(description="trans pth to onnx usage") -parser.add_argument( '--src_path', type=str, default='/home/datasets/WIDERFace/WIDER_val/images/', help='Default val data location(default: %(default)s)') -args = parser.parse_args() - -def img2bin(src_path, save_path): - preprocess = transforms.Compose([ - transforms.Resize(256, Image.BICUBIC), - transforms.CenterCrop(224), - transforms.ToTensor(), - transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), - ]) - - i = 0 - in_files = os.listdir(src_path) - for file in in_files: - i = i + 1 - print(file, "===",i) - files = os.listdir(src_path + '/' + file) - for re_file in files: - img_file = src_path + "/" + file + "/" + re_file - input_image = Image.open(img_file).convert('RGB') - input_tensor = preprocess(input_image) - img = np.array(input_tensor).astype(np.float32) - img.tofile(os.path.join(save_path, re_file.split('.')[0] + ".bin")) - -def bin2info(bin_dir, info_data, width, height): - bin_images = glob(os.path.join(bin_dir, '*.bin')) - with open(info_data, 'w') as file: - for index, img in enumerate(bin_images): - print('str(index)',str(index), 'img', img) - img = "./bin_out" + img.split("bin_out")[1] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - -if __name__ == "__main__": - - bin_path = "./bin_out/" - info_path = "info_result.info" - img2bin(args.src_path, bin_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#coding=utf-8 + +import os +from PIL import Image +import numpy as np +from glob import glob +from torchvision import datasets, transforms +import argparse + +parser = argparse.ArgumentParser(description="trans pth to onnx usage") +parser.add_argument( '--src_path', type=str, default='/home/datasets/WIDERFace/WIDER_val/images/', help='Default val data location(default: %(default)s)') +args = parser.parse_args() + +def img2bin(src_path, save_path): + preprocess = transforms.Compose([ + transforms.Resize(256, Image.BICUBIC), + transforms.CenterCrop(224), + transforms.ToTensor(), + transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), + ]) + + i = 0 + in_files = os.listdir(src_path) + for file in in_files: + i = i + 1 + print(file, "===",i) + files = os.listdir(src_path + '/' + file) + for re_file in files: + img_file = src_path + "/" + file + "/" + re_file + input_image = Image.open(img_file).convert('RGB') + input_tensor = preprocess(input_image) + img = np.array(input_tensor).astype(np.float32) + img.tofile(os.path.join(save_path, re_file.split('.')[0] + ".bin")) + +def bin2info(bin_dir, info_data, width, height): + bin_images = glob(os.path.join(bin_dir, '*.bin')) + with open(info_data, 'w') as file: + for index, img in enumerate(bin_images): + print('str(index)',str(index), 'img', img) + img = "./bin_out" + img.split("bin_out")[1] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + +if __name__ == "__main__": + + bin_path = "./bin_out/" + info_path = "info_result.info" + img2bin(args.src_path, bin_path) bin2info(bin_path, info_path,224,224) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/DSFD/eval_tools/dsfd_acc_eval.py b/ACL_PyTorch/contrib/cv/detection/DSFD/eval_tools/dsfd_acc_eval.py index 7ccd8164bd969ec55991eeda606101ed5a43156d..b512b1556f57ad20832ea2effebc690cb498b45a 100644 --- a/ACL_PyTorch/contrib/cv/detection/DSFD/eval_tools/dsfd_acc_eval.py +++ b/ACL_PyTorch/contrib/cv/detection/DSFD/eval_tools/dsfd_acc_eval.py @@ -1,392 +1,392 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#coding=utf-8 - -import os -import tqdm -import pickle -import argparse -import numpy as np -from scipy.io import loadmat -from bbox import bbox_overlaps -import torch -import time - -#from IPython import embed - -def get_gt_boxes(gt_dir): - """ gt dir: (wider_face_val.mat, wider_easy_val.mat, wider_medium_val.mat, wider_hard_val.mat)""" - - gt_mat = loadmat(os.path.join(gt_dir, 'wider_face_val.mat')) - hard_mat = loadmat(os.path.join(gt_dir, 'wider_hard_val.mat')) - medium_mat = loadmat(os.path.join(gt_dir, 'wider_medium_val.mat')) - easy_mat = loadmat(os.path.join(gt_dir, 'wider_easy_val.mat')) - - facebox_list = gt_mat['face_bbx_list'] - event_list = gt_mat['event_list'] - file_list = gt_mat['file_list'] - - hard_gt_list = hard_mat['gt_list'] - medium_gt_list = medium_mat['gt_list'] - easy_gt_list = easy_mat['gt_list'] - - return facebox_list, event_list, file_list, hard_gt_list, medium_gt_list, easy_gt_list - - -def get_gt_boxes_from_txt(gt_path, cache_dir): - - cache_file = os.path.join(cache_dir, 'gt_cache.pkl') - if os.path.exists(cache_file): - f = open(cache_file, 'rb') - boxes = pickle.load(f) - f.close() - return boxes - - f = open(gt_path, 'r') - state = 0 - lines = f.readlines() - lines = list(map(lambda x: x.rstrip('\r\n'), lines)) - boxes = {} - print(len(lines)) - f.close() - current_boxes = [] - current_name = None - for line in lines: - if state == 0 and '--' in line: - state = 1 - current_name = line - continue - if state == 1: - state = 2 - continue - - if state == 2 and '--' in line: - state = 1 - boxes[current_name] = np.array(current_boxes).astype('float32') - current_name = line - current_boxes = [] - continue - - if state == 2: - box = [float(x) for x in line.split(' ')[:4]] - current_boxes.append(box) - continue - - f = open(cache_file, 'wb') - pickle.dump(boxes, f) - f.close() - return boxes - - -def read_pred_file(filepath): - with open(filepath, 'r') as f: - try: - lines = f.readlines() - img_file = filepath.split('/')[-1] #改写 - #lines = lines[2:] - except Exception as e: - print(str(e)) - - boxes = [] - for line in lines: - line = line.rstrip('\r\n').split(' ') - if line[0] is '': - continue - # a = float(line[4]) - boxes.append([float(line[0]), float(line[1]), float(line[2]), float(line[3]), float(line[4])]) - boxes = np.array(boxes) - # boxes = np.array(list(map(lambda x: [float(a) for a in x.rstrip('\r\n').split(' ')], lines))).astype('float') - return img_file.split('.')[0], boxes - -def get_preds(pred_dir): - events = os.listdir(pred_dir) - boxes = dict() - pbar = tqdm.tqdm(events, ncols=100) - pbar.set_description('Reading Predictions') - for event in pbar: - current_event = dict() - imgname, _boxes = read_pred_file(os.path.join(pred_dir, event)) - current_event[imgname.rstrip('.jpg')] = _boxes - boxes[event] = current_event - return boxes - - -def norm_score(pred): - """ norm score - pred {key: [[x1,y1,x2,y2,s]]} - """ - - max_score = 0 - min_score = 1 - - for _, k in pred.items(): - for _, v in k.items(): - if len(v) == 0: - continue - _min = np.min(v[:, -1]) - _max = np.max(v[:, -1]) - max_score = max(_max, max_score) - min_score = min(_min, min_score) - - diff = max_score - min_score - for _, k in pred.items(): - for _, v in k.items(): - if len(v) == 0: - continue - v[:, -1] = (v[:, -1] - min_score)/diff - - -def image_eval(pred, gt, ignore, iou_thresh): - """ single image evaluation - pred: Nx5 - gt: Nx4 - ignore: - """ - - _pred = list(pred.copy().values()) - _gt = gt.copy() - pred_recall = [] - recall_list = np.zeros(_gt.shape[0]) - proposal_list = np.ones((1,5)) - - _pred[:2] = _pred[:2] + _pred[:0] - _pred[:3] = _pred[:3] + _pred[:1] - _gt[:, 2] = _gt[:, 2] + _gt[:, 0] - _gt[:, 3] = _gt[:, 3] + _gt[:, 1] - - overlaps = bbox_overlaps(np.squeeze(np.array(_pred[:4]), axis=1), _gt) - for h in range(len(_pred)): - gt_overlap = overlaps[h] - max_overlap, max_idx = gt_overlap.max(), gt_overlap.argmax() - if max_overlap >= iou_thresh: - if ignore[max_idx] == 0: - recall_list[max_idx] = -1 - proposal_list[h] = -1 - elif recall_list[max_idx] == 0: - recall_list[max_idx] = 1 - r_keep_index = np.where(recall_list == 1)[0] - pred_recall.append(len(list(r_keep_index))) - return pred_recall, proposal_list - - -def img_pr_info(thresh_num, pred_info, proposal_list, pred_recall): - pr_info = np.zeros((thresh_num, 2)).astype('float') - pred_info = list(pred_info.copy().values()) - - for t in range(thresh_num): - thresh = 1 - (t+1)/thresh_num - r_index = np.where(np.array(pred_info[:4]) >= thresh) - if len(r_index) == 0: - pr_info[t, 0] = 0 - pr_info[t, 1] = 0 - else: - pr_info[t, 0] = 1 - pr_info[t, 1] = 1 - return pr_info - -def dataset_pr_info(thresh_num, pr_curve, count_face): - _pr_curve = np.zeros((thresh_num, 2)) - for i in range(thresh_num): - _pr_curve[i, 0] = pr_curve[i, 1] / pr_curve[i, 0] - _pr_curve[i, 1] = pr_curve[i, 1] / count_face - return _pr_curve - -def reprocess(res): - for i in range(len(res)): - if res[i] >= 0.3: - res[i] *= 2.93 - elif res[i] >= 0.15: - res[i] *= 5.5 - else: - res[i] *= 12.3 - return res - -def voc_ap(repr): - # correct AP calculation - # first append sentinel values at the end - aps = [] - for id in range(len(repr)): - # compute the precision envelope - if id == 0: - rec = [elem*6*1135 for elem in repr[id][0][0]] - elif id == 1: - rec = [elem*6*2075 for elem in repr[id][0][0]] - else: - rec = [elem*6*4605 for elem in repr[id][0][0]] - prec = repr[id][0][1] - mrec = np.concatenate(([0.], rec, [1.])) - mpre = np.concatenate(([0.], prec, [0.])) - - for i in range(mpre.size - 1, 0, -1): - mpre[i - 1] = np.maximum(mpre[i - 1], mpre[i]) - i = np.where(mrec[1:] != mrec[:-1])[0] - ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1]) - aps.append(ap) - return aps - -def bbox_vote(det): - order = det[:, 4].ravel().argsort()[::-1] - det = det[order, :] - dets = np.zeros((0, 5), dtype=np.float32) - while det.shape[0] > 0: - # IOU - area = (det[:, 2] - det[:, 0] + 1) * (det[:, 3] - det[:, 1] + 1) - xx1 = np.maximum(det[0, 0], det[:, 0]) - yy1 = np.maximum(det[0, 1], det[:, 1]) - xx2 = np.minimum(det[0, 2], det[:, 2]) - yy2 = np.minimum(det[0, 3], det[:, 3]) - w = np.maximum(0.0, xx1 - xx2 + 1) - h = np.maximum(0.0, yy2 - yy1 + 1) - inter = w * h - o = inter / (area[0] + area[:] - inter) - - # get needed merge det and delete these det - merge_index = np.where(o >= 0.3)[0] #o>=0.3 - - det_accu = det[merge_index, :] - det = np.delete(det, merge_index, 0) - - if merge_index.shape[0] <= 1: - break - det_accu[:, 0:4] = det_accu[:, 0:4] * np.tile(det_accu[:, -1:], (1, 4)) - max_score = np.max(det_accu[:, 4]) - det_accu_sum = np.zeros((1, 5)) - det_accu_sum[:, 0:4] = np.sum( - det_accu[:, 0:4], axis=0) / np.sum(det_accu[:, -1:]) - det_accu_sum[:, 4] = max_score - try: - dets = np.row_stack((dets, det_accu_sum)) - except: - dets = det_accu_sum - - dets = dets[0:750, :] - return dets - -def tensor2txt(det, called_file): - dets = bbox_vote(det) - fout = os.path.join(args.save_path, called_file.split('/')[-1]) - if not os.path.exists(fout): - os.system(r"touch {}".format(fout)) - fout = open(fout ,'w') - - for i in range(dets.shape[0]): - xmin = dets[i][0] - ymin = dets[i][1] - xmax = dets[i][2] - ymax = dets[i][3] - score = dets[i][4] - fout.write('{:.1f} {:.1f} {:.1f} {:.1f} {:.3f}\n'.format(xmin, ymin, (xmax - xmin + 1), (ymax - ymin + 1), score)) - - -def file2tensor(annotation_file): - filelist = os.listdir(annotation_file) - for annfile in filelist: - if annfile.endswith('_1.txt'): - print("process:", annfile) - called_file = annfile - annfile = os.path.join(annotation_file,annfile) - size = os.path.getsize(annfile) - res = [] - L = int(size / 4) - annfile = open(annfile, 'r+').readlines() - res = annfile[0].strip().split(' ') - res = list(map(float, res))[:390] - sum = 0.0 - for elem in res: - try: - sum += elem - except Exception as e: - print(str(e)) - dim_res = np.array(res).reshape(1, 2, -1, 5) - tensor_res = torch.tensor(dim_res, dtype=torch.float32) - detections = tensor_res - img = torch.randn([640,640]) - det_conf = detections[0, 1, :, 0] - shrink = 1 - det_xmin = img.shape[1] * detections[0, 1, :, 1] / shrink - det_ymin = img.shape[0] * detections[0, 1, :, 2] / shrink - det_xmax = img.shape[1] * detections[0, 1, :, 3] / shrink - det_ymax = img.shape[0] * detections[0, 1, :, 4] / shrink - det = np.column_stack((det_xmin, det_ymin, det_xmax, det_ymax, det_conf)) - - keep_index = np.where(det[:, 4] >= args.thresh)[0] - det = det[keep_index, :] - tensor2txt(det, called_file) - - -def evaluation(pred, gt_path, iou_thresh=0.5): - facebox_list, event_list, file_list, hard_gt_list, medium_gt_list, easy_gt_list = get_gt_boxes(gt_path) - event_num = len(event_list) - thresh_num = 1000 - settings = ['easy', 'medium', 'hard'] - setting_gts = [easy_gt_list, medium_gt_list, hard_gt_list] - file2tensor(pred) - pred = get_preds(args.save_path) - norm_score(pred) - repr = [] - - for setting_id in range(len(settings)): - # different setting - gt_list = setting_gts[setting_id] - count_face = 0 - pr_curve = np.zeros((thresh_num, 2)).astype('float') - tmp_inf = [] - # [hard, medium, easy] - pbar = tqdm.tqdm(range(event_num), ncols=100) - pbar.set_description('Processing {}'.format(settings[setting_id])) - for i in pbar: - img_list = file_list[i][0] - sub_gt_list = gt_list[i][0] - gt_bbx_list = facebox_list[i][0] - for j in range(len(img_list)): - pred_info = pred[str(img_list[j][0][0])+'_1.txt'] - gt_boxes = gt_bbx_list[j][0].astype('float') - keep_index = sub_gt_list[j][0] - count_face += len(keep_index) - if len(gt_boxes) == 0 or len(pred_info) == 0: - continue - ignore = np.zeros(gt_boxes.shape[0]) - if len(keep_index) != 0: - ignore[keep_index-1] = 1 - try: - pred_recall, proposal_list = image_eval(pred_info, gt_boxes, ignore, iou_thresh) - _img_pr_info = img_pr_info(thresh_num, pred_info, proposal_list, pred_recall) - pr_curve += _img_pr_info - except: - pass - pr_curve = dataset_pr_info(thresh_num, pr_curve, count_face) - - recall = pr_curve[:, 1] - propose = pr_curve[:, 0] - tmp_inf.append([recall,propose]) - repr.append(tmp_inf) - aps = voc_ap(repr) - - print(time.asctime( time.localtime(time.time()))) - print("==================== Results ====================") - print("Easy Val AP: {}".format(aps[0])) - print("Medium Val AP: {}".format(aps[1])) - print("Hard Val AP: {}".format(aps[2])) - print("=================================================") - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('-p', '--pred', default="../result/dumpOutput_device0/") - parser.add_argument('-g', '--gt', default='./ground_truth/') - parser.add_argument('--thresh', default=0.05, type=float, help='Final confidence threshold') - parser.add_argument('-save_path', default='./infer_results/', help='Final confidence threshold') - args = parser.parse_args() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#coding=utf-8 + +import os +import tqdm +import pickle +import argparse +import numpy as np +from scipy.io import loadmat +from bbox import bbox_overlaps +import torch +import time + +#from IPython import embed + +def get_gt_boxes(gt_dir): + """ gt dir: (wider_face_val.mat, wider_easy_val.mat, wider_medium_val.mat, wider_hard_val.mat)""" + + gt_mat = loadmat(os.path.join(gt_dir, 'wider_face_val.mat')) + hard_mat = loadmat(os.path.join(gt_dir, 'wider_hard_val.mat')) + medium_mat = loadmat(os.path.join(gt_dir, 'wider_medium_val.mat')) + easy_mat = loadmat(os.path.join(gt_dir, 'wider_easy_val.mat')) + + facebox_list = gt_mat['face_bbx_list'] + event_list = gt_mat['event_list'] + file_list = gt_mat['file_list'] + + hard_gt_list = hard_mat['gt_list'] + medium_gt_list = medium_mat['gt_list'] + easy_gt_list = easy_mat['gt_list'] + + return facebox_list, event_list, file_list, hard_gt_list, medium_gt_list, easy_gt_list + + +def get_gt_boxes_from_txt(gt_path, cache_dir): + + cache_file = os.path.join(cache_dir, 'gt_cache.pkl') + if os.path.exists(cache_file): + f = open(cache_file, 'rb') + boxes = pickle.load(f) + f.close() + return boxes + + f = open(gt_path, 'r') + state = 0 + lines = f.readlines() + lines = list(map(lambda x: x.rstrip('\r\n'), lines)) + boxes = {} + print(len(lines)) + f.close() + current_boxes = [] + current_name = None + for line in lines: + if state == 0 and '--' in line: + state = 1 + current_name = line + continue + if state == 1: + state = 2 + continue + + if state == 2 and '--' in line: + state = 1 + boxes[current_name] = np.array(current_boxes).astype('float32') + current_name = line + current_boxes = [] + continue + + if state == 2: + box = [float(x) for x in line.split(' ')[:4]] + current_boxes.append(box) + continue + + f = open(cache_file, 'wb') + pickle.dump(boxes, f) + f.close() + return boxes + + +def read_pred_file(filepath): + with open(filepath, 'r') as f: + try: + lines = f.readlines() + img_file = filepath.split('/')[-1] #改写 + #lines = lines[2:] + except Exception as e: + print(str(e)) + + boxes = [] + for line in lines: + line = line.rstrip('\r\n').split(' ') + if line[0] is '': + continue + # a = float(line[4]) + boxes.append([float(line[0]), float(line[1]), float(line[2]), float(line[3]), float(line[4])]) + boxes = np.array(boxes) + # boxes = np.array(list(map(lambda x: [float(a) for a in x.rstrip('\r\n').split(' ')], lines))).astype('float') + return img_file.split('.')[0], boxes + +def get_preds(pred_dir): + events = os.listdir(pred_dir) + boxes = dict() + pbar = tqdm.tqdm(events, ncols=100) + pbar.set_description('Reading Predictions') + for event in pbar: + current_event = dict() + imgname, _boxes = read_pred_file(os.path.join(pred_dir, event)) + current_event[imgname.rstrip('.jpg')] = _boxes + boxes[event] = current_event + return boxes + + +def norm_score(pred): + """ norm score + pred {key: [[x1,y1,x2,y2,s]]} + """ + + max_score = 0 + min_score = 1 + + for _, k in pred.items(): + for _, v in k.items(): + if len(v) == 0: + continue + _min = np.min(v[:, -1]) + _max = np.max(v[:, -1]) + max_score = max(_max, max_score) + min_score = min(_min, min_score) + + diff = max_score - min_score + for _, k in pred.items(): + for _, v in k.items(): + if len(v) == 0: + continue + v[:, -1] = (v[:, -1] - min_score)/diff + + +def image_eval(pred, gt, ignore, iou_thresh): + """ single image evaluation + pred: Nx5 + gt: Nx4 + ignore: + """ + + _pred = list(pred.copy().values()) + _gt = gt.copy() + pred_recall = [] + recall_list = np.zeros(_gt.shape[0]) + proposal_list = np.ones((1,5)) + + _pred[:2] = _pred[:2] + _pred[:0] + _pred[:3] = _pred[:3] + _pred[:1] + _gt[:, 2] = _gt[:, 2] + _gt[:, 0] + _gt[:, 3] = _gt[:, 3] + _gt[:, 1] + + overlaps = bbox_overlaps(np.squeeze(np.array(_pred[:4]), axis=1), _gt) + for h in range(len(_pred)): + gt_overlap = overlaps[h] + max_overlap, max_idx = gt_overlap.max(), gt_overlap.argmax() + if max_overlap >= iou_thresh: + if ignore[max_idx] == 0: + recall_list[max_idx] = -1 + proposal_list[h] = -1 + elif recall_list[max_idx] == 0: + recall_list[max_idx] = 1 + r_keep_index = np.where(recall_list == 1)[0] + pred_recall.append(len(list(r_keep_index))) + return pred_recall, proposal_list + + +def img_pr_info(thresh_num, pred_info, proposal_list, pred_recall): + pr_info = np.zeros((thresh_num, 2)).astype('float') + pred_info = list(pred_info.copy().values()) + + for t in range(thresh_num): + thresh = 1 - (t+1)/thresh_num + r_index = np.where(np.array(pred_info[:4]) >= thresh) + if len(r_index) == 0: + pr_info[t, 0] = 0 + pr_info[t, 1] = 0 + else: + pr_info[t, 0] = 1 + pr_info[t, 1] = 1 + return pr_info + +def dataset_pr_info(thresh_num, pr_curve, count_face): + _pr_curve = np.zeros((thresh_num, 2)) + for i in range(thresh_num): + _pr_curve[i, 0] = pr_curve[i, 1] / pr_curve[i, 0] + _pr_curve[i, 1] = pr_curve[i, 1] / count_face + return _pr_curve + +def reprocess(res): + for i in range(len(res)): + if res[i] >= 0.3: + res[i] *= 2.93 + elif res[i] >= 0.15: + res[i] *= 5.5 + else: + res[i] *= 12.3 + return res + +def voc_ap(repr): + # correct AP calculation + # first append sentinel values at the end + aps = [] + for id in range(len(repr)): + # compute the precision envelope + if id == 0: + rec = [elem*6*1135 for elem in repr[id][0][0]] + elif id == 1: + rec = [elem*6*2075 for elem in repr[id][0][0]] + else: + rec = [elem*6*4605 for elem in repr[id][0][0]] + prec = repr[id][0][1] + mrec = np.concatenate(([0.], rec, [1.])) + mpre = np.concatenate(([0.], prec, [0.])) + + for i in range(mpre.size - 1, 0, -1): + mpre[i - 1] = np.maximum(mpre[i - 1], mpre[i]) + i = np.where(mrec[1:] != mrec[:-1])[0] + ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1]) + aps.append(ap) + return aps + +def bbox_vote(det): + order = det[:, 4].ravel().argsort()[::-1] + det = det[order, :] + dets = np.zeros((0, 5), dtype=np.float32) + while det.shape[0] > 0: + # IOU + area = (det[:, 2] - det[:, 0] + 1) * (det[:, 3] - det[:, 1] + 1) + xx1 = np.maximum(det[0, 0], det[:, 0]) + yy1 = np.maximum(det[0, 1], det[:, 1]) + xx2 = np.minimum(det[0, 2], det[:, 2]) + yy2 = np.minimum(det[0, 3], det[:, 3]) + w = np.maximum(0.0, xx1 - xx2 + 1) + h = np.maximum(0.0, yy2 - yy1 + 1) + inter = w * h + o = inter / (area[0] + area[:] - inter) + + # get needed merge det and delete these det + merge_index = np.where(o >= 0.3)[0] #o>=0.3 + + det_accu = det[merge_index, :] + det = np.delete(det, merge_index, 0) + + if merge_index.shape[0] <= 1: + break + det_accu[:, 0:4] = det_accu[:, 0:4] * np.tile(det_accu[:, -1:], (1, 4)) + max_score = np.max(det_accu[:, 4]) + det_accu_sum = np.zeros((1, 5)) + det_accu_sum[:, 0:4] = np.sum( + det_accu[:, 0:4], axis=0) / np.sum(det_accu[:, -1:]) + det_accu_sum[:, 4] = max_score + try: + dets = np.row_stack((dets, det_accu_sum)) + except: + dets = det_accu_sum + + dets = dets[0:750, :] + return dets + +def tensor2txt(det, called_file): + dets = bbox_vote(det) + fout = os.path.join(args.save_path, called_file.split('/')[-1]) + if not os.path.exists(fout): + os.system(r"touch {}".format(fout)) + fout = open(fout ,'w') + + for i in range(dets.shape[0]): + xmin = dets[i][0] + ymin = dets[i][1] + xmax = dets[i][2] + ymax = dets[i][3] + score = dets[i][4] + fout.write('{:.1f} {:.1f} {:.1f} {:.1f} {:.3f}\n'.format(xmin, ymin, (xmax - xmin + 1), (ymax - ymin + 1), score)) + + +def file2tensor(annotation_file): + filelist = os.listdir(annotation_file) + for annfile in filelist: + if annfile.endswith('_1.txt'): + print("process:", annfile) + called_file = annfile + annfile = os.path.join(annotation_file,annfile) + size = os.path.getsize(annfile) + res = [] + L = int(size / 4) + annfile = open(annfile, 'r+').readlines() + res = annfile[0].strip().split(' ') + res = list(map(float, res))[:390] + sum = 0.0 + for elem in res: + try: + sum += elem + except Exception as e: + print(str(e)) + dim_res = np.array(res).reshape(1, 2, -1, 5) + tensor_res = torch.tensor(dim_res, dtype=torch.float32) + detections = tensor_res + img = torch.randn([640,640]) + det_conf = detections[0, 1, :, 0] + shrink = 1 + det_xmin = img.shape[1] * detections[0, 1, :, 1] / shrink + det_ymin = img.shape[0] * detections[0, 1, :, 2] / shrink + det_xmax = img.shape[1] * detections[0, 1, :, 3] / shrink + det_ymax = img.shape[0] * detections[0, 1, :, 4] / shrink + det = np.column_stack((det_xmin, det_ymin, det_xmax, det_ymax, det_conf)) + + keep_index = np.where(det[:, 4] >= args.thresh)[0] + det = det[keep_index, :] + tensor2txt(det, called_file) + + +def evaluation(pred, gt_path, iou_thresh=0.5): + facebox_list, event_list, file_list, hard_gt_list, medium_gt_list, easy_gt_list = get_gt_boxes(gt_path) + event_num = len(event_list) + thresh_num = 1000 + settings = ['easy', 'medium', 'hard'] + setting_gts = [easy_gt_list, medium_gt_list, hard_gt_list] + file2tensor(pred) + pred = get_preds(args.save_path) + norm_score(pred) + repr = [] + + for setting_id in range(len(settings)): + # different setting + gt_list = setting_gts[setting_id] + count_face = 0 + pr_curve = np.zeros((thresh_num, 2)).astype('float') + tmp_inf = [] + # [hard, medium, easy] + pbar = tqdm.tqdm(range(event_num), ncols=100) + pbar.set_description('Processing {}'.format(settings[setting_id])) + for i in pbar: + img_list = file_list[i][0] + sub_gt_list = gt_list[i][0] + gt_bbx_list = facebox_list[i][0] + for j in range(len(img_list)): + pred_info = pred[str(img_list[j][0][0])+'_1.txt'] + gt_boxes = gt_bbx_list[j][0].astype('float') + keep_index = sub_gt_list[j][0] + count_face += len(keep_index) + if len(gt_boxes) == 0 or len(pred_info) == 0: + continue + ignore = np.zeros(gt_boxes.shape[0]) + if len(keep_index) != 0: + ignore[keep_index-1] = 1 + try: + pred_recall, proposal_list = image_eval(pred_info, gt_boxes, ignore, iou_thresh) + _img_pr_info = img_pr_info(thresh_num, pred_info, proposal_list, pred_recall) + pr_curve += _img_pr_info + except: + pass + pr_curve = dataset_pr_info(thresh_num, pr_curve, count_face) + + recall = pr_curve[:, 1] + propose = pr_curve[:, 0] + tmp_inf.append([recall,propose]) + repr.append(tmp_inf) + aps = voc_ap(repr) + + print(time.asctime( time.localtime(time.time()))) + print("==================== Results ====================") + print("Easy Val AP: {}".format(aps[0])) + print("Medium Val AP: {}".format(aps[1])) + print("Hard Val AP: {}".format(aps[2])) + print("=================================================") + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('-p', '--pred', default="../result/dumpOutput_device0/") + parser.add_argument('-g', '--gt', default='./ground_truth/') + parser.add_argument('--thresh', default=0.05, type=float, help='Final confidence threshold') + parser.add_argument('-save_path', default='./infer_results/', help='Final confidence threshold') + args = parser.parse_args() evaluation(args.pred, args.gt) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/DSFD/requirements.txt b/ACL_PyTorch/contrib/cv/detection/DSFD/requirements.txt index bf12959916f03c54d92b5926c818833539d77a42..994f395c0467a4a18a56ae3c3acdc1e931cf2cf4 100644 --- a/ACL_PyTorch/contrib/cv/detection/DSFD/requirements.txt +++ b/ACL_PyTorch/contrib/cv/detection/DSFD/requirements.txt @@ -1,9 +1,9 @@ -torch==1.5.0 -torchvision==0.6.0 -pillow -Cython -easydict -scipy==1.7.2 -opencv-python==4.5.3.56 -numpy -tqdm==4.62.2 +torch==1.5.0 +torchvision==0.6.0 +pillow +Cython +easydict +scipy==1.7.2 +opencv-python==4.5.3.56 +numpy +tqdm==4.62.2 diff --git a/ACL_PyTorch/contrib/cv/detection/DSFD/test/dsfd_pth2onnx.py b/ACL_PyTorch/contrib/cv/detection/DSFD/test/dsfd_pth2onnx.py index dbe7e85598af16bbde098cafc80d20e71c60f0d1..f8deb52e3f1882825797a50d4f3d56938545f9e8 100644 --- a/ACL_PyTorch/contrib/cv/detection/DSFD/test/dsfd_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/DSFD/test/dsfd_pth2onnx.py @@ -1,67 +1,67 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#coding=utf-8 -#torch.__version >= 1.3.0 -import sys -sys.path.append("..") - -import torch.onnx -from models.factory import build_net -import argparse - - -parser = argparse.ArgumentParser(description="trans pth to onnx usage") -parser.add_argument( '--model_path', type=str, default='../dsfd.pth', help='Default ph model location(default: %(default)s)') -args = parser.parse_args() - - -#Function to Convert to ONNX -def Convert_ONNX(model): - print("enter Convert_ONNX") - - # set the model to inference mode - model.eval() - - # 构建输入信息和输出信息 - input_names = ["image"] - output_names = ["modelOutput1", "modelOutput2", "modelOutput3", "modelOutput4", "modelOutput5", "modelOutput6"] - #dynamic_axes = {'image': {0: '4'}, 'modelOutput': {0: '-1'}} - dynamic_axes = {'image': {0: '4'}, 'modelOutput1': {0: '4'}, 'modelOutput2': {0: '4'}, 'modelOutput3': {0: '4'}, - 'modelOutput4': {0: '4'}, 'modelOutput5': {0: '4'},'modelOutput6': {0: '4'}} - #dynamic_axes = {'image': {0: '4'}, 'modelOutput': {0: '4'}} - dummy_input = torch.randn(4, 3, 224, 224) - - # 开始转换 - torch.onnx.export(model, - dummy_input, - "dsfd.onnx", - input_names=input_names, - dynamic_axes=dynamic_axes, - output_names=output_names, - opset_version=11, - verbose=True) - print("*************Convert to ONNX model file SUCCESS!*************") - - -if __name__ == '__main__': - - model = build_net('train', 2, 'resnet152') - model.load_state_dict(torch.load(args.model_path, map_location=torch.device('cpu'))) - Convert_ONNX(model) - - - - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#coding=utf-8 +#torch.__version >= 1.3.0 +import sys +sys.path.append("..") + +import torch.onnx +from models.factory import build_net +import argparse + + +parser = argparse.ArgumentParser(description="trans pth to onnx usage") +parser.add_argument( '--model_path', type=str, default='../dsfd.pth', help='Default ph model location(default: %(default)s)') +args = parser.parse_args() + + +#Function to Convert to ONNX +def Convert_ONNX(model): + print("enter Convert_ONNX") + + # set the model to inference mode + model.eval() + + # 构建输入信息和输出信息 + input_names = ["image"] + output_names = ["modelOutput1", "modelOutput2", "modelOutput3", "modelOutput4", "modelOutput5", "modelOutput6"] + #dynamic_axes = {'image': {0: '4'}, 'modelOutput': {0: '-1'}} + dynamic_axes = {'image': {0: '4'}, 'modelOutput1': {0: '4'}, 'modelOutput2': {0: '4'}, 'modelOutput3': {0: '4'}, + 'modelOutput4': {0: '4'}, 'modelOutput5': {0: '4'},'modelOutput6': {0: '4'}} + #dynamic_axes = {'image': {0: '4'}, 'modelOutput': {0: '4'}} + dummy_input = torch.randn(4, 3, 224, 224) + + # 开始转换 + torch.onnx.export(model, + dummy_input, + "dsfd.onnx", + input_names=input_names, + dynamic_axes=dynamic_axes, + output_names=output_names, + opset_version=11, + verbose=True) + print("*************Convert to ONNX model file SUCCESS!*************") + + +if __name__ == '__main__': + + model = build_net('train', 2, 'resnet152') + model.load_state_dict(torch.load(args.model_path, map_location=torch.device('cpu'))) + Convert_ONNX(model) + + + + + diff --git a/ACL_PyTorch/contrib/cv/detection/Deepspeech/README.md b/ACL_PyTorch/contrib/cv/detection/Deepspeech/README.md index 431abb974e76236b139c26b99d483f972ca56cf8..f441c12e87be4714f7fd7c4a416820e69f8975b2 100644 --- a/ACL_PyTorch/contrib/cv/detection/Deepspeech/README.md +++ b/ACL_PyTorch/contrib/cv/detection/Deepspeech/README.md @@ -1,253 +1,253 @@ -# DeepSpeech模型PyTorch离线推理指导 -- [1 环境说明](#1-环境说明) - - [1.1 环境搭建与使用说明](#11-环境搭建与使用说明) -- [2 推理流程](#2-推理流程) - - [2.1 获取开源PyTorch模型代码与权重文件](#21-获取开源PyTorch模型代码与权重文件) - - [2.2 导出onnx模型](#22-导出onnx模型) - - [2.3 转换为om模型](#23-转换为om模型) - - [2.4 数据集处理](#24-数据集处理) - - [2.5 离线推理](#25-离线推理) -- [3 精度统计](#3-精度统计) - - [3.1 离线推理精度](#31-离线推理精度) - - [3.2 精度对比](#32-精度对比) -- [4 性能对比](#4-性能对比) - - [4.1 npu性能数据](#41-npu性能数据) - - [4.2 gpu性能数据](#42-gpu性能数据) - - [4.3 性能数据对比](#43-性能数据对比) - - - - -## 1 环境说明 - -- **[环境搭建与使用说明](#11-环境搭建与使用说明)** - - -### 1.1 环境搭建与使用说明 - - -深度学习框架与第三方库 - -``` -python3.7.5 - -torch == 1.8.0 -torchaudio == 0.8.0 -torchvision == 0.9.0 -torchelastic == 0.2.2 - -onnx -onnxruntime -onnxoptimizer - -fairscale -flask -google-cloud-storage -hydra-core -jupyter -librosa -matplotlib -numpy -optuna -pytest -python-levenshtein -pytorch-lightning>=1.1 -scipy -sklearn -sox -tqdm -wget -git+https://github.com/romesco/hydra-lightning/#subdirectory=hydra-configs-pytorch-lightning -``` - -其中apex安装使用pip install会报错,应使用下述方式安装: -``` -git clone https://github.com/NVIDIA/apex.git -cd apex -python3 setup.py install --cpp_ext --cuda_ext -``` - -**说明:** -> -> X86架构:pytorch和torchvision可以通过官方下载whl包安装,其他可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和opencv可以通过github下载源码编译安装,其他可以通过pip3.7 install 包名 安装 -> -> 以上为多数网络需要安装的软件与推荐的版本,根据实际情况安装。如果python脚本运行过程中import 模块失败,安装相应模块即可,如果报错是缺少动态库,网上搜索报错信息找到相应安装包,执行apt-get install 包名安装即可 - - - -## 2 推理流程 - -- **[获取开源PyTorch模型代码与权重文件](#21-获取开源PyTorch模型代码与权重文件)** - -- **[导出onnx模型](#22-导出onnx模型)** - -- **[转换为om模型](#23-转换为om模型)** - -- **[数据集处理](#24-数据集处理)** - -- **[离线推理](#25-离线推理)** - - -### 2.1 获取开源PyTorch模型代码与权重文件 - -#### 2.1.1 基于开源PyTorch框架的Deepspeech开源模型代码 -``` -git clone https://github.com/SeanNaren/deepspeech.pytorch.git -b V3.0 -``` -#### 2.1.2 修改deepspeech.pytorch/deepspeech_pytorch/model.py - -#### 2.1.3 [下载ckpt权重文件](https://github.com/SeanNaren/deepspeech.pytorch/releases/download/V3.0/an4_pretrained_v3.ckpt) -``` -wget https://github.com/SeanNaren/deepspeech.pytorch/releases/download/V3.0/an4_pretrained_v3.ckpt -``` - - -### 2.2 导出onnx模型 - -#### 2.2.1 配置环境变量 - - 将env.sh文件放到根目录下 - - source环境变量 -``` -source env.sh -``` -#### 2.2.2 将ckpt2onnx.py放到根目录下 -#### 2.2.3 执行pth2onnx脚本,生成onnx模型文件 -``` -python3 ckpt2onnx.py --ckpt_path ./an4_pretrained_v3.ckpt --out_file deepspeech.onnx -``` -**说明:** -> -> --ckpt_path:ckpt权重文件 -> --out_file:生成的onnx文件名 -> - - -### 2.3 转换为om模型 - -#### 2.3.1 设置环境变量 -``` -source env.sh -``` -#### 2.3.2 使用Ascend atc工具将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 -``` -atc --framework=5 --model=./deepspeech.onnx --input_format=NCHW --input_shape="spect:1,1,161,621;transcript:1" --output=deepspeech_bs1 --log=debug --soc_version=Ascend310 -``` - - -### 2.4 数据集处理 - -#### 2.4.1 获取数据集 -获取AN4数据集 -``` -cd deepspeech.pytorch/data -python3 an4.py -cd ../.. -``` - -#### 2.4.2 数据预处理 - - 将预处理脚本deepspeech_preprocess.py放到根目录下 - - 执行预处理脚本,生成数据集预处理后的bin文件 -``` -python3 deepspeech_preprocess.py --data_file ./deepspeech.pytorch/data/an4_test_manifest.json --save_path ./deepspeech.pytorch/data/an4_dataset/test --label_file ./deepspeech.pytorch/labels.json -``` -**说明:** -> -> --data_file:存放数据路径的json文件 -> --save_path:预处理产生的bin文件存储路径(会在save_path目录下建立两个文件夹spect和sizes分别存放两组输入文件) -> --label_file: labels文件路径 -> - - -### 2.5 离线推理 - -#### 2.5.1 msame工具概述 -输入.om模型和模型所需要的输入bin文件,输出模型的输出数据文件,支持多次推理(指对同一输入数据进行推理)。 -模型必须是通过atc工具转换的om模型,输入bin文件需要符合模型的输入要求(支持模型多输入)。 -**说明:** -> -> benchmark工具暂不支持多输入,因此改用msame -> -#### 2.5.2 离线推理 - - [获取msame工具](https://gitee.com/ascend/tools/tree/master/msame) - - 执行离线推理 -``` -./msame --model "./deepspeech_bs1.om" --input "./deepspeech.pytorch/data/an4_dataset/test/spect,./deepspeech.pytorch/data/an4_dataset/test/sizes" --output "./deepspeech.pytorch/result" --outfmt TXT - -``` -**说明:** -> -> 将/tools/msame/msame文件复制到根目录下,执行上述命令,或直接在msame文件夹下执行命令,将input、output等路径改为绝对路径 -> 输出保存在--output路径下,会自动生成新文件夹 -> - - - -## 3 精度统计 - -- **[离线推理精度](#31-离线推理精度)** - -- **[精度对比](#32-精度对比)** - - -### 3.1 离线推理精度 - - 将后处理脚本deepspeech_postprocess.py放到根目录下 - - 调用后处理脚本产生推理结果 -``` -python3 deepspeech_postprocess.py --out_path ./deepspeech.pytorch/result --info_path ./deepspeech.pytorch/data/an4_dataset/test --label_file ./deepspeech.pytorch/labels.json -``` -**说明:** -> -> --out_path:离线推理输出的路径,是msame推理后的输出路径 -> --info_path:与执行数据预处理脚本deepspeech_preprocess.py时设置的--save_path一致 -> --label_file: labels文件路径 -> - -### 3.2 精度对比 - -| 模型 | 官网ckpt精度 | 310离线推理精度 | -| :------: | :------: | :------: | -| Deepspeech bs1 | [Average WER 9.573 Average CER 5.515](https://github.com/SeanNaren/deepspeech.pytorch/releases) | Average WER 9.573 Average CER 5.515 | - -**说明:** -> -> 将得到的om离线模型推理精度与该模型github代码仓上公布的精度对比,精度与之一致,故精度达标 -> - - - -## 4 性能对比 - -- **[npu性能数据](#41-npu性能数据)** - -- **[gpu性能数据](#42-gpu性能数据)** - -- **[性能优化](#43-性能优化)** - - -### 4.1 npu性能数据 -由于benchmark工具不支持多输入,改为使用msame进行om的离线推理。msame工具在推理时会输出每条数据运行的时间,计算10条数据运行的时间均值,作为性能的衡量标准。由于msame不支持多batch,因此以bs1的数据为准。 -``` -Run time of each data: 9.09s -performance: 0.11seq/s -``` - -### 4.2 gpu性能数据 -在装有T4卡的服务器上测试gpu性能,在GPU上进行在线推理,取5次运行的平均时长作为性能的衡量标准。 -``` -Run time of each data: 0.28s -performance: 3.44seq/s -``` - -### 4.3 性能优化 -使用性能分析工具profiling,查看了模型中每类算子总体耗时与百分比和模型每个算子的aicore耗时,发现DynamicRNN耗时最多,使用autotune进行性能优化,优化后性能如下: -``` -Run time of each data: 2.03s -performance: 0.49seq/s -``` -在此基础上,对TransData算子进行优化,优化后性能如下: -``` -Run time of each data: 1.41s -performance: 0.71seq/s +# DeepSpeech模型PyTorch离线推理指导 +- [1 环境说明](#1-环境说明) + - [1.1 环境搭建与使用说明](#11-环境搭建与使用说明) +- [2 推理流程](#2-推理流程) + - [2.1 获取开源PyTorch模型代码与权重文件](#21-获取开源PyTorch模型代码与权重文件) + - [2.2 导出onnx模型](#22-导出onnx模型) + - [2.3 转换为om模型](#23-转换为om模型) + - [2.4 数据集处理](#24-数据集处理) + - [2.5 离线推理](#25-离线推理) +- [3 精度统计](#3-精度统计) + - [3.1 离线推理精度](#31-离线推理精度) + - [3.2 精度对比](#32-精度对比) +- [4 性能对比](#4-性能对比) + - [4.1 npu性能数据](#41-npu性能数据) + - [4.2 gpu性能数据](#42-gpu性能数据) + - [4.3 性能数据对比](#43-性能数据对比) + + + + +## 1 环境说明 + +- **[环境搭建与使用说明](#11-环境搭建与使用说明)** + + +### 1.1 环境搭建与使用说明 + + +深度学习框架与第三方库 + +``` +python3.7.5 + +torch == 1.8.0 +torchaudio == 0.8.0 +torchvision == 0.9.0 +torchelastic == 0.2.2 + +onnx +onnxruntime +onnxoptimizer + +fairscale +flask +google-cloud-storage +hydra-core +jupyter +librosa +matplotlib +numpy +optuna +pytest +python-levenshtein +pytorch-lightning>=1.1 +scipy +sklearn +sox +tqdm +wget +git+https://github.com/romesco/hydra-lightning/#subdirectory=hydra-configs-pytorch-lightning +``` + +其中apex安装使用pip install会报错,应使用下述方式安装: +``` +git clone https://github.com/NVIDIA/apex.git +cd apex +python3 setup.py install --cpp_ext --cuda_ext +``` + +**说明:** +> +> X86架构:pytorch和torchvision可以通过官方下载whl包安装,其他可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和opencv可以通过github下载源码编译安装,其他可以通过pip3.7 install 包名 安装 +> +> 以上为多数网络需要安装的软件与推荐的版本,根据实际情况安装。如果python脚本运行过程中import 模块失败,安装相应模块即可,如果报错是缺少动态库,网上搜索报错信息找到相应安装包,执行apt-get install 包名安装即可 + + + +## 2 推理流程 + +- **[获取开源PyTorch模型代码与权重文件](#21-获取开源PyTorch模型代码与权重文件)** + +- **[导出onnx模型](#22-导出onnx模型)** + +- **[转换为om模型](#23-转换为om模型)** + +- **[数据集处理](#24-数据集处理)** + +- **[离线推理](#25-离线推理)** + + +### 2.1 获取开源PyTorch模型代码与权重文件 + +#### 2.1.1 基于开源PyTorch框架的Deepspeech开源模型代码 +``` +git clone https://github.com/SeanNaren/deepspeech.pytorch.git -b V3.0 +``` +#### 2.1.2 修改deepspeech.pytorch/deepspeech_pytorch/model.py + +#### 2.1.3 [下载ckpt权重文件](https://github.com/SeanNaren/deepspeech.pytorch/releases/download/V3.0/an4_pretrained_v3.ckpt) +``` +wget https://github.com/SeanNaren/deepspeech.pytorch/releases/download/V3.0/an4_pretrained_v3.ckpt +``` + + +### 2.2 导出onnx模型 + +#### 2.2.1 配置环境变量 + - 将env.sh文件放到根目录下 + - source环境变量 +``` +source env.sh +``` +#### 2.2.2 将ckpt2onnx.py放到根目录下 +#### 2.2.3 执行pth2onnx脚本,生成onnx模型文件 +``` +python3 ckpt2onnx.py --ckpt_path ./an4_pretrained_v3.ckpt --out_file deepspeech.onnx +``` +**说明:** +> +> --ckpt_path:ckpt权重文件 +> --out_file:生成的onnx文件名 +> + + +### 2.3 转换为om模型 + +#### 2.3.1 设置环境变量 +``` +source env.sh +``` +#### 2.3.2 使用Ascend atc工具将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 +``` +atc --framework=5 --model=./deepspeech.onnx --input_format=NCHW --input_shape="spect:1,1,161,621;transcript:1" --output=deepspeech_bs1 --log=debug --soc_version=Ascend310 +``` + + +### 2.4 数据集处理 + +#### 2.4.1 获取数据集 +获取AN4数据集 +``` +cd deepspeech.pytorch/data +python3 an4.py +cd ../.. +``` + +#### 2.4.2 数据预处理 + - 将预处理脚本deepspeech_preprocess.py放到根目录下 + - 执行预处理脚本,生成数据集预处理后的bin文件 +``` +python3 deepspeech_preprocess.py --data_file ./deepspeech.pytorch/data/an4_test_manifest.json --save_path ./deepspeech.pytorch/data/an4_dataset/test --label_file ./deepspeech.pytorch/labels.json +``` +**说明:** +> +> --data_file:存放数据路径的json文件 +> --save_path:预处理产生的bin文件存储路径(会在save_path目录下建立两个文件夹spect和sizes分别存放两组输入文件) +> --label_file: labels文件路径 +> + + +### 2.5 离线推理 + +#### 2.5.1 msame工具概述 +输入.om模型和模型所需要的输入bin文件,输出模型的输出数据文件,支持多次推理(指对同一输入数据进行推理)。 +模型必须是通过atc工具转换的om模型,输入bin文件需要符合模型的输入要求(支持模型多输入)。 +**说明:** +> +> benchmark工具暂不支持多输入,因此改用msame +> +#### 2.5.2 离线推理 + - [获取msame工具](https://gitee.com/ascend/tools/tree/master/msame) + - 执行离线推理 +``` +./msame --model "./deepspeech_bs1.om" --input "./deepspeech.pytorch/data/an4_dataset/test/spect,./deepspeech.pytorch/data/an4_dataset/test/sizes" --output "./deepspeech.pytorch/result" --outfmt TXT + +``` +**说明:** +> +> 将/tools/msame/msame文件复制到根目录下,执行上述命令,或直接在msame文件夹下执行命令,将input、output等路径改为绝对路径 +> 输出保存在--output路径下,会自动生成新文件夹 +> + + + +## 3 精度统计 + +- **[离线推理精度](#31-离线推理精度)** + +- **[精度对比](#32-精度对比)** + + +### 3.1 离线推理精度 + - 将后处理脚本deepspeech_postprocess.py放到根目录下 + - 调用后处理脚本产生推理结果 +``` +python3 deepspeech_postprocess.py --out_path ./deepspeech.pytorch/result --info_path ./deepspeech.pytorch/data/an4_dataset/test --label_file ./deepspeech.pytorch/labels.json +``` +**说明:** +> +> --out_path:离线推理输出的路径,是msame推理后的输出路径 +> --info_path:与执行数据预处理脚本deepspeech_preprocess.py时设置的--save_path一致 +> --label_file: labels文件路径 +> + +### 3.2 精度对比 + +| 模型 | 官网ckpt精度 | 310离线推理精度 | +| :------: | :------: | :------: | +| Deepspeech bs1 | [Average WER 9.573 Average CER 5.515](https://github.com/SeanNaren/deepspeech.pytorch/releases) | Average WER 9.573 Average CER 5.515 | + +**说明:** +> +> 将得到的om离线模型推理精度与该模型github代码仓上公布的精度对比,精度与之一致,故精度达标 +> + + + +## 4 性能对比 + +- **[npu性能数据](#41-npu性能数据)** + +- **[gpu性能数据](#42-gpu性能数据)** + +- **[性能优化](#43-性能优化)** + + +### 4.1 npu性能数据 +由于benchmark工具不支持多输入,改为使用msame进行om的离线推理。msame工具在推理时会输出每条数据运行的时间,计算10条数据运行的时间均值,作为性能的衡量标准。由于msame不支持多batch,因此以bs1的数据为准。 +``` +Run time of each data: 9.09s +performance: 0.11seq/s +``` + +### 4.2 gpu性能数据 +在装有T4卡的服务器上测试gpu性能,在GPU上进行在线推理,取5次运行的平均时长作为性能的衡量标准。 +``` +Run time of each data: 0.28s +performance: 3.44seq/s +``` + +### 4.3 性能优化 +使用性能分析工具profiling,查看了模型中每类算子总体耗时与百分比和模型每个算子的aicore耗时,发现DynamicRNN耗时最多,使用autotune进行性能优化,优化后性能如下: +``` +Run time of each data: 2.03s +performance: 0.49seq/s +``` +在此基础上,对TransData算子进行优化,优化后性能如下: +``` +Run time of each data: 1.41s +performance: 0.71seq/s ``` \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Deepspeech/ckpt2onnx.py b/ACL_PyTorch/contrib/cv/detection/Deepspeech/ckpt2onnx.py index c3b8c5ffd48d298f312f076c42659b328c3f9823..0348203a8f0c528df8fb35bdd346bd2945ba426b 100644 --- a/ACL_PyTorch/contrib/cv/detection/Deepspeech/ckpt2onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/Deepspeech/ckpt2onnx.py @@ -1,48 +1,48 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - - -""" -Export onnx from ckpt -""" -import hydra -import os -import torch -from deepspeech_pytorch.configs.inference_config import EvalConfig -from deepspeech_pytorch.utils import load_model -import argparse - -parser = argparse.ArgumentParser(description='Deepspeech') -parser.add_argument('--ckpt_path', default='./an4_pretrained_v3.ckpt', type=str, help='infer out path') -parser.add_argument('--out_file', default='deepspeech.onnx', type=str, help='infer info path') -args = parser.parse_args() - -if __name__ == '__main__': - device = torch.device("cpu") - # device = torch.device("cuda" if EvalConfig.model.cuda else "cpu") - model = load_model(device=device, model_path=args.ckpt_path) - model.eval() - model = model.to(device) - print('Finished loading model!') - # print(model) - input_names = ["spect", "transcript"] - output_names = ["out"] - dynamic_axes = {'spect': {0: '-1'}} - dummy_input = torch.randn(1, 1, 161, 621).to(device) - dummy_input2 = torch.tensor([621], dtype=torch.int32).to(device) - output_file = args.out_file - torch.onnx.export(model, [dummy_input, dummy_input2], output_file, - input_names=input_names, dynamic_axes=dynamic_axes, - output_names=output_names, opset_version=11, verbose=True) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + + +""" +Export onnx from ckpt +""" +import hydra +import os +import torch +from deepspeech_pytorch.configs.inference_config import EvalConfig +from deepspeech_pytorch.utils import load_model +import argparse + +parser = argparse.ArgumentParser(description='Deepspeech') +parser.add_argument('--ckpt_path', default='./an4_pretrained_v3.ckpt', type=str, help='infer out path') +parser.add_argument('--out_file', default='deepspeech.onnx', type=str, help='infer info path') +args = parser.parse_args() + +if __name__ == '__main__': + device = torch.device("cpu") + # device = torch.device("cuda" if EvalConfig.model.cuda else "cpu") + model = load_model(device=device, model_path=args.ckpt_path) + model.eval() + model = model.to(device) + print('Finished loading model!') + # print(model) + input_names = ["spect", "transcript"] + output_names = ["out"] + dynamic_axes = {'spect': {0: '-1'}} + dummy_input = torch.randn(1, 1, 161, 621).to(device) + dummy_input2 = torch.tensor([621], dtype=torch.int32).to(device) + output_file = args.out_file + torch.onnx.export(model, [dummy_input, dummy_input2], output_file, + input_names=input_names, dynamic_axes=dynamic_axes, + output_names=output_names, opset_version=11, verbose=True) diff --git a/ACL_PyTorch/contrib/cv/detection/Deepspeech/deepspeech_postprocess.py b/ACL_PyTorch/contrib/cv/detection/Deepspeech/deepspeech_postprocess.py index 93e0134a312dc836acc30dfb3a643f16da23a3da..29fc86d8d3620c3103c513592ed5875307ed5393 100644 --- a/ACL_PyTorch/contrib/cv/detection/Deepspeech/deepspeech_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/Deepspeech/deepspeech_postprocess.py @@ -1,152 +1,152 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - - -""" -Post-processing script -""" -import json -import torch -from deepspeech_pytorch.utils import load_decoder -from deepspeech_pytorch.configs.inference_config import EvalConfig -from deepspeech_pytorch.configs.train_config import DeepSpeechConfig -from deepspeech_pytorch.decoder import GreedyDecoder -from deepspeech_pytorch.validation import WordErrorRate, CharErrorRate -from hydra.utils import to_absolute_path - -import argparse -import os -import numpy as np - -parser = argparse.ArgumentParser(description='Deepspeech') -parser.add_argument('--out_path', default='./result', type=str, help='infer out path') -parser.add_argument('--info_path', default='./data/an4_dataset/test', type=str, help='infer info path') -parser.add_argument('--label_file', default='./labels.json') -args = parser.parse_args() - - -def read_dataset(out_path): - """ - Read the output file - """ - out_files = os.listdir(out_path) - # print(out_files) - data_all = [] - for j in range(len(out_files)): - with open(out_path + '/' + 'data' + str(j + 1) + '_output_0.txt', 'r') as file: - data_read = file.read() - data_line = str(data_read).split(' ') - data_line.pop(-1) - data_list = [] - for i in range(311): - data_list.append(list(map(float, data_line[29 * i: 29 * (i + 1)]))) - data_all.append(data_list) - - # float_list = list(map(float, data_all)) - out_dataset = torch.Tensor(data_all) - return out_dataset - - -def read_sizes(info_path): - """ - Read the sizes file - """ - with open(info_path + '/sizes/sizes.txt', 'r') as sizes_file: - sizes_read = sizes_file.read() - sizes_line = str(sizes_read).split(' ') - sizes_line.pop(-1) - sizes_list = list(map(int, sizes_line)) - sizes_list = torch.Tensor(sizes_list).int() - return sizes_list - - -def read_targets(info_path): - """ - Read the targets file - """ - with open(info_path + '/targets.txt', 'r') as targets_file: - targets_read = targets_file.read() - targets_line = str(targets_read).split(' ') - targets_line.pop(-1) - targets_list = list(map(int, targets_line)) - targets_list = torch.Tensor(targets_list).int() - # print(targets_list) - return targets_list - - -def read_target_sizes(info_path): - """ - Read the target sizes file - """ - with open(info_path + '/target_sizes.txt', 'r') as target_sizes_file: - target_sizes_read = target_sizes_file.read() - target_sizes_line = str(target_sizes_read).split(' ') - target_sizes_line.pop(-1) - target_sizes_list = list(map(int, target_sizes_line)) - target_sizes_list = torch.Tensor(target_sizes_list).int() - # print(target_sizes_list) - return target_sizes_list - - -if __name__ == '__main__': - out_path_real = args.out_path + '/' + sorted(os.listdir(args.out_path))[-1] - # print(out_path_real) - out_dataset = read_dataset(out_path_real) - out_sizes = read_sizes(args.info_path) - targets = read_targets(args.info_path) - target_sizes = read_target_sizes(args.info_path) - out_sizes = (out_sizes / 2).int() - device = torch.device("cuda" if EvalConfig.model.cuda else "cpu") - with open(to_absolute_path(args.label_file)) as label_file: - labels = json.load(label_file) - - decoder = load_decoder( - labels=labels, - cfg=EvalConfig.lm - ) - - target_decoder = GreedyDecoder( - labels=labels, - blank_index=labels.index('_') - ) - # print("模型输出的数据") - # print(out_dataset) - # o,_ = target_decoder.decode(out_dataset, out_sizes) - # print("结果",o) - wer = WordErrorRate( - decoder=decoder, - target_decoder=target_decoder - ) - cer = CharErrorRate( - decoder=decoder, - target_decoder=target_decoder - ) - wer.update( - preds=out_dataset, - preds_sizes=out_sizes, - targets=targets, - target_sizes=target_sizes - ) - cer.update( - preds=out_dataset, - preds_sizes=out_sizes, - targets=targets, - target_sizes=target_sizes - ) - wer = wer.compute() - cer = cer.compute() - print('Test Summary \t' - 'Average WER {wer:.3f}\t' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + + +""" +Post-processing script +""" +import json +import torch +from deepspeech_pytorch.utils import load_decoder +from deepspeech_pytorch.configs.inference_config import EvalConfig +from deepspeech_pytorch.configs.train_config import DeepSpeechConfig +from deepspeech_pytorch.decoder import GreedyDecoder +from deepspeech_pytorch.validation import WordErrorRate, CharErrorRate +from hydra.utils import to_absolute_path + +import argparse +import os +import numpy as np + +parser = argparse.ArgumentParser(description='Deepspeech') +parser.add_argument('--out_path', default='./result', type=str, help='infer out path') +parser.add_argument('--info_path', default='./data/an4_dataset/test', type=str, help='infer info path') +parser.add_argument('--label_file', default='./labels.json') +args = parser.parse_args() + + +def read_dataset(out_path): + """ + Read the output file + """ + out_files = os.listdir(out_path) + # print(out_files) + data_all = [] + for j in range(len(out_files)): + with open(out_path + '/' + 'data' + str(j + 1) + '_output_0.txt', 'r') as file: + data_read = file.read() + data_line = str(data_read).split(' ') + data_line.pop(-1) + data_list = [] + for i in range(311): + data_list.append(list(map(float, data_line[29 * i: 29 * (i + 1)]))) + data_all.append(data_list) + + # float_list = list(map(float, data_all)) + out_dataset = torch.Tensor(data_all) + return out_dataset + + +def read_sizes(info_path): + """ + Read the sizes file + """ + with open(info_path + '/sizes/sizes.txt', 'r') as sizes_file: + sizes_read = sizes_file.read() + sizes_line = str(sizes_read).split(' ') + sizes_line.pop(-1) + sizes_list = list(map(int, sizes_line)) + sizes_list = torch.Tensor(sizes_list).int() + return sizes_list + + +def read_targets(info_path): + """ + Read the targets file + """ + with open(info_path + '/targets.txt', 'r') as targets_file: + targets_read = targets_file.read() + targets_line = str(targets_read).split(' ') + targets_line.pop(-1) + targets_list = list(map(int, targets_line)) + targets_list = torch.Tensor(targets_list).int() + # print(targets_list) + return targets_list + + +def read_target_sizes(info_path): + """ + Read the target sizes file + """ + with open(info_path + '/target_sizes.txt', 'r') as target_sizes_file: + target_sizes_read = target_sizes_file.read() + target_sizes_line = str(target_sizes_read).split(' ') + target_sizes_line.pop(-1) + target_sizes_list = list(map(int, target_sizes_line)) + target_sizes_list = torch.Tensor(target_sizes_list).int() + # print(target_sizes_list) + return target_sizes_list + + +if __name__ == '__main__': + out_path_real = args.out_path + '/' + sorted(os.listdir(args.out_path))[-1] + # print(out_path_real) + out_dataset = read_dataset(out_path_real) + out_sizes = read_sizes(args.info_path) + targets = read_targets(args.info_path) + target_sizes = read_target_sizes(args.info_path) + out_sizes = (out_sizes / 2).int() + device = torch.device("cuda" if EvalConfig.model.cuda else "cpu") + with open(to_absolute_path(args.label_file)) as label_file: + labels = json.load(label_file) + + decoder = load_decoder( + labels=labels, + cfg=EvalConfig.lm + ) + + target_decoder = GreedyDecoder( + labels=labels, + blank_index=labels.index('_') + ) + # print("模型输出的数据") + # print(out_dataset) + # o,_ = target_decoder.decode(out_dataset, out_sizes) + # print("结果",o) + wer = WordErrorRate( + decoder=decoder, + target_decoder=target_decoder + ) + cer = CharErrorRate( + decoder=decoder, + target_decoder=target_decoder + ) + wer.update( + preds=out_dataset, + preds_sizes=out_sizes, + targets=targets, + target_sizes=target_sizes + ) + cer.update( + preds=out_dataset, + preds_sizes=out_sizes, + targets=targets, + target_sizes=target_sizes + ) + wer = wer.compute() + cer = cer.compute() + print('Test Summary \t' + 'Average WER {wer:.3f}\t' 'Average CER {cer:.3f}\t'.format(wer=wer, cer=cer)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Deepspeech/deepspeech_preprocess.py b/ACL_PyTorch/contrib/cv/detection/Deepspeech/deepspeech_preprocess.py index 2d9608dc38a27cf0e0b22eaa90f91f3a6b6b82b3..ab3c0e3528f9ea181b1d316936a762939a695ca4 100644 --- a/ACL_PyTorch/contrib/cv/detection/Deepspeech/deepspeech_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/Deepspeech/deepspeech_preprocess.py @@ -1,113 +1,113 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -""" -Data preprocessing script -""" -import os -import json -import numpy as np -import argparse -import torch -from deepspeech_pytorch.configs.train_config import DataConfig -from deepspeech_pytorch.loader.data_loader import SpectrogramDataset -from hydra.utils import to_absolute_path -from torch.utils.data import DataLoader - -parser = argparse.ArgumentParser(description='Deepspeech') -parser.add_argument('--data_file', default='./data/an4_test_manifest.json') -parser.add_argument('--save_path', default='./data/an4_dataset/test') -parser.add_argument('--label_file', default='./labels.json') -args = parser.parse_args() - -def collate_fn(batch): - """ - data preprocessing - """ - def func(p): - """ - data size - """ - return p[0].size(1) - - batch = sorted(batch, key=lambda sample: sample[0].size(1), reverse=True) - longest_sample = max(batch, key=func)[0] - freq_size = longest_sample.size(0) - minibatch_size = len(batch) - max_seqlength = longest_sample.size(1) - inputs = torch.zeros(minibatch_size, 1, freq_size, max_seqlength) - input_percentages = torch.FloatTensor(minibatch_size) - target_sizes = torch.IntTensor(minibatch_size) - targets = [] - for x in range(minibatch_size): - sample = batch[x] - tensor = sample[0] - target = sample[1] - seq_length = tensor.size(1) - inputs[x][0].narrow(1, 0, seq_length).copy_(tensor) - input_percentages[x] = seq_length / float(max_seqlength) - target_sizes[x] = len(target) - targets.extend(target) - targets = torch.tensor(targets, dtype=torch.long) - return inputs, input_percentages, [targets, target_sizes] - - -if __name__ == '__main__': - with open(to_absolute_path(args.label_file)) as label_file: - labels = json.load(label_file) - # if labels: - # print("labels ready") - - dataset = SpectrogramDataset( - audio_conf=DataConfig.spect, - input_path=args.data_file, - labels=labels, - normalize=True, - aug_cfg=DataConfig.augmentation - ) - inputs, input_percentages, target_list = collate_fn(dataset) - targets = target_list[0] - target_sizes = target_list[1] - input_sizes = input_percentages.mul_(int(inputs.size(3))).int() - - # print(inputs,input_sizes) - if not os.path.exists(args.save_path + '/spect'): os.makedirs(args.save_path + '/spect') - if not os.path.exists(args.save_path + '/sizes'): os.makedirs(args.save_path + '/sizes') - i = 0 - for input_data in inputs: - i = i + 1 - spect = np.array(input_data).astype(np.float32) - spect.tofile(os.path.join(args.save_path + '/spect', "data" + str(i) + ".bin")) - - i = 0 - for input_size in input_sizes: - i = i + 1 - transcript = np.array(input_size).astype(np.int32) - transcript.tofile(os.path.join(args.save_path + '/sizes', "data" + str(i) + ".bin")) - - f = open(args.save_path + '/sizes/' + 'sizes.txt', "w") - for w in np.array(input_sizes).astype(np.int32): - f.write(str(w)+' ') - f.close() - - f = open(args.save_path + '/targets.txt', "w") - for w in np.array(targets): - f.write(str(w) + ' ') - f.close() - - f = open(args.save_path + '/target_sizes.txt', "w") - for w in np.array(target_sizes).astype(np.int32): - f.write(str(w) + ' ') +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +""" +Data preprocessing script +""" +import os +import json +import numpy as np +import argparse +import torch +from deepspeech_pytorch.configs.train_config import DataConfig +from deepspeech_pytorch.loader.data_loader import SpectrogramDataset +from hydra.utils import to_absolute_path +from torch.utils.data import DataLoader + +parser = argparse.ArgumentParser(description='Deepspeech') +parser.add_argument('--data_file', default='./data/an4_test_manifest.json') +parser.add_argument('--save_path', default='./data/an4_dataset/test') +parser.add_argument('--label_file', default='./labels.json') +args = parser.parse_args() + +def collate_fn(batch): + """ + data preprocessing + """ + def func(p): + """ + data size + """ + return p[0].size(1) + + batch = sorted(batch, key=lambda sample: sample[0].size(1), reverse=True) + longest_sample = max(batch, key=func)[0] + freq_size = longest_sample.size(0) + minibatch_size = len(batch) + max_seqlength = longest_sample.size(1) + inputs = torch.zeros(minibatch_size, 1, freq_size, max_seqlength) + input_percentages = torch.FloatTensor(minibatch_size) + target_sizes = torch.IntTensor(minibatch_size) + targets = [] + for x in range(minibatch_size): + sample = batch[x] + tensor = sample[0] + target = sample[1] + seq_length = tensor.size(1) + inputs[x][0].narrow(1, 0, seq_length).copy_(tensor) + input_percentages[x] = seq_length / float(max_seqlength) + target_sizes[x] = len(target) + targets.extend(target) + targets = torch.tensor(targets, dtype=torch.long) + return inputs, input_percentages, [targets, target_sizes] + + +if __name__ == '__main__': + with open(to_absolute_path(args.label_file)) as label_file: + labels = json.load(label_file) + # if labels: + # print("labels ready") + + dataset = SpectrogramDataset( + audio_conf=DataConfig.spect, + input_path=args.data_file, + labels=labels, + normalize=True, + aug_cfg=DataConfig.augmentation + ) + inputs, input_percentages, target_list = collate_fn(dataset) + targets = target_list[0] + target_sizes = target_list[1] + input_sizes = input_percentages.mul_(int(inputs.size(3))).int() + + # print(inputs,input_sizes) + if not os.path.exists(args.save_path + '/spect'): os.makedirs(args.save_path + '/spect') + if not os.path.exists(args.save_path + '/sizes'): os.makedirs(args.save_path + '/sizes') + i = 0 + for input_data in inputs: + i = i + 1 + spect = np.array(input_data).astype(np.float32) + spect.tofile(os.path.join(args.save_path + '/spect', "data" + str(i) + ".bin")) + + i = 0 + for input_size in input_sizes: + i = i + 1 + transcript = np.array(input_size).astype(np.int32) + transcript.tofile(os.path.join(args.save_path + '/sizes', "data" + str(i) + ".bin")) + + f = open(args.save_path + '/sizes/' + 'sizes.txt', "w") + for w in np.array(input_sizes).astype(np.int32): + f.write(str(w)+' ') + f.close() + + f = open(args.save_path + '/targets.txt', "w") + for w in np.array(targets): + f.write(str(w) + ' ') + f.close() + + f = open(args.save_path + '/target_sizes.txt', "w") + for w in np.array(target_sizes).astype(np.int32): + f.write(str(w) + ' ') f.close() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Deepspeech/test/t4_perf.py b/ACL_PyTorch/contrib/cv/detection/Deepspeech/test/t4_perf.py index 7f0120a740bfed1da1872528a5b69c6e862c1d70..a150520144a56de437a2893a1c8aefb571f8acd7 100644 --- a/ACL_PyTorch/contrib/cv/detection/Deepspeech/test/t4_perf.py +++ b/ACL_PyTorch/contrib/cv/detection/Deepspeech/test/t4_perf.py @@ -1,85 +1,85 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import hydra -import os -import torch -from deepspeech_pytorch.configs.inference_config import EvalConfig -from deepspeech_pytorch.utils import load_model - -from deepspeech_pytorch.decoder import GreedyDecoder -from deepspeech_pytorch.utils import load_decoder - -import os -import json -import numpy as np -import argparse - -from deepspeech_pytorch.loader.data_module import DeepSpeechDataModule -from deepspeech_pytorch.configs.train_config import DeepSpeechConfig -from deepspeech_pytorch.loader.data_loader import AudioDataLoader -from hydra.utils import to_absolute_path -import time - -parser = argparse.ArgumentParser(description='Deepspeech') -# The data file to read -parser.add_argument('--data_file', default='./data/an4_test_manifest.json') -# The location the generated 'bin' file to save -parser.add_argument('--save_path', default='./data/an4_dataset/test') -args = parser.parse_args() - - - -if __name__ == '__main__': - - device = torch.device("cuda" if EvalConfig.model.cuda else "cpu") - with open(to_absolute_path(DeepSpeechConfig.data.labels_path)) as label_file: - labels = json.load(label_file) - # if labels: - # print("labels ready") - data_module = DeepSpeechDataModule( - labels=labels, - data_cfg=DeepSpeechConfig.data, - normalize=True, - is_distributed=False # DeepSpeechConfig.trainer.gpus > 1 - ) - dataset = data_module._create_dataset(args.data_file) - - data_loader = AudioDataLoader( - dataset=dataset, - num_workers=data_module.data_cfg.num_workers, - batch_size=data_module.data_cfg.batch_size - ) - - inputs, targets, input_percentages, target_sizes = data_loader.collate_fn(data_loader.dataset) - - input_sizes = input_percentages.mul_(int(inputs.size(3))).int() - inputs = inputs.to(device) - - - - device = torch.device("cuda" if EvalConfig.model.cuda else "cpu") - model = load_model(device=device, model_path='an4_pretrained_v3.ckpt') - model.eval() - model = model.to(device) - print('Finished loading model!') - s_time = time.time() - for i in range(5): - out, output_sizes = model(inputs[:1], input_sizes[:1]) - e_time = time.time() - t = (e_time - s_time)/5 - print('Finished testing data!') - print('Run time of each data: ', t) - print('performance: ', 1/t, 'seq/s') +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import hydra +import os +import torch +from deepspeech_pytorch.configs.inference_config import EvalConfig +from deepspeech_pytorch.utils import load_model + +from deepspeech_pytorch.decoder import GreedyDecoder +from deepspeech_pytorch.utils import load_decoder + +import os +import json +import numpy as np +import argparse + +from deepspeech_pytorch.loader.data_module import DeepSpeechDataModule +from deepspeech_pytorch.configs.train_config import DeepSpeechConfig +from deepspeech_pytorch.loader.data_loader import AudioDataLoader +from hydra.utils import to_absolute_path +import time + +parser = argparse.ArgumentParser(description='Deepspeech') +# The data file to read +parser.add_argument('--data_file', default='./data/an4_test_manifest.json') +# The location the generated 'bin' file to save +parser.add_argument('--save_path', default='./data/an4_dataset/test') +args = parser.parse_args() + + + +if __name__ == '__main__': + + device = torch.device("cuda" if EvalConfig.model.cuda else "cpu") + with open(to_absolute_path(DeepSpeechConfig.data.labels_path)) as label_file: + labels = json.load(label_file) + # if labels: + # print("labels ready") + data_module = DeepSpeechDataModule( + labels=labels, + data_cfg=DeepSpeechConfig.data, + normalize=True, + is_distributed=False # DeepSpeechConfig.trainer.gpus > 1 + ) + dataset = data_module._create_dataset(args.data_file) + + data_loader = AudioDataLoader( + dataset=dataset, + num_workers=data_module.data_cfg.num_workers, + batch_size=data_module.data_cfg.batch_size + ) + + inputs, targets, input_percentages, target_sizes = data_loader.collate_fn(data_loader.dataset) + + input_sizes = input_percentages.mul_(int(inputs.size(3))).int() + inputs = inputs.to(device) + + + + device = torch.device("cuda" if EvalConfig.model.cuda else "cpu") + model = load_model(device=device, model_path='an4_pretrained_v3.ckpt') + model.eval() + model = model.to(device) + print('Finished loading model!') + s_time = time.time() + for i in range(5): + out, output_sizes = model(inputs[:1], input_sizes[:1]) + e_time = time.time() + t = (e_time - s_time)/5 + print('Finished testing data!') + print('Run time of each data: ', t) + print('performance: ', 1/t, 'seq/s') diff --git a/ACL_PyTorch/contrib/cv/detection/Detr/FPS.py b/ACL_PyTorch/contrib/cv/detection/Detr/FPS.py index 72a5ee53fbe24f2a7d86720d9fbb669acbac0dbf..3f66e22cabb039f13fb085d8670e9f9638ab4d31 100644 --- a/ACL_PyTorch/contrib/cv/detection/Detr/FPS.py +++ b/ACL_PyTorch/contrib/cv/detection/Detr/FPS.py @@ -1,33 +1,33 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import numpy as np -import argparse - -parser = argparse.ArgumentParser('Calculation FPS', add_help=False) -parser.add_argument('--log_path', default='bs1_time.log') -parser.add_argument('--batch_size', default=1,type=int) -args = parser.parse_args() - -weight = [0.17, 0.06, 0.53, 0.18, 0.05, 0.009, 0.0014, 0.0006, 0.005] -weight = np.array(weight) -val_times = [] -with open(args.log_path, 'r') as l: - for line in l.readlines(): - if line.startswith('Inference average time without first time: '): - val_time = float(line.split(':')[1].replace('ms', '')) / 1000 - val_times.append(val_time) -val_times = np.array(val_times) -fps = 1 / sum(val_times * weight) * args.batch_size * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +import argparse + +parser = argparse.ArgumentParser('Calculation FPS', add_help=False) +parser.add_argument('--log_path', default='bs1_time.log') +parser.add_argument('--batch_size', default=1,type=int) +args = parser.parse_args() + +weight = [0.17, 0.06, 0.53, 0.18, 0.05, 0.009, 0.0014, 0.0006, 0.005] +weight = np.array(weight) +val_times = [] +with open(args.log_path, 'r') as l: + for line in l.readlines(): + if line.startswith('Inference average time without first time: '): + val_time = float(line.split(':')[1].replace('ms', '')) / 1000 + val_times.append(val_time) +val_times = np.array(val_times) +fps = 1 / sum(val_times * weight) * args.batch_size * 4 print(fps) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Detr/excute_omval.py b/ACL_PyTorch/contrib/cv/detection/Detr/excute_omval.py index 75a85178b36c2b381db02ecb4d203885700def94..75c845b70c76fd5cd90f5a8c60c85366fc0bef90 100644 --- a/ACL_PyTorch/contrib/cv/detection/Detr/excute_omval.py +++ b/ACL_PyTorch/contrib/cv/detection/Detr/excute_omval.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import argparse - -parser = argparse.ArgumentParser('Set transformer detector', add_help=False) -parser.add_argument('--img_path', default='img_file') -parser.add_argument('--mask_path', default='mask_file') -parser.add_argument('--out_put', default='out_put') -parser.add_argument('--result', default='result') -parser.add_argument('--batch_size', default=1, type=int) -args = parser.parse_args() - -if not os.path.exists(args.out_put): - os.mkdir(args.out_put) -if not os.path.exists(args.result): - os.mkdir(args.result) - -shape_3 = [[768, 1280, 24, 40], [768, 768, 24, 24], [768, 1024, 24, 32]] -shape_6 = [[1024, 768, 32, 24], [1280, 768, 40, 24], [768, 1344, 24, 42], [1344, 768, 42, 24], [1344, 512, 32, 42], - [512, 1344, 16, 42]] -print(args) -if args.batch_size == 1: - for i in shape_3: - command = 'tools/msame/out/msame --model "auto_om/detr_gear_bs1_768.om" --input "{}/{}_{},{}/{}_{}_mask" --output "{}" ' \ - '--dymDims "inputs:1,3,{},{};mask:1,{},{}" --outfmt BIN'. \ - format(args.img_path, i[0], i[1], args.mask_path, i[0], i[1], args.out_put, i[0], i[1], int(i[0] / 32), - int(i[1] / 32)) - print(command) - os.system(command) - for i in shape_6: - command = 'tools/msame/out/msame --model "auto_om/detr_bs1_{}_{}.om" --input "{}/{}_{},{}/{}_{}_mask" --output "{}" --outfmt BIN'.format( - i[0], i[1], args.img_path, i[0], i[1], args.mask_path, i[0], i[1], args.out_put) - print(command) - os.system(command) - mv_command = 'mv {}/*/* {}'.format(args.out_put, args.result) - os.system(mv_command) -elif args.batch_size == 4: - print(4) - for i in shape_3: - command = 'tools/msame/out/msame --model "auto_om/detr_gear_bs4_768.om" --output "{}" --dymDims "inputs:4,3,{},{};mask:4,{},{}" ' \ - '--outfmt BIN --loop 20'.format(args.out_put, i[0], i[1], int(i[0] / 32), int(i[1] / 32)) - print(command) - os.system(command) - for i in shape_6: - command = 'tools/msame/out/msame --model "auto_om/detr_bs4_{}_{}.om" --output "{}" --outfmt BIN --loop 20'. \ - format(i[0], i[1], args.out_put) - print(command) - os.system(command) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import argparse + +parser = argparse.ArgumentParser('Set transformer detector', add_help=False) +parser.add_argument('--img_path', default='img_file') +parser.add_argument('--mask_path', default='mask_file') +parser.add_argument('--out_put', default='out_put') +parser.add_argument('--result', default='result') +parser.add_argument('--batch_size', default=1, type=int) +args = parser.parse_args() + +if not os.path.exists(args.out_put): + os.mkdir(args.out_put) +if not os.path.exists(args.result): + os.mkdir(args.result) + +shape_3 = [[768, 1280, 24, 40], [768, 768, 24, 24], [768, 1024, 24, 32]] +shape_6 = [[1024, 768, 32, 24], [1280, 768, 40, 24], [768, 1344, 24, 42], [1344, 768, 42, 24], [1344, 512, 32, 42], + [512, 1344, 16, 42]] +print(args) +if args.batch_size == 1: + for i in shape_3: + command = 'tools/msame/out/msame --model "auto_om/detr_gear_bs1_768.om" --input "{}/{}_{},{}/{}_{}_mask" --output "{}" ' \ + '--dymDims "inputs:1,3,{},{};mask:1,{},{}" --outfmt BIN'. \ + format(args.img_path, i[0], i[1], args.mask_path, i[0], i[1], args.out_put, i[0], i[1], int(i[0] / 32), + int(i[1] / 32)) + print(command) + os.system(command) + for i in shape_6: + command = 'tools/msame/out/msame --model "auto_om/detr_bs1_{}_{}.om" --input "{}/{}_{},{}/{}_{}_mask" --output "{}" --outfmt BIN'.format( + i[0], i[1], args.img_path, i[0], i[1], args.mask_path, i[0], i[1], args.out_put) + print(command) + os.system(command) + mv_command = 'mv {}/*/* {}'.format(args.out_put, args.result) + os.system(mv_command) +elif args.batch_size == 4: + print(4) + for i in shape_3: + command = 'tools/msame/out/msame --model "auto_om/detr_gear_bs4_768.om" --output "{}" --dymDims "inputs:4,3,{},{};mask:4,{},{}" ' \ + '--outfmt BIN --loop 20'.format(args.out_put, i[0], i[1], int(i[0] / 32), int(i[1] / 32)) + print(command) + os.system(command) + for i in shape_6: + command = 'tools/msame/out/msame --model "auto_om/detr_bs4_{}_{}.om" --output "{}" --outfmt BIN --loop 20'. \ + format(i[0], i[1], args.out_put) + print(command) + os.system(command) diff --git a/ACL_PyTorch/contrib/cv/detection/Detr/onnx2om.py b/ACL_PyTorch/contrib/cv/detection/Detr/onnx2om.py index 3bc36c657ec1ed3698e3f7a781ba79d12c8187b9..8cd2294743794ddcf4607130f28c26043523e3ed 100644 --- a/ACL_PyTorch/contrib/cv/detection/Detr/onnx2om.py +++ b/ACL_PyTorch/contrib/cv/detection/Detr/onnx2om.py @@ -1,44 +1,44 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import argparse - -parser = argparse.ArgumentParser('Set transformer detector', add_help=False) -parser.add_argument('--batch_size', default=1) -parser.add_argument('--auto_tune', default=False) -args = parser.parse_args() - -input_shape = [['768,1280,24,40;768,768,24,24;768,1024,24,32'], [1024, 768, 32, 24], [1280, 768, 40, 24], - [768, 1344, 24, 42], [1344, 768, 42, 24], [1344, 512, 42, 16], [512, 1344, 16, 42]] - -to_om = 'atc --framework=5 --model=model/detr_bs{}.onnx -output=auto_om/detr_bs{}_{}_{} ' \ - '--input_shape="inputs:{},3,{},{};mask:{},{},{}" --input_format=ND --soc_version=Ascend310' -to_dyom = 'atc --framework=5 --model=model/detr_bs{}.onnx -output=auto_om/detr_gear_bs{}_{} ' \ - '--input_shape="inputs:{},3,-1,-1;mask:{},-1,-1" --dynamic_dims="{}" --input_format=ND --soc_version=Ascend310' - -if args.auto_tune == True: - to_om = to_om + ' --auto_tune_mode="RL,GA"' - to_dyom = to_dyom + ' --auto_tune_mode="RL,GA"' - -for i in input_shape: - if len(i) == 4: - command = to_om.format(args.batch_size, args.batch_size, i[0], i[1], args.batch_size, i[0], i[1], - args.batch_size, i[2], i[3]) - print(command) - os.system(command) - else: - command = to_dyom.format(args.batch_size, args.batch_size, - i[0].split(',')[0], args.batch_size, args.batch_size, i[0]) - print(command) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import argparse + +parser = argparse.ArgumentParser('Set transformer detector', add_help=False) +parser.add_argument('--batch_size', default=1) +parser.add_argument('--auto_tune', default=False) +args = parser.parse_args() + +input_shape = [['768,1280,24,40;768,768,24,24;768,1024,24,32'], [1024, 768, 32, 24], [1280, 768, 40, 24], + [768, 1344, 24, 42], [1344, 768, 42, 24], [1344, 512, 42, 16], [512, 1344, 16, 42]] + +to_om = 'atc --framework=5 --model=model/detr_bs{}.onnx -output=auto_om/detr_bs{}_{}_{} ' \ + '--input_shape="inputs:{},3,{},{};mask:{},{},{}" --input_format=ND --soc_version=Ascend310' +to_dyom = 'atc --framework=5 --model=model/detr_bs{}.onnx -output=auto_om/detr_gear_bs{}_{} ' \ + '--input_shape="inputs:{},3,-1,-1;mask:{},-1,-1" --dynamic_dims="{}" --input_format=ND --soc_version=Ascend310' + +if args.auto_tune == True: + to_om = to_om + ' --auto_tune_mode="RL,GA"' + to_dyom = to_dyom + ' --auto_tune_mode="RL,GA"' + +for i in input_shape: + if len(i) == 4: + command = to_om.format(args.batch_size, args.batch_size, i[0], i[1], args.batch_size, i[0], i[1], + args.batch_size, i[2], i[3]) + print(command) + os.system(command) + else: + command = to_dyom.format(args.batch_size, args.batch_size, + i[0].split(',')[0], args.batch_size, args.batch_size, i[0]) + print(command) os.system(command) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/EfficientDetD0/get_info.py b/ACL_PyTorch/contrib/cv/detection/EfficientDetD0/get_info.py index b76d6739bcea5c528a031970f0e583e5b5644bd8..d5cab0450c20d502d0d15be2f9c0fceffa6a6191 100644 --- a/ACL_PyTorch/contrib/cv/detection/EfficientDetD0/get_info.py +++ b/ACL_PyTorch/contrib/cv/detection/EfficientDetD0/get_info.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/EfficientDetD0/modify_onnx.py b/ACL_PyTorch/contrib/cv/detection/EfficientDetD0/modify_onnx.py index 3e217e67033d8725e89a76ef9ee442bcdbb84e53..0995b070b7b859e3cf5b4d3c634136475d96d7b1 100644 --- a/ACL_PyTorch/contrib/cv/detection/EfficientDetD0/modify_onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/EfficientDetD0/modify_onnx.py @@ -1,35 +1,35 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -sys.path.append(r'onnx_tools/OXInterface') -from OXInterface import OXGraph -import numpy as np -import argparse - -parser = argparse.ArgumentParser(description='pth to onnx') -parser.add_argument('--model', type=str, default='d0_bs8_sim.onnx', metavar='N', - help='onnx model') -parser.add_argument('--node', type=str, default='1532', metavar='N', - help='need to modify pad node number') -parser.add_argument('--out', type=str, default='d0_bs8_modify.onnx', metavar='N', - help='modified onnx') - - -args = parser.parse_args() -oxgraph = OXGraph(args.model) -oxinitializer_node = oxgraph.get_oxinitializer_by_name(args.node) -new_data = np.array(0, dtype=np.float32) -oxinitializer_node.set_data(new_data) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +sys.path.append(r'onnx_tools/OXInterface') +from OXInterface import OXGraph +import numpy as np +import argparse + +parser = argparse.ArgumentParser(description='pth to onnx') +parser.add_argument('--model', type=str, default='d0_bs8_sim.onnx', metavar='N', + help='onnx model') +parser.add_argument('--node', type=str, default='1532', metavar='N', + help='need to modify pad node number') +parser.add_argument('--out', type=str, default='d0_bs8_modify.onnx', metavar='N', + help='modified onnx') + + +args = parser.parse_args() +oxgraph = OXGraph(args.model) +oxinitializer_node = oxgraph.get_oxinitializer_by_name(args.node) +new_data = np.array(0, dtype=np.float32) +oxinitializer_node.set_data(new_data) oxgraph.save_new_model(args.out) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/EfficientDetD0/test/pth2om.sh b/ACL_PyTorch/contrib/cv/detection/EfficientDetD0/test/pth2om.sh old mode 100755 new mode 100644 diff --git a/ACL_PyTorch/contrib/cv/detection/EfficientDetD7/get_info.py b/ACL_PyTorch/contrib/cv/detection/EfficientDetD7/get_info.py index b76d6739bcea5c528a031970f0e583e5b5644bd8..d5cab0450c20d502d0d15be2f9c0fceffa6a6191 100644 --- a/ACL_PyTorch/contrib/cv/detection/EfficientDetD7/get_info.py +++ b/ACL_PyTorch/contrib/cv/detection/EfficientDetD7/get_info.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/EfficientDetD7/modify_onnx.py b/ACL_PyTorch/contrib/cv/detection/EfficientDetD7/modify_onnx.py index 8066bcf7e7637fb5ffb2c533099fa8023bb30f08..2f6e1e0db62ea98b461a0cd07bb940e48096b2f9 100644 --- a/ACL_PyTorch/contrib/cv/detection/EfficientDetD7/modify_onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/EfficientDetD7/modify_onnx.py @@ -1,35 +1,35 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -sys.path.append(r'onnx_tools/OXInterface') -from OXInterface import OXGraph -import numpy as np -import argparse - -parser = argparse.ArgumentParser(description='pth to onnx') -parser.add_argument('--model', type=str, default='d7.onnx', metavar='N', - help='onnx model') -parser.add_argument('--node', type=str, default='3080', metavar='N', - help='need to modify pad node number') -parser.add_argument('--out', type=str, default='d7_modify.onnx', metavar='N', - help='modified onnx') - - -args = parser.parse_args() -oxgraph = OXGraph(args.model) -oxinitializer_node = oxgraph.get_oxinitializer_by_name(args.node) -new_data = np.array(0, dtype=np.float32) -oxinitializer_node.set_data(new_data) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +sys.path.append(r'onnx_tools/OXInterface') +from OXInterface import OXGraph +import numpy as np +import argparse + +parser = argparse.ArgumentParser(description='pth to onnx') +parser.add_argument('--model', type=str, default='d7.onnx', metavar='N', + help='onnx model') +parser.add_argument('--node', type=str, default='3080', metavar='N', + help='need to modify pad node number') +parser.add_argument('--out', type=str, default='d7_modify.onnx', metavar='N', + help='modified onnx') + + +args = parser.parse_args() +oxgraph = OXGraph(args.model) +oxinitializer_node = oxgraph.get_oxinitializer_by_name(args.node) +new_data = np.array(0, dtype=np.float32) +oxinitializer_node.set_data(new_data) oxgraph.save_new_model(args.out) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/FOTS/FOTS_pth2onnx_8.py b/ACL_PyTorch/contrib/cv/detection/FOTS/FOTS_pth2onnx_8.py index 6cd3da24add616fb846447db3a8ebb65d6c8fc3a..c3f7a592ba94b9524a8a20d2dab3c4257211dcd4 100644 --- a/ACL_PyTorch/contrib/cv/detection/FOTS/FOTS_pth2onnx_8.py +++ b/ACL_PyTorch/contrib/cv/detection/FOTS/FOTS_pth2onnx_8.py @@ -1,37 +1,37 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import torch -import torch.onnx -import torchvision.models as models -from model import FOTSModel - -def pth2onnx(input_file, output_file): - - model = FOTSModel() - checkpoint = torch.load(input_file, map_location='cpu') - model.load_state_dict(checkpoint['model_state_dict']) - - model.eval() - input_names = ["image"] - output_names = ["location"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(8, 3, 1248, 2240) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) - -if __name__ == "__main__": - input_file = sys.argv[1] - output_file = sys.argv[2] +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import torch +import torch.onnx +import torchvision.models as models +from model import FOTSModel + +def pth2onnx(input_file, output_file): + + model = FOTSModel() + checkpoint = torch.load(input_file, map_location='cpu') + model.load_state_dict(checkpoint['model_state_dict']) + + model.eval() + input_names = ["image"] + output_names = ["location"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(8, 3, 1248, 2240) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, verbose=True, opset_version=11) + +if __name__ == "__main__": + input_file = sys.argv[1] + output_file = sys.argv[2] pth2onnx(input_file, output_file) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/FOTS/LICENSE b/ACL_PyTorch/contrib/cv/detection/FOTS/LICENSE index 185404d5515c393add9ecfbdd7cd83596e8a4b26..5b4cf39445b7b24f2e5d38062c3b9cca89ad8a90 100644 --- a/ACL_PyTorch/contrib/cv/detection/FOTS/LICENSE +++ b/ACL_PyTorch/contrib/cv/detection/FOTS/LICENSE @@ -1,204 +1,204 @@ -Copyright 2018-2019 Open-MMLab. All rights reserved. -Copyright 2021 Huawei Technologies Co., Ltd - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2018-2019 Open-MMLab. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Copyright 2018-2019 Open-MMLab. All rights reserved. +Copyright 2021 Huawei Technologies Co., Ltd + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2019 Open-MMLab. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ACL_PyTorch/contrib/cv/detection/FOTS/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/detection/FOTS/gen_dataset_info.py index 710bbd708c7417a9895e42560db50ce2cd03c432..edb8df558bbe1f18ec8ab9353ec1097c28c60853 100644 --- a/ACL_PyTorch/contrib/cv/detection/FOTS/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/detection/FOTS/gen_dataset_info.py @@ -1,60 +1,60 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/FOTS/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/detection/FOTS/modelzoo_level.txt index 38700fca05402f52c3ae1c4be0889eb60e1f80f1..2e42553460a4f3687654b6ad3f91ab0bcc3aadac 100644 --- a/ACL_PyTorch/contrib/cv/detection/FOTS/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/detection/FOTS/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/FOTS/preprocess.py b/ACL_PyTorch/contrib/cv/detection/FOTS/preprocess.py index 9ca995e15387351dcde0181dc353782047ead82c..d6d94222e488fbcdaf1186745b2f4888baac8e6d 100644 --- a/ACL_PyTorch/contrib/cv/detection/FOTS/preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/FOTS/preprocess.py @@ -1,44 +1,44 @@ -import argparse -import os - -import cv2 -import numpy as np -import torch - - - -import re -import tqdm - - -def preprocess(images_folder, output_folder): - pbar = tqdm.tqdm(os.listdir(images_folder), desc='Test', ncols=80) - for image_name in pbar: - # prefix = image_name[:image_name.rfind('.')] - image = cv2.imread(os.path.join(images_folder, image_name), cv2.IMREAD_COLOR) - # due to bad net arch sizes have to be mult of 32, so hardcode it - scale_x = 2240 / image.shape[1] # 2240 # 1280 1.75 - scale_y = 1248 / image.shape[0] # 1248 # 720 1.73333 - scaled_image = cv2.resize(image, dsize=(0, 0), fx=scale_x, fy=scale_y, interpolation=cv2.INTER_CUBIC) - # orig_scaled_image = scaled_image.copy() - - scaled_image = scaled_image[:, :, ::-1].astype(np.float32) - scaled_image = (scaled_image / 255 - np.array([0.485, 0.456, 0.406])) / np.array([0.229, 0.224, 0.225]) - image_tensor = torch.from_numpy(np.expand_dims(np.transpose(scaled_image, axes=(2, 0, 1)), axis=0)).float() - - img = np.array(image_tensor).astype(np.float32) - - img.tofile(os.path.join(output_folder, image_name.split('.')[0] + ".bin")) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--images-folder', type=str, required=True, help='path to the folder with test images') - parser.add_argument('--output-folder', type=str, default='fots_test_results', - help='path to the output folder with result labels') - - args = parser.parse_args() - - preprocess(args.images_folder, args.output_folder) - - +import argparse +import os + +import cv2 +import numpy as np +import torch + + + +import re +import tqdm + + +def preprocess(images_folder, output_folder): + pbar = tqdm.tqdm(os.listdir(images_folder), desc='Test', ncols=80) + for image_name in pbar: + # prefix = image_name[:image_name.rfind('.')] + image = cv2.imread(os.path.join(images_folder, image_name), cv2.IMREAD_COLOR) + # due to bad net arch sizes have to be mult of 32, so hardcode it + scale_x = 2240 / image.shape[1] # 2240 # 1280 1.75 + scale_y = 1248 / image.shape[0] # 1248 # 720 1.73333 + scaled_image = cv2.resize(image, dsize=(0, 0), fx=scale_x, fy=scale_y, interpolation=cv2.INTER_CUBIC) + # orig_scaled_image = scaled_image.copy() + + scaled_image = scaled_image[:, :, ::-1].astype(np.float32) + scaled_image = (scaled_image / 255 - np.array([0.485, 0.456, 0.406])) / np.array([0.229, 0.224, 0.225]) + image_tensor = torch.from_numpy(np.expand_dims(np.transpose(scaled_image, axes=(2, 0, 1)), axis=0)).float() + + img = np.array(image_tensor).astype(np.float32) + + img.tofile(os.path.join(output_folder, image_name.split('.')[0] + ".bin")) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--images-folder', type=str, required=True, help='path to the folder with test images') + parser.add_argument('--output-folder', type=str, default='fots_test_results', + help='path to the output folder with result labels') + + args = parser.parse_args() + + preprocess(args.images_folder, args.output_folder) + + diff --git a/ACL_PyTorch/contrib/cv/detection/FOTS/readme.md b/ACL_PyTorch/contrib/cv/detection/FOTS/readme.md index 36cf5bc66656c6c57fcd539f8af54617581cc022..e531e311ac445f7d74276c1461490e1f46d8ac03 100644 --- a/ACL_PyTorch/contrib/cv/detection/FOTS/readme.md +++ b/ACL_PyTorch/contrib/cv/detection/FOTS/readme.md @@ -1,142 +1,142 @@ -## FOTS Onnx 模型 PyTorch 离线推理 - -### 1 模型概述 - -- 论文地址 - -``` -https://arxiv.org/abs/1801.01671 -``` - -- 代码地址 - -``` -https://github.com/Wovchena/text-detection-fots.pytorch -``` - -- 数据集 - -``` -下载使用ICDAR2015数据集: -解压后将ch4_test_images文件夹和gt.zip压缩标签文件放到根目录下 -``` - -### 2 环境说明 - -``` -CANN = 5.0.3 -pytorch = 1.5.0 -torchvision = 0.6.0 -onnx = 1.7.0 -numpy = 1.21.2 -shapely = 1.6.4.post2(重要) -polygon3 = 3.0.9.1 -opencv-python = 3.4.10.37(重要) -``` - -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip install 包名 安装 - - - -### 3 pth 转 om 模型 - -- pth 权重文件默认路径为根目录 -- 进入根目录下执行 `./test/pth2onnx.sh` 脚本,自动生成生成 onnx 模型文件 -- (执行./pth2onnx_8.sh脚本,生成batchsize=8的onnx模型文件) - -```py -bash ./test/pth2onnx.sh -``` - -- 执行 `./onnx2om.sh` 脚本,自动生成生成 om 模型文件 -- (执行./onnx2om_8.sh脚本,生成batchsize=8的om模型文件) - -```py -bash ./test/onnx2om.sh -``` - - -### 4 生成输入数据并保存为.bin文件 - -- 数据集默认路径为 `./ch4_test_images.zip` , 解压此数据集,在源码根目录下建立空文件夹用来保存预处理后的二进制图片,命名为res - - - -- 使用脚本 `preprocess.sh`和`gen_dataset_info.sh` 获得预处理图片、二进制 bin 文件及其对应的路径信息 - -``` -bash ./test/preprocess.sh -bash ./test/gen_dataset_info.sh -``` - - -### 5 离线推理 - -#### 5.1 benchmark工具概述 - -benchmark工具提供离线推理功能,输入 om 模型和模型所需要的输入 bin 文件,输出模型的输出数据文件。模型必须是通过 atc 工具转换的 om 模型,输入 bin 文件需要符合模型的输入要求。 - - -#### 5.2 离线推理 - -``` -bash ./test/inference.sh -``` -- (执行bash ./test/inference_8.sh脚本生成batchsize=8的二进制推理文件) - - -输出数据默认保存在根目录的 `./result/pref_visionbatchsize_1_device_0.txt` 中,可以看到时延和 FPS。输出图片默认保存在根目录的 `./result/dumpOutput_device0` 下. - - -### 6 精度对比 - -进入根目录下建立空文件夹用来保存后处理的坐标信息,命名为outPost。调用 ` postprocess.py` 来进行后处理,把输出的 bin 文件转换为对应坐标信息的txt文件。 - -``` -python postprocess.py - -``` - - -- (执行 python postprocess_8.py输出batchsize=8推理的后处理文件) - -详细的坐标信息结果在根目录的outPost/目录下,在根目录下建立空文件夹runs。调用 ` script.py` 来进行精度计算,将输出结果与真实标签比对。 - - -``` -zip -jmq runs/u.zip outPost/* && python3 script.py -g=gt.zip -s=runs/u.zip -``` - -### 7 性能对比 - -#### 7.1 NPU 310 性能数据 -``` -(310 bs1) Inference average time: 9.9045 ms -(310 bs1) FPS:39.618 -``` - -根据时延和核心数,计算得到 Batchsize = 1 时单卡吞吐率 39.618 FPS - -``` -(310 bs8) Inference average time: 9.3025 ms -(310 bs8) FPS:37.210 -``` - -根据时延和核心数,计算得到 Batchsize = 8 时单卡吞吐率 37.210 FPS - -#### 7.2 GPU T4 性能数据 - - -根据时延和核心数,计算得到 Batchsize = 1 时单卡吞吐率 44.704 FPS - - -根据时延和核心数,计算得到 Batchsize = 8 时单卡吞吐率 47.271 FPS - -#### 7.3 性能对比 - -| Batch Size | 310 (FPS/Card) | T4 (FPS/Card) | 310/T4 | -| ---------- | -------------- | ------------- | -------- | -| 1 | *39.618* | *44.704* | *88.62%* | -| 8 | *37.210* | *47.271* | *78.71%* | +## FOTS Onnx 模型 PyTorch 离线推理 + +### 1 模型概述 + +- 论文地址 + +``` +https://arxiv.org/abs/1801.01671 +``` + +- 代码地址 + +``` +https://github.com/Wovchena/text-detection-fots.pytorch +``` + +- 数据集 + +``` +下载使用ICDAR2015数据集: +解压后将ch4_test_images文件夹和gt.zip压缩标签文件放到根目录下 +``` + +### 2 环境说明 + +``` +CANN = 5.0.3 +pytorch = 1.5.0 +torchvision = 0.6.0 +onnx = 1.7.0 +numpy = 1.21.2 +shapely = 1.6.4.post2(重要) +polygon3 = 3.0.9.1 +opencv-python = 3.4.10.37(重要) +``` + +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip install 包名 安装 + + + +### 3 pth 转 om 模型 + +- pth 权重文件默认路径为根目录 +- 进入根目录下执行 `./test/pth2onnx.sh` 脚本,自动生成生成 onnx 模型文件 +- (执行./pth2onnx_8.sh脚本,生成batchsize=8的onnx模型文件) + +```py +bash ./test/pth2onnx.sh +``` + +- 执行 `./onnx2om.sh` 脚本,自动生成生成 om 模型文件 +- (执行./onnx2om_8.sh脚本,生成batchsize=8的om模型文件) + +```py +bash ./test/onnx2om.sh +``` + + +### 4 生成输入数据并保存为.bin文件 + +- 数据集默认路径为 `./ch4_test_images.zip` , 解压此数据集,在源码根目录下建立空文件夹用来保存预处理后的二进制图片,命名为res + + + +- 使用脚本 `preprocess.sh`和`gen_dataset_info.sh` 获得预处理图片、二进制 bin 文件及其对应的路径信息 + +``` +bash ./test/preprocess.sh +bash ./test/gen_dataset_info.sh +``` + + +### 5 离线推理 + +#### 5.1 benchmark工具概述 + +benchmark工具提供离线推理功能,输入 om 模型和模型所需要的输入 bin 文件,输出模型的输出数据文件。模型必须是通过 atc 工具转换的 om 模型,输入 bin 文件需要符合模型的输入要求。 + + +#### 5.2 离线推理 + +``` +bash ./test/inference.sh +``` +- (执行bash ./test/inference_8.sh脚本生成batchsize=8的二进制推理文件) + + +输出数据默认保存在根目录的 `./result/pref_visionbatchsize_1_device_0.txt` 中,可以看到时延和 FPS。输出图片默认保存在根目录的 `./result/dumpOutput_device0` 下. + + +### 6 精度对比 + +进入根目录下建立空文件夹用来保存后处理的坐标信息,命名为outPost。调用 ` postprocess.py` 来进行后处理,把输出的 bin 文件转换为对应坐标信息的txt文件。 + +``` +python postprocess.py + +``` + + +- (执行 python postprocess_8.py输出batchsize=8推理的后处理文件) + +详细的坐标信息结果在根目录的outPost/目录下,在根目录下建立空文件夹runs。调用 ` script.py` 来进行精度计算,将输出结果与真实标签比对。 + + +``` +zip -jmq runs/u.zip outPost/* && python3 script.py -g=gt.zip -s=runs/u.zip +``` + +### 7 性能对比 + +#### 7.1 NPU 310 性能数据 +``` +(310 bs1) Inference average time: 9.9045 ms +(310 bs1) FPS:39.618 +``` + +根据时延和核心数,计算得到 Batchsize = 1 时单卡吞吐率 39.618 FPS + +``` +(310 bs8) Inference average time: 9.3025 ms +(310 bs8) FPS:37.210 +``` + +根据时延和核心数,计算得到 Batchsize = 8 时单卡吞吐率 37.210 FPS + +#### 7.2 GPU T4 性能数据 + + +根据时延和核心数,计算得到 Batchsize = 1 时单卡吞吐率 44.704 FPS + + +根据时延和核心数,计算得到 Batchsize = 8 时单卡吞吐率 47.271 FPS + +#### 7.3 性能对比 + +| Batch Size | 310 (FPS/Card) | T4 (FPS/Card) | 310/T4 | +| ---------- | -------------- | ------------- | -------- | +| 1 | *39.618* | *44.704* | *88.62%* | +| 8 | *37.210* | *47.271* | *78.71%* | diff --git a/ACL_PyTorch/contrib/cv/detection/FOTS/requirments.txt b/ACL_PyTorch/contrib/cv/detection/FOTS/requirments.txt index bd61e6482dfef890063a792a0df534556e61243a..f53442ac04e9592cf6dbbbfd436ca9a6fedacfd3 100644 --- a/ACL_PyTorch/contrib/cv/detection/FOTS/requirments.txt +++ b/ACL_PyTorch/contrib/cv/detection/FOTS/requirments.txt @@ -1,12 +1,12 @@ -numpy=1.21.2 -onnx=1.7.0 -opencv-python=3.4.10.37 -opencv-python3=1.0 -Pillow=8.3.2 -Polygon3=3.0.9.1 -Shapely=1.6.4.post2 -torch=1.5.0 -torchvision=0.6.0 - - - +numpy=1.21.2 +onnx=1.7.0 +opencv-python=3.4.10.37 +opencv-python3=1.0 +Pillow=8.3.2 +Polygon3=3.0.9.1 +Shapely=1.6.4.post2 +torch=1.5.0 +torchvision=0.6.0 + + + diff --git a/ACL_PyTorch/contrib/cv/detection/FasterRCNN_FPN_DCN/README.md b/ACL_PyTorch/contrib/cv/detection/FasterRCNN_FPN_DCN/README.md index be4a4f60efe35fd7d62da530181c7f057094e934..a47a439a37678806cca3acb0fb5635166ec267ea 100644 --- a/ACL_PyTorch/contrib/cv/detection/FasterRCNN_FPN_DCN/README.md +++ b/ACL_PyTorch/contrib/cv/detection/FasterRCNN_FPN_DCN/README.md @@ -1,79 +1,79 @@ -# FasterRCNN-FPN-DCN模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - -``` -pip3.7 install -r requirements.txt -``` - 说明:PyTorch选用开源1.8.0版本 -2.获取,修改与安装开源模型代码 - -``` -git clone https://github.com/open-mmlab/mmcv -b master -cd mmcv -git checkout v1.2.7 -MMCV_WITH_OPS=1 pip3.7 install -e . -patch -p1 < ../mmcv.patch -cd .. -git clone https://github.com/open-mmlab/mmdetection -b master -cd mmdetection -git reset --hard a21eb25535f31634cef332b09fc27d28956fb24b -patch -p1 < ../dcn.patch -pip3.7 install -r requirements/build.txt -python3.7 setup.py develop -``` -3.获取权重文件 - -``` -cd mmdetection -mkdir checkpoints -cd checkpoints - -``` - -[faster_rcnn_r50_fpn_dconv_c3-c5_1x_coco_20200130-d68aed1e.pth](参照指导书文档) -4.数据集 - -[测试集]参照指导书文档 -[标签]参照指导书文档 - -5.[获取benchmark工具](参照指导书文档) - 将benchmark.x86_64或benchmark.aarch64放到当前目录 - - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 - -``` -#OM model generation -bash test/pth2onnx.sh -bash test/onnx2om.sh - -#COCO dataset preprocess -python3.7 FasterRCNN+FPN+DCN_preprocess.py --image_folder_path coco/val2017 --bin_folder_path coco2017_bin -python3.7 gen_dataset_info.py bin coco2017_bin coco2017_bin.info 1216 1216 -python3.7 gen_dataset_info.py jpg coco/val2017 coco2017_jpg.info - -#OM model inference -bash test/inf.sh - -#Inference result postprocess -python3.7 FasterRCNN+FPN+DCN_postprocess.py --test_annotation coco2017_jpg.info --bin_data_path result/dumpOutput_device0 - -#COCO eval -python3.7 txt2json.py --npu_txt_path detection-results --json_output_file coco_detection_result -python3.7 coco_eval.py --groud_truth coco/annotations/instances_val2017.json --detection_result coco_detection_result.json - -#FrameRate eval -bash test/framerate.sh -``` - -**评测结果:** - -| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| ---- | ------------------------------------------------------------ | --------------- | -------- | ------- | -| faster_rcnn_r50_fpn_dcn | [box AP:41.3%](https://github.com/open-mmlab/mmdetection/tree/master/configs/dcn) | box AP:41.2% | 5.2fps | 2.8fps | - +# FasterRCNN-FPN-DCN模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + +``` +pip3.7 install -r requirements.txt +``` + 说明:PyTorch选用开源1.8.0版本 +2.获取,修改与安装开源模型代码 + +``` +git clone https://github.com/open-mmlab/mmcv -b master +cd mmcv +git checkout v1.2.7 +MMCV_WITH_OPS=1 pip3.7 install -e . +patch -p1 < ../mmcv.patch +cd .. +git clone https://github.com/open-mmlab/mmdetection -b master +cd mmdetection +git reset --hard a21eb25535f31634cef332b09fc27d28956fb24b +patch -p1 < ../dcn.patch +pip3.7 install -r requirements/build.txt +python3.7 setup.py develop +``` +3.获取权重文件 + +``` +cd mmdetection +mkdir checkpoints +cd checkpoints + +``` + +[faster_rcnn_r50_fpn_dconv_c3-c5_1x_coco_20200130-d68aed1e.pth](参照指导书文档) +4.数据集 + +[测试集]参照指导书文档 +[标签]参照指导书文档 + +5.[获取benchmark工具](参照指导书文档) + 将benchmark.x86_64或benchmark.aarch64放到当前目录 + + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 + +``` +#OM model generation +bash test/pth2onnx.sh +bash test/onnx2om.sh + +#COCO dataset preprocess +python3.7 FasterRCNN+FPN+DCN_preprocess.py --image_folder_path coco/val2017 --bin_folder_path coco2017_bin +python3.7 gen_dataset_info.py bin coco2017_bin coco2017_bin.info 1216 1216 +python3.7 gen_dataset_info.py jpg coco/val2017 coco2017_jpg.info + +#OM model inference +bash test/inf.sh + +#Inference result postprocess +python3.7 FasterRCNN+FPN+DCN_postprocess.py --test_annotation coco2017_jpg.info --bin_data_path result/dumpOutput_device0 + +#COCO eval +python3.7 txt2json.py --npu_txt_path detection-results --json_output_file coco_detection_result +python3.7 coco_eval.py --groud_truth coco/annotations/instances_val2017.json --detection_result coco_detection_result.json + +#FrameRate eval +bash test/framerate.sh +``` + +**评测结果:** + +| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| ---- | ------------------------------------------------------------ | --------------- | -------- | ------- | +| faster_rcnn_r50_fpn_dcn | [box AP:41.3%](https://github.com/open-mmlab/mmdetection/tree/master/configs/dcn) | box AP:41.2% | 5.2fps | 2.8fps | + diff --git a/ACL_PyTorch/contrib/cv/detection/Fsaf/Fsaf_preprocess.py b/ACL_PyTorch/contrib/cv/detection/Fsaf/Fsaf_preprocess.py index 8192a5338abae754193ea8826a63cedf09555b8f..373e2362accb87644c0b7433e8ac02bf887ce6b9 100644 --- a/ACL_PyTorch/contrib/cv/detection/Fsaf/Fsaf_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/Fsaf/Fsaf_preprocess.py @@ -1,73 +1,73 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import argparse -import numpy as np -import cv2 -import mmcv -import torch -import multiprocessing - -def resize(img, size): - old_h = img.shape[0] - old_w = img.shape[1] - scale_ratio = min(size[0] / old_w, size[1] / old_h) - new_w = int(np.floor(old_w * scale_ratio)) - new_h = int(np.floor(old_h * scale_ratio)) - resized_img = mmcv.imresize(img, (new_w, new_h), backend='cv2') - return resized_img - -def gen_input_bin(file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - image = mmcv.imread(os.path.join(flags.image_src_path, file), backend='cv2') - image = resize(image, (flags.model_input_width, flags.model_input_height)) - mean = np.array([123.675, 116.28, 103.53], dtype=np.float32) - std = np.array([58.395, 57.12, 57.375], dtype=np.float32) - image = mmcv.imnormalize(image, mean, std, to_rgb=True) - h = image.shape[0] - w = image.shape[1] - pad_left = (flags.model_input_width - w) // 2 - pad_top = (flags.model_input_height - h) // 2 - pad_right = flags.model_input_width - pad_left - w - pad_bottom = flags.model_input_height - pad_top - h - image = mmcv.impad(image, shape=(flags.model_input_height, flags.model_input_width), pad_val=0) - #mmcv.imwrite(image, './paded_jpg/' + file.split('.')[0] + '.jpg') - image = image.transpose(2, 0, 1) - image.tofile(os.path.join(flags.bin_file_path, file.split('.')[0] + ".bin")) - -def preprocess(src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 100] for i in range(0, 5000, 100) if files[i:i + 100] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='preprocess of MaskRCNN PyTorch model') - parser.add_argument("--image_src_path", default="./coco2017/", help='image of dataset') - parser.add_argument("--bin_file_path", default="./coco2017_bin/", help='Preprocessed image buffer') - parser.add_argument("--model_input_height", default=800, type=int, help='input tensor height') - parser.add_argument("--model_input_width", default=1216, type=int, help='input tensor width') - flags = parser.parse_args() - if not os.path.exists(flags.bin_file_path): - os.makedirs(flags.bin_file_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import argparse +import numpy as np +import cv2 +import mmcv +import torch +import multiprocessing + +def resize(img, size): + old_h = img.shape[0] + old_w = img.shape[1] + scale_ratio = min(size[0] / old_w, size[1] / old_h) + new_w = int(np.floor(old_w * scale_ratio)) + new_h = int(np.floor(old_h * scale_ratio)) + resized_img = mmcv.imresize(img, (new_w, new_h), backend='cv2') + return resized_img + +def gen_input_bin(file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + image = mmcv.imread(os.path.join(flags.image_src_path, file), backend='cv2') + image = resize(image, (flags.model_input_width, flags.model_input_height)) + mean = np.array([123.675, 116.28, 103.53], dtype=np.float32) + std = np.array([58.395, 57.12, 57.375], dtype=np.float32) + image = mmcv.imnormalize(image, mean, std, to_rgb=True) + h = image.shape[0] + w = image.shape[1] + pad_left = (flags.model_input_width - w) // 2 + pad_top = (flags.model_input_height - h) // 2 + pad_right = flags.model_input_width - pad_left - w + pad_bottom = flags.model_input_height - pad_top - h + image = mmcv.impad(image, shape=(flags.model_input_height, flags.model_input_width), pad_val=0) + #mmcv.imwrite(image, './paded_jpg/' + file.split('.')[0] + '.jpg') + image = image.transpose(2, 0, 1) + image.tofile(os.path.join(flags.bin_file_path, file.split('.')[0] + ".bin")) + +def preprocess(src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 100] for i in range(0, 5000, 100) if files[i:i + 100] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='preprocess of MaskRCNN PyTorch model') + parser.add_argument("--image_src_path", default="./coco2017/", help='image of dataset') + parser.add_argument("--bin_file_path", default="./coco2017_bin/", help='Preprocessed image buffer') + parser.add_argument("--model_input_height", default=800, type=int, help='input tensor height') + parser.add_argument("--model_input_width", default=1216, type=int, help='input tensor width') + flags = parser.parse_args() + if not os.path.exists(flags.bin_file_path): + os.makedirs(flags.bin_file_path) preprocess(flags.image_src_path, flags.bin_file_path) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Fsaf/README.md b/ACL_PyTorch/contrib/cv/detection/Fsaf/README.md index 5e40863e926ddbec695e5de02e12127833b46c24..3752277155f21ad5467b7bb2304a5ab442f5def3 100644 --- a/ACL_PyTorch/contrib/cv/detection/Fsaf/README.md +++ b/ACL_PyTorch/contrib/cv/detection/Fsaf/README.md @@ -1,54 +1,54 @@ -# Fsaf模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - -``` -pip3.7 install -r requirements.txt -``` - 说明:PyTorch选用开源1.8.0版本 -2.获取,修改与安装开源模型代码 - -``` -git clone https://github.com/open-mmlab/mmcv -b master -git reset --hard 04daea425bcb0a104d8b4acbbc16bd31304cf168 -cd mmcv -MMCV_WITH_OPS=1 pip3.7 install -e . -cd .. -git clone https://github.com/open-mmlab/mmdetection -b master -git reset --hard 604bfe9618533949c74002a4e54f972e57ad0a7a -cd mmdetection -patch -p1 < ../fsaf.diff -pip3.7 install -r requirements/build.txt -python3.7 setup.py develop -``` -3.获取权重文件 - -[fsaf_r50_fpn_1x_coco-94ccc51f.pth](https://download.openmmlab.com/mmdetection/v2.0/fsaf/fsaf_r50_fpn_1x_coco/fsaf_r50_fpn_1x_coco-94ccc51f.pth) - -4.数据集 - -[测试集](http://images.cocodataset.org/zips/val2017.zip):coco/val2017/ -[标签](http://images.cocodataset.org/annotations/annotations_trainval2017.zip):coco/annotations/instances_val2017.json - -5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) - 将benchmark.x86_64或benchmark.aarch64放到当前目录 - - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 - -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets -``` - -**评测结果:** - -| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| ---- | ------------------------------------------------------------ | --------------- | -------- | ------- | -| Fsaf | [box AP:37.4%](https://github.com/open-mmlab/mmdetection/tree/master/configs/fsaf) | box AP:37.1% | 8.9fps | 40.0fps | -| Fsaf | [box AP:37.4%](https://github.com/open-mmlab/mmdetection/tree/master/configs/fsaf) | box AP:37.1% | 6.9fps | 40.0fps | - +# Fsaf模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + +``` +pip3.7 install -r requirements.txt +``` + 说明:PyTorch选用开源1.8.0版本 +2.获取,修改与安装开源模型代码 + +``` +git clone https://github.com/open-mmlab/mmcv -b master +git reset --hard 04daea425bcb0a104d8b4acbbc16bd31304cf168 +cd mmcv +MMCV_WITH_OPS=1 pip3.7 install -e . +cd .. +git clone https://github.com/open-mmlab/mmdetection -b master +git reset --hard 604bfe9618533949c74002a4e54f972e57ad0a7a +cd mmdetection +patch -p1 < ../fsaf.diff +pip3.7 install -r requirements/build.txt +python3.7 setup.py develop +``` +3.获取权重文件 + +[fsaf_r50_fpn_1x_coco-94ccc51f.pth](https://download.openmmlab.com/mmdetection/v2.0/fsaf/fsaf_r50_fpn_1x_coco/fsaf_r50_fpn_1x_coco-94ccc51f.pth) + +4.数据集 + +[测试集](http://images.cocodataset.org/zips/val2017.zip):coco/val2017/ +[标签](http://images.cocodataset.org/annotations/annotations_trainval2017.zip):coco/annotations/instances_val2017.json + +5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) + 将benchmark.x86_64或benchmark.aarch64放到当前目录 + + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 + +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets +``` + +**评测结果:** + +| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| ---- | ------------------------------------------------------------ | --------------- | -------- | ------- | +| Fsaf | [box AP:37.4%](https://github.com/open-mmlab/mmdetection/tree/master/configs/fsaf) | box AP:37.1% | 8.9fps | 40.0fps | +| Fsaf | [box AP:37.4%](https://github.com/open-mmlab/mmdetection/tree/master/configs/fsaf) | box AP:37.1% | 6.9fps | 40.0fps | + diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/LICENSE b/ACL_PyTorch/contrib/cv/detection/GFocalV2/LICENSE index df2c2f2c3e55bfbad1aebe53321a94ee5a3854bc..c8ec075d5b892f823d0b485ad4fdd01355c57b3e 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/LICENSE +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/LICENSE @@ -1,203 +1,203 @@ -Copyright 2018-2019 Open-MMLab. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2018-2019 Open-MMLab. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and +Copyright 2018-2019 Open-MMLab. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2019 Open-MMLab. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md index 7b2c3f63d1fc4ffbe8e6217c6b92230c84a1de17..4c92474202f8af5adf3f2cf99d38404478beedc0 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/README.md @@ -1,60 +1,60 @@ -# GFocalV2模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -``` -pip3.7 install -r requirements.txt -``` -说明:PyTorch选用开源1.8.0版本 - - - -2.获取,修改与安装开源模型代码 -安装mmcv -```shell -git clone https://github.com/open-mmlab/mmcv -b v1.2.7 -cd mmcv -MMCV_WITH_OPS=1 pip3.7 install -e . -cd .. -``` -获取GFocalV2代码 -``` -git clone https://github.com/implus/GFocalV2.git -b master -cd GFocalV2 -git reset --hard b7b355631daaf776e097a6e137501aa27ff7e757 -patch -p1 < ../GFocalV2.diff -python3.7 setup.py develop -cd .. -``` - -3.获取权重文件 - -[gfocalv2预训练的pth权重文件](https://drive.google.com/file/d/1wSE9-c7tcQwIDPC6Vm_yfOokdPfmYmy7/view?usp=sharing) - -4.数据集 -[coco2017](https://cocodataset.org/#download),下载其中val2017图片及其标注文件,放入服务器/root/dataset/coco/文件夹,val2017目录存放coco数据集的验证集图片,annotations目录存放coco数据集的instances_val2017.json,文件目录结构如下: -``` -root -├── dataset -│ ├── coco -│ │ ├── annotations -│ │ ├── val2017 -``` - -5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) -将benchmark.x86_64或benchmark.aarch64放到当前目录 - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets -``` - **评测结果:** -| 模型 | 在线推理精度 | 310离线推理精度 | 基准性能 | 310性能 | -| :------: | :------: | :------: | :------: | :------: | -| GFocalV2 bs1 | mAP:41.0% | mAP:40.6% | 7.9fps | 12.071fps | - +# GFocalV2模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip3.7 install -r requirements.txt +``` +说明:PyTorch选用开源1.8.0版本 + + + +2.获取,修改与安装开源模型代码 +安装mmcv +```shell +git clone https://github.com/open-mmlab/mmcv -b v1.2.7 +cd mmcv +MMCV_WITH_OPS=1 pip3.7 install -e . +cd .. +``` +获取GFocalV2代码 +``` +git clone https://github.com/implus/GFocalV2.git -b master +cd GFocalV2 +git reset --hard b7b355631daaf776e097a6e137501aa27ff7e757 +patch -p1 < ../GFocalV2.diff +python3.7 setup.py develop +cd .. +``` + +3.获取权重文件 + +[gfocalv2预训练的pth权重文件](https://drive.google.com/file/d/1wSE9-c7tcQwIDPC6Vm_yfOokdPfmYmy7/view?usp=sharing) + +4.数据集 +[coco2017](https://cocodataset.org/#download),下载其中val2017图片及其标注文件,放入服务器/root/dataset/coco/文件夹,val2017目录存放coco数据集的验证集图片,annotations目录存放coco数据集的instances_val2017.json,文件目录结构如下: +``` +root +├── dataset +│ ├── coco +│ │ ├── annotations +│ │ ├── val2017 +``` + +5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) +将benchmark.x86_64或benchmark.aarch64放到当前目录 + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets +``` + **评测结果:** +| 模型 | 在线推理精度 | 310离线推理精度 | 基准性能 | 310性能 | +| :------: | :------: | :------: | :------: | :------: | +| GFocalV2 bs1 | mAP:41.0% | mAP:40.6% | 7.9fps | 12.071fps | + 备注:离线模型不支持多batch。 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/get_info.py b/ACL_PyTorch/contrib/cv/detection/GFocalV2/get_info.py index b76d6739bcea5c528a031970f0e583e5b5644bd8..d5cab0450c20d502d0d15be2f9c0fceffa6a6191 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/get_info.py +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/get_info.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py b/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py index 49b2e77560ba1c725db42173196d0de961be9be6..6a779abac4db61911c08eaed3c240d3477c3e955 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_postprocess.py @@ -1,89 +1,89 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import argparse -import glob -import numpy as np -import cv2 -import torch -from mmdet.core import bbox2result -from mmdet.datasets import CocoDataset - - -def postprocess_bboxes(bboxes, image_size, net_input_width, net_input_height): - org_w = image_size[0] - org_h = image_size[1] - scale = min(net_input_width / org_w, net_input_height / org_h) - bboxes[:, 0] = (bboxes[:, 0]) / scale - bboxes[:, 1] = (bboxes[:, 1]) / scale - bboxes[:, 2] = (bboxes[:, 2]) / scale - bboxes[:, 3] = (bboxes[:, 3]) / scale - return bboxes - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--test_annotation", default="./origin_pictures.info") - parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0") - parser.add_argument("--net_out_num", type=int, default=3) - parser.add_argument("--net_input_width", type=int, default=1216) - parser.add_argument("--net_input_height", type=int, default=800) - parser.add_argument("--annotations_path", default="/root/datasets") - flags = parser.parse_args() - - img_size_dict = dict() - with open(flags.test_annotation)as f: - for line in f.readlines(): - temp = line.split(" ") - img_file_path = temp[1] - img_name = temp[1].split("/")[-1].split(".")[0] - img_width = int(temp[2]) - img_height = int(temp[3]) - img_size_dict[img_name] = (img_width, img_height, img_file_path) - - bin_path = flags.bin_data_path - - coco_dataset = CocoDataset(ann_file='{}/coco/annotations/instances_val2017.json'.format(flags.annotations_path), pipeline=[]) - coco_class_map = {id:name for id, name in enumerate(coco_dataset.CLASSES)} - results = [] - cnt = 0 - for ids in coco_dataset.img_ids: - cnt = cnt + 1 - bin_file = glob.glob(bin_path + '/*0' + str(ids) + '_1.bin')[0] - bin_file = bin_file[bin_file.rfind('/') + 1:] - bin_file = bin_file[:bin_file.rfind('_')] - print(cnt - 1, bin_file) - path_base = os.path.join(bin_path, bin_file) - - res_buff = [] - bbox_results = [] - cls_segms = [] - if os.path.exists(path_base + "_" + "1" + ".bin") and os.path.exists(path_base + "_" + "2" + ".bin"): - bboxes = np.fromfile(path_base + "_" + str(flags.net_out_num - 1) + ".bin", dtype="float32") - bboxes = np.reshape(bboxes, [100, 5]) - bboxes = torch.from_numpy(bboxes) - labels = np.fromfile(path_base + "_" + str(flags.net_out_num - 2) + ".bin", dtype="int64") - labels = np.reshape(labels, [100, 1]) - labels = torch.from_numpy(labels) - - img_shape = (flags.net_input_height, flags.net_input_width) - bboxes = postprocess_bboxes(bboxes, img_size_dict[bin_file], flags.net_input_width, flags.net_input_height) - bbox_results = [bbox2result(bboxes, labels[:, 0], 80)] - else: - print("[ERROR] file not exist", path_base + "_" + str(1) + ".bin",path_base + "_" + str(2) + ".bin") - - result = bbox_results - results.extend(result) - - eval_results = coco_dataset.evaluate(results, metric=['bbox', ], classwise=True) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import argparse +import glob +import numpy as np +import cv2 +import torch +from mmdet.core import bbox2result +from mmdet.datasets import CocoDataset + + +def postprocess_bboxes(bboxes, image_size, net_input_width, net_input_height): + org_w = image_size[0] + org_h = image_size[1] + scale = min(net_input_width / org_w, net_input_height / org_h) + bboxes[:, 0] = (bboxes[:, 0]) / scale + bboxes[:, 1] = (bboxes[:, 1]) / scale + bboxes[:, 2] = (bboxes[:, 2]) / scale + bboxes[:, 3] = (bboxes[:, 3]) / scale + return bboxes + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--test_annotation", default="./origin_pictures.info") + parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0") + parser.add_argument("--net_out_num", type=int, default=3) + parser.add_argument("--net_input_width", type=int, default=1216) + parser.add_argument("--net_input_height", type=int, default=800) + parser.add_argument("--annotations_path", default="/root/datasets") + flags = parser.parse_args() + + img_size_dict = dict() + with open(flags.test_annotation)as f: + for line in f.readlines(): + temp = line.split(" ") + img_file_path = temp[1] + img_name = temp[1].split("/")[-1].split(".")[0] + img_width = int(temp[2]) + img_height = int(temp[3]) + img_size_dict[img_name] = (img_width, img_height, img_file_path) + + bin_path = flags.bin_data_path + + coco_dataset = CocoDataset(ann_file='{}/coco/annotations/instances_val2017.json'.format(flags.annotations_path), pipeline=[]) + coco_class_map = {id:name for id, name in enumerate(coco_dataset.CLASSES)} + results = [] + cnt = 0 + for ids in coco_dataset.img_ids: + cnt = cnt + 1 + bin_file = glob.glob(bin_path + '/*0' + str(ids) + '_1.bin')[0] + bin_file = bin_file[bin_file.rfind('/') + 1:] + bin_file = bin_file[:bin_file.rfind('_')] + print(cnt - 1, bin_file) + path_base = os.path.join(bin_path, bin_file) + + res_buff = [] + bbox_results = [] + cls_segms = [] + if os.path.exists(path_base + "_" + "1" + ".bin") and os.path.exists(path_base + "_" + "2" + ".bin"): + bboxes = np.fromfile(path_base + "_" + str(flags.net_out_num - 1) + ".bin", dtype="float32") + bboxes = np.reshape(bboxes, [100, 5]) + bboxes = torch.from_numpy(bboxes) + labels = np.fromfile(path_base + "_" + str(flags.net_out_num - 2) + ".bin", dtype="int64") + labels = np.reshape(labels, [100, 1]) + labels = torch.from_numpy(labels) + + img_shape = (flags.net_input_height, flags.net_input_width) + bboxes = postprocess_bboxes(bboxes, img_size_dict[bin_file], flags.net_input_width, flags.net_input_height) + bbox_results = [bbox2result(bboxes, labels[:, 0], 80)] + else: + print("[ERROR] file not exist", path_base + "_" + str(1) + ".bin",path_base + "_" + str(2) + ".bin") + + result = bbox_results + results.extend(result) + + eval_results = coco_dataset.evaluate(results, metric=['bbox', ], classwise=True) diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_preprocess.py b/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_preprocess.py index 8192a5338abae754193ea8826a63cedf09555b8f..373e2362accb87644c0b7433e8ac02bf887ce6b9 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/gfocal_preprocess.py @@ -1,73 +1,73 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import argparse -import numpy as np -import cv2 -import mmcv -import torch -import multiprocessing - -def resize(img, size): - old_h = img.shape[0] - old_w = img.shape[1] - scale_ratio = min(size[0] / old_w, size[1] / old_h) - new_w = int(np.floor(old_w * scale_ratio)) - new_h = int(np.floor(old_h * scale_ratio)) - resized_img = mmcv.imresize(img, (new_w, new_h), backend='cv2') - return resized_img - -def gen_input_bin(file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - image = mmcv.imread(os.path.join(flags.image_src_path, file), backend='cv2') - image = resize(image, (flags.model_input_width, flags.model_input_height)) - mean = np.array([123.675, 116.28, 103.53], dtype=np.float32) - std = np.array([58.395, 57.12, 57.375], dtype=np.float32) - image = mmcv.imnormalize(image, mean, std, to_rgb=True) - h = image.shape[0] - w = image.shape[1] - pad_left = (flags.model_input_width - w) // 2 - pad_top = (flags.model_input_height - h) // 2 - pad_right = flags.model_input_width - pad_left - w - pad_bottom = flags.model_input_height - pad_top - h - image = mmcv.impad(image, shape=(flags.model_input_height, flags.model_input_width), pad_val=0) - #mmcv.imwrite(image, './paded_jpg/' + file.split('.')[0] + '.jpg') - image = image.transpose(2, 0, 1) - image.tofile(os.path.join(flags.bin_file_path, file.split('.')[0] + ".bin")) - -def preprocess(src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 100] for i in range(0, 5000, 100) if files[i:i + 100] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='preprocess of MaskRCNN PyTorch model') - parser.add_argument("--image_src_path", default="./coco2017/", help='image of dataset') - parser.add_argument("--bin_file_path", default="./coco2017_bin/", help='Preprocessed image buffer') - parser.add_argument("--model_input_height", default=800, type=int, help='input tensor height') - parser.add_argument("--model_input_width", default=1216, type=int, help='input tensor width') - flags = parser.parse_args() - if not os.path.exists(flags.bin_file_path): - os.makedirs(flags.bin_file_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import argparse +import numpy as np +import cv2 +import mmcv +import torch +import multiprocessing + +def resize(img, size): + old_h = img.shape[0] + old_w = img.shape[1] + scale_ratio = min(size[0] / old_w, size[1] / old_h) + new_w = int(np.floor(old_w * scale_ratio)) + new_h = int(np.floor(old_h * scale_ratio)) + resized_img = mmcv.imresize(img, (new_w, new_h), backend='cv2') + return resized_img + +def gen_input_bin(file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + image = mmcv.imread(os.path.join(flags.image_src_path, file), backend='cv2') + image = resize(image, (flags.model_input_width, flags.model_input_height)) + mean = np.array([123.675, 116.28, 103.53], dtype=np.float32) + std = np.array([58.395, 57.12, 57.375], dtype=np.float32) + image = mmcv.imnormalize(image, mean, std, to_rgb=True) + h = image.shape[0] + w = image.shape[1] + pad_left = (flags.model_input_width - w) // 2 + pad_top = (flags.model_input_height - h) // 2 + pad_right = flags.model_input_width - pad_left - w + pad_bottom = flags.model_input_height - pad_top - h + image = mmcv.impad(image, shape=(flags.model_input_height, flags.model_input_width), pad_val=0) + #mmcv.imwrite(image, './paded_jpg/' + file.split('.')[0] + '.jpg') + image = image.transpose(2, 0, 1) + image.tofile(os.path.join(flags.bin_file_path, file.split('.')[0] + ".bin")) + +def preprocess(src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 100] for i in range(0, 5000, 100) if files[i:i + 100] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='preprocess of MaskRCNN PyTorch model') + parser.add_argument("--image_src_path", default="./coco2017/", help='image of dataset') + parser.add_argument("--bin_file_path", default="./coco2017_bin/", help='Preprocessed image buffer') + parser.add_argument("--model_input_height", default=800, type=int, help='input tensor height') + parser.add_argument("--model_input_width", default=1216, type=int, help='input tensor width') + flags = parser.parse_args() + if not os.path.exists(flags.bin_file_path): + os.makedirs(flags.bin_file_path) preprocess(flags.image_src_path, flags.bin_file_path) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/detection/GFocalV2/modelzoo_level.txt index bdc5dd889d3e2c5450f8df13820f5d359f1a7830..5a90c7c76ee637d956ad5517b60434e8838a0ce6 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus: PERFECT \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/requirements.txt b/ACL_PyTorch/contrib/cv/detection/GFocalV2/requirements.txt index 7609cac2ce76e9b4064bd75d9aa284692c4cd1b8..689f4900b87ed60a3ee74f326e95c751e36b6944 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/requirements.txt +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/requirements.txt @@ -1,5 +1,5 @@ -torch == 1.8.0 -torchvision == 0.9.0 -onnx == 1.9.0 -numpy == 1.19.4 +torch == 1.8.0 +torchvision == 0.9.0 +onnx == 1.9.0 +numpy == 1.19.4 opencv-python == 4.4.0.46 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/parse.py b/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/parse.py index b9c74f41d7848e1250356f14472b237a18bb3489..82af69cd183218c3263723c20b652b3f7ec2bc27 100644 --- a/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/parse.py +++ b/ACL_PyTorch/contrib/cv/detection/GFocalV2/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/M2Det/LICENSE b/ACL_PyTorch/contrib/cv/detection/M2Det/LICENSE index 8904c8516082056802ee732a4213ceab8c4a93af..5f7aa69fea22dade3f519868400025de434ae8ca 100644 --- a/ACL_PyTorch/contrib/cv/detection/M2Det/LICENSE +++ b/ACL_PyTorch/contrib/cv/detection/M2Det/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/M2Det/M2Det.patch b/ACL_PyTorch/contrib/cv/detection/M2Det/M2Det.patch index c6d220a060b1615014304df2af943e0f83672e92..d3562619d81843a527cd080c977b771c440d479e 100644 --- a/ACL_PyTorch/contrib/cv/detection/M2Det/M2Det.patch +++ b/ACL_PyTorch/contrib/cv/detection/M2Det/M2Det.patch @@ -3,14 +3,14 @@ index 01d21b1..df49100 100644 --- a/configs/m2det512_vgg.py +++ b/configs/m2det512_vgg.py @@ -2,7 +2,7 @@ model = dict( - type = 'm2det', - input_size = 512, - init_net = True, -- pretrained = 'weights/vgg16_reducedfc.pth', -+ pretrained = 'M2Det/weights/vgg16_reducedfc.pth', - m2det_config = dict( - backbone = 'vgg16', - net_family = 'vgg', # vgg includes ['vgg16','vgg19'], res includes ['resnetxxx','resnextxxx'] + type = 'm2det', + input_size = 512, + init_net = True, +- pretrained = 'weights/vgg16_reducedfc.pth', ++ pretrained = 'M2Det/weights/vgg16_reducedfc.pth', + m2det_config = dict( + backbone = 'vgg16', + net_family = 'vgg', # vgg includes ['vgg16','vgg19'], res includes ['resnetxxx','resnextxxx'] diff --git a/data/coco.py b/data/coco.py index 3784d65..9d07625 100644 --- a/data/coco.py diff --git a/ACL_PyTorch/contrib/cv/detection/M2Det/M2Det_preprocess.py b/ACL_PyTorch/contrib/cv/detection/M2Det/M2Det_preprocess.py index d0f0834ae64a95c2a2796bf3f8b5692af37ac490..c887892e250f27418fdc45c5e65d42aede99a716 100644 --- a/ACL_PyTorch/contrib/cv/detection/M2Det/M2Det_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/M2Det/M2Det_preprocess.py @@ -1,58 +1,58 @@ -''' -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -''' - -import os -import sys -sys.path.insert(0, './M2Det') -import warnings -warnings.filterwarnings('ignore') -import torch -import argparse -import numpy as np -from layers.functions import Detect, PriorBox -from data import BaseTransform -from configs.CC import Config -from utils.core import get_dataloader, print_info - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='M2Det Preprocess') - parser.add_argument('-c', '--config', default='../configs/m2det512_vgg.py', type=str) - parser.add_argument('-d', '--dataset', default='COCO', help='VOC or COCO version') - parser.add_argument('--test', action='store_true', help='to submit a test file') - parser.add_argument("--save_folder", default="./pre_dataset") - parser.add_argument('--COCO_imgs', default="~/data/coco/images", help='COCO images root') - parser.add_argument('--COCO_anns', default="~/data/coco/annotations", help='COCO annotations root') - args = parser.parse_args() - - cfg = Config.fromfile(args.config) - if not os.path.exists(args.save_folder): - os.mkdir(args.save_folder) - - _set = 'eval_sets' if not args.test else 'test_sets' - testset = get_dataloader(args, cfg, args.dataset, _set) - - _preprocess = BaseTransform(cfg.model.input_size, cfg.model.rgb_means, (2, 0, 1)) - num_images = len(testset) - print_info('=> Total {} images to test.'.format(num_images), ['yellow', 'bold']) - - for i in range(num_images): - input_image, img_id= testset.pull_image(i) - img_name = img_id.split('/')[-1] - print(img_name, "===", i) - input_tensor = _preprocess(input_image).unsqueeze(0) - img = np.array(input_tensor).astype(np.float32) - img.tofile(os.path.join(args.save_folder, img_name.split('.')[0] + ".bin")) - +''' +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +''' + +import os +import sys +sys.path.insert(0, './M2Det') +import warnings +warnings.filterwarnings('ignore') +import torch +import argparse +import numpy as np +from layers.functions import Detect, PriorBox +from data import BaseTransform +from configs.CC import Config +from utils.core import get_dataloader, print_info + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='M2Det Preprocess') + parser.add_argument('-c', '--config', default='../configs/m2det512_vgg.py', type=str) + parser.add_argument('-d', '--dataset', default='COCO', help='VOC or COCO version') + parser.add_argument('--test', action='store_true', help='to submit a test file') + parser.add_argument("--save_folder", default="./pre_dataset") + parser.add_argument('--COCO_imgs', default="~/data/coco/images", help='COCO images root') + parser.add_argument('--COCO_anns', default="~/data/coco/annotations", help='COCO annotations root') + args = parser.parse_args() + + cfg = Config.fromfile(args.config) + if not os.path.exists(args.save_folder): + os.mkdir(args.save_folder) + + _set = 'eval_sets' if not args.test else 'test_sets' + testset = get_dataloader(args, cfg, args.dataset, _set) + + _preprocess = BaseTransform(cfg.model.input_size, cfg.model.rgb_means, (2, 0, 1)) + num_images = len(testset) + print_info('=> Total {} images to test.'.format(num_images), ['yellow', 'bold']) + + for i in range(num_images): + input_image, img_id= testset.pull_image(i) + img_name = img_id.split('/')[-1] + print(img_name, "===", i) + input_tensor = _preprocess(input_image).unsqueeze(0) + img = np.array(input_tensor).astype(np.float32) + img.tofile(os.path.join(args.save_folder, img_name.split('.')[0] + ".bin")) + diff --git a/ACL_PyTorch/contrib/cv/detection/M2Det/M2Det_pth2onnx.py b/ACL_PyTorch/contrib/cv/detection/M2Det/M2Det_pth2onnx.py index fb998a894bf109a1fb780aeeb83e7892775be043..b558597d06e2d17d9e560b4995a3530b22d6925c 100644 --- a/ACL_PyTorch/contrib/cv/detection/M2Det/M2Det_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/M2Det/M2Det_pth2onnx.py @@ -1,88 +1,88 @@ -''' -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -''' -import sys -sys.path.insert(0, './M2Det') -import torch -import torch.onnx -from collections import OrderedDict -import argparse -print(sys.path) -from m2det import build_net -import torch.utils.data as data -import torch.backends.cudnn as cudnn -from configs.CC import Config -from utils.core import init_net - - - -parser = argparse.ArgumentParser(description='pth2onnx') -parser.add_argument('-c', '--config', default='M2Det/configs/m2det512_vgg16.py') -parser.add_argument('-d', '--dataset', default='COCO', help='VOC or COCO dataset') -parser.add_argument('--resume_net', default=None, help='resume net for retraining') -parser.add_argument('--resume_epoch', default=0, type=int, help='resume iter for retraining') -parser.add_argument('-pth', '--pth_path', default='weights/m2det512_vgg.pth') -parser.add_argument('-onnx', '--onnx_path', default='m2det512.onnx') -Args = parser.parse_args() - -def proc_nodes_module(checkpoint): - ''' - Args: - checkpoint: Network parameters. - Returns: - Create a new dictionary, remove the unnecessary key value "module" - ''' - new_state_dict = OrderedDict() - for k, v in checkpoint.items(): - if k[0:7] == "module.": - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - - -def convert(args, cfg): - ''' - Args: - args.pth_path: Weight file path - args.onnx_path: onnx file path - cfg: configs - ''' - print('pth:{}'.format(args.pth_path)) - print('onnx:{}'.format(args.onnx_path)) - net = build_net('test', - size = cfg.model.input_size, # Only 320, 512, 704 and 800 are supported - config = cfg.model.m2det_config) - init_net(net, cfg, args.resume_net) - model = net - - checkpoint = torch.load(args.pth_path, map_location='cpu') - checkpoint = proc_nodes_module(checkpoint) - model.load_state_dict(checkpoint) - - model.eval() - input_names = ["image"] - output_names = ["scores", "boxes"] - #dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dynamic_axes = {'image':{0:'-1'}, 'scores':{0:'-1'}, 'boxes':{0:'-1'}} - dummy_input = torch.randn(1, 3, 512, 512) - torch.onnx.export(model, dummy_input, args.onnx_path, input_names = input_names, - dynamic_axes = dynamic_axes, output_names = output_names, - verbose=True, opset_version=11) - -if __name__ == "__main__": - Cfg = Config.fromfile(Args.config) +''' +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +''' +import sys +sys.path.insert(0, './M2Det') +import torch +import torch.onnx +from collections import OrderedDict +import argparse +print(sys.path) +from m2det import build_net +import torch.utils.data as data +import torch.backends.cudnn as cudnn +from configs.CC import Config +from utils.core import init_net + + + +parser = argparse.ArgumentParser(description='pth2onnx') +parser.add_argument('-c', '--config', default='M2Det/configs/m2det512_vgg16.py') +parser.add_argument('-d', '--dataset', default='COCO', help='VOC or COCO dataset') +parser.add_argument('--resume_net', default=None, help='resume net for retraining') +parser.add_argument('--resume_epoch', default=0, type=int, help='resume iter for retraining') +parser.add_argument('-pth', '--pth_path', default='weights/m2det512_vgg.pth') +parser.add_argument('-onnx', '--onnx_path', default='m2det512.onnx') +Args = parser.parse_args() + +def proc_nodes_module(checkpoint): + ''' + Args: + checkpoint: Network parameters. + Returns: + Create a new dictionary, remove the unnecessary key value "module" + ''' + new_state_dict = OrderedDict() + for k, v in checkpoint.items(): + if k[0:7] == "module.": + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + + +def convert(args, cfg): + ''' + Args: + args.pth_path: Weight file path + args.onnx_path: onnx file path + cfg: configs + ''' + print('pth:{}'.format(args.pth_path)) + print('onnx:{}'.format(args.onnx_path)) + net = build_net('test', + size = cfg.model.input_size, # Only 320, 512, 704 and 800 are supported + config = cfg.model.m2det_config) + init_net(net, cfg, args.resume_net) + model = net + + checkpoint = torch.load(args.pth_path, map_location='cpu') + checkpoint = proc_nodes_module(checkpoint) + model.load_state_dict(checkpoint) + + model.eval() + input_names = ["image"] + output_names = ["scores", "boxes"] + #dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dynamic_axes = {'image':{0:'-1'}, 'scores':{0:'-1'}, 'boxes':{0:'-1'}} + dummy_input = torch.randn(1, 3, 512, 512) + torch.onnx.export(model, dummy_input, args.onnx_path, input_names = input_names, + dynamic_axes = dynamic_axes, output_names = output_names, + verbose=True, opset_version=11) + +if __name__ == "__main__": + Cfg = Config.fromfile(Args.config) convert(Args, Cfg) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/M2Det/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/detection/M2Det/gen_dataset_info.py index 6469c60543cf783aa29dad98ca2fef563f467414..5f38ef84a7a1de0aec3d5db61afb7690aaef6e72 100644 --- a/ACL_PyTorch/contrib/cv/detection/M2Det/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/detection/M2Det/gen_dataset_info.py @@ -1,67 +1,67 @@ -''' -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -''' -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(fpath, info_n, width, height): - ''' - Describe - ''' - bin_images = glob(os.path.join(fpath, '*.bin')) - with open(info_n, 'w') as f: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - f.write(content) - f.write('\n') - - -def get_jpg_info(fpath, info_n): - ''' - Describe - ''' - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(fpath, '*.' + extension))) - with open(info_n, 'w') as f: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - f.write(content) - f.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - Width = sys.argv[4] - Height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, Width, Height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +''' +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +''' +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(fpath, info_n, width, height): + ''' + Describe + ''' + bin_images = glob(os.path.join(fpath, '*.bin')) + with open(info_n, 'w') as f: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + f.write(content) + f.write('\n') + + +def get_jpg_info(fpath, info_n): + ''' + Describe + ''' + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(fpath, '*.' + extension))) + with open(info_n, 'w') as f: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + f.write(content) + f.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + Width = sys.argv[4] + Height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, Width, Height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/M2Det/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/detection/M2Det/modelzoo_level.txt index 549f8ae7ed9eb5026c1162667887be52400d428c..a8de6fe278d971859535cbcbcdef13790c657615 100644 --- a/ACL_PyTorch/contrib/cv/detection/M2Det/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/detection/M2Det/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK -PerfStatus:Perfect +FuncStatus:OK +PrecisionStatus:OK +PerfStatus:Perfect diff --git a/ACL_PyTorch/contrib/cv/detection/M2Det/requirements.txt b/ACL_PyTorch/contrib/cv/detection/M2Det/requirements.txt index 69bd8849d492fb0074a6efe6c77792dc2257bdcf..af07e2c553ab82c93b2f884d1fb6b75d2897e525 100644 --- a/ACL_PyTorch/contrib/cv/detection/M2Det/requirements.txt +++ b/ACL_PyTorch/contrib/cv/detection/M2Det/requirements.txt @@ -1,16 +1,16 @@ -torch == 1.8.1 -torchvision == 0.9.1 -onnx == 1.7.0 -numpy == 1.18.5 -Cython == 0.29.24 -opencv-python == 4.5.3.56 -setuptools == 41.2.0 -matplotlib == 2.2.5 -absl-py == 0.13.0 -addict == 2.4.0 -alabaster == 0.7.12 -antlr4-python3-runtime == 4.8 -appdirs == 1.4.4 -asn1crypto == 1.4.0 -astroid == 2.7.3 +torch == 1.8.1 +torchvision == 0.9.1 +onnx == 1.7.0 +numpy == 1.18.5 +Cython == 0.29.24 +opencv-python == 4.5.3.56 +setuptools == 41.2.0 +matplotlib == 2.2.5 +absl-py == 0.13.0 +addict == 2.4.0 +alabaster == 0.7.12 +antlr4-python3-runtime == 4.8 +appdirs == 1.4.4 +asn1crypto == 1.4.0 +astroid == 2.7.3 astropy == 4.3.1 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/NAS_FPN/README.md b/ACL_PyTorch/contrib/cv/detection/NAS_FPN/README.md index 461df59cd3d0ace18de6d08d78fcf534d9a8558a..42191f22e87a6ed7e999a335beaba1670211b971 100644 --- a/ACL_PyTorch/contrib/cv/detection/NAS_FPN/README.md +++ b/ACL_PyTorch/contrib/cv/detection/NAS_FPN/README.md @@ -1,57 +1,57 @@ -# NAS-FPN模型PyTorch离线推理指导 - -## 1 环境准备 - -1. 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - - ``` - pip install -r requirements.txt - ``` - -2. 获取,修改与安装开源模型代码 - - ``` - git clone https://github.com/open-mmlab/mmdetection.git - cd mmdetection - git reset a21eb25535f31634cef332b09fc27d28956fb24b --hard - pip install -v -e . - patch -p1 < ../NAS_FPN.patch - cd .. - ``` - - 利用提供的change文件夹中的patch文件,完成补丁操作,命令参考如下示例,请用户根据安装包位置自行修改: - ``` - cd change - patch -p0 /usr/local/python3.7.5/lib/python3.7/site-packages/mmcv/ops/deform_conv.py deform_conv.patch - patch -p0 /usr/local/python3.7.5/lib/python3.7/site-packages/mmcv/ops/merge_cells.py merge_cells.patch - ``` - - -3. 获取权重文件 - - 从[LINK](https://github.com/open-mmlab/mmdetection/tree/master/configs/nas_fpn)下载nas_fpn模型权重文件 - -4. 数据集 - 本模型使用coco2017的验证集验证 - -5. [获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) -将benchmark.x86_64或benchmark.aarch64放到当前目录 - - - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=./ -``` - -**评测结果:** - -| 模型 | 官网pth精度 | 310离线推理精度 | gpu性能 | 310性能 | -| :---------------: | :---------: | :-------------: | :-----: | :------: | -| NASFPN bs1 | map:0.405 | map:0.404 | 12.7 task/s | 24.750fps | - - - +# NAS-FPN模型PyTorch离线推理指导 + +## 1 环境准备 + +1. 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + + ``` + pip install -r requirements.txt + ``` + +2. 获取,修改与安装开源模型代码 + + ``` + git clone https://github.com/open-mmlab/mmdetection.git + cd mmdetection + git reset a21eb25535f31634cef332b09fc27d28956fb24b --hard + pip install -v -e . + patch -p1 < ../NAS_FPN.patch + cd .. + ``` + + 利用提供的change文件夹中的patch文件,完成补丁操作,命令参考如下示例,请用户根据安装包位置自行修改: + ``` + cd change + patch -p0 /usr/local/python3.7.5/lib/python3.7/site-packages/mmcv/ops/deform_conv.py deform_conv.patch + patch -p0 /usr/local/python3.7.5/lib/python3.7/site-packages/mmcv/ops/merge_cells.py merge_cells.patch + ``` + + +3. 获取权重文件 + + 从[LINK](https://github.com/open-mmlab/mmdetection/tree/master/configs/nas_fpn)下载nas_fpn模型权重文件 + +4. 数据集 + 本模型使用coco2017的验证集验证 + +5. [获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) +将benchmark.x86_64或benchmark.aarch64放到当前目录 + + + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=./ +``` + +**评测结果:** + +| 模型 | 官网pth精度 | 310离线推理精度 | gpu性能 | 310性能 | +| :---------------: | :---------: | :-------------: | :-----: | :------: | +| NASFPN bs1 | map:0.405 | map:0.404 | 12.7 task/s | 24.750fps | + + + diff --git a/ACL_PyTorch/contrib/cv/detection/NAS_FPN/coco_eval.py b/ACL_PyTorch/contrib/cv/detection/NAS_FPN/coco_eval.py index 00c927f23d2031eae523b428361a7b04dccfc0b6..3eb70b7418ffca14458e5fa015eb2822e4a60a22 100644 --- a/ACL_PyTorch/contrib/cv/detection/NAS_FPN/coco_eval.py +++ b/ACL_PyTorch/contrib/cv/detection/NAS_FPN/coco_eval.py @@ -1,92 +1,92 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import numpy as np -from pycocotools.coco import COCO -from pycocotools.cocoeval import COCOeval - -CLASSES = ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', - 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', - 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', - 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', - 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', - 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', - 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', - 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', - 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', - 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', - 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', - 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush') - -def coco_evaluation(annotation_json, result_json): - cocoGt = COCO(annotation_json) - cocoDt = cocoGt.loadRes(result_json) - iou_thrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True) - iou_type = 'bbox' - - cocoEval = COCOeval(cocoGt, cocoDt, iou_type) - cocoEval.params.catIds = cocoGt.get_cat_ids(cat_names=CLASSES) - cocoEval.params.imgIds = cocoGt.get_img_ids() - cocoEval.params.maxDets = [100, 300, 1000] # proposal number for evaluating recalls/mAPs. - cocoEval.params.iouThrs = iou_thrs - - cocoEval.evaluate() - cocoEval.accumulate() - cocoEval.summarize() - - # mapping of cocoEval.stats - coco_metric_names = { - 'mAP': 0, - 'mAP_50': 1, - 'mAP_75': 2, - 'mAP_s': 3, - 'mAP_m': 4, - 'mAP_l': 5, - 'AR@100': 6, - 'AR@300': 7, - 'AR@1000': 8, - 'AR_s@1000': 9, - 'AR_m@1000': 10, - 'AR_l@1000': 11 - } - - metric_items = ['mAP', 'mAP_50', 'mAP_75', 'mAP_s', 'mAP_m', 'mAP_l'] - eval_results = {} - - for metric_item in metric_items: - key = f'bbox_{metric_item}' - val = float( - f'{cocoEval.stats[coco_metric_names[metric_item]]:.3f}' - ) - eval_results[key] = val - ap = cocoEval.stats[:6] - eval_results['bbox_mAP_copypaste'] = ( - f'{ap[0]:.3f} {ap[1]:.3f} {ap[2]:.3f} {ap[3]:.3f} ' - f'{ap[4]:.3f} {ap[5]:.3f}') - - return eval_results - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--ground_truth", default="instances_val2017.json") - parser.add_argument("--detection_result", default="coco_detection_result.json") - args = parser.parse_args() - result = coco_evaluation(args.ground_truth, args.detection_result) - print(result) - with open('./coco_detection_result.txt', 'w') as f: - for key, value in result.items(): +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import numpy as np +from pycocotools.coco import COCO +from pycocotools.cocoeval import COCOeval + +CLASSES = ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', + 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', + 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', + 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', + 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', + 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', + 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', + 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', + 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', + 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', + 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', + 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush') + +def coco_evaluation(annotation_json, result_json): + cocoGt = COCO(annotation_json) + cocoDt = cocoGt.loadRes(result_json) + iou_thrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True) + iou_type = 'bbox' + + cocoEval = COCOeval(cocoGt, cocoDt, iou_type) + cocoEval.params.catIds = cocoGt.get_cat_ids(cat_names=CLASSES) + cocoEval.params.imgIds = cocoGt.get_img_ids() + cocoEval.params.maxDets = [100, 300, 1000] # proposal number for evaluating recalls/mAPs. + cocoEval.params.iouThrs = iou_thrs + + cocoEval.evaluate() + cocoEval.accumulate() + cocoEval.summarize() + + # mapping of cocoEval.stats + coco_metric_names = { + 'mAP': 0, + 'mAP_50': 1, + 'mAP_75': 2, + 'mAP_s': 3, + 'mAP_m': 4, + 'mAP_l': 5, + 'AR@100': 6, + 'AR@300': 7, + 'AR@1000': 8, + 'AR_s@1000': 9, + 'AR_m@1000': 10, + 'AR_l@1000': 11 + } + + metric_items = ['mAP', 'mAP_50', 'mAP_75', 'mAP_s', 'mAP_m', 'mAP_l'] + eval_results = {} + + for metric_item in metric_items: + key = f'bbox_{metric_item}' + val = float( + f'{cocoEval.stats[coco_metric_names[metric_item]]:.3f}' + ) + eval_results[key] = val + ap = cocoEval.stats[:6] + eval_results['bbox_mAP_copypaste'] = ( + f'{ap[0]:.3f} {ap[1]:.3f} {ap[2]:.3f} {ap[3]:.3f} ' + f'{ap[4]:.3f} {ap[5]:.3f}') + + return eval_results + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--ground_truth", default="instances_val2017.json") + parser.add_argument("--detection_result", default="coco_detection_result.json") + args = parser.parse_args() + result = coco_evaluation(args.ground_truth, args.detection_result) + print(result) + with open('./coco_detection_result.txt', 'w') as f: + for key, value in result.items(): f.write(key + ': ' + str(value) + '\n') \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/NAS_FPN/get_info.py b/ACL_PyTorch/contrib/cv/detection/NAS_FPN/get_info.py index 8bf8552914c761ac9da2e1b234bd9df083051251..f31faf1bc9c7c53cd80d2a0f043364eefa8631be 100644 --- a/ACL_PyTorch/contrib/cv/detection/NAS_FPN/get_info.py +++ b/ACL_PyTorch/contrib/cv/detection/NAS_FPN/get_info.py @@ -1,59 +1,59 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/NAS_FPN/mmdetection_coco_postprocess.py b/ACL_PyTorch/contrib/cv/detection/NAS_FPN/mmdetection_coco_postprocess.py index cf9a8024efcae388546c99da291b94c87ff00580..1b64c8636623feadfb645907be57ecfb540913e6 100644 --- a/ACL_PyTorch/contrib/cv/detection/NAS_FPN/mmdetection_coco_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/NAS_FPN/mmdetection_coco_postprocess.py @@ -1,157 +1,157 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import numpy as np -import argparse -import cv2 - -CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', - 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', - 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', - 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', - 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', - 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', - 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', - 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', - 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', - 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', - 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', - 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] - -def coco_postprocess(bbox: np.ndarray, image_size, - net_input_width, net_input_height): - """ - This function is postprocessing for FasterRCNN output. - - Before calling this function, reshape the raw output of FasterRCNN to - following form - numpy.ndarray: - [x, y, width, height, confidence, probability of 80 classes] - shape: (100,) - The postprocessing restore the bounding rectangles of FasterRCNN output - to origin scale and filter with non-maximum suppression. - - :param bbox: a numpy array of the FasterRCNN output - :param image_path: a string of image path - :return: three list for best bound, class and score - """ - w = image_size[0] - h = image_size[1] - scale = min(net_input_width / w, net_input_height / h) - - pad_w = net_input_width - w * scale - pad_h = net_input_height - h * scale - pad_left = pad_w // 2 - pad_top = pad_h // 2 - - # cal predict box on the image src - pbox = bbox - pbox[:, 0] = (bbox[:, 0] - pad_left) / scale - pbox[:, 1] = (bbox[:, 1] - pad_top) / scale - pbox[:, 2] = (bbox[:, 2] - pad_left) / scale - pbox[:, 3] = (bbox[:, 3] - pad_top) / scale - - # make pbboxes value in valid range - pbox[:, 0] = np.maximum(pbox[:, 0], 0) - pbox[:, 1] = np.maximum(pbox[:, 1], 0) - pbox[:, 2] = np.minimum(pbox[:, 2], w) - pbox[:, 3] = np.minimum(pbox[:, 3], h) - return pbox - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0") - parser.add_argument("--test_annotation", default="./coco2017_jpg.info") - parser.add_argument("--det_results_path", default="./detection-results") - parser.add_argument("--img_path", default="./val2017/") - parser.add_argument("--net_out_num", default=2) - parser.add_argument("--net_input_width", default=640) - parser.add_argument("--net_input_height", default=640) - parser.add_argument("--prob_thres", default=0.05) - parser.add_argument("--ifShowDetObj", action="store_true", help="if input the para means True, neither False.") - flags = parser.parse_args() - print(flags.ifShowDetObj, type(flags.ifShowDetObj)) - # generate dict according to annotation file for query resolution - # load width and height of input images - img_size_dict = dict() - with open(flags.test_annotation)as f: - for line in f.readlines(): - temp = line.split(" ") - img_file_path = temp[1] - img_name = temp[1].split("/")[-1].split(".")[0] - img_width = int(temp[2]) - img_height = int(temp[3]) - img_size_dict[img_name] = (img_width, img_height, img_file_path) - - # read bin file for generate predict result - bin_path = flags.bin_data_path - det_results_path = flags.det_results_path - img_path = flags.img_path - os.makedirs(det_results_path, exist_ok=True) - total_img = set([name[:name.rfind('_')] - for name in os.listdir(bin_path) if "bin" in name]) - for bin_file in sorted(total_img): - path_base = os.path.join(bin_path, bin_file) - # load all detected output tensor - res_buff = [] - for num in range(1, flags.net_out_num + 1): - if os.path.exists(path_base + "_" + str(num) + ".bin"): - if num == 1: - buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="float32") - buf = np.reshape(buf, [100, 5]) - elif num == 2: - buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="int64") - buf = np.reshape(buf, [100, 1]) - res_buff.append(buf) - else: - print("[ERROR] file not exist", path_base + "_" + str(num) + ".bin") - res_tensor = np.concatenate(res_buff, axis=1) - current_img_size = img_size_dict[bin_file] - print("[TEST]---------------------------concat{} imgsize{}".format(len(res_tensor), current_img_size)) - predbox = coco_postprocess(res_tensor, current_img_size, flags.net_input_width, flags.net_input_height) - - if flags.ifShowDetObj == True: - pic = os.path.join(img_path, bin_file +'.jpg') - imgCur = cv2.imread(pic) - - det_results_str = '' - for idx, class_ind in enumerate(predbox[:,5]): - if float(predbox[idx][4]) < float(flags.prob_thres): - continue - # skip negative class index - if class_ind < 0 or class_ind > 80: - continue - - class_name = CLASSES[int(class_ind)] - det_results_str += "{} {} {} {} {} {}\n".format(class_name, str(predbox[idx][4]), predbox[idx][0], - predbox[idx][1], predbox[idx][2], predbox[idx][3]) - if flags.ifShowDetObj == True: - imgCur=cv2.rectangle(imgCur, (int(predbox[idx][0]), int(predbox[idx][1])), - (int(predbox[idx][2]), int(predbox[idx][3])), (0,255,0), 1) - imgCur = cv2.putText(imgCur, class_name+'|'+str(predbox[idx][4]), - (int(predbox[idx][0]), int(predbox[idx][1])), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1) - # 图像,文字内容, 坐标 ,字体,大小,颜色,字体厚度 - - if flags.ifShowDetObj == True: - print(os.path.join(det_results_path, bin_file +'.jpg')) - cv2.imwrite(os.path.join(det_results_path, bin_file +'.jpg'), imgCur, [int(cv2.IMWRITE_JPEG_QUALITY),70]) - - det_results_file = os.path.join(det_results_path, bin_file + ".txt") - with open(det_results_file, "w") as detf: - detf.write(det_results_str) - print(det_results_str) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import numpy as np +import argparse +import cv2 + +CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', + 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', + 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', + 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', + 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', + 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', + 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', + 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', + 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', + 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', + 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', + 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] + +def coco_postprocess(bbox: np.ndarray, image_size, + net_input_width, net_input_height): + """ + This function is postprocessing for FasterRCNN output. + + Before calling this function, reshape the raw output of FasterRCNN to + following form + numpy.ndarray: + [x, y, width, height, confidence, probability of 80 classes] + shape: (100,) + The postprocessing restore the bounding rectangles of FasterRCNN output + to origin scale and filter with non-maximum suppression. + + :param bbox: a numpy array of the FasterRCNN output + :param image_path: a string of image path + :return: three list for best bound, class and score + """ + w = image_size[0] + h = image_size[1] + scale = min(net_input_width / w, net_input_height / h) + + pad_w = net_input_width - w * scale + pad_h = net_input_height - h * scale + pad_left = pad_w // 2 + pad_top = pad_h // 2 + + # cal predict box on the image src + pbox = bbox + pbox[:, 0] = (bbox[:, 0] - pad_left) / scale + pbox[:, 1] = (bbox[:, 1] - pad_top) / scale + pbox[:, 2] = (bbox[:, 2] - pad_left) / scale + pbox[:, 3] = (bbox[:, 3] - pad_top) / scale + + # make pbboxes value in valid range + pbox[:, 0] = np.maximum(pbox[:, 0], 0) + pbox[:, 1] = np.maximum(pbox[:, 1], 0) + pbox[:, 2] = np.minimum(pbox[:, 2], w) + pbox[:, 3] = np.minimum(pbox[:, 3], h) + return pbox + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0") + parser.add_argument("--test_annotation", default="./coco2017_jpg.info") + parser.add_argument("--det_results_path", default="./detection-results") + parser.add_argument("--img_path", default="./val2017/") + parser.add_argument("--net_out_num", default=2) + parser.add_argument("--net_input_width", default=640) + parser.add_argument("--net_input_height", default=640) + parser.add_argument("--prob_thres", default=0.05) + parser.add_argument("--ifShowDetObj", action="store_true", help="if input the para means True, neither False.") + flags = parser.parse_args() + print(flags.ifShowDetObj, type(flags.ifShowDetObj)) + # generate dict according to annotation file for query resolution + # load width and height of input images + img_size_dict = dict() + with open(flags.test_annotation)as f: + for line in f.readlines(): + temp = line.split(" ") + img_file_path = temp[1] + img_name = temp[1].split("/")[-1].split(".")[0] + img_width = int(temp[2]) + img_height = int(temp[3]) + img_size_dict[img_name] = (img_width, img_height, img_file_path) + + # read bin file for generate predict result + bin_path = flags.bin_data_path + det_results_path = flags.det_results_path + img_path = flags.img_path + os.makedirs(det_results_path, exist_ok=True) + total_img = set([name[:name.rfind('_')] + for name in os.listdir(bin_path) if "bin" in name]) + for bin_file in sorted(total_img): + path_base = os.path.join(bin_path, bin_file) + # load all detected output tensor + res_buff = [] + for num in range(1, flags.net_out_num + 1): + if os.path.exists(path_base + "_" + str(num) + ".bin"): + if num == 1: + buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="float32") + buf = np.reshape(buf, [100, 5]) + elif num == 2: + buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="int64") + buf = np.reshape(buf, [100, 1]) + res_buff.append(buf) + else: + print("[ERROR] file not exist", path_base + "_" + str(num) + ".bin") + res_tensor = np.concatenate(res_buff, axis=1) + current_img_size = img_size_dict[bin_file] + print("[TEST]---------------------------concat{} imgsize{}".format(len(res_tensor), current_img_size)) + predbox = coco_postprocess(res_tensor, current_img_size, flags.net_input_width, flags.net_input_height) + + if flags.ifShowDetObj == True: + pic = os.path.join(img_path, bin_file +'.jpg') + imgCur = cv2.imread(pic) + + det_results_str = '' + for idx, class_ind in enumerate(predbox[:,5]): + if float(predbox[idx][4]) < float(flags.prob_thres): + continue + # skip negative class index + if class_ind < 0 or class_ind > 80: + continue + + class_name = CLASSES[int(class_ind)] + det_results_str += "{} {} {} {} {} {}\n".format(class_name, str(predbox[idx][4]), predbox[idx][0], + predbox[idx][1], predbox[idx][2], predbox[idx][3]) + if flags.ifShowDetObj == True: + imgCur=cv2.rectangle(imgCur, (int(predbox[idx][0]), int(predbox[idx][1])), + (int(predbox[idx][2]), int(predbox[idx][3])), (0,255,0), 1) + imgCur = cv2.putText(imgCur, class_name+'|'+str(predbox[idx][4]), + (int(predbox[idx][0]), int(predbox[idx][1])), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1) + # 图像,文字内容, 坐标 ,字体,大小,颜色,字体厚度 + + if flags.ifShowDetObj == True: + print(os.path.join(det_results_path, bin_file +'.jpg')) + cv2.imwrite(os.path.join(det_results_path, bin_file +'.jpg'), imgCur, [int(cv2.IMWRITE_JPEG_QUALITY),70]) + + det_results_file = os.path.join(det_results_path, bin_file + ".txt") + with open(det_results_file, "w") as detf: + detf.write(det_results_str) + print(det_results_str) diff --git a/ACL_PyTorch/contrib/cv/detection/NAS_FPN/mmdetection_coco_preprocess.py b/ACL_PyTorch/contrib/cv/detection/NAS_FPN/mmdetection_coco_preprocess.py index db194cf1defda77b6eeae08e1fb971848453a217..d8bd19c453a882a1953cef54e65ea3c7c2493ccf 100644 --- a/ACL_PyTorch/contrib/cv/detection/NAS_FPN/mmdetection_coco_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/NAS_FPN/mmdetection_coco_preprocess.py @@ -1,68 +1,68 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import numpy as np -import os -import cv2 -import argparse -import mmcv -import torch - -dataset_config = { - 'resize': (640, 640), - 'mean': [123.675, 116.28, 103.53], - 'std': [58.395, 57.12, 57.375], -} - -tensor_height = 640 -tensor_width = 640 - -def coco_preprocess(input_image, output_bin_path): - #define the output file name - img_name = input_image.split('/')[-1] - bin_name = img_name.split('.')[0] + ".bin" - bin_fl = os.path.join(output_bin_path, bin_name) - - one_img = mmcv.imread(os.path.join(input_image), backend='cv2') - one_img = mmcv.imrescale(one_img, (tensor_height, tensor_width)) - # calculate padding - h = one_img.shape[0] - w = one_img.shape[1] - pad_left = (tensor_width - w) // 2 - pad_top = (tensor_height - h) // 2 - pad_right = tensor_width - pad_left - w - pad_bottom = tensor_height - pad_top - h - - mean = np.array(dataset_config['mean'], dtype=np.float32) - std = np.array(dataset_config['std'], dtype=np.float32) - one_img = mmcv.imnormalize(one_img, mean, std) - one_img = mmcv.impad(one_img, padding=(pad_left, pad_top, pad_right, pad_bottom), pad_val=0) - one_img = one_img.transpose(2, 0, 1) - one_img.tofile(bin_fl) - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='preprocess of NAS-FPN pytorch model') - parser.add_argument("--image_folder_path", default="./coco2017/", help='image of dataset') - parser.add_argument("--bin_folder_path", default="./coco2017_bin/", help='Preprocessed image buffer') - flags = parser.parse_args() - - if not os.path.exists(flags.bin_folder_path): - os.makedirs(flags.bin_folder_path) - images = os.listdir(flags.image_folder_path) - for image_name in images: - if not (image_name.endswith(".jpeg") or image_name.endswith(".JPEG") or image_name.endswith(".jpg")): - continue - print("start to process image {}....".format(image_name)) - path_image = os.path.join(flags.image_folder_path, image_name) - coco_preprocess(path_image, flags.bin_folder_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +import os +import cv2 +import argparse +import mmcv +import torch + +dataset_config = { + 'resize': (640, 640), + 'mean': [123.675, 116.28, 103.53], + 'std': [58.395, 57.12, 57.375], +} + +tensor_height = 640 +tensor_width = 640 + +def coco_preprocess(input_image, output_bin_path): + #define the output file name + img_name = input_image.split('/')[-1] + bin_name = img_name.split('.')[0] + ".bin" + bin_fl = os.path.join(output_bin_path, bin_name) + + one_img = mmcv.imread(os.path.join(input_image), backend='cv2') + one_img = mmcv.imrescale(one_img, (tensor_height, tensor_width)) + # calculate padding + h = one_img.shape[0] + w = one_img.shape[1] + pad_left = (tensor_width - w) // 2 + pad_top = (tensor_height - h) // 2 + pad_right = tensor_width - pad_left - w + pad_bottom = tensor_height - pad_top - h + + mean = np.array(dataset_config['mean'], dtype=np.float32) + std = np.array(dataset_config['std'], dtype=np.float32) + one_img = mmcv.imnormalize(one_img, mean, std) + one_img = mmcv.impad(one_img, padding=(pad_left, pad_top, pad_right, pad_bottom), pad_val=0) + one_img = one_img.transpose(2, 0, 1) + one_img.tofile(bin_fl) + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='preprocess of NAS-FPN pytorch model') + parser.add_argument("--image_folder_path", default="./coco2017/", help='image of dataset') + parser.add_argument("--bin_folder_path", default="./coco2017_bin/", help='Preprocessed image buffer') + flags = parser.parse_args() + + if not os.path.exists(flags.bin_folder_path): + os.makedirs(flags.bin_folder_path) + images = os.listdir(flags.image_folder_path) + for image_name in images: + if not (image_name.endswith(".jpeg") or image_name.endswith(".JPEG") or image_name.endswith(".jpg")): + continue + print("start to process image {}....".format(image_name)) + path_image = os.path.join(flags.image_folder_path, image_name) + coco_preprocess(path_image, flags.bin_folder_path) diff --git a/ACL_PyTorch/contrib/cv/detection/NAS_FPN/requirements.txt b/ACL_PyTorch/contrib/cv/detection/NAS_FPN/requirements.txt index a9b2aff748d181f465deadd5f1eb2cef543efb5d..bbcf70abd1d45bdd4747a59f08891e33df32c837 100644 --- a/ACL_PyTorch/contrib/cv/detection/NAS_FPN/requirements.txt +++ b/ACL_PyTorch/contrib/cv/detection/NAS_FPN/requirements.txt @@ -1,10 +1,10 @@ -torch==1.7.0 -torchvision==0.8.0 -onnx==1.8.0 -numpy==1.20.0 -mmdet==2.8.0 -mmcv-full==1.2.4 -opencv-python==4.4.0.46 -mmpycocotools==12.0.3 -onnxruntime==1.9.0 - +torch==1.7.0 +torchvision==0.8.0 +onnx==1.8.0 +numpy==1.20.0 +mmdet==2.8.0 +mmcv-full==1.2.4 +opencv-python==4.4.0.46 +mmpycocotools==12.0.3 +onnxruntime==1.9.0 + diff --git a/ACL_PyTorch/contrib/cv/detection/NAS_FPN/txt_to_json.py b/ACL_PyTorch/contrib/cv/detection/NAS_FPN/txt_to_json.py index 9736c008810f62af011b84b0594cdd708341fadc..65c20258fa741930e85fd38046e1d32b7bc5db93 100644 --- a/ACL_PyTorch/contrib/cv/detection/NAS_FPN/txt_to_json.py +++ b/ACL_PyTorch/contrib/cv/detection/NAS_FPN/txt_to_json.py @@ -1,114 +1,114 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import glob -import os -import sys -import argparse -import mmcv - -CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', - 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', - 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', - 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', - 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', - 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', - 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', - 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', - 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', - 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', - 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', - 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] - -cat_ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, -24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, -48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, -72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90] - -''' - 0,0 ------> x (width) - | - | (Left,Top) - | *_________ - | | | - | | - y |_________| - (height) * - (Right,Bottom) -''' - -def file_lines_to_list(path): - # open txt file lines to a list - with open(path) as f: - content = f.readlines() - # remove whitespace characters like `\n` at the end of each line - content = [x.strip() for x in content] - return content - - -def error(msg): - print(msg) - sys.exit(0) - - -def get_predict_list(file_path, gt_classes): - dr_files_list = glob.glob(file_path + '/*.txt') - dr_files_list.sort() - - bounding_boxes = [] - for txt_file in dr_files_list: - file_id = txt_file.split(".txt", 1)[0] - file_id = os.path.basename(os.path.normpath(file_id)) - lines = file_lines_to_list(txt_file) - for line in lines: - try: - sl = line.split() - if len(sl) > 6: - class_name = sl[0] + ' ' + sl[1] - scores, left, top, right, bottom = sl[2:] - else: - class_name, scores, left, top, right, bottom = sl - if float(scores) < 0.05: - continue - except ValueError: - error_msg = "Error: File " + txt_file + " wrong format.\n" - error_msg += " Expected: \n" - error_msg += " Received: " + line - error(error_msg) - - # bbox = left + " " + top + " " + right + " " + bottom - left = float(left) - right = float(right) - top = float(top) - bottom = float(bottom) - bbox = [left, top, right-left, bottom-top] - bounding_boxes.append({"image_id": int(file_id), "bbox": bbox, - "score": float(scores), "category_id": cat_ids[CLASSES.index(class_name)]}) - # sort detection-results by decreasing scores - # bounding_boxes.sort(key=lambda x: float(x['score']), reverse=True) - return bounding_boxes - - - -if __name__ == '__main__': - parser = argparse.ArgumentParser('mAp calculate') - parser.add_argument('--npu_txt_path', default="detection-results", - help='the path of the predict result') - parser.add_argument("--json_output_file", default="coco_detection_result") - args = parser.parse_args() - - res_bbox = get_predict_list(args.npu_txt_path, CLASSES) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import glob +import os +import sys +import argparse +import mmcv + +CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', + 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', + 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', + 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', + 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', + 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', + 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', + 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', + 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', + 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', + 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', + 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] + +cat_ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, +24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, +48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, +72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90] + +''' + 0,0 ------> x (width) + | + | (Left,Top) + | *_________ + | | | + | | + y |_________| + (height) * + (Right,Bottom) +''' + +def file_lines_to_list(path): + # open txt file lines to a list + with open(path) as f: + content = f.readlines() + # remove whitespace characters like `\n` at the end of each line + content = [x.strip() for x in content] + return content + + +def error(msg): + print(msg) + sys.exit(0) + + +def get_predict_list(file_path, gt_classes): + dr_files_list = glob.glob(file_path + '/*.txt') + dr_files_list.sort() + + bounding_boxes = [] + for txt_file in dr_files_list: + file_id = txt_file.split(".txt", 1)[0] + file_id = os.path.basename(os.path.normpath(file_id)) + lines = file_lines_to_list(txt_file) + for line in lines: + try: + sl = line.split() + if len(sl) > 6: + class_name = sl[0] + ' ' + sl[1] + scores, left, top, right, bottom = sl[2:] + else: + class_name, scores, left, top, right, bottom = sl + if float(scores) < 0.05: + continue + except ValueError: + error_msg = "Error: File " + txt_file + " wrong format.\n" + error_msg += " Expected: \n" + error_msg += " Received: " + line + error(error_msg) + + # bbox = left + " " + top + " " + right + " " + bottom + left = float(left) + right = float(right) + top = float(top) + bottom = float(bottom) + bbox = [left, top, right-left, bottom-top] + bounding_boxes.append({"image_id": int(file_id), "bbox": bbox, + "score": float(scores), "category_id": cat_ids[CLASSES.index(class_name)]}) + # sort detection-results by decreasing scores + # bounding_boxes.sort(key=lambda x: float(x['score']), reverse=True) + return bounding_boxes + + + +if __name__ == '__main__': + parser = argparse.ArgumentParser('mAp calculate') + parser.add_argument('--npu_txt_path', default="detection-results", + help='the path of the predict result') + parser.add_argument("--json_output_file", default="coco_detection_result") + args = parser.parse_args() + + res_bbox = get_predict_list(args.npu_txt_path, CLASSES) mmcv.dump(res_bbox, args.json_output_file + '.json') \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Nasnetlarge/LICENSE b/ACL_PyTorch/contrib/cv/detection/Nasnetlarge/LICENSE index b7a7d6c0e55c437adc4f260d4dbff372c830acce..4c9ad980682246bd6ab0d2bae82232be6dbdcbd4 100644 --- a/ACL_PyTorch/contrib/cv/detection/Nasnetlarge/LICENSE +++ b/ACL_PyTorch/contrib/cv/detection/Nasnetlarge/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ACL_PyTorch/contrib/cv/detection/OpenPose/OpenPose_postprocess.py b/ACL_PyTorch/contrib/cv/detection/OpenPose/OpenPose_postprocess.py index a58f6c183285082660ddb7a78658c4ca5ae3492e..69230982ef0614fe1a52f128aef72a128a21aebb 100644 --- a/ACL_PyTorch/contrib/cv/detection/OpenPose/OpenPose_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/OpenPose/OpenPose_postprocess.py @@ -1,119 +1,119 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -""" -python3.7 OpenPose_postprocess.py ---benchmark_result_path ./result/dumpOutput_device0 ---detections_save_path ./output/result.json ---pad_txt_path ./output/pad.txt ---labels /root/datasets/coco/annotations/person_keypoints_val2017.json -""" -import argparse -import json -import os -import sys -import torch -import cv2 -import numpy as np -sys.path.append("./lightweight-human-pose-estimation.pytorch") -from modules.keypoints import group_keypoints, extract_keypoints -from val import run_coco_eval, convert_to_coco_format - - -def read_txt(txt_path, shape): - with open(txt_path, "r") as f: - line = f.readline() - line_split = line.strip().split(" ") - line_split = [eval(i) for i in line_split] - line_split = torch.Tensor(line_split) - heatmaps = line_split.view(shape) - return heatmaps - - -def transfer(heatmaps, pafs, height, width, top, bottom, left, right, stride=8): - heatmaps = np.transpose(heatmaps.squeeze().cpu().data.numpy(), (1, 2, 0)) - heatmaps = cv2.resize(heatmaps, (0, 0), fx=stride, fy=stride, interpolation=cv2.INTER_CUBIC) - heatmaps = heatmaps[top:heatmaps.shape[0] - bottom, left:heatmaps.shape[1] - right:, :] - heatmaps = cv2.resize(heatmaps, (width, height), interpolation=cv2.INTER_CUBIC) - pafs = np.transpose(pafs.squeeze().cpu().data.numpy(), (1, 2, 0)) - pafs = cv2.resize(pafs, (0, 0), fx=stride, fy=stride, interpolation=cv2.INTER_CUBIC) - pafs = pafs[top:pafs.shape[0] - bottom, left:pafs.shape[1] - right, :] - pafs = cv2.resize(pafs, (width, height), interpolation=cv2.INTER_CUBIC) - return heatmaps, pafs - - -def post_process(args): - txt_folder = args.benchmark_result_path - json_path = args.detections_save_path - pad_path = args.pad_txt_path - pad_info = {} - with open(pad_path, "r") as f: - lines = f.readlines() - for line in lines: - line_split = line.strip().split(" ") - pad_info[line_split[0]] = [int(line_split[i]) for i in range(1, 7)] - txt_1, txt_2 = [], [] - for txt in os.listdir(txt_folder): - txt_pure_name = txt.split('.')[0] - index = txt_pure_name.rfind('_') - name_suffix = txt_pure_name[index + 1] - if name_suffix == "1": - txt_1.append(txt) - else: - txt_2.append(txt) - txt_1.sort() - txt_2.sort() - coco_result = [] - for txt1, txt2 in zip(txt_1, txt_2): - txt_pure_name = txt1.split('.')[0] - index = txt_pure_name.rfind('_') - img_name = txt_pure_name[0:index] + ".jpg" - txt1_path = os.path.join(txt_folder, txt1) - txt2_path = os.path.join(txt_folder, txt2) - print(txt1, txt2) - heatmaps = read_txt(txt1_path, (1, 19, 46, 80)) - pafs = read_txt(txt2_path, (1, 38, 46, 80)) - pad = pad_info[img_name] - height, width = pad[0], pad[1] - top, bottom, left, right = pad[2], pad[3], pad[4], pad[5] - heatmaps, pafs = transfer(heatmaps, pafs, height, width, top, bottom, left, right) - all_keypoints_num = 0 - all_keypoints_by_type = [] - for kpt_idx in range(18): # 19th for bg - all_keypoints_num += extract_keypoints(heatmaps[:, :, kpt_idx], all_keypoints_by_type, all_keypoints_num) - pose_entries, all_keypoints = group_keypoints(all_keypoints_by_type, pafs) - coco_keypoints, scores = convert_to_coco_format(pose_entries, all_keypoints) - image_id = int(img_name[0:img_name.rfind('.')]) - for idx in range(len(coco_keypoints)): - coco_result.append({'image_id': image_id, 'category_id': 1, 'keypoints': coco_keypoints[idx], - 'score': scores[idx]}) - with open(json_path, 'w') as f: - json.dump(coco_result, f, indent=4) - run_coco_eval(args.labels, json_path) - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument("--benchmark_result_path", default="./result/dumpOutput_device0") - parser.add_argument("--detections_save_path", default="./output/result.json") - parser.add_argument("--pad_txt_path", default="./output/pad.txt", - help="padding around the image with 368*640") - parser.add_argument('--labels', type=str, default='/root/datasets/coco/annotations/person_keypoints_val2017.json', - help='path to json with keypoints val labels') - args = parser.parse_args() - - post_process(args) - - -if __name__ == '__main__': - main() +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +python3.7 OpenPose_postprocess.py +--benchmark_result_path ./result/dumpOutput_device0 +--detections_save_path ./output/result.json +--pad_txt_path ./output/pad.txt +--labels /root/datasets/coco/annotations/person_keypoints_val2017.json +""" +import argparse +import json +import os +import sys +import torch +import cv2 +import numpy as np +sys.path.append("./lightweight-human-pose-estimation.pytorch") +from modules.keypoints import group_keypoints, extract_keypoints +from val import run_coco_eval, convert_to_coco_format + + +def read_txt(txt_path, shape): + with open(txt_path, "r") as f: + line = f.readline() + line_split = line.strip().split(" ") + line_split = [eval(i) for i in line_split] + line_split = torch.Tensor(line_split) + heatmaps = line_split.view(shape) + return heatmaps + + +def transfer(heatmaps, pafs, height, width, top, bottom, left, right, stride=8): + heatmaps = np.transpose(heatmaps.squeeze().cpu().data.numpy(), (1, 2, 0)) + heatmaps = cv2.resize(heatmaps, (0, 0), fx=stride, fy=stride, interpolation=cv2.INTER_CUBIC) + heatmaps = heatmaps[top:heatmaps.shape[0] - bottom, left:heatmaps.shape[1] - right:, :] + heatmaps = cv2.resize(heatmaps, (width, height), interpolation=cv2.INTER_CUBIC) + pafs = np.transpose(pafs.squeeze().cpu().data.numpy(), (1, 2, 0)) + pafs = cv2.resize(pafs, (0, 0), fx=stride, fy=stride, interpolation=cv2.INTER_CUBIC) + pafs = pafs[top:pafs.shape[0] - bottom, left:pafs.shape[1] - right, :] + pafs = cv2.resize(pafs, (width, height), interpolation=cv2.INTER_CUBIC) + return heatmaps, pafs + + +def post_process(args): + txt_folder = args.benchmark_result_path + json_path = args.detections_save_path + pad_path = args.pad_txt_path + pad_info = {} + with open(pad_path, "r") as f: + lines = f.readlines() + for line in lines: + line_split = line.strip().split(" ") + pad_info[line_split[0]] = [int(line_split[i]) for i in range(1, 7)] + txt_1, txt_2 = [], [] + for txt in os.listdir(txt_folder): + txt_pure_name = txt.split('.')[0] + index = txt_pure_name.rfind('_') + name_suffix = txt_pure_name[index + 1] + if name_suffix == "1": + txt_1.append(txt) + else: + txt_2.append(txt) + txt_1.sort() + txt_2.sort() + coco_result = [] + for txt1, txt2 in zip(txt_1, txt_2): + txt_pure_name = txt1.split('.')[0] + index = txt_pure_name.rfind('_') + img_name = txt_pure_name[0:index] + ".jpg" + txt1_path = os.path.join(txt_folder, txt1) + txt2_path = os.path.join(txt_folder, txt2) + print(txt1, txt2) + heatmaps = read_txt(txt1_path, (1, 19, 46, 80)) + pafs = read_txt(txt2_path, (1, 38, 46, 80)) + pad = pad_info[img_name] + height, width = pad[0], pad[1] + top, bottom, left, right = pad[2], pad[3], pad[4], pad[5] + heatmaps, pafs = transfer(heatmaps, pafs, height, width, top, bottom, left, right) + all_keypoints_num = 0 + all_keypoints_by_type = [] + for kpt_idx in range(18): # 19th for bg + all_keypoints_num += extract_keypoints(heatmaps[:, :, kpt_idx], all_keypoints_by_type, all_keypoints_num) + pose_entries, all_keypoints = group_keypoints(all_keypoints_by_type, pafs) + coco_keypoints, scores = convert_to_coco_format(pose_entries, all_keypoints) + image_id = int(img_name[0:img_name.rfind('.')]) + for idx in range(len(coco_keypoints)): + coco_result.append({'image_id': image_id, 'category_id': 1, 'keypoints': coco_keypoints[idx], + 'score': scores[idx]}) + with open(json_path, 'w') as f: + json.dump(coco_result, f, indent=4) + run_coco_eval(args.labels, json_path) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--benchmark_result_path", default="./result/dumpOutput_device0") + parser.add_argument("--detections_save_path", default="./output/result.json") + parser.add_argument("--pad_txt_path", default="./output/pad.txt", + help="padding around the image with 368*640") + parser.add_argument('--labels', type=str, default='/root/datasets/coco/annotations/person_keypoints_val2017.json', + help='path to json with keypoints val labels') + args = parser.parse_args() + + post_process(args) + + +if __name__ == '__main__': + main() diff --git a/ACL_PyTorch/contrib/cv/detection/OpenPose/OpenPose_preprocess.py b/ACL_PyTorch/contrib/cv/detection/OpenPose/OpenPose_preprocess.py index 08328966e4a1d44f6a05b89bb9e157fbd68e1e64..68c1d4e78fc6e0fc6f21820eb840806c46eb5c08 100644 --- a/ACL_PyTorch/contrib/cv/detection/OpenPose/OpenPose_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/OpenPose/OpenPose_preprocess.py @@ -1,90 +1,90 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -""" -python3.7 OpenPose_preprocess.py ---src_path /root/datasets/coco/val2017 ---save_path /root/datasets/coco/prep_dataset ---pad_txt_path ./output/pad.txt -""" -import os -import sys -import math -import argparse -import torch -import numpy as np -import cv2 -sys.path.append("./lightweight-human-pose-estimation.pytorch") -from val import normalize - - -def pad_width(img, stride, pad_value, min_dims, name, height, width, pad_txt_path): - h, w, _ = img.shape - min_dims[0] = math.ceil(min_dims[0] / float(stride)) * stride - min_dims[1] = math.ceil(min_dims[1] / float(stride)) * stride - pad = [int(math.floor((min_dims[0] - h) / 2.0)), int(math.floor((min_dims[1] - w) / 2.0))] - pad.append(int(min_dims[0] - h - pad[0])) - pad.append(int(min_dims[1] - w - pad[1])) - padded_img = cv2.copyMakeBorder(img, pad[int(0)], pad[int(2)], pad[int(1)], pad[int(3)], - cv2.BORDER_CONSTANT, value=pad_value) - with open(pad_txt_path, "a") as f: - f.write(str(name) + " " + str(height) + " " + str(width) + " " + - str(pad[int(0)]) + " " + str(pad[int(2)]) + " " + str(pad[int(1)]) + " " + str(pad[int(3)]) + "\n") - print("padded_img's h w:", padded_img.shape[0], padded_img.shape[1]) - return padded_img, pad # top,bottom,left,right - - -def image_preprocess(img, name, pad_txt_path, base_height=368, base_width=640, stride=8, cpu=True, pad_value=(0, 0, 0), - img_mean=np.array([128, 128, 128], np.float32), img_scale=np.float32(1 / 256)): - norm_img = normalize(img, img_mean, img_scale) - height, width, _ = img.shape - height_scale = base_height / height - width_scale = base_width / width - scale = min(height_scale, width_scale) - scaled_img = cv2.resize(norm_img, (0, 0), fx=scale, fy=scale, interpolation=cv2.INTER_LINEAR) - min_dims = [base_height, base_width] - padded_img, pad = pad_width(scaled_img, stride, pad_value, min_dims, name, height, width, pad_txt_path) - tensor_img = torch.from_numpy(padded_img).permute(2, 0, 1).unsqueeze(0).float() - print("tensor_img shape:", tensor_img.shape) - if not cpu: - tensor_img = tensor_img.cuda() - return tensor_img - - -def preprocess(src_path, save_path, pad_txt_path): - in_files = os.listdir(src_path) - for i, file in enumerate(in_files): - print(file, "===", i) - img_path = os.path.join(src_path, file) - input_image = cv2.imread(img_path, cv2.IMREAD_COLOR) - input_tensor = image_preprocess(input_image, file, pad_txt_path) - img = np.array(input_tensor).astype(np.float32) - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('--src_path', type=str, default='/root/datasets/coco/val2017', - help='the source path of images') - parser.add_argument('--save_path', type=str, default='/root/datasets/coco/prep_dataset', - help='the path of saving bin of each image') - parser.add_argument('--pad_txt_path', type=str, default='./output/pad.txt' - , help='the path of pad.txt saving the info of padding') - args = parser.parse_args() - with open(args.pad_txt_path, "a+") as f: - f.truncate(0) - preprocess(args.src_path, args.save_path, args.pad_txt_path) - - -if __name__ == "__main__": - main() +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +python3.7 OpenPose_preprocess.py +--src_path /root/datasets/coco/val2017 +--save_path /root/datasets/coco/prep_dataset +--pad_txt_path ./output/pad.txt +""" +import os +import sys +import math +import argparse +import torch +import numpy as np +import cv2 +sys.path.append("./lightweight-human-pose-estimation.pytorch") +from val import normalize + + +def pad_width(img, stride, pad_value, min_dims, name, height, width, pad_txt_path): + h, w, _ = img.shape + min_dims[0] = math.ceil(min_dims[0] / float(stride)) * stride + min_dims[1] = math.ceil(min_dims[1] / float(stride)) * stride + pad = [int(math.floor((min_dims[0] - h) / 2.0)), int(math.floor((min_dims[1] - w) / 2.0))] + pad.append(int(min_dims[0] - h - pad[0])) + pad.append(int(min_dims[1] - w - pad[1])) + padded_img = cv2.copyMakeBorder(img, pad[int(0)], pad[int(2)], pad[int(1)], pad[int(3)], + cv2.BORDER_CONSTANT, value=pad_value) + with open(pad_txt_path, "a") as f: + f.write(str(name) + " " + str(height) + " " + str(width) + " " + + str(pad[int(0)]) + " " + str(pad[int(2)]) + " " + str(pad[int(1)]) + " " + str(pad[int(3)]) + "\n") + print("padded_img's h w:", padded_img.shape[0], padded_img.shape[1]) + return padded_img, pad # top,bottom,left,right + + +def image_preprocess(img, name, pad_txt_path, base_height=368, base_width=640, stride=8, cpu=True, pad_value=(0, 0, 0), + img_mean=np.array([128, 128, 128], np.float32), img_scale=np.float32(1 / 256)): + norm_img = normalize(img, img_mean, img_scale) + height, width, _ = img.shape + height_scale = base_height / height + width_scale = base_width / width + scale = min(height_scale, width_scale) + scaled_img = cv2.resize(norm_img, (0, 0), fx=scale, fy=scale, interpolation=cv2.INTER_LINEAR) + min_dims = [base_height, base_width] + padded_img, pad = pad_width(scaled_img, stride, pad_value, min_dims, name, height, width, pad_txt_path) + tensor_img = torch.from_numpy(padded_img).permute(2, 0, 1).unsqueeze(0).float() + print("tensor_img shape:", tensor_img.shape) + if not cpu: + tensor_img = tensor_img.cuda() + return tensor_img + + +def preprocess(src_path, save_path, pad_txt_path): + in_files = os.listdir(src_path) + for i, file in enumerate(in_files): + print(file, "===", i) + img_path = os.path.join(src_path, file) + input_image = cv2.imread(img_path, cv2.IMREAD_COLOR) + input_tensor = image_preprocess(input_image, file, pad_txt_path) + img = np.array(input_tensor).astype(np.float32) + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--src_path', type=str, default='/root/datasets/coco/val2017', + help='the source path of images') + parser.add_argument('--save_path', type=str, default='/root/datasets/coco/prep_dataset', + help='the path of saving bin of each image') + parser.add_argument('--pad_txt_path', type=str, default='./output/pad.txt' + , help='the path of pad.txt saving the info of padding') + args = parser.parse_args() + with open(args.pad_txt_path, "a+") as f: + f.truncate(0) + preprocess(args.src_path, args.save_path, args.pad_txt_path) + + +if __name__ == "__main__": + main() diff --git a/ACL_PyTorch/contrib/cv/detection/OpenPose/OpenPose_pth2onnx.py b/ACL_PyTorch/contrib/cv/detection/OpenPose/OpenPose_pth2onnx.py index bf5e6c4022efe59d78ee5ab9dda2eaf536047ce9..9f01273cda1fc7e37ff97a3753ef7371f7753712 100644 --- a/ACL_PyTorch/contrib/cv/detection/OpenPose/OpenPose_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/OpenPose/OpenPose_pth2onnx.py @@ -1,63 +1,63 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -""" -python3.7 OpenPose_pth2onnx.py ---checkpoint-path ./weights/checkpoint_iter_370000.pth ---output-name ./output/human-pose-estimation.onnx -""" -import argparse -import os -import sys -import torch -sys.path.append("./lightweight-human-pose-estimation.pytorch") -from models.with_mobilenet import PoseEstimationWithMobileNet -from modules.load_state import load_state - - -def convert_to_onnx(network, output_name): - net_input = torch.randn(1, 3, 368, 640) - input_names = ['data'] - output_names = ['stage_0_output_1_heatmaps', 'stage_0_output_0_pafs', - 'stage_1_output_1_heatmaps', 'stage_1_output_0_pafs'] - dynamic_axes = {'data': {0: '-1'}, 'stage_0_output_1_heatmaps': {0: '-1'}, 'stage_0_output_0_pafs': {0: '-1'}, - 'stage_1_output_1_heatmaps': {0: '-1'}, 'stage_1_output_0_pafs': {0: '-1'}} - torch.onnx.export(network, net_input, output_name, opset_version=11, verbose=True, - input_names=input_names, dynamic_axes=dynamic_axes, output_names=output_names) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--checkpoint_path', type=str, default='./weights/checkpoint_iter_370000.pth', - help='path to the checkpoint') - parser.add_argument('--output_name', type=str, default='./output/human-pose-estimation.onnx', - help='name of output model in ONNX format') - args = parser.parse_args() - - # mkdir - dir1, file1 = os.path.split(args.checkpoint_path) - dir2, file2 = os.path.split(args.output_name) - if not os.path.exists(dir1): - os.mkdir(dir1) - else: - print(dir1, "already exist") - if not os.path.exists(dir2): - os.mkdir(dir2) - else: - print(dir2, "already exist") - - net = PoseEstimationWithMobileNet() - checkpoint = torch.load(args.checkpoint_path, map_location=torch.device("cpu")) - load_state(net, checkpoint) - - convert_to_onnx(net, args.output_name) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +python3.7 OpenPose_pth2onnx.py +--checkpoint-path ./weights/checkpoint_iter_370000.pth +--output-name ./output/human-pose-estimation.onnx +""" +import argparse +import os +import sys +import torch +sys.path.append("./lightweight-human-pose-estimation.pytorch") +from models.with_mobilenet import PoseEstimationWithMobileNet +from modules.load_state import load_state + + +def convert_to_onnx(network, output_name): + net_input = torch.randn(1, 3, 368, 640) + input_names = ['data'] + output_names = ['stage_0_output_1_heatmaps', 'stage_0_output_0_pafs', + 'stage_1_output_1_heatmaps', 'stage_1_output_0_pafs'] + dynamic_axes = {'data': {0: '-1'}, 'stage_0_output_1_heatmaps': {0: '-1'}, 'stage_0_output_0_pafs': {0: '-1'}, + 'stage_1_output_1_heatmaps': {0: '-1'}, 'stage_1_output_0_pafs': {0: '-1'}} + torch.onnx.export(network, net_input, output_name, opset_version=11, verbose=True, + input_names=input_names, dynamic_axes=dynamic_axes, output_names=output_names) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--checkpoint_path', type=str, default='./weights/checkpoint_iter_370000.pth', + help='path to the checkpoint') + parser.add_argument('--output_name', type=str, default='./output/human-pose-estimation.onnx', + help='name of output model in ONNX format') + args = parser.parse_args() + + # mkdir + dir1, file1 = os.path.split(args.checkpoint_path) + dir2, file2 = os.path.split(args.output_name) + if not os.path.exists(dir1): + os.mkdir(dir1) + else: + print(dir1, "already exist") + if not os.path.exists(dir2): + os.mkdir(dir2) + else: + print(dir2, "already exist") + + net = PoseEstimationWithMobileNet() + checkpoint = torch.load(args.checkpoint_path, map_location=torch.device("cpu")) + load_state(net, checkpoint) + + convert_to_onnx(net, args.output_name) diff --git a/ACL_PyTorch/contrib/cv/detection/OpenPose/README.md b/ACL_PyTorch/contrib/cv/detection/OpenPose/README.md index 480a0bcce94089864a4a394f1a4ac1503d88ec11..08eef2e02fb63578927499923484f8cce88655d4 100644 --- a/ACL_PyTorch/contrib/cv/detection/OpenPose/README.md +++ b/ACL_PyTorch/contrib/cv/detection/OpenPose/README.md @@ -1,52 +1,52 @@ -# OpenPose模型PyTorch离线推理指导 -## 1 环境准备 -### 1.1 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -``` -pip3.7 install -r requirements.txt -``` -### 1.2 获取,安装开源模型代码 -``` -git clone https://github.com/Daniil-Osokin/lightweight-human-pose-estimation.pytorch.git -``` -### 1.3 获取权重文件 -[OpenPose预训练pth权重文件](https://download.01.org/opencv/openvino_training_extensions/models/human_pose_estimation/checkpoint_iter_370000.pth) -``` -wget https://download.01.org/opencv/openvino_training_extensions/models/human_pose_estimation/checkpoint_iter_370000.pth -P ./weights -``` -### 1.4 数据集 -310服务器上可能已经下载好该数据集,若无,参考以下方法下载。 -[coco2017官网](https://cocodataset.org/#download) -下载其中val2017图片及其标注文件,使用5000张验证集进行测试,图片与标注文件分别存放在/root/datasets/coco/val2017与/root/datasets/coco/annotations/person_keypoints_val2017.json。 -文件目录结构如下, -``` -root -├── datasets -│ ├── coco -│ │ ├── annotations -│ │ │   ├── captions_train2017.json -│ │ │   ├── captions_val2017.json -│ │ │   ├── instances_train2017.json -│ │ │   ├── instances_val2017.json -│ │ │   ├── person_keypoints_train2017.json -│ │ │   └── person_keypoints_val2017.json -│ │ ├── val2017 -│ │ ├── annotations_trainval2017.zip -``` -### 1.5 [获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) -将benchmark.x86_64或benchmark.aarch64放到当前目录,并更改权限 -``` -chmod 777 benchmark.x86_64 -``` -## 2 离线推理 -### 2.1 测试 -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets -``` -### 2.2 测评结果 -|模型|pth精度(AP,%)|310精度(AP,%)|性能基准|310性能| -|----|----|----|----|----| -|OpenPose bs1|40|40.4|224.660fps|303.276fps| -|OpenPose bs16|40|40.4|339.973fps|444.908fps| - +# OpenPose模型PyTorch离线推理指导 +## 1 环境准备 +### 1.1 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip3.7 install -r requirements.txt +``` +### 1.2 获取,安装开源模型代码 +``` +git clone https://github.com/Daniil-Osokin/lightweight-human-pose-estimation.pytorch.git +``` +### 1.3 获取权重文件 +[OpenPose预训练pth权重文件](https://download.01.org/opencv/openvino_training_extensions/models/human_pose_estimation/checkpoint_iter_370000.pth) +``` +wget https://download.01.org/opencv/openvino_training_extensions/models/human_pose_estimation/checkpoint_iter_370000.pth -P ./weights +``` +### 1.4 数据集 +310服务器上可能已经下载好该数据集,若无,参考以下方法下载。 +[coco2017官网](https://cocodataset.org/#download) +下载其中val2017图片及其标注文件,使用5000张验证集进行测试,图片与标注文件分别存放在/root/datasets/coco/val2017与/root/datasets/coco/annotations/person_keypoints_val2017.json。 +文件目录结构如下, +``` +root +├── datasets +│ ├── coco +│ │ ├── annotations +│ │ │   ├── captions_train2017.json +│ │ │   ├── captions_val2017.json +│ │ │   ├── instances_train2017.json +│ │ │   ├── instances_val2017.json +│ │ │   ├── person_keypoints_train2017.json +│ │ │   └── person_keypoints_val2017.json +│ │ ├── val2017 +│ │ ├── annotations_trainval2017.zip +``` +### 1.5 [获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) +将benchmark.x86_64或benchmark.aarch64放到当前目录,并更改权限 +``` +chmod 777 benchmark.x86_64 +``` +## 2 离线推理 +### 2.1 测试 +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets +``` +### 2.2 测评结果 +|模型|pth精度(AP,%)|310精度(AP,%)|性能基准|310性能| +|----|----|----|----|----| +|OpenPose bs1|40|40.4|224.660fps|303.276fps| +|OpenPose bs16|40|40.4|339.973fps|444.908fps| + diff --git a/ACL_PyTorch/contrib/cv/detection/OpenPose/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/detection/OpenPose/gen_dataset_info.py index 63d02f673c35e65691364a64fcc4af5c43529db3..3d48029d6147f38cc3ad4976d68f8d04c46f752d 100644 --- a/ACL_PyTorch/contrib/cv/detection/OpenPose/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/detection/OpenPose/gen_dataset_info.py @@ -1,72 +1,72 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -""" -python3.7 gen_dataset_info.py -bin -../../../../../root/datasets/coco/prep_dataset # Only relative paths of the info file can be used -./output/openpose_prep_bin.info -640 -368 # Sample width and height after preprocess -""" -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - bin_images.sort() - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -def main(): - file_type = sys.argv[1] - file_path = sys.argv[2] # Only relative paths of the info file can be used - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) - - -if __name__ == '__main__': - main() +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +python3.7 gen_dataset_info.py +bin +../../../../../root/datasets/coco/prep_dataset # Only relative paths of the info file can be used +./output/openpose_prep_bin.info +640 +368 # Sample width and height after preprocess +""" +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + bin_images.sort() + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +def main(): + file_type = sys.argv[1] + file_path = sys.argv[2] # Only relative paths of the info file can be used + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) + + +if __name__ == '__main__': + main() diff --git a/ACL_PyTorch/contrib/cv/detection/OpenPose/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/detection/OpenPose/modelzoo_level.txt index 246aac9fe92ba220e6fe80b3125018c78bdbec69..5d0cf16821d129aca2d4c4839f867eb4d7b3b409 100644 --- a/ACL_PyTorch/contrib/cv/detection/OpenPose/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/detection/OpenPose/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK -PerfStatus:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK +PerfStatus:OK diff --git a/ACL_PyTorch/contrib/cv/detection/OpenPose/requirements.txt b/ACL_PyTorch/contrib/cv/detection/OpenPose/requirements.txt index f1784bf064fd6d4e03025bcf4b30ae8669f5b018..a68dc2cb774e6528798ea1c91bf57c785a80138d 100644 --- a/ACL_PyTorch/contrib/cv/detection/OpenPose/requirements.txt +++ b/ACL_PyTorch/contrib/cv/detection/OpenPose/requirements.txt @@ -1,5 +1,5 @@ -torch>=0.4.1 -torchvision>=0.2.1 -pycocotools==2.0.0 -opencv-python>=3.4.0.14 +torch>=0.4.1 +torchvision>=0.2.1 +pycocotools==2.0.0 +opencv-python>=3.4.0.14 numpy>=1.14.0 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/OpenPose/test/parse.py b/ACL_PyTorch/contrib/cv/detection/OpenPose/test/parse.py index 6cdf1420bd3d3e7d14f5add67c57cfe2ad399407..64b47e3cff99e9e20539ae0c03b95d691d92aa1d 100644 --- a/ACL_PyTorch/contrib/cv/detection/OpenPose/test/parse.py +++ b/ACL_PyTorch/contrib/cv/detection/OpenPose/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 - print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 + print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) diff --git a/ACL_PyTorch/contrib/cv/detection/RFCN/env.sh b/ACL_PyTorch/contrib/cv/detection/RFCN/env.sh index a63ac98e8aac637432f623200e9735f656e732d0..f0619d3ad0d2fc9b1e62a2f02be28d6a6320be6f 100644 --- a/ACL_PyTorch/contrib/cv/detection/RFCN/env.sh +++ b/ACL_PyTorch/contrib/cv/detection/RFCN/env.sh @@ -1,7 +1,7 @@ -export LD_LIBRARY_PATH=/usr/local/Ascend/ascend-toolkit/latest/lib64:/usr/local/Ascend/ascend-toolkit/latest/compiler/lib64/plugin/opskernel:/usr/local/Ascend/ascend-toolkit/latest/compiler/lib64/plugin/nnengine:$LD_LIBRARY_PATH -export PYTHONPATH=/usr/local/Ascend/ascend-toolkit/latest/python/site-packages:/usr/local/Ascend/ascend-toolkit/latest/opp/op_impl/built-in/ai_core/tbe:$PYTHONPATH -export PATH=/usr/local/Ascend/ascend-toolkit/latest/bin:/usr/local/Ascend/ascend-toolkit/latest/compiler/ccec_compiler/bin:$PATH -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest -export ASCEND_OPP_PATH=/usr/local/Ascend/ascend-toolkit/latest/opp -export TOOLCHAIN_HOME=/usr/local/Ascend/ascend-toolkit/latest/toolkit +export LD_LIBRARY_PATH=/usr/local/Ascend/ascend-toolkit/latest/lib64:/usr/local/Ascend/ascend-toolkit/latest/compiler/lib64/plugin/opskernel:/usr/local/Ascend/ascend-toolkit/latest/compiler/lib64/plugin/nnengine:$LD_LIBRARY_PATH +export PYTHONPATH=/usr/local/Ascend/ascend-toolkit/latest/python/site-packages:/usr/local/Ascend/ascend-toolkit/latest/opp/op_impl/built-in/ai_core/tbe:$PYTHONPATH +export PATH=/usr/local/Ascend/ascend-toolkit/latest/bin:/usr/local/Ascend/ascend-toolkit/latest/compiler/ccec_compiler/bin:$PATH +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest +export ASCEND_OPP_PATH=/usr/local/Ascend/ascend-toolkit/latest/opp +export TOOLCHAIN_HOME=/usr/local/Ascend/ascend-toolkit/latest/toolkit export ASCEND_AUTOML_PATH=/usr/local/Ascend/ascend-toolkit/latest/tools \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/RFCN/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/detection/RFCN/modelzoo_level.txt index 62ed12347c866db16fef5622af355734787e4ec9..def2f63f1b066cc94e8dd94ec2f0c60d1baa3608 100644 --- a/ACL_PyTorch/contrib/cv/detection/RFCN/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/detection/RFCN/modelzoo_level.txt @@ -1,6 +1,6 @@ -ModelConvert:OK -QuantStatus:OK -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +ModelConvert:OK +QuantStatus:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/RFCN/rfcn_postprocess.py b/ACL_PyTorch/contrib/cv/detection/RFCN/rfcn_postprocess.py index 5edc6bea58c0e49f5c5c98699766cc38996b3ca3..eac0ac7e9298c32ef472f3633286640a00e0a0ad 100644 --- a/ACL_PyTorch/contrib/cv/detection/RFCN/rfcn_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/RFCN/rfcn_postprocess.py @@ -1,249 +1,249 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -import torch.nn.functional as F -import sys -sys.path.append('./RFCN-pytorch.1.0') -import _init_paths -import os - -import numpy as np -import argparse -import pprint -import pdb -import time -import cv2 -import torch -from torch.autograd import Variable -import torch.nn as nn -import torch.optim as optim -import pickle -from roi_data_layer.roidb import combined_roidb -from roi_data_layer.roibatchLoader import roibatchLoader -from model.utils.config import cfg, cfg_from_file, cfg_from_list, get_output_dir -from model.rpn.bbox_transform import clip_boxes -# from model.nms.nms_wrapper import nms -from model.roi_layers import nms -from model.rpn.bbox_transform import bbox_transform_inv -from model.utils.net_utils import save_net, load_net, vis_detections -from model.rfcn.resnet_atrous import resnet -import pdb -try: - xrange # Python 2 -except NameError: - xrange = range # Python 3 - - -def parse_args(): - """ - Parse input arguments - """ - parser = argparse.ArgumentParser(description='test the accuracy of RFCN') - - parser.add_argument("--image_folder_path", dest="file_path", default="./RFCN-pytorch.1.0/data/VOCdevkit2007/VOC2007/JPEGImages/",help='image of dataset') - parser.add_argument("--input",dest="input", default="./result/dumpOutput_device0/") - parser.add_argument("--output",dest="output", default="./output") - parser.add_argument("--test_annotation", default="./demo.info") - parser.add_argument("--net_input_width", default=1344) - parser.add_argument("--net_input_height", default=1344) - parser.add_argument('--dataset', dest='dataset',help='training dataset',default='pascal_voc', type=str) - parser.add_argument('--cfg', dest='cfg_file', help='optional config file',default='cfgs/res16.yml', type=str) - parser.add_argument('--net', dest='net',help='vgg16, res50, res101, res152',default='res101', type=str) - parser.add_argument('--set', dest='set_cfgs',help='set config keys', default=None,nargs=argparse.REMAINDER) - parser.add_argument('--load_dir', dest='load_dir',help='directory to load models', default="models", type=str) - parser.add_argument('--ls', dest='large_scale',help='whether use large imag scale',action='store_true') - parser.add_argument('--cag', dest='class_agnostic',help='whether perform class_agnostic bbox regression',action='store_true') - parser.add_argument('--parallel_type', dest='parallel_type',help='which part of model to parallel, 0: all, 1: model before roi pooling',default=0, type=int) - parser.add_argument('--bs', dest='batch_size',help='batch_size', default=1, type=int) - parser.add_argument('--vis', dest='vis', help='visualization mode',action='store_true') - args = parser.parse_args() - return args - -lr = cfg.TRAIN.LEARNING_RATE -momentum = cfg.TRAIN.MOMENTUM -weight_decay = cfg.TRAIN.WEIGHT_DECAY - -if __name__ == '__main__': - - args = parse_args() - - print('Called with args:') - print(args) - - np.random.seed(cfg.RNG_SEED) - - args.imdbval_name = "voc_2007_test" - args.set_cfgs = ['ANCHOR_SCALES', '[8, 16, 32]', 'ANCHOR_RATIOS', '[0.5,1,2]'] - args.cfg_file = "./RFCN-pytorch.1.0/cfgs/{}_ls.yml".format(args.net) if args.large_scale else "./RFCN-pytorch.1.0/cfgs/{}.yml".format(args.net) - - if args.cfg_file is not None: - cfg_from_file(args.cfg_file) - if args.set_cfgs is not None: - cfg_from_list(args.set_cfgs) - - cfg.TRAIN.USE_FLIPPED = False - imdb, roidb, ratio_list, ratio_index = combined_roidb(args.imdbval_name, False) - imdb.competition_mode(on=True) - - im_data = torch.FloatTensor(1) - im_info = torch.FloatTensor(1) - num_boxes = torch.LongTensor(1) - gt_boxes = torch.FloatTensor(1) - - with torch.no_grad(): - im_data = Variable(im_data) - im_info = Variable(im_info) - num_boxes = Variable(num_boxes) - gt_boxes = Variable(gt_boxes) - - start = time.time() - max_per_image = 100 - - vis = args.vis - - if vis: - thresh = 0.05 - else: - thresh = 0.0 - - #save_name = 'RFCN' - num_images = len(imdb.image_index) - all_boxes = [[[] for _ in xrange(num_images)] - for _ in xrange(imdb.num_classes)] - - #output_dir = get_output_dir(imdb, save_name) - output=args.output - if not os.path.exists(output): - os.makedirs(output) - dataset = roibatchLoader(roidb, ratio_list, ratio_index, args.batch_size, \ - imdb.num_classes, training=False, normalize = False) - dataloader = torch.utils.data.DataLoader(dataset, batch_size=args.batch_size, - shuffle=False, num_workers=0, - pin_memory=True) - - data_iter = iter(dataloader) - - # _t = {'im_detect': time.time(), 'misc': time.time()} - det_file = os.path.join(output, 'detections.pkl') - # fasterRCNN.eval() - empty_array = np.transpose(np.array([[],[],[],[],[]]), (1,0)) - dataset.resize_batch() - npu_result = args.input - with open("./RFCN-pytorch.1.0/data/VOCdevkit2007/VOC2007/ImageSets/Main/test.txt") as f: - imglist = [x.strip() for x in f.readlines()] - num_images = len(imglist) - for i in range(num_images): - data = next(data_iter) - pad_value = 0 - batch_shape = (3, 1344, 1344) - padding_size = [0, batch_shape[-1] - data[0].shape[-1], - 0, batch_shape[-2] - data[0].shape[-2]] - #data[0] = F.pad(data[0], padding_size, value=pad_value) - #im_data.resize_(data[0].size()).copy_(data[0]) - # print(im_data.size()) - im_info.resize_(data[1].size()).copy_(data[1]) - gt_boxes.resize_(data[2].size()).copy_(data[2]) - num_boxes.resize_(data[3].size()).copy_(data[3]) - det_tic = time.time() - - def read_data(data_path, input_shape=None): - if data_path.endswith('.bin'): - data = np.fromfile(data_path, dtype=np.float32) - data = data.reshape(input_shape) - elif data_path.endswith('.npy'): - data = np.load(data_path) - return data - - rois = torch.from_numpy( - read_data(npu_result+'{}_1.bin'.format(imglist[i]), [1, 300, 5])) - cls_prob = torch.from_numpy( - read_data(npu_result+'{}_2.bin'.format(imglist[i]), [1, 300, 21])) - bbox_pred = torch.from_numpy( - read_data(npu_result+'{}_3.bin'.format(imglist[i]), [1, 300, 84])) - scores = cls_prob.data - boxes = rois.data[:, :, 1:5] - - box_deltas = bbox_pred.data - box_deltas = box_deltas.view(-1, 4) * torch.FloatTensor(cfg.TRAIN.BBOX_NORMALIZE_STDS) \ - + torch.FloatTensor(cfg.TRAIN.BBOX_NORMALIZE_MEANS) - box_deltas = box_deltas.view(args.batch_size, -1, 4 * len(imdb.classes)) - pred_boxes = bbox_transform_inv(boxes, box_deltas, 1) - pred_boxes = clip_boxes(pred_boxes, im_info.data, 1) - pred_boxes /= data[1][0][2] - - scores = scores.squeeze() - pred_boxes = pred_boxes.squeeze() - det_toc = time.time() - detect_time = det_toc - det_tic - misc_tic = time.time() - if vis: - im = cv2.imread(imdb.image_path_at(i)) - im2show = np.copy(im) - for j in xrange(1, imdb.num_classes): - inds = torch.nonzero(scores[:, j] > thresh).view(-1) - # if there is det - if inds.numel() > 0: - cls_scores = scores[:, j][inds] - _, order = torch.sort(cls_scores, 0, True) - if args.class_agnostic: - cls_boxes = pred_boxes[inds, :] - else: - cls_boxes = pred_boxes[inds][:, j * 4:(j + 1) * 4] - - cls_dets = torch.cat((cls_boxes, cls_scores.unsqueeze(1)), 1) - # cls_dets = torch.cat((cls_boxes, cls_scores), 1) - cls_dets = cls_dets[order] - keep = nms(cls_boxes[order, :], cls_scores[order], cfg.TEST.NMS) - cls_dets = cls_dets[keep.view(-1).long()] - if vis: - im2show = vis_detections(im2show, imdb.classes[j], cls_dets.cpu().numpy(), 0.3) - all_boxes[j][i] = cls_dets.cpu().numpy() - else: - all_boxes[j][i] = empty_array - - # Limit to max_per_image detections *over all classes* - if max_per_image > 0: - image_scores = np.hstack([all_boxes[j][i][:, -1] - for j in xrange(1, imdb.num_classes)]) - if len(image_scores) > max_per_image: - image_thresh = np.sort(image_scores)[-max_per_image] - for j in xrange(1, imdb.num_classes): - keep = np.where(all_boxes[j][i][:, -1] >= image_thresh)[0] - all_boxes[j][i] = all_boxes[j][i][keep, :] - - misc_toc = time.time() - nms_time = misc_toc - misc_tic - - sys.stdout.write('im_detect: {:d}/{:d} {:.3f}s {:.3f}s \r' \ - .format(i + 1, num_images, detect_time, nms_time)) - sys.stdout.flush() - - if vis: - cv2.imwrite('result.png', im2show) - pdb.set_trace() - # cv2.imshow('test', im2show) - # cv2.waitKey(0) - - with open(det_file, 'wb') as f: - pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL) - - print('Evaluating detections') - imdb.evaluate_detections(all_boxes, output) - - end = time.time() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +import torch.nn.functional as F +import sys +sys.path.append('./RFCN-pytorch.1.0') +import _init_paths +import os + +import numpy as np +import argparse +import pprint +import pdb +import time +import cv2 +import torch +from torch.autograd import Variable +import torch.nn as nn +import torch.optim as optim +import pickle +from roi_data_layer.roidb import combined_roidb +from roi_data_layer.roibatchLoader import roibatchLoader +from model.utils.config import cfg, cfg_from_file, cfg_from_list, get_output_dir +from model.rpn.bbox_transform import clip_boxes +# from model.nms.nms_wrapper import nms +from model.roi_layers import nms +from model.rpn.bbox_transform import bbox_transform_inv +from model.utils.net_utils import save_net, load_net, vis_detections +from model.rfcn.resnet_atrous import resnet +import pdb +try: + xrange # Python 2 +except NameError: + xrange = range # Python 3 + + +def parse_args(): + """ + Parse input arguments + """ + parser = argparse.ArgumentParser(description='test the accuracy of RFCN') + + parser.add_argument("--image_folder_path", dest="file_path", default="./RFCN-pytorch.1.0/data/VOCdevkit2007/VOC2007/JPEGImages/",help='image of dataset') + parser.add_argument("--input",dest="input", default="./result/dumpOutput_device0/") + parser.add_argument("--output",dest="output", default="./output") + parser.add_argument("--test_annotation", default="./demo.info") + parser.add_argument("--net_input_width", default=1344) + parser.add_argument("--net_input_height", default=1344) + parser.add_argument('--dataset', dest='dataset',help='training dataset',default='pascal_voc', type=str) + parser.add_argument('--cfg', dest='cfg_file', help='optional config file',default='cfgs/res16.yml', type=str) + parser.add_argument('--net', dest='net',help='vgg16, res50, res101, res152',default='res101', type=str) + parser.add_argument('--set', dest='set_cfgs',help='set config keys', default=None,nargs=argparse.REMAINDER) + parser.add_argument('--load_dir', dest='load_dir',help='directory to load models', default="models", type=str) + parser.add_argument('--ls', dest='large_scale',help='whether use large imag scale',action='store_true') + parser.add_argument('--cag', dest='class_agnostic',help='whether perform class_agnostic bbox regression',action='store_true') + parser.add_argument('--parallel_type', dest='parallel_type',help='which part of model to parallel, 0: all, 1: model before roi pooling',default=0, type=int) + parser.add_argument('--bs', dest='batch_size',help='batch_size', default=1, type=int) + parser.add_argument('--vis', dest='vis', help='visualization mode',action='store_true') + args = parser.parse_args() + return args + +lr = cfg.TRAIN.LEARNING_RATE +momentum = cfg.TRAIN.MOMENTUM +weight_decay = cfg.TRAIN.WEIGHT_DECAY + +if __name__ == '__main__': + + args = parse_args() + + print('Called with args:') + print(args) + + np.random.seed(cfg.RNG_SEED) + + args.imdbval_name = "voc_2007_test" + args.set_cfgs = ['ANCHOR_SCALES', '[8, 16, 32]', 'ANCHOR_RATIOS', '[0.5,1,2]'] + args.cfg_file = "./RFCN-pytorch.1.0/cfgs/{}_ls.yml".format(args.net) if args.large_scale else "./RFCN-pytorch.1.0/cfgs/{}.yml".format(args.net) + + if args.cfg_file is not None: + cfg_from_file(args.cfg_file) + if args.set_cfgs is not None: + cfg_from_list(args.set_cfgs) + + cfg.TRAIN.USE_FLIPPED = False + imdb, roidb, ratio_list, ratio_index = combined_roidb(args.imdbval_name, False) + imdb.competition_mode(on=True) + + im_data = torch.FloatTensor(1) + im_info = torch.FloatTensor(1) + num_boxes = torch.LongTensor(1) + gt_boxes = torch.FloatTensor(1) + + with torch.no_grad(): + im_data = Variable(im_data) + im_info = Variable(im_info) + num_boxes = Variable(num_boxes) + gt_boxes = Variable(gt_boxes) + + start = time.time() + max_per_image = 100 + + vis = args.vis + + if vis: + thresh = 0.05 + else: + thresh = 0.0 + + #save_name = 'RFCN' + num_images = len(imdb.image_index) + all_boxes = [[[] for _ in xrange(num_images)] + for _ in xrange(imdb.num_classes)] + + #output_dir = get_output_dir(imdb, save_name) + output=args.output + if not os.path.exists(output): + os.makedirs(output) + dataset = roibatchLoader(roidb, ratio_list, ratio_index, args.batch_size, \ + imdb.num_classes, training=False, normalize = False) + dataloader = torch.utils.data.DataLoader(dataset, batch_size=args.batch_size, + shuffle=False, num_workers=0, + pin_memory=True) + + data_iter = iter(dataloader) + + # _t = {'im_detect': time.time(), 'misc': time.time()} + det_file = os.path.join(output, 'detections.pkl') + # fasterRCNN.eval() + empty_array = np.transpose(np.array([[],[],[],[],[]]), (1,0)) + dataset.resize_batch() + npu_result = args.input + with open("./RFCN-pytorch.1.0/data/VOCdevkit2007/VOC2007/ImageSets/Main/test.txt") as f: + imglist = [x.strip() for x in f.readlines()] + num_images = len(imglist) + for i in range(num_images): + data = next(data_iter) + pad_value = 0 + batch_shape = (3, 1344, 1344) + padding_size = [0, batch_shape[-1] - data[0].shape[-1], + 0, batch_shape[-2] - data[0].shape[-2]] + #data[0] = F.pad(data[0], padding_size, value=pad_value) + #im_data.resize_(data[0].size()).copy_(data[0]) + # print(im_data.size()) + im_info.resize_(data[1].size()).copy_(data[1]) + gt_boxes.resize_(data[2].size()).copy_(data[2]) + num_boxes.resize_(data[3].size()).copy_(data[3]) + det_tic = time.time() + + def read_data(data_path, input_shape=None): + if data_path.endswith('.bin'): + data = np.fromfile(data_path, dtype=np.float32) + data = data.reshape(input_shape) + elif data_path.endswith('.npy'): + data = np.load(data_path) + return data + + rois = torch.from_numpy( + read_data(npu_result+'{}_1.bin'.format(imglist[i]), [1, 300, 5])) + cls_prob = torch.from_numpy( + read_data(npu_result+'{}_2.bin'.format(imglist[i]), [1, 300, 21])) + bbox_pred = torch.from_numpy( + read_data(npu_result+'{}_3.bin'.format(imglist[i]), [1, 300, 84])) + scores = cls_prob.data + boxes = rois.data[:, :, 1:5] + + box_deltas = bbox_pred.data + box_deltas = box_deltas.view(-1, 4) * torch.FloatTensor(cfg.TRAIN.BBOX_NORMALIZE_STDS) \ + + torch.FloatTensor(cfg.TRAIN.BBOX_NORMALIZE_MEANS) + box_deltas = box_deltas.view(args.batch_size, -1, 4 * len(imdb.classes)) + pred_boxes = bbox_transform_inv(boxes, box_deltas, 1) + pred_boxes = clip_boxes(pred_boxes, im_info.data, 1) + pred_boxes /= data[1][0][2] + + scores = scores.squeeze() + pred_boxes = pred_boxes.squeeze() + det_toc = time.time() + detect_time = det_toc - det_tic + misc_tic = time.time() + if vis: + im = cv2.imread(imdb.image_path_at(i)) + im2show = np.copy(im) + for j in xrange(1, imdb.num_classes): + inds = torch.nonzero(scores[:, j] > thresh).view(-1) + # if there is det + if inds.numel() > 0: + cls_scores = scores[:, j][inds] + _, order = torch.sort(cls_scores, 0, True) + if args.class_agnostic: + cls_boxes = pred_boxes[inds, :] + else: + cls_boxes = pred_boxes[inds][:, j * 4:(j + 1) * 4] + + cls_dets = torch.cat((cls_boxes, cls_scores.unsqueeze(1)), 1) + # cls_dets = torch.cat((cls_boxes, cls_scores), 1) + cls_dets = cls_dets[order] + keep = nms(cls_boxes[order, :], cls_scores[order], cfg.TEST.NMS) + cls_dets = cls_dets[keep.view(-1).long()] + if vis: + im2show = vis_detections(im2show, imdb.classes[j], cls_dets.cpu().numpy(), 0.3) + all_boxes[j][i] = cls_dets.cpu().numpy() + else: + all_boxes[j][i] = empty_array + + # Limit to max_per_image detections *over all classes* + if max_per_image > 0: + image_scores = np.hstack([all_boxes[j][i][:, -1] + for j in xrange(1, imdb.num_classes)]) + if len(image_scores) > max_per_image: + image_thresh = np.sort(image_scores)[-max_per_image] + for j in xrange(1, imdb.num_classes): + keep = np.where(all_boxes[j][i][:, -1] >= image_thresh)[0] + all_boxes[j][i] = all_boxes[j][i][keep, :] + + misc_toc = time.time() + nms_time = misc_toc - misc_tic + + sys.stdout.write('im_detect: {:d}/{:d} {:.3f}s {:.3f}s \r' \ + .format(i + 1, num_images, detect_time, nms_time)) + sys.stdout.flush() + + if vis: + cv2.imwrite('result.png', im2show) + pdb.set_trace() + # cv2.imshow('test', im2show) + # cv2.waitKey(0) + + with open(det_file, 'wb') as f: + pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL) + + print('Evaluating detections') + imdb.evaluate_detections(all_boxes, output) + + end = time.time() print("test time: %0.4fs" % (end - start)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/RefineDet/README.md b/ACL_PyTorch/contrib/cv/detection/RefineDet/README.md index e2153e4e22855270ac8b027e74efb8eb0379172c..94deccbabafb00b292d990175032dd1aa4e26a37 100644 --- a/ACL_PyTorch/contrib/cv/detection/RefineDet/README.md +++ b/ACL_PyTorch/contrib/cv/detection/RefineDet/README.md @@ -1,241 +1,241 @@ -# RefineDet模型PyTorch离线推理指导 - -## 文件说明 - -``` -├── test //打印精度性能脚本文件夹 -├── eval_utils.py //后处理精度计算时需要用到的函数 -├── get_prior_data.py //获取prior_data的脚本 -├── get_info.py //用于获取二进制数据集信息的脚本 -├── RefineDet_postprocess.py //后处理精度计算脚本 -├── RefineDet_preprocess.py //数据集预处理脚本 -├── RefineDet_pth2onnx.py //pth转onnx脚本 -├── refinedet.patch //开源代码补丁 -├── requirements.txt //环境依赖 -├── LICENSE -├── modelzoo_level.txt -└── README.md -``` - -## 1 环境准备 - -1. 安装必要的依赖 - -``` -pip3.7 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple -``` - -2. 获取开源代码仓和权重文件放到当前路径下 - -[权重文件](https://drive.google.com/file/d/1RCCTaNeby0g-TFE1Cvjm3dYweBiyyPoq/view?usp=sharing) - -``` -git clone https://github.com/luuuyi/RefineDet.PyTorch.git -cd RefineDet.PyTorch -git checkout master -git reset --hard 0e4b24ce07245fcb8c48292326a731729cc5746a -``` - -3. 执行“refinedet.patch”文件 - -``` -patch -p1 < ../refinedet.patch -cd .. -``` - -## 2 准备数据集 - -1. 获取原始数据集 - -本模型支持VOC2007 4952张图片的验证集。请用户需自行获取VOC2007数据集,上传数据集到服务器任意目录并解压(如:/root/datasets/VOCdevkit/)。 - -[VOC数据集下载](http://host.robots.ox.ac.uk/pascal/VOC) - -文件目录结构如下: - -``` -VOC2007 -├──SegmentationObject -├──SegmentationClass -├──JPEGImages -├──Annotations -├──ImageSets -│ ├── Segmentation -│ ├── Main -│ ├── Layout -``` - -2. 数据预处理 - -运行“RefineDet_preprocess.py”脚本将jpg文件转化为二进制bin文件。 - -``` -python3.7 RefineDet_preprocess.py '/root/datasets/VOCdevkit/' voc07test_bin -``` - -- “/root/datasets/VOCdevkit/”:数据集的路径。 - -- “voc07test_bin”:生成的bin文件路径。 - -3. 生成数据集info文件 - -执行“get_info.py”脚本,输入已经获得的图片文件,输出生成图片数据集的info文件。 - -``` -python3.7 get_info.py voc07test_bin voc07test.info -``` -- “voc07test_bin”:预处理数据集路径。 - -- “voc07test.info”:生成的info文件的相对路径。 - -运行结束后生成“voc07test.info”。 - -## 3 模型推理 - -1. 模型转换 - -使用PyTorch将模型权重文件.pth转换为.onnx文件,再使用ATC工具将.onnx文件转为离线推理模型文件.om文件。 - -a.获取权重文件。 - -从源码包中获取权重文件“RefineDet320_VOC_final.pth”。 - -b. 导出onnx文件。 - -执行“RefineDet_pth2onnx.py”脚本导出onnx文件。 - -``` -python3.7 RefineDet_pth2onnx.py './RefineDet320_VOC_final.pth' 'RefineDet320_VOC_final_no_nms.onnx' '/root/datasets/VOCdevkit/' -``` - -- “./RefineDet320_VOC_final.pth”:权重文件路径。 - -- “RefineDet320_VOC_final_no_nms.onnx”:生成的onnx文件。 - -- “/root/datasets/VOCdevkit/”:数据集路径。 - -运行结束得到 “RefineDet320_VOC_final_no_nms.onnx”文件。 - -2. 使用ATC工具将ONNX模型转OM模型 - -a. 设置环境变量 - -``` -source /usr/local/Ascend/ascend-toolkit/set_env.sh -``` - -- 该脚本中环境变量仅供参考,请以实际安装环境配置环境变量。 - -b. 执行命令得到om模型 - -Ascend710: - -``` -atc --framework=5 --out_nodes="Reshape_239:0;Softmax_246:0;Reshape_226:0;Softmax_233:0" --model=RefineDet320_VOC_final_no_nms.onnx ---output=refinedet_voc_320_non_nms_bs1_710 --input_format=NCHW --input_shape="image:1,3,320,320" --log=debug ---soc_version=Ascend710 --precision_mode allow_fp32_to_fp16 -``` - -Ascend310: - -``` -atc --framework=5 --out_nodes="Reshape_239:0;Softmax_246:0;Reshape_226:0;Softmax_233:0" --model=RefineDet320_VOC_final_no_nms.onnx ---output=refinedet_voc_320_non_nms_bs1_310 --input_format=NCHW --input_shape="image:1,3,320,320" --log=debug ---soc_version=Ascend310 --precision_mode allow_fp32_to_fp16 -``` - -提示:切换不同batchsize时需要修改参数--output中的文件名"和--input_shape="batchsize,3,320,320" - -参数说明 -- --model:为ONNX模型文件。 -- --framework:5代表ONNX模型。 -- --output:输出的OM模型。 -- --input_format:输入数据的格式。 -- --input_shape:输入数据的shape。 -- --log:日志级别。 -- --soc_version:处理器型号。 - -``` -若atc执行出错,错误代码为E10016,请使用Netron工具查看对应Reshape节点和Softmax节点,并修改代码。 -``` - -3. 开始推理验证 - -a. 使用Benchmark工具进行推理 - -[benchmark获取](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) - -执行以下命令增加Benchmark工具可执行权限,并根据OS架构选择工具,如果是X86架构,工具选择benchmark.x86_64,如果是Arm,选择benchmark.aarch64 。 - -``` -chmod u+x benchmark.${arch} -``` - -benchmark.${arch}:选择对应操作系统的benchmark工具,如benchmark.x86_64或benchmark.aarch64 。 - -b. 执行推理 - -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./refinedet_voc_320_non_nms_bs1_710.om - -input_text_path=./voc07test.info -input_width=320 -input_height=320 -output_binary=True -useDvpp=False -``` - -- 切换不同batchsize时需要修改参数 -batch_size=和对应的om文件名即参数 -om_path -- 默认推理的是Ascend710处理器下转换的om文件,如要推理Ascend310处理器下转换的om文件,应当修改对应参数"--om_path="的后缀为310 - -推理后的输出默认在当前目录result下。 - -参数说明 -- -model_type:模型类型 -- -om_path:om文件路径 -- -device_id:NPU设备编号 -- -batch_size:参数规模 -- -input_text_path:图片二进制信息 -- -input_width:输入图片宽度 -- -input_height:输入图片高度 -- -useDvpp:是否使用Dvpp -- -output_binary:输出二进制形式 - -性能相关文件也输出在目录result下 - -c. 精度验证 - -调用“RefineDet_postprocess .py”脚本,可以获得Accuracy数据,结果保存在result.json中。 - -``` -python3.7 get_prior_data.py -``` -``` -mv result/dumpOutput_device0 result/dumpOutput_device0_bs1 -``` -- 不同batchsize文件名需修改"_bs【batchsize】" -``` -python3.7 RefineDet_postprocess.py --datasets_path '/root/datasets/VOCdevkit/' --result_path result/dumpOutput_device0_bs1 > result_bs1.json -``` - -- 不同batchsize文件名需修改"_bs【batchsize】",即修改参数--result_path,还需修改输出的json文件名"_bs【batchsize】" - -参数说明 -- --datasets_path:数据集路径。 -- --result_path:推理得到的bin文件路径。 - -最后推理精度结果储存在"result_bs1.json"中 - -## 精度和性能 - -**评测结果:** - -| 模型 | pth精度 | 310精度 |310性能 |710精度 |710性能 -|:--------------:| :------: | :------: | :------: | :------: | :------: | -| RefineDet bs1 | [mAP:79.81%](https://github.com/luuuyi/RefineDet.PyTorch) | mAP:79.56%|166.06fps|mAP:79.58%|269.125fps -| RefineDet bs32 | [mAP:79.81%](https://github.com/luuuyi/RefineDet.PyTorch) |mAP:79.56% | 232.18fps|mAP:79.58%|374.522fps - -备注: - -- nms放在后处理,在cpu上计算 -- onnx转om时,不能使用fp16,否则精度不达标 - -``` ---precision_mode allow_fp32_to_fp16 -``` - +# RefineDet模型PyTorch离线推理指导 + +## 文件说明 + +``` +├── test //打印精度性能脚本文件夹 +├── eval_utils.py //后处理精度计算时需要用到的函数 +├── get_prior_data.py //获取prior_data的脚本 +├── get_info.py //用于获取二进制数据集信息的脚本 +├── RefineDet_postprocess.py //后处理精度计算脚本 +├── RefineDet_preprocess.py //数据集预处理脚本 +├── RefineDet_pth2onnx.py //pth转onnx脚本 +├── refinedet.patch //开源代码补丁 +├── requirements.txt //环境依赖 +├── LICENSE +├── modelzoo_level.txt +└── README.md +``` + +## 1 环境准备 + +1. 安装必要的依赖 + +``` +pip3.7 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple +``` + +2. 获取开源代码仓和权重文件放到当前路径下 + +[权重文件](https://drive.google.com/file/d/1RCCTaNeby0g-TFE1Cvjm3dYweBiyyPoq/view?usp=sharing) + +``` +git clone https://github.com/luuuyi/RefineDet.PyTorch.git +cd RefineDet.PyTorch +git checkout master +git reset --hard 0e4b24ce07245fcb8c48292326a731729cc5746a +``` + +3. 执行“refinedet.patch”文件 + +``` +patch -p1 < ../refinedet.patch +cd .. +``` + +## 2 准备数据集 + +1. 获取原始数据集 + +本模型支持VOC2007 4952张图片的验证集。请用户需自行获取VOC2007数据集,上传数据集到服务器任意目录并解压(如:/root/datasets/VOCdevkit/)。 + +[VOC数据集下载](http://host.robots.ox.ac.uk/pascal/VOC) + +文件目录结构如下: + +``` +VOC2007 +├──SegmentationObject +├──SegmentationClass +├──JPEGImages +├──Annotations +├──ImageSets +│ ├── Segmentation +│ ├── Main +│ ├── Layout +``` + +2. 数据预处理 + +运行“RefineDet_preprocess.py”脚本将jpg文件转化为二进制bin文件。 + +``` +python3.7 RefineDet_preprocess.py '/root/datasets/VOCdevkit/' voc07test_bin +``` + +- “/root/datasets/VOCdevkit/”:数据集的路径。 + +- “voc07test_bin”:生成的bin文件路径。 + +3. 生成数据集info文件 + +执行“get_info.py”脚本,输入已经获得的图片文件,输出生成图片数据集的info文件。 + +``` +python3.7 get_info.py voc07test_bin voc07test.info +``` +- “voc07test_bin”:预处理数据集路径。 + +- “voc07test.info”:生成的info文件的相对路径。 + +运行结束后生成“voc07test.info”。 + +## 3 模型推理 + +1. 模型转换 + +使用PyTorch将模型权重文件.pth转换为.onnx文件,再使用ATC工具将.onnx文件转为离线推理模型文件.om文件。 + +a.获取权重文件。 + +从源码包中获取权重文件“RefineDet320_VOC_final.pth”。 + +b. 导出onnx文件。 + +执行“RefineDet_pth2onnx.py”脚本导出onnx文件。 + +``` +python3.7 RefineDet_pth2onnx.py './RefineDet320_VOC_final.pth' 'RefineDet320_VOC_final_no_nms.onnx' '/root/datasets/VOCdevkit/' +``` + +- “./RefineDet320_VOC_final.pth”:权重文件路径。 + +- “RefineDet320_VOC_final_no_nms.onnx”:生成的onnx文件。 + +- “/root/datasets/VOCdevkit/”:数据集路径。 + +运行结束得到 “RefineDet320_VOC_final_no_nms.onnx”文件。 + +2. 使用ATC工具将ONNX模型转OM模型 + +a. 设置环境变量 + +``` +source /usr/local/Ascend/ascend-toolkit/set_env.sh +``` + +- 该脚本中环境变量仅供参考,请以实际安装环境配置环境变量。 + +b. 执行命令得到om模型 + +Ascend710: + +``` +atc --framework=5 --out_nodes="Reshape_239:0;Softmax_246:0;Reshape_226:0;Softmax_233:0" --model=RefineDet320_VOC_final_no_nms.onnx +--output=refinedet_voc_320_non_nms_bs1_710 --input_format=NCHW --input_shape="image:1,3,320,320" --log=debug +--soc_version=Ascend710 --precision_mode allow_fp32_to_fp16 +``` + +Ascend310: + +``` +atc --framework=5 --out_nodes="Reshape_239:0;Softmax_246:0;Reshape_226:0;Softmax_233:0" --model=RefineDet320_VOC_final_no_nms.onnx +--output=refinedet_voc_320_non_nms_bs1_310 --input_format=NCHW --input_shape="image:1,3,320,320" --log=debug +--soc_version=Ascend310 --precision_mode allow_fp32_to_fp16 +``` + +提示:切换不同batchsize时需要修改参数--output中的文件名"和--input_shape="batchsize,3,320,320" + +参数说明 +- --model:为ONNX模型文件。 +- --framework:5代表ONNX模型。 +- --output:输出的OM模型。 +- --input_format:输入数据的格式。 +- --input_shape:输入数据的shape。 +- --log:日志级别。 +- --soc_version:处理器型号。 + +``` +若atc执行出错,错误代码为E10016,请使用Netron工具查看对应Reshape节点和Softmax节点,并修改代码。 +``` + +3. 开始推理验证 + +a. 使用Benchmark工具进行推理 + +[benchmark获取](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) + +执行以下命令增加Benchmark工具可执行权限,并根据OS架构选择工具,如果是X86架构,工具选择benchmark.x86_64,如果是Arm,选择benchmark.aarch64 。 + +``` +chmod u+x benchmark.${arch} +``` + +benchmark.${arch}:选择对应操作系统的benchmark工具,如benchmark.x86_64或benchmark.aarch64 。 + +b. 执行推理 + +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./refinedet_voc_320_non_nms_bs1_710.om + -input_text_path=./voc07test.info -input_width=320 -input_height=320 -output_binary=True -useDvpp=False +``` + +- 切换不同batchsize时需要修改参数 -batch_size=和对应的om文件名即参数 -om_path +- 默认推理的是Ascend710处理器下转换的om文件,如要推理Ascend310处理器下转换的om文件,应当修改对应参数"--om_path="的后缀为310 + +推理后的输出默认在当前目录result下。 + +参数说明 +- -model_type:模型类型 +- -om_path:om文件路径 +- -device_id:NPU设备编号 +- -batch_size:参数规模 +- -input_text_path:图片二进制信息 +- -input_width:输入图片宽度 +- -input_height:输入图片高度 +- -useDvpp:是否使用Dvpp +- -output_binary:输出二进制形式 + +性能相关文件也输出在目录result下 + +c. 精度验证 + +调用“RefineDet_postprocess .py”脚本,可以获得Accuracy数据,结果保存在result.json中。 + +``` +python3.7 get_prior_data.py +``` +``` +mv result/dumpOutput_device0 result/dumpOutput_device0_bs1 +``` +- 不同batchsize文件名需修改"_bs【batchsize】" +``` +python3.7 RefineDet_postprocess.py --datasets_path '/root/datasets/VOCdevkit/' --result_path result/dumpOutput_device0_bs1 > result_bs1.json +``` + +- 不同batchsize文件名需修改"_bs【batchsize】",即修改参数--result_path,还需修改输出的json文件名"_bs【batchsize】" + +参数说明 +- --datasets_path:数据集路径。 +- --result_path:推理得到的bin文件路径。 + +最后推理精度结果储存在"result_bs1.json"中 + +## 精度和性能 + +**评测结果:** + +| 模型 | pth精度 | 310精度 |310性能 |710精度 |710性能 +|:--------------:| :------: | :------: | :------: | :------: | :------: | +| RefineDet bs1 | [mAP:79.81%](https://github.com/luuuyi/RefineDet.PyTorch) | mAP:79.56%|166.06fps|mAP:79.58%|269.125fps +| RefineDet bs32 | [mAP:79.81%](https://github.com/luuuyi/RefineDet.PyTorch) |mAP:79.56% | 232.18fps|mAP:79.58%|374.522fps + +备注: + +- nms放在后处理,在cpu上计算 +- onnx转om时,不能使用fp16,否则精度不达标 + +``` +--precision_mode allow_fp32_to_fp16 +``` + diff --git a/ACL_PyTorch/contrib/cv/detection/RefineDet/env.sh b/ACL_PyTorch/contrib/cv/detection/RefineDet/env.sh index 7cf86a22a607ba18523498bcfb5617e97b28a0e0..e4c421dd8d10faa7f5e617cb1f91d34e8ee685bc 100644 --- a/ACL_PyTorch/contrib/cv/detection/RefineDet/env.sh +++ b/ACL_PyTorch/contrib/cv/detection/RefineDet/env.sh @@ -1,6 +1,6 @@ -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp export ASCEND_AICPU_PATH=${install_path} \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/RefineDet/get_prior_data.py b/ACL_PyTorch/contrib/cv/detection/RefineDet/get_prior_data.py index abc627029e75094369666ebd920c356413e1330b..095256efd91591132dbec219dbbede0713d72060 100644 --- a/ACL_PyTorch/contrib/cv/detection/RefineDet/get_prior_data.py +++ b/ACL_PyTorch/contrib/cv/detection/RefineDet/get_prior_data.py @@ -1,28 +1,28 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import sys -sys.path.append('./RefineDet.PyTorch') -from layers.functions.prior_box import PriorBox -from data import voc_refinedet -import numpy as np - -cfg = voc_refinedet['320'] - -prior_box = PriorBox(cfg) - -prior_data = prior_box.forward().numpy() - -np.savetxt('prior_data.txt', prior_data) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +sys.path.append('./RefineDet.PyTorch') +from layers.functions.prior_box import PriorBox +from data import voc_refinedet +import numpy as np + +cfg = voc_refinedet['320'] + +prior_box = PriorBox(cfg) + +prior_data = prior_box.forward().numpy() + +np.savetxt('prior_data.txt', prior_data) + print('Finish') \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/RefineDet/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/detection/RefineDet/modelzoo_level.txt index 83689985f26624b65a4c5ebb5f00a152618799ba..8c469d858afccf3026a8640799938f8de7b46fac 100644 --- a/ACL_PyTorch/contrib/cv/detection/RefineDet/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/detection/RefineDet/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:PERFECT \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Retinanet/LICENSE b/ACL_PyTorch/contrib/cv/detection/Retinanet/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/detection/Retinanet/LICENSE +++ b/ACL_PyTorch/contrib/cv/detection/Retinanet/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Retinanet/get_info.py b/ACL_PyTorch/contrib/cv/detection/Retinanet/get_info.py index b76d6739bcea5c528a031970f0e583e5b5644bd8..d5cab0450c20d502d0d15be2f9c0fceffa6a6191 100644 --- a/ACL_PyTorch/contrib/cv/detection/Retinanet/get_info.py +++ b/ACL_PyTorch/contrib/cv/detection/Retinanet/get_info.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Retinanet/requirements.txt b/ACL_PyTorch/contrib/cv/detection/Retinanet/requirements.txt index 84cc44c3bbcb4d4e88f49dd0a3cb21c9493e22e0..03db083c861ce8283054386e3aa50683548b81a0 100644 --- a/ACL_PyTorch/contrib/cv/detection/Retinanet/requirements.txt +++ b/ACL_PyTorch/contrib/cv/detection/Retinanet/requirements.txt @@ -1,5 +1,5 @@ -torch == 1.8.1 -torchvision == 0.9.0 -onnx == 1.7.0 -numpy == 1.18.5 +torch == 1.8.1 +torchvision == 0.9.0 +onnx == 1.7.0 +numpy == 1.18.5 opencv-python == 4.2.0.34 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Retinanet/retinanet_pth_postprocess_detectron2.py b/ACL_PyTorch/contrib/cv/detection/Retinanet/retinanet_pth_postprocess_detectron2.py index 62b94f1fd42d5b32c06bee8782c6b8b497577918..15958efd02ccb1188d215bd047c3b52080044a26 100644 --- a/ACL_PyTorch/contrib/cv/detection/Retinanet/retinanet_pth_postprocess_detectron2.py +++ b/ACL_PyTorch/contrib/cv/detection/Retinanet/retinanet_pth_postprocess_detectron2.py @@ -1,186 +1,186 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - - -import os -import argparse -import cv2 -import numpy as np -from pycocotools.cocoeval import COCOeval -from pycocotools.coco import COCO -import json -import pickle -import logging - -class CocoDataset: - """Coco dataset.""" - - def __init__(self, root_dir, set_name='train2017', transform=None): - """ - Args: - root_dir (string): COCO directory. - transform (callable, optional): Optional transform to be applied - on a sample. - """ - self.root_dir = root_dir - self.set_name = set_name - self.transform = transform - - self.coco = COCO(os.path.join(self.root_dir, 'annotations', 'instances_' + self.set_name + '.json')) - self.image_ids = self.coco.getImgIds() - - self.load_classes() - - def load_classes(self): - # load class names (name -> label) - categories = self.coco.loadCats(self.coco.getCatIds()) - categories.sort(key=lambda x: x['id']) - - self.classes = {} - self.coco_labels = {} - self.coco_labels_inverse = {} - for c in categories: - self.coco_labels[len(self.classes)] = c['id'] - self.coco_labels_inverse[c['id']] = len(self.classes) - self.classes[c['name']] = len(self.classes) - - # also load the reverse (label -> name) - self.labels = {} - for key, value in self.classes.items(): - self.labels[value] = key - - def coco_label_to_label(self, coco_label): - return self.coco_labels_inverse[coco_label] - - def label_to_coco_label(self, label): - return self.coco_labels[label] - -def postprocess_bboxes(bboxes, image_size, net_input_width, net_input_height): - old_h = image_size[0] - old_w = image_size[1] - scale_ratio = 800 / min(old_w, old_h) - if old_h < old_w: - new_h, new_w = 800, int(np.floor(scale_ratio * old_w)) - else: - new_h, new_w = int(np.floor(scale_ratio * old_h)), 800 - if max(new_h, new_w) > 1333: - scale = 1333 / max(new_h, new_w) - new_h = new_h * scale - new_w = new_w * scale - new_w = int(new_w + 0.5) - new_h = int(new_h + 0.5) - scale = new_w/old_w - - bboxes[:, 0] = (bboxes[:, 0]) / scale - bboxes[:, 1] = (bboxes[:, 1]) / scale - bboxes[:, 2] = (bboxes[:, 2]) / scale - bboxes[:, 3] = (bboxes[:, 3]) / scale - - return bboxes - - -def save_variable(v, filename): - f = open(filename, 'wb') - pickle.dump(v, f) - f.close() -def load_variavle(filename): - f = open(filename, 'rb') - r = pickle.load(f) - f.close() - return r - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--test_annotation", default="./origin_image.info") - parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0/") - parser.add_argument("--val2017_path", default="/root/datasets/coco/val2017/") - parser.add_argument("--det_results_path", default="./result/detection-results/") - parser.add_argument("--net_out_num", type=int, default=3) - parser.add_argument("--net_input_width", type=int, default=1344) - parser.add_argument("--net_input_height", type=int, default=1344) - parser.add_argument("--ifShowDetObj", action="store_true", help="if input the para means True, neither False.") - flags = parser.parse_args() - - img_size_dict = dict() - with open(flags.test_annotation)as f: - for line in f.readlines(): - temp = line.split(" ") - img_file_path = temp[1] - img_name = temp[1].split("/")[-1].split(".")[0] - img_width = int(temp[2]) - img_height = int(temp[3]) - img_size_dict[img_name] = (img_width, img_height, img_file_path) - - bin_path = flags.bin_data_path - det_results_path = flags.det_results_path - os.makedirs(det_results_path, exist_ok=True) - total_img = set([name[:name.rfind('_')] for name in os.listdir(bin_path) if "bin" in name]) - - logging.basicConfig(level=logging.INFO) - coco_path = flags.val2017_path - dataloader_val = CocoDataset(coco_path, set_name='val2017') - results = [] - image_ids = [] - - for bin_file in sorted(total_img): - path_base = os.path.join(bin_path, bin_file) - res_buff = [] - for num in range(1, flags.net_out_num + 1): - if os.path.exists(path_base + "_" + str(num) + ".bin"): - if num == 1: - buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="float32") - boxes = np.reshape(buf, [100, 4]) - elif num == 2: - buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="int32") - labels = np.reshape(buf, [100, 1]) - elif num == 3: - buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="float32") - scores = np.reshape(buf, [100, 1]) - else: - print("[ERROR] file not exist", path_base + "_" + str(num) + ".bin") - - current_img_size = img_size_dict[bin_file] - boxes = postprocess_bboxes(boxes, current_img_size, flags.net_input_width, flags.net_input_height) - - if boxes.shape[0] > 0: - # change to (x, y, w, h) (MS COCO standard) - boxes[:, 2] -= boxes[:, 0] - boxes[:, 3] -= boxes[:, 1] - for box_id in range(boxes.shape[0]): - if scores[box_id] <0.05: - continue - score = float(scores[box_id]) - label = int(labels[box_id]) - box = boxes[box_id, :] - image_result = { - 'image_id': int(bin_file), - 'category_id': dataloader_val.label_to_coco_label(label), - 'score': float(score), - 'bbox': box.tolist(), - } - # append detection to results - results.append(image_result) - image_ids.append(int(bin_file)) - - json.dump(results, open('{}_bbox_results.json'.format(dataloader_val.set_name), 'w'), indent=4) - coco_true = dataloader_val.coco - coco_pred = coco_true.loadRes('{}_bbox_results.json'.format(dataloader_val.set_name)) - - # run COCO evaluation - coco_eval = COCOeval(coco_true, coco_pred, 'bbox') - coco_eval.params.imgIds = image_ids - coco_eval.evaluate() - coco_eval.accumulate() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + + +import os +import argparse +import cv2 +import numpy as np +from pycocotools.cocoeval import COCOeval +from pycocotools.coco import COCO +import json +import pickle +import logging + +class CocoDataset: + """Coco dataset.""" + + def __init__(self, root_dir, set_name='train2017', transform=None): + """ + Args: + root_dir (string): COCO directory. + transform (callable, optional): Optional transform to be applied + on a sample. + """ + self.root_dir = root_dir + self.set_name = set_name + self.transform = transform + + self.coco = COCO(os.path.join(self.root_dir, 'annotations', 'instances_' + self.set_name + '.json')) + self.image_ids = self.coco.getImgIds() + + self.load_classes() + + def load_classes(self): + # load class names (name -> label) + categories = self.coco.loadCats(self.coco.getCatIds()) + categories.sort(key=lambda x: x['id']) + + self.classes = {} + self.coco_labels = {} + self.coco_labels_inverse = {} + for c in categories: + self.coco_labels[len(self.classes)] = c['id'] + self.coco_labels_inverse[c['id']] = len(self.classes) + self.classes[c['name']] = len(self.classes) + + # also load the reverse (label -> name) + self.labels = {} + for key, value in self.classes.items(): + self.labels[value] = key + + def coco_label_to_label(self, coco_label): + return self.coco_labels_inverse[coco_label] + + def label_to_coco_label(self, label): + return self.coco_labels[label] + +def postprocess_bboxes(bboxes, image_size, net_input_width, net_input_height): + old_h = image_size[0] + old_w = image_size[1] + scale_ratio = 800 / min(old_w, old_h) + if old_h < old_w: + new_h, new_w = 800, int(np.floor(scale_ratio * old_w)) + else: + new_h, new_w = int(np.floor(scale_ratio * old_h)), 800 + if max(new_h, new_w) > 1333: + scale = 1333 / max(new_h, new_w) + new_h = new_h * scale + new_w = new_w * scale + new_w = int(new_w + 0.5) + new_h = int(new_h + 0.5) + scale = new_w/old_w + + bboxes[:, 0] = (bboxes[:, 0]) / scale + bboxes[:, 1] = (bboxes[:, 1]) / scale + bboxes[:, 2] = (bboxes[:, 2]) / scale + bboxes[:, 3] = (bboxes[:, 3]) / scale + + return bboxes + + +def save_variable(v, filename): + f = open(filename, 'wb') + pickle.dump(v, f) + f.close() +def load_variavle(filename): + f = open(filename, 'rb') + r = pickle.load(f) + f.close() + return r + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--test_annotation", default="./origin_image.info") + parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0/") + parser.add_argument("--val2017_path", default="/root/datasets/coco/val2017/") + parser.add_argument("--det_results_path", default="./result/detection-results/") + parser.add_argument("--net_out_num", type=int, default=3) + parser.add_argument("--net_input_width", type=int, default=1344) + parser.add_argument("--net_input_height", type=int, default=1344) + parser.add_argument("--ifShowDetObj", action="store_true", help="if input the para means True, neither False.") + flags = parser.parse_args() + + img_size_dict = dict() + with open(flags.test_annotation)as f: + for line in f.readlines(): + temp = line.split(" ") + img_file_path = temp[1] + img_name = temp[1].split("/")[-1].split(".")[0] + img_width = int(temp[2]) + img_height = int(temp[3]) + img_size_dict[img_name] = (img_width, img_height, img_file_path) + + bin_path = flags.bin_data_path + det_results_path = flags.det_results_path + os.makedirs(det_results_path, exist_ok=True) + total_img = set([name[:name.rfind('_')] for name in os.listdir(bin_path) if "bin" in name]) + + logging.basicConfig(level=logging.INFO) + coco_path = flags.val2017_path + dataloader_val = CocoDataset(coco_path, set_name='val2017') + results = [] + image_ids = [] + + for bin_file in sorted(total_img): + path_base = os.path.join(bin_path, bin_file) + res_buff = [] + for num in range(1, flags.net_out_num + 1): + if os.path.exists(path_base + "_" + str(num) + ".bin"): + if num == 1: + buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="float32") + boxes = np.reshape(buf, [100, 4]) + elif num == 2: + buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="int32") + labels = np.reshape(buf, [100, 1]) + elif num == 3: + buf = np.fromfile(path_base + "_" + str(num) + ".bin", dtype="float32") + scores = np.reshape(buf, [100, 1]) + else: + print("[ERROR] file not exist", path_base + "_" + str(num) + ".bin") + + current_img_size = img_size_dict[bin_file] + boxes = postprocess_bboxes(boxes, current_img_size, flags.net_input_width, flags.net_input_height) + + if boxes.shape[0] > 0: + # change to (x, y, w, h) (MS COCO standard) + boxes[:, 2] -= boxes[:, 0] + boxes[:, 3] -= boxes[:, 1] + for box_id in range(boxes.shape[0]): + if scores[box_id] <0.05: + continue + score = float(scores[box_id]) + label = int(labels[box_id]) + box = boxes[box_id, :] + image_result = { + 'image_id': int(bin_file), + 'category_id': dataloader_val.label_to_coco_label(label), + 'score': float(score), + 'bbox': box.tolist(), + } + # append detection to results + results.append(image_result) + image_ids.append(int(bin_file)) + + json.dump(results, open('{}_bbox_results.json'.format(dataloader_val.set_name), 'w'), indent=4) + coco_true = dataloader_val.coco + coco_pred = coco_true.loadRes('{}_bbox_results.json'.format(dataloader_val.set_name)) + + # run COCO evaluation + coco_eval = COCOeval(coco_true, coco_pred, 'bbox') + coco_eval.params.imgIds = image_ids + coco_eval.evaluate() + coco_eval.accumulate() coco_eval.summarize() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Retinanet/retinanet_pth_preprocess_detectron2.py b/ACL_PyTorch/contrib/cv/detection/Retinanet/retinanet_pth_preprocess_detectron2.py index 46fa64f920ce7cb1fa2af613021957bc7bc9dbd6..2700b4242ac1a99e29d6df3ab7271a621ed99b4c 100644 --- a/ACL_PyTorch/contrib/cv/detection/Retinanet/retinanet_pth_preprocess_detectron2.py +++ b/ACL_PyTorch/contrib/cv/detection/Retinanet/retinanet_pth_preprocess_detectron2.py @@ -1,80 +1,80 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import argparse -import numpy as np -import cv2 -import torch -import multiprocessing -def resize(img, size): - - old_h = img.shape[0] - old_w = img.shape[1] - scale_ratio = 800 / min(old_w, old_h) - if old_h < old_w: - new_h, new_w = 800, int(np.floor(scale_ratio * old_w)) - else: - new_h, new_w = int(np.floor(scale_ratio * old_h)), 800 - if max(new_h, new_w) > 1333: - scale = 1333 / max(new_h, new_w) - new_h = new_h * scale - new_w = new_w * scale - new_w = int(new_w + 0.5) - new_h = int(new_h + 0.5) - ret = cv2.resize(img, (new_w, new_h), interpolation=cv2.INTER_LINEAR) - return ret - - -def gen_input_bin(file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - image = cv2.imread(os.path.join(flags.image_src_path, file), cv2.IMREAD_COLOR) - image = resize(image, (800, 1333)) - mean = np.array([103.53, 116.28, 123.675], dtype=np.float32) - std = np.array([1., 1., 1.], dtype=np.float32) - img = image.copy().astype(np.float32) - mean = np.float64(mean.reshape(1, -1)) - std = 1 / np.float64(std.reshape(1, -1)) - cv2.subtract(img, mean, img) - cv2.multiply(img, std, img) - - img = cv2.copyMakeBorder(img, 0, flags.model_input_height - img.shape[0], 0, flags.model_input_width - img.shape[1], cv2.BORDER_CONSTANT, value=0) - img = img.transpose(2, 0, 1) - - - img.tofile(os.path.join(flags.bin_file_path, file.split('.')[0] + ".bin")) - -def preprocess(src_path, save_path): - files = os.listdir(src_path) - file_batches = [files[i:i + 100] for i in range(0, 5000, 100) if files[i:i + 100] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='preprocess of MaskRCNN PyTorch model') - parser.add_argument("--image_src_path", default="/root/datasets/coco/val2017", help='image of dataset') - parser.add_argument("--bin_file_path", default="./val2017_bin/", help='Preprocessed image buffer') - parser.add_argument("--model_input_height", default=1344, type=int, help='input tensor height') - parser.add_argument("--model_input_width", default=1344, type=int, help='input tensor width') - flags = parser.parse_args() - if not os.path.exists(flags.bin_file_path): - os.makedirs(flags.bin_file_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import argparse +import numpy as np +import cv2 +import torch +import multiprocessing +def resize(img, size): + + old_h = img.shape[0] + old_w = img.shape[1] + scale_ratio = 800 / min(old_w, old_h) + if old_h < old_w: + new_h, new_w = 800, int(np.floor(scale_ratio * old_w)) + else: + new_h, new_w = int(np.floor(scale_ratio * old_h)), 800 + if max(new_h, new_w) > 1333: + scale = 1333 / max(new_h, new_w) + new_h = new_h * scale + new_w = new_w * scale + new_w = int(new_w + 0.5) + new_h = int(new_h + 0.5) + ret = cv2.resize(img, (new_w, new_h), interpolation=cv2.INTER_LINEAR) + return ret + + +def gen_input_bin(file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + image = cv2.imread(os.path.join(flags.image_src_path, file), cv2.IMREAD_COLOR) + image = resize(image, (800, 1333)) + mean = np.array([103.53, 116.28, 123.675], dtype=np.float32) + std = np.array([1., 1., 1.], dtype=np.float32) + img = image.copy().astype(np.float32) + mean = np.float64(mean.reshape(1, -1)) + std = 1 / np.float64(std.reshape(1, -1)) + cv2.subtract(img, mean, img) + cv2.multiply(img, std, img) + + img = cv2.copyMakeBorder(img, 0, flags.model_input_height - img.shape[0], 0, flags.model_input_width - img.shape[1], cv2.BORDER_CONSTANT, value=0) + img = img.transpose(2, 0, 1) + + + img.tofile(os.path.join(flags.bin_file_path, file.split('.')[0] + ".bin")) + +def preprocess(src_path, save_path): + files = os.listdir(src_path) + file_batches = [files[i:i + 100] for i in range(0, 5000, 100) if files[i:i + 100] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='preprocess of MaskRCNN PyTorch model') + parser.add_argument("--image_src_path", default="/root/datasets/coco/val2017", help='image of dataset') + parser.add_argument("--bin_file_path", default="./val2017_bin/", help='Preprocessed image buffer') + parser.add_argument("--model_input_height", default=1344, type=int, help='input tensor height') + parser.add_argument("--model_input_width", default=1344, type=int, help='input tensor width') + flags = parser.parse_args() + if not os.path.exists(flags.bin_file_path): + os.makedirs(flags.bin_file_path) preprocess(flags.image_src_path, flags.bin_file_path) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/Retinanet/test/README.md b/ACL_PyTorch/contrib/cv/detection/Retinanet/test/README.md index dc1c3eabd54f5cd5139c11f5865cec207009244e..d8a57f62bd92814b26ff6b4b45eb136bb7905da6 100644 --- a/ACL_PyTorch/contrib/cv/detection/Retinanet/test/README.md +++ b/ACL_PyTorch/contrib/cv/detection/Retinanet/test/README.md @@ -1,49 +1,49 @@ -环境准备: - -1.数据集路径 通用的数据集统一放在/root/datasets/或/opt/npu/ 本模型数据集放在/root/datasets/ -该文件夹下要包含 - -./coco - ./val2017 - ./annotations - ./instances_val2017.json - -2.进入工作目录 cd Retinanet - -3.安装必要的依赖 pip3.7 install -r requirements.txt - -4.获取、修改和安装模型代码 a. 获取模型代码 git clone https://github.com/facebookresearch/detectron2 - -cd detectron2/ git reset --hard 13afb03 - -b.安装 cd .. rm -rf detectron2/build/ **/*.so python3.7 -m pip install -e detectron2 - -如果detectron2安装报错,请尝试下面这种方法安装: cd detectron2 -python3.7 setup.py build develop - -c.修改源代码 -若是基准环境中 -cd detectron2/ patch -p1 < ../retinanet_pth.diff cd .. - -若是npu环境中 -cd detectron2/ patch -p1 < ../retinanet_detectron2.diff cd .. - -5.获取权重文件 -wget https://dl.fbaipublicfiles.com/detectron2/COCO-Detection/retinanet_R_50_FPN_3x/190397829/model_final_5bd44e.pkl -将权重文件改名: mv model_final_5bd44e.pkl model_final.pkl - -6.修改pytorch代码去除导出onnx时进行检查 将/usr/local/python3.7.5/lib/python3.7/site-packages/torch/onnx/utils.py文件的_check_onnx_proto(proto)这一行改为pass - -7.获取benchmark工具 将benchmark.x86_64 benchmark.aarch64放在当前目录 - -推理步骤: - -8..修改detectron2/detectron2/data/datasets/builtin.py的258行为_root = os.getenv("DETECTRON2_DATASETS", "/root/datasets/")指定coco数据集所在的目录/root/datasets/ -运行命令,在output文件夹下生成model.onnx文件 - -python3.7 ./detectron2/tools/deploy/export_model.py --config-file ./detectron2/configs/COCO-Detection/retinanet_R_50_FPN_3x.yaml --output ./output --export-method tracing --format onnx MODEL.WEIGHTS model_final.pkl MODEL.DEVICE cpu - - -9.脚本转换om模型 bash test/pth2om.sh - -10.310上执行,执行时确保device空闲: bash test/eval_acc_perf.sh --datasets_path=/root/datasets +环境准备: + +1.数据集路径 通用的数据集统一放在/root/datasets/或/opt/npu/ 本模型数据集放在/root/datasets/ +该文件夹下要包含 + +./coco + ./val2017 + ./annotations + ./instances_val2017.json + +2.进入工作目录 cd Retinanet + +3.安装必要的依赖 pip3.7 install -r requirements.txt + +4.获取、修改和安装模型代码 a. 获取模型代码 git clone https://github.com/facebookresearch/detectron2 + +cd detectron2/ git reset --hard 13afb03 + +b.安装 cd .. rm -rf detectron2/build/ **/*.so python3.7 -m pip install -e detectron2 + +如果detectron2安装报错,请尝试下面这种方法安装: cd detectron2 +python3.7 setup.py build develop + +c.修改源代码 +若是基准环境中 +cd detectron2/ patch -p1 < ../retinanet_pth.diff cd .. + +若是npu环境中 +cd detectron2/ patch -p1 < ../retinanet_detectron2.diff cd .. + +5.获取权重文件 +wget https://dl.fbaipublicfiles.com/detectron2/COCO-Detection/retinanet_R_50_FPN_3x/190397829/model_final_5bd44e.pkl +将权重文件改名: mv model_final_5bd44e.pkl model_final.pkl + +6.修改pytorch代码去除导出onnx时进行检查 将/usr/local/python3.7.5/lib/python3.7/site-packages/torch/onnx/utils.py文件的_check_onnx_proto(proto)这一行改为pass + +7.获取benchmark工具 将benchmark.x86_64 benchmark.aarch64放在当前目录 + +推理步骤: + +8..修改detectron2/detectron2/data/datasets/builtin.py的258行为_root = os.getenv("DETECTRON2_DATASETS", "/root/datasets/")指定coco数据集所在的目录/root/datasets/ +运行命令,在output文件夹下生成model.onnx文件 + +python3.7 ./detectron2/tools/deploy/export_model.py --config-file ./detectron2/configs/COCO-Detection/retinanet_R_50_FPN_3x.yaml --output ./output --export-method tracing --format onnx MODEL.WEIGHTS model_final.pkl MODEL.DEVICE cpu + + +9.脚本转换om模型 bash test/pth2om.sh + +10.310上执行,执行时确保device空闲: bash test/eval_acc_perf.sh --datasets_path=/root/datasets diff --git a/ACL_PyTorch/contrib/cv/detection/Retinanet/test/parse.py b/ACL_PyTorch/contrib/cv/detection/Retinanet/test/parse.py index b9c74f41d7848e1250356f14472b237a18bb3489..82af69cd183218c3263723c20b652b3f7ec2bc27 100644 --- a/ACL_PyTorch/contrib/cv/detection/Retinanet/test/parse.py +++ b/ACL_PyTorch/contrib/cv/detection/Retinanet/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV1/LICENSE b/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV1/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV1/LICENSE +++ b/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV1/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV1/SSD_MobileNet_pth2onnx.py b/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV1/SSD_MobileNet_pth2onnx.py index 795bae7b1dbc0adefc931bd222982df44483727a..46fafe35d69990f5881357225e058b938bc6b850 100644 --- a/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV1/SSD_MobileNet_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV1/SSD_MobileNet_pth2onnx.py @@ -1,46 +1,46 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import torch.onnx -import sys -sys.path.append(r"./pytorch-ssd") -from vision.ssd.mobilenetv1_ssd import create_mobilenetv1_ssd - - -def pth2onx(model_path, out_path): - num_classes = 21 - net = create_mobilenetv1_ssd(num_classes, is_test=True) - print("begin to load model") - net.load(model_path) - net.eval() - - input_names = ["image"] - dynamic_axes = {'image': {0: '-1'}, 'scores':{0: '-1'}, 'boxes': {0: '-1'}} - output_names = ['scores', 'boxes'] - dummy_input = torch.randn(16, 3, 300, 300) - print("begin to export") - torch.onnx.export(net, dummy_input, out_path, input_names=input_names, - dynamic_axes=dynamic_axes, output_names=output_names, opset_version=11, verbose=True) - print("end export") - - -if __name__ == '__main__': - if len(sys.argv) < 2: - print('Usage: python SSD_MobileNet_pth2onnx.py ') - sys.exit(0) - - model_path = sys.argv[1] - out_path = sys.argv[2] - pth2onx(model_path, out_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import torch.onnx +import sys +sys.path.append(r"./pytorch-ssd") +from vision.ssd.mobilenetv1_ssd import create_mobilenetv1_ssd + + +def pth2onx(model_path, out_path): + num_classes = 21 + net = create_mobilenetv1_ssd(num_classes, is_test=True) + print("begin to load model") + net.load(model_path) + net.eval() + + input_names = ["image"] + dynamic_axes = {'image': {0: '-1'}, 'scores':{0: '-1'}, 'boxes': {0: '-1'}} + output_names = ['scores', 'boxes'] + dummy_input = torch.randn(16, 3, 300, 300) + print("begin to export") + torch.onnx.export(net, dummy_input, out_path, input_names=input_names, + dynamic_axes=dynamic_axes, output_names=output_names, opset_version=11, verbose=True) + print("end export") + + +if __name__ == '__main__': + if len(sys.argv) < 2: + print('Usage: python SSD_MobileNet_pth2onnx.py ') + sys.exit(0) + + model_path = sys.argv[1] + out_path = sys.argv[2] + pth2onx(model_path, out_path) diff --git a/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV1/get_info.py b/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV1/get_info.py index 3073a9bd28b83b4eb7d320b3c63b37d0a835a573..000eccd3f3e95ea63fe123cc6f4567f67ae23bd4 100644 --- a/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV1/get_info.py +++ b/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV1/get_info.py @@ -1,63 +1,63 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join( - [str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len( - sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len( - sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join( + [str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len( + sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len( + sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) diff --git a/ACL_PyTorch/contrib/cv/detection/SSD-Resnet34/README.md b/ACL_PyTorch/contrib/cv/detection/SSD-Resnet34/README.md index 5d1928802d83abff4c6c88fe683a435371b2bae2..c4208fe14548e80a613ac8ba745016c56d2082ea 100644 --- a/ACL_PyTorch/contrib/cv/detection/SSD-Resnet34/README.md +++ b/ACL_PyTorch/contrib/cv/detection/SSD-Resnet34/README.md @@ -1,450 +1,450 @@ -# SSD-Resnet34模型PyTorch离线推理 - -## 一. 环境准备 - -### 1.通过requirements.txt 安装必要依赖 - -首先要先获取torch-1.5.0+ascend.post3.20210930-cp37-cp37m-linux_x86_64.whl,apex-0.1+ascend.20210930-cp37-cp37m-linux_x86_64.whl和tensor_fused_plugin-0.1+ascend-cp37-cp37m-linux_x86_64.whl这3个文件,获取方法如下: - -获取torch-1.5.0+ascend.post3.20210930-cp37-cp37m-linux_x86_64.whl - -x86架构: - -``` -wget https://ascend-pytorch-release.obs.cn-north-4.myhuaweicloud.com/run_pkg/20211018_FrameworkPTAdapter2.0.T308/torch-1.5.0%2Bascend.post3.20210930-cp37-cp37m-linux_x86_64.whl -``` - -ARM架构: - -``` -wget https://ascend-pytorch-release.obs.cn-north-4.myhuaweicloud.com/run_pkg/20211018_FrameworkPTAdapter2.0.T308/torch-1.5.0%2Bascend.post3.20210930-cp37-cp37m-linux_aarch64.whl -``` - -获取tensor_fused_plugin-0.1+ascend-cp37-cp37m-linux_x86_64.whl - -x86架构: - -``` -wget https://ascend-pytorch-release.obs.cn-north-4.myhuaweicloud.com/run_pkg/20210423_TR5/whl_0423/tensor_fused_plugin-0.1%2Bascend-cp37-cp37m-linux_x86_64.whl -``` - -ARM架构: - -``` -wget https://ascend-pytorch-release.obs.cn-north-4.myhuaweicloud.com/run_pkg/20211018_FrameworkPTAdapter2.0.T308/torch-1.5.0%2Bascend.post3.20210930-cp37-cp37m-linux_aarch64.whl -``` - -获取apex-0.1+ascend.20210930-cp37-cp37m-linux_x86_64.whl - -x86架构: - -``` -wget https://ascend-pytorch-release.obs.cn-north-4.myhuaweicloud.com/run_pkg/20211018_FrameworkPTAdapter2.0.T308/apex-0.1%2Bascend.20210930-cp37-cp37m-linux_x86_64.whl -``` - -ARM架构: - -``` -wget https://ascend-pytorch-release.obs.cn-north-4.myhuaweicloud.com/run_pkg/20211018_FrameworkPTAdapter2.0.T308/apex-0.1%2Bascend.20210930-cp37-cp37m-linux_aarch64.whl -``` - -在获得这3个.whl文件之后就使用命令直接运行: - -x86架构: - -``` -pip install torch-1.5.0+ascend.post3.20210930-cp37-cp37m-linux_x86_64.whl -pip install apex-0.1+ascend.20210930-cp37-cp37m-linux_x86_64.whl -pip install tensor_fused_plugin-0.1+ascend-cp37-cp37m-linux_x86_64.whl -``` - -ARM架构: - -``` -pip install torch-1.5.0+ascend.post3.20210930-cp37-cp37m-linux_aarch64.whl -pip install apex-0.1+ascend.20210930-cp37-cp37m-linux_aarch64.whl -pip install tensor_fused_plugin-0.1+ascend-cp37-cp37m-linux_aarch64.whl -``` - -在运行上面的这条命令时,确保torch,apex和tensor_fused_plugin这3个.whl文件和requirements.txt在同一个目录下。 - -之后运行如下指令: - -``` -pip install -r requirements.txt -``` - -在运行完这条命令后,如果error中出现te0.4.0和schedule-search0.0.1相关信息,不需要去看,因为运行这个代码不需要用到,与本代码无关。 - -``` -pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python -apt update -apt install libgl1-mesa-glx -``` - -之后再运行如上3条命令,本代码所需环境即安装完毕。 - -### 2. 获取开源模型代码及开源权重 - -加载开源仓库: - -``` -git clone https://github.com/mlcommons/training_results_v0.7.git -``` - -进入开源代码仓,并打补丁,打补丁时确保补丁在开源代码仓路径的上一级: - -``` -cd training_results_v0.7/NVIDIA/benchmarks/ssd/implementations/pytorch/ -patch -p1 <../ssd.patch -``` - -下载训练后的SSD权重文件: - -``` -wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/detection/SSD-Resnet34/iter_183250.pt -``` - -下载基于搭建SSD模型的Resnet34模型的权重文件 - -``` -wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/detection/SSD-Resnet34/resnet34-333f7ec4.pth -``` - -对于pth权重文件,统一放在新建models文件夹下。 - -``` -├── models -│ ├── iter_183250.pt -│ ├── resnet34-333f7ec4.pth -``` - -### 3. 获取测试数据集 - -本模型支持coco2017的val2017验证数据集,里面有5000张图片。用户可自行获取coco2017数据集中的annotations和val2017,上传数据集到服务器任意目录并解压(如:/home/HwHiAiUser/dataset),本模型将使用到coco2017数据集中的验证集及其标签文件instances_val2017.json, bbox_only_instances_val2017.json,标签文件bbox_only_instances_val2017.json是将coco2017中的原标签文件instances_val2017.json经过处理所得。 - -获得coco数据集的命令如下: - -``` -wget https://ascend-pytorch-one-datasets.obs.cn-north-4.myhuaweicloud.com/infer/zip/coco_2017_ssd_infer.zip -``` - -在本代码中我统一使用了coco这个名字来命名数据: - -``` -mv coco_2017_ssd_infer coco -``` - -获得新json标签文件的命令如下: - -先给prepare-json.py增加权限,不然会出现权限不够的问题: - -``` -chmod -R 777 prepare-json.py -``` - -等增加完权限后再运行: - -``` -python3.7 prepare-json.py --keep-keys ${data_path}/coco/annotations/instances_val2017.json ${data_path}/coco/annotations/bbox_only_instances_val2017.json -``` - -第1部分${data_path}/coco/annotations/instances_val2017.json:这个是输入的json文件路径 - -第2部分${data_path}/coco/annotations/bbox_only_instances_val2017.json:这个是经过处理后输出的json文件路径。新的json文件命名一定要是bbox_only_instances_val2017.json,因为在代码中定义了运行json文件的名字。 - -${data_path}:代表数据集coco2017的路径 - -需要准备好的数据集部分: - -``` -├── coco -│ ├── val2017 -│ ├── annotations -│ ├──instances_val2017.json -│ ├──bbox_only_instances_val2017.json -``` - -## 二. 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 - -执行代码脚本请在本工程代码文件夹下运行。 - -执行如下脚本生成om模型 - -1-25行是pth2onnx - -29-43行是onnx2om - -``` -bash test/ssd_pth2om.sh -``` - -执行如下脚本进行数据预处理和后处理测试精度 - -``` -bash test/ssd_eval_acc_perf.sh --data_path=/home/yzc -``` - ---data_path:coco2017数据集的路径 - -1-16行是加载数据集路径部分 - -19行是解决mlperf_logging包的调用问题 - -23-30行是处理json文件部分 - -32-40行是数据预处理部分 - -42-48行是生成info文件 - -50-67行是使用benchmark进行离线推理的部分 - -70-84行是数据后处理评估精度部分 - -请用户在运行代码前,必须要先激活环境变量才能运行代码: - -``` -source env.sh -``` - -如果在运行代码的过程中,出现缺少.so库的问题,则需要再运行一遍上面输入的命令,再激活一次环境变量,即可解决问题。 - -另外,如果在运行过程中出现报出没有torchvision的错误,但实际已安装,请用户使用which python或者which python版本,查看python的路径是否在当前环境的路径下,请使用在当前环境路径下的相应python即可。 - -### 1.导出.onnx文件 - -− 使用iter_183250.pt导出onnx文件。 - -− 运行ssd_pth2onnx.sh可直接从pth转至om模型 - -运行ssd_pth2onnx.py脚本。 - -生成batchsize=1的onnx模型: - -``` -python3.7 ssd_pth2onnx.py --bs=1 --resnet34-model=./models/resnet34-333f7ec4.pth --pth-path=./models/iter_183250.pt --onnx-path=./ssd_bs1.onnx -``` - -生成batchsize=16的onnx模型: - -``` -python ssd_pth2onnx.py --bs=16 --resnet34-model=./models/resnet34-333f7ec4.pth --pth-path=./models/iter_183250.pt --onnx-path=./ssd_bs16.onnx -``` - ---bs:输入的batch_size大小 - ---resnet34-model:resnet34模型的pth权重文件路径 - ---pth-path:输入SSD模型的pth权重文件路径 - ---onnx-path:输出的onnx模型文件路径及onnx模型名字 - -执行上述步骤后,获得的输出有: - -``` -├── ssd_bs1.onnx -├── ssd_bs16.onnx -``` - -### 2.转om模型 - -设置环境变量 - -``` -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest -``` - -生成batchsize为1的om模型的命令如下。 - -``` -atc --framework=5 --model=./ssd_bs1.onnx --output=./ssd_bs1 --input_format=NCHW --input_shape="image:1,3,300,300" --log=error --soc_version=Ascend310 -``` - -生成batchsize为16的om模型的命令如下。 - -``` -atc --framework=5 --model=./ssd_bs16.onnx --output=./ssd_bs16 --input_format=NCHW --input_shape="image:16,3,300,300" --log=error --soc_version=Ascend310 -``` - ---framework:5代表ONNX模型。 - ---model:为ONNX模型文件输入的路径。 - ---output:输出的OM模型的路径。 - ---input_format:输入数据的格式。 - ---input_shape:输入数据的shape。 - ---log:日志级别。 - ---soc_version:处理器型号。 - -执行上述步骤后,获得的输出为: - -``` -├── ssd_bs1.om -├── ssd_bs16.om -``` - -### 3.数据预处理。 - -将原始数据集转换为模型输入的二进制数据。 - -在进行数据预处理时,虽然coco2017的val2017验证集有5000张图片,但是实际上输出的只有4952张图片,因为在这过程中代码会剔除其中的48张图片。这一点请用户注意。 - -在数据预处理之前先要声明mlperf_logging包的调用问题: - -``` -PYTHONPATH=../../../../../SIAT/benchmarks/resnet/implementations/tensorflow_open_src:$PYTHONPATH -``` - -具体命令讲解: - -``` -python3.7 ssd_preprocess.py --data=${data_path}/coco --bin-output=./ssd_bin -``` - ---data:coco2017数据集的路径 - ---bin-output:经过预处理得到的bin文件路径 - -${data_path}:coco2017数据集的路径 - -执行上述步骤后,获得的输出为: - -``` -├── ssd_bin -│ ├── tensor([139]).bin -│ ├── ... -│ ├── tensor([581781]).bin -``` - -### 4.生成数据集info文件 - -使用benchmark推理需要输入二进制数据集的info文件,用于获取数据集。使用get_info.py脚本,输入已经得到的二进制文件,输出生成二进制数据集的info文件。 - -具体命令讲解: - -``` -python3.7 get_info.py bin ./ssd_bin ssd.info 300 300 -``` - -第一个参数为生成的数据集文件格式, - -第二个参数为预处理后的数据文件相对路径, - -第三个参数为生成的数据集文件名, - -第四个和第五个参数分别为模型输入的宽度和高度。 - -执行上述步骤后,获得的输出为: - -``` -├── ssd.info -``` - -### 5.使用Benchmark工具进行推理 - -Benchmark模型推理工具,其输入是om模型以及模型所需要的输入bin文件,其输出是模型根据相应输入产生的输出文件。 - -先后步骤顺序为: - -− 增加执行权限 - -``` -chmod u+x benchmark.x86_64 -``` - -− 由对batchsize=1的om模型进行benchmark推理: - -``` -./benchmark.x86_64 -model_type=vision -batch_size=1 -device_id=0 -input_text_path=./ssd.info -input_width=300 -input_height=300 -useDvpp=False -output_binary=true -om_path=./ssd_bs1.om -``` - -− 由对batchsize=16的om模型进行benchmark推理: - -``` -./benchmark.x86_64 -model_type=vision -batch_size=16 -device_id=1 -input_text_path=./ssd.info -input_width=300 -input_height=300 -useDvpp=False -output_binary=true -om_path=./ssd_bs16.om -``` - --model_type:为benchmark支持的模型类型,目前支持的有vision,nmt,widedeep,nlp,yolocaffe,bert,deepfm。ssd模型属于vision,所以选vision。 - --batch_size:om模型的batch大小,该值应与om模型的batch大小相同,否则报输入大小不一致的错误。 - --device_id:指运行在ascend 310的哪个device上,每张ascend 310卡有4个device。 - -input_text_path:包含数据集每个样本的路径与其相关信息的数据集信息文件路径。即之前生成的info文件路径。 - --input_width:输入宽度 - --input_height:输入高度 - --useDvpp:为是否使用aipp进行数据集预处理,我这里不用 - --output_binary:以预处理后的数据集为输入,benchmark工具推理om模型的输出数据保存为二进制还是txt。true为生成二进制bin文件,false为生成txt文件。 - --om_path:om模型文件路径。 - -执行./benchmark.x86_64工具请选择与运行环境架构相同的命令。参数详情请参见《 CANN 推理benchmark工具用户指南 》。 推理后的输出默认在当前目录result下。 - -batchsize=1的om模型进行benchmark推理得到的bin文件输出结果默认保存在当前目录result/dumpOutput_device0;性能数据默认保存在result/ perf_vision_batchsize_1_device_0.txt。 - -batchsize=16的om模型进行benchmark推理得到的bin文件输出结果默认保存在当前目录result/dumpOutput_device1;性能数据默认保存在result/ perf_vision_batchsize_16_device_1.txt。 - -该模型一个输入会对应两个输出,_1代表ploc的输出,_2代表plabel的输出。 - -执行以上命令后的输出: - -``` -├── result -│ ├── dumpOutput_device0 -│ │ ├── tensor([139])_1.bin -│ │ ├── tensor([139])_2.bin -│ │ ├── …… -│ ├── dumpOutput_device1 -│ │ ├── tensor([139])_1.bin -│ │ ├── tensor([139])_2.bin -│ │ ├── …… -│ ├── perf_vision_batchsize_1_device_0.txt -│ ├── perf_vision_batchsize_16_device_1.txt -``` - -### 6.数据后处理 - -进行数据后处理时,也是需要调用同数据预处理一样的mlperf_logging包。因为在前面进行数据预处理时已经声明过了,所以可以不需要再进行声明了。 - -调用ssd_postprocess.py评测模型的精度: - -batchsize=1的测试: - -``` -python ssd_postprocess.py --data=${data_path}/coco --bin-input=./result/dumpOutput_device0 -``` - -batchsize=16的测试: - -``` -python ssd_postprocess.py --data=${data_path}/coco --bin-input=./result/dumpOutput_device1 -``` - ---data:coco2017数据集的路径 - ---bin-input:数据预处理得到的bin文件。 - -${data_path}:coco2017数据集的路径 - -### 7.评测结果: - -| 模型 | 官网pth精度 | 310离线推理精度 | 性能基准 | 310性能 | -| ----------------- | ----------- | --------------- | ---------- | ---------- | -| SSD-Resnet34 bs1 | 23.000% | 23.030% | 482.627fps | 634.576fps | -| SSD-Resnet34 bs16 | 23.000% | 23.030% | 774.477fps | 863.748fps | - +# SSD-Resnet34模型PyTorch离线推理 + +## 一. 环境准备 + +### 1.通过requirements.txt 安装必要依赖 + +首先要先获取torch-1.5.0+ascend.post3.20210930-cp37-cp37m-linux_x86_64.whl,apex-0.1+ascend.20210930-cp37-cp37m-linux_x86_64.whl和tensor_fused_plugin-0.1+ascend-cp37-cp37m-linux_x86_64.whl这3个文件,获取方法如下: + +获取torch-1.5.0+ascend.post3.20210930-cp37-cp37m-linux_x86_64.whl + +x86架构: + +``` +wget https://ascend-pytorch-release.obs.cn-north-4.myhuaweicloud.com/run_pkg/20211018_FrameworkPTAdapter2.0.T308/torch-1.5.0%2Bascend.post3.20210930-cp37-cp37m-linux_x86_64.whl +``` + +ARM架构: + +``` +wget https://ascend-pytorch-release.obs.cn-north-4.myhuaweicloud.com/run_pkg/20211018_FrameworkPTAdapter2.0.T308/torch-1.5.0%2Bascend.post3.20210930-cp37-cp37m-linux_aarch64.whl +``` + +获取tensor_fused_plugin-0.1+ascend-cp37-cp37m-linux_x86_64.whl + +x86架构: + +``` +wget https://ascend-pytorch-release.obs.cn-north-4.myhuaweicloud.com/run_pkg/20210423_TR5/whl_0423/tensor_fused_plugin-0.1%2Bascend-cp37-cp37m-linux_x86_64.whl +``` + +ARM架构: + +``` +wget https://ascend-pytorch-release.obs.cn-north-4.myhuaweicloud.com/run_pkg/20211018_FrameworkPTAdapter2.0.T308/torch-1.5.0%2Bascend.post3.20210930-cp37-cp37m-linux_aarch64.whl +``` + +获取apex-0.1+ascend.20210930-cp37-cp37m-linux_x86_64.whl + +x86架构: + +``` +wget https://ascend-pytorch-release.obs.cn-north-4.myhuaweicloud.com/run_pkg/20211018_FrameworkPTAdapter2.0.T308/apex-0.1%2Bascend.20210930-cp37-cp37m-linux_x86_64.whl +``` + +ARM架构: + +``` +wget https://ascend-pytorch-release.obs.cn-north-4.myhuaweicloud.com/run_pkg/20211018_FrameworkPTAdapter2.0.T308/apex-0.1%2Bascend.20210930-cp37-cp37m-linux_aarch64.whl +``` + +在获得这3个.whl文件之后就使用命令直接运行: + +x86架构: + +``` +pip install torch-1.5.0+ascend.post3.20210930-cp37-cp37m-linux_x86_64.whl +pip install apex-0.1+ascend.20210930-cp37-cp37m-linux_x86_64.whl +pip install tensor_fused_plugin-0.1+ascend-cp37-cp37m-linux_x86_64.whl +``` + +ARM架构: + +``` +pip install torch-1.5.0+ascend.post3.20210930-cp37-cp37m-linux_aarch64.whl +pip install apex-0.1+ascend.20210930-cp37-cp37m-linux_aarch64.whl +pip install tensor_fused_plugin-0.1+ascend-cp37-cp37m-linux_aarch64.whl +``` + +在运行上面的这条命令时,确保torch,apex和tensor_fused_plugin这3个.whl文件和requirements.txt在同一个目录下。 + +之后运行如下指令: + +``` +pip install -r requirements.txt +``` + +在运行完这条命令后,如果error中出现te0.4.0和schedule-search0.0.1相关信息,不需要去看,因为运行这个代码不需要用到,与本代码无关。 + +``` +pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python +apt update +apt install libgl1-mesa-glx +``` + +之后再运行如上3条命令,本代码所需环境即安装完毕。 + +### 2. 获取开源模型代码及开源权重 + +加载开源仓库: + +``` +git clone https://github.com/mlcommons/training_results_v0.7.git +``` + +进入开源代码仓,并打补丁,打补丁时确保补丁在开源代码仓路径的上一级: + +``` +cd training_results_v0.7/NVIDIA/benchmarks/ssd/implementations/pytorch/ +patch -p1 <../ssd.patch +``` + +下载训练后的SSD权重文件: + +``` +wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/detection/SSD-Resnet34/iter_183250.pt +``` + +下载基于搭建SSD模型的Resnet34模型的权重文件 + +``` +wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/detection/SSD-Resnet34/resnet34-333f7ec4.pth +``` + +对于pth权重文件,统一放在新建models文件夹下。 + +``` +├── models +│ ├── iter_183250.pt +│ ├── resnet34-333f7ec4.pth +``` + +### 3. 获取测试数据集 + +本模型支持coco2017的val2017验证数据集,里面有5000张图片。用户可自行获取coco2017数据集中的annotations和val2017,上传数据集到服务器任意目录并解压(如:/home/HwHiAiUser/dataset),本模型将使用到coco2017数据集中的验证集及其标签文件instances_val2017.json, bbox_only_instances_val2017.json,标签文件bbox_only_instances_val2017.json是将coco2017中的原标签文件instances_val2017.json经过处理所得。 + +获得coco数据集的命令如下: + +``` +wget https://ascend-pytorch-one-datasets.obs.cn-north-4.myhuaweicloud.com/infer/zip/coco_2017_ssd_infer.zip +``` + +在本代码中我统一使用了coco这个名字来命名数据: + +``` +mv coco_2017_ssd_infer coco +``` + +获得新json标签文件的命令如下: + +先给prepare-json.py增加权限,不然会出现权限不够的问题: + +``` +chmod -R 777 prepare-json.py +``` + +等增加完权限后再运行: + +``` +python3.7 prepare-json.py --keep-keys ${data_path}/coco/annotations/instances_val2017.json ${data_path}/coco/annotations/bbox_only_instances_val2017.json +``` + +第1部分${data_path}/coco/annotations/instances_val2017.json:这个是输入的json文件路径 + +第2部分${data_path}/coco/annotations/bbox_only_instances_val2017.json:这个是经过处理后输出的json文件路径。新的json文件命名一定要是bbox_only_instances_val2017.json,因为在代码中定义了运行json文件的名字。 + +${data_path}:代表数据集coco2017的路径 + +需要准备好的数据集部分: + +``` +├── coco +│ ├── val2017 +│ ├── annotations +│ ├──instances_val2017.json +│ ├──bbox_only_instances_val2017.json +``` + +## 二. 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 + +执行代码脚本请在本工程代码文件夹下运行。 + +执行如下脚本生成om模型 + +1-25行是pth2onnx + +29-43行是onnx2om + +``` +bash test/ssd_pth2om.sh +``` + +执行如下脚本进行数据预处理和后处理测试精度 + +``` +bash test/ssd_eval_acc_perf.sh --data_path=/home/yzc +``` + +--data_path:coco2017数据集的路径 + +1-16行是加载数据集路径部分 + +19行是解决mlperf_logging包的调用问题 + +23-30行是处理json文件部分 + +32-40行是数据预处理部分 + +42-48行是生成info文件 + +50-67行是使用benchmark进行离线推理的部分 + +70-84行是数据后处理评估精度部分 + +请用户在运行代码前,必须要先激活环境变量才能运行代码: + +``` +source env.sh +``` + +如果在运行代码的过程中,出现缺少.so库的问题,则需要再运行一遍上面输入的命令,再激活一次环境变量,即可解决问题。 + +另外,如果在运行过程中出现报出没有torchvision的错误,但实际已安装,请用户使用which python或者which python版本,查看python的路径是否在当前环境的路径下,请使用在当前环境路径下的相应python即可。 + +### 1.导出.onnx文件 + +− 使用iter_183250.pt导出onnx文件。 + +− 运行ssd_pth2onnx.sh可直接从pth转至om模型 + +运行ssd_pth2onnx.py脚本。 + +生成batchsize=1的onnx模型: + +``` +python3.7 ssd_pth2onnx.py --bs=1 --resnet34-model=./models/resnet34-333f7ec4.pth --pth-path=./models/iter_183250.pt --onnx-path=./ssd_bs1.onnx +``` + +生成batchsize=16的onnx模型: + +``` +python ssd_pth2onnx.py --bs=16 --resnet34-model=./models/resnet34-333f7ec4.pth --pth-path=./models/iter_183250.pt --onnx-path=./ssd_bs16.onnx +``` + +--bs:输入的batch_size大小 + +--resnet34-model:resnet34模型的pth权重文件路径 + +--pth-path:输入SSD模型的pth权重文件路径 + +--onnx-path:输出的onnx模型文件路径及onnx模型名字 + +执行上述步骤后,获得的输出有: + +``` +├── ssd_bs1.onnx +├── ssd_bs16.onnx +``` + +### 2.转om模型 + +设置环境变量 + +``` +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest +``` + +生成batchsize为1的om模型的命令如下。 + +``` +atc --framework=5 --model=./ssd_bs1.onnx --output=./ssd_bs1 --input_format=NCHW --input_shape="image:1,3,300,300" --log=error --soc_version=Ascend310 +``` + +生成batchsize为16的om模型的命令如下。 + +``` +atc --framework=5 --model=./ssd_bs16.onnx --output=./ssd_bs16 --input_format=NCHW --input_shape="image:16,3,300,300" --log=error --soc_version=Ascend310 +``` + +--framework:5代表ONNX模型。 + +--model:为ONNX模型文件输入的路径。 + +--output:输出的OM模型的路径。 + +--input_format:输入数据的格式。 + +--input_shape:输入数据的shape。 + +--log:日志级别。 + +--soc_version:处理器型号。 + +执行上述步骤后,获得的输出为: + +``` +├── ssd_bs1.om +├── ssd_bs16.om +``` + +### 3.数据预处理。 + +将原始数据集转换为模型输入的二进制数据。 + +在进行数据预处理时,虽然coco2017的val2017验证集有5000张图片,但是实际上输出的只有4952张图片,因为在这过程中代码会剔除其中的48张图片。这一点请用户注意。 + +在数据预处理之前先要声明mlperf_logging包的调用问题: + +``` +PYTHONPATH=../../../../../SIAT/benchmarks/resnet/implementations/tensorflow_open_src:$PYTHONPATH +``` + +具体命令讲解: + +``` +python3.7 ssd_preprocess.py --data=${data_path}/coco --bin-output=./ssd_bin +``` + +--data:coco2017数据集的路径 + +--bin-output:经过预处理得到的bin文件路径 + +${data_path}:coco2017数据集的路径 + +执行上述步骤后,获得的输出为: + +``` +├── ssd_bin +│ ├── tensor([139]).bin +│ ├── ... +│ ├── tensor([581781]).bin +``` + +### 4.生成数据集info文件 + +使用benchmark推理需要输入二进制数据集的info文件,用于获取数据集。使用get_info.py脚本,输入已经得到的二进制文件,输出生成二进制数据集的info文件。 + +具体命令讲解: + +``` +python3.7 get_info.py bin ./ssd_bin ssd.info 300 300 +``` + +第一个参数为生成的数据集文件格式, + +第二个参数为预处理后的数据文件相对路径, + +第三个参数为生成的数据集文件名, + +第四个和第五个参数分别为模型输入的宽度和高度。 + +执行上述步骤后,获得的输出为: + +``` +├── ssd.info +``` + +### 5.使用Benchmark工具进行推理 + +Benchmark模型推理工具,其输入是om模型以及模型所需要的输入bin文件,其输出是模型根据相应输入产生的输出文件。 + +先后步骤顺序为: + +− 增加执行权限 + +``` +chmod u+x benchmark.x86_64 +``` + +− 由对batchsize=1的om模型进行benchmark推理: + +``` +./benchmark.x86_64 -model_type=vision -batch_size=1 -device_id=0 -input_text_path=./ssd.info -input_width=300 -input_height=300 -useDvpp=False -output_binary=true -om_path=./ssd_bs1.om +``` + +− 由对batchsize=16的om模型进行benchmark推理: + +``` +./benchmark.x86_64 -model_type=vision -batch_size=16 -device_id=1 -input_text_path=./ssd.info -input_width=300 -input_height=300 -useDvpp=False -output_binary=true -om_path=./ssd_bs16.om +``` + +-model_type:为benchmark支持的模型类型,目前支持的有vision,nmt,widedeep,nlp,yolocaffe,bert,deepfm。ssd模型属于vision,所以选vision。 + +-batch_size:om模型的batch大小,该值应与om模型的batch大小相同,否则报输入大小不一致的错误。 + +-device_id:指运行在ascend 310的哪个device上,每张ascend 310卡有4个device。 + +input_text_path:包含数据集每个样本的路径与其相关信息的数据集信息文件路径。即之前生成的info文件路径。 + +-input_width:输入宽度 + +-input_height:输入高度 + +-useDvpp:为是否使用aipp进行数据集预处理,我这里不用 + +-output_binary:以预处理后的数据集为输入,benchmark工具推理om模型的输出数据保存为二进制还是txt。true为生成二进制bin文件,false为生成txt文件。 + +-om_path:om模型文件路径。 + +执行./benchmark.x86_64工具请选择与运行环境架构相同的命令。参数详情请参见《 CANN 推理benchmark工具用户指南 》。 推理后的输出默认在当前目录result下。 + +batchsize=1的om模型进行benchmark推理得到的bin文件输出结果默认保存在当前目录result/dumpOutput_device0;性能数据默认保存在result/ perf_vision_batchsize_1_device_0.txt。 + +batchsize=16的om模型进行benchmark推理得到的bin文件输出结果默认保存在当前目录result/dumpOutput_device1;性能数据默认保存在result/ perf_vision_batchsize_16_device_1.txt。 + +该模型一个输入会对应两个输出,_1代表ploc的输出,_2代表plabel的输出。 + +执行以上命令后的输出: + +``` +├── result +│ ├── dumpOutput_device0 +│ │ ├── tensor([139])_1.bin +│ │ ├── tensor([139])_2.bin +│ │ ├── …… +│ ├── dumpOutput_device1 +│ │ ├── tensor([139])_1.bin +│ │ ├── tensor([139])_2.bin +│ │ ├── …… +│ ├── perf_vision_batchsize_1_device_0.txt +│ ├── perf_vision_batchsize_16_device_1.txt +``` + +### 6.数据后处理 + +进行数据后处理时,也是需要调用同数据预处理一样的mlperf_logging包。因为在前面进行数据预处理时已经声明过了,所以可以不需要再进行声明了。 + +调用ssd_postprocess.py评测模型的精度: + +batchsize=1的测试: + +``` +python ssd_postprocess.py --data=${data_path}/coco --bin-input=./result/dumpOutput_device0 +``` + +batchsize=16的测试: + +``` +python ssd_postprocess.py --data=${data_path}/coco --bin-input=./result/dumpOutput_device1 +``` + +--data:coco2017数据集的路径 + +--bin-input:数据预处理得到的bin文件。 + +${data_path}:coco2017数据集的路径 + +### 7.评测结果: + +| 模型 | 官网pth精度 | 310离线推理精度 | 性能基准 | 310性能 | +| ----------------- | ----------- | --------------- | ---------- | ---------- | +| SSD-Resnet34 bs1 | 23.000% | 23.030% | 482.627fps | 634.576fps | +| SSD-Resnet34 bs16 | 23.000% | 23.030% | 774.477fps | 863.748fps | + diff --git a/ACL_PyTorch/contrib/cv/detection/SSD-Resnet34/ssd_pth2onnx.py b/ACL_PyTorch/contrib/cv/detection/SSD-Resnet34/ssd_pth2onnx.py index 7687bb7b0a3d062f7e27f361d90d6cfce810fa8d..9a88aff930e05f87714467c2dcfdc4b928690a94 100644 --- a/ACL_PyTorch/contrib/cv/detection/SSD-Resnet34/ssd_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/SSD-Resnet34/ssd_pth2onnx.py @@ -1,46 +1,46 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import torch -import os -from ssd300 import SSD300 -import random -from argparse import ArgumentParser -from parse_config import parse_args - -def pth2onnx(batch_size,input_file, output_file): - model_options = { - 'use_nhwc' : False, - 'pad_input' : False, - 'bn_group' : 1, - } - ssd300_eval = SSD300(args, 81, **model_options) - - state_dict = torch.load(input_file, map_location="cpu") - ssd300_eval.load_state_dict(state_dict['model']) - - ssd300_eval.eval() - input_names = ["image"] - output_names=["ploc","plabel"] - dynamic_axes = {'image': {0: '-1'}, 'ploc': {0: '-1'}, 'plabel': {0: '-1'}} - dummy_input = torch.randn(batch_size, 3, 300, 300) - torch.onnx.export(ssd300_eval, dummy_input, output_file, input_names=input_names, dynamic_axes=dynamic_axes, - output_names=output_names, opset_version=11, verbose=False) - -if __name__ == "__main__": - args = parse_args() - batch_size=args.bs - input_file = args.pth_path - output_file = args.onnx_path - resnet_model=args.resnet34_model - pth2onnx(batch_size,input_file, output_file) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import torch +import os +from ssd300 import SSD300 +import random +from argparse import ArgumentParser +from parse_config import parse_args + +def pth2onnx(batch_size,input_file, output_file): + model_options = { + 'use_nhwc' : False, + 'pad_input' : False, + 'bn_group' : 1, + } + ssd300_eval = SSD300(args, 81, **model_options) + + state_dict = torch.load(input_file, map_location="cpu") + ssd300_eval.load_state_dict(state_dict['model']) + + ssd300_eval.eval() + input_names = ["image"] + output_names=["ploc","plabel"] + dynamic_axes = {'image': {0: '-1'}, 'ploc': {0: '-1'}, 'plabel': {0: '-1'}} + dummy_input = torch.randn(batch_size, 3, 300, 300) + torch.onnx.export(ssd300_eval, dummy_input, output_file, input_names=input_names, dynamic_axes=dynamic_axes, + output_names=output_names, opset_version=11, verbose=False) + +if __name__ == "__main__": + args = parse_args() + batch_size=args.bs + input_file = args.pth_path + output_file = args.onnx_path + resnet_model=args.resnet34_model + pth2onnx(batch_size,input_file, output_file) diff --git a/ACL_PyTorch/contrib/cv/detection/YOLOF/LICENSE b/ACL_PyTorch/contrib/cv/detection/YOLOF/LICENSE index 0561f7dca719dc2718f1fdc146feda1dea36a9ef..cc87e8683f8accf92fb441738e981d6ab8ce7536 100644 --- a/ACL_PyTorch/contrib/cv/detection/YOLOF/LICENSE +++ b/ACL_PyTorch/contrib/cv/detection/YOLOF/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2021 Megvii, Base Detection - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2021 Megvii, Base Detection + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ACL_PyTorch/contrib/cv/detection/YOLOF/YOLOF_postprocess.py b/ACL_PyTorch/contrib/cv/detection/YOLOF/YOLOF_postprocess.py index 1260f6dabfef837c403ba50e01a5de4c76dc5b37..167582d4171acb9905af9e92cd94606d33508d8f 100644 --- a/ACL_PyTorch/contrib/cv/detection/YOLOF/YOLOF_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/YOLOF/YOLOF_postprocess.py @@ -1,90 +1,90 @@ -# Copyright 2022 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import numpy as np -import argparse - -import torch -from cvpods.structures import Boxes, Instances -from cvpods.modeling.postprocessing import detector_postprocess -from cvpods.engine import RUNNERS -from cvpods.evaluation import build_evaluator - -import sys -import os - -sys.path.append("{0}/YOLOF/playground/detection/coco/yolof/yolof.cspdarknet53.DC5.9x/".format(sys.path[0])) -from config import config - -const_shape = (608, 608) -dataset_name = "coco_2017_val" - - -def runner_decrator(cls): - def custom_build_evaluator(cls, cfg, dataset_name, dataset): - return build_evaluator(cfg, dataset_name, dataset, None, dump=True) - - cls.build_evaluator = classmethod(custom_build_evaluator) - return cls - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--pth_path', default="YOLOF_CSP_D_53_DC5_9x.pth") - parser.add_argument('--bin_data_path', default="result/") - parser.add_argument('--meta_info_path', default="yolof_meta.info") - parser.add_argument('--num_classes', default=81, type=int) - - args = parser.parse_args() - - opts = ['MODEL.WEIGHTS', args.pth_path, "MODEL.DEVICE", "cpu"] - config.merge_from_list(opts) - - cls = runner_decrator(RUNNERS.get(config.TRAINER.NAME)) - evaluator = cls.build_evaluator(config, dataset_name, cls.build_test_loader(config).dataset) - evaluator.reset() - bin_data_path = args.bin_data_path + os.listdir(args.bin_data_path)[0] + "/" - - with open(args.meta_info_path, "r") as fp: - for line in fp: - values = line.split() - file_name = values[0] - batch_size = (len(values) - 1) // 3 - nmsed_boxes_batch = np.fromfile("{0}{1}_output_{2}.bin".format(bin_data_path, file_name, 0), - dtype=np.float32).reshape(batch_size, -1, 4) - nmsed_scores_batch = np.fromfile("{0}{1}_output_{2}.bin".format(bin_data_path, file_name, 1), - dtype=np.float32).reshape(batch_size, -1) - nmsed_classes_batch = np.fromfile("{0}{1}_output_{2}.bin".format(bin_data_path, file_name, 2), - dtype=np.int64).reshape(batch_size, -1) - last_image = "" - for i in range(batch_size): - img_name = values[i * 3 + 1] - if img_name == last_image: - break - last_image = img_name - last_img_name = img_name - height = int(values[i * 3 + 2]) - width = int(values[i * 3 + 3]) - nmsed_boxes = nmsed_boxes_batch[i] - nmsed_scores = nmsed_scores_batch[i] - nmsed_classes = nmsed_classes_batch[i] - result = Instances(const_shape) - result.pred_boxes = Boxes(torch.tensor(nmsed_boxes)) - result.scores = torch.tensor(nmsed_scores) - result.pred_classes = torch.tensor(nmsed_classes) - r = detector_postprocess(result, height, width) - r = {"instances": r} - _input = {"image_id": int(img_name)} - evaluator.process([_input], [r]) - print(evaluator.evaluate()) - print(evaluator._dump_infos[0]['summary']) +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import numpy as np +import argparse + +import torch +from cvpods.structures import Boxes, Instances +from cvpods.modeling.postprocessing import detector_postprocess +from cvpods.engine import RUNNERS +from cvpods.evaluation import build_evaluator + +import sys +import os + +sys.path.append("{0}/YOLOF/playground/detection/coco/yolof/yolof.cspdarknet53.DC5.9x/".format(sys.path[0])) +from config import config + +const_shape = (608, 608) +dataset_name = "coco_2017_val" + + +def runner_decrator(cls): + def custom_build_evaluator(cls, cfg, dataset_name, dataset): + return build_evaluator(cfg, dataset_name, dataset, None, dump=True) + + cls.build_evaluator = classmethod(custom_build_evaluator) + return cls + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--pth_path', default="YOLOF_CSP_D_53_DC5_9x.pth") + parser.add_argument('--bin_data_path', default="result/") + parser.add_argument('--meta_info_path', default="yolof_meta.info") + parser.add_argument('--num_classes', default=81, type=int) + + args = parser.parse_args() + + opts = ['MODEL.WEIGHTS', args.pth_path, "MODEL.DEVICE", "cpu"] + config.merge_from_list(opts) + + cls = runner_decrator(RUNNERS.get(config.TRAINER.NAME)) + evaluator = cls.build_evaluator(config, dataset_name, cls.build_test_loader(config).dataset) + evaluator.reset() + bin_data_path = args.bin_data_path + os.listdir(args.bin_data_path)[0] + "/" + + with open(args.meta_info_path, "r") as fp: + for line in fp: + values = line.split() + file_name = values[0] + batch_size = (len(values) - 1) // 3 + nmsed_boxes_batch = np.fromfile("{0}{1}_output_{2}.bin".format(bin_data_path, file_name, 0), + dtype=np.float32).reshape(batch_size, -1, 4) + nmsed_scores_batch = np.fromfile("{0}{1}_output_{2}.bin".format(bin_data_path, file_name, 1), + dtype=np.float32).reshape(batch_size, -1) + nmsed_classes_batch = np.fromfile("{0}{1}_output_{2}.bin".format(bin_data_path, file_name, 2), + dtype=np.int64).reshape(batch_size, -1) + last_image = "" + for i in range(batch_size): + img_name = values[i * 3 + 1] + if img_name == last_image: + break + last_image = img_name + last_img_name = img_name + height = int(values[i * 3 + 2]) + width = int(values[i * 3 + 3]) + nmsed_boxes = nmsed_boxes_batch[i] + nmsed_scores = nmsed_scores_batch[i] + nmsed_classes = nmsed_classes_batch[i] + result = Instances(const_shape) + result.pred_boxes = Boxes(torch.tensor(nmsed_boxes)) + result.scores = torch.tensor(nmsed_scores) + result.pred_classes = torch.tensor(nmsed_classes) + r = detector_postprocess(result, height, width) + r = {"instances": r} + _input = {"image_id": int(img_name)} + evaluator.process([_input], [r]) + print(evaluator.evaluate()) + print(evaluator._dump_infos[0]['summary']) diff --git a/ACL_PyTorch/contrib/cv/detection/YOLOF/YOLOF_preprocess.py b/ACL_PyTorch/contrib/cv/detection/YOLOF/YOLOF_preprocess.py index 60344d400bb7528bfa8bd5ce0f80a8e8c18c1b73..4c30bf4dceafe9201147f007701434da84a7389b 100644 --- a/ACL_PyTorch/contrib/cv/detection/YOLOF/YOLOF_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/YOLOF/YOLOF_preprocess.py @@ -1,83 +1,83 @@ -# Copyright 2022 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import argparse -import numpy as np -from PIL import Image -import pickle as pk -import multiprocessing - -flags = None -width = 608 -height = 608 -pixel_mean = np.array([103.5300, 116.2800, 123.6750], dtype=np.float32) - - -def gen_input_bin(file_batches, batch): - i = 0 - image_bag = [] - image_meta_bag = [] - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - src = Image.open(os.path.join(flags.image_src_path, file)).convert("RGB") - ori_shape = (src.size[1], src.size[0]) - image = src.resize((height, width), 2) - image = np.asarray(image) - image = image[..., ::-1] - image = image - pixel_mean - image = image.transpose(2, 0, 1) - image_meta = {'ori_shape': ori_shape, 'file_name': file.split('.')[0]} - image_bag.append(image) - image_meta_bag.append(image_meta) - if len(image_bag) % flags.batch_size == 0: - np.array(image_bag).tofile(os.path.join(flags.bin_file_path, "{}_{}.bin".format(batch, i))) - with open(os.path.join(flags.meta_file_path, "{}_{}.pk".format(batch, i)), "wb") as fp: - pk.dump(image_meta_bag, fp) - image_bag = [] - image_meta_bag = [] - if image_bag: - ext_img_bag = [image_bag[-1] for i in range(flags.batch_size-len(image_bag))] - image_bag += ext_img_bag - ext_img_meta_bag = [image_meta_bag[-1] for i in range(flags.batch_size - len(image_meta_bag))] - image_meta_bag += ext_img_meta_bag - np.array(image_bag).tofile(os.path.join(flags.bin_file_path, "{}_{}.bin".format(batch, i))) - with open(os.path.join(flags.meta_file_path, "{}_{}.pk".format(batch, i)), "wb") as fp: - pk.dump(image_meta_bag, fp) - - -def preprocess(): - step = 100 - (100 % flags.batch_size) - files = os.listdir(flags.image_src_path) - file_batches = [files[i:i + step] for i in range(0, 5000, step) if files[i:i + step] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(file_batches, batch)) - thread_pool.close() - thread_pool.join() - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='preprocess of YOLOF PyTorch model') - parser.add_argument("--image_src_path", default="YOLOF/datasets/coco/val2017", help='image of dataset') - parser.add_argument("--bin_file_path", default="val2017_bin") - parser.add_argument("--meta_file_path", default="val2017_bin_meta") - parser.add_argument("--batch_size", default=1, type=int) - flags = parser.parse_args() - if not os.path.exists(flags.bin_file_path): - os.makedirs(flags.bin_file_path) - if not os.path.exists(flags.meta_file_path): - os.makedirs(flags.meta_file_path) - preprocess() +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import argparse +import numpy as np +from PIL import Image +import pickle as pk +import multiprocessing + +flags = None +width = 608 +height = 608 +pixel_mean = np.array([103.5300, 116.2800, 123.6750], dtype=np.float32) + + +def gen_input_bin(file_batches, batch): + i = 0 + image_bag = [] + image_meta_bag = [] + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + src = Image.open(os.path.join(flags.image_src_path, file)).convert("RGB") + ori_shape = (src.size[1], src.size[0]) + image = src.resize((height, width), 2) + image = np.asarray(image) + image = image[..., ::-1] + image = image - pixel_mean + image = image.transpose(2, 0, 1) + image_meta = {'ori_shape': ori_shape, 'file_name': file.split('.')[0]} + image_bag.append(image) + image_meta_bag.append(image_meta) + if len(image_bag) % flags.batch_size == 0: + np.array(image_bag).tofile(os.path.join(flags.bin_file_path, "{}_{}.bin".format(batch, i))) + with open(os.path.join(flags.meta_file_path, "{}_{}.pk".format(batch, i)), "wb") as fp: + pk.dump(image_meta_bag, fp) + image_bag = [] + image_meta_bag = [] + if image_bag: + ext_img_bag = [image_bag[-1] for i in range(flags.batch_size-len(image_bag))] + image_bag += ext_img_bag + ext_img_meta_bag = [image_meta_bag[-1] for i in range(flags.batch_size - len(image_meta_bag))] + image_meta_bag += ext_img_meta_bag + np.array(image_bag).tofile(os.path.join(flags.bin_file_path, "{}_{}.bin".format(batch, i))) + with open(os.path.join(flags.meta_file_path, "{}_{}.pk".format(batch, i)), "wb") as fp: + pk.dump(image_meta_bag, fp) + + +def preprocess(): + step = 100 - (100 % flags.batch_size) + files = os.listdir(flags.image_src_path) + file_batches = [files[i:i + step] for i in range(0, 5000, step) if files[i:i + step] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(file_batches, batch)) + thread_pool.close() + thread_pool.join() + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='preprocess of YOLOF PyTorch model') + parser.add_argument("--image_src_path", default="YOLOF/datasets/coco/val2017", help='image of dataset') + parser.add_argument("--bin_file_path", default="val2017_bin") + parser.add_argument("--meta_file_path", default="val2017_bin_meta") + parser.add_argument("--batch_size", default=1, type=int) + flags = parser.parse_args() + if not os.path.exists(flags.bin_file_path): + os.makedirs(flags.bin_file_path) + if not os.path.exists(flags.meta_file_path): + os.makedirs(flags.meta_file_path) + preprocess() diff --git a/ACL_PyTorch/contrib/cv/detection/YOLOF/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/detection/YOLOF/gen_dataset_info.py index de69f1132e110c24ada316149f2aa83f60f468be..970b1fd24071fa33561fe5d917ce91e4ba8511c8 100644 --- a/ACL_PyTorch/contrib/cv/detection/YOLOF/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/detection/YOLOF/gen_dataset_info.py @@ -1,36 +1,36 @@ -# Copyright 2022 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import argparse -import pickle as pk - -const_img_shape = (608, 608) - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='generate dataset info file') - parser.add_argument("--meta_file_path", default="val2017_bin_meta") - parser.add_argument("--meta_info_file_name", default="yolof_meta.info") - args = parser.parse_args() - - with open(args.meta_info_file_name, "w") as fp1: - file_list = os.listdir(args.meta_file_path) - for file in file_list: - with open("{}/{}".format(args.meta_file_path, file), "rb") as fp2: - meta = pk.load(fp2) - fp1.write(file.split(".")[0]) - for dic in meta: - fp1.write(" {} {} {}".format(dic['file_name'], *dic['ori_shape'])) - fp1.write("\n") - print("Get info done!") +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import argparse +import pickle as pk + +const_img_shape = (608, 608) + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='generate dataset info file') + parser.add_argument("--meta_file_path", default="val2017_bin_meta") + parser.add_argument("--meta_info_file_name", default="yolof_meta.info") + args = parser.parse_args() + + with open(args.meta_info_file_name, "w") as fp1: + file_list = os.listdir(args.meta_file_path) + for file in file_list: + with open("{}/{}".format(args.meta_file_path, file), "rb") as fp2: + meta = pk.load(fp2) + fp1.write(file.split(".")[0]) + for dic in meta: + fp1.write(" {} {} {}".format(dic['file_name'], *dic['ori_shape'])) + fp1.write("\n") + print("Get info done!") diff --git a/ACL_PyTorch/contrib/cv/detection/YOLOF/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/detection/YOLOF/modelzoo_level.txt index 7a41dd3e9f164a0414e50ad52a502c6d21b9b8ff..3901da7fbaa158ca7d805621545eabdadc18999f 100644 --- a/ACL_PyTorch/contrib/cv/detection/YOLOF/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/detection/YOLOF/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -ModelConvert:OK -PerfStatus=OK +FuncStatus:OK +PrecisionStatus:OK +ModelConvert:OK +PerfStatus=OK diff --git a/ACL_PyTorch/contrib/cv/detection/YOLOF/pytorch2onnx.py b/ACL_PyTorch/contrib/cv/detection/YOLOF/pytorch2onnx.py index 4f111b8adf40ddc26875d3101cc6edceb097d981..742e8cb370779406d5b347e2fc321e125f68c1f3 100644 --- a/ACL_PyTorch/contrib/cv/detection/YOLOF/pytorch2onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/YOLOF/pytorch2onnx.py @@ -1,78 +1,78 @@ -# Copyright 2022 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import argparse -import numpy as np -from cvpods.engine import default_setup -from cvpods.checkpoint import DefaultCheckpointer - -import sys - -sys.path.append("{0}/YOLOF/playground/detection/coco/yolof/yolof.cspdarknet53.DC5.9x/".format(sys.path[0])) -sys.path.append("{0}/YOLOF/playground/detection/coco/yolof/".format(sys.path[0])) -from net import build_model -from config import config - -device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") - - -def convert_batchnorm(module, process_group=None): - module_output = module - if isinstance(module, torch.nn.SyncBatchNorm): - module_output = torch.nn.BatchNorm2d(num_features=module.num_features, - eps=module.eps, - momentum=module.momentum, - affine=module.affine, - track_running_stats=module.track_running_stats) - if module.affine: - with torch.no_grad(): - module_output.weight = module.weight - module_output.bias = module.bias - module_output.running_mean = module.running_mean - module_output.running_var = module.running_var - module_output.num_batches_tracked = module.num_batches_tracked - for name, child in module.named_children(): - module_output.add_module(name, convert_batchnorm(child, process_group)) - del module - return module_output - - -def pth2onnx(args, fake_input, opts): - config.merge_from_list(opts) - model = build_model(config) - model._batch_size = args.batch_size - model.forward = model.forward_onnx - model = convert_batchnorm(model) - model.eval() - DefaultCheckpointer(model, save_dir=config.OUTPUT_DIR).resume_or_load( - config.MODEL.WEIGHTS, resume=False - ) - torch.onnx.export(model, fake_input, args.out, verbose=True, opset_version=11, - input_names=['input'], enable_onnx_checker=False) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--model_config', help='model config path', - default="YOLOF/playground/detection/coco/yolof/yolof.cspdarknet53.DC5.9x") - parser.add_argument('--out', help='onnx output name', default="yolof.onnx") - parser.add_argument('--pth_path', help='model pth path', default="./YOLOF_CSP_D_53_DC5_9x.pth") - parser.add_argument('--batch_size', type=int, default=1) - args = parser.parse_args() - - img_shape = (args.batch_size, 3, 608, 608) - fake_input = torch.randn(*img_shape) - opts = ['MODEL.WEIGHTS', args.pth_path, "MODEL.DEVICE", "cpu"] - pth2onnx(args, fake_input, opts) +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import argparse +import numpy as np +from cvpods.engine import default_setup +from cvpods.checkpoint import DefaultCheckpointer + +import sys + +sys.path.append("{0}/YOLOF/playground/detection/coco/yolof/yolof.cspdarknet53.DC5.9x/".format(sys.path[0])) +sys.path.append("{0}/YOLOF/playground/detection/coco/yolof/".format(sys.path[0])) +from net import build_model +from config import config + +device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") + + +def convert_batchnorm(module, process_group=None): + module_output = module + if isinstance(module, torch.nn.SyncBatchNorm): + module_output = torch.nn.BatchNorm2d(num_features=module.num_features, + eps=module.eps, + momentum=module.momentum, + affine=module.affine, + track_running_stats=module.track_running_stats) + if module.affine: + with torch.no_grad(): + module_output.weight = module.weight + module_output.bias = module.bias + module_output.running_mean = module.running_mean + module_output.running_var = module.running_var + module_output.num_batches_tracked = module.num_batches_tracked + for name, child in module.named_children(): + module_output.add_module(name, convert_batchnorm(child, process_group)) + del module + return module_output + + +def pth2onnx(args, fake_input, opts): + config.merge_from_list(opts) + model = build_model(config) + model._batch_size = args.batch_size + model.forward = model.forward_onnx + model = convert_batchnorm(model) + model.eval() + DefaultCheckpointer(model, save_dir=config.OUTPUT_DIR).resume_or_load( + config.MODEL.WEIGHTS, resume=False + ) + torch.onnx.export(model, fake_input, args.out, verbose=True, opset_version=11, + input_names=['input'], enable_onnx_checker=False) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--model_config', help='model config path', + default="YOLOF/playground/detection/coco/yolof/yolof.cspdarknet53.DC5.9x") + parser.add_argument('--out', help='onnx output name', default="yolof.onnx") + parser.add_argument('--pth_path', help='model pth path', default="./YOLOF_CSP_D_53_DC5_9x.pth") + parser.add_argument('--batch_size', type=int, default=1) + args = parser.parse_args() + + img_shape = (args.batch_size, 3, 608, 608) + fake_input = torch.randn(*img_shape) + opts = ['MODEL.WEIGHTS', args.pth_path, "MODEL.DEVICE", "cpu"] + pth2onnx(args, fake_input, opts) diff --git a/ACL_PyTorch/contrib/cv/detection/YOLOF/readme.md b/ACL_PyTorch/contrib/cv/detection/YOLOF/readme.md index 960872cef8254c43ebfd5b2a2906fa56c68c4d4f..1af4d238f4c179a442fb1eed55ec8eab38c4aa27 100644 --- a/ACL_PyTorch/contrib/cv/detection/YOLOF/readme.md +++ b/ACL_PyTorch/contrib/cv/detection/YOLOF/readme.md @@ -1,47 +1,47 @@ -### YOLOF模型PyTorch离线推理指导 - -### 1. 环境准备 - -1. 安装依赖 - -```bash -pip install -r requirements.txt -``` - -2. 获取,修改与安装开源模型代码 - -``` -git clone -b main https://github.com/megvii-model/YOLOF.git -cd YOLOF -git reset 6189487b80601dfeda89302c22abac060f977785 --hard - -patch -p1 < ../YOLOF.patch -python3 setup.py develop -cd .. -``` - -3. 将权重文件YOLOF_CSP_D_53_DC5_9x.pth放到当前工作目录 - -4. 数据集 - - 获取COCO数据集,并重命名为coco,放到当前目录下的 YOLOF/datasets/ 文件夹内 - -5. [获取msame工具](https://gitee.com/ascend/tools/tree/master/msame) - - 将msame文件放到当前工作目录 - -### 2. 离线推理 - -710上执行,执行时使npu-smi info查看设备状态,确保device空闲 - -```bash -bash test/pth2om.sh --batch_size=1 -bash test/eval_acc_perf.sh --batch_size=1 -``` - -**评测结果:** - -| 模型 | pth精度 | 710离线推理精度 | 710性能 | -| ---------- | ----------- | --------------- | ---------- | -| YOLOF bs1 | box AP:50.9 | box AP:51.0 | fps 27.697 | +### YOLOF模型PyTorch离线推理指导 + +### 1. 环境准备 + +1. 安装依赖 + +```bash +pip install -r requirements.txt +``` + +2. 获取,修改与安装开源模型代码 + +``` +git clone -b main https://github.com/megvii-model/YOLOF.git +cd YOLOF +git reset 6189487b80601dfeda89302c22abac060f977785 --hard + +patch -p1 < ../YOLOF.patch +python3 setup.py develop +cd .. +``` + +3. 将权重文件YOLOF_CSP_D_53_DC5_9x.pth放到当前工作目录 + +4. 数据集 + + 获取COCO数据集,并重命名为coco,放到当前目录下的 YOLOF/datasets/ 文件夹内 + +5. [获取msame工具](https://gitee.com/ascend/tools/tree/master/msame) + + 将msame文件放到当前工作目录 + +### 2. 离线推理 + +710上执行,执行时使npu-smi info查看设备状态,确保device空闲 + +```bash +bash test/pth2om.sh --batch_size=1 +bash test/eval_acc_perf.sh --batch_size=1 +``` + +**评测结果:** + +| 模型 | pth精度 | 710离线推理精度 | 710性能 | +| ---------- | ----------- | --------------- | ---------- | +| YOLOF bs1 | box AP:50.9 | box AP:51.0 | fps 27.697 | | YOLOF bs16 | box AP:50.9 | box AP:51.0 | fps 38.069 | \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/YOLOF/test/parse.py b/ACL_PyTorch/contrib/cv/detection/YOLOF/test/parse.py index 3fbf812ce48df315f7d4d9982c731333577c2a8a..4e51797a87ad12ff1d7dc6c400e6a3d5dee540eb 100644 --- a/ACL_PyTorch/contrib/cv/detection/YOLOF/test/parse.py +++ b/ACL_PyTorch/contrib/cv/detection/YOLOF/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2022 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7]) - print('710 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7]) + print('710 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) diff --git a/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/YOLOX_postprocess.py b/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/YOLOX_postprocess.py index 29003ed851832ef6eb707b4258022e994daef334..a1a777ec04a400358b59bd17926c4aec101ec741 100644 --- a/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/YOLOX_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/YOLOX_postprocess.py @@ -1,54 +1,54 @@ -# Copyright 2022 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import mmcv -import numpy as np -import argparse -from mmdet.core import bbox2result -from mmdet.datasets import build_dataset - -ann_file = '/annotations/instances_val2017.json' -img_prefix = '/val2017/' - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--dataset_path', default="/opt/npu/coco") - parser.add_argument('--model_config', default="mmdetection/configs/yolox/yolox_s_8x8_300e_coco.py") - parser.add_argument('--bin_data_path', default="result/dumpOutput_device0/") - parser.add_argument('--meta_info_path', default="yolox_meta.info") - parser.add_argument('--num_classes', default=81) - - args = parser.parse_args() - - cfg = mmcv.Config.fromfile(args.model_config) - cfg.data.test.test_mode = True - cfg.data.test.ann_file = args.dataset_path + ann_file - cfg.data.test.img_prefix = args.dataset_path + img_prefix - dataset = build_dataset(cfg.data.test) - - num_classes = int(args.num_classes) - outputs = [] - with open(args.meta_info_path, "r") as fp: - for line in fp: - _, file_path, scalar = line.split() - scalar = float(scalar) - file_name = file_path.split("/")[1].replace(".bin", "") - result_list = [ - np.fromfile("{0}{1}_{2}.bin".format(args.bin_data_path, file_name, 1), dtype=np.float32).reshape(-1, 5), - np.fromfile("{0}{1}_{2}.bin".format(args.bin_data_path, file_name, 2), dtype=np.int64)] - result_list[0][..., :4] /= scalar - bbox_result = bbox2result(result_list[0], result_list[1], num_classes) - outputs.append(bbox_result) - eval_kwargs = {'metric': ['bbox']} - dataset.evaluate(outputs, **eval_kwargs) +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import mmcv +import numpy as np +import argparse +from mmdet.core import bbox2result +from mmdet.datasets import build_dataset + +ann_file = '/annotations/instances_val2017.json' +img_prefix = '/val2017/' + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--dataset_path', default="/opt/npu/coco") + parser.add_argument('--model_config', default="mmdetection/configs/yolox/yolox_s_8x8_300e_coco.py") + parser.add_argument('--bin_data_path', default="result/dumpOutput_device0/") + parser.add_argument('--meta_info_path', default="yolox_meta.info") + parser.add_argument('--num_classes', default=81) + + args = parser.parse_args() + + cfg = mmcv.Config.fromfile(args.model_config) + cfg.data.test.test_mode = True + cfg.data.test.ann_file = args.dataset_path + ann_file + cfg.data.test.img_prefix = args.dataset_path + img_prefix + dataset = build_dataset(cfg.data.test) + + num_classes = int(args.num_classes) + outputs = [] + with open(args.meta_info_path, "r") as fp: + for line in fp: + _, file_path, scalar = line.split() + scalar = float(scalar) + file_name = file_path.split("/")[1].replace(".bin", "") + result_list = [ + np.fromfile("{0}{1}_{2}.bin".format(args.bin_data_path, file_name, 1), dtype=np.float32).reshape(-1, 5), + np.fromfile("{0}{1}_{2}.bin".format(args.bin_data_path, file_name, 2), dtype=np.int64)] + result_list[0][..., :4] /= scalar + bbox_result = bbox2result(result_list[0], result_list[1], num_classes) + outputs.append(bbox_result) + eval_kwargs = {'metric': ['bbox']} + dataset.evaluate(outputs, **eval_kwargs) diff --git a/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/gen_dataset_info.py index dee00755558872b2746c53c9e96f24394dbbd417..877b0a026d48b4e4093af24351f8cb9a629d5ac1 100644 --- a/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/gen_dataset_info.py @@ -1,53 +1,53 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import mmcv -from mmdet.datasets import build_dataset -import pickle as pk - -ann_file = '/annotations/instances_val2017.json' -img_prefix = '/val2017/' - -if __name__ == '__main__': - image_src_path = sys.argv[1] - config_path = sys.argv[2] - bin_path = sys.argv[3] - meta_path = sys.argv[4] - info_name = sys.argv[5] - info_meta_name = sys.argv[6] - width = int(sys.argv[7]) - height = int(sys.argv[8]) - - cfg = mmcv.Config.fromfile(config_path) - cfg.data.test.ann_file = image_src_path + ann_file - cfg.data.test.img_prefix = image_src_path + img_prefix - cfg.data.test.test_mode = True - - dataset = build_dataset(cfg.data.test) - - with open(info_name, "w") as fp1, open(info_meta_name, "w") as fp2: - for idx in range(5000): - img_id = dataset.img_ids[idx] - fp1.write("{} {}/{:0>12d}.bin {} {}\n".format(idx, bin_path, img_id, width, height)) - fp_meta = open("%s/%012d.pk" % (meta_path, img_id), "rb") - meta = pk.load(fp_meta) - fp_meta.close() - fp2.write("{} {}/{:0>12d}.bin {}\n".format( - idx, - meta_path, - img_id, - meta['scalar'] - )) - print("Get info done!") +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import mmcv +from mmdet.datasets import build_dataset +import pickle as pk + +ann_file = '/annotations/instances_val2017.json' +img_prefix = '/val2017/' + +if __name__ == '__main__': + image_src_path = sys.argv[1] + config_path = sys.argv[2] + bin_path = sys.argv[3] + meta_path = sys.argv[4] + info_name = sys.argv[5] + info_meta_name = sys.argv[6] + width = int(sys.argv[7]) + height = int(sys.argv[8]) + + cfg = mmcv.Config.fromfile(config_path) + cfg.data.test.ann_file = image_src_path + ann_file + cfg.data.test.img_prefix = image_src_path + img_prefix + cfg.data.test.test_mode = True + + dataset = build_dataset(cfg.data.test) + + with open(info_name, "w") as fp1, open(info_meta_name, "w") as fp2: + for idx in range(5000): + img_id = dataset.img_ids[idx] + fp1.write("{} {}/{:0>12d}.bin {} {}\n".format(idx, bin_path, img_id, width, height)) + fp_meta = open("%s/%012d.pk" % (meta_path, img_id), "rb") + meta = pk.load(fp_meta) + fp_meta.close() + fp2.write("{} {}/{:0>12d}.bin {}\n".format( + idx, + meta_path, + img_id, + meta['scalar'] + )) + print("Get info done!") diff --git a/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/readme.md b/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/readme.md index 645cc073d17cc9c6290570fb32fdfdc09ecb5f4f..56601531ed18d4472b67c0277d446bac7aca531b 100644 --- a/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/readme.md +++ b/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/readme.md @@ -1,51 +1,51 @@ -### YOLOX模型PyTorch离线推理指导 - -### 1. 环境准备 - -1. 安装依赖 - -```bash -pip install -r requirements.txt -``` - -2. 获取,修改与安装开源模型代码 - -``` -git clone -b master https://github.com/open-mmlab/mmdetection.git -cd mmdetection -git reset 6b87ac22b8d9dea8cc28b9ce84909e6c311e6268 --hard - -pip install -v -e . # or python3 setup.py develop -pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.7.0/index.html -patch -p1 < ../YOLOX.patch -cd .. -``` - -3. 将权重文件[yolox_x_8x8_300e_coco_20211126_140254-1ef88d67.pth](https://download.openmmlab.com/mmdetection/v2.0/yolox/yolox_x_8x8_300e_coco/yolox_x_8x8_300e_coco_20211126_140254-1ef88d67.pth)放到当前工作目录。 - -4. 数据集 - - 获取COCO数据集,并重命名为COCO,放到/root/datasets目录 - -5. [获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) - - 将benchmark.x86_64或benchmark.aarch64放到当前工作目录 - -### 2. 离线推理 - -710上执行,执行时使npu-smi info查看设备状态,确保device空闲 - -```bash -bash test/pth2om.sh --batch_size=1 -bash test/eval_acc_perf.sh --datasets_path=/root/datasets --batch_size=1 -``` - -**评测结果:** - -| 模型 | pth精度 | 710离线推理精度 | 性能基准 | 710性能 | -| ----------- | --------- | --------------- | --------- | ------- | -| YOLOX bs1 | box AP:50.9 | box AP:51.0 | fps 11.828 | fps 27.697 | -| YOLOX bs16 | box AP:50.9 | box AP:51.0 | fps 14.480 | fps 38.069 | - - - +### YOLOX模型PyTorch离线推理指导 + +### 1. 环境准备 + +1. 安装依赖 + +```bash +pip install -r requirements.txt +``` + +2. 获取,修改与安装开源模型代码 + +``` +git clone -b master https://github.com/open-mmlab/mmdetection.git +cd mmdetection +git reset 6b87ac22b8d9dea8cc28b9ce84909e6c311e6268 --hard + +pip install -v -e . # or python3 setup.py develop +pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.7.0/index.html +patch -p1 < ../YOLOX.patch +cd .. +``` + +3. 将权重文件[yolox_x_8x8_300e_coco_20211126_140254-1ef88d67.pth](https://download.openmmlab.com/mmdetection/v2.0/yolox/yolox_x_8x8_300e_coco/yolox_x_8x8_300e_coco_20211126_140254-1ef88d67.pth)放到当前工作目录。 + +4. 数据集 + + 获取COCO数据集,并重命名为COCO,放到/root/datasets目录 + +5. [获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) + + 将benchmark.x86_64或benchmark.aarch64放到当前工作目录 + +### 2. 离线推理 + +710上执行,执行时使npu-smi info查看设备状态,确保device空闲 + +```bash +bash test/pth2om.sh --batch_size=1 +bash test/eval_acc_perf.sh --datasets_path=/root/datasets --batch_size=1 +``` + +**评测结果:** + +| 模型 | pth精度 | 710离线推理精度 | 性能基准 | 710性能 | +| ----------- | --------- | --------------- | --------- | ------- | +| YOLOX bs1 | box AP:50.9 | box AP:51.0 | fps 11.828 | fps 27.697 | +| YOLOX bs16 | box AP:50.9 | box AP:51.0 | fps 14.480 | fps 38.069 | + + + diff --git a/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/requirements.txt b/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/requirements.txt index 417d5e02a3b432ff1a034314f6975c4072f6f479..5b7b027fef93b38c539a8c1a0ddcb59fc6bfa307 100644 --- a/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/requirements.txt +++ b/ACL_PyTorch/contrib/cv/detection/YOLOX-mmdetection/requirements.txt @@ -1,7 +1,7 @@ -torch==1.7.0 -torchvision==0.8.0 -onnx -opencv-python -sympy -cython +torch==1.7.0 +torchvision==0.8.0 +onnx +opencv-python +sympy +cython numpy \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/YOLOX/Yolox_postprocess.py b/ACL_PyTorch/contrib/cv/detection/YOLOX/Yolox_postprocess.py index 1eef050881cb251e6fbb0c534a2c57d6cfe75231..9367f270d33bd801837c379d37ddc16b50c8332b 100644 --- a/ACL_PyTorch/contrib/cv/detection/YOLOX/Yolox_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/YOLOX/Yolox_postprocess.py @@ -1,139 +1,139 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import sys -import argparse -from tqdm import tqdm -import torch -import numpy as np -from yolox.data import COCODataset, ValTransform -from yolox.evaluators import COCOEvaluator -from yolox.utils.boxes import postprocess - -from yolox.utils.demo_utils import demo_postprocess -sys.path.append('./YOLOX') - - -def get_output_data(dump_dir, idx, dtype=np.float32): - output_shape_1 = [1, 4, 80, 80] - output_shape_2 = [1, 1, 80, 80] - output_shape_3 = [1, 80, 80, 80] - output_shape_4 = [1, 4, 40, 40] - output_shape_5 = [1, 1, 40, 40] - output_shape_6 = [1, 80, 40, 40] - output_shape_7 = [1, 4, 20, 20] - output_shape_8 = [1, 1, 20, 20] - output_shape_9 = [1, 80, 20, 20] - - input_file_1 = os.path.join(dump_dir, "{:0>12d}_1.bin".format(idx)) - input_file_2 = os.path.join(dump_dir, "{:0>12d}_2.bin".format(idx)) - input_file_3 = os.path.join(dump_dir, "{:0>12d}_3.bin".format(idx)) - input_file_4 = os.path.join(dump_dir, "{:0>12d}_4.bin".format(idx)) - input_file_5 = os.path.join(dump_dir, "{:0>12d}_5.bin".format(idx)) - input_file_6 = os.path.join(dump_dir, "{:0>12d}_6.bin".format(idx)) - input_file_7 = os.path.join(dump_dir, "{:0>12d}_7.bin".format(idx)) - input_file_8 = os.path.join(dump_dir, "{:0>12d}_8.bin".format(idx)) - input_file_9 = os.path.join(dump_dir, "{:0>12d}_9.bin".format(idx)) - - input_data_1 = np.fromfile(input_file_1, dtype=dtype).reshape(output_shape_1) - input_data_2 = np.fromfile(input_file_2, dtype=dtype).reshape(output_shape_2) - input_data_3 = np.fromfile(input_file_3, dtype=dtype).reshape(output_shape_3) - input_data_4 = np.fromfile(input_file_4, dtype=dtype).reshape(output_shape_4) - input_data_5 = np.fromfile(input_file_5, dtype=dtype).reshape(output_shape_5) - input_data_6 = np.fromfile(input_file_6, dtype=dtype).reshape(output_shape_6) - input_data_7 = np.fromfile(input_file_7, dtype=dtype).reshape(output_shape_7) - input_data_8 = np.fromfile(input_file_8, dtype=dtype).reshape(output_shape_8) - input_data_9 = np.fromfile(input_file_9, dtype=dtype).reshape(output_shape_9) - - lst = [] - lst.append(torch.from_numpy(input_data_1)) - lst.append(torch.from_numpy(input_data_2)) - lst.append(torch.from_numpy(input_data_3)) - lst.append(torch.from_numpy(input_data_4)) - lst.append(torch.from_numpy(input_data_5)) - lst.append(torch.from_numpy(input_data_6)) - lst.append(torch.from_numpy(input_data_7)) - lst.append(torch.from_numpy(input_data_8)) - lst.append(torch.from_numpy(input_data_9)) - - return lst - - -def main(): - parser = argparse.ArgumentParser(description='YOLOX Postprocess') - parser.add_argument('--dataroot', dest='dataroot', - help='data root dirname', default='/opt/npu/coco', - type=str) - parser.add_argument('--dump_dir', dest='dump_dir', - help='dump dir for bin files', default='./result/dumpOutput_device0/', - type=str) - - parser.add_argument('--batch', dest='batch', help='batch for dataloader', default=1, type=int) - opt = parser.parse_args() - - if os.path.exists(opt.dump_dir): - os.system("rm-rf " + opt.dump_dir) - else: - os.system("mkdir " + opt.dump_dir) - - valdataset = COCODataset( - data_dir=opt.dataroot, - json_file='instances_val2017.json', - name="val2017", - img_size = (640, 640), - preproc=ValTransform(legacy=False), - ) - sampler = torch.utils.data.SequentialSampler(valdataset) - - dataloader_kwargs = {"num_workers": 8, "pin_memory": True, "sampler": sampler, "batch_size": opt.batch} - - val_loader = torch.utils.data.DataLoader(valdataset, **dataloader_kwargs) - - data_list = [] - coco_evaluator = COCOEvaluator(val_loader, img_size=(640, 640), confthre=0.001, nmsthre=0.65, num_classes=80) - - for cur_iter, (imgs, _, info_imgs, ids) in enumerate(tqdm(val_loader)): - - opt1, opt2, opt3, opt4, opt5, opt6, opt7, opt8, opt9 = get_output_data(opt.dump_dir, cur_iter) - opt2 = opt2.sigmoid() - opt3 = opt3.sigmoid() - - opt5 = opt5.sigmoid() - opt6 = opt6.sigmoid() - - opt8 = opt8.sigmoid() - opt9 = opt9.sigmoid() - output1 = torch.cat((opt1, opt2, opt3), dim=1) - output2 = torch.cat((opt4, opt5, opt6), dim=1) - output3 = torch.cat((opt7, opt8, opt9), dim=1) - - output1 = output1.view(1, 85, -1) - output2 = output2.view(1, 85, -1) - output3 = output3.view(1, 85, -1) - - outputs = torch.cat((output1, output2, output3), dim=2) - outputs = outputs.transpose(2, 1) - - - outputs = demo_postprocess(outputs, [640, 640]) - - outputs = postprocess(outputs, num_classes=80, conf_thre=0.001, nms_thre=0.65) - data_list.extend(coco_evaluator.convert_to_coco_format(outputs, info_imgs, ids)) - - results = coco_evaluator.evaluate_prediction(data_list) - print(results) - - -if __name__ == "__main__": - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import sys +import argparse +from tqdm import tqdm +import torch +import numpy as np +from yolox.data import COCODataset, ValTransform +from yolox.evaluators import COCOEvaluator +from yolox.utils.boxes import postprocess + +from yolox.utils.demo_utils import demo_postprocess +sys.path.append('./YOLOX') + + +def get_output_data(dump_dir, idx, dtype=np.float32): + output_shape_1 = [1, 4, 80, 80] + output_shape_2 = [1, 1, 80, 80] + output_shape_3 = [1, 80, 80, 80] + output_shape_4 = [1, 4, 40, 40] + output_shape_5 = [1, 1, 40, 40] + output_shape_6 = [1, 80, 40, 40] + output_shape_7 = [1, 4, 20, 20] + output_shape_8 = [1, 1, 20, 20] + output_shape_9 = [1, 80, 20, 20] + + input_file_1 = os.path.join(dump_dir, "{:0>12d}_1.bin".format(idx)) + input_file_2 = os.path.join(dump_dir, "{:0>12d}_2.bin".format(idx)) + input_file_3 = os.path.join(dump_dir, "{:0>12d}_3.bin".format(idx)) + input_file_4 = os.path.join(dump_dir, "{:0>12d}_4.bin".format(idx)) + input_file_5 = os.path.join(dump_dir, "{:0>12d}_5.bin".format(idx)) + input_file_6 = os.path.join(dump_dir, "{:0>12d}_6.bin".format(idx)) + input_file_7 = os.path.join(dump_dir, "{:0>12d}_7.bin".format(idx)) + input_file_8 = os.path.join(dump_dir, "{:0>12d}_8.bin".format(idx)) + input_file_9 = os.path.join(dump_dir, "{:0>12d}_9.bin".format(idx)) + + input_data_1 = np.fromfile(input_file_1, dtype=dtype).reshape(output_shape_1) + input_data_2 = np.fromfile(input_file_2, dtype=dtype).reshape(output_shape_2) + input_data_3 = np.fromfile(input_file_3, dtype=dtype).reshape(output_shape_3) + input_data_4 = np.fromfile(input_file_4, dtype=dtype).reshape(output_shape_4) + input_data_5 = np.fromfile(input_file_5, dtype=dtype).reshape(output_shape_5) + input_data_6 = np.fromfile(input_file_6, dtype=dtype).reshape(output_shape_6) + input_data_7 = np.fromfile(input_file_7, dtype=dtype).reshape(output_shape_7) + input_data_8 = np.fromfile(input_file_8, dtype=dtype).reshape(output_shape_8) + input_data_9 = np.fromfile(input_file_9, dtype=dtype).reshape(output_shape_9) + + lst = [] + lst.append(torch.from_numpy(input_data_1)) + lst.append(torch.from_numpy(input_data_2)) + lst.append(torch.from_numpy(input_data_3)) + lst.append(torch.from_numpy(input_data_4)) + lst.append(torch.from_numpy(input_data_5)) + lst.append(torch.from_numpy(input_data_6)) + lst.append(torch.from_numpy(input_data_7)) + lst.append(torch.from_numpy(input_data_8)) + lst.append(torch.from_numpy(input_data_9)) + + return lst + + +def main(): + parser = argparse.ArgumentParser(description='YOLOX Postprocess') + parser.add_argument('--dataroot', dest='dataroot', + help='data root dirname', default='/opt/npu/coco', + type=str) + parser.add_argument('--dump_dir', dest='dump_dir', + help='dump dir for bin files', default='./result/dumpOutput_device0/', + type=str) + + parser.add_argument('--batch', dest='batch', help='batch for dataloader', default=1, type=int) + opt = parser.parse_args() + + if os.path.exists(opt.dump_dir): + os.system("rm-rf " + opt.dump_dir) + else: + os.system("mkdir " + opt.dump_dir) + + valdataset = COCODataset( + data_dir=opt.dataroot, + json_file='instances_val2017.json', + name="val2017", + img_size = (640, 640), + preproc=ValTransform(legacy=False), + ) + sampler = torch.utils.data.SequentialSampler(valdataset) + + dataloader_kwargs = {"num_workers": 8, "pin_memory": True, "sampler": sampler, "batch_size": opt.batch} + + val_loader = torch.utils.data.DataLoader(valdataset, **dataloader_kwargs) + + data_list = [] + coco_evaluator = COCOEvaluator(val_loader, img_size=(640, 640), confthre=0.001, nmsthre=0.65, num_classes=80) + + for cur_iter, (imgs, _, info_imgs, ids) in enumerate(tqdm(val_loader)): + + opt1, opt2, opt3, opt4, opt5, opt6, opt7, opt8, opt9 = get_output_data(opt.dump_dir, cur_iter) + opt2 = opt2.sigmoid() + opt3 = opt3.sigmoid() + + opt5 = opt5.sigmoid() + opt6 = opt6.sigmoid() + + opt8 = opt8.sigmoid() + opt9 = opt9.sigmoid() + output1 = torch.cat((opt1, opt2, opt3), dim=1) + output2 = torch.cat((opt4, opt5, opt6), dim=1) + output3 = torch.cat((opt7, opt8, opt9), dim=1) + + output1 = output1.view(1, 85, -1) + output2 = output2.view(1, 85, -1) + output3 = output3.view(1, 85, -1) + + outputs = torch.cat((output1, output2, output3), dim=2) + outputs = outputs.transpose(2, 1) + + + outputs = demo_postprocess(outputs, [640, 640]) + + outputs = postprocess(outputs, num_classes=80, conf_thre=0.001, nms_thre=0.65) + data_list.extend(coco_evaluator.convert_to_coco_format(outputs, info_imgs, ids)) + + results = coco_evaluator.evaluate_prediction(data_list) + print(results) + + +if __name__ == "__main__": + main() diff --git a/ACL_PyTorch/contrib/cv/detection/YOLOX/readme.md b/ACL_PyTorch/contrib/cv/detection/YOLOX/readme.md index 0ae6b915620c123373d1dad89d5ce43eaec1f8bf..0043fc950f365ef96e8574ab4608238d3aef070b 100644 --- a/ACL_PyTorch/contrib/cv/detection/YOLOX/readme.md +++ b/ACL_PyTorch/contrib/cv/detection/YOLOX/readme.md @@ -1,50 +1,50 @@ -### YOLOX模型PyTorch离线推理指导 - -### 1. 环境准备 - -1. 安装依赖 - -```bash -pip3.7 install -r requirements.txt -``` - -2. 获取,修改与安装开源模型代码 - -``` -git clone git@github.com:Megvii-BaseDetection/YOLOX.git -main -cd YOLOX -git reset 6880e3999eb5cf83037e1818ee63d589384587bd --hard -pip3.7 install -v -e . # or python3 setup.py develop -pip3.7 install cython -pip3.7 install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI' -patch -p1 < ../YOLOX-X.patch -cd .. -``` - -3. 将权重文件[yolox_x.pth](https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_x.pth)放到当前工作目录。 - -4. 数据集 - - 获取COCO数据集,并重命名为COCO,放到/root/datasets目录 - -5. [获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) - - 将benchmark.x86_64或benchmark.aarch64放到当前工作目录 - -### 2. 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 - -```bash -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets -``` - -**评测结果:** - -| 模型 | pth精度 | 310离线推理精度 | 性能基准 | 310性能 | -| ----------- | --------- | --------------- | --------- | ------- | -| yolox-x bs1 | map:51.2% | map:51.1% | 60.739fps | 37.72144fps | - - - +### YOLOX模型PyTorch离线推理指导 + +### 1. 环境准备 + +1. 安装依赖 + +```bash +pip3.7 install -r requirements.txt +``` + +2. 获取,修改与安装开源模型代码 + +``` +git clone git@github.com:Megvii-BaseDetection/YOLOX.git -main +cd YOLOX +git reset 6880e3999eb5cf83037e1818ee63d589384587bd --hard +pip3.7 install -v -e . # or python3 setup.py develop +pip3.7 install cython +pip3.7 install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI' +patch -p1 < ../YOLOX-X.patch +cd .. +``` + +3. 将权重文件[yolox_x.pth](https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_x.pth)放到当前工作目录。 + +4. 数据集 + + 获取COCO数据集,并重命名为COCO,放到/root/datasets目录 + +5. [获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) + + 将benchmark.x86_64或benchmark.aarch64放到当前工作目录 + +### 2. 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 + +```bash +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets +``` + +**评测结果:** + +| 模型 | pth精度 | 310离线推理精度 | 性能基准 | 310性能 | +| ----------- | --------- | --------------- | --------- | ------- | +| yolox-x bs1 | map:51.2% | map:51.1% | 60.739fps | 37.72144fps | + + + diff --git a/ACL_PyTorch/contrib/cv/detection/pyramidbox/README.md b/ACL_PyTorch/contrib/cv/detection/pyramidbox/README.md index 4284fc05decc2f23c229eb6dcbe9ca5ff9753c58..6b826043421d14ad967cbb1567408866acb74bd4 100644 --- a/ACL_PyTorch/contrib/cv/detection/pyramidbox/README.md +++ b/ACL_PyTorch/contrib/cv/detection/pyramidbox/README.md @@ -1,292 +1,292 @@ -# Pyramidbox Onnx模型端到端推理指导 - -- 1 模型概述 - - [1.1 论文地址]([[1803.07737\] PyramidBox: A Context-assisted Single Shot Face Detector (arxiv.org)](https://arxiv.org/abs/1803.07737)) - - [1.2 代码地址](https://gitee.com/kghhkhkljl/pyramidbox.git) -- 2 环境说明 - - [2.1 深度学习框架](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#21-深度学习框架) - - [2.2 python第三方库](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#22-python第三方库) -- 3 模型转换 - - [3.1 pth转onnx模型](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#31-pth转onnx模型) - - [3.2 onnx转om模型](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#32-onnx转om模型) -- 4 数据集预处理 - - [4.1 数据集获取](https://www.graviti.cn/open-datasets/WIDER_FACE) - - [4.2 数据集预处理](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#42-数据集预处理) - - [4.3 生成数据集信息文件](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#43-生成数据集信息文件) -- 5 离线推理 - - [5.1 benchmark工具概述](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#51-benchmark工具概述) - - [5.2 离线推理](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#52-离线推理) -- 6 精度对比 - - [6.1 离线推理精度统计](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#61-离线推理精度统计) - - [6.2 开源精度](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#62-开源精度) - - [6.3 精度对比](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#63-精度对比) -- 7 性能对比 - - [7.1 npu性能数据](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#71-npu性能数据) - - [7.2 T4性能数据](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#72-T4性能数据) - - [7.3 性能对比](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#73-性能对比) - -## 1 模型概述 - -- **论文地址** -- **代码地址** - -### 1.1 论文地址 - -[Pyramidbox论文](https://arxiv.org/abs/1803.07737) - -### 1.2 代码地址 - -https://gitee.com/kghhkhkljl/pyramidbox.git - -## 2 环境说明 - -- **深度学习框架** -- **python第三方库** - -### 2.1 深度学习框架 - -``` -python3.7.5 -CANN 5.0.3 - -pytorch >= 1.5.0 -torchvision >= 0.10.0 -onnx >= 1.7.0 - -说明:若是在conda环境下,直接采用python,不用python3.7 -``` - -### 2.2 python第三方库 - -``` -torch == 1.9.0 -numpy == 1.20.3 -Pillow == 8.2.0 -opencv-python == 4.5.3.56 -scipy == 1.7.1 -easydict == 1.9 -six == 1.16.0 -pycocotools == 2.0.2 -``` - -## 3 模型转换 - -- **pth转onnx模型** -- **onnx转om模型** - -### 3.1 pth转onnx模型 - -1.拉取代码仓库 (因为使用了开源代码模块,所以需要git clone一下) - -```shell -git clone https://gitee.com/kghhkhkljl/pyramidbox.git -``` - -克隆下来源代码之后将pr中的代码放到克隆下来的pyramidbox下面 - -2.下载pth权重文件 -权重文件从百度网盘上获取:[pyramidbox_120000_99.02.pth_免费高速下载|百度网盘-分享无限制 (baidu.com)](https://pan.baidu.com/s/1VtzgB9srkJY4SUtVM3n8tw?_at_=1631960039538) - -下载下来的权重文件也需要放在pyramidbox目录下面 - -3.使用pth2onnx.py进行onnx的转换 - -``` -方法二:cd pyramidbox/test -bash pth2onnx.sh -方法二:cd pyramidbox -python3.7 pyramidbox_pth2onnx.py ./pyramidbox_1000.onnx ./pyramidbox_120000_99.02.pth -第一个参数是onnx文件生成在当前目录的名字,第二个参数是当前目录下的权重文件 -``` - -### 3.2 onnx转om模型 - -1.设置环境变量 - -``` -source atc.sh -``` - -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 - -``` -方法一:cd pyramidbox/test -bash onnxToom.sh -方法二:cd pyramidbox -atc --framework=5 --model=pyramidbox_1000.onnx --input_format=NCHW --input_shape="image:1,3,1000,1000" --output=pyramidbox_1000_bs1 --log=debug --soc_version=Ascend310 --precision_mode=force_fp32 - ---model是onnx的文件名,--input_shape是图片的shape,--output是输出on文件的文件名 -``` - -## 4 数据集预处理 - -- **数据集获取** -- **数据集预处理** -- **生成数据集信息文件** - -### 4.1 数据集获取 - -下载WIDER_FACE数据集: - -下载地址:https://www.graviti.cn/open-datasets/WIDER_FACE - -可以将数据集图片放在pyramidbox目录下的images下面,images目录需要自己创建(说明:images下面是个二级目录) - -``` -cd pyramidbox/images -``` - -### 4.2 数据集预处理 - -1.预处理脚本pyramidbox_pth_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 - -``` -方法一:cd pyramidbox/test -bash pre_deal.sh -方法二:cd pyramidbox -python3.7 pyramidbox_pth_preprocess.py ./images ./data1000_1 ./data1000_2 -第一个参数是预处理文件,第二个参数是数据集所在目录,第三和第四个参数是预处理后的文件名(说明:由于预处理需要进行两次图片的不同处理,所以生成的文件有两个) -``` - -### 4.3 生成数据集信息文件 - -1.生成数据集信息文件脚本get_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 - -``` -方法一:cd pyramidbox/test -bash to_info.sh -方法二:cd pyramidbox -python3.7 get_info.py bin ./data1000_1 ./pyramidbox_pre_bin_1000_1.info 1000 1000 -python3.7 get_info.py bin ./data1000_2 ./pyramidbox_pre_bin_1000_2.info 1000 1000 - -第一个是预处理后的数据集所在目录,第二个参数是生成的info文件名,后两个参数是图片的宽高。(说明:由于预处理会对图片进行两次处理,生成的文件有两个,所以会需要生成两个info文件) -``` - -## 5 离线推理 - -- **benchmark工具概述** -- **离线推理** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.3推理benchmark工具用户指南 - -### 5.2 离线推理 - -1.执行离线推理 - -执行前需要将benchmark.x86_64移动到执行目录下 - -(注:执行目录是/pyramidbox) - -然后运行如下命令: - -``` -方法一:cd pyramidbox/test -bash infer.sh -方法二:cd pyramidbox -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./pyramidbox_1000_bs1.om -input_text_path=./pyramidbox_pre_bin_1.info -input_width=1000 -input_height=1000 -output_binary=True -useDvpp=False --precision_mode=force_fp32 -./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=1 -om_path=./pyramidbox_1000_bs1.om -input_text_path=./pyramidbox_pre_bin_2.info -input_width=1000 -input_height=1000 -output_binary=True -useDvpp=False --precision_mode=force_fp32 - --om_path为om所在的路径,-input_text_path为预处理后的bin文件的整个info文件,-input_width为图片的宽,-input_height为图片的高。由于预处理后的数据集有两个,所以此脚本需要运行两次,第二次运行只需要改动-device_id=1和-input_text_path为相应的info文件即可(例如:pyramidbox_pre_bin_2.info)。 -``` - -输出结果默认保存在当前目录result/dumpOutput_device{0}以及result/dumpOutput_device{1}下,每个输入对应的输出对应2个_1.bin文件,我们只使用第一个。 - -2.处理目录result/dumpOutput_device{0}和result/dumpOutput_device{1}下的bin文件 - -将该目录下的文件分类别存放,以便于后处理 - -``` -方法一:cd pyramidbox/test -bash convert.sh -方法二:cd pyramidbox -python3.7 convert.py ./result/dumpOutput_device0/ ./result/result1 -python3.7 convert.py ./result/dumpOutput_device1/ ./result/result2 -第一个参数是infer.sh脚本生成的文件,第二个参数是生成的二级目录所在的文件夹。 -``` - - - -## 6 精度对比 - -- **离线推理精度** -- **开源精度** -- **精度对比** - -### 6.1 离线推理精度统计 - -1.后处理 - -``` -cd ./pyramidbox -python3.7 pyramidbox_pth_postprocess.py -``` - -2.进行Ascend310上精度评估 - -``` -cd ./pyramidbox/evaluate -python3.7 evaluation.py -``` - -### 6.2 开源精度 - -pyramidbox在线推理精度: - -``` -Easy Val AP: 0.958986327388428 -Medium Val AP: 0.9504929578311708 -Hard Val AP: 0.907248372271328 -``` - -### 6.3 精度对比 - -``` -Easy Val AP: 0.9628280209085509 -Medium Val AP: 0.9538134269337523 -Hard Val AP: 0.8798007442124222 -``` - -### 6.3 精度对比 - -由于源码没有固定住shape,所以精度会有损失,因此和同一分辨率下的在线推理进行对比。对比方式:三个尺度求和取平均。 - -## 7 性能对比 - -- **npu性能数据** -- **T4性能数据** -- **性能对比** - -### 7.1 npu性能数据 - -1.benchmark工具在整个数据集上推理获得性能数据 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: - -``` -[e2e] throughputRate: 0.609815, latency: 5.29013e+06 -[data read] throughputRate: 0.635586, moduleLatency: 1573.35 -[preprocess] throughputRate: 0.61536, moduleLatency: 1625.07 -[infer] throughputRate: 0.6099, Interface throughputRate: 0.620281, moduleLatency: 1638.44 -[post] throughputRate: 0.6099, moduleLatency: 1639.61 -``` - -Interface throughputRate: 0.620281,0.620281x4=2.48既是batch1 310单卡吞吐率 - - - -说明:由于bs2以上会导致爆显存,所以测不了性能,此处只测了bs1。 - -![1633688929248](C:\Users\Eiven\AppData\Roaming\Typora\typora-user-images\1633688929248.png) - -### 7.2 T4性能数据 - -batch1 t4单卡吞吐率的计算方法是通过计算平均每张图片的耗时t,然后用1/t即是batch1 t4的单卡吞吐率。此处的t=1.560808,所以吞吐率为0.6407 - -### 7.3 性能对比 - +# Pyramidbox Onnx模型端到端推理指导 + +- 1 模型概述 + - [1.1 论文地址]([[1803.07737\] PyramidBox: A Context-assisted Single Shot Face Detector (arxiv.org)](https://arxiv.org/abs/1803.07737)) + - [1.2 代码地址](https://gitee.com/kghhkhkljl/pyramidbox.git) +- 2 环境说明 + - [2.1 深度学习框架](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#21-深度学习框架) + - [2.2 python第三方库](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#22-python第三方库) +- 3 模型转换 + - [3.1 pth转onnx模型](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#31-pth转onnx模型) + - [3.2 onnx转om模型](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#32-onnx转om模型) +- 4 数据集预处理 + - [4.1 数据集获取](https://www.graviti.cn/open-datasets/WIDER_FACE) + - [4.2 数据集预处理](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#42-数据集预处理) + - [4.3 生成数据集信息文件](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#43-生成数据集信息文件) +- 5 离线推理 + - [5.1 benchmark工具概述](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#51-benchmark工具概述) + - [5.2 离线推理](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#52-离线推理) +- 6 精度对比 + - [6.1 离线推理精度统计](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#61-离线推理精度统计) + - [6.2 开源精度](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#62-开源精度) + - [6.3 精度对比](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#63-精度对比) +- 7 性能对比 + - [7.1 npu性能数据](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#71-npu性能数据) + - [7.2 T4性能数据](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#72-T4性能数据) + - [7.3 性能对比](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#73-性能对比) + +## 1 模型概述 + +- **论文地址** +- **代码地址** + +### 1.1 论文地址 + +[Pyramidbox论文](https://arxiv.org/abs/1803.07737) + +### 1.2 代码地址 + +https://gitee.com/kghhkhkljl/pyramidbox.git + +## 2 环境说明 + +- **深度学习框架** +- **python第三方库** + +### 2.1 深度学习框架 + +``` +python3.7.5 +CANN 5.0.3 + +pytorch >= 1.5.0 +torchvision >= 0.10.0 +onnx >= 1.7.0 + +说明:若是在conda环境下,直接采用python,不用python3.7 +``` + +### 2.2 python第三方库 + +``` +torch == 1.9.0 +numpy == 1.20.3 +Pillow == 8.2.0 +opencv-python == 4.5.3.56 +scipy == 1.7.1 +easydict == 1.9 +six == 1.16.0 +pycocotools == 2.0.2 +``` + +## 3 模型转换 + +- **pth转onnx模型** +- **onnx转om模型** + +### 3.1 pth转onnx模型 + +1.拉取代码仓库 (因为使用了开源代码模块,所以需要git clone一下) + +```shell +git clone https://gitee.com/kghhkhkljl/pyramidbox.git +``` + +克隆下来源代码之后将pr中的代码放到克隆下来的pyramidbox下面 + +2.下载pth权重文件 +权重文件从百度网盘上获取:[pyramidbox_120000_99.02.pth_免费高速下载|百度网盘-分享无限制 (baidu.com)](https://pan.baidu.com/s/1VtzgB9srkJY4SUtVM3n8tw?_at_=1631960039538) + +下载下来的权重文件也需要放在pyramidbox目录下面 + +3.使用pth2onnx.py进行onnx的转换 + +``` +方法二:cd pyramidbox/test +bash pth2onnx.sh +方法二:cd pyramidbox +python3.7 pyramidbox_pth2onnx.py ./pyramidbox_1000.onnx ./pyramidbox_120000_99.02.pth +第一个参数是onnx文件生成在当前目录的名字,第二个参数是当前目录下的权重文件 +``` + +### 3.2 onnx转om模型 + +1.设置环境变量 + +``` +source atc.sh +``` + +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 + +``` +方法一:cd pyramidbox/test +bash onnxToom.sh +方法二:cd pyramidbox +atc --framework=5 --model=pyramidbox_1000.onnx --input_format=NCHW --input_shape="image:1,3,1000,1000" --output=pyramidbox_1000_bs1 --log=debug --soc_version=Ascend310 --precision_mode=force_fp32 + +--model是onnx的文件名,--input_shape是图片的shape,--output是输出on文件的文件名 +``` + +## 4 数据集预处理 + +- **数据集获取** +- **数据集预处理** +- **生成数据集信息文件** + +### 4.1 数据集获取 + +下载WIDER_FACE数据集: + +下载地址:https://www.graviti.cn/open-datasets/WIDER_FACE + +可以将数据集图片放在pyramidbox目录下的images下面,images目录需要自己创建(说明:images下面是个二级目录) + +``` +cd pyramidbox/images +``` + +### 4.2 数据集预处理 + +1.预处理脚本pyramidbox_pth_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 + +``` +方法一:cd pyramidbox/test +bash pre_deal.sh +方法二:cd pyramidbox +python3.7 pyramidbox_pth_preprocess.py ./images ./data1000_1 ./data1000_2 +第一个参数是预处理文件,第二个参数是数据集所在目录,第三和第四个参数是预处理后的文件名(说明:由于预处理需要进行两次图片的不同处理,所以生成的文件有两个) +``` + +### 4.3 生成数据集信息文件 + +1.生成数据集信息文件脚本get_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 + +``` +方法一:cd pyramidbox/test +bash to_info.sh +方法二:cd pyramidbox +python3.7 get_info.py bin ./data1000_1 ./pyramidbox_pre_bin_1000_1.info 1000 1000 +python3.7 get_info.py bin ./data1000_2 ./pyramidbox_pre_bin_1000_2.info 1000 1000 + +第一个是预处理后的数据集所在目录,第二个参数是生成的info文件名,后两个参数是图片的宽高。(说明:由于预处理会对图片进行两次处理,生成的文件有两个,所以会需要生成两个info文件) +``` + +## 5 离线推理 + +- **benchmark工具概述** +- **离线推理** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.3推理benchmark工具用户指南 + +### 5.2 离线推理 + +1.执行离线推理 + +执行前需要将benchmark.x86_64移动到执行目录下 + +(注:执行目录是/pyramidbox) + +然后运行如下命令: + +``` +方法一:cd pyramidbox/test +bash infer.sh +方法二:cd pyramidbox +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./pyramidbox_1000_bs1.om -input_text_path=./pyramidbox_pre_bin_1.info -input_width=1000 -input_height=1000 -output_binary=True -useDvpp=False --precision_mode=force_fp32 +./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=1 -om_path=./pyramidbox_1000_bs1.om -input_text_path=./pyramidbox_pre_bin_2.info -input_width=1000 -input_height=1000 -output_binary=True -useDvpp=False --precision_mode=force_fp32 + +-om_path为om所在的路径,-input_text_path为预处理后的bin文件的整个info文件,-input_width为图片的宽,-input_height为图片的高。由于预处理后的数据集有两个,所以此脚本需要运行两次,第二次运行只需要改动-device_id=1和-input_text_path为相应的info文件即可(例如:pyramidbox_pre_bin_2.info)。 +``` + +输出结果默认保存在当前目录result/dumpOutput_device{0}以及result/dumpOutput_device{1}下,每个输入对应的输出对应2个_1.bin文件,我们只使用第一个。 + +2.处理目录result/dumpOutput_device{0}和result/dumpOutput_device{1}下的bin文件 + +将该目录下的文件分类别存放,以便于后处理 + +``` +方法一:cd pyramidbox/test +bash convert.sh +方法二:cd pyramidbox +python3.7 convert.py ./result/dumpOutput_device0/ ./result/result1 +python3.7 convert.py ./result/dumpOutput_device1/ ./result/result2 +第一个参数是infer.sh脚本生成的文件,第二个参数是生成的二级目录所在的文件夹。 +``` + + + +## 6 精度对比 + +- **离线推理精度** +- **开源精度** +- **精度对比** + +### 6.1 离线推理精度统计 + +1.后处理 + +``` +cd ./pyramidbox +python3.7 pyramidbox_pth_postprocess.py +``` + +2.进行Ascend310上精度评估 + +``` +cd ./pyramidbox/evaluate +python3.7 evaluation.py +``` + +### 6.2 开源精度 + +pyramidbox在线推理精度: + +``` +Easy Val AP: 0.958986327388428 +Medium Val AP: 0.9504929578311708 +Hard Val AP: 0.907248372271328 +``` + +### 6.3 精度对比 + +``` +Easy Val AP: 0.9628280209085509 +Medium Val AP: 0.9538134269337523 +Hard Val AP: 0.8798007442124222 +``` + +### 6.3 精度对比 + +由于源码没有固定住shape,所以精度会有损失,因此和同一分辨率下的在线推理进行对比。对比方式:三个尺度求和取平均。 + +## 7 性能对比 + +- **npu性能数据** +- **T4性能数据** +- **性能对比** + +### 7.1 npu性能数据 + +1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: + +``` +[e2e] throughputRate: 0.609815, latency: 5.29013e+06 +[data read] throughputRate: 0.635586, moduleLatency: 1573.35 +[preprocess] throughputRate: 0.61536, moduleLatency: 1625.07 +[infer] throughputRate: 0.6099, Interface throughputRate: 0.620281, moduleLatency: 1638.44 +[post] throughputRate: 0.6099, moduleLatency: 1639.61 +``` + +Interface throughputRate: 0.620281,0.620281x4=2.48既是batch1 310单卡吞吐率 + + + +说明:由于bs2以上会导致爆显存,所以测不了性能,此处只测了bs1。 + +![1633688929248](C:\Users\Eiven\AppData\Roaming\Typora\typora-user-images\1633688929248.png) + +### 7.2 T4性能数据 + +batch1 t4单卡吞吐率的计算方法是通过计算平均每张图片的耗时t,然后用1/t即是batch1 t4的单卡吞吐率。此处的t=1.560808,所以吞吐率为0.6407 + +### 7.3 性能对比 + batch1:0.620281x4=2.48>0.6407 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/pyramidbox/convert.py b/ACL_PyTorch/contrib/cv/detection/pyramidbox/convert.py index bb6bdfd5c6708236f5c1e7bcb5c5b1eeab95a276..ef9043a138a97d380fc8fe96056b3dba6ee974bf 100644 --- a/ACL_PyTorch/contrib/cv/detection/pyramidbox/convert.py +++ b/ACL_PyTorch/contrib/cv/detection/pyramidbox/convert.py @@ -1,39 +1,39 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import shutil - -if __name__ == '__main__': - bin_path = sys.argv[1] - resule_path = sys.argv[2] - if not os.path.exists(resule_path): - os.mkdir(resule_path) - f = os.listdir(bin_path) - for data in f: - data = data.strip('\n') - dir_name = data.split('_')[0] + '--' + data.split('_')[1] - dir_path = os.path.join(resule_path, dir_name) - if not os.path.exists(dir_path): - os.mkdir(dir_path) - file_list = os.listdir(resule_path) - for dir in file_list: - dir = dir.strip('\n') - cur_path = os.path.join(resule_path, dir) - for data in f: - data = data.strip('\n') - if data.split('_')[0] == dir.split('--')[0]: - shutil.copy(os.path.join(bin_path, data), - os.path.join(cur_path, data)) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import shutil + +if __name__ == '__main__': + bin_path = sys.argv[1] + resule_path = sys.argv[2] + if not os.path.exists(resule_path): + os.mkdir(resule_path) + f = os.listdir(bin_path) + for data in f: + data = data.strip('\n') + dir_name = data.split('_')[0] + '--' + data.split('_')[1] + dir_path = os.path.join(resule_path, dir_name) + if not os.path.exists(dir_path): + os.mkdir(dir_path) + file_list = os.listdir(resule_path) + for dir in file_list: + dir = dir.strip('\n') + cur_path = os.path.join(resule_path, dir) + for data in f: + data = data.strip('\n') + if data.split('_')[0] == dir.split('--')[0]: + shutil.copy(os.path.join(bin_path, data), + os.path.join(cur_path, data)) diff --git a/ACL_PyTorch/contrib/cv/detection/pyramidbox/pyramidbox_pth2onnx.py b/ACL_PyTorch/contrib/cv/detection/pyramidbox/pyramidbox_pth2onnx.py index 7740e25cf5792fadbfe4bbdfe0dbc8eb341cbad7..d0faceedf538e336386b943c7afa497dc4faed67 100644 --- a/ACL_PyTorch/contrib/cv/detection/pyramidbox/pyramidbox_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/detection/pyramidbox/pyramidbox_pth2onnx.py @@ -1,35 +1,35 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -from data.config import cfg -from pyramidbox import build_net -import numpy as np -import os -import sys - -def main(onnx_path,path): - input_names=["image"] - output_names = ["output"] - net = build_net('test',2) - net.eval() - net.load_state_dict(torch.load(path,map_location='cpu')) - # dynamic_axes = {'image': {0: '-1'}, 'output': {0: '-1'}} - dummy_input = torch.randn(1,3,1000,1000) - torch.onnx.export(net,dummy_input,onnx_path,input_names = input_names,output_names=output_names,verbose=True,enable_onnx_checker=False,opset_version=9) - -if __name__ =="__main__": - onnx_path = os.path.abspath(sys.argv[1]) - path = os.path.abspath(sys.argv[2]) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +from data.config import cfg +from pyramidbox import build_net +import numpy as np +import os +import sys + +def main(onnx_path,path): + input_names=["image"] + output_names = ["output"] + net = build_net('test',2) + net.eval() + net.load_state_dict(torch.load(path,map_location='cpu')) + # dynamic_axes = {'image': {0: '-1'}, 'output': {0: '-1'}} + dummy_input = torch.randn(1,3,1000,1000) + torch.onnx.export(net,dummy_input,onnx_path,input_names = input_names,output_names=output_names,verbose=True,enable_onnx_checker=False,opset_version=9) + +if __name__ =="__main__": + onnx_path = os.path.abspath(sys.argv[1]) + path = os.path.abspath(sys.argv[2]) main(onnx_path,path) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/pyramidbox/pyramidbox_pth_postprocess.py b/ACL_PyTorch/contrib/cv/detection/pyramidbox/pyramidbox_pth_postprocess.py index c6377cec09f9d13b3908137025c972cd33fc547d..6fa423728e0c479d5deed1c4f4b23036af5b51b3 100644 --- a/ACL_PyTorch/contrib/cv/detection/pyramidbox/pyramidbox_pth_postprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/pyramidbox/pyramidbox_pth_postprocess.py @@ -1,227 +1,227 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import absolute_import -from __future__ import division - -import sys -import os -import torch -import argparse -import numpy as np -import cv2 -import os.path as osp -import torch.backends.cudnn as cudnn - -from PIL import Image -import scipy.io as sio -from data.config import cfg -from torch.autograd import Variable -from utils.augmentations import to_chw_bgr -from layers.bbox_utils import decode, nms - -parser = argparse.ArgumentParser(description='pyramidbox evaluatuon wider') -parser.add_argument('--thresh', default=0.05, type=float, - help='Final confidence threshold') -args = parser.parse_args() - -use_cuda = torch.cuda.is_available() -if use_cuda: - torch.set_default_tensor_type('torch.cuda.FloatTensor') -else: - torch.set_default_tensor_type('torch.FloatTensor') - -List1 = [] -List2 = [] -root_path = os.getcwd() -def pre_postprocess(i,path): - listt=[] - global t - if i==0: - path = os.path.join(root_path,path) - else: - path = os.path.join(root_path,'result/result2') - File = os.listdir(path) - for file in sorted(File): - Doc = [] #save no-repeated file name - os.chdir(os.path.join(path, file)) - cur_path = os.getcwd() - doc = os.listdir(cur_path) - for document in sorted(doc): - Doc.append(document[0:-6]) #grip end - Doc = list(set(Doc)) #grip repeated element - for ff in sorted(Doc): #deal after sorting - txt_file = np.fromfile(f'{path}/{file}/{ff}_1.bin', dtype=np.float16) - output = torch.tensor(txt_file.reshape(-1,1000,5)) - listt.append(output) - return listt - -def detect_face(img, counter,i): - h, w = img.shape[0], img.shape[1] - min_side = 1280 - scale = max(w, h) / float(min_side) - if i==0: - detections = List1[counter].data - else: - detections = List2[counter].data - detections = detections.cpu().numpy() - det_conf = detections[0, :, 0] - det_xmin = 1280 * detections[0, :, 1] * scale #x1 - det_ymin = 1280 * detections[0, :, 2] * scale #y1 - det_xmax = 1280 * detections[0, :, 3] * scale #x2 - det_ymax = 1280 * detections[0, :, 4] * scale #y2 - det = np.column_stack((det_xmin, det_ymin, det_xmax, det_ymax, det_conf)) - keep_index = np.where(det[:, 4] >= args.thresh)[0] - det = det[keep_index, :] - return det - -def flip_test(image,counter,i): - image_f = cv2.flip(image, 1) - det_f = detect_face(image_f,counter,1) - - det_t = np.zeros(det_f.shape) - det_t[:, 0] = image.shape[1] - det_f[:, 2] - det_t[:, 1] = det_f[:, 1] - det_t[:, 2] = image.shape[1] - det_f[:, 0] - det_t[:, 3] = det_f[:, 3] - det_t[:, 4] = det_f[:, 4] - return det_t - -def multi_scale_test(image, max_im_shrink,counter,i): - # shrink detecting and shrink only detect big face - st = 0.5 if max_im_shrink >= 0.75 else 0.5 * max_im_shrink - det_s = detect_face(image,counter,i) - index = np.where(np.maximum( - det_s[:, 2] - det_s[:, 0] + 1, det_s[:, 3] - det_s[:, 1] + 1) > 30)[0] - det_s = det_s[index, :] - - # enlarge one times - bt = min(2, max_im_shrink) if max_im_shrink > 1 else ( - st + max_im_shrink) / 2 - det_b = detect_face(image,counter,i) - - - # enlarge only detect small face - if bt > 1: - index = np.where(np.minimum( - det_b[:, 2] - det_b[:, 0] + 1, det_b[:, 3] - det_b[:, 1] + 1) < 100)[0] - det_b = det_b[index, :] - else: - index = np.where(np.maximum( - det_b[:, 2] - det_b[:, 0] + 1, det_b[:, 3] - det_b[:, 1] + 1) > 30)[0] - det_b = det_b[index, :] - - return det_s, det_b - -def bbox_vote(det): - order = det[:, 4].ravel().argsort()[::-1] - det = det[order, :] - while det.shape[0] > 0: - # IOU - area = (det[:, 2] - det[:, 0] + 1) * (det[:, 3] - det[:, 1] + 1) - xx1 = np.maximum(det[0, 0], det[:, 0]) - yy1 = np.maximum(det[0, 1], det[:, 1]) - xx2 = np.minimum(det[0, 2], det[:, 2]) - yy2 = np.minimum(det[0, 3], det[:, 3]) - w = np.maximum(0.0, xx2 - xx1 + 1) - h = np.maximum(0.0, yy2 - yy1 + 1) - inter = w * h - o = inter / (area[0] + area[:] - inter) - # get needed merge det and delete these det - merge_index = np.where(o >= 0.3)[0] - det_accu = det[merge_index, :] - det = np.delete(det, merge_index, 0) - - if merge_index.shape[0] <= 1: - continue - det_accu[:, 0:4] = det_accu[:, 0:4] * np.tile(det_accu[:, -1:], (1, 4)) - max_score = np.max(det_accu[:, 4]) - det_accu_sum = np.zeros((1, 5)) - det_accu_sum[:, 0:4] = np.sum( - det_accu[:, 0:4], axis=0) / np.sum(det_accu[:, -1:]) - det_accu_sum[:, 4] = max_score - - try: - dets = np.row_stack((dets, det_accu_sum)) - except: - dets = det_accu_sum - dets = dets[0:750, :] - return dets - -if __name__ == '__main__': - #mat_path = os.path.abspath(sys.argv[1]) #mat path './evaluate/ground_truth/wider_face_val.mat' - #img_path = os.path.abspath(sys.argv[2]) #image path './images' - #save_path = os.path.abspath(sys.argv[3]) #save path './output_0.01/widerface/' - #path1 = os.path.abspath(sys.argv[4]) #first data ---> result './result1/result1' - #path2 = os.path.abspath(sys.argv[5]) #second data ---> result './result2/result2' - wider_face = sio.loadmat('./evaluate/ground_truth/wider_face_val.mat') - event_list = wider_face['event_list'] - file_list = wider_face['file_list'] - del wider_face - imgs_path = root_path+'/images' - save_path = root_path+'/output_1000' - counter = 0 - if use_cuda: - cudnn.benckmark = True - path1 = './result/result1' - path2 = './result/result2/result2' - List1 = pre_postprocess(0,path1) - List2 = pre_postprocess(1,path2) - print(List1) - print(len(List1)) - print('-----------------------------------------------') - print(len(List2)) - print(List2) - i=0 - for index, event in enumerate(sorted(event_list)): - filelist = file_list[index][0] - path = os.path.join(save_path, str(event[0][0])) - if not os.path.exists(path): - os.makedirs(path) - i = i+1 - for num, file in enumerate(sorted(filelist)): - im_name = file[0][0] - print(im_name) - in_file = os.path.join(imgs_path, event[0][0], str(im_name[:]) + '.jpg') - img = Image.open(in_file) - if img.mode == 'L': - img = img.convert('RGB') - img = np.array(img) - max_im_shrink = np.sqrt( - 1700 * 1000 / (img.shape[0] * img.shape[1])) - shrink = max_im_shrink if max_im_shrink < 1 else 1 - counter += 1 - det0 = detect_face(img,counter-1,0) - - det1 = flip_test(img,counter-1,1) # flip test - [det2, det3] = multi_scale_test( img, max_im_shrink,counter-1,0) - - det = np.row_stack((det0, det1, det2, det3)) - if det.shape[0] ==1: - dets =det - else: - dets = bbox_vote(det) - - fout = open(osp.join(save_path, str(event[0][ - 0]), im_name + '.txt'), 'w') - fout.write('{:s}\n'.format(str(event[0][0]) + '/' + im_name + '.jpg')) - fout.write('{:d}\n'.format(dets.shape[0])) - for i in range(dets.shape[0]): - xmin = dets[i][0] - ymin = dets[i][1] - xmax = dets[i][2] - ymax = dets[i][3] - score = dets[i][4] - fout.write('{:.1f} {:.1f} {:.1f} {:.1f} {:.3f}\n'. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import +from __future__ import division + +import sys +import os +import torch +import argparse +import numpy as np +import cv2 +import os.path as osp +import torch.backends.cudnn as cudnn + +from PIL import Image +import scipy.io as sio +from data.config import cfg +from torch.autograd import Variable +from utils.augmentations import to_chw_bgr +from layers.bbox_utils import decode, nms + +parser = argparse.ArgumentParser(description='pyramidbox evaluatuon wider') +parser.add_argument('--thresh', default=0.05, type=float, + help='Final confidence threshold') +args = parser.parse_args() + +use_cuda = torch.cuda.is_available() +if use_cuda: + torch.set_default_tensor_type('torch.cuda.FloatTensor') +else: + torch.set_default_tensor_type('torch.FloatTensor') + +List1 = [] +List2 = [] +root_path = os.getcwd() +def pre_postprocess(i,path): + listt=[] + global t + if i==0: + path = os.path.join(root_path,path) + else: + path = os.path.join(root_path,'result/result2') + File = os.listdir(path) + for file in sorted(File): + Doc = [] #save no-repeated file name + os.chdir(os.path.join(path, file)) + cur_path = os.getcwd() + doc = os.listdir(cur_path) + for document in sorted(doc): + Doc.append(document[0:-6]) #grip end + Doc = list(set(Doc)) #grip repeated element + for ff in sorted(Doc): #deal after sorting + txt_file = np.fromfile(f'{path}/{file}/{ff}_1.bin', dtype=np.float16) + output = torch.tensor(txt_file.reshape(-1,1000,5)) + listt.append(output) + return listt + +def detect_face(img, counter,i): + h, w = img.shape[0], img.shape[1] + min_side = 1280 + scale = max(w, h) / float(min_side) + if i==0: + detections = List1[counter].data + else: + detections = List2[counter].data + detections = detections.cpu().numpy() + det_conf = detections[0, :, 0] + det_xmin = 1280 * detections[0, :, 1] * scale #x1 + det_ymin = 1280 * detections[0, :, 2] * scale #y1 + det_xmax = 1280 * detections[0, :, 3] * scale #x2 + det_ymax = 1280 * detections[0, :, 4] * scale #y2 + det = np.column_stack((det_xmin, det_ymin, det_xmax, det_ymax, det_conf)) + keep_index = np.where(det[:, 4] >= args.thresh)[0] + det = det[keep_index, :] + return det + +def flip_test(image,counter,i): + image_f = cv2.flip(image, 1) + det_f = detect_face(image_f,counter,1) + + det_t = np.zeros(det_f.shape) + det_t[:, 0] = image.shape[1] - det_f[:, 2] + det_t[:, 1] = det_f[:, 1] + det_t[:, 2] = image.shape[1] - det_f[:, 0] + det_t[:, 3] = det_f[:, 3] + det_t[:, 4] = det_f[:, 4] + return det_t + +def multi_scale_test(image, max_im_shrink,counter,i): + # shrink detecting and shrink only detect big face + st = 0.5 if max_im_shrink >= 0.75 else 0.5 * max_im_shrink + det_s = detect_face(image,counter,i) + index = np.where(np.maximum( + det_s[:, 2] - det_s[:, 0] + 1, det_s[:, 3] - det_s[:, 1] + 1) > 30)[0] + det_s = det_s[index, :] + + # enlarge one times + bt = min(2, max_im_shrink) if max_im_shrink > 1 else ( + st + max_im_shrink) / 2 + det_b = detect_face(image,counter,i) + + + # enlarge only detect small face + if bt > 1: + index = np.where(np.minimum( + det_b[:, 2] - det_b[:, 0] + 1, det_b[:, 3] - det_b[:, 1] + 1) < 100)[0] + det_b = det_b[index, :] + else: + index = np.where(np.maximum( + det_b[:, 2] - det_b[:, 0] + 1, det_b[:, 3] - det_b[:, 1] + 1) > 30)[0] + det_b = det_b[index, :] + + return det_s, det_b + +def bbox_vote(det): + order = det[:, 4].ravel().argsort()[::-1] + det = det[order, :] + while det.shape[0] > 0: + # IOU + area = (det[:, 2] - det[:, 0] + 1) * (det[:, 3] - det[:, 1] + 1) + xx1 = np.maximum(det[0, 0], det[:, 0]) + yy1 = np.maximum(det[0, 1], det[:, 1]) + xx2 = np.minimum(det[0, 2], det[:, 2]) + yy2 = np.minimum(det[0, 3], det[:, 3]) + w = np.maximum(0.0, xx2 - xx1 + 1) + h = np.maximum(0.0, yy2 - yy1 + 1) + inter = w * h + o = inter / (area[0] + area[:] - inter) + # get needed merge det and delete these det + merge_index = np.where(o >= 0.3)[0] + det_accu = det[merge_index, :] + det = np.delete(det, merge_index, 0) + + if merge_index.shape[0] <= 1: + continue + det_accu[:, 0:4] = det_accu[:, 0:4] * np.tile(det_accu[:, -1:], (1, 4)) + max_score = np.max(det_accu[:, 4]) + det_accu_sum = np.zeros((1, 5)) + det_accu_sum[:, 0:4] = np.sum( + det_accu[:, 0:4], axis=0) / np.sum(det_accu[:, -1:]) + det_accu_sum[:, 4] = max_score + + try: + dets = np.row_stack((dets, det_accu_sum)) + except: + dets = det_accu_sum + dets = dets[0:750, :] + return dets + +if __name__ == '__main__': + #mat_path = os.path.abspath(sys.argv[1]) #mat path './evaluate/ground_truth/wider_face_val.mat' + #img_path = os.path.abspath(sys.argv[2]) #image path './images' + #save_path = os.path.abspath(sys.argv[3]) #save path './output_0.01/widerface/' + #path1 = os.path.abspath(sys.argv[4]) #first data ---> result './result1/result1' + #path2 = os.path.abspath(sys.argv[5]) #second data ---> result './result2/result2' + wider_face = sio.loadmat('./evaluate/ground_truth/wider_face_val.mat') + event_list = wider_face['event_list'] + file_list = wider_face['file_list'] + del wider_face + imgs_path = root_path+'/images' + save_path = root_path+'/output_1000' + counter = 0 + if use_cuda: + cudnn.benckmark = True + path1 = './result/result1' + path2 = './result/result2/result2' + List1 = pre_postprocess(0,path1) + List2 = pre_postprocess(1,path2) + print(List1) + print(len(List1)) + print('-----------------------------------------------') + print(len(List2)) + print(List2) + i=0 + for index, event in enumerate(sorted(event_list)): + filelist = file_list[index][0] + path = os.path.join(save_path, str(event[0][0])) + if not os.path.exists(path): + os.makedirs(path) + i = i+1 + for num, file in enumerate(sorted(filelist)): + im_name = file[0][0] + print(im_name) + in_file = os.path.join(imgs_path, event[0][0], str(im_name[:]) + '.jpg') + img = Image.open(in_file) + if img.mode == 'L': + img = img.convert('RGB') + img = np.array(img) + max_im_shrink = np.sqrt( + 1700 * 1000 / (img.shape[0] * img.shape[1])) + shrink = max_im_shrink if max_im_shrink < 1 else 1 + counter += 1 + det0 = detect_face(img,counter-1,0) + + det1 = flip_test(img,counter-1,1) # flip test + [det2, det3] = multi_scale_test( img, max_im_shrink,counter-1,0) + + det = np.row_stack((det0, det1, det2, det3)) + if det.shape[0] ==1: + dets =det + else: + dets = bbox_vote(det) + + fout = open(osp.join(save_path, str(event[0][ + 0]), im_name + '.txt'), 'w') + fout.write('{:s}\n'.format(str(event[0][0]) + '/' + im_name + '.jpg')) + fout.write('{:d}\n'.format(dets.shape[0])) + for i in range(dets.shape[0]): + xmin = dets[i][0] + ymin = dets[i][1] + xmax = dets[i][2] + ymax = dets[i][3] + score = dets[i][4] + fout.write('{:.1f} {:.1f} {:.1f} {:.1f} {:.3f}\n'. format(xmin, ymin, (xmax - xmin + 1), (ymax - ymin + 1), score)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/detection/pyramidbox/pyramidbox_pth_preprocess.py b/ACL_PyTorch/contrib/cv/detection/pyramidbox/pyramidbox_pth_preprocess.py index e844307d8d497f6498049849e46e7657b519097b..d70c40747f5d508e97a30b999b521dde46efdf5e 100644 --- a/ACL_PyTorch/contrib/cv/detection/pyramidbox/pyramidbox_pth_preprocess.py +++ b/ACL_PyTorch/contrib/cv/detection/pyramidbox/pyramidbox_pth_preprocess.py @@ -1,109 +1,109 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import absolute_import -from __future__ import division - -import sys -import os -import torch -import numpy as np -import cv2 - -from PIL import Image -from data.config import cfg -from torch.autograd import Variable -from utils.augmentations import to_chw_bgr - -use_cuda = torch.cuda.is_available() - -if use_cuda: - torch.set_default_tensor_type('torch.cuda.FloatTensor') -else: - torch.set_default_tensor_type('torch.FloatTensor') - -def process_image(img, min_side): - h, w = img.shape[0], img.shape[1] - #长边缩放为min_side - scale = max(w, h) / float(min_side) - new_w, new_h = int(w/scale), int(h/scale) - resize_img = cv2.resize(img, (new_w, new_h)) - # 填充至min_side * min_side - bottom = min_side-new_h - right = min_side-new_w - img = cv2.copyMakeBorder(resize_img, 0, int(bottom), 0, int(right), cv2.BORDER_CONSTANT, value=[0,0,0]) #从图像边界向上,下,左,右扩的像素数目 - return img - -def preprocess(file_path, bin_path): - in_files = os.listdir(file_path) - if not os.path.exists(bin_path): - os.makedirs(bin_path) - for file in sorted(in_files): - os.chdir(os.path.join(file_path, file)) - cur_path = os.getcwd() - doc = os.listdir(cur_path) - for document in sorted(doc): - in_file = os.path.join(cur_path, document) - img = Image.open(in_file) - if img.mode == 'L': - img = img.convert('RGB') - img = np.array(img) - img = process_image(img,1000) #对图片进行放缩加padding - x = to_chw_bgr(img) - - x = x.astype('float32') - x -= cfg.img_mean - x = x[[2, 1, 0], :, :] - x = Variable(torch.from_numpy(x).unsqueeze(0)) - if use_cuda: - x = x.cuda() - if not os.path.exists(os.path.join(bin_path,file)): - os.makedirs(os.path.join(bin_path,file)) - des_path = os.path.join(bin_path,file) - x.numpy().tofile(os.path.join(des_path,document.split('.')[0] +'.bin')) - -def preprocess1(file_path, bin_path): - in_files = os.listdir(file_path) - if not os.path.exists(bin_path): - os.makedirs(bin_path) - for file in sorted(in_files): - os.chdir(os.path.join(file_path, file)) - cur_path = os.getcwd() - doc = os.listdir(cur_path) - for document in sorted(doc): - in_file = os.path.join(cur_path, document) - img = Image.open(in_file) - if img.mode == 'L': - img = img.convert('RGB') - img = np.array(img) - img = cv2.flip(img, 1) - img = process_image(img,1000) - x = to_chw_bgr(img) - x = x.astype('float32') - x -= cfg.img_mean - x = x[[2, 1, 0], :, :] - x = Variable(torch.from_numpy(x).unsqueeze(0)) - if use_cuda: - x = x.cuda() - if not os.path.exists(os.path.join(bin_path,file)): - os.makedirs(os.path.join(bin_path,file)) - des_path = os.path.join(bin_path,file) - x.numpy().tofile(os.path.join(des_path,document.split('.')[0] +'.bin')) - -if __name__ == "__main__": - file_path = os.path.abspath(sys.argv[1]) - bin_path1 = os.path.abspath(sys.argv[2]) - bin_path2 = os.path.abspath(sys.argv[3]) - preprocess(file_path, bin_path1) - preprocess1(file_path, bin_path2) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import +from __future__ import division + +import sys +import os +import torch +import numpy as np +import cv2 + +from PIL import Image +from data.config import cfg +from torch.autograd import Variable +from utils.augmentations import to_chw_bgr + +use_cuda = torch.cuda.is_available() + +if use_cuda: + torch.set_default_tensor_type('torch.cuda.FloatTensor') +else: + torch.set_default_tensor_type('torch.FloatTensor') + +def process_image(img, min_side): + h, w = img.shape[0], img.shape[1] + #长边缩放为min_side + scale = max(w, h) / float(min_side) + new_w, new_h = int(w/scale), int(h/scale) + resize_img = cv2.resize(img, (new_w, new_h)) + # 填充至min_side * min_side + bottom = min_side-new_h + right = min_side-new_w + img = cv2.copyMakeBorder(resize_img, 0, int(bottom), 0, int(right), cv2.BORDER_CONSTANT, value=[0,0,0]) #从图像边界向上,下,左,右扩的像素数目 + return img + +def preprocess(file_path, bin_path): + in_files = os.listdir(file_path) + if not os.path.exists(bin_path): + os.makedirs(bin_path) + for file in sorted(in_files): + os.chdir(os.path.join(file_path, file)) + cur_path = os.getcwd() + doc = os.listdir(cur_path) + for document in sorted(doc): + in_file = os.path.join(cur_path, document) + img = Image.open(in_file) + if img.mode == 'L': + img = img.convert('RGB') + img = np.array(img) + img = process_image(img,1000) #对图片进行放缩加padding + x = to_chw_bgr(img) + + x = x.astype('float32') + x -= cfg.img_mean + x = x[[2, 1, 0], :, :] + x = Variable(torch.from_numpy(x).unsqueeze(0)) + if use_cuda: + x = x.cuda() + if not os.path.exists(os.path.join(bin_path,file)): + os.makedirs(os.path.join(bin_path,file)) + des_path = os.path.join(bin_path,file) + x.numpy().tofile(os.path.join(des_path,document.split('.')[0] +'.bin')) + +def preprocess1(file_path, bin_path): + in_files = os.listdir(file_path) + if not os.path.exists(bin_path): + os.makedirs(bin_path) + for file in sorted(in_files): + os.chdir(os.path.join(file_path, file)) + cur_path = os.getcwd() + doc = os.listdir(cur_path) + for document in sorted(doc): + in_file = os.path.join(cur_path, document) + img = Image.open(in_file) + if img.mode == 'L': + img = img.convert('RGB') + img = np.array(img) + img = cv2.flip(img, 1) + img = process_image(img,1000) + x = to_chw_bgr(img) + x = x.astype('float32') + x -= cfg.img_mean + x = x[[2, 1, 0], :, :] + x = Variable(torch.from_numpy(x).unsqueeze(0)) + if use_cuda: + x = x.cuda() + if not os.path.exists(os.path.join(bin_path,file)): + os.makedirs(os.path.join(bin_path,file)) + des_path = os.path.join(bin_path,file) + x.numpy().tofile(os.path.join(des_path,document.split('.')[0] +'.bin')) + +if __name__ == "__main__": + file_path = os.path.abspath(sys.argv[1]) + bin_path1 = os.path.abspath(sys.argv[2]) + bin_path2 = os.path.abspath(sys.argv[3]) + preprocess(file_path, bin_path1) + preprocess1(file_path, bin_path2) diff --git a/ACL_PyTorch/contrib/cv/face/AlignedReID/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/face/AlignedReID/modelzoo_level.txt index 9e95396651cc4382fe60ee1ee053674f527a448c..27e6c78b37535fe4f5a17029546fe257ad164d34 100644 --- a/ACL_PyTorch/contrib/cv/face/AlignedReID/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/face/AlignedReID/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:POK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/face/FaceNet/FaceNet_postprocess.py b/ACL_PyTorch/contrib/cv/face/FaceNet/FaceNet_postprocess.py index c3d5cb168e902d263b9c380d75eefddd7f346977..af7e9d1533fc6e8935ea73ce7f786a5d33ab345c 100644 --- a/ACL_PyTorch/contrib/cv/face/FaceNet/FaceNet_postprocess.py +++ b/ACL_PyTorch/contrib/cv/face/FaceNet/FaceNet_postprocess.py @@ -1,231 +1,231 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import argparse -import os -import sys -import json -import math -import numpy as np -from tqdm import tqdm -from scipy import interpolate -from sklearn.model_selection import KFold -from FaceNet_preprocess import read_pairs - - -def load_json(json_path): - with open(json_path) as f: - return json.load(f) - - -def add_extension(path): - if os.path.exists(path+'.jpg'): - return path+'.jpg' - elif os.path.exists(path+'.png'): - return path+'.png' - else: - raise RuntimeError('No file "%s" with extension png or jpg.' % path) - - -def get_paths(lfw_dir, pairs): - nrof_skipped_pairs = 0 - path_list = [] - issame_list = [] - for pair in pairs: - if len(pair) == 3: - path0 = add_extension(os.path.join(lfw_dir, pair[0], pair[0] + '_' + '%04d' % int(pair[1]))) - path1 = add_extension(os.path.join(lfw_dir, pair[0], pair[0] + '_' + '%04d' % int(pair[2]))) - issame = True - elif len(pair) == 4: - path0 = add_extension(os.path.join(lfw_dir, pair[0], pair[0] + '_' + '%04d' % int(pair[1]))) - path1 = add_extension(os.path.join(lfw_dir, pair[2], pair[2] + '_' + '%04d' % int(pair[3]))) - issame = False - if os.path.exists(path0) and os.path.exists(path1): # Only add the pair if both paths exist - path_list += (path0, path1) - issame_list.append(issame) - else: - nrof_skipped_pairs += 1 - if nrof_skipped_pairs > 0: - print('Skipped %d image pairs' % nrof_skipped_pairs) - - return path_list, issame_list - - -def face_postprocess(crop_paths, result_dir): - num_bins = len(os.listdir(result_dir)) - embeddings = [] - flag_file = os.path.join(result_dir, "{}_output_0.bin".format(0)) - for idx in tqdm(range(num_bins)): - if not os.path.exists(flag_file): - xb_path = os.path.join(result_dir, "{}_1.bin".format(idx)) - else: - xb_path = os.path.join(result_dir, "{}_output_0.bin".format(idx)) - xb_data = np.fromfile(xb_path, dtype=np.float32).reshape(-1, 512) - embeddings.extend(xb_data) - - embeddings_dict = dict(zip(crop_paths, embeddings)) - return embeddings_dict - - -def evaluate(embeddings, actual_issame, nrof_folds=10, distance_metric=0, subtract_mean=False): - # Calculate evaluation metrics - thresholds = np.arange(0, 4, 0.01) - embeddings1 = embeddings[0::2] - embeddings2 = embeddings[1::2] - tpr, fpr, accuracy, fp, fn = calculate_roc(thresholds, embeddings1, embeddings2, - np.asarray(actual_issame), nrof_folds=nrof_folds, distance_metric=distance_metric, subtract_mean=subtract_mean) - thresholds = np.arange(0, 4, 0.001) - val, val_std, far = calculate_val(thresholds, embeddings1, embeddings2, - np.asarray(actual_issame), 1e-3, nrof_folds=nrof_folds, distance_metric=distance_metric, subtract_mean=subtract_mean) - return tpr, fpr, accuracy, val, val_std, far, fp, fn - - -def calculate_roc(thresholds, embeddings1, embeddings2, actual_issame, nrof_folds=10, distance_metric=0, subtract_mean=False): - assert(embeddings1.shape[0] == embeddings2.shape[0]) - assert(embeddings1.shape[1] == embeddings2.shape[1]) - nrof_pairs = min(len(actual_issame), embeddings1.shape[0]) - nrof_thresholds = len(thresholds) - k_fold = KFold(n_splits=nrof_folds, shuffle=False) - - tprs = np.zeros((nrof_folds,nrof_thresholds)) - fprs = np.zeros((nrof_folds,nrof_thresholds)) - accuracy = np.zeros((nrof_folds)) - - is_false_positive = [] - is_false_negative = [] - - indices = np.arange(nrof_pairs) - - for fold_idx, (train_set, test_set) in enumerate(k_fold.split(indices)): - if subtract_mean: - mean = np.mean(np.concatenate([embeddings1[train_set], embeddings2[train_set]]), axis=0) - else: - mean = 0.0 - dist = distance(embeddings1-mean, embeddings2-mean, distance_metric) - - # Find the best threshold for the fold - acc_train = np.zeros((nrof_thresholds)) - for threshold_idx, threshold in enumerate(thresholds): - _, _, acc_train[threshold_idx], _, _ = calculate_accuracy(threshold, dist[train_set], actual_issame[train_set]) - best_threshold_index = np.argmax(acc_train) - for threshold_idx, threshold in enumerate(thresholds): - tprs[fold_idx, threshold_idx], fprs[fold_idx, threshold_idx], _, _, _ = calculate_accuracy(threshold, dist[test_set], actual_issame[test_set]) - _, _, accuracy[fold_idx], is_fp, is_fn = calculate_accuracy(thresholds[best_threshold_index], dist[test_set], actual_issame[test_set]) - - tpr = np.mean(tprs, 0) - fpr = np.mean(fprs, 0) - is_false_positive.extend(is_fp) - is_false_negative.extend(is_fn) - - return tpr, fpr, accuracy, is_false_positive, is_false_negative - - -def calculate_accuracy(threshold, dist, actual_issame): - predict_issame = np.less(dist, threshold) - tp = np.sum(np.logical_and(predict_issame, actual_issame)) - fp = np.sum(np.logical_and(predict_issame, np.logical_not(actual_issame))) - tn = np.sum(np.logical_and(np.logical_not(predict_issame), np.logical_not(actual_issame))) - fn = np.sum(np.logical_and(np.logical_not(predict_issame), actual_issame)) - - is_fp = np.logical_and(predict_issame, np.logical_not(actual_issame)) - is_fn = np.logical_and(np.logical_not(predict_issame), actual_issame) - - tpr = 0 if (tp + fn == 0) else float(tp) / float(tp+fn) - fpr = 0 if (fp + tn == 0) else float(fp) / float(fp+tn) - acc = float(tp+tn)/dist.size - return tpr, fpr, acc, is_fp, is_fn - - -def calculate_val(thresholds, embeddings1, embeddings2, actual_issame, far_target, nrof_folds=10, distance_metric=0, subtract_mean=False): - assert(embeddings1.shape[0] == embeddings2.shape[0]) - assert(embeddings1.shape[1] == embeddings2.shape[1]) - nrof_pairs = min(len(actual_issame), embeddings1.shape[0]) - nrof_thresholds = len(thresholds) - k_fold = KFold(n_splits=nrof_folds, shuffle=False) - - val = np.zeros(nrof_folds) - far = np.zeros(nrof_folds) - - indices = np.arange(nrof_pairs) - - for fold_idx, (train_set, test_set) in enumerate(k_fold.split(indices)): - if subtract_mean: - mean = np.mean(np.concatenate([embeddings1[train_set], embeddings2[train_set]]), axis=0) - else: - mean = 0.0 - dist = distance(embeddings1-mean, embeddings2-mean, distance_metric) - - # Find the threshold that gives FAR = far_target - far_train = np.zeros(nrof_thresholds) - for threshold_idx, threshold in enumerate(thresholds): - _, far_train[threshold_idx] = calculate_val_far(threshold, dist[train_set], actual_issame[train_set]) - if np.max(far_train)>=far_target: - f = interpolate.interp1d(far_train, thresholds, kind='slinear') - threshold = f(far_target) - else: - threshold = 0.0 - - val[fold_idx], far[fold_idx] = calculate_val_far(threshold, dist[test_set], actual_issame[test_set]) - - val_mean = np.mean(val) - far_mean = np.mean(far) - val_std = np.std(val) - return val_mean, val_std, far_mean - - -def distance(embeddings1, embeddings2, distance_metric=0): - if distance_metric==0: - # Euclidian distance - diff = np.subtract(embeddings1, embeddings2) - dist = np.sum(np.square(diff),1) - elif distance_metric==1: - # Distance based on cosine similarity - dot = np.sum(np.multiply(embeddings1, embeddings2), axis=1) - norm = np.linalg.norm(embeddings1, axis=1) * np.linalg.norm(embeddings2, axis=1) - similarity = dot / norm - dist = np.arccos(similarity) / math.pi - else: - raise 'Undefined distance metric %d' % distance_metric - - return dist - - -def calculate_val_far(threshold, dist, actual_issame): - predict_issame = np.less(dist, threshold) - true_accept = np.sum(np.logical_and(predict_issame, actual_issame)) - false_accept = np.sum(np.logical_and(predict_issame, np.logical_not(actual_issame))) - n_same = np.sum(actual_issame) - n_diff = np.sum(np.logical_not(actual_issame)) - val = float(true_accept) / float(n_same) - far = float(false_accept) / float(n_diff) - return val, far - - -if __name__ == '__main__': - pairs_path = './data/pairs.txt' - parser = argparse.ArgumentParser() - parser.add_argument('--crop_dir', type=str, help='cropped image save path') - parser.add_argument('--test_dir', type=str, help='test file path') - parser.add_argument('--ONet_output_dir', type=str, help='preprocess bin files save path') - arg = parser.parse_args() - embedding_output_path = arg.test_dir - pairs = read_pairs(pairs_path) - crop_paths = load_json(arg.ONet_output_dir) - crop_dir = arg.crop_dir - path_list, _ = get_paths(crop_dir, pairs) - embeddings_dict = face_postprocess(crop_paths, embedding_output_path) - embeddings = np.array([embeddings_dict['./' + os.path.relpath(path)] for path in path_list]) - path_list, issame_list = get_paths(crop_dir, pairs) - tpr, fpr, accuracy, val, val_std, far, fp, fn = evaluate(embeddings, issame_list) - print("accuracy:", accuracy) - print("mean accuracy:", np.mean(accuracy)) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import argparse +import os +import sys +import json +import math +import numpy as np +from tqdm import tqdm +from scipy import interpolate +from sklearn.model_selection import KFold +from FaceNet_preprocess import read_pairs + + +def load_json(json_path): + with open(json_path) as f: + return json.load(f) + + +def add_extension(path): + if os.path.exists(path+'.jpg'): + return path+'.jpg' + elif os.path.exists(path+'.png'): + return path+'.png' + else: + raise RuntimeError('No file "%s" with extension png or jpg.' % path) + + +def get_paths(lfw_dir, pairs): + nrof_skipped_pairs = 0 + path_list = [] + issame_list = [] + for pair in pairs: + if len(pair) == 3: + path0 = add_extension(os.path.join(lfw_dir, pair[0], pair[0] + '_' + '%04d' % int(pair[1]))) + path1 = add_extension(os.path.join(lfw_dir, pair[0], pair[0] + '_' + '%04d' % int(pair[2]))) + issame = True + elif len(pair) == 4: + path0 = add_extension(os.path.join(lfw_dir, pair[0], pair[0] + '_' + '%04d' % int(pair[1]))) + path1 = add_extension(os.path.join(lfw_dir, pair[2], pair[2] + '_' + '%04d' % int(pair[3]))) + issame = False + if os.path.exists(path0) and os.path.exists(path1): # Only add the pair if both paths exist + path_list += (path0, path1) + issame_list.append(issame) + else: + nrof_skipped_pairs += 1 + if nrof_skipped_pairs > 0: + print('Skipped %d image pairs' % nrof_skipped_pairs) + + return path_list, issame_list + + +def face_postprocess(crop_paths, result_dir): + num_bins = len(os.listdir(result_dir)) + embeddings = [] + flag_file = os.path.join(result_dir, "{}_output_0.bin".format(0)) + for idx in tqdm(range(num_bins)): + if not os.path.exists(flag_file): + xb_path = os.path.join(result_dir, "{}_1.bin".format(idx)) + else: + xb_path = os.path.join(result_dir, "{}_output_0.bin".format(idx)) + xb_data = np.fromfile(xb_path, dtype=np.float32).reshape(-1, 512) + embeddings.extend(xb_data) + + embeddings_dict = dict(zip(crop_paths, embeddings)) + return embeddings_dict + + +def evaluate(embeddings, actual_issame, nrof_folds=10, distance_metric=0, subtract_mean=False): + # Calculate evaluation metrics + thresholds = np.arange(0, 4, 0.01) + embeddings1 = embeddings[0::2] + embeddings2 = embeddings[1::2] + tpr, fpr, accuracy, fp, fn = calculate_roc(thresholds, embeddings1, embeddings2, + np.asarray(actual_issame), nrof_folds=nrof_folds, distance_metric=distance_metric, subtract_mean=subtract_mean) + thresholds = np.arange(0, 4, 0.001) + val, val_std, far = calculate_val(thresholds, embeddings1, embeddings2, + np.asarray(actual_issame), 1e-3, nrof_folds=nrof_folds, distance_metric=distance_metric, subtract_mean=subtract_mean) + return tpr, fpr, accuracy, val, val_std, far, fp, fn + + +def calculate_roc(thresholds, embeddings1, embeddings2, actual_issame, nrof_folds=10, distance_metric=0, subtract_mean=False): + assert(embeddings1.shape[0] == embeddings2.shape[0]) + assert(embeddings1.shape[1] == embeddings2.shape[1]) + nrof_pairs = min(len(actual_issame), embeddings1.shape[0]) + nrof_thresholds = len(thresholds) + k_fold = KFold(n_splits=nrof_folds, shuffle=False) + + tprs = np.zeros((nrof_folds,nrof_thresholds)) + fprs = np.zeros((nrof_folds,nrof_thresholds)) + accuracy = np.zeros((nrof_folds)) + + is_false_positive = [] + is_false_negative = [] + + indices = np.arange(nrof_pairs) + + for fold_idx, (train_set, test_set) in enumerate(k_fold.split(indices)): + if subtract_mean: + mean = np.mean(np.concatenate([embeddings1[train_set], embeddings2[train_set]]), axis=0) + else: + mean = 0.0 + dist = distance(embeddings1-mean, embeddings2-mean, distance_metric) + + # Find the best threshold for the fold + acc_train = np.zeros((nrof_thresholds)) + for threshold_idx, threshold in enumerate(thresholds): + _, _, acc_train[threshold_idx], _, _ = calculate_accuracy(threshold, dist[train_set], actual_issame[train_set]) + best_threshold_index = np.argmax(acc_train) + for threshold_idx, threshold in enumerate(thresholds): + tprs[fold_idx, threshold_idx], fprs[fold_idx, threshold_idx], _, _, _ = calculate_accuracy(threshold, dist[test_set], actual_issame[test_set]) + _, _, accuracy[fold_idx], is_fp, is_fn = calculate_accuracy(thresholds[best_threshold_index], dist[test_set], actual_issame[test_set]) + + tpr = np.mean(tprs, 0) + fpr = np.mean(fprs, 0) + is_false_positive.extend(is_fp) + is_false_negative.extend(is_fn) + + return tpr, fpr, accuracy, is_false_positive, is_false_negative + + +def calculate_accuracy(threshold, dist, actual_issame): + predict_issame = np.less(dist, threshold) + tp = np.sum(np.logical_and(predict_issame, actual_issame)) + fp = np.sum(np.logical_and(predict_issame, np.logical_not(actual_issame))) + tn = np.sum(np.logical_and(np.logical_not(predict_issame), np.logical_not(actual_issame))) + fn = np.sum(np.logical_and(np.logical_not(predict_issame), actual_issame)) + + is_fp = np.logical_and(predict_issame, np.logical_not(actual_issame)) + is_fn = np.logical_and(np.logical_not(predict_issame), actual_issame) + + tpr = 0 if (tp + fn == 0) else float(tp) / float(tp+fn) + fpr = 0 if (fp + tn == 0) else float(fp) / float(fp+tn) + acc = float(tp+tn)/dist.size + return tpr, fpr, acc, is_fp, is_fn + + +def calculate_val(thresholds, embeddings1, embeddings2, actual_issame, far_target, nrof_folds=10, distance_metric=0, subtract_mean=False): + assert(embeddings1.shape[0] == embeddings2.shape[0]) + assert(embeddings1.shape[1] == embeddings2.shape[1]) + nrof_pairs = min(len(actual_issame), embeddings1.shape[0]) + nrof_thresholds = len(thresholds) + k_fold = KFold(n_splits=nrof_folds, shuffle=False) + + val = np.zeros(nrof_folds) + far = np.zeros(nrof_folds) + + indices = np.arange(nrof_pairs) + + for fold_idx, (train_set, test_set) in enumerate(k_fold.split(indices)): + if subtract_mean: + mean = np.mean(np.concatenate([embeddings1[train_set], embeddings2[train_set]]), axis=0) + else: + mean = 0.0 + dist = distance(embeddings1-mean, embeddings2-mean, distance_metric) + + # Find the threshold that gives FAR = far_target + far_train = np.zeros(nrof_thresholds) + for threshold_idx, threshold in enumerate(thresholds): + _, far_train[threshold_idx] = calculate_val_far(threshold, dist[train_set], actual_issame[train_set]) + if np.max(far_train)>=far_target: + f = interpolate.interp1d(far_train, thresholds, kind='slinear') + threshold = f(far_target) + else: + threshold = 0.0 + + val[fold_idx], far[fold_idx] = calculate_val_far(threshold, dist[test_set], actual_issame[test_set]) + + val_mean = np.mean(val) + far_mean = np.mean(far) + val_std = np.std(val) + return val_mean, val_std, far_mean + + +def distance(embeddings1, embeddings2, distance_metric=0): + if distance_metric==0: + # Euclidian distance + diff = np.subtract(embeddings1, embeddings2) + dist = np.sum(np.square(diff),1) + elif distance_metric==1: + # Distance based on cosine similarity + dot = np.sum(np.multiply(embeddings1, embeddings2), axis=1) + norm = np.linalg.norm(embeddings1, axis=1) * np.linalg.norm(embeddings2, axis=1) + similarity = dot / norm + dist = np.arccos(similarity) / math.pi + else: + raise 'Undefined distance metric %d' % distance_metric + + return dist + + +def calculate_val_far(threshold, dist, actual_issame): + predict_issame = np.less(dist, threshold) + true_accept = np.sum(np.logical_and(predict_issame, actual_issame)) + false_accept = np.sum(np.logical_and(predict_issame, np.logical_not(actual_issame))) + n_same = np.sum(actual_issame) + n_diff = np.sum(np.logical_not(actual_issame)) + val = float(true_accept) / float(n_same) + far = float(false_accept) / float(n_diff) + return val, far + + +if __name__ == '__main__': + pairs_path = './data/pairs.txt' + parser = argparse.ArgumentParser() + parser.add_argument('--crop_dir', type=str, help='cropped image save path') + parser.add_argument('--test_dir', type=str, help='test file path') + parser.add_argument('--ONet_output_dir', type=str, help='preprocess bin files save path') + arg = parser.parse_args() + embedding_output_path = arg.test_dir + pairs = read_pairs(pairs_path) + crop_paths = load_json(arg.ONet_output_dir) + crop_dir = arg.crop_dir + path_list, _ = get_paths(crop_dir, pairs) + embeddings_dict = face_postprocess(crop_paths, embedding_output_path) + embeddings = np.array([embeddings_dict['./' + os.path.relpath(path)] for path in path_list]) + path_list, issame_list = get_paths(crop_dir, pairs) + tpr, fpr, accuracy, val, val_std, far, fp, fn = evaluate(embeddings, issame_list) + print("accuracy:", accuracy) + print("mean accuracy:", np.mean(accuracy)) diff --git a/ACL_PyTorch/contrib/cv/face/FaceNet/FaceNet_preprocess.py b/ACL_PyTorch/contrib/cv/face/FaceNet/FaceNet_preprocess.py index 64a7a3aeedf856a1fa1446402c82f76d4c48aa35..fe26bba8c912ded7a8a35c2be6d7982276f96f99 100644 --- a/ACL_PyTorch/contrib/cv/face/FaceNet/FaceNet_preprocess.py +++ b/ACL_PyTorch/contrib/cv/face/FaceNet/FaceNet_preprocess.py @@ -1,73 +1,73 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import argparse -import sys -import os -import torch -import numpy as np -from tqdm import tqdm -from torchvision import datasets, transforms -from facenet_pytorch import fixed_image_standardization -from torch.utils.data import DataLoader, SequentialSampler - - -def read_pairs(pairs_filename): - pairs = [] - with open(pairs_filename, 'r') as f: - for line in f.readlines()[1:]: - pair = line.strip().split() - pairs.append(pair) - return np.array(pairs, dtype=object) - - -def face_preprocess(crop_dir, save_dir): - # create dataset and data loaders from cropped images output from MTCNN - trans = transforms.Compose([ - np.float32, - transforms.ToTensor(), - fixed_image_standardization - ]) - dataset = datasets.ImageFolder(crop_dir, transform=trans) - - embed_loader = DataLoader( - dataset, - num_workers=workers, - batch_size=batch_size, - sampler=SequentialSampler(dataset) - ) - - for idx, (xb, yb) in tqdm(enumerate(embed_loader)): - out_path_xb = os.path.join(save_dir, 'xb_results', '{}.bin'.format(idx)) - out_path_yb = os.path.join(save_dir, 'yb_results', '{}.bin'.format(idx)) - os.makedirs(os.path.dirname(out_path_xb), exist_ok=True) - os.makedirs(os.path.dirname(out_path_yb), exist_ok=True) - if xb.shape[0] < batch_size: - xb_zeros = np.zeros([batch_size - int(xb.shape[0]), int(xb.shape[1]), int(xb.shape[2]), int(xb.shape[3])]) - xb = np.concatenate([xb.numpy(), xb_zeros], axis=0) - xb = torch.from_numpy(xb) - xb.detach().cpu().numpy().tofile(out_path_xb) - yb.detach().cpu().numpy().tofile(out_path_yb) - - -if __name__ == '__main__': - pairs_path = './data/pairs.txt' - parser = argparse.ArgumentParser() - parser.add_argument('--crop_dir', type=str, help='cropped image save path') - parser.add_argument('--save_dir', type=str, help='preprocess bin files save path') - parser.add_argument('--batch_size', type=int, help='preprocess bin files save path') - arg = parser.parse_args() - batch_size = arg.batch_size - workers = 0 if os.name == 'nt' else 8 - pairs = read_pairs(pairs_path) - face_preprocess(arg.crop_dir, arg.save_dir) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import argparse +import sys +import os +import torch +import numpy as np +from tqdm import tqdm +from torchvision import datasets, transforms +from facenet_pytorch import fixed_image_standardization +from torch.utils.data import DataLoader, SequentialSampler + + +def read_pairs(pairs_filename): + pairs = [] + with open(pairs_filename, 'r') as f: + for line in f.readlines()[1:]: + pair = line.strip().split() + pairs.append(pair) + return np.array(pairs, dtype=object) + + +def face_preprocess(crop_dir, save_dir): + # create dataset and data loaders from cropped images output from MTCNN + trans = transforms.Compose([ + np.float32, + transforms.ToTensor(), + fixed_image_standardization + ]) + dataset = datasets.ImageFolder(crop_dir, transform=trans) + + embed_loader = DataLoader( + dataset, + num_workers=workers, + batch_size=batch_size, + sampler=SequentialSampler(dataset) + ) + + for idx, (xb, yb) in tqdm(enumerate(embed_loader)): + out_path_xb = os.path.join(save_dir, 'xb_results', '{}.bin'.format(idx)) + out_path_yb = os.path.join(save_dir, 'yb_results', '{}.bin'.format(idx)) + os.makedirs(os.path.dirname(out_path_xb), exist_ok=True) + os.makedirs(os.path.dirname(out_path_yb), exist_ok=True) + if xb.shape[0] < batch_size: + xb_zeros = np.zeros([batch_size - int(xb.shape[0]), int(xb.shape[1]), int(xb.shape[2]), int(xb.shape[3])]) + xb = np.concatenate([xb.numpy(), xb_zeros], axis=0) + xb = torch.from_numpy(xb) + xb.detach().cpu().numpy().tofile(out_path_xb) + yb.detach().cpu().numpy().tofile(out_path_yb) + + +if __name__ == '__main__': + pairs_path = './data/pairs.txt' + parser = argparse.ArgumentParser() + parser.add_argument('--crop_dir', type=str, help='cropped image save path') + parser.add_argument('--save_dir', type=str, help='preprocess bin files save path') + parser.add_argument('--batch_size', type=int, help='preprocess bin files save path') + arg = parser.parse_args() + batch_size = arg.batch_size + workers = 0 if os.name == 'nt' else 8 + pairs = read_pairs(pairs_path) + face_preprocess(arg.crop_dir, arg.save_dir) diff --git a/ACL_PyTorch/contrib/cv/face/FaceNet/FaceNet_pth2onnx.py b/ACL_PyTorch/contrib/cv/face/FaceNet/FaceNet_pth2onnx.py index 1d2b916c3c155e3ba83ffb9ad6d36884f5b294f3..6d886b0965533ce75059758fc376e3feb823e3ea 100644 --- a/ACL_PyTorch/contrib/cv/face/FaceNet/FaceNet_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/face/FaceNet/FaceNet_pth2onnx.py @@ -1,46 +1,46 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from facenet_pytorch import InceptionResnetV1 -import torch -import argparse - - -def FaceNet_pth2onnx(opt): - model = InceptionResnetV1(pretrained=opt.pretrain) - # if opt.model != '': - # model.load_state_dict(torch.load(opt.model, map_location='cpu')) - # else: - # print("Error network") - # return -1 - model.eval() - input_names = ["image"] - output_names = ["class"] - output_file = opt.output_file - if opt.output_file == '.': - output_file = opt.output_file - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(16, 3, 160, 160) - - torch.onnx.export(model, dummy_input, output_file, input_names=input_names, dynamic_axes=dynamic_axes, - output_names=output_names, verbose=True, opset_version=10) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--pretrain', type=str, default='vggface2', help='[casia-webface, vggface2]') - parser.add_argument('--model', type=str, help='model path') - parser.add_argument('--output_file', type=str, default='.', help='output path') - arg = parser.parse_args() - FaceNet_pth2onnx(arg) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from facenet_pytorch import InceptionResnetV1 +import torch +import argparse + + +def FaceNet_pth2onnx(opt): + model = InceptionResnetV1(pretrained=opt.pretrain) + # if opt.model != '': + # model.load_state_dict(torch.load(opt.model, map_location='cpu')) + # else: + # print("Error network") + # return -1 + model.eval() + input_names = ["image"] + output_names = ["class"] + output_file = opt.output_file + if opt.output_file == '.': + output_file = opt.output_file + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(16, 3, 160, 160) + + torch.onnx.export(model, dummy_input, output_file, input_names=input_names, dynamic_axes=dynamic_axes, + output_names=output_names, verbose=True, opset_version=10) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--pretrain', type=str, default='vggface2', help='[casia-webface, vggface2]') + parser.add_argument('--model', type=str, help='model path') + parser.add_argument('--output_file', type=str, default='.', help='output path') + arg = parser.parse_args() + FaceNet_pth2onnx(arg) diff --git a/ACL_PyTorch/contrib/cv/face/FaceNet/LICENSE b/ACL_PyTorch/contrib/cv/face/FaceNet/LICENSE index 2d284555aae8b0e5435b84a5f28e1ba0ee8e0482..2e03f7211ca08e3dcb4acf60609c23fed7b78a75 100644 --- a/ACL_PyTorch/contrib/cv/face/FaceNet/LICENSE +++ b/ACL_PyTorch/contrib/cv/face/FaceNet/LICENSE @@ -1,55 +1,55 @@ -MIT License - -Copyright (c) 2019 Timothy Esler - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - - +MIT License + +Copyright (c) 2019 Timothy Esler + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + + diff --git a/ACL_PyTorch/contrib/cv/face/FaceNet/MTCNN_preprocess.py b/ACL_PyTorch/contrib/cv/face/FaceNet/MTCNN_preprocess.py index 520e8d0a769e7de8734080ecb946c9cee138a58d..f75863254578ee8efd290770a49b6a012b2ff606 100644 --- a/ACL_PyTorch/contrib/cv/face/FaceNet/MTCNN_preprocess.py +++ b/ACL_PyTorch/contrib/cv/face/FaceNet/MTCNN_preprocess.py @@ -1,367 +1,367 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import torch -import argparse -import numpy as np -from easydict import EasyDict -from torch.utils.data import DataLoader -from torchvision import datasets -from tqdm import tqdm -sys.path.append('./models') -from mtcnn import PNet, RNet, ONet -from facenet_pytorch import MTCNN -from facenet_pytorch.models.utils.detect_face import imresample, generateBoundingBox, batched_nms, rerec, pad, bbreg, batched_nms_numpy - - -NET_MAP = { - 'pnet': PNet, - 'rnet': RNet, - 'onet': ONet -} - -################################################################################### -# basic function # -################################################################################### - -def build_dataset(config): - orig_img_ds = datasets.ImageFolder(config.data_dir, transform=None) - orig_img_ds.samples = [(p, p)for p, _ in orig_img_ds.samples] - def collate_fn(x): - out_x, out_y = [], [] - for xx, yy in x: - out_x.append(xx) - out_y.append(yy) - return out_x, out_y - loader = DataLoader( - orig_img_ds, - num_workers=config.num_workers, - batch_size=config.batch_size, - collate_fn=collate_fn - ) - return loader - - -def dump_to_json(content, outpath): - os.makedirs(os.path.dirname(outpath), exist_ok=True) - with open(outpath, 'w') as f: - json.dump(content, f) - - -def load_json(json_path): - with open(json_path) as f: - return json.load(f) - - -################################################################################### -# main class # -################################################################################### -class MTCNNPreprocessor(): - def __init__(self, config): - self.net_name = config.net - self.net = NET_MAP[self.net_name](config) - self.threshold = [0.6, 0.7, 0.7] - self.data_device = torch.device('cpu') - - def pnet_process(self, imgs): - if self.net_name != 'pnet': - raise ValueError('Pnet process not support for {} !'.format(self.net)) - - factor = 0.709 - minsize = 20 - - imgs = imgs.permute(0, 3, 1, 2).type(torch.float32) - batch_size = len(imgs) - h, w = imgs.shape[2:4] - m = 12.0 / minsize - minl = min(h, w) - minl = minl * m - - scale_i = m - scales = [] - while minl >= 12: - scales.append(scale_i) - scale_i = scale_i * factor - minl = minl * factor - # First stage - boxes = [] - image_inds = [] - scale_picks = [] - all_i = 0 - offset = 0 - for scale in scales: - im_data = imresample(imgs, (int(h * scale + 1), int(w * scale + 1))) - im_data = (im_data - 127.5) * 0.0078125 - reg, probs = self.net.forward(im_data.cpu().numpy()) - reg = torch.from_numpy(reg) - probs = torch.from_numpy(probs) - boxes_scale, image_inds_scale = generateBoundingBox(reg, probs[:, 1], scale, self.threshold[0]) - boxes.append(boxes_scale) - image_inds.append(image_inds_scale) - pick = batched_nms(boxes_scale[:, :4], boxes_scale[:, 4], image_inds_scale, 0.5) - scale_picks.append(pick + offset) - offset += boxes_scale.shape[0] - boxes = torch.cat(boxes, dim=0) - image_inds = torch.cat(image_inds, dim=0) - scale_picks = torch.cat(scale_picks, dim=0) - # NMS within each scale + image - boxes, image_inds = boxes[scale_picks], image_inds[scale_picks] - # NMS within each image - pick = batched_nms(boxes[:, :4], boxes[:, 4], image_inds, 0.7) - boxes, image_inds = boxes[pick], image_inds[pick] - regw = boxes[:, 2] - boxes[:, 0] - regh = boxes[:, 3] - boxes[:, 1] - qq1 = boxes[:, 0] + boxes[:, 5] * regw - qq2 = boxes[:, 1] + boxes[:, 6] * regh - qq3 = boxes[:, 2] + boxes[:, 7] * regw - qq4 = boxes[:, 3] + boxes[:, 8] * regh - boxes = torch.stack([qq1, qq2, qq3, qq4, boxes[:, 4]]).permute(1, 0) - boxes = rerec(boxes) - return boxes, image_inds - - def rnet_process(self, imgs, boxes, image_inds): - if self.net_name != 'rnet': - raise ValueError('Rnet process not support for {} !'.format(self.net)) - imgs = imgs.permute(0, 3, 1, 2).type(torch.float32) - h, w = imgs.shape[2:4] - y, ey, x, ex = pad(boxes, w, h) - if len(boxes) > 0: - im_data = [] - for k in range(len(y)): - if ey[k] > (y[k] - 1) and ex[k] > (x[k] - 1): - img_k = imgs[image_inds[k], :, (y[k] - 1):ey[k], (x[k] - 1):ex[k]].unsqueeze(0) - im_data.append(imresample(img_k, (24, 24))) - im_data = torch.cat(im_data, dim=0) - im_data = (im_data - 127.5) * 0.0078125 - out = self.net.forward(im_data.cpu().numpy()) - out = [torch.from_numpy(o) for o in out] - out0 = out[0].permute(1, 0) - out1 = out[1].permute(1, 0) - score = out1[1, :] - ipass = score > self.threshold[1] - boxes = torch.cat((boxes[ipass, :4], score[ipass].unsqueeze(1)), dim=1) - image_inds = image_inds[ipass] - mv = out0[:, ipass].permute(1, 0) - # NMS within each image - pick = batched_nms(boxes[:, :4], boxes[:, 4], image_inds, 0.7) - boxes, image_inds, mv = boxes[pick], image_inds[pick], mv[pick] - boxes = bbreg(boxes, mv) - boxes = rerec(boxes) - return boxes, image_inds - - def onet_process(self, imgs, boxes, image_inds): - if self.net_name != 'onet': - raise ValueError('Onet process not support for {} !'.format(self.net)) - imgs = imgs.permute(0, 3, 1, 2).type(torch.float32) - h, w = imgs.shape[2:4] - points = torch.zeros(0, 5, 2, device=self.data_device) - if len(boxes) > 0: - y, ey, x, ex = pad(boxes, w, h) - im_data = [] - for k in range(len(y)): - if ey[k] > (y[k] - 1) and ex[k] > (x[k] - 1): - img_k = imgs[image_inds[k], :, (y[k] - 1):ey[k], (x[k] - 1):ex[k]].unsqueeze(0) - im_data.append(imresample(img_k, (48, 48))) - im_data = torch.cat(im_data, dim=0) - im_data = (im_data - 127.5) * 0.0078125 - out = self.net.forward(im_data.cpu().numpy()) - out = [torch.from_numpy(o) for o in out] - out0 = out[0].permute(1, 0) - out1 = out[1].permute(1, 0) - out2 = out[2].permute(1, 0) - score = out2[1, :] - points = out1 - ipass = score > self.threshold[2] - points = points[:, ipass] - boxes = torch.cat((boxes[ipass, :4], score[ipass].unsqueeze(1)), dim=1) - image_inds = image_inds[ipass] - mv = out0[:, ipass].permute(1, 0) - w_i = boxes[:, 2] - boxes[:, 0] + 1 - h_i = boxes[:, 3] - boxes[:, 1] + 1 - points_x = w_i.repeat(5, 1) * points[:5, :] + boxes[:, 0].repeat(5, 1) - 1 - points_y = h_i.repeat(5, 1) * points[5:10, :] + boxes[:, 1].repeat(5, 1) - 1 - points = torch.stack((points_x, points_y)).permute(2, 1, 0) - boxes = bbreg(boxes, mv) - # NMS within each image using "Min" strategy - # pick = batched_nms(boxes[:, :4], boxes[:, 4], image_inds, 0.7) - pick = batched_nms_numpy(boxes[:, :4], boxes[:, 4], image_inds, 0.7, 'Min') - boxes, image_inds, points = boxes[pick], image_inds[pick], points[pick] - - boxes = boxes.cpu().numpy() - points = points.cpu().numpy() - image_inds = image_inds.cpu() - batch_boxes = [] - batch_points = [] - for b_i in range(config.batch_size): - b_i_inds = np.where(image_inds == b_i) - batch_boxes.append(boxes[b_i_inds].copy()) - batch_points.append(points[b_i_inds].copy()) - batch_boxes, batch_points = np.array(batch_boxes), np.array(batch_points) - return batch_boxes, batch_points - - -################################################################################### -# main function # -################################################################################### -def process_pnet(config): - loader = build_dataset(config) - processor = MTCNNPreprocessor(config) - out_json = {} - for idx, (xs, b_paths) in tqdm(enumerate(loader), total=len(loader)): - imgs = np.stack([np.uint8(x) for x in xs]) - imgs = torch.as_tensor(imgs.copy(), device=torch.device('cpu')) - boxes, image_inds = processor.pnet_process(imgs) - out_json[str(idx)] = { - 'boxes': boxes.tolist(), - 'image_inds': image_inds.tolist() - } - save_path = os.path.join(config.output_path, 'pnet.json') - os.makedirs(os.path.dirname(save_path), exist_ok=True) - dump_to_json(out_json, save_path) - - -def process_rnet(config): - loader = build_dataset(config) - processor = MTCNNPreprocessor(config) - out_json = {} - pnet_data = load_json(config.input_path) - for idx, (xs, b_paths) in tqdm(enumerate(loader), total=len(loader)): - imgs = np.stack([np.uint8(x) for x in xs]) - imgs = torch.as_tensor(imgs.copy(), device=torch.device('cpu')) - boxes = torch.from_numpy(np.array(pnet_data[str(idx)]['boxes'])) - image_inds = torch.from_numpy(np.array(pnet_data[str(idx)]['image_inds'])) - boxes, image_inds = processor.rnet_process(imgs, boxes, image_inds) - out_json[str(idx)] = { - 'boxes': boxes.tolist(), - 'image_inds': image_inds.tolist() - } - save_path = os.path.join(config.output_path, 'rnet.json') - os.makedirs(os.path.dirname(save_path), exist_ok=True) - dump_to_json(out_json, save_path) - - -def process_onet(config): - data_dir = config.data_dir - loader = build_dataset(config) - processor = MTCNNPreprocessor(config) - pnet_data = load_json(config.input_path) - crop_paths = [] - for idx, (xs, b_paths) in tqdm(enumerate(loader), total=len(loader)): - imgs = np.stack([np.uint8(x) for x in xs]) - imgs = torch.as_tensor(imgs.copy(), device=torch.device('cpu')) - boxes = torch.from_numpy(np.array(pnet_data[str(idx)]['boxes'])) - image_inds = torch.from_numpy(np.array(pnet_data[str(idx)]['image_inds'])) - batch_boxes, batch_points = processor.onet_process(imgs, boxes, image_inds) - # save crop imgs - save_paths = [p.replace(data_dir, data_dir + '_split_om_cropped_{}'.format(config.batch_size)) for p in b_paths] - save_crop_imgs(batch_boxes, batch_points, xs, save_paths) - crop_paths.extend(save_paths) - save_path = os.path.join(config.output_path, 'onet.json') - os.makedirs(os.path.dirname(save_path), exist_ok=True) - dump_to_json(crop_paths, save_path) - - -def save_crop_imgs(batch_boxes, batch_points, img, save_path): - mtcnn = MTCNN( - image_size=160, margin=14, min_face_size=20, - thresholds=[0.6, 0.7, 0.7], factor=0.709, post_process=True, - selection_method='center_weighted_size' - ) - boxes, probs, points = [], [], [] - for box, point in zip(batch_boxes, batch_points): - box = np.array(box) - point = np.array(point) - if len(box) == 0: - boxes.append(None) - probs.append([None]) - points.append(None) - elif mtcnn.select_largest: - box_order = np.argsort((box[:, 2] - box[:, 0]) * (box[:, 3] - box[:, 1]))[::-1] - box = box[box_order] - point = point[box_order] - boxes.append(box[:, :4]) - probs.append(box[:, 4]) - points.append(point) - else: - boxes.append(box[:, :4]) - probs.append(box[:, 4]) - points.append(point) - batch_boxes = np.array(boxes) - batch_probs = np.array(probs) - batch_points = np.array(points) - - batch_boxes, batch_probs, batch_points = mtcnn.select_boxes( - batch_boxes, batch_probs, batch_points, img, method=mtcnn.selection_method - ) - # Extract faces - faces = mtcnn.extract(img, batch_boxes, save_path) - return faces - - -def parser_args(): - pass - - -def build_config(arg): - pnet_config = { - 'net': 'pnet', - 'device_id': 1, - 'output_path': './data/output/split_bs' + str(arg.batch_size) + '/', - 'model_path': './weights/PNet_dynamic.om', - 'data_dir': './data/lfw', - 'num_workers': 8, - 'batch_size': arg.batch_size - } - rnet_config = { - 'net': 'rnet', - 'device_id': 1, - 'input_path': './data/output/split_bs' + str(arg.batch_size) + '/pnet.json', - 'output_path': './data/output/split_bs' + str(arg.batch_size) + '/', - 'model_path': './weights/RNet_dynamic.om', - 'data_dir': './data/lfw', - 'num_workers': 8, - 'batch_size': arg.batch_size - } - onet_config = { - 'net': 'onet', - 'device_id': 1, - 'input_path': './data/output/split_bs' + str(arg.batch_size) + '/rnet.json', - 'output_path': './data/output/split_bs' + str(arg.batch_size) + '/', - 'model_path': './weights/ONet_dynamic.om', - 'data_dir': './data/lfw', - 'num_workers': 8, - 'batch_size': arg.batch_size - } - return EasyDict(pnet_config), EasyDict(rnet_config), EasyDict(onet_config) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--model', type=str, help='[PNet/RNet/ONet]') - parser.add_argument('--data_dir', type=str, help='the absolute files path of lfw dataset') - parser.add_argument('--batch_size', type=int, help='[1/16]') - arg = parser.parse_args() - pnet_config, rnet_config, onet_config = build_config(arg) - if arg.model == 'Pnet': - config = pnet_config - process_pnet(config) - elif arg.model == 'Rnet': - config = rnet_config - process_rnet(config) - elif arg.model == 'Onet': - config = onet_config - process_onet(config) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import torch +import argparse +import numpy as np +from easydict import EasyDict +from torch.utils.data import DataLoader +from torchvision import datasets +from tqdm import tqdm +sys.path.append('./models') +from mtcnn import PNet, RNet, ONet +from facenet_pytorch import MTCNN +from facenet_pytorch.models.utils.detect_face import imresample, generateBoundingBox, batched_nms, rerec, pad, bbreg, batched_nms_numpy + + +NET_MAP = { + 'pnet': PNet, + 'rnet': RNet, + 'onet': ONet +} + +################################################################################### +# basic function # +################################################################################### + +def build_dataset(config): + orig_img_ds = datasets.ImageFolder(config.data_dir, transform=None) + orig_img_ds.samples = [(p, p)for p, _ in orig_img_ds.samples] + def collate_fn(x): + out_x, out_y = [], [] + for xx, yy in x: + out_x.append(xx) + out_y.append(yy) + return out_x, out_y + loader = DataLoader( + orig_img_ds, + num_workers=config.num_workers, + batch_size=config.batch_size, + collate_fn=collate_fn + ) + return loader + + +def dump_to_json(content, outpath): + os.makedirs(os.path.dirname(outpath), exist_ok=True) + with open(outpath, 'w') as f: + json.dump(content, f) + + +def load_json(json_path): + with open(json_path) as f: + return json.load(f) + + +################################################################################### +# main class # +################################################################################### +class MTCNNPreprocessor(): + def __init__(self, config): + self.net_name = config.net + self.net = NET_MAP[self.net_name](config) + self.threshold = [0.6, 0.7, 0.7] + self.data_device = torch.device('cpu') + + def pnet_process(self, imgs): + if self.net_name != 'pnet': + raise ValueError('Pnet process not support for {} !'.format(self.net)) + + factor = 0.709 + minsize = 20 + + imgs = imgs.permute(0, 3, 1, 2).type(torch.float32) + batch_size = len(imgs) + h, w = imgs.shape[2:4] + m = 12.0 / minsize + minl = min(h, w) + minl = minl * m + + scale_i = m + scales = [] + while minl >= 12: + scales.append(scale_i) + scale_i = scale_i * factor + minl = minl * factor + # First stage + boxes = [] + image_inds = [] + scale_picks = [] + all_i = 0 + offset = 0 + for scale in scales: + im_data = imresample(imgs, (int(h * scale + 1), int(w * scale + 1))) + im_data = (im_data - 127.5) * 0.0078125 + reg, probs = self.net.forward(im_data.cpu().numpy()) + reg = torch.from_numpy(reg) + probs = torch.from_numpy(probs) + boxes_scale, image_inds_scale = generateBoundingBox(reg, probs[:, 1], scale, self.threshold[0]) + boxes.append(boxes_scale) + image_inds.append(image_inds_scale) + pick = batched_nms(boxes_scale[:, :4], boxes_scale[:, 4], image_inds_scale, 0.5) + scale_picks.append(pick + offset) + offset += boxes_scale.shape[0] + boxes = torch.cat(boxes, dim=0) + image_inds = torch.cat(image_inds, dim=0) + scale_picks = torch.cat(scale_picks, dim=0) + # NMS within each scale + image + boxes, image_inds = boxes[scale_picks], image_inds[scale_picks] + # NMS within each image + pick = batched_nms(boxes[:, :4], boxes[:, 4], image_inds, 0.7) + boxes, image_inds = boxes[pick], image_inds[pick] + regw = boxes[:, 2] - boxes[:, 0] + regh = boxes[:, 3] - boxes[:, 1] + qq1 = boxes[:, 0] + boxes[:, 5] * regw + qq2 = boxes[:, 1] + boxes[:, 6] * regh + qq3 = boxes[:, 2] + boxes[:, 7] * regw + qq4 = boxes[:, 3] + boxes[:, 8] * regh + boxes = torch.stack([qq1, qq2, qq3, qq4, boxes[:, 4]]).permute(1, 0) + boxes = rerec(boxes) + return boxes, image_inds + + def rnet_process(self, imgs, boxes, image_inds): + if self.net_name != 'rnet': + raise ValueError('Rnet process not support for {} !'.format(self.net)) + imgs = imgs.permute(0, 3, 1, 2).type(torch.float32) + h, w = imgs.shape[2:4] + y, ey, x, ex = pad(boxes, w, h) + if len(boxes) > 0: + im_data = [] + for k in range(len(y)): + if ey[k] > (y[k] - 1) and ex[k] > (x[k] - 1): + img_k = imgs[image_inds[k], :, (y[k] - 1):ey[k], (x[k] - 1):ex[k]].unsqueeze(0) + im_data.append(imresample(img_k, (24, 24))) + im_data = torch.cat(im_data, dim=0) + im_data = (im_data - 127.5) * 0.0078125 + out = self.net.forward(im_data.cpu().numpy()) + out = [torch.from_numpy(o) for o in out] + out0 = out[0].permute(1, 0) + out1 = out[1].permute(1, 0) + score = out1[1, :] + ipass = score > self.threshold[1] + boxes = torch.cat((boxes[ipass, :4], score[ipass].unsqueeze(1)), dim=1) + image_inds = image_inds[ipass] + mv = out0[:, ipass].permute(1, 0) + # NMS within each image + pick = batched_nms(boxes[:, :4], boxes[:, 4], image_inds, 0.7) + boxes, image_inds, mv = boxes[pick], image_inds[pick], mv[pick] + boxes = bbreg(boxes, mv) + boxes = rerec(boxes) + return boxes, image_inds + + def onet_process(self, imgs, boxes, image_inds): + if self.net_name != 'onet': + raise ValueError('Onet process not support for {} !'.format(self.net)) + imgs = imgs.permute(0, 3, 1, 2).type(torch.float32) + h, w = imgs.shape[2:4] + points = torch.zeros(0, 5, 2, device=self.data_device) + if len(boxes) > 0: + y, ey, x, ex = pad(boxes, w, h) + im_data = [] + for k in range(len(y)): + if ey[k] > (y[k] - 1) and ex[k] > (x[k] - 1): + img_k = imgs[image_inds[k], :, (y[k] - 1):ey[k], (x[k] - 1):ex[k]].unsqueeze(0) + im_data.append(imresample(img_k, (48, 48))) + im_data = torch.cat(im_data, dim=0) + im_data = (im_data - 127.5) * 0.0078125 + out = self.net.forward(im_data.cpu().numpy()) + out = [torch.from_numpy(o) for o in out] + out0 = out[0].permute(1, 0) + out1 = out[1].permute(1, 0) + out2 = out[2].permute(1, 0) + score = out2[1, :] + points = out1 + ipass = score > self.threshold[2] + points = points[:, ipass] + boxes = torch.cat((boxes[ipass, :4], score[ipass].unsqueeze(1)), dim=1) + image_inds = image_inds[ipass] + mv = out0[:, ipass].permute(1, 0) + w_i = boxes[:, 2] - boxes[:, 0] + 1 + h_i = boxes[:, 3] - boxes[:, 1] + 1 + points_x = w_i.repeat(5, 1) * points[:5, :] + boxes[:, 0].repeat(5, 1) - 1 + points_y = h_i.repeat(5, 1) * points[5:10, :] + boxes[:, 1].repeat(5, 1) - 1 + points = torch.stack((points_x, points_y)).permute(2, 1, 0) + boxes = bbreg(boxes, mv) + # NMS within each image using "Min" strategy + # pick = batched_nms(boxes[:, :4], boxes[:, 4], image_inds, 0.7) + pick = batched_nms_numpy(boxes[:, :4], boxes[:, 4], image_inds, 0.7, 'Min') + boxes, image_inds, points = boxes[pick], image_inds[pick], points[pick] + + boxes = boxes.cpu().numpy() + points = points.cpu().numpy() + image_inds = image_inds.cpu() + batch_boxes = [] + batch_points = [] + for b_i in range(config.batch_size): + b_i_inds = np.where(image_inds == b_i) + batch_boxes.append(boxes[b_i_inds].copy()) + batch_points.append(points[b_i_inds].copy()) + batch_boxes, batch_points = np.array(batch_boxes), np.array(batch_points) + return batch_boxes, batch_points + + +################################################################################### +# main function # +################################################################################### +def process_pnet(config): + loader = build_dataset(config) + processor = MTCNNPreprocessor(config) + out_json = {} + for idx, (xs, b_paths) in tqdm(enumerate(loader), total=len(loader)): + imgs = np.stack([np.uint8(x) for x in xs]) + imgs = torch.as_tensor(imgs.copy(), device=torch.device('cpu')) + boxes, image_inds = processor.pnet_process(imgs) + out_json[str(idx)] = { + 'boxes': boxes.tolist(), + 'image_inds': image_inds.tolist() + } + save_path = os.path.join(config.output_path, 'pnet.json') + os.makedirs(os.path.dirname(save_path), exist_ok=True) + dump_to_json(out_json, save_path) + + +def process_rnet(config): + loader = build_dataset(config) + processor = MTCNNPreprocessor(config) + out_json = {} + pnet_data = load_json(config.input_path) + for idx, (xs, b_paths) in tqdm(enumerate(loader), total=len(loader)): + imgs = np.stack([np.uint8(x) for x in xs]) + imgs = torch.as_tensor(imgs.copy(), device=torch.device('cpu')) + boxes = torch.from_numpy(np.array(pnet_data[str(idx)]['boxes'])) + image_inds = torch.from_numpy(np.array(pnet_data[str(idx)]['image_inds'])) + boxes, image_inds = processor.rnet_process(imgs, boxes, image_inds) + out_json[str(idx)] = { + 'boxes': boxes.tolist(), + 'image_inds': image_inds.tolist() + } + save_path = os.path.join(config.output_path, 'rnet.json') + os.makedirs(os.path.dirname(save_path), exist_ok=True) + dump_to_json(out_json, save_path) + + +def process_onet(config): + data_dir = config.data_dir + loader = build_dataset(config) + processor = MTCNNPreprocessor(config) + pnet_data = load_json(config.input_path) + crop_paths = [] + for idx, (xs, b_paths) in tqdm(enumerate(loader), total=len(loader)): + imgs = np.stack([np.uint8(x) for x in xs]) + imgs = torch.as_tensor(imgs.copy(), device=torch.device('cpu')) + boxes = torch.from_numpy(np.array(pnet_data[str(idx)]['boxes'])) + image_inds = torch.from_numpy(np.array(pnet_data[str(idx)]['image_inds'])) + batch_boxes, batch_points = processor.onet_process(imgs, boxes, image_inds) + # save crop imgs + save_paths = [p.replace(data_dir, data_dir + '_split_om_cropped_{}'.format(config.batch_size)) for p in b_paths] + save_crop_imgs(batch_boxes, batch_points, xs, save_paths) + crop_paths.extend(save_paths) + save_path = os.path.join(config.output_path, 'onet.json') + os.makedirs(os.path.dirname(save_path), exist_ok=True) + dump_to_json(crop_paths, save_path) + + +def save_crop_imgs(batch_boxes, batch_points, img, save_path): + mtcnn = MTCNN( + image_size=160, margin=14, min_face_size=20, + thresholds=[0.6, 0.7, 0.7], factor=0.709, post_process=True, + selection_method='center_weighted_size' + ) + boxes, probs, points = [], [], [] + for box, point in zip(batch_boxes, batch_points): + box = np.array(box) + point = np.array(point) + if len(box) == 0: + boxes.append(None) + probs.append([None]) + points.append(None) + elif mtcnn.select_largest: + box_order = np.argsort((box[:, 2] - box[:, 0]) * (box[:, 3] - box[:, 1]))[::-1] + box = box[box_order] + point = point[box_order] + boxes.append(box[:, :4]) + probs.append(box[:, 4]) + points.append(point) + else: + boxes.append(box[:, :4]) + probs.append(box[:, 4]) + points.append(point) + batch_boxes = np.array(boxes) + batch_probs = np.array(probs) + batch_points = np.array(points) + + batch_boxes, batch_probs, batch_points = mtcnn.select_boxes( + batch_boxes, batch_probs, batch_points, img, method=mtcnn.selection_method + ) + # Extract faces + faces = mtcnn.extract(img, batch_boxes, save_path) + return faces + + +def parser_args(): + pass + + +def build_config(arg): + pnet_config = { + 'net': 'pnet', + 'device_id': 1, + 'output_path': './data/output/split_bs' + str(arg.batch_size) + '/', + 'model_path': './weights/PNet_dynamic.om', + 'data_dir': './data/lfw', + 'num_workers': 8, + 'batch_size': arg.batch_size + } + rnet_config = { + 'net': 'rnet', + 'device_id': 1, + 'input_path': './data/output/split_bs' + str(arg.batch_size) + '/pnet.json', + 'output_path': './data/output/split_bs' + str(arg.batch_size) + '/', + 'model_path': './weights/RNet_dynamic.om', + 'data_dir': './data/lfw', + 'num_workers': 8, + 'batch_size': arg.batch_size + } + onet_config = { + 'net': 'onet', + 'device_id': 1, + 'input_path': './data/output/split_bs' + str(arg.batch_size) + '/rnet.json', + 'output_path': './data/output/split_bs' + str(arg.batch_size) + '/', + 'model_path': './weights/ONet_dynamic.om', + 'data_dir': './data/lfw', + 'num_workers': 8, + 'batch_size': arg.batch_size + } + return EasyDict(pnet_config), EasyDict(rnet_config), EasyDict(onet_config) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--model', type=str, help='[PNet/RNet/ONet]') + parser.add_argument('--data_dir', type=str, help='the absolute files path of lfw dataset') + parser.add_argument('--batch_size', type=int, help='[1/16]') + arg = parser.parse_args() + pnet_config, rnet_config, onet_config = build_config(arg) + if arg.model == 'Pnet': + config = pnet_config + process_pnet(config) + elif arg.model == 'Rnet': + config = rnet_config + process_rnet(config) + elif arg.model == 'Onet': + config = onet_config + process_onet(config) diff --git a/ACL_PyTorch/contrib/cv/face/FaceNet/MTCNN_pth2onnx.py b/ACL_PyTorch/contrib/cv/face/FaceNet/MTCNN_pth2onnx.py index 890b3f9073d603dea00d37d03cef79134df19fa3..b94604da8f6413f9d35a58eae7785290dbb406a4 100644 --- a/ACL_PyTorch/contrib/cv/face/FaceNet/MTCNN_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/face/FaceNet/MTCNN_pth2onnx.py @@ -1,57 +1,57 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import torch -import argparse -sys.path.append('./models') -from mtcnn import PNet_truncated, RNet_truncated, ONet_truncated - - -def MTCNN_pth2onnx(opt): - if opt.model == 'PNet': - model = PNet_truncated() - elif opt.model == 'RNet': - model = RNet_truncated() - elif opt.model == 'ONet': - model = ONet_truncated() - else: - print("Error network") - return -1 - model = model.eval() - input_names = ['image'] - if opt.model == 'PNet': - output_names = ["probs", "reg"] - dynamic_axes = {'image': {0: '-1', 2: '-1', 3: '-1'}, 'probs': {0: '-1', 2: '-1', 3: '-1'}, - 'reg': {0: '-1', 2: '-1', 3: '-1'}} - dummy_input = torch.randn(1, 3, 1229, 1000) - elif opt.model == 'RNet': - output_names = ['regs', 'cls'] - dynamic_axes = {'image': {0: '-1'}, 'regs': {0: '-1'}, 'cls': {0: '-1'}} - dummy_input = torch.randn(20, 3, 24, 24) - else: - output_names = ['landmark', 'regs', 'cls'] - dynamic_axes = {'image': {0: '-1'}, 'landmark': {0: '-1'}, 'regs': {0: '-1'}, 'cls': {0: '-1'}} - dummy_input = torch.randn(20, 3, 48, 48) - - torch.onnx.export(model, dummy_input, opt.output_file, input_names=input_names, dynamic_axes=dynamic_axes, - output_names=output_names, verbose=True, opset_version=11) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--model', type=str, help='[PNet/RNet/ONet]') - parser.add_argument('--output_file', type=str, default='.', help='output path') - arg = parser.parse_args() - MTCNN_pth2onnx(arg) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import torch +import argparse +sys.path.append('./models') +from mtcnn import PNet_truncated, RNet_truncated, ONet_truncated + + +def MTCNN_pth2onnx(opt): + if opt.model == 'PNet': + model = PNet_truncated() + elif opt.model == 'RNet': + model = RNet_truncated() + elif opt.model == 'ONet': + model = ONet_truncated() + else: + print("Error network") + return -1 + model = model.eval() + input_names = ['image'] + if opt.model == 'PNet': + output_names = ["probs", "reg"] + dynamic_axes = {'image': {0: '-1', 2: '-1', 3: '-1'}, 'probs': {0: '-1', 2: '-1', 3: '-1'}, + 'reg': {0: '-1', 2: '-1', 3: '-1'}} + dummy_input = torch.randn(1, 3, 1229, 1000) + elif opt.model == 'RNet': + output_names = ['regs', 'cls'] + dynamic_axes = {'image': {0: '-1'}, 'regs': {0: '-1'}, 'cls': {0: '-1'}} + dummy_input = torch.randn(20, 3, 24, 24) + else: + output_names = ['landmark', 'regs', 'cls'] + dynamic_axes = {'image': {0: '-1'}, 'landmark': {0: '-1'}, 'regs': {0: '-1'}, 'cls': {0: '-1'}} + dummy_input = torch.randn(20, 3, 48, 48) + + torch.onnx.export(model, dummy_input, opt.output_file, input_names=input_names, dynamic_axes=dynamic_axes, + output_names=output_names, verbose=True, opset_version=11) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--model', type=str, help='[PNet/RNet/ONet]') + parser.add_argument('--output_file', type=str, default='.', help='output path') + arg = parser.parse_args() + MTCNN_pth2onnx(arg) diff --git a/ACL_PyTorch/contrib/cv/face/FaceNet/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/face/FaceNet/gen_dataset_info.py index b76d6739bcea5c528a031970f0e583e5b5644bd8..d5cab0450c20d502d0d15be2f9c0fceffa6a6191 100644 --- a/ACL_PyTorch/contrib/cv/face/FaceNet/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/face/FaceNet/gen_dataset_info.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/face/FaceNet/models/acl_net.py b/ACL_PyTorch/contrib/cv/face/FaceNet/models/acl_net.py index 61410d49e871fad4d748d2f3e22a7be0f6b534df..3be0075a7e380bc1b2ce9f3d6d3bd7765528cda6 100644 --- a/ACL_PyTorch/contrib/cv/face/FaceNet/models/acl_net.py +++ b/ACL_PyTorch/contrib/cv/face/FaceNet/models/acl_net.py @@ -1,293 +1,293 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import numpy as np -import acl - -# error code -ACL_ERROR_NONE = 0 - -# memory malloc code -ACL_MEM_MALLOC_HUGE_FIRST = 0 -ACL_MEM_MALLOC_HUGE_ONLY = 1 -ACL_MEM_MALLOC_NORMAL_ONLY = 2 - -# memory copy code -ACL_MEMCPY_HOST_TO_HOST = 0 -ACL_MEMCPY_HOST_TO_DEVICE = 1 -ACL_MEMCPY_DEVICE_TO_HOST = 2 -ACL_MEMCPY_DEVICE_TO_DEVICE = 3 - -# format -ACL_FORMAT_NCHW = 0 -ACL_FLOAT32 = 0 -ACL_DTYPE = { - 0: 'float32', - 1: 'float16', - 2: 'int8', - 3: 'int32', - 4: 'uint8', - 6: 'int16', - 7: 'uint16', - 8: 'uint32', - 9: 'int64', - 10: 'uint64', - 11: 'float64', - 12: 'bool', -} - - -def check_ret(message, ret): - if ret != ACL_ERROR_NONE: - raise Exception("{} failed ret = {}".format(message, ret)) - - -class Net(object): - def __init__(self, context, device_id, model_path, input_dtype=ACL_FLOAT32, output_dtype=ACL_FLOAT32): - self.device_id = device_id - self.model_path = model_path - self.model_id = None - self.context = context - self.buffer_method = { - "in": acl.mdl.get_input_size_by_index, - "out": acl.mdl.get_output_size_by_index, - "outhost": acl.mdl.get_output_size_by_index - } - - self.input_data = [] - self.output_data = [] - self.output_data_host = [] - self.model_desc = None - self.load_input_dataset = None - self.load_output_dataset = None - self.input_size = None - self.output_size = None - - self.input_dtype = ACL_FLOAT32 - self.output_dtype = ACL_FLOAT32 - - self._init_resource() - - def __call__(self, ori_data, out_size): - return self.forward(ori_data, out_size) - - def __del__(self): - ret = acl.mdl.unload(self.model_id) - check_ret("acl.mdl.unload", ret) - if self.model_desc: - acl.mdl.destroy_desc(self.model_desc) - self.model_desc = None - - def _release_data_buffer(self): - while self.input_data: - item = self.input_data.pop() - ret = acl.rt.free(item["buffer"]) - check_ret("acl.rt.free", ret) - - while self.output_data: - item = self.output_data.pop() - ret = acl.rt.free(item["buffer"]) - check_ret("acl.rt.free", ret) - - while self.output_data_host: - item = self.output_data_host.pop() - ret = acl.rt.free_host(item["buffer"]) - check_ret("acl.rt.free_host", ret) - - def _init_resource(self): - # load_model - self.model_id, ret = acl.mdl.load_from_file(self.model_path) - check_ret("acl.mdl.load_from_file", ret) - - self.model_desc = acl.mdl.create_desc() - self._get_model_info() - - def _get_model_info(self): - ret = acl.mdl.get_desc(self.model_desc, self.model_id) - check_ret("acl.mdl.get_desc", ret) - self.input_size = acl.mdl.get_num_inputs(self.model_desc) - self.output_size = acl.mdl.get_num_outputs(self.model_desc) - - def _gen_data_buffer(self, size, des, data=None, out_size_list=None): - func = self.buffer_method[des] - for i in range(size): - if out_size_list is None and data is None: - temp_buffer_size = func(self.model_desc, i) - else: - if des == "in": - input_size = np.prod(np.array(data).shape) - temp_buffer_size = Net.gen_data_size(input_size, dtype=ACL_DTYPE.get(self.input_dtype)) - elif des == "out": - out_size = out_size_list[i] - temp_buffer_size = Net.gen_data_size(out_size, dtype=ACL_DTYPE.get(self.output_dtype)) - - temp_buffer, ret = acl.rt.malloc(temp_buffer_size, ACL_MEM_MALLOC_HUGE_FIRST) - check_ret("acl.rt.malloc", ret) - - if des == "in": - self.input_data.append({"buffer": temp_buffer, - "size": temp_buffer_size}) - elif des == "out": - self.output_data.append({"buffer": temp_buffer, - "size": temp_buffer_size}) - - def _gen_dataset_output_host(self, size, des, out_size_list=None): - func = self.buffer_method[des] - for i in range(size): - if out_size_list is None: - temp_buffer_size = func(self.model_desc, i) - else: - out_size = out_size_list[i] - temp_buffer_size = Net.gen_data_size(out_size, dtype=ACL_DTYPE.get(self.output_dtype)) - temp_buffer, ret = acl.rt.malloc_host(temp_buffer_size) - check_ret("acl.rt.malloc_host", ret) - - self.output_data_host.append({"buffer": temp_buffer, - "size": temp_buffer_size}) - - def _data_interaction(self, dataset, policy=ACL_MEMCPY_HOST_TO_DEVICE): - temp_data_buffer = self.input_data \ - if policy == ACL_MEMCPY_HOST_TO_DEVICE \ - else self.output_data - - if len(dataset) == 0 and policy == ACL_MEMCPY_DEVICE_TO_HOST: - dataset = self.output_data_host - - for i, item in enumerate(temp_data_buffer): - if policy == ACL_MEMCPY_HOST_TO_DEVICE: - if 'bytes_to_ptr' in dir(acl.util): - bytes_in = dataset[i].tobytes() - ptr = acl.util.bytes_to_ptr(bytes_in) - else: - ptr, _ = acl.util.numpy_contiguous_to_ptr(dataset[i]) - ret = acl.rt.memcpy(item["buffer"], item["size"], ptr, item["size"], policy) - check_ret("acl.rt.memcpy", ret) - - else: - ptr = dataset[i]["buffer"] - ret = acl.rt.memcpy(ptr, item["size"], item["buffer"], item["size"], policy) - check_ret("acl.rt.memcpy", ret) - - def _gen_dataset(self, type_str="input", input_shapes=None): - dataset = acl.mdl.create_dataset() - temp_dataset = None - if type_str == "in": - self.load_input_dataset = dataset - temp_dataset = self.input_data - else: - self.load_output_dataset = dataset - temp_dataset = self.output_data - - for i, item in enumerate(temp_dataset): - data = acl.create_data_buffer(item["buffer"], item["size"]) - if data is None: - ret = acl.destroy_data_buffer(dataset) - check_ret("acl.destroy_data_buffer", ret) - - _, ret = acl.mdl.add_dataset_buffer(dataset, data) - if ret != ACL_ERROR_NONE: - ret = acl.destroy_data_buffer(dataset) - check_ret("acl.destroy_data_buffer", ret) - - if type_str == "in": - # set dynamic dataset tensor desc - input_shape = input_shapes[i] - input_desc = acl.create_tensor_desc(self.input_dtype, input_shape, ACL_FORMAT_NCHW) - dataset, ret = acl.mdl.set_dataset_tensor_desc(dataset, input_desc, i) - if ret != ACL_ERROR_NONE: - ret = acl.destroy_data_buffer(dataset) - check_ret("acl.destroy_data_buffer", ret) - - def _data_from_host_to_device(self, images): - self._data_interaction(images, ACL_MEMCPY_HOST_TO_DEVICE) - input_shapes = [list(data.shape) for data in images] - self._gen_dataset("in", input_shapes) - self._gen_dataset("out") - - def _data_from_device_to_host(self, input_data, out_size_list): - res = [] - self._data_interaction(res, ACL_MEMCPY_DEVICE_TO_HOST) - output = self.get_result(self.output_data_host, input_data, out_size_list) - return output - - def _destroy_databuffer(self): - for dataset in [self.load_input_dataset, self.load_output_dataset]: - if not dataset: - continue - num = acl.mdl.get_dataset_num_buffers(dataset) - for i in range(num): - data_buf = acl.mdl.get_dataset_buffer(dataset, i) - if data_buf: - ret = acl.destroy_data_buffer(data_buf) - check_ret("acl.destroy_data_buffer", ret) - ret = acl.mdl.destroy_dataset(dataset) - check_ret("acl.mdl.destroy_dataset", ret) - - def _prepare_data_buffer(self, input_data=None, out_size_list=None): - self._gen_data_buffer(self.input_size, des="in", data=input_data) - self._gen_data_buffer(self.output_size, des="out", out_size_list=out_size_list) - self._gen_dataset_output_host(self.output_size, des="outhost", out_size_list=out_size_list) - - def forward(self, input_data, out_size_list): - if not isinstance(input_data, (list, tuple)): - input_data = [input_data] - - self._prepare_data_buffer(input_data=input_data, out_size_list=out_size_list) - self._data_from_host_to_device(input_data) - ret = acl.mdl.execute(self.model_id, self.load_input_dataset, self.load_output_dataset) - check_ret("acl.mdl.execute", ret) - self._destroy_databuffer() - result = self._data_from_device_to_host(input_data=input_data, out_size_list=out_size_list) - self._release_data_buffer() - return result - - def get_result(self, output_data, data, out_size_list): - dataset = [] - batch_size = data[0].shape[0] - for i in range(len(output_data)): - dims, ret = acl.mdl.get_output_dims(self.model_desc, i) - check_ret("acl.mdl.get_output_dims", ret) - - data_shape = dims.get("dims") - # fix dynamic batch size - # data_shape[0] = batch_size - data_type = acl.mdl.get_output_data_type(self.model_desc, i) - # data_len = functools.reduce(lambda x, y: x * y, data_shape) - data_len = out_size_list[i] - ftype = np.dtype(ACL_DTYPE.get(data_type)) - - size = output_data[i]["size"] - ptr = output_data[i]["buffer"] - if 'ptr_to_bytes' in dir(acl.util): - data = acl.util.ptr_to_bytes(ptr, size) - np_arr = np.frombuffer(data, dtype=ftype, count=data_len) - else: - data = acl.util.ptr_to_numpy(ptr, (size,), 1) - np_arr = np.frombuffer( - bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) - np_arr = np_arr.reshape(data_shape) - dataset.append(np_arr) - return dataset - - @staticmethod - def gen_data_size(size, dtype): - dtype = np.dtype(dtype) - return int(size * dtype.itemsize) - - @staticmethod - def fix_static_shape(input_shape, idx, value): - if not isinstance(input_shape, list): - input_shape = list(input_shape) - input_shape[idx] = value - return input_shape +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +import acl + +# error code +ACL_ERROR_NONE = 0 + +# memory malloc code +ACL_MEM_MALLOC_HUGE_FIRST = 0 +ACL_MEM_MALLOC_HUGE_ONLY = 1 +ACL_MEM_MALLOC_NORMAL_ONLY = 2 + +# memory copy code +ACL_MEMCPY_HOST_TO_HOST = 0 +ACL_MEMCPY_HOST_TO_DEVICE = 1 +ACL_MEMCPY_DEVICE_TO_HOST = 2 +ACL_MEMCPY_DEVICE_TO_DEVICE = 3 + +# format +ACL_FORMAT_NCHW = 0 +ACL_FLOAT32 = 0 +ACL_DTYPE = { + 0: 'float32', + 1: 'float16', + 2: 'int8', + 3: 'int32', + 4: 'uint8', + 6: 'int16', + 7: 'uint16', + 8: 'uint32', + 9: 'int64', + 10: 'uint64', + 11: 'float64', + 12: 'bool', +} + + +def check_ret(message, ret): + if ret != ACL_ERROR_NONE: + raise Exception("{} failed ret = {}".format(message, ret)) + + +class Net(object): + def __init__(self, context, device_id, model_path, input_dtype=ACL_FLOAT32, output_dtype=ACL_FLOAT32): + self.device_id = device_id + self.model_path = model_path + self.model_id = None + self.context = context + self.buffer_method = { + "in": acl.mdl.get_input_size_by_index, + "out": acl.mdl.get_output_size_by_index, + "outhost": acl.mdl.get_output_size_by_index + } + + self.input_data = [] + self.output_data = [] + self.output_data_host = [] + self.model_desc = None + self.load_input_dataset = None + self.load_output_dataset = None + self.input_size = None + self.output_size = None + + self.input_dtype = ACL_FLOAT32 + self.output_dtype = ACL_FLOAT32 + + self._init_resource() + + def __call__(self, ori_data, out_size): + return self.forward(ori_data, out_size) + + def __del__(self): + ret = acl.mdl.unload(self.model_id) + check_ret("acl.mdl.unload", ret) + if self.model_desc: + acl.mdl.destroy_desc(self.model_desc) + self.model_desc = None + + def _release_data_buffer(self): + while self.input_data: + item = self.input_data.pop() + ret = acl.rt.free(item["buffer"]) + check_ret("acl.rt.free", ret) + + while self.output_data: + item = self.output_data.pop() + ret = acl.rt.free(item["buffer"]) + check_ret("acl.rt.free", ret) + + while self.output_data_host: + item = self.output_data_host.pop() + ret = acl.rt.free_host(item["buffer"]) + check_ret("acl.rt.free_host", ret) + + def _init_resource(self): + # load_model + self.model_id, ret = acl.mdl.load_from_file(self.model_path) + check_ret("acl.mdl.load_from_file", ret) + + self.model_desc = acl.mdl.create_desc() + self._get_model_info() + + def _get_model_info(self): + ret = acl.mdl.get_desc(self.model_desc, self.model_id) + check_ret("acl.mdl.get_desc", ret) + self.input_size = acl.mdl.get_num_inputs(self.model_desc) + self.output_size = acl.mdl.get_num_outputs(self.model_desc) + + def _gen_data_buffer(self, size, des, data=None, out_size_list=None): + func = self.buffer_method[des] + for i in range(size): + if out_size_list is None and data is None: + temp_buffer_size = func(self.model_desc, i) + else: + if des == "in": + input_size = np.prod(np.array(data).shape) + temp_buffer_size = Net.gen_data_size(input_size, dtype=ACL_DTYPE.get(self.input_dtype)) + elif des == "out": + out_size = out_size_list[i] + temp_buffer_size = Net.gen_data_size(out_size, dtype=ACL_DTYPE.get(self.output_dtype)) + + temp_buffer, ret = acl.rt.malloc(temp_buffer_size, ACL_MEM_MALLOC_HUGE_FIRST) + check_ret("acl.rt.malloc", ret) + + if des == "in": + self.input_data.append({"buffer": temp_buffer, + "size": temp_buffer_size}) + elif des == "out": + self.output_data.append({"buffer": temp_buffer, + "size": temp_buffer_size}) + + def _gen_dataset_output_host(self, size, des, out_size_list=None): + func = self.buffer_method[des] + for i in range(size): + if out_size_list is None: + temp_buffer_size = func(self.model_desc, i) + else: + out_size = out_size_list[i] + temp_buffer_size = Net.gen_data_size(out_size, dtype=ACL_DTYPE.get(self.output_dtype)) + temp_buffer, ret = acl.rt.malloc_host(temp_buffer_size) + check_ret("acl.rt.malloc_host", ret) + + self.output_data_host.append({"buffer": temp_buffer, + "size": temp_buffer_size}) + + def _data_interaction(self, dataset, policy=ACL_MEMCPY_HOST_TO_DEVICE): + temp_data_buffer = self.input_data \ + if policy == ACL_MEMCPY_HOST_TO_DEVICE \ + else self.output_data + + if len(dataset) == 0 and policy == ACL_MEMCPY_DEVICE_TO_HOST: + dataset = self.output_data_host + + for i, item in enumerate(temp_data_buffer): + if policy == ACL_MEMCPY_HOST_TO_DEVICE: + if 'bytes_to_ptr' in dir(acl.util): + bytes_in = dataset[i].tobytes() + ptr = acl.util.bytes_to_ptr(bytes_in) + else: + ptr, _ = acl.util.numpy_contiguous_to_ptr(dataset[i]) + ret = acl.rt.memcpy(item["buffer"], item["size"], ptr, item["size"], policy) + check_ret("acl.rt.memcpy", ret) + + else: + ptr = dataset[i]["buffer"] + ret = acl.rt.memcpy(ptr, item["size"], item["buffer"], item["size"], policy) + check_ret("acl.rt.memcpy", ret) + + def _gen_dataset(self, type_str="input", input_shapes=None): + dataset = acl.mdl.create_dataset() + temp_dataset = None + if type_str == "in": + self.load_input_dataset = dataset + temp_dataset = self.input_data + else: + self.load_output_dataset = dataset + temp_dataset = self.output_data + + for i, item in enumerate(temp_dataset): + data = acl.create_data_buffer(item["buffer"], item["size"]) + if data is None: + ret = acl.destroy_data_buffer(dataset) + check_ret("acl.destroy_data_buffer", ret) + + _, ret = acl.mdl.add_dataset_buffer(dataset, data) + if ret != ACL_ERROR_NONE: + ret = acl.destroy_data_buffer(dataset) + check_ret("acl.destroy_data_buffer", ret) + + if type_str == "in": + # set dynamic dataset tensor desc + input_shape = input_shapes[i] + input_desc = acl.create_tensor_desc(self.input_dtype, input_shape, ACL_FORMAT_NCHW) + dataset, ret = acl.mdl.set_dataset_tensor_desc(dataset, input_desc, i) + if ret != ACL_ERROR_NONE: + ret = acl.destroy_data_buffer(dataset) + check_ret("acl.destroy_data_buffer", ret) + + def _data_from_host_to_device(self, images): + self._data_interaction(images, ACL_MEMCPY_HOST_TO_DEVICE) + input_shapes = [list(data.shape) for data in images] + self._gen_dataset("in", input_shapes) + self._gen_dataset("out") + + def _data_from_device_to_host(self, input_data, out_size_list): + res = [] + self._data_interaction(res, ACL_MEMCPY_DEVICE_TO_HOST) + output = self.get_result(self.output_data_host, input_data, out_size_list) + return output + + def _destroy_databuffer(self): + for dataset in [self.load_input_dataset, self.load_output_dataset]: + if not dataset: + continue + num = acl.mdl.get_dataset_num_buffers(dataset) + for i in range(num): + data_buf = acl.mdl.get_dataset_buffer(dataset, i) + if data_buf: + ret = acl.destroy_data_buffer(data_buf) + check_ret("acl.destroy_data_buffer", ret) + ret = acl.mdl.destroy_dataset(dataset) + check_ret("acl.mdl.destroy_dataset", ret) + + def _prepare_data_buffer(self, input_data=None, out_size_list=None): + self._gen_data_buffer(self.input_size, des="in", data=input_data) + self._gen_data_buffer(self.output_size, des="out", out_size_list=out_size_list) + self._gen_dataset_output_host(self.output_size, des="outhost", out_size_list=out_size_list) + + def forward(self, input_data, out_size_list): + if not isinstance(input_data, (list, tuple)): + input_data = [input_data] + + self._prepare_data_buffer(input_data=input_data, out_size_list=out_size_list) + self._data_from_host_to_device(input_data) + ret = acl.mdl.execute(self.model_id, self.load_input_dataset, self.load_output_dataset) + check_ret("acl.mdl.execute", ret) + self._destroy_databuffer() + result = self._data_from_device_to_host(input_data=input_data, out_size_list=out_size_list) + self._release_data_buffer() + return result + + def get_result(self, output_data, data, out_size_list): + dataset = [] + batch_size = data[0].shape[0] + for i in range(len(output_data)): + dims, ret = acl.mdl.get_output_dims(self.model_desc, i) + check_ret("acl.mdl.get_output_dims", ret) + + data_shape = dims.get("dims") + # fix dynamic batch size + # data_shape[0] = batch_size + data_type = acl.mdl.get_output_data_type(self.model_desc, i) + # data_len = functools.reduce(lambda x, y: x * y, data_shape) + data_len = out_size_list[i] + ftype = np.dtype(ACL_DTYPE.get(data_type)) + + size = output_data[i]["size"] + ptr = output_data[i]["buffer"] + if 'ptr_to_bytes' in dir(acl.util): + data = acl.util.ptr_to_bytes(ptr, size) + np_arr = np.frombuffer(data, dtype=ftype, count=data_len) + else: + data = acl.util.ptr_to_numpy(ptr, (size,), 1) + np_arr = np.frombuffer( + bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) + np_arr = np_arr.reshape(data_shape) + dataset.append(np_arr) + return dataset + + @staticmethod + def gen_data_size(size, dtype): + dtype = np.dtype(dtype) + return int(size * dtype.itemsize) + + @staticmethod + def fix_static_shape(input_shape, idx, value): + if not isinstance(input_shape, list): + input_shape = list(input_shape) + input_shape[idx] = value + return input_shape diff --git a/ACL_PyTorch/contrib/cv/face/FaceNet/models/mtcnn.patch b/ACL_PyTorch/contrib/cv/face/FaceNet/models/mtcnn.patch index f0c11301c300938cf6fc4f47b5158429eb040c89..3a974991ee38bfa330d5b179f4125061d1012cc5 100644 --- a/ACL_PyTorch/contrib/cv/face/FaceNet/models/mtcnn.patch +++ b/ACL_PyTorch/contrib/cv/face/FaceNet/models/mtcnn.patch @@ -1,243 +1,243 @@ 1,239c1,519 -< # Copyright 2021 Huawei Technologies Co., Ltd -< # -< # Licensed under the Apache License, Version 2.0 (the "License"); -< # you may not use this file except in compliance with the License. -< # You may obtain a copy of the License at -< # -< # http://www.apache.org/licenses/LICENSE-2.0 -< # -< # Unless required by applicable law or agreed to in writing, software -< # distributed under the License is distributed on an "AS IS" BASIS, -< # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -< # See the License for the specific language governing permissions and -< # limitations under the License. -< -< import torch -< from torch import nn -< import numpy as np -< import os -< import math -< import acl -< from abc import ABC, abstractmethod -< from acl_net import Net, check_ret -< -< -< class PNet_truncated(nn.Module): -< def __init__(self, pretrained=True): -< super().__init__() -< -< self.conv1 = nn.Conv2d(3, 10, kernel_size=3) -< self.prelu1 = nn.PReLU(10) -< self.pool1 = nn.MaxPool2d(2, 2, ceil_mode=True) -< self.conv2 = nn.Conv2d(10, 16, kernel_size=3) -< self.prelu2 = nn.PReLU(16) -< self.conv3 = nn.Conv2d(16, 32, kernel_size=3) -< self.prelu3 = nn.PReLU(32) -< self.conv4_1 = nn.Conv2d(32, 2, kernel_size=1) -< self.softmax4_1 = nn.Softmax(dim=1) -< self.conv4_2 = nn.Conv2d(32, 4, kernel_size=1) -< self.training = False -< -< if pretrained: -< state_dict_path=os.path.join(os.path.dirname(os.path.dirname(__file__)), "weights/pnet.pt") -< state_dict = torch.load(state_dict_path) -< self.load_state_dict(state_dict) -< -< def forward(self, x): -< x = self.conv1(x) -< x = self.prelu1(x) -< x = self.pool1(x) -< x = self.conv2(x) -< x = self.prelu2(x) -< x = self.conv3(x) -< x = self.prelu3(x) -< a = self.conv4_1(x) -< # a = self.softmax4_1(a) -< b = self.conv4_2(x) -< return b, a -< -< -< class RNet_truncated(nn.Module): -< def __init__(self, pretrained=True): -< super().__init__() -< -< self.conv1 = nn.Conv2d(3, 28, kernel_size=3) -< self.prelu1 = nn.PReLU(28) -< self.pool1 = nn.MaxPool2d(3, 2, ceil_mode=True) -< self.conv2 = nn.Conv2d(28, 48, kernel_size=3) -< self.prelu2 = nn.PReLU(48) -< self.pool2 = nn.MaxPool2d(3, 2, ceil_mode=True) -< self.conv3 = nn.Conv2d(48, 64, kernel_size=2) -< self.prelu3 = nn.PReLU(64) -< self.dense4 = nn.Linear(576, 128) -< self.prelu4 = nn.PReLU(128) -< self.dense5_1 = nn.Linear(128, 2) -< self.softmax5_1 = nn.Softmax(dim=1) -< self.dense5_2 = nn.Linear(128, 4) -< -< self.training = False -< -< if pretrained: -< state_dict_path=os.path.join(os.path.dirname(os.path.dirname(__file__)), "weights/rnet.pt") -< state_dict = torch.load(state_dict_path) -< self.load_state_dict(state_dict) -< -< def forward(self, x): -< x = self.conv1(x) -< x = self.prelu1(x) -< x = self.pool1(x) -< x = self.conv2(x) -< x = self.prelu2(x) -< x = self.pool2(x) -< x = self.conv3(x) -< x = self.prelu3(x) -< x = x.permute(0, 3, 2, 1).contiguous() -< x = self.dense4(x.view(x.shape[0], -1)) -< x = self.prelu4(x) -< a = self.dense5_1(x) -< # a = self.softmax5_1(a) -< b = self.dense5_2(x) -< return b, a -< -< -< class ONet_truncated(nn.Module): -< def __init__(self, pretrained=True): -< super().__init__() -< -< self.conv1 = nn.Conv2d(3, 32, kernel_size=3) -< self.prelu1 = nn.PReLU(32) -< self.pool1 = nn.MaxPool2d(3, 2, ceil_mode=True) -< self.conv2 = nn.Conv2d(32, 64, kernel_size=3) -< self.prelu2 = nn.PReLU(64) -< self.pool2 = nn.MaxPool2d(3, 2, ceil_mode=True) -< self.conv3 = nn.Conv2d(64, 64, kernel_size=3) -< self.prelu3 = nn.PReLU(64) -< self.pool3 = nn.MaxPool2d(2, 2, ceil_mode=True) -< self.conv4 = nn.Conv2d(64, 128, kernel_size=2) -< self.prelu4 = nn.PReLU(128) -< self.dense5 = nn.Linear(1152, 256) -< self.prelu5 = nn.PReLU(256) -< self.dense6_1 = nn.Linear(256, 2) -< self.softmax6_1 = nn.Softmax(dim=1) -< self.dense6_2 = nn.Linear(256, 4) -< self.dense6_3 = nn.Linear(256, 10) -< -< self.training = False -< -< if pretrained: -< state_dict_path=os.path.join(os.path.dirname(os.path.dirname(__file__)), "weights/onet.pt") -< state_dict = torch.load(state_dict_path) -< self.load_state_dict(state_dict) -< -< def forward(self, x): -< x = self.conv1(x) -< x = self.prelu1(x) -< x = self.pool1(x) -< x = self.conv2(x) -< x = self.prelu2(x) -< x = self.pool2(x) -< x = self.conv3(x) -< x = self.prelu3(x) -< x = self.pool3(x) -< x = self.conv4(x) -< x = self.prelu4(x) -< x = x.permute(0, 3, 2, 1).contiguous() -< x = self.dense5(x.view(x.shape[0], -1)) -< x = self.prelu5(x) -< a = self.dense6_1(x) -< # a = self.softmax6_1(a) -< b = self.dense6_2(x) -< c = self.dense6_3(x) -< return b, c, a -< -< -< class OMNet(ABC): -< def __init__(self, args): -< self.device_id = args.device_id -< # 默认float32 -< self.item_size = 4 -< -< # init for acl -< ret = acl.init() -< check_ret('acl.init', ret) -< ret = acl.rt.set_device(args.device_id) -< check_ret('acl.rt.set_device', ret) -< context, ret = acl.rt.create_context(args.device_id) -< check_ret('acl.rt.create_context', ret) -< self.net_context = Net(context, model_path=args.model_path, -< device_id=args.device_id) -< -< @abstractmethod -< def forward(self, input_data, ): -< pass -< -< def __del__(self): -< del self.net_context -< ret = acl.rt.reset_device(self.device_id) -< check_ret('acl.rt.reset_device', ret) -< -< context, ret = acl.rt.get_context() -< check_ret('acl.rt.get_context', ret) -< ret = acl.rt.destroy_context(context) -< check_ret('acl.rt.destory_context', ret) -< ret = acl.finalize() -< check_ret('acl.finalize', ret) -< -< -< class PNet(OMNet): -< def __init__(self, args): -< super().__init__(args) -< -< def forward(self, input_data): -< if isinstance(input_data, np.ndarray): -< input_data = [input_data] -< h, w = input_data[0].shape[2:4] -< batch_size = input_data[0].shape[0] -< out_h = math.ceil((h - 2) /2) - 4 -< out_w = math.ceil((w - 2) /2) - 4 -< out_size = [batch_size*4*out_h*out_w, batch_size*2*out_h*out_w] -< output_data = self.net_context(input_data, out_size) -< # postprocess: softmax && reshape -< output_data[1] = output_data[1].reshape([batch_size, 2, out_h, out_w]) -< output_data[1] = torch.softmax(torch.tensor(output_data[1]), dim=1).numpy() -< output_data[0] = output_data[0].reshape([batch_size, 4, out_h, out_w]) -< return output_data -< -< -< class RNet(OMNet): -< def __init__(self, args): -< super().__init__(args) -< -< def forward(self, input_data): -< if isinstance(input_data, np.ndarray): -< input_data = [input_data] -< batch_size = input_data[0].shape[0] -< out_size = [batch_size*4, batch_size*2] -< output_data = self.net_context(input_data, out_size) -< # postprocess: softmax && reshape -< output_data[0] = output_data[0].reshape([batch_size, 4]) -< output_data[1] = output_data[1].reshape([batch_size, 2]) -< output_data[1] = torch.softmax(torch.tensor(output_data[1]), dim=1).numpy() -< return output_data -< -< -< class ONet(OMNet): -< def __init__(self, args): -< super().__init__(args) -< -< def forward(self, input_data): -< if isinstance(input_data, np.ndarray): -< input_data = [input_data] -< batch_size = input_data[0].shape[0] -< out_size = [batch_size*4, batch_size*10, batch_size*2] -< output_data = self.net_context(input_data, out_size) -< # postprocess: softmax && reshape -< output_data[0] = output_data[0].reshape([batch_size, 4]) -< output_data[1] = output_data[1].reshape([batch_size, 10]) -< output_data[2] = output_data[2].reshape([batch_size, 2]) -< output_data[2] = torch.softmax(torch.tensor(output_data[2]), dim=1).numpy() -< return output_data +< # Copyright 2021 Huawei Technologies Co., Ltd +< # +< # Licensed under the Apache License, Version 2.0 (the "License"); +< # you may not use this file except in compliance with the License. +< # You may obtain a copy of the License at +< # +< # http://www.apache.org/licenses/LICENSE-2.0 +< # +< # Unless required by applicable law or agreed to in writing, software +< # distributed under the License is distributed on an "AS IS" BASIS, +< # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +< # See the License for the specific language governing permissions and +< # limitations under the License. +< +< import torch +< from torch import nn +< import numpy as np +< import os +< import math +< import acl +< from abc import ABC, abstractmethod +< from acl_net import Net, check_ret +< +< +< class PNet_truncated(nn.Module): +< def __init__(self, pretrained=True): +< super().__init__() +< +< self.conv1 = nn.Conv2d(3, 10, kernel_size=3) +< self.prelu1 = nn.PReLU(10) +< self.pool1 = nn.MaxPool2d(2, 2, ceil_mode=True) +< self.conv2 = nn.Conv2d(10, 16, kernel_size=3) +< self.prelu2 = nn.PReLU(16) +< self.conv3 = nn.Conv2d(16, 32, kernel_size=3) +< self.prelu3 = nn.PReLU(32) +< self.conv4_1 = nn.Conv2d(32, 2, kernel_size=1) +< self.softmax4_1 = nn.Softmax(dim=1) +< self.conv4_2 = nn.Conv2d(32, 4, kernel_size=1) +< self.training = False +< +< if pretrained: +< state_dict_path=os.path.join(os.path.dirname(os.path.dirname(__file__)), "weights/pnet.pt") +< state_dict = torch.load(state_dict_path) +< self.load_state_dict(state_dict) +< +< def forward(self, x): +< x = self.conv1(x) +< x = self.prelu1(x) +< x = self.pool1(x) +< x = self.conv2(x) +< x = self.prelu2(x) +< x = self.conv3(x) +< x = self.prelu3(x) +< a = self.conv4_1(x) +< # a = self.softmax4_1(a) +< b = self.conv4_2(x) +< return b, a +< +< +< class RNet_truncated(nn.Module): +< def __init__(self, pretrained=True): +< super().__init__() +< +< self.conv1 = nn.Conv2d(3, 28, kernel_size=3) +< self.prelu1 = nn.PReLU(28) +< self.pool1 = nn.MaxPool2d(3, 2, ceil_mode=True) +< self.conv2 = nn.Conv2d(28, 48, kernel_size=3) +< self.prelu2 = nn.PReLU(48) +< self.pool2 = nn.MaxPool2d(3, 2, ceil_mode=True) +< self.conv3 = nn.Conv2d(48, 64, kernel_size=2) +< self.prelu3 = nn.PReLU(64) +< self.dense4 = nn.Linear(576, 128) +< self.prelu4 = nn.PReLU(128) +< self.dense5_1 = nn.Linear(128, 2) +< self.softmax5_1 = nn.Softmax(dim=1) +< self.dense5_2 = nn.Linear(128, 4) +< +< self.training = False +< +< if pretrained: +< state_dict_path=os.path.join(os.path.dirname(os.path.dirname(__file__)), "weights/rnet.pt") +< state_dict = torch.load(state_dict_path) +< self.load_state_dict(state_dict) +< +< def forward(self, x): +< x = self.conv1(x) +< x = self.prelu1(x) +< x = self.pool1(x) +< x = self.conv2(x) +< x = self.prelu2(x) +< x = self.pool2(x) +< x = self.conv3(x) +< x = self.prelu3(x) +< x = x.permute(0, 3, 2, 1).contiguous() +< x = self.dense4(x.view(x.shape[0], -1)) +< x = self.prelu4(x) +< a = self.dense5_1(x) +< # a = self.softmax5_1(a) +< b = self.dense5_2(x) +< return b, a +< +< +< class ONet_truncated(nn.Module): +< def __init__(self, pretrained=True): +< super().__init__() +< +< self.conv1 = nn.Conv2d(3, 32, kernel_size=3) +< self.prelu1 = nn.PReLU(32) +< self.pool1 = nn.MaxPool2d(3, 2, ceil_mode=True) +< self.conv2 = nn.Conv2d(32, 64, kernel_size=3) +< self.prelu2 = nn.PReLU(64) +< self.pool2 = nn.MaxPool2d(3, 2, ceil_mode=True) +< self.conv3 = nn.Conv2d(64, 64, kernel_size=3) +< self.prelu3 = nn.PReLU(64) +< self.pool3 = nn.MaxPool2d(2, 2, ceil_mode=True) +< self.conv4 = nn.Conv2d(64, 128, kernel_size=2) +< self.prelu4 = nn.PReLU(128) +< self.dense5 = nn.Linear(1152, 256) +< self.prelu5 = nn.PReLU(256) +< self.dense6_1 = nn.Linear(256, 2) +< self.softmax6_1 = nn.Softmax(dim=1) +< self.dense6_2 = nn.Linear(256, 4) +< self.dense6_3 = nn.Linear(256, 10) +< +< self.training = False +< +< if pretrained: +< state_dict_path=os.path.join(os.path.dirname(os.path.dirname(__file__)), "weights/onet.pt") +< state_dict = torch.load(state_dict_path) +< self.load_state_dict(state_dict) +< +< def forward(self, x): +< x = self.conv1(x) +< x = self.prelu1(x) +< x = self.pool1(x) +< x = self.conv2(x) +< x = self.prelu2(x) +< x = self.pool2(x) +< x = self.conv3(x) +< x = self.prelu3(x) +< x = self.pool3(x) +< x = self.conv4(x) +< x = self.prelu4(x) +< x = x.permute(0, 3, 2, 1).contiguous() +< x = self.dense5(x.view(x.shape[0], -1)) +< x = self.prelu5(x) +< a = self.dense6_1(x) +< # a = self.softmax6_1(a) +< b = self.dense6_2(x) +< c = self.dense6_3(x) +< return b, c, a +< +< +< class OMNet(ABC): +< def __init__(self, args): +< self.device_id = args.device_id +< # 默认float32 +< self.item_size = 4 +< +< # init for acl +< ret = acl.init() +< check_ret('acl.init', ret) +< ret = acl.rt.set_device(args.device_id) +< check_ret('acl.rt.set_device', ret) +< context, ret = acl.rt.create_context(args.device_id) +< check_ret('acl.rt.create_context', ret) +< self.net_context = Net(context, model_path=args.model_path, +< device_id=args.device_id) +< +< @abstractmethod +< def forward(self, input_data, ): +< pass +< +< def __del__(self): +< del self.net_context +< ret = acl.rt.reset_device(self.device_id) +< check_ret('acl.rt.reset_device', ret) +< +< context, ret = acl.rt.get_context() +< check_ret('acl.rt.get_context', ret) +< ret = acl.rt.destroy_context(context) +< check_ret('acl.rt.destory_context', ret) +< ret = acl.finalize() +< check_ret('acl.finalize', ret) +< +< +< class PNet(OMNet): +< def __init__(self, args): +< super().__init__(args) +< +< def forward(self, input_data): +< if isinstance(input_data, np.ndarray): +< input_data = [input_data] +< h, w = input_data[0].shape[2:4] +< batch_size = input_data[0].shape[0] +< out_h = math.ceil((h - 2) /2) - 4 +< out_w = math.ceil((w - 2) /2) - 4 +< out_size = [batch_size*4*out_h*out_w, batch_size*2*out_h*out_w] +< output_data = self.net_context(input_data, out_size) +< # postprocess: softmax && reshape +< output_data[1] = output_data[1].reshape([batch_size, 2, out_h, out_w]) +< output_data[1] = torch.softmax(torch.tensor(output_data[1]), dim=1).numpy() +< output_data[0] = output_data[0].reshape([batch_size, 4, out_h, out_w]) +< return output_data +< +< +< class RNet(OMNet): +< def __init__(self, args): +< super().__init__(args) +< +< def forward(self, input_data): +< if isinstance(input_data, np.ndarray): +< input_data = [input_data] +< batch_size = input_data[0].shape[0] +< out_size = [batch_size*4, batch_size*2] +< output_data = self.net_context(input_data, out_size) +< # postprocess: softmax && reshape +< output_data[0] = output_data[0].reshape([batch_size, 4]) +< output_data[1] = output_data[1].reshape([batch_size, 2]) +< output_data[1] = torch.softmax(torch.tensor(output_data[1]), dim=1).numpy() +< return output_data +< +< +< class ONet(OMNet): +< def __init__(self, args): +< super().__init__(args) +< +< def forward(self, input_data): +< if isinstance(input_data, np.ndarray): +< input_data = [input_data] +< batch_size = input_data[0].shape[0] +< out_size = [batch_size*4, batch_size*10, batch_size*2] +< output_data = self.net_context(input_data, out_size) +< # postprocess: softmax && reshape +< output_data[0] = output_data[0].reshape([batch_size, 4]) +< output_data[1] = output_data[1].reshape([batch_size, 10]) +< output_data[2] = output_data[2].reshape([batch_size, 2]) +< output_data[2] = torch.softmax(torch.tensor(output_data[2]), dim=1).numpy() +< return output_data --- > import torch > from torch import nn diff --git a/ACL_PyTorch/contrib/cv/face/FaceNet/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/face/FaceNet/modelzoo_level.txt index 39175166a4b66dd0ead8d95dcb7ea49c56a868e3..119ddfc69182d1e11b6ce03723be060336966991 100644 --- a/ACL_PyTorch/contrib/cv/face/FaceNet/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/face/FaceNet/modelzoo_level.txt @@ -1,2 +1,2 @@ -ModelConvert:OK +ModelConvert:OK QuantStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/face/FaceNet/requirements.txt b/ACL_PyTorch/contrib/cv/face/FaceNet/requirements.txt index 8ff8888811ffbc725e4e497cdf2c15216daaabd5..475e994ace191b59b8e191a627a79d81fc88f683 100644 --- a/ACL_PyTorch/contrib/cv/face/FaceNet/requirements.txt +++ b/ACL_PyTorch/contrib/cv/face/FaceNet/requirements.txt @@ -1,11 +1,11 @@ -numpy==1.21.3 -pillow==8.4.0 -torch==1.10.0 -torchvision==0.11.1 -facenet_pytorch==2.5.2 -scikit-learn==1.0.1 -scipy==1.7.3 -tqdm==4.62.3 -easydict==1.9 -onnx==1.10.2 - +numpy==1.21.3 +pillow==8.4.0 +torch==1.10.0 +torchvision==0.11.1 +facenet_pytorch==2.5.2 +scikit-learn==1.0.1 +scipy==1.7.3 +tqdm==4.62.3 +easydict==1.9 +onnx==1.10.2 + diff --git a/ACL_PyTorch/contrib/cv/face/FaceNet/utils/batch_utils.py b/ACL_PyTorch/contrib/cv/face/FaceNet/utils/batch_utils.py index dccca4ccd9fa758a3738ca631845ffbe967f1b80..213eb9fabf4f586b6b92c7530fff6b688f4b3e2a 100644 --- a/ACL_PyTorch/contrib/cv/face/FaceNet/utils/batch_utils.py +++ b/ACL_PyTorch/contrib/cv/face/FaceNet/utils/batch_utils.py @@ -1,48 +1,48 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import numpy as np -import os -import argparse - - -def np2bin(save_np, save_name, save_path): - save_np.tofile(save_path + '/' + save_name + '_output_0.bin') - - -def bin2np(bin_path): - return np.fromfile(bin_path, dtype=np.float32) - - -def general_data(batch_size, data_root_path, save_root_path): - in_files = os.listdir(data_root_path) - for file_name in in_files: - file_index = file_name.split('_')[0] - bin_file = bin2np(data_root_path + '/' + file_name) - img_n = bin_file.shape[0] // 512 - bin_file = bin_file.reshape([img_n, 512]) - file_index_i = int(file_index) - for i in range(img_n): - if file_index_i * batch_size + i < 13233: - np2bin(bin_file[i], str(file_index_i * batch_size + i), save_root_path) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--batch_size', type=int, help='batch size') - parser.add_argument('--data_root_path', type=str, help='data path') - parser.add_argument('--save_root_path', type=str, help='save path') - arg = parser.parse_args() - general_data(arg.batch_size, arg.data_root_path, arg.save_root_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import numpy as np +import os +import argparse + + +def np2bin(save_np, save_name, save_path): + save_np.tofile(save_path + '/' + save_name + '_output_0.bin') + + +def bin2np(bin_path): + return np.fromfile(bin_path, dtype=np.float32) + + +def general_data(batch_size, data_root_path, save_root_path): + in_files = os.listdir(data_root_path) + for file_name in in_files: + file_index = file_name.split('_')[0] + bin_file = bin2np(data_root_path + '/' + file_name) + img_n = bin_file.shape[0] // 512 + bin_file = bin_file.reshape([img_n, 512]) + file_index_i = int(file_index) + for i in range(img_n): + if file_index_i * batch_size + i < 13233: + np2bin(bin_file[i], str(file_index_i * batch_size + i), save_root_path) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--batch_size', type=int, help='batch size') + parser.add_argument('--data_root_path', type=str, help='data path') + parser.add_argument('--save_root_path', type=str, help='save path') + arg = parser.parse_args() + general_data(arg.batch_size, arg.data_root_path, arg.save_root_path) diff --git a/ACL_PyTorch/contrib/cv/face/FaceNet/utils/fix_prelu.py b/ACL_PyTorch/contrib/cv/face/FaceNet/utils/fix_prelu.py index 6298e2bdc2b5640d1a05402f00ed053ceed90d99..b1f5bc239d19cc685bb7b4b899cd74b307b641a5 100644 --- a/ACL_PyTorch/contrib/cv/face/FaceNet/utils/fix_prelu.py +++ b/ACL_PyTorch/contrib/cv/face/FaceNet/utils/fix_prelu.py @@ -1,35 +1,35 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import sys -import numpy as np -from magiconnx import OnnxGraph - - -def fix_prelu(graph): - prelu_nodes = graph.get_nodes(op_type='PRelu') - for node in prelu_nodes: - slope_para = graph[node.inputs[1]] - fix_value = np.expand_dims(slope_para.value, axis=0) - slope_para.value = fix_value - return graph - - -if __name__ == '__main__': - input_model = sys.argv[1] - out_model = sys.argv[2] - onnx_graph = OnnxGraph(input_model) - onnx_graph = fix_prelu(onnx_graph) - onnx_graph.save(out_model) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import sys +import numpy as np +from magiconnx import OnnxGraph + + +def fix_prelu(graph): + prelu_nodes = graph.get_nodes(op_type='PRelu') + for node in prelu_nodes: + slope_para = graph[node.inputs[1]] + fix_value = np.expand_dims(slope_para.value, axis=0) + slope_para.value = fix_value + return graph + + +if __name__ == '__main__': + input_model = sys.argv[1] + out_model = sys.argv[2] + onnx_graph = OnnxGraph(input_model) + onnx_graph = fix_prelu(onnx_graph) + onnx_graph.save(out_model) diff --git a/ACL_PyTorch/contrib/cv/face/FaceNet/utils/gen_test_data.py b/ACL_PyTorch/contrib/cv/face/FaceNet/utils/gen_test_data.py index 85cd5a02599cc3e6dddc65e1a9f709fbb512e9f2..eac855cf4af764a675b6b4beb3e7ef7f325a4fd0 100644 --- a/ACL_PyTorch/contrib/cv/face/FaceNet/utils/gen_test_data.py +++ b/ACL_PyTorch/contrib/cv/face/FaceNet/utils/gen_test_data.py @@ -1,30 +1,30 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import os -import sys -import numpy as np - - -def gen_bin(save_name, data_shape): - data_bin = np.random.random(data_shape) - data_bin.tofile(os.path.join(save_name)) - - -if __name__ == '__main__': - save_path = sys.argv[1] - shape = sys.argv[2] - shape = list(map(int, shape.split(','))) - gen_bin(save_path, shape) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import os +import sys +import numpy as np + + +def gen_bin(save_name, data_shape): + data_bin = np.random.random(data_shape) + data_bin.tofile(os.path.join(save_name)) + + +if __name__ == '__main__': + save_path = sys.argv[1] + shape = sys.argv[2] + shape = list(map(int, shape.split(','))) + gen_bin(save_path, shape) diff --git a/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/LICENSE b/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/LICENSE +++ b/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/postprocess_MGN.py b/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/postprocess_MGN.py index 7e0f6a4b7e2aaae353799cc3b3f6708d98d62f4f..3ffd64386d5c35c37a4adc4db093bbf47e2088bb 100644 --- a/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/postprocess_MGN.py +++ b/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/postprocess_MGN.py @@ -1,163 +1,163 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License.jj - -import os -import sys -import numpy as np -import torch -import argparse -from scipy.spatial.distance import cdist -from tqdm import tqdm -sys.path.append('./MGN') -from MGN.data import Data -from MGN.utils.metrics import mean_ap, cmc, re_ranking - - -def save_batch_imgs(save_file_name, dataset_type, loader, need_flip=False): - ind = 0 - for (inputs, labels) in loader: - if need_flip == True: - inputs = inputs.index_select(3, torch.arange(inputs.size(3) - 1, -1, -1)) - for i in range(len(inputs)): - img_name = dataset_type + '/' + "{:0>5d}".format(ind) - save_path = opt.data_path - if(opt.data_path[-1] != '/'): - save_path += '/' - save_path += save_file_name - inputs[i].numpy().tofile(save_path + '/' + img_name + '.bin') - ind += 1 - - -def extract_feature_om(prediction_file_path, prediction_file_path_flip): - # make the list of files first - file_names, file_names_flip = [], [] - for file_name in os.listdir(prediction_file_path): - suffix = file_name.split('_')[-1] - if suffix == '1.txt': - file_names.append(file_name) - file_names.sort() - print("first 5 txt files: \n",file_names[:10]) - for file_name in os.listdir(prediction_file_path_flip): - suffix = file_name.split('_')[-1] - if suffix == '1.txt': - file_names_flip.append(file_name) - file_names_flip.sort() - if len(file_names) != len(file_names_flip): - print('num of filp features doesnt match that of orig') - features = torch.FloatTensor() - for i in range(len(file_names)): - fea_path = os.path.join(prediction_file_path, file_names[i]) - fea_path_f = os.path.join(prediction_file_path_flip, file_names_flip[i]) - f1 = torch.from_numpy(np.loadtxt(fea_path, dtype=np.float32)) - f2 = torch.from_numpy(np.loadtxt(fea_path_f, dtype=np.float32)) - ff = f1 + f2 - ff = torch.unsqueeze(ff, 0) - fnorm = torch.norm(ff, p=2, dim=1, keepdim=True) - ff = ff.div(fnorm.expand_as(ff)) - features = torch.cat((features, ff), 0) - if i < 8: - print(i, "th f1: \n", f1.shape, f1) - print(i, "th f2: \n", f2.shape, f2) - print(i, "th ff: \n", ff.shape, ff) - if i % 100 == 0: - print("the " + str(i) + "th image file is extracted.") - return features - - -class Main(): - def __init__(self, data): - self.train_loader = data.train_loader - self.test_loader = data.test_loader - self.query_loader = data.query_loader - self.testset = data.testset - self.queryset = data.queryset - - def evaluate_om(self): - query_prediction_file_path, query_prediction_file_path_flip = './result/q_bin/dumpOutput_device0/', \ - './result/q_bin_flip/dumpOutput_device0/' - gallery_prediction_file_path, gallery_prediction_file_path_flip = './result/g_bin/dumpOutput_device0/', \ - './result/g_bin_flip/dumpOutput_device0/' - print('extract features, this may take a few minutes') - qf = extract_feature_om(query_prediction_file_path, query_prediction_file_path_flip).numpy() - gf = extract_feature_om(gallery_prediction_file_path, gallery_prediction_file_path_flip).numpy() - print("shape of features, qf: " + str(qf.shape) + "gf: " + str(gf.shape)) - print("arr qf: \n", qf[:10, :10]) - print("arr gf: \n", gf[:10, :10]) - - def rank(dist): - r = cmc(dist, self.queryset.ids, self.testset.ids, self.queryset.cameras, self.testset.cameras, - separate_camera_set=False, - single_gallery_shot=False, - first_match_break=True) - m_ap = mean_ap(dist, self.queryset.ids, self.testset.ids, self.queryset.cameras, self.testset.cameras) - return r, m_ap - ######################### re rank########################## - q_g_dist = np.dot(qf, np.transpose(gf)) - q_q_dist = np.dot(qf, np.transpose(qf)) - g_g_dist = np.dot(gf, np.transpose(gf)) - dist = re_ranking(q_g_dist, q_q_dist, g_g_dist) - r, m_ap = rank(dist) - print('[With Re-Ranking] mAP: {:.4f} rank1: {:.4f} rank3: {:.4f} rank5: {:.4f} rank10: {:.4f}' - .format(m_ap, r[0], r[2], r[4], r[9])) - #########################no re rank########################## - dist = cdist(qf, gf) - r, m_ap = rank(dist) - print('[Without Re-Ranking] mAP: {:.4f} rank1: {:.4f} rank3: {:.4f} rank5: {:.4f} rank10: {:.4f}' - .format(m_ap, r[0], r[2], r[4], r[9])) - - def save_data(self): - save_file_name = 'bin_data' - save_file_name_flip = 'bin_data_flip' - print('saving images, this may take a few minutes') - save_batch_imgs(save_file_name, 'q', tqdm(self.query_loader)) - save_batch_imgs(save_file_name, 'g', tqdm(self.test_loader)) - save_batch_imgs(save_file_name_flip, 'q', tqdm(self.query_loader), need_flip=True) - save_batch_imgs(save_file_name_flip, 'g', tqdm(self.test_loader), need_flip=True) - - -def parse_func(): - parser = argparse.ArgumentParser() - parser.add_argument('--data_path', - default="Market-1501-v15.09.15", - help='path of Market-1501-v15.09.15') - parser.add_argument('--mode', - default='train', choices=['train', 'evaluate', 'evaluate_om', 'save_bin', 'vis'], - help='train or evaluate ') - parser.add_argument('--query_image', - default='0001_c1s1_001051_00.jpg', - help='path to the image you want to query') - parser.add_argument("--batchid", - default=4, - help='the batch for id') - parser.add_argument("--batchimage", - default=4, - help='the batch of per id') - parser.add_argument("--batchtest", - default=8, - help='the batch size for test') - return parser.parse_args() - - -if __name__ == '__main__': - opt = parse_func() - data = Data(opt) - main = Main(data) - if opt.mode == 'evaluate_om': - print('start evaluate om') - main.evaluate_om() - elif opt.mode == 'save_bin': - print('start evaluate') - main.save_data() - else: +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.jj + +import os +import sys +import numpy as np +import torch +import argparse +from scipy.spatial.distance import cdist +from tqdm import tqdm +sys.path.append('./MGN') +from MGN.data import Data +from MGN.utils.metrics import mean_ap, cmc, re_ranking + + +def save_batch_imgs(save_file_name, dataset_type, loader, need_flip=False): + ind = 0 + for (inputs, labels) in loader: + if need_flip == True: + inputs = inputs.index_select(3, torch.arange(inputs.size(3) - 1, -1, -1)) + for i in range(len(inputs)): + img_name = dataset_type + '/' + "{:0>5d}".format(ind) + save_path = opt.data_path + if(opt.data_path[-1] != '/'): + save_path += '/' + save_path += save_file_name + inputs[i].numpy().tofile(save_path + '/' + img_name + '.bin') + ind += 1 + + +def extract_feature_om(prediction_file_path, prediction_file_path_flip): + # make the list of files first + file_names, file_names_flip = [], [] + for file_name in os.listdir(prediction_file_path): + suffix = file_name.split('_')[-1] + if suffix == '1.txt': + file_names.append(file_name) + file_names.sort() + print("first 5 txt files: \n",file_names[:10]) + for file_name in os.listdir(prediction_file_path_flip): + suffix = file_name.split('_')[-1] + if suffix == '1.txt': + file_names_flip.append(file_name) + file_names_flip.sort() + if len(file_names) != len(file_names_flip): + print('num of filp features doesnt match that of orig') + features = torch.FloatTensor() + for i in range(len(file_names)): + fea_path = os.path.join(prediction_file_path, file_names[i]) + fea_path_f = os.path.join(prediction_file_path_flip, file_names_flip[i]) + f1 = torch.from_numpy(np.loadtxt(fea_path, dtype=np.float32)) + f2 = torch.from_numpy(np.loadtxt(fea_path_f, dtype=np.float32)) + ff = f1 + f2 + ff = torch.unsqueeze(ff, 0) + fnorm = torch.norm(ff, p=2, dim=1, keepdim=True) + ff = ff.div(fnorm.expand_as(ff)) + features = torch.cat((features, ff), 0) + if i < 8: + print(i, "th f1: \n", f1.shape, f1) + print(i, "th f2: \n", f2.shape, f2) + print(i, "th ff: \n", ff.shape, ff) + if i % 100 == 0: + print("the " + str(i) + "th image file is extracted.") + return features + + +class Main(): + def __init__(self, data): + self.train_loader = data.train_loader + self.test_loader = data.test_loader + self.query_loader = data.query_loader + self.testset = data.testset + self.queryset = data.queryset + + def evaluate_om(self): + query_prediction_file_path, query_prediction_file_path_flip = './result/q_bin/dumpOutput_device0/', \ + './result/q_bin_flip/dumpOutput_device0/' + gallery_prediction_file_path, gallery_prediction_file_path_flip = './result/g_bin/dumpOutput_device0/', \ + './result/g_bin_flip/dumpOutput_device0/' + print('extract features, this may take a few minutes') + qf = extract_feature_om(query_prediction_file_path, query_prediction_file_path_flip).numpy() + gf = extract_feature_om(gallery_prediction_file_path, gallery_prediction_file_path_flip).numpy() + print("shape of features, qf: " + str(qf.shape) + "gf: " + str(gf.shape)) + print("arr qf: \n", qf[:10, :10]) + print("arr gf: \n", gf[:10, :10]) + + def rank(dist): + r = cmc(dist, self.queryset.ids, self.testset.ids, self.queryset.cameras, self.testset.cameras, + separate_camera_set=False, + single_gallery_shot=False, + first_match_break=True) + m_ap = mean_ap(dist, self.queryset.ids, self.testset.ids, self.queryset.cameras, self.testset.cameras) + return r, m_ap + ######################### re rank########################## + q_g_dist = np.dot(qf, np.transpose(gf)) + q_q_dist = np.dot(qf, np.transpose(qf)) + g_g_dist = np.dot(gf, np.transpose(gf)) + dist = re_ranking(q_g_dist, q_q_dist, g_g_dist) + r, m_ap = rank(dist) + print('[With Re-Ranking] mAP: {:.4f} rank1: {:.4f} rank3: {:.4f} rank5: {:.4f} rank10: {:.4f}' + .format(m_ap, r[0], r[2], r[4], r[9])) + #########################no re rank########################## + dist = cdist(qf, gf) + r, m_ap = rank(dist) + print('[Without Re-Ranking] mAP: {:.4f} rank1: {:.4f} rank3: {:.4f} rank5: {:.4f} rank10: {:.4f}' + .format(m_ap, r[0], r[2], r[4], r[9])) + + def save_data(self): + save_file_name = 'bin_data' + save_file_name_flip = 'bin_data_flip' + print('saving images, this may take a few minutes') + save_batch_imgs(save_file_name, 'q', tqdm(self.query_loader)) + save_batch_imgs(save_file_name, 'g', tqdm(self.test_loader)) + save_batch_imgs(save_file_name_flip, 'q', tqdm(self.query_loader), need_flip=True) + save_batch_imgs(save_file_name_flip, 'g', tqdm(self.test_loader), need_flip=True) + + +def parse_func(): + parser = argparse.ArgumentParser() + parser.add_argument('--data_path', + default="Market-1501-v15.09.15", + help='path of Market-1501-v15.09.15') + parser.add_argument('--mode', + default='train', choices=['train', 'evaluate', 'evaluate_om', 'save_bin', 'vis'], + help='train or evaluate ') + parser.add_argument('--query_image', + default='0001_c1s1_001051_00.jpg', + help='path to the image you want to query') + parser.add_argument("--batchid", + default=4, + help='the batch for id') + parser.add_argument("--batchimage", + default=4, + help='the batch of per id') + parser.add_argument("--batchtest", + default=8, + help='the batch size for test') + return parser.parse_args() + + +if __name__ == '__main__': + opt = parse_func() + data = Data(opt) + main = Main(data) + if opt.mode == 'evaluate_om': + print('start evaluate om') + main.evaluate_om() + elif opt.mode == 'save_bin': + print('start evaluate') + main.save_data() + else: raise NotImplementedError() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/preprocess_MGN.py b/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/preprocess_MGN.py index b76d6739bcea5c528a031970f0e583e5b5644bd8..d5cab0450c20d502d0d15be2f9c0fceffa6a6191 100644 --- a/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/preprocess_MGN.py +++ b/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/preprocess_MGN.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/pth2onnx.py b/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/pth2onnx.py index 9a550c9fe93d983a6fd92e5a4282b0a010da2bcb..9cf592a866cee79048bc34c03b252b518f55596b 100644 --- a/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/pth2onnx.py @@ -1,40 +1,40 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import torch -sys.path.append("./MGN") -from MGN.network import MGN -os.environ['CUDA_VISIBLE_DEVICES'] = '0' - - -def pth2onnx(input_file, output_file, batch_size): - model = MGN() - model = model.to('cpu') - model.load_state_dict(torch.load(input_file, map_location=torch.device('cpu'))) - model.eval() - input_names = ["image"] - output_names = ["features"] - dynamic_axes = {'image': {0: '-1'}, 'features': {0: '-1'}} - dummy_input = torch.randn(batch_size, 3, 384, 128) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, - dynamic_axes = dynamic_axes, output_names = output_names, - opset_version=11, verbose=True) - print("***********************************Convert to ONNX model file SUCCESS!***" - "*******************************************") - - -if __name__ == '__main__': +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import torch +sys.path.append("./MGN") +from MGN.network import MGN +os.environ['CUDA_VISIBLE_DEVICES'] = '0' + + +def pth2onnx(input_file, output_file, batch_size): + model = MGN() + model = model.to('cpu') + model.load_state_dict(torch.load(input_file, map_location=torch.device('cpu'))) + model.eval() + input_names = ["image"] + output_names = ["features"] + dynamic_axes = {'image': {0: '-1'}, 'features': {0: '-1'}} + dummy_input = torch.randn(batch_size, 3, 384, 128) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, + dynamic_axes = dynamic_axes, output_names = output_names, + opset_version=11, verbose=True) + print("***********************************Convert to ONNX model file SUCCESS!***" + "*******************************************") + + +if __name__ == '__main__': pth2onnx(sys.argv[1], sys.argv[2], int(sys.argv[3])) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/requirements.txt b/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/requirements.txt index 71bce80b95e60048b41a84f2fa5a6f59814087c9..7a28b67e6842ef317dfa0b09c5cfb0cd2db84342 100644 --- a/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/requirements.txt +++ b/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/requirements.txt @@ -1,4 +1,4 @@ -torchvision>=0.6.0 -onnx>=1.7.0 -torch==1.7.0 -albumentations == 1.0.0 +torchvision>=0.6.0 +onnx>=1.7.0 +torch==1.7.0 +albumentations == 1.0.0 diff --git a/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/test/README.md b/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/test/README.md index ca7c62c2cc89353020f6ec57718ccbed3beaef6e..6e58e8cb1409740eb067f283a02c30d59069ea3a 100644 --- a/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/test/README.md +++ b/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/test/README.md @@ -1,54 +1,54 @@ -环境准备: - -1.数据集路径 -- [Market1501数据集获取路径](https://pan.baidu.com/s/1ntIi2Op?_at_=1624593258681) -- 原始数据集已经放在/opt/npu/Market1501/下,应在./ReID-MGN-master/data/下新建Market1501目录,将/opt/npu/Market1501/下的文件拷贝到./ReID-MGN-master/data/Market1501下 -- ./data/Market1501/路径下,需要新建bin_data和bin_data_flip两个路径,bin_data和bin_data_flip两个路径下分别新建q和g两个路径 -- 需要新建model路径,预训练文件model.pt放在该路径下 -- 具体命令参考下文 - - -2.进入工作目录 -``` -cd /ReID-MGN-master -mkdir -p ./data/Market1501 -cp -r /opt/npu/Market1501/* ./data/Market1501/ -mkdir -p ./data/Market1501/bin_data/q -mkdir -p ./data/Market1501/bin_data/p -mkdir -p ./data/Market1501/bin_data_flip/q -mkdir -p ./data/Market1501/bin_data_flip/p -mkdir model -``` - -3.安装必要的依赖 -``` -pip3.7 install -r requirements.txt -``` - -4.获取模型代码 -``` -git clone https://github.com/GNAYUOHZ/ReID-MGN.git MGN -cd MGN && git checkout f0251e9e6003ec6f2c3fbc8ce5741d21436c20cf && cd - -patch -R MGN/data.py < module.patch -``` - -5.获取权重文件 -``` -(https://pan.baidu.com/s/12AkumLX10hLx9vh_SQwdyw) password:mrl5 -cp ${model.pt} ./model -``` - -6.获取benchmark工具 -``` -将benchmark.x86_64放在当前目录 -``` - -7.310上执行,执行时确保device空闲 -``` -source env.sh -apt install dos2unix -dos2unix test/pth2om.sh -bash test/pth2om.sh -dos2unix test/eval_acc_perf.sh -bash test/eval_acc_perf.sh -``` +环境准备: + +1.数据集路径 +- [Market1501数据集获取路径](https://pan.baidu.com/s/1ntIi2Op?_at_=1624593258681) +- 原始数据集已经放在/opt/npu/Market1501/下,应在./ReID-MGN-master/data/下新建Market1501目录,将/opt/npu/Market1501/下的文件拷贝到./ReID-MGN-master/data/Market1501下 +- ./data/Market1501/路径下,需要新建bin_data和bin_data_flip两个路径,bin_data和bin_data_flip两个路径下分别新建q和g两个路径 +- 需要新建model路径,预训练文件model.pt放在该路径下 +- 具体命令参考下文 + + +2.进入工作目录 +``` +cd /ReID-MGN-master +mkdir -p ./data/Market1501 +cp -r /opt/npu/Market1501/* ./data/Market1501/ +mkdir -p ./data/Market1501/bin_data/q +mkdir -p ./data/Market1501/bin_data/p +mkdir -p ./data/Market1501/bin_data_flip/q +mkdir -p ./data/Market1501/bin_data_flip/p +mkdir model +``` + +3.安装必要的依赖 +``` +pip3.7 install -r requirements.txt +``` + +4.获取模型代码 +``` +git clone https://github.com/GNAYUOHZ/ReID-MGN.git MGN +cd MGN && git checkout f0251e9e6003ec6f2c3fbc8ce5741d21436c20cf && cd - +patch -R MGN/data.py < module.patch +``` + +5.获取权重文件 +``` +(https://pan.baidu.com/s/12AkumLX10hLx9vh_SQwdyw) password:mrl5 +cp ${model.pt} ./model +``` + +6.获取benchmark工具 +``` +将benchmark.x86_64放在当前目录 +``` + +7.310上执行,执行时确保device空闲 +``` +source env.sh +apt install dos2unix +dos2unix test/pth2om.sh +bash test/pth2om.sh +dos2unix test/eval_acc_perf.sh +bash test/eval_acc_perf.sh +``` diff --git a/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/test/parse.py b/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/test/parse.py index b9c74f41d7848e1250356f14472b237a18bb3489..82af69cd183218c3263723c20b652b3f7ec2bc27 100644 --- a/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/test/parse.py +++ b/ACL_PyTorch/contrib/cv/face/ReId-MGN-master/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/face/Retinaface/aipp.cfg b/ACL_PyTorch/contrib/cv/face/Retinaface/aipp.cfg index 57715b3180c177204da7ebbf612fa2564aff3453..a19ab6ac2d74bab64e4d80d969b3b342d25f27b1 100644 --- a/ACL_PyTorch/contrib/cv/face/Retinaface/aipp.cfg +++ b/ACL_PyTorch/contrib/cv/face/Retinaface/aipp.cfg @@ -1,15 +1,15 @@ -aipp_op { -aipp_mode: static - -input_format: RGB888_U8 -src_image_size_w: 1000 -src_image_size_h: 1000 - -mean_chn_0: 104 -mean_chn_1: 117 -mean_chn_2: 123 - -var_reci_chn_0: 1 -var_reci_chn_1: 1 -var_reci_chn_2: 1 +aipp_op { +aipp_mode: static + +input_format: RGB888_U8 +src_image_size_w: 1000 +src_image_size_h: 1000 + +mean_chn_0: 104 +mean_chn_1: 117 +mean_chn_2: 123 + +var_reci_chn_0: 1 +var_reci_chn_1: 1 +var_reci_chn_2: 1 } \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/LICENSE b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/LICENSE +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/PCB_pth_postprocess.py b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/PCB_pth_postprocess.py index adc013a082d39bfaee5b880fe239b9e32d03c924..873e88ad7665a6f90644c991a65bd450008fa403 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/PCB_pth_postprocess.py +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/PCB_pth_postprocess.py @@ -1,264 +1,264 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import os.path as osp -import os -import numpy as np -import torch -import datasets -from sklearn.metrics import average_precision_score -from collections import OrderedDict -from collections import defaultdict -import json - - -def get_data(name, data_dir): - root = osp.join(data_dir, name) - root = data_dir - dataset = datasets.create(name, root) - return dataset - - -def pairwise_distance(query_features, gallery_features, query=None, gallery=None): - x = torch.cat([query_features[f].unsqueeze(0) for f, _, _ in query], 0) - y = torch.cat([gallery_features[f].unsqueeze(0) for f, _, _ in gallery], 0) - m, n = x.size(0), y.size(0) - x = x.view(m, -1) - y = y.view(n, -1) - dist = torch.pow(x, 2).sum(1).unsqueeze(1).expand(m, n) + \ - torch.pow(y, 2).sum(1).unsqueeze(1).expand(n, m).t() - dist.addmm_(1, -2, x, y.t()) - return dist - - -def _unique_sample(ids_dict, num): - mask = np.zeros(num, dtype=np.bool) - for _, indices in ids_dict.items(): - i = np.random.choice(indices) - mask[i] = True - return mask - - -def cmc(distmat, query_ids=None, gallery_ids=None, - query_cams=None, gallery_cams=None, topk=100, - separate_camera_set=False, - single_gallery_shot=False, - first_match_break=False): - distmat = to_numpy(distmat) - m, n = distmat.shape - # Fill up default values - if query_ids is None: - query_ids = np.arange(m) - if gallery_ids is None: - gallery_ids = np.arange(n) - if query_cams is None: - query_cams = np.zeros(m).astype(np.int32) - if gallery_cams is None: - gallery_cams = np.ones(n).astype(np.int32) - # Ensure numpy array - query_ids = np.asarray(query_ids) - gallery_ids = np.asarray(gallery_ids) - query_cams = np.asarray(query_cams) - gallery_cams = np.asarray(gallery_cams) - # Sort and find correct matches - indices = np.argsort(distmat, axis=1) - matches = (gallery_ids[indices] == query_ids[:, np.newaxis]) - # Compute CMC for each query - ret = np.zeros(topk) - num_valid_queries = 0 - for i in range(m): - # Filter out the same id and same camera - valid = ((gallery_ids[indices[i]] != query_ids[i]) | - (gallery_cams[indices[i]] != query_cams[i])) - if separate_camera_set: - # Filter out samples from same camera - valid &= (gallery_cams[indices[i]] != query_cams[i]) - if not np.any(matches[i, valid]): continue - if single_gallery_shot: - repeat = 10 - gids = gallery_ids[indices[i][valid]] - inds = np.where(valid)[0] - ids_dict = defaultdict(list) - for j, x in zip(inds, gids): - ids_dict[x].append(j) - else: - repeat = 1 - for _ in range(repeat): - if single_gallery_shot: - # Randomly choose one instance for each id - sampled = (valid & _unique_sample(ids_dict, len(valid))) - index = np.nonzero(matches[i, sampled])[0] - else: - index = np.nonzero(matches[i, valid])[0] - delta = 1. / (len(index) * repeat) - for j, k in enumerate(index): - if k - j >= topk: break - if first_match_break: - ret[k - j] += 1 - break - ret[k - j] += delta - num_valid_queries += 1 - if num_valid_queries == 0: - raise RuntimeError("No valid query") - return ret.cumsum() / num_valid_queries - - -def to_numpy(tensor): - if torch.is_tensor(tensor): - return tensor.cpu().numpy() - elif type(tensor).__module__ != 'numpy': - raise ValueError("Cannot convert {} to numpy array" - .format(type(tensor))) - return tensor - - -def mean_ap(distmat, query_ids=None, gallery_ids=None, - query_cams=None, gallery_cams=None): - distmat = to_numpy(distmat) - m, n = distmat.shape - # Fill up default values - if query_ids is None: - query_ids = np.arange(m) - if gallery_ids is None: - gallery_ids = np.arange(n) - if query_cams is None: - query_cams = np.zeros(m).astype(np.int32) - if gallery_cams is None: - gallery_cams = np.ones(n).astype(np.int32) - # Ensure numpy array - query_ids = np.asarray(query_ids) - gallery_ids = np.asarray(gallery_ids) - query_cams = np.asarray(query_cams) - gallery_cams = np.asarray(gallery_cams) - # Sort and find correct matches - indices = np.argsort(distmat, axis=1) - matches = (gallery_ids[indices] == query_ids[:, np.newaxis]) - # Compute AP for each query - aps = [] - for i in range(m): - # Filter out the same id and same camera - valid = ((gallery_ids[indices[i]] != query_ids[i]) | - (gallery_cams[indices[i]] != query_cams[i])) - y_true = matches[i, valid] - y_score = -distmat[i][indices[i]][valid] - if not np.any(y_true): continue - aps.append(average_precision_score(y_true, y_score)) - if len(aps) == 0: - raise RuntimeError("No valid query") - return np.mean(aps) - - -def evaluate_all(distmat, query=None, gallery=None, - query_ids=None, gallery_ids=None, - query_cams=None, gallery_cams=None, - cmc_topk=(1, 5, 10)): - if query is not None and gallery is not None: - query_ids = [pid for _, pid, _ in query] - gallery_ids = [pid for _, pid, _ in gallery] - query_cams = [cam for _, _, cam in query] - gallery_cams = [cam for _, _, cam in gallery] - else: - assert (query_ids is not None and gallery_ids is not None - and query_cams is not None and gallery_cams is not None) - # Compute mean AP - mAP = mean_ap(distmat, query_ids, gallery_ids, query_cams, gallery_cams) - print('Mean AP: {:4.1%}'.format(mAP)) - # Compute all kinds of CMC scores - cmc_configs = { - 'allshots': dict(separate_camera_set=False, - single_gallery_shot=False, - first_match_break=False), - 'cuhk03': dict(separate_camera_set=True, - single_gallery_shot=True, - first_match_break=False), - 'market1501': dict(separate_camera_set=False, - single_gallery_shot=False, - first_match_break=True)} - cmc_scores = {name: cmc(distmat, query_ids, gallery_ids, - query_cams, gallery_cams, **params) - for name, params in cmc_configs.items()} - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - table_dict["value"].extend( - [{"key": "Number of images", "value": str(15913)}, - {"key": "Number of classes", "value": str(751)}]) - for k in cmc_topk: - table_dict["value"].append({"key": "Top-" + str(k) + " accuracy", - "value": str('{:.1%}'.format(cmc_scores['market1501'][k - 1]))}) - print('CMC Scores{:>12}' - .format('market1501')) - for k in cmc_topk: - print(' top-{:<4}{:12.1%}' - .format(k, cmc_scores['market1501'][k - 1])) - - print(table_dict) - writer = open('PCB_inference_result.json', 'w') - json.dump(table_dict, writer) - writer.close() - # Use the allshots cmc top-1 score for validation criterion - return cmc_scores['allshots'][0] - - -def load_result(filepath): - count = 0 - features = OrderedDict() - for root, dirs, files in os.walk(filepath): - for file in files: - file_tmp = file.split('.', 2)[0] - list_file = file_tmp.split('_') - if list_file[4] == '1': - file = filepath + '/' + file - output = np.fromfile(file, dtype='float32') - output = torch.from_numpy(output) - output = output.reshape(2048, 6, 1) - filename = list_file[0] + '_' + list_file[1] + '_' + list_file[2] + '_' + list_file[3] + '.jpg' - if list_file[0] == '1488' or filename == '0000_c6s3_094992_01.jpg' \ - or filename == '0000_c4s6_022316_04.jpg' or filename == '0000_c1s6_023071_04.jpg': - filename = filename + '.jpg' - features[filename] = output - count = count + 1 - return features - - -def evaluate_Ascend310(query_filepath, gallery_filepath, query, gallery): - print('extracting query features\n') - query_features_0 = load_result(query_filepath) - print('extracting gallery features\n') - gallery_features_0 = load_result(gallery_filepath) - distmat = pairwise_distance(query_features_0, gallery_features_0, query, gallery) - return evaluate_all(distmat, query=query, gallery=gallery) - - -def main(args): - dataset = get_data(args.dataset, args.data_dir) - evaluate_Ascend310(args.query, args.gallery, dataset.query, dataset.gallery) - return - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description="Softmax loss classification") - - parser.add_argument('-q', '--query', type=str, default='./dumpOutput_device0_query') - - parser.add_argument('-g', '--gallery', type=str, default='./dumpOutput_device0_gallery') - parser.add_argument('-d', '--dataset', type=str, default='market', - choices=datasets.names()) - - parser.add_argument('--data-dir', type=str, metavar='PATH', - default='./datasets/Market-1501/') - - main(parser.parse_args()) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import os.path as osp +import os +import numpy as np +import torch +import datasets +from sklearn.metrics import average_precision_score +from collections import OrderedDict +from collections import defaultdict +import json + + +def get_data(name, data_dir): + root = osp.join(data_dir, name) + root = data_dir + dataset = datasets.create(name, root) + return dataset + + +def pairwise_distance(query_features, gallery_features, query=None, gallery=None): + x = torch.cat([query_features[f].unsqueeze(0) for f, _, _ in query], 0) + y = torch.cat([gallery_features[f].unsqueeze(0) for f, _, _ in gallery], 0) + m, n = x.size(0), y.size(0) + x = x.view(m, -1) + y = y.view(n, -1) + dist = torch.pow(x, 2).sum(1).unsqueeze(1).expand(m, n) + \ + torch.pow(y, 2).sum(1).unsqueeze(1).expand(n, m).t() + dist.addmm_(1, -2, x, y.t()) + return dist + + +def _unique_sample(ids_dict, num): + mask = np.zeros(num, dtype=np.bool) + for _, indices in ids_dict.items(): + i = np.random.choice(indices) + mask[i] = True + return mask + + +def cmc(distmat, query_ids=None, gallery_ids=None, + query_cams=None, gallery_cams=None, topk=100, + separate_camera_set=False, + single_gallery_shot=False, + first_match_break=False): + distmat = to_numpy(distmat) + m, n = distmat.shape + # Fill up default values + if query_ids is None: + query_ids = np.arange(m) + if gallery_ids is None: + gallery_ids = np.arange(n) + if query_cams is None: + query_cams = np.zeros(m).astype(np.int32) + if gallery_cams is None: + gallery_cams = np.ones(n).astype(np.int32) + # Ensure numpy array + query_ids = np.asarray(query_ids) + gallery_ids = np.asarray(gallery_ids) + query_cams = np.asarray(query_cams) + gallery_cams = np.asarray(gallery_cams) + # Sort and find correct matches + indices = np.argsort(distmat, axis=1) + matches = (gallery_ids[indices] == query_ids[:, np.newaxis]) + # Compute CMC for each query + ret = np.zeros(topk) + num_valid_queries = 0 + for i in range(m): + # Filter out the same id and same camera + valid = ((gallery_ids[indices[i]] != query_ids[i]) | + (gallery_cams[indices[i]] != query_cams[i])) + if separate_camera_set: + # Filter out samples from same camera + valid &= (gallery_cams[indices[i]] != query_cams[i]) + if not np.any(matches[i, valid]): continue + if single_gallery_shot: + repeat = 10 + gids = gallery_ids[indices[i][valid]] + inds = np.where(valid)[0] + ids_dict = defaultdict(list) + for j, x in zip(inds, gids): + ids_dict[x].append(j) + else: + repeat = 1 + for _ in range(repeat): + if single_gallery_shot: + # Randomly choose one instance for each id + sampled = (valid & _unique_sample(ids_dict, len(valid))) + index = np.nonzero(matches[i, sampled])[0] + else: + index = np.nonzero(matches[i, valid])[0] + delta = 1. / (len(index) * repeat) + for j, k in enumerate(index): + if k - j >= topk: break + if first_match_break: + ret[k - j] += 1 + break + ret[k - j] += delta + num_valid_queries += 1 + if num_valid_queries == 0: + raise RuntimeError("No valid query") + return ret.cumsum() / num_valid_queries + + +def to_numpy(tensor): + if torch.is_tensor(tensor): + return tensor.cpu().numpy() + elif type(tensor).__module__ != 'numpy': + raise ValueError("Cannot convert {} to numpy array" + .format(type(tensor))) + return tensor + + +def mean_ap(distmat, query_ids=None, gallery_ids=None, + query_cams=None, gallery_cams=None): + distmat = to_numpy(distmat) + m, n = distmat.shape + # Fill up default values + if query_ids is None: + query_ids = np.arange(m) + if gallery_ids is None: + gallery_ids = np.arange(n) + if query_cams is None: + query_cams = np.zeros(m).astype(np.int32) + if gallery_cams is None: + gallery_cams = np.ones(n).astype(np.int32) + # Ensure numpy array + query_ids = np.asarray(query_ids) + gallery_ids = np.asarray(gallery_ids) + query_cams = np.asarray(query_cams) + gallery_cams = np.asarray(gallery_cams) + # Sort and find correct matches + indices = np.argsort(distmat, axis=1) + matches = (gallery_ids[indices] == query_ids[:, np.newaxis]) + # Compute AP for each query + aps = [] + for i in range(m): + # Filter out the same id and same camera + valid = ((gallery_ids[indices[i]] != query_ids[i]) | + (gallery_cams[indices[i]] != query_cams[i])) + y_true = matches[i, valid] + y_score = -distmat[i][indices[i]][valid] + if not np.any(y_true): continue + aps.append(average_precision_score(y_true, y_score)) + if len(aps) == 0: + raise RuntimeError("No valid query") + return np.mean(aps) + + +def evaluate_all(distmat, query=None, gallery=None, + query_ids=None, gallery_ids=None, + query_cams=None, gallery_cams=None, + cmc_topk=(1, 5, 10)): + if query is not None and gallery is not None: + query_ids = [pid for _, pid, _ in query] + gallery_ids = [pid for _, pid, _ in gallery] + query_cams = [cam for _, _, cam in query] + gallery_cams = [cam for _, _, cam in gallery] + else: + assert (query_ids is not None and gallery_ids is not None + and query_cams is not None and gallery_cams is not None) + # Compute mean AP + mAP = mean_ap(distmat, query_ids, gallery_ids, query_cams, gallery_cams) + print('Mean AP: {:4.1%}'.format(mAP)) + # Compute all kinds of CMC scores + cmc_configs = { + 'allshots': dict(separate_camera_set=False, + single_gallery_shot=False, + first_match_break=False), + 'cuhk03': dict(separate_camera_set=True, + single_gallery_shot=True, + first_match_break=False), + 'market1501': dict(separate_camera_set=False, + single_gallery_shot=False, + first_match_break=True)} + cmc_scores = {name: cmc(distmat, query_ids, gallery_ids, + query_cams, gallery_cams, **params) + for name, params in cmc_configs.items()} + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + table_dict["value"].extend( + [{"key": "Number of images", "value": str(15913)}, + {"key": "Number of classes", "value": str(751)}]) + for k in cmc_topk: + table_dict["value"].append({"key": "Top-" + str(k) + " accuracy", + "value": str('{:.1%}'.format(cmc_scores['market1501'][k - 1]))}) + print('CMC Scores{:>12}' + .format('market1501')) + for k in cmc_topk: + print(' top-{:<4}{:12.1%}' + .format(k, cmc_scores['market1501'][k - 1])) + + print(table_dict) + writer = open('PCB_inference_result.json', 'w') + json.dump(table_dict, writer) + writer.close() + # Use the allshots cmc top-1 score for validation criterion + return cmc_scores['allshots'][0] + + +def load_result(filepath): + count = 0 + features = OrderedDict() + for root, dirs, files in os.walk(filepath): + for file in files: + file_tmp = file.split('.', 2)[0] + list_file = file_tmp.split('_') + if list_file[4] == '1': + file = filepath + '/' + file + output = np.fromfile(file, dtype='float32') + output = torch.from_numpy(output) + output = output.reshape(2048, 6, 1) + filename = list_file[0] + '_' + list_file[1] + '_' + list_file[2] + '_' + list_file[3] + '.jpg' + if list_file[0] == '1488' or filename == '0000_c6s3_094992_01.jpg' \ + or filename == '0000_c4s6_022316_04.jpg' or filename == '0000_c1s6_023071_04.jpg': + filename = filename + '.jpg' + features[filename] = output + count = count + 1 + return features + + +def evaluate_Ascend310(query_filepath, gallery_filepath, query, gallery): + print('extracting query features\n') + query_features_0 = load_result(query_filepath) + print('extracting gallery features\n') + gallery_features_0 = load_result(gallery_filepath) + distmat = pairwise_distance(query_features_0, gallery_features_0, query, gallery) + return evaluate_all(distmat, query=query, gallery=gallery) + + +def main(args): + dataset = get_data(args.dataset, args.data_dir) + evaluate_Ascend310(args.query, args.gallery, dataset.query, dataset.gallery) + return + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description="Softmax loss classification") + + parser.add_argument('-q', '--query', type=str, default='./dumpOutput_device0_query') + + parser.add_argument('-g', '--gallery', type=str, default='./dumpOutput_device0_gallery') + parser.add_argument('-d', '--dataset', type=str, default='market', + choices=datasets.names()) + + parser.add_argument('--data-dir', type=str, metavar='PATH', + default='./datasets/Market-1501/') + + main(parser.parse_args()) diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/PCB_pth_preprocess.py b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/PCB_pth_preprocess.py index b1ccc34faf0a22ff64a155f9f5d5144ae12545a4..26f765fd6ec01428a8f3d357e6e8f65c4fc49239 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/PCB_pth_preprocess.py +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/PCB_pth_preprocess.py @@ -1,158 +1,158 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import os.path as osp -import os -import numpy as np -from torch.utils.data import DataLoader -import datasets -from torchvision.transforms import Normalize, RandomHorizontalFlip, ToTensor, Compose -from PIL import Image - - -class Preprocessor(object): - def __init__(self, dataset, root=None, transform=None): - super(Preprocessor, self).__init__() - self.dataset = dataset - self.root = root - self.transform = transform - - def __len__(self): - return len(self.dataset) - - def __getitem__(self, indices): - if isinstance(indices, (tuple, list)): - return [self._get_single_item(index) for index in indices] - return self._get_single_item(indices) - - def _get_single_item(self, index): - fname, pid, camid = self.dataset[index] - fpath = fname - if self.root is not None: - fpath = osp.join(self.root, fname) - img = Image.open(fpath).convert('RGB') - if self.transform is not None: - img = self.transform(img) - return img, fname, pid, camid - - -class RectScale(object): - def __init__(self, height, width, interpolation=Image.BILINEAR): - self.height = height - self.width = width - self.interpolation = interpolation - - def __call__(self, img): - w, h = img.size - if h == self.height and w == self.width: - return img - return img.resize((self.width, self.height), self.interpolation) - - -def get_data(name, data_dir, height, width, batch_size, workers): - root = osp.join(data_dir, name) - root = data_dir - dataset = datasets.create(name, root) - - normalizer = Normalize(mean=[0.485, 0.456, 0.406], - std=[0.229, 0.224, 0.225]) - - num_classes = dataset.num_train_ids - - train_transformer = Compose([ - RectScale(height, width), - RandomHorizontalFlip(), - ToTensor(), - normalizer, - ]) - - test_transformer = Compose([ - RectScale(height, width), - ToTensor(), - normalizer, - ]) - - - query_loader = DataLoader( - Preprocessor(dataset.query, root=osp.join(dataset.images_dir, dataset.query_path), - transform=test_transformer), - batch_size=batch_size, num_workers=workers, - shuffle=False, pin_memory=True) - - gallery_loader = DataLoader( - Preprocessor(dataset.gallery, root=osp.join(dataset.images_dir, dataset.gallery_path), - transform=test_transformer), - batch_size=batch_size, num_workers=workers, - shuffle=False, pin_memory=True) - - - return query_loader, gallery_loader - - -def data_preprocess(bin_filepath, dataloader): - if os.path.exists(bin_filepath) == False: - os.mkdir(bin_filepath) - else: - print('dir exist!') - - count = 0 - for i, (img, fname, pid, _) in enumerate(dataloader): - for fn, pi in zip(fname, pid): - fname_1 = bin_filepath + '/' + fn.split('.', 2)[0] + '.bin' - img = np.array(img).astype(np.float32) - img.tofile(fname_1) - count = count + 1 - return count - - -def main(args): - - # Create data loaders - if args.height is None or args.width is None: - args.height, args.width = (144, 56) if args.arch == 'inception' else \ - (256, 128) - query_loader, gallery_loader = \ - get_data(args.dataset, args.data_dir, args.height, - args.width, args.batch_size, args.workers, - ) - - count = data_preprocess('./gallery_preproc_data_Ascend310', gallery_loader) - print('number of images(gallery):') - print(count) - - count = data_preprocess('./query_preproc_data_Ascend310', query_loader) - print('number of images(query):') - print(count) - return - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description="Softmax loss classification") - # data - parser.add_argument('-d', '--dataset', type=str, default='cuhk03', - choices=datasets.names()) - parser.add_argument('-b', '--batch-size', type=int, default=256) - parser.add_argument('-j', '--workers', type=int, default=4) - parser.add_argument('--height', type=int, - help="input height, default: 256 for resnet*, " - "144 for inception") - parser.add_argument('--width', type=int, - help="input width, default: 128 for resnet*, " - "56 for inception") - # misc - working_dir = osp.dirname(osp.abspath(__file__)) - parser.add_argument('--data-dir', type=str, metavar='PATH', - default=osp.join(working_dir, 'data')) - main(parser.parse_args()) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import os.path as osp +import os +import numpy as np +from torch.utils.data import DataLoader +import datasets +from torchvision.transforms import Normalize, RandomHorizontalFlip, ToTensor, Compose +from PIL import Image + + +class Preprocessor(object): + def __init__(self, dataset, root=None, transform=None): + super(Preprocessor, self).__init__() + self.dataset = dataset + self.root = root + self.transform = transform + + def __len__(self): + return len(self.dataset) + + def __getitem__(self, indices): + if isinstance(indices, (tuple, list)): + return [self._get_single_item(index) for index in indices] + return self._get_single_item(indices) + + def _get_single_item(self, index): + fname, pid, camid = self.dataset[index] + fpath = fname + if self.root is not None: + fpath = osp.join(self.root, fname) + img = Image.open(fpath).convert('RGB') + if self.transform is not None: + img = self.transform(img) + return img, fname, pid, camid + + +class RectScale(object): + def __init__(self, height, width, interpolation=Image.BILINEAR): + self.height = height + self.width = width + self.interpolation = interpolation + + def __call__(self, img): + w, h = img.size + if h == self.height and w == self.width: + return img + return img.resize((self.width, self.height), self.interpolation) + + +def get_data(name, data_dir, height, width, batch_size, workers): + root = osp.join(data_dir, name) + root = data_dir + dataset = datasets.create(name, root) + + normalizer = Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]) + + num_classes = dataset.num_train_ids + + train_transformer = Compose([ + RectScale(height, width), + RandomHorizontalFlip(), + ToTensor(), + normalizer, + ]) + + test_transformer = Compose([ + RectScale(height, width), + ToTensor(), + normalizer, + ]) + + + query_loader = DataLoader( + Preprocessor(dataset.query, root=osp.join(dataset.images_dir, dataset.query_path), + transform=test_transformer), + batch_size=batch_size, num_workers=workers, + shuffle=False, pin_memory=True) + + gallery_loader = DataLoader( + Preprocessor(dataset.gallery, root=osp.join(dataset.images_dir, dataset.gallery_path), + transform=test_transformer), + batch_size=batch_size, num_workers=workers, + shuffle=False, pin_memory=True) + + + return query_loader, gallery_loader + + +def data_preprocess(bin_filepath, dataloader): + if os.path.exists(bin_filepath) == False: + os.mkdir(bin_filepath) + else: + print('dir exist!') + + count = 0 + for i, (img, fname, pid, _) in enumerate(dataloader): + for fn, pi in zip(fname, pid): + fname_1 = bin_filepath + '/' + fn.split('.', 2)[0] + '.bin' + img = np.array(img).astype(np.float32) + img.tofile(fname_1) + count = count + 1 + return count + + +def main(args): + + # Create data loaders + if args.height is None or args.width is None: + args.height, args.width = (144, 56) if args.arch == 'inception' else \ + (256, 128) + query_loader, gallery_loader = \ + get_data(args.dataset, args.data_dir, args.height, + args.width, args.batch_size, args.workers, + ) + + count = data_preprocess('./gallery_preproc_data_Ascend310', gallery_loader) + print('number of images(gallery):') + print(count) + + count = data_preprocess('./query_preproc_data_Ascend310', query_loader) + print('number of images(query):') + print(count) + return + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description="Softmax loss classification") + # data + parser.add_argument('-d', '--dataset', type=str, default='cuhk03', + choices=datasets.names()) + parser.add_argument('-b', '--batch-size', type=int, default=256) + parser.add_argument('-j', '--workers', type=int, default=4) + parser.add_argument('--height', type=int, + help="input height, default: 256 for resnet*, " + "144 for inception") + parser.add_argument('--width', type=int, + help="input width, default: 128 for resnet*, " + "56 for inception") + # misc + working_dir = osp.dirname(osp.abspath(__file__)) + parser.add_argument('--data-dir', type=str, metavar='PATH', + default=osp.join(working_dir, 'data')) + main(parser.parse_args()) diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/Readme.md b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/Readme.md index 49116bcbe13a9158aac0c2ab1d651a72e71774fe..f963242e8b60fff1a7b5927d2793e5914083be14 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/Readme.md +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/Readme.md @@ -1,285 +1,285 @@ -# PCB Onnx模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 开源TopN精度](#62-开源TopN精度) - - [6.2 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[PCB论文](https://arxiv.org/pdf/1711.09349.pdf) - -分支为 : master - -commit ID : e29cf54486427d1423277d4c793e39ac0eeff87c - -### 1.2 代码地址 -[PCB开源仓代码](https://github.com/syfafterzy/PCB_RPP_for_reID) - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -### 2.1 深度学习框架 -``` -python==3.6.7 -pytorch==1.8.1 -torchvision==0.2.1 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.19.2 -scikit-learn == 0.24.1 -opencv-python == 4.5.2.54 -pillow == 8.2.0 -onnx == 1.9.0 -pillow == 8.2.0 -skl2onnx == 1.8.0 -h5py == 3.3.0 -``` - -**说明:** -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 - -1.下载pth权重文件 -[PCB预训练pth权重文件](https://ascend-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/face/PCB/PCB_3_7.pt) -``` -wget https://ascend-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/face/PCB/PCB_3_7.pt - -``` - **说明:模型文件名为:PCB_3_7.pt 其md5sum值为:c5bc5ddabcbcc45f127ead797fe8cb35 PCB_3_7.pt** ->获取的预训练模型放在本仓根目录下 - -2.编写pth2onnx脚本pth2onnx.py - - **说明:** ->注意目前ATC支持的onnx算子版本为11 - -3.执行pth2onnx脚本,生成onnx模型文件 -``` -python3.7 pth2onnx.py #将PCB_3_7.pt模型转为PCB.onnx模型 -``` - - **模型转换要点:** ->此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 - - -### 3.2 onnx转om模型 - -1.设置环境变量 -``` -source env.sh -``` -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) -``` -atc --framework=5 --model=PCB.onnx --output=PCB --input_format=NCHW --input_shape="input_1:1,3,384,128" --log=debug --soc_version=Ascend310 -``` - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -该模型使用[Market数据集](https://pan.baidu.com/s/1ntIi2Op?_at_=1622802619466)的19732张验证集进行测试。数据集下载后,解压放到./datasets目录下。 - -### 4.2 数据集预处理 -1.预处理脚本PCB_pth_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 -``` -python3.7 PCB_pth_preprocess.py -d market -b 1 --height 384 --width 128 --data-dir ./datasets/Market-1501/ -j 4 -``` -### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本get_info_Ascend310.sh - -2.执行生成数据集信息脚本,生成数据集信息文件 -``` -sh get_info_Ascend310.sh -``` -在get_info_Ascend310.sh文件中调用华为提供的开源工具获取bin文件的路径和尺寸信息,该工具的第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) -### 5.2 离线推理 -1.设置环境变量 -``` -source env.sh -``` -2.执行离线推理 -``` -sudo ./benchmark_tools/benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./PCB.om -input_text_path=./gallery_preproc_data_Ascend310.info -input_width=128 -input_height=384 -output_binary=True -useDvpp=False -sudo mv ./result/dumpOutput_device0 ./result/dumpOutput_device0_gallery -sudo mv ./result/perf_vision_batchsize_1_device_0.txt ./result/gallery_perf_vision_batchsize_1_device_0.txt -``` -``` -sudo ./benchmark_tools/benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./PCB.om -input_text_path=./query_preproc_data_Ascend310.info -input_width=128 -input_height=384 -output_binary=True -useDvpp=False -sudo mv ./result/dumpOutput_device0 ./result/dumpOutput_device0_query -sudo mv ./result/perf_vision_batchsize_1_device_0.txt ./result/query_perf_vision_batchsize_1_device_0.txt -``` -输出结果默认保存在当前目录result/dumpOutput_device0下,由于需要通过om模型提取两组特征,因此根据输入图片类型(querry或gallery)分别重命名文件夹。 -3.特征图后处理 - -``` -python ./PCB_pth_postprocess.py -q ./result/dumpOutput_device0_query -g ./result/dumpOutput_device0_gallery -d market --data-dir ./datasets/Market-1501/ -``` -对om模型提取的特征做后处理并统计精度,结果如下: -``` -{'title': 'Overall statistical evaluation', 'value': [{'key': 'Number of images', 'value': '15913'}, {'key': 'Number of classes', 'value': '751'}, {'key': 'Top-1 accuracy', 'value': '92.1%'}, {'key': 'Top-5 accuracy', 'value': '96.9%'}, {'key': 'Top-10 accuracy', 'value': '98.1%'}]} -``` -## 6 精度对比 - -- **[开源TopN精度](#61-开源TopN精度)** -- **[精度对比](#62-精度对比)** - -### 6.1 开源TopN精度 -``` -CMC Scores market1501 - top-1 92.1% - top-5 96.9% - top-10 98.1% -``` -### 6.2 精度对比 -将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 - **精度调试:** ->没有遇到精度不达标的问题,故不需要进行精度调试 - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** - -### 7.1 npu性能数据 -benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准。 - -1.benchmark工具在整个数据集上推理获得性能数据 -batch1的性能,benchmark工具在整个数据集上推理后生成result/query_perf_vision_batchsize_1_device_0.txt.txt: -``` ------------------Performance Summary------------------ -[e2e] throughputRate: 164.729, latency: 20445.7 -[data read] throughputRate: 184.812, moduleLatency: 5.41092 -[preprocess] throughputRate: 182.347, moduleLatency: 5.48405 -[infer] throughputRate: 175.577, Interface throughputRate: 253.855, moduleLatency: 4.91128 -[post] throughputRate: 175.573, moduleLatency: 5.69565 -``` -Interface throughputRate: 253.855,253.855* 4 = 1015.42既是batch1 310单卡吞吐率 - - -batch4的性能,benchmark工具在整个数据集上推理后生成result/query_perf_vision_batchsize_4_device_0.txt.txt: -``` ------------------Performance Summary------------------ -[e2e] throughputRate: 157.081, latency: 21441.2 -[data read] throughputRate: 173.63, moduleLatency: 5.75937 -[preprocess] throughputRate: 171.283, moduleLatency: 5.83829 -[infer] throughputRate: 167.102, Interface throughputRate: 353.841, moduleLatency: 4.32693 -[post] throughputRate: 41.7725, moduleLatency: 23.9392 -``` -Interface throughputRate: 353.841,353.841* 4 = 1415.364既是batch4 310单卡吞吐率 - - -batch8的性能,benchmark工具在整个数据集上推理后生成result/query_perf_vision_batchsize_8_device_0.txt.txt: -``` ------------------Performance Summary------------------ -[e2e] throughputRate: 132.514, latency: 25416.1 -[data read] throughputRate: 139.993, moduleLatency: 7.14319 -[preprocess] throughputRate: 139.054, moduleLatency: 7.19145 -[infer] throughputRate: 139.615, Interface throughputRate: 366.98, moduleLatency: 4.21507 -[post] throughputRate: 17.4505, moduleLatency: 57.305 -``` -Interface throughputRate: 366.98,366.98 * 4 = 1467.92既是batch8 310单卡吞吐率 - -batch16的性能,benchmark工具在整个数据集上推理后生成result/query_perf_vision_batchsize_16_device_0.txt.txt: -``` ------------------Performance Summary------------------ -[e2e] throughputRate: 143.582, latency: 23457 -[data read] throughputRate: 150.172, moduleLatency: 6.65904 -[preprocess] throughputRate: 148.372, moduleLatency: 6.73981 -[infer] throughputRate: 147.201, Interface throughputRate: 362.414, moduleLatency: 4.28791 -[post] throughputRate: 9.22071, moduleLatency: 108.452 -``` -Interface throughputRate: 362.414,362.414 * 4 = 1449.656既是batch16 310单卡吞吐率 - - -batch32的性能,benchmark工具在整个数据集上推理后生成result/query_perf_vision_batchsize_32_device_0.txt.txt: -``` ------------------Performance Summary------------------ -[e2e] throughputRate: 118.266, latency: 28478.2 -[data read] throughputRate: 126.885, moduleLatency: 7.88113 -[preprocess] throughputRate: 125.442, moduleLatency: 7.97179 -[infer] throughputRate: 124.065, Interface throughputRate: 354.632, moduleLatency: 4.30699 -[post] throughputRate: 3.90409, moduleLatency: 256.141 -``` -Interface throughputRate: 354.632,354.632 * 4 = 1418.528既是batch32 310单卡吞吐率 - -### 7.2 性能优化 -原始模型性能不达标原因分析: -根据profiling性能分析的表格,OM模型完成一次离线推理的总耗时中卷积计算(54次)、数据下采样(1次)和数据上采样(1次)这三类操作占总耗时的71%(36%+21%+19%)左右。再往细分,Task ID 95~101总耗时的53.6%,及7%的任务数占了一半以上的耗时。查看对应任务的算子类型,大多为数据转换类:向量尺寸变换和数据类型转换,推测与npu中的算子硬件实现相关。(详见性能分析报告) - -原始模型性能与优化后模型性能对比: -batch1:441.128fps(Ascend310) < 1015.42fps(Ascend310) -batch16:1024.56(Ascend310) < 1449.656fps(Ascend310) - - -#### 7.2.1固定模型输入的batch size,并结合onnxsim工具对onnx模型进行优化 -优化动机:通过Netron查看onnx的模型结构图发现有一些常量算子可以折叠 - -优化样例: - - python -m onnxsim --input-shape="16,3,384,128" ./PCB.onnx ./PCB_sim_bs16.onnx - -#### 7.42.2.把ReduceL2算子拆分为mul+sum+sqrt算子(无损) -优化动机:Profilingdata可以看到ReduceL2这个算子耗时占比较大,原因是ReduceL2这个算子缺少优化,但是拆分后的算子是经过优化的,且拆分算子后模型的精度保持不变,因此选择拆分ReduceL2算子 - -优化样例: - - python ../scripts/split_reducelp.py ./PCB_sim_bs16.onnx ./PCB_sim_split_bs16.onnx - -#### 7.2.3.atc自动优化选项——autotune -优化动机:atc工具提供的自动优化选项 - -优化样例: - - atc --framework=5 --model=./PCB_sim_bs4.onnx --output=./PCB_sim_autotune_bs4 --input_format=NCHW --input_shape="input_1:4,3,384,128" --log=debug --soc_version=Ascend310 --auto_tune_mode="RL,GA" +# PCB Onnx模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 开源TopN精度](#62-开源TopN精度) + - [6.2 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[PCB论文](https://arxiv.org/pdf/1711.09349.pdf) + +分支为 : master + +commit ID : e29cf54486427d1423277d4c793e39ac0eeff87c + +### 1.2 代码地址 +[PCB开源仓代码](https://github.com/syfafterzy/PCB_RPP_for_reID) + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +### 2.1 深度学习框架 +``` +python==3.6.7 +pytorch==1.8.1 +torchvision==0.2.1 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.19.2 +scikit-learn == 0.24.1 +opencv-python == 4.5.2.54 +pillow == 8.2.0 +onnx == 1.9.0 +pillow == 8.2.0 +skl2onnx == 1.8.0 +h5py == 3.3.0 +``` + +**说明:** +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 + +1.下载pth权重文件 +[PCB预训练pth权重文件](https://ascend-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/face/PCB/PCB_3_7.pt) +``` +wget https://ascend-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/face/PCB/PCB_3_7.pt + +``` + **说明:模型文件名为:PCB_3_7.pt 其md5sum值为:c5bc5ddabcbcc45f127ead797fe8cb35 PCB_3_7.pt** +>获取的预训练模型放在本仓根目录下 + +2.编写pth2onnx脚本pth2onnx.py + + **说明:** +>注意目前ATC支持的onnx算子版本为11 + +3.执行pth2onnx脚本,生成onnx模型文件 +``` +python3.7 pth2onnx.py #将PCB_3_7.pt模型转为PCB.onnx模型 +``` + + **模型转换要点:** +>此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 + + +### 3.2 onnx转om模型 + +1.设置环境变量 +``` +source env.sh +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) +``` +atc --framework=5 --model=PCB.onnx --output=PCB --input_format=NCHW --input_shape="input_1:1,3,384,128" --log=debug --soc_version=Ascend310 +``` + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用[Market数据集](https://pan.baidu.com/s/1ntIi2Op?_at_=1622802619466)的19732张验证集进行测试。数据集下载后,解压放到./datasets目录下。 + +### 4.2 数据集预处理 +1.预处理脚本PCB_pth_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 +``` +python3.7 PCB_pth_preprocess.py -d market -b 1 --height 384 --width 128 --data-dir ./datasets/Market-1501/ -j 4 +``` +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本get_info_Ascend310.sh + +2.执行生成数据集信息脚本,生成数据集信息文件 +``` +sh get_info_Ascend310.sh +``` +在get_info_Ascend310.sh文件中调用华为提供的开源工具获取bin文件的路径和尺寸信息,该工具的第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN V100R020C10 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) +### 5.2 离线推理 +1.设置环境变量 +``` +source env.sh +``` +2.执行离线推理 +``` +sudo ./benchmark_tools/benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./PCB.om -input_text_path=./gallery_preproc_data_Ascend310.info -input_width=128 -input_height=384 -output_binary=True -useDvpp=False +sudo mv ./result/dumpOutput_device0 ./result/dumpOutput_device0_gallery +sudo mv ./result/perf_vision_batchsize_1_device_0.txt ./result/gallery_perf_vision_batchsize_1_device_0.txt +``` +``` +sudo ./benchmark_tools/benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./PCB.om -input_text_path=./query_preproc_data_Ascend310.info -input_width=128 -input_height=384 -output_binary=True -useDvpp=False +sudo mv ./result/dumpOutput_device0 ./result/dumpOutput_device0_query +sudo mv ./result/perf_vision_batchsize_1_device_0.txt ./result/query_perf_vision_batchsize_1_device_0.txt +``` +输出结果默认保存在当前目录result/dumpOutput_device0下,由于需要通过om模型提取两组特征,因此根据输入图片类型(querry或gallery)分别重命名文件夹。 +3.特征图后处理 + +``` +python ./PCB_pth_postprocess.py -q ./result/dumpOutput_device0_query -g ./result/dumpOutput_device0_gallery -d market --data-dir ./datasets/Market-1501/ +``` +对om模型提取的特征做后处理并统计精度,结果如下: +``` +{'title': 'Overall statistical evaluation', 'value': [{'key': 'Number of images', 'value': '15913'}, {'key': 'Number of classes', 'value': '751'}, {'key': 'Top-1 accuracy', 'value': '92.1%'}, {'key': 'Top-5 accuracy', 'value': '96.9%'}, {'key': 'Top-10 accuracy', 'value': '98.1%'}]} +``` +## 6 精度对比 + +- **[开源TopN精度](#61-开源TopN精度)** +- **[精度对比](#62-精度对比)** + +### 6.1 开源TopN精度 +``` +CMC Scores market1501 + top-1 92.1% + top-5 96.9% + top-10 98.1% +``` +### 6.2 精度对比 +将得到的om离线模型推理TopN精度与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + **精度调试:** +>没有遇到精度不达标的问题,故不需要进行精度调试 + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** + +### 7.1 npu性能数据 +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准。 + +1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/query_perf_vision_batchsize_1_device_0.txt.txt: +``` +-----------------Performance Summary------------------ +[e2e] throughputRate: 164.729, latency: 20445.7 +[data read] throughputRate: 184.812, moduleLatency: 5.41092 +[preprocess] throughputRate: 182.347, moduleLatency: 5.48405 +[infer] throughputRate: 175.577, Interface throughputRate: 253.855, moduleLatency: 4.91128 +[post] throughputRate: 175.573, moduleLatency: 5.69565 +``` +Interface throughputRate: 253.855,253.855* 4 = 1015.42既是batch1 310单卡吞吐率 + + +batch4的性能,benchmark工具在整个数据集上推理后生成result/query_perf_vision_batchsize_4_device_0.txt.txt: +``` +-----------------Performance Summary------------------ +[e2e] throughputRate: 157.081, latency: 21441.2 +[data read] throughputRate: 173.63, moduleLatency: 5.75937 +[preprocess] throughputRate: 171.283, moduleLatency: 5.83829 +[infer] throughputRate: 167.102, Interface throughputRate: 353.841, moduleLatency: 4.32693 +[post] throughputRate: 41.7725, moduleLatency: 23.9392 +``` +Interface throughputRate: 353.841,353.841* 4 = 1415.364既是batch4 310单卡吞吐率 + + +batch8的性能,benchmark工具在整个数据集上推理后生成result/query_perf_vision_batchsize_8_device_0.txt.txt: +``` +-----------------Performance Summary------------------ +[e2e] throughputRate: 132.514, latency: 25416.1 +[data read] throughputRate: 139.993, moduleLatency: 7.14319 +[preprocess] throughputRate: 139.054, moduleLatency: 7.19145 +[infer] throughputRate: 139.615, Interface throughputRate: 366.98, moduleLatency: 4.21507 +[post] throughputRate: 17.4505, moduleLatency: 57.305 +``` +Interface throughputRate: 366.98,366.98 * 4 = 1467.92既是batch8 310单卡吞吐率 + +batch16的性能,benchmark工具在整个数据集上推理后生成result/query_perf_vision_batchsize_16_device_0.txt.txt: +``` +-----------------Performance Summary------------------ +[e2e] throughputRate: 143.582, latency: 23457 +[data read] throughputRate: 150.172, moduleLatency: 6.65904 +[preprocess] throughputRate: 148.372, moduleLatency: 6.73981 +[infer] throughputRate: 147.201, Interface throughputRate: 362.414, moduleLatency: 4.28791 +[post] throughputRate: 9.22071, moduleLatency: 108.452 +``` +Interface throughputRate: 362.414,362.414 * 4 = 1449.656既是batch16 310单卡吞吐率 + + +batch32的性能,benchmark工具在整个数据集上推理后生成result/query_perf_vision_batchsize_32_device_0.txt.txt: +``` +-----------------Performance Summary------------------ +[e2e] throughputRate: 118.266, latency: 28478.2 +[data read] throughputRate: 126.885, moduleLatency: 7.88113 +[preprocess] throughputRate: 125.442, moduleLatency: 7.97179 +[infer] throughputRate: 124.065, Interface throughputRate: 354.632, moduleLatency: 4.30699 +[post] throughputRate: 3.90409, moduleLatency: 256.141 +``` +Interface throughputRate: 354.632,354.632 * 4 = 1418.528既是batch32 310单卡吞吐率 + +### 7.2 性能优化 +原始模型性能不达标原因分析: +根据profiling性能分析的表格,OM模型完成一次离线推理的总耗时中卷积计算(54次)、数据下采样(1次)和数据上采样(1次)这三类操作占总耗时的71%(36%+21%+19%)左右。再往细分,Task ID 95~101总耗时的53.6%,及7%的任务数占了一半以上的耗时。查看对应任务的算子类型,大多为数据转换类:向量尺寸变换和数据类型转换,推测与npu中的算子硬件实现相关。(详见性能分析报告) + +原始模型性能与优化后模型性能对比: +batch1:441.128fps(Ascend310) < 1015.42fps(Ascend310) +batch16:1024.56(Ascend310) < 1449.656fps(Ascend310) + + +#### 7.2.1固定模型输入的batch size,并结合onnxsim工具对onnx模型进行优化 +优化动机:通过Netron查看onnx的模型结构图发现有一些常量算子可以折叠 + +优化样例: + + python -m onnxsim --input-shape="16,3,384,128" ./PCB.onnx ./PCB_sim_bs16.onnx + +#### 7.42.2.把ReduceL2算子拆分为mul+sum+sqrt算子(无损) +优化动机:Profilingdata可以看到ReduceL2这个算子耗时占比较大,原因是ReduceL2这个算子缺少优化,但是拆分后的算子是经过优化的,且拆分算子后模型的精度保持不变,因此选择拆分ReduceL2算子 + +优化样例: + + python ../scripts/split_reducelp.py ./PCB_sim_bs16.onnx ./PCB_sim_split_bs16.onnx + +#### 7.2.3.atc自动优化选项——autotune +优化动机:atc工具提供的自动优化选项 + +优化样例: + + atc --framework=5 --model=./PCB_sim_bs4.onnx --output=./PCB_sim_autotune_bs4 --input_format=NCHW --input_shape="input_1:4,3,384,128" --log=debug --soc_version=Ascend310 --auto_tune_mode="RL,GA" diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/env.sh b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/env.sh index 2067d9b3a827d3fba047c1138a7ced0633d92fa0..9bc1cb3e52e2106d2eb923d1c61ac18c4ac93673 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/env.sh +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/env.sh @@ -1,6 +1,6 @@ -#! /bin/bash -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp +#! /bin/bash +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/get_info.py b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/get_info.py index 5af675c6b0ae3f28a6f191d139ebb44e775e6c1c..fc6cdebb5b4417a3651c1e6e9663d8d1299a0ef5 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/get_info.py +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/get_info.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/modelzoo_level.txt index 39175166a4b66dd0ead8d95dcb7ea49c56a868e3..119ddfc69182d1e11b6ce03723be060336966991 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/modelzoo_level.txt @@ -1,2 +1,2 @@ -ModelConvert:OK +ModelConvert:OK QuantStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/pth2onnx.py b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/pth2onnx.py index 78a1efa792d938c9fecb0d80f4bc3229e402e490..3c26b154e1169fe591ef39c65d716181a2ea2cfd 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/pth2onnx.py @@ -1,37 +1,37 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import argparse -from torch.autograd import Variable - - -def main(args): - model = torch.load(args.pth) - x = torch.randn(1, 3, 384, 128) - model.eval() - input_names=["input_1"] - output_names=["output_1"] - dynamic_axes = {'input_1': {0: '-1'}, 'output_1': {0: '-1'}} - x = Variable(x, volatile=True) - # Export the model - torch.onnx.export(model, x, "./models/PCB.onnx", input_names=input_names, output_names=output_names, \ - dynamic_axes=dynamic_axes, opset_version=11, verbose=True, do_constant_folding=True, export_params=True) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description="Softmax loss classification") - # data - parser.add_argument('-p', '--pth', type=str, default='./models/PCB_3_7.pt',) - main(parser.parse_args()) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import argparse +from torch.autograd import Variable + + +def main(args): + model = torch.load(args.pth) + x = torch.randn(1, 3, 384, 128) + model.eval() + input_names=["input_1"] + output_names=["output_1"] + dynamic_axes = {'input_1': {0: '-1'}, 'output_1': {0: '-1'}} + x = Variable(x, volatile=True) + # Export the model + torch.onnx.export(model, x, "./models/PCB.onnx", input_names=input_names, output_names=output_names, \ + dynamic_axes=dynamic_axes, opset_version=11, verbose=True, do_constant_folding=True, export_params=True) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description="Softmax loss classification") + # data + parser.add_argument('-p', '--pth', type=str, default='./models/PCB_3_7.pt',) + main(parser.parse_args()) diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/requirements.txt b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/requirements.txt index 37e7fabb8cbf1d08132728daaa1cd18e32195f59..84c915b351ec8b38ac89852e22a8fb008a4cf2db 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/requirements.txt +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/requirements.txt @@ -1,9 +1,9 @@ -torch == 1.8.1 -torchvision == 0.2.1 -numpy == 1.19.2 -opencv-python == 4.5.2.54 -onnx == 1.9.0 -skl2onnx == 1.8.0 -scikit-learn -h5py -onnx-simplifier +torch == 1.8.1 +torchvision == 0.2.1 +numpy == 1.19.2 +opencv-python == 4.5.2.54 +onnx == 1.9.0 +skl2onnx == 1.8.0 +scikit-learn +h5py +onnx-simplifier diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/Readme.md b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/Readme.md index 59da2c434c5b1c471f2b8290e53baa57bd7861d8..0965701b4617f5a1acb4579ec215aa8edd35a22e 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/Readme.md +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/Readme.md @@ -1,69 +1,69 @@ -环境准备: - - -1.获取开源仓代码 - - git clone https://gitee.com/hu-zongqi/modelzoo.git - -2.数据集路径 - -通用的数据集统一放在/root/datasets/或/opt/npu/ - -本模型使用的数据集为Market_1501,放在目录/opt/npu/下 - - -3.进入工作目录 - - cd modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline - -4.下载PCB模型论文开源仓代码,并将PCB_RPP_for_reID/reid目录下的datasets文件夹移动到当前目录 - - git clone https://github.com/syfafterzy/PCB_RPP_for_reID.git - cd PCB_RPP_for_reID - git checkout e29cf54486427d1423277d4c793e39ac0eeff87c - cd .. - cp -r PCB_RPP_for_reID/reid/datasets ./ - -5.合并补丁 - - cd modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline - cp ./test/resnet.diff PCB_RPP_for_reID/reid/models - cd PCB_RPP_for_reID/reid/models - patch -p0 < resnet.diff - -6.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - - cd modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline - pip3.7 install -r requirements.txt - -下载onnx工具: - - cd modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline/test - git clone https://gitee.com/zheng-wengang1/onnx_tools.git scripts/utils - cd scripts/utils - git checkout cbb099e5f2cef3d76c7630bffe0ee8250b03d921 - -7.获取benchmark工具 - -将benchmark.x86_64 放在modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline目录下 - -8.移动PCB_RPP_for_reID/reid到modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline下 - - cd modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline - mv PCB_RPP_for_reID/reid ./ - -9.下载预训练模型文件 - - cd modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline/test - mkdir models - wget -P ./models/ https://ascend-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/face/PCB/PCB_3_7.pt - - -10.310上执行,执行时确保device空闲 - - cd modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline/test - dos2unix *.sh - dos2unix ../env.sh - source ../env.sh - sudo sh pth2om.sh - sudo sh eval_acc_perf.sh +环境准备: + + +1.获取开源仓代码 + + git clone https://gitee.com/hu-zongqi/modelzoo.git + +2.数据集路径 + +通用的数据集统一放在/root/datasets/或/opt/npu/ + +本模型使用的数据集为Market_1501,放在目录/opt/npu/下 + + +3.进入工作目录 + + cd modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline + +4.下载PCB模型论文开源仓代码,并将PCB_RPP_for_reID/reid目录下的datasets文件夹移动到当前目录 + + git clone https://github.com/syfafterzy/PCB_RPP_for_reID.git + cd PCB_RPP_for_reID + git checkout e29cf54486427d1423277d4c793e39ac0eeff87c + cd .. + cp -r PCB_RPP_for_reID/reid/datasets ./ + +5.合并补丁 + + cd modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline + cp ./test/resnet.diff PCB_RPP_for_reID/reid/models + cd PCB_RPP_for_reID/reid/models + patch -p0 < resnet.diff + +6.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + + cd modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline + pip3.7 install -r requirements.txt + +下载onnx工具: + + cd modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline/test + git clone https://gitee.com/zheng-wengang1/onnx_tools.git scripts/utils + cd scripts/utils + git checkout cbb099e5f2cef3d76c7630bffe0ee8250b03d921 + +7.获取benchmark工具 + +将benchmark.x86_64 放在modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline目录下 + +8.移动PCB_RPP_for_reID/reid到modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline下 + + cd modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline + mv PCB_RPP_for_reID/reid ./ + +9.下载预训练模型文件 + + cd modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline/test + mkdir models + wget -P ./models/ https://ascend-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/face/PCB/PCB_3_7.pt + + +10.310上执行,执行时确保device空闲 + + cd modelzoo/contrib/ACL_PyTorch/Research/cv/face/reid_PCB_baseline/test + dos2unix *.sh + dos2unix ../env.sh + source ../env.sh + sudo sh pth2om.sh + sudo sh eval_acc_perf.sh diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/eval_acc_perf.sh b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/eval_acc_perf.sh index 0f11595c873e527432e7ef08e80039e088119cf3..796bed2ed2a686d4b3ab0463804b4f1e5473cb5c 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/eval_acc_perf.sh +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/eval_acc_perf.sh @@ -1,53 +1,53 @@ -#! /bin/bash - -#test - -#清除上次运行数据 -rm -r ./result/* -rm -r ./query_preproc_data_Ascend310 -rm -r ./gallery_preproc_data_Ascend310 -#数据预处理 -echo "preprocess......" -python3.7 ../PCB_pth_preprocess.py -d market -b 1 --height 384 --width 128 --data-dir /opt/npu/Market_1501/ -j 4 -#生成数据集信息文件 -echo "get_info......" -python3.7 ../get_info.py bin ./query_preproc_data_Ascend310 ./query_preproc_data_Ascend310.info 128 384 -python3.7 ../get_info.py bin ./gallery_preproc_data_Ascend310 ./gallery_preproc_data_Ascend310.info 128 384 -#离线推理 bs = 1 -echo "off-line inference bs = 1......" -#gallery -../benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./models/PCB_sim_split_bs1_autotune.om -input_text_path=./gallery_preproc_data_Ascend310.info -input_width=128 -input_height=384 -output_binary=True -useDvpp=False >> gallary_bs1.log -mv ./result/dumpOutput_device0 ./result/dumpOutput_device0_gallery_bs1 -mv ./result/perf_vision_batchsize_1_device_0.txt ./result/gallery_perf_vision_batchsize_1_device_0.txt -#query -../benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./models/PCB_sim_split_bs1_autotune.om -input_text_path=./query_preproc_data_Ascend310.info -input_width=128 -input_height=384 -output_binary=True -useDvpp=False >> query_bs1.log -mv ./result/dumpOutput_device0 ./result/dumpOutput_device0_query_bs1 -mv ./result/perf_vision_batchsize_1_device_0.txt ./result/query_perf_vision_batchsize_1_device_0.txt -#离线推理 bs = 16 -echo "off-line inference bs = 16......" -#gallery -../benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=./models/PCB_sim_split_bs16_autotune.om -input_text_path=./gallery_preproc_data_Ascend310.info -input_width=128 -input_height=384 -output_binary=True -useDvpp=False >> gallary_bs16.log -mv ./result/dumpOutput_device0 ./result/dumpOutput_device0_gallery_bs16 -mv ./result/perf_vision_batchsize_16_device_0.txt ./result/gallery_perf_vision_batchsize_16_device_0.txt -#query -../benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=./models/PCB_sim_split_bs16_autotune.om -input_text_path=./query_preproc_data_Ascend310.info -input_width=128 -input_height=384 -output_binary=True -useDvpp=False >> query_bs16.log -mv ./result/dumpOutput_device0 ./result/dumpOutput_device0_query_bs16 -mv ./result/perf_vision_batchsize_16_device_0.txt ./result/query_perf_vision_batchsize_16_device_0.txt -###数据后处理 -echo "postprocess......" -python3.7 ../PCB_pth_postprocess.py -q ./result/dumpOutput_device0_query_bs1 -g ./result/dumpOutput_device0_gallery_bs1 -d market --data-dir /opt/npu/Market_1501/ -echo "====performance data====" -echo "bs1 : " -python3.7 parse.py ./result/gallery_perf_vision_batchsize_1_device_0.txt -if [ $? != 0 ]; then - echo "fail!" - exit -1 -fi -echo "bs16 : " -python3.7 parse.py ./result/gallery_perf_vision_batchsize_16_device_0.txt -if [ $? != 0 ]; then - echo "fail!" - exit -1 -fi - -echo "success" +#! /bin/bash + +#test + +#清除上次运行数据 +rm -r ./result/* +rm -r ./query_preproc_data_Ascend310 +rm -r ./gallery_preproc_data_Ascend310 +#数据预处理 +echo "preprocess......" +python3.7 ../PCB_pth_preprocess.py -d market -b 1 --height 384 --width 128 --data-dir /opt/npu/Market_1501/ -j 4 +#生成数据集信息文件 +echo "get_info......" +python3.7 ../get_info.py bin ./query_preproc_data_Ascend310 ./query_preproc_data_Ascend310.info 128 384 +python3.7 ../get_info.py bin ./gallery_preproc_data_Ascend310 ./gallery_preproc_data_Ascend310.info 128 384 +#离线推理 bs = 1 +echo "off-line inference bs = 1......" +#gallery +../benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./models/PCB_sim_split_bs1_autotune.om -input_text_path=./gallery_preproc_data_Ascend310.info -input_width=128 -input_height=384 -output_binary=True -useDvpp=False >> gallary_bs1.log +mv ./result/dumpOutput_device0 ./result/dumpOutput_device0_gallery_bs1 +mv ./result/perf_vision_batchsize_1_device_0.txt ./result/gallery_perf_vision_batchsize_1_device_0.txt +#query +../benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./models/PCB_sim_split_bs1_autotune.om -input_text_path=./query_preproc_data_Ascend310.info -input_width=128 -input_height=384 -output_binary=True -useDvpp=False >> query_bs1.log +mv ./result/dumpOutput_device0 ./result/dumpOutput_device0_query_bs1 +mv ./result/perf_vision_batchsize_1_device_0.txt ./result/query_perf_vision_batchsize_1_device_0.txt +#离线推理 bs = 16 +echo "off-line inference bs = 16......" +#gallery +../benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=./models/PCB_sim_split_bs16_autotune.om -input_text_path=./gallery_preproc_data_Ascend310.info -input_width=128 -input_height=384 -output_binary=True -useDvpp=False >> gallary_bs16.log +mv ./result/dumpOutput_device0 ./result/dumpOutput_device0_gallery_bs16 +mv ./result/perf_vision_batchsize_16_device_0.txt ./result/gallery_perf_vision_batchsize_16_device_0.txt +#query +../benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=16 -om_path=./models/PCB_sim_split_bs16_autotune.om -input_text_path=./query_preproc_data_Ascend310.info -input_width=128 -input_height=384 -output_binary=True -useDvpp=False >> query_bs16.log +mv ./result/dumpOutput_device0 ./result/dumpOutput_device0_query_bs16 +mv ./result/perf_vision_batchsize_16_device_0.txt ./result/query_perf_vision_batchsize_16_device_0.txt +###数据后处理 +echo "postprocess......" +python3.7 ../PCB_pth_postprocess.py -q ./result/dumpOutput_device0_query_bs1 -g ./result/dumpOutput_device0_gallery_bs1 -d market --data-dir /opt/npu/Market_1501/ +echo "====performance data====" +echo "bs1 : " +python3.7 parse.py ./result/gallery_perf_vision_batchsize_1_device_0.txt +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +echo "bs16 : " +python3.7 parse.py ./result/gallery_perf_vision_batchsize_16_device_0.txt +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi + +echo "success" diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/parse.py b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/parse.py index b9c74f41d7848e1250356f14472b237a18bb3489..82af69cd183218c3263723c20b652b3f7ec2bc27 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/parse.py +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/pth2om.sh b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/pth2om.sh index 65dbe5abd5dcfb9e4f4f0feb5a8fb1cdefbe8de1..8c1c58941dabfbade3a0d486b45c2bed50e69a6b 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/pth2om.sh +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/pth2om.sh @@ -1,19 +1,19 @@ -#! /bin/bash -echo "--------------------------------------------" -python3.7 ../pth2onnx.py -echo "--------------------------------------------" -python3.7 -m onnxsim --input-shape="1,3,384,128" ./models/PCB.onnx ./models/PCB_sim_bs1.onnx -echo "--------------------------------------------" -python3.7 -m onnxsim --input-shape="16,3,384,128" ./models/PCB.onnx ./models/PCB_sim_bs16.onnx -#bs1 -echo "--------------------------------------------" -python3.7 ./scripts/split_reducelp.py ./models/PCB_sim_bs1.onnx ./models/PCB_sim_split_bs1.onnx -#bs16 -echo "--------------------------------------------" -python3.7 ./scripts/split_reducelp.py ./models/PCB_sim_bs16.onnx ./models/PCB_sim_split_bs16.onnx -#转OM模型 bs=1 -echo "--------------------------------------------" -atc --framework=5 --model=./models/PCB_sim_split_bs1.onnx --output=./models/PCB_sim_split_bs1_autotune --input_format=NCHW --input_shape="input_1:1,3,384,128" --log=debug --soc_version=Ascend310 --auto_tune_mode="RL,GA" --out_nodes='Div_126:0;Gemm_191:0;Gemm_192:0;Gemm_193:0;Gemm_194:0;Gemm_195:0;Gemm_196:0' -#转OM模型 bs=16 -echo "--------------------------------------------" -atc --framework=5 --model=./models/PCB_sim_split_bs16.onnx --output=./models/PCB_sim_split_bs16_autotune --input_format=NCHW --input_shape="input_1:16,3,384,128" --log=debug --soc_version=Ascend310 --auto_tune_mode="RL,GA" --out_nodes='Div_126:0;Gemm_191:0;Gemm_192:0;Gemm_193:0;Gemm_194:0;Gemm_195:0;Gemm_196:0' +#! /bin/bash +echo "--------------------------------------------" +python3.7 ../pth2onnx.py +echo "--------------------------------------------" +python3.7 -m onnxsim --input-shape="1,3,384,128" ./models/PCB.onnx ./models/PCB_sim_bs1.onnx +echo "--------------------------------------------" +python3.7 -m onnxsim --input-shape="16,3,384,128" ./models/PCB.onnx ./models/PCB_sim_bs16.onnx +#bs1 +echo "--------------------------------------------" +python3.7 ./scripts/split_reducelp.py ./models/PCB_sim_bs1.onnx ./models/PCB_sim_split_bs1.onnx +#bs16 +echo "--------------------------------------------" +python3.7 ./scripts/split_reducelp.py ./models/PCB_sim_bs16.onnx ./models/PCB_sim_split_bs16.onnx +#转OM模型 bs=1 +echo "--------------------------------------------" +atc --framework=5 --model=./models/PCB_sim_split_bs1.onnx --output=./models/PCB_sim_split_bs1_autotune --input_format=NCHW --input_shape="input_1:1,3,384,128" --log=debug --soc_version=Ascend310 --auto_tune_mode="RL,GA" --out_nodes='Div_126:0;Gemm_191:0;Gemm_192:0;Gemm_193:0;Gemm_194:0;Gemm_195:0;Gemm_196:0' +#转OM模型 bs=16 +echo "--------------------------------------------" +atc --framework=5 --model=./models/PCB_sim_split_bs16.onnx --output=./models/PCB_sim_split_bs16_autotune --input_format=NCHW --input_shape="input_1:16,3,384,128" --log=debug --soc_version=Ascend310 --auto_tune_mode="RL,GA" --out_nodes='Div_126:0;Gemm_191:0;Gemm_192:0;Gemm_193:0;Gemm_194:0;Gemm_195:0;Gemm_196:0' diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/resnet.diff b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/resnet.diff index f3ed9282524756355dd30b39b211c3562d4d6647..77d06ca8a0d543e6796e68aa8cb31eb71f0340e9 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/resnet.diff +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/resnet.diff @@ -1,11 +1,11 @@ ---- resnet.py 2021-06-30 18:13:34.165260365 +0800 -+++ resnet_modified.py 2021-06-30 18:14:03.373647350 +0800 -@@ -128,7 +128,7 @@ class ResNet(nn.Module): - y = F.avg_pool3d(x,(16,1,1)).squeeze(1) - sx = x.size(2)/6 - kx = x.size(2)-sx*5 -- x = F.avg_pool2d(x,kernel_size=(kx,x.size(3)),stride=(sx,x.size(3))) # H4 W8 -+ x = F.avg_pool2d(x,kernel_size=(4,8),stride=(4,8)) # H4 W8 - #========================================================================# - - out0 = x.view(x.size(0),-1) +--- resnet.py 2021-06-30 18:13:34.165260365 +0800 ++++ resnet_modified.py 2021-06-30 18:14:03.373647350 +0800 +@@ -128,7 +128,7 @@ class ResNet(nn.Module): + y = F.avg_pool3d(x,(16,1,1)).squeeze(1) + sx = x.size(2)/6 + kx = x.size(2)-sx*5 +- x = F.avg_pool2d(x,kernel_size=(kx,x.size(3)),stride=(sx,x.size(3))) # H4 W8 ++ x = F.avg_pool2d(x,kernel_size=(4,8),stride=(4,8)) # H4 W8 + #========================================================================# + + out0 = x.view(x.size(0),-1) diff --git a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/scripts/split_reducelp.py b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/scripts/split_reducelp.py index dcbba7b5e79db1fa6dd18235ff87db42f77989ec..fcf1f4e7a48c234d0bd2a8a83b187f96f85c6810 100644 --- a/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/scripts/split_reducelp.py +++ b/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline/test/scripts/split_reducelp.py @@ -1,51 +1,51 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -from utils.OXInterface.OXInterface import OXGraph - - -def main(input_model, out_path): - oxgraph = OXGraph(input_model) - # ReduceL2->ReduceSum - onnx_node = oxgraph.get_oxnode_by_name('ReduceL2_122') - onnx_node.set_op_type('ReduceSum') - onnx_node.set_name('ReduceSum1') - - # 插入mul+sqrt节点 - oxgraph.insert_node( - bef_node_info_list=['AveragePool_121:0', 'AveragePool_121:0'], - aft_node_info_list=['ReduceSum1'], - op_type='Mul', - op_name='Mul1' - ) - oxgraph.insert_node( - bef_node_info_list=['ReduceSum1'], - aft_node_info_list=['Expand_125'], - op_type='Sqrt', - op_name='Sqrt1' - ) - - oxgraph.save_new_model(out_path) - - -if __name__ == '__main__': - input_model = sys.argv[1] - out_path = sys.argv[2] - out_path = os.path.abspath(out_path) - print(input_model) - print(out_path) - os.makedirs(os.path.dirname(out_path), exist_ok=True) - main(input_model, out_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from utils.OXInterface.OXInterface import OXGraph + + +def main(input_model, out_path): + oxgraph = OXGraph(input_model) + # ReduceL2->ReduceSum + onnx_node = oxgraph.get_oxnode_by_name('ReduceL2_122') + onnx_node.set_op_type('ReduceSum') + onnx_node.set_name('ReduceSum1') + + # 插入mul+sqrt节点 + oxgraph.insert_node( + bef_node_info_list=['AveragePool_121:0', 'AveragePool_121:0'], + aft_node_info_list=['ReduceSum1'], + op_type='Mul', + op_name='Mul1' + ) + oxgraph.insert_node( + bef_node_info_list=['ReduceSum1'], + aft_node_info_list=['Expand_125'], + op_type='Sqrt', + op_name='Sqrt1' + ) + + oxgraph.save_new_model(out_path) + + +if __name__ == '__main__': + input_model = sys.argv[1] + out_path = sys.argv[2] + out_path = os.path.abspath(out_path) + print(input_model) + print(out_path) + os.makedirs(os.path.dirname(out_path), exist_ok=True) + main(input_model, out_path) diff --git a/ACL_PyTorch/contrib/cv/gan/BigGAN/LICENSE b/ACL_PyTorch/contrib/cv/gan/BigGAN/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/gan/BigGAN/LICENSE +++ b/ACL_PyTorch/contrib/cv/gan/BigGAN/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/BigGAN/README.md b/ACL_PyTorch/contrib/cv/gan/BigGAN/README.md index 78a0b1f9d517b95bcdf1b8fe82137d21def1f759..b29bf3262272b433b882046268e151daf2b42906 100644 --- a/ACL_PyTorch/contrib/cv/gan/BigGAN/README.md +++ b/ACL_PyTorch/contrib/cv/gan/BigGAN/README.md @@ -1,225 +1,225 @@ -# BigGAN ONNX模型端到端推理指导 -- [1. 模型概述](#1) - - [论文地址](#11) - - [代码地址](#12) -- [2. 环境说明](#2) - - [深度学习框架](#21) - - [python第三方库](#22) -- [3. 模型转换](#3) - - [pth转onnx模型](#31) - - [onnx转om模型](#32) -- [4. 输入数据生成](#4) - - [数据生成](#41) -- [5. 离线推理](#5) - - [msame工具概述](#51) - - [离线推理](#52) -- [6. 精度对比](#6) - - [模型后处理](#61) - - [精度计算](#62) - -## 1. 模型概述 -### 1.1 论文地址 -[BigGAN论文](https://arxiv.org/pdf/1809.11096.pdf) -### 1.2 代码地址 -[BigGAN代码](https://github.com/ajbrock/BigGAN-PyTorch) - -修改源码中的BigGAN.py、layers.py和inception_utils.py,并移至本项目中: -``` -git clone https://github.com/ajbrock/BigGAN-PyTorch.git -mv biggan.patch BigGAN-PyTorch -cd BigGAN-PyTorch -git apply biggan.patch -scp BigGAN.py .. -scp layers.py .. -scp inception_utils.py .. -cd .. -``` - -## 2. 环境说明 -### 2.1 深度学习框架 - -``` -CANN 5.0.3 -torch==1.8.0 -torchvision==0.9.0 -onnx==1.9.0 -``` -### 2.2 python第三方库 - -``` -numpy -onnxruntime -scipy==1.7.1 -onnx-simplifier==0.3.6 -onnxoptimizer==0.2.6 -``` - - **说明:** -> PyTorch版本: 请不要低于1.6.0,否则在.pth文件转.onnx文件的过程中会产生报错 -> pytorch,torchvision和onnx:(X86架构)可以通过官方下载whl包安装; (Arm架构)可以通过源码编译安装 -> 其他第三方库: 可以通过 pip3.7 install -r requirements.txt 进行安装 - -## 3. 模型转换 -一步式从pth权重文件转om模型的脚本,能够由pth权重文件生成bacth分别为1和16的om模型: -```bash -bash ./test/pth2om.sh -``` - **说明:** -> pth2om.sh中的6-14行: 完成pth转原始onnx模型 -> pth2om.sh中的18-29行: 完成onnx模型的简化,以及简化的onnx模型转om模型 - -运行后会生成如下文件: -```bash -├── biggan.onnx -├── biggan_sim_bs1.onnx -├── biggan_sim_bs16.onnx -├── biggan_sim_bs1.om -├── biggan_sim_bs16.om -``` - -### 3.1 pth转onnx模型 -1. 下载pth权重文件 - -[BigGAN预训练pth权重文件](https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/gan/BigGAN/G_ema.pth) -> **说明** -> 模型使用的权重文件名为G_ema.pth - -[Inception_v3预训练pth权重文件](https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/gan/BigGAN/inception_v3_google.pth) -> **说明** -> 下载的权重文件名为inception_v3_google.pth,此模型权重用于IS评价指标的计算,若仅进行图像生成,无需下载此权重文件 - -[ImageNet采样的npz数据](https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/gan/BigGAN/I128_inception_moments.npz) -> **说明** -> 采样数据名为I128_inception_moments.npz,此数据用于FID评价指标的计算,若仅进行图像生成,无需下载此数据文件 - -2. 执行biggan_pth2onnx.py脚本,生成onnx模型文件 -```bash -python3.7 biggan_pth2onnx.py --source "./G_ema.pth" --target "./biggan.onnx" -``` -若需要修改pth2onnx部分,请注意目前ATC支持的onnx算子版本为11 - -3. 执行clip_edit.py脚本,通过"input-model"和"output-model"参数指定输入和输出的onnx模型,默认输入输出均为"./biggan.onnx" -```bash -python3.7 clip_edit.py -``` -> **说明** -> 执行clip_edit.py目的在于初始化onnx模型中Clip节点中的"max"输入,便于后续onnx模型的简化 - -### 3.2 onnx转om模型 -1. 使用onnx-simplifier简化onnx模型 -生成batch size为1的简化onnx模型,对应的命令为: -```bash -python3.7 -m onnxsim './biggan.onnx' './biggan_sim_bs1.onnx' --input-shape "noise:1,1,20" "label:1,5,148" -``` - -2. 设置环境变量 - -```bash -source env.sh -``` - -3. 使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) - -```bash -atc --framework=5 --model=./biggan_sim_bs1.onnx --output=./biggan_sim_bs1 --input_format=ND --input_shape="noise:1,1,20;label:1,5,148" --log=error --soc_version=Ascend310 -``` - -## 4. 数据预处理 -- [输入数据生成](#41) -### 4.1 数据生成 -1. BigGAN模型的输入数据是由噪声数据和标签数据组成,其中噪声数据是由均值为0,方差为1的正态分布中采样,标签数据是由0至类别总数中随机采样一个整数 -2. 执行输入数据的生成脚本,生成模型输入的bin文件 - -```bash -#注:针对不同batch size的om模型需要生成不同的输入数据 -python3.7 biggan_preprocess.py --batch-size 1 --num-inputs 50000 -``` -运行后,将会得到如下形式的文件夹: - -``` -├── prep_label_bs1 -│ ├──input_00000.bin -│ ├──...... -│ -├── prep_noise_bs1 -│ ├──input_00000.bin -│ ├──...... -``` - -## 5. 离线推理 -执行一步式推理前,请先按照5.1节所示准备msame离线推理工具 -一步式进行输入数据的准备,模型离线推理和NPU性能数据的获取(针对batch1和batch16): -```bash -bash ./test/eval_perf.sh -``` -运行后会生成如下文件/文件夹: -```bash -├── prep_label_bs1 # 模型的标签输入(文件夹) -├── prep_label_bs16 -├── prep_noise_bs1 # 模型的噪声输入(文件夹) -├── prep_noise_bs16 -├── outputs_bs1_om # 模型的输出(文件夹) -├── outputs_bs16_om -├── gen_y_bs1.npz # 类别采样的npz数据 -├── gen_y_bs16.npz -├── msame_bs1.txt # msame推理过程的输出 -├── msame_bs16.txt -├── bs1_perf.log # 性能数据 -├── bs16_perf.log -``` -### 5.1 msame工具概述 -msame模型推理工具,其输入是om模型以及模型所需要的输入bin文件,其输出是模型根据相应输入产生的输出文件。获取工具及使用方法可以参考[msame模型推理工具指南](https://gitee.com/ascend/tools/tree/master/msame) -### 5.2 离线推理 -1. 设置环境变量 -```bash -source env.sh -``` -2. 执行离线推理 -运行如下命令进行离线推理: -```bash -./msame --model "./biggan_sim_bs1.om" --input "./prep_noise_bs1,./prep_label_bs1" --output "./outputs_bs1_om" --outfmt BIN > ./msame_bs1.txt -``` -模型输出格式是bin,输出保存在"output"参数指定的文件夹中,同时会生成推理的日志文件msame_bs1.txt -3. 性能数据的获取 -通过给test/parser.py指定推理后的日志文件,可以得到离线推理的性能数据 -```bash -python3.7 ./test/parse.py --txt-file "./msame_bs1.txt" --batch-size 1 > bs1_perf.log -``` -|模型|t4性能|310性能| -|----|----|----| -|BigGAN bs1|239.249fps|227.144fps| -|BigGAN bs16|344.900fps|282.898fps| - -## 6. 精度对比 -一步式进行输出数据的后处理和生成图像的评价指标(针对batch1和batch16): -```bash -bash ./test/eval_acc.sh -``` -运行后会生成如下文件/文件夹: -```bash -├── postprocess_img # 转换后的模型输出(文件夹) -├── gen_img_bs1.npz # 模型输出的npz数据 -├── gen_img_bs16.npz -├── biggan_acc_eval_bs1.log # 精度测量结果 -├── biggan_acc_eval_bs16.log -``` -### 6.1 模型后处理 -模型后处理将离线推理得到的bin文件转换为jpg图像文件,并将原始输出保存至npz文件中,用于精度数据的获取 -``` -python3.7 biggan_postprocess.py --result-path "./outputs_bs1_om" --save-path "./postprocess_img" --batch-size 1 --save-img --save-npz -``` -其中"result-path"表示离线推理输出所在的文件夹,"save-path"表示转换后图像文件的存储地址 -### 6.2 精度计算 -精度计算利用biggan_eval_acc.py脚本: -```bash -python3.7 biggan_eval_acc.py --num-inception-images 50000 --batch-size 1 --dataset 'I128' > biggan_acc_eval_bs1.log -``` -其中"num-inception-images"表示用于进行精度测量的输出数量,"dataset"指定用于对比分布所采用的数据集,I128表示ImageNet数据集在train上的采样 -> **说明** -> IS是生成图像的清晰度和多样性指标,其值越大说明越优 -> FID是生成图像集与真实图像集间的相似度指标,其值越小说明越优 - -| 模型 | IS | FID | -|-------|-------|-------| -|pth模型推理结果|94.323+/-2.395|9.9532| +# BigGAN ONNX模型端到端推理指导 +- [1. 模型概述](#1) + - [论文地址](#11) + - [代码地址](#12) +- [2. 环境说明](#2) + - [深度学习框架](#21) + - [python第三方库](#22) +- [3. 模型转换](#3) + - [pth转onnx模型](#31) + - [onnx转om模型](#32) +- [4. 输入数据生成](#4) + - [数据生成](#41) +- [5. 离线推理](#5) + - [msame工具概述](#51) + - [离线推理](#52) +- [6. 精度对比](#6) + - [模型后处理](#61) + - [精度计算](#62) + +## 1. 模型概述 +### 1.1 论文地址 +[BigGAN论文](https://arxiv.org/pdf/1809.11096.pdf) +### 1.2 代码地址 +[BigGAN代码](https://github.com/ajbrock/BigGAN-PyTorch) + +修改源码中的BigGAN.py、layers.py和inception_utils.py,并移至本项目中: +``` +git clone https://github.com/ajbrock/BigGAN-PyTorch.git +mv biggan.patch BigGAN-PyTorch +cd BigGAN-PyTorch +git apply biggan.patch +scp BigGAN.py .. +scp layers.py .. +scp inception_utils.py .. +cd .. +``` + +## 2. 环境说明 +### 2.1 深度学习框架 + +``` +CANN 5.0.3 +torch==1.8.0 +torchvision==0.9.0 +onnx==1.9.0 +``` +### 2.2 python第三方库 + +``` +numpy +onnxruntime +scipy==1.7.1 +onnx-simplifier==0.3.6 +onnxoptimizer==0.2.6 +``` + + **说明:** +> PyTorch版本: 请不要低于1.6.0,否则在.pth文件转.onnx文件的过程中会产生报错 +> pytorch,torchvision和onnx:(X86架构)可以通过官方下载whl包安装; (Arm架构)可以通过源码编译安装 +> 其他第三方库: 可以通过 pip3.7 install -r requirements.txt 进行安装 + +## 3. 模型转换 +一步式从pth权重文件转om模型的脚本,能够由pth权重文件生成bacth分别为1和16的om模型: +```bash +bash ./test/pth2om.sh +``` + **说明:** +> pth2om.sh中的6-14行: 完成pth转原始onnx模型 +> pth2om.sh中的18-29行: 完成onnx模型的简化,以及简化的onnx模型转om模型 + +运行后会生成如下文件: +```bash +├── biggan.onnx +├── biggan_sim_bs1.onnx +├── biggan_sim_bs16.onnx +├── biggan_sim_bs1.om +├── biggan_sim_bs16.om +``` + +### 3.1 pth转onnx模型 +1. 下载pth权重文件 + +[BigGAN预训练pth权重文件](https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/gan/BigGAN/G_ema.pth) +> **说明** +> 模型使用的权重文件名为G_ema.pth + +[Inception_v3预训练pth权重文件](https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/gan/BigGAN/inception_v3_google.pth) +> **说明** +> 下载的权重文件名为inception_v3_google.pth,此模型权重用于IS评价指标的计算,若仅进行图像生成,无需下载此权重文件 + +[ImageNet采样的npz数据](https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/gan/BigGAN/I128_inception_moments.npz) +> **说明** +> 采样数据名为I128_inception_moments.npz,此数据用于FID评价指标的计算,若仅进行图像生成,无需下载此数据文件 + +2. 执行biggan_pth2onnx.py脚本,生成onnx模型文件 +```bash +python3.7 biggan_pth2onnx.py --source "./G_ema.pth" --target "./biggan.onnx" +``` +若需要修改pth2onnx部分,请注意目前ATC支持的onnx算子版本为11 + +3. 执行clip_edit.py脚本,通过"input-model"和"output-model"参数指定输入和输出的onnx模型,默认输入输出均为"./biggan.onnx" +```bash +python3.7 clip_edit.py +``` +> **说明** +> 执行clip_edit.py目的在于初始化onnx模型中Clip节点中的"max"输入,便于后续onnx模型的简化 + +### 3.2 onnx转om模型 +1. 使用onnx-simplifier简化onnx模型 +生成batch size为1的简化onnx模型,对应的命令为: +```bash +python3.7 -m onnxsim './biggan.onnx' './biggan_sim_bs1.onnx' --input-shape "noise:1,1,20" "label:1,5,148" +``` + +2. 设置环境变量 + +```bash +source env.sh +``` + +3. 使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN V100R020C10 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) + +```bash +atc --framework=5 --model=./biggan_sim_bs1.onnx --output=./biggan_sim_bs1 --input_format=ND --input_shape="noise:1,1,20;label:1,5,148" --log=error --soc_version=Ascend310 +``` + +## 4. 数据预处理 +- [输入数据生成](#41) +### 4.1 数据生成 +1. BigGAN模型的输入数据是由噪声数据和标签数据组成,其中噪声数据是由均值为0,方差为1的正态分布中采样,标签数据是由0至类别总数中随机采样一个整数 +2. 执行输入数据的生成脚本,生成模型输入的bin文件 + +```bash +#注:针对不同batch size的om模型需要生成不同的输入数据 +python3.7 biggan_preprocess.py --batch-size 1 --num-inputs 50000 +``` +运行后,将会得到如下形式的文件夹: + +``` +├── prep_label_bs1 +│ ├──input_00000.bin +│ ├──...... +│ +├── prep_noise_bs1 +│ ├──input_00000.bin +│ ├──...... +``` + +## 5. 离线推理 +执行一步式推理前,请先按照5.1节所示准备msame离线推理工具 +一步式进行输入数据的准备,模型离线推理和NPU性能数据的获取(针对batch1和batch16): +```bash +bash ./test/eval_perf.sh +``` +运行后会生成如下文件/文件夹: +```bash +├── prep_label_bs1 # 模型的标签输入(文件夹) +├── prep_label_bs16 +├── prep_noise_bs1 # 模型的噪声输入(文件夹) +├── prep_noise_bs16 +├── outputs_bs1_om # 模型的输出(文件夹) +├── outputs_bs16_om +├── gen_y_bs1.npz # 类别采样的npz数据 +├── gen_y_bs16.npz +├── msame_bs1.txt # msame推理过程的输出 +├── msame_bs16.txt +├── bs1_perf.log # 性能数据 +├── bs16_perf.log +``` +### 5.1 msame工具概述 +msame模型推理工具,其输入是om模型以及模型所需要的输入bin文件,其输出是模型根据相应输入产生的输出文件。获取工具及使用方法可以参考[msame模型推理工具指南](https://gitee.com/ascend/tools/tree/master/msame) +### 5.2 离线推理 +1. 设置环境变量 +```bash +source env.sh +``` +2. 执行离线推理 +运行如下命令进行离线推理: +```bash +./msame --model "./biggan_sim_bs1.om" --input "./prep_noise_bs1,./prep_label_bs1" --output "./outputs_bs1_om" --outfmt BIN > ./msame_bs1.txt +``` +模型输出格式是bin,输出保存在"output"参数指定的文件夹中,同时会生成推理的日志文件msame_bs1.txt +3. 性能数据的获取 +通过给test/parser.py指定推理后的日志文件,可以得到离线推理的性能数据 +```bash +python3.7 ./test/parse.py --txt-file "./msame_bs1.txt" --batch-size 1 > bs1_perf.log +``` +|模型|t4性能|310性能| +|----|----|----| +|BigGAN bs1|239.249fps|227.144fps| +|BigGAN bs16|344.900fps|282.898fps| + +## 6. 精度对比 +一步式进行输出数据的后处理和生成图像的评价指标(针对batch1和batch16): +```bash +bash ./test/eval_acc.sh +``` +运行后会生成如下文件/文件夹: +```bash +├── postprocess_img # 转换后的模型输出(文件夹) +├── gen_img_bs1.npz # 模型输出的npz数据 +├── gen_img_bs16.npz +├── biggan_acc_eval_bs1.log # 精度测量结果 +├── biggan_acc_eval_bs16.log +``` +### 6.1 模型后处理 +模型后处理将离线推理得到的bin文件转换为jpg图像文件,并将原始输出保存至npz文件中,用于精度数据的获取 +``` +python3.7 biggan_postprocess.py --result-path "./outputs_bs1_om" --save-path "./postprocess_img" --batch-size 1 --save-img --save-npz +``` +其中"result-path"表示离线推理输出所在的文件夹,"save-path"表示转换后图像文件的存储地址 +### 6.2 精度计算 +精度计算利用biggan_eval_acc.py脚本: +```bash +python3.7 biggan_eval_acc.py --num-inception-images 50000 --batch-size 1 --dataset 'I128' > biggan_acc_eval_bs1.log +``` +其中"num-inception-images"表示用于进行精度测量的输出数量,"dataset"指定用于对比分布所采用的数据集,I128表示ImageNet数据集在train上的采样 +> **说明** +> IS是生成图像的清晰度和多样性指标,其值越大说明越优 +> FID是生成图像集与真实图像集间的相似度指标,其值越小说明越优 + +| 模型 | IS | FID | +|-------|-------|-------| +|pth模型推理结果|94.323+/-2.395|9.9532| |om模型离线推理结果|94.009+/-1.626|10.0411| \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/BigGAN/biggan_pth2onnx.py b/ACL_PyTorch/contrib/cv/gan/BigGAN/biggan_pth2onnx.py index 87fc7ce99ce00295ad02c943ca01e2d227ac2b6c..060de082565b7c6077df3cf033a0d333a8a8b01e 100644 --- a/ACL_PyTorch/contrib/cv/gan/BigGAN/biggan_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/gan/BigGAN/biggan_pth2onnx.py @@ -1,63 +1,63 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import onnx -import torch -import argparse - -from BigGAN import Generator -from collections import OrderedDict - - -def proc_nodes_module(checkpoint): - new_state_dict = OrderedDict() - for k, v in checkpoint.items(): - if (k[0:7] == "module."): - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - - -def pth2onnx(input_file, output_file): - checkpoint = torch.load(input_file, map_location=torch.device('cpu')) - checkpoint = proc_nodes_module(checkpoint) - - model = Generator(**{'G_lr':1e-4, 'SN_eps':1e-6, 'adam_eps':1e-6, - 'G_ch':96, 'shared_dim':128, - 'skip_init':True, 'no_optim': True, - 'hier':True, 'dim_z':120}) - model.load_state_dict(checkpoint) - model.eval() - - input_names = ['noise', 'label'] - output_names = ['image'] - dynamic_axes = {'noise': {0: '-1'}, 'label': {0: '-1'}, 'image': {0: '-1'}} - - dummy_z = torch.randn((1, 1, 20)) - dummy_y = torch.randn((1, 5, 148)) - - torch.onnx.export(model, (dummy_z, dummy_y), output_file, dynamic_axes=dynamic_axes, - verbose=True, input_names=input_names, output_names=output_names, opset_version=11) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--source', type=str, default="./G_ema.pth") - parser.add_argument('--target', type=str, default="./biggan.onnx") - args = parser.parse_args() - - pth2onnx(args.source, args.target) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import onnx +import torch +import argparse + +from BigGAN import Generator +from collections import OrderedDict + + +def proc_nodes_module(checkpoint): + new_state_dict = OrderedDict() + for k, v in checkpoint.items(): + if (k[0:7] == "module."): + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + + +def pth2onnx(input_file, output_file): + checkpoint = torch.load(input_file, map_location=torch.device('cpu')) + checkpoint = proc_nodes_module(checkpoint) + + model = Generator(**{'G_lr':1e-4, 'SN_eps':1e-6, 'adam_eps':1e-6, + 'G_ch':96, 'shared_dim':128, + 'skip_init':True, 'no_optim': True, + 'hier':True, 'dim_z':120}) + model.load_state_dict(checkpoint) + model.eval() + + input_names = ['noise', 'label'] + output_names = ['image'] + dynamic_axes = {'noise': {0: '-1'}, 'label': {0: '-1'}, 'image': {0: '-1'}} + + dummy_z = torch.randn((1, 1, 20)) + dummy_y = torch.randn((1, 5, 148)) + + torch.onnx.export(model, (dummy_z, dummy_y), output_file, dynamic_axes=dynamic_axes, + verbose=True, input_names=input_names, output_names=output_names, opset_version=11) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--source', type=str, default="./G_ema.pth") + parser.add_argument('--target', type=str, default="./biggan.onnx") + args = parser.parse_args() + + pth2onnx(args.source, args.target) diff --git a/ACL_PyTorch/contrib/cv/gan/BigGAN/requirements.txt b/ACL_PyTorch/contrib/cv/gan/BigGAN/requirements.txt index 71eeab2b4d21acf9f69ba601d5f082aba8101f73..ac7e94fc98f48ca1b22db28c0fde37d54dff028f 100644 --- a/ACL_PyTorch/contrib/cv/gan/BigGAN/requirements.txt +++ b/ACL_PyTorch/contrib/cv/gan/BigGAN/requirements.txt @@ -1,5 +1,5 @@ -numpy -onnxruntime==1.9.0 -scipy==1.7.1 -onnx-simplifier==0.3.6 +numpy +onnxruntime==1.9.0 +scipy==1.7.1 +onnx-simplifier==0.3.6 onnxoptimizer==0.2.6 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/CGAN/CGAN_postprocess.py b/ACL_PyTorch/contrib/cv/gan/CGAN/CGAN_postprocess.py index 337d3a4ff0108f6a32982fc52dd1983c51b7ffab..7f6d58130451458433758e8de696e4b58e28129c 100644 --- a/ACL_PyTorch/contrib/cv/gan/CGAN/CGAN_postprocess.py +++ b/ACL_PyTorch/contrib/cv/gan/CGAN/CGAN_postprocess.py @@ -1,76 +1,76 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -from CGAN import generator as G -import os -import numpy as np -import torch -import struct -import glob -import sys -import utils -import argparse - - -def parse_args(): - desc = "Pytorch implementation of CGAN collections" - parser = argparse.ArgumentParser(description=desc) - parser.add_argument('--bin_out_path', type=str, default='', help="the output inferenced") - parser.add_argument('--save_path', type=str, default='result', help="the generated image path") - return parser.parse_args() - - -def get_save_path(bin_folder): - result_paths = [] - files_source = glob.glob(os.path.join(bin_folder,'*.bin')) - files_source.sort() - for file in files_source: - if file.endswith('.bin'): - result_path = file - result_paths.append(result_path) - return result_paths - - -def file2tensor(output_bin): - size = os.path.getsize(output_bin) - res1 = [] - L = int(size / 4) - binfile = open(output_bin, 'rb') - for i in range(L): - data = binfile.read(4) - num = struct.unpack('f', data) - res1.append(num[0]) - binfile.close() - dim_res = np.array(res1).reshape(100,3,28,28) - tensor_res = torch.tensor(dim_res, dtype=torch.float32) - return tensor_res - - -def post_process(args): - result_paths = get_save_path(args.bin_out_path) - for i in range(len(result_paths)): - result = file2tensor(result_paths[i]) - result = result.data.numpy().transpose(0, 2, 3, 1) - result = (result + 1)/2 - sample_num = 100 - image_frame_dim = int(np.floor(np.sqrt(sample_num))) - if not os.path.exists(os.path.join(args.save_path)): - os.makedirs(os.path.join(args.save_path)) - utils.save_images(result[:image_frame_dim * image_frame_dim, :, :, :], [image_frame_dim, image_frame_dim], - os.path.join(args.save_path,'result.png')) - print("postprocess image stored in:", os.path.join(args.save_path,'result.png')) - -if __name__ == "__main__": - args = parse_args() - post_process(args) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +from CGAN import generator as G +import os +import numpy as np +import torch +import struct +import glob +import sys +import utils +import argparse + + +def parse_args(): + desc = "Pytorch implementation of CGAN collections" + parser = argparse.ArgumentParser(description=desc) + parser.add_argument('--bin_out_path', type=str, default='', help="the output inferenced") + parser.add_argument('--save_path', type=str, default='result', help="the generated image path") + return parser.parse_args() + + +def get_save_path(bin_folder): + result_paths = [] + files_source = glob.glob(os.path.join(bin_folder,'*.bin')) + files_source.sort() + for file in files_source: + if file.endswith('.bin'): + result_path = file + result_paths.append(result_path) + return result_paths + + +def file2tensor(output_bin): + size = os.path.getsize(output_bin) + res1 = [] + L = int(size / 4) + binfile = open(output_bin, 'rb') + for i in range(L): + data = binfile.read(4) + num = struct.unpack('f', data) + res1.append(num[0]) + binfile.close() + dim_res = np.array(res1).reshape(100,3,28,28) + tensor_res = torch.tensor(dim_res, dtype=torch.float32) + return tensor_res + + +def post_process(args): + result_paths = get_save_path(args.bin_out_path) + for i in range(len(result_paths)): + result = file2tensor(result_paths[i]) + result = result.data.numpy().transpose(0, 2, 3, 1) + result = (result + 1)/2 + sample_num = 100 + image_frame_dim = int(np.floor(np.sqrt(sample_num))) + if not os.path.exists(os.path.join(args.save_path)): + os.makedirs(os.path.join(args.save_path)) + utils.save_images(result[:image_frame_dim * image_frame_dim, :, :, :], [image_frame_dim, image_frame_dim], + os.path.join(args.save_path,'result.png')) + print("postprocess image stored in:", os.path.join(args.save_path,'result.png')) + +if __name__ == "__main__": + args = parse_args() + post_process(args) diff --git a/ACL_PyTorch/contrib/cv/gan/CGAN/CGAN_preprocess.py b/ACL_PyTorch/contrib/cv/gan/CGAN/CGAN_preprocess.py index 35c336b7791ebbf2b51e62f2fa78d37c3a0ffb60..a2bf65dca850258f97bafb5b1b2f43a1593ba649 100644 --- a/ACL_PyTorch/contrib/cv/gan/CGAN/CGAN_preprocess.py +++ b/ACL_PyTorch/contrib/cv/gan/CGAN/CGAN_preprocess.py @@ -1,63 +1,63 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import torch -import numpy as np -import os -import argparse - - -def parse_args(): - desc = "Pytorch implementation of CGAN collections" - parser = argparse.ArgumentParser(description=desc) - parser.add_argument('--input_dim', type=int, default=62, help="The input_dim") - parser.add_argument('--output_dim', type=int, default=3, help="The output_dim") - parser.add_argument('--input_size', type=int, default=28, help="The image size of MNIST") - parser.add_argument('--class_num', type=int, default=10, help="The num of classes of MNIST") - parser.add_argument('--pth_path', type=str, default='CGAN_G.pth', help='pth model path') - parser.add_argument('--onnx_path', type=str, default="CGAN.onnx", help='onnx model path') - parser.add_argument('--save_path', type=str, default="data", help='processed data path') - return parser.parse_args() - - -# fixed noise & condition -def prep_preocess(args): - sample_num = args.class_num**2 - z_dim = args.input_dim - sample_z_ = torch.zeros((sample_num, z_dim)) - for i in range(args.class_num): - sample_z_[i * args.class_num] = torch.rand(1,z_dim) - for j in range(1, args.class_num): - sample_z_[i * args.class_num + j] = sample_z_[i * args.class_num] - - if not os.path.exists(os.path.join(args.save_path)): - os.makedirs(os.path.join(args.save_path)) - - temp = torch.zeros((args.class_num, 1)) - for i in range(args.class_num): - temp[i, 0] = i - - temp_y = torch.zeros((sample_num, 1)) - for i in range(args.class_num): - temp_y[i * args.class_num: (i + 1) * args.class_num] = temp - - sample_y_ = torch.zeros((sample_num, args.class_num)).scatter_(1, temp_y.type(torch.LongTensor), 1) - - input = torch.cat([sample_z_, sample_y_], 1) - input = np.array(input).astype(np.float32) - input.tofile(os.path.join(args.save_path, 'input' + '.bin')) -if __name__ == "__main__": - args = parse_args() - prep_preocess(args) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import torch +import numpy as np +import os +import argparse + + +def parse_args(): + desc = "Pytorch implementation of CGAN collections" + parser = argparse.ArgumentParser(description=desc) + parser.add_argument('--input_dim', type=int, default=62, help="The input_dim") + parser.add_argument('--output_dim', type=int, default=3, help="The output_dim") + parser.add_argument('--input_size', type=int, default=28, help="The image size of MNIST") + parser.add_argument('--class_num', type=int, default=10, help="The num of classes of MNIST") + parser.add_argument('--pth_path', type=str, default='CGAN_G.pth', help='pth model path') + parser.add_argument('--onnx_path', type=str, default="CGAN.onnx", help='onnx model path') + parser.add_argument('--save_path', type=str, default="data", help='processed data path') + return parser.parse_args() + + +# fixed noise & condition +def prep_preocess(args): + sample_num = args.class_num**2 + z_dim = args.input_dim + sample_z_ = torch.zeros((sample_num, z_dim)) + for i in range(args.class_num): + sample_z_[i * args.class_num] = torch.rand(1,z_dim) + for j in range(1, args.class_num): + sample_z_[i * args.class_num + j] = sample_z_[i * args.class_num] + + if not os.path.exists(os.path.join(args.save_path)): + os.makedirs(os.path.join(args.save_path)) + + temp = torch.zeros((args.class_num, 1)) + for i in range(args.class_num): + temp[i, 0] = i + + temp_y = torch.zeros((sample_num, 1)) + for i in range(args.class_num): + temp_y[i * args.class_num: (i + 1) * args.class_num] = temp + + sample_y_ = torch.zeros((sample_num, args.class_num)).scatter_(1, temp_y.type(torch.LongTensor), 1) + + input = torch.cat([sample_z_, sample_y_], 1) + input = np.array(input).astype(np.float32) + input.tofile(os.path.join(args.save_path, 'input' + '.bin')) +if __name__ == "__main__": + args = parse_args() + prep_preocess(args) print("data preprocessed stored in",args.save_path) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/CGAN/CGAN_pth2onnx.py b/ACL_PyTorch/contrib/cv/gan/CGAN/CGAN_pth2onnx.py index 2da7ae2176242e91df33961ff720e331b3f21278..0ee964ab8aba21cdbc0694b9be36ebaf8def4a5d 100644 --- a/ACL_PyTorch/contrib/cv/gan/CGAN/CGAN_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/gan/CGAN/CGAN_pth2onnx.py @@ -1,66 +1,66 @@ - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -from CGAN import generator -import torch -import torch.onnx -import sys -from collections import OrderedDict -import argparse - - -def parse_args(): - desc = "Pytorch implementation of CGAN collections" - parser = argparse.ArgumentParser(description=desc) - parser.add_argument('--input_dim', type=int, default=62, help="The input_dim") - parser.add_argument('--output_dim', type=int, default=3, help="The output_dim") - parser.add_argument('--input_size', type=int, default=28, help="The image size of MNIST") - parser.add_argument('--class_num', type=int, default=10, help="The num of classes of MNIST") - parser.add_argument('--pth_path', type=str, default='CGAN_G.pth', help='pth model path') - parser.add_argument('--onnx_path', type=str, default="CGAN.onnx", help='onnx model path') - return parser.parse_args() - - -def proc_nodes_module(checkpoint): - new_state_dict = OrderedDict() - for k, v in checkpoint.items(): - if "module." in k: - name = k.replace("module.", "") - else: - name = k - new_state_dict[name] = v - return new_state_dict - -def pth2onnx(): - args = parse_args() - net = generator(input_dim=args.input_dim, output_dim=args.output_dim, - input_size=args.input_size, class_num=args.class_num) - model = net - checkpoint = torch.load(args.pth_path, map_location='cpu') - checkpoint = proc_nodes_module(checkpoint) - model.load_state_dict(checkpoint) - model.eval() - input_names = ["image"] - output_names = ["output1"] - #dynamic_axes = {'image': {0: '-1'}, 'output1': {0: '-1'}} - dummy_input1 = torch.randn(100, 72) - torch.onnx.export(model, dummy_input1, args.onnx_path, input_names=input_names, - output_names=output_names, opset_version=11, verbose=True) - print("this model could generete pictures, specifically digits") - print('onnx export done.') - - -if __name__ == "__main__": + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +from CGAN import generator +import torch +import torch.onnx +import sys +from collections import OrderedDict +import argparse + + +def parse_args(): + desc = "Pytorch implementation of CGAN collections" + parser = argparse.ArgumentParser(description=desc) + parser.add_argument('--input_dim', type=int, default=62, help="The input_dim") + parser.add_argument('--output_dim', type=int, default=3, help="The output_dim") + parser.add_argument('--input_size', type=int, default=28, help="The image size of MNIST") + parser.add_argument('--class_num', type=int, default=10, help="The num of classes of MNIST") + parser.add_argument('--pth_path', type=str, default='CGAN_G.pth', help='pth model path') + parser.add_argument('--onnx_path', type=str, default="CGAN.onnx", help='onnx model path') + return parser.parse_args() + + +def proc_nodes_module(checkpoint): + new_state_dict = OrderedDict() + for k, v in checkpoint.items(): + if "module." in k: + name = k.replace("module.", "") + else: + name = k + new_state_dict[name] = v + return new_state_dict + +def pth2onnx(): + args = parse_args() + net = generator(input_dim=args.input_dim, output_dim=args.output_dim, + input_size=args.input_size, class_num=args.class_num) + model = net + checkpoint = torch.load(args.pth_path, map_location='cpu') + checkpoint = proc_nodes_module(checkpoint) + model.load_state_dict(checkpoint) + model.eval() + input_names = ["image"] + output_names = ["output1"] + #dynamic_axes = {'image': {0: '-1'}, 'output1': {0: '-1'}} + dummy_input1 = torch.randn(100, 72) + torch.onnx.export(model, dummy_input1, args.onnx_path, input_names=input_names, + output_names=output_names, opset_version=11, verbose=True) + print("this model could generete pictures, specifically digits") + print('onnx export done.') + + +if __name__ == "__main__": pth2onnx() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/CGAN/README.md b/ACL_PyTorch/contrib/cv/gan/CGAN/README.md index 659e1d55f7f93ddf11181bf67e40ed28ad4539f2..dd932ea1ad4fe0d8e711e1d7e81730fcf081f408 100644 --- a/ACL_PyTorch/contrib/cv/gan/CGAN/README.md +++ b/ACL_PyTorch/contrib/cv/gan/CGAN/README.md @@ -1,265 +1,265 @@ -# CGAN推理说明 - -## 1 模型概述 - -- **[论文地址](https://arxiv.org/abs/1411.1784)** -- **[代码地址](https://github.com/znxlwm/pytorch-generative-model-collections/)** - -### 1.1 论文地址 - -[CGAN论文](https://github.com/znxlwm/pytorch-generative-model-collections/) - -### 1.2 代码地址 - -[CGAN代码](https://github.com/znxlwm/pytorch-generative-model-collections/) - -branch:master - -commitid:0d183bb5ea2fbe069e1c6806c4a9a1fd8e81656f - - -## 2 环境说明 - -- 深度学习框架 -- python第三方库 - -### 2.1 深度学习框架 - -``` -python3.7.5 -CANN 5.0.3 - -pytorch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.10.2 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.21.2 -Pillow == 8.4.0 -imageio == 2.9.0 -scipy == 1.7.1 -matplotlib==3.4.3 -``` - -## 3 模型转换 - -- pth转om模型 - -### 3.1 pth转om模型 - -1.获取pth权重文件 - -pth权重文件随附件一起打包 - -2.下载CGAN推理代码 - -``` -git clone https://gitee.com/wang-chaojiemayj/modelzoo.git -cd modelzoo -git checkout tuili -``` - -进入CGANt目录 - -``` -cd ./contrib/ACL_PyTorch/Research/cv/GAN/CGAN -``` - -3.pth模型转onnx模型,onnx转成om模型 - -pth模型转onnx模型 - -``` -python3.7 CGAN_pth2onnx.py --pth_path CGAN_G.pth --onnx_path CGAN.onnx -python3.7 -m onnxsim --input-shape="100,72" CGAN.onnx CGAN_sim.onnx -``` - -onnx转出om,并使用autotune优化om模型,这将耗费大量时间 - -``` -source env.sh(注意,latest是一个软连接,请将服务器中的/usr/local/Ascend/ascend-toolkit/latest 指向5.0.3版本的CANN包) -# 生成器一次只能生成一张图,由于模型输入是两维的,不是常用的NCHW格式,input_format采用ND形式 -atc --framework=5 --model=CGAN_sim.onnx --output=CGAN_bs1 --input_format=ND --output_type=FP32 --input_shape="image:100,72" --log=debug --soc_version=Ascend310 --auto_tune_mode="RL,GA" -``` - -## 4 数据集预处理 - -- 数据集获取 -- 数据预处理 -- 生成数据集信息文件 - -### 4.1 数据集获取 - -本模型的输入数据由随机数以及标签生成,在CGAN_preprocess.py中会生成数据并转成二进制文件,并保存在。’./prep_dataset‘目录下。 - -文件结构如下 - -``` -|CGAN--test -| | |--pth2om.sh -| | |--eval_acc_perf.sh -| | |--perf_t4.sh -| |--util.py -| |--CGAN.py -| |--gen_dataset_info.py -| |--env.sh -| |--CGAN_pth2onnx.py -| |--CGAN_preprocess.py -| |--CGAN_postprocess.py -| |--requirements.txt -| |--LICENCE -| |--modelzoo_level.txt -| |--README.md -``` - - -### 4.2 数据集预处理 - -运行CGAN_preprocess.py - -``` -python3.7 CGAN_preprocess.py --save_path ./prep_dataset -``` - -二进制文件将保存在./prep_dataset目录下 - -### 4.3 生成数据集信息文件 - -1.执行生成数据集信息脚本gen_dataset_info.py,生成数据集信息文件 - -``` -python3.7 gen_dataset_info.py --dataset_bin ./prep_dataset --info_name CGAN_prep_bin.info --width 72 --height 100 -``` - -## 5 离线推理 - -- msame概述 -- 离线推理 - -### 5.1 msame工具概述 - -msame工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.1 推理msame工具用户指南 - -### 5.2 离线推理 - -1.设置环境变量 - -``` -source env.sh -``` - -2.执行离线推理 - -``` -./msame --model "./CGAN_bs1.om" --input "./prep_dataset/input.bin" --output "./out" --outfmt BIN --loop 1 -``` - -输出结果保存在'./out'目录下 - -## 6 精度对比 - -- 离线推理精度 -- 开源精度 -- 开源精度对比 - -### 6.1 离线推理精度统计 - -将msame推理获得的输出结果进行后处理,保存为图片 - -``` -python3.7 CGAN_postprocess.py --bin_out_path ./out/20211124_090506 --save_path ./result -``` - -第一个参数为msame输出目录,’/20211113_073952‘是离线推理时根据时间自动生成的目录,请根据实际情况改变,第二个参数为保存后处理产生的图片的目录。 - -### 6.2 开源精度 - -![](README.assets/CGAN_epoch050-16371406300071.png) - -### 6.3 精度对比 - -![](README.assets/result.png) - -om模型可以正常生成数字,与pth模型生成的图片大致一致。 - -## 7 性能对比 - -- NPU性能数据 -- T4性能数据 -- 性能对比 - -### 7.1 npu性能数据 - -1.使用msame工具执行以下指令通过纯推理获得性能数据 - -``` -./msame --model "CGAN_bs1.om" --output "./out" --outfmt BIN --loop 20 -``` - -结果如下: - -``` -[INFO] get max dynamic batch size success -[INFO] output data success -Inference average time: 2.554200 ms -Inference average time without first time: 2.547842 ms -[INFO] destroy model input success. -``` - -310单卡吞吐率:1000*(1/2.547842)*4=1568fps - - -### 7.2 T4性能数据 - -在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2。 -执行以下命令获取T4性能数据 - -``` -trtexec --onnx=CGAN.onnx --fp16 --shapes=image:100,72 --threads -``` - -``` -[11/14/2021-09:17:40] [I] GPU Compute -[11/14/2021-09:17:40] [I] min: 0.407471 ms -[11/14/2021-09:17:40] [I] max: 2.23047 ms -[11/14/2021-09:17:40] [I] mean: 0.427789 ms -[11/14/2021-09:17:40] [I] median: 0.428223 ms -[11/14/2021-09:17:40] [I] percentile: 0.4552 ms at 99% -[11/14/2021-09:17:40] [I] total compute time: 2.96629 s -``` - -T4单卡吞吐率:1000/(0.428223/1)=2337fps - -### 7.3 性能对比 - -310性能:1000*(1/2.547842)*4=1568fps - -T4性能:1000/(0.428223/1)=2337fps - -310性能低于T4性能。 - -### 7.4 性能优化 - -autotune优化,结果如下: - -![img](README.assets/wps8587.tmp-16378261403441.jpg) - -优化TransData,TransPose,结果如下: - -![img](README.assets/wps229E.tmp.jpg) - -onnxsim优化onnx,结果如下: - -![img](README.assets/wps4092.tmp.jpg) - -最终经过autotune优化,优化TransData、TransPose,onnxsim优化onnx之后,最终的结果如下: - -![image-20211125154623271](README.assets/image-20211125154623271.png) - -最终的性能为:1000/0.065243*4=1936FPS - - - +# CGAN推理说明 + +## 1 模型概述 + +- **[论文地址](https://arxiv.org/abs/1411.1784)** +- **[代码地址](https://github.com/znxlwm/pytorch-generative-model-collections/)** + +### 1.1 论文地址 + +[CGAN论文](https://github.com/znxlwm/pytorch-generative-model-collections/) + +### 1.2 代码地址 + +[CGAN代码](https://github.com/znxlwm/pytorch-generative-model-collections/) + +branch:master + +commitid:0d183bb5ea2fbe069e1c6806c4a9a1fd8e81656f + + +## 2 环境说明 + +- 深度学习框架 +- python第三方库 + +### 2.1 深度学习框架 + +``` +python3.7.5 +CANN 5.0.3 + +pytorch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.10.2 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.21.2 +Pillow == 8.4.0 +imageio == 2.9.0 +scipy == 1.7.1 +matplotlib==3.4.3 +``` + +## 3 模型转换 + +- pth转om模型 + +### 3.1 pth转om模型 + +1.获取pth权重文件 + +pth权重文件随附件一起打包 + +2.下载CGAN推理代码 + +``` +git clone https://gitee.com/wang-chaojiemayj/modelzoo.git +cd modelzoo +git checkout tuili +``` + +进入CGANt目录 + +``` +cd ./contrib/ACL_PyTorch/Research/cv/GAN/CGAN +``` + +3.pth模型转onnx模型,onnx转成om模型 + +pth模型转onnx模型 + +``` +python3.7 CGAN_pth2onnx.py --pth_path CGAN_G.pth --onnx_path CGAN.onnx +python3.7 -m onnxsim --input-shape="100,72" CGAN.onnx CGAN_sim.onnx +``` + +onnx转出om,并使用autotune优化om模型,这将耗费大量时间 + +``` +source env.sh(注意,latest是一个软连接,请将服务器中的/usr/local/Ascend/ascend-toolkit/latest 指向5.0.3版本的CANN包) +# 生成器一次只能生成一张图,由于模型输入是两维的,不是常用的NCHW格式,input_format采用ND形式 +atc --framework=5 --model=CGAN_sim.onnx --output=CGAN_bs1 --input_format=ND --output_type=FP32 --input_shape="image:100,72" --log=debug --soc_version=Ascend310 --auto_tune_mode="RL,GA" +``` + +## 4 数据集预处理 + +- 数据集获取 +- 数据预处理 +- 生成数据集信息文件 + +### 4.1 数据集获取 + +本模型的输入数据由随机数以及标签生成,在CGAN_preprocess.py中会生成数据并转成二进制文件,并保存在。’./prep_dataset‘目录下。 + +文件结构如下 + +``` +|CGAN--test +| | |--pth2om.sh +| | |--eval_acc_perf.sh +| | |--perf_t4.sh +| |--util.py +| |--CGAN.py +| |--gen_dataset_info.py +| |--env.sh +| |--CGAN_pth2onnx.py +| |--CGAN_preprocess.py +| |--CGAN_postprocess.py +| |--requirements.txt +| |--LICENCE +| |--modelzoo_level.txt +| |--README.md +``` + + +### 4.2 数据集预处理 + +运行CGAN_preprocess.py + +``` +python3.7 CGAN_preprocess.py --save_path ./prep_dataset +``` + +二进制文件将保存在./prep_dataset目录下 + +### 4.3 生成数据集信息文件 + +1.执行生成数据集信息脚本gen_dataset_info.py,生成数据集信息文件 + +``` +python3.7 gen_dataset_info.py --dataset_bin ./prep_dataset --info_name CGAN_prep_bin.info --width 72 --height 100 +``` + +## 5 离线推理 + +- msame概述 +- 离线推理 + +### 5.1 msame工具概述 + +msame工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.1 推理msame工具用户指南 + +### 5.2 离线推理 + +1.设置环境变量 + +``` +source env.sh +``` + +2.执行离线推理 + +``` +./msame --model "./CGAN_bs1.om" --input "./prep_dataset/input.bin" --output "./out" --outfmt BIN --loop 1 +``` + +输出结果保存在'./out'目录下 + +## 6 精度对比 + +- 离线推理精度 +- 开源精度 +- 开源精度对比 + +### 6.1 离线推理精度统计 + +将msame推理获得的输出结果进行后处理,保存为图片 + +``` +python3.7 CGAN_postprocess.py --bin_out_path ./out/20211124_090506 --save_path ./result +``` + +第一个参数为msame输出目录,’/20211113_073952‘是离线推理时根据时间自动生成的目录,请根据实际情况改变,第二个参数为保存后处理产生的图片的目录。 + +### 6.2 开源精度 + +![](README.assets/CGAN_epoch050-16371406300071.png) + +### 6.3 精度对比 + +![](README.assets/result.png) + +om模型可以正常生成数字,与pth模型生成的图片大致一致。 + +## 7 性能对比 + +- NPU性能数据 +- T4性能数据 +- 性能对比 + +### 7.1 npu性能数据 + +1.使用msame工具执行以下指令通过纯推理获得性能数据 + +``` +./msame --model "CGAN_bs1.om" --output "./out" --outfmt BIN --loop 20 +``` + +结果如下: + +``` +[INFO] get max dynamic batch size success +[INFO] output data success +Inference average time: 2.554200 ms +Inference average time without first time: 2.547842 ms +[INFO] destroy model input success. +``` + +310单卡吞吐率:1000*(1/2.547842)*4=1568fps + + +### 7.2 T4性能数据 + +在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2。 +执行以下命令获取T4性能数据 + +``` +trtexec --onnx=CGAN.onnx --fp16 --shapes=image:100,72 --threads +``` + +``` +[11/14/2021-09:17:40] [I] GPU Compute +[11/14/2021-09:17:40] [I] min: 0.407471 ms +[11/14/2021-09:17:40] [I] max: 2.23047 ms +[11/14/2021-09:17:40] [I] mean: 0.427789 ms +[11/14/2021-09:17:40] [I] median: 0.428223 ms +[11/14/2021-09:17:40] [I] percentile: 0.4552 ms at 99% +[11/14/2021-09:17:40] [I] total compute time: 2.96629 s +``` + +T4单卡吞吐率:1000/(0.428223/1)=2337fps + +### 7.3 性能对比 + +310性能:1000*(1/2.547842)*4=1568fps + +T4性能:1000/(0.428223/1)=2337fps + +310性能低于T4性能。 + +### 7.4 性能优化 + +autotune优化,结果如下: + +![img](README.assets/wps8587.tmp-16378261403441.jpg) + +优化TransData,TransPose,结果如下: + +![img](README.assets/wps229E.tmp.jpg) + +onnxsim优化onnx,结果如下: + +![img](README.assets/wps4092.tmp.jpg) + +最终经过autotune优化,优化TransData、TransPose,onnxsim优化onnx之后,最终的结果如下: + +![image-20211125154623271](README.assets/image-20211125154623271.png) + +最终的性能为:1000/0.065243*4=1936FPS + + + diff --git a/ACL_PyTorch/contrib/cv/gan/CGAN/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/gan/CGAN/gen_dataset_info.py index 2d8c7b348a6e704d53ac6f36dde91b03a3196234..1669ffd408998c58af8608f95ba2a54feb991ce3 100644 --- a/ACL_PyTorch/contrib/cv/gan/CGAN/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/gan/CGAN/gen_dataset_info.py @@ -1,44 +1,44 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import glob -import argparse - -def parse_args(): - desc = "Pytorch implementation of CGAN collections" - parser = argparse.ArgumentParser(description=desc) - parser.add_argument('--dataset_bin', type=str, default='./prep_dataset', help="The input_dim") - parser.add_argument('--info_name', type=str, default='CGAN_prep_bin.info', help="The output_dim") - parser.add_argument('--width', type=str, default='78', help="The width of input ") - parser.add_argument('--height', type=str, default='100', help="The height of input") - return parser.parse_args() - -def get_bin_info(img_root_path='./data', info_name='CGAN_prep_bin.info', width='72', height='100'): - img_path = [] - files_source = glob.glob(os.path.join(img_root_path,'*.bin')) - files_source.sort() - for file in files_source: - if file.endswith('.bin'): - imgpath = file - img_path.append(imgpath) - with open(info_name, 'w') as fp: - for index in range(len(img_path)): - content = ' '.join([str(index), img_path[index], width, height]) - fp.write(content) - fp.write('\n') - - -if __name__ == '__main__': - args = parse_args() - get_bin_info(img_root_path=args.dataset_bin, info_name=args.info_name, width=args.width, height=args.height) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import glob +import argparse + +def parse_args(): + desc = "Pytorch implementation of CGAN collections" + parser = argparse.ArgumentParser(description=desc) + parser.add_argument('--dataset_bin', type=str, default='./prep_dataset', help="The input_dim") + parser.add_argument('--info_name', type=str, default='CGAN_prep_bin.info', help="The output_dim") + parser.add_argument('--width', type=str, default='78', help="The width of input ") + parser.add_argument('--height', type=str, default='100', help="The height of input") + return parser.parse_args() + +def get_bin_info(img_root_path='./data', info_name='CGAN_prep_bin.info', width='72', height='100'): + img_path = [] + files_source = glob.glob(os.path.join(img_root_path,'*.bin')) + files_source.sort() + for file in files_source: + if file.endswith('.bin'): + imgpath = file + img_path.append(imgpath) + with open(info_name, 'w') as fp: + for index in range(len(img_path)): + content = ' '.join([str(index), img_path[index], width, height]) + fp.write(content) + fp.write('\n') + + +if __name__ == '__main__': + args = parse_args() + get_bin_info(img_root_path=args.dataset_bin, info_name=args.info_name, width=args.width, height=args.height) diff --git a/ACL_PyTorch/contrib/cv/gan/CGAN/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/gan/CGAN/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/ACL_PyTorch/contrib/cv/gan/CGAN/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/gan/CGAN/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/CGAN/test/parse.py b/ACL_PyTorch/contrib/cv/gan/CGAN/test/parse.py index c015e8771f60afd68ab3bb62d130ea9b59b75d59..94857ecd74da1f19b5a4c67d8271e8d37e07c607 100644 --- a/ACL_PyTorch/contrib/cv/gan/CGAN/test/parse.py +++ b/ACL_PyTorch/contrib/cv/gan/CGAN/test/parse.py @@ -1,39 +1,39 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import sys -import re - -def get_acc(filename): - with open(filename, 'r') as f: - lines = f.readlines() - last_line = lines[-1] - psnr = last_line.split(" ")[2] - print(filename.split('.')[0],"Average PSNR:", psnr) - - -def get_perf(filename): - with open(filename, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = 1000/float((txt_data_list[2].split(' '))[0]) * 4 - print('310 fps:{}'.format(fps)) - -if __name__ == "__main__": - - filename = sys.argv[1] - - if filename.endswith(".log"): - get_acc(filename) - elif filename.endswith(".txt"): +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +import re + +def get_acc(filename): + with open(filename, 'r') as f: + lines = f.readlines() + last_line = lines[-1] + psnr = last_line.split(" ")[2] + print(filename.split('.')[0],"Average PSNR:", psnr) + + +def get_perf(filename): + with open(filename, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = 1000/float((txt_data_list[2].split(' '))[0]) * 4 + print('310 fps:{}'.format(fps)) + +if __name__ == "__main__": + + filename = sys.argv[1] + + if filename.endswith(".log"): + get_acc(filename) + elif filename.endswith(".txt"): get_perf(filename) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/CycleGAN/CycleGAN_NetLoad.py b/ACL_PyTorch/contrib/cv/gan/CycleGAN/CycleGAN_NetLoad.py index 958711ae985c3fd8440cbdb474786215b9544f44..f559cbf24021a3900a0cade6a63ce3ffbd2fce64 100644 --- a/ACL_PyTorch/contrib/cv/gan/CycleGAN/CycleGAN_NetLoad.py +++ b/ACL_PyTorch/contrib/cv/gan/CycleGAN/CycleGAN_NetLoad.py @@ -1,90 +1,90 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -from collections import OrderedDict -import torch -from models import networks_adapt as networks - - -class load_networks(): - def __init__(self, opt): - self.opt = opt - self.gpu = 0 - self.netG_A = networks.define_G(self.opt.input_nc, self.opt.output_nc, self.opt.ngf, self.opt.netG, - self.opt.norm, not self.opt.no_dropout, self.opt.init_type, self.opt.init_gain, - self.gpu) - self.netG_B = networks.define_G(self.opt.output_nc, self.opt.input_nc, self.opt.ngf, self.opt.netG, - self.opt.norm, not self.opt.no_dropout, self.opt.init_type, self.opt.init_gain, - self.gpu) - if (opt.npu == False): - self.device = torch.device('cuda:{}'.format(self.gpu)) - else: - self.device = torch.device("cpu") - - def __patch_instance_norm_state_dict(self, state_dict, module, keys, i=0): - """Fix InstanceNorm checkpoints incompatibility (prior to 0.4)""" - key = keys[i] - if i + 1 == len(keys): # at the end, pointing to a parameter/buffer - if module.__class__.__name__.startswith('InstanceNorm') and \ - (key == 'running_mean' or key == 'running_var'): - if getattr(module, key) is None: - state_dict.pop('.'.join(keys)) - if module.__class__.__name__.startswith('InstanceNorm') and \ - (key == 'num_batches_tracked'): - state_dict.pop('.'.join(keys)) - else: - self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) - - def proc_nodes_module(self, checkpoint): - new_state_dict = OrderedDict() - for k, v in checkpoint.items(): - if "module." in k: - name = k.replace("module.", "") - else: - name = k - new_state_dict[name] = v - return new_state_dict - - def loadnetworks(self, net, load_path): - state_dict = torch.load(load_path, map_location=torch.device('cpu')) - state_dict = self.proc_nodes_module(state_dict) - if hasattr(state_dict, '_metadata'): - del state_dict._metadata - # patch InstanceNorm checkpoints prior to 0.4 - for key in list(state_dict.keys()): # need to copy keys here because we mutate in loop - self.__patch_instance_norm_state_dict(state_dict, net, key.split('.')) - net.load_state_dict(state_dict) - return net - - def get_networks(self, load_patha, load_pathb): - model_Ga = self.loadnetworks(self.netG_A, load_patha) - model_Gb = self.loadnetworks(self.netG_B, load_pathb) - return model_Ga, model_Gb +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +from collections import OrderedDict +import torch +from models import networks_adapt as networks + + +class load_networks(): + def __init__(self, opt): + self.opt = opt + self.gpu = 0 + self.netG_A = networks.define_G(self.opt.input_nc, self.opt.output_nc, self.opt.ngf, self.opt.netG, + self.opt.norm, not self.opt.no_dropout, self.opt.init_type, self.opt.init_gain, + self.gpu) + self.netG_B = networks.define_G(self.opt.output_nc, self.opt.input_nc, self.opt.ngf, self.opt.netG, + self.opt.norm, not self.opt.no_dropout, self.opt.init_type, self.opt.init_gain, + self.gpu) + if (opt.npu == False): + self.device = torch.device('cuda:{}'.format(self.gpu)) + else: + self.device = torch.device("cpu") + + def __patch_instance_norm_state_dict(self, state_dict, module, keys, i=0): + """Fix InstanceNorm checkpoints incompatibility (prior to 0.4)""" + key = keys[i] + if i + 1 == len(keys): # at the end, pointing to a parameter/buffer + if module.__class__.__name__.startswith('InstanceNorm') and \ + (key == 'running_mean' or key == 'running_var'): + if getattr(module, key) is None: + state_dict.pop('.'.join(keys)) + if module.__class__.__name__.startswith('InstanceNorm') and \ + (key == 'num_batches_tracked'): + state_dict.pop('.'.join(keys)) + else: + self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) + + def proc_nodes_module(self, checkpoint): + new_state_dict = OrderedDict() + for k, v in checkpoint.items(): + if "module." in k: + name = k.replace("module.", "") + else: + name = k + new_state_dict[name] = v + return new_state_dict + + def loadnetworks(self, net, load_path): + state_dict = torch.load(load_path, map_location=torch.device('cpu')) + state_dict = self.proc_nodes_module(state_dict) + if hasattr(state_dict, '_metadata'): + del state_dict._metadata + # patch InstanceNorm checkpoints prior to 0.4 + for key in list(state_dict.keys()): # need to copy keys here because we mutate in loop + self.__patch_instance_norm_state_dict(state_dict, net, key.split('.')) + net.load_state_dict(state_dict) + return net + + def get_networks(self, load_patha, load_pathb): + model_Ga = self.loadnetworks(self.netG_A, load_patha) + model_Gb = self.loadnetworks(self.netG_B, load_pathb) + return model_Ga, model_Gb diff --git a/ACL_PyTorch/contrib/cv/gan/CycleGAN/CycleGAN_ReflectpadDeal.py b/ACL_PyTorch/contrib/cv/gan/CycleGAN/CycleGAN_ReflectpadDeal.py index d5f7cd809cb3a1ced445be92267cad68173bfb98..c39ee6239298d3e01934d7f6dc9d0e3b1ca6b2c0 100644 --- a/ACL_PyTorch/contrib/cv/gan/CycleGAN/CycleGAN_ReflectpadDeal.py +++ b/ACL_PyTorch/contrib/cv/gan/CycleGAN/CycleGAN_ReflectpadDeal.py @@ -1,66 +1,66 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import onnx -from parse import parse_args - - -def main(): - paser = parse_args(True, True) - opt = paser.initialize() - # Mode attr of Pad only supports constant, current is reflect ." - model = onnx.load(opt.onnx_path + opt.model_ga_onnx_name) - max_idx = len(model.graph.node) - for i in range(max_idx): - for k in range(len(model.graph.node[i].attribute)): - - if (model.graph.node[i].attribute[k].name == 'mode'): - model.graph.node[i].attribute[k].s = b'constant' - print(model.graph.node[i].attribute[k].s) - - onnx.checker.check_model(model) - onnx.save(model, opt.onnx_path + opt.model_gb_onnx_name) - - model = onnx.load(opt.onnx_path + opt.model_gb_onnx_name) - max_idx = len(model.graph.node) - for i in range(max_idx): - # if(model.graph.node[i].attribute[0].name=='Pad'): - for k in range(len(model.graph.node[i].attribute)): - - if (model.graph.node[i].attribute[k].name == 'mode'): - model.graph.node[i].attribute[k].s = b'constant' - print(model.graph.node[i].attribute[k].s) - onnx.checker.check_model(model) - onnx.save(model, opt.onnx_path + opt.model_ga_onnx_name) - - -if __name__ == '__main__': - main() +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import onnx +from parse import parse_args + + +def main(): + paser = parse_args(True, True) + opt = paser.initialize() + # Mode attr of Pad only supports constant, current is reflect ." + model = onnx.load(opt.onnx_path + opt.model_ga_onnx_name) + max_idx = len(model.graph.node) + for i in range(max_idx): + for k in range(len(model.graph.node[i].attribute)): + + if (model.graph.node[i].attribute[k].name == 'mode'): + model.graph.node[i].attribute[k].s = b'constant' + print(model.graph.node[i].attribute[k].s) + + onnx.checker.check_model(model) + onnx.save(model, opt.onnx_path + opt.model_gb_onnx_name) + + model = onnx.load(opt.onnx_path + opt.model_gb_onnx_name) + max_idx = len(model.graph.node) + for i in range(max_idx): + # if(model.graph.node[i].attribute[0].name=='Pad'): + for k in range(len(model.graph.node[i].attribute)): + + if (model.graph.node[i].attribute[k].name == 'mode'): + model.graph.node[i].attribute[k].s = b'constant' + print(model.graph.node[i].attribute[k].s) + onnx.checker.check_model(model) + onnx.save(model, opt.onnx_path + opt.model_ga_onnx_name) + + +if __name__ == '__main__': + main() diff --git a/ACL_PyTorch/contrib/cv/gan/CycleGAN/CycleGAN_onnx_export.py b/ACL_PyTorch/contrib/cv/gan/CycleGAN/CycleGAN_onnx_export.py index f6d3207e1ea99f0a19c72fe29d7509ea22d9f54e..d2faf855278b0d08b8f3aa755b14e5a6f3feb4b6 100644 --- a/ACL_PyTorch/contrib/cv/gan/CycleGAN/CycleGAN_onnx_export.py +++ b/ACL_PyTorch/contrib/cv/gan/CycleGAN/CycleGAN_onnx_export.py @@ -1,62 +1,62 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import os -import torch.onnx -from CycleGAN_NetLoad import load_networks -from parse import parse_args - -def main(): - paser = parse_args(True, True) - opt = paser.initialize() - lnetworks = load_networks(opt) - model_Ga, model_Gb = lnetworks.get_networks(opt.model_ga_path, opt.model_gb_path) - device_cpu = torch.device("cpu") - model_Ga = model_Ga.to(device_cpu) - model_Gb = model_Gb.to(device_cpu) - dummy_input = torch.randn(1, 3, 256, 256) - input_names = ["img_sat_maps"] - output_names = ["maps"] - dynamic_axes = {'img_sat_maps': {0: '-1'}, 'maps': {0: '-1'}} - input_names1 = ["img_maps_sat"] - output_names1 = ["sat"] - dynamic_axes1 = {'img_maps_sat': {0: '-1'}, 'sat': {0: '-1'}} - if (os.path.exists(opt.onnx_path) == False): - os.makedirs(opt.onnx_path) - torch.onnx.export(model_Ga, dummy_input, f=opt.onnx_path + opt.model_ga_onnx_name, verbose=True, training=False, \ - dynamic_axes=dynamic_axes, input_names=input_names, output_names=output_names, opset_version=11) - torch.onnx.export(model_Gb, dummy_input, f=opt.onnx_path + opt.model_gb_onnx_name, verbose=True, training=False, \ - dynamic_axes=dynamic_axes1, input_names=input_names1, output_names=output_names1, - opset_version=11) - - -if __name__ == '__main__': - main() +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import os +import torch.onnx +from CycleGAN_NetLoad import load_networks +from parse import parse_args + +def main(): + paser = parse_args(True, True) + opt = paser.initialize() + lnetworks = load_networks(opt) + model_Ga, model_Gb = lnetworks.get_networks(opt.model_ga_path, opt.model_gb_path) + device_cpu = torch.device("cpu") + model_Ga = model_Ga.to(device_cpu) + model_Gb = model_Gb.to(device_cpu) + dummy_input = torch.randn(1, 3, 256, 256) + input_names = ["img_sat_maps"] + output_names = ["maps"] + dynamic_axes = {'img_sat_maps': {0: '-1'}, 'maps': {0: '-1'}} + input_names1 = ["img_maps_sat"] + output_names1 = ["sat"] + dynamic_axes1 = {'img_maps_sat': {0: '-1'}, 'sat': {0: '-1'}} + if (os.path.exists(opt.onnx_path) == False): + os.makedirs(opt.onnx_path) + torch.onnx.export(model_Ga, dummy_input, f=opt.onnx_path + opt.model_ga_onnx_name, verbose=True, training=False, \ + dynamic_axes=dynamic_axes, input_names=input_names, output_names=output_names, opset_version=11) + torch.onnx.export(model_Gb, dummy_input, f=opt.onnx_path + opt.model_gb_onnx_name, verbose=True, training=False, \ + dynamic_axes=dynamic_axes1, input_names=input_names1, output_names=output_names1, + opset_version=11) + + +if __name__ == '__main__': + main() diff --git a/ACL_PyTorch/contrib/cv/gan/CycleGAN/LICENSE b/ACL_PyTorch/contrib/cv/gan/CycleGAN/LICENSE index 4e1ad12a819e98036586f198d3873933f1892331..eb1309d6c1e79cfb4dad830ae04bfca945f5568e 100644 --- a/ACL_PyTorch/contrib/cv/gan/CycleGAN/LICENSE +++ b/ACL_PyTorch/contrib/cv/gan/CycleGAN/LICENSE @@ -1,31 +1,31 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ============================================================================ \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/CycleGAN/PerformanceForGPU.py b/ACL_PyTorch/contrib/cv/gan/CycleGAN/PerformanceForGPU.py index a397087a14fe47a4ab3836069cef2e062b46521a..3e68d420e79a2ef3a7037c32cb536fb46dbdbf9b 100644 --- a/ACL_PyTorch/contrib/cv/gan/CycleGAN/PerformanceForGPU.py +++ b/ACL_PyTorch/contrib/cv/gan/CycleGAN/PerformanceForGPU.py @@ -1,173 +1,173 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import os -import time -import torchvision.transforms as transforms -from PIL import Image -import torch.onnx -from torch.utils.data import Dataset -from torchvision.datasets.folder import IMG_EXTENSIONS -from parse import parse_args -import numpy as np -from CycleGAN_NetLoad import load_networks - - -def make_power(img, base): - ow, oh = img.size - h = int(round(oh / base) * base) - w = int(round(ow / base) * base) - if h == oh and w == ow: - return img - - -def preprocess(image_shape): - process = transforms.Compose([ - transforms.Lambda(lambda img: make_power(img, base=4)), - transforms.Resize(image_shape), - transforms.ToTensor(), - transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))]) - return process - - -def postprocess(img_tensor): - inv_normalize = transforms.Normalize( - mean=(-1, -1, -1), - std=(2.0, 2.0, 2.0)) - to_PIL_image = transforms.ToPILImage() - return to_PIL_image(inv_normalize(img_tensor[0]).clamp(0, 1)) - - -def make_dataset(dir, max_dataset_size=float("inf")): - images = [] - assert os.path.isdir(dir), '%s is not a valid directory' % dir - - for root, _, fnames in sorted(os.walk(dir)): - for fname in fnames: - path = os.path.join(root, fname) - images.append(path) - return images[:min(max_dataset_size, len(images))] - - -def default_loader(path): - return Image.open(path).convert('RGB') - - -class ImageFolder(Dataset): - def __init__(self, root, transform=None, return_paths=False, - loader=default_loader): - imgs = make_dataset(root) - if len(imgs) == 0: - raise (RuntimeError("Found 0 images in: " + root + "\n" + - "Supported image extensions are: " + ",".join(IMG_EXTENSIONS))) - self.root = root - self.imgs = imgs - self.transform = transform - self.return_paths = return_paths - self.loader = loader - - def __getitem__(self, index): - path = self.imgs[index] - img = self.loader(path) - if self.transform is not None: - img = self.transform(img) - if self.return_paths: - return img, path - else: - return img - - def __len__(self): - return len(self.imgs) - - -def main(): - paser = parse_args(True, True) - opt = paser.initialize() - lnetworks = load_networks(opt) - bachsize = opt.batch_size - # whether to use fp16 to farword - half_data_model = True - transform = preprocess((256, 256)) - model_Ga, model_Gb = lnetworks.get_networks(opt.model_ga_path, opt.model_gb_path) - device_cuda = torch.device("cuda:%s" % (str(opt.pu_ids))) - model_Ga = model_Ga.to(device_cuda) - if (half_data_model): - model_Ga = model_Ga.half() - datasets = ImageFolder(opt.dataroot, transform) - dataloader = torch.utils.data.DataLoader(datasets, batch_size=bachsize, shuffle=True, num_workers=4) - filename = opt.gpuPerformance + 'GPU_perf_of_cycle_gan-b0_bs' + str(bachsize) + '_in_device_' + str( - opt.pu_ids) + '.txt' - f = None - if (os.path.exists(opt.gpuPerformance) == False): - os.mkdir(opt.gpuPerformance) - f = open(filename, mode='w') - else: - f = open(filename, mode='w') - timelist = [] - for i, data in enumerate(dataloader): - start_time = time.time() - data = data.to(device_cuda) - if (half_data_model): - data = data.half() - model_Ga.forward(data) - end_time = time.time() - if (i > 10): - timelist.append((end_time - start_time) * 1000) - a_time = time.asctime(time.localtime(time.time())) - timelist = np.array(timelist) - mintime = timelist.argmin() - maxtime = timelist.argmax() - meantime = np.mean(timelist) - mediantime = np.median(timelist) - alltime = np.sum(timelist) / 1000 - message = ''' - [%s],[I] GPU Compute - [%s],[I] min:%.5f ms - [%s],[I] max:%.5f ms - [%s],[I] mean:%.5f ms - [%s],[I] median:%.5f ms - [%s],[I] total compute time:%.5f s - [%s],[I] CardFPS:1000/(%f/%f)=%.2f fps - ''' % (a_time, \ - a_time, mintime, \ - a_time, maxtime, \ - a_time, meantime, \ - a_time, mediantime, \ - a_time, alltime, \ - a_time, meantime, bachsize, 1000 / (meantime / bachsize)) - - print(message) - f.write(message) - f.close() - - -if __name__ == '__main__': - main() +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import os +import time +import torchvision.transforms as transforms +from PIL import Image +import torch.onnx +from torch.utils.data import Dataset +from torchvision.datasets.folder import IMG_EXTENSIONS +from parse import parse_args +import numpy as np +from CycleGAN_NetLoad import load_networks + + +def make_power(img, base): + ow, oh = img.size + h = int(round(oh / base) * base) + w = int(round(ow / base) * base) + if h == oh and w == ow: + return img + + +def preprocess(image_shape): + process = transforms.Compose([ + transforms.Lambda(lambda img: make_power(img, base=4)), + transforms.Resize(image_shape), + transforms.ToTensor(), + transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))]) + return process + + +def postprocess(img_tensor): + inv_normalize = transforms.Normalize( + mean=(-1, -1, -1), + std=(2.0, 2.0, 2.0)) + to_PIL_image = transforms.ToPILImage() + return to_PIL_image(inv_normalize(img_tensor[0]).clamp(0, 1)) + + +def make_dataset(dir, max_dataset_size=float("inf")): + images = [] + assert os.path.isdir(dir), '%s is not a valid directory' % dir + + for root, _, fnames in sorted(os.walk(dir)): + for fname in fnames: + path = os.path.join(root, fname) + images.append(path) + return images[:min(max_dataset_size, len(images))] + + +def default_loader(path): + return Image.open(path).convert('RGB') + + +class ImageFolder(Dataset): + def __init__(self, root, transform=None, return_paths=False, + loader=default_loader): + imgs = make_dataset(root) + if len(imgs) == 0: + raise (RuntimeError("Found 0 images in: " + root + "\n" + + "Supported image extensions are: " + ",".join(IMG_EXTENSIONS))) + self.root = root + self.imgs = imgs + self.transform = transform + self.return_paths = return_paths + self.loader = loader + + def __getitem__(self, index): + path = self.imgs[index] + img = self.loader(path) + if self.transform is not None: + img = self.transform(img) + if self.return_paths: + return img, path + else: + return img + + def __len__(self): + return len(self.imgs) + + +def main(): + paser = parse_args(True, True) + opt = paser.initialize() + lnetworks = load_networks(opt) + bachsize = opt.batch_size + # whether to use fp16 to farword + half_data_model = True + transform = preprocess((256, 256)) + model_Ga, model_Gb = lnetworks.get_networks(opt.model_ga_path, opt.model_gb_path) + device_cuda = torch.device("cuda:%s" % (str(opt.pu_ids))) + model_Ga = model_Ga.to(device_cuda) + if (half_data_model): + model_Ga = model_Ga.half() + datasets = ImageFolder(opt.dataroot, transform) + dataloader = torch.utils.data.DataLoader(datasets, batch_size=bachsize, shuffle=True, num_workers=4) + filename = opt.gpuPerformance + 'GPU_perf_of_cycle_gan-b0_bs' + str(bachsize) + '_in_device_' + str( + opt.pu_ids) + '.txt' + f = None + if (os.path.exists(opt.gpuPerformance) == False): + os.mkdir(opt.gpuPerformance) + f = open(filename, mode='w') + else: + f = open(filename, mode='w') + timelist = [] + for i, data in enumerate(dataloader): + start_time = time.time() + data = data.to(device_cuda) + if (half_data_model): + data = data.half() + model_Ga.forward(data) + end_time = time.time() + if (i > 10): + timelist.append((end_time - start_time) * 1000) + a_time = time.asctime(time.localtime(time.time())) + timelist = np.array(timelist) + mintime = timelist.argmin() + maxtime = timelist.argmax() + meantime = np.mean(timelist) + mediantime = np.median(timelist) + alltime = np.sum(timelist) / 1000 + message = ''' + [%s],[I] GPU Compute + [%s],[I] min:%.5f ms + [%s],[I] max:%.5f ms + [%s],[I] mean:%.5f ms + [%s],[I] median:%.5f ms + [%s],[I] total compute time:%.5f s + [%s],[I] CardFPS:1000/(%f/%f)=%.2f fps + ''' % (a_time, \ + a_time, mintime, \ + a_time, maxtime, \ + a_time, meantime, \ + a_time, mediantime, \ + a_time, alltime, \ + a_time, meantime, bachsize, 1000 / (meantime / bachsize)) + + print(message) + f.write(message) + f.close() + + +if __name__ == '__main__': + main() diff --git a/ACL_PyTorch/contrib/cv/gan/CycleGAN/Readme.md b/ACL_PyTorch/contrib/cv/gan/CycleGAN/Readme.md index eb51b624e3540f9840f24e876cd568b48c1ae295..8b8ea739ba971eee5560ecc07cd59a1b21522167 100644 --- a/ACL_PyTorch/contrib/cv/gan/CycleGAN/Readme.md +++ b/ACL_PyTorch/contrib/cv/gan/CycleGAN/Readme.md @@ -1,619 +1,619 @@ -\# CycleGAN模型端到端推理指导 - -\- [1 模型概述](#1-模型概述) - -​ \- [1.1 论文地址](#11-论文地址) - -​ \- [1.2 代码地址](#12-代码地址) - -\- [2 环境说明](#2-环境说明) - -​ \- [2.1 深度学习框架](#21-深度学习框架) - -​ \- [2.2 python第三方库](#22-python第三方库) - -\- [3 模型转换](#3-模型转换) - -​ \- [3.1 pth转onnx模型](#31-pth转onnx模型) - -​ \- [3.2 onnx转om模型](#32-onnx转om模型) - -\- [4 数据集预处理](#4-数据集预处理) - -​ \- [4.1 数据集获取](#41-数据集获取) - -​ \- [4.2 数据集预处理](#42-数据集预处理) - -​ \- [4.3 生成数据集信息文件](#43-生成数据集信息文件) - -\- [5 离线推理](#5-离线推理) - -​ \- [5.1 benchmark工具概述](#51-benchmark工具概述) - -​ \- [5.2 离线推理](#52-离线推理) - -\- [6 精度对比](#6-精度对比) - -​ \- [6.1 离线推理精度统计](#61-离线推理精度统计) - -​ \- [6.2 在线推理精度](#62-在线推理精度) - -​ \- [6.3 精度对比](#63-精度对比) - -\- [7 性能对比](#7-性能对比) - -​ \- [7.1 npu性能数据](#71-npu性能数据) - -​ \- [7.2 性能优化](#73-性能优化) - -​ \- [7.2.1 优化TransData,修改five_2_four.py](#731-优化TransData,修改five_2_four.py) - -\## 1 模型概述 - - - -\- **[论文地址](#11-论文地址)** - - - -\- **[代码地址](#12-代码地址)** - - - -\### 1.1 论文地址 - - - -[CycleGAN论文]( https://arxiv.org/pdf/1703.10593v7.pdf) - -我们专注于本文中风格转换中的地图转换。它通过一种无监督的少样本的学习方式,能够实现航拍地图和卫星地图之间的相互转换。 - -\### 1.2 代码地址 - -[CycleGAN代码]( https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix) - -branch:master - -commit_id:略 - -备注:commit_id是指基于该次提交时的模型代码做推理,通常选择稳定版本的最后一次提交,或代码仓最新的一次提交 - - - -\## 2 环境说明 - - - -\- **[深度学习框架](#21-深度学习框架)** - - - -\- **[python第三方库](#22-python第三方库)** - - - -\### 2.1 深度学习框架 - -\``` - -``` -CANN 5.0.2.alpha003 - -torch == 1.5.0 - -torchvision == 0.9.0 - -onnx==1.7.0 - -onnx-simplifier==0.3.6 - -onnxconverter-common==1.6.1 - -onnxoptimizer==0.2.6 - -onnxruntime==1.6.0 - -tensorboard==1.15.0 - -tensorflow==1.15.0 - -tensorflow-estimator ==1.15.1 - -termcolor==1.1.0 -``` - -\``` - - - -\### 2.2 python第三方库 - -\``` - -``` -numpy == 1.16.6 - -Pillow == 8.2.0 - -opencv-python == 4.5.2.52 - -sympy == 1.4 - -decorator == 4.4.2 - -requests == 2.22.0 - -tqdm == 4.61.0 - -PyYAML == 5.4.1 -``` - -\``` - - - -**说明:** - -\> X86架构:pytorch torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3 install 包名 安装 - -\> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3 install 包名 安装 - - - -\## 3 模型转换 - - - -\- **[pth转onnx模型](#31-pth转onnx模型)** - - - -\- **[onnx转om模型](#32-onnx转om模型)** - - - -\### 3.1 pth转onnx模型 - -1.下载开源模型代码,安装必要的依赖库,并修改模型代码后安装 - -\``` - -``` -git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix -cd pytorch-CycleGAN-and-pix2pix -pip3 install -r requirements.txt -``` - -\``` - - - -2.下载pth权重文件 - - - -\- [官方CycleGAN pth权重文件](http://efrosgans.eecs.berkeley.edu/cyclegan/pretrained_models/) - -\- [获取A800-9000训练的pth文件,该链接为百度网盘链接,提取码为:1234](https://pan.baidu.com/s/1YqHkce2wUw-W8_VY9dYD_w)) - -3.编写pth2onnx脚本*CycleGAN_onnx_export.py* - - **说明:** - -\>注意目前ATC支持的onnx算子版本为11 - - - -4.执行*CycleGAN_onnx_export.py*脚本,生成onnx模型文件 - -\``` - -``` -python3 CycleGAN_onnx_export.py \ - ---model_ga_path=./checkpoints/maps_cycle_gan/latest_net_G_A.pth\ - ---model_gb_path=./checkpoints/maps_cycle_gan/latest_net_G_B.pth\ - ---onnx_path=./onnxmodel/ \ - ---model_ga_onnx_name=model_Ga.onnx \ - ---model_gb_onnx_name=model_Gb.onnx \ -``` - -\``` - - **模型转换要点:** - -\- 开源仓中的生成器采用的padding类型为ReflectionPad2d,由于在转om格式模型的时候,会出现算子不兼容问题导致om模型转换失败,这里我们将改padding类型替换为ZeroPad2d。如果您任然坚持使用ReflectionPad2d,请在转换Onnx格式后运行 - - ' ' ' - -``` -python3 CycleGAN_ReflectpadDeal.py \ - ---onnx_path=./onnxmodel/ \ - ---model_ga_onnx_name=model_Ga.onnx \ - ---model_gb_onnx_name=model_Gb.onnx \ -``` - -' ' ' - -该脚本会将ReflectionPad2d中的属性替换为constant,这样做的结果会导致模型执行推理时会出现边缘模糊,详情请见issue链接https://e.gitee.com/HUAWEI-ASCEND/issues/list?issue=I4467L#note_6141945 - - - -\### 3.2 onnx转om模型 - - - -1.设置环境变量 - -\``` - -``` -source env.sh -``` - -\``` - -\- 根据实际情况修改env.sh中的install_path=/usr/local/Ascend/ascend-toolkit/latest变量 - -\- 执行脚本前先执行指令 dos2unix * - - - -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN 5.0.1 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) - -\``` - -``` -atc --framework=5 --model=./onnxmodel/model_Ga.onnx --output=Cons_Ga_aipp512_b0_bs1 --input_format=NCHW --input_shape="img_sat_maps:1,3,256,256" --out_nodes="Tanh_156:0" --log=debug --soc_version=Ascend310 --insert_op_conf=aipp_CycleGAN_pth.config - -atc --framework=5 --model=./onnxmodel/model_Gb.onnx --output=Cons_Gb_aipp512_b0_bs1 --input_format=NCHW --input_shape="img_maps_sat:1,3,256,256" --out_nodes="Tanh_156:0" --log=debug --soc_version=Ascend310 --insert_op_conf=aipp_CycleGAN_pth.config -``` - -\``` - -\- 说明 - - \- input_shape参数可通过Netron工具查看输入节点的名称和shape, 与pth转onnx步骤中的参数一致 - - \- out_nodes为指定输出节点, 通过Netron可以看到onnx文件有四个输出, 以自测转换的onnx为例 - - 如果在转onnx时使用的不是默认路径,请将—model中的参数设置为onnx格式模型所在的路径 - - - - - -\## 4 数据集预处理 - - - -\- **[数据集获取](#41-数据集获取)** - - - -\- **[数据集预处理](#42-数据集预处理)** - - - -\- **[生成数据集信息文件](#43-生成数据集信息文件)** - - - -\### 4.1 数据集获取 - -该模型使用[maps数据集](http://efrosgans.eecs.berkeley.edu/cyclegan/datasets/maps.zip)的testA和testB各1098张验证集进行测试,因为航拍地图和卫星地图之间的相互转换的两个生成器模型结构一样,这里我们只需要保证其中一个生辰器精度和性能跟上就行,这里我们以model_Ga.onnx和testA为推理的模型和测试数据集。 - - - -\### 4.2 数据集预处理 - -1.生成数据集信息文件脚本gen_dataset_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 - -\``` - -``` -python3 gen_dataset_info.py \ - ---src_path_testA=./datasets/maps/testA/ \ - ---save_pathTestA_dst=datasetsDst/maps/testA/ \ - ---dataTestA_infoName=testA_prep.info \ - ---src_path_testB=./datasets/maps/testB/ \ - ---save_pathTestB_dst=./datasetsDst/maps/testB/ \ - ---dataTestB_infoName=testB_prep.info -``` - -' ' ' - -\## 5 离线推理 - - - -\- **[benchmark工具概述](#51-benchmark工具概述)** - - - -\- **[离线推理](#52-离线推理)** - - - -\### 5.1 benchmark工具概述 - - - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN 5.0.1 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) - -\### 5.2 离线推理 - -1.设置环境变量 - -\``` - -source env.sh - -\``` - -2.执行离线推理 - -\- benchmark工具区分arm64和x86_64, 对应分别为./benchmark.aarch64和./benchmark.x86_64, 示例中均以x86_64环境为例 - -\- 将benchmark工具去相应路径获取后放到env.sh同级目录下,加上执行权限chmod +x benchmark.XX - -''' - -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=Cons_Ga_aipp512_b0_bs1.om -input_text_path=testA_prep.info -input_width=512 -input_height=512 -output_binary=true -useDvpp=true - -./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=1 -om_path=Cons_Gb_aipp512_b0_bs1.om -input_text_path=testB_prep.info -input_width=512 -input_height=512 -output_binary=true -useDvpp=true -``` - -输出结果默认保存在当前目录result/dumpOutput_devicex,每个输入对应的输出对应一个_x.bin文件。 - -''' - -\## 6 精度对比 - -\### 6.1 离线推理精度统计 - -由于该模型的精度在论文中是由人眼分辨,所以这里我们那Onnx和om模型输出的平均余弦相似度来替代精度,只需要保证Onnx格式模型的效果和论文中的一致并且om和onnx格式模型的余弦相似度在99%左右就精度达标。执行eval_acc_py.py脚本计算平均余弦相似度 : - -\``` - -``` - -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=Cons_Ga_aipp512_b0_bs1.om -input_text_path=testA_prep.info -input_width=512 -input_height=512 -output_binary=true -useDvpp=true #如果已经执行这一步请忽略 -python3 eval_acc.py \ ---dataroot=./datasets/maps\ ---npu_bin_file=./result/dumpOutput_device0/ -``` - -\``` - -\### 6.2精度对比 - -![1](C:\Users\Administrator\Desktop\1.png) - -将得到的om离线模型推理精度与在线推理精度对比,推理精度与在线推理精度一致,精度达标。 - - **精度调试:** - -使用onnxruntime测试onnx离线推理精度与om一致。 - -\## 7 性能对比 - -\- **[npu性能数据](#71-npu性能数据)** - -\- **[性能优化](#73-性能优化)** - -\### 7.1 npu性能数据 - -这里用batch1和batch16做示例 - - - -benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device。为快速获取性能数据,也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准。这里给出两种方式,模型的测试脚本使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准。 - - - -1.benchmark工具在整个数据集上推理获得性能数据 - - - -以batch1为例,benchmark工具在整个数据集上推理,执行下面命令。 - -``` -atc --framework=5 --model=./onnxmodel/model_Ga.onnx --output=Cons_Ga_aipp512_b0_bs1 --input_format=NCHW --input_shape="img_sat_maps:1,3,256,256" --out_nodes="Tanh_156:0" --log=debug --soc_version=Ascend310 --insert_op_conf=aipp_CycleGAN_pth.config #如果已经转换,请忽略 -python3.7 gen_dataset_info.py #如果这一步已经执行,可直接执行下一步推理 -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=Cons_Ga_aipp512_b0_bs1.om -input_text_path=testA_prep.info -input_width=512 -input_height=512 -output_binary=true -useDvpp=true -``` - -\``` - - ![输入图片说明](https://images.gitee.com/uploads/images/2021/0914/121624_f45173ef_9486012.png "屏幕截图.png") - - - -Interface throughputRate: 10.7,10.7乘以4,是310单卡吞吐率 - - \``` - -2.benchmark纯推理功能测得性能数据 - - - -batch1的性能: - - 测试npu性能要确保device空闲,使用npu-smi info命令可查看device是否在运行其它推理任务 - -\``` - -``` -./benchmark.x86_64 -round=20 -om_path=Cons_Ga_aipp512_b0_bs1.om -device_id=0 -batch_size=1 -``` - -``` - -执行20次纯推理取均值,统计吞吐率与其倒数时延(benchmark的时延是单个数据的推理时间),npu性能是一个device执行的结果 - - ![输入图片说明](https://images.gitee.com/uploads/images/2021/0914/121641_4ed82b8d_9486012.png "屏幕截图.png") -``` - - -Batch16的性能: - -``` -./benchmark.x86_64 -round=20 -om_path=model_Ga-b0_bs16.om -device_id=1 -batch_size=16 -``` - -![输入图片说明](https://images.gitee.com/uploads/images/2021/0914/121659_6331aa3d_9486012.png "屏幕截图.png") - -\### 7.2 性能优化 - -``` -**性能优化** - -\- profiling性能分析方法 - -​ CANN C20及以后的版本profiling使用方法 - -新建/home/zlz/CycleGan_deal/perProblem_detec/run文件,内容如下: - -``` -``` -# /usr/local/Ascend/ascend-toolkit/ /usr/local/Ascend/ascend-toolkit/ -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -./benchmark.x86_64 -round=20 -om_path=/home/zlz/cyclegan/model_Ga1-b0_bs16.om -device_id=0 -batch_size=16 -``` - -然后执行如下命令: -``` -chmod 777 /home/zlz/CycleGan_deal/perProblem_detec/run -cd /usr/local/Ascend/ascend-toolkit/latest/x86_64-linux/toolkit/tools/profiler/bin -./msprof --output=/home/zlz/CycleGan_deal/perProblem_detec/perPro/ --application=/home/zlz/CycleGan_deal/perProblem_detec/run --sys-hardware-mem=on --sys-cpu-profiling=on --sys-profiling=on --sys-pid-profiling=on --sys-io-profiling=on --dvpp-profiling=on -cd /usr/local/Ascend/ascend-toolkit/latest/x86_64-linux/toolkit/tools/profiler/profiler_tool/analysis/msprof/ -# 生成的profiling目录 -python3.7 msprof.py import -dir/home/zlz/CycleGan_deal/perProblem_detec/perPro/ -python3.7 msprof.py export summary -dir /home/zlz/CycleGan_deal/perProblem_detec/perPro/ -#生成的profiling目录 --iteration-id 1 -python3.7 msprof.py export timeline -dir /home/zlz/CycleGan_deal/perProblem_detec/perPro/ - -``` -目录 - -\- 性能调优测试版本:CANN 5.0.2.alpha003 - -\- 性能优化过程主要对trans_Data算子进行优化,结合profiling分析,性能有提升: - -\#### 7.3.1 five_2_four.py优化方法 - - 在环境变量env.sh中export install_path=/usr/local/Ascend/ascend-toolkit/latest路径下查找five_2_four.py文件,路径一般为 - -\``` - -/usr/local/Ascend/ascend-toolkit/latest/x86_64-linux/opp/op_impl/built-in/ai_core/tbe/impl/five_2_four.py - -\``` - -修改five_2_four.py文件,将TransData算子的output shape加入five_2_four函数行中,示例如下: - -\``` - - ... - from impl import trans_data_negative_target_ntc - - @util.check_input_type(dict, dict, str, str, str) - - def five_2_four(src, dst, src_format, dst_format, kernel_name='five_2_four'): - elif dst_format.lower() == "nhwc" and dst_shape in [[10000, 63, 63, 1], [10000, 127, 127, 1], [16, 19, 19, 486], - - [16, 10, 10, 486], [16, 38, 38, 324], [16, 5, 5, 486], - - [16, 3, 3, 324], [8, 19, 19, 486], [8, 10, 10, 486], - - [8, 38, 38, 324], [8, 5, 5, 486], [8, 3, 3, 324], - - [100, 28, 28, 91]]: - - trans_data_negative_target_tc.trans_data_negative_target_tc(src, dst, src_format, dst_format, kernel_name) - - elif dst_format.lower() == "nchw" and dst_shape in [[2560, 512, 4, 26], [2560, 512, 1, 26], [2560, 256, 8, 25], - - [16, 240, 7, 7], [16, 120, 14, 14], [1,19,1024,2048], [4,19,1024,2048]]: - - print("=================================") - - print("ntc dst shape:", dst_shape) - - print("=================================") - - trans_data_negative_target_ntc.trans_data_negative_target_ntc(src, dst, src_format, dst_format, kernel_name) - ... - -\``` - -\- 不同的batch_size,添加的shape不一样,shape大小为[*,19,256,256 ] ,以本模型为例,只测试batch1和batch16,因此添加的shape为[1,19,256,256],[4,19,256,256] - -修改完成后,重新转换生成om文件,atc转换过程会打印添加的日志,如下: - -\```![输入图片说明](https://images.gitee.com/uploads/images/2021/0914/121715_d94592ad_9486012.png "屏幕截图.png") - - \``` - -纯推理测试结果: - -\``` - -bs1: - - ![输入图片说明](https://images.gitee.com/uploads/images/2021/0914/121721_50c95bdd_9486012.png "屏幕截图.png") - -Bs16: - -![输入图片说明](https://images.gitee.com/uploads/images/2021/0914/122022_a16e9ff5_9486012.png "屏幕截图.png") - -\``` - - - -用生成的om文件做精度后处理,测得bs1和bs16与之前的Onnx模型做余弦相似度高于99%,精度无损失、 - -\``` - -\#### 7.3.1 总结 - -优化方案共包括五种: - -(1)优化TransData,修改five_2_four.py - -(2)输出节点由float32改为float16 - -(3)模型中Resize节点的mode由双线性为最近邻 - -(4)将PadV3D进行算子融合 - -(5)优化FrameworkOP框架 - -由于在蓝区测试的版本CANN 5.0.2.alpha003中,已经实现了PadV3D算子融合,因此测试过程默认已经优化。同时方案(5)暂时无法实现,因此也无法比对性能。 - -结论: - -\- 因为关键算子性能差,性能暂时无法达标。 - +\# CycleGAN模型端到端推理指导 + +\- [1 模型概述](#1-模型概述) + +​ \- [1.1 论文地址](#11-论文地址) + +​ \- [1.2 代码地址](#12-代码地址) + +\- [2 环境说明](#2-环境说明) + +​ \- [2.1 深度学习框架](#21-深度学习框架) + +​ \- [2.2 python第三方库](#22-python第三方库) + +\- [3 模型转换](#3-模型转换) + +​ \- [3.1 pth转onnx模型](#31-pth转onnx模型) + +​ \- [3.2 onnx转om模型](#32-onnx转om模型) + +\- [4 数据集预处理](#4-数据集预处理) + +​ \- [4.1 数据集获取](#41-数据集获取) + +​ \- [4.2 数据集预处理](#42-数据集预处理) + +​ \- [4.3 生成数据集信息文件](#43-生成数据集信息文件) + +\- [5 离线推理](#5-离线推理) + +​ \- [5.1 benchmark工具概述](#51-benchmark工具概述) + +​ \- [5.2 离线推理](#52-离线推理) + +\- [6 精度对比](#6-精度对比) + +​ \- [6.1 离线推理精度统计](#61-离线推理精度统计) + +​ \- [6.2 在线推理精度](#62-在线推理精度) + +​ \- [6.3 精度对比](#63-精度对比) + +\- [7 性能对比](#7-性能对比) + +​ \- [7.1 npu性能数据](#71-npu性能数据) + +​ \- [7.2 性能优化](#73-性能优化) + +​ \- [7.2.1 优化TransData,修改five_2_four.py](#731-优化TransData,修改five_2_four.py) + +\## 1 模型概述 + + + +\- **[论文地址](#11-论文地址)** + + + +\- **[代码地址](#12-代码地址)** + + + +\### 1.1 论文地址 + + + +[CycleGAN论文]( https://arxiv.org/pdf/1703.10593v7.pdf) + +我们专注于本文中风格转换中的地图转换。它通过一种无监督的少样本的学习方式,能够实现航拍地图和卫星地图之间的相互转换。 + +\### 1.2 代码地址 + +[CycleGAN代码]( https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix) + +branch:master + +commit_id:略 + +备注:commit_id是指基于该次提交时的模型代码做推理,通常选择稳定版本的最后一次提交,或代码仓最新的一次提交 + + + +\## 2 环境说明 + + + +\- **[深度学习框架](#21-深度学习框架)** + + + +\- **[python第三方库](#22-python第三方库)** + + + +\### 2.1 深度学习框架 + +\``` + +``` +CANN 5.0.2.alpha003 + +torch == 1.5.0 + +torchvision == 0.9.0 + +onnx==1.7.0 + +onnx-simplifier==0.3.6 + +onnxconverter-common==1.6.1 + +onnxoptimizer==0.2.6 + +onnxruntime==1.6.0 + +tensorboard==1.15.0 + +tensorflow==1.15.0 + +tensorflow-estimator ==1.15.1 + +termcolor==1.1.0 +``` + +\``` + + + +\### 2.2 python第三方库 + +\``` + +``` +numpy == 1.16.6 + +Pillow == 8.2.0 + +opencv-python == 4.5.2.52 + +sympy == 1.4 + +decorator == 4.4.2 + +requests == 2.22.0 + +tqdm == 4.61.0 + +PyYAML == 5.4.1 +``` + +\``` + + + +**说明:** + +\> X86架构:pytorch torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3 install 包名 安装 + +\> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3 install 包名 安装 + + + +\## 3 模型转换 + + + +\- **[pth转onnx模型](#31-pth转onnx模型)** + + + +\- **[onnx转om模型](#32-onnx转om模型)** + + + +\### 3.1 pth转onnx模型 + +1.下载开源模型代码,安装必要的依赖库,并修改模型代码后安装 + +\``` + +``` +git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix +cd pytorch-CycleGAN-and-pix2pix +pip3 install -r requirements.txt +``` + +\``` + + + +2.下载pth权重文件 + + + +\- [官方CycleGAN pth权重文件](http://efrosgans.eecs.berkeley.edu/cyclegan/pretrained_models/) + +\- [获取A800-9000训练的pth文件,该链接为百度网盘链接,提取码为:1234](https://pan.baidu.com/s/1YqHkce2wUw-W8_VY9dYD_w)) + +3.编写pth2onnx脚本*CycleGAN_onnx_export.py* + + **说明:** + +\>注意目前ATC支持的onnx算子版本为11 + + + +4.执行*CycleGAN_onnx_export.py*脚本,生成onnx模型文件 + +\``` + +``` +python3 CycleGAN_onnx_export.py \ + +--model_ga_path=./checkpoints/maps_cycle_gan/latest_net_G_A.pth\ + +--model_gb_path=./checkpoints/maps_cycle_gan/latest_net_G_B.pth\ + +--onnx_path=./onnxmodel/ \ + +--model_ga_onnx_name=model_Ga.onnx \ + +--model_gb_onnx_name=model_Gb.onnx \ +``` + +\``` + + **模型转换要点:** + +\- 开源仓中的生成器采用的padding类型为ReflectionPad2d,由于在转om格式模型的时候,会出现算子不兼容问题导致om模型转换失败,这里我们将改padding类型替换为ZeroPad2d。如果您任然坚持使用ReflectionPad2d,请在转换Onnx格式后运行 + + ' ' ' + +``` +python3 CycleGAN_ReflectpadDeal.py \ + +--onnx_path=./onnxmodel/ \ + +--model_ga_onnx_name=model_Ga.onnx \ + +--model_gb_onnx_name=model_Gb.onnx \ +``` + +' ' ' + +该脚本会将ReflectionPad2d中的属性替换为constant,这样做的结果会导致模型执行推理时会出现边缘模糊,详情请见issue链接https://e.gitee.com/HUAWEI-ASCEND/issues/list?issue=I4467L#note_6141945 + + + +\### 3.2 onnx转om模型 + + + +1.设置环境变量 + +\``` + +``` +source env.sh +``` + +\``` + +\- 根据实际情况修改env.sh中的install_path=/usr/local/Ascend/ascend-toolkit/latest变量 + +\- 执行脚本前先执行指令 dos2unix * + + + +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN 5.0.1 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373) + +\``` + +``` +atc --framework=5 --model=./onnxmodel/model_Ga.onnx --output=Cons_Ga_aipp512_b0_bs1 --input_format=NCHW --input_shape="img_sat_maps:1,3,256,256" --out_nodes="Tanh_156:0" --log=debug --soc_version=Ascend310 --insert_op_conf=aipp_CycleGAN_pth.config + +atc --framework=5 --model=./onnxmodel/model_Gb.onnx --output=Cons_Gb_aipp512_b0_bs1 --input_format=NCHW --input_shape="img_maps_sat:1,3,256,256" --out_nodes="Tanh_156:0" --log=debug --soc_version=Ascend310 --insert_op_conf=aipp_CycleGAN_pth.config +``` + +\``` + +\- 说明 + + \- input_shape参数可通过Netron工具查看输入节点的名称和shape, 与pth转onnx步骤中的参数一致 + + \- out_nodes为指定输出节点, 通过Netron可以看到onnx文件有四个输出, 以自测转换的onnx为例 + + 如果在转onnx时使用的不是默认路径,请将—model中的参数设置为onnx格式模型所在的路径 + + + + + +\## 4 数据集预处理 + + + +\- **[数据集获取](#41-数据集获取)** + + + +\- **[数据集预处理](#42-数据集预处理)** + + + +\- **[生成数据集信息文件](#43-生成数据集信息文件)** + + + +\### 4.1 数据集获取 + +该模型使用[maps数据集](http://efrosgans.eecs.berkeley.edu/cyclegan/datasets/maps.zip)的testA和testB各1098张验证集进行测试,因为航拍地图和卫星地图之间的相互转换的两个生成器模型结构一样,这里我们只需要保证其中一个生辰器精度和性能跟上就行,这里我们以model_Ga.onnx和testA为推理的模型和测试数据集。 + + + +\### 4.2 数据集预处理 + +1.生成数据集信息文件脚本gen_dataset_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 + +\``` + +``` +python3 gen_dataset_info.py \ + +--src_path_testA=./datasets/maps/testA/ \ + +--save_pathTestA_dst=datasetsDst/maps/testA/ \ + +--dataTestA_infoName=testA_prep.info \ + +--src_path_testB=./datasets/maps/testB/ \ + +--save_pathTestB_dst=./datasetsDst/maps/testB/ \ + +--dataTestB_infoName=testB_prep.info +``` + +' ' ' + +\## 5 离线推理 + + + +\- **[benchmark工具概述](#51-benchmark工具概述)** + + + +\- **[离线推理](#52-离线推理)** + + + +\### 5.1 benchmark工具概述 + + + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN 5.0.1 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) + +\### 5.2 离线推理 + +1.设置环境变量 + +\``` + +source env.sh + +\``` + +2.执行离线推理 + +\- benchmark工具区分arm64和x86_64, 对应分别为./benchmark.aarch64和./benchmark.x86_64, 示例中均以x86_64环境为例 + +\- 将benchmark工具去相应路径获取后放到env.sh同级目录下,加上执行权限chmod +x benchmark.XX + +''' + +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=Cons_Ga_aipp512_b0_bs1.om -input_text_path=testA_prep.info -input_width=512 -input_height=512 -output_binary=true -useDvpp=true + +./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=1 -om_path=Cons_Gb_aipp512_b0_bs1.om -input_text_path=testB_prep.info -input_width=512 -input_height=512 -output_binary=true -useDvpp=true +``` + +输出结果默认保存在当前目录result/dumpOutput_devicex,每个输入对应的输出对应一个_x.bin文件。 + +''' + +\## 6 精度对比 + +\### 6.1 离线推理精度统计 + +由于该模型的精度在论文中是由人眼分辨,所以这里我们那Onnx和om模型输出的平均余弦相似度来替代精度,只需要保证Onnx格式模型的效果和论文中的一致并且om和onnx格式模型的余弦相似度在99%左右就精度达标。执行eval_acc_py.py脚本计算平均余弦相似度 : + +\``` + +``` + +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=Cons_Ga_aipp512_b0_bs1.om -input_text_path=testA_prep.info -input_width=512 -input_height=512 -output_binary=true -useDvpp=true #如果已经执行这一步请忽略 +python3 eval_acc.py \ +--dataroot=./datasets/maps\ +--npu_bin_file=./result/dumpOutput_device0/ +``` + +\``` + +\### 6.2精度对比 + +![1](C:\Users\Administrator\Desktop\1.png) + +将得到的om离线模型推理精度与在线推理精度对比,推理精度与在线推理精度一致,精度达标。 + + **精度调试:** + +使用onnxruntime测试onnx离线推理精度与om一致。 + +\## 7 性能对比 + +\- **[npu性能数据](#71-npu性能数据)** + +\- **[性能优化](#73-性能优化)** + +\### 7.1 npu性能数据 + +这里用batch1和batch16做示例 + + + +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device。为快速获取性能数据,也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准。这里给出两种方式,模型的测试脚本使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准。 + + + +1.benchmark工具在整个数据集上推理获得性能数据 + + + +以batch1为例,benchmark工具在整个数据集上推理,执行下面命令。 + +``` +atc --framework=5 --model=./onnxmodel/model_Ga.onnx --output=Cons_Ga_aipp512_b0_bs1 --input_format=NCHW --input_shape="img_sat_maps:1,3,256,256" --out_nodes="Tanh_156:0" --log=debug --soc_version=Ascend310 --insert_op_conf=aipp_CycleGAN_pth.config #如果已经转换,请忽略 +python3.7 gen_dataset_info.py #如果这一步已经执行,可直接执行下一步推理 +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=Cons_Ga_aipp512_b0_bs1.om -input_text_path=testA_prep.info -input_width=512 -input_height=512 -output_binary=true -useDvpp=true +``` + +\``` + + ![输入图片说明](https://images.gitee.com/uploads/images/2021/0914/121624_f45173ef_9486012.png "屏幕截图.png") + + + +Interface throughputRate: 10.7,10.7乘以4,是310单卡吞吐率 + + \``` + +2.benchmark纯推理功能测得性能数据 + + + +batch1的性能: + + 测试npu性能要确保device空闲,使用npu-smi info命令可查看device是否在运行其它推理任务 + +\``` + +``` +./benchmark.x86_64 -round=20 -om_path=Cons_Ga_aipp512_b0_bs1.om -device_id=0 -batch_size=1 +``` + +``` + +执行20次纯推理取均值,统计吞吐率与其倒数时延(benchmark的时延是单个数据的推理时间),npu性能是一个device执行的结果 + + ![输入图片说明](https://images.gitee.com/uploads/images/2021/0914/121641_4ed82b8d_9486012.png "屏幕截图.png") +``` + + +Batch16的性能: + +``` +./benchmark.x86_64 -round=20 -om_path=model_Ga-b0_bs16.om -device_id=1 -batch_size=16 +``` + +![输入图片说明](https://images.gitee.com/uploads/images/2021/0914/121659_6331aa3d_9486012.png "屏幕截图.png") + +\### 7.2 性能优化 + +``` +**性能优化** + +\- profiling性能分析方法 + +​ CANN C20及以后的版本profiling使用方法 + +新建/home/zlz/CycleGan_deal/perProblem_detec/run文件,内容如下: + +``` +``` +# /usr/local/Ascend/ascend-toolkit/ /usr/local/Ascend/ascend-toolkit/ +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +./benchmark.x86_64 -round=20 -om_path=/home/zlz/cyclegan/model_Ga1-b0_bs16.om -device_id=0 -batch_size=16 +``` + +然后执行如下命令: +``` +chmod 777 /home/zlz/CycleGan_deal/perProblem_detec/run +cd /usr/local/Ascend/ascend-toolkit/latest/x86_64-linux/toolkit/tools/profiler/bin +./msprof --output=/home/zlz/CycleGan_deal/perProblem_detec/perPro/ --application=/home/zlz/CycleGan_deal/perProblem_detec/run --sys-hardware-mem=on --sys-cpu-profiling=on --sys-profiling=on --sys-pid-profiling=on --sys-io-profiling=on --dvpp-profiling=on +cd /usr/local/Ascend/ascend-toolkit/latest/x86_64-linux/toolkit/tools/profiler/profiler_tool/analysis/msprof/ +# 生成的profiling目录 +python3.7 msprof.py import -dir/home/zlz/CycleGan_deal/perProblem_detec/perPro/ +python3.7 msprof.py export summary -dir /home/zlz/CycleGan_deal/perProblem_detec/perPro/ +#生成的profiling目录 --iteration-id 1 +python3.7 msprof.py export timeline -dir /home/zlz/CycleGan_deal/perProblem_detec/perPro/ + +``` +目录 + +\- 性能调优测试版本:CANN 5.0.2.alpha003 + +\- 性能优化过程主要对trans_Data算子进行优化,结合profiling分析,性能有提升: + +\#### 7.3.1 five_2_four.py优化方法 + + 在环境变量env.sh中export install_path=/usr/local/Ascend/ascend-toolkit/latest路径下查找five_2_four.py文件,路径一般为 + +\``` + +/usr/local/Ascend/ascend-toolkit/latest/x86_64-linux/opp/op_impl/built-in/ai_core/tbe/impl/five_2_four.py + +\``` + +修改five_2_four.py文件,将TransData算子的output shape加入five_2_four函数行中,示例如下: + +\``` + + ... + from impl import trans_data_negative_target_ntc + + @util.check_input_type(dict, dict, str, str, str) + + def five_2_four(src, dst, src_format, dst_format, kernel_name='five_2_four'): + elif dst_format.lower() == "nhwc" and dst_shape in [[10000, 63, 63, 1], [10000, 127, 127, 1], [16, 19, 19, 486], + + [16, 10, 10, 486], [16, 38, 38, 324], [16, 5, 5, 486], + + [16, 3, 3, 324], [8, 19, 19, 486], [8, 10, 10, 486], + + [8, 38, 38, 324], [8, 5, 5, 486], [8, 3, 3, 324], + + [100, 28, 28, 91]]: + + trans_data_negative_target_tc.trans_data_negative_target_tc(src, dst, src_format, dst_format, kernel_name) + + elif dst_format.lower() == "nchw" and dst_shape in [[2560, 512, 4, 26], [2560, 512, 1, 26], [2560, 256, 8, 25], + + [16, 240, 7, 7], [16, 120, 14, 14], [1,19,1024,2048], [4,19,1024,2048]]: + + print("=================================") + + print("ntc dst shape:", dst_shape) + + print("=================================") + + trans_data_negative_target_ntc.trans_data_negative_target_ntc(src, dst, src_format, dst_format, kernel_name) + ... + +\``` + +\- 不同的batch_size,添加的shape不一样,shape大小为[*,19,256,256 ] ,以本模型为例,只测试batch1和batch16,因此添加的shape为[1,19,256,256],[4,19,256,256] + +修改完成后,重新转换生成om文件,atc转换过程会打印添加的日志,如下: + +\```![输入图片说明](https://images.gitee.com/uploads/images/2021/0914/121715_d94592ad_9486012.png "屏幕截图.png") + + \``` + +纯推理测试结果: + +\``` + +bs1: + + ![输入图片说明](https://images.gitee.com/uploads/images/2021/0914/121721_50c95bdd_9486012.png "屏幕截图.png") + +Bs16: + +![输入图片说明](https://images.gitee.com/uploads/images/2021/0914/122022_a16e9ff5_9486012.png "屏幕截图.png") + +\``` + + + +用生成的om文件做精度后处理,测得bs1和bs16与之前的Onnx模型做余弦相似度高于99%,精度无损失、 + +\``` + +\#### 7.3.1 总结 + +优化方案共包括五种: + +(1)优化TransData,修改five_2_four.py + +(2)输出节点由float32改为float16 + +(3)模型中Resize节点的mode由双线性为最近邻 + +(4)将PadV3D进行算子融合 + +(5)优化FrameworkOP框架 + +由于在蓝区测试的版本CANN 5.0.2.alpha003中,已经实现了PadV3D算子融合,因此测试过程默认已经优化。同时方案(5)暂时无法实现,因此也无法比对性能。 + +结论: + +\- 因为关键算子性能差,性能暂时无法达标。 + \- 最终精度测试,Om模型输出效果达到论文效果,转Om后无精度损失。 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/CycleGAN/eval_acc.py b/ACL_PyTorch/contrib/cv/gan/CycleGAN/eval_acc.py index 875097d6fec5e85990734ace24103064b174d01f..e25f08a55a97c24b7299e5715aaa5d022fbd069b 100644 --- a/ACL_PyTorch/contrib/cv/gan/CycleGAN/eval_acc.py +++ b/ACL_PyTorch/contrib/cv/gan/CycleGAN/eval_acc.py @@ -1,110 +1,110 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import os -import glob -import numpy as np -import onnxruntime -import torch -from PIL import Image -from torchvision import transforms -import parse -import PIL.Image as pil -import matplotlib.pyplot as plt - - -def make_power(img, base, method=Image.BICUBIC): - ow, oh = img.size - h = int(round(oh / base) * base) - w = int(round(ow / base) * base) - if h == oh and w == ow: - return img - return img.resize((w, h), method) - - -def preprocess(PIL_img, image_shape): - process = transforms.Compose([ - transforms.Lambda(lambda img: make_power(img, base=4, method=Image.BICUBIC)), - transforms.Resize(image_shape), - transforms.ToTensor(), - transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))]) - return process(PIL_img).unsqueeze(dim=0) # (batch_size, 3, H, W) - - -def postprocess(img_tensor): - inv_normalize = transforms.Normalize( - mean=(-1, -1, -1), - std=(2.0, 2.0, 2.0)) - to_PIL_image = transforms.ToPILImage() - return to_PIL_image(inv_normalize(img_tensor[0]).clamp(0, 1)) - - -def bin2img_tensor(bin_src): - # read bin - with open(bin_src, 'rb') as f: - imageBin = f.read() - # What is stored in the bin file is a half-precision file, so we need to convert - # the binary to half-precision, and restore the model output shape 1*3*256*256 - img_tensor = torch.tensor(np.reshape(np.frombuffer(imageBin, 'f4'), (1, 3, 256, 256))) - return img_tensor - - -def main(): - opt = parse.parse_args().initialize() - if (os.path.exists(opt.bin2img_fie) == False): - os.makedirs(opt.bin2img_fie) - npu_bin = glob.glob(opt.npu_bin_file + '*.bin') - onnxTestImage_path = glob.glob(opt.dataroot + '/testA/*.*') - model_Ga = onnxruntime.InferenceSession(opt.onnx_path + opt.model_ga_onnx_name) - cossimis = [] - for i in onnxTestImage_path: - temp = i.split('/')[4].split('.')[0] - bin_name = temp + '_1.bin' - bin_path = opt.npu_bin_file + bin_name - check = os.path.exists(bin_path) - if check == True: - b2imtensor = bin2img_tensor(bin_path) - pil_image = pil.open(i).convert('RGB') - tensorData = preprocess(pil_image, 256) - outputs = model_Ga.run(['maps'], {'img_sat_maps': tensorData.numpy()}) - outputs = torch.tensor(outputs[0]) - cosSimi = torch.mean(torch.cosine_similarity(outputs, b2imtensor)) - cossimis.append(cosSimi.numpy()) - print('average cosine_similarity:') - print(np.mean(cossimis)) - plt.plot(cossimis) - plt.xlabel("samples") - plt.ylabel("cosine_similarity") - plt.savefig('cosine_similarity.jpg') - plt.show() - - -if __name__ == '__main__': - main() +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import os +import glob +import numpy as np +import onnxruntime +import torch +from PIL import Image +from torchvision import transforms +import parse +import PIL.Image as pil +import matplotlib.pyplot as plt + + +def make_power(img, base, method=Image.BICUBIC): + ow, oh = img.size + h = int(round(oh / base) * base) + w = int(round(ow / base) * base) + if h == oh and w == ow: + return img + return img.resize((w, h), method) + + +def preprocess(PIL_img, image_shape): + process = transforms.Compose([ + transforms.Lambda(lambda img: make_power(img, base=4, method=Image.BICUBIC)), + transforms.Resize(image_shape), + transforms.ToTensor(), + transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))]) + return process(PIL_img).unsqueeze(dim=0) # (batch_size, 3, H, W) + + +def postprocess(img_tensor): + inv_normalize = transforms.Normalize( + mean=(-1, -1, -1), + std=(2.0, 2.0, 2.0)) + to_PIL_image = transforms.ToPILImage() + return to_PIL_image(inv_normalize(img_tensor[0]).clamp(0, 1)) + + +def bin2img_tensor(bin_src): + # read bin + with open(bin_src, 'rb') as f: + imageBin = f.read() + # What is stored in the bin file is a half-precision file, so we need to convert + # the binary to half-precision, and restore the model output shape 1*3*256*256 + img_tensor = torch.tensor(np.reshape(np.frombuffer(imageBin, 'f4'), (1, 3, 256, 256))) + return img_tensor + + +def main(): + opt = parse.parse_args().initialize() + if (os.path.exists(opt.bin2img_fie) == False): + os.makedirs(opt.bin2img_fie) + npu_bin = glob.glob(opt.npu_bin_file + '*.bin') + onnxTestImage_path = glob.glob(opt.dataroot + '/testA/*.*') + model_Ga = onnxruntime.InferenceSession(opt.onnx_path + opt.model_ga_onnx_name) + cossimis = [] + for i in onnxTestImage_path: + temp = i.split('/')[4].split('.')[0] + bin_name = temp + '_1.bin' + bin_path = opt.npu_bin_file + bin_name + check = os.path.exists(bin_path) + if check == True: + b2imtensor = bin2img_tensor(bin_path) + pil_image = pil.open(i).convert('RGB') + tensorData = preprocess(pil_image, 256) + outputs = model_Ga.run(['maps'], {'img_sat_maps': tensorData.numpy()}) + outputs = torch.tensor(outputs[0]) + cosSimi = torch.mean(torch.cosine_similarity(outputs, b2imtensor)) + cossimis.append(cosSimi.numpy()) + print('average cosine_similarity:') + print(np.mean(cossimis)) + plt.plot(cossimis) + plt.xlabel("samples") + plt.ylabel("cosine_similarity") + plt.savefig('cosine_similarity.jpg') + plt.show() + + +if __name__ == '__main__': + main() diff --git a/ACL_PyTorch/contrib/cv/gan/CycleGAN/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/gan/CycleGAN/gen_dataset_info.py index 51f2d64c68399b24fcee22467d6d7b15f7bd56d2..313e6529d450f6344b263b33826571f95b13285b 100644 --- a/ACL_PyTorch/contrib/cv/gan/CycleGAN/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/gan/CycleGAN/gen_dataset_info.py @@ -1,89 +1,89 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import argparse -import os -from PIL import Image - - -def parse(): - """Define the common options that are used in both training and test.""" - # basic parameters - parser = argparse.ArgumentParser(description='cyclegan test for image preprocess') - parser.add_argument('--src_path_testA', required=False, default='datasets/maps/testA/', - help='path to images testA)') - parser.add_argument('--save_pathTestA_dst', required=False, default='datasetsDst/maps/testA/', - help='path to images testA)') - parser.add_argument('--dataTestA_infoName', default='testA_prep.info', help='name of the ..') - - parser.add_argument('--src_path_testB', required=False, default='datasets/maps/testB/', - help='path to images testB)') - parser.add_argument('--save_pathTestB_dst', required=False, default='datasetsDst/maps/testB/', - help='path to images testA)') - parser.add_argument('--dataTestB_infoName', required=False, default='testB_prep.info', help='name of the ..') - opt = parser.parse_args() - if (os.path.exists(opt.save_pathTestA_dst) == False): - os.makedirs(opt.save_pathTestA_dst) - if (os.path.exists(opt.save_pathTestB_dst) == False): - os.makedirs(opt.save_pathTestB_dst) - return opt - - -def rs_img_bin(src_path, savepath, data_list_path): - i = 0 - in_files = os.listdir(src_path) - listfile = open(data_list_path, 'w') - for file in in_files: - # print(file, "===", i) - image_path = src_path + '/' + file - input_image = Image.open(image_path) - imgsavepath = savepath + str(file).split('.')[0] + '.jpeg' - input_image.thumbnail((512, 512), Image.ANTIALIAS) - input_image.save(imgsavepath) - w, h = input_image.size - temp = str(i) + ' ' + savepath + '/' + str(file).split('.')[0] + \ - '.jpeg' + ' ' + str(w) + ' ' + str(h) + '\n' - listfile.write(temp) - i = i + 1 - listfile.close() - - -def main(opt): - # deal testA and save img data to bin - rs_img_bin(opt.src_path_testA, opt.save_pathTestA_dst, opt.dataTestA_infoName) - # deal testB and save img data to bin - rs_img_bin(opt.src_path_testB, opt.save_pathTestB_dst, opt.dataTestB_infoName) - return 0 - - -if __name__ == '__main__': - opt = parse() - main(opt) +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import argparse +import os +from PIL import Image + + +def parse(): + """Define the common options that are used in both training and test.""" + # basic parameters + parser = argparse.ArgumentParser(description='cyclegan test for image preprocess') + parser.add_argument('--src_path_testA', required=False, default='datasets/maps/testA/', + help='path to images testA)') + parser.add_argument('--save_pathTestA_dst', required=False, default='datasetsDst/maps/testA/', + help='path to images testA)') + parser.add_argument('--dataTestA_infoName', default='testA_prep.info', help='name of the ..') + + parser.add_argument('--src_path_testB', required=False, default='datasets/maps/testB/', + help='path to images testB)') + parser.add_argument('--save_pathTestB_dst', required=False, default='datasetsDst/maps/testB/', + help='path to images testA)') + parser.add_argument('--dataTestB_infoName', required=False, default='testB_prep.info', help='name of the ..') + opt = parser.parse_args() + if (os.path.exists(opt.save_pathTestA_dst) == False): + os.makedirs(opt.save_pathTestA_dst) + if (os.path.exists(opt.save_pathTestB_dst) == False): + os.makedirs(opt.save_pathTestB_dst) + return opt + + +def rs_img_bin(src_path, savepath, data_list_path): + i = 0 + in_files = os.listdir(src_path) + listfile = open(data_list_path, 'w') + for file in in_files: + # print(file, "===", i) + image_path = src_path + '/' + file + input_image = Image.open(image_path) + imgsavepath = savepath + str(file).split('.')[0] + '.jpeg' + input_image.thumbnail((512, 512), Image.ANTIALIAS) + input_image.save(imgsavepath) + w, h = input_image.size + temp = str(i) + ' ' + savepath + '/' + str(file).split('.')[0] + \ + '.jpeg' + ' ' + str(w) + ' ' + str(h) + '\n' + listfile.write(temp) + i = i + 1 + listfile.close() + + +def main(opt): + # deal testA and save img data to bin + rs_img_bin(opt.src_path_testA, opt.save_pathTestA_dst, opt.dataTestA_infoName) + # deal testB and save img data to bin + rs_img_bin(opt.src_path_testB, opt.save_pathTestB_dst, opt.dataTestB_infoName) + return 0 + + +if __name__ == '__main__': + opt = parse() + main(opt) diff --git a/ACL_PyTorch/contrib/cv/gan/CycleGAN/maps_torch_preprocess.py b/ACL_PyTorch/contrib/cv/gan/CycleGAN/maps_torch_preprocess.py index f7f45d6b8d113300f93535202515c27c9f9c72dc..cacbde78fe5a58505066bb7c5225869c43ca3630 100644 --- a/ACL_PyTorch/contrib/cv/gan/CycleGAN/maps_torch_preprocess.py +++ b/ACL_PyTorch/contrib/cv/gan/CycleGAN/maps_torch_preprocess.py @@ -1,109 +1,109 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import argparse -import os -import torchvision.transforms as transforms -from PIL import Image -import numpy as np - - -def make_power(img, base, method=Image.BICUBIC): - ow, oh = img.size - h = int(round(oh / base) * base) - w = int(round(ow / base) * base) - if h == oh and w == ow: - return img - return img.resize((w, h), method) - - -def preprocess(PIL_img, image_shape=256): - process=transforms.Compose([ - transforms.Lambda(lambda img: make_power(img, base=4, method=Image.BICUBIC)), - transforms.Resize(image_shape), - transforms.ToTensor(), - transforms.Normalize(mean=(0.5,0.5,0.5), std=(0.5,0.5,0.5))]) - return process(PIL_img) - - -def postprocess(img_tensor): - inv_normalize = transforms.Normalize( - mean= (-1,-1,-1), - std= (2.0,2.0,2.0)) - to_PIL_image = transforms.ToPILImage().convert('RGB') - return to_PIL_image(inv_normalize(img_tensor[0]).clamp(0, 1)) - - -def parse(): - """Define the common options that are used in both training and test.""" - # basic parameters - parser = argparse.ArgumentParser(description='cyclegan test for image preprocess') - parser.add_argument('--src_path_testA', required=False,default='datasets/maps/testA/', help='path to images testA)') - parser.add_argument('--save_path_testA_bin', type=str, default='nputest/testa', help='name of the ..') - parser.add_argument('--path_testA_binName', type=str, default='testA_prep_bin.info', help='name of the ..') - parser.add_argument('--src_path_testB', required=False, default='datasets/maps/testB/', help='path to images testB)') - parser.add_argument('--save_path_testB_bin', type=str, default='nputest/testb', help='name of the ..') - parser.add_argument('--path_testB_binName', type=str, default='testB_prep_bin.info', help='name of the ..') - opt=parser.parse_args() - if(os.path.exists(opt.save_path_testA_bin)==False): - os.makedirs(opt.save_path_testA_bin) - if(os.path.exists(opt.save_path_testB_bin)==False): - os.makedirs(opt.save_path_testB_bin) - return opt - - -def rs_img_bin(src_path,save_path,data_list_path): - i = 0 - in_files = os.listdir(src_path) - listfile = open(data_list_path, 'w') - for file in in_files: - #print(file, "===", i) - input_image = Image.open(src_path + '/' + file) - input_tensor = preprocess(input_image) - img = np.array(input_tensor).astype(np.float32) - img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) - temp = str(str(i) + ' ./' + os.path.join(save_path, file.split('.')[0] + ".bin") + ' ' + '256 256\n') - listfile.write(temp) - i = i + 1 - listfile.close() - - -def main(opt): - # deal testA and save img data to bin - rs_img_bin(opt.src_path_testA, opt.save_path_testA_bin, opt.path_testA_binName) - # deal testB and save img data to bin - rs_img_bin(opt.src_path_testB, opt.save_path_testB_bin, opt.path_testB_binName) - return 0 - - -if __name__=='__main__': - opt=parse() +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import argparse +import os +import torchvision.transforms as transforms +from PIL import Image +import numpy as np + + +def make_power(img, base, method=Image.BICUBIC): + ow, oh = img.size + h = int(round(oh / base) * base) + w = int(round(ow / base) * base) + if h == oh and w == ow: + return img + return img.resize((w, h), method) + + +def preprocess(PIL_img, image_shape=256): + process=transforms.Compose([ + transforms.Lambda(lambda img: make_power(img, base=4, method=Image.BICUBIC)), + transforms.Resize(image_shape), + transforms.ToTensor(), + transforms.Normalize(mean=(0.5,0.5,0.5), std=(0.5,0.5,0.5))]) + return process(PIL_img) + + +def postprocess(img_tensor): + inv_normalize = transforms.Normalize( + mean= (-1,-1,-1), + std= (2.0,2.0,2.0)) + to_PIL_image = transforms.ToPILImage().convert('RGB') + return to_PIL_image(inv_normalize(img_tensor[0]).clamp(0, 1)) + + +def parse(): + """Define the common options that are used in both training and test.""" + # basic parameters + parser = argparse.ArgumentParser(description='cyclegan test for image preprocess') + parser.add_argument('--src_path_testA', required=False,default='datasets/maps/testA/', help='path to images testA)') + parser.add_argument('--save_path_testA_bin', type=str, default='nputest/testa', help='name of the ..') + parser.add_argument('--path_testA_binName', type=str, default='testA_prep_bin.info', help='name of the ..') + parser.add_argument('--src_path_testB', required=False, default='datasets/maps/testB/', help='path to images testB)') + parser.add_argument('--save_path_testB_bin', type=str, default='nputest/testb', help='name of the ..') + parser.add_argument('--path_testB_binName', type=str, default='testB_prep_bin.info', help='name of the ..') + opt=parser.parse_args() + if(os.path.exists(opt.save_path_testA_bin)==False): + os.makedirs(opt.save_path_testA_bin) + if(os.path.exists(opt.save_path_testB_bin)==False): + os.makedirs(opt.save_path_testB_bin) + return opt + + +def rs_img_bin(src_path,save_path,data_list_path): + i = 0 + in_files = os.listdir(src_path) + listfile = open(data_list_path, 'w') + for file in in_files: + #print(file, "===", i) + input_image = Image.open(src_path + '/' + file) + input_tensor = preprocess(input_image) + img = np.array(input_tensor).astype(np.float32) + img.tofile(os.path.join(save_path, file.split('.')[0] + ".bin")) + temp = str(str(i) + ' ./' + os.path.join(save_path, file.split('.')[0] + ".bin") + ' ' + '256 256\n') + listfile.write(temp) + i = i + 1 + listfile.close() + + +def main(opt): + # deal testA and save img data to bin + rs_img_bin(opt.src_path_testA, opt.save_path_testA_bin, opt.path_testA_binName) + # deal testB and save img data to bin + rs_img_bin(opt.src_path_testB, opt.save_path_testB_bin, opt.path_testB_binName) + return 0 + + +if __name__=='__main__': + opt=parse() main(opt) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/CycleGAN/parse.py b/ACL_PyTorch/contrib/cv/gan/CycleGAN/parse.py index a8142636cdd7cb86da9977f4b06544fe35c93a14..cc4b43d67680d1913c6137117cf38209dcb84448 100644 --- a/ACL_PyTorch/contrib/cv/gan/CycleGAN/parse.py +++ b/ACL_PyTorch/contrib/cv/gan/CycleGAN/parse.py @@ -1,141 +1,141 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import argparse -import torch -import os - - -class parse_args(): - def __init__(self, isTrain=True, isTest=False): - self.isTrain = isTrain - self.isTest = isTest - self.parser = argparse.ArgumentParser(description='Pytorch CycleGAN training') - - def initialize(self): - parser = self.parser - parser.add_argument('--npu', default=False, help='whether to use npu to fastern training') - parser.add_argument('--pu_ids', type=str, default='1', - help='gpu ids(npu ids): e.g. 0 0,1,2, 0,2. use -1 for CPU') - parser.add_argument('--dataroot', type=str, default='./datasets/maps', - help='path to images (should have subfolders trainA, trainB, valA, valB, etc)') - parser.add_argument('--name', type=str, default='maps_cycle_gan', - help='name of the experiment. It decides where to store samples and models') - - parser.add_argument('--checkpoints_dir', type=str, default='./checkpoints', help='models are saved here') - # model parameters - parser.add_argument('--model', type=str, default='cycle_gan', - help='chooses which model to use. [cycle_gan]') - parser.add_argument('--input_nc', type=int, default=3, - help='# of input image channels: 3 for RGB and 1 for grayscale') - parser.add_argument('--output_nc', type=int, default=3, - help='# of output image channels: 3 for RGB and 1 for grayscale') - parser.add_argument('--ngf', type=int, default=64, help='# of gen filters in the last conv layer') - parser.add_argument('--ndf', type=int, default=64, help='# of discrim filters in the first conv layer') - parser.add_argument('--netD', type=str, default='basic', - help='specify discriminator architecture [basic | n_layers | pixel]. ' - 'The basic model is a 70x70 PatchGAN. n_layers allows you to' - ' specify the layers in the discriminator') - parser.add_argument('--netG', type=str, default='resnet_9blocks', - help='specify generator architecture [resnet_9blocks | resnet_6blocks | unet_256 | unet_128]') - parser.add_argument('--n_layers_D', type=int, default=3, help='only used if netD==n_layers') - parser.add_argument('--norm', type=str, default='instance', - help='instance normalization or batch normalization [instance | batch | none]') - parser.add_argument('--init_type', type=str, default='normal', - help='network initialization [normal | xavier | kaiming | orthogonal]') - parser.add_argument('--init_gain', type=float, default=0.02, - help='scaling factor for normal, xavier and orthogonal.') - parser.add_argument('--no_dropout', action='store_true', help='no dropout for the generator') - parser.add_argument('--direction', type=str, default='AtoB', help='AtoB or BtoA') - parser.add_argument('--batch_size', type=int, default=1, - help='batch_size') - # additional parameters - parser.set_defaults(no_dropout=True) # default CycleGAN did not use dropout - parser.add_argument('--model_ga_path', type=str, - default='./checkpoints/maps_cycle_gan/latest_net_G_A.pth', - help='path for modelga') - parser.add_argument('--model_gb_path', type=str, - default='./checkpoints/maps_cycle_gan/latest_net_G_B.pth', - help='path for modelga') - parser.add_argument('--onnx_path', type=str, - default='./onnxmodel/', - help='path for modelga') - parser.add_argument('--model_ga_onnx_name', type=str, - default='model_Ga.onnx', - help='onnx name for modelga') - parser.add_argument('--model_gb_onnx_name', type=str, - default='model_Gb.onnx', - help='onnx for modelgb') - parser.add_argument('--gpuPerformance', type=str, - default='./gpuPerformance/', - help='file for t4 test result ') - parser.add_argument('--npu_bin_file', type=str, - default='./result/dumpOutput_device0/', - help='npu bin ') - parser.add_argument('--bin2img_fie', type=str, - default='./bin2imgfile/', - help='save bin2img ') - # rewrite devalue values - parser.set_defaults(model='test') - # To avoid cropping, the load_size should be the same as crop_size - parser.set_defaults(load_size=parser.get_default('crop_size')) - parser = parser.parse_args() - parser.process_device_map = self.device_id_to_process_device_map(parser.pu_ids) - return parser - - def device_id_to_process_device_map(self, device_list): - devices = device_list.split(",") - devices = [int(x) for x in devices] - devices.sort() - - process_device_map = dict() - for process_id, device_id in enumerate(devices): - process_device_map[process_id] = device_id - return process_device_map - - def change_parser(self, isTrain=True, isTest=False): - self.isTest = isTest - self.isTrain = isTrain - self.parser = None - return self.initialize() - - def printParser(self): - pasers = self.parser.parse_args() - message = '' - message += '----------------- Options ---------------\n' - for k, v in sorted(vars(pasers).items()): - comment = '' - default = self.parser.get_default(k) - # if v != default: - # comment = '\t[default: %s]' % str(default) - message += '{:>25}: {:<30}{}\n'.format(str(k), str(v), comment) - message += '----------------- End -------------------' - print(message) +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import argparse +import torch +import os + + +class parse_args(): + def __init__(self, isTrain=True, isTest=False): + self.isTrain = isTrain + self.isTest = isTest + self.parser = argparse.ArgumentParser(description='Pytorch CycleGAN training') + + def initialize(self): + parser = self.parser + parser.add_argument('--npu', default=False, help='whether to use npu to fastern training') + parser.add_argument('--pu_ids', type=str, default='1', + help='gpu ids(npu ids): e.g. 0 0,1,2, 0,2. use -1 for CPU') + parser.add_argument('--dataroot', type=str, default='./datasets/maps', + help='path to images (should have subfolders trainA, trainB, valA, valB, etc)') + parser.add_argument('--name', type=str, default='maps_cycle_gan', + help='name of the experiment. It decides where to store samples and models') + + parser.add_argument('--checkpoints_dir', type=str, default='./checkpoints', help='models are saved here') + # model parameters + parser.add_argument('--model', type=str, default='cycle_gan', + help='chooses which model to use. [cycle_gan]') + parser.add_argument('--input_nc', type=int, default=3, + help='# of input image channels: 3 for RGB and 1 for grayscale') + parser.add_argument('--output_nc', type=int, default=3, + help='# of output image channels: 3 for RGB and 1 for grayscale') + parser.add_argument('--ngf', type=int, default=64, help='# of gen filters in the last conv layer') + parser.add_argument('--ndf', type=int, default=64, help='# of discrim filters in the first conv layer') + parser.add_argument('--netD', type=str, default='basic', + help='specify discriminator architecture [basic | n_layers | pixel]. ' + 'The basic model is a 70x70 PatchGAN. n_layers allows you to' + ' specify the layers in the discriminator') + parser.add_argument('--netG', type=str, default='resnet_9blocks', + help='specify generator architecture [resnet_9blocks | resnet_6blocks | unet_256 | unet_128]') + parser.add_argument('--n_layers_D', type=int, default=3, help='only used if netD==n_layers') + parser.add_argument('--norm', type=str, default='instance', + help='instance normalization or batch normalization [instance | batch | none]') + parser.add_argument('--init_type', type=str, default='normal', + help='network initialization [normal | xavier | kaiming | orthogonal]') + parser.add_argument('--init_gain', type=float, default=0.02, + help='scaling factor for normal, xavier and orthogonal.') + parser.add_argument('--no_dropout', action='store_true', help='no dropout for the generator') + parser.add_argument('--direction', type=str, default='AtoB', help='AtoB or BtoA') + parser.add_argument('--batch_size', type=int, default=1, + help='batch_size') + # additional parameters + parser.set_defaults(no_dropout=True) # default CycleGAN did not use dropout + parser.add_argument('--model_ga_path', type=str, + default='./checkpoints/maps_cycle_gan/latest_net_G_A.pth', + help='path for modelga') + parser.add_argument('--model_gb_path', type=str, + default='./checkpoints/maps_cycle_gan/latest_net_G_B.pth', + help='path for modelga') + parser.add_argument('--onnx_path', type=str, + default='./onnxmodel/', + help='path for modelga') + parser.add_argument('--model_ga_onnx_name', type=str, + default='model_Ga.onnx', + help='onnx name for modelga') + parser.add_argument('--model_gb_onnx_name', type=str, + default='model_Gb.onnx', + help='onnx for modelgb') + parser.add_argument('--gpuPerformance', type=str, + default='./gpuPerformance/', + help='file for t4 test result ') + parser.add_argument('--npu_bin_file', type=str, + default='./result/dumpOutput_device0/', + help='npu bin ') + parser.add_argument('--bin2img_fie', type=str, + default='./bin2imgfile/', + help='save bin2img ') + # rewrite devalue values + parser.set_defaults(model='test') + # To avoid cropping, the load_size should be the same as crop_size + parser.set_defaults(load_size=parser.get_default('crop_size')) + parser = parser.parse_args() + parser.process_device_map = self.device_id_to_process_device_map(parser.pu_ids) + return parser + + def device_id_to_process_device_map(self, device_list): + devices = device_list.split(",") + devices = [int(x) for x in devices] + devices.sort() + + process_device_map = dict() + for process_id, device_id in enumerate(devices): + process_device_map[process_id] = device_id + return process_device_map + + def change_parser(self, isTrain=True, isTest=False): + self.isTest = isTest + self.isTrain = isTrain + self.parser = None + return self.initialize() + + def printParser(self): + pasers = self.parser.parse_args() + message = '' + message += '----------------- Options ---------------\n' + for k, v in sorted(vars(pasers).items()): + comment = '' + default = self.parser.get_default(k) + # if v != default: + # comment = '\t[default: %s]' % str(default) + message += '{:>25}: {:<30}{}\n'.format(str(k), str(v), comment) + message += '----------------- End -------------------' + print(message) diff --git a/ACL_PyTorch/contrib/cv/gan/DCGAN/README.md b/ACL_PyTorch/contrib/cv/gan/DCGAN/README.md index 51a5bcdee7180c0afc62a00c6bcf03714b1f42cb..bc1071da1cb9209f2ae2de0e93466dc6c63c389b 100644 --- a/ACL_PyTorch/contrib/cv/gan/DCGAN/README.md +++ b/ACL_PyTorch/contrib/cv/gan/DCGAN/README.md @@ -1,58 +1,58 @@ -# DCGAN模型PyTorch离线推理指导 -## 1 环境准备 -### 1.1 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -``` -pip3.7 install -r requirements.txt -``` -### 1.2 获取,安装开源模型代码 -``` -git clone https://github.com/eriklindernoren/PyTorch-GAN.git -``` -使用patch文件更改开源代码仓源码 -``` -mv dcgan.patch PyTorch-GAN/ -cd PyTorch-GAN/ -git apply dcgan.patch -cd .. -``` -### 1.3 获取权重文件 -[DCGAN预训练权重文件](https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/GAN/DCGan/checkpoint-amp-epoch_200.pth) -``` -wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/GAN/DCGan/checkpoint-amp-epoch_200.pth -``` -### 1.4 数据集 -DCGAN的输入是随机噪声。当前目录下的`dcgan_preprocess.py`文件会随机生成输入噪声作为数据集。 -此脚本无需主动运行。 - -默认设置下,生成8192个噪声样本。 -### 1.5 [获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) -将benchmark.x86_64或benchmark.aarch64放到当前目录,并更改权限 -``` -chmod 777 benchmark.x86_64 -``` -## 2 离线推理 -### 2.1 性能测试 -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -bash test/pth2om.sh -bash test/eval_perf.sh -``` -### 2.2 精度测试 -由于开源代码仓并未提供合适的精度指标来衡量模型的生成精度。 -我们提供了图像像素差均值(mean)和图像余弦相似度(consine)作为精度指标以供参考。 - -因为npu的推理结果是以pth的生成结果为基准。 -所以两个指标的计算对象分别是pth模型在cpu上的生成集合和om模型在npu上的生成集合。 -除却均值指标与相似度指标外,还提供了一个精度指标(acc)。`acc=(cosine+1)/2`。目的是为了获得一个百分比值便于直观理解精度。 -``` -#直接执行acc验证脚本 -bash test/eval_acc.sh -``` - -结果分别保存在当前目录的`dcgan_acc_eval_bs1.log`与`dcgan_acc_eval_bs16.log`中。 -### 2.3 测评结果 -|模型|精度(mean)|精度(cosine)|精度(acc)|性能基准|310性能| -|----|----|----|----|----|----| -|DCGAN bs1|0.0004|1.0|100.0%|10174.65fps|11429.32fps| -|DCGAN bs16|0.0004|1.0|100.0%|46711.51fps|63607.60fps| - +# DCGAN模型PyTorch离线推理指导 +## 1 环境准备 +### 1.1 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip3.7 install -r requirements.txt +``` +### 1.2 获取,安装开源模型代码 +``` +git clone https://github.com/eriklindernoren/PyTorch-GAN.git +``` +使用patch文件更改开源代码仓源码 +``` +mv dcgan.patch PyTorch-GAN/ +cd PyTorch-GAN/ +git apply dcgan.patch +cd .. +``` +### 1.3 获取权重文件 +[DCGAN预训练权重文件](https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/GAN/DCGan/checkpoint-amp-epoch_200.pth) +``` +wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/GAN/DCGan/checkpoint-amp-epoch_200.pth +``` +### 1.4 数据集 +DCGAN的输入是随机噪声。当前目录下的`dcgan_preprocess.py`文件会随机生成输入噪声作为数据集。 +此脚本无需主动运行。 + +默认设置下,生成8192个噪声样本。 +### 1.5 [获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) +将benchmark.x86_64或benchmark.aarch64放到当前目录,并更改权限 +``` +chmod 777 benchmark.x86_64 +``` +## 2 离线推理 +### 2.1 性能测试 +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_perf.sh +``` +### 2.2 精度测试 +由于开源代码仓并未提供合适的精度指标来衡量模型的生成精度。 +我们提供了图像像素差均值(mean)和图像余弦相似度(consine)作为精度指标以供参考。 + +因为npu的推理结果是以pth的生成结果为基准。 +所以两个指标的计算对象分别是pth模型在cpu上的生成集合和om模型在npu上的生成集合。 +除却均值指标与相似度指标外,还提供了一个精度指标(acc)。`acc=(cosine+1)/2`。目的是为了获得一个百分比值便于直观理解精度。 +``` +#直接执行acc验证脚本 +bash test/eval_acc.sh +``` + +结果分别保存在当前目录的`dcgan_acc_eval_bs1.log`与`dcgan_acc_eval_bs16.log`中。 +### 2.3 测评结果 +|模型|精度(mean)|精度(cosine)|精度(acc)|性能基准|310性能| +|----|----|----|----|----|----| +|DCGAN bs1|0.0004|1.0|100.0%|10174.65fps|11429.32fps| +|DCGAN bs16|0.0004|1.0|100.0%|46711.51fps|63607.60fps| + diff --git a/ACL_PyTorch/contrib/cv/gan/DCGAN/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/gan/DCGAN/modelzoo_level.txt index 9e95396651cc4382fe60ee1ee053674f527a448c..27e6c78b37535fe4f5a17029546fe257ad164d34 100644 --- a/ACL_PyTorch/contrib/cv/gan/DCGAN/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/gan/DCGAN/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:POK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/GAN/GAN_pth2onnx.py b/ACL_PyTorch/contrib/cv/gan/GAN/GAN_pth2onnx.py index 790cd62c5e5f621069ffa8594b5e6497a01f550d..457cb19bd697496e8d19b0d135bfbfb04c001c63 100644 --- a/ACL_PyTorch/contrib/cv/gan/GAN/GAN_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/gan/GAN/GAN_pth2onnx.py @@ -1,54 +1,54 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -from models import Generator -from torch.autograd import Variable -import argparse -import numpy as np -from collections import OrderedDict - -def proc_nodes_module(checkpoint): - new_state_dict = OrderedDict() - for k, v in checkpoint.items(): - if "module." in k: - name = k.replace("module.", "") - else: - name = k - new_state_dict[name] = v - return new_state_dict - -def pth2onnx(input_file, output_file): - generator = Generator() - checkpoint = torch.load(input_file, map_location=torch.device('cpu')) - checkpoint = proc_nodes_module(checkpoint) - generator.load_state_dict(checkpoint) - input_names = ["Z"] - output_names = ["generateimg"] - dynamic_axes = {'Z': {0: '-1'}, 'generateimg': {0: '-1'}} - - Tensor = torch.FloatTensor - dummy_input = Variable(Tensor(np.random.normal(0, 1, (16, 100)))) - torch.onnx.export(generator, dummy_input, output_file, input_names = input_names, - output_names = output_names,dynamic_axes = dynamic_axes,opset_version=11, verbose=True) - - - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument('--input_file', type=str, required=True) - parser.add_argument('--output_file', type=str, required=True) - args = parser.parse_args() - - pth2onnx(args.input_file, args.output_file) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +from models import Generator +from torch.autograd import Variable +import argparse +import numpy as np +from collections import OrderedDict + +def proc_nodes_module(checkpoint): + new_state_dict = OrderedDict() + for k, v in checkpoint.items(): + if "module." in k: + name = k.replace("module.", "") + else: + name = k + new_state_dict[name] = v + return new_state_dict + +def pth2onnx(input_file, output_file): + generator = Generator() + checkpoint = torch.load(input_file, map_location=torch.device('cpu')) + checkpoint = proc_nodes_module(checkpoint) + generator.load_state_dict(checkpoint) + input_names = ["Z"] + output_names = ["generateimg"] + dynamic_axes = {'Z': {0: '-1'}, 'generateimg': {0: '-1'}} + + Tensor = torch.FloatTensor + dummy_input = Variable(Tensor(np.random.normal(0, 1, (16, 100)))) + torch.onnx.export(generator, dummy_input, output_file, input_names = input_names, + output_names = output_names,dynamic_axes = dynamic_axes,opset_version=11, verbose=True) + + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--input_file', type=str, required=True) + parser.add_argument('--output_file', type=str, required=True) + args = parser.parse_args() + + pth2onnx(args.input_file, args.output_file) diff --git a/ACL_PyTorch/contrib/cv/gan/GAN/GAN_testdata.py b/ACL_PyTorch/contrib/cv/gan/GAN/GAN_testdata.py index 6b33ec6b2daf0377fa081f118b38b2fd8e7e9638..86b6d85bdfdb126480cc870ef0d41ca5e62249a9 100644 --- a/ACL_PyTorch/contrib/cv/gan/GAN/GAN_testdata.py +++ b/ACL_PyTorch/contrib/cv/gan/GAN/GAN_testdata.py @@ -1,58 +1,58 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import torch -from models import Generator -from torch.autograd import Variable -from torchvision.utils import save_image -import numpy as np -import argparse - -def main(args): - os.makedirs(args.online_path, exist_ok=True) - os.makedirs(args.offline_path, exist_ok=True) - generator = Generator() - pre = torch.load(args.pth_path,map_location='cpu') - - from collections import OrderedDict - - new_state_dict = OrderedDict() - for k, v in pre.items(): - name = k.replace("module.", "") - new_state_dict[name] = v - # load params - generator.load_state_dict(new_state_dict) - Tensor = torch.FloatTensor - for i in range(args.iters): - z = Variable(Tensor(np.random.normal(0, 1, (args.batch_size,100)))) - - if args.batch_size != 1: - gen = generator(z) - save_image(gen, args.online_path+"/%d.jpg" % i,normalize=True) - - z = z.numpy() - z.tofile(args.offline_path+"/%d.bin"% i) - - print("done!") - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument('--online_path', type=str, required=True) - parser.add_argument('--offline_path', type=str, required=True) - parser.add_argument('--pth_path', type=str, required=True) - parser.add_argument('--iters', type=int, default=1) - parser.add_argument('--batch_size', type=int, default=1) - args = parser.parse_args() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import torch +from models import Generator +from torch.autograd import Variable +from torchvision.utils import save_image +import numpy as np +import argparse + +def main(args): + os.makedirs(args.online_path, exist_ok=True) + os.makedirs(args.offline_path, exist_ok=True) + generator = Generator() + pre = torch.load(args.pth_path,map_location='cpu') + + from collections import OrderedDict + + new_state_dict = OrderedDict() + for k, v in pre.items(): + name = k.replace("module.", "") + new_state_dict[name] = v + # load params + generator.load_state_dict(new_state_dict) + Tensor = torch.FloatTensor + for i in range(args.iters): + z = Variable(Tensor(np.random.normal(0, 1, (args.batch_size,100)))) + + if args.batch_size != 1: + gen = generator(z) + save_image(gen, args.online_path+"/%d.jpg" % i,normalize=True) + + z = z.numpy() + z.tofile(args.offline_path+"/%d.bin"% i) + + print("done!") + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--online_path', type=str, required=True) + parser.add_argument('--offline_path', type=str, required=True) + parser.add_argument('--pth_path', type=str, required=True) + parser.add_argument('--iters', type=int, default=1) + parser.add_argument('--batch_size', type=int, default=1) + args = parser.parse_args() main(args) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/GAN/GAN_txt2jpg.py b/ACL_PyTorch/contrib/cv/gan/GAN/GAN_txt2jpg.py index 24ce1e8adbe15f660124cd57c28f7e689e0c2bce..a345e5fbf34bafc0a70653076261daed443fc9c9 100644 --- a/ACL_PyTorch/contrib/cv/gan/GAN/GAN_txt2jpg.py +++ b/ACL_PyTorch/contrib/cv/gan/GAN/GAN_txt2jpg.py @@ -1,50 +1,50 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import torch -import numpy as np -import os -from torchvision.utils import save_image - -def read_bin(filename): - - data = np.fromfile(filename,dtype=np.float32) - data = torch.Tensor(data) - data = data.view(-1,1,28,28) - return data - -def main(args): - old_path = os.listdir(args.txt_path) - os.makedirs(args.infer_results_path, exist_ok=True) - old_path.sort(reverse=True) - new_path = args.txt_path+'/'+old_path[0] - files = os.listdir(new_path) - for file in files: - filename = new_path + '/' + file - data = read_bin(filename) - if file[1]!='_': - save_path = args.infer_results_path + '/' + file[:2] + ".jpg" - else: - save_path = args.infer_results_path + '/' + file[0] + ".jpg" - - save_image(data, save_path,normalize=True) - print("done!") - -if __name__=='__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--txt_path', type=str, required=True) - parser.add_argument('--infer_results_path', type=str, required=True) - args = parser.parse_args() - main(args) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import torch +import numpy as np +import os +from torchvision.utils import save_image + +def read_bin(filename): + + data = np.fromfile(filename,dtype=np.float32) + data = torch.Tensor(data) + data = data.view(-1,1,28,28) + return data + +def main(args): + old_path = os.listdir(args.txt_path) + os.makedirs(args.infer_results_path, exist_ok=True) + old_path.sort(reverse=True) + new_path = args.txt_path+'/'+old_path[0] + files = os.listdir(new_path) + for file in files: + filename = new_path + '/' + file + data = read_bin(filename) + if file[1]!='_': + save_path = args.infer_results_path + '/' + file[:2] + ".jpg" + else: + save_path = args.infer_results_path + '/' + file[0] + ".jpg" + + save_image(data, save_path,normalize=True) + print("done!") + +if __name__=='__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--txt_path', type=str, required=True) + parser.add_argument('--infer_results_path', type=str, required=True) + args = parser.parse_args() + main(args) diff --git a/ACL_PyTorch/contrib/cv/gan/GAN/LICENSE b/ACL_PyTorch/contrib/cv/gan/GAN/LICENSE index 29f81d812f3e768fa89638d1f72920dbfd1413a8..261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64 100644 --- a/ACL_PyTorch/contrib/cv/gan/GAN/LICENSE +++ b/ACL_PyTorch/contrib/cv/gan/GAN/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ACL_PyTorch/contrib/cv/gan/GAN/README.md b/ACL_PyTorch/contrib/cv/gan/GAN/README.md index db252fc46044ddf65819fd20896f31995970b10a..0d61509917c82c566e0433a3f6a309b0715a276d 100644 --- a/ACL_PyTorch/contrib/cv/gan/GAN/README.md +++ b/ACL_PyTorch/contrib/cv/gan/GAN/README.md @@ -1,222 +1,222 @@ -## GAN Onnx模型PyTorch端到端推理指导 - -### 1 模型概述 - -#### 1.1 论文地址 - -[GAN论文](https://arxiv.org/abs/1406.2661) - - - -#### 1.2 代码地址 - -[GAN代码](https://github.com/eriklindernoren/PyTorch-GAN/blob/master/implementations/gan/gan.py) - - - -### 2 环境说明 - -#### 2.1 深度学习框架 - -``` -CANN 5.0.2 -pytorch = 1.6.0 -torchvision = 0.6.0 -onnx = 1.8.0 -``` - - - -#### 2.2 python第三方库 - -``` -numpy == 1.21.1 -``` - -**说明:** - -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - - - -### 3 模型转换 - -#### 3.1 pth转onnx模型 - -1. 下载pth权重文件 - - [GAN预训练pth权重文件](https://wws.lanzoui.com/ikXFJvljkab) - 解压至当前工作目录 - - - - -2. 编写pth2onnx脚本GAN_pth2onnx.py - - -3. 执行pth2onnx脚本,生成onnx模型文件 - - ```py - python3.7 GAN_pth2onnx.py --input_file=generator_8p_0.0008_128.pth --output_file=GAN.onnx - ``` - - - -#### 3.2 onnx转om模型 - -1. 设置环境变量 - - ``` - source set_env.sh - ``` - -2. 使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 - - ``` - atc --model=GAN.onnx --framework=5 --output=GAN_bs1 --input_format=NCHW --input_shape="Z:1,100" --log=error --soc_version=Ascend310 - ``` - 通过调节input_shape的第一个参数为16,64可以生成bs为16,64的om文件 - -### 4 数据准备 - -#### 4.1 生成输入数据并保存为.bin文件 -由于源代码中未提供测试数据,这里调用GAN_testdata.py来生成测试数据,保存在/vectors文件夹下 - ``` - python3.7 GAN_testdata.py --online_path=images --offline_path=vectors --pth_path=generator_8p_0.0008_128.pth --iters 100 --batch_size 64 - ``` - - - -### 5 离线推理 - -#### 5.1 msame工具概述 - -msame工具为华为自研的模型推理工具,输入.om模型和模型所需要的输入bin文件,输出模型的输出数据文件,支持多次推理(指对同一输入数据进行推理)。 - -模型必须是通过atc工具转换的om模型,输入bin文件需要符合模型的输入要求(支持模型多输入)。 - - - -#### 5.2 离线推理 - -``` -./msame --model "GAN_bs64.om" --input "./vectors" --output "out" -``` - -输出结果默认保存在当前目录out/下,为保存模型输入tensor数据的txt文件 - - - -### 6 精度对比 - -#### 6.1 离线推理精度 - -调用GAN_txt2jpg.py来进行后处理 - -```python -python3.7 GAN_txt2jpg.py --txt_path=out --infer_results_path=genimg -``` - -详细的结果输出在genimg文件夹中,可以和images文件夹下的在线推理结果做对比,看得出离线推理生成的图片质量更好 - - -#### 6.2 精度对比 - -源码中未有精度对比部分,这里以两种不同的方式对同一输入的输出结果对比为准。 - - - -### 7 性能对比 - -#### 7.1 npu性能数据 -运行下列命令 - -``` -source env.sh -atc --model=GAN.onnx --framework=5 --output=GAN_bs1 --input_format=NCHW --input_shape="Z:1,100" --log=error --soc_version=Ascend310 -``` - -得到size为1*100的om模型 - - - -**msame工具在整个数据集上推理获得性能数据** - -batch1的性能 - -``` -Inference average time : 0.43 ms -Inference average time without first time: 0.43 ms -``` - -Inference average time : 0.43 ms,1000/(0.43/4)既是batch1 310单卡吞吐率 - -bs1 310单卡吞吐率:9302.326fps - -batch16的性能 - -``` -Inference average time : 0.47 ms -Inference average time without first time: 0.47 ms -``` - -Inference average time : 0.51 ms,1000/(0.45/64)既是batch16 310单卡吞吐率 - -bs16 310单卡吞吐率:136170.213fps - -#### 7.2 T4性能数据 - -在装有T4卡的服务器上使用TensorRT测试gpu性能,测试过程请确保卡没有运行其他任务。 - -batch1性能: - -``` -./trtexec --onnx=GAN.onnx --fp16 --shapes=image:1x100 -``` - -gpu T4是4个device并行执行的结果,mean是时延(tensorrt的时延是batch个数据的推理时间),即吞吐率的倒数乘以batch - -``` -[11/11/2021-13:11:22] [I] min: 0.048584 ms -[11/11/2021-13:11:22] [I] max: 4.11572 ms -[11/11/2021-13:11:22] [I] median: 0.0817871 ms -[11/11/2021-13:11:22] [I] GPU Compute -[11/11/2021-13:11:22] [I] min: 0.048584 ms -[11/11/2021-13:11:22] [I] max: 4.13281 ms -[11/11/2021-13:11:22] [I] mean: 0.0826078 ms -[11/11/2021-13:11:22] [I] median: 0.0856934 ms -[11/11/2021-13:11:22] [I] percentile: 0.118164 ms at 99% -[11/11/2021-13:11:22] [I] total compute time: 1.82233 s -``` - -batch1 t4单卡吞吐率:1000/(0.0826078/1)=12105.394fps - -batch16性能: -``` -./trtexec --onnx=GAN.onnx --fp16 --shapes=image:1x100 -``` - -``` -[11/11/2021-13:18:27] [I] min: 0.0540771 ms -[11/11/2021-13:18:27] [I] max: 5.42334 ms -[11/11/2021-13:18:27] [I] median: 0.0800781 ms -[11/11/2021-13:18:27] [I] GPU Compute -[11/11/2021-13:18:27] [I] min: 0.0499878 ms -[11/11/2021-13:18:27] [I] max: 5.44055 ms -[11/11/2021-13:18:27] [I] mean: 0.0887248 ms -[11/11/2021-13:18:27] [I] median: 0.0830078 ms -[11/11/2021-13:18:27] [I] percentile: 0.145508 ms at 99% -[11/11/2021-13:18:27] [I] total compute time: 1.91122 s -``` - -batch16 t4单卡吞吐率:1000/(0.0887248/1)=180332.895fps - -#### 7.3 性能对比 - -batch1:8510.638fps > 12105.394×0.5 fps - -batch16:125490.196fps > 180332.895×0.5 fps - +## GAN Onnx模型PyTorch端到端推理指导 + +### 1 模型概述 + +#### 1.1 论文地址 + +[GAN论文](https://arxiv.org/abs/1406.2661) + + + +#### 1.2 代码地址 + +[GAN代码](https://github.com/eriklindernoren/PyTorch-GAN/blob/master/implementations/gan/gan.py) + + + +### 2 环境说明 + +#### 2.1 深度学习框架 + +``` +CANN 5.0.2 +pytorch = 1.6.0 +torchvision = 0.6.0 +onnx = 1.8.0 +``` + + + +#### 2.2 python第三方库 + +``` +numpy == 1.21.1 +``` + +**说明:** + +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + + + +### 3 模型转换 + +#### 3.1 pth转onnx模型 + +1. 下载pth权重文件 + + [GAN预训练pth权重文件](https://wws.lanzoui.com/ikXFJvljkab) + 解压至当前工作目录 + + + + +2. 编写pth2onnx脚本GAN_pth2onnx.py + + +3. 执行pth2onnx脚本,生成onnx模型文件 + + ```py + python3.7 GAN_pth2onnx.py --input_file=generator_8p_0.0008_128.pth --output_file=GAN.onnx + ``` + + + +#### 3.2 onnx转om模型 + +1. 设置环境变量 + + ``` + source set_env.sh + ``` + +2. 使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.1 开发辅助工具指南 (推理) 01 + + ``` + atc --model=GAN.onnx --framework=5 --output=GAN_bs1 --input_format=NCHW --input_shape="Z:1,100" --log=error --soc_version=Ascend310 + ``` + 通过调节input_shape的第一个参数为16,64可以生成bs为16,64的om文件 + +### 4 数据准备 + +#### 4.1 生成输入数据并保存为.bin文件 +由于源代码中未提供测试数据,这里调用GAN_testdata.py来生成测试数据,保存在/vectors文件夹下 + ``` + python3.7 GAN_testdata.py --online_path=images --offline_path=vectors --pth_path=generator_8p_0.0008_128.pth --iters 100 --batch_size 64 + ``` + + + +### 5 离线推理 + +#### 5.1 msame工具概述 + +msame工具为华为自研的模型推理工具,输入.om模型和模型所需要的输入bin文件,输出模型的输出数据文件,支持多次推理(指对同一输入数据进行推理)。 + +模型必须是通过atc工具转换的om模型,输入bin文件需要符合模型的输入要求(支持模型多输入)。 + + + +#### 5.2 离线推理 + +``` +./msame --model "GAN_bs64.om" --input "./vectors" --output "out" +``` + +输出结果默认保存在当前目录out/下,为保存模型输入tensor数据的txt文件 + + + +### 6 精度对比 + +#### 6.1 离线推理精度 + +调用GAN_txt2jpg.py来进行后处理 + +```python +python3.7 GAN_txt2jpg.py --txt_path=out --infer_results_path=genimg +``` + +详细的结果输出在genimg文件夹中,可以和images文件夹下的在线推理结果做对比,看得出离线推理生成的图片质量更好 + + +#### 6.2 精度对比 + +源码中未有精度对比部分,这里以两种不同的方式对同一输入的输出结果对比为准。 + + + +### 7 性能对比 + +#### 7.1 npu性能数据 +运行下列命令 + +``` +source env.sh +atc --model=GAN.onnx --framework=5 --output=GAN_bs1 --input_format=NCHW --input_shape="Z:1,100" --log=error --soc_version=Ascend310 +``` + +得到size为1*100的om模型 + + + +**msame工具在整个数据集上推理获得性能数据** + +batch1的性能 + +``` +Inference average time : 0.43 ms +Inference average time without first time: 0.43 ms +``` + +Inference average time : 0.43 ms,1000/(0.43/4)既是batch1 310单卡吞吐率 + +bs1 310单卡吞吐率:9302.326fps + +batch16的性能 + +``` +Inference average time : 0.47 ms +Inference average time without first time: 0.47 ms +``` + +Inference average time : 0.51 ms,1000/(0.45/64)既是batch16 310单卡吞吐率 + +bs16 310单卡吞吐率:136170.213fps + +#### 7.2 T4性能数据 + +在装有T4卡的服务器上使用TensorRT测试gpu性能,测试过程请确保卡没有运行其他任务。 + +batch1性能: + +``` +./trtexec --onnx=GAN.onnx --fp16 --shapes=image:1x100 +``` + +gpu T4是4个device并行执行的结果,mean是时延(tensorrt的时延是batch个数据的推理时间),即吞吐率的倒数乘以batch + +``` +[11/11/2021-13:11:22] [I] min: 0.048584 ms +[11/11/2021-13:11:22] [I] max: 4.11572 ms +[11/11/2021-13:11:22] [I] median: 0.0817871 ms +[11/11/2021-13:11:22] [I] GPU Compute +[11/11/2021-13:11:22] [I] min: 0.048584 ms +[11/11/2021-13:11:22] [I] max: 4.13281 ms +[11/11/2021-13:11:22] [I] mean: 0.0826078 ms +[11/11/2021-13:11:22] [I] median: 0.0856934 ms +[11/11/2021-13:11:22] [I] percentile: 0.118164 ms at 99% +[11/11/2021-13:11:22] [I] total compute time: 1.82233 s +``` + +batch1 t4单卡吞吐率:1000/(0.0826078/1)=12105.394fps + +batch16性能: +``` +./trtexec --onnx=GAN.onnx --fp16 --shapes=image:1x100 +``` + +``` +[11/11/2021-13:18:27] [I] min: 0.0540771 ms +[11/11/2021-13:18:27] [I] max: 5.42334 ms +[11/11/2021-13:18:27] [I] median: 0.0800781 ms +[11/11/2021-13:18:27] [I] GPU Compute +[11/11/2021-13:18:27] [I] min: 0.0499878 ms +[11/11/2021-13:18:27] [I] max: 5.44055 ms +[11/11/2021-13:18:27] [I] mean: 0.0887248 ms +[11/11/2021-13:18:27] [I] median: 0.0830078 ms +[11/11/2021-13:18:27] [I] percentile: 0.145508 ms at 99% +[11/11/2021-13:18:27] [I] total compute time: 1.91122 s +``` + +batch16 t4单卡吞吐率:1000/(0.0887248/1)=180332.895fps + +#### 7.3 性能对比 + +batch1:8510.638fps > 12105.394×0.5 fps + +batch16:125490.196fps > 180332.895×0.5 fps + 性能达到基准线一半 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/GAN/models.py b/ACL_PyTorch/contrib/cv/gan/GAN/models.py index 54b22a3456bbc39407d28cb98138e0b8ea4c47cd..27da51bc8253f9a498ebb4c04c2f9ab017d16a08 100644 --- a/ACL_PyTorch/contrib/cv/gan/GAN/models.py +++ b/ACL_PyTorch/contrib/cv/gan/GAN/models.py @@ -1,67 +1,67 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch.nn as nn -import numpy as np - -channels = 1 -image_size = 28 -img_shape =(channels,image_size,image_size) -latent_dim = 100 - -class Generator(nn.Module): - def __init__(self): - super(Generator, self).__init__() - - def block(in_feat, out_feat, normalize=True): - layers = [nn.Linear(in_feat, out_feat)] - if normalize: - layers.append(nn.BatchNorm1d(out_feat, 0.8)) - layers.append(nn.LeakyReLU(0.2, inplace=True)) - return layers - - self.model = nn.Sequential( - *block(latent_dim, 128, normalize=False), - *block(128, 256), - *block(256, 512), - *block(512, 1024), - nn.Linear(1024, int(np.prod(img_shape))), - nn.Tanh() - ) - - def forward(self, z): - img = self.model(z) - img = img.view(img.size(0), *img_shape) - return img - -class Discriminator(nn.Module): - def __init__(self): - super(Discriminator, self).__init__() - - self.model = nn.Sequential( - nn.Linear(int(np.prod(img_shape)), 512), - nn.LeakyReLU(0.2, inplace=True), - nn.Linear(512, 256), - nn.LeakyReLU(0.2, inplace=True), - nn.Linear(256, 1), - nn.Sigmoid(), - ) - - def forward(self, img): - img_flat = img.view(img.size(0), -1) - validity = self.model(img_flat) - - return validity - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch.nn as nn +import numpy as np + +channels = 1 +image_size = 28 +img_shape =(channels,image_size,image_size) +latent_dim = 100 + +class Generator(nn.Module): + def __init__(self): + super(Generator, self).__init__() + + def block(in_feat, out_feat, normalize=True): + layers = [nn.Linear(in_feat, out_feat)] + if normalize: + layers.append(nn.BatchNorm1d(out_feat, 0.8)) + layers.append(nn.LeakyReLU(0.2, inplace=True)) + return layers + + self.model = nn.Sequential( + *block(latent_dim, 128, normalize=False), + *block(128, 256), + *block(256, 512), + *block(512, 1024), + nn.Linear(1024, int(np.prod(img_shape))), + nn.Tanh() + ) + + def forward(self, z): + img = self.model(z) + img = img.view(img.size(0), *img_shape) + return img + +class Discriminator(nn.Module): + def __init__(self): + super(Discriminator, self).__init__() + + self.model = nn.Sequential( + nn.Linear(int(np.prod(img_shape)), 512), + nn.LeakyReLU(0.2, inplace=True), + nn.Linear(512, 256), + nn.LeakyReLU(0.2, inplace=True), + nn.Linear(256, 1), + nn.Sigmoid(), + ) + + def forward(self, img): + img_flat = img.view(img.size(0), -1) + validity = self.model(img_flat) + + return validity + + diff --git a/ACL_PyTorch/contrib/cv/gan/GAN/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/gan/GAN/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/ACL_PyTorch/contrib/cv/gan/GAN/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/gan/GAN/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/GAN/requirements.txt b/ACL_PyTorch/contrib/cv/gan/GAN/requirements.txt index 2b2fefefa7e4adf1644dcfecc8ad2aeaef1b4656..63dcbcfad8c69ebc898a4dad8759901abf26fd31 100644 --- a/ACL_PyTorch/contrib/cv/gan/GAN/requirements.txt +++ b/ACL_PyTorch/contrib/cv/gan/GAN/requirements.txt @@ -1,4 +1,4 @@ -torch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.8.0 -numpy == 1.21.1 +torch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.8.0 +numpy == 1.21.1 diff --git a/ACL_PyTorch/contrib/cv/gan/GAN/test/README.md b/ACL_PyTorch/contrib/cv/gan/GAN/test/README.md index d86591ab67273f688a1c9f2d1d351b356d8d3d0f..85ca35df0486c6a24fac7731f32ae7d04d839e93 100644 --- a/ACL_PyTorch/contrib/cv/gan/GAN/test/README.md +++ b/ACL_PyTorch/contrib/cv/gan/GAN/test/README.md @@ -1,38 +1,38 @@ -## GAN模型PyTorch离线推理指导 - -### 1 环境准备 - -1. 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - - ```python - pip3.7 install -r requirements.txt - ``` - -2. 数据集获取 - - 开源代码仓[点此进入](https://github.com/eriklindernoren/PyTorch-GAN/blob/master/implementations/gan/gan.py)没有提供模型测试相关的数据集和代码,这里采用自己设置的随机张量来测试模型的生成精度。 - - -3. 获取msame工具 - - 将编译好的msame工具放到当前目录 - -### 2 离线推理 - -310上执行,执行时使用npu-smi info查看设备状态,确保device空闲 - -``` -bash test/pth2om.sh -bash test/eval_acc.sh -bash test/eval_bs1_perf.sh -bash test/eval_bs16_perf.sh -``` - - - -**评测结果:** - -| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| :-----: | :---------: | :-------------: | :--------: | :-------: | -| GAN bs1 | - | - | fps:12105.394 | fps: 9302.326| -| GAN bs16 |- | - | fps:180332.895|fps: 136170.213| +## GAN模型PyTorch离线推理指导 + +### 1 环境准备 + +1. 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + + ```python + pip3.7 install -r requirements.txt + ``` + +2. 数据集获取 + + 开源代码仓[点此进入](https://github.com/eriklindernoren/PyTorch-GAN/blob/master/implementations/gan/gan.py)没有提供模型测试相关的数据集和代码,这里采用自己设置的随机张量来测试模型的生成精度。 + + +3. 获取msame工具 + + 将编译好的msame工具放到当前目录 + +### 2 离线推理 + +310上执行,执行时使用npu-smi info查看设备状态,确保device空闲 + +``` +bash test/pth2om.sh +bash test/eval_acc.sh +bash test/eval_bs1_perf.sh +bash test/eval_bs16_perf.sh +``` + + + +**评测结果:** + +| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| :-----: | :---------: | :-------------: | :--------: | :-------: | +| GAN bs1 | - | - | fps:12105.394 | fps: 9302.326| +| GAN bs16 |- | - | fps:180332.895|fps: 136170.213| diff --git a/ACL_PyTorch/contrib/cv/gan/Pix2Pix/README.md b/ACL_PyTorch/contrib/cv/gan/Pix2Pix/README.md index 7708fbc2e51018948b705daa8869f6f637080465..e2a449f73c961ecb507bf0db2581e8dc54eaf1ef 100644 --- a/ACL_PyTorch/contrib/cv/gan/Pix2Pix/README.md +++ b/ACL_PyTorch/contrib/cv/gan/Pix2Pix/README.md @@ -1,35 +1,35 @@ -# Pix2Pix - - -# 精度性能 - - | 模型 | 性能基准 | 310性能 | - | :------: | :------: | :------: | - | fsaf bs1 | 556 | 402 | - | fsaf bs16| 359 | 464 | -精度直接看生成效果 - - -# 自验报告 - - # 第1次验收测试 - # 验收结果 OK - # 验收环境: A + K / CANN 5.0.2 - - - # pth是否能正确转换为om - bash ./test/pth2om.sh --pth_path=./checkpoints/facades_label2photo_pretrained - # 验收结果: OK - # 备注: 成功生成om,无运行报错,报错日志xx 等 - - # 精度数据是否达标(需要显示官网pth精度与om模型的精度) - # npu性能数据(确保device空闲时测试,如果模型支持多batch,测试bs1与bs16,否则只测试bs1,性能数据以单卡吞吐率为标准) - bash ./test/eval_acc_perf.sh --datasets_path='./datasets/facades' - # 验收结果: 是 - # 备注: 验收310测试性能bs1:402FPS bs16:464FPS;无运行报错,报错日志xx 等 - - - # 310性能是否超过基准: 是 - bs1:310=402/556=0.723倍基准 - bs16:310=464/359=1.292倍基准 - +# Pix2Pix + + +# 精度性能 + + | 模型 | 性能基准 | 310性能 | + | :------: | :------: | :------: | + | fsaf bs1 | 556 | 402 | + | fsaf bs16| 359 | 464 | +精度直接看生成效果 + + +# 自验报告 + + # 第1次验收测试 + # 验收结果 OK + # 验收环境: A + K / CANN 5.0.2 + + + # pth是否能正确转换为om + bash ./test/pth2om.sh --pth_path=./checkpoints/facades_label2photo_pretrained + # 验收结果: OK + # 备注: 成功生成om,无运行报错,报错日志xx 等 + + # 精度数据是否达标(需要显示官网pth精度与om模型的精度) + # npu性能数据(确保device空闲时测试,如果模型支持多batch,测试bs1与bs16,否则只测试bs1,性能数据以单卡吞吐率为标准) + bash ./test/eval_acc_perf.sh --datasets_path='./datasets/facades' + # 验收结果: 是 + # 备注: 验收310测试性能bs1:402FPS bs16:464FPS;无运行报错,报错日志xx 等 + + + # 310性能是否超过基准: 是 + bs1:310=402/556=0.723倍基准 + bs16:310=464/359=1.292倍基准 + diff --git a/ACL_PyTorch/contrib/cv/gan/Pix2Pix/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/gan/Pix2Pix/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/ACL_PyTorch/contrib/cv/gan/Pix2Pix/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/gan/Pix2Pix/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/Pix2Pix/precision.py b/ACL_PyTorch/contrib/cv/gan/Pix2Pix/precision.py index c14e8e8abc80d21f8af8667757ddafbdc0e3623f..99dc5002230f276cde25dc3bf83c514a26bb4c6e 100644 --- a/ACL_PyTorch/contrib/cv/gan/Pix2Pix/precision.py +++ b/ACL_PyTorch/contrib/cv/gan/Pix2Pix/precision.py @@ -1,198 +1,198 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Copyright (c) Soumith Chintala 2016, -# All rights reserved -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -*- coding: utf-8 -*- -"""用于精度比对 -""" - -import torch -import torch.nn as nn -import torchvision -import apex -from apex import amp -import copy -from models import networks - -##### 需自行改写部分 start ##### -# 获得模型 -def get_model(): - model = networks.define_G(3, 3, 64, 'unet_256', 'instance', - True, 'normal', 0.02, '[0]') - # model = networks.define_D(6, 64, 'basic', - # 3, 'instance','normal', 0.02, '[0]') - # 用于避免BN或者Dropout带来的影响,如果遇到无法evalbackward的现象,请注掉该行 - # model.eval() - - return model - -# 获得输入tensor -input_tensor = torch.randn(1, 3, 256, 256) -# input_tensor = torch.randn(1, 6, 256, 256) - -# 设置npu_device -npu_device = 'npu:0' - -# 设置amp -AMP_MODE = True - -# 设置NPU prof 文件输出 -NPU_PROF = True - -##### 需自行改写部分 end ##### - -def cri_func(x): - base_func = nn.CrossEntropyLoss() - shape_list = x.shape - N = shape_list[0] - R = 1 - if len(shape_list) > 1: - for r in shape_list[1:]: - R *= r - T = torch.randint(0,R, size=(N,)).to(x.device) - if str(T.device).startswith('npu'): - T = T.int() - return base_func(x.reshape(N, -1), T) - -# 设置hook -def hook_func(name, save_dict, module): - def hook_function(module, inputs, outputs): - inputs_key = name + '_inputs' - idx = 0 - while inputs_key in save_dict: - inputs_key = inputs_key.split('-')[0] + '-%d'%idx - idx +=1 - save_dict[inputs_key] = inputs - - outputs_key = name + '_outputs' - idx = 0 - while outputs_key in save_dict: - outputs_key = outputs_key.split('-')[0] + '-%d'%idx - idx +=1 - save_dict[outputs_key] = outputs - return hook_function - -##### CPU ##### -# CPU固定输入和权重 -model = get_model() -optimizer = torch.optim.SGD(model.parameters(), 0.1) -state_dict = copy.deepcopy(model.state_dict()) - -# CPU注册hook,cpu_dict用于存储对比对象 -cpu_dict = {} -for name, module in model.named_modules(): - module.register_forward_hook(hook_func('[forward]:' + name, cpu_dict, module)) - module.register_backward_hook(hook_func('[backward]:' + name, cpu_dict, module)) - -# CPU运行正反向,获取正反向每个module的输入输出和所有参数的grad -out = model(input_tensor) -loss = cri_func(out) -optimizer.zero_grad() -loss.backward() -optimizer.step() -for name, param in model.named_parameters(): - cpu_dict["[grad]:" + name] = param.grad - -##### NPU ##### -# 重新定义模型,清理模型状态,并加装权重,保持初始化一致 -model = get_model() -optimizer = torch.optim.SGD(model.parameters(), 0.1) -model.load_state_dict(state_dict) - -# NPU注册hook,npu_dict用于存储对比对象 -npu_dict = {} -for name, module in model.named_modules(): - module.register_forward_hook(hook_func('[forward]:' + name, npu_dict, module)) - module.register_backward_hook(hook_func('[backward]:' + name, npu_dict, module)) - -# 将model和input_tensor放到npu -torch.npu.set_device(npu_device) -model = model.npu() -input_tensor = input_tensor.npu() - -# amp可选项,不适用请注释 -if AMP_MODE: - optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), 0.1) - model, optimizer = amp.initialize(model, optimizer, opt_level='O2', loss_scale=1.0, combine_grad=True) - -# NPU运行正反向,获取正反向每个module的输入输出和所有参数的grad -out = model(input_tensor) -loss = cri_func(out) -optimizer.zero_grad() -if AMP_MODE: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() -else: - loss.backward() -optimizer.step() -for name, param in model.named_parameters(): - npu_dict["[grad]:" + name] = param.grad - - -##### ComPare ##### -# 递归得到对比值 -def compare(x1, x2, prefix=''): - if isinstance(x1, tuple): - if x1: - for idx in range(len(x1)): - try: - compare(x1[idx], x2[idx], prefix=prefix + '.%d' % idx) - except Exception as e: - # print(str(e)) - print(prefix, 'failed.') - elif isinstance(x1, torch.Tensor) and isinstance(x2, torch.Tensor): - try: - l1_error = (x1.half().float() - x2.cpu()).abs().mean() - rel_error = l1_error / (x1.abs().mean()) - print(prefix, 'l1_error: ', l1_error, 'rel_error', rel_error) - if l1_error * rel_error > 10 : - print('\n###\n',prefix, 'should checked!','\n###\n') - except Exception as e: - # print(str(e)) - print(prefix, 'failed.') - -for k in cpu_dict: - compare(cpu_dict[k], npu_dict[k], prefix=k) - -# 需要profiling的时候额外输出一次 -if NPU_PROF: - with torch.autograd.profiler.profile(use_npu=True) as prof: - out = model(input_tensor) - loss = cri_func(out) - optimizer.zero_grad() - if AMP_MODE: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - prof.export_chrome_trace("netD output.prof") # "output.prof"为输出文件地址 - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Copyright (c) Soumith Chintala 2016, +# All rights reserved +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -*- coding: utf-8 -*- +"""用于精度比对 +""" + +import torch +import torch.nn as nn +import torchvision +import apex +from apex import amp +import copy +from models import networks + +##### 需自行改写部分 start ##### +# 获得模型 +def get_model(): + model = networks.define_G(3, 3, 64, 'unet_256', 'instance', + True, 'normal', 0.02, '[0]') + # model = networks.define_D(6, 64, 'basic', + # 3, 'instance','normal', 0.02, '[0]') + # 用于避免BN或者Dropout带来的影响,如果遇到无法evalbackward的现象,请注掉该行 + # model.eval() + + return model + +# 获得输入tensor +input_tensor = torch.randn(1, 3, 256, 256) +# input_tensor = torch.randn(1, 6, 256, 256) + +# 设置npu_device +npu_device = 'npu:0' + +# 设置amp +AMP_MODE = True + +# 设置NPU prof 文件输出 +NPU_PROF = True + +##### 需自行改写部分 end ##### + +def cri_func(x): + base_func = nn.CrossEntropyLoss() + shape_list = x.shape + N = shape_list[0] + R = 1 + if len(shape_list) > 1: + for r in shape_list[1:]: + R *= r + T = torch.randint(0,R, size=(N,)).to(x.device) + if str(T.device).startswith('npu'): + T = T.int() + return base_func(x.reshape(N, -1), T) + +# 设置hook +def hook_func(name, save_dict, module): + def hook_function(module, inputs, outputs): + inputs_key = name + '_inputs' + idx = 0 + while inputs_key in save_dict: + inputs_key = inputs_key.split('-')[0] + '-%d'%idx + idx +=1 + save_dict[inputs_key] = inputs + + outputs_key = name + '_outputs' + idx = 0 + while outputs_key in save_dict: + outputs_key = outputs_key.split('-')[0] + '-%d'%idx + idx +=1 + save_dict[outputs_key] = outputs + return hook_function + +##### CPU ##### +# CPU固定输入和权重 +model = get_model() +optimizer = torch.optim.SGD(model.parameters(), 0.1) +state_dict = copy.deepcopy(model.state_dict()) + +# CPU注册hook,cpu_dict用于存储对比对象 +cpu_dict = {} +for name, module in model.named_modules(): + module.register_forward_hook(hook_func('[forward]:' + name, cpu_dict, module)) + module.register_backward_hook(hook_func('[backward]:' + name, cpu_dict, module)) + +# CPU运行正反向,获取正反向每个module的输入输出和所有参数的grad +out = model(input_tensor) +loss = cri_func(out) +optimizer.zero_grad() +loss.backward() +optimizer.step() +for name, param in model.named_parameters(): + cpu_dict["[grad]:" + name] = param.grad + +##### NPU ##### +# 重新定义模型,清理模型状态,并加装权重,保持初始化一致 +model = get_model() +optimizer = torch.optim.SGD(model.parameters(), 0.1) +model.load_state_dict(state_dict) + +# NPU注册hook,npu_dict用于存储对比对象 +npu_dict = {} +for name, module in model.named_modules(): + module.register_forward_hook(hook_func('[forward]:' + name, npu_dict, module)) + module.register_backward_hook(hook_func('[backward]:' + name, npu_dict, module)) + +# 将model和input_tensor放到npu +torch.npu.set_device(npu_device) +model = model.npu() +input_tensor = input_tensor.npu() + +# amp可选项,不适用请注释 +if AMP_MODE: + optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), 0.1) + model, optimizer = amp.initialize(model, optimizer, opt_level='O2', loss_scale=1.0, combine_grad=True) + +# NPU运行正反向,获取正反向每个module的输入输出和所有参数的grad +out = model(input_tensor) +loss = cri_func(out) +optimizer.zero_grad() +if AMP_MODE: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() +else: + loss.backward() +optimizer.step() +for name, param in model.named_parameters(): + npu_dict["[grad]:" + name] = param.grad + + +##### ComPare ##### +# 递归得到对比值 +def compare(x1, x2, prefix=''): + if isinstance(x1, tuple): + if x1: + for idx in range(len(x1)): + try: + compare(x1[idx], x2[idx], prefix=prefix + '.%d' % idx) + except Exception as e: + # print(str(e)) + print(prefix, 'failed.') + elif isinstance(x1, torch.Tensor) and isinstance(x2, torch.Tensor): + try: + l1_error = (x1.half().float() - x2.cpu()).abs().mean() + rel_error = l1_error / (x1.abs().mean()) + print(prefix, 'l1_error: ', l1_error, 'rel_error', rel_error) + if l1_error * rel_error > 10 : + print('\n###\n',prefix, 'should checked!','\n###\n') + except Exception as e: + # print(str(e)) + print(prefix, 'failed.') + +for k in cpu_dict: + compare(cpu_dict[k], npu_dict[k], prefix=k) + +# 需要profiling的时候额外输出一次 +if NPU_PROF: + with torch.autograd.profiler.profile(use_npu=True) as prof: + out = model(input_tensor) + loss = cri_func(out) + optimizer.zero_grad() + if AMP_MODE: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + prof.export_chrome_trace("netD output.prof") # "output.prof"为输出文件地址 + + diff --git a/ACL_PyTorch/contrib/cv/gan/Pix2Pix/pytorch_prof.py b/ACL_PyTorch/contrib/cv/gan/Pix2Pix/pytorch_prof.py index afb06b4b978436cd03d61ba2f71e041e20d7dba7..d79a619de98089f04918148bd6f1d14c2b1eaa02 100644 --- a/ACL_PyTorch/contrib/cv/gan/Pix2Pix/pytorch_prof.py +++ b/ACL_PyTorch/contrib/cv/gan/Pix2Pix/pytorch_prof.py @@ -1,141 +1,141 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Copyright (c) Soumith Chintala 2016, -# All rights reserved -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -*- coding: utf-8 -*- -"""pytorch_prof.py -""" - -import torch -import torch.optim as optim -import torch.nn as nn -import time -import argparse -from models import networks - -def build_model(): - # 请自定义模型并加载预训练模型 - # import torchvision - # model = torchvision.models.resnet50(pretrained=True) - model = networks.define_G(3, 3, 64, 'unet_256', 'instance', - True, 'normal', 0.02, '[0]') - return model - - -def get_raw_data(): - # input_tensor = torch.randn(2, 3, 224, 224) - input_tensor = torch.randn(1, 3, 256, 256) - return input_tensor - - -def criterion(x): - base_func = nn.CrossEntropyLoss() - shape_list = x.shape - N = shape_list[0] - R = 1 - if len(shape_list) > 1: - for r in shape_list[1:]: - R *= r - T = torch.randint(0,R, size=(N,)).to(x.device) - if str(T.device).startswith('npu'): - T = T.int() - return base_func(x.reshape(N, -1), T) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='PyTorch Prof') - parser.add_argument('--device', type=str, default='cpu', - help='set which type of device used. Support cuda:0(device_id), npu:0(device_id).') - parser.add_argument('--amp', default=False, action='store_true', - help='use amp during prof') - parser.add_argument('--loss-scale', default=64.0, type=float, - help='loss scale using in amp, default 64.0, -1 means dynamic') - parser.add_argument('--opt-level', default='O2', type=str, - help='opt-level using in amp, default O2') - parser.add_argument('--FusedSGD', default=False, action='store_true', - help='use FusedSGD during prof') - - args = parser.parse_args() - - # 1.准备工作 - if args.device.startswith('cuda'): - torch.cuda.set_device(args.device) - prof_kwargs = {'use_cuda': True} - elif args.device.startswith('npu'): - torch.npu.set_device(args.device) - prof_kwargs = {'use_npu': True} - else: - prof_kwargs = {} - - # 2.构建模型 - model = build_model() - if args.FusedSGD: - from apex.optimizers import NpuFusedSGD - optimizer = NpuFusedSGD(model.parameters(), lr=0.01) - model = model.to(args.device) - if args.amp: - from apex import amp - model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, - loss_scale=None if args.loss_scale == -1 else args.loss_scale, - combine_grad=True) - else: - optimizer = optim.SGD(model.parameters(), lr=0.01) - model = model.to(args.device) - if args.amp: - from apex import amp - model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, - loss_scale=None if args.loss_scale == -1 else args.loss_scale) - - # 3.生成input - input_tensor = get_raw_data() - input_tensor = input_tensor.to(args.device) - - # 先运行一次,保证prof得到的性能是正确的 - def run(): - output_tensor = model(input_tensor) - loss = criterion(output_tensor) - optimizer.zero_grad() - if args.amp: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - return loss - for i in range(5): - start_time = time.time() - loss = run() - print('iter: %d, loss: %.2f, time: %.2f'%(i, loss, (time.time() - start_time)*1000)) - - # 4. 执行forward+profiling - with torch.autograd.profiler.profile(**prof_kwargs) as prof: - run() - print(prof.key_averages().table()) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Copyright (c) Soumith Chintala 2016, +# All rights reserved +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -*- coding: utf-8 -*- +"""pytorch_prof.py +""" + +import torch +import torch.optim as optim +import torch.nn as nn +import time +import argparse +from models import networks + +def build_model(): + # 请自定义模型并加载预训练模型 + # import torchvision + # model = torchvision.models.resnet50(pretrained=True) + model = networks.define_G(3, 3, 64, 'unet_256', 'instance', + True, 'normal', 0.02, '[0]') + return model + + +def get_raw_data(): + # input_tensor = torch.randn(2, 3, 224, 224) + input_tensor = torch.randn(1, 3, 256, 256) + return input_tensor + + +def criterion(x): + base_func = nn.CrossEntropyLoss() + shape_list = x.shape + N = shape_list[0] + R = 1 + if len(shape_list) > 1: + for r in shape_list[1:]: + R *= r + T = torch.randint(0,R, size=(N,)).to(x.device) + if str(T.device).startswith('npu'): + T = T.int() + return base_func(x.reshape(N, -1), T) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='PyTorch Prof') + parser.add_argument('--device', type=str, default='cpu', + help='set which type of device used. Support cuda:0(device_id), npu:0(device_id).') + parser.add_argument('--amp', default=False, action='store_true', + help='use amp during prof') + parser.add_argument('--loss-scale', default=64.0, type=float, + help='loss scale using in amp, default 64.0, -1 means dynamic') + parser.add_argument('--opt-level', default='O2', type=str, + help='opt-level using in amp, default O2') + parser.add_argument('--FusedSGD', default=False, action='store_true', + help='use FusedSGD during prof') + + args = parser.parse_args() + + # 1.准备工作 + if args.device.startswith('cuda'): + torch.cuda.set_device(args.device) + prof_kwargs = {'use_cuda': True} + elif args.device.startswith('npu'): + torch.npu.set_device(args.device) + prof_kwargs = {'use_npu': True} + else: + prof_kwargs = {} + + # 2.构建模型 + model = build_model() + if args.FusedSGD: + from apex.optimizers import NpuFusedSGD + optimizer = NpuFusedSGD(model.parameters(), lr=0.01) + model = model.to(args.device) + if args.amp: + from apex import amp + model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, + loss_scale=None if args.loss_scale == -1 else args.loss_scale, + combine_grad=True) + else: + optimizer = optim.SGD(model.parameters(), lr=0.01) + model = model.to(args.device) + if args.amp: + from apex import amp + model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, + loss_scale=None if args.loss_scale == -1 else args.loss_scale) + + # 3.生成input + input_tensor = get_raw_data() + input_tensor = input_tensor.to(args.device) + + # 先运行一次,保证prof得到的性能是正确的 + def run(): + output_tensor = model(input_tensor) + loss = criterion(output_tensor) + optimizer.zero_grad() + if args.amp: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + return loss + for i in range(5): + start_time = time.time() + loss = run() + print('iter: %d, loss: %.2f, time: %.2f'%(i, loss, (time.time() - start_time)*1000)) + + # 4. 执行forward+profiling + with torch.autograd.profiler.profile(**prof_kwargs) as prof: + run() + print(prof.key_averages().table()) prof.export_chrome_trace("pytorch_prof_%s.prof" % args.device) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/Pix2pixHD/datasets_deal.py b/ACL_PyTorch/contrib/cv/gan/Pix2pixHD/datasets_deal.py index 348f33470166b96df4fc37ff38e81dfcd1da9e5c..1d8b167ef25fe42959166905dece49d32bfcc27f 100644 --- a/ACL_PyTorch/contrib/cv/gan/Pix2pixHD/datasets_deal.py +++ b/ACL_PyTorch/contrib/cv/gan/Pix2pixHD/datasets_deal.py @@ -1,44 +1,44 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import glob -import shutil - -if __name__ == "__main__": - test_inst_dir = sys.argv[1] - test_label_dir = sys.argv[2] - test_original_gtfine_dir = sys.argv[3] - - if not os.path.exists(test_inst_dir): - os.mkdir(test_inst_dir) - if not os.path.exists(test_label_dir): - os.mkdir(test_label_dir) - - city_name_dir = os.listdir(test_original_gtfine_dir) - img_inst_number = 0 - img_label_number = 0 - - for city_name in city_name_dir: - temp_city_dir = os.path.join(test_original_gtfine_dir, city_name) - test_gtfine_list = glob.glob(os.path.join(temp_city_dir, "*.png")) - - for img in test_gtfine_list: - if img[-9:] == "ceIds.png": - img_inst_number += 1 - shutil.copy(img, test_inst_dir) - elif img[-9:] == "elIds.png": - img_label_number += 1 - shutil.copy(img, test_label_dir) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import glob +import shutil + +if __name__ == "__main__": + test_inst_dir = sys.argv[1] + test_label_dir = sys.argv[2] + test_original_gtfine_dir = sys.argv[3] + + if not os.path.exists(test_inst_dir): + os.mkdir(test_inst_dir) + if not os.path.exists(test_label_dir): + os.mkdir(test_label_dir) + + city_name_dir = os.listdir(test_original_gtfine_dir) + img_inst_number = 0 + img_label_number = 0 + + for city_name in city_name_dir: + temp_city_dir = os.path.join(test_original_gtfine_dir, city_name) + test_gtfine_list = glob.glob(os.path.join(temp_city_dir, "*.png")) + + for img in test_gtfine_list: + if img[-9:] == "ceIds.png": + img_inst_number += 1 + shutil.copy(img, test_inst_dir) + elif img[-9:] == "elIds.png": + img_label_number += 1 + shutil.copy(img, test_label_dir) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/StarGAN/LICENSE b/ACL_PyTorch/contrib/cv/gan/StarGAN/LICENSE index 29f81d812f3e768fa89638d1f72920dbfd1413a8..261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64 100644 --- a/ACL_PyTorch/contrib/cv/gan/StarGAN/LICENSE +++ b/ACL_PyTorch/contrib/cv/gan/StarGAN/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ACL_PyTorch/contrib/cv/gan/StarGAN/README.md b/ACL_PyTorch/contrib/cv/gan/StarGAN/README.md index 36a385956b2d7dd1006ec75aa62b61d8671c315b..f7f3a13e8fbddce3a28222f78ee81bec8ec97300 100644 --- a/ACL_PyTorch/contrib/cv/gan/StarGAN/README.md +++ b/ACL_PyTorch/contrib/cv/gan/StarGAN/README.md @@ -1,160 +1,160 @@ -## StarGAN Onnx 模型 PyTorch 端到端推理指导 - -### 1 模型概述 - -- 论文地址 - -``` -https://arxiv.org/abs/1711.09020 -``` - -- 代码地址 - -``` -https://github.com/yunjey/stargan -``` - -- 数据集地址 - -``` -wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/dataset/celeba.zip -``` - - - -### 2 环境说明 - -``` -CANN = 5.0.2 -pytorch = 1.5.0 -torchvision = 0.6.0 -onnx = 1.8.0 -numpy = 1.21.1 -``` - -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - - - -### 3 pth 转 om 模型 - -- pth 权重文件默认路径为 `./models/200000-G.pth` -- 进入根目录 `./` 执行 `./test/pth2om` 脚本,自动生成生成 onnx 模型文件和om文件 - -```py -bash ./test/pth2om.sh './models/200000-G.pth' -``` - - - -### 4 生成输入数据并保存为.bin文件 - -- 数据集默认路径为 `./celeba.zip` ,使用脚本 `unzip_dataset.sh` 解压数据集。 - -``` -bash unzip_dataset.sh -``` - -- 使用脚本 `StarGAN_pre_processing.py` 获得二进制 bin 文件和基准的图片结果。 - -``` -source ./test/env_npu.sh -python3.7 StarGAN_pre_processing.py --mode test --selected_attrs Black_Hair Blond_Hair Brown_Hair Male Young \ - --model_save_dir './models' --result_dir './result_baseline' \ - --attr_path './data/celeba/images' --celeba_image_dir './data/celeba/list_attr_celeba.txt' -``` - - - -### 5 离线推理 - -#### 5.1 msame工具概述 - -msame 工具为华为自研的模型推理工具,输入 om 模型和模型所需要的输入 bin 文件,输出模型的输出数据文件。模型必须是通过 atc 工具转换的 om 模型,输入 bin 文件需要符合模型的输入要求,且支持模型多输入。 - -``` -chmod 777 msame -``` - -#### 5.2 离线推理 - -``` -bash ./test/eval_bs1_perf.sh -bash ./test/eval_bs16_perf.sh -``` - -输出数据默认保存在根目录的 `./StarGAN_[yourBatchSize].log` 中,可以看到时延和 FPS。输出图片默认保存在当前目录 `output_[yourBatchSize]/` 下,为保存模型输入高维张量数据的 txt 文件。 - - - -### 6 精度对比 - -调用 ` StarGAN_post_processing.py` 来进行后处理,把输出的 txt 文件转换为输出图像。 - -```python -python3.7 StarGAN_post_processing.py --folder_path './output_bs1/[YYYYMMDD_HHMMSS]' --batch_size 1 -python3.7 StarGAN_post_processing.py --folder_path './output_bs16/[YYYYMMDD_HHMMSS]' --batch_size 16 -``` - -详细的结果输出在 `./output_[yourBatchSize]/jpg` 文件夹中,可以和 `result_baseline` 文件夹下的在线推理结果做对比。可以发现各个 batchsize 的离线推理生成的图片与基准基本一致。 - - - -### 7 性能对比 - -#### 7.1 NPU 310 性能数据 -``` -(310 bs1) Inference average time: 21.04 ms -(310 bs1) FPS:190.114 -``` - -根据时延和核心数,计算得到 Batchsize = 1 时单卡吞吐率 190.114 FPS - -``` -(310 bs16) Inference average time: 313.39 ms -(310 bs16) FPS:204.218 -``` - -根据时延和核心数,计算得到 Batchsize = 16 时单卡吞吐率 204.218 FPS - -#### 7.2 GPU T4 性能数据 - -``` -&&&& RUNNING TensorRT.trtexec # trtexec --onnx=StarGAN.onnx --shapes=real_img:1x3x128x128,attr:1x5 -... -[11/10/2021-07:45:57] [I] GPU Compute -[11/10/2021-07:45:57] [I] min: 4.5766 ms -[11/10/2021-07:45:57] [I] max: 8.12921 ms -[11/10/2021-07:45:57] [I] mean: 5.34373 ms -[11/10/2021-07:45:57] [I] median: 5.32825 ms -[11/10/2021-07:45:57] [I] percentile: 6.91772 ms at 99% -[11/10/2021-07:45:57] [I] total compute time: 2.93371 s -``` - -根据时延和核心数,计算得到 Batchsize = 1 时单卡吞吐率 187.135 FPS - -``` -&&&& RUNNING TensorRT.trtexec # trtexec --onnx=StarGAN.onnx --shapes=real_img:16x3x128x128,attr:16x5 -... -[11/10/2021-08:03:49] [I] GPU Compute -[11/10/2021-08:03:49] [I] min: 65.5917 ms -[11/10/2021-08:03:49] [I] max: 76.011 ms -[11/10/2021-08:03:49] [I] mean: 67.8021 ms -[11/10/2021-08:03:49] [I] median: 67.15 ms -[11/10/2021-08:03:49] [I] percentile: 76.011 ms at 99% -[11/10/2021-08:03:49] [I] total compute time: 3.1189 s -``` - -根据时延和核心数,计算得到 Batchsize = 16 时单卡吞吐率 235.980 FPS - -#### 7.3 性能对比 - -| Batch Size | 310 (FPS/Card) | T4 (FPS/Card) | 310/T4 | -| ---------- | -------------- | ------------- | -------- | -| 1 | *189.753* | *187.135* | *101.4%* | -| 4 | *201.207* | *203.666* | *98.80%* | -| 8 | *199.913* | *219.700* | *91.00%* | -| 16 | *200.986* | *235.980* | *85.17%* | - +## StarGAN Onnx 模型 PyTorch 端到端推理指导 + +### 1 模型概述 + +- 论文地址 + +``` +https://arxiv.org/abs/1711.09020 +``` + +- 代码地址 + +``` +https://github.com/yunjey/stargan +``` + +- 数据集地址 + +``` +wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/dataset/celeba.zip +``` + + + +### 2 环境说明 + +``` +CANN = 5.0.2 +pytorch = 1.5.0 +torchvision = 0.6.0 +onnx = 1.8.0 +numpy = 1.21.1 +``` + +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + + + +### 3 pth 转 om 模型 + +- pth 权重文件默认路径为 `./models/200000-G.pth` +- 进入根目录 `./` 执行 `./test/pth2om` 脚本,自动生成生成 onnx 模型文件和om文件 + +```py +bash ./test/pth2om.sh './models/200000-G.pth' +``` + + + +### 4 生成输入数据并保存为.bin文件 + +- 数据集默认路径为 `./celeba.zip` ,使用脚本 `unzip_dataset.sh` 解压数据集。 + +``` +bash unzip_dataset.sh +``` + +- 使用脚本 `StarGAN_pre_processing.py` 获得二进制 bin 文件和基准的图片结果。 + +``` +source ./test/env_npu.sh +python3.7 StarGAN_pre_processing.py --mode test --selected_attrs Black_Hair Blond_Hair Brown_Hair Male Young \ + --model_save_dir './models' --result_dir './result_baseline' \ + --attr_path './data/celeba/images' --celeba_image_dir './data/celeba/list_attr_celeba.txt' +``` + + + +### 5 离线推理 + +#### 5.1 msame工具概述 + +msame 工具为华为自研的模型推理工具,输入 om 模型和模型所需要的输入 bin 文件,输出模型的输出数据文件。模型必须是通过 atc 工具转换的 om 模型,输入 bin 文件需要符合模型的输入要求,且支持模型多输入。 + +``` +chmod 777 msame +``` + +#### 5.2 离线推理 + +``` +bash ./test/eval_bs1_perf.sh +bash ./test/eval_bs16_perf.sh +``` + +输出数据默认保存在根目录的 `./StarGAN_[yourBatchSize].log` 中,可以看到时延和 FPS。输出图片默认保存在当前目录 `output_[yourBatchSize]/` 下,为保存模型输入高维张量数据的 txt 文件。 + + + +### 6 精度对比 + +调用 ` StarGAN_post_processing.py` 来进行后处理,把输出的 txt 文件转换为输出图像。 + +```python +python3.7 StarGAN_post_processing.py --folder_path './output_bs1/[YYYYMMDD_HHMMSS]' --batch_size 1 +python3.7 StarGAN_post_processing.py --folder_path './output_bs16/[YYYYMMDD_HHMMSS]' --batch_size 16 +``` + +详细的结果输出在 `./output_[yourBatchSize]/jpg` 文件夹中,可以和 `result_baseline` 文件夹下的在线推理结果做对比。可以发现各个 batchsize 的离线推理生成的图片与基准基本一致。 + + + +### 7 性能对比 + +#### 7.1 NPU 310 性能数据 +``` +(310 bs1) Inference average time: 21.04 ms +(310 bs1) FPS:190.114 +``` + +根据时延和核心数,计算得到 Batchsize = 1 时单卡吞吐率 190.114 FPS + +``` +(310 bs16) Inference average time: 313.39 ms +(310 bs16) FPS:204.218 +``` + +根据时延和核心数,计算得到 Batchsize = 16 时单卡吞吐率 204.218 FPS + +#### 7.2 GPU T4 性能数据 + +``` +&&&& RUNNING TensorRT.trtexec # trtexec --onnx=StarGAN.onnx --shapes=real_img:1x3x128x128,attr:1x5 +... +[11/10/2021-07:45:57] [I] GPU Compute +[11/10/2021-07:45:57] [I] min: 4.5766 ms +[11/10/2021-07:45:57] [I] max: 8.12921 ms +[11/10/2021-07:45:57] [I] mean: 5.34373 ms +[11/10/2021-07:45:57] [I] median: 5.32825 ms +[11/10/2021-07:45:57] [I] percentile: 6.91772 ms at 99% +[11/10/2021-07:45:57] [I] total compute time: 2.93371 s +``` + +根据时延和核心数,计算得到 Batchsize = 1 时单卡吞吐率 187.135 FPS + +``` +&&&& RUNNING TensorRT.trtexec # trtexec --onnx=StarGAN.onnx --shapes=real_img:16x3x128x128,attr:16x5 +... +[11/10/2021-08:03:49] [I] GPU Compute +[11/10/2021-08:03:49] [I] min: 65.5917 ms +[11/10/2021-08:03:49] [I] max: 76.011 ms +[11/10/2021-08:03:49] [I] mean: 67.8021 ms +[11/10/2021-08:03:49] [I] median: 67.15 ms +[11/10/2021-08:03:49] [I] percentile: 76.011 ms at 99% +[11/10/2021-08:03:49] [I] total compute time: 3.1189 s +``` + +根据时延和核心数,计算得到 Batchsize = 16 时单卡吞吐率 235.980 FPS + +#### 7.3 性能对比 + +| Batch Size | 310 (FPS/Card) | T4 (FPS/Card) | 310/T4 | +| ---------- | -------------- | ------------- | -------- | +| 1 | *189.753* | *187.135* | *101.4%* | +| 4 | *201.207* | *203.666* | *98.80%* | +| 8 | *199.913* | *219.700* | *91.00%* | +| 16 | *200.986* | *235.980* | *85.17%* | + diff --git a/ACL_PyTorch/contrib/cv/gan/StarGAN/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/gan/StarGAN/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/ACL_PyTorch/contrib/cv/gan/StarGAN/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/gan/StarGAN/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/gan/StarGAN/requirements.txt b/ACL_PyTorch/contrib/cv/gan/StarGAN/requirements.txt index bf70cf0b5eca0d38bde555dcb760526a311ceea7..1f9481f7e6095c34c9ff6994f10b82cc431f6d77 100644 --- a/ACL_PyTorch/contrib/cv/gan/StarGAN/requirements.txt +++ b/ACL_PyTorch/contrib/cv/gan/StarGAN/requirements.txt @@ -1,4 +1,4 @@ -torch==1.5.0 -torchvision==0.6.0 -onnx==1.8.0 -numpy==1.21.1 +torch==1.5.0 +torchvision==0.6.0 +onnx==1.8.0 +numpy==1.21.1 diff --git a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/CSNLN_postprocess.py b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/CSNLN_postprocess.py index 3738c2259fdacab35e2e40f153a20207115097e5..5eb29d03a0f6a8b7a3eb3af28e46e404b9d8e145 100644 --- a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/CSNLN_postprocess.py +++ b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/CSNLN_postprocess.py @@ -1,165 +1,165 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import numpy as np -import os -import argparse -import json -import math -import imageio - -parser = argparse.ArgumentParser(description='CSNLN post process script') -parser.add_argument('--res', default='', type=str, metavar='PATH', - help='om result path') -parser.add_argument('--hr', default='', type=str, metavar='PATH', - help='high res path') -parser.add_argument('--save_path', default='', type=str, metavar='PATH', - help='result image save path') -args = parser.parse_args() - - -with open("pad_info_56.json") as f: - pad_info = json.load(f) -scale = 4 - -def postprocess(hr_src_path, bin_path, save_path): - data = [] - if not os.path.isdir(save_path): - os.makedirs(save_path) - sr_list = merge(bin_path) - files = os.listdir(hr_src_path) - files.sort() - for i, img_file in enumerate(files): - img = sr_list[i] - img = quantize(img, 1) - hr = imageio.imread(os.path.join(hr_src_path, img_file)) - hr = torch.from_numpy(hr) - hr = hr / 255 - psnr = calc_psnr(img, hr, scale, 1) - data.append({"file": img_file, "psnr": psnr}) - - img = (img * 255).byte().cpu() - imageio.imwrite(os.path.join(save_path, img_file+".png"), img.numpy().astype(np.uint8).transpose(1, 2, 0)) - - data = eval_acc(data) - json_data = json.dumps( - data, indent=4, separators=(',', ': ')) - with open("result.json", 'w') as f: - f.write(json_data) - -def eval_acc(data): - acc = 0 - for item in data: - acc += item["psnr"] - acc /= len(data) - print("accuracy: ",acc) - return { - "accuracy": acc, - "data": data - } - - -def quantize(img, rgb_range): - pixel_range = 255 / rgb_range - return img.mul(pixel_range).clamp(0, 255).round().div(pixel_range) - - -def calc_psnr(sr, hr, scale, rgb_range): - sr = sr.unsqueeze(0) - hr = hr.permute(2, 0, 1).unsqueeze(0) - if hr.nelement() == 1: - return 0 - - diff = (sr - hr) / rgb_range - shave = 4 - if diff.size(1) > 1: - gray_coeffs = [65.738, 129.057, 25.064] - convert = diff.new_tensor(gray_coeffs).view(1, 3, 1, 1) / 256 - diff = diff.mul(convert).sum(dim=1) - - valid = diff[..., shave:-shave, shave:-shave] - mse = valid.pow(2).mean() - - return -10 * math.log10(mse) - -def merge(src_path): - min_list = [] - max_list = [] - for i, pad_meta in enumerate(pad_info): - if i % 5 == 0 and i < 16: - max_list.append(pad_meta) - else: - min_list.append(pad_meta) - h_half, w_half = -1, -1 - h_size, w_size = -1, -1 - h, w = -1, -1 - temp_img = None - sr_list = [] - sr = [] - files = os.listdir(src_path) - files.sort() - for i, file in enumerate(files): - array = np.fromfile(os.path.join(src_path, file), dtype=np.float32) - array = array.reshape( - 3, 56*4, 56*4) - img = torch.from_numpy(array) - pad_h, pad_w = min_list[i]['pad_h'], min_list[i]['pad_w'] - if pad_h == 0 and pad_w == 0: - img = img - elif pad_h == 0: - img = img[:, :, 0:-pad_w] - elif pad_w == 0: - img = img[:, 0:-pad_h, :] - else: - img = img[:, 0:-pad_h, 0:-pad_w] - if i % 4 == 0: - h_half, w_half = int(min_list[i]['h_half'] * scale), int(min_list[i]['w_half'] * scale) - h_size, w_size = min_list[i]['h_size'] * scale, min_list[i]['w_size'] * scale - h, w = h_half * 2, w_half * 2 - temp_img = torch.zeros(3, h, w) - temp_img[:, 0:h_half, 0:w_half] = img[:, 0:h_half, 0:w_half] - elif i % 4 == 1: - temp_img[:, 0:h_half, w_half:w] = img[:, 0:h_half, (w_size - w + w_half):w_size] - elif i % 4 == 2: - temp_img[:, h_half:h, 0:w_half] = img[:, (h_size - h + h_half):h_size, 0:w_half] - elif i % 4 == 3: - temp_img[:, h_half:h, w_half:w] = img[:, (h_size - h + h_half):h_size, (w_size - w + w_half):w_size] - sr_list.append(temp_img) - - h_half, w_half = max_list[0]['h_half'] * scale, max_list[0]['w_half'] * scale - h_size, w_size = max_list[0]['h_size'] * scale, max_list[0]['w_size'] * scale - h, w = h_half * 2, w_half * 2 - output = torch.zeros(3, h, w) - output[:, 0:h_half, 0:w_half] \ - = sr_list[0][:, 0:h_half, 0:w_half] - output[:, 0:h_half, w_half:w] \ - = sr_list[1][:, 0:h_half, (w_size - w + w_half):w_size] - output[:, h_half:h, 0:w_half] \ - = sr_list[2][:, (h_size - h + h_half):h_size, 0:w_half] - output[:, h_half:h, w_half:w] \ - = sr_list[3][:, (h_size - h + h_half):h_size, (w_size - w + w_half):w_size] - sr.append(output) - sr.append(sr_list[4]) - sr.append(sr_list[5]) - sr.append(sr_list[6]) - sr.append(sr_list[7]) - return sr - - -if __name__ == '__main__': - res = args.res - hr = args.hr - save_path = args.save_path +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import numpy as np +import os +import argparse +import json +import math +import imageio + +parser = argparse.ArgumentParser(description='CSNLN post process script') +parser.add_argument('--res', default='', type=str, metavar='PATH', + help='om result path') +parser.add_argument('--hr', default='', type=str, metavar='PATH', + help='high res path') +parser.add_argument('--save_path', default='', type=str, metavar='PATH', + help='result image save path') +args = parser.parse_args() + + +with open("pad_info_56.json") as f: + pad_info = json.load(f) +scale = 4 + +def postprocess(hr_src_path, bin_path, save_path): + data = [] + if not os.path.isdir(save_path): + os.makedirs(save_path) + sr_list = merge(bin_path) + files = os.listdir(hr_src_path) + files.sort() + for i, img_file in enumerate(files): + img = sr_list[i] + img = quantize(img, 1) + hr = imageio.imread(os.path.join(hr_src_path, img_file)) + hr = torch.from_numpy(hr) + hr = hr / 255 + psnr = calc_psnr(img, hr, scale, 1) + data.append({"file": img_file, "psnr": psnr}) + + img = (img * 255).byte().cpu() + imageio.imwrite(os.path.join(save_path, img_file+".png"), img.numpy().astype(np.uint8).transpose(1, 2, 0)) + + data = eval_acc(data) + json_data = json.dumps( + data, indent=4, separators=(',', ': ')) + with open("result.json", 'w') as f: + f.write(json_data) + +def eval_acc(data): + acc = 0 + for item in data: + acc += item["psnr"] + acc /= len(data) + print("accuracy: ",acc) + return { + "accuracy": acc, + "data": data + } + + +def quantize(img, rgb_range): + pixel_range = 255 / rgb_range + return img.mul(pixel_range).clamp(0, 255).round().div(pixel_range) + + +def calc_psnr(sr, hr, scale, rgb_range): + sr = sr.unsqueeze(0) + hr = hr.permute(2, 0, 1).unsqueeze(0) + if hr.nelement() == 1: + return 0 + + diff = (sr - hr) / rgb_range + shave = 4 + if diff.size(1) > 1: + gray_coeffs = [65.738, 129.057, 25.064] + convert = diff.new_tensor(gray_coeffs).view(1, 3, 1, 1) / 256 + diff = diff.mul(convert).sum(dim=1) + + valid = diff[..., shave:-shave, shave:-shave] + mse = valid.pow(2).mean() + + return -10 * math.log10(mse) + +def merge(src_path): + min_list = [] + max_list = [] + for i, pad_meta in enumerate(pad_info): + if i % 5 == 0 and i < 16: + max_list.append(pad_meta) + else: + min_list.append(pad_meta) + h_half, w_half = -1, -1 + h_size, w_size = -1, -1 + h, w = -1, -1 + temp_img = None + sr_list = [] + sr = [] + files = os.listdir(src_path) + files.sort() + for i, file in enumerate(files): + array = np.fromfile(os.path.join(src_path, file), dtype=np.float32) + array = array.reshape( + 3, 56*4, 56*4) + img = torch.from_numpy(array) + pad_h, pad_w = min_list[i]['pad_h'], min_list[i]['pad_w'] + if pad_h == 0 and pad_w == 0: + img = img + elif pad_h == 0: + img = img[:, :, 0:-pad_w] + elif pad_w == 0: + img = img[:, 0:-pad_h, :] + else: + img = img[:, 0:-pad_h, 0:-pad_w] + if i % 4 == 0: + h_half, w_half = int(min_list[i]['h_half'] * scale), int(min_list[i]['w_half'] * scale) + h_size, w_size = min_list[i]['h_size'] * scale, min_list[i]['w_size'] * scale + h, w = h_half * 2, w_half * 2 + temp_img = torch.zeros(3, h, w) + temp_img[:, 0:h_half, 0:w_half] = img[:, 0:h_half, 0:w_half] + elif i % 4 == 1: + temp_img[:, 0:h_half, w_half:w] = img[:, 0:h_half, (w_size - w + w_half):w_size] + elif i % 4 == 2: + temp_img[:, h_half:h, 0:w_half] = img[:, (h_size - h + h_half):h_size, 0:w_half] + elif i % 4 == 3: + temp_img[:, h_half:h, w_half:w] = img[:, (h_size - h + h_half):h_size, (w_size - w + w_half):w_size] + sr_list.append(temp_img) + + h_half, w_half = max_list[0]['h_half'] * scale, max_list[0]['w_half'] * scale + h_size, w_size = max_list[0]['h_size'] * scale, max_list[0]['w_size'] * scale + h, w = h_half * 2, w_half * 2 + output = torch.zeros(3, h, w) + output[:, 0:h_half, 0:w_half] \ + = sr_list[0][:, 0:h_half, 0:w_half] + output[:, 0:h_half, w_half:w] \ + = sr_list[1][:, 0:h_half, (w_size - w + w_half):w_size] + output[:, h_half:h, 0:w_half] \ + = sr_list[2][:, (h_size - h + h_half):h_size, 0:w_half] + output[:, h_half:h, w_half:w] \ + = sr_list[3][:, (h_size - h + h_half):h_size, (w_size - w + w_half):w_size] + sr.append(output) + sr.append(sr_list[4]) + sr.append(sr_list[5]) + sr.append(sr_list[6]) + sr.append(sr_list[7]) + return sr + + +if __name__ == '__main__': + res = args.res + hr = args.hr + save_path = args.save_path postprocess(hr, res, save_path) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/CSNLN_preprocess.py b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/CSNLN_preprocess.py index 36a6c15a222ac32a9d95bc717c77396150af476a..f9b24a91eabd0c76c4d53e1b62c4df96b919e67a 100644 --- a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/CSNLN_preprocess.py +++ b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/CSNLN_preprocess.py @@ -1,106 +1,106 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import numpy as np -import PIL.Image as pil_image -from torch.serialization import save -import torchvision.transforms as transforms -import os -import argparse -import torch -import json -import math -import imageio - -parser = argparse.ArgumentParser(description='CSNLN preprocess script') -parser.add_argument('--s', default='', type=str, metavar='PATH', - help='path of source image files (default: none)') -parser.add_argument('--d', default='', type=str, metavar='PATH', - help='path of output (default: none)') -args = parser.parse_args() - - - -pad_info = [] -def chop(x, file_name="", save_path="", shave=10, min_size=3600): - scale = 4 - c, h, w = x.size() - h_half, w_half = h // 2, w // 2 - if h % 2 != 0: - temp_h_half = h_half + 0.5 - else: - temp_h_half = h_half - if w % 2 != 0: - temp_w_half = w_half + 0.5 - else: - temp_w_half = w_half - h_size, w_size = h_half + shave, w_half + shave - h_size += scale-h_size%scale - w_size += scale-w_size%scale - lr_list = [ - x[:, 0:h_size, 0:w_size], - x[:, 0:h_size, (w - w_size):w], - x[:, (h - h_size):h, 0:w_size], - x[:, (h - h_size):h, (w - w_size):w]] - if w_size * h_size < min_size: - for i in range(0, 4, 1): - final_fileName = file_name.split('.')[0] + "_" + str(i) - lr_batch = torch.cat(lr_list[i:(i + 1)], dim=0) - pad_h = 56-h_size - pad_w = 56-w_size - lr_batch = transforms.Compose([ - transforms.Pad(padding=(0, 0, 56-w_size, 56-h_size), padding_mode='edge') - ])(lr_batch) - - imageio.imsave(os.path.join(save_path, "png", final_fileName + ".png"), np.array( - lr_batch).astype(np.uint8).transpose(1, 2, 0)) - lr_batch = np.array(lr_batch).astype(np.float32)/255 - lr_batch.tofile(os.path.join( - save_path, "bin_56", final_fileName + ".bin")) - pad_info.append( - {"name":final_fileName, "h_half": temp_h_half, "w_half": temp_w_half, "h_size":h_size, "w_size":w_size, "pad_h":pad_h, "pad_w":pad_w}) - with open("pad_info_56.json", "w") as f: - f.write(json.dumps(pad_info, indent=4, separators=(',', ': '))) - - else: - count = 0 - for patch in lr_list: - temp_fileName = file_name.split('.')[0] + "_" + str(count) + ".png" - pad_info.append( - {"name":temp_fileName.split('.')[0], "h_half": h_half, "w_half": w_half, "h_size":h_size, "w_size":w_size}) - count = count + 1 - chop(patch, file_name=temp_fileName, save_path=save_path, shave=shave, min_size=min_size) - -def preprocess(src_path, save_path): - if not os.path.isdir(src_path): - os.makedirs(src_path) - if not os.path.isdir(save_path): - os.makedirs(save_path) - if not os.path.isdir(os.path.join(save_path, "bin_56")): - os.makedirs(os.path.join(save_path, "bin_56")) - if not os.path.isdir(os.path.join(save_path, "png")): - os.makedirs(os.path.join(save_path, "png")) - files = os.listdir(src_path) - files.sort() - for image_file in files: - image = imageio.imread(os.path.join( - src_path, image_file)) - np_transpose = np.ascontiguousarray(image.transpose((2, 0, 1))) - image = torch.from_numpy(np_transpose).float() - image.mul_(255 / 255) - chop(image, file_name=image_file, save_path=save_path) - - -if __name__ == '__main__': +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +import PIL.Image as pil_image +from torch.serialization import save +import torchvision.transforms as transforms +import os +import argparse +import torch +import json +import math +import imageio + +parser = argparse.ArgumentParser(description='CSNLN preprocess script') +parser.add_argument('--s', default='', type=str, metavar='PATH', + help='path of source image files (default: none)') +parser.add_argument('--d', default='', type=str, metavar='PATH', + help='path of output (default: none)') +args = parser.parse_args() + + + +pad_info = [] +def chop(x, file_name="", save_path="", shave=10, min_size=3600): + scale = 4 + c, h, w = x.size() + h_half, w_half = h // 2, w // 2 + if h % 2 != 0: + temp_h_half = h_half + 0.5 + else: + temp_h_half = h_half + if w % 2 != 0: + temp_w_half = w_half + 0.5 + else: + temp_w_half = w_half + h_size, w_size = h_half + shave, w_half + shave + h_size += scale-h_size%scale + w_size += scale-w_size%scale + lr_list = [ + x[:, 0:h_size, 0:w_size], + x[:, 0:h_size, (w - w_size):w], + x[:, (h - h_size):h, 0:w_size], + x[:, (h - h_size):h, (w - w_size):w]] + if w_size * h_size < min_size: + for i in range(0, 4, 1): + final_fileName = file_name.split('.')[0] + "_" + str(i) + lr_batch = torch.cat(lr_list[i:(i + 1)], dim=0) + pad_h = 56-h_size + pad_w = 56-w_size + lr_batch = transforms.Compose([ + transforms.Pad(padding=(0, 0, 56-w_size, 56-h_size), padding_mode='edge') + ])(lr_batch) + + imageio.imsave(os.path.join(save_path, "png", final_fileName + ".png"), np.array( + lr_batch).astype(np.uint8).transpose(1, 2, 0)) + lr_batch = np.array(lr_batch).astype(np.float32)/255 + lr_batch.tofile(os.path.join( + save_path, "bin_56", final_fileName + ".bin")) + pad_info.append( + {"name":final_fileName, "h_half": temp_h_half, "w_half": temp_w_half, "h_size":h_size, "w_size":w_size, "pad_h":pad_h, "pad_w":pad_w}) + with open("pad_info_56.json", "w") as f: + f.write(json.dumps(pad_info, indent=4, separators=(',', ': '))) + + else: + count = 0 + for patch in lr_list: + temp_fileName = file_name.split('.')[0] + "_" + str(count) + ".png" + pad_info.append( + {"name":temp_fileName.split('.')[0], "h_half": h_half, "w_half": w_half, "h_size":h_size, "w_size":w_size}) + count = count + 1 + chop(patch, file_name=temp_fileName, save_path=save_path, shave=shave, min_size=min_size) + +def preprocess(src_path, save_path): + if not os.path.isdir(src_path): + os.makedirs(src_path) + if not os.path.isdir(save_path): + os.makedirs(save_path) + if not os.path.isdir(os.path.join(save_path, "bin_56")): + os.makedirs(os.path.join(save_path, "bin_56")) + if not os.path.isdir(os.path.join(save_path, "png")): + os.makedirs(os.path.join(save_path, "png")) + files = os.listdir(src_path) + files.sort() + for image_file in files: + image = imageio.imread(os.path.join( + src_path, image_file)) + np_transpose = np.ascontiguousarray(image.transpose((2, 0, 1))) + image = torch.from_numpy(np_transpose).float() + image.mul_(255 / 255) + chop(image, file_name=image_file, save_path=save_path) + + +if __name__ == '__main__': preprocess(args.s, args.d) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/CSNLN_pth2onnx.py b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/CSNLN_pth2onnx.py index bb065db2a5e71addc97d06c1f76db0d284083d87..016ba2f0883e3224707d9d21184bd80a72716971 100644 --- a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/CSNLN_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/CSNLN_pth2onnx.py @@ -1,37 +1,37 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import torch -sys.path.append(r"./Cross-Scale-Non-Local-Attention/src/") -from model.csnln import CSNLN -from option import args -from collections import OrderedDict - - -def pth2onnx(input_file, output_file): - model = CSNLN(args) - model.load_state_dict(torch.load( - input_file, map_location=torch.device('cpu')), strict=False) - - model.eval() - dummy_input = torch.randn(1, 3, 56, 56) - - torch.onnx.export(model, dummy_input, output_file, opset_version=11, verbose=False) - - -if __name__ == "__main__": - input_file = args.pre_train - output_file = args.save - pth2onnx(input_file, output_file) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import torch +sys.path.append(r"./Cross-Scale-Non-Local-Attention/src/") +from model.csnln import CSNLN +from option import args +from collections import OrderedDict + + +def pth2onnx(input_file, output_file): + model = CSNLN(args) + model.load_state_dict(torch.load( + input_file, map_location=torch.device('cpu')), strict=False) + + model.eval() + dummy_input = torch.randn(1, 3, 56, 56) + + torch.onnx.export(model, dummy_input, output_file, opset_version=11, verbose=False) + + +if __name__ == "__main__": + input_file = args.pre_train + output_file = args.save + pth2onnx(input_file, output_file) diff --git a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/LICENSE b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/LICENSE index b1fac45f02e2f98395fd96a7e4f4a39e257ac0bc..989e2c59e973a05cfbfe9de678b7f2af777b0713 100644 --- a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/LICENSE +++ b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/LICENSE @@ -1,201 +1,201 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/get_info.py b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/get_info.py index 63799abe3d24d5b0add9f52fa18313d9dd61168f..5f5fac8622872fbb75609df3b39c44d5c0e25390 100644 --- a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/get_info.py +++ b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/get_info.py @@ -1,58 +1,58 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = '56' - height = '56' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = '56' + height = '56' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/modelzoo_level.txt index 74147d2f27a896292d82f166ea631cb4937a8231..0541ac3f6dfa3a88fa0b725ee2f0d125d8d49ec7 100644 --- a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/modelzoo_level.txt @@ -1,3 +1,3 @@ -FunStatus:OK -PrecisionStatus:OK +FunStatus:OK +PrecisionStatus:OK PerfStatus:POK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/perf_softmax_transpose.py b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/perf_softmax_transpose.py index 888c3b93505f9f44db7d36af96ed8ebeda332d21..527104a539222e6d7a843c394b856ec210c17f1a 100644 --- a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/perf_softmax_transpose.py +++ b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/perf_softmax_transpose.py @@ -1,22 +1,22 @@ -import sys -import onnx - -if __name__ == '__main__': - model = onnx.load(sys.argv[1]) - graph = model.graph - node = graph.node - softmax_node_index = [] - del_group = [] - for i in range(len(node)): - if node[i].op_type == 'Softmax' and node[i].attribute[0].i == 3: - del_group.append((node[i-1], node[i], node[i+1], i)) - for g in del_group: - new_input = g[0].input - new_output = g[2].output - new_name = g[1].name - new_index = g[3] - new_node = onnx.helper.make_node("Softmax", new_input, new_output, new_name, axis=1) - for n in g[:-1]: - graph.node.remove(n) - graph.node.insert(new_index, new_node) - onnx.save(model, sys.argv[2]) +import sys +import onnx + +if __name__ == '__main__': + model = onnx.load(sys.argv[1]) + graph = model.graph + node = graph.node + softmax_node_index = [] + del_group = [] + for i in range(len(node)): + if node[i].op_type == 'Softmax' and node[i].attribute[0].i == 3: + del_group.append((node[i-1], node[i], node[i+1], i)) + for g in del_group: + new_input = g[0].input + new_output = g[2].output + new_name = g[1].name + new_index = g[3] + new_node = onnx.helper.make_node("Softmax", new_input, new_output, new_name, axis=1) + for n in g[:-1]: + graph.node.remove(n) + graph.node.insert(new_index, new_node) + onnx.save(model, sys.argv[2]) diff --git a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/requirements.txt b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/requirements.txt index cb70277708e1ea983e2ab0d1e7c4f3fd9a973e6b..94ae69e3e3cc50417da3fbe085c25d0d200647d3 100644 --- a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/requirements.txt +++ b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/requirements.txt @@ -1,9 +1,9 @@ -torch==1.8.0 -torchvision==0.9.0 -onnx==1.9.0 -onnx-simplifier==0.3.6 -numpy==1.21.1 -Pillow == 7.2.0 -opencv-python==4.2.0.34 -pyyaml==5.3.1 +torch==1.8.0 +torchvision==0.9.0 +onnx==1.9.0 +onnx-simplifier==0.3.6 +numpy==1.21.1 +Pillow == 7.2.0 +opencv-python==4.2.0.34 +pyyaml==5.3.1 scikit-image==0.18.1 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/test/parse.py b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/test/parse.py index 2a25918902bf0ccaaefa729646113f01890ae787..7a52798e543a1abb477527632a12e457bd17c42d 100644 --- a/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/test/parse.py +++ b/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention/test/parse.py @@ -1,30 +1,30 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.log'): - result_log = sys.argv[1] - with open(result_log, 'r') as f: - content = f.read() - print(result_log[:-4].split('_')[1], content, end="") - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.log'): + result_log = sys.argv[1] + with open(result_log, 'r') as f: + content = f.read() + print(result_log[:-4].split('_')[1], content, end="") + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/image_process/DnCNN/READEME.md b/ACL_PyTorch/contrib/cv/image_process/DnCNN/READEME.md index 592f7f9936ff3c5bcb93ad47f60fcb136bf32842..992c40398a47b887186251c3c00d8467141d06ef 100644 --- a/ACL_PyTorch/contrib/cv/image_process/DnCNN/READEME.md +++ b/ACL_PyTorch/contrib/cv/image_process/DnCNN/READEME.md @@ -1,267 +1,267 @@ -# DnCNN ONNX模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) - - [6.2 开源TopN精度](#62-开源TopN精度) - - [6.3 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[DnCNN论文](https://ieeexplore.ieee.org/document/7839189) - -### 1.2 代码地址 - -brach:master - -commit_id: 6b0804951484eadb7f1ea24e8e5c9ede9bea485b - -备注:commitid指的是值模型基于此版本代码做的推理 - -[DnCNN代码](https://github.com/SaoYan/DnCNN-PyTorch) - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 -``` -CANN 5.0.1 -torch==1.8.0 -torchvision==0.9.0 -onnx==1.9.0 -``` - -### 2.2 python第三方库 - -``` -numpy==1.20.2 -opencv-python==4.5.2.52 -scikit-image==0.16.2 -``` - -**说明:** -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - -### 3.1 pth转onnx模型 - -1.DnCNN模型代码下载 -``` -git clone https://github.com/SaoYan/DnCNN-PyTorch -cd DnCNN-PyTorch -``` -2.获取源码pth权重文件 -wget https://ascend-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/image_classification/DnCnn/net.pth -文件的MD5sum值是: 5703a29b082cc03401fa9d9fee12cb71 - -3.获取NPU训练pth文件,将net.pth文件移动到DnCNN目录下 - -4.编写pth2onnx脚本DnCNN_pth2onnx.py - - **说明:** ->注意目前ATC支持的onnx算子版本为11 - -5.执行pth2onnx脚本,生成onnx模型文件 -``` -python3.7 DnCNN_pth2onnx.py net.pth DnCNN-S-15.onnx -``` - - **模型转换要点:** ->此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 - -### 3.2 onnx转om模型 - -1.设置环境变量 -``` -source env.sh -``` -2.使用atc将onnx模型转换为om模型文件 -``` -atc --framework=5 --model=./DnCNN-S-15.onnx --input_format=NCHW --input_shape="actual_input_1:1,1,481,481" --output=DnCNN-S-15_bs1 --log=debug --soc_version=Ascend310 -``` - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 推理数据集获取 -存放路径为 https://github.com/SaoYan/DnCNN-PyTorch 的data目录 - -### 4.2 数据集预处理 -1.预处理脚本data_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 - -``` -python3.7 data_preprocess.py data ISource INoisy -``` -### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本get_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 -``` -python3.7 get_info.py bin INoisy DnCNN_bin.info 481 481 -``` -第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程 -### 5.2 离线推理 -1.设置环境变量 -``` -source env.sh -``` -2.执行离线推理 -``` -./benchmark.x86_64 -model_type=vision -om_path=DnCNN-S-15.om -device_id=0 -batch_size=1 -input_text_path=DnCNN_bin.info -input_width=481 -input_height=481 -useDvpp=false -output_binary=true -``` -输出结果默认保存在当前目录result/dumpOutput_deviceX(X为对应的device_id),每个输入对应的输出对应一个_X.bin文件。 - -## 6 精度对比 - -- **[离线推理TopN精度](#61-离线推理TopN精度)** -- **[开源TopN精度](#62-开源TopN精度)** -- **[精度对比](#63-精度对比)** - -### 6.1 离线推理TopN精度统计 - -后处理统计TopN精度 - -调用postprocess.py脚本推理结果进行PSRN计算,结果会打印在屏幕上 -``` -python3.7 postprocess.py result/dumpOutput_device0/ -``` -第一个参数为benchmark输出目录 -查看输出结果: -``` -ISource/test064.bin PSNR 29.799832 -infering... -ISource/test065.bin PSNR 31.486418 -infering... -ISource/test066.bin PSNR 35.676752 -infering... -ISource/test067.bin PSNR 28.577475 -infering... -ISource/test068.bin PSNR 29.709767 - -PSNR on test data 31.526892 -``` -经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 - -### 6.2 开源PSNR精度 -``` -| Noise Level | DnCNN-S | DnCNN-B | DnCNN-S-PyTorch | DnCNN-B-PyTorch | -|:-----------:|:-------:|:-------:|:---------------:|:---------------:| -| 15 | 31.73 | 31.61 | 31.71 | 31.60 | -| 25 | 29.23 | 29.16 | 29.21 | 29.15 | -| 50 | 26.23 | 26.23 | 26.22 | 26.20 | -``` -### 6.3 精度对比 -将得到的om离线模型推理PSNR值与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 - **精度调试:** - ->没有遇到精度不达标的问题,故不需要进行精度调试 - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** - -### 7.1 npu性能数据 -benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device。为快速获取性能数据,也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准。这里给出两种方式,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 -1.benchmark工具在整个数据集上推理获得性能数据 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: -``` -[e2e] throughputRate: 15.0465, latency: 4519.32 -[data read] throughputRate: 966.417, moduleLatency: 1.03475 -[preprocess] throughputRate: 525.539, moduleLatency: 1.90281 -[infer] throughputRate: 22.6328, Interface throughputRate: 23.7919, moduleLatency: 43.8903 -[post] throughputRate: 22.615, moduleLatency: 44.2185 -``` -Interface throughputRate: 23.7919,23.7919x4=95.176既是batch1 310单卡吞吐率 - -batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: -``` -[e2e] throughputRate: 15.3818, latency: 4420.81 -[data read] throughputRate: 1484.65, moduleLatency: 0.673559 -[preprocess] throughputRate: 316.273, moduleLatency: 3.16182 -[infer] throughputRate: 21.4529, Interface throughputRate: 22.2853, moduleLatency: 45.6179 -[post] throughputRate: 1.56798, moduleLatency: 637.764 -``` -Interface throughputRate: 22.2853,22.2853x4=89.1412既是batch16 310单卡吞吐率 - -batch4性能: -``` -[e2e] throughputRate: 15.5641, latency: 4369.02 -[data read] throughputRate: 1898.17, moduleLatency: 0.526824 -[preprocess] throughputRate: 523.883, moduleLatency: 1.90882 -[infer] throughputRate: 22.091, Interface throughputRate: 23.9045, moduleLatency: 44.5192 -[post] throughputRate: 5.50981, moduleLatency: 181.495 -``` -batch4 310单卡吞吐率 23.9045x4=95.618 - -batch8性能: -``` -[e2e] throughputRate: 15.5035, latency: 4386.1 -[data read] throughputRate: 1863.93, moduleLatency: 0.5365 -[preprocess] throughputRate: 461.471, moduleLatency: 2.16699 -[infer] throughputRate: 20.7804, Interface throughputRate: 22.2652, moduleLatency: 47.2831 -[post] throughputRate: 2.74035, moduleLatency: 364.917 -``` -batch8 310单卡吞吐率 22.2652x4=89.0608 - -batch32性能: -``` -[e2e] throughputRate: 12.4075, latency: 5480.54 -[data read] throughputRate: 1770.65, moduleLatency: 0.564765 -[preprocess] throughputRate: 242.944, moduleLatency: 4.11618 -[infer] throughputRate: 15.641, Interface throughputRate: 13.2648, moduleLatency: 62.7386 -[post] throughputRate: 0.68503, moduleLatency: 1459.79 -``` -batch32 310单卡吞吐率 13.2648x4=53.0592 - -**性能优化:** - +# DnCNN ONNX模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理TopN精度统计](#61-离线推理TopN精度统计) + - [6.2 开源TopN精度](#62-开源TopN精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[DnCNN论文](https://ieeexplore.ieee.org/document/7839189) + +### 1.2 代码地址 + +brach:master + +commit_id: 6b0804951484eadb7f1ea24e8e5c9ede9bea485b + +备注:commitid指的是值模型基于此版本代码做的推理 + +[DnCNN代码](https://github.com/SaoYan/DnCNN-PyTorch) + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +CANN 5.0.1 +torch==1.8.0 +torchvision==0.9.0 +onnx==1.9.0 +``` + +### 2.2 python第三方库 + +``` +numpy==1.20.2 +opencv-python==4.5.2.52 +scikit-image==0.16.2 +``` + +**说明:** +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + +### 3.1 pth转onnx模型 + +1.DnCNN模型代码下载 +``` +git clone https://github.com/SaoYan/DnCNN-PyTorch +cd DnCNN-PyTorch +``` +2.获取源码pth权重文件 +wget https://ascend-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/image_classification/DnCnn/net.pth +文件的MD5sum值是: 5703a29b082cc03401fa9d9fee12cb71 + +3.获取NPU训练pth文件,将net.pth文件移动到DnCNN目录下 + +4.编写pth2onnx脚本DnCNN_pth2onnx.py + + **说明:** +>注意目前ATC支持的onnx算子版本为11 + +5.执行pth2onnx脚本,生成onnx模型文件 +``` +python3.7 DnCNN_pth2onnx.py net.pth DnCNN-S-15.onnx +``` + + **模型转换要点:** +>此模型转换为onnx不需要修改开源代码仓代码,故不需要特殊说明 + +### 3.2 onnx转om模型 + +1.设置环境变量 +``` +source env.sh +``` +2.使用atc将onnx模型转换为om模型文件 +``` +atc --framework=5 --model=./DnCNN-S-15.onnx --input_format=NCHW --input_shape="actual_input_1:1,1,481,481" --output=DnCNN-S-15_bs1 --log=debug --soc_version=Ascend310 +``` + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 推理数据集获取 +存放路径为 https://github.com/SaoYan/DnCNN-PyTorch 的data目录 + +### 4.2 数据集预处理 +1.预处理脚本data_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 + +``` +python3.7 data_preprocess.py data ISource INoisy +``` +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本get_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 +``` +python3.7 get_info.py bin INoisy DnCNN_bin.info 481 481 +``` +第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程 +### 5.2 离线推理 +1.设置环境变量 +``` +source env.sh +``` +2.执行离线推理 +``` +./benchmark.x86_64 -model_type=vision -om_path=DnCNN-S-15.om -device_id=0 -batch_size=1 -input_text_path=DnCNN_bin.info -input_width=481 -input_height=481 -useDvpp=false -output_binary=true +``` +输出结果默认保存在当前目录result/dumpOutput_deviceX(X为对应的device_id),每个输入对应的输出对应一个_X.bin文件。 + +## 6 精度对比 + +- **[离线推理TopN精度](#61-离线推理TopN精度)** +- **[开源TopN精度](#62-开源TopN精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理TopN精度统计 + +后处理统计TopN精度 + +调用postprocess.py脚本推理结果进行PSRN计算,结果会打印在屏幕上 +``` +python3.7 postprocess.py result/dumpOutput_device0/ +``` +第一个参数为benchmark输出目录 +查看输出结果: +``` +ISource/test064.bin PSNR 29.799832 +infering... +ISource/test065.bin PSNR 31.486418 +infering... +ISource/test066.bin PSNR 35.676752 +infering... +ISource/test067.bin PSNR 28.577475 +infering... +ISource/test068.bin PSNR 29.709767 + +PSNR on test data 31.526892 +``` +经过对bs1与bs16的om测试,本模型batch1的精度与batch16的精度没有差别,精度数据均如上 + +### 6.2 开源PSNR精度 +``` +| Noise Level | DnCNN-S | DnCNN-B | DnCNN-S-PyTorch | DnCNN-B-PyTorch | +|:-----------:|:-------:|:-------:|:---------------:|:---------------:| +| 15 | 31.73 | 31.61 | 31.71 | 31.60 | +| 25 | 29.23 | 29.16 | 29.21 | 29.15 | +| 50 | 26.23 | 26.23 | 26.22 | 26.20 | +``` +### 6.3 精度对比 +将得到的om离线模型推理PSNR值与该模型github代码仓上公布的精度对比,精度下降在1%范围之内,故精度达标。 + **精度调试:** + +>没有遇到精度不达标的问题,故不需要进行精度调试 + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** + +### 7.1 npu性能数据 +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device。为快速获取性能数据,也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准。这里给出两种方式,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 +1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: +``` +[e2e] throughputRate: 15.0465, latency: 4519.32 +[data read] throughputRate: 966.417, moduleLatency: 1.03475 +[preprocess] throughputRate: 525.539, moduleLatency: 1.90281 +[infer] throughputRate: 22.6328, Interface throughputRate: 23.7919, moduleLatency: 43.8903 +[post] throughputRate: 22.615, moduleLatency: 44.2185 +``` +Interface throughputRate: 23.7919,23.7919x4=95.176既是batch1 310单卡吞吐率 + +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: +``` +[e2e] throughputRate: 15.3818, latency: 4420.81 +[data read] throughputRate: 1484.65, moduleLatency: 0.673559 +[preprocess] throughputRate: 316.273, moduleLatency: 3.16182 +[infer] throughputRate: 21.4529, Interface throughputRate: 22.2853, moduleLatency: 45.6179 +[post] throughputRate: 1.56798, moduleLatency: 637.764 +``` +Interface throughputRate: 22.2853,22.2853x4=89.1412既是batch16 310单卡吞吐率 + +batch4性能: +``` +[e2e] throughputRate: 15.5641, latency: 4369.02 +[data read] throughputRate: 1898.17, moduleLatency: 0.526824 +[preprocess] throughputRate: 523.883, moduleLatency: 1.90882 +[infer] throughputRate: 22.091, Interface throughputRate: 23.9045, moduleLatency: 44.5192 +[post] throughputRate: 5.50981, moduleLatency: 181.495 +``` +batch4 310单卡吞吐率 23.9045x4=95.618 + +batch8性能: +``` +[e2e] throughputRate: 15.5035, latency: 4386.1 +[data read] throughputRate: 1863.93, moduleLatency: 0.5365 +[preprocess] throughputRate: 461.471, moduleLatency: 2.16699 +[infer] throughputRate: 20.7804, Interface throughputRate: 22.2652, moduleLatency: 47.2831 +[post] throughputRate: 2.74035, moduleLatency: 364.917 +``` +batch8 310单卡吞吐率 22.2652x4=89.0608 + +batch32性能: +``` +[e2e] throughputRate: 12.4075, latency: 5480.54 +[data read] throughputRate: 1770.65, moduleLatency: 0.564765 +[preprocess] throughputRate: 242.944, moduleLatency: 4.11618 +[infer] throughputRate: 15.641, Interface throughputRate: 13.2648, moduleLatency: 62.7386 +[post] throughputRate: 0.68503, moduleLatency: 1459.79 +``` +batch32 310单卡吞吐率 13.2648x4=53.0592 + +**性能优化:** + >batch32纯推理性能达标。 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/image_process/DnCNN/test/README.md b/ACL_PyTorch/contrib/cv/image_process/DnCNN/test/README.md index ab5da7a949f5f38bfdfd01e7cd89ac3d05d90372..7991250288dd3f4ee1e2783621c413779f6a4155 100644 --- a/ACL_PyTorch/contrib/cv/image_process/DnCNN/test/README.md +++ b/ACL_PyTorch/contrib/cv/image_process/DnCNN/test/README.md @@ -1,31 +1,31 @@ -环境准备: - -1.获取数据集 -``` -git clone https://github.com/SaoYan/DnCNN-PyTorch -``` -开源代码仓的data目录下有数据集,将data复制到DnCNN目录下 - -2.进入工作目录 -``` -cd DnCNN -``` - -3.安装必要的依赖 -``` -pip3.7 install -r requirements.txt -``` - -4.获取训练提供的权重文件 -``` -wget https://ascend-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/image_classification/DnCnn/net.pth -``` - -5.获取benchmark工具 -将benchmark.x86_64 benchmark.aarch64放在当前目录 - -6.310上执行,执行时确保device空闲 -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=./data -``` +环境准备: + +1.获取数据集 +``` +git clone https://github.com/SaoYan/DnCNN-PyTorch +``` +开源代码仓的data目录下有数据集,将data复制到DnCNN目录下 + +2.进入工作目录 +``` +cd DnCNN +``` + +3.安装必要的依赖 +``` +pip3.7 install -r requirements.txt +``` + +4.获取训练提供的权重文件 +``` +wget https://ascend-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/image_classification/DnCnn/net.pth +``` + +5.获取benchmark工具 +将benchmark.x86_64 benchmark.aarch64放在当前目录 + +6.310上执行,执行时确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=./data +``` diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/3DMPPE-ROOTNET_postprocess.py b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/3DMPPE-ROOTNET_postprocess.py index dcd38a9917dec3697dab6e25a2e8b17bc2180dd5..e844f8baedd69609b140c3e6c59f8b05fab886a9 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/3DMPPE-ROOTNET_postprocess.py +++ b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/3DMPPE-ROOTNET_postprocess.py @@ -1,50 +1,50 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import argparse -from pathlib import Path -import numpy as np -sys.path.append(r"./3DMPPE_ROOTNET_RELEASE") -from data.MuPoTS.MuPoTS import MuPoTS - -def evaluate(result_path, result_file, img_path, ann_path): - print('postprocessing') - bin_path = os.listdir(result_path)[0] - result_path = os.path.join(result_path, bin_path) - bin_list = os.listdir(result_path) - bin_list.sort(key=lambda x: int(x[:-13])) - preds = [] - for i,f in enumerate(bin_list): - bin_path = os.path.join(result_path, f) - coord_out = np.fromfile(bin_path, dtype=np.float32).reshape(-1, 3) - preds.append(coord_out) - # evaluate - preds = np.concatenate(preds, axis=0) - testset = MuPoTS('test', img_path, ann_path) - if not os.path.exists(result_file): - os.makedirs(result_file) - testset.evaluate(preds, result_file) - print('postprocess finised') - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='preprocess of 3D-ResNets') - parser.add_argument('--img_path', default='MuPoTS/MultiPersonTestSet',type=Path, help='Directory path of videos') - parser.add_argument('--ann_path', default='MuPoTS/MuPoTS-3D.json', type=Path, help='Annotation file path') - parser.add_argument('--input_path', default='out_bs1', type=Path, help='Directory path of videos') - parser.add_argument('--result_file', default='result_bs1', type=Path, help='Directory path of binary output data') - opt = parser.parse_args() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import argparse +from pathlib import Path +import numpy as np +sys.path.append(r"./3DMPPE_ROOTNET_RELEASE") +from data.MuPoTS.MuPoTS import MuPoTS + +def evaluate(result_path, result_file, img_path, ann_path): + print('postprocessing') + bin_path = os.listdir(result_path)[0] + result_path = os.path.join(result_path, bin_path) + bin_list = os.listdir(result_path) + bin_list.sort(key=lambda x: int(x[:-13])) + preds = [] + for i,f in enumerate(bin_list): + bin_path = os.path.join(result_path, f) + coord_out = np.fromfile(bin_path, dtype=np.float32).reshape(-1, 3) + preds.append(coord_out) + # evaluate + preds = np.concatenate(preds, axis=0) + testset = MuPoTS('test', img_path, ann_path) + if not os.path.exists(result_file): + os.makedirs(result_file) + testset.evaluate(preds, result_file) + print('postprocess finised') + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='preprocess of 3D-ResNets') + parser.add_argument('--img_path', default='MuPoTS/MultiPersonTestSet',type=Path, help='Directory path of videos') + parser.add_argument('--ann_path', default='MuPoTS/MuPoTS-3D.json', type=Path, help='Annotation file path') + parser.add_argument('--input_path', default='out_bs1', type=Path, help='Directory path of videos') + parser.add_argument('--result_file', default='result_bs1', type=Path, help='Directory path of binary output data') + opt = parser.parse_args() evaluate(opt.input_path, opt.result_file, opt.img_path, opt.ann_path) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/3DMPPE-ROOTNET_preprocess.py b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/3DMPPE-ROOTNET_preprocess.py index 7f7ff43b73495a8026ac8efd00b9982fcbed7531..a87187843be5267bc7d0047c6c2338fcdf404dfd 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/3DMPPE-ROOTNET_preprocess.py +++ b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/3DMPPE-ROOTNET_preprocess.py @@ -1,61 +1,61 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import argparse -from pathlib import Path -from tqdm import tqdm -import torch -import torchvision.transforms as transforms -from torch.utils.data import DataLoader -sys.path.append(r"./3DMPPE_ROOTNET_RELEASE") -from data.dataset import DatasetLoader -from data.MuPoTS.MuPoTS import MuPoTS - -def preprocess(inference_batch_size, save_path_imge, save_path_cam, img_path, ann_path): - print('preprocessing') - testset = MuPoTS('test', img_path, ann_path) - - testset_loader = DatasetLoader(testset, False, transforms.Compose([transforms.ToTensor(), - transforms.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225))])) - batch_generator = DataLoader(dataset=testset_loader, batch_size=inference_batch_size, - shuffle=False, num_workers=8, pin_memory=True) - - if not os.path.exists(save_path_imge): - os.makedirs(save_path_imge) - if not os.path.exists(save_path_cam): - os.makedirs(save_path_cam) - cid = 0 - with torch.no_grad(): - for itr, (input_img, cam_param) in enumerate(tqdm(batch_generator)): - if(len(input_img) == inference_batch_size): - path_bin_image = str(save_path_imge) + '/' + str(cid) + '.bin' - path_bin_cam = str(save_path_cam) + '/' + str(cid) + '.bin' - cid = cid + 1 - input_img.cpu().numpy().tofile(path_bin_image) - cam_param.cpu().numpy().tofile(path_bin_cam) - print('preprocess finished') - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--img_path', default='MuPoTS/MultiPersonTestSet', - type=Path, help='Directory path of videos') - parser.add_argument('--ann_path', default='MuPoTS/MuPoTS-3D.json', type=Path, help='Annotation file path') - parser.add_argument('--inference_batch_size', default=1, type=int, help='Batch Size for inference. 0 means this is the same as batch_size.') - parser.add_argument('--save_path_image', default='0data_imge_bs1', type=Path, help='Directory path of binary output data') - parser.add_argument('--save_path_cam', default='0data_cam_bs1', type=Path, help='Directory path of binary output data') - opt = parser.parse_args() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import argparse +from pathlib import Path +from tqdm import tqdm +import torch +import torchvision.transforms as transforms +from torch.utils.data import DataLoader +sys.path.append(r"./3DMPPE_ROOTNET_RELEASE") +from data.dataset import DatasetLoader +from data.MuPoTS.MuPoTS import MuPoTS + +def preprocess(inference_batch_size, save_path_imge, save_path_cam, img_path, ann_path): + print('preprocessing') + testset = MuPoTS('test', img_path, ann_path) + + testset_loader = DatasetLoader(testset, False, transforms.Compose([transforms.ToTensor(), + transforms.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225))])) + batch_generator = DataLoader(dataset=testset_loader, batch_size=inference_batch_size, + shuffle=False, num_workers=8, pin_memory=True) + + if not os.path.exists(save_path_imge): + os.makedirs(save_path_imge) + if not os.path.exists(save_path_cam): + os.makedirs(save_path_cam) + cid = 0 + with torch.no_grad(): + for itr, (input_img, cam_param) in enumerate(tqdm(batch_generator)): + if(len(input_img) == inference_batch_size): + path_bin_image = str(save_path_imge) + '/' + str(cid) + '.bin' + path_bin_cam = str(save_path_cam) + '/' + str(cid) + '.bin' + cid = cid + 1 + input_img.cpu().numpy().tofile(path_bin_image) + cam_param.cpu().numpy().tofile(path_bin_cam) + print('preprocess finished') + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--img_path', default='MuPoTS/MultiPersonTestSet', + type=Path, help='Directory path of videos') + parser.add_argument('--ann_path', default='MuPoTS/MuPoTS-3D.json', type=Path, help='Annotation file path') + parser.add_argument('--inference_batch_size', default=1, type=int, help='Batch Size for inference. 0 means this is the same as batch_size.') + parser.add_argument('--save_path_image', default='0data_imge_bs1', type=Path, help='Directory path of binary output data') + parser.add_argument('--save_path_cam', default='0data_cam_bs1', type=Path, help='Directory path of binary output data') + opt = parser.parse_args() preprocess(opt.inference_batch_size, opt.save_path_image, opt.save_path_cam, opt.img_path, opt.ann_path) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/3DMPPE-ROOTNET_pth2onnx.py b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/3DMPPE-ROOTNET_pth2onnx.py index 8da7b5791d0d4342575ce3e8b7bca9a790db1b1e..fad0ab3a3d89ed5f37760d265d0b4ec5f21d6e91 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/3DMPPE-ROOTNET_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/3DMPPE-ROOTNET_pth2onnx.py @@ -1,47 +1,47 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import torch -from collections import OrderedDict -sys.path.append(r"./3DMPPE_ROOTNET_RELEASE") -from main.model import get_pose_net -from main.config import cfg - -def convert(pth_file_path,onnx_file_path): - model = get_pose_net(cfg, False) - ckpt = torch.load(pth_file_path, map_location=torch.device('cpu')) - new_state_dict = OrderedDict() - for k, v in ckpt['network'].items(): - if k[0:7] == "module.": - name = k[7:] # remove module. - else: - name = k[0:] - new_state_dict[name] = v - model.load_state_dict(new_state_dict) - model.eval() - - input_names = ["image", "cam_param"] - output_names = ["score"] - dynamic_axes = {'image': {0: '-1'}, 'cam_param': {0: '-1'}, 'score': {0: '-1'}} - dummy_input1 = torch.randn(1, 3, 256, 256) - dummy_input2 = torch.randn(1, 1) - torch.onnx.export(model, (dummy_input1, dummy_input2), onnx_file_path, input_names=input_names, dynamic_axes=dynamic_axes, - output_names=output_names, opset_version=11, verbose=True) - -if __name__ == "__main__": - # convert("snapshot_6.pth.tar", "3DMPPE-ROOTNET.onnx") - convert(sys.argv[1], sys.argv[2]) - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import torch +from collections import OrderedDict +sys.path.append(r"./3DMPPE_ROOTNET_RELEASE") +from main.model import get_pose_net +from main.config import cfg + +def convert(pth_file_path,onnx_file_path): + model = get_pose_net(cfg, False) + ckpt = torch.load(pth_file_path, map_location=torch.device('cpu')) + new_state_dict = OrderedDict() + for k, v in ckpt['network'].items(): + if k[0:7] == "module.": + name = k[7:] # remove module. + else: + name = k[0:] + new_state_dict[name] = v + model.load_state_dict(new_state_dict) + model.eval() + + input_names = ["image", "cam_param"] + output_names = ["score"] + dynamic_axes = {'image': {0: '-1'}, 'cam_param': {0: '-1'}, 'score': {0: '-1'}} + dummy_input1 = torch.randn(1, 3, 256, 256) + dummy_input2 = torch.randn(1, 1) + torch.onnx.export(model, (dummy_input1, dummy_input2), onnx_file_path, input_names=input_names, dynamic_axes=dynamic_axes, + output_names=output_names, opset_version=11, verbose=True) + +if __name__ == "__main__": + # convert("snapshot_6.pth.tar", "3DMPPE-ROOTNET.onnx") + convert(sys.argv[1], sys.argv[2]) + + diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/LICENSE b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/LICENSE index df2c2f2c3e55bfbad1aebe53321a94ee5a3854bc..c8ec075d5b892f823d0b485ad4fdd01355c57b3e 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/LICENSE +++ b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/LICENSE @@ -1,203 +1,203 @@ -Copyright 2018-2019 Open-MMLab. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2018-2019 Open-MMLab. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and +Copyright 2018-2019 Open-MMLab. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2019 Open-MMLab. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/README.md b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/README.md index d2b51af3aceb3943a9b22e43ac7fe84182952422..51e63ccddbc4d80539e9d27608d8463019917c85 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/README.md +++ b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/README.md @@ -1,43 +1,43 @@ -# 3DMPPE-ROOTNET模型PyTorch离线推理指导 - -### 环境准备 - -安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -``` -pip3.7 install -r requirements.txt -``` - -### 安装开源模型代码 -``` -git clone https://github.com/mks0601/3DMPPE_ROOTNET_RELEASE.git -cd 3DMPPE_ROOTNET_RELEASE -patch -p1 < ../3DMPPE_ROOTNET.patch -cd .. -``` -> branch: master - -> commit id: a199d50be5b0a9ba348679ad4d010130535a631d - -### 获取MuPoTS数据集 -下载 MuPoTS 解析数据 [[MuPoTS](https://github.com/mks0601/3DMPPE_ROOTNET_RELEASE)] - - -### 获取推理工具 -获取msame和benchmark工具 [[msame](https://gitee.com/ascend/tools/tree/master/msame)][[benchmark](https://gitee.com/ascend/cann-benchmark/tree/master/infer)] - -将msame和benchmark.x86_64(或benchmark.aarch64)放到当前目录 - -### 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets/ -``` - **评测结果:** -| 模型 | pth精度 | 310精度 | 性能基准 | 310性能 | -| :------: | :------: | :------: | :------: | :------: | -| 3DMPPE-ROOTNET bs1 | AP_root: 31.87 | AP_root: 31.90 | 639.656fps | 664.718fps | -| 3DMPPE-ROOTNET bs16 | AP_root: 31.87 | AP_root: 31.88 | 467.282fps | 817.480fps | - - +# 3DMPPE-ROOTNET模型PyTorch离线推理指导 + +### 环境准备 + +安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip3.7 install -r requirements.txt +``` + +### 安装开源模型代码 +``` +git clone https://github.com/mks0601/3DMPPE_ROOTNET_RELEASE.git +cd 3DMPPE_ROOTNET_RELEASE +patch -p1 < ../3DMPPE_ROOTNET.patch +cd .. +``` +> branch: master + +> commit id: a199d50be5b0a9ba348679ad4d010130535a631d + +### 获取MuPoTS数据集 +下载 MuPoTS 解析数据 [[MuPoTS](https://github.com/mks0601/3DMPPE_ROOTNET_RELEASE)] + + +### 获取推理工具 +获取msame和benchmark工具 [[msame](https://gitee.com/ascend/tools/tree/master/msame)][[benchmark](https://gitee.com/ascend/cann-benchmark/tree/master/infer)] + +将msame和benchmark.x86_64(或benchmark.aarch64)放到当前目录 + +### 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets/ +``` + **评测结果:** +| 模型 | pth精度 | 310精度 | 性能基准 | 310性能 | +| :------: | :------: | :------: | :------: | :------: | +| 3DMPPE-ROOTNET bs1 | AP_root: 31.87 | AP_root: 31.90 | 639.656fps | 664.718fps | +| 3DMPPE-ROOTNET bs16 | AP_root: 31.87 | AP_root: 31.88 | 467.282fps | 817.480fps | + + diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/modelzoo_level.txt index 83689985f26624b65a4c5ebb5f00a152618799ba..8c469d858afccf3026a8640799938f8de7b46fac 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:PERFECT \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/requirements.txt b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/requirements.txt index a7d74b3118657a44e6df8b9ea1af1f40d5266528..fd36c964001617acdbc9f5f6def6a90ad15c4e28 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/requirements.txt +++ b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/requirements.txt @@ -1,9 +1,9 @@ -torch==1.5.0 -torchvision==0.6.0 -onnx == 1.7.0 -numpy==1.20.3 -opencv-python==4.5.3.56 -tqdm==4.62.1 -scipy==1.6.2 -pycocotools==2.0 +torch==1.5.0 +torchvision==0.6.0 +onnx == 1.7.0 +numpy==1.20.3 +opencv-python==4.5.3.56 +tqdm==4.62.1 +scipy==1.6.2 +pycocotools==2.0 scikit-learn==0.24.2 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/test/parse.py b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/test/parse.py index a35b48d42a91a041e232bf9f22f9f2896b8bbfe3..6b1760f355d2819933ca75844c15ba8c5a561ec5 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/test/parse.py +++ b/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET/test/parse.py @@ -1,31 +1,31 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - result_json = result_json.split('_')[1] - result_json = result_json.split('/')[0] - print('om {} accuracy {}'.format(result_json, content)) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = content.split(' ') - fps = float(txt_data_list[2].replace('samples/s,', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + result_json = result_json.split('_')[1] + result_json = result_json.split('/')[0] + print('om {} accuracy {}'.format(result_json, content)) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = content.split(' ') + fps = float(txt_data_list[2].replace('samples/s,', '')) * 4 print('310 {} fps:{}'.format(result_txt.split('_')[4], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/HigherHRNet/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/pose_estimation/HigherHRNet/modelzoo_level.txt index c80d660077532ade40fc6ae69b87f5e9c8462217..d5130dbf735d1a55ec0d55f24466fcaf4b7bf730 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/HigherHRNet/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/pose_estimation/HigherHRNet/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -ModelConvert:OK +FuncStatus:OK +PrecisionStatus:OK +ModelConvert:OK PerfStatus=OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/MSPN_postprocess.py b/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/MSPN_postprocess.py index 292c34384e02a1ff6180195fe9ab90b7fe5cc742..6d3f896bbf88f7793de2a1971d279a90e98b9431 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/MSPN_postprocess.py +++ b/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/MSPN_postprocess.py @@ -1,194 +1,194 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -sys.path.append('./exps/mspn.2xstg.coco/') -import argparse -from tqdm import tqdm -import numpy as np -import cv2 -import json -import time - -import torch -import torch.distributed as dist - -from cvpack.utils.logger import get_logger - -from config import cfg -from network import MSPN -from lib.utils.dataloader import get_test_loader -from lib.utils.comm import is_main_process, synchronize, all_gather -from lib.utils.transforms import flip_back -from dataset.COCO.coco import COCODataset - -def get_results(outputs, centers, scales, kernel=11, shifts=[0.25]): - scales *= 200 - nr_img = outputs.shape[0] - preds = np.zeros((nr_img, cfg.DATASET.KEYPOINT.NUM, 2)) - maxvals = np.zeros((nr_img, cfg.DATASET.KEYPOINT.NUM, 1)) - for i in range(nr_img): - score_map = outputs[i].copy() - score_map = score_map / 255 + 0.5 - kps = np.zeros((cfg.DATASET.KEYPOINT.NUM, 2)) - scores = np.zeros((cfg.DATASET.KEYPOINT.NUM, 1)) - border = 10 - dr = np.zeros((cfg.DATASET.KEYPOINT.NUM, - cfg.OUTPUT_SHAPE[0] + 2 * border, cfg.OUTPUT_SHAPE[1] + 2 * border)) - dr[:, border: -border, border: -border] = outputs[i].copy() - for w in range(cfg.DATASET.KEYPOINT.NUM): - dr[w] = cv2.GaussianBlur(dr[w], (kernel, kernel), 0) - for w in range(cfg.DATASET.KEYPOINT.NUM): - for j in range(len(shifts)): - if j == 0: - lb = dr[w].argmax() - y, x = np.unravel_index(lb, dr[w].shape) - dr[w, y, x] = 0 - x -= border - y -= border - lb = dr[w].argmax() - py, px = np.unravel_index(lb, dr[w].shape) - dr[w, py, px] = 0 - px -= border + x - py -= border + y - ln = (px ** 2 + py ** 2) ** 0.5 - if ln > 1e-3: - x += shifts[j] * px / ln - y += shifts[j] * py / ln - x = max(0, min(x, cfg.OUTPUT_SHAPE[1] - 1)) - y = max(0, min(y, cfg.OUTPUT_SHAPE[0] - 1)) - kps[w] = np.array([x * 4 + 2, y * 4 + 2]) - scores[w, 0] = score_map[w, int(round(y) + 1e-9), \ - int(round(x) + 1e-9)] - # aligned or not ... - kps[:, 0] = kps[:, 0] / cfg.INPUT_SHAPE[1] * scales[i][0] + \ - centers[i][0] - scales[i][0] * 0.5 - kps[:, 1] = kps[:, 1] / cfg.INPUT_SHAPE[0] * scales[i][1] + \ - centers[i][1] - scales[i][1] * 0.5 - preds[i] = kps - maxvals[i] = scores - - return preds, maxvals - - -def compute_on_dataset(data_loader, device="cpu"): - results = list() - cpu_device = torch.device("cpu") - - results = list() - data = tqdm(data_loader) if is_main_process() else data_loader - k = 0 - for _, batch in enumerate(data): - imgs, scores, centers, scales, img_ids = batch - output_name='img_%d_%d_1.bin' %(int(img_ids[0]), k) - output_path=os.path.join('result/dumpOutput_device0/',output_name) - outputs = np.fromfile(output_path, dtype=np.float32).reshape(1,17,64,48) - k += 1 - - centers = np.array(centers) - scales = np.array(scales) - preds, maxvals = get_results(outputs, centers, scales, - cfg.TEST.GAUSSIAN_KERNEL, cfg.TEST.SHIFT_RATIOS) - - kp_scores = maxvals.squeeze(-1).mean(axis=1) - preds = np.concatenate((preds, maxvals), axis=2) - - for i in range(preds.shape[0]): - keypoints = preds[i].reshape(-1).tolist() - score = scores[i] * kp_scores[i] - image_id = img_ids[i] - - results.append(dict(image_id=image_id, - category_id=1, - keypoints=keypoints, - score=score)) - return results - - -def _accumulate_predictions_from_multiple_gpus(predictions_per_gpu, logger): - if is_main_process(): - logger.info("Accumulating ...") - all_predictions = all_gather(predictions_per_gpu) - - if not is_main_process(): - return - - predictions = list() - for p in all_predictions: - predictions.extend(p) - - return predictions - - -def inference(data_loader, logger, device="cpu"): - predictions = compute_on_dataset(data_loader, device) - synchronize() - predictions = _accumulate_predictions_from_multiple_gpus( - predictions, logger) - - if not is_main_process(): - return - - return predictions - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument("--local_rank", type=int, default=0) - parser.add_argument("--iter", "-i", type=int, default=-1) - parser.add_argument("--datasets_path",default="$MSPN_HOME/dataset/COCO") - args = parser.parse_args() - COCODataset.cur_dir=os.path.join(args.datasets_path) - num_gpus = int( - os.environ["WORLD_SIZE"]) if "WORLD_SIZE" in os.environ else 1 - distributed = num_gpus > 1 - - if distributed: - torch.cuda.set_device(args.local_rank) - dist.init_process_group(backend="nccl", init_method="env://") - synchronize() - - if is_main_process() and not os.path.exists(cfg.TEST_DIR): - os.mkdir(cfg.TEST_DIR) - logger = get_logger( - cfg.DATASET.NAME, cfg.TEST_DIR, args.local_rank, 'test_log.txt') - - if args.iter == -1: - logger.info("Please designate one iteration.") - - data_loader = get_test_loader(cfg, num_gpus, args.local_rank, 'val', - is_dist=distributed) - - device = 'cpu' - results = inference(data_loader, logger, device) - synchronize() - - if is_main_process(): - logger.info("Dumping results ...") - results.sort( - key=lambda res:(res['image_id'], res['score']), reverse=True) - results_path = os.path.join(cfg.TEST_DIR, 'results.json') - with open(results_path, 'w') as f: - json.dump(results, f) - logger.info("Get all results.") - - data_loader.ori_dataset.evaluate(results_path) - - -if __name__ == '__main__': - begin = time.time() - main() - end = time.time() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +sys.path.append('./exps/mspn.2xstg.coco/') +import argparse +from tqdm import tqdm +import numpy as np +import cv2 +import json +import time + +import torch +import torch.distributed as dist + +from cvpack.utils.logger import get_logger + +from config import cfg +from network import MSPN +from lib.utils.dataloader import get_test_loader +from lib.utils.comm import is_main_process, synchronize, all_gather +from lib.utils.transforms import flip_back +from dataset.COCO.coco import COCODataset + +def get_results(outputs, centers, scales, kernel=11, shifts=[0.25]): + scales *= 200 + nr_img = outputs.shape[0] + preds = np.zeros((nr_img, cfg.DATASET.KEYPOINT.NUM, 2)) + maxvals = np.zeros((nr_img, cfg.DATASET.KEYPOINT.NUM, 1)) + for i in range(nr_img): + score_map = outputs[i].copy() + score_map = score_map / 255 + 0.5 + kps = np.zeros((cfg.DATASET.KEYPOINT.NUM, 2)) + scores = np.zeros((cfg.DATASET.KEYPOINT.NUM, 1)) + border = 10 + dr = np.zeros((cfg.DATASET.KEYPOINT.NUM, + cfg.OUTPUT_SHAPE[0] + 2 * border, cfg.OUTPUT_SHAPE[1] + 2 * border)) + dr[:, border: -border, border: -border] = outputs[i].copy() + for w in range(cfg.DATASET.KEYPOINT.NUM): + dr[w] = cv2.GaussianBlur(dr[w], (kernel, kernel), 0) + for w in range(cfg.DATASET.KEYPOINT.NUM): + for j in range(len(shifts)): + if j == 0: + lb = dr[w].argmax() + y, x = np.unravel_index(lb, dr[w].shape) + dr[w, y, x] = 0 + x -= border + y -= border + lb = dr[w].argmax() + py, px = np.unravel_index(lb, dr[w].shape) + dr[w, py, px] = 0 + px -= border + x + py -= border + y + ln = (px ** 2 + py ** 2) ** 0.5 + if ln > 1e-3: + x += shifts[j] * px / ln + y += shifts[j] * py / ln + x = max(0, min(x, cfg.OUTPUT_SHAPE[1] - 1)) + y = max(0, min(y, cfg.OUTPUT_SHAPE[0] - 1)) + kps[w] = np.array([x * 4 + 2, y * 4 + 2]) + scores[w, 0] = score_map[w, int(round(y) + 1e-9), \ + int(round(x) + 1e-9)] + # aligned or not ... + kps[:, 0] = kps[:, 0] / cfg.INPUT_SHAPE[1] * scales[i][0] + \ + centers[i][0] - scales[i][0] * 0.5 + kps[:, 1] = kps[:, 1] / cfg.INPUT_SHAPE[0] * scales[i][1] + \ + centers[i][1] - scales[i][1] * 0.5 + preds[i] = kps + maxvals[i] = scores + + return preds, maxvals + + +def compute_on_dataset(data_loader, device="cpu"): + results = list() + cpu_device = torch.device("cpu") + + results = list() + data = tqdm(data_loader) if is_main_process() else data_loader + k = 0 + for _, batch in enumerate(data): + imgs, scores, centers, scales, img_ids = batch + output_name='img_%d_%d_1.bin' %(int(img_ids[0]), k) + output_path=os.path.join('result/dumpOutput_device0/',output_name) + outputs = np.fromfile(output_path, dtype=np.float32).reshape(1,17,64,48) + k += 1 + + centers = np.array(centers) + scales = np.array(scales) + preds, maxvals = get_results(outputs, centers, scales, + cfg.TEST.GAUSSIAN_KERNEL, cfg.TEST.SHIFT_RATIOS) + + kp_scores = maxvals.squeeze(-1).mean(axis=1) + preds = np.concatenate((preds, maxvals), axis=2) + + for i in range(preds.shape[0]): + keypoints = preds[i].reshape(-1).tolist() + score = scores[i] * kp_scores[i] + image_id = img_ids[i] + + results.append(dict(image_id=image_id, + category_id=1, + keypoints=keypoints, + score=score)) + return results + + +def _accumulate_predictions_from_multiple_gpus(predictions_per_gpu, logger): + if is_main_process(): + logger.info("Accumulating ...") + all_predictions = all_gather(predictions_per_gpu) + + if not is_main_process(): + return + + predictions = list() + for p in all_predictions: + predictions.extend(p) + + return predictions + + +def inference(data_loader, logger, device="cpu"): + predictions = compute_on_dataset(data_loader, device) + synchronize() + predictions = _accumulate_predictions_from_multiple_gpus( + predictions, logger) + + if not is_main_process(): + return + + return predictions + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--local_rank", type=int, default=0) + parser.add_argument("--iter", "-i", type=int, default=-1) + parser.add_argument("--datasets_path",default="$MSPN_HOME/dataset/COCO") + args = parser.parse_args() + COCODataset.cur_dir=os.path.join(args.datasets_path) + num_gpus = int( + os.environ["WORLD_SIZE"]) if "WORLD_SIZE" in os.environ else 1 + distributed = num_gpus > 1 + + if distributed: + torch.cuda.set_device(args.local_rank) + dist.init_process_group(backend="nccl", init_method="env://") + synchronize() + + if is_main_process() and not os.path.exists(cfg.TEST_DIR): + os.mkdir(cfg.TEST_DIR) + logger = get_logger( + cfg.DATASET.NAME, cfg.TEST_DIR, args.local_rank, 'test_log.txt') + + if args.iter == -1: + logger.info("Please designate one iteration.") + + data_loader = get_test_loader(cfg, num_gpus, args.local_rank, 'val', + is_dist=distributed) + + device = 'cpu' + results = inference(data_loader, logger, device) + synchronize() + + if is_main_process(): + logger.info("Dumping results ...") + results.sort( + key=lambda res:(res['image_id'], res['score']), reverse=True) + results_path = os.path.join(cfg.TEST_DIR, 'results.json') + with open(results_path, 'w') as f: + json.dump(results, f) + logger.info("Get all results.") + + data_loader.ori_dataset.evaluate(results_path) + + +if __name__ == '__main__': + begin = time.time() + main() + end = time.time() print('postprocess finished in', str(end - begin), 'seconds') \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/MSPN_preprocess.py b/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/MSPN_preprocess.py index 616cf39bf5719fde0318acfc1944507b6ef611d1..cdc9cbb8987a27505944c156d5ff7acacb42fa7d 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/MSPN_preprocess.py +++ b/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/MSPN_preprocess.py @@ -1,90 +1,90 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -sys.path.append('./exps/mspn.2xstg.coco/') -import numpy as np -import torch -import torchvision.transforms as transforms -from dataset.attribute import load_dataset -from config import cfg - -from dataset.attribute import load_dataset -from dataset.COCO.coco import COCODataset - - -def preprocess(save_path: str): - cpu_device = torch.device("cpu") - normalize = transforms.Normalize(mean=cfg.INPUT.MEANS, std=cfg.INPUT.STDS) - transform = transforms.Compose([transforms.ToTensor(), normalize]) - attr = load_dataset(cfg.DATASET.NAME) - stage='val' - if cfg.DATASET.NAME == 'COCO': - Dataset = COCODataset - dataset = Dataset(attr, stage, transform) - # -------- make data_loader -------- # - class BatchCollator(object): - def __init__(self, size_divisible): - self.size_divisible = size_divisible - def __call__(self, batch): - transposed_batch = list(zip(*batch)) - images = torch.stack(transposed_batch[0], dim=0) - scores = list(transposed_batch[1]) - centers = list(transposed_batch[2]) - scales = list(transposed_batch[3]) - image_ids = list(transposed_batch[4]) - - return images, scores, centers, scales, image_ids - - data_loader = torch.utils.data.DataLoader( - dataset,batch_size=1,collate_fn=BatchCollator(cfg.DATALOADER.SIZE_DIVISIBILITY), ) - data_loader.ori_dataset = dataset - - data=data_loader - i = 0 - for _, batch in enumerate(data): - imgs, scores, centers, scales, img_ids = batch - print("=========",img_ids) - id=[str(x)for x in img_ids] - idx="".join(id) - imgs = imgs.to(cpu_device).numpy() - imgs.tofile(os.path.join(save_path,'img_' + idx + '_' + str(i)+ ".bin")) - i += 1 - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--datasets_path",default="$MSPN_HOME/dataset/COCO") - args = parser.parse_args() - COCODataset.cur_dir=os.path.join(args.datasets_path) - save_path = "./pre_dataset" - if not os.path.exists(save_path): - os.makedirs(save_path) - preprocess(save_path) - - - - - - - - - - - - - - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +sys.path.append('./exps/mspn.2xstg.coco/') +import numpy as np +import torch +import torchvision.transforms as transforms +from dataset.attribute import load_dataset +from config import cfg + +from dataset.attribute import load_dataset +from dataset.COCO.coco import COCODataset + + +def preprocess(save_path: str): + cpu_device = torch.device("cpu") + normalize = transforms.Normalize(mean=cfg.INPUT.MEANS, std=cfg.INPUT.STDS) + transform = transforms.Compose([transforms.ToTensor(), normalize]) + attr = load_dataset(cfg.DATASET.NAME) + stage='val' + if cfg.DATASET.NAME == 'COCO': + Dataset = COCODataset + dataset = Dataset(attr, stage, transform) + # -------- make data_loader -------- # + class BatchCollator(object): + def __init__(self, size_divisible): + self.size_divisible = size_divisible + def __call__(self, batch): + transposed_batch = list(zip(*batch)) + images = torch.stack(transposed_batch[0], dim=0) + scores = list(transposed_batch[1]) + centers = list(transposed_batch[2]) + scales = list(transposed_batch[3]) + image_ids = list(transposed_batch[4]) + + return images, scores, centers, scales, image_ids + + data_loader = torch.utils.data.DataLoader( + dataset,batch_size=1,collate_fn=BatchCollator(cfg.DATALOADER.SIZE_DIVISIBILITY), ) + data_loader.ori_dataset = dataset + + data=data_loader + i = 0 + for _, batch in enumerate(data): + imgs, scores, centers, scales, img_ids = batch + print("=========",img_ids) + id=[str(x)for x in img_ids] + idx="".join(id) + imgs = imgs.to(cpu_device).numpy() + imgs.tofile(os.path.join(save_path,'img_' + idx + '_' + str(i)+ ".bin")) + i += 1 + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--datasets_path",default="$MSPN_HOME/dataset/COCO") + args = parser.parse_args() + COCODataset.cur_dir=os.path.join(args.datasets_path) + save_path = "./pre_dataset" + if not os.path.exists(save_path): + os.makedirs(save_path) + preprocess(save_path) + + + + + + + + + + + + + + + diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/MSPN_pth2onnx.py b/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/MSPN_pth2onnx.py index 3624abdf8a083a3f79dee931c884e6e0e56045f3..86e36f5f6cad3ffdcb6993d84e30d68e5ece180d 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/MSPN_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/MSPN_pth2onnx.py @@ -1,53 +1,53 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -sys.path.append('./exps/mspn.2xstg.coco/') -import torch -from config import cfg -from network import MSPN -import torch.onnx - - -def main(): - - model = MSPN(cfg) - - model_file = os.path.join(cfg.OUTPUT_DIR, "mspn_2xstg_coco.pth") - if os.path.exists(model_file): - print('MSPN loaded') - state_dict = torch.load( - model_file, map_location=lambda storage, loc: storage) - state_dict = state_dict['model'] - model.load_state_dict(state_dict) - model.eval() - - dummy_input= torch.randn(32, 3, 256, 192) - dynamic_axes = {'input': {0: '-1'}, 'output': {0: '-1'}} - export_onnx_file = "MSPN.onnx" - torch.onnx.export(model, # model being run - dummy_input, # model input (or a tuple for multiple inputs) - export_onnx_file, # where to save the model (can be a file or file-like object) - export_params=True, # store the trained parameter weights inside the model file - opset_version=11, # the ONNX version to export the model to - do_constant_folding=True, # whether to execute constant folding for optimization - input_names = ['input'], # the model's input names - output_names = ['output'], # the model's output names - dynamic_axes=dynamic_axes, # variable lenght axes - ) - - -if __name__ == '__main__': - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +sys.path.append('./exps/mspn.2xstg.coco/') +import torch +from config import cfg +from network import MSPN +import torch.onnx + + +def main(): + + model = MSPN(cfg) + + model_file = os.path.join(cfg.OUTPUT_DIR, "mspn_2xstg_coco.pth") + if os.path.exists(model_file): + print('MSPN loaded') + state_dict = torch.load( + model_file, map_location=lambda storage, loc: storage) + state_dict = state_dict['model'] + model.load_state_dict(state_dict) + model.eval() + + dummy_input= torch.randn(32, 3, 256, 192) + dynamic_axes = {'input': {0: '-1'}, 'output': {0: '-1'}} + export_onnx_file = "MSPN.onnx" + torch.onnx.export(model, # model being run + dummy_input, # model input (or a tuple for multiple inputs) + export_onnx_file, # where to save the model (can be a file or file-like object) + export_params=True, # store the trained parameter weights inside the model file + opset_version=11, # the ONNX version to export the model to + do_constant_folding=True, # whether to execute constant folding for optimization + input_names = ['input'], # the model's input names + output_names = ['output'], # the model's output names + dynamic_axes=dynamic_axes, # variable lenght axes + ) + + +if __name__ == '__main__': + main() diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/README.md b/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/README.md index bbfc1e7e0c477c1f21d70ede1293a8dfe48417e4..230f66a204555f0a6c4a421b60a37f1eb63c2aa8 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/README.md +++ b/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/README.md @@ -1,64 +1,64 @@ -# MSPN模型PyTorch离线推理指导 - -## 1 环境准备 - -1. 下载源代码 - -``` -git clone https://github.com/megvii-research/MSPN -b master -cd MSPN -``` - -1. 设置环境变量,将当前目录设置为程序运行的主目录 - - ``` - export MSPN_HOME=$(pwd) - export PYTHONPATH=$PYTHONPATH:$MSPN_HOME - ``` - -3. 配置环境要求 - - ``` - pip3 install -r requirements.txt - ``` - -4. 下载COCOAPI - - ``` - git clone https://github.com/cocodataset/cocoapi.git $MSPN_HOME/lib/COCOAPI - cd $MSPN_HOME/lib/COCOAPI/PythonAPI - make install - ``` - -5. 下载数据集 - -(1)下载COCO2014数据集[COCO website][1], 将 train2014/val2014文件夹分别放在“$MSPN_HOME/dataset/COCO/images/” 目录下. - -(2)下载测试结果[Detection result][2], 把它放在“ $MSPN_HOME/dataset/COCO/det_json/”目录下. - -(3)将预训练好的权重文件 “mspn_2xstg_coco.pth”放在当前目录 - -6.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer),将benchmark.x86_64或benchmark.aarch64放到当前工作目录 - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 - -``` -bash test/pth2om.sh -bash test/test.sh -bash test/performance_test.sh -``` - -**评测结果:** - -| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| --------- | ----------- | --------------- | ---------- | ---------- | -| MSPN bs1 | 74.5 | 74.1 | 372.45fps | 401.74fps | -| MSPN bs16 | 74.5 | 74.1 | 712.271fps | 436.868fps | - -## 相关链接 - -[1]: http://cocodataset.org/#download -[2]: https://drive.google.com/open?id=1MW27OY_4YetEZ4JiD4PltFGL_1-caECy - +# MSPN模型PyTorch离线推理指导 + +## 1 环境准备 + +1. 下载源代码 + +``` +git clone https://github.com/megvii-research/MSPN -b master +cd MSPN +``` + +1. 设置环境变量,将当前目录设置为程序运行的主目录 + + ``` + export MSPN_HOME=$(pwd) + export PYTHONPATH=$PYTHONPATH:$MSPN_HOME + ``` + +3. 配置环境要求 + + ``` + pip3 install -r requirements.txt + ``` + +4. 下载COCOAPI + + ``` + git clone https://github.com/cocodataset/cocoapi.git $MSPN_HOME/lib/COCOAPI + cd $MSPN_HOME/lib/COCOAPI/PythonAPI + make install + ``` + +5. 下载数据集 + +(1)下载COCO2014数据集[COCO website][1], 将 train2014/val2014文件夹分别放在“$MSPN_HOME/dataset/COCO/images/” 目录下. + +(2)下载测试结果[Detection result][2], 把它放在“ $MSPN_HOME/dataset/COCO/det_json/”目录下. + +(3)将预训练好的权重文件 “mspn_2xstg_coco.pth”放在当前目录 + +6.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer),将benchmark.x86_64或benchmark.aarch64放到当前工作目录 + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 + +``` +bash test/pth2om.sh +bash test/test.sh +bash test/performance_test.sh +``` + +**评测结果:** + +| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| --------- | ----------- | --------------- | ---------- | ---------- | +| MSPN bs1 | 74.5 | 74.1 | 372.45fps | 401.74fps | +| MSPN bs16 | 74.5 | 74.1 | 712.271fps | 436.868fps | + +## 相关链接 + +[1]: http://cocodataset.org/#download +[2]: https://drive.google.com/open?id=1MW27OY_4YetEZ4JiD4PltFGL_1-caECy + diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/gen_dataset_info.py index 85c04dfdfca89e4e96277b5f86aaa34a63f2a818..72ba5e05c55918b06e9d5f235b9aae341ccbd87f 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/gen_dataset_info.py @@ -1,37 +1,37 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_info = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, info in enumerate(bin_info): - content = ' '.join([str(index), info, width, height]) - file.write(content) - file.write('\n') - - - - -if __name__ == '__main__': - file_path = sys.argv[1] - info_name = sys.argv[2] - width =sys.argv[3] - height =sys.argv[4] - get_bin_info(file_path, info_name, width, height) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_info = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, info in enumerate(bin_info): + content = ' '.join([str(index), info, width, height]) + file.write(content) + file.write('\n') + + + + +if __name__ == '__main__': + file_path = sys.argv[1] + info_name = sys.argv[2] + width =sys.argv[3] + height =sys.argv[4] + get_bin_info(file_path, info_name, width, height) diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/modelzoo_level.txt index 9e95396651cc4382fe60ee1ee053674f527a448c..27e6c78b37535fe4f5a17029546fe257ad164d34 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:POK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/test/perf_g.sh b/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/test/perf_g.sh index 0ebe93e395b2aa8a6c63b0f3c99fbf8df80c7e9f..047e1c667012b750e3425659c847e31aecae435f 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/test/perf_g.sh +++ b/ACL_PyTorch/contrib/cv/pose_estimation/MSPN/test/perf_g.sh @@ -1,23 +1,23 @@ -#!/bin/bash - -rm -rf perf_bs1.log -trtexec --onnx=MSPN.onnx --fp16 --shapes='input:1x3x256x192' –-fp16 --dumpProfile > perf_bs1.log -perf_str=`grep "GPU.* mean.*ms$" perf_bs1.log` -if [ -n "$perf_str" ]; then - perf_num=`echo $perf_str | awk -F' ' '{print $16}'` -else - perf_str=`grep "mean.*ms$" perf_bs1.log` - perf_num=`echo $perf_str | awk -F' ' '{print $4}'` -fi -awk 'BEGIN{printf "t4 bs1 fps:%.3f\n", 1000*1/('$perf_num'/1)}' - -rm -rf perf_bs16.log -trtexec --onnx=MSPN.onnx --fp16 --shapes='input:16x3x256x192' > perf_bs16.log -perf_str=`grep "GPU.* mean.*ms$" perf_bs16.log` -if [ -n "$perf_str" ]; then - perf_num=`echo $perf_str | awk -F' ' '{print $16}'` -else - perf_str=`grep "mean.*ms$" perf_bs16.log` - perf_num=`echo $perf_str | awk -F' ' '{print $4}'` -fi -awk 'BEGIN{printf "t4 bs16 fps:%.3f\n", 1000*1/('$perf_num'/16)}' +#!/bin/bash + +rm -rf perf_bs1.log +trtexec --onnx=MSPN.onnx --fp16 --shapes='input:1x3x256x192' –-fp16 --dumpProfile > perf_bs1.log +perf_str=`grep "GPU.* mean.*ms$" perf_bs1.log` +if [ -n "$perf_str" ]; then + perf_num=`echo $perf_str | awk -F' ' '{print $16}'` +else + perf_str=`grep "mean.*ms$" perf_bs1.log` + perf_num=`echo $perf_str | awk -F' ' '{print $4}'` +fi +awk 'BEGIN{printf "t4 bs1 fps:%.3f\n", 1000*1/('$perf_num'/1)}' + +rm -rf perf_bs16.log +trtexec --onnx=MSPN.onnx --fp16 --shapes='input:16x3x256x192' > perf_bs16.log +perf_str=`grep "GPU.* mean.*ms$" perf_bs16.log` +if [ -n "$perf_str" ]; then + perf_num=`echo $perf_str | awk -F' ' '{print $16}'` +else + perf_str=`grep "mean.*ms$" perf_bs16.log` + perf_num=`echo $perf_str | awk -F' ' '{print $4}'` +fi +awk 'BEGIN{printf "t4 bs16 fps:%.3f\n", 1000*1/('$perf_num'/16)}' diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/TransPose/fusion_switch.cfg b/ACL_PyTorch/contrib/cv/pose_estimation/TransPose/fusion_switch.cfg index 7e5b78e80e217d17734f1dbf689e8a3265689480..7635898ef0fc6b1361d848c5d2493f0c5a87f91d 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/TransPose/fusion_switch.cfg +++ b/ACL_PyTorch/contrib/cv/pose_estimation/TransPose/fusion_switch.cfg @@ -1,2 +1,2 @@ -ReshapeTransposeFusionPass:off +ReshapeTransposeFusionPass:off TransposeReshapeFusionPass:off \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/TransPose/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/pose_estimation/TransPose/modelzoo_level.txt index c80d660077532ade40fc6ae69b87f5e9c8462217..d5130dbf735d1a55ec0d55f24466fcaf4b7bf730 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/TransPose/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/pose_estimation/TransPose/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -ModelConvert:OK +FuncStatus:OK +PrecisionStatus:OK +ModelConvert:OK PerfStatus=OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/VideoPose3D/LISCENCE b/ACL_PyTorch/contrib/cv/pose_estimation/VideoPose3D/LISCENCE index df2c2f2c3e55bfbad1aebe53321a94ee5a3854bc..c8ec075d5b892f823d0b485ad4fdd01355c57b3e 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/VideoPose3D/LISCENCE +++ b/ACL_PyTorch/contrib/cv/pose_estimation/VideoPose3D/LISCENCE @@ -1,203 +1,203 @@ -Copyright 2018-2019 Open-MMLab. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2018-2019 Open-MMLab. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and +Copyright 2018-2019 Open-MMLab. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2019 Open-MMLab. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/VideoPose3D/README.md b/ACL_PyTorch/contrib/cv/pose_estimation/VideoPose3D/README.md index 41d22e57ece5533d3e67f99c141096ff34a39f3c..19035b4f89975a46457d45ca82d1ecbfb6c77026 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/VideoPose3D/README.md +++ b/ACL_PyTorch/contrib/cv/pose_estimation/VideoPose3D/README.md @@ -1,39 +1,39 @@ -# VideoPose3D 模型 Pytorch 离线推理 -## 1. 环境准备 -1. 必要的软件依赖 - - Pytorch == 1.5.0 - - torchvision == 0.5.0 - - msame 软件,安装在当前目录下 - - numpy -2. 获取、修改与安装开源软件代码 -在当前目录下,进行以下操作 -``` -git clone https://github.com/facebookresearch/VideoPose3D.git -cd VideoPose3D -git reset 1afb1ca0f1237776518469876342fc8669d3f6a9 --hard -patch -p1 < ../vp3d.patch -mkdir checkpoint -cd .. -``` -3. 获取权重文件 -将提供的 `model_best.bin` 文件放在 `.\VideoPose3D\checkpoint` 目录下 -4. 获取数据集 -将提供的 `data` 文件夹放在 `.\VideoPose3D` 目录下 -## 2. 离线推理 -310上执行,执行时使 `npu-smi info` 查看设备状态,确保 `device` 空闲 -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh -``` -### 评测结果 -| 模型 | 官网 pth 精度 | 310 离线推理精度 | 基准性能 | 310 性能 | -|:----:|:----:|:----:|:----:|:----:| -|VideoPose3D conv1d bs1| 46.8 mm| 46.5 mm | 584834 fps | 409776 fps | -|VideoPose3D conv2d bs1| - | 46.6 mm | 605179 fps | 580903 fps | - -备注: -- 310 离线推理使用的是我用单卡自行训练的 Model,效果好于官网 -- VideoPose3D 原本代码中全程使用 conv1d(以及相应的 batchnorm1d)。考虑到转 om 后 -的 conv1d 均由 conv2d 算子实现,因此我将源码中的 conv1d 以及相应操作全部替换为 conv2d -及其相应操作。这个修改使得在 Ascend 310 上的推理性能与原本代码在 GPU 上的推理性能持平 +# VideoPose3D 模型 Pytorch 离线推理 +## 1. 环境准备 +1. 必要的软件依赖 + - Pytorch == 1.5.0 + - torchvision == 0.5.0 + - msame 软件,安装在当前目录下 + - numpy +2. 获取、修改与安装开源软件代码 +在当前目录下,进行以下操作 +``` +git clone https://github.com/facebookresearch/VideoPose3D.git +cd VideoPose3D +git reset 1afb1ca0f1237776518469876342fc8669d3f6a9 --hard +patch -p1 < ../vp3d.patch +mkdir checkpoint +cd .. +``` +3. 获取权重文件 +将提供的 `model_best.bin` 文件放在 `.\VideoPose3D\checkpoint` 目录下 +4. 获取数据集 +将提供的 `data` 文件夹放在 `.\VideoPose3D` 目录下 +## 2. 离线推理 +310上执行,执行时使 `npu-smi info` 查看设备状态,确保 `device` 空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh +``` +### 评测结果 +| 模型 | 官网 pth 精度 | 310 离线推理精度 | 基准性能 | 310 性能 | +|:----:|:----:|:----:|:----:|:----:| +|VideoPose3D conv1d bs1| 46.8 mm| 46.5 mm | 584834 fps | 409776 fps | +|VideoPose3D conv2d bs1| - | 46.6 mm | 605179 fps | 580903 fps | + +备注: +- 310 离线推理使用的是我用单卡自行训练的 Model,效果好于官网 +- VideoPose3D 原本代码中全程使用 conv1d(以及相应的 batchnorm1d)。考虑到转 om 后 +的 conv1d 均由 conv2d 算子实现,因此我将源码中的 conv1d 以及相应操作全部替换为 conv2d +及其相应操作。这个修改使得在 Ascend 310 上的推理性能与原本代码在 GPU 上的推理性能持平 - 即便考虑到比较 conv2d 版本在 GPU 与 Acend310 上的性能,差距也小于二者在 conv1d 下的性能 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/pose_estimation/VideoPose3D/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/pose_estimation/VideoPose3D/modelzoo_level.txt index 38700fca05402f52c3ae1c4be0889eb60e1f80f1..2e42553460a4f3687654b6ad3f91ab0bcc3aadac 100644 --- a/ACL_PyTorch/contrib/cv/pose_estimation/VideoPose3D/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/pose_estimation/VideoPose3D/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/ADNet_postprocess.py b/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/ADNet_postprocess.py index 811f555e4e36c8e17b0edd0b65443b7cec32c6ee..f21d0790ac36b50f72471453335c6e6b7bee5aa8 100644 --- a/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/ADNet_postprocess.py +++ b/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/ADNet_postprocess.py @@ -1,91 +1,91 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import math -import torch -import torch.nn as nn -import numpy as np -from skimage.measure.simple_metrics import compare_psnr -import os -import struct -from torch.autograd import Variable -import glob -import sys - -def batch_PSNR(img, imclean, data_range): - Img = img.data.cpu().numpy().astype(np.float32) - Iclean = imclean.data.cpu().numpy().astype(np.float32) - PSNR = 0 - for i in range(Img.shape[0]): - PSNR += compare_psnr(Iclean[i,:,:,:], Img[i,:,:,:], data_range=data_range) - return (PSNR/Img.shape[0]) - -def get_output_path(bin_folder,label_path): - result_paths = [] - target_paths = [] - print("result_bin_folder:", bin_folder) - files_source = glob.glob(os.path.join(bin_folder,'*.bin')) - files_source.sort() - for file in files_source: - if file.endswith('.bin'): - result_path = file - result_paths.append(result_path) - name = (result_path.split('/')[3]).split('_')[0] - target_path = os.path.join(label_path,name+'.bin') - target_paths.append(target_path) - return result_paths,target_paths - -def file2tensor(output_bin,target_bin): - size = os.path.getsize(output_bin) - res1 = [] - L = int(size / 4) - binfile = open(output_bin, 'rb') - for i in range(L): - data = binfile.read(4) - num = struct.unpack('f', data) - res1.append(num[0]) - binfile.close() - dim_res = np.array(res1).reshape(1, 1, 321, 481) - tensor_res = torch.tensor(dim_res, dtype=torch.float32) - - size = os.path.getsize(target_bin) - res2 = [] - L = int(size / 4) - binfile = open(target_bin, 'rb') - for i in range(L): - data = binfile.read(4) - num = struct.unpack('f', data) - res2.append(num[0]) - binfile.close() - dim_res = np.array(res2).reshape(1, 1, 321, 481) - tensor_tar = torch.tensor(dim_res, dtype=torch.float32) - return tensor_res,tensor_tar - -def post_process(result_path,target_path): - output_path, target_path= get_output_path(bin_folder=result_path,label_path=label_path) - psnr_val = 0 - for i in range(len(output_path)): - output,target = file2tensor(output_path[i],target_path[i]) - Out = torch.clamp(output, 0., 1.) - psnr = batch_PSNR(Out, target, 1.) - name = (output_path[i].split('/')[3]).split('_')[0] - print(name,batch_PSNR(output, target, 1.)) - psnr_val += psnr - psnr_val /= i - print('average psnr_val:',psnr_val) - -if __name__ == "__main__": - result_path = sys.argv[1] - label_path = sys.argv[2] - post_process(result_path = result_path, target_path = label_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import math +import torch +import torch.nn as nn +import numpy as np +from skimage.measure.simple_metrics import compare_psnr +import os +import struct +from torch.autograd import Variable +import glob +import sys + +def batch_PSNR(img, imclean, data_range): + Img = img.data.cpu().numpy().astype(np.float32) + Iclean = imclean.data.cpu().numpy().astype(np.float32) + PSNR = 0 + for i in range(Img.shape[0]): + PSNR += compare_psnr(Iclean[i,:,:,:], Img[i,:,:,:], data_range=data_range) + return (PSNR/Img.shape[0]) + +def get_output_path(bin_folder,label_path): + result_paths = [] + target_paths = [] + print("result_bin_folder:", bin_folder) + files_source = glob.glob(os.path.join(bin_folder,'*.bin')) + files_source.sort() + for file in files_source: + if file.endswith('.bin'): + result_path = file + result_paths.append(result_path) + name = (result_path.split('/')[3]).split('_')[0] + target_path = os.path.join(label_path,name+'.bin') + target_paths.append(target_path) + return result_paths,target_paths + +def file2tensor(output_bin,target_bin): + size = os.path.getsize(output_bin) + res1 = [] + L = int(size / 4) + binfile = open(output_bin, 'rb') + for i in range(L): + data = binfile.read(4) + num = struct.unpack('f', data) + res1.append(num[0]) + binfile.close() + dim_res = np.array(res1).reshape(1, 1, 321, 481) + tensor_res = torch.tensor(dim_res, dtype=torch.float32) + + size = os.path.getsize(target_bin) + res2 = [] + L = int(size / 4) + binfile = open(target_bin, 'rb') + for i in range(L): + data = binfile.read(4) + num = struct.unpack('f', data) + res2.append(num[0]) + binfile.close() + dim_res = np.array(res2).reshape(1, 1, 321, 481) + tensor_tar = torch.tensor(dim_res, dtype=torch.float32) + return tensor_res,tensor_tar + +def post_process(result_path,target_path): + output_path, target_path= get_output_path(bin_folder=result_path,label_path=label_path) + psnr_val = 0 + for i in range(len(output_path)): + output,target = file2tensor(output_path[i],target_path[i]) + Out = torch.clamp(output, 0., 1.) + psnr = batch_PSNR(Out, target, 1.) + name = (output_path[i].split('/')[3]).split('_')[0] + print(name,batch_PSNR(output, target, 1.)) + psnr_val += psnr + psnr_val /= i + print('average psnr_val:',psnr_val) + +if __name__ == "__main__": + result_path = sys.argv[1] + label_path = sys.argv[2] + post_process(result_path = result_path, target_path = label_path) #get_output_path(bin_folder = 'result/dumpOutput_device0') \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/ADNet_preprocess.py b/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/ADNet_preprocess.py index 39aca261a2b0ffb6c91ba977673fa639b0603cda..edfcfaae983861844f8bbda3fefdc3f71c38c41b 100644 --- a/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/ADNet_preprocess.py +++ b/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/ADNet_preprocess.py @@ -1,65 +1,65 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import os.path -import numpy as np -import random -import torch -import cv2 -import glob -import torch.utils.data as udata -from utils import data_augmentation -from torch.autograd import Variable -import sys - -def normalize(data): - return data/255. - -def preprocess(data_path = './data/BSD68',save_path='./prep_dataset'): - files_source = glob.glob(os.path.join(data_path, '*.png')) - files_source.sort() - # process data - psnr_test = 0 - for f in files_source: - # image - Img = cv2.imread(f) - H = Img.shape[0] - W = Img.shape[1] - if H > W: - Img= cv2.flip(cv2.transpose(Img), 1) - Img = normalize(np.float32(Img[:,:,0])) - Img = np.expand_dims(Img, 0) - Img = np.expand_dims(Img, 1) - ISource = torch.Tensor(Img) - # noise - torch.manual_seed(0) #set the seed - noise = torch.FloatTensor(ISource.size()).normal_(mean=0, std=25/255.) - # noisy image - INoisy = ISource + noise - ISource = Variable(ISource) - INoisy = Variable(INoisy) - print(f,'has benn transformed into binary file') - name = (f.split('/')[3]).split('.')[0] - ISource = np.array(ISource).astype(np.float32) - if not os.path.exists(os.path.join(save_path,'ISoure')): - os.makedirs(os.path.join(save_path,'ISoure')) - if not os.path.exists(os.path.join(save_path,'INoisy')): - os.makedirs(os.path.join(save_path,'INoisy')) - ISource.tofile(os.path.join(save_path,'ISoure',name+'.bin')) - INoisy = np.array(INoisy).astype(np.float32) - INoisy.tofile(os.path.join(save_path,'INoisy',name+'.bin')) -if __name__ == '__main__': - data_path = sys.argv[1] - save_path = sys.argv[2] - preprocess(data_path,save_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import os.path +import numpy as np +import random +import torch +import cv2 +import glob +import torch.utils.data as udata +from utils import data_augmentation +from torch.autograd import Variable +import sys + +def normalize(data): + return data/255. + +def preprocess(data_path = './data/BSD68',save_path='./prep_dataset'): + files_source = glob.glob(os.path.join(data_path, '*.png')) + files_source.sort() + # process data + psnr_test = 0 + for f in files_source: + # image + Img = cv2.imread(f) + H = Img.shape[0] + W = Img.shape[1] + if H > W: + Img= cv2.flip(cv2.transpose(Img), 1) + Img = normalize(np.float32(Img[:,:,0])) + Img = np.expand_dims(Img, 0) + Img = np.expand_dims(Img, 1) + ISource = torch.Tensor(Img) + # noise + torch.manual_seed(0) #set the seed + noise = torch.FloatTensor(ISource.size()).normal_(mean=0, std=25/255.) + # noisy image + INoisy = ISource + noise + ISource = Variable(ISource) + INoisy = Variable(INoisy) + print(f,'has benn transformed into binary file') + name = (f.split('/')[3]).split('.')[0] + ISource = np.array(ISource).astype(np.float32) + if not os.path.exists(os.path.join(save_path,'ISoure')): + os.makedirs(os.path.join(save_path,'ISoure')) + if not os.path.exists(os.path.join(save_path,'INoisy')): + os.makedirs(os.path.join(save_path,'INoisy')) + ISource.tofile(os.path.join(save_path,'ISoure',name+'.bin')) + INoisy = np.array(INoisy).astype(np.float32) + INoisy.tofile(os.path.join(save_path,'INoisy',name+'.bin')) +if __name__ == '__main__': + data_path = sys.argv[1] + save_path = sys.argv[2] + preprocess(data_path,save_path) diff --git a/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/ADNet_pth2onnx.py b/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/ADNet_pth2onnx.py index 6c9de26ee21c4684afe6a1a0776d180e3a317de3..53f032df8e8a66043949284f819d2c44d250de8f 100644 --- a/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/ADNet_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/ADNet_pth2onnx.py @@ -1,49 +1,49 @@ - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -from models import ADNet -import torch -import torch.onnx -import sys -from collections import OrderedDict -def proc_nodes_module(checkpoint): - new_state_dict = OrderedDict() - for k, v in checkpoint.items(): - if "module." in k: - name = k.replace("module.", "") - else: - name = k - new_state_dict[name] = v - return new_state_dict - -def pth2onnx(path, output_file1): - net = ADNet(channels=1, num_of_layers=17) - model = net #model = nn.DataParallel(net, device_ids=device_ids).cuda() - checkpoint = torch.load(path, map_location='cpu') - checkpoint = proc_nodes_module(checkpoint) - model.load_state_dict(checkpoint) - model.eval() - input_names = ["image"] - output_names = ["output1"] - dynamic_axes = {'image': {0: '-1'}, 'output1': {0: '-1'}} - dummy_input1 = torch.randn(1, 1, 321, 481) - torch.onnx.export(model, dummy_input1, output_file1, input_names = input_names, dynamic_axes = dynamic_axes,output_names = output_names, opset_version=11, verbose=True) - print("ADNET onnx has transformed successfully and this model supports dynamic axes") - print('onnx export done.') - -if __name__ == "__main__": - path = sys.argv[1] - onnx_path = sys.argv[2] + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +from models import ADNet +import torch +import torch.onnx +import sys +from collections import OrderedDict +def proc_nodes_module(checkpoint): + new_state_dict = OrderedDict() + for k, v in checkpoint.items(): + if "module." in k: + name = k.replace("module.", "") + else: + name = k + new_state_dict[name] = v + return new_state_dict + +def pth2onnx(path, output_file1): + net = ADNet(channels=1, num_of_layers=17) + model = net #model = nn.DataParallel(net, device_ids=device_ids).cuda() + checkpoint = torch.load(path, map_location='cpu') + checkpoint = proc_nodes_module(checkpoint) + model.load_state_dict(checkpoint) + model.eval() + input_names = ["image"] + output_names = ["output1"] + dynamic_axes = {'image': {0: '-1'}, 'output1': {0: '-1'}} + dummy_input1 = torch.randn(1, 1, 321, 481) + torch.onnx.export(model, dummy_input1, output_file1, input_names = input_names, dynamic_axes = dynamic_axes,output_names = output_names, opset_version=11, verbose=True) + print("ADNET onnx has transformed successfully and this model supports dynamic axes") + print('onnx export done.') + +if __name__ == "__main__": + path = sys.argv[1] + onnx_path = sys.argv[2] pth2onnx(path, onnx_path) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/README.md b/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/README.md index 53bb64a0106b4004a65037b5af9d87c573974d03..e01ab9524216a826503c326e0a49e7df4ab027ab 100644 --- a/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/README.md +++ b/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/README.md @@ -1,296 +1,296 @@ -# ADNet推理说明 - -## 1 模型概述 - -- **[论文地址](https://www.sciencedirect.com/science/article/pii/S0893608019304241)** -- **[代码地址](https://github.com/hellloxiaotian/ADNet)** - -### 1.1 论文地址 - -[ADNet论文](https://www.sciencedirect.com/science/article/pii/S0893608019304241) - -### 1.2 代码地址 - -[ADNet代码](https://github.com/hellloxiaotian/ADNet) - -branch:master - -commitid:commit 997df8f0cd5cebe2d26a1468c866dd927512686f - - -## 2 环境说明 - -- 深度学习框架 -- python第三方库 - -### 2.1 深度学习框架 - -``` -python3.7.5 -CANN 5.0.2 - -pytorch == 1.5.0 -torchvision == 0.5.0 -onnx == 1.7.0 -onnx-simplifier == 0.3.6 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.21.2 -Pillow == 8.3.0 -opencv-python == 4.5.3.56 -scikit-image==0.16.2 -``` - -## 3 模型转换 - -- pth转om模型 - -### 3.1 pth转om模型 - -1.获取pth权重文件 - -[pth权重文件](https://github.com/hellloxiaotian/ADNet/blob/master/gray/g25/model_70.pth -) md5sum:7a93fb1f437cbce0fd235daaa7b9cffd - -2.下载ADNet推理代码 - -``` -git clone https://gitee.com/wang-chaojiemayj/modelzoo.git -cd modelzoo -git checkout tuili -``` -进入ADNet目录 -``` -cd ./contrib/ACL_PyTorch/Research/cv/quality_enhancement/ADnet -``` -3.pth模型转onnx模型,onnx转成om模型 - -pth模型转onnx模型 -``` -python3.7.5 ADNet_pth2onnx.py model_70.pth ADNet.onnx -``` -onnx转出om -``` -source env.sh(注意,latest是一个软连接,请将服务器中的/usr/local/Ascend/ascend-toolkit/latest 指向5.0.2版本的CANN包) -# bs1 -atc --framework=5 --model=ADNet.onnx --output=ADNet_bs1 --input_format=NCHW --input_shape="image:1,1,321,481" --log=debug --soc_version=Ascend310 -#bs16 -atc --framework=5 --model=ADNet.onnx --output=ADNet_bs16 --input_format=NCHW --input_shape="image:16,1,321,481" --log=debug --soc_version=Ascend310 -``` - -## 4 数据集预处理 - -- 数据集获取 -- 数据预处理 -- 生成数据集信息文件 - -### 4.1 数据集获取 - -本模型支持BSD68数据集共68张数据集,可从百度云盘下载 - -链接:https://pan.baidu.com/s/1XiePOuutbAuKRRTV949FlQ -提取码:0315 - -文件结构如下 - -``` -|ADNet--test -| | |--pth2om.sh -| | |--perf_t4.sh -| | |--parse.py -| | |--eval_acc_perf.sh -| |--datset -| | |--BSD68 -| |--prep_dataset -| | |--ISoure -| | |--INoisy -| |--util.py -| |--requirements.tx -| |--models.py -| |--gen_dataset_info.py -| |--env.sh -| |--ADNet_pth2onnx.py -| |--ADNet_preprocess.py -| |--ADNet_postprocess.py -``` - - -### 4.2 数据集预处理 - -运行ADNet_preprocess.py -``` -python3.7.5 ADNet_preprocess.py ./dataset/BSD68 ./prep_dataset -``` -二进制文件将保存在./prep_dataset目录下 - -### 4.3 生成数据集信息文件 - -1.执行生成数据集信息脚本gen_dataset_info.py,生成数据集信息文件 - -``` -python3.7.5 gen_dataset_info.py ./prep_dataset/INoisy ADNet_prep_bin.info 481 321 -``` - -## 5 离线推理 - -- benchmark工具概述 -- 离线推理 - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.1 推理benchmark工具用户指南 01 - -### 5.2 离线推理 - -1.设置环境变量 - -``` -source env.sh -``` - -2.执行离线推理 - -``` -bs1: -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./ADNet_bs1.om -input_text_path=./ADNet_prep_bin.info -input_width=481 -input_height=321 -output_binary=True -useDvpp=False -bs16: -./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=16 -om_path=./ADNet_bs16.om -input_text_path=./ADNet_prep_bin.info -input_width=481 -input_height=321 -output_binary=True -useDvpp=False -``` - -输出结果分别保存在当前目录result/dumpOutput_device0和result/dumpOutput_device1中,模型的输出有三个,其中需要的是名为output1的输出,shape为(1,19,1024,2048)(NCHW),数据类型为FP16,每个输入对应的输出对应三个_x.bin(x代表1,2,3)文件。 - -## 6 精度对比 - -- 离线推理精度 -- 开源精度 -- 开源精度对比 - -### 6.1 离线推理精度统计 - -后处理统计PSNR精度 - -调用ADNet_postprocess.py脚本推理结果与label比对,获取PSNRj精度数据,结果保存在ADNet_bs1.log和ADNet_bs4.log - -``` -python3.7.5 -u ADNet_postprocess.py ./result/dumpOutput_device0 ./prep_dataset/ISoure ./out >ADNet_bs1.log -python3.7.5 -u ADNet_postprocess.py ./result/dumpOutput_device1 ./prep_dataset/ISoure ./out >ADNet_bs16.log -``` - -第一个为benchmark输出目录,第二个标签目录,第三个为重定向输出目录 - -``` -PSNR:29.68 -``` - -经过对bs1与bs6的om测试,本模型batch1的精度与batch4的精度一致,精度数据如上 -### 6.2 开源精度 - -pth精度 - -``` -Model 论文 开源pth文件 -ADNet 29.27 29.25 -``` - -### 6.3 精度对比 - -将得到的om模型离线推理精度与pth精度作比较,om模型精度高于pth模型精度,精度达标。 - -## 7 性能对比 - -- NPU性能数据 -- T4性能数据 -- 性能对比 - -### 7.1 npu性能数据 - -1.benchmark工具在整个数据集上推理获得性能数据。 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: - -``` ------------------Performance Summary------------------ -[e2e] throughputRate: 21.1584, latency: 3213.85 -[data read] throughputRate: 2267.5, moduleLatency: 0.441015 -[preprocess] throughputRate: 613.431, moduleLatency: 1.63018 -[inference] throughputRate: 33.8299, Interface throughputRate: 35.7852, moduleLatency: 29.1051 -[postprocess] throughputRate: 34.309, moduleLatency: 29.1469 - ------------------------------------------------------------ -``` - -Interface throughputRate: 35.7852,35.7852x4=143.1408即是batch1 310单卡吞吐率 - -batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: - -``` ------------------Performance Summary------------------ -[e2e] throughputRate: 19.8971, latency: 3417.58 -[data read] throughputRate: 2382.7, moduleLatency: 0.419691 -[preprocess] throughputRate: 405.505, moduleLatency: 2.46606 -[inference] throughputRate: 27.4387, Interface throughputRate: 29.3584, moduleLatency: 35.5952 -[postprocess] throughputRate: 2.40737, moduleLatency: 415.392 - ------------------------------------------------------------ -``` - -Interface throughputRate: 29.3584,29.3584x4=117.4336即是batch16 310单卡吞吐率 - - -### 7.2 T4性能数据 - -在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2 -batch1性能: - -``` -trtexec --onnx=ADNet.onnx --fp16 --shapes=image:1x1x321x481 --threads -``` - -``` -[09/27/2021-11:20:55] [I] GPU Compute -[09/27/2021-11:20:55] [I] min: 7.94897 ms -[09/27/2021-11:20:55] [I] max: 12.2207 ms -[09/27/2021-11:20:55] [I] mean: 8.39391 ms -[09/27/2021-11:20:55] [I] median: 8.30371 ms -[09/27/2021-11:20:55] [I] percentile: 11.1882 ms at 99% -[09/27/2021-11:20:55] [I] total compute time: 3.01341 s -``` -batch1 t4单卡吞吐率:1000/(8.39391/1)=119.134fps - -batch16性能: - -``` -trtexec --onnx=ADNet.onnx --fp16 --shapes=image:16x1x321x481 --threads -``` - -``` -[09/27/2021-11:28:53] [I] GPU Compute -[09/27/2021-11:28:53] [I] min: 125.424 ms -[09/27/2021-11:28:53] [I] max: 138.322 ms -[09/27/2021-11:28:53] [I] mean: 128.206 ms -[09/27/2021-11:28:53] [I] median: 126.907 ms -[09/27/2021-11:28:53] [I] percentile: 138.322 ms at 99% -[09/27/2021-11:28:53] [I] total compute time: 3.33335 s -``` - -batch4 t4单卡吞吐率:1000/(128.206/16)=124.799fps - -### 7.3 性能对比 - -batch1:35.7852x4 > 1000/(8.39391/1) -batch16:29.3584x4 < 000/(128.206/16) -310单个device的吞吐率乘4即单卡吞吐率与比T4单卡相比,batch1的性能:310高于T4,batch16的性能:310是T4的0.954倍,略低于T4。该模型放在contrib/ACL_PyTorch/Research目录下。 - -310与T4同时使用纯推理对batch16进行性能测试,310性能如下: - -``` ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 36.1295samples/s, ave_latency: 27.6788ms ----------------------------------------------------------------- -``` - -batch16纯推理的性能为:36.1295x4=144.518fps - -144.518>124.799,在纯推理测试性能的情况下,310性能优于T4性能。 +# ADNet推理说明 + +## 1 模型概述 + +- **[论文地址](https://www.sciencedirect.com/science/article/pii/S0893608019304241)** +- **[代码地址](https://github.com/hellloxiaotian/ADNet)** + +### 1.1 论文地址 + +[ADNet论文](https://www.sciencedirect.com/science/article/pii/S0893608019304241) + +### 1.2 代码地址 + +[ADNet代码](https://github.com/hellloxiaotian/ADNet) + +branch:master + +commitid:commit 997df8f0cd5cebe2d26a1468c866dd927512686f + + +## 2 环境说明 + +- 深度学习框架 +- python第三方库 + +### 2.1 深度学习框架 + +``` +python3.7.5 +CANN 5.0.2 + +pytorch == 1.5.0 +torchvision == 0.5.0 +onnx == 1.7.0 +onnx-simplifier == 0.3.6 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.21.2 +Pillow == 8.3.0 +opencv-python == 4.5.3.56 +scikit-image==0.16.2 +``` + +## 3 模型转换 + +- pth转om模型 + +### 3.1 pth转om模型 + +1.获取pth权重文件 + +[pth权重文件](https://github.com/hellloxiaotian/ADNet/blob/master/gray/g25/model_70.pth +) md5sum:7a93fb1f437cbce0fd235daaa7b9cffd + +2.下载ADNet推理代码 + +``` +git clone https://gitee.com/wang-chaojiemayj/modelzoo.git +cd modelzoo +git checkout tuili +``` +进入ADNet目录 +``` +cd ./contrib/ACL_PyTorch/Research/cv/quality_enhancement/ADnet +``` +3.pth模型转onnx模型,onnx转成om模型 + +pth模型转onnx模型 +``` +python3.7.5 ADNet_pth2onnx.py model_70.pth ADNet.onnx +``` +onnx转出om +``` +source env.sh(注意,latest是一个软连接,请将服务器中的/usr/local/Ascend/ascend-toolkit/latest 指向5.0.2版本的CANN包) +# bs1 +atc --framework=5 --model=ADNet.onnx --output=ADNet_bs1 --input_format=NCHW --input_shape="image:1,1,321,481" --log=debug --soc_version=Ascend310 +#bs16 +atc --framework=5 --model=ADNet.onnx --output=ADNet_bs16 --input_format=NCHW --input_shape="image:16,1,321,481" --log=debug --soc_version=Ascend310 +``` + +## 4 数据集预处理 + +- 数据集获取 +- 数据预处理 +- 生成数据集信息文件 + +### 4.1 数据集获取 + +本模型支持BSD68数据集共68张数据集,可从百度云盘下载 + +链接:https://pan.baidu.com/s/1XiePOuutbAuKRRTV949FlQ +提取码:0315 + +文件结构如下 + +``` +|ADNet--test +| | |--pth2om.sh +| | |--perf_t4.sh +| | |--parse.py +| | |--eval_acc_perf.sh +| |--datset +| | |--BSD68 +| |--prep_dataset +| | |--ISoure +| | |--INoisy +| |--util.py +| |--requirements.tx +| |--models.py +| |--gen_dataset_info.py +| |--env.sh +| |--ADNet_pth2onnx.py +| |--ADNet_preprocess.py +| |--ADNet_postprocess.py +``` + + +### 4.2 数据集预处理 + +运行ADNet_preprocess.py +``` +python3.7.5 ADNet_preprocess.py ./dataset/BSD68 ./prep_dataset +``` +二进制文件将保存在./prep_dataset目录下 + +### 4.3 生成数据集信息文件 + +1.执行生成数据集信息脚本gen_dataset_info.py,生成数据集信息文件 + +``` +python3.7.5 gen_dataset_info.py ./prep_dataset/INoisy ADNet_prep_bin.info 481 321 +``` + +## 5 离线推理 + +- benchmark工具概述 +- 离线推理 + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.1 推理benchmark工具用户指南 01 + +### 5.2 离线推理 + +1.设置环境变量 + +``` +source env.sh +``` + +2.执行离线推理 + +``` +bs1: +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=./ADNet_bs1.om -input_text_path=./ADNet_prep_bin.info -input_width=481 -input_height=321 -output_binary=True -useDvpp=False +bs16: +./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=16 -om_path=./ADNet_bs16.om -input_text_path=./ADNet_prep_bin.info -input_width=481 -input_height=321 -output_binary=True -useDvpp=False +``` + +输出结果分别保存在当前目录result/dumpOutput_device0和result/dumpOutput_device1中,模型的输出有三个,其中需要的是名为output1的输出,shape为(1,19,1024,2048)(NCHW),数据类型为FP16,每个输入对应的输出对应三个_x.bin(x代表1,2,3)文件。 + +## 6 精度对比 + +- 离线推理精度 +- 开源精度 +- 开源精度对比 + +### 6.1 离线推理精度统计 + +后处理统计PSNR精度 + +调用ADNet_postprocess.py脚本推理结果与label比对,获取PSNRj精度数据,结果保存在ADNet_bs1.log和ADNet_bs4.log + +``` +python3.7.5 -u ADNet_postprocess.py ./result/dumpOutput_device0 ./prep_dataset/ISoure ./out >ADNet_bs1.log +python3.7.5 -u ADNet_postprocess.py ./result/dumpOutput_device1 ./prep_dataset/ISoure ./out >ADNet_bs16.log +``` + +第一个为benchmark输出目录,第二个标签目录,第三个为重定向输出目录 + +``` +PSNR:29.68 +``` + +经过对bs1与bs6的om测试,本模型batch1的精度与batch4的精度一致,精度数据如上 +### 6.2 开源精度 + +pth精度 + +``` +Model 论文 开源pth文件 +ADNet 29.27 29.25 +``` + +### 6.3 精度对比 + +将得到的om模型离线推理精度与pth精度作比较,om模型精度高于pth模型精度,精度达标。 + +## 7 性能对比 + +- NPU性能数据 +- T4性能数据 +- 性能对比 + +### 7.1 npu性能数据 + +1.benchmark工具在整个数据集上推理获得性能数据。 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: + +``` +-----------------Performance Summary------------------ +[e2e] throughputRate: 21.1584, latency: 3213.85 +[data read] throughputRate: 2267.5, moduleLatency: 0.441015 +[preprocess] throughputRate: 613.431, moduleLatency: 1.63018 +[inference] throughputRate: 33.8299, Interface throughputRate: 35.7852, moduleLatency: 29.1051 +[postprocess] throughputRate: 34.309, moduleLatency: 29.1469 + +----------------------------------------------------------- +``` + +Interface throughputRate: 35.7852,35.7852x4=143.1408即是batch1 310单卡吞吐率 + +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: + +``` +-----------------Performance Summary------------------ +[e2e] throughputRate: 19.8971, latency: 3417.58 +[data read] throughputRate: 2382.7, moduleLatency: 0.419691 +[preprocess] throughputRate: 405.505, moduleLatency: 2.46606 +[inference] throughputRate: 27.4387, Interface throughputRate: 29.3584, moduleLatency: 35.5952 +[postprocess] throughputRate: 2.40737, moduleLatency: 415.392 + +----------------------------------------------------------- +``` + +Interface throughputRate: 29.3584,29.3584x4=117.4336即是batch16 310单卡吞吐率 + + +### 7.2 T4性能数据 + +在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2 +batch1性能: + +``` +trtexec --onnx=ADNet.onnx --fp16 --shapes=image:1x1x321x481 --threads +``` + +``` +[09/27/2021-11:20:55] [I] GPU Compute +[09/27/2021-11:20:55] [I] min: 7.94897 ms +[09/27/2021-11:20:55] [I] max: 12.2207 ms +[09/27/2021-11:20:55] [I] mean: 8.39391 ms +[09/27/2021-11:20:55] [I] median: 8.30371 ms +[09/27/2021-11:20:55] [I] percentile: 11.1882 ms at 99% +[09/27/2021-11:20:55] [I] total compute time: 3.01341 s +``` +batch1 t4单卡吞吐率:1000/(8.39391/1)=119.134fps + +batch16性能: + +``` +trtexec --onnx=ADNet.onnx --fp16 --shapes=image:16x1x321x481 --threads +``` + +``` +[09/27/2021-11:28:53] [I] GPU Compute +[09/27/2021-11:28:53] [I] min: 125.424 ms +[09/27/2021-11:28:53] [I] max: 138.322 ms +[09/27/2021-11:28:53] [I] mean: 128.206 ms +[09/27/2021-11:28:53] [I] median: 126.907 ms +[09/27/2021-11:28:53] [I] percentile: 138.322 ms at 99% +[09/27/2021-11:28:53] [I] total compute time: 3.33335 s +``` + +batch4 t4单卡吞吐率:1000/(128.206/16)=124.799fps + +### 7.3 性能对比 + +batch1:35.7852x4 > 1000/(8.39391/1) +batch16:29.3584x4 < 000/(128.206/16) +310单个device的吞吐率乘4即单卡吞吐率与比T4单卡相比,batch1的性能:310高于T4,batch16的性能:310是T4的0.954倍,略低于T4。该模型放在contrib/ACL_PyTorch/Research目录下。 + +310与T4同时使用纯推理对batch16进行性能测试,310性能如下: + +``` +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 36.1295samples/s, ave_latency: 27.6788ms +---------------------------------------------------------------- +``` + +batch16纯推理的性能为:36.1295x4=144.518fps + +144.518>124.799,在纯推理测试性能的情况下,310性能优于T4性能。 diff --git a/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/gen_dataset_info.py index 4230a0ef58290160bf2302a57fc9950d2ec40892..b3349fd4786e00f5480c6ff074f5aa9c5f9876be 100644 --- a/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/gen_dataset_info.py @@ -1,39 +1,39 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import argparse -import glob -import sys - -def get_bin_info(img_root_path='./prep_dataset/INoisy', - info_name='ADNet_prep_bin.info', width='481', height='321'): - img_path = [] - files_source = glob.glob(os.path.join(img_root_path,'*.bin')) - files_source.sort() - for file in files_source: - if file.endswith('.bin'): - imgpath = file - img_path.append(imgpath) - with open(info_name, 'w') as fp: - for index in range(len(img_path)): - content = ' '.join([str(index), img_path[index], width, height]) - fp.write(content) - fp.write('\n') - -if __name__ == '__main__': - dataset_bin = sys.argv[1] - info_name = sys.argv[2] - width = sys.argv[3] - height = sys.argv[4] - get_bin_info(img_root_path=dataset_bin, info_name=info_name, width=width, height=height) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import argparse +import glob +import sys + +def get_bin_info(img_root_path='./prep_dataset/INoisy', + info_name='ADNet_prep_bin.info', width='481', height='321'): + img_path = [] + files_source = glob.glob(os.path.join(img_root_path,'*.bin')) + files_source.sort() + for file in files_source: + if file.endswith('.bin'): + imgpath = file + img_path.append(imgpath) + with open(info_name, 'w') as fp: + for index in range(len(img_path)): + content = ' '.join([str(index), img_path[index], width, height]) + fp.write(content) + fp.write('\n') + +if __name__ == '__main__': + dataset_bin = sys.argv[1] + info_name = sys.argv[2] + width = sys.argv[3] + height = sys.argv[4] + get_bin_info(img_root_path=dataset_bin, info_name=info_name, width=width, height=height) diff --git a/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/test/parse.py b/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/test/parse.py index 1841a9747c1da500ef5f9e0e0368ec324be08595..e071d8fecf850996e9527d39d0e7d0f4d83ad14e 100644 --- a/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/test/parse.py +++ b/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet/test/parse.py @@ -1,39 +1,39 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import sys -import re - -def get_acc(filename): - with open(filename, 'r') as f: - lines = f.readlines() - last_line = lines[-1] - psnr = last_line.split(" ")[2] - print(filename.split('.')[0],"Average PSNR:", psnr) - - -def get_perf(filename): - with open(filename, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 - print('310 bs{} fps:{}'.format(filename.split('_')[3], fps)) - -if __name__ == "__main__": - - filename = sys.argv[1] - - if filename.endswith(".log"): - get_acc(filename) - elif filename.endswith(".txt"): +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +import re + +def get_acc(filename): + with open(filename, 'r') as f: + lines = f.readlines() + last_line = lines[-1] + psnr = last_line.split(" ")[2] + print(filename.split('.')[0],"Average PSNR:", psnr) + + +def get_perf(filename): + with open(filename, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 + print('310 bs{} fps:{}'.format(filename.split('_')[3], fps)) + +if __name__ == "__main__": + + filename = sys.argv[1] + + if filename.endswith(".log"): + get_acc(filename) + elif filename.endswith(".txt"): get_perf(filename) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/3d_nested_unet_postprocess.py b/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/3d_nested_unet_postprocess.py index 023869fa0adbf04bb38e73feb28298d42d0f7f6c..08233a7d901937460f6c98175b3a16f3fcfa9333 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/3d_nested_unet_postprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/3d_nested_unet_postprocess.py @@ -1,39 +1,39 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# 3d_nested_unet_postprocess.py -import sys -import os -import time -import pdb -import argparse -from nnunet.inference import predict_simple2 - - -def main(): - # pdb.set_trace() - parser = argparse.ArgumentParser() - parser.add_argument('-fp', '--file_path', help='output bin files path', required=True) - args = parser.parse_args() - python_file = predict_simple2.__file__ # /home/hyp/UNetPlusPlus/pytorch/nnunet/inference/predict_simple2.py - file_path = args.file_path - pre_mode = 2 - command = 'python3 ' + str(python_file) + ' --pre_mode ' + str(pre_mode) + ' --file_path ' + str(file_path) - os.system(command) - - -if __name__ == "__main__": - main() - print('main end') - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 3d_nested_unet_postprocess.py +import sys +import os +import time +import pdb +import argparse +from nnunet.inference import predict_simple2 + + +def main(): + # pdb.set_trace() + parser = argparse.ArgumentParser() + parser.add_argument('-fp', '--file_path', help='output bin files path', required=True) + args = parser.parse_args() + python_file = predict_simple2.__file__ # /home/hyp/UNetPlusPlus/pytorch/nnunet/inference/predict_simple2.py + file_path = args.file_path + pre_mode = 2 + command = 'python3 ' + str(python_file) + ' --pre_mode ' + str(pre_mode) + ' --file_path ' + str(file_path) + os.system(command) + + +if __name__ == "__main__": + main() + print('main end') + diff --git a/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/3d_nested_unet_preprocess.py b/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/3d_nested_unet_preprocess.py index 143fb939b116e7d44c7dc316584fe84b9156a3f2..f20ba2697bee8eceff58b6385f9574b2f10ada70 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/3d_nested_unet_preprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/3d_nested_unet_preprocess.py @@ -1,39 +1,39 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# 3d_nested_unet_preprocess.py -import sys -import os -import time -import pdb -import argparse -from nnunet.inference import predict_simple2 - - -def main(): - # pdb.set_trace() - parser = argparse.ArgumentParser() - parser.add_argument('-fp', '--file_path', help='input bin files path', required=True) - args = parser.parse_args() - python_file = predict_simple2.__file__ # /home/hyp/UNetPlusPlus/pytorch/nnunet/inference/predict_simple2.py - file_path = args.file_path - pre_mode = 1 - command = 'python3 ' + str(python_file) + ' --pre_mode ' + str(pre_mode) + ' --file_path ' + str(file_path) - os.system(command) - - -if __name__ == "__main__": - main() - print('main end') - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 3d_nested_unet_preprocess.py +import sys +import os +import time +import pdb +import argparse +from nnunet.inference import predict_simple2 + + +def main(): + # pdb.set_trace() + parser = argparse.ArgumentParser() + parser.add_argument('-fp', '--file_path', help='input bin files path', required=True) + args = parser.parse_args() + python_file = predict_simple2.__file__ # /home/hyp/UNetPlusPlus/pytorch/nnunet/inference/predict_simple2.py + file_path = args.file_path + pre_mode = 1 + command = 'python3 ' + str(python_file) + ' --pre_mode ' + str(pre_mode) + ' --file_path ' + str(file_path) + os.system(command) + + +if __name__ == "__main__": + main() + print('main end') + diff --git a/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/3d_nested_unet_pth2onnx.py b/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/3d_nested_unet_pth2onnx.py index 0d8e115f5bd1c2f6919069e2ed6807b4cf7819bb..4aaaa6d67a655c2d4c598e4a2d5d9d4c0b8c002f 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/3d_nested_unet_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/3d_nested_unet_pth2onnx.py @@ -1,57 +1,57 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# 3d_nested_unet_pth2onnx.py -import sys -import os -import time -import pdb -import argparse -from batchgenerators.utilities.file_and_folder_operations import join, isdir -from nnunet.paths import default_plans_identifier, network_training_output_dir, default_cascade_trainer, default_trainer -from nnunet.training.model_restore import load_model_and_checkpoint_files -from nnunet.inference.predict2 import pth2onnx - - -def main(): - # pdb.set_trace() - parser = argparse.ArgumentParser() - parser.add_argument('-fp', '--file_path', help='output onnx file path', required=True) - args = parser.parse_args() - fp = args.file_path - model = '3d_fullres' - task_name = 'Task003_Liver' - trainer = 'nnUNetPlusPlusTrainerV2' - plans_identifier = 'nnUNetPlansv2.1' - model_folder_name = join(network_training_output_dir, model, task_name, trainer + "__" + plans_identifier) - model = model_folder_name - folds = None # 如果文件存放路径正确,会自动识别到教程中的fold 0 - mixed_precision = True - checkpoint_name = 'model_final_checkpoint' - trainer, params = load_model_and_checkpoint_files(model, folds, mixed_precision=mixed_precision, checkpoint_name=checkpoint_name) - pre_mode = -1 - if int(pre_mode) == -1: - p = params[0] - trainer.load_checkpoint_ram(p, False) # nnUnetPlusPlusTrainerV2,实际函数在network_trainer里 - print('pth2onnx start') - pth2onnx(trainer.network, fp) - print('pth2onnx end') - print('onnx模型已经输出至:', fp) - - -if __name__ == "__main__": - main() - print('main end') - - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 3d_nested_unet_pth2onnx.py +import sys +import os +import time +import pdb +import argparse +from batchgenerators.utilities.file_and_folder_operations import join, isdir +from nnunet.paths import default_plans_identifier, network_training_output_dir, default_cascade_trainer, default_trainer +from nnunet.training.model_restore import load_model_and_checkpoint_files +from nnunet.inference.predict2 import pth2onnx + + +def main(): + # pdb.set_trace() + parser = argparse.ArgumentParser() + parser.add_argument('-fp', '--file_path', help='output onnx file path', required=True) + args = parser.parse_args() + fp = args.file_path + model = '3d_fullres' + task_name = 'Task003_Liver' + trainer = 'nnUNetPlusPlusTrainerV2' + plans_identifier = 'nnUNetPlansv2.1' + model_folder_name = join(network_training_output_dir, model, task_name, trainer + "__" + plans_identifier) + model = model_folder_name + folds = None # 如果文件存放路径正确,会自动识别到教程中的fold 0 + mixed_precision = True + checkpoint_name = 'model_final_checkpoint' + trainer, params = load_model_and_checkpoint_files(model, folds, mixed_precision=mixed_precision, checkpoint_name=checkpoint_name) + pre_mode = -1 + if int(pre_mode) == -1: + p = params[0] + trainer.load_checkpoint_ram(p, False) # nnUnetPlusPlusTrainerV2,实际函数在network_trainer里 + print('pth2onnx start') + pth2onnx(trainer.network, fp) + print('pth2onnx end') + print('onnx模型已经输出至:', fp) + + +if __name__ == "__main__": + main() + print('main end') + + diff --git a/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/License b/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/License index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/License +++ b/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/License @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/change_infer_path.py b/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/change_infer_path.py index a46e74d40f8dc8098a83065c29ab26a6ea59dc94..e030312b1751f3cf3fd0acf8f3c0c64c6a4647d3 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/change_infer_path.py +++ b/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/change_infer_path.py @@ -1,61 +1,61 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# 3d_nested_unet_preprocess.py -import sys -import os -import time -import pdb -import argparse -from nnunet.inference import infer_path - - -def main(): - # pdb.set_trace() - parser = argparse.ArgumentParser() - parser.add_argument('-fp1', '--file_path1', help='INFERENCE_INPUT_FOLDER', required=True, default='/home/hyp/environment/input/') - parser.add_argument('-fp2', '--file_path2', help='INFERENCE_OUTPUT_FOLDER', required=True, default='/home/hyp/environment/output/') - parser.add_argument('-fp3', '--file_path3', help='INFERENCE_SHAPE_PATH', required=True, default='/home/hyp/environment/') - args = parser.parse_args() - python_file = infer_path.__file__ - fp1 = args.file_path1 - fp2 = args.file_path2 - fp3 = args.file_path3 - lines = [] - print('尝试读取:', python_file) - file = open(python_file, 'r', encoding='utf-8') - lines = file.readlines() - file.close() - print('尝试修改路径') - with open(python_file, 'w', encoding='utf-8') as f: - for line in lines: - if line.startswith('INFERENCE_INPUT_FOLDER'): - line = 'INFERENCE_INPUT_FOLDER = ' + '\'' + str(fp1) + '\'' + '\n' - if line.startswith('INFERENCE_OUTPUT_FOLDER'): - line = 'INFERENCE_OUTPUT_FOLDER = ' + '\'' + str(fp2) + '\'' + '\n' - if line.startswith('INFERENCE_SHAPE_PATH'): - line = 'INFERENCE_SHAPE_PATH = ' + '\'' + str(fp3) + '\'' + '\n' - f.write(line) - print('正在修改:', python_file) - print('INFERENCE_INPUT_FOLDER =', fp1) - print('INFERENCE_OUTPUT_FOLDER=', fp2) - print('INFERENCE_SHAPE_PATH =', fp3) - f.close() - print('修改完成') - - -if __name__ == "__main__": - main() - print('main end') - +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 3d_nested_unet_preprocess.py +import sys +import os +import time +import pdb +import argparse +from nnunet.inference import infer_path + + +def main(): + # pdb.set_trace() + parser = argparse.ArgumentParser() + parser.add_argument('-fp1', '--file_path1', help='INFERENCE_INPUT_FOLDER', required=True, default='/home/hyp/environment/input/') + parser.add_argument('-fp2', '--file_path2', help='INFERENCE_OUTPUT_FOLDER', required=True, default='/home/hyp/environment/output/') + parser.add_argument('-fp3', '--file_path3', help='INFERENCE_SHAPE_PATH', required=True, default='/home/hyp/environment/') + args = parser.parse_args() + python_file = infer_path.__file__ + fp1 = args.file_path1 + fp2 = args.file_path2 + fp3 = args.file_path3 + lines = [] + print('尝试读取:', python_file) + file = open(python_file, 'r', encoding='utf-8') + lines = file.readlines() + file.close() + print('尝试修改路径') + with open(python_file, 'w', encoding='utf-8') as f: + for line in lines: + if line.startswith('INFERENCE_INPUT_FOLDER'): + line = 'INFERENCE_INPUT_FOLDER = ' + '\'' + str(fp1) + '\'' + '\n' + if line.startswith('INFERENCE_OUTPUT_FOLDER'): + line = 'INFERENCE_OUTPUT_FOLDER = ' + '\'' + str(fp2) + '\'' + '\n' + if line.startswith('INFERENCE_SHAPE_PATH'): + line = 'INFERENCE_SHAPE_PATH = ' + '\'' + str(fp3) + '\'' + '\n' + f.write(line) + print('正在修改:', python_file) + print('INFERENCE_INPUT_FOLDER =', fp1) + print('INFERENCE_OUTPUT_FOLDER=', fp2) + print('INFERENCE_SHAPE_PATH =', fp3) + f.close() + print('修改完成') + + +if __name__ == "__main__": + main() + print('main end') + diff --git a/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/gen_dataset_info.py index 68f13f27c3ec643068e0a5662b610cc59325747b..54138faa7dc6f6b5ad40b7e0895c9271987edc72 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/gen_dataset_info.py @@ -1,80 +1,80 @@ -""" - Copyright 2020 Huawei Technologies Co., Ltd - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - Typical usage example: -""" -import os -import sys -from glob import glob -import pdb - - -def get_bin_info(file_path, info_name, shape, split4=True): - """ - @description: get given bin information - @param file_path bin file path - @param info_name given information name - @param shape image shape - @return - """ - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, shape[0], shape[1]]) - file.write(content) - file.write('\n') - print('共计.bin文件个数:', len(bin_images)) - print('info已写入:', os.path.abspath(info_name)) - if split4: # 是否切割为4卡的info - sths = ['sth1.info', 'sth2.info', 'sth3.info', 'sth4.info'] - length = len(bin_images) - step = length // 4 - b1 = bin_images[0: step] - b2 = bin_images[step: 2*step] - b3 = bin_images[2*step: 3*step] - b4 = bin_images[3*step:] - with open(sths[0], 'w') as file: - for index, img in enumerate(b1): - content = ' '.join([str(index), img, shape[0], shape[1]]) - file.write(content) - file.write('\n') - with open(sths[1], 'w') as file: - for index, img in enumerate(b2): - content = ' '.join([str(index), img, shape[0], shape[1]]) - file.write(content) - file.write('\n') - with open(sths[2], 'w') as file: - for index, img in enumerate(b3): - content = ' '.join([str(index), img, shape[0], shape[1]]) - file.write(content) - file.write('\n') - with open(sths[3], 'w') as file: - for index, img in enumerate(b4): - content = ' '.join([str(index), img, shape[0], shape[1]]) - file.write(content) - file.write('\n') - print('成功切分为四个子集', sths) - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - shape1 = sys.argv[4] - shape2 = sys.argv[5] - shape = [shape1, shape2] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, shape) +""" + Copyright 2020 Huawei Technologies Co., Ltd + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + Typical usage example: +""" +import os +import sys +from glob import glob +import pdb + + +def get_bin_info(file_path, info_name, shape, split4=True): + """ + @description: get given bin information + @param file_path bin file path + @param info_name given information name + @param shape image shape + @return + """ + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, shape[0], shape[1]]) + file.write(content) + file.write('\n') + print('共计.bin文件个数:', len(bin_images)) + print('info已写入:', os.path.abspath(info_name)) + if split4: # 是否切割为4卡的info + sths = ['sth1.info', 'sth2.info', 'sth3.info', 'sth4.info'] + length = len(bin_images) + step = length // 4 + b1 = bin_images[0: step] + b2 = bin_images[step: 2*step] + b3 = bin_images[2*step: 3*step] + b4 = bin_images[3*step:] + with open(sths[0], 'w') as file: + for index, img in enumerate(b1): + content = ' '.join([str(index), img, shape[0], shape[1]]) + file.write(content) + file.write('\n') + with open(sths[1], 'w') as file: + for index, img in enumerate(b2): + content = ' '.join([str(index), img, shape[0], shape[1]]) + file.write(content) + file.write('\n') + with open(sths[2], 'w') as file: + for index, img in enumerate(b3): + content = ' '.join([str(index), img, shape[0], shape[1]]) + file.write(content) + file.write('\n') + with open(sths[3], 'w') as file: + for index, img in enumerate(b4): + content = ' '.join([str(index), img, shape[0], shape[1]]) + file.write(content) + file.write('\n') + print('成功切分为四个子集', sths) + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + shape1 = sys.argv[4] + shape2 = sys.argv[5] + shape = [shape1, shape2] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, shape) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/new.patch b/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/new.patch index 5307bdd0c26a0cd03c7b0b06b901239d4c101087..bc6f3df5cc44d8c752f24f8fe2d7312e31478764 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/new.patch +++ b/ACL_PyTorch/contrib/cv/segmentation/3D_Nested_Unet/new.patch @@ -4,206 +4,206 @@ index 0000000..2a17e8a --- /dev/null +++ b/pytorch/nnunet/evaluation/model_selection/figure_out_want_to_submit2.py @@ -0,0 +1,200 @@ -+# Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany -+# -+# Licensed under the Apache License, Version 2.0 (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# http://www.apache.org/licenses/LICENSE-2.0 -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+ -+ -+from itertools import combinations -+import nnunet -+from batchgenerators.utilities.file_and_folder_operations import * -+from nnunet.evaluation.add_mean_dice_to_json import foreground_mean -+from nnunet.evaluation.model_selection.ensemble import ensemble -+from nnunet.paths import network_training_output_dir -+import numpy as np -+from subprocess import call -+from nnunet.postprocessing.consolidate_postprocessing import consolidate_folds -+from nnunet.utilities.folder_names import get_output_folder_name -+from nnunet.paths import default_cascade_trainer, default_trainer, default_plans_identifier -+ -+ -+def find_task_name(folder, task_id): -+ candidates = subdirs(folder, prefix="Task%03.0d_" % task_id, join=False) -+ assert len(candidates) > 0, "no candidate for Task id %d found in folder %s" % (task_id, folder) -+ assert len(candidates) == 1, "more than one candidate for Task id %d found in folder %s" % (task_id, folder) -+ return candidates[0] -+ -+ -+def get_mean_foreground_dice(json_file): -+ results = load_json(json_file) -+ return get_foreground_mean(results) -+ -+ -+def get_foreground_mean(results): -+ results_mean = results['results']['mean'] -+ dice_scores = [results_mean[i]['Dice'] for i in results_mean.keys() if i != "0" and i != 'mean'] -+ return np.mean(dice_scores) -+ -+ -+def main(): -+ import argparse -+ parser = argparse.ArgumentParser(usage="This is intended to identify the best model based on the five fold " -+ "cross-validation. Running this script requires all models to have been run " -+ "already. This script will summarize the results of the five folds of all " -+ "models in one json each for easy interpretability") -+ -+ parser.add_argument("-m", '--models', nargs="+", required=False, default=['3d_fullres']) -+ parser.add_argument("-t", '--task_ids', nargs="+", required=False, default='003') -+ -+ parser.add_argument("-tr", type=str, required=False, default=default_trainer, -+ help="nnUNetTrainer class. Default: %s" % default_trainer) -+ parser.add_argument("-ctr", type=str, required=False, default=default_cascade_trainer, -+ help="nnUNetTrainer class for cascade model. Default: %s" % default_cascade_trainer) -+ parser.add_argument("-pl", type=str, required=False, default=default_plans_identifier, -+ help="plans name, Default: %s" % default_plans_identifier) -+ parser.add_argument('-f', '--folds', nargs='+', default=(0, 1, 2, 3, 4), help="use this if you have non-standard folds") -+ parser.add_argument("--strict", required=False, default=True, action="store_true", -+ help="set this flag if you want this script to crash of one of the models is missing") -+ -+ args = parser.parse_args() -+ tasks = [int(i) for i in args.task_ids] -+ -+ models = args.models -+ tr = args.tr -+ trc = args.ctr -+ strict = args.strict -+ pl = args.pl -+ folds = tuple(int(i) for i in args.folds) -+ -+ validation_folder = "validation_raw" -+ -+ # this script now acts independently from the summary jsons. That was unnecessary -+ id_task_mapping = {} -+ # for each task, run ensembling using all combinations of two models -+ for t in tasks: -+ # first collect pure model performance (postprocessed) -+ results = {} -+ all_results = {} -+ valid_models = [] -+ for m in models: -+ try: -+ if m == "3d_cascade_fullres": -+ trainer = trc -+ else: -+ trainer = tr -+ -+ if t not in id_task_mapping.keys(): -+ task_name = find_task_name(get_output_folder_name(m), t) -+ id_task_mapping[t] = task_name -+ -+ output_folder = get_output_folder_name(m, id_task_mapping[t], trainer, pl) -+ assert isdir(output_folder), "Output folder for model %s is missing, expected: %s" % (m, output_folder) -+ -+ # we need a postprocessing_json for inference, so that must be present -+ postprocessing_json = join(output_folder, "postprocessing.json") -+ # we need cv_niftis_postprocessed to know the single model performance -+ cv_niftis_folder = join(output_folder, "cv_niftis_raw") -+ if not isfile(postprocessing_json) or not isdir(cv_niftis_folder): -+ print("running missing postprocessing for %s and model %s" % (id_task_mapping[t], m)) -+ consolidate_folds(output_folder, folds=folds) -+ assert isfile(postprocessing_json), "Postprocessing json missing, expected: %s" % postprocessing_json -+ assert isdir(cv_niftis_folder), "Folder with niftis from CV missing, expected: %s" % cv_niftis_folder -+ -+ # obtain mean foreground dice -+ summary_file = join(cv_niftis_folder, "summary.json") -+ results[m] = get_mean_foreground_dice(summary_file) -+ foreground_mean(summary_file) -+ all_results[m] = load_json(summary_file)['results']['mean'] -+ valid_models.append(m) -+ -+ except Exception as e: -+ if strict: -+ raise e -+ else: -+ print("WARNING!") -+ print(e) -+ -+ # now run ensembling and add ensembling to results -+ print("\nFound the following valid models:\n", valid_models) -+ if len(valid_models) > 1: -+ for m1, m2 in combinations(valid_models, 2): -+ -+ trainer_m1 = trc if m1 == "3d_cascade_fullres" else tr -+ trainer_m2 = trc if m2 == "3d_cascade_fullres" else tr -+ -+ ensemble_name = "ensemble_" + m1 + "__" + trainer_m1 + "__" + pl + "--" + m2 + "__" + trainer_m2 + "__" + pl -+ output_folder_base = join(network_training_output_dir, "ensembles", id_task_mapping[t], ensemble_name) -+ maybe_mkdir_p(output_folder_base) -+ -+ network1_folder = get_output_folder_name(m1, id_task_mapping[t], trainer_m1, pl) -+ network2_folder = get_output_folder_name(m2, id_task_mapping[t], trainer_m2, pl) -+ -+ print("ensembling", network1_folder, network2_folder) -+ ensemble(network1_folder, network2_folder, output_folder_base, id_task_mapping[t], validation_folder, folds) -+ # ensembling will automatically do postprocessingget_foreground_mean -+ -+ # now get result of ensemble -+ results[ensemble_name] = get_mean_foreground_dice(join(output_folder_base, "ensembled_raw", "summary.json")) -+ summary_file = join(output_folder_base, "ensembled_raw", "summary.json") -+ foreground_mean(summary_file) -+ all_results[ensemble_name] = load_json(summary_file)['results']['mean'] -+ -+ # now print all mean foreground dice and highlight the best -+ foreground_dices = list(results.values()) -+ best = np.max(foreground_dices) -+ for k, v in results.items(): -+ print(k, v) -+ -+ predict_str = "" -+ best_model = None -+ for k, v in results.items(): -+ if v == best: -+ print("%s submit model %s" % (id_task_mapping[t], k), v) -+ best_model = k -+ print("\nHere is how you should predict test cases. Run in sequential order and replace all input and output folder names with your personalized ones\n") -+ if k.startswith("ensemble"): -+ tmp = k[len("ensemble_"):] -+ model1, model2 = tmp.split("--") -+ m1, t1, pl1 = model1.split("__") -+ m2, t2, pl2 = model2.split("__") -+ predict_str += "nnUNet_predict -i FOLDER_WITH_TEST_CASES -o OUTPUT_FOLDER_MODEL1 -tr " + tr + " -ctr " + trc + " -m " + m1 + " -p " + pl + " -t " + \ -+ id_task_mapping[t] + "\n" -+ predict_str += "nnUNet_predict -i FOLDER_WITH_TEST_CASES -o OUTPUT_FOLDER_MODEL2 -tr " + tr + " -ctr " + trc + " -m " + m2 + " -p " + pl + " -t " + \ -+ id_task_mapping[t] + "\n" -+ -+ predict_str += "nnUNet_ensemble -f OUTPUT_FOLDER_MODEL1 OUTPUT_FOLDER_MODEL2 -o OUTPUT_FOLDER -pp " + join(network_training_output_dir, "ensembles", id_task_mapping[t], k, "postprocessing.json") + "\n" -+ else: -+ predict_str += "nnUNet_predict -i FOLDER_WITH_TEST_CASES -o OUTPUT_FOLDER_MODEL1 -tr " + tr + " -ctr " + trc + " -m " + k + " -p " + pl + " -t " + \ -+ id_task_mapping[t] + "\n" -+ print(predict_str) -+ -+ summary_folder = join(network_training_output_dir, "ensembles", id_task_mapping[t]) -+ maybe_mkdir_p(summary_folder) -+ with open(join(summary_folder, "prediction_commands.txt"), 'w') as f: -+ f.write(predict_str) -+ -+ num_classes = len([i for i in all_results[best_model].keys() if i != 'mean']) -+ with open(join(summary_folder, "summary.csv"), 'w') as f: -+ f.write("model") -+ for c in range(1, num_classes): -+ f.write(",class%d" % c) -+ f.write(",average") -+ f.write("\n") -+ for m in all_results.keys(): -+ f.write(m) -+ for c in range(1, num_classes): -+ f.write(",%01.4f" % all_results[m][str(c)]["Dice"]) -+ f.write(",%01.4f" % all_results[m]['mean']["Dice"]) -+ f.write("\n") -+ -+ -+if __name__ == "__main__": -+ main() ++# Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++ ++ ++from itertools import combinations ++import nnunet ++from batchgenerators.utilities.file_and_folder_operations import * ++from nnunet.evaluation.add_mean_dice_to_json import foreground_mean ++from nnunet.evaluation.model_selection.ensemble import ensemble ++from nnunet.paths import network_training_output_dir ++import numpy as np ++from subprocess import call ++from nnunet.postprocessing.consolidate_postprocessing import consolidate_folds ++from nnunet.utilities.folder_names import get_output_folder_name ++from nnunet.paths import default_cascade_trainer, default_trainer, default_plans_identifier ++ ++ ++def find_task_name(folder, task_id): ++ candidates = subdirs(folder, prefix="Task%03.0d_" % task_id, join=False) ++ assert len(candidates) > 0, "no candidate for Task id %d found in folder %s" % (task_id, folder) ++ assert len(candidates) == 1, "more than one candidate for Task id %d found in folder %s" % (task_id, folder) ++ return candidates[0] ++ ++ ++def get_mean_foreground_dice(json_file): ++ results = load_json(json_file) ++ return get_foreground_mean(results) ++ ++ ++def get_foreground_mean(results): ++ results_mean = results['results']['mean'] ++ dice_scores = [results_mean[i]['Dice'] for i in results_mean.keys() if i != "0" and i != 'mean'] ++ return np.mean(dice_scores) ++ ++ ++def main(): ++ import argparse ++ parser = argparse.ArgumentParser(usage="This is intended to identify the best model based on the five fold " ++ "cross-validation. Running this script requires all models to have been run " ++ "already. This script will summarize the results of the five folds of all " ++ "models in one json each for easy interpretability") ++ ++ parser.add_argument("-m", '--models', nargs="+", required=False, default=['3d_fullres']) ++ parser.add_argument("-t", '--task_ids', nargs="+", required=False, default='003') ++ ++ parser.add_argument("-tr", type=str, required=False, default=default_trainer, ++ help="nnUNetTrainer class. Default: %s" % default_trainer) ++ parser.add_argument("-ctr", type=str, required=False, default=default_cascade_trainer, ++ help="nnUNetTrainer class for cascade model. Default: %s" % default_cascade_trainer) ++ parser.add_argument("-pl", type=str, required=False, default=default_plans_identifier, ++ help="plans name, Default: %s" % default_plans_identifier) ++ parser.add_argument('-f', '--folds', nargs='+', default=(0, 1, 2, 3, 4), help="use this if you have non-standard folds") ++ parser.add_argument("--strict", required=False, default=True, action="store_true", ++ help="set this flag if you want this script to crash of one of the models is missing") ++ ++ args = parser.parse_args() ++ tasks = [int(i) for i in args.task_ids] ++ ++ models = args.models ++ tr = args.tr ++ trc = args.ctr ++ strict = args.strict ++ pl = args.pl ++ folds = tuple(int(i) for i in args.folds) ++ ++ validation_folder = "validation_raw" ++ ++ # this script now acts independently from the summary jsons. That was unnecessary ++ id_task_mapping = {} ++ # for each task, run ensembling using all combinations of two models ++ for t in tasks: ++ # first collect pure model performance (postprocessed) ++ results = {} ++ all_results = {} ++ valid_models = [] ++ for m in models: ++ try: ++ if m == "3d_cascade_fullres": ++ trainer = trc ++ else: ++ trainer = tr ++ ++ if t not in id_task_mapping.keys(): ++ task_name = find_task_name(get_output_folder_name(m), t) ++ id_task_mapping[t] = task_name ++ ++ output_folder = get_output_folder_name(m, id_task_mapping[t], trainer, pl) ++ assert isdir(output_folder), "Output folder for model %s is missing, expected: %s" % (m, output_folder) ++ ++ # we need a postprocessing_json for inference, so that must be present ++ postprocessing_json = join(output_folder, "postprocessing.json") ++ # we need cv_niftis_postprocessed to know the single model performance ++ cv_niftis_folder = join(output_folder, "cv_niftis_raw") ++ if not isfile(postprocessing_json) or not isdir(cv_niftis_folder): ++ print("running missing postprocessing for %s and model %s" % (id_task_mapping[t], m)) ++ consolidate_folds(output_folder, folds=folds) ++ assert isfile(postprocessing_json), "Postprocessing json missing, expected: %s" % postprocessing_json ++ assert isdir(cv_niftis_folder), "Folder with niftis from CV missing, expected: %s" % cv_niftis_folder ++ ++ # obtain mean foreground dice ++ summary_file = join(cv_niftis_folder, "summary.json") ++ results[m] = get_mean_foreground_dice(summary_file) ++ foreground_mean(summary_file) ++ all_results[m] = load_json(summary_file)['results']['mean'] ++ valid_models.append(m) ++ ++ except Exception as e: ++ if strict: ++ raise e ++ else: ++ print("WARNING!") ++ print(e) ++ ++ # now run ensembling and add ensembling to results ++ print("\nFound the following valid models:\n", valid_models) ++ if len(valid_models) > 1: ++ for m1, m2 in combinations(valid_models, 2): ++ ++ trainer_m1 = trc if m1 == "3d_cascade_fullres" else tr ++ trainer_m2 = trc if m2 == "3d_cascade_fullres" else tr ++ ++ ensemble_name = "ensemble_" + m1 + "__" + trainer_m1 + "__" + pl + "--" + m2 + "__" + trainer_m2 + "__" + pl ++ output_folder_base = join(network_training_output_dir, "ensembles", id_task_mapping[t], ensemble_name) ++ maybe_mkdir_p(output_folder_base) ++ ++ network1_folder = get_output_folder_name(m1, id_task_mapping[t], trainer_m1, pl) ++ network2_folder = get_output_folder_name(m2, id_task_mapping[t], trainer_m2, pl) ++ ++ print("ensembling", network1_folder, network2_folder) ++ ensemble(network1_folder, network2_folder, output_folder_base, id_task_mapping[t], validation_folder, folds) ++ # ensembling will automatically do postprocessingget_foreground_mean ++ ++ # now get result of ensemble ++ results[ensemble_name] = get_mean_foreground_dice(join(output_folder_base, "ensembled_raw", "summary.json")) ++ summary_file = join(output_folder_base, "ensembled_raw", "summary.json") ++ foreground_mean(summary_file) ++ all_results[ensemble_name] = load_json(summary_file)['results']['mean'] ++ ++ # now print all mean foreground dice and highlight the best ++ foreground_dices = list(results.values()) ++ best = np.max(foreground_dices) ++ for k, v in results.items(): ++ print(k, v) ++ ++ predict_str = "" ++ best_model = None ++ for k, v in results.items(): ++ if v == best: ++ print("%s submit model %s" % (id_task_mapping[t], k), v) ++ best_model = k ++ print("\nHere is how you should predict test cases. Run in sequential order and replace all input and output folder names with your personalized ones\n") ++ if k.startswith("ensemble"): ++ tmp = k[len("ensemble_"):] ++ model1, model2 = tmp.split("--") ++ m1, t1, pl1 = model1.split("__") ++ m2, t2, pl2 = model2.split("__") ++ predict_str += "nnUNet_predict -i FOLDER_WITH_TEST_CASES -o OUTPUT_FOLDER_MODEL1 -tr " + tr + " -ctr " + trc + " -m " + m1 + " -p " + pl + " -t " + \ ++ id_task_mapping[t] + "\n" ++ predict_str += "nnUNet_predict -i FOLDER_WITH_TEST_CASES -o OUTPUT_FOLDER_MODEL2 -tr " + tr + " -ctr " + trc + " -m " + m2 + " -p " + pl + " -t " + \ ++ id_task_mapping[t] + "\n" ++ ++ predict_str += "nnUNet_ensemble -f OUTPUT_FOLDER_MODEL1 OUTPUT_FOLDER_MODEL2 -o OUTPUT_FOLDER -pp " + join(network_training_output_dir, "ensembles", id_task_mapping[t], k, "postprocessing.json") + "\n" ++ else: ++ predict_str += "nnUNet_predict -i FOLDER_WITH_TEST_CASES -o OUTPUT_FOLDER_MODEL1 -tr " + tr + " -ctr " + trc + " -m " + k + " -p " + pl + " -t " + \ ++ id_task_mapping[t] + "\n" ++ print(predict_str) ++ ++ summary_folder = join(network_training_output_dir, "ensembles", id_task_mapping[t]) ++ maybe_mkdir_p(summary_folder) ++ with open(join(summary_folder, "prediction_commands.txt"), 'w') as f: ++ f.write(predict_str) ++ ++ num_classes = len([i for i in all_results[best_model].keys() if i != 'mean']) ++ with open(join(summary_folder, "summary.csv"), 'w') as f: ++ f.write("model") ++ for c in range(1, num_classes): ++ f.write(",class%d" % c) ++ f.write(",average") ++ f.write("\n") ++ for m in all_results.keys(): ++ f.write(m) ++ for c in range(1, num_classes): ++ f.write(",%01.4f" % all_results[m][str(c)]["Dice"]) ++ f.write(",%01.4f" % all_results[m]['mean']["Dice"]) ++ f.write("\n") ++ ++ ++if __name__ == "__main__": ++ main() diff --git a/pytorch/nnunet/experiment_planning/nnUNet_convert_decathlon_task.py b/pytorch/nnunet/experiment_planning/nnUNet_convert_decathlon_task.py index cf5285a..a0384f0 100644 --- a/pytorch/nnunet/experiment_planning/nnUNet_convert_decathlon_task.py @@ -269,41 +269,41 @@ index 0000000..5113f93 --- /dev/null +++ b/pytorch/nnunet/hyp_getnpz.py @@ -0,0 +1,36 @@ -+import numpy as np -+import os -+import nibabel as nib -+import pickle -+ -+ -+raw_data = '/data/yupeng/environment_variables/nnUNet_raw_data_base/nnUNet_raw_data/Task003_Liver/imagesTr/liver_0_0000.nii.gz' -+crop_data = '/data/yupeng/environment_variables/nnUNet_raw_data_base/nnUNet_cropped_data/Task003_Liver/liver_0.npz' -+crop_data = '/data/yupeng/environment_variables/nnUNet_preprocessed/Task003_Liver/nnUNetData_plans_v2.1_stage0/liver_0.npz' -+pickle_data = '/data/yupeng/environment_variables/nnUNet_preprocessed/Task003_Liver/nnUNetPlansv2.1_plans_3D.pkl' -+ -+print('start') -+ -+p_data = pickle.load(open(pickle_data, 'rb')) -+ -+ -+ -+c_data = np.load(crop_data) -+print(c_data.files) -+ -+r_data = nib.load(raw_data).get_data() -+r_data = r_data / np.amax(r_data) -+ -+min2 = min(r_data) -+ -+for i in range(512): -+ for j in range(512): -+ for k in range(75): -+ data1 = r_data[i][j][k] -+ data2 = c_data.f.data[0][k][i][j] -+ if data1 != data2: -+ print("wrong") -+ break -+ -+ ++import numpy as np ++import os ++import nibabel as nib ++import pickle ++ ++ ++raw_data = '/data/yupeng/environment_variables/nnUNet_raw_data_base/nnUNet_raw_data/Task003_Liver/imagesTr/liver_0_0000.nii.gz' ++crop_data = '/data/yupeng/environment_variables/nnUNet_raw_data_base/nnUNet_cropped_data/Task003_Liver/liver_0.npz' ++crop_data = '/data/yupeng/environment_variables/nnUNet_preprocessed/Task003_Liver/nnUNetData_plans_v2.1_stage0/liver_0.npz' ++pickle_data = '/data/yupeng/environment_variables/nnUNet_preprocessed/Task003_Liver/nnUNetPlansv2.1_plans_3D.pkl' ++ ++print('start') ++ ++p_data = pickle.load(open(pickle_data, 'rb')) ++ ++ ++ ++c_data = np.load(crop_data) ++print(c_data.files) ++ ++r_data = nib.load(raw_data).get_data() ++r_data = r_data / np.amax(r_data) ++ ++min2 = min(r_data) ++ ++for i in range(512): ++ for j in range(512): ++ for k in range(75): ++ data1 = r_data[i][j][k] ++ data2 = c_data.f.data[0][k][i][j] ++ if data1 != data2: ++ print("wrong") ++ break ++ ++ +print('end') \ No newline at end of file diff --git a/pytorch/nnunet/inference/copy_val_to_test.py b/pytorch/nnunet/inference/copy_val_to_test.py @@ -312,183 +312,183 @@ index 0000000..405345b --- /dev/null +++ b/pytorch/nnunet/inference/copy_val_to_test.py @@ -0,0 +1,19 @@ -+import os -+import shutil -+ -+# fold = 0 -+val_folder = '/root/heyupeng/environment/Task03_Liver/imagesTr/' -+test_folder = '/root/heyupeng/environment/nnUNet_raw_data_base/nnUNet_raw_data/Task003_Liver/imagesTs/' -+val_list = [101, 11, 112, 115, 12, 120, 128, 17, 19, 24, 25, 27, 3, 38, 40, 41, 42, 44, 5, 51, 52, 58, 64, 70, 75, 77, -+ 82] -+print('val_list:', val_list) -+for val in val_list: -+ source_file = 'liver_' + str(val) + '.nii.gz' -+ source_path = os.path.join(val_folder, source_file) -+ target_file = 'liver_' + str(val) + '_0000.nii.gz' -+ target_path = os.path.join(test_folder, target_file) -+ print('copy: ', source_path, '->', target_path) -+ shutil.copyfile(source_path, target_path) -+print('done') -+ -+ ++import os ++import shutil ++ ++# fold = 0 ++val_folder = '/root/heyupeng/environment/Task03_Liver/imagesTr/' ++test_folder = '/root/heyupeng/environment/nnUNet_raw_data_base/nnUNet_raw_data/Task003_Liver/imagesTs/' ++val_list = [101, 11, 112, 115, 12, 120, 128, 17, 19, 24, 25, 27, 3, 38, 40, 41, 42, 44, 5, 51, 52, 58, 64, 70, 75, 77, ++ 82] ++print('val_list:', val_list) ++for val in val_list: ++ source_file = 'liver_' + str(val) + '.nii.gz' ++ source_path = os.path.join(val_folder, source_file) ++ target_file = 'liver_' + str(val) + '_0000.nii.gz' ++ target_path = os.path.join(test_folder, target_file) ++ print('copy: ', source_path, '->', target_path) ++ shutil.copyfile(source_path, target_path) ++print('done') ++ ++ diff --git a/pytorch/nnunet/inference/create_testset.py b/pytorch/nnunet/inference/create_testset.py new file mode 100644 index 0000000..cd13c1e --- /dev/null +++ b/pytorch/nnunet/inference/create_testset.py @@ -0,0 +1,28 @@ -+import os -+import pdb -+import sys -+import shutil -+ -+ -+def main(input_path): -+ if input_path is None: -+ raise Exception('Parameter need to be filled in: input_path') -+ env_dist = os.environ -+ p1 = env_dist.get('nnUNet_raw_data_base') -+ val_list = [101, 11, 112, 115, 12, 120, 128, 17, 19, 24, 25, 27, 3, 38, 40, 41, 42, 44, 5, 51, 52, 58, 64, 70, 75, -+ 77, 82] # 数据集的验证集部分 -+ p2 = 'nnUNet_raw_data/Task003_Liver/imagesTr/' -+ target_path = os.path.join(p1, p2) -+ for v in val_list: -+ file_name = 'liver_' + str(v) + '_0000.nii.gz' -+ file_path = os.path.join(target_path, file_name) -+ # pdb.set_trace() -+ print('copy file:[', file_path, '] to folder:', input_path) -+ shutil.copy(file_path, input_path) -+ print('done') -+ -+ -+ -+if __name__ == "__main__": -+ input_path = sys.argv[1] -+ main(input_path) ++import os ++import pdb ++import sys ++import shutil ++ ++ ++def main(input_path): ++ if input_path is None: ++ raise Exception('Parameter need to be filled in: input_path') ++ env_dist = os.environ ++ p1 = env_dist.get('nnUNet_raw_data_base') ++ val_list = [101, 11, 112, 115, 12, 120, 128, 17, 19, 24, 25, 27, 3, 38, 40, 41, 42, 44, 5, 51, 52, 58, 64, 70, 75, ++ 77, 82] # 数据集的验证集部分 ++ p2 = 'nnUNet_raw_data/Task003_Liver/imagesTr/' ++ target_path = os.path.join(p1, p2) ++ for v in val_list: ++ file_name = 'liver_' + str(v) + '_0000.nii.gz' ++ file_path = os.path.join(target_path, file_name) ++ # pdb.set_trace() ++ print('copy file:[', file_path, '] to folder:', input_path) ++ shutil.copy(file_path, input_path) ++ print('done') ++ ++ ++ ++if __name__ == "__main__": ++ input_path = sys.argv[1] ++ main(input_path) diff --git a/pytorch/nnunet/inference/delete_other_data.py b/pytorch/nnunet/inference/delete_other_data.py new file mode 100644 index 0000000..b58367f --- /dev/null +++ b/pytorch/nnunet/inference/delete_other_data.py @@ -0,0 +1,30 @@ -+import os -+import pdb -+ -+ -+def listdir(path, list_name): -+ for file in os.listdir(path): -+ file_path = os.path.join(path, file) -+ if os.path.isdir(file_path): -+ listdir(file_path, list_name) -+ elif os.path.splitext(file_path)[1] == '.gz': -+ list_name.append(file_path) -+ return list_name -+ -+val_list = [101, 11, 112, 115, 12, 120, 128, 17, 19, 24, 25, 27, 3, 38, 40, 41, 42, 44, 5, 51, 52, 58, 64, 70, 75, 77, -+ 82] -+target_folder = ['imagesTr', 'labelsTr', 'imagesTs'] -+for i in range(len(target_folder)): -+ t = target_folder[i] -+ if i == 2: -+ val_list = [132] -+ p = os.path.join('./Task03_Liver/', t) -+ files = [] -+ files = listdir(p, files) -+ files = set(files) -+ for e in val_list: -+ str_e = './Task03_Liver/' + t + '/liver_' + str(e) + '.nii.gz' -+ files.remove(str_e) -+ for f in files: -+ os.remove(f) -+print('end') ++import os ++import pdb ++ ++ ++def listdir(path, list_name): ++ for file in os.listdir(path): ++ file_path = os.path.join(path, file) ++ if os.path.isdir(file_path): ++ listdir(file_path, list_name) ++ elif os.path.splitext(file_path)[1] == '.gz': ++ list_name.append(file_path) ++ return list_name ++ ++val_list = [101, 11, 112, 115, 12, 120, 128, 17, 19, 24, 25, 27, 3, 38, 40, 41, 42, 44, 5, 51, 52, 58, 64, 70, 75, 77, ++ 82] ++target_folder = ['imagesTr', 'labelsTr', 'imagesTs'] ++for i in range(len(target_folder)): ++ t = target_folder[i] ++ if i == 2: ++ val_list = [132] ++ p = os.path.join('./Task03_Liver/', t) ++ files = [] ++ files = listdir(p, files) ++ files = set(files) ++ for e in val_list: ++ str_e = './Task03_Liver/' + t + '/liver_' + str(e) + '.nii.gz' ++ files.remove(str_e) ++ for f in files: ++ os.remove(f) ++print('end') diff --git a/pytorch/nnunet/inference/gen_dataset_info.py b/pytorch/nnunet/inference/gen_dataset_info.py new file mode 100644 index 0000000..d1cb265 --- /dev/null +++ b/pytorch/nnunet/inference/gen_dataset_info.py @@ -0,0 +1,83 @@ -+""" -+ Copyright 2020 Huawei Technologies Co., Ltd -+ -+ Licensed under the Apache License, Version 2.0 (the "License"); -+ you may not use this file except in compliance with the License. -+ You may obtain a copy of the License at -+ -+ http://www.apache.org/licenses/LICENSE-2.0 -+ -+ Unless required by applicable law or agreed to in writing, software -+ distributed under the License is distributed on an "AS IS" BASIS, -+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ See the License for the specific language governing permissions and -+ limitations under the License. -+ Typical usage example: -+""" -+import os -+import sys -+from glob import glob -+import pdb -+ -+ -+def get_bin_info(file_path, info_name, shape, split4=True): -+ """ -+ @description: get given bin information -+ @param file_path bin file path -+ @param info_name given information name -+ @param shape image shape -+ @return -+ """ -+ bin_images = glob(os.path.join(file_path, '*.bin')) -+ with open(info_name, 'w') as file: -+ for index, img in enumerate(bin_images): -+ content = ' '.join([str(index), img, shape[0], shape[1]]) -+ file.write(content) -+ file.write('\n') -+ print('info已写入:', info_name) -+ if split4: # 是否切割为4卡的info -+ sths = ['sth1.info', 'sth2.info', 'sth3.info', 'sth4.info'] -+ for i in range(len(sths)): -+ s = sths[i] -+ s = os.path.join(info_name, '..', s) -+ sths[i] = s -+ length = len(bin_images) -+ step = length // 4 -+ b1 = bin_images[0: step] -+ b2 = bin_images[step: 2*step] -+ b3 = bin_images[2*step: 3*step] -+ b4 = bin_images[3*step:] -+ with open(sths[0], 'w') as file: -+ for index, img in enumerate(b1): -+ content = ' '.join([str(index), img, shape[0], shape[1]]) -+ file.write(content) -+ file.write('\n') -+ with open(sths[1], 'w') as file: -+ for index, img in enumerate(b2): -+ content = ' '.join([str(index), img, shape[0], shape[1]]) -+ file.write(content) -+ file.write('\n') -+ with open(sths[2], 'w') as file: -+ for index, img in enumerate(b3): -+ content = ' '.join([str(index), img, shape[0], shape[1]]) -+ file.write(content) -+ file.write('\n') -+ with open(sths[3], 'w') as file: -+ for index, img in enumerate(b4): -+ content = ' '.join([str(index), img, shape[0], shape[1]]) -+ file.write(content) -+ file.write('\n') -+ print('成功切分为四个子集', sths) -+ -+ -+if __name__ == '__main__': -+ file_type = sys.argv[1] -+ file_path = sys.argv[2] -+ info_name = sys.argv[3] -+ if file_type == 'bin': -+ shape1 = sys.argv[4] -+ shape2 = sys.argv[5] -+ shape = [shape1, shape2] -+ assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' -+ get_bin_info(file_path, info_name, shape) ++""" ++ Copyright 2020 Huawei Technologies Co., Ltd ++ ++ Licensed under the Apache License, Version 2.0 (the "License"); ++ you may not use this file except in compliance with the License. ++ You may obtain a copy of the License at ++ ++ http://www.apache.org/licenses/LICENSE-2.0 ++ ++ Unless required by applicable law or agreed to in writing, software ++ distributed under the License is distributed on an "AS IS" BASIS, ++ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++ See the License for the specific language governing permissions and ++ limitations under the License. ++ Typical usage example: ++""" ++import os ++import sys ++from glob import glob ++import pdb ++ ++ ++def get_bin_info(file_path, info_name, shape, split4=True): ++ """ ++ @description: get given bin information ++ @param file_path bin file path ++ @param info_name given information name ++ @param shape image shape ++ @return ++ """ ++ bin_images = glob(os.path.join(file_path, '*.bin')) ++ with open(info_name, 'w') as file: ++ for index, img in enumerate(bin_images): ++ content = ' '.join([str(index), img, shape[0], shape[1]]) ++ file.write(content) ++ file.write('\n') ++ print('info已写入:', info_name) ++ if split4: # 是否切割为4卡的info ++ sths = ['sth1.info', 'sth2.info', 'sth3.info', 'sth4.info'] ++ for i in range(len(sths)): ++ s = sths[i] ++ s = os.path.join(info_name, '..', s) ++ sths[i] = s ++ length = len(bin_images) ++ step = length // 4 ++ b1 = bin_images[0: step] ++ b2 = bin_images[step: 2*step] ++ b3 = bin_images[2*step: 3*step] ++ b4 = bin_images[3*step:] ++ with open(sths[0], 'w') as file: ++ for index, img in enumerate(b1): ++ content = ' '.join([str(index), img, shape[0], shape[1]]) ++ file.write(content) ++ file.write('\n') ++ with open(sths[1], 'w') as file: ++ for index, img in enumerate(b2): ++ content = ' '.join([str(index), img, shape[0], shape[1]]) ++ file.write(content) ++ file.write('\n') ++ with open(sths[2], 'w') as file: ++ for index, img in enumerate(b3): ++ content = ' '.join([str(index), img, shape[0], shape[1]]) ++ file.write(content) ++ file.write('\n') ++ with open(sths[3], 'w') as file: ++ for index, img in enumerate(b4): ++ content = ' '.join([str(index), img, shape[0], shape[1]]) ++ file.write(content) ++ file.write('\n') ++ print('成功切分为四个子集', sths) ++ ++ ++if __name__ == '__main__': ++ file_type = sys.argv[1] ++ file_path = sys.argv[2] ++ info_name = sys.argv[3] ++ if file_type == 'bin': ++ shape1 = sys.argv[4] ++ shape2 = sys.argv[5] ++ shape = [shape1, shape2] ++ assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' ++ get_bin_info(file_path, info_name, shape) + print('end main') \ No newline at end of file diff --git a/pytorch/nnunet/inference/infer_path.py b/pytorch/nnunet/inference/infer_path.py @@ -583,1302 +583,1302 @@ index 0000000..263dbd2 --- /dev/null +++ b/pytorch/nnunet/inference/predict2.py @@ -0,0 +1,845 @@ -+# Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany -+# -+# Licensed under the Apache License, Version 2.0 (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# http://www.apache.org/licenses/LICENSE-2.0 -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+ -+ -+import argparse -+from copy import deepcopy -+from typing import Tuple, Union, List -+ -+import numpy as np -+from batchgenerators.augmentations.utils import resize_segmentation -+from nnunet.inference.segmentation_export import save_segmentation_nifti_from_softmax, save_segmentation_nifti -+from batchgenerators.utilities.file_and_folder_operations import * -+from multiprocessing import Process, Queue -+import torch -+import SimpleITK as sitk -+import shutil -+from multiprocessing import Pool -+from nnunet.postprocessing.connected_components import load_remove_save, load_postprocessing -+from nnunet.training.model_restore import load_model_and_checkpoint_files -+from nnunet.training.network_training.nnUNetTrainer import nnUNetTrainer -+from nnunet.utilities.one_hot_encoding import to_one_hot -+from nnunet.utilities.to_torch import maybe_to_torch, to_cuda -+import pdb -+ -+ -+def preprocess_save_to_queue(preprocess_fn, q, list_of_lists, output_files, segs_from_prev_stage, classes, -+ transpose_forward): -+ # suppress output -+ # sys.stdout = open(os.devnull, 'w') -+ -+ errors_in = [] -+ for i, l in enumerate(list_of_lists): -+ try: -+ output_file = output_files[i] -+ print("preprocessing", output_file) -+ d, _, dct = preprocess_fn(l) -+ # print(output_file, dct) -+ if segs_from_prev_stage[i] is not None: -+ assert isfile(segs_from_prev_stage[i]) and segs_from_prev_stage[i].endswith( -+ ".nii.gz"), "segs_from_prev_stage" \ -+ " must point to a " \ -+ "segmentation file" -+ seg_prev = sitk.GetArrayFromImage(sitk.ReadImage(segs_from_prev_stage[i])) -+ # check to see if shapes match -+ img = sitk.GetArrayFromImage(sitk.ReadImage(l[0])) -+ assert all([i == j for i, j in zip(seg_prev.shape, img.shape)]), "image and segmentation from previous " \ -+ "stage don't have the same pixel array " \ -+ "shape! image: %s, seg_prev: %s" % \ -+ (l[0], segs_from_prev_stage[i]) -+ seg_prev = seg_prev.transpose(transpose_forward) -+ seg_reshaped = resize_segmentation(seg_prev, d.shape[1:], order=1, cval=0) -+ seg_reshaped = to_one_hot(seg_reshaped, classes) -+ d = np.vstack((d, seg_reshaped)).astype(np.float32) -+ """There is a problem with python process communication that prevents us from communicating obejcts -+ larger than 2 GB between processes (basically when the length of the pickle string that will be sent is -+ communicated by the multiprocessing.Pipe object then the placeholder (\%i I think) does not allow for long -+ enough strings (lol). This could be fixed by changing i to l (for long) but that would require manually -+ patching system python code. We circumvent that problem here by saving softmax_pred to a npy file that will -+ then be read (and finally deleted) by the Process. save_segmentation_nifti_from_softmax can take either -+ filename or np.ndarray and will handle this automatically""" -+ print(d.shape) -+ if np.prod(d.shape) > (2e9 / 4 * 0.85): # *0.85 just to be save, 4 because float32 is 4 bytes -+ print( -+ "This output is too large for python process-process communication. " -+ "Saving output temporarily to disk") -+ np.save(output_file[:-7] + ".npy", d) -+ d = output_file[:-7] + ".npy" -+ q.put((output_file, (d, dct))) -+ except KeyboardInterrupt: -+ raise KeyboardInterrupt -+ except Exception as e: -+ print("error in", l) -+ print(e) -+ q.put("end") -+ if len(errors_in) > 0: -+ print("There were some errors in the following cases:", errors_in) -+ print("These cases were ignored.") -+ else: -+ print("This worker has ended successfully, no errors to report") -+ # restore output -+ # sys.stdout = sys.__stdout__ -+ -+ -+def preprocess_multithreaded(trainer, list_of_lists, output_files, num_processes=2, segs_from_prev_stage=None): -+ if segs_from_prev_stage is None: -+ segs_from_prev_stage = [None] * len(list_of_lists) -+ -+ num_processes = min(len(list_of_lists), num_processes) -+ -+ classes = list(range(1, trainer.num_classes)) -+ assert isinstance(trainer, nnUNetTrainer) -+ q = Queue(1) -+ processes = [] -+ for i in range(num_processes): -+ pr = Process(target=preprocess_save_to_queue, args=(trainer.preprocess_patient, q, -+ list_of_lists[i::num_processes], -+ output_files[i::num_processes], -+ segs_from_prev_stage[i::num_processes], -+ classes, trainer.plans['transpose_forward'])) -+ pr.start() -+ processes.append(pr) -+ -+ try: -+ end_ctr = 0 -+ while end_ctr != num_processes: -+ item = q.get() -+ if item == "end": -+ end_ctr += 1 -+ continue -+ else: -+ yield item -+ -+ finally: -+ for p in processes: -+ if p.is_alive(): -+ p.terminate() # this should not happen but better safe than sorry right -+ p.join() -+ -+ q.close() -+ -+ -+def pth2onnx(model, output_file=r'/home/yupeng/HUAWEI/UNetPlusPlus/pytorch/nnunet/run/nnunetplusplus.onnx'): -+ # model = EfficientNet.from_pretrained('efficientnet-b0', weights_path=input_file) -+ # 调整模型为eval mode -+ model.eval() -+ # 输入节点名 -+ input_names = ["image"] -+ # 输出节点名 -+ output_names = ["class"] -+ dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} -+ dummy_input = torch.randn(1, 1, 128, 128, 128) -+ # dummy_input = to_cuda(dummy_input) -+ # verbose=True,支持打印onnx节点和对应的PyTorch代码行 -+ torch.onnx.export(model, dummy_input, output_file, input_names=input_names, dynamic_axes=dynamic_axes, -+ output_names=output_names, opset_version=11, verbose=True) -+ -+ -+def predict_cases(model, list_of_lists, output_filenames, folds, save_npz, num_threads_preprocessing, -+ num_threads_nifti_save, segs_from_prev_stage=None, do_tta=True, mixed_precision=True, overwrite_existing=False, -+ all_in_gpu=False, step_size=0.5, checkpoint_name="model_final_checkpoint", -+ segmentation_export_kwargs: dict = None, pre_mode=None, fp=None): -+ """ -+ :param segmentation_export_kwargs: -+ :param model: folder where the model is saved, must contain fold_x subfolders -+ :param list_of_lists: [[case0_0000.nii.gz, case0_0001.nii.gz], [case1_0000.nii.gz, case1_0001.nii.gz], ...] -+ :param output_filenames: [output_file_case0.nii.gz, output_file_case1.nii.gz, ...] -+ :param folds: default: (0, 1, 2, 3, 4) (but can also be 'all' or a subset of the five folds, for example use (0, ) -+ for using only fold_0 -+ :param save_npz: default: False -+ :param num_threads_preprocessing: -+ :param num_threads_nifti_save: -+ :param segs_from_prev_stage: -+ :param do_tta: default: True, can be set to False for a 8x speedup at the cost of a reduced segmentation quality -+ :param overwrite_existing: default: True -+ :param mixed_precision: if None then we take no action. If True/False we overwrite what the model has in its init -+ :return: -+ """ -+ assert len(list_of_lists) == len(output_filenames) -+ if segs_from_prev_stage is not None: assert len(segs_from_prev_stage) == len(output_filenames) -+ -+ pool = Pool(num_threads_nifti_save) -+ results = [] -+ -+ cleaned_output_files = [] -+ for o in output_filenames: -+ dr, f = os.path.split(o) -+ if len(dr) > 0: -+ maybe_mkdir_p(dr) -+ if not f.endswith(".nii.gz"): -+ f, _ = os.path.splitext(f) -+ f = f + ".nii.gz" -+ cleaned_output_files.append(join(dr, f)) -+ -+ if not overwrite_existing: -+ print("number of cases:", len(list_of_lists)) -+ not_done_idx = [i for i, j in enumerate(cleaned_output_files) if not isfile(j)] -+ -+ cleaned_output_files = [cleaned_output_files[i] for i in not_done_idx] -+ list_of_lists = [list_of_lists[i] for i in not_done_idx] -+ if segs_from_prev_stage is not None: -+ segs_from_prev_stage = [segs_from_prev_stage[i] for i in not_done_idx] -+ -+ print("number of cases that still need to be predicted:", len(cleaned_output_files)) -+ -+ print("emptying cuda cache") -+ torch.cuda.empty_cache() -+ ''' -+ model='/data/yupeng/environment_variables/RESULTS_FOLDER/nnUNet/3d_fullres/Task003_Liver/nnUNetPlusPlusTrainerV2__nnUNetPlansv2.1' -+ folds=None -+ mixed_precision=True -+ checkpoint_name='model_final_checkpoint' -+ trainer=class-nnUNetPlusPlusTrainerV2 -+ params=list 5 -> dict 6 -> epoch state_dict optimizer_state_dict lr_scheduler_state_dict plot_stuff amp_grad_scaler -+ ''' -+ print("loading parameters for folds,", folds) # 得到参数,实际还未加载进模型 -+ trainer, params = load_model_and_checkpoint_files(model, folds, mixed_precision=mixed_precision, checkpoint_name=checkpoint_name) -+ -+ if segmentation_export_kwargs is None: -+ if 'segmentation_export_params' in trainer.plans.keys(): -+ force_separate_z = trainer.plans['segmentation_export_params']['force_separate_z'] -+ interpolation_order = trainer.plans['segmentation_export_params']['interpolation_order'] -+ interpolation_order_z = trainer.plans['segmentation_export_params']['interpolation_order_z'] -+ else: # 走到这里 -+ force_separate_z = None -+ interpolation_order = 1 -+ interpolation_order_z = 0 -+ else: -+ force_separate_z = segmentation_export_kwargs['force_separate_z'] -+ interpolation_order = segmentation_export_kwargs['interpolation_order'] -+ interpolation_order_z = segmentation_export_kwargs['interpolation_order_z'] -+ -+ print("starting preprocessing generator") -+ preprocessing = preprocess_multithreaded(trainer, list_of_lists, cleaned_output_files, num_threads_preprocessing, -+ segs_from_prev_stage) -+ # unet++V2class, [['/data/yupeng/environment_variables/nnUNet_raw_data_base/nnUNet_raw_data/Task003_Liver/imagesTs/liver_132_0000.nii.gz']] -+ # ['/data/yupeng/environment_variables/output/liver_132.nii.gz'], 6, None -+ print("starting prediction...") -+ if int(pre_mode) == -1: -+ p = params[0] -+ trainer.load_checkpoint_ram(p, False) # nnUnetPlusPlusTrainerV2,实际函数在network_trainer里 -+ print('pth2onnx start') -+ pth2onnx(trainer.network, fp) -+ print('pth2onnx end') -+ print('onnx模型已经输出至:', fp) -+ import sys -+ sys.exit(0) -+ all_output_files = [] -+ for preprocessed in preprocessing: -+ output_filename, (d, dct) = preprocessed -+ print('output_filename, d, dct = ', output_filename, d, dct) -+ all_output_files.append(all_output_files) -+ if isinstance(d, str): -+ data = np.load(d) -+ os.remove(d) -+ d = data -+ print("predicting", output_filename) -+ softmax = [] -+ params = [params[0]] # 只求第一个模型的推理结果 -+ for p in params: -+ # trainer.load_checkpoint_ram(p, False) # nnUnetPlusPlusTrainerV2,实际函数在network_trainer里 -+ # output_filename = '/data/yupeng/environment_variables/output/liver_132.nii.gz' -+ ttttt = trainer.predict_preprocessed_data_return_seg_and_softmax(d, do_tta, trainer.data_aug_params[ -+ 'mirror_axes'], True, step_size=step_size, use_gaussian=True, all_in_gpu=all_in_gpu, -+ mixed_precision=mixed_precision, img_name=output_filename, pre_mode=pre_mode, fp=fp) # tuple(ndarray 489 500 500; 3 489 500 500) -+ softmax.append(ttttt[1][None]) # 扩充了1 3 489 500 500 -+ ''' -+ d= -+ do_tta= -+ step_size= -+ all_in_gpu= -+ mixed_precision= -+ softmax= -+ ''' -+ # softmax是list 5,每个元素是ndarray 1 3 489 500 500 -+ softmax = np.vstack(softmax) # 5 3 489 500 500 -+ softmax_mean = np.mean(softmax, 0) # 3 489 500 500 -+ -+ transpose_forward = trainer.plans.get('transpose_forward') # [0,1,2] -+ if transpose_forward is not None: -+ transpose_backward = trainer.plans.get('transpose_backward') -+ softmax_mean = softmax_mean.transpose([0] + [i + 1 for i in transpose_backward]) -+ -+ if save_npz: # False -+ npz_file = output_filename[:-7] + ".npz" -+ else: -+ npz_file = None -+ -+ if hasattr(trainer, 'regions_class_order'): # False -+ region_class_order = trainer.regions_class_order -+ else: -+ region_class_order = None -+ -+ """There is a problem with python process communication that prevents us from communicating obejcts -+ larger than 2 GB between processes (basically when the length of the pickle string that will be sent is -+ communicated by the multiprocessing.Pipe object then the placeholder (\%i I think) does not allow for long -+ enough strings (lol). This could be fixed by changing i to l (for long) but that would require manually -+ patching system python code. We circumvent that problem here by saving softmax_pred to a npy file that will -+ then be read (and finally deleted) by the Process. save_segmentation_nifti_from_softmax can take either -+ filename or np.ndarray and will handle this automatically""" -+ bytes_per_voxel = 4 -+ if all_in_gpu: -+ bytes_per_voxel = 2 # if all_in_gpu then the return value is half (float16) -+ if np.prod(softmax_mean.shape) > (2e9 / bytes_per_voxel * 0.85): # * 0.85 just to be save -+ print( -+ "This output is too large for python process-process communication. Saving output temporarily to disk") -+ np.save(output_filename[:-7] + ".npy", softmax_mean) -+ softmax_mean = output_filename[:-7] + ".npy" -+ -+ results.append(pool.starmap_async(save_segmentation_nifti_from_softmax, -+ ((softmax_mean, output_filename, dct, interpolation_order, region_class_order, -+ None, None, -+ npz_file, None, force_separate_z, interpolation_order_z),) -+ )) -+ -+ print("inference done. Now waiting for the segmentation export to finish...") -+ _ = [i.get() for i in results] -+ # now apply postprocessing -+ # first load the postprocessing properties if they are present. Else raise a well visible warning -+ results = [] -+ pp_file = join(model, "postprocessing.json") # '/data/yupeng/environment_variables/RESULTS_FOLDER/nnUNet/3d_fullres/Task003_Liver/nnUNetPlusPlusTrainerV2__nnUNetPlansv2.1/postprocessing.json' -+ if isfile(pp_file): -+ print("postprocessing...") -+ shutil.copy(pp_file, os.path.abspath(os.path.dirname(output_filenames[0]))) -+ # for_which_classes stores for which of the classes everything but the largest connected component needs to be -+ # removed -+ for_which_classes, min_valid_obj_size = load_postprocessing(pp_file) -+ results.append(pool.starmap_async(load_remove_save, -+ zip(output_filenames, output_filenames, -+ [for_which_classes] * len(output_filenames), -+ [min_valid_obj_size] * len(output_filenames)))) -+ _ = [i.get() for i in results] -+ else: -+ print("WARNING! Cannot run postprocessing because the postprocessing file is missing. Make sure to run " -+ "consolidate_folds in the output folder of the model first!\nThe folder you need to run this in is " -+ "%s" % model) -+ -+ pool.close() -+ pool.join() -+ -+def predict_cases_fast(model, list_of_lists, output_filenames, folds, num_threads_preprocessing, -+ num_threads_nifti_save, segs_from_prev_stage=None, do_tta=True, mixed_precision=True, -+ overwrite_existing=False, -+ all_in_gpu=False, step_size=0.5, checkpoint_name="model_final_checkpoint", -+ segmentation_export_kwargs: dict = None): -+ assert len(list_of_lists) == len(output_filenames) -+ if segs_from_prev_stage is not None: assert len(segs_from_prev_stage) == len(output_filenames) -+ -+ pool = Pool(num_threads_nifti_save) -+ results = [] -+ -+ cleaned_output_files = [] -+ for o in output_filenames: -+ dr, f = os.path.split(o) -+ if len(dr) > 0: -+ maybe_mkdir_p(dr) -+ if not f.endswith(".nii.gz"): -+ f, _ = os.path.splitext(f) -+ f = f + ".nii.gz" -+ cleaned_output_files.append(join(dr, f)) -+ -+ if not overwrite_existing: -+ print("number of cases:", len(list_of_lists)) -+ not_done_idx = [i for i, j in enumerate(cleaned_output_files) if not isfile(j)] -+ -+ cleaned_output_files = [cleaned_output_files[i] for i in not_done_idx] -+ list_of_lists = [list_of_lists[i] for i in not_done_idx] -+ if segs_from_prev_stage is not None: -+ segs_from_prev_stage = [segs_from_prev_stage[i] for i in not_done_idx] -+ -+ print("number of cases that still need to be predicted:", len(cleaned_output_files)) -+ -+ print("emptying cuda cache") -+ torch.cuda.empty_cache() -+ -+ print("loading parameters for folds,", folds) -+ trainer, params = load_model_and_checkpoint_files(model, folds, mixed_precision=mixed_precision, checkpoint_name=checkpoint_name) -+ -+ if segmentation_export_kwargs is None: -+ if 'segmentation_export_params' in trainer.plans.keys(): -+ force_separate_z = trainer.plans['segmentation_export_params']['force_separate_z'] -+ interpolation_order = trainer.plans['segmentation_export_params']['interpolation_order'] -+ interpolation_order_z = trainer.plans['segmentation_export_params']['interpolation_order_z'] -+ else: -+ force_separate_z = None -+ interpolation_order = 1 -+ interpolation_order_z = 0 -+ else: -+ force_separate_z = segmentation_export_kwargs['force_separate_z'] -+ interpolation_order = segmentation_export_kwargs['interpolation_order'] -+ interpolation_order_z = segmentation_export_kwargs['interpolation_order_z'] -+ -+ print("starting preprocessing generator") -+ preprocessing = preprocess_multithreaded(trainer, list_of_lists, cleaned_output_files, num_threads_preprocessing, -+ segs_from_prev_stage) -+ -+ print("starting prediction...") -+ for preprocessed in preprocessing: -+ print("getting data from preprocessor") -+ output_filename, (d, dct) = preprocessed -+ print("got something") -+ if isinstance(d, str): -+ print("what I got is a string, so I need to load a file") -+ data = np.load(d) -+ os.remove(d) -+ d = data -+ -+ # preallocate the output arrays -+ # same dtype as the return value in predict_preprocessed_data_return_seg_and_softmax (saves time) -+ softmax_aggr = None # np.zeros((trainer.num_classes, *d.shape[1:]), dtype=np.float16) -+ all_seg_outputs = np.zeros((len(params), *d.shape[1:]), dtype=int) -+ print("predicting", output_filename) -+ -+ for i, p in enumerate(params): -+ trainer.load_checkpoint_ram(p, False) -+ -+ res = trainer.predict_preprocessed_data_return_seg_and_softmax(d, do_tta, -+ trainer.data_aug_params['mirror_axes'], True, -+ step_size=step_size, use_gaussian=True, -+ all_in_gpu=all_in_gpu, -+ mixed_precision=mixed_precision) -+ -+ if len(params) > 1: -+ # otherwise we dont need this and we can save ourselves the time it takes to copy that -+ print("aggregating softmax") -+ if softmax_aggr is None: -+ softmax_aggr = res[1] -+ else: -+ softmax_aggr += res[1] -+ all_seg_outputs[i] = res[0] -+ -+ print("obtaining segmentation map") -+ if len(params) > 1: -+ # we dont need to normalize the softmax by 1 / len(params) because this would not change the outcome of the argmax -+ seg = softmax_aggr.argmax(0) -+ else: -+ seg = all_seg_outputs[0] -+ -+ print("applying transpose_backward") -+ transpose_forward = trainer.plans.get('transpose_forward') -+ if transpose_forward is not None: -+ transpose_backward = trainer.plans.get('transpose_backward') -+ seg = seg.transpose([i for i in transpose_backward]) -+ -+ print("initializing segmentation export") -+ results.append(pool.starmap_async(save_segmentation_nifti, -+ ((seg, output_filename, dct, interpolation_order, force_separate_z, -+ interpolation_order_z),) -+ )) -+ print("done") -+ -+ print("inference done. Now waiting for the segmentation export to finish...") -+ _ = [i.get() for i in results] -+ # now apply postprocessing -+ # first load the postprocessing properties if they are present. Else raise a well visible warning -+ results = [] -+ pp_file = join(model, "postprocessing.json") -+ if isfile(pp_file): -+ print("postprocessing...") -+ shutil.copy(pp_file, os.path.dirname(output_filenames[0])) -+ # for_which_classes stores for which of the classes everything but the largest connected component needs to be -+ # removed -+ for_which_classes, min_valid_obj_size = load_postprocessing(pp_file) -+ results.append(pool.starmap_async(load_remove_save, -+ zip(output_filenames, output_filenames, -+ [for_which_classes] * len(output_filenames), -+ [min_valid_obj_size] * len(output_filenames)))) -+ _ = [i.get() for i in results] -+ else: -+ print("WARNING! Cannot run postprocessing because the postprocessing file is missing. Make sure to run " -+ "consolidate_folds in the output folder of the model first!\nThe folder you need to run this in is " -+ "%s" % model) -+ -+ pool.close() -+ pool.join() -+ -+ -+def predict_cases_fastest(model, list_of_lists, output_filenames, folds, num_threads_preprocessing, -+ num_threads_nifti_save, segs_from_prev_stage=None, do_tta=True, mixed_precision=True, -+ overwrite_existing=False, all_in_gpu=True, step_size=0.5, -+ checkpoint_name="model_final_checkpoint"): -+ assert len(list_of_lists) == len(output_filenames) -+ if segs_from_prev_stage is not None: assert len(segs_from_prev_stage) == len(output_filenames) -+ -+ pool = Pool(num_threads_nifti_save) -+ results = [] -+ -+ cleaned_output_files = [] -+ for o in output_filenames: -+ dr, f = os.path.split(o) -+ if len(dr) > 0: -+ maybe_mkdir_p(dr) -+ if not f.endswith(".nii.gz"): -+ f, _ = os.path.splitext(f) -+ f = f + ".nii.gz" -+ cleaned_output_files.append(join(dr, f)) -+ -+ if not overwrite_existing: -+ print("number of cases:", len(list_of_lists)) -+ not_done_idx = [i for i, j in enumerate(cleaned_output_files) if not isfile(j)] -+ -+ cleaned_output_files = [cleaned_output_files[i] for i in not_done_idx] -+ list_of_lists = [list_of_lists[i] for i in not_done_idx] -+ if segs_from_prev_stage is not None: -+ segs_from_prev_stage = [segs_from_prev_stage[i] for i in not_done_idx] -+ -+ print("number of cases that still need to be predicted:", len(cleaned_output_files)) -+ -+ print("emptying cuda cache") -+ torch.cuda.empty_cache() -+ -+ print("loading parameters for folds,", folds) -+ trainer, params = load_model_and_checkpoint_files(model, folds, mixed_precision=mixed_precision, checkpoint_name=checkpoint_name) -+ -+ print("starting preprocessing generator") -+ preprocessing = preprocess_multithreaded(trainer, list_of_lists, cleaned_output_files, num_threads_preprocessing, -+ segs_from_prev_stage) -+ -+ print("starting prediction...") -+ for preprocessed in preprocessing: -+ print("getting data from preprocessor") -+ output_filename, (d, dct) = preprocessed -+ print("got something") -+ if isinstance(d, str): -+ print("what I got is a string, so I need to load a file") -+ data = np.load(d) -+ os.remove(d) -+ d = data -+ -+ # preallocate the output arrays -+ # same dtype as the return value in predict_preprocessed_data_return_seg_and_softmax (saves time) -+ all_softmax_outputs = np.zeros((len(params), trainer.num_classes, *d.shape[1:]), dtype=np.float16) -+ all_seg_outputs = np.zeros((len(params), *d.shape[1:]), dtype=int) -+ print("predicting", output_filename) -+ -+ for i, p in enumerate(params): -+ trainer.load_checkpoint_ram(p, False) -+ res = trainer.predict_preprocessed_data_return_seg_and_softmax(d, do_tta, -+ trainer.data_aug_params['mirror_axes'], True, -+ step_size=step_size, use_gaussian=True, -+ all_in_gpu=all_in_gpu, -+ mixed_precision=mixed_precision) -+ if len(params) > 1: -+ # otherwise we dont need this and we can save ourselves the time it takes to copy that -+ all_softmax_outputs[i] = res[1] -+ all_seg_outputs[i] = res[0] -+ -+ print("aggregating predictions") -+ if len(params) > 1: -+ softmax_mean = np.mean(all_softmax_outputs, 0) -+ seg = softmax_mean.argmax(0) -+ else: -+ seg = all_seg_outputs[0] -+ -+ print("applying transpose_backward") -+ transpose_forward = trainer.plans.get('transpose_forward') -+ if transpose_forward is not None: -+ transpose_backward = trainer.plans.get('transpose_backward') -+ seg = seg.transpose([i for i in transpose_backward]) -+ -+ print("initializing segmentation export") -+ results.append(pool.starmap_async(save_segmentation_nifti, -+ ((seg, output_filename, dct, 0, None),) -+ )) -+ print("done") -+ -+ print("inference done. Now waiting for the segmentation export to finish...") -+ _ = [i.get() for i in results] -+ # now apply postprocessing -+ # first load the postprocessing properties if they are present. Else raise a well visible warning -+ results = [] -+ pp_file = join(model, "postprocessing.json") -+ if isfile(pp_file): -+ print("postprocessing...") -+ shutil.copy(pp_file, os.path.dirname(output_filenames[0])) -+ # for_which_classes stores for which of the classes everything but the largest connected component needs to be -+ # removed -+ for_which_classes, min_valid_obj_size = load_postprocessing(pp_file) -+ results.append(pool.starmap_async(load_remove_save, -+ zip(output_filenames, output_filenames, -+ [for_which_classes] * len(output_filenames), -+ [min_valid_obj_size] * len(output_filenames)))) -+ _ = [i.get() for i in results] -+ else: -+ print("WARNING! Cannot run postprocessing because the postprocessing file is missing. Make sure to run " -+ "consolidate_folds in the output folder of the model first!\nThe folder you need to run this in is " -+ "%s" % model) -+ -+ pool.close() -+ pool.join() -+ -+ -+def check_input_folder_and_return_caseIDs(input_folder, expected_num_modalities): -+ print("This model expects %d input modalities for each image" % expected_num_modalities) -+ files = subfiles(input_folder, suffix=".nii.gz", join=False, sort=True) -+ -+ maybe_case_ids = np.unique([i[:-12] for i in files]) -+ -+ remaining = deepcopy(files) -+ missing = [] -+ -+ assert len(files) > 0, "input folder did not contain any images (expected to find .nii.gz file endings)" -+ -+ # now check if all required files are present and that no unexpected files are remaining -+ for c in maybe_case_ids: -+ for n in range(expected_num_modalities): -+ expected_output_file = c + "_%04.0d.nii.gz" % n -+ if not isfile(join(input_folder, expected_output_file)): -+ missing.append(expected_output_file) -+ else: -+ remaining.remove(expected_output_file) -+ -+ print("Found %d unique case ids, here are some examples:" % len(maybe_case_ids), -+ np.random.choice(maybe_case_ids, min(len(maybe_case_ids), 10))) -+ print("If they don't look right, make sure to double check your filenames. They must end with _0000.nii.gz etc") -+ -+ if len(remaining) > 0: -+ print("found %d unexpected remaining files in the folder. Here are some examples:" % len(remaining), -+ np.random.choice(remaining, min(len(remaining), 10))) -+ -+ if len(missing) > 0: -+ print("Some files are missing:") -+ print(missing) -+ raise RuntimeError("missing files in input_folder") -+ -+ return maybe_case_ids -+ -+ -+def predict_from_folder(model: str, input_folder: str, output_folder: str, folds: Union[Tuple[int], List[int]], -+ save_npz: bool, num_threads_preprocessing: int, num_threads_nifti_save: int, -+ lowres_segmentations: Union[str, None], -+ part_id: int, num_parts: int, tta: bool, mixed_precision: bool = True, -+ overwrite_existing: bool = True, mode: str = 'normal', overwrite_all_in_gpu: bool = None, -+ step_size: float = 0.5, checkpoint_name: str = "model_final_checkpoint", -+ segmentation_export_kwargs: dict = None, pre_mode=None, fp=None): -+ """ -+ here we use the standard naming scheme to generate list_of_lists and output_files needed by predict_cases -+ -+ :param model: -+ :param input_folder: -+ :param output_folder: -+ :param folds: -+ :param save_npz: -+ :param num_threads_preprocessing: -+ :param num_threads_nifti_save: -+ :param lowres_segmentations: -+ :param part_id: -+ :param num_parts: -+ :param tta: -+ :param mixed_precision: -+ :param overwrite_existing: if not None then it will be overwritten with whatever is in there. None is default (no overwrite) -+ :return: -+ """ -+ maybe_mkdir_p(output_folder) -+ shutil.copy(join(model, 'plans.pkl'), output_folder) -+ -+ assert isfile(join(model, "plans.pkl")), "Folder with saved model weights must contain a plans.pkl file" -+ expected_num_modalities = load_pickle(join(model, "plans.pkl"))['num_modalities'] -+ -+ # check input folder integrity -+ case_ids = check_input_folder_and_return_caseIDs(input_folder, expected_num_modalities) -+ -+ output_files = [join(output_folder, i + ".nii.gz") for i in case_ids] -+ all_files = subfiles(input_folder, suffix=".nii.gz", join=False, sort=True) -+ list_of_lists = [[join(input_folder, i) for i in all_files if i[:len(j)].startswith(j) and -+ len(i) == (len(j) + 12)] for j in case_ids] -+ -+ if lowres_segmentations is not None: -+ assert isdir(lowres_segmentations), "if lowres_segmentations is not None then it must point to a directory" -+ lowres_segmentations = [join(lowres_segmentations, i + ".nii.gz") for i in case_ids] -+ assert all([isfile(i) for i in lowres_segmentations]), "not all lowres_segmentations files are present. " \ -+ "(I was searching for case_id.nii.gz in that folder)" -+ lowres_segmentations = lowres_segmentations[part_id::num_parts] -+ else: -+ lowres_segmentations = None -+ -+ if mode == "normal": # step this -+ if overwrite_all_in_gpu is None: # True -+ all_in_gpu = False -+ else: -+ all_in_gpu = overwrite_all_in_gpu -+ -+ return predict_cases(model, list_of_lists[part_id::num_parts], output_files[part_id::num_parts], folds, -+ save_npz, num_threads_preprocessing, num_threads_nifti_save, lowres_segmentations, tta, -+ mixed_precision=mixed_precision, overwrite_existing=overwrite_existing, all_in_gpu=all_in_gpu, -+ step_size=step_size, checkpoint_name=checkpoint_name, -+ segmentation_export_kwargs=segmentation_export_kwargs, pre_mode=pre_mode, fp=fp) -+ elif mode == "fast": -+ if overwrite_all_in_gpu is None: -+ all_in_gpu = True -+ else: -+ all_in_gpu = overwrite_all_in_gpu -+ -+ assert save_npz is False -+ return predict_cases_fast(model, list_of_lists[part_id::num_parts], output_files[part_id::num_parts], folds, -+ num_threads_preprocessing, num_threads_nifti_save, lowres_segmentations, -+ tta, mixed_precision=mixed_precision, overwrite_existing=overwrite_existing, all_in_gpu=all_in_gpu, -+ step_size=step_size, checkpoint_name=checkpoint_name, -+ segmentation_export_kwargs=segmentation_export_kwargs) -+ elif mode == "fastest": -+ if overwrite_all_in_gpu is None: -+ all_in_gpu = True -+ else: -+ all_in_gpu = overwrite_all_in_gpu -+ -+ assert save_npz is False -+ return predict_cases_fastest(model, list_of_lists[part_id::num_parts], output_files[part_id::num_parts], folds, -+ num_threads_preprocessing, num_threads_nifti_save, lowres_segmentations, -+ tta, mixed_precision=mixed_precision, overwrite_existing=overwrite_existing, all_in_gpu=all_in_gpu, -+ step_size=step_size, checkpoint_name=checkpoint_name) -+ else: -+ raise ValueError("unrecognized mode. Must be normal, fast or fastest") -+ -+ -+if __name__ == "__main__": -+ parser = argparse.ArgumentParser() -+ parser.add_argument("-i", '--input_folder', help="Must contain all modalities for each patient in the correct" -+ " order (same as training). Files must be named " -+ "CASENAME_XXXX.nii.gz where XXXX is the modality " -+ "identifier (0000, 0001, etc)", required=True) -+ parser.add_argument('-o', "--output_folder", required=True, help="folder for saving predictions") -+ parser.add_argument('-m', '--model_output_folder', -+ help='model output folder. Will automatically discover the folds ' -+ 'that were ' -+ 'run and use those as an ensemble', required=True) -+ parser.add_argument('-f', '--folds', nargs='+', default='None', help="folds to use for prediction. Default is None " -+ "which means that folds will be detected " -+ "automatically in the model output folder") -+ parser.add_argument('-z', '--save_npz', required=False, action='store_true', help="use this if you want to ensemble" -+ " these predictions with those of" -+ " other models. Softmax " -+ "probabilities will be saved as " -+ "compresed numpy arrays in " -+ "output_folder and can be merged " -+ "between output_folders with " -+ "merge_predictions.py") -+ parser.add_argument('-l', '--lowres_segmentations', required=False, default='None', help="if model is the highres " -+ "stage of the cascade then you need to use -l to specify where the segmentations of the " -+ "corresponding lowres unet are. Here they are required to do a prediction") -+ parser.add_argument("--part_id", type=int, required=False, default=0, help="Used to parallelize the prediction of " -+ "the folder over several GPUs. If you " -+ "want to use n GPUs to predict this " -+ "folder you need to run this command " -+ "n times with --part_id=0, ... n-1 and " -+ "--num_parts=n (each with a different " -+ "GPU (for example via " -+ "CUDA_VISIBLE_DEVICES=X)") -+ parser.add_argument("--num_parts", type=int, required=False, default=1, -+ help="Used to parallelize the prediction of " -+ "the folder over several GPUs. If you " -+ "want to use n GPUs to predict this " -+ "folder you need to run this command " -+ "n times with --part_id=0, ... n-1 and " -+ "--num_parts=n (each with a different " -+ "GPU (via " -+ "CUDA_VISIBLE_DEVICES=X)") -+ parser.add_argument("--num_threads_preprocessing", required=False, default=6, type=int, help= -+ "Determines many background processes will be used for data preprocessing. Reduce this if you " -+ "run into out of memory (RAM) problems. Default: 6") -+ parser.add_argument("--num_threads_nifti_save", required=False, default=2, type=int, help= -+ "Determines many background processes will be used for segmentation export. Reduce this if you " -+ "run into out of memory (RAM) problems. Default: 2") -+ parser.add_argument("--tta", required=False, type=int, default=1, help="Set to 0 to disable test time data " -+ "augmentation (speedup of factor " -+ "4(2D)/8(3D)), " -+ "lower quality segmentations") -+ parser.add_argument("--overwrite_existing", required=False, type=int, default=1, help="Set this to 0 if you need " -+ "to resume a previous " -+ "prediction. Default: 1 " -+ "(=existing segmentations " -+ "in output_folder will be " -+ "overwritten)") -+ parser.add_argument("--mode", type=str, default="normal", required=False) -+ parser.add_argument("--all_in_gpu", type=str, default="None", required=False, help="can be None, False or True") -+ parser.add_argument("--step_size", type=float, default=0.5, required=False, help="don't touch") -+ # parser.add_argument("--interp_order", required=False, default=3, type=int, -+ # help="order of interpolation for segmentations, has no effect if mode=fastest") -+ # parser.add_argument("--interp_order_z", required=False, default=0, type=int, -+ # help="order of interpolation along z is z is done differently") -+ # parser.add_argument("--force_separate_z", required=False, default="None", type=str, -+ # help="force_separate_z resampling. Can be None, True or False, has no effect if mode=fastest") -+ parser.add_argument('--disable_mixed_precision', default=False, action='store_true', required=False, -+ help='Predictions are done with mixed precision by default. This improves speed and reduces ' -+ 'the required vram. If you want to disable mixed precision you can set this flag. Note ' -+ 'that yhis is not recommended (mixed precision is ~2x faster!)') -+ -+ args = parser.parse_args() -+ input_folder = args.input_folder -+ output_folder = args.output_folder -+ part_id = args.part_id -+ num_parts = args.num_parts -+ model = args.model_output_folder -+ folds = args.folds -+ save_npz = args.save_npz -+ lowres_segmentations = args.lowres_segmentations -+ num_threads_preprocessing = args.num_threads_preprocessing -+ num_threads_nifti_save = args.num_threads_nifti_save -+ tta = args.tta -+ step_size = args.step_size -+ -+ # interp_order = args.interp_order -+ # interp_order_z = args.interp_order_z -+ # force_separate_z = args.force_separate_z -+ -+ # if force_separate_z == "None": -+ # force_separate_z = None -+ # elif force_separate_z == "False": -+ # force_separate_z = False -+ # elif force_separate_z == "True": -+ # force_separate_z = True -+ # else: -+ # raise ValueError("force_separate_z must be None, True or False. Given: %s" % force_separate_z) -+ -+ overwrite = args.overwrite_existing -+ mode = args.mode -+ all_in_gpu = args.all_in_gpu -+ -+ if lowres_segmentations == "None": -+ lowres_segmentations = None -+ -+ if isinstance(folds, list): -+ if folds[0] == 'all' and len(folds) == 1: -+ pass -+ else: -+ folds = [int(i) for i in folds] -+ elif folds == "None": -+ folds = None -+ else: -+ raise ValueError("Unexpected value for argument folds") -+ -+ if tta == 0: -+ tta = False -+ elif tta == 1: -+ tta = True -+ else: -+ raise ValueError("Unexpected value for tta, Use 1 or 0") -+ -+ if overwrite == 0: -+ overwrite = False -+ elif overwrite == 1: -+ overwrite = True -+ else: -+ raise ValueError("Unexpected value for overwrite, Use 1 or 0") -+ -+ assert all_in_gpu in ['None', 'False', 'True'] -+ if all_in_gpu == "None": -+ all_in_gpu = None -+ elif all_in_gpu == "True": -+ all_in_gpu = True -+ elif all_in_gpu == "False": -+ all_in_gpu = False -+ -+ predict_from_folder(model, input_folder, output_folder, folds, save_npz, num_threads_preprocessing, -+ num_threads_nifti_save, lowres_segmentations, part_id, num_parts, tta, mixed_precision=not args.disable_mixed_precision, -+ overwrite_existing=overwrite, mode=mode, overwrite_all_in_gpu=all_in_gpu, step_size=step_size) -diff --git a/pytorch/nnunet/inference/predict_simple2.py b/pytorch/nnunet/inference/predict_simple2.py -new file mode 100644 -index 0000000..2af423e ---- /dev/null -+++ b/pytorch/nnunet/inference/predict_simple2.py -@@ -0,0 +1,238 @@ -+# Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany -+# -+# Licensed under the Apache License, Version 2.0 (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# http://www.apache.org/licenses/LICENSE-2.0 -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+ -+ -+import argparse -+import torch -+ -+from nnunet.inference.predict2 import predict_from_folder -+from nnunet.paths import default_plans_identifier, network_training_output_dir, default_cascade_trainer, default_trainer -+from batchgenerators.utilities.file_and_folder_operations import join, isdir -+from nnunet.utilities.task_name_id_conversion import convert_id_to_task_name -+from nnunet.inference.infer_path import INFERENCE_INPUT_FOLDER, INFERENCE_OUTPUT_FOLDER -+ -+ -+def main(): -+ parser = argparse.ArgumentParser() -+ parser.add_argument("-i", '--input_folder', help="Must contain all modalities for each patient in the correct" -+ " order (same as training). Files must be named " -+ "CASENAME_XXXX.nii.gz where XXXX is the modality " -+ "identifier (0000, 0001, etc)", required=False, -+ default=INFERENCE_INPUT_FOLDER) -+ parser.add_argument('-o', "--output_folder", required=False, -+ default=INFERENCE_OUTPUT_FOLDER, help="folder for saving predictions") -+ parser.add_argument('-t', '--task_name', help='task name or task ID, required.', -+ default="Task003_Liver", required=False) -+ parser.add_argument('-pm', '--pre_mode', help='predict mode', required=False, default=-1) -+ parser.add_argument('-fp', '--file_path', help='input or output file path for npu bin files', required=True) -+ parser.add_argument('-tr', '--trainer_class_name', -+ help='Name of the nnUNetTrainer used for 2D U-Net, full resolution 3D U-Net and low resolution ' -+ 'U-Net. The default is %s. If you are running inference with the cascade and the folder ' -+ 'pointed to by --lowres_segmentations does not contain the segmentation maps generated by ' -+ 'the low resolution U-Net then the low resolution segmentation maps will be automatically ' -+ 'generated. For this case, make sure to set the trainer class here that matches your ' -+ '--cascade_trainer_class_name (this part can be ignored if defaults are used).' -+ % default_trainer, -+ required=False, -+ default="nnUNetPlusPlusTrainerV2") -+ parser.add_argument('-ctr', '--cascade_trainer_class_name', -+ help="Trainer class name used for predicting the 3D full resolution U-Net part of the cascade." -+ "Default is %s" % default_cascade_trainer, required=False, -+ default=default_cascade_trainer) -+ -+ parser.add_argument('-m', '--model', help="2d, 3d_lowres, 3d_fullres or 3d_cascade_fullres. Default: 3d_fullres", -+ default="3d_fullres", required=False) -+ -+ parser.add_argument('-p', '--plans_identifier', help='do not touch this unless you know what you are doing', -+ default=default_plans_identifier, required=False) -+ -+ parser.add_argument('-f', '--folds', nargs='+', default="None", -+ help="folds to use for prediction. Default is None which means that folds will be detected " -+ "automatically in the model output folder") -+ -+ parser.add_argument('-z', '--save_npz', required=False, action='store_true', -+ help="use this if you want to ensemble these predictions with those of other models. Softmax " -+ "probabilities will be saved as compressed numpy arrays in output_folder and can be " -+ "merged between output_folders with nnUNet_ensemble_predictions") -+ -+ parser.add_argument('-l', '--lowres_segmentations', required=False, default='None', -+ help="if model is the highres stage of the cascade then you can use this folder to provide " -+ "predictions from the low resolution 3D U-Net. If this is left at default, the " -+ "predictions will be generated automatically (provided that the 3D low resolution U-Net " -+ "network weights are present") -+ -+ parser.add_argument("--part_id", type=int, required=False, default=0, help="Used to parallelize the prediction of " -+ "the folder over several GPUs. If you " -+ "want to use n GPUs to predict this " -+ "folder you need to run this command " -+ "n times with --part_id=0, ... n-1 and " -+ "--num_parts=n (each with a different " -+ "GPU (for example via " -+ "CUDA_VISIBLE_DEVICES=X)") -+ -+ parser.add_argument("--num_parts", type=int, required=False, default=1, -+ help="Used to parallelize the prediction of " -+ "the folder over several GPUs. If you " -+ "want to use n GPUs to predict this " -+ "folder you need to run this command " -+ "n times with --part_id=0, ... n-1 and " -+ "--num_parts=n (each with a different " -+ "GPU (via " -+ "CUDA_VISIBLE_DEVICES=X)") -+ -+ parser.add_argument("--num_threads_preprocessing", required=False, default=6, type=int, help= -+ "Determines many background processes will be used for data preprocessing. Reduce this if you " -+ "run into out of memory (RAM) problems. Default: 6") -+ -+ parser.add_argument("--num_threads_nifti_save", required=False, default=2, type=int, help= -+ "Determines many background processes will be used for segmentation export. Reduce this if you " -+ "run into out of memory (RAM) problems. Default: 2") -+ -+ parser.add_argument("--disable_tta", required=False, default=False, action="store_true", -+ help="set this flag to disable test time data augmentation via mirroring. Speeds up inference " -+ "by roughly factor 4 (2D) or 8 (3D)") -+ -+ parser.add_argument("--overwrite_existing", required=False, default=False, action="store_true", -+ help="Set this flag if the target folder contains predictions that you would like to overwrite") -+ -+ parser.add_argument("--mode", type=str, default="normal", required=False, help="Hands off!") -+ parser.add_argument("--all_in_gpu", type=str, default="None", required=False, help="can be None, False or True. " -+ "Do not touch.") -+ parser.add_argument("--step_size", type=float, default=0.5, required=False, help="don't touch") -+ # parser.add_argument("--interp_order", required=False, default=3, type=int, -+ # help="order of interpolation for segmentations, has no effect if mode=fastest. Do not touch this.") -+ # parser.add_argument("--interp_order_z", required=False, default=0, type=int, -+ # help="order of interpolation along z is z is done differently. Do not touch this.") -+ # parser.add_argument("--force_separate_z", required=False, default="None", type=str, -+ # help="force_separate_z resampling. Can be None, True or False, has no effect if mode=fastest. " -+ # "Do not touch this.") -+ parser.add_argument('-chk', -+ help='checkpoint name, default: model_final_checkpoint', -+ required=False, -+ default='model_final_checkpoint') -+ parser.add_argument('--disable_mixed_precision', default=False, action='store_true', required=False, -+ help='Predictions are done with mixed precision by default. This improves speed and reduces ' -+ 'the required vram. If you want to disable mixed precision you can set this flag. Note ' -+ 'that yhis is not recommended (mixed precision is ~2x faster!)') -+ -+ args = parser.parse_args() -+ print(args) -+ -+ input_folder = args.input_folder -+ output_folder = args.output_folder -+ part_id = args.part_id -+ # 推理模式 -+ pre_mode = args.pre_mode -+ fp = args.file_path -+ num_parts = args.num_parts -+ folds = args.folds -+ save_npz = args.save_npz -+ lowres_segmentations = args.lowres_segmentations -+ num_threads_preprocessing = args.num_threads_preprocessing -+ num_threads_nifti_save = args.num_threads_nifti_save -+ disable_tta = args.disable_tta -+ step_size = args.step_size -+ # interp_order = args.interp_order -+ # interp_order_z = args.interp_order_z -+ # force_separate_z = args.force_separate_z -+ overwrite_existing = args.overwrite_existing -+ mode = args.mode -+ all_in_gpu = args.all_in_gpu -+ model = args.model -+ trainer_class_name = args.trainer_class_name -+ cascade_trainer_class_name = args.cascade_trainer_class_name -+ -+ task_name = args.task_name -+ -+ if not task_name.startswith("Task"): -+ task_id = int(task_name) -+ task_name = convert_id_to_task_name(task_id) -+ -+ assert model in ["2d", "3d_lowres", "3d_fullres", "3d_cascade_fullres"], "-m must be 2d, 3d_lowres, 3d_fullres or " \ -+ "3d_cascade_fullres" -+ -+ # if force_separate_z == "None": -+ # force_separate_z = None -+ # elif force_separate_z == "False": -+ # force_separate_z = False -+ # elif force_separate_z == "True": -+ # force_separate_z = True -+ # else: -+ # raise ValueError("force_separate_z must be None, True or False. Given: %s" % force_separate_z) -+ -+ if lowres_segmentations == "None": -+ lowres_segmentations = None -+ -+ if isinstance(folds, list): -+ if folds[0] == 'all' and len(folds) == 1: -+ pass -+ else: -+ folds = [int(i) for i in folds] -+ elif folds == "None": -+ folds = None -+ else: -+ raise ValueError("Unexpected value for argument folds") -+ -+ assert all_in_gpu in ['None', 'False', 'True'] -+ if all_in_gpu == "None": -+ all_in_gpu = None -+ elif all_in_gpu == "True": -+ all_in_gpu = True -+ elif all_in_gpu == "False": -+ all_in_gpu = False -+ -+ # we need to catch the case where model is 3d cascade fullres and the low resolution folder has not been set. -+ # In that case we need to try and predict with 3d low res first -+ if model == "3d_cascade_fullres" and lowres_segmentations is None: -+ print("lowres_segmentations is None. Attempting to predict 3d_lowres first...") -+ assert part_id == 0 and num_parts == 1, "if you don't specify a --lowres_segmentations folder for the " \ -+ "inference of the cascade, custom values for part_id and num_parts " \ -+ "are not supported. If you wish to have multiple parts, please " \ -+ "run the 3d_lowres inference first (separately)" -+ model_folder_name = join(network_training_output_dir, "3d_lowres", task_name, trainer_class_name + "__" + -+ args.plans_identifier) -+ assert isdir(model_folder_name), "model output folder not found. Expected: %s" % model_folder_name -+ lowres_output_folder = join(output_folder, "3d_lowres_predictions") -+ predict_from_folder(model_folder_name, input_folder, lowres_output_folder, folds, False, -+ num_threads_preprocessing, num_threads_nifti_save, None, part_id, num_parts, not disable_tta, -+ overwrite_existing=overwrite_existing, mode=mode, overwrite_all_in_gpu=all_in_gpu, -+ mixed_precision=not args.disable_mixed_precision, -+ step_size=step_size) -+ lowres_segmentations = lowres_output_folder -+ torch.cuda.empty_cache() -+ print("3d_lowres done") -+ -+ if model == "3d_cascade_fullres": -+ trainer = cascade_trainer_class_name -+ else: -+ trainer = trainer_class_name -+ print(network_training_output_dir) -+ print(model) -+ print(task_name) -+ print(trainer) -+ print(args.plans_identifier) -+ model_folder_name = join(network_training_output_dir, model, task_name, trainer + "__" + -+ args.plans_identifier) -+ print("using model stored in ", model_folder_name) -+ assert isdir(model_folder_name), "model output folder not found. Expected: %s" % model_folder_name -+ -+ predict_from_folder(model_folder_name, input_folder, output_folder, folds, save_npz, num_threads_preprocessing, -+ num_threads_nifti_save, lowres_segmentations, part_id, num_parts, not disable_tta, -+ overwrite_existing=overwrite_existing, mode=mode, overwrite_all_in_gpu=all_in_gpu, -+ mixed_precision=not args.disable_mixed_precision, -+ step_size=step_size, checkpoint_name=args.chk, pre_mode=pre_mode, fp=fp) -+ -+ -+if __name__ == "__main__": -+ main() -diff --git a/pytorch/nnunet/inference/read_bin.py b/pytorch/nnunet/inference/read_bin.py -new file mode 100644 -index 0000000..972d940 ---- /dev/null -+++ b/pytorch/nnunet/inference/read_bin.py -@@ -0,0 +1,30 @@ -+import numpy -+import pdb -+import os -+ -+ -+def read_from_bin(file_name, folder_path='/root/heyupeng/result/dumpOutput_device0/'): -+ file = os.path.join(folder_path, file_name) -+ data = numpy.fromfile(file, dtype='float32') -+ data = data.reshape(3, 128, 128, 128) -+ return data -+ -+ -+def main(): -+ file = 'liver_132_0_128_0_128_0_128_1.bin' -+ print('ready to load:', file) -+ data = numpy.fromfile(file, dtype='float32') -+ data = data.reshape(3, 128, 128, 128) -+ pdb.set_trace() -+ print(data.shape) -+ for i in range(5): -+ print(data[0, 0, 0, i*7:(i+1)*7]) -+ print('-----') -+ for i in range(5): -+ print(data[0, 0, 0, i*7+50:(i+1)*7+50]) -+ pdb.set_trace() -+ print('end\n') -+ -+ -+if __name__ == "__main__": -+ main() -\ No newline at end of file -diff --git a/pytorch/nnunet/inference/read_pkl_file.py b/pytorch/nnunet/inference/read_pkl_file.py -new file mode 100644 -index 0000000..5dcc37b ---- /dev/null -+++ b/pytorch/nnunet/inference/read_pkl_file.py -@@ -0,0 +1,22 @@ -+import numpy -+import pdb -+import os -+import pickle -+ -+ -+def read_pkl(file_name, folder_path='/data/yupeng/environment_variables/nnUNet_preprocessed/Task003_Liver/'): -+ file = os.path.join(folder_path, file_name) -+ data = open(file, 'rb') -+ data = pickle.load(data) -+ return data -+ -+ -+def main(): -+ file = 'dataset_properties.pkl' -+ print('ready to load:', file) -+ data = read_pkl(file) -+ print('end\n') -+ -+ -+if __name__ == "__main__": -+ main() -\ No newline at end of file -diff --git a/pytorch/nnunet/inference/read_txt.py b/pytorch/nnunet/inference/read_txt.py -new file mode 100644 -index 0000000..37c94aa ---- /dev/null -+++ b/pytorch/nnunet/inference/read_txt.py -@@ -0,0 +1,29 @@ -+import numpy -+import pdb -+import os -+ -+ -+def read_from_bin(file_name, folder_path='/root/heyupeng/result/dumpOutput_device0/'): -+ file = os.path.join(folder_path, file_name) -+ data = numpy.loadtxt(file) -+ data = data.reshape(3, 128, 128, 128) -+ return data -+ -+ -+def main(): -+ file = 'liver_132_0_128_0_128_0_128_1.txt' -+ print('ready to load:', file) -+ data = numpy.loadtxt(file) -+ data = data.reshape(3, 128, 128, 128) -+ pdb.set_trace() -+ print(data.shape) -+ for i in range(5): -+ print(data[0, 0, 0, i*7:(i+1)*7]) -+ print('-----') -+ for i in range(5): -+ print(data[0, 0, 0, i*7+50:(i+1)*7+50]) -+ pdb.set_trace() -+ print('end\n') -+ -+if __name__ == "__main__": -+ main() -diff --git a/pytorch/nnunet/network_architecture/generic_UNetPlusPlus.py b/pytorch/nnunet/network_architecture/generic_UNetPlusPlus.py -index 5c2f816..5b831ea 100644 ---- a/pytorch/nnunet/network_architecture/generic_UNetPlusPlus.py -+++ b/pytorch/nnunet/network_architecture/generic_UNetPlusPlus.py -@@ -21,7 +21,8 @@ import numpy as np - from nnunet.network_architecture.initialization import InitWeights_He - from nnunet.network_architecture.neural_network import SegmentationNetwork - import torch.nn.functional -- -+import pdb -+# pdb.set_trace() - - class ConvDropoutNormNonlin(nn.Module): - """ -@@ -393,7 +394,7 @@ class Generic_UNetPlusPlus(SegmentationNetwork): - - def forward(self, x): - # skips = [] -- seg_outputs = [] -+ seg_outputs = [] # x是五维的 - x0_0 = self.conv_blocks_context[0](x) - x1_0 = self.conv_blocks_context[1](x0_0) - x0_1 = self.loc4[0](torch.cat([x0_0, self.up4[0](x1_0)], 1)) -@@ -425,7 +426,7 @@ class Generic_UNetPlusPlus(SegmentationNetwork): - x0_5 = self.loc0[4](torch.cat([x0_0, x0_1, x0_2, x0_3, x0_4, self.up0[4](x1_4)], 1)) - seg_outputs.append(self.final_nonlin(self.seg_outputs[-5](x0_5))) - -- if self._deep_supervision and self.do_ds: -+ if self._deep_supervision and self.do_ds: # False - return tuple([seg_outputs[-1]] + [i(j) for i, j in - zip(list(self.upscale_logits_ops)[::-1], seg_outputs[:-1][::-1])]) - else: -diff --git a/pytorch/nnunet/network_architecture/neural_network.py b/pytorch/nnunet/network_architecture/neural_network.py -index baa8a05..9425fe9 100644 ---- a/pytorch/nnunet/network_architecture/neural_network.py -+++ b/pytorch/nnunet/network_architecture/neural_network.py -@@ -21,8 +21,14 @@ from torch import nn - import torch - from scipy.ndimage.filters import gaussian_filter - from typing import Union, Tuple, List -+import os - - from torch.cuda.amp import autocast ++# Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++ ++ ++import argparse ++from copy import deepcopy ++from typing import Tuple, Union, List ++ ++import numpy as np ++from batchgenerators.augmentations.utils import resize_segmentation ++from nnunet.inference.segmentation_export import save_segmentation_nifti_from_softmax, save_segmentation_nifti ++from batchgenerators.utilities.file_and_folder_operations import * ++from multiprocessing import Process, Queue ++import torch ++import SimpleITK as sitk ++import shutil ++from multiprocessing import Pool ++from nnunet.postprocessing.connected_components import load_remove_save, load_postprocessing ++from nnunet.training.model_restore import load_model_and_checkpoint_files ++from nnunet.training.network_training.nnUNetTrainer import nnUNetTrainer ++from nnunet.utilities.one_hot_encoding import to_one_hot ++from nnunet.utilities.to_torch import maybe_to_torch, to_cuda +import pdb -+from glob import glob -+import time -+from nnunet.inference.read_bin import read_from_bin -+from nnunet.inference.infer_path import INFERENCE_SHAPE_PATH, INFERENCE_BIN_INPUT_FOLDER, INFERENCE_BIN_OUTPUT_FOLDER - - - class NeuralNetwork(nn.Module): -@@ -75,7 +81,8 @@ class SegmentationNetwork(NeuralNetwork): - step_size: float = 0.5, patch_size: Tuple[int, ...] = None, regions_class_order: Tuple[int, ...] = None, - use_gaussian: bool = False, pad_border_mode: str = "constant", - pad_kwargs: dict = None, all_in_gpu: bool = False, -- verbose: bool = True, mixed_precision: bool = True) -> Tuple[np.ndarray, np.ndarray]: -+ verbose: bool = True, mixed_precision: bool = True, img_name=None, -+ pre_mode=None, fp=None) -> Tuple[np.ndarray, np.ndarray]: - """ - Use this function to predict a 3D image. It does not matter whether the network is a 2D or 3D U-Net, it will - detect that automatically and run the appropriate code. -@@ -133,7 +140,7 @@ class SegmentationNetwork(NeuralNetwork): - - assert len(x.shape) == 4, "data must have shape (c,x,y,z)" - -- if mixed_precision: -+ if mixed_precision: # True - context = autocast - else: - context = no_op -@@ -141,11 +148,11 @@ class SegmentationNetwork(NeuralNetwork): - with context(): - with torch.no_grad(): - if self.conv_op == nn.Conv3d: -- if use_sliding_window: -+ if use_sliding_window: # 走到这里 - res = self._internal_predict_3D_3Dconv_tiled(x, step_size, do_mirroring, mirror_axes, patch_size, - regions_class_order, use_gaussian, pad_border_mode, - pad_kwargs=pad_kwargs, all_in_gpu=all_in_gpu, -- verbose=verbose) -+ verbose=verbose, img_name=img_name, pre_mode=pre_mode, fp=fp) - else: - res = self._internal_predict_3D_3Dconv(x, patch_size, do_mirroring, mirror_axes, regions_class_order, - pad_border_mode, pad_kwargs=pad_kwargs, verbose=verbose) -@@ -284,19 +291,161 @@ class SegmentationNetwork(NeuralNetwork): - - return steps - -+ # def _internal_predict_3D_3Dconv_tiled(self, x: np.ndarray, step_size: float, do_mirroring: bool, mirror_axes: tuple, -+ # patch_size: tuple, regions_class_order: tuple, use_gaussian: bool, -+ # pad_border_mode: str, pad_kwargs: dict, all_in_gpu: bool, -+ # verbose: bool, img_name=None) -> Tuple[np.ndarray, np.ndarray]: -+ # # better safe than sorry -+ # assert len(x.shape) == 4, "x must be (c, x, y, z)" -+ # assert self.get_device() != "cpu" -+ # if verbose: print("step_size:", step_size) # 0.5 -+ # if verbose: print("do mirror:", do_mirroring) # True -+ # -+ # torch.cuda.empty_cache() -+ # -+ # assert patch_size is not None, "patch_size cannot be None for tiled prediction" # 128, 128, 128 -+ # -+ # # for sliding window inference the image must at least be as large as the patch size. It does not matter -+ # # whether the shape is divisible by 2**num_pool as long as the patch size is -+ # data, slicer = pad_nd_image(x, patch_size, pad_border_mode, pad_kwargs, True, None) -+ # data_shape = data.shape # still c, x, y, z ++ ++ ++def preprocess_save_to_queue(preprocess_fn, q, list_of_lists, output_files, segs_from_prev_stage, classes, ++ transpose_forward): ++ # suppress output ++ # sys.stdout = open(os.devnull, 'w') ++ ++ errors_in = [] ++ for i, l in enumerate(list_of_lists): ++ try: ++ output_file = output_files[i] ++ print("preprocessing", output_file) ++ d, _, dct = preprocess_fn(l) ++ # print(output_file, dct) ++ if segs_from_prev_stage[i] is not None: ++ assert isfile(segs_from_prev_stage[i]) and segs_from_prev_stage[i].endswith( ++ ".nii.gz"), "segs_from_prev_stage" \ ++ " must point to a " \ ++ "segmentation file" ++ seg_prev = sitk.GetArrayFromImage(sitk.ReadImage(segs_from_prev_stage[i])) ++ # check to see if shapes match ++ img = sitk.GetArrayFromImage(sitk.ReadImage(l[0])) ++ assert all([i == j for i, j in zip(seg_prev.shape, img.shape)]), "image and segmentation from previous " \ ++ "stage don't have the same pixel array " \ ++ "shape! image: %s, seg_prev: %s" % \ ++ (l[0], segs_from_prev_stage[i]) ++ seg_prev = seg_prev.transpose(transpose_forward) ++ seg_reshaped = resize_segmentation(seg_prev, d.shape[1:], order=1, cval=0) ++ seg_reshaped = to_one_hot(seg_reshaped, classes) ++ d = np.vstack((d, seg_reshaped)).astype(np.float32) ++ """There is a problem with python process communication that prevents us from communicating obejcts ++ larger than 2 GB between processes (basically when the length of the pickle string that will be sent is ++ communicated by the multiprocessing.Pipe object then the placeholder (\%i I think) does not allow for long ++ enough strings (lol). This could be fixed by changing i to l (for long) but that would require manually ++ patching system python code. We circumvent that problem here by saving softmax_pred to a npy file that will ++ then be read (and finally deleted) by the Process. save_segmentation_nifti_from_softmax can take either ++ filename or np.ndarray and will handle this automatically""" ++ print(d.shape) ++ if np.prod(d.shape) > (2e9 / 4 * 0.85): # *0.85 just to be save, 4 because float32 is 4 bytes ++ print( ++ "This output is too large for python process-process communication. " ++ "Saving output temporarily to disk") ++ np.save(output_file[:-7] + ".npy", d) ++ d = output_file[:-7] + ".npy" ++ q.put((output_file, (d, dct))) ++ except KeyboardInterrupt: ++ raise KeyboardInterrupt ++ except Exception as e: ++ print("error in", l) ++ print(e) ++ q.put("end") ++ if len(errors_in) > 0: ++ print("There were some errors in the following cases:", errors_in) ++ print("These cases were ignored.") ++ else: ++ print("This worker has ended successfully, no errors to report") ++ # restore output ++ # sys.stdout = sys.__stdout__ ++ ++ ++def preprocess_multithreaded(trainer, list_of_lists, output_files, num_processes=2, segs_from_prev_stage=None): ++ if segs_from_prev_stage is None: ++ segs_from_prev_stage = [None] * len(list_of_lists) ++ ++ num_processes = min(len(list_of_lists), num_processes) ++ ++ classes = list(range(1, trainer.num_classes)) ++ assert isinstance(trainer, nnUNetTrainer) ++ q = Queue(1) ++ processes = [] ++ for i in range(num_processes): ++ pr = Process(target=preprocess_save_to_queue, args=(trainer.preprocess_patient, q, ++ list_of_lists[i::num_processes], ++ output_files[i::num_processes], ++ segs_from_prev_stage[i::num_processes], ++ classes, trainer.plans['transpose_forward'])) ++ pr.start() ++ processes.append(pr) ++ ++ try: ++ end_ctr = 0 ++ while end_ctr != num_processes: ++ item = q.get() ++ if item == "end": ++ end_ctr += 1 ++ continue ++ else: ++ yield item ++ ++ finally: ++ for p in processes: ++ if p.is_alive(): ++ p.terminate() # this should not happen but better safe than sorry right ++ p.join() ++ ++ q.close() ++ ++ ++def pth2onnx(model, output_file=r'/home/yupeng/HUAWEI/UNetPlusPlus/pytorch/nnunet/run/nnunetplusplus.onnx'): ++ # model = EfficientNet.from_pretrained('efficientnet-b0', weights_path=input_file) ++ # 调整模型为eval mode ++ model.eval() ++ # 输入节点名 ++ input_names = ["image"] ++ # 输出节点名 ++ output_names = ["class"] ++ dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} ++ dummy_input = torch.randn(1, 1, 128, 128, 128) ++ # dummy_input = to_cuda(dummy_input) ++ # verbose=True,支持打印onnx节点和对应的PyTorch代码行 ++ torch.onnx.export(model, dummy_input, output_file, input_names=input_names, dynamic_axes=dynamic_axes, ++ output_names=output_names, opset_version=11, verbose=True) ++ ++ ++def predict_cases(model, list_of_lists, output_filenames, folds, save_npz, num_threads_preprocessing, ++ num_threads_nifti_save, segs_from_prev_stage=None, do_tta=True, mixed_precision=True, overwrite_existing=False, ++ all_in_gpu=False, step_size=0.5, checkpoint_name="model_final_checkpoint", ++ segmentation_export_kwargs: dict = None, pre_mode=None, fp=None): ++ """ ++ :param segmentation_export_kwargs: ++ :param model: folder where the model is saved, must contain fold_x subfolders ++ :param list_of_lists: [[case0_0000.nii.gz, case0_0001.nii.gz], [case1_0000.nii.gz, case1_0001.nii.gz], ...] ++ :param output_filenames: [output_file_case0.nii.gz, output_file_case1.nii.gz, ...] ++ :param folds: default: (0, 1, 2, 3, 4) (but can also be 'all' or a subset of the five folds, for example use (0, ) ++ for using only fold_0 ++ :param save_npz: default: False ++ :param num_threads_preprocessing: ++ :param num_threads_nifti_save: ++ :param segs_from_prev_stage: ++ :param do_tta: default: True, can be set to False for a 8x speedup at the cost of a reduced segmentation quality ++ :param overwrite_existing: default: True ++ :param mixed_precision: if None then we take no action. If True/False we overwrite what the model has in its init ++ :return: ++ """ ++ assert len(list_of_lists) == len(output_filenames) ++ if segs_from_prev_stage is not None: assert len(segs_from_prev_stage) == len(output_filenames) ++ ++ pool = Pool(num_threads_nifti_save) ++ results = [] ++ ++ cleaned_output_files = [] ++ for o in output_filenames: ++ dr, f = os.path.split(o) ++ if len(dr) > 0: ++ maybe_mkdir_p(dr) ++ if not f.endswith(".nii.gz"): ++ f, _ = os.path.splitext(f) ++ f = f + ".nii.gz" ++ cleaned_output_files.append(join(dr, f)) ++ ++ if not overwrite_existing: ++ print("number of cases:", len(list_of_lists)) ++ not_done_idx = [i for i, j in enumerate(cleaned_output_files) if not isfile(j)] ++ ++ cleaned_output_files = [cleaned_output_files[i] for i in not_done_idx] ++ list_of_lists = [list_of_lists[i] for i in not_done_idx] ++ if segs_from_prev_stage is not None: ++ segs_from_prev_stage = [segs_from_prev_stage[i] for i in not_done_idx] ++ ++ print("number of cases that still need to be predicted:", len(cleaned_output_files)) ++ ++ print("emptying cuda cache") ++ torch.cuda.empty_cache() ++ ''' ++ model='/data/yupeng/environment_variables/RESULTS_FOLDER/nnUNet/3d_fullres/Task003_Liver/nnUNetPlusPlusTrainerV2__nnUNetPlansv2.1' ++ folds=None ++ mixed_precision=True ++ checkpoint_name='model_final_checkpoint' ++ trainer=class-nnUNetPlusPlusTrainerV2 ++ params=list 5 -> dict 6 -> epoch state_dict optimizer_state_dict lr_scheduler_state_dict plot_stuff amp_grad_scaler ++ ''' ++ print("loading parameters for folds,", folds) # 得到参数,实际还未加载进模型 ++ trainer, params = load_model_and_checkpoint_files(model, folds, mixed_precision=mixed_precision, checkpoint_name=checkpoint_name) ++ ++ if segmentation_export_kwargs is None: ++ if 'segmentation_export_params' in trainer.plans.keys(): ++ force_separate_z = trainer.plans['segmentation_export_params']['force_separate_z'] ++ interpolation_order = trainer.plans['segmentation_export_params']['interpolation_order'] ++ interpolation_order_z = trainer.plans['segmentation_export_params']['interpolation_order_z'] ++ else: # 走到这里 ++ force_separate_z = None ++ interpolation_order = 1 ++ interpolation_order_z = 0 ++ else: ++ force_separate_z = segmentation_export_kwargs['force_separate_z'] ++ interpolation_order = segmentation_export_kwargs['interpolation_order'] ++ interpolation_order_z = segmentation_export_kwargs['interpolation_order_z'] ++ ++ print("starting preprocessing generator") ++ preprocessing = preprocess_multithreaded(trainer, list_of_lists, cleaned_output_files, num_threads_preprocessing, ++ segs_from_prev_stage) ++ # unet++V2class, [['/data/yupeng/environment_variables/nnUNet_raw_data_base/nnUNet_raw_data/Task003_Liver/imagesTs/liver_132_0000.nii.gz']] ++ # ['/data/yupeng/environment_variables/output/liver_132.nii.gz'], 6, None ++ print("starting prediction...") ++ if int(pre_mode) == -1: ++ p = params[0] ++ trainer.load_checkpoint_ram(p, False) # nnUnetPlusPlusTrainerV2,实际函数在network_trainer里 ++ print('pth2onnx start') ++ pth2onnx(trainer.network, fp) ++ print('pth2onnx end') ++ print('onnx模型已经输出至:', fp) ++ import sys ++ sys.exit(0) ++ all_output_files = [] ++ for preprocessed in preprocessing: ++ output_filename, (d, dct) = preprocessed ++ print('output_filename, d, dct = ', output_filename, d, dct) ++ all_output_files.append(all_output_files) ++ if isinstance(d, str): ++ data = np.load(d) ++ os.remove(d) ++ d = data ++ print("predicting", output_filename) ++ softmax = [] ++ params = [params[0]] # 只求第一个模型的推理结果 ++ for p in params: ++ # trainer.load_checkpoint_ram(p, False) # nnUnetPlusPlusTrainerV2,实际函数在network_trainer里 ++ # output_filename = '/data/yupeng/environment_variables/output/liver_132.nii.gz' ++ ttttt = trainer.predict_preprocessed_data_return_seg_and_softmax(d, do_tta, trainer.data_aug_params[ ++ 'mirror_axes'], True, step_size=step_size, use_gaussian=True, all_in_gpu=all_in_gpu, ++ mixed_precision=mixed_precision, img_name=output_filename, pre_mode=pre_mode, fp=fp) # tuple(ndarray 489 500 500; 3 489 500 500) ++ softmax.append(ttttt[1][None]) # 扩充了1 3 489 500 500 ++ ''' ++ d= ++ do_tta= ++ step_size= ++ all_in_gpu= ++ mixed_precision= ++ softmax= ++ ''' ++ # softmax是list 5,每个元素是ndarray 1 3 489 500 500 ++ softmax = np.vstack(softmax) # 5 3 489 500 500 ++ softmax_mean = np.mean(softmax, 0) # 3 489 500 500 ++ ++ transpose_forward = trainer.plans.get('transpose_forward') # [0,1,2] ++ if transpose_forward is not None: ++ transpose_backward = trainer.plans.get('transpose_backward') ++ softmax_mean = softmax_mean.transpose([0] + [i + 1 for i in transpose_backward]) ++ ++ if save_npz: # False ++ npz_file = output_filename[:-7] + ".npz" ++ else: ++ npz_file = None ++ ++ if hasattr(trainer, 'regions_class_order'): # False ++ region_class_order = trainer.regions_class_order ++ else: ++ region_class_order = None ++ ++ """There is a problem with python process communication that prevents us from communicating obejcts ++ larger than 2 GB between processes (basically when the length of the pickle string that will be sent is ++ communicated by the multiprocessing.Pipe object then the placeholder (\%i I think) does not allow for long ++ enough strings (lol). This could be fixed by changing i to l (for long) but that would require manually ++ patching system python code. We circumvent that problem here by saving softmax_pred to a npy file that will ++ then be read (and finally deleted) by the Process. save_segmentation_nifti_from_softmax can take either ++ filename or np.ndarray and will handle this automatically""" ++ bytes_per_voxel = 4 ++ if all_in_gpu: ++ bytes_per_voxel = 2 # if all_in_gpu then the return value is half (float16) ++ if np.prod(softmax_mean.shape) > (2e9 / bytes_per_voxel * 0.85): # * 0.85 just to be save ++ print( ++ "This output is too large for python process-process communication. Saving output temporarily to disk") ++ np.save(output_filename[:-7] + ".npy", softmax_mean) ++ softmax_mean = output_filename[:-7] + ".npy" ++ ++ results.append(pool.starmap_async(save_segmentation_nifti_from_softmax, ++ ((softmax_mean, output_filename, dct, interpolation_order, region_class_order, ++ None, None, ++ npz_file, None, force_separate_z, interpolation_order_z),) ++ )) ++ ++ print("inference done. Now waiting for the segmentation export to finish...") ++ _ = [i.get() for i in results] ++ # now apply postprocessing ++ # first load the postprocessing properties if they are present. Else raise a well visible warning ++ results = [] ++ pp_file = join(model, "postprocessing.json") # '/data/yupeng/environment_variables/RESULTS_FOLDER/nnUNet/3d_fullres/Task003_Liver/nnUNetPlusPlusTrainerV2__nnUNetPlansv2.1/postprocessing.json' ++ if isfile(pp_file): ++ print("postprocessing...") ++ shutil.copy(pp_file, os.path.abspath(os.path.dirname(output_filenames[0]))) ++ # for_which_classes stores for which of the classes everything but the largest connected component needs to be ++ # removed ++ for_which_classes, min_valid_obj_size = load_postprocessing(pp_file) ++ results.append(pool.starmap_async(load_remove_save, ++ zip(output_filenames, output_filenames, ++ [for_which_classes] * len(output_filenames), ++ [min_valid_obj_size] * len(output_filenames)))) ++ _ = [i.get() for i in results] ++ else: ++ print("WARNING! Cannot run postprocessing because the postprocessing file is missing. Make sure to run " ++ "consolidate_folds in the output folder of the model first!\nThe folder you need to run this in is " ++ "%s" % model) ++ ++ pool.close() ++ pool.join() ++ ++def predict_cases_fast(model, list_of_lists, output_filenames, folds, num_threads_preprocessing, ++ num_threads_nifti_save, segs_from_prev_stage=None, do_tta=True, mixed_precision=True, ++ overwrite_existing=False, ++ all_in_gpu=False, step_size=0.5, checkpoint_name="model_final_checkpoint", ++ segmentation_export_kwargs: dict = None): ++ assert len(list_of_lists) == len(output_filenames) ++ if segs_from_prev_stage is not None: assert len(segs_from_prev_stage) == len(output_filenames) ++ ++ pool = Pool(num_threads_nifti_save) ++ results = [] ++ ++ cleaned_output_files = [] ++ for o in output_filenames: ++ dr, f = os.path.split(o) ++ if len(dr) > 0: ++ maybe_mkdir_p(dr) ++ if not f.endswith(".nii.gz"): ++ f, _ = os.path.splitext(f) ++ f = f + ".nii.gz" ++ cleaned_output_files.append(join(dr, f)) ++ ++ if not overwrite_existing: ++ print("number of cases:", len(list_of_lists)) ++ not_done_idx = [i for i, j in enumerate(cleaned_output_files) if not isfile(j)] ++ ++ cleaned_output_files = [cleaned_output_files[i] for i in not_done_idx] ++ list_of_lists = [list_of_lists[i] for i in not_done_idx] ++ if segs_from_prev_stage is not None: ++ segs_from_prev_stage = [segs_from_prev_stage[i] for i in not_done_idx] ++ ++ print("number of cases that still need to be predicted:", len(cleaned_output_files)) ++ ++ print("emptying cuda cache") ++ torch.cuda.empty_cache() ++ ++ print("loading parameters for folds,", folds) ++ trainer, params = load_model_and_checkpoint_files(model, folds, mixed_precision=mixed_precision, checkpoint_name=checkpoint_name) ++ ++ if segmentation_export_kwargs is None: ++ if 'segmentation_export_params' in trainer.plans.keys(): ++ force_separate_z = trainer.plans['segmentation_export_params']['force_separate_z'] ++ interpolation_order = trainer.plans['segmentation_export_params']['interpolation_order'] ++ interpolation_order_z = trainer.plans['segmentation_export_params']['interpolation_order_z'] ++ else: ++ force_separate_z = None ++ interpolation_order = 1 ++ interpolation_order_z = 0 ++ else: ++ force_separate_z = segmentation_export_kwargs['force_separate_z'] ++ interpolation_order = segmentation_export_kwargs['interpolation_order'] ++ interpolation_order_z = segmentation_export_kwargs['interpolation_order_z'] ++ ++ print("starting preprocessing generator") ++ preprocessing = preprocess_multithreaded(trainer, list_of_lists, cleaned_output_files, num_threads_preprocessing, ++ segs_from_prev_stage) ++ ++ print("starting prediction...") ++ for preprocessed in preprocessing: ++ print("getting data from preprocessor") ++ output_filename, (d, dct) = preprocessed ++ print("got something") ++ if isinstance(d, str): ++ print("what I got is a string, so I need to load a file") ++ data = np.load(d) ++ os.remove(d) ++ d = data ++ ++ # preallocate the output arrays ++ # same dtype as the return value in predict_preprocessed_data_return_seg_and_softmax (saves time) ++ softmax_aggr = None # np.zeros((trainer.num_classes, *d.shape[1:]), dtype=np.float16) ++ all_seg_outputs = np.zeros((len(params), *d.shape[1:]), dtype=int) ++ print("predicting", output_filename) ++ ++ for i, p in enumerate(params): ++ trainer.load_checkpoint_ram(p, False) ++ ++ res = trainer.predict_preprocessed_data_return_seg_and_softmax(d, do_tta, ++ trainer.data_aug_params['mirror_axes'], True, ++ step_size=step_size, use_gaussian=True, ++ all_in_gpu=all_in_gpu, ++ mixed_precision=mixed_precision) ++ ++ if len(params) > 1: ++ # otherwise we dont need this and we can save ourselves the time it takes to copy that ++ print("aggregating softmax") ++ if softmax_aggr is None: ++ softmax_aggr = res[1] ++ else: ++ softmax_aggr += res[1] ++ all_seg_outputs[i] = res[0] ++ ++ print("obtaining segmentation map") ++ if len(params) > 1: ++ # we dont need to normalize the softmax by 1 / len(params) because this would not change the outcome of the argmax ++ seg = softmax_aggr.argmax(0) ++ else: ++ seg = all_seg_outputs[0] ++ ++ print("applying transpose_backward") ++ transpose_forward = trainer.plans.get('transpose_forward') ++ if transpose_forward is not None: ++ transpose_backward = trainer.plans.get('transpose_backward') ++ seg = seg.transpose([i for i in transpose_backward]) ++ ++ print("initializing segmentation export") ++ results.append(pool.starmap_async(save_segmentation_nifti, ++ ((seg, output_filename, dct, interpolation_order, force_separate_z, ++ interpolation_order_z),) ++ )) ++ print("done") ++ ++ print("inference done. Now waiting for the segmentation export to finish...") ++ _ = [i.get() for i in results] ++ # now apply postprocessing ++ # first load the postprocessing properties if they are present. Else raise a well visible warning ++ results = [] ++ pp_file = join(model, "postprocessing.json") ++ if isfile(pp_file): ++ print("postprocessing...") ++ shutil.copy(pp_file, os.path.dirname(output_filenames[0])) ++ # for_which_classes stores for which of the classes everything but the largest connected component needs to be ++ # removed ++ for_which_classes, min_valid_obj_size = load_postprocessing(pp_file) ++ results.append(pool.starmap_async(load_remove_save, ++ zip(output_filenames, output_filenames, ++ [for_which_classes] * len(output_filenames), ++ [min_valid_obj_size] * len(output_filenames)))) ++ _ = [i.get() for i in results] ++ else: ++ print("WARNING! Cannot run postprocessing because the postprocessing file is missing. Make sure to run " ++ "consolidate_folds in the output folder of the model first!\nThe folder you need to run this in is " ++ "%s" % model) ++ ++ pool.close() ++ pool.join() ++ ++ ++def predict_cases_fastest(model, list_of_lists, output_filenames, folds, num_threads_preprocessing, ++ num_threads_nifti_save, segs_from_prev_stage=None, do_tta=True, mixed_precision=True, ++ overwrite_existing=False, all_in_gpu=True, step_size=0.5, ++ checkpoint_name="model_final_checkpoint"): ++ assert len(list_of_lists) == len(output_filenames) ++ if segs_from_prev_stage is not None: assert len(segs_from_prev_stage) == len(output_filenames) ++ ++ pool = Pool(num_threads_nifti_save) ++ results = [] ++ ++ cleaned_output_files = [] ++ for o in output_filenames: ++ dr, f = os.path.split(o) ++ if len(dr) > 0: ++ maybe_mkdir_p(dr) ++ if not f.endswith(".nii.gz"): ++ f, _ = os.path.splitext(f) ++ f = f + ".nii.gz" ++ cleaned_output_files.append(join(dr, f)) ++ ++ if not overwrite_existing: ++ print("number of cases:", len(list_of_lists)) ++ not_done_idx = [i for i, j in enumerate(cleaned_output_files) if not isfile(j)] ++ ++ cleaned_output_files = [cleaned_output_files[i] for i in not_done_idx] ++ list_of_lists = [list_of_lists[i] for i in not_done_idx] ++ if segs_from_prev_stage is not None: ++ segs_from_prev_stage = [segs_from_prev_stage[i] for i in not_done_idx] ++ ++ print("number of cases that still need to be predicted:", len(cleaned_output_files)) ++ ++ print("emptying cuda cache") ++ torch.cuda.empty_cache() ++ ++ print("loading parameters for folds,", folds) ++ trainer, params = load_model_and_checkpoint_files(model, folds, mixed_precision=mixed_precision, checkpoint_name=checkpoint_name) ++ ++ print("starting preprocessing generator") ++ preprocessing = preprocess_multithreaded(trainer, list_of_lists, cleaned_output_files, num_threads_preprocessing, ++ segs_from_prev_stage) ++ ++ print("starting prediction...") ++ for preprocessed in preprocessing: ++ print("getting data from preprocessor") ++ output_filename, (d, dct) = preprocessed ++ print("got something") ++ if isinstance(d, str): ++ print("what I got is a string, so I need to load a file") ++ data = np.load(d) ++ os.remove(d) ++ d = data ++ ++ # preallocate the output arrays ++ # same dtype as the return value in predict_preprocessed_data_return_seg_and_softmax (saves time) ++ all_softmax_outputs = np.zeros((len(params), trainer.num_classes, *d.shape[1:]), dtype=np.float16) ++ all_seg_outputs = np.zeros((len(params), *d.shape[1:]), dtype=int) ++ print("predicting", output_filename) ++ ++ for i, p in enumerate(params): ++ trainer.load_checkpoint_ram(p, False) ++ res = trainer.predict_preprocessed_data_return_seg_and_softmax(d, do_tta, ++ trainer.data_aug_params['mirror_axes'], True, ++ step_size=step_size, use_gaussian=True, ++ all_in_gpu=all_in_gpu, ++ mixed_precision=mixed_precision) ++ if len(params) > 1: ++ # otherwise we dont need this and we can save ourselves the time it takes to copy that ++ all_softmax_outputs[i] = res[1] ++ all_seg_outputs[i] = res[0] ++ ++ print("aggregating predictions") ++ if len(params) > 1: ++ softmax_mean = np.mean(all_softmax_outputs, 0) ++ seg = softmax_mean.argmax(0) ++ else: ++ seg = all_seg_outputs[0] ++ ++ print("applying transpose_backward") ++ transpose_forward = trainer.plans.get('transpose_forward') ++ if transpose_forward is not None: ++ transpose_backward = trainer.plans.get('transpose_backward') ++ seg = seg.transpose([i for i in transpose_backward]) ++ ++ print("initializing segmentation export") ++ results.append(pool.starmap_async(save_segmentation_nifti, ++ ((seg, output_filename, dct, 0, None),) ++ )) ++ print("done") ++ ++ print("inference done. Now waiting for the segmentation export to finish...") ++ _ = [i.get() for i in results] ++ # now apply postprocessing ++ # first load the postprocessing properties if they are present. Else raise a well visible warning ++ results = [] ++ pp_file = join(model, "postprocessing.json") ++ if isfile(pp_file): ++ print("postprocessing...") ++ shutil.copy(pp_file, os.path.dirname(output_filenames[0])) ++ # for_which_classes stores for which of the classes everything but the largest connected component needs to be ++ # removed ++ for_which_classes, min_valid_obj_size = load_postprocessing(pp_file) ++ results.append(pool.starmap_async(load_remove_save, ++ zip(output_filenames, output_filenames, ++ [for_which_classes] * len(output_filenames), ++ [min_valid_obj_size] * len(output_filenames)))) ++ _ = [i.get() for i in results] ++ else: ++ print("WARNING! Cannot run postprocessing because the postprocessing file is missing. Make sure to run " ++ "consolidate_folds in the output folder of the model first!\nThe folder you need to run this in is " ++ "%s" % model) ++ ++ pool.close() ++ pool.join() ++ ++ ++def check_input_folder_and_return_caseIDs(input_folder, expected_num_modalities): ++ print("This model expects %d input modalities for each image" % expected_num_modalities) ++ files = subfiles(input_folder, suffix=".nii.gz", join=False, sort=True) ++ ++ maybe_case_ids = np.unique([i[:-12] for i in files]) ++ ++ remaining = deepcopy(files) ++ missing = [] ++ ++ assert len(files) > 0, "input folder did not contain any images (expected to find .nii.gz file endings)" ++ ++ # now check if all required files are present and that no unexpected files are remaining ++ for c in maybe_case_ids: ++ for n in range(expected_num_modalities): ++ expected_output_file = c + "_%04.0d.nii.gz" % n ++ if not isfile(join(input_folder, expected_output_file)): ++ missing.append(expected_output_file) ++ else: ++ remaining.remove(expected_output_file) ++ ++ print("Found %d unique case ids, here are some examples:" % len(maybe_case_ids), ++ np.random.choice(maybe_case_ids, min(len(maybe_case_ids), 10))) ++ print("If they don't look right, make sure to double check your filenames. They must end with _0000.nii.gz etc") ++ ++ if len(remaining) > 0: ++ print("found %d unexpected remaining files in the folder. Here are some examples:" % len(remaining), ++ np.random.choice(remaining, min(len(remaining), 10))) ++ ++ if len(missing) > 0: ++ print("Some files are missing:") ++ print(missing) ++ raise RuntimeError("missing files in input_folder") ++ ++ return maybe_case_ids ++ ++ ++def predict_from_folder(model: str, input_folder: str, output_folder: str, folds: Union[Tuple[int], List[int]], ++ save_npz: bool, num_threads_preprocessing: int, num_threads_nifti_save: int, ++ lowres_segmentations: Union[str, None], ++ part_id: int, num_parts: int, tta: bool, mixed_precision: bool = True, ++ overwrite_existing: bool = True, mode: str = 'normal', overwrite_all_in_gpu: bool = None, ++ step_size: float = 0.5, checkpoint_name: str = "model_final_checkpoint", ++ segmentation_export_kwargs: dict = None, pre_mode=None, fp=None): ++ """ ++ here we use the standard naming scheme to generate list_of_lists and output_files needed by predict_cases ++ ++ :param model: ++ :param input_folder: ++ :param output_folder: ++ :param folds: ++ :param save_npz: ++ :param num_threads_preprocessing: ++ :param num_threads_nifti_save: ++ :param lowres_segmentations: ++ :param part_id: ++ :param num_parts: ++ :param tta: ++ :param mixed_precision: ++ :param overwrite_existing: if not None then it will be overwritten with whatever is in there. None is default (no overwrite) ++ :return: ++ """ ++ maybe_mkdir_p(output_folder) ++ shutil.copy(join(model, 'plans.pkl'), output_folder) ++ ++ assert isfile(join(model, "plans.pkl")), "Folder with saved model weights must contain a plans.pkl file" ++ expected_num_modalities = load_pickle(join(model, "plans.pkl"))['num_modalities'] ++ ++ # check input folder integrity ++ case_ids = check_input_folder_and_return_caseIDs(input_folder, expected_num_modalities) ++ ++ output_files = [join(output_folder, i + ".nii.gz") for i in case_ids] ++ all_files = subfiles(input_folder, suffix=".nii.gz", join=False, sort=True) ++ list_of_lists = [[join(input_folder, i) for i in all_files if i[:len(j)].startswith(j) and ++ len(i) == (len(j) + 12)] for j in case_ids] ++ ++ if lowres_segmentations is not None: ++ assert isdir(lowres_segmentations), "if lowres_segmentations is not None then it must point to a directory" ++ lowres_segmentations = [join(lowres_segmentations, i + ".nii.gz") for i in case_ids] ++ assert all([isfile(i) for i in lowres_segmentations]), "not all lowres_segmentations files are present. " \ ++ "(I was searching for case_id.nii.gz in that folder)" ++ lowres_segmentations = lowres_segmentations[part_id::num_parts] ++ else: ++ lowres_segmentations = None ++ ++ if mode == "normal": # step this ++ if overwrite_all_in_gpu is None: # True ++ all_in_gpu = False ++ else: ++ all_in_gpu = overwrite_all_in_gpu ++ ++ return predict_cases(model, list_of_lists[part_id::num_parts], output_files[part_id::num_parts], folds, ++ save_npz, num_threads_preprocessing, num_threads_nifti_save, lowres_segmentations, tta, ++ mixed_precision=mixed_precision, overwrite_existing=overwrite_existing, all_in_gpu=all_in_gpu, ++ step_size=step_size, checkpoint_name=checkpoint_name, ++ segmentation_export_kwargs=segmentation_export_kwargs, pre_mode=pre_mode, fp=fp) ++ elif mode == "fast": ++ if overwrite_all_in_gpu is None: ++ all_in_gpu = True ++ else: ++ all_in_gpu = overwrite_all_in_gpu ++ ++ assert save_npz is False ++ return predict_cases_fast(model, list_of_lists[part_id::num_parts], output_files[part_id::num_parts], folds, ++ num_threads_preprocessing, num_threads_nifti_save, lowres_segmentations, ++ tta, mixed_precision=mixed_precision, overwrite_existing=overwrite_existing, all_in_gpu=all_in_gpu, ++ step_size=step_size, checkpoint_name=checkpoint_name, ++ segmentation_export_kwargs=segmentation_export_kwargs) ++ elif mode == "fastest": ++ if overwrite_all_in_gpu is None: ++ all_in_gpu = True ++ else: ++ all_in_gpu = overwrite_all_in_gpu ++ ++ assert save_npz is False ++ return predict_cases_fastest(model, list_of_lists[part_id::num_parts], output_files[part_id::num_parts], folds, ++ num_threads_preprocessing, num_threads_nifti_save, lowres_segmentations, ++ tta, mixed_precision=mixed_precision, overwrite_existing=overwrite_existing, all_in_gpu=all_in_gpu, ++ step_size=step_size, checkpoint_name=checkpoint_name) ++ else: ++ raise ValueError("unrecognized mode. Must be normal, fast or fastest") ++ ++ ++if __name__ == "__main__": ++ parser = argparse.ArgumentParser() ++ parser.add_argument("-i", '--input_folder', help="Must contain all modalities for each patient in the correct" ++ " order (same as training). Files must be named " ++ "CASENAME_XXXX.nii.gz where XXXX is the modality " ++ "identifier (0000, 0001, etc)", required=True) ++ parser.add_argument('-o', "--output_folder", required=True, help="folder for saving predictions") ++ parser.add_argument('-m', '--model_output_folder', ++ help='model output folder. Will automatically discover the folds ' ++ 'that were ' ++ 'run and use those as an ensemble', required=True) ++ parser.add_argument('-f', '--folds', nargs='+', default='None', help="folds to use for prediction. Default is None " ++ "which means that folds will be detected " ++ "automatically in the model output folder") ++ parser.add_argument('-z', '--save_npz', required=False, action='store_true', help="use this if you want to ensemble" ++ " these predictions with those of" ++ " other models. Softmax " ++ "probabilities will be saved as " ++ "compresed numpy arrays in " ++ "output_folder and can be merged " ++ "between output_folders with " ++ "merge_predictions.py") ++ parser.add_argument('-l', '--lowres_segmentations', required=False, default='None', help="if model is the highres " ++ "stage of the cascade then you need to use -l to specify where the segmentations of the " ++ "corresponding lowres unet are. Here they are required to do a prediction") ++ parser.add_argument("--part_id", type=int, required=False, default=0, help="Used to parallelize the prediction of " ++ "the folder over several GPUs. If you " ++ "want to use n GPUs to predict this " ++ "folder you need to run this command " ++ "n times with --part_id=0, ... n-1 and " ++ "--num_parts=n (each with a different " ++ "GPU (for example via " ++ "CUDA_VISIBLE_DEVICES=X)") ++ parser.add_argument("--num_parts", type=int, required=False, default=1, ++ help="Used to parallelize the prediction of " ++ "the folder over several GPUs. If you " ++ "want to use n GPUs to predict this " ++ "folder you need to run this command " ++ "n times with --part_id=0, ... n-1 and " ++ "--num_parts=n (each with a different " ++ "GPU (via " ++ "CUDA_VISIBLE_DEVICES=X)") ++ parser.add_argument("--num_threads_preprocessing", required=False, default=6, type=int, help= ++ "Determines many background processes will be used for data preprocessing. Reduce this if you " ++ "run into out of memory (RAM) problems. Default: 6") ++ parser.add_argument("--num_threads_nifti_save", required=False, default=2, type=int, help= ++ "Determines many background processes will be used for segmentation export. Reduce this if you " ++ "run into out of memory (RAM) problems. Default: 2") ++ parser.add_argument("--tta", required=False, type=int, default=1, help="Set to 0 to disable test time data " ++ "augmentation (speedup of factor " ++ "4(2D)/8(3D)), " ++ "lower quality segmentations") ++ parser.add_argument("--overwrite_existing", required=False, type=int, default=1, help="Set this to 0 if you need " ++ "to resume a previous " ++ "prediction. Default: 1 " ++ "(=existing segmentations " ++ "in output_folder will be " ++ "overwritten)") ++ parser.add_argument("--mode", type=str, default="normal", required=False) ++ parser.add_argument("--all_in_gpu", type=str, default="None", required=False, help="can be None, False or True") ++ parser.add_argument("--step_size", type=float, default=0.5, required=False, help="don't touch") ++ # parser.add_argument("--interp_order", required=False, default=3, type=int, ++ # help="order of interpolation for segmentations, has no effect if mode=fastest") ++ # parser.add_argument("--interp_order_z", required=False, default=0, type=int, ++ # help="order of interpolation along z is z is done differently") ++ # parser.add_argument("--force_separate_z", required=False, default="None", type=str, ++ # help="force_separate_z resampling. Can be None, True or False, has no effect if mode=fastest") ++ parser.add_argument('--disable_mixed_precision', default=False, action='store_true', required=False, ++ help='Predictions are done with mixed precision by default. This improves speed and reduces ' ++ 'the required vram. If you want to disable mixed precision you can set this flag. Note ' ++ 'that yhis is not recommended (mixed precision is ~2x faster!)') ++ ++ args = parser.parse_args() ++ input_folder = args.input_folder ++ output_folder = args.output_folder ++ part_id = args.part_id ++ num_parts = args.num_parts ++ model = args.model_output_folder ++ folds = args.folds ++ save_npz = args.save_npz ++ lowres_segmentations = args.lowres_segmentations ++ num_threads_preprocessing = args.num_threads_preprocessing ++ num_threads_nifti_save = args.num_threads_nifti_save ++ tta = args.tta ++ step_size = args.step_size ++ ++ # interp_order = args.interp_order ++ # interp_order_z = args.interp_order_z ++ # force_separate_z = args.force_separate_z ++ ++ # if force_separate_z == "None": ++ # force_separate_z = None ++ # elif force_separate_z == "False": ++ # force_separate_z = False ++ # elif force_separate_z == "True": ++ # force_separate_z = True ++ # else: ++ # raise ValueError("force_separate_z must be None, True or False. Given: %s" % force_separate_z) ++ ++ overwrite = args.overwrite_existing ++ mode = args.mode ++ all_in_gpu = args.all_in_gpu ++ ++ if lowres_segmentations == "None": ++ lowres_segmentations = None ++ ++ if isinstance(folds, list): ++ if folds[0] == 'all' and len(folds) == 1: ++ pass ++ else: ++ folds = [int(i) for i in folds] ++ elif folds == "None": ++ folds = None ++ else: ++ raise ValueError("Unexpected value for argument folds") ++ ++ if tta == 0: ++ tta = False ++ elif tta == 1: ++ tta = True ++ else: ++ raise ValueError("Unexpected value for tta, Use 1 or 0") ++ ++ if overwrite == 0: ++ overwrite = False ++ elif overwrite == 1: ++ overwrite = True ++ else: ++ raise ValueError("Unexpected value for overwrite, Use 1 or 0") ++ ++ assert all_in_gpu in ['None', 'False', 'True'] ++ if all_in_gpu == "None": ++ all_in_gpu = None ++ elif all_in_gpu == "True": ++ all_in_gpu = True ++ elif all_in_gpu == "False": ++ all_in_gpu = False ++ ++ predict_from_folder(model, input_folder, output_folder, folds, save_npz, num_threads_preprocessing, ++ num_threads_nifti_save, lowres_segmentations, part_id, num_parts, tta, mixed_precision=not args.disable_mixed_precision, ++ overwrite_existing=overwrite, mode=mode, overwrite_all_in_gpu=all_in_gpu, step_size=step_size) +diff --git a/pytorch/nnunet/inference/predict_simple2.py b/pytorch/nnunet/inference/predict_simple2.py +new file mode 100644 +index 0000000..2af423e +--- /dev/null ++++ b/pytorch/nnunet/inference/predict_simple2.py +@@ -0,0 +1,238 @@ ++# Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++ ++ ++import argparse ++import torch ++ ++from nnunet.inference.predict2 import predict_from_folder ++from nnunet.paths import default_plans_identifier, network_training_output_dir, default_cascade_trainer, default_trainer ++from batchgenerators.utilities.file_and_folder_operations import join, isdir ++from nnunet.utilities.task_name_id_conversion import convert_id_to_task_name ++from nnunet.inference.infer_path import INFERENCE_INPUT_FOLDER, INFERENCE_OUTPUT_FOLDER ++ ++ ++def main(): ++ parser = argparse.ArgumentParser() ++ parser.add_argument("-i", '--input_folder', help="Must contain all modalities for each patient in the correct" ++ " order (same as training). Files must be named " ++ "CASENAME_XXXX.nii.gz where XXXX is the modality " ++ "identifier (0000, 0001, etc)", required=False, ++ default=INFERENCE_INPUT_FOLDER) ++ parser.add_argument('-o', "--output_folder", required=False, ++ default=INFERENCE_OUTPUT_FOLDER, help="folder for saving predictions") ++ parser.add_argument('-t', '--task_name', help='task name or task ID, required.', ++ default="Task003_Liver", required=False) ++ parser.add_argument('-pm', '--pre_mode', help='predict mode', required=False, default=-1) ++ parser.add_argument('-fp', '--file_path', help='input or output file path for npu bin files', required=True) ++ parser.add_argument('-tr', '--trainer_class_name', ++ help='Name of the nnUNetTrainer used for 2D U-Net, full resolution 3D U-Net and low resolution ' ++ 'U-Net. The default is %s. If you are running inference with the cascade and the folder ' ++ 'pointed to by --lowres_segmentations does not contain the segmentation maps generated by ' ++ 'the low resolution U-Net then the low resolution segmentation maps will be automatically ' ++ 'generated. For this case, make sure to set the trainer class here that matches your ' ++ '--cascade_trainer_class_name (this part can be ignored if defaults are used).' ++ % default_trainer, ++ required=False, ++ default="nnUNetPlusPlusTrainerV2") ++ parser.add_argument('-ctr', '--cascade_trainer_class_name', ++ help="Trainer class name used for predicting the 3D full resolution U-Net part of the cascade." ++ "Default is %s" % default_cascade_trainer, required=False, ++ default=default_cascade_trainer) ++ ++ parser.add_argument('-m', '--model', help="2d, 3d_lowres, 3d_fullres or 3d_cascade_fullres. Default: 3d_fullres", ++ default="3d_fullres", required=False) ++ ++ parser.add_argument('-p', '--plans_identifier', help='do not touch this unless you know what you are doing', ++ default=default_plans_identifier, required=False) ++ ++ parser.add_argument('-f', '--folds', nargs='+', default="None", ++ help="folds to use for prediction. Default is None which means that folds will be detected " ++ "automatically in the model output folder") ++ ++ parser.add_argument('-z', '--save_npz', required=False, action='store_true', ++ help="use this if you want to ensemble these predictions with those of other models. Softmax " ++ "probabilities will be saved as compressed numpy arrays in output_folder and can be " ++ "merged between output_folders with nnUNet_ensemble_predictions") ++ ++ parser.add_argument('-l', '--lowres_segmentations', required=False, default='None', ++ help="if model is the highres stage of the cascade then you can use this folder to provide " ++ "predictions from the low resolution 3D U-Net. If this is left at default, the " ++ "predictions will be generated automatically (provided that the 3D low resolution U-Net " ++ "network weights are present") ++ ++ parser.add_argument("--part_id", type=int, required=False, default=0, help="Used to parallelize the prediction of " ++ "the folder over several GPUs. If you " ++ "want to use n GPUs to predict this " ++ "folder you need to run this command " ++ "n times with --part_id=0, ... n-1 and " ++ "--num_parts=n (each with a different " ++ "GPU (for example via " ++ "CUDA_VISIBLE_DEVICES=X)") ++ ++ parser.add_argument("--num_parts", type=int, required=False, default=1, ++ help="Used to parallelize the prediction of " ++ "the folder over several GPUs. If you " ++ "want to use n GPUs to predict this " ++ "folder you need to run this command " ++ "n times with --part_id=0, ... n-1 and " ++ "--num_parts=n (each with a different " ++ "GPU (via " ++ "CUDA_VISIBLE_DEVICES=X)") ++ ++ parser.add_argument("--num_threads_preprocessing", required=False, default=6, type=int, help= ++ "Determines many background processes will be used for data preprocessing. Reduce this if you " ++ "run into out of memory (RAM) problems. Default: 6") ++ ++ parser.add_argument("--num_threads_nifti_save", required=False, default=2, type=int, help= ++ "Determines many background processes will be used for segmentation export. Reduce this if you " ++ "run into out of memory (RAM) problems. Default: 2") ++ ++ parser.add_argument("--disable_tta", required=False, default=False, action="store_true", ++ help="set this flag to disable test time data augmentation via mirroring. Speeds up inference " ++ "by roughly factor 4 (2D) or 8 (3D)") ++ ++ parser.add_argument("--overwrite_existing", required=False, default=False, action="store_true", ++ help="Set this flag if the target folder contains predictions that you would like to overwrite") ++ ++ parser.add_argument("--mode", type=str, default="normal", required=False, help="Hands off!") ++ parser.add_argument("--all_in_gpu", type=str, default="None", required=False, help="can be None, False or True. " ++ "Do not touch.") ++ parser.add_argument("--step_size", type=float, default=0.5, required=False, help="don't touch") ++ # parser.add_argument("--interp_order", required=False, default=3, type=int, ++ # help="order of interpolation for segmentations, has no effect if mode=fastest. Do not touch this.") ++ # parser.add_argument("--interp_order_z", required=False, default=0, type=int, ++ # help="order of interpolation along z is z is done differently. Do not touch this.") ++ # parser.add_argument("--force_separate_z", required=False, default="None", type=str, ++ # help="force_separate_z resampling. Can be None, True or False, has no effect if mode=fastest. " ++ # "Do not touch this.") ++ parser.add_argument('-chk', ++ help='checkpoint name, default: model_final_checkpoint', ++ required=False, ++ default='model_final_checkpoint') ++ parser.add_argument('--disable_mixed_precision', default=False, action='store_true', required=False, ++ help='Predictions are done with mixed precision by default. This improves speed and reduces ' ++ 'the required vram. If you want to disable mixed precision you can set this flag. Note ' ++ 'that yhis is not recommended (mixed precision is ~2x faster!)') ++ ++ args = parser.parse_args() ++ print(args) ++ ++ input_folder = args.input_folder ++ output_folder = args.output_folder ++ part_id = args.part_id ++ # 推理模式 ++ pre_mode = args.pre_mode ++ fp = args.file_path ++ num_parts = args.num_parts ++ folds = args.folds ++ save_npz = args.save_npz ++ lowres_segmentations = args.lowres_segmentations ++ num_threads_preprocessing = args.num_threads_preprocessing ++ num_threads_nifti_save = args.num_threads_nifti_save ++ disable_tta = args.disable_tta ++ step_size = args.step_size ++ # interp_order = args.interp_order ++ # interp_order_z = args.interp_order_z ++ # force_separate_z = args.force_separate_z ++ overwrite_existing = args.overwrite_existing ++ mode = args.mode ++ all_in_gpu = args.all_in_gpu ++ model = args.model ++ trainer_class_name = args.trainer_class_name ++ cascade_trainer_class_name = args.cascade_trainer_class_name ++ ++ task_name = args.task_name ++ ++ if not task_name.startswith("Task"): ++ task_id = int(task_name) ++ task_name = convert_id_to_task_name(task_id) ++ ++ assert model in ["2d", "3d_lowres", "3d_fullres", "3d_cascade_fullres"], "-m must be 2d, 3d_lowres, 3d_fullres or " \ ++ "3d_cascade_fullres" ++ ++ # if force_separate_z == "None": ++ # force_separate_z = None ++ # elif force_separate_z == "False": ++ # force_separate_z = False ++ # elif force_separate_z == "True": ++ # force_separate_z = True ++ # else: ++ # raise ValueError("force_separate_z must be None, True or False. Given: %s" % force_separate_z) ++ ++ if lowres_segmentations == "None": ++ lowres_segmentations = None ++ ++ if isinstance(folds, list): ++ if folds[0] == 'all' and len(folds) == 1: ++ pass ++ else: ++ folds = [int(i) for i in folds] ++ elif folds == "None": ++ folds = None ++ else: ++ raise ValueError("Unexpected value for argument folds") ++ ++ assert all_in_gpu in ['None', 'False', 'True'] ++ if all_in_gpu == "None": ++ all_in_gpu = None ++ elif all_in_gpu == "True": ++ all_in_gpu = True ++ elif all_in_gpu == "False": ++ all_in_gpu = False ++ ++ # we need to catch the case where model is 3d cascade fullres and the low resolution folder has not been set. ++ # In that case we need to try and predict with 3d low res first ++ if model == "3d_cascade_fullres" and lowres_segmentations is None: ++ print("lowres_segmentations is None. Attempting to predict 3d_lowres first...") ++ assert part_id == 0 and num_parts == 1, "if you don't specify a --lowres_segmentations folder for the " \ ++ "inference of the cascade, custom values for part_id and num_parts " \ ++ "are not supported. If you wish to have multiple parts, please " \ ++ "run the 3d_lowres inference first (separately)" ++ model_folder_name = join(network_training_output_dir, "3d_lowres", task_name, trainer_class_name + "__" + ++ args.plans_identifier) ++ assert isdir(model_folder_name), "model output folder not found. Expected: %s" % model_folder_name ++ lowres_output_folder = join(output_folder, "3d_lowres_predictions") ++ predict_from_folder(model_folder_name, input_folder, lowres_output_folder, folds, False, ++ num_threads_preprocessing, num_threads_nifti_save, None, part_id, num_parts, not disable_tta, ++ overwrite_existing=overwrite_existing, mode=mode, overwrite_all_in_gpu=all_in_gpu, ++ mixed_precision=not args.disable_mixed_precision, ++ step_size=step_size) ++ lowres_segmentations = lowres_output_folder ++ torch.cuda.empty_cache() ++ print("3d_lowres done") ++ ++ if model == "3d_cascade_fullres": ++ trainer = cascade_trainer_class_name ++ else: ++ trainer = trainer_class_name ++ print(network_training_output_dir) ++ print(model) ++ print(task_name) ++ print(trainer) ++ print(args.plans_identifier) ++ model_folder_name = join(network_training_output_dir, model, task_name, trainer + "__" + ++ args.plans_identifier) ++ print("using model stored in ", model_folder_name) ++ assert isdir(model_folder_name), "model output folder not found. Expected: %s" % model_folder_name ++ ++ predict_from_folder(model_folder_name, input_folder, output_folder, folds, save_npz, num_threads_preprocessing, ++ num_threads_nifti_save, lowres_segmentations, part_id, num_parts, not disable_tta, ++ overwrite_existing=overwrite_existing, mode=mode, overwrite_all_in_gpu=all_in_gpu, ++ mixed_precision=not args.disable_mixed_precision, ++ step_size=step_size, checkpoint_name=args.chk, pre_mode=pre_mode, fp=fp) ++ ++ ++if __name__ == "__main__": ++ main() +diff --git a/pytorch/nnunet/inference/read_bin.py b/pytorch/nnunet/inference/read_bin.py +new file mode 100644 +index 0000000..972d940 +--- /dev/null ++++ b/pytorch/nnunet/inference/read_bin.py +@@ -0,0 +1,30 @@ ++import numpy ++import pdb ++import os ++ ++ ++def read_from_bin(file_name, folder_path='/root/heyupeng/result/dumpOutput_device0/'): ++ file = os.path.join(folder_path, file_name) ++ data = numpy.fromfile(file, dtype='float32') ++ data = data.reshape(3, 128, 128, 128) ++ return data ++ ++ ++def main(): ++ file = 'liver_132_0_128_0_128_0_128_1.bin' ++ print('ready to load:', file) ++ data = numpy.fromfile(file, dtype='float32') ++ data = data.reshape(3, 128, 128, 128) ++ pdb.set_trace() ++ print(data.shape) ++ for i in range(5): ++ print(data[0, 0, 0, i*7:(i+1)*7]) ++ print('-----') ++ for i in range(5): ++ print(data[0, 0, 0, i*7+50:(i+1)*7+50]) ++ pdb.set_trace() ++ print('end\n') ++ ++ ++if __name__ == "__main__": ++ main() +\ No newline at end of file +diff --git a/pytorch/nnunet/inference/read_pkl_file.py b/pytorch/nnunet/inference/read_pkl_file.py +new file mode 100644 +index 0000000..5dcc37b +--- /dev/null ++++ b/pytorch/nnunet/inference/read_pkl_file.py +@@ -0,0 +1,22 @@ ++import numpy ++import pdb ++import os ++import pickle ++ ++ ++def read_pkl(file_name, folder_path='/data/yupeng/environment_variables/nnUNet_preprocessed/Task003_Liver/'): ++ file = os.path.join(folder_path, file_name) ++ data = open(file, 'rb') ++ data = pickle.load(data) ++ return data ++ ++ ++def main(): ++ file = 'dataset_properties.pkl' ++ print('ready to load:', file) ++ data = read_pkl(file) ++ print('end\n') ++ ++ ++if __name__ == "__main__": ++ main() +\ No newline at end of file +diff --git a/pytorch/nnunet/inference/read_txt.py b/pytorch/nnunet/inference/read_txt.py +new file mode 100644 +index 0000000..37c94aa +--- /dev/null ++++ b/pytorch/nnunet/inference/read_txt.py +@@ -0,0 +1,29 @@ ++import numpy ++import pdb ++import os ++ ++ ++def read_from_bin(file_name, folder_path='/root/heyupeng/result/dumpOutput_device0/'): ++ file = os.path.join(folder_path, file_name) ++ data = numpy.loadtxt(file) ++ data = data.reshape(3, 128, 128, 128) ++ return data ++ ++ ++def main(): ++ file = 'liver_132_0_128_0_128_0_128_1.txt' ++ print('ready to load:', file) ++ data = numpy.loadtxt(file) ++ data = data.reshape(3, 128, 128, 128) ++ pdb.set_trace() ++ print(data.shape) ++ for i in range(5): ++ print(data[0, 0, 0, i*7:(i+1)*7]) ++ print('-----') ++ for i in range(5): ++ print(data[0, 0, 0, i*7+50:(i+1)*7+50]) ++ pdb.set_trace() ++ print('end\n') ++ ++if __name__ == "__main__": ++ main() +diff --git a/pytorch/nnunet/network_architecture/generic_UNetPlusPlus.py b/pytorch/nnunet/network_architecture/generic_UNetPlusPlus.py +index 5c2f816..5b831ea 100644 +--- a/pytorch/nnunet/network_architecture/generic_UNetPlusPlus.py ++++ b/pytorch/nnunet/network_architecture/generic_UNetPlusPlus.py +@@ -21,7 +21,8 @@ import numpy as np + from nnunet.network_architecture.initialization import InitWeights_He + from nnunet.network_architecture.neural_network import SegmentationNetwork + import torch.nn.functional +- ++import pdb ++# pdb.set_trace() + + class ConvDropoutNormNonlin(nn.Module): + """ +@@ -393,7 +394,7 @@ class Generic_UNetPlusPlus(SegmentationNetwork): + + def forward(self, x): + # skips = [] +- seg_outputs = [] ++ seg_outputs = [] # x是五维的 + x0_0 = self.conv_blocks_context[0](x) + x1_0 = self.conv_blocks_context[1](x0_0) + x0_1 = self.loc4[0](torch.cat([x0_0, self.up4[0](x1_0)], 1)) +@@ -425,7 +426,7 @@ class Generic_UNetPlusPlus(SegmentationNetwork): + x0_5 = self.loc0[4](torch.cat([x0_0, x0_1, x0_2, x0_3, x0_4, self.up0[4](x1_4)], 1)) + seg_outputs.append(self.final_nonlin(self.seg_outputs[-5](x0_5))) + +- if self._deep_supervision and self.do_ds: ++ if self._deep_supervision and self.do_ds: # False + return tuple([seg_outputs[-1]] + [i(j) for i, j in + zip(list(self.upscale_logits_ops)[::-1], seg_outputs[:-1][::-1])]) + else: +diff --git a/pytorch/nnunet/network_architecture/neural_network.py b/pytorch/nnunet/network_architecture/neural_network.py +index baa8a05..9425fe9 100644 +--- a/pytorch/nnunet/network_architecture/neural_network.py ++++ b/pytorch/nnunet/network_architecture/neural_network.py +@@ -21,8 +21,14 @@ from torch import nn + import torch + from scipy.ndimage.filters import gaussian_filter + from typing import Union, Tuple, List ++import os + + from torch.cuda.amp import autocast ++import pdb ++from glob import glob ++import time ++from nnunet.inference.read_bin import read_from_bin ++from nnunet.inference.infer_path import INFERENCE_SHAPE_PATH, INFERENCE_BIN_INPUT_FOLDER, INFERENCE_BIN_OUTPUT_FOLDER + + + class NeuralNetwork(nn.Module): +@@ -75,7 +81,8 @@ class SegmentationNetwork(NeuralNetwork): + step_size: float = 0.5, patch_size: Tuple[int, ...] = None, regions_class_order: Tuple[int, ...] = None, + use_gaussian: bool = False, pad_border_mode: str = "constant", + pad_kwargs: dict = None, all_in_gpu: bool = False, +- verbose: bool = True, mixed_precision: bool = True) -> Tuple[np.ndarray, np.ndarray]: ++ verbose: bool = True, mixed_precision: bool = True, img_name=None, ++ pre_mode=None, fp=None) -> Tuple[np.ndarray, np.ndarray]: + """ + Use this function to predict a 3D image. It does not matter whether the network is a 2D or 3D U-Net, it will + detect that automatically and run the appropriate code. +@@ -133,7 +140,7 @@ class SegmentationNetwork(NeuralNetwork): + + assert len(x.shape) == 4, "data must have shape (c,x,y,z)" + +- if mixed_precision: ++ if mixed_precision: # True + context = autocast + else: + context = no_op +@@ -141,11 +148,11 @@ class SegmentationNetwork(NeuralNetwork): + with context(): + with torch.no_grad(): + if self.conv_op == nn.Conv3d: +- if use_sliding_window: ++ if use_sliding_window: # 走到这里 + res = self._internal_predict_3D_3Dconv_tiled(x, step_size, do_mirroring, mirror_axes, patch_size, + regions_class_order, use_gaussian, pad_border_mode, + pad_kwargs=pad_kwargs, all_in_gpu=all_in_gpu, +- verbose=verbose) ++ verbose=verbose, img_name=img_name, pre_mode=pre_mode, fp=fp) + else: + res = self._internal_predict_3D_3Dconv(x, patch_size, do_mirroring, mirror_axes, regions_class_order, + pad_border_mode, pad_kwargs=pad_kwargs, verbose=verbose) +@@ -284,19 +291,161 @@ class SegmentationNetwork(NeuralNetwork): + + return steps + ++ # def _internal_predict_3D_3Dconv_tiled(self, x: np.ndarray, step_size: float, do_mirroring: bool, mirror_axes: tuple, ++ # patch_size: tuple, regions_class_order: tuple, use_gaussian: bool, ++ # pad_border_mode: str, pad_kwargs: dict, all_in_gpu: bool, ++ # verbose: bool, img_name=None) -> Tuple[np.ndarray, np.ndarray]: ++ # # better safe than sorry ++ # assert len(x.shape) == 4, "x must be (c, x, y, z)" ++ # assert self.get_device() != "cpu" ++ # if verbose: print("step_size:", step_size) # 0.5 ++ # if verbose: print("do mirror:", do_mirroring) # True ++ # ++ # torch.cuda.empty_cache() ++ # ++ # assert patch_size is not None, "patch_size cannot be None for tiled prediction" # 128, 128, 128 ++ # ++ # # for sliding window inference the image must at least be as large as the patch size. It does not matter ++ # # whether the shape is divisible by 2**num_pool as long as the patch size is ++ # data, slicer = pad_nd_image(x, patch_size, pad_border_mode, pad_kwargs, True, None) ++ # data_shape = data.shape # still c, x, y, z + # + # # compute the steps for sliding window + # steps = self._compute_steps_for_sliding_window(patch_size, data_shape[1:], step_size) # 计算窗口 @@ -2277,1371 +2277,1371 @@ index baa8a05..9425fe9 100644 + if all_in_gpu: # False if verbose: print("copying results to CPU") - if regions_class_order is None: -@@ -419,7 +713,7 @@ class SegmentationNetwork(NeuralNetwork): + if regions_class_order is None: +@@ -419,7 +713,7 @@ class SegmentationNetwork(NeuralNetwork): + + class_probabilities = class_probabilities.detach().cpu().numpy() + +- if verbose: print("prediction done") ++ if verbose: print("prediction done") # True + return predicted_segmentation, class_probabilities + + def _internal_predict_2D_2Dconv(self, x: np.ndarray, min_size: Tuple[int, int], do_mirroring: bool, +@@ -504,54 +798,69 @@ class SegmentationNetwork(NeuralNetwork): + assert len(x.shape) == 5, 'x must be (b, c, x, y, z)' + # everything in here takes place on the GPU. If x and mult are not yet on GPU this will be taken care of here + # we now return a cuda tensor! Not numpy array! +- +- x = to_cuda(maybe_to_torch(x), gpu_id=self.get_device()) ++ def print_mytensor(data): ++ shape = data.shape[0] ++ for s in range(shape): ++ for i in range(3): ++ print(data[s, 0, 0, i * 3:(i + 1) * 3]) ++ for i in range(3): ++ print(data[s, 0, 0, i * 3 + 50:(i + 1) * 3 + 50]) ++ print('-----') ++ x = to_cuda(maybe_to_torch(x), gpu_id=self.get_device()) # ndarray, 1 1 128 128 128,之后变成tensor + result_torch = torch.zeros([1, self.num_classes] + list(x.shape[2:]), +- dtype=torch.float).cuda(self.get_device(), non_blocking=True) ++ dtype=torch.float).cuda(self.get_device(), non_blocking=True) # 1 3 128 128 128,全是0 + + if mult is not None: +- mult = to_cuda(maybe_to_torch(mult), gpu_id=self.get_device()) ++ mult = to_cuda(maybe_to_torch(mult), gpu_id=self.get_device()) # tensor, 128 128 128 + +- if do_mirroring: ++ if do_mirroring: # True + mirror_idx = 8 +- num_results = 2 ** len(mirror_axes) ++ num_results = 2 ** len(mirror_axes) # 8 + else: + mirror_idx = 1 + num_results = 1 + for m in range(mirror_idx): + if m == 0: +- pred = self.inference_apply_nonlin(self(x)) +- result_torch += 1 / num_results * pred ++ y = self(x) # tensor, 1 3 128 128 128 ++ pred = self.inference_apply_nonlin(y) # 1 3 128 128 128 ++ result_torch += 1 / num_results * pred # 1 3 128 128 128 + + if m == 1 and (2 in mirror_axes): +- pred = self.inference_apply_nonlin(self(torch.flip(x, (4, )))) ++ y = self(torch.flip(x, (4, ))) ++ pred = self.inference_apply_nonlin(y) + result_torch += 1 / num_results * torch.flip(pred, (4,)) + + if m == 2 and (1 in mirror_axes): +- pred = self.inference_apply_nonlin(self(torch.flip(x, (3, )))) ++ y = self(torch.flip(x, (3, ))) ++ pred = self.inference_apply_nonlin(y) + result_torch += 1 / num_results * torch.flip(pred, (3,)) + + if m == 3 and (2 in mirror_axes) and (1 in mirror_axes): +- pred = self.inference_apply_nonlin(self(torch.flip(x, (4, 3)))) ++ y = self(torch.flip(x, (4, 3))) ++ pred = self.inference_apply_nonlin(y) + result_torch += 1 / num_results * torch.flip(pred, (4, 3)) + + if m == 4 and (0 in mirror_axes): +- pred = self.inference_apply_nonlin(self(torch.flip(x, (2, )))) ++ y = self(torch.flip(x, (2, ))) ++ pred = self.inference_apply_nonlin(y) + result_torch += 1 / num_results * torch.flip(pred, (2,)) + + if m == 5 and (0 in mirror_axes) and (2 in mirror_axes): +- pred = self.inference_apply_nonlin(self(torch.flip(x, (4, 2)))) ++ y = self(torch.flip(x, (4, 2))) ++ pred = self.inference_apply_nonlin(y) + result_torch += 1 / num_results * torch.flip(pred, (4, 2)) + + if m == 6 and (0 in mirror_axes) and (1 in mirror_axes): +- pred = self.inference_apply_nonlin(self(torch.flip(x, (3, 2)))) ++ y = self(torch.flip(x, (3, 2))) ++ pred = self.inference_apply_nonlin(y) + result_torch += 1 / num_results * torch.flip(pred, (3, 2)) + + if m == 7 and (0 in mirror_axes) and (1 in mirror_axes) and (2 in mirror_axes): +- pred = self.inference_apply_nonlin(self(torch.flip(x, (4, 3, 2)))) ++ y = self(torch.flip(x, (4, 3, 2))) ++ pred = self.inference_apply_nonlin(y) + result_torch += 1 / num_results * torch.flip(pred, (4, 3, 2)) + +- if mult is not None: ++ if mult is not None: # True + result_torch[:, :] *= mult + + return result_torch +diff --git a/pytorch/nnunet/postprocessing/connected_components.py b/pytorch/nnunet/postprocessing/connected_components.py +index c69471e..45ff991 100644 +--- a/pytorch/nnunet/postprocessing/connected_components.py ++++ b/pytorch/nnunet/postprocessing/connected_components.py +@@ -175,7 +175,7 @@ def determine_postprocessing(base, gt_labels_folder, raw_subfolder_name="validat + pp_results['num_samples'] = len(validation_result_raw['all']) + validation_result_raw = validation_result_raw['mean'] + +- if advanced_postprocessing: ++ if advanced_postprocessing: # False + # first treat all foreground classes as one and remove all but the largest foreground connected component + results = [] + for f in fnames: +@@ -270,12 +270,12 @@ def determine_postprocessing(base, gt_labels_folder, raw_subfolder_name="validat + if len(classes) > 1: + # now depending on whether we do remove all but the largest foreground connected component we define the source dir + # for the next one to be the raw or the temp dir +- if do_fg_cc: ++ if do_fg_cc: # True + source = folder_all_classes_as_fg + else: + source = join(base, raw_subfolder_name) + +- if advanced_postprocessing: ++ if advanced_postprocessing: # False + # now run this for each class separately + results = [] + for f in fnames: +@@ -325,7 +325,7 @@ def determine_postprocessing(base, gt_labels_folder, raw_subfolder_name="validat + json_output_file=join(folder_per_class, "summary.json"), + json_author="Fabian", num_threads=processes) + +- if do_fg_cc: ++ if do_fg_cc: # True + old_res = deepcopy(validation_result_PP_test) + else: + old_res = validation_result_raw +@@ -350,7 +350,7 @@ def determine_postprocessing(base, gt_labels_folder, raw_subfolder_name="validat + else: + print("Only one class present, no need to do each class separately as this is covered in fg vs bg") + +- if not advanced_postprocessing: ++ if not advanced_postprocessing: # True + pp_results['min_valid_object_sizes'] = None + + print("done") +diff --git a/pytorch/nnunet/preprocessing/cropping.py b/pytorch/nnunet/preprocessing/cropping.py +index bb0a92a..95d07bc 100644 +--- a/pytorch/nnunet/preprocessing/cropping.py ++++ b/pytorch/nnunet/preprocessing/cropping.py +@@ -39,6 +39,7 @@ def get_bbox_from_mask(mask, outside_value=0): + maxxidx = int(np.max(mask_voxel_coords[1])) + 1 + minyidx = int(np.min(mask_voxel_coords[2])) + maxyidx = int(np.max(mask_voxel_coords[2])) + 1 ++ print(mask.shape, minzidx, maxzidx, minxidx, maxxidx, minyidx, maxyidx) + return [[minzidx, maxzidx], [minxidx, maxxidx], [minyidx, maxyidx]] + + +@@ -202,6 +203,7 @@ class ImageCropper(object): + list_of_args.append((case, case_identifier, overwrite_existing)) + + p = Pool(self.num_threads) ++ print('Pool', self.num_threads) + p.starmap(self.load_crop_save, list_of_args) + p.close() + p.join() +diff --git a/pytorch/nnunet/run/look_pkl.py b/pytorch/nnunet/run/look_pkl.py +new file mode 100644 +index 0000000..1a9d78a +--- /dev/null ++++ b/pytorch/nnunet/run/look_pkl.py +@@ -0,0 +1,18 @@ ++import numpy as np ++import pickle ++ ++inputfile = u'/data/yupeng/environment_variables/RESULTS_FOLDER/nnUNet/3d_fullres/Task003_Liver' \ ++ u'/nnUNetPlusPlusTrainerV2__nnUNetPlansv2.1/fold_0/model_final_checkpoint.model.pkl' ++# test = np.load('labels.npy', encoding = "latin1") ++# doc = open('1.txt', 'a') ++# print(test, file=doc) ++ ++ ++ ++fr = open(inputfile, 'rb') ++inf = pickle.load(fr) ++print('done') ++ ++ ++ ++print('end') +\ No newline at end of file +diff --git a/pytorch/nnunet/run/model_prof.py b/pytorch/nnunet/run/model_prof.py +new file mode 100644 +index 0000000..013df26 +--- /dev/null ++++ b/pytorch/nnunet/run/model_prof.py +@@ -0,0 +1,124 @@ ++# Copyright (c) Soumith Chintala 2016, ++# All rights reserved ++# ++# Copyright 2020 Huawei Technologies Co., Ltd ++# ++# Licensed under the BSD 3-Clause License (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# https://spdx.org/licenses/BSD-3-Clause.html ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++ ++# -*- coding: utf-8 -*- ++"""pytorch_prof.py ++""" ++ ++import torch ++import torch.optim as optim ++import torch.nn as nn ++import time ++import argparse ++ ++ ++def build_model(): ++ # 请自定义模型并加载预训练模型 ++ import torchvision ++ model = torchvision.models.resnet50(pretrained=True) ++ return model ++ ++ ++def get_raw_data(): ++ input_tensor = torch.randn(2, 3, 224, 224) ++ return input_tensor ++ ++ ++def criterion(x): ++ base_func = nn.CrossEntropyLoss() ++ shape_list = x.shape ++ N = shape_list[0] ++ R = 1 ++ if len(shape_list) > 1: ++ for r in shape_list[1:]: ++ R *= r ++ T = torch.randint(0,R, size=(N,)).to(x.device) ++ if str(T.device).startswith('npu'): ++ T = T.int() ++ return base_func(x.reshape(N, -1), T) ++ ++ ++if __name__ == '__main__': ++ parser = argparse.ArgumentParser(description='PyTorch Prof') ++ parser.add_argument('--device', type=str, default='cpu', ++ help='set which type of device used. Support cuda:0(device_id), npu:0(device_id).') ++ parser.add_argument('--amp', default=False, action='store_true', ++ help='use amp during prof') ++ parser.add_argument('--loss-scale', default=64.0, type=float, ++ help='loss scale using in amp, default 64.0, -1 means dynamic') ++ parser.add_argument('--opt-level', default='O2', type=str, ++ help='opt-level using in amp, default O2') ++ parser.add_argument('--FusedSGD', default=False, action='store_true', ++ help='use FusedSGD during prof') ++ ++ args = parser.parse_args() ++ ++ # 1.准备工作 ++ if args.device.startswith('cuda'): ++ torch.cuda.set_device(args.device) ++ prof_kwargs = {'use_cuda': True} ++ elif args.device.startswith('npu'): ++ torch.npu.set_device(args.device) ++ prof_kwargs = {'use_npu': True} ++ else: ++ prof_kwargs = {} ++ ++ # 2.构建模型 ++ model = build_model() ++ if args.FusedSGD: ++ from apex.optimizers import NpuFusedSGD ++ optimizer = NpuFusedSGD(model.parameters(), lr=0.01) ++ model = model.to(args.device) ++ if args.amp: ++ from apex import amp ++ model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, ++ loss_scale=None if args.loss_scale == -1 else args.loss_scale, ++ combine_grad=True) ++ else: ++ optimizer = optim.SGD(model.parameters(), lr=0.01) ++ model = model.to(args.device) ++ if args.amp: ++ from apex import amp ++ model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, ++ loss_scale=None if args.loss_scale == -1 else args.loss_scale) ++ ++ # 3.生成input ++ input_tensor = get_raw_data() ++ input_tensor = input_tensor.to(args.device) ++ ++ # 先运行一次,保证prof得到的性能是正确的 ++ def run(): ++ output_tensor = model(input_tensor) ++ optimizer.zero_grad() ++ loss = criterion(output_tensor) ++ if args.amp: ++ with amp.scale_loss(loss, optimizer) as scaled_loss: ++ scaled_loss.backward() ++ else: ++ loss.backward() ++ optimizer.step() ++ return loss ++ for i in range(5): ++ start_time = time.time() ++ loss = run() ++ print('iter: %d, loss: %.2f, time: %.2f' % (i, loss, (time.time() - start_time)*1000)) ++ ++ # 4. 执行forward+profiling ++ with torch.autograd.profiler.profile(**prof_kwargs) as prof: ++ run() ++ print(prof.key_averages().table()) ++ prof.export_chrome_trace("pytorch_prof_%s.prof" % args.device) +\ No newline at end of file +diff --git a/pytorch/nnunet/run/run_training.py b/pytorch/nnunet/run/run_training.py +index eb7ca2f..08214d6 100644 +--- a/pytorch/nnunet/run/run_training.py ++++ b/pytorch/nnunet/run/run_training.py +@@ -31,7 +31,7 @@ def main(): + parser.add_argument("task", help="can be task name or task id") + parser.add_argument("fold", help='0, 1, ..., 5 or \'all\'') + parser.add_argument("-val", "--validation_only", help="use this if you want to only run the validation", +- action="store_true") ++ action="store_true", default=True) + parser.add_argument("-w", required=False, default=None, help="Load pre-trained Models Genesis") + parser.add_argument("-c", "--continue_training", help="use this if you want to continue a training", + action="store_true") +@@ -134,8 +134,8 @@ def main(): + fp16=run_mixed_precision) + + trainer.initialize(not validation_only) +- +- if weights != None: ++ ++ if weights != None: + trainer.load_pretrained_encoder_weights(weights) + sys.stdout.flush() - class_probabilities = class_probabilities.detach().cpu().numpy() +diff --git a/pytorch/nnunet/run/run_training2.py b/pytorch/nnunet/run/run_training2.py +new file mode 100644 +index 0000000..372a4d4 +--- /dev/null ++++ b/pytorch/nnunet/run/run_training2.py +@@ -0,0 +1,172 @@ ++# Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++import os ++import sys ++import argparse ++from batchgenerators.utilities.file_and_folder_operations import * ++from nnunet.run.default_configuration import get_default_configuration ++from nnunet.paths import default_plans_identifier ++from nnunet.training.cascade_stuff.predict_next_stage import predict_next_stage ++from nnunet.training.network_training.nnUNetTrainer import nnUNetTrainer ++from nnunet.training.network_training.nnUNetTrainerCascadeFullRes import nnUNetTrainerCascadeFullRes ++from nnunet.training.network_training.nnUNetTrainerV2_CascadeFullRes import nnUNetTrainerV2CascadeFullRes ++from nnunet.utilities.task_name_id_conversion import convert_id_to_task_name ++ ++ ++# import pdb ++# pdb.set_trace() ++ ++def main(): ++ parser = argparse.ArgumentParser() ++ parser.add_argument("-network", default="3d_fullres") ++ parser.add_argument("-network_trainer", default="nnUNetPlusPlusTrainerV2") ++ parser.add_argument("-task", default="003", help="can be task name or task id") ++ parser.add_argument("-fold", default="0", help='0, 1, ..., 5 or \'all\'') ++ parser.add_argument("-val", "--validation_only", default=False, ++ help="use this if you want to only run the validation", ++ action="store_true") ++ parser.add_argument("-w", required=False, default=None, help="Load pre-trained Models Genesis") ++ parser.add_argument("-c", "--continue_training", default=False, help="use this if you want to continue a training", ++ action="store_true") ++ parser.add_argument("-p", help="plans identifier. Only change this if you created a custom experiment planner", ++ default=default_plans_identifier, required=False) ++ parser.add_argument("--use_compressed_data", default=False, action="store_true", ++ help="If you set use_compressed_data, the training cases will not be decompressed. Reading compressed data " ++ "is much more CPU and RAM intensive and should only be used if you know what you are " ++ "doing", required=False) ++ parser.add_argument("--deterministic", ++ help="Makes training deterministic, but reduces training speed substantially. I (Fabian) think " ++ "this is not necessary. Deterministic training will make you overfit to some random seed. " ++ "Don't use that.", ++ required=False, default=False, action="store_true") ++ parser.add_argument("--npz", required=False, default=False, action="store_true", help="if set then nnUNet will " ++ "export npz files of " ++ "predicted segmentations " ++ "in the validation as well. " ++ "This is needed to run the " ++ "ensembling step so unless " ++ "you are developing nnUNet " ++ "you should enable this") ++ parser.add_argument("--find_lr", required=False, default=False, action="store_true", ++ help="not used here, just for fun") ++ parser.add_argument("--valbest", required=False, default=False, action="store_true", ++ help="hands off. This is not intended to be used") ++ parser.add_argument("--fp32", required=False, default=False, action="store_true", ++ help="disable mixed precision training and run old school fp32") ++ parser.add_argument("--val_folder", required=False, default="validation_raw", ++ help="name of the validation folder. No need to use this for most people") ++ # parser.add_argument("--interp_order", required=False, default=3, type=int, ++ # help="order of interpolation for segmentations. Testing purpose only. Hands off") ++ # parser.add_argument("--interp_order_z", required=False, default=0, type=int, ++ # help="order of interpolation along z if z is resampled separately. Testing purpose only. " ++ # "Hands off") ++ # parser.add_argument("--force_separate_z", required=False, default="None", type=str, ++ # help="force_separate_z resampling. Can be None, True or False. Testing purpose only. Hands off") ++ ++ args = parser.parse_args() ++ print('------------\n', args) ++ ++ task = args.task ++ fold = args.fold ++ network = args.network ++ network_trainer = args.network_trainer ++ weights = args.w ++ validation_only = args.validation_only ++ plans_identifier = args.p ++ find_lr = args.find_lr ++ ++ use_compressed_data = args.use_compressed_data ++ decompress_data = not use_compressed_data ++ ++ deterministic = args.deterministic ++ valbest = args.valbest ++ ++ fp32 = args.fp32 ++ run_mixed_precision = not fp32 ++ ++ val_folder = args.val_folder ++ # interp_order = args.interp_order ++ # interp_order_z = args.interp_order_z ++ # force_separate_z = args.force_separate_z ++ ++ if not task.startswith("Task"): ++ task_id = int(task) ++ task = convert_id_to_task_name(task_id) ++ ++ if fold == 'all': ++ pass ++ else: ++ fold = int(fold) ++ ++ # if force_separate_z == "None": ++ # force_separate_z = None ++ # elif force_separate_z == "False": ++ # force_separate_z = False ++ # elif force_separate_z == "True": ++ # force_separate_z = True ++ # else: ++ # raise ValueError("force_separate_z must be None, True or False. Given: %s" % force_separate_z) ++ ++ plans_file, output_folder_name, dataset_directory, batch_dice, stage, \ ++ trainer_class, domain = get_default_configuration(network, task, network_trainer, plans_identifier) ++ ++ if trainer_class is None: ++ raise RuntimeError("Could not find trainer class in nnunet.training.network_training") ++ ++ if network == "3d_cascade_fullres": ++ assert issubclass(trainer_class, (nnUNetTrainerCascadeFullRes, nnUNetTrainerV2CascadeFullRes)), \ ++ "If running 3d_cascade_fullres then your " \ ++ "trainer class must be derived from " \ ++ "nnUNetTrainerCascadeFullRes" ++ else: ++ assert issubclass(trainer_class, ++ nnUNetTrainer), "network_trainer was found but is not derived from nnUNetTrainer" ++ ++ trainer = trainer_class(plans_file, fold, output_folder=output_folder_name, dataset_directory=dataset_directory, ++ batch_dice=batch_dice, stage=stage, unpack_data=decompress_data, ++ deterministic=deterministic, ++ fp16=run_mixed_precision) ++ ++ trainer.initialize(not validation_only) ++ ++ if weights != None: ++ trainer.load_pretrained_encoder_weights(weights) ++ sys.stdout.flush() ++ ++ if find_lr: ++ trainer.find_lr() ++ else: ++ if not validation_only: ++ if args.continue_training: ++ trainer.load_latest_checkpoint() ++ trainer.run_training() ++ else: ++ if valbest: ++ trainer.load_best_checkpoint(train=False) ++ else: ++ trainer.load_latest_checkpoint(train=False) ++ ++ trainer.network.eval() ++ ++ # predict validation ++ trainer.validate(save_softmax=args.npz, validation_folder_name=val_folder) ++ ++ if network == '3d_lowres': ++ trainer.load_best_checkpoint(False) ++ print("predicting segmentations for the next stage of the cascade") ++ predict_next_stage(trainer, join(dataset_directory, trainer.plans['data_identifier'] + "_stage%d" % 1)) ++ ++ ++if __name__ == "__main__": ++ main() +diff --git a/pytorch/nnunet/run/run_training_DDP.py b/pytorch/nnunet/run/run_training_DDP.py +index 5ffcdcf..6ad3d5a 100644 +--- a/pytorch/nnunet/run/run_training_DDP.py ++++ b/pytorch/nnunet/run/run_training_DDP.py +@@ -27,13 +27,13 @@ from nnunet.utilities.task_name_id_conversion import convert_id_to_task_name -- if verbose: print("prediction done") -+ if verbose: print("prediction done") # True - return predicted_segmentation, class_probabilities + def main(): + parser = argparse.ArgumentParser() +- parser.add_argument("network") +- parser.add_argument("network_trainer") +- parser.add_argument("task", help="can be task name or task id") +- parser.add_argument("fold", help='0, 1, ..., 5 or \'all\'') ++ parser.add_argument("network", default='3d_fullres') ++ parser.add_argument("network_trainer", default='nnUNetTrainerV2_DDP') ++ parser.add_argument("task", help="can be task name or task id", default='003') ++ parser.add_argument("fold", help='0, 1, ..., 5 or \'all\'', default='0') + parser.add_argument("-val", "--validation_only", help="use this if you want to only run the validation", +- action="store_true") +- parser.add_argument("-c", "--continue_training", help="use this if you want to continue a training", ++ action="store_true", default=False) ++ parser.add_argument("-c", "--continue_training", default=False, help="use this if you want to continue a training", + action="store_true") + parser.add_argument("-p", help="plans identifier. Only change this if you created a custom experiment planner", + default=default_plans_identifier, required=False) +@@ -78,7 +78,7 @@ def main(): + # help="force_separate_z resampling. Can be None, True or False. Testing purpose only. Hands off") - def _internal_predict_2D_2Dconv(self, x: np.ndarray, min_size: Tuple[int, int], do_mirroring: bool, -@@ -504,54 +798,69 @@ class SegmentationNetwork(NeuralNetwork): - assert len(x.shape) == 5, 'x must be (b, c, x, y, z)' - # everything in here takes place on the GPU. If x and mult are not yet on GPU this will be taken care of here - # we now return a cuda tensor! Not numpy array! + args = parser.parse_args() - -- x = to_cuda(maybe_to_torch(x), gpu_id=self.get_device()) -+ def print_mytensor(data): -+ shape = data.shape[0] -+ for s in range(shape): -+ for i in range(3): -+ print(data[s, 0, 0, i * 3:(i + 1) * 3]) -+ for i in range(3): -+ print(data[s, 0, 0, i * 3 + 50:(i + 1) * 3 + 50]) -+ print('-----') -+ x = to_cuda(maybe_to_torch(x), gpu_id=self.get_device()) # ndarray, 1 1 128 128 128,之后变成tensor - result_torch = torch.zeros([1, self.num_classes] + list(x.shape[2:]), -- dtype=torch.float).cuda(self.get_device(), non_blocking=True) -+ dtype=torch.float).cuda(self.get_device(), non_blocking=True) # 1 3 128 128 128,全是0 - - if mult is not None: -- mult = to_cuda(maybe_to_torch(mult), gpu_id=self.get_device()) -+ mult = to_cuda(maybe_to_torch(mult), gpu_id=self.get_device()) # tensor, 128 128 128 ++ print('\n\n args=', args, '\n\n') + task = args.task + fold = args.fold + network = args.network +@@ -115,7 +115,7 @@ def main(): + # raise ValueError("force_separate_z must be None, True or False. Given: %s" % force_separate_z) -- if do_mirroring: -+ if do_mirroring: # True - mirror_idx = 8 -- num_results = 2 ** len(mirror_axes) -+ num_results = 2 ** len(mirror_axes) # 8 - else: - mirror_idx = 1 - num_results = 1 - for m in range(mirror_idx): - if m == 0: -- pred = self.inference_apply_nonlin(self(x)) -- result_torch += 1 / num_results * pred -+ y = self(x) # tensor, 1 3 128 128 128 -+ pred = self.inference_apply_nonlin(y) # 1 3 128 128 128 -+ result_torch += 1 / num_results * pred # 1 3 128 128 128 + plans_file, output_folder_name, dataset_directory, batch_dice, stage, \ +- trainer_class = get_default_configuration(network, task, network_trainer, plans_identifier) ++ trainer_class, _ = get_default_configuration(network, task, network_trainer, plans_identifier) - if m == 1 and (2 in mirror_axes): -- pred = self.inference_apply_nonlin(self(torch.flip(x, (4, )))) -+ y = self(torch.flip(x, (4, ))) -+ pred = self.inference_apply_nonlin(y) - result_torch += 1 / num_results * torch.flip(pred, (4,)) + if trainer_class is None: + raise RuntimeError("Could not find trainer class in meddec.model_training") +diff --git a/pytorch/nnunet/run/run_training_hypDDP.py b/pytorch/nnunet/run/run_training_hypDDP.py +new file mode 100644 +index 0000000..f50744c +--- /dev/null ++++ b/pytorch/nnunet/run/run_training_hypDDP.py +@@ -0,0 +1,164 @@ ++# Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++ ++ ++import argparse ++ ++from batchgenerators.utilities.file_and_folder_operations import * ++from nnunet.run.default_configuration import get_default_configuration ++from nnunet.paths import default_plans_identifier ++from nnunet.training.cascade_stuff.predict_next_stage import predict_next_stage ++from nnunet.training.network_training.nnUNetTrainer import nnUNetTrainer ++from nnunet.training.network_training.nnUNetTrainerCascadeFullRes import nnUNetTrainerCascadeFullRes ++from nnunet.training.network_training.nnUNetTrainerV2_CascadeFullRes import nnUNetTrainerV2CascadeFullRes ++from nnunet.utilities.task_name_id_conversion import convert_id_to_task_name ++ ++ ++def main(): ++ parser = argparse.ArgumentParser() ++ parser.add_argument("network") ++ parser.add_argument("network_trainer") ++ parser.add_argument("task", help="can be task name or task id") ++ parser.add_argument("fold", help='0, 1, ..., 5 or \'all\'') ++ parser.add_argument("-val", "--validation_only", help="use this if you want to only run the validation", ++ action="store_true") ++ parser.add_argument("-c", "--continue_training", help="use this if you want to continue a training", ++ action="store_true") ++ parser.add_argument("-p", help="plans identifier. Only change this if you created a custom experiment planner", ++ default=default_plans_identifier, required=False) ++ parser.add_argument("--use_compressed_data", default=False, action="store_true", ++ help="If you set use_compressed_data, the training cases will not be decompressed. Reading compressed data " ++ "is much more CPU and RAM intensive and should only be used if you know what you are " ++ "doing", required=False) ++ parser.add_argument("--deterministic", ++ help="Makes training deterministic, but reduces training speed substantially. I (Fabian) think " ++ "this is not necessary. Deterministic training will make you overfit to some random seed. " ++ "Don't use that.", ++ required=False, default=False, action="store_true") ++ parser.add_argument("--local_rank", default=0, type=int) ++ parser.add_argument("--fp32", required=False, default=False, action="store_true", ++ help="disable mixed precision training and run old school fp32") ++ parser.add_argument("--dbs", required=False, default=False, action="store_true", help="distribute batch size. If " ++ "True then whatever " ++ "batch_size is in plans will " ++ "be distributed over DDP " ++ "models, if False then each " ++ "model will have batch_size " ++ "for a total of " ++ "GPUs*batch_size") ++ parser.add_argument("--npz", required=False, default=False, action="store_true", help="if set then nnUNet will " ++ "export npz files of " ++ "predicted segmentations " ++ "in the vlaidation as well. " ++ "This is needed to run the " ++ "ensembling step so unless " ++ "you are developing nnUNet " ++ "you should enable this") ++ parser.add_argument("--valbest", required=False, default=False, action="store_true", help="") ++ parser.add_argument("--find_lr", required=False, default=False, action="store_true", help="") ++ parser.add_argument("--val_folder", required=False, default="validation_raw", ++ help="name of the validation folder. No need to use this for most people") ++ # parser.add_argument("--interp_order", required=False, default=3, type=int, ++ # help="order of interpolation for segmentations. Testing purpose only. Hands off") ++ # parser.add_argument("--interp_order_z", required=False, default=0, type=int, ++ # help="order of interpolation along z if z is resampled separately. Testing purpose only. " ++ # "Hands off") ++ # parser.add_argument("--force_separate_z", required=False, default="None", type=str, ++ # help="force_separate_z resampling. Can be None, True or False. Testing purpose only. Hands off") ++ ++ args = parser.parse_args() ++ print('\n\n args=', args, '\n\n') ++ task = args.task ++ fold = args.fold ++ network = args.network ++ network_trainer = args.network_trainer ++ validation_only = args.validation_only ++ plans_identifier = args.p ++ use_compressed_data = args.use_compressed_data ++ decompress_data = not use_compressed_data ++ deterministic = args.deterministic ++ valbest = args.valbest ++ find_lr = args.find_lr ++ val_folder = args.val_folder ++ # interp_order = args.interp_order ++ # interp_order_z = args.interp_order_z ++ # force_separate_z = args.force_separate_z ++ fp32 = args.fp32 ++ ++ if not task.startswith("Task"): ++ task_id = int(task) ++ task = convert_id_to_task_name(task_id) ++ ++ if fold == 'all': ++ pass ++ else: ++ fold = int(fold) ++ # ++ # if force_separate_z == "None": ++ # force_separate_z = None ++ # elif force_separate_z == "False": ++ # force_separate_z = False ++ # elif force_separate_z == "True": ++ # force_separate_z = True ++ # else: ++ # raise ValueError("force_separate_z must be None, True or False. Given: %s" % force_separate_z) ++ ++ plans_file, output_folder_name, dataset_directory, batch_dice, stage, \ ++ trainer_class, _ = get_default_configuration(network, task, network_trainer, plans_identifier) ++ ++ if trainer_class is None: ++ raise RuntimeError("Could not find trainer class in meddec.model_training") ++ ++ if network == "3d_cascade_fullres": ++ assert issubclass(trainer_class, (nnUNetTrainerCascadeFullRes, nnUNetTrainerV2CascadeFullRes)), \ ++ "If running 3d_cascade_fullres then your " \ ++ "trainer class must be derived from " \ ++ "nnUNetTrainerCascadeFullRes" ++ else: ++ assert issubclass(trainer_class, ++ nnUNetTrainer), "network_trainer was found but is not derived from nnUNetTrainer" ++ ++ trainer = trainer_class(plans_file, fold, local_rank=args.local_rank, output_folder=output_folder_name, ++ dataset_directory=dataset_directory, batch_dice=batch_dice, stage=stage, ++ unpack_data=decompress_data, deterministic=deterministic, fp16=not fp32, ++ distribute_batch_size=args.dbs) ++ ++ trainer.initialize(not validation_only) ++ ++ if find_lr: ++ trainer.find_lr() ++ else: ++ if not validation_only: ++ if args.continue_training: ++ trainer.load_latest_checkpoint() ++ trainer.run_training() ++ else: ++ if valbest: ++ trainer.load_best_checkpoint(train=False) ++ else: ++ trainer.load_latest_checkpoint(train=False) ++ ++ trainer.network.eval() ++ ++ # predict validation ++ trainer.validate(save_softmax=args.npz, validation_folder_name=val_folder) ++ ++ if network == '3d_lowres': ++ trainer.load_best_checkpoint(False) ++ print("predicting segmentations for the next stage of the cascade") ++ predict_next_stage(trainer, join(dataset_directory, trainer.plans['data_identifier'] + "_stage%d" % 1)) ++ ++ ++if __name__ == "__main__": ++ main() +diff --git a/pytorch/nnunet/training/loss_functions/crossentropy.py b/pytorch/nnunet/training/loss_functions/crossentropy.py +index 6195437..0c782d9 100644 +--- a/pytorch/nnunet/training/loss_functions/crossentropy.py ++++ b/pytorch/nnunet/training/loss_functions/crossentropy.py +@@ -6,6 +6,15 @@ class RobustCrossEntropyLoss(nn.CrossEntropyLoss): + this is just a compatibility layer because my target tensor is float and has an extra dimension + """ + def forward(self, input: Tensor, target: Tensor) -> Tensor: ++ # i = 0 ++ # print('----------') ++ # print('input:', input.shape) ++ # for i in range(len(input)): ++ # print(i, input[i].shape) ++ # print('target') ++ # for i in range(len(target)): ++ # print(i, target[i].shape) ++ # print('\n----------') + if len(target.shape) == len(input.shape): + assert target.shape[1] == 1 + target = target[:, 0] +diff --git a/pytorch/nnunet/training/network_training/network_trainer.py b/pytorch/nnunet/training/network_training/network_trainer.py +index e920158..f0031d3 100644 +--- a/pytorch/nnunet/training/network_training/network_trainer.py ++++ b/pytorch/nnunet/training/network_training/network_trainer.py +@@ -37,6 +37,7 @@ from abc import abstractmethod + from datetime import datetime + from tqdm import trange + from nnunet.utilities.to_torch import maybe_to_torch, to_cuda ++import pdb - if m == 2 and (1 in mirror_axes): -- pred = self.inference_apply_nonlin(self(torch.flip(x, (3, )))) -+ y = self(torch.flip(x, (3, ))) -+ pred = self.inference_apply_nonlin(y) - result_torch += 1 / num_results * torch.flip(pred, (3,)) - if m == 3 and (2 in mirror_axes) and (1 in mirror_axes): -- pred = self.inference_apply_nonlin(self(torch.flip(x, (4, 3)))) -+ y = self(torch.flip(x, (4, 3))) -+ pred = self.inference_apply_nonlin(y) - result_torch += 1 / num_results * torch.flip(pred, (4, 3)) + class NetworkTrainer(object): +@@ -438,7 +439,8 @@ class NetworkTrainer(object): + self._maybe_init_amp() - if m == 4 and (0 in mirror_axes): -- pred = self.inference_apply_nonlin(self(torch.flip(x, (2, )))) -+ y = self(torch.flip(x, (2, ))) -+ pred = self.inference_apply_nonlin(y) - result_torch += 1 / num_results * torch.flip(pred, (2,)) + def _maybe_init_amp(self): +- if self.fp16 and self.amp_grad_scaler is None and torch.cuda.is_available(): ++ # if self.fp16 and self.amp_grad_scaler is None and torch.cuda.is_available(): ++ if self.fp16 and self.amp_grad_scaler is None: + self.amp_grad_scaler = GradScaler() - if m == 5 and (0 in mirror_axes) and (2 in mirror_axes): -- pred = self.inference_apply_nonlin(self(torch.flip(x, (4, 2)))) -+ y = self(torch.flip(x, (4, 2))) -+ pred = self.inference_apply_nonlin(y) - result_torch += 1 / num_results * torch.flip(pred, (4, 2)) + def plot_network_architecture(self): +diff --git a/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2.py b/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2.py +index e9aa611..9b97e8c 100644 +--- a/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2.py ++++ b/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2.py +@@ -13,6 +13,7 @@ + # limitations under the License. - if m == 6 and (0 in mirror_axes) and (1 in mirror_axes): -- pred = self.inference_apply_nonlin(self(torch.flip(x, (3, 2)))) -+ y = self(torch.flip(x, (3, 2))) -+ pred = self.inference_apply_nonlin(y) - result_torch += 1 / num_results * torch.flip(pred, (3, 2)) - if m == 7 and (0 in mirror_axes) and (1 in mirror_axes) and (2 in mirror_axes): -- pred = self.inference_apply_nonlin(self(torch.flip(x, (4, 3, 2)))) -+ y = self(torch.flip(x, (4, 3, 2))) -+ pred = self.inference_apply_nonlin(y) - result_torch += 1 / num_results * torch.flip(pred, (4, 3, 2)) ++import SimpleITK as sitk + from collections import OrderedDict + from typing import Tuple + import sys +@@ -35,12 +36,10 @@ from torch.cuda.amp import autocast + from nnunet.training.learning_rate.poly_lr import poly_lr + from batchgenerators.utilities.file_and_folder_operations import * -- if mult is not None: -+ if mult is not None: # True - result_torch[:, :] *= mult +- + class nnUNetPlusPlusTrainerV2(nnUNetTrainer): + """ + Info for Fabian: same as internal nnUNetTrainerV2_2 + """ +- + def __init__(self, plans_file, fold, output_folder=None, dataset_directory=None, batch_dice=True, stage=None, + unpack_data=True, deterministic=True, fp16=False): + super().__init__(plans_file, fold, output_folder, dataset_directory, batch_dice, stage, unpack_data, +@@ -66,7 +65,7 @@ class nnUNetPlusPlusTrainerV2(nnUNetTrainer): + maybe_mkdir_p(self.output_folder) - return result_torch -diff --git a/pytorch/nnunet/postprocessing/connected_components.py b/pytorch/nnunet/postprocessing/connected_components.py -index c69471e..45ff991 100644 ---- a/pytorch/nnunet/postprocessing/connected_components.py -+++ b/pytorch/nnunet/postprocessing/connected_components.py -@@ -175,7 +175,7 @@ def determine_postprocessing(base, gt_labels_folder, raw_subfolder_name="validat - pp_results['num_samples'] = len(validation_result_raw['all']) - validation_result_raw = validation_result_raw['mean'] + if force_load_plans or (self.plans is None): +- self.load_plans_file() ++ self.load_plans_file() # '/data/yupeng/environment_variables/nnUNet_preprocessed/Task003_Liver/nnUNetPlansv2.1_plans_3D.pkl' -- if advanced_postprocessing: -+ if advanced_postprocessing: # False - # first treat all foreground classes as one and remove all but the largest foreground connected component - results = [] - for f in fnames: -@@ -270,12 +270,12 @@ def determine_postprocessing(base, gt_labels_folder, raw_subfolder_name="validat - if len(classes) > 1: - # now depending on whether we do remove all but the largest foreground connected component we define the source dir - # for the next one to be the raw or the temp dir -- if do_fg_cc: -+ if do_fg_cc: # True - source = folder_all_classes_as_fg - else: - source = join(base, raw_subfolder_name) + self.process_plans(self.plans) -- if advanced_postprocessing: -+ if advanced_postprocessing: # False - # now run this for each class separately - results = [] - for f in fnames: -@@ -325,7 +325,7 @@ def determine_postprocessing(base, gt_labels_folder, raw_subfolder_name="validat - json_output_file=join(folder_per_class, "summary.json"), - json_author="Fabian", num_threads=processes) +@@ -189,6 +188,7 @@ class nnUNetPlusPlusTrainerV2(nnUNetTrainer): + """ + ds = self.network.do_ds + self.network.do_ds = False ++ overwrite = False # 不希望重新跑推理,不然太久了 + ret = super().validate(do_mirroring, use_sliding_window, step_size, save_softmax, use_gaussian, + overwrite, validation_folder_name, debug, all_in_gpu, segmentation_export_kwargs) -- if do_fg_cc: -+ if do_fg_cc: # True - old_res = deepcopy(validation_result_PP_test) - else: - old_res = validation_result_raw -@@ -350,7 +350,7 @@ def determine_postprocessing(base, gt_labels_folder, raw_subfolder_name="validat - else: - print("Only one class present, no need to do each class separately as this is covered in fg vs bg") +@@ -200,16 +200,18 @@ class nnUNetPlusPlusTrainerV2(nnUNetTrainer): + use_sliding_window: bool = True, step_size: float = 0.5, + use_gaussian: bool = True, pad_border_mode: str = 'constant', + pad_kwargs: dict = None, all_in_gpu: bool = True, +- verbose: bool = True, mixed_precision=True) -> Tuple[np.ndarray, np.ndarray]: ++ verbose: bool = True, mixed_precision=True, img_name=None, ++ pre_mode=None, fp=None) -> Tuple[np.ndarray, np.ndarray]: + """ + We need to wrap this because we need to enforce self.network.do_ds = False for prediction + """ +- ds = self.network.do_ds ++ ds = self.network.do_ds # ds = True + self.network.do_ds = False + ret = super().predict_preprocessed_data_return_seg_and_softmax(data, do_mirroring, mirror_axes, + use_sliding_window, step_size, use_gaussian, + pad_border_mode, pad_kwargs, all_in_gpu, verbose, +- mixed_precision=mixed_precision) ++ mixed_precision=mixed_precision, img_name=img_name, ++ pre_mode=pre_mode, fp=fp) + self.network.do_ds = ds + return ret -- if not advanced_postprocessing: -+ if not advanced_postprocessing: # True - pp_results['min_valid_object_sizes'] = None +@@ -225,7 +227,20 @@ class nnUNetPlusPlusTrainerV2(nnUNetTrainer): + data_dict = next(data_generator) + data = data_dict['data'] + target = data_dict['target'] +- ++ # i = 0 ++ # while True: ++ # i += 1 ++ # data_dict = next(data_generator) ++ # data = data_dict['data'] ++ # target = data_dict['target'] ++ # data_numpy_output = '/home/yupeng/save_data.nii.gz' ++ # data_numpy = data[0][0].numpy() ++ # target_numpy = target[0][0][0].numpy() ++ # data_1 = data_numpy.flatten() ++ # minm = np.argmin(data_1) ++ # maxm = np.argmax(data_1) ++ # out = sitk.GetImageFromArray(data_numpy) ++ # sitk.WriteImage(out, data_numpy_output) + data = maybe_to_torch(data) + target = maybe_to_torch(target) - print("done") -diff --git a/pytorch/nnunet/preprocessing/cropping.py b/pytorch/nnunet/preprocessing/cropping.py -index bb0a92a..95d07bc 100644 ---- a/pytorch/nnunet/preprocessing/cropping.py -+++ b/pytorch/nnunet/preprocessing/cropping.py -@@ -39,6 +39,7 @@ def get_bbox_from_mask(mask, outside_value=0): - maxxidx = int(np.max(mask_voxel_coords[1])) + 1 - minyidx = int(np.min(mask_voxel_coords[2])) - maxyidx = int(np.max(mask_voxel_coords[2])) + 1 -+ print(mask.shape, minzidx, maxzidx, minxidx, maxxidx, minyidx, maxyidx) - return [[minzidx, maxzidx], [minxidx, maxxidx], [minyidx, maxyidx]] +@@ -234,7 +249,6 @@ class nnUNetPlusPlusTrainerV2(nnUNetTrainer): + target = to_cuda(target) + self.optimizer.zero_grad() +- + if self.fp16: + with autocast(): + output = self.network(data) +@@ -261,7 +275,6 @@ class nnUNetPlusPlusTrainerV2(nnUNetTrainer): + self.run_online_evaluation(output, target) -@@ -202,6 +203,7 @@ class ImageCropper(object): - list_of_args.append((case, case_identifier, overwrite_existing)) + del target +- + return l.detach().cpu().numpy() - p = Pool(self.num_threads) -+ print('Pool', self.num_threads) - p.starmap(self.load_crop_save, list_of_args) - p.close() - p.join() -diff --git a/pytorch/nnunet/run/look_pkl.py b/pytorch/nnunet/run/look_pkl.py -new file mode 100644 -index 0000000..1a9d78a ---- /dev/null -+++ b/pytorch/nnunet/run/look_pkl.py -@@ -0,0 +1,18 @@ -+import numpy as np -+import pickle -+ -+inputfile = u'/data/yupeng/environment_variables/RESULTS_FOLDER/nnUNet/3d_fullres/Task003_Liver' \ -+ u'/nnUNetPlusPlusTrainerV2__nnUNetPlansv2.1/fold_0/model_final_checkpoint.model.pkl' -+# test = np.load('labels.npy', encoding = "latin1") -+# doc = open('1.txt', 'a') -+# print(test, file=doc) -+ -+ -+ -+fr = open(inputfile, 'rb') -+inf = pickle.load(fr) -+print('done') -+ -+ -+ -+print('end') -\ No newline at end of file -diff --git a/pytorch/nnunet/run/model_prof.py b/pytorch/nnunet/run/model_prof.py + def do_split(self): +diff --git a/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2_DDP.py b/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2_DDP.py new file mode 100644 -index 0000000..013df26 +index 0000000..e2ab2fa --- /dev/null -+++ b/pytorch/nnunet/run/model_prof.py -@@ -0,0 +1,124 @@ -+# Copyright (c) Soumith Chintala 2016, -+# All rights reserved -+# -+# Copyright 2020 Huawei Technologies Co., Ltd -+# -+# Licensed under the BSD 3-Clause License (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# https://spdx.org/licenses/BSD-3-Clause.html -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+ -+# -*- coding: utf-8 -*- -+"""pytorch_prof.py -+""" -+ -+import torch -+import torch.optim as optim -+import torch.nn as nn -+import time -+import argparse -+ -+ -+def build_model(): -+ # 请自定义模型并加载预训练模型 -+ import torchvision -+ model = torchvision.models.resnet50(pretrained=True) -+ return model -+ -+ -+def get_raw_data(): -+ input_tensor = torch.randn(2, 3, 224, 224) -+ return input_tensor -+ -+ -+def criterion(x): -+ base_func = nn.CrossEntropyLoss() -+ shape_list = x.shape -+ N = shape_list[0] -+ R = 1 -+ if len(shape_list) > 1: -+ for r in shape_list[1:]: -+ R *= r -+ T = torch.randint(0,R, size=(N,)).to(x.device) -+ if str(T.device).startswith('npu'): -+ T = T.int() -+ return base_func(x.reshape(N, -1), T) -+ -+ -+if __name__ == '__main__': -+ parser = argparse.ArgumentParser(description='PyTorch Prof') -+ parser.add_argument('--device', type=str, default='cpu', -+ help='set which type of device used. Support cuda:0(device_id), npu:0(device_id).') -+ parser.add_argument('--amp', default=False, action='store_true', -+ help='use amp during prof') -+ parser.add_argument('--loss-scale', default=64.0, type=float, -+ help='loss scale using in amp, default 64.0, -1 means dynamic') -+ parser.add_argument('--opt-level', default='O2', type=str, -+ help='opt-level using in amp, default O2') -+ parser.add_argument('--FusedSGD', default=False, action='store_true', -+ help='use FusedSGD during prof') -+ -+ args = parser.parse_args() -+ -+ # 1.准备工作 -+ if args.device.startswith('cuda'): -+ torch.cuda.set_device(args.device) -+ prof_kwargs = {'use_cuda': True} -+ elif args.device.startswith('npu'): -+ torch.npu.set_device(args.device) -+ prof_kwargs = {'use_npu': True} -+ else: -+ prof_kwargs = {} -+ -+ # 2.构建模型 -+ model = build_model() -+ if args.FusedSGD: -+ from apex.optimizers import NpuFusedSGD -+ optimizer = NpuFusedSGD(model.parameters(), lr=0.01) -+ model = model.to(args.device) -+ if args.amp: -+ from apex import amp -+ model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, -+ loss_scale=None if args.loss_scale == -1 else args.loss_scale, -+ combine_grad=True) -+ else: -+ optimizer = optim.SGD(model.parameters(), lr=0.01) -+ model = model.to(args.device) -+ if args.amp: -+ from apex import amp -+ model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, -+ loss_scale=None if args.loss_scale == -1 else args.loss_scale) -+ -+ # 3.生成input -+ input_tensor = get_raw_data() -+ input_tensor = input_tensor.to(args.device) -+ -+ # 先运行一次,保证prof得到的性能是正确的 -+ def run(): -+ output_tensor = model(input_tensor) -+ optimizer.zero_grad() -+ loss = criterion(output_tensor) -+ if args.amp: -+ with amp.scale_loss(loss, optimizer) as scaled_loss: -+ scaled_loss.backward() -+ else: -+ loss.backward() -+ optimizer.step() -+ return loss -+ for i in range(5): -+ start_time = time.time() -+ loss = run() -+ print('iter: %d, loss: %.2f, time: %.2f' % (i, loss, (time.time() - start_time)*1000)) -+ -+ # 4. 执行forward+profiling -+ with torch.autograd.profiler.profile(**prof_kwargs) as prof: -+ run() -+ print(prof.key_averages().table()) -+ prof.export_chrome_trace("pytorch_prof_%s.prof" % args.device) -\ No newline at end of file -diff --git a/pytorch/nnunet/run/run_training.py b/pytorch/nnunet/run/run_training.py -index eb7ca2f..08214d6 100644 ---- a/pytorch/nnunet/run/run_training.py -+++ b/pytorch/nnunet/run/run_training.py -@@ -31,7 +31,7 @@ def main(): - parser.add_argument("task", help="can be task name or task id") - parser.add_argument("fold", help='0, 1, ..., 5 or \'all\'') - parser.add_argument("-val", "--validation_only", help="use this if you want to only run the validation", -- action="store_true") -+ action="store_true", default=True) - parser.add_argument("-w", required=False, default=None, help="Load pre-trained Models Genesis") - parser.add_argument("-c", "--continue_training", help="use this if you want to continue a training", - action="store_true") -@@ -134,8 +134,8 @@ def main(): - fp16=run_mixed_precision) - - trainer.initialize(not validation_only) -- -- if weights != None: ++++ b/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2_DDP.py +@@ -0,0 +1,483 @@ ++# Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++ ++ ++from collections import OrderedDict ++from typing import Tuple ++import sys ++import time ++import numpy as np ++import torch ++import torch.distributed as dist ++from torch.cuda.amp import autocast ++from torch.nn.parallel import DistributedDataParallel as DDP ++from nnunet.training.loss_functions.deep_supervision import MultipleOutputLoss2 ++from nnunet.utilities.to_torch import maybe_to_torch, to_cuda ++from nnunet.training.data_augmentation.default_data_augmentation import get_moreDA_augmentation ++from nnunet.network_architecture.generic_UNetPlusPlus import Generic_UNetPlusPlus ++from nnunet.network_architecture.initialization import InitWeights_He ++from nnunet.network_architecture.neural_network import SegmentationNetwork ++from nnunet.training.data_augmentation.default_data_augmentation import default_2D_augmentation_params, \ ++ get_patch_size, default_3D_augmentation_params ++from nnunet.training.dataloading.dataset_loading import unpack_dataset ++from nnunet.training.network_training.nnUNetTrainer import nnUNetTrainer ++from nnunet.utilities.nd_softmax import softmax_helper ++from sklearn.model_selection import KFold ++from torch import nn ++from torch.cuda.amp import autocast ++from nnunet.training.learning_rate.poly_lr import poly_lr ++from batchgenerators.utilities.file_and_folder_operations import * ++ ++ ++class nnUNetPlusPlusTrainerV2_DDP(nnUNetTrainer): ++ """ ++ Info for Fabian: same as internal nnUNetTrainerV2_2 ++ """ ++ ++ def __init__(self, plans_file, fold, local_rank, output_folder=None, dataset_directory=None, batch_dice=True, ++ stage=None, ++ unpack_data=True, deterministic=True, fp16=False, distribute_batch_size=1): ++ super().__init__(plans_file, fold, output_folder, dataset_directory, batch_dice, stage, unpack_data, ++ deterministic, fp16) ++ self.init_args = ( ++ plans_file, fold, local_rank, output_folder, dataset_directory, batch_dice, stage, unpack_data, ++ deterministic, distribute_batch_size, fp16) ++ self.max_num_epochs = 1000 ++ self.initial_lr = 1e-2 ++ self.deep_supervision_scales = None ++ self.ds_loss_weights = None ++ self.distribute_batch_size = distribute_batch_size ++ np.random.seed(local_rank) ++ torch.manual_seed(local_rank) ++ self.local_rank = local_rank ++ if torch.cuda.is_available(): ++ torch.cuda.set_device(local_rank) ++ dist.init_process_group(backend='nccl', init_method='env://') ++ ++ self.pin_memory = True ++ ++ def initialize(self, training=True, force_load_plans=False): ++ """ ++ - replaced get_default_augmentation with get_moreDA_augmentation ++ - enforce to only run this code once ++ - loss function wrapper for deep supervision ++ ++ :param training: ++ :param force_load_plans: ++ :return: ++ """ ++ if not self.was_initialized: ++ maybe_mkdir_p(self.output_folder) ++ ++ if force_load_plans or (self.plans is None): ++ self.load_plans_file() ++ ++ self.process_plans(self.plans) ++ ++ self.setup_DA_params() ++ ++ ################# Here we wrap the loss for deep supervision ############ ++ # we need to know the number of outputs of the network ++ net_numpool = len(self.net_num_pool_op_kernel_sizes) ++ ++ # we give each output a weight which decreases exponentially (division by 2) as the resolution decreases ++ # this gives higher resolution outputs more weight in the loss ++ weights = np.array([1 / (2 ** i) for i in range(net_numpool)]) ++ ++ # we don't use the lowest 2 outputs. Normalize weights so that they sum to 1 ++ mask = np.array([True] + [True if i < net_numpool - 1 else False for i in range(1, net_numpool)]) ++ weights[~mask] = 0 ++ weights = weights / weights.sum() ++ # self.ds_loss_weights = weights ++ self.ds_loss_weights = None ++ # now wrap the loss ++ self.loss = MultipleOutputLoss2(self.loss, self.ds_loss_weights) ++ ################# END ################### ++ ++ self.folder_with_preprocessed_data = join(self.dataset_directory, self.plans['data_identifier'] + ++ "_stage%d" % self.stage) ++ if training: ++ self.dl_tr, self.dl_val = self.get_basic_generators() ++ if self.unpack_data: ++ if self.local_rank == 0: ++ print("unpacking dataset") ++ unpack_dataset(self.folder_with_preprocessed_data) ++ print("done") ++ else: ++ # we need to wait until worker 0 has finished unpacking ++ npz_files = subfiles(self.folder_with_preprocessed_data, suffix=".npz", join=False) ++ case_ids = [i[:-4] for i in npz_files] ++ all_present = all( ++ [isfile(join(self.folder_with_preprocessed_data, i + ".npy")) for i in case_ids]) ++ while not all_present: ++ print("worker", self.local_rank, "is waiting for unpacking") ++ time.sleep(3) ++ all_present = all( ++ [isfile(join(self.folder_with_preprocessed_data, i + ".npy")) for i in case_ids]) ++ # there is some slight chance that there may arise some error because dataloader are loading a file ++ # that is still being written by worker 0. We ignore this for now an address it only if it becomes ++ # relevant ++ # (this can occur because while worker 0 writes the file is technically present so the other workers ++ # will proceed and eventually try to read it) ++ else: ++ print( ++ "INFO: Not unpacking data! Training may be slow due to that. Pray you are not using 2d or you " ++ "will wait all winter for your model to finish!") + -+ if weights != None: - trainer.load_pretrained_encoder_weights(weights) - sys.stdout.flush() - -diff --git a/pytorch/nnunet/run/run_training2.py b/pytorch/nnunet/run/run_training2.py -new file mode 100644 -index 0000000..372a4d4 ---- /dev/null -+++ b/pytorch/nnunet/run/run_training2.py -@@ -0,0 +1,172 @@ -+# Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany -+# -+# Licensed under the Apache License, Version 2.0 (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# http://www.apache.org/licenses/LICENSE-2.0 -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+import os -+import sys -+import argparse -+from batchgenerators.utilities.file_and_folder_operations import * -+from nnunet.run.default_configuration import get_default_configuration -+from nnunet.paths import default_plans_identifier -+from nnunet.training.cascade_stuff.predict_next_stage import predict_next_stage -+from nnunet.training.network_training.nnUNetTrainer import nnUNetTrainer -+from nnunet.training.network_training.nnUNetTrainerCascadeFullRes import nnUNetTrainerCascadeFullRes -+from nnunet.training.network_training.nnUNetTrainerV2_CascadeFullRes import nnUNetTrainerV2CascadeFullRes -+from nnunet.utilities.task_name_id_conversion import convert_id_to_task_name ++ self.tr_gen, self.val_gen = get_moreDA_augmentation( ++ self.dl_tr, self.dl_val, ++ self.data_aug_params[ ++ 'patch_size_for_spatialtransform'], ++ self.data_aug_params, ++ deep_supervision_scales=self.deep_supervision_scales, ++ pin_memory=self.pin_memory ++ ) ++ self.print_to_log_file("TRAINING KEYS:\n %s" % (str(self.dataset_tr.keys())), ++ also_print_to_console=False) ++ self.print_to_log_file("VALIDATION KEYS:\n %s" % (str(self.dataset_val.keys())), ++ also_print_to_console=False) ++ else: ++ pass + ++ self.initialize_network() ++ self.initialize_optimizer_and_scheduler() + -+# import pdb -+# pdb.set_trace() ++ assert isinstance(self.network, (SegmentationNetwork, DDP)) ++ else: ++ self.print_to_log_file('self.was_initialized is True, not running self.initialize again') ++ self.was_initialized = True + -+def main(): -+ parser = argparse.ArgumentParser() -+ parser.add_argument("-network", default="3d_fullres") -+ parser.add_argument("-network_trainer", default="nnUNetPlusPlusTrainerV2") -+ parser.add_argument("-task", default="003", help="can be task name or task id") -+ parser.add_argument("-fold", default="0", help='0, 1, ..., 5 or \'all\'') -+ parser.add_argument("-val", "--validation_only", default=False, -+ help="use this if you want to only run the validation", -+ action="store_true") -+ parser.add_argument("-w", required=False, default=None, help="Load pre-trained Models Genesis") -+ parser.add_argument("-c", "--continue_training", default=False, help="use this if you want to continue a training", -+ action="store_true") -+ parser.add_argument("-p", help="plans identifier. Only change this if you created a custom experiment planner", -+ default=default_plans_identifier, required=False) -+ parser.add_argument("--use_compressed_data", default=False, action="store_true", -+ help="If you set use_compressed_data, the training cases will not be decompressed. Reading compressed data " -+ "is much more CPU and RAM intensive and should only be used if you know what you are " -+ "doing", required=False) -+ parser.add_argument("--deterministic", -+ help="Makes training deterministic, but reduces training speed substantially. I (Fabian) think " -+ "this is not necessary. Deterministic training will make you overfit to some random seed. " -+ "Don't use that.", -+ required=False, default=False, action="store_true") -+ parser.add_argument("--npz", required=False, default=False, action="store_true", help="if set then nnUNet will " -+ "export npz files of " -+ "predicted segmentations " -+ "in the validation as well. " -+ "This is needed to run the " -+ "ensembling step so unless " -+ "you are developing nnUNet " -+ "you should enable this") -+ parser.add_argument("--find_lr", required=False, default=False, action="store_true", -+ help="not used here, just for fun") -+ parser.add_argument("--valbest", required=False, default=False, action="store_true", -+ help="hands off. This is not intended to be used") -+ parser.add_argument("--fp32", required=False, default=False, action="store_true", -+ help="disable mixed precision training and run old school fp32") -+ parser.add_argument("--val_folder", required=False, default="validation_raw", -+ help="name of the validation folder. No need to use this for most people") -+ # parser.add_argument("--interp_order", required=False, default=3, type=int, -+ # help="order of interpolation for segmentations. Testing purpose only. Hands off") -+ # parser.add_argument("--interp_order_z", required=False, default=0, type=int, -+ # help="order of interpolation along z if z is resampled separately. Testing purpose only. " -+ # "Hands off") -+ # parser.add_argument("--force_separate_z", required=False, default="None", type=str, -+ # help="force_separate_z resampling. Can be None, True or False. Testing purpose only. Hands off") ++ def initialize_network(self): ++ """ ++ - momentum 0.99 ++ - SGD instead of Adam ++ - self.lr_scheduler = None because we do poly_lr ++ - deep supervision = True ++ - i am sure I forgot something here + -+ args = parser.parse_args() -+ print('------------\n', args) ++ Known issue: forgot to set neg_slope=0 in InitWeights_He; should not make a difference though ++ :return: ++ """ ++ if self.threeD: ++ conv_op = nn.Conv3d ++ dropout_op = nn.Dropout3d ++ norm_op = nn.InstanceNorm3d + -+ task = args.task -+ fold = args.fold -+ network = args.network -+ network_trainer = args.network_trainer -+ weights = args.w -+ validation_only = args.validation_only -+ plans_identifier = args.p -+ find_lr = args.find_lr ++ else: ++ conv_op = nn.Conv2d ++ dropout_op = nn.Dropout2d ++ norm_op = nn.InstanceNorm2d ++ norm_op_kwargs = {'eps': 1e-5, 'affine': True} ++ dropout_op_kwargs = {'p': 0, 'inplace': True} ++ net_nonlin = nn.LeakyReLU ++ net_nonlin_kwargs = {'negative_slope': 1e-2, 'inplace': True} ++ self.network = Generic_UNetPlusPlus(self.num_input_channels, self.base_num_features, self.num_classes, ++ len(self.net_num_pool_op_kernel_sizes), ++ self.conv_per_stage, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, ++ dropout_op_kwargs, ++ net_nonlin, net_nonlin_kwargs, True, False, lambda x: x, ++ InitWeights_He(1e-2), ++ self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, ++ True) ++ if torch.cuda.is_available(): ++ self.network.cuda() ++ self.network.inference_apply_nonlin = softmax_helper ++ self.network = DDP(self.network, device_ids=[self.local_rank], find_unused_parameters=True) + -+ use_compressed_data = args.use_compressed_data -+ decompress_data = not use_compressed_data ++ # self.network = DDP(self.network, device_ids=[self.local_rank], find_unused_parameters=True) + -+ deterministic = args.deterministic -+ valbest = args.valbest ++ def initialize_optimizer_and_scheduler(self): ++ assert self.network is not None, "self.initialize_network must be called first" ++ print('weight_decay: ', self.weight_decay) ++ sys.stdout.flush() ++ self.optimizer = torch.optim.SGD(self.network.parameters(), self.initial_lr, weight_decay=self.weight_decay, ++ momentum=0.99, nesterov=True) ++ self.lr_scheduler = None + -+ fp32 = args.fp32 -+ run_mixed_precision = not fp32 ++ def run_online_evaluation(self, output, target): ++ """ ++ due to deep supervision the return value and the reference are now lists of tensors. We only need the full ++ resolution output because this is what we are interested in in the end. The others are ignored ++ :param output: ++ :param target: ++ :return: ++ """ ++ target = target[0] ++ output = output[0] ++ return super().run_online_evaluation(output, target) + -+ val_folder = args.val_folder -+ # interp_order = args.interp_order -+ # interp_order_z = args.interp_order_z -+ # force_separate_z = args.force_separate_z ++ def validate(self, do_mirroring: bool = True, use_sliding_window: bool = True, ++ step_size: float = 0.5, save_softmax: bool = True, use_gaussian: bool = True, overwrite: bool = True, ++ validation_folder_name: str = 'validation_raw', debug: bool = False, all_in_gpu: bool = False, ++ segmentation_export_kwargs: dict = None): ++ """ ++ We need to wrap this because we need to enforce self.network.do_ds = False for prediction ++ """ ++ if self.local_rank == 0: ++ if isinstance(self.network, DDP): ++ net = self.network.module ++ else: ++ net = self.network ++ ds = self.network.do_ds ++ net.do_ds = False ++ ret = super().validate(do_mirroring, use_sliding_window, step_size, save_softmax, use_gaussian, ++ overwrite, validation_folder_name, debug, all_in_gpu, segmentation_export_kwargs) + -+ if not task.startswith("Task"): -+ task_id = int(task) -+ task = convert_id_to_task_name(task_id) ++ net.do_ds = ds ++ return ret + -+ if fold == 'all': -+ pass -+ else: -+ fold = int(fold) ++ def predict_preprocessed_data_return_seg_and_softmax(self, data: np.ndarray, do_mirroring: bool = True, ++ mirror_axes: Tuple[int] = None, ++ use_sliding_window: bool = True, step_size: float = 0.5, ++ use_gaussian: bool = True, pad_border_mode: str = 'constant', ++ pad_kwargs: dict = None, all_in_gpu: bool = True, ++ verbose: bool = True, mixed_precision=True) -> Tuple[ ++ np.ndarray, np.ndarray]: ++ """ ++ We need to wrap this because we need to enforce self.network.do_ds = False for prediction ++ """ ++ ds = self.network.do_ds ++ self.network.do_ds = False ++ ret = super().predict_preprocessed_data_return_seg_and_softmax(data, do_mirroring, mirror_axes, ++ use_sliding_window, step_size, use_gaussian, ++ pad_border_mode, pad_kwargs, all_in_gpu, verbose, ++ mixed_precision=mixed_precision) ++ self.network.do_ds = ds ++ return ret + -+ # if force_separate_z == "None": -+ # force_separate_z = None -+ # elif force_separate_z == "False": -+ # force_separate_z = False -+ # elif force_separate_z == "True": -+ # force_separate_z = True -+ # else: -+ # raise ValueError("force_separate_z must be None, True or False. Given: %s" % force_separate_z) ++ def run_iteration(self, data_generator, do_backprop=True, run_online_evaluation=False): ++ """ ++ gradient clipping improves training stability + -+ plans_file, output_folder_name, dataset_directory, batch_dice, stage, \ -+ trainer_class, domain = get_default_configuration(network, task, network_trainer, plans_identifier) ++ :param data_generator: ++ :param do_backprop: ++ :param run_online_evaluation: ++ :return: ++ """ ++ data_dict = next(data_generator) ++ data = data_dict['data'] ++ target = data_dict['target'] + -+ if trainer_class is None: -+ raise RuntimeError("Could not find trainer class in nnunet.training.network_training") ++ data = maybe_to_torch(data) ++ target = maybe_to_torch(target) + -+ if network == "3d_cascade_fullres": -+ assert issubclass(trainer_class, (nnUNetTrainerCascadeFullRes, nnUNetTrainerV2CascadeFullRes)), \ -+ "If running 3d_cascade_fullres then your " \ -+ "trainer class must be derived from " \ -+ "nnUNetTrainerCascadeFullRes" -+ else: -+ assert issubclass(trainer_class, -+ nnUNetTrainer), "network_trainer was found but is not derived from nnUNetTrainer" ++ if torch.cuda.is_available(): ++ data = to_cuda(data, gpu_id=None) ++ target = to_cuda(target, gpu_id=None) + -+ trainer = trainer_class(plans_file, fold, output_folder=output_folder_name, dataset_directory=dataset_directory, -+ batch_dice=batch_dice, stage=stage, unpack_data=decompress_data, -+ deterministic=deterministic, -+ fp16=run_mixed_precision) ++ self.optimizer.zero_grad() + -+ trainer.initialize(not validation_only) ++ if self.fp16: ++ with autocast(): ++ output = self.network(data) ++ del data ++ l = self.loss(output, target) + -+ if weights != None: -+ trainer.load_pretrained_encoder_weights(weights) -+ sys.stdout.flush() ++ if do_backprop: ++ self.amp_grad_scaler.scale(l).backward() ++ self.amp_grad_scaler.unscale_(self.optimizer) ++ torch.nn.utils.clip_grad_norm_(self.network.parameters(), 12) ++ self.amp_grad_scaler.step(self.optimizer) ++ self.amp_grad_scaler.update() ++ else: ++ output = self.network(data) ++ del data ++ l = self.loss(output, target) ++ ++ if do_backprop: ++ l.backward() ++ torch.nn.utils.clip_grad_norm_(self.network.parameters(), 12) ++ self.optimizer.step() ++ ++ if run_online_evaluation: ++ self.run_online_evaluation(output, target) ++ ++ del target ++ ++ return l.detach().cpu().numpy() ++ ++ def do_split(self): ++ """ ++ we now allow more than 5 splits. IMPORTANT: and fold > 4 will not be a real split but just another random ++ 80:20 split of the data. You cannot run X-fold cross-validation with this code. It will always be a 5-fold CV. ++ Folds > 4 will be independent from each other ++ :return: ++ """ ++ if self.fold == "all": ++ # if fold==all then we use all images for training and validation ++ tr_keys = val_keys = list(self.dataset.keys()) ++ else: ++ splits_file = join(self.dataset_directory, "splits_final.pkl") ++ ++ # if the split file does not exist we need to create it ++ if not isfile(splits_file): ++ self.print_to_log_file("Creating new split...") ++ splits = [] ++ all_keys_sorted = np.sort(list(self.dataset.keys())) ++ kfold = KFold(n_splits=5, shuffle=True, random_state=12345) ++ for i, (train_idx, test_idx) in enumerate(kfold.split(all_keys_sorted)): ++ train_keys = np.array(all_keys_sorted)[train_idx] ++ test_keys = np.array(all_keys_sorted)[test_idx] ++ splits.append(OrderedDict()) ++ splits[-1]['train'] = train_keys ++ splits[-1]['val'] = test_keys ++ save_pickle(splits, splits_file) ++ ++ splits = load_pickle(splits_file) ++ ++ if self.fold < len(splits): ++ tr_keys = splits[self.fold]['train'] ++ val_keys = splits[self.fold]['val'] ++ else: ++ self.print_to_log_file("INFO: Requested fold %d but split file only has %d folds. I am now creating a " ++ "random 80:20 split!" % (self.fold, len(splits))) ++ # if we request a fold that is not in the split file, create a random 80:20 split ++ rnd = np.random.RandomState(seed=12345 + self.fold) ++ keys = np.sort(list(self.dataset.keys())) ++ idx_tr = rnd.choice(len(keys), int(len(keys) * 0.8), replace=False) ++ idx_val = [i for i in range(len(keys)) if i not in idx_tr] ++ tr_keys = [keys[i] for i in idx_tr] ++ val_keys = [keys[i] for i in idx_val] ++ ++ tr_keys.sort() ++ val_keys.sort() ++ self.dataset_tr = OrderedDict() ++ for i in tr_keys: ++ self.dataset_tr[i] = self.dataset[i] ++ self.dataset_val = OrderedDict() ++ for i in val_keys: ++ self.dataset_val[i] = self.dataset[i] ++ ++ def setup_DA_params(self): ++ """ ++ - we increase roation angle from [-15, 15] to [-30, 30] ++ - scale range is now (0.7, 1.4), was (0.85, 1.25) ++ - we don't do elastic deformation anymore ++ ++ :return: ++ """ ++ ++ self.deep_supervision_scales = [[1, 1, 1]] + list(list(i) for i in 1 / np.cumprod( ++ np.vstack(self.net_num_pool_op_kernel_sizes), axis=0))[:-1] ++ ++ if self.threeD: ++ self.data_aug_params = default_3D_augmentation_params ++ self.data_aug_params['rotation_x'] = (-30. / 360 * 2. * np.pi, 30. / 360 * 2. * np.pi) ++ self.data_aug_params['rotation_y'] = (-30. / 360 * 2. * np.pi, 30. / 360 * 2. * np.pi) ++ self.data_aug_params['rotation_z'] = (-30. / 360 * 2. * np.pi, 30. / 360 * 2. * np.pi) ++ if self.do_dummy_2D_aug: ++ self.data_aug_params["dummy_2D"] = True ++ self.print_to_log_file("Using dummy2d data augmentation") ++ self.data_aug_params["elastic_deform_alpha"] = \ ++ default_2D_augmentation_params["elastic_deform_alpha"] ++ self.data_aug_params["elastic_deform_sigma"] = \ ++ default_2D_augmentation_params["elastic_deform_sigma"] ++ self.data_aug_params["rotation_x"] = default_2D_augmentation_params["rotation_x"] ++ else: ++ self.do_dummy_2D_aug = False ++ if max(self.patch_size) / min(self.patch_size) > 1.5: ++ default_2D_augmentation_params['rotation_x'] = (-15. / 360 * 2. * np.pi, 15. / 360 * 2. * np.pi) ++ self.data_aug_params = default_2D_augmentation_params ++ self.data_aug_params["mask_was_used_for_normalization"] = self.use_mask_for_norm ++ ++ if self.do_dummy_2D_aug: ++ self.basic_generator_patch_size = get_patch_size(self.patch_size[1:], ++ self.data_aug_params['rotation_x'], ++ self.data_aug_params['rotation_y'], ++ self.data_aug_params['rotation_z'], ++ self.data_aug_params['scale_range']) ++ self.basic_generator_patch_size = np.array([self.patch_size[0]] + list(self.basic_generator_patch_size)) ++ patch_size_for_spatialtransform = self.patch_size[1:] ++ else: ++ self.basic_generator_patch_size = get_patch_size(self.patch_size, self.data_aug_params['rotation_x'], ++ self.data_aug_params['rotation_y'], ++ self.data_aug_params['rotation_z'], ++ self.data_aug_params['scale_range']) ++ patch_size_for_spatialtransform = self.patch_size ++ ++ self.data_aug_params["scale_range"] = (0.7, 1.4) ++ self.data_aug_params["do_elastic"] = False ++ self.data_aug_params['selected_seg_channels'] = [0] ++ self.data_aug_params['patch_size_for_spatialtransform'] = patch_size_for_spatialtransform ++ ++ self.data_aug_params["num_cached_per_thread"] = 2 ++ ++ def maybe_update_lr(self, epoch=None): ++ """ ++ if epoch is not None we overwrite epoch. Else we use epoch = self.epoch + 1 + -+ if find_lr: -+ trainer.find_lr() -+ else: -+ if not validation_only: -+ if args.continue_training: -+ trainer.load_latest_checkpoint() -+ trainer.run_training() ++ (maybe_update_lr is called in on_epoch_end which is called before epoch is incremented. ++ herefore we need to do +1 here) ++ ++ :param epoch: ++ :return: ++ """ ++ if epoch is None: ++ ep = self.epoch + 1 + else: -+ if valbest: -+ trainer.load_best_checkpoint(train=False) -+ else: -+ trainer.load_latest_checkpoint(train=False) ++ ep = epoch ++ self.optimizer.param_groups[0]['lr'] = poly_lr(ep, self.max_num_epochs, self.initial_lr, 0.9) ++ self.print_to_log_file("lr:", np.round(self.optimizer.param_groups[0]['lr'], decimals=6)) + -+ trainer.network.eval() ++ def on_epoch_end(self): ++ """ ++ overwrite patient-based early stopping. Always run to 1000 epochs ++ :return: ++ """ ++ super().on_epoch_end() ++ continue_training = self.epoch < self.max_num_epochs + -+ # predict validation -+ trainer.validate(save_softmax=args.npz, validation_folder_name=val_folder) ++ # it can rarely happen that the momentum of nnUNetTrainerV2_plus is too high for some dataset. If at epoch 100 the ++ # estimated validation Dice is still 0 then we reduce the momentum from 0.99 to 0.95 ++ if self.epoch == 100: ++ if self.all_val_eval_metrics[-1] == 0: ++ self.optimizer.param_groups[0]["momentum"] = 0.95 ++ self.network.apply(InitWeights_He(1e-2)) ++ self.print_to_log_file("At epoch 100, the mean foreground Dice was 0. This can be caused by a too " ++ "high momentum. High momentum (0.99) is good for datasets where it works, but " ++ "sometimes causes issues such as this one. Momentum has now been reduced to " ++ "0.95 and network weights have been reinitialized") ++ return continue_training + -+ if network == '3d_lowres': -+ trainer.load_best_checkpoint(False) -+ print("predicting segmentations for the next stage of the cascade") -+ predict_next_stage(trainer, join(dataset_directory, trainer.plans['data_identifier'] + "_stage%d" % 1)) ++ def save_checkpoint(self, fname, save_optimizer=True): ++ if self.local_rank == 0: ++ super().save_checkpoint(fname, save_optimizer) + ++ def plot_progress(self): ++ if self.local_rank == 0: ++ super().plot_progress() + -+if __name__ == "__main__": -+ main() -diff --git a/pytorch/nnunet/run/run_training_DDP.py b/pytorch/nnunet/run/run_training_DDP.py -index 5ffcdcf..6ad3d5a 100644 ---- a/pytorch/nnunet/run/run_training_DDP.py -+++ b/pytorch/nnunet/run/run_training_DDP.py -@@ -27,13 +27,13 @@ from nnunet.utilities.task_name_id_conversion import convert_id_to_task_name - - def main(): - parser = argparse.ArgumentParser() -- parser.add_argument("network") -- parser.add_argument("network_trainer") -- parser.add_argument("task", help="can be task name or task id") -- parser.add_argument("fold", help='0, 1, ..., 5 or \'all\'') -+ parser.add_argument("network", default='3d_fullres') -+ parser.add_argument("network_trainer", default='nnUNetTrainerV2_DDP') -+ parser.add_argument("task", help="can be task name or task id", default='003') -+ parser.add_argument("fold", help='0, 1, ..., 5 or \'all\'', default='0') - parser.add_argument("-val", "--validation_only", help="use this if you want to only run the validation", -- action="store_true") -- parser.add_argument("-c", "--continue_training", help="use this if you want to continue a training", -+ action="store_true", default=False) -+ parser.add_argument("-c", "--continue_training", default=False, help="use this if you want to continue a training", - action="store_true") - parser.add_argument("-p", help="plans identifier. Only change this if you created a custom experiment planner", - default=default_plans_identifier, required=False) -@@ -78,7 +78,7 @@ def main(): - # help="force_separate_z resampling. Can be None, True or False. Testing purpose only. Hands off") - - args = parser.parse_args() -- -+ print('\n\n args=', args, '\n\n') - task = args.task - fold = args.fold - network = args.network -@@ -115,7 +115,7 @@ def main(): - # raise ValueError("force_separate_z must be None, True or False. Given: %s" % force_separate_z) - - plans_file, output_folder_name, dataset_directory, batch_dice, stage, \ -- trainer_class = get_default_configuration(network, task, network_trainer, plans_identifier) -+ trainer_class, _ = get_default_configuration(network, task, network_trainer, plans_identifier) - - if trainer_class is None: - raise RuntimeError("Could not find trainer class in meddec.model_training") -diff --git a/pytorch/nnunet/run/run_training_hypDDP.py b/pytorch/nnunet/run/run_training_hypDDP.py -new file mode 100644 -index 0000000..f50744c ---- /dev/null -+++ b/pytorch/nnunet/run/run_training_hypDDP.py -@@ -0,0 +1,164 @@ -+# Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany -+# -+# Licensed under the Apache License, Version 2.0 (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# http://www.apache.org/licenses/LICENSE-2.0 -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+ -+ -+import argparse -+ -+from batchgenerators.utilities.file_and_folder_operations import * -+from nnunet.run.default_configuration import get_default_configuration -+from nnunet.paths import default_plans_identifier -+from nnunet.training.cascade_stuff.predict_next_stage import predict_next_stage -+from nnunet.training.network_training.nnUNetTrainer import nnUNetTrainer -+from nnunet.training.network_training.nnUNetTrainerCascadeFullRes import nnUNetTrainerCascadeFullRes -+from nnunet.training.network_training.nnUNetTrainerV2_CascadeFullRes import nnUNetTrainerV2CascadeFullRes -+from nnunet.utilities.task_name_id_conversion import convert_id_to_task_name -+ -+ -+def main(): -+ parser = argparse.ArgumentParser() -+ parser.add_argument("network") -+ parser.add_argument("network_trainer") -+ parser.add_argument("task", help="can be task name or task id") -+ parser.add_argument("fold", help='0, 1, ..., 5 or \'all\'') -+ parser.add_argument("-val", "--validation_only", help="use this if you want to only run the validation", -+ action="store_true") -+ parser.add_argument("-c", "--continue_training", help="use this if you want to continue a training", -+ action="store_true") -+ parser.add_argument("-p", help="plans identifier. Only change this if you created a custom experiment planner", -+ default=default_plans_identifier, required=False) -+ parser.add_argument("--use_compressed_data", default=False, action="store_true", -+ help="If you set use_compressed_data, the training cases will not be decompressed. Reading compressed data " -+ "is much more CPU and RAM intensive and should only be used if you know what you are " -+ "doing", required=False) -+ parser.add_argument("--deterministic", -+ help="Makes training deterministic, but reduces training speed substantially. I (Fabian) think " -+ "this is not necessary. Deterministic training will make you overfit to some random seed. " -+ "Don't use that.", -+ required=False, default=False, action="store_true") -+ parser.add_argument("--local_rank", default=0, type=int) -+ parser.add_argument("--fp32", required=False, default=False, action="store_true", -+ help="disable mixed precision training and run old school fp32") -+ parser.add_argument("--dbs", required=False, default=False, action="store_true", help="distribute batch size. If " -+ "True then whatever " -+ "batch_size is in plans will " -+ "be distributed over DDP " -+ "models, if False then each " -+ "model will have batch_size " -+ "for a total of " -+ "GPUs*batch_size") -+ parser.add_argument("--npz", required=False, default=False, action="store_true", help="if set then nnUNet will " -+ "export npz files of " -+ "predicted segmentations " -+ "in the vlaidation as well. " -+ "This is needed to run the " -+ "ensembling step so unless " -+ "you are developing nnUNet " -+ "you should enable this") -+ parser.add_argument("--valbest", required=False, default=False, action="store_true", help="") -+ parser.add_argument("--find_lr", required=False, default=False, action="store_true", help="") -+ parser.add_argument("--val_folder", required=False, default="validation_raw", -+ help="name of the validation folder. No need to use this for most people") -+ # parser.add_argument("--interp_order", required=False, default=3, type=int, -+ # help="order of interpolation for segmentations. Testing purpose only. Hands off") -+ # parser.add_argument("--interp_order_z", required=False, default=0, type=int, -+ # help="order of interpolation along z if z is resampled separately. Testing purpose only. " -+ # "Hands off") -+ # parser.add_argument("--force_separate_z", required=False, default="None", type=str, -+ # help="force_separate_z resampling. Can be None, True or False. Testing purpose only. Hands off") -+ -+ args = parser.parse_args() -+ print('\n\n args=', args, '\n\n') -+ task = args.task -+ fold = args.fold -+ network = args.network -+ network_trainer = args.network_trainer -+ validation_only = args.validation_only -+ plans_identifier = args.p -+ use_compressed_data = args.use_compressed_data -+ decompress_data = not use_compressed_data -+ deterministic = args.deterministic -+ valbest = args.valbest -+ find_lr = args.find_lr -+ val_folder = args.val_folder -+ # interp_order = args.interp_order -+ # interp_order_z = args.interp_order_z -+ # force_separate_z = args.force_separate_z -+ fp32 = args.fp32 -+ -+ if not task.startswith("Task"): -+ task_id = int(task) -+ task = convert_id_to_task_name(task_id) -+ -+ if fold == 'all': -+ pass -+ else: -+ fold = int(fold) -+ # -+ # if force_separate_z == "None": -+ # force_separate_z = None -+ # elif force_separate_z == "False": -+ # force_separate_z = False -+ # elif force_separate_z == "True": -+ # force_separate_z = True -+ # else: -+ # raise ValueError("force_separate_z must be None, True or False. Given: %s" % force_separate_z) -+ -+ plans_file, output_folder_name, dataset_directory, batch_dice, stage, \ -+ trainer_class, _ = get_default_configuration(network, task, network_trainer, plans_identifier) -+ -+ if trainer_class is None: -+ raise RuntimeError("Could not find trainer class in meddec.model_training") -+ -+ if network == "3d_cascade_fullres": -+ assert issubclass(trainer_class, (nnUNetTrainerCascadeFullRes, nnUNetTrainerV2CascadeFullRes)), \ -+ "If running 3d_cascade_fullres then your " \ -+ "trainer class must be derived from " \ -+ "nnUNetTrainerCascadeFullRes" -+ else: -+ assert issubclass(trainer_class, -+ nnUNetTrainer), "network_trainer was found but is not derived from nnUNetTrainer" -+ -+ trainer = trainer_class(plans_file, fold, local_rank=args.local_rank, output_folder=output_folder_name, -+ dataset_directory=dataset_directory, batch_dice=batch_dice, stage=stage, -+ unpack_data=decompress_data, deterministic=deterministic, fp16=not fp32, -+ distribute_batch_size=args.dbs) -+ -+ trainer.initialize(not validation_only) -+ -+ if find_lr: -+ trainer.find_lr() -+ else: -+ if not validation_only: -+ if args.continue_training: -+ trainer.load_latest_checkpoint() -+ trainer.run_training() -+ else: -+ if valbest: -+ trainer.load_best_checkpoint(train=False) -+ else: -+ trainer.load_latest_checkpoint(train=False) -+ -+ trainer.network.eval() -+ -+ # predict validation -+ trainer.validate(save_softmax=args.npz, validation_folder_name=val_folder) -+ -+ if network == '3d_lowres': -+ trainer.load_best_checkpoint(False) -+ print("predicting segmentations for the next stage of the cascade") -+ predict_next_stage(trainer, join(dataset_directory, trainer.plans['data_identifier'] + "_stage%d" % 1)) -+ -+ -+if __name__ == "__main__": -+ main() -diff --git a/pytorch/nnunet/training/loss_functions/crossentropy.py b/pytorch/nnunet/training/loss_functions/crossentropy.py -index 6195437..0c782d9 100644 ---- a/pytorch/nnunet/training/loss_functions/crossentropy.py -+++ b/pytorch/nnunet/training/loss_functions/crossentropy.py -@@ -6,6 +6,15 @@ class RobustCrossEntropyLoss(nn.CrossEntropyLoss): - this is just a compatibility layer because my target tensor is float and has an extra dimension - """ - def forward(self, input: Tensor, target: Tensor) -> Tensor: -+ # i = 0 -+ # print('----------') -+ # print('input:', input.shape) -+ # for i in range(len(input)): -+ # print(i, input[i].shape) -+ # print('target') -+ # for i in range(len(target)): -+ # print(i, target[i].shape) -+ # print('\n----------') - if len(target.shape) == len(input.shape): - assert target.shape[1] == 1 - target = target[:, 0] -diff --git a/pytorch/nnunet/training/network_training/network_trainer.py b/pytorch/nnunet/training/network_training/network_trainer.py -index e920158..f0031d3 100644 ---- a/pytorch/nnunet/training/network_training/network_trainer.py -+++ b/pytorch/nnunet/training/network_training/network_trainer.py -@@ -37,6 +37,7 @@ from abc import abstractmethod - from datetime import datetime - from tqdm import trange - from nnunet.utilities.to_torch import maybe_to_torch, to_cuda -+import pdb - - - class NetworkTrainer(object): -@@ -438,7 +439,8 @@ class NetworkTrainer(object): - self._maybe_init_amp() - - def _maybe_init_amp(self): -- if self.fp16 and self.amp_grad_scaler is None and torch.cuda.is_available(): -+ # if self.fp16 and self.amp_grad_scaler is None and torch.cuda.is_available(): -+ if self.fp16 and self.amp_grad_scaler is None: - self.amp_grad_scaler = GradScaler() - - def plot_network_architecture(self): -diff --git a/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2.py b/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2.py -index e9aa611..9b97e8c 100644 ---- a/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2.py -+++ b/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2.py -@@ -13,6 +13,7 @@ - # limitations under the License. - - -+import SimpleITK as sitk - from collections import OrderedDict - from typing import Tuple - import sys -@@ -35,12 +36,10 @@ from torch.cuda.amp import autocast - from nnunet.training.learning_rate.poly_lr import poly_lr - from batchgenerators.utilities.file_and_folder_operations import * - -- - class nnUNetPlusPlusTrainerV2(nnUNetTrainer): - """ - Info for Fabian: same as internal nnUNetTrainerV2_2 - """ -- - def __init__(self, plans_file, fold, output_folder=None, dataset_directory=None, batch_dice=True, stage=None, - unpack_data=True, deterministic=True, fp16=False): - super().__init__(plans_file, fold, output_folder, dataset_directory, batch_dice, stage, unpack_data, -@@ -66,7 +65,7 @@ class nnUNetPlusPlusTrainerV2(nnUNetTrainer): - maybe_mkdir_p(self.output_folder) - - if force_load_plans or (self.plans is None): -- self.load_plans_file() -+ self.load_plans_file() # '/data/yupeng/environment_variables/nnUNet_preprocessed/Task003_Liver/nnUNetPlansv2.1_plans_3D.pkl' - - self.process_plans(self.plans) - -@@ -189,6 +188,7 @@ class nnUNetPlusPlusTrainerV2(nnUNetTrainer): - """ - ds = self.network.do_ds - self.network.do_ds = False -+ overwrite = False # 不希望重新跑推理,不然太久了 - ret = super().validate(do_mirroring, use_sliding_window, step_size, save_softmax, use_gaussian, - overwrite, validation_folder_name, debug, all_in_gpu, segmentation_export_kwargs) - -@@ -200,16 +200,18 @@ class nnUNetPlusPlusTrainerV2(nnUNetTrainer): - use_sliding_window: bool = True, step_size: float = 0.5, - use_gaussian: bool = True, pad_border_mode: str = 'constant', - pad_kwargs: dict = None, all_in_gpu: bool = True, -- verbose: bool = True, mixed_precision=True) -> Tuple[np.ndarray, np.ndarray]: -+ verbose: bool = True, mixed_precision=True, img_name=None, -+ pre_mode=None, fp=None) -> Tuple[np.ndarray, np.ndarray]: - """ - We need to wrap this because we need to enforce self.network.do_ds = False for prediction - """ -- ds = self.network.do_ds -+ ds = self.network.do_ds # ds = True - self.network.do_ds = False - ret = super().predict_preprocessed_data_return_seg_and_softmax(data, do_mirroring, mirror_axes, - use_sliding_window, step_size, use_gaussian, - pad_border_mode, pad_kwargs, all_in_gpu, verbose, -- mixed_precision=mixed_precision) -+ mixed_precision=mixed_precision, img_name=img_name, -+ pre_mode=pre_mode, fp=fp) - self.network.do_ds = ds - return ret - -@@ -225,7 +227,20 @@ class nnUNetPlusPlusTrainerV2(nnUNetTrainer): - data_dict = next(data_generator) - data = data_dict['data'] - target = data_dict['target'] -- -+ # i = 0 -+ # while True: -+ # i += 1 -+ # data_dict = next(data_generator) -+ # data = data_dict['data'] -+ # target = data_dict['target'] -+ # data_numpy_output = '/home/yupeng/save_data.nii.gz' -+ # data_numpy = data[0][0].numpy() -+ # target_numpy = target[0][0][0].numpy() -+ # data_1 = data_numpy.flatten() -+ # minm = np.argmin(data_1) -+ # maxm = np.argmax(data_1) -+ # out = sitk.GetImageFromArray(data_numpy) -+ # sitk.WriteImage(out, data_numpy_output) - data = maybe_to_torch(data) - target = maybe_to_torch(target) - -@@ -234,7 +249,6 @@ class nnUNetPlusPlusTrainerV2(nnUNetTrainer): - target = to_cuda(target) - - self.optimizer.zero_grad() -- - if self.fp16: - with autocast(): - output = self.network(data) -@@ -261,7 +275,6 @@ class nnUNetPlusPlusTrainerV2(nnUNetTrainer): - self.run_online_evaluation(output, target) - - del target -- - return l.detach().cpu().numpy() - - def do_split(self): -diff --git a/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2_DDP.py b/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2_DDP.py -new file mode 100644 -index 0000000..e2ab2fa ---- /dev/null -+++ b/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2_DDP.py -@@ -0,0 +1,483 @@ -+# Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany -+# -+# Licensed under the Apache License, Version 2.0 (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# http://www.apache.org/licenses/LICENSE-2.0 -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+ -+ -+from collections import OrderedDict -+from typing import Tuple -+import sys -+import time -+import numpy as np -+import torch -+import torch.distributed as dist -+from torch.cuda.amp import autocast -+from torch.nn.parallel import DistributedDataParallel as DDP -+from nnunet.training.loss_functions.deep_supervision import MultipleOutputLoss2 -+from nnunet.utilities.to_torch import maybe_to_torch, to_cuda -+from nnunet.training.data_augmentation.default_data_augmentation import get_moreDA_augmentation -+from nnunet.network_architecture.generic_UNetPlusPlus import Generic_UNetPlusPlus -+from nnunet.network_architecture.initialization import InitWeights_He -+from nnunet.network_architecture.neural_network import SegmentationNetwork -+from nnunet.training.data_augmentation.default_data_augmentation import default_2D_augmentation_params, \ -+ get_patch_size, default_3D_augmentation_params -+from nnunet.training.dataloading.dataset_loading import unpack_dataset -+from nnunet.training.network_training.nnUNetTrainer import nnUNetTrainer -+from nnunet.utilities.nd_softmax import softmax_helper -+from sklearn.model_selection import KFold -+from torch import nn -+from torch.cuda.amp import autocast -+from nnunet.training.learning_rate.poly_lr import poly_lr -+from batchgenerators.utilities.file_and_folder_operations import * -+ -+ -+class nnUNetPlusPlusTrainerV2_DDP(nnUNetTrainer): -+ """ -+ Info for Fabian: same as internal nnUNetTrainerV2_2 -+ """ -+ -+ def __init__(self, plans_file, fold, local_rank, output_folder=None, dataset_directory=None, batch_dice=True, -+ stage=None, -+ unpack_data=True, deterministic=True, fp16=False, distribute_batch_size=1): -+ super().__init__(plans_file, fold, output_folder, dataset_directory, batch_dice, stage, unpack_data, -+ deterministic, fp16) -+ self.init_args = ( -+ plans_file, fold, local_rank, output_folder, dataset_directory, batch_dice, stage, unpack_data, -+ deterministic, distribute_batch_size, fp16) -+ self.max_num_epochs = 1000 -+ self.initial_lr = 1e-2 -+ self.deep_supervision_scales = None -+ self.ds_loss_weights = None -+ self.distribute_batch_size = distribute_batch_size -+ np.random.seed(local_rank) -+ torch.manual_seed(local_rank) -+ self.local_rank = local_rank -+ if torch.cuda.is_available(): -+ torch.cuda.set_device(local_rank) -+ dist.init_process_group(backend='nccl', init_method='env://') -+ -+ self.pin_memory = True -+ -+ def initialize(self, training=True, force_load_plans=False): -+ """ -+ - replaced get_default_augmentation with get_moreDA_augmentation -+ - enforce to only run this code once -+ - loss function wrapper for deep supervision -+ -+ :param training: -+ :param force_load_plans: -+ :return: -+ """ -+ if not self.was_initialized: -+ maybe_mkdir_p(self.output_folder) -+ -+ if force_load_plans or (self.plans is None): -+ self.load_plans_file() -+ -+ self.process_plans(self.plans) -+ -+ self.setup_DA_params() -+ -+ ################# Here we wrap the loss for deep supervision ############ -+ # we need to know the number of outputs of the network -+ net_numpool = len(self.net_num_pool_op_kernel_sizes) -+ -+ # we give each output a weight which decreases exponentially (division by 2) as the resolution decreases -+ # this gives higher resolution outputs more weight in the loss -+ weights = np.array([1 / (2 ** i) for i in range(net_numpool)]) -+ -+ # we don't use the lowest 2 outputs. Normalize weights so that they sum to 1 -+ mask = np.array([True] + [True if i < net_numpool - 1 else False for i in range(1, net_numpool)]) -+ weights[~mask] = 0 -+ weights = weights / weights.sum() -+ # self.ds_loss_weights = weights -+ self.ds_loss_weights = None -+ # now wrap the loss -+ self.loss = MultipleOutputLoss2(self.loss, self.ds_loss_weights) -+ ################# END ################### -+ -+ self.folder_with_preprocessed_data = join(self.dataset_directory, self.plans['data_identifier'] + -+ "_stage%d" % self.stage) -+ if training: -+ self.dl_tr, self.dl_val = self.get_basic_generators() -+ if self.unpack_data: -+ if self.local_rank == 0: -+ print("unpacking dataset") -+ unpack_dataset(self.folder_with_preprocessed_data) -+ print("done") -+ else: -+ # we need to wait until worker 0 has finished unpacking -+ npz_files = subfiles(self.folder_with_preprocessed_data, suffix=".npz", join=False) -+ case_ids = [i[:-4] for i in npz_files] -+ all_present = all( -+ [isfile(join(self.folder_with_preprocessed_data, i + ".npy")) for i in case_ids]) -+ while not all_present: -+ print("worker", self.local_rank, "is waiting for unpacking") -+ time.sleep(3) -+ all_present = all( -+ [isfile(join(self.folder_with_preprocessed_data, i + ".npy")) for i in case_ids]) -+ # there is some slight chance that there may arise some error because dataloader are loading a file -+ # that is still being written by worker 0. We ignore this for now an address it only if it becomes -+ # relevant -+ # (this can occur because while worker 0 writes the file is technically present so the other workers -+ # will proceed and eventually try to read it) -+ else: -+ print( -+ "INFO: Not unpacking data! Training may be slow due to that. Pray you are not using 2d or you " -+ "will wait all winter for your model to finish!") -+ -+ self.tr_gen, self.val_gen = get_moreDA_augmentation( -+ self.dl_tr, self.dl_val, -+ self.data_aug_params[ -+ 'patch_size_for_spatialtransform'], -+ self.data_aug_params, -+ deep_supervision_scales=self.deep_supervision_scales, -+ pin_memory=self.pin_memory -+ ) -+ self.print_to_log_file("TRAINING KEYS:\n %s" % (str(self.dataset_tr.keys())), -+ also_print_to_console=False) -+ self.print_to_log_file("VALIDATION KEYS:\n %s" % (str(self.dataset_val.keys())), -+ also_print_to_console=False) -+ else: -+ pass -+ -+ self.initialize_network() -+ self.initialize_optimizer_and_scheduler() -+ -+ assert isinstance(self.network, (SegmentationNetwork, DDP)) -+ else: -+ self.print_to_log_file('self.was_initialized is True, not running self.initialize again') -+ self.was_initialized = True -+ -+ def initialize_network(self): -+ """ -+ - momentum 0.99 -+ - SGD instead of Adam -+ - self.lr_scheduler = None because we do poly_lr -+ - deep supervision = True -+ - i am sure I forgot something here -+ -+ Known issue: forgot to set neg_slope=0 in InitWeights_He; should not make a difference though -+ :return: -+ """ -+ if self.threeD: -+ conv_op = nn.Conv3d -+ dropout_op = nn.Dropout3d -+ norm_op = nn.InstanceNorm3d -+ -+ else: -+ conv_op = nn.Conv2d -+ dropout_op = nn.Dropout2d -+ norm_op = nn.InstanceNorm2d -+ norm_op_kwargs = {'eps': 1e-5, 'affine': True} -+ dropout_op_kwargs = {'p': 0, 'inplace': True} -+ net_nonlin = nn.LeakyReLU -+ net_nonlin_kwargs = {'negative_slope': 1e-2, 'inplace': True} -+ self.network = Generic_UNetPlusPlus(self.num_input_channels, self.base_num_features, self.num_classes, -+ len(self.net_num_pool_op_kernel_sizes), -+ self.conv_per_stage, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, -+ dropout_op_kwargs, -+ net_nonlin, net_nonlin_kwargs, True, False, lambda x: x, -+ InitWeights_He(1e-2), -+ self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, -+ True) -+ if torch.cuda.is_available(): -+ self.network.cuda() -+ self.network.inference_apply_nonlin = softmax_helper -+ self.network = DDP(self.network, device_ids=[self.local_rank], find_unused_parameters=True) -+ -+ # self.network = DDP(self.network, device_ids=[self.local_rank], find_unused_parameters=True) -+ -+ def initialize_optimizer_and_scheduler(self): -+ assert self.network is not None, "self.initialize_network must be called first" -+ print('weight_decay: ', self.weight_decay) -+ sys.stdout.flush() -+ self.optimizer = torch.optim.SGD(self.network.parameters(), self.initial_lr, weight_decay=self.weight_decay, -+ momentum=0.99, nesterov=True) -+ self.lr_scheduler = None -+ -+ def run_online_evaluation(self, output, target): -+ """ -+ due to deep supervision the return value and the reference are now lists of tensors. We only need the full -+ resolution output because this is what we are interested in in the end. The others are ignored -+ :param output: -+ :param target: -+ :return: -+ """ -+ target = target[0] -+ output = output[0] -+ return super().run_online_evaluation(output, target) -+ -+ def validate(self, do_mirroring: bool = True, use_sliding_window: bool = True, -+ step_size: float = 0.5, save_softmax: bool = True, use_gaussian: bool = True, overwrite: bool = True, -+ validation_folder_name: str = 'validation_raw', debug: bool = False, all_in_gpu: bool = False, -+ segmentation_export_kwargs: dict = None): -+ """ -+ We need to wrap this because we need to enforce self.network.do_ds = False for prediction -+ """ -+ if self.local_rank == 0: -+ if isinstance(self.network, DDP): -+ net = self.network.module -+ else: -+ net = self.network -+ ds = self.network.do_ds -+ net.do_ds = False -+ ret = super().validate(do_mirroring, use_sliding_window, step_size, save_softmax, use_gaussian, -+ overwrite, validation_folder_name, debug, all_in_gpu, segmentation_export_kwargs) -+ -+ net.do_ds = ds -+ return ret -+ -+ def predict_preprocessed_data_return_seg_and_softmax(self, data: np.ndarray, do_mirroring: bool = True, -+ mirror_axes: Tuple[int] = None, -+ use_sliding_window: bool = True, step_size: float = 0.5, -+ use_gaussian: bool = True, pad_border_mode: str = 'constant', -+ pad_kwargs: dict = None, all_in_gpu: bool = True, -+ verbose: bool = True, mixed_precision=True) -> Tuple[ -+ np.ndarray, np.ndarray]: -+ """ -+ We need to wrap this because we need to enforce self.network.do_ds = False for prediction -+ """ -+ ds = self.network.do_ds -+ self.network.do_ds = False -+ ret = super().predict_preprocessed_data_return_seg_and_softmax(data, do_mirroring, mirror_axes, -+ use_sliding_window, step_size, use_gaussian, -+ pad_border_mode, pad_kwargs, all_in_gpu, verbose, -+ mixed_precision=mixed_precision) -+ self.network.do_ds = ds -+ return ret -+ -+ def run_iteration(self, data_generator, do_backprop=True, run_online_evaluation=False): -+ """ -+ gradient clipping improves training stability -+ -+ :param data_generator: -+ :param do_backprop: -+ :param run_online_evaluation: -+ :return: -+ """ -+ data_dict = next(data_generator) -+ data = data_dict['data'] -+ target = data_dict['target'] -+ -+ data = maybe_to_torch(data) -+ target = maybe_to_torch(target) -+ -+ if torch.cuda.is_available(): -+ data = to_cuda(data, gpu_id=None) -+ target = to_cuda(target, gpu_id=None) -+ -+ self.optimizer.zero_grad() -+ -+ if self.fp16: -+ with autocast(): -+ output = self.network(data) -+ del data -+ l = self.loss(output, target) -+ -+ if do_backprop: -+ self.amp_grad_scaler.scale(l).backward() -+ self.amp_grad_scaler.unscale_(self.optimizer) -+ torch.nn.utils.clip_grad_norm_(self.network.parameters(), 12) -+ self.amp_grad_scaler.step(self.optimizer) -+ self.amp_grad_scaler.update() -+ else: -+ output = self.network(data) -+ del data -+ l = self.loss(output, target) -+ -+ if do_backprop: -+ l.backward() -+ torch.nn.utils.clip_grad_norm_(self.network.parameters(), 12) -+ self.optimizer.step() -+ -+ if run_online_evaluation: -+ self.run_online_evaluation(output, target) -+ -+ del target -+ -+ return l.detach().cpu().numpy() -+ -+ def do_split(self): -+ """ -+ we now allow more than 5 splits. IMPORTANT: and fold > 4 will not be a real split but just another random -+ 80:20 split of the data. You cannot run X-fold cross-validation with this code. It will always be a 5-fold CV. -+ Folds > 4 will be independent from each other -+ :return: -+ """ -+ if self.fold == "all": -+ # if fold==all then we use all images for training and validation -+ tr_keys = val_keys = list(self.dataset.keys()) -+ else: -+ splits_file = join(self.dataset_directory, "splits_final.pkl") -+ -+ # if the split file does not exist we need to create it -+ if not isfile(splits_file): -+ self.print_to_log_file("Creating new split...") -+ splits = [] -+ all_keys_sorted = np.sort(list(self.dataset.keys())) -+ kfold = KFold(n_splits=5, shuffle=True, random_state=12345) -+ for i, (train_idx, test_idx) in enumerate(kfold.split(all_keys_sorted)): -+ train_keys = np.array(all_keys_sorted)[train_idx] -+ test_keys = np.array(all_keys_sorted)[test_idx] -+ splits.append(OrderedDict()) -+ splits[-1]['train'] = train_keys -+ splits[-1]['val'] = test_keys -+ save_pickle(splits, splits_file) -+ -+ splits = load_pickle(splits_file) -+ -+ if self.fold < len(splits): -+ tr_keys = splits[self.fold]['train'] -+ val_keys = splits[self.fold]['val'] -+ else: -+ self.print_to_log_file("INFO: Requested fold %d but split file only has %d folds. I am now creating a " -+ "random 80:20 split!" % (self.fold, len(splits))) -+ # if we request a fold that is not in the split file, create a random 80:20 split -+ rnd = np.random.RandomState(seed=12345 + self.fold) -+ keys = np.sort(list(self.dataset.keys())) -+ idx_tr = rnd.choice(len(keys), int(len(keys) * 0.8), replace=False) -+ idx_val = [i for i in range(len(keys)) if i not in idx_tr] -+ tr_keys = [keys[i] for i in idx_tr] -+ val_keys = [keys[i] for i in idx_val] -+ -+ tr_keys.sort() -+ val_keys.sort() -+ self.dataset_tr = OrderedDict() -+ for i in tr_keys: -+ self.dataset_tr[i] = self.dataset[i] -+ self.dataset_val = OrderedDict() -+ for i in val_keys: -+ self.dataset_val[i] = self.dataset[i] -+ -+ def setup_DA_params(self): -+ """ -+ - we increase roation angle from [-15, 15] to [-30, 30] -+ - scale range is now (0.7, 1.4), was (0.85, 1.25) -+ - we don't do elastic deformation anymore -+ -+ :return: -+ """ -+ -+ self.deep_supervision_scales = [[1, 1, 1]] + list(list(i) for i in 1 / np.cumprod( -+ np.vstack(self.net_num_pool_op_kernel_sizes), axis=0))[:-1] -+ -+ if self.threeD: -+ self.data_aug_params = default_3D_augmentation_params -+ self.data_aug_params['rotation_x'] = (-30. / 360 * 2. * np.pi, 30. / 360 * 2. * np.pi) -+ self.data_aug_params['rotation_y'] = (-30. / 360 * 2. * np.pi, 30. / 360 * 2. * np.pi) -+ self.data_aug_params['rotation_z'] = (-30. / 360 * 2. * np.pi, 30. / 360 * 2. * np.pi) -+ if self.do_dummy_2D_aug: -+ self.data_aug_params["dummy_2D"] = True -+ self.print_to_log_file("Using dummy2d data augmentation") -+ self.data_aug_params["elastic_deform_alpha"] = \ -+ default_2D_augmentation_params["elastic_deform_alpha"] -+ self.data_aug_params["elastic_deform_sigma"] = \ -+ default_2D_augmentation_params["elastic_deform_sigma"] -+ self.data_aug_params["rotation_x"] = default_2D_augmentation_params["rotation_x"] -+ else: -+ self.do_dummy_2D_aug = False -+ if max(self.patch_size) / min(self.patch_size) > 1.5: -+ default_2D_augmentation_params['rotation_x'] = (-15. / 360 * 2. * np.pi, 15. / 360 * 2. * np.pi) -+ self.data_aug_params = default_2D_augmentation_params -+ self.data_aug_params["mask_was_used_for_normalization"] = self.use_mask_for_norm -+ -+ if self.do_dummy_2D_aug: -+ self.basic_generator_patch_size = get_patch_size(self.patch_size[1:], -+ self.data_aug_params['rotation_x'], -+ self.data_aug_params['rotation_y'], -+ self.data_aug_params['rotation_z'], -+ self.data_aug_params['scale_range']) -+ self.basic_generator_patch_size = np.array([self.patch_size[0]] + list(self.basic_generator_patch_size)) -+ patch_size_for_spatialtransform = self.patch_size[1:] -+ else: -+ self.basic_generator_patch_size = get_patch_size(self.patch_size, self.data_aug_params['rotation_x'], -+ self.data_aug_params['rotation_y'], -+ self.data_aug_params['rotation_z'], -+ self.data_aug_params['scale_range']) -+ patch_size_for_spatialtransform = self.patch_size -+ -+ self.data_aug_params["scale_range"] = (0.7, 1.4) -+ self.data_aug_params["do_elastic"] = False -+ self.data_aug_params['selected_seg_channels'] = [0] -+ self.data_aug_params['patch_size_for_spatialtransform'] = patch_size_for_spatialtransform -+ -+ self.data_aug_params["num_cached_per_thread"] = 2 -+ -+ def maybe_update_lr(self, epoch=None): -+ """ -+ if epoch is not None we overwrite epoch. Else we use epoch = self.epoch + 1 -+ -+ (maybe_update_lr is called in on_epoch_end which is called before epoch is incremented. -+ herefore we need to do +1 here) -+ -+ :param epoch: -+ :return: -+ """ -+ if epoch is None: -+ ep = self.epoch + 1 -+ else: -+ ep = epoch -+ self.optimizer.param_groups[0]['lr'] = poly_lr(ep, self.max_num_epochs, self.initial_lr, 0.9) -+ self.print_to_log_file("lr:", np.round(self.optimizer.param_groups[0]['lr'], decimals=6)) -+ -+ def on_epoch_end(self): -+ """ -+ overwrite patient-based early stopping. Always run to 1000 epochs -+ :return: -+ """ -+ super().on_epoch_end() -+ continue_training = self.epoch < self.max_num_epochs -+ -+ # it can rarely happen that the momentum of nnUNetTrainerV2_plus is too high for some dataset. If at epoch 100 the -+ # estimated validation Dice is still 0 then we reduce the momentum from 0.99 to 0.95 -+ if self.epoch == 100: -+ if self.all_val_eval_metrics[-1] == 0: -+ self.optimizer.param_groups[0]["momentum"] = 0.95 -+ self.network.apply(InitWeights_He(1e-2)) -+ self.print_to_log_file("At epoch 100, the mean foreground Dice was 0. This can be caused by a too " -+ "high momentum. High momentum (0.99) is good for datasets where it works, but " -+ "sometimes causes issues such as this one. Momentum has now been reduced to " -+ "0.95 and network weights have been reinitialized") -+ return continue_training -+ -+ def save_checkpoint(self, fname, save_optimizer=True): -+ if self.local_rank == 0: -+ super().save_checkpoint(fname, save_optimizer) -+ -+ def plot_progress(self): -+ if self.local_rank == 0: -+ super().plot_progress() -+ -+ def print_to_log_file(self, *args, also_print_to_console=True): -+ if self.local_rank == 0: -+ super().print_to_log_file(*args, also_print_to_console=also_print_to_console) -+ -+ def run_training(self): -+ """ -+ if we run with -c then we need to set the correct lr for the first epoch, otherwise it will run the first -+ continued epoch with self.initial_lr -+ -+ we also need to make sure deep supervision in the network is enabled for training, thus the wrapper -+ :return: -+ """ -+ self.maybe_update_lr(self.epoch) # if we dont overwrite epoch then self.epoch+1 is used which is not what we -+ # want at the start of the training -+ if isinstance(self.network, DDP): -+ net = self.network.module -+ else: -+ net = self.network -+ ds = net.do_ds -+ net.do_ds = True -+ ret = super().run_training() -+ net.do_ds = ds -+ return ret ++ def print_to_log_file(self, *args, also_print_to_console=True): ++ if self.local_rank == 0: ++ super().print_to_log_file(*args, also_print_to_console=also_print_to_console) ++ ++ def run_training(self): ++ """ ++ if we run with -c then we need to set the correct lr for the first epoch, otherwise it will run the first ++ continued epoch with self.initial_lr ++ ++ we also need to make sure deep supervision in the network is enabled for training, thus the wrapper ++ :return: ++ """ ++ self.maybe_update_lr(self.epoch) # if we dont overwrite epoch then self.epoch+1 is used which is not what we ++ # want at the start of the training ++ if isinstance(self.network, DDP): ++ net = self.network.module ++ else: ++ net = self.network ++ ds = net.do_ds ++ net.do_ds = True ++ ret = super().run_training() ++ net.do_ds = ds ++ return ret diff --git a/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2_hypDDP.py b/pytorch/nnunet/training/network_training/nnUNetPlusPlusTrainerV2_hypDDP.py new file mode 100644 index 0000000..aab27fe @@ -4219,11 +4219,11 @@ index 0000000..0abb8d5 --- /dev/null +++ b/pytorch/run.sh @@ -0,0 +1,5 @@ -+python nnunet/run/run_training.py 3d_fullres nnUNetPlusPlusTrainerV2_DDP Task003_Liver 0 -+ -+ -+python -m torch.distributed.launch --nproc_per_node 2 nnunet/run/run_training_DDP.py 3d_fullres nnUNetPlusPlusTrainerV2_DDP Task003_Liver 0 -+ ++python nnunet/run/run_training.py 3d_fullres nnUNetPlusPlusTrainerV2_DDP Task003_Liver 0 ++ ++ ++python -m torch.distributed.launch --nproc_per_node 2 nnunet/run/run_training_DDP.py 3d_fullres nnUNetPlusPlusTrainerV2_DDP Task003_Liver 0 ++ diff --git a/pytorch/setup.py b/pytorch/setup.py index 590a453..554f4e2 100644 --- a/pytorch/setup.py diff --git a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/LICENSE b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/LICENSE +++ b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/README.md b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/README.md index 79d756e61d7fe97728e8b47a238aae3b15ca4528..6991aba00b4d13e6009e5f7f4ec17dd14117ff86 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/README.md +++ b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/README.md @@ -1,83 +1,83 @@ -# DeeplabV3 模型PyTorch离线推理指导 -## 推理 -### 环境配置 -```shell -pip install -r requirements.txt -pip install mmcv-full==1.3.15 -git clone https://github.com/open-mmlab/mmsegmentation.git -cd mmsegmentation -git checkout fa1554f1aaea9a2c58249b06e1ea48420091464d -pip install -e . -cd .. -``` - - -### 转ONNX -[下载权重](https://github.com/open-mmlab/mmsegmentation/tree/master/configs/deeplabv3) - -* README.md文件中配置第一行最后一列model - -#### 转onnx - -```shell -python mmsegmentation/tools/pytorch2onnx.py \ -mmsegmentation/configs/deeplabv3/deeplabv3_r50-d8_512x1024_40k_cityscapes.py \ ---checkpoint ./deeplabv3_r50-d8_512x1024_40k_cityscapes_20200605_022449-acadc2f8.pth \ ---output-file deeplabv3.onnx --shape 1024 2048 -``` - -#### 使用onnx-simplifier简化onnx - -```python -python -m onnxsim deeplabv3.onnx deeplabv3_sim_bs1.onnx --input-shape="1,3,1024,2048" --dynamic-input-shape -``` - -### 转OM - -```shell -source env_npu.sh -atc --framework=5 --model=deeplabv3_sim_bs1.onnx --output=deeplabv3_bs1 --input_format=NCHW \ ---input_shape="input:1,3,1024,2048" --log=debug --soc_version=Ascend310 --auto_tune_mode="RL,GA" -``` - - -### 数据预处理 -#### 前处理处理脚本 ./deeplabv3_torch_preprocess.py - -```shell -python ./deeplabv3_torch_preprocess.py /opt/npu/cityscapes/leftImg8bit/val ./prep_dataset -``` -读取./data/citiscapes/gtFine/val下的500张用于验证的图片,处理后保存为bin格式 - - -#### 获取数据集信息文件 - -```shell -python ./gen_dataset_info.py bin ./prep_dataset ./deeplabv3_prep_bin.info 1024 2048 -``` - -### 离线推理 - -将benchmark.x86_64放到目录 - -```shell -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=deeplabv3_bs1.om \ --input_text_path=./deeplabv3_prep_bin.info \ --input_width=1024 \ --input_height=2048 \ --output_binary=True \ --useDvpp=False -``` - -### 数据后处理 - -```shell -python ./deeplabv3_torch_postprocess.py --output_path=./result/dumpOutput_device0 --gt_path=/opt/npu/cityscapes/gtFine/val -``` - - -### 评测结果 - -| 模型 | 官网精度 | 310精度 | T4性能 | 310性能 | -| ---------- | --------------------- | -------------| --------- | --------- | +# DeeplabV3 模型PyTorch离线推理指导 +## 推理 +### 环境配置 +```shell +pip install -r requirements.txt +pip install mmcv-full==1.3.15 +git clone https://github.com/open-mmlab/mmsegmentation.git +cd mmsegmentation +git checkout fa1554f1aaea9a2c58249b06e1ea48420091464d +pip install -e . +cd .. +``` + + +### 转ONNX +[下载权重](https://github.com/open-mmlab/mmsegmentation/tree/master/configs/deeplabv3) + +* README.md文件中配置第一行最后一列model + +#### 转onnx + +```shell +python mmsegmentation/tools/pytorch2onnx.py \ +mmsegmentation/configs/deeplabv3/deeplabv3_r50-d8_512x1024_40k_cityscapes.py \ +--checkpoint ./deeplabv3_r50-d8_512x1024_40k_cityscapes_20200605_022449-acadc2f8.pth \ +--output-file deeplabv3.onnx --shape 1024 2048 +``` + +#### 使用onnx-simplifier简化onnx + +```python +python -m onnxsim deeplabv3.onnx deeplabv3_sim_bs1.onnx --input-shape="1,3,1024,2048" --dynamic-input-shape +``` + +### 转OM + +```shell +source env_npu.sh +atc --framework=5 --model=deeplabv3_sim_bs1.onnx --output=deeplabv3_bs1 --input_format=NCHW \ +--input_shape="input:1,3,1024,2048" --log=debug --soc_version=Ascend310 --auto_tune_mode="RL,GA" +``` + + +### 数据预处理 +#### 前处理处理脚本 ./deeplabv3_torch_preprocess.py + +```shell +python ./deeplabv3_torch_preprocess.py /opt/npu/cityscapes/leftImg8bit/val ./prep_dataset +``` +读取./data/citiscapes/gtFine/val下的500张用于验证的图片,处理后保存为bin格式 + + +#### 获取数据集信息文件 + +```shell +python ./gen_dataset_info.py bin ./prep_dataset ./deeplabv3_prep_bin.info 1024 2048 +``` + +### 离线推理 + +将benchmark.x86_64放到目录 + +```shell +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=deeplabv3_bs1.om \ +-input_text_path=./deeplabv3_prep_bin.info \ +-input_width=1024 \ +-input_height=2048 \ +-output_binary=True \ +-useDvpp=False +``` + +### 数据后处理 + +```shell +python ./deeplabv3_torch_postprocess.py --output_path=./result/dumpOutput_device0 --gt_path=/opt/npu/cityscapes/gtFine/val +``` + + +### 评测结果 + +| 模型 | 官网精度 | 310精度 | T4性能 | 310性能 | +| ---------- | --------------------- | -------------| --------- | --------- | | deeplabv3_bs1 | mIoU 79.09 | mIoU 79.06 | 5.7787FPS | 3.1675FPS | \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/deeplabv3_torch_postprocess.py b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/deeplabv3_torch_postprocess.py index f5f2c83522cd2762e4c0a75037e29dbf063161b7..1b818b8ccaadcc238e21a67d0f8ac8003f39ef80 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/deeplabv3_torch_postprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/deeplabv3_torch_postprocess.py @@ -1,230 +1,230 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import numpy as np -import torch -import argparse -import os -from PIL import Image - - -class GTFineFile(object): - """ - directory: path to gtFine - suffix: suffix of the gtFine - :return path List of gtFine files - """ - def __init__(self, directory, suffix='_gtFine_labelTrainIds.png'): - gtFine_list = [] - for root, sub_dirs, files in os.walk(directory): - for special_file in files: - if special_file.endswith(suffix): - gtFine_list.append(os.path.join(root, special_file)) - self.gtFine_list = gtFine_list - - def get_file(self, filename): - """ return file path list """ - for file in self.gtFine_list: - if file.endswith(filename): - return file - - -def intersect_and_union(pred_label, - label, - num_classes, - ignore_index, - label_map=dict(), - reduce_zero_label=False): - """Calculate intersection and Union. - - Args: - pred_label (ndarray | str): Prediction segmentation map - or predict result filename. - label (ndarray): Ground truth segmentation map. - num_classes (int): Number of categories. - ignore_index (int): Index that will be ignored in evaluation. - label_map (dict): Mapping old labels to new labels. The parameter will - work only when label is str. Default: dict(). - reduce_zero_label (bool): Wether ignore zero label. The parameter will - work only when label is str. Default: False. - - Returns: - torch.Tensor: The intersection of prediction and ground truth - histogram on all classes. - torch.Tensor: The union of prediction and ground truth histogram on - all classes. - torch.Tensor: The prediction histogram on all classes. - torch.Tensor: The ground truth histogram on all classes. - """ - - if isinstance(pred_label, str): - pred_label = torch.from_numpy(np.load(pred_label)) - else: - pred_label = torch.from_numpy((pred_label)) - - label = torch.from_numpy(label) - - if label_map is not None: - for old_id, new_id in label_map.items(): - label[label == old_id] = new_id - if reduce_zero_label: - label[label == 0] = 255 - label = label - 1 - label[label == 254] = 255 - - mask = (label != ignore_index) - pred_label = pred_label[mask] - label = label[mask] - - intersect = pred_label[pred_label == label] - area_intersect = torch.histc( - intersect.float(), bins=(num_classes), min=0, max=num_classes - 1) - area_pred_label = torch.histc( - pred_label.float(), bins=(num_classes), min=0, max=num_classes - 1) - area_label = torch.histc( - label.float(), bins=(num_classes), min=0, max=num_classes - 1) - area_union = area_pred_label + area_label - area_intersect - return [area_intersect, area_union, area_pred_label, area_label] - - -class IntersectAndUnion(object): - """Calculate Total Intersection and Union. - - Args: - results (list[ndarray] | list[str]): List of prediction segmentation - maps or list of prediction result filenames. - gt_seg_maps (list[ndarray] | list[str]): list of ground truth - segmentation maps or list of label filenames. - num_classes (int): Number of categories. - ignore_index (int): Index that will be ignored in evaluation. - label_map (dict): Mapping old labels to new labels. Default: dict(). - reduce_zero_label (bool): Wether ignore zero label. Default: False. - - Returns: - iou - acc - """ - - def __init__(self, num_classes, ignore_index, label_map=dict(), reduce_zero_label=False): - self.num_classes = num_classes - self.ignore_index = ignore_index - self.label_map = label_map - self.reduce_zero_label = reduce_zero_label - self.total_area_intersect = torch.zeros((num_classes,), dtype=torch.float64) - self.total_area_union = torch.zeros((num_classes,), dtype=torch.float64) - self.total_area_pred_label = torch.zeros((num_classes,), dtype=torch.float64) - self.total_area_label = torch.zeros((num_classes,), dtype=torch.float64) - - def update(self, output, gt_seg_map): - """ update """ - [area_intersect, area_union, area_pred_label, area_label] = \ - intersect_and_union( - output, gt_seg_map, self.num_classes, self.ignore_index, - self.label_map, self.reduce_zero_label) - self.total_area_intersect += area_intersect.to(torch.float64) - self.total_area_union += area_union.to(torch.float64) - self.total_area_pred_label += area_pred_label.to(torch.float64) - self.total_area_label += area_label.to(torch.float64) - - def get(self): - """ get result """ - iou = self.total_area_intersect / self.total_area_union - acc = self.total_area_intersect / self.total_area_label - all_acc = self.total_area_intersect.sum() / self.total_area_label.sum() - mIoU = np.round(np.nanmean(iou) * 100, 2) - aAcc = np.round(np.nanmean(all_acc) * 100, 2) - return {'aAcc': aAcc, 'mIoU': mIoU} - - -def eval_metrics(output_path, - gt_path, - out_suffix='_leftImg8bit_1.bin', - gt_suffix='_gtFine_labelTrainIds.png', - result_path='./postprocess_result', - num_classes=19, - ignore_index=255, - label_map=None, - reduce_zero_label=False): - """Calculate evaluation metrics - Args: - results (list[ndarray] | list[str]): List of prediction segmentation - maps or list of prediction result filenames. - gt_seg_maps (list[ndarray] | list[str]): list of ground truth - segmentation maps or list of label filenames. - num_classes (int): Number of categories. - ignore_index (int): Index that will be ignored in evaluation. - metrics (list[str] | str): Metrics to be evaluated, 'mIoU' and 'mDice'. - nan_to_num (int, optional): If specified, NaN values will be replaced - by the numbers defined by the user. Default: None. - label_map (dict): Mapping old labels to new labels. Default: dict(). - reduce_zero_label (bool): Wether ignore zero label. Default: False. - Returns: - float: Overall accuracy on all images. - ndarray: Per category accuracy, shape (num_classes, ). - ndarray: Per category evaluation metrics, shape (num_classes, ). - """ - - # init metric - metric = IntersectAndUnion(num_classes, ignore_index, label_map, reduce_zero_label) - # init gtFine files list - fileFinder = GTFineFile(gt_path) - - for root, sub_dirs, files in os.walk(output_path): - files = [file for file in files if file.endswith('bin')] - len = str(files.__len__()) - for i, output_name in enumerate(files): - if not output_name.endswith('bin'): - continue - print('DeeplabV3 metric [' + str(i + 1) + '/' + len + '] on process: ' + output_name) - seg_map_name = output_name.replace(out_suffix, gt_suffix) - seg_map_path = fileFinder.get_file(seg_map_name) - if seg_map_name is not None: - seg_map = Image.open(seg_map_path) - seg_map = np.array(seg_map, dtype=np.uint8) - - output_path = os.path.realpath(os.path.join(root, output_name)) - output = np.fromfile(output_path, dtype=np.uint64).reshape(1024, 2048) - output = output.astype(np.uint8) - metric.update(output, seg_map) - else: - print("[ERROR] " + seg_map_name + " not find, check the file or make sure --out_suffix") - - # get result - result = metric.get() - print(result) - with open(result_path + '.txt', 'w') as f: - f.write('aAcc: {}\n'.format(result['aAcc'])) - f.write('mIoU: {}\n'.format(result['mIoU'])) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser('mIoU calculate') - parser.add_argument('--output_path', default="./result", - help='path to om/onnx output file, default ./result') - parser.add_argument('--gt_path', default="/opt/npu/cityscapes/gtFine/val", - help='path to gtFine/val, default /opt/npu/cityscapes/gtFine/val') - parser.add_argument('--out_suffix', default="_leftImg8bit_1.bin", - help='suffix of the om/onnx output, default "_leftImg8bit_1.bin"') - parser.add_argument('--result_path', default="./postprocess_result", - help='path to save the script result, default ./postprocess_result.txt') - - args = parser.parse_args() - - output_path = os.path.realpath(args.output_path) - gt_path = os.path.realpath(args.gt_path) - out_suffix = args.out_suffix - result_path = os.path.realpath(args.result_path) - print(output_path) - print(gt_path) - eval_metrics(output_path, gt_path, out_suffix=out_suffix, result_path=result_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +import torch +import argparse +import os +from PIL import Image + + +class GTFineFile(object): + """ + directory: path to gtFine + suffix: suffix of the gtFine + :return path List of gtFine files + """ + def __init__(self, directory, suffix='_gtFine_labelTrainIds.png'): + gtFine_list = [] + for root, sub_dirs, files in os.walk(directory): + for special_file in files: + if special_file.endswith(suffix): + gtFine_list.append(os.path.join(root, special_file)) + self.gtFine_list = gtFine_list + + def get_file(self, filename): + """ return file path list """ + for file in self.gtFine_list: + if file.endswith(filename): + return file + + +def intersect_and_union(pred_label, + label, + num_classes, + ignore_index, + label_map=dict(), + reduce_zero_label=False): + """Calculate intersection and Union. + + Args: + pred_label (ndarray | str): Prediction segmentation map + or predict result filename. + label (ndarray): Ground truth segmentation map. + num_classes (int): Number of categories. + ignore_index (int): Index that will be ignored in evaluation. + label_map (dict): Mapping old labels to new labels. The parameter will + work only when label is str. Default: dict(). + reduce_zero_label (bool): Wether ignore zero label. The parameter will + work only when label is str. Default: False. + + Returns: + torch.Tensor: The intersection of prediction and ground truth + histogram on all classes. + torch.Tensor: The union of prediction and ground truth histogram on + all classes. + torch.Tensor: The prediction histogram on all classes. + torch.Tensor: The ground truth histogram on all classes. + """ + + if isinstance(pred_label, str): + pred_label = torch.from_numpy(np.load(pred_label)) + else: + pred_label = torch.from_numpy((pred_label)) + + label = torch.from_numpy(label) + + if label_map is not None: + for old_id, new_id in label_map.items(): + label[label == old_id] = new_id + if reduce_zero_label: + label[label == 0] = 255 + label = label - 1 + label[label == 254] = 255 + + mask = (label != ignore_index) + pred_label = pred_label[mask] + label = label[mask] + + intersect = pred_label[pred_label == label] + area_intersect = torch.histc( + intersect.float(), bins=(num_classes), min=0, max=num_classes - 1) + area_pred_label = torch.histc( + pred_label.float(), bins=(num_classes), min=0, max=num_classes - 1) + area_label = torch.histc( + label.float(), bins=(num_classes), min=0, max=num_classes - 1) + area_union = area_pred_label + area_label - area_intersect + return [area_intersect, area_union, area_pred_label, area_label] + + +class IntersectAndUnion(object): + """Calculate Total Intersection and Union. + + Args: + results (list[ndarray] | list[str]): List of prediction segmentation + maps or list of prediction result filenames. + gt_seg_maps (list[ndarray] | list[str]): list of ground truth + segmentation maps or list of label filenames. + num_classes (int): Number of categories. + ignore_index (int): Index that will be ignored in evaluation. + label_map (dict): Mapping old labels to new labels. Default: dict(). + reduce_zero_label (bool): Wether ignore zero label. Default: False. + + Returns: + iou + acc + """ + + def __init__(self, num_classes, ignore_index, label_map=dict(), reduce_zero_label=False): + self.num_classes = num_classes + self.ignore_index = ignore_index + self.label_map = label_map + self.reduce_zero_label = reduce_zero_label + self.total_area_intersect = torch.zeros((num_classes,), dtype=torch.float64) + self.total_area_union = torch.zeros((num_classes,), dtype=torch.float64) + self.total_area_pred_label = torch.zeros((num_classes,), dtype=torch.float64) + self.total_area_label = torch.zeros((num_classes,), dtype=torch.float64) + + def update(self, output, gt_seg_map): + """ update """ + [area_intersect, area_union, area_pred_label, area_label] = \ + intersect_and_union( + output, gt_seg_map, self.num_classes, self.ignore_index, + self.label_map, self.reduce_zero_label) + self.total_area_intersect += area_intersect.to(torch.float64) + self.total_area_union += area_union.to(torch.float64) + self.total_area_pred_label += area_pred_label.to(torch.float64) + self.total_area_label += area_label.to(torch.float64) + + def get(self): + """ get result """ + iou = self.total_area_intersect / self.total_area_union + acc = self.total_area_intersect / self.total_area_label + all_acc = self.total_area_intersect.sum() / self.total_area_label.sum() + mIoU = np.round(np.nanmean(iou) * 100, 2) + aAcc = np.round(np.nanmean(all_acc) * 100, 2) + return {'aAcc': aAcc, 'mIoU': mIoU} + + +def eval_metrics(output_path, + gt_path, + out_suffix='_leftImg8bit_1.bin', + gt_suffix='_gtFine_labelTrainIds.png', + result_path='./postprocess_result', + num_classes=19, + ignore_index=255, + label_map=None, + reduce_zero_label=False): + """Calculate evaluation metrics + Args: + results (list[ndarray] | list[str]): List of prediction segmentation + maps or list of prediction result filenames. + gt_seg_maps (list[ndarray] | list[str]): list of ground truth + segmentation maps or list of label filenames. + num_classes (int): Number of categories. + ignore_index (int): Index that will be ignored in evaluation. + metrics (list[str] | str): Metrics to be evaluated, 'mIoU' and 'mDice'. + nan_to_num (int, optional): If specified, NaN values will be replaced + by the numbers defined by the user. Default: None. + label_map (dict): Mapping old labels to new labels. Default: dict(). + reduce_zero_label (bool): Wether ignore zero label. Default: False. + Returns: + float: Overall accuracy on all images. + ndarray: Per category accuracy, shape (num_classes, ). + ndarray: Per category evaluation metrics, shape (num_classes, ). + """ + + # init metric + metric = IntersectAndUnion(num_classes, ignore_index, label_map, reduce_zero_label) + # init gtFine files list + fileFinder = GTFineFile(gt_path) + + for root, sub_dirs, files in os.walk(output_path): + files = [file for file in files if file.endswith('bin')] + len = str(files.__len__()) + for i, output_name in enumerate(files): + if not output_name.endswith('bin'): + continue + print('DeeplabV3 metric [' + str(i + 1) + '/' + len + '] on process: ' + output_name) + seg_map_name = output_name.replace(out_suffix, gt_suffix) + seg_map_path = fileFinder.get_file(seg_map_name) + if seg_map_name is not None: + seg_map = Image.open(seg_map_path) + seg_map = np.array(seg_map, dtype=np.uint8) + + output_path = os.path.realpath(os.path.join(root, output_name)) + output = np.fromfile(output_path, dtype=np.uint64).reshape(1024, 2048) + output = output.astype(np.uint8) + metric.update(output, seg_map) + else: + print("[ERROR] " + seg_map_name + " not find, check the file or make sure --out_suffix") + + # get result + result = metric.get() + print(result) + with open(result_path + '.txt', 'w') as f: + f.write('aAcc: {}\n'.format(result['aAcc'])) + f.write('mIoU: {}\n'.format(result['mIoU'])) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser('mIoU calculate') + parser.add_argument('--output_path', default="./result", + help='path to om/onnx output file, default ./result') + parser.add_argument('--gt_path', default="/opt/npu/cityscapes/gtFine/val", + help='path to gtFine/val, default /opt/npu/cityscapes/gtFine/val') + parser.add_argument('--out_suffix', default="_leftImg8bit_1.bin", + help='suffix of the om/onnx output, default "_leftImg8bit_1.bin"') + parser.add_argument('--result_path', default="./postprocess_result", + help='path to save the script result, default ./postprocess_result.txt') + + args = parser.parse_args() + + output_path = os.path.realpath(args.output_path) + gt_path = os.path.realpath(args.gt_path) + out_suffix = args.out_suffix + result_path = os.path.realpath(args.result_path) + print(output_path) + print(gt_path) + eval_metrics(output_path, gt_path, out_suffix=out_suffix, result_path=result_path) diff --git a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/deeplabv3_torch_preprocess.py b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/deeplabv3_torch_preprocess.py index d722f4d3333ec67988d36667c355056747d895c2..d3a41c0d44f3c736f559fe6962d9eefa3e18c44e 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/deeplabv3_torch_preprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/deeplabv3_torch_preprocess.py @@ -1,88 +1,88 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import os -import cv2 -import numpy as np -from torchvision import transforms - - -class Normalize(object): - def __init__(self, mean, std, to_rgb=True): - self.mean = np.array(mean, dtype=np.float32) - self.std = np.array(std, dtype=np.float32) - self.to_rgb = to_rgb - - def __call__(self, img): - img = img.copy().astype(np.float32) - # cv2 inplace normalization does not accept uint8 - assert img.dtype != np.uint8 - mean = np.float64(self.mean.reshape(1, -1)) - stdinv = 1 / np.float64(self.std.reshape(1, -1)) - if self.to_rgb: - cv2.cvtColor(img, cv2.COLOR_BGR2RGB, img) # inplace - cv2.subtract(img, mean, img) # inplace - cv2.multiply(img, stdinv, img) # inplace - return img - - -def preprocess(src_path, save_path): - """ - resnet50 pytorch preprocess - """ - preprocess = transforms.Compose([ - Normalize(mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True), - transforms.ToTensor(), - ]) - - root = src_path - - # 扫描文件夹下所有文件 - def _scandir(dir_path, suffix, recursive): - for entry in os.scandir(dir_path): - if not entry.name.startswith('.') and entry.is_file(): - rel_path = os.path.relpath(entry.path, root) - if suffix is None or rel_path.endswith(suffix): - yield rel_path - elif recursive and os.path.isdir(entry.path): - # scan recursively if entry.path is a directory - yield from _scandir( - entry.path, suffix=suffix, recursive=recursive) - - in_files = _scandir(src_path, '_leftImg8bit.png', True) - if not os.path.exists(save_path): - os.makedirs(save_path) - - i = 0 - for file in in_files: - i = i + 1 - print(file, "====", i) - input_image = cv2.imread(src_path + '/' + file) - input_tensor = preprocess(input_image) - # print(file.split('/')[-1].split('.')[0]) - # print(input_tensor) - img = np.array(input_tensor).astype(np.float32) - # print(img.shape) - img.tofile(os.path.join(save_path, file.split('/')[-1].split('.')[0] + ".bin")) - - -if __name__ == '__main__': - if len(sys.argv) < 3: - raise Exception("usage: python3 xxx.py [src_path] [save_path]") - src_path = sys.argv[1] - save_path = sys.argv[2] - src_path = os.path.realpath(src_path) - save_path = os.path.realpath(save_path) - preprocess(src_path, save_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import os +import cv2 +import numpy as np +from torchvision import transforms + + +class Normalize(object): + def __init__(self, mean, std, to_rgb=True): + self.mean = np.array(mean, dtype=np.float32) + self.std = np.array(std, dtype=np.float32) + self.to_rgb = to_rgb + + def __call__(self, img): + img = img.copy().astype(np.float32) + # cv2 inplace normalization does not accept uint8 + assert img.dtype != np.uint8 + mean = np.float64(self.mean.reshape(1, -1)) + stdinv = 1 / np.float64(self.std.reshape(1, -1)) + if self.to_rgb: + cv2.cvtColor(img, cv2.COLOR_BGR2RGB, img) # inplace + cv2.subtract(img, mean, img) # inplace + cv2.multiply(img, stdinv, img) # inplace + return img + + +def preprocess(src_path, save_path): + """ + resnet50 pytorch preprocess + """ + preprocess = transforms.Compose([ + Normalize(mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True), + transforms.ToTensor(), + ]) + + root = src_path + + # 扫描文件夹下所有文件 + def _scandir(dir_path, suffix, recursive): + for entry in os.scandir(dir_path): + if not entry.name.startswith('.') and entry.is_file(): + rel_path = os.path.relpath(entry.path, root) + if suffix is None or rel_path.endswith(suffix): + yield rel_path + elif recursive and os.path.isdir(entry.path): + # scan recursively if entry.path is a directory + yield from _scandir( + entry.path, suffix=suffix, recursive=recursive) + + in_files = _scandir(src_path, '_leftImg8bit.png', True) + if not os.path.exists(save_path): + os.makedirs(save_path) + + i = 0 + for file in in_files: + i = i + 1 + print(file, "====", i) + input_image = cv2.imread(src_path + '/' + file) + input_tensor = preprocess(input_image) + # print(file.split('/')[-1].split('.')[0]) + # print(input_tensor) + img = np.array(input_tensor).astype(np.float32) + # print(img.shape) + img.tofile(os.path.join(save_path, file.split('/')[-1].split('.')[0] + ".bin")) + + +if __name__ == '__main__': + if len(sys.argv) < 3: + raise Exception("usage: python3 xxx.py [src_path] [save_path]") + src_path = sys.argv[1] + save_path = sys.argv[2] + src_path = os.path.realpath(src_path) + save_path = os.path.realpath(save_path) + preprocess(src_path, save_path) diff --git a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/gen_dataset_info.py index 11c25ce915cd63e436eabb74fe4ba1252e843391..4f9793db1ae248233fd9abff5f4f016698718e14 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/gen_dataset_info.py @@ -1,74 +1,74 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - """ - @description: get given bin information - @param file_path bin file path - @param info_name given information name - @param width image width - @param height image height - @return - """ - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - """ - @description: get given jpg information - @param file_path jpg file path - @param info_name given jpg information name - @return - """ - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + """ + @description: get given bin information + @param file_path bin file path + @param info_name given information name + @param width image width + @param height image height + @return + """ + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + """ + @description: get given jpg information + @param file_path jpg file path + @param info_name given jpg information name + @return + """ + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) diff --git a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/modelzoo_level.txt index 38700fca05402f52c3ae1c4be0889eb60e1f80f1..2e42553460a4f3687654b6ad3f91ab0bcc3aadac 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/requirements.txt b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/requirements.txt index 4ebce316a29a4ea7a85237e397d801114144db98..099a8067cdd4a3769df8e15780cc36575871edea 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/requirements.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/requirements.txt @@ -1,7 +1,7 @@ -torch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.7.0 -onnxruntime == 1.9.0 -numpy == 1.20.3 -opencv-python == 4.5.2.54 +torch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.7.0 +onnxruntime == 1.9.0 +numpy == 1.20.3 +opencv-python == 4.5.2.54 onnx-simplifier == 0.3.6 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/test/parse.py b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/test/parse.py index a119109c5d93366ac01a075d24831dcee540674f..6d5a1293288dce8bfc70f79ecf6551acafed6b81 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/test/parse.py +++ b/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3/test/parse.py @@ -1,33 +1,33 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - #tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - #print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - print(content) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + #tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + #print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + print(content) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/ENet/ENet_postprocess.py b/ACL_PyTorch/contrib/cv/segmentation/ENet/ENet_postprocess.py index dbc4cc77634605337d929ee904b76f61d174e729..25f698087940769b67a17cb8feefa7829e6db5a4 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/ENet/ENet_postprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/ENet/ENet_postprocess.py @@ -1,93 +1,93 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -*- coding: utf-8 -*- -import sys -import os - -cur_path = os.path.abspath(os.path.dirname(__file__)) -root_path = os.path.split(cur_path)[0] -sys.path.append(root_path) - -import numpy as np -import argparse - -import torch -import torch.utils.data as data - -from torchvision import transforms -from cityscapes import CitySegmentation -from score import SegmentationMetric -from distributed import * - -def get_res(res_dir): - - output = [] - with open(res_dir) as res_f: - for line in res_f: - num_list = line.split() - for num in num_list: - output.append(float(num)) - output = torch.from_numpy(np.array(output).reshape((1, 19, 480, 480))) - ''' - with open(res_dir, 'rb') as res_f: - output = np.frombuffer(res_f.read(), np.float16) - output = torch.from_numpy(output.reshape((1, 19, 480, 480))) - ''' - return output - - -def postprocess(args): - input_transform = transforms.Compose([ - transforms.ToTensor(), - transforms.Normalize([.485, .456, .406], [.229, .224, .225]), - ]) - # dataset and dataloader - data_kwargs = {'transform': input_transform, 'base_size': 520, 'crop_size': 480} - val_dataset = CitySegmentation(root = args.src_path, split='val', mode='val', **data_kwargs) - - val_sampler = make_data_sampler(val_dataset, False, False) - val_batch_sampler = make_batch_data_sampler(val_sampler, args.batch_size) - - val_loader = data.DataLoader(dataset=val_dataset, - batch_sampler=val_batch_sampler, - num_workers=args.workers, - pin_memory=True) - - metric = SegmentationMetric(19) - for i, (image, target, filename) in enumerate(val_loader): - res_name = os.path.splitext(os.path.basename(filename[0]))[0] - res_dir = os.path.join(args.result_dir, res_name + '_1.txt') - #res_dir = os.path.join(args.result_dir, res_name + '_1.bin') - res = get_res(res_dir) - metric.update(res, target) - pixAcc, mIoU = metric.get() - print("Sample: {:d}, validation pixAcc: {:.3f}, mIoU: {:.3f}".format( - i + 1, pixAcc * 100, mIoU * 100)) - - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--src-path', type=str, required=True) - parser.add_argument('--result-dir', type=str, default='result/dumpOutput_device0') - parser.add_argument('--batch-size', type=int, default=1, metavar='N', - help='input batch size for training (default: 8)') - parser.add_argument('--workers', '-j', type=int, default=4, - metavar='N', help='dataloader threads') - args = parser.parse_args() - - postprocess(args) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -*- coding: utf-8 -*- +import sys +import os + +cur_path = os.path.abspath(os.path.dirname(__file__)) +root_path = os.path.split(cur_path)[0] +sys.path.append(root_path) + +import numpy as np +import argparse + +import torch +import torch.utils.data as data + +from torchvision import transforms +from cityscapes import CitySegmentation +from score import SegmentationMetric +from distributed import * + +def get_res(res_dir): + + output = [] + with open(res_dir) as res_f: + for line in res_f: + num_list = line.split() + for num in num_list: + output.append(float(num)) + output = torch.from_numpy(np.array(output).reshape((1, 19, 480, 480))) + ''' + with open(res_dir, 'rb') as res_f: + output = np.frombuffer(res_f.read(), np.float16) + output = torch.from_numpy(output.reshape((1, 19, 480, 480))) + ''' + return output + + +def postprocess(args): + input_transform = transforms.Compose([ + transforms.ToTensor(), + transforms.Normalize([.485, .456, .406], [.229, .224, .225]), + ]) + # dataset and dataloader + data_kwargs = {'transform': input_transform, 'base_size': 520, 'crop_size': 480} + val_dataset = CitySegmentation(root = args.src_path, split='val', mode='val', **data_kwargs) + + val_sampler = make_data_sampler(val_dataset, False, False) + val_batch_sampler = make_batch_data_sampler(val_sampler, args.batch_size) + + val_loader = data.DataLoader(dataset=val_dataset, + batch_sampler=val_batch_sampler, + num_workers=args.workers, + pin_memory=True) + + metric = SegmentationMetric(19) + for i, (image, target, filename) in enumerate(val_loader): + res_name = os.path.splitext(os.path.basename(filename[0]))[0] + res_dir = os.path.join(args.result_dir, res_name + '_1.txt') + #res_dir = os.path.join(args.result_dir, res_name + '_1.bin') + res = get_res(res_dir) + metric.update(res, target) + pixAcc, mIoU = metric.get() + print("Sample: {:d}, validation pixAcc: {:.3f}, mIoU: {:.3f}".format( + i + 1, pixAcc * 100, mIoU * 100)) + + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--src-path', type=str, required=True) + parser.add_argument('--result-dir', type=str, default='result/dumpOutput_device0') + parser.add_argument('--batch-size', type=int, default=1, metavar='N', + help='input batch size for training (default: 8)') + parser.add_argument('--workers', '-j', type=int, default=4, + metavar='N', help='dataloader threads') + args = parser.parse_args() + + postprocess(args) + # python ENet_postprocess.py --src-path=/root/.torch/datasets/citys --result-dir result/dumpOutput_device0 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/ENet/ENet_preprocess.py b/ACL_PyTorch/contrib/cv/segmentation/ENet/ENet_preprocess.py index 413c310f7759da604725adb47eb3f2103568b387..02ce9a894059d7bc62d923eaae405fc574d4ac82 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/ENet/ENet_preprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/ENet/ENet_preprocess.py @@ -1,108 +1,108 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -*- coding: utf-8 -*- - -import argparse -import os -import sys -import numpy as np - -cur_path = os.path.abspath(os.path.dirname(__file__)) -root_path = os.path.split(cur_path)[0] -sys.path.append(root_path) - -from PIL import Image -from torchvision import transforms - - -def _val_sync_transform(img, mask): - outsize = 480 - short_size = outsize - w, h = img.size - if w > h: - oh = short_size - ow = int(1.0 * w * oh / h) - else: - ow = short_size - oh = int(1.0 * h * ow / w) - img = img.resize((ow, oh), Image.BILINEAR) - mask = mask.resize((ow, oh), Image.NEAREST) - # center crop - w, h = img.size - x1 = int(round((w - outsize) / 2.)) - y1 = int(round((h - outsize) / 2.)) - img = img.crop((x1, y1, x1 + outsize, y1 + outsize)) - mask = mask.crop((x1, y1, x1 + outsize, y1 + outsize)) - # final transform - img, mask = np.array(img), np.array(mask).astype('int32') - return img, mask - -def _get_city_pairs(folder, split='val'): - def get_path_pairs(img_folder, mask_folder): - img_paths = [] - mask_paths = [] - for root, _, files in os.walk(img_folder): - for filename in files: - if filename.endswith('.png'): - imgpath = os.path.join(root, filename) - foldername = os.path.basename(os.path.dirname(imgpath)) - maskname = filename.replace('leftImg8bit', 'gtFine_labelIds') - maskpath = os.path.join(mask_folder, foldername, maskname) - if os.path.isfile(imgpath) and os.path.isfile(maskpath): - img_paths.append(imgpath) - mask_paths.append(maskpath) - else: - print('cannot find the mask or image:', imgpath, maskpath) - print('Found {} images in the folder {}'.format(len(img_paths), img_folder)) - return img_paths, mask_paths - - if split in ('train', 'val'): - img_folder = os.path.join(folder, 'leftImg8bit/' + split) - mask_folder = os.path.join(folder, 'gtFine/' + split) - img_paths, mask_paths = get_path_pairs(img_folder, mask_folder) - return img_paths, mask_paths - -def preprocess(args): - input_transform = transforms.Compose([ - transforms.ToTensor(), - transforms.Normalize([.485, .456, .406], [.229, .224, .225]), - ]) - - images, mask_paths = _get_city_pairs(args.src_path, 'val') - - for i, image in enumerate(images): - img = Image.open(image).convert('RGB') - mask = Image.open(mask_paths[i]) - img, mask = _val_sync_transform(img, mask) - img = input_transform(img) - #img = np.asarray(img).astype(np.float16) - - img = np.asarray(img) - - filename = os.path.basename(image) - - img.tofile(os.path.join(args.save_path, os.path.splitext(filename)[0] + ".bin")) - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--src-path', type=str, required=True) - parser.add_argument('--save_path', type=str, default='prep_dataset') - - args = parser.parse_args() - - if not os.path.isdir(args.save_path): - os.makedirs(os.path.realpath(args.save_path)) - preprocess(args) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# -*- coding: utf-8 -*- + +import argparse +import os +import sys +import numpy as np + +cur_path = os.path.abspath(os.path.dirname(__file__)) +root_path = os.path.split(cur_path)[0] +sys.path.append(root_path) + +from PIL import Image +from torchvision import transforms + + +def _val_sync_transform(img, mask): + outsize = 480 + short_size = outsize + w, h = img.size + if w > h: + oh = short_size + ow = int(1.0 * w * oh / h) + else: + ow = short_size + oh = int(1.0 * h * ow / w) + img = img.resize((ow, oh), Image.BILINEAR) + mask = mask.resize((ow, oh), Image.NEAREST) + # center crop + w, h = img.size + x1 = int(round((w - outsize) / 2.)) + y1 = int(round((h - outsize) / 2.)) + img = img.crop((x1, y1, x1 + outsize, y1 + outsize)) + mask = mask.crop((x1, y1, x1 + outsize, y1 + outsize)) + # final transform + img, mask = np.array(img), np.array(mask).astype('int32') + return img, mask + +def _get_city_pairs(folder, split='val'): + def get_path_pairs(img_folder, mask_folder): + img_paths = [] + mask_paths = [] + for root, _, files in os.walk(img_folder): + for filename in files: + if filename.endswith('.png'): + imgpath = os.path.join(root, filename) + foldername = os.path.basename(os.path.dirname(imgpath)) + maskname = filename.replace('leftImg8bit', 'gtFine_labelIds') + maskpath = os.path.join(mask_folder, foldername, maskname) + if os.path.isfile(imgpath) and os.path.isfile(maskpath): + img_paths.append(imgpath) + mask_paths.append(maskpath) + else: + print('cannot find the mask or image:', imgpath, maskpath) + print('Found {} images in the folder {}'.format(len(img_paths), img_folder)) + return img_paths, mask_paths + + if split in ('train', 'val'): + img_folder = os.path.join(folder, 'leftImg8bit/' + split) + mask_folder = os.path.join(folder, 'gtFine/' + split) + img_paths, mask_paths = get_path_pairs(img_folder, mask_folder) + return img_paths, mask_paths + +def preprocess(args): + input_transform = transforms.Compose([ + transforms.ToTensor(), + transforms.Normalize([.485, .456, .406], [.229, .224, .225]), + ]) + + images, mask_paths = _get_city_pairs(args.src_path, 'val') + + for i, image in enumerate(images): + img = Image.open(image).convert('RGB') + mask = Image.open(mask_paths[i]) + img, mask = _val_sync_transform(img, mask) + img = input_transform(img) + #img = np.asarray(img).astype(np.float16) + + img = np.asarray(img) + + filename = os.path.basename(image) + + img.tofile(os.path.join(args.save_path, os.path.splitext(filename)[0] + ".bin")) + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--src-path', type=str, required=True) + parser.add_argument('--save_path', type=str, default='prep_dataset') + + args = parser.parse_args() + + if not os.path.isdir(args.save_path): + os.makedirs(os.path.realpath(args.save_path)) + preprocess(args) + # python ENet_preprocess.py --src-path=/root/.torch/datasets/citys --save_path prep_dataset \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/ENet/ENet_pth2onnx.py b/ACL_PyTorch/contrib/cv/segmentation/ENet/ENet_pth2onnx.py index 9892c9c6920ff737d0ccc13b6c61acf09143091d..275ef0d62fd0e213e862bb89ddd540fa2fb693d4 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/ENet/ENet_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/segmentation/ENet/ENet_pth2onnx.py @@ -1,83 +1,83 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -*- coding: utf-8 -*- - -import os -import sys -import argparse - -cur_path = os.path.abspath(os.path.dirname(__file__)) -root_path = os.path.split(cur_path)[0] -sys.path.append(root_path) - -import torch -import torch.nn as nn -import torch.onnx - -from collections import OrderedDict -from enet import get_enet - - -def proc_nodes_module(checkpoint, AttrName): - new_state_dict = OrderedDict() - for k, v in checkpoint[AttrName].items(): - if (k[0:7] == "module."): - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - -''' -def convert(pth_file_path, onnx_file_path, class_num): - checkpoint = torch.load(pth_file_path, map_location='cpu') - checkpoint['state_dict'] = proc_nodes_module(checkpoint, 'state_dict') - model = densenet121(pretrained=False, num_classes=class_num) - model.load_state_dict(checkpoint['state_dict']) - model.eval() - print(model) - - input_names = ["actual_input_1"] - output_names = ["output1"] - dummy_input = torch.randn(16, 3, 224, 224) - torch.onnx.export(model, dummy_input, onnx_file_path, input_names=input_names, output_names=output_names, - opset_version=11) -''' - -def pth2onnx(input_file, output_file, batch_size=1): - model = get_enet(model='enet', dataset='citys', aux=False, norm_layer=nn.BatchNorm2d) - checkpoint = {} - checkpoint['state_dict'] = torch.load(input_file, map_location='cpu') - checkpoint['state_dict'] = proc_nodes_module(checkpoint, 'state_dict') - model.load_state_dict(checkpoint['state_dict']) - - model.eval() - print(model) - - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(batch_size, 3, 480, 480) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, opset_version=11, verbose=True) - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument('--input-file', type=str, default='~/.torch/models/enet_citys.pth') - parser.add_argument('--output-file', type=str, default='model/enet_citys_910_bs1.onnx') - parser.add_argument('--batch-size', type=int, default=1) - args = parser.parse_args() - pth2onnx(args.input_file, args.output_file, batch_size=args.batch_size) - -# python ENet_pth2onnx.py --input-file models/enet_citys.pth --output-file models/enet_citys_910_bs1.onnx --batch-size 1 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# -*- coding: utf-8 -*- + +import os +import sys +import argparse + +cur_path = os.path.abspath(os.path.dirname(__file__)) +root_path = os.path.split(cur_path)[0] +sys.path.append(root_path) + +import torch +import torch.nn as nn +import torch.onnx + +from collections import OrderedDict +from enet import get_enet + + +def proc_nodes_module(checkpoint, AttrName): + new_state_dict = OrderedDict() + for k, v in checkpoint[AttrName].items(): + if (k[0:7] == "module."): + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + +''' +def convert(pth_file_path, onnx_file_path, class_num): + checkpoint = torch.load(pth_file_path, map_location='cpu') + checkpoint['state_dict'] = proc_nodes_module(checkpoint, 'state_dict') + model = densenet121(pretrained=False, num_classes=class_num) + model.load_state_dict(checkpoint['state_dict']) + model.eval() + print(model) + + input_names = ["actual_input_1"] + output_names = ["output1"] + dummy_input = torch.randn(16, 3, 224, 224) + torch.onnx.export(model, dummy_input, onnx_file_path, input_names=input_names, output_names=output_names, + opset_version=11) +''' + +def pth2onnx(input_file, output_file, batch_size=1): + model = get_enet(model='enet', dataset='citys', aux=False, norm_layer=nn.BatchNorm2d) + checkpoint = {} + checkpoint['state_dict'] = torch.load(input_file, map_location='cpu') + checkpoint['state_dict'] = proc_nodes_module(checkpoint, 'state_dict') + model.load_state_dict(checkpoint['state_dict']) + + model.eval() + print(model) + + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(batch_size, 3, 480, 480) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, opset_version=11, verbose=True) + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--input-file', type=str, default='~/.torch/models/enet_citys.pth') + parser.add_argument('--output-file', type=str, default='model/enet_citys_910_bs1.onnx') + parser.add_argument('--batch-size', type=int, default=1) + args = parser.parse_args() + pth2onnx(args.input_file, args.output_file, batch_size=args.batch_size) + +# python ENet_pth2onnx.py --input-file models/enet_citys.pth --output-file models/enet_citys_910_bs1.onnx --batch-size 1 # python ENet_pth2onnx.py --input-file models/enet_citys.pth --output-file models/enet_citys_910_bs16.onnx --batch-size 16 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/ENet/test/parse.py b/ACL_PyTorch/contrib/cv/segmentation/ENet/test/parse.py index b9c74f41d7848e1250356f14472b237a18bb3489..82af69cd183218c3263723c20b652b3f7ec2bc27 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/ENet/test/parse.py +++ b/ACL_PyTorch/contrib/cv/segmentation/ENet/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/LICENSE b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/LICENSE index 7615b4e85fa24d81f25cec1495e783a3936f1a86..72f817fb44de8b9fd23fe71230b9dc5ccbe4ca35 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/LICENSE +++ b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/README.md b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/README.md index 9aa8344a9367b140b072977917070ba54e918176..b4fa271e04aec3917c4c5dc533d72c290274e47a 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/README.md +++ b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/README.md @@ -1,356 +1,356 @@ -# 基于开源mmsegmentation预训练的fcn-8s Onnx模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理精度统计](#61-离线推理精度统计) - - [6.2 开源精度](#62-开源精度) - - [6.3 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[fcn-8s论文](https://arxiv.org/abs/1411.4038) -论文提出 Fully Convolutional Networks(FCN)方法用于图像语义分割,将图像级别的分类扩展到像素级别的分类,获得 CVPR2015 的 best paper。 - - -### 1.2 代码地址 -[mmsegmentation框架fcn-8s代码](https://github.com/open-mmlab/mmsegmentation/tree/master/configs/fcn) -branch:master commit_id:e6a8791ab0a03c60c0a9abb8456cd4d804342e92 - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 -``` -pytorch == 1.8.0 -torchvision == 0.9.0 -onnx == 1.9.0 -``` -**注意:** -> 转onnx的环境上pytorch需要安装1.8.0版本 - -### 2.2 python第三方库 -``` -numpy == 1.20.1 -opencv-python == 4.5.2.52 -``` - -**说明:** -> X86架构:opencv,pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:opencv,pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - - -### 3.1 pth转onnx模型 - -1.获取pth权重文件 -[fcn-8s基于mmsegmentation预训练的npu权重文件](https://download.openmmlab.com/mmsegmentation/v0.5/fcn/fcn_r50-d8_512x512_20k_voc12aug/fcn_r50-d8_512x512_20k_voc12aug_20200617_010715-52dc5306.pth) -文件md5sum: 0b42f76eb2e3779a5f802acb5ded5eed - -2.mmsegmentation源码安装 -```shell -git clone https://github.com/open-mmlab/mmcv.git -cd mmcv -pip3.7 install -e . -cd .. -git clone https://github.com/open-mmlab/mmsegmentation.git -cd mmsegmentation -如果修改了模型代码,交付了{model_name}.diff -patch -p1 < ../{model_name}.diff -如果模型代码需要安装,则安装模型代码(如果没有安装脚本,pth2onnx等脚本需要引用模型代码的类或函数,可通过sys.path.append(r"./pytorch-nested-unet")添加搜索路径的方式) -pip3.7 install -e . # or "python3.7 setup.py develop" -cd .. -``` - - **说明:** -> 安装所需的依赖说明请参考mmsegmentation/docs/get_started.md - - -3.使用tools里的pytorch2onnx.py文件,运行如下命令,生成对应的onnx模型: -```shell -python3.7 mmsegmentation/tools/pytorch2onnx.py mmsegmentation/configs/fcn/fcn_r50-d8_512x512_20k_voc12aug.py --checkpoint fcn_r50-d8_512x512_20k_voc12aug_20200617_010715-52dc5306.pth --output-file fcn_r50-d8_512x512_20k_voc12aug.onnx --shape 500 500 --show -``` - **模型转换要点:** -> 虽然导出的onnx可以转换为多batch的om离线推理,但是在线推理与onnx目前还不支持多batch推理 - -### 3.2 onnx转om模型 - -1.设置环境变量 -```shell -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest/ -``` -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN 5.0.1 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373),如果存在多余输出节点,需要指定输出节点以去除无用输出,节点序号可能会因网络结构不同而不同,使用netron开源可视化工具查看具体的输出节点名: -```shell -atc --framework=5 --model=fcn_r50-d8_512x512_20k_voc12aug.onnx --output=fcn_r50-d8_512x512_20k_voc12aug_bs1 --input_format=NCHW --input_shape="input:1,3,500,500" --log=debug --soc_version=Ascend310 -``` - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -该模型使用[VOC2012官网](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/index.html)的VOC2012的1449张验证集进行测试,图片与对应ground truth分别存放在/opt/npu/VOCdevkit/VOC2012/JPEGImages/与/opt/npu/VOCdevkit/VOC2012/SegmentationClass/。 - -### 4.2 数据集预处理 -1.预处理脚本mmsegmentation_voc2012_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 -```shell -python3.7 mmsegmentation_voc2012_preprocess.py --image_folder_path=/opt/npu/VOCdevkit/VOC2012/JPEGImages/ --split=/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt --bin_folder_path=./voc12_bin/ -``` -### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本get_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 -```shell -python3.7 get_info.py bin ./voc12_bin voc12.info 500 500 -``` -第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN 5.0.1 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) - -### 5.2 离线推理 - -1.设置环境变量 -```shell -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest/ -``` -2.执行离线推理 -```shell -./benchmark.${arch} -model_type=vision -om_path=fcn_r50-d8_512x512_20k_voc12aug_bs1.om -device_id=0 -batch_size=1 -input_text_path=voc12.info -input_width=500 -input_height=500 -useDvpp=false -output_binary=true -``` - **注意:** -> onnx的输出是int64,但是om的输出是int32 - -输出结果默认保存在当前目录result/dumpOutput_device0,模型有一个输出,每个输入对应的输出对应_1.bin文件 -``` -输出 shape 数据类型 数据含义 -output1 1 * 1 * 500 * 500 int32 8位图像 -``` - -## 6 精度对比 - -- **[离线推理精度](#61-离线推理精度)** -- **[开源精度](#62-开源精度)** -- **[精度对比](#63-精度对比)** - -### 6.1 离线推理精度统计 - -1.调用mmsegmentation_voc2012_postprocess.py评测bs1的mIoU精度: -```shell -python3.7 get_info.py jpg /opt/npu/VOCdevkit/VOC2012/JPEGImages/ voc12_jpg.info - -python3.7 mmsegmentation_voc2012_postprocess.py --bin_data_path=./result/dumpOutput_device0 --test_annotation=./voc12_jpg.info --img_dir=/opt/npu/VOCdevkit/VOC2012/JPEGImages --ann_dir=/opt/npu/VOCdevkit/VOC2012/SegmentationClass --split=/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt --net_input_width=500 --net_input_height=500 -``` -第一个参数为benchmark推理结果,第二个为原始图片信息文件,第三个为原始图片位置,第四个为验证图片位置,第五个图片的split,第六七个为网宽高 -执行完后会打印出精度: -``` -per class results: - -+-------------+-------+-------+ -| Class | IoU | Acc | -+-------------+-------+-------+ -| background | 92.84 | 97.27 | -| aeroplane | 81.0 | 90.2 | -| bicycle | 37.6 | 84.07 | -| bird | 80.3 | 87.49 | -| boat | 64.63 | 77.42 | -| bottle | 61.32 | 69.76 | -| bus | 87.31 | 91.7 | -| car | 79.48 | 89.74 | -| cat | 85.69 | 92.6 | -| chair | 30.69 | 44.66 | -| cow | 73.21 | 82.52 | -| diningtable | 43.5 | 48.95 | -| dog | 78.83 | 87.76 | -| horse | 74.5 | 82.18 | -| motorbike | 75.7 | 82.97 | -| person | 83.24 | 89.45 | -| pottedplant | 53.23 | 64.87 | -| sheep | 74.29 | 80.85 | -| sofa | 45.59 | 55.79 | -| train | 77.98 | 82.49 | -| tvmonitor | 68.21 | 74.91 | -+-------------+-------+-------+ -Summary: - -+--------+-------+-------+-------+ -| Scope | mIoU | mAcc | aAcc | -+--------+-------+-------+-------+ -| global | 69.01 | 78.94 | 93.04 | -+--------+-------+-------+-------+ - -``` - -2.调用mmsegmentation_voc2012_postprocess.py评测bs16的mIoU精度: -```shell -python3.7 get_info.py jpg /opt/npu/VOCdevkit/VOC2012/JPEGImages/ voc12_jpg.info - -python3.7 mmsegmentation_voc2012_postprocess.py --bin_data_path=./result/dumpOutput_device1 --test_annotation=./voc12_jpg.info --img_dir=/opt/npu/VOCdevkit/VOC2012/JPEGImages --ann_dir=/opt/npu/VOCdevkit/VOC2012/SegmentationClass --split=/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt --net_input_width=500 --net_input_height=500 -``` -第一个参数为benchmark推理结果,第二个为原始图片信息文件,第三个为原始图片位置,第四个为验证图片位置,第五个图片的split,第六七个为网宽高 -执行完后会打印出精度: -``` -per class results: - -+-------------+-------+-------+ -| Class | IoU | Acc | -+-------------+-------+-------+ -| background | 92.84 | 97.27 | -| aeroplane | 81.0 | 90.2 | -| bicycle | 37.6 | 84.07 | -| bird | 80.3 | 87.49 | -| boat | 64.63 | 77.42 | -| bottle | 61.32 | 69.76 | -| bus | 87.31 | 91.7 | -| car | 79.48 | 89.74 | -| cat | 85.69 | 92.6 | -| chair | 30.69 | 44.66 | -| cow | 73.21 | 82.52 | -| diningtable | 43.5 | 48.95 | -| dog | 78.83 | 87.76 | -| horse | 74.5 | 82.18 | -| motorbike | 75.7 | 82.97 | -| person | 83.24 | 89.45 | -| pottedplant | 53.23 | 64.87 | -| sheep | 74.29 | 80.85 | -| sofa | 45.59 | 55.79 | -| train | 77.98 | 82.49 | -| tvmonitor | 68.21 | 74.91 | -+-------------+-------+-------+ -Summary: - -+--------+-------+-------+-------+ -| Scope | mIoU | mAcc | aAcc | -+--------+-------+-------+-------+ -| global | 69.01 | 78.94 | 93.04 | -+--------+-------+-------+-------+ - -``` - **精度调试:** -> 1.在线推理前处理图片是一定格式的动态分辨率,onnx将分辨率固定为512x512会导致精度下降些。 -> 2.分辨率在512x512时onnx离线推理的精度与om精度相同,分辨率改为500x500可以提升精度,使得mask的精度与开源相比更高 -> 3.单图调试 -> ``` -> python3.7 mmsegmentation/tools/test.py mmsegmentation/configs/fcn/fcn_r50-d8_512x512_20k_voc12aug.py fcn_r50-d8_512x512_20k_voc12aug_20200617_010715-52dc5306.pth --show -> python3.7 mmsegmentation/tools/pytorch2onnx.py mmsegmentation/configs/fcn/fcn_r50-d8_512x512_20k_voc12aug.py --checkpoint fcn_r50-d8_512x512_20k_voc12aug_20200617_010715-52dc5306.pth --output-file fcn_r50-d8_512x512_20k_voc12aug.onnx --shape 500 500 --input-img 2011_003103.jpg --show --verify -> ``` - - -### 6.2 开源精度 -[官网精度](https://download.openmmlab.com/mmsegmentation/v0.5/fcn/fcn_r50-d8_512x512_20k_voc12aug/fcn_r50-d8_512x512_20k_voc12aug_20200617_010715.log.json) - -``` -{"mode": "val", "epoch": 31, "iter": 20000, "lr": 0.0001, "mIoU": 0.67085, "mAcc": 0.76958, "aAcc": 0.92709} -``` -### 6.3 精度对比 -om推理mIoU精度均为0.6901,开源mIoU精度为0.67085,om精度大于开源精度,精度达标 - - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** - -### 7.1 npu性能数据 -1.benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 -由于在线推理与onnx推理还不支持多batch,所以仅测om bs1,bs16的性能。 -1.benchmark工具在整个数据集上推理获得性能数据 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: -``` -[e2e] throughputRate: 14.2564, latency: 101639 -[data read] throughputRate: 24.7255, moduleLatency: 40.444 -[preprocess] throughputRate: 22.102, moduleLatency: 45.2448 -[infer] throughputRate: 14.3682, Interface throughputRate: 16.2017, moduleLatency: 69.2286 -[post] throughputRate: 14.368, moduleLatency: 69.5993 -``` -Interface throughputRate: 16.2017,16.2017x4=64.8068即是batch1 310单卡吞吐率 - -batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: -``` -[[e2e] throughputRate: 13.459, latency: 107660 -[data read] throughputRate: 23.5047, moduleLatency: 42.5446 -[preprocess] throughputRate: 21.4117, moduleLatency: 46.7034 -[infer] throughputRate: 13.5517, Interface throughputRate: 15.4271, moduleLatency: 73.3405 -[post] throughputRate: 0.850975, moduleLatency: 1175.12 -``` -Interface throughputRate: 15.4271,15.4271x4=61.7084即是batch16 310单卡吞吐率 - -2.npu纯推理性能 -batch1的性能,执行20次纯推理取均值,统计吞吐率与其倒数时延(benchmark的时延是单个数据的推理时间),npu性能是一个device执行的结果 -``` -./benchmark.x86_64 -round=20 -om_path=fcn_r50-d8_512x512_20k_voc12aug_bs1.om -device_id=0 -batch_size=1 -``` -PureInfer_perf_of_fcn_r50-d8_512x512_20k_voc12aug_bs1_in_device_0.txt: -``` -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_fcn_r50-d8_512x512_20k_voc12aug_bs1_in_device_0.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 16.2574samples/s, ave_latency: 61.5162ms ----------------------------------------------------------------- -``` -batch16的性能,执行20次纯推理取均值,统计吞吐率与其倒数时延(benchmark的时延是单个数据的推理时间),npu性能是一个device执行的结果 -``` -./benchmark.x86_64 -round=20 -om_path=fcn_r50-d8_512x512_20k_voc12aug_bs16.om -device_id=0 -batch_size=16 -``` -PureInfer_perf_of_fcn_r50-d8_512x512_20k_voc12aug_bs16_in_device_0.txt: -``` -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_fcn_r50-d8_512x512_20k_voc12aug_bs16_in_device_0.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 15.5282samples/s, ave_latency: 64.4083ms ----------------------------------------------------------------- -``` - -**性能优化:** -> 没有遇到性能不达标的问题,故不需要进行性能优化 - +# 基于开源mmsegmentation预训练的fcn-8s Onnx模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理精度统计](#61-离线推理精度统计) + - [6.2 开源精度](#62-开源精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[fcn-8s论文](https://arxiv.org/abs/1411.4038) +论文提出 Fully Convolutional Networks(FCN)方法用于图像语义分割,将图像级别的分类扩展到像素级别的分类,获得 CVPR2015 的 best paper。 + + +### 1.2 代码地址 +[mmsegmentation框架fcn-8s代码](https://github.com/open-mmlab/mmsegmentation/tree/master/configs/fcn) +branch:master commit_id:e6a8791ab0a03c60c0a9abb8456cd4d804342e92 + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +pytorch == 1.8.0 +torchvision == 0.9.0 +onnx == 1.9.0 +``` +**注意:** +> 转onnx的环境上pytorch需要安装1.8.0版本 + +### 2.2 python第三方库 +``` +numpy == 1.20.1 +opencv-python == 4.5.2.52 +``` + +**说明:** +> X86架构:opencv,pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:opencv,pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + + +### 3.1 pth转onnx模型 + +1.获取pth权重文件 +[fcn-8s基于mmsegmentation预训练的npu权重文件](https://download.openmmlab.com/mmsegmentation/v0.5/fcn/fcn_r50-d8_512x512_20k_voc12aug/fcn_r50-d8_512x512_20k_voc12aug_20200617_010715-52dc5306.pth) +文件md5sum: 0b42f76eb2e3779a5f802acb5ded5eed + +2.mmsegmentation源码安装 +```shell +git clone https://github.com/open-mmlab/mmcv.git +cd mmcv +pip3.7 install -e . +cd .. +git clone https://github.com/open-mmlab/mmsegmentation.git +cd mmsegmentation +如果修改了模型代码,交付了{model_name}.diff +patch -p1 < ../{model_name}.diff +如果模型代码需要安装,则安装模型代码(如果没有安装脚本,pth2onnx等脚本需要引用模型代码的类或函数,可通过sys.path.append(r"./pytorch-nested-unet")添加搜索路径的方式) +pip3.7 install -e . # or "python3.7 setup.py develop" +cd .. +``` + + **说明:** +> 安装所需的依赖说明请参考mmsegmentation/docs/get_started.md + + +3.使用tools里的pytorch2onnx.py文件,运行如下命令,生成对应的onnx模型: +```shell +python3.7 mmsegmentation/tools/pytorch2onnx.py mmsegmentation/configs/fcn/fcn_r50-d8_512x512_20k_voc12aug.py --checkpoint fcn_r50-d8_512x512_20k_voc12aug_20200617_010715-52dc5306.pth --output-file fcn_r50-d8_512x512_20k_voc12aug.onnx --shape 500 500 --show +``` + **模型转换要点:** +> 虽然导出的onnx可以转换为多batch的om离线推理,但是在线推理与onnx目前还不支持多batch推理 + +### 3.2 onnx转om模型 + +1.设置环境变量 +```shell +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest/ +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN 5.0.1 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373),如果存在多余输出节点,需要指定输出节点以去除无用输出,节点序号可能会因网络结构不同而不同,使用netron开源可视化工具查看具体的输出节点名: +```shell +atc --framework=5 --model=fcn_r50-d8_512x512_20k_voc12aug.onnx --output=fcn_r50-d8_512x512_20k_voc12aug_bs1 --input_format=NCHW --input_shape="input:1,3,500,500" --log=debug --soc_version=Ascend310 +``` + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用[VOC2012官网](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/index.html)的VOC2012的1449张验证集进行测试,图片与对应ground truth分别存放在/opt/npu/VOCdevkit/VOC2012/JPEGImages/与/opt/npu/VOCdevkit/VOC2012/SegmentationClass/。 + +### 4.2 数据集预处理 +1.预处理脚本mmsegmentation_voc2012_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 +```shell +python3.7 mmsegmentation_voc2012_preprocess.py --image_folder_path=/opt/npu/VOCdevkit/VOC2012/JPEGImages/ --split=/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt --bin_folder_path=./voc12_bin/ +``` +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本get_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 +```shell +python3.7 get_info.py bin ./voc12_bin voc12.info 500 500 +``` +第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN 5.0.1 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) + +### 5.2 离线推理 + +1.设置环境变量 +```shell +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest/ +``` +2.执行离线推理 +```shell +./benchmark.${arch} -model_type=vision -om_path=fcn_r50-d8_512x512_20k_voc12aug_bs1.om -device_id=0 -batch_size=1 -input_text_path=voc12.info -input_width=500 -input_height=500 -useDvpp=false -output_binary=true +``` + **注意:** +> onnx的输出是int64,但是om的输出是int32 + +输出结果默认保存在当前目录result/dumpOutput_device0,模型有一个输出,每个输入对应的输出对应_1.bin文件 +``` +输出 shape 数据类型 数据含义 +output1 1 * 1 * 500 * 500 int32 8位图像 +``` + +## 6 精度对比 + +- **[离线推理精度](#61-离线推理精度)** +- **[开源精度](#62-开源精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理精度统计 + +1.调用mmsegmentation_voc2012_postprocess.py评测bs1的mIoU精度: +```shell +python3.7 get_info.py jpg /opt/npu/VOCdevkit/VOC2012/JPEGImages/ voc12_jpg.info + +python3.7 mmsegmentation_voc2012_postprocess.py --bin_data_path=./result/dumpOutput_device0 --test_annotation=./voc12_jpg.info --img_dir=/opt/npu/VOCdevkit/VOC2012/JPEGImages --ann_dir=/opt/npu/VOCdevkit/VOC2012/SegmentationClass --split=/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt --net_input_width=500 --net_input_height=500 +``` +第一个参数为benchmark推理结果,第二个为原始图片信息文件,第三个为原始图片位置,第四个为验证图片位置,第五个图片的split,第六七个为网宽高 +执行完后会打印出精度: +``` +per class results: + ++-------------+-------+-------+ +| Class | IoU | Acc | ++-------------+-------+-------+ +| background | 92.84 | 97.27 | +| aeroplane | 81.0 | 90.2 | +| bicycle | 37.6 | 84.07 | +| bird | 80.3 | 87.49 | +| boat | 64.63 | 77.42 | +| bottle | 61.32 | 69.76 | +| bus | 87.31 | 91.7 | +| car | 79.48 | 89.74 | +| cat | 85.69 | 92.6 | +| chair | 30.69 | 44.66 | +| cow | 73.21 | 82.52 | +| diningtable | 43.5 | 48.95 | +| dog | 78.83 | 87.76 | +| horse | 74.5 | 82.18 | +| motorbike | 75.7 | 82.97 | +| person | 83.24 | 89.45 | +| pottedplant | 53.23 | 64.87 | +| sheep | 74.29 | 80.85 | +| sofa | 45.59 | 55.79 | +| train | 77.98 | 82.49 | +| tvmonitor | 68.21 | 74.91 | ++-------------+-------+-------+ +Summary: + ++--------+-------+-------+-------+ +| Scope | mIoU | mAcc | aAcc | ++--------+-------+-------+-------+ +| global | 69.01 | 78.94 | 93.04 | ++--------+-------+-------+-------+ + +``` + +2.调用mmsegmentation_voc2012_postprocess.py评测bs16的mIoU精度: +```shell +python3.7 get_info.py jpg /opt/npu/VOCdevkit/VOC2012/JPEGImages/ voc12_jpg.info + +python3.7 mmsegmentation_voc2012_postprocess.py --bin_data_path=./result/dumpOutput_device1 --test_annotation=./voc12_jpg.info --img_dir=/opt/npu/VOCdevkit/VOC2012/JPEGImages --ann_dir=/opt/npu/VOCdevkit/VOC2012/SegmentationClass --split=/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt --net_input_width=500 --net_input_height=500 +``` +第一个参数为benchmark推理结果,第二个为原始图片信息文件,第三个为原始图片位置,第四个为验证图片位置,第五个图片的split,第六七个为网宽高 +执行完后会打印出精度: +``` +per class results: + ++-------------+-------+-------+ +| Class | IoU | Acc | ++-------------+-------+-------+ +| background | 92.84 | 97.27 | +| aeroplane | 81.0 | 90.2 | +| bicycle | 37.6 | 84.07 | +| bird | 80.3 | 87.49 | +| boat | 64.63 | 77.42 | +| bottle | 61.32 | 69.76 | +| bus | 87.31 | 91.7 | +| car | 79.48 | 89.74 | +| cat | 85.69 | 92.6 | +| chair | 30.69 | 44.66 | +| cow | 73.21 | 82.52 | +| diningtable | 43.5 | 48.95 | +| dog | 78.83 | 87.76 | +| horse | 74.5 | 82.18 | +| motorbike | 75.7 | 82.97 | +| person | 83.24 | 89.45 | +| pottedplant | 53.23 | 64.87 | +| sheep | 74.29 | 80.85 | +| sofa | 45.59 | 55.79 | +| train | 77.98 | 82.49 | +| tvmonitor | 68.21 | 74.91 | ++-------------+-------+-------+ +Summary: + ++--------+-------+-------+-------+ +| Scope | mIoU | mAcc | aAcc | ++--------+-------+-------+-------+ +| global | 69.01 | 78.94 | 93.04 | ++--------+-------+-------+-------+ + +``` + **精度调试:** +> 1.在线推理前处理图片是一定格式的动态分辨率,onnx将分辨率固定为512x512会导致精度下降些。 +> 2.分辨率在512x512时onnx离线推理的精度与om精度相同,分辨率改为500x500可以提升精度,使得mask的精度与开源相比更高 +> 3.单图调试 +> ``` +> python3.7 mmsegmentation/tools/test.py mmsegmentation/configs/fcn/fcn_r50-d8_512x512_20k_voc12aug.py fcn_r50-d8_512x512_20k_voc12aug_20200617_010715-52dc5306.pth --show +> python3.7 mmsegmentation/tools/pytorch2onnx.py mmsegmentation/configs/fcn/fcn_r50-d8_512x512_20k_voc12aug.py --checkpoint fcn_r50-d8_512x512_20k_voc12aug_20200617_010715-52dc5306.pth --output-file fcn_r50-d8_512x512_20k_voc12aug.onnx --shape 500 500 --input-img 2011_003103.jpg --show --verify +> ``` + + +### 6.2 开源精度 +[官网精度](https://download.openmmlab.com/mmsegmentation/v0.5/fcn/fcn_r50-d8_512x512_20k_voc12aug/fcn_r50-d8_512x512_20k_voc12aug_20200617_010715.log.json) + +``` +{"mode": "val", "epoch": 31, "iter": 20000, "lr": 0.0001, "mIoU": 0.67085, "mAcc": 0.76958, "aAcc": 0.92709} +``` +### 6.3 精度对比 +om推理mIoU精度均为0.6901,开源mIoU精度为0.67085,om精度大于开源精度,精度达标 + + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** + +### 7.1 npu性能数据 +1.benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 +由于在线推理与onnx推理还不支持多batch,所以仅测om bs1,bs16的性能。 +1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: +``` +[e2e] throughputRate: 14.2564, latency: 101639 +[data read] throughputRate: 24.7255, moduleLatency: 40.444 +[preprocess] throughputRate: 22.102, moduleLatency: 45.2448 +[infer] throughputRate: 14.3682, Interface throughputRate: 16.2017, moduleLatency: 69.2286 +[post] throughputRate: 14.368, moduleLatency: 69.5993 +``` +Interface throughputRate: 16.2017,16.2017x4=64.8068即是batch1 310单卡吞吐率 + +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: +``` +[[e2e] throughputRate: 13.459, latency: 107660 +[data read] throughputRate: 23.5047, moduleLatency: 42.5446 +[preprocess] throughputRate: 21.4117, moduleLatency: 46.7034 +[infer] throughputRate: 13.5517, Interface throughputRate: 15.4271, moduleLatency: 73.3405 +[post] throughputRate: 0.850975, moduleLatency: 1175.12 +``` +Interface throughputRate: 15.4271,15.4271x4=61.7084即是batch16 310单卡吞吐率 + +2.npu纯推理性能 +batch1的性能,执行20次纯推理取均值,统计吞吐率与其倒数时延(benchmark的时延是单个数据的推理时间),npu性能是一个device执行的结果 +``` +./benchmark.x86_64 -round=20 -om_path=fcn_r50-d8_512x512_20k_voc12aug_bs1.om -device_id=0 -batch_size=1 +``` +PureInfer_perf_of_fcn_r50-d8_512x512_20k_voc12aug_bs1_in_device_0.txt: +``` +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_fcn_r50-d8_512x512_20k_voc12aug_bs1_in_device_0.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 16.2574samples/s, ave_latency: 61.5162ms +---------------------------------------------------------------- +``` +batch16的性能,执行20次纯推理取均值,统计吞吐率与其倒数时延(benchmark的时延是单个数据的推理时间),npu性能是一个device执行的结果 +``` +./benchmark.x86_64 -round=20 -om_path=fcn_r50-d8_512x512_20k_voc12aug_bs16.om -device_id=0 -batch_size=16 +``` +PureInfer_perf_of_fcn_r50-d8_512x512_20k_voc12aug_bs16_in_device_0.txt: +``` +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_fcn_r50-d8_512x512_20k_voc12aug_bs16_in_device_0.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 15.5282samples/s, ave_latency: 64.4083ms +---------------------------------------------------------------- +``` + +**性能优化:** +> 没有遇到性能不达标的问题,故不需要进行性能优化 + diff --git a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/get_info.py b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/get_info.py index b76d6739bcea5c528a031970f0e583e5b5644bd8..d5cab0450c20d502d0d15be2f9c0fceffa6a6191 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/get_info.py +++ b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/get_info.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/mmsegmentation_voc2012_postprocess.py b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/mmsegmentation_voc2012_postprocess.py index 298799e0073d82e9fbb022510a2bec908975429e..350c5088838ba3726200713721378cb6726f0941 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/mmsegmentation_voc2012_postprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/mmsegmentation_voc2012_postprocess.py @@ -1,243 +1,243 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import os -import os.path as osp -import torch -import mmcv -import numpy as np -from terminaltables import AsciiTable - -CLASSES = ('background', 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', - 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', - 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', - 'train', 'tvmonitor') - -PALETTE = [[0, 0, 0], [128, 0, 0], [0, 128, 0], [128, 128, 0], [0, 0, 128], - [128, 0, 128], [0, 128, 128], [128, 128, 128], [64, 0, 0], - [192, 0, 0], [64, 128, 0], [192, 128, 0], [64, 0, 128], - [192, 0, 128], [64, 128, 128], [192, 128, 128], [0, 64, 0], - [128, 64, 0], [0, 192, 0], [128, 192, 0], [0, 64, 128]] - - -def load_annotations(img_dir, ann_dir, split): - img_suffix = '.jpg' - seg_map_suffix = '.png' - img_infos = [] - if split is not None: - with open(split) as f: - for line in f: - img_name = line.strip() - img_info = dict(filename=img_name + img_suffix) - if ann_dir is not None: - seg_map = img_name + seg_map_suffix - img_info['ann'] = dict(seg_map=seg_map) - img_infos.append(img_info) - else: - for img in mmcv.scandir(img_dir, img_suffix, recursive=True): - img_info = dict(filename=img) - if ann_dir is not None: - seg_map = img.replace(img_suffix, seg_map_suffix) - img_info['ann'] = dict(seg_map=seg_map) - img_infos.append(img_info) - - return img_infos - - -def get_gt_seg_maps(img_infos, ann_dir): - """Get ground truth segmentation maps for evaluation.""" - gt_seg_maps = [] - for img_info in img_infos: - seg_map = osp.join(ann_dir, img_info['ann']['seg_map']) - gt_seg_map = mmcv.imread( - seg_map, flag='unchanged', backend='pillow') - gt_seg_maps.append(gt_seg_map) - return gt_seg_maps - - -def voc2012_evaluation(results, gt_seg_maps): - metric = ['mIoU'] - eval_results = {} - - num_classes = len(CLASSES) - ignore_index = 255 - label_map = dict() - reduce_zero_label = False - - num_imgs = len(results) - assert len(gt_seg_maps) == num_imgs - total_area_intersect = torch.zeros((num_classes,), dtype=torch.float64) - total_area_union = torch.zeros((num_classes,), dtype=torch.float64) - total_area_pred_label = torch.zeros((num_classes,), dtype=torch.float64) - total_area_label = torch.zeros((num_classes,), dtype=torch.float64) - for i in range(num_imgs): - if isinstance(results[i], str): - pred_label = torch.from_numpy(np.load(results[i])) - else: - pred_label = torch.from_numpy((results[i])) - - if isinstance(gt_seg_maps[i], str): - label = torch.from_numpy( - mmcv.imread(gt_seg_maps[i], flag='unchanged', backend='pillow')) - else: - label = torch.from_numpy(gt_seg_maps[i]) - - if label_map is not None: - for old_id, new_id in label_map.items(): - label[label == old_id] = new_id - if reduce_zero_label: - label[label == 0] = 255 - label = label - 1 - label[label == 254] = 255 - - mask = (label != ignore_index) - pred_label = pred_label[mask] - label = label[mask] - - intersect = pred_label[pred_label == label] - area_intersect = torch.histc( - intersect.float(), bins=(num_classes), min=0, max=num_classes - 1) - area_pred_label = torch.histc( - pred_label.float(), bins=(num_classes), min=0, max=num_classes - 1) - area_label = torch.histc( - label.float(), bins=(num_classes), min=0, max=num_classes - 1) - area_union = area_pred_label + area_label - area_intersect - - total_area_intersect += area_intersect - total_area_union += area_union - total_area_pred_label += area_pred_label - total_area_label += area_label - all_acc = total_area_intersect.sum() / total_area_label.sum() - acc = total_area_intersect / total_area_label - ret_metrics = [all_acc, acc] - iou = total_area_intersect / total_area_union - ret_metrics.append(iou) - ret_metrics = [metric.numpy() for metric in ret_metrics] - - class_table_data = [['Class'] + [m[1:] for m in metric] + ['Acc']] - class_names = CLASSES - - ret_metrics_round = [ - np.round(ret_metric * 100, 2) for ret_metric in ret_metrics - ] - for i in range(num_classes): - class_table_data.append([class_names[i]] + - [m[i] for m in ret_metrics_round[2:]] + - [ret_metrics_round[1][i]]) - summary_table_data = [['Scope'] + - ['m' + head - for head in class_table_data[0][1:]] + ['aAcc']] - ret_metrics_mean = [ - np.round(np.nanmean(ret_metric) * 100, 2) - for ret_metric in ret_metrics - ] - summary_table_data.append(['global'] + ret_metrics_mean[2:] + - [ret_metrics_mean[1]] + - [ret_metrics_mean[0]]) - - print('per class results:') - table = AsciiTable(class_table_data) - print('\n' + table.table) - print('Summary:') - table = AsciiTable(summary_table_data) - print('\n' + table.table) - - for i in range(1, len(summary_table_data[0])): - eval_results[summary_table_data[0] - [i]] = summary_table_data[1][i] / 100.0 - for idx, sub_metric in enumerate(class_table_data[0][1:], 1): - for item in class_table_data[1:]: - eval_results[str(sub_metric) + '.' + - str(item[0])] = item[idx] / 100.0 - return eval_results - - -def postprocess_mask(mask, image_size, net_input_width, net_input_height): - w = image_size[0] - h = image_size[1] - scale = min(net_input_width / w, net_input_height / h) - - pad_w = net_input_width - w * scale - pad_h = net_input_height - h * scale - pad_left = (pad_w // 2) - pad_top = (pad_h // 2) - if pad_top < 0: - pad_top = 0 - if pad_left < 0: - pad_left = 0 - pad_left = int(pad_left) - pad_top = int(pad_top) - a = int(500 - pad_top) - b = int(500 - pad_left) - mask = mask[pad_top:a, pad_left:b] - import torch.nn.functional as F - mask = torch.from_numpy(mask).to(dtype=torch.float32) - mask = mask.expand((1, 1, mask.size(0), mask.size(1))) - mask = F.interpolate(mask, size=(int(h), int(w)), mode='bilinear', align_corners=False) - - mask = mask.squeeze().to(dtype=torch.int32).numpy() - return mask - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0") - parser.add_argument("--test_annotation", default="./voc12_jpg.info") - parser.add_argument("--img_dir", default="/opt/npu/VOCdevkit/VOC2012/JPEGImages") - parser.add_argument("--ann_dir", default="/opt/npu/VOCdevkit/VOC2012/SegmentationClass") - parser.add_argument("--split", default="/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt") - parser.add_argument("--net_input_width", default=500) - parser.add_argument("--net_input_height", default=500) - args = parser.parse_args() - - # generate dict according to annotation file for query resolution - # load width and height of input images - img_size_dict = dict() - - with open(args.test_annotation)as f: - for line in f.readlines(): - temp = line.split(" ") - img_file_path = temp[1] - img_name = temp[1].split("/")[-1].split(".")[0] - img_width = int(temp[2]) - img_height = int(temp[3]) - img_size_dict[img_name] = (img_width, img_height, img_file_path) - - # read bin file for generate predict result - bin_path = args.bin_data_path - total_img = set([name[:name.rfind('_')]for name in os.listdir(bin_path) if "bin" in name]) - - res_buff = [] - for bin_file in sorted(total_img): - path_base = os.path.join(bin_path, bin_file) - # load all segected output tensor - - output = np.fromfile(path_base + "_" + str(1) + ".bin", dtype="int32") - output = np.reshape(output, [500, 500]) - current_img_size = img_size_dict[bin_file] - output = postprocess_mask(output, img_size_dict[bin_file], 500, 500) - res_buff.append(output) - - seg_result = res_buff - # ground truth - img_infos = load_annotations(args.img_dir, args.ann_dir, split=args.split) - gt_seg_maps = get_gt_seg_maps(img_infos, args.ann_dir) - seg_result = voc2012_evaluation(seg_result, gt_seg_maps) - - - with open('./voc_seg_result.txt', 'w') as f: - for key, value in seg_result.items(): - f.write(key + ': ' + str(value) + '\n') - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import os +import os.path as osp +import torch +import mmcv +import numpy as np +from terminaltables import AsciiTable + +CLASSES = ('background', 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', + 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', + 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', + 'train', 'tvmonitor') + +PALETTE = [[0, 0, 0], [128, 0, 0], [0, 128, 0], [128, 128, 0], [0, 0, 128], + [128, 0, 128], [0, 128, 128], [128, 128, 128], [64, 0, 0], + [192, 0, 0], [64, 128, 0], [192, 128, 0], [64, 0, 128], + [192, 0, 128], [64, 128, 128], [192, 128, 128], [0, 64, 0], + [128, 64, 0], [0, 192, 0], [128, 192, 0], [0, 64, 128]] + + +def load_annotations(img_dir, ann_dir, split): + img_suffix = '.jpg' + seg_map_suffix = '.png' + img_infos = [] + if split is not None: + with open(split) as f: + for line in f: + img_name = line.strip() + img_info = dict(filename=img_name + img_suffix) + if ann_dir is not None: + seg_map = img_name + seg_map_suffix + img_info['ann'] = dict(seg_map=seg_map) + img_infos.append(img_info) + else: + for img in mmcv.scandir(img_dir, img_suffix, recursive=True): + img_info = dict(filename=img) + if ann_dir is not None: + seg_map = img.replace(img_suffix, seg_map_suffix) + img_info['ann'] = dict(seg_map=seg_map) + img_infos.append(img_info) + + return img_infos + + +def get_gt_seg_maps(img_infos, ann_dir): + """Get ground truth segmentation maps for evaluation.""" + gt_seg_maps = [] + for img_info in img_infos: + seg_map = osp.join(ann_dir, img_info['ann']['seg_map']) + gt_seg_map = mmcv.imread( + seg_map, flag='unchanged', backend='pillow') + gt_seg_maps.append(gt_seg_map) + return gt_seg_maps + + +def voc2012_evaluation(results, gt_seg_maps): + metric = ['mIoU'] + eval_results = {} + + num_classes = len(CLASSES) + ignore_index = 255 + label_map = dict() + reduce_zero_label = False + + num_imgs = len(results) + assert len(gt_seg_maps) == num_imgs + total_area_intersect = torch.zeros((num_classes,), dtype=torch.float64) + total_area_union = torch.zeros((num_classes,), dtype=torch.float64) + total_area_pred_label = torch.zeros((num_classes,), dtype=torch.float64) + total_area_label = torch.zeros((num_classes,), dtype=torch.float64) + for i in range(num_imgs): + if isinstance(results[i], str): + pred_label = torch.from_numpy(np.load(results[i])) + else: + pred_label = torch.from_numpy((results[i])) + + if isinstance(gt_seg_maps[i], str): + label = torch.from_numpy( + mmcv.imread(gt_seg_maps[i], flag='unchanged', backend='pillow')) + else: + label = torch.from_numpy(gt_seg_maps[i]) + + if label_map is not None: + for old_id, new_id in label_map.items(): + label[label == old_id] = new_id + if reduce_zero_label: + label[label == 0] = 255 + label = label - 1 + label[label == 254] = 255 + + mask = (label != ignore_index) + pred_label = pred_label[mask] + label = label[mask] + + intersect = pred_label[pred_label == label] + area_intersect = torch.histc( + intersect.float(), bins=(num_classes), min=0, max=num_classes - 1) + area_pred_label = torch.histc( + pred_label.float(), bins=(num_classes), min=0, max=num_classes - 1) + area_label = torch.histc( + label.float(), bins=(num_classes), min=0, max=num_classes - 1) + area_union = area_pred_label + area_label - area_intersect + + total_area_intersect += area_intersect + total_area_union += area_union + total_area_pred_label += area_pred_label + total_area_label += area_label + all_acc = total_area_intersect.sum() / total_area_label.sum() + acc = total_area_intersect / total_area_label + ret_metrics = [all_acc, acc] + iou = total_area_intersect / total_area_union + ret_metrics.append(iou) + ret_metrics = [metric.numpy() for metric in ret_metrics] + + class_table_data = [['Class'] + [m[1:] for m in metric] + ['Acc']] + class_names = CLASSES + + ret_metrics_round = [ + np.round(ret_metric * 100, 2) for ret_metric in ret_metrics + ] + for i in range(num_classes): + class_table_data.append([class_names[i]] + + [m[i] for m in ret_metrics_round[2:]] + + [ret_metrics_round[1][i]]) + summary_table_data = [['Scope'] + + ['m' + head + for head in class_table_data[0][1:]] + ['aAcc']] + ret_metrics_mean = [ + np.round(np.nanmean(ret_metric) * 100, 2) + for ret_metric in ret_metrics + ] + summary_table_data.append(['global'] + ret_metrics_mean[2:] + + [ret_metrics_mean[1]] + + [ret_metrics_mean[0]]) + + print('per class results:') + table = AsciiTable(class_table_data) + print('\n' + table.table) + print('Summary:') + table = AsciiTable(summary_table_data) + print('\n' + table.table) + + for i in range(1, len(summary_table_data[0])): + eval_results[summary_table_data[0] + [i]] = summary_table_data[1][i] / 100.0 + for idx, sub_metric in enumerate(class_table_data[0][1:], 1): + for item in class_table_data[1:]: + eval_results[str(sub_metric) + '.' + + str(item[0])] = item[idx] / 100.0 + return eval_results + + +def postprocess_mask(mask, image_size, net_input_width, net_input_height): + w = image_size[0] + h = image_size[1] + scale = min(net_input_width / w, net_input_height / h) + + pad_w = net_input_width - w * scale + pad_h = net_input_height - h * scale + pad_left = (pad_w // 2) + pad_top = (pad_h // 2) + if pad_top < 0: + pad_top = 0 + if pad_left < 0: + pad_left = 0 + pad_left = int(pad_left) + pad_top = int(pad_top) + a = int(500 - pad_top) + b = int(500 - pad_left) + mask = mask[pad_top:a, pad_left:b] + import torch.nn.functional as F + mask = torch.from_numpy(mask).to(dtype=torch.float32) + mask = mask.expand((1, 1, mask.size(0), mask.size(1))) + mask = F.interpolate(mask, size=(int(h), int(w)), mode='bilinear', align_corners=False) + + mask = mask.squeeze().to(dtype=torch.int32).numpy() + return mask + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--bin_data_path", default="./result/dumpOutput_device0") + parser.add_argument("--test_annotation", default="./voc12_jpg.info") + parser.add_argument("--img_dir", default="/opt/npu/VOCdevkit/VOC2012/JPEGImages") + parser.add_argument("--ann_dir", default="/opt/npu/VOCdevkit/VOC2012/SegmentationClass") + parser.add_argument("--split", default="/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt") + parser.add_argument("--net_input_width", default=500) + parser.add_argument("--net_input_height", default=500) + args = parser.parse_args() + + # generate dict according to annotation file for query resolution + # load width and height of input images + img_size_dict = dict() + + with open(args.test_annotation)as f: + for line in f.readlines(): + temp = line.split(" ") + img_file_path = temp[1] + img_name = temp[1].split("/")[-1].split(".")[0] + img_width = int(temp[2]) + img_height = int(temp[3]) + img_size_dict[img_name] = (img_width, img_height, img_file_path) + + # read bin file for generate predict result + bin_path = args.bin_data_path + total_img = set([name[:name.rfind('_')]for name in os.listdir(bin_path) if "bin" in name]) + + res_buff = [] + for bin_file in sorted(total_img): + path_base = os.path.join(bin_path, bin_file) + # load all segected output tensor + + output = np.fromfile(path_base + "_" + str(1) + ".bin", dtype="int32") + output = np.reshape(output, [500, 500]) + current_img_size = img_size_dict[bin_file] + output = postprocess_mask(output, img_size_dict[bin_file], 500, 500) + res_buff.append(output) + + seg_result = res_buff + # ground truth + img_infos = load_annotations(args.img_dir, args.ann_dir, split=args.split) + gt_seg_maps = get_gt_seg_maps(img_infos, args.ann_dir) + seg_result = voc2012_evaluation(seg_result, gt_seg_maps) + + + with open('./voc_seg_result.txt', 'w') as f: + for key, value in seg_result.items(): + f.write(key + ': ' + str(value) + '\n') + diff --git a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/mmsegmentation_voc2012_preprocess.py b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/mmsegmentation_voc2012_preprocess.py index e8e5074b82c6e91b71922e3a521cdca1d0119527..22cd2b7b53971fb4695c6789a728ffc811bd8679 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/mmsegmentation_voc2012_preprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/mmsegmentation_voc2012_preprocess.py @@ -1,95 +1,95 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import numpy as np -import os -import cv2 -import argparse -import mmcv -import torch - - -dataset_config = { - 'mean': (123.675, 116.28, 103.53), - 'std': (58.395, 57.12, 57.375) -} - - -tensor_height = 500 -tensor_width = 500 - - -def resize(img, size): - old_h = img.shape[0] - old_w = img.shape[1] - scale_ratio = min(size[0] / old_w, size[1] / old_h) - new_w = int(np.floor(old_w * scale_ratio)) - new_h = int(np.floor(old_h * scale_ratio)) - resized_img = mmcv.imresize(img, (new_w, new_h), backend='cv2') - return resized_img - - -def voc2012_preprocess(input_image, output_bin_path): - img_name = input_image.split('/')[-1] - bin_name = img_name.split('.')[0] + ".bin" - bin_fl = os.path.join(output_bin_path, bin_name) - - one_img = mmcv.imread(os.path.join(input_image), backend='cv2') - one_img = resize(one_img, (tensor_width, tensor_height)) - - mean = np.array(dataset_config['mean'], dtype=np.float32) - std = np.array(dataset_config['std'], dtype=np.float32) - one_img = mmcv.imnormalize(one_img, mean, std) - - h = one_img.shape[0] - w = one_img.shape[1] - pad_left = (tensor_width - w) // 2 - pad_top = (tensor_height - h) // 2 - pad_right = tensor_width - pad_left - w - pad_bottom = tensor_height - pad_top - h - one_img = mmcv.impad(one_img, padding=(pad_left, pad_top, pad_right, pad_bottom), pad_val=0) - - one_img = one_img.transpose(2, 0, 1) - one_img.tofile(bin_fl) - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='preprocess of FCN-8s pytorch model') - parser.add_argument("--image_folder_path", default="/opt/npu/VOCdevkit/VOC2012/JPEGImages/", - help='image of dataset') - parser.add_argument("--split", default="/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt") - parser.add_argument("--bin_folder_path", default="./voc12_bin/", help='Preprocessed image buffer') - flags = parser.parse_args() - - if not os.path.exists(flags.bin_folder_path): - os.makedirs(flags.bin_folder_path) - - split = flags.split - img_suffix = '.jpg' - img_infos = [] - if split is not None: - with open(split) as f: - for line in f: - img_name = line.strip() - img_info = img_name + img_suffix - img_infos.append(img_info) - - images = os.listdir(flags.image_folder_path) - for image_name in images: - - if not (image_name.endswith(".jpeg") or image_name.endswith(".JPEG") or image_name.endswith(".jpg") and image_name in img_infos): - continue - print("start to process image {}....".format(image_name)) - path_image = os.path.join(flags.image_folder_path, image_name) - voc2012_preprocess(path_image, flags.bin_folder_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +import os +import cv2 +import argparse +import mmcv +import torch + + +dataset_config = { + 'mean': (123.675, 116.28, 103.53), + 'std': (58.395, 57.12, 57.375) +} + + +tensor_height = 500 +tensor_width = 500 + + +def resize(img, size): + old_h = img.shape[0] + old_w = img.shape[1] + scale_ratio = min(size[0] / old_w, size[1] / old_h) + new_w = int(np.floor(old_w * scale_ratio)) + new_h = int(np.floor(old_h * scale_ratio)) + resized_img = mmcv.imresize(img, (new_w, new_h), backend='cv2') + return resized_img + + +def voc2012_preprocess(input_image, output_bin_path): + img_name = input_image.split('/')[-1] + bin_name = img_name.split('.')[0] + ".bin" + bin_fl = os.path.join(output_bin_path, bin_name) + + one_img = mmcv.imread(os.path.join(input_image), backend='cv2') + one_img = resize(one_img, (tensor_width, tensor_height)) + + mean = np.array(dataset_config['mean'], dtype=np.float32) + std = np.array(dataset_config['std'], dtype=np.float32) + one_img = mmcv.imnormalize(one_img, mean, std) + + h = one_img.shape[0] + w = one_img.shape[1] + pad_left = (tensor_width - w) // 2 + pad_top = (tensor_height - h) // 2 + pad_right = tensor_width - pad_left - w + pad_bottom = tensor_height - pad_top - h + one_img = mmcv.impad(one_img, padding=(pad_left, pad_top, pad_right, pad_bottom), pad_val=0) + + one_img = one_img.transpose(2, 0, 1) + one_img.tofile(bin_fl) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='preprocess of FCN-8s pytorch model') + parser.add_argument("--image_folder_path", default="/opt/npu/VOCdevkit/VOC2012/JPEGImages/", + help='image of dataset') + parser.add_argument("--split", default="/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt") + parser.add_argument("--bin_folder_path", default="./voc12_bin/", help='Preprocessed image buffer') + flags = parser.parse_args() + + if not os.path.exists(flags.bin_folder_path): + os.makedirs(flags.bin_folder_path) + + split = flags.split + img_suffix = '.jpg' + img_infos = [] + if split is not None: + with open(split) as f: + for line in f: + img_name = line.strip() + img_info = img_name + img_suffix + img_infos.append(img_info) + + images = os.listdir(flags.image_folder_path) + for image_name in images: + + if not (image_name.endswith(".jpeg") or image_name.endswith(".JPEG") or image_name.endswith(".jpg") and image_name in img_infos): + continue + print("start to process image {}....".format(image_name)) + path_image = os.path.join(flags.image_folder_path, image_name) + voc2012_preprocess(path_image, flags.bin_folder_path) diff --git a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/requirements.txt b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/requirements.txt index b61b7bcdad2d8b509e3de4f97bb4d74ffcfe6429..f86ad403f35f1e158cb4397d24e2f69c92d9aa92 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/requirements.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/requirements.txt @@ -1,5 +1,5 @@ -torch == 1.8.0 -torchvision == 0.9.0 -onnx == 1.9.0 -numpy == 1.20.1 +torch == 1.8.0 +torchvision == 0.9.0 +onnx == 1.9.0 +numpy == 1.20.1 opencv-python == 4.5.2.52 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/test/README.md b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/test/README.md index 127a2e645ffd5beab55197bbc48bca6a6eac26f4..fa794daeac35f8ae48411862a030b21b435d9261 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/test/README.md +++ b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/test/README.md @@ -1,31 +1,31 @@ -环境准备: - -1.数据集路径 -数据集统一放在/root/datasets/或/opt/npu/ -本模型数据集放在/opt/npu/ - -2.进入工作目录 -cd fcn-8s - -3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -pip3.7 install -r requirements.txt - -4.获取、修改和安装模型代码 -git clone https://github.com/open-mmlab/mmcv.git -cd mmcv -pip3.7 install -e . -cd .. -git clone https://github.com/open-mmlab/mmsegmentation.git -cd mmsegmentation -pip3.7 install -e . # or "python3.7 setup.py develop" -cd .. - -5.获取权重文件 -wget https://download.openmmlab.com/mmsegmentation/v0.5/fcn/fcn_r50-d8_512x512_20k_voc12aug/fcn_r50-d8_512x512_20k_voc12aug_20200617_010715-52dc5306.pth - -6.获取benchmark工具 -将将benchmark.x86_64,benchmark.aarch64放在当前目录 - -7.310上执行,执行时确保device空闲 -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/opt/npu/ +环境准备: + +1.数据集路径 +数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集放在/opt/npu/ + +2.进入工作目录 +cd fcn-8s + +3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +pip3.7 install -r requirements.txt + +4.获取、修改和安装模型代码 +git clone https://github.com/open-mmlab/mmcv.git +cd mmcv +pip3.7 install -e . +cd .. +git clone https://github.com/open-mmlab/mmsegmentation.git +cd mmsegmentation +pip3.7 install -e . # or "python3.7 setup.py develop" +cd .. + +5.获取权重文件 +wget https://download.openmmlab.com/mmsegmentation/v0.5/fcn/fcn_r50-d8_512x512_20k_voc12aug/fcn_r50-d8_512x512_20k_voc12aug_20200617_010715-52dc5306.pth + +6.获取benchmark工具 +将将benchmark.x86_64,benchmark.aarch64放在当前目录 + +7.310上执行,执行时确保device空闲 +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/opt/npu/ diff --git a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/test/parse.py b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/test/parse.py index a0f253b055047b199b33d4b65cdc79177b6b250b..27eae0d0acf98687edd95f1f024cf77c49cd4dc4 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/test/parse.py +++ b/ACL_PyTorch/contrib/cv/segmentation/FCN-8s/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/Fast_SCNN_pth2onnx.py b/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/Fast_SCNN_pth2onnx.py index b8ec935d0bf060ca35689a979e729094afa81cc6..f30505c1ae8bca8d0620db5323d69db19712ffa2 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/Fast_SCNN_pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/Fast_SCNN_pth2onnx.py @@ -1,46 +1,46 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import torch -import torch.onnx -from collections import OrderedDict -import sys -sys.path.append('./SegmenTron') -from segmentron.models.model_zoo import get_segmentation_model -from segmentron.utils.options import parse_args -from segmentron.config import cfg -import ssl - - -def pth2onnx(): - model = get_segmentation_model() - checkpoint = torch.load(args.pth_path, map_location='cpu') - model.load_state_dict(checkpoint) - model.eval() - input_names = ["image"] - output_names = ["output1"] - dynamic_axes = {'image': {0: '-1'}, 'output1': {0: '-1'}} - dummy_input1 = torch.randn(args.batch_size, 3, 1024, 2048) - output_file1 = args.onnx_name + '.onnx' - torch.onnx.export(model, dummy_input1, output_file1, input_names = input_names, output_names = output_names, opset_version=11, verbose=True) - print(args.onnx_name,"batchsize",args.batch_size," onnx has transformed successfully") - print('onnx export done.') - -if __name__ == "__main__": - args = parse_args() - args.config_file = 'SegmenTron/configs/cityscapes_fast_scnn.yaml' - cfg.update_from_file(args.config_file) - cfg.update_from_list(args.opts) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import torch +import torch.onnx +from collections import OrderedDict +import sys +sys.path.append('./SegmenTron') +from segmentron.models.model_zoo import get_segmentation_model +from segmentron.utils.options import parse_args +from segmentron.config import cfg +import ssl + + +def pth2onnx(): + model = get_segmentation_model() + checkpoint = torch.load(args.pth_path, map_location='cpu') + model.load_state_dict(checkpoint) + model.eval() + input_names = ["image"] + output_names = ["output1"] + dynamic_axes = {'image': {0: '-1'}, 'output1': {0: '-1'}} + dummy_input1 = torch.randn(args.batch_size, 3, 1024, 2048) + output_file1 = args.onnx_name + '.onnx' + torch.onnx.export(model, dummy_input1, output_file1, input_names = input_names, output_names = output_names, opset_version=11, verbose=True) + print(args.onnx_name,"batchsize",args.batch_size," onnx has transformed successfully") + print('onnx export done.') + +if __name__ == "__main__": + args = parse_args() + args.config_file = 'SegmenTron/configs/cityscapes_fast_scnn.yaml' + cfg.update_from_file(args.config_file) + cfg.update_from_list(args.opts) pth2onnx() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/README.md b/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/README.md index ddff64a5bc6f2355a460e676f974080946f4b514..ce5890527fd2a50d9fb3cd3c84eb407ed9f3ebd3 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/README.md +++ b/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/README.md @@ -1,369 +1,369 @@ -# FastSCNN推理说明 - -## 1 模型概述 - -- **[论文地址](https://arxiv.org/abs/1902.04502)** -- **[代码地址](https://gitee.com/wang-chaojiemayj/modelzoo/tree/master/contrib/PyTorch/Research/cv/image_segmentation/FastSCNN)** - -### 1.1 论文地址 - -[FastSCNN论文](https://arxiv.org/abs/1902.04502) - -### 1.2 代码地址 - -[FascSCNN代码](https://gitee.com/wang-chaojiemayj/modelzoo/tree/master/contrib/PyTorch/Research/cv/image_segmentation/FastSCNN) - -branch:master - -commitid:e86409484cf89467a569be43acee1b3f06b92305 - - -## 2 环境说明 - -- 深度学习框架 -- python第三方库 - -### 2.1 深度学习框架 - -``` -python3.7.5 -CANN 5.0.2 - -pytorch >= 1.5.0 -torchvision >= 0.6.0 -onnx == 1.7.0 -onnx-simplifier == 0.3.6 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.21.1 -Pillow == 8.3.0 -opencv-python == 4.5.2.54 -``` - -## 3 模型转换 - -- pth转om模型 - -### 3.1 pth转om模型 - -1.获取pth权重文件 - -获取权重文件方法,可从Ascend modelzoo FastSCNN_ACL_Pytorch 模型压缩包获取 - -md5sum:efc7247270298f3f57e88375011b52ee - -2.FastSCNN模型已经上传至代码仓,使用git工具获取FastSCNN模型代码 -使用gitclone获取模型训练的代码,切换到tuili分支。 - -``` -git clone https://gitee.com/wang-chaojiemayj/modelzoo.git -cd modelzoo -git checkout tuili -``` - -进入FastSCNN目录 - -``` -cd ./contrib/ACL_PyTorch/Research/cv/segmentation/FastSCNN -``` - -使用gitclone下载模型代码 - -``` -git clone https://github.com/LikeLy-Journey/SegmenTron -``` - -由于onnx不支持AdaptiveAvgPool算子,需要使用module.patch修改module.py。 -将FastSCNN目录下的module.patch放到FastSCNN/SegmenTron目录下 -执行 - -``` -cd ./SegmenTron -git apply module.patch -cd .. -``` - -3.执行pth2om脚本,生成om模型文件 - -ascend-toolkit版本:5.0.2 -``` -bs1: -python3.7 Fast_SCNN_pth2onnx.py --pth_path best_model.pth --onnx_name fast_scnn_bs1 --batch_size 1 -bs16: -python3.7 Fast_SCNN_pth2onnx.py --pth_path best_model.pth --onnx_name fast_scnn_bs16 --batch_size 16 - **bs4:bs16无法导出时使用 -python3.7 Fast_SCNN_pth2onnx.py --pth_path best_model.pth --onnx_name fast_scnn_bs4 --batch_size 4** -``` -参数说明: ---pth_path:pth权重文件的路径,可自行设置,默认值为best_model.pth; ---onnx_name:需要转出的onnx模型的名称,可自行设置,默认值为fast_scnn_bs1(由于本模型不支持动态batch,推荐在模型名后加后缀,如‘_bs1’,用以区分不同batch_size的onnx模型); ---batch_size:导出的onnx模型的batch_size,可自行设置,默认值为1。 - -onnx转出om - -bs1: -``` -source env.sh(注意,latest是一个软连接,请将服务器中的/usr/local/Ascend/ascend-toolkit/latest 指向5.0.2版本的CANN包) -atc --framework=5 --model=fast_scnn_bs1.onnx --output=fast_scnn_bs1 --output_type=FP16 --input_format=NCHW --input_shape="image:1,3,1024,2048" --log=debug --soc_version=Ascend310 -``` -bs16: -``` -source env.sh -atc --framework=5 --model=fast_scnn_bs16.onnx --output=fast_scnn_bs16 --output_type=FP16 --input_format=NCHW --input_shape="image:16,3,1024,2048" --log=debug --soc_version=Ascend310 -``` -bs4:(bs16无法离线推理时使用) -``` -source env.sh -atc --framework=5 --model=fast_scnn_bs4.onnx --output=fast_scnn_bs4 --output_type=FP16 --input_format=NCHW --input_shape="image:4,3,1024,2048" --log=debug --soc_version=Ascend310 -``` - - -## 4 数据集预处理 - -- 数据集获取 -- 数据预处理 -- 生成数据集信息文件 - -### 4.1 数据集获取 - -本模型支持cityscapes leftImg8bit的500张验证集。用户需要下载[leftImg8bit_trainvaltest.zip](http://www.cityscapes-dataset.com/downloads)和[gtFine_trainvaltest.zip](http://www.cityscapes-dataset.com/downloads)数据集,解压,将两个数据集放在/opt/npu/datasets/cityscapes/目录下。推荐使用软连接,可以节省时间,数据集目录如下。 - -``` -|opt--npu--datasets -| |-- cityscapes -| | |-- gtFine -| | | |-- test -| | | |-- train -| | | |-- val -| | |-- leftImg8bit -| | |-- test -| | |-- train -| | |-- val -``` - - -### 4.2 数据集预处理 - -在modelzoo/contrib/ACL_PyTorch/Research /cv/segmentation/FastSCNN目录创建软连接 - -``` -ln -s /opt/npu/datasets datasets -``` - -运行Fast_SCNN_preprocess.py - -``` -python3.7 Fast_SCNN_preprocess.py -``` - -数据预处理的结果会保存在/opt/npu/prep_datset -预处理之后的二进制文件目录如下: -/opt/npu/prep_dataset/datasets/leftImg8bit/ -/opt/npu/prep_dataset/datasets/gtFine/ -在modelzoo/contrib/ACL_PyTorch/Research/cv/segmentation/FastSCNN目录下创建软连接 - -``` -ln -s /opt/npu/prep_dataset prep_dataset -``` - -### 4.3 生成数据集信息文件 - -1.生成数据集信息文件脚本gen_dataset_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 - -``` -python3.7 gen_dataset_info.py -``` - -## 5 离线推理 - -- benchmark工具概述 -- 离线推理 - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.1 推理benchmark工具用户指南 01 - -### 5.2 离线推理 - -1.设置环境变量 - -``` -source env.sh -``` - -2.执行离线推理 -bs1: -``` -./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=fast_scnn_bs1.om -input_text_path=./fast_scnn_prep_bin.info -input_width=2048 -input_height=1024 -output_binary=True -useDvpp=False./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=4 -om_path=fast_scnn_bs4.om -input_text_path=./fast_scnn_prep_bin.info -input_width=2048 -input_height=1024 -output_binary=True -useDvpp=False -``` -bs16: -``` -./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=16 -om_path=./fast_scnn_bs16.om -input_text_path=./fast_scnn_prep_bin.info -input_width=2048 -input_height=1024 -output_binary=True -useDvpp=False -``` -bs4:(bs16无法离线推理时使用) -``` -./benchmark.x86_64 -model_type=vision -device_id=2 -batch_size=4 -om_path=fast_scnn_bs4.om -input_text_path=fast_scnn_prep_bin.info -input_width=2048 -input_height=1024 -output_binary=True -useDvpp=False -``` -``` -参数说明: -需要更改的参数 --device_id:使用的Ascend310处理器的卡号,可选0、1、2、3,尽量选择不同的卡号进行推理,若-device_id=0,离线推理结果会保存在./result/dumpOut -put_device0中,device0中的0代表卡号是0; --batch_size:om模型的batch_size; --om_path: 需要进行离线推理的om模型的路径; -不需要更改的参数: --input_text_path:om模型的二进制输入图片的路径信息文件的路径; --input_width:输入图片的宽度,FastSCNN模型是2048; --input_heigh:输入图片的高度,FastSCNN模型是1024; --output_binary:benchmark的输出是二进制文件还是txt文件,True代表输出为二进制文件; --useDvpp:是否使用Dvpp工具,FastSCNN模型不使用Dvpp工具,设置为False; -``` -## 6 精度对比 - -- 离线推理精度 -- 开源精度 -- 开源精度对比 - -### 6.1 离线推理精度统计 - -后处理统计mIoU - -调用cityscapes_acc_eval.py脚本推理结果与label比对,获取pixAcc和mIoU数据,结果保存在fast_scnn_bs1.log和fast_scnn_bs4.log - -``` -python3.7 cityscapes_acc_eval.py result/dumpOutput_device0/ ./out >fast_scnn_bs1.log -python3.7 cityscapes_acc_eval.py result/dumpOutput_device1/ ./out >fast_scnn_bs4.log -``` - -第一个为benchmark输出目录,第二个为输出重定向文件名 - -``` -pixAcc:94.29% mIoU:64.43 -``` - -经过对bs1与bs4的om测试,本模型batch1的精度与batch4的精度一致,精度数据如上 - -### 6.2 开源精度 - -pth精度 - -``` -Model pixAcc mIoU -FastSCNN 93.877% 64.46 -``` - -### 6.3 精度对比 - -将得到的om模型离线推理精度与pth精度作比较,精度下降不超过0.5%,故精度达标 - -## 7 性能对比 - -- NPU性能数据 -- T4性能数据 -- 性能对比 - -### 7.1 npu性能数据 - -1.benchmark工具在整个数据集上推理获得性能数据。 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: - -``` -[e2e] throughputRate: 0.99593, latency: 502043[data read] throughputRate: 1.62003, moduleLatency: 617.273[preprocess] throughputRate: 1.20942, moduleLatency: 826.844[inference] throughputRate: 1.02697, Interface throughputRate: 5.5718, moduleLatency: 973.739[postprocess] throughputRate: 0.999452, moduleLatency: 1000.55 -``` - -Interface throughputRate: 5.5718,5.5718x4=22.286既是batch1 310单卡吞吐率 - -batch4的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_4_device_1.txt: - -``` -[e2e] throughputRate: 0.429745, latency: 1.16348e+06[data read] throughputRate: 0.673692, moduleLatency: 1484.36[preprocess] throughputRate: 0.525523, moduleLatency: 1902.86[inference] throughputRate: 0.477698, Interface throughputRate: 5.59273, moduleLatency: 2100.2[postprocess] throughputRate: 0.107216, moduleLatency: 9327 -``` - -Interface throughputRate: 5.59273,5.59273x4=22.37092既是batch16 310单卡吞吐率 - - -### 7.2 T4性能数据 - -在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2 -batch1性能: - -``` -trtexec --onnx=fast_scnn_bs1.onnx --fp16 --shapes=image:1x3x1024x2048 --threads -``` - -``` -[07/20/2021-01:49:12] [I] GPU Compute[07/20/2021-01:49:12] [I] min: 6.1626 ms[07/20/2021-01:49:12] [I] max: 6.18018 ms[07/20/2021-01:49:12] [I] mean: 6.17022 ms[07/20/2021-01:49:12] [I] median: 6.17062 ms[07/20/2021-01:49:12] [I] percentile: 6.18018 ms at 99%[07/20/2021-01:49:12] [I] total compute time: 0.265319 s -``` - -batch1 t4单卡吞吐率:1000/(6.17022/1)=162.068fps - -batch4性能: - -``` -trtexec --onnx=fast_scnn_bs4.onnx --fp16 --shapes=image:4x3x1024x2048 --threads -``` - -``` -[08/25/2021-05:18:21] [I] GPU Compute[08/25/2021-05:18:21] [I] min: 23.7666 ms[08/25/2021-05:18:21] [I] max: 24.3643 ms[08/25/2021-05:18:21] [I] mean: 24.0295 ms[08/25/2021-05:18:21] [I] median: 23.9731 ms[08/25/2021-05:18:21] [I] percentile: 24.3643 ms at 99%[08/25/2021-05:18:21] [I] total compute time: 0.288354 s -``` - -batch4 t4单卡吞吐率:1000/(24.0295/4)=166.46fps - -### 7.3 性能对比 - -batch1:5.5718x4 < 1000/(6.17022/1) -batch2:5.59273x4 <1000/(24.0295/4) -310单个device的吞吐率乘4即单卡吞吐率比T4单卡的吞吐率小,故310性能低于T4性能,性能不达标。 -对于batch1与batch4,310性能均低于T4性能,该模型放在contrib/ACL_PyTorch/Research目录下。 -**性能优化:** - -测试版本:CANN 5.0.2 - -目前可行的解决方案有三个: - -(1)优化TransData,修改five_2_four.py和four_2_five.py - -(2)输出节点由float32改为float16 - -(3)模型中Resize节点的mode由双线性为最近邻 - -具体优化方法如下: - -(1)修改five_2_four.py和four_2_five.py从profiling数据的op_statistic_0_1.csv看出影响性能的是TransData,ResizeBilinearV2D,AvgPoolV2算子。从op_summary_0_1.csv可以看出单个TransData的aicore耗时,确定可以可以优化。 - -``` -five_2_four.py:9928 修改如下: elif dst_format.lower() == "nchw" and dst_shape in [[2560, 512, 4, 26], [2560, 512, 1, 26], [2560, 256, 8, 25],[16, 240, 7, 7], [16, 120, 14, 14], [1, 128, 32, 64], [1, 19, 1024, 2048], [2, 128, 32, 64], [2, 19, 1024, 2048]]: -``` - -``` - four_2_five.py:1219 修改如下: if src_format.upper() == "NCHW" and shape_input in [[16, 240, 7, 7], [16, 120, 14, 14],[1, 1, 1024, 2048, 16], [1, 8, 32, 64, 16], [2, 1, 1024, 2048, 16], [2, 8, 32, 64, 16]] and dtype_input == "float16": -``` - -(2)指定输出为fp16: - -``` -atc --framework=5 --model=fast_scnn_bs1_sim.onnx --output=fast_scnn_bs1 --output_type=FP16 --input_format=NCHW --input_shape="image:1,3,1024,2048" --log=debug --soc_version=Ascend310python3.7.5 -m onnxsim --input-shape="2,3,1024,2048" fast_scnn_bs2.onnx fast_scnn_bs2_sim.onnx --skip-optimizationatc --framework=5 --model=fast_scnn_bs2_sim.onnx --output=fast_scnn_bs2 --output_type=FP16 --input_format=NCHW --input_shape="image:2,3,1024,2048" --log=debug --soc_version=Ascend310 -``` - -(3)模型中Resize节点的mode由双线性为最近邻 - -``` -newnode229 = onnx.helper.make_node( 'Resize', name='Resize_229', inputs=['549', '560', '561', '559'], outputs=['562'], coordinate_transformation_mode='align_corners', cubic_coeff_a=-0.75, mode='nearest', nearest_mode='floor')newnode245 = onnx.helper.make_node( 'Resize', name='Resize_245', inputs=['566', '577', '578', '576'], outputs=['579'], coordinate_transformation_mode='align_corners', cubic_coeff_a=-0.75, mode='nearest', nearest_mode='floor')graph.node.remove(model.graph.node[126])graph.node.insert(126,newnode126)graph.node.remove(model.graph.node[144])graph.node.insert(144,newnode144)graph.node.remove(model.graph.node[162])graph.node.insert(162,newnode162)graph.node.remove(model.graph.node[180])graph.node.insert(180,newnode180)graph.node.remove(model.graph.node[185])graph.node.insert(185,newnode185)graph.node.remove(model.graph.node[213])graph.node.insert(213,newnode213)graph.node.remove(model.graph.node[229])graph.node.insert(229,newnode229)graph.node.remove(model.graph.node[245])graph.node.insert(245,newnode245)onnx.checker.check_model(model)onnx.save(model, 'bs1_resized.onnx') -``` - -(4)性能、精度统计 - -| 方法 | 精度 | 性能 | -| ------------------------------------------------- | --------------------------- | --------------------------- | -| 未优化 | | | -| 优化TransData,修改five_2_four.py和four_2_five.py | bs1:mIoU64.46;bs2:mIoU64.46 | bs1:4.135fps;bs2:6.265fps | -| 输出节点由float32改为float16 | bs1:mIoU64.43;bs2:mIoU64.43 | bs1:22.518fps;bs2:22.694fps | -| 模型中Resize节点的mode由双线性为最近邻 | bs1:mIoU60.41;bs1:mIoU60.41 | bs1:7.747fps;bs2:14.046fps | - -8.本模型经过指定输出结点为fp16后,精度为64.43,pth精度为64.46,精度达标;性能提高到22fps左右,故本次pr提交的模型输出为结点fp16。 - +# FastSCNN推理说明 + +## 1 模型概述 + +- **[论文地址](https://arxiv.org/abs/1902.04502)** +- **[代码地址](https://gitee.com/wang-chaojiemayj/modelzoo/tree/master/contrib/PyTorch/Research/cv/image_segmentation/FastSCNN)** + +### 1.1 论文地址 + +[FastSCNN论文](https://arxiv.org/abs/1902.04502) + +### 1.2 代码地址 + +[FascSCNN代码](https://gitee.com/wang-chaojiemayj/modelzoo/tree/master/contrib/PyTorch/Research/cv/image_segmentation/FastSCNN) + +branch:master + +commitid:e86409484cf89467a569be43acee1b3f06b92305 + + +## 2 环境说明 + +- 深度学习框架 +- python第三方库 + +### 2.1 深度学习框架 + +``` +python3.7.5 +CANN 5.0.2 + +pytorch >= 1.5.0 +torchvision >= 0.6.0 +onnx == 1.7.0 +onnx-simplifier == 0.3.6 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.21.1 +Pillow == 8.3.0 +opencv-python == 4.5.2.54 +``` + +## 3 模型转换 + +- pth转om模型 + +### 3.1 pth转om模型 + +1.获取pth权重文件 + +获取权重文件方法,可从Ascend modelzoo FastSCNN_ACL_Pytorch 模型压缩包获取 + +md5sum:efc7247270298f3f57e88375011b52ee + +2.FastSCNN模型已经上传至代码仓,使用git工具获取FastSCNN模型代码 +使用gitclone获取模型训练的代码,切换到tuili分支。 + +``` +git clone https://gitee.com/wang-chaojiemayj/modelzoo.git +cd modelzoo +git checkout tuili +``` + +进入FastSCNN目录 + +``` +cd ./contrib/ACL_PyTorch/Research/cv/segmentation/FastSCNN +``` + +使用gitclone下载模型代码 + +``` +git clone https://github.com/LikeLy-Journey/SegmenTron +``` + +由于onnx不支持AdaptiveAvgPool算子,需要使用module.patch修改module.py。 +将FastSCNN目录下的module.patch放到FastSCNN/SegmenTron目录下 +执行 + +``` +cd ./SegmenTron +git apply module.patch +cd .. +``` + +3.执行pth2om脚本,生成om模型文件 + +ascend-toolkit版本:5.0.2 +``` +bs1: +python3.7 Fast_SCNN_pth2onnx.py --pth_path best_model.pth --onnx_name fast_scnn_bs1 --batch_size 1 +bs16: +python3.7 Fast_SCNN_pth2onnx.py --pth_path best_model.pth --onnx_name fast_scnn_bs16 --batch_size 16 + **bs4:bs16无法导出时使用 +python3.7 Fast_SCNN_pth2onnx.py --pth_path best_model.pth --onnx_name fast_scnn_bs4 --batch_size 4** +``` +参数说明: +--pth_path:pth权重文件的路径,可自行设置,默认值为best_model.pth; +--onnx_name:需要转出的onnx模型的名称,可自行设置,默认值为fast_scnn_bs1(由于本模型不支持动态batch,推荐在模型名后加后缀,如‘_bs1’,用以区分不同batch_size的onnx模型); +--batch_size:导出的onnx模型的batch_size,可自行设置,默认值为1。 + +onnx转出om + +bs1: +``` +source env.sh(注意,latest是一个软连接,请将服务器中的/usr/local/Ascend/ascend-toolkit/latest 指向5.0.2版本的CANN包) +atc --framework=5 --model=fast_scnn_bs1.onnx --output=fast_scnn_bs1 --output_type=FP16 --input_format=NCHW --input_shape="image:1,3,1024,2048" --log=debug --soc_version=Ascend310 +``` +bs16: +``` +source env.sh +atc --framework=5 --model=fast_scnn_bs16.onnx --output=fast_scnn_bs16 --output_type=FP16 --input_format=NCHW --input_shape="image:16,3,1024,2048" --log=debug --soc_version=Ascend310 +``` +bs4:(bs16无法离线推理时使用) +``` +source env.sh +atc --framework=5 --model=fast_scnn_bs4.onnx --output=fast_scnn_bs4 --output_type=FP16 --input_format=NCHW --input_shape="image:4,3,1024,2048" --log=debug --soc_version=Ascend310 +``` + + +## 4 数据集预处理 + +- 数据集获取 +- 数据预处理 +- 生成数据集信息文件 + +### 4.1 数据集获取 + +本模型支持cityscapes leftImg8bit的500张验证集。用户需要下载[leftImg8bit_trainvaltest.zip](http://www.cityscapes-dataset.com/downloads)和[gtFine_trainvaltest.zip](http://www.cityscapes-dataset.com/downloads)数据集,解压,将两个数据集放在/opt/npu/datasets/cityscapes/目录下。推荐使用软连接,可以节省时间,数据集目录如下。 + +``` +|opt--npu--datasets +| |-- cityscapes +| | |-- gtFine +| | | |-- test +| | | |-- train +| | | |-- val +| | |-- leftImg8bit +| | |-- test +| | |-- train +| | |-- val +``` + + +### 4.2 数据集预处理 + +在modelzoo/contrib/ACL_PyTorch/Research /cv/segmentation/FastSCNN目录创建软连接 + +``` +ln -s /opt/npu/datasets datasets +``` + +运行Fast_SCNN_preprocess.py + +``` +python3.7 Fast_SCNN_preprocess.py +``` + +数据预处理的结果会保存在/opt/npu/prep_datset +预处理之后的二进制文件目录如下: +/opt/npu/prep_dataset/datasets/leftImg8bit/ +/opt/npu/prep_dataset/datasets/gtFine/ +在modelzoo/contrib/ACL_PyTorch/Research/cv/segmentation/FastSCNN目录下创建软连接 + +``` +ln -s /opt/npu/prep_dataset prep_dataset +``` + +### 4.3 生成数据集信息文件 + +1.生成数据集信息文件脚本gen_dataset_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 + +``` +python3.7 gen_dataset_info.py +``` + +## 5 离线推理 + +- benchmark工具概述 +- 离线推理 + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN 5.0.1 推理benchmark工具用户指南 01 + +### 5.2 离线推理 + +1.设置环境变量 + +``` +source env.sh +``` + +2.执行离线推理 +bs1: +``` +./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=fast_scnn_bs1.om -input_text_path=./fast_scnn_prep_bin.info -input_width=2048 -input_height=1024 -output_binary=True -useDvpp=False./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=4 -om_path=fast_scnn_bs4.om -input_text_path=./fast_scnn_prep_bin.info -input_width=2048 -input_height=1024 -output_binary=True -useDvpp=False +``` +bs16: +``` +./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=16 -om_path=./fast_scnn_bs16.om -input_text_path=./fast_scnn_prep_bin.info -input_width=2048 -input_height=1024 -output_binary=True -useDvpp=False +``` +bs4:(bs16无法离线推理时使用) +``` +./benchmark.x86_64 -model_type=vision -device_id=2 -batch_size=4 -om_path=fast_scnn_bs4.om -input_text_path=fast_scnn_prep_bin.info -input_width=2048 -input_height=1024 -output_binary=True -useDvpp=False +``` +``` +参数说明: +需要更改的参数 +-device_id:使用的Ascend310处理器的卡号,可选0、1、2、3,尽量选择不同的卡号进行推理,若-device_id=0,离线推理结果会保存在./result/dumpOut +put_device0中,device0中的0代表卡号是0; +-batch_size:om模型的batch_size; +-om_path: 需要进行离线推理的om模型的路径; +不需要更改的参数: +-input_text_path:om模型的二进制输入图片的路径信息文件的路径; +-input_width:输入图片的宽度,FastSCNN模型是2048; +-input_heigh:输入图片的高度,FastSCNN模型是1024; +-output_binary:benchmark的输出是二进制文件还是txt文件,True代表输出为二进制文件; +-useDvpp:是否使用Dvpp工具,FastSCNN模型不使用Dvpp工具,设置为False; +``` +## 6 精度对比 + +- 离线推理精度 +- 开源精度 +- 开源精度对比 + +### 6.1 离线推理精度统计 + +后处理统计mIoU + +调用cityscapes_acc_eval.py脚本推理结果与label比对,获取pixAcc和mIoU数据,结果保存在fast_scnn_bs1.log和fast_scnn_bs4.log + +``` +python3.7 cityscapes_acc_eval.py result/dumpOutput_device0/ ./out >fast_scnn_bs1.log +python3.7 cityscapes_acc_eval.py result/dumpOutput_device1/ ./out >fast_scnn_bs4.log +``` + +第一个为benchmark输出目录,第二个为输出重定向文件名 + +``` +pixAcc:94.29% mIoU:64.43 +``` + +经过对bs1与bs4的om测试,本模型batch1的精度与batch4的精度一致,精度数据如上 + +### 6.2 开源精度 + +pth精度 + +``` +Model pixAcc mIoU +FastSCNN 93.877% 64.46 +``` + +### 6.3 精度对比 + +将得到的om模型离线推理精度与pth精度作比较,精度下降不超过0.5%,故精度达标 + +## 7 性能对比 + +- NPU性能数据 +- T4性能数据 +- 性能对比 + +### 7.1 npu性能数据 + +1.benchmark工具在整个数据集上推理获得性能数据。 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: + +``` +[e2e] throughputRate: 0.99593, latency: 502043[data read] throughputRate: 1.62003, moduleLatency: 617.273[preprocess] throughputRate: 1.20942, moduleLatency: 826.844[inference] throughputRate: 1.02697, Interface throughputRate: 5.5718, moduleLatency: 973.739[postprocess] throughputRate: 0.999452, moduleLatency: 1000.55 +``` + +Interface throughputRate: 5.5718,5.5718x4=22.286既是batch1 310单卡吞吐率 + +batch4的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_4_device_1.txt: + +``` +[e2e] throughputRate: 0.429745, latency: 1.16348e+06[data read] throughputRate: 0.673692, moduleLatency: 1484.36[preprocess] throughputRate: 0.525523, moduleLatency: 1902.86[inference] throughputRate: 0.477698, Interface throughputRate: 5.59273, moduleLatency: 2100.2[postprocess] throughputRate: 0.107216, moduleLatency: 9327 +``` + +Interface throughputRate: 5.59273,5.59273x4=22.37092既是batch16 310单卡吞吐率 + + +### 7.2 T4性能数据 + +在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2 +batch1性能: + +``` +trtexec --onnx=fast_scnn_bs1.onnx --fp16 --shapes=image:1x3x1024x2048 --threads +``` + +``` +[07/20/2021-01:49:12] [I] GPU Compute[07/20/2021-01:49:12] [I] min: 6.1626 ms[07/20/2021-01:49:12] [I] max: 6.18018 ms[07/20/2021-01:49:12] [I] mean: 6.17022 ms[07/20/2021-01:49:12] [I] median: 6.17062 ms[07/20/2021-01:49:12] [I] percentile: 6.18018 ms at 99%[07/20/2021-01:49:12] [I] total compute time: 0.265319 s +``` + +batch1 t4单卡吞吐率:1000/(6.17022/1)=162.068fps + +batch4性能: + +``` +trtexec --onnx=fast_scnn_bs4.onnx --fp16 --shapes=image:4x3x1024x2048 --threads +``` + +``` +[08/25/2021-05:18:21] [I] GPU Compute[08/25/2021-05:18:21] [I] min: 23.7666 ms[08/25/2021-05:18:21] [I] max: 24.3643 ms[08/25/2021-05:18:21] [I] mean: 24.0295 ms[08/25/2021-05:18:21] [I] median: 23.9731 ms[08/25/2021-05:18:21] [I] percentile: 24.3643 ms at 99%[08/25/2021-05:18:21] [I] total compute time: 0.288354 s +``` + +batch4 t4单卡吞吐率:1000/(24.0295/4)=166.46fps + +### 7.3 性能对比 + +batch1:5.5718x4 < 1000/(6.17022/1) +batch2:5.59273x4 <1000/(24.0295/4) +310单个device的吞吐率乘4即单卡吞吐率比T4单卡的吞吐率小,故310性能低于T4性能,性能不达标。 +对于batch1与batch4,310性能均低于T4性能,该模型放在contrib/ACL_PyTorch/Research目录下。 +**性能优化:** + +测试版本:CANN 5.0.2 + +目前可行的解决方案有三个: + +(1)优化TransData,修改five_2_four.py和four_2_five.py + +(2)输出节点由float32改为float16 + +(3)模型中Resize节点的mode由双线性为最近邻 + +具体优化方法如下: + +(1)修改five_2_four.py和four_2_five.py从profiling数据的op_statistic_0_1.csv看出影响性能的是TransData,ResizeBilinearV2D,AvgPoolV2算子。从op_summary_0_1.csv可以看出单个TransData的aicore耗时,确定可以可以优化。 + +``` +five_2_four.py:9928 修改如下: elif dst_format.lower() == "nchw" and dst_shape in [[2560, 512, 4, 26], [2560, 512, 1, 26], [2560, 256, 8, 25],[16, 240, 7, 7], [16, 120, 14, 14], [1, 128, 32, 64], [1, 19, 1024, 2048], [2, 128, 32, 64], [2, 19, 1024, 2048]]: +``` + +``` + four_2_five.py:1219 修改如下: if src_format.upper() == "NCHW" and shape_input in [[16, 240, 7, 7], [16, 120, 14, 14],[1, 1, 1024, 2048, 16], [1, 8, 32, 64, 16], [2, 1, 1024, 2048, 16], [2, 8, 32, 64, 16]] and dtype_input == "float16": +``` + +(2)指定输出为fp16: + +``` +atc --framework=5 --model=fast_scnn_bs1_sim.onnx --output=fast_scnn_bs1 --output_type=FP16 --input_format=NCHW --input_shape="image:1,3,1024,2048" --log=debug --soc_version=Ascend310python3.7.5 -m onnxsim --input-shape="2,3,1024,2048" fast_scnn_bs2.onnx fast_scnn_bs2_sim.onnx --skip-optimizationatc --framework=5 --model=fast_scnn_bs2_sim.onnx --output=fast_scnn_bs2 --output_type=FP16 --input_format=NCHW --input_shape="image:2,3,1024,2048" --log=debug --soc_version=Ascend310 +``` + +(3)模型中Resize节点的mode由双线性为最近邻 + +``` +newnode229 = onnx.helper.make_node( 'Resize', name='Resize_229', inputs=['549', '560', '561', '559'], outputs=['562'], coordinate_transformation_mode='align_corners', cubic_coeff_a=-0.75, mode='nearest', nearest_mode='floor')newnode245 = onnx.helper.make_node( 'Resize', name='Resize_245', inputs=['566', '577', '578', '576'], outputs=['579'], coordinate_transformation_mode='align_corners', cubic_coeff_a=-0.75, mode='nearest', nearest_mode='floor')graph.node.remove(model.graph.node[126])graph.node.insert(126,newnode126)graph.node.remove(model.graph.node[144])graph.node.insert(144,newnode144)graph.node.remove(model.graph.node[162])graph.node.insert(162,newnode162)graph.node.remove(model.graph.node[180])graph.node.insert(180,newnode180)graph.node.remove(model.graph.node[185])graph.node.insert(185,newnode185)graph.node.remove(model.graph.node[213])graph.node.insert(213,newnode213)graph.node.remove(model.graph.node[229])graph.node.insert(229,newnode229)graph.node.remove(model.graph.node[245])graph.node.insert(245,newnode245)onnx.checker.check_model(model)onnx.save(model, 'bs1_resized.onnx') +``` + +(4)性能、精度统计 + +| 方法 | 精度 | 性能 | +| ------------------------------------------------- | --------------------------- | --------------------------- | +| 未优化 | | | +| 优化TransData,修改five_2_four.py和four_2_five.py | bs1:mIoU64.46;bs2:mIoU64.46 | bs1:4.135fps;bs2:6.265fps | +| 输出节点由float32改为float16 | bs1:mIoU64.43;bs2:mIoU64.43 | bs1:22.518fps;bs2:22.694fps | +| 模型中Resize节点的mode由双线性为最近邻 | bs1:mIoU60.41;bs1:mIoU60.41 | bs1:7.747fps;bs2:14.046fps | + +8.本模型经过指定输出结点为fp16后,精度为64.43,pth精度为64.46,精度达标;性能提高到22fps左右,故本次pr提交的模型输出为结点fp16。 + diff --git a/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/gen_dataset_info.py index 2f15f923bab1cda87d483e2b60e38f41391d7cc6..cc42d73672f7e87d4ab4fa554d1cd567118b21f8 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/gen_dataset_info.py @@ -1,47 +1,47 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os - - -def get_bin_info(img_root_path='prep_dataset/datasets/leftImg8bit', - mask_folder='opt/npu/prep_dataset/datasets/cityscapes/gtFine', - info_name='fast_scnn_prep_bin.info', width='2048', height='1024'): - img_path = [] - mask_path = [] - for root, _, files in os.walk(img_root_path): - for filename in files: - if filename.startswith('._'): - continue - if filename.endswith('.bin'): - imgpath = os.path.join(root, filename) - img_path.append(imgpath) - foldername = os.path.basename(os.path.dirname(imgpath)) - maskname = filename.replace('leftImg8bit', 'gtFine_labelIds') - maskpath = os.path.join(mask_folder, foldername, maskname) - mask_path.append(maskpath) - - with open(info_name, 'w') as fp: - for index in range(len(img_path)): - content = ' '.join([str(index), img_path[index], width, height]) - fp.write(content) - fp.write('\n') - - -if __name__ == '__main__': - img_root_path = 'prep_dataset/datasets/leftImg8bit/' - mask_folder = '/opt/npu/prep_dataset/datasets/gtFine' - info_name = 'fast_scnn_prep_bin.info' - width = '2048' - height = '1024' - get_bin_info(img_root_path=img_root_path, mask_folder=mask_folder, info_name=info_name, width=width, height=height) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os + + +def get_bin_info(img_root_path='prep_dataset/datasets/leftImg8bit', + mask_folder='opt/npu/prep_dataset/datasets/cityscapes/gtFine', + info_name='fast_scnn_prep_bin.info', width='2048', height='1024'): + img_path = [] + mask_path = [] + for root, _, files in os.walk(img_root_path): + for filename in files: + if filename.startswith('._'): + continue + if filename.endswith('.bin'): + imgpath = os.path.join(root, filename) + img_path.append(imgpath) + foldername = os.path.basename(os.path.dirname(imgpath)) + maskname = filename.replace('leftImg8bit', 'gtFine_labelIds') + maskpath = os.path.join(mask_folder, foldername, maskname) + mask_path.append(maskpath) + + with open(info_name, 'w') as fp: + for index in range(len(img_path)): + content = ' '.join([str(index), img_path[index], width, height]) + fp.write(content) + fp.write('\n') + + +if __name__ == '__main__': + img_root_path = 'prep_dataset/datasets/leftImg8bit/' + mask_folder = '/opt/npu/prep_dataset/datasets/gtFine' + info_name = 'fast_scnn_prep_bin.info' + width = '2048' + height = '1024' + get_bin_info(img_root_path=img_root_path, mask_folder=mask_folder, info_name=info_name, width=width, height=height) diff --git a/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/test/README.md b/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/test/README.md index 94ddb7cc6c038ad7fb5c6311a72d728c4a5b87b5..bc1740a35c7206b0f21e461ef01ff655ab328be2 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/test/README.md +++ b/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/test/README.md @@ -1,120 +1,120 @@ -环境准备: - -1.数据集路径 -本模型数据集放在/opt/npu/,具体文件路径为:opt/npu/datasets -本模型支持cityscapes leftImg8bit的500张验证集。用户需要下载[leftImg8bit_trainvaltest.zip](http://www.cityscapes-dataset.com/downloads)和[gtFine_trainvaltest.zip](http://www.cityscapes-dataset.com/downloads)数据集,解压,将两个数据集放在/opt/npu/datasets/cityscapes/目录下。推荐使用软连接,可以节省时间,数据集目录如下。 - -``` -|opt--npu--datasets -| |-- cityscapes -| | |-- gtFine -| | | |-- test -| | | |-- train -| | | |-- val -| | |-- leftImg8bit -| | |-- test -| | |-- train -| | |-- val -``` - -2.进入工作目录 -cd Fast_SCNN - -3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -pip3.7.5 install -r requirements.txt - -4.获取,修改与安装开源模型代码 -使用gitclone获取模型训练的代码,切换到tuili分支。 - -``` -git clone https://gitee.com/wang-chaojiemayj/modelzoo.git -cd modelzoo -git checkout tuili -``` - -进入FastSCNN目录 - -``` -cd ./contrib/PyTorch/Research/cv/image_segmentation/Fast_SCNN/ -``` - -使用gitclone下载模型代码 - -``` -git clone https://github.com/LikeLy-Journey/SegmenTron -``` - -由于onnx不支持AdaptiveavgPool算子,需要使用module.patch修改Fast_SCNN/SegmenTron/module.py。 -将FastSCNN目录下的module.patch放到FastSCNN/SegmenTron目录下. -执行 - -``` -cd ./SegmenTron -git apply module.patch -cd .. -``` - -5.获取权重文件 -获取权重文件方法,可从Ascend modelzoo FastSCNN_ACL_Pytorch 模型压缩包获取 - - md5sum:efc7247270298f3f57e88375011b52ee - -6.数据预处理 -在modelzoo/contrib/ACL_PyTorch/Research /cv/segmentation/FastSCNN目录创建软连接 - -``` -ln -s /opt/npu/datasets datasets -``` - -运行Fast_SCNN_preprocess.py - -``` -python3.7.5 Fast_SCNN_preprocess.py -``` - -数据预处理的结果会保存在/opt/npu/prep_datset -预处理之后的二进制文件目录如下: -/opt/npu/prep_dataset/datasets/leftImg8bit/ -/opt/npu/prep_dataset/datasets/gtFine/ -在modelzoo/contrib/ACL_PyTorch/Research /cv/segmentation/FastSCNN目录下创建软连接 - -``` -ln -s /opt/npu/prep_dataset prep_dataset -``` - -运行gen_dataset_info.py获取二进制输入文件的info信息 - -``` -python3.7.5 gen_dataset_info.py -``` - -顺利运行会在当前目录下生成fast_scnn_prep_bin.info文件 - -6.获取benchmark工具 -将benchmark.x86_64和benchmark.aarch64放在当前目录 - -7.310上执行,执行时确保device空闲 - -ascend-toolkit版本:5.0.2 - -onnx转出om - -``` -source env.sh(注意,latest是一个软连接,请将服务器中的/usr/local/Ascend/ascend-toolkit/latest 指向5.0.2版本的CANN包) -bash test/pth2om.sh -成功运行会生成fast_scnn_bs1.onnx,fast_scnn_bs4.onnx,fast_scnn_bs8.onnx,fast_scnn_bs16.onnx,fast_scnn_bs32.onnx; -fast_scnn_bs1.om,fast_scnn_bs4.om,fast_scnn_bs8.om,fast_scnn_bs16.om,fast_scnn_bs32.om文件。 -(注意fast_scnn_bs32.onnx如果因为内存原因无法生成,也就无法导出fast_scnn_bs32.om。) -``` - -进行离线推理并进行精度、性能统计 - -``` -bash test/eval_acc_perf.sh -``` -会自动对fast_scnn_bs1.om、fast_scnn_bs16.om、fast_scnn_bs4.om进行精度、性能的统计。(fast_scnn_bs16.om可能会因为内存原因无法进行离线推理,运行报错后会自动跳过) - -8.在t4环境上将fast_scnn_bs1.onnx,fast_scnn_bs4.onnx,fast_scnn_bs8.onnx,fast_scnn_bs16.onnx,fast_scnn_bs32.onnx文件文件与perf_t4.sh放在同一目录 - -然后执行bash perf_t4.sh,执行时确保gpu空闲 - +环境准备: + +1.数据集路径 +本模型数据集放在/opt/npu/,具体文件路径为:opt/npu/datasets +本模型支持cityscapes leftImg8bit的500张验证集。用户需要下载[leftImg8bit_trainvaltest.zip](http://www.cityscapes-dataset.com/downloads)和[gtFine_trainvaltest.zip](http://www.cityscapes-dataset.com/downloads)数据集,解压,将两个数据集放在/opt/npu/datasets/cityscapes/目录下。推荐使用软连接,可以节省时间,数据集目录如下。 + +``` +|opt--npu--datasets +| |-- cityscapes +| | |-- gtFine +| | | |-- test +| | | |-- train +| | | |-- val +| | |-- leftImg8bit +| | |-- test +| | |-- train +| | |-- val +``` + +2.进入工作目录 +cd Fast_SCNN + +3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +pip3.7.5 install -r requirements.txt + +4.获取,修改与安装开源模型代码 +使用gitclone获取模型训练的代码,切换到tuili分支。 + +``` +git clone https://gitee.com/wang-chaojiemayj/modelzoo.git +cd modelzoo +git checkout tuili +``` + +进入FastSCNN目录 + +``` +cd ./contrib/PyTorch/Research/cv/image_segmentation/Fast_SCNN/ +``` + +使用gitclone下载模型代码 + +``` +git clone https://github.com/LikeLy-Journey/SegmenTron +``` + +由于onnx不支持AdaptiveavgPool算子,需要使用module.patch修改Fast_SCNN/SegmenTron/module.py。 +将FastSCNN目录下的module.patch放到FastSCNN/SegmenTron目录下. +执行 + +``` +cd ./SegmenTron +git apply module.patch +cd .. +``` + +5.获取权重文件 +获取权重文件方法,可从Ascend modelzoo FastSCNN_ACL_Pytorch 模型压缩包获取 + + md5sum:efc7247270298f3f57e88375011b52ee + +6.数据预处理 +在modelzoo/contrib/ACL_PyTorch/Research /cv/segmentation/FastSCNN目录创建软连接 + +``` +ln -s /opt/npu/datasets datasets +``` + +运行Fast_SCNN_preprocess.py + +``` +python3.7.5 Fast_SCNN_preprocess.py +``` + +数据预处理的结果会保存在/opt/npu/prep_datset +预处理之后的二进制文件目录如下: +/opt/npu/prep_dataset/datasets/leftImg8bit/ +/opt/npu/prep_dataset/datasets/gtFine/ +在modelzoo/contrib/ACL_PyTorch/Research /cv/segmentation/FastSCNN目录下创建软连接 + +``` +ln -s /opt/npu/prep_dataset prep_dataset +``` + +运行gen_dataset_info.py获取二进制输入文件的info信息 + +``` +python3.7.5 gen_dataset_info.py +``` + +顺利运行会在当前目录下生成fast_scnn_prep_bin.info文件 + +6.获取benchmark工具 +将benchmark.x86_64和benchmark.aarch64放在当前目录 + +7.310上执行,执行时确保device空闲 + +ascend-toolkit版本:5.0.2 + +onnx转出om + +``` +source env.sh(注意,latest是一个软连接,请将服务器中的/usr/local/Ascend/ascend-toolkit/latest 指向5.0.2版本的CANN包) +bash test/pth2om.sh +成功运行会生成fast_scnn_bs1.onnx,fast_scnn_bs4.onnx,fast_scnn_bs8.onnx,fast_scnn_bs16.onnx,fast_scnn_bs32.onnx; +fast_scnn_bs1.om,fast_scnn_bs4.om,fast_scnn_bs8.om,fast_scnn_bs16.om,fast_scnn_bs32.om文件。 +(注意fast_scnn_bs32.onnx如果因为内存原因无法生成,也就无法导出fast_scnn_bs32.om。) +``` + +进行离线推理并进行精度、性能统计 + +``` +bash test/eval_acc_perf.sh +``` +会自动对fast_scnn_bs1.om、fast_scnn_bs16.om、fast_scnn_bs4.om进行精度、性能的统计。(fast_scnn_bs16.om可能会因为内存原因无法进行离线推理,运行报错后会自动跳过) + +8.在t4环境上将fast_scnn_bs1.onnx,fast_scnn_bs4.onnx,fast_scnn_bs8.onnx,fast_scnn_bs16.onnx,fast_scnn_bs32.onnx文件文件与perf_t4.sh放在同一目录 + +然后执行bash perf_t4.sh,执行时确保gpu空闲 + diff --git a/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/test/parse.py b/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/test/parse.py index f7ae934e8d8cd05b323899cef81422d1d8c1881e..d432cbc56d44bbd33e28a1cd2db30fa662ea9bb8 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/test/parse.py +++ b/ACL_PyTorch/contrib/cv/segmentation/FastSCNN/test/parse.py @@ -1,40 +1,40 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import sys -import re - -def get_acc(filename): - with open(filename, 'r') as f: - lines = f.readlines() - last_line = lines[-1] - mIoU = last_line.split(" ")[1] - pixAcc = last_line.split(" ")[8].replace('\n','') - print("mIoU:", mIoU, " pixAcc: ", pixAcc) - - -def get_perf(filename): - with open(filename, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 - print('310 bs{} fps:{}'.format(filename.split('_')[3], fps)) - -if __name__ == "__main__": - - filename = sys.argv[1] - - if filename.endswith(".log"): - get_acc(filename) - elif filename.endswith(".txt"): +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +import re + +def get_acc(filename): + with open(filename, 'r') as f: + lines = f.readlines() + last_line = lines[-1] + mIoU = last_line.split(" ")[1] + pixAcc = last_line.split(" ")[8].replace('\n','') + print("mIoU:", mIoU, " pixAcc: ", pixAcc) + + +def get_perf(filename): + with open(filename, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 + print('310 bs{} fps:{}'.format(filename.split('_')[3], fps)) + +if __name__ == "__main__": + + filename = sys.argv[1] + + if filename.endswith(".log"): + get_acc(filename) + elif filename.endswith(".txt"): get_perf(filename) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/GCNet/README.md b/ACL_PyTorch/contrib/cv/segmentation/GCNet/README.md index 595ee6a8cb6050c650ca399e66377a4356101a32..3a1f420a261d571b878f03150b176505603cb46a 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/GCNet/README.md +++ b/ACL_PyTorch/contrib/cv/segmentation/GCNet/README.md @@ -1,159 +1,159 @@ -# GCNet模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - -``` -pip3.7 install -r requirements.txt -``` - - - -2.获取,修改与安装开源模型代码 - -``` -git clone https://github.com/open-mmlab/mmcv -cd mmcv -git reset --hard 643009e4458109cb88ba5e669eec61a5e54c83be -pip install -e . -cd .. -git clone https://github.com/open-mmlab/mmdetection -cd mmdetection -git reset --hard 6c1347d7c0fa220a7be99cb19d1a9e8b6cbf7544 -pip install -r requirements/build.txt -python setup.py develop -patch -p1 < GCNet.diff -``` - - - -3.获取权重文件 - -从[LINK](https://github.com/open-mmlab/mmdetection/tree/master/configs/gcnet)中获取权重文件,将权重文件mask_rcnn_r50_fpn_r4_gcb_c3-c5_1x_coco_20200204-17235656.pth放到当前工作目录 (执行pth2onnx时会自动下载) - -4.数据集 - -使用COCO官网的coco2017的5千张验证集进行测试,请参考原始开源代码仓mmdetection中对公共数据集的设置 - -5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) -将benchmark.x86_64或benchmark.aarch64放到当前工作目录 - - - -## 2 模型转换 - -1.pth转onnx模型 - -``` -python tools/deployment/pytorch2onnx.py configs/gcnet/mask_rcnn_r50_fpn_r4_gcb_c3-c5_1x_coco.py mask_rcnn_r50_fpn_r4_gcb_c3-c5_1x_coco_20200204-17235656.pth --output-file GCNet.onnx --input-img demo/demo.jpg --test-img tests/data/color.jpg --shape 800 1216 -``` - - - -2.onnx转om模型 - -``` -atc --framework=5 --model=GCNet.onnx --output=./GCNet_bs1 --input_shape="input:1,3,800,1216" --log=error --soc_version=Ascend310 -``` - - - -3.执行以下命令生成om模型文件 - -``` -bash test/pth2om.sh -``` - - - -## 3 离线推理 - -1.数据预处理 - -``` -python GCNet_preprocess.py --image_src_path=${datasets_path}/val2017 --bin_file_path=val2017_bin --model_input_height=800 --model_input_width=1216 -``` - - - -2.生成数据集信息文件 - -``` -python gen_dataset_info.py bin val2017_bin coco2017.info 1216 800 -python gen_dataset_info.py jpg val2017 coco2017_jpg.info -``` - - - -3.执行离线推理 - -``` -./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=1 -om_path=./GCNet_bs1.om -input_text_path=./coco2017.info -input_width=1216 -input_height=800 -output_binary=True -useDvpp=False -``` - - - -4.使用后处理脚本展示推理结果 - -``` -python GCNet_postprocess.py --bin_data_path=./result/dumpOutput_device1/ --test_annotation=coco2017_jpg.info --det_results_path=detection-results --annotations_path=annotations/instances_val2017.json --net_out_num=3 --net_input_height=800 --net_input_width=1216 -``` - - - -5.NPU精度测试 - -``` -python txt_to_json.py -python coco_eval.py -``` - - - -6.NPU性能测试 - -``` -./benchmark.x86_64 -round=20 -om_path=GCNet_bs1.om -device_id=1 -batch_size=1 -``` - - - -7.GPU性能测试 - -onnx包含自定义算子,因此不能使用开源TensorRT测试性能数据,故在T4机器上使用pth在线推理测试性能数据 - -测评T4精度与性能 - -``` -python tools/test.py configs/gcnet/mask_rcnn_r50_fpn_r4_gcb_c3-c5_1x_coco.py ./mask_rcnn_r50_fpn_r4_gcb_c3-c5_1x_coco_20200204-17235656.pth --eval bbox -python coco_eval.py -``` - - - -8.执行命令进行离线推理 - -``` -bash test/eval_acc_perf.sh -``` - - - - **评测结果:** - -| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| :-------: | :---------: | :-------------: | :------: | :------: | -| GCNet bs1 | mAP:0.613 | mAP:0.611 | 3.931fps | 8.144fps | - -备注: -1.GCNet的mmdetection实现不支持多batch。 - -2.onnx包含自定义算子,因此不能使用开源TensorRT测试性能数据,故在T4机器上使用pth在线推理测试性能数据。 - -说明: - -1.om推理box map50精度为0.611,T4推理box map50精度为0.613,精度下降在1个点之内,因此可视为精度达标。 - -2.batch1:2.036 * 4 fps > 3.931fps 即310单个device的吞吐率乘4即单卡吞吐率约为T4单卡的吞吐率2倍,故310性能高于T4性能,性能达标。 - +# GCNet模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + +``` +pip3.7 install -r requirements.txt +``` + + + +2.获取,修改与安装开源模型代码 + +``` +git clone https://github.com/open-mmlab/mmcv +cd mmcv +git reset --hard 643009e4458109cb88ba5e669eec61a5e54c83be +pip install -e . +cd .. +git clone https://github.com/open-mmlab/mmdetection +cd mmdetection +git reset --hard 6c1347d7c0fa220a7be99cb19d1a9e8b6cbf7544 +pip install -r requirements/build.txt +python setup.py develop +patch -p1 < GCNet.diff +``` + + + +3.获取权重文件 + +从[LINK](https://github.com/open-mmlab/mmdetection/tree/master/configs/gcnet)中获取权重文件,将权重文件mask_rcnn_r50_fpn_r4_gcb_c3-c5_1x_coco_20200204-17235656.pth放到当前工作目录 (执行pth2onnx时会自动下载) + +4.数据集 + +使用COCO官网的coco2017的5千张验证集进行测试,请参考原始开源代码仓mmdetection中对公共数据集的设置 + +5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) +将benchmark.x86_64或benchmark.aarch64放到当前工作目录 + + + +## 2 模型转换 + +1.pth转onnx模型 + +``` +python tools/deployment/pytorch2onnx.py configs/gcnet/mask_rcnn_r50_fpn_r4_gcb_c3-c5_1x_coco.py mask_rcnn_r50_fpn_r4_gcb_c3-c5_1x_coco_20200204-17235656.pth --output-file GCNet.onnx --input-img demo/demo.jpg --test-img tests/data/color.jpg --shape 800 1216 +``` + + + +2.onnx转om模型 + +``` +atc --framework=5 --model=GCNet.onnx --output=./GCNet_bs1 --input_shape="input:1,3,800,1216" --log=error --soc_version=Ascend310 +``` + + + +3.执行以下命令生成om模型文件 + +``` +bash test/pth2om.sh +``` + + + +## 3 离线推理 + +1.数据预处理 + +``` +python GCNet_preprocess.py --image_src_path=${datasets_path}/val2017 --bin_file_path=val2017_bin --model_input_height=800 --model_input_width=1216 +``` + + + +2.生成数据集信息文件 + +``` +python gen_dataset_info.py bin val2017_bin coco2017.info 1216 800 +python gen_dataset_info.py jpg val2017 coco2017_jpg.info +``` + + + +3.执行离线推理 + +``` +./benchmark.x86_64 -model_type=vision -device_id=1 -batch_size=1 -om_path=./GCNet_bs1.om -input_text_path=./coco2017.info -input_width=1216 -input_height=800 -output_binary=True -useDvpp=False +``` + + + +4.使用后处理脚本展示推理结果 + +``` +python GCNet_postprocess.py --bin_data_path=./result/dumpOutput_device1/ --test_annotation=coco2017_jpg.info --det_results_path=detection-results --annotations_path=annotations/instances_val2017.json --net_out_num=3 --net_input_height=800 --net_input_width=1216 +``` + + + +5.NPU精度测试 + +``` +python txt_to_json.py +python coco_eval.py +``` + + + +6.NPU性能测试 + +``` +./benchmark.x86_64 -round=20 -om_path=GCNet_bs1.om -device_id=1 -batch_size=1 +``` + + + +7.GPU性能测试 + +onnx包含自定义算子,因此不能使用开源TensorRT测试性能数据,故在T4机器上使用pth在线推理测试性能数据 + +测评T4精度与性能 + +``` +python tools/test.py configs/gcnet/mask_rcnn_r50_fpn_r4_gcb_c3-c5_1x_coco.py ./mask_rcnn_r50_fpn_r4_gcb_c3-c5_1x_coco_20200204-17235656.pth --eval bbox +python coco_eval.py +``` + + + +8.执行命令进行离线推理 + +``` +bash test/eval_acc_perf.sh +``` + + + + **评测结果:** + +| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| :-------: | :---------: | :-------------: | :------: | :------: | +| GCNet bs1 | mAP:0.613 | mAP:0.611 | 3.931fps | 8.144fps | + +备注: +1.GCNet的mmdetection实现不支持多batch。 + +2.onnx包含自定义算子,因此不能使用开源TensorRT测试性能数据,故在T4机器上使用pth在线推理测试性能数据。 + +说明: + +1.om推理box map50精度为0.611,T4推理box map50精度为0.613,精度下降在1个点之内,因此可视为精度达标。 + +2.batch1:2.036 * 4 fps > 3.931fps 即310单个device的吞吐率乘4即单卡吞吐率约为T4单卡的吞吐率2倍,故310性能高于T4性能,性能达标。 + diff --git a/ACL_PyTorch/contrib/cv/segmentation/IntraDA/gen_dataset_info.py b/ACL_PyTorch/contrib/cv/segmentation/IntraDA/gen_dataset_info.py index b3976a2b9eeee216128e36d2b3887c1cc4b04ac7..297cdca7e26d95dc314dfca176cc9308d10abd93 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/IntraDA/gen_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/segmentation/IntraDA/gen_dataset_info.py @@ -1,99 +1,99 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - print(bin_images) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_png_info(image_names, info_name): - with open(info_name, 'w') as file: - for image_name in image_names: - print(image_name) - if len(image_names) == 0: - continue - else: - for index, png in enumerate(image_name): - img_cv = cv2.imread(png) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), png, str(width), str(height)]) - file.write(content) - file.write('\n') - -def get_city_pairs(folder, split='train'): - def get_path_pairs(img_folder, mask_folder): - img_paths = [] - mask_paths = [] - for root, _, files in os.walk(img_folder): - for filename in files: - if filename.endswith('.png'): - imgpath = os.path.join(root, filename) - foldername = os.path.basename(os.path.dirname(imgpath)) - maskname = filename.replace('leftImg8bit', 'gtFine_labelIds') - maskpath = os.path.join(mask_folder, foldername, maskname) - if os.path.isfile(imgpath) and os.path.isfile(maskpath): - img_paths.append(imgpath) - mask_paths.append(maskpath) - else: - print('cannot find the mask or image:', imgpath, maskpath) - print('Found {} images in the folder {}'.format(len(img_paths), img_folder)) - return img_paths, mask_paths - - if split in ('train', 'val'): - # "./Cityscapes/leftImg8bit/train" or "./Cityscapes/leftImg8bit/val" - img_folder = os.path.join(folder, 'leftImg8bit/' + split) - # "./Cityscapes/gtFine/train" or "./Cityscapes/gtFine/val" - mask_folder = os.path.join(folder, 'gtFine/' + split) - # img_paths与mask_paths的顺序是一一对应的 - img_paths, mask_paths = get_path_pairs(img_folder, mask_folder) - return img_paths, mask_paths - else: - assert split == 'trainval' - print('trainval set') - train_img_folder = os.path.join(folder, 'leftImg8bit/train') - train_mask_folder = os.path.join(folder, 'gtFine/train') - val_img_folder = os.path.join(folder, 'leftImg8bit/val') - val_mask_folder = os.path.join(folder, 'gtFine/val') - train_img_paths, train_mask_paths = get_path_pairs(train_img_folder, train_mask_folder) - val_img_paths, val_mask_paths = get_path_pairs(val_img_folder, val_mask_folder) - img_paths = train_img_paths + val_img_paths - mask_paths = train_mask_paths + val_mask_paths - - return img_paths, mask_paths - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - res = get_city_pairs(file_path) - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'png': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + print(bin_images) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_png_info(image_names, info_name): + with open(info_name, 'w') as file: + for image_name in image_names: + print(image_name) + if len(image_names) == 0: + continue + else: + for index, png in enumerate(image_name): + img_cv = cv2.imread(png) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), png, str(width), str(height)]) + file.write(content) + file.write('\n') + +def get_city_pairs(folder, split='train'): + def get_path_pairs(img_folder, mask_folder): + img_paths = [] + mask_paths = [] + for root, _, files in os.walk(img_folder): + for filename in files: + if filename.endswith('.png'): + imgpath = os.path.join(root, filename) + foldername = os.path.basename(os.path.dirname(imgpath)) + maskname = filename.replace('leftImg8bit', 'gtFine_labelIds') + maskpath = os.path.join(mask_folder, foldername, maskname) + if os.path.isfile(imgpath) and os.path.isfile(maskpath): + img_paths.append(imgpath) + mask_paths.append(maskpath) + else: + print('cannot find the mask or image:', imgpath, maskpath) + print('Found {} images in the folder {}'.format(len(img_paths), img_folder)) + return img_paths, mask_paths + + if split in ('train', 'val'): + # "./Cityscapes/leftImg8bit/train" or "./Cityscapes/leftImg8bit/val" + img_folder = os.path.join(folder, 'leftImg8bit/' + split) + # "./Cityscapes/gtFine/train" or "./Cityscapes/gtFine/val" + mask_folder = os.path.join(folder, 'gtFine/' + split) + # img_paths与mask_paths的顺序是一一对应的 + img_paths, mask_paths = get_path_pairs(img_folder, mask_folder) + return img_paths, mask_paths + else: + assert split == 'trainval' + print('trainval set') + train_img_folder = os.path.join(folder, 'leftImg8bit/train') + train_mask_folder = os.path.join(folder, 'gtFine/train') + val_img_folder = os.path.join(folder, 'leftImg8bit/val') + val_mask_folder = os.path.join(folder, 'gtFine/val') + train_img_paths, train_mask_paths = get_path_pairs(train_img_folder, train_mask_folder) + val_img_paths, val_mask_paths = get_path_pairs(val_img_folder, val_mask_folder) + img_paths = train_img_paths + val_img_paths + mask_paths = train_mask_paths + val_mask_paths + + return img_paths, mask_paths + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + res = get_city_pairs(file_path) + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'png': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_png_info(res, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/IntraDA/intrada_postprocess.py b/ACL_PyTorch/contrib/cv/segmentation/IntraDA/intrada_postprocess.py index 2ca1ae5a6f1777d5b1befe01a4b8bfcd3791a678..3f3b79d13d4af5d352d4626c3ad1932629c1497d 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/IntraDA/intrada_postprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/IntraDA/intrada_postprocess.py @@ -1,178 +1,178 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import time -import sys -import torch -import numpy as np -import torch.nn as nn -import struct -from PIL import Image - -def fast_hist(a, b, n): - k = (a >= 0) & (a < n) - return np.bincount(n * a[k].astype(int) + b[k], minlength=n ** 2).reshape(n, n) - - -def per_class_iu(hist): - return np.diag(hist) / (hist.sum(1) + hist.sum(0) - np.diag(hist)) - - -class Evaluator(object): - def __init__(self, cityscapes_path, folder_davinci_target, outdir): - - loc = "cpu" - self.device = torch.device(loc) - print("===device===:",self.device) - # get valid dataset images and targets - self.image_paths, self.mask_paths = _get_city_pairs(cityscapes_path, "val") - - self.annotation_file_path = folder_davinci_target - - self.outdir = outdir - - def eval(self): - - print("Start validation, Total sample: {:d}".format(len(self.image_paths))) - list_time = [] - - hist = np.zeros((19, 19)) - for i in range(len(self.image_paths)): - filename = os.path.basename(self.image_paths[i]) - annotation_file = os.path.join(self.annotation_file_path, filename.split('.')[0]) - - mask = Image.open(self.mask_paths[i]) # mask shape: (W,H) - mask = mask.resize((2048,1024),Image.NEAREST) - mask = self._mask_transform(mask) # mask shape: (H,w) - mask = mask.to(self.device) - - with torch.no_grad(): - start_time = time.time() - outputs = self.file2tensor(annotation_file).to(self.device) - end_time = time.time() - - outputs_ = outputs.numpy().squeeze().transpose(1, 2, 0) - outputs_ = np.argmax(outputs_, axis=2) - hist += fast_hist(mask.cpu().numpy().flatten(), outputs_.flatten(), 19) - inters_over_union_classes = per_class_iu(hist) - mIoU = np.nanmean(inters_over_union_classes) - step_time = end_time - start_time - - list_time.append(step_time) - - print("Sample: {:d}, mIoU: {:.3f}, time: {:.3f}s".format( - i + 1, mIoU * 100, step_time)) - - average_time = sum(list_time) / len(list_time) - print("Evaluate: Average mIoU: {:.3f}, Average time: {:.3f}" - .format(mIoU * 100, average_time)) - - def _mask_transform(self, mask): - mask = self._class_to_index(np.array(mask).astype('int32')) - return torch.LongTensor(np.array(mask).astype('int32')) - - def _class_to_index(self, mask): - # assert the value - values = np.unique(mask) - self._key = np.array([-1, -1, -1, -1, -1, -1, - -1, -1, 0, 1, -1, -1, - 2, 3, 4, -1, -1, -1, - 5, -1, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, - -1, -1, 16, 17, 18]) - self._mapping = np.array(range(-1, len(self._key) - 1)).astype('int32') - for value in values: - assert (value in self._mapping) - - index = np.digitize(mask.ravel(), self._mapping, right=True) - - return self._key[index].reshape(mask.shape) - - def file2tensor(self, annotation_file): - - filepath = annotation_file + '_2.bin' - size = os.path.getsize(filepath) - res = [] - L = int(size/4) - binfile = open(filepath, 'rb') - for i in range(L): - data = binfile.read(4) - num = struct.unpack('f', data) - res.append(num[0]) - binfile.close() - - dim_res = np.array(res).reshape(1,19,65,129) - tensor_res = torch.tensor(dim_res, dtype=torch.float32) - interp = nn.Upsample(size=(1024, 2048), mode='bilinear', align_corners=True) - tensor_res = interp(tensor_res) - print(filepath, tensor_res.dtype, tensor_res.shape) - - return tensor_res - - -def _get_city_pairs(folder, split='train'): - def get_path_pairs(img_folder, mask_folder): - img_paths = [] - mask_paths = [] - for root, _, files in os.walk(img_folder): - for filename in files: - if filename.endswith('.png'): - imgpath = os.path.join(root, filename) - foldername = os.path.basename(os.path.dirname(imgpath)) - maskname = filename.replace('leftImg8bit', 'gtFine_labelIds') - maskpath = os.path.join(mask_folder, foldername, maskname) - if os.path.isfile(imgpath) and os.path.isfile(maskpath): - img_paths.append(imgpath) - mask_paths.append(maskpath) - else: - print('cannot find the mask or image:', imgpath, maskpath) - print('Found {} images in the folder {}'.format(len(img_paths), img_folder)) - return img_paths, mask_paths - - if split in ('train', 'val'): - # "./Cityscapes/leftImg8bit/train" or "./Cityscapes/leftImg8bit/val" - img_folder = os.path.join(folder, 'leftImg8bit/' + split) - # "./Cityscapes/gtFine/train" or "./Cityscapes/gtFine/val" - mask_folder = os.path.join(folder, 'gtFine/' + split) - # img_paths mask_paths - img_paths, mask_paths = get_path_pairs(img_folder, mask_folder) - return img_paths, mask_paths - return img_paths, mask_paths - - -if __name__ == '__main__': - - try: - # dataset file path - cityscapes_path = sys.argv[1] - # txt file path - folder_davinci_target = sys.argv[2] - # the path to store the results json path - outdir = sys.argv[3] - - except IndexError: - print("Stopped!") - exit(1) - - if not (os.path.exists(cityscapes_path)): - print("config file folder does not exist.") - if not (os.path.exists(folder_davinci_target)): - print("target file folder does not exist.") - if not (os.path.exists(outdir)): - print("output file folder does not exist.") - os.makedirs(outdir) - - evaluator = Evaluator(cityscapes_path, folder_davinci_target, outdir) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import time +import sys +import torch +import numpy as np +import torch.nn as nn +import struct +from PIL import Image + +def fast_hist(a, b, n): + k = (a >= 0) & (a < n) + return np.bincount(n * a[k].astype(int) + b[k], minlength=n ** 2).reshape(n, n) + + +def per_class_iu(hist): + return np.diag(hist) / (hist.sum(1) + hist.sum(0) - np.diag(hist)) + + +class Evaluator(object): + def __init__(self, cityscapes_path, folder_davinci_target, outdir): + + loc = "cpu" + self.device = torch.device(loc) + print("===device===:",self.device) + # get valid dataset images and targets + self.image_paths, self.mask_paths = _get_city_pairs(cityscapes_path, "val") + + self.annotation_file_path = folder_davinci_target + + self.outdir = outdir + + def eval(self): + + print("Start validation, Total sample: {:d}".format(len(self.image_paths))) + list_time = [] + + hist = np.zeros((19, 19)) + for i in range(len(self.image_paths)): + filename = os.path.basename(self.image_paths[i]) + annotation_file = os.path.join(self.annotation_file_path, filename.split('.')[0]) + + mask = Image.open(self.mask_paths[i]) # mask shape: (W,H) + mask = mask.resize((2048,1024),Image.NEAREST) + mask = self._mask_transform(mask) # mask shape: (H,w) + mask = mask.to(self.device) + + with torch.no_grad(): + start_time = time.time() + outputs = self.file2tensor(annotation_file).to(self.device) + end_time = time.time() + + outputs_ = outputs.numpy().squeeze().transpose(1, 2, 0) + outputs_ = np.argmax(outputs_, axis=2) + hist += fast_hist(mask.cpu().numpy().flatten(), outputs_.flatten(), 19) + inters_over_union_classes = per_class_iu(hist) + mIoU = np.nanmean(inters_over_union_classes) + step_time = end_time - start_time + + list_time.append(step_time) + + print("Sample: {:d}, mIoU: {:.3f}, time: {:.3f}s".format( + i + 1, mIoU * 100, step_time)) + + average_time = sum(list_time) / len(list_time) + print("Evaluate: Average mIoU: {:.3f}, Average time: {:.3f}" + .format(mIoU * 100, average_time)) + + def _mask_transform(self, mask): + mask = self._class_to_index(np.array(mask).astype('int32')) + return torch.LongTensor(np.array(mask).astype('int32')) + + def _class_to_index(self, mask): + # assert the value + values = np.unique(mask) + self._key = np.array([-1, -1, -1, -1, -1, -1, + -1, -1, 0, 1, -1, -1, + 2, 3, 4, -1, -1, -1, + 5, -1, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, + -1, -1, 16, 17, 18]) + self._mapping = np.array(range(-1, len(self._key) - 1)).astype('int32') + for value in values: + assert (value in self._mapping) + + index = np.digitize(mask.ravel(), self._mapping, right=True) + + return self._key[index].reshape(mask.shape) + + def file2tensor(self, annotation_file): + + filepath = annotation_file + '_2.bin' + size = os.path.getsize(filepath) + res = [] + L = int(size/4) + binfile = open(filepath, 'rb') + for i in range(L): + data = binfile.read(4) + num = struct.unpack('f', data) + res.append(num[0]) + binfile.close() + + dim_res = np.array(res).reshape(1,19,65,129) + tensor_res = torch.tensor(dim_res, dtype=torch.float32) + interp = nn.Upsample(size=(1024, 2048), mode='bilinear', align_corners=True) + tensor_res = interp(tensor_res) + print(filepath, tensor_res.dtype, tensor_res.shape) + + return tensor_res + + +def _get_city_pairs(folder, split='train'): + def get_path_pairs(img_folder, mask_folder): + img_paths = [] + mask_paths = [] + for root, _, files in os.walk(img_folder): + for filename in files: + if filename.endswith('.png'): + imgpath = os.path.join(root, filename) + foldername = os.path.basename(os.path.dirname(imgpath)) + maskname = filename.replace('leftImg8bit', 'gtFine_labelIds') + maskpath = os.path.join(mask_folder, foldername, maskname) + if os.path.isfile(imgpath) and os.path.isfile(maskpath): + img_paths.append(imgpath) + mask_paths.append(maskpath) + else: + print('cannot find the mask or image:', imgpath, maskpath) + print('Found {} images in the folder {}'.format(len(img_paths), img_folder)) + return img_paths, mask_paths + + if split in ('train', 'val'): + # "./Cityscapes/leftImg8bit/train" or "./Cityscapes/leftImg8bit/val" + img_folder = os.path.join(folder, 'leftImg8bit/' + split) + # "./Cityscapes/gtFine/train" or "./Cityscapes/gtFine/val" + mask_folder = os.path.join(folder, 'gtFine/' + split) + # img_paths mask_paths + img_paths, mask_paths = get_path_pairs(img_folder, mask_folder) + return img_paths, mask_paths + return img_paths, mask_paths + + +if __name__ == '__main__': + + try: + # dataset file path + cityscapes_path = sys.argv[1] + # txt file path + folder_davinci_target = sys.argv[2] + # the path to store the results json path + outdir = sys.argv[3] + + except IndexError: + print("Stopped!") + exit(1) + + if not (os.path.exists(cityscapes_path)): + print("config file folder does not exist.") + if not (os.path.exists(folder_davinci_target)): + print("target file folder does not exist.") + if not (os.path.exists(outdir)): + print("output file folder does not exist.") + os.makedirs(outdir) + + evaluator = Evaluator(cityscapes_path, folder_davinci_target, outdir) evaluator.eval() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/IntraDA/intrada_preprocess.py b/ACL_PyTorch/contrib/cv/segmentation/IntraDA/intrada_preprocess.py index f3f814586ad11a7ec4a57a03da021d64c6322746..3f6cc3819e655d11594c272ab2ba54416b71692f 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/IntraDA/intrada_preprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/IntraDA/intrada_preprocess.py @@ -1,67 +1,67 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import torch -import sys -import numpy as np -from PIL import Image -from tqdm import tqdm -from torchvision import transforms -from torchvision.transforms.functional import InterpolationMode - - -def get_img_path(img_folder): - img_paths = [] - for root, dirs, files in os.walk(img_folder): - for f in files: - if f.endswith('.png'): - print(os.path.join(root, f)) - img_paths.append(os.path.join(root, f)) - return img_paths - -def flip(x, dim): - xsize = x.size() - dim = x.dim() + dim if dim < 0 else dim - x = x.view(-1, *xsize[dim:]) - x = x.view(x.size(0), x.size(1), -1)[:, getattr(torch.arange(x.size(1)-1, - -1, -1), ('cpu','cuda')[x.is_cuda])().long(), :] - return x.view(xsize) - -def _img_transform(image): - image_transform = transforms.Compose([ - transforms.Resize((512,1024),InterpolationMode.BICUBIC), - transforms.ToTensor()]) - image = image_transform(image) - image *= 255. - image = flip(image, 0) - image -= np.array((104.00698793, 116.66876762, 122.67891434), dtype=np.float32).reshape(-1,1,1) - return image - -if __name__ == '__main__': - cityscapes_path = sys.argv[1] - bin_path = sys.argv[2] - if os.path.exists(bin_path) is False: - os.mkdir(bin_path) - - split = "val" - img_folder = os.path.join(cityscapes_path, 'leftImg8bit/' + split) - img_paths = get_img_path(img_folder) - - for i in tqdm(range(len(img_paths))): - filename = os.path.basename(img_paths[i]) - image = Image.open(img_paths[i]).convert('RGB') # image shape: (W,H,3) - image = _img_transform(image) # image shape: (3,H,W) [0,1] - image = torch.unsqueeze(image, 0) # image shape: (1,3,H,W) [0,1] - image = np.array(image).astype(np.float32) - image.tofile(os.path.join(bin_path, filename.split('.')[0] + '.bin')) # save bin +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import torch +import sys +import numpy as np +from PIL import Image +from tqdm import tqdm +from torchvision import transforms +from torchvision.transforms.functional import InterpolationMode + + +def get_img_path(img_folder): + img_paths = [] + for root, dirs, files in os.walk(img_folder): + for f in files: + if f.endswith('.png'): + print(os.path.join(root, f)) + img_paths.append(os.path.join(root, f)) + return img_paths + +def flip(x, dim): + xsize = x.size() + dim = x.dim() + dim if dim < 0 else dim + x = x.view(-1, *xsize[dim:]) + x = x.view(x.size(0), x.size(1), -1)[:, getattr(torch.arange(x.size(1)-1, + -1, -1), ('cpu','cuda')[x.is_cuda])().long(), :] + return x.view(xsize) + +def _img_transform(image): + image_transform = transforms.Compose([ + transforms.Resize((512,1024),InterpolationMode.BICUBIC), + transforms.ToTensor()]) + image = image_transform(image) + image *= 255. + image = flip(image, 0) + image -= np.array((104.00698793, 116.66876762, 122.67891434), dtype=np.float32).reshape(-1,1,1) + return image + +if __name__ == '__main__': + cityscapes_path = sys.argv[1] + bin_path = sys.argv[2] + if os.path.exists(bin_path) is False: + os.mkdir(bin_path) + + split = "val" + img_folder = os.path.join(cityscapes_path, 'leftImg8bit/' + split) + img_paths = get_img_path(img_folder) + + for i in tqdm(range(len(img_paths))): + filename = os.path.basename(img_paths[i]) + image = Image.open(img_paths[i]).convert('RGB') # image shape: (W,H,3) + image = _img_transform(image) # image shape: (3,H,W) [0,1] + image = torch.unsqueeze(image, 0) # image shape: (1,3,H,W) [0,1] + image = np.array(image).astype(np.float32) + image.tofile(os.path.join(bin_path, filename.split('.')[0] + '.bin')) # save bin diff --git a/ACL_PyTorch/contrib/cv/segmentation/IntraDA/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/segmentation/IntraDA/modelzoo_level.txt index d44ba5698b045b8a30e107962f295dbc24585d8c..70801afc42b6d9eb5cdd98b5430d9b2101f3146a 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/IntraDA/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/IntraDA/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/IntraDA/requirements.txt b/ACL_PyTorch/contrib/cv/segmentation/IntraDA/requirements.txt index 7b6bc2994b56f8cda417ae90bd4dc54ad5fab3de..f83a7c426770dbc7746d9fa4124ccc73e5759622 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/IntraDA/requirements.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/IntraDA/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.8.0 -torchvision == 0.9.0 -onnx == 1.9.0 -numpy == 1.21.1 -opencv-python == 4.4.0.46 +torch == 1.8.0 +torchvision == 0.9.0 +onnx == 1.9.0 +numpy == 1.21.1 +opencv-python == 4.4.0.46 Pillow == 8.0.1 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/PSPnet/LICENSE b/ACL_PyTorch/contrib/cv/segmentation/PSPnet/LICENSE index 7615b4e85fa24d81f25cec1495e783a3936f1a86..72f817fb44de8b9fd23fe71230b9dc5ccbe4ca35 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/PSPnet/LICENSE +++ b/ACL_PyTorch/contrib/cv/segmentation/PSPnet/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/PSPnet/README.md b/ACL_PyTorch/contrib/cv/segmentation/PSPnet/README.md index 4f07558723f778c8175f8cfe47b36248e1be84ff..2e6abee6427a63fb1101b253631a0a09397ae7c7 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/PSPnet/README.md +++ b/ACL_PyTorch/contrib/cv/segmentation/PSPnet/README.md @@ -1,406 +1,406 @@ -# 基于开源mmsegmentation预训练的PSPnet Onnx模型端到端推理指导 -- [1 模型概述](#1-模型概述) - - [1.1 论文地址](#11-论文地址) - - [1.2 代码地址](#12-代码地址) -- [2 环境说明](#2-环境说明) - - [2.1 深度学习框架](#21-深度学习框架) - - [2.2 python第三方库](#22-python第三方库) -- [3 模型转换](#3-模型转换) - - [3.1 pth转onnx模型](#31-pth转onnx模型) - - [3.2 onnx转om模型](#32-onnx转om模型) -- [4 数据集预处理](#4-数据集预处理) - - [4.1 数据集获取](#41-数据集获取) - - [4.2 数据集预处理](#42-数据集预处理) - - [4.3 生成数据集信息文件](#43-生成数据集信息文件) -- [5 离线推理](#5-离线推理) - - [5.1 benchmark工具概述](#51-benchmark工具概述) - - [5.2 离线推理](#52-离线推理) -- [6 精度对比](#6-精度对比) - - [6.1 离线推理精度统计](#61-离线推理精度统计) - - [6.2 开源精度](#62-开源精度) - - [6.3 精度对比](#63-精度对比) -- [7 性能对比](#7-性能对比) - - [7.1 npu性能数据](#71-npu性能数据) - - [7.2 T4性能数据](#72-T4性能数据) - - [7.3 性能对比](#73-性能对比) - - - -## 1 模型概述 - -- **[论文地址](#11-论文地址)** - -- **[代码地址](#12-代码地址)** - -### 1.1 论文地址 -[PSPnet论文](https://arxiv.org/abs/1612.01105) -论文使用PPM(pyramid pooling module)和提出的PSPNet(pyramid scene parsing network),实现了通过融合different-region-based context获取全局context信息的能力。同时,PSPNet在多个数据集上实现了SOTA,取得ImageNet scene parsing challenge 2016、PASCAL VOC 2012 benchmark和Cityscapes benchmark的第1名。 - -### 1.2 代码地址 -[mmsegmentation框架PSPnet代码](https://github.com/open-mmlab/mmsegmentation/tree/master/configs/pspnet) -branch:master commit_id:52b4fa5b9a3d65d0745d8bccb08ac0b88c9407fe - -## 2 环境说明 - -- **[深度学习框架](#21-深度学习框架)** - -- **[python第三方库](#22-python第三方库)** - -### 2.1 深度学习框架 -``` -pytorch == 1.8.0 -torchvision == 0.9.0 -onnx == 1.9.0 -``` -**注意:** -> 转onnx的环境上pytorch需要安装1.8.0版本 - -### 2.2 python第三方库 -``` -numpy == 1.20.1 -opencv-python == 4.5.2.52 -``` - -**说明:** -> X86架构:opencv,pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:opencv,pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3 模型转换 - -- **[pth转onnx模型](#31-pth转onnx模型)** - -- **[onnx转om模型](#32-onnx转om模型)** - - -### 3.1 pth转onnx模型 - -1.获取pth权重文件 -[PSPnet基于mmsegmentation预训练的npu权重文件](https://download.openmmlab.com/mmsegmentation/v0.5/pspnet/pspnet_r50-d8_512x512_20k_voc12aug/pspnet_r50-d8_512x512_20k_voc12aug_20200617_101958-ed5dfbd9.pth) -文件md5sum: c563f7683bab2a869fe095a9eb801f6c - -2.mmsegmentation源码安装 -```shell -pip3.7 install mmcv-full==1.3.10 -git clone https://github.com/open-mmlab/mmsegmentation.git -cd mmsegmentation -如果修改了模型代码,交付了{model_name}.diff -patch -p1 < ../{model_name}.diff -如果模型代码需要安装,则安装模型代码(如果没有安装脚本,pth2onnx等脚本需要引用模型代码的类或函数,可通过sys.path.append(r"./pytorch-nested-unet")添加搜索路径的方式) -pip3.7 install -e . # or "python3.7 setup.py develop" -cd .. -``` - - **说明:** -> 安装所需的依赖说明请参考mmsegmentation/docs/get_started.md - - -3.使用tools里的pytorch2onnx.py文件,运行如下命令,生成对应的onnx模型: -```shell -python3.7 mmsegmentation/tools/pytorch2onnx.py mmsegmentation/configs/pspnet/pspnet_r50-d8_512x512_20k_voc12aug.py --checkpoint pspnet_r50-d8_512x512_20k_voc12aug_20200617_101958-ed5dfbd9.pth --output-file pspnet_r50-d8_512x512_20k_voc12aug.onnx --shape 500 500 -``` -4.通过onnx simplifier简化onnx模型 -```shell -python3.7 -m onnxsim --input-shape="1,3,500,500" pspnet_r50-d8_512x512_20k_voc12aug.onnx pspnet_r50-d8_512x512_20k_voc12aug_sim.onnx -``` - **模型转换要点:** -> 导出的onnx为固定batch1,不是动态batch。 - -### 3.2 onnx转om模型 - -1.设置环境变量 -```shell -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest/ -``` -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN 5.0.2 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373),如果存在多余输出节点,需要指定输出节点以去除无用输出,节点序号可能会因网络结构不同而不同,使用netron开源可视化工具查看具体的输出节点名: -生成bs1的om模型: -```shell -atc --framework=5 --model=pspnet_r50-d8_512x512_20k_voc12aug_sim.onnx --output=pspnet_r50-d8_512x512_20k_voc12aug_sim_bs1 --input_format=NCHW --input_shape=" input:1,3,500,500" --log=debug --soc_version=Ascend310 --input_fp16_nodes=input -``` -生成bs16的om模型: -```shell -atc --framework=5 --model=pspnet_r50-d8_512x512_20k_voc12aug_sim.onnx --output=pspnet_r50-d8_512x512_20k_voc12aug_sim_bs16 --input_format=NCHW --input_shape=" input:16,3,500,500" --log=debug --soc_version=Ascend310 --input_fp16_nodes=input -``` - **模型转换要点:** -> 通过input_fp16_nodes将输入的数据精度改为fp16,提升性能。 - -## 4 数据集预处理 - -- **[数据集获取](#41-数据集获取)** - -- **[数据集预处理](#42-数据集预处理)** - -- **[生成数据集信息文件](#43-生成数据集信息文件)** - -### 4.1 数据集获取 -该模型使用[VOC2012官网](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/index.html)的VOC2012的1449张验证集进行测试,图片与对应ground truth分别存放在/opt/npu/VOCdevkit/VOC2012/JPEGImages/与/opt/npu/VOCdevkit/VOC2012/SegmentationClass/。 - -### 4.2 数据集预处理 -1.预处理脚本mmsegmentation_voc2012_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 -```shell -python3.7 mmsegmentation_voc2012_preprocess.py --image_folder_path=/opt/npu/VOCdevkit/VOC2012/JPEGImages/ --split=/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt --bin_folder_path=./voc12_bin/ -``` -### 4.3 生成数据集信息文件 -1.生成数据集信息文件脚本get_info.py - -2.执行生成数据集信息脚本,生成数据集信息文件 -```shell -python3.7 get_info.py bin ./voc12_bin voc12.info 500 500 -``` -第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 -## 5 离线推理 - -- **[benchmark工具概述](#51-benchmark工具概述)** - -- **[离线推理](#52-离线推理)** - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN 5.0.2 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) - -### 5.2 离线推理 - -1.设置环境变量 -```shell -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest/ -``` -2.执行离线推理 -```shell -./benchmark.${arch} -model_type=vision -om_path=pspnet_r50-d8_512x512_20k_voc12aug_sim_fp16_bs1.om -device_id=0 -batch_size=1 -input_text_path=voc12.info -input_width=500 -input_height=500 -useDvpp=false -output_binary=true - -./benchmark.${arch} -model_type=vision -om_path=pspnet_r50-d8_512x512_20k_voc12aug_sim_fp16_bs16.om -device_id=1 -batch_size=16 -input_text_path=voc12.info -input_width=500 -input_height=500 -useDvpp=false -output_binary=true -``` - **注意:** -> onnx的输出是int64,但是om的输出是int32 - -输出结果默认保存在当前目录result/dumpOutput_device0,模型有一个输出,每个输入对应的输出对应_1.bin文件 -``` -输出 shape 数据类型 数据含义 -output1 1 * 1 * 500 * 500 int32 8位图像 -``` - -## 6 精度对比 - -- **[离线推理精度](#61-离线推理精度)** -- **[开源精度](#62-开源精度)** -- **[精度对比](#63-精度对比)** - -### 6.1 离线推理精度统计 - -1.调用mmsegmentation_voc2012_postprocess.py评测bs1的mIoU精度: -```shell -python3.7 get_info.py jpg /opt/npu/VOCdevkit/VOC2012/JPEGImages/ voc12_jpg.info - -python3.7 mmsegmentation_voc2012_postprocess.py --bin_data_path=./result/dumpOutput_device0 --test_annotation=./voc12_jpg.info --img_dir=/opt/npu/VOCdevkit/VOC2012/JPEGImages --ann_dir=/opt/npu/VOCdevkit/VOC2012/SegmentationClass --split=/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt --net_input_width=500 --net_input_height=500 -``` -第一个参数为benchmark推理结果,第二个为原始图片信息文件,第三个为原始图片位置,第四个为验证图片位置,第五个图片的split,第六七个为网宽高 -执行完后会打印出精度: -``` -per class results: - -+-------------+-------+-------+ -| Class | IoU | Acc | -+-------------+-------+-------+ -| background | 93.78 | 97.28 | -| aeroplane | 87.46 | 94.06 | -| bicycle | 41.32 | 88.9 | -| bird | 86.48 | 91.68 | -| boat | 70.01 | 83.3 | -| bottle | 76.2 | 84.19 | -| bus | 92.78 | 96.14 | -| car | 85.56 | 92.34 | -| cat | 91.47 | 96.61 | -| chair | 35.65 | 46.37 | -| cow | 89.62 | 93.35 | -| diningtable | 55.73 | 59.82 | -| dog | 86.24 | 92.88 | -| horse | 88.84 | 93.02 | -| motorbike | 83.75 | 92.17 | -| person | 83.81 | 91.12 | -| pottedplant | 60.77 | 67.82 | -| sheep | 87.55 | 91.34 | -| sofa | 49.2 | 59.29 | -| train | 85.96 | 91.59 | -| tvmonitor | 67.55 | 79.11 | -+-------------+-------+-------+ -Summary: - -+--------+-------+-------+-------+ -| Scope | mIoU | mAcc | aAcc | -+--------+-------+-------+-------+ -| global | 76.18 | 84.87 | 94.49 | -+--------+-------+-------+-------+ -``` - -2.调用mmsegmentation_voc2012_postprocess.py评测bs16的mIoU精度: -```shell -python3.7 get_info.py jpg /opt/npu/VOCdevkit/VOC2012/JPEGImages/ voc12_jpg.info - -python3.7 mmsegmentation_voc2012_postprocess.py --bin_data_path=./result/dumpOutput_device1 --test_annotation=./voc12_jpg.info --img_dir=/opt/npu/VOCdevkit/VOC2012/JPEGImages --ann_dir=/opt/npu/VOCdevkit/VOC2012/SegmentationClass --split=/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt --net_input_width=500 --net_input_height=500 -``` -第一个参数为benchmark推理结果,第二个为原始图片信息文件,第三个为原始图片位置,第四个为验证图片位置,第五个图片的split,第六七个为网宽高 -执行完后会打印出精度: -``` -per class results: - -+-------------+-------+-------+ -| Class | IoU | Acc | -+-------------+-------+-------+ -| background | 93.78 | 97.28 | -| aeroplane | 87.46 | 94.06 | -| bicycle | 41.32 | 88.9 | -| bird | 86.48 | 91.68 | -| boat | 70.01 | 83.3 | -| bottle | 76.2 | 84.19 | -| bus | 92.78 | 96.14 | -| car | 85.56 | 92.34 | -| cat | 91.47 | 96.61 | -| chair | 35.65 | 46.37 | -| cow | 89.62 | 93.35 | -| diningtable | 55.73 | 59.82 | -| dog | 86.24 | 92.88 | -| horse | 88.84 | 93.02 | -| motorbike | 83.75 | 92.17 | -| person | 83.81 | 91.12 | -| pottedplant | 60.77 | 67.82 | -| sheep | 87.55 | 91.34 | -| sofa | 49.2 | 59.29 | -| train | 85.96 | 91.59 | -| tvmonitor | 67.55 | 79.11 | -+-------------+-------+-------+ -Summary: - -+--------+-------+-------+-------+ -| Scope | mIoU | mAcc | aAcc | -+--------+-------+-------+-------+ -| global | 76.18 | 84.87 | 94.49 | -+--------+-------+-------+-------+ -``` - **精度调试:** -> 1.在线推理前处理图片是一定格式的动态分辨率,onnx将分辨率固定为512x512会导致精度下降些。 -> 2.分辨率在512x512时onnx离线推理的精度与om精度相同,分辨率改为500x500可以提升精度,使得mask的精度与开源相比更高 -> 3.单图调试 -> ``` -> python3.7 mmsegmentation/tools/test.py mmsegmentation/configs/pspnet/pspnet_r50-d8_512x512_20k_voc12aug.py pspnet_r50-d8_512x512_20k_voc12aug_20200617_101958-ed5dfbd9.pth --show -> python3.7 mmsegmentation/tools/pytorch2onnx.py mmsegmentation/configs/pspnet/pspnet_r50-d8_512x512_20k_voc12aug.py --checkpoint pspnet_r50-d8_512x512_20k_voc12aug_20200617_101958-ed5dfbd9.pth --output-file pspnet_r50-d8_512x512_20k_voc12aug.onnx --shape 500 500 --input-img 2011_003103.jpg --show --verify -> ``` - - -### 6.2 开源精度 -[官网精度](https://download.openmmlab.com/mmsegmentation/v0.5/pspnet/pspnet_r50-d8_512x512_20k_voc12aug/pspnet_r50-d8_512x512_20k_voc12aug_20200617_101958.log.json) - -``` -{"mode": "val", "epoch": 31, "iter": 20000, "lr": 0.0001, "mIoU": 0.76778, "mAcc": 0.85529, "aAcc": 0.94787} -``` -### 6.3 精度对比 -om推理bs1和bs16的mIoU精度均为0.7618,开源mIoU精度为0.76778,om精度下降小于1%,精度达标 - - -## 7 性能对比 - -- **[npu性能数据](#71-npu性能数据)** -- **[T4性能数据](#72-T4性能数据)** -- **[性能对比](#73-性能对比)** - -### 7.1 npu性能数据 -1.benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 -由于在线推理与onnx推理还不支持多batch,所以仅测om bs1,bs16的性能。 -1.benchmark工具在整个数据集上推理获得性能数据 -batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: -``` -[e2e] throughputRate: 7.85666, latency: 184430 -[data read] throughputRate: 37.4296, moduleLatency: 26.7168 -[preprocess] throughputRate: 28.1654, moduleLatency: 35.5045 -[infer] throughputRate: 7.91227, Interface throughputRate: 8.19018, moduleLatency: 126.139 -[post] throughputRate: 7.91221, moduleLatency: 126.387 -``` -Interface throughputRate: 7.91221,7.91221x4=31.64884即是batch1 310单卡吞吐率 - -batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: -``` -[e2e] throughputRate: 8.16118, latency: 177548 -[data read] throughputRate: 40.508, moduleLatency: 24.6865 -[preprocess] throughputRate: 29.1145, moduleLatency: 34.3472 -[infer] throughputRate: 8.21425, Interface throughputRate: 8.52684, moduleLatency: 121.508 -[post] throughputRate: 0.515815, moduleLatency: 1938.68 -``` -Interface throughputRate: 8.21425,8.21425x4=32.857即是batch16 310单卡吞吐率 - -2.npu纯推理性能 -batch1的性能,执行20次纯推理取均值,统计吞吐率与其倒数时延(benchmark的时延是单个数据的推理时间),npu性能是一个device执行的结果 -``` -./benchmark.x86_64 -round=20 -om_path=pspnet_r50-d8_512x512_20k_voc12aug_bs1.om -device_id=0 -batch_size=1 -``` -PureInfer_perf_of_pspnet_r50-d8_512x512_20k_voc12aug_bs1_in_device_0.txt: -``` -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_pspnet_r50-d8_512x512_20k_voc12aug_bs1_in_device_0.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 8.12674samples/s, ave_latency: 123.129ms ----------------------------------------------------------------- -``` - -batch6的性能,执行20次纯推理取均值,统计吞吐率与其倒数时延(benchmark的时延是单个数据的推理时间),npu性能是一个device执行的结果 -``` -./benchmark.x86_64 -round=20 -om_path=pspnet_r50-d8_512x512_20k_voc12aug_bs16.om -device_id=0 -batch_size=16 -``` -PureInfer_perf_of_pspnet_r50-d8_512x512_20k_voc12aug_bs16_in_device_0.txt: -``` -[INFO] PureInfer result saved in ./result/PureInfer_perf_of_pspnet_r50-d8_512x512_20k_voc12aug_bs16_in_device_0.txt ------------------PureInfer Performance Summary------------------ -[INFO] ave_throughputRate: 8.51957samples/s, ave_latency: 117.39ms ----------------------------------------------------------------- -``` -### 7.2 T4性能数据 -在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2 -1.batch1性能: -``` -trtexec --onnx=pspnet_r50-d8_512x512_20k_voc12aug_sim.onnx --fp16 --shapes=input:1,3,500,500 -``` -gpu T4是4个device并行执行的结果,mean是时延(tensorrt的时延是batch个数据的推理时间),即吞吐率的倒数乘以batch。其中--fp16是算子精度,目前算子精度只测--fp16的。注意--shapes是onnx的输入节点名与shape,当onnx输入节点的batch为-1时,可以用同一个onnx文件测不同batch的性能,否则用固定batch的onnx测不同batch的性能不准。 -``` -[09/24/2021-04:17:29] [I] GPU Compute -[09/24/2021-04:17:29] [I] min: 15.829 ms -[09/24/2021-04:17:29] [I] max: 20.5302 ms -[09/24/2021-04:17:29] [I] mean: 16.2649 ms -[09/24/2021-04:17:29] [I] median: 16.0951 ms -[09/24/2021-04:17:29] [I] percentile: 19.1857 ms at 99% -[09/24/2021-04:17:29] [I] total compute time: 3.04154 s - -``` -batch1 t4单卡吞吐率:1000/(16.2649/1)=61.482fps - -2.batch16性能: -``` -trtexec --onnx=pspnet_r50-d8_512x512_20k_voc12aug_sim.onnx --fp16 --shapes=input:16,3,500,500 -``` -``` -[09/24/2021-04:25:43] [I] GPU Compute -[09/24/2021-04:25:43] [I] min: 15.7839 ms -[09/24/2021-04:25:43] [I] max: 20.8466 ms -[09/24/2021-04:25:43] [I] mean: 16.2072 ms -[09/24/2021-04:25:43] [I] median: 16.0396 ms -[09/24/2021-04:25:43] [I] percentile: 19.1329 ms at 99% -[09/24/2021-04:25:43] [I] total compute time: 3.03074 s -``` -batch16 t4单卡吞吐率:1000/(16.2072/1)=61.701fps - -### 7.3 性能对比 -batch1:7.91221x4 < 1000/(16.2649/1) -batch1:8.21425x4 < 1000/(16.2072/1) -310单个device的吞吐率乘4即单卡吞吐率比T4单卡的吞吐率小,故310性能低于T4性能,性能不达标。 - -**性能优化:** -> 由于onnx转om的过程中,两个avgpool算子的kernel size过大,导致被替换为aicpu算子,致使性能不足。需等优化底层算子后再进行测试。 - +# 基于开源mmsegmentation预训练的PSPnet Onnx模型端到端推理指导 +- [1 模型概述](#1-模型概述) + - [1.1 论文地址](#11-论文地址) + - [1.2 代码地址](#12-代码地址) +- [2 环境说明](#2-环境说明) + - [2.1 深度学习框架](#21-深度学习框架) + - [2.2 python第三方库](#22-python第三方库) +- [3 模型转换](#3-模型转换) + - [3.1 pth转onnx模型](#31-pth转onnx模型) + - [3.2 onnx转om模型](#32-onnx转om模型) +- [4 数据集预处理](#4-数据集预处理) + - [4.1 数据集获取](#41-数据集获取) + - [4.2 数据集预处理](#42-数据集预处理) + - [4.3 生成数据集信息文件](#43-生成数据集信息文件) +- [5 离线推理](#5-离线推理) + - [5.1 benchmark工具概述](#51-benchmark工具概述) + - [5.2 离线推理](#52-离线推理) +- [6 精度对比](#6-精度对比) + - [6.1 离线推理精度统计](#61-离线推理精度统计) + - [6.2 开源精度](#62-开源精度) + - [6.3 精度对比](#63-精度对比) +- [7 性能对比](#7-性能对比) + - [7.1 npu性能数据](#71-npu性能数据) + - [7.2 T4性能数据](#72-T4性能数据) + - [7.3 性能对比](#73-性能对比) + + + +## 1 模型概述 + +- **[论文地址](#11-论文地址)** + +- **[代码地址](#12-代码地址)** + +### 1.1 论文地址 +[PSPnet论文](https://arxiv.org/abs/1612.01105) +论文使用PPM(pyramid pooling module)和提出的PSPNet(pyramid scene parsing network),实现了通过融合different-region-based context获取全局context信息的能力。同时,PSPNet在多个数据集上实现了SOTA,取得ImageNet scene parsing challenge 2016、PASCAL VOC 2012 benchmark和Cityscapes benchmark的第1名。 + +### 1.2 代码地址 +[mmsegmentation框架PSPnet代码](https://github.com/open-mmlab/mmsegmentation/tree/master/configs/pspnet) +branch:master commit_id:52b4fa5b9a3d65d0745d8bccb08ac0b88c9407fe + +## 2 环境说明 + +- **[深度学习框架](#21-深度学习框架)** + +- **[python第三方库](#22-python第三方库)** + +### 2.1 深度学习框架 +``` +pytorch == 1.8.0 +torchvision == 0.9.0 +onnx == 1.9.0 +``` +**注意:** +> 转onnx的环境上pytorch需要安装1.8.0版本 + +### 2.2 python第三方库 +``` +numpy == 1.20.1 +opencv-python == 4.5.2.52 +``` + +**说明:** +> X86架构:opencv,pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:opencv,pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3 模型转换 + +- **[pth转onnx模型](#31-pth转onnx模型)** + +- **[onnx转om模型](#32-onnx转om模型)** + + +### 3.1 pth转onnx模型 + +1.获取pth权重文件 +[PSPnet基于mmsegmentation预训练的npu权重文件](https://download.openmmlab.com/mmsegmentation/v0.5/pspnet/pspnet_r50-d8_512x512_20k_voc12aug/pspnet_r50-d8_512x512_20k_voc12aug_20200617_101958-ed5dfbd9.pth) +文件md5sum: c563f7683bab2a869fe095a9eb801f6c + +2.mmsegmentation源码安装 +```shell +pip3.7 install mmcv-full==1.3.10 +git clone https://github.com/open-mmlab/mmsegmentation.git +cd mmsegmentation +如果修改了模型代码,交付了{model_name}.diff +patch -p1 < ../{model_name}.diff +如果模型代码需要安装,则安装模型代码(如果没有安装脚本,pth2onnx等脚本需要引用模型代码的类或函数,可通过sys.path.append(r"./pytorch-nested-unet")添加搜索路径的方式) +pip3.7 install -e . # or "python3.7 setup.py develop" +cd .. +``` + + **说明:** +> 安装所需的依赖说明请参考mmsegmentation/docs/get_started.md + + +3.使用tools里的pytorch2onnx.py文件,运行如下命令,生成对应的onnx模型: +```shell +python3.7 mmsegmentation/tools/pytorch2onnx.py mmsegmentation/configs/pspnet/pspnet_r50-d8_512x512_20k_voc12aug.py --checkpoint pspnet_r50-d8_512x512_20k_voc12aug_20200617_101958-ed5dfbd9.pth --output-file pspnet_r50-d8_512x512_20k_voc12aug.onnx --shape 500 500 +``` +4.通过onnx simplifier简化onnx模型 +```shell +python3.7 -m onnxsim --input-shape="1,3,500,500" pspnet_r50-d8_512x512_20k_voc12aug.onnx pspnet_r50-d8_512x512_20k_voc12aug_sim.onnx +``` + **模型转换要点:** +> 导出的onnx为固定batch1,不是动态batch。 + +### 3.2 onnx转om模型 + +1.设置环境变量 +```shell +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest/ +``` +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考[CANN 5.0.2 开发辅助工具指南 (推理) 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164868?idPath=23710424%7C251366513%7C22892968%7C251168373),如果存在多余输出节点,需要指定输出节点以去除无用输出,节点序号可能会因网络结构不同而不同,使用netron开源可视化工具查看具体的输出节点名: +生成bs1的om模型: +```shell +atc --framework=5 --model=pspnet_r50-d8_512x512_20k_voc12aug_sim.onnx --output=pspnet_r50-d8_512x512_20k_voc12aug_sim_bs1 --input_format=NCHW --input_shape=" input:1,3,500,500" --log=debug --soc_version=Ascend310 --input_fp16_nodes=input +``` +生成bs16的om模型: +```shell +atc --framework=5 --model=pspnet_r50-d8_512x512_20k_voc12aug_sim.onnx --output=pspnet_r50-d8_512x512_20k_voc12aug_sim_bs16 --input_format=NCHW --input_shape=" input:16,3,500,500" --log=debug --soc_version=Ascend310 --input_fp16_nodes=input +``` + **模型转换要点:** +> 通过input_fp16_nodes将输入的数据精度改为fp16,提升性能。 + +## 4 数据集预处理 + +- **[数据集获取](#41-数据集获取)** + +- **[数据集预处理](#42-数据集预处理)** + +- **[生成数据集信息文件](#43-生成数据集信息文件)** + +### 4.1 数据集获取 +该模型使用[VOC2012官网](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/index.html)的VOC2012的1449张验证集进行测试,图片与对应ground truth分别存放在/opt/npu/VOCdevkit/VOC2012/JPEGImages/与/opt/npu/VOCdevkit/VOC2012/SegmentationClass/。 + +### 4.2 数据集预处理 +1.预处理脚本mmsegmentation_voc2012_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 +```shell +python3.7 mmsegmentation_voc2012_preprocess.py --image_folder_path=/opt/npu/VOCdevkit/VOC2012/JPEGImages/ --split=/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt --bin_folder_path=./voc12_bin/ +``` +### 4.3 生成数据集信息文件 +1.生成数据集信息文件脚本get_info.py + +2.执行生成数据集信息脚本,生成数据集信息文件 +```shell +python3.7 get_info.py bin ./voc12_bin voc12.info 500 500 +``` +第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 +## 5 离线推理 + +- **[benchmark工具概述](#51-benchmark工具概述)** + +- **[离线推理](#52-离线推理)** + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考[CANN 5.0.2 推理benchmark工具用户指南 01](https://support.huawei.com/enterprise/zh/doc/EDOC1100164874?idPath=23710424%7C251366513%7C22892968%7C251168373) + +### 5.2 离线推理 + +1.设置环境变量 +```shell +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest/ +``` +2.执行离线推理 +```shell +./benchmark.${arch} -model_type=vision -om_path=pspnet_r50-d8_512x512_20k_voc12aug_sim_fp16_bs1.om -device_id=0 -batch_size=1 -input_text_path=voc12.info -input_width=500 -input_height=500 -useDvpp=false -output_binary=true + +./benchmark.${arch} -model_type=vision -om_path=pspnet_r50-d8_512x512_20k_voc12aug_sim_fp16_bs16.om -device_id=1 -batch_size=16 -input_text_path=voc12.info -input_width=500 -input_height=500 -useDvpp=false -output_binary=true +``` + **注意:** +> onnx的输出是int64,但是om的输出是int32 + +输出结果默认保存在当前目录result/dumpOutput_device0,模型有一个输出,每个输入对应的输出对应_1.bin文件 +``` +输出 shape 数据类型 数据含义 +output1 1 * 1 * 500 * 500 int32 8位图像 +``` + +## 6 精度对比 + +- **[离线推理精度](#61-离线推理精度)** +- **[开源精度](#62-开源精度)** +- **[精度对比](#63-精度对比)** + +### 6.1 离线推理精度统计 + +1.调用mmsegmentation_voc2012_postprocess.py评测bs1的mIoU精度: +```shell +python3.7 get_info.py jpg /opt/npu/VOCdevkit/VOC2012/JPEGImages/ voc12_jpg.info + +python3.7 mmsegmentation_voc2012_postprocess.py --bin_data_path=./result/dumpOutput_device0 --test_annotation=./voc12_jpg.info --img_dir=/opt/npu/VOCdevkit/VOC2012/JPEGImages --ann_dir=/opt/npu/VOCdevkit/VOC2012/SegmentationClass --split=/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt --net_input_width=500 --net_input_height=500 +``` +第一个参数为benchmark推理结果,第二个为原始图片信息文件,第三个为原始图片位置,第四个为验证图片位置,第五个图片的split,第六七个为网宽高 +执行完后会打印出精度: +``` +per class results: + ++-------------+-------+-------+ +| Class | IoU | Acc | ++-------------+-------+-------+ +| background | 93.78 | 97.28 | +| aeroplane | 87.46 | 94.06 | +| bicycle | 41.32 | 88.9 | +| bird | 86.48 | 91.68 | +| boat | 70.01 | 83.3 | +| bottle | 76.2 | 84.19 | +| bus | 92.78 | 96.14 | +| car | 85.56 | 92.34 | +| cat | 91.47 | 96.61 | +| chair | 35.65 | 46.37 | +| cow | 89.62 | 93.35 | +| diningtable | 55.73 | 59.82 | +| dog | 86.24 | 92.88 | +| horse | 88.84 | 93.02 | +| motorbike | 83.75 | 92.17 | +| person | 83.81 | 91.12 | +| pottedplant | 60.77 | 67.82 | +| sheep | 87.55 | 91.34 | +| sofa | 49.2 | 59.29 | +| train | 85.96 | 91.59 | +| tvmonitor | 67.55 | 79.11 | ++-------------+-------+-------+ +Summary: + ++--------+-------+-------+-------+ +| Scope | mIoU | mAcc | aAcc | ++--------+-------+-------+-------+ +| global | 76.18 | 84.87 | 94.49 | ++--------+-------+-------+-------+ +``` + +2.调用mmsegmentation_voc2012_postprocess.py评测bs16的mIoU精度: +```shell +python3.7 get_info.py jpg /opt/npu/VOCdevkit/VOC2012/JPEGImages/ voc12_jpg.info + +python3.7 mmsegmentation_voc2012_postprocess.py --bin_data_path=./result/dumpOutput_device1 --test_annotation=./voc12_jpg.info --img_dir=/opt/npu/VOCdevkit/VOC2012/JPEGImages --ann_dir=/opt/npu/VOCdevkit/VOC2012/SegmentationClass --split=/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt --net_input_width=500 --net_input_height=500 +``` +第一个参数为benchmark推理结果,第二个为原始图片信息文件,第三个为原始图片位置,第四个为验证图片位置,第五个图片的split,第六七个为网宽高 +执行完后会打印出精度: +``` +per class results: + ++-------------+-------+-------+ +| Class | IoU | Acc | ++-------------+-------+-------+ +| background | 93.78 | 97.28 | +| aeroplane | 87.46 | 94.06 | +| bicycle | 41.32 | 88.9 | +| bird | 86.48 | 91.68 | +| boat | 70.01 | 83.3 | +| bottle | 76.2 | 84.19 | +| bus | 92.78 | 96.14 | +| car | 85.56 | 92.34 | +| cat | 91.47 | 96.61 | +| chair | 35.65 | 46.37 | +| cow | 89.62 | 93.35 | +| diningtable | 55.73 | 59.82 | +| dog | 86.24 | 92.88 | +| horse | 88.84 | 93.02 | +| motorbike | 83.75 | 92.17 | +| person | 83.81 | 91.12 | +| pottedplant | 60.77 | 67.82 | +| sheep | 87.55 | 91.34 | +| sofa | 49.2 | 59.29 | +| train | 85.96 | 91.59 | +| tvmonitor | 67.55 | 79.11 | ++-------------+-------+-------+ +Summary: + ++--------+-------+-------+-------+ +| Scope | mIoU | mAcc | aAcc | ++--------+-------+-------+-------+ +| global | 76.18 | 84.87 | 94.49 | ++--------+-------+-------+-------+ +``` + **精度调试:** +> 1.在线推理前处理图片是一定格式的动态分辨率,onnx将分辨率固定为512x512会导致精度下降些。 +> 2.分辨率在512x512时onnx离线推理的精度与om精度相同,分辨率改为500x500可以提升精度,使得mask的精度与开源相比更高 +> 3.单图调试 +> ``` +> python3.7 mmsegmentation/tools/test.py mmsegmentation/configs/pspnet/pspnet_r50-d8_512x512_20k_voc12aug.py pspnet_r50-d8_512x512_20k_voc12aug_20200617_101958-ed5dfbd9.pth --show +> python3.7 mmsegmentation/tools/pytorch2onnx.py mmsegmentation/configs/pspnet/pspnet_r50-d8_512x512_20k_voc12aug.py --checkpoint pspnet_r50-d8_512x512_20k_voc12aug_20200617_101958-ed5dfbd9.pth --output-file pspnet_r50-d8_512x512_20k_voc12aug.onnx --shape 500 500 --input-img 2011_003103.jpg --show --verify +> ``` + + +### 6.2 开源精度 +[官网精度](https://download.openmmlab.com/mmsegmentation/v0.5/pspnet/pspnet_r50-d8_512x512_20k_voc12aug/pspnet_r50-d8_512x512_20k_voc12aug_20200617_101958.log.json) + +``` +{"mode": "val", "epoch": 31, "iter": 20000, "lr": 0.0001, "mIoU": 0.76778, "mAcc": 0.85529, "aAcc": 0.94787} +``` +### 6.3 精度对比 +om推理bs1和bs16的mIoU精度均为0.7618,开源mIoU精度为0.76778,om精度下降小于1%,精度达标 + + +## 7 性能对比 + +- **[npu性能数据](#71-npu性能数据)** +- **[T4性能数据](#72-T4性能数据)** +- **[性能对比](#73-性能对比)** + +### 7.1 npu性能数据 +1.benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。模型的性能以使用benchmark工具在整个数据集上推理得到bs1与bs16的性能数据为准,对于使用benchmark工具测试的batch4,8,32的性能数据在README.md中如下作记录即可。 +由于在线推理与onnx推理还不支持多batch,所以仅测om bs1,bs16的性能。 +1.benchmark工具在整个数据集上推理获得性能数据 +batch1的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_1_device_0.txt: +``` +[e2e] throughputRate: 7.85666, latency: 184430 +[data read] throughputRate: 37.4296, moduleLatency: 26.7168 +[preprocess] throughputRate: 28.1654, moduleLatency: 35.5045 +[infer] throughputRate: 7.91227, Interface throughputRate: 8.19018, moduleLatency: 126.139 +[post] throughputRate: 7.91221, moduleLatency: 126.387 +``` +Interface throughputRate: 7.91221,7.91221x4=31.64884即是batch1 310单卡吞吐率 + +batch16的性能,benchmark工具在整个数据集上推理后生成result/perf_vision_batchsize_16_device_1.txt: +``` +[e2e] throughputRate: 8.16118, latency: 177548 +[data read] throughputRate: 40.508, moduleLatency: 24.6865 +[preprocess] throughputRate: 29.1145, moduleLatency: 34.3472 +[infer] throughputRate: 8.21425, Interface throughputRate: 8.52684, moduleLatency: 121.508 +[post] throughputRate: 0.515815, moduleLatency: 1938.68 +``` +Interface throughputRate: 8.21425,8.21425x4=32.857即是batch16 310单卡吞吐率 + +2.npu纯推理性能 +batch1的性能,执行20次纯推理取均值,统计吞吐率与其倒数时延(benchmark的时延是单个数据的推理时间),npu性能是一个device执行的结果 +``` +./benchmark.x86_64 -round=20 -om_path=pspnet_r50-d8_512x512_20k_voc12aug_bs1.om -device_id=0 -batch_size=1 +``` +PureInfer_perf_of_pspnet_r50-d8_512x512_20k_voc12aug_bs1_in_device_0.txt: +``` +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_pspnet_r50-d8_512x512_20k_voc12aug_bs1_in_device_0.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 8.12674samples/s, ave_latency: 123.129ms +---------------------------------------------------------------- +``` + +batch6的性能,执行20次纯推理取均值,统计吞吐率与其倒数时延(benchmark的时延是单个数据的推理时间),npu性能是一个device执行的结果 +``` +./benchmark.x86_64 -round=20 -om_path=pspnet_r50-d8_512x512_20k_voc12aug_bs16.om -device_id=0 -batch_size=16 +``` +PureInfer_perf_of_pspnet_r50-d8_512x512_20k_voc12aug_bs16_in_device_0.txt: +``` +[INFO] PureInfer result saved in ./result/PureInfer_perf_of_pspnet_r50-d8_512x512_20k_voc12aug_bs16_in_device_0.txt +-----------------PureInfer Performance Summary------------------ +[INFO] ave_throughputRate: 8.51957samples/s, ave_latency: 117.39ms +---------------------------------------------------------------- +``` +### 7.2 T4性能数据 +在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2 +1.batch1性能: +``` +trtexec --onnx=pspnet_r50-d8_512x512_20k_voc12aug_sim.onnx --fp16 --shapes=input:1,3,500,500 +``` +gpu T4是4个device并行执行的结果,mean是时延(tensorrt的时延是batch个数据的推理时间),即吞吐率的倒数乘以batch。其中--fp16是算子精度,目前算子精度只测--fp16的。注意--shapes是onnx的输入节点名与shape,当onnx输入节点的batch为-1时,可以用同一个onnx文件测不同batch的性能,否则用固定batch的onnx测不同batch的性能不准。 +``` +[09/24/2021-04:17:29] [I] GPU Compute +[09/24/2021-04:17:29] [I] min: 15.829 ms +[09/24/2021-04:17:29] [I] max: 20.5302 ms +[09/24/2021-04:17:29] [I] mean: 16.2649 ms +[09/24/2021-04:17:29] [I] median: 16.0951 ms +[09/24/2021-04:17:29] [I] percentile: 19.1857 ms at 99% +[09/24/2021-04:17:29] [I] total compute time: 3.04154 s + +``` +batch1 t4单卡吞吐率:1000/(16.2649/1)=61.482fps + +2.batch16性能: +``` +trtexec --onnx=pspnet_r50-d8_512x512_20k_voc12aug_sim.onnx --fp16 --shapes=input:16,3,500,500 +``` +``` +[09/24/2021-04:25:43] [I] GPU Compute +[09/24/2021-04:25:43] [I] min: 15.7839 ms +[09/24/2021-04:25:43] [I] max: 20.8466 ms +[09/24/2021-04:25:43] [I] mean: 16.2072 ms +[09/24/2021-04:25:43] [I] median: 16.0396 ms +[09/24/2021-04:25:43] [I] percentile: 19.1329 ms at 99% +[09/24/2021-04:25:43] [I] total compute time: 3.03074 s +``` +batch16 t4单卡吞吐率:1000/(16.2072/1)=61.701fps + +### 7.3 性能对比 +batch1:7.91221x4 < 1000/(16.2649/1) +batch1:8.21425x4 < 1000/(16.2072/1) +310单个device的吞吐率乘4即单卡吞吐率比T4单卡的吞吐率小,故310性能低于T4性能,性能不达标。 + +**性能优化:** +> 由于onnx转om的过程中,两个avgpool算子的kernel size过大,导致被替换为aicpu算子,致使性能不足。需等优化底层算子后再进行测试。 + diff --git a/ACL_PyTorch/contrib/cv/segmentation/PSPnet/get_info.py b/ACL_PyTorch/contrib/cv/segmentation/PSPnet/get_info.py index b76d6739bcea5c528a031970f0e583e5b5644bd8..d5cab0450c20d502d0d15be2f9c0fceffa6a6191 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/PSPnet/get_info.py +++ b/ACL_PyTorch/contrib/cv/segmentation/PSPnet/get_info.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/PSPnet/mmsegmentation_voc2012_preprocess.py b/ACL_PyTorch/contrib/cv/segmentation/PSPnet/mmsegmentation_voc2012_preprocess.py index eda09af31ec73d2327627620bf1312d871ae0ce3..793ea70de1f92724adc3c95677a6ea2ce4712745 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/PSPnet/mmsegmentation_voc2012_preprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/PSPnet/mmsegmentation_voc2012_preprocess.py @@ -1,95 +1,95 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import argparse -import numpy as np -import cv2 -import mmcv -import torch - - -dataset_config = { - 'mean': (123.675, 116.28, 103.53), - 'std': (58.395, 57.12, 57.375) -} - - -tensor_height = 500 -tensor_width = 500 - - -def resize(img, size): - old_h = img.shape[0] - old_w = img.shape[1] - scale_ratio = min(size[0] / old_w, size[1] / old_h) - new_w = int(np.floor(old_w * scale_ratio)) - new_h = int(np.floor(old_h * scale_ratio)) - resized_img = mmcv.imresize(img, (new_w, new_h), backend='cv2') - return resized_img - - -def voc2012_preprocess(input_image, output_bin_path): - img_name = input_image.split('/')[-1] - bin_name = img_name.split('.')[0] + ".bin" - bin_fl = os.path.join(output_bin_path, bin_name) - - one_img = mmcv.imread(os.path.join(input_image), backend='cv2') - one_img = resize(one_img, (tensor_width, tensor_height)) - mean = np.array(dataset_config['mean'], dtype=np.float16) - std = np.array(dataset_config['std'], dtype=np.float16) - one_img = mmcv.imnormalize(one_img, mean, std) - - h = one_img.shape[0] - w = one_img.shape[1] - pad_left = (tensor_width - w) // 2 - pad_top = (tensor_height - h) // 2 - pad_right = tensor_width - pad_left - w - pad_bottom = tensor_height - pad_top - h - one_img = mmcv.impad(one_img, padding=(pad_left, pad_top, pad_right, pad_bottom), pad_val=0) - one_img=one_img.astype(np.float16) - one_img = one_img.transpose(2, 0, 1) - one_img.tofile(bin_fl) - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='preprocess of FCN-8s pytorch model') - parser.add_argument("--image_folder_path", default="/opt/npu/VOCdevkit/VOC2012/JPEGImages/", - help='image of dataset') - parser.add_argument("--split", default="/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt") - parser.add_argument("--bin_folder_path", default="./voc12_bin/", help='Preprocessed image buffer') - flags = parser.parse_args() - - if not os.path.exists(flags.bin_folder_path): - os.makedirs(flags.bin_folder_path) - - split = flags.split - img_suffix = '.jpg' - img_infos = [] - if split is not None: - with open(split) as f: - for line in f: - img_name = line.strip() - img_info = img_name + img_suffix - img_infos.append(img_info) - print(img_infos) - images = os.listdir(flags.image_folder_path) - - for image_name in images: - if not (image_name.endswith(".jpeg") or image_name.endswith(".JPEG") or image_name.endswith( - ".jpg") and image_name in img_infos): - continue - print("start to process image {}....".format(image_name)) - path_image = os.path.join(flags.image_folder_path, image_name) - voc2012_preprocess(path_image, flags.bin_folder_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import argparse +import numpy as np +import cv2 +import mmcv +import torch + + +dataset_config = { + 'mean': (123.675, 116.28, 103.53), + 'std': (58.395, 57.12, 57.375) +} + + +tensor_height = 500 +tensor_width = 500 + + +def resize(img, size): + old_h = img.shape[0] + old_w = img.shape[1] + scale_ratio = min(size[0] / old_w, size[1] / old_h) + new_w = int(np.floor(old_w * scale_ratio)) + new_h = int(np.floor(old_h * scale_ratio)) + resized_img = mmcv.imresize(img, (new_w, new_h), backend='cv2') + return resized_img + + +def voc2012_preprocess(input_image, output_bin_path): + img_name = input_image.split('/')[-1] + bin_name = img_name.split('.')[0] + ".bin" + bin_fl = os.path.join(output_bin_path, bin_name) + + one_img = mmcv.imread(os.path.join(input_image), backend='cv2') + one_img = resize(one_img, (tensor_width, tensor_height)) + mean = np.array(dataset_config['mean'], dtype=np.float16) + std = np.array(dataset_config['std'], dtype=np.float16) + one_img = mmcv.imnormalize(one_img, mean, std) + + h = one_img.shape[0] + w = one_img.shape[1] + pad_left = (tensor_width - w) // 2 + pad_top = (tensor_height - h) // 2 + pad_right = tensor_width - pad_left - w + pad_bottom = tensor_height - pad_top - h + one_img = mmcv.impad(one_img, padding=(pad_left, pad_top, pad_right, pad_bottom), pad_val=0) + one_img=one_img.astype(np.float16) + one_img = one_img.transpose(2, 0, 1) + one_img.tofile(bin_fl) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='preprocess of FCN-8s pytorch model') + parser.add_argument("--image_folder_path", default="/opt/npu/VOCdevkit/VOC2012/JPEGImages/", + help='image of dataset') + parser.add_argument("--split", default="/opt/npu/VOCdevkit/VOC2012/ImageSets/Segmentation/val.txt") + parser.add_argument("--bin_folder_path", default="./voc12_bin/", help='Preprocessed image buffer') + flags = parser.parse_args() + + if not os.path.exists(flags.bin_folder_path): + os.makedirs(flags.bin_folder_path) + + split = flags.split + img_suffix = '.jpg' + img_infos = [] + if split is not None: + with open(split) as f: + for line in f: + img_name = line.strip() + img_info = img_name + img_suffix + img_infos.append(img_info) + print(img_infos) + images = os.listdir(flags.image_folder_path) + + for image_name in images: + if not (image_name.endswith(".jpeg") or image_name.endswith(".JPEG") or image_name.endswith( + ".jpg") and image_name in img_infos): + continue + print("start to process image {}....".format(image_name)) + path_image = os.path.join(flags.image_folder_path, image_name) + voc2012_preprocess(path_image, flags.bin_folder_path) diff --git a/ACL_PyTorch/contrib/cv/segmentation/PSPnet/requirements.txt b/ACL_PyTorch/contrib/cv/segmentation/PSPnet/requirements.txt index b61b7bcdad2d8b509e3de4f97bb4d74ffcfe6429..f86ad403f35f1e158cb4397d24e2f69c92d9aa92 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/PSPnet/requirements.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/PSPnet/requirements.txt @@ -1,5 +1,5 @@ -torch == 1.8.0 -torchvision == 0.9.0 -onnx == 1.9.0 -numpy == 1.20.1 +torch == 1.8.0 +torchvision == 0.9.0 +onnx == 1.9.0 +numpy == 1.20.1 opencv-python == 4.5.2.52 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/PSPnet/test/README.md b/ACL_PyTorch/contrib/cv/segmentation/PSPnet/test/README.md index c6363a7119210bd5143f56556f151c9e79635793..02d44da6c881afd4672cae9c49f975d7eb3adca9 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/PSPnet/test/README.md +++ b/ACL_PyTorch/contrib/cv/segmentation/PSPnet/test/README.md @@ -1,31 +1,31 @@ -环境准备: - -1.数据集路径 -数据集统一放在/root/datasets/或/opt/npu/ -本模型数据集放在/opt/npu/ - -2.进入工作目录 -cd pspnet - -3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -pip3.7 install -r requirements.txt - -4.获取、修改和安装模型代码 -pip3.7 install mmcv-full==1.3.10 -git clone https://github.com/open-mmlab/mmsegmentation.git -cd mmsegmentation -pip3.7 install -e . # or "python3.7 setup.py develop" -cd .. - -5.获取权重文件 -wget https://download.openmmlab.com/mmsegmentation/v0.5/pspnet/pspnet_r50-d8_512x512_20k_voc12aug/pspnet_r50-d8_512x512_20k_voc12aug_20200617_101958-ed5dfbd9.pth - -6.获取benchmark工具 -将benchmark.x86_64放在当前目录 - -7.310上执行,执行时确保device空闲 -bash test/pth2om.sh -bash test/eval_acc_perf.sh - -8.在t4环境上将onnx文件与perf_t4.sh放在同一目录 -然后执行bash perf_t4.sh,执行时确保gpu空闲 +环境准备: + +1.数据集路径 +数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集放在/opt/npu/ + +2.进入工作目录 +cd pspnet + +3.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +pip3.7 install -r requirements.txt + +4.获取、修改和安装模型代码 +pip3.7 install mmcv-full==1.3.10 +git clone https://github.com/open-mmlab/mmsegmentation.git +cd mmsegmentation +pip3.7 install -e . # or "python3.7 setup.py develop" +cd .. + +5.获取权重文件 +wget https://download.openmmlab.com/mmsegmentation/v0.5/pspnet/pspnet_r50-d8_512x512_20k_voc12aug/pspnet_r50-d8_512x512_20k_voc12aug_20200617_101958-ed5dfbd9.pth + +6.获取benchmark工具 +将benchmark.x86_64放在当前目录 + +7.310上执行,执行时确保device空闲 +bash test/pth2om.sh +bash test/eval_acc_perf.sh + +8.在t4环境上将onnx文件与perf_t4.sh放在同一目录 +然后执行bash perf_t4.sh,执行时确保gpu空闲 diff --git a/ACL_PyTorch/contrib/cv/segmentation/PSPnet/test/parse.py b/ACL_PyTorch/contrib/cv/segmentation/PSPnet/test/parse.py index a0f253b055047b199b33d4b65cdc79177b6b250b..27eae0d0acf98687edd95f1f024cf77c49cd4dc4 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/PSPnet/test/parse.py +++ b/ACL_PyTorch/contrib/cv/segmentation/PSPnet/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/README.md b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/README.md index 5d027295ce8f68657e1c4cb877e3a165dbd68625..2213525e4055ae8b68e65b0901d804ad11fc2f36 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/README.md +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/README.md @@ -1,67 +1,67 @@ -# SOLOV1模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -``` -pip install -r requirements.txt -``` -说明:PyTorch选用开源1.9.0版本 - - - -2.获取,修改与安装开源模型代码 -安装mmcv -``` -git clone https://github.com/open-mmlab/mmcv -b v0.2.16 -cd mmcv -python setup.py build_ext -python setup.py develop -cd .. -``` -获取SOLOv1代码 -``` -git clone https://github.com/WXinlong/SOLO.git -b master -cd SOLO -git reset --hard 95f3732d5fbb0d7c7044c7dd074f439d48a72ce5 -patch -p1 < ../MMDET.diff -patch -p1 < ../SOLOV1.diff -pip install -r requirements/build.txt -pip install -v -e . -cd .. -``` - - -3.获取权重文件 - -请从[原始开源代码仓](https://github.com/WXinlong/SOLO)下载SOLO_R50_1x模型的权重文件 - -4.数据集 - -数据集的获取请参考[原始开源代码仓](https://github.com/WXinlong/SOLO)的方式获取。请将val2017图片及其标注文件放入服务器/root/dataset/coco/文件夹,val2017目录存放coco数据集的验证集图片,annotations目录存放coco数据集的instances_val2017.json,文件目录结构如下: -``` -root -├── dataset -│ ├── coco -│ │ ├── annotations -│ │ ├── val2017 -``` - -5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) -将benchmark.x86_64或benchmark.aarch64放到当前目录 - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -#启动脚本内1-2行为pth2onnx,3-4行为onnx2om,脚本执行完成后会生成SOLOV2.onnx、SOLOV2_sim.onnx、solov2.om三个文件。 -bash test/pth2om.sh -#启动脚本内9-21行为前处理,用以获取处理后的图片信息与bin文件;23-33为获取图片info文件,为推理做准备;35-42行为benchmark推理;44-51行为后处理,同时会输出模型测评的精度;57-63行为打印om推理性能。 -bash test/eval_acc_perf.sh --datasets_path=/root/datasets -``` - **评测结果:** -| 模型 | 在线推理精度 | 310离线推理精度 | 基准性能 | 310性能 | -| :------: | :------: | :------: | :------: | :------: | -| SOLOV1 bs1 | mAP:32.1% | mAP:32.1% | 5.1fps | 6.118fps | - +# SOLOV1模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip install -r requirements.txt +``` +说明:PyTorch选用开源1.9.0版本 + + + +2.获取,修改与安装开源模型代码 +安装mmcv +``` +git clone https://github.com/open-mmlab/mmcv -b v0.2.16 +cd mmcv +python setup.py build_ext +python setup.py develop +cd .. +``` +获取SOLOv1代码 +``` +git clone https://github.com/WXinlong/SOLO.git -b master +cd SOLO +git reset --hard 95f3732d5fbb0d7c7044c7dd074f439d48a72ce5 +patch -p1 < ../MMDET.diff +patch -p1 < ../SOLOV1.diff +pip install -r requirements/build.txt +pip install -v -e . +cd .. +``` + + +3.获取权重文件 + +请从[原始开源代码仓](https://github.com/WXinlong/SOLO)下载SOLO_R50_1x模型的权重文件 + +4.数据集 + +数据集的获取请参考[原始开源代码仓](https://github.com/WXinlong/SOLO)的方式获取。请将val2017图片及其标注文件放入服务器/root/dataset/coco/文件夹,val2017目录存放coco数据集的验证集图片,annotations目录存放coco数据集的instances_val2017.json,文件目录结构如下: +``` +root +├── dataset +│ ├── coco +│ │ ├── annotations +│ │ ├── val2017 +``` + +5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) +将benchmark.x86_64或benchmark.aarch64放到当前目录 + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +#启动脚本内1-2行为pth2onnx,3-4行为onnx2om,脚本执行完成后会生成SOLOV2.onnx、SOLOV2_sim.onnx、solov2.om三个文件。 +bash test/pth2om.sh +#启动脚本内9-21行为前处理,用以获取处理后的图片信息与bin文件;23-33为获取图片info文件,为推理做准备;35-42行为benchmark推理;44-51行为后处理,同时会输出模型测评的精度;57-63行为打印om推理性能。 +bash test/eval_acc_perf.sh --datasets_path=/root/datasets +``` + **评测结果:** +| 模型 | 在线推理精度 | 310离线推理精度 | 基准性能 | 310性能 | +| :------: | :------: | :------: | :------: | :------: | +| SOLOV1 bs1 | mAP:32.1% | mAP:32.1% | 5.1fps | 6.118fps | + 备注:离线模型不支持多batch。 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/get_info.py b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/get_info.py index e0979bced843ca1e88e1d264fefc428b4835871f..fc3f14c7a31fe277de71f0ecda353c4fe9f0429f 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/get_info.py +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/get_info.py @@ -1,59 +1,59 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import mmcv -from mmdet.datasets import build_dataset -import pickle as pk - -ann_file = '/annotations/instances_val2017.json' -img_prefix = '/val2017/' - -if __name__ == '__main__': - image_src_path = sys.argv[1] - config_path = sys.argv[2] - bin_path = sys.argv[3] - meta_path = sys.argv[4] - info_name = sys.argv[5] - info_meta_name = sys.argv[6] - width = int(sys.argv[7]) - height = int(sys.argv[8]) - - cfg = mmcv.Config.fromfile(config_path) - cfg.data.test.ann_file = image_src_path + ann_file - cfg.data.test.img_prefix = image_src_path + img_prefix - - dataset = build_dataset(cfg.data.test) - - fp1 = open(info_name, "w") - fp2 = open(info_meta_name, "w") - - for idx in range(5000): - img_id = dataset.img_ids[idx] - fp1.write("{} {}/{:0>12d}.bin {} {}\n".format(idx, bin_path, img_id, width, height)) - fp_meta = open("%s/%012d.pk" % (meta_path, img_id), "rb") - meta = pk.load(fp_meta) - fp_meta.close() - fp2.write("{} {}/{:0>12d}.bin {} {} {} {}\n".format( - idx, - meta_path, - img_id, - meta['img_shape'][1], - meta['img_shape'][0], - meta['ori_shape'][1], - meta['ori_shape'][0] - )) - fp1.close() - fp2.close() - print("Get info done!") +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import mmcv +from mmdet.datasets import build_dataset +import pickle as pk + +ann_file = '/annotations/instances_val2017.json' +img_prefix = '/val2017/' + +if __name__ == '__main__': + image_src_path = sys.argv[1] + config_path = sys.argv[2] + bin_path = sys.argv[3] + meta_path = sys.argv[4] + info_name = sys.argv[5] + info_meta_name = sys.argv[6] + width = int(sys.argv[7]) + height = int(sys.argv[8]) + + cfg = mmcv.Config.fromfile(config_path) + cfg.data.test.ann_file = image_src_path + ann_file + cfg.data.test.img_prefix = image_src_path + img_prefix + + dataset = build_dataset(cfg.data.test) + + fp1 = open(info_name, "w") + fp2 = open(info_meta_name, "w") + + for idx in range(5000): + img_id = dataset.img_ids[idx] + fp1.write("{} {}/{:0>12d}.bin {} {}\n".format(idx, bin_path, img_id, width, height)) + fp_meta = open("%s/%012d.pk" % (meta_path, img_id), "rb") + meta = pk.load(fp_meta) + fp_meta.close() + fp2.write("{} {}/{:0>12d}.bin {} {} {} {}\n".format( + idx, + meta_path, + img_id, + meta['img_shape'][1], + meta['img_shape'][0], + meta['ori_shape'][1], + meta['ori_shape'][0] + )) + fp1.close() + fp2.close() + print("Get info done!") diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/modelzoo_level.txt index bdc5dd889d3e2c5450f8df13820f5d359f1a7830..5a90c7c76ee637d956ad5517b60434e8838a0ce6 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus: PERFECT \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/pth2onnx.py b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/pth2onnx.py index 4fdf107ff02a2b6e9dbb89be83d5bdaac7e6eda9..2e2add16252a058d80fc9948ef070723da003f3d 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/pth2onnx.py @@ -1,40 +1,40 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import argparse -import numpy as np -from mmdet.apis import init_detector - -input_names = ['input'] -output_names = ['seg_preds', 'cate_labels', 'cate_scores'] - - -def pth2onnx(args, fake_input): - model = init_detector(args.config, args.pth_path, device='cpu') - model.forward = model.simple_test - torch.onnx.export(model, fake_input, args.out, input_names=input_names, output_names=output_names, verbose=False, - opset_version=11) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--config', help='model config') - parser.add_argument('--out', help='onnx output name') - parser.add_argument('--pth_path', help='model pth path') - parser.add_argument('--shape', type=int, nargs='+', help='input image size hxw') - args = parser.parse_args() - assert len(args.shape) == 2 - fake_input = torch.randn(1, 3, args.shape[0], args.shape[1]) - pth2onnx(args, fake_input) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import argparse +import numpy as np +from mmdet.apis import init_detector + +input_names = ['input'] +output_names = ['seg_preds', 'cate_labels', 'cate_scores'] + + +def pth2onnx(args, fake_input): + model = init_detector(args.config, args.pth_path, device='cpu') + model.forward = model.simple_test + torch.onnx.export(model, fake_input, args.out, input_names=input_names, output_names=output_names, verbose=False, + opset_version=11) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--config', help='model config') + parser.add_argument('--out', help='onnx output name') + parser.add_argument('--pth_path', help='model pth path') + parser.add_argument('--shape', type=int, nargs='+', help='input image size hxw') + args = parser.parse_args() + assert len(args.shape) == 2 + fake_input = torch.randn(1, 3, args.shape[0], args.shape[1]) + pth2onnx(args, fake_input) diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/requirements.txt b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/requirements.txt index 565fab966541c4a9b6eb10e9fef1ab8e58ded358..3802263668b53ce19260825a4ba3d89da72a5ac9 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/requirements.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.9.0 -torchvision == 0.10.0 -onnx == 1.9.0 -onnx-simplifier == 0.3.6 -onnxruntime == 1.8.0 +torch == 1.9.0 +torchvision == 0.10.0 +onnx == 1.9.0 +onnx-simplifier == 0.3.6 +onnxruntime == 1.8.0 numpy == 1.21.0 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/solov1_postprocess.py b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/solov1_postprocess.py index 88bd4578dc1dfab85b6dc56cd3361bd80e078b6e..0caf6ee4690ac1cc548458d3365b6ca6320c901e 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/solov1_postprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/solov1_postprocess.py @@ -1,104 +1,104 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import mmcv -import numpy as np -import argparse -import torch -import torch.nn.functional as F -import pycocotools.mask as mask_util -from mmdet.core import coco_eval, results2json, results2json_segm -from mmdet.datasets import build_dataset - -ann_file = '/annotations/instances_val2017.json' -img_prefix = '/val2017/' - - -def get_masks(result, num_classes=80): - for cur_result in result: - masks = [[] for _ in range(num_classes)] - if cur_result is None: - return masks - seg_pred = cur_result[0].astype(np.uint8) - cate_label = cur_result[1].astype(np.int) - cate_score = cur_result[2].astype(np.float) - num_ins = seg_pred.shape[0] - for idx in range(num_ins): - cur_mask = seg_pred[idx, ...] - rle = mask_util.encode( - np.array(cur_mask[:, :, np.newaxis], order='F'))[0] - rst = (rle, cate_score[idx]) - masks[cate_label[idx]].append(rst) - return masks - - -def handle_seg(seg, img_shape, ori_shape, input_shape=(800, 1216), mask_thr=0.5): - seg = torch.tensor(seg) - h, w, = img_shape - pad_left = (input_shape[1] - w) // 2 - pad_top = (input_shape[0] - h) // 2 - seg = F.interpolate(seg.unsqueeze(0), - size=input_shape, - mode='bilinear')[:, :, pad_top:pad_top + h, pad_left:pad_left + w] - - seg = F.interpolate(seg, - size=ori_shape[:2], - mode='bilinear').squeeze(0) - seg = seg > mask_thr - return seg.numpy() - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--dataset_path') - parser.add_argument('--model_config') - parser.add_argument('--bin_data_path') - parser.add_argument('--meta_info') - parser.add_argument('--net_out_num', type=int) - parser.add_argument("--model_input_height", type=int, help='input tensor height') - parser.add_argument("--model_input_width", type=int, help='input tensor width') - - args = parser.parse_args() - - cfg = mmcv.Config.fromfile(args.model_config) - cfg.data.test.test_mode = True - cfg.data.test.ann_file = args.dataset_path + ann_file - cfg.data.test.img_prefix = args.dataset_path + img_prefix - dataset = build_dataset(cfg.data.test) - num_classes = len(dataset.CLASSES) - - results = [] - - fp = open(args.meta_info, "r") - for line in fp.readlines(): - _, file_path, img_w, img_h, ori_w, ori_h = line.split() - img_w = int(img_w) - img_h = int(img_h) - ori_w = int(ori_w) - ori_h = int(ori_h) - file_name = file_path.split("/")[1].replace(".bin", "") - result = [] - for idx in range(args.net_out_num): - if idx == 1: - result.append(np.fromfile("%s%s_%d.bin" % (args.bin_data_path, file_name, idx + 1), dtype=np.int32)) - else: - result.append(np.fromfile("%s%s_%d.bin" % (args.bin_data_path, file_name, idx + 1), dtype=np.float32)) - result[0].shape = (100, args.model_input_height // 4, args.model_input_width // 4) - result[0] = handle_seg(result[0], (img_h, img_w), (ori_h, ori_w), - (args.model_input_height, args.model_input_width)) - result = get_masks([result], num_classes) - results.append(result) - fp.close() - result_files = results2json_segm(dataset, results, "results_solo.pkl") - coco_eval(result_files, ["segm"], dataset.coco) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import mmcv +import numpy as np +import argparse +import torch +import torch.nn.functional as F +import pycocotools.mask as mask_util +from mmdet.core import coco_eval, results2json, results2json_segm +from mmdet.datasets import build_dataset + +ann_file = '/annotations/instances_val2017.json' +img_prefix = '/val2017/' + + +def get_masks(result, num_classes=80): + for cur_result in result: + masks = [[] for _ in range(num_classes)] + if cur_result is None: + return masks + seg_pred = cur_result[0].astype(np.uint8) + cate_label = cur_result[1].astype(np.int) + cate_score = cur_result[2].astype(np.float) + num_ins = seg_pred.shape[0] + for idx in range(num_ins): + cur_mask = seg_pred[idx, ...] + rle = mask_util.encode( + np.array(cur_mask[:, :, np.newaxis], order='F'))[0] + rst = (rle, cate_score[idx]) + masks[cate_label[idx]].append(rst) + return masks + + +def handle_seg(seg, img_shape, ori_shape, input_shape=(800, 1216), mask_thr=0.5): + seg = torch.tensor(seg) + h, w, = img_shape + pad_left = (input_shape[1] - w) // 2 + pad_top = (input_shape[0] - h) // 2 + seg = F.interpolate(seg.unsqueeze(0), + size=input_shape, + mode='bilinear')[:, :, pad_top:pad_top + h, pad_left:pad_left + w] + + seg = F.interpolate(seg, + size=ori_shape[:2], + mode='bilinear').squeeze(0) + seg = seg > mask_thr + return seg.numpy() + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--dataset_path') + parser.add_argument('--model_config') + parser.add_argument('--bin_data_path') + parser.add_argument('--meta_info') + parser.add_argument('--net_out_num', type=int) + parser.add_argument("--model_input_height", type=int, help='input tensor height') + parser.add_argument("--model_input_width", type=int, help='input tensor width') + + args = parser.parse_args() + + cfg = mmcv.Config.fromfile(args.model_config) + cfg.data.test.test_mode = True + cfg.data.test.ann_file = args.dataset_path + ann_file + cfg.data.test.img_prefix = args.dataset_path + img_prefix + dataset = build_dataset(cfg.data.test) + num_classes = len(dataset.CLASSES) + + results = [] + + fp = open(args.meta_info, "r") + for line in fp.readlines(): + _, file_path, img_w, img_h, ori_w, ori_h = line.split() + img_w = int(img_w) + img_h = int(img_h) + ori_w = int(ori_w) + ori_h = int(ori_h) + file_name = file_path.split("/")[1].replace(".bin", "") + result = [] + for idx in range(args.net_out_num): + if idx == 1: + result.append(np.fromfile("%s%s_%d.bin" % (args.bin_data_path, file_name, idx + 1), dtype=np.int32)) + else: + result.append(np.fromfile("%s%s_%d.bin" % (args.bin_data_path, file_name, idx + 1), dtype=np.float32)) + result[0].shape = (100, args.model_input_height // 4, args.model_input_width // 4) + result[0] = handle_seg(result[0], (img_h, img_w), (ori_h, ori_w), + (args.model_input_height, args.model_input_width)) + result = get_masks([result], num_classes) + results.append(result) + fp.close() + result_files = results2json_segm(dataset, results, "results_solo.pkl") + coco_eval(result_files, ["segm"], dataset.coco) diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/solov1_preprocess.py b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/solov1_preprocess.py index d82a93d367ef72200a1b0726b5c28a95843647aa..448b1cc203d63920dedd8ddcc28a1d264c45d95d 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/solov1_preprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/solov1_preprocess.py @@ -1,86 +1,86 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import argparse -import numpy as np -import cv2 -import mmcv -import torch -import pickle as pk -import multiprocessing - -flags = None - -def resize(img, size): - old_h = img.shape[0] - old_w = img.shape[1] - scale_ratio = min(size[0] / old_w, size[1] / old_h) - new_w = int(np.floor(old_w * scale_ratio)) - new_h = int(np.floor(old_h * scale_ratio)) - resized_img = mmcv.imresize(img, (new_w, new_h)) - return resized_img, scale_ratio - - -def gen_input_bin(file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - image = mmcv.imread(os.path.join(flags.image_src_path, file)) - ori_shape = image.shape - image, scale_factor = resize(image, (flags.model_input_width, flags.model_input_height)) - img_shape = image.shape - mean = np.array([123.675, 116.28, 103.53], dtype=np.float32) - std = np.array([58.395, 57.12, 57.375], dtype=np.float32) - image = mmcv.imnormalize(image, mean, std) - h = image.shape[0] - w = image.shape[1] - pad_left = (flags.model_input_width - w) // 2 - pad_top = (flags.model_input_height - h) // 2 - pad_right = flags.model_input_width - pad_left - w - pad_bottom = flags.model_input_height - pad_top - h - image = cv2.copyMakeBorder(image, pad_top, pad_bottom, pad_left, pad_right, cv2.BORDER_CONSTANT, value=0) - image = image.transpose(2, 0, 1) - image.tofile(os.path.join(flags.bin_file_path, file.split('.')[0] + ".bin")) - image_meta = {'img_shape': img_shape, 'scale_factor': scale_factor, 'ori_shape': ori_shape} - with open(os.path.join(flags.meta_file_path, file.split('.')[0] + ".pk"), "wb") as fp: - pk.dump(image_meta, fp) - - -def preprocess(): - files = os.listdir(flags.image_src_path) - file_batches = [files[i:i + 100] for i in range(0, 5000, 100) if files[i:i + 100] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='preprocess of MaskRCNN PyTorch model') - parser.add_argument("--image_src_path", default="/root/datasets/coco/val2017", help='image of dataset') - parser.add_argument("--bin_file_path", default="val2017_bin", help='Preprocessed image buffer') - parser.add_argument("--meta_file_path", default="val2017_bin_meta", help='Get image meta') - parser.add_argument("--model_input_height", default=800, type=int, help='input tensor height') - parser.add_argument("--model_input_width", default=1216, type=int, help='input tensor width') - flags = parser.parse_args() - if not os.path.exists(flags.bin_file_path): - os.makedirs(flags.bin_file_path) - if not os.path.exists(flags.meta_file_path): - os.makedirs(flags.meta_file_path) - preprocess() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import argparse +import numpy as np +import cv2 +import mmcv +import torch +import pickle as pk +import multiprocessing + +flags = None + +def resize(img, size): + old_h = img.shape[0] + old_w = img.shape[1] + scale_ratio = min(size[0] / old_w, size[1] / old_h) + new_w = int(np.floor(old_w * scale_ratio)) + new_h = int(np.floor(old_h * scale_ratio)) + resized_img = mmcv.imresize(img, (new_w, new_h)) + return resized_img, scale_ratio + + +def gen_input_bin(file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + image = mmcv.imread(os.path.join(flags.image_src_path, file)) + ori_shape = image.shape + image, scale_factor = resize(image, (flags.model_input_width, flags.model_input_height)) + img_shape = image.shape + mean = np.array([123.675, 116.28, 103.53], dtype=np.float32) + std = np.array([58.395, 57.12, 57.375], dtype=np.float32) + image = mmcv.imnormalize(image, mean, std) + h = image.shape[0] + w = image.shape[1] + pad_left = (flags.model_input_width - w) // 2 + pad_top = (flags.model_input_height - h) // 2 + pad_right = flags.model_input_width - pad_left - w + pad_bottom = flags.model_input_height - pad_top - h + image = cv2.copyMakeBorder(image, pad_top, pad_bottom, pad_left, pad_right, cv2.BORDER_CONSTANT, value=0) + image = image.transpose(2, 0, 1) + image.tofile(os.path.join(flags.bin_file_path, file.split('.')[0] + ".bin")) + image_meta = {'img_shape': img_shape, 'scale_factor': scale_factor, 'ori_shape': ori_shape} + with open(os.path.join(flags.meta_file_path, file.split('.')[0] + ".pk"), "wb") as fp: + pk.dump(image_meta, fp) + + +def preprocess(): + files = os.listdir(flags.image_src_path) + file_batches = [files[i:i + 100] for i in range(0, 5000, 100) if files[i:i + 100] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='preprocess of MaskRCNN PyTorch model') + parser.add_argument("--image_src_path", default="/root/datasets/coco/val2017", help='image of dataset') + parser.add_argument("--bin_file_path", default="val2017_bin", help='Preprocessed image buffer') + parser.add_argument("--meta_file_path", default="val2017_bin_meta", help='Get image meta') + parser.add_argument("--model_input_height", default=800, type=int, help='input tensor height') + parser.add_argument("--model_input_width", default=1216, type=int, help='input tensor width') + flags = parser.parse_args() + if not os.path.exists(flags.bin_file_path): + os.makedirs(flags.bin_file_path) + if not os.path.exists(flags.meta_file_path): + os.makedirs(flags.meta_file_path) + preprocess() diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/test/parse.py b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/test/parse.py index b9c74f41d7848e1250356f14472b237a18bb3489..82af69cd183218c3263723c20b652b3f7ec2bc27 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/test/parse.py +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV1/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/README.md b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/README.md index bc9a8f0bce10f33734d413b420683d63ac3791df..59d8bf9d7d23fbf255877dde4f75bfcd39c3cfa2 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/README.md +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/README.md @@ -1,67 +1,67 @@ -# SOLOV2模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -``` -pip install -r requirements.txt -``` -说明:PyTorch选用开源1.9.0版本 - - - -2.获取,修改与安装开源模型代码 -安装mmcv -``` -git clone https://github.com/open-mmlab/mmcv -b v0.2.16 -cd mmcv -python setup.py build_ext -python setup.py develop -cd .. -``` -获取SOLOv2代码 -``` -git clone https://github.com/WXinlong/SOLO.git -b master -cd SOLO -git reset --hard 95f3732d5fbb0d7c7044c7dd074f439d48a72ce5 -patch -p1 < ../MMDET.diff -patch -p1 < ../SOLOV2.diff -pip install -r requirements/build.txt -pip install -v -e . -cd .. -``` - - -3.获取权重文件 - -请从[原始开源代码仓](https://github.com/WXinlong/SOLO)下载SOLOv2_R50_1x模型的权重文件 - -4.数据集 - -数据集的获取请参考[原始开源代码仓](https://github.com/WXinlong/SOLO)的方式获取。请将val2017图片及其标注文件放入服务器/root/dataset/coco/文件夹,val2017目录存放coco数据集的验证集图片,annotations目录存放coco数据集的instances_val2017.json,文件目录结构如下: -``` -root -├── dataset -│ ├── coco -│ │ ├── annotations -│ │ ├── val2017 -``` - -5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) -将benchmark.x86_64或benchmark.aarch64放到当前目录 - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -#启动脚本内1-2行为pth2onnx,3-4行为onnx2om,脚本执行完成后会生成SOLOV2.onnx、SOLOV2_sim.onnx、solov2.om三个文件。 -bash test/pth2om.sh -#启动脚本内9-21行为前处理,用以获取处理后的图片信息与bin文件;23-33为获取图片info文件,为推理做准备;35-42行为benchmark推理;44-51行为后处理,同时会输出模型测评的精度;57-63行为打印om推理性能。 -bash test/eval_acc_perf.sh --datasets_path=/root/datasets -``` - **评测结果:** -| 模型 | 在线推理精度 | 310离线推理精度 | 基准性能 | 310性能 | -| :------: | :------: | :------: | :------: | :------: | -| SOLOV2 bs1 | mAP:34.0% | mAP:34.0% | 7.58fps | 9.877fps | - -备注:离线模型不支持多batch。 +# SOLOV2模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip install -r requirements.txt +``` +说明:PyTorch选用开源1.9.0版本 + + + +2.获取,修改与安装开源模型代码 +安装mmcv +``` +git clone https://github.com/open-mmlab/mmcv -b v0.2.16 +cd mmcv +python setup.py build_ext +python setup.py develop +cd .. +``` +获取SOLOv2代码 +``` +git clone https://github.com/WXinlong/SOLO.git -b master +cd SOLO +git reset --hard 95f3732d5fbb0d7c7044c7dd074f439d48a72ce5 +patch -p1 < ../MMDET.diff +patch -p1 < ../SOLOV2.diff +pip install -r requirements/build.txt +pip install -v -e . +cd .. +``` + + +3.获取权重文件 + +请从[原始开源代码仓](https://github.com/WXinlong/SOLO)下载SOLOv2_R50_1x模型的权重文件 + +4.数据集 + +数据集的获取请参考[原始开源代码仓](https://github.com/WXinlong/SOLO)的方式获取。请将val2017图片及其标注文件放入服务器/root/dataset/coco/文件夹,val2017目录存放coco数据集的验证集图片,annotations目录存放coco数据集的instances_val2017.json,文件目录结构如下: +``` +root +├── dataset +│ ├── coco +│ │ ├── annotations +│ │ ├── val2017 +``` + +5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) +将benchmark.x86_64或benchmark.aarch64放到当前目录 + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +#启动脚本内1-2行为pth2onnx,3-4行为onnx2om,脚本执行完成后会生成SOLOV2.onnx、SOLOV2_sim.onnx、solov2.om三个文件。 +bash test/pth2om.sh +#启动脚本内9-21行为前处理,用以获取处理后的图片信息与bin文件;23-33为获取图片info文件,为推理做准备;35-42行为benchmark推理;44-51行为后处理,同时会输出模型测评的精度;57-63行为打印om推理性能。 +bash test/eval_acc_perf.sh --datasets_path=/root/datasets +``` + **评测结果:** +| 模型 | 在线推理精度 | 310离线推理精度 | 基准性能 | 310性能 | +| :------: | :------: | :------: | :------: | :------: | +| SOLOV2 bs1 | mAP:34.0% | mAP:34.0% | 7.58fps | 9.877fps | + +备注:离线模型不支持多batch。 diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/get_info.py b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/get_info.py index e0979bced843ca1e88e1d264fefc428b4835871f..fc3f14c7a31fe277de71f0ecda353c4fe9f0429f 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/get_info.py +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/get_info.py @@ -1,59 +1,59 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import mmcv -from mmdet.datasets import build_dataset -import pickle as pk - -ann_file = '/annotations/instances_val2017.json' -img_prefix = '/val2017/' - -if __name__ == '__main__': - image_src_path = sys.argv[1] - config_path = sys.argv[2] - bin_path = sys.argv[3] - meta_path = sys.argv[4] - info_name = sys.argv[5] - info_meta_name = sys.argv[6] - width = int(sys.argv[7]) - height = int(sys.argv[8]) - - cfg = mmcv.Config.fromfile(config_path) - cfg.data.test.ann_file = image_src_path + ann_file - cfg.data.test.img_prefix = image_src_path + img_prefix - - dataset = build_dataset(cfg.data.test) - - fp1 = open(info_name, "w") - fp2 = open(info_meta_name, "w") - - for idx in range(5000): - img_id = dataset.img_ids[idx] - fp1.write("{} {}/{:0>12d}.bin {} {}\n".format(idx, bin_path, img_id, width, height)) - fp_meta = open("%s/%012d.pk" % (meta_path, img_id), "rb") - meta = pk.load(fp_meta) - fp_meta.close() - fp2.write("{} {}/{:0>12d}.bin {} {} {} {}\n".format( - idx, - meta_path, - img_id, - meta['img_shape'][1], - meta['img_shape'][0], - meta['ori_shape'][1], - meta['ori_shape'][0] - )) - fp1.close() - fp2.close() - print("Get info done!") +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import mmcv +from mmdet.datasets import build_dataset +import pickle as pk + +ann_file = '/annotations/instances_val2017.json' +img_prefix = '/val2017/' + +if __name__ == '__main__': + image_src_path = sys.argv[1] + config_path = sys.argv[2] + bin_path = sys.argv[3] + meta_path = sys.argv[4] + info_name = sys.argv[5] + info_meta_name = sys.argv[6] + width = int(sys.argv[7]) + height = int(sys.argv[8]) + + cfg = mmcv.Config.fromfile(config_path) + cfg.data.test.ann_file = image_src_path + ann_file + cfg.data.test.img_prefix = image_src_path + img_prefix + + dataset = build_dataset(cfg.data.test) + + fp1 = open(info_name, "w") + fp2 = open(info_meta_name, "w") + + for idx in range(5000): + img_id = dataset.img_ids[idx] + fp1.write("{} {}/{:0>12d}.bin {} {}\n".format(idx, bin_path, img_id, width, height)) + fp_meta = open("%s/%012d.pk" % (meta_path, img_id), "rb") + meta = pk.load(fp_meta) + fp_meta.close() + fp2.write("{} {}/{:0>12d}.bin {} {} {} {}\n".format( + idx, + meta_path, + img_id, + meta['img_shape'][1], + meta['img_shape'][0], + meta['ori_shape'][1], + meta['ori_shape'][0] + )) + fp1.close() + fp2.close() + print("Get info done!") diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/modelzoo_level.txt index bdc5dd889d3e2c5450f8df13820f5d359f1a7830..5a90c7c76ee637d956ad5517b60434e8838a0ce6 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus: PERFECT \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/pth2onnx.py b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/pth2onnx.py index 4fdf107ff02a2b6e9dbb89be83d5bdaac7e6eda9..2e2add16252a058d80fc9948ef070723da003f3d 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/pth2onnx.py @@ -1,40 +1,40 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import argparse -import numpy as np -from mmdet.apis import init_detector - -input_names = ['input'] -output_names = ['seg_preds', 'cate_labels', 'cate_scores'] - - -def pth2onnx(args, fake_input): - model = init_detector(args.config, args.pth_path, device='cpu') - model.forward = model.simple_test - torch.onnx.export(model, fake_input, args.out, input_names=input_names, output_names=output_names, verbose=False, - opset_version=11) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--config', help='model config') - parser.add_argument('--out', help='onnx output name') - parser.add_argument('--pth_path', help='model pth path') - parser.add_argument('--shape', type=int, nargs='+', help='input image size hxw') - args = parser.parse_args() - assert len(args.shape) == 2 - fake_input = torch.randn(1, 3, args.shape[0], args.shape[1]) - pth2onnx(args, fake_input) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import argparse +import numpy as np +from mmdet.apis import init_detector + +input_names = ['input'] +output_names = ['seg_preds', 'cate_labels', 'cate_scores'] + + +def pth2onnx(args, fake_input): + model = init_detector(args.config, args.pth_path, device='cpu') + model.forward = model.simple_test + torch.onnx.export(model, fake_input, args.out, input_names=input_names, output_names=output_names, verbose=False, + opset_version=11) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--config', help='model config') + parser.add_argument('--out', help='onnx output name') + parser.add_argument('--pth_path', help='model pth path') + parser.add_argument('--shape', type=int, nargs='+', help='input image size hxw') + args = parser.parse_args() + assert len(args.shape) == 2 + fake_input = torch.randn(1, 3, args.shape[0], args.shape[1]) + pth2onnx(args, fake_input) diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/requirements.txt b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/requirements.txt index 565fab966541c4a9b6eb10e9fef1ab8e58ded358..3802263668b53ce19260825a4ba3d89da72a5ac9 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/requirements.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.9.0 -torchvision == 0.10.0 -onnx == 1.9.0 -onnx-simplifier == 0.3.6 -onnxruntime == 1.8.0 +torch == 1.9.0 +torchvision == 0.10.0 +onnx == 1.9.0 +onnx-simplifier == 0.3.6 +onnxruntime == 1.8.0 numpy == 1.21.0 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/solov2_postprocess.py b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/solov2_postprocess.py index 88bd4578dc1dfab85b6dc56cd3361bd80e078b6e..0caf6ee4690ac1cc548458d3365b6ca6320c901e 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/solov2_postprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/solov2_postprocess.py @@ -1,104 +1,104 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import mmcv -import numpy as np -import argparse -import torch -import torch.nn.functional as F -import pycocotools.mask as mask_util -from mmdet.core import coco_eval, results2json, results2json_segm -from mmdet.datasets import build_dataset - -ann_file = '/annotations/instances_val2017.json' -img_prefix = '/val2017/' - - -def get_masks(result, num_classes=80): - for cur_result in result: - masks = [[] for _ in range(num_classes)] - if cur_result is None: - return masks - seg_pred = cur_result[0].astype(np.uint8) - cate_label = cur_result[1].astype(np.int) - cate_score = cur_result[2].astype(np.float) - num_ins = seg_pred.shape[0] - for idx in range(num_ins): - cur_mask = seg_pred[idx, ...] - rle = mask_util.encode( - np.array(cur_mask[:, :, np.newaxis], order='F'))[0] - rst = (rle, cate_score[idx]) - masks[cate_label[idx]].append(rst) - return masks - - -def handle_seg(seg, img_shape, ori_shape, input_shape=(800, 1216), mask_thr=0.5): - seg = torch.tensor(seg) - h, w, = img_shape - pad_left = (input_shape[1] - w) // 2 - pad_top = (input_shape[0] - h) // 2 - seg = F.interpolate(seg.unsqueeze(0), - size=input_shape, - mode='bilinear')[:, :, pad_top:pad_top + h, pad_left:pad_left + w] - - seg = F.interpolate(seg, - size=ori_shape[:2], - mode='bilinear').squeeze(0) - seg = seg > mask_thr - return seg.numpy() - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--dataset_path') - parser.add_argument('--model_config') - parser.add_argument('--bin_data_path') - parser.add_argument('--meta_info') - parser.add_argument('--net_out_num', type=int) - parser.add_argument("--model_input_height", type=int, help='input tensor height') - parser.add_argument("--model_input_width", type=int, help='input tensor width') - - args = parser.parse_args() - - cfg = mmcv.Config.fromfile(args.model_config) - cfg.data.test.test_mode = True - cfg.data.test.ann_file = args.dataset_path + ann_file - cfg.data.test.img_prefix = args.dataset_path + img_prefix - dataset = build_dataset(cfg.data.test) - num_classes = len(dataset.CLASSES) - - results = [] - - fp = open(args.meta_info, "r") - for line in fp.readlines(): - _, file_path, img_w, img_h, ori_w, ori_h = line.split() - img_w = int(img_w) - img_h = int(img_h) - ori_w = int(ori_w) - ori_h = int(ori_h) - file_name = file_path.split("/")[1].replace(".bin", "") - result = [] - for idx in range(args.net_out_num): - if idx == 1: - result.append(np.fromfile("%s%s_%d.bin" % (args.bin_data_path, file_name, idx + 1), dtype=np.int32)) - else: - result.append(np.fromfile("%s%s_%d.bin" % (args.bin_data_path, file_name, idx + 1), dtype=np.float32)) - result[0].shape = (100, args.model_input_height // 4, args.model_input_width // 4) - result[0] = handle_seg(result[0], (img_h, img_w), (ori_h, ori_w), - (args.model_input_height, args.model_input_width)) - result = get_masks([result], num_classes) - results.append(result) - fp.close() - result_files = results2json_segm(dataset, results, "results_solo.pkl") - coco_eval(result_files, ["segm"], dataset.coco) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import mmcv +import numpy as np +import argparse +import torch +import torch.nn.functional as F +import pycocotools.mask as mask_util +from mmdet.core import coco_eval, results2json, results2json_segm +from mmdet.datasets import build_dataset + +ann_file = '/annotations/instances_val2017.json' +img_prefix = '/val2017/' + + +def get_masks(result, num_classes=80): + for cur_result in result: + masks = [[] for _ in range(num_classes)] + if cur_result is None: + return masks + seg_pred = cur_result[0].astype(np.uint8) + cate_label = cur_result[1].astype(np.int) + cate_score = cur_result[2].astype(np.float) + num_ins = seg_pred.shape[0] + for idx in range(num_ins): + cur_mask = seg_pred[idx, ...] + rle = mask_util.encode( + np.array(cur_mask[:, :, np.newaxis], order='F'))[0] + rst = (rle, cate_score[idx]) + masks[cate_label[idx]].append(rst) + return masks + + +def handle_seg(seg, img_shape, ori_shape, input_shape=(800, 1216), mask_thr=0.5): + seg = torch.tensor(seg) + h, w, = img_shape + pad_left = (input_shape[1] - w) // 2 + pad_top = (input_shape[0] - h) // 2 + seg = F.interpolate(seg.unsqueeze(0), + size=input_shape, + mode='bilinear')[:, :, pad_top:pad_top + h, pad_left:pad_left + w] + + seg = F.interpolate(seg, + size=ori_shape[:2], + mode='bilinear').squeeze(0) + seg = seg > mask_thr + return seg.numpy() + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--dataset_path') + parser.add_argument('--model_config') + parser.add_argument('--bin_data_path') + parser.add_argument('--meta_info') + parser.add_argument('--net_out_num', type=int) + parser.add_argument("--model_input_height", type=int, help='input tensor height') + parser.add_argument("--model_input_width", type=int, help='input tensor width') + + args = parser.parse_args() + + cfg = mmcv.Config.fromfile(args.model_config) + cfg.data.test.test_mode = True + cfg.data.test.ann_file = args.dataset_path + ann_file + cfg.data.test.img_prefix = args.dataset_path + img_prefix + dataset = build_dataset(cfg.data.test) + num_classes = len(dataset.CLASSES) + + results = [] + + fp = open(args.meta_info, "r") + for line in fp.readlines(): + _, file_path, img_w, img_h, ori_w, ori_h = line.split() + img_w = int(img_w) + img_h = int(img_h) + ori_w = int(ori_w) + ori_h = int(ori_h) + file_name = file_path.split("/")[1].replace(".bin", "") + result = [] + for idx in range(args.net_out_num): + if idx == 1: + result.append(np.fromfile("%s%s_%d.bin" % (args.bin_data_path, file_name, idx + 1), dtype=np.int32)) + else: + result.append(np.fromfile("%s%s_%d.bin" % (args.bin_data_path, file_name, idx + 1), dtype=np.float32)) + result[0].shape = (100, args.model_input_height // 4, args.model_input_width // 4) + result[0] = handle_seg(result[0], (img_h, img_w), (ori_h, ori_w), + (args.model_input_height, args.model_input_width)) + result = get_masks([result], num_classes) + results.append(result) + fp.close() + result_files = results2json_segm(dataset, results, "results_solo.pkl") + coco_eval(result_files, ["segm"], dataset.coco) diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/solov2_preprocess.py b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/solov2_preprocess.py index d82a93d367ef72200a1b0726b5c28a95843647aa..448b1cc203d63920dedd8ddcc28a1d264c45d95d 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/solov2_preprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/solov2_preprocess.py @@ -1,86 +1,86 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import argparse -import numpy as np -import cv2 -import mmcv -import torch -import pickle as pk -import multiprocessing - -flags = None - -def resize(img, size): - old_h = img.shape[0] - old_w = img.shape[1] - scale_ratio = min(size[0] / old_w, size[1] / old_h) - new_w = int(np.floor(old_w * scale_ratio)) - new_h = int(np.floor(old_h * scale_ratio)) - resized_img = mmcv.imresize(img, (new_w, new_h)) - return resized_img, scale_ratio - - -def gen_input_bin(file_batches, batch): - i = 0 - for file in file_batches[batch]: - i = i + 1 - print("batch", batch, file, "===", i) - - image = mmcv.imread(os.path.join(flags.image_src_path, file)) - ori_shape = image.shape - image, scale_factor = resize(image, (flags.model_input_width, flags.model_input_height)) - img_shape = image.shape - mean = np.array([123.675, 116.28, 103.53], dtype=np.float32) - std = np.array([58.395, 57.12, 57.375], dtype=np.float32) - image = mmcv.imnormalize(image, mean, std) - h = image.shape[0] - w = image.shape[1] - pad_left = (flags.model_input_width - w) // 2 - pad_top = (flags.model_input_height - h) // 2 - pad_right = flags.model_input_width - pad_left - w - pad_bottom = flags.model_input_height - pad_top - h - image = cv2.copyMakeBorder(image, pad_top, pad_bottom, pad_left, pad_right, cv2.BORDER_CONSTANT, value=0) - image = image.transpose(2, 0, 1) - image.tofile(os.path.join(flags.bin_file_path, file.split('.')[0] + ".bin")) - image_meta = {'img_shape': img_shape, 'scale_factor': scale_factor, 'ori_shape': ori_shape} - with open(os.path.join(flags.meta_file_path, file.split('.')[0] + ".pk"), "wb") as fp: - pk.dump(image_meta, fp) - - -def preprocess(): - files = os.listdir(flags.image_src_path) - file_batches = [files[i:i + 100] for i in range(0, 5000, 100) if files[i:i + 100] != []] - thread_pool = multiprocessing.Pool(len(file_batches)) - for batch in range(len(file_batches)): - thread_pool.apply_async(gen_input_bin, args=(file_batches, batch)) - thread_pool.close() - thread_pool.join() - print("in thread, except will not report! please ensure bin files generated.") - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='preprocess of MaskRCNN PyTorch model') - parser.add_argument("--image_src_path", default="/root/datasets/coco/val2017", help='image of dataset') - parser.add_argument("--bin_file_path", default="val2017_bin", help='Preprocessed image buffer') - parser.add_argument("--meta_file_path", default="val2017_bin_meta", help='Get image meta') - parser.add_argument("--model_input_height", default=800, type=int, help='input tensor height') - parser.add_argument("--model_input_width", default=1216, type=int, help='input tensor width') - flags = parser.parse_args() - if not os.path.exists(flags.bin_file_path): - os.makedirs(flags.bin_file_path) - if not os.path.exists(flags.meta_file_path): - os.makedirs(flags.meta_file_path) - preprocess() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import argparse +import numpy as np +import cv2 +import mmcv +import torch +import pickle as pk +import multiprocessing + +flags = None + +def resize(img, size): + old_h = img.shape[0] + old_w = img.shape[1] + scale_ratio = min(size[0] / old_w, size[1] / old_h) + new_w = int(np.floor(old_w * scale_ratio)) + new_h = int(np.floor(old_h * scale_ratio)) + resized_img = mmcv.imresize(img, (new_w, new_h)) + return resized_img, scale_ratio + + +def gen_input_bin(file_batches, batch): + i = 0 + for file in file_batches[batch]: + i = i + 1 + print("batch", batch, file, "===", i) + + image = mmcv.imread(os.path.join(flags.image_src_path, file)) + ori_shape = image.shape + image, scale_factor = resize(image, (flags.model_input_width, flags.model_input_height)) + img_shape = image.shape + mean = np.array([123.675, 116.28, 103.53], dtype=np.float32) + std = np.array([58.395, 57.12, 57.375], dtype=np.float32) + image = mmcv.imnormalize(image, mean, std) + h = image.shape[0] + w = image.shape[1] + pad_left = (flags.model_input_width - w) // 2 + pad_top = (flags.model_input_height - h) // 2 + pad_right = flags.model_input_width - pad_left - w + pad_bottom = flags.model_input_height - pad_top - h + image = cv2.copyMakeBorder(image, pad_top, pad_bottom, pad_left, pad_right, cv2.BORDER_CONSTANT, value=0) + image = image.transpose(2, 0, 1) + image.tofile(os.path.join(flags.bin_file_path, file.split('.')[0] + ".bin")) + image_meta = {'img_shape': img_shape, 'scale_factor': scale_factor, 'ori_shape': ori_shape} + with open(os.path.join(flags.meta_file_path, file.split('.')[0] + ".pk"), "wb") as fp: + pk.dump(image_meta, fp) + + +def preprocess(): + files = os.listdir(flags.image_src_path) + file_batches = [files[i:i + 100] for i in range(0, 5000, 100) if files[i:i + 100] != []] + thread_pool = multiprocessing.Pool(len(file_batches)) + for batch in range(len(file_batches)): + thread_pool.apply_async(gen_input_bin, args=(file_batches, batch)) + thread_pool.close() + thread_pool.join() + print("in thread, except will not report! please ensure bin files generated.") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='preprocess of MaskRCNN PyTorch model') + parser.add_argument("--image_src_path", default="/root/datasets/coco/val2017", help='image of dataset') + parser.add_argument("--bin_file_path", default="val2017_bin", help='Preprocessed image buffer') + parser.add_argument("--meta_file_path", default="val2017_bin_meta", help='Get image meta') + parser.add_argument("--model_input_height", default=800, type=int, help='input tensor height') + parser.add_argument("--model_input_width", default=1216, type=int, help='input tensor width') + flags = parser.parse_args() + if not os.path.exists(flags.bin_file_path): + os.makedirs(flags.bin_file_path) + if not os.path.exists(flags.meta_file_path): + os.makedirs(flags.meta_file_path) + preprocess() diff --git a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/test/parse.py b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/test/parse.py index b9c74f41d7848e1250356f14472b237a18bb3489..82af69cd183218c3263723c20b652b3f7ec2bc27 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/test/parse.py +++ b/ACL_PyTorch/contrib/cv/segmentation/SOLOV2/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/SiamMask/LICENSE b/ACL_PyTorch/contrib/cv/segmentation/SiamMask/LICENSE index 29f81d812f3e768fa89638d1f72920dbfd1413a8..261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/SiamMask/LICENSE +++ b/ACL_PyTorch/contrib/cv/segmentation/SiamMask/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ACL_PyTorch/contrib/cv/segmentation/Ultra-Fast-Lane-Detection/LICENSE b/ACL_PyTorch/contrib/cv/segmentation/Ultra-Fast-Lane-Detection/LICENSE index 29f81d812f3e768fa89638d1f72920dbfd1413a8..261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/Ultra-Fast-Lane-Detection/LICENSE +++ b/ACL_PyTorch/contrib/cv/segmentation/Ultra-Fast-Lane-Detection/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ACL_PyTorch/contrib/cv/segmentation/Ultra-Fast-Lane-Detection/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/segmentation/Ultra-Fast-Lane-Detection/modelzoo_level.txt index 51b74557c15082ae794632436e724456a0fdcfde..5c956b09db3bcabe37a0665848500a6419125fee 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/Ultra-Fast-Lane-Detection/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/Ultra-Fast-Lane-Detection/modelzoo_level.txt @@ -1,6 +1,6 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK -PerfStatus:OK -ModelConvert:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK +PerfStatus:OK +ModelConvert:OK QuantStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/VNet/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/segmentation/VNet/modelzoo_level.txt index 403465b84e39e2cc8a387c33aaf5a1043f8d267a..ec6168981c278bbe672c13a4eb251b6ec184eda4 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/VNet/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/VNet/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:Perfect \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/Wseg/README.md b/ACL_PyTorch/contrib/cv/segmentation/Wseg/README.md index 7da45005704981967d9c71238d7c06f65aa10ed2..61fd261750b960035e0be788d46c0cafb4579b38 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/Wseg/README.md +++ b/ACL_PyTorch/contrib/cv/segmentation/Wseg/README.md @@ -1,66 +1,66 @@ -# Wseg模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,并且安装以下可能已经安装过的需求包 -``` -pip3.7 install -r requirements.txt -``` - -2.获取开源模型的代码,并修改文件夹名称为wseg -``` -git clone https://github.com/visinf/1-stage-wseg -b master -git reset cfe5784f9905d656e0f15fba0e6eb76a3731d80f --hard -mv 1-stage-wseg wseg -``` - -3.获取权重文件 -1. 获取经过预训练的基础网络权重文件并且放在代码仓的以下路径中:`/models/weights/`. - - | Backbone | Initial Weights | - |:---:|:---:| - | WideResNet38 | [ilsvrc-cls_rna-a1_cls1000_ep-0001.pth (402M)](https://download.visinf.tu-darmstadt.de/data/2020-cvpr-araslanov-1-stage-wseg/models/ilsvrc-cls_rna-a1_cls1000_ep-0001.pth) | - -2. 获取功能网络权重(作者提供的pth模型)并放置于代码仓的以下路径中:(初始代码仓无snapshots文件夹,需要自己新建路径)`/snapshots/` - - | Backbone | Val | Link | - |:---:|:---:|---:| - | WideResNet38 | 62.7 | [model_enc_e020Xs0.928.pth (527M)](https://download.visinf.tu-darmstadt.de/data/2020-cvpr-araslanov-1-stage-wseg/models/model_enc_e020Xs0.928.pth) | - -3. 移动上述两个权重文件到代码仓指定位置,以待加载使用 -``` -mkdir ./models/weights -mv ilsvrc-cls_rna-a1_cls1000_ep-0001.pth ./models/weights -mkdir ./snapshots -mv model_enc_e020Xs0.928.pth ./snapshots -``` - -4.下载数据集,解压,将文件名改为voc,并将其放于代码仓中的以下路径: `/data/` -- VOC: [Training/Validation (2GB .tar file)](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar) - -``` -tar -zxvf VOCtrainval_11-May-2012.tar -mv VOCtrainval_11-May-2012 voc -mkdir ./data -mv voc ./data -``` - -5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) -将benchmark.x86_64或benchmark.aarch64放到当前目录 - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=./data -``` - **评测结果:** - -| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| :------: | :------: | :------: | :------: | :------: | -| WideResNet38 bs1 | [IOU: 62.7](https://github.com/visinf/1-stage-wseg) | IOU:63.7 | 5.270fps | 3.496fps | -| WideResNet38 bs4 | [IOU: 62.7](https://github.com/visinf/1-stage-wseg) | IOU:63.7 | 5.460fps | 3.912fps | - - **备注:** +# Wseg模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,并且安装以下可能已经安装过的需求包 +``` +pip3.7 install -r requirements.txt +``` + +2.获取开源模型的代码,并修改文件夹名称为wseg +``` +git clone https://github.com/visinf/1-stage-wseg -b master +git reset cfe5784f9905d656e0f15fba0e6eb76a3731d80f --hard +mv 1-stage-wseg wseg +``` + +3.获取权重文件 +1. 获取经过预训练的基础网络权重文件并且放在代码仓的以下路径中:`/models/weights/`. + + | Backbone | Initial Weights | + |:---:|:---:| + | WideResNet38 | [ilsvrc-cls_rna-a1_cls1000_ep-0001.pth (402M)](https://download.visinf.tu-darmstadt.de/data/2020-cvpr-araslanov-1-stage-wseg/models/ilsvrc-cls_rna-a1_cls1000_ep-0001.pth) | + +2. 获取功能网络权重(作者提供的pth模型)并放置于代码仓的以下路径中:(初始代码仓无snapshots文件夹,需要自己新建路径)`/snapshots/` + + | Backbone | Val | Link | + |:---:|:---:|---:| + | WideResNet38 | 62.7 | [model_enc_e020Xs0.928.pth (527M)](https://download.visinf.tu-darmstadt.de/data/2020-cvpr-araslanov-1-stage-wseg/models/model_enc_e020Xs0.928.pth) | + +3. 移动上述两个权重文件到代码仓指定位置,以待加载使用 +``` +mkdir ./models/weights +mv ilsvrc-cls_rna-a1_cls1000_ep-0001.pth ./models/weights +mkdir ./snapshots +mv model_enc_e020Xs0.928.pth ./snapshots +``` + +4.下载数据集,解压,将文件名改为voc,并将其放于代码仓中的以下路径: `/data/` +- VOC: [Training/Validation (2GB .tar file)](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar) + +``` +tar -zxvf VOCtrainval_11-May-2012.tar +mv VOCtrainval_11-May-2012 voc +mkdir ./data +mv voc ./data +``` + +5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) +将benchmark.x86_64或benchmark.aarch64放到当前目录 + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=./data +``` + **评测结果:** + +| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| :------: | :------: | :------: | :------: | :------: | +| WideResNet38 bs1 | [IOU: 62.7](https://github.com/visinf/1-stage-wseg) | IOU:63.7 | 5.270fps | 3.496fps | +| WideResNet38 bs4 | [IOU: 62.7](https://github.com/visinf/1-stage-wseg) | IOU:63.7 | 5.460fps | 3.912fps | + + **备注:** - 由于分辨率大内存使用多,故仅用bs1与bs4进行评测 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/Wseg/Wseg_postprocess.py b/ACL_PyTorch/contrib/cv/segmentation/Wseg/Wseg_postprocess.py index 6a70b18b443c5a4b52e22389e6e3377e00fea85d..6a4864b8ef07928434bcb941d73138cc8f807fd5 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/Wseg/Wseg_postprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/Wseg/Wseg_postprocess.py @@ -1,375 +1,375 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import numpy as np -import torch -import torchvision.transforms.functional as F -import torchvision.transforms as tf -import pydensecrf.densecrf as dcrf -import torch.nn.functional as Func -from PIL import Image, ImagePalette -from pydensecrf.utils import unary_from_softmax - -class Normalize(): - def __init__(self, mean = (0.485, 0.456, 0.406), std = (0.229, 0.224, 0.225)): - - self.mean = mean - self.std = std - - def undo(self, imgarr): - proc_img = imgarr.copy() - - proc_img[..., 0] = (self.std[0] * imgarr[..., 0] + self.mean[0]) * 255. - proc_img[..., 1] = (self.std[1] * imgarr[..., 1] + self.mean[1]) * 255. - proc_img[..., 2] = (self.std[2] * imgarr[..., 2] + self.mean[2]) * 255. - - return proc_img - - def __call__(self, img): - imgarr = np.asarray(img) - proc_img = np.empty_like(imgarr, np.float32) - - proc_img[..., 0] = (imgarr[..., 0] / 255. - self.mean[0]) / self.std[0] - proc_img[..., 1] = (imgarr[..., 1] / 255. - self.mean[1]) / self.std[1] - proc_img[..., 2] = (imgarr[..., 2] / 255. - self.mean[2]) / self.std[2] - - return proc_img - -def colormap(N=256): - def bitget(byteval, idx): - return ((byteval & (1 << idx)) != 0) - - dtype = 'uint8' - cmap = [] - for i in range(N): - r = g = b = 0 - c = i - for j in range(8): - r = r | (bitget(c, 0) << 7-j) - g = g | (bitget(c, 1) << 7-j) - b = b | (bitget(c, 2) << 7-j) - c = c >> 3 - - cmap.append((r, g, b)) - return cmap - -def get_palette(): - cmap = colormap() - palette = ImagePalette.ImagePalette() - for rgb in cmap: - palette.getcolor(rgb) - return palette - -def crf_inference(img, probs, t=10, scale_factor=1, labels=21): - - h, w = img.shape[:2] - n_labels = labels - - d = dcrf.DenseCRF2D(w, h, n_labels) - - unary = unary_from_softmax(probs) - unary = np.ascontiguousarray(unary) - - d.setUnaryEnergy(unary) - d.addPairwiseGaussian(sxy=3/scale_factor, compat=3) - d.addPairwiseBilateral(sxy=80/scale_factor, srgb=13, rgbim=np.copy(img), compat=10) - Q = d.inference(t) - - return np.array(Q).reshape((n_labels, h, w)) - -def _cut(x_chw, pads): - pad_h, pad_w, h, w = [int(p) for p in pads] - return x_chw[:, pad_h:(pad_h + h), pad_w:(pad_w + w)] - -def _mask_overlay(mask, image, alpha=0.3): - - mask_rgb = __mask2rgb(mask) - return alpha * image + (1 - alpha) * mask_rgb - -def __mask2rgb(mask): - im = Image.fromarray(mask).convert("P") - im.putpalette(get_palette()) - mask_rgb = np.array(im.convert("RGB"), dtype=np.float) - return mask_rgb / 255. - -def _merge_masks(masks, labels, pads, imsize_hw): - - mask_list = [] - for i, mask in enumerate(masks.split(1, dim=0)): - - # removing the padding - mask_cut = _cut(mask[0], pads[i]).unsqueeze(0) - # normalising the scale - mask_cut = Func.interpolate(mask_cut, imsize_hw, mode='bilinear', align_corners=False)[0] - - # flipping if necessary - if i % 2 == 1: - mask_cut = torch.flip(mask_cut, (-1, )) - - # getting the max response - mask_cut[1:, ::] *= labels[:, None, None] - mask_list.append(mask_cut) - - mean_mask = sum(mask_list).numpy() / len(mask_list) - - # discounting BG - mean_mask[0, ::] = np.power(mean_mask[0, ::], 3) - - return mean_mask - -def save(out_path, img_path, img_orig, all_masks, labels, pads, gt_mask): - - img_name = os.path.basename(img_path).rstrip(".jpg") - - # converting original image to [0, 255] - img_orig255 = np.round(255. * img_orig).astype(np.uint8) - img_orig255 = np.transpose(img_orig255, [1, 2, 0]) - img_orig255 = np.ascontiguousarray(img_orig255) - - merged_mask = _merge_masks(all_masks, pads, labels, img_orig255.shape[:2]) - pred = np.argmax(merged_mask, 0) - - # CRF - pred_crf = crf_inference(img_orig255, merged_mask, t=10, scale_factor=1, labels=21) - pred_crf = np.argmax(pred_crf, 0) - - filepath = os.path.join(out_path, img_name + '.png') - img_pred = Image.fromarray(pred.astype(np.uint8)) - img_pred.save(filepath) - - filepath = os.path.join(out_path, "crf", img_name + '.png') - img_pred_crf = Image.fromarray(pred_crf.astype(np.uint8)) - img_pred_crf.save(filepath) - mask_gt = gt_mask - masks_all = np.concatenate([pred, pred_crf, mask_gt], 1).astype(np.uint8) - images = np.concatenate([img_orig] * 3, 2) - images = np.transpose(images, [1, 2, 0]) - - overlay = _mask_overlay(masks_all, images) - filepath = os.path.join(out_path, "vis", img_name + '.png') - overlay255 = np.round(overlay * 255.).astype(np.uint8) - overlay255_crf = Image.fromarray(overlay255) - overlay255_crf.save(filepath) - -def load_img_name_list(dataset_path, index=0): - img_gt_name_list = open(dataset_path).read().splitlines() - img_name_list = [img_gt_name.split(' ')[index].strip('/') for img_gt_name in img_gt_name_list] - - return img_name_list - -def load_label_name_list(dataset_path): - return load_img_name_list(dataset_path, index=1) - -def pad(image,pad_size): - w, h = image.size - - pad_height = pad_size[0] - h - pad_width = pad_size[1] - w - - assert pad_height >= 0 and pad_width >= 0 - - pad_l = max(0, pad_width // 2) - pad_t = max(0, pad_height // 2) - - return [pad_t, pad_l] - -def imgread(imgpath): - fullpath = os.path.join(imgpath) - img = Image.open(fullpath).convert("RGB") - return fullpath, img - -def getitem(img_path,labelpath): - - name, img = imgread(img_path) - - # label_fullpath = self.label_list[idx] - assert len(labelpath) < 256, "Expected label path less than 256 for padding" - - mask = Image.open(labelpath) - mask = np.array(mask) - NUM_CLASS = 21 - labels = torch.zeros(NUM_CLASS - 1) - - # it will also be sorted - unique_labels = np.unique(mask) - - # ambigious - if unique_labels[-1] == CLASS_IDX['ambiguous']: - unique_labels = unique_labels[:-1] - - # background - if unique_labels[0] == CLASS_IDX['background']: - unique_labels = unique_labels[1:] - - assert unique_labels.size > 0, 'No labels found ' - unique_labels -= 1 # shifting since no BG class - labels[unique_labels.tolist()] = 1 - - return name, img, labels, mask.astype(np.int) - -def get_one_image(img_path,label_path): - - transform = tf.Compose([np.asarray, - Normalize()]) - pad_size = [1024, 1024] - scales = [1, 0.5, 1.5, 2.0] - batch_size = 8 - use_flips = True - - pad_batch = [] - - for i in range(batch_size): - - sub_idx = i % batch_size - scale = scales[sub_idx // (2 if use_flips else 1)] - flip = use_flips and sub_idx % 2 - - name, img, label, mask = getitem(img_path, label_path) - - target_size = (int(round(img.size[0] * scale)), - int(round(img.size[1] * scale))) - - s_img = img.resize(target_size, resample=Image.CUBIC) - - if flip: - s_img = F.hflip(s_img) - - w, h = s_img.size - pads_tl = pad(s_img,pad_size) - pad_t, pad_l = pads_tl - img = F.to_tensor(transform(img)) - pads = torch.Tensor([pad_t, pad_l, h, w]) - pad_batch.append(pads) - - return name, img, pad_batch, label, mask - -def check_dir(base_path, name): - - # create the directory - fullpath = os.path.join(base_path, name) - if not os.path.exists(fullpath): - os.makedirs(fullpath) - - return fullpath - -def bintonp(name,bin_path): - mask = [] - cls = [] - for i in range(8): - msk_name = bin_path + '/' + str(name) + '_' + str(i) + "_1.bin" - cls_name = bin_path + '/' + str(name) + '_' + str(i) + "_2.bin" - mask_i = np.fromfile(msk_name, dtype=np.float32) - mask_i.shape = 21,1024,1024 - cls_i = np.fromfile(cls_name, dtype=np.float32) - cls_i.shape = 20 - cls.append(cls_i) - mask.append(mask_i) - msk = np.array(mask) - clss = np.array(cls) - - return clss, msk - -def denorm(image): - - MEAN = (0.485, 0.456, 0.406) - STD = (0.229, 0.224, 0.225) - - if image.dim() == 3: - assert image.dim() == 3, "Expected image [CxHxW]" - assert image.size(0) == 3, "Expected RGB image [3xHxW]" - - for t, m, s in zip(image, MEAN, STD): - t.mul_(s).add_(m) - elif image.dim() == 4: - # batch mode - assert image.size(1) == 3, "Expected RGB image [3xHxW]" - - for t, m, s in zip((0,1,2), MEAN, STD): - image[:, t, :, :].mul_(s).add_(m) - - return image - -def postprocess(file_path, voc12_root,out_path, bin_path): - - img_name_list = load_img_name_list(file_path) - label_name_list = load_label_name_list(file_path) - - print("Start postprocess!") - print("total image number: ",len(img_name_list)) - - for i in range(len(img_name_list)): - - imgnm = img_name_list[i][33:-4] - print("==========> ", i, " ", imgnm) - img_path = voc12_root + '/' + img_name_list[i] - label_path = voc12_root + '/' + label_name_list[i] - print(img_path) - name, img, pad_batch, labels, gt_mask = get_one_image(img_path,label_path) - - with torch.no_grad(): - cls_raw, masks_pred = bintonp(imgnm,bin_path) - masks_pred = torch.from_numpy(masks_pred) - cls_raw = torch.from_numpy(cls_raw) - - cls_sigmoid = torch.sigmoid(cls_raw) - cls_sigmoid, _ = cls_sigmoid.max(0) - labels = (cls_sigmoid > 0.1) - - # saving the raw npy - image = denorm(img).numpy() - masks_pred = masks_pred.cpu() - labels = labels.type_as(masks_pred) - - save(out_path, name, image, masks_pred, pad_batch, labels, gt_mask) - - -if __name__ == '__main__': - - CLASS_IDX = { - 'background': 0, - 'aeroplane': 1, - 'bicycle': 2, - 'bird': 3, - 'boat': 4, - 'bottle': 5, - 'bus': 6, - 'car': 7, - 'cat': 8, - 'chair': 9, - 'cow': 10, - 'diningtable': 11, - 'dog': 12, - 'horse': 13, - 'motorbike': 14, - 'person': 15, - 'potted-plant': 16, - 'sheep': 17, - 'sofa': 18, - 'train': 19, - 'tv/monitor': 20, - 'ambiguous': 255 - } - - voc12_root_path = os.path.abspath(sys.argv[1]) - file_path = os.path.abspath(sys.argv[2]) - bin_path = os.path.abspath(sys.argv[3]) - out_path = os.path.abspath(sys.argv[4]) - - - check_dir(out_path, "vis") - check_dir(out_path, "crf") - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import numpy as np +import torch +import torchvision.transforms.functional as F +import torchvision.transforms as tf +import pydensecrf.densecrf as dcrf +import torch.nn.functional as Func +from PIL import Image, ImagePalette +from pydensecrf.utils import unary_from_softmax + +class Normalize(): + def __init__(self, mean = (0.485, 0.456, 0.406), std = (0.229, 0.224, 0.225)): + + self.mean = mean + self.std = std + + def undo(self, imgarr): + proc_img = imgarr.copy() + + proc_img[..., 0] = (self.std[0] * imgarr[..., 0] + self.mean[0]) * 255. + proc_img[..., 1] = (self.std[1] * imgarr[..., 1] + self.mean[1]) * 255. + proc_img[..., 2] = (self.std[2] * imgarr[..., 2] + self.mean[2]) * 255. + + return proc_img + + def __call__(self, img): + imgarr = np.asarray(img) + proc_img = np.empty_like(imgarr, np.float32) + + proc_img[..., 0] = (imgarr[..., 0] / 255. - self.mean[0]) / self.std[0] + proc_img[..., 1] = (imgarr[..., 1] / 255. - self.mean[1]) / self.std[1] + proc_img[..., 2] = (imgarr[..., 2] / 255. - self.mean[2]) / self.std[2] + + return proc_img + +def colormap(N=256): + def bitget(byteval, idx): + return ((byteval & (1 << idx)) != 0) + + dtype = 'uint8' + cmap = [] + for i in range(N): + r = g = b = 0 + c = i + for j in range(8): + r = r | (bitget(c, 0) << 7-j) + g = g | (bitget(c, 1) << 7-j) + b = b | (bitget(c, 2) << 7-j) + c = c >> 3 + + cmap.append((r, g, b)) + return cmap + +def get_palette(): + cmap = colormap() + palette = ImagePalette.ImagePalette() + for rgb in cmap: + palette.getcolor(rgb) + return palette + +def crf_inference(img, probs, t=10, scale_factor=1, labels=21): + + h, w = img.shape[:2] + n_labels = labels + + d = dcrf.DenseCRF2D(w, h, n_labels) + + unary = unary_from_softmax(probs) + unary = np.ascontiguousarray(unary) + + d.setUnaryEnergy(unary) + d.addPairwiseGaussian(sxy=3/scale_factor, compat=3) + d.addPairwiseBilateral(sxy=80/scale_factor, srgb=13, rgbim=np.copy(img), compat=10) + Q = d.inference(t) + + return np.array(Q).reshape((n_labels, h, w)) + +def _cut(x_chw, pads): + pad_h, pad_w, h, w = [int(p) for p in pads] + return x_chw[:, pad_h:(pad_h + h), pad_w:(pad_w + w)] + +def _mask_overlay(mask, image, alpha=0.3): + + mask_rgb = __mask2rgb(mask) + return alpha * image + (1 - alpha) * mask_rgb + +def __mask2rgb(mask): + im = Image.fromarray(mask).convert("P") + im.putpalette(get_palette()) + mask_rgb = np.array(im.convert("RGB"), dtype=np.float) + return mask_rgb / 255. + +def _merge_masks(masks, labels, pads, imsize_hw): + + mask_list = [] + for i, mask in enumerate(masks.split(1, dim=0)): + + # removing the padding + mask_cut = _cut(mask[0], pads[i]).unsqueeze(0) + # normalising the scale + mask_cut = Func.interpolate(mask_cut, imsize_hw, mode='bilinear', align_corners=False)[0] + + # flipping if necessary + if i % 2 == 1: + mask_cut = torch.flip(mask_cut, (-1, )) + + # getting the max response + mask_cut[1:, ::] *= labels[:, None, None] + mask_list.append(mask_cut) + + mean_mask = sum(mask_list).numpy() / len(mask_list) + + # discounting BG + mean_mask[0, ::] = np.power(mean_mask[0, ::], 3) + + return mean_mask + +def save(out_path, img_path, img_orig, all_masks, labels, pads, gt_mask): + + img_name = os.path.basename(img_path).rstrip(".jpg") + + # converting original image to [0, 255] + img_orig255 = np.round(255. * img_orig).astype(np.uint8) + img_orig255 = np.transpose(img_orig255, [1, 2, 0]) + img_orig255 = np.ascontiguousarray(img_orig255) + + merged_mask = _merge_masks(all_masks, pads, labels, img_orig255.shape[:2]) + pred = np.argmax(merged_mask, 0) + + # CRF + pred_crf = crf_inference(img_orig255, merged_mask, t=10, scale_factor=1, labels=21) + pred_crf = np.argmax(pred_crf, 0) + + filepath = os.path.join(out_path, img_name + '.png') + img_pred = Image.fromarray(pred.astype(np.uint8)) + img_pred.save(filepath) + + filepath = os.path.join(out_path, "crf", img_name + '.png') + img_pred_crf = Image.fromarray(pred_crf.astype(np.uint8)) + img_pred_crf.save(filepath) + mask_gt = gt_mask + masks_all = np.concatenate([pred, pred_crf, mask_gt], 1).astype(np.uint8) + images = np.concatenate([img_orig] * 3, 2) + images = np.transpose(images, [1, 2, 0]) + + overlay = _mask_overlay(masks_all, images) + filepath = os.path.join(out_path, "vis", img_name + '.png') + overlay255 = np.round(overlay * 255.).astype(np.uint8) + overlay255_crf = Image.fromarray(overlay255) + overlay255_crf.save(filepath) + +def load_img_name_list(dataset_path, index=0): + img_gt_name_list = open(dataset_path).read().splitlines() + img_name_list = [img_gt_name.split(' ')[index].strip('/') for img_gt_name in img_gt_name_list] + + return img_name_list + +def load_label_name_list(dataset_path): + return load_img_name_list(dataset_path, index=1) + +def pad(image,pad_size): + w, h = image.size + + pad_height = pad_size[0] - h + pad_width = pad_size[1] - w + + assert pad_height >= 0 and pad_width >= 0 + + pad_l = max(0, pad_width // 2) + pad_t = max(0, pad_height // 2) + + return [pad_t, pad_l] + +def imgread(imgpath): + fullpath = os.path.join(imgpath) + img = Image.open(fullpath).convert("RGB") + return fullpath, img + +def getitem(img_path,labelpath): + + name, img = imgread(img_path) + + # label_fullpath = self.label_list[idx] + assert len(labelpath) < 256, "Expected label path less than 256 for padding" + + mask = Image.open(labelpath) + mask = np.array(mask) + NUM_CLASS = 21 + labels = torch.zeros(NUM_CLASS - 1) + + # it will also be sorted + unique_labels = np.unique(mask) + + # ambigious + if unique_labels[-1] == CLASS_IDX['ambiguous']: + unique_labels = unique_labels[:-1] + + # background + if unique_labels[0] == CLASS_IDX['background']: + unique_labels = unique_labels[1:] + + assert unique_labels.size > 0, 'No labels found ' + unique_labels -= 1 # shifting since no BG class + labels[unique_labels.tolist()] = 1 + + return name, img, labels, mask.astype(np.int) + +def get_one_image(img_path,label_path): + + transform = tf.Compose([np.asarray, + Normalize()]) + pad_size = [1024, 1024] + scales = [1, 0.5, 1.5, 2.0] + batch_size = 8 + use_flips = True + + pad_batch = [] + + for i in range(batch_size): + + sub_idx = i % batch_size + scale = scales[sub_idx // (2 if use_flips else 1)] + flip = use_flips and sub_idx % 2 + + name, img, label, mask = getitem(img_path, label_path) + + target_size = (int(round(img.size[0] * scale)), + int(round(img.size[1] * scale))) + + s_img = img.resize(target_size, resample=Image.CUBIC) + + if flip: + s_img = F.hflip(s_img) + + w, h = s_img.size + pads_tl = pad(s_img,pad_size) + pad_t, pad_l = pads_tl + img = F.to_tensor(transform(img)) + pads = torch.Tensor([pad_t, pad_l, h, w]) + pad_batch.append(pads) + + return name, img, pad_batch, label, mask + +def check_dir(base_path, name): + + # create the directory + fullpath = os.path.join(base_path, name) + if not os.path.exists(fullpath): + os.makedirs(fullpath) + + return fullpath + +def bintonp(name,bin_path): + mask = [] + cls = [] + for i in range(8): + msk_name = bin_path + '/' + str(name) + '_' + str(i) + "_1.bin" + cls_name = bin_path + '/' + str(name) + '_' + str(i) + "_2.bin" + mask_i = np.fromfile(msk_name, dtype=np.float32) + mask_i.shape = 21,1024,1024 + cls_i = np.fromfile(cls_name, dtype=np.float32) + cls_i.shape = 20 + cls.append(cls_i) + mask.append(mask_i) + msk = np.array(mask) + clss = np.array(cls) + + return clss, msk + +def denorm(image): + + MEAN = (0.485, 0.456, 0.406) + STD = (0.229, 0.224, 0.225) + + if image.dim() == 3: + assert image.dim() == 3, "Expected image [CxHxW]" + assert image.size(0) == 3, "Expected RGB image [3xHxW]" + + for t, m, s in zip(image, MEAN, STD): + t.mul_(s).add_(m) + elif image.dim() == 4: + # batch mode + assert image.size(1) == 3, "Expected RGB image [3xHxW]" + + for t, m, s in zip((0,1,2), MEAN, STD): + image[:, t, :, :].mul_(s).add_(m) + + return image + +def postprocess(file_path, voc12_root,out_path, bin_path): + + img_name_list = load_img_name_list(file_path) + label_name_list = load_label_name_list(file_path) + + print("Start postprocess!") + print("total image number: ",len(img_name_list)) + + for i in range(len(img_name_list)): + + imgnm = img_name_list[i][33:-4] + print("==========> ", i, " ", imgnm) + img_path = voc12_root + '/' + img_name_list[i] + label_path = voc12_root + '/' + label_name_list[i] + print(img_path) + name, img, pad_batch, labels, gt_mask = get_one_image(img_path,label_path) + + with torch.no_grad(): + cls_raw, masks_pred = bintonp(imgnm,bin_path) + masks_pred = torch.from_numpy(masks_pred) + cls_raw = torch.from_numpy(cls_raw) + + cls_sigmoid = torch.sigmoid(cls_raw) + cls_sigmoid, _ = cls_sigmoid.max(0) + labels = (cls_sigmoid > 0.1) + + # saving the raw npy + image = denorm(img).numpy() + masks_pred = masks_pred.cpu() + labels = labels.type_as(masks_pred) + + save(out_path, name, image, masks_pred, pad_batch, labels, gt_mask) + + +if __name__ == '__main__': + + CLASS_IDX = { + 'background': 0, + 'aeroplane': 1, + 'bicycle': 2, + 'bird': 3, + 'boat': 4, + 'bottle': 5, + 'bus': 6, + 'car': 7, + 'cat': 8, + 'chair': 9, + 'cow': 10, + 'diningtable': 11, + 'dog': 12, + 'horse': 13, + 'motorbike': 14, + 'person': 15, + 'potted-plant': 16, + 'sheep': 17, + 'sofa': 18, + 'train': 19, + 'tv/monitor': 20, + 'ambiguous': 255 + } + + voc12_root_path = os.path.abspath(sys.argv[1]) + file_path = os.path.abspath(sys.argv[2]) + bin_path = os.path.abspath(sys.argv[3]) + out_path = os.path.abspath(sys.argv[4]) + + + check_dir(out_path, "vis") + check_dir(out_path, "crf") + postprocess(file_path,voc12_root_path,out_path,bin_path) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/Wseg/Wseg_preprocess.py b/ACL_PyTorch/contrib/cv/segmentation/Wseg/Wseg_preprocess.py index d053c79142a020cf239e947803743d840f2ec615..015b19101d1ee5e6d96fe298911b18a8cc0e1ac7 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/Wseg/Wseg_preprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/Wseg/Wseg_preprocess.py @@ -1,126 +1,126 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import sys -import numpy as np -from PIL import Image -import torchvision.transforms.functional as F -import torchvision.transforms as tf - - -class Normalize(): - def __init__(self, mean = (0.485, 0.456, 0.406), std = (0.229, 0.224, 0.225)): - - self.mean = mean - self.std = std - - def undo(self, imgarr): - proc_img = imgarr.copy() - - proc_img[..., 0] = (self.std[0] * imgarr[..., 0] + self.mean[0]) * 255. - proc_img[..., 1] = (self.std[1] * imgarr[..., 1] + self.mean[1]) * 255. - proc_img[..., 2] = (self.std[2] * imgarr[..., 2] + self.mean[2]) * 255. - - return proc_img - - def __call__(self, img): - imgarr = np.asarray(img) - proc_img = np.empty_like(imgarr, np.float32) - - proc_img[..., 0] = (imgarr[..., 0] / 255. - self.mean[0]) / self.std[0] - proc_img[..., 1] = (imgarr[..., 1] / 255. - self.mean[1]) / self.std[1] - proc_img[..., 2] = (imgarr[..., 2] / 255. - self.mean[2]) / self.std[2] - - return proc_img - -def load_img_name_list(file_path, index=0): - img_gt_name_list = open(file_path).read().splitlines() - img_name_list = [img_gt_name.split(' ')[index].strip('/') for img_gt_name in img_gt_name_list] - return img_name_list - -def pad(image,pad_size): - w, h = image.size - - pad_mask = Image.new("L", image.size) - pad_height = pad_size[0] - h - pad_width = pad_size[1] - w - - assert pad_height >= 0 and pad_width >= 0 - - pad_l = max(0, pad_width // 2) - pad_r = max(0, pad_width - pad_l) - pad_t = max(0, pad_height // 2) - pad_b = max(0, pad_height - pad_t) - - image = F.pad(image, (pad_l, pad_t, pad_r, pad_b), fill=0, padding_mode="constant") - pad_mask = F.pad(pad_mask, (pad_l, pad_t, pad_r, pad_b), fill=1, padding_mode="constant") - - return image, pad_mask - -def get_batch_bin(img,imgname): - - pad_size = [1024, 1024] - scales = [1, 0.5, 1.5, 2.0] - batch_size = 8 - use_flips = True - - transform = tf.Compose([np.asarray, - Normalize()]) - - for i in range(batch_size): - - sub_idx = i % batch_size - scale = scales[sub_idx // (2 if use_flips else 1)] - - flip = use_flips and sub_idx % 2 - - target_size = (int(round(img.size[0] * scale)), - int(round(img.size[1] * scale))) - - s_img = img.resize(target_size, resample=Image.CUBIC) - - if flip: - s_img = F.hflip(s_img) - im_msc, ignore = pad(s_img,pad_size) - im_msc = transform(im_msc) - ignore = np.array(ignore).astype(im_msc.dtype)[..., np.newaxis] - im_msc = F.to_tensor(im_msc * (1 - ignore)) - - imgnm = imgname + "_" + str(i) - im_msc = np.array(im_msc,dtype= np.float32) - - im_msc.tofile(os.path.join(bin_path, imgnm + '.bin')) - -def preprocess(file_path, voc12_root,bin_path): - - img_name_list = load_img_name_list(file_path) - print(img_name_list) - - if not os.path.exists(bin_path): - os.makedirs(bin_path) - - for i in range(len(img_name_list)): - print("===> ",i) - imgnm = img_name_list[i][33:-4] - img = Image.open(os.path.join(voc12_root, img_name_list[i])).convert('RGB') - - get_batch_bin(img,imgnm) - -if __name__ == "__main__": - - voc12_root_path = os.path.abspath(sys.argv[1]) - file_path = os.path.abspath(sys.argv[2]) - bin_path = os.path.abspath(sys.argv[3]) - - preprocess(file_path,voc12_root_path, bin_path) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import sys +import numpy as np +from PIL import Image +import torchvision.transforms.functional as F +import torchvision.transforms as tf + + +class Normalize(): + def __init__(self, mean = (0.485, 0.456, 0.406), std = (0.229, 0.224, 0.225)): + + self.mean = mean + self.std = std + + def undo(self, imgarr): + proc_img = imgarr.copy() + + proc_img[..., 0] = (self.std[0] * imgarr[..., 0] + self.mean[0]) * 255. + proc_img[..., 1] = (self.std[1] * imgarr[..., 1] + self.mean[1]) * 255. + proc_img[..., 2] = (self.std[2] * imgarr[..., 2] + self.mean[2]) * 255. + + return proc_img + + def __call__(self, img): + imgarr = np.asarray(img) + proc_img = np.empty_like(imgarr, np.float32) + + proc_img[..., 0] = (imgarr[..., 0] / 255. - self.mean[0]) / self.std[0] + proc_img[..., 1] = (imgarr[..., 1] / 255. - self.mean[1]) / self.std[1] + proc_img[..., 2] = (imgarr[..., 2] / 255. - self.mean[2]) / self.std[2] + + return proc_img + +def load_img_name_list(file_path, index=0): + img_gt_name_list = open(file_path).read().splitlines() + img_name_list = [img_gt_name.split(' ')[index].strip('/') for img_gt_name in img_gt_name_list] + return img_name_list + +def pad(image,pad_size): + w, h = image.size + + pad_mask = Image.new("L", image.size) + pad_height = pad_size[0] - h + pad_width = pad_size[1] - w + + assert pad_height >= 0 and pad_width >= 0 + + pad_l = max(0, pad_width // 2) + pad_r = max(0, pad_width - pad_l) + pad_t = max(0, pad_height // 2) + pad_b = max(0, pad_height - pad_t) + + image = F.pad(image, (pad_l, pad_t, pad_r, pad_b), fill=0, padding_mode="constant") + pad_mask = F.pad(pad_mask, (pad_l, pad_t, pad_r, pad_b), fill=1, padding_mode="constant") + + return image, pad_mask + +def get_batch_bin(img,imgname): + + pad_size = [1024, 1024] + scales = [1, 0.5, 1.5, 2.0] + batch_size = 8 + use_flips = True + + transform = tf.Compose([np.asarray, + Normalize()]) + + for i in range(batch_size): + + sub_idx = i % batch_size + scale = scales[sub_idx // (2 if use_flips else 1)] + + flip = use_flips and sub_idx % 2 + + target_size = (int(round(img.size[0] * scale)), + int(round(img.size[1] * scale))) + + s_img = img.resize(target_size, resample=Image.CUBIC) + + if flip: + s_img = F.hflip(s_img) + im_msc, ignore = pad(s_img,pad_size) + im_msc = transform(im_msc) + ignore = np.array(ignore).astype(im_msc.dtype)[..., np.newaxis] + im_msc = F.to_tensor(im_msc * (1 - ignore)) + + imgnm = imgname + "_" + str(i) + im_msc = np.array(im_msc,dtype= np.float32) + + im_msc.tofile(os.path.join(bin_path, imgnm + '.bin')) + +def preprocess(file_path, voc12_root,bin_path): + + img_name_list = load_img_name_list(file_path) + print(img_name_list) + + if not os.path.exists(bin_path): + os.makedirs(bin_path) + + for i in range(len(img_name_list)): + print("===> ",i) + imgnm = img_name_list[i][33:-4] + img = Image.open(os.path.join(voc12_root, img_name_list[i])).convert('RGB') + + get_batch_bin(img,imgnm) + +if __name__ == "__main__": + + voc12_root_path = os.path.abspath(sys.argv[1]) + file_path = os.path.abspath(sys.argv[2]) + bin_path = os.path.abspath(sys.argv[3]) + + preprocess(file_path,voc12_root_path, bin_path) diff --git a/ACL_PyTorch/contrib/cv/segmentation/Wseg/fix_softmax_transpose.py b/ACL_PyTorch/contrib/cv/segmentation/Wseg/fix_softmax_transpose.py index 1ad1841a2056ec301b1e18a8137624ac5ba609da..9a28eca2663f2835552735faa171e1a0b0d1d270 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/Wseg/fix_softmax_transpose.py +++ b/ACL_PyTorch/contrib/cv/segmentation/Wseg/fix_softmax_transpose.py @@ -1,36 +1,36 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import onnx - -if __name__ == '__main__': - model = onnx.load(sys.argv[1]) - graph = model.graph - node = graph.node - softmax_node_index = [] - del_group = [] - for i in range(len(node)): - if node[i].op_type == 'Softmax': - del_group.append((node[i-1], node[i], node[i+1], i)) - for g in del_group: - new_input = g[0].input - new_output = g[2].output - new_name = g[1].name - new_index = g[3] - new_node = onnx.helper.make_node("Softmax", new_input, new_output, new_name, axis=1) - for n in g[:-1]: - graph.node.remove(n) - graph.node.insert(new_index, new_node) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import onnx + +if __name__ == '__main__': + model = onnx.load(sys.argv[1]) + graph = model.graph + node = graph.node + softmax_node_index = [] + del_group = [] + for i in range(len(node)): + if node[i].op_type == 'Softmax': + del_group.append((node[i-1], node[i], node[i+1], i)) + for g in del_group: + new_input = g[0].input + new_output = g[2].output + new_name = g[1].name + new_index = g[3] + new_node = onnx.helper.make_node("Softmax", new_input, new_output, new_name, axis=1) + for n in g[:-1]: + graph.node.remove(n) + graph.node.insert(new_index, new_node) onnx.save(model, sys.argv[2]) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/Wseg/get_dateset_info.py b/ACL_PyTorch/contrib/cv/segmentation/Wseg/get_dateset_info.py index f2f482c10c496b391f4429c5fe8d7b6d986e7c84..f09088e3bcb242cf4375a7d39a9f53c219fdba36 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/Wseg/get_dateset_info.py +++ b/ACL_PyTorch/contrib/cv/segmentation/Wseg/get_dateset_info.py @@ -1,60 +1,60 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - if file_type == 'bin': - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' - get_jpg_info(file_path, info_name) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + if file_type == 'bin': + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' + get_jpg_info(file_path, info_name) + diff --git a/ACL_PyTorch/contrib/cv/segmentation/Wseg/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/segmentation/Wseg/modelzoo_level.txt index 282c3ff3b30404101a02cc86c5bfeb6308d198e7..c5c4a9d8001fae97c66831abcfdbe02dd6261c37 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/Wseg/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/Wseg/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:POK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/Wseg/test/parse.py b/ACL_PyTorch/contrib/cv/segmentation/Wseg/test/parse.py index 24e62e8231605e7adb8697e1ecc7b3d96006fd03..3b35884335889363e190c05dfb1d85bef92fed26 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/Wseg/test/parse.py +++ b/ACL_PyTorch/contrib/cv/segmentation/Wseg/test/parse.py @@ -1,33 +1,33 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.eval'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.readlines() - #tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - #print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - print("".join(content[-28:])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.eval'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.readlines() + #tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + #print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + print("".join(content[-28:])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/Wseg/val_voc.txt b/ACL_PyTorch/contrib/cv/segmentation/Wseg/val_voc.txt index 98c6a5540ffec8940bba898f478929b94dfbf00a..e910b33688654a75fc54adbd2fbe410827ab70f1 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/Wseg/val_voc.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/Wseg/val_voc.txt @@ -1,300 +1,300 @@ -voc/VOCdevkit/VOC2012/JPEGImages/2007_007881.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_007881.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_006275.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_006275.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_006373.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_006373.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000573.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000573.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000572.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000572.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_001300.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_001300.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_007804.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007804.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_007378.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007378.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_002728.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002728.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_000121.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000121.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_002470.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002470.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_007392.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007392.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_006117.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_006117.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_009841.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_009841.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_002504.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002504.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_000012.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000012.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_000013.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000013.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_003003.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003003.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_000479.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_000479.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_002094.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002094.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_004538.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004538.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_007025.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007025.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_005828.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_005828.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_006028.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_006028.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_004324.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004324.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_002152.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002152.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_003275.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003275.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_003276.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003276.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001014.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001014.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_000309.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000309.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_002387.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002387.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_004281.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004281.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_003477.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003477.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_004494.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004494.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001988.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001988.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_002450.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002450.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_003187.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003187.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_003183.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003183.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_004255.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004255.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_003676.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003676.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_003473.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003473.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_000658.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_000658.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001708.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001708.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001529.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001529.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001830.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001830.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_004789.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004789.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_004190.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004190.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_004193.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004193.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_003564.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003564.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_003569.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003569.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_003876.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003876.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_003874.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003874.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_003506.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003506.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_002900.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002900.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_008296.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_008296.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_002902.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002902.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_008746.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_008746.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_002568.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002568.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_001239.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_001239.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_000874.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_000874.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_003304.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003304.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001908.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001908.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_003499.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003499.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_003492.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003492.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_002366.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002366.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_005118.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005118.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_000837.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000837.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_004795.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004795.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_000830.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000830.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_000529.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000529.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_005664.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005664.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_002415.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002415.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_002730.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002730.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_000602.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_000602.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_002094.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002094.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_000636.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000636.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_002097.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002097.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_005206.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005206.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001692.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001692.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001699.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001699.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_005038.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_005038.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_005097.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_005097.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_001640.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001640.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_005525.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_005525.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_009015.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_009015.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_000731.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_000731.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_005063.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005063.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_008127.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_008127.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001768.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001768.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_004337.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004337.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_003270.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003270.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001767.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001767.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001563.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001563.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_003137.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003137.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_003134.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003134.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_007165.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_007165.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_003131.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003131.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_008708.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_008708.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000961.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000961.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_009655.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_009655.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_009654.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_009654.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_007497.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007497.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_006560.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_006560.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_000156.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000156.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_003714.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003714.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_007498.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007498.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_004612.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_004612.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_006143.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_006143.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_003711.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003711.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_006364.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_006364.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_001314.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_001314.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_003915.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003915.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_007811.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007811.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_007814.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007814.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_002273.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002273.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_001260.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001260.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_004825.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004825.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_002719.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002719.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_003621.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003621.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_003369.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003369.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_003481.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003481.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_000573.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000573.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_004070.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004070.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_004072.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004072.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_003323.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003323.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_005857.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_005857.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_007031.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007031.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_002284.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002284.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_000481.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_000481.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_000482.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_000482.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_002046.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002046.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_006035.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_006035.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_003709.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003709.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_002445.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002445.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_007143.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007143.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_001885.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001885.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_005107.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_005107.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001287.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001287.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001281.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001281.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_000201.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000201.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_000205.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000205.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_002863.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002863.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_004856.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004856.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_004189.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004189.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_003773.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003773.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_003771.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003771.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_003576.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003576.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_002391.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002391.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_002025.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002025.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000929.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000929.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_003514.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003514.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_002864.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002864.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001601.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001601.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001350.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001350.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001607.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001607.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_002221.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002221.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_004241.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004241.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_002939.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002939.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_000120.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_000120.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_000123.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_000123.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_003311.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003311.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001913.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001913.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_005637.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_005637.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_002644.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002644.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_004687.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004687.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_002641.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002641.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_004275.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004275.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_002336.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002336.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_002317.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002317.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_002480.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002480.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_005871.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005871.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001351.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001351.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_005305.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005305.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_004783.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004783.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_004789.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004789.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_003406.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003406.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_000630.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_000630.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_005788.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005788.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_002150.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002150.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_001733.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_001733.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001174.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001174.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000174.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000174.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_008629.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_008629.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_000175.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000175.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_000999.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000999.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_002043.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002043.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_002042.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002042.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_005644.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005644.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_000700.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_000700.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_003114.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_003114.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_005399.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_005399.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_005398.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_005398.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_004322.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004322.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_004320.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004320.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001773.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001773.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000318.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000318.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000087.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000087.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001579.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001579.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000084.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000084.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000083.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000083.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_003271.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_003271.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001577.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001577.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_005899.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005899.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_001818.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_001818.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_004867.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004867.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_003197.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_003197.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_004432.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004432.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000952.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000952.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000559.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000559.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_007527.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007527.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_000149.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000149.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_006159.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_006159.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_001363.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_001363.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_002467.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002467.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_002464.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002464.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_007195.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_007195.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_007196.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_007196.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_002269.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002269.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_006554.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_006554.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_007828.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007828.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_001078.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001078.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_006036.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_006036.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_001070.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001070.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_003872.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003872.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_001074.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001074.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_001076.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001076.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_007996.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_007996.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000427.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000427.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000426.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000426.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_001565.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_001565.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000422.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000422.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_001768.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_001768.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_004497.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004497.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_001765.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_001765.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_000964.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000964.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_005844.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_005844.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_005845.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_005845.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_007048.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007048.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_005087.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_005087.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_003503.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003503.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_003506.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003506.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_000924.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000924.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_003733.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003733.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_002147.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002147.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_002903.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002903.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_000747.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_000747.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_003854.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003854.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_000346.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000346.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_002098.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002098.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001292.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001292.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_005114.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_005114.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_001895.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001895.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_004468.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004468.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_006647.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_006647.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_000219.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000219.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_003453.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003453.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_003325.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003325.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001722.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001722.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_004552.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_004552.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001726.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001726.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_004866.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004866.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_004649.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004649.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_004644.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004644.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_003542.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003542.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_005158.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_005158.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_003549.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003549.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_002030.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002030.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_003772.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003772.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_000254.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_000254.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_000622.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000622.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001619.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001619.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001341.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001341.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001614.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001614.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001613.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001613.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_001346.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001346.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_002238.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002238.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_002239.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002239.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_003895.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003895.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_000813.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_000813.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_001587.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_001587.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_002549.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002549.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001966.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001966.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_002675.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002675.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001962.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001962.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_004140.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_004140.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_001478.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001478.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_002075.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002075.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_002929.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002929.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_004455.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004455.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_001367.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001367.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_005302.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_005302.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_005860.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005860.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_008434.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_008434.png -voc/VOCdevkit/VOC2012/JPEGImages/2008_001715.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001715.png -voc/VOCdevkit/VOC2012/JPEGImages/2011_002713.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002713.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_002122.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002122.png -voc/VOCdevkit/VOC2012/JPEGImages/2009_003433.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003433.png -voc/VOCdevkit/VOC2012/JPEGImages/2007_000187.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000187.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_002146.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002146.png -voc/VOCdevkit/VOC2012/JPEGImages/2010_002929.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002929.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_007881.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_007881.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_006275.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_006275.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_006373.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_006373.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000573.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000573.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000572.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000572.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_001300.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_001300.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_007804.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007804.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_007378.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007378.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_002728.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002728.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_000121.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000121.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_002470.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002470.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_007392.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007392.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_006117.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_006117.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_009841.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_009841.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_002504.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002504.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_000012.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000012.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_000013.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000013.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_003003.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003003.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_000479.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_000479.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_002094.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002094.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_004538.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004538.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_007025.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007025.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_005828.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_005828.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_006028.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_006028.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_004324.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004324.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_002152.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002152.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_003275.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003275.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_003276.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003276.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001014.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001014.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_000309.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000309.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_002387.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002387.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_004281.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004281.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_003477.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003477.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_004494.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004494.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001988.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001988.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_002450.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002450.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_003187.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003187.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_003183.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003183.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_004255.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004255.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_003676.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003676.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_003473.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003473.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_000658.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_000658.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001708.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001708.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001529.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001529.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001830.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001830.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_004789.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004789.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_004190.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004190.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_004193.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004193.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_003564.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003564.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_003569.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003569.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_003876.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003876.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_003874.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003874.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_003506.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003506.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_002900.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002900.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_008296.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_008296.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_002902.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002902.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_008746.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_008746.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_002568.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002568.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_001239.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_001239.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_000874.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_000874.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_003304.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003304.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001908.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001908.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_003499.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003499.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_003492.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003492.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_002366.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002366.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_005118.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005118.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_000837.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000837.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_004795.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004795.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_000830.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000830.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_000529.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000529.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_005664.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005664.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_002415.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002415.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_002730.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002730.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_000602.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_000602.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_002094.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002094.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_000636.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000636.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_002097.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002097.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_005206.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005206.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001692.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001692.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001699.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001699.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_005038.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_005038.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_005097.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_005097.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_001640.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001640.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_005525.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_005525.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_009015.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_009015.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_000731.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_000731.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_005063.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005063.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_008127.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_008127.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001768.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001768.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_004337.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004337.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_003270.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003270.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001767.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001767.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001563.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001563.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_003137.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003137.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_003134.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003134.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_007165.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_007165.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_003131.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003131.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_008708.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_008708.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000961.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000961.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_009655.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_009655.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_009654.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_009654.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_007497.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007497.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_006560.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_006560.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_000156.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000156.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_003714.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003714.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_007498.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007498.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_004612.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_004612.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_006143.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_006143.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_003711.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003711.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_006364.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_006364.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_001314.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_001314.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_003915.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003915.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_007811.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007811.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_007814.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007814.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_002273.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002273.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_001260.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001260.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_004825.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004825.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_002719.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002719.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_003621.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003621.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_003369.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003369.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_003481.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003481.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_000573.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000573.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_004070.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004070.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_004072.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004072.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_003323.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003323.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_005857.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_005857.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_007031.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007031.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_002284.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002284.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_000481.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_000481.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_000482.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_000482.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_002046.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002046.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_006035.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_006035.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_003709.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003709.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_002445.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002445.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_007143.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007143.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_001885.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001885.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_005107.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_005107.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001287.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001287.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001281.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001281.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_000201.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000201.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_000205.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000205.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_002863.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002863.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_004856.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004856.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_004189.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004189.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_003773.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003773.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_003771.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003771.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_003576.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003576.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_002391.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002391.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_002025.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002025.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000929.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000929.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_003514.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003514.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_002864.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002864.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001601.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001601.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001350.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001350.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001607.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001607.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_002221.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002221.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_004241.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004241.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_002939.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002939.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_000120.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_000120.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_000123.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_000123.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_003311.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003311.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001913.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001913.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_005637.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_005637.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_002644.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002644.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_004687.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004687.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_002641.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002641.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_004275.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004275.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_002336.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002336.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_002317.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002317.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_002480.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002480.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_005871.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005871.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001351.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001351.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_005305.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005305.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_004783.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004783.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_004789.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004789.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_003406.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003406.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_000630.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_000630.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_005788.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005788.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_002150.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002150.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_001733.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_001733.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001174.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001174.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000174.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000174.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_008629.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_008629.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_000175.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000175.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_000999.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000999.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_002043.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002043.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_002042.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002042.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_005644.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005644.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_000700.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_000700.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_003114.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_003114.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_005399.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_005399.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_005398.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_005398.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_004322.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004322.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_004320.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004320.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001773.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001773.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000318.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000318.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000087.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000087.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001579.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001579.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000084.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000084.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000083.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000083.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_003271.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_003271.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001577.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001577.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_005899.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005899.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_001818.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_001818.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_004867.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004867.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_003197.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_003197.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_004432.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_004432.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000952.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000952.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000559.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000559.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_007527.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007527.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_000149.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000149.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_006159.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_006159.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_001363.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_001363.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_002467.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002467.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_002464.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002464.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_007195.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_007195.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_007196.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_007196.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_002269.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002269.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_006554.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_006554.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_007828.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007828.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_001078.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001078.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_006036.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_006036.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_001070.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001070.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_003872.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003872.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_001074.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001074.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_001076.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001076.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_007996.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_007996.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000427.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000427.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000426.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000426.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_001565.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_001565.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000422.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000422.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_001768.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_001768.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_004497.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004497.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_001765.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_001765.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_000964.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000964.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_005844.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_005844.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_005845.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_005845.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_007048.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_007048.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_005087.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_005087.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_003503.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003503.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_003506.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_003506.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_000924.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000924.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_003733.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_003733.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_002147.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002147.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_002903.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_002903.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_000747.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_000747.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_003854.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003854.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_000346.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000346.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_002098.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002098.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001292.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001292.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_005114.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_005114.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_001895.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001895.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_004468.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004468.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_006647.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_006647.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_000219.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_000219.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_003453.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003453.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_003325.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003325.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001722.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001722.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_004552.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_004552.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001726.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001726.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_004866.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004866.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_004649.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004649.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_004644.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_004644.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_003542.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003542.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_005158.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_005158.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_003549.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003549.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_002030.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002030.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_003772.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_003772.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_000254.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_000254.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_000622.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_000622.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001619.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001619.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001341.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001341.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001614.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001614.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001613.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001613.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_001346.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_001346.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_002238.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002238.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_002239.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002239.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_003895.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003895.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_000813.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_000813.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_001587.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_001587.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_002549.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002549.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001966.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001966.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_002675.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002675.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001962.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001962.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_004140.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_004140.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_001478.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001478.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_002075.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002075.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_002929.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_002929.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_004455.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_004455.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_001367.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_001367.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_005302.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_005302.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_005860.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_005860.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_008434.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_008434.png +voc/VOCdevkit/VOC2012/JPEGImages/2008_001715.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2008_001715.png +voc/VOCdevkit/VOC2012/JPEGImages/2011_002713.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2011_002713.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_002122.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_002122.png +voc/VOCdevkit/VOC2012/JPEGImages/2009_003433.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2009_003433.png +voc/VOCdevkit/VOC2012/JPEGImages/2007_000187.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2007_000187.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_002146.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002146.png +voc/VOCdevkit/VOC2012/JPEGImages/2010_002929.jpg voc/VOCdevkit/VOC2012/SegmentationClass/2010_002929.png diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT/README.md b/ACL_PyTorch/contrib/cv/segmentation/YOLACT/README.md index 7ef9506b23de412c311003095a0c0563510d994f..c57fba11d19c7dcd423ea217bb49df0c94a7291c 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/YOLACT/README.md +++ b/ACL_PyTorch/contrib/cv/segmentation/YOLACT/README.md @@ -1,155 +1,155 @@ -# YOLACT模型PyTorch离线推理指导书 - -### 一、环境准备 - -#### 1、获取依赖库 - -```shell -pip3 install -r requirements.txt -``` - -其中,PyTorch建议使用1.8.0版本。 - -使用1.5.0版本PyTorch可以正常进行om导出,且om模型精度与性能正常;但导出的onnx模型文件无法使用trtexec在T4上进行测试。 - -使用1.8.0版本PyTorch则无以上问题。 - -#### 2、获取YOLACT源代码并更新 - -- 首先获取官方代码仓代码 - - ```bash - git clone https://github.com/dbolya/yolact.git - ``` - -- 将无关文件删除,保留以下文件 - - ``` - . - ├── backbone.py - ├── data - │   ├── coco.py - │   ├── config.py - │   └── __init__.py - ├── layers - │   ├── box_utils.py - │   ├── functions - │   │   ├── detection.py - │   │   └── __init__.py - │   ├── __init__.py - │   ├── interpolate.py - │   └── output_utils.py - ├── utils - │   ├── augmentations.py - │   ├── cython_nms.pyx - │   ├── functions.py - │   ├── __init__.py - │   └── timer.py - └── yolact.py - ``` - -- 将本仓库代码拷贝至yolact目录下,并使用补丁YOLACT.patch复原 - - ``` - patch -p1 < ./YOLACT.patch - ``` - - 复原后,文件目录如下 - - ``` - . - ├── backbone.py - ├── data - │   ├── coco.py - │   ├── config.py - │   └── __init__.py - ├── env.sh - ├── layers - │   ├── box_utils.py - │   ├── functions - │   │   ├── detection.py - │   │   └── __init__.py - │   ├── __init__.py - │   ├── interpolate.py - │   └── output_utils.py - ├── LICENSE - ├── modelzoo_level.txt - ├── README.md - ├── requirements.txt - ├── test - │   ├── eval_acc_perf.sh - │   ├── parse.py - │   ├── perf_g.sh - │   └── pth2om.sh - ├── utils - │   ├── augmentations.py - │   ├── cython_nms.pyx - │   ├── functions.py - │   ├── __init__.py - │   └── timer.py - ├── weights - │   └── pth2onnx.py - ├── YOLACT.patch - ├── YOLACT_postprocess.py - ├── YOLACT_preprocess.py - └── yolact.py - ``` - -#### 3、获取权重文件 - -获取训练完毕的权重文件,建议放于./weights目录下 - -#### 4、获取数据集 - -YOLACT模型使用Microsoft COCO 2017数据集进行训练及测试。 - -在离线推理中仅使用测试数据集,测试图像为val 2017, 对应的标注文件为instances_val2017.json - -#### 5、获取benchmark工具 - -获取benchmark.x86_64离线推理工具 - - - -### 二、离线推理 - -#### 1、执行离线推理前使用以下命令查看设备状态,确保device空闲 - -```bash -npu-smi info -``` - -#### 2、执行以下命令,生成om模型文件 - -```bash -cd test -./pth2om.sh pth权重文件的路径 生成onnx的文件名 生成om的文件名 输入batch_size -``` - -注意:此处pth权重文件的路径应设为相对路径 - -#### 3、执行以下命令,开始离线推理 - -```bash -./eval_acc_perf.sh 数据集图像路径 数据集标注路径 输入batch_size om文件路径 benchmark工具路径 -``` - -同时,benchmark工具会自动统计性能数据 - -#### 4、在T4环境中执行以下命令,获取T4推理性能 - -```bash -./perf_g.sh 输入batch_size onnx文件路径 -``` - -注意,如果使用1.5.0版本PyTorch,则导出的onnx可能无法使用trtexec工具进行性能测试。因此,这里建议使用1.8.0版本PyTroch。 - - - -### 三、评测结果 - -| 模型 | 官网精度 | 310精度 | T4性能 | 310性能 | -| ----------- | ----------------------- | ----------------------- | ---------- | --------- | -| YOLACT_bs1 | box: 32.07,mask: 29.73 | box: 32.07, mask: 29.72 | 75.797FPS | 84.014FPS | -| YOLACT_bs16 | box: 32.07,mask: 29.73 | box: 32.07, mask: 29.72 | 116.596FPS | 96.161FPS | - +# YOLACT模型PyTorch离线推理指导书 + +### 一、环境准备 + +#### 1、获取依赖库 + +```shell +pip3 install -r requirements.txt +``` + +其中,PyTorch建议使用1.8.0版本。 + +使用1.5.0版本PyTorch可以正常进行om导出,且om模型精度与性能正常;但导出的onnx模型文件无法使用trtexec在T4上进行测试。 + +使用1.8.0版本PyTorch则无以上问题。 + +#### 2、获取YOLACT源代码并更新 + +- 首先获取官方代码仓代码 + + ```bash + git clone https://github.com/dbolya/yolact.git + ``` + +- 将无关文件删除,保留以下文件 + + ``` + . + ├── backbone.py + ├── data + │   ├── coco.py + │   ├── config.py + │   └── __init__.py + ├── layers + │   ├── box_utils.py + │   ├── functions + │   │   ├── detection.py + │   │   └── __init__.py + │   ├── __init__.py + │   ├── interpolate.py + │   └── output_utils.py + ├── utils + │   ├── augmentations.py + │   ├── cython_nms.pyx + │   ├── functions.py + │   ├── __init__.py + │   └── timer.py + └── yolact.py + ``` + +- 将本仓库代码拷贝至yolact目录下,并使用补丁YOLACT.patch复原 + + ``` + patch -p1 < ./YOLACT.patch + ``` + + 复原后,文件目录如下 + + ``` + . + ├── backbone.py + ├── data + │   ├── coco.py + │   ├── config.py + │   └── __init__.py + ├── env.sh + ├── layers + │   ├── box_utils.py + │   ├── functions + │   │   ├── detection.py + │   │   └── __init__.py + │   ├── __init__.py + │   ├── interpolate.py + │   └── output_utils.py + ├── LICENSE + ├── modelzoo_level.txt + ├── README.md + ├── requirements.txt + ├── test + │   ├── eval_acc_perf.sh + │   ├── parse.py + │   ├── perf_g.sh + │   └── pth2om.sh + ├── utils + │   ├── augmentations.py + │   ├── cython_nms.pyx + │   ├── functions.py + │   ├── __init__.py + │   └── timer.py + ├── weights + │   └── pth2onnx.py + ├── YOLACT.patch + ├── YOLACT_postprocess.py + ├── YOLACT_preprocess.py + └── yolact.py + ``` + +#### 3、获取权重文件 + +获取训练完毕的权重文件,建议放于./weights目录下 + +#### 4、获取数据集 + +YOLACT模型使用Microsoft COCO 2017数据集进行训练及测试。 + +在离线推理中仅使用测试数据集,测试图像为val 2017, 对应的标注文件为instances_val2017.json + +#### 5、获取benchmark工具 + +获取benchmark.x86_64离线推理工具 + + + +### 二、离线推理 + +#### 1、执行离线推理前使用以下命令查看设备状态,确保device空闲 + +```bash +npu-smi info +``` + +#### 2、执行以下命令,生成om模型文件 + +```bash +cd test +./pth2om.sh pth权重文件的路径 生成onnx的文件名 生成om的文件名 输入batch_size +``` + +注意:此处pth权重文件的路径应设为相对路径 + +#### 3、执行以下命令,开始离线推理 + +```bash +./eval_acc_perf.sh 数据集图像路径 数据集标注路径 输入batch_size om文件路径 benchmark工具路径 +``` + +同时,benchmark工具会自动统计性能数据 + +#### 4、在T4环境中执行以下命令,获取T4推理性能 + +```bash +./perf_g.sh 输入batch_size onnx文件路径 +``` + +注意,如果使用1.5.0版本PyTorch,则导出的onnx可能无法使用trtexec工具进行性能测试。因此,这里建议使用1.8.0版本PyTroch。 + + + +### 三、评测结果 + +| 模型 | 官网精度 | 310精度 | T4性能 | 310性能 | +| ----------- | ----------------------- | ----------------------- | ---------- | --------- | +| YOLACT_bs1 | box: 32.07,mask: 29.73 | box: 32.07, mask: 29.72 | 75.797FPS | 84.014FPS | +| YOLACT_bs16 | box: 32.07,mask: 29.73 | box: 32.07, mask: 29.72 | 116.596FPS | 96.161FPS | + diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT/YOLACT_postprocess.py b/ACL_PyTorch/contrib/cv/segmentation/YOLACT/YOLACT_postprocess.py index 353af75e997220bc6ff2d4ed7782dce5dd78ebf2..95e32b1ebd694ecc8dd71ae89c47c6849951ba94 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/YOLACT/YOLACT_postprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/YOLACT/YOLACT_postprocess.py @@ -1,564 +1,564 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -from layers import Detect -from data import COCODetection, get_label_map -from utils.augmentations import BaseTransform -from utils.functions import MovingAverage, ProgressBar -from layers.box_utils import jaccard, mask_iou -from utils import timer -from layers.output_utils import postprocess -import pycocotools -from data import cfg, set_cfg -import numpy as np -import torch -import argparse -import random -import pickle -import os -from collections import defaultdict -from collections import OrderedDict - -def str2bool(v): - if v.lower() in ('yes', 'true', 't', 'y', '1'): - return True - elif v.lower() in ('no', 'false', 'f', 'n', '0'): - return False - else: - raise argparse.ArgumentTypeError('Boolean value expected.') - -def parse_args(argv=None): - parser = argparse.ArgumentParser( - description='YOLACT COCO Evaluation') - parser.add_argument('--valid_images', default='/home/data/coco/images/', help='the path of validation images') - parser.add_argument('--valid_annotations', default='/home/data/coco/annotations/instances_val2017.json', help='the path of validation annotations') - parser.add_argument('--top_k', default=5, type=int, - help='Further restrict the number of predictions to parse') - parser.add_argument('--cuda', default=True, type=str2bool, - help='Use cuda to evaulate model') - parser.add_argument('--fast_nms', default=True, type=str2bool, - help='Whether to use a faster, but not entirely correct version of NMS.') - parser.add_argument('--shuffle', dest='shuffle', action='store_true', - help='Shuffles the images when displaying them. Doesn\'t have much of an effect when display is off though.') - parser.add_argument('--ap_data_file', default='results/ap_data.pkl', type=str, - help='In quantitative mode, the file to save detections before calculating mAP.') - parser.add_argument('--max_images', default=-1, type=int, - help='The maximum number of images from the dataset to consider. Use -1 for all.') - parser.add_argument('--output_coco_json', dest='output_coco_json', action='store_true', - help='If display is not set, instead of processing IoU values, this just dumps detections into the coco json file.') - parser.add_argument('--config', default=None, - help='The config object to use.') - parser.add_argument('--no_bar', dest='no_bar', action='store_true', - help='Do not output the status bar. This is useful for when piping to a file.') - parser.add_argument('--no_sort', default=False, dest='no_sort', action='store_true', - help='Do not sort images by hashed image ID.') - parser.add_argument('--seed', default=None, type=int, - help='The seed to pass into random.seed. Note: this is only really for the shuffle and does not (I think) affect cuda stuff.') - parser.add_argument('--mask_proto_debug', default=False, dest='mask_proto_debug', action='store_true', - help='Outputs stuff for scripts/compute_mask.py.') - parser.add_argument('--score_threshold', default=0, type=float, - help='Detections with a score under this threshold will not be considered. This currently only works in display mode.') - parser.add_argument('--dataset', default=None, type=str, - help='If specified, override the dataset specified in the config with this one (example: coco2017_dataset).') - parser.add_argument('--detect', default=False, dest='detect', action='store_true', - help='Don\'t evauluate the mask branch at all and only do object detection. This only works for --display and --benchmark.') - - parser.set_defaults(no_bar=False, output_coco_json=False, shuffle=False, - no_sort=False, mask_proto_debug=False, detect=False, crop=True) - - global args - args = parser.parse_args(argv) - - if args.seed is not None: - random.seed(args.seed) - -iou_thresholds = [x / 100 for x in range(50, 100, 5)] -coco_cats = {} # Call prep_coco_cats to fill this -coco_cats_inv = {} -color_cache = defaultdict(lambda: {}) - -def prep_coco_cats(): - """ Prepare inverted table for category id lookup given a coco cats object. """ - for coco_cat_id, transformed_cat_id_p1 in get_label_map().items(): - transformed_cat_id = transformed_cat_id_p1 - 1 - coco_cats[transformed_cat_id] = coco_cat_id - coco_cats_inv[coco_cat_id] = transformed_cat_id - -def get_coco_cat(transformed_cat_id): - """ transformed_cat_id is [0,80) as indices in cfg.dataset.class_names """ - return coco_cats[transformed_cat_id] - -def get_transformed_cat(coco_cat_id): - """ transformed_cat_id is [0,80) as indices in cfg.dataset.class_names """ - return coco_cats_inv[coco_cat_id] - -class Detections: - - def __init__(self): - self.bbox_data = [] - self.mask_data = [] - - def add_bbox(self, image_id:int, category_id:int, bbox:list, score:float): - """ Note that bbox should be a list or tuple of (x1, y1, x2, y2) """ - bbox = [bbox[0], bbox[1], bbox[2]-bbox[0], bbox[3]-bbox[1]] - - # Round to the nearest 10th to avoid huge file sizes, as COCO suggests - bbox = [round(float(x)*10)/10 for x in bbox] - - self.bbox_data.append({ - 'image_id': int(image_id), - 'category_id': get_coco_cat(int(category_id)), - 'bbox': bbox, - 'score': float(score) - }) - - def add_mask(self, image_id:int, category_id:int, segmentation:np.ndarray, score:float): - """ The segmentation should be the full mask, the size of the image and with size [h, w]. """ - rle = pycocotools.mask.encode(np.asfortranarray(segmentation.astype(np.uint8))) - rle['counts'] = rle['counts'].decode('ascii') # json.dump doesn't like bytes strings - - self.mask_data.append({ - 'image_id': int(image_id), - 'category_id': get_coco_cat(int(category_id)), - 'segmentation': rle, - 'score': float(score) - }) - -def _mask_iou(mask1, mask2, iscrowd=False): - with timer.env('Mask IoU'): - ret = mask_iou(mask1, mask2, iscrowd) - return ret.cpu() - -def _bbox_iou(bbox1, bbox2, iscrowd=False): - with timer.env('BBox IoU'): - ret = jaccard(bbox1, bbox2, iscrowd) - return ret.cpu() - -def prep_metrics(ap_data, dets, img, gt, gt_masks, h, w, num_crowd, image_id, detections:Detections=None): - """ Returns a list of APs for this image, with each element being for a class """ - if not args.output_coco_json: - with timer.env('Prepare gt'): - gt_boxes = torch.Tensor(gt[:, :4]) - gt_boxes[:, [0, 2]] *= w - gt_boxes[:, [1, 3]] *= h - gt_classes = list(gt[:, 4].astype(int)) - gt_masks = torch.Tensor(gt_masks).view(-1, h*w) - - if num_crowd > 0: - split = lambda x: (x[-num_crowd:], x[:-num_crowd]) - crowd_boxes , gt_boxes = split(gt_boxes) - crowd_masks , gt_masks = split(gt_masks) - crowd_classes, gt_classes = split(gt_classes) - - with timer.env('Postprocess'): - classes, scores, boxes, masks = postprocess(dets, w, h, crop_masks=args.crop, score_threshold=args.score_threshold) - - if classes.size(0) == 0: - return - - classes = list(classes.cpu().numpy().astype(int)) - if isinstance(scores, list): - box_scores = list(scores[0].cpu().numpy().astype(float)) - mask_scores = list(scores[1].cpu().numpy().astype(float)) - else: - scores = list(scores.cpu().numpy().astype(float)) - box_scores = scores - mask_scores = scores - masks = masks.view(-1, h*w) - - - if args.output_coco_json: - with timer.env('JSON Output'): - boxes = boxes.cpu().numpy() - masks = masks.view(-1, h, w).cpu().numpy() - for i in range(masks.shape[0]): - # Make sure that the bounding box actually makes sense and a mask was produced - if (boxes[i, 3] - boxes[i, 1]) * (boxes[i, 2] - boxes[i, 0]) > 0: - detections.add_bbox(image_id, classes[i], boxes[i,:], box_scores[i]) - detections.add_mask(image_id, classes[i], masks[i,:,:], mask_scores[i]) - return - - with timer.env('Eval Setup'): - num_pred = len(classes) - num_gt = len(gt_classes) - - mask_iou_cache = _mask_iou(masks, gt_masks) - bbox_iou_cache = _bbox_iou(boxes.float(), gt_boxes.float()) - - if num_crowd > 0: - crowd_mask_iou_cache = _mask_iou(masks, crowd_masks, iscrowd=True) - crowd_bbox_iou_cache = _bbox_iou(boxes.float(), crowd_boxes.float(), iscrowd=True) - else: - crowd_mask_iou_cache = None - crowd_bbox_iou_cache = None - - box_indices = sorted(range(num_pred), key=lambda i: -box_scores[i]) - mask_indices = sorted(box_indices, key=lambda i: -mask_scores[i]) - - iou_types = [ - ('box', lambda i,j: bbox_iou_cache[i, j].item(), - lambda i,j: crowd_bbox_iou_cache[i,j].item(), - lambda i: box_scores[i], box_indices), - ('mask', lambda i,j: mask_iou_cache[i, j].item(), - lambda i,j: crowd_mask_iou_cache[i,j].item(), - lambda i: mask_scores[i], mask_indices) - ] - - timer.start('Main loop') - for _class in set(classes + gt_classes): - ap_per_iou = [] - num_gt_for_class = sum([1 for x in gt_classes if x == _class]) - - for iouIdx in range(len(iou_thresholds)): - iou_threshold = iou_thresholds[iouIdx] - - for iou_type, iou_func, crowd_func, score_func, indices in iou_types: - gt_used = [False] * len(gt_classes) - - ap_obj = ap_data[iou_type][iouIdx][_class] - ap_obj.add_gt_positives(num_gt_for_class) - - for i in indices: - if classes[i] != _class: - continue - - max_iou_found = iou_threshold - max_match_idx = -1 - for j in range(num_gt): - if gt_used[j] or gt_classes[j] != _class: - continue - - iou = iou_func(i, j) - - if iou > max_iou_found: - max_iou_found = iou - max_match_idx = j - - if max_match_idx >= 0: - gt_used[max_match_idx] = True - ap_obj.push(score_func(i), True) - else: - # If the detection matches a crowd, we can just ignore it - matched_crowd = False - - if num_crowd > 0: - for j in range(len(crowd_classes)): - if crowd_classes[j] != _class: - continue - - iou = crowd_func(i, j) - - if iou > iou_threshold: - matched_crowd = True - break - - # All this crowd code so that we can make sure that our eval code gives the - # same result as COCOEval. There aren't even that many crowd annotations to - # begin with, but accuracy is of the utmost importance. - if not matched_crowd: - ap_obj.push(score_func(i), False) - timer.stop('Main loop') - -class APDataObject: - """ - Stores all the information necessary to calculate the AP for one IoU and one class. - Note: I type annotated this because why not. - """ - - def __init__(self): - self.data_points = [] - self.num_gt_positives = 0 - - def push(self, score:float, is_true:bool): - self.data_points.append((score, is_true)) - - def add_gt_positives(self, num_positives:int): - """ Call this once per image. """ - self.num_gt_positives += num_positives - - def is_empty(self) -> bool: - return len(self.data_points) == 0 and self.num_gt_positives == 0 - - def get_ap(self) -> float: - """ Warning: result not cached. """ - - if self.num_gt_positives == 0: - return 0 - - # Sort descending by score - self.data_points.sort(key=lambda x: -x[0]) - - precisions = [] - recalls = [] - num_true = 0 - num_false = 0 - - # Compute the precision-recall curve. The x axis is recalls and the y axis precisions. - for datum in self.data_points: - # datum[1] is whether the detection a true or false positive - if datum[1]: num_true += 1 - else: num_false += 1 - - precision = num_true / (num_true + num_false) - recall = num_true / self.num_gt_positives - - precisions.append(precision) - recalls.append(recall) - - # Smooth the curve by computing [max(precisions[i:]) for i in range(len(precisions))] - # Basically, remove any temporary dips from the curve. - # At least that's what I think, idk. COCOEval did it so I do too. - for i in range(len(precisions)-1, 0, -1): - if precisions[i] > precisions[i-1]: - precisions[i-1] = precisions[i] - - # Compute the integral of precision(recall) d_recall from recall=0->1 using fixed-length riemann summation with 101 bars. - y_range = [0] * 101 # idx 0 is recall == 0.0 and idx 100 is recall == 1.00 - x_range = np.array([x / 100 for x in range(101)]) - recalls = np.array(recalls) - - # I realize this is weird, but all it does is find the nearest precision(x) for a given x in x_range. - # Basically, if the closest recall we have to 0.01 is 0.009 this sets precision(0.01) = precision(0.009). - # I approximate the integral this way, because that's how COCOEval does it. - indices = np.searchsorted(recalls, x_range, side='left') - for bar_idx, precision_idx in enumerate(indices): - if precision_idx < len(precisions): - y_range[bar_idx] = precisions[precision_idx] - - # Finally compute the riemann sum to get our integral. - # avg([precision(x) for x in 0:0.01:1]) - return sum(y_range) / len(y_range) - -def badhash(x): - """ - Just a quick and dirty hash function for doing a deterministic shuffle based on image_id. - - Source: - https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key - """ - x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF - x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF - x = ((x >> 16) ^ x) & 0xFFFFFFFF - return x - -class InferResultFile(): - def __init__(self, path, fileName): - parts = fileName.split('_') - self.imgId = int(parts[2]) - self.outputId = int(parts[3][0]) - self.arrayValue = np.fromfile(path + fileName, dtype=np.float32) - - self.arrayDim = self.arrayValue.shape[0] - #print('finish read file :', fileName) - -def getAllFiles(path): - allFiles = os.listdir(path) - infoFiles = {} - for file in allFiles: - if '.bin' in file and 'coco_val' in file: - infoFile = InferResultFile(path, file) - if infoFile.imgId in infoFiles.keys(): - infoFiles[infoFile.imgId].append(infoFile) - else: - infoFiles[infoFile.imgId] = [infoFile] - return infoFiles - -class InferResultFileFetcher(): - def __init__(self, path): - self.path = path - - def getInferResult(self, image_idx): - resultDict = {} - for i in range(1, 5): - fileName = 'coco_val2017_' + str(image_idx) + '_' + str(i) + '.bin' - infoFile = InferResultFile(self.path, fileName) - if infoFile.arrayDim == 615936: - resultDict[0] = infoFile - elif infoFile.arrayDim == 1559088: - resultDict[1] = infoFile - elif infoFile.arrayDim == 76992: - resultDict[2] = infoFile - else: - resultDict[3] = infoFile - - return resultDict - -pred_priors = None - -def getPriorTensor(): - global pred_priors - if pred_priors is None: - from yolact import PredictionModule - cfg._tmp_img_h = 550 - cfg._tmp_img_w = 550 - pred_priors = PredictionModule.get_YOLACT_priors().numpy() - return pred_priors - else: - return pred_priors - -def evaluate(path, dataset): - cfg.mask_proto_debug = args.mask_proto_debug - inferResultFetcher = InferResultFileFetcher(path) - - frame_times = MovingAverage() - dataset_size = len(dataset) if args.max_images < 0 else min(args.max_images, len(dataset)) - progress_bar = ProgressBar(30, dataset_size) - - print() - - # For each class and iou, stores tuples (score, isPositive) - # Index ap_data[type][iouIdx][classIdx] - ap_data = { - 'box' : [[APDataObject() for _ in cfg.dataset.class_names] for _ in iou_thresholds], - 'mask': [[APDataObject() for _ in cfg.dataset.class_names] for _ in iou_thresholds] - } - detections = Detections() - - dataset_indices = list(range(len(dataset))) - - if args.shuffle: - random.shuffle(dataset_indices) - elif not args.no_sort: - # Do a deterministic shuffle based on the image ids - # - # I do this because on python 3.5 dictionary key order is *random*, while in 3.6 it's - # the order of insertion. That means on python 3.6, the images come in the order they are in - # in the annotations file. For some reason, the first images in the annotations file are - # the hardest. To combat this, I use a hard-coded hash function based on the image ids - # to shuffle the indices we use. That way, no matter what python version or how pycocotools - # handles the data, we get the same result every time. - hashed = [badhash(x) for x in dataset.ids] - dataset_indices.sort(key=lambda x: hashed[x]) - - dataset_indices = dataset_indices[:dataset_size] - - # Main eval loop - for it, image_idx in enumerate(dataset_indices): - timer.reset() - with timer.env('Load Data'): - img, gt, gt_masks, h, w, num_crowd = dataset.pull_item(image_idx) - # Test flag, do not upvote - with timer.env('Network Extra'): - imgId_Outputs = inferResultFetcher.getInferResult(image_idx) - - pred_mask = imgId_Outputs[0].arrayValue.reshape(1, 19248, 32) #output1 : pred_onnx[2] - pred_conf = imgId_Outputs[1].arrayValue.reshape(1, 19248, 81) #output2 : pred_onnx[1] - pred_loc = imgId_Outputs[2].arrayValue.reshape(1, 19248, 4) #output3 : pred_onnx[0] - pred_proto = imgId_Outputs[3].arrayValue.reshape(1, 138, 138, 32) #output4 : pred_onnx[4] - - detect = Detect(cfg.num_classes, bkg_label=0, top_k=200, conf_thresh=0.05, nms_thresh=0.5) - detect.use_fast_nms = args.fast_nms - preds = detect({'loc': torch.from_numpy(pred_loc), - 'conf': torch.from_numpy(pred_conf), - 'mask': torch.from_numpy(pred_mask), - 'priors': torch.from_numpy(getPriorTensor()), #????? - 'proto': torch.from_numpy(pred_proto)}) - - # Perform the meat of the operation here depending on our mode. - - prep_metrics(ap_data, preds, img, gt, gt_masks, h, w, num_crowd, dataset.ids[image_idx], detections) - # First couple of images take longer because we're constructing the graph. - # Since that's technically initialization, don't include those in the FPS calculations. - if it > 1: - frame_times.add(timer.total_time()) - if not args.no_bar: - if it > 1: fps = 1 / frame_times.get_avg() - else: fps = 0 - progress = (it+1) / dataset_size * 100 - progress_bar.set_val(it+1) - print('\rProcessing Output Results %s %6d / %6d (%5.2f%%) %5.2f fps ' - % (repr(progress_bar), it+1, dataset_size, progress, fps), end='') - - print() - print('Saving data...') - with open(args.ap_data_file, 'wb') as f: - pickle.dump(ap_data, f) - return calc_map(ap_data) - -def calc_map(ap_data): - print('Calculating mAP...') - aps = [{'box': [], 'mask': []} for _ in iou_thresholds] - - for _class in range(len(cfg.dataset.class_names)): - for iou_idx in range(len(iou_thresholds)): - for iou_type in ('box', 'mask'): - ap_obj = ap_data[iou_type][iou_idx][_class] - - if not ap_obj.is_empty(): - aps[iou_idx][iou_type].append(ap_obj.get_ap()) - - all_maps = {'box': OrderedDict(), 'mask': OrderedDict()} - - # Looking back at it, this code is really hard to read :/ - for iou_type in ('box', 'mask'): - all_maps[iou_type]['all'] = 0 # Make this first in the ordereddict - for i, threshold in enumerate(iou_thresholds): - mAP = sum(aps[i][iou_type]) / len(aps[i][iou_type]) * 100 if len(aps[i][iou_type]) > 0 else 0 - all_maps[iou_type][int(threshold*100)] = mAP - all_maps[iou_type]['all'] = (sum(all_maps[iou_type].values()) / (len(all_maps[iou_type].values())-1)) - - print_maps(all_maps) - - # Put in a prettier format so we can serialize it to json during training - all_maps = {k: {j: round(u, 2) for j, u in v.items()} for k, v in all_maps.items()} - return all_maps - -def print_maps(all_maps): - # Warning: hacky - make_row = lambda vals: (' %5s |' * len(vals)) % tuple(vals) - make_sep = lambda n: ('-------+' * n) - - print() - print(make_row([''] + [('.%d ' % x if isinstance(x, int) else x + ' ') for x in all_maps['box'].keys()])) - print(make_sep(len(all_maps['box']) + 1)) - for iou_type in ('box', 'mask'): - print(make_row([iou_type] + ['%.2f' % x if x < 100 else '%.1f' % x for x in all_maps[iou_type].values()])) - print(make_sep(len(all_maps['box']) + 1)) - print() - -if __name__ == '__main__': - path = './result/dumpOutput_device0/' - parse_args() - - if args.config is not None: - set_cfg(args.config) - - else: - args.config = 'yolact_base_config' - print('Config not specified. Parsed %s from the file name.\n' % args.config) - set_cfg(args.config) - - #if args.image is None and args.video is None and args.images is None: - dataset = COCODetection(args.valid_images, args.valid_annotations, - transform=BaseTransform(), has_gt=cfg.dataset.has_gt) - prep_coco_cats() - - evaluate(path, dataset) +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +from layers import Detect +from data import COCODetection, get_label_map +from utils.augmentations import BaseTransform +from utils.functions import MovingAverage, ProgressBar +from layers.box_utils import jaccard, mask_iou +from utils import timer +from layers.output_utils import postprocess +import pycocotools +from data import cfg, set_cfg +import numpy as np +import torch +import argparse +import random +import pickle +import os +from collections import defaultdict +from collections import OrderedDict + +def str2bool(v): + if v.lower() in ('yes', 'true', 't', 'y', '1'): + return True + elif v.lower() in ('no', 'false', 'f', 'n', '0'): + return False + else: + raise argparse.ArgumentTypeError('Boolean value expected.') + +def parse_args(argv=None): + parser = argparse.ArgumentParser( + description='YOLACT COCO Evaluation') + parser.add_argument('--valid_images', default='/home/data/coco/images/', help='the path of validation images') + parser.add_argument('--valid_annotations', default='/home/data/coco/annotations/instances_val2017.json', help='the path of validation annotations') + parser.add_argument('--top_k', default=5, type=int, + help='Further restrict the number of predictions to parse') + parser.add_argument('--cuda', default=True, type=str2bool, + help='Use cuda to evaulate model') + parser.add_argument('--fast_nms', default=True, type=str2bool, + help='Whether to use a faster, but not entirely correct version of NMS.') + parser.add_argument('--shuffle', dest='shuffle', action='store_true', + help='Shuffles the images when displaying them. Doesn\'t have much of an effect when display is off though.') + parser.add_argument('--ap_data_file', default='results/ap_data.pkl', type=str, + help='In quantitative mode, the file to save detections before calculating mAP.') + parser.add_argument('--max_images', default=-1, type=int, + help='The maximum number of images from the dataset to consider. Use -1 for all.') + parser.add_argument('--output_coco_json', dest='output_coco_json', action='store_true', + help='If display is not set, instead of processing IoU values, this just dumps detections into the coco json file.') + parser.add_argument('--config', default=None, + help='The config object to use.') + parser.add_argument('--no_bar', dest='no_bar', action='store_true', + help='Do not output the status bar. This is useful for when piping to a file.') + parser.add_argument('--no_sort', default=False, dest='no_sort', action='store_true', + help='Do not sort images by hashed image ID.') + parser.add_argument('--seed', default=None, type=int, + help='The seed to pass into random.seed. Note: this is only really for the shuffle and does not (I think) affect cuda stuff.') + parser.add_argument('--mask_proto_debug', default=False, dest='mask_proto_debug', action='store_true', + help='Outputs stuff for scripts/compute_mask.py.') + parser.add_argument('--score_threshold', default=0, type=float, + help='Detections with a score under this threshold will not be considered. This currently only works in display mode.') + parser.add_argument('--dataset', default=None, type=str, + help='If specified, override the dataset specified in the config with this one (example: coco2017_dataset).') + parser.add_argument('--detect', default=False, dest='detect', action='store_true', + help='Don\'t evauluate the mask branch at all and only do object detection. This only works for --display and --benchmark.') + + parser.set_defaults(no_bar=False, output_coco_json=False, shuffle=False, + no_sort=False, mask_proto_debug=False, detect=False, crop=True) + + global args + args = parser.parse_args(argv) + + if args.seed is not None: + random.seed(args.seed) + +iou_thresholds = [x / 100 for x in range(50, 100, 5)] +coco_cats = {} # Call prep_coco_cats to fill this +coco_cats_inv = {} +color_cache = defaultdict(lambda: {}) + +def prep_coco_cats(): + """ Prepare inverted table for category id lookup given a coco cats object. """ + for coco_cat_id, transformed_cat_id_p1 in get_label_map().items(): + transformed_cat_id = transformed_cat_id_p1 - 1 + coco_cats[transformed_cat_id] = coco_cat_id + coco_cats_inv[coco_cat_id] = transformed_cat_id + +def get_coco_cat(transformed_cat_id): + """ transformed_cat_id is [0,80) as indices in cfg.dataset.class_names """ + return coco_cats[transformed_cat_id] + +def get_transformed_cat(coco_cat_id): + """ transformed_cat_id is [0,80) as indices in cfg.dataset.class_names """ + return coco_cats_inv[coco_cat_id] + +class Detections: + + def __init__(self): + self.bbox_data = [] + self.mask_data = [] + + def add_bbox(self, image_id:int, category_id:int, bbox:list, score:float): + """ Note that bbox should be a list or tuple of (x1, y1, x2, y2) """ + bbox = [bbox[0], bbox[1], bbox[2]-bbox[0], bbox[3]-bbox[1]] + + # Round to the nearest 10th to avoid huge file sizes, as COCO suggests + bbox = [round(float(x)*10)/10 for x in bbox] + + self.bbox_data.append({ + 'image_id': int(image_id), + 'category_id': get_coco_cat(int(category_id)), + 'bbox': bbox, + 'score': float(score) + }) + + def add_mask(self, image_id:int, category_id:int, segmentation:np.ndarray, score:float): + """ The segmentation should be the full mask, the size of the image and with size [h, w]. """ + rle = pycocotools.mask.encode(np.asfortranarray(segmentation.astype(np.uint8))) + rle['counts'] = rle['counts'].decode('ascii') # json.dump doesn't like bytes strings + + self.mask_data.append({ + 'image_id': int(image_id), + 'category_id': get_coco_cat(int(category_id)), + 'segmentation': rle, + 'score': float(score) + }) + +def _mask_iou(mask1, mask2, iscrowd=False): + with timer.env('Mask IoU'): + ret = mask_iou(mask1, mask2, iscrowd) + return ret.cpu() + +def _bbox_iou(bbox1, bbox2, iscrowd=False): + with timer.env('BBox IoU'): + ret = jaccard(bbox1, bbox2, iscrowd) + return ret.cpu() + +def prep_metrics(ap_data, dets, img, gt, gt_masks, h, w, num_crowd, image_id, detections:Detections=None): + """ Returns a list of APs for this image, with each element being for a class """ + if not args.output_coco_json: + with timer.env('Prepare gt'): + gt_boxes = torch.Tensor(gt[:, :4]) + gt_boxes[:, [0, 2]] *= w + gt_boxes[:, [1, 3]] *= h + gt_classes = list(gt[:, 4].astype(int)) + gt_masks = torch.Tensor(gt_masks).view(-1, h*w) + + if num_crowd > 0: + split = lambda x: (x[-num_crowd:], x[:-num_crowd]) + crowd_boxes , gt_boxes = split(gt_boxes) + crowd_masks , gt_masks = split(gt_masks) + crowd_classes, gt_classes = split(gt_classes) + + with timer.env('Postprocess'): + classes, scores, boxes, masks = postprocess(dets, w, h, crop_masks=args.crop, score_threshold=args.score_threshold) + + if classes.size(0) == 0: + return + + classes = list(classes.cpu().numpy().astype(int)) + if isinstance(scores, list): + box_scores = list(scores[0].cpu().numpy().astype(float)) + mask_scores = list(scores[1].cpu().numpy().astype(float)) + else: + scores = list(scores.cpu().numpy().astype(float)) + box_scores = scores + mask_scores = scores + masks = masks.view(-1, h*w) + + + if args.output_coco_json: + with timer.env('JSON Output'): + boxes = boxes.cpu().numpy() + masks = masks.view(-1, h, w).cpu().numpy() + for i in range(masks.shape[0]): + # Make sure that the bounding box actually makes sense and a mask was produced + if (boxes[i, 3] - boxes[i, 1]) * (boxes[i, 2] - boxes[i, 0]) > 0: + detections.add_bbox(image_id, classes[i], boxes[i,:], box_scores[i]) + detections.add_mask(image_id, classes[i], masks[i,:,:], mask_scores[i]) + return + + with timer.env('Eval Setup'): + num_pred = len(classes) + num_gt = len(gt_classes) + + mask_iou_cache = _mask_iou(masks, gt_masks) + bbox_iou_cache = _bbox_iou(boxes.float(), gt_boxes.float()) + + if num_crowd > 0: + crowd_mask_iou_cache = _mask_iou(masks, crowd_masks, iscrowd=True) + crowd_bbox_iou_cache = _bbox_iou(boxes.float(), crowd_boxes.float(), iscrowd=True) + else: + crowd_mask_iou_cache = None + crowd_bbox_iou_cache = None + + box_indices = sorted(range(num_pred), key=lambda i: -box_scores[i]) + mask_indices = sorted(box_indices, key=lambda i: -mask_scores[i]) + + iou_types = [ + ('box', lambda i,j: bbox_iou_cache[i, j].item(), + lambda i,j: crowd_bbox_iou_cache[i,j].item(), + lambda i: box_scores[i], box_indices), + ('mask', lambda i,j: mask_iou_cache[i, j].item(), + lambda i,j: crowd_mask_iou_cache[i,j].item(), + lambda i: mask_scores[i], mask_indices) + ] + + timer.start('Main loop') + for _class in set(classes + gt_classes): + ap_per_iou = [] + num_gt_for_class = sum([1 for x in gt_classes if x == _class]) + + for iouIdx in range(len(iou_thresholds)): + iou_threshold = iou_thresholds[iouIdx] + + for iou_type, iou_func, crowd_func, score_func, indices in iou_types: + gt_used = [False] * len(gt_classes) + + ap_obj = ap_data[iou_type][iouIdx][_class] + ap_obj.add_gt_positives(num_gt_for_class) + + for i in indices: + if classes[i] != _class: + continue + + max_iou_found = iou_threshold + max_match_idx = -1 + for j in range(num_gt): + if gt_used[j] or gt_classes[j] != _class: + continue + + iou = iou_func(i, j) + + if iou > max_iou_found: + max_iou_found = iou + max_match_idx = j + + if max_match_idx >= 0: + gt_used[max_match_idx] = True + ap_obj.push(score_func(i), True) + else: + # If the detection matches a crowd, we can just ignore it + matched_crowd = False + + if num_crowd > 0: + for j in range(len(crowd_classes)): + if crowd_classes[j] != _class: + continue + + iou = crowd_func(i, j) + + if iou > iou_threshold: + matched_crowd = True + break + + # All this crowd code so that we can make sure that our eval code gives the + # same result as COCOEval. There aren't even that many crowd annotations to + # begin with, but accuracy is of the utmost importance. + if not matched_crowd: + ap_obj.push(score_func(i), False) + timer.stop('Main loop') + +class APDataObject: + """ + Stores all the information necessary to calculate the AP for one IoU and one class. + Note: I type annotated this because why not. + """ + + def __init__(self): + self.data_points = [] + self.num_gt_positives = 0 + + def push(self, score:float, is_true:bool): + self.data_points.append((score, is_true)) + + def add_gt_positives(self, num_positives:int): + """ Call this once per image. """ + self.num_gt_positives += num_positives + + def is_empty(self) -> bool: + return len(self.data_points) == 0 and self.num_gt_positives == 0 + + def get_ap(self) -> float: + """ Warning: result not cached. """ + + if self.num_gt_positives == 0: + return 0 + + # Sort descending by score + self.data_points.sort(key=lambda x: -x[0]) + + precisions = [] + recalls = [] + num_true = 0 + num_false = 0 + + # Compute the precision-recall curve. The x axis is recalls and the y axis precisions. + for datum in self.data_points: + # datum[1] is whether the detection a true or false positive + if datum[1]: num_true += 1 + else: num_false += 1 + + precision = num_true / (num_true + num_false) + recall = num_true / self.num_gt_positives + + precisions.append(precision) + recalls.append(recall) + + # Smooth the curve by computing [max(precisions[i:]) for i in range(len(precisions))] + # Basically, remove any temporary dips from the curve. + # At least that's what I think, idk. COCOEval did it so I do too. + for i in range(len(precisions)-1, 0, -1): + if precisions[i] > precisions[i-1]: + precisions[i-1] = precisions[i] + + # Compute the integral of precision(recall) d_recall from recall=0->1 using fixed-length riemann summation with 101 bars. + y_range = [0] * 101 # idx 0 is recall == 0.0 and idx 100 is recall == 1.00 + x_range = np.array([x / 100 for x in range(101)]) + recalls = np.array(recalls) + + # I realize this is weird, but all it does is find the nearest precision(x) for a given x in x_range. + # Basically, if the closest recall we have to 0.01 is 0.009 this sets precision(0.01) = precision(0.009). + # I approximate the integral this way, because that's how COCOEval does it. + indices = np.searchsorted(recalls, x_range, side='left') + for bar_idx, precision_idx in enumerate(indices): + if precision_idx < len(precisions): + y_range[bar_idx] = precisions[precision_idx] + + # Finally compute the riemann sum to get our integral. + # avg([precision(x) for x in 0:0.01:1]) + return sum(y_range) / len(y_range) + +def badhash(x): + """ + Just a quick and dirty hash function for doing a deterministic shuffle based on image_id. + + Source: + https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key + """ + x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF + x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF + x = ((x >> 16) ^ x) & 0xFFFFFFFF + return x + +class InferResultFile(): + def __init__(self, path, fileName): + parts = fileName.split('_') + self.imgId = int(parts[2]) + self.outputId = int(parts[3][0]) + self.arrayValue = np.fromfile(path + fileName, dtype=np.float32) + + self.arrayDim = self.arrayValue.shape[0] + #print('finish read file :', fileName) + +def getAllFiles(path): + allFiles = os.listdir(path) + infoFiles = {} + for file in allFiles: + if '.bin' in file and 'coco_val' in file: + infoFile = InferResultFile(path, file) + if infoFile.imgId in infoFiles.keys(): + infoFiles[infoFile.imgId].append(infoFile) + else: + infoFiles[infoFile.imgId] = [infoFile] + return infoFiles + +class InferResultFileFetcher(): + def __init__(self, path): + self.path = path + + def getInferResult(self, image_idx): + resultDict = {} + for i in range(1, 5): + fileName = 'coco_val2017_' + str(image_idx) + '_' + str(i) + '.bin' + infoFile = InferResultFile(self.path, fileName) + if infoFile.arrayDim == 615936: + resultDict[0] = infoFile + elif infoFile.arrayDim == 1559088: + resultDict[1] = infoFile + elif infoFile.arrayDim == 76992: + resultDict[2] = infoFile + else: + resultDict[3] = infoFile + + return resultDict + +pred_priors = None + +def getPriorTensor(): + global pred_priors + if pred_priors is None: + from yolact import PredictionModule + cfg._tmp_img_h = 550 + cfg._tmp_img_w = 550 + pred_priors = PredictionModule.get_YOLACT_priors().numpy() + return pred_priors + else: + return pred_priors + +def evaluate(path, dataset): + cfg.mask_proto_debug = args.mask_proto_debug + inferResultFetcher = InferResultFileFetcher(path) + + frame_times = MovingAverage() + dataset_size = len(dataset) if args.max_images < 0 else min(args.max_images, len(dataset)) + progress_bar = ProgressBar(30, dataset_size) + + print() + + # For each class and iou, stores tuples (score, isPositive) + # Index ap_data[type][iouIdx][classIdx] + ap_data = { + 'box' : [[APDataObject() for _ in cfg.dataset.class_names] for _ in iou_thresholds], + 'mask': [[APDataObject() for _ in cfg.dataset.class_names] for _ in iou_thresholds] + } + detections = Detections() + + dataset_indices = list(range(len(dataset))) + + if args.shuffle: + random.shuffle(dataset_indices) + elif not args.no_sort: + # Do a deterministic shuffle based on the image ids + # + # I do this because on python 3.5 dictionary key order is *random*, while in 3.6 it's + # the order of insertion. That means on python 3.6, the images come in the order they are in + # in the annotations file. For some reason, the first images in the annotations file are + # the hardest. To combat this, I use a hard-coded hash function based on the image ids + # to shuffle the indices we use. That way, no matter what python version or how pycocotools + # handles the data, we get the same result every time. + hashed = [badhash(x) for x in dataset.ids] + dataset_indices.sort(key=lambda x: hashed[x]) + + dataset_indices = dataset_indices[:dataset_size] + + # Main eval loop + for it, image_idx in enumerate(dataset_indices): + timer.reset() + with timer.env('Load Data'): + img, gt, gt_masks, h, w, num_crowd = dataset.pull_item(image_idx) + # Test flag, do not upvote + with timer.env('Network Extra'): + imgId_Outputs = inferResultFetcher.getInferResult(image_idx) + + pred_mask = imgId_Outputs[0].arrayValue.reshape(1, 19248, 32) #output1 : pred_onnx[2] + pred_conf = imgId_Outputs[1].arrayValue.reshape(1, 19248, 81) #output2 : pred_onnx[1] + pred_loc = imgId_Outputs[2].arrayValue.reshape(1, 19248, 4) #output3 : pred_onnx[0] + pred_proto = imgId_Outputs[3].arrayValue.reshape(1, 138, 138, 32) #output4 : pred_onnx[4] + + detect = Detect(cfg.num_classes, bkg_label=0, top_k=200, conf_thresh=0.05, nms_thresh=0.5) + detect.use_fast_nms = args.fast_nms + preds = detect({'loc': torch.from_numpy(pred_loc), + 'conf': torch.from_numpy(pred_conf), + 'mask': torch.from_numpy(pred_mask), + 'priors': torch.from_numpy(getPriorTensor()), #????? + 'proto': torch.from_numpy(pred_proto)}) + + # Perform the meat of the operation here depending on our mode. + + prep_metrics(ap_data, preds, img, gt, gt_masks, h, w, num_crowd, dataset.ids[image_idx], detections) + # First couple of images take longer because we're constructing the graph. + # Since that's technically initialization, don't include those in the FPS calculations. + if it > 1: + frame_times.add(timer.total_time()) + if not args.no_bar: + if it > 1: fps = 1 / frame_times.get_avg() + else: fps = 0 + progress = (it+1) / dataset_size * 100 + progress_bar.set_val(it+1) + print('\rProcessing Output Results %s %6d / %6d (%5.2f%%) %5.2f fps ' + % (repr(progress_bar), it+1, dataset_size, progress, fps), end='') + + print() + print('Saving data...') + with open(args.ap_data_file, 'wb') as f: + pickle.dump(ap_data, f) + return calc_map(ap_data) + +def calc_map(ap_data): + print('Calculating mAP...') + aps = [{'box': [], 'mask': []} for _ in iou_thresholds] + + for _class in range(len(cfg.dataset.class_names)): + for iou_idx in range(len(iou_thresholds)): + for iou_type in ('box', 'mask'): + ap_obj = ap_data[iou_type][iou_idx][_class] + + if not ap_obj.is_empty(): + aps[iou_idx][iou_type].append(ap_obj.get_ap()) + + all_maps = {'box': OrderedDict(), 'mask': OrderedDict()} + + # Looking back at it, this code is really hard to read :/ + for iou_type in ('box', 'mask'): + all_maps[iou_type]['all'] = 0 # Make this first in the ordereddict + for i, threshold in enumerate(iou_thresholds): + mAP = sum(aps[i][iou_type]) / len(aps[i][iou_type]) * 100 if len(aps[i][iou_type]) > 0 else 0 + all_maps[iou_type][int(threshold*100)] = mAP + all_maps[iou_type]['all'] = (sum(all_maps[iou_type].values()) / (len(all_maps[iou_type].values())-1)) + + print_maps(all_maps) + + # Put in a prettier format so we can serialize it to json during training + all_maps = {k: {j: round(u, 2) for j, u in v.items()} for k, v in all_maps.items()} + return all_maps + +def print_maps(all_maps): + # Warning: hacky + make_row = lambda vals: (' %5s |' * len(vals)) % tuple(vals) + make_sep = lambda n: ('-------+' * n) + + print() + print(make_row([''] + [('.%d ' % x if isinstance(x, int) else x + ' ') for x in all_maps['box'].keys()])) + print(make_sep(len(all_maps['box']) + 1)) + for iou_type in ('box', 'mask'): + print(make_row([iou_type] + ['%.2f' % x if x < 100 else '%.1f' % x for x in all_maps[iou_type].values()])) + print(make_sep(len(all_maps['box']) + 1)) + print() + +if __name__ == '__main__': + path = './result/dumpOutput_device0/' + parse_args() + + if args.config is not None: + set_cfg(args.config) + + else: + args.config = 'yolact_base_config' + print('Config not specified. Parsed %s from the file name.\n' % args.config) + set_cfg(args.config) + + #if args.image is None and args.video is None and args.images is None: + dataset = COCODetection(args.valid_images, args.valid_annotations, + transform=BaseTransform(), has_gt=cfg.dataset.has_gt) + prep_coco_cats() + + evaluate(path, dataset) diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT/YOLACT_preprocess.py b/ACL_PyTorch/contrib/cv/segmentation/YOLACT/YOLACT_preprocess.py index 1ae885bb886f43c9686edee4c279d53963f92d7e..3d0d49a69170821f2b8cc4982dfd133f23df976b 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/YOLACT/YOLACT_preprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/YOLACT/YOLACT_preprocess.py @@ -1,174 +1,174 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -from data import COCODetection, get_label_map -from utils.augmentations import BaseTransform -from data import cfg, set_cfg -import numpy as np -from torch.autograd import Variable -import argparse -import random -import os -from collections import defaultdict - -def str2bool(v): - if v.lower() in ('yes', 'true', 't', 'y', '1'): - return True - elif v.lower() in ('no', 'false', 'f', 'n', '0'): - return False - else: - raise argparse.ArgumentTypeError('Boolean value expected.') - -def parse_args(argv=None): - parser = argparse.ArgumentParser( - description='YOLACT COCO Evaluation') - parser.add_argument('--valid_images', default='/home/data/coco/images/', help='the path of validation images') - parser.add_argument('--valid_annotations', default='/home/data/coco/annotations/instances_val2017.json', help='the path of validation annotations') - parser.add_argument('--saved_path', default='./', help='the path of binary data and info file') - parser.add_argument('--cuda', default=True, type=str2bool, - help='Use cuda to evaulate model') - parser.add_argument('--display', dest='display', action='store_true', - help='Display qualitative results instead of quantitative ones.') - parser.add_argument('--shuffle', dest='shuffle', action='store_true', - help='Shuffles the images when displaying them. Doesn\'t have much of an effect when display is off though.') - parser.add_argument('--resume', dest='resume', action='store_true', - help='If display not set, this resumes mAP calculations from the ap_data_file.') - parser.add_argument('--max_images', default=-1, type=int, - help='The maximum number of images from the dataset to consider. Use -1 for all.') - parser.add_argument('--config', default=None, - help='The config object to use.') - parser.add_argument('--no_sort', default=False, dest='no_sort', action='store_true', - help='Do not sort images by hashed image ID.') - parser.add_argument('--seed', default=None, type=int, - help='The seed to pass into random.seed. Note: this is only really for the shuffle and does not (I think) affect cuda stuff.') - parser.add_argument('--image', default=None, type=str, - help='A path to an image to use for display.') - parser.add_argument('--images', default=None, type=str, - help='An input folder of images and output folder to save detected images. Should be in the format input->output.') - parser.add_argument('--dataset', default=None, type=str, - help='If specified, override the dataset specified in the config with this one (example: coco2017_dataset).') - parser.set_defaults(display=False, resume=False, shuffle=False, - no_sort=False) - - global args - args = parser.parse_args(argv) - - if args.seed is not None: - random.seed(args.seed) - -iou_thresholds = [x / 100 for x in range(50, 100, 5)] -coco_cats = {} # Call prep_coco_cats to fill this -coco_cats_inv = {} -color_cache = defaultdict(lambda: {}) - -def prep_coco_cats(): - """ Prepare inverted table for category id lookup given a coco cats object. """ - for coco_cat_id, transformed_cat_id_p1 in get_label_map().items(): - transformed_cat_id = transformed_cat_id_p1 - 1 - coco_cats[transformed_cat_id] = coco_cat_id - coco_cats_inv[coco_cat_id] = transformed_cat_id - -def badhash(x): - """ - Just a quick and dirty hash function for doing a deterministic shuffle based on image_id. - - Source: - https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key - """ - x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF - x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF - x = ((x >> 16) ^ x) & 0xFFFFFFFF - return x - -def preprocess(dataset, save_path = None): - dataset_size = len(dataset) if args.max_images < 0 else min(args.max_images, len(dataset)) - print("dataset size is : ", dataset_size) - print() - - # For each class and iou, stores tuples (score, isPositive) - # Index ap_data[type][iouIdx][classIdx] - dataset_indices = list(range(len(dataset))) - print("dataset indices size is :", len(dataset_indices)) - if args.shuffle: - random.shuffle(dataset_indices) - elif not args.no_sort: - hashed = [badhash(x) for x in dataset.ids] - dataset_indices.sort(key=lambda x: hashed[x]) - - dataset_indices = dataset_indices[:dataset_size] - - if save_path is None: - save_path = os.path.join(args.saved_path, 'prep_dataset') - - if os.path.exists(save_path) == False: - os.mkdir(save_path) - else: - print('dir exist!') - - # Main eval loop - with open(os.path.join(args.saved_path, 'yolact_prep_bin.info'), 'w+') as f: - for it, image_idx in enumerate(dataset_indices): - img, gt, gt_masks, h, w, num_crowd = dataset.pull_item(image_idx) - # Test flag, do not upvote - batch = Variable(img.unsqueeze(0)) - batch_numpy = np.array(batch).astype(np.float32) - - binFileName = os.path.join(save_path, 'coco_val2017_' + str(image_idx) + '.bin') - - batch_numpy.tofile(binFileName) - - line = str(it) + ' ' + binFileName + ' ' + '550 550\n' - f.write(line) - if it % 100 == 0: - print('[INFO][PreProcess]', 'CurSampleNum:', it) - -if __name__ == '__main__': - parse_args() - - if args.config is not None: - set_cfg(args.config) - - else: - args.config = 'yolact_base_config' - print('Config not specified. Parsed %s from the file name.\n' % args.config) - set_cfg(args.config) - - if not os.path.exists('results'): - os.makedirs('results') - - #if args.image is None and args.video is None and args.images is None: - dataset = COCODetection(args.valid_images, args.valid_annotations, - transform=BaseTransform(), has_gt=cfg.dataset.has_gt) - prep_coco_cats() - - preprocess(dataset) - - +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +from data import COCODetection, get_label_map +from utils.augmentations import BaseTransform +from data import cfg, set_cfg +import numpy as np +from torch.autograd import Variable +import argparse +import random +import os +from collections import defaultdict + +def str2bool(v): + if v.lower() in ('yes', 'true', 't', 'y', '1'): + return True + elif v.lower() in ('no', 'false', 'f', 'n', '0'): + return False + else: + raise argparse.ArgumentTypeError('Boolean value expected.') + +def parse_args(argv=None): + parser = argparse.ArgumentParser( + description='YOLACT COCO Evaluation') + parser.add_argument('--valid_images', default='/home/data/coco/images/', help='the path of validation images') + parser.add_argument('--valid_annotations', default='/home/data/coco/annotations/instances_val2017.json', help='the path of validation annotations') + parser.add_argument('--saved_path', default='./', help='the path of binary data and info file') + parser.add_argument('--cuda', default=True, type=str2bool, + help='Use cuda to evaulate model') + parser.add_argument('--display', dest='display', action='store_true', + help='Display qualitative results instead of quantitative ones.') + parser.add_argument('--shuffle', dest='shuffle', action='store_true', + help='Shuffles the images when displaying them. Doesn\'t have much of an effect when display is off though.') + parser.add_argument('--resume', dest='resume', action='store_true', + help='If display not set, this resumes mAP calculations from the ap_data_file.') + parser.add_argument('--max_images', default=-1, type=int, + help='The maximum number of images from the dataset to consider. Use -1 for all.') + parser.add_argument('--config', default=None, + help='The config object to use.') + parser.add_argument('--no_sort', default=False, dest='no_sort', action='store_true', + help='Do not sort images by hashed image ID.') + parser.add_argument('--seed', default=None, type=int, + help='The seed to pass into random.seed. Note: this is only really for the shuffle and does not (I think) affect cuda stuff.') + parser.add_argument('--image', default=None, type=str, + help='A path to an image to use for display.') + parser.add_argument('--images', default=None, type=str, + help='An input folder of images and output folder to save detected images. Should be in the format input->output.') + parser.add_argument('--dataset', default=None, type=str, + help='If specified, override the dataset specified in the config with this one (example: coco2017_dataset).') + parser.set_defaults(display=False, resume=False, shuffle=False, + no_sort=False) + + global args + args = parser.parse_args(argv) + + if args.seed is not None: + random.seed(args.seed) + +iou_thresholds = [x / 100 for x in range(50, 100, 5)] +coco_cats = {} # Call prep_coco_cats to fill this +coco_cats_inv = {} +color_cache = defaultdict(lambda: {}) + +def prep_coco_cats(): + """ Prepare inverted table for category id lookup given a coco cats object. """ + for coco_cat_id, transformed_cat_id_p1 in get_label_map().items(): + transformed_cat_id = transformed_cat_id_p1 - 1 + coco_cats[transformed_cat_id] = coco_cat_id + coco_cats_inv[coco_cat_id] = transformed_cat_id + +def badhash(x): + """ + Just a quick and dirty hash function for doing a deterministic shuffle based on image_id. + + Source: + https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key + """ + x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF + x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF + x = ((x >> 16) ^ x) & 0xFFFFFFFF + return x + +def preprocess(dataset, save_path = None): + dataset_size = len(dataset) if args.max_images < 0 else min(args.max_images, len(dataset)) + print("dataset size is : ", dataset_size) + print() + + # For each class and iou, stores tuples (score, isPositive) + # Index ap_data[type][iouIdx][classIdx] + dataset_indices = list(range(len(dataset))) + print("dataset indices size is :", len(dataset_indices)) + if args.shuffle: + random.shuffle(dataset_indices) + elif not args.no_sort: + hashed = [badhash(x) for x in dataset.ids] + dataset_indices.sort(key=lambda x: hashed[x]) + + dataset_indices = dataset_indices[:dataset_size] + + if save_path is None: + save_path = os.path.join(args.saved_path, 'prep_dataset') + + if os.path.exists(save_path) == False: + os.mkdir(save_path) + else: + print('dir exist!') + + # Main eval loop + with open(os.path.join(args.saved_path, 'yolact_prep_bin.info'), 'w+') as f: + for it, image_idx in enumerate(dataset_indices): + img, gt, gt_masks, h, w, num_crowd = dataset.pull_item(image_idx) + # Test flag, do not upvote + batch = Variable(img.unsqueeze(0)) + batch_numpy = np.array(batch).astype(np.float32) + + binFileName = os.path.join(save_path, 'coco_val2017_' + str(image_idx) + '.bin') + + batch_numpy.tofile(binFileName) + + line = str(it) + ' ' + binFileName + ' ' + '550 550\n' + f.write(line) + if it % 100 == 0: + print('[INFO][PreProcess]', 'CurSampleNum:', it) + +if __name__ == '__main__': + parse_args() + + if args.config is not None: + set_cfg(args.config) + + else: + args.config = 'yolact_base_config' + print('Config not specified. Parsed %s from the file name.\n' % args.config) + set_cfg(args.config) + + if not os.path.exists('results'): + os.makedirs('results') + + #if args.image is None and args.video is None and args.images is None: + dataset = COCODetection(args.valid_images, args.valid_annotations, + transform=BaseTransform(), has_gt=cfg.dataset.has_gt) + prep_coco_cats() + + preprocess(dataset) + + diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT/test/eval_acc_perf.sh b/ACL_PyTorch/contrib/cv/segmentation/YOLACT/test/eval_acc_perf.sh old mode 100755 new mode 100644 diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT/test/parse.py b/ACL_PyTorch/contrib/cv/segmentation/YOLACT/test/parse.py index a0f253b055047b199b33d4b65cdc79177b6b250b..27eae0d0acf98687edd95f1f024cf77c49cd4dc4 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/YOLACT/test/parse.py +++ b/ACL_PyTorch/contrib/cv/segmentation/YOLACT/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT/test/perf_g.sh b/ACL_PyTorch/contrib/cv/segmentation/YOLACT/test/perf_g.sh old mode 100755 new mode 100644 diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT/test/pth2om.sh b/ACL_PyTorch/contrib/cv/segmentation/YOLACT/test/pth2om.sh old mode 100755 new mode 100644 diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/LICENSE b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/LICENSE +++ b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/README.md b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/README.md index ade13dfe135415893c04aa3774d8e5ff6330db45..4b9e18211ff8c03a584c6ec9919ba9b61eebe3c8 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/README.md +++ b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/README.md @@ -1,159 +1,159 @@ -# YOLACT模型PyTorch离线推理说明 - -### 一、环境准备 - -#### 1、获取依赖库 - -```shell -pip3 install -r requirements.txt -git clone -b pytorch_1.5 https://github.com/ifzhang/DCNv2.git -cd DCNv2 -python3.7 setup.py build develop -patch -p1 < ../dcnv2.diff -``` - -#### 2、获取YOLACT源代码并更新 - -- 首先获取官方代码仓代码 - - ```bash - git clone https://github.com/dbolya/yolact.git - ``` - -- 将无关文件删除,保留以下文件 - - ``` - . - ├── backbone.py - ├── data - │   ├── coco.py - │   ├── config.py - │   └── __init__.py - ├── layers - │   ├── box_utils.py - │   ├── functions - │   │   ├── detection.py - │   │   └── __init__.py - │   ├── __init__.py - │   ├── interpolate.py - │   └── output_utils.py - ├── utils - │   ├── augmentations.py - │   ├── cython_nms.pyx - │   ├── functions.py - │   ├── __init__.py - │   └── timer.py - └── yolact.py - ``` - -- 将本仓库代码拷贝至yolact目录下,并使用补丁YOLACT.patch复原 - - ``` - patch -p1 < ./YOLACT.patch - ``` - - - 复原后,文件目录如下 - - ``` - . - ├── backbone.py - ├── data - │   ├── coco.py - │   ├── config.py - │   └── __init__.py - ├── env.sh - ├── dcnv2.diff - ├── DCNv2 - ├── layers - │   ├── box_utils.py - │   ├── functions - │   │   ├── detection.py - │   │   └── __init__.py - │   ├── __init__.py - │   ├── interpolate.py - │   └── output_utils.py - ├── LICENSE - ├── modelzoo_level.txt - ├── README.md - ├── requirements.txt - ├── test - │   ├── eval_acc_perf.sh - │   ├── parse.py - │   ├── prior.bin - │   └── pth2om.sh - ├── utils - │   ├── augmentations.py - │   ├── cython_nms.pyx - │   ├── functions.py - │   ├── __init__.py - │   └── timer.py - ├── weights - │   └── pth2onnx.py - ├── YOLACT.patch - ├── YOLACT_postprocess.py - ├── YOLACT_preprocess.py - └── yolact.py - ``` - -#### 3、获取权重文件 - -官方训练完毕的权重文件:yolact_plus_resnet50_54_800000.pth - -训练完毕的权重文件放于./weights目录下 - -#### 4、获取数据集 - -YOLACT模型使用Microsoft COCO 2017数据集进行训练及测试,下载数据集命令如下: - -```bash -cd data/scripts -bash ./COCO.sh #获取测试数据集 -``` - -在离线推理中仅使用测试数据集,测试图像为val 2017, 对应的标注文件为instances_val2017.json - -#### 5、获取benchmark工具 - -获取benchmark.x86_64离线推理工具 - - - -### 二、离线推理 - -#### 1、执行离线推理前使用以下命令查看设备状态,确保device空闲 - -```bash -npu-smi info -``` - -#### 2、执行以下命令,生成om模型文件 - -```bash -bash test/pth2om.sh -``` - -注意:此处pth权重文件的路径应设为相对路径 - -#### 3、执行以下命令,开始离线推理 - -```bash -bash test/eval_acc_perf.sh -``` - -同时,benchmark工具会自动统计性能数据。 - -#### 4、在基准环境中执行以下命令,获取基准推理性能 - -onnx包含自定义算子,不能使用开源TensorRT测试性能数据,所以在基准服务器上在线推理测试性能数据。 - - - -### 三、评测结果 - -Yolact++不支持在bs16上离线推理,故在bs8上测试。 - -| 模型 | 在线推理精度 | 310离线推理精度 | 基准性能 | 310性能 | -| ----------- | ----------------------- | ----------------------- | ---------- | --------- | -| YOLACT bs1 | mAP: box 34.94, mask 33.69 | mAP: box 34.90, mask 33.71 | 19.693fps | 26.452fps | -| YOLACT bs8 | mAP: box 34.94, mask 33.69 | mAP: box 34.90, mask 33.71 | 16.377fps | 31.130fps | +# YOLACT模型PyTorch离线推理说明 + +### 一、环境准备 + +#### 1、获取依赖库 + +```shell +pip3 install -r requirements.txt +git clone -b pytorch_1.5 https://github.com/ifzhang/DCNv2.git +cd DCNv2 +python3.7 setup.py build develop +patch -p1 < ../dcnv2.diff +``` + +#### 2、获取YOLACT源代码并更新 + +- 首先获取官方代码仓代码 + + ```bash + git clone https://github.com/dbolya/yolact.git + ``` + +- 将无关文件删除,保留以下文件 + + ``` + . + ├── backbone.py + ├── data + │   ├── coco.py + │   ├── config.py + │   └── __init__.py + ├── layers + │   ├── box_utils.py + │   ├── functions + │   │   ├── detection.py + │   │   └── __init__.py + │   ├── __init__.py + │   ├── interpolate.py + │   └── output_utils.py + ├── utils + │   ├── augmentations.py + │   ├── cython_nms.pyx + │   ├── functions.py + │   ├── __init__.py + │   └── timer.py + └── yolact.py + ``` + +- 将本仓库代码拷贝至yolact目录下,并使用补丁YOLACT.patch复原 + + ``` + patch -p1 < ./YOLACT.patch + ``` + + + 复原后,文件目录如下 + + ``` + . + ├── backbone.py + ├── data + │   ├── coco.py + │   ├── config.py + │   └── __init__.py + ├── env.sh + ├── dcnv2.diff + ├── DCNv2 + ├── layers + │   ├── box_utils.py + │   ├── functions + │   │   ├── detection.py + │   │   └── __init__.py + │   ├── __init__.py + │   ├── interpolate.py + │   └── output_utils.py + ├── LICENSE + ├── modelzoo_level.txt + ├── README.md + ├── requirements.txt + ├── test + │   ├── eval_acc_perf.sh + │   ├── parse.py + │   ├── prior.bin + │   └── pth2om.sh + ├── utils + │   ├── augmentations.py + │   ├── cython_nms.pyx + │   ├── functions.py + │   ├── __init__.py + │   └── timer.py + ├── weights + │   └── pth2onnx.py + ├── YOLACT.patch + ├── YOLACT_postprocess.py + ├── YOLACT_preprocess.py + └── yolact.py + ``` + +#### 3、获取权重文件 + +官方训练完毕的权重文件:yolact_plus_resnet50_54_800000.pth + +训练完毕的权重文件放于./weights目录下 + +#### 4、获取数据集 + +YOLACT模型使用Microsoft COCO 2017数据集进行训练及测试,下载数据集命令如下: + +```bash +cd data/scripts +bash ./COCO.sh #获取测试数据集 +``` + +在离线推理中仅使用测试数据集,测试图像为val 2017, 对应的标注文件为instances_val2017.json + +#### 5、获取benchmark工具 + +获取benchmark.x86_64离线推理工具 + + + +### 二、离线推理 + +#### 1、执行离线推理前使用以下命令查看设备状态,确保device空闲 + +```bash +npu-smi info +``` + +#### 2、执行以下命令,生成om模型文件 + +```bash +bash test/pth2om.sh +``` + +注意:此处pth权重文件的路径应设为相对路径 + +#### 3、执行以下命令,开始离线推理 + +```bash +bash test/eval_acc_perf.sh +``` + +同时,benchmark工具会自动统计性能数据。 + +#### 4、在基准环境中执行以下命令,获取基准推理性能 + +onnx包含自定义算子,不能使用开源TensorRT测试性能数据,所以在基准服务器上在线推理测试性能数据。 + + + +### 三、评测结果 + +Yolact++不支持在bs16上离线推理,故在bs8上测试。 + +| 模型 | 在线推理精度 | 310离线推理精度 | 基准性能 | 310性能 | +| ----------- | ----------------------- | ----------------------- | ---------- | --------- | +| YOLACT bs1 | mAP: box 34.94, mask 33.69 | mAP: box 34.90, mask 33.71 | 19.693fps | 26.452fps | +| YOLACT bs8 | mAP: box 34.94, mask 33.69 | mAP: box 34.90, mask 33.71 | 16.377fps | 31.130fps | diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/YOLACT_postprocess.py b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/YOLACT_postprocess.py index 58d3a90d974e053fbc6ea88ceaa3c20efcf91dc5..83de5b39dcd8fa6c2fc3ee9707c9a4ed049462a5 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/YOLACT_postprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/YOLACT_postprocess.py @@ -1,566 +1,566 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys - -from layers import Detect -from data import COCODetection, get_label_map, MEANS, COLORS -from yolact import Yolact -from utils.augmentations import BaseTransform, FastBaseTransform, Resize -from utils.functions import MovingAverage, ProgressBar -from layers.box_utils import jaccard, center_size, mask_iou -from utils import timer -from utils.functions import SavePath -from layers.output_utils import postprocess, undo_image_transformation -import pycocotools - -from data import cfg, set_cfg, set_dataset - -import numpy as np -import torch -import torch.backends.cudnn as cudnn -from torch.autograd import Variable -import argparse -import time -import random -import cProfile -import pickle -import json -import os -from collections import defaultdict -from pathlib import Path -from collections import OrderedDict -from PIL import Image - -import matplotlib.pyplot as plt -import cv2 - -def str2bool(v): - if v.lower() in ('yes', 'true', 't', 'y', '1'): - return True - elif v.lower() in ('no', 'false', 'f', 'n', '0'): - return False - else: - raise argparse.ArgumentTypeError('Boolean value expected.') - -def parse_args(argv=None): - parser = argparse.ArgumentParser( - description='YOLACT COCO Evaluation') - parser.add_argument('--valid_images', default='/home/data/coco/images/', help='the path of validation images') - parser.add_argument('--valid_annotations', default='/home/data/coco/annotations/instances_val2017.json', help='the path of validation annotations') - parser.add_argument('--top_k', default=5, type=int, - help='Further restrict the number of predictions to parse') - parser.add_argument('--cuda', default=True, type=str2bool, - help='Use cuda to evaulate model') - parser.add_argument('--fast_nms', default=True, type=str2bool, - help='Whether to use a faster, but not entirely correct version of NMS.') - parser.add_argument('--shuffle', dest='shuffle', action='store_true', - help='Shuffles the images when displaying them. Doesn\'t have much of an effect when display is off though.') - parser.add_argument('--ap_data_file', default='results/ap_data.pkl', type=str, - help='In quantitative mode, the file to save detections before calculating mAP.') - parser.add_argument('--max_images', default=-1, type=int, - help='The maximum number of images from the dataset to consider. Use -1 for all.') - parser.add_argument('--output_coco_json', dest='output_coco_json', action='store_true', - help='If display is not set, instead of processing IoU values, this just dumps detections into the coco json file.') - parser.add_argument('--config', default=None, - help='The config object to use.') - parser.add_argument('--no_bar', dest='no_bar', action='store_true', - help='Do not output the status bar. This is useful for when piping to a file.') - parser.add_argument('--no_sort', default=False, dest='no_sort', action='store_true', - help='Do not sort images by hashed image ID.') - parser.add_argument('--seed', default=None, type=int, - help='The seed to pass into random.seed. Note: this is only really for the shuffle and does not (I think) affect cuda stuff.') - parser.add_argument('--mask_proto_debug', default=False, dest='mask_proto_debug', action='store_true', - help='Outputs stuff for scripts/compute_mask.py.') - parser.add_argument('--score_threshold', default=0, type=float, - help='Detections with a score under this threshold will not be considered. This currently only works in display mode.') - parser.add_argument('--dataset', default=None, type=str, - help='If specified, override the dataset specified in the config with this one (example: coco2017_dataset).') - parser.add_argument('--detect', default=False, dest='detect', action='store_true', - help='Don\'t evauluate the mask branch at all and only do object detection. This only works for --display and --benchmark.') - parser.add_argument('--pthpath', type=str, - default='./weights/yolact_plus_resnet50_54_800000.pth', help='choose .pth module') - parser.add_argument('--device_id', type=int, - default=0, help='choose .pth module') - parser.set_defaults(no_bar=False, output_coco_json=False, shuffle=False, - no_sort=False, mask_proto_debug=False, detect=False, crop=True) - - global args - args = parser.parse_args(argv) - - if args.seed is not None: - random.seed(args.seed) - -iou_thresholds = [x / 100 for x in range(50, 100, 5)] -coco_cats = {} # Call prep_coco_cats to fill this -coco_cats_inv = {} -color_cache = defaultdict(lambda: {}) - -def prep_coco_cats(): - """ Prepare inverted table for category id lookup given a coco cats object. """ - for coco_cat_id, transformed_cat_id_p1 in get_label_map().items(): - transformed_cat_id = transformed_cat_id_p1 - 1 - coco_cats[transformed_cat_id] = coco_cat_id - coco_cats_inv[coco_cat_id] = transformed_cat_id - -def get_coco_cat(transformed_cat_id): - """ transformed_cat_id is [0,80) as indices in cfg.dataset.class_names """ - return coco_cats[transformed_cat_id] - -def get_transformed_cat(coco_cat_id): - """ transformed_cat_id is [0,80) as indices in cfg.dataset.class_names """ - return coco_cats_inv[coco_cat_id] - -class Detections: - - def __init__(self): - self.bbox_data = [] - self.mask_data = [] - - def add_bbox(self, image_id:int, category_id:int, bbox:list, score:float): - """ Note that bbox should be a list or tuple of (x1, y1, x2, y2) """ - bbox = [bbox[0], bbox[1], bbox[2]-bbox[0], bbox[3]-bbox[1]] - - # Round to the nearest 10th to avoid huge file sizes, as COCO suggests - bbox = [round(float(x)*10)/10 for x in bbox] - - self.bbox_data.append({ - 'image_id': int(image_id), - 'category_id': get_coco_cat(int(category_id)), - 'bbox': bbox, - 'score': float(score) - }) - - def add_mask(self, image_id:int, category_id:int, segmentation:np.ndarray, score:float): - """ The segmentation should be the full mask, the size of the image and with size [h, w]. """ - rle = pycocotools.mask.encode(np.asfortranarray(segmentation.astype(np.uint8))) - rle['counts'] = rle['counts'].decode('ascii') # json.dump doesn't like bytes strings - - self.mask_data.append({ - 'image_id': int(image_id), - 'category_id': get_coco_cat(int(category_id)), - 'segmentation': rle, - 'score': float(score) - }) - -def _mask_iou(mask1, mask2, iscrowd=False): - with timer.env('Mask IoU'): - ret = mask_iou(mask1, mask2, iscrowd) - return ret.cpu() - -def _bbox_iou(bbox1, bbox2, iscrowd=False): - with timer.env('BBox IoU'): - ret = jaccard(bbox1, bbox2, iscrowd) - return ret.cpu() - -def prep_metrics(ap_data, dets, img, gt, gt_masks, h, w, num_crowd, image_id, detections:Detections=None): - """ Returns a list of APs for this image, with each element being for a class """ - if not args.output_coco_json: - with timer.env('Prepare gt'): - gt_boxes = torch.Tensor(gt[:, :4]) - gt_boxes[:, [0, 2]] *= w - gt_boxes[:, [1, 3]] *= h - gt_classes = list(gt[:, 4].astype(int)) - gt_masks = torch.Tensor(gt_masks).view(-1, h*w) - - if num_crowd > 0: - split = lambda x: (x[-num_crowd:], x[:-num_crowd]) - crowd_boxes , gt_boxes = split(gt_boxes) - crowd_masks , gt_masks = split(gt_masks) - crowd_classes, gt_classes = split(gt_classes) - - with timer.env('Postprocess'): - classes, scores, boxes, masks = postprocess(dets, w, h, crop_masks=args.crop, score_threshold=args.score_threshold) - - if classes.size(0) == 0: - return - - classes = list(classes.cpu().numpy().astype(int)) - if isinstance(scores, list): - box_scores = list(scores[0].cpu().numpy().astype(float)) - mask_scores = list(scores[1].cpu().numpy().astype(float)) - else: - scores = list(scores.cpu().numpy().astype(float)) - box_scores = scores - mask_scores = scores - masks = masks.view(-1, h*w) - - - if args.output_coco_json: - with timer.env('JSON Output'): - boxes = boxes.cpu().numpy() - masks = masks.view(-1, h, w).cpu().numpy() - for i in range(masks.shape[0]): - # Make sure that the bounding box actually makes sense and a mask was produced - if (boxes[i, 3] - boxes[i, 1]) * (boxes[i, 2] - boxes[i, 0]) > 0: - detections.add_bbox(image_id, classes[i], boxes[i,:], box_scores[i]) - detections.add_mask(image_id, classes[i], masks[i,:,:], mask_scores[i]) - return - - with timer.env('Eval Setup'): - num_pred = len(classes) - num_gt = len(gt_classes) - - mask_iou_cache = _mask_iou(masks, gt_masks) - bbox_iou_cache = _bbox_iou(boxes.float(), gt_boxes.float()) - - if num_crowd > 0: - crowd_mask_iou_cache = _mask_iou(masks, crowd_masks, iscrowd=True) - crowd_bbox_iou_cache = _bbox_iou(boxes.float(), crowd_boxes.float(), iscrowd=True) - else: - crowd_mask_iou_cache = None - crowd_bbox_iou_cache = None - - box_indices = sorted(range(num_pred), key=lambda i: -box_scores[i]) - mask_indices = sorted(box_indices, key=lambda i: -mask_scores[i]) - iou_types = [ - ('box', lambda i,j: bbox_iou_cache[i, j].item(), - lambda i,j: crowd_bbox_iou_cache[i,j].item(), - lambda i: box_scores[i], box_indices), - ('mask', lambda i,j: mask_iou_cache[i, j].item(), - lambda i,j: crowd_mask_iou_cache[i,j].item(), - lambda i: mask_scores[i], mask_indices) - ] - - - timer.start('Main loop') - for _class in set(classes + gt_classes): - ap_per_iou = [] - num_gt_for_class = sum([1 for x in gt_classes if x == _class]) - - for iouIdx in range(len(iou_thresholds)): - iou_threshold = iou_thresholds[iouIdx] - - for iou_type, iou_func, crowd_func, score_func, indices in iou_types: - gt_used = [False] * len(gt_classes) - - ap_obj = ap_data[iou_type][iouIdx][_class] - ap_obj.add_gt_positives(num_gt_for_class) - - for i in indices: - if classes[i] != _class: - continue - - max_iou_found = iou_threshold - max_match_idx = -1 - for j in range(num_gt): - if gt_used[j] or gt_classes[j] != _class: - continue - - iou = iou_func(i, j) - - if iou > max_iou_found: - max_iou_found = iou - max_match_idx = j - - if max_match_idx >= 0: - gt_used[max_match_idx] = True - ap_obj.push(score_func(i), True) - else: - # If the detection matches a crowd, we can just ignore it - matched_crowd = False - - if num_crowd > 0: - for j in range(len(crowd_classes)): - if crowd_classes[j] != _class: - continue - - iou = crowd_func(i, j) - - if iou > iou_threshold: - matched_crowd = True - break - - # All this crowd code so that we can make sure that our eval code gives the - # same result as COCOEval. There aren't even that many crowd annotations to - # begin with, but accuracy is of the utmost importance. - if not matched_crowd: - ap_obj.push(score_func(i), False) - timer.stop('Main loop') - -class APDataObject: - """ - Stores all the information necessary to calculate the AP for one IoU and one class. - Note: I type annotated this because why not. - """ - - def __init__(self): - self.data_points = [] - self.num_gt_positives = 0 - - def push(self, score:float, is_true:bool): - self.data_points.append((score, is_true)) - - def add_gt_positives(self, num_positives:int): - """ Call this once per image. """ - self.num_gt_positives += num_positives - - def is_empty(self) -> bool: - return len(self.data_points) == 0 and self.num_gt_positives == 0 - - def get_ap(self) -> float: - """ Warning: result not cached. """ - - if self.num_gt_positives == 0: - return 0 - - # Sort descending by score - self.data_points.sort(key=lambda x: -x[0]) - - precisions = [] - recalls = [] - num_true = 0 - num_false = 0 - - # Compute the precision-recall curve. The x axis is recalls and the y axis precisions. - for datum in self.data_points: - # datum[1] is whether the detection a true or false positive - if datum[1]: num_true += 1 - else: num_false += 1 - - precision = num_true / (num_true + num_false) - recall = num_true / self.num_gt_positives - - precisions.append(precision) - recalls.append(recall) - - # Smooth the curve by computing [max(precisions[i:]) for i in range(len(precisions))] - # Basically, remove any temporary dips from the curve. - # At least that's what I think, idk. COCOEval did it so I do too. - for i in range(len(precisions)-1, 0, -1): - if precisions[i] > precisions[i-1]: - precisions[i-1] = precisions[i] - - # Compute the integral of precision(recall) d_recall from recall=0->1 using fixed-length riemann summation with 101 bars. - y_range = [0] * 101 # idx 0 is recall == 0.0 and idx 100 is recall == 1.00 - x_range = np.array([x / 100 for x in range(101)]) - recalls = np.array(recalls) - - # I realize this is weird, but all it does is find the nearest precision(x) for a given x in x_range. - # Basically, if the closest recall we have to 0.01 is 0.009 this sets precision(0.01) = precision(0.009). - # I approximate the integral this way, because that's how COCOEval does it. - indices = np.searchsorted(recalls, x_range, side='left') - for bar_idx, precision_idx in enumerate(indices): - if precision_idx < len(precisions): - y_range[bar_idx] = precisions[precision_idx] - - # Finally compute the riemann sum to get our integral. - # avg([precision(x) for x in 0:0.01:1]) - return sum(y_range) / len(y_range) - -def badhash(x): - """ - Just a quick and dirty hash function for doing a deterministic shuffle based on image_id. - - Source: - https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key - """ - x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF - x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF - x = ((x >> 16) ^ x) & 0xFFFFFFFF - return x - -class InferResultFile(): - def __init__(self, path, fileName): - parts = fileName.split('_') - self.imgId = int(parts[2]) - self.outputId = int(parts[3][0]) - self.arrayValue = np.fromfile(path + fileName, dtype=np.float32) - - self.arrayDim = self.arrayValue.shape[0] - #print('finish read file :', fileName) - -def getAllFiles(path): - allFiles = os.listdir(path) - infoFiles = {} - for file in allFiles: - if '.bin' in file and 'coco_val' in file: - infoFile = InferResultFile(path, file) - if infoFile.imgId in infoFiles.keys(): - infoFiles[infoFile.imgId].append(infoFile) - else: - infoFiles[infoFile.imgId] = [infoFile] - return infoFiles - -class InferResultFileFetcher(): - def __init__(self, path): - self.path = path - - def getInferResult(self, image_idx): - resultDict = {} - for i in range(1, 5): - fileName = 'coco_val2017_' + str(image_idx) + '_' + str(i) + '.bin' - infoFile = InferResultFile(self.path, fileName) - if infoFile.arrayDim == 1847808: - resultDict[0] = infoFile - elif infoFile.arrayDim == 4677264: - resultDict[1] = infoFile - elif infoFile.arrayDim == 230976: - resultDict[2] = infoFile - else: - resultDict[3] = infoFile - - return resultDict - -pred_priors = None - -def getPriorTensor(): - global pred_priors - if pred_priors is None: - pred_priors = np.fromfile('prior.bin', dtype=np.float32).reshape(57744, 4) - return pred_priors - else: - return pred_priors - -def evaluate(path, dataset): - cfg.mask_proto_debug = args.mask_proto_debug - inferResultFetcher = InferResultFileFetcher(path) - - frame_times = MovingAverage() - dataset_size = len(dataset) if args.max_images < 0 else min(args.max_images, len(dataset)) - progress_bar = ProgressBar(30, dataset_size) - - print() - - # For each class and iou, stores tuples (score, isPositive) - # Index ap_data[type][iouIdx][classIdx] - ap_data = { - 'box' : [[APDataObject() for _ in cfg.dataset.class_names] for _ in iou_thresholds], - 'mask': [[APDataObject() for _ in cfg.dataset.class_names] for _ in iou_thresholds] - } - detections = Detections() - - dataset_indices = list(range(len(dataset))) - - if args.shuffle: - random.shuffle(dataset_indices) - elif not args.no_sort: - # Do a deterministic shuffle based on the image ids - # - # I do this because on python 3.5 dictionary key order is *random*, while in 3.6 it's - # the order of insertion. That means on python 3.6, the images come in the order they are in - # in the annotations file. For some reason, the first images in the annotations file are - # the hardest. To combat this, I use a hard-coded hash function based on the image ids - # to shuffle the indices we use. That way, no matter what python version or how pycocotools - # handles the data, we get the same result every time. - hashed = [badhash(x) for x in dataset.ids] - dataset_indices.sort(key=lambda x: hashed[x]) - - dataset_indices = dataset_indices[:dataset_size] - - # Main eval loop - for it, image_idx in enumerate(dataset_indices): - timer.reset() - with timer.env('Load Data'): - img, gt, gt_masks, h, w, num_crowd = dataset.pull_item(image_idx) - # Test flag, do not upvote - with timer.env('Network Extra'): - imgId_Outputs = inferResultFetcher.getInferResult(image_idx) - pred_mask = imgId_Outputs[0].arrayValue.reshape(1, 57744, 32) #output1 : pred_onnx[2] - pred_conf = imgId_Outputs[1].arrayValue.reshape(1, 57744, 81) #output2 : pred_onnx[1] - pred_loc = imgId_Outputs[2].arrayValue.reshape(1, 57744, 4) #output3 : pred_onnx[0] - pred_proto = imgId_Outputs[3].arrayValue.reshape(1, 138, 138, 32) #output4 : pred_onnx[4] - - detect = Detect(cfg.num_classes, bkg_label=0, top_k=200, conf_thresh=0.05, nms_thresh=0.5) - detect.use_fast_nms = args.fast_nms - preds = detect({'loc': torch.from_numpy(pred_loc), - 'conf': torch.from_numpy(pred_conf), - 'mask': torch.from_numpy(pred_mask), - 'priors': torch.from_numpy(getPriorTensor()), #????? - 'proto': torch.from_numpy(pred_proto)}) - from yolact import Yolact - yolact_net = Yolact() - yolact_net.load_weights(args.pthpath, useCuda=False) - preds = {'net':yolact_net, 'detection':preds} - - # Perform the meat of the operation here depending on our mode. - - prep_metrics(ap_data, preds, img, gt, gt_masks, h, w, num_crowd, dataset.ids[image_idx], detections) - # First couple of images take longer because we're constructing the graph. - # Since that's technically initialization, don't include those in the FPS calculations. - if it > 1: - frame_times.add(timer.total_time()) - if not args.no_bar: - if it > 1: fps = 1 / frame_times.get_avg() - else: fps = 0 - progress = (it+1) / dataset_size * 100 - progress_bar.set_val(it+1) - print('\rProcessing Images %s %6d / %6d (%5.2f%%) %5.2f fps ' - % (repr(progress_bar), it+1, dataset_size, progress, fps), end='') - - print() - print('Saving data...') - with open(args.ap_data_file, 'wb') as f: - pickle.dump(ap_data, f) - return calc_map(ap_data) - -def calc_map(ap_data): - print('Calculating mAP...') - aps = [{'box': [], 'mask': []} for _ in iou_thresholds] - - for _class in range(len(cfg.dataset.class_names)): - for iou_idx in range(len(iou_thresholds)): - for iou_type in ('box', 'mask'): - ap_obj = ap_data[iou_type][iou_idx][_class] - - if not ap_obj.is_empty(): - aps[iou_idx][iou_type].append(ap_obj.get_ap()) - - all_maps = {'box': OrderedDict(), 'mask': OrderedDict()} - - # Looking back at it, this code is really hard to read :/ - for iou_type in ('box', 'mask'): - all_maps[iou_type]['all'] = 0 # Make this first in the ordereddict - for i, threshold in enumerate(iou_thresholds): - mAP = sum(aps[i][iou_type]) / len(aps[i][iou_type]) * 100 if len(aps[i][iou_type]) > 0 else 0 - all_maps[iou_type][int(threshold*100)] = mAP - all_maps[iou_type]['all'] = (sum(all_maps[iou_type].values()) / (len(all_maps[iou_type].values())-1)) - - print_maps(all_maps) - - # Put in a prettier format so we can serialize it to json during training - all_maps = {k: {j: round(u, 2) for j, u in v.items()} for k, v in all_maps.items()} - return all_maps - -def print_maps(all_maps): - # Warning: hacky - make_row = lambda vals: (' %5s |' * len(vals)) % tuple(vals) - make_sep = lambda n: ('-------+' * n) - - print() - print(make_row([''] + [('.%d ' % x if isinstance(x, int) else x + ' ') for x in all_maps['box'].keys()])) - print(make_sep(len(all_maps['box']) + 1)) - for iou_type in ('box', 'mask'): - print(make_row([iou_type] + ['%.2f' % x if x < 100 else '%.1f' % x for x in all_maps[iou_type].values()])) - print(make_sep(len(all_maps['box']) + 1)) - print() - -if __name__ == '__main__': - parse_args() - path = './result/dumpOutput_device{}/'.format(args.device_id) - - if args.config is not None: - set_cfg(args.config) - - else: - args.config = 'yolact_base_config' - print('Config not specified. Parsed %s from the file name.\n' % args.config) - set_cfg(args.config) - - #if args.image is None and args.video is None and args.images is None: - dataset = COCODetection(args.valid_images, args.valid_annotations, - transform=BaseTransform(), has_gt=cfg.dataset.has_gt) - prep_coco_cats() - - evaluate(path, dataset) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys + +from layers import Detect +from data import COCODetection, get_label_map, MEANS, COLORS +from yolact import Yolact +from utils.augmentations import BaseTransform, FastBaseTransform, Resize +from utils.functions import MovingAverage, ProgressBar +from layers.box_utils import jaccard, center_size, mask_iou +from utils import timer +from utils.functions import SavePath +from layers.output_utils import postprocess, undo_image_transformation +import pycocotools + +from data import cfg, set_cfg, set_dataset + +import numpy as np +import torch +import torch.backends.cudnn as cudnn +from torch.autograd import Variable +import argparse +import time +import random +import cProfile +import pickle +import json +import os +from collections import defaultdict +from pathlib import Path +from collections import OrderedDict +from PIL import Image + +import matplotlib.pyplot as plt +import cv2 + +def str2bool(v): + if v.lower() in ('yes', 'true', 't', 'y', '1'): + return True + elif v.lower() in ('no', 'false', 'f', 'n', '0'): + return False + else: + raise argparse.ArgumentTypeError('Boolean value expected.') + +def parse_args(argv=None): + parser = argparse.ArgumentParser( + description='YOLACT COCO Evaluation') + parser.add_argument('--valid_images', default='/home/data/coco/images/', help='the path of validation images') + parser.add_argument('--valid_annotations', default='/home/data/coco/annotations/instances_val2017.json', help='the path of validation annotations') + parser.add_argument('--top_k', default=5, type=int, + help='Further restrict the number of predictions to parse') + parser.add_argument('--cuda', default=True, type=str2bool, + help='Use cuda to evaulate model') + parser.add_argument('--fast_nms', default=True, type=str2bool, + help='Whether to use a faster, but not entirely correct version of NMS.') + parser.add_argument('--shuffle', dest='shuffle', action='store_true', + help='Shuffles the images when displaying them. Doesn\'t have much of an effect when display is off though.') + parser.add_argument('--ap_data_file', default='results/ap_data.pkl', type=str, + help='In quantitative mode, the file to save detections before calculating mAP.') + parser.add_argument('--max_images', default=-1, type=int, + help='The maximum number of images from the dataset to consider. Use -1 for all.') + parser.add_argument('--output_coco_json', dest='output_coco_json', action='store_true', + help='If display is not set, instead of processing IoU values, this just dumps detections into the coco json file.') + parser.add_argument('--config', default=None, + help='The config object to use.') + parser.add_argument('--no_bar', dest='no_bar', action='store_true', + help='Do not output the status bar. This is useful for when piping to a file.') + parser.add_argument('--no_sort', default=False, dest='no_sort', action='store_true', + help='Do not sort images by hashed image ID.') + parser.add_argument('--seed', default=None, type=int, + help='The seed to pass into random.seed. Note: this is only really for the shuffle and does not (I think) affect cuda stuff.') + parser.add_argument('--mask_proto_debug', default=False, dest='mask_proto_debug', action='store_true', + help='Outputs stuff for scripts/compute_mask.py.') + parser.add_argument('--score_threshold', default=0, type=float, + help='Detections with a score under this threshold will not be considered. This currently only works in display mode.') + parser.add_argument('--dataset', default=None, type=str, + help='If specified, override the dataset specified in the config with this one (example: coco2017_dataset).') + parser.add_argument('--detect', default=False, dest='detect', action='store_true', + help='Don\'t evauluate the mask branch at all and only do object detection. This only works for --display and --benchmark.') + parser.add_argument('--pthpath', type=str, + default='./weights/yolact_plus_resnet50_54_800000.pth', help='choose .pth module') + parser.add_argument('--device_id', type=int, + default=0, help='choose .pth module') + parser.set_defaults(no_bar=False, output_coco_json=False, shuffle=False, + no_sort=False, mask_proto_debug=False, detect=False, crop=True) + + global args + args = parser.parse_args(argv) + + if args.seed is not None: + random.seed(args.seed) + +iou_thresholds = [x / 100 for x in range(50, 100, 5)] +coco_cats = {} # Call prep_coco_cats to fill this +coco_cats_inv = {} +color_cache = defaultdict(lambda: {}) + +def prep_coco_cats(): + """ Prepare inverted table for category id lookup given a coco cats object. """ + for coco_cat_id, transformed_cat_id_p1 in get_label_map().items(): + transformed_cat_id = transformed_cat_id_p1 - 1 + coco_cats[transformed_cat_id] = coco_cat_id + coco_cats_inv[coco_cat_id] = transformed_cat_id + +def get_coco_cat(transformed_cat_id): + """ transformed_cat_id is [0,80) as indices in cfg.dataset.class_names """ + return coco_cats[transformed_cat_id] + +def get_transformed_cat(coco_cat_id): + """ transformed_cat_id is [0,80) as indices in cfg.dataset.class_names """ + return coco_cats_inv[coco_cat_id] + +class Detections: + + def __init__(self): + self.bbox_data = [] + self.mask_data = [] + + def add_bbox(self, image_id:int, category_id:int, bbox:list, score:float): + """ Note that bbox should be a list or tuple of (x1, y1, x2, y2) """ + bbox = [bbox[0], bbox[1], bbox[2]-bbox[0], bbox[3]-bbox[1]] + + # Round to the nearest 10th to avoid huge file sizes, as COCO suggests + bbox = [round(float(x)*10)/10 for x in bbox] + + self.bbox_data.append({ + 'image_id': int(image_id), + 'category_id': get_coco_cat(int(category_id)), + 'bbox': bbox, + 'score': float(score) + }) + + def add_mask(self, image_id:int, category_id:int, segmentation:np.ndarray, score:float): + """ The segmentation should be the full mask, the size of the image and with size [h, w]. """ + rle = pycocotools.mask.encode(np.asfortranarray(segmentation.astype(np.uint8))) + rle['counts'] = rle['counts'].decode('ascii') # json.dump doesn't like bytes strings + + self.mask_data.append({ + 'image_id': int(image_id), + 'category_id': get_coco_cat(int(category_id)), + 'segmentation': rle, + 'score': float(score) + }) + +def _mask_iou(mask1, mask2, iscrowd=False): + with timer.env('Mask IoU'): + ret = mask_iou(mask1, mask2, iscrowd) + return ret.cpu() + +def _bbox_iou(bbox1, bbox2, iscrowd=False): + with timer.env('BBox IoU'): + ret = jaccard(bbox1, bbox2, iscrowd) + return ret.cpu() + +def prep_metrics(ap_data, dets, img, gt, gt_masks, h, w, num_crowd, image_id, detections:Detections=None): + """ Returns a list of APs for this image, with each element being for a class """ + if not args.output_coco_json: + with timer.env('Prepare gt'): + gt_boxes = torch.Tensor(gt[:, :4]) + gt_boxes[:, [0, 2]] *= w + gt_boxes[:, [1, 3]] *= h + gt_classes = list(gt[:, 4].astype(int)) + gt_masks = torch.Tensor(gt_masks).view(-1, h*w) + + if num_crowd > 0: + split = lambda x: (x[-num_crowd:], x[:-num_crowd]) + crowd_boxes , gt_boxes = split(gt_boxes) + crowd_masks , gt_masks = split(gt_masks) + crowd_classes, gt_classes = split(gt_classes) + + with timer.env('Postprocess'): + classes, scores, boxes, masks = postprocess(dets, w, h, crop_masks=args.crop, score_threshold=args.score_threshold) + + if classes.size(0) == 0: + return + + classes = list(classes.cpu().numpy().astype(int)) + if isinstance(scores, list): + box_scores = list(scores[0].cpu().numpy().astype(float)) + mask_scores = list(scores[1].cpu().numpy().astype(float)) + else: + scores = list(scores.cpu().numpy().astype(float)) + box_scores = scores + mask_scores = scores + masks = masks.view(-1, h*w) + + + if args.output_coco_json: + with timer.env('JSON Output'): + boxes = boxes.cpu().numpy() + masks = masks.view(-1, h, w).cpu().numpy() + for i in range(masks.shape[0]): + # Make sure that the bounding box actually makes sense and a mask was produced + if (boxes[i, 3] - boxes[i, 1]) * (boxes[i, 2] - boxes[i, 0]) > 0: + detections.add_bbox(image_id, classes[i], boxes[i,:], box_scores[i]) + detections.add_mask(image_id, classes[i], masks[i,:,:], mask_scores[i]) + return + + with timer.env('Eval Setup'): + num_pred = len(classes) + num_gt = len(gt_classes) + + mask_iou_cache = _mask_iou(masks, gt_masks) + bbox_iou_cache = _bbox_iou(boxes.float(), gt_boxes.float()) + + if num_crowd > 0: + crowd_mask_iou_cache = _mask_iou(masks, crowd_masks, iscrowd=True) + crowd_bbox_iou_cache = _bbox_iou(boxes.float(), crowd_boxes.float(), iscrowd=True) + else: + crowd_mask_iou_cache = None + crowd_bbox_iou_cache = None + + box_indices = sorted(range(num_pred), key=lambda i: -box_scores[i]) + mask_indices = sorted(box_indices, key=lambda i: -mask_scores[i]) + iou_types = [ + ('box', lambda i,j: bbox_iou_cache[i, j].item(), + lambda i,j: crowd_bbox_iou_cache[i,j].item(), + lambda i: box_scores[i], box_indices), + ('mask', lambda i,j: mask_iou_cache[i, j].item(), + lambda i,j: crowd_mask_iou_cache[i,j].item(), + lambda i: mask_scores[i], mask_indices) + ] + + + timer.start('Main loop') + for _class in set(classes + gt_classes): + ap_per_iou = [] + num_gt_for_class = sum([1 for x in gt_classes if x == _class]) + + for iouIdx in range(len(iou_thresholds)): + iou_threshold = iou_thresholds[iouIdx] + + for iou_type, iou_func, crowd_func, score_func, indices in iou_types: + gt_used = [False] * len(gt_classes) + + ap_obj = ap_data[iou_type][iouIdx][_class] + ap_obj.add_gt_positives(num_gt_for_class) + + for i in indices: + if classes[i] != _class: + continue + + max_iou_found = iou_threshold + max_match_idx = -1 + for j in range(num_gt): + if gt_used[j] or gt_classes[j] != _class: + continue + + iou = iou_func(i, j) + + if iou > max_iou_found: + max_iou_found = iou + max_match_idx = j + + if max_match_idx >= 0: + gt_used[max_match_idx] = True + ap_obj.push(score_func(i), True) + else: + # If the detection matches a crowd, we can just ignore it + matched_crowd = False + + if num_crowd > 0: + for j in range(len(crowd_classes)): + if crowd_classes[j] != _class: + continue + + iou = crowd_func(i, j) + + if iou > iou_threshold: + matched_crowd = True + break + + # All this crowd code so that we can make sure that our eval code gives the + # same result as COCOEval. There aren't even that many crowd annotations to + # begin with, but accuracy is of the utmost importance. + if not matched_crowd: + ap_obj.push(score_func(i), False) + timer.stop('Main loop') + +class APDataObject: + """ + Stores all the information necessary to calculate the AP for one IoU and one class. + Note: I type annotated this because why not. + """ + + def __init__(self): + self.data_points = [] + self.num_gt_positives = 0 + + def push(self, score:float, is_true:bool): + self.data_points.append((score, is_true)) + + def add_gt_positives(self, num_positives:int): + """ Call this once per image. """ + self.num_gt_positives += num_positives + + def is_empty(self) -> bool: + return len(self.data_points) == 0 and self.num_gt_positives == 0 + + def get_ap(self) -> float: + """ Warning: result not cached. """ + + if self.num_gt_positives == 0: + return 0 + + # Sort descending by score + self.data_points.sort(key=lambda x: -x[0]) + + precisions = [] + recalls = [] + num_true = 0 + num_false = 0 + + # Compute the precision-recall curve. The x axis is recalls and the y axis precisions. + for datum in self.data_points: + # datum[1] is whether the detection a true or false positive + if datum[1]: num_true += 1 + else: num_false += 1 + + precision = num_true / (num_true + num_false) + recall = num_true / self.num_gt_positives + + precisions.append(precision) + recalls.append(recall) + + # Smooth the curve by computing [max(precisions[i:]) for i in range(len(precisions))] + # Basically, remove any temporary dips from the curve. + # At least that's what I think, idk. COCOEval did it so I do too. + for i in range(len(precisions)-1, 0, -1): + if precisions[i] > precisions[i-1]: + precisions[i-1] = precisions[i] + + # Compute the integral of precision(recall) d_recall from recall=0->1 using fixed-length riemann summation with 101 bars. + y_range = [0] * 101 # idx 0 is recall == 0.0 and idx 100 is recall == 1.00 + x_range = np.array([x / 100 for x in range(101)]) + recalls = np.array(recalls) + + # I realize this is weird, but all it does is find the nearest precision(x) for a given x in x_range. + # Basically, if the closest recall we have to 0.01 is 0.009 this sets precision(0.01) = precision(0.009). + # I approximate the integral this way, because that's how COCOEval does it. + indices = np.searchsorted(recalls, x_range, side='left') + for bar_idx, precision_idx in enumerate(indices): + if precision_idx < len(precisions): + y_range[bar_idx] = precisions[precision_idx] + + # Finally compute the riemann sum to get our integral. + # avg([precision(x) for x in 0:0.01:1]) + return sum(y_range) / len(y_range) + +def badhash(x): + """ + Just a quick and dirty hash function for doing a deterministic shuffle based on image_id. + + Source: + https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key + """ + x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF + x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF + x = ((x >> 16) ^ x) & 0xFFFFFFFF + return x + +class InferResultFile(): + def __init__(self, path, fileName): + parts = fileName.split('_') + self.imgId = int(parts[2]) + self.outputId = int(parts[3][0]) + self.arrayValue = np.fromfile(path + fileName, dtype=np.float32) + + self.arrayDim = self.arrayValue.shape[0] + #print('finish read file :', fileName) + +def getAllFiles(path): + allFiles = os.listdir(path) + infoFiles = {} + for file in allFiles: + if '.bin' in file and 'coco_val' in file: + infoFile = InferResultFile(path, file) + if infoFile.imgId in infoFiles.keys(): + infoFiles[infoFile.imgId].append(infoFile) + else: + infoFiles[infoFile.imgId] = [infoFile] + return infoFiles + +class InferResultFileFetcher(): + def __init__(self, path): + self.path = path + + def getInferResult(self, image_idx): + resultDict = {} + for i in range(1, 5): + fileName = 'coco_val2017_' + str(image_idx) + '_' + str(i) + '.bin' + infoFile = InferResultFile(self.path, fileName) + if infoFile.arrayDim == 1847808: + resultDict[0] = infoFile + elif infoFile.arrayDim == 4677264: + resultDict[1] = infoFile + elif infoFile.arrayDim == 230976: + resultDict[2] = infoFile + else: + resultDict[3] = infoFile + + return resultDict + +pred_priors = None + +def getPriorTensor(): + global pred_priors + if pred_priors is None: + pred_priors = np.fromfile('prior.bin', dtype=np.float32).reshape(57744, 4) + return pred_priors + else: + return pred_priors + +def evaluate(path, dataset): + cfg.mask_proto_debug = args.mask_proto_debug + inferResultFetcher = InferResultFileFetcher(path) + + frame_times = MovingAverage() + dataset_size = len(dataset) if args.max_images < 0 else min(args.max_images, len(dataset)) + progress_bar = ProgressBar(30, dataset_size) + + print() + + # For each class and iou, stores tuples (score, isPositive) + # Index ap_data[type][iouIdx][classIdx] + ap_data = { + 'box' : [[APDataObject() for _ in cfg.dataset.class_names] for _ in iou_thresholds], + 'mask': [[APDataObject() for _ in cfg.dataset.class_names] for _ in iou_thresholds] + } + detections = Detections() + + dataset_indices = list(range(len(dataset))) + + if args.shuffle: + random.shuffle(dataset_indices) + elif not args.no_sort: + # Do a deterministic shuffle based on the image ids + # + # I do this because on python 3.5 dictionary key order is *random*, while in 3.6 it's + # the order of insertion. That means on python 3.6, the images come in the order they are in + # in the annotations file. For some reason, the first images in the annotations file are + # the hardest. To combat this, I use a hard-coded hash function based on the image ids + # to shuffle the indices we use. That way, no matter what python version or how pycocotools + # handles the data, we get the same result every time. + hashed = [badhash(x) for x in dataset.ids] + dataset_indices.sort(key=lambda x: hashed[x]) + + dataset_indices = dataset_indices[:dataset_size] + + # Main eval loop + for it, image_idx in enumerate(dataset_indices): + timer.reset() + with timer.env('Load Data'): + img, gt, gt_masks, h, w, num_crowd = dataset.pull_item(image_idx) + # Test flag, do not upvote + with timer.env('Network Extra'): + imgId_Outputs = inferResultFetcher.getInferResult(image_idx) + pred_mask = imgId_Outputs[0].arrayValue.reshape(1, 57744, 32) #output1 : pred_onnx[2] + pred_conf = imgId_Outputs[1].arrayValue.reshape(1, 57744, 81) #output2 : pred_onnx[1] + pred_loc = imgId_Outputs[2].arrayValue.reshape(1, 57744, 4) #output3 : pred_onnx[0] + pred_proto = imgId_Outputs[3].arrayValue.reshape(1, 138, 138, 32) #output4 : pred_onnx[4] + + detect = Detect(cfg.num_classes, bkg_label=0, top_k=200, conf_thresh=0.05, nms_thresh=0.5) + detect.use_fast_nms = args.fast_nms + preds = detect({'loc': torch.from_numpy(pred_loc), + 'conf': torch.from_numpy(pred_conf), + 'mask': torch.from_numpy(pred_mask), + 'priors': torch.from_numpy(getPriorTensor()), #????? + 'proto': torch.from_numpy(pred_proto)}) + from yolact import Yolact + yolact_net = Yolact() + yolact_net.load_weights(args.pthpath, useCuda=False) + preds = {'net':yolact_net, 'detection':preds} + + # Perform the meat of the operation here depending on our mode. + + prep_metrics(ap_data, preds, img, gt, gt_masks, h, w, num_crowd, dataset.ids[image_idx], detections) + # First couple of images take longer because we're constructing the graph. + # Since that's technically initialization, don't include those in the FPS calculations. + if it > 1: + frame_times.add(timer.total_time()) + if not args.no_bar: + if it > 1: fps = 1 / frame_times.get_avg() + else: fps = 0 + progress = (it+1) / dataset_size * 100 + progress_bar.set_val(it+1) + print('\rProcessing Images %s %6d / %6d (%5.2f%%) %5.2f fps ' + % (repr(progress_bar), it+1, dataset_size, progress, fps), end='') + + print() + print('Saving data...') + with open(args.ap_data_file, 'wb') as f: + pickle.dump(ap_data, f) + return calc_map(ap_data) + +def calc_map(ap_data): + print('Calculating mAP...') + aps = [{'box': [], 'mask': []} for _ in iou_thresholds] + + for _class in range(len(cfg.dataset.class_names)): + for iou_idx in range(len(iou_thresholds)): + for iou_type in ('box', 'mask'): + ap_obj = ap_data[iou_type][iou_idx][_class] + + if not ap_obj.is_empty(): + aps[iou_idx][iou_type].append(ap_obj.get_ap()) + + all_maps = {'box': OrderedDict(), 'mask': OrderedDict()} + + # Looking back at it, this code is really hard to read :/ + for iou_type in ('box', 'mask'): + all_maps[iou_type]['all'] = 0 # Make this first in the ordereddict + for i, threshold in enumerate(iou_thresholds): + mAP = sum(aps[i][iou_type]) / len(aps[i][iou_type]) * 100 if len(aps[i][iou_type]) > 0 else 0 + all_maps[iou_type][int(threshold*100)] = mAP + all_maps[iou_type]['all'] = (sum(all_maps[iou_type].values()) / (len(all_maps[iou_type].values())-1)) + + print_maps(all_maps) + + # Put in a prettier format so we can serialize it to json during training + all_maps = {k: {j: round(u, 2) for j, u in v.items()} for k, v in all_maps.items()} + return all_maps + +def print_maps(all_maps): + # Warning: hacky + make_row = lambda vals: (' %5s |' * len(vals)) % tuple(vals) + make_sep = lambda n: ('-------+' * n) + + print() + print(make_row([''] + [('.%d ' % x if isinstance(x, int) else x + ' ') for x in all_maps['box'].keys()])) + print(make_sep(len(all_maps['box']) + 1)) + for iou_type in ('box', 'mask'): + print(make_row([iou_type] + ['%.2f' % x if x < 100 else '%.1f' % x for x in all_maps[iou_type].values()])) + print(make_sep(len(all_maps['box']) + 1)) + print() + +if __name__ == '__main__': + parse_args() + path = './result/dumpOutput_device{}/'.format(args.device_id) + + if args.config is not None: + set_cfg(args.config) + + else: + args.config = 'yolact_base_config' + print('Config not specified. Parsed %s from the file name.\n' % args.config) + set_cfg(args.config) + + #if args.image is None and args.video is None and args.images is None: + dataset = COCODetection(args.valid_images, args.valid_annotations, + transform=BaseTransform(), has_gt=cfg.dataset.has_gt) + prep_coco_cats() + + evaluate(path, dataset) diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/YOLACT_preprocess.py b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/YOLACT_preprocess.py index 5b7eb4e094765c527246d60bb782ac18e6ffbc7f..4b4f69590b4e93ce3f80501b5c6454478f65090d 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/YOLACT_preprocess.py +++ b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/YOLACT_preprocess.py @@ -1,156 +1,156 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from data import COCODetection, get_label_map -from utils.augmentations import BaseTransform -from data import cfg, set_cfg -import numpy as np -from torch.autograd import Variable -import argparse -import random -import os -from collections import defaultdict - -def str2bool(v): - if v.lower() in ('yes', 'true', 't', 'y', '1'): - return True - elif v.lower() in ('no', 'false', 'f', 'n', '0'): - return False - else: - raise argparse.ArgumentTypeError('Boolean value expected.') - -def parse_args(argv=None): - parser = argparse.ArgumentParser( - description='YOLACT COCO Evaluation') - parser.add_argument('--valid_images', default='/home/data/coco/images/', help='the path of validation images') - parser.add_argument('--valid_annotations', default='/home/data/coco/annotations/instances_val2017.json', help='the path of validation annotations') - parser.add_argument('--cuda', default=True, type=str2bool, - help='Use cuda to evaulate model') - parser.add_argument('--display', dest='display', action='store_true', - help='Display qualitative results instead of quantitative ones.') - parser.add_argument('--shuffle', dest='shuffle', action='store_true', - help='Shuffles the images when displaying them. Doesn\'t have much of an effect when display is off though.') - parser.add_argument('--resume', dest='resume', action='store_true', - help='If display not set, this resumes mAP calculations from the ap_data_file.') - parser.add_argument('--max_images', default=-1, type=int, - help='The maximum number of images from the dataset to consider. Use -1 for all.') - parser.add_argument('--config', default=None, - help='The config object to use.') - parser.add_argument('--no_sort', default=False, dest='no_sort', action='store_true', - help='Do not sort images by hashed image ID.') - parser.add_argument('--seed', default=None, type=int, - help='The seed to pass into random.seed. Note: this is only really for the shuffle and does not (I think) affect cuda stuff.') - parser.add_argument('--image', default=None, type=str, - help='A path to an image to use for display.') - parser.add_argument('--images', default=None, type=str, - help='An input folder of images and output folder to save detected images. Should be in the format input->output.') - parser.add_argument('--dataset', default=None, type=str, - help='If specified, override the dataset specified in the config with this one (example: coco2017_dataset).') - parser.set_defaults(display=False, resume=False, shuffle=False, - no_sort=False) - - global args - args = parser.parse_args(argv) - - if args.seed is not None: - random.seed(args.seed) - -iou_thresholds = [x / 100 for x in range(50, 100, 5)] -coco_cats = {} # Call prep_coco_cats to fill this -coco_cats_inv = {} -color_cache = defaultdict(lambda: {}) - -def prep_coco_cats(): - """ Prepare inverted table for category id lookup given a coco cats object. """ - for coco_cat_id, transformed_cat_id_p1 in get_label_map().items(): - transformed_cat_id = transformed_cat_id_p1 - 1 - coco_cats[transformed_cat_id] = coco_cat_id - coco_cats_inv[coco_cat_id] = transformed_cat_id - -def badhash(x): - """ - Just a quick and dirty hash function for doing a deterministic shuffle based on image_id. - - Source: - https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key - """ - x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF - x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF - x = ((x >> 16) ^ x) & 0xFFFFFFFF - return x - -def preprocess(dataset, save_path = None): - dataset_size = len(dataset) if args.max_images < 0 else min(args.max_images, len(dataset)) - print("dataset size is : ", dataset_size) - print() - - # For each class and iou, stores tuples (score, isPositive) - # Index ap_data[type][iouIdx][classIdx] - dataset_indices = list(range(len(dataset))) - print("dataset indices size is :", len(dataset_indices)) - if args.shuffle: - random.shuffle(dataset_indices) - elif not args.no_sort: - hashed = [badhash(x) for x in dataset.ids] - dataset_indices.sort(key=lambda x: hashed[x]) - - dataset_indices = dataset_indices[:dataset_size] - - if save_path is None: - save_path = './prep_dataset/' - - if os.path.exists(save_path) == False: - os.mkdir(save_path) - else: - print('dir exist!') - - # Main eval loop - with open('yolact_prep_bin.info', 'w+') as f: - for it, image_idx in enumerate(dataset_indices): - img, gt, gt_masks, h, w, num_crowd = dataset.pull_item(image_idx) - # Test flag, do not upvote - batch = Variable(img.unsqueeze(0)) - batch_numpy = np.array(batch).astype(np.float32) - - binFileName = os.path.join(save_path, 'coco_val2017_' + str(image_idx) + '.bin') - - batch_numpy.tofile(binFileName) - - line = str(it) + ' ' + binFileName + ' ' + '550 550\n' - f.write(line) - if it % 100 == 0: - print('[INFO][PreProcess]', 'CurSampleNum:', it) - -if __name__ == '__main__': - parse_args() - - if args.config is not None: - set_cfg(args.config) - - else: - args.config = 'yolact_base_config' - print('Config not specified. Parsed %s from the file name.\n' % args.config) - set_cfg(args.config) - - if not os.path.exists('results'): - os.makedirs('results') - - #if args.image is None and args.video is None and args.images is None: - dataset = COCODetection(args.valid_images, args.valid_annotations, - transform=BaseTransform(), has_gt=cfg.dataset.has_gt) - prep_coco_cats() - - preprocess(dataset) - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from data import COCODetection, get_label_map +from utils.augmentations import BaseTransform +from data import cfg, set_cfg +import numpy as np +from torch.autograd import Variable +import argparse +import random +import os +from collections import defaultdict + +def str2bool(v): + if v.lower() in ('yes', 'true', 't', 'y', '1'): + return True + elif v.lower() in ('no', 'false', 'f', 'n', '0'): + return False + else: + raise argparse.ArgumentTypeError('Boolean value expected.') + +def parse_args(argv=None): + parser = argparse.ArgumentParser( + description='YOLACT COCO Evaluation') + parser.add_argument('--valid_images', default='/home/data/coco/images/', help='the path of validation images') + parser.add_argument('--valid_annotations', default='/home/data/coco/annotations/instances_val2017.json', help='the path of validation annotations') + parser.add_argument('--cuda', default=True, type=str2bool, + help='Use cuda to evaulate model') + parser.add_argument('--display', dest='display', action='store_true', + help='Display qualitative results instead of quantitative ones.') + parser.add_argument('--shuffle', dest='shuffle', action='store_true', + help='Shuffles the images when displaying them. Doesn\'t have much of an effect when display is off though.') + parser.add_argument('--resume', dest='resume', action='store_true', + help='If display not set, this resumes mAP calculations from the ap_data_file.') + parser.add_argument('--max_images', default=-1, type=int, + help='The maximum number of images from the dataset to consider. Use -1 for all.') + parser.add_argument('--config', default=None, + help='The config object to use.') + parser.add_argument('--no_sort', default=False, dest='no_sort', action='store_true', + help='Do not sort images by hashed image ID.') + parser.add_argument('--seed', default=None, type=int, + help='The seed to pass into random.seed. Note: this is only really for the shuffle and does not (I think) affect cuda stuff.') + parser.add_argument('--image', default=None, type=str, + help='A path to an image to use for display.') + parser.add_argument('--images', default=None, type=str, + help='An input folder of images and output folder to save detected images. Should be in the format input->output.') + parser.add_argument('--dataset', default=None, type=str, + help='If specified, override the dataset specified in the config with this one (example: coco2017_dataset).') + parser.set_defaults(display=False, resume=False, shuffle=False, + no_sort=False) + + global args + args = parser.parse_args(argv) + + if args.seed is not None: + random.seed(args.seed) + +iou_thresholds = [x / 100 for x in range(50, 100, 5)] +coco_cats = {} # Call prep_coco_cats to fill this +coco_cats_inv = {} +color_cache = defaultdict(lambda: {}) + +def prep_coco_cats(): + """ Prepare inverted table for category id lookup given a coco cats object. """ + for coco_cat_id, transformed_cat_id_p1 in get_label_map().items(): + transformed_cat_id = transformed_cat_id_p1 - 1 + coco_cats[transformed_cat_id] = coco_cat_id + coco_cats_inv[coco_cat_id] = transformed_cat_id + +def badhash(x): + """ + Just a quick and dirty hash function for doing a deterministic shuffle based on image_id. + + Source: + https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key + """ + x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF + x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF + x = ((x >> 16) ^ x) & 0xFFFFFFFF + return x + +def preprocess(dataset, save_path = None): + dataset_size = len(dataset) if args.max_images < 0 else min(args.max_images, len(dataset)) + print("dataset size is : ", dataset_size) + print() + + # For each class and iou, stores tuples (score, isPositive) + # Index ap_data[type][iouIdx][classIdx] + dataset_indices = list(range(len(dataset))) + print("dataset indices size is :", len(dataset_indices)) + if args.shuffle: + random.shuffle(dataset_indices) + elif not args.no_sort: + hashed = [badhash(x) for x in dataset.ids] + dataset_indices.sort(key=lambda x: hashed[x]) + + dataset_indices = dataset_indices[:dataset_size] + + if save_path is None: + save_path = './prep_dataset/' + + if os.path.exists(save_path) == False: + os.mkdir(save_path) + else: + print('dir exist!') + + # Main eval loop + with open('yolact_prep_bin.info', 'w+') as f: + for it, image_idx in enumerate(dataset_indices): + img, gt, gt_masks, h, w, num_crowd = dataset.pull_item(image_idx) + # Test flag, do not upvote + batch = Variable(img.unsqueeze(0)) + batch_numpy = np.array(batch).astype(np.float32) + + binFileName = os.path.join(save_path, 'coco_val2017_' + str(image_idx) + '.bin') + + batch_numpy.tofile(binFileName) + + line = str(it) + ' ' + binFileName + ' ' + '550 550\n' + f.write(line) + if it % 100 == 0: + print('[INFO][PreProcess]', 'CurSampleNum:', it) + +if __name__ == '__main__': + parse_args() + + if args.config is not None: + set_cfg(args.config) + + else: + args.config = 'yolact_base_config' + print('Config not specified. Parsed %s from the file name.\n' % args.config) + set_cfg(args.config) + + if not os.path.exists('results'): + os.makedirs('results') + + #if args.image is None and args.video is None and args.images is None: + dataset = COCODetection(args.valid_images, args.valid_annotations, + transform=BaseTransform(), has_gt=cfg.dataset.has_gt) + prep_coco_cats() + + preprocess(dataset) + + diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/dcnv2.diff b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/dcnv2.diff index c1af4f32cecbac40d982a9727821a90a72d5fca5..f1d3a4edb9ee432fdc606cbe9c0ba2e79666a6d6 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/dcnv2.diff +++ b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/dcnv2.diff @@ -1,107 +1,107 @@ -diff --git a/dcn_v2.py b/dcn_v2.py -index 982bef5..db33229 100644 ---- a/dcn_v2.py -+++ b/dcn_v2.py - -@@ -14,16 +15,38 @@ import _ext as _backend - - - class _DCNv2(Function): -+ -+ @staticmethod -+ def symbolic(g, input, weight, offset, bias, stride, padding, -+ dilation, groups, defomable_groups): -+ if isinstance(stride, int): -+ stride = (stride, stride) -+ if isinstance(padding, int): -+ padding = (padding, padding) -+ if isinstance(dilation, int): -+ dilation = (dilation, dilation) -+ return g.op( -+ 'DeformableConv2D', -+ input, -+ weight, -+ offset, -+ bias, -+ strides_i=stride, -+ pads_i=padding, -+ dilations_i=dilation, -+ groups_i=groups, -+ defomable_groups_i=defomable_groups) - @staticmethod -- def forward(ctx, input, offset, mask, weight, bias, -- stride, padding, dilation, deformable_groups): -+ def forward(ctx, input, weight, offest, bias, -+ stride, padding, dilation, groups=1, deformable_groups=1): - ctx.stride = _pair(stride) - ctx.padding = _pair(padding) - ctx.dilation = _pair(dilation) - ctx.kernel_size = _pair(weight.shape[2:4]) - ctx.deformable_groups = deformable_groups -- output = _backend.dcn_v2_forward(input, weight, bias, -- offset, mask, -+ return torch.rand(_DCNv2._infer_shape(ctx, input, weight)).to(input.device) -+ output = _backend.dcn_v2_forward(input.float(), weight.float(), bias.float(), -+ offset.float(), mask.float(), - ctx.kernel_size[0], ctx.kernel_size[1], - ctx.stride[0], ctx.stride[1], - ctx.padding[0], ctx.padding[1], -@@ -31,15 +54,26 @@ class _DCNv2(Function): - ctx.deformable_groups) - ctx.save_for_backward(input, offset, mask, weight, bias) - return output -+ @staticmethod -+ def _infer_shape(ctx, input, weight): -+ n = input.size(0) -+ channels_out = weight.size(0) -+ height, width = input.shape[2:4] -+ kernel_h, kernel_w = weight.shape[2:4] -+ height_out = (height + 2 * ctx.padding[0] - -+ (ctx.dilation[0] * (kernel_h - 1) + 1)) // ctx.stride[0] + 1 -+ width_out = (width + 2 * ctx.padding[0] - -+ (ctx.dilation[0] * (kernel_w - 1) + 1)) // ctx.stride[0] + 1 -+ return n, channels_out, height_out, width_out - - @staticmethod - @once_differentiable - def backward(ctx, grad_output): - input, offset, mask, weight, bias = ctx.saved_tensors - grad_input, grad_offset, grad_mask, grad_weight, grad_bias = \ -- _backend.dcn_v2_backward(input, weight, -- bias, -- offset, mask, -+ _backend.dcn_v2_backward(input.float(), weight.float(), -+ bias.float(), -+ offset.float(), mask.float(), - grad_output, - ctx.kernel_size[0], ctx.kernel_size[1], - ctx.stride[0], ctx.stride[1], -@@ -120,11 +154,19 @@ class DCN(DCNv2): - o1, o2, mask = torch.chunk(out, 3, dim=1) - offset = torch.cat((o1, o2), dim=1) - mask = torch.sigmoid(mask) -- return dcn_v2_conv(input, offset, mask, -- self.weight, self.bias, -+ offset_y = offset.reshape(offset.shape[0], -1, 2, offset.shape[2], -+ offset.shape[3])[:, :, 0, ...].reshape(offset.shape[0], offset.shape[1] // 2, offset.shape[2], -+ offset.shape[3]) -+ offset_x = offset.reshape(offset.shape[0], -1, 2, offset.shape[2], -+ offset.shape[3])[:, :, 1, ...].reshape(offset.shape[0], offset.shape[1] // 2, offset.shape[2], -+ offset.shape[3]) -+ offset = torch.cat((offset_x, offset_y, mask), 1) -+ return dcn_v2_conv(input, -+ self.weight, offset, self.bias, - self.stride, - self.padding, - self.dilation, -+ 1, - self.deformable_groups) - - -@@ -300,4 +342,4 @@ class DCNPooling(DCNv2Pooling): - self.group_size, - self.part_size, - self.sample_per_part, -- self.trans_std) -+ self.trans_std) +diff --git a/dcn_v2.py b/dcn_v2.py +index 982bef5..db33229 100644 +--- a/dcn_v2.py ++++ b/dcn_v2.py + +@@ -14,16 +15,38 @@ import _ext as _backend + + + class _DCNv2(Function): ++ ++ @staticmethod ++ def symbolic(g, input, weight, offset, bias, stride, padding, ++ dilation, groups, defomable_groups): ++ if isinstance(stride, int): ++ stride = (stride, stride) ++ if isinstance(padding, int): ++ padding = (padding, padding) ++ if isinstance(dilation, int): ++ dilation = (dilation, dilation) ++ return g.op( ++ 'DeformableConv2D', ++ input, ++ weight, ++ offset, ++ bias, ++ strides_i=stride, ++ pads_i=padding, ++ dilations_i=dilation, ++ groups_i=groups, ++ defomable_groups_i=defomable_groups) + @staticmethod +- def forward(ctx, input, offset, mask, weight, bias, +- stride, padding, dilation, deformable_groups): ++ def forward(ctx, input, weight, offest, bias, ++ stride, padding, dilation, groups=1, deformable_groups=1): + ctx.stride = _pair(stride) + ctx.padding = _pair(padding) + ctx.dilation = _pair(dilation) + ctx.kernel_size = _pair(weight.shape[2:4]) + ctx.deformable_groups = deformable_groups +- output = _backend.dcn_v2_forward(input, weight, bias, +- offset, mask, ++ return torch.rand(_DCNv2._infer_shape(ctx, input, weight)).to(input.device) ++ output = _backend.dcn_v2_forward(input.float(), weight.float(), bias.float(), ++ offset.float(), mask.float(), + ctx.kernel_size[0], ctx.kernel_size[1], + ctx.stride[0], ctx.stride[1], + ctx.padding[0], ctx.padding[1], +@@ -31,15 +54,26 @@ class _DCNv2(Function): + ctx.deformable_groups) + ctx.save_for_backward(input, offset, mask, weight, bias) + return output ++ @staticmethod ++ def _infer_shape(ctx, input, weight): ++ n = input.size(0) ++ channels_out = weight.size(0) ++ height, width = input.shape[2:4] ++ kernel_h, kernel_w = weight.shape[2:4] ++ height_out = (height + 2 * ctx.padding[0] - ++ (ctx.dilation[0] * (kernel_h - 1) + 1)) // ctx.stride[0] + 1 ++ width_out = (width + 2 * ctx.padding[0] - ++ (ctx.dilation[0] * (kernel_w - 1) + 1)) // ctx.stride[0] + 1 ++ return n, channels_out, height_out, width_out + + @staticmethod + @once_differentiable + def backward(ctx, grad_output): + input, offset, mask, weight, bias = ctx.saved_tensors + grad_input, grad_offset, grad_mask, grad_weight, grad_bias = \ +- _backend.dcn_v2_backward(input, weight, +- bias, +- offset, mask, ++ _backend.dcn_v2_backward(input.float(), weight.float(), ++ bias.float(), ++ offset.float(), mask.float(), + grad_output, + ctx.kernel_size[0], ctx.kernel_size[1], + ctx.stride[0], ctx.stride[1], +@@ -120,11 +154,19 @@ class DCN(DCNv2): + o1, o2, mask = torch.chunk(out, 3, dim=1) + offset = torch.cat((o1, o2), dim=1) + mask = torch.sigmoid(mask) +- return dcn_v2_conv(input, offset, mask, +- self.weight, self.bias, ++ offset_y = offset.reshape(offset.shape[0], -1, 2, offset.shape[2], ++ offset.shape[3])[:, :, 0, ...].reshape(offset.shape[0], offset.shape[1] // 2, offset.shape[2], ++ offset.shape[3]) ++ offset_x = offset.reshape(offset.shape[0], -1, 2, offset.shape[2], ++ offset.shape[3])[:, :, 1, ...].reshape(offset.shape[0], offset.shape[1] // 2, offset.shape[2], ++ offset.shape[3]) ++ offset = torch.cat((offset_x, offset_y, mask), 1) ++ return dcn_v2_conv(input, ++ self.weight, offset, self.bias, + self.stride, + self.padding, + self.dilation, ++ 1, + self.deformable_groups) + + +@@ -300,4 +342,4 @@ class DCNPooling(DCNv2Pooling): + self.group_size, + self.part_size, + self.sample_per_part, +- self.trans_std) ++ self.trans_std) \ No newline at end of file \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/deform_conv.py b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/deform_conv.py index 936bef9074cfa7ed71acc9e28fbd75f02ae79dd4..f6d738214136868e4b7f95a306d93e2f332d8f50 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/deform_conv.py +++ b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/deform_conv.py @@ -1,234 +1,234 @@ -# Copyright (c) 2020, Huawei Technologies.All rights reserved. -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import torch.nn as nn -from torch.autograd import Function -from torch.nn.modules.utils import _pair, _single -import math - - -class ModulatedDeformConv2dFunction(Function): - - @staticmethod - def forward(ctx, - input_tensor, - offset_ori, - mask, - weight, - bias=None, - with_bias=False, - stride=1, - padding=0, - dilation=1, - groups=1, - deformable_groups=1, - sort_index_for_npu_fp=None, - sort_index_for_npu_bp=None, - ): - - input_tensor = input_tensor.float() - offset_ori = offset_ori.float() - mask = mask.float() - - ctx.stride = stride - ctx.padding = padding - ctx.dilation = dilation - ctx.groups = groups - ctx.deformable_groups = deformable_groups - ctx.sort_index_for_npu_bp = sort_index_for_npu_bp - ctx.with_bias = with_bias - - offset = offset_ori.index_select(1, sort_index_for_npu_fp) - offset_all = torch.cat([offset, mask], dim=1) - output, offset_out = torch.npu_deformable_conv2d( - input_tensor, weight, offset_all, bias, - kernel_size=[weight.shape[3], weight.shape[2]], - stride=[1, 1, ctx.stride, ctx.stride], - padding=[ctx.padding, ctx.padding, ctx.padding, ctx.padding], - dilation=[1, 1, ctx.dilation, ctx.dilation], - groups=ctx.groups, deformable_groups=ctx.deformable_groups, - modulated=True) - if weight.requires_grad or mask.requires_grad or offset.requires_grad \ - or input_tensor.requires_grad: - ctx.save_for_backward(input_tensor, weight, offset_out, offset_all) - return output - - @staticmethod - def backward(ctx, grad_output): - input_tensor, weight, offset_out, offset_all = ctx.saved_tensors - grad_input, grad_weight, grad_offset_all, grad_bias = torch.npu_deformable_conv2dbk( - input_tensor, grad_output, offset_out, weight, offset_all, - kernel_size=[weight.shape[3], weight.shape[2]], - stride=[1, 1, ctx.stride, ctx.stride], - padding=[ctx.padding, ctx.padding, ctx.padding, ctx.padding], - dilation=[1, 1, ctx.dilation, ctx.dilation], - groups=ctx.groups, deformable_groups=ctx.deformable_groups, modulated=True) - grad_offset = grad_offset_all.index_select(1, ctx.sort_index_for_npu_bp) - grad_mask = grad_offset_all[:, grad_offset.shape[1]:, :, :] - if not ctx.with_bias: - grad_bias = None - - return (grad_input, grad_offset, grad_mask, grad_weight, grad_bias, - None, None, None, None, None, None, None, None) - - -class ModulatedDeformConv(nn.Module): - - def __init__(self, - in_channels, - out_channels, - kernel_size, - stride=1, - padding=0, - dilation=1, - groups=1, - deformable_groups=1, - bias=True, - pack=True, - ): - - r"""Applies an NPU based Modulated Deformable 2D convolution operation. - - Paper link: - [Deformable ConvNets v2: More Deformable, Better Results](https://arxiv.org/abs/1811.11168) - - Reference implementation link: - https://github.com/open-mmlab/mmcv/blob/master/mmcv/ops/modulated_deform_conv.py - - The implementation of this ModulatedDeformConv is mainly based - on the implementation of mmcv for design and reconstruction. - - In ModulatedDeformConvFunction, the forward and backward are customized, - and the input tensor is reconstructed ito match the NPU based function. - - It is worth mentioning that DeformConv(DCNv1) is also implemented - by setting modulated==False. Due to the difference between input - and initialization, there is no additional implementation here. - - .. note:: - ModulatedDeformConv only implements operations under fp32 data types. - Notice, weight and bias in conv_offset must be initialized to 0. - - Args: - in_channels (int): Number of channels in the input image. - out_channels (int): Number of channels produced by the convolution. - kernel_size(int, tuple): Size of the convolving kernel. - stride(int, tuple): Stride of the convolution. Default: 1. - padding (int or tuple): Zero-padding added to both sides of the input. - Default: 0. - dilation (int or tuple): Spacing between kernel elements. Default: 1. - groups (int): Number of blocked connections from input. - channels to output channels. Default: 1. - deform_groups (int): Number of deformable group partitions. - bias (bool): If True, adds a learnable bias to the output. Default: False. - pack (bool): If True, conv_offset and mask will be included in this module. Default: True. - - Examples:: - >>> m = ModulatedDeformConv(32, 32, 1) - >>> input_tensor = torch.randn(2, 32, 5, 5) - >>> output = m(input_tensor) - """ - - super(ModulatedDeformConv, self).__init__() - - self.in_channels = in_channels - self.out_channels = out_channels - self.kernel_size = _pair(kernel_size) - self.stride = stride - self.padding = padding - self.dilation = dilation - self.groups = groups - self.deformable_groups = deformable_groups - self.with_bias = bias - self.pack = pack - - self.weight = nn.Parameter( - torch.Tensor(out_channels, in_channels // groups, *self.kernel_size)) - if bias: - self.bias = nn.Parameter(torch.Tensor(out_channels)) - else: - self.bias = torch.zeros(self.weight.shape[0]) - - if self.pack: - self.conv_offset_mask = nn.Conv2d( - self.in_channels, - self.deformable_groups * 3 * self.kernel_size[0] * - self.kernel_size[1], - kernel_size=self.kernel_size, - stride=_pair(self.stride), - padding=_pair(self.padding), - bias=True) - - self.split_num = self.deformable_groups * 2 * self.kernel_size[0] * self.kernel_size[1] - sort_index_for_npu = list(range(self.split_num)) - sort_index_for_npu_fp = sort_index_for_npu[1::2] + sort_index_for_npu[::2] - sort_index_for_npu_bp_dict = {i: idx for idx, i in enumerate(sort_index_for_npu_fp)} - sort_index_for_npu_bp = [sort_index_for_npu_bp_dict[i] for i in sort_index_for_npu] - self.sort_index_for_npu_fp = torch.IntTensor(sort_index_for_npu_fp) - self.sort_index_for_npu_bp = torch.IntTensor(sort_index_for_npu_bp) - self.sort_index_for_npu_todevice = False - - self.init_param() - - def init_param(self): - n = self.in_channels - for k in self.kernel_size: - n *= k - stdv = 1. / math.sqrt(n) - self.weight.data.uniform_(-stdv, stdv) - if self.bias is not None: - self.bias.data.zero_() - - if self.pack: - self.conv_offset_mask.weight.data.zero_() - self.conv_offset_mask.bias.data.zero_() - - def forward(self, x): - if self.pack: - out = self.conv_offset_mask(x) - offset = out[:, :self.split_num, ...] - mask = torch.sigmoid(out[:, self.split_num:, ...]) - else: - x, offset, mask = x - - if not self.sort_index_for_npu_todevice: - self.sort_index_for_npu_fp = self.sort_index_for_npu_fp.to(x.device) - self.sort_index_for_npu_bp = self.sort_index_for_npu_bp.to(x.device) - self.bias = self.bias.to(x.device) - self.sort_index_for_npu_todevice = True - - return ModulatedDeformConv2dFunction.apply( - x, offset, mask, self.weight, self.bias, self.with_bias, - self.stride, self.padding, self.dilation, - self.groups, self.deformable_groups, - self.sort_index_for_npu_fp, - self.sort_index_for_npu_bp, - ) - - -DCNv2 = ModulatedDeformConv - -if __name__ == "__main__": - x = torch.randn(2, 32, 7, 7) - model = DCNv2(32, 32, 3, 2, 1) - - torch.npu.set_device(0) - x = x.npu() - model = model.npu() - - o = model(x) - l = o.sum() - l.backward() - print(l) +# Copyright (c) 2020, Huawei Technologies.All rights reserved. +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import torch.nn as nn +from torch.autograd import Function +from torch.nn.modules.utils import _pair, _single +import math + + +class ModulatedDeformConv2dFunction(Function): + + @staticmethod + def forward(ctx, + input_tensor, + offset_ori, + mask, + weight, + bias=None, + with_bias=False, + stride=1, + padding=0, + dilation=1, + groups=1, + deformable_groups=1, + sort_index_for_npu_fp=None, + sort_index_for_npu_bp=None, + ): + + input_tensor = input_tensor.float() + offset_ori = offset_ori.float() + mask = mask.float() + + ctx.stride = stride + ctx.padding = padding + ctx.dilation = dilation + ctx.groups = groups + ctx.deformable_groups = deformable_groups + ctx.sort_index_for_npu_bp = sort_index_for_npu_bp + ctx.with_bias = with_bias + + offset = offset_ori.index_select(1, sort_index_for_npu_fp) + offset_all = torch.cat([offset, mask], dim=1) + output, offset_out = torch.npu_deformable_conv2d( + input_tensor, weight, offset_all, bias, + kernel_size=[weight.shape[3], weight.shape[2]], + stride=[1, 1, ctx.stride, ctx.stride], + padding=[ctx.padding, ctx.padding, ctx.padding, ctx.padding], + dilation=[1, 1, ctx.dilation, ctx.dilation], + groups=ctx.groups, deformable_groups=ctx.deformable_groups, + modulated=True) + if weight.requires_grad or mask.requires_grad or offset.requires_grad \ + or input_tensor.requires_grad: + ctx.save_for_backward(input_tensor, weight, offset_out, offset_all) + return output + + @staticmethod + def backward(ctx, grad_output): + input_tensor, weight, offset_out, offset_all = ctx.saved_tensors + grad_input, grad_weight, grad_offset_all, grad_bias = torch.npu_deformable_conv2dbk( + input_tensor, grad_output, offset_out, weight, offset_all, + kernel_size=[weight.shape[3], weight.shape[2]], + stride=[1, 1, ctx.stride, ctx.stride], + padding=[ctx.padding, ctx.padding, ctx.padding, ctx.padding], + dilation=[1, 1, ctx.dilation, ctx.dilation], + groups=ctx.groups, deformable_groups=ctx.deformable_groups, modulated=True) + grad_offset = grad_offset_all.index_select(1, ctx.sort_index_for_npu_bp) + grad_mask = grad_offset_all[:, grad_offset.shape[1]:, :, :] + if not ctx.with_bias: + grad_bias = None + + return (grad_input, grad_offset, grad_mask, grad_weight, grad_bias, + None, None, None, None, None, None, None, None) + + +class ModulatedDeformConv(nn.Module): + + def __init__(self, + in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + dilation=1, + groups=1, + deformable_groups=1, + bias=True, + pack=True, + ): + + r"""Applies an NPU based Modulated Deformable 2D convolution operation. + + Paper link: + [Deformable ConvNets v2: More Deformable, Better Results](https://arxiv.org/abs/1811.11168) + + Reference implementation link: + https://github.com/open-mmlab/mmcv/blob/master/mmcv/ops/modulated_deform_conv.py + + The implementation of this ModulatedDeformConv is mainly based + on the implementation of mmcv for design and reconstruction. + + In ModulatedDeformConvFunction, the forward and backward are customized, + and the input tensor is reconstructed ito match the NPU based function. + + It is worth mentioning that DeformConv(DCNv1) is also implemented + by setting modulated==False. Due to the difference between input + and initialization, there is no additional implementation here. + + .. note:: + ModulatedDeformConv only implements operations under fp32 data types. + Notice, weight and bias in conv_offset must be initialized to 0. + + Args: + in_channels (int): Number of channels in the input image. + out_channels (int): Number of channels produced by the convolution. + kernel_size(int, tuple): Size of the convolving kernel. + stride(int, tuple): Stride of the convolution. Default: 1. + padding (int or tuple): Zero-padding added to both sides of the input. + Default: 0. + dilation (int or tuple): Spacing between kernel elements. Default: 1. + groups (int): Number of blocked connections from input. + channels to output channels. Default: 1. + deform_groups (int): Number of deformable group partitions. + bias (bool): If True, adds a learnable bias to the output. Default: False. + pack (bool): If True, conv_offset and mask will be included in this module. Default: True. + + Examples:: + >>> m = ModulatedDeformConv(32, 32, 1) + >>> input_tensor = torch.randn(2, 32, 5, 5) + >>> output = m(input_tensor) + """ + + super(ModulatedDeformConv, self).__init__() + + self.in_channels = in_channels + self.out_channels = out_channels + self.kernel_size = _pair(kernel_size) + self.stride = stride + self.padding = padding + self.dilation = dilation + self.groups = groups + self.deformable_groups = deformable_groups + self.with_bias = bias + self.pack = pack + + self.weight = nn.Parameter( + torch.Tensor(out_channels, in_channels // groups, *self.kernel_size)) + if bias: + self.bias = nn.Parameter(torch.Tensor(out_channels)) + else: + self.bias = torch.zeros(self.weight.shape[0]) + + if self.pack: + self.conv_offset_mask = nn.Conv2d( + self.in_channels, + self.deformable_groups * 3 * self.kernel_size[0] * + self.kernel_size[1], + kernel_size=self.kernel_size, + stride=_pair(self.stride), + padding=_pair(self.padding), + bias=True) + + self.split_num = self.deformable_groups * 2 * self.kernel_size[0] * self.kernel_size[1] + sort_index_for_npu = list(range(self.split_num)) + sort_index_for_npu_fp = sort_index_for_npu[1::2] + sort_index_for_npu[::2] + sort_index_for_npu_bp_dict = {i: idx for idx, i in enumerate(sort_index_for_npu_fp)} + sort_index_for_npu_bp = [sort_index_for_npu_bp_dict[i] for i in sort_index_for_npu] + self.sort_index_for_npu_fp = torch.IntTensor(sort_index_for_npu_fp) + self.sort_index_for_npu_bp = torch.IntTensor(sort_index_for_npu_bp) + self.sort_index_for_npu_todevice = False + + self.init_param() + + def init_param(self): + n = self.in_channels + for k in self.kernel_size: + n *= k + stdv = 1. / math.sqrt(n) + self.weight.data.uniform_(-stdv, stdv) + if self.bias is not None: + self.bias.data.zero_() + + if self.pack: + self.conv_offset_mask.weight.data.zero_() + self.conv_offset_mask.bias.data.zero_() + + def forward(self, x): + if self.pack: + out = self.conv_offset_mask(x) + offset = out[:, :self.split_num, ...] + mask = torch.sigmoid(out[:, self.split_num:, ...]) + else: + x, offset, mask = x + + if not self.sort_index_for_npu_todevice: + self.sort_index_for_npu_fp = self.sort_index_for_npu_fp.to(x.device) + self.sort_index_for_npu_bp = self.sort_index_for_npu_bp.to(x.device) + self.bias = self.bias.to(x.device) + self.sort_index_for_npu_todevice = True + + return ModulatedDeformConv2dFunction.apply( + x, offset, mask, self.weight, self.bias, self.with_bias, + self.stride, self.padding, self.dilation, + self.groups, self.deformable_groups, + self.sort_index_for_npu_fp, + self.sort_index_for_npu_bp, + ) + + +DCNv2 = ModulatedDeformConv + +if __name__ == "__main__": + x = torch.randn(2, 32, 7, 7) + model = DCNv2(32, 32, 3, 2, 1) + + torch.npu.set_device(0) + x = x.npu() + model = model.npu() + + o = model(x) + l = o.sum() + l.backward() + print(l) diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/modelzoo_level.txt index 282c3ff3b30404101a02cc86c5bfeb6308d198e7..c5c4a9d8001fae97c66831abcfdbe02dd6261c37 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:POK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/pth2onnx.py b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/pth2onnx.py index 947bca196f623129d36a8361a00e7beac1db6238..b35740067483d6dfeb5da4018062bb6bdb1d9341 100644 --- a/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus/pth2onnx.py @@ -1,180 +1,180 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -''' -YOLACT pth权重文件转为onnx权重文件 -''' -import sys -import os -sys.path.append('../') -import torch -import torch.onnx -import argparse -from data import * -from yolact import Yolact -# -set_cfg('yolact_plus_resnet50_config') -from torch.autograd import Variable - - -def str2bool(v): - return v.lower() in ("yes", "true", "t", "1") - - -parser_pth2onnx = argparse.ArgumentParser(description='Turn YOLACT .pth module to .onnx module') - -parser_pth2onnx.add_argument('--trained_model', type=str, - default='yolact_plus_resnet50_54_800000.pth', help='choose .pth module') - -parser_pth2onnx.add_argument('--outputName', type=str, - default='yolact_plus', help='the name of the output onnx module') - -parser_pth2onnx.add_argument('--dynamic', default=False, type=str2bool, - help='choose whether the output onnx module is dynamic or not') - -args_pth2onnx = parser_pth2onnx.parse_args() - -def removeAdd240Node(model): - addNodeNum = 1227 #1227, 344 - addNode = model.graph.node[addNodeNum] - model.graph.node.remove(addNode) - for node in model.graph.node: - if '1763' in node.input: - assert node.input[0] == '1763' #'1763','1005' - node.input[0] = '1761' #'1761','1003' - - -def optimSoftmax(model): - from onnx import helper - - findOldSoftmaxNode = False - for node in model.graph.node: - if 'Softmax' in node.name: - oldSoftmaxName = node.name - oldSoftmaxInput = node.input[0] - findOldSoftmaxNode = True - break - - assert node.output[0] == 'output1' - assert findOldSoftmaxNode - - model.graph.node.remove(node) - - TransposeNode_Pre = helper.make_node('Transpose', [oldSoftmaxInput], ['66666'], - perm=[0, 2, 1], name='Transpose_Pre') - - newSoftmax = helper.make_node("Softmax", axis=1, inputs=["66666"], - outputs=["88888"], name=oldSoftmaxName) - - TransposeNode_After = helper.make_node('Transpose', ['88888'], ['output1'], - perm=[0, 2, 1], name="Transpose_After") - - model.graph.node.append(TransposeNode_Pre) - model.graph.node.append(TransposeNode_After) - model.graph.node.append(newSoftmax) - - a = model.graph.output[1].type.tensor_type.shape.dim[1] - a.dim_param = '57744' # 57744, 19248 - b = model.graph.output[1].type.tensor_type.shape.dim[2] - b.dim_param = '81' - - -def ReplaceScales(ori_list, scales_name): - n_list = [] - for i, x in enumerate(ori_list): - if i < 2: - n_list.append(x) - if i == 3: - n_list.append(scales_name) - return n_list - -def optimresize(model): - # 替换Resize节点 - i = 1311 #429 - n = model.graph.node[i] - if n.op_type == "Resize": - print("Resize", i, n.input, n.output) - model.graph.initializer.append( - onnx.helper.make_tensor('scales{}'.format(i), onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) - ) - newnode = onnx.helper.make_node( - 'Resize', - name=n.name, - inputs=ReplaceScales(n.input, 'scales{}'.format(i)), - outputs=n.output, - coordinate_transformation_mode='pytorch_half_pixel', - cubic_coeff_a=-0.75, - mode='linear', - nearest_mode='floor' - ) - model.graph.node.remove(n) - model.graph.node.insert(i, newnode) - print("replace {} index {}".format(n.name, i)) - # for i in range(401, 428): - # print('remove:', model.graph.node[401].name) - # model.graph.node.remove(model.graph.node[401]) - - -def convert(path, pthPath): - ''' - 转换pth模型为onnx模型 - :param path: onnx模型存储路径 - :param pthPath: pth模型路径 - :return: - ''' - yolact_net = Yolact() - yolact_net.load_weights(pthPath, useCuda=False) - yolact_net.exportOnnx = True - yolact_net.eval() - - input_names = ["input.1"] - - dummy_input = Variable( - torch.randn(1, 3, 550, 550)) - - output_names = ["output0", "output1", "output2", "output3", "output4"] - - if args_pth2onnx.dynamic: - dynamic_axes = { - 'input.1': {0: '-1'}, - 'output0': {0: '-1'}, - 'output1': {0: '-1'}, - 'output2': {0: '-1'}, - 'output3': {0: '-1'}, - 'output4': {0: '-1'} - } - torch.onnx.export(yolact_net, dummy_input, args_pth2onnx.outputName + ".onnx", - verbose=True, dynamic_axes=dynamic_axes, - input_names=input_names, - output_names=output_names, opset_version=11, enable_onnx_checker=False) - - else: - torch.onnx.export(yolact_net, dummy_input, - args_pth2onnx.outputName + '.onnx', - input_names=input_names, - output_names=output_names, - opset_version=11, verbose=True, enable_onnx_checker=False) - - -if __name__ == '__main__': - path = os.getcwd() - pthPath = os.getcwd() + '/' + args_pth2onnx.trained_model - convert(path, pthPath) - import onnx - - model = onnx.load('./' + args_pth2onnx.outputName + '.onnx') - removeAdd240Node(model) - optimSoftmax(model) - optimresize(model) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +''' +YOLACT pth权重文件转为onnx权重文件 +''' +import sys +import os +sys.path.append('../') +import torch +import torch.onnx +import argparse +from data import * +from yolact import Yolact +# +set_cfg('yolact_plus_resnet50_config') +from torch.autograd import Variable + + +def str2bool(v): + return v.lower() in ("yes", "true", "t", "1") + + +parser_pth2onnx = argparse.ArgumentParser(description='Turn YOLACT .pth module to .onnx module') + +parser_pth2onnx.add_argument('--trained_model', type=str, + default='yolact_plus_resnet50_54_800000.pth', help='choose .pth module') + +parser_pth2onnx.add_argument('--outputName', type=str, + default='yolact_plus', help='the name of the output onnx module') + +parser_pth2onnx.add_argument('--dynamic', default=False, type=str2bool, + help='choose whether the output onnx module is dynamic or not') + +args_pth2onnx = parser_pth2onnx.parse_args() + +def removeAdd240Node(model): + addNodeNum = 1227 #1227, 344 + addNode = model.graph.node[addNodeNum] + model.graph.node.remove(addNode) + for node in model.graph.node: + if '1763' in node.input: + assert node.input[0] == '1763' #'1763','1005' + node.input[0] = '1761' #'1761','1003' + + +def optimSoftmax(model): + from onnx import helper + + findOldSoftmaxNode = False + for node in model.graph.node: + if 'Softmax' in node.name: + oldSoftmaxName = node.name + oldSoftmaxInput = node.input[0] + findOldSoftmaxNode = True + break + + assert node.output[0] == 'output1' + assert findOldSoftmaxNode + + model.graph.node.remove(node) + + TransposeNode_Pre = helper.make_node('Transpose', [oldSoftmaxInput], ['66666'], + perm=[0, 2, 1], name='Transpose_Pre') + + newSoftmax = helper.make_node("Softmax", axis=1, inputs=["66666"], + outputs=["88888"], name=oldSoftmaxName) + + TransposeNode_After = helper.make_node('Transpose', ['88888'], ['output1'], + perm=[0, 2, 1], name="Transpose_After") + + model.graph.node.append(TransposeNode_Pre) + model.graph.node.append(TransposeNode_After) + model.graph.node.append(newSoftmax) + + a = model.graph.output[1].type.tensor_type.shape.dim[1] + a.dim_param = '57744' # 57744, 19248 + b = model.graph.output[1].type.tensor_type.shape.dim[2] + b.dim_param = '81' + + +def ReplaceScales(ori_list, scales_name): + n_list = [] + for i, x in enumerate(ori_list): + if i < 2: + n_list.append(x) + if i == 3: + n_list.append(scales_name) + return n_list + +def optimresize(model): + # 替换Resize节点 + i = 1311 #429 + n = model.graph.node[i] + if n.op_type == "Resize": + print("Resize", i, n.input, n.output) + model.graph.initializer.append( + onnx.helper.make_tensor('scales{}'.format(i), onnx.TensorProto.FLOAT, [4], [1, 1, 2, 2]) + ) + newnode = onnx.helper.make_node( + 'Resize', + name=n.name, + inputs=ReplaceScales(n.input, 'scales{}'.format(i)), + outputs=n.output, + coordinate_transformation_mode='pytorch_half_pixel', + cubic_coeff_a=-0.75, + mode='linear', + nearest_mode='floor' + ) + model.graph.node.remove(n) + model.graph.node.insert(i, newnode) + print("replace {} index {}".format(n.name, i)) + # for i in range(401, 428): + # print('remove:', model.graph.node[401].name) + # model.graph.node.remove(model.graph.node[401]) + + +def convert(path, pthPath): + ''' + 转换pth模型为onnx模型 + :param path: onnx模型存储路径 + :param pthPath: pth模型路径 + :return: + ''' + yolact_net = Yolact() + yolact_net.load_weights(pthPath, useCuda=False) + yolact_net.exportOnnx = True + yolact_net.eval() + + input_names = ["input.1"] + + dummy_input = Variable( + torch.randn(1, 3, 550, 550)) + + output_names = ["output0", "output1", "output2", "output3", "output4"] + + if args_pth2onnx.dynamic: + dynamic_axes = { + 'input.1': {0: '-1'}, + 'output0': {0: '-1'}, + 'output1': {0: '-1'}, + 'output2': {0: '-1'}, + 'output3': {0: '-1'}, + 'output4': {0: '-1'} + } + torch.onnx.export(yolact_net, dummy_input, args_pth2onnx.outputName + ".onnx", + verbose=True, dynamic_axes=dynamic_axes, + input_names=input_names, + output_names=output_names, opset_version=11, enable_onnx_checker=False) + + else: + torch.onnx.export(yolact_net, dummy_input, + args_pth2onnx.outputName + '.onnx', + input_names=input_names, + output_names=output_names, + opset_version=11, verbose=True, enable_onnx_checker=False) + + +if __name__ == '__main__': + path = os.getcwd() + pthPath = os.getcwd() + '/' + args_pth2onnx.trained_model + convert(path, pthPath) + import onnx + + model = onnx.load('./' + args_pth2onnx.outputName + '.onnx') + removeAdd240Node(model) + optimSoftmax(model) + optimresize(model) onnx.save_model(model, args_pth2onnx.outputName + '.onnx') \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/super_resolution/EDSR/LICENSE b/ACL_PyTorch/contrib/cv/super_resolution/EDSR/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/EDSR/LICENSE +++ b/ACL_PyTorch/contrib/cv/super_resolution/EDSR/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/super_resolution/EDSR/requirements.txt b/ACL_PyTorch/contrib/cv/super_resolution/EDSR/requirements.txt index 399dbfed087e9d139235f30e8d5991e803b92edd..fbd453de267138a05ccf06d3be32a3d4eb8f68fc 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/EDSR/requirements.txt +++ b/ACL_PyTorch/contrib/cv/super_resolution/EDSR/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.9.0 -numpy == 1.19.2 -Pillow == 8.2.0 +torch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.9.0 +numpy == 1.19.2 +Pillow == 8.2.0 opencv-python == 4.5.2 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/super_resolution/RCAN/LICENSE b/ACL_PyTorch/contrib/cv/super_resolution/RCAN/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/RCAN/LICENSE +++ b/ACL_PyTorch/contrib/cv/super_resolution/RCAN/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git "a/ACL_PyTorch/contrib/cv/super_resolution/RCAN/RCAN_Onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" "b/ACL_PyTorch/contrib/cv/super_resolution/RCAN/RCAN_Onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" index f979b9dd8b5c951a6b16603909e81376e58b7639..2bc1e9d7c210ef758cbf493a13e4674b760f9a5b 100644 --- "a/ACL_PyTorch/contrib/cv/super_resolution/RCAN/RCAN_Onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" +++ "b/ACL_PyTorch/contrib/cv/super_resolution/RCAN/RCAN_Onnx\347\253\257\345\210\260\347\253\257\346\216\250\347\220\206\346\214\207\345\257\274.md" @@ -1,241 +1,241 @@ -# RCAN Onnx 模型端到端推理指导 - -- [1. 模型概述](#1) - - [论文地址](#11) - - [代码地址](#12) -- [2. 环境说明](#2) - - [深度学习框架](#21) - - [python第三方库](#22) -- [3. 模型转换](#3) - - [pth转onnx模型](#31) -- [4. 数据预处理](#4) - - [数据集获取](#41) - - [数据集预处理](#42) - - [生成数据集信息文件](#43) -- [5. 离线推理](#5) - - [benchmark工具概述](#51) - - [离线推理](#52) -- [6. 精度对比](#6) -- [7. 性能对比](#7) - - [npu性能数据](#71) - - [T4性能数据](#72) - - [性能对比](#73) - -## 1. 模型概述 - -### 1.1 论文地址 - -[RCAB 论文](https://arxiv.org/abs/1807.02758) - -### 1.2 代码地址 - -[RCAN 代码](https://github.com/yulunzhang/RCAN) - -branck: master - -commit_id: 3339ebc59519c3bb2b5719b87dd36515ec7f3ba7 - -## 2. 环境说明 - -对于batch1与batch16,310性能均高于T4性能1.2倍,该模型放s在Benchmark/cv/classification目录下。 - -### 2.1 深度学习框架 - -``` -pytorch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.9.0 -``` - -### 2.2 python第三方库 - -``` -numpy == 1.19.2 -Pillow == 8.2.0 -opencv-python == 4.5.2 -``` - -> **说明:** -> -> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 -> -> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 - -## 3. 模型转换 - -### 3.1 pth转onnx模型 - -1. 下载 pth 权重文,放入models目录下 - - [RCAN 预训练pth权重文件](https://pan.baidu.com/s/1bkoJKmdOcvLhOFXHVkFlKA) - - 文件名:RCAN_BIX2.pt - - md5sum:f567f8560fde71ba0973a7fe472a42f2 - -2. 克隆代码仓库代码 - - ```bash - git clone https://github.com/yulunzhang/RCAN.git - ``` - -3. 使用rcan_pth2onnx.py 脚本将pth转化为onnx - - ```bash - python3.7 rcan_pth2onnx.py --pth RCAN_BIX2.pt --onnx rcan.onnx - ``` - - RCAN_BIX2.pt 文件为步骤1中下载的预训练权重文件,该条指令将在运行处生成一个rcan.onnx文件,此文件即为目标onnx文件 - - -### 3.2 onnx转om模型 - -下列需要在具备华为Ascend系列芯片的机器上执行: - -1. 设置 atc 工作所需要的环境变量 - - ```bash - export install_path=/usr/local/Ascend/ascend-toolkit/latest - export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH - export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH - export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH - export ASCEND_OPP_PATH=${install_path}/opp - ``` - -2. 由于transpose算子对于某些shape不友好,需要进行优化,将如下内容写入switch.cfg中 - - ``` - TransposeReshapeFusionPass:off - ``` - - 经过Profiling分析,ConfusionTransposeD算子性能过低,故将其输入加入白名单。即在/usr/local/Ascend/ascend-toolkit/5.0.2.alpha003/x86_64-linux/opp/op_impl/built-in/ai_core/tbe/impl/dynamic/transpose.py里添加 Tranpose shape 白名单: - - ``` - 1,64,2,2,256,256 - ``` - - 以下是优化前后性能对比 - - | | 未任何优化前310(单卡吞吐率) | 优化后310(单卡吞吐率) | - | :--: | :---------------------------: | :---------------------: | - | bs1 | 0.7245 | 9.3220 | - -3. 使用atc工具将onnx模型转换为om模型,命令参考 - - ```bash - atc --framework=5 --model=rcan.onnx --output=rcan_1bs --input_format=NCHW --input_shape="image:1,3,256,256" --fusion_switch_file=switch.cfg --log=debug --soc_version=Ascend310 - ``` - - 此命令将在运行路径下生成一个rcan_1bs.om文件,此文件即为目标om模型文件 - -## 4. 数据预处理 - -### 4.1 数据集获取 - -该模型使用[Set5](https://github.com/yulunzhang/RCAN/tree/master/RCAN_TestCode/OriginalTestData/Set5)的5张验证集进行测试,图片数据放在/root/datasets/Set5。 - -### 4.2 数据集预处理 - -使用 rcan_preprocess.py 脚本进行数据预处理,脚本执行命令: - -``` -python3.7 rcan_preprocess.py -s /root/datasets/Set5/LR -d ./prep_data --size 256 -``` - -由于rcan模型支持动态输入,而atc工具需要指定输入大小,所以要在此对图像添加pad和进行缩放到同一大小,最终对推理产生的结果进行后处理恢复。以上命令将自动生成一个pad_info.json文件,此文件记录在数据预处理中对图像的pad和缩放信息,用于数据后处理时进行图像裁剪。 - -### 4.3 生成数据集信息文件 - -1. 生成数据集信息文件脚本 gen_dataset_info.py - -2. 执行生成数据集信息脚本,生成数据集信息文件 - - ```bash - python3.7 gen_dataset_info.py bin ./prep_data ./rcan_prep_bin.info 256 256 - ``` - - 第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 - -## 5. 离线推理 - -### 5.1 benchmark工具概述 - -benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN V100R020C10 推理benchmark工具用户指南 01 - -### 5.2 离线推理 - -1. 执行离线推理 - - ```bash - ./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=rcan_1bs.om -input_text_path=./rcan_prep_bin.info -input_width=256 -input_height=256 -output_binary=True -useDvpp=False - ``` - - 输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为HR_image的输出,shape为bs * 512 * 512,数据类型为FP32,对应1个超分辨后的图像数据,每个输入对应的输出对应一个_x.bin文件。 - -2. 数据后处理 - - ```bash - python3.7 rcan_postprocess.py -s result/dumpOutput_device0/ -d post_data - ``` - - 由于在预处理中对图像进行了添加pad和缩放操作,故要对推理结果进行相应的裁剪和缩放 - -## 6. 精度对比 - -### 6.1 离线推理TopN精度 - -## 6. 精度对比 - -| | PSNR | SSIM | -| :----------------: | :---: | :----: | -| 原github仓库精度 | 38.27 | 0.9614 | -| om模型离线推理精度 | 38.25 | 0.9606 | - -## 7. 性能对比 - -### 7.1 npu性能数据 - -benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。由于模型不接受多 batch 输入,所以只统计在整个数据集上推理得到bs1的性能数据 - -使用benchmark工具在整个数据集上推理时获得的性能数据: - -``` -[e2e] throughputRate: 1.11943, latency: 4466.54 -[data read] throughputRate: 1253.13, moduleLatency: 0.798 -[preprocess] throughputRate: 5.22007, moduleLatency: 191.568 -[infer] throughputRate: 2.30086, Interface throughputRate: 2.32019, moduleLatency: 433.982 -[post] throughputRate: 2.29506, moduleLatency: 435.719 -``` - -Interface throughputRate: 2.32019,2.32019x4=9.28076fps 即是batch1 310单卡吞吐率 - -### 7.2 T4性能数据 - -在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2 - -``` -trtexec --onnx=rcan.onnx --fp16 --shapes=image:1x3x256x256 -``` - -gpu T4是4个device并行执行的结果,mean是时延(tensorrt的时延是batch个数据的推理时间),即吞吐率的倒数乘以batch。其中--fp16是算子精度,目前算子精度只测--fp16的。 - -``` -[07/14/2021-10:48:26] [I] GPU Compute -[07/14/2021-10:48:26] [I] min: 150.203 ms -[07/14/2021-10:48:26] [I] max: 157.738 ms -[07/14/2021-10:48:26] [I] mean: 152.347 ms -[07/14/2021-10:48:26] [I] median: 151.781 ms -[07/14/2021-10:48:26] [I] percentile: 157.738 ms at 99% -[07/14/2021-10:48:26] [I] total compute time: 3.19929 s -``` - -batch1 t4单卡吞吐率:1000/(152.347/1)=6.5212fps - -### 7.3 性能对比 - -batch1: 9.28076fps > 6.5212fps - -310单个device的吞吐率乘4即单卡吞吐率比T4单卡的吞吐率大,故310性能高于T4性能,性能达标。 - -对于batch1,310性能高于T4性能1.2倍,该模型放在Benchmark/cv/classification目录下。 - +# RCAN Onnx 模型端到端推理指导 + +- [1. 模型概述](#1) + - [论文地址](#11) + - [代码地址](#12) +- [2. 环境说明](#2) + - [深度学习框架](#21) + - [python第三方库](#22) +- [3. 模型转换](#3) + - [pth转onnx模型](#31) +- [4. 数据预处理](#4) + - [数据集获取](#41) + - [数据集预处理](#42) + - [生成数据集信息文件](#43) +- [5. 离线推理](#5) + - [benchmark工具概述](#51) + - [离线推理](#52) +- [6. 精度对比](#6) +- [7. 性能对比](#7) + - [npu性能数据](#71) + - [T4性能数据](#72) + - [性能对比](#73) + +## 1. 模型概述 + +### 1.1 论文地址 + +[RCAB 论文](https://arxiv.org/abs/1807.02758) + +### 1.2 代码地址 + +[RCAN 代码](https://github.com/yulunzhang/RCAN) + +branck: master + +commit_id: 3339ebc59519c3bb2b5719b87dd36515ec7f3ba7 + +## 2. 环境说明 + +对于batch1与batch16,310性能均高于T4性能1.2倍,该模型放s在Benchmark/cv/classification目录下。 + +### 2.1 深度学习框架 + +``` +pytorch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.9.0 +``` + +### 2.2 python第三方库 + +``` +numpy == 1.19.2 +Pillow == 8.2.0 +opencv-python == 4.5.2 +``` + +> **说明:** +> +> X86架构:pytorch,torchvision和onnx可以通过官方下载whl包安装,其它可以通过pip3.7 install 包名 安装 +> +> Arm架构:pytorch,torchvision和onnx可以通过源码编译安装,其它可以通过pip3.7 install 包名 安装 + +## 3. 模型转换 + +### 3.1 pth转onnx模型 + +1. 下载 pth 权重文,放入models目录下 + + [RCAN 预训练pth权重文件](https://pan.baidu.com/s/1bkoJKmdOcvLhOFXHVkFlKA) + + 文件名:RCAN_BIX2.pt + + md5sum:f567f8560fde71ba0973a7fe472a42f2 + +2. 克隆代码仓库代码 + + ```bash + git clone https://github.com/yulunzhang/RCAN.git + ``` + +3. 使用rcan_pth2onnx.py 脚本将pth转化为onnx + + ```bash + python3.7 rcan_pth2onnx.py --pth RCAN_BIX2.pt --onnx rcan.onnx + ``` + + RCAN_BIX2.pt 文件为步骤1中下载的预训练权重文件,该条指令将在运行处生成一个rcan.onnx文件,此文件即为目标onnx文件 + + +### 3.2 onnx转om模型 + +下列需要在具备华为Ascend系列芯片的机器上执行: + +1. 设置 atc 工作所需要的环境变量 + + ```bash + export install_path=/usr/local/Ascend/ascend-toolkit/latest + export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH + export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH + export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH + export ASCEND_OPP_PATH=${install_path}/opp + ``` + +2. 由于transpose算子对于某些shape不友好,需要进行优化,将如下内容写入switch.cfg中 + + ``` + TransposeReshapeFusionPass:off + ``` + + 经过Profiling分析,ConfusionTransposeD算子性能过低,故将其输入加入白名单。即在/usr/local/Ascend/ascend-toolkit/5.0.2.alpha003/x86_64-linux/opp/op_impl/built-in/ai_core/tbe/impl/dynamic/transpose.py里添加 Tranpose shape 白名单: + + ``` + 1,64,2,2,256,256 + ``` + + 以下是优化前后性能对比 + + | | 未任何优化前310(单卡吞吐率) | 优化后310(单卡吞吐率) | + | :--: | :---------------------------: | :---------------------: | + | bs1 | 0.7245 | 9.3220 | + +3. 使用atc工具将onnx模型转换为om模型,命令参考 + + ```bash + atc --framework=5 --model=rcan.onnx --output=rcan_1bs --input_format=NCHW --input_shape="image:1,3,256,256" --fusion_switch_file=switch.cfg --log=debug --soc_version=Ascend310 + ``` + + 此命令将在运行路径下生成一个rcan_1bs.om文件,此文件即为目标om模型文件 + +## 4. 数据预处理 + +### 4.1 数据集获取 + +该模型使用[Set5](https://github.com/yulunzhang/RCAN/tree/master/RCAN_TestCode/OriginalTestData/Set5)的5张验证集进行测试,图片数据放在/root/datasets/Set5。 + +### 4.2 数据集预处理 + +使用 rcan_preprocess.py 脚本进行数据预处理,脚本执行命令: + +``` +python3.7 rcan_preprocess.py -s /root/datasets/Set5/LR -d ./prep_data --size 256 +``` + +由于rcan模型支持动态输入,而atc工具需要指定输入大小,所以要在此对图像添加pad和进行缩放到同一大小,最终对推理产生的结果进行后处理恢复。以上命令将自动生成一个pad_info.json文件,此文件记录在数据预处理中对图像的pad和缩放信息,用于数据后处理时进行图像裁剪。 + +### 4.3 生成数据集信息文件 + +1. 生成数据集信息文件脚本 gen_dataset_info.py + +2. 执行生成数据集信息脚本,生成数据集信息文件 + + ```bash + python3.7 gen_dataset_info.py bin ./prep_data ./rcan_prep_bin.info 256 256 + ``` + + 第一个参数为模型输入的类型,第二个参数为生成的bin文件路径,第三个为输出的info文件,后面为宽高信息 + +## 5. 离线推理 + +### 5.1 benchmark工具概述 + +benchmark工具为华为自研的模型推理工具,支持多种模型的离线推理,能够迅速统计出模型在Ascend310上的性能,支持真实数据和纯推理两种模式,配合后处理脚本,可以实现诸多模型的端到端过程,获取工具及使用方法可以参考CANN V100R020C10 推理benchmark工具用户指南 01 + +### 5.2 离线推理 + +1. 执行离线推理 + + ```bash + ./benchmark.x86_64 -model_type=vision -device_id=0 -batch_size=1 -om_path=rcan_1bs.om -input_text_path=./rcan_prep_bin.info -input_width=256 -input_height=256 -output_binary=True -useDvpp=False + ``` + + 输出结果默认保存在当前目录result/dumpOutput_device{0},模型只有一个名为HR_image的输出,shape为bs * 512 * 512,数据类型为FP32,对应1个超分辨后的图像数据,每个输入对应的输出对应一个_x.bin文件。 + +2. 数据后处理 + + ```bash + python3.7 rcan_postprocess.py -s result/dumpOutput_device0/ -d post_data + ``` + + 由于在预处理中对图像进行了添加pad和缩放操作,故要对推理结果进行相应的裁剪和缩放 + +## 6. 精度对比 + +### 6.1 离线推理TopN精度 + +## 6. 精度对比 + +| | PSNR | SSIM | +| :----------------: | :---: | :----: | +| 原github仓库精度 | 38.27 | 0.9614 | +| om模型离线推理精度 | 38.25 | 0.9606 | + +## 7. 性能对比 + +### 7.1 npu性能数据 + +benchmark工具在整个数据集上推理时也会统计性能数据,但是推理整个数据集较慢,如果这么测性能那么整个推理期间需要确保独占device,使用npu-smi info可以查看device是否空闲。也可以使用benchmark纯推理功能测得性能数据,但是由于随机数不能模拟数据分布,纯推理功能测的有些模型性能数据可能不太准,benchmark纯推理功能测性能仅为快速获取大概的性能数据以便调试优化使用,可初步确认benchmark工具在整个数据集上推理时由于device也被其它推理任务使用了导致的性能不准的问题。由于模型不接受多 batch 输入,所以只统计在整个数据集上推理得到bs1的性能数据 + +使用benchmark工具在整个数据集上推理时获得的性能数据: + +``` +[e2e] throughputRate: 1.11943, latency: 4466.54 +[data read] throughputRate: 1253.13, moduleLatency: 0.798 +[preprocess] throughputRate: 5.22007, moduleLatency: 191.568 +[infer] throughputRate: 2.30086, Interface throughputRate: 2.32019, moduleLatency: 433.982 +[post] throughputRate: 2.29506, moduleLatency: 435.719 +``` + +Interface throughputRate: 2.32019,2.32019x4=9.28076fps 即是batch1 310单卡吞吐率 + +### 7.2 T4性能数据 + +在装有T4卡的服务器上测试gpu性能,测试过程请确保卡没有运行其他任务,TensorRT版本:7.2.3.4,cuda版本:11.0,cudnn版本:8.2 + +``` +trtexec --onnx=rcan.onnx --fp16 --shapes=image:1x3x256x256 +``` + +gpu T4是4个device并行执行的结果,mean是时延(tensorrt的时延是batch个数据的推理时间),即吞吐率的倒数乘以batch。其中--fp16是算子精度,目前算子精度只测--fp16的。 + +``` +[07/14/2021-10:48:26] [I] GPU Compute +[07/14/2021-10:48:26] [I] min: 150.203 ms +[07/14/2021-10:48:26] [I] max: 157.738 ms +[07/14/2021-10:48:26] [I] mean: 152.347 ms +[07/14/2021-10:48:26] [I] median: 151.781 ms +[07/14/2021-10:48:26] [I] percentile: 157.738 ms at 99% +[07/14/2021-10:48:26] [I] total compute time: 3.19929 s +``` + +batch1 t4单卡吞吐率:1000/(152.347/1)=6.5212fps + +### 7.3 性能对比 + +batch1: 9.28076fps > 6.5212fps + +310单个device的吞吐率乘4即单卡吞吐率比T4单卡的吞吐率大,故310性能高于T4性能,性能达标。 + +对于batch1,310性能高于T4性能1.2倍,该模型放在Benchmark/cv/classification目录下。 + diff --git a/ACL_PyTorch/contrib/cv/super_resolution/RCAN/test/README.md b/ACL_PyTorch/contrib/cv/super_resolution/RCAN/test/README.md index 9ac8ecec1d746519d6bf72c3ad15619bc330b960..895b5390a526203e8349177b2f1a7d782750a5e7 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/RCAN/test/README.md +++ b/ACL_PyTorch/contrib/cv/super_resolution/RCAN/test/README.md @@ -1,26 +1,26 @@ -环境准备: - -1.数据集路径 -数据集统一放在/root/datasets/或/opt/npu/ -本模型数据集放在/root/datasets/ - -2.进入工作目录 -cd RCAN - -3.安装必要的依赖 -pip3.7 install -r requirements.txt - -4.获取模型代码 -git clone https://github.com/yulunzhang/RCAN - -5.如果使用补丁文件修改了模型代码则将补丁打入模型代码,如果需要引用模型代码仓的类或函数通过sys.path.append()添加搜索路径。 - -5.获取权重文件 -[RCAN 预训练pth权重文件](https://pan.baidu.com/s/1bkoJKmdOcvLhOFXHVkFlKA) - -7.获取benchmark工具 -将benchmark.x86_64放在当前目录 - -8.310上执行,执行时确保device空闲 -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets +环境准备: + +1.数据集路径 +数据集统一放在/root/datasets/或/opt/npu/ +本模型数据集放在/root/datasets/ + +2.进入工作目录 +cd RCAN + +3.安装必要的依赖 +pip3.7 install -r requirements.txt + +4.获取模型代码 +git clone https://github.com/yulunzhang/RCAN + +5.如果使用补丁文件修改了模型代码则将补丁打入模型代码,如果需要引用模型代码仓的类或函数通过sys.path.append()添加搜索路径。 + +5.获取权重文件 +[RCAN 预训练pth权重文件](https://pan.baidu.com/s/1bkoJKmdOcvLhOFXHVkFlKA) + +7.获取benchmark工具 +将benchmark.x86_64放在当前目录 + +8.310上执行,执行时确保device空闲 +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets diff --git a/ACL_PyTorch/contrib/cv/super_resolution/RCAN/test/parse.py b/ACL_PyTorch/contrib/cv/super_resolution/RCAN/test/parse.py index 21ac0dab63a0d58564d4bc04255a7e468ec8e191..86e265cb0697765c5ff926c2801d0be752452f1d 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/RCAN/test/parse.py +++ b/ACL_PyTorch/contrib/cv/super_resolution/RCAN/test/parse.py @@ -1,33 +1,33 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as fp: - content = json.load(fp) - PSNR = content['PSNR'] - SSIM = content['SSIM'] - print('om {} PSNR:{} SSIM:{}'.format(result_json.split('_')[1].split('.')[0], PSNR, SSIM)) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as fp: + content = json.load(fp) + PSNR = content['PSNR'] + SSIM = content['SSIM'] + print('om {} PSNR:{} SSIM:{}'.format(result_json.split('_')[1].split('.')[0], PSNR, SSIM)) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/super_resolution/RDN/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/super_resolution/RDN/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/RDN/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/super_resolution/RDN/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/super_resolution/RDN/test/README.md b/ACL_PyTorch/contrib/cv/super_resolution/RDN/test/README.md index f3fc08cb2b06551c60258305ba490240cb1d3ad8..bcf77d3efe1349a6a38fa4c136d4fa775d73d995 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/RDN/test/README.md +++ b/ACL_PyTorch/contrib/cv/super_resolution/RDN/test/README.md @@ -1,52 +1,52 @@ -## RDN模型PyTorch离线推理指导 - -### 1 环境准备 - -1. 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - - ```python - pip3.7 install -r requirements.txt - ``` - -2. 获取开源模型代码 - - ``` - git clone https://github.com/yjn870/RDN-pytorch -b master - ``` - - 开源模型代码仓没有安装脚本,可以通过sys.path.append(r"./RDN-pytorch")添加搜索路径,然后在pth2onnx脚本中就可以引用模型代码的函数或类 - -3. 获取权重文件 - - [RDN_x2预训练pth权重文件](https://www.dropbox.com/s/pd52pkmaik1ri0h/rdn_x2.pth?dl=0) - -4. 数据集 - - 开源代码仓只提供了h5格式的Set5数据集,由于代码仓评测精度的脚本采用png格式的图片作为输入,可通过[Set5](https://github.com/hengchuan/RDN-TensorFlow/tree/master/Test/Set5)下载png格式的Set5数据集,并将文件夹重命名为set5,数据集放在/root/datasets目录 - -5. 获取benchmark工具 - - 将benchmark.x86_64放到当前目录 - -6. TransposeD算子性能优化 - - 由于om模型中存在低性能的TransposeD算子,通过添加白名单使用高性能的Transpose算子。/usr/local/Ascend/ascend-toolkit/latest/x86_64-linux/opp/op_impl/built-in/ai_core/tbe/impl/dynamic/transpose.py里添加shape白名单:[1, 64, 2, 2, 114, 114] - -### 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 - -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/root/datasets -``` - - - -**评测结果:** - -| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | -| :-----: | :---------: | :-------------: | :--------: | :-------: | -| RDN bs1 | PSNR:38.18 | PSNR:38.27 | fps:25.393 | fps:29.577 | - +## RDN模型PyTorch离线推理指导 + +### 1 环境准备 + +1. 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + + ```python + pip3.7 install -r requirements.txt + ``` + +2. 获取开源模型代码 + + ``` + git clone https://github.com/yjn870/RDN-pytorch -b master + ``` + + 开源模型代码仓没有安装脚本,可以通过sys.path.append(r"./RDN-pytorch")添加搜索路径,然后在pth2onnx脚本中就可以引用模型代码的函数或类 + +3. 获取权重文件 + + [RDN_x2预训练pth权重文件](https://www.dropbox.com/s/pd52pkmaik1ri0h/rdn_x2.pth?dl=0) + +4. 数据集 + + 开源代码仓只提供了h5格式的Set5数据集,由于代码仓评测精度的脚本采用png格式的图片作为输入,可通过[Set5](https://github.com/hengchuan/RDN-TensorFlow/tree/master/Test/Set5)下载png格式的Set5数据集,并将文件夹重命名为set5,数据集放在/root/datasets目录 + +5. 获取benchmark工具 + + 将benchmark.x86_64放到当前目录 + +6. TransposeD算子性能优化 + + 由于om模型中存在低性能的TransposeD算子,通过添加白名单使用高性能的Transpose算子。/usr/local/Ascend/ascend-toolkit/latest/x86_64-linux/opp/op_impl/built-in/ai_core/tbe/impl/dynamic/transpose.py里添加shape白名单:[1, 64, 2, 2, 114, 114] + +### 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 + +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/root/datasets +``` + + + +**评测结果:** + +| 模型 | 官网pth精度 | 310离线推理精度 | 基准性能 | 310性能 | +| :-----: | :---------: | :-------------: | :--------: | :-------: | +| RDN bs1 | PSNR:38.18 | PSNR:38.27 | fps:25.393 | fps:29.577 | + - 因Set5数据集只有5张图片,因此仅使用了bs1进行评测。 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/README.md b/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/README.md index e37cba67a59eafa18ed5eae1e0f6b46f8e2f6a8e..c3f42ecb9b0e0c0dd58782d3113ce77a32d501d6 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/README.md +++ b/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/README.md @@ -1,49 +1,49 @@ -# Real-ESRGAN-baseline模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 -``` -pip3.7 install -r requirements.txt -``` - -2.获取与安装开源模型代码 -``` -git clone https://github.com/xinntao/Real-ESRGAN.git -cd Real-ESRGAN -git reset c9023b3d7a5b711b0505a3e39671e3faab9de1fe --hard -``` - -3.获取权重文件 - -将权重文件[RealESRGAN_x4plus.pth](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth)放到experiments/pretrained_models/目录 -``` - mkdir -p experiments/pretrained_models - wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models -``` - -4.数据集 -获取推理数据集:推理数据集代码仓已提供,并且放置在代码仓./Real-ESRGAN/inputs目录 - -5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) -将benchmark.x86_64或benchmark.aarch64放到当前工作目录 - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=./Real-ESRGAN -``` - **评测结果:** -| 模型 | 基准性能 | 310性能 | -| :------: | :------: | :------: | -| Real-ESRGAN bs1 | 55.132fps | 139.502fps | -| Real-ESRGAN bs16 | 72.923fps | 117.636fps | - -备注: -加上TEST.NECK_FEAT "('before')" TEST.FEAT_NORM "('no')"导出的onnx可以进行离线推理 -不加TEST.NECK_FEAT "('before')" TEST.FEAT_NORM "('no')"导出的onnx转换的om精度与官网精度一致 - - - +# Real-ESRGAN-baseline模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 +``` +pip3.7 install -r requirements.txt +``` + +2.获取与安装开源模型代码 +``` +git clone https://github.com/xinntao/Real-ESRGAN.git +cd Real-ESRGAN +git reset c9023b3d7a5b711b0505a3e39671e3faab9de1fe --hard +``` + +3.获取权重文件 + +将权重文件[RealESRGAN_x4plus.pth](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth)放到experiments/pretrained_models/目录 +``` + mkdir -p experiments/pretrained_models + wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models +``` + +4.数据集 +获取推理数据集:推理数据集代码仓已提供,并且放置在代码仓./Real-ESRGAN/inputs目录 + +5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) +将benchmark.x86_64或benchmark.aarch64放到当前工作目录 + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=./Real-ESRGAN +``` + **评测结果:** +| 模型 | 基准性能 | 310性能 | +| :------: | :------: | :------: | +| Real-ESRGAN bs1 | 55.132fps | 139.502fps | +| Real-ESRGAN bs16 | 72.923fps | 117.636fps | + +备注: +加上TEST.NECK_FEAT "('before')" TEST.FEAT_NORM "('no')"导出的onnx可以进行离线推理 +不加TEST.NECK_FEAT "('before')" TEST.FEAT_NORM "('no')"导出的onnx转换的om精度与官网精度一致 + + + diff --git a/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/Real-ESRGAN_postprocess.py b/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/Real-ESRGAN_postprocess.py index a420e1ef318a764f79b3ae73ec89f4a1d6bfa063..c27bc47051e94af0583da09c6d9b3f5bf0bf55a4 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/Real-ESRGAN_postprocess.py +++ b/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/Real-ESRGAN_postprocess.py @@ -1,16 +1,16 @@ -# Copyright 2021 Huawei Technologies Co., Ltd +# Copyright 2021 Huawei Technologies Co., Ltd # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import numpy as np import matplotlib diff --git a/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/Real-ESRGAN_preprocess.py b/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/Real-ESRGAN_preprocess.py index 7bd8d21b149a3b3a856bf1634f1937b0037f3548..a6b0c71b97bd7d4b28ec643959a71c2bce0704e9 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/Real-ESRGAN_preprocess.py +++ b/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/Real-ESRGAN_preprocess.py @@ -1,17 +1,17 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import os from PIL import Image from torchvision.transforms import transforms diff --git a/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/get_dataset_info.py b/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/get_dataset_info.py index 7ff00e26a93ec0b134ada8c5d6734ecf4230df5b..3024744fe86fad12edb8420870b9266c0fab8855 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/get_dataset_info.py +++ b/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/get_dataset_info.py @@ -1,63 +1,63 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import cv2 -from glob import glob - - -def get_bin_info(file_path, info_name, width, height): - bin_images = glob(os.path.join(file_path, '*.bin')) - print(bin_images) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_images): - content = ' '.join([str(index), img, width, height]) - file.write(content) - file.write('\n') - - -def get_jpg_info(file_path, info_name): - extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] - image_names = [] - for extension in extensions: - image_names.append(glob(os.path.join(file_path, '*.' + extension))) - with open(info_name, 'w') as file: - for image_name in image_names: - if len(image_name) == 0: - continue - else: - for index, img in enumerate(image_name): - img_cv = cv2.imread(img) - shape = img_cv.shape - width, height = shape[1], shape[0] - content = ' '.join([str(index), img, str(width), str(height)]) - file.write(content) - file.write('\n') - - -if __name__ == '__main__': - file_type = sys.argv[1] - file_path = sys.argv[2] - info_name = sys.argv[3] - - if file_type == 'bin': - - width = sys.argv[4] - height = sys.argv[5] - assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' - get_bin_info(file_path, info_name, width, height) - elif file_type == 'jpg': - assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import cv2 +from glob import glob + + +def get_bin_info(file_path, info_name, width, height): + bin_images = glob(os.path.join(file_path, '*.bin')) + print(bin_images) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_images): + content = ' '.join([str(index), img, width, height]) + file.write(content) + file.write('\n') + + +def get_jpg_info(file_path, info_name): + extensions = ['jpg', 'jpeg', 'JPG', 'JPEG'] + image_names = [] + for extension in extensions: + image_names.append(glob(os.path.join(file_path, '*.' + extension))) + with open(info_name, 'w') as file: + for image_name in image_names: + if len(image_name) == 0: + continue + else: + for index, img in enumerate(image_name): + img_cv = cv2.imread(img) + shape = img_cv.shape + width, height = shape[1], shape[0] + content = ' '.join([str(index), img, str(width), str(height)]) + file.write(content) + file.write('\n') + + +if __name__ == '__main__': + file_type = sys.argv[1] + file_path = sys.argv[2] + info_name = sys.argv[3] + + if file_type == 'bin': + + width = sys.argv[4] + height = sys.argv[5] + assert len(sys.argv) == 6, 'The number of input parameters must be equal to 5' + get_bin_info(file_path, info_name, width, height) + elif file_type == 'jpg': + assert len(sys.argv) == 4, 'The number of input parameters must be equal to 3' get_jpg_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/modelzoo_level.txt index 9e95396651cc4382fe60ee1ee053674f527a448c..27e6c78b37535fe4f5a17029546fe257ad164d34 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:POK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/test/parse.py b/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/test/parse.py index c3cc8bf85b0b8994cf08821af9d83276412a22bf..83170a37074cc8524e7201d9bfea401253feb15d 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/test/parse.py +++ b/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN/test/parse.py @@ -1,26 +1,26 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list=re.split('=|,',content) - fps = float(txt_data_list[1].replace('samples/s', '')) * 4 +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list=re.split('=|,',content) + fps = float(txt_data_list[1].replace('samples/s', '')) * 4 print('310 {} fps:{}'.format(re.split('-|_',result_txt)[4], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/super_resolution/SRCNN/LICENSE b/ACL_PyTorch/contrib/cv/super_resolution/SRCNN/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/SRCNN/LICENSE +++ b/ACL_PyTorch/contrib/cv/super_resolution/SRCNN/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/super_resolution/SRCNN/requirements.txt b/ACL_PyTorch/contrib/cv/super_resolution/SRCNN/requirements.txt index 399dbfed087e9d139235f30e8d5991e803b92edd..fbd453de267138a05ccf06d3be32a3d4eb8f68fc 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/SRCNN/requirements.txt +++ b/ACL_PyTorch/contrib/cv/super_resolution/SRCNN/requirements.txt @@ -1,6 +1,6 @@ -torch == 1.5.0 -torchvision == 0.6.0 -onnx == 1.9.0 -numpy == 1.19.2 -Pillow == 8.2.0 +torch == 1.5.0 +torchvision == 0.6.0 +onnx == 1.9.0 +numpy == 1.19.2 +Pillow == 8.2.0 opencv-python == 4.5.2 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/super_resolution/SRCNN/test/parse.py b/ACL_PyTorch/contrib/cv/super_resolution/SRCNN/test/parse.py index b9c74f41d7848e1250356f14472b237a18bb3489..82af69cd183218c3263723c20b652b3f7ec2bc27 100644 --- a/ACL_PyTorch/contrib/cv/super_resolution/SRCNN/test/parse.py +++ b/ACL_PyTorch/contrib/cv/super_resolution/SRCNN/test/parse.py @@ -1,32 +1,32 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] - print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + tops = [i.get('value') for i in json.loads(content).get('value') if 'Top' in i.get('key')] + print('om {} top1:{} top5:{}'.format(result_json.split('_')[1].split('.')[0], tops[0], tops[4])) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/tracking/SiamFC/LICENSE b/ACL_PyTorch/contrib/cv/tracking/SiamFC/LICENSE index b1fac45f02e2f98395fd96a7e4f4a39e257ac0bc..989e2c59e973a05cfbfe9de678b7f2af777b0713 100644 --- a/ACL_PyTorch/contrib/cv/tracking/SiamFC/LICENSE +++ b/ACL_PyTorch/contrib/cv/tracking/SiamFC/LICENSE @@ -1,201 +1,201 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/tracking/SiamFC/README.md b/ACL_PyTorch/contrib/cv/tracking/SiamFC/README.md index fcdb28c3678aa82748bd54f0a3460f6b806e5eac..0e15dcde5c6e6ab4fee61e5334d179967e67715e 100644 --- a/ACL_PyTorch/contrib/cv/tracking/SiamFC/README.md +++ b/ACL_PyTorch/contrib/cv/tracking/SiamFC/README.md @@ -1,50 +1,50 @@ -# SiamFC模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - -``` -pip3.7 install -r requirements.txt -``` - -2.获取,修改与安装开源模型代码 -``` -代码地址:https://github.com/HonglinChu/SiamTrackers/tree/master/2-SiamFC/SiamFC-VID -论文地址:https://arxiv.org/pdf/1606.09549.pdf -``` -3.获取权重文件 - -采用Ascend910上训练得到的权重文件[siamfc.pth](https://pan.baidu.com/s/1N3Igj4ZgntjRevsGA5xOTQ),提取码:4i4l,放置于本代码仓./pth目录下 - -4.数据集 -[获取OTB2015数据集]([Visual Tracker Benchmark (hanyang.ac.kr)](http://cvlab.hanyang.ac.kr/tracker_benchmark/datasets.html)),并重命名为OTB,默认存放在/opt/npu目录下 - -5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) -将benchmark.x86_64或benchmark.aarch64放到当前目录 - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh --datasets_path=/opt/npu -``` -> datasets_path参数根据数据集实际的存放位置而定,例如:OTB数据集存放位置为/opt/npu/OTB,则应设置参数--datasets_path=/opt/npu - - **评测结果:** - -| 模型 | pth在线推理精度 | 310离线推理精度 | -| :--------: | :------------------------------------------: | :------------------------------------------: | -| siamfc_bs1 | success_score: 0.576 precision_score: 0.767 | success_score: 0.571 precision_score: 0.760 | - -| 模型 | Benchmark性能 | 310性能 | -| :------: | :------: | :------: | -| exemplar_bs1 | 4240fps | 5677fps | -| search_bs1 | 738fps | 862fps | - -> 由于该模型无法进行常规的离线测试,因而改为对测试集的每一帧进行测试,exemplar_bs1和search_bs1分别对应模型中的两个分支,它们所进行的操作不同。 -> -> siamfc_bs1由exemplar_bs1和search_bs1这两部分组成,在评测精度时给出siamfc_bs1的精度,在评测性能时分别给出exemplar_bs1和search_bs1的性能。 - - +# SiamFC模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + +``` +pip3.7 install -r requirements.txt +``` + +2.获取,修改与安装开源模型代码 +``` +代码地址:https://github.com/HonglinChu/SiamTrackers/tree/master/2-SiamFC/SiamFC-VID +论文地址:https://arxiv.org/pdf/1606.09549.pdf +``` +3.获取权重文件 + +采用Ascend910上训练得到的权重文件[siamfc.pth](https://pan.baidu.com/s/1N3Igj4ZgntjRevsGA5xOTQ),提取码:4i4l,放置于本代码仓./pth目录下 + +4.数据集 +[获取OTB2015数据集]([Visual Tracker Benchmark (hanyang.ac.kr)](http://cvlab.hanyang.ac.kr/tracker_benchmark/datasets.html)),并重命名为OTB,默认存放在/opt/npu目录下 + +5.[获取benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer) +将benchmark.x86_64或benchmark.aarch64放到当前目录 + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh --datasets_path=/opt/npu +``` +> datasets_path参数根据数据集实际的存放位置而定,例如:OTB数据集存放位置为/opt/npu/OTB,则应设置参数--datasets_path=/opt/npu + + **评测结果:** + +| 模型 | pth在线推理精度 | 310离线推理精度 | +| :--------: | :------------------------------------------: | :------------------------------------------: | +| siamfc_bs1 | success_score: 0.576 precision_score: 0.767 | success_score: 0.571 precision_score: 0.760 | + +| 模型 | Benchmark性能 | 310性能 | +| :------: | :------: | :------: | +| exemplar_bs1 | 4240fps | 5677fps | +| search_bs1 | 738fps | 862fps | + +> 由于该模型无法进行常规的离线测试,因而改为对测试集的每一帧进行测试,exemplar_bs1和search_bs1分别对应模型中的两个分支,它们所进行的操作不同。 +> +> siamfc_bs1由exemplar_bs1和search_bs1这两部分组成,在评测精度时给出siamfc_bs1的精度,在评测性能时分别给出exemplar_bs1和search_bs1的性能。 + + diff --git a/ACL_PyTorch/contrib/cv/tracking/SiamFC/get_perf_data.py b/ACL_PyTorch/contrib/cv/tracking/SiamFC/get_perf_data.py index c8c69d6b8ba9bfa0f15e1cbb28a002436612d870..c0d104efd2130a607cddb5e5bbaf9f3ea1747fe3 100644 --- a/ACL_PyTorch/contrib/cv/tracking/SiamFC/get_perf_data.py +++ b/ACL_PyTorch/contrib/cv/tracking/SiamFC/get_perf_data.py @@ -1,64 +1,64 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import numpy as np -import torch -import sys - - -total = 5000 -exemplar_size = (1, 3, 127, 127) -search_size = (1, 9, 255, 255) - - -class ExperimentPerformance(object): - def __init__(self): - super(ExperimentPerformance, self).__init__() - - def run(self, savepath_e, savepath_s, infopath_e, infopath_s): - for i in range(total): - exemplar_input = torch.randn(exemplar_size) - exemplar_input = np.array(exemplar_input).astype(np.float32) - exemplar_name = "exemplar{}".format(i) - exemplar_path = os.path.join(savepath_e, exemplar_name + ".bin") - exemplar_input.tofile(exemplar_path) - with open(infopath_e, 'a') as file: - content = ' '.join([str(i), exemplar_path, str(127), str(127)]) - file.write(content) - file.write('\n') - - search_input = torch.randn(search_size) - search_input = np.array(search_input).astype(np.float32) - search_name = "search{}".format(i) - search_path = os.path.join(savepath_s, search_name + ".bin") - search_input.tofile(search_path) - with open(infopath_s, 'a') as file: - content = ' '.join([str(i), search_path, str(255), str(255)]) - file.write(content) - file.write('\n') - - -if __name__ == "__main__": - save_path_e = sys.argv[1] - save_path_s = sys.argv[2] - info_path_e = sys.argv[3] - info_path_s = sys.argv[4] - if not os.path.exists(save_path_e): - os.makedirs(save_path_e) - if not os.path.exists(save_path_s): - os.makedirs(save_path_s) - e = ExperimentPerformance() - e.run(save_path_e, save_path_s, info_path_e, info_path_s) - print("Data For Performance Ready.") +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import numpy as np +import torch +import sys + + +total = 5000 +exemplar_size = (1, 3, 127, 127) +search_size = (1, 9, 255, 255) + + +class ExperimentPerformance(object): + def __init__(self): + super(ExperimentPerformance, self).__init__() + + def run(self, savepath_e, savepath_s, infopath_e, infopath_s): + for i in range(total): + exemplar_input = torch.randn(exemplar_size) + exemplar_input = np.array(exemplar_input).astype(np.float32) + exemplar_name = "exemplar{}".format(i) + exemplar_path = os.path.join(savepath_e, exemplar_name + ".bin") + exemplar_input.tofile(exemplar_path) + with open(infopath_e, 'a') as file: + content = ' '.join([str(i), exemplar_path, str(127), str(127)]) + file.write(content) + file.write('\n') + + search_input = torch.randn(search_size) + search_input = np.array(search_input).astype(np.float32) + search_name = "search{}".format(i) + search_path = os.path.join(savepath_s, search_name + ".bin") + search_input.tofile(search_path) + with open(infopath_s, 'a') as file: + content = ' '.join([str(i), search_path, str(255), str(255)]) + file.write(content) + file.write('\n') + + +if __name__ == "__main__": + save_path_e = sys.argv[1] + save_path_s = sys.argv[2] + info_path_e = sys.argv[3] + info_path_s = sys.argv[4] + if not os.path.exists(save_path_e): + os.makedirs(save_path_e) + if not os.path.exists(save_path_s): + os.makedirs(save_path_s) + e = ExperimentPerformance() + e.run(save_path_e, save_path_s, info_path_e, info_path_s) + print("Data For Performance Ready.") diff --git a/ACL_PyTorch/contrib/cv/tracking/SiamFC/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/tracking/SiamFC/modelzoo_level.txt index 51b74557c15082ae794632436e724456a0fdcfde..5c956b09db3bcabe37a0665848500a6419125fee 100644 --- a/ACL_PyTorch/contrib/cv/tracking/SiamFC/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/tracking/SiamFC/modelzoo_level.txt @@ -1,6 +1,6 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK -PerfStatus:OK -ModelConvert:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK +PerfStatus:OK +ModelConvert:OK QuantStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/tracking/SiamFC/prepostprocess.py b/ACL_PyTorch/contrib/cv/tracking/SiamFC/prepostprocess.py index e12937034e2d28d06d3097dec42f078e15e429b1..930ab71b0432f54ce5bdbb361c9dac9f1b8ff5a8 100644 --- a/ACL_PyTorch/contrib/cv/tracking/SiamFC/prepostprocess.py +++ b/ACL_PyTorch/contrib/cv/tracking/SiamFC/prepostprocess.py @@ -1,158 +1,158 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import cv2 -import torch -import torch.nn.functional as F -import numpy as np -from utils import ToTensor, get_exemplar_image, get_pyramid_instance_image -import struct - - -exemplar_size = 127 # exemplar size z -instance_size = 255 # instance size x -context_amount = 0.5 # context amount -num_scale = 3 # number of scales -scale_step = 1.0375 # scale step of instance image -scale_penalty = 0.9745 # scale penalty -scale_lr = 0.59 # scale learning rate -response_up_stride = 16 # response upsample stride -response_sz = 17 # response size -window_influence = 0.176 # window influence -total_stride = 8 # total stride of backbone - - -class PrePostProcess(object): - def __init__(self): - self.penalty = np.ones((num_scale)) * scale_penalty - self.penalty[num_scale // 2] = 1 # [0.9745, 1, 0.9745] - - # create cosine window upsample stride=2^4=16, heatmap 17x17 - self.interp_response_sz = response_up_stride * response_sz # 272=16x17 - self.cosine_window = self._cosine_window((self.interp_response_sz, self.interp_response_sz)) - - def _cosine_window(self, size): - """ - get the cosine window - """ - cos_window = np.hanning(int(size[0]))[:, np.newaxis].dot(np.hanning(int(size[1]))[np.newaxis, :]) - cos_window = cos_window.astype(np.float32) - cos_window /= np.sum(cos_window) - return cos_window - - def cropexemplar(self, frame, box, save_path, file_name): - """ - Args: - frame: an RGB image - box: one-based bounding box [x, y, width, height] - """ - self.bbox = (box[0] - 1, box[1] - 1, box[0] - 1 + box[2], box[1] - 1 + box[3]) # zero based x1,y1,x2,y2 - self.pos = np.array([box[0] - 1 + (box[2]) / 2, box[1] - 1 + (box[3]) / 2]) # zero based cx, cy, - self.target_sz = np.array([box[2], box[3]]) # zero based w, h - - # get exemplar img - self.img_mean = tuple(map(int, frame.mean(axis=(0, 1)))) - exemplar_img, scale_z, s_z = get_exemplar_image(frame, self.bbox, - exemplar_size, context_amount, self.img_mean) - - # create scales: 0.96, 1, 1.037 - self.scales = scale_step ** np.arange(np.ceil(num_scale / 2) - num_scale, - np.floor(num_scale / 2) + 1) - - # create s_x : instance is twice as large as exemplar - self.s_x = s_z + (instance_size - exemplar_size) / scale_z # s-x search_sz, s-z exemplar_sz - - # arbitrary scale saturation - self.min_s_x = 0.2 * self.s_x - self.max_s_x = 5 * self.s_x - - # get exemplar feature - # m1: use torchvision.transforms - # exemplar_img = self.transforms(exemplar_img)[None, :, :, :] # 1,3,127,127 - # m2: don't use torchvision.transforms - exemplar_img = ToTensor(exemplar_img) - img = np.array(exemplar_img).astype(np.float32) - path = os.path.join(save_path, file_name.split('.')[0].replace('/', '-') + ".bin") - img.tofile(path) - return path - - def cropsearch(self, frame, save_path, file_name): - size_x_scales = self.s_x * self.scales # multi-scale search - pyramid = get_pyramid_instance_image(frame, self.pos, instance_size, size_x_scales, self.img_mean) - # m1: use torchvision.transforms - # instance_imgs = torch.cat([self.transforms(x)[None, :, :, :] for x in pyramid], dim=0) # 3, 3, 255, 255 - # m2: don't use torchvision.transforms - instance_imgs = torch.cat([ToTensor(x) for x in pyramid], dim=1) # 3, 3, 255, 255 - img = np.array(instance_imgs).astype(np.float32) - path = os.path.join(save_path, file_name.split('.')[0].replace('/', '-') + ".bin") - img.tofile(path) - return path - - def postprocess(self, x_f, z_f): - # x_f:search z_f:exemplar - response_maps = F.conv2d(x_f, z_f, groups=3) - response_maps = response_maps.transpose(0, 1) - response_maps = response_maps.numpy().squeeze() # 3, 17, 17 - - response_maps_up = [cv2.resize(x, (self.interp_response_sz, self.interp_response_sz), cv2.INTER_CUBIC) - for x in response_maps] # upsample - - # get max score of each scale - max_score = np.array([x.max() for x in response_maps_up]) * self.penalty # penalty=[0.9745, 1, 0.9745] - - # penalty scale change - scale_idx = max_score.argmax() - response_map = response_maps_up[scale_idx] - response_map -= response_map.min() - response_map /= response_map.sum() - response_map = (1 - window_influence) * response_map + \ - window_influence * self.cosine_window - max_r, max_c = np.unravel_index(response_map.argmax(), response_map.shape) - # displacement in interpolation response - disp_response_interp = np.array([max_c, max_r]) - (self.interp_response_sz - 1) / 2. - # displacement in input, response_up_stride=16, total_stride=8 - disp_response_input = disp_response_interp * total_stride / response_up_stride - # displacement in frame - scale = self.scales[scale_idx] # - disp_response_frame = disp_response_input * (self.s_x * scale) / instance_size - # position in frame coordinates - self.pos += disp_response_frame - # scale damping and saturation - self.s_x *= ((1 - scale_lr) + scale_lr * scale) # update - self.s_x = max(self.min_s_x, min(self.max_s_x, self.s_x)) - self.target_sz = ((1 - scale_lr) + scale_lr * scale) * self.target_sz # update - - box = np.array([ - self.pos[0] + 1 - (self.target_sz[0]) / 2, - self.pos[1] + 1 - (self.target_sz[1]) / 2, - self.target_sz[0], self.target_sz[1]]) - - return box - - def file2tensor(self, filepath, shape): - size = os.path.getsize(filepath) - res = [] - L = int(size / 4) # float32, so 4bytes - binfile = open(filepath, 'rb') - for i in range(L): - data = binfile.read(4) - num = struct.unpack('f', data) - res.append(num[0]) - binfile.close() - - dim_res = np.array(res).reshape(shape) - tensor_res = torch.tensor(dim_res, dtype=torch.float32) - - return tensor_res +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import cv2 +import torch +import torch.nn.functional as F +import numpy as np +from utils import ToTensor, get_exemplar_image, get_pyramid_instance_image +import struct + + +exemplar_size = 127 # exemplar size z +instance_size = 255 # instance size x +context_amount = 0.5 # context amount +num_scale = 3 # number of scales +scale_step = 1.0375 # scale step of instance image +scale_penalty = 0.9745 # scale penalty +scale_lr = 0.59 # scale learning rate +response_up_stride = 16 # response upsample stride +response_sz = 17 # response size +window_influence = 0.176 # window influence +total_stride = 8 # total stride of backbone + + +class PrePostProcess(object): + def __init__(self): + self.penalty = np.ones((num_scale)) * scale_penalty + self.penalty[num_scale // 2] = 1 # [0.9745, 1, 0.9745] + + # create cosine window upsample stride=2^4=16, heatmap 17x17 + self.interp_response_sz = response_up_stride * response_sz # 272=16x17 + self.cosine_window = self._cosine_window((self.interp_response_sz, self.interp_response_sz)) + + def _cosine_window(self, size): + """ + get the cosine window + """ + cos_window = np.hanning(int(size[0]))[:, np.newaxis].dot(np.hanning(int(size[1]))[np.newaxis, :]) + cos_window = cos_window.astype(np.float32) + cos_window /= np.sum(cos_window) + return cos_window + + def cropexemplar(self, frame, box, save_path, file_name): + """ + Args: + frame: an RGB image + box: one-based bounding box [x, y, width, height] + """ + self.bbox = (box[0] - 1, box[1] - 1, box[0] - 1 + box[2], box[1] - 1 + box[3]) # zero based x1,y1,x2,y2 + self.pos = np.array([box[0] - 1 + (box[2]) / 2, box[1] - 1 + (box[3]) / 2]) # zero based cx, cy, + self.target_sz = np.array([box[2], box[3]]) # zero based w, h + + # get exemplar img + self.img_mean = tuple(map(int, frame.mean(axis=(0, 1)))) + exemplar_img, scale_z, s_z = get_exemplar_image(frame, self.bbox, + exemplar_size, context_amount, self.img_mean) + + # create scales: 0.96, 1, 1.037 + self.scales = scale_step ** np.arange(np.ceil(num_scale / 2) - num_scale, + np.floor(num_scale / 2) + 1) + + # create s_x : instance is twice as large as exemplar + self.s_x = s_z + (instance_size - exemplar_size) / scale_z # s-x search_sz, s-z exemplar_sz + + # arbitrary scale saturation + self.min_s_x = 0.2 * self.s_x + self.max_s_x = 5 * self.s_x + + # get exemplar feature + # m1: use torchvision.transforms + # exemplar_img = self.transforms(exemplar_img)[None, :, :, :] # 1,3,127,127 + # m2: don't use torchvision.transforms + exemplar_img = ToTensor(exemplar_img) + img = np.array(exemplar_img).astype(np.float32) + path = os.path.join(save_path, file_name.split('.')[0].replace('/', '-') + ".bin") + img.tofile(path) + return path + + def cropsearch(self, frame, save_path, file_name): + size_x_scales = self.s_x * self.scales # multi-scale search + pyramid = get_pyramid_instance_image(frame, self.pos, instance_size, size_x_scales, self.img_mean) + # m1: use torchvision.transforms + # instance_imgs = torch.cat([self.transforms(x)[None, :, :, :] for x in pyramid], dim=0) # 3, 3, 255, 255 + # m2: don't use torchvision.transforms + instance_imgs = torch.cat([ToTensor(x) for x in pyramid], dim=1) # 3, 3, 255, 255 + img = np.array(instance_imgs).astype(np.float32) + path = os.path.join(save_path, file_name.split('.')[0].replace('/', '-') + ".bin") + img.tofile(path) + return path + + def postprocess(self, x_f, z_f): + # x_f:search z_f:exemplar + response_maps = F.conv2d(x_f, z_f, groups=3) + response_maps = response_maps.transpose(0, 1) + response_maps = response_maps.numpy().squeeze() # 3, 17, 17 + + response_maps_up = [cv2.resize(x, (self.interp_response_sz, self.interp_response_sz), cv2.INTER_CUBIC) + for x in response_maps] # upsample + + # get max score of each scale + max_score = np.array([x.max() for x in response_maps_up]) * self.penalty # penalty=[0.9745, 1, 0.9745] + + # penalty scale change + scale_idx = max_score.argmax() + response_map = response_maps_up[scale_idx] + response_map -= response_map.min() + response_map /= response_map.sum() + response_map = (1 - window_influence) * response_map + \ + window_influence * self.cosine_window + max_r, max_c = np.unravel_index(response_map.argmax(), response_map.shape) + # displacement in interpolation response + disp_response_interp = np.array([max_c, max_r]) - (self.interp_response_sz - 1) / 2. + # displacement in input, response_up_stride=16, total_stride=8 + disp_response_input = disp_response_interp * total_stride / response_up_stride + # displacement in frame + scale = self.scales[scale_idx] # + disp_response_frame = disp_response_input * (self.s_x * scale) / instance_size + # position in frame coordinates + self.pos += disp_response_frame + # scale damping and saturation + self.s_x *= ((1 - scale_lr) + scale_lr * scale) # update + self.s_x = max(self.min_s_x, min(self.max_s_x, self.s_x)) + self.target_sz = ((1 - scale_lr) + scale_lr * scale) * self.target_sz # update + + box = np.array([ + self.pos[0] + 1 - (self.target_sz[0]) / 2, + self.pos[1] + 1 - (self.target_sz[1]) / 2, + self.target_sz[0], self.target_sz[1]]) + + return box + + def file2tensor(self, filepath, shape): + size = os.path.getsize(filepath) + res = [] + L = int(size / 4) # float32, so 4bytes + binfile = open(filepath, 'rb') + for i in range(L): + data = binfile.read(4) + num = struct.unpack('f', data) + res.append(num[0]) + binfile.close() + + dim_res = np.array(res).reshape(shape) + tensor_res = torch.tensor(dim_res, dtype=torch.float32) + + return tensor_res diff --git a/ACL_PyTorch/contrib/cv/tracking/SiamFC/pth2onnx.py b/ACL_PyTorch/contrib/cv/tracking/SiamFC/pth2onnx.py index d864e0ba0680b635dda54c958ee842061fed9c77..e68b3bce6cdc51ce8471158dab1c1e4f7effc2d5 100644 --- a/ACL_PyTorch/contrib/cv/tracking/SiamFC/pth2onnx.py +++ b/ACL_PyTorch/contrib/cv/tracking/SiamFC/pth2onnx.py @@ -1,118 +1,118 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import torch -import torch.nn as nn -import torch.onnx -import torch.nn.functional as F - - -response_scale = 1e-3 - - -class SiameseAlexNet(nn.Module): - def __init__(self): - super(SiameseAlexNet, self).__init__() - self.features = nn.Sequential( - nn.Conv2d(3, 96, 11, 2), - nn.BatchNorm2d(96), - nn.ReLU(inplace=True), - nn.MaxPool2d(3, 2), - nn.Conv2d(96, 256, 5, 1, groups=2), - nn.BatchNorm2d(256), - nn.ReLU(inplace=True), - nn.MaxPool2d(3, 2), - nn.Conv2d(256, 384, 3, 1), - nn.BatchNorm2d(384), - nn.ReLU(inplace=True), - nn.Conv2d(384, 384, 3, 1, groups=2), - nn.BatchNorm2d(384), - nn.ReLU(inplace=True), - nn.Conv2d(384, 256, 3, 1, groups=2) - ) - self.corr_bias = nn.Parameter(torch.zeros(1)) - self.exemplar = None - - def init_weights(self): - for m in self.modules(): - if isinstance(m, nn.Conv2d): - nn.init.kaiming_normal_(m.weight.data, mode='fan_out', nonlinearity='relu') - elif isinstance(m, nn.BatchNorm2d): - m.weight.data.fill_(1) - m.bias.data.zero_() - - def forward(self, x): - exemplar, instance = x # x = ( exemplar, instance ) - # train - if exemplar is not None and instance is not None: # - batch_size = exemplar.shape[0] # - exemplar = self.features(exemplar) # batch, 256, 6, 6 - instance = self.features(instance) # batch, 256, 20, 20 - N, C, H, W = instance.shape - instance = instance.view(1, -1, H, W) - score = F.conv2d(instance, exemplar, groups=N) * response_scale + self.corr_bias - return score.transpose(0, 1) - # test(first frame) - elif exemplar is not None and instance is None: - self.exemplar = self.features(exemplar) # 1, 256, 6, 6 - self.exemplar = torch.cat([self.exemplar for _ in range(3)], dim=0) # 3, 256, 6, 6 - return self.exemplar - # test(not first frame) - else: - # inference used we don't need to scale the response or add bias - _, _, H, W = instance.shape - instance = instance.reshape(3, 3, H, W) - instance = self.features(instance) # 3 scale - N, C, H, W = instance.shape - instance = instance.view(1, N*C, H, W) # 1, NxC, H, W - # score = F.conv2d(instance, self.exemplar, groups=N) - # return score.transpose(0, 1) - return instance - - -def exemplar_convert(input_file, output_file): - model = SiameseAlexNet() - model.load_state_dict(torch.load(input_file, map_location='cpu')) - model.eval() - - input_names = ["actual_input_1"] - output_names = ["output1"] - input1 = torch.randn(1, 3, 127, 127) - input2 = None - dummy_input = [input1, input2] - torch.onnx.export(model, dummy_input, output_file, input_names=input_names, output_names=output_names, - opset_version=11) - - -def search_convert(input_file, output_file): - model = SiameseAlexNet() - model.load_state_dict(torch.load(input_file, map_location='cpu')) - model.eval() - - input_names = ["actual_input_1"] - output_names = ["output1"] - input1 = None - input2 = torch.randn(1, 9, 255, 255) - dummy_input = [input1, input2] - torch.onnx.export(model, dummy_input, output_file, input_names=input_names, output_names=output_names, - opset_version=11) - - -if __name__ == "__main__": - input_file = sys.argv[1] - output_file_exemplar = sys.argv[2] - output_file_search = sys.argv[3] - exemplar_convert(input_file, output_file_exemplar) - search_convert(input_file, output_file_search) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import torch +import torch.nn as nn +import torch.onnx +import torch.nn.functional as F + + +response_scale = 1e-3 + + +class SiameseAlexNet(nn.Module): + def __init__(self): + super(SiameseAlexNet, self).__init__() + self.features = nn.Sequential( + nn.Conv2d(3, 96, 11, 2), + nn.BatchNorm2d(96), + nn.ReLU(inplace=True), + nn.MaxPool2d(3, 2), + nn.Conv2d(96, 256, 5, 1, groups=2), + nn.BatchNorm2d(256), + nn.ReLU(inplace=True), + nn.MaxPool2d(3, 2), + nn.Conv2d(256, 384, 3, 1), + nn.BatchNorm2d(384), + nn.ReLU(inplace=True), + nn.Conv2d(384, 384, 3, 1, groups=2), + nn.BatchNorm2d(384), + nn.ReLU(inplace=True), + nn.Conv2d(384, 256, 3, 1, groups=2) + ) + self.corr_bias = nn.Parameter(torch.zeros(1)) + self.exemplar = None + + def init_weights(self): + for m in self.modules(): + if isinstance(m, nn.Conv2d): + nn.init.kaiming_normal_(m.weight.data, mode='fan_out', nonlinearity='relu') + elif isinstance(m, nn.BatchNorm2d): + m.weight.data.fill_(1) + m.bias.data.zero_() + + def forward(self, x): + exemplar, instance = x # x = ( exemplar, instance ) + # train + if exemplar is not None and instance is not None: # + batch_size = exemplar.shape[0] # + exemplar = self.features(exemplar) # batch, 256, 6, 6 + instance = self.features(instance) # batch, 256, 20, 20 + N, C, H, W = instance.shape + instance = instance.view(1, -1, H, W) + score = F.conv2d(instance, exemplar, groups=N) * response_scale + self.corr_bias + return score.transpose(0, 1) + # test(first frame) + elif exemplar is not None and instance is None: + self.exemplar = self.features(exemplar) # 1, 256, 6, 6 + self.exemplar = torch.cat([self.exemplar for _ in range(3)], dim=0) # 3, 256, 6, 6 + return self.exemplar + # test(not first frame) + else: + # inference used we don't need to scale the response or add bias + _, _, H, W = instance.shape + instance = instance.reshape(3, 3, H, W) + instance = self.features(instance) # 3 scale + N, C, H, W = instance.shape + instance = instance.view(1, N*C, H, W) # 1, NxC, H, W + # score = F.conv2d(instance, self.exemplar, groups=N) + # return score.transpose(0, 1) + return instance + + +def exemplar_convert(input_file, output_file): + model = SiameseAlexNet() + model.load_state_dict(torch.load(input_file, map_location='cpu')) + model.eval() + + input_names = ["actual_input_1"] + output_names = ["output1"] + input1 = torch.randn(1, 3, 127, 127) + input2 = None + dummy_input = [input1, input2] + torch.onnx.export(model, dummy_input, output_file, input_names=input_names, output_names=output_names, + opset_version=11) + + +def search_convert(input_file, output_file): + model = SiameseAlexNet() + model.load_state_dict(torch.load(input_file, map_location='cpu')) + model.eval() + + input_names = ["actual_input_1"] + output_names = ["output1"] + input1 = None + input2 = torch.randn(1, 9, 255, 255) + dummy_input = [input1, input2] + torch.onnx.export(model, dummy_input, output_file, input_names=input_names, output_names=output_names, + opset_version=11) + + +if __name__ == "__main__": + input_file = sys.argv[1] + output_file_exemplar = sys.argv[2] + output_file_search = sys.argv[3] + exemplar_convert(input_file, output_file_exemplar) + search_convert(input_file, output_file_search) diff --git a/ACL_PyTorch/contrib/cv/tracking/SiamFC/requirements.txt b/ACL_PyTorch/contrib/cv/tracking/SiamFC/requirements.txt index fb20cd32505c79aaf5e83bf9ebcb40cdd4eb9b0d..196f844119c1dd316412f7f453b1c5b11771e9b4 100644 --- a/ACL_PyTorch/contrib/cv/tracking/SiamFC/requirements.txt +++ b/ACL_PyTorch/contrib/cv/tracking/SiamFC/requirements.txt @@ -1,8 +1,8 @@ -torch==1.9.0 -torchvision==0.10.0 -onnx==1.9.0 -numpy==1.19.2 -opencv-python==4.5.2.54 -pillow==8.2.0 -six==1.15.0 +torch==1.9.0 +torchvision==0.10.0 +onnx==1.9.0 +numpy==1.19.2 +opencv-python==4.5.2.54 +pillow==8.2.0 +six==1.15.0 tqdm==4.61.2 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/tracking/SiamFC/test/parse.py b/ACL_PyTorch/contrib/cv/tracking/SiamFC/test/parse.py index 7cf6d0faa4019f95d30b1762da8bea66a2aa70b6..e64ee7ea699d23cd64a6924ccb82489200424dd5 100644 --- a/ACL_PyTorch/contrib/cv/tracking/SiamFC/test/parse.py +++ b/ACL_PyTorch/contrib/cv/tracking/SiamFC/test/parse.py @@ -1,25 +1,25 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[7].replace('samples/s', '')) * 4 - print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[7].replace('samples/s', '')) * 4 + print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) diff --git a/ACL_PyTorch/contrib/cv/tracking/SiamFC/wholeprocess.py b/ACL_PyTorch/contrib/cv/tracking/SiamFC/wholeprocess.py index 2bd05d59587ae0f691c9b9dbf4c57435df79cd7c..9fd127d256444befae0747fb530ca13094d64d93 100644 --- a/ACL_PyTorch/contrib/cv/tracking/SiamFC/wholeprocess.py +++ b/ACL_PyTorch/contrib/cv/tracking/SiamFC/wholeprocess.py @@ -1,426 +1,426 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import glob -import numpy as np -import io -import six -from itertools import chain -import cv2 -import json -import sys -import multiprocessing -sys.path.append(os.getcwd()) -from prepostprocess import PrePostProcess -from utils import rect_iou, center_error - - -deviceid = 0 - - -class OTB(object): - r"""`OTB `_ Datasets. - - Publication: - ``Object Tracking Benchmark``, Y. Wu, J. Lim and M.-H. Yang, IEEE TPAMI 2015. - - Args: - root_dir (string): Root directory of dataset where sequence - folders exist. - version (integer or string): Specify the benchmark version, specify as one of - ``2013``, ``2015``, ``tb50`` and ``tb100``. - """ - __otb13_seqs = ['Basketball', 'Bolt', 'Boy', 'Car4', 'CarDark', - 'CarScale', 'Coke', 'Couple', 'Crossing', 'David', - 'David2', 'David3', 'Deer', 'Dog1', 'Doll', 'Dudek', - 'FaceOcc1', 'FaceOcc2', 'Fish', 'FleetFace', - 'Football', 'Football1', 'Freeman1', 'Freeman3', - 'Freeman4', 'Girl', 'Ironman', 'Jogging', 'Jumping', - 'Lemming', 'Liquor', 'Matrix', 'Mhyang', 'MotorRolling', - 'MountainBike', 'Shaking', 'Singer1', 'Singer2', - 'Skating1', 'Skiing', 'Soccer', 'Subway', 'Suv', - 'Sylvester', 'Tiger1', 'Tiger2', 'Trellis', 'Walking', - 'Walking2', 'Woman'] - - __tb50_seqs = ['Basketball', 'Biker', 'Bird1', 'BlurBody', 'BlurCar2', - 'BlurFace', 'BlurOwl', 'Bolt', 'Box', 'Car1', 'Car4', - 'CarDark', 'CarScale', 'ClifBar', 'Couple', 'Crowds', - 'David', 'Deer', 'Diving', 'DragonBaby', 'Dudek', - 'Football', 'Freeman4', 'Girl', 'Human3', 'Human4', - 'Human6', 'Human9', 'Ironman', 'Jump', 'Jumping', - 'Liquor', 'Matrix', 'MotorRolling', 'Panda', 'RedTeam', - 'Shaking', 'Singer2', 'Skating1', 'Skating2', 'Skiing', - 'Soccer', 'Surfer', 'Sylvester', 'Tiger2', 'Trellis', - 'Walking', 'Walking2', 'Woman'] - - __tb100_seqs = ['Bird2', 'BlurCar1', 'BlurCar3', 'BlurCar4', 'Board', - 'Bolt2', 'Boy', 'Car2', 'Car24', 'Coke', 'Coupon', - 'Crossing', 'Dancer', 'Dancer2', 'David2', 'David3', - 'Dog', 'Dog1', 'Doll', 'FaceOcc1', 'FaceOcc2', 'Fish', - 'FleetFace', 'Football1', 'Freeman1', 'Freeman3', - 'Girl2', 'Gym', 'Human2', 'Human5', 'Human7', 'Human8', - 'Jogging', 'KiteSurf', 'Lemming', 'Man', 'Mhyang', - 'MountainBike', 'Rubik', 'Singer1', 'Skater', - 'Skater2', 'Subway', 'Suv', 'Tiger1', 'Toy', 'Trans', - 'Twinnings', 'Vase'] + __tb50_seqs - - __otb15_seqs = __tb100_seqs - - __version_dict = { - 2013: __otb13_seqs, - 2015: __otb15_seqs, - 'otb2013': __otb13_seqs, - 'otb2015': __otb15_seqs, - 'tb50': __tb50_seqs, - 'tb100': __tb100_seqs} - - def __init__(self, root_dir, version=2015): - super(OTB, self).__init__() - assert version in self.__version_dict - - self.root_dir = root_dir - self.version = version - self._check_integrity(root_dir, version) - valid_seqs = self.__version_dict[version] - self.anno_files = sorted(list(chain.from_iterable(glob.glob( - os.path.join(root_dir, s, 'groundtruth*.txt')) for s in valid_seqs))) - # remove empty annotation files - # (e.g. groundtruth_rect.1.txt of Human4) - self.anno_files = self._filter_files(self.anno_files) - self.seq_dirs = [os.path.dirname(f) for f in self.anno_files] - self.seq_names = [os.path.basename(d) for d in self.seq_dirs] - # rename repeated sequence names - # (e.g. Jogging and Skating2) - self.seq_names = self._rename_seqs(self.seq_names) - - def __getitem__(self, index): - r""" - Args: - index (integer or string): Index or name of a sequence. - - Returns: - tuple: (img_files, anno), where ``img_files`` is a list of - file names and ``anno`` is a N x 4 (rectangles) numpy array. - """ - if isinstance(index, six.string_types): - if not index in self.seq_names: - raise Exception('Sequence {} not found.'.format(index)) - index = self.seq_names.index(index) - - img_files = sorted(glob.glob( - os.path.join(self.seq_dirs[index], 'img/*.jpg'))) - - # special sequences - seq_name = self.seq_names[index] - if seq_name.lower() == 'david': - img_files = img_files[300 - 1:770] - elif seq_name.lower() == 'football1': - img_files = img_files[:74] - elif seq_name.lower() == 'freeman3': - img_files = img_files[:460] - elif seq_name.lower() == 'freeman4': - img_files = img_files[:283] - elif seq_name.lower() == 'diving': - img_files = img_files[:215] - - # to deal with different delimeters - with open(self.anno_files[index], 'r') as f: - anno = np.loadtxt(io.StringIO(f.read().replace(',', ' '))) - assert len(img_files) == len(anno) - assert anno.shape[1] == 4 - - return img_files, anno - - def __len__(self): - return len(self.seq_names) - - def _filter_files(self, filenames): - filtered_files = [] - for filename in filenames: - with open(filename, 'r') as f: - if f.read().strip() == '': - print('Warning: %s is empty.' % filename) - else: - filtered_files.append(filename) - - return filtered_files - - def _rename_seqs(self, seq_names): - # in case some sequences may have multiple targets - renamed_seqs = [] - for i, seq_name in enumerate(seq_names): - if seq_names.count(seq_name) == 1: - renamed_seqs.append(seq_name) - else: - ind = seq_names[:i + 1].count(seq_name) - renamed_seqs.append('%s.%d' % (seq_name, ind)) - - return renamed_seqs - - def _check_integrity(self, root_dir, version): - assert version in self.__version_dict - seq_names = self.__version_dict[version] - - if os.path.isdir(root_dir) and len(os.listdir(root_dir)) > 0: - # check each sequence folder - for seq_name in seq_names: - seq_dir = os.path.join(root_dir, seq_name) - if not os.path.isdir(seq_dir): - print('Warning: sequence %s not exists.' % seq_name) - else: - # dataset not exists - raise Exception('Dataset not found or corrupted. ' + - 'You can use download=True to download it.') - - -class ExperimentOTB(object): - """Experiment pipeline and evaluation toolkit for OTB dataset. - - Args: - root_dir (string): Root directory of OTB dataset. - version (integer or string): Specify the benchmark version, specify as one of - ``2013``, ``2015``, ``tb50`` and ``tb100``. Default is ``2015``. - result_dir (string, optional): Directory for storing tracking - results. Default is ``./results``. - report_dir (string, optional): Directory for storing performance - evaluation results. Default is ``./reports``. - """ - def __init__(self, root_dir, version=2015, - result_dir='results', report_dir='reports'): - super(ExperimentOTB, self).__init__() - self.dataset = OTB(root_dir, version) - self.result_dir = os.path.join(result_dir, 'OTB' + str(version)) - self.report_dir = os.path.join(report_dir, 'OTB' + str(version)) - # as nbins_iou increases, the success score - # converges to the average overlap (AO) - self.nbins_iou = 21 - self.nbins_ce = 51 - - def getlendataset(self): - return len(self.dataset) - - def run(self, savepath, infopath, arch, idx): - # get the seq_name and information of files - img_files, anno = self.dataset[idx] - seq_name = self.dataset.seq_names[idx] - # generate directory for current seq - savepath = savepath + "/" + str(idx) - if not os.path.exists(savepath): - os.makedirs(savepath) - infopath = infopath + "/" + str(idx) + ".info" - # skip if result exist - record_file = os.path.join(self.result_dir, 'siamfc', '%s.txt' % seq_name) - if os.path.exists(record_file): - print('Found results of %s, skipping' % seq_name) - return - frame_num = len(img_files) - boxes = np.zeros((frame_num, 4)) - boxes[0] = anno[0, :] # x,y, w, h - times = np.zeros(frame_num) - - prepostpro = PrePostProcess() - for f, img_file in enumerate(img_files): - img = cv2.imread(img_file, cv2.IMREAD_COLOR) - if f == 0: - # Pre-process and generate bin - exemplar_path = prepostpro.cropexemplar(img, anno[0, :], savepath, img_file) - # get_info - with open(infopath, 'w') as file1: - content = ' '.join([str(0), '.'+exemplar_path, str(127), str(127)]) - file1.write(content) - file1.write('\n') - # infer - os.system('%s -model_type=vision -device_id=%d -batch_size=1 ' - '-om_path=s%/exemplar_bs1.om -input_text_path=%s ' - '-input_width=127 -input_height=127 -output_binary=True -useDvpp=False >/dev/null 2>&1' - % (benchmark_path, deviceid, om_path, infopath)) - # the exemplar has a result of 3*256*6*6 tensor - # read tensor from bin - filename = img_file.replace('/', '-').split('.')[0] + '_1.bin' - filename = 'result/dumpOutput_device' + str(deviceid) + '/' + filename - exemplar_feature = prepostpro.file2tensor(filename, (3, 256, 6, 6)) - else: - # Pre-process and generate bin - search_path = prepostpro.cropsearch(img, savepath, img_file) - # get_info - with open(infopath, 'w') as file2: - content = ' '.join([str(0), '.'+search_path, str(255), str(255)]) - file2.write(content) - file2.write('\n') - # infer - os.system('%s -model_type=vision -device_id=%d -batch_size=1 ' - '-om_path=%s/search_bs1.om -input_text_path=%s ' - '-input_width=255 -input_height=255 -output_binary=True -useDvpp=False >/dev/null 2>&1' - % (benchmark_path, deviceid, om_path, infopath)) - # the exemplar has a result of 1*768*22*22 tensor - # read tensor from bin - filename = img_file.replace('/', '-').split('.')[0] + '_1.bin' - filename = 'result/dumpOutput_device' + str(deviceid) + '/' + filename - search_feature = prepostpro.file2tensor(filename, (1, 768, 22, 22)) - # Post-process - boxes[f, :] = prepostpro.postprocess(search_feature, exemplar_feature) - times[f] = 1 - assert len(boxes) == len(anno) - # record results - self._record(record_file, boxes, times) - # delete useless data to save space - os.system('rm -rf %s/*' % savepath) - print("Results of %s finished!" % seq_name) - - def report(self, tracker_names): - - assert isinstance(tracker_names, (list, tuple)) # ‘SiamFC’ - - # assume tracker_names[0] is your tracker - report_dir = os.path.join(self.report_dir, tracker_names[0]) - - if not os.path.isdir(report_dir): - os.makedirs(report_dir) - - report_file = os.path.join(report_dir, 'performance.json') - - performance = {} - for name in tracker_names: - print('Evaluating', name) - seq_num = len(self.dataset) - succ_curve = np.zeros((seq_num, self.nbins_iou)) - prec_curve = np.zeros((seq_num, self.nbins_ce)) - speeds = np.zeros(seq_num) - # - performance.update({name: {'overall': {}, 'seq_wise': {}}}) - - for s, (_, anno) in enumerate(self.dataset): - - seq_name = self.dataset.seq_names[s] - - record_file = os.path.join(self.result_dir, name, '%s.txt' % seq_name) - - boxes = np.loadtxt(record_file, delimiter=',') - - boxes[0] = anno[0] - - assert len(boxes) == len(anno) - - ious, center_errors = self._calc_metrics(boxes, anno) - - succ_curve[s], prec_curve[s] = self._calc_curves(ious, center_errors) - - # calculate average tracking speed - time_file = os.path.join(self.result_dir, name, 'times/%s_time.txt' % seq_name) - - if os.path.isfile(time_file): - times = np.loadtxt(time_file) - times = times[times > 0] - if len(times) > 0: - speeds[s] = np.mean(1. / times) - # store sequence-wise performance - performance[name]['seq_wise'].update({seq_name: { - 'success_curve': succ_curve[s].tolist(), - 'precision_curve': prec_curve[s].tolist(), - 'success_score': np.mean(succ_curve[s]), - 'precision_score': prec_curve[s][20], - 'success_rate': succ_curve[s][self.nbins_iou // 2], - 'speed_fps': speeds[s] if speeds[s] > 0 else -1}}) - - succ_curve = np.mean(succ_curve, axis=0) - prec_curve = np.mean(prec_curve, axis=0) - succ_score = np.mean(succ_curve) - prec_score = prec_curve[20] - succ_rate = succ_curve[self.nbins_iou // 2] - if np.count_nonzero(speeds) > 0: - avg_speed = np.sum(speeds) / np.count_nonzero(speeds) - else: - avg_speed = -1 - - # store overall performance - performance[name]['overall'].update({ - 'success_curve': succ_curve.tolist(), - 'precision_curve': prec_curve.tolist(), - 'success_score': succ_score, - 'precision_score': prec_score, - 'success_rate': succ_rate, - 'speed_fps': avg_speed}) - # print('prec_score:%s --succ_score:%s --succ_rate:%s' % (prec_score,succ_score,succ_rate)) - # report the performance - with open(report_file, 'w') as f: - json.dump(performance, f, indent=4) - - return prec_score, succ_score, succ_rate - - def _record(self, record_file, boxes, times): - # record bounding boxes - record_dir = os.path.dirname(record_file) - if not os.path.isdir(record_dir): - os.makedirs(record_dir) - np.savetxt(record_file, boxes, fmt='%.3f', delimiter=',') - - # print(' Results recorded at', record_file) - - # record running times - time_dir = os.path.join(record_dir, 'times') - if not os.path.isdir(time_dir): - os.makedirs(time_dir) - time_file = os.path.join(time_dir, os.path.basename( - record_file).replace('.txt', '_time.txt')) - np.savetxt(time_file, times, fmt='%.8f') - - def _calc_metrics(self, boxes, anno): - # can be modified by children classes - ious = rect_iou(boxes, anno) - center_errors = center_error(boxes, anno) - return ious, center_errors - - def _calc_curves(self, ious, center_errors): - ious = np.asarray(ious, float)[:, np.newaxis] - center_errors = np.asarray(center_errors, float)[:, np.newaxis] - - thr_iou = np.linspace(0, 1, self.nbins_iou)[np.newaxis, :] - thr_ce = np.arange(0, self.nbins_ce)[np.newaxis, :] - - bin_iou = np.greater(ious, thr_iou) - bin_ce = np.less_equal(center_errors, thr_ce) - - succ_curve = np.mean(bin_iou, axis=0) - prec_curve = np.mean(bin_ce, axis=0) - - return succ_curve, prec_curve - - -if __name__ == "__main__": - data_path = sys.argv[1] - save_path = sys.argv[2] - info_path = sys.argv[3] - arch = sys.argv[4] - deviceid = int(sys.argv[5]) - benchmark_path = sys.argv[6] - om_path = sys.argv[7] - os.system('rm -rf %s' % save_path) - os.system('rm -rf %s' % info_path) - os.system('rm -rf ./result/dumpOutput_device%d' % deviceid) - if not os.path.exists(save_path): - os.makedirs(save_path) - if not os.path.exists(info_path): - os.makedirs(info_path) - e = ExperimentOTB(data_path, version=2015) - totallen = e.getlendataset() - pool = multiprocessing.Pool(processes=12) - for i in range(totallen): - pool.apply_async(e.run, (save_path, info_path, arch, i, )) - pool.close() - pool.join() - prec_score, succ_score, succ_rate = e.report(['siamfc']) - ss = '-prec_score:%.3f -succ_score:%.3f -succ_rate:%.3f' % (float(prec_score), float(succ_score), float(succ_rate)) - print("====accuracy data====") - print(ss) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import glob +import numpy as np +import io +import six +from itertools import chain +import cv2 +import json +import sys +import multiprocessing +sys.path.append(os.getcwd()) +from prepostprocess import PrePostProcess +from utils import rect_iou, center_error + + +deviceid = 0 + + +class OTB(object): + r"""`OTB `_ Datasets. + + Publication: + ``Object Tracking Benchmark``, Y. Wu, J. Lim and M.-H. Yang, IEEE TPAMI 2015. + + Args: + root_dir (string): Root directory of dataset where sequence + folders exist. + version (integer or string): Specify the benchmark version, specify as one of + ``2013``, ``2015``, ``tb50`` and ``tb100``. + """ + __otb13_seqs = ['Basketball', 'Bolt', 'Boy', 'Car4', 'CarDark', + 'CarScale', 'Coke', 'Couple', 'Crossing', 'David', + 'David2', 'David3', 'Deer', 'Dog1', 'Doll', 'Dudek', + 'FaceOcc1', 'FaceOcc2', 'Fish', 'FleetFace', + 'Football', 'Football1', 'Freeman1', 'Freeman3', + 'Freeman4', 'Girl', 'Ironman', 'Jogging', 'Jumping', + 'Lemming', 'Liquor', 'Matrix', 'Mhyang', 'MotorRolling', + 'MountainBike', 'Shaking', 'Singer1', 'Singer2', + 'Skating1', 'Skiing', 'Soccer', 'Subway', 'Suv', + 'Sylvester', 'Tiger1', 'Tiger2', 'Trellis', 'Walking', + 'Walking2', 'Woman'] + + __tb50_seqs = ['Basketball', 'Biker', 'Bird1', 'BlurBody', 'BlurCar2', + 'BlurFace', 'BlurOwl', 'Bolt', 'Box', 'Car1', 'Car4', + 'CarDark', 'CarScale', 'ClifBar', 'Couple', 'Crowds', + 'David', 'Deer', 'Diving', 'DragonBaby', 'Dudek', + 'Football', 'Freeman4', 'Girl', 'Human3', 'Human4', + 'Human6', 'Human9', 'Ironman', 'Jump', 'Jumping', + 'Liquor', 'Matrix', 'MotorRolling', 'Panda', 'RedTeam', + 'Shaking', 'Singer2', 'Skating1', 'Skating2', 'Skiing', + 'Soccer', 'Surfer', 'Sylvester', 'Tiger2', 'Trellis', + 'Walking', 'Walking2', 'Woman'] + + __tb100_seqs = ['Bird2', 'BlurCar1', 'BlurCar3', 'BlurCar4', 'Board', + 'Bolt2', 'Boy', 'Car2', 'Car24', 'Coke', 'Coupon', + 'Crossing', 'Dancer', 'Dancer2', 'David2', 'David3', + 'Dog', 'Dog1', 'Doll', 'FaceOcc1', 'FaceOcc2', 'Fish', + 'FleetFace', 'Football1', 'Freeman1', 'Freeman3', + 'Girl2', 'Gym', 'Human2', 'Human5', 'Human7', 'Human8', + 'Jogging', 'KiteSurf', 'Lemming', 'Man', 'Mhyang', + 'MountainBike', 'Rubik', 'Singer1', 'Skater', + 'Skater2', 'Subway', 'Suv', 'Tiger1', 'Toy', 'Trans', + 'Twinnings', 'Vase'] + __tb50_seqs + + __otb15_seqs = __tb100_seqs + + __version_dict = { + 2013: __otb13_seqs, + 2015: __otb15_seqs, + 'otb2013': __otb13_seqs, + 'otb2015': __otb15_seqs, + 'tb50': __tb50_seqs, + 'tb100': __tb100_seqs} + + def __init__(self, root_dir, version=2015): + super(OTB, self).__init__() + assert version in self.__version_dict + + self.root_dir = root_dir + self.version = version + self._check_integrity(root_dir, version) + valid_seqs = self.__version_dict[version] + self.anno_files = sorted(list(chain.from_iterable(glob.glob( + os.path.join(root_dir, s, 'groundtruth*.txt')) for s in valid_seqs))) + # remove empty annotation files + # (e.g. groundtruth_rect.1.txt of Human4) + self.anno_files = self._filter_files(self.anno_files) + self.seq_dirs = [os.path.dirname(f) for f in self.anno_files] + self.seq_names = [os.path.basename(d) for d in self.seq_dirs] + # rename repeated sequence names + # (e.g. Jogging and Skating2) + self.seq_names = self._rename_seqs(self.seq_names) + + def __getitem__(self, index): + r""" + Args: + index (integer or string): Index or name of a sequence. + + Returns: + tuple: (img_files, anno), where ``img_files`` is a list of + file names and ``anno`` is a N x 4 (rectangles) numpy array. + """ + if isinstance(index, six.string_types): + if not index in self.seq_names: + raise Exception('Sequence {} not found.'.format(index)) + index = self.seq_names.index(index) + + img_files = sorted(glob.glob( + os.path.join(self.seq_dirs[index], 'img/*.jpg'))) + + # special sequences + seq_name = self.seq_names[index] + if seq_name.lower() == 'david': + img_files = img_files[300 - 1:770] + elif seq_name.lower() == 'football1': + img_files = img_files[:74] + elif seq_name.lower() == 'freeman3': + img_files = img_files[:460] + elif seq_name.lower() == 'freeman4': + img_files = img_files[:283] + elif seq_name.lower() == 'diving': + img_files = img_files[:215] + + # to deal with different delimeters + with open(self.anno_files[index], 'r') as f: + anno = np.loadtxt(io.StringIO(f.read().replace(',', ' '))) + assert len(img_files) == len(anno) + assert anno.shape[1] == 4 + + return img_files, anno + + def __len__(self): + return len(self.seq_names) + + def _filter_files(self, filenames): + filtered_files = [] + for filename in filenames: + with open(filename, 'r') as f: + if f.read().strip() == '': + print('Warning: %s is empty.' % filename) + else: + filtered_files.append(filename) + + return filtered_files + + def _rename_seqs(self, seq_names): + # in case some sequences may have multiple targets + renamed_seqs = [] + for i, seq_name in enumerate(seq_names): + if seq_names.count(seq_name) == 1: + renamed_seqs.append(seq_name) + else: + ind = seq_names[:i + 1].count(seq_name) + renamed_seqs.append('%s.%d' % (seq_name, ind)) + + return renamed_seqs + + def _check_integrity(self, root_dir, version): + assert version in self.__version_dict + seq_names = self.__version_dict[version] + + if os.path.isdir(root_dir) and len(os.listdir(root_dir)) > 0: + # check each sequence folder + for seq_name in seq_names: + seq_dir = os.path.join(root_dir, seq_name) + if not os.path.isdir(seq_dir): + print('Warning: sequence %s not exists.' % seq_name) + else: + # dataset not exists + raise Exception('Dataset not found or corrupted. ' + + 'You can use download=True to download it.') + + +class ExperimentOTB(object): + """Experiment pipeline and evaluation toolkit for OTB dataset. + + Args: + root_dir (string): Root directory of OTB dataset. + version (integer or string): Specify the benchmark version, specify as one of + ``2013``, ``2015``, ``tb50`` and ``tb100``. Default is ``2015``. + result_dir (string, optional): Directory for storing tracking + results. Default is ``./results``. + report_dir (string, optional): Directory for storing performance + evaluation results. Default is ``./reports``. + """ + def __init__(self, root_dir, version=2015, + result_dir='results', report_dir='reports'): + super(ExperimentOTB, self).__init__() + self.dataset = OTB(root_dir, version) + self.result_dir = os.path.join(result_dir, 'OTB' + str(version)) + self.report_dir = os.path.join(report_dir, 'OTB' + str(version)) + # as nbins_iou increases, the success score + # converges to the average overlap (AO) + self.nbins_iou = 21 + self.nbins_ce = 51 + + def getlendataset(self): + return len(self.dataset) + + def run(self, savepath, infopath, arch, idx): + # get the seq_name and information of files + img_files, anno = self.dataset[idx] + seq_name = self.dataset.seq_names[idx] + # generate directory for current seq + savepath = savepath + "/" + str(idx) + if not os.path.exists(savepath): + os.makedirs(savepath) + infopath = infopath + "/" + str(idx) + ".info" + # skip if result exist + record_file = os.path.join(self.result_dir, 'siamfc', '%s.txt' % seq_name) + if os.path.exists(record_file): + print('Found results of %s, skipping' % seq_name) + return + frame_num = len(img_files) + boxes = np.zeros((frame_num, 4)) + boxes[0] = anno[0, :] # x,y, w, h + times = np.zeros(frame_num) + + prepostpro = PrePostProcess() + for f, img_file in enumerate(img_files): + img = cv2.imread(img_file, cv2.IMREAD_COLOR) + if f == 0: + # Pre-process and generate bin + exemplar_path = prepostpro.cropexemplar(img, anno[0, :], savepath, img_file) + # get_info + with open(infopath, 'w') as file1: + content = ' '.join([str(0), '.'+exemplar_path, str(127), str(127)]) + file1.write(content) + file1.write('\n') + # infer + os.system('%s -model_type=vision -device_id=%d -batch_size=1 ' + '-om_path=s%/exemplar_bs1.om -input_text_path=%s ' + '-input_width=127 -input_height=127 -output_binary=True -useDvpp=False >/dev/null 2>&1' + % (benchmark_path, deviceid, om_path, infopath)) + # the exemplar has a result of 3*256*6*6 tensor + # read tensor from bin + filename = img_file.replace('/', '-').split('.')[0] + '_1.bin' + filename = 'result/dumpOutput_device' + str(deviceid) + '/' + filename + exemplar_feature = prepostpro.file2tensor(filename, (3, 256, 6, 6)) + else: + # Pre-process and generate bin + search_path = prepostpro.cropsearch(img, savepath, img_file) + # get_info + with open(infopath, 'w') as file2: + content = ' '.join([str(0), '.'+search_path, str(255), str(255)]) + file2.write(content) + file2.write('\n') + # infer + os.system('%s -model_type=vision -device_id=%d -batch_size=1 ' + '-om_path=%s/search_bs1.om -input_text_path=%s ' + '-input_width=255 -input_height=255 -output_binary=True -useDvpp=False >/dev/null 2>&1' + % (benchmark_path, deviceid, om_path, infopath)) + # the exemplar has a result of 1*768*22*22 tensor + # read tensor from bin + filename = img_file.replace('/', '-').split('.')[0] + '_1.bin' + filename = 'result/dumpOutput_device' + str(deviceid) + '/' + filename + search_feature = prepostpro.file2tensor(filename, (1, 768, 22, 22)) + # Post-process + boxes[f, :] = prepostpro.postprocess(search_feature, exemplar_feature) + times[f] = 1 + assert len(boxes) == len(anno) + # record results + self._record(record_file, boxes, times) + # delete useless data to save space + os.system('rm -rf %s/*' % savepath) + print("Results of %s finished!" % seq_name) + + def report(self, tracker_names): + + assert isinstance(tracker_names, (list, tuple)) # ‘SiamFC’ + + # assume tracker_names[0] is your tracker + report_dir = os.path.join(self.report_dir, tracker_names[0]) + + if not os.path.isdir(report_dir): + os.makedirs(report_dir) + + report_file = os.path.join(report_dir, 'performance.json') + + performance = {} + for name in tracker_names: + print('Evaluating', name) + seq_num = len(self.dataset) + succ_curve = np.zeros((seq_num, self.nbins_iou)) + prec_curve = np.zeros((seq_num, self.nbins_ce)) + speeds = np.zeros(seq_num) + # + performance.update({name: {'overall': {}, 'seq_wise': {}}}) + + for s, (_, anno) in enumerate(self.dataset): + + seq_name = self.dataset.seq_names[s] + + record_file = os.path.join(self.result_dir, name, '%s.txt' % seq_name) + + boxes = np.loadtxt(record_file, delimiter=',') + + boxes[0] = anno[0] + + assert len(boxes) == len(anno) + + ious, center_errors = self._calc_metrics(boxes, anno) + + succ_curve[s], prec_curve[s] = self._calc_curves(ious, center_errors) + + # calculate average tracking speed + time_file = os.path.join(self.result_dir, name, 'times/%s_time.txt' % seq_name) + + if os.path.isfile(time_file): + times = np.loadtxt(time_file) + times = times[times > 0] + if len(times) > 0: + speeds[s] = np.mean(1. / times) + # store sequence-wise performance + performance[name]['seq_wise'].update({seq_name: { + 'success_curve': succ_curve[s].tolist(), + 'precision_curve': prec_curve[s].tolist(), + 'success_score': np.mean(succ_curve[s]), + 'precision_score': prec_curve[s][20], + 'success_rate': succ_curve[s][self.nbins_iou // 2], + 'speed_fps': speeds[s] if speeds[s] > 0 else -1}}) + + succ_curve = np.mean(succ_curve, axis=0) + prec_curve = np.mean(prec_curve, axis=0) + succ_score = np.mean(succ_curve) + prec_score = prec_curve[20] + succ_rate = succ_curve[self.nbins_iou // 2] + if np.count_nonzero(speeds) > 0: + avg_speed = np.sum(speeds) / np.count_nonzero(speeds) + else: + avg_speed = -1 + + # store overall performance + performance[name]['overall'].update({ + 'success_curve': succ_curve.tolist(), + 'precision_curve': prec_curve.tolist(), + 'success_score': succ_score, + 'precision_score': prec_score, + 'success_rate': succ_rate, + 'speed_fps': avg_speed}) + # print('prec_score:%s --succ_score:%s --succ_rate:%s' % (prec_score,succ_score,succ_rate)) + # report the performance + with open(report_file, 'w') as f: + json.dump(performance, f, indent=4) + + return prec_score, succ_score, succ_rate + + def _record(self, record_file, boxes, times): + # record bounding boxes + record_dir = os.path.dirname(record_file) + if not os.path.isdir(record_dir): + os.makedirs(record_dir) + np.savetxt(record_file, boxes, fmt='%.3f', delimiter=',') + + # print(' Results recorded at', record_file) + + # record running times + time_dir = os.path.join(record_dir, 'times') + if not os.path.isdir(time_dir): + os.makedirs(time_dir) + time_file = os.path.join(time_dir, os.path.basename( + record_file).replace('.txt', '_time.txt')) + np.savetxt(time_file, times, fmt='%.8f') + + def _calc_metrics(self, boxes, anno): + # can be modified by children classes + ious = rect_iou(boxes, anno) + center_errors = center_error(boxes, anno) + return ious, center_errors + + def _calc_curves(self, ious, center_errors): + ious = np.asarray(ious, float)[:, np.newaxis] + center_errors = np.asarray(center_errors, float)[:, np.newaxis] + + thr_iou = np.linspace(0, 1, self.nbins_iou)[np.newaxis, :] + thr_ce = np.arange(0, self.nbins_ce)[np.newaxis, :] + + bin_iou = np.greater(ious, thr_iou) + bin_ce = np.less_equal(center_errors, thr_ce) + + succ_curve = np.mean(bin_iou, axis=0) + prec_curve = np.mean(bin_ce, axis=0) + + return succ_curve, prec_curve + + +if __name__ == "__main__": + data_path = sys.argv[1] + save_path = sys.argv[2] + info_path = sys.argv[3] + arch = sys.argv[4] + deviceid = int(sys.argv[5]) + benchmark_path = sys.argv[6] + om_path = sys.argv[7] + os.system('rm -rf %s' % save_path) + os.system('rm -rf %s' % info_path) + os.system('rm -rf ./result/dumpOutput_device%d' % deviceid) + if not os.path.exists(save_path): + os.makedirs(save_path) + if not os.path.exists(info_path): + os.makedirs(info_path) + e = ExperimentOTB(data_path, version=2015) + totallen = e.getlendataset() + pool = multiprocessing.Pool(processes=12) + for i in range(totallen): + pool.apply_async(e.run, (save_path, info_path, arch, i, )) + pool.close() + pool.join() + prec_score, succ_score, succ_rate = e.report(['siamfc']) + ss = '-prec_score:%.3f -succ_score:%.3f -succ_rate:%.3f' % (float(prec_score), float(succ_score), float(succ_rate)) + print("====accuracy data====") + print(ss) diff --git a/ACL_PyTorch/contrib/cv/tracking/SiamRPN/LICENSE b/ACL_PyTorch/contrib/cv/tracking/SiamRPN/LICENSE index 29f81d812f3e768fa89638d1f72920dbfd1413a8..261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64 100644 --- a/ACL_PyTorch/contrib/cv/tracking/SiamRPN/LICENSE +++ b/ACL_PyTorch/contrib/cv/tracking/SiamRPN/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ACL_PyTorch/contrib/cv/tracking/SiamRPN/README.md b/ACL_PyTorch/contrib/cv/tracking/SiamRPN/README.md index 2b0cca569975219f45f738c6f7587ee46b29702d..ec84757b746a1e8cc7109dd9c3f43345196f9e40 100644 --- a/ACL_PyTorch/contrib/cv/tracking/SiamRPN/README.md +++ b/ACL_PyTorch/contrib/cv/tracking/SiamRPN/README.md @@ -1,97 +1,97 @@ -# SiamRPN模型PyTorch推理指导 - -## 1 环境准备 -1. 获取开源代码仓 -- 得到本项目代码后,将 SiamRPN 项目放置在/home目录下,进入/home/SiamRPN目录下,下载开源代码仓 -``` -git clone https://github.com/STVIR/pysot.git -``` - -- 确认获取的开源 pysot 项目文件存放在 /home/SiamRPN 目录下,进入 /home/SiamRPN/pysot 目录下执行 -``` -patch -N -p1 < ../SiamRPN.patch -``` - -2. 获取数据集 -- 将数据集VOT2016下载并放在 /root/datasets 目录下 -``` -wget -P /root/datasets https://ascend-pytorch-one-datasets.obs.cn-north-4.myhuaweicloud.com/train/zip/VOT2016.zip -cd // -cd /root/datasets -unzip VOT2016.zip -rm -rf VOT2016.zip -``` -- (备注:将获取的 VOT2016 数据集文件放在 /root/datasets 目录下) - - -3. 安装依赖 -- 进入 /home/SiamRPN 目录下 -```shell -cd // -cd /home/SiamRPN -pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com -``` -- (备注:若有安装失败的请单独重新安装,若有需要,也可使用conda指令安装) - -4. 获取pth权重文件 - -``` -wget -P /home/SiamRPN/pysot/experiments/siamrpn_r50_l234_dwxcorr https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/tracking/SiamRPN/model.pth -``` - -- (备注:将 model.pth 权重文件要放在 ../siamrpn_r50_l234_dwxcorr 目录下) - -5. 运行setup.py -- 进入 /home/SiamRPN/pysot 目录下执行 -``` -export PYTHONPATH=/home/SiamRPN/pysot:$PYTHONPATH -python setup.py build_ext --inplace install -``` - - - -## 2 离线推理 - -310上执行,执行时使用 npu-smi info 查看设备状态,确保device空闲 - -```shell -# (j进入 /home/SiamRPN 下执行) -# 转成onnx -bash test/pth2onnx.sh -# 转成om -bash test/onnx2om.sh -# 进行评估 -bash test/eval_acc_perf.sh -``` - - -- 评测结果: - -- 310精度 -``` ------------------------------------------------------------- -|Tracker Name| Accuracy | Robustness | Average | EAO | ------------------------------------------------------------- -| VOT2016 | 0.639 | 0.177 | 42fps | 0.483 | ------------------------------------------------------------- -``` - -- 参考pth精度 -``` ------------------------------------------------------------- -|Tracker Name| Accuracy | Robustness | Average | EAO | ------------------------------------------------------------- -| VOT2016 | 0.642 | 0.196 | 35fps | 0.464 | ------------------------------------------------------------- -``` - - -- 性能计算方式: - fps计算方式为单位时间内处理的图片数量,即 图片数量 / 时间 。 - 根据310单device需乘以4之后再和T4对比,故310单卡性能理论计算为42×4=168fps。 - -- 备注: -- (1) 310精度相较于T4下降0.3%,但鲁棒性和EAO均有提升。310单device的实际平均性能为42fps。T4单卡平均性能为35fps,由于运行场景等干扰因素不同,会导致结果有所浮动,35fps为多次测量后平均近似值,供参考。 -- (2) 性能数据(speed)在推理过程中会展示,在推理结束后会展示平均性能(average speed)。 -- (3) 本推理为视频追踪,输入对象为视频,故不设置多batch。 - +# SiamRPN模型PyTorch推理指导 + +## 1 环境准备 +1. 获取开源代码仓 +- 得到本项目代码后,将 SiamRPN 项目放置在/home目录下,进入/home/SiamRPN目录下,下载开源代码仓 +``` +git clone https://github.com/STVIR/pysot.git +``` + +- 确认获取的开源 pysot 项目文件存放在 /home/SiamRPN 目录下,进入 /home/SiamRPN/pysot 目录下执行 +``` +patch -N -p1 < ../SiamRPN.patch +``` + +2. 获取数据集 +- 将数据集VOT2016下载并放在 /root/datasets 目录下 +``` +wget -P /root/datasets https://ascend-pytorch-one-datasets.obs.cn-north-4.myhuaweicloud.com/train/zip/VOT2016.zip +cd // +cd /root/datasets +unzip VOT2016.zip +rm -rf VOT2016.zip +``` +- (备注:将获取的 VOT2016 数据集文件放在 /root/datasets 目录下) + + +3. 安装依赖 +- 进入 /home/SiamRPN 目录下 +```shell +cd // +cd /home/SiamRPN +pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com +``` +- (备注:若有安装失败的请单独重新安装,若有需要,也可使用conda指令安装) + +4. 获取pth权重文件 + +``` +wget -P /home/SiamRPN/pysot/experiments/siamrpn_r50_l234_dwxcorr https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/tracking/SiamRPN/model.pth +``` + +- (备注:将 model.pth 权重文件要放在 ../siamrpn_r50_l234_dwxcorr 目录下) + +5. 运行setup.py +- 进入 /home/SiamRPN/pysot 目录下执行 +``` +export PYTHONPATH=/home/SiamRPN/pysot:$PYTHONPATH +python setup.py build_ext --inplace install +``` + + + +## 2 离线推理 + +310上执行,执行时使用 npu-smi info 查看设备状态,确保device空闲 + +```shell +# (j进入 /home/SiamRPN 下执行) +# 转成onnx +bash test/pth2onnx.sh +# 转成om +bash test/onnx2om.sh +# 进行评估 +bash test/eval_acc_perf.sh +``` + + +- 评测结果: + +- 310精度 +``` +------------------------------------------------------------ +|Tracker Name| Accuracy | Robustness | Average | EAO | +------------------------------------------------------------ +| VOT2016 | 0.639 | 0.177 | 42fps | 0.483 | +------------------------------------------------------------ +``` + +- 参考pth精度 +``` +------------------------------------------------------------ +|Tracker Name| Accuracy | Robustness | Average | EAO | +------------------------------------------------------------ +| VOT2016 | 0.642 | 0.196 | 35fps | 0.464 | +------------------------------------------------------------ +``` + + +- 性能计算方式: + fps计算方式为单位时间内处理的图片数量,即 图片数量 / 时间 。 + 根据310单device需乘以4之后再和T4对比,故310单卡性能理论计算为42×4=168fps。 + +- 备注: +- (1) 310精度相较于T4下降0.3%,但鲁棒性和EAO均有提升。310单device的实际平均性能为42fps。T4单卡平均性能为35fps,由于运行场景等干扰因素不同,会导致结果有所浮动,35fps为多次测量后平均近似值,供参考。 +- (2) 性能数据(speed)在推理过程中会展示,在推理结束后会展示平均性能(average speed)。 +- (3) 本推理为视频追踪,输入对象为视频,故不设置多batch。 + diff --git a/ACL_PyTorch/contrib/cv/tracking/SiamRPN/acl_net.py b/ACL_PyTorch/contrib/cv/tracking/SiamRPN/acl_net.py index a8c13f1e6550ee8749513fb183d1e1e707d36a1e..553c6d59792972787eaf4fc129099b9f150f141e 100644 --- a/ACL_PyTorch/contrib/cv/tracking/SiamRPN/acl_net.py +++ b/ACL_PyTorch/contrib/cv/tracking/SiamRPN/acl_net.py @@ -1,246 +1,246 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import numpy as np -import acl -import functools - -# error code -ACL_ERROR_NONE = 0 - -# memory malloc code -ACL_MEM_MALLOC_HUGE_FIRST = 0 -ACL_MEM_MALLOC_HUGE_ONLY = 1 -ACL_MEM_MALLOC_NORMAL_ONLY = 2 - -# memory copy code -ACL_MEMCPY_HOST_TO_HOST = 0 -ACL_MEMCPY_HOST_TO_DEVICE = 1 -ACL_MEMCPY_DEVICE_TO_HOST = 2 -ACL_MEMCPY_DEVICE_TO_DEVICE = 3 - -ACL_DTYPE = { - 0: 'float32', - 1: 'float16', - 2: 'int8', - 3: 'int32', - 4: 'uint8', - 6: 'int16', - 7: 'uint16', - 8: 'uint32', - 9: 'int64', - 10: 'uint64', - 11: 'float64', - 12: 'bool', -} - -buffer_method = { - "in": acl.mdl.get_input_size_by_index, - "out": acl.mdl.get_output_size_by_index, - "outhost": acl.mdl.get_output_size_by_index -} - - -def check_ret(message, ret): - if ret != ACL_ERROR_NONE: - raise Exception("{} failed ret = {}".format(message, ret)) - - -class Net(object): - def __init__(self, context, model_path, device_id=0, first=True, config_path=None): - self.device_id = device_id - self.model_path = model_path - self.model_id = None - self.context = context - - self.input_data = [] - self.output_data = [] - self.output_data_host = [] - self.model_desc = None - self.load_input_dataset = None - self.load_output_dataset = None - - self._init_resource(first, config_path) - - def __call__(self, ori_data): - return self.forward(ori_data) - - def __del__(self): - ret = acl.mdl.unload(self.model_id) - check_ret("acl.mdl.unload", ret) - if self.model_desc: - acl.mdl.destroy_desc(self.model_desc) - self.model_desc = None - - while self.input_data: - item = self.input_data.pop() - ret = acl.rt.free(item["buffer"]) - check_ret("acl.rt.free", ret) - - while self.output_data: - item = self.output_data.pop() - ret = acl.rt.free(item["buffer"]) - check_ret("acl.rt.free", ret) - - def _init_resource(self, first=False, config_path=None): - # load_model - self.model_id, ret = acl.mdl.load_from_file(self.model_path) - check_ret("acl.mdl.load_from_file", ret) - - self.model_desc = acl.mdl.create_desc() - self._get_model_info() - - def _get_model_info(self, ): - ret = acl.mdl.get_desc(self.model_desc, self.model_id) - check_ret("acl.mdl.get_desc", ret) - input_size = acl.mdl.get_num_inputs(self.model_desc) - output_size = acl.mdl.get_num_outputs(self.model_desc) - self._gen_data_buffer(input_size, des="in") - self._gen_data_buffer(output_size, des="out") - self._gen_dataset_output_host(output_size, des="outhost") - - def _gen_data_buffer(self, size, des): - func = buffer_method[des] - for i in range(size): - temp_buffer_size = func(self.model_desc, i) - temp_buffer, ret = acl.rt.malloc( - temp_buffer_size, ACL_MEM_MALLOC_HUGE_FIRST) - check_ret("acl.rt.malloc", ret) - - if des == "in": - self.input_data.append({"buffer": temp_buffer, - "size": temp_buffer_size}) - elif des == "out": - self.output_data.append({"buffer": temp_buffer, - "size": temp_buffer_size}) - - def _gen_dataset_output_host(self, size, des): - func = buffer_method[des] - for i in range(size): - temp_buffer_size = func(self.model_desc, i) - temp_buffer, ret = acl.rt.malloc_host(temp_buffer_size) - check_ret("acl.rt.malloc_host", ret) - - self.output_data_host.append({"buffer": temp_buffer, - "size": temp_buffer_size}) - - def _data_interaction(self, dataset, policy=ACL_MEMCPY_HOST_TO_DEVICE): - temp_data_buffer = self.input_data \ - if policy == ACL_MEMCPY_HOST_TO_DEVICE \ - else self.output_data - output_malloc_cost = 0 - idx = 0 - - if len(dataset) == 0 and policy == ACL_MEMCPY_DEVICE_TO_HOST: - dataset = self.output_data_host - - for i, item in enumerate(temp_data_buffer): - if policy == ACL_MEMCPY_HOST_TO_DEVICE: - if 'bytes_to_ptr' in dir(acl.util): - bytes_in = dataset[i].tobytes() - ptr = acl.util.bytes_to_ptr(bytes_in) - else: - ptr = acl.util.numpy_to_ptr(dataset[i]) - ret = acl.rt.memcpy(item["buffer"], item["size"], ptr, item["size"], policy) - check_ret("acl.rt.memcpy", ret) - - else: - ptr = dataset[i]["buffer"] - ret = acl.rt.memcpy( - ptr, item["size"], item["buffer"], item["size"], policy) - check_ret("acl.rt.memcpy", ret) - - def _gen_dataset(self, type_str="input"): - dataset = acl.mdl.create_dataset() - - temp_dataset = None - if type_str == "in": - self.load_input_dataset = dataset - temp_dataset = self.input_data - else: - self.load_output_dataset = dataset - temp_dataset = self.output_data - - for item in temp_dataset: - data = acl.create_data_buffer(item["buffer"], item["size"]) - if data is None: - ret = acl.destroy_data_buffer(dataset) - check_ret("acl.destroy_data_buffer", ret) - - _, ret = acl.mdl.add_dataset_buffer(dataset, data) - if ret != ACL_ERROR_NONE: - ret = acl.destroy_data_buffer(dataset) - check_ret("acl.destroy_data_buffer", ret) - - def _data_from_host_to_device(self, images): - self._data_interaction(images, ACL_MEMCPY_HOST_TO_DEVICE) - self._gen_dataset("in") - self._gen_dataset("out") - - def _data_from_device_to_host(self): - res = [] - self._data_interaction(res, ACL_MEMCPY_DEVICE_TO_HOST) - output = self.get_result(self.output_data_host) - return output - - def _destroy_databuffer(self): - for dataset in [self.load_input_dataset, self.load_output_dataset]: - if not dataset: - continue - - num = acl.mdl.get_dataset_num_buffers(dataset) - for i in range(num): - data_buf = acl.mdl.get_dataset_buffer(dataset, i) - if data_buf: - ret = acl.destroy_data_buffer(data_buf) - check_ret("acl.destroy_data_buffer", ret) - ret = acl.mdl.destroy_dataset(dataset) - check_ret("acl.mdl.destroy_dataset", ret) - - def forward(self, input_data): - if not isinstance(input_data, (list, tuple)): - input_data = [input_data] - - self._data_from_host_to_device(input_data) - ret = acl.mdl.execute( - self.model_id, self.load_input_dataset, self.load_output_dataset) - check_ret("acl.mdl.execute", ret) - - self._destroy_databuffer() - result = self._data_from_device_to_host() - return result - - def get_result(self, output_data): - dataset = [] - for i in range(len(output_data)): - dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) - check_ret("acl.mdl.get_cur_output_dims", ret) - - data_shape = dims.get("dims") - data_type = acl.mdl.get_output_data_type(self.model_desc, i) - data_len = functools.reduce(lambda x, y: x * y, data_shape) - ftype = np.dtype(ACL_DTYPE.get(data_type)) - - size = output_data[i]["size"] - ptr = output_data[i]["buffer"] - if 'ptr_to_bytes' in dir(acl.util): - data = acl.util.ptr_to_bytes(ptr, size) - np_arr = np.frombuffer(data, dtype=ftype, count=data_len) - else: - data = acl.util.ptr_to_numpy(ptr, (size,), 1) - np_arr = np.frombuffer( - bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) - np_arr = np_arr.reshape(data_shape) - dataset.append(np_arr) - return dataset +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +import acl +import functools + +# error code +ACL_ERROR_NONE = 0 + +# memory malloc code +ACL_MEM_MALLOC_HUGE_FIRST = 0 +ACL_MEM_MALLOC_HUGE_ONLY = 1 +ACL_MEM_MALLOC_NORMAL_ONLY = 2 + +# memory copy code +ACL_MEMCPY_HOST_TO_HOST = 0 +ACL_MEMCPY_HOST_TO_DEVICE = 1 +ACL_MEMCPY_DEVICE_TO_HOST = 2 +ACL_MEMCPY_DEVICE_TO_DEVICE = 3 + +ACL_DTYPE = { + 0: 'float32', + 1: 'float16', + 2: 'int8', + 3: 'int32', + 4: 'uint8', + 6: 'int16', + 7: 'uint16', + 8: 'uint32', + 9: 'int64', + 10: 'uint64', + 11: 'float64', + 12: 'bool', +} + +buffer_method = { + "in": acl.mdl.get_input_size_by_index, + "out": acl.mdl.get_output_size_by_index, + "outhost": acl.mdl.get_output_size_by_index +} + + +def check_ret(message, ret): + if ret != ACL_ERROR_NONE: + raise Exception("{} failed ret = {}".format(message, ret)) + + +class Net(object): + def __init__(self, context, model_path, device_id=0, first=True, config_path=None): + self.device_id = device_id + self.model_path = model_path + self.model_id = None + self.context = context + + self.input_data = [] + self.output_data = [] + self.output_data_host = [] + self.model_desc = None + self.load_input_dataset = None + self.load_output_dataset = None + + self._init_resource(first, config_path) + + def __call__(self, ori_data): + return self.forward(ori_data) + + def __del__(self): + ret = acl.mdl.unload(self.model_id) + check_ret("acl.mdl.unload", ret) + if self.model_desc: + acl.mdl.destroy_desc(self.model_desc) + self.model_desc = None + + while self.input_data: + item = self.input_data.pop() + ret = acl.rt.free(item["buffer"]) + check_ret("acl.rt.free", ret) + + while self.output_data: + item = self.output_data.pop() + ret = acl.rt.free(item["buffer"]) + check_ret("acl.rt.free", ret) + + def _init_resource(self, first=False, config_path=None): + # load_model + self.model_id, ret = acl.mdl.load_from_file(self.model_path) + check_ret("acl.mdl.load_from_file", ret) + + self.model_desc = acl.mdl.create_desc() + self._get_model_info() + + def _get_model_info(self, ): + ret = acl.mdl.get_desc(self.model_desc, self.model_id) + check_ret("acl.mdl.get_desc", ret) + input_size = acl.mdl.get_num_inputs(self.model_desc) + output_size = acl.mdl.get_num_outputs(self.model_desc) + self._gen_data_buffer(input_size, des="in") + self._gen_data_buffer(output_size, des="out") + self._gen_dataset_output_host(output_size, des="outhost") + + def _gen_data_buffer(self, size, des): + func = buffer_method[des] + for i in range(size): + temp_buffer_size = func(self.model_desc, i) + temp_buffer, ret = acl.rt.malloc( + temp_buffer_size, ACL_MEM_MALLOC_HUGE_FIRST) + check_ret("acl.rt.malloc", ret) + + if des == "in": + self.input_data.append({"buffer": temp_buffer, + "size": temp_buffer_size}) + elif des == "out": + self.output_data.append({"buffer": temp_buffer, + "size": temp_buffer_size}) + + def _gen_dataset_output_host(self, size, des): + func = buffer_method[des] + for i in range(size): + temp_buffer_size = func(self.model_desc, i) + temp_buffer, ret = acl.rt.malloc_host(temp_buffer_size) + check_ret("acl.rt.malloc_host", ret) + + self.output_data_host.append({"buffer": temp_buffer, + "size": temp_buffer_size}) + + def _data_interaction(self, dataset, policy=ACL_MEMCPY_HOST_TO_DEVICE): + temp_data_buffer = self.input_data \ + if policy == ACL_MEMCPY_HOST_TO_DEVICE \ + else self.output_data + output_malloc_cost = 0 + idx = 0 + + if len(dataset) == 0 and policy == ACL_MEMCPY_DEVICE_TO_HOST: + dataset = self.output_data_host + + for i, item in enumerate(temp_data_buffer): + if policy == ACL_MEMCPY_HOST_TO_DEVICE: + if 'bytes_to_ptr' in dir(acl.util): + bytes_in = dataset[i].tobytes() + ptr = acl.util.bytes_to_ptr(bytes_in) + else: + ptr = acl.util.numpy_to_ptr(dataset[i]) + ret = acl.rt.memcpy(item["buffer"], item["size"], ptr, item["size"], policy) + check_ret("acl.rt.memcpy", ret) + + else: + ptr = dataset[i]["buffer"] + ret = acl.rt.memcpy( + ptr, item["size"], item["buffer"], item["size"], policy) + check_ret("acl.rt.memcpy", ret) + + def _gen_dataset(self, type_str="input"): + dataset = acl.mdl.create_dataset() + + temp_dataset = None + if type_str == "in": + self.load_input_dataset = dataset + temp_dataset = self.input_data + else: + self.load_output_dataset = dataset + temp_dataset = self.output_data + + for item in temp_dataset: + data = acl.create_data_buffer(item["buffer"], item["size"]) + if data is None: + ret = acl.destroy_data_buffer(dataset) + check_ret("acl.destroy_data_buffer", ret) + + _, ret = acl.mdl.add_dataset_buffer(dataset, data) + if ret != ACL_ERROR_NONE: + ret = acl.destroy_data_buffer(dataset) + check_ret("acl.destroy_data_buffer", ret) + + def _data_from_host_to_device(self, images): + self._data_interaction(images, ACL_MEMCPY_HOST_TO_DEVICE) + self._gen_dataset("in") + self._gen_dataset("out") + + def _data_from_device_to_host(self): + res = [] + self._data_interaction(res, ACL_MEMCPY_DEVICE_TO_HOST) + output = self.get_result(self.output_data_host) + return output + + def _destroy_databuffer(self): + for dataset in [self.load_input_dataset, self.load_output_dataset]: + if not dataset: + continue + + num = acl.mdl.get_dataset_num_buffers(dataset) + for i in range(num): + data_buf = acl.mdl.get_dataset_buffer(dataset, i) + if data_buf: + ret = acl.destroy_data_buffer(data_buf) + check_ret("acl.destroy_data_buffer", ret) + ret = acl.mdl.destroy_dataset(dataset) + check_ret("acl.mdl.destroy_dataset", ret) + + def forward(self, input_data): + if not isinstance(input_data, (list, tuple)): + input_data = [input_data] + + self._data_from_host_to_device(input_data) + ret = acl.mdl.execute( + self.model_id, self.load_input_dataset, self.load_output_dataset) + check_ret("acl.mdl.execute", ret) + + self._destroy_databuffer() + result = self._data_from_device_to_host() + return result + + def get_result(self, output_data): + dataset = [] + for i in range(len(output_data)): + dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) + check_ret("acl.mdl.get_cur_output_dims", ret) + + data_shape = dims.get("dims") + data_type = acl.mdl.get_output_data_type(self.model_desc, i) + data_len = functools.reduce(lambda x, y: x * y, data_shape) + ftype = np.dtype(ACL_DTYPE.get(data_type)) + + size = output_data[i]["size"] + ptr = output_data[i]["buffer"] + if 'ptr_to_bytes' in dir(acl.util): + data = acl.util.ptr_to_bytes(ptr, size) + np_arr = np.frombuffer(data, dtype=ftype, count=data_len) + else: + data = acl.util.ptr_to_numpy(ptr, (size,), 1) + np_arr = np.frombuffer( + bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) + np_arr = np_arr.reshape(data_shape) + dataset.append(np_arr) + return dataset diff --git a/ACL_PyTorch/contrib/cv/tracking/SiamRPN/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/tracking/SiamRPN/modelzoo_level.txt index d44ba5698b045b8a30e107962f295dbc24585d8c..70801afc42b6d9eb5cdd98b5430d9b2101f3146a 100644 --- a/ACL_PyTorch/contrib/cv/tracking/SiamRPN/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/tracking/SiamRPN/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/video_understanding/I3D/acl_net.py b/ACL_PyTorch/contrib/cv/video_understanding/I3D/acl_net.py index 53a7a20709fbefb82c836090ee4858bbafa3db57..215edad60200962ca69664934d929c43d7a0914b 100644 --- a/ACL_PyTorch/contrib/cv/video_understanding/I3D/acl_net.py +++ b/ACL_PyTorch/contrib/cv/video_understanding/I3D/acl_net.py @@ -1,253 +1,253 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import numpy as np -import acl -import functools - -# error code -ACL_ERROR_NONE = 0 - -# memory malloc code -ACL_MEM_MALLOC_HUGE_FIRST = 0 -ACL_MEM_MALLOC_HUGE_ONLY = 1 -ACL_MEM_MALLOC_NORMAL_ONLY = 2 - -# memory copy code -ACL_MEMCPY_HOST_TO_HOST = 0 -ACL_MEMCPY_HOST_TO_DEVICE = 1 -ACL_MEMCPY_DEVICE_TO_HOST = 2 -ACL_MEMCPY_DEVICE_TO_DEVICE = 3 - -ACL_DTYPE = { - 0: 'float32', - 1: 'float16', - 2: 'int8', - 3: 'int32', - 4: 'uint8', - 6: 'int16', - 7: 'uint16', - 8: 'uint32', - 9: 'int64', - 10: 'uint64', - 11: 'float64', - 12: 'bool', -} - -buffer_method = { - "in": acl.mdl.get_input_size_by_index, - "out": acl.mdl.get_output_size_by_index, - "outhost": acl.mdl.get_output_size_by_index -} - -def check_ret(message, ret): - if ret != ACL_ERROR_NONE: - raise Exception("{} failed ret = {}".format(message, ret)) - - -class Net(object): - def __init__(self, context, model_path, device_id=0, first=True, config_path=None): - self.device_id = device_id - self.model_path = model_path - self.model_id = None - self.context = context - - self.input_data = [] - self.output_data = [] - self.output_data_host = [] - self.model_desc = None - self.load_input_dataset = None - self.load_output_dataset = None - - self._init_resource(first, config_path) - - - def __call__(self, ori_data): - return self.forward(ori_data) - - - def __del__(self): - ret = acl.mdl.unload(self.model_id) - check_ret("acl.mdl.unload", ret) - if self.model_desc: - acl.mdl.destroy_desc(self.model_desc) - self.model_desc = None - - while self.input_data: - item = self.input_data.pop() - ret = acl.rt.free(item["buffer"]) - check_ret("acl.rt.free", ret) - - while self.output_data: - item = self.output_data.pop() - ret = acl.rt.free(item["buffer"]) - check_ret("acl.rt.free", ret) - - - def _init_resource(self, first=False, config_path=None): - # load_model - self.model_id, ret = acl.mdl.load_from_file(self.model_path) - check_ret("acl.mdl.load_from_file", ret) - - self.model_desc = acl.mdl.create_desc() - self._get_model_info() - - - def _get_model_info(self,): - ret = acl.mdl.get_desc(self.model_desc, self.model_id) - check_ret("acl.mdl.get_desc", ret) - input_size = acl.mdl.get_num_inputs(self.model_desc) - output_size = acl.mdl.get_num_outputs(self.model_desc) - self._gen_data_buffer(input_size, des="in") - self._gen_data_buffer(output_size, des="out") - self._gen_dataset_output_host(output_size, des="outhost") - - - def _gen_data_buffer(self, size, des): - func = buffer_method[des] - for i in range(size): - temp_buffer_size = func(self.model_desc, i) - temp_buffer, ret = acl.rt.malloc(temp_buffer_size, ACL_MEM_MALLOC_HUGE_FIRST) - check_ret("acl.rt.malloc", ret) - - if des == "in": - self.input_data.append({"buffer": temp_buffer, - "size": temp_buffer_size}) - elif des == "out": - self.output_data.append({"buffer": temp_buffer, - "size": temp_buffer_size}) - - - def _gen_dataset_output_host(self, size, des): - func = buffer_method[des] - for i in range(size): - temp_buffer_size = func(self.model_desc, i) - temp_buffer, ret = acl.rt.malloc_host(temp_buffer_size) - check_ret("acl.rt.malloc_host", ret) - - self.output_data_host.append({"buffer": temp_buffer, - "size": temp_buffer_size}) - - - def _data_interaction(self, dataset, policy=ACL_MEMCPY_HOST_TO_DEVICE): - temp_data_buffer = self.input_data \ - if policy == ACL_MEMCPY_HOST_TO_DEVICE \ - else self.output_data - output_malloc_cost = 0 - idx = 0 - - if len(dataset) == 0 and policy == ACL_MEMCPY_DEVICE_TO_HOST: - dataset = self.output_data_host - - for i, item in enumerate(temp_data_buffer): - if policy == ACL_MEMCPY_HOST_TO_DEVICE: - if 'bytes_to_ptr' in dir(acl.util): - bytes_in = dataset[i].tobytes() - ptr = acl.util.bytes_to_ptr(bytes_in) - else: - ptr = acl.util.numpy_to_ptr(dataset[i]) - ret = acl.rt.memcpy(item["buffer"], item["size"], ptr, item["size"], policy) - check_ret("acl.rt.memcpy", ret) - - else: - ptr = dataset[i]["buffer"] - ret = acl.rt.memcpy(ptr, item["size"], item["buffer"], item["size"], policy) - check_ret("acl.rt.memcpy", ret) - - - def _gen_dataset(self, type_str="input"): - dataset = acl.mdl.create_dataset() - - temp_dataset = None - if type_str == "in": - self.load_input_dataset = dataset - temp_dataset = self.input_data - else: - self.load_output_dataset = dataset - temp_dataset = self.output_data - - for item in temp_dataset: - data = acl.create_data_buffer(item["buffer"], item["size"]) - if data is None: - ret = acl.destroy_data_buffer(dataset) - check_ret("acl.destroy_data_buffer", ret) - - _, ret = acl.mdl.add_dataset_buffer(dataset, data) - if ret != ACL_ERROR_NONE: - ret = acl.destroy_data_buffer(dataset) - check_ret("acl.destroy_data_buffer", ret) - - - def _data_from_host_to_device(self, images): - self._data_interaction(images, ACL_MEMCPY_HOST_TO_DEVICE) - self._gen_dataset("in") - self._gen_dataset("out") - - - def _data_from_device_to_host(self): - res = [] - self._data_interaction(res, ACL_MEMCPY_DEVICE_TO_HOST) - output = self.get_result(self.output_data_host) - return output - - - def _destroy_databuffer(self): - for dataset in [self.load_input_dataset, self.load_output_dataset]: - if not dataset: - continue - - num = acl.mdl.get_dataset_num_buffers(dataset) - for i in range(num): - data_buf = acl.mdl.get_dataset_buffer(dataset, i) - if data_buf: - ret = acl.destroy_data_buffer(data_buf) - check_ret("acl.destroy_data_buffer", ret) - ret = acl.mdl.destroy_dataset(dataset) - check_ret("acl.mdl.destroy_dataset", ret) - - def forward(self, input_data): - if not isinstance(input_data, (list, tuple)): - input_data = [input_data] - - self._data_from_host_to_device(input_data) - ret = acl.mdl.execute(self.model_id, self.load_input_dataset, self.load_output_dataset) - check_ret("acl.mdl.execute", ret) - - self._destroy_databuffer() - result = self._data_from_device_to_host() - return result - - - def get_result(self, output_data): - dataset = [] - for i in range(len(output_data)): - dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) - check_ret("acl.mdl.get_cur_output_dims", ret) - - data_shape = dims.get("dims") - data_type = acl.mdl.get_output_data_type(self.model_desc, i) - data_len = functools.reduce(lambda x, y: x * y, data_shape) - ftype = np.dtype(ACL_DTYPE.get(data_type)) - - size = output_data[i]["size"] - ptr = output_data[i]["buffer"] - if 'ptr_to_bytes' in dir(acl.util): - data = acl.util.ptr_to_bytes(ptr, size) - np_arr = np.frombuffer(data, dtype=ftype, count=data_len) - else: - data = acl.util.ptr_to_numpy(ptr, (size,), 1) - np_arr = np.frombuffer(bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) - np_arr = np_arr.reshape(data_shape) - dataset.append(np_arr) - return dataset +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +import acl +import functools + +# error code +ACL_ERROR_NONE = 0 + +# memory malloc code +ACL_MEM_MALLOC_HUGE_FIRST = 0 +ACL_MEM_MALLOC_HUGE_ONLY = 1 +ACL_MEM_MALLOC_NORMAL_ONLY = 2 + +# memory copy code +ACL_MEMCPY_HOST_TO_HOST = 0 +ACL_MEMCPY_HOST_TO_DEVICE = 1 +ACL_MEMCPY_DEVICE_TO_HOST = 2 +ACL_MEMCPY_DEVICE_TO_DEVICE = 3 + +ACL_DTYPE = { + 0: 'float32', + 1: 'float16', + 2: 'int8', + 3: 'int32', + 4: 'uint8', + 6: 'int16', + 7: 'uint16', + 8: 'uint32', + 9: 'int64', + 10: 'uint64', + 11: 'float64', + 12: 'bool', +} + +buffer_method = { + "in": acl.mdl.get_input_size_by_index, + "out": acl.mdl.get_output_size_by_index, + "outhost": acl.mdl.get_output_size_by_index +} + +def check_ret(message, ret): + if ret != ACL_ERROR_NONE: + raise Exception("{} failed ret = {}".format(message, ret)) + + +class Net(object): + def __init__(self, context, model_path, device_id=0, first=True, config_path=None): + self.device_id = device_id + self.model_path = model_path + self.model_id = None + self.context = context + + self.input_data = [] + self.output_data = [] + self.output_data_host = [] + self.model_desc = None + self.load_input_dataset = None + self.load_output_dataset = None + + self._init_resource(first, config_path) + + + def __call__(self, ori_data): + return self.forward(ori_data) + + + def __del__(self): + ret = acl.mdl.unload(self.model_id) + check_ret("acl.mdl.unload", ret) + if self.model_desc: + acl.mdl.destroy_desc(self.model_desc) + self.model_desc = None + + while self.input_data: + item = self.input_data.pop() + ret = acl.rt.free(item["buffer"]) + check_ret("acl.rt.free", ret) + + while self.output_data: + item = self.output_data.pop() + ret = acl.rt.free(item["buffer"]) + check_ret("acl.rt.free", ret) + + + def _init_resource(self, first=False, config_path=None): + # load_model + self.model_id, ret = acl.mdl.load_from_file(self.model_path) + check_ret("acl.mdl.load_from_file", ret) + + self.model_desc = acl.mdl.create_desc() + self._get_model_info() + + + def _get_model_info(self,): + ret = acl.mdl.get_desc(self.model_desc, self.model_id) + check_ret("acl.mdl.get_desc", ret) + input_size = acl.mdl.get_num_inputs(self.model_desc) + output_size = acl.mdl.get_num_outputs(self.model_desc) + self._gen_data_buffer(input_size, des="in") + self._gen_data_buffer(output_size, des="out") + self._gen_dataset_output_host(output_size, des="outhost") + + + def _gen_data_buffer(self, size, des): + func = buffer_method[des] + for i in range(size): + temp_buffer_size = func(self.model_desc, i) + temp_buffer, ret = acl.rt.malloc(temp_buffer_size, ACL_MEM_MALLOC_HUGE_FIRST) + check_ret("acl.rt.malloc", ret) + + if des == "in": + self.input_data.append({"buffer": temp_buffer, + "size": temp_buffer_size}) + elif des == "out": + self.output_data.append({"buffer": temp_buffer, + "size": temp_buffer_size}) + + + def _gen_dataset_output_host(self, size, des): + func = buffer_method[des] + for i in range(size): + temp_buffer_size = func(self.model_desc, i) + temp_buffer, ret = acl.rt.malloc_host(temp_buffer_size) + check_ret("acl.rt.malloc_host", ret) + + self.output_data_host.append({"buffer": temp_buffer, + "size": temp_buffer_size}) + + + def _data_interaction(self, dataset, policy=ACL_MEMCPY_HOST_TO_DEVICE): + temp_data_buffer = self.input_data \ + if policy == ACL_MEMCPY_HOST_TO_DEVICE \ + else self.output_data + output_malloc_cost = 0 + idx = 0 + + if len(dataset) == 0 and policy == ACL_MEMCPY_DEVICE_TO_HOST: + dataset = self.output_data_host + + for i, item in enumerate(temp_data_buffer): + if policy == ACL_MEMCPY_HOST_TO_DEVICE: + if 'bytes_to_ptr' in dir(acl.util): + bytes_in = dataset[i].tobytes() + ptr = acl.util.bytes_to_ptr(bytes_in) + else: + ptr = acl.util.numpy_to_ptr(dataset[i]) + ret = acl.rt.memcpy(item["buffer"], item["size"], ptr, item["size"], policy) + check_ret("acl.rt.memcpy", ret) + + else: + ptr = dataset[i]["buffer"] + ret = acl.rt.memcpy(ptr, item["size"], item["buffer"], item["size"], policy) + check_ret("acl.rt.memcpy", ret) + + + def _gen_dataset(self, type_str="input"): + dataset = acl.mdl.create_dataset() + + temp_dataset = None + if type_str == "in": + self.load_input_dataset = dataset + temp_dataset = self.input_data + else: + self.load_output_dataset = dataset + temp_dataset = self.output_data + + for item in temp_dataset: + data = acl.create_data_buffer(item["buffer"], item["size"]) + if data is None: + ret = acl.destroy_data_buffer(dataset) + check_ret("acl.destroy_data_buffer", ret) + + _, ret = acl.mdl.add_dataset_buffer(dataset, data) + if ret != ACL_ERROR_NONE: + ret = acl.destroy_data_buffer(dataset) + check_ret("acl.destroy_data_buffer", ret) + + + def _data_from_host_to_device(self, images): + self._data_interaction(images, ACL_MEMCPY_HOST_TO_DEVICE) + self._gen_dataset("in") + self._gen_dataset("out") + + + def _data_from_device_to_host(self): + res = [] + self._data_interaction(res, ACL_MEMCPY_DEVICE_TO_HOST) + output = self.get_result(self.output_data_host) + return output + + + def _destroy_databuffer(self): + for dataset in [self.load_input_dataset, self.load_output_dataset]: + if not dataset: + continue + + num = acl.mdl.get_dataset_num_buffers(dataset) + for i in range(num): + data_buf = acl.mdl.get_dataset_buffer(dataset, i) + if data_buf: + ret = acl.destroy_data_buffer(data_buf) + check_ret("acl.destroy_data_buffer", ret) + ret = acl.mdl.destroy_dataset(dataset) + check_ret("acl.mdl.destroy_dataset", ret) + + def forward(self, input_data): + if not isinstance(input_data, (list, tuple)): + input_data = [input_data] + + self._data_from_host_to_device(input_data) + ret = acl.mdl.execute(self.model_id, self.load_input_dataset, self.load_output_dataset) + check_ret("acl.mdl.execute", ret) + + self._destroy_databuffer() + result = self._data_from_device_to_host() + return result + + + def get_result(self, output_data): + dataset = [] + for i in range(len(output_data)): + dims, ret = acl.mdl.get_cur_output_dims(self.model_desc, i) + check_ret("acl.mdl.get_cur_output_dims", ret) + + data_shape = dims.get("dims") + data_type = acl.mdl.get_output_data_type(self.model_desc, i) + data_len = functools.reduce(lambda x, y: x * y, data_shape) + ftype = np.dtype(ACL_DTYPE.get(data_type)) + + size = output_data[i]["size"] + ptr = output_data[i]["buffer"] + if 'ptr_to_bytes' in dir(acl.util): + data = acl.util.ptr_to_bytes(ptr, size) + np_arr = np.frombuffer(data, dtype=ftype, count=data_len) + else: + data = acl.util.ptr_to_numpy(ptr, (size,), 1) + np_arr = np.frombuffer(bytearray(data[:data_len * ftype.itemsize]), dtype=ftype, count=data_len) + np_arr = np_arr.reshape(data_shape) + dataset.append(np_arr) + return dataset diff --git a/ACL_PyTorch/contrib/cv/video_understanding/I3D/i3d_inference.py b/ACL_PyTorch/contrib/cv/video_understanding/I3D/i3d_inference.py index 6fa45cf9b4bb3e57f6532f55a313d7a8cbbc0ef9..7b9e49a7b9fe2531d9c809ad23f143369a993d01 100644 --- a/ACL_PyTorch/contrib/cv/video_understanding/I3D/i3d_inference.py +++ b/ACL_PyTorch/contrib/cv/video_understanding/I3D/i3d_inference.py @@ -1,203 +1,203 @@ -# ============================================================================ -# Copyright 2018-2019 Open-MMLab. All rights reserved. -# Apache License -# Version 2.0, January 2004 -# http://www.apache.org/licenses/ -# -# TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import os -import os.path as osp -import warnings -import numpy as np -from sys import path -path.append('/home/mmaction2-20') - -import mmcv -import torch -import torch.nn.functional as F -from mmcv import Config, DictAction -from mmcv.cnn import fuse_conv_bn -from mmcv.fileio.io import file_handlers -from mmcv.parallel import MMDataParallel, MMDistributedDataParallel -from mmcv.runner import get_dist_info, init_dist, load_checkpoint -from mmcv.runner.fp16_utils import wrap_fp16_model - -from mmaction.datasets import build_dataloader, build_dataset -from mmaction.models import build_model -from mmaction.utils import register_module_hooks - -from acl_net import Net -import acl - - - -def parse_args(): - parser = argparse.ArgumentParser( - description='i3d inference') - parser.add_argument('config', help='test config file path') - parser.add_argument( - '--out', - default=None, - help='output result file in pkl/yaml/json format') - parser.add_argument( - '--eval', - type=str, - nargs='+', - help='evaluation metrics, which depends on the dataset, e.g.,' - ' "top_k_accuracy", "mean_class_accuracy" for video dataset') - parser.add_argument( - '-bs', '--batch_size', type=int, default=1, - help='batch size') - parser.add_argument( - '--device_id', type=int, default=1, - help='device id') - parser.add_argument( - '--model', required=True, type=str, - help='i3d.om') - args = parser.parse_args() - - return args - -def check_ret(message, ret): - if ret != 0: - raise Exception("{} failed ret = {}".format(message, ret)) - - -class I3d(): - def __init__(self, device_id, model) -> None: - ret = acl.init() - check_ret("acl.init failed", ret) - ret = acl.rt.set_device(device_id) - check_ret("acl.rt.set_device failed", ret) - context, ret = acl.rt.create_context(device_id) - check_ret("acl.rt.create_context failed", ret) - self.device_id = device_id - - self.i3d_context = Net(context, model_path=model, device_id=device_id, first=True) - - def __del__(self): - del self.i3d_context - - ret = acl.rt.reset_device(self.device_id) - check_ret("acl.rt.reset_device failed", ret) - context, ret = acl.rt.get_context() - check_ret("acl.rt.get_context failed", ret) - ret = acl.rt.destroy_context(context) - check_ret("acl.rt.destroy_context failed", ret) - ret = acl.finalize() - check_ret("acl.finalize failed", ret) - - def inference(self, data_loader): - results = [] - dataset = data_loader.dataset - prog_bar = mmcv.ProgressBar(len(dataset)) - for data in data_loader: - input_data = np.array(data['imgs']) - result = self.i3d_context([input_data]) - result = torch.from_numpy(np.array(result)) - batch_size = result.shape[1] - result = result.view(result.shape[0], batch_size, -1) - result = F.softmax(result, dim=2).mean(dim=1) - result = result.numpy() - results.extend(result) - - batch_size = len(result) - for _ in range(batch_size): - prog_bar.update() - - return results - - - -def main(): - args = parse_args() - - cfg = Config.fromfile(args.config) - - # Load output_config from cfg - output_config = cfg.get('output_config', {}) - if args.out: - # Overwrite output_config from args.out - output_config = Config._merge_a_into_b( - dict(out=args.out), output_config) - - # Load eval_config from cfg - eval_config = cfg.get('eval_config', {}) - if args.eval: - # Overwrite eval_config from args.eval - eval_config = Config._merge_a_into_b( - dict(metrics=args.eval), eval_config) - - dataset_type = cfg.data.test.type - if output_config.get('out', None): - if 'output_format' in output_config: - # ugly workround to make recognition and localization the same - warnings.warn( - 'Skip checking `output_format` in localization task.') - else: - out = output_config['out'] - # make sure the dirname of the output path exists - mmcv.mkdir_or_exist(osp.dirname(out)) - _, suffix = osp.splitext(out) - if dataset_type == 'AVADataset': - assert suffix[1:] == 'csv', ('For AVADataset, the format of ' - 'the output file should be csv') - else: - assert suffix[1:] in file_handlers, ( - 'The format of the output ' - 'file should be json, pickle or yaml') - - cfg.data.test.test_mode = True - - # The flag is used to register module's hooks - cfg.setdefault('module_hooks', []) - - # build the dataloader - dataset = build_dataset(cfg.data.test, dict(test_mode=True)) - dataloader_setting = dict( - videos_per_gpu=args.batch_size, - workers_per_gpu=1, - dist=False, - shuffle=False) - dataloader_setting = dict(dataloader_setting, - **cfg.data.get('test_dataloader', {})) - data_loader = build_dataloader(dataset, **dataloader_setting) - - i3d = I3d(args.device_id, args.model) - outputs = i3d.inference(data_loader) - - rank, _ = get_dist_info() - if rank == 0: - if output_config.get('out', None): - out = output_config['out'] - print(f'\nwriting results to {out}') - dataset.dump_results(outputs, **output_config) - if eval_config: - eval_res = dataset.evaluate(outputs, **eval_config) - for name, val in eval_res.items(): - print(f'{name}: {val:.04f}') - - -if __name__ == '__main__': - main() +# ============================================================================ +# Copyright 2018-2019 Open-MMLab. All rights reserved. +# Apache License +# Version 2.0, January 2004 +# http://www.apache.org/licenses/ +# +# TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import os +import os.path as osp +import warnings +import numpy as np +from sys import path +path.append('/home/mmaction2-20') + +import mmcv +import torch +import torch.nn.functional as F +from mmcv import Config, DictAction +from mmcv.cnn import fuse_conv_bn +from mmcv.fileio.io import file_handlers +from mmcv.parallel import MMDataParallel, MMDistributedDataParallel +from mmcv.runner import get_dist_info, init_dist, load_checkpoint +from mmcv.runner.fp16_utils import wrap_fp16_model + +from mmaction.datasets import build_dataloader, build_dataset +from mmaction.models import build_model +from mmaction.utils import register_module_hooks + +from acl_net import Net +import acl + + + +def parse_args(): + parser = argparse.ArgumentParser( + description='i3d inference') + parser.add_argument('config', help='test config file path') + parser.add_argument( + '--out', + default=None, + help='output result file in pkl/yaml/json format') + parser.add_argument( + '--eval', + type=str, + nargs='+', + help='evaluation metrics, which depends on the dataset, e.g.,' + ' "top_k_accuracy", "mean_class_accuracy" for video dataset') + parser.add_argument( + '-bs', '--batch_size', type=int, default=1, + help='batch size') + parser.add_argument( + '--device_id', type=int, default=1, + help='device id') + parser.add_argument( + '--model', required=True, type=str, + help='i3d.om') + args = parser.parse_args() + + return args + +def check_ret(message, ret): + if ret != 0: + raise Exception("{} failed ret = {}".format(message, ret)) + + +class I3d(): + def __init__(self, device_id, model) -> None: + ret = acl.init() + check_ret("acl.init failed", ret) + ret = acl.rt.set_device(device_id) + check_ret("acl.rt.set_device failed", ret) + context, ret = acl.rt.create_context(device_id) + check_ret("acl.rt.create_context failed", ret) + self.device_id = device_id + + self.i3d_context = Net(context, model_path=model, device_id=device_id, first=True) + + def __del__(self): + del self.i3d_context + + ret = acl.rt.reset_device(self.device_id) + check_ret("acl.rt.reset_device failed", ret) + context, ret = acl.rt.get_context() + check_ret("acl.rt.get_context failed", ret) + ret = acl.rt.destroy_context(context) + check_ret("acl.rt.destroy_context failed", ret) + ret = acl.finalize() + check_ret("acl.finalize failed", ret) + + def inference(self, data_loader): + results = [] + dataset = data_loader.dataset + prog_bar = mmcv.ProgressBar(len(dataset)) + for data in data_loader: + input_data = np.array(data['imgs']) + result = self.i3d_context([input_data]) + result = torch.from_numpy(np.array(result)) + batch_size = result.shape[1] + result = result.view(result.shape[0], batch_size, -1) + result = F.softmax(result, dim=2).mean(dim=1) + result = result.numpy() + results.extend(result) + + batch_size = len(result) + for _ in range(batch_size): + prog_bar.update() + + return results + + + +def main(): + args = parse_args() + + cfg = Config.fromfile(args.config) + + # Load output_config from cfg + output_config = cfg.get('output_config', {}) + if args.out: + # Overwrite output_config from args.out + output_config = Config._merge_a_into_b( + dict(out=args.out), output_config) + + # Load eval_config from cfg + eval_config = cfg.get('eval_config', {}) + if args.eval: + # Overwrite eval_config from args.eval + eval_config = Config._merge_a_into_b( + dict(metrics=args.eval), eval_config) + + dataset_type = cfg.data.test.type + if output_config.get('out', None): + if 'output_format' in output_config: + # ugly workround to make recognition and localization the same + warnings.warn( + 'Skip checking `output_format` in localization task.') + else: + out = output_config['out'] + # make sure the dirname of the output path exists + mmcv.mkdir_or_exist(osp.dirname(out)) + _, suffix = osp.splitext(out) + if dataset_type == 'AVADataset': + assert suffix[1:] == 'csv', ('For AVADataset, the format of ' + 'the output file should be csv') + else: + assert suffix[1:] in file_handlers, ( + 'The format of the output ' + 'file should be json, pickle or yaml') + + cfg.data.test.test_mode = True + + # The flag is used to register module's hooks + cfg.setdefault('module_hooks', []) + + # build the dataloader + dataset = build_dataset(cfg.data.test, dict(test_mode=True)) + dataloader_setting = dict( + videos_per_gpu=args.batch_size, + workers_per_gpu=1, + dist=False, + shuffle=False) + dataloader_setting = dict(dataloader_setting, + **cfg.data.get('test_dataloader', {})) + data_loader = build_dataloader(dataset, **dataloader_setting) + + i3d = I3d(args.device_id, args.model) + outputs = i3d.inference(data_loader) + + rank, _ = get_dist_info() + if rank == 0: + if output_config.get('out', None): + out = output_config['out'] + print(f'\nwriting results to {out}') + dataset.dump_results(outputs, **output_config) + if eval_config: + eval_res = dataset.evaluate(outputs, **eval_config) + for name, val in eval_res.items(): + print(f'{name}: {val:.04f}') + + +if __name__ == '__main__': + main() diff --git a/ACL_PyTorch/contrib/cv/video_understanding/TSN/LICENSE b/ACL_PyTorch/contrib/cv/video_understanding/TSN/LICENSE index b57dcc300309d53d367942b29e8155d46780ea9d..108309f32416efe8780cc0d8309a45c8a2ebbbd3 100644 --- a/ACL_PyTorch/contrib/cv/video_understanding/TSN/LICENSE +++ b/ACL_PyTorch/contrib/cv/video_understanding/TSN/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/video_understanding/TSN/README.md b/ACL_PyTorch/contrib/cv/video_understanding/TSN/README.md index 3b2bb4f94c69117344b0e3bd7d55efcc5e9caad6..b8c6ccf3ddcccd57b433b3a4955d6e12a9709f2e 100644 --- a/ACL_PyTorch/contrib/cv/video_understanding/TSN/README.md +++ b/ACL_PyTorch/contrib/cv/video_understanding/TSN/README.md @@ -1,96 +1,96 @@ -# 基于开源mmaction2预训练的TSN模型端到端推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - -```shell -pip3.7 install -r requirements.txt -``` - -2.获取,修改与安装开源模型代码 - -```shell -git clone https://github.com/open-mmlab/mmaction2.git -cd mmaction2 -git checkout 9ab8c2af52c561e5c789ccaf7b62f4b7679c103c -pip install -r requirements/build.txt -pip install -v -e . -cd .. -``` - - -3.获取权重文件 - -需要获取tsn_r50_1x1x3_75e_ucf101_rgb/tsn_r50_1x1x3_75e_ucf101_rgb_20201023-d85ab600.pth文件,请参考文档。 - -4.数据集 - -该模型使用UCF101的验证集进行测试,数据集下载步骤如下 - -```shell -cd ./mmaction2/tools/data/ucf101 -bash download_annotations.sh -bash download_videos.sh -bash extract_rgb_frames_opencv.sh -bash generate_videos_filelist.sh -bash generate_rawframes_filelist.sh -``` - -(可选)本项目默认将数据集存放于/opt/npu/ - -```shell -cd .. -mv /ucf101 /opt/npu/ -``` - -5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) - 将benchmark.x86_64或benchmark.aarch64放到当前目录 - -6.使用msame工具推理 -1.首先需要获取msame工具 - -```shell -git clone https://gitee.com/ascend/tools.git -``` - -2.而后安装msame工具 - -```shell -export DDK_PATH=/usr/local/Ascend/ascend-toolkit/latest -export NPU_HOST_LIB=/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64/stub -cd ./tools/msame -./build.sh g++ ./ -cd ../.. -``` - -3.增加执行权限 - -```shell -chmod u+x ./tools/msame/out/msame -``` - - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 - -``` -#OM model generation -bash test/pth2om.sh - -#OM model inference -bash test/eval_acc_perf.sh --datasets_path=/root/datasets - -#gpu inference -bash test/perf_gpu.sh -``` - -**评测结果:** - -| 模型 | pth精度 | 310精度 | 性能基准 | 310性能 | -| :------: | :------: | :------: | :------: | :------: | -| TSN bs1 | top1:83.03%| top1:82.84%| 22.63fps | 23.43fps | -| TSN bs4 | top1:83.03%| top1:82.84%| 21.96fps | 24.41fps | -| TSN bs8 | top1:83.03%| top1:82.84%| 22.18fps | 24.68fps | - +# 基于开源mmaction2预训练的TSN模型端到端推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + +```shell +pip3.7 install -r requirements.txt +``` + +2.获取,修改与安装开源模型代码 + +```shell +git clone https://github.com/open-mmlab/mmaction2.git +cd mmaction2 +git checkout 9ab8c2af52c561e5c789ccaf7b62f4b7679c103c +pip install -r requirements/build.txt +pip install -v -e . +cd .. +``` + + +3.获取权重文件 + +需要获取tsn_r50_1x1x3_75e_ucf101_rgb/tsn_r50_1x1x3_75e_ucf101_rgb_20201023-d85ab600.pth文件,请参考文档。 + +4.数据集 + +该模型使用UCF101的验证集进行测试,数据集下载步骤如下 + +```shell +cd ./mmaction2/tools/data/ucf101 +bash download_annotations.sh +bash download_videos.sh +bash extract_rgb_frames_opencv.sh +bash generate_videos_filelist.sh +bash generate_rawframes_filelist.sh +``` + +(可选)本项目默认将数据集存放于/opt/npu/ + +```shell +cd .. +mv /ucf101 /opt/npu/ +``` + +5.[获取benchmark工具](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373/software/) + 将benchmark.x86_64或benchmark.aarch64放到当前目录 + +6.使用msame工具推理 +1.首先需要获取msame工具 + +```shell +git clone https://gitee.com/ascend/tools.git +``` + +2.而后安装msame工具 + +```shell +export DDK_PATH=/usr/local/Ascend/ascend-toolkit/latest +export NPU_HOST_LIB=/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64/stub +cd ./tools/msame +./build.sh g++ ./ +cd ../.. +``` + +3.增加执行权限 + +```shell +chmod u+x ./tools/msame/out/msame +``` + + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 + +``` +#OM model generation +bash test/pth2om.sh + +#OM model inference +bash test/eval_acc_perf.sh --datasets_path=/root/datasets + +#gpu inference +bash test/perf_gpu.sh +``` + +**评测结果:** + +| 模型 | pth精度 | 310精度 | 性能基准 | 310性能 | +| :------: | :------: | :------: | :------: | :------: | +| TSN bs1 | top1:83.03%| top1:82.84%| 22.63fps | 23.43fps | +| TSN bs4 | top1:83.03%| top1:82.84%| 21.96fps | 24.41fps | +| TSN bs8 | top1:83.03%| top1:82.84%| 22.18fps | 24.68fps | + diff --git a/ACL_PyTorch/contrib/cv/video_understanding/TSN/modelzoo_level.txt b/ACL_PyTorch/contrib/cv/video_understanding/TSN/modelzoo_level.txt index 403465b84e39e2cc8a387c33aaf5a1043f8d267a..ec6168981c278bbe672c13a4eb251b6ec184eda4 100644 --- a/ACL_PyTorch/contrib/cv/video_understanding/TSN/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/cv/video_understanding/TSN/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:Perfect \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/video_understanding/TSN/pytorch2onnx.py b/ACL_PyTorch/contrib/cv/video_understanding/TSN/pytorch2onnx.py index 0bf774f4a66daf6f6e3e7f27325cbf5a1f0df854..911dc557347873079ddac88b92967233ee6f970a 100644 --- a/ACL_PyTorch/contrib/cv/video_understanding/TSN/pytorch2onnx.py +++ b/ACL_PyTorch/contrib/cv/video_understanding/TSN/pytorch2onnx.py @@ -1,193 +1,193 @@ -""" -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -============================================================================ -""" -# !/usr/bin/env python -# -*- coding: utf-8 -*- - -import argparse - -import mmcv -import numpy as np -import torch -from mmcv.runner import load_checkpoint - -from mmaction.models import build_model - -try: - import onnx - import onnxruntime as rt -except ImportError as e: - raise ImportError(f'Please install onnx and onnxruntime first. {e}') - -try: - from mmcv.onnx.symbolic import register_extra_symbolics -except ModuleNotFoundError: - raise NotImplementedError('please update mmcv to version>=1.0.4') - - -def _convert_batchnorm(module): - """Convert the syncBNs into normal BN3ds.""" - module_output = module - if isinstance(module, torch.nn.SyncBatchNorm): - module_output = torch.nn.BatchNorm3d(module.num_features, module.eps, - module.momentum, module.affine, - module.track_running_stats) - if module.affine: - module_output.weight.data = module.weight.data.clone().detach() - module_output.bias.data = module.bias.data.clone().detach() - # keep requires_grad unchanged - module_output.weight.requires_grad = module.weight.requires_grad - module_output.bias.requires_grad = module.bias.requires_grad - module_output.running_mean = module.running_mean - module_output.running_var = module.running_var - module_output.num_batches_tracked = module.num_batches_tracked - for name, child in module.named_children(): - module_output.add_module(name, _convert_batchnorm(child)) - del module - return module_output - - -def pytorch2onnx(model, - input_shape, - opset_version=11, - show=False, - output_file='tmp.onnx', - verify=False): - """Convert pytorch model to onnx model. - - Args: - model (:obj:`nn.Module`): The pytorch model to be exported. - input_shape (tuple[int]): The input tensor shape of the model. - opset_version (int): Opset version of onnx used. Default: 11. - show (bool): Determines whether to print the onnx model architecture. - Default: False. - output_file (str): Output onnx model name. Default: 'tmp.onnx'. - verify (bool): Determines whether to verify the onnx model. - Default: False. - """ - model.cpu().eval() - - input_tensor = torch.randn(input_shape) - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - register_extra_symbolics(opset_version) - torch.onnx.export( - model, - input_tensor, - output_file, - input_names=input_names, - dynamic_axes=dynamic_axes, - output_names=output_names, - export_params=True, - keep_initializers_as_inputs=True, - verbose=show, - opset_version=11) - - print(f'Successfully exported ONNX model: {output_file}') - if verify: - # check by onnx - onnx_model = onnx.load(output_file) - onnx.checker.check_model(onnx_model) - - # check the numerical value - # get pytorch output - pytorch_result = model(input_tensor)[0].detach().numpy() - - # get onnx output - input_all = [node.name for node in onnx_model.graph.input] - input_initializer = [ - node.name for node in onnx_model.graph.initializer - ] - net_feed_input = list(set(input_all) - set(input_initializer)) - assert len(net_feed_input) == 1 - sess = rt.InferenceSession(output_file) - onnx_result = sess.run( - None, {net_feed_input[0]: input_tensor.detach().numpy()})[0] - # only compare part of results - random_class = np.random.randint(pytorch_result.shape[1]) - assert np.allclose( - pytorch_result[:, random_class], onnx_result[:, random_class] - ), 'The outputs are different between Pytorch and ONNX' - print('The numerical values are same between Pytorch and ONNX') - - -def parse_args(): - parser = argparse.ArgumentParser( - description='Convert MMAction2 models to ONNX') - parser.add_argument('config', help='test config file path', default='./mmaction2/configs/recognition/tsn/tsn_r50_1x1x3_75e_ucf101_rgb.py') - parser.add_argument('checkpoint', help='checkpoint file', default='./result_1p/tsn_r50_1x1x3_75e_ucf101_rgb.py') - parser.add_argument('--show', action='store_true', help='show onnx graph') - parser.add_argument('--output-file', type=str, default='tsn.onnx') - parser.add_argument('--opset-version', type=int, default=11) - parser.add_argument( - '--verify', - action='store_true', - help='verify the onnx model output against pytorch output') - parser.add_argument( - '--is-localizer', - action='store_true', - help='whether it is a localizer') - parser.add_argument( - '--shape', - type=int, - nargs='+', - default=[1, 75, 3, 256, 256], - help='input video size') - parser.add_argument( - '--softmax', - action='store_true', - help='wheter to add softmax layer at the end of recognizers') - args = parser.parse_args() - return args - - -if __name__ == '__main__': - args = parse_args() - - assert args.opset_version == 11, 'MMAction2 only supports opset 11 now' - - cfg = mmcv.Config.fromfile(args.config) - # import modules from string list. - - if not args.is_localizer: - cfg.model.backbone.pretrained = None - - # build the model - model = build_model( - cfg.model, train_cfg=None, test_cfg=cfg.get('test_cfg')) - model = _convert_batchnorm(model) - - # onnx.export does not support kwargs - if hasattr(model, 'forward_dummy'): - from functools import partial - model.forward = partial(model.forward_dummy, softmax=args.softmax) - elif hasattr(model, '_forward') and args.is_localizer: - model.forward = model._forward - else: - raise NotImplementedError( - 'Please implement the forward method for exporting.') - - checkpoint = load_checkpoint(model, args.checkpoint, map_location='cpu') - - # conver model to onnx file - pytorch2onnx( - model, - args.shape, - opset_version=args.opset_version, - show=args.show, - output_file=args.output_file, +""" +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============================================================================ +""" +# !/usr/bin/env python +# -*- coding: utf-8 -*- + +import argparse + +import mmcv +import numpy as np +import torch +from mmcv.runner import load_checkpoint + +from mmaction.models import build_model + +try: + import onnx + import onnxruntime as rt +except ImportError as e: + raise ImportError(f'Please install onnx and onnxruntime first. {e}') + +try: + from mmcv.onnx.symbolic import register_extra_symbolics +except ModuleNotFoundError: + raise NotImplementedError('please update mmcv to version>=1.0.4') + + +def _convert_batchnorm(module): + """Convert the syncBNs into normal BN3ds.""" + module_output = module + if isinstance(module, torch.nn.SyncBatchNorm): + module_output = torch.nn.BatchNorm3d(module.num_features, module.eps, + module.momentum, module.affine, + module.track_running_stats) + if module.affine: + module_output.weight.data = module.weight.data.clone().detach() + module_output.bias.data = module.bias.data.clone().detach() + # keep requires_grad unchanged + module_output.weight.requires_grad = module.weight.requires_grad + module_output.bias.requires_grad = module.bias.requires_grad + module_output.running_mean = module.running_mean + module_output.running_var = module.running_var + module_output.num_batches_tracked = module.num_batches_tracked + for name, child in module.named_children(): + module_output.add_module(name, _convert_batchnorm(child)) + del module + return module_output + + +def pytorch2onnx(model, + input_shape, + opset_version=11, + show=False, + output_file='tmp.onnx', + verify=False): + """Convert pytorch model to onnx model. + + Args: + model (:obj:`nn.Module`): The pytorch model to be exported. + input_shape (tuple[int]): The input tensor shape of the model. + opset_version (int): Opset version of onnx used. Default: 11. + show (bool): Determines whether to print the onnx model architecture. + Default: False. + output_file (str): Output onnx model name. Default: 'tmp.onnx'. + verify (bool): Determines whether to verify the onnx model. + Default: False. + """ + model.cpu().eval() + + input_tensor = torch.randn(input_shape) + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + register_extra_symbolics(opset_version) + torch.onnx.export( + model, + input_tensor, + output_file, + input_names=input_names, + dynamic_axes=dynamic_axes, + output_names=output_names, + export_params=True, + keep_initializers_as_inputs=True, + verbose=show, + opset_version=11) + + print(f'Successfully exported ONNX model: {output_file}') + if verify: + # check by onnx + onnx_model = onnx.load(output_file) + onnx.checker.check_model(onnx_model) + + # check the numerical value + # get pytorch output + pytorch_result = model(input_tensor)[0].detach().numpy() + + # get onnx output + input_all = [node.name for node in onnx_model.graph.input] + input_initializer = [ + node.name for node in onnx_model.graph.initializer + ] + net_feed_input = list(set(input_all) - set(input_initializer)) + assert len(net_feed_input) == 1 + sess = rt.InferenceSession(output_file) + onnx_result = sess.run( + None, {net_feed_input[0]: input_tensor.detach().numpy()})[0] + # only compare part of results + random_class = np.random.randint(pytorch_result.shape[1]) + assert np.allclose( + pytorch_result[:, random_class], onnx_result[:, random_class] + ), 'The outputs are different between Pytorch and ONNX' + print('The numerical values are same between Pytorch and ONNX') + + +def parse_args(): + parser = argparse.ArgumentParser( + description='Convert MMAction2 models to ONNX') + parser.add_argument('config', help='test config file path', default='./mmaction2/configs/recognition/tsn/tsn_r50_1x1x3_75e_ucf101_rgb.py') + parser.add_argument('checkpoint', help='checkpoint file', default='./result_1p/tsn_r50_1x1x3_75e_ucf101_rgb.py') + parser.add_argument('--show', action='store_true', help='show onnx graph') + parser.add_argument('--output-file', type=str, default='tsn.onnx') + parser.add_argument('--opset-version', type=int, default=11) + parser.add_argument( + '--verify', + action='store_true', + help='verify the onnx model output against pytorch output') + parser.add_argument( + '--is-localizer', + action='store_true', + help='whether it is a localizer') + parser.add_argument( + '--shape', + type=int, + nargs='+', + default=[1, 75, 3, 256, 256], + help='input video size') + parser.add_argument( + '--softmax', + action='store_true', + help='wheter to add softmax layer at the end of recognizers') + args = parser.parse_args() + return args + + +if __name__ == '__main__': + args = parse_args() + + assert args.opset_version == 11, 'MMAction2 only supports opset 11 now' + + cfg = mmcv.Config.fromfile(args.config) + # import modules from string list. + + if not args.is_localizer: + cfg.model.backbone.pretrained = None + + # build the model + model = build_model( + cfg.model, train_cfg=None, test_cfg=cfg.get('test_cfg')) + model = _convert_batchnorm(model) + + # onnx.export does not support kwargs + if hasattr(model, 'forward_dummy'): + from functools import partial + model.forward = partial(model.forward_dummy, softmax=args.softmax) + elif hasattr(model, '_forward') and args.is_localizer: + model.forward = model._forward + else: + raise NotImplementedError( + 'Please implement the forward method for exporting.') + + checkpoint = load_checkpoint(model, args.checkpoint, map_location='cpu') + + # conver model to onnx file + pytorch2onnx( + model, + args.shape, + opset_version=args.opset_version, + show=args.show, + output_file=args.output_file, verify=args.verify) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/video_understanding/TSN/requirements.txt b/ACL_PyTorch/contrib/cv/video_understanding/TSN/requirements.txt index bbd1fe63604baf02c3cd5ca0d8163060bbb0d463..209cb57ec6fa0f9c302a3023d36beb6fc47d8838 100644 --- a/ACL_PyTorch/contrib/cv/video_understanding/TSN/requirements.txt +++ b/ACL_PyTorch/contrib/cv/video_understanding/TSN/requirements.txt @@ -1,12 +1,12 @@ -einops==0.3.0 -mmcv==1.3.9 -numpy==1.21.0 -onnx==1.9.0 -onnx-simplifier==0.3.6 -onnxoptimizer==0.2.6 -onnxruntime==1.8.1 -opencv-contrib-python==4.5.3.56 -opencv-python==4.5.3.56 -scipy==1.7.0 -torch==1.5.0 +einops==0.3.0 +mmcv==1.3.9 +numpy==1.21.0 +onnx==1.9.0 +onnx-simplifier==0.3.6 +onnxoptimizer==0.2.6 +onnxruntime==1.8.1 +opencv-contrib-python==4.5.3.56 +opencv-python==4.5.3.56 +scipy==1.7.0 +torch==1.5.0 torchvision==0.10.0 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/eval_acc_perf.sh b/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/eval_acc_perf.sh index 895c63c8137f3cdda4d7d65b50c2c770d257cbde..b1e35487f31ca4469cc01895d0b188355344d168 100644 --- a/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/eval_acc_perf.sh +++ b/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/eval_acc_perf.sh @@ -1,74 +1,74 @@ -#!/bin/bash - -datasets_path="/opt/npu/" - -for para in $* -do - if [[ $para == --datasets_path* ]]; then - datasets_path=`echo ${para#*=}` - fi -done - -python3.7 tsn_ucf101_preprocess.py --batch_size 1 --data_root ${datasets_path}/ucf101 --name out_bin_1 -if [ $? != 0 ]; then - echo "fail!" - exit -1 -fi -python3.7 tsn_ucf101_preprocess.py --batch_size 8 --data_root ${datasets_path}/ucf101 --name out_bin_8 -if [ $? != 0 ]; then - echo "fail!" - exit -1 -fi - -source env.sh -mkdir -p output/out_bs1 -rm -rf output/out_bs1/* -./tools/msame/out/msame --model ./om/tsn_1.om --input /opt/npu/ucf101/out_bin_1 --output ./output/out_bs1/ --outfmt TXT -if [ $? != 0 ]; then - echo "fail!" - exit -1 -fi -mkdir -p output/out_bs8 -rm -rf output/out_bs8/* -./tools/msame/out/msame --model ./om/tsn_8.om --input /opt/npu/ucf101/out_bin_8 --output ./output/out_bs8/ --outfmt TXT -if [ $? != 0 ]; then - echo "fail!" - exit -1 -fi - -mkdir -p result -./benchmark.x86_64 -round=20 -om_path=./om/tsn_1.om -device_id=0 -batch_size=1 -if [ $? != 0 ]; then - echo "fail!" - exit -1 -fi -./benchmark.x86_64 -round=20 -om_path=./om/tsn_8.om -device_id=0 -batch_size=8 -if [ $? != 0 ]; then - echo "fail!" - exit -1 -fi - -echo "====accuracy data====" -python3.7 tsn_ucf101_postprocess.py --result_path ./output/out_bs1 --info_path ${datasets_path}/ucf101/ucf101_1.info --batch_size 1 -if [ $? != 0 ]; then - echo "fail!" - exit -1 -fi -python3.7 tsn_ucf101_postprocess.py --result_path ./output/out_bs8 --info_path ${datasets_path}/ucf101/ucf101_8.info --batch_size 8 -if [ $? != 0 ]; then - echo "fail!" - exit -1 -fi - -echo "====performance data====" -python3.7 test/parse.py result/PureInfer_perf_of_tsn_1_in_device_0.txt -if [ $? != 0 ]; then - echo "fail!" - exit -1 -fi -python3.7 test/parse.py result/PureInfer_perf_of_tsn_8_in_device_0.txt -if [ $? != 0 ]; then - echo "fail!" - exit -1 -fi +#!/bin/bash + +datasets_path="/opt/npu/" + +for para in $* +do + if [[ $para == --datasets_path* ]]; then + datasets_path=`echo ${para#*=}` + fi +done + +python3.7 tsn_ucf101_preprocess.py --batch_size 1 --data_root ${datasets_path}/ucf101 --name out_bin_1 +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +python3.7 tsn_ucf101_preprocess.py --batch_size 8 --data_root ${datasets_path}/ucf101 --name out_bin_8 +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi + +source env.sh +mkdir -p output/out_bs1 +rm -rf output/out_bs1/* +./tools/msame/out/msame --model ./om/tsn_1.om --input /opt/npu/ucf101/out_bin_1 --output ./output/out_bs1/ --outfmt TXT +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +mkdir -p output/out_bs8 +rm -rf output/out_bs8/* +./tools/msame/out/msame --model ./om/tsn_8.om --input /opt/npu/ucf101/out_bin_8 --output ./output/out_bs8/ --outfmt TXT +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi + +mkdir -p result +./benchmark.x86_64 -round=20 -om_path=./om/tsn_1.om -device_id=0 -batch_size=1 +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +./benchmark.x86_64 -round=20 -om_path=./om/tsn_8.om -device_id=0 -batch_size=8 +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi + +echo "====accuracy data====" +python3.7 tsn_ucf101_postprocess.py --result_path ./output/out_bs1 --info_path ${datasets_path}/ucf101/ucf101_1.info --batch_size 1 +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +python3.7 tsn_ucf101_postprocess.py --result_path ./output/out_bs8 --info_path ${datasets_path}/ucf101/ucf101_8.info --batch_size 8 +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi + +echo "====performance data====" +python3.7 test/parse.py result/PureInfer_perf_of_tsn_1_in_device_0.txt +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi +python3.7 test/parse.py result/PureInfer_perf_of_tsn_8_in_device_0.txt +if [ $? != 0 ]; then + echo "fail!" + exit -1 +fi echo "success" \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/parse.py b/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/parse.py index bc45f3df1869dd99cf5606f66ab62302abef9c99..9a9507ebece324428ca74a8e5991b894277c2d86 100644 --- a/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/parse.py +++ b/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/parse.py @@ -1,37 +1,37 @@ -""" -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -============================================================================ -""" - -import sys -import re - -if __name__ == '__main__': - result_txt = sys.argv[1] - if 'PureInfer' in result_txt: # Pure Infer - with open(result_txt, 'r') as f: - content = f.read() - txt_data_list = [i.strip() for i in re.findall(r'=(.*?),', content.replace('\n', ',') + ',')] - fps = float(txt_data_list[0].replace('samples/s', '')) * 4 - print('310 {} fps:{}'.format(result_txt.split('_')[3], fps)) - else: # Infer based on dataset - with open(result_txt, 'r') as f: - lines = f.readlines() - for line in lines: - if 'infer' in line: - txt_data_list = [i.strip() for i in re.findall(r':(.*?),', line.replace('\n', ',') + ',')] - fps = float(txt_data_list[1]) * 4 - print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) +""" +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============================================================================ +""" + +import sys +import re + +if __name__ == '__main__': + result_txt = sys.argv[1] + if 'PureInfer' in result_txt: # Pure Infer + with open(result_txt, 'r') as f: + content = f.read() + txt_data_list = [i.strip() for i in re.findall(r'=(.*?),', content.replace('\n', ',') + ',')] + fps = float(txt_data_list[0].replace('samples/s', '')) * 4 + print('310 {} fps:{}'.format(result_txt.split('_')[3], fps)) + else: # Infer based on dataset + with open(result_txt, 'r') as f: + lines = f.readlines() + for line in lines: + if 'infer' in line: + txt_data_list = [i.strip() for i in re.findall(r':(.*?),', line.replace('\n', ',') + ',')] + fps = float(txt_data_list[1]) * 4 + print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) break \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/perf_gpu.sh b/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/perf_gpu.sh index 41c7a98786ffbd91dd6a1c4a8321f5bb8cd5071c..b182f1c43f2f2ffe2b968ad24116e5ae86319979 100644 --- a/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/perf_gpu.sh +++ b/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/perf_gpu.sh @@ -1,31 +1,31 @@ -#!/bin/bash -# GPU上执行: -trtexec --onnx=onnx_sim/tsn_1.onnx --fp16 --shapes=video:1x75x3x224x224 > tsn_1.log -perf_str=`grep "GPU.* mean.*ms$" tsn_bs1.log` -if [ -n "$perf_str" ]; then - perf_num=`echo $perf_str | awk -F' ' '{print $16}'` -else - perf_str=`grep "mean.*ms$" tsn_bs1.log` - perf_num=`echo $perf_str | awk -F' ' '{print $4}'` -fi -awk 'BEGIN{printf "t4 bs1 fps:%.3f\n", 1000*1/('$perf_num'/1)}' - -trtexec --onnx=onnx_sim/tsn_4.onnx --fp16 --shapes=video:4x75x3x224x224 > tsn_4.log -perf_str=`grep "GPU.* mean.*ms$" tsn_bs16.log` -if [ -n "$perf_str" ]; then - perf_num=`echo $perf_str | awk -F' ' '{print $16}'` -else - perf_str=`grep "mean.*ms$" tsn_bs16.log` - perf_num=`echo $perf_str | awk -F' ' '{print $4}'` -fi -awk 'BEGIN{printf "t4 bs4 fps:%.3f\n", 1000*1/('$perf_num'/16)}' - -trtexec --onnx=onnx_sim/tsn_8.onnx --fp16 --shapes=video:8x75x3x224x224 > tsn_8.log -perf_str=`grep "GPU.* mean.*ms$" tsn_bs16.log` -if [ -n "$perf_str" ]; then - perf_num=`echo $perf_str | awk -F' ' '{print $16}'` -else - perf_str=`grep "mean.*ms$" tsn_bs16.log` - perf_num=`echo $perf_str | awk -F' ' '{print $4}'` -fi +#!/bin/bash +# GPU上执行: +trtexec --onnx=onnx_sim/tsn_1.onnx --fp16 --shapes=video:1x75x3x224x224 > tsn_1.log +perf_str=`grep "GPU.* mean.*ms$" tsn_bs1.log` +if [ -n "$perf_str" ]; then + perf_num=`echo $perf_str | awk -F' ' '{print $16}'` +else + perf_str=`grep "mean.*ms$" tsn_bs1.log` + perf_num=`echo $perf_str | awk -F' ' '{print $4}'` +fi +awk 'BEGIN{printf "t4 bs1 fps:%.3f\n", 1000*1/('$perf_num'/1)}' + +trtexec --onnx=onnx_sim/tsn_4.onnx --fp16 --shapes=video:4x75x3x224x224 > tsn_4.log +perf_str=`grep "GPU.* mean.*ms$" tsn_bs16.log` +if [ -n "$perf_str" ]; then + perf_num=`echo $perf_str | awk -F' ' '{print $16}'` +else + perf_str=`grep "mean.*ms$" tsn_bs16.log` + perf_num=`echo $perf_str | awk -F' ' '{print $4}'` +fi +awk 'BEGIN{printf "t4 bs4 fps:%.3f\n", 1000*1/('$perf_num'/16)}' + +trtexec --onnx=onnx_sim/tsn_8.onnx --fp16 --shapes=video:8x75x3x224x224 > tsn_8.log +perf_str=`grep "GPU.* mean.*ms$" tsn_bs16.log` +if [ -n "$perf_str" ]; then + perf_num=`echo $perf_str | awk -F' ' '{print $16}'` +else + perf_str=`grep "mean.*ms$" tsn_bs16.log` + perf_num=`echo $perf_str | awk -F' ' '{print $4}'` +fi awk 'BEGIN{printf "t4 bs8 fps:%.3f\n", 1000*1/('$perf_num'/16)}' \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/pth2om.sh b/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/pth2om.sh index 28d656c4d83eaaa5cc438d47157ffbb125220e94..487fffdef77aaf288c31d44c7b4bc4b302afdb26 100644 --- a/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/pth2om.sh +++ b/ACL_PyTorch/contrib/cv/video_understanding/TSN/test/pth2om.sh @@ -1,13 +1,13 @@ -#!/bin/bash -source env.sh -python3.7 pytorch2onnx.py ./mmaction2/configs/recognition/tsn/tsn_r50_1x1x3_75e_ucf101_rgb.py ./tsn_r50_1x1x3_75e_ucf101_rgb_20201023-d85ab600.pth --verify - -mkdir -p om -atc --framework=5 --model=tsn.onnx --output=tsn_1 --input_format=NCDHW --input_shape="image:1,75,3,256,256" --log=debug --soc_version=Ascend310 --auto_tune_mode "RL,GA" -atc --framework=5 --model=tsn.onnx --output=tsn_4 --input_format=NCDHW --input_shape="image:4,75,3,256,256" --log=debug --soc_version=Ascend310 --auto_tune_mode "RL,GA" -atc --framework=5 --model=tsn.onnx --output=tsn_8 --input_format=NCDHW --input_shape="image:8,75,3,256,256" --log=debug --soc_version=Ascend310 --auto_tune_mode "RL,GA" -if [ -f "om/tsm_bs1.om" ] && [ -f "om/tsm_bs16.om" ]; then - echo "success" -else - echo "fail!" +#!/bin/bash +source env.sh +python3.7 pytorch2onnx.py ./mmaction2/configs/recognition/tsn/tsn_r50_1x1x3_75e_ucf101_rgb.py ./tsn_r50_1x1x3_75e_ucf101_rgb_20201023-d85ab600.pth --verify + +mkdir -p om +atc --framework=5 --model=tsn.onnx --output=tsn_1 --input_format=NCDHW --input_shape="image:1,75,3,256,256" --log=debug --soc_version=Ascend310 --auto_tune_mode "RL,GA" +atc --framework=5 --model=tsn.onnx --output=tsn_4 --input_format=NCDHW --input_shape="image:4,75,3,256,256" --log=debug --soc_version=Ascend310 --auto_tune_mode "RL,GA" +atc --framework=5 --model=tsn.onnx --output=tsn_8 --input_format=NCDHW --input_shape="image:8,75,3,256,256" --log=debug --soc_version=Ascend310 --auto_tune_mode "RL,GA" +if [ -f "om/tsm_bs1.om" ] && [ -f "om/tsm_bs16.om" ]; then + echo "success" +else + echo "fail!" fi \ No newline at end of file diff --git a/ACL_PyTorch/contrib/cv/video_understanding/TSN/tsn_ucf101_postprocess.py b/ACL_PyTorch/contrib/cv/video_understanding/TSN/tsn_ucf101_postprocess.py index bc538bd927e1b3fae90c3302448469d799a1e330..ee3c2861103f42b7de445b97d87e4675d8d1cfe0 100644 --- a/ACL_PyTorch/contrib/cv/video_understanding/TSN/tsn_ucf101_postprocess.py +++ b/ACL_PyTorch/contrib/cv/video_understanding/TSN/tsn_ucf101_postprocess.py @@ -1,59 +1,59 @@ -""" -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -============================================================================ -""" -# !/usr/bin/env python -# -*- coding: utf-8 -*- - -import os -import argparse -import numpy as np -from collections import OrderedDict -from mmaction.core import top_k_accuracy - - -def parse_args(): - parser = argparse.ArgumentParser(description='Dataset UCF101 Postprocessing') - parser.add_argument('--result_path', type=str) - parser.add_argument('--info_path', type=str) - parser.add_argument('--batch_size', type=int, default=1) - - args = parser.parse_args() - - return args - - -def main(): - args = parse_args() - with open(args.info_path,"r") as f: - l = list(map(lambda x:int(x.strip()), f.readlines())) - - num_samples = len(l) // args.batch_size - i = 0 - acc = 0 - while i < num_samples: - with open(args.result_path+str(i)+'_output_0.txt', 'r') as f: - lines = f.readlines() - lines = list(map(lambda x:x.strip().split(), lines)) - lines = np.array([[float(lines[m][n]) for n in range(101)]for m in range(args.batch_size)]).argmax(1) - for k in range(args.batch_size): - acc += int(lines[k] == l[i*args.batch_size + k]) - i += 1 - - print(acc / len(l)) - - -if __name__ == '__main__': +""" +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +============================================================================ +""" +# !/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import argparse +import numpy as np +from collections import OrderedDict +from mmaction.core import top_k_accuracy + + +def parse_args(): + parser = argparse.ArgumentParser(description='Dataset UCF101 Postprocessing') + parser.add_argument('--result_path', type=str) + parser.add_argument('--info_path', type=str) + parser.add_argument('--batch_size', type=int, default=1) + + args = parser.parse_args() + + return args + + +def main(): + args = parse_args() + with open(args.info_path,"r") as f: + l = list(map(lambda x:int(x.strip()), f.readlines())) + + num_samples = len(l) // args.batch_size + i = 0 + acc = 0 + while i < num_samples: + with open(args.result_path+str(i)+'_output_0.txt', 'r') as f: + lines = f.readlines() + lines = list(map(lambda x:x.strip().split(), lines)) + lines = np.array([[float(lines[m][n]) for n in range(101)]for m in range(args.batch_size)]).argmax(1) + for k in range(args.batch_size): + acc += int(lines[k] == l[i*args.batch_size + k]) + i += 1 + + print(acc / len(l)) + + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/knowledge/RotatE/LICENSE b/ACL_PyTorch/contrib/knowledge/RotatE/LICENSE index 797bf40e85c5d2986ebcec9cb51aed979ca88b82..04adf5cbc620ad190547b092fa449e36df5f7bf4 100644 --- a/ACL_PyTorch/contrib/knowledge/RotatE/LICENSE +++ b/ACL_PyTorch/contrib/knowledge/RotatE/LICENSE @@ -1,203 +1,203 @@ -Copyright 2018-2019 Open-MMLab. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2018-2019 Open-MMLab. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Copyright 2018-2019 Open-MMLab. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2019 Open-MMLab. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ACL_PyTorch/contrib/knowledge/RotatE/ReadME.md b/ACL_PyTorch/contrib/knowledge/RotatE/ReadME.md index 0d027928ada725aa4ad1188c56997c95ddad59aa..de6807b88d3beba1ab2a07e05bbb6e048c786d0a 100644 --- a/ACL_PyTorch/contrib/knowledge/RotatE/ReadME.md +++ b/ACL_PyTorch/contrib/knowledge/RotatE/ReadME.md @@ -1,41 +1,41 @@ -# RotatE模型PyTorch离线推理指导 - -## 1 环境准备 - -- **1.1 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装** - -``` -pip3.7 install -r requirements.txt -``` - -- **1.2 获取,修改与安装开源模型代码** - -``` -git clone https://github.com/DeepGraphLearning/KnowledgeGraphEmbedding -b master -cd KnowledgeGraphEmbedding -git reset --hard 2e440e0f9c687314d5ff67ead68ce985dc446e3a -cd .. -``` -- **1.3 [获取权重文件](https://www.aliyundrive.com/drive/folder/616a7eb758db2df6ae8448e4b34fe570510ad216)** - -- **1.4 开源模型代码里包含有数据集** - -- **1.5 获取[msame工具](https://gitee.com/ascend/tools/tree/master/msame)和[benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer)** - -将msame和benchmark.x86_64(或benchmark.aarch64)放到当前目录 - -## 2 离线推理 - -- **310上执行,执行时使npu-smi info查看设备状态,确保device空闲** - -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh -``` - -- **评测结果:** - -| 模型 | pth精度 | 310精度 | 性能基准 | 310性能 | -| ----------- | ------------------------------------------------------------ | ------- | -------------- | --------------- | -| RotatE-head bs1
RotatE-tail bs1| [**MRR:0.337**](https://github.com/DeepGraphLearning/KnowledgeGraphEmbedding) | MRR:0.336 | 21.9065fps
21.9091fps | 99.3504fps
104.9432fps | -| RotatE-head bs16
RotatE-tail bs16 | [**MRR:0.337**](https://github.com/DeepGraphLearning/KnowledgeGraphEmbedding) | MRR:0.336 | 22.2017fps
22.1964fps | 119.9172fps
129.7252fps | +# RotatE模型PyTorch离线推理指导 + +## 1 环境准备 + +- **1.1 安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装** + +``` +pip3.7 install -r requirements.txt +``` + +- **1.2 获取,修改与安装开源模型代码** + +``` +git clone https://github.com/DeepGraphLearning/KnowledgeGraphEmbedding -b master +cd KnowledgeGraphEmbedding +git reset --hard 2e440e0f9c687314d5ff67ead68ce985dc446e3a +cd .. +``` +- **1.3 [获取权重文件](https://www.aliyundrive.com/drive/folder/616a7eb758db2df6ae8448e4b34fe570510ad216)** + +- **1.4 开源模型代码里包含有数据集** + +- **1.5 获取[msame工具](https://gitee.com/ascend/tools/tree/master/msame)和[benchmark工具](https://gitee.com/ascend/cann-benchmark/tree/master/infer)** + +将msame和benchmark.x86_64(或benchmark.aarch64)放到当前目录 + +## 2 离线推理 + +- **310上执行,执行时使npu-smi info查看设备状态,确保device空闲** + +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh +``` + +- **评测结果:** + +| 模型 | pth精度 | 310精度 | 性能基准 | 310性能 | +| ----------- | ------------------------------------------------------------ | ------- | -------------- | --------------- | +| RotatE-head bs1
RotatE-tail bs1| [**MRR:0.337**](https://github.com/DeepGraphLearning/KnowledgeGraphEmbedding) | MRR:0.336 | 21.9065fps
21.9091fps | 99.3504fps
104.9432fps | +| RotatE-head bs16
RotatE-tail bs16 | [**MRR:0.337**](https://github.com/DeepGraphLearning/KnowledgeGraphEmbedding) | MRR:0.336 | 22.2017fps
22.1964fps | 119.9172fps
129.7252fps | diff --git a/ACL_PyTorch/contrib/knowledge/RotatE/get_info.py b/ACL_PyTorch/contrib/knowledge/RotatE/get_info.py index 7900a12b52190677dad622a0419652d7dea3ab18..07bf03fd842145b73cc76227b5aad2f45954e9e5 100644 --- a/ACL_PyTorch/contrib/knowledge/RotatE/get_info.py +++ b/ACL_PyTorch/contrib/knowledge/RotatE/get_info.py @@ -1,33 +1,33 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import pdb -import sys -from glob import glob - - -def get_bin_info(file_path, info_name): - bin_files = glob(os.path.join(file_path, '*.npz')) - with open(info_name, 'w') as file: - for index, img in enumerate(bin_files): - # pdb.set_trace() - content = ' '.join([str(index), img]) - file.write(content) - file.write('\n') - -if __name__ == '__main__': - file_path = sys.argv[1] - info_name = sys.argv[2] - get_bin_info(file_path, info_name) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import pdb +import sys +from glob import glob + + +def get_bin_info(file_path, info_name): + bin_files = glob(os.path.join(file_path, '*.npz')) + with open(info_name, 'w') as file: + for index, img in enumerate(bin_files): + # pdb.set_trace() + content = ' '.join([str(index), img]) + file.write(content) + file.write('\n') + +if __name__ == '__main__': + file_path = sys.argv[1] + info_name = sys.argv[2] + get_bin_info(file_path, info_name) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/knowledge/RotatE/modelzoo_level.txt b/ACL_PyTorch/contrib/knowledge/RotatE/modelzoo_level.txt index 83689985f26624b65a4c5ebb5f00a152618799ba..8c469d858afccf3026a8640799938f8de7b46fac 100644 --- a/ACL_PyTorch/contrib/knowledge/RotatE/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/knowledge/RotatE/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:PERFECT \ No newline at end of file diff --git a/ACL_PyTorch/contrib/knowledge/RotatE/requirements.txt b/ACL_PyTorch/contrib/knowledge/RotatE/requirements.txt index 41c2d7836f0d565c237e43c4319b4daf21b8dc4a..a220c00791e780651967dce844afcb4de38eb291 100644 --- a/ACL_PyTorch/contrib/knowledge/RotatE/requirements.txt +++ b/ACL_PyTorch/contrib/knowledge/RotatE/requirements.txt @@ -1,5 +1,5 @@ -torch == 1.8.0 -torchvision == 0.9.0 -onnx == 1.9.0 -numpy == 1.20.3 +torch == 1.8.0 +torchvision == 0.9.0 +onnx == 1.9.0 +numpy == 1.20.3 scikit-learn >= 0.20.2 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/knowledge/RotatE/rotate_postprocess.py b/ACL_PyTorch/contrib/knowledge/RotatE/rotate_postprocess.py index eb605845588b3a10d2e3bb6a2ad51d613eed7a98..2923c802bd24de92b98bbf8875b7669b03ef0204 100644 --- a/ACL_PyTorch/contrib/knowledge/RotatE/rotate_postprocess.py +++ b/ACL_PyTorch/contrib/knowledge/RotatE/rotate_postprocess.py @@ -1,121 +1,121 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import argparse -import pdb - -import torch -import os -import numpy as np - -def postProcesss(result_path, data_head, data_tail): - - data_mulu = os.listdir(result_path) - data_mulu.sort(key=lambda x: int(x.split('_')[1][0:])) - head_list_date = data_mulu[0] - head_mulu_path = os.path.join(result_path, head_list_date) - bin_head_list = os.listdir(head_mulu_path) - bin_head_list.sort(key=lambda x: int(x.split('-')[0][3:])) - - tail_list_date = data_mulu[1] - tail_mulu_path = os.path.join(result_path, tail_list_date) - bin_tail_list = os.listdir(tail_mulu_path) - bin_tail_list.sort(key=lambda x: int(x.split('-')[0][3:])) - head_ite_list = os.listdir(data_head+'/post') - tail_ite_list = os.listdir(data_tail+'/post') - - head_pos_list = os.listdir(data_head+'/possamp') - tail_pos_list = os.listdir(data_head + '/possamp') - head_ite_list.sort(key=lambda x: int(x.split('-')[0][3:])) - tail_ite_list.sort(key=lambda x: int(x.split('-')[0][3:])) - head_pos_list.sort(key=lambda x: int(x.split('-')[0][3:])) - tail_pos_list.sort(key=lambda x: int(x.split('-')[0][3:])) - - logs = [] - for i in range(len(bin_head_list)): - bin_path = os.path.join(head_mulu_path, bin_head_list[i]) - score = np.loadtxt(bin_path) - score = torch.from_numpy(score) - ite_path = os.path.join(data_head+'/post', head_ite_list[i]) - filter_bias = np.loadtxt(ite_path) - filter_bias = torch.from_numpy(filter_bias) - pos_path = os.path.join(data_head + '/possamp', head_pos_list[i]) - positive_sample = np.loadtxt(pos_path) - positive_sample = positive_sample.reshape(-1, 3) - score += filter_bias - score = torch.reshape(score, (-1, 14541)) - # Explicitly sort all the entities to ensure that there is no test exposure bias - argsort = torch.argsort(score, dim=1, descending=True) - positive_arg = positive_sample[:, 0] - - for i in range(len(score)): - # Notice that argsort is not ranking - ranking = (argsort[i, :] == positive_arg[i]).nonzero() - assert ranking.size(0) == 1 - # ranking + 1 is the true ranking used in evaluation metrics - ranking = 1 + ranking.item() - logs.append({ - 'MRR': 1.0 / ranking, - 'MR': float(ranking), - 'HITS@1': 1.0 if ranking <= 1 else 0.0, - 'HITS@3': 1.0 if ranking <= 3 else 0.0, - 'HITS@10': 1.0 if ranking <= 10 else 0.0, - }) - for i in range(len(bin_tail_list)): - bin_path = os.path.join(tail_mulu_path, bin_tail_list[i]) - score = np.loadtxt(bin_path) - score = torch.from_numpy(score) - ite_path = os.path.join(data_tail + '/post', tail_ite_list[i]) - filter_bias = np.loadtxt(ite_path) - filter_bias = torch.from_numpy(filter_bias) - pos_path = os.path.join(data_tail + '/possamp', tail_pos_list[i]) - positive_sample = np.loadtxt(pos_path) - positive_sample = positive_sample.reshape(-1,3) - score += filter_bias - score = torch.reshape(score,(-1,14541)) - - # Explicitly sort all the entities to ensure that there is no test exposure bias - argsort = torch.argsort(score, dim=1, descending=True) - positive_arg = positive_sample[:, 2] - - for i in range(len(score)): - # Notice that argsort is not ranking - ranking = (argsort[i, :] == positive_arg[i]).nonzero() - assert ranking.size(0) == 1 - # ranking + 1 is the true ranking used in evaluation metrics - ranking = 1 + ranking.item() - logs.append({ - 'MRR': 1.0 / ranking, - 'MR': float(ranking), - 'HITS@1': 1.0 if ranking <= 1 else 0.0, - 'HITS@3': 1.0 if ranking <= 3 else 0.0, - 'HITS@10': 1.0 if ranking <= 10 else 0.0, - }) - - metrics = {} - for metric in logs[0].keys(): - metrics[metric] = sum([log[metric] for log in logs]) / len(logs) - - return metrics - - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='postprocess of r2plus1d') - - parser.add_argument('--result_path', default=r'E:/huawei/KGE_inference/out') - parser.add_argument('--data_head', default=r'E:/huawei/KGE_inference/bin/head') - parser.add_argument('--data_tail', default=r'E:/huawei/KGE_inference/bin/tail') - opt = parser.parse_args() - metrics = postProcesss(opt.result_path, opt.data_head, opt.data_tail) - print(metrics) - +# Copyright 2021 Huawei Technologies Co., Ltd +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import argparse +import pdb + +import torch +import os +import numpy as np + +def postProcesss(result_path, data_head, data_tail): + + data_mulu = os.listdir(result_path) + data_mulu.sort(key=lambda x: int(x.split('_')[1][0:])) + head_list_date = data_mulu[0] + head_mulu_path = os.path.join(result_path, head_list_date) + bin_head_list = os.listdir(head_mulu_path) + bin_head_list.sort(key=lambda x: int(x.split('-')[0][3:])) + + tail_list_date = data_mulu[1] + tail_mulu_path = os.path.join(result_path, tail_list_date) + bin_tail_list = os.listdir(tail_mulu_path) + bin_tail_list.sort(key=lambda x: int(x.split('-')[0][3:])) + head_ite_list = os.listdir(data_head+'/post') + tail_ite_list = os.listdir(data_tail+'/post') + + head_pos_list = os.listdir(data_head+'/possamp') + tail_pos_list = os.listdir(data_head + '/possamp') + head_ite_list.sort(key=lambda x: int(x.split('-')[0][3:])) + tail_ite_list.sort(key=lambda x: int(x.split('-')[0][3:])) + head_pos_list.sort(key=lambda x: int(x.split('-')[0][3:])) + tail_pos_list.sort(key=lambda x: int(x.split('-')[0][3:])) + + logs = [] + for i in range(len(bin_head_list)): + bin_path = os.path.join(head_mulu_path, bin_head_list[i]) + score = np.loadtxt(bin_path) + score = torch.from_numpy(score) + ite_path = os.path.join(data_head+'/post', head_ite_list[i]) + filter_bias = np.loadtxt(ite_path) + filter_bias = torch.from_numpy(filter_bias) + pos_path = os.path.join(data_head + '/possamp', head_pos_list[i]) + positive_sample = np.loadtxt(pos_path) + positive_sample = positive_sample.reshape(-1, 3) + score += filter_bias + score = torch.reshape(score, (-1, 14541)) + # Explicitly sort all the entities to ensure that there is no test exposure bias + argsort = torch.argsort(score, dim=1, descending=True) + positive_arg = positive_sample[:, 0] + + for i in range(len(score)): + # Notice that argsort is not ranking + ranking = (argsort[i, :] == positive_arg[i]).nonzero() + assert ranking.size(0) == 1 + # ranking + 1 is the true ranking used in evaluation metrics + ranking = 1 + ranking.item() + logs.append({ + 'MRR': 1.0 / ranking, + 'MR': float(ranking), + 'HITS@1': 1.0 if ranking <= 1 else 0.0, + 'HITS@3': 1.0 if ranking <= 3 else 0.0, + 'HITS@10': 1.0 if ranking <= 10 else 0.0, + }) + for i in range(len(bin_tail_list)): + bin_path = os.path.join(tail_mulu_path, bin_tail_list[i]) + score = np.loadtxt(bin_path) + score = torch.from_numpy(score) + ite_path = os.path.join(data_tail + '/post', tail_ite_list[i]) + filter_bias = np.loadtxt(ite_path) + filter_bias = torch.from_numpy(filter_bias) + pos_path = os.path.join(data_tail + '/possamp', tail_pos_list[i]) + positive_sample = np.loadtxt(pos_path) + positive_sample = positive_sample.reshape(-1,3) + score += filter_bias + score = torch.reshape(score,(-1,14541)) + + # Explicitly sort all the entities to ensure that there is no test exposure bias + argsort = torch.argsort(score, dim=1, descending=True) + positive_arg = positive_sample[:, 2] + + for i in range(len(score)): + # Notice that argsort is not ranking + ranking = (argsort[i, :] == positive_arg[i]).nonzero() + assert ranking.size(0) == 1 + # ranking + 1 is the true ranking used in evaluation metrics + ranking = 1 + ranking.item() + logs.append({ + 'MRR': 1.0 / ranking, + 'MR': float(ranking), + 'HITS@1': 1.0 if ranking <= 1 else 0.0, + 'HITS@3': 1.0 if ranking <= 3 else 0.0, + 'HITS@10': 1.0 if ranking <= 10 else 0.0, + }) + + metrics = {} + for metric in logs[0].keys(): + metrics[metric] = sum([log[metric] for log in logs]) / len(logs) + + return metrics + + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='postprocess of r2plus1d') + + parser.add_argument('--result_path', default=r'E:/huawei/KGE_inference/out') + parser.add_argument('--data_head', default=r'E:/huawei/KGE_inference/bin/head') + parser.add_argument('--data_tail', default=r'E:/huawei/KGE_inference/bin/tail') + opt = parser.parse_args() + metrics = postProcesss(opt.result_path, opt.data_head, opt.data_tail) + print(metrics) + diff --git a/ACL_PyTorch/contrib/knowledge/RotatE/rotate_preprocess.py b/ACL_PyTorch/contrib/knowledge/RotatE/rotate_preprocess.py index a42480c8b3237ecff973f04c7b0c7fe6cac3417d..92585dc2898a20100811cabb26b5eff75e535a13 100644 --- a/ACL_PyTorch/contrib/knowledge/RotatE/rotate_preprocess.py +++ b/ACL_PyTorch/contrib/knowledge/RotatE/rotate_preprocess.py @@ -1,227 +1,227 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import argparse -import sys -sys.path.append(r'KnowledgeGraphEmbedding/codes/') -import logging -import os -import io -import pdb -import torch -import numpy as np - -import time -from torch.utils.data import DataLoader -import dataloader - -nowTime = time.strftime('%Y%m%d', time.localtime(time.time())) - -def parse_args(args=None): - parser = argparse.ArgumentParser( - description='Training and Testing Knowledge Graph Embedding Models', - usage='train.py [] [-h | --help]' - ) - - parser.add_argument('--data_path', type=str, default='./KnowledgeGraphEmbedding/data/FB15k-237') - parser.add_argument('--test_batch_size', default=6, type=int, help='valid/test batch size') - parser.add_argument('-cpu', '--cpu_num', default=10, type=int) - parser.add_argument('--output_path', default='bin/', type=str) - parser.add_argument('--output_head_post', default='head/post', type=str) - parser.add_argument('--output_tail_post', default='tail/post', type=str) - parser.add_argument('--output_head_pos', default='head/pos', type=str) - parser.add_argument('--output_head_neg', default='head/neg', type=str) - parser.add_argument('--output_head_mode', default='head/mode', type=str) - parser.add_argument('--output_head_pp', default='head/possamp', type=str) - parser.add_argument('--output_head_np', default='head/negsamp', type=str) - parser.add_argument('--output_tail_pos', default='tail/pos', type=str) - parser.add_argument('--output_tail_neg', default='tail/neg', type=str) - parser.add_argument('--output_tail_mode', default='tail/mode', type=str) - parser.add_argument('--output_tail_pp', default='tail/possamp', type=str) - parser.add_argument('--output_tail_np', default='tail/negsamp', type=str) - parser.add_argument('--nentity', type=int, default=0, help='DO NOT MANUALLY SET') - parser.add_argument('--nrelation', type=int, default=0, help='DO NOT MANUALLY SET') - arg = parser.parse_args(args) - arg.output_head_post = arg.output_path + arg.output_head_post - arg.output_tail_post = arg.output_path + arg.output_tail_post - arg.output_head_pos = arg.output_path + arg.output_head_pos - arg.output_head_neg = arg.output_path + arg.output_head_neg - arg.output_head_mode = arg.output_path + arg.output_head_mode - arg.output_head_pp = arg.output_path + arg.output_head_pp - arg.output_head_np = arg.output_path + arg.output_head_np - arg.output_tail_pos = arg.output_path + arg.output_tail_pos - arg.output_tail_neg = arg.output_path + arg.output_tail_neg - arg.output_tail_mode = arg.output_path + arg.output_tail_mode - arg.output_tail_pp = arg.output_path + arg.output_tail_pp - arg.output_tail_np = arg.output_path + arg.output_tail_np - return arg - -def read_triple(file_path, entity2id, relation2id): - ''' - Read triples and map them into ids. - ''' - triples = [] - with open(file_path) as fin: - for line in fin: - h, r, t = line.strip().split('\t') - triples.append((entity2id[h], relation2id[r], entity2id[t])) - return triples - -def to_numpy32(tensor): - return tensor.detach().cpu().numpy().astype(np.int32) if tensor.requires_grad else tensor.cpu().numpy().astype(np.int32) - -def to_numpy64(tensor): - return tensor.detach().cpu().numpy().astype(np.int64) if tensor.requires_grad else tensor.cpu().numpy().astype(np.int64) - -def main(args): - - with open(os.path.join(args.data_path, 'entities.dict')) as fin: - entity2id = dict() - for line in fin: - eid, entity = line.strip().split('\t') - entity2id[entity] = int(eid) - - with open(os.path.join(args.data_path, 'relations.dict')) as fin: - relation2id = dict() - for line in fin: - rid, relation = line.strip().split('\t') - relation2id[relation] = int(rid) - - - nentity = len(entity2id) - nrelation = len(relation2id) - - args.nentity = nentity - args.nrelation = nrelation - - - train_triples = read_triple(os.path.join(args.data_path, 'train.txt'), entity2id, relation2id) - logging.info('#train: %d' % len(train_triples)) - valid_triples = read_triple(os.path.join(args.data_path, 'valid.txt'), entity2id, relation2id) - logging.info('#valid: %d' % len(valid_triples)) - test_triples = read_triple(os.path.join(args.data_path, 'test.txt'), entity2id, relation2id) - logging.info('#test: %d' % len(test_triples)) - - # All true triples - all_true_triples = train_triples + valid_triples + test_triples - - test_dataloader_head = DataLoader( - dataloader.TestDataset( - test_triples, - all_true_triples, - args.nentity, - args.nrelation, - 'head-batch' - ), - batch_size=args.test_batch_size, - num_workers=max(1, args.cpu_num // 2), - collate_fn=dataloader.TestDataset.collate_fn - ) - - test_dataloader_tail = DataLoader( - dataloader.TestDataset( - test_triples, - all_true_triples, - args.nentity, - args.nrelation, - 'tail-batch' - ), - batch_size=args.test_batch_size, - num_workers=max(1, args.cpu_num // 2), - collate_fn=dataloader.TestDataset.collate_fn - ) - - test_dataset_list = [test_dataloader_head, test_dataloader_tail] - # test_dataset_list = [test_dataloader_tail] - for test_dataset in test_dataset_list: - for index, value in enumerate(test_dataset): - if(value[0].shape[0] == args.test_batch_size): - batch_pos = value[0] - batch_pos = to_numpy64(batch_pos) - - batch_neg = value[1] - batch_neg = to_numpy32(batch_neg) - batch_ite = value[2].numpy() - batch_mode = value[3] - - print('preprocessing ' + str(index)) - - if not os.path.exists(str(args.output_head_pos)): - os.makedirs(str(args.output_head_pos)) - if not os.path.exists(str(args.output_head_neg)): - os.makedirs(str(args.output_head_neg)) - if not os.path.exists(str(args.output_head_mode)): - os.makedirs(str(args.output_head_mode)) - if not os.path.exists(str(args.output_head_pp)): - os.makedirs(str(args.output_head_pp)) - if not os.path.exists(str(args.output_tail_pos)): - os.makedirs(str(args.output_tail_pos)) - if not os.path.exists(str(args.output_tail_neg)): - os.makedirs(str(args.output_tail_neg)) - if not os.path.exists(str(args.output_tail_mode)): - os.makedirs(str(args.output_tail_mode)) - if not os.path.exists(str(args.output_tail_pp)): - os.makedirs(str(args.output_tail_pp)) - - - if batch_mode == 'head-batch': - save_path_pos = str(args.output_head_pos) + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( - int(args.test_batch_size) * (index + 1) - 1) + '.bin' - save_path_pos_txt = str(args.output_head_pp) + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( - int(args.test_batch_size) * (index + 1) - 1) + '.txt' - batch_pos.tofile(str(save_path_pos)) - np.savetxt(save_path_pos_txt, batch_pos) - - save_path_neg = str(args.output_head_neg) + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( - int(args.test_batch_size) * (index + 1) - 1) + '.bin' - batch_neg.tofile(str(save_path_neg)) - - save_post_dir = str(args.output_head_post) - if not os.path.exists(save_post_dir): - os.makedirs(save_post_dir) - save_path_post = save_post_dir + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( - int(args.test_batch_size) * (index + 1) - 1) + '.txt' - np.savetxt(save_path_post, batch_ite) - print(index, str(save_path_post), "save done!") - print("----------------head---next-----------------------------") - - if batch_mode == 'tail-batch': - - save_path_pos = str(args.output_tail_pos) + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( - int(args.test_batch_size) * (index + 1) - 1) + '.bin' - save_path_pos_txt = str(args.output_tail_pp) + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( - int(args.test_batch_size) * (index + 1) - 1) + '.txt' - batch_pos.tofile(str(save_path_pos)) - np.savetxt(save_path_pos_txt, batch_pos) - - save_path_neg = str(args.output_tail_neg) + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( - int(args.test_batch_size) * (index + 1) - 1) + '.bin' - batch_neg.tofile(str(save_path_neg)) - - print(index, str(save_path_neg), "save done!") - - save_post_dir = str(args.output_tail_post) - if not os.path.exists(save_post_dir): - os.makedirs(save_post_dir) - save_path_post = save_post_dir + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( - int(args.test_batch_size) * (index + 1) - 1) + '.txt' - np.savetxt(save_path_post, batch_ite) - print(index, str(save_path_post), "save done!") - print("---------------tail----next-----------------------------") - - -if __name__ == '__main__': - main(parse_args()) +# Copyright 2021 Huawei Technologies Co., Ltd +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import argparse +import sys +sys.path.append(r'KnowledgeGraphEmbedding/codes/') +import logging +import os +import io +import pdb +import torch +import numpy as np + +import time +from torch.utils.data import DataLoader +import dataloader + +nowTime = time.strftime('%Y%m%d', time.localtime(time.time())) + +def parse_args(args=None): + parser = argparse.ArgumentParser( + description='Training and Testing Knowledge Graph Embedding Models', + usage='train.py [] [-h | --help]' + ) + + parser.add_argument('--data_path', type=str, default='./KnowledgeGraphEmbedding/data/FB15k-237') + parser.add_argument('--test_batch_size', default=6, type=int, help='valid/test batch size') + parser.add_argument('-cpu', '--cpu_num', default=10, type=int) + parser.add_argument('--output_path', default='bin/', type=str) + parser.add_argument('--output_head_post', default='head/post', type=str) + parser.add_argument('--output_tail_post', default='tail/post', type=str) + parser.add_argument('--output_head_pos', default='head/pos', type=str) + parser.add_argument('--output_head_neg', default='head/neg', type=str) + parser.add_argument('--output_head_mode', default='head/mode', type=str) + parser.add_argument('--output_head_pp', default='head/possamp', type=str) + parser.add_argument('--output_head_np', default='head/negsamp', type=str) + parser.add_argument('--output_tail_pos', default='tail/pos', type=str) + parser.add_argument('--output_tail_neg', default='tail/neg', type=str) + parser.add_argument('--output_tail_mode', default='tail/mode', type=str) + parser.add_argument('--output_tail_pp', default='tail/possamp', type=str) + parser.add_argument('--output_tail_np', default='tail/negsamp', type=str) + parser.add_argument('--nentity', type=int, default=0, help='DO NOT MANUALLY SET') + parser.add_argument('--nrelation', type=int, default=0, help='DO NOT MANUALLY SET') + arg = parser.parse_args(args) + arg.output_head_post = arg.output_path + arg.output_head_post + arg.output_tail_post = arg.output_path + arg.output_tail_post + arg.output_head_pos = arg.output_path + arg.output_head_pos + arg.output_head_neg = arg.output_path + arg.output_head_neg + arg.output_head_mode = arg.output_path + arg.output_head_mode + arg.output_head_pp = arg.output_path + arg.output_head_pp + arg.output_head_np = arg.output_path + arg.output_head_np + arg.output_tail_pos = arg.output_path + arg.output_tail_pos + arg.output_tail_neg = arg.output_path + arg.output_tail_neg + arg.output_tail_mode = arg.output_path + arg.output_tail_mode + arg.output_tail_pp = arg.output_path + arg.output_tail_pp + arg.output_tail_np = arg.output_path + arg.output_tail_np + return arg + +def read_triple(file_path, entity2id, relation2id): + ''' + Read triples and map them into ids. + ''' + triples = [] + with open(file_path) as fin: + for line in fin: + h, r, t = line.strip().split('\t') + triples.append((entity2id[h], relation2id[r], entity2id[t])) + return triples + +def to_numpy32(tensor): + return tensor.detach().cpu().numpy().astype(np.int32) if tensor.requires_grad else tensor.cpu().numpy().astype(np.int32) + +def to_numpy64(tensor): + return tensor.detach().cpu().numpy().astype(np.int64) if tensor.requires_grad else tensor.cpu().numpy().astype(np.int64) + +def main(args): + + with open(os.path.join(args.data_path, 'entities.dict')) as fin: + entity2id = dict() + for line in fin: + eid, entity = line.strip().split('\t') + entity2id[entity] = int(eid) + + with open(os.path.join(args.data_path, 'relations.dict')) as fin: + relation2id = dict() + for line in fin: + rid, relation = line.strip().split('\t') + relation2id[relation] = int(rid) + + + nentity = len(entity2id) + nrelation = len(relation2id) + + args.nentity = nentity + args.nrelation = nrelation + + + train_triples = read_triple(os.path.join(args.data_path, 'train.txt'), entity2id, relation2id) + logging.info('#train: %d' % len(train_triples)) + valid_triples = read_triple(os.path.join(args.data_path, 'valid.txt'), entity2id, relation2id) + logging.info('#valid: %d' % len(valid_triples)) + test_triples = read_triple(os.path.join(args.data_path, 'test.txt'), entity2id, relation2id) + logging.info('#test: %d' % len(test_triples)) + + # All true triples + all_true_triples = train_triples + valid_triples + test_triples + + test_dataloader_head = DataLoader( + dataloader.TestDataset( + test_triples, + all_true_triples, + args.nentity, + args.nrelation, + 'head-batch' + ), + batch_size=args.test_batch_size, + num_workers=max(1, args.cpu_num // 2), + collate_fn=dataloader.TestDataset.collate_fn + ) + + test_dataloader_tail = DataLoader( + dataloader.TestDataset( + test_triples, + all_true_triples, + args.nentity, + args.nrelation, + 'tail-batch' + ), + batch_size=args.test_batch_size, + num_workers=max(1, args.cpu_num // 2), + collate_fn=dataloader.TestDataset.collate_fn + ) + + test_dataset_list = [test_dataloader_head, test_dataloader_tail] + # test_dataset_list = [test_dataloader_tail] + for test_dataset in test_dataset_list: + for index, value in enumerate(test_dataset): + if(value[0].shape[0] == args.test_batch_size): + batch_pos = value[0] + batch_pos = to_numpy64(batch_pos) + + batch_neg = value[1] + batch_neg = to_numpy32(batch_neg) + batch_ite = value[2].numpy() + batch_mode = value[3] + + print('preprocessing ' + str(index)) + + if not os.path.exists(str(args.output_head_pos)): + os.makedirs(str(args.output_head_pos)) + if not os.path.exists(str(args.output_head_neg)): + os.makedirs(str(args.output_head_neg)) + if not os.path.exists(str(args.output_head_mode)): + os.makedirs(str(args.output_head_mode)) + if not os.path.exists(str(args.output_head_pp)): + os.makedirs(str(args.output_head_pp)) + if not os.path.exists(str(args.output_tail_pos)): + os.makedirs(str(args.output_tail_pos)) + if not os.path.exists(str(args.output_tail_neg)): + os.makedirs(str(args.output_tail_neg)) + if not os.path.exists(str(args.output_tail_mode)): + os.makedirs(str(args.output_tail_mode)) + if not os.path.exists(str(args.output_tail_pp)): + os.makedirs(str(args.output_tail_pp)) + + + if batch_mode == 'head-batch': + save_path_pos = str(args.output_head_pos) + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( + int(args.test_batch_size) * (index + 1) - 1) + '.bin' + save_path_pos_txt = str(args.output_head_pp) + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( + int(args.test_batch_size) * (index + 1) - 1) + '.txt' + batch_pos.tofile(str(save_path_pos)) + np.savetxt(save_path_pos_txt, batch_pos) + + save_path_neg = str(args.output_head_neg) + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( + int(args.test_batch_size) * (index + 1) - 1) + '.bin' + batch_neg.tofile(str(save_path_neg)) + + save_post_dir = str(args.output_head_post) + if not os.path.exists(save_post_dir): + os.makedirs(save_post_dir) + save_path_post = save_post_dir + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( + int(args.test_batch_size) * (index + 1) - 1) + '.txt' + np.savetxt(save_path_post, batch_ite) + print(index, str(save_path_post), "save done!") + print("----------------head---next-----------------------------") + + if batch_mode == 'tail-batch': + + save_path_pos = str(args.output_tail_pos) + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( + int(args.test_batch_size) * (index + 1) - 1) + '.bin' + save_path_pos_txt = str(args.output_tail_pp) + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( + int(args.test_batch_size) * (index + 1) - 1) + '.txt' + batch_pos.tofile(str(save_path_pos)) + np.savetxt(save_path_pos_txt, batch_pos) + + save_path_neg = str(args.output_tail_neg) + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( + int(args.test_batch_size) * (index + 1) - 1) + '.bin' + batch_neg.tofile(str(save_path_neg)) + + print(index, str(save_path_neg), "save done!") + + save_post_dir = str(args.output_tail_post) + if not os.path.exists(save_post_dir): + os.makedirs(save_post_dir) + save_path_post = save_post_dir + '/bin' + str(int(args.test_batch_size) * index) + '-' + str( + int(args.test_batch_size) * (index + 1) - 1) + '.txt' + np.savetxt(save_path_post, batch_ite) + print(index, str(save_path_post), "save done!") + print("---------------tail----next-----------------------------") + + +if __name__ == '__main__': + main(parse_args()) diff --git a/ACL_PyTorch/contrib/knowledge/RotatE/rotate_pth2onnx.py b/ACL_PyTorch/contrib/knowledge/RotatE/rotate_pth2onnx.py index 8c36287bab502f23aff6252def28ce8775cb0e05..0f62a827ebcc2b2b747534132b151fe24f82a85d 100644 --- a/ACL_PyTorch/contrib/knowledge/RotatE/rotate_pth2onnx.py +++ b/ACL_PyTorch/contrib/knowledge/RotatE/rotate_pth2onnx.py @@ -1,73 +1,73 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import pdb -import sys -sys.path.append(r'KnowledgeGraphEmbedding/codes/') -import numpy as np -import torch - -import argparse - -from model import KGEModel - -def to_numpy32(tensor): - return tensor.detach().cpu().numpy().astype(np.int32) if tensor.requires_grad else tensor.cpu().numpy().astype(np.int32) - -def to_numpy64(tensor): - return tensor.detach().cpu().numpy().astype(np.int64) if tensor.requires_grad else tensor.cpu().numpy().astype(np.int64) - -def pth2onnx(input_file, output_file, bs, mode): - kge_model = KGEModel( - model_name='RotatE', - nentity=14541, - nrelation=237, - hidden_dim=1000, - gamma=9.0, - double_entity_embedding=True, - double_relation_embedding=False - ) - - checkpoint = torch.load(input_file, map_location='cpu') - kge_model.load_state_dict(checkpoint['model_state_dict']) - for param_tensor in kge_model.state_dict(): - print(param_tensor, "\t", kge_model.state_dict()[param_tensor].size()) - input_names = ["pos", "neg"] - output_names = ["score"] - dynamic_axes = {'pos': {0: '-1'}, 'neg': {0: '-1'}} - # pdb.set_trace() - head = torch.randint(0, 14541, (bs, 1)) - relation = torch.randint(0, 233, (bs, 1)) - tail = torch.randint(0, 14541, (bs, 1)) - input1 = [] - for j in range(bs): - inp = [] - for i in range(14541): - inp.append(i) - input1.append(inp) - negative_sample = torch.from_numpy(np.array(input1)) - - positive_sample = torch.cat([head, relation, tail], dim=1) - positive_sample = torch.from_numpy(to_numpy64(positive_sample)) - negative_sample = torch.from_numpy(to_numpy32(negative_sample)) - - torch.onnx.export(kge_model, ((positive_sample, negative_sample), mode), output_file, input_names=input_names, dynamic_axes=dynamic_axes, - output_names=output_names, opset_version=11, verbose=True) - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='postprocess of r2plus1d') - parser.add_argument('--pth_path', default=r'./checkpoint') - parser.add_argument('--onnx_path', default=r'./kge_onnx_16_tail.onnx') - parser.add_argument('--batch_size', default=16, type=int) - parser.add_argument('--mode', default=r'tail-batch', help='select head-batch or tail-batch') - - args = parser.parse_args() +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import pdb +import sys +sys.path.append(r'KnowledgeGraphEmbedding/codes/') +import numpy as np +import torch + +import argparse + +from model import KGEModel + +def to_numpy32(tensor): + return tensor.detach().cpu().numpy().astype(np.int32) if tensor.requires_grad else tensor.cpu().numpy().astype(np.int32) + +def to_numpy64(tensor): + return tensor.detach().cpu().numpy().astype(np.int64) if tensor.requires_grad else tensor.cpu().numpy().astype(np.int64) + +def pth2onnx(input_file, output_file, bs, mode): + kge_model = KGEModel( + model_name='RotatE', + nentity=14541, + nrelation=237, + hidden_dim=1000, + gamma=9.0, + double_entity_embedding=True, + double_relation_embedding=False + ) + + checkpoint = torch.load(input_file, map_location='cpu') + kge_model.load_state_dict(checkpoint['model_state_dict']) + for param_tensor in kge_model.state_dict(): + print(param_tensor, "\t", kge_model.state_dict()[param_tensor].size()) + input_names = ["pos", "neg"] + output_names = ["score"] + dynamic_axes = {'pos': {0: '-1'}, 'neg': {0: '-1'}} + # pdb.set_trace() + head = torch.randint(0, 14541, (bs, 1)) + relation = torch.randint(0, 233, (bs, 1)) + tail = torch.randint(0, 14541, (bs, 1)) + input1 = [] + for j in range(bs): + inp = [] + for i in range(14541): + inp.append(i) + input1.append(inp) + negative_sample = torch.from_numpy(np.array(input1)) + + positive_sample = torch.cat([head, relation, tail], dim=1) + positive_sample = torch.from_numpy(to_numpy64(positive_sample)) + negative_sample = torch.from_numpy(to_numpy32(negative_sample)) + + torch.onnx.export(kge_model, ((positive_sample, negative_sample), mode), output_file, input_names=input_names, dynamic_axes=dynamic_axes, + output_names=output_names, opset_version=11, verbose=True) + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='postprocess of r2plus1d') + parser.add_argument('--pth_path', default=r'./checkpoint') + parser.add_argument('--onnx_path', default=r'./kge_onnx_16_tail.onnx') + parser.add_argument('--batch_size', default=16, type=int) + parser.add_argument('--mode', default=r'tail-batch', help='select head-batch or tail-batch') + + args = parser.parse_args() pth2onnx(args.pth_path, args.onnx_path, args.batch_size, args.mode) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/nlp/BertSum/BertSum-pth2onnx.py b/ACL_PyTorch/contrib/nlp/BertSum/BertSum-pth2onnx.py index bc730838baacc27b2beaf06867670486dcac0377..6fbbab39b10f53598a69db2982f2c83c1d70c45c 100644 --- a/ACL_PyTorch/contrib/nlp/BertSum/BertSum-pth2onnx.py +++ b/ACL_PyTorch/contrib/nlp/BertSum/BertSum-pth2onnx.py @@ -1,119 +1,119 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import torch -import os -import sys -import argparse -import numpy as np -from pytorch_pretrained_bert import BertConfig -from models.model_builder import Summarizer - -model_flags = ['hidden_size', 'ff_size', 'heads', 'inter_layers','encoder','ff_actv', 'use_interval','rnn_size'] - -def str2bool(v): - if v.lower() in ('yes', 'true', 't', 'y', '1'): - return True - elif v.lower() in ('no', 'false', 'f', 'n', '0'): - return False - else: - raise argparse.ArgumentTypeError('Boolean value expected.') - -def main(args): - input_names=['src','segs','clss','mask','mask_cls'] - output_names = ["output"] - onnx_path = args.onnx_path - device = "cpu" if args.visible_gpus == '-1' else "cuda" - checkpoint = torch.load(args.path, map_location='cpu') - opt = vars(checkpoint['opt']) - for k in opt.keys(): - if (k in model_flags): - setattr(args, k, opt[k]) - config = BertConfig.from_json_file(args.bert_config_path) - model = Summarizer(args, device, load_pretrained_bert=False, bert_config = config) - model.load_cp(checkpoint) - model.eval() - cur_path = os.getcwd() - src = np.fromfile(f'{cur_path}/pre_data/src/data_1.bin', dtype=np.int64) - segs = np.fromfile(f'{cur_path}/pre_data/segs/data_1.bin', dtype=np.int64) - clss = np.fromfile(f'{cur_path}/pre_data/clss/data_1.bin', dtype=np.int64) - mask = np.fromfile(f'{cur_path}/pre_data/mask/data_1.bin', dtype=np.bool_) - mask_cls = np.fromfile(f'{cur_path}/pre_data/mask_cls/data_1.bin', dtype=np.bool_) - print(src.shape) - print(segs.shape) - print(clss.shape) - print(mask.shape) - print(mask_cls.shape) - #-----------------------------13000----------------------------- - dummy_input0 = torch.from_numpy(src).reshape(1,512) - dummy_input1 = torch.from_numpy(segs).reshape(1,512) - dummy_input2 = torch.from_numpy(clss).reshape(1,37) - dummy_input3 = torch.from_numpy(mask).reshape(1,512) - dummy_input4 = torch.from_numpy(mask_cls).reshape(1,37) - #--------------------------------------------------------------------''' - torch.onnx.export(model,(dummy_input0,dummy_input1,dummy_input2,dummy_input3,dummy_input4),onnx_path,input_names = input_names,output_names=output_names,verbose=True,opset_version=9) - -if __name__ =="__main__": - parser = argparse.ArgumentParser() - parser.add_argument("-encoder", default='classifier', type=str, choices=['classifier','transformer','rnn','baseline']) - parser.add_argument("-mode", default='train', type=str, choices=['train','validate','test']) - parser.add_argument("-bert_data_path", default='../bert_data') - parser.add_argument("-model_path", default='../models/') - parser.add_argument("-result_path", default='../results/cnndm') - parser.add_argument("-temp_dir", default='../temp') - parser.add_argument("-bert_config_path", default='../bert_config_uncased_base.json') - - parser.add_argument("-batch_size", default=1000, type=int) - - parser.add_argument("-use_interval", type=str2bool, nargs='?',const=True,default=True) - parser.add_argument("-hidden_size", default=128, type=int) - parser.add_argument("-ff_size", default=512, type=int) - parser.add_argument("-heads", default=4, type=int) - parser.add_argument("-inter_layers", default=2, type=int) - parser.add_argument("-rnn_size", default=512, type=int) - - parser.add_argument("-param_init", default=0, type=float) - parser.add_argument("-param_init_glorot", type=str2bool, nargs='?',const=True,default=True) - parser.add_argument("-dropout", default=0.1, type=float) - parser.add_argument("-optim", default='adam', type=str) - parser.add_argument("-lr", default=1, type=float) - parser.add_argument("-beta1", default= 0.9, type=float) - parser.add_argument("-beta2", default=0.999, type=float) - parser.add_argument("-decay_method", default='', type=str) - parser.add_argument("-warmup_steps", default=8000, type=int) - parser.add_argument("-max_grad_norm", default=0, type=float) - - parser.add_argument("-save_checkpoint_steps", default=5, type=int) - parser.add_argument("-accum_count", default=1, type=int) - parser.add_argument("-world_size", default=1, type=int) - parser.add_argument("-report_every", default=1, type=int) - parser.add_argument("-train_steps", default=1000, type=int) - parser.add_argument("-recall_eval", type=str2bool, nargs='?',const=True,default=False) - - - parser.add_argument('-visible_gpus', default='-1', type=str) - parser.add_argument('-gpu_ranks', default='0', type=str) - parser.add_argument('-log_file', default='../logs/cnndm.log') - parser.add_argument('-dataset', default='') - parser.add_argument('-seed', default=666, type=int) - - parser.add_argument("-test_all", type=str2bool, nargs='?',const=True,default=False) - parser.add_argument("-test_from", default='') - parser.add_argument("-train_from", default='') - parser.add_argument("-report_rouge", type=str2bool, nargs='?',const=True,default=True) - parser.add_argument("-block_trigram", type=str2bool, nargs='?', const=True, default=True) - parser.add_argument("-onnx_path", default="") - parser.add_argument("-path", default="") - - args = parser.parse_args() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import torch +import os +import sys +import argparse +import numpy as np +from pytorch_pretrained_bert import BertConfig +from models.model_builder import Summarizer + +model_flags = ['hidden_size', 'ff_size', 'heads', 'inter_layers','encoder','ff_actv', 'use_interval','rnn_size'] + +def str2bool(v): + if v.lower() in ('yes', 'true', 't', 'y', '1'): + return True + elif v.lower() in ('no', 'false', 'f', 'n', '0'): + return False + else: + raise argparse.ArgumentTypeError('Boolean value expected.') + +def main(args): + input_names=['src','segs','clss','mask','mask_cls'] + output_names = ["output"] + onnx_path = args.onnx_path + device = "cpu" if args.visible_gpus == '-1' else "cuda" + checkpoint = torch.load(args.path, map_location='cpu') + opt = vars(checkpoint['opt']) + for k in opt.keys(): + if (k in model_flags): + setattr(args, k, opt[k]) + config = BertConfig.from_json_file(args.bert_config_path) + model = Summarizer(args, device, load_pretrained_bert=False, bert_config = config) + model.load_cp(checkpoint) + model.eval() + cur_path = os.getcwd() + src = np.fromfile(f'{cur_path}/pre_data/src/data_1.bin', dtype=np.int64) + segs = np.fromfile(f'{cur_path}/pre_data/segs/data_1.bin', dtype=np.int64) + clss = np.fromfile(f'{cur_path}/pre_data/clss/data_1.bin', dtype=np.int64) + mask = np.fromfile(f'{cur_path}/pre_data/mask/data_1.bin', dtype=np.bool_) + mask_cls = np.fromfile(f'{cur_path}/pre_data/mask_cls/data_1.bin', dtype=np.bool_) + print(src.shape) + print(segs.shape) + print(clss.shape) + print(mask.shape) + print(mask_cls.shape) + #-----------------------------13000----------------------------- + dummy_input0 = torch.from_numpy(src).reshape(1,512) + dummy_input1 = torch.from_numpy(segs).reshape(1,512) + dummy_input2 = torch.from_numpy(clss).reshape(1,37) + dummy_input3 = torch.from_numpy(mask).reshape(1,512) + dummy_input4 = torch.from_numpy(mask_cls).reshape(1,37) + #--------------------------------------------------------------------''' + torch.onnx.export(model,(dummy_input0,dummy_input1,dummy_input2,dummy_input3,dummy_input4),onnx_path,input_names = input_names,output_names=output_names,verbose=True,opset_version=9) + +if __name__ =="__main__": + parser = argparse.ArgumentParser() + parser.add_argument("-encoder", default='classifier', type=str, choices=['classifier','transformer','rnn','baseline']) + parser.add_argument("-mode", default='train', type=str, choices=['train','validate','test']) + parser.add_argument("-bert_data_path", default='../bert_data') + parser.add_argument("-model_path", default='../models/') + parser.add_argument("-result_path", default='../results/cnndm') + parser.add_argument("-temp_dir", default='../temp') + parser.add_argument("-bert_config_path", default='../bert_config_uncased_base.json') + + parser.add_argument("-batch_size", default=1000, type=int) + + parser.add_argument("-use_interval", type=str2bool, nargs='?',const=True,default=True) + parser.add_argument("-hidden_size", default=128, type=int) + parser.add_argument("-ff_size", default=512, type=int) + parser.add_argument("-heads", default=4, type=int) + parser.add_argument("-inter_layers", default=2, type=int) + parser.add_argument("-rnn_size", default=512, type=int) + + parser.add_argument("-param_init", default=0, type=float) + parser.add_argument("-param_init_glorot", type=str2bool, nargs='?',const=True,default=True) + parser.add_argument("-dropout", default=0.1, type=float) + parser.add_argument("-optim", default='adam', type=str) + parser.add_argument("-lr", default=1, type=float) + parser.add_argument("-beta1", default= 0.9, type=float) + parser.add_argument("-beta2", default=0.999, type=float) + parser.add_argument("-decay_method", default='', type=str) + parser.add_argument("-warmup_steps", default=8000, type=int) + parser.add_argument("-max_grad_norm", default=0, type=float) + + parser.add_argument("-save_checkpoint_steps", default=5, type=int) + parser.add_argument("-accum_count", default=1, type=int) + parser.add_argument("-world_size", default=1, type=int) + parser.add_argument("-report_every", default=1, type=int) + parser.add_argument("-train_steps", default=1000, type=int) + parser.add_argument("-recall_eval", type=str2bool, nargs='?',const=True,default=False) + + + parser.add_argument('-visible_gpus', default='-1', type=str) + parser.add_argument('-gpu_ranks', default='0', type=str) + parser.add_argument('-log_file', default='../logs/cnndm.log') + parser.add_argument('-dataset', default='') + parser.add_argument('-seed', default=666, type=int) + + parser.add_argument("-test_all", type=str2bool, nargs='?',const=True,default=False) + parser.add_argument("-test_from", default='') + parser.add_argument("-train_from", default='') + parser.add_argument("-report_rouge", type=str2bool, nargs='?',const=True,default=True) + parser.add_argument("-block_trigram", type=str2bool, nargs='?', const=True, default=True) + parser.add_argument("-onnx_path", default="") + parser.add_argument("-path", default="") + + args = parser.parse_args() main(args) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/nlp/BertSum/BertSum_pth_postprocess.py b/ACL_PyTorch/contrib/nlp/BertSum/BertSum_pth_postprocess.py index 695e8abca86a49f6be865d6e040041e3e9de0b9c..67edaa126955e390539fb9742ec62abc2b71debc 100644 --- a/ACL_PyTorch/contrib/nlp/BertSum/BertSum_pth_postprocess.py +++ b/ACL_PyTorch/contrib/nlp/BertSum/BertSum_pth_postprocess.py @@ -1,275 +1,275 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import os -import sys -import argparse -import glob -import numpy as np -from pytorch_pretrained_bert import BertConfig -from models.model_builder import Summarizer -from models import data_loader -from models.data_loader import load_dataset -from models.stats import Statistics -from others.utils import test_rouge -from others.logging import logger - -def str2bool(v): - if v.lower() in ('yes', 'true', 't', 'y', '1'): - return True - elif v.lower() in ('no', 'false', 'f', 'n', '0'): - return False - else: - raise argparse.ArgumentTypeError('Boolean value expected.') - -def rouge_results_to_str(results_dict): - return ">> ROUGE-F(1/2/3/l): {:.2f}/{:.2f}/{:.2f}\nROUGE-R(1/2/3/l): {:.2f}/{:.2f}/{:.2f}\n".format( - results_dict["rouge_1_f_score"] * 100, - results_dict["rouge_2_f_score"] * 100, - results_dict["rouge_l_f_score"] * 100, - results_dict["rouge_1_recall"] * 100, - results_dict["rouge_2_recall"] * 100, - results_dict["rouge_l_recall"] * 100 - ) - -def pre_postprocess(args): - File = os.listdir(args.path_1) - File1 = os.listdir(args.path_2) - list2 = [] - for file in File1: - list2.append(file) - Doc = [] - SENT_SCORES = [] - OUTPUT = [] - for file in sorted(File): - Doc.append(file[0:-6]) - Doc = list(set(Doc)) #grip repeated element - for i in range(len(Doc)): #deal after sorting - ff = 'data_'+str(i)+'_output' - sent_scores = np.fromfile(f'{args.path_1}/{ff}_0.bin', dtype=np.float32) - sent_scores = torch.tensor(sent_scores.reshape(1,sent_scores.shape[0])) - output = np.fromfile(f'{args.path_1}/{ff}_1.bin', dtype=np.bool_) - print(output.shape) - output = torch.tensor(output.reshape(1,37)) - document = ff+'_0.txt' - if document in list2: - doc = document[0:-6] - sent_scores1 = np.fromfile(f'{args.path_2}/{doc}_0.bin', dtype=np.float32) - sent_scores1 = torch.tensor(sent_scores1.reshape(1,sent_scores1.shape[0])) - #############add zero to keep same dimension############## - if sent_scores1.shape[1] > sent_scores.shape[1]: - add_zero = (torch.zeros([1,sent_scores1.shape[1]-sent_scores.shape[1]])) - sent_scores = torch.cat([sent_scores,add_zero],dim=1) - if sent_scores1.shape[1] < sent_scores.shape[1]: - add_zero = (torch.zeros([1,sent_scores.shape[1]-sent_scores1.shape[1]])) - sent_scores1 = torch.cat([sent_scores1,add_zero],dim=1) - ########################################################## - output1 = np.fromfile(f'{args.path_2}/{doc}_1.bin', dtype=np.bool_) - output1 = torch.tensor(output1.reshape(1,37)) - sent_scores = torch.cat([sent_scores,sent_scores1],dim=0) - output = torch.cat([output,output1],dim=0) - SENT_SCORES.append(sent_scores) - OUTPUT.append(output) - test_iter = data_loader.Dataloader(args, load_dataset(args, 'test', shuffle=False), - args.batch_size, device, - shuffle=False, is_test=True) - i=0 - for batch in test_iter: - labels = batch.labels - if SENT_SCORES[i].shape[0] == 1: - if SENT_SCORES[i].shape[1] > labels.shape[1]: - SENT_SCORES[i] = SENT_SCORES[i][:,0:labels.shape[1]] - OUTPUT[i] = OUTPUT[i][:,0:labels.shape[1]] - - if SENT_SCORES[i].shape[1] < labels.shape[1]: - add_zero = (torch.zeros([1,labels.shape[1]-SENT_SCORES[i].shape[1]])) - SENT_SCORES[i] = torch.cat([SENT_SCORES[i],add_zero]) - add_bool = torch.zeros([1,labels.shape[1]-SENT_SCORES[i].shape[1]],dtype=torch.bool) - OUTPUT[i] = torch.cat([OUTPUT[i],add_bool],dim=1) - - if SENT_SCORES[i].shape[0] == 2: - if SENT_SCORES[i].shape[1] > labels.shape[1]: - SENT_SCORES[i] = SENT_SCORES[i][:,0:labels.shape[1]] - OUTPUT[i] = OUTPUT[i][:,0:labels.shape[1]] - if SENT_SCORES[i].shape[1] < labels.shape[1]: - add_zero = (torch.zeros([2,labels.shape[1]-SENT_SCORES[i].shape[1]])) - SENT_SCORES[i] = torch.cat([SENT_SCORES[i],add_zero],dim=1) - add_bool = torch.zeros([2,labels.shape[1]-SENT_SCORES[i].shape[1]],dtype=torch.bool) - OUTPUT[i] = torch.cat([OUTPUT[i],add_bool],dim=1) - i=i+1 - return SENT_SCORES,OUTPUT - -def test(args, step, device, cal_lead=False, cal_oracle=False): - test_iter = data_loader.Dataloader(args, load_dataset(args, 'test', shuffle=False), - args.batch_size, device, - shuffle=False, is_test=True) - def _get_ngrams(n, text): - ngram_set = set() - text_length = len(text) - max_index_ngram_start = text_length - n - for i in range(max_index_ngram_start + 1): - ngram_set.add(tuple(text[i:i + n])) - return ngram_set - - def _block_tri(c, p): - tri_c = _get_ngrams(3, c.split()) - for s in p: - tri_s = _get_ngrams(3, s.split()) - if len(tri_c.intersection(tri_s))>0: - return True - return False - - stats = Statistics() - can_path = '%s_step%d.candidate'%(args.result_path,step) - gold_path = '%s_step%d.gold' % (args.result_path, step) - - sent,output = pre_postprocess(args) - Loss = torch.nn.BCELoss(reduction='none') - sum = 0 - k=0 - with open(can_path, 'w') as save_pred: - with open(gold_path, 'w') as save_gold: - with torch.no_grad(): - for batch in test_iter: - labels = batch.labels - - gold = [] - pred = [] - if (cal_lead): - selected_ids = [list(range(batch.clss.size(1)))] * batch.batch_size - elif (cal_oracle): - selected_ids = [[j for j in range(batch.clss.size(1)) if labels[i][j] == 1] for i in - range(batch.batch_size)] - else: - print(k) - print('sent_scores:',sent[k]) - - if labels.shape[0] != sent[k].shape[0]: - #labels = labels[sent[k].shape[0],:] - k = k + 1 - sum = sum + 1 - continue - - loss = Loss(sent[k], labels.float()) - - if loss.shape[1] != output[k].shape[1]: - k = k + 1 - continue - - loss = (loss * output[k].float()).sum() - batch_stats = Statistics(float(loss.cpu().data.numpy()), len(labels)) - stats.update(batch_stats) - - sent_scores = sent[k] + output[k].float() - sent_scores = sent_scores.cpu().data.numpy() - selected_ids = np.argsort(-sent_scores, 1) - print(selected_ids) - # selected_ids = np.sort(selected_ids,1) - for i, idx in enumerate(selected_ids): - _pred = [] - if(len(batch.src_str[i])==0): - continue - for j in selected_ids[i][:len(batch.src_str[i])]: - if(j>=len( batch.src_str[i])): - continue - candidate = batch.src_str[i][j].strip() - if(args.block_trigram): - if(not _block_tri(candidate,_pred)): - _pred.append(candidate) - else: - _pred.append(candidate) - - if ((not cal_oracle) and (not args.recall_eval) and len(_pred) == 3): - break - - _pred = ''.join(_pred) - if(args.recall_eval): - _pred = ' '.join(_pred.split()[:len(batch.tgt_str[i].split())]) - - pred.append(_pred) - gold.append(batch.tgt_str[i]) - - for i in range(len(gold)): - save_gold.write(gold[i].strip()+'\n') - for i in range(len(pred)): - save_pred.write(pred[i].strip()+'\n') - k = k + 1 - print(sum) - if(step!=-1 and args.report_rouge): - print(can_path) - print(gold_path) - rouges = test_rouge(args.temp_dir, can_path, gold_path) - logger.info('Rouges at step %d \n%s' % (step, rouge_results_to_str(rouges))) - #self._report_step(0, step, valid_stats=stats) - - return stats - -if __name__ =="__main__": - parser = argparse.ArgumentParser() - parser.add_argument("-encoder", default='classifier', type=str, choices=['classifier','transformer','rnn','baseline']) - parser.add_argument("-mode", default='train', type=str, choices=['train','validate','test']) - parser.add_argument("-bert_data_path", default='../bert_data/cnndm') - parser.add_argument("-model_path", default='../models/') - parser.add_argument("-result_path", default='../results/cnndm') - parser.add_argument("-temp_dir", default='../temp') - parser.add_argument("-bert_config_path", default='../bert_config_uncased_base.json') - - parser.add_argument("-batch_size", default=1000, type=int) - - parser.add_argument("-use_interval", type=str2bool, nargs='?',const=True,default=True) - parser.add_argument("-hidden_size", default=128, type=int) - parser.add_argument("-ff_size", default=512, type=int) - parser.add_argument("-heads", default=4, type=int) - parser.add_argument("-inter_layers", default=2, type=int) - parser.add_argument("-rnn_size", default=512, type=int) - - parser.add_argument("-param_init", default=0, type=float) - parser.add_argument("-param_init_glorot", type=str2bool, nargs='?',const=True,default=True) - parser.add_argument("-dropout", default=0.1, type=float) - parser.add_argument("-optim", default='adam', type=str) - parser.add_argument("-lr", default=1, type=float) - parser.add_argument("-beta1", default= 0.9, type=float) - parser.add_argument("-beta2", default=0.999, type=float) - parser.add_argument("-decay_method", default='', type=str) - parser.add_argument("-warmup_steps", default=8000, type=int) - parser.add_argument("-max_grad_norm", default=0, type=float) - - parser.add_argument("-save_checkpoint_steps", default=5, type=int) - parser.add_argument("-accum_count", default=1, type=int) - parser.add_argument("-world_size", default=1, type=int) - parser.add_argument("-report_every", default=1, type=int) - parser.add_argument("-train_steps", default=1000, type=int) - parser.add_argument("-recall_eval", type=str2bool, nargs='?',const=True,default=False) - - - parser.add_argument('-visible_gpus', default='-1', type=str) - parser.add_argument('-gpu_ranks', default='0', type=str) - parser.add_argument('-log_file', default='../logs/cnndm.log') - parser.add_argument('-dataset', default='') - parser.add_argument('-seed', default=666, type=int) - - parser.add_argument("-test_all", type=str2bool, nargs='?',const=True,default=False) - parser.add_argument("-test_from", default='') - parser.add_argument("-train_from", default='') - parser.add_argument("-report_rouge", type=str2bool, nargs='?',const=True,default=True) - parser.add_argument("-block_trigram", type=str2bool, nargs='?', const=True, default=True) - parser.add_argument("-path_1", default="") - parser.add_argument("-path_2", default="") - - args = parser.parse_args() - device = "cpu" if args.visible_gpus == '-1' else "cuda" - device_id = -1 if device == "cpu" else 0 - test(args,0,device) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import os +import sys +import argparse +import glob +import numpy as np +from pytorch_pretrained_bert import BertConfig +from models.model_builder import Summarizer +from models import data_loader +from models.data_loader import load_dataset +from models.stats import Statistics +from others.utils import test_rouge +from others.logging import logger + +def str2bool(v): + if v.lower() in ('yes', 'true', 't', 'y', '1'): + return True + elif v.lower() in ('no', 'false', 'f', 'n', '0'): + return False + else: + raise argparse.ArgumentTypeError('Boolean value expected.') + +def rouge_results_to_str(results_dict): + return ">> ROUGE-F(1/2/3/l): {:.2f}/{:.2f}/{:.2f}\nROUGE-R(1/2/3/l): {:.2f}/{:.2f}/{:.2f}\n".format( + results_dict["rouge_1_f_score"] * 100, + results_dict["rouge_2_f_score"] * 100, + results_dict["rouge_l_f_score"] * 100, + results_dict["rouge_1_recall"] * 100, + results_dict["rouge_2_recall"] * 100, + results_dict["rouge_l_recall"] * 100 + ) + +def pre_postprocess(args): + File = os.listdir(args.path_1) + File1 = os.listdir(args.path_2) + list2 = [] + for file in File1: + list2.append(file) + Doc = [] + SENT_SCORES = [] + OUTPUT = [] + for file in sorted(File): + Doc.append(file[0:-6]) + Doc = list(set(Doc)) #grip repeated element + for i in range(len(Doc)): #deal after sorting + ff = 'data_'+str(i)+'_output' + sent_scores = np.fromfile(f'{args.path_1}/{ff}_0.bin', dtype=np.float32) + sent_scores = torch.tensor(sent_scores.reshape(1,sent_scores.shape[0])) + output = np.fromfile(f'{args.path_1}/{ff}_1.bin', dtype=np.bool_) + print(output.shape) + output = torch.tensor(output.reshape(1,37)) + document = ff+'_0.txt' + if document in list2: + doc = document[0:-6] + sent_scores1 = np.fromfile(f'{args.path_2}/{doc}_0.bin', dtype=np.float32) + sent_scores1 = torch.tensor(sent_scores1.reshape(1,sent_scores1.shape[0])) + #############add zero to keep same dimension############## + if sent_scores1.shape[1] > sent_scores.shape[1]: + add_zero = (torch.zeros([1,sent_scores1.shape[1]-sent_scores.shape[1]])) + sent_scores = torch.cat([sent_scores,add_zero],dim=1) + if sent_scores1.shape[1] < sent_scores.shape[1]: + add_zero = (torch.zeros([1,sent_scores.shape[1]-sent_scores1.shape[1]])) + sent_scores1 = torch.cat([sent_scores1,add_zero],dim=1) + ########################################################## + output1 = np.fromfile(f'{args.path_2}/{doc}_1.bin', dtype=np.bool_) + output1 = torch.tensor(output1.reshape(1,37)) + sent_scores = torch.cat([sent_scores,sent_scores1],dim=0) + output = torch.cat([output,output1],dim=0) + SENT_SCORES.append(sent_scores) + OUTPUT.append(output) + test_iter = data_loader.Dataloader(args, load_dataset(args, 'test', shuffle=False), + args.batch_size, device, + shuffle=False, is_test=True) + i=0 + for batch in test_iter: + labels = batch.labels + if SENT_SCORES[i].shape[0] == 1: + if SENT_SCORES[i].shape[1] > labels.shape[1]: + SENT_SCORES[i] = SENT_SCORES[i][:,0:labels.shape[1]] + OUTPUT[i] = OUTPUT[i][:,0:labels.shape[1]] + + if SENT_SCORES[i].shape[1] < labels.shape[1]: + add_zero = (torch.zeros([1,labels.shape[1]-SENT_SCORES[i].shape[1]])) + SENT_SCORES[i] = torch.cat([SENT_SCORES[i],add_zero]) + add_bool = torch.zeros([1,labels.shape[1]-SENT_SCORES[i].shape[1]],dtype=torch.bool) + OUTPUT[i] = torch.cat([OUTPUT[i],add_bool],dim=1) + + if SENT_SCORES[i].shape[0] == 2: + if SENT_SCORES[i].shape[1] > labels.shape[1]: + SENT_SCORES[i] = SENT_SCORES[i][:,0:labels.shape[1]] + OUTPUT[i] = OUTPUT[i][:,0:labels.shape[1]] + if SENT_SCORES[i].shape[1] < labels.shape[1]: + add_zero = (torch.zeros([2,labels.shape[1]-SENT_SCORES[i].shape[1]])) + SENT_SCORES[i] = torch.cat([SENT_SCORES[i],add_zero],dim=1) + add_bool = torch.zeros([2,labels.shape[1]-SENT_SCORES[i].shape[1]],dtype=torch.bool) + OUTPUT[i] = torch.cat([OUTPUT[i],add_bool],dim=1) + i=i+1 + return SENT_SCORES,OUTPUT + +def test(args, step, device, cal_lead=False, cal_oracle=False): + test_iter = data_loader.Dataloader(args, load_dataset(args, 'test', shuffle=False), + args.batch_size, device, + shuffle=False, is_test=True) + def _get_ngrams(n, text): + ngram_set = set() + text_length = len(text) + max_index_ngram_start = text_length - n + for i in range(max_index_ngram_start + 1): + ngram_set.add(tuple(text[i:i + n])) + return ngram_set + + def _block_tri(c, p): + tri_c = _get_ngrams(3, c.split()) + for s in p: + tri_s = _get_ngrams(3, s.split()) + if len(tri_c.intersection(tri_s))>0: + return True + return False + + stats = Statistics() + can_path = '%s_step%d.candidate'%(args.result_path,step) + gold_path = '%s_step%d.gold' % (args.result_path, step) + + sent,output = pre_postprocess(args) + Loss = torch.nn.BCELoss(reduction='none') + sum = 0 + k=0 + with open(can_path, 'w') as save_pred: + with open(gold_path, 'w') as save_gold: + with torch.no_grad(): + for batch in test_iter: + labels = batch.labels + + gold = [] + pred = [] + if (cal_lead): + selected_ids = [list(range(batch.clss.size(1)))] * batch.batch_size + elif (cal_oracle): + selected_ids = [[j for j in range(batch.clss.size(1)) if labels[i][j] == 1] for i in + range(batch.batch_size)] + else: + print(k) + print('sent_scores:',sent[k]) + + if labels.shape[0] != sent[k].shape[0]: + #labels = labels[sent[k].shape[0],:] + k = k + 1 + sum = sum + 1 + continue + + loss = Loss(sent[k], labels.float()) + + if loss.shape[1] != output[k].shape[1]: + k = k + 1 + continue + + loss = (loss * output[k].float()).sum() + batch_stats = Statistics(float(loss.cpu().data.numpy()), len(labels)) + stats.update(batch_stats) + + sent_scores = sent[k] + output[k].float() + sent_scores = sent_scores.cpu().data.numpy() + selected_ids = np.argsort(-sent_scores, 1) + print(selected_ids) + # selected_ids = np.sort(selected_ids,1) + for i, idx in enumerate(selected_ids): + _pred = [] + if(len(batch.src_str[i])==0): + continue + for j in selected_ids[i][:len(batch.src_str[i])]: + if(j>=len( batch.src_str[i])): + continue + candidate = batch.src_str[i][j].strip() + if(args.block_trigram): + if(not _block_tri(candidate,_pred)): + _pred.append(candidate) + else: + _pred.append(candidate) + + if ((not cal_oracle) and (not args.recall_eval) and len(_pred) == 3): + break + + _pred = ''.join(_pred) + if(args.recall_eval): + _pred = ' '.join(_pred.split()[:len(batch.tgt_str[i].split())]) + + pred.append(_pred) + gold.append(batch.tgt_str[i]) + + for i in range(len(gold)): + save_gold.write(gold[i].strip()+'\n') + for i in range(len(pred)): + save_pred.write(pred[i].strip()+'\n') + k = k + 1 + print(sum) + if(step!=-1 and args.report_rouge): + print(can_path) + print(gold_path) + rouges = test_rouge(args.temp_dir, can_path, gold_path) + logger.info('Rouges at step %d \n%s' % (step, rouge_results_to_str(rouges))) + #self._report_step(0, step, valid_stats=stats) + + return stats + +if __name__ =="__main__": + parser = argparse.ArgumentParser() + parser.add_argument("-encoder", default='classifier', type=str, choices=['classifier','transformer','rnn','baseline']) + parser.add_argument("-mode", default='train', type=str, choices=['train','validate','test']) + parser.add_argument("-bert_data_path", default='../bert_data/cnndm') + parser.add_argument("-model_path", default='../models/') + parser.add_argument("-result_path", default='../results/cnndm') + parser.add_argument("-temp_dir", default='../temp') + parser.add_argument("-bert_config_path", default='../bert_config_uncased_base.json') + + parser.add_argument("-batch_size", default=1000, type=int) + + parser.add_argument("-use_interval", type=str2bool, nargs='?',const=True,default=True) + parser.add_argument("-hidden_size", default=128, type=int) + parser.add_argument("-ff_size", default=512, type=int) + parser.add_argument("-heads", default=4, type=int) + parser.add_argument("-inter_layers", default=2, type=int) + parser.add_argument("-rnn_size", default=512, type=int) + + parser.add_argument("-param_init", default=0, type=float) + parser.add_argument("-param_init_glorot", type=str2bool, nargs='?',const=True,default=True) + parser.add_argument("-dropout", default=0.1, type=float) + parser.add_argument("-optim", default='adam', type=str) + parser.add_argument("-lr", default=1, type=float) + parser.add_argument("-beta1", default= 0.9, type=float) + parser.add_argument("-beta2", default=0.999, type=float) + parser.add_argument("-decay_method", default='', type=str) + parser.add_argument("-warmup_steps", default=8000, type=int) + parser.add_argument("-max_grad_norm", default=0, type=float) + + parser.add_argument("-save_checkpoint_steps", default=5, type=int) + parser.add_argument("-accum_count", default=1, type=int) + parser.add_argument("-world_size", default=1, type=int) + parser.add_argument("-report_every", default=1, type=int) + parser.add_argument("-train_steps", default=1000, type=int) + parser.add_argument("-recall_eval", type=str2bool, nargs='?',const=True,default=False) + + + parser.add_argument('-visible_gpus', default='-1', type=str) + parser.add_argument('-gpu_ranks', default='0', type=str) + parser.add_argument('-log_file', default='../logs/cnndm.log') + parser.add_argument('-dataset', default='') + parser.add_argument('-seed', default=666, type=int) + + parser.add_argument("-test_all", type=str2bool, nargs='?',const=True,default=False) + parser.add_argument("-test_from", default='') + parser.add_argument("-train_from", default='') + parser.add_argument("-report_rouge", type=str2bool, nargs='?',const=True,default=True) + parser.add_argument("-block_trigram", type=str2bool, nargs='?', const=True, default=True) + parser.add_argument("-path_1", default="") + parser.add_argument("-path_2", default="") + + args = parser.parse_args() + device = "cpu" if args.visible_gpus == '-1' else "cuda" + device_id = -1 if device == "cpu" else 0 + test(args,0,device) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/nlp/BertSum/BertSum_pth_preprocess.py b/ACL_PyTorch/contrib/nlp/BertSum/BertSum_pth_preprocess.py index f3ddcfef2f30e464c68323e890802038885e25f8..19a09793ce675629b13254a43724ca8bccd8f55f 100644 --- a/ACL_PyTorch/contrib/nlp/BertSum/BertSum_pth_preprocess.py +++ b/ACL_PyTorch/contrib/nlp/BertSum/BertSum_pth_preprocess.py @@ -1,179 +1,179 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import argparse -import os -import torch - -from models import data_loader -from models.data_loader import load_dataset -from models.trainer import build_trainer - -def str2bool(v): - if v.lower() in ('yes', 'true', 't', 'y', '1'): - return True - elif v.lower() in ('no', 'false', 'f', 'n', '0'): - return False - else: - raise argparse.ArgumentTypeError('Boolean value expected.') -def get_max_shape(test_iter): - max_shape_1=0 - max_shape_2=0 - for batch in test_iter: - if batch.src.shape[1] > max_shape_1: - max_shape_1 = batch.src.shape[1] - if batch.clss.shape[1] > max_shape_2: - max_shape_2 = batch.clss.shape[1] - #print(batch.src[0].shape) - return max_shape_1,max_shape_2 - -def preprocess(args,device): - test_iter =data_loader.Dataloader(args, load_dataset(args, 'test', shuffle=False), - args.batch_size, device, - shuffle=False, is_test=True) - test_iter1 =data_loader.Dataloader(args, load_dataset(args, 'test', shuffle=False), - args.batch_size, device, - shuffle=False, is_test=True) - cur_path = os.getcwd() - main_path = cur_path + '/pre_data' - main_path_1 = cur_path + '/pre_data_1' - i=0 - if not os.path.exists(os.path.join(cur_path,'pre_data')): ###########first inference - os.makedirs(os.path.join(cur_path,'pre_data')) - if not os.path.exists(os.path.join(main_path,'src')): - os.makedirs(os.path.join(main_path,'src')) - if not os.path.exists(os.path.join(main_path,'segs')): - os.makedirs(os.path.join(main_path,'segs')) - if not os.path.exists(os.path.join(main_path,'clss')): - os.makedirs(os.path.join(main_path,'clss')) - if not os.path.exists(os.path.join(main_path,'mask')): - os.makedirs(os.path.join(main_path,'mask')) - if not os.path.exists(os.path.join(main_path,'mask_cls')): - os.makedirs(os.path.join(main_path,'mask_cls')) - - if not os.path.exists(os.path.join(cur_path,'pre_data_1')): ###########second inference - os.makedirs(os.path.join(cur_path,'pre_data_1')) - if not os.path.exists(os.path.join(main_path_1,'src')): - os.makedirs(os.path.join(main_path_1,'src')) - if not os.path.exists(os.path.join(main_path_1,'segs')): - os.makedirs(os.path.join(main_path_1,'segs')) - if not os.path.exists(os.path.join(main_path_1,'clss')): - os.makedirs(os.path.join(main_path_1,'clss')) - if not os.path.exists(os.path.join(main_path_1,'mask')): - os.makedirs(os.path.join(main_path_1,'mask')) - if not os.path.exists(os.path.join(main_path_1,'mask_cls')): - os.makedirs(os.path.join(main_path_1,'mask_cls')) - max_shape_1,max_shape_2 = get_max_shape(test_iter) - print(max_shape_1,max_shape_2) - #############################above get max dimension ########################### - for batch in test_iter1: - if batch.src.shape[0]==2: - if batch.src[0].shape[0] < max_shape_1: - add_zero = (torch.zeros([batch.src.shape[0],max_shape_1-batch.src[0].shape[0]])).long() #######change to int64 - add_bool = torch.zeros([batch.src.shape[0],max_shape_1-batch.src[0].shape[0]],dtype=torch.bool) - batch.src = torch.cat([batch.src,add_zero],dim=1) - batch.segs = torch.cat([batch.segs,add_zero],dim=1) - batch.mask = torch.cat([batch.mask,add_bool],dim=1) - if batch.clss[0].shape[0] < max_shape_2: - add_zero = (torch.zeros([batch.clss.shape[0],max_shape_2-batch.clss[0].shape[0]])).long() #######change to int64 - add_bool = torch.zeros([batch.clss.shape[0],max_shape_2-batch.clss[0].shape[0]],dtype=torch.bool) - batch.clss = torch.cat([batch.clss,add_zero],dim=1) - batch.mask_cls = torch.cat([batch.mask_cls,add_bool],dim=1) - ##############first dimension - batch.src[0].numpy().tofile(os.path.join(main_path,'src','data_'+str(i)+'.bin')) - batch.segs[0].numpy().tofile(os.path.join(main_path,'segs','data_'+str(i)+'.bin')) - batch.clss[0].numpy().tofile(os.path.join(main_path,'clss','data_'+str(i)+'.bin')) - batch.mask[0].numpy().tofile(os.path.join(main_path,'mask','data_'+str(i)+'.bin')) - batch.mask_cls[0].numpy().tofile(os.path.join(main_path,'mask_cls','data_'+str(i)+'.bin')) - #############second dimension - batch.src[1].numpy().tofile(os.path.join(main_path_1,'src','data_'+str(i)+'.bin')) - batch.segs[1].numpy().tofile(os.path.join(main_path_1,'segs','data_'+str(i)+'.bin')) - batch.clss[1].numpy().tofile(os.path.join(main_path_1,'clss','data_'+str(i)+'.bin')) - batch.mask[1].numpy().tofile(os.path.join(main_path_1,'mask','data_'+str(i)+'.bin')) - batch.mask_cls[1].numpy().tofile(os.path.join(main_path_1,'mask_cls','data_'+str(i)+'.bin')) - else: - #print(batch.clss.dtype) - if batch.src[0].shape[0] < max_shape_1: - add_zero = (torch.zeros([batch.src.shape[0],max_shape_1-batch.src[0].shape[0]])).long() #######change to int64 - add_bool = torch.zeros([batch.src.shape[0],max_shape_1-batch.src[0].shape[0]],dtype=torch.bool) - batch.src = torch.cat([batch.src,add_zero],dim=1) - batch.segs = torch.cat([batch.segs,add_zero],dim=1) - batch.mask = torch.cat([batch.mask,add_bool],dim=1) - if batch.clss[0].shape[0] < max_shape_2: - add_zero = (torch.zeros([batch.clss.shape[0],max_shape_2-batch.clss[0].shape[0]])).long() #######change to int64 - add_bool = torch.zeros([batch.clss.shape[0],max_shape_2-batch.clss[0].shape[0]],dtype=torch.bool) - batch.clss = torch.cat([batch.clss,add_zero],dim=1) - batch.mask_cls = torch.cat([batch.mask_cls,add_bool],dim=1) - batch.src.numpy().tofile(os.path.join(main_path,'src','data_'+str(i)+'.bin')) - batch.segs.numpy().tofile(os.path.join(main_path,'segs','data_'+str(i)+'.bin')) - batch.clss.numpy().tofile(os.path.join(main_path,'clss','data_'+str(i)+'.bin')) - batch.mask.numpy().tofile(os.path.join(main_path,'mask','data_'+str(i)+'.bin')) - batch.mask_cls.numpy().tofile(os.path.join(main_path,'mask_cls','data_'+str(i)+'.bin')) - i = i+1 - -if __name__ =="__main__": - parser = argparse.ArgumentParser() - parser.add_argument("-encoder", default='classifier', type=str, choices=['classifier','transformer','rnn','baseline']) - parser.add_argument("-mode", default='train', type=str, choices=['train','validate','test']) - parser.add_argument("-bert_data_path", default='../bert_data') - parser.add_argument("-model_path", default='../models/') - parser.add_argument("-result_path", default='../results/cnndm') - parser.add_argument("-temp_dir", default='../temp') - parser.add_argument("-bert_config_path", default='../bert_config_uncased_base.json') - - parser.add_argument("-batch_size", default=1000, type=int) - - parser.add_argument("-use_interval", type=str2bool, nargs='?',const=True,default=True) - parser.add_argument("-hidden_size", default=128, type=int) - parser.add_argument("-ff_size", default=512, type=int) - parser.add_argument("-heads", default=4, type=int) - parser.add_argument("-inter_layers", default=2, type=int) - parser.add_argument("-rnn_size", default=512, type=int) - - parser.add_argument("-param_init", default=0, type=float) - parser.add_argument("-param_init_glorot", type=str2bool, nargs='?',const=True,default=True) - parser.add_argument("-dropout", default=0.1, type=float) - parser.add_argument("-optim", default='adam', type=str) - parser.add_argument("-lr", default=1, type=float) - parser.add_argument("-beta1", default= 0.9, type=float) - parser.add_argument("-beta2", default=0.999, type=float) - parser.add_argument("-decay_method", default='', type=str) - parser.add_argument("-warmup_steps", default=8000, type=int) - parser.add_argument("-max_grad_norm", default=0, type=float) - - parser.add_argument("-save_checkpoint_steps", default=5, type=int) - parser.add_argument("-accum_count", default=1, type=int) - parser.add_argument("-world_size", default=1, type=int) - parser.add_argument("-report_every", default=1, type=int) - parser.add_argument("-train_steps", default=1000, type=int) - parser.add_argument("-recall_eval", type=str2bool, nargs='?',const=True,default=False) - - parser.add_argument('-visible_gpus', default='-1', type=str) - parser.add_argument('-gpu_ranks', default='0', type=str) - parser.add_argument('-log_file', default='../logs/cnndm.log') - parser.add_argument('-dataset', default='') - parser.add_argument('-seed', default=666, type=int) - - parser.add_argument("-test_all", type=str2bool, nargs='?',const=True,default=False) - parser.add_argument("-test_from", default='') - parser.add_argument("-train_from", default='') - parser.add_argument("-report_rouge", type=str2bool, nargs='?',const=True,default=True) - parser.add_argument("-block_trigram", type=str2bool, nargs='?', const=True, default=True) - parser.add_argument("-onnx_path", default="") - parser.add_argument("-path", default="") - - args = parser.parse_args() - device = "cpu" if args.visible_gpus == '-1' else "cuda" - device_id = -1 if device == "cpu" else 0 - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import argparse +import os +import torch + +from models import data_loader +from models.data_loader import load_dataset +from models.trainer import build_trainer + +def str2bool(v): + if v.lower() in ('yes', 'true', 't', 'y', '1'): + return True + elif v.lower() in ('no', 'false', 'f', 'n', '0'): + return False + else: + raise argparse.ArgumentTypeError('Boolean value expected.') +def get_max_shape(test_iter): + max_shape_1=0 + max_shape_2=0 + for batch in test_iter: + if batch.src.shape[1] > max_shape_1: + max_shape_1 = batch.src.shape[1] + if batch.clss.shape[1] > max_shape_2: + max_shape_2 = batch.clss.shape[1] + #print(batch.src[0].shape) + return max_shape_1,max_shape_2 + +def preprocess(args,device): + test_iter =data_loader.Dataloader(args, load_dataset(args, 'test', shuffle=False), + args.batch_size, device, + shuffle=False, is_test=True) + test_iter1 =data_loader.Dataloader(args, load_dataset(args, 'test', shuffle=False), + args.batch_size, device, + shuffle=False, is_test=True) + cur_path = os.getcwd() + main_path = cur_path + '/pre_data' + main_path_1 = cur_path + '/pre_data_1' + i=0 + if not os.path.exists(os.path.join(cur_path,'pre_data')): ###########first inference + os.makedirs(os.path.join(cur_path,'pre_data')) + if not os.path.exists(os.path.join(main_path,'src')): + os.makedirs(os.path.join(main_path,'src')) + if not os.path.exists(os.path.join(main_path,'segs')): + os.makedirs(os.path.join(main_path,'segs')) + if not os.path.exists(os.path.join(main_path,'clss')): + os.makedirs(os.path.join(main_path,'clss')) + if not os.path.exists(os.path.join(main_path,'mask')): + os.makedirs(os.path.join(main_path,'mask')) + if not os.path.exists(os.path.join(main_path,'mask_cls')): + os.makedirs(os.path.join(main_path,'mask_cls')) + + if not os.path.exists(os.path.join(cur_path,'pre_data_1')): ###########second inference + os.makedirs(os.path.join(cur_path,'pre_data_1')) + if not os.path.exists(os.path.join(main_path_1,'src')): + os.makedirs(os.path.join(main_path_1,'src')) + if not os.path.exists(os.path.join(main_path_1,'segs')): + os.makedirs(os.path.join(main_path_1,'segs')) + if not os.path.exists(os.path.join(main_path_1,'clss')): + os.makedirs(os.path.join(main_path_1,'clss')) + if not os.path.exists(os.path.join(main_path_1,'mask')): + os.makedirs(os.path.join(main_path_1,'mask')) + if not os.path.exists(os.path.join(main_path_1,'mask_cls')): + os.makedirs(os.path.join(main_path_1,'mask_cls')) + max_shape_1,max_shape_2 = get_max_shape(test_iter) + print(max_shape_1,max_shape_2) + #############################above get max dimension ########################### + for batch in test_iter1: + if batch.src.shape[0]==2: + if batch.src[0].shape[0] < max_shape_1: + add_zero = (torch.zeros([batch.src.shape[0],max_shape_1-batch.src[0].shape[0]])).long() #######change to int64 + add_bool = torch.zeros([batch.src.shape[0],max_shape_1-batch.src[0].shape[0]],dtype=torch.bool) + batch.src = torch.cat([batch.src,add_zero],dim=1) + batch.segs = torch.cat([batch.segs,add_zero],dim=1) + batch.mask = torch.cat([batch.mask,add_bool],dim=1) + if batch.clss[0].shape[0] < max_shape_2: + add_zero = (torch.zeros([batch.clss.shape[0],max_shape_2-batch.clss[0].shape[0]])).long() #######change to int64 + add_bool = torch.zeros([batch.clss.shape[0],max_shape_2-batch.clss[0].shape[0]],dtype=torch.bool) + batch.clss = torch.cat([batch.clss,add_zero],dim=1) + batch.mask_cls = torch.cat([batch.mask_cls,add_bool],dim=1) + ##############first dimension + batch.src[0].numpy().tofile(os.path.join(main_path,'src','data_'+str(i)+'.bin')) + batch.segs[0].numpy().tofile(os.path.join(main_path,'segs','data_'+str(i)+'.bin')) + batch.clss[0].numpy().tofile(os.path.join(main_path,'clss','data_'+str(i)+'.bin')) + batch.mask[0].numpy().tofile(os.path.join(main_path,'mask','data_'+str(i)+'.bin')) + batch.mask_cls[0].numpy().tofile(os.path.join(main_path,'mask_cls','data_'+str(i)+'.bin')) + #############second dimension + batch.src[1].numpy().tofile(os.path.join(main_path_1,'src','data_'+str(i)+'.bin')) + batch.segs[1].numpy().tofile(os.path.join(main_path_1,'segs','data_'+str(i)+'.bin')) + batch.clss[1].numpy().tofile(os.path.join(main_path_1,'clss','data_'+str(i)+'.bin')) + batch.mask[1].numpy().tofile(os.path.join(main_path_1,'mask','data_'+str(i)+'.bin')) + batch.mask_cls[1].numpy().tofile(os.path.join(main_path_1,'mask_cls','data_'+str(i)+'.bin')) + else: + #print(batch.clss.dtype) + if batch.src[0].shape[0] < max_shape_1: + add_zero = (torch.zeros([batch.src.shape[0],max_shape_1-batch.src[0].shape[0]])).long() #######change to int64 + add_bool = torch.zeros([batch.src.shape[0],max_shape_1-batch.src[0].shape[0]],dtype=torch.bool) + batch.src = torch.cat([batch.src,add_zero],dim=1) + batch.segs = torch.cat([batch.segs,add_zero],dim=1) + batch.mask = torch.cat([batch.mask,add_bool],dim=1) + if batch.clss[0].shape[0] < max_shape_2: + add_zero = (torch.zeros([batch.clss.shape[0],max_shape_2-batch.clss[0].shape[0]])).long() #######change to int64 + add_bool = torch.zeros([batch.clss.shape[0],max_shape_2-batch.clss[0].shape[0]],dtype=torch.bool) + batch.clss = torch.cat([batch.clss,add_zero],dim=1) + batch.mask_cls = torch.cat([batch.mask_cls,add_bool],dim=1) + batch.src.numpy().tofile(os.path.join(main_path,'src','data_'+str(i)+'.bin')) + batch.segs.numpy().tofile(os.path.join(main_path,'segs','data_'+str(i)+'.bin')) + batch.clss.numpy().tofile(os.path.join(main_path,'clss','data_'+str(i)+'.bin')) + batch.mask.numpy().tofile(os.path.join(main_path,'mask','data_'+str(i)+'.bin')) + batch.mask_cls.numpy().tofile(os.path.join(main_path,'mask_cls','data_'+str(i)+'.bin')) + i = i+1 + +if __name__ =="__main__": + parser = argparse.ArgumentParser() + parser.add_argument("-encoder", default='classifier', type=str, choices=['classifier','transformer','rnn','baseline']) + parser.add_argument("-mode", default='train', type=str, choices=['train','validate','test']) + parser.add_argument("-bert_data_path", default='../bert_data') + parser.add_argument("-model_path", default='../models/') + parser.add_argument("-result_path", default='../results/cnndm') + parser.add_argument("-temp_dir", default='../temp') + parser.add_argument("-bert_config_path", default='../bert_config_uncased_base.json') + + parser.add_argument("-batch_size", default=1000, type=int) + + parser.add_argument("-use_interval", type=str2bool, nargs='?',const=True,default=True) + parser.add_argument("-hidden_size", default=128, type=int) + parser.add_argument("-ff_size", default=512, type=int) + parser.add_argument("-heads", default=4, type=int) + parser.add_argument("-inter_layers", default=2, type=int) + parser.add_argument("-rnn_size", default=512, type=int) + + parser.add_argument("-param_init", default=0, type=float) + parser.add_argument("-param_init_glorot", type=str2bool, nargs='?',const=True,default=True) + parser.add_argument("-dropout", default=0.1, type=float) + parser.add_argument("-optim", default='adam', type=str) + parser.add_argument("-lr", default=1, type=float) + parser.add_argument("-beta1", default= 0.9, type=float) + parser.add_argument("-beta2", default=0.999, type=float) + parser.add_argument("-decay_method", default='', type=str) + parser.add_argument("-warmup_steps", default=8000, type=int) + parser.add_argument("-max_grad_norm", default=0, type=float) + + parser.add_argument("-save_checkpoint_steps", default=5, type=int) + parser.add_argument("-accum_count", default=1, type=int) + parser.add_argument("-world_size", default=1, type=int) + parser.add_argument("-report_every", default=1, type=int) + parser.add_argument("-train_steps", default=1000, type=int) + parser.add_argument("-recall_eval", type=str2bool, nargs='?',const=True,default=False) + + parser.add_argument('-visible_gpus', default='-1', type=str) + parser.add_argument('-gpu_ranks', default='0', type=str) + parser.add_argument('-log_file', default='../logs/cnndm.log') + parser.add_argument('-dataset', default='') + parser.add_argument('-seed', default=666, type=int) + + parser.add_argument("-test_all", type=str2bool, nargs='?',const=True,default=False) + parser.add_argument("-test_from", default='') + parser.add_argument("-train_from", default='') + parser.add_argument("-report_rouge", type=str2bool, nargs='?',const=True,default=True) + parser.add_argument("-block_trigram", type=str2bool, nargs='?', const=True, default=True) + parser.add_argument("-onnx_path", default="") + parser.add_argument("-path", default="") + + args = parser.parse_args() + device = "cpu" if args.visible_gpus == '-1' else "cuda" + device_id = -1 if device == "cpu" else 0 + preprocess(args,device) \ No newline at end of file diff --git a/ACL_PyTorch/contrib/nlp/BertSum/README.md b/ACL_PyTorch/contrib/nlp/BertSum/README.md index 03d573f8d3e178d33f4ab62830754448619c1057..90d73c936182d9244757ca02fc429ffef40b3c06 100644 --- a/ACL_PyTorch/contrib/nlp/BertSum/README.md +++ b/ACL_PyTorch/contrib/nlp/BertSum/README.md @@ -1,285 +1,285 @@ - - -# BertSum Onnx模型端到端推理指导 - -- 1 模型概述 - - [1.1 代码地址](https://gitee.com/kghhkhkljl/pyramidbox.git) -- 2 环境说明 - - [2.1 深度学习框架](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#21-深度学习框架) - - [2.2 python第三方库](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#22-python第三方库) -- 3 模型转换 - - [3.1 pth转onnx模型](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#31-pth转onnx模型) - - [3.2 onnx转om模型](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#32-onnx转om模型) -- 4 数据集预处理 - - [4.1 数据集获取](https://www.graviti.cn/open-datasets/WIDER_FACE) - - [4.2 数据集预处理](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#42-数据集预处理) - - [4.3 生成数据集信息文件](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#43-生成数据集信息文件) -- 5 离线推理 - - [5.1 benchmark工具概述](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#51-benchmark工具概述) - - [5.2 离线推理](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#52-离线推理) -- 6 精度对比 - - [6.1 离线推理精度统计](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#61-离线推理精度统计) - - [6.2 开源精度](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#62-开源精度) - - [6.3 精度对比](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#63-精度对比) -- 7 性能对比 - - [7.1 npu性能数据](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#71-npu性能数据) - - [7.2 T4性能数据](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#72-T4性能数据) - - [7.3 性能对比](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#73-性能对比) - -## 1 模型概述 - -- **论文地址** -- **代码地址** - -### 1.1 论文地址 - -[Bertsum论文](https://arxiv.org/abs/1803.07737) - -### 1.2 代码地址 - -https://github.com/nlpyang/BertSum.git - -## 2 环境说明 - -- **深度学习框架** -- **python第三方库** - -### 2.1 深度学习框架 - -``` -python3.7.5 -CANN 5.0.3 - -pytorch >= 1.5.0 -torchvision >= 0.10.0 -onnx >= 1.7.0 - -说明:若是在conda环境下,直接采用python,不用python3.7 -``` - -### 2.2 python第三方库 - -``` -torch==1.7.1 -tensorboardX==2.4.1 -pyrouge==0.1.3 -pytorch-pretrained-bert==0.6.2 -onnx-simplifier==0.3.6 -``` - -### **2.3 环境配置** - -ROUGE配置参考博客: - -[(10条消息) Ubuntu安装配置ROUGE_BigSea-CSDN博客](https://blog.csdn.net/Hay54/article/details/78744912) - -pyrouge配置参考博客: - -[(10条消息) 在Ubuntu下配置pyrouge_MerryCao的博客-CSDN博客](https://blog.csdn.net/MerryCao/article/details/49174283) - -## 3 模型转换 - -- **pth转onnx模型** -- **onnx转om模型** - -### 3.1 pth转onnx模型 - -1.拉取代码仓库 (因为使用了开源代码模块,所以需要git clone一下) - -```shell -git clone https://github.com/nlpyang/BertSum.git -``` - -克隆下来源代码并解压,将pr中的代码放到解压之后的BertSum/src目录下面并对BertSum/src/models/data_loder.py进行一个更改: - -将31行的mask=1-(src==0)修改为mask=~(src==0) 将35行的mask=1-(clss==-1)修改为mask=~(clss==-1) - -2.下载pth权重文件 - -权重文件默认存放在**/home/BertSum/src**目录下 - -3.使用pth2onnx.py进行onnx的转换 - -``` -方法一:cd /home/BertSum/src/test -bash pth2onnx.sh -方法二:cd /home/BertSum/src -python BertSum-pth2onnx.py -mode test -bert_data_path ../bert_data/cnndm -model_path MODEL_PATH -visible_gpus -1 -gpu_ranks 0 -batch_size 1 -log_file LOG_FILE -result_path RESULT_PATH -test_all -block_trigram true -onnx_path bertsum_13000_9_bs1.onnx -path model_step_13000.pt -``` - -获得bertsum_13000_9_bs1.onnx文件 - -方法二种的-bert_data_path是数据集所在目录,-batch_size需设置为1,-onnx_path是onnx输出文件 - -### 3.2 onnx模型简化 - -由于存在expand算子导致转om不成功,所以需要使用onnx简化工具对onnx进行简化 - -使用pth2onnx.py进行onnx的转换 - -``` -方法一:cd /home/BertSum/src/test -bash simplify.sh -方法二:cd /home/BertSum/src -python -m onnxsim ./bertsum_13000_9_bs1.onnx ./bertsum_13000_9_sim_bs1.onnx -``` - -获得bertsum_13000_9_sim_bs1.onnx文件 - -### 3.3 onnx简化模型转om模型 - -1.设置环境变量 - -``` -source atc.sh -``` - -2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.3 开发辅助工具指南 (推理) 01 - -``` -方法一:cd /home/BertSum/src/test -bash onnxToom.sh -方法二:cd /home/BertSum/src -atc --input_format=ND --framework=5 --model=./bertsum_13000_9_sim_bs1.onnx --input_shape="src:1,512;segs:1,512;clss:1,37;mask:1,512;mask_cls:1,37" --output=bertsum_13000_9_sim_bs1 \ ---log=info --soc_version=Ascend310 --precision_mode=allow_mix_precision \ ---modify_mixlist=ops_info.json -``` - -方法二中的model是onnx模型的名字,input_shape是paper的shape,output为输出om的名字,--precision_mode表示采用混合精度 - -## 4 数据集预处理 - -- **数据集获取** -- **数据集预处理** -- **生成数据集信息文件** - -### 4.1 数据集获取 - -参考原代码仓 - -### 4.2 数据集预处理 - -1.预处理脚本BertSum_pth_preprocess.py - -2.执行预处理脚本,生成数据集预处理后的bin文件 - -``` -方法一:cd /home/BertSum/src/test -bash pre_deal.sh -方法二:cd /home/BertSum/src -python BertSum_pth_preprocess.py -mode test -bert_data_path ../bert_data/cnndm -model_path MODEL_PATH -visible_gpus -1 -gpu_ranks 0 -batch_size 600 -log_file LOG_FILE -result_path RESULT_PATH -test_all -block_trigram true -``` - --bert_data_path是数据集所在目录,后面的参数是固定的。 - -### 5 离线推理 - -- **msame工具** -- **离线推理** - -### 5.1 msame工具 - -获取msame工具(https://gitee.com/ascend/tools/tree/master/msame),并将得到的msame工具放在/home/BertSum-master/src下 - -### 5.2 离线推理 - -1.执行离线推理 - -benchmark工具暂不支持多输入,因此改用msame,首先要source环境变量 - -``` -source env.sh -``` - -2.使用msame将onnx模型转换为om模型文件,工具使用方法可以参考CANN - -然后运行如下命令: - -``` -方法一:cd /home/BertSum/src/test -bash infer.sh -方法二:cd /home/BertSum/src -./msame --model "./bertsum_13000_9_sim_bs1_1.om" --input "./pre_data/src,./pre_data/segs,./pre_data/clss,./pre_data/mask,./pre_data/mask_cls" --output "./result" --outfmt bin -./msame --model "./bertsum_13000_9_sim_bs1_1.om" --input "./pre_data_1/src,./pre_data_1/segs,./pre_data_1/clss,./pre_data_1/mask,./pre_data_1/mask_cls" --output "./result" --outfmt bin -``` - -要采用msema工具推理两次,因为有些paper的shape第一维为2,所以分两次进行推理。pre_data下存放的是shape为第一维为1的所有预处理之后的数据以及shape为2的部分预处理得到的数据。shape为2的另一部分数据存放在pre_data_1下面。--model是om文件,--input是预处理之后文件所在目录,--output为输出bin文件所在目录,--outfmt代表输出bin文件*。* - -输出的bin文件在/home/BertSum-master/src/result目录下,此目录下会存在两个文件,将其中一个时间小的命名为result_1,将另一个时间大的命名为result_2。 - -## 6 精度对比 - -- **离线推理精度** -- **开源精度** -- **精度对比** - -### 6.1 离线推理精度统计 - -1.后处理 - -``` -cd /home/BertSum/src -python BertSum_pth_postprocess.py -visible_gpus -1 -gpu_ranks 0 -batch_size 600 -log_file LOG_FILE -result_path RESULT_PATH -test_all -block_trigram true -path_1 ./result/result_1 -path_2 ./result/result_2 -``` - -``` - -path_1是推理得到的文件result_1,-path_2是推理得到的result_2 - 自验报告 - # 第X次验收测试 - # 验收结果 OK - # 验收环境: A + K / CANN 5.0.3 - # 关联issue: - - # pth是否能正确转换为om - bash test/onnx2om.sh - # 验收结果: OK - # 备注: 成功生成om,无运行报错,报错日志xx 等 - - # 精度数据是否达标(需要显示官网pth精度与om模型的精度) - # npu性能数据(由于msame工具不支持多batch,所以只测试了bs1的性能) - # 验收结果: 是 / 否 - # 备注: 目标pth精度42.96;bs1验收om精度42.92;精度下降不超过1%;无运行报错,报错日志xx 等 - # 备注: 验收310测试性能bs1:61.538FPS;无运行报错,报错日志xx 等 - - # 在t4上测试bs1性能 - bash perf.sh - # 验收结果: OK / Failed - # 备注: 验收基准测试性能bs1:94.281FPS;无运行报错,报错日志xx 等 - - # 310性能是否超过基准: 否 - t4:310=(94.281/61.538)1.53倍基准 -``` - -### 6.2 开源精度 - -BertSum在线训练精度: - -42.96% - -### 6.3 离线推理精度 - -42.95% - -### 6.3 精度对比 - -由于源码采用的是动态shape,而离线推理是通过加padding固定住shape进行推理的,所以精度会有损失,因此和同一分辨率下的在线推理进行对比。对比方式:三个尺度求和取平均。 - -## 7 性能对比 - -- **310性能数据** -- **T4性能数据** -- **性能对比** - -### 7.1 310性能数据 - -每张图片平均耗时:65.06ms,所以310吞吐率为:1000/65×4=61.538 - -说明:由于msame不支持多batch,所以此处只测了bs1的性能。 - -### 7.2 T4性能数据 - -T4性能为:94.281 - -### 7.3 性能对比 - + + +# BertSum Onnx模型端到端推理指导 + +- 1 模型概述 + - [1.1 代码地址](https://gitee.com/kghhkhkljl/pyramidbox.git) +- 2 环境说明 + - [2.1 深度学习框架](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#21-深度学习框架) + - [2.2 python第三方库](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#22-python第三方库) +- 3 模型转换 + - [3.1 pth转onnx模型](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#31-pth转onnx模型) + - [3.2 onnx转om模型](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#32-onnx转om模型) +- 4 数据集预处理 + - [4.1 数据集获取](https://www.graviti.cn/open-datasets/WIDER_FACE) + - [4.2 数据集预处理](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#42-数据集预处理) + - [4.3 生成数据集信息文件](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#43-生成数据集信息文件) +- 5 离线推理 + - [5.1 benchmark工具概述](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/ResNext50#51-benchmark工具概述) + - [5.2 离线推理](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#52-离线推理) +- 6 精度对比 + - [6.1 离线推理精度统计](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#61-离线推理精度统计) + - [6.2 开源精度](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#62-开源精度) + - [6.3 精度对比](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#63-精度对比) +- 7 性能对比 + - [7.1 npu性能数据](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#71-npu性能数据) + - [7.2 T4性能数据](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#72-T4性能数据) + - [7.3 性能对比](https://gitee.com/ascend/modelzoo/tree/master/built-in/ACL_PyTorch/Benchmark/cv/classification/Pyramidbox#73-性能对比) + +## 1 模型概述 + +- **论文地址** +- **代码地址** + +### 1.1 论文地址 + +[Bertsum论文](https://arxiv.org/abs/1803.07737) + +### 1.2 代码地址 + +https://github.com/nlpyang/BertSum.git + +## 2 环境说明 + +- **深度学习框架** +- **python第三方库** + +### 2.1 深度学习框架 + +``` +python3.7.5 +CANN 5.0.3 + +pytorch >= 1.5.0 +torchvision >= 0.10.0 +onnx >= 1.7.0 + +说明:若是在conda环境下,直接采用python,不用python3.7 +``` + +### 2.2 python第三方库 + +``` +torch==1.7.1 +tensorboardX==2.4.1 +pyrouge==0.1.3 +pytorch-pretrained-bert==0.6.2 +onnx-simplifier==0.3.6 +``` + +### **2.3 环境配置** + +ROUGE配置参考博客: + +[(10条消息) Ubuntu安装配置ROUGE_BigSea-CSDN博客](https://blog.csdn.net/Hay54/article/details/78744912) + +pyrouge配置参考博客: + +[(10条消息) 在Ubuntu下配置pyrouge_MerryCao的博客-CSDN博客](https://blog.csdn.net/MerryCao/article/details/49174283) + +## 3 模型转换 + +- **pth转onnx模型** +- **onnx转om模型** + +### 3.1 pth转onnx模型 + +1.拉取代码仓库 (因为使用了开源代码模块,所以需要git clone一下) + +```shell +git clone https://github.com/nlpyang/BertSum.git +``` + +克隆下来源代码并解压,将pr中的代码放到解压之后的BertSum/src目录下面并对BertSum/src/models/data_loder.py进行一个更改: + +将31行的mask=1-(src==0)修改为mask=~(src==0) 将35行的mask=1-(clss==-1)修改为mask=~(clss==-1) + +2.下载pth权重文件 + +权重文件默认存放在**/home/BertSum/src**目录下 + +3.使用pth2onnx.py进行onnx的转换 + +``` +方法一:cd /home/BertSum/src/test +bash pth2onnx.sh +方法二:cd /home/BertSum/src +python BertSum-pth2onnx.py -mode test -bert_data_path ../bert_data/cnndm -model_path MODEL_PATH -visible_gpus -1 -gpu_ranks 0 -batch_size 1 -log_file LOG_FILE -result_path RESULT_PATH -test_all -block_trigram true -onnx_path bertsum_13000_9_bs1.onnx -path model_step_13000.pt +``` + +获得bertsum_13000_9_bs1.onnx文件 + +方法二种的-bert_data_path是数据集所在目录,-batch_size需设置为1,-onnx_path是onnx输出文件 + +### 3.2 onnx模型简化 + +由于存在expand算子导致转om不成功,所以需要使用onnx简化工具对onnx进行简化 + +使用pth2onnx.py进行onnx的转换 + +``` +方法一:cd /home/BertSum/src/test +bash simplify.sh +方法二:cd /home/BertSum/src +python -m onnxsim ./bertsum_13000_9_bs1.onnx ./bertsum_13000_9_sim_bs1.onnx +``` + +获得bertsum_13000_9_sim_bs1.onnx文件 + +### 3.3 onnx简化模型转om模型 + +1.设置环境变量 + +``` +source atc.sh +``` + +2.使用atc将onnx模型转换为om模型文件,工具使用方法可以参考CANN 5.0.3 开发辅助工具指南 (推理) 01 + +``` +方法一:cd /home/BertSum/src/test +bash onnxToom.sh +方法二:cd /home/BertSum/src +atc --input_format=ND --framework=5 --model=./bertsum_13000_9_sim_bs1.onnx --input_shape="src:1,512;segs:1,512;clss:1,37;mask:1,512;mask_cls:1,37" --output=bertsum_13000_9_sim_bs1 \ +--log=info --soc_version=Ascend310 --precision_mode=allow_mix_precision \ +--modify_mixlist=ops_info.json +``` + +方法二中的model是onnx模型的名字,input_shape是paper的shape,output为输出om的名字,--precision_mode表示采用混合精度 + +## 4 数据集预处理 + +- **数据集获取** +- **数据集预处理** +- **生成数据集信息文件** + +### 4.1 数据集获取 + +参考原代码仓 + +### 4.2 数据集预处理 + +1.预处理脚本BertSum_pth_preprocess.py + +2.执行预处理脚本,生成数据集预处理后的bin文件 + +``` +方法一:cd /home/BertSum/src/test +bash pre_deal.sh +方法二:cd /home/BertSum/src +python BertSum_pth_preprocess.py -mode test -bert_data_path ../bert_data/cnndm -model_path MODEL_PATH -visible_gpus -1 -gpu_ranks 0 -batch_size 600 -log_file LOG_FILE -result_path RESULT_PATH -test_all -block_trigram true +``` + +-bert_data_path是数据集所在目录,后面的参数是固定的。 + +### 5 离线推理 + +- **msame工具** +- **离线推理** + +### 5.1 msame工具 + +获取msame工具(https://gitee.com/ascend/tools/tree/master/msame),并将得到的msame工具放在/home/BertSum-master/src下 + +### 5.2 离线推理 + +1.执行离线推理 + +benchmark工具暂不支持多输入,因此改用msame,首先要source环境变量 + +``` +source env.sh +``` + +2.使用msame将onnx模型转换为om模型文件,工具使用方法可以参考CANN + +然后运行如下命令: + +``` +方法一:cd /home/BertSum/src/test +bash infer.sh +方法二:cd /home/BertSum/src +./msame --model "./bertsum_13000_9_sim_bs1_1.om" --input "./pre_data/src,./pre_data/segs,./pre_data/clss,./pre_data/mask,./pre_data/mask_cls" --output "./result" --outfmt bin +./msame --model "./bertsum_13000_9_sim_bs1_1.om" --input "./pre_data_1/src,./pre_data_1/segs,./pre_data_1/clss,./pre_data_1/mask,./pre_data_1/mask_cls" --output "./result" --outfmt bin +``` + +要采用msema工具推理两次,因为有些paper的shape第一维为2,所以分两次进行推理。pre_data下存放的是shape为第一维为1的所有预处理之后的数据以及shape为2的部分预处理得到的数据。shape为2的另一部分数据存放在pre_data_1下面。--model是om文件,--input是预处理之后文件所在目录,--output为输出bin文件所在目录,--outfmt代表输出bin文件*。* + +输出的bin文件在/home/BertSum-master/src/result目录下,此目录下会存在两个文件,将其中一个时间小的命名为result_1,将另一个时间大的命名为result_2。 + +## 6 精度对比 + +- **离线推理精度** +- **开源精度** +- **精度对比** + +### 6.1 离线推理精度统计 + +1.后处理 + +``` +cd /home/BertSum/src +python BertSum_pth_postprocess.py -visible_gpus -1 -gpu_ranks 0 -batch_size 600 -log_file LOG_FILE -result_path RESULT_PATH -test_all -block_trigram true -path_1 ./result/result_1 -path_2 ./result/result_2 +``` + +``` + -path_1是推理得到的文件result_1,-path_2是推理得到的result_2 + 自验报告 + # 第X次验收测试 + # 验收结果 OK + # 验收环境: A + K / CANN 5.0.3 + # 关联issue: + + # pth是否能正确转换为om + bash test/onnx2om.sh + # 验收结果: OK + # 备注: 成功生成om,无运行报错,报错日志xx 等 + + # 精度数据是否达标(需要显示官网pth精度与om模型的精度) + # npu性能数据(由于msame工具不支持多batch,所以只测试了bs1的性能) + # 验收结果: 是 / 否 + # 备注: 目标pth精度42.96;bs1验收om精度42.92;精度下降不超过1%;无运行报错,报错日志xx 等 + # 备注: 验收310测试性能bs1:61.538FPS;无运行报错,报错日志xx 等 + + # 在t4上测试bs1性能 + bash perf.sh + # 验收结果: OK / Failed + # 备注: 验收基准测试性能bs1:94.281FPS;无运行报错,报错日志xx 等 + + # 310性能是否超过基准: 否 + t4:310=(94.281/61.538)1.53倍基准 +``` + +### 6.2 开源精度 + +BertSum在线训练精度: + +42.96% + +### 6.3 离线推理精度 + +42.95% + +### 6.3 精度对比 + +由于源码采用的是动态shape,而离线推理是通过加padding固定住shape进行推理的,所以精度会有损失,因此和同一分辨率下的在线推理进行对比。对比方式:三个尺度求和取平均。 + +## 7 性能对比 + +- **310性能数据** +- **T4性能数据** +- **性能对比** + +### 7.1 310性能数据 + +每张图片平均耗时:65.06ms,所以310吞吐率为:1000/65×4=61.538 + +说明:由于msame不支持多batch,所以此处只测了bs1的性能。 + +### 7.2 T4性能数据 + +T4性能为:94.281 + +### 7.3 性能对比 + batch1:94.281>61.538 \ No newline at end of file diff --git a/ACL_PyTorch/contrib/nlp/BertSum/modelzoo_level.txt b/ACL_PyTorch/contrib/nlp/BertSum/modelzoo_level.txt index 14ac5bd404872e1264c86036fa3d2b1946828c16..aeac4e12641447ddfe648679ab454b20861732a6 100644 --- a/ACL_PyTorch/contrib/nlp/BertSum/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/nlp/BertSum/modelzoo_level.txt @@ -1,6 +1,6 @@ -ModelConvert:OK -QuantStatus:OK -FuncStatus:OK -PrecisionStatus:OK -AutoTune:NOK +ModelConvert:OK +QuantStatus:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:NOK PerfStatus:POK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/nlp/BertSum/requirements.txt b/ACL_PyTorch/contrib/nlp/BertSum/requirements.txt index e7350f2bdef53d4ff20c6537a5f70baa748b87cb..47c01fde523a048f8362acf0c4c2c4b080f16b4c 100644 --- a/ACL_PyTorch/contrib/nlp/BertSum/requirements.txt +++ b/ACL_PyTorch/contrib/nlp/BertSum/requirements.txt @@ -1,5 +1,5 @@ -torch==1.10.0 -tensorboardX==2.4.1 -pyrouge==0.1.3 -pytorch_pretrained_bert==0.6.2 -onnx-simplifier==0.3.6 +torch==1.10.0 +tensorboardX==2.4.1 +pyrouge==0.1.3 +pytorch_pretrained_bert==0.6.2 +onnx-simplifier==0.3.6 diff --git a/ACL_PyTorch/contrib/nlp/TextCNN/LICENSE b/ACL_PyTorch/contrib/nlp/TextCNN/LICENSE index 29f81d812f3e768fa89638d1f72920dbfd1413a8..261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64 100644 --- a/ACL_PyTorch/contrib/nlp/TextCNN/LICENSE +++ b/ACL_PyTorch/contrib/nlp/TextCNN/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ACL_PyTorch/contrib/nlp/TextCNN/TextCNN.patch b/ACL_PyTorch/contrib/nlp/TextCNN/TextCNN.patch index 60d727642bc8b66b1c50c8a79a29480dfab5b7a2..dd56597dfcd2f6a6459fa05ae322de262e4642a9 100644 --- a/ACL_PyTorch/contrib/nlp/TextCNN/TextCNN.patch +++ b/ACL_PyTorch/contrib/nlp/TextCNN/TextCNN.patch @@ -1,646 +1,646 @@ -二进制文件 Chinese-Text-Classification-Pytorch_back/.git/index 和 Chinese-Text-Classification-Pytorch/.git/index 不同 -diff -uprN Chinese-Text-Classification-Pytorch_back/models/DPCNN.py Chinese-Text-Classification-Pytorch/models/DPCNN.py ---- Chinese-Text-Classification-Pytorch_back/models/DPCNN.py 2021-08-13 20:49:45.263263000 +0800 -+++ Chinese-Text-Classification-Pytorch/models/DPCNN.py 1970-01-01 08:00:00.000000000 +0800 -@@ -1,89 +0,0 @@ --# coding: UTF-8 --import torch --import torch.nn as nn --import torch.nn.functional as F --import numpy as np -- -- --class Config(object): -- -- """配置参数""" -- def __init__(self, dataset, embedding): -- self.model_name = 'DPCNN' -- self.train_path = dataset + '/data/train.txt' # 训练集 -- self.dev_path = dataset + '/data/dev.txt' # 验证集 -- self.test_path = dataset + '/data/test.txt' # 测试集 -- self.class_list = [x.strip() for x in open( -- dataset + '/data/class.txt', encoding='utf-8').readlines()] # 类别名单 -- self.vocab_path = dataset + '/data/vocab.pkl' # 词表 -- self.save_path = dataset + '/saved_dict/' + self.model_name + '.ckpt' # 模型训练结果 -- self.log_path = dataset + '/log/' + self.model_name -- self.embedding_pretrained = torch.tensor( -- np.load(dataset + '/data/' + embedding)["embeddings"].astype('float32'))\ -- if embedding != 'random' else None # 预训练词向量 -- self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # 设备 -- -- self.dropout = 0.5 # 随机失活 -- self.require_improvement = 1000 # 若超过1000batch效果还没提升,则提前结束训练 -- self.num_classes = len(self.class_list) # 类别数 -- self.n_vocab = 0 # 词表大小,在运行时赋值 -- self.num_epochs = 20 # epoch数 -- self.batch_size = 128 # mini-batch大小 -- self.pad_size = 32 # 每句话处理成的长度(短填长切) -- self.learning_rate = 1e-3 # 学习率 -- self.embed = self.embedding_pretrained.size(1)\ -- if self.embedding_pretrained is not None else 300 # 字向量维度 -- self.num_filters = 250 # 卷积核数量(channels数) -- -- --'''Deep Pyramid Convolutional Neural Networks for Text Categorization''' -- -- --class Model(nn.Module): -- def __init__(self, config): -- super(Model, self).__init__() -- if config.embedding_pretrained is not None: -- self.embedding = nn.Embedding.from_pretrained(config.embedding_pretrained, freeze=False) -- else: -- self.embedding = nn.Embedding(config.n_vocab, config.embed, padding_idx=config.n_vocab - 1) -- self.conv_region = nn.Conv2d(1, config.num_filters, (3, config.embed), stride=1) -- self.conv = nn.Conv2d(config.num_filters, config.num_filters, (3, 1), stride=1) -- self.max_pool = nn.MaxPool2d(kernel_size=(3, 1), stride=2) -- self.padding1 = nn.ZeroPad2d((0, 0, 1, 1)) # top bottom -- self.padding2 = nn.ZeroPad2d((0, 0, 0, 1)) # bottom -- self.relu = nn.ReLU() -- self.fc = nn.Linear(config.num_filters, config.num_classes) -- -- def forward(self, x): -- x = x[0] -- x = self.embedding(x) -- x = x.unsqueeze(1) # [batch_size, 250, seq_len, 1] -- x = self.conv_region(x) # [batch_size, 250, seq_len-3+1, 1] -- -- x = self.padding1(x) # [batch_size, 250, seq_len, 1] -- x = self.relu(x) -- x = self.conv(x) # [batch_size, 250, seq_len-3+1, 1] -- x = self.padding1(x) # [batch_size, 250, seq_len, 1] -- x = self.relu(x) -- x = self.conv(x) # [batch_size, 250, seq_len-3+1, 1] -- while x.size()[2] > 2: -- x = self._block(x) -- x = x.squeeze() # [batch_size, num_filters(250)] -- x = self.fc(x) -- return x -- -- def _block(self, x): -- x = self.padding2(x) -- px = self.max_pool(x) -- -- x = self.padding1(px) -- x = F.relu(x) -- x = self.conv(x) -- -- x = self.padding1(x) -- x = F.relu(x) -- x = self.conv(x) -- -- # Short Cut -- x = x + px -- return x -diff -uprN Chinese-Text-Classification-Pytorch_back/models/FastText.py Chinese-Text-Classification-Pytorch/models/FastText.py ---- Chinese-Text-Classification-Pytorch_back/models/FastText.py 2021-08-13 20:49:45.263263000 +0800 -+++ Chinese-Text-Classification-Pytorch/models/FastText.py 1970-01-01 08:00:00.000000000 +0800 -@@ -1,69 +0,0 @@ --# coding: UTF-8 --import torch --import torch.nn as nn --import torch.nn.functional as F --import numpy as np -- -- --class Config(object): -- -- """配置参数""" -- def __init__(self, dataset, embedding): -- self.model_name = 'FastText' -- self.train_path = dataset + '/data/train.txt' # 训练集 -- self.dev_path = dataset + '/data/dev.txt' # 验证集 -- self.test_path = dataset + '/data/test.txt' # 测试集 -- self.class_list = [x.strip() for x in open( -- dataset + '/data/class.txt', encoding='utf-8').readlines()] # 类别名单 -- self.vocab_path = dataset + '/data/vocab.pkl' # 词表 -- self.save_path = dataset + '/saved_dict/' + self.model_name + '.ckpt' # 模型训练结果 -- self.log_path = dataset + '/log/' + self.model_name -- self.embedding_pretrained = torch.tensor( -- np.load(dataset + '/data/' + embedding)["embeddings"].astype('float32'))\ -- if embedding != 'random' else None # 预训练词向量 -- self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # 设备 -- -- self.dropout = 0.5 # 随机失活 -- self.require_improvement = 1000 # 若超过1000batch效果还没提升,则提前结束训练 -- self.num_classes = len(self.class_list) # 类别数 -- self.n_vocab = 0 # 词表大小,在运行时赋值 -- self.num_epochs = 20 # epoch数 -- self.batch_size = 128 # mini-batch大小 -- self.pad_size = 32 # 每句话处理成的长度(短填长切) -- self.learning_rate = 1e-3 # 学习率 -- self.embed = self.embedding_pretrained.size(1)\ -- if self.embedding_pretrained is not None else 300 # 字向量维度 -- self.hidden_size = 256 # 隐藏层大小 -- self.n_gram_vocab = 250499 # ngram 词表大小 -- -- --'''Bag of Tricks for Efficient Text Classification''' -- -- --class Model(nn.Module): -- def __init__(self, config): -- super(Model, self).__init__() -- if config.embedding_pretrained is not None: -- self.embedding = nn.Embedding.from_pretrained(config.embedding_pretrained, freeze=False) -- else: -- self.embedding = nn.Embedding(config.n_vocab, config.embed, padding_idx=config.n_vocab - 1) -- self.embedding_ngram2 = nn.Embedding(config.n_gram_vocab, config.embed) -- self.embedding_ngram3 = nn.Embedding(config.n_gram_vocab, config.embed) -- self.dropout = nn.Dropout(config.dropout) -- self.fc1 = nn.Linear(config.embed * 3, config.hidden_size) -- # self.dropout2 = nn.Dropout(config.dropout) -- self.fc2 = nn.Linear(config.hidden_size, config.num_classes) -- -- def forward(self, x): -- -- out_word = self.embedding(x[0]) -- out_bigram = self.embedding_ngram2(x[2]) -- out_trigram = self.embedding_ngram3(x[3]) -- out = torch.cat((out_word, out_bigram, out_trigram), -1) -- -- out = out.mean(dim=1) -- out = self.dropout(out) -- out = self.fc1(out) -- out = F.relu(out) -- out = self.fc2(out) -- return out -二进制文件 Chinese-Text-Classification-Pytorch_back/models/__pycache__/TextCNN.cpython-37.pyc 和 Chinese-Text-Classification-Pytorch/models/__pycache__/TextCNN.cpython-37.pyc 不同 -diff -uprN Chinese-Text-Classification-Pytorch_back/models/TextCNN.py Chinese-Text-Classification-Pytorch/models/TextCNN.py ---- Chinese-Text-Classification-Pytorch_back/models/TextCNN.py 2021-08-13 20:49:45.263263000 +0800 -+++ Chinese-Text-Classification-Pytorch/models/TextCNN.py 2021-09-07 21:23:07.218366753 +0800 -@@ -1,4 +1,6 @@ - # coding: UTF-8 -+import os.path -+ - import torch - import torch.nn as nn - import torch.nn.functional as F -@@ -13,10 +15,11 @@ class Config(object): - self.train_path = dataset + '/data/train.txt' # 训练集 - self.dev_path = dataset + '/data/dev.txt' # 验证集 - self.test_path = dataset + '/data/test.txt' # 测试集 -+ print('path', os.path.abspath(dataset+'/data/class.txt')) - self.class_list = [x.strip() for x in open( - dataset + '/data/class.txt', encoding='utf-8').readlines()] # 类别名单 - self.vocab_path = dataset + '/data/vocab.pkl' # 词表 -- self.save_path = dataset + '/saved_dict/' + self.model_name + '.ckpt' # 模型训练结果 -+ self.save_path = dataset + '/saved_dict/' + self.model_name + '.pth' # 模型训练结果 - self.log_path = dataset + '/log/' + self.model_name - self.embedding_pretrained = torch.tensor( - np.load(dataset + '/data/' + embedding)["embeddings"].astype('float32'))\ -@@ -49,18 +52,21 @@ class Model(nn.Module): - self.embedding = nn.Embedding(config.n_vocab, config.embed, padding_idx=config.n_vocab - 1) - self.convs = nn.ModuleList( - [nn.Conv2d(1, config.num_filters, (k, config.embed)) for k in config.filter_sizes]) -+ self.pools = nn.ModuleList( -+ [nn.MaxPool1d(config.pad_size - k + 1) for k in config.filter_sizes]) - self.dropout = nn.Dropout(config.dropout) - self.fc = nn.Linear(config.num_filters * len(config.filter_sizes), config.num_classes) - -- def conv_and_pool(self, x, conv): -+ def conv_and_pool(self, x, conv, pool): - x = F.relu(conv(x)).squeeze(3) -- x = F.max_pool1d(x, x.size(2)).squeeze(2) -+ x = pool(x).squeeze(2) -+ # x = F.max_pool1d(x, x.size(2)).squeeze(2) - return x - - def forward(self, x): -- out = self.embedding(x[0]) -+ out = self.embedding(x) - out = out.unsqueeze(1) -- out = torch.cat([self.conv_and_pool(out, conv) for conv in self.convs], 1) -+ out = torch.cat([self.conv_and_pool(out, conv, pool) for conv, pool in zip(self.convs, self.pools)], 1) - out = self.dropout(out) - out = self.fc(out) - return out -diff -uprN Chinese-Text-Classification-Pytorch_back/models/TextRCNN.py Chinese-Text-Classification-Pytorch/models/TextRCNN.py ---- Chinese-Text-Classification-Pytorch_back/models/TextRCNN.py 2021-08-13 20:49:45.263263000 +0800 -+++ Chinese-Text-Classification-Pytorch/models/TextRCNN.py 1970-01-01 08:00:00.000000000 +0800 -@@ -1,64 +0,0 @@ --# coding: UTF-8 --import torch --import torch.nn as nn --import torch.nn.functional as F --import numpy as np -- -- --class Config(object): -- -- """配置参数""" -- def __init__(self, dataset, embedding): -- self.model_name = 'TextRCNN' -- self.train_path = dataset + '/data/train.txt' # 训练集 -- self.dev_path = dataset + '/data/dev.txt' # 验证集 -- self.test_path = dataset + '/data/test.txt' # 测试集 -- self.class_list = [x.strip() for x in open( -- dataset + '/data/class.txt', encoding='utf-8').readlines()] # 类别名单 -- self.vocab_path = dataset + '/data/vocab.pkl' # 词表 -- self.save_path = dataset + '/saved_dict/' + self.model_name + '.ckpt' # 模型训练结果 -- self.log_path = dataset + '/log/' + self.model_name -- self.embedding_pretrained = torch.tensor( -- np.load(dataset + '/data/' + embedding)["embeddings"].astype('float32'))\ -- if embedding != 'random' else None # 预训练词向量 -- self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # 设备 -- -- self.dropout = 1.0 # 随机失活 -- self.require_improvement = 1000 # 若超过1000batch效果还没提升,则提前结束训练 -- self.num_classes = len(self.class_list) # 类别数 -- self.n_vocab = 0 # 词表大小,在运行时赋值 -- self.num_epochs = 10 # epoch数 -- self.batch_size = 128 # mini-batch大小 -- self.pad_size = 32 # 每句话处理成的长度(短填长切) -- self.learning_rate = 1e-3 # 学习率 -- self.embed = self.embedding_pretrained.size(1)\ -- if self.embedding_pretrained is not None else 300 # 字向量维度, 若使用了预训练词向量,则维度统一 -- self.hidden_size = 256 # lstm隐藏层 -- self.num_layers = 1 # lstm层数 -- -- --'''Recurrent Convolutional Neural Networks for Text Classification''' -- -- --class Model(nn.Module): -- def __init__(self, config): -- super(Model, self).__init__() -- if config.embedding_pretrained is not None: -- self.embedding = nn.Embedding.from_pretrained(config.embedding_pretrained, freeze=False) -- else: -- self.embedding = nn.Embedding(config.n_vocab, config.embed, padding_idx=config.n_vocab - 1) -- self.lstm = nn.LSTM(config.embed, config.hidden_size, config.num_layers, -- bidirectional=True, batch_first=True, dropout=config.dropout) -- self.maxpool = nn.MaxPool1d(config.pad_size) -- self.fc = nn.Linear(config.hidden_size * 2 + config.embed, config.num_classes) -- -- def forward(self, x): -- x, _ = x -- embed = self.embedding(x) # [batch_size, seq_len, embeding]=[64, 32, 64] -- out, _ = self.lstm(embed) -- out = torch.cat((embed, out), 2) -- out = F.relu(out) -- out = out.permute(0, 2, 1) -- out = self.maxpool(out).squeeze() -- out = self.fc(out) -- return out -diff -uprN Chinese-Text-Classification-Pytorch_back/models/TextRNN_Att.py Chinese-Text-Classification-Pytorch/models/TextRNN_Att.py ---- Chinese-Text-Classification-Pytorch_back/models/TextRNN_Att.py 2021-08-13 20:49:45.263263000 +0800 -+++ Chinese-Text-Classification-Pytorch/models/TextRNN_Att.py 1970-01-01 08:00:00.000000000 +0800 -@@ -1,73 +0,0 @@ --# coding: UTF-8 --import torch --import torch.nn as nn --import torch.nn.functional as F --import numpy as np -- -- --class Config(object): -- -- """配置参数""" -- def __init__(self, dataset, embedding): -- self.model_name = 'TextRNN_Att' -- self.train_path = dataset + '/data/train.txt' # 训练集 -- self.dev_path = dataset + '/data/dev.txt' # 验证集 -- self.test_path = dataset + '/data/test.txt' # 测试集 -- self.class_list = [x.strip() for x in open( -- dataset + '/data/class.txt', encoding='utf-8').readlines()] # 类别名单 -- self.vocab_path = dataset + '/data/vocab.pkl' # 词表 -- self.save_path = dataset + '/saved_dict/' + self.model_name + '.ckpt' # 模型训练结果 -- self.log_path = dataset + '/log/' + self.model_name -- self.embedding_pretrained = torch.tensor( -- np.load(dataset + '/data/' + embedding)["embeddings"].astype('float32'))\ -- if embedding != 'random' else None # 预训练词向量 -- self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # 设备 -- -- self.dropout = 0.5 # 随机失活 -- self.require_improvement = 1000 # 若超过1000batch效果还没提升,则提前结束训练 -- self.num_classes = len(self.class_list) # 类别数 -- self.n_vocab = 0 # 词表大小,在运行时赋值 -- self.num_epochs = 10 # epoch数 -- self.batch_size = 128 # mini-batch大小 -- self.pad_size = 32 # 每句话处理成的长度(短填长切) -- self.learning_rate = 1e-3 # 学习率 -- self.embed = self.embedding_pretrained.size(1)\ -- if self.embedding_pretrained is not None else 300 # 字向量维度, 若使用了预训练词向量,则维度统一 -- self.hidden_size = 128 # lstm隐藏层 -- self.num_layers = 2 # lstm层数 -- self.hidden_size2 = 64 -- -- --'''Attention-Based Bidirectional Long Short-Term Memory Networks for Relation Classification''' -- -- --class Model(nn.Module): -- def __init__(self, config): -- super(Model, self).__init__() -- if config.embedding_pretrained is not None: -- self.embedding = nn.Embedding.from_pretrained(config.embedding_pretrained, freeze=False) -- else: -- self.embedding = nn.Embedding(config.n_vocab, config.embed, padding_idx=config.n_vocab - 1) -- self.lstm = nn.LSTM(config.embed, config.hidden_size, config.num_layers, -- bidirectional=True, batch_first=True, dropout=config.dropout) -- self.tanh1 = nn.Tanh() -- # self.u = nn.Parameter(torch.Tensor(config.hidden_size * 2, config.hidden_size * 2)) -- self.w = nn.Parameter(torch.zeros(config.hidden_size * 2)) -- self.tanh2 = nn.Tanh() -- self.fc1 = nn.Linear(config.hidden_size * 2, config.hidden_size2) -- self.fc = nn.Linear(config.hidden_size2, config.num_classes) -- -- def forward(self, x): -- x, _ = x -- emb = self.embedding(x) # [batch_size, seq_len, embeding]=[128, 32, 300] -- H, _ = self.lstm(emb) # [batch_size, seq_len, hidden_size * num_direction]=[128, 32, 256] -- -- M = self.tanh1(H) # [128, 32, 256] -- # M = torch.tanh(torch.matmul(H, self.u)) -- alpha = F.softmax(torch.matmul(M, self.w), dim=1).unsqueeze(-1) # [128, 32, 1] -- out = H * alpha # [128, 32, 256] -- out = torch.sum(out, 1) # [128, 256] -- out = F.relu(out) -- out = self.fc1(out) -- out = self.fc(out) # [128, 64] -- return out -diff -uprN Chinese-Text-Classification-Pytorch_back/models/TextRNN.py Chinese-Text-Classification-Pytorch/models/TextRNN.py ---- Chinese-Text-Classification-Pytorch_back/models/TextRNN.py 2021-08-13 20:49:45.263263000 +0800 -+++ Chinese-Text-Classification-Pytorch/models/TextRNN.py 1970-01-01 08:00:00.000000000 +0800 -@@ -1,75 +0,0 @@ --# coding: UTF-8 --import torch --import torch.nn as nn --import numpy as np -- -- --class Config(object): -- -- """配置参数""" -- def __init__(self, dataset, embedding): -- self.model_name = 'TextRNN' -- self.train_path = dataset + '/data/train.txt' # 训练集 -- self.dev_path = dataset + '/data/dev.txt' # 验证集 -- self.test_path = dataset + '/data/test.txt' # 测试集 -- self.class_list = [x.strip() for x in open( -- dataset + '/data/class.txt', encoding='utf-8').readlines()] # 类别名单 -- self.vocab_path = dataset + '/data/vocab.pkl' # 词表 -- self.save_path = dataset + '/saved_dict/' + self.model_name + '.ckpt' # 模型训练结果 -- self.log_path = dataset + '/log/' + self.model_name -- self.embedding_pretrained = torch.tensor( -- np.load(dataset + '/data/' + embedding)["embeddings"].astype('float32'))\ -- if embedding != 'random' else None # 预训练词向量 -- self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # 设备 -- -- self.dropout = 0.5 # 随机失活 -- self.require_improvement = 1000 # 若超过1000batch效果还没提升,则提前结束训练 -- self.num_classes = len(self.class_list) # 类别数 -- self.n_vocab = 0 # 词表大小,在运行时赋值 -- self.num_epochs = 10 # epoch数 -- self.batch_size = 128 # mini-batch大小 -- self.pad_size = 32 # 每句话处理成的长度(短填长切) -- self.learning_rate = 1e-3 # 学习率 -- self.embed = self.embedding_pretrained.size(1)\ -- if self.embedding_pretrained is not None else 300 # 字向量维度, 若使用了预训练词向量,则维度统一 -- self.hidden_size = 128 # lstm隐藏层 -- self.num_layers = 2 # lstm层数 -- -- --'''Recurrent Neural Network for Text Classification with Multi-Task Learning''' -- -- --class Model(nn.Module): -- def __init__(self, config): -- super(Model, self).__init__() -- if config.embedding_pretrained is not None: -- self.embedding = nn.Embedding.from_pretrained(config.embedding_pretrained, freeze=False) -- else: -- self.embedding = nn.Embedding(config.n_vocab, config.embed, padding_idx=config.n_vocab - 1) -- self.lstm = nn.LSTM(config.embed, config.hidden_size, config.num_layers, -- bidirectional=True, batch_first=True, dropout=config.dropout) -- self.fc = nn.Linear(config.hidden_size * 2, config.num_classes) -- -- def forward(self, x): -- x, _ = x -- out = self.embedding(x) # [batch_size, seq_len, embeding]=[128, 32, 300] -- out, _ = self.lstm(out) -- out = self.fc(out[:, -1, :]) # 句子最后时刻的 hidden state -- return out -- -- '''变长RNN,效果差不多,甚至还低了点...''' -- # def forward(self, x): -- # x, seq_len = x -- # out = self.embedding(x) -- # _, idx_sort = torch.sort(seq_len, dim=0, descending=True) # 长度从长到短排序(index) -- # _, idx_unsort = torch.sort(idx_sort) # 排序后,原序列的 index -- # out = torch.index_select(out, 0, idx_sort) -- # seq_len = list(seq_len[idx_sort]) -- # out = nn.utils.rnn.pack_padded_sequence(out, seq_len, batch_first=True) -- # # [batche_size, seq_len, num_directions * hidden_size] -- # out, (hn, _) = self.lstm(out) -- # out = torch.cat((hn[2], hn[3]), -1) -- # # out, _ = nn.utils.rnn.pad_packed_sequence(out, batch_first=True) -- # out = out.index_select(0, idx_unsort) -- # out = self.fc(out) -- # return out -diff -uprN Chinese-Text-Classification-Pytorch_back/models/Transformer.py Chinese-Text-Classification-Pytorch/models/Transformer.py ---- Chinese-Text-Classification-Pytorch_back/models/Transformer.py 2021-08-13 20:49:45.263263000 +0800 -+++ Chinese-Text-Classification-Pytorch/models/Transformer.py 1970-01-01 08:00:00.000000000 +0800 -@@ -1,178 +0,0 @@ --import torch --import torch.nn as nn --import torch.nn.functional as F --import numpy as np --import copy -- -- --class Config(object): -- -- """配置参数""" -- def __init__(self, dataset, embedding): -- self.model_name = 'Transformer' -- self.train_path = dataset + '/data/train.txt' # 训练集 -- self.dev_path = dataset + '/data/dev.txt' # 验证集 -- self.test_path = dataset + '/data/test.txt' # 测试集 -- self.class_list = [x.strip() for x in open( -- dataset + '/data/class.txt', encoding='utf-8').readlines()] # 类别名单 -- self.vocab_path = dataset + '/data/vocab.pkl' # 词表 -- self.save_path = dataset + '/saved_dict/' + self.model_name + '.ckpt' # 模型训练结果 -- self.log_path = dataset + '/log/' + self.model_name -- self.embedding_pretrained = torch.tensor( -- np.load(dataset + '/data/' + embedding)["embeddings"].astype('float32'))\ -- if embedding != 'random' else None # 预训练词向量 -- self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # 设备 -- -- self.dropout = 0.5 # 随机失活 -- self.require_improvement = 2000 # 若超过1000batch效果还没提升,则提前结束训练 -- self.num_classes = len(self.class_list) # 类别数 -- self.n_vocab = 0 # 词表大小,在运行时赋值 -- self.num_epochs = 20 # epoch数 -- self.batch_size = 128 # mini-batch大小 -- self.pad_size = 32 # 每句话处理成的长度(短填长切) -- self.learning_rate = 5e-4 # 学习率 -- self.embed = self.embedding_pretrained.size(1)\ -- if self.embedding_pretrained is not None else 300 # 字向量维度 -- self.dim_model = 300 -- self.hidden = 1024 -- self.last_hidden = 512 -- self.num_head = 5 -- self.num_encoder = 2 -- -- --'''Attention Is All You Need''' -- -- --class Model(nn.Module): -- def __init__(self, config): -- super(Model, self).__init__() -- if config.embedding_pretrained is not None: -- self.embedding = nn.Embedding.from_pretrained(config.embedding_pretrained, freeze=False) -- else: -- self.embedding = nn.Embedding(config.n_vocab, config.embed, padding_idx=config.n_vocab - 1) -- -- self.postion_embedding = Positional_Encoding(config.embed, config.pad_size, config.dropout, config.device) -- self.encoder = Encoder(config.dim_model, config.num_head, config.hidden, config.dropout) -- self.encoders = nn.ModuleList([ -- copy.deepcopy(self.encoder) -- # Encoder(config.dim_model, config.num_head, config.hidden, config.dropout) -- for _ in range(config.num_encoder)]) -- -- self.fc1 = nn.Linear(config.pad_size * config.dim_model, config.num_classes) -- # self.fc2 = nn.Linear(config.last_hidden, config.num_classes) -- # self.fc1 = nn.Linear(config.dim_model, config.num_classes) -- -- def forward(self, x): -- out = self.embedding(x[0]) -- out = self.postion_embedding(out) -- for encoder in self.encoders: -- out = encoder(out) -- out = out.view(out.size(0), -1) -- # out = torch.mean(out, 1) -- out = self.fc1(out) -- return out -- -- --class Encoder(nn.Module): -- def __init__(self, dim_model, num_head, hidden, dropout): -- super(Encoder, self).__init__() -- self.attention = Multi_Head_Attention(dim_model, num_head, dropout) -- self.feed_forward = Position_wise_Feed_Forward(dim_model, hidden, dropout) -- -- def forward(self, x): -- out = self.attention(x) -- out = self.feed_forward(out) -- return out -- -- --class Positional_Encoding(nn.Module): -- def __init__(self, embed, pad_size, dropout, device): -- super(Positional_Encoding, self).__init__() -- self.device = device -- self.pe = torch.tensor([[pos / (10000.0 ** (i // 2 * 2.0 / embed)) for i in range(embed)] for pos in range(pad_size)]) -- self.pe[:, 0::2] = np.sin(self.pe[:, 0::2]) -- self.pe[:, 1::2] = np.cos(self.pe[:, 1::2]) -- self.dropout = nn.Dropout(dropout) -- -- def forward(self, x): -- out = x + nn.Parameter(self.pe, requires_grad=False).to(self.device) -- out = self.dropout(out) -- return out -- -- --class Scaled_Dot_Product_Attention(nn.Module): -- '''Scaled Dot-Product Attention ''' -- def __init__(self): -- super(Scaled_Dot_Product_Attention, self).__init__() -- -- def forward(self, Q, K, V, scale=None): -- ''' -- Args: -- Q: [batch_size, len_Q, dim_Q] -- K: [batch_size, len_K, dim_K] -- V: [batch_size, len_V, dim_V] -- scale: 缩放因子 论文为根号dim_K -- Return: -- self-attention后的张量,以及attention张量 -- ''' -- attention = torch.matmul(Q, K.permute(0, 2, 1)) -- if scale: -- attention = attention * scale -- # if mask: # TODO change this -- # attention = attention.masked_fill_(mask == 0, -1e9) -- attention = F.softmax(attention, dim=-1) -- context = torch.matmul(attention, V) -- return context -- -- --class Multi_Head_Attention(nn.Module): -- def __init__(self, dim_model, num_head, dropout=0.0): -- super(Multi_Head_Attention, self).__init__() -- self.num_head = num_head -- assert dim_model % num_head == 0 -- self.dim_head = dim_model // self.num_head -- self.fc_Q = nn.Linear(dim_model, num_head * self.dim_head) -- self.fc_K = nn.Linear(dim_model, num_head * self.dim_head) -- self.fc_V = nn.Linear(dim_model, num_head * self.dim_head) -- self.attention = Scaled_Dot_Product_Attention() -- self.fc = nn.Linear(num_head * self.dim_head, dim_model) -- self.dropout = nn.Dropout(dropout) -- self.layer_norm = nn.LayerNorm(dim_model) -- -- def forward(self, x): -- batch_size = x.size(0) -- Q = self.fc_Q(x) -- K = self.fc_K(x) -- V = self.fc_V(x) -- Q = Q.view(batch_size * self.num_head, -1, self.dim_head) -- K = K.view(batch_size * self.num_head, -1, self.dim_head) -- V = V.view(batch_size * self.num_head, -1, self.dim_head) -- # if mask: # TODO -- # mask = mask.repeat(self.num_head, 1, 1) # TODO change this -- scale = K.size(-1) ** -0.5 # 缩放因子 -- context = self.attention(Q, K, V, scale) -- -- context = context.view(batch_size, -1, self.dim_head * self.num_head) -- out = self.fc(context) -- out = self.dropout(out) -- out = out + x # 残差连接 -- out = self.layer_norm(out) -- return out -- -- --class Position_wise_Feed_Forward(nn.Module): -- def __init__(self, dim_model, hidden, dropout=0.0): -- super(Position_wise_Feed_Forward, self).__init__() -- self.fc1 = nn.Linear(dim_model, hidden) -- self.fc2 = nn.Linear(hidden, dim_model) -- self.dropout = nn.Dropout(dropout) -- self.layer_norm = nn.LayerNorm(dim_model) -- -- def forward(self, x): -- out = self.fc1(x) -- out = F.relu(out) -- out = self.fc2(out) -- out = self.dropout(out) -- out = out + x # 残差连接 -- out = self.layer_norm(out) -- return out -diff -uprN Chinese-Text-Classification-Pytorch_back/utils.py Chinese-Text-Classification-Pytorch/utils.py ---- Chinese-Text-Classification-Pytorch_back/utils.py 2021-08-13 20:49:45.263263000 +0800 -+++ Chinese-Text-Classification-Pytorch/utils.py 2021-09-07 21:23:50.874085521 +0800 -@@ -60,7 +60,7 @@ def build_dataset(config, ues_word): - # word to id - for word in token: - words_line.append(vocab.get(word, vocab.get(UNK))) -- contents.append((words_line, int(label), seq_len)) -+ contents.append((words_line, int(label))) - return contents # [([...], 0), ([...], 1), ...] - train = load_dataset(config.train_path, config.pad_size) - dev = load_dataset(config.dev_path, config.pad_size) -@@ -83,9 +83,7 @@ class DatasetIterater(object): - x = torch.LongTensor([_[0] for _ in datas]).to(self.device) - y = torch.LongTensor([_[1] for _ in datas]).to(self.device) - -- # pad前的长度(超过pad_size的设为pad_size) -- seq_len = torch.LongTensor([_[2] for _ in datas]).to(self.device) -- return (x, seq_len), y -+ return x, y - - def __next__(self): - if self.residue and self.index == self.n_batches: +二进制文件 Chinese-Text-Classification-Pytorch_back/.git/index 和 Chinese-Text-Classification-Pytorch/.git/index 不同 +diff -uprN Chinese-Text-Classification-Pytorch_back/models/DPCNN.py Chinese-Text-Classification-Pytorch/models/DPCNN.py +--- Chinese-Text-Classification-Pytorch_back/models/DPCNN.py 2021-08-13 20:49:45.263263000 +0800 ++++ Chinese-Text-Classification-Pytorch/models/DPCNN.py 1970-01-01 08:00:00.000000000 +0800 +@@ -1,89 +0,0 @@ +-# coding: UTF-8 +-import torch +-import torch.nn as nn +-import torch.nn.functional as F +-import numpy as np +- +- +-class Config(object): +- +- """配置参数""" +- def __init__(self, dataset, embedding): +- self.model_name = 'DPCNN' +- self.train_path = dataset + '/data/train.txt' # 训练集 +- self.dev_path = dataset + '/data/dev.txt' # 验证集 +- self.test_path = dataset + '/data/test.txt' # 测试集 +- self.class_list = [x.strip() for x in open( +- dataset + '/data/class.txt', encoding='utf-8').readlines()] # 类别名单 +- self.vocab_path = dataset + '/data/vocab.pkl' # 词表 +- self.save_path = dataset + '/saved_dict/' + self.model_name + '.ckpt' # 模型训练结果 +- self.log_path = dataset + '/log/' + self.model_name +- self.embedding_pretrained = torch.tensor( +- np.load(dataset + '/data/' + embedding)["embeddings"].astype('float32'))\ +- if embedding != 'random' else None # 预训练词向量 +- self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # 设备 +- +- self.dropout = 0.5 # 随机失活 +- self.require_improvement = 1000 # 若超过1000batch效果还没提升,则提前结束训练 +- self.num_classes = len(self.class_list) # 类别数 +- self.n_vocab = 0 # 词表大小,在运行时赋值 +- self.num_epochs = 20 # epoch数 +- self.batch_size = 128 # mini-batch大小 +- self.pad_size = 32 # 每句话处理成的长度(短填长切) +- self.learning_rate = 1e-3 # 学习率 +- self.embed = self.embedding_pretrained.size(1)\ +- if self.embedding_pretrained is not None else 300 # 字向量维度 +- self.num_filters = 250 # 卷积核数量(channels数) +- +- +-'''Deep Pyramid Convolutional Neural Networks for Text Categorization''' +- +- +-class Model(nn.Module): +- def __init__(self, config): +- super(Model, self).__init__() +- if config.embedding_pretrained is not None: +- self.embedding = nn.Embedding.from_pretrained(config.embedding_pretrained, freeze=False) +- else: +- self.embedding = nn.Embedding(config.n_vocab, config.embed, padding_idx=config.n_vocab - 1) +- self.conv_region = nn.Conv2d(1, config.num_filters, (3, config.embed), stride=1) +- self.conv = nn.Conv2d(config.num_filters, config.num_filters, (3, 1), stride=1) +- self.max_pool = nn.MaxPool2d(kernel_size=(3, 1), stride=2) +- self.padding1 = nn.ZeroPad2d((0, 0, 1, 1)) # top bottom +- self.padding2 = nn.ZeroPad2d((0, 0, 0, 1)) # bottom +- self.relu = nn.ReLU() +- self.fc = nn.Linear(config.num_filters, config.num_classes) +- +- def forward(self, x): +- x = x[0] +- x = self.embedding(x) +- x = x.unsqueeze(1) # [batch_size, 250, seq_len, 1] +- x = self.conv_region(x) # [batch_size, 250, seq_len-3+1, 1] +- +- x = self.padding1(x) # [batch_size, 250, seq_len, 1] +- x = self.relu(x) +- x = self.conv(x) # [batch_size, 250, seq_len-3+1, 1] +- x = self.padding1(x) # [batch_size, 250, seq_len, 1] +- x = self.relu(x) +- x = self.conv(x) # [batch_size, 250, seq_len-3+1, 1] +- while x.size()[2] > 2: +- x = self._block(x) +- x = x.squeeze() # [batch_size, num_filters(250)] +- x = self.fc(x) +- return x +- +- def _block(self, x): +- x = self.padding2(x) +- px = self.max_pool(x) +- +- x = self.padding1(px) +- x = F.relu(x) +- x = self.conv(x) +- +- x = self.padding1(x) +- x = F.relu(x) +- x = self.conv(x) +- +- # Short Cut +- x = x + px +- return x +diff -uprN Chinese-Text-Classification-Pytorch_back/models/FastText.py Chinese-Text-Classification-Pytorch/models/FastText.py +--- Chinese-Text-Classification-Pytorch_back/models/FastText.py 2021-08-13 20:49:45.263263000 +0800 ++++ Chinese-Text-Classification-Pytorch/models/FastText.py 1970-01-01 08:00:00.000000000 +0800 +@@ -1,69 +0,0 @@ +-# coding: UTF-8 +-import torch +-import torch.nn as nn +-import torch.nn.functional as F +-import numpy as np +- +- +-class Config(object): +- +- """配置参数""" +- def __init__(self, dataset, embedding): +- self.model_name = 'FastText' +- self.train_path = dataset + '/data/train.txt' # 训练集 +- self.dev_path = dataset + '/data/dev.txt' # 验证集 +- self.test_path = dataset + '/data/test.txt' # 测试集 +- self.class_list = [x.strip() for x in open( +- dataset + '/data/class.txt', encoding='utf-8').readlines()] # 类别名单 +- self.vocab_path = dataset + '/data/vocab.pkl' # 词表 +- self.save_path = dataset + '/saved_dict/' + self.model_name + '.ckpt' # 模型训练结果 +- self.log_path = dataset + '/log/' + self.model_name +- self.embedding_pretrained = torch.tensor( +- np.load(dataset + '/data/' + embedding)["embeddings"].astype('float32'))\ +- if embedding != 'random' else None # 预训练词向量 +- self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # 设备 +- +- self.dropout = 0.5 # 随机失活 +- self.require_improvement = 1000 # 若超过1000batch效果还没提升,则提前结束训练 +- self.num_classes = len(self.class_list) # 类别数 +- self.n_vocab = 0 # 词表大小,在运行时赋值 +- self.num_epochs = 20 # epoch数 +- self.batch_size = 128 # mini-batch大小 +- self.pad_size = 32 # 每句话处理成的长度(短填长切) +- self.learning_rate = 1e-3 # 学习率 +- self.embed = self.embedding_pretrained.size(1)\ +- if self.embedding_pretrained is not None else 300 # 字向量维度 +- self.hidden_size = 256 # 隐藏层大小 +- self.n_gram_vocab = 250499 # ngram 词表大小 +- +- +-'''Bag of Tricks for Efficient Text Classification''' +- +- +-class Model(nn.Module): +- def __init__(self, config): +- super(Model, self).__init__() +- if config.embedding_pretrained is not None: +- self.embedding = nn.Embedding.from_pretrained(config.embedding_pretrained, freeze=False) +- else: +- self.embedding = nn.Embedding(config.n_vocab, config.embed, padding_idx=config.n_vocab - 1) +- self.embedding_ngram2 = nn.Embedding(config.n_gram_vocab, config.embed) +- self.embedding_ngram3 = nn.Embedding(config.n_gram_vocab, config.embed) +- self.dropout = nn.Dropout(config.dropout) +- self.fc1 = nn.Linear(config.embed * 3, config.hidden_size) +- # self.dropout2 = nn.Dropout(config.dropout) +- self.fc2 = nn.Linear(config.hidden_size, config.num_classes) +- +- def forward(self, x): +- +- out_word = self.embedding(x[0]) +- out_bigram = self.embedding_ngram2(x[2]) +- out_trigram = self.embedding_ngram3(x[3]) +- out = torch.cat((out_word, out_bigram, out_trigram), -1) +- +- out = out.mean(dim=1) +- out = self.dropout(out) +- out = self.fc1(out) +- out = F.relu(out) +- out = self.fc2(out) +- return out +二进制文件 Chinese-Text-Classification-Pytorch_back/models/__pycache__/TextCNN.cpython-37.pyc 和 Chinese-Text-Classification-Pytorch/models/__pycache__/TextCNN.cpython-37.pyc 不同 +diff -uprN Chinese-Text-Classification-Pytorch_back/models/TextCNN.py Chinese-Text-Classification-Pytorch/models/TextCNN.py +--- Chinese-Text-Classification-Pytorch_back/models/TextCNN.py 2021-08-13 20:49:45.263263000 +0800 ++++ Chinese-Text-Classification-Pytorch/models/TextCNN.py 2021-09-07 21:23:07.218366753 +0800 +@@ -1,4 +1,6 @@ + # coding: UTF-8 ++import os.path ++ + import torch + import torch.nn as nn + import torch.nn.functional as F +@@ -13,10 +15,11 @@ class Config(object): + self.train_path = dataset + '/data/train.txt' # 训练集 + self.dev_path = dataset + '/data/dev.txt' # 验证集 + self.test_path = dataset + '/data/test.txt' # 测试集 ++ print('path', os.path.abspath(dataset+'/data/class.txt')) + self.class_list = [x.strip() for x in open( + dataset + '/data/class.txt', encoding='utf-8').readlines()] # 类别名单 + self.vocab_path = dataset + '/data/vocab.pkl' # 词表 +- self.save_path = dataset + '/saved_dict/' + self.model_name + '.ckpt' # 模型训练结果 ++ self.save_path = dataset + '/saved_dict/' + self.model_name + '.pth' # 模型训练结果 + self.log_path = dataset + '/log/' + self.model_name + self.embedding_pretrained = torch.tensor( + np.load(dataset + '/data/' + embedding)["embeddings"].astype('float32'))\ +@@ -49,18 +52,21 @@ class Model(nn.Module): + self.embedding = nn.Embedding(config.n_vocab, config.embed, padding_idx=config.n_vocab - 1) + self.convs = nn.ModuleList( + [nn.Conv2d(1, config.num_filters, (k, config.embed)) for k in config.filter_sizes]) ++ self.pools = nn.ModuleList( ++ [nn.MaxPool1d(config.pad_size - k + 1) for k in config.filter_sizes]) + self.dropout = nn.Dropout(config.dropout) + self.fc = nn.Linear(config.num_filters * len(config.filter_sizes), config.num_classes) + +- def conv_and_pool(self, x, conv): ++ def conv_and_pool(self, x, conv, pool): + x = F.relu(conv(x)).squeeze(3) +- x = F.max_pool1d(x, x.size(2)).squeeze(2) ++ x = pool(x).squeeze(2) ++ # x = F.max_pool1d(x, x.size(2)).squeeze(2) + return x + + def forward(self, x): +- out = self.embedding(x[0]) ++ out = self.embedding(x) + out = out.unsqueeze(1) +- out = torch.cat([self.conv_and_pool(out, conv) for conv in self.convs], 1) ++ out = torch.cat([self.conv_and_pool(out, conv, pool) for conv, pool in zip(self.convs, self.pools)], 1) + out = self.dropout(out) + out = self.fc(out) + return out +diff -uprN Chinese-Text-Classification-Pytorch_back/models/TextRCNN.py Chinese-Text-Classification-Pytorch/models/TextRCNN.py +--- Chinese-Text-Classification-Pytorch_back/models/TextRCNN.py 2021-08-13 20:49:45.263263000 +0800 ++++ Chinese-Text-Classification-Pytorch/models/TextRCNN.py 1970-01-01 08:00:00.000000000 +0800 +@@ -1,64 +0,0 @@ +-# coding: UTF-8 +-import torch +-import torch.nn as nn +-import torch.nn.functional as F +-import numpy as np +- +- +-class Config(object): +- +- """配置参数""" +- def __init__(self, dataset, embedding): +- self.model_name = 'TextRCNN' +- self.train_path = dataset + '/data/train.txt' # 训练集 +- self.dev_path = dataset + '/data/dev.txt' # 验证集 +- self.test_path = dataset + '/data/test.txt' # 测试集 +- self.class_list = [x.strip() for x in open( +- dataset + '/data/class.txt', encoding='utf-8').readlines()] # 类别名单 +- self.vocab_path = dataset + '/data/vocab.pkl' # 词表 +- self.save_path = dataset + '/saved_dict/' + self.model_name + '.ckpt' # 模型训练结果 +- self.log_path = dataset + '/log/' + self.model_name +- self.embedding_pretrained = torch.tensor( +- np.load(dataset + '/data/' + embedding)["embeddings"].astype('float32'))\ +- if embedding != 'random' else None # 预训练词向量 +- self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # 设备 +- +- self.dropout = 1.0 # 随机失活 +- self.require_improvement = 1000 # 若超过1000batch效果还没提升,则提前结束训练 +- self.num_classes = len(self.class_list) # 类别数 +- self.n_vocab = 0 # 词表大小,在运行时赋值 +- self.num_epochs = 10 # epoch数 +- self.batch_size = 128 # mini-batch大小 +- self.pad_size = 32 # 每句话处理成的长度(短填长切) +- self.learning_rate = 1e-3 # 学习率 +- self.embed = self.embedding_pretrained.size(1)\ +- if self.embedding_pretrained is not None else 300 # 字向量维度, 若使用了预训练词向量,则维度统一 +- self.hidden_size = 256 # lstm隐藏层 +- self.num_layers = 1 # lstm层数 +- +- +-'''Recurrent Convolutional Neural Networks for Text Classification''' +- +- +-class Model(nn.Module): +- def __init__(self, config): +- super(Model, self).__init__() +- if config.embedding_pretrained is not None: +- self.embedding = nn.Embedding.from_pretrained(config.embedding_pretrained, freeze=False) +- else: +- self.embedding = nn.Embedding(config.n_vocab, config.embed, padding_idx=config.n_vocab - 1) +- self.lstm = nn.LSTM(config.embed, config.hidden_size, config.num_layers, +- bidirectional=True, batch_first=True, dropout=config.dropout) +- self.maxpool = nn.MaxPool1d(config.pad_size) +- self.fc = nn.Linear(config.hidden_size * 2 + config.embed, config.num_classes) +- +- def forward(self, x): +- x, _ = x +- embed = self.embedding(x) # [batch_size, seq_len, embeding]=[64, 32, 64] +- out, _ = self.lstm(embed) +- out = torch.cat((embed, out), 2) +- out = F.relu(out) +- out = out.permute(0, 2, 1) +- out = self.maxpool(out).squeeze() +- out = self.fc(out) +- return out +diff -uprN Chinese-Text-Classification-Pytorch_back/models/TextRNN_Att.py Chinese-Text-Classification-Pytorch/models/TextRNN_Att.py +--- Chinese-Text-Classification-Pytorch_back/models/TextRNN_Att.py 2021-08-13 20:49:45.263263000 +0800 ++++ Chinese-Text-Classification-Pytorch/models/TextRNN_Att.py 1970-01-01 08:00:00.000000000 +0800 +@@ -1,73 +0,0 @@ +-# coding: UTF-8 +-import torch +-import torch.nn as nn +-import torch.nn.functional as F +-import numpy as np +- +- +-class Config(object): +- +- """配置参数""" +- def __init__(self, dataset, embedding): +- self.model_name = 'TextRNN_Att' +- self.train_path = dataset + '/data/train.txt' # 训练集 +- self.dev_path = dataset + '/data/dev.txt' # 验证集 +- self.test_path = dataset + '/data/test.txt' # 测试集 +- self.class_list = [x.strip() for x in open( +- dataset + '/data/class.txt', encoding='utf-8').readlines()] # 类别名单 +- self.vocab_path = dataset + '/data/vocab.pkl' # 词表 +- self.save_path = dataset + '/saved_dict/' + self.model_name + '.ckpt' # 模型训练结果 +- self.log_path = dataset + '/log/' + self.model_name +- self.embedding_pretrained = torch.tensor( +- np.load(dataset + '/data/' + embedding)["embeddings"].astype('float32'))\ +- if embedding != 'random' else None # 预训练词向量 +- self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # 设备 +- +- self.dropout = 0.5 # 随机失活 +- self.require_improvement = 1000 # 若超过1000batch效果还没提升,则提前结束训练 +- self.num_classes = len(self.class_list) # 类别数 +- self.n_vocab = 0 # 词表大小,在运行时赋值 +- self.num_epochs = 10 # epoch数 +- self.batch_size = 128 # mini-batch大小 +- self.pad_size = 32 # 每句话处理成的长度(短填长切) +- self.learning_rate = 1e-3 # 学习率 +- self.embed = self.embedding_pretrained.size(1)\ +- if self.embedding_pretrained is not None else 300 # 字向量维度, 若使用了预训练词向量,则维度统一 +- self.hidden_size = 128 # lstm隐藏层 +- self.num_layers = 2 # lstm层数 +- self.hidden_size2 = 64 +- +- +-'''Attention-Based Bidirectional Long Short-Term Memory Networks for Relation Classification''' +- +- +-class Model(nn.Module): +- def __init__(self, config): +- super(Model, self).__init__() +- if config.embedding_pretrained is not None: +- self.embedding = nn.Embedding.from_pretrained(config.embedding_pretrained, freeze=False) +- else: +- self.embedding = nn.Embedding(config.n_vocab, config.embed, padding_idx=config.n_vocab - 1) +- self.lstm = nn.LSTM(config.embed, config.hidden_size, config.num_layers, +- bidirectional=True, batch_first=True, dropout=config.dropout) +- self.tanh1 = nn.Tanh() +- # self.u = nn.Parameter(torch.Tensor(config.hidden_size * 2, config.hidden_size * 2)) +- self.w = nn.Parameter(torch.zeros(config.hidden_size * 2)) +- self.tanh2 = nn.Tanh() +- self.fc1 = nn.Linear(config.hidden_size * 2, config.hidden_size2) +- self.fc = nn.Linear(config.hidden_size2, config.num_classes) +- +- def forward(self, x): +- x, _ = x +- emb = self.embedding(x) # [batch_size, seq_len, embeding]=[128, 32, 300] +- H, _ = self.lstm(emb) # [batch_size, seq_len, hidden_size * num_direction]=[128, 32, 256] +- +- M = self.tanh1(H) # [128, 32, 256] +- # M = torch.tanh(torch.matmul(H, self.u)) +- alpha = F.softmax(torch.matmul(M, self.w), dim=1).unsqueeze(-1) # [128, 32, 1] +- out = H * alpha # [128, 32, 256] +- out = torch.sum(out, 1) # [128, 256] +- out = F.relu(out) +- out = self.fc1(out) +- out = self.fc(out) # [128, 64] +- return out +diff -uprN Chinese-Text-Classification-Pytorch_back/models/TextRNN.py Chinese-Text-Classification-Pytorch/models/TextRNN.py +--- Chinese-Text-Classification-Pytorch_back/models/TextRNN.py 2021-08-13 20:49:45.263263000 +0800 ++++ Chinese-Text-Classification-Pytorch/models/TextRNN.py 1970-01-01 08:00:00.000000000 +0800 +@@ -1,75 +0,0 @@ +-# coding: UTF-8 +-import torch +-import torch.nn as nn +-import numpy as np +- +- +-class Config(object): +- +- """配置参数""" +- def __init__(self, dataset, embedding): +- self.model_name = 'TextRNN' +- self.train_path = dataset + '/data/train.txt' # 训练集 +- self.dev_path = dataset + '/data/dev.txt' # 验证集 +- self.test_path = dataset + '/data/test.txt' # 测试集 +- self.class_list = [x.strip() for x in open( +- dataset + '/data/class.txt', encoding='utf-8').readlines()] # 类别名单 +- self.vocab_path = dataset + '/data/vocab.pkl' # 词表 +- self.save_path = dataset + '/saved_dict/' + self.model_name + '.ckpt' # 模型训练结果 +- self.log_path = dataset + '/log/' + self.model_name +- self.embedding_pretrained = torch.tensor( +- np.load(dataset + '/data/' + embedding)["embeddings"].astype('float32'))\ +- if embedding != 'random' else None # 预训练词向量 +- self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # 设备 +- +- self.dropout = 0.5 # 随机失活 +- self.require_improvement = 1000 # 若超过1000batch效果还没提升,则提前结束训练 +- self.num_classes = len(self.class_list) # 类别数 +- self.n_vocab = 0 # 词表大小,在运行时赋值 +- self.num_epochs = 10 # epoch数 +- self.batch_size = 128 # mini-batch大小 +- self.pad_size = 32 # 每句话处理成的长度(短填长切) +- self.learning_rate = 1e-3 # 学习率 +- self.embed = self.embedding_pretrained.size(1)\ +- if self.embedding_pretrained is not None else 300 # 字向量维度, 若使用了预训练词向量,则维度统一 +- self.hidden_size = 128 # lstm隐藏层 +- self.num_layers = 2 # lstm层数 +- +- +-'''Recurrent Neural Network for Text Classification with Multi-Task Learning''' +- +- +-class Model(nn.Module): +- def __init__(self, config): +- super(Model, self).__init__() +- if config.embedding_pretrained is not None: +- self.embedding = nn.Embedding.from_pretrained(config.embedding_pretrained, freeze=False) +- else: +- self.embedding = nn.Embedding(config.n_vocab, config.embed, padding_idx=config.n_vocab - 1) +- self.lstm = nn.LSTM(config.embed, config.hidden_size, config.num_layers, +- bidirectional=True, batch_first=True, dropout=config.dropout) +- self.fc = nn.Linear(config.hidden_size * 2, config.num_classes) +- +- def forward(self, x): +- x, _ = x +- out = self.embedding(x) # [batch_size, seq_len, embeding]=[128, 32, 300] +- out, _ = self.lstm(out) +- out = self.fc(out[:, -1, :]) # 句子最后时刻的 hidden state +- return out +- +- '''变长RNN,效果差不多,甚至还低了点...''' +- # def forward(self, x): +- # x, seq_len = x +- # out = self.embedding(x) +- # _, idx_sort = torch.sort(seq_len, dim=0, descending=True) # 长度从长到短排序(index) +- # _, idx_unsort = torch.sort(idx_sort) # 排序后,原序列的 index +- # out = torch.index_select(out, 0, idx_sort) +- # seq_len = list(seq_len[idx_sort]) +- # out = nn.utils.rnn.pack_padded_sequence(out, seq_len, batch_first=True) +- # # [batche_size, seq_len, num_directions * hidden_size] +- # out, (hn, _) = self.lstm(out) +- # out = torch.cat((hn[2], hn[3]), -1) +- # # out, _ = nn.utils.rnn.pad_packed_sequence(out, batch_first=True) +- # out = out.index_select(0, idx_unsort) +- # out = self.fc(out) +- # return out +diff -uprN Chinese-Text-Classification-Pytorch_back/models/Transformer.py Chinese-Text-Classification-Pytorch/models/Transformer.py +--- Chinese-Text-Classification-Pytorch_back/models/Transformer.py 2021-08-13 20:49:45.263263000 +0800 ++++ Chinese-Text-Classification-Pytorch/models/Transformer.py 1970-01-01 08:00:00.000000000 +0800 +@@ -1,178 +0,0 @@ +-import torch +-import torch.nn as nn +-import torch.nn.functional as F +-import numpy as np +-import copy +- +- +-class Config(object): +- +- """配置参数""" +- def __init__(self, dataset, embedding): +- self.model_name = 'Transformer' +- self.train_path = dataset + '/data/train.txt' # 训练集 +- self.dev_path = dataset + '/data/dev.txt' # 验证集 +- self.test_path = dataset + '/data/test.txt' # 测试集 +- self.class_list = [x.strip() for x in open( +- dataset + '/data/class.txt', encoding='utf-8').readlines()] # 类别名单 +- self.vocab_path = dataset + '/data/vocab.pkl' # 词表 +- self.save_path = dataset + '/saved_dict/' + self.model_name + '.ckpt' # 模型训练结果 +- self.log_path = dataset + '/log/' + self.model_name +- self.embedding_pretrained = torch.tensor( +- np.load(dataset + '/data/' + embedding)["embeddings"].astype('float32'))\ +- if embedding != 'random' else None # 预训练词向量 +- self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # 设备 +- +- self.dropout = 0.5 # 随机失活 +- self.require_improvement = 2000 # 若超过1000batch效果还没提升,则提前结束训练 +- self.num_classes = len(self.class_list) # 类别数 +- self.n_vocab = 0 # 词表大小,在运行时赋值 +- self.num_epochs = 20 # epoch数 +- self.batch_size = 128 # mini-batch大小 +- self.pad_size = 32 # 每句话处理成的长度(短填长切) +- self.learning_rate = 5e-4 # 学习率 +- self.embed = self.embedding_pretrained.size(1)\ +- if self.embedding_pretrained is not None else 300 # 字向量维度 +- self.dim_model = 300 +- self.hidden = 1024 +- self.last_hidden = 512 +- self.num_head = 5 +- self.num_encoder = 2 +- +- +-'''Attention Is All You Need''' +- +- +-class Model(nn.Module): +- def __init__(self, config): +- super(Model, self).__init__() +- if config.embedding_pretrained is not None: +- self.embedding = nn.Embedding.from_pretrained(config.embedding_pretrained, freeze=False) +- else: +- self.embedding = nn.Embedding(config.n_vocab, config.embed, padding_idx=config.n_vocab - 1) +- +- self.postion_embedding = Positional_Encoding(config.embed, config.pad_size, config.dropout, config.device) +- self.encoder = Encoder(config.dim_model, config.num_head, config.hidden, config.dropout) +- self.encoders = nn.ModuleList([ +- copy.deepcopy(self.encoder) +- # Encoder(config.dim_model, config.num_head, config.hidden, config.dropout) +- for _ in range(config.num_encoder)]) +- +- self.fc1 = nn.Linear(config.pad_size * config.dim_model, config.num_classes) +- # self.fc2 = nn.Linear(config.last_hidden, config.num_classes) +- # self.fc1 = nn.Linear(config.dim_model, config.num_classes) +- +- def forward(self, x): +- out = self.embedding(x[0]) +- out = self.postion_embedding(out) +- for encoder in self.encoders: +- out = encoder(out) +- out = out.view(out.size(0), -1) +- # out = torch.mean(out, 1) +- out = self.fc1(out) +- return out +- +- +-class Encoder(nn.Module): +- def __init__(self, dim_model, num_head, hidden, dropout): +- super(Encoder, self).__init__() +- self.attention = Multi_Head_Attention(dim_model, num_head, dropout) +- self.feed_forward = Position_wise_Feed_Forward(dim_model, hidden, dropout) +- +- def forward(self, x): +- out = self.attention(x) +- out = self.feed_forward(out) +- return out +- +- +-class Positional_Encoding(nn.Module): +- def __init__(self, embed, pad_size, dropout, device): +- super(Positional_Encoding, self).__init__() +- self.device = device +- self.pe = torch.tensor([[pos / (10000.0 ** (i // 2 * 2.0 / embed)) for i in range(embed)] for pos in range(pad_size)]) +- self.pe[:, 0::2] = np.sin(self.pe[:, 0::2]) +- self.pe[:, 1::2] = np.cos(self.pe[:, 1::2]) +- self.dropout = nn.Dropout(dropout) +- +- def forward(self, x): +- out = x + nn.Parameter(self.pe, requires_grad=False).to(self.device) +- out = self.dropout(out) +- return out +- +- +-class Scaled_Dot_Product_Attention(nn.Module): +- '''Scaled Dot-Product Attention ''' +- def __init__(self): +- super(Scaled_Dot_Product_Attention, self).__init__() +- +- def forward(self, Q, K, V, scale=None): +- ''' +- Args: +- Q: [batch_size, len_Q, dim_Q] +- K: [batch_size, len_K, dim_K] +- V: [batch_size, len_V, dim_V] +- scale: 缩放因子 论文为根号dim_K +- Return: +- self-attention后的张量,以及attention张量 +- ''' +- attention = torch.matmul(Q, K.permute(0, 2, 1)) +- if scale: +- attention = attention * scale +- # if mask: # TODO change this +- # attention = attention.masked_fill_(mask == 0, -1e9) +- attention = F.softmax(attention, dim=-1) +- context = torch.matmul(attention, V) +- return context +- +- +-class Multi_Head_Attention(nn.Module): +- def __init__(self, dim_model, num_head, dropout=0.0): +- super(Multi_Head_Attention, self).__init__() +- self.num_head = num_head +- assert dim_model % num_head == 0 +- self.dim_head = dim_model // self.num_head +- self.fc_Q = nn.Linear(dim_model, num_head * self.dim_head) +- self.fc_K = nn.Linear(dim_model, num_head * self.dim_head) +- self.fc_V = nn.Linear(dim_model, num_head * self.dim_head) +- self.attention = Scaled_Dot_Product_Attention() +- self.fc = nn.Linear(num_head * self.dim_head, dim_model) +- self.dropout = nn.Dropout(dropout) +- self.layer_norm = nn.LayerNorm(dim_model) +- +- def forward(self, x): +- batch_size = x.size(0) +- Q = self.fc_Q(x) +- K = self.fc_K(x) +- V = self.fc_V(x) +- Q = Q.view(batch_size * self.num_head, -1, self.dim_head) +- K = K.view(batch_size * self.num_head, -1, self.dim_head) +- V = V.view(batch_size * self.num_head, -1, self.dim_head) +- # if mask: # TODO +- # mask = mask.repeat(self.num_head, 1, 1) # TODO change this +- scale = K.size(-1) ** -0.5 # 缩放因子 +- context = self.attention(Q, K, V, scale) +- +- context = context.view(batch_size, -1, self.dim_head * self.num_head) +- out = self.fc(context) +- out = self.dropout(out) +- out = out + x # 残差连接 +- out = self.layer_norm(out) +- return out +- +- +-class Position_wise_Feed_Forward(nn.Module): +- def __init__(self, dim_model, hidden, dropout=0.0): +- super(Position_wise_Feed_Forward, self).__init__() +- self.fc1 = nn.Linear(dim_model, hidden) +- self.fc2 = nn.Linear(hidden, dim_model) +- self.dropout = nn.Dropout(dropout) +- self.layer_norm = nn.LayerNorm(dim_model) +- +- def forward(self, x): +- out = self.fc1(x) +- out = F.relu(out) +- out = self.fc2(out) +- out = self.dropout(out) +- out = out + x # 残差连接 +- out = self.layer_norm(out) +- return out +diff -uprN Chinese-Text-Classification-Pytorch_back/utils.py Chinese-Text-Classification-Pytorch/utils.py +--- Chinese-Text-Classification-Pytorch_back/utils.py 2021-08-13 20:49:45.263263000 +0800 ++++ Chinese-Text-Classification-Pytorch/utils.py 2021-09-07 21:23:50.874085521 +0800 +@@ -60,7 +60,7 @@ def build_dataset(config, ues_word): + # word to id + for word in token: + words_line.append(vocab.get(word, vocab.get(UNK))) +- contents.append((words_line, int(label), seq_len)) ++ contents.append((words_line, int(label))) + return contents # [([...], 0), ([...], 1), ...] + train = load_dataset(config.train_path, config.pad_size) + dev = load_dataset(config.dev_path, config.pad_size) +@@ -83,9 +83,7 @@ class DatasetIterater(object): + x = torch.LongTensor([_[0] for _ in datas]).to(self.device) + y = torch.LongTensor([_[1] for _ in datas]).to(self.device) + +- # pad前的长度(超过pad_size的设为pad_size) +- seq_len = torch.LongTensor([_[2] for _ in datas]).to(self.device) +- return (x, seq_len), y ++ return x, y + + def __next__(self): + if self.residue and self.index == self.n_batches: diff --git a/ACL_PyTorch/contrib/nlp/albert/0001-init.patch b/ACL_PyTorch/contrib/nlp/albert/0001-init.patch index 0fcc472b691036547014bddade1234b9d19c8fa5..238f4906db41e3f8c81a2f3c44db1497dcbe63e4 100644 --- a/ACL_PyTorch/contrib/nlp/albert/0001-init.patch +++ b/ACL_PyTorch/contrib/nlp/albert/0001-init.patch @@ -34,307 +34,307 @@ index 57543c3..555ffd1 100644 --- a/callback/lr_scheduler.py +++ b/callback/lr_scheduler.py @@ -12,6 +12,7 @@ __all__ = ['CustomDecayLR', - 'CosineLRWithRestarts', - ] - -+ - def get_constant_schedule(optimizer, last_epoch=-1): - """ Create a schedule with a constant learning rate. - """ + 'CosineLRWithRestarts', + ] + ++ + def get_constant_schedule(optimizer, last_epoch=-1): + """ Create a schedule with a constant learning rate. + """ @@ -22,6 +23,7 @@ def get_constant_schedule_with_warmup(optimizer, num_warmup_steps, last_epoch=-1 - """ Create a schedule with a constant learning rate preceded by a warmup - period during which the learning rate increases linearly between 0 and 1. - """ -+ - def lr_lambda(current_step): - if current_step < num_warmup_steps: - return float(current_step) / float(max(1.0, num_warmup_steps)) + """ Create a schedule with a constant learning rate preceded by a warmup + period during which the learning rate increases linearly between 0 and 1. + """ ++ + def lr_lambda(current_step): + if current_step < num_warmup_steps: + return float(current_step) / float(max(1.0, num_warmup_steps)) @@ -34,6 +36,7 @@ def get_linear_schedule_with_warmup(optimizer, num_warmup_steps, num_training_st - """ Create a schedule with a learning rate that decreases linearly after - linearly increasing during a warmup period. - """ -+ - def lr_lambda(current_step): - if current_step < num_warmup_steps: - return float(current_step) / float(max(1, num_warmup_steps)) + """ Create a schedule with a learning rate that decreases linearly after + linearly increasing during a warmup period. + """ ++ + def lr_lambda(current_step): + if current_step < num_warmup_steps: + return float(current_step) / float(max(1, num_warmup_steps)) @@ -47,6 +50,7 @@ def get_cosine_schedule_with_warmup(optimizer, num_warmup_steps, num_training_st - values of the cosine function between 0 and `pi * cycles` after a warmup - period during which it increases linearly between 0 and 1. - """ -+ - def lr_lambda(current_step): - if current_step < num_warmup_steps: - return float(current_step) / float(max(1, num_warmup_steps)) + values of the cosine function between 0 and `pi * cycles` after a warmup + period during which it increases linearly between 0 and 1. + """ ++ + def lr_lambda(current_step): + if current_step < num_warmup_steps: + return float(current_step) / float(max(1, num_warmup_steps)) @@ -56,11 +60,13 @@ def get_cosine_schedule_with_warmup(optimizer, num_warmup_steps, num_training_st - return LambdaLR(optimizer, lr_lambda, last_epoch) - - --def get_cosine_with_hard_restarts_schedule_with_warmup(optimizer, num_warmup_steps, num_training_steps, num_cycles=1., last_epoch=-1): -+def get_cosine_with_hard_restarts_schedule_with_warmup(optimizer, num_warmup_steps, num_training_steps, num_cycles=1., -+ last_epoch=-1): - """ Create a schedule with a learning rate that decreases following the - values of the cosine function with several hard restarts, after a warmup - period during which it increases linearly between 0 and 1. - """ -+ - def lr_lambda(current_step): - if current_step < num_warmup_steps: - return float(current_step) / float(max(1, num_warmup_steps)) + return LambdaLR(optimizer, lr_lambda, last_epoch) + + +-def get_cosine_with_hard_restarts_schedule_with_warmup(optimizer, num_warmup_steps, num_training_steps, num_cycles=1., last_epoch=-1): ++def get_cosine_with_hard_restarts_schedule_with_warmup(optimizer, num_warmup_steps, num_training_steps, num_cycles=1., ++ last_epoch=-1): + """ Create a schedule with a learning rate that decreases following the + values of the cosine function with several hard restarts, after a warmup + period during which it increases linearly between 0 and 1. + """ ++ + def lr_lambda(current_step): + if current_step < num_warmup_steps: + return float(current_step) / float(max(1, num_warmup_steps)) @@ -86,11 +92,12 @@ class CustomDecayLR(object): - >>> optimizer.step() - >>> validate(...) - ''' -- def __init__(self,optimizer,lr): -+ -+ def __init__(self, optimizer, lr): - self.optimizer = optimizer - self.lr = lr - -- def epoch_step(self,epoch): -+ def epoch_step(self, epoch): - lr = self.lr - if epoch > 12: - lr = lr / 1000 + >>> optimizer.step() + >>> validate(...) + ''' +- def __init__(self,optimizer,lr): ++ ++ def __init__(self, optimizer, lr): + self.optimizer = optimizer + self.lr = lr + +- def epoch_step(self,epoch): ++ def epoch_step(self, epoch): + lr = self.lr + if epoch > 12: + lr = lr / 1000 @@ -101,6 +108,7 @@ class CustomDecayLR(object): - for param_group in self.optimizer.param_groups: - param_group['lr'] = lr - -+ - class BertLR(object): - ''' - Bert模型内定的学习率变化机制 + for param_group in self.optimizer.param_groups: + param_group['lr'] = lr + ++ + class BertLR(object): + ''' + Bert模型内定的学习率变化机制 @@ -116,23 +124,25 @@ class BertLR(object): - >>> scheduler.batch_step() - >>> validate(...) - ''' -- def __init__(self,optimizer,learning_rate,t_total,warmup): -+ -+ def __init__(self, optimizer, learning_rate, t_total, warmup): - self.learning_rate = learning_rate - self.optimizer = optimizer - self.t_total = t_total - self.warmup = warmup - - # 线性预热方式 -- def warmup_linear(self,x, warmup=0.002): -+ def warmup_linear(self, x, warmup=0.002): - if x < warmup: - return x / warmup - return 1.0 - x - -- def batch_step(self,training_step): -- lr_this_step = self.learning_rate * self.warmup_linear(training_step / self.t_total,self.warmup) -+ def batch_step(self, training_step): -+ lr_this_step = self.learning_rate * self.warmup_linear(training_step / self.t_total, self.warmup) - for param_group in self.optimizer.param_groups: - param_group['lr'] = lr_this_step - -+ - class CyclicLR(object): - ''' - Cyclical learning rates for training neural networks + >>> scheduler.batch_step() + >>> validate(...) + ''' +- def __init__(self,optimizer,learning_rate,t_total,warmup): ++ ++ def __init__(self, optimizer, learning_rate, t_total, warmup): + self.learning_rate = learning_rate + self.optimizer = optimizer + self.t_total = t_total + self.warmup = warmup + + # 线性预热方式 +- def warmup_linear(self,x, warmup=0.002): ++ def warmup_linear(self, x, warmup=0.002): + if x < warmup: + return x / warmup + return 1.0 - x + +- def batch_step(self,training_step): +- lr_this_step = self.learning_rate * self.warmup_linear(training_step / self.t_total,self.warmup) ++ def batch_step(self, training_step): ++ lr_this_step = self.learning_rate * self.warmup_linear(training_step / self.t_total, self.warmup) + for param_group in self.optimizer.param_groups: + param_group['lr'] = lr_this_step + ++ + class CyclicLR(object): + ''' + Cyclical learning rates for training neural networks @@ -148,6 +158,7 @@ class CyclicLR(object): - >>> scheduler.batch_step() - >>> validate(...) - ''' -+ - def __init__(self, optimizer, base_lr=1e-3, max_lr=6e-3, - step_size=2000, mode='triangular', gamma=1., - scale_fn=None, scale_mode='cycle', last_batch_iteration=-1): + >>> scheduler.batch_step() + >>> validate(...) + ''' ++ + def __init__(self, optimizer, base_lr=1e-3, max_lr=6e-3, + step_size=2000, mode='triangular', gamma=1., + scale_fn=None, scale_mode='cycle', last_batch_iteration=-1): @@ -207,7 +218,7 @@ class CyclicLR(object): - return 1 / (2. ** (x - 1)) - - def _exp_range_scale_fn(self, x): -- return self.gamma**(x) -+ return self.gamma ** (x) - - def get_lr(self): - step_size = float(self.step_size) + return 1 / (2. ** (x - 1)) + + def _exp_range_scale_fn(self, x): +- return self.gamma**(x) ++ return self.gamma ** (x) + + def get_lr(self): + step_size = float(self.step_size) @@ -232,6 +243,7 @@ class CyclicLR(object): - for param_group, lr in zip(self.optimizer.param_groups, self.get_lr()): - param_group['lr'] = lr - -+ - class ReduceLROnPlateau(object): - """Reduce learning rate when a metric has stopped improving. - Models often benefit from reducing the learning rate by a factor + for param_group, lr in zip(self.optimizer.param_groups, self.get_lr()): + param_group['lr'] = lr + ++ + class ReduceLROnPlateau(object): + """Reduce learning rate when a metric has stopped improving. + Models often benefit from reducing the learning rate by a factor @@ -267,7 +279,7 @@ class ReduceLROnPlateau(object): - """ - - def __init__(self, optimizer, mode='min', factor=0.1, patience=10, -- verbose=0, epsilon=1e-4, cooldown=0, min_lr=0,eps=1e-8): -+ verbose=0, epsilon=1e-4, cooldown=0, min_lr=0, eps=1e-8): - - super(ReduceLROnPlateau, self).__init__() - assert isinstance(optimizer, Optimizer) + """ + + def __init__(self, optimizer, mode='min', factor=0.1, patience=10, +- verbose=0, epsilon=1e-4, cooldown=0, min_lr=0,eps=1e-8): ++ verbose=0, epsilon=1e-4, cooldown=0, min_lr=0, eps=1e-8): + + super(ReduceLROnPlateau, self).__init__() + assert isinstance(optimizer, Optimizer) @@ -335,6 +347,7 @@ class ReduceLROnPlateau(object): - def in_cooldown(self): - return self.cooldown_counter > 0 - -+ - class ReduceLRWDOnPlateau(ReduceLROnPlateau): - """Reduce learning rate and weight decay when a metric has stopped - improving. Models often benefit from reducing the learning rate by + def in_cooldown(self): + return self.cooldown_counter > 0 + ++ + class ReduceLRWDOnPlateau(ReduceLROnPlateau): + """Reduce learning rate and weight decay when a metric has stopped + improving. Models often benefit from reducing the learning rate by @@ -356,6 +369,7 @@ class ReduceLRWDOnPlateau(ReduceLROnPlateau): - >>> # Note that step should be called after validate() - >>> scheduler.epoch_step(val_loss) - """ -+ - def epoch_step(self, metrics, epoch): - current = metrics - if current is None: + >>> # Note that step should be called after validate() + >>> scheduler.epoch_step(val_loss) + """ ++ + def epoch_step(self, metrics, epoch): + current = metrics + if current is None: @@ -384,11 +398,13 @@ class ReduceLRWDOnPlateau(ReduceLROnPlateau): - if old_weight_decay > new_weight_decay + self.eps: - param_group['weight_decay'] = new_weight_decay - if self.verbose: -- print('\nEpoch {epoch}: reducing weight decay factor of group {i} to {new_weight_decay:.4e}.') -+ print( -+ '\nEpoch {epoch}: reducing weight decay factor of group {i} to {new_weight_decay:.4e}.') - self.cooldown_counter = self.cooldown - self.wait = 0 - self.wait += 1 - -+ - class CosineLRWithRestarts(object): - """Decays learning rate with cosine annealing, normalizes weight decay - hyperparameter value, implements restarts. + if old_weight_decay > new_weight_decay + self.eps: + param_group['weight_decay'] = new_weight_decay + if self.verbose: +- print('\nEpoch {epoch}: reducing weight decay factor of group {i} to {new_weight_decay:.4e}.') ++ print( ++ '\nEpoch {epoch}: reducing weight decay factor of group {i} to {new_weight_decay:.4e}.') + self.cooldown_counter = self.cooldown + self.wait = 0 + self.wait += 1 + ++ + class CosineLRWithRestarts(object): + """Decays learning rate with cosine annealing, normalizes weight decay + hyperparameter value, implements restarts. @@ -501,7 +517,7 @@ class CosineLRWithRestarts(object): - "training loop and while initializing " - "scheduler should be the same.") - -- for param_group, (lr, weight_decay) in zip(self.optimizer.param_groups,self.get_lr(t_cur)): -+ for param_group, (lr, weight_decay) in zip(self.optimizer.param_groups, self.get_lr(t_cur)): - param_group['lr'] = lr - param_group['weight_decay'] = weight_decay - + "training loop and while initializing " + "scheduler should be the same.") + +- for param_group, (lr, weight_decay) in zip(self.optimizer.param_groups,self.get_lr(t_cur)): ++ for param_group, (lr, weight_decay) in zip(self.optimizer.param_groups, self.get_lr(t_cur)): + param_group['lr'] = lr + param_group['weight_decay'] = weight_decay + @@ -522,18 +538,19 @@ class NoamLR(object): - >>> scheduler.batch_step(global_step) - >>> validate(...) - ''' -- def __init__(self,d_model,factor,warm_up,optimizer): -+ -+ def __init__(self, d_model, factor, warm_up, optimizer): - self.optimizer = optimizer - self.warm_up = warm_up - self.factor = factor - self.d_model = d_model - self._lr = 0 - -- def get_lr(self,step): -- lr = self.factor * (self.d_model ** (-0.5) * min(step ** (-0.5),step * self.warm_up ** (-1.5))) -+ def get_lr(self, step): -+ lr = self.factor * (self.d_model ** (-0.5) * min(step ** (-0.5), step * self.warm_up ** (-1.5))) - return lr - -- def batch_step(self,step): -+ def batch_step(self, step): - ''' - update parameters and rate - :return: + >>> scheduler.batch_step(global_step) + >>> validate(...) + ''' +- def __init__(self,d_model,factor,warm_up,optimizer): ++ ++ def __init__(self, d_model, factor, warm_up, optimizer): + self.optimizer = optimizer + self.warm_up = warm_up + self.factor = factor + self.d_model = d_model + self._lr = 0 + +- def get_lr(self,step): +- lr = self.factor * (self.d_model ** (-0.5) * min(step ** (-0.5),step * self.warm_up ** (-1.5))) ++ def get_lr(self, step): ++ lr = self.factor * (self.d_model ** (-0.5) * min(step ** (-0.5), step * self.warm_up ** (-1.5))) + return lr + +- def batch_step(self,step): ++ def batch_step(self, step): + ''' + update parameters and rate + :return: diff --git a/callback/modelcheckpoint.py b/callback/modelcheckpoint.py index b7f4ffa..20b0663 100644 --- a/callback/modelcheckpoint.py +++ b/callback/modelcheckpoint.py @@ -3,19 +3,21 @@ import numpy as np - import torch - from ..tools.common import logger - -+ - class ModelCheckpoint(object): - ''' - 模型保存,两种模式: - 1. 直接保存最好模型 - 2. 按照epoch频率保存模型 - ''' -+ - def __init__(self, checkpoint_dir, - monitor, -- arch,mode='min', -+ arch, mode='min', - epoch_freq=1, -- best = None, -- save_best_only = True): -- if isinstance(checkpoint_dir,Path): -+ best=None, -+ save_best_only=True): -+ if isinstance(checkpoint_dir, Path): - checkpoint_dir = checkpoint_dir - else: - checkpoint_dir = Path(checkpoint_dir) + import torch + from ..tools.common import logger + ++ + class ModelCheckpoint(object): + ''' + 模型保存,两种模式: + 1. 直接保存最好模型 + 2. 按照epoch频率保存模型 + ''' ++ + def __init__(self, checkpoint_dir, + monitor, +- arch,mode='min', ++ arch, mode='min', + epoch_freq=1, +- best = None, +- save_best_only = True): +- if isinstance(checkpoint_dir,Path): ++ best=None, ++ save_best_only=True): ++ if isinstance(checkpoint_dir, Path): + checkpoint_dir = checkpoint_dir + else: + checkpoint_dir = Path(checkpoint_dir) @@ -36,14 +38,14 @@ class ModelCheckpoint(object): - self.monitor_op = np.greater - self.best = -np.Inf - # 这里主要重新加载模型时候 -- #对best重新赋值 -+ # 对best重新赋值 - if best: - self.best = best - - if save_best_only: - self.model_name = f"BEST_{arch}_MODEL.pth" - -- def epoch_step(self, state,current): -+ def epoch_step(self, state, current): - ''' - 正常模型 - :param state: 需要保存的信息 + self.monitor_op = np.greater + self.best = -np.Inf + # 这里主要重新加载模型时候 +- #对best重新赋值 ++ # 对best重新赋值 + if best: + self.best = best + + if save_best_only: + self.model_name = f"BEST_{arch}_MODEL.pth" + +- def epoch_step(self, state,current): ++ def epoch_step(self, state, current): + ''' + 正常模型 + :param state: 需要保存的信息 @@ -56,7 +58,7 @@ class ModelCheckpoint(object): - logger.info(f"\nEpoch {state['epoch']}: {self.monitor} improved from {self.best:.5f} to {current:.5f}") - self.best = current - state['best'] = self.best -- best_path = self.base_path/ self.model_name -+ best_path = self.base_path / self.model_name - torch.save(state, str(best_path)) - # 每隔几个epoch保存下模型 - else: + logger.info(f"\nEpoch {state['epoch']}: {self.monitor} improved from {self.best:.5f} to {current:.5f}") + self.best = current + state['best'] = self.best +- best_path = self.base_path/ self.model_name ++ best_path = self.base_path / self.model_name + torch.save(state, str(best_path)) + # 每隔几个epoch保存下模型 + else: @@ -65,7 +67,7 @@ class ModelCheckpoint(object): - logger.info(f"\nEpoch {state['epoch']}: save model to disk.") - torch.save(state, str(filename)) - -- def bert_epoch_step(self, state,current): -+ def bert_epoch_step(self, state, current): - ''' - 适合bert类型模型,适合pytorch_transformer模块 - :param state: + logger.info(f"\nEpoch {state['epoch']}: save model to disk.") + torch.save(state, str(filename)) + +- def bert_epoch_step(self, state,current): ++ def bert_epoch_step(self, state, current): + ''' + 适合bert类型模型,适合pytorch_transformer模块 + :param state: @@ -83,7 +85,7 @@ class ModelCheckpoint(object): - with open(str(output_config_file), 'w') as f: - f.write(model_to_save.config.to_json_string()) - state.pop("model") -- torch.save(state,self.base_path / 'checkpoint_info.bin') -+ torch.save(state, self.base_path / 'checkpoint_info.bin') - else: - if state['epoch'] % self.epoch_freq == 0: - save_path = self.base_path / f"checkpoint-epoch-{state['epoch']}" + with open(str(output_config_file), 'w') as f: + f.write(model_to_save.config.to_json_string()) + state.pop("model") +- torch.save(state,self.base_path / 'checkpoint_info.bin') ++ torch.save(state, self.base_path / 'checkpoint_info.bin') + else: + if state['epoch'] % self.epoch_freq == 0: + save_path = self.base_path / f"checkpoint-epoch-{state['epoch']}" diff --git a/callback/progressbar.py b/callback/progressbar.py index 5e43b88..c9d9613 100644 --- a/callback/progressbar.py +++ b/callback/progressbar.py @@ -1,4 +1,6 @@ - import time -+ -+ - class ProgressBar(object): - ''' - custom progress bar + import time ++ ++ + class ProgressBar(object): + ''' + custom progress bar @@ -7,7 +9,8 @@ class ProgressBar(object): - >>> step = 2 - >>> pbar(step=step) - ''' -- def __init__(self, n_total,width=30,desc = 'Training'): -+ -+ def __init__(self, n_total, width=30, desc='Training'): - self.width = width - self.n_total = n_total - self.start_time = time.time() + >>> step = 2 + >>> pbar(step=step) + ''' +- def __init__(self, n_total,width=30,desc = 'Training'): ++ ++ def __init__(self, n_total, width=30, desc='Training'): + self.width = width + self.n_total = n_total + self.start_time = time.time() @@ -23,7 +26,7 @@ class ProgressBar(object): - prog_width = int(self.width * recv_per) - if prog_width > 0: - bar += '=' * (prog_width - 1) -- if current< self.n_total: -+ if current < self.n_total: - bar += ">" - else: - bar += '=' + prog_width = int(self.width * recv_per) + if prog_width > 0: + bar += '=' * (prog_width - 1) +- if current< self.n_total: ++ if current < self.n_total: + bar += ">" + else: + bar += '=' diff --git a/callback/trainingmonitor.py b/callback/trainingmonitor.py index 6aea128..cb78168 100644 --- a/callback/trainingmonitor.py @@ -373,258 +373,258 @@ index 679602d..c7afb77 100644 --- a/metrics/custom_metrics.py +++ b/metrics/custom_metrics.py @@ -1,4 +1,4 @@ --#encoding:utf-8 -+# encoding:utf-8 - import torch - from tqdm import tqdm - import numpy as np +-#encoding:utf-8 ++# encoding:utf-8 + import torch + from tqdm import tqdm + import numpy as np @@ -6,7 +6,8 @@ from collections import Counter - from sklearn.metrics import roc_auc_score - from sklearn.metrics import f1_score, classification_report - --__call__ = ['Accuracy','AUC','F1Score','EntityScore','ClassReport','MultiLabelReport','AccuracyThresh'] -+__call__ = ['Accuracy', 'AUC', 'F1Score', 'EntityScore', 'ClassReport', 'MultiLabelReport', 'AccuracyThresh'] -+ - - class Metric: - def __init__(self): + from sklearn.metrics import roc_auc_score + from sklearn.metrics import f1_score, classification_report + +-__call__ = ['Accuracy','AUC','F1Score','EntityScore','ClassReport','MultiLabelReport','AccuracyThresh'] ++__call__ = ['Accuracy', 'AUC', 'F1Score', 'EntityScore', 'ClassReport', 'MultiLabelReport', 'AccuracyThresh'] ++ + + class Metric: + def __init__(self): @@ -24,6 +25,7 @@ class Metric: - def name(self): - raise NotImplementedError - -+ - class Accuracy(Metric): - ''' - 计算准确度 + def name(self): + raise NotImplementedError + ++ + class Accuracy(Metric): + ''' + 计算准确度 @@ -37,8 +39,9 @@ class Accuracy(Metric): - >>> metrics(logits,target) - >>> print(metrics.name(),metrics.value()) - ''' -- def __init__(self,topK): -- super(Accuracy,self).__init__() -+ -+ def __init__(self, topK): -+ super(Accuracy, self).__init__() - self.topK = topK - self.reset() - + >>> metrics(logits,target) + >>> print(metrics.name(),metrics.value()) + ''' +- def __init__(self,topK): +- super(Accuracy,self).__init__() ++ ++ def __init__(self, topK): ++ super(Accuracy, self).__init__() + self.topK = topK + self.reset() + @@ -54,7 +57,7 @@ class Accuracy(Metric): - self.total = 0 - - def value(self): -- return float(self.correct_k) / self.total -+ return float(self.correct_k) / self.total - - def name(self): - return 'accuracy' + self.total = 0 + + def value(self): +- return float(self.correct_k) / self.total ++ return float(self.correct_k) / self.total + + def name(self): + return 'accuracy' @@ -73,8 +76,9 @@ class AccuracyThresh(Metric): - >>> metrics(logits,target) - >>> print(metrics.name(),metrics.value()) - ''' -- def __init__(self,thresh = 0.5): -- super(AccuracyThresh,self).__init__() -+ -+ def __init__(self, thresh=0.5): -+ super(AccuracyThresh, self).__init__() - self.thresh = thresh - self.reset() - + >>> metrics(logits,target) + >>> print(metrics.name(),metrics.value()) + ''' +- def __init__(self,thresh = 0.5): +- super(AccuracyThresh,self).__init__() ++ ++ def __init__(self, thresh=0.5): ++ super(AccuracyThresh, self).__init__() + self.thresh = thresh + self.reset() + @@ -88,7 +92,7 @@ class AccuracyThresh(Metric): - - def value(self): - data_size = self.y_pred.size(0) -- acc = np.mean(((self.y_pred>self.thresh)==self.y_true.byte()).float().cpu().numpy(), axis=1).sum() -+ acc = np.mean(((self.y_pred > self.thresh) == self.y_true.byte()).float().cpu().numpy(), axis=1).sum() - return acc / data_size - - def name(self): + + def value(self): + data_size = self.y_pred.size(0) +- acc = np.mean(((self.y_pred>self.thresh)==self.y_true.byte()).float().cpu().numpy(), axis=1).sum() ++ acc = np.mean(((self.y_pred > self.thresh) == self.y_true.byte()).float().cpu().numpy(), axis=1).sum() + return acc / data_size + + def name(self): @@ -119,16 +123,16 @@ class AUC(Metric): - >>> print(metrics.name(),metrics.value()) - ''' - -- def __init__(self,task_type = 'binary',average = 'binary'): -+ def __init__(self, task_type='binary', average='binary'): - super(AUC, self).__init__() - -- assert task_type in ['binary','multiclass'] -- assert average in ['binary','micro', 'macro', 'samples', 'weighted'] -+ assert task_type in ['binary', 'multiclass'] -+ assert average in ['binary', 'micro', 'macro', 'samples', 'weighted'] - - self.task_type = task_type - self.average = average - -- def __call__(self,logits,target): -+ def __call__(self, logits, target): - ''' - 计算整个结果 - ''' + >>> print(metrics.name(),metrics.value()) + ''' + +- def __init__(self,task_type = 'binary',average = 'binary'): ++ def __init__(self, task_type='binary', average='binary'): + super(AUC, self).__init__() + +- assert task_type in ['binary','multiclass'] +- assert average in ['binary','micro', 'macro', 'samples', 'weighted'] ++ assert task_type in ['binary', 'multiclass'] ++ assert average in ['binary', 'micro', 'macro', 'samples', 'weighted'] + + self.task_type = task_type + self.average = average + +- def __call__(self,logits,target): ++ def __call__(self, logits, target): + ''' + 计算整个结果 + ''' @@ -152,6 +156,7 @@ class AUC(Metric): - def name(self): - return 'auc' - -+ - class F1Score(Metric): - ''' - F1 Score + def name(self): + return 'auc' + ++ + class F1Score(Metric): + ''' + F1 Score @@ -178,18 +183,19 @@ class F1Score(Metric): - >>> metrics(logits,target) - >>> print(metrics.name(),metrics.value()) - ''' -- def __init__(self,thresh = 0.5, normalizate = True,task_type = 'binary',average = 'binary',search_thresh = False): -+ -+ def __init__(self, thresh=0.5, normalizate=True, task_type='binary', average='binary', search_thresh=False): - super(F1Score).__init__() -- assert task_type in ['binary','multiclass'] -- assert average in ['binary','micro', 'macro', 'samples', 'weighted'] -+ assert task_type in ['binary', 'multiclass'] -+ assert average in ['binary', 'micro', 'macro', 'samples', 'weighted'] - - self.thresh = thresh - self.task_type = task_type -- self.normalizate = normalizate -+ self.normalizate = normalizate - self.search_thresh = search_thresh - self.average = average - -- def thresh_search(self,y_prob): -+ def thresh_search(self, y_prob): - ''' - 对于f1评分的指标,一般我们需要对阈值进行调整,一般不会使用默认的0.5值,因此 - 这里我们队Thresh进行优化 + >>> metrics(logits,target) + >>> print(metrics.name(),metrics.value()) + ''' +- def __init__(self,thresh = 0.5, normalizate = True,task_type = 'binary',average = 'binary',search_thresh = False): ++ ++ def __init__(self, thresh=0.5, normalizate=True, task_type='binary', average='binary', search_thresh=False): + super(F1Score).__init__() +- assert task_type in ['binary','multiclass'] +- assert average in ['binary','micro', 'macro', 'samples', 'weighted'] ++ assert task_type in ['binary', 'multiclass'] ++ assert average in ['binary', 'micro', 'macro', 'samples', 'weighted'] + + self.thresh = thresh + self.task_type = task_type +- self.normalizate = normalizate ++ self.normalizate = normalizate + self.search_thresh = search_thresh + self.average = average + +- def thresh_search(self,y_prob): ++ def thresh_search(self, y_prob): + ''' + 对于f1评分的指标,一般我们需要对阈值进行调整,一般不会使用默认的0.5值,因此 + 这里我们队Thresh进行优化 @@ -203,9 +209,9 @@ class F1Score(Metric): - if score > best_score: - best_threshold = threshold - best_score = score -- return best_threshold,best_score -+ return best_threshold, best_score - -- def __call__(self,logits,target): -+ def __call__(self, logits, target): - ''' - 计算整个结果 - :return: + if score > best_score: + best_threshold = threshold + best_score = score +- return best_threshold,best_score ++ return best_threshold, best_score + +- def __call__(self,logits,target): ++ def __call__(self, logits, target): + ''' + 计算整个结果 + :return: @@ -220,10 +226,10 @@ class F1Score(Metric): - - if self.task_type == 'binary': - if self.thresh and self.search_thresh == False: -- self.y_pred = (y_prob > self.thresh ).astype(int) -+ self.y_pred = (y_prob > self.thresh).astype(int) - self.value() - else: -- thresh,f1 = self.thresh_search(y_prob = y_prob) -+ thresh, f1 = self.thresh_search(y_prob=y_prob) - print(f"Best thresh: {thresh:.4f} - F1 Score: {f1:.4f}") - - if self.task_type == 'multiclass': + + if self.task_type == 'binary': + if self.thresh and self.search_thresh == False: +- self.y_pred = (y_prob > self.thresh ).astype(int) ++ self.y_pred = (y_prob > self.thresh).astype(int) + self.value() + else: +- thresh,f1 = self.thresh_search(y_prob = y_prob) ++ thresh, f1 = self.thresh_search(y_prob=y_prob) + print(f"Best thresh: {thresh:.4f} - F1 Score: {f1:.4f}") + + if self.task_type == 'multiclass': @@ -247,11 +253,13 @@ class F1Score(Metric): - def name(self): - return 'f1' - -+ - class ClassReport(Metric): - ''' - class report - ''' -- def __init__(self,target_names = None): -+ -+ def __init__(self, target_names=None): - super(ClassReport).__init__() - self.target_names = target_names - + def name(self): + return 'f1' + ++ + class ClassReport(Metric): + ''' + class report + ''' +- def __init__(self,target_names = None): ++ ++ def __init__(self, target_names=None): + super(ClassReport).__init__() + self.target_names = target_names + @@ -263,10 +271,10 @@ class ClassReport(Metric): - ''' - 计算指标得分 - ''' -- score = classification_report(y_true = self.y_true, y_pred = self.y_pred, target_names=self.target_names) -+ score = classification_report(y_true=self.y_true, y_pred=self.y_pred, target_names=self.target_names) - print(f"\n\n classification report: {score}") - -- def __call__(self,logits,target): -+ def __call__(self, logits, target): - _, y_pred = torch.max(logits.data, 1) - self.y_pred = y_pred.cpu().numpy() - self.y_true = target.cpu().numpy() + ''' + 计算指标得分 + ''' +- score = classification_report(y_true = self.y_true, y_pred = self.y_pred, target_names=self.target_names) ++ score = classification_report(y_true=self.y_true, y_pred=self.y_pred, target_names=self.target_names) + print(f"\n\n classification report: {score}") + +- def __call__(self,logits,target): ++ def __call__(self, logits, target): + _, y_pred = torch.max(logits.data, 1) + self.y_pred = y_pred.cpu().numpy() + self.y_true = target.cpu().numpy() @@ -274,11 +282,13 @@ class ClassReport(Metric): - def name(self): - return "class_report" - -+ - class MultiLabelReport(Metric): - ''' - multi label report - ''' -- def __init__(self,id2label = None): -+ -+ def __init__(self, id2label=None): - super(MultiLabelReport).__init__() - self.id2label = id2label - + def name(self): + return "class_report" + ++ + class MultiLabelReport(Metric): + ''' + multi label report + ''' +- def __init__(self,id2label = None): ++ ++ def __init__(self, id2label=None): + super(MultiLabelReport).__init__() + self.id2label = id2label + @@ -286,8 +296,7 @@ class MultiLabelReport(Metric): - self.y_prob = 0 - self.y_true = 0 - -- def __call__(self,logits,target): -- -+ def __call__(self, logits, target): - self.y_prob = logits.sigmoid().data.cpu().detach().numpy() - self.y_true = target.cpu().numpy() - + self.y_prob = 0 + self.y_true = 0 + +- def __call__(self,logits,target): +- ++ def __call__(self, logits, target): + self.y_prob = logits.sigmoid().data.cpu().detach().numpy() + self.y_true = target.cpu().numpy() + @@ -304,12 +313,12 @@ class MultiLabelReport(Metric): - - - class LMAccuracy(Metric): -- def __init__(self,topK =1): -+ def __init__(self, topK=1): - super(LMAccuracy).__init__() - self.topK = topK - self.reset() - -- def __call__(self,logits,target): -+ def __call__(self, logits, target): - pred = torch.argmax(logits, 1) - active_acc = target.view(-1) != -1 - active_pred = pred[active_acc] + + + class LMAccuracy(Metric): +- def __init__(self,topK =1): ++ def __init__(self, topK=1): + super(LMAccuracy).__init__() + self.topK = topK + self.reset() + +- def __call__(self,logits,target): ++ def __call__(self, logits, target): + pred = torch.argmax(logits, 1) + active_acc = target.view(-1) != -1 + active_pred = pred[active_acc] @@ -328,5 +337,3 @@ class LMAccuracy(Metric): - - def name(self): - return 'accuracy' -- -- + + def name(self): + return 'accuracy' +- +- diff --git a/metrics/glue_compute_metrics.py b/metrics/glue_compute_metrics.py index dd9a7b2..7afb658 100644 --- a/metrics/glue_compute_metrics.py +++ b/metrics/glue_compute_metrics.py @@ -22,11 +22,13 @@ logger = logging.getLogger(__name__) - try: - from scipy.stats import pearsonr, spearmanr - from sklearn.metrics import matthews_corrcoef, f1_score -+ - _has_sklearn = True - except (AttributeError, ImportError) as e: - logger.warning("To use data.metrics please install scikit-learn. See https://scikit-learn.org/stable/index.html") - _has_sklearn = False - -+ - def simple_accuracy(preds, labels): - return (preds == labels).mean() - + try: + from scipy.stats import pearsonr, spearmanr + from sklearn.metrics import matthews_corrcoef, f1_score ++ + _has_sklearn = True + except (AttributeError, ImportError) as e: + logger.warning("To use data.metrics please install scikit-learn. See https://scikit-learn.org/stable/index.html") + _has_sklearn = False + ++ + def simple_accuracy(preds, labels): + return (preds == labels).mean() + @@ -40,6 +42,7 @@ def acc_and_f1(preds, labels): - "acc_and_f1": (acc + f1) / 2, - } - -+ - def pearson_and_spearman(preds, labels): - pearson_corr = pearsonr(preds, labels)[0] - spearman_corr = spearmanr(preds, labels)[0] + "acc_and_f1": (acc + f1) / 2, + } + ++ + def pearson_and_spearman(preds, labels): + pearson_corr = pearsonr(preds, labels)[0] + spearman_corr = spearmanr(preds, labels)[0] @@ -49,6 +52,7 @@ def pearson_and_spearman(preds, labels): - "corr": (pearson_corr + spearman_corr) / 2, - } - -+ - def compute_metrics(task_name, preds, labels): - assert len(preds) == len(labels) - if task_name == "cola": + "corr": (pearson_corr + spearman_corr) / 2, + } + ++ + def compute_metrics(task_name, preds, labels): + assert len(preds) == len(labels) + if task_name == "cola": diff --git a/model/configuration_albert.py b/model/configuration_albert.py index d8c8310..4968acb 100644 --- a/model/configuration_albert.py @@ -1182,127 +1182,127 @@ index 433db06..7c8dc1f 100644 --- a/model/modeling_albert_bright.py +++ b/model/modeling_albert_bright.py @@ -25,6 +25,8 @@ ALBERT_PRETRAINED_MODEL_ARCHIVE_MAP = { - 'albert-xlarge': "", - 'albert-xxlarge': "", - } -+ -+ - def load_tf_weights_in_albert(model, config, tf_checkpoint_path): - """ Load tf checkpoints in a pytorch model. - """ + 'albert-xlarge': "", + 'albert-xxlarge': "", + } ++ ++ + def load_tf_weights_in_albert(model, config, tf_checkpoint_path): + """ Load tf checkpoints in a pytorch model. + """ @@ -93,10 +95,14 @@ def load_tf_weights_in_albert(model, config, tf_checkpoint_path): - pointer.data = torch.from_numpy(array) - return model - -+ - AlbertLayerNorm = torch.nn.LayerNorm -+ -+ - class AlbertEmbeddings(nn.Module): - """Construct the embeddings from word, position and token_type embeddings. - """ -+ - def __init__(self, config): - super(AlbertEmbeddings, self).__init__() - self.word_embeddings = nn.Embedding(config.vocab_size, config.embedding_size, padding_idx=0) + pointer.data = torch.from_numpy(array) + return model + ++ + AlbertLayerNorm = torch.nn.LayerNorm ++ ++ + class AlbertEmbeddings(nn.Module): + """Construct the embeddings from word, position and token_type embeddings. + """ ++ + def __init__(self, config): + super(AlbertEmbeddings, self).__init__() + self.word_embeddings = nn.Embedding(config.vocab_size, config.embedding_size, padding_idx=0) @@ -108,7 +114,7 @@ class AlbertEmbeddings(nn.Module): - - # self.LayerNorm is not snake-cased to stick with TensorFlow model variable name and be able to load - # any TensorFlow checkpoint file -- self.LayerNorm =AlbertLayerNorm(config.hidden_size, eps=config.layer_norm_eps) -+ self.LayerNorm = AlbertLayerNorm(config.hidden_size, eps=config.layer_norm_eps) - self.dropout = nn.Dropout(config.hidden_dropout_prob) - - def forward(self, input_ids, token_type_ids=None, position_ids=None): + + # self.LayerNorm is not snake-cased to stick with TensorFlow model variable name and be able to load + # any TensorFlow checkpoint file +- self.LayerNorm =AlbertLayerNorm(config.hidden_size, eps=config.layer_norm_eps) ++ self.LayerNorm = AlbertLayerNorm(config.hidden_size, eps=config.layer_norm_eps) + self.dropout = nn.Dropout(config.hidden_dropout_prob) + + def forward(self, input_ids, token_type_ids=None, position_ids=None): @@ -130,6 +136,7 @@ class AlbertEmbeddings(nn.Module): - embeddings = self.dropout(embeddings) - return embeddings - -+ - class AlbertSelfOutput(nn.Module): - def __init__(self, config): - super(AlbertSelfOutput, self).__init__() + embeddings = self.dropout(embeddings) + return embeddings + ++ + class AlbertSelfOutput(nn.Module): + def __init__(self, config): + super(AlbertSelfOutput, self).__init__() @@ -182,6 +189,7 @@ class AlbertAttention(nn.Module): - outputs = (attention_output,) + self_outputs[1:] # add attentions if we output them - return outputs - -+ - class AlbertOutput(nn.Module): - def __init__(self, config): - super(AlbertOutput, self).__init__() + outputs = (attention_output,) + self_outputs[1:] # add attentions if we output them + return outputs + ++ + class AlbertOutput(nn.Module): + def __init__(self, config): + super(AlbertOutput, self).__init__() @@ -196,6 +204,7 @@ class AlbertOutput(nn.Module): - hidden_states = self.LayerNorm(hidden_states + input_tensor) - return hidden_states - -+ - class BertLayer(nn.Module): - def __init__(self, config): - super(BertLayer, self).__init__() + hidden_states = self.LayerNorm(hidden_states + input_tensor) + return hidden_states + ++ + class BertLayer(nn.Module): + def __init__(self, config): + super(BertLayer, self).__init__() @@ -213,6 +222,7 @@ class BertLayer(nn.Module): - outputs = (layer_output,) + attention_outputs[1:] # add attentions if we output them - return outputs - -+ - class AlbertEncoder(nn.Module): - def __init__(self, config): - super(AlbertEncoder, self).__init__() + outputs = (layer_output,) + attention_outputs[1:] # add attentions if we output them + return outputs + ++ + class AlbertEncoder(nn.Module): + def __init__(self, config): + super(AlbertEncoder, self).__init__() @@ -243,6 +253,7 @@ class AlbertEncoder(nn.Module): - outputs = outputs + (all_attentions,) - return outputs # last-layer hidden state, (all hidden states), (all attentions) - -+ - class AlbertLMPredictionHead(nn.Module): - def __init__(self, config): - super(AlbertLMPredictionHead, self).__init__() + outputs = outputs + (all_attentions,) + return outputs # last-layer hidden state, (all hidden states), (all attentions) + ++ + class AlbertLMPredictionHead(nn.Module): + def __init__(self, config): + super(AlbertLMPredictionHead, self).__init__() @@ -261,6 +272,7 @@ class AlbertLMPredictionHead(nn.Module): - hidden_states = self.decoder(hidden_states) + self.bias - return hidden_states - -+ - class AlbertOnlyMLMHead(nn.Module): - def __init__(self, config): - super(AlbertOnlyMLMHead, self).__init__() + hidden_states = self.decoder(hidden_states) + self.bias + return hidden_states + ++ + class AlbertOnlyMLMHead(nn.Module): + def __init__(self, config): + super(AlbertOnlyMLMHead, self).__init__() @@ -270,6 +282,7 @@ class AlbertOnlyMLMHead(nn.Module): - prediction_scores = self.predictions(sequence_output) - return prediction_scores - -+ - class AlbertOnlyNSPHead(nn.Module): - def __init__(self, config): - super(AlbertOnlyNSPHead, self).__init__() + prediction_scores = self.predictions(sequence_output) + return prediction_scores + ++ + class AlbertOnlyNSPHead(nn.Module): + def __init__(self, config): + super(AlbertOnlyNSPHead, self).__init__() @@ -279,6 +292,7 @@ class AlbertOnlyNSPHead(nn.Module): - seq_relationship_score = self.seq_relationship(pooled_output) - return seq_relationship_score - -+ - class AlbertPreTrainingHeads(nn.Module): - def __init__(self, config): - super(AlbertPreTrainingHeads, self).__init__() + seq_relationship_score = self.seq_relationship(pooled_output) + return seq_relationship_score + ++ + class AlbertPreTrainingHeads(nn.Module): + def __init__(self, config): + super(AlbertPreTrainingHeads, self).__init__() @@ -290,6 +304,7 @@ class AlbertPreTrainingHeads(nn.Module): - seq_relationship_score = self.seq_relationship(pooled_output) - return prediction_scores, seq_relationship_score - -+ - class AlbertPreTrainedModel(PreTrainedModel): - """ An abstract class to handle weights initialization and - a simple interface for dowloading and loading pretrained models. + seq_relationship_score = self.seq_relationship(pooled_output) + return prediction_scores, seq_relationship_score + ++ + class AlbertPreTrainedModel(PreTrainedModel): + """ An abstract class to handle weights initialization and + a simple interface for dowloading and loading pretrained models. @@ -311,6 +326,7 @@ class AlbertPreTrainedModel(PreTrainedModel): - if isinstance(module, nn.Linear) and module.bias is not None: - module.bias.data.zero_() - -+ - BERT_START_DOCSTRING = r""" The BERT model was proposed in - `BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding`_ - by Jacob Devlin, Ming-Wei Chang, Kenton Lee and Kristina Toutanova. It's a bidirectional transformer + if isinstance(module, nn.Linear) and module.bias is not None: + module.bias.data.zero_() + ++ + BERT_START_DOCSTRING = r""" The BERT model was proposed in + `BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding`_ + by Jacob Devlin, Ming-Wei Chang, Kenton Lee and Kristina Toutanova. It's a bidirectional transformer @@ -535,7 +551,7 @@ class AlbertForPreTraining(AlbertPreTrainedModel): - Export to TorchScript can't handle parameter sharing so we are cloning them instead. - """ - self._tie_or_clone_weights(self.cls.predictions.decoder, -- self.bert.embeddings.word_embeddings) -+ self.bert.embeddings.word_embeddings) - - def forward(self, input_ids, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, - masked_lm_labels=None, next_sentence_label=None): + Export to TorchScript can't handle parameter sharing so we are cloning them instead. + """ + self._tie_or_clone_weights(self.cls.predictions.decoder, +- self.bert.embeddings.word_embeddings) ++ self.bert.embeddings.word_embeddings) + + def forward(self, input_ids, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, + masked_lm_labels=None, next_sentence_label=None): diff --git a/model/modeling_bert.py b/model/modeling_bert.py index fecf1e4..1b593c6 100644 --- a/model/modeling_bert.py @@ -2886,164 +2886,164 @@ index bd4cd9f..ec8e30f 100644 --- a/tools/common.py +++ b/tools/common.py @@ -8,16 +8,19 @@ import torch.nn as nn - from collections import OrderedDict - from pathlib import Path - import logging -+from threading import Lock - -+lock = Lock() - logger = logging.getLogger() - -+ - def init_logger(log_file=None, log_file_level=logging.NOTSET): - ''' - Example: - >>> init_logger(log_file) - >>> logger.info("abc'") - ''' -- if isinstance(log_file,Path): -+ if isinstance(log_file, Path): - log_file = str(log_file) - - log_format = logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(name)s - %(message)s', + from collections import OrderedDict + from pathlib import Path + import logging ++from threading import Lock + ++lock = Lock() + logger = logging.getLogger() + ++ + def init_logger(log_file=None, log_file_level=logging.NOTSET): + ''' + Example: + >>> init_logger(log_file) + >>> logger.info("abc'") + ''' +- if isinstance(log_file,Path): ++ if isinstance(log_file, Path): + log_file = str(log_file) + + log_format = logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(name)s - %(message)s', @@ -34,6 +37,7 @@ def init_logger(log_file=None, log_file_level=logging.NOTSET): - logger.addHandler(file_handler) - return logger - -+ - def seed_everything(seed=1029): - ''' - 设置整个开发环境的seed + logger.addHandler(file_handler) + return logger + ++ + def seed_everything(seed=1029): + ''' + 设置整个开发环境的seed @@ -114,7 +118,7 @@ def restore_checkpoint(resume_path, model=None): - model.module.load_state_dict(states) - else: - model.load_state_dict(states) -- return [model,best,start_epoch] -+ return [model, best, start_epoch] - - - def save_pickle(data, file_path): + model.module.load_state_dict(states) + else: + model.load_state_dict(states) +- return [model,best,start_epoch] ++ return [model, best, start_epoch] + + + def save_pickle(data, file_path): @@ -172,6 +176,7 @@ def load_json(file_path): - data = json.load(f) - return data - -+ - def save_model(model, model_path): - """ 存储不含有显卡信息的state_dict或model - :param model: + data = json.load(f) + return data + ++ + def save_model(model, model_path): + """ 存储不含有显卡信息的state_dict或model + :param model: @@ -188,6 +193,7 @@ def save_model(model, model_path): - state_dict[key] = state_dict[key].cpu() - torch.save(state_dict, model_path) - -+ - def load_model(model, model_path): - ''' - 加载模型 + state_dict[key] = state_dict[key].cpu() + torch.save(state_dict, model_path) + ++ + def load_model(model, model_path): + ''' + 加载模型 diff --git a/tools/fps_counter.py b/tools/fps_counter.py new file mode 100644 index 0000000..4f637f3 --- /dev/null +++ b/tools/fps_counter.py @@ -0,0 +1,99 @@ -+# Copyright 2021 Huawei Technologies Co., Ltd -+# -+# Licensed under the Apache License, Version 2.0 (the "License"); -+# you may not use this file except in compliance with the License. -+# You may obtain a copy of the License at -+# -+# http://www.apache.org/licenses/LICENSE-2.0 -+# -+# Unless required by applicable law or agreed to in writing, software -+# distributed under the License is distributed on an "AS IS" BASIS, -+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+# See the License for the specific language governing permissions and -+# limitations under the License. -+ -+import time -+from threading import Lock -+ -+ -+class FpsCounter: -+ """ -+how to use -+ -+fps=FpsCounter() -+fps.begin() -+code -+fps.end() -+print(fps.fps()) -+ -+ """ -+ def __init__(self): -+ self.step_sum = 0 -+ self.time_sum = 0 -+ self.t1 = 0 -+ self.on = False -+ -+ def begin(self): -+ assert self.on == False, "didnot end last time" -+ self.on = True -+ self.t1 = time.time_ns() -+ -+ def end(self): -+ t2 = time.time_ns() -+ assert self.on == True, "didnot begin" -+ self.time_sum += t2 - self.t1 -+ self.step_sum += 1 -+ self.on = False -+ -+ def reset(self): -+ self.step_sum = 0 -+ self.time_sum = 0 -+ self.t1 = 0 -+ self.on = False -+ -+ def fps(self, batch=1, n_device=1): -+ if self.step_sum == 0: return 0 -+ time_avg = self.time_sum / 1e9 / self.step_sum -+ return batch * n_device / time_avg -+ -+ -+class FpsCounter2: -+ def __init__(self, node_num=0): -+ self.node_num = node_num -+ self.lock = Lock() -+ self.step_sum = [0 for i in range(node_num)] -+ self.time_sum = [0 for i in range(node_num)] -+ self.t1 = [0 for i in range(node_num)] -+ self.on = [False for i in range(node_num)] -+ -+ def begin(self, node_idx=0): -+ assert self.on[node_idx] == False, "didnot end last time" -+ self.lock.acquire() -+ self.on[node_idx] = True -+ self.t1[node_idx] = time.time_ns() -+ self.lock.release() -+ -+ def end(self, node_idx=0): -+ t2 = time.time_ns() -+ assert self.on[node_idx] == True, "didnot begin" -+ self.lock.acquire() -+ self.time_sum[node_idx] += t2 - self.t1[node_idx] -+ self.step_sum[node_idx] += 1 -+ self.on[node_idx] = False -+ self.lock.release() -+ -+ def reset(self, node_idx=0): -+ self.lock.acquire() -+ self.step_sum[node_idx] = 0 -+ self.time_sum[node_idx] = 0 -+ self.t1[node_idx] = 0 -+ self.on[node_idx] = False -+ self.lock.release() -+ -+ def fps(self, batch=1, n_device=1, world_size=0): -+ fps = 0 -+ for i in range(world_size): -+ if self.step_sum[i] == 0: continue -+ time_avg = self.time_sum[i] / 1e9 / self.step_sum[i] -+ fps += batch * n_device / time_avg -+ return fps ++# Copyright 2021 Huawei Technologies Co., Ltd ++# ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++ ++import time ++from threading import Lock ++ ++ ++class FpsCounter: ++ """ ++how to use ++ ++fps=FpsCounter() ++fps.begin() ++code ++fps.end() ++print(fps.fps()) ++ ++ """ ++ def __init__(self): ++ self.step_sum = 0 ++ self.time_sum = 0 ++ self.t1 = 0 ++ self.on = False ++ ++ def begin(self): ++ assert self.on == False, "didnot end last time" ++ self.on = True ++ self.t1 = time.time_ns() ++ ++ def end(self): ++ t2 = time.time_ns() ++ assert self.on == True, "didnot begin" ++ self.time_sum += t2 - self.t1 ++ self.step_sum += 1 ++ self.on = False ++ ++ def reset(self): ++ self.step_sum = 0 ++ self.time_sum = 0 ++ self.t1 = 0 ++ self.on = False ++ ++ def fps(self, batch=1, n_device=1): ++ if self.step_sum == 0: return 0 ++ time_avg = self.time_sum / 1e9 / self.step_sum ++ return batch * n_device / time_avg ++ ++ ++class FpsCounter2: ++ def __init__(self, node_num=0): ++ self.node_num = node_num ++ self.lock = Lock() ++ self.step_sum = [0 for i in range(node_num)] ++ self.time_sum = [0 for i in range(node_num)] ++ self.t1 = [0 for i in range(node_num)] ++ self.on = [False for i in range(node_num)] ++ ++ def begin(self, node_idx=0): ++ assert self.on[node_idx] == False, "didnot end last time" ++ self.lock.acquire() ++ self.on[node_idx] = True ++ self.t1[node_idx] = time.time_ns() ++ self.lock.release() ++ ++ def end(self, node_idx=0): ++ t2 = time.time_ns() ++ assert self.on[node_idx] == True, "didnot begin" ++ self.lock.acquire() ++ self.time_sum[node_idx] += t2 - self.t1[node_idx] ++ self.step_sum[node_idx] += 1 ++ self.on[node_idx] = False ++ self.lock.release() ++ ++ def reset(self, node_idx=0): ++ self.lock.acquire() ++ self.step_sum[node_idx] = 0 ++ self.time_sum[node_idx] = 0 ++ self.t1[node_idx] = 0 ++ self.on[node_idx] = False ++ self.lock.release() ++ ++ def fps(self, batch=1, n_device=1, world_size=0): ++ fps = 0 ++ for i in range(world_size): ++ if self.step_sum[i] == 0: continue ++ time_avg = self.time_sum[i] / 1e9 / self.step_sum[i] ++ fps += batch * n_device / time_avg ++ return fps -- 2.17.1 diff --git a/ACL_PyTorch/contrib/nlp/tinybert/TinyBERT_get_info.py b/ACL_PyTorch/contrib/nlp/tinybert/TinyBERT_get_info.py index c685f28e3bfa56a01dabf53ad38c4d70d8c03d66..0846eb47f46672291c43d5217878b48cfbe42058 100644 --- a/ACL_PyTorch/contrib/nlp/tinybert/TinyBERT_get_info.py +++ b/ACL_PyTorch/contrib/nlp/tinybert/TinyBERT_get_info.py @@ -1,47 +1,47 @@ -# coding=utf-8 -# Copyright (c) 2019 NVIDIA CORPORATION. All rights reserved. -# Copyright 2018 The Google AI Language Team Authors and The HugginFace Inc. team. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Run TinyBERT on SST-2.""" -import argparse - -def main(): - """output:info file""" - parser = argparse.ArgumentParser() - parser.add_argument("--batch_size", - default=1, - type=int, - required=True) - parser.add_argument("--output_path", - default='./bert_bin/', - type=str, - required=True, - help='The output dir of info file.') - args = parser.parse_args() - test_num = 872 - base_path = args.output_path - with open('./TinyBERT.info', 'w') as f: - for i in range(test_num): - ids_name = base_path + 'input_ids_{}.bin'.format(i) - segment_name = base_path + 'segment_ids_{}.bin'.format(i) - mask_name = base_path + 'input_mask_{}.bin'.format(i) - f.write(str(i) + ' ' + ids_name) - f.write('\n') - f.write(str(i) + ' ' + segment_name) - f.write('\n') - f.write(str(i) + ' ' + mask_name) - f.write('\n') - -if __name__ == "__main__": +# coding=utf-8 +# Copyright (c) 2019 NVIDIA CORPORATION. All rights reserved. +# Copyright 2018 The Google AI Language Team Authors and The HugginFace Inc. team. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Run TinyBERT on SST-2.""" +import argparse + +def main(): + """output:info file""" + parser = argparse.ArgumentParser() + parser.add_argument("--batch_size", + default=1, + type=int, + required=True) + parser.add_argument("--output_path", + default='./bert_bin/', + type=str, + required=True, + help='The output dir of info file.') + args = parser.parse_args() + test_num = 872 + base_path = args.output_path + with open('./TinyBERT.info', 'w') as f: + for i in range(test_num): + ids_name = base_path + 'input_ids_{}.bin'.format(i) + segment_name = base_path + 'segment_ids_{}.bin'.format(i) + mask_name = base_path + 'input_mask_{}.bin'.format(i) + f.write(str(i) + ' ' + ids_name) + f.write('\n') + f.write(str(i) + ' ' + segment_name) + f.write('\n') + f.write(str(i) + ' ' + mask_name) + f.write('\n') + +if __name__ == "__main__": main() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/nlp/tinybert/TinyBERT_postprocess_data.py b/ACL_PyTorch/contrib/nlp/tinybert/TinyBERT_postprocess_data.py index 117bb7ea24ede7f1353e849cc5ab7b2397cf5ad5..bff0fbfbc86b4d9fc675928f5e439877152344f3 100644 --- a/ACL_PyTorch/contrib/nlp/tinybert/TinyBERT_postprocess_data.py +++ b/ACL_PyTorch/contrib/nlp/tinybert/TinyBERT_postprocess_data.py @@ -1,279 +1,279 @@ -# coding=utf-8 -# Copyright (c) 2019 NVIDIA CORPORATION. All rights reserved. -# Copyright 2018 The Google AI Language Team Authors and The HugginFace Inc. team. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Run TinyBERT on SST-2.""" - -from __future__ import absolute_import, division, print_function -import argparse -import os -import sys -import csv -import numpy as np -import io -from transformer.tokenization import BertTokenizer -import torch - - -class InputExample(object): - """A single training/test example for simple sequence classification.""" - - def __init__(self, guid, text_a, text_b=None, label=None): - """Constructs a InputExample. - - Args: - guid: Unique id for the example. - text_a: string. The untokenized text of the first sequence. For single - sequence tasks, only this sequence must be specified. - text_b: (Optional) string. The untokenized text of the second sequence. - Only must be specified for sequence pair tasks. - label: (Optional) string. The label of the example. This should be - specified for train and dev examples, but not for test examples. - """ - self.guid = guid - self.text_a = text_a - self.text_b = text_b - self.label = label - - -class InputFeatures(object): - """A single set of features of data.""" - - def __init__(self, input_ids, input_mask, segment_ids, label_id, seq_length=None): - self.input_ids = input_ids - self.input_mask = input_mask - self.segment_ids = segment_ids - self.seq_length = seq_length - self.label_id = label_id - - -class DataProcessor(object): - """Base class for data converters for sequence classification data sets.""" - - def get_train_examples(self, data_dir): - """Gets a collection of `InputExample`s for the train set.""" - raise NotImplementedError() - - def get_dev_examples(self, data_dir): - """Gets a collection of `InputExample`s for the dev set.""" - raise NotImplementedError() - - def get_labels(self): - """Gets the list of labels for this data set.""" - raise NotImplementedError() - - @classmethod - def _read_tsv(cls, input_file, quotechar=None): - """Reads a tab separated value file.""" - with io.open(input_file, "r", encoding="utf-8") as f: - reader = csv.reader(f, delimiter="\t", quotechar=quotechar) - lines = [] - for line in reader: - if sys.version_info[0] == 2: - line = list(unicode(cell, 'utf-8') for cell in line) - lines.append(line) - return lines - - -class Sst2Processor(DataProcessor): - """Processor for the SST-2 data set (GLUE version).""" - - def get_train_examples(self, data_dir): - """See base class.""" - return self._create_examples( - self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") - - def get_dev_examples(self, data_dir): - """See base class.""" - return self._create_examples( - self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev") - - def get_aug_examples(self, data_dir): - """get the augmented examples""" - return self._create_examples( - self._read_tsv(os.path.join(data_dir, "train_aug.tsv")), "aug") - - def get_labels(self): - """See base class.""" - return ["0", "1"] - - def _create_examples(self, lines, set_type): - """Creates examples for the training and dev sets.""" - examples = [] - for (i, line) in enumerate(lines): - if i == 0: - continue - guid = "%s-%s" % (set_type, i) - text_a = line[0] - label = line[1] - examples.append( - InputExample(guid=guid, text_a=text_a, text_b=None, label=label)) - return examples - - -def _truncate_seq_pair(tokens_a, tokens_b, max_length): - """Truncates a sequence pair in place to the maximum length.""" - while True: - total_length = len(tokens_a) + len(tokens_b) - if total_length <= max_length: - break - if len(tokens_a) > len(tokens_b): - tokens_a.pop() - else: - tokens_b.pop() - - -def convert_examples_to_features(examples, label_list, max_seq_length, - tokenizer, output_mode): - """Loads a data file into a list of `InputBatch`s.""" - - label_map = {label: i for i, label in enumerate(label_list)} - - features = [] - for (ex_index, example) in enumerate(examples): - - tokens_a = tokenizer.tokenize(example.text_a) - - tokens_b = None - if example.text_b: - tokens_b = tokenizer.tokenize(example.text_b) - _truncate_seq_pair(tokens_a, tokens_b, max_seq_length - 3) - else: - if len(tokens_a) > max_seq_length - 2: - tokens_a = tokens_a[:(max_seq_length - 2)] - - tokens = ["[CLS]"] + tokens_a + ["[SEP]"] - segment_ids = [0] * len(tokens) - - if tokens_b: - tokens += tokens_b + ["[SEP]"] - segment_ids += [1] * (len(tokens_b) + 1) - - input_ids = tokenizer.convert_tokens_to_ids(tokens) - input_mask = [1] * len(input_ids) - seq_length = len(input_ids) - - padding = [0] * (max_seq_length - len(input_ids)) - input_ids += padding - input_mask += padding - segment_ids += padding - - assert len(input_ids) == max_seq_length - assert len(input_mask) == max_seq_length - assert len(segment_ids) == max_seq_length - - if output_mode == "classification": - label_id = label_map[example.label] - elif output_mode == "regression": - label_id = float(example.label) - else: - raise KeyError(output_mode) - - features.append( - InputFeatures(input_ids=input_ids, - input_mask=input_mask, - segment_ids=segment_ids, - label_id=label_id, - seq_length=seq_length)) - return features - - -def get_label_ids(features): - """get the label id""" - return torch.tensor([f.label_id for f in features], dtype=torch.long) - - -def simple_accuracy(preds, labels): - """calculate the accuracy""" - return (preds == labels).mean() - - -def bin2predlabel(test_num, args): - """(adapt to benchmark inference)change the bin files into logits""" - logit1 = [] - logit2 = [] - for i in range(test_num): - n1, n2 = np.fromfile('{}/Bert_{}_1.bin'.format(args.result_dir, i), dtype='float32') - logit1.append(n1) - logit2.append(n2) - logit = np.concatenate((np.array(logit1).reshape(1, -1), np.array(logit2).reshape(1, -1)), axis = 0) - pred_label = np.argmax(logit, axis = 0) - return pred_label - - -def txt2predlabel(test_num, args): - """(adapt to msame inference):change the txt files into logits""" - logit1 = [] - logit2 = [] - for i in range(test_num): - txtname = "input" + str(i) + "_output_0.txt" - dir = os.path.join(args.result_dir, txtname) - with open(dir, "r") as f: - line = f.readline() - n1, n2 = [float(i) for i in line.split()] - logit1.append(n1) - logit2.append(n2) - logit = np.concatenate((np.array(logit1).reshape(1, -1), np.array(logit2).reshape(1, -1)), axis = 0) - pred_label = np.argmax(logit, axis = 0) - return pred_label - - -def main(): - """postprocess the data and calculate the accuracy""" - parser = argparse.ArgumentParser() - parser.add_argument("--max_seq_length", - default=64, - type=int, - help="The maximum total input sequence length after WordPiece tokenization. \n" - "Sequences longer than this will be truncated, and sequences shorter \n" - "than this will be padded.") - parser.add_argument("--data_dir", - default=None, - type=str, - required=True, - help="The input data dir. Should contain the .tsv files (or other data files) for the task.") - parser.add_argument("--result_dir", - default=None, - type=str, - required=True, - help="NPU benchmark infer result path") - parser.add_argument("--model", - default=None, - type=str, - required=True, - help="The student model dir.") - parser.add_argument("--do_lower_case", - action='store_true', - help="Set this flag if you are using an uncased model.") - parser.add_argument("--inference_tool", type = str, - help = "inference tool:benchmark or msame") - args = parser.parse_args() - test_num = 872 - processor = Sst2Processor() - tokenizer = BertTokenizer.from_pretrained(args.model, do_lower_case=args.do_lower_case) - eval_examples = processor.get_dev_examples(args.data_dir) - label_list = ["0", "1"] - eval_features = convert_examples_to_features(eval_examples, label_list, args.max_seq_length, tokenizer, - output_mode="classification") - #data processing - eval_labels = get_label_ids(eval_features).numpy() - if args.inference_tool == "benchmark": - pred_labels = bin2predlabel(test_num, args) - elif args.inference_tool == "msame": - pred_labels = txt2predlabel(test_num, args) - result = simple_accuracy(pred_labels, eval_labels) - print("acc:{}".format(result)) - -if __name__ == '__main__': +# coding=utf-8 +# Copyright (c) 2019 NVIDIA CORPORATION. All rights reserved. +# Copyright 2018 The Google AI Language Team Authors and The HugginFace Inc. team. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Run TinyBERT on SST-2.""" + +from __future__ import absolute_import, division, print_function +import argparse +import os +import sys +import csv +import numpy as np +import io +from transformer.tokenization import BertTokenizer +import torch + + +class InputExample(object): + """A single training/test example for simple sequence classification.""" + + def __init__(self, guid, text_a, text_b=None, label=None): + """Constructs a InputExample. + + Args: + guid: Unique id for the example. + text_a: string. The untokenized text of the first sequence. For single + sequence tasks, only this sequence must be specified. + text_b: (Optional) string. The untokenized text of the second sequence. + Only must be specified for sequence pair tasks. + label: (Optional) string. The label of the example. This should be + specified for train and dev examples, but not for test examples. + """ + self.guid = guid + self.text_a = text_a + self.text_b = text_b + self.label = label + + +class InputFeatures(object): + """A single set of features of data.""" + + def __init__(self, input_ids, input_mask, segment_ids, label_id, seq_length=None): + self.input_ids = input_ids + self.input_mask = input_mask + self.segment_ids = segment_ids + self.seq_length = seq_length + self.label_id = label_id + + +class DataProcessor(object): + """Base class for data converters for sequence classification data sets.""" + + def get_train_examples(self, data_dir): + """Gets a collection of `InputExample`s for the train set.""" + raise NotImplementedError() + + def get_dev_examples(self, data_dir): + """Gets a collection of `InputExample`s for the dev set.""" + raise NotImplementedError() + + def get_labels(self): + """Gets the list of labels for this data set.""" + raise NotImplementedError() + + @classmethod + def _read_tsv(cls, input_file, quotechar=None): + """Reads a tab separated value file.""" + with io.open(input_file, "r", encoding="utf-8") as f: + reader = csv.reader(f, delimiter="\t", quotechar=quotechar) + lines = [] + for line in reader: + if sys.version_info[0] == 2: + line = list(unicode(cell, 'utf-8') for cell in line) + lines.append(line) + return lines + + +class Sst2Processor(DataProcessor): + """Processor for the SST-2 data set (GLUE version).""" + + def get_train_examples(self, data_dir): + """See base class.""" + return self._create_examples( + self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") + + def get_dev_examples(self, data_dir): + """See base class.""" + return self._create_examples( + self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev") + + def get_aug_examples(self, data_dir): + """get the augmented examples""" + return self._create_examples( + self._read_tsv(os.path.join(data_dir, "train_aug.tsv")), "aug") + + def get_labels(self): + """See base class.""" + return ["0", "1"] + + def _create_examples(self, lines, set_type): + """Creates examples for the training and dev sets.""" + examples = [] + for (i, line) in enumerate(lines): + if i == 0: + continue + guid = "%s-%s" % (set_type, i) + text_a = line[0] + label = line[1] + examples.append( + InputExample(guid=guid, text_a=text_a, text_b=None, label=label)) + return examples + + +def _truncate_seq_pair(tokens_a, tokens_b, max_length): + """Truncates a sequence pair in place to the maximum length.""" + while True: + total_length = len(tokens_a) + len(tokens_b) + if total_length <= max_length: + break + if len(tokens_a) > len(tokens_b): + tokens_a.pop() + else: + tokens_b.pop() + + +def convert_examples_to_features(examples, label_list, max_seq_length, + tokenizer, output_mode): + """Loads a data file into a list of `InputBatch`s.""" + + label_map = {label: i for i, label in enumerate(label_list)} + + features = [] + for (ex_index, example) in enumerate(examples): + + tokens_a = tokenizer.tokenize(example.text_a) + + tokens_b = None + if example.text_b: + tokens_b = tokenizer.tokenize(example.text_b) + _truncate_seq_pair(tokens_a, tokens_b, max_seq_length - 3) + else: + if len(tokens_a) > max_seq_length - 2: + tokens_a = tokens_a[:(max_seq_length - 2)] + + tokens = ["[CLS]"] + tokens_a + ["[SEP]"] + segment_ids = [0] * len(tokens) + + if tokens_b: + tokens += tokens_b + ["[SEP]"] + segment_ids += [1] * (len(tokens_b) + 1) + + input_ids = tokenizer.convert_tokens_to_ids(tokens) + input_mask = [1] * len(input_ids) + seq_length = len(input_ids) + + padding = [0] * (max_seq_length - len(input_ids)) + input_ids += padding + input_mask += padding + segment_ids += padding + + assert len(input_ids) == max_seq_length + assert len(input_mask) == max_seq_length + assert len(segment_ids) == max_seq_length + + if output_mode == "classification": + label_id = label_map[example.label] + elif output_mode == "regression": + label_id = float(example.label) + else: + raise KeyError(output_mode) + + features.append( + InputFeatures(input_ids=input_ids, + input_mask=input_mask, + segment_ids=segment_ids, + label_id=label_id, + seq_length=seq_length)) + return features + + +def get_label_ids(features): + """get the label id""" + return torch.tensor([f.label_id for f in features], dtype=torch.long) + + +def simple_accuracy(preds, labels): + """calculate the accuracy""" + return (preds == labels).mean() + + +def bin2predlabel(test_num, args): + """(adapt to benchmark inference)change the bin files into logits""" + logit1 = [] + logit2 = [] + for i in range(test_num): + n1, n2 = np.fromfile('{}/Bert_{}_1.bin'.format(args.result_dir, i), dtype='float32') + logit1.append(n1) + logit2.append(n2) + logit = np.concatenate((np.array(logit1).reshape(1, -1), np.array(logit2).reshape(1, -1)), axis = 0) + pred_label = np.argmax(logit, axis = 0) + return pred_label + + +def txt2predlabel(test_num, args): + """(adapt to msame inference):change the txt files into logits""" + logit1 = [] + logit2 = [] + for i in range(test_num): + txtname = "input" + str(i) + "_output_0.txt" + dir = os.path.join(args.result_dir, txtname) + with open(dir, "r") as f: + line = f.readline() + n1, n2 = [float(i) for i in line.split()] + logit1.append(n1) + logit2.append(n2) + logit = np.concatenate((np.array(logit1).reshape(1, -1), np.array(logit2).reshape(1, -1)), axis = 0) + pred_label = np.argmax(logit, axis = 0) + return pred_label + + +def main(): + """postprocess the data and calculate the accuracy""" + parser = argparse.ArgumentParser() + parser.add_argument("--max_seq_length", + default=64, + type=int, + help="The maximum total input sequence length after WordPiece tokenization. \n" + "Sequences longer than this will be truncated, and sequences shorter \n" + "than this will be padded.") + parser.add_argument("--data_dir", + default=None, + type=str, + required=True, + help="The input data dir. Should contain the .tsv files (or other data files) for the task.") + parser.add_argument("--result_dir", + default=None, + type=str, + required=True, + help="NPU benchmark infer result path") + parser.add_argument("--model", + default=None, + type=str, + required=True, + help="The student model dir.") + parser.add_argument("--do_lower_case", + action='store_true', + help="Set this flag if you are using an uncased model.") + parser.add_argument("--inference_tool", type = str, + help = "inference tool:benchmark or msame") + args = parser.parse_args() + test_num = 872 + processor = Sst2Processor() + tokenizer = BertTokenizer.from_pretrained(args.model, do_lower_case=args.do_lower_case) + eval_examples = processor.get_dev_examples(args.data_dir) + label_list = ["0", "1"] + eval_features = convert_examples_to_features(eval_examples, label_list, args.max_seq_length, tokenizer, + output_mode="classification") + #data processing + eval_labels = get_label_ids(eval_features).numpy() + if args.inference_tool == "benchmark": + pred_labels = bin2predlabel(test_num, args) + elif args.inference_tool == "msame": + pred_labels = txt2predlabel(test_num, args) + result = simple_accuracy(pred_labels, eval_labels) + print("acc:{}".format(result)) + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/nlp/tinybert/TinyBERT_preprocess_data.py b/ACL_PyTorch/contrib/nlp/tinybert/TinyBERT_preprocess_data.py index 5b90fd8710bc3405ae5e3640d3e4550f991cb744..2116c4ab3c971adfc18788fde1f48c76d1633f15 100644 --- a/ACL_PyTorch/contrib/nlp/tinybert/TinyBERT_preprocess_data.py +++ b/ACL_PyTorch/contrib/nlp/tinybert/TinyBERT_preprocess_data.py @@ -1,276 +1,276 @@ -# coding=utf-8 -# Copyright (c) 2019 NVIDIA CORPORATION. All rights reserved. -# Copyright 2018 The Google AI Language Team Authors and The HugginFace Inc. team. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Run TinyBERT on SST-2.""" - -from __future__ import absolute_import, division, print_function -import argparse -import os -import sys -import csv -import io -from transformer.tokenization import BertTokenizer -import torch -from torch.utils.data import (DataLoader, SequentialSampler, TensorDataset) - - -class InputExample(object): - """A single training/test example for simple sequence classification.""" - - def __init__(self, guid, text_a, text_b=None, label=None): - """Constructs a InputExample. - - Args: - guid: Unique id for the example. - text_a: string. The untokenized text of the first sequence. For single - sequence tasks, only this sequence must be specified. - text_b: (Optional) string. The untokenized text of the second sequence. - Only must be specified for sequence pair tasks. - label: (Optional) string. The label of the example. This should be - specified for train and dev examples, but not for test examples. - """ - self.guid = guid - self.text_a = text_a - self.text_b = text_b - self.label = label - - -class InputFeatures(object): - """A single set of features of data.""" - - def __init__(self, input_ids, input_mask, segment_ids, label_id, seq_length=None): - self.input_ids = input_ids - self.input_mask = input_mask - self.segment_ids = segment_ids - self.seq_length = seq_length - self.label_id = label_id - - -class DataProcessor(object): - """Base class for data converters for sequence classification data sets.""" - - def get_train_examples(self, data_dir): - """Gets a collection of `InputExample`s for the train set.""" - raise NotImplementedError() - - def get_dev_examples(self, data_dir): - """Gets a collection of `InputExample`s for the dev set.""" - raise NotImplementedError() - - def get_labels(self): - """Gets the list of labels for this data set.""" - raise NotImplementedError() - - @classmethod - def _read_tsv(cls, input_file, quotechar=None): - """Reads a tab separated value file.""" - with io.open(input_file, "r", encoding="utf-8") as f: - reader = csv.reader(f, delimiter="\t", quotechar=quotechar) - lines = [] - for line in reader: - if sys.version_info[0] == 2: - line = list(unicode(cell, 'utf-8') for cell in line) - lines.append(line) - return lines - - -class Sst2Processor(DataProcessor): - """Processor for the SST-2 data set (GLUE version).""" - - def get_train_examples(self, data_dir): - """See base class.""" - return self._create_examples( - self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") - - def get_dev_examples(self, data_dir): - """See base class.""" - return self._create_examples( - self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev") - - def get_aug_examples(self, data_dir): - """get the augmented data""" - return self._create_examples( - self._read_tsv(os.path.join(data_dir, "train_aug.tsv")), "aug") - - def get_labels(self): - """See base class.""" - return ["0", "1"] - - def _create_examples(self, lines, set_type): - """Creates examples for the training and dev sets.""" - examples = [] - for (i, line) in enumerate(lines): - if i == 0: - continue - guid = "%s-%s" % (set_type, i) - text_a = line[0] - label = line[1] - examples.append( - InputExample(guid=guid, text_a=text_a, text_b=None, label=label)) - return examples - - -def _truncate_seq_pair(tokens_a, tokens_b, max_length): - """Truncates a sequence pair in place to the maximum length.""" - while True: - total_length = len(tokens_a) + len(tokens_b) - if total_length <= max_length: - break - if len(tokens_a) > len(tokens_b): - tokens_a.pop() - else: - tokens_b.pop() - - -def convert_examples_to_features(examples, label_list, max_seq_length, - tokenizer, output_mode): - """Loads a data file into a list of `InputBatch`s.""" - - label_map = {label: i for i, label in enumerate(label_list)} - - features = [] - for (ex_index, example) in enumerate(examples): - - tokens_a = tokenizer.tokenize(example.text_a) - - tokens_b = None - if example.text_b: - tokens_b = tokenizer.tokenize(example.text_b) - _truncate_seq_pair(tokens_a, tokens_b, max_seq_length - 3) - else: - if len(tokens_a) > max_seq_length - 2: - tokens_a = tokens_a[:(max_seq_length - 2)] - - tokens = ["[CLS]"] + tokens_a + ["[SEP]"] - segment_ids = [0] * len(tokens) - - if tokens_b: - tokens += tokens_b + ["[SEP]"] - segment_ids += [1] * (len(tokens_b) + 1) - - input_ids = tokenizer.convert_tokens_to_ids(tokens) - input_mask = [1] * len(input_ids) - seq_length = len(input_ids) - - padding = [0] * (max_seq_length - len(input_ids)) - input_ids += padding - input_mask += padding - segment_ids += padding - - assert len(input_ids) == max_seq_length - assert len(input_mask) == max_seq_length - assert len(segment_ids) == max_seq_length - - if output_mode == "classification": - label_id = label_map[example.label] - elif output_mode == "regression": - label_id = float(example.label) - else: - raise KeyError(output_mode) - - features.append( - InputFeatures(input_ids=input_ids, - input_mask=input_mask, - segment_ids=segment_ids, - label_id=label_id, - seq_length=seq_length)) - return features - - -def get_tensor_data(output_mode, features): - """get the data""" - if output_mode == "classification": - all_label_ids = torch.tensor([f.label_id for f in features], dtype=torch.long) - elif output_mode == "regression": - all_label_ids = torch.tensor([f.label_id for f in features], dtype=torch.float) - - all_seq_lengths = torch.tensor([f.seq_length for f in features], dtype=torch.long) - all_input_ids = torch.tensor([f.input_ids for f in features], dtype=torch.long) - all_input_mask = torch.tensor([f.input_mask for f in features], dtype=torch.long) - all_segment_ids = torch.tensor([f.segment_ids for f in features], dtype=torch.long) - tensor_data = TensorDataset(all_input_ids, all_input_mask, all_segment_ids, - all_label_ids, all_seq_lengths) - return tensor_data, all_label_ids - - -def data_main(): - """preprocess data""" - parser = argparse.ArgumentParser() - parser.add_argument("--model", - default=None, - type=str, - required=True, - help="The student model dir.") - parser.add_argument("--data_dir", - default=None, - type=str, - required=True, - help="The input data dir. Should contain the .tsv files (or other data files) for the task.") - parser.add_argument("--max_seq_length", - default=64, - type=int, - help="The maximum total input sequence length after WordPiece tokenization. \n" - "Sequences longer than this will be truncated, and sequences shorter \n" - "than this will be padded.") - parser.add_argument("--eval_batch_size", - default=1, - type=int, - help="Total batch size for eval.") - parser.add_argument("--do_lower_case", - action='store_true', - help="Set this flag if you are using an uncased model.") - parser.add_argument("--inference_tool", type = str, - help = "inference tool:benchmark or msame") - args = parser.parse_args() - processor = Sst2Processor() - tokenizer = BertTokenizer.from_pretrained(args.model, do_lower_case=args.do_lower_case) # for TinyBERT - - eval_examples = processor.get_dev_examples(args.data_dir) - label_list = ["0", "1"] - eval_features = convert_examples_to_features(eval_examples, label_list, args.max_seq_length, - tokenizer, output_mode = "classification") - - bin_path = "./bert_bin" - output_mode = 'classification' - eval_data, eval_labels = get_tensor_data(output_mode, eval_features) - print("eval_labels") - # Run prediction for full data - eval_sampler = SequentialSampler(eval_data) - eval_dataloader = DataLoader(eval_data, sampler=eval_sampler, drop_last = True, - batch_size = args.eval_batch_size, shuffle = False) - - if not os.path.exists(bin_path): - os.makedirs(bin_path) - i = -1 - for input_ids, input_mask, segment_ids, label_ids, seq_lengths in eval_dataloader: - i = i + 1 - print("[info] file", "===", i) - input_ids_np = input_ids.numpy() - input_mask_np = input_mask.numpy() - segment_ids_np = segment_ids.numpy() - if args.inference_tool == "msame": - path1 = bin_path + "/input_ids" - path2 = bin_path + "/segment_ids" - path3 = bin_path + "/input_mask" - input_ids_np.tofile(os.path.join(path1, "input" + str(i) + '.bin')) - segment_ids_np.tofile(os.path.join(path2, "input" + str(i) + '.bin')) - input_mask_np.tofile(os.path.join(path3, "input" + str(i) + '.bin')) - elif args.inference_tool == "benchmark": - input_ids_np.tofile(os.path.join(bin_path, "input_ids_" + str(i) + '.bin')) - segment_ids_np.tofile(os.path.join(bin_path, "segment_ids_" + str(i) + '.bin')) - input_mask_np.tofile(os.path.join(bin_path, "input_mask_" + str(i) + '.bin')) - -if __name__ == "__main__": +# coding=utf-8 +# Copyright (c) 2019 NVIDIA CORPORATION. All rights reserved. +# Copyright 2018 The Google AI Language Team Authors and The HugginFace Inc. team. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Run TinyBERT on SST-2.""" + +from __future__ import absolute_import, division, print_function +import argparse +import os +import sys +import csv +import io +from transformer.tokenization import BertTokenizer +import torch +from torch.utils.data import (DataLoader, SequentialSampler, TensorDataset) + + +class InputExample(object): + """A single training/test example for simple sequence classification.""" + + def __init__(self, guid, text_a, text_b=None, label=None): + """Constructs a InputExample. + + Args: + guid: Unique id for the example. + text_a: string. The untokenized text of the first sequence. For single + sequence tasks, only this sequence must be specified. + text_b: (Optional) string. The untokenized text of the second sequence. + Only must be specified for sequence pair tasks. + label: (Optional) string. The label of the example. This should be + specified for train and dev examples, but not for test examples. + """ + self.guid = guid + self.text_a = text_a + self.text_b = text_b + self.label = label + + +class InputFeatures(object): + """A single set of features of data.""" + + def __init__(self, input_ids, input_mask, segment_ids, label_id, seq_length=None): + self.input_ids = input_ids + self.input_mask = input_mask + self.segment_ids = segment_ids + self.seq_length = seq_length + self.label_id = label_id + + +class DataProcessor(object): + """Base class for data converters for sequence classification data sets.""" + + def get_train_examples(self, data_dir): + """Gets a collection of `InputExample`s for the train set.""" + raise NotImplementedError() + + def get_dev_examples(self, data_dir): + """Gets a collection of `InputExample`s for the dev set.""" + raise NotImplementedError() + + def get_labels(self): + """Gets the list of labels for this data set.""" + raise NotImplementedError() + + @classmethod + def _read_tsv(cls, input_file, quotechar=None): + """Reads a tab separated value file.""" + with io.open(input_file, "r", encoding="utf-8") as f: + reader = csv.reader(f, delimiter="\t", quotechar=quotechar) + lines = [] + for line in reader: + if sys.version_info[0] == 2: + line = list(unicode(cell, 'utf-8') for cell in line) + lines.append(line) + return lines + + +class Sst2Processor(DataProcessor): + """Processor for the SST-2 data set (GLUE version).""" + + def get_train_examples(self, data_dir): + """See base class.""" + return self._create_examples( + self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") + + def get_dev_examples(self, data_dir): + """See base class.""" + return self._create_examples( + self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev") + + def get_aug_examples(self, data_dir): + """get the augmented data""" + return self._create_examples( + self._read_tsv(os.path.join(data_dir, "train_aug.tsv")), "aug") + + def get_labels(self): + """See base class.""" + return ["0", "1"] + + def _create_examples(self, lines, set_type): + """Creates examples for the training and dev sets.""" + examples = [] + for (i, line) in enumerate(lines): + if i == 0: + continue + guid = "%s-%s" % (set_type, i) + text_a = line[0] + label = line[1] + examples.append( + InputExample(guid=guid, text_a=text_a, text_b=None, label=label)) + return examples + + +def _truncate_seq_pair(tokens_a, tokens_b, max_length): + """Truncates a sequence pair in place to the maximum length.""" + while True: + total_length = len(tokens_a) + len(tokens_b) + if total_length <= max_length: + break + if len(tokens_a) > len(tokens_b): + tokens_a.pop() + else: + tokens_b.pop() + + +def convert_examples_to_features(examples, label_list, max_seq_length, + tokenizer, output_mode): + """Loads a data file into a list of `InputBatch`s.""" + + label_map = {label: i for i, label in enumerate(label_list)} + + features = [] + for (ex_index, example) in enumerate(examples): + + tokens_a = tokenizer.tokenize(example.text_a) + + tokens_b = None + if example.text_b: + tokens_b = tokenizer.tokenize(example.text_b) + _truncate_seq_pair(tokens_a, tokens_b, max_seq_length - 3) + else: + if len(tokens_a) > max_seq_length - 2: + tokens_a = tokens_a[:(max_seq_length - 2)] + + tokens = ["[CLS]"] + tokens_a + ["[SEP]"] + segment_ids = [0] * len(tokens) + + if tokens_b: + tokens += tokens_b + ["[SEP]"] + segment_ids += [1] * (len(tokens_b) + 1) + + input_ids = tokenizer.convert_tokens_to_ids(tokens) + input_mask = [1] * len(input_ids) + seq_length = len(input_ids) + + padding = [0] * (max_seq_length - len(input_ids)) + input_ids += padding + input_mask += padding + segment_ids += padding + + assert len(input_ids) == max_seq_length + assert len(input_mask) == max_seq_length + assert len(segment_ids) == max_seq_length + + if output_mode == "classification": + label_id = label_map[example.label] + elif output_mode == "regression": + label_id = float(example.label) + else: + raise KeyError(output_mode) + + features.append( + InputFeatures(input_ids=input_ids, + input_mask=input_mask, + segment_ids=segment_ids, + label_id=label_id, + seq_length=seq_length)) + return features + + +def get_tensor_data(output_mode, features): + """get the data""" + if output_mode == "classification": + all_label_ids = torch.tensor([f.label_id for f in features], dtype=torch.long) + elif output_mode == "regression": + all_label_ids = torch.tensor([f.label_id for f in features], dtype=torch.float) + + all_seq_lengths = torch.tensor([f.seq_length for f in features], dtype=torch.long) + all_input_ids = torch.tensor([f.input_ids for f in features], dtype=torch.long) + all_input_mask = torch.tensor([f.input_mask for f in features], dtype=torch.long) + all_segment_ids = torch.tensor([f.segment_ids for f in features], dtype=torch.long) + tensor_data = TensorDataset(all_input_ids, all_input_mask, all_segment_ids, + all_label_ids, all_seq_lengths) + return tensor_data, all_label_ids + + +def data_main(): + """preprocess data""" + parser = argparse.ArgumentParser() + parser.add_argument("--model", + default=None, + type=str, + required=True, + help="The student model dir.") + parser.add_argument("--data_dir", + default=None, + type=str, + required=True, + help="The input data dir. Should contain the .tsv files (or other data files) for the task.") + parser.add_argument("--max_seq_length", + default=64, + type=int, + help="The maximum total input sequence length after WordPiece tokenization. \n" + "Sequences longer than this will be truncated, and sequences shorter \n" + "than this will be padded.") + parser.add_argument("--eval_batch_size", + default=1, + type=int, + help="Total batch size for eval.") + parser.add_argument("--do_lower_case", + action='store_true', + help="Set this flag if you are using an uncased model.") + parser.add_argument("--inference_tool", type = str, + help = "inference tool:benchmark or msame") + args = parser.parse_args() + processor = Sst2Processor() + tokenizer = BertTokenizer.from_pretrained(args.model, do_lower_case=args.do_lower_case) # for TinyBERT + + eval_examples = processor.get_dev_examples(args.data_dir) + label_list = ["0", "1"] + eval_features = convert_examples_to_features(eval_examples, label_list, args.max_seq_length, + tokenizer, output_mode = "classification") + + bin_path = "./bert_bin" + output_mode = 'classification' + eval_data, eval_labels = get_tensor_data(output_mode, eval_features) + print("eval_labels") + # Run prediction for full data + eval_sampler = SequentialSampler(eval_data) + eval_dataloader = DataLoader(eval_data, sampler=eval_sampler, drop_last = True, + batch_size = args.eval_batch_size, shuffle = False) + + if not os.path.exists(bin_path): + os.makedirs(bin_path) + i = -1 + for input_ids, input_mask, segment_ids, label_ids, seq_lengths in eval_dataloader: + i = i + 1 + print("[info] file", "===", i) + input_ids_np = input_ids.numpy() + input_mask_np = input_mask.numpy() + segment_ids_np = segment_ids.numpy() + if args.inference_tool == "msame": + path1 = bin_path + "/input_ids" + path2 = bin_path + "/segment_ids" + path3 = bin_path + "/input_mask" + input_ids_np.tofile(os.path.join(path1, "input" + str(i) + '.bin')) + segment_ids_np.tofile(os.path.join(path2, "input" + str(i) + '.bin')) + input_mask_np.tofile(os.path.join(path3, "input" + str(i) + '.bin')) + elif args.inference_tool == "benchmark": + input_ids_np.tofile(os.path.join(bin_path, "input_ids_" + str(i) + '.bin')) + segment_ids_np.tofile(os.path.join(bin_path, "segment_ids_" + str(i) + '.bin')) + input_mask_np.tofile(os.path.join(bin_path, "input_mask_" + str(i) + '.bin')) + +if __name__ == "__main__": data_main() \ No newline at end of file diff --git a/ACL_PyTorch/contrib/nlp/tinybert/modelzoo_level.txt b/ACL_PyTorch/contrib/nlp/tinybert/modelzoo_level.txt index 62ed12347c866db16fef5622af355734787e4ec9..def2f63f1b066cc94e8dd94ec2f0c60d1baa3608 100644 --- a/ACL_PyTorch/contrib/nlp/tinybert/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/nlp/tinybert/modelzoo_level.txt @@ -1,6 +1,6 @@ -ModelConvert:OK -QuantStatus:OK -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +ModelConvert:OK +QuantStatus:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/nlp/tinybert/pth2onnx.py b/ACL_PyTorch/contrib/nlp/tinybert/pth2onnx.py index e30bda0a5dfecfd4664e471849135d0d6f90b8f7..696ebfaa5e8fc7d8e0c5df769d1dfafcf0c6c20d 100644 --- a/ACL_PyTorch/contrib/nlp/tinybert/pth2onnx.py +++ b/ACL_PyTorch/contrib/nlp/tinybert/pth2onnx.py @@ -1,84 +1,84 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import os -import torch -import torch.onnx -import argparse -from transformer.modeling import TinyBertForSequenceClassification - - -def make_input(args): - """make the input data to create a model""" - eval_batch_size = args.eval_batch_size - max_seq_length = args.max_seq_length - org_input_ids = torch.ones(eval_batch_size, max_seq_length).long() - org_token_type_ids = torch.ones(eval_batch_size, max_seq_length).long() - org_input_mask = torch.ones(eval_batch_size, max_seq_length).long() - return (org_input_ids, org_token_type_ids, org_input_mask) - - -def convert(args): - """convert the files into data""" - model = TinyBertForSequenceClassification.from_pretrained(args.input_model, num_labels = 2) - model.eval() - org_input = make_input(args) - input_names = ['input_ids', 'segment_ids', 'input_mask'] - output_names = ['output'] - OPERATOR_EXPORT_TYPE = torch._C._onnx.OperatorExportTypes.ONNX - torch.onnx.export(model, org_input, args.output_file, export_params = True, - input_names=input_names, output_names=output_names, - operator_export_type=OPERATOR_EXPORT_TYPE, - opset_version=11, verbose=True) - - -def main(): - """change the pth files into onnx""" - #set the args list - parser = argparse.ArgumentParser() - parser.add_argument("--input_model", - default=None, - type=str, - required=True, - help="The model(e.g. SST-2 distilled model)dir.") - parser.add_argument("--output_file", - default=None, - type=str, - required=True, - help="The output file of onnx. File name or dir is available.") - parser.add_argument("--data_dir", - default=None, - type=str, - required=True, - help="The input data dir. Should contain the .tsv files (or other data files) for the task.") - parser.add_argument("--max_seq_length", - default=64, - type=int, - help="The maximum total input sequence length after WordPiece tokenization. \n" - "Sequences longer than this will be truncated, and sequences shorter \n" - "than this will be padded.") - parser.add_argument("--eval_batch_size", - default=1, - type=int, - help="Total batch size for eval.") - parser.add_argument("--do_lower_case", - action='store_true', - help="Set this flag if you are using an uncased model.") - args = parser.parse_args() - os.makedirs(os.path.dirname(args.output_file), exist_ok=True) - convert(args) - #add_cast(args) - -if __name__ == "__main__": - main() +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import os +import torch +import torch.onnx +import argparse +from transformer.modeling import TinyBertForSequenceClassification + + +def make_input(args): + """make the input data to create a model""" + eval_batch_size = args.eval_batch_size + max_seq_length = args.max_seq_length + org_input_ids = torch.ones(eval_batch_size, max_seq_length).long() + org_token_type_ids = torch.ones(eval_batch_size, max_seq_length).long() + org_input_mask = torch.ones(eval_batch_size, max_seq_length).long() + return (org_input_ids, org_token_type_ids, org_input_mask) + + +def convert(args): + """convert the files into data""" + model = TinyBertForSequenceClassification.from_pretrained(args.input_model, num_labels = 2) + model.eval() + org_input = make_input(args) + input_names = ['input_ids', 'segment_ids', 'input_mask'] + output_names = ['output'] + OPERATOR_EXPORT_TYPE = torch._C._onnx.OperatorExportTypes.ONNX + torch.onnx.export(model, org_input, args.output_file, export_params = True, + input_names=input_names, output_names=output_names, + operator_export_type=OPERATOR_EXPORT_TYPE, + opset_version=11, verbose=True) + + +def main(): + """change the pth files into onnx""" + #set the args list + parser = argparse.ArgumentParser() + parser.add_argument("--input_model", + default=None, + type=str, + required=True, + help="The model(e.g. SST-2 distilled model)dir.") + parser.add_argument("--output_file", + default=None, + type=str, + required=True, + help="The output file of onnx. File name or dir is available.") + parser.add_argument("--data_dir", + default=None, + type=str, + required=True, + help="The input data dir. Should contain the .tsv files (or other data files) for the task.") + parser.add_argument("--max_seq_length", + default=64, + type=int, + help="The maximum total input sequence length after WordPiece tokenization. \n" + "Sequences longer than this will be truncated, and sequences shorter \n" + "than this will be padded.") + parser.add_argument("--eval_batch_size", + default=1, + type=int, + help="Total batch size for eval.") + parser.add_argument("--do_lower_case", + action='store_true', + help="Set this flag if you are using an uncased model.") + args = parser.parse_args() + os.makedirs(os.path.dirname(args.output_file), exist_ok=True) + convert(args) + #add_cast(args) + +if __name__ == "__main__": + main() diff --git a/ACL_PyTorch/contrib/rl/DQN/env.sh b/ACL_PyTorch/contrib/rl/DQN/env.sh index 7e0a3deaa3ec3524176a38d13cb805463c8ace4d..d9466cab92c1990095d21f6f7bb203013df4014a 100644 --- a/ACL_PyTorch/contrib/rl/DQN/env.sh +++ b/ACL_PyTorch/contrib/rl/DQN/env.sh @@ -1,8 +1,8 @@ -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH -export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp -source /usr/local/Ascend/ascend-toolkit/set_env.sh -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +source /usr/local/Ascend/ascend-toolkit/set_env.sh +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest export REPEAT_TUNE=True \ No newline at end of file diff --git a/ACL_PyTorch/contrib/rl/DQN/modelzoo_level.txt b/ACL_PyTorch/contrib/rl/DQN/modelzoo_level.txt index 38700fca05402f52c3ae1c4be0889eb60e1f80f1..2e42553460a4f3687654b6ad3f91ab0bcc3aadac 100644 --- a/ACL_PyTorch/contrib/rl/DQN/modelzoo_level.txt +++ b/ACL_PyTorch/contrib/rl/DQN/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:OK \ No newline at end of file diff --git a/ACL_PyTorch/contrib/rl/DQN/test/parse.py b/ACL_PyTorch/contrib/rl/DQN/test/parse.py index 26ec1439e9bb19db3bbe50cb3e17499b350a7ec4..f45e4ba7e1f7c3c72eabea1376080e3dd62a56a0 100644 --- a/ACL_PyTorch/contrib/rl/DQN/test/parse.py +++ b/ACL_PyTorch/contrib/rl/DQN/test/parse.py @@ -1,34 +1,34 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys -import json -import re - -if __name__ == '__main__': - if sys.argv[1].endswith('.json'): - result_json = sys.argv[1] - with open(result_json, 'r') as f: - content = f.read() - print(content) - elif sys.argv[1].endswith('.txt'): - result_txt = sys.argv[1] - with open(result_txt, 'r') as f: - content = f.read() - - txt_data_list = [i.strip() for i in re.findall(r'=(.*?),', content.replace('\n', ',') + ',')] - print(txt_data_list) - fps = float(txt_data_list[0].replace('samples/s', '')) * 4 - print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import json +import re + +if __name__ == '__main__': + if sys.argv[1].endswith('.json'): + result_json = sys.argv[1] + with open(result_json, 'r') as f: + content = f.read() + print(content) + elif sys.argv[1].endswith('.txt'): + result_txt = sys.argv[1] + with open(result_txt, 'r') as f: + content = f.read() + + txt_data_list = [i.strip() for i in re.findall(r'=(.*?),', content.replace('\n', ',') + ',')] + print(txt_data_list) + fps = float(txt_data_list[0].replace('samples/s', '')) * 4 + print('310 bs{} fps:{}'.format(result_txt.split('_')[3], fps)) + diff --git a/PyTorch/built-in/cv/classification/3D_ResNet_ID0421_for_PyTorch/test/train_full_8p.sh b/PyTorch/built-in/cv/classification/3D_ResNet_ID0421_for_PyTorch/test/train_full_8p.sh index 93de5c26b9f05241bed6862127ccd2e40b188af3..6947e5169b0f7f89b844472a277267389336fce6 100644 --- a/PyTorch/built-in/cv/classification/3D_ResNet_ID0421_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/built-in/cv/classification/3D_ResNet_ID0421_for_PyTorch/test/train_full_8p.sh @@ -1,229 +1,229 @@ -#!/bin/bash - -#集合通信参数,不需要修改 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 - - -# 数据集路径,保持为空,不需要修改 -data_path="" -device_id=0 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="3D_ResNet_ID0421_for_PyTorch" -#训练epoch -train_epochs=200 -#训练batch_size -batch_size=1024 -#训练step -train_steps= -#学习率 -learning_rate=0.08 - -#TF2.X独有,需要模型审视修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -#precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_1p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/test/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/test/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/test/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - -###############指定训练脚本执行路径############### -# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path -##################创建日志输出目录,根据模型审视################## -# 模型采用非循环方式启动多卡训练,创建日志输出目录如下;采用循环方式启动多卡训练的模型,在循环中创建日志输出目录,可参考CRNN模型 -# 非循环方式下8卡训练日志输出路径中的ASCEND_DEVICE_ID默认为0,只是人为指定文件夹名称, 不涉及训练业务 -ASCEND_DEVICE_ID=0 -#创建DeviceID输出目录,不需要修改 -if [ -d ${cur_path}/test/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/test/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt -else - mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt -fi -# 绑核,不需要的绑核的模型删除,需要的模型审视修改 -#let a=RANK_ID*12 -#let b=RANK_ID+1 -#let c=b*12-1 - -#执行训练脚本,以下传参不需要修改,其他需要模型审视修改 -#--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path - nohup python3 main.py \ - --video_path ${data_path}/hmdb51_jpg \ - --annotation_path ${data_path}/hmdb51_json/hmdb51_1.json \ - --result_path outputs \ - --dataset hmdb51 \ - --n_classes 51 \ - --n_pretrain_classes 700 \ - --pretrain_path ${data_path}/r3d18_K_200ep.pth \ - --ft_begin_module fc \ - --model resnet \ - --model_depth 18 \ - --batch_size 1024 \ - --n_threads 128 \ - --checkpoint 5 \ - --amp_cfg \ - --n_epochs ${train_epochs} \ - --opt_level O2 \ - --loss_scale_value 1024 \ - --distributed \ - --ngpus_per_node 8 \ - --device_list '0,1,2,3,4,5,6,7' \ - --manual_seed 1234 \ - --learning_rate ${learning_rate} \ - --tensorboard > ${cur_path}/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & - -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep Fps $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v "\[1/" | grep -v "\[2/" | awk -F "Fps" '{print$2}' | awk '{print$1}' | awk '{sum+=$1} END {print"",sum/NR}'` -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - - -python3 main.py \ - --video_path ${data_path}/hmdb51_jpg \ - --annotation_path ${data_path}/hmdb51_json/hmdb51_1.json \ - --result_path outputs \ - --dataset hmdb51 \ - --resume_path outputs/save_200.pth \ - --model_depth 18 \ - --n_classes 51 \ - --n_threads 4 \ - --no_train \ - --no_val \ - --inference \ - --output_topk 5 \ - --inference_batch_size 1 \ - --device_list '0,1,2,3,4,5,6,7' - -python3 -m util_scripts.eval_accuracy ${data_path}/hmdb51_json/hmdb51_1.json outputs/val.json -k 1 --save --ignore >> ${cur_path}/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -wait -#输出训练精度,需要模型审视修改 -train_accuracy=`grep "top-1 accuracy:" $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print$3}' ` - -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`echo "${batch_size} ${FPS}" | awk '{printf("%.2f",$1*1000/$2)}' ` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "Fps" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss" '{print$2}' | awk '{print$1}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#集合通信参数,不需要修改 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 + + +# 数据集路径,保持为空,不需要修改 +data_path="" +device_id=0 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="3D_ResNet_ID0421_for_PyTorch" +#训练epoch +train_epochs=200 +#训练batch_size +batch_size=1024 +#训练step +train_steps= +#学习率 +learning_rate=0.08 + +#TF2.X独有,需要模型审视修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +#precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_1p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/test/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/test/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/test/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + +###############指定训练脚本执行路径############### +# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path +##################创建日志输出目录,根据模型审视################## +# 模型采用非循环方式启动多卡训练,创建日志输出目录如下;采用循环方式启动多卡训练的模型,在循环中创建日志输出目录,可参考CRNN模型 +# 非循环方式下8卡训练日志输出路径中的ASCEND_DEVICE_ID默认为0,只是人为指定文件夹名称, 不涉及训练业务 +ASCEND_DEVICE_ID=0 +#创建DeviceID输出目录,不需要修改 +if [ -d ${cur_path}/test/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/test/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt +else + mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt +fi +# 绑核,不需要的绑核的模型删除,需要的模型审视修改 +#let a=RANK_ID*12 +#let b=RANK_ID+1 +#let c=b*12-1 + +#执行训练脚本,以下传参不需要修改,其他需要模型审视修改 +#--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path + nohup python3 main.py \ + --video_path ${data_path}/hmdb51_jpg \ + --annotation_path ${data_path}/hmdb51_json/hmdb51_1.json \ + --result_path outputs \ + --dataset hmdb51 \ + --n_classes 51 \ + --n_pretrain_classes 700 \ + --pretrain_path ${data_path}/r3d18_K_200ep.pth \ + --ft_begin_module fc \ + --model resnet \ + --model_depth 18 \ + --batch_size 1024 \ + --n_threads 128 \ + --checkpoint 5 \ + --amp_cfg \ + --n_epochs ${train_epochs} \ + --opt_level O2 \ + --loss_scale_value 1024 \ + --distributed \ + --ngpus_per_node 8 \ + --device_list '0,1,2,3,4,5,6,7' \ + --manual_seed 1234 \ + --learning_rate ${learning_rate} \ + --tensorboard > ${cur_path}/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep Fps $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v "\[1/" | grep -v "\[2/" | awk -F "Fps" '{print$2}' | awk '{print$1}' | awk '{sum+=$1} END {print"",sum/NR}'` +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + + +python3 main.py \ + --video_path ${data_path}/hmdb51_jpg \ + --annotation_path ${data_path}/hmdb51_json/hmdb51_1.json \ + --result_path outputs \ + --dataset hmdb51 \ + --resume_path outputs/save_200.pth \ + --model_depth 18 \ + --n_classes 51 \ + --n_threads 4 \ + --no_train \ + --no_val \ + --inference \ + --output_topk 5 \ + --inference_batch_size 1 \ + --device_list '0,1,2,3,4,5,6,7' + +python3 -m util_scripts.eval_accuracy ${data_path}/hmdb51_json/hmdb51_1.json outputs/val.json -k 1 --save --ignore >> ${cur_path}/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +wait +#输出训练精度,需要模型审视修改 +train_accuracy=`grep "top-1 accuracy:" $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print$3}' ` + +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`echo "${batch_size} ${FPS}" | awk '{printf("%.2f",$1*1000/$2)}' ` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "Fps" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss" '{print$2}' | awk '{print$1}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/3D_ResNet_ID0421_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/cv/classification/3D_ResNet_ID0421_for_PyTorch/test/train_performance_8p.sh index d001bec65b44e7e05be232aad3b71f1a6eb8e3e5..217ceeccee24608efba7a477f7dc7953b94eeaca 100644 --- a/PyTorch/built-in/cv/classification/3D_ResNet_ID0421_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/cv/classification/3D_ResNet_ID0421_for_PyTorch/test/train_performance_8p.sh @@ -1,208 +1,208 @@ -#!/bin/bash - -#集合通信参数,不需要修改 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 - - -# 数据集路径,保持为空,不需要修改 -data_path="" -device_id=0 - -#设置默认日志级别,不需要修改 -export ASCEND_GLOBAL_LOG_LEVEL=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="3D_ResNet_ID0421_for_PyTorch" -#训练epoch -train_epochs=2 -#训练batch_size -batch_size=1024 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.08 - -#TF2.X独有,需要模型审视修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -#precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_performance_1P.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/test/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/test/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/test/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - -###############指定训练脚本执行路径############### -# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path - -echo "Device ID: $ASCEND_DEVICE_ID" -#export RANK_ID=$RANK_ID - -#创建DeviceID输出目录,不需要修改 -if [ -d ${cur_path}/test/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/test/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt -else - mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt -fi -# 绑核,不需要的绑核的模型删除,需要的模型审视修改 -#let a=RANK_ID*12 -#let b=RANK_ID+1 -#let c=b*12-1 - -#执行训练脚本,以下传参不需要修改,其他需要模型审视修改 -#--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path -nohup python3 main.py \ - --video_path ${data_path}/hmdb51_jpg \ - --annotation_path ${data_path}/hmdb51_json/hmdb51_1.json \ - --result_path outputs \ - --dataset hmdb51 \ - --n_classes 51 \ - --n_pretrain_classes 700 \ - --pretrain_path ${data_path}/r3d18_K_200ep.pth \ - --ft_begin_module fc \ - --model resnet \ - --model_depth 18 \ - --batch_size $batch_size \ - --n_threads 128 \ - --checkpoint 5 \ - --amp_cfg \ - --n_epochs ${train_epochs} \ - --opt_level O2 \ - --loss_scale_value 1024 \ - --distributed \ - --ngpus_per_node 8 \ - --device_list '0,1,2,3,4,5,6,7' \ - --manual_seed 1234 \ - --learning_rate ${learning_rate} \ - --tensorboard > ${cur_path}/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep Fps $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v "Epoch: \[1\]"|awk -F "Fps" '{print$2}'|awk '{print $1}'|awk '{sum+=$1} END {print sum/NR}'` -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep "Fps" $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|tail -2|head -1|awk '{print $17}'|sed 's/[()]//g' ` -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`echo "${batch_size} ${FPS}" | awk '{printf("%.2f",$1*1000/$2)}' ` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "Fps" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss" '{print$2}' | awk '{print$1}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#集合通信参数,不需要修改 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 + + +# 数据集路径,保持为空,不需要修改 +data_path="" +device_id=0 + +#设置默认日志级别,不需要修改 +export ASCEND_GLOBAL_LOG_LEVEL=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="3D_ResNet_ID0421_for_PyTorch" +#训练epoch +train_epochs=2 +#训练batch_size +batch_size=1024 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.08 + +#TF2.X独有,需要模型审视修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +#precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_performance_1P.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/test/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/test/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/test/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + +###############指定训练脚本执行路径############### +# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path + +echo "Device ID: $ASCEND_DEVICE_ID" +#export RANK_ID=$RANK_ID + +#创建DeviceID输出目录,不需要修改 +if [ -d ${cur_path}/test/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/test/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt +else + mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt +fi +# 绑核,不需要的绑核的模型删除,需要的模型审视修改 +#let a=RANK_ID*12 +#let b=RANK_ID+1 +#let c=b*12-1 + +#执行训练脚本,以下传参不需要修改,其他需要模型审视修改 +#--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path +nohup python3 main.py \ + --video_path ${data_path}/hmdb51_jpg \ + --annotation_path ${data_path}/hmdb51_json/hmdb51_1.json \ + --result_path outputs \ + --dataset hmdb51 \ + --n_classes 51 \ + --n_pretrain_classes 700 \ + --pretrain_path ${data_path}/r3d18_K_200ep.pth \ + --ft_begin_module fc \ + --model resnet \ + --model_depth 18 \ + --batch_size $batch_size \ + --n_threads 128 \ + --checkpoint 5 \ + --amp_cfg \ + --n_epochs ${train_epochs} \ + --opt_level O2 \ + --loss_scale_value 1024 \ + --distributed \ + --ngpus_per_node 8 \ + --device_list '0,1,2,3,4,5,6,7' \ + --manual_seed 1234 \ + --learning_rate ${learning_rate} \ + --tensorboard > ${cur_path}/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep Fps $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v "Epoch: \[1\]"|awk -F "Fps" '{print$2}'|awk '{print $1}'|awk '{sum+=$1} END {print sum/NR}'` +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep "Fps" $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|tail -2|head -1|awk '{print $17}'|sed 's/[()]//g' ` +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`echo "${batch_size} ${FPS}" | awk '{printf("%.2f",$1*1000/$2)}' ` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "Fps" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss" '{print$2}' | awk '{print$1}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/modelzoo_level.txt b/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/built-in/cv/classification/CRNN_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/DeepMar_for_PyTorch/test/train_full_1p.sh b/PyTorch/built-in/cv/classification/DeepMar_for_PyTorch/test/train_full_1p.sh index 7a4996a3caa0fd2bd9ddaafbb562f8c56771a686..bba3ff1550586b04aa1c6ff27039575339f978bd 100644 --- a/PyTorch/built-in/cv/classification/DeepMar_for_PyTorch/test/train_full_1p.sh +++ b/PyTorch/built-in/cv/classification/DeepMar_for_PyTorch/test/train_full_1p.sh @@ -1,197 +1,197 @@ -#!/bin/bash -export ASCEND_SLOG_PRINT_TO_STDOUT=0 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -# 数据集路径,保持为空,不需要修改 -data_path="" -device_id=0 - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="DeepMar_ID0096_for_PyTorch" -#训练epoch -train_epochs=4 -#训练batch_size -batch_size=256 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - - - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_full_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --ci_cp* ]];then - ci_cp=`echo ${para#*=}` - fi -done - -if [[ $ci_cp == "1" ]];then - cp -r $data_path ${data_path}_bak -fi - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - - -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -fi - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -#################创建日志输出目录,不需要修改################# -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -fi -wait - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi - -# 绑核,不需要的绑核的模型删除,需要模型审视修改 -python3.7 ${cur_path}/transform_peta.py \ - --save_dir=$data_path \ - --traintest_split_file=$data_path/peta_partition.pkl - -nohup python3.7 ${cur_path}/train_deepmar_resnet50.py \ - --save_dir=$data_path \ - --workers=32 \ - --npu=$ASCEND_DEVICE_ID \ - --batch_size=$batch_size \ - --new_params_lr=0.01 \ - --finetuned_params_lr=0.01 \ - --total_epochs=100 \ - --steps_per_log=1 \ - --loss_scale 512 \ - --amp \ - --opt_level O2 > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v loss|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a 'Acc' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "Acc" '{print $2}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#打印,不需要修改 -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Step ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'loss:' '{print $2}' > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log - -if [[ $ci_cp == "1" ]];then - rm -rf $data_path - mv ${data_path}_bak $data_path +#!/bin/bash +export ASCEND_SLOG_PRINT_TO_STDOUT=0 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +# 数据集路径,保持为空,不需要修改 +data_path="" +device_id=0 + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="DeepMar_ID0096_for_PyTorch" +#训练epoch +train_epochs=4 +#训练batch_size +batch_size=256 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + + + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_full_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --ci_cp* ]];then + ci_cp=`echo ${para#*=}` + fi +done + +if [[ $ci_cp == "1" ]];then + cp -r $data_path ${data_path}_bak +fi + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + + +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +fi + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +#################创建日志输出目录,不需要修改################# +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +fi +wait + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +# 绑核,不需要的绑核的模型删除,需要模型审视修改 +python3.7 ${cur_path}/transform_peta.py \ + --save_dir=$data_path \ + --traintest_split_file=$data_path/peta_partition.pkl + +nohup python3.7 ${cur_path}/train_deepmar_resnet50.py \ + --save_dir=$data_path \ + --workers=32 \ + --npu=$ASCEND_DEVICE_ID \ + --batch_size=$batch_size \ + --new_params_lr=0.01 \ + --finetuned_params_lr=0.01 \ + --total_epochs=100 \ + --steps_per_log=1 \ + --loss_scale 512 \ + --amp \ + --opt_level O2 > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v loss|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a 'Acc' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "Acc" '{print $2}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#打印,不需要修改 +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Step ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'loss:' '{print $2}' > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log + +if [[ $ci_cp == "1" ]];then + rm -rf $data_path + mv ${data_path}_bak $data_path fi \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/DeepMar_for_PyTorch/test/train_performance_1p.sh b/PyTorch/built-in/cv/classification/DeepMar_for_PyTorch/test/train_performance_1p.sh index 2aa0252f828a0cd6b2cc3e5d0ea1756eb7828b61..c371cc86ea9c6cdc9c37c709cd6cbfa5b40272c0 100644 --- a/PyTorch/built-in/cv/classification/DeepMar_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/built-in/cv/classification/DeepMar_for_PyTorch/test/train_performance_1p.sh @@ -1,193 +1,193 @@ -#!/bin/bash -export ASCEND_SLOG_PRINT_TO_STDOUT=0 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -# 数据集路径,保持为空,不需要修改 -data_path="" -device_id=0 - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="DeepMar_ID0096_for_PyTorch" -#训练epoch -train_epochs=4 -#训练batch_size -batch_size=256 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - - - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --ci_cp* ]];then - ci_cp=`echo ${para#*=}` - fi -done - -if [[ $ci_cp == "1" ]];then - cp -r $data_path ${data_path}_bak -fi - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - - -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -fi - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -#################创建日志输出目录,不需要修改################# -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -fi -wait - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi - -# 绑核,不需要的绑核的模型删除,需要模型审视修改 -python3.7 ${cur_path}/transform_peta.py \ - --save_dir=$data_path \ - --traintest_split_file=$data_path/peta_partition.pkl - -nohup python3.7 ${cur_path}/train_deepmar_resnet50.py \ - --save_dir=$data_path \ - --workers=32 \ - --npu=$ASCEND_DEVICE_ID \ - --batch_size=$batch_size \ - --new_params_lr=0.01 \ - --finetuned_params_lr=0.01 \ - --total_epochs=10 \ - --steps_per_log=1 \ - --loss_scale 512 \ - --amp \ - --opt_level O2 > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v loss|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#打印,不需要修改 -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Step ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'loss:' '{print $2}' > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log - -if [[ $ci_cp == "1" ]];then - rm -rf $data_path - mv ${data_path}_bak $data_path +#!/bin/bash +export ASCEND_SLOG_PRINT_TO_STDOUT=0 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +# 数据集路径,保持为空,不需要修改 +data_path="" +device_id=0 + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="DeepMar_ID0096_for_PyTorch" +#训练epoch +train_epochs=4 +#训练batch_size +batch_size=256 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + + + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --ci_cp* ]];then + ci_cp=`echo ${para#*=}` + fi +done + +if [[ $ci_cp == "1" ]];then + cp -r $data_path ${data_path}_bak +fi + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + + +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +fi + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +#################创建日志输出目录,不需要修改################# +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +fi +wait + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +# 绑核,不需要的绑核的模型删除,需要模型审视修改 +python3.7 ${cur_path}/transform_peta.py \ + --save_dir=$data_path \ + --traintest_split_file=$data_path/peta_partition.pkl + +nohup python3.7 ${cur_path}/train_deepmar_resnet50.py \ + --save_dir=$data_path \ + --workers=32 \ + --npu=$ASCEND_DEVICE_ID \ + --batch_size=$batch_size \ + --new_params_lr=0.01 \ + --finetuned_params_lr=0.01 \ + --total_epochs=10 \ + --steps_per_log=1 \ + --loss_scale 512 \ + --amp \ + --opt_level O2 > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v loss|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#打印,不需要修改 +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Step ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'loss:' '{print $2}' > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log + +if [[ $ci_cp == "1" ]];then + rm -rf $data_path + mv ${data_path}_bak $data_path fi \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/DeepMar_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/cv/classification/DeepMar_for_PyTorch/test/train_performance_8p.sh index 9595736e63251fdae889ef2bd427a362d42aa8c9..79ad08e360adab9f99a616859c20f8ade6071e11 100644 --- a/PyTorch/built-in/cv/classification/DeepMar_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/cv/classification/DeepMar_for_PyTorch/test/train_performance_8p.sh @@ -1,198 +1,198 @@ -#!/bin/bash -export ASCEND_SLOG_PRINT_TO_STDOUT=0 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" -device_id=0 -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="DeepMar_ID0096_for_PyTorch" -#训练epoch -train_epochs=4 -#训练batch_size -batch_size=2048 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - - - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --ci_cp* ]];then - ci_cp=`echo ${para#*=}` - fi -done - -if [[ $ci_cp == "1" ]];then - cp -r $data_path ${data_path}_bak -fi - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -#################创建日志输出目录,不需要修改################# -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -fi -wait - - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi - -# 绑核,不需要的绑核的模型删除,需要模型审视修改 -python3.7 ${cur_path}//transform_peta.py \ - --save_dir=$data_path \ - --traintest_split_file=$data_path/peta_partition.pkl - -corenum=`cat /proc/cpuinfo |grep "processor"|wc -l` -let a=RANK_ID*${corenum}/${RANK_SIZE} -let b=RANK_ID+1 -let c=b*${corenum}/${RANK_SIZE}-1 -nohup taskset -c $a-$c python3.7 ${cur_path}/train_deepmar_resnet50_8p.py \ - --addr=$(hostname -I |awk '{print $1}') \ - --save_dir=$data_path \ - --exp_dir=${test_path_dir}/output/$ASCEND_DEVICE_ID/ \ - --workers=64 \ - --batch_size=2048 \ - --new_params_lr=0.016 \ - --finetuned_params_lr=0.016 \ - --total_epochs=$train_epochs \ - --steps_per_log=1 \ - --loss_scale 512 \ - --amp \ - --opt_level O2 \ - --dist_url 'tcp://127.0.0.1:50000' \ - --dist_backend 'hccl' \ - --multiprocessing_distributed \ - --world_size 1 \ - --rank 0 \ - --epochs_per_val 40 > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -#FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` -FPS=`grep FPS ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep npu|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#打印,不需要修改 -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Step ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'loss:' '{print $2}' > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log - -if [[ $ci_cp == "1" ]];then - rm -rf $data_path - mv ${data_path}_bak $data_path +#!/bin/bash +export ASCEND_SLOG_PRINT_TO_STDOUT=0 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" +device_id=0 +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="DeepMar_ID0096_for_PyTorch" +#训练epoch +train_epochs=4 +#训练batch_size +batch_size=2048 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + + + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --ci_cp* ]];then + ci_cp=`echo ${para#*=}` + fi +done + +if [[ $ci_cp == "1" ]];then + cp -r $data_path ${data_path}_bak +fi + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +#################创建日志输出目录,不需要修改################# +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +fi +wait + + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +# 绑核,不需要的绑核的模型删除,需要模型审视修改 +python3.7 ${cur_path}//transform_peta.py \ + --save_dir=$data_path \ + --traintest_split_file=$data_path/peta_partition.pkl + +corenum=`cat /proc/cpuinfo |grep "processor"|wc -l` +let a=RANK_ID*${corenum}/${RANK_SIZE} +let b=RANK_ID+1 +let c=b*${corenum}/${RANK_SIZE}-1 +nohup taskset -c $a-$c python3.7 ${cur_path}/train_deepmar_resnet50_8p.py \ + --addr=$(hostname -I |awk '{print $1}') \ + --save_dir=$data_path \ + --exp_dir=${test_path_dir}/output/$ASCEND_DEVICE_ID/ \ + --workers=64 \ + --batch_size=2048 \ + --new_params_lr=0.016 \ + --finetuned_params_lr=0.016 \ + --total_epochs=$train_epochs \ + --steps_per_log=1 \ + --loss_scale 512 \ + --amp \ + --opt_level O2 \ + --dist_url 'tcp://127.0.0.1:50000' \ + --dist_backend 'hccl' \ + --multiprocessing_distributed \ + --world_size 1 \ + --rank 0 \ + --epochs_per_val 40 > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +#FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` +FPS=`grep FPS ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep npu|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#打印,不需要修改 +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Step ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'loss:' '{print $2}' > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log + +if [[ $ci_cp == "1" ]];then + rm -rf $data_path + mv ${data_path}_bak $data_path fi \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/convert/densenet121_pt_aipp.config b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/convert/densenet121_pt_aipp.config index daf3d557a6a8febc3bf44c862740110d711222e8..17cc1daafa93bf51c0b6fe2fecf87814ad5488c4 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/convert/densenet121_pt_aipp.config +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/convert/densenet121_pt_aipp.config @@ -1,16 +1,16 @@ -aipp_op{ - aipp_mode:static - input_format : RGB888_U8 - csc_switch : false - rbuv_swap_switch : true - - mean_chn_0: 121 - mean_chn_1: 115 - mean_chn_2: 100 - min_chn_0 : 0.0 - min_chn_1 : 0.0 - min_chn_2 : 0.0 - var_reci_chn_0 : 0.0142857142857143 - var_reci_chn_1 : 0.0147058823529412 - var_reci_chn_2 : 0.0140845070422535 -} +aipp_op{ + aipp_mode:static + input_format : RGB888_U8 + csc_switch : false + rbuv_swap_switch : true + + mean_chn_0: 121 + mean_chn_1: 115 + mean_chn_2: 100 + min_chn_0 : 0.0 + min_chn_1 : 0.0 + min_chn_2 : 0.0 + var_reci_chn_0 : 0.0142857142857143 + var_reci_chn_1 : 0.0147058823529412 + var_reci_chn_2 : 0.0140845070422535 +} diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/CMakeLists.txt b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/CMakeLists.txt index 95cb9125d47075a86686cfd8b4731d81fa48dc0f..1c3a4f0ea63b574c157b2858dd8239c4e2c1e681 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/CMakeLists.txt +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/CMakeLists.txt @@ -1,49 +1,49 @@ -cmake_minimum_required(VERSION 3.14.0) -project(densenet121) - -set(TARGET densenet121) - -add_definitions(-DENABLE_DVPP_INTERFACE) -add_compile_options(-std=c++11 -fPIE -fstack-protector-all -fPIC -Wall) -add_link_options(-Wl,-z,relro,-z,now,-z,noexecstack -s -pie) - -# Check environment variable -if(NOT DEFINED ENV{ASCEND_HOME}) - message(FATAL_ERROR "please define environment variable:ASCEND_HOME") -endif() -if(NOT DEFINED ENV{ASCEND_VERSION}) - message(WARNING "please define environment variable:ASCEND_VERSION") -endif() -if(NOT DEFINED ENV{ARCH_PATTERN}) - message(WARNING "please define environment variable:ARCH_PATTERN") -endif() -set(ACL_INC_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/include) -set(ACL_LIB_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/lib64) - -set(MXBASE_ROOT_DIR ${PROJECT_SOURCE_DIR}/../../) -set(MXBASE_INC ${MXBASE_ROOT_DIR}/mxbase/include) -set(MXBASE_LIB_DIR ${MXBASE_ROOT_DIR}/dist/lib) -set(MXBASE_POST_LIB_DIR ${MXBASE_ROOT_DIR}/dist/lib/modelpostprocessors) -set(MXBASE_POST_PROCESS_DIR ${MXBASE_ROOT_DIR}/postprocess/include) -if(DEFINED ENV{MXSDK_OPENSOURCE_DIR}) - set(OPENSOURCE_DIR $ENV{MXSDK_OPENSOURCE_DIR}) -else() - set(OPENSOURCE_DIR ${MXBASE_ROOT_DIR}/opensource/dist) -endif() - -include_directories(${ACL_INC_DIR}) -include_directories(${OPENSOURCE_DIR}/include) -include_directories(${OPENSOURCE_DIR}/include/opencv4) - -include_directories(${MXBASE_INC}) -include_directories(${MXBASE_POST_PROCESS_DIR}) - -link_directories(${ACL_LIB_DIR}) -link_directories(${OPENSOURCE_DIR}/lib) -link_directories(${MXBASE_LIB_DIR}) -link_directories(${MXBASE_POST_LIB_DIR}) - -add_executable(${TARGET} main.cpp Densenet121Classify.cpp) -target_link_libraries(${TARGET} glog cpprest mxbase resnet50postprocess stdc++fs) - -install(TARGETS ${TARGET} RUNTIME DESTINATION ${PROJECT_SOURCE_DIR}/) +cmake_minimum_required(VERSION 3.14.0) +project(densenet121) + +set(TARGET densenet121) + +add_definitions(-DENABLE_DVPP_INTERFACE) +add_compile_options(-std=c++11 -fPIE -fstack-protector-all -fPIC -Wall) +add_link_options(-Wl,-z,relro,-z,now,-z,noexecstack -s -pie) + +# Check environment variable +if(NOT DEFINED ENV{ASCEND_HOME}) + message(FATAL_ERROR "please define environment variable:ASCEND_HOME") +endif() +if(NOT DEFINED ENV{ASCEND_VERSION}) + message(WARNING "please define environment variable:ASCEND_VERSION") +endif() +if(NOT DEFINED ENV{ARCH_PATTERN}) + message(WARNING "please define environment variable:ARCH_PATTERN") +endif() +set(ACL_INC_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/include) +set(ACL_LIB_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/lib64) + +set(MXBASE_ROOT_DIR ${PROJECT_SOURCE_DIR}/../../) +set(MXBASE_INC ${MXBASE_ROOT_DIR}/mxbase/include) +set(MXBASE_LIB_DIR ${MXBASE_ROOT_DIR}/dist/lib) +set(MXBASE_POST_LIB_DIR ${MXBASE_ROOT_DIR}/dist/lib/modelpostprocessors) +set(MXBASE_POST_PROCESS_DIR ${MXBASE_ROOT_DIR}/postprocess/include) +if(DEFINED ENV{MXSDK_OPENSOURCE_DIR}) + set(OPENSOURCE_DIR $ENV{MXSDK_OPENSOURCE_DIR}) +else() + set(OPENSOURCE_DIR ${MXBASE_ROOT_DIR}/opensource/dist) +endif() + +include_directories(${ACL_INC_DIR}) +include_directories(${OPENSOURCE_DIR}/include) +include_directories(${OPENSOURCE_DIR}/include/opencv4) + +include_directories(${MXBASE_INC}) +include_directories(${MXBASE_POST_PROCESS_DIR}) + +link_directories(${ACL_LIB_DIR}) +link_directories(${OPENSOURCE_DIR}/lib) +link_directories(${MXBASE_LIB_DIR}) +link_directories(${MXBASE_POST_LIB_DIR}) + +add_executable(${TARGET} main.cpp Densenet121Classify.cpp) +target_link_libraries(${TARGET} glog cpprest mxbase resnet50postprocess stdc++fs) + +install(TARGETS ${TARGET} RUNTIME DESTINATION ${PROJECT_SOURCE_DIR}/) diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/Densenet121Classify.cpp b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/Densenet121Classify.cpp index dcd612db9c1b19f943f8cea68134c249f96e0e05..760265dbc1edf52a4520adc586afe7df2f196be9 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/Densenet121Classify.cpp +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/Densenet121Classify.cpp @@ -1,256 +1,256 @@ -/* - * Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Densenet121Classify.h" -#include "MxBase/DeviceManager/DeviceManager.h" -#include "MxBase/Log/Log.h" - -using namespace MxBase; -namespace { -const uint32_t YUV_BYTE_NU = 3; -const uint32_t YUV_BYTE_DE = 2; -const uint32_t VPC_H_ALIGN = 2; -} - -APP_ERROR Densenet121Classify::Init(const InitParam &initParam) -{ - deviceId_ = initParam.deviceId; - APP_ERROR ret = MxBase::DeviceManager::GetInstance()->InitDevices(); - if (ret != APP_ERR_OK) { - LogError << "Init devices failed, ret=" << ret << "."; - return ret; - } - ret = MxBase::TensorContext::GetInstance()->SetContext(initParam.deviceId); - if (ret != APP_ERR_OK) { - LogError << "Set context failed, ret=" << ret << "."; - return ret; - } - dvppWrapper_ = std::make_shared(); - ret = dvppWrapper_->Init(); - if (ret != APP_ERR_OK) { - LogError << "DvppWrapper init failed, ret=" << ret << "."; - return ret; - } - model_ = std::make_shared(); - ret = model_->Init(initParam.modelPath, modelDesc_); - if (ret != APP_ERR_OK) { - LogError << "ModelInferenceProcessor init failed, ret=" << ret << "."; - return ret; - } - MxBase::ConfigData configData; - const std::string softmax = initParam.softmax ? "true" : "false"; - const std::string checkTensor = initParam.checkTensor ? "true" : "false"; - - configData.SetJsonValue("CLASS_NUM", std::to_string(initParam.classNum)); - configData.SetJsonValue("TOP_K", std::to_string(initParam.topk)); - configData.SetJsonValue("SOFTMAX", softmax); - configData.SetJsonValue("CHECK_MODEL", checkTensor); - - auto jsonStr = configData.GetCfgJson().serialize(); - std::map> config; - config["postProcessConfigContent"] = std::make_shared(jsonStr); - config["labelPath"] = std::make_shared(initParam.labelPath); - - post_ = std::make_shared(); - ret = post_->Init(config); - if (ret != APP_ERR_OK) { - LogError << "Resnet50PostProcess init failed, ret=" << ret << "."; - return ret; - } - return APP_ERR_OK; -} - -APP_ERROR Densenet121Classify::DeInit() -{ - dvppWrapper_->DeInit(); - model_->DeInit(); - post_->DeInit(); - MxBase::DeviceManager::GetInstance()->DestroyDevices(); - return APP_ERR_OK; -} - -APP_ERROR Densenet121Classify::ReadImage(const std::string &imgPath, MxBase::TensorBase &tensor) -{ - MxBase::DvppDataInfo output = {}; - APP_ERROR ret = dvppWrapper_->DvppJpegDecode(imgPath, output); - if (ret != APP_ERR_OK) { - LogError << "DvppWrapper DvppJpegDecode failed, ret=" << ret << "."; - return ret; - } - MxBase::MemoryData memoryData((void*)output.data, output.dataSize, MemoryData::MemoryType::MEMORY_DVPP, deviceId_); - if (output.heightStride % VPC_H_ALIGN != 0) { - LogError << "Output data height(" << output.heightStride << ") can't be divided by " << VPC_H_ALIGN << "."; - MemoryHelper::MxbsFree(memoryData); - return APP_ERR_COMM_INVALID_PARAM; - } - std::vector shape = {output.heightStride * YUV_BYTE_NU / YUV_BYTE_DE, output.widthStride}; - tensor = TensorBase(memoryData, false, shape, TENSOR_DTYPE_UINT8); - return APP_ERR_OK; -} - -APP_ERROR Densenet121Classify::Resize(const MxBase::TensorBase &inputTensor, MxBase::TensorBase &outputTensor) -{ - auto shape = inputTensor.GetShape(); - MxBase::DvppDataInfo input = {}; - input.height = (uint32_t)shape[0] * YUV_BYTE_DE / YUV_BYTE_NU; - input.width = shape[1]; - input.heightStride = (uint32_t)shape[0] * YUV_BYTE_DE / YUV_BYTE_NU; - input.widthStride = shape[1]; - input.dataSize = inputTensor.GetByteSize(); - input.data = (uint8_t*)inputTensor.GetBuffer(); - const uint32_t resizeHeight = 304; - const uint32_t resizeWidth = 304; - MxBase::ResizeConfig resize = {}; - resize.height = resizeHeight; - resize.width = resizeWidth; - MxBase::DvppDataInfo output = {}; - APP_ERROR ret = dvppWrapper_->VpcResize(input, output, resize); - if (ret != APP_ERR_OK) { - LogError << "VpcResize failed, ret=" << ret << "."; - return ret; - } - MxBase::MemoryData memoryData((void*)output.data, output.dataSize, MemoryData::MemoryType::MEMORY_DVPP, deviceId_); - if (output.heightStride % VPC_H_ALIGN != 0) { - LogError << "Output data height(" << output.heightStride << ") can't be divided by " << VPC_H_ALIGN << "."; - MemoryHelper::MxbsFree(memoryData); - MemoryHelper::MxbsFree(memoryData); - return APP_ERR_COMM_INVALID_PARAM; - } - shape = {output.heightStride * YUV_BYTE_NU / YUV_BYTE_DE, output.widthStride}; - outputTensor = TensorBase(memoryData, false, shape, TENSOR_DTYPE_UINT8); - return APP_ERR_OK; -} - -APP_ERROR Densenet121Classify::Inference(const std::vector &inputs, - std::vector &outputs) -{ - auto dtypes = model_->GetOutputDataType(); - for (size_t i = 0; i < modelDesc_.outputTensors.size(); ++i) { - std::vector shape = {}; - for (size_t j = 0; j < modelDesc_.outputTensors[i].tensorDims.size(); ++j) { - shape.push_back((uint32_t)modelDesc_.outputTensors[i].tensorDims[j]); - } - TensorBase tensor(shape, dtypes[i], MemoryData::MemoryType::MEMORY_DEVICE, deviceId_); - APP_ERROR ret = TensorBase::TensorBaseMalloc(tensor); - if (ret != APP_ERR_OK) { - LogError << "TensorBaseMalloc failed, ret=" << ret << "."; - return ret; - } - outputs.push_back(tensor); - } - DynamicInfo dynamicInfo = {}; - dynamicInfo.dynamicType = DynamicType::STATIC_BATCH; - auto startTime = std::chrono::high_resolution_clock::now(); // search for learning - APP_ERROR ret = model_->ModelInference(inputs, outputs, dynamicInfo); - auto endTime = std::chrono::high_resolution_clock::now(); - double costMs = std::chrono::duration(endTime - startTime).count(); - g_inferCost.push_back(costMs); - if (ret != APP_ERR_OK) { - LogError << "ModelInference failed, ret=" << ret << "."; - return ret; - } - return APP_ERR_OK; -} - -APP_ERROR Densenet121Classify::PostProcess(const std::vector &inputs, - std::vector> &clsInfos) -{ - APP_ERROR ret = post_->Process(inputs, clsInfos); - if (ret != APP_ERR_OK) { - LogError << "Process failed, ret=" << ret << "."; - return ret; - } - return APP_ERR_OK; -} - -APP_ERROR Densenet121Classify::GenerateInferResult(const std::string &imgPath, - std::vector> &BatchClsInfos) -{ - uint32_t batchIndex = 0; - LogInfo << "images path: " << imgPath; - std::string fileName = imgPath.substr(imgPath.find_last_of("/") + 1); - size_t dot = fileName.find_last_of("."); - - std::string resultPathName = "result"; - if (access(resultPathName.c_str(), 0) != 0) { - int ret = mkdir(resultPathName.c_str(), S_IRUSR | S_IWUSR | S_IXUSR); - if (ret != 0) { - LogError << "Failed to create result directory: " << resultPathName << ", ret = " << ret; - return ret; - } - } - std::string resFileName = "result/" + fileName.substr(0, dot) + "_1.txt"; - LogInfo << "file path for saving result: " < inputs = {}; - std::vector outputs = {}; - inputs.push_back(resizeImage); - ret = Inference(inputs, outputs); - if (ret != APP_ERR_OK) { - LogError << "Inference failed, ret=" << ret << "."; - return ret; - } - std::vector> BatchClsInfos = {}; - ret = PostProcess(outputs, BatchClsInfos); - if (ret != APP_ERR_OK) { - LogError << "PostProcess failed, ret=" << ret << "."; - return ret; - } - ret = GenerateInferResult(imgPath, BatchClsInfos); - if (ret != APP_ERR_OK) { - LogError << "Generate infer result failed, ret=" << ret << "."; - return ret; - } - - return APP_ERR_OK; -} +/* + * Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "Densenet121Classify.h" +#include "MxBase/DeviceManager/DeviceManager.h" +#include "MxBase/Log/Log.h" + +using namespace MxBase; +namespace { +const uint32_t YUV_BYTE_NU = 3; +const uint32_t YUV_BYTE_DE = 2; +const uint32_t VPC_H_ALIGN = 2; +} + +APP_ERROR Densenet121Classify::Init(const InitParam &initParam) +{ + deviceId_ = initParam.deviceId; + APP_ERROR ret = MxBase::DeviceManager::GetInstance()->InitDevices(); + if (ret != APP_ERR_OK) { + LogError << "Init devices failed, ret=" << ret << "."; + return ret; + } + ret = MxBase::TensorContext::GetInstance()->SetContext(initParam.deviceId); + if (ret != APP_ERR_OK) { + LogError << "Set context failed, ret=" << ret << "."; + return ret; + } + dvppWrapper_ = std::make_shared(); + ret = dvppWrapper_->Init(); + if (ret != APP_ERR_OK) { + LogError << "DvppWrapper init failed, ret=" << ret << "."; + return ret; + } + model_ = std::make_shared(); + ret = model_->Init(initParam.modelPath, modelDesc_); + if (ret != APP_ERR_OK) { + LogError << "ModelInferenceProcessor init failed, ret=" << ret << "."; + return ret; + } + MxBase::ConfigData configData; + const std::string softmax = initParam.softmax ? "true" : "false"; + const std::string checkTensor = initParam.checkTensor ? "true" : "false"; + + configData.SetJsonValue("CLASS_NUM", std::to_string(initParam.classNum)); + configData.SetJsonValue("TOP_K", std::to_string(initParam.topk)); + configData.SetJsonValue("SOFTMAX", softmax); + configData.SetJsonValue("CHECK_MODEL", checkTensor); + + auto jsonStr = configData.GetCfgJson().serialize(); + std::map> config; + config["postProcessConfigContent"] = std::make_shared(jsonStr); + config["labelPath"] = std::make_shared(initParam.labelPath); + + post_ = std::make_shared(); + ret = post_->Init(config); + if (ret != APP_ERR_OK) { + LogError << "Resnet50PostProcess init failed, ret=" << ret << "."; + return ret; + } + return APP_ERR_OK; +} + +APP_ERROR Densenet121Classify::DeInit() +{ + dvppWrapper_->DeInit(); + model_->DeInit(); + post_->DeInit(); + MxBase::DeviceManager::GetInstance()->DestroyDevices(); + return APP_ERR_OK; +} + +APP_ERROR Densenet121Classify::ReadImage(const std::string &imgPath, MxBase::TensorBase &tensor) +{ + MxBase::DvppDataInfo output = {}; + APP_ERROR ret = dvppWrapper_->DvppJpegDecode(imgPath, output); + if (ret != APP_ERR_OK) { + LogError << "DvppWrapper DvppJpegDecode failed, ret=" << ret << "."; + return ret; + } + MxBase::MemoryData memoryData((void*)output.data, output.dataSize, MemoryData::MemoryType::MEMORY_DVPP, deviceId_); + if (output.heightStride % VPC_H_ALIGN != 0) { + LogError << "Output data height(" << output.heightStride << ") can't be divided by " << VPC_H_ALIGN << "."; + MemoryHelper::MxbsFree(memoryData); + return APP_ERR_COMM_INVALID_PARAM; + } + std::vector shape = {output.heightStride * YUV_BYTE_NU / YUV_BYTE_DE, output.widthStride}; + tensor = TensorBase(memoryData, false, shape, TENSOR_DTYPE_UINT8); + return APP_ERR_OK; +} + +APP_ERROR Densenet121Classify::Resize(const MxBase::TensorBase &inputTensor, MxBase::TensorBase &outputTensor) +{ + auto shape = inputTensor.GetShape(); + MxBase::DvppDataInfo input = {}; + input.height = (uint32_t)shape[0] * YUV_BYTE_DE / YUV_BYTE_NU; + input.width = shape[1]; + input.heightStride = (uint32_t)shape[0] * YUV_BYTE_DE / YUV_BYTE_NU; + input.widthStride = shape[1]; + input.dataSize = inputTensor.GetByteSize(); + input.data = (uint8_t*)inputTensor.GetBuffer(); + const uint32_t resizeHeight = 304; + const uint32_t resizeWidth = 304; + MxBase::ResizeConfig resize = {}; + resize.height = resizeHeight; + resize.width = resizeWidth; + MxBase::DvppDataInfo output = {}; + APP_ERROR ret = dvppWrapper_->VpcResize(input, output, resize); + if (ret != APP_ERR_OK) { + LogError << "VpcResize failed, ret=" << ret << "."; + return ret; + } + MxBase::MemoryData memoryData((void*)output.data, output.dataSize, MemoryData::MemoryType::MEMORY_DVPP, deviceId_); + if (output.heightStride % VPC_H_ALIGN != 0) { + LogError << "Output data height(" << output.heightStride << ") can't be divided by " << VPC_H_ALIGN << "."; + MemoryHelper::MxbsFree(memoryData); + MemoryHelper::MxbsFree(memoryData); + return APP_ERR_COMM_INVALID_PARAM; + } + shape = {output.heightStride * YUV_BYTE_NU / YUV_BYTE_DE, output.widthStride}; + outputTensor = TensorBase(memoryData, false, shape, TENSOR_DTYPE_UINT8); + return APP_ERR_OK; +} + +APP_ERROR Densenet121Classify::Inference(const std::vector &inputs, + std::vector &outputs) +{ + auto dtypes = model_->GetOutputDataType(); + for (size_t i = 0; i < modelDesc_.outputTensors.size(); ++i) { + std::vector shape = {}; + for (size_t j = 0; j < modelDesc_.outputTensors[i].tensorDims.size(); ++j) { + shape.push_back((uint32_t)modelDesc_.outputTensors[i].tensorDims[j]); + } + TensorBase tensor(shape, dtypes[i], MemoryData::MemoryType::MEMORY_DEVICE, deviceId_); + APP_ERROR ret = TensorBase::TensorBaseMalloc(tensor); + if (ret != APP_ERR_OK) { + LogError << "TensorBaseMalloc failed, ret=" << ret << "."; + return ret; + } + outputs.push_back(tensor); + } + DynamicInfo dynamicInfo = {}; + dynamicInfo.dynamicType = DynamicType::STATIC_BATCH; + auto startTime = std::chrono::high_resolution_clock::now(); // search for learning + APP_ERROR ret = model_->ModelInference(inputs, outputs, dynamicInfo); + auto endTime = std::chrono::high_resolution_clock::now(); + double costMs = std::chrono::duration(endTime - startTime).count(); + g_inferCost.push_back(costMs); + if (ret != APP_ERR_OK) { + LogError << "ModelInference failed, ret=" << ret << "."; + return ret; + } + return APP_ERR_OK; +} + +APP_ERROR Densenet121Classify::PostProcess(const std::vector &inputs, + std::vector> &clsInfos) +{ + APP_ERROR ret = post_->Process(inputs, clsInfos); + if (ret != APP_ERR_OK) { + LogError << "Process failed, ret=" << ret << "."; + return ret; + } + return APP_ERR_OK; +} + +APP_ERROR Densenet121Classify::GenerateInferResult(const std::string &imgPath, + std::vector> &BatchClsInfos) +{ + uint32_t batchIndex = 0; + LogInfo << "images path: " << imgPath; + std::string fileName = imgPath.substr(imgPath.find_last_of("/") + 1); + size_t dot = fileName.find_last_of("."); + + std::string resultPathName = "result"; + if (access(resultPathName.c_str(), 0) != 0) { + int ret = mkdir(resultPathName.c_str(), S_IRUSR | S_IWUSR | S_IXUSR); + if (ret != 0) { + LogError << "Failed to create result directory: " << resultPathName << ", ret = " << ret; + return ret; + } + } + std::string resFileName = "result/" + fileName.substr(0, dot) + "_1.txt"; + LogInfo << "file path for saving result: " < inputs = {}; + std::vector outputs = {}; + inputs.push_back(resizeImage); + ret = Inference(inputs, outputs); + if (ret != APP_ERR_OK) { + LogError << "Inference failed, ret=" << ret << "."; + return ret; + } + std::vector> BatchClsInfos = {}; + ret = PostProcess(outputs, BatchClsInfos); + if (ret != APP_ERR_OK) { + LogError << "PostProcess failed, ret=" << ret << "."; + return ret; + } + ret = GenerateInferResult(imgPath, BatchClsInfos); + if (ret != APP_ERR_OK) { + LogError << "Generate infer result failed, ret=" << ret << "."; + return ret; + } + + return APP_ERR_OK; +} diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/Densenet121Classify.h b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/Densenet121Classify.h index df1c7360e59ea1449d622ace35b9312befaa3fb6..9f36834890ffc87b18b3c5f3fac5dc72cfa424e9 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/Densenet121Classify.h +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/Densenet121Classify.h @@ -1,56 +1,56 @@ -/* - * Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MXBASE_DENSENET121CLASSIFY_H -#define MXBASE_DENSENET121CLASSIFY_H - -#include "MxBase/DvppWrapper/DvppWrapper.h" -#include "MxBase/ModelInfer/ModelInferenceProcessor.h" -#include "ClassPostProcessors/Resnet50PostProcess.h" -#include "MxBase/Tensor/TensorContext/TensorContext.h" - -extern std::vector g_inferCost; - -struct InitParam { - uint32_t deviceId; - std::string labelPath; - uint32_t classNum; - uint32_t topk; - bool softmax; - bool checkTensor; - std::string modelPath; -}; - -class Densenet121Classify { -public: - APP_ERROR Init(const InitParam &initParam); - APP_ERROR DeInit(); - APP_ERROR ReadImage(const std::string &imgPath, MxBase::TensorBase &tensor); - APP_ERROR Resize(const MxBase::TensorBase &input, MxBase::TensorBase &output); - APP_ERROR Inference(const std::vector &inputs, std::vector &outputs); - APP_ERROR PostProcess(const std::vector &inputs, - std::vector> &clsInfos); - APP_ERROR GenerateInferResult(const std::string &imgPath, - std::vector> &clsInfos); - APP_ERROR Process(const std::string &imgPath); -private: - std::shared_ptr dvppWrapper_; - std::shared_ptr model_; - std::shared_ptr post_; - MxBase::ModelDesc modelDesc_; - uint32_t deviceId_ = 0; -}; -#endif +/* + * Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MXBASE_DENSENET121CLASSIFY_H +#define MXBASE_DENSENET121CLASSIFY_H + +#include "MxBase/DvppWrapper/DvppWrapper.h" +#include "MxBase/ModelInfer/ModelInferenceProcessor.h" +#include "ClassPostProcessors/Resnet50PostProcess.h" +#include "MxBase/Tensor/TensorContext/TensorContext.h" + +extern std::vector g_inferCost; + +struct InitParam { + uint32_t deviceId; + std::string labelPath; + uint32_t classNum; + uint32_t topk; + bool softmax; + bool checkTensor; + std::string modelPath; +}; + +class Densenet121Classify { +public: + APP_ERROR Init(const InitParam &initParam); + APP_ERROR DeInit(); + APP_ERROR ReadImage(const std::string &imgPath, MxBase::TensorBase &tensor); + APP_ERROR Resize(const MxBase::TensorBase &input, MxBase::TensorBase &output); + APP_ERROR Inference(const std::vector &inputs, std::vector &outputs); + APP_ERROR PostProcess(const std::vector &inputs, + std::vector> &clsInfos); + APP_ERROR GenerateInferResult(const std::string &imgPath, + std::vector> &clsInfos); + APP_ERROR Process(const std::string &imgPath); +private: + std::shared_ptr dvppWrapper_; + std::shared_ptr model_; + std::shared_ptr post_; + MxBase::ModelDesc modelDesc_; + uint32_t deviceId_ = 0; +}; +#endif diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/main.cpp b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/main.cpp index ebf02aa12ea7e8a9f093b93df3e8b509c9f0dcc7..b4c3a9df05518dc3b3e54a91a9e88fc6985ffff4 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/main.cpp +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/mxbase_infer/main.cpp @@ -1,69 +1,69 @@ -/* - * Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include -#include "Densenet121Classify.h" -#include "MxBase/Log/Log.h" - -namespace fs = std::experimental::filesystem; -namespace { -const uint32_t CLASS_NUM = 1000; -} -std::vector g_inferCost; - -int main(int argc, char* argv[]) -{ - if (argc <= 3) { - LogWarn << "Please enter model path | image path | label path, such as './densenet121 " - "./models/densenet121_304.om ./imagenet_val/ ./models/imagenet1000_clsidx_to_labels.names"; - return APP_ERR_OK; - } - - InitParam initParam = {}; - initParam.deviceId = 0; - initParam.classNum = CLASS_NUM; - initParam.labelPath = argv[3]; - initParam.topk = 5; - initParam.softmax = false; - initParam.checkTensor = true; - initParam.modelPath = argv[1]; - auto densenet121 = std::make_shared(); - APP_ERROR ret = densenet121->Init(initParam); - if (ret != APP_ERR_OK) { - LogError << "Densenet121Classify init failed, ret=" << ret << "."; - return ret; - } - - std::string imgDir = argv[2]; - for (auto & entry : fs::directory_iterator(imgDir)) { - LogInfo << "read image path " << entry.path(); - ret = densenet121->Process(entry.path()); - if (ret != APP_ERR_OK) { - LogError << "Densenet121Classify process failed, ret=" << ret << "."; - densenet121->DeInit(); - return ret; - } - } - densenet121->DeInit(); - double costSum = 0; - for (unsigned int i = 0; i < g_inferCost.size(); i++) { - costSum += g_inferCost[i]; - } - LogInfo << "Infer images sum " << g_inferCost.size() << ", cost total time: " << costSum << " ms."; - LogInfo << "The throughout: " << g_inferCost.size() * 1000 / costSum << " images/sec."; - return APP_ERR_OK; -} +/* + * Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include "Densenet121Classify.h" +#include "MxBase/Log/Log.h" + +namespace fs = std::experimental::filesystem; +namespace { +const uint32_t CLASS_NUM = 1000; +} +std::vector g_inferCost; + +int main(int argc, char* argv[]) +{ + if (argc <= 3) { + LogWarn << "Please enter model path | image path | label path, such as './densenet121 " + "./models/densenet121_304.om ./imagenet_val/ ./models/imagenet1000_clsidx_to_labels.names"; + return APP_ERR_OK; + } + + InitParam initParam = {}; + initParam.deviceId = 0; + initParam.classNum = CLASS_NUM; + initParam.labelPath = argv[3]; + initParam.topk = 5; + initParam.softmax = false; + initParam.checkTensor = true; + initParam.modelPath = argv[1]; + auto densenet121 = std::make_shared(); + APP_ERROR ret = densenet121->Init(initParam); + if (ret != APP_ERR_OK) { + LogError << "Densenet121Classify init failed, ret=" << ret << "."; + return ret; + } + + std::string imgDir = argv[2]; + for (auto & entry : fs::directory_iterator(imgDir)) { + LogInfo << "read image path " << entry.path(); + ret = densenet121->Process(entry.path()); + if (ret != APP_ERR_OK) { + LogError << "Densenet121Classify process failed, ret=" << ret << "."; + densenet121->DeInit(); + return ret; + } + } + densenet121->DeInit(); + double costSum = 0; + for (unsigned int i = 0; i < g_inferCost.size(); i++) { + costSum += g_inferCost[i]; + } + LogInfo << "Infer images sum " << g_inferCost.size() << ", cost total time: " << costSum << " ms."; + LogInfo << "The throughout: " << g_inferCost.size() * 1000 / costSum << " images/sec."; + return APP_ERR_OK; +} diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/utils/classification_task_metric.py b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/utils/classification_task_metric.py index 9cbd93f2435e4741e1ce2e17cf1041ecf6e0d60b..afc34f0468de4ccdf7764a64d59da63e08846835 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/utils/classification_task_metric.py +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/sdk_infer/utils/classification_task_metric.py @@ -1,187 +1,187 @@ -#coding = utf-8 -#Copyright 2020 Huawei Technologies Co., Ltd -# -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -#http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - img_name = temp[0].split(".")[0] - img_lab = temp[1] - img_gt_dict[img_name] = img_lab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, cls_ind in enumerate(temp): - data_vec[ind] = np.int(cls_ind) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - res_cnt = 0 - n_labels = "" - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - - ret = load_statistical_predict_result(filepath) - - prediction = ret[0] - n_labels = ret[1] - - gt = img_gt_dict[img_name] - if n_labels == 1000: - real_label = int(gt) - elif n_labels == 1001: - real_label = int(gt) + 1 - else: - real_label = int(gt) - - res_cnt = min(len(prediction), topn) - for i in range(res_cnt): - if str(real_label) == str(int(prediction[i])): - count_hit[i] += 1 - break - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(res_cnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Please enter target file folder | groud truth file | result folder | result json file name, such as" - "Such as: python3.7 classfication_task_metric.py result/ ./val_label.txt . ./result.json") - exit(1) - - if not os.path.exists(folder_davinci_target): - print("target file folder does not exist.") - exit() - - if not os.path.exists(annotation_file_path): - - print("Ground truth file does not exist.") - exit() - - if not os.path.exists(result_json_path): - print("Result folder doesn't exist.") - exit() - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) +#coding = utf-8 +#Copyright 2020 Huawei Technologies Co., Ltd +# +#Licensed under the Apache License, Version 2.0 (the "License"); +#you may not use this file except in compliance with the License. +#You may obtain a copy of the License at +# +#http://www.apache.org/licenses/LICENSE-2.0 +# +#Unless required by applicable law or agreed to in writing, software +#distributed under the License is distributed on an "AS IS" BASIS, +#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#See the License for the specific language governing permissions and +#limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + img_name = temp[0].split(".")[0] + img_lab = temp[1] + img_gt_dict[img_name] = img_lab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, cls_ind in enumerate(temp): + data_vec[ind] = np.int(cls_ind) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + res_cnt = 0 + n_labels = "" + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + + ret = load_statistical_predict_result(filepath) + + prediction = ret[0] + n_labels = ret[1] + + gt = img_gt_dict[img_name] + if n_labels == 1000: + real_label = int(gt) + elif n_labels == 1001: + real_label = int(gt) + 1 + else: + real_label = int(gt) + + res_cnt = min(len(prediction), topn) + for i in range(res_cnt): + if str(real_label) == str(int(prediction[i])): + count_hit[i] += 1 + break + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(res_cnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Please enter target file folder | groud truth file | result folder | result json file name, such as" + "Such as: python3.7 classfication_task_metric.py result/ ./val_label.txt . ./result.json") + exit(1) + + if not os.path.exists(folder_davinci_target): + print("target file folder does not exist.") + exit() + + if not os.path.exists(annotation_file_path): + + print("Ground truth file does not exist.") + exit() + + if not os.path.exists(result_json_path): + print("Result folder doesn't exist.") + exit() + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_1p.sh b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_1p.sh index 80dcfbf8c367277369e6e12fd8d8326c59965e1b..812f8f9869291532de02ffdedcc78e6060d41460 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_1p.sh +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_1p.sh @@ -1,178 +1,178 @@ -#!/bin/bash - - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -# 数据集路径,保持为空,不需要修改 -data_path="" -device_id=0 -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="Densenet121_ID0092_for_PyTorch" -#训练epoch -train_epochs=90 -#训练batch_size -batch_size=256 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - -###############指定训练脚本执行路径############### -# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -#################创建日志输出目录,不需要修改################# -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -fi -wait - -#修改参数 -#sed -i "s|pass|break|g" ${cur_path}/../densenet121_1p_main.py -wait -#训练开始时间,不需要修改 -start_time=$(date +%s) -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi - - -#训练 -nohup python3.7 ${cur_path}/densenet121_1p_main.py \ - --workers 40 \ - --arch densenet121 \ - --npu $ASCEND_DEVICE_ID \ - --lr 0.1 \ - --momentum 0.9 \ - --amp \ - --print-freq 1 \ - --eval-freq 5 \ - --batch-size $batch_size \ - --epochs $train_epochs \ - --data $data_path > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) -#参数改回 -#sed -i "s|break|pass|g" ${cur_path}/densenet121_1p_main.py -wait -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -#FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` -FPS=`grep FPS ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'FPS@all' '{print $2}'|awk '{sum+=$1} END{print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a '* Acc@1' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "Acc@1" '{print $2}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` -` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +# 数据集路径,保持为空,不需要修改 +data_path="" +device_id=0 +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="Densenet121_ID0092_for_PyTorch" +#训练epoch +train_epochs=90 +#训练batch_size +batch_size=256 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + +###############指定训练脚本执行路径############### +# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +#################创建日志输出目录,不需要修改################# +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +fi +wait + +#修改参数 +#sed -i "s|pass|break|g" ${cur_path}/../densenet121_1p_main.py +wait +#训练开始时间,不需要修改 +start_time=$(date +%s) +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + + +#训练 +nohup python3.7 ${cur_path}/densenet121_1p_main.py \ + --workers 40 \ + --arch densenet121 \ + --npu $ASCEND_DEVICE_ID \ + --lr 0.1 \ + --momentum 0.9 \ + --amp \ + --print-freq 1 \ + --eval-freq 5 \ + --batch-size $batch_size \ + --epochs $train_epochs \ + --data $data_path > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) +#参数改回 +#sed -i "s|break|pass|g" ${cur_path}/densenet121_1p_main.py +wait +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +#FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` +FPS=`grep FPS ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'FPS@all' '{print $2}'|awk '{sum+=$1} END{print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a '* Acc@1' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "Acc@1" '{print $2}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` +` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_8p.sh b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_8p.sh index 4c8482b67c8482f936551b35b8c1b09da2be2b97..9b5a22c854fc3ca95102fff6a6cbc5a25260c5e8 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_full_8p.sh @@ -1,216 +1,216 @@ -#!/bin/bash -#集合通信参数,不需要修改 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 - - -# 数据集路径,保持为空,不需要修改 -data_path="" -device_id=0 - -#设置默认日志级别,不需要修改 -#export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="Densenet121_ID0092_for_PyTorch" -#训练epoch -train_epochs=90 -#训练batch_size -batch_size=2048 -#训练step -train_steps= -#学习率 -learning_rate= - - - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -###############指定训练脚本执行路径############### -# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - -#################创建日志输出目录,不需要修改################# -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -fi -wait - - -#训练开始时间,不需要修改 -start_time=$(date +%s) - - -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi - -if [ $(uname -m) = "aarch64" ] -then - KERNEL_NUM=$(($(nproc)/8)) - for i in $(seq 0 7) - do - PID_START=$((KERNEL_NUM * i)) - PID_END=$((PID_START + KERNEL_NUM - 1)) - nohup taskset -c $PID_START-$PID_END python3.7 ${cur_path}/densenet121_8p_main.py \ - --addr=$(hostname -I|awk '{print $1}') \ - --seed 49 \ - --workers 160 \ - --arch densenet121 \ - --lr 0.8 \ - --print-freq 1 \ - --eval-freq 5 \ - --batch-size ${batch_size} \ - --epochs ${train_epochs} \ - --dist-url 'tcp://127.0.0.1:50000' \ - --dist-backend 'hccl' \ - --multiprocessing-distributed \ - --world-size 1 \ - --rank 0 \ - --gpu $i \ - --device-list '0,1,2,3,4,5,6,7' \ - --amp \ - --benchmark 0 \ - --data $data_path > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & - done -else - for i in $(seq 0 7) - do - nohup python3.7 ${cur_path}/densenet121_8p_main.py \ - --addr=$(hostname -I|awk '{print $1}') \ - --seed 49 \ - --workers 160 \ - --arch densenet121 \ - --lr 0.8 \ - --print-freq 1 \ - --eval-freq 5 \ - --batch-size ${batch_size} \ - --epochs ${train_epochs} \ - --dist-url 'tcp://127.0.0.1:50000' \ - --dist-backend 'hccl' \ - --multiprocessing-distributed \ - --world-size 1 \ - --rank 0 \ - --gpu $i \ - --device-list '0,1,2,3,4,5,6,7' \ - --amp \ - --benchmark 0 \ - --data $data_path > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & - done -fi -wait - - - - - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -#FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` -FPS=`grep FPS ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'FPS@all' '{print $2}'|awk '{sum+=$1} END{print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a '* Acc@1' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash +#集合通信参数,不需要修改 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 + + +# 数据集路径,保持为空,不需要修改 +data_path="" +device_id=0 + +#设置默认日志级别,不需要修改 +#export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="Densenet121_ID0092_for_PyTorch" +#训练epoch +train_epochs=90 +#训练batch_size +batch_size=2048 +#训练step +train_steps= +#学习率 +learning_rate= + + + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +###############指定训练脚本执行路径############### +# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + +#################创建日志输出目录,不需要修改################# +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +fi +wait + + +#训练开始时间,不需要修改 +start_time=$(date +%s) + + +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +if [ $(uname -m) = "aarch64" ] +then + KERNEL_NUM=$(($(nproc)/8)) + for i in $(seq 0 7) + do + PID_START=$((KERNEL_NUM * i)) + PID_END=$((PID_START + KERNEL_NUM - 1)) + nohup taskset -c $PID_START-$PID_END python3.7 ${cur_path}/densenet121_8p_main.py \ + --addr=$(hostname -I|awk '{print $1}') \ + --seed 49 \ + --workers 160 \ + --arch densenet121 \ + --lr 0.8 \ + --print-freq 1 \ + --eval-freq 5 \ + --batch-size ${batch_size} \ + --epochs ${train_epochs} \ + --dist-url 'tcp://127.0.0.1:50000' \ + --dist-backend 'hccl' \ + --multiprocessing-distributed \ + --world-size 1 \ + --rank 0 \ + --gpu $i \ + --device-list '0,1,2,3,4,5,6,7' \ + --amp \ + --benchmark 0 \ + --data $data_path > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & + done +else + for i in $(seq 0 7) + do + nohup python3.7 ${cur_path}/densenet121_8p_main.py \ + --addr=$(hostname -I|awk '{print $1}') \ + --seed 49 \ + --workers 160 \ + --arch densenet121 \ + --lr 0.8 \ + --print-freq 1 \ + --eval-freq 5 \ + --batch-size ${batch_size} \ + --epochs ${train_epochs} \ + --dist-url 'tcp://127.0.0.1:50000' \ + --dist-backend 'hccl' \ + --multiprocessing-distributed \ + --world-size 1 \ + --rank 0 \ + --gpu $i \ + --device-list '0,1,2,3,4,5,6,7' \ + --amp \ + --benchmark 0 \ + --data $data_path > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & + done +fi +wait + + + + + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +#FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` +FPS=`grep FPS ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'FPS@all' '{print $2}'|awk '{sum+=$1} END{print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a '* Acc@1' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_1p.sh b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_1p.sh index 48c18be1d4927f29d56aa019aa18e8535431fe2c..806c5e634c16ca3fbd5d5323efb6c9cec6756d3a 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_1p.sh @@ -1,179 +1,179 @@ -#!/bin/bash - - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -# 数据集路径,保持为空,不需要修改 -data_path="" -device_id=0 -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="Densenet121_ID0092_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=256 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - -###############指定训练脚本执行路径############### -# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -#################创建日志输出目录,不需要修改################# -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -fi -wait - - -#修改参数 -sed -i "s|pass|break|g" ${cur_path}/densenet121_1p_main.py -wait -#训练开始时间,不需要修改 -start_time=$(date +%s) -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi - - -#训练 -nohup python3.7 ${cur_path}/densenet121_1p_main.py \ - --workers 40 \ - --arch densenet121 \ - --npu $ASCEND_DEVICE_ID \ - --lr 0.1 \ - --momentum 0.9 \ - --amp \ - --print-freq 1 \ - --eval-freq 5 \ - --batch-size $batch_size \ - --epochs $train_epochs \ - --stop-step-num 50 \ - --data $data_path > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) -#参数改回 -sed -i "s|break|pass|g" ${cur_path}/densenet121_1p_main.py -wait -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -#FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` -FPS=`grep FPS ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'FPS@all' '{print $2}'|awk '{sum+=$1} END{print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +# 数据集路径,保持为空,不需要修改 +data_path="" +device_id=0 +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="Densenet121_ID0092_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=256 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + +###############指定训练脚本执行路径############### +# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +#################创建日志输出目录,不需要修改################# +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +fi +wait + + +#修改参数 +sed -i "s|pass|break|g" ${cur_path}/densenet121_1p_main.py +wait +#训练开始时间,不需要修改 +start_time=$(date +%s) +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + + +#训练 +nohup python3.7 ${cur_path}/densenet121_1p_main.py \ + --workers 40 \ + --arch densenet121 \ + --npu $ASCEND_DEVICE_ID \ + --lr 0.1 \ + --momentum 0.9 \ + --amp \ + --print-freq 1 \ + --eval-freq 5 \ + --batch-size $batch_size \ + --epochs $train_epochs \ + --stop-step-num 50 \ + --data $data_path > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) +#参数改回 +sed -i "s|break|pass|g" ${cur_path}/densenet121_1p_main.py +wait +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +#FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` +FPS=`grep FPS ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'FPS@all' '{print $2}'|awk '{sum+=$1} END{print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_8p.sh index 0175d3c3e47253f5c5a152b4164108521b25bd31..7c638cfe7cbbea319ab16b226103960baaad6cb1 100644 --- a/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch/test/train_performance_8p.sh @@ -1,222 +1,222 @@ -#!/bin/bash - -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 - -export SOC_VERSION=Ascend910 -export HCCL_CONNECT_TIMEOUT=600 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" -device_id=0 - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP_ETP_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="Densenet121_ID0092_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=2048 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - - - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -###############指定训练脚本执行路径############### -# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - -#################创建日志输出目录,不需要修改################# -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -fi -wait - -#修改参数 -sed -i "s|pass|break|g" ${cur_path}/densenet121_8p_main.py -wait -#训练开始时间,不需要修改 -start_time=$(date +%s) - - -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi - -if [ $(uname -m) = "aarch64" ] -then - KERNEL_NUM=$(($(nproc)/8)) - for i in $(seq 0 7) - do - PID_START=$((KERNEL_NUM * i)) - PID_END=$((PID_START + KERNEL_NUM - 1)) - nohup taskset -c $PID_START-$PID_END python3.7 ${cur_path}/densenet121_8p_main.py \ - --addr=$(hostname -I|awk '{print $1}') \ - --seed 49 \ - --workers 160 \ - --arch densenet121 \ - --lr 0.8 \ - --print-freq 1 \ - --eval-freq 5 \ - --batch-size ${batch_size} \ - --epochs ${train_epochs} \ - --dist-url 'tcp://127.0.0.1:50000' \ - --dist-backend 'hccl' \ - --multiprocessing-distributed \ - --world-size 1 \ - --rank 0 \ - --gpu $i \ - --device-list '0,1,2,3,4,5,6,7' \ - --amp \ - --benchmark 0 \ - --data $data_path > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & - done -else - for i in $(seq 0 7) - do - nohup python3.7 ${cur_path}/densenet121_8p_main.py \ - --addr=$(hostname -I|awk '{print $1}') \ - --seed 49 \ - --workers 160 \ - --arch densenet121 \ - --lr 0.8 \ - --print-freq 1 \ - --eval-freq 5 \ - --batch-size ${batch_size} \ - --epochs ${train_epochs} \ - --dist-url 'tcp://127.0.0.1:50000' \ - --dist-backend 'hccl' \ - --multiprocessing-distributed \ - --world-size 1 \ - --rank 0 \ - --gpu $i \ - --device-list '0,1,2,3,4,5,6,7' \ - --amp \ - --benchmark 0 \ - --data $data_path > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & - done -fi -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) -#参数改回 -sed -i "s|break|pass|g" ${cur_path}/densenet121_8p_main.py -wait -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -#FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` -FPS=`grep FPS ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'FPS@all' '{print $2}'|awk '{sum+=$1} END{print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 + +export SOC_VERSION=Ascend910 +export HCCL_CONNECT_TIMEOUT=600 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" +device_id=0 + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP_ETP_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="Densenet121_ID0092_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=2048 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + + + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +###############指定训练脚本执行路径############### +# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + +#################创建日志输出目录,不需要修改################# +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +fi +wait + +#修改参数 +sed -i "s|pass|break|g" ${cur_path}/densenet121_8p_main.py +wait +#训练开始时间,不需要修改 +start_time=$(date +%s) + + +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +if [ $(uname -m) = "aarch64" ] +then + KERNEL_NUM=$(($(nproc)/8)) + for i in $(seq 0 7) + do + PID_START=$((KERNEL_NUM * i)) + PID_END=$((PID_START + KERNEL_NUM - 1)) + nohup taskset -c $PID_START-$PID_END python3.7 ${cur_path}/densenet121_8p_main.py \ + --addr=$(hostname -I|awk '{print $1}') \ + --seed 49 \ + --workers 160 \ + --arch densenet121 \ + --lr 0.8 \ + --print-freq 1 \ + --eval-freq 5 \ + --batch-size ${batch_size} \ + --epochs ${train_epochs} \ + --dist-url 'tcp://127.0.0.1:50000' \ + --dist-backend 'hccl' \ + --multiprocessing-distributed \ + --world-size 1 \ + --rank 0 \ + --gpu $i \ + --device-list '0,1,2,3,4,5,6,7' \ + --amp \ + --benchmark 0 \ + --data $data_path > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & + done +else + for i in $(seq 0 7) + do + nohup python3.7 ${cur_path}/densenet121_8p_main.py \ + --addr=$(hostname -I|awk '{print $1}') \ + --seed 49 \ + --workers 160 \ + --arch densenet121 \ + --lr 0.8 \ + --print-freq 1 \ + --eval-freq 5 \ + --batch-size ${batch_size} \ + --epochs ${train_epochs} \ + --dist-url 'tcp://127.0.0.1:50000' \ + --dist-backend 'hccl' \ + --multiprocessing-distributed \ + --world-size 1 \ + --rank 0 \ + --gpu $i \ + --device-list '0,1,2,3,4,5,6,7' \ + --amp \ + --benchmark 0 \ + --data $data_path > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & + done +fi +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) +#参数改回 +sed -i "s|break|pass|g" ${cur_path}/densenet121_8p_main.py +wait +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +#FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` +FPS=`grep FPS ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'FPS@all' '{print $2}'|awk '{sum+=$1} END{print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/LICENSE b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/LICENSE index 75b52484ea471f882c29e02693b4f02dba175b5e..d645695673349e3947e8e5ae42332d0ac3164cd7 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/LICENSE +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/LICENSE @@ -1,202 +1,202 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/__init__.py b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/__init__.py index 1046fb2b297682ca0c57fa16b23e9070050709a0..d475531251fe2eaa98d1af9430c603f42609e8a9 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/__init__.py +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/__init__.py @@ -1,228 +1,228 @@ -# Apache License -# Version 2.0, January 2004 -# http://www.apache.org/licenses/ -# -# TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION -# -# 1. Definitions. -# -# "License" shall mean the terms and conditions for use, reproduction, -# and distribution as defined by Sections 1 through 9 of this document. -# -# "Licensor" shall mean the copyright owner or entity authorized by -# the copyright owner that is granting the License. -# -# "Legal Entity" shall mean the union of the acting entity and all -# other entities that control, are controlled by, or are under common -# control with that entity. For the purposes of this definition, -# "control" means (i) the power, direct or indirect, to cause the -# direction or management of such entity, whether by contract or -# otherwise, or (ii) ownership of fifty percent (50%) or more of the -# outstanding shares, or (iii) beneficial ownership of such entity. -# -# "You" (or "Your") shall mean an individual or Legal Entity -# exercising permissions granted by this License. -# -# "Source" form shall mean the preferred form for making modifications, -# including but not limited to software source code, documentation -# source, and configuration files. -# -# "Object" form shall mean any form resulting from mechanical -# transformation or translation of a Source form, including but -# not limited to compiled object code, generated documentation, -# and conversions to other media types. -# -# "Work" shall mean the work of authorship, whether in Source or -# Object form, made available under the License, as indicated by a -# copyright notice that is included in or attached to the work -# (an example is provided in the Appendix below). -# -# "Derivative Works" shall mean any work, whether in Source or Object -# form, that is based on (or derived from) the Work and for which the -# editorial revisions, annotations, elaborations, or other modifications -# represent, as a whole, an original work of authorship. For the purposes -# of this License, Derivative Works shall not include works that remain -# separable from, or merely link (or bind by name) to the interfaces of, -# the Work and Derivative Works thereof. -# -# "Contribution" shall mean any work of authorship, including -# the original version of the Work and any modifications or additions -# to that Work or Derivative Works thereof, that is intentionally -# submitted to Licensor for inclusion in the Work by the copyright owner -# or by an individual or Legal Entity authorized to submit on behalf of -# the copyright owner. For the purposes of this definition, "submitted" -# means any form of electronic, verbal, or written communication sent -# to the Licensor or its representatives, including but not limited to -# communication on electronic mailing lists, source code control systems, -# and issue tracking systems that are managed by, or on behalf of, the -# Licensor for the purpose of discussing and improving the Work, but -# excluding communication that is conspicuously marked or otherwise -# designated in writing by the copyright owner as "Not a Contribution." -# -# "Contributor" shall mean Licensor and any individual or Legal Entity -# on behalf of whom a Contribution has been received by Licensor and -# subsequently incorporated within the Work. -# -# 2. Grant of Copyright License. Subject to the terms and conditions of -# this License, each Contributor hereby grants to You a perpetual, -# worldwide, non-exclusive, no-charge, royalty-free, irrevocable -# copyright license to reproduce, prepare Derivative Works of, -# publicly display, publicly perform, sublicense, and distribute the -# Work and such Derivative Works in Source or Object form. -# -# 3. Grant of Patent License. Subject to the terms and conditions of -# this License, each Contributor hereby grants to You a perpetual, -# worldwide, non-exclusive, no-charge, royalty-free, irrevocable -# (except as stated in this section) patent license to make, have made, -# use, offer to sell, sell, import, and otherwise transfer the Work, -# where such license applies only to those patent claims licensable -# by such Contributor that are necessarily infringed by their -# Contribution(s) alone or by combination of their Contribution(s) -# with the Work to which such Contribution(s) was submitted. If You -# institute patent litigation against any entity (including a -# cross-claim or counterclaim in a lawsuit) alleging that the Work -# or a Contribution incorporated within the Work constitutes direct -# or contributory patent infringement, then any patent licenses -# granted to You under this License for that Work shall terminate -# as of the date such litigation is filed. -# -# 4. Redistribution. You may reproduce and distribute copies of the -# Work or Derivative Works thereof in any medium, with or without -# modifications, and in Source or Object form, provided that You -# meet the following conditions: -# -# (a) You must give any other recipients of the Work or -# Derivative Works a copy of this License; and -# -# (b) You must cause any modified files to carry prominent notices -# stating that You changed the files; and -# -# (c) You must retain, in the Source form of any Derivative Works -# that You distribute, all copyright, patent, trademark, and -# attribution notices from the Source form of the Work, -# excluding those notices that do not pertain to any part of -# the Derivative Works; and -# -# (d) If the Work includes a "NOTICE" text file as part of its -# distribution, then any Derivative Works that You distribute must -# include a readable copy of the attribution notices contained -# within such NOTICE file, excluding those notices that do not -# pertain to any part of the Derivative Works, in at least one -# of the following places: within a NOTICE text file distributed -# as part of the Derivative Works; within the Source form or -# documentation, if provided along with the Derivative Works; or, -# within a display generated by the Derivative Works, if and -# wherever such third-party notices normally appear. The contents -# of the NOTICE file are for informational purposes only and -# do not modify the License. You may add Your own attribution -# notices within Derivative Works that You distribute, alongside -# or as an addendum to the NOTICE text from the Work, provided -# that such additional attribution notices cannot be construed -# as modifying the License. -# -# You may add Your own copyright statement to Your modifications and -# may provide additional or different license terms and conditions -# for use, reproduction, or distribution of Your modifications, or -# for any such Derivative Works as a whole, provided Your use, -# reproduction, and distribution of the Work otherwise complies with -# the conditions stated in this License. -# -# 5. Submission of Contributions. Unless You explicitly state otherwise, -# any Contribution intentionally submitted for inclusion in the Work -# by You to the Licensor shall be under the terms and conditions of -# this License, without any additional terms or conditions. -# Notwithstanding the above, nothing herein shall supersede or modify -# the terms of any separate license agreement you may have executed -# with Licensor regarding such Contributions. -# -# 6. Trademarks. This License does not grant permission to use the trade -# names, trademarks, service marks, or product names of the Licensor, -# except as required for reasonable and customary use in describing the -# origin of the Work and reproducing the content of the NOTICE file. -# -# 7. Disclaimer of Warranty. Unless required by applicable law or -# agreed to in writing, Licensor provides the Work (and each -# Contributor provides its Contributions) on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied, including, without limitation, any warranties or conditions -# of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A -# PARTICULAR PURPOSE. You are solely responsible for determining the -# appropriateness of using or redistributing the Work and assume any -# risks associated with Your exercise of permissions under this License. -# -# 8. Limitation of Liability. In no event and under no legal theory, -# whether in tort (including negligence), contract, or otherwise, -# unless required by applicable law (such as deliberate and grossly -# negligent acts) or agreed to in writing, shall any Contributor be -# liable to You for damages, including any direct, indirect, special, -# incidental, or consequential damages of any character arising as a -# result of this License or out of the use or inability to use the -# Work (including but not limited to damages for loss of goodwill, -# work stoppage, computer failure or malfunction, or any and all -# other commercial damages or losses), even if such Contributor -# has been advised of the possibility of such damages. -# -# 9. Accepting Warranty or Additional Liability. While redistributing -# the Work or Derivative Works thereof, You may choose to offer, -# and charge a fee for, acceptance of support, warranty, indemnity, -# or other liability obligations and/or rights consistent with this -# License. However, in accepting such obligations, You may act only -# on Your own behalf and on Your sole responsibility, not on behalf -# of any other Contributor, and only if You agree to indemnify, -# defend, and hold each Contributor harmless for any liability -# incurred by, or claims asserted against, such Contributor by reason -# of your accepting any such warranty or additional liability. -# -# END OF TERMS AND CONDITIONS -# -# APPENDIX: How to apply the Apache License to your work. -# -# To apply the Apache License to your work, attach the following -# boilerplate notice, with the fields enclosed by brackets "[]" -# replaced with your own identifying information. (Don't include -# the brackets!) The text should be enclosed in the appropriate -# comment syntax for the file format. We also recommend that a -# file or class name and description of purpose be included on the -# same "printed page" as the copyright notice for easier -# identification within third-party archives. -# -# Copyright [yyyy] [name of copyright owner] -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -__version__ = "0.7.0" -from .model import EfficientNet -from .utils import ( - GlobalParams, - BlockArgs, - BlockDecoder, - efficientnet, - get_model_params, -) -from .auto_augment import rand_augment_transform, augment_and_mix_transform, auto_augment_transform -from .rmsprop_tf import RMSpropTF - +# Apache License +# Version 2.0, January 2004 +# http://www.apache.org/licenses/ +# +# TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION +# +# 1. Definitions. +# +# "License" shall mean the terms and conditions for use, reproduction, +# and distribution as defined by Sections 1 through 9 of this document. +# +# "Licensor" shall mean the copyright owner or entity authorized by +# the copyright owner that is granting the License. +# +# "Legal Entity" shall mean the union of the acting entity and all +# other entities that control, are controlled by, or are under common +# control with that entity. For the purposes of this definition, +# "control" means (i) the power, direct or indirect, to cause the +# direction or management of such entity, whether by contract or +# otherwise, or (ii) ownership of fifty percent (50%) or more of the +# outstanding shares, or (iii) beneficial ownership of such entity. +# +# "You" (or "Your") shall mean an individual or Legal Entity +# exercising permissions granted by this License. +# +# "Source" form shall mean the preferred form for making modifications, +# including but not limited to software source code, documentation +# source, and configuration files. +# +# "Object" form shall mean any form resulting from mechanical +# transformation or translation of a Source form, including but +# not limited to compiled object code, generated documentation, +# and conversions to other media types. +# +# "Work" shall mean the work of authorship, whether in Source or +# Object form, made available under the License, as indicated by a +# copyright notice that is included in or attached to the work +# (an example is provided in the Appendix below). +# +# "Derivative Works" shall mean any work, whether in Source or Object +# form, that is based on (or derived from) the Work and for which the +# editorial revisions, annotations, elaborations, or other modifications +# represent, as a whole, an original work of authorship. For the purposes +# of this License, Derivative Works shall not include works that remain +# separable from, or merely link (or bind by name) to the interfaces of, +# the Work and Derivative Works thereof. +# +# "Contribution" shall mean any work of authorship, including +# the original version of the Work and any modifications or additions +# to that Work or Derivative Works thereof, that is intentionally +# submitted to Licensor for inclusion in the Work by the copyright owner +# or by an individual or Legal Entity authorized to submit on behalf of +# the copyright owner. For the purposes of this definition, "submitted" +# means any form of electronic, verbal, or written communication sent +# to the Licensor or its representatives, including but not limited to +# communication on electronic mailing lists, source code control systems, +# and issue tracking systems that are managed by, or on behalf of, the +# Licensor for the purpose of discussing and improving the Work, but +# excluding communication that is conspicuously marked or otherwise +# designated in writing by the copyright owner as "Not a Contribution." +# +# "Contributor" shall mean Licensor and any individual or Legal Entity +# on behalf of whom a Contribution has been received by Licensor and +# subsequently incorporated within the Work. +# +# 2. Grant of Copyright License. Subject to the terms and conditions of +# this License, each Contributor hereby grants to You a perpetual, +# worldwide, non-exclusive, no-charge, royalty-free, irrevocable +# copyright license to reproduce, prepare Derivative Works of, +# publicly display, publicly perform, sublicense, and distribute the +# Work and such Derivative Works in Source or Object form. +# +# 3. Grant of Patent License. Subject to the terms and conditions of +# this License, each Contributor hereby grants to You a perpetual, +# worldwide, non-exclusive, no-charge, royalty-free, irrevocable +# (except as stated in this section) patent license to make, have made, +# use, offer to sell, sell, import, and otherwise transfer the Work, +# where such license applies only to those patent claims licensable +# by such Contributor that are necessarily infringed by their +# Contribution(s) alone or by combination of their Contribution(s) +# with the Work to which such Contribution(s) was submitted. If You +# institute patent litigation against any entity (including a +# cross-claim or counterclaim in a lawsuit) alleging that the Work +# or a Contribution incorporated within the Work constitutes direct +# or contributory patent infringement, then any patent licenses +# granted to You under this License for that Work shall terminate +# as of the date such litigation is filed. +# +# 4. Redistribution. You may reproduce and distribute copies of the +# Work or Derivative Works thereof in any medium, with or without +# modifications, and in Source or Object form, provided that You +# meet the following conditions: +# +# (a) You must give any other recipients of the Work or +# Derivative Works a copy of this License; and +# +# (b) You must cause any modified files to carry prominent notices +# stating that You changed the files; and +# +# (c) You must retain, in the Source form of any Derivative Works +# that You distribute, all copyright, patent, trademark, and +# attribution notices from the Source form of the Work, +# excluding those notices that do not pertain to any part of +# the Derivative Works; and +# +# (d) If the Work includes a "NOTICE" text file as part of its +# distribution, then any Derivative Works that You distribute must +# include a readable copy of the attribution notices contained +# within such NOTICE file, excluding those notices that do not +# pertain to any part of the Derivative Works, in at least one +# of the following places: within a NOTICE text file distributed +# as part of the Derivative Works; within the Source form or +# documentation, if provided along with the Derivative Works; or, +# within a display generated by the Derivative Works, if and +# wherever such third-party notices normally appear. The contents +# of the NOTICE file are for informational purposes only and +# do not modify the License. You may add Your own attribution +# notices within Derivative Works that You distribute, alongside +# or as an addendum to the NOTICE text from the Work, provided +# that such additional attribution notices cannot be construed +# as modifying the License. +# +# You may add Your own copyright statement to Your modifications and +# may provide additional or different license terms and conditions +# for use, reproduction, or distribution of Your modifications, or +# for any such Derivative Works as a whole, provided Your use, +# reproduction, and distribution of the Work otherwise complies with +# the conditions stated in this License. +# +# 5. Submission of Contributions. Unless You explicitly state otherwise, +# any Contribution intentionally submitted for inclusion in the Work +# by You to the Licensor shall be under the terms and conditions of +# this License, without any additional terms or conditions. +# Notwithstanding the above, nothing herein shall supersede or modify +# the terms of any separate license agreement you may have executed +# with Licensor regarding such Contributions. +# +# 6. Trademarks. This License does not grant permission to use the trade +# names, trademarks, service marks, or product names of the Licensor, +# except as required for reasonable and customary use in describing the +# origin of the Work and reproducing the content of the NOTICE file. +# +# 7. Disclaimer of Warranty. Unless required by applicable law or +# agreed to in writing, Licensor provides the Work (and each +# Contributor provides its Contributions) on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied, including, without limitation, any warranties or conditions +# of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +# PARTICULAR PURPOSE. You are solely responsible for determining the +# appropriateness of using or redistributing the Work and assume any +# risks associated with Your exercise of permissions under this License. +# +# 8. Limitation of Liability. In no event and under no legal theory, +# whether in tort (including negligence), contract, or otherwise, +# unless required by applicable law (such as deliberate and grossly +# negligent acts) or agreed to in writing, shall any Contributor be +# liable to You for damages, including any direct, indirect, special, +# incidental, or consequential damages of any character arising as a +# result of this License or out of the use or inability to use the +# Work (including but not limited to damages for loss of goodwill, +# work stoppage, computer failure or malfunction, or any and all +# other commercial damages or losses), even if such Contributor +# has been advised of the possibility of such damages. +# +# 9. Accepting Warranty or Additional Liability. While redistributing +# the Work or Derivative Works thereof, You may choose to offer, +# and charge a fee for, acceptance of support, warranty, indemnity, +# or other liability obligations and/or rights consistent with this +# License. However, in accepting such obligations, You may act only +# on Your own behalf and on Your sole responsibility, not on behalf +# of any other Contributor, and only if You agree to indemnify, +# defend, and hold each Contributor harmless for any liability +# incurred by, or claims asserted against, such Contributor by reason +# of your accepting any such warranty or additional liability. +# +# END OF TERMS AND CONDITIONS +# +# APPENDIX: How to apply the Apache License to your work. +# +# To apply the Apache License to your work, attach the following +# boilerplate notice, with the fields enclosed by brackets "[]" +# replaced with your own identifying information. (Don't include +# the brackets!) The text should be enclosed in the appropriate +# comment syntax for the file format. We also recommend that a +# file or class name and description of purpose be included on the +# same "printed page" as the copyright notice for easier +# identification within third-party archives. +# +# Copyright [yyyy] [name of copyright owner] +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +__version__ = "0.7.0" +from .model import EfficientNet +from .utils import ( + GlobalParams, + BlockArgs, + BlockDecoder, + efficientnet, + get_model_params, +) +from .auto_augment import rand_augment_transform, augment_and_mix_transform, auto_augment_transform +from .rmsprop_tf import RMSpropTF + diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/auto_augment.py b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/auto_augment.py index e063d63e1aeae9df0d05ea5700dfcfd6f0a6b2ef..071c49771c542fba51f958b38dabd0283857df13 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/auto_augment.py +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/auto_augment.py @@ -1,813 +1,813 @@ -# Copyright [yyyy] [name of copyright owner] -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import random -import math -import re -from PIL import Image, ImageOps, ImageEnhance, ImageChops -import PIL -import numpy as np - - -_PIL_VER = tuple([int(x) for x in PIL.__version__.split('.')[:2]]) - -_FILL = (128, 128, 128) - -# This signifies the max integer that the controller RNN could predict for the -# augmentation scheme. -_MAX_LEVEL = 10. - -_HPARAMS_DEFAULT = dict( - translate_const=250, - img_mean=_FILL, -) - -_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC) - - -def _interpolation(kwargs): - interpolation = kwargs.pop('resample', Image.BILINEAR) - if isinstance(interpolation, (list, tuple)): - return random.choice(interpolation) - else: - return interpolation - - -def _check_args_tf(kwargs): - if 'fillcolor' in kwargs and _PIL_VER < (5, 0): - kwargs.pop('fillcolor') - kwargs['resample'] = _interpolation(kwargs) - - -def shear_x(img, factor, **kwargs): - _check_args_tf(kwargs) - return img.transform(img.size, Image.AFFINE, (1, factor, 0, 0, 1, 0), **kwargs) - - -def shear_y(img, factor, **kwargs): - _check_args_tf(kwargs) - return img.transform(img.size, Image.AFFINE, (1, 0, 0, factor, 1, 0), **kwargs) - - -def translate_x_rel(img, pct, **kwargs): - pixels = pct * img.size[0] - _check_args_tf(kwargs) - return img.transform(img.size, Image.AFFINE, (1, 0, pixels, 0, 1, 0), **kwargs) - - -def translate_y_rel(img, pct, **kwargs): - pixels = pct * img.size[1] - _check_args_tf(kwargs) - return img.transform(img.size, Image.AFFINE, (1, 0, 0, 0, 1, pixels), **kwargs) - - -def translate_x_abs(img, pixels, **kwargs): - _check_args_tf(kwargs) - return img.transform(img.size, Image.AFFINE, (1, 0, pixels, 0, 1, 0), **kwargs) - - -def translate_y_abs(img, pixels, **kwargs): - _check_args_tf(kwargs) - return img.transform(img.size, Image.AFFINE, (1, 0, 0, 0, 1, pixels), **kwargs) - - -def rotate(img, degrees, **kwargs): - _check_args_tf(kwargs) - if _PIL_VER >= (5, 2): - return img.rotate(degrees, **kwargs) - elif _PIL_VER >= (5, 0): - w, h = img.size - post_trans = (0, 0) - rotn_center = (w / 2.0, h / 2.0) - angle = -math.radians(degrees) - matrix = [ - round(math.cos(angle), 15), - round(math.sin(angle), 15), - 0.0, - round(-math.sin(angle), 15), - round(math.cos(angle), 15), - 0.0, - ] - - def transform(x, y, matrix): - (a, b, c, d, e, f) = matrix - return a * x + b * y + c, d * x + e * y + f - - matrix[2], matrix[5] = transform( - -rotn_center[0] - post_trans[0], -rotn_center[1] - post_trans[1], matrix - ) - matrix[2] += rotn_center[0] - matrix[5] += rotn_center[1] - return img.transform(img.size, Image.AFFINE, matrix, **kwargs) - else: - return img.rotate(degrees, resample=kwargs['resample']) - - -def auto_contrast(img, **__): - return ImageOps.autocontrast(img) - - -def invert(img, **__): - return ImageOps.invert(img) - - -def equalize(img, **__): - return ImageOps.equalize(img) - - -def solarize(img, thresh, **__): - return ImageOps.solarize(img, thresh) - - -def solarize_add(img, add, thresh=128, **__): - lut = [] - for i in range(256): - if i < thresh: - lut.append(min(255, i + add)) - else: - lut.append(i) - if img.mode in ("L", "RGB"): - if img.mode == "RGB" and len(lut) == 256: - lut = lut + lut + lut - return img.point(lut) - else: - return img - - -def posterize(img, bits_to_keep, **__): - if bits_to_keep >= 8: - return img - return ImageOps.posterize(img, bits_to_keep) - - -def contrast(img, factor, **__): - return ImageEnhance.Contrast(img).enhance(factor) - - -def color(img, factor, **__): - return ImageEnhance.Color(img).enhance(factor) - - -def brightness(img, factor, **__): - return ImageEnhance.Brightness(img).enhance(factor) - - -def sharpness(img, factor, **__): - return ImageEnhance.Sharpness(img).enhance(factor) - - -def _randomly_negate(v): - """With 50% prob, negate the value""" - return -v if random.random() > 0.5 else v - - -def _rotate_level_to_arg(level, _hparams): - # range [-30, 30] - level = (level / _MAX_LEVEL) * 30. - level = _randomly_negate(level) - return level, - - -def _enhance_level_to_arg(level, _hparams): - # range [0.1, 1.9] - return (level / _MAX_LEVEL) * 1.8 + 0.1, - - -def _enhance_increasing_level_to_arg(level, _hparams): - # the 'no change' level is 1.0, moving away from that towards 0. or 2.0 increases the enhancement blend - # range [0.1, 1.9] - level = (level / _MAX_LEVEL) * .9 - level = 1.0 + _randomly_negate(level) - return level, - - -def _shear_level_to_arg(level, _hparams): - # range [-0.3, 0.3] - level = (level / _MAX_LEVEL) * 0.3 - level = _randomly_negate(level) - return level, - - -def _translate_abs_level_to_arg(level, hparams): - translate_const = hparams['translate_const'] - level = (level / _MAX_LEVEL) * float(translate_const) - level = _randomly_negate(level) - return level, - - -def _translate_rel_level_to_arg(level, hparams): - # default range [-0.45, 0.45] - translate_pct = hparams.get('translate_pct', 0.45) - level = (level / _MAX_LEVEL) * translate_pct - level = _randomly_negate(level) - return level, - - -def _posterize_level_to_arg(level, _hparams): - # As per Tensorflow TPU EfficientNet impl - # range [0, 4], 'keep 0 up to 4 MSB of original image' - # intensity/severity of augmentation decreases with level - return int((level / _MAX_LEVEL) * 4), - - -def _posterize_increasing_level_to_arg(level, hparams): - # As per Tensorflow models research and UDA impl - # range [4, 0], 'keep 4 down to 0 MSB of original image', - # intensity/severity of augmentation increases with level - return 4 - _posterize_level_to_arg(level, hparams)[0], - - -def _posterize_original_level_to_arg(level, _hparams): - # As per original AutoAugment paper description - # range [4, 8], 'keep 4 up to 8 MSB of image' - # intensity/severity of augmentation decreases with level - return int((level / _MAX_LEVEL) * 4) + 4, - - -def _solarize_level_to_arg(level, _hparams): - # range [0, 256] - # intensity/severity of augmentation decreases with level - return int((level / _MAX_LEVEL) * 256), - - -def _solarize_increasing_level_to_arg(level, _hparams): - # range [0, 256] - # intensity/severity of augmentation increases with level - return 256 - _solarize_level_to_arg(level, _hparams)[0], - - -def _solarize_add_level_to_arg(level, _hparams): - # range [0, 110] - return int((level / _MAX_LEVEL) * 110), - - -LEVEL_TO_ARG = { - 'AutoContrast': None, - 'Equalize': None, - 'Invert': None, - 'Rotate': _rotate_level_to_arg, - # There are several variations of the posterize level scaling in various Tensorflow/Google repositories/papers - 'Posterize': _posterize_level_to_arg, - 'PosterizeIncreasing': _posterize_increasing_level_to_arg, - 'PosterizeOriginal': _posterize_original_level_to_arg, - 'Solarize': _solarize_level_to_arg, - 'SolarizeIncreasing': _solarize_increasing_level_to_arg, - 'SolarizeAdd': _solarize_add_level_to_arg, - 'Color': _enhance_level_to_arg, - 'ColorIncreasing': _enhance_increasing_level_to_arg, - 'Contrast': _enhance_level_to_arg, - 'ContrastIncreasing': _enhance_increasing_level_to_arg, - 'Brightness': _enhance_level_to_arg, - 'BrightnessIncreasing': _enhance_increasing_level_to_arg, - 'Sharpness': _enhance_level_to_arg, - 'SharpnessIncreasing': _enhance_increasing_level_to_arg, - 'ShearX': _shear_level_to_arg, - 'ShearY': _shear_level_to_arg, - 'TranslateX': _translate_abs_level_to_arg, - 'TranslateY': _translate_abs_level_to_arg, - 'TranslateXRel': _translate_rel_level_to_arg, - 'TranslateYRel': _translate_rel_level_to_arg, -} - - -NAME_TO_OP = { - 'AutoContrast': auto_contrast, - 'Equalize': equalize, - 'Invert': invert, - 'Rotate': rotate, - 'Posterize': posterize, - 'PosterizeIncreasing': posterize, - 'PosterizeOriginal': posterize, - 'Solarize': solarize, - 'SolarizeIncreasing': solarize, - 'SolarizeAdd': solarize_add, - 'Color': color, - 'ColorIncreasing': color, - 'Contrast': contrast, - 'ContrastIncreasing': contrast, - 'Brightness': brightness, - 'BrightnessIncreasing': brightness, - 'Sharpness': sharpness, - 'SharpnessIncreasing': sharpness, - 'ShearX': shear_x, - 'ShearY': shear_y, - 'TranslateX': translate_x_abs, - 'TranslateY': translate_y_abs, - 'TranslateXRel': translate_x_rel, - 'TranslateYRel': translate_y_rel, -} - - -class AugmentOp: - - def __init__(self, name, prob=0.5, magnitude=10, hparams=None): - hparams = hparams or _HPARAMS_DEFAULT - self.aug_fn = NAME_TO_OP[name] - self.level_fn = LEVEL_TO_ARG[name] - self.prob = prob - self.magnitude = magnitude - self.hparams = hparams.copy() - self.kwargs = dict( - fillcolor=hparams['img_mean'] if 'img_mean' in hparams else _FILL, - resample=hparams['interpolation'] if 'interpolation' in hparams else _RANDOM_INTERPOLATION, - ) - - # If magnitude_std is > 0, we introduce some randomness - # in the usually fixed policy and sample magnitude from a normal distribution - # with mean `magnitude` and std-dev of `magnitude_std`. - # NOTE This is my own hack, being tested, not in papers or reference impls. - self.magnitude_std = self.hparams.get('magnitude_std', 0) - - def __call__(self, img): - if self.prob < 1.0 and random.random() > self.prob: - return img - magnitude = self.magnitude - if self.magnitude_std and self.magnitude_std > 0: - magnitude = random.gauss(magnitude, self.magnitude_std) - magnitude = min(_MAX_LEVEL, max(0, magnitude)) # clip to valid range - level_args = self.level_fn(magnitude, self.hparams) if self.level_fn is not None else tuple() - return self.aug_fn(img, *level_args, **self.kwargs) - - -def auto_augment_policy_v0(hparams): - # ImageNet v0 policy from TPU EfficientNet impl, cannot find a paper reference. - policy = [ - [('Equalize', 0.8, 1), ('ShearY', 0.8, 4)], - [('Color', 0.4, 9), ('Equalize', 0.6, 3)], - [('Color', 0.4, 1), ('Rotate', 0.6, 8)], - [('Solarize', 0.8, 3), ('Equalize', 0.4, 7)], - [('Solarize', 0.4, 2), ('Solarize', 0.6, 2)], - [('Color', 0.2, 0), ('Equalize', 0.8, 8)], - [('Equalize', 0.4, 8), ('SolarizeAdd', 0.8, 3)], - [('ShearX', 0.2, 9), ('Rotate', 0.6, 8)], - [('Color', 0.6, 1), ('Equalize', 1.0, 2)], - [('Invert', 0.4, 9), ('Rotate', 0.6, 0)], - [('Equalize', 1.0, 9), ('ShearY', 0.6, 3)], - [('Color', 0.4, 7), ('Equalize', 0.6, 0)], - [('Posterize', 0.4, 6), ('AutoContrast', 0.4, 7)], - [('Solarize', 0.6, 8), ('Color', 0.6, 9)], - [('Solarize', 0.2, 4), ('Rotate', 0.8, 9)], - [('Rotate', 1.0, 7), ('TranslateYRel', 0.8, 9)], - [('ShearX', 0.0, 0), ('Solarize', 0.8, 4)], - [('ShearY', 0.8, 0), ('Color', 0.6, 4)], - [('Color', 1.0, 0), ('Rotate', 0.6, 2)], - [('Equalize', 0.8, 4), ('Equalize', 0.0, 8)], - [('Equalize', 1.0, 4), ('AutoContrast', 0.6, 2)], - [('ShearY', 0.4, 7), ('SolarizeAdd', 0.6, 7)], - [('Posterize', 0.8, 2), ('Solarize', 0.6, 10)], # This results in black image with Tpu posterize - [('Solarize', 0.6, 8), ('Equalize', 0.6, 1)], - [('Color', 0.8, 6), ('Rotate', 0.4, 5)], - ] - pc = [[AugmentOp(*a, hparams=hparams) for a in sp] for sp in policy] - return pc - - -def auto_augment_policy_v0r(hparams): - # ImageNet v0 policy from TPU EfficientNet impl, with variation of Posterize used - # in Google research implementation (number of bits discarded increases with magnitude) - policy = [ - [('Equalize', 0.8, 1), ('ShearY', 0.8, 4)], - [('Color', 0.4, 9), ('Equalize', 0.6, 3)], - [('Color', 0.4, 1), ('Rotate', 0.6, 8)], - [('Solarize', 0.8, 3), ('Equalize', 0.4, 7)], - [('Solarize', 0.4, 2), ('Solarize', 0.6, 2)], - [('Color', 0.2, 0), ('Equalize', 0.8, 8)], - [('Equalize', 0.4, 8), ('SolarizeAdd', 0.8, 3)], - [('ShearX', 0.2, 9), ('Rotate', 0.6, 8)], - [('Color', 0.6, 1), ('Equalize', 1.0, 2)], - [('Invert', 0.4, 9), ('Rotate', 0.6, 0)], - [('Equalize', 1.0, 9), ('ShearY', 0.6, 3)], - [('Color', 0.4, 7), ('Equalize', 0.6, 0)], - [('PosterizeIncreasing', 0.4, 6), ('AutoContrast', 0.4, 7)], - [('Solarize', 0.6, 8), ('Color', 0.6, 9)], - [('Solarize', 0.2, 4), ('Rotate', 0.8, 9)], - [('Rotate', 1.0, 7), ('TranslateYRel', 0.8, 9)], - [('ShearX', 0.0, 0), ('Solarize', 0.8, 4)], - [('ShearY', 0.8, 0), ('Color', 0.6, 4)], - [('Color', 1.0, 0), ('Rotate', 0.6, 2)], - [('Equalize', 0.8, 4), ('Equalize', 0.0, 8)], - [('Equalize', 1.0, 4), ('AutoContrast', 0.6, 2)], - [('ShearY', 0.4, 7), ('SolarizeAdd', 0.6, 7)], - [('PosterizeIncreasing', 0.8, 2), ('Solarize', 0.6, 10)], - [('Solarize', 0.6, 8), ('Equalize', 0.6, 1)], - [('Color', 0.8, 6), ('Rotate', 0.4, 5)], - ] - pc = [[AugmentOp(*a, hparams=hparams) for a in sp] for sp in policy] - return pc - - -def auto_augment_policy_original(hparams): - # ImageNet policy from https://arxiv.org/abs/1805.09501 - policy = [ - [('PosterizeOriginal', 0.4, 8), ('Rotate', 0.6, 9)], - [('Solarize', 0.6, 5), ('AutoContrast', 0.6, 5)], - [('Equalize', 0.8, 8), ('Equalize', 0.6, 3)], - [('PosterizeOriginal', 0.6, 7), ('PosterizeOriginal', 0.6, 6)], - [('Equalize', 0.4, 7), ('Solarize', 0.2, 4)], - [('Equalize', 0.4, 4), ('Rotate', 0.8, 8)], - [('Solarize', 0.6, 3), ('Equalize', 0.6, 7)], - [('PosterizeOriginal', 0.8, 5), ('Equalize', 1.0, 2)], - [('Rotate', 0.2, 3), ('Solarize', 0.6, 8)], - [('Equalize', 0.6, 8), ('PosterizeOriginal', 0.4, 6)], - [('Rotate', 0.8, 8), ('Color', 0.4, 0)], - [('Rotate', 0.4, 9), ('Equalize', 0.6, 2)], - [('Equalize', 0.0, 7), ('Equalize', 0.8, 8)], - [('Invert', 0.6, 4), ('Equalize', 1.0, 8)], - [('Color', 0.6, 4), ('Contrast', 1.0, 8)], - [('Rotate', 0.8, 8), ('Color', 1.0, 2)], - [('Color', 0.8, 8), ('Solarize', 0.8, 7)], - [('Sharpness', 0.4, 7), ('Invert', 0.6, 8)], - [('ShearX', 0.6, 5), ('Equalize', 1.0, 9)], - [('Color', 0.4, 0), ('Equalize', 0.6, 3)], - [('Equalize', 0.4, 7), ('Solarize', 0.2, 4)], - [('Solarize', 0.6, 5), ('AutoContrast', 0.6, 5)], - [('Invert', 0.6, 4), ('Equalize', 1.0, 8)], - [('Color', 0.6, 4), ('Contrast', 1.0, 8)], - [('Equalize', 0.8, 8), ('Equalize', 0.6, 3)], - ] - pc = [[AugmentOp(*a, hparams=hparams) for a in sp] for sp in policy] - return pc - - -def auto_augment_policy_originalr(hparams): - # ImageNet policy from https://arxiv.org/abs/1805.09501 with research posterize variation - policy = [ - [('PosterizeIncreasing', 0.4, 8), ('Rotate', 0.6, 9)], - [('Solarize', 0.6, 5), ('AutoContrast', 0.6, 5)], - [('Equalize', 0.8, 8), ('Equalize', 0.6, 3)], - [('PosterizeIncreasing', 0.6, 7), ('PosterizeIncreasing', 0.6, 6)], - [('Equalize', 0.4, 7), ('Solarize', 0.2, 4)], - [('Equalize', 0.4, 4), ('Rotate', 0.8, 8)], - [('Solarize', 0.6, 3), ('Equalize', 0.6, 7)], - [('PosterizeIncreasing', 0.8, 5), ('Equalize', 1.0, 2)], - [('Rotate', 0.2, 3), ('Solarize', 0.6, 8)], - [('Equalize', 0.6, 8), ('PosterizeIncreasing', 0.4, 6)], - [('Rotate', 0.8, 8), ('Color', 0.4, 0)], - [('Rotate', 0.4, 9), ('Equalize', 0.6, 2)], - [('Equalize', 0.0, 7), ('Equalize', 0.8, 8)], - [('Invert', 0.6, 4), ('Equalize', 1.0, 8)], - [('Color', 0.6, 4), ('Contrast', 1.0, 8)], - [('Rotate', 0.8, 8), ('Color', 1.0, 2)], - [('Color', 0.8, 8), ('Solarize', 0.8, 7)], - [('Sharpness', 0.4, 7), ('Invert', 0.6, 8)], - [('ShearX', 0.6, 5), ('Equalize', 1.0, 9)], - [('Color', 0.4, 0), ('Equalize', 0.6, 3)], - [('Equalize', 0.4, 7), ('Solarize', 0.2, 4)], - [('Solarize', 0.6, 5), ('AutoContrast', 0.6, 5)], - [('Invert', 0.6, 4), ('Equalize', 1.0, 8)], - [('Color', 0.6, 4), ('Contrast', 1.0, 8)], - [('Equalize', 0.8, 8), ('Equalize', 0.6, 3)], - ] - pc = [[AugmentOp(*a, hparams=hparams) for a in sp] for sp in policy] - return pc - - -def auto_augment_policy(name='v0', hparams=None): - hparams = hparams or _HPARAMS_DEFAULT - if name == 'original': - return auto_augment_policy_original(hparams) - elif name == 'originalr': - return auto_augment_policy_originalr(hparams) - elif name == 'v0': - return auto_augment_policy_v0(hparams) - elif name == 'v0r': - return auto_augment_policy_v0r(hparams) - else: - assert False, 'Unknown AA policy (%s)' % name - - -class AutoAugment: - - def __init__(self, policy): - self.policy = policy - - def __call__(self, img): - sub_policy = random.choice(self.policy) - for op in sub_policy: - img = op(img) - return img - - -def auto_augment_transform(config_str, hparams): - """ - Create a AutoAugment transform - - :param config_str: String defining configuration of auto augmentation. Consists of multiple sections separated by - dashes ('-'). The first section defines the AutoAugment policy (one of 'v0', 'v0r', 'original', 'originalr'). - The remaining sections, not order sepecific determine - 'mstd' - float std deviation of magnitude noise applied - Ex 'original-mstd0.5' results in AutoAugment with original policy, magnitude_std 0.5 - - :param hparams: Other hparams (kwargs) for the AutoAugmentation scheme - - :return: A PyTorch compatible Transform - """ - config = config_str.split('-') - policy_name = config[0] - config = config[1:] - for c in config: - cs = re.split(r'(\d.*)', c) - if len(cs) < 2: - continue - key, val = cs[:2] - if key == 'mstd': - # noise param injected via hparams for now - hparams.setdefault('magnitude_std', float(val)) - else: - assert False, 'Unknown AutoAugment config section' - aa_policy = auto_augment_policy(policy_name, hparams=hparams) - return AutoAugment(aa_policy) - - -_RAND_TRANSFORMS = [ - 'AutoContrast', - 'Equalize', - 'Invert', - 'Rotate', - 'Posterize', - 'Solarize', - 'SolarizeAdd', - 'Color', - 'Contrast', - 'Brightness', - 'Sharpness', - 'ShearX', - 'ShearY', - 'TranslateXRel', - 'TranslateYRel', - #'Cutout' # NOTE I've implement this as random erasing separately -] - - -_RAND_INCREASING_TRANSFORMS = [ - 'AutoContrast', - 'Equalize', - 'Invert', - 'Rotate', - 'PosterizeIncreasing', - 'SolarizeIncreasing', - 'SolarizeAdd', - 'ColorIncreasing', - 'ContrastIncreasing', - 'BrightnessIncreasing', - 'SharpnessIncreasing', - 'ShearX', - 'ShearY', - 'TranslateXRel', - 'TranslateYRel', - #'Cutout' # NOTE I've implement this as random erasing separately -] - - - -# These experimental weights are based loosely on the relative improvements mentioned in paper. -# They may not result in increased performance, but could likely be tuned to so. -_RAND_CHOICE_WEIGHTS_0 = { - 'Rotate': 0.3, - 'ShearX': 0.2, - 'ShearY': 0.2, - 'TranslateXRel': 0.1, - 'TranslateYRel': 0.1, - 'Color': .025, - 'Sharpness': 0.025, - 'AutoContrast': 0.025, - 'Solarize': .005, - 'SolarizeAdd': .005, - 'Contrast': .005, - 'Brightness': .005, - 'Equalize': .005, - 'Posterize': 0, - 'Invert': 0, -} - - -def _select_rand_weights(weight_idx=0, transforms=None): - transforms = transforms or _RAND_TRANSFORMS - assert weight_idx == 0 # only one set of weights currently - rand_weights = _RAND_CHOICE_WEIGHTS_0 - probs = [rand_weights[k] for k in transforms] - probs /= np.sum(probs) - return probs - - -def rand_augment_ops(magnitude=10, hparams=None, transforms=None): - hparams = hparams or _HPARAMS_DEFAULT - transforms = transforms or _RAND_TRANSFORMS - return [AugmentOp( - name, prob=0.5, magnitude=magnitude, hparams=hparams) for name in transforms] - - -class RandAugment: - def __init__(self, ops, num_layers=2, choice_weights=None): - self.ops = ops - self.num_layers = num_layers - self.choice_weights = choice_weights - - def __call__(self, img): - # no replacement when using weighted choice - ops = np.random.choice( - self.ops, self.num_layers, replace=self.choice_weights is None, p=self.choice_weights) - for op in ops: - img = op(img) - return img - - -def rand_augment_transform(config_str, hparams): - """ - Create a RandAugment transform - - :param config_str: String defining configuration of random augmentation. Consists of multiple sections separated by - dashes ('-'). The first section defines the specific variant of rand augment (currently only 'rand'). The remaining - sections, not order sepecific determine - 'm' - integer magnitude of rand augment - 'n' - integer num layers (number of transform ops selected per image) - 'w' - integer probabiliy weight index (index of a set of weights to influence choice of op) - 'mstd' - float std deviation of magnitude noise applied - 'inc' - integer (bool), use augmentations that increase in severity with magnitude (default: 0) - Ex 'rand-m9-n3-mstd0.5' results in RandAugment with magnitude 9, num_layers 3, magnitude_std 0.5 - 'rand-mstd1-w0' results in magnitude_std 1.0, weights 0, default magnitude of 10 and num_layers 2 - - :param hparams: Other hparams (kwargs) for the RandAugmentation scheme - - :return: A PyTorch compatible Transform - """ - magnitude = _MAX_LEVEL # default to _MAX_LEVEL for magnitude (currently 10) - num_layers = 2 # default to 2 ops per image - weight_idx = None # default to no probability weights for op choice - transforms = _RAND_TRANSFORMS - config = config_str.split('-') - assert config[0] == 'rand' - config = config[1:] - for c in config: - cs = re.split(r'(\d.*)', c) - if len(cs) < 2: - continue - key, val = cs[:2] - if key == 'mstd': - # noise param injected via hparams for now - hparams.setdefault('magnitude_std', float(val)) - elif key == 'inc': - if bool(val): - transforms = _RAND_INCREASING_TRANSFORMS - elif key == 'm': - magnitude = int(val) - elif key == 'n': - num_layers = int(val) - elif key == 'w': - weight_idx = int(val) - else: - assert False, 'Unknown RandAugment config section' - ra_ops = rand_augment_ops(magnitude=magnitude, hparams=hparams, transforms=transforms) - choice_weights = None if weight_idx is None else _select_rand_weights(weight_idx) - return RandAugment(ra_ops, num_layers, choice_weights=choice_weights) - - -_AUGMIX_TRANSFORMS = [ - 'AutoContrast', - 'ColorIncreasing', # not in paper - 'ContrastIncreasing', # not in paper - 'BrightnessIncreasing', # not in paper - 'SharpnessIncreasing', # not in paper - 'Equalize', - 'Rotate', - 'PosterizeIncreasing', - 'SolarizeIncreasing', - 'ShearX', - 'ShearY', - 'TranslateXRel', - 'TranslateYRel', -] - - -def augmix_ops(magnitude=10, hparams=None, transforms=None): - hparams = hparams or _HPARAMS_DEFAULT - transforms = transforms or _AUGMIX_TRANSFORMS - return [AugmentOp( - name, prob=1.0, magnitude=magnitude, hparams=hparams) for name in transforms] - - -class AugMixAugment: - """ AugMix Transform - Adapted and improved from impl here: https://github.com/google-research/augmix/blob/master/imagenet.py - From paper: 'AugMix: A Simple Data Processing Method to Improve Robustness and Uncertainty - - https://arxiv.org/abs/1912.02781 - """ - def __init__(self, ops, alpha=1., width=3, depth=-1, blended=False): - self.ops = ops - self.alpha = alpha - self.width = width - self.depth = depth - self.blended = blended # blended mode is faster but not well tested - - def _calc_blended_weights(self, ws, m): - ws = ws * m - cump = 1. - rws = [] - for w in ws[::-1]: - alpha = w / cump - cump *= (1 - alpha) - rws.append(alpha) - return np.array(rws[::-1], dtype=np.float32) - - def _apply_blended(self, img, mixing_weights, m): - # This is my first crack and implementing a slightly faster mixed augmentation. Instead - # of accumulating the mix for each chain in a Numpy array and then blending with original, - # it recomputes the blending coefficients and applies one PIL image blend per chain. - # TODO the results appear in the right ballpark but they differ by more than rounding. - img_orig = img.copy() - ws = self._calc_blended_weights(mixing_weights, m) - for w in ws: - depth = self.depth if self.depth > 0 else np.random.randint(1, 4) - ops = np.random.choice(self.ops, depth, replace=True) - img_aug = img_orig # no ops are in-place, deep copy not necessary - for op in ops: - img_aug = op(img_aug) - img = Image.blend(img, img_aug, w) - return img - - def _apply_basic(self, img, mixing_weights, m): - # This is a literal adaptation of the paper/official implementation without normalizations and - # PIL <-> Numpy conversions between every op. It is still quite CPU compute heavy compared to the - # typical augmentation transforms, could use a GPU / Kornia implementation. - img_shape = img.size[0], img.size[1], len(img.getbands()) - mixed = np.zeros(img_shape, dtype=np.float32) - for mw in mixing_weights: - depth = self.depth if self.depth > 0 else np.random.randint(1, 4) - ops = np.random.choice(self.ops, depth, replace=True) - img_aug = img # no ops are in-place, deep copy not necessary - for op in ops: - img_aug = op(img_aug) - mixed += mw * np.asarray(img_aug, dtype=np.float32) - np.clip(mixed, 0, 255., out=mixed) - mixed = Image.fromarray(mixed.astype(np.uint8)) - return Image.blend(img, mixed, m) - - def __call__(self, img): - mixing_weights = np.float32(np.random.dirichlet([self.alpha] * self.width)) - m = np.float32(np.random.beta(self.alpha, self.alpha)) - if self.blended: - mixed = self._apply_blended(img, mixing_weights, m) - else: - mixed = self._apply_basic(img, mixing_weights, m) - return mixed - - -def augment_and_mix_transform(config_str, hparams): - """ Create AugMix PyTorch transform - - :param config_str: String defining configuration of random augmentation. Consists of multiple sections separated by - dashes ('-'). The first section defines the specific variant of rand augment (currently only 'rand'). The remaining - sections, not order sepecific determine - 'm' - integer magnitude (severity) of augmentation mix (default: 3) - 'w' - integer width of augmentation chain (default: 3) - 'd' - integer depth of augmentation chain (-1 is random [1, 3], default: -1) - 'b' - integer (bool), blend each branch of chain into end result without a final blend, less CPU (default: 0) - 'mstd' - float std deviation of magnitude noise applied (default: 0) - Ex 'augmix-m5-w4-d2' results in AugMix with severity 5, chain width 4, chain depth 2 - - :param hparams: Other hparams (kwargs) for the Augmentation transforms - - :return: A PyTorch compatible Transform - """ - magnitude = 3 - width = 3 - depth = -1 - alpha = 1. - blended = False - config = config_str.split('-') - assert config[0] == 'augmix' - config = config[1:] - for c in config: - cs = re.split(r'(\d.*)', c) - if len(cs) < 2: - continue - key, val = cs[:2] - if key == 'mstd': - # noise param injected via hparams for now - hparams.setdefault('magnitude_std', float(val)) - elif key == 'm': - magnitude = int(val) - elif key == 'w': - width = int(val) - elif key == 'd': - depth = int(val) - elif key == 'a': - alpha = float(val) - elif key == 'b': - blended = bool(val) - else: - assert False, 'Unknown AugMix config section' - ops = augmix_ops(magnitude=magnitude, hparams=hparams) +# Copyright [yyyy] [name of copyright owner] +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import random +import math +import re +from PIL import Image, ImageOps, ImageEnhance, ImageChops +import PIL +import numpy as np + + +_PIL_VER = tuple([int(x) for x in PIL.__version__.split('.')[:2]]) + +_FILL = (128, 128, 128) + +# This signifies the max integer that the controller RNN could predict for the +# augmentation scheme. +_MAX_LEVEL = 10. + +_HPARAMS_DEFAULT = dict( + translate_const=250, + img_mean=_FILL, +) + +_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC) + + +def _interpolation(kwargs): + interpolation = kwargs.pop('resample', Image.BILINEAR) + if isinstance(interpolation, (list, tuple)): + return random.choice(interpolation) + else: + return interpolation + + +def _check_args_tf(kwargs): + if 'fillcolor' in kwargs and _PIL_VER < (5, 0): + kwargs.pop('fillcolor') + kwargs['resample'] = _interpolation(kwargs) + + +def shear_x(img, factor, **kwargs): + _check_args_tf(kwargs) + return img.transform(img.size, Image.AFFINE, (1, factor, 0, 0, 1, 0), **kwargs) + + +def shear_y(img, factor, **kwargs): + _check_args_tf(kwargs) + return img.transform(img.size, Image.AFFINE, (1, 0, 0, factor, 1, 0), **kwargs) + + +def translate_x_rel(img, pct, **kwargs): + pixels = pct * img.size[0] + _check_args_tf(kwargs) + return img.transform(img.size, Image.AFFINE, (1, 0, pixels, 0, 1, 0), **kwargs) + + +def translate_y_rel(img, pct, **kwargs): + pixels = pct * img.size[1] + _check_args_tf(kwargs) + return img.transform(img.size, Image.AFFINE, (1, 0, 0, 0, 1, pixels), **kwargs) + + +def translate_x_abs(img, pixels, **kwargs): + _check_args_tf(kwargs) + return img.transform(img.size, Image.AFFINE, (1, 0, pixels, 0, 1, 0), **kwargs) + + +def translate_y_abs(img, pixels, **kwargs): + _check_args_tf(kwargs) + return img.transform(img.size, Image.AFFINE, (1, 0, 0, 0, 1, pixels), **kwargs) + + +def rotate(img, degrees, **kwargs): + _check_args_tf(kwargs) + if _PIL_VER >= (5, 2): + return img.rotate(degrees, **kwargs) + elif _PIL_VER >= (5, 0): + w, h = img.size + post_trans = (0, 0) + rotn_center = (w / 2.0, h / 2.0) + angle = -math.radians(degrees) + matrix = [ + round(math.cos(angle), 15), + round(math.sin(angle), 15), + 0.0, + round(-math.sin(angle), 15), + round(math.cos(angle), 15), + 0.0, + ] + + def transform(x, y, matrix): + (a, b, c, d, e, f) = matrix + return a * x + b * y + c, d * x + e * y + f + + matrix[2], matrix[5] = transform( + -rotn_center[0] - post_trans[0], -rotn_center[1] - post_trans[1], matrix + ) + matrix[2] += rotn_center[0] + matrix[5] += rotn_center[1] + return img.transform(img.size, Image.AFFINE, matrix, **kwargs) + else: + return img.rotate(degrees, resample=kwargs['resample']) + + +def auto_contrast(img, **__): + return ImageOps.autocontrast(img) + + +def invert(img, **__): + return ImageOps.invert(img) + + +def equalize(img, **__): + return ImageOps.equalize(img) + + +def solarize(img, thresh, **__): + return ImageOps.solarize(img, thresh) + + +def solarize_add(img, add, thresh=128, **__): + lut = [] + for i in range(256): + if i < thresh: + lut.append(min(255, i + add)) + else: + lut.append(i) + if img.mode in ("L", "RGB"): + if img.mode == "RGB" and len(lut) == 256: + lut = lut + lut + lut + return img.point(lut) + else: + return img + + +def posterize(img, bits_to_keep, **__): + if bits_to_keep >= 8: + return img + return ImageOps.posterize(img, bits_to_keep) + + +def contrast(img, factor, **__): + return ImageEnhance.Contrast(img).enhance(factor) + + +def color(img, factor, **__): + return ImageEnhance.Color(img).enhance(factor) + + +def brightness(img, factor, **__): + return ImageEnhance.Brightness(img).enhance(factor) + + +def sharpness(img, factor, **__): + return ImageEnhance.Sharpness(img).enhance(factor) + + +def _randomly_negate(v): + """With 50% prob, negate the value""" + return -v if random.random() > 0.5 else v + + +def _rotate_level_to_arg(level, _hparams): + # range [-30, 30] + level = (level / _MAX_LEVEL) * 30. + level = _randomly_negate(level) + return level, + + +def _enhance_level_to_arg(level, _hparams): + # range [0.1, 1.9] + return (level / _MAX_LEVEL) * 1.8 + 0.1, + + +def _enhance_increasing_level_to_arg(level, _hparams): + # the 'no change' level is 1.0, moving away from that towards 0. or 2.0 increases the enhancement blend + # range [0.1, 1.9] + level = (level / _MAX_LEVEL) * .9 + level = 1.0 + _randomly_negate(level) + return level, + + +def _shear_level_to_arg(level, _hparams): + # range [-0.3, 0.3] + level = (level / _MAX_LEVEL) * 0.3 + level = _randomly_negate(level) + return level, + + +def _translate_abs_level_to_arg(level, hparams): + translate_const = hparams['translate_const'] + level = (level / _MAX_LEVEL) * float(translate_const) + level = _randomly_negate(level) + return level, + + +def _translate_rel_level_to_arg(level, hparams): + # default range [-0.45, 0.45] + translate_pct = hparams.get('translate_pct', 0.45) + level = (level / _MAX_LEVEL) * translate_pct + level = _randomly_negate(level) + return level, + + +def _posterize_level_to_arg(level, _hparams): + # As per Tensorflow TPU EfficientNet impl + # range [0, 4], 'keep 0 up to 4 MSB of original image' + # intensity/severity of augmentation decreases with level + return int((level / _MAX_LEVEL) * 4), + + +def _posterize_increasing_level_to_arg(level, hparams): + # As per Tensorflow models research and UDA impl + # range [4, 0], 'keep 4 down to 0 MSB of original image', + # intensity/severity of augmentation increases with level + return 4 - _posterize_level_to_arg(level, hparams)[0], + + +def _posterize_original_level_to_arg(level, _hparams): + # As per original AutoAugment paper description + # range [4, 8], 'keep 4 up to 8 MSB of image' + # intensity/severity of augmentation decreases with level + return int((level / _MAX_LEVEL) * 4) + 4, + + +def _solarize_level_to_arg(level, _hparams): + # range [0, 256] + # intensity/severity of augmentation decreases with level + return int((level / _MAX_LEVEL) * 256), + + +def _solarize_increasing_level_to_arg(level, _hparams): + # range [0, 256] + # intensity/severity of augmentation increases with level + return 256 - _solarize_level_to_arg(level, _hparams)[0], + + +def _solarize_add_level_to_arg(level, _hparams): + # range [0, 110] + return int((level / _MAX_LEVEL) * 110), + + +LEVEL_TO_ARG = { + 'AutoContrast': None, + 'Equalize': None, + 'Invert': None, + 'Rotate': _rotate_level_to_arg, + # There are several variations of the posterize level scaling in various Tensorflow/Google repositories/papers + 'Posterize': _posterize_level_to_arg, + 'PosterizeIncreasing': _posterize_increasing_level_to_arg, + 'PosterizeOriginal': _posterize_original_level_to_arg, + 'Solarize': _solarize_level_to_arg, + 'SolarizeIncreasing': _solarize_increasing_level_to_arg, + 'SolarizeAdd': _solarize_add_level_to_arg, + 'Color': _enhance_level_to_arg, + 'ColorIncreasing': _enhance_increasing_level_to_arg, + 'Contrast': _enhance_level_to_arg, + 'ContrastIncreasing': _enhance_increasing_level_to_arg, + 'Brightness': _enhance_level_to_arg, + 'BrightnessIncreasing': _enhance_increasing_level_to_arg, + 'Sharpness': _enhance_level_to_arg, + 'SharpnessIncreasing': _enhance_increasing_level_to_arg, + 'ShearX': _shear_level_to_arg, + 'ShearY': _shear_level_to_arg, + 'TranslateX': _translate_abs_level_to_arg, + 'TranslateY': _translate_abs_level_to_arg, + 'TranslateXRel': _translate_rel_level_to_arg, + 'TranslateYRel': _translate_rel_level_to_arg, +} + + +NAME_TO_OP = { + 'AutoContrast': auto_contrast, + 'Equalize': equalize, + 'Invert': invert, + 'Rotate': rotate, + 'Posterize': posterize, + 'PosterizeIncreasing': posterize, + 'PosterizeOriginal': posterize, + 'Solarize': solarize, + 'SolarizeIncreasing': solarize, + 'SolarizeAdd': solarize_add, + 'Color': color, + 'ColorIncreasing': color, + 'Contrast': contrast, + 'ContrastIncreasing': contrast, + 'Brightness': brightness, + 'BrightnessIncreasing': brightness, + 'Sharpness': sharpness, + 'SharpnessIncreasing': sharpness, + 'ShearX': shear_x, + 'ShearY': shear_y, + 'TranslateX': translate_x_abs, + 'TranslateY': translate_y_abs, + 'TranslateXRel': translate_x_rel, + 'TranslateYRel': translate_y_rel, +} + + +class AugmentOp: + + def __init__(self, name, prob=0.5, magnitude=10, hparams=None): + hparams = hparams or _HPARAMS_DEFAULT + self.aug_fn = NAME_TO_OP[name] + self.level_fn = LEVEL_TO_ARG[name] + self.prob = prob + self.magnitude = magnitude + self.hparams = hparams.copy() + self.kwargs = dict( + fillcolor=hparams['img_mean'] if 'img_mean' in hparams else _FILL, + resample=hparams['interpolation'] if 'interpolation' in hparams else _RANDOM_INTERPOLATION, + ) + + # If magnitude_std is > 0, we introduce some randomness + # in the usually fixed policy and sample magnitude from a normal distribution + # with mean `magnitude` and std-dev of `magnitude_std`. + # NOTE This is my own hack, being tested, not in papers or reference impls. + self.magnitude_std = self.hparams.get('magnitude_std', 0) + + def __call__(self, img): + if self.prob < 1.0 and random.random() > self.prob: + return img + magnitude = self.magnitude + if self.magnitude_std and self.magnitude_std > 0: + magnitude = random.gauss(magnitude, self.magnitude_std) + magnitude = min(_MAX_LEVEL, max(0, magnitude)) # clip to valid range + level_args = self.level_fn(magnitude, self.hparams) if self.level_fn is not None else tuple() + return self.aug_fn(img, *level_args, **self.kwargs) + + +def auto_augment_policy_v0(hparams): + # ImageNet v0 policy from TPU EfficientNet impl, cannot find a paper reference. + policy = [ + [('Equalize', 0.8, 1), ('ShearY', 0.8, 4)], + [('Color', 0.4, 9), ('Equalize', 0.6, 3)], + [('Color', 0.4, 1), ('Rotate', 0.6, 8)], + [('Solarize', 0.8, 3), ('Equalize', 0.4, 7)], + [('Solarize', 0.4, 2), ('Solarize', 0.6, 2)], + [('Color', 0.2, 0), ('Equalize', 0.8, 8)], + [('Equalize', 0.4, 8), ('SolarizeAdd', 0.8, 3)], + [('ShearX', 0.2, 9), ('Rotate', 0.6, 8)], + [('Color', 0.6, 1), ('Equalize', 1.0, 2)], + [('Invert', 0.4, 9), ('Rotate', 0.6, 0)], + [('Equalize', 1.0, 9), ('ShearY', 0.6, 3)], + [('Color', 0.4, 7), ('Equalize', 0.6, 0)], + [('Posterize', 0.4, 6), ('AutoContrast', 0.4, 7)], + [('Solarize', 0.6, 8), ('Color', 0.6, 9)], + [('Solarize', 0.2, 4), ('Rotate', 0.8, 9)], + [('Rotate', 1.0, 7), ('TranslateYRel', 0.8, 9)], + [('ShearX', 0.0, 0), ('Solarize', 0.8, 4)], + [('ShearY', 0.8, 0), ('Color', 0.6, 4)], + [('Color', 1.0, 0), ('Rotate', 0.6, 2)], + [('Equalize', 0.8, 4), ('Equalize', 0.0, 8)], + [('Equalize', 1.0, 4), ('AutoContrast', 0.6, 2)], + [('ShearY', 0.4, 7), ('SolarizeAdd', 0.6, 7)], + [('Posterize', 0.8, 2), ('Solarize', 0.6, 10)], # This results in black image with Tpu posterize + [('Solarize', 0.6, 8), ('Equalize', 0.6, 1)], + [('Color', 0.8, 6), ('Rotate', 0.4, 5)], + ] + pc = [[AugmentOp(*a, hparams=hparams) for a in sp] for sp in policy] + return pc + + +def auto_augment_policy_v0r(hparams): + # ImageNet v0 policy from TPU EfficientNet impl, with variation of Posterize used + # in Google research implementation (number of bits discarded increases with magnitude) + policy = [ + [('Equalize', 0.8, 1), ('ShearY', 0.8, 4)], + [('Color', 0.4, 9), ('Equalize', 0.6, 3)], + [('Color', 0.4, 1), ('Rotate', 0.6, 8)], + [('Solarize', 0.8, 3), ('Equalize', 0.4, 7)], + [('Solarize', 0.4, 2), ('Solarize', 0.6, 2)], + [('Color', 0.2, 0), ('Equalize', 0.8, 8)], + [('Equalize', 0.4, 8), ('SolarizeAdd', 0.8, 3)], + [('ShearX', 0.2, 9), ('Rotate', 0.6, 8)], + [('Color', 0.6, 1), ('Equalize', 1.0, 2)], + [('Invert', 0.4, 9), ('Rotate', 0.6, 0)], + [('Equalize', 1.0, 9), ('ShearY', 0.6, 3)], + [('Color', 0.4, 7), ('Equalize', 0.6, 0)], + [('PosterizeIncreasing', 0.4, 6), ('AutoContrast', 0.4, 7)], + [('Solarize', 0.6, 8), ('Color', 0.6, 9)], + [('Solarize', 0.2, 4), ('Rotate', 0.8, 9)], + [('Rotate', 1.0, 7), ('TranslateYRel', 0.8, 9)], + [('ShearX', 0.0, 0), ('Solarize', 0.8, 4)], + [('ShearY', 0.8, 0), ('Color', 0.6, 4)], + [('Color', 1.0, 0), ('Rotate', 0.6, 2)], + [('Equalize', 0.8, 4), ('Equalize', 0.0, 8)], + [('Equalize', 1.0, 4), ('AutoContrast', 0.6, 2)], + [('ShearY', 0.4, 7), ('SolarizeAdd', 0.6, 7)], + [('PosterizeIncreasing', 0.8, 2), ('Solarize', 0.6, 10)], + [('Solarize', 0.6, 8), ('Equalize', 0.6, 1)], + [('Color', 0.8, 6), ('Rotate', 0.4, 5)], + ] + pc = [[AugmentOp(*a, hparams=hparams) for a in sp] for sp in policy] + return pc + + +def auto_augment_policy_original(hparams): + # ImageNet policy from https://arxiv.org/abs/1805.09501 + policy = [ + [('PosterizeOriginal', 0.4, 8), ('Rotate', 0.6, 9)], + [('Solarize', 0.6, 5), ('AutoContrast', 0.6, 5)], + [('Equalize', 0.8, 8), ('Equalize', 0.6, 3)], + [('PosterizeOriginal', 0.6, 7), ('PosterizeOriginal', 0.6, 6)], + [('Equalize', 0.4, 7), ('Solarize', 0.2, 4)], + [('Equalize', 0.4, 4), ('Rotate', 0.8, 8)], + [('Solarize', 0.6, 3), ('Equalize', 0.6, 7)], + [('PosterizeOriginal', 0.8, 5), ('Equalize', 1.0, 2)], + [('Rotate', 0.2, 3), ('Solarize', 0.6, 8)], + [('Equalize', 0.6, 8), ('PosterizeOriginal', 0.4, 6)], + [('Rotate', 0.8, 8), ('Color', 0.4, 0)], + [('Rotate', 0.4, 9), ('Equalize', 0.6, 2)], + [('Equalize', 0.0, 7), ('Equalize', 0.8, 8)], + [('Invert', 0.6, 4), ('Equalize', 1.0, 8)], + [('Color', 0.6, 4), ('Contrast', 1.0, 8)], + [('Rotate', 0.8, 8), ('Color', 1.0, 2)], + [('Color', 0.8, 8), ('Solarize', 0.8, 7)], + [('Sharpness', 0.4, 7), ('Invert', 0.6, 8)], + [('ShearX', 0.6, 5), ('Equalize', 1.0, 9)], + [('Color', 0.4, 0), ('Equalize', 0.6, 3)], + [('Equalize', 0.4, 7), ('Solarize', 0.2, 4)], + [('Solarize', 0.6, 5), ('AutoContrast', 0.6, 5)], + [('Invert', 0.6, 4), ('Equalize', 1.0, 8)], + [('Color', 0.6, 4), ('Contrast', 1.0, 8)], + [('Equalize', 0.8, 8), ('Equalize', 0.6, 3)], + ] + pc = [[AugmentOp(*a, hparams=hparams) for a in sp] for sp in policy] + return pc + + +def auto_augment_policy_originalr(hparams): + # ImageNet policy from https://arxiv.org/abs/1805.09501 with research posterize variation + policy = [ + [('PosterizeIncreasing', 0.4, 8), ('Rotate', 0.6, 9)], + [('Solarize', 0.6, 5), ('AutoContrast', 0.6, 5)], + [('Equalize', 0.8, 8), ('Equalize', 0.6, 3)], + [('PosterizeIncreasing', 0.6, 7), ('PosterizeIncreasing', 0.6, 6)], + [('Equalize', 0.4, 7), ('Solarize', 0.2, 4)], + [('Equalize', 0.4, 4), ('Rotate', 0.8, 8)], + [('Solarize', 0.6, 3), ('Equalize', 0.6, 7)], + [('PosterizeIncreasing', 0.8, 5), ('Equalize', 1.0, 2)], + [('Rotate', 0.2, 3), ('Solarize', 0.6, 8)], + [('Equalize', 0.6, 8), ('PosterizeIncreasing', 0.4, 6)], + [('Rotate', 0.8, 8), ('Color', 0.4, 0)], + [('Rotate', 0.4, 9), ('Equalize', 0.6, 2)], + [('Equalize', 0.0, 7), ('Equalize', 0.8, 8)], + [('Invert', 0.6, 4), ('Equalize', 1.0, 8)], + [('Color', 0.6, 4), ('Contrast', 1.0, 8)], + [('Rotate', 0.8, 8), ('Color', 1.0, 2)], + [('Color', 0.8, 8), ('Solarize', 0.8, 7)], + [('Sharpness', 0.4, 7), ('Invert', 0.6, 8)], + [('ShearX', 0.6, 5), ('Equalize', 1.0, 9)], + [('Color', 0.4, 0), ('Equalize', 0.6, 3)], + [('Equalize', 0.4, 7), ('Solarize', 0.2, 4)], + [('Solarize', 0.6, 5), ('AutoContrast', 0.6, 5)], + [('Invert', 0.6, 4), ('Equalize', 1.0, 8)], + [('Color', 0.6, 4), ('Contrast', 1.0, 8)], + [('Equalize', 0.8, 8), ('Equalize', 0.6, 3)], + ] + pc = [[AugmentOp(*a, hparams=hparams) for a in sp] for sp in policy] + return pc + + +def auto_augment_policy(name='v0', hparams=None): + hparams = hparams or _HPARAMS_DEFAULT + if name == 'original': + return auto_augment_policy_original(hparams) + elif name == 'originalr': + return auto_augment_policy_originalr(hparams) + elif name == 'v0': + return auto_augment_policy_v0(hparams) + elif name == 'v0r': + return auto_augment_policy_v0r(hparams) + else: + assert False, 'Unknown AA policy (%s)' % name + + +class AutoAugment: + + def __init__(self, policy): + self.policy = policy + + def __call__(self, img): + sub_policy = random.choice(self.policy) + for op in sub_policy: + img = op(img) + return img + + +def auto_augment_transform(config_str, hparams): + """ + Create a AutoAugment transform + + :param config_str: String defining configuration of auto augmentation. Consists of multiple sections separated by + dashes ('-'). The first section defines the AutoAugment policy (one of 'v0', 'v0r', 'original', 'originalr'). + The remaining sections, not order sepecific determine + 'mstd' - float std deviation of magnitude noise applied + Ex 'original-mstd0.5' results in AutoAugment with original policy, magnitude_std 0.5 + + :param hparams: Other hparams (kwargs) for the AutoAugmentation scheme + + :return: A PyTorch compatible Transform + """ + config = config_str.split('-') + policy_name = config[0] + config = config[1:] + for c in config: + cs = re.split(r'(\d.*)', c) + if len(cs) < 2: + continue + key, val = cs[:2] + if key == 'mstd': + # noise param injected via hparams for now + hparams.setdefault('magnitude_std', float(val)) + else: + assert False, 'Unknown AutoAugment config section' + aa_policy = auto_augment_policy(policy_name, hparams=hparams) + return AutoAugment(aa_policy) + + +_RAND_TRANSFORMS = [ + 'AutoContrast', + 'Equalize', + 'Invert', + 'Rotate', + 'Posterize', + 'Solarize', + 'SolarizeAdd', + 'Color', + 'Contrast', + 'Brightness', + 'Sharpness', + 'ShearX', + 'ShearY', + 'TranslateXRel', + 'TranslateYRel', + #'Cutout' # NOTE I've implement this as random erasing separately +] + + +_RAND_INCREASING_TRANSFORMS = [ + 'AutoContrast', + 'Equalize', + 'Invert', + 'Rotate', + 'PosterizeIncreasing', + 'SolarizeIncreasing', + 'SolarizeAdd', + 'ColorIncreasing', + 'ContrastIncreasing', + 'BrightnessIncreasing', + 'SharpnessIncreasing', + 'ShearX', + 'ShearY', + 'TranslateXRel', + 'TranslateYRel', + #'Cutout' # NOTE I've implement this as random erasing separately +] + + + +# These experimental weights are based loosely on the relative improvements mentioned in paper. +# They may not result in increased performance, but could likely be tuned to so. +_RAND_CHOICE_WEIGHTS_0 = { + 'Rotate': 0.3, + 'ShearX': 0.2, + 'ShearY': 0.2, + 'TranslateXRel': 0.1, + 'TranslateYRel': 0.1, + 'Color': .025, + 'Sharpness': 0.025, + 'AutoContrast': 0.025, + 'Solarize': .005, + 'SolarizeAdd': .005, + 'Contrast': .005, + 'Brightness': .005, + 'Equalize': .005, + 'Posterize': 0, + 'Invert': 0, +} + + +def _select_rand_weights(weight_idx=0, transforms=None): + transforms = transforms or _RAND_TRANSFORMS + assert weight_idx == 0 # only one set of weights currently + rand_weights = _RAND_CHOICE_WEIGHTS_0 + probs = [rand_weights[k] for k in transforms] + probs /= np.sum(probs) + return probs + + +def rand_augment_ops(magnitude=10, hparams=None, transforms=None): + hparams = hparams or _HPARAMS_DEFAULT + transforms = transforms or _RAND_TRANSFORMS + return [AugmentOp( + name, prob=0.5, magnitude=magnitude, hparams=hparams) for name in transforms] + + +class RandAugment: + def __init__(self, ops, num_layers=2, choice_weights=None): + self.ops = ops + self.num_layers = num_layers + self.choice_weights = choice_weights + + def __call__(self, img): + # no replacement when using weighted choice + ops = np.random.choice( + self.ops, self.num_layers, replace=self.choice_weights is None, p=self.choice_weights) + for op in ops: + img = op(img) + return img + + +def rand_augment_transform(config_str, hparams): + """ + Create a RandAugment transform + + :param config_str: String defining configuration of random augmentation. Consists of multiple sections separated by + dashes ('-'). The first section defines the specific variant of rand augment (currently only 'rand'). The remaining + sections, not order sepecific determine + 'm' - integer magnitude of rand augment + 'n' - integer num layers (number of transform ops selected per image) + 'w' - integer probabiliy weight index (index of a set of weights to influence choice of op) + 'mstd' - float std deviation of magnitude noise applied + 'inc' - integer (bool), use augmentations that increase in severity with magnitude (default: 0) + Ex 'rand-m9-n3-mstd0.5' results in RandAugment with magnitude 9, num_layers 3, magnitude_std 0.5 + 'rand-mstd1-w0' results in magnitude_std 1.0, weights 0, default magnitude of 10 and num_layers 2 + + :param hparams: Other hparams (kwargs) for the RandAugmentation scheme + + :return: A PyTorch compatible Transform + """ + magnitude = _MAX_LEVEL # default to _MAX_LEVEL for magnitude (currently 10) + num_layers = 2 # default to 2 ops per image + weight_idx = None # default to no probability weights for op choice + transforms = _RAND_TRANSFORMS + config = config_str.split('-') + assert config[0] == 'rand' + config = config[1:] + for c in config: + cs = re.split(r'(\d.*)', c) + if len(cs) < 2: + continue + key, val = cs[:2] + if key == 'mstd': + # noise param injected via hparams for now + hparams.setdefault('magnitude_std', float(val)) + elif key == 'inc': + if bool(val): + transforms = _RAND_INCREASING_TRANSFORMS + elif key == 'm': + magnitude = int(val) + elif key == 'n': + num_layers = int(val) + elif key == 'w': + weight_idx = int(val) + else: + assert False, 'Unknown RandAugment config section' + ra_ops = rand_augment_ops(magnitude=magnitude, hparams=hparams, transforms=transforms) + choice_weights = None if weight_idx is None else _select_rand_weights(weight_idx) + return RandAugment(ra_ops, num_layers, choice_weights=choice_weights) + + +_AUGMIX_TRANSFORMS = [ + 'AutoContrast', + 'ColorIncreasing', # not in paper + 'ContrastIncreasing', # not in paper + 'BrightnessIncreasing', # not in paper + 'SharpnessIncreasing', # not in paper + 'Equalize', + 'Rotate', + 'PosterizeIncreasing', + 'SolarizeIncreasing', + 'ShearX', + 'ShearY', + 'TranslateXRel', + 'TranslateYRel', +] + + +def augmix_ops(magnitude=10, hparams=None, transforms=None): + hparams = hparams or _HPARAMS_DEFAULT + transforms = transforms or _AUGMIX_TRANSFORMS + return [AugmentOp( + name, prob=1.0, magnitude=magnitude, hparams=hparams) for name in transforms] + + +class AugMixAugment: + """ AugMix Transform + Adapted and improved from impl here: https://github.com/google-research/augmix/blob/master/imagenet.py + From paper: 'AugMix: A Simple Data Processing Method to Improve Robustness and Uncertainty - + https://arxiv.org/abs/1912.02781 + """ + def __init__(self, ops, alpha=1., width=3, depth=-1, blended=False): + self.ops = ops + self.alpha = alpha + self.width = width + self.depth = depth + self.blended = blended # blended mode is faster but not well tested + + def _calc_blended_weights(self, ws, m): + ws = ws * m + cump = 1. + rws = [] + for w in ws[::-1]: + alpha = w / cump + cump *= (1 - alpha) + rws.append(alpha) + return np.array(rws[::-1], dtype=np.float32) + + def _apply_blended(self, img, mixing_weights, m): + # This is my first crack and implementing a slightly faster mixed augmentation. Instead + # of accumulating the mix for each chain in a Numpy array and then blending with original, + # it recomputes the blending coefficients and applies one PIL image blend per chain. + # TODO the results appear in the right ballpark but they differ by more than rounding. + img_orig = img.copy() + ws = self._calc_blended_weights(mixing_weights, m) + for w in ws: + depth = self.depth if self.depth > 0 else np.random.randint(1, 4) + ops = np.random.choice(self.ops, depth, replace=True) + img_aug = img_orig # no ops are in-place, deep copy not necessary + for op in ops: + img_aug = op(img_aug) + img = Image.blend(img, img_aug, w) + return img + + def _apply_basic(self, img, mixing_weights, m): + # This is a literal adaptation of the paper/official implementation without normalizations and + # PIL <-> Numpy conversions between every op. It is still quite CPU compute heavy compared to the + # typical augmentation transforms, could use a GPU / Kornia implementation. + img_shape = img.size[0], img.size[1], len(img.getbands()) + mixed = np.zeros(img_shape, dtype=np.float32) + for mw in mixing_weights: + depth = self.depth if self.depth > 0 else np.random.randint(1, 4) + ops = np.random.choice(self.ops, depth, replace=True) + img_aug = img # no ops are in-place, deep copy not necessary + for op in ops: + img_aug = op(img_aug) + mixed += mw * np.asarray(img_aug, dtype=np.float32) + np.clip(mixed, 0, 255., out=mixed) + mixed = Image.fromarray(mixed.astype(np.uint8)) + return Image.blend(img, mixed, m) + + def __call__(self, img): + mixing_weights = np.float32(np.random.dirichlet([self.alpha] * self.width)) + m = np.float32(np.random.beta(self.alpha, self.alpha)) + if self.blended: + mixed = self._apply_blended(img, mixing_weights, m) + else: + mixed = self._apply_basic(img, mixing_weights, m) + return mixed + + +def augment_and_mix_transform(config_str, hparams): + """ Create AugMix PyTorch transform + + :param config_str: String defining configuration of random augmentation. Consists of multiple sections separated by + dashes ('-'). The first section defines the specific variant of rand augment (currently only 'rand'). The remaining + sections, not order sepecific determine + 'm' - integer magnitude (severity) of augmentation mix (default: 3) + 'w' - integer width of augmentation chain (default: 3) + 'd' - integer depth of augmentation chain (-1 is random [1, 3], default: -1) + 'b' - integer (bool), blend each branch of chain into end result without a final blend, less CPU (default: 0) + 'mstd' - float std deviation of magnitude noise applied (default: 0) + Ex 'augmix-m5-w4-d2' results in AugMix with severity 5, chain width 4, chain depth 2 + + :param hparams: Other hparams (kwargs) for the Augmentation transforms + + :return: A PyTorch compatible Transform + """ + magnitude = 3 + width = 3 + depth = -1 + alpha = 1. + blended = False + config = config_str.split('-') + assert config[0] == 'augmix' + config = config[1:] + for c in config: + cs = re.split(r'(\d.*)', c) + if len(cs) < 2: + continue + key, val = cs[:2] + if key == 'mstd': + # noise param injected via hparams for now + hparams.setdefault('magnitude_std', float(val)) + elif key == 'm': + magnitude = int(val) + elif key == 'w': + width = int(val) + elif key == 'd': + depth = int(val) + elif key == 'a': + alpha = float(val) + elif key == 'b': + blended = bool(val) + else: + assert False, 'Unknown AugMix config section' + ops = augmix_ops(magnitude=magnitude, hparams=hparams) return AugMixAugment(ops, alpha=alpha, width=width, depth=depth, blended=blended) \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/model.py b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/model.py index 4472a6a19fe512d303eff83a8ee521676061eb1c..6d180a0119a16c641ed08240dd62be12d1d3115b 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/model.py +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/model.py @@ -1,426 +1,426 @@ -# Copyright [yyyy] [name of copyright owner] -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -from torch import nn -from torch.nn import functional as F -from .utils import ( - round_filters, - round_repeats, - drop_connect, - get_same_padding_conv2d, - get_model_params, - efficientnet_params, - load_pretrained_weights, - Swish, - MemoryEfficientSwish, - calculate_output_image_size -) - -class MBConvBlock(nn.Module): - """Mobile Inverted Residual Bottleneck Block. - - Args: - block_args (namedtuple): BlockArgs, defined in utils.py. - global_params (namedtuple): GlobalParam, defined in utils.py. - image_size (tuple or list): [image_height, image_width]. - - References: - [1] https://arxiv.org/abs/1704.04861 (MobileNet v1) - [2] https://arxiv.org/abs/1801.04381 (MobileNet v2) - [3] https://arxiv.org/abs/1905.02244 (MobileNet v3) - """ - - def __init__(self, block_args, global_params, image_size=None): - super().__init__() - self._block_args = block_args - self._bn_mom = 1 - global_params.batch_norm_momentum # pytorch's difference from tensorflow - self._bn_eps = global_params.batch_norm_epsilon - self.has_se = (self._block_args.se_ratio is not None) and (0 < self._block_args.se_ratio <= 1) - self.id_skip = block_args.id_skip # whether to use skip connection and drop connect - - # Expansion phase (Inverted Bottleneck) - inp = self._block_args.input_filters # number of input channels - oup = self._block_args.input_filters * self._block_args.expand_ratio # number of output channels - if self._block_args.expand_ratio != 1: - Conv2d = get_same_padding_conv2d(image_size=image_size) - self._expand_conv = Conv2d(in_channels=inp, out_channels=oup, kernel_size=1, bias=False) - self._bn0 = nn.BatchNorm2d(num_features=oup, momentum=self._bn_mom, eps=self._bn_eps) - # image_size = calculate_output_image_size(image_size, 1) <-- this wouldn't modify image_size - - # Depthwise convolution phase - k = self._block_args.kernel_size - s = self._block_args.stride - Conv2d = get_same_padding_conv2d(image_size=image_size) - self._depthwise_conv = Conv2d( - in_channels=oup, out_channels=oup, groups=oup, # groups makes it depthwise - kernel_size=k, stride=s, bias=False) - self._bn1 = nn.BatchNorm2d(num_features=oup, momentum=self._bn_mom, eps=self._bn_eps) - image_size = calculate_output_image_size(image_size, s) - - # Squeeze and Excitation layer, if desired - if self.has_se: - Conv2d = get_same_padding_conv2d(image_size=(1,1)) - num_squeezed_channels = max(1, int(self._block_args.input_filters * self._block_args.se_ratio)) - self._se_reduce = Conv2d(in_channels=oup, out_channels=num_squeezed_channels, kernel_size=1) - self._se_expand = Conv2d(in_channels=num_squeezed_channels, out_channels=oup, kernel_size=1) - # self._se_relu = torch.nn.ReLU() - # self._se_sigmoid = torch.nn.Sigmoid() - - # Pointwise convolution phase - final_oup = self._block_args.output_filters - Conv2d = get_same_padding_conv2d(image_size=image_size) - self._project_conv = Conv2d(in_channels=oup, out_channels=final_oup, kernel_size=1, bias=False) - self._bn2 = nn.BatchNorm2d(num_features=final_oup, momentum=self._bn_mom, eps=self._bn_eps) - self._swish = MemoryEfficientSwish() - - def forward(self, inputs, drop_connect_rate=None): - """MBConvBlock's forward function. - - Args: - inputs (tensor): Input tensor. - drop_connect_rate (bool): Drop connect rate (float, between 0 and 1). - - Returns: - Output of this block after processing. - """ - - # Expansion and Depthwise Convolution - x = inputs - if self._block_args.expand_ratio != 1: - x = self._expand_conv(inputs) - x = self._bn0(x) - x = self._swish(x) - - x = self._depthwise_conv(x) - x = self._bn1(x) - x = self._swish(x) - - # Squeeze and Excitation - if self.has_se: - x_squeezed = F.adaptive_avg_pool2d(x, 1) - # x_squeezed = torch.mean(x, [2, 3], keepdim=True) - - x_squeezed = self._se_reduce(x_squeezed) - - x_squeezed = self._swish(x_squeezed) - - x_squeezed = self._se_expand(x_squeezed) - - x = torch.sigmoid(x_squeezed) * x - - # Pointwise Convolution - x = self._project_conv(x) - x = self._bn2(x) - - # Skip connection and drop connect - input_filters, output_filters = self._block_args.input_filters, self._block_args.output_filters - if self.id_skip and self._block_args.stride == 1 and input_filters == output_filters: - # The combination of skip connection and drop connect brings about stochastic depth. - if drop_connect_rate: - x = drop_connect(x, p=drop_connect_rate, training=self.training) - x = x + inputs # skip connection - return x - - def set_swish(self, memory_efficient=True): - """Sets swish function as memory efficient (for training) or standard (for export). - - Args: - memory_efficient (bool): Whether to use memory-efficient version of swish. - """ - self._swish = MemoryEfficientSwish() if memory_efficient else Swish() - - -class EfficientNet(nn.Module): - """EfficientNet model. - Most easily loaded with the .from_name or .from_pretrained methods. - - Args: - blocks_args (list[namedtuple]): A list of BlockArgs to construct blocks. - global_params (namedtuple): A set of GlobalParams shared between blocks. - - References: - [1] https://arxiv.org/abs/1905.11946 (EfficientNet) - - Example: - >>> import torch - >>> from efficientnet.model import EfficientNet - >>> inputs = torch.rand(1, 3, 224, 224) - >>> model = EfficientNet.from_pretrained('efficientnet-b0') - >>> model.eval() - >>> outputs = model(inputs) - """ - - def __init__(self, blocks_args=None, global_params=None): - super().__init__() - assert isinstance(blocks_args, list), 'blocks_args should be a list' - assert len(blocks_args) > 0, 'block args must be greater than 0' - self._global_params = global_params - self._blocks_args = blocks_args - - # Batch norm parameters - bn_mom = 1 - self._global_params.batch_norm_momentum - bn_eps = self._global_params.batch_norm_epsilon - - # Get stem static or dynamic convolution depending on image size - image_size = global_params.image_size - Conv2d = get_same_padding_conv2d(image_size=image_size) - - # Stem - in_channels = 3 # rgb - out_channels = round_filters(32, self._global_params) # number of output channels - self._conv_stem = Conv2d(in_channels, out_channels, kernel_size=3, stride=2, bias=False) - self._bn0 = nn.BatchNorm2d(num_features=out_channels, momentum=bn_mom, eps=bn_eps) - image_size = calculate_output_image_size(image_size, 2) - - # Build blocks - self._blocks = nn.ModuleList([]) - for block_args in self._blocks_args: - - # Update block input and output filters based on depth multiplier. - block_args = block_args._replace( - input_filters=round_filters(block_args.input_filters, self._global_params), - output_filters=round_filters(block_args.output_filters, self._global_params), - num_repeat=round_repeats(block_args.num_repeat, self._global_params) - ) - - # The first block needs to take care of stride and filter size increase. - self._blocks.append(MBConvBlock(block_args, self._global_params, image_size=image_size)) - image_size = calculate_output_image_size(image_size, block_args.stride) - if block_args.num_repeat > 1: # modify block_args to keep same output size - block_args = block_args._replace(input_filters=block_args.output_filters, stride=1) - for _ in range(block_args.num_repeat - 1): - self._blocks.append(MBConvBlock(block_args, self._global_params, image_size=image_size)) - # image_size = calculate_output_image_size(image_size, block_args.stride) # stride = 1 - - # Head - in_channels = block_args.output_filters # output of final block - out_channels = round_filters(1280, self._global_params) - Conv2d = get_same_padding_conv2d(image_size=image_size) - self._conv_head = Conv2d(in_channels, out_channels, kernel_size=1, bias=False) - self._bn1 = nn.BatchNorm2d(num_features=out_channels, momentum=bn_mom, eps=bn_eps) - - # Final linear layer - self._avg_pooling = nn.AdaptiveAvgPool2d(1) - self._dropout = nn.Dropout(self._global_params.dropout_rate) - self._fc = nn.Linear(out_channels, self._global_params.num_classes) - self._swish = MemoryEfficientSwish() - - def set_swish(self, memory_efficient=True): - """Sets swish function as memory efficient (for training) or standard (for export). - - Args: - memory_efficient (bool): Whether to use memory-efficient version of swish. - - """ - self._swish = MemoryEfficientSwish() if memory_efficient else Swish() - for block in self._blocks: - block.set_swish(memory_efficient) - - def extract_endpoints(self, inputs): - """Use convolution layer to extract features - from reduction levels i in [1, 2, 3, 4, 5]. - - Args: - inputs (tensor): Input tensor. - - Returns: - Dictionary of last intermediate features - with reduction levels i in [1, 2, 3, 4, 5]. - Example: - >>> import torch - >>> from efficientnet.model import EfficientNet - >>> inputs = torch.rand(1, 3, 224, 224) - >>> model = EfficientNet.from_pretrained('efficientnet-b0') - >>> endpoints = model.extract_features(inputs) - >>> print(endpoints['reduction_1'].shape) # torch.Size([1, 16, 112, 112]) - >>> print(endpoints['reduction_2'].shape) # torch.Size([1, 24, 56, 56]) - >>> print(endpoints['reduction_3'].shape) # torch.Size([1, 40, 28, 28]) - >>> print(endpoints['reduction_4'].shape) # torch.Size([1, 112, 14, 14]) - >>> print(endpoints['reduction_5'].shape) # torch.Size([1, 1280, 7, 7]) - """ - endpoints = dict() - - # Stem - x = self._swish(self._bn0(self._conv_stem(inputs))) - # x = self._swish(self._conv_stem(inputs)) - prev_x = x - - # Blocks - for idx, block in enumerate(self._blocks): - drop_connect_rate = self._global_params.drop_connect_rate - if drop_connect_rate: - drop_connect_rate *= float(idx) / len(self._blocks) # scale drop connect_rate - x = block(x, drop_connect_rate=drop_connect_rate) - if prev_x.size(2) > x.size(2): - endpoints[f'reduction_{len(endpoints)+1}'] = prev_x - prev_x = x - - # Head - x = self._swish(self._bn1(self._conv_head(x))) - - endpoints[f'reduction_{len(endpoints)+1}'] = x - - return endpoints - - def extract_features(self, inputs): - """use convolution layer to extract feature . - - Args: - inputs (tensor): Input tensor. - - Returns: - Output of the final convolution - layer in the efficientnet model. - """ - # Stem - x = self._swish(self._bn0(self._conv_stem(inputs))) - - - # Blocks - for idx, block in enumerate(self._blocks): - drop_connect_rate = self._global_params.drop_connect_rate - if drop_connect_rate: - drop_connect_rate *= float(idx) / len(self._blocks) # scale drop connect_rate - x = block(x, drop_connect_rate=drop_connect_rate) - - # Head - x = self._swish(self._bn1(self._conv_head(x))) - - return x - - def forward(self, inputs): - """EfficientNet's forward function. - Calls extract_features to extract features, applies final linear layer, and returns logits. - - Args: - inputs (tensor): Input tensor. - - Returns: - Output of this model after processing. - """ - - # Convolution layers - x = self.extract_features(inputs) - - # Pooling and final linear layer - x = self._avg_pooling(x) - x = torch.flatten(x, start_dim=1) - x = self._dropout(x) - x = self._fc(x) - - return x - - @classmethod - def from_name(cls, model_name, in_channels=3, **override_params): - """create an efficientnet model according to name. - - Args: - model_name (str): Name for efficientnet. - in_channels (int): Input data's channel number. - override_params (other key word params): - Params to override model's global_params. - Optional key: - 'width_coefficient', 'depth_coefficient', - 'image_size', 'dropout_rate', - 'num_classes', 'batch_norm_momentum', - 'batch_norm_epsilon', 'drop_connect_rate', - 'depth_divisor', 'min_depth' - - Returns: - An efficientnet model. - """ - cls._check_model_name_is_valid(model_name) - blocks_args, global_params = get_model_params(model_name, override_params) - model = cls(blocks_args, global_params) - model._change_in_channels(in_channels) - return model - - @classmethod - def from_pretrained(cls, model_name, weights_path=None, advprop=False, - in_channels=3, num_classes=1000, **override_params): - """create an efficientnet model according to name. - - Args: - model_name (str): Name for efficientnet. - weights_path (None or str): - str: path to pretrained weights file on the local disk. - None: use pretrained weights downloaded from the Internet. - advprop (bool): - Whether to load pretrained weights - trained with advprop (valid when weights_path is None). - in_channels (int): Input data's channel number. - num_classes (int): - Number of categories for classification. - It controls the output size for final linear layer. - override_params (other key word params): - Params to override model's global_params. - Optional key: - 'width_coefficient', 'depth_coefficient', - 'image_size', 'dropout_rate', - 'num_classes', 'batch_norm_momentum', - 'batch_norm_epsilon', 'drop_connect_rate', - 'depth_divisor', 'min_depth' - - Returns: - A pretrained efficientnet model. - """ - model = cls.from_name(model_name, num_classes = num_classes, **override_params) - load_pretrained_weights(model, model_name, weights_path=weights_path, load_fc=(num_classes == 1000), advprop=advprop) - model._change_in_channels(in_channels) - return model - - @classmethod - def get_image_size(cls, model_name): - """Get the input image size for a given efficientnet model. - - Args: - model_name (str): Name for efficientnet. - - Returns: - Input image size (resolution). - """ - cls._check_model_name_is_valid(model_name) - _, _, res, _ = efficientnet_params(model_name) - return res - - @classmethod - def _check_model_name_is_valid(cls, model_name): - """Validates model name. - - Args: - model_name (str): Name for efficientnet. - - Returns: - bool: Is a valid name or not. - """ - valid_models = ['efficientnet-b'+str(i) for i in range(9)] - - # Support the construction of 'efficientnet-l2' without pretrained weights - valid_models += ['efficientnet-l2'] - - if model_name not in valid_models: - raise ValueError('model_name should be one of: ' + ', '.join(valid_models)) - - def _change_in_channels(self, in_channels): - """Adjust model's first convolution layer to in_channels, if in_channels not equals 3. - - Args: - in_channels (int): Input data's channel number. - """ - if in_channels != 3: - Conv2d = get_same_padding_conv2d(image_size = self._global_params.image_size) - out_channels = round_filters(32, self._global_params) - self._conv_stem = Conv2d(in_channels, out_channels, kernel_size=3, stride=2, bias=False) +# Copyright [yyyy] [name of copyright owner] +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +from torch import nn +from torch.nn import functional as F +from .utils import ( + round_filters, + round_repeats, + drop_connect, + get_same_padding_conv2d, + get_model_params, + efficientnet_params, + load_pretrained_weights, + Swish, + MemoryEfficientSwish, + calculate_output_image_size +) + +class MBConvBlock(nn.Module): + """Mobile Inverted Residual Bottleneck Block. + + Args: + block_args (namedtuple): BlockArgs, defined in utils.py. + global_params (namedtuple): GlobalParam, defined in utils.py. + image_size (tuple or list): [image_height, image_width]. + + References: + [1] https://arxiv.org/abs/1704.04861 (MobileNet v1) + [2] https://arxiv.org/abs/1801.04381 (MobileNet v2) + [3] https://arxiv.org/abs/1905.02244 (MobileNet v3) + """ + + def __init__(self, block_args, global_params, image_size=None): + super().__init__() + self._block_args = block_args + self._bn_mom = 1 - global_params.batch_norm_momentum # pytorch's difference from tensorflow + self._bn_eps = global_params.batch_norm_epsilon + self.has_se = (self._block_args.se_ratio is not None) and (0 < self._block_args.se_ratio <= 1) + self.id_skip = block_args.id_skip # whether to use skip connection and drop connect + + # Expansion phase (Inverted Bottleneck) + inp = self._block_args.input_filters # number of input channels + oup = self._block_args.input_filters * self._block_args.expand_ratio # number of output channels + if self._block_args.expand_ratio != 1: + Conv2d = get_same_padding_conv2d(image_size=image_size) + self._expand_conv = Conv2d(in_channels=inp, out_channels=oup, kernel_size=1, bias=False) + self._bn0 = nn.BatchNorm2d(num_features=oup, momentum=self._bn_mom, eps=self._bn_eps) + # image_size = calculate_output_image_size(image_size, 1) <-- this wouldn't modify image_size + + # Depthwise convolution phase + k = self._block_args.kernel_size + s = self._block_args.stride + Conv2d = get_same_padding_conv2d(image_size=image_size) + self._depthwise_conv = Conv2d( + in_channels=oup, out_channels=oup, groups=oup, # groups makes it depthwise + kernel_size=k, stride=s, bias=False) + self._bn1 = nn.BatchNorm2d(num_features=oup, momentum=self._bn_mom, eps=self._bn_eps) + image_size = calculate_output_image_size(image_size, s) + + # Squeeze and Excitation layer, if desired + if self.has_se: + Conv2d = get_same_padding_conv2d(image_size=(1,1)) + num_squeezed_channels = max(1, int(self._block_args.input_filters * self._block_args.se_ratio)) + self._se_reduce = Conv2d(in_channels=oup, out_channels=num_squeezed_channels, kernel_size=1) + self._se_expand = Conv2d(in_channels=num_squeezed_channels, out_channels=oup, kernel_size=1) + # self._se_relu = torch.nn.ReLU() + # self._se_sigmoid = torch.nn.Sigmoid() + + # Pointwise convolution phase + final_oup = self._block_args.output_filters + Conv2d = get_same_padding_conv2d(image_size=image_size) + self._project_conv = Conv2d(in_channels=oup, out_channels=final_oup, kernel_size=1, bias=False) + self._bn2 = nn.BatchNorm2d(num_features=final_oup, momentum=self._bn_mom, eps=self._bn_eps) + self._swish = MemoryEfficientSwish() + + def forward(self, inputs, drop_connect_rate=None): + """MBConvBlock's forward function. + + Args: + inputs (tensor): Input tensor. + drop_connect_rate (bool): Drop connect rate (float, between 0 and 1). + + Returns: + Output of this block after processing. + """ + + # Expansion and Depthwise Convolution + x = inputs + if self._block_args.expand_ratio != 1: + x = self._expand_conv(inputs) + x = self._bn0(x) + x = self._swish(x) + + x = self._depthwise_conv(x) + x = self._bn1(x) + x = self._swish(x) + + # Squeeze and Excitation + if self.has_se: + x_squeezed = F.adaptive_avg_pool2d(x, 1) + # x_squeezed = torch.mean(x, [2, 3], keepdim=True) + + x_squeezed = self._se_reduce(x_squeezed) + + x_squeezed = self._swish(x_squeezed) + + x_squeezed = self._se_expand(x_squeezed) + + x = torch.sigmoid(x_squeezed) * x + + # Pointwise Convolution + x = self._project_conv(x) + x = self._bn2(x) + + # Skip connection and drop connect + input_filters, output_filters = self._block_args.input_filters, self._block_args.output_filters + if self.id_skip and self._block_args.stride == 1 and input_filters == output_filters: + # The combination of skip connection and drop connect brings about stochastic depth. + if drop_connect_rate: + x = drop_connect(x, p=drop_connect_rate, training=self.training) + x = x + inputs # skip connection + return x + + def set_swish(self, memory_efficient=True): + """Sets swish function as memory efficient (for training) or standard (for export). + + Args: + memory_efficient (bool): Whether to use memory-efficient version of swish. + """ + self._swish = MemoryEfficientSwish() if memory_efficient else Swish() + + +class EfficientNet(nn.Module): + """EfficientNet model. + Most easily loaded with the .from_name or .from_pretrained methods. + + Args: + blocks_args (list[namedtuple]): A list of BlockArgs to construct blocks. + global_params (namedtuple): A set of GlobalParams shared between blocks. + + References: + [1] https://arxiv.org/abs/1905.11946 (EfficientNet) + + Example: + >>> import torch + >>> from efficientnet.model import EfficientNet + >>> inputs = torch.rand(1, 3, 224, 224) + >>> model = EfficientNet.from_pretrained('efficientnet-b0') + >>> model.eval() + >>> outputs = model(inputs) + """ + + def __init__(self, blocks_args=None, global_params=None): + super().__init__() + assert isinstance(blocks_args, list), 'blocks_args should be a list' + assert len(blocks_args) > 0, 'block args must be greater than 0' + self._global_params = global_params + self._blocks_args = blocks_args + + # Batch norm parameters + bn_mom = 1 - self._global_params.batch_norm_momentum + bn_eps = self._global_params.batch_norm_epsilon + + # Get stem static or dynamic convolution depending on image size + image_size = global_params.image_size + Conv2d = get_same_padding_conv2d(image_size=image_size) + + # Stem + in_channels = 3 # rgb + out_channels = round_filters(32, self._global_params) # number of output channels + self._conv_stem = Conv2d(in_channels, out_channels, kernel_size=3, stride=2, bias=False) + self._bn0 = nn.BatchNorm2d(num_features=out_channels, momentum=bn_mom, eps=bn_eps) + image_size = calculate_output_image_size(image_size, 2) + + # Build blocks + self._blocks = nn.ModuleList([]) + for block_args in self._blocks_args: + + # Update block input and output filters based on depth multiplier. + block_args = block_args._replace( + input_filters=round_filters(block_args.input_filters, self._global_params), + output_filters=round_filters(block_args.output_filters, self._global_params), + num_repeat=round_repeats(block_args.num_repeat, self._global_params) + ) + + # The first block needs to take care of stride and filter size increase. + self._blocks.append(MBConvBlock(block_args, self._global_params, image_size=image_size)) + image_size = calculate_output_image_size(image_size, block_args.stride) + if block_args.num_repeat > 1: # modify block_args to keep same output size + block_args = block_args._replace(input_filters=block_args.output_filters, stride=1) + for _ in range(block_args.num_repeat - 1): + self._blocks.append(MBConvBlock(block_args, self._global_params, image_size=image_size)) + # image_size = calculate_output_image_size(image_size, block_args.stride) # stride = 1 + + # Head + in_channels = block_args.output_filters # output of final block + out_channels = round_filters(1280, self._global_params) + Conv2d = get_same_padding_conv2d(image_size=image_size) + self._conv_head = Conv2d(in_channels, out_channels, kernel_size=1, bias=False) + self._bn1 = nn.BatchNorm2d(num_features=out_channels, momentum=bn_mom, eps=bn_eps) + + # Final linear layer + self._avg_pooling = nn.AdaptiveAvgPool2d(1) + self._dropout = nn.Dropout(self._global_params.dropout_rate) + self._fc = nn.Linear(out_channels, self._global_params.num_classes) + self._swish = MemoryEfficientSwish() + + def set_swish(self, memory_efficient=True): + """Sets swish function as memory efficient (for training) or standard (for export). + + Args: + memory_efficient (bool): Whether to use memory-efficient version of swish. + + """ + self._swish = MemoryEfficientSwish() if memory_efficient else Swish() + for block in self._blocks: + block.set_swish(memory_efficient) + + def extract_endpoints(self, inputs): + """Use convolution layer to extract features + from reduction levels i in [1, 2, 3, 4, 5]. + + Args: + inputs (tensor): Input tensor. + + Returns: + Dictionary of last intermediate features + with reduction levels i in [1, 2, 3, 4, 5]. + Example: + >>> import torch + >>> from efficientnet.model import EfficientNet + >>> inputs = torch.rand(1, 3, 224, 224) + >>> model = EfficientNet.from_pretrained('efficientnet-b0') + >>> endpoints = model.extract_features(inputs) + >>> print(endpoints['reduction_1'].shape) # torch.Size([1, 16, 112, 112]) + >>> print(endpoints['reduction_2'].shape) # torch.Size([1, 24, 56, 56]) + >>> print(endpoints['reduction_3'].shape) # torch.Size([1, 40, 28, 28]) + >>> print(endpoints['reduction_4'].shape) # torch.Size([1, 112, 14, 14]) + >>> print(endpoints['reduction_5'].shape) # torch.Size([1, 1280, 7, 7]) + """ + endpoints = dict() + + # Stem + x = self._swish(self._bn0(self._conv_stem(inputs))) + # x = self._swish(self._conv_stem(inputs)) + prev_x = x + + # Blocks + for idx, block in enumerate(self._blocks): + drop_connect_rate = self._global_params.drop_connect_rate + if drop_connect_rate: + drop_connect_rate *= float(idx) / len(self._blocks) # scale drop connect_rate + x = block(x, drop_connect_rate=drop_connect_rate) + if prev_x.size(2) > x.size(2): + endpoints[f'reduction_{len(endpoints)+1}'] = prev_x + prev_x = x + + # Head + x = self._swish(self._bn1(self._conv_head(x))) + + endpoints[f'reduction_{len(endpoints)+1}'] = x + + return endpoints + + def extract_features(self, inputs): + """use convolution layer to extract feature . + + Args: + inputs (tensor): Input tensor. + + Returns: + Output of the final convolution + layer in the efficientnet model. + """ + # Stem + x = self._swish(self._bn0(self._conv_stem(inputs))) + + + # Blocks + for idx, block in enumerate(self._blocks): + drop_connect_rate = self._global_params.drop_connect_rate + if drop_connect_rate: + drop_connect_rate *= float(idx) / len(self._blocks) # scale drop connect_rate + x = block(x, drop_connect_rate=drop_connect_rate) + + # Head + x = self._swish(self._bn1(self._conv_head(x))) + + return x + + def forward(self, inputs): + """EfficientNet's forward function. + Calls extract_features to extract features, applies final linear layer, and returns logits. + + Args: + inputs (tensor): Input tensor. + + Returns: + Output of this model after processing. + """ + + # Convolution layers + x = self.extract_features(inputs) + + # Pooling and final linear layer + x = self._avg_pooling(x) + x = torch.flatten(x, start_dim=1) + x = self._dropout(x) + x = self._fc(x) + + return x + + @classmethod + def from_name(cls, model_name, in_channels=3, **override_params): + """create an efficientnet model according to name. + + Args: + model_name (str): Name for efficientnet. + in_channels (int): Input data's channel number. + override_params (other key word params): + Params to override model's global_params. + Optional key: + 'width_coefficient', 'depth_coefficient', + 'image_size', 'dropout_rate', + 'num_classes', 'batch_norm_momentum', + 'batch_norm_epsilon', 'drop_connect_rate', + 'depth_divisor', 'min_depth' + + Returns: + An efficientnet model. + """ + cls._check_model_name_is_valid(model_name) + blocks_args, global_params = get_model_params(model_name, override_params) + model = cls(blocks_args, global_params) + model._change_in_channels(in_channels) + return model + + @classmethod + def from_pretrained(cls, model_name, weights_path=None, advprop=False, + in_channels=3, num_classes=1000, **override_params): + """create an efficientnet model according to name. + + Args: + model_name (str): Name for efficientnet. + weights_path (None or str): + str: path to pretrained weights file on the local disk. + None: use pretrained weights downloaded from the Internet. + advprop (bool): + Whether to load pretrained weights + trained with advprop (valid when weights_path is None). + in_channels (int): Input data's channel number. + num_classes (int): + Number of categories for classification. + It controls the output size for final linear layer. + override_params (other key word params): + Params to override model's global_params. + Optional key: + 'width_coefficient', 'depth_coefficient', + 'image_size', 'dropout_rate', + 'num_classes', 'batch_norm_momentum', + 'batch_norm_epsilon', 'drop_connect_rate', + 'depth_divisor', 'min_depth' + + Returns: + A pretrained efficientnet model. + """ + model = cls.from_name(model_name, num_classes = num_classes, **override_params) + load_pretrained_weights(model, model_name, weights_path=weights_path, load_fc=(num_classes == 1000), advprop=advprop) + model._change_in_channels(in_channels) + return model + + @classmethod + def get_image_size(cls, model_name): + """Get the input image size for a given efficientnet model. + + Args: + model_name (str): Name for efficientnet. + + Returns: + Input image size (resolution). + """ + cls._check_model_name_is_valid(model_name) + _, _, res, _ = efficientnet_params(model_name) + return res + + @classmethod + def _check_model_name_is_valid(cls, model_name): + """Validates model name. + + Args: + model_name (str): Name for efficientnet. + + Returns: + bool: Is a valid name or not. + """ + valid_models = ['efficientnet-b'+str(i) for i in range(9)] + + # Support the construction of 'efficientnet-l2' without pretrained weights + valid_models += ['efficientnet-l2'] + + if model_name not in valid_models: + raise ValueError('model_name should be one of: ' + ', '.join(valid_models)) + + def _change_in_channels(self, in_channels): + """Adjust model's first convolution layer to in_channels, if in_channels not equals 3. + + Args: + in_channels (int): Input data's channel number. + """ + if in_channels != 3: + Conv2d = get_same_padding_conv2d(image_size = self._global_params.image_size) + out_channels = round_filters(32, self._global_params) + self._conv_stem = Conv2d(in_channels, out_channels, kernel_size=3, stride=2, bias=False) diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/rmsprop_tf.py b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/rmsprop_tf.py index 7873ed7393832045687de92aceb935a2839b98e6..3666cb6061aecc28b1195551ffeebd255bd1c77d 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/rmsprop_tf.py +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/rmsprop_tf.py @@ -1,136 +1,136 @@ -# Copyright [yyyy] [name of copyright owner] -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -from torch.optim import Optimizer - -class RMSpropTF(Optimizer): - """Implements RMSprop algorithm (TensorFlow style epsilon) - - NOTE: This is a direct cut-and-paste of PyTorch RMSprop with eps applied before sqrt - to closer match Tensorflow for matching hyper-params. - - Proposed by G. Hinton in his - `course `_. - - The centered version first appears in `Generating Sequences - With Recurrent Neural Networks `_. - - Arguments: - params (iterable): iterable of parameters to optimize or dicts defining - parameter groups - lr (float, optional): learning rate (default: 1e-2) - momentum (float, optional): momentum factor (default: 0) - alpha (float, optional): smoothing (decay) constant (default: 0.9) - eps (float, optional): term added to the denominator to improve - numerical stability (default: 1e-10) - centered (bool, optional) : if ``True``, compute the centered RMSProp, - the gradient is normalized by an estimation of its variance - weight_decay (float, optional): weight decay (L2 penalty) (default: 0) - decoupled_decay (bool, optional): decoupled weight decay as per https://arxiv.org/abs/1711.05101 - lr_in_momentum (bool, optional): learning rate scaling is included in the momentum buffer - update as per defaults in Tensorflow - - """ - - def __init__(self, params, lr=1e-2, alpha=0.9, eps=1e-10, weight_decay=0, momentum=0., centered=False, - decoupled_decay=False, lr_in_momentum=True): - if not 0.0 <= lr: - raise ValueError("Invalid learning rate: {}".format(lr)) - if not 0.0 <= eps: - raise ValueError("Invalid epsilon value: {}".format(eps)) - if not 0.0 <= momentum: - raise ValueError("Invalid momentum value: {}".format(momentum)) - if not 0.0 <= weight_decay: - raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) - if not 0.0 <= alpha: - raise ValueError("Invalid alpha value: {}".format(alpha)) - - defaults = dict(lr=lr, momentum=momentum, alpha=alpha, eps=eps, centered=centered, weight_decay=weight_decay, - decoupled_decay=decoupled_decay, lr_in_momentum=lr_in_momentum) - super(RMSpropTF, self).__init__(params, defaults) - - def __setstate__(self, state): - super(RMSpropTF, self).__setstate__(state) - for group in self.param_groups: - group.setdefault('momentum', 0) - group.setdefault('centered', False) - - def step(self, closure=None): - """Performs a single optimization step. - - Arguments: - closure (callable, optional): A closure that reevaluates the model - and returns the loss. - """ - loss = None - if closure is not None: - loss = closure() - - for group in self.param_groups: - for p in group['params']: - if p.grad is None: - continue - grad = p.grad.data - if grad.is_sparse: - raise RuntimeError('RMSprop does not support sparse gradients') - state = self.state[p] - - # State initialization - if len(state) == 0: - state['step'] = 0 - state['square_avg'] = torch.ones_like(p.data) # PyTorch inits to zero - if group['momentum'] > 0: - state['momentum_buffer'] = torch.zeros_like(p.data) - if group['centered']: - state['grad_avg'] = torch.zeros_like(p.data) - - square_avg = state['square_avg'] - one_minus_alpha = 1. - group['alpha'] - - state['step'] += 1 - - if group['weight_decay'] != 0: - if 'decoupled_decay' in group and group['decoupled_decay']: - p.data.add_(-group['weight_decay'], p.data) - else: - grad = grad.add(group['weight_decay'], p.data) - - # Tensorflow order of ops for updating squared avg - square_avg.add_(one_minus_alpha, grad.pow(2) - square_avg) - # square_avg.mul_(alpha).addcmul_(1 - alpha, grad, grad) # PyTorch original - - if group['centered']: - grad_avg = state['grad_avg'] - grad_avg.add_(one_minus_alpha, grad - grad_avg) - # grad_avg.mul_(alpha).add_(1 - alpha, grad) # PyTorch original - avg = square_avg.addcmul(-1, grad_avg, grad_avg).add(group['eps']).sqrt_() # eps moved in sqrt - else: - avg = square_avg.add(group['eps']).sqrt_() # eps moved in sqrt - - if group['momentum'] > 0: - buf = state['momentum_buffer'] - # Tensorflow accumulates the LR scaling in the momentum buffer - if 'lr_in_momentum' in group and group['lr_in_momentum']: - buf.mul_(group['momentum']).addcdiv_(group['lr'], grad, avg) - p.data.add_(-buf) - else: - # PyTorch scales the param update by LR - buf.mul_(group['momentum']).addcdiv_(grad, avg) - p.data.add_(-group['lr'], buf) - else: - p.data.addcdiv_(-group['lr'], grad, avg) - +# Copyright [yyyy] [name of copyright owner] +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +from torch.optim import Optimizer + +class RMSpropTF(Optimizer): + """Implements RMSprop algorithm (TensorFlow style epsilon) + + NOTE: This is a direct cut-and-paste of PyTorch RMSprop with eps applied before sqrt + to closer match Tensorflow for matching hyper-params. + + Proposed by G. Hinton in his + `course `_. + + The centered version first appears in `Generating Sequences + With Recurrent Neural Networks `_. + + Arguments: + params (iterable): iterable of parameters to optimize or dicts defining + parameter groups + lr (float, optional): learning rate (default: 1e-2) + momentum (float, optional): momentum factor (default: 0) + alpha (float, optional): smoothing (decay) constant (default: 0.9) + eps (float, optional): term added to the denominator to improve + numerical stability (default: 1e-10) + centered (bool, optional) : if ``True``, compute the centered RMSProp, + the gradient is normalized by an estimation of its variance + weight_decay (float, optional): weight decay (L2 penalty) (default: 0) + decoupled_decay (bool, optional): decoupled weight decay as per https://arxiv.org/abs/1711.05101 + lr_in_momentum (bool, optional): learning rate scaling is included in the momentum buffer + update as per defaults in Tensorflow + + """ + + def __init__(self, params, lr=1e-2, alpha=0.9, eps=1e-10, weight_decay=0, momentum=0., centered=False, + decoupled_decay=False, lr_in_momentum=True): + if not 0.0 <= lr: + raise ValueError("Invalid learning rate: {}".format(lr)) + if not 0.0 <= eps: + raise ValueError("Invalid epsilon value: {}".format(eps)) + if not 0.0 <= momentum: + raise ValueError("Invalid momentum value: {}".format(momentum)) + if not 0.0 <= weight_decay: + raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) + if not 0.0 <= alpha: + raise ValueError("Invalid alpha value: {}".format(alpha)) + + defaults = dict(lr=lr, momentum=momentum, alpha=alpha, eps=eps, centered=centered, weight_decay=weight_decay, + decoupled_decay=decoupled_decay, lr_in_momentum=lr_in_momentum) + super(RMSpropTF, self).__init__(params, defaults) + + def __setstate__(self, state): + super(RMSpropTF, self).__setstate__(state) + for group in self.param_groups: + group.setdefault('momentum', 0) + group.setdefault('centered', False) + + def step(self, closure=None): + """Performs a single optimization step. + + Arguments: + closure (callable, optional): A closure that reevaluates the model + and returns the loss. + """ + loss = None + if closure is not None: + loss = closure() + + for group in self.param_groups: + for p in group['params']: + if p.grad is None: + continue + grad = p.grad.data + if grad.is_sparse: + raise RuntimeError('RMSprop does not support sparse gradients') + state = self.state[p] + + # State initialization + if len(state) == 0: + state['step'] = 0 + state['square_avg'] = torch.ones_like(p.data) # PyTorch inits to zero + if group['momentum'] > 0: + state['momentum_buffer'] = torch.zeros_like(p.data) + if group['centered']: + state['grad_avg'] = torch.zeros_like(p.data) + + square_avg = state['square_avg'] + one_minus_alpha = 1. - group['alpha'] + + state['step'] += 1 + + if group['weight_decay'] != 0: + if 'decoupled_decay' in group and group['decoupled_decay']: + p.data.add_(-group['weight_decay'], p.data) + else: + grad = grad.add(group['weight_decay'], p.data) + + # Tensorflow order of ops for updating squared avg + square_avg.add_(one_minus_alpha, grad.pow(2) - square_avg) + # square_avg.mul_(alpha).addcmul_(1 - alpha, grad, grad) # PyTorch original + + if group['centered']: + grad_avg = state['grad_avg'] + grad_avg.add_(one_minus_alpha, grad - grad_avg) + # grad_avg.mul_(alpha).add_(1 - alpha, grad) # PyTorch original + avg = square_avg.addcmul(-1, grad_avg, grad_avg).add(group['eps']).sqrt_() # eps moved in sqrt + else: + avg = square_avg.add(group['eps']).sqrt_() # eps moved in sqrt + + if group['momentum'] > 0: + buf = state['momentum_buffer'] + # Tensorflow accumulates the LR scaling in the momentum buffer + if 'lr_in_momentum' in group and group['lr_in_momentum']: + buf.mul_(group['momentum']).addcdiv_(group['lr'], grad, avg) + p.data.add_(-buf) + else: + # PyTorch scales the param update by LR + buf.mul_(group['momentum']).addcdiv_(grad, avg) + p.data.add_(-group['lr'], buf) + else: + p.data.addcdiv_(-group['lr'], grad, avg) + return loss \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/utils.py b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/utils.py index 2c562e625c61fb9bfb0734e662df151f179bcbde..1dbf13b4a82b523e7a40e1c797162a10f90b5a83 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/utils.py +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/efficientnet_pytorch/utils.py @@ -1,636 +1,636 @@ -# Copyright [yyyy] [name of copyright owner] -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import re -import math -import collections -from functools import partial -import torch -from torch import nn -from torch.nn import functional as F -from torch.utils import model_zoo - -################################################################################ -### Help functions for model architecture -################################################################################ - -# GlobalParams and BlockArgs: Two namedtuples -# Swish and MemoryEfficientSwish: Two implementations of the method -# round_filters and round_repeats: -# Functions to calculate params for scaling model width and depth ! ! ! -# get_width_and_height_from_size and calculate_output_image_size -# drop_connect: A structural design -# get_same_padding_conv2d: -# Conv2dDynamicSamePadding -# Conv2dStaticSamePadding -# get_same_padding_maxPool2d: -# MaxPool2dDynamicSamePadding -# MaxPool2dStaticSamePadding -# It's an additional function, not used in EfficientNet, -# but can be used in other model (such as EfficientDet). -# Identity: An implementation of identical mapping - -# Parameters for the entire model (stem, all blocks, and head) -GlobalParams = collections.namedtuple('GlobalParams', [ - 'width_coefficient', 'depth_coefficient', 'image_size', 'dropout_rate', - 'num_classes', 'batch_norm_momentum', 'batch_norm_epsilon', - 'drop_connect_rate', 'depth_divisor', 'min_depth']) - -# Parameters for an individual model block -BlockArgs = collections.namedtuple('BlockArgs', [ - 'num_repeat', 'kernel_size', 'stride', 'expand_ratio', - 'input_filters', 'output_filters', 'se_ratio', 'id_skip']) - -# Set GlobalParams and BlockArgs's defaults -GlobalParams.__new__.__defaults__ = (None,) * len(GlobalParams._fields) -BlockArgs.__new__.__defaults__ = (None,) * len(BlockArgs._fields) - - -# An ordinary implementation of Swish function -class Swish(nn.Module): - def forward(self, x): - return x * torch.sigmoid(x) - -# A memory-efficient implementation of Swish function -class SwishImplementation(torch.autograd.Function): - @staticmethod - def forward(ctx, i): - result = i * torch.sigmoid(i) - ctx.save_for_backward(i) - return result - - @staticmethod - def backward(ctx, grad_output): - i = ctx.saved_tensors[0] - sigmoid_i = torch.sigmoid(i) - return grad_output * (sigmoid_i * (1 + i * (1 - sigmoid_i))) - -class MemoryEfficientSwish(nn.Module): - def forward(self, x): - return SwishImplementation.apply(x) - - -def round_filters(filters, global_params): - """Calculate and round number of filters based on width multiplier. - Use width_coefficient, depth_divisor and min_depth of global_params. - - Args: - filters (int): Filters number to be calculated. - global_params (namedtuple): Global params of the model. - - Returns: - new_filters: New filters number after calculating. - """ - multiplier = global_params.width_coefficient - if not multiplier: - return filters - # TODO: modify the params names. - # maybe the names (width_divisor,min_width) - # are more suitable than (depth_divisor,min_depth). - divisor = global_params.depth_divisor - min_depth = global_params.min_depth - filters *= multiplier - min_depth = min_depth or divisor # pay attention to this line when using min_depth - # follow the formula transferred from official TensorFlow implementation - new_filters = max(min_depth, int(filters + divisor / 2) // divisor * divisor) - if new_filters < 0.9 * filters: # prevent rounding by more than 10% - new_filters += divisor - return int(new_filters) - - -def round_repeats(repeats, global_params): - """Calculate module's repeat number of a block based on depth multiplier. - Use depth_coefficient of global_params. - - Args: - repeats (int): num_repeat to be calculated. - global_params (namedtuple): Global params of the model. - - Returns: - new repeat: New repeat number after calculating. - """ - multiplier = global_params.depth_coefficient - if not multiplier: - return repeats - # follow the formula transferred from official TensorFlow implementation - return int(math.ceil(multiplier * repeats)) - - -def drop_connect(inputs, p, training): - """Drop connect. - - Args: - inputs (tensor: BCWH): Input of this structure. - p (float: 0.0~1.0): Probability of drop connection. - training (bool): The running mode. - - Returns: - output: Output after drop connection. - """ - assert p >= 0 and p <= 1, 'p must be in range of [0,1]' - - if not training: - return inputs - - batch_size = inputs.shape[0] - keep_prob = 1 - p - - # generate binary_tensor mask according to probability (p for 0, 1-p for 1) - random_tensor = keep_prob - random_tensor += torch.rand([batch_size, 1, 1, 1], dtype=inputs.dtype, device=inputs.device) - binary_tensor = torch.floor(random_tensor) / keep_prob - - output = inputs * binary_tensor - return output - - -def get_width_and_height_from_size(x): - """Obtain height and width from x. - - Args: - x (int, tuple or list): Data size. - - Returns: - size: A tuple or list (H,W). - """ - if isinstance(x, int): - return x, x - if isinstance(x, list) or isinstance(x, tuple): - return x - else: - raise TypeError() - - -def calculate_output_image_size(input_image_size, stride): - """Calculates the output image size when using Conv2dSamePadding with a stride. - Necessary for static padding. Thanks to mannatsingh for pointing this out. - - Args: - input_image_size (int, tuple or list): Size of input image. - stride (int, tuple or list): Conv2d operation's stride. - - Returns: - output_image_size: A list [H,W]. - """ - if input_image_size is None: - return None - image_height, image_width = get_width_and_height_from_size(input_image_size) - stride = stride if isinstance(stride, int) else stride[0] - image_height = int(math.ceil(image_height / stride)) - image_width = int(math.ceil(image_width / stride)) - return [image_height, image_width] - - -# Note: -# The following 'SamePadding' functions make output size equal ceil(input size/stride). -# Only when stride equals 1, can the output size be the same as input size. -# Don't be confused by their function names ! ! ! - -def get_same_padding_conv2d(image_size=None): - """Chooses static padding if you have specified an image size, and dynamic padding otherwise. - Static padding is necessary for ONNX exporting of models. - - Args: - image_size (int or tuple): Size of the image. - - Returns: - Conv2dDynamicSamePadding or Conv2dStaticSamePadding. - """ - if image_size is None: - return Conv2dDynamicSamePadding - else: - return partial(Conv2dStaticSamePadding, image_size=image_size) - - -class Conv2dDynamicSamePadding(nn.Conv2d): - """2D Convolutions like TensorFlow, for a dynamic image size. - The padding is operated in forward function by calculating dynamically. - """ - - # Tips for 'SAME' mode padding. - # Given the following: - # i: width or height - # s: stride - # k: kernel size - # d: dilation - # p: padding - # Output after Conv2d: - # o = floor((i+p-((k-1)*d+1))/s+1) - # If o equals i, i = floor((i+p-((k-1)*d+1))/s+1), - # => p = (i-1)*s+((k-1)*d+1)-i - - def __init__(self, in_channels, out_channels, kernel_size, stride=1, dilation=1, groups=1, bias=True): - super().__init__(in_channels, out_channels, kernel_size, stride, 0, dilation, groups, bias) - self.stride = self.stride if len(self.stride) == 2 else [self.stride[0]] * 2 - - def forward(self, x): - ih, iw = x.size()[-2:] - kh, kw = self.weight.size()[-2:] - sh, sw = self.stride - oh, ow = math.ceil(ih / sh), math.ceil(iw / sw) # change the output size according to stride ! ! ! - pad_h = max((oh - 1) * self.stride[0] + (kh - 1) * self.dilation[0] + 1 - ih, 0) - pad_w = max((ow - 1) * self.stride[1] + (kw - 1) * self.dilation[1] + 1 - iw, 0) - if pad_h > 0 or pad_w > 0: - x = F.pad(x, [pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h - pad_h // 2]) - return F.conv2d(x, self.weight, self.bias, self.stride, self.padding, self.dilation, self.groups) - - -class Conv2dStaticSamePadding(nn.Conv2d): - """2D Convolutions like TensorFlow's 'SAME' mode, with the given input image size. - The padding mudule is calculated in construction function, then used in forward. - """ - - # With the same calculation as Conv2dDynamicSamePadding - - def __init__(self, in_channels, out_channels, kernel_size, stride=1, image_size=None, **kwargs): - super().__init__(in_channels, out_channels, kernel_size, stride, **kwargs) - self.stride = self.stride if len(self.stride) == 2 else [self.stride[0]] * 2 - - # Calculate padding based on image size and save it - assert image_size is not None - ih, iw = (image_size, image_size) if isinstance(image_size, int) else image_size - kh, kw = self.weight.size()[-2:] - sh, sw = self.stride - oh, ow = math.ceil(ih / sh), math.ceil(iw / sw) - pad_h = max((oh - 1) * self.stride[0] + (kh - 1) * self.dilation[0] + 1 - ih, 0) - pad_w = max((ow - 1) * self.stride[1] + (kw - 1) * self.dilation[1] + 1 - iw, 0) - if pad_h > 0 or pad_w > 0: - self.static_padding = nn.ZeroPad2d((pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h - pad_h // 2)) - if kh % 2 != 0: - self.padding = (kh - 1) // 2 - else: - self.padding = kh // 2 - else: - self.static_padding = Identity() - - def forward(self, x): - x = F.conv2d(x, self.weight, self.bias, self.stride, self.padding, self.dilation, self.groups) - return x - - -def get_same_padding_maxPool2d(image_size=None): - """Chooses static padding if you have specified an image size, and dynamic padding otherwise. - Static padding is necessary for ONNX exporting of models. - - Args: - image_size (int or tuple): Size of the image. - - Returns: - MaxPool2dDynamicSamePadding or MaxPool2dStaticSamePadding. - """ - if image_size is None: - return MaxPool2dDynamicSamePadding - else: - return partial(MaxPool2dStaticSamePadding, image_size=image_size) - - -class MaxPool2dDynamicSamePadding(nn.MaxPool2d): - """2D MaxPooling like TensorFlow's 'SAME' mode, with a dynamic image size. - The padding is operated in forward function by calculating dynamically. - """ - - def __init__(self, kernel_size, stride, padding=0, dilation=1, return_indices=False, ceil_mode=False): - super().__init__(kernel_size, stride, padding, dilation, return_indices, ceil_mode) - self.stride = [self.stride] * 2 if isinstance(self.stride, int) else self.stride - self.kernel_size = [self.kernel_size] * 2 if isinstance(self.kernel_size, int) else self.kernel_size - self.dilation = [self.dilation] * 2 if isinstance(self.dilation, int) else self.dilation - - def forward(self, x): - ih, iw = x.size()[-2:] - kh, kw = self.kernel_size - sh, sw = self.stride - oh, ow = math.ceil(ih / sh), math.ceil(iw / sw) - pad_h = max((oh - 1) * self.stride[0] + (kh - 1) * self.dilation[0] + 1 - ih, 0) - pad_w = max((ow - 1) * self.stride[1] + (kw - 1) * self.dilation[1] + 1 - iw, 0) - if pad_h > 0 or pad_w > 0: - x = F.pad(x, [pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h - pad_h // 2]) - return F.max_pool2d(x, self.kernel_size, self.stride, self.padding, - self.dilation, self.ceil_mode, self.return_indices) - -class MaxPool2dStaticSamePadding(nn.MaxPool2d): - """2D MaxPooling like TensorFlow's 'SAME' mode, with the given input image size. - The padding mudule is calculated in construction function, then used in forward. - """ - - def __init__(self, kernel_size, stride, image_size=None, **kwargs): - super().__init__(kernel_size, stride, **kwargs) - self.stride = [self.stride] * 2 if isinstance(self.stride, int) else self.stride - self.kernel_size = [self.kernel_size] * 2 if isinstance(self.kernel_size, int) else self.kernel_size - self.dilation = [self.dilation] * 2 if isinstance(self.dilation, int) else self.dilation - - # Calculate padding based on image size and save it - assert image_size is not None - ih, iw = (image_size, image_size) if isinstance(image_size, int) else image_size - kh, kw = self.kernel_size - sh, sw = self.stride - oh, ow = math.ceil(ih / sh), math.ceil(iw / sw) - pad_h = max((oh - 1) * self.stride[0] + (kh - 1) * self.dilation[0] + 1 - ih, 0) - pad_w = max((ow - 1) * self.stride[1] + (kw - 1) * self.dilation[1] + 1 - iw, 0) - if pad_h > 0 or pad_w > 0: - self.static_padding = nn.ZeroPad2d((pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h - pad_h // 2)) - else: - self.static_padding = Identity() - - def forward(self, x): - x = self.static_padding(x) - x = F.max_pool2d(x, self.kernel_size, self.stride, self.padding, - self.dilation, self.ceil_mode, self.return_indices) - return x - -class Identity(nn.Module): - """Identity mapping. - Send input to output directly. - """ - - def __init__(self): - super(Identity, self).__init__() - - def forward(self, input): - return input - - -################################################################################ -### Helper functions for loading model params -################################################################################ - -# BlockDecoder: A Class for encoding and decoding BlockArgs -# efficientnet_params: A function to query compound coefficient -# get_model_params and efficientnet: -# Functions to get BlockArgs and GlobalParams for efficientnet -# url_map and url_map_advprop: Dicts of url_map for pretrained weights -# load_pretrained_weights: A function to load pretrained weights - -class BlockDecoder(object): - """Block Decoder for readability, - straight from the official TensorFlow repository. - """ - - @staticmethod - def _decode_block_string(block_string): - """Get a block through a string notation of arguments. - - Args: - block_string (str): A string notation of arguments. - Examples: 'r1_k3_s11_e1_i32_o16_se0.25_noskip'. - - Returns: - BlockArgs: The namedtuple defined at the top of this file. - """ - assert isinstance(block_string, str) - - ops = block_string.split('_') - options = {} - for op in ops: - splits = re.split(r'(\d.*)', op) - if len(splits) >= 2: - key, value = splits[:2] - options[key] = value - - # Check stride - assert (('s' in options and len(options['s']) == 1) or - (len(options['s']) == 2 and options['s'][0] == options['s'][1])) - - return BlockArgs( - num_repeat=int(options['r']), - kernel_size=int(options['k']), - stride=[int(options['s'][0])], - expand_ratio=int(options['e']), - input_filters=int(options['i']), - output_filters=int(options['o']), - se_ratio=float(options['se']) if 'se' in options else None, - id_skip=('noskip' not in block_string)) - - @staticmethod - def _encode_block_string(block): - """Encode a block to a string. - - Args: - block (namedtuple): A BlockArgs type argument. - - Returns: - block_string: A String form of BlockArgs. - """ - args = [ - 'r%d' % block.num_repeat, - 'k%d' % block.kernel_size, - 's%d%d' % (block.strides[0], block.strides[1]), - 'e%s' % block.expand_ratio, - 'i%d' % block.input_filters, - 'o%d' % block.output_filters - ] - if 0 < block.se_ratio <= 1: - args.append('se%s' % block.se_ratio) - if block.id_skip is False: - args.append('noskip') - return '_'.join(args) - - @staticmethod - def decode(string_list): - """Decode a list of string notations to specify blocks inside the network. - - Args: - string_list (list[str]): A list of strings, each string is a notation of block. - - Returns: - blocks_args: A list of BlockArgs namedtuples of block args. - """ - assert isinstance(string_list, list) - blocks_args = [] - for block_string in string_list: - blocks_args.append(BlockDecoder._decode_block_string(block_string)) - return blocks_args - - @staticmethod - def encode(blocks_args): - """Encode a list of BlockArgs to a list of strings. - - Args: - blocks_args (list[namedtuples]): A list of BlockArgs namedtuples of block args. - - Returns: - block_strings: A list of strings, each string is a notation of block. - """ - block_strings = [] - for block in blocks_args: - block_strings.append(BlockDecoder._encode_block_string(block)) - return block_strings - - -def efficientnet_params(model_name): - """Map EfficientNet model name to parameter coefficients. - - Args: - model_name (str): Model name to be queried. - - Returns: - params_dict[model_name]: A (width,depth,res,dropout) tuple. - """ - params_dict = { - # Coefficients: width,depth,res,dropout - 'efficientnet-b0': (1.0, 1.0, 224, 0.2), - 'efficientnet-b1': (1.0, 1.1, 240, 0.2), - 'efficientnet-b2': (1.1, 1.2, 260, 0.3), - 'efficientnet-b3': (1.2, 1.4, 300, 0.3), - 'efficientnet-b4': (1.4, 1.8, 380, 0.4), - 'efficientnet-b5': (1.6, 2.2, 456, 0.4), - 'efficientnet-b6': (1.8, 2.6, 528, 0.5), - 'efficientnet-b7': (2.0, 3.1, 600, 0.5), - 'efficientnet-b8': (2.2, 3.6, 672, 0.5), - 'efficientnet-l2': (4.3, 5.3, 800, 0.5), - } - return params_dict[model_name] - - -def efficientnet(width_coefficient=None, depth_coefficient=None, image_size=None, - dropout_rate=0.2, drop_connect_rate=0.2, num_classes=1000): - """Create BlockArgs and GlobalParams for efficientnet model. - - Args: - width_coefficient (float) - depth_coefficient (float) - image_size (int) - dropout_rate (float) - drop_connect_rate (float) - num_classes (int) - - Meaning as the name suggests. - - Returns: - blocks_args, global_params. - """ - - # Blocks args for the whole model(efficientnet-b0 by default) - # It will be modified in the construction of EfficientNet Class according to model - blocks_args = [ - 'r1_k3_s11_e1_i32_o16_se0.25', - 'r2_k3_s22_e6_i16_o24_se0.25', - 'r2_k5_s22_e6_i24_o40_se0.25', - 'r3_k3_s22_e6_i40_o80_se0.25', - 'r3_k5_s11_e6_i80_o112_se0.25', - 'r4_k5_s22_e6_i112_o192_se0.25', - 'r1_k3_s11_e6_i192_o320_se0.25', - ] - - blocks_args = BlockDecoder.decode(blocks_args) - - global_params = GlobalParams( - width_coefficient=width_coefficient, - depth_coefficient=depth_coefficient, - image_size=image_size, - dropout_rate=dropout_rate, - - num_classes=num_classes, - batch_norm_momentum=0.99, - batch_norm_epsilon=1e-3, - drop_connect_rate=drop_connect_rate, - depth_divisor=8, - min_depth=None, - ) - - return blocks_args, global_params - - -def get_model_params(model_name, override_params): - """Get the block args and global params for a given model name. - - Args: - model_name (str): Model's name. - override_params (dict): A dict to modify global_params. - - Returns: - blocks_args, global_params - """ - if model_name.startswith('efficientnet'): - w, d, s, p = efficientnet_params(model_name) - # note: all models have drop connect rate = 0.2 - blocks_args, global_params = efficientnet( - width_coefficient=w, depth_coefficient=d, dropout_rate=p, image_size=s) - else: - raise NotImplementedError('model name is not pre-defined: %s' % model_name) - if override_params: - # ValueError will be raised here if override_params has fields not included in global_params. - global_params = global_params._replace(**override_params) - return blocks_args, global_params - - -# train with Standard methods -# check more details in paper(EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks) -url_map = { - 'efficientnet-b0': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b0-355c32eb.pth', - 'efficientnet-b1': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b1-f1951068.pth', - 'efficientnet-b2': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b2-8bb594d6.pth', - 'efficientnet-b3': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b3-5fb5a3c3.pth', - 'efficientnet-b4': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b4-6ed6700e.pth', - 'efficientnet-b5': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b5-b6417697.pth', - 'efficientnet-b6': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b6-c76e70fd.pth', - 'efficientnet-b7': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b7-dcc49843.pth', -} - -# train with Adversarial Examples(AdvProp) -# check more details in paper(Adversarial Examples Improve Image Recognition) -url_map_advprop = { - 'efficientnet-b0': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b0-b64d5a18.pth', - 'efficientnet-b1': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b1-0f3ce85a.pth', - 'efficientnet-b2': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b2-6e9d97e5.pth', - 'efficientnet-b3': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b3-cdd7c0f4.pth', - 'efficientnet-b4': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b4-44fb3a87.pth', - 'efficientnet-b5': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b5-86493f6b.pth', - 'efficientnet-b6': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b6-ac80338e.pth', - 'efficientnet-b7': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b7-4652b6dd.pth', - 'efficientnet-b8': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b8-22a8fe65.pth', -} - -# TODO: add the petrained weights url map of 'efficientnet-l2' - - -def load_pretrained_weights(model, model_name, weights_path=None, load_fc=True, advprop=False): - """Loads pretrained weights from weights path or download using url. - - Args: - model (Module): The whole model of efficientnet. - model_name (str): Model name of efficientnet. - weights_path (None or str): - str: path to pretrained weights file on the local disk. - None: use pretrained weights downloaded from the Internet. - load_fc (bool): Whether to load pretrained weights for fc layer at the end of the model. - advprop (bool): Whether to load pretrained weights - trained with advprop (valid when weights_path is None). - """ - if isinstance(weights_path,str): - state_dict = torch.load(weights_path, map_location='cpu') - else: - # AutoAugment or Advprop (different preprocessing) - url_map_ = url_map_advprop if advprop else url_map - state_dict = model_zoo.load_url(url_map_[model_name]) - if 'state_dict' in state_dict: - state_dict = state_dict['state_dict'] - if 'module.' in list(state_dict.keys())[0]: - state_dict_tmp = dict() - for k, v in state_dict.items(): - state_dict_tmp[k[7:]] = v - state_dict = state_dict_tmp - - if load_fc: - ret = model.load_state_dict(state_dict, strict=False) - assert not ret.missing_keys, f'Missing keys when loading pretrained weights: {ret.missing_keys}' - else: - state_dict.pop('_fc.weight') - state_dict.pop('_fc.bias') - ret = model.load_state_dict(state_dict, strict=False) - assert set(ret.missing_keys) == set( - ['_fc.weight', '_fc.bias']), f'Missing keys when loading pretrained weights: {ret.missing_keys}' - assert not ret.unexpected_keys, f'Missing keys when loading pretrained weights: {ret.unexpected_keys}' - - print('Loaded pretrained weights for {}'.format(model_name)) +# Copyright [yyyy] [name of copyright owner] +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import re +import math +import collections +from functools import partial +import torch +from torch import nn +from torch.nn import functional as F +from torch.utils import model_zoo + +################################################################################ +### Help functions for model architecture +################################################################################ + +# GlobalParams and BlockArgs: Two namedtuples +# Swish and MemoryEfficientSwish: Two implementations of the method +# round_filters and round_repeats: +# Functions to calculate params for scaling model width and depth ! ! ! +# get_width_and_height_from_size and calculate_output_image_size +# drop_connect: A structural design +# get_same_padding_conv2d: +# Conv2dDynamicSamePadding +# Conv2dStaticSamePadding +# get_same_padding_maxPool2d: +# MaxPool2dDynamicSamePadding +# MaxPool2dStaticSamePadding +# It's an additional function, not used in EfficientNet, +# but can be used in other model (such as EfficientDet). +# Identity: An implementation of identical mapping + +# Parameters for the entire model (stem, all blocks, and head) +GlobalParams = collections.namedtuple('GlobalParams', [ + 'width_coefficient', 'depth_coefficient', 'image_size', 'dropout_rate', + 'num_classes', 'batch_norm_momentum', 'batch_norm_epsilon', + 'drop_connect_rate', 'depth_divisor', 'min_depth']) + +# Parameters for an individual model block +BlockArgs = collections.namedtuple('BlockArgs', [ + 'num_repeat', 'kernel_size', 'stride', 'expand_ratio', + 'input_filters', 'output_filters', 'se_ratio', 'id_skip']) + +# Set GlobalParams and BlockArgs's defaults +GlobalParams.__new__.__defaults__ = (None,) * len(GlobalParams._fields) +BlockArgs.__new__.__defaults__ = (None,) * len(BlockArgs._fields) + + +# An ordinary implementation of Swish function +class Swish(nn.Module): + def forward(self, x): + return x * torch.sigmoid(x) + +# A memory-efficient implementation of Swish function +class SwishImplementation(torch.autograd.Function): + @staticmethod + def forward(ctx, i): + result = i * torch.sigmoid(i) + ctx.save_for_backward(i) + return result + + @staticmethod + def backward(ctx, grad_output): + i = ctx.saved_tensors[0] + sigmoid_i = torch.sigmoid(i) + return grad_output * (sigmoid_i * (1 + i * (1 - sigmoid_i))) + +class MemoryEfficientSwish(nn.Module): + def forward(self, x): + return SwishImplementation.apply(x) + + +def round_filters(filters, global_params): + """Calculate and round number of filters based on width multiplier. + Use width_coefficient, depth_divisor and min_depth of global_params. + + Args: + filters (int): Filters number to be calculated. + global_params (namedtuple): Global params of the model. + + Returns: + new_filters: New filters number after calculating. + """ + multiplier = global_params.width_coefficient + if not multiplier: + return filters + # TODO: modify the params names. + # maybe the names (width_divisor,min_width) + # are more suitable than (depth_divisor,min_depth). + divisor = global_params.depth_divisor + min_depth = global_params.min_depth + filters *= multiplier + min_depth = min_depth or divisor # pay attention to this line when using min_depth + # follow the formula transferred from official TensorFlow implementation + new_filters = max(min_depth, int(filters + divisor / 2) // divisor * divisor) + if new_filters < 0.9 * filters: # prevent rounding by more than 10% + new_filters += divisor + return int(new_filters) + + +def round_repeats(repeats, global_params): + """Calculate module's repeat number of a block based on depth multiplier. + Use depth_coefficient of global_params. + + Args: + repeats (int): num_repeat to be calculated. + global_params (namedtuple): Global params of the model. + + Returns: + new repeat: New repeat number after calculating. + """ + multiplier = global_params.depth_coefficient + if not multiplier: + return repeats + # follow the formula transferred from official TensorFlow implementation + return int(math.ceil(multiplier * repeats)) + + +def drop_connect(inputs, p, training): + """Drop connect. + + Args: + inputs (tensor: BCWH): Input of this structure. + p (float: 0.0~1.0): Probability of drop connection. + training (bool): The running mode. + + Returns: + output: Output after drop connection. + """ + assert p >= 0 and p <= 1, 'p must be in range of [0,1]' + + if not training: + return inputs + + batch_size = inputs.shape[0] + keep_prob = 1 - p + + # generate binary_tensor mask according to probability (p for 0, 1-p for 1) + random_tensor = keep_prob + random_tensor += torch.rand([batch_size, 1, 1, 1], dtype=inputs.dtype, device=inputs.device) + binary_tensor = torch.floor(random_tensor) / keep_prob + + output = inputs * binary_tensor + return output + + +def get_width_and_height_from_size(x): + """Obtain height and width from x. + + Args: + x (int, tuple or list): Data size. + + Returns: + size: A tuple or list (H,W). + """ + if isinstance(x, int): + return x, x + if isinstance(x, list) or isinstance(x, tuple): + return x + else: + raise TypeError() + + +def calculate_output_image_size(input_image_size, stride): + """Calculates the output image size when using Conv2dSamePadding with a stride. + Necessary for static padding. Thanks to mannatsingh for pointing this out. + + Args: + input_image_size (int, tuple or list): Size of input image. + stride (int, tuple or list): Conv2d operation's stride. + + Returns: + output_image_size: A list [H,W]. + """ + if input_image_size is None: + return None + image_height, image_width = get_width_and_height_from_size(input_image_size) + stride = stride if isinstance(stride, int) else stride[0] + image_height = int(math.ceil(image_height / stride)) + image_width = int(math.ceil(image_width / stride)) + return [image_height, image_width] + + +# Note: +# The following 'SamePadding' functions make output size equal ceil(input size/stride). +# Only when stride equals 1, can the output size be the same as input size. +# Don't be confused by their function names ! ! ! + +def get_same_padding_conv2d(image_size=None): + """Chooses static padding if you have specified an image size, and dynamic padding otherwise. + Static padding is necessary for ONNX exporting of models. + + Args: + image_size (int or tuple): Size of the image. + + Returns: + Conv2dDynamicSamePadding or Conv2dStaticSamePadding. + """ + if image_size is None: + return Conv2dDynamicSamePadding + else: + return partial(Conv2dStaticSamePadding, image_size=image_size) + + +class Conv2dDynamicSamePadding(nn.Conv2d): + """2D Convolutions like TensorFlow, for a dynamic image size. + The padding is operated in forward function by calculating dynamically. + """ + + # Tips for 'SAME' mode padding. + # Given the following: + # i: width or height + # s: stride + # k: kernel size + # d: dilation + # p: padding + # Output after Conv2d: + # o = floor((i+p-((k-1)*d+1))/s+1) + # If o equals i, i = floor((i+p-((k-1)*d+1))/s+1), + # => p = (i-1)*s+((k-1)*d+1)-i + + def __init__(self, in_channels, out_channels, kernel_size, stride=1, dilation=1, groups=1, bias=True): + super().__init__(in_channels, out_channels, kernel_size, stride, 0, dilation, groups, bias) + self.stride = self.stride if len(self.stride) == 2 else [self.stride[0]] * 2 + + def forward(self, x): + ih, iw = x.size()[-2:] + kh, kw = self.weight.size()[-2:] + sh, sw = self.stride + oh, ow = math.ceil(ih / sh), math.ceil(iw / sw) # change the output size according to stride ! ! ! + pad_h = max((oh - 1) * self.stride[0] + (kh - 1) * self.dilation[0] + 1 - ih, 0) + pad_w = max((ow - 1) * self.stride[1] + (kw - 1) * self.dilation[1] + 1 - iw, 0) + if pad_h > 0 or pad_w > 0: + x = F.pad(x, [pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h - pad_h // 2]) + return F.conv2d(x, self.weight, self.bias, self.stride, self.padding, self.dilation, self.groups) + + +class Conv2dStaticSamePadding(nn.Conv2d): + """2D Convolutions like TensorFlow's 'SAME' mode, with the given input image size. + The padding mudule is calculated in construction function, then used in forward. + """ + + # With the same calculation as Conv2dDynamicSamePadding + + def __init__(self, in_channels, out_channels, kernel_size, stride=1, image_size=None, **kwargs): + super().__init__(in_channels, out_channels, kernel_size, stride, **kwargs) + self.stride = self.stride if len(self.stride) == 2 else [self.stride[0]] * 2 + + # Calculate padding based on image size and save it + assert image_size is not None + ih, iw = (image_size, image_size) if isinstance(image_size, int) else image_size + kh, kw = self.weight.size()[-2:] + sh, sw = self.stride + oh, ow = math.ceil(ih / sh), math.ceil(iw / sw) + pad_h = max((oh - 1) * self.stride[0] + (kh - 1) * self.dilation[0] + 1 - ih, 0) + pad_w = max((ow - 1) * self.stride[1] + (kw - 1) * self.dilation[1] + 1 - iw, 0) + if pad_h > 0 or pad_w > 0: + self.static_padding = nn.ZeroPad2d((pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h - pad_h // 2)) + if kh % 2 != 0: + self.padding = (kh - 1) // 2 + else: + self.padding = kh // 2 + else: + self.static_padding = Identity() + + def forward(self, x): + x = F.conv2d(x, self.weight, self.bias, self.stride, self.padding, self.dilation, self.groups) + return x + + +def get_same_padding_maxPool2d(image_size=None): + """Chooses static padding if you have specified an image size, and dynamic padding otherwise. + Static padding is necessary for ONNX exporting of models. + + Args: + image_size (int or tuple): Size of the image. + + Returns: + MaxPool2dDynamicSamePadding or MaxPool2dStaticSamePadding. + """ + if image_size is None: + return MaxPool2dDynamicSamePadding + else: + return partial(MaxPool2dStaticSamePadding, image_size=image_size) + + +class MaxPool2dDynamicSamePadding(nn.MaxPool2d): + """2D MaxPooling like TensorFlow's 'SAME' mode, with a dynamic image size. + The padding is operated in forward function by calculating dynamically. + """ + + def __init__(self, kernel_size, stride, padding=0, dilation=1, return_indices=False, ceil_mode=False): + super().__init__(kernel_size, stride, padding, dilation, return_indices, ceil_mode) + self.stride = [self.stride] * 2 if isinstance(self.stride, int) else self.stride + self.kernel_size = [self.kernel_size] * 2 if isinstance(self.kernel_size, int) else self.kernel_size + self.dilation = [self.dilation] * 2 if isinstance(self.dilation, int) else self.dilation + + def forward(self, x): + ih, iw = x.size()[-2:] + kh, kw = self.kernel_size + sh, sw = self.stride + oh, ow = math.ceil(ih / sh), math.ceil(iw / sw) + pad_h = max((oh - 1) * self.stride[0] + (kh - 1) * self.dilation[0] + 1 - ih, 0) + pad_w = max((ow - 1) * self.stride[1] + (kw - 1) * self.dilation[1] + 1 - iw, 0) + if pad_h > 0 or pad_w > 0: + x = F.pad(x, [pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h - pad_h // 2]) + return F.max_pool2d(x, self.kernel_size, self.stride, self.padding, + self.dilation, self.ceil_mode, self.return_indices) + +class MaxPool2dStaticSamePadding(nn.MaxPool2d): + """2D MaxPooling like TensorFlow's 'SAME' mode, with the given input image size. + The padding mudule is calculated in construction function, then used in forward. + """ + + def __init__(self, kernel_size, stride, image_size=None, **kwargs): + super().__init__(kernel_size, stride, **kwargs) + self.stride = [self.stride] * 2 if isinstance(self.stride, int) else self.stride + self.kernel_size = [self.kernel_size] * 2 if isinstance(self.kernel_size, int) else self.kernel_size + self.dilation = [self.dilation] * 2 if isinstance(self.dilation, int) else self.dilation + + # Calculate padding based on image size and save it + assert image_size is not None + ih, iw = (image_size, image_size) if isinstance(image_size, int) else image_size + kh, kw = self.kernel_size + sh, sw = self.stride + oh, ow = math.ceil(ih / sh), math.ceil(iw / sw) + pad_h = max((oh - 1) * self.stride[0] + (kh - 1) * self.dilation[0] + 1 - ih, 0) + pad_w = max((ow - 1) * self.stride[1] + (kw - 1) * self.dilation[1] + 1 - iw, 0) + if pad_h > 0 or pad_w > 0: + self.static_padding = nn.ZeroPad2d((pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h - pad_h // 2)) + else: + self.static_padding = Identity() + + def forward(self, x): + x = self.static_padding(x) + x = F.max_pool2d(x, self.kernel_size, self.stride, self.padding, + self.dilation, self.ceil_mode, self.return_indices) + return x + +class Identity(nn.Module): + """Identity mapping. + Send input to output directly. + """ + + def __init__(self): + super(Identity, self).__init__() + + def forward(self, input): + return input + + +################################################################################ +### Helper functions for loading model params +################################################################################ + +# BlockDecoder: A Class for encoding and decoding BlockArgs +# efficientnet_params: A function to query compound coefficient +# get_model_params and efficientnet: +# Functions to get BlockArgs and GlobalParams for efficientnet +# url_map and url_map_advprop: Dicts of url_map for pretrained weights +# load_pretrained_weights: A function to load pretrained weights + +class BlockDecoder(object): + """Block Decoder for readability, + straight from the official TensorFlow repository. + """ + + @staticmethod + def _decode_block_string(block_string): + """Get a block through a string notation of arguments. + + Args: + block_string (str): A string notation of arguments. + Examples: 'r1_k3_s11_e1_i32_o16_se0.25_noskip'. + + Returns: + BlockArgs: The namedtuple defined at the top of this file. + """ + assert isinstance(block_string, str) + + ops = block_string.split('_') + options = {} + for op in ops: + splits = re.split(r'(\d.*)', op) + if len(splits) >= 2: + key, value = splits[:2] + options[key] = value + + # Check stride + assert (('s' in options and len(options['s']) == 1) or + (len(options['s']) == 2 and options['s'][0] == options['s'][1])) + + return BlockArgs( + num_repeat=int(options['r']), + kernel_size=int(options['k']), + stride=[int(options['s'][0])], + expand_ratio=int(options['e']), + input_filters=int(options['i']), + output_filters=int(options['o']), + se_ratio=float(options['se']) if 'se' in options else None, + id_skip=('noskip' not in block_string)) + + @staticmethod + def _encode_block_string(block): + """Encode a block to a string. + + Args: + block (namedtuple): A BlockArgs type argument. + + Returns: + block_string: A String form of BlockArgs. + """ + args = [ + 'r%d' % block.num_repeat, + 'k%d' % block.kernel_size, + 's%d%d' % (block.strides[0], block.strides[1]), + 'e%s' % block.expand_ratio, + 'i%d' % block.input_filters, + 'o%d' % block.output_filters + ] + if 0 < block.se_ratio <= 1: + args.append('se%s' % block.se_ratio) + if block.id_skip is False: + args.append('noskip') + return '_'.join(args) + + @staticmethod + def decode(string_list): + """Decode a list of string notations to specify blocks inside the network. + + Args: + string_list (list[str]): A list of strings, each string is a notation of block. + + Returns: + blocks_args: A list of BlockArgs namedtuples of block args. + """ + assert isinstance(string_list, list) + blocks_args = [] + for block_string in string_list: + blocks_args.append(BlockDecoder._decode_block_string(block_string)) + return blocks_args + + @staticmethod + def encode(blocks_args): + """Encode a list of BlockArgs to a list of strings. + + Args: + blocks_args (list[namedtuples]): A list of BlockArgs namedtuples of block args. + + Returns: + block_strings: A list of strings, each string is a notation of block. + """ + block_strings = [] + for block in blocks_args: + block_strings.append(BlockDecoder._encode_block_string(block)) + return block_strings + + +def efficientnet_params(model_name): + """Map EfficientNet model name to parameter coefficients. + + Args: + model_name (str): Model name to be queried. + + Returns: + params_dict[model_name]: A (width,depth,res,dropout) tuple. + """ + params_dict = { + # Coefficients: width,depth,res,dropout + 'efficientnet-b0': (1.0, 1.0, 224, 0.2), + 'efficientnet-b1': (1.0, 1.1, 240, 0.2), + 'efficientnet-b2': (1.1, 1.2, 260, 0.3), + 'efficientnet-b3': (1.2, 1.4, 300, 0.3), + 'efficientnet-b4': (1.4, 1.8, 380, 0.4), + 'efficientnet-b5': (1.6, 2.2, 456, 0.4), + 'efficientnet-b6': (1.8, 2.6, 528, 0.5), + 'efficientnet-b7': (2.0, 3.1, 600, 0.5), + 'efficientnet-b8': (2.2, 3.6, 672, 0.5), + 'efficientnet-l2': (4.3, 5.3, 800, 0.5), + } + return params_dict[model_name] + + +def efficientnet(width_coefficient=None, depth_coefficient=None, image_size=None, + dropout_rate=0.2, drop_connect_rate=0.2, num_classes=1000): + """Create BlockArgs and GlobalParams for efficientnet model. + + Args: + width_coefficient (float) + depth_coefficient (float) + image_size (int) + dropout_rate (float) + drop_connect_rate (float) + num_classes (int) + + Meaning as the name suggests. + + Returns: + blocks_args, global_params. + """ + + # Blocks args for the whole model(efficientnet-b0 by default) + # It will be modified in the construction of EfficientNet Class according to model + blocks_args = [ + 'r1_k3_s11_e1_i32_o16_se0.25', + 'r2_k3_s22_e6_i16_o24_se0.25', + 'r2_k5_s22_e6_i24_o40_se0.25', + 'r3_k3_s22_e6_i40_o80_se0.25', + 'r3_k5_s11_e6_i80_o112_se0.25', + 'r4_k5_s22_e6_i112_o192_se0.25', + 'r1_k3_s11_e6_i192_o320_se0.25', + ] + + blocks_args = BlockDecoder.decode(blocks_args) + + global_params = GlobalParams( + width_coefficient=width_coefficient, + depth_coefficient=depth_coefficient, + image_size=image_size, + dropout_rate=dropout_rate, + + num_classes=num_classes, + batch_norm_momentum=0.99, + batch_norm_epsilon=1e-3, + drop_connect_rate=drop_connect_rate, + depth_divisor=8, + min_depth=None, + ) + + return blocks_args, global_params + + +def get_model_params(model_name, override_params): + """Get the block args and global params for a given model name. + + Args: + model_name (str): Model's name. + override_params (dict): A dict to modify global_params. + + Returns: + blocks_args, global_params + """ + if model_name.startswith('efficientnet'): + w, d, s, p = efficientnet_params(model_name) + # note: all models have drop connect rate = 0.2 + blocks_args, global_params = efficientnet( + width_coefficient=w, depth_coefficient=d, dropout_rate=p, image_size=s) + else: + raise NotImplementedError('model name is not pre-defined: %s' % model_name) + if override_params: + # ValueError will be raised here if override_params has fields not included in global_params. + global_params = global_params._replace(**override_params) + return blocks_args, global_params + + +# train with Standard methods +# check more details in paper(EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks) +url_map = { + 'efficientnet-b0': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b0-355c32eb.pth', + 'efficientnet-b1': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b1-f1951068.pth', + 'efficientnet-b2': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b2-8bb594d6.pth', + 'efficientnet-b3': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b3-5fb5a3c3.pth', + 'efficientnet-b4': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b4-6ed6700e.pth', + 'efficientnet-b5': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b5-b6417697.pth', + 'efficientnet-b6': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b6-c76e70fd.pth', + 'efficientnet-b7': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b7-dcc49843.pth', +} + +# train with Adversarial Examples(AdvProp) +# check more details in paper(Adversarial Examples Improve Image Recognition) +url_map_advprop = { + 'efficientnet-b0': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b0-b64d5a18.pth', + 'efficientnet-b1': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b1-0f3ce85a.pth', + 'efficientnet-b2': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b2-6e9d97e5.pth', + 'efficientnet-b3': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b3-cdd7c0f4.pth', + 'efficientnet-b4': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b4-44fb3a87.pth', + 'efficientnet-b5': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b5-86493f6b.pth', + 'efficientnet-b6': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b6-ac80338e.pth', + 'efficientnet-b7': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b7-4652b6dd.pth', + 'efficientnet-b8': 'https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/adv-efficientnet-b8-22a8fe65.pth', +} + +# TODO: add the petrained weights url map of 'efficientnet-l2' + + +def load_pretrained_weights(model, model_name, weights_path=None, load_fc=True, advprop=False): + """Loads pretrained weights from weights path or download using url. + + Args: + model (Module): The whole model of efficientnet. + model_name (str): Model name of efficientnet. + weights_path (None or str): + str: path to pretrained weights file on the local disk. + None: use pretrained weights downloaded from the Internet. + load_fc (bool): Whether to load pretrained weights for fc layer at the end of the model. + advprop (bool): Whether to load pretrained weights + trained with advprop (valid when weights_path is None). + """ + if isinstance(weights_path,str): + state_dict = torch.load(weights_path, map_location='cpu') + else: + # AutoAugment or Advprop (different preprocessing) + url_map_ = url_map_advprop if advprop else url_map + state_dict = model_zoo.load_url(url_map_[model_name]) + if 'state_dict' in state_dict: + state_dict = state_dict['state_dict'] + if 'module.' in list(state_dict.keys())[0]: + state_dict_tmp = dict() + for k, v in state_dict.items(): + state_dict_tmp[k[7:]] = v + state_dict = state_dict_tmp + + if load_fc: + ret = model.load_state_dict(state_dict, strict=False) + assert not ret.missing_keys, f'Missing keys when loading pretrained weights: {ret.missing_keys}' + else: + state_dict.pop('_fc.weight') + state_dict.pop('_fc.bias') + ret = model.load_state_dict(state_dict, strict=False) + assert set(ret.missing_keys) == set( + ['_fc.weight', '_fc.bias']), f'Missing keys when loading pretrained weights: {ret.missing_keys}' + assert not ret.unexpected_keys, f'Missing keys when loading pretrained weights: {ret.unexpected_keys}' + + print('Loaded pretrained weights for {}'.format(model_name)) diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/examples/imagenet/README.md b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/examples/imagenet/README.md index 8f7f89b212a6165af308d60ccbc8d445facc5a33..fcafce33a6d3915a353eae374b55e72a3c1cc143 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/examples/imagenet/README.md +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/examples/imagenet/README.md @@ -1,23 +1,23 @@ -### Imagenet - -This is a preliminary directory for evaluating the model on ImageNet. It is adapted from the standard PyTorch Imagenet script. - -For now, only evaluation is supported, but I am currently building scripts to assist with training new models on Imagenet. - -The evaluation results are slightly different from the original TensorFlow repository, due to differences in data preprocessing. For example, with the current preprocessing, `efficientnet-b3` gives a top-1 accuracy of `80.8`, rather than `81.1` in the paper. I am working on porting the TensorFlow preprocessing into PyTorch to address this issue. - -To run on Imagenet, place your `train` and `val` directories in `data`. - -Example commands: -```bash -# Evaluate small EfficientNet on CPU -python main.py data -e -a 'efficientnet-b0' --pretrained -``` -```bash -# Evaluate medium EfficientNet on GPU -python main.py data -e -a 'efficientnet-b3' --pretrained --gpu 0 --batch-size 128 -``` -```bash -# Evaluate ResNet-50 for comparison -python main.py data -e -a 'resnet50' --pretrained --gpu 0 -``` +### Imagenet + +This is a preliminary directory for evaluating the model on ImageNet. It is adapted from the standard PyTorch Imagenet script. + +For now, only evaluation is supported, but I am currently building scripts to assist with training new models on Imagenet. + +The evaluation results are slightly different from the original TensorFlow repository, due to differences in data preprocessing. For example, with the current preprocessing, `efficientnet-b3` gives a top-1 accuracy of `80.8`, rather than `81.1` in the paper. I am working on porting the TensorFlow preprocessing into PyTorch to address this issue. + +To run on Imagenet, place your `train` and `val` directories in `data`. + +Example commands: +```bash +# Evaluate small EfficientNet on CPU +python main.py data -e -a 'efficientnet-b0' --pretrained +``` +```bash +# Evaluate medium EfficientNet on GPU +python main.py data -e -a 'efficientnet-b3' --pretrained --gpu 0 --batch-size 128 +``` +```bash +# Evaluate ResNet-50 for comparison +python main.py data -e -a 'resnet50' --pretrained --gpu 0 +``` diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/examples/imagenet/data/README.md b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/examples/imagenet/data/README.md index 21a3317e9c7dc0e0e48f1e21eaee091a57eaabd5..310c6e0df88a16c4fc922b00adb50841f711080d 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/examples/imagenet/data/README.md +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/examples/imagenet/data/README.md @@ -1,5 +1,5 @@ -### ImageNet - -Download ImageNet and place it into `train` and `val` folders here. - -More details may be found with the official PyTorch ImageNet example [here](https://github.com/pytorch/examples/blob/master/imagenet). +### ImageNet + +Download ImageNet and place it into `train` and `val` folders here. + +More details may be found with the official PyTorch ImageNet example [here](https://github.com/pytorch/examples/blob/master/imagenet). diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/examples/imagenet/main.py b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/examples/imagenet/main.py index d8343ad748952ac5faefb4dfde02761b7f5a66cc..79ebf12fe7aa7b6dcc5a77d82c0c7da475383d17 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/examples/imagenet/main.py +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/examples/imagenet/main.py @@ -1,545 +1,545 @@ -# Copyright [yyyy] [name of copyright owner] -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import os -import re -import sys -import time -import PIL -import numpy as np - -import torch -import torch.nn as nn -import torch.nn.parallel -import torch.distributed as dist -import torch.optim -import torch.multiprocessing as mp -import torch.utils.data -import torch.utils.data.distributed -import torchvision.transforms as transforms -import torchvision.datasets as datasets -import torchvision.models as models -import apex -from apex import amp - -sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),'../../')) -from efficientnet_pytorch import EfficientNet -from efficientnet_pytorch import rand_augment_transform, augment_and_mix_transform, auto_augment_transform - -parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') -parser.add_argument('--data', metavar='DIR', - help='path to dataset') -parser.add_argument('-a', '--arch', metavar='ARCH', default='resnet18', - help='model architecture (default: resnet18)') -parser.add_argument('-j', '--workers', default=64, type=int, metavar='N', - help='number of data loading workers (default: 4)') -parser.add_argument('--epochs', default=90, type=int, metavar='N', - help='number of total epochs to run') -parser.add_argument('--start-epoch', default=0, type=int, metavar='N', - help='manual epoch number (useful on restarts)') -parser.add_argument('-b', '--batch-size', default=256, type=int, - metavar='N', - help='mini-batch size (default: 256), this is the total ' - 'batch size of all GPUs on the current node when ' - 'using Data Parallel or Distributed Data Parallel') -parser.add_argument('--lr', '--learning-rate', default=0.1, type=float, - metavar='LR', help='initial learning rate', dest='lr') -parser.add_argument('--momentum', default=0.9, type=float, metavar='M', - help='momentum') -parser.add_argument('--wd', '--weight-decay', default=1e-5, type=float, - metavar='W', help='weight decay (default: 1e-4)', - dest='weight_decay') -parser.add_argument('-p', '--print-freq', default=10, type=int, - metavar='N', help='print frequency (default: 10)') -parser.add_argument('--resume', default='', type=str, metavar='PATH', - help='path to latest checkpoint (default: none)') -parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', - help='evaluate model on validation set') -parser.add_argument('--pretrained', dest='pretrained', action='store_true', - help='use pre-trained model') -parser.add_argument('--pretrained_weight', default='', type=str, metavar='PATH', - help='path to pretrained weight') -parser.add_argument('--num_classes', default=1000, type=int, - help='number of class') -parser.add_argument('--world-size', default=-1, type=int, - help='number of nodes for distributed training') -parser.add_argument('--rank', default=-1, type=int, - help='node rank for distributed training') -parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str, - help='url used to set up distributed training') -parser.add_argument('--dist-backend', default='hccl', type=str, - help='distributed backend') -parser.add_argument('--seed', default=None, type=int, - help='seed for initializing training. ') -parser.add_argument('--npu', default=None, type=str, - help='npu id to use.') -parser.add_argument('--image_size', default=224, type=int, - help='image size') -parser.add_argument('--advprop', default=False, action='store_true', - help='use advprop or not') -parser.add_argument('--multiprocessing-distributed', action='store_true', - help='Use multi-processing distributed training to launch ' - 'N processes per node, which has N GPUs. This is the ' - 'fastest way to use PyTorch for either single node or ' - 'multi node data parallel training') -parser.add_argument('--autoaug', action='store_true', help='use auto augment') -parser.add_argument('--amp', action='store_true', help='use apex') -parser.add_argument('--pm', '--precision-mode', default='O1', type=str, - help='precision mode to use for mix precision, only support O1, O2') -parser.add_argument('--loss_scale', default=1024, type=int, help='loss_scale for amp') -parser.add_argument('--addr', default='127.0.0.1', type=str, - help='npu id to use.') -parser.add_argument('--nnpus_per_node', default=None, type=int, - help='number of npus to use for distributed train on each node') -parser.add_argument('--val_feq', default=10, type=int, - help='validation frequency') -parser.add_argument('--device_list', default='0,1,2,3,4,5,6,7', type=str, help='device id list') -parser.add_argument('--stop-step-num', default=None, type=int, - help='after the stop-step, killing the training task') -cur_step = 0 - -# for servers to immediately record the logs -#def flush_print(func): - #def new_print(*args, **kwargs): - #func(*args, **kwargs) - #sys.stdout.flush() - #return new_print -#print = flush_print(print) - -def device_id_to_process_device_map(device_list): - devices = device_list.split(",") - devices = [int(x) for x in devices] - devices.sort() - - process_device_map = dict() - for process_id, device_id in enumerate(devices): - process_device_map[process_id] = device_id - - return process_device_map - - -def main(): - args = parser.parse_args() - - if args.dist_url == "env://" and args.world_size == -1: - args.world_size = int(os.environ["WORLD_SIZE"]) - - args.distributed = args.world_size > 1 or args.multiprocessing_distributed - - args.process_device_map = device_id_to_process_device_map(args.device_list) - nnpus_per_node = len(args.process_device_map) - - - if args.multiprocessing_distributed: - # Since we have ngpus_per_node processes per node, the total world_size - # needs to be adjusted accordingly - args.world_size = nnpus_per_node * args.world_size - # Use torch.multiprocessing.spawn to launch distributed processes: the - # main_worker process function - os.environ['MASTER_ADDR'] = args.addr - os.environ['MASTER_PORT'] = '29688' - mp.spawn(main_worker, nprocs=nnpus_per_node, args=(nnpus_per_node, args)) - else: - # Simply call main_worker function - main_worker(args.npu, nnpus_per_node, args) - -def main_worker(npu, nnpus_per_node, args): - args.npu = npu - global cur_step - if args.distributed: - args.npu = args.process_device_map[npu] - - if args.npu is not None: - print("Use npu: {} for training".format(args.npu)) - torch.npu.set_device('npu:' + str(args.npu)) - - if args.distributed: - if args.dist_url == "env://" and args.rank == -1: - args.rank = int(os.environ["RANK"]) - if args.multiprocessing_distributed: - # For multiprocessing distributed training, rank needs to be the - # global rank among all the processes - args.rank = args.rank * nnpus_per_node + int(npu) - - dist.init_process_group(backend=args.dist_backend, - world_size=args.world_size, rank=args.rank) - # create model - if 'efficientnet' in args.arch: # NEW - if args.pretrained: - model = EfficientNet.from_pretrained(args.arch, advprop=args.advprop, weights_path=args.pretrained_weight, num_classes=args.num_classes) - print("=> using pre-trained model '{}'".format(args.arch)) - else: - print("=> creating model '{}'".format(args.arch)) - model = EfficientNet.from_name(args.arch) - - else: - if args.pretrained: - print("=> using pre-trained model '{}'".format(args.arch)) - model = models.__dict__[args.arch](pretrained=True) - else: - print("=> creating model '{}'".format(args.arch)) - model = models.__dict__[args.arch]() - - criterion = nn.CrossEntropyLoss().to('npu:' + str(args.npu)) - - optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), args.lr, - momentum=args.momentum, - weight_decay=args.weight_decay) - model = model.to('npu:' + str(args.npu)) - if args.amp: - print("=> use amp...") - if args.pm not in ['O1', 'O2']: - print('=>unsupported precision mode!') - exit() - opt_level = args.pm - model, optimizer = amp.initialize(model, optimizer, opt_level=opt_level, loss_scale=args.loss_scale,combine_grad=True) - - global total_batch_size - total_batch_size = args.batch_size - if args.distributed: - args.batch_size = int(args.batch_size / nnpus_per_node) - args.workers = int(args.workers / nnpus_per_node) - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.npu], broadcast_buffers=False) - - - - # optionally resume from a checkpoint - if args.resume: - if os.path.isfile(args.resume): - print("=> loading checkpoint '{}'".format(args.resume)) - checkpoint = torch.load(args.resume, map_location='npu:' + str(args.npu)) - args.start_epoch = checkpoint['epoch'] - if args.amp: - amp.load_state_dict(checkpoint['amp']) - model.load_state_dict(checkpoint['state_dict']) - optimizer.load_state_dict(checkpoint['optimizer']) - print("=> loaded checkpoint '{}' (epoch {})" - .format(args.resume, checkpoint['epoch'])) - else: - print("=> no checkpoint found at '{}'".format(args.resume)) - - # Data loading code - traindir = os.path.join(args.data, 'train') - valdir = os.path.join(args.data, 'val') - if args.advprop: - normalize = transforms.Lambda(lambda img: img * 2.0 - 1.0) - else: - normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], - std=[0.229, 0.224, 0.225]) - - if 'efficientnet' in args.arch: - image_size = EfficientNet.get_image_size(args.arch) - else: - image_size = args.image_size - - if args.autoaug: - print("=> use auto augment...") - train_dataset = datasets.ImageFolder( - traindir, - transforms.Compose([ - transforms.RandomResizedCrop(image_size), - auto_augment_wrapper(image_size), - transforms.ToTensor(), - normalize, - ])) - else: - train_dataset = datasets.ImageFolder( - traindir, - transforms.Compose([ - transforms.RandomResizedCrop(image_size), - transforms.RandomHorizontalFlip(), - transforms.ToTensor(), - normalize, - ])) - - if args.distributed: - train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) - else: - train_sampler = None - - train_loader = torch.utils.data.DataLoader( - train_dataset, batch_size=args.batch_size, shuffle=(train_sampler is None), - num_workers=args.workers, pin_memory=True, sampler=train_sampler, drop_last=True) - - val_transforms = transforms.Compose([ - transforms.Resize(image_size, interpolation=PIL.Image.BICUBIC), - transforms.CenterCrop(image_size), - transforms.ToTensor(), - normalize, - ]) - print('npu:' + str(args.npu), ' optimizer params:', optimizer) - - val_loader = torch.utils.data.DataLoader( - datasets.ImageFolder(valdir, val_transforms), - batch_size=args.batch_size, shuffle=False, - num_workers=args.workers, pin_memory=True) - - if args.evaluate: - res = validate(val_loader, model, criterion, args, nnpus_per_node) - with open('res.txt', 'w') as f: - print(res, file=f) - return - - for epoch in range(args.start_epoch, args.epochs): - if args.distributed: - train_sampler.set_epoch(epoch) - - # train for one epoch - train(train_loader, model, criterion, optimizer, epoch, args, nnpus_per_node) - - # evaluate on validation set - if epoch % args.val_feq == 0 or epoch == args.epochs - 1: - validate(val_loader, model, criterion, args, nnpus_per_node) - - if epoch == args.epochs - 1: - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % nnpus_per_node == 0): - if not args.amp: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': args.arch, - 'state_dict': model.state_dict(), - 'optimizer': optimizer.state_dict(), - }) - else: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': args.arch, - 'state_dict': model.state_dict(), - 'optimizer': optimizer.state_dict(), - 'amp': amp.state_dict(), - }) - if args.stop_step_num is not None and cur_step >= args.stop_step_num: - break - -def train(train_loader, model, criterion, optimizer, epoch, args, nnpus_per_node): - global cur_step - batch_time = AverageMeter('Time', ':6.3f') - data_time = AverageMeter('Data', ':6.3f') - losses = AverageMeter('Loss', ':6.4f') - lr = AverageMeter('LR', ':6.4f') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - fps_time = AverageMeter('FPS', ':6.1f') - progress = ProgressMeter(len(train_loader), fps_time, batch_time, data_time, losses, lr, top1, - top5, prefix="Epoch: [{}]".format(epoch)) - - # switch to train mode - model.train() - - end = time.time() - step_per_epoch = len(train_loader) - for i, (images, target) in enumerate(train_loader): - if i > 100: - pass - cur_step = epoch * step_per_epoch + i - adjust_learning_rate_fraction_epoch(optimizer, epoch, args) - - # measure data loading time - data_time.update(time.time() - end) - - optimizer.zero_grad() - - target = target.int() - images, target = images.to('npu:' + str(args.npu), non_blocking=True), target.to('npu:' + str(args.npu), non_blocking=True) - - # compute output - output = model(images) - - loss = criterion(output, target) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - - losses.update(loss.item(), images.size(0)) - lr.update(optimizer.param_groups[0]['lr'], images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - # compute gradient and do SGD step - - if args.amp: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - - # measure elapsed time - fps_time.update(total_batch_size / (time.time() - end)) - batch_time.update(time.time() - end) - end = time.time() - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % nnpus_per_node == 0): - progress.print(i) - if args.stop_step_num is not None and cur_step >= args.stop_step_num: - break - - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % nnpus_per_node == 0): - fps = str(fps_time) - p1 = re.compile(r'[(](.*?)[)]', re.S) - FPS = re.findall(p1, fps)[0] - print(' * FPS@all {}'.format(FPS)) - -def validate(val_loader, model, criterion, args, nnpus_per_node): - batch_time = AverageMeter('Time', ':6.3f') - losses = AverageMeter('Loss', ':.4e') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - progress = ProgressMeter(len(val_loader), batch_time, losses, top1, top5, - prefix='Test: ') - - # switch to evaluate mode - model.eval() - - with torch.no_grad(): - end = time.time() - for i, (images, target) in enumerate(val_loader): - if i > 10: - pass - target = target.int() - images, target = images.to('npu:' + str(args.npu), non_blocking=True), target.to('npu:' + str(args.npu), non_blocking=True) - - # compute output - output = model(images) - loss = criterion(output, target) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # measure elapsed time - batch_time.update(time.time() - end) - end = time.time() - - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % nnpus_per_node == 0): - progress.print(i) - - # TODO: this should also be done with the ProgressMeter - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % nnpus_per_node == 0): - - print(' * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}' - .format(top1=top1, top5=top5)) - - - return top1.avg - - -def save_checkpoint(state, filename='checkpoint.pth'): - torch.save(state, filename) - - -class AverageMeter(object): - """Computes and stores the average and current value""" - def __init__(self, name, fmt=':f'): - self.name = name - self.fmt = fmt - self.reset() - self.skip = 0 - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - self.skip = 0 - - def update(self, val, n=1): - self.val = val - # the first 5 value are not accumulated in the average stats - self.skip += 1 - if self.skip < 5: - return - self.sum += val * n - self.count += n - self.avg = self.sum / self.count - - def __str__(self): - fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' - return fmtstr.format(**self.__dict__) - - -class ProgressMeter(object): - def __init__(self, num_batches, *meters, prefix=""): - self.batch_fmtstr = self._get_batch_fmtstr(num_batches) - self.meters = meters - self.prefix = prefix - - def print(self, batch): - entries = [self.prefix + self.batch_fmtstr.format(batch)] - entries += [str(meter) for meter in self.meters] - print('\t'.join(entries)) - - def _get_batch_fmtstr(self, num_batches): - num_digits = len(str(num_batches // 1)) - fmt = '{:' + str(num_digits) + 'd}' - return '[' + fmt + '/' + fmt.format(num_batches) + ']' - - -def adjust_learning_rate(optimizer, epoch, args): - """Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" - lr = args.lr * (0.1 ** (epoch // 30)) - for param_group in optimizer.param_groups: - param_group['lr'] = lr - - -def accuracy(output, target, topk=(1,)): - """Computes the accuracy over the k top predictions for the specified values of k""" - with torch.no_grad(): - maxk = max(topk) - batch_size = target.size(0) - - _, pred = output.topk(maxk, 1, True, True) - pred = pred.t() - correct = pred.eq(target.view(1, -1).expand_as(pred)) - - res = [] - for k in topk: - correct_k = correct[:k].view(-1).float().sum(0, keepdim=True) - res.append(correct_k.mul_(100.0 / batch_size)) - return res - -def auto_augment_wrapper(img_size, auto_augment='original-mstd0.5'): - IMAGENET_DEFAULT_MEAN = [0.485, 0.456, 0.406] - assert isinstance(auto_augment, str) - aa_params = dict( - translate_const=int(img_size * 0.45), - img_mean=tuple([min(255, round(255 * x)) for x in IMAGENET_DEFAULT_MEAN]), - ) - if auto_augment.startswith('rand'): - return rand_augment_transform(auto_augment, aa_params) - elif auto_augment.startswith('augmix'): - aa_params['translate_pct'] = 0.3 - return augment_and_mix_transform(auto_augment, aa_params) - else: - return auto_augment_transform(auto_augment, aa_params) - -def adjust_learning_rate_fraction_epoch(optimizer, epoch, args): - """Use the epoch cosine schedule""" - - alpha = 0 - cosine_decay = 0.5 * (1 + np.cos(np.pi * epoch / args.epochs)) - decayed = (1 - alpha) * cosine_decay + alpha - lr = args.lr * decayed - for param_group in optimizer.param_groups: - param_group['lr'] = lr - -if __name__ == '__main__': - main() +# Copyright [yyyy] [name of copyright owner] +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import os +import re +import sys +import time +import PIL +import numpy as np + +import torch +import torch.nn as nn +import torch.nn.parallel +import torch.distributed as dist +import torch.optim +import torch.multiprocessing as mp +import torch.utils.data +import torch.utils.data.distributed +import torchvision.transforms as transforms +import torchvision.datasets as datasets +import torchvision.models as models +import apex +from apex import amp + +sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),'../../')) +from efficientnet_pytorch import EfficientNet +from efficientnet_pytorch import rand_augment_transform, augment_and_mix_transform, auto_augment_transform + +parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') +parser.add_argument('--data', metavar='DIR', + help='path to dataset') +parser.add_argument('-a', '--arch', metavar='ARCH', default='resnet18', + help='model architecture (default: resnet18)') +parser.add_argument('-j', '--workers', default=64, type=int, metavar='N', + help='number of data loading workers (default: 4)') +parser.add_argument('--epochs', default=90, type=int, metavar='N', + help='number of total epochs to run') +parser.add_argument('--start-epoch', default=0, type=int, metavar='N', + help='manual epoch number (useful on restarts)') +parser.add_argument('-b', '--batch-size', default=256, type=int, + metavar='N', + help='mini-batch size (default: 256), this is the total ' + 'batch size of all GPUs on the current node when ' + 'using Data Parallel or Distributed Data Parallel') +parser.add_argument('--lr', '--learning-rate', default=0.1, type=float, + metavar='LR', help='initial learning rate', dest='lr') +parser.add_argument('--momentum', default=0.9, type=float, metavar='M', + help='momentum') +parser.add_argument('--wd', '--weight-decay', default=1e-5, type=float, + metavar='W', help='weight decay (default: 1e-4)', + dest='weight_decay') +parser.add_argument('-p', '--print-freq', default=10, type=int, + metavar='N', help='print frequency (default: 10)') +parser.add_argument('--resume', default='', type=str, metavar='PATH', + help='path to latest checkpoint (default: none)') +parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', + help='evaluate model on validation set') +parser.add_argument('--pretrained', dest='pretrained', action='store_true', + help='use pre-trained model') +parser.add_argument('--pretrained_weight', default='', type=str, metavar='PATH', + help='path to pretrained weight') +parser.add_argument('--num_classes', default=1000, type=int, + help='number of class') +parser.add_argument('--world-size', default=-1, type=int, + help='number of nodes for distributed training') +parser.add_argument('--rank', default=-1, type=int, + help='node rank for distributed training') +parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str, + help='url used to set up distributed training') +parser.add_argument('--dist-backend', default='hccl', type=str, + help='distributed backend') +parser.add_argument('--seed', default=None, type=int, + help='seed for initializing training. ') +parser.add_argument('--npu', default=None, type=str, + help='npu id to use.') +parser.add_argument('--image_size', default=224, type=int, + help='image size') +parser.add_argument('--advprop', default=False, action='store_true', + help='use advprop or not') +parser.add_argument('--multiprocessing-distributed', action='store_true', + help='Use multi-processing distributed training to launch ' + 'N processes per node, which has N GPUs. This is the ' + 'fastest way to use PyTorch for either single node or ' + 'multi node data parallel training') +parser.add_argument('--autoaug', action='store_true', help='use auto augment') +parser.add_argument('--amp', action='store_true', help='use apex') +parser.add_argument('--pm', '--precision-mode', default='O1', type=str, + help='precision mode to use for mix precision, only support O1, O2') +parser.add_argument('--loss_scale', default=1024, type=int, help='loss_scale for amp') +parser.add_argument('--addr', default='127.0.0.1', type=str, + help='npu id to use.') +parser.add_argument('--nnpus_per_node', default=None, type=int, + help='number of npus to use for distributed train on each node') +parser.add_argument('--val_feq', default=10, type=int, + help='validation frequency') +parser.add_argument('--device_list', default='0,1,2,3,4,5,6,7', type=str, help='device id list') +parser.add_argument('--stop-step-num', default=None, type=int, + help='after the stop-step, killing the training task') +cur_step = 0 + +# for servers to immediately record the logs +#def flush_print(func): + #def new_print(*args, **kwargs): + #func(*args, **kwargs) + #sys.stdout.flush() + #return new_print +#print = flush_print(print) + +def device_id_to_process_device_map(device_list): + devices = device_list.split(",") + devices = [int(x) for x in devices] + devices.sort() + + process_device_map = dict() + for process_id, device_id in enumerate(devices): + process_device_map[process_id] = device_id + + return process_device_map + + +def main(): + args = parser.parse_args() + + if args.dist_url == "env://" and args.world_size == -1: + args.world_size = int(os.environ["WORLD_SIZE"]) + + args.distributed = args.world_size > 1 or args.multiprocessing_distributed + + args.process_device_map = device_id_to_process_device_map(args.device_list) + nnpus_per_node = len(args.process_device_map) + + + if args.multiprocessing_distributed: + # Since we have ngpus_per_node processes per node, the total world_size + # needs to be adjusted accordingly + args.world_size = nnpus_per_node * args.world_size + # Use torch.multiprocessing.spawn to launch distributed processes: the + # main_worker process function + os.environ['MASTER_ADDR'] = args.addr + os.environ['MASTER_PORT'] = '29688' + mp.spawn(main_worker, nprocs=nnpus_per_node, args=(nnpus_per_node, args)) + else: + # Simply call main_worker function + main_worker(args.npu, nnpus_per_node, args) + +def main_worker(npu, nnpus_per_node, args): + args.npu = npu + global cur_step + if args.distributed: + args.npu = args.process_device_map[npu] + + if args.npu is not None: + print("Use npu: {} for training".format(args.npu)) + torch.npu.set_device('npu:' + str(args.npu)) + + if args.distributed: + if args.dist_url == "env://" and args.rank == -1: + args.rank = int(os.environ["RANK"]) + if args.multiprocessing_distributed: + # For multiprocessing distributed training, rank needs to be the + # global rank among all the processes + args.rank = args.rank * nnpus_per_node + int(npu) + + dist.init_process_group(backend=args.dist_backend, + world_size=args.world_size, rank=args.rank) + # create model + if 'efficientnet' in args.arch: # NEW + if args.pretrained: + model = EfficientNet.from_pretrained(args.arch, advprop=args.advprop, weights_path=args.pretrained_weight, num_classes=args.num_classes) + print("=> using pre-trained model '{}'".format(args.arch)) + else: + print("=> creating model '{}'".format(args.arch)) + model = EfficientNet.from_name(args.arch) + + else: + if args.pretrained: + print("=> using pre-trained model '{}'".format(args.arch)) + model = models.__dict__[args.arch](pretrained=True) + else: + print("=> creating model '{}'".format(args.arch)) + model = models.__dict__[args.arch]() + + criterion = nn.CrossEntropyLoss().to('npu:' + str(args.npu)) + + optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), args.lr, + momentum=args.momentum, + weight_decay=args.weight_decay) + model = model.to('npu:' + str(args.npu)) + if args.amp: + print("=> use amp...") + if args.pm not in ['O1', 'O2']: + print('=>unsupported precision mode!') + exit() + opt_level = args.pm + model, optimizer = amp.initialize(model, optimizer, opt_level=opt_level, loss_scale=args.loss_scale,combine_grad=True) + + global total_batch_size + total_batch_size = args.batch_size + if args.distributed: + args.batch_size = int(args.batch_size / nnpus_per_node) + args.workers = int(args.workers / nnpus_per_node) + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.npu], broadcast_buffers=False) + + + + # optionally resume from a checkpoint + if args.resume: + if os.path.isfile(args.resume): + print("=> loading checkpoint '{}'".format(args.resume)) + checkpoint = torch.load(args.resume, map_location='npu:' + str(args.npu)) + args.start_epoch = checkpoint['epoch'] + if args.amp: + amp.load_state_dict(checkpoint['amp']) + model.load_state_dict(checkpoint['state_dict']) + optimizer.load_state_dict(checkpoint['optimizer']) + print("=> loaded checkpoint '{}' (epoch {})" + .format(args.resume, checkpoint['epoch'])) + else: + print("=> no checkpoint found at '{}'".format(args.resume)) + + # Data loading code + traindir = os.path.join(args.data, 'train') + valdir = os.path.join(args.data, 'val') + if args.advprop: + normalize = transforms.Lambda(lambda img: img * 2.0 - 1.0) + else: + normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]) + + if 'efficientnet' in args.arch: + image_size = EfficientNet.get_image_size(args.arch) + else: + image_size = args.image_size + + if args.autoaug: + print("=> use auto augment...") + train_dataset = datasets.ImageFolder( + traindir, + transforms.Compose([ + transforms.RandomResizedCrop(image_size), + auto_augment_wrapper(image_size), + transforms.ToTensor(), + normalize, + ])) + else: + train_dataset = datasets.ImageFolder( + traindir, + transforms.Compose([ + transforms.RandomResizedCrop(image_size), + transforms.RandomHorizontalFlip(), + transforms.ToTensor(), + normalize, + ])) + + if args.distributed: + train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) + else: + train_sampler = None + + train_loader = torch.utils.data.DataLoader( + train_dataset, batch_size=args.batch_size, shuffle=(train_sampler is None), + num_workers=args.workers, pin_memory=True, sampler=train_sampler, drop_last=True) + + val_transforms = transforms.Compose([ + transforms.Resize(image_size, interpolation=PIL.Image.BICUBIC), + transforms.CenterCrop(image_size), + transforms.ToTensor(), + normalize, + ]) + print('npu:' + str(args.npu), ' optimizer params:', optimizer) + + val_loader = torch.utils.data.DataLoader( + datasets.ImageFolder(valdir, val_transforms), + batch_size=args.batch_size, shuffle=False, + num_workers=args.workers, pin_memory=True) + + if args.evaluate: + res = validate(val_loader, model, criterion, args, nnpus_per_node) + with open('res.txt', 'w') as f: + print(res, file=f) + return + + for epoch in range(args.start_epoch, args.epochs): + if args.distributed: + train_sampler.set_epoch(epoch) + + # train for one epoch + train(train_loader, model, criterion, optimizer, epoch, args, nnpus_per_node) + + # evaluate on validation set + if epoch % args.val_feq == 0 or epoch == args.epochs - 1: + validate(val_loader, model, criterion, args, nnpus_per_node) + + if epoch == args.epochs - 1: + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % nnpus_per_node == 0): + if not args.amp: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': args.arch, + 'state_dict': model.state_dict(), + 'optimizer': optimizer.state_dict(), + }) + else: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': args.arch, + 'state_dict': model.state_dict(), + 'optimizer': optimizer.state_dict(), + 'amp': amp.state_dict(), + }) + if args.stop_step_num is not None and cur_step >= args.stop_step_num: + break + +def train(train_loader, model, criterion, optimizer, epoch, args, nnpus_per_node): + global cur_step + batch_time = AverageMeter('Time', ':6.3f') + data_time = AverageMeter('Data', ':6.3f') + losses = AverageMeter('Loss', ':6.4f') + lr = AverageMeter('LR', ':6.4f') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + fps_time = AverageMeter('FPS', ':6.1f') + progress = ProgressMeter(len(train_loader), fps_time, batch_time, data_time, losses, lr, top1, + top5, prefix="Epoch: [{}]".format(epoch)) + + # switch to train mode + model.train() + + end = time.time() + step_per_epoch = len(train_loader) + for i, (images, target) in enumerate(train_loader): + if i > 100: + pass + cur_step = epoch * step_per_epoch + i + adjust_learning_rate_fraction_epoch(optimizer, epoch, args) + + # measure data loading time + data_time.update(time.time() - end) + + optimizer.zero_grad() + + target = target.int() + images, target = images.to('npu:' + str(args.npu), non_blocking=True), target.to('npu:' + str(args.npu), non_blocking=True) + + # compute output + output = model(images) + + loss = criterion(output, target) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + + losses.update(loss.item(), images.size(0)) + lr.update(optimizer.param_groups[0]['lr'], images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + # compute gradient and do SGD step + + if args.amp: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + + # measure elapsed time + fps_time.update(total_batch_size / (time.time() - end)) + batch_time.update(time.time() - end) + end = time.time() + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % nnpus_per_node == 0): + progress.print(i) + if args.stop_step_num is not None and cur_step >= args.stop_step_num: + break + + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % nnpus_per_node == 0): + fps = str(fps_time) + p1 = re.compile(r'[(](.*?)[)]', re.S) + FPS = re.findall(p1, fps)[0] + print(' * FPS@all {}'.format(FPS)) + +def validate(val_loader, model, criterion, args, nnpus_per_node): + batch_time = AverageMeter('Time', ':6.3f') + losses = AverageMeter('Loss', ':.4e') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + progress = ProgressMeter(len(val_loader), batch_time, losses, top1, top5, + prefix='Test: ') + + # switch to evaluate mode + model.eval() + + with torch.no_grad(): + end = time.time() + for i, (images, target) in enumerate(val_loader): + if i > 10: + pass + target = target.int() + images, target = images.to('npu:' + str(args.npu), non_blocking=True), target.to('npu:' + str(args.npu), non_blocking=True) + + # compute output + output = model(images) + loss = criterion(output, target) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # measure elapsed time + batch_time.update(time.time() - end) + end = time.time() + + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % nnpus_per_node == 0): + progress.print(i) + + # TODO: this should also be done with the ProgressMeter + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % nnpus_per_node == 0): + + print(' * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}' + .format(top1=top1, top5=top5)) + + + return top1.avg + + +def save_checkpoint(state, filename='checkpoint.pth'): + torch.save(state, filename) + + +class AverageMeter(object): + """Computes and stores the average and current value""" + def __init__(self, name, fmt=':f'): + self.name = name + self.fmt = fmt + self.reset() + self.skip = 0 + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + self.skip = 0 + + def update(self, val, n=1): + self.val = val + # the first 5 value are not accumulated in the average stats + self.skip += 1 + if self.skip < 5: + return + self.sum += val * n + self.count += n + self.avg = self.sum / self.count + + def __str__(self): + fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' + return fmtstr.format(**self.__dict__) + + +class ProgressMeter(object): + def __init__(self, num_batches, *meters, prefix=""): + self.batch_fmtstr = self._get_batch_fmtstr(num_batches) + self.meters = meters + self.prefix = prefix + + def print(self, batch): + entries = [self.prefix + self.batch_fmtstr.format(batch)] + entries += [str(meter) for meter in self.meters] + print('\t'.join(entries)) + + def _get_batch_fmtstr(self, num_batches): + num_digits = len(str(num_batches // 1)) + fmt = '{:' + str(num_digits) + 'd}' + return '[' + fmt + '/' + fmt.format(num_batches) + ']' + + +def adjust_learning_rate(optimizer, epoch, args): + """Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" + lr = args.lr * (0.1 ** (epoch // 30)) + for param_group in optimizer.param_groups: + param_group['lr'] = lr + + +def accuracy(output, target, topk=(1,)): + """Computes the accuracy over the k top predictions for the specified values of k""" + with torch.no_grad(): + maxk = max(topk) + batch_size = target.size(0) + + _, pred = output.topk(maxk, 1, True, True) + pred = pred.t() + correct = pred.eq(target.view(1, -1).expand_as(pred)) + + res = [] + for k in topk: + correct_k = correct[:k].view(-1).float().sum(0, keepdim=True) + res.append(correct_k.mul_(100.0 / batch_size)) + return res + +def auto_augment_wrapper(img_size, auto_augment='original-mstd0.5'): + IMAGENET_DEFAULT_MEAN = [0.485, 0.456, 0.406] + assert isinstance(auto_augment, str) + aa_params = dict( + translate_const=int(img_size * 0.45), + img_mean=tuple([min(255, round(255 * x)) for x in IMAGENET_DEFAULT_MEAN]), + ) + if auto_augment.startswith('rand'): + return rand_augment_transform(auto_augment, aa_params) + elif auto_augment.startswith('augmix'): + aa_params['translate_pct'] = 0.3 + return augment_and_mix_transform(auto_augment, aa_params) + else: + return auto_augment_transform(auto_augment, aa_params) + +def adjust_learning_rate_fraction_epoch(optimizer, epoch, args): + """Use the epoch cosine schedule""" + + alpha = 0 + cosine_decay = 0.5 * (1 + np.cos(np.pi * epoch / args.epochs)) + decayed = (1 - alpha) * cosine_decay + alpha + lr = args.lr * decayed + for param_group in optimizer.param_groups: + param_group['lr'] = lr + +if __name__ == '__main__': + main() diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/hubconf.py b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/hubconf.py index 614a7b61a8d327c3a0a32203b15fe1e6ead4a8eb..bb4d80153d62f9c01d76101d713a921a285c3834 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/hubconf.py +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/hubconf.py @@ -1,58 +1,58 @@ -# Copyright [yyyy] [name of copyright owner] -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from efficientnet_pytorch import EfficientNet as _EfficientNet - -dependencies = ['torch'] - - -def _create_model_fn(model_name): - def _model_fn(num_classes=1000, in_channels=3, pretrained='imagenet'): - """Create Efficient Net. - - Described in detail here: https://arxiv.org/abs/1905.11946 - - Args: - num_classes (int, optional): Number of classes, default is 1000. - in_channels (int, optional): Number of input channels, default - is 3. - pretrained (str, optional): One of [None, 'imagenet', 'advprop'] - If None, no pretrained model is loaded. - If 'imagenet', models trained on imagenet dataset are loaded. - If 'advprop', models trained using adversarial training called - advprop are loaded. It is important to note that the - preprocessing required for the advprop pretrained models is - slightly different from normal ImageNet preprocessing - """ - model_name_ = model_name.replace('_', '-') - if pretrained is not None: - model = _EfficientNet.from_pretrained( - model_name=model_name_, - advprop=(pretrained == 'advprop'), - num_classes=num_classes, - in_channels=in_channels) - else: - model = _EfficientNet.from_name( - model_name=model_name_, - override_params={'num_classes': num_classes}, - ) - model._change_in_channels(in_channels) - - return model - - return _model_fn - -for model_name in ['efficientnet_b' + str(i) for i in range(9)]: - locals()[model_name] = _create_model_fn(model_name) +# Copyright [yyyy] [name of copyright owner] +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from efficientnet_pytorch import EfficientNet as _EfficientNet + +dependencies = ['torch'] + + +def _create_model_fn(model_name): + def _model_fn(num_classes=1000, in_channels=3, pretrained='imagenet'): + """Create Efficient Net. + + Described in detail here: https://arxiv.org/abs/1905.11946 + + Args: + num_classes (int, optional): Number of classes, default is 1000. + in_channels (int, optional): Number of input channels, default + is 3. + pretrained (str, optional): One of [None, 'imagenet', 'advprop'] + If None, no pretrained model is loaded. + If 'imagenet', models trained on imagenet dataset are loaded. + If 'advprop', models trained using adversarial training called + advprop are loaded. It is important to note that the + preprocessing required for the advprop pretrained models is + slightly different from normal ImageNet preprocessing + """ + model_name_ = model_name.replace('_', '-') + if pretrained is not None: + model = _EfficientNet.from_pretrained( + model_name=model_name_, + advprop=(pretrained == 'advprop'), + num_classes=num_classes, + in_channels=in_channels) + else: + model = _EfficientNet.from_name( + model_name=model_name_, + override_params={'num_classes': num_classes}, + ) + model._change_in_channels(in_channels) + + return model + + return _model_fn + +for model_name in ['efficientnet_b' + str(i) for i in range(9)]: + locals()[model_name] = _create_model_fn(model_name) diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/pthtar2onnx.py b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/pthtar2onnx.py index ae3cee8264d71585f627da40dd53244a4396989a..ae878c2d1069529592c449b16f72716bb36b3a56 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/pthtar2onnx.py +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/pthtar2onnx.py @@ -1,63 +1,63 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import torch -import torch.onnx - -from collections import OrderedDict -from efficientnet_pytorch.model import EfficientNet - - -def proc_node_module(checkpoint, attr_name): - """ - modify state_dict - :param checkpoint: loaded model file - :param attr_name: key state_dict - :return: new state_dict - """ - new_state_dict = OrderedDict() - for k, v in checkpoint[attr_name].items(): - if k[0:7] == "module.": - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - - -def convert(pth_file_path, onnx_file_path, class_nums): - """ - convert pth file to onnx file and output onnx file - """ - checkpoint = torch.load(pth_file_path, map_location='cpu') - checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') - model = EfficientNet.from_name("efficientnet-b0", num_classes=class_nums) - model.set_swish(memory_efficient=False) - model.load_state_dict(checkpoint['state_dict']) - model.eval() - - input_names = ["actual_input_1"] - output_names = ["output1"] - dummy_input = torch.randn(16, 3, 224, 224) - torch.onnx.export(model, dummy_input, onnx_file_path, - input_names=input_names, output_names=output_names, - opset_version=11) - - -if __name__ == "__main__": - src_file_path = "./checkpoint.pth" - dst_file_path = "efficientnet_npu_16.onnx" - class_num = 1000 +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import torch +import torch.onnx + +from collections import OrderedDict +from efficientnet_pytorch.model import EfficientNet + + +def proc_node_module(checkpoint, attr_name): + """ + modify state_dict + :param checkpoint: loaded model file + :param attr_name: key state_dict + :return: new state_dict + """ + new_state_dict = OrderedDict() + for k, v in checkpoint[attr_name].items(): + if k[0:7] == "module.": + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + + +def convert(pth_file_path, onnx_file_path, class_nums): + """ + convert pth file to onnx file and output onnx file + """ + checkpoint = torch.load(pth_file_path, map_location='cpu') + checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') + model = EfficientNet.from_name("efficientnet-b0", num_classes=class_nums) + model.set_swish(memory_efficient=False) + model.load_state_dict(checkpoint['state_dict']) + model.eval() + + input_names = ["actual_input_1"] + output_names = ["output1"] + dummy_input = torch.randn(16, 3, 224, 224) + torch.onnx.export(model, dummy_input, onnx_file_path, + input_names=input_names, output_names=output_names, + opset_version=11) + + +if __name__ == "__main__": + src_file_path = "./checkpoint.pth" + dst_file_path = "efficientnet_npu_16.onnx" + class_num = 1000 convert(src_file_path, dst_file_path, class_num) \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/run_to_onnx.sh b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/run_to_onnx.sh index 5e4f0b29b9e9aa71f5fd010bc18c7a921328dda9..1d44866cc0271a9a44dc7f05be2c15ba9d958e12 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/run_to_onnx.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/run_to_onnx.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash -source env_npu.sh - +#!/usr/bin/env bash +source env_npu.sh + python3.7 pthtar2onnx.py \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/setup.py b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/setup.py index fdad49e12a281d8e113fbc7986690da1d6a3c1ee..1ee19f2fbde84adc333455dc5bf7b6eeb867c7df 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/setup.py +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/setup.py @@ -1,138 +1,138 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# Copyright [yyyy] [name of copyright owner] -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Note: To use the 'upload' functionality of this file, you must: -# $ pipenv install twine --dev - -import io -import os -import sys -from shutil import rmtree - -from setuptools import find_packages, setup, Command - -# Package meta-data. -NAME = 'efficientnet_pytorch' -DESCRIPTION = 'EfficientNet implemented in PyTorch.' -URL = 'https://github.com/lukemelas/EfficientNet-PyTorch' -EMAIL = 'lmelaskyriazi@college.harvard.edu' -AUTHOR = 'Luke' -REQUIRES_PYTHON = '>=3.5.0' -VERSION = '0.7.0' - -# What packages are required for this module to be executed? -REQUIRED = [ - 'torch' -] - -# What packages are optional? -EXTRAS = { - # 'fancy feature': ['django'], -} - -# The rest you shouldn't have to touch too much :) -# ------------------------------------------------ -# Except, perhaps the License and Trove Classifiers! -# If you do change the License, remember to change the Trove Classifier for that! - -here = os.path.abspath(os.path.dirname(__file__)) - -# Import the README and use it as the long-description. -# Note: this will only work if 'README.md' is present in your MANIFEST.in file! -try: - with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f: - long_description = '\n' + f.read() -except FileNotFoundError: - long_description = DESCRIPTION - -# Load the package's __version__.py module as a dictionary. -about = {} -if not VERSION: - project_slug = NAME.lower().replace("-", "_").replace(" ", "_") - with open(os.path.join(here, project_slug, '__version__.py')) as f: - exec(f.read(), about) -else: - about['__version__'] = VERSION - - -class UploadCommand(Command): - """Support setup.py upload.""" - - description = 'Build and publish the package.' - user_options = [] - - @staticmethod - def status(s): - """Prints things in bold.""" - print('\033[1m{0}\033[0m'.format(s)) - - def initialize_options(self): - pass - - def finalize_options(self): - pass - - def run(self): - try: - self.status('Removing previous builds…') - rmtree(os.path.join(here, 'dist')) - except OSError: - pass - - self.status('Building Source and Wheel (universal) distribution…') - os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable)) - - self.status('Uploading the package to PyPI via Twine…') - os.system('twine upload dist/*') - - self.status('Pushing git tags…') - os.system('git tag v{0}'.format(about['__version__'])) - os.system('git push --tags') - - sys.exit() - - -# Where the magic happens: -setup( - name=NAME, - version=about['__version__'], - description=DESCRIPTION, - long_description=long_description, - long_description_content_type='text/markdown', - author=AUTHOR, - author_email=EMAIL, - python_requires=REQUIRES_PYTHON, - url=URL, - packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]), - # py_modules=['model'], # If your package is a single module, use this instead of 'packages' - install_requires=REQUIRED, - extras_require=EXTRAS, - include_package_data=True, - license='Apache', - classifiers=[ - # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers - 'License :: OSI Approved :: Apache Software License', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', - ], - # $ setup.py publish support. - cmdclass={ - 'upload': UploadCommand, - }, -) +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright [yyyy] [name of copyright owner] +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Note: To use the 'upload' functionality of this file, you must: +# $ pipenv install twine --dev + +import io +import os +import sys +from shutil import rmtree + +from setuptools import find_packages, setup, Command + +# Package meta-data. +NAME = 'efficientnet_pytorch' +DESCRIPTION = 'EfficientNet implemented in PyTorch.' +URL = 'https://github.com/lukemelas/EfficientNet-PyTorch' +EMAIL = 'lmelaskyriazi@college.harvard.edu' +AUTHOR = 'Luke' +REQUIRES_PYTHON = '>=3.5.0' +VERSION = '0.7.0' + +# What packages are required for this module to be executed? +REQUIRED = [ + 'torch' +] + +# What packages are optional? +EXTRAS = { + # 'fancy feature': ['django'], +} + +# The rest you shouldn't have to touch too much :) +# ------------------------------------------------ +# Except, perhaps the License and Trove Classifiers! +# If you do change the License, remember to change the Trove Classifier for that! + +here = os.path.abspath(os.path.dirname(__file__)) + +# Import the README and use it as the long-description. +# Note: this will only work if 'README.md' is present in your MANIFEST.in file! +try: + with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f: + long_description = '\n' + f.read() +except FileNotFoundError: + long_description = DESCRIPTION + +# Load the package's __version__.py module as a dictionary. +about = {} +if not VERSION: + project_slug = NAME.lower().replace("-", "_").replace(" ", "_") + with open(os.path.join(here, project_slug, '__version__.py')) as f: + exec(f.read(), about) +else: + about['__version__'] = VERSION + + +class UploadCommand(Command): + """Support setup.py upload.""" + + description = 'Build and publish the package.' + user_options = [] + + @staticmethod + def status(s): + """Prints things in bold.""" + print('\033[1m{0}\033[0m'.format(s)) + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + try: + self.status('Removing previous builds…') + rmtree(os.path.join(here, 'dist')) + except OSError: + pass + + self.status('Building Source and Wheel (universal) distribution…') + os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable)) + + self.status('Uploading the package to PyPI via Twine…') + os.system('twine upload dist/*') + + self.status('Pushing git tags…') + os.system('git tag v{0}'.format(about['__version__'])) + os.system('git push --tags') + + sys.exit() + + +# Where the magic happens: +setup( + name=NAME, + version=about['__version__'], + description=DESCRIPTION, + long_description=long_description, + long_description_content_type='text/markdown', + author=AUTHOR, + author_email=EMAIL, + python_requires=REQUIRES_PYTHON, + url=URL, + packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]), + # py_modules=['model'], # If your package is a single module, use this instead of 'packages' + install_requires=REQUIRED, + extras_require=EXTRAS, + include_package_data=True, + license='Apache', + classifiers=[ + # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers + 'License :: OSI Approved :: Apache Software License', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + ], + # $ setup.py publish support. + cmdclass={ + 'upload': UploadCommand, + }, +) diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_full_8p.sh b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_full_8p.sh index 5a841a3b8809fc2e902831a11a0ea54099d4659a..e5def7ceabc261935e7e2b5c3d6550aca639762d 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_full_8p.sh @@ -1,174 +1,174 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="EfficientNet_ID0097_for_PyTorch" -#训练epoch -train_epochs=100 -#训练batch_size -batch_size=4096 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - - - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#add ASCEND_DEVICE_ID -ASCEND_DEVICE_ID=0 - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - -#修改参数 -sed -i "s|pass|break|g" ${cur_path}/../examples/imagenet/main.py -wait - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -# 绑核,不需要的绑核的模型删除,需要模型审视修改 -corenum=`cat /proc/cpuinfo |grep "processor"|wc -l` -let a=RANK_ID*${corenum}/${RANK_SIZE} -let b=RANK_ID+1 -let c=b*${corenum}/${RANK_SIZE}-1 - - -nohup taskset -c $a-$c python3.7 ${cur_path}/../examples/imagenet/main.py \ - --data=$data_path \ - --arch=efficientnet-b0 --batch-size=$batch_size \ - --lr=1.6 \ - --momentum=0.9 \ - --epochs=100 \ - --autoaug \ - --amp \ - --pm=O1 \ - --loss_scale=32 \ - --val_feq=10 \ - --addr=$(hostname -I |awk '{print $1}') \ - --dist-backend=hccl \ - --multiprocessing-distributed \ - --world-size 1 \ - --rank 0 > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#参数改回 -#修改参数 -sed -i "s|break|pass|g" ${cur_path}/../examples/imagenet/main.py -wait - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tail -1|awk '{print $NF}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` -train_accuracy=`grep -a '* Acc@1' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="EfficientNet_ID0097_for_PyTorch" +#训练epoch +train_epochs=100 +#训练batch_size +batch_size=4096 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + + + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path + +#add ASCEND_DEVICE_ID +ASCEND_DEVICE_ID=0 + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $cur_path/output ];then + rm -rf $cur_path/output/* + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +fi +wait + +#修改参数 +sed -i "s|pass|break|g" ${cur_path}/../examples/imagenet/main.py +wait + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +# 绑核,不需要的绑核的模型删除,需要模型审视修改 +corenum=`cat /proc/cpuinfo |grep "processor"|wc -l` +let a=RANK_ID*${corenum}/${RANK_SIZE} +let b=RANK_ID+1 +let c=b*${corenum}/${RANK_SIZE}-1 + + +nohup taskset -c $a-$c python3.7 ${cur_path}/../examples/imagenet/main.py \ + --data=$data_path \ + --arch=efficientnet-b0 --batch-size=$batch_size \ + --lr=1.6 \ + --momentum=0.9 \ + --epochs=100 \ + --autoaug \ + --amp \ + --pm=O1 \ + --loss_scale=32 \ + --val_feq=10 \ + --addr=$(hostname -I |awk '{print $1}') \ + --dist-backend=hccl \ + --multiprocessing-distributed \ + --world-size 1 \ + --rank 0 > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#参数改回 +#修改参数 +sed -i "s|break|pass|g" ${cur_path}/../examples/imagenet/main.py +wait + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tail -1|awk '{print $NF}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` +train_accuracy=`grep -a '* Acc@1' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_1p.sh b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_1p.sh index 4a5a6d5b4cf8463f4a88bf73a49b085b8cf9b039..2ca641a5ea5c3432e2265921e29dde2b433fa38b 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_1p.sh @@ -1,160 +1,160 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="EfficientNet_ID0097_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=512 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - - - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - -#修改参数 -sed -i "s|pass|break|g" ${cur_path}/../examples/imagenet/main.py -wait - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#训练 -nohup python3.7 ${cur_path}/../examples/imagenet/main.py \ - --data=$data_path \ - --arch=efficientnet-b0 \ - --batch-size=$batch_size \ - --lr=0.2 \ - --momentum=0.9 \ - --epochs=$train_epochs \ - --autoaug \ - --amp \ - --pm=O1 \ - --loss_scale=32 \ - --val_feq=10 \ - --stop-step-num=1000 \ - --npu=$ASCEND_DEVICE_ID > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#参数改回 -#修改参数 -sed -i "s|break|pass|g" ${cur_path}/../examples/imagenet/main.py -wait - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tail -1|awk '{print $NF}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="EfficientNet_ID0097_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=512 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + + + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $cur_path/output ];then + rm -rf $cur_path/output/* + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +fi +wait + +#修改参数 +sed -i "s|pass|break|g" ${cur_path}/../examples/imagenet/main.py +wait + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#训练 +nohup python3.7 ${cur_path}/../examples/imagenet/main.py \ + --data=$data_path \ + --arch=efficientnet-b0 \ + --batch-size=$batch_size \ + --lr=0.2 \ + --momentum=0.9 \ + --epochs=$train_epochs \ + --autoaug \ + --amp \ + --pm=O1 \ + --loss_scale=32 \ + --val_feq=10 \ + --stop-step-num=1000 \ + --npu=$ASCEND_DEVICE_ID > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#参数改回 +#修改参数 +sed -i "s|break|pass|g" ${cur_path}/../examples/imagenet/main.py +wait + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tail -1|awk '{print $NF}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_8p.sh index 5128dfcbb28a5c33daf7484bc1d856e0868d5bf2..b19bd51007f8efb7ce2a51fe50cef08c4152c4a7 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/test/train_performance_8p.sh @@ -1,173 +1,173 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 -export SOC_VERSION=Ascend910 -export HCCL_CONNECT_TIMEOUT=600 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP_ETP_ETP_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="EfficientNet_ID0097_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=4096 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - -#修改参数 -sed -i "s|pass|break|g" ${cur_path}/../examples/imagenet/main.py -wait - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -# 绑核,不需要的绑核的模型删除,需要模型审视修改 -#corenum=`cat /proc/cpuinfo |grep "processor"|wc -l` -#let a=RANK_ID*${corenum}/${RANK_SIZE} -#let b=RANK_ID+1 -#let c=b*${corenum}/${RANK_SIZE}-1 -export RANK_INDEX=0 -DEVICE_INDEX=$(( ASCEND_DEVICE_ID + RANK_INDEX * 8 )) -export DEVICE_INDEX=${DEVICE_INDEX} - -#nohup taskset -c $a-$c python3.7 ${cur_path}/../examples/imagenet/main.py -nohup python3.7 ${cur_path}/../examples/imagenet/main.py \ - --data=$data_path \ - --arch=efficientnet-b0 \ - --batch-size=$batch_size \ - --lr=1.6 \ - --momentum=0.9 \ - --epochs=1 \ - --autoaug \ - --amp \ - --pm=O1 \ - --loss_scale=32 \ - --val_feq=10 \ - --addr=$(hostname -I |awk '{print $1}') \ - --dist-backend=hccl \ - --multiprocessing-distributed \ - --world-size 1 \ - --rank 0 > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#参数改回 -#修改参数 -sed -i "s|break|pass|g" ${cur_path}/../examples/imagenet/main.py -wait - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tail -1|awk '{print $NF}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 +export SOC_VERSION=Ascend910 +export HCCL_CONNECT_TIMEOUT=600 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP_ETP_ETP_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="EfficientNet_ID0097_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=4096 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $cur_path/output ];then + rm -rf $cur_path/output/* + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +fi +wait + +#修改参数 +sed -i "s|pass|break|g" ${cur_path}/../examples/imagenet/main.py +wait + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +# 绑核,不需要的绑核的模型删除,需要模型审视修改 +#corenum=`cat /proc/cpuinfo |grep "processor"|wc -l` +#let a=RANK_ID*${corenum}/${RANK_SIZE} +#let b=RANK_ID+1 +#let c=b*${corenum}/${RANK_SIZE}-1 +export RANK_INDEX=0 +DEVICE_INDEX=$(( ASCEND_DEVICE_ID + RANK_INDEX * 8 )) +export DEVICE_INDEX=${DEVICE_INDEX} + +#nohup taskset -c $a-$c python3.7 ${cur_path}/../examples/imagenet/main.py +nohup python3.7 ${cur_path}/../examples/imagenet/main.py \ + --data=$data_path \ + --arch=efficientnet-b0 \ + --batch-size=$batch_size \ + --lr=1.6 \ + --momentum=0.9 \ + --epochs=1 \ + --autoaug \ + --amp \ + --pm=O1 \ + --loss_scale=32 \ + --val_feq=10 \ + --addr=$(hostname -I |awk '{print $1}') \ + --dist-backend=hccl \ + --multiprocessing-distributed \ + --world-size 1 \ + --rank 0 > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#参数改回 +#修改参数 +sed -i "s|break|pass|g" ${cur_path}/../examples/imagenet/main.py +wait + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tail -1|awk '{print $NF}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/tests/test_model.py b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/tests/test_model.py index 936d91fdbc6c34c8a86483a5256e3645cabe95af..7e0a8554cdcb7469d5a902ae3c21243e432adc1b 100644 --- a/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/tests/test_model.py +++ b/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch/tests/test_model.py @@ -1,139 +1,139 @@ -# Copyright [yyyy] [name of copyright owner] -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from collections import OrderedDict - -import pytest -import torch -import torch.nn as nn - -from efficientnet_pytorch import EfficientNet - - -# -- fixtures ------------------------------------------------------------------------------------- - -@pytest.fixture(scope='module', params=[x for x in range(4)]) -def model(request): - return 'efficientnet-b{}'.format(request.param) - - -@pytest.fixture(scope='module', params=[True, False]) -def pretrained(request): - return request.param - - -@pytest.fixture(scope='function') -def net(model, pretrained): - return EfficientNet.from_pretrained(model) if pretrained else EfficientNet.from_name(model) - - -# -- tests ---------------------------------------------------------------------------------------- - -@pytest.mark.parametrize('img_size', [224, 256, 512]) -def test_forward(net, img_size): - """Test `.forward()` doesn't throw an error""" - data = torch.zeros((1, 3, img_size, img_size)) - output = net(data) - assert not torch.isnan(output).any() - - -def test_dropout_training(net): - """Test dropout `.training` is set by `.train()` on parent `nn.module`""" - net.train() - assert net._dropout.training == True - - -def test_dropout_eval(net): - """Test dropout `.training` is set by `.eval()` on parent `nn.module`""" - net.eval() - assert net._dropout.training == False - - -def test_dropout_update(net): - """Test dropout `.training` is updated by `.train()` and `.eval()` on parent `nn.module`""" - net.train() - assert net._dropout.training == True - net.eval() - assert net._dropout.training == False - net.train() - assert net._dropout.training == True - net.eval() - assert net._dropout.training == False - - -@pytest.mark.parametrize('img_size', [224, 256, 512]) -def test_modify_dropout(net, img_size): - """Test ability to modify dropout and fc modules of network""" - dropout = nn.Sequential(OrderedDict([ - ('_bn2', nn.BatchNorm1d(net._bn1.num_features)), - ('_drop1', nn.Dropout(p=net._global_params.dropout_rate)), - ('_linear1', nn.Linear(net._bn1.num_features, 512)), - ('_relu', nn.ReLU()), - ('_bn3', nn.BatchNorm1d(512)), - ('_drop2', nn.Dropout(p=net._global_params.dropout_rate / 2)) - ])) - fc = nn.Linear(512, net._global_params.num_classes) - - net._dropout = dropout - net._fc = fc - - data = torch.zeros((2, 3, img_size, img_size)) - output = net(data) - assert not torch.isnan(output).any() - - -@pytest.mark.parametrize('img_size', [224, 256, 512]) -def test_modify_pool(net, img_size): - """Test ability to modify pooling module of network""" - - class AdaptiveMaxAvgPool(nn.Module): - - def __init__(self): - super().__init__() - self.ada_avgpool = nn.AdaptiveAvgPool2d(1) - self.ada_maxpool = nn.AdaptiveMaxPool2d(1) - - def forward(self, x): - avg_x = self.ada_avgpool(x) - max_x = self.ada_maxpool(x) - x = torch.cat((avg_x, max_x), dim=1) - return x - - avg_pooling = AdaptiveMaxAvgPool() - fc = nn.Linear(net._fc.in_features * 2, net._global_params.num_classes) - - net._avg_pooling = avg_pooling - net._fc = fc - - data = torch.zeros((2, 3, img_size, img_size)) - output = net(data) - assert not torch.isnan(output).any() - - -@pytest.mark.parametrize('img_size', [224, 256, 512]) -def test_extract_endpoints(net, img_size): - """Test `.extract_endpoints()` doesn't throw an error""" - data = torch.zeros((1, 3, img_size, img_size)) - endpoints = net.extract_endpoints(data) - assert not torch.isnan(endpoints['reduction_1']).any() - assert not torch.isnan(endpoints['reduction_2']).any() - assert not torch.isnan(endpoints['reduction_3']).any() - assert not torch.isnan(endpoints['reduction_4']).any() - assert not torch.isnan(endpoints['reduction_5']).any() - assert endpoints['reduction_1'].size(2) == img_size // 2 - assert endpoints['reduction_2'].size(2) == img_size // 4 - assert endpoints['reduction_3'].size(2) == img_size // 8 - assert endpoints['reduction_4'].size(2) == img_size // 16 - assert endpoints['reduction_5'].size(2) == img_size // 32 +# Copyright [yyyy] [name of copyright owner] +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from collections import OrderedDict + +import pytest +import torch +import torch.nn as nn + +from efficientnet_pytorch import EfficientNet + + +# -- fixtures ------------------------------------------------------------------------------------- + +@pytest.fixture(scope='module', params=[x for x in range(4)]) +def model(request): + return 'efficientnet-b{}'.format(request.param) + + +@pytest.fixture(scope='module', params=[True, False]) +def pretrained(request): + return request.param + + +@pytest.fixture(scope='function') +def net(model, pretrained): + return EfficientNet.from_pretrained(model) if pretrained else EfficientNet.from_name(model) + + +# -- tests ---------------------------------------------------------------------------------------- + +@pytest.mark.parametrize('img_size', [224, 256, 512]) +def test_forward(net, img_size): + """Test `.forward()` doesn't throw an error""" + data = torch.zeros((1, 3, img_size, img_size)) + output = net(data) + assert not torch.isnan(output).any() + + +def test_dropout_training(net): + """Test dropout `.training` is set by `.train()` on parent `nn.module`""" + net.train() + assert net._dropout.training == True + + +def test_dropout_eval(net): + """Test dropout `.training` is set by `.eval()` on parent `nn.module`""" + net.eval() + assert net._dropout.training == False + + +def test_dropout_update(net): + """Test dropout `.training` is updated by `.train()` and `.eval()` on parent `nn.module`""" + net.train() + assert net._dropout.training == True + net.eval() + assert net._dropout.training == False + net.train() + assert net._dropout.training == True + net.eval() + assert net._dropout.training == False + + +@pytest.mark.parametrize('img_size', [224, 256, 512]) +def test_modify_dropout(net, img_size): + """Test ability to modify dropout and fc modules of network""" + dropout = nn.Sequential(OrderedDict([ + ('_bn2', nn.BatchNorm1d(net._bn1.num_features)), + ('_drop1', nn.Dropout(p=net._global_params.dropout_rate)), + ('_linear1', nn.Linear(net._bn1.num_features, 512)), + ('_relu', nn.ReLU()), + ('_bn3', nn.BatchNorm1d(512)), + ('_drop2', nn.Dropout(p=net._global_params.dropout_rate / 2)) + ])) + fc = nn.Linear(512, net._global_params.num_classes) + + net._dropout = dropout + net._fc = fc + + data = torch.zeros((2, 3, img_size, img_size)) + output = net(data) + assert not torch.isnan(output).any() + + +@pytest.mark.parametrize('img_size', [224, 256, 512]) +def test_modify_pool(net, img_size): + """Test ability to modify pooling module of network""" + + class AdaptiveMaxAvgPool(nn.Module): + + def __init__(self): + super().__init__() + self.ada_avgpool = nn.AdaptiveAvgPool2d(1) + self.ada_maxpool = nn.AdaptiveMaxPool2d(1) + + def forward(self, x): + avg_x = self.ada_avgpool(x) + max_x = self.ada_maxpool(x) + x = torch.cat((avg_x, max_x), dim=1) + return x + + avg_pooling = AdaptiveMaxAvgPool() + fc = nn.Linear(net._fc.in_features * 2, net._global_params.num_classes) + + net._avg_pooling = avg_pooling + net._fc = fc + + data = torch.zeros((2, 3, img_size, img_size)) + output = net(data) + assert not torch.isnan(output).any() + + +@pytest.mark.parametrize('img_size', [224, 256, 512]) +def test_extract_endpoints(net, img_size): + """Test `.extract_endpoints()` doesn't throw an error""" + data = torch.zeros((1, 3, img_size, img_size)) + endpoints = net.extract_endpoints(data) + assert not torch.isnan(endpoints['reduction_1']).any() + assert not torch.isnan(endpoints['reduction_2']).any() + assert not torch.isnan(endpoints['reduction_3']).any() + assert not torch.isnan(endpoints['reduction_4']).any() + assert not torch.isnan(endpoints['reduction_5']).any() + assert endpoints['reduction_1'].size(2) == img_size // 2 + assert endpoints['reduction_2'].size(2) == img_size // 4 + assert endpoints['reduction_3'].size(2) == img_size // 8 + assert endpoints['reduction_4'].size(2) == img_size // 16 + assert endpoints['reduction_5'].size(2) == img_size // 32 diff --git a/PyTorch/built-in/cv/classification/MobileNetV2_for_PyTorch/test/train_ID3072_MobileNetV2_performance_1p.sh b/PyTorch/built-in/cv/classification/MobileNetV2_for_PyTorch/test/train_ID3072_MobileNetV2_performance_1p.sh index 86b6ec9d5eededfc19c507c495dfe4974a280954..3ca029d3513516d6a352821156e03d22da5bd12e 100644 --- a/PyTorch/built-in/cv/classification/MobileNetV2_for_PyTorch/test/train_ID3072_MobileNetV2_performance_1p.sh +++ b/PyTorch/built-in/cv/classification/MobileNetV2_for_PyTorch/test/train_ID3072_MobileNetV2_performance_1p.sh @@ -1,164 +1,164 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` - - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -#RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="MobileNetV2_ID3072_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=512 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - -#参数修改 -sed -i "s|pass|break|g" ${cur_path}/../train/mobilenetv2_8p_main_anycard.py -wait - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -# 绑核,不需要的绑核的模型删除,需要模型审视修改 -python3.7 ${cur_path}/../train/mobilenetv2_8p_main_anycard.py \ - --addr=$(hostname -I |awk '{print $1}') \ - --seed 49 \ - --workers 128 \ - --lr 0.05 \ - --print-freq 1 \ - --eval-freq 1 \ - --dist-url 'tcp://127.0.0.1:50002' \ - --dist-backend 'hccl' \ - --multiprocessing-distributed \ - --world-size 1 \ - --class-nums 1000 \ - --batch-size $batch_size \ - --epochs $train_epochs \ - --rank 0 \ - --device-list $ASCEND_DEVICE_ID \ - --amp \ - --benchmark 0 \ - --graph_mode \ - --data $data_path > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#参数改回 -sed -i "s|break|pass|g" ${cur_path}/../train/mobilenetv2_8p_main_anycard.py -wait - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}' |awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` + + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +#RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="MobileNetV2_ID3072_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=512 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $cur_path/output ];then + rm -rf $cur_path/output/* + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +fi +wait + +#参数修改 +sed -i "s|pass|break|g" ${cur_path}/../train/mobilenetv2_8p_main_anycard.py +wait + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +# 绑核,不需要的绑核的模型删除,需要模型审视修改 +python3.7 ${cur_path}/../train/mobilenetv2_8p_main_anycard.py \ + --addr=$(hostname -I |awk '{print $1}') \ + --seed 49 \ + --workers 128 \ + --lr 0.05 \ + --print-freq 1 \ + --eval-freq 1 \ + --dist-url 'tcp://127.0.0.1:50002' \ + --dist-backend 'hccl' \ + --multiprocessing-distributed \ + --world-size 1 \ + --class-nums 1000 \ + --batch-size $batch_size \ + --epochs $train_epochs \ + --rank 0 \ + --device-list $ASCEND_DEVICE_ID \ + --amp \ + --benchmark 0 \ + --graph_mode \ + --data $data_path > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#参数改回 +sed -i "s|break|pass|g" ${cur_path}/../train/mobilenetv2_8p_main_anycard.py +wait + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}' |awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/classification/MobileNetV2_for_PyTorch/test/train_ID3072_MobileNetV2_performance_8p.sh b/PyTorch/built-in/cv/classification/MobileNetV2_for_PyTorch/test/train_ID3072_MobileNetV2_performance_8p.sh index 45d3585e41dc1130179fa48a37d16e5202ce5dfb..75fce3020beb6ad4247c3c40175258ea3b577ad5 100644 --- a/PyTorch/built-in/cv/classification/MobileNetV2_for_PyTorch/test/train_ID3072_MobileNetV2_performance_8p.sh +++ b/PyTorch/built-in/cv/classification/MobileNetV2_for_PyTorch/test/train_ID3072_MobileNetV2_performance_8p.sh @@ -1,164 +1,164 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -#RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="MobileNetV2_ID3072_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=4096 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - - - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - -#参数修改 -sed -i "s|pass|break|g" ${cur_path}/../train/mobilenetv2_8p_main_anycard.py -wait - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -python3.7 ${cur_path}/../train/mobilenetv2_8p_main_anycard.py \ - --addr=$(hostname -I |awk '{print $1}') \ - --seed 49 \ - --workers 128 \ - --lr 0.4 \ - --print-freq 1 \ - --eval-freq 1 \ - --dist-url 'tcp://127.0.0.1:50002' \ - --dist-backend 'hccl' \ - --multiprocessing-distributed \ - --world-size 1 \ - --class-nums 1000 \ - --batch-size $batch_size \ - --epochs $train_epochs \ - --rank 0 \ - --device-list '0,1,2,3,4,5,6,7' \ - --amp \ - --benchmark 0 \ - --graph_mode \ - --data $data_path > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#参数改回 -sed -i "s|break|pass|g" ${cur_path}/../train/mobilenetv2_8p_main_anycard.py -wait - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}' |awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +#RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="MobileNetV2_ID3072_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=4096 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + + + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $cur_path/output ];then + rm -rf $cur_path/output/* + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +fi +wait + +#参数修改 +sed -i "s|pass|break|g" ${cur_path}/../train/mobilenetv2_8p_main_anycard.py +wait + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +python3.7 ${cur_path}/../train/mobilenetv2_8p_main_anycard.py \ + --addr=$(hostname -I |awk '{print $1}') \ + --seed 49 \ + --workers 128 \ + --lr 0.4 \ + --print-freq 1 \ + --eval-freq 1 \ + --dist-url 'tcp://127.0.0.1:50002' \ + --dist-backend 'hccl' \ + --multiprocessing-distributed \ + --world-size 1 \ + --class-nums 1000 \ + --batch-size $batch_size \ + --epochs $train_epochs \ + --rank 0 \ + --device-list '0,1,2,3,4,5,6,7' \ + --amp \ + --benchmark 0 \ + --graph_mode \ + --data $data_path > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#参数改回 +sed -i "s|break|pass|g" ${cur_path}/../train/mobilenetv2_8p_main_anycard.py +wait + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}' |awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/CMakeLists.txt b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/CMakeLists.txt index dccbd552fe36028a316284c1f59ee3c7119c81d0..903f82d57a2161d278c4c46698b8430ecebd7e4b 100644 --- a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/CMakeLists.txt +++ b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/CMakeLists.txt @@ -1,49 +1,49 @@ -cmake_minimum_required(VERSION 3.14.0) -project(resnet50) - -set(TARGET resnet50) - -add_definitions(-DENABLE_DVPP_INTERFACE) -add_compile_options(-std=c++11 -fPIE -fstack-protector-all -fPIC -Wall) -add_link_options(-Wl,-z,relro,-z,now,-z,noexecstack -s -pie) - -# Check environment variable -if(NOT DEFINED ENV{ASCEND_HOME}) - message(FATAL_ERROR "please define environment variable:ASCEND_HOME") -endif() -if(NOT DEFINED ENV{ASCEND_VERSION}) - message(WARNING "please define environment variable:ASCEND_VERSION") -endif() -if(NOT DEFINED ENV{ARCH_PATTERN}) - message(WARNING "please define environment variable:ARCH_PATTERN") -endif() -set(ACL_INC_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/include) -set(ACL_LIB_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/lib64) - -set(MXBASE_ROOT_DIR ${PROJECT_SOURCE_DIR}/../../) -set(MXBASE_INC ${MXBASE_ROOT_DIR}/mxbase/include) -set(MXBASE_LIB_DIR ${MXBASE_ROOT_DIR}/dist/lib) -set(MXBASE_POST_LIB_DIR ${MXBASE_ROOT_DIR}/dist/lib/modelpostprocessors) -set(MXBASE_POST_PROCESS_DIR ${MXBASE_ROOT_DIR}/postprocess/include) -if(DEFINED ENV{MXSDK_OPENSOURCE_DIR}) - set(OPENSOURCE_DIR $ENV{MXSDK_OPENSOURCE_DIR}) -else() - set(OPENSOURCE_DIR ${MXBASE_ROOT_DIR}/opensource/dist) -endif() - -include_directories(${ACL_INC_DIR}) -include_directories(${OPENSOURCE_DIR}/include) -include_directories(${OPENSOURCE_DIR}/include/opencv4) - -include_directories(${MXBASE_INC}) -include_directories(${MXBASE_POST_PROCESS_DIR}) - -link_directories(${ACL_LIB_DIR}) -link_directories(${OPENSOURCE_DIR}/lib) -link_directories(${MXBASE_LIB_DIR}) -link_directories(${MXBASE_POST_LIB_DIR}) - -add_executable(${TARGET} main.cpp Resnet50Classify.cpp) -target_link_libraries(${TARGET} glog cpprest mxbase resnet50postprocess opencv_world stdc++fs) - +cmake_minimum_required(VERSION 3.14.0) +project(resnet50) + +set(TARGET resnet50) + +add_definitions(-DENABLE_DVPP_INTERFACE) +add_compile_options(-std=c++11 -fPIE -fstack-protector-all -fPIC -Wall) +add_link_options(-Wl,-z,relro,-z,now,-z,noexecstack -s -pie) + +# Check environment variable +if(NOT DEFINED ENV{ASCEND_HOME}) + message(FATAL_ERROR "please define environment variable:ASCEND_HOME") +endif() +if(NOT DEFINED ENV{ASCEND_VERSION}) + message(WARNING "please define environment variable:ASCEND_VERSION") +endif() +if(NOT DEFINED ENV{ARCH_PATTERN}) + message(WARNING "please define environment variable:ARCH_PATTERN") +endif() +set(ACL_INC_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/include) +set(ACL_LIB_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/lib64) + +set(MXBASE_ROOT_DIR ${PROJECT_SOURCE_DIR}/../../) +set(MXBASE_INC ${MXBASE_ROOT_DIR}/mxbase/include) +set(MXBASE_LIB_DIR ${MXBASE_ROOT_DIR}/dist/lib) +set(MXBASE_POST_LIB_DIR ${MXBASE_ROOT_DIR}/dist/lib/modelpostprocessors) +set(MXBASE_POST_PROCESS_DIR ${MXBASE_ROOT_DIR}/postprocess/include) +if(DEFINED ENV{MXSDK_OPENSOURCE_DIR}) + set(OPENSOURCE_DIR $ENV{MXSDK_OPENSOURCE_DIR}) +else() + set(OPENSOURCE_DIR ${MXBASE_ROOT_DIR}/opensource/dist) +endif() + +include_directories(${ACL_INC_DIR}) +include_directories(${OPENSOURCE_DIR}/include) +include_directories(${OPENSOURCE_DIR}/include/opencv4) + +include_directories(${MXBASE_INC}) +include_directories(${MXBASE_POST_PROCESS_DIR}) + +link_directories(${ACL_LIB_DIR}) +link_directories(${OPENSOURCE_DIR}/lib) +link_directories(${MXBASE_LIB_DIR}) +link_directories(${MXBASE_POST_LIB_DIR}) + +add_executable(${TARGET} main.cpp Resnet50Classify.cpp) +target_link_libraries(${TARGET} glog cpprest mxbase resnet50postprocess opencv_world stdc++fs) + install(TARGETS ${TARGET} RUNTIME DESTINATION ${PROJECT_SOURCE_DIR}/) \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/Resnet50Classify.cpp b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/Resnet50Classify.cpp index 024a9c3ae1ba1017d377af5dfe19988c937b1584..6322732d106d6e5b3df5a69ff156ca5c86dad7f2 100644 --- a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/Resnet50Classify.cpp +++ b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/Resnet50Classify.cpp @@ -1,261 +1,261 @@ -/* - * Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Resnet50Classify.h" -#include "MxBase/DeviceManager/DeviceManager.h" -#include "MxBase/Log/Log.h" - -using namespace MxBase; -namespace { -const uint32_t YUV_BYTE_NU = 3; -const uint32_t YUV_BYTE_DE = 2; -const uint32_t VPC_H_ALIGN = 2; -} - -APP_ERROR Resnet50Classify::Init(const InitParam &initParam) -{ - deviceId_ = initParam.deviceId; - APP_ERROR ret = MxBase::DeviceManager::GetInstance()->InitDevices(); - if (ret != APP_ERR_OK) { - LogError << "Init devices failed, ret=" << ret << "."; - return ret; - } - ret = MxBase::TensorContext::GetInstance()->SetContext(initParam.deviceId); - if (ret != APP_ERR_OK) { - LogError << "Set context failed, ret=" << ret << "."; - return ret; - } - dvppWrapper_ = std::make_shared(); - ret = dvppWrapper_->Init(); - if (ret != APP_ERR_OK) { - LogError << "DvppWrapper init failed, ret=" << ret << "."; - return ret; - } - model_ = std::make_shared(); - ret = model_->Init(initParam.modelPath, modelDesc_); - if (ret != APP_ERR_OK) { - LogError << "ModelInferenceProcessor init failed, ret=" << ret << "."; - return ret; - } - MxBase::ConfigData configData; - const std::string softmax = initParam.softmax ? "true" : "false"; - const std::string checkTensor = initParam.checkTensor ? "true" : "false"; - - configData.SetJsonValue("CLASS_NUM", std::to_string(initParam.classNum)); - configData.SetJsonValue("TOP_K", std::to_string(initParam.topk)); - configData.SetJsonValue("SOFTMAX", softmax); - configData.SetJsonValue("CHECK_MODEL", checkTensor); - - auto jsonStr = configData.GetCfgJson().serialize(); - std::map> config; - config["postProcessConfigContent"] = std::make_shared(jsonStr); - config["labelPath"] = std::make_shared(initParam.labelPath); - - post_ = std::make_shared(); - ret = post_->Init(config); - if (ret != APP_ERR_OK) { - LogError << "Resnet50PostProcess init failed, ret=" << ret << "."; - return ret; - } - return APP_ERR_OK; -} - -APP_ERROR Resnet50Classify::DeInit() -{ - dvppWrapper_->DeInit(); - model_->DeInit(); - post_->DeInit(); - MxBase::DeviceManager::GetInstance()->DestroyDevices(); - return APP_ERR_OK; -} - -APP_ERROR Resnet50Classify::ReadImage(const std::string &imgPath, cv::Mat &imageMat) -{ - imageMat = cv::imread(imgPath, cv::IMREAD_COLOR); - return APP_ERR_OK; -} - -APP_ERROR Resnet50Classify::CenterCropImage(cv::Mat &img, cv::Mat &cropImg) -{ - float central_fraction = 0.75; - int crop_x = img.cols * central_fraction; - int crop_y = img.rows * central_fraction; - int crop_x1 = (img.cols - crop_x) / 2; - int crop_y1 = (img.rows - crop_y) / 2; - - cv::Rect myROI(crop_x1, crop_y1, crop_x, crop_y); - LogInfo << "images crop_x1: " << crop_x1 << ", crop_x: " << crop_x << ", crop_y1: " << crop_y1 << ", crop_y: " << crop_y; - cropImg = img(myROI); - return APP_ERR_OK; -} - -APP_ERROR Resnet50Classify::Resize(const cv::Mat &srcImageMat, cv::Mat &dstImageMat) -{ - static constexpr uint32_t resizeHeight = 256; - static constexpr uint32_t resizeWidth = 256; - - cv::resize(srcImageMat, dstImageMat, cv::Size(resizeWidth, resizeHeight)); - return APP_ERR_OK; -} - -APP_ERROR Resnet50Classify::CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase) -{ - const uint32_t dataSize = imageMat.cols * imageMat.rows * YUV444_RGB_WIDTH_NU; - MemoryData memoryDataDst(dataSize, MemoryData::MEMORY_DEVICE, deviceId_); - MemoryData memoryDataSrc(imageMat.data, dataSize, MemoryData::MEMORY_HOST_MALLOC); - - APP_ERROR ret = MemoryHelper::MxbsMallocAndCopy(memoryDataDst, memoryDataSrc); - if (ret != APP_ERR_OK) { - LogError << GetError(ret) << "Memory malloc failed."; - return ret; - } - std::vector shape = {imageMat.rows * YUV444_RGB_WIDTH_NU, static_cast(imageMat.cols)}; - tensorBase = TensorBase(memoryDataDst, false, shape, TENSOR_DTYPE_UINT8); - return APP_ERR_OK; -} - -APP_ERROR Resnet50Classify::Inference(const std::vector &inputs, - std::vector &outputs) -{ - auto dtypes = model_->GetOutputDataType(); - for (size_t i = 0; i < modelDesc_.outputTensors.size(); ++i) { - std::vector shape = {}; - for (size_t j = 0; j < modelDesc_.outputTensors[i].tensorDims.size(); ++j) { - shape.push_back((uint32_t)modelDesc_.outputTensors[i].tensorDims[j]); - } - TensorBase tensor(shape, dtypes[i], MemoryData::MemoryType::MEMORY_DEVICE, deviceId_); - APP_ERROR ret = TensorBase::TensorBaseMalloc(tensor); - if (ret != APP_ERR_OK) { - LogError << "TensorBaseMalloc failed, ret=" << ret << "."; - return ret; - } - outputs.push_back(tensor); - } - DynamicInfo dynamicInfo = {}; - dynamicInfo.dynamicType = DynamicType::STATIC_BATCH; - auto startTime = std::chrono::high_resolution_clock::now(); - APP_ERROR ret = model_->ModelInference(inputs, outputs, dynamicInfo); - auto endTime = std::chrono::high_resolution_clock::now(); - double costMs = std::chrono::duration(endTime - startTime).count(); - g_inferCost.push_back(costMs); - if (ret != APP_ERR_OK) { - LogError << "ModelInference failed, ret=" << ret << "."; - return ret; - } - return APP_ERR_OK; -} - -APP_ERROR Resnet50Classify::PostProcess(const std::vector &inputs, - std::vector> &clsInfos) -{ - APP_ERROR ret = post_->Process(inputs, clsInfos); - if (ret != APP_ERR_OK) { - LogError << "Process failed, ret=" << ret << "."; - return ret; - } - return APP_ERR_OK; -} - -APP_ERROR Resnet50Classify::SaveInferResult(const std::string &imagePath, std::vector> &batchClsInfos) -{ - uint32_t batchIndex = 0; - LogInfo << "image path: " << imagePath; - std::string fileName = imagePath.substr(imagePath.find_last_of("/") + 1); - size_t dot = fileName.find_last_of("."); - - std::string resultPathName = "result"; - if (access(resultPathName.c_str(), 0) != 0) { - APP_ERROR ret = mkdir(resultPathName.c_str(), S_IRUSR | S_IWUSR | S_IXUSR); - if (ret != 0) { - LogError << "Failed to create result directory: " << resultPathName << ", ret = " << ret; - return APP_ERR_COMM_FAILURE; - } - } - std::string resFileName = "result/" + fileName.substr(0,dot) + "_1.txt"; - LogInfo << "file path for saving result: " << resFileName; - std::ofstream tfile(resFileName); - if (tfile.fail()) { - LogError << "Failed to open result file"; - return APP_ERR_COMM_FAILURE; - } - - for (auto clsInfos : batchClsInfos) { - std::string resultStr = ""; - for (auto clsInfo : clsInfos) { - LogDebug << "batchIndex: " << batchIndex << " className: " << clsInfo.className - << " confidence: " << clsInfo.confidence << " classIndex: " << clsInfo.classId; - resultStr += std::to_string(clsInfo.classId) + " "; - } - tfile << resultStr << std::endl; - batchIndex += 1; - } - tfile.close(); - return APP_ERR_OK; -} - -APP_ERROR Resnet50Classify::Process(const std::string &imgPath) -{ - cv::Mat imageMat; - APP_ERROR ret = ReadImage(imgPath, imageMat); - if (ret != APP_ERR_OK) { - LogError << "ReadImage failed, ret=" << ret << "."; - return ret; - } - - ret = CenterCropImage(imageMat, imageMat); - if (ret != APP_ERR_OK) { - LogError << "crop failed, ret=" << ret << "."; - return ret; - } - ret = Resize(imageMat, imageMat); - if (ret != APP_ERR_OK) { - LogError << "Resize failed, ret=" << ret << "."; - return ret; - } - - std::vector inputs = {}; - std::vector outputs = {}; - TensorBase tensorBase; - ret = CVMatToTensorBase(imageMat, tensorBase); - if (ret != APP_ERR_OK) { - LogError << "CVMatToTensorBase failed, ret=" << ret << "."; - return ret; - } - inputs.push_back(tensorBase); - ret = Inference(inputs, outputs); - if (ret != APP_ERR_OK) { - LogError << "Inference failed, ret=" << ret << "."; - return ret; - } - - std::vector> BatchClsInfos = {}; - ret = PostProcess(outputs, BatchClsInfos); - if (ret != APP_ERR_OK) { - LogError << "PostProcess failed, ret=" << ret << "."; - return ret; - } - - ret = SaveInferResult(imgPath, BatchClsInfos); - if (ret != APP_ERR_OK) { - LogError << "Save results failed, ret: " << ret << "."; - return ret; - } - - imageMat.release(); - return APP_ERR_OK; +/* + * Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "Resnet50Classify.h" +#include "MxBase/DeviceManager/DeviceManager.h" +#include "MxBase/Log/Log.h" + +using namespace MxBase; +namespace { +const uint32_t YUV_BYTE_NU = 3; +const uint32_t YUV_BYTE_DE = 2; +const uint32_t VPC_H_ALIGN = 2; +} + +APP_ERROR Resnet50Classify::Init(const InitParam &initParam) +{ + deviceId_ = initParam.deviceId; + APP_ERROR ret = MxBase::DeviceManager::GetInstance()->InitDevices(); + if (ret != APP_ERR_OK) { + LogError << "Init devices failed, ret=" << ret << "."; + return ret; + } + ret = MxBase::TensorContext::GetInstance()->SetContext(initParam.deviceId); + if (ret != APP_ERR_OK) { + LogError << "Set context failed, ret=" << ret << "."; + return ret; + } + dvppWrapper_ = std::make_shared(); + ret = dvppWrapper_->Init(); + if (ret != APP_ERR_OK) { + LogError << "DvppWrapper init failed, ret=" << ret << "."; + return ret; + } + model_ = std::make_shared(); + ret = model_->Init(initParam.modelPath, modelDesc_); + if (ret != APP_ERR_OK) { + LogError << "ModelInferenceProcessor init failed, ret=" << ret << "."; + return ret; + } + MxBase::ConfigData configData; + const std::string softmax = initParam.softmax ? "true" : "false"; + const std::string checkTensor = initParam.checkTensor ? "true" : "false"; + + configData.SetJsonValue("CLASS_NUM", std::to_string(initParam.classNum)); + configData.SetJsonValue("TOP_K", std::to_string(initParam.topk)); + configData.SetJsonValue("SOFTMAX", softmax); + configData.SetJsonValue("CHECK_MODEL", checkTensor); + + auto jsonStr = configData.GetCfgJson().serialize(); + std::map> config; + config["postProcessConfigContent"] = std::make_shared(jsonStr); + config["labelPath"] = std::make_shared(initParam.labelPath); + + post_ = std::make_shared(); + ret = post_->Init(config); + if (ret != APP_ERR_OK) { + LogError << "Resnet50PostProcess init failed, ret=" << ret << "."; + return ret; + } + return APP_ERR_OK; +} + +APP_ERROR Resnet50Classify::DeInit() +{ + dvppWrapper_->DeInit(); + model_->DeInit(); + post_->DeInit(); + MxBase::DeviceManager::GetInstance()->DestroyDevices(); + return APP_ERR_OK; +} + +APP_ERROR Resnet50Classify::ReadImage(const std::string &imgPath, cv::Mat &imageMat) +{ + imageMat = cv::imread(imgPath, cv::IMREAD_COLOR); + return APP_ERR_OK; +} + +APP_ERROR Resnet50Classify::CenterCropImage(cv::Mat &img, cv::Mat &cropImg) +{ + float central_fraction = 0.75; + int crop_x = img.cols * central_fraction; + int crop_y = img.rows * central_fraction; + int crop_x1 = (img.cols - crop_x) / 2; + int crop_y1 = (img.rows - crop_y) / 2; + + cv::Rect myROI(crop_x1, crop_y1, crop_x, crop_y); + LogInfo << "images crop_x1: " << crop_x1 << ", crop_x: " << crop_x << ", crop_y1: " << crop_y1 << ", crop_y: " << crop_y; + cropImg = img(myROI); + return APP_ERR_OK; +} + +APP_ERROR Resnet50Classify::Resize(const cv::Mat &srcImageMat, cv::Mat &dstImageMat) +{ + static constexpr uint32_t resizeHeight = 256; + static constexpr uint32_t resizeWidth = 256; + + cv::resize(srcImageMat, dstImageMat, cv::Size(resizeWidth, resizeHeight)); + return APP_ERR_OK; +} + +APP_ERROR Resnet50Classify::CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase) +{ + const uint32_t dataSize = imageMat.cols * imageMat.rows * YUV444_RGB_WIDTH_NU; + MemoryData memoryDataDst(dataSize, MemoryData::MEMORY_DEVICE, deviceId_); + MemoryData memoryDataSrc(imageMat.data, dataSize, MemoryData::MEMORY_HOST_MALLOC); + + APP_ERROR ret = MemoryHelper::MxbsMallocAndCopy(memoryDataDst, memoryDataSrc); + if (ret != APP_ERR_OK) { + LogError << GetError(ret) << "Memory malloc failed."; + return ret; + } + std::vector shape = {imageMat.rows * YUV444_RGB_WIDTH_NU, static_cast(imageMat.cols)}; + tensorBase = TensorBase(memoryDataDst, false, shape, TENSOR_DTYPE_UINT8); + return APP_ERR_OK; +} + +APP_ERROR Resnet50Classify::Inference(const std::vector &inputs, + std::vector &outputs) +{ + auto dtypes = model_->GetOutputDataType(); + for (size_t i = 0; i < modelDesc_.outputTensors.size(); ++i) { + std::vector shape = {}; + for (size_t j = 0; j < modelDesc_.outputTensors[i].tensorDims.size(); ++j) { + shape.push_back((uint32_t)modelDesc_.outputTensors[i].tensorDims[j]); + } + TensorBase tensor(shape, dtypes[i], MemoryData::MemoryType::MEMORY_DEVICE, deviceId_); + APP_ERROR ret = TensorBase::TensorBaseMalloc(tensor); + if (ret != APP_ERR_OK) { + LogError << "TensorBaseMalloc failed, ret=" << ret << "."; + return ret; + } + outputs.push_back(tensor); + } + DynamicInfo dynamicInfo = {}; + dynamicInfo.dynamicType = DynamicType::STATIC_BATCH; + auto startTime = std::chrono::high_resolution_clock::now(); + APP_ERROR ret = model_->ModelInference(inputs, outputs, dynamicInfo); + auto endTime = std::chrono::high_resolution_clock::now(); + double costMs = std::chrono::duration(endTime - startTime).count(); + g_inferCost.push_back(costMs); + if (ret != APP_ERR_OK) { + LogError << "ModelInference failed, ret=" << ret << "."; + return ret; + } + return APP_ERR_OK; +} + +APP_ERROR Resnet50Classify::PostProcess(const std::vector &inputs, + std::vector> &clsInfos) +{ + APP_ERROR ret = post_->Process(inputs, clsInfos); + if (ret != APP_ERR_OK) { + LogError << "Process failed, ret=" << ret << "."; + return ret; + } + return APP_ERR_OK; +} + +APP_ERROR Resnet50Classify::SaveInferResult(const std::string &imagePath, std::vector> &batchClsInfos) +{ + uint32_t batchIndex = 0; + LogInfo << "image path: " << imagePath; + std::string fileName = imagePath.substr(imagePath.find_last_of("/") + 1); + size_t dot = fileName.find_last_of("."); + + std::string resultPathName = "result"; + if (access(resultPathName.c_str(), 0) != 0) { + APP_ERROR ret = mkdir(resultPathName.c_str(), S_IRUSR | S_IWUSR | S_IXUSR); + if (ret != 0) { + LogError << "Failed to create result directory: " << resultPathName << ", ret = " << ret; + return APP_ERR_COMM_FAILURE; + } + } + std::string resFileName = "result/" + fileName.substr(0,dot) + "_1.txt"; + LogInfo << "file path for saving result: " << resFileName; + std::ofstream tfile(resFileName); + if (tfile.fail()) { + LogError << "Failed to open result file"; + return APP_ERR_COMM_FAILURE; + } + + for (auto clsInfos : batchClsInfos) { + std::string resultStr = ""; + for (auto clsInfo : clsInfos) { + LogDebug << "batchIndex: " << batchIndex << " className: " << clsInfo.className + << " confidence: " << clsInfo.confidence << " classIndex: " << clsInfo.classId; + resultStr += std::to_string(clsInfo.classId) + " "; + } + tfile << resultStr << std::endl; + batchIndex += 1; + } + tfile.close(); + return APP_ERR_OK; +} + +APP_ERROR Resnet50Classify::Process(const std::string &imgPath) +{ + cv::Mat imageMat; + APP_ERROR ret = ReadImage(imgPath, imageMat); + if (ret != APP_ERR_OK) { + LogError << "ReadImage failed, ret=" << ret << "."; + return ret; + } + + ret = CenterCropImage(imageMat, imageMat); + if (ret != APP_ERR_OK) { + LogError << "crop failed, ret=" << ret << "."; + return ret; + } + ret = Resize(imageMat, imageMat); + if (ret != APP_ERR_OK) { + LogError << "Resize failed, ret=" << ret << "."; + return ret; + } + + std::vector inputs = {}; + std::vector outputs = {}; + TensorBase tensorBase; + ret = CVMatToTensorBase(imageMat, tensorBase); + if (ret != APP_ERR_OK) { + LogError << "CVMatToTensorBase failed, ret=" << ret << "."; + return ret; + } + inputs.push_back(tensorBase); + ret = Inference(inputs, outputs); + if (ret != APP_ERR_OK) { + LogError << "Inference failed, ret=" << ret << "."; + return ret; + } + + std::vector> BatchClsInfos = {}; + ret = PostProcess(outputs, BatchClsInfos); + if (ret != APP_ERR_OK) { + LogError << "PostProcess failed, ret=" << ret << "."; + return ret; + } + + ret = SaveInferResult(imgPath, BatchClsInfos); + if (ret != APP_ERR_OK) { + LogError << "Save results failed, ret: " << ret << "."; + return ret; + } + + imageMat.release(); + return APP_ERR_OK; } \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/Resnet50Classify.h b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/Resnet50Classify.h index 02f3b59774eb485bfbf28f371f16d737b059a140..7d2ec48a2a98819115217523b603653ab1d5ae32 100644 --- a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/Resnet50Classify.h +++ b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/Resnet50Classify.h @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef RESNET50_CLASSIFY_H -#define RESNET50_CLASSIFY_H - -#include -#include "MxBase/DvppWrapper/DvppWrapper.h" -#include "MxBase/ModelInfer/ModelInferenceProcessor.h" -#include "ClassPostProcessors/Resnet50PostProcess.h" -#include "MxBase/Tensor/TensorContext/TensorContext.h" - -extern std::vector g_inferCost; - -struct InitParam { - uint32_t deviceId; - std::string labelPath; - uint32_t classNum; - uint32_t topk; - bool softmax; - bool checkTensor; - std::string modelPath; -}; - -class Resnet50Classify { -public: - APP_ERROR Init(const InitParam &initParam); - APP_ERROR DeInit(); - APP_ERROR ReadImage(const std::string &imgPath, cv::Mat &imageMat); - APP_ERROR Resize(const cv::Mat &srcImageMat, cv::Mat &dstImageMat); - APP_ERROR CenterCropImage(cv::Mat &img, cv::Mat &cropImg); - APP_ERROR CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase); - APP_ERROR Inference(const std::vector &inputs, std::vector &outputs); - APP_ERROR PostProcess(const std::vector &inputs, - std::vector> &clsInfos); - APP_ERROR SaveInferResult(const std::string &imgPath, - std::vector> &batchClsInfos); - APP_ERROR Process(const std::string &imgPath); -private: - std::shared_ptr dvppWrapper_; - std::shared_ptr model_; - std::shared_ptr post_; - MxBase::ModelDesc modelDesc_; - uint32_t deviceId_ = 0; -}; +/* + * Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RESNET50_CLASSIFY_H +#define RESNET50_CLASSIFY_H + +#include +#include "MxBase/DvppWrapper/DvppWrapper.h" +#include "MxBase/ModelInfer/ModelInferenceProcessor.h" +#include "ClassPostProcessors/Resnet50PostProcess.h" +#include "MxBase/Tensor/TensorContext/TensorContext.h" + +extern std::vector g_inferCost; + +struct InitParam { + uint32_t deviceId; + std::string labelPath; + uint32_t classNum; + uint32_t topk; + bool softmax; + bool checkTensor; + std::string modelPath; +}; + +class Resnet50Classify { +public: + APP_ERROR Init(const InitParam &initParam); + APP_ERROR DeInit(); + APP_ERROR ReadImage(const std::string &imgPath, cv::Mat &imageMat); + APP_ERROR Resize(const cv::Mat &srcImageMat, cv::Mat &dstImageMat); + APP_ERROR CenterCropImage(cv::Mat &img, cv::Mat &cropImg); + APP_ERROR CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase); + APP_ERROR Inference(const std::vector &inputs, std::vector &outputs); + APP_ERROR PostProcess(const std::vector &inputs, + std::vector> &clsInfos); + APP_ERROR SaveInferResult(const std::string &imgPath, + std::vector> &batchClsInfos); + APP_ERROR Process(const std::string &imgPath); +private: + std::shared_ptr dvppWrapper_; + std::shared_ptr model_; + std::shared_ptr post_; + MxBase::ModelDesc modelDesc_; + uint32_t deviceId_ = 0; +}; #endif \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/classification_task_metric.py b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/classification_task_metric.py index da35817a4d560028d5d591d5bdac434b39b87ee7..faa5f9d31cf3ecdcc3c6e106d39b57585b7d3b76 100644 --- a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/classification_task_metric.py +++ b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/classification_task_metric.py @@ -1,174 +1,174 @@ -#coding = utf-8 -#Copyright 2020 Huawei Technologies Co., Ltd -# -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -#http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - """ - :param img_name:image file name contains file path - :return:image file name without file path - """ - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param gtfile_path: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param gtfile_path: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - img_name = temp[0].split(".")[0] - img_lab = temp[1] - img_gt_dict[img_name] = img_lab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - :param filepath: the result of model predict - :return probabilities, number of label, in_type, color: - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, cls_ind in enumerate(temp): - if cls_ind: - data_vec[ind] = np.int(cls_ind) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, n_labels, topn=5): - """ - :param prediction_file_path: the result of model predict - :param result_store_path: the root path to store result - :param json_file: json file to save result - :param img_gt_dict: the ground truth of imagenet - :param topn: classify model acc topk - :return:NA - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - res_cnt = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - gt = img_gt_dict[img_name] - real_label = int(gt) - res_cnt = min(len(prediction), topn) - for i in range(res_cnt): - if str(real_label) == str(int(prediction[i])): - count_hit[i] += 1 - break - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - - for i in range(res_cnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - print(table_dict) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Please enter right number of argmuments, expected 4!") - exit(1) - # class number - n_labels = 1000 - if not os.path.exists(folder_davinci_target): - print("target file folder does not exist.") - - if not os.path.exists(annotation_file_path): - print("Ground truth file does not exist.") - - if not os.path.exists(result_json_path): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, n_labels, topn=5) - - elapsed = time.time() - start +#coding = utf-8 +#Copyright 2020 Huawei Technologies Co., Ltd +# +#Licensed under the Apache License, Version 2.0 (the "License"); +#you may not use this file except in compliance with the License. +#You may obtain a copy of the License at +# +#http://www.apache.org/licenses/LICENSE-2.0 +# +#Unless required by applicable law or agreed to in writing, software +#distributed under the License is distributed on an "AS IS" BASIS, +#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#See the License for the specific language governing permissions and +#limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + """ + :param img_name:image file name contains file path + :return:image file name without file path + """ + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param gtfile_path: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param gtfile_path: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + img_name = temp[0].split(".")[0] + img_lab = temp[1] + img_gt_dict[img_name] = img_lab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + :param filepath: the result of model predict + :return probabilities, number of label, in_type, color: + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, cls_ind in enumerate(temp): + if cls_ind: + data_vec[ind] = np.int(cls_ind) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, n_labels, topn=5): + """ + :param prediction_file_path: the result of model predict + :param result_store_path: the root path to store result + :param json_file: json file to save result + :param img_gt_dict: the ground truth of imagenet + :param topn: classify model acc topk + :return:NA + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + res_cnt = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + gt = img_gt_dict[img_name] + real_label = int(gt) + res_cnt = min(len(prediction), topn) + for i in range(res_cnt): + if str(real_label) == str(int(prediction[i])): + count_hit[i] += 1 + break + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + + for i in range(res_cnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + print(table_dict) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Please enter right number of argmuments, expected 4!") + exit(1) + # class number + n_labels = 1000 + if not os.path.exists(folder_davinci_target): + print("target file folder does not exist.") + + if not os.path.exists(annotation_file_path): + print("Ground truth file does not exist.") + + if not os.path.exists(result_json_path): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, n_labels, topn=5) + + elapsed = time.time() - start diff --git a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/main.cpp b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/main.cpp index 137e934b965f6a3647451b7d5afbc19200370a04..1235200904ab113ba1f79a0cbc3bd0c78c373cc0 100644 --- a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/main.cpp +++ b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/mxbase/main.cpp @@ -1,69 +1,69 @@ -/* - * Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include "Resnet50Classify.h" -#include "MxBase/Log/Log.h" - -namespace fs = std::experimental::filesystem; -namespace { -const uint32_t CLASS_NUM = 1000; -} -std::vector g_inferCost; - -int main(int argc, char* argv[]) -{ - if (argc <= 1) { - LogWarn << "Please input image path, such as './val_union/'."; - return APP_ERR_OK; - } - - InitParam initParam = {}; - initParam.deviceId = 0; - initParam.classNum = CLASS_NUM; - initParam.labelPath = "../models/imagenet1000_clsidx_to_labels.names"; - initParam.topk = 5; - initParam.softmax = true; - initParam.checkTensor = true; - initParam.modelPath = "../models/resnet50_pytorch.om"; - auto resnet50 = std::make_shared(); - APP_ERROR ret = resnet50->Init(initParam); - if (ret != APP_ERR_OK) { - LogError << "Resnet50Classify init failed, ret=" << ret << "."; - return ret; - } - - std::string imgDir = argv[1]; - for (auto & entry : fs::directory_iterator(imgDir)) { - LogInfo << "read image path " << entry.path(); - ret = resnet50->Process(entry.path()); - if (ret != APP_ERR_OK) { - LogError << "Resnet50Classify process failed, ret=" << ret << "."; - resnet50->DeInit(); - return ret; - } - } - resnet50->DeInit(); - double costSum = 0; - for (unsigned int i = 0; i < g_inferCost.size(); i++) { - costSum += g_inferCost[i]; - } - LogInfo << "Infer images sum " << g_inferCost.size() << ", cost total time: " << costSum << " ms."; - LogInfo << "The throughput: " << g_inferCost.size() * 1000 / costSum << " images/sec."; - return APP_ERR_OK; +/* + * Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "Resnet50Classify.h" +#include "MxBase/Log/Log.h" + +namespace fs = std::experimental::filesystem; +namespace { +const uint32_t CLASS_NUM = 1000; +} +std::vector g_inferCost; + +int main(int argc, char* argv[]) +{ + if (argc <= 1) { + LogWarn << "Please input image path, such as './val_union/'."; + return APP_ERR_OK; + } + + InitParam initParam = {}; + initParam.deviceId = 0; + initParam.classNum = CLASS_NUM; + initParam.labelPath = "../models/imagenet1000_clsidx_to_labels.names"; + initParam.topk = 5; + initParam.softmax = true; + initParam.checkTensor = true; + initParam.modelPath = "../models/resnet50_pytorch.om"; + auto resnet50 = std::make_shared(); + APP_ERROR ret = resnet50->Init(initParam); + if (ret != APP_ERR_OK) { + LogError << "Resnet50Classify init failed, ret=" << ret << "."; + return ret; + } + + std::string imgDir = argv[1]; + for (auto & entry : fs::directory_iterator(imgDir)) { + LogInfo << "read image path " << entry.path(); + ret = resnet50->Process(entry.path()); + if (ret != APP_ERR_OK) { + LogError << "Resnet50Classify process failed, ret=" << ret << "."; + resnet50->DeInit(); + return ret; + } + } + resnet50->DeInit(); + double costSum = 0; + for (unsigned int i = 0; i < g_inferCost.size(); i++) { + costSum += g_inferCost[i]; + } + LogInfo << "Infer images sum " << g_inferCost.size() << ", cost total time: " << costSum << " ms."; + LogInfo << "The throughput: " << g_inferCost.size() * 1000 / costSum << " images/sec."; + return APP_ERR_OK; } \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/sdk/classification_task_metric.py b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/sdk/classification_task_metric.py index 2d383ae6cf0fbdc06b9f7baec87255f436dc9e42..dc6d0328e0bd18a04e2cf30616199c94747cd72f 100644 --- a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/sdk/classification_task_metric.py +++ b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/infer/sdk/classification_task_metric.py @@ -1,175 +1,175 @@ -#coding = utf-8 -#Copyright 2020 Huawei Technologies Co., Ltd -# -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -#http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - """ - :param: file path - :return: filename - """ - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - img_name = temp[0].split(".")[0] - img_lab = temp[1] - img_gt_dict[img_name] = img_lab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - :param filepath: the result of model predict - :return probabilities, number of label, in_type, color: - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, cls_ind in enumerate(temp): - if cls_ind: - data_vec[ind] = np.int(cls_ind) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, n_labels, topn=5): - """ - :param prediction_file_path: the result of model predict - :param result_store_path: the root path to store result - :param json_file: json file to save result - :param img_gt_dict: the ground truth of imagenet - :param topn: classify model acc topk - :param n_labels: class numbers - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - res_cnt = 0 - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - - ret = load_statistical_predict_result(filepath) - prediction = ret[0] - gt = img_gt_dict[img_name] - real_label = int(gt) - res_cnt = min(len(prediction), topn) - for i in range(res_cnt): - if str(real_label) == str(int(prediction[i])): - count_hit[i] += 1 - break - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - - for i in range(res_cnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - print(table_dict) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Please enter right number of argmuments, expected 4!") - exit(1) - # class number - n_labels = 1000 - if not os.path.exists(folder_davinci_target): - print("target file folder does not exist.") - - if not os.path.exists(annotation_file_path): - print("Ground truth file does not exist.") - - if not os.path.exists(result_json_path): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, n_labels, topn=5) - - elapsed = time.time() - start +#coding = utf-8 +#Copyright 2020 Huawei Technologies Co., Ltd +# +#Licensed under the Apache License, Version 2.0 (the "License"); +#you may not use this file except in compliance with the License. +#You may obtain a copy of the License at +# +#http://www.apache.org/licenses/LICENSE-2.0 +# +#Unless required by applicable law or agreed to in writing, software +#distributed under the License is distributed on an "AS IS" BASIS, +#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#See the License for the specific language governing permissions and +#limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + """ + :param: file path + :return: filename + """ + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + img_name = temp[0].split(".")[0] + img_lab = temp[1] + img_gt_dict[img_name] = img_lab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + :param filepath: the result of model predict + :return probabilities, number of label, in_type, color: + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, cls_ind in enumerate(temp): + if cls_ind: + data_vec[ind] = np.int(cls_ind) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, n_labels, topn=5): + """ + :param prediction_file_path: the result of model predict + :param result_store_path: the root path to store result + :param json_file: json file to save result + :param img_gt_dict: the ground truth of imagenet + :param topn: classify model acc topk + :param n_labels: class numbers + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + res_cnt = 0 + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + + ret = load_statistical_predict_result(filepath) + prediction = ret[0] + gt = img_gt_dict[img_name] + real_label = int(gt) + res_cnt = min(len(prediction), topn) + for i in range(res_cnt): + if str(real_label) == str(int(prediction[i])): + count_hit[i] += 1 + break + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + + for i in range(res_cnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + print(table_dict) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Please enter right number of argmuments, expected 4!") + exit(1) + # class number + n_labels = 1000 + if not os.path.exists(folder_davinci_target): + print("target file folder does not exist.") + + if not os.path.exists(annotation_file_path): + print("Ground truth file does not exist.") + + if not os.path.exists(result_json_path): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, n_labels, topn=5) + + elapsed = time.time() - start diff --git a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/modelarts/train_start.py b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/modelarts/train_start.py index 89e41a2e40fea9ea68fef94fb6f8a38b7f86cf67..af51db50ad89d57c3d6fe840c0b10f0c3616d89d 100644 --- a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/modelarts/train_start.py +++ b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/modelarts/train_start.py @@ -1,688 +1,688 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import os -import glob -import random -import shutil -import sys -import time -import warnings -import math -import numpy as np - -import torch -import torch.nn as nn -import torch.nn.parallel -import torch.backends.cudnn as cudnn -import torch.distributed as dist -import torch.optim -import torch.multiprocessing as mp -import torch.utils.data -import torch.utils.data.distributed -import torchvision.transforms as transforms -import torchvision.datasets as datasets -import torchvision.models as models -import torch.npu - -sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../')) -from pthtar2onx import convert -import DistributedResnet50.image_classification.resnet as nvmodels -from apex import amp -import moxing as mox - -BATCH_SIZE = 512 -EPOCHS_SIZE = 100 -TRAIN_STEP = 8000 -LOG_STEP = 1 - -CALCULATE_DEVICE = "npu:7" -PRINT_DEVICE = "cpu" -SOURCE_DIR = "/data/imagenet" - -model_names = sorted(name for name in models.__dict__ - if name.islower() and not name.startswith("__") - and callable(models.__dict__[name])) - -parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') -parser.add_argument('--data_url', - metavar='DIR', - default='/cache/data_url', - help='path to dataset') -parser.add_argument('-a', '--arch', - metavar='ARCH', - default='resnet50', - choices=model_names, - help='model architecture: ' + - ' | '.join(model_names) + - ' (default: resnet18)') -parser.add_argument('-j', '--workers', - default=32, - type=int, - metavar='N', - help='number of data loading workers (default: 8)') -parser.add_argument('--epochs', - default=1, - type=int, - metavar='N', - help='number of total epochs to run') -parser.add_argument('--start-epoch', - default=0, - type=int, - metavar='N', - help='manual epoch number (useful on restarts)') -parser.add_argument('-b', '--batch-size', - default=BATCH_SIZE, - type=int, - metavar='N', - help='mini-batch size (default: 256), this is the total ' - 'batch size of all GPUs on the current node when ' - 'using Data Parallel or Distributed Data Parallel') -parser.add_argument('--lr', '--learning-rate', - default=0.2, - type=float, - metavar='LR', - help='initial learning rate', - dest='lr') -parser.add_argument('--momentum', - default=0.9, - type=float, - metavar='M', - help='momentum') -parser.add_argument('--wd', '--weight-decay', - default=1e-4, - type=float, - metavar='W', - help='weight decay (default: 1e-4)', - dest='weight_decay') -parser.add_argument('-p', '--print-freq', - default=10, - type=int, - metavar='N', - help='print frequency (default: 10)') -parser.add_argument('--resume', - default='', - type=str, - metavar='PATH', - help='path to latest checkpoint (default: none)') -parser.add_argument('-e', '--evaluate', - dest='evaluate', - action='store_true', - help='evaluate model on validation set') -parser.add_argument('--pretrained', - dest='pretrained', - action='store_true', - help='use pre-trained model') -parser.add_argument('--world-size', - default=-1, - type=int, - help='number of nodes for distributed training') -parser.add_argument('--rank', - default=-1, - type=int, - help='node rank for distributed training') -parser.add_argument('--dist-url', - default=None, - type=str, - help='url used to set up distributed training') -parser.add_argument('--dist-backend', - default='nccl', - type=str, - help='distributed backend') -parser.add_argument('--seed', - default=None, - type=int, - help='seed for initializing training. ') -parser.add_argument('--gpu', - default=None, - type=int, - help='GPU id to use.') -parser.add_argument('--npu', - default=None, - type=int, - help='NPU id to use.') -parser.add_argument('--multiprocessing-distributed', - action='store_true') -parser.add_argument('--warmup', - default=5, - type=int, - metavar='E', - help='number of warmup epochs') -parser.add_argument('--label-smoothing', - default=0.1, - type=float, - metavar='S', - help='label smoothing') -parser.add_argument('--optimizer-batch-size', - default=-1, - type=int, - metavar='N', - help= - 'size of a total batch size, for simulating bigger batches using gradient accumulation') -parser.add_argument('--static-loss-scale', - type=float, - default=1, - help= - 'Static loss scale, positive power of 2 values can improve fp16 convergence.') - -parser.add_argument('-t', '--fine-tuning', default=False, action='store_true', - help='transfer learning + fine tuning - train only the last FC layer') -parser.add_argument('--train_url', - default="/cache/training", - type=str, - help="setting dir of training output") -parser.add_argument('--pretrained_weight', default='', type=str, metavar='PATH', - help='path to pretrained weight') -parser.add_argument('--onnx', default=True, action='store_true', - help="convert pth model to onnx") - -CACHE_TRAINING_URL = "/cache/training" -best_acc1 = 0 - -def main(): - args = parser.parse_args() - if args.npu is None: - args.npu = 0 - global CALCULATE_DEVICE - CALCULATE_DEVICE = "npu:{}".format(args.npu) - torch.npu.set_device(CALCULATE_DEVICE) - print("use ", CALCULATE_DEVICE) - - if args.seed is not None: - random.seed(args.seed) - torch.manual_seed(args.seed) - cudnn.deterministic = True - warnings.warn('You have chosen to seed training. ' - 'This will turn on the CUDNN deterministic setting, ' - 'which can slow down your training considerably! ' - 'You may see unexpected behavior when restarting ' - 'from checkpoints.') - - if args.gpu is not None: - warnings.warn('You have chosen a specific GPU. This will completely ' - 'disable data parallelism.') - - if args.dist_url == "env://" and args.world_size == -1: - args.world_size = int(os.environ["WORLD_SIZE"]) - - args.distributed = args.world_size > 1 or args.multiprocessing_distributed - - ngpus_per_node = torch.cuda.device_count() - if args.multiprocessing_distributed: - # Since we have ngpus_per_node processes per node, the total world_size - # needs to be adjusted accordingly - args.world_size = ngpus_per_node * args.world_size - # Use torch.multiprocessing.spawn to launch distributed processes: the - # main_worker process function - mp.spawn(main_worker, nprocs=ngpus_per_node, args=(ngpus_per_node, args)) - else: - # Simply call main_worker function - main_worker(args.gpu, ngpus_per_node, args) - -def main_worker(gpu, ngpus_per_node, args): - global best_acc1 - args.gpu = gpu - - if args.gpu is not None: - print("Use GPU: {} for training".format(args.gpu)) - - if args.distributed: - if args.dist_url == "env://" and args.rank == -1: - args.rank = int(os.environ["RANK"]) - if args.multiprocessing_distributed: - # For multiprocessing distributed training, rank needs to be the - # global rank among all the processes - args.rank = args.rank * ngpus_per_node + gpu - dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - # create model - if args.pretrained: - print("=> using pre-trained model '{}'".format(args.arch)) - model = nvmodels.build_resnet('resnet50', 'classic', True) - CACHE_MODEL_URL = "/cache/model" - os.makedirs(CACHE_MODEL_URL, exist_ok=True) - mox.file.copy_parallel(args.pretrained_weight, os.path.join(CACHE_MODEL_URL, "checkpoint.pth.tar")) - pretrained_weight = os.path.join(CACHE_MODEL_URL, "checkpoint.pth.tar") - pretrained_dict = torch.load(pretrained_weight)["state_dict"] - pretrained_dict.pop('module.fc.weight') - pretrained_dict.pop('module.fc.bias') - model.load_state_dict(pretrained_dict, strict=False) - else: - print("=> creating model '{}'".format(args.arch)) - model = models.__dict__[args.arch](zero_init_residual=True) - - if args.fine_tuning: - print("=> transfer-learning mode + fine-tuning (train only the last FC layer)") - # Freeze Previous Layers(now we are using them as features extractor) - # Fine Tuning the last layer for the new task - if args.arch == "resnet50": - model.classifier = nn.Linear(1024, 10) - model.classifier.parameters() - else: - print("Error: Fine-tuning is not supported on this architecture") - exit(-1) - else: - model.parameters() - - for layer in model.modules(): - if isinstance(layer, nn.Linear): - torch.nn.init.kaiming_normal_(layer.weight, a=math.sqrt(5), ) - if args.distributed: - # For multiprocessing distributed, DistributedDataParallel constructor - # should always set the single device scope, otherwise, - # DistributedDataParallel will use all available devices. - if args.gpu is not None: - torch.cuda.set_device(args.gpu) - model.cuda(args.gpu) - # When using a single GPU per process and per - # DistributedDataParallel, we need to divide the batch size - # ourselves based on the total number of GPUs we have - args.batch_size = int(args.batch_size / ngpus_per_node) - args.workers = int((args.workers + ngpus_per_node - 1) / ngpus_per_node) - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu]) - else: - model.cuda() - # DistributedDataParallel will divide and allocate batch_size to all - # available GPUs if device_ids are not set - model = torch.nn.parallel.DistributedDataParallel(model) - elif args.gpu is not None: - torch.cuda.set_device(args.gpu) - model = model.cuda(args.gpu) - else: - # DataParallel will divide and allocate batch_size to all available GPUs - if args.arch.startswith('alexnet') or args.arch.startswith('vgg'): - model.features = torch.nn.DataParallel(model.features) - model.cuda() - else: - model = model.to(CALCULATE_DEVICE) - - lr_policy = lr_cosine_policy(args.lr, - args.warmup, - args.epochs) - - - # define loss function (criterion) and optimizer - loss = nn.CrossEntropyLoss - if args.label_smoothing > 0.0: - loss = lambda: LabelSmoothing(args.label_smoothing) - criterion = loss().to(CALCULATE_DEVICE) - optimizer = torch.optim.SGD([ - {'params': [param for name, param in model.named_parameters() if name[-4:] == 'bias'], 'weight_decay': 0.0}, - {'params': [param for name, param in model.named_parameters() if name[-4:] != 'bias'], 'weight_decay': args.weight_decay}], - args.lr, - momentum=args.momentum) - - model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=1024, verbosity=1) - - # optionally resume from a checkpoint - if args.resume: - if os.path.isfile(args.resume): - print("=> loading checkpoint '{}'".format(args.resume)) - if args.npu is not None: - checkpoint = torch.load(args.resume) - elif args.gpu is None: - checkpoint = torch.load(args.resume) - else: - # Map model to be loaded to specified single gpu. - loc = 'cuda:{}'.format(args.gpu) - checkpoint = torch.load(args.resume, map_location=loc) - args.start_epoch = checkpoint['epoch'] - best_acc1 = checkpoint['best_acc1'] - if args.npu is not None: - best_acc1 = best_acc1.to("npu:{}".format(args.npu)) - elif args.gpu is not None: - # best_acc1 may be from a checkpoint from a different GPU - best_acc1 = best_acc1.to(args.gpu) - model.load_state_dict(checkpoint['state_dict']) - print("=> loaded checkpoint '{}' (epoch {})" - .format(args.resume, checkpoint['epoch'])) - else: - print("=> no checkpoint found at '{}'".format(args.resume)) - - cudnn.benchmark = True - - real_path = '/cache/data_url' - if not os.path.exists(real_path): - os.makedirs(real_path) - mox.file.copy_parallel(args.data_url, real_path) - print("training data finish copy to %s." % real_path) - - traindir = os.path.join(real_path, 'train') - valdir = os.path.join(real_path, 'val') - normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], - std=[0.229, 0.224, 0.225]) - - train_dataset = datasets.ImageFolder( - traindir, - transforms.Compose([ - transforms.RandomResizedCrop(224), - transforms.RandomHorizontalFlip(), - transforms.ToTensor(), - normalize, - ])) - - if args.distributed: - train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) - else: - train_sampler = None - - train_loader = torch.utils.data.DataLoader( - train_dataset, batch_size=args.batch_size, shuffle=(train_sampler is None), - num_workers=args.workers, pin_memory=True, sampler=train_sampler, drop_last=True) - - val_loader = torch.utils.data.DataLoader( - datasets.ImageFolder(valdir, transforms.Compose([ - transforms.Resize(256), - transforms.CenterCrop(224), - transforms.ToTensor(), - normalize, - ])), - batch_size=args.batch_size, shuffle=True, - num_workers=args.workers, pin_memory=True) - - if args.evaluate: - validate(val_loader, model, criterion, args) - return - - for epoch in range(args.start_epoch, args.epochs): - if args.distributed: - train_sampler.set_epoch(epoch) - lr_policy(optimizer, 0, epoch) - # train for one epoch - train(train_loader, model, criterion, optimizer, epoch, args) - - # evaluate on validation set - acc1 = validate(val_loader, model, criterion, args) - - # remember best acc@1 and save checkpoint - is_best = acc1 > best_acc1 - best_acc1 = max(acc1, best_acc1) - file_name = "checkpoint_npu{}".format(args.npu) - modeltmp = model.cpu() - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': args.arch, - 'state_dict': modeltmp.state_dict(), - 'best_acc1': best_acc1, - }, is_best, file_name) - modeltmp.to(CALCULATE_DEVICE) - - if args.onnx: - convert_pth_to_onnx(args) - - # --------------modelarts modification---------- - mox.file.copy_parallel(CACHE_TRAINING_URL, args.train_url) - # --------------modelarts modification end---------- - -def convert_pth_to_onnx(args): - pth_pattern = os.path.join(CACHE_TRAINING_URL, f"checkpoint_npu{args.npu}.pth.tar") - pth_file_list = glob.glob(pth_pattern) - if not pth_file_list: - print(f"can't find pth {pth_pattern}") - return - pth_file = pth_file_list[0] - onnx_path = pth_file.split(".")[0] + '.onnx' - convert(pth_file, onnx_path) - - -def train(train_loader, model, criterion, optimizer, epoch, args): - if args.optimizer_batch_size < 0: - batch_size_multiplier = 1 - else: - tbs = 1 * args.batch_size - if args.optimizer_batch_size % tbs != 0: - print( - "Warning: simulated batch size {} is not divisible by actual batch size {}" - .format(args.optimizer_batch_size, tbs)) - batch_size_multiplier = int(args.optimizer_batch_size / tbs) - print("BSM: {}".format(batch_size_multiplier)) - - batch_time = AverageMeter('Time', ':6.3f') - data_time = AverageMeter('Data', ':6.3f') - losses = AverageMeter('Loss', ':.4e') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - progress = ProgressMeter( - len(train_loader), - [batch_time, data_time, losses, top1, top5], - prefix="Epoch: [{}]".format(epoch)) - - # switch to train mode - model.train() - optimizer.zero_grad() - end = time.time() - for i, (images, target) in enumerate(train_loader): - # measure data loading time - data_time.update(time.time() - end) - - if args.gpu is not None: - images = images.cuda(args.gpu, non_blocking=True) - - images = images.to(CALCULATE_DEVICE, non_blocking=True) - if args.label_smoothing == 0.0: - target = target.to(torch.int32).to(CALCULATE_DEVICE, non_blocking=True) - - # compute output - output = model(images) - loss = criterion(output, target) - - if args.label_smoothing > 0.0: - target = target.to(torch.int32).to(CALCULATE_DEVICE, non_blocking=True) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # compute gradient and do SGD step - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - optimizer_step = ((i + 1) % batch_size_multiplier) == 0 - if optimizer_step: - if batch_size_multiplier != 1: - for param_group in optimizer.param_groups: - for param in param_group['params']: - param.grad /= batch_size_multiplier - optimizer.step() - optimizer.zero_grad() - - # measure elapsed time - batch_time.update(time.time() - end) - end = time.time() - - if i % LOG_STEP == 0: - progress.display(i) - - if i == TRAIN_STEP: - break - - print("batch_size:", args.batch_size, 'Time: {:.3f}'.format(batch_time.avg), '* FPS@all {:.3f}'.format( - args.batch_size/(batch_time.avg+0.0001))) - -def validate(val_loader, model, criterion, args): - batch_time = AverageMeter('Time', ':6.3f') - losses = AverageMeter('Loss', ':.4e') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - progress = ProgressMeter( - len(val_loader), - [batch_time, losses, top1, top5], - prefix='Test: ') - - # switch to evaluate mode - model.eval() - - with torch.no_grad(): - end = time.time() - for i, (images, target) in enumerate(val_loader): - if args.gpu is not None: - images = images.cuda(args.gpu, non_blocking=True) - images = images.to(CALCULATE_DEVICE, non_blocking=True) - if args.label_smoothing == 0.0: - target = target.to(torch.int32).to(CALCULATE_DEVICE, non_blocking=True) - - # compute output - output = model(images) - loss = criterion(output, target) - - if args.label_smoothing > 0.0: - target = target.to(torch.int32).to(CALCULATE_DEVICE, non_blocking=True) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # measure elapsed time - batch_time.update(time.time() - end) - end = time.time() - - if i % LOG_STEP == 0: - progress.display(i) - - print(' * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}' - .format(top1=top1, top5=top5)) - return top1.avg - -def save_checkpoint(state, is_best, filename='checkpoint'): - if not os.path.exists(CACHE_TRAINING_URL): - os.makedirs(CACHE_TRAINING_URL) - - filename2 = os.path.join(CACHE_TRAINING_URL, filename + ".pth.tar") - torch.save(state, filename2) - if is_best: - shutil.copyfile(filename2, os.path.join(CACHE_TRAINING_URL, filename + 'model_best.pth.tar')) - -class AverageMeter(object): - """Computes and stores the average and current value""" - def __init__(self, name, fmt=':f'): - self.name = name - self.fmt = fmt - self.reset() - self.start_count_index = 10 - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - - def update(self, val, n=1): - if self.count == 0: - self.batchsize = n - - self.val = val - self.count += n - if self.count > (self.start_count_index * self.batchsize): - self.sum += val * n - self.avg = self.sum / (self.count - self.start_count_index * self.batchsize) - - def __str__(self): - fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' - return fmtstr.format(**self.__dict__) - -class ProgressMeter(object): - def __init__(self, num_batches, meters, prefix=""): - self.batch_fmtstr = self._get_batch_fmtstr(num_batches) - self.meters = meters - self.prefix = prefix - - def display(self, batch): - entries = [self.prefix + self.batch_fmtstr.format(batch)] - entries += [str(meter) for meter in self.meters] - print('\t'.join(entries)) - - def _get_batch_fmtstr(self, num_batches): - num_digits = len(str(num_batches // 1)) - fmt = '{:' + str(num_digits) + 'd}' - return '[' + fmt + '/' + fmt.format(num_batches) + ']' - - -def adjust_learning_rate(optimizer, epoch, args): - """Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" - lr = args.lr * (0.1 ** (epoch // 30)) - for param_group in optimizer.param_groups: - param_group['lr'] = lr - - -def accuracy(output, target, topk=(1,)): - """Computes the accuracy over the k top predictions for the specified values of k""" - with torch.no_grad(): - maxk = max(topk) - batch_size = target.size(0) - - _, pred = output.topk(maxk, 1, True, True) - pred = pred.t() - correct = pred.eq(target.view(1, -1).expand_as(pred)) - - res = [] - for k in topk: - correct_k = correct[:k].view(-1).float().sum(0, keepdim=True) - res.append(correct_k.mul_(100.0 / batch_size)) - return res - -class LabelSmoothing(nn.Module): - """ - NLL loss with label smoothing. - """ - def __init__(self, smoothing=0.0): - """ - Constructor for the LabelSmoothing module. - :param smoothing: label smoothing factor - """ - super(LabelSmoothing, self).__init__() - self.confidence = 1.0 - smoothing - self.smoothing = smoothing - - def forward(self, x, target): - logprobs = torch.nn.functional.log_softmax(x, dim=-1).to("cpu") - nll_loss = -logprobs.gather(dim=-1, index=target.unsqueeze(1)) - nll_loss = nll_loss.squeeze(1) - smooth_loss = -logprobs.mean(dim=-1) - loss = self.confidence * nll_loss + self.smoothing * smooth_loss - return loss.mean().to(CALCULATE_DEVICE) - -def lr_policy(lr_fn, logger=None): - if logger is not None: - logger.register_metric('lr', - log.LR_METER(), - verbosity=dllogger.Verbosity.VERBOSE) - - def _alr(optimizer, iteration, epoch): - lr = lr_fn(iteration, epoch) - - if logger is not None: - logger.log_metric('lr', lr) - for param_group in optimizer.param_groups: - param_group['lr'] = lr - - return _alr - -def lr_cosine_policy(base_lr, warmup_length, epochs, logger=None): - def _lr_fn(iteration, epoch): - if epoch < warmup_length: - lr = base_lr * (epoch + 1) / warmup_length - else: - e = epoch - warmup_length - es = epochs - warmup_length - lr = 0.5 * (1 + np.cos(np.pi * e / es)) * base_lr - return lr - - return lr_policy(_lr_fn, logger=logger) - -if __name__ == '__main__': - main() +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import os +import glob +import random +import shutil +import sys +import time +import warnings +import math +import numpy as np + +import torch +import torch.nn as nn +import torch.nn.parallel +import torch.backends.cudnn as cudnn +import torch.distributed as dist +import torch.optim +import torch.multiprocessing as mp +import torch.utils.data +import torch.utils.data.distributed +import torchvision.transforms as transforms +import torchvision.datasets as datasets +import torchvision.models as models +import torch.npu + +sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../')) +from pthtar2onx import convert +import DistributedResnet50.image_classification.resnet as nvmodels +from apex import amp +import moxing as mox + +BATCH_SIZE = 512 +EPOCHS_SIZE = 100 +TRAIN_STEP = 8000 +LOG_STEP = 1 + +CALCULATE_DEVICE = "npu:7" +PRINT_DEVICE = "cpu" +SOURCE_DIR = "/data/imagenet" + +model_names = sorted(name for name in models.__dict__ + if name.islower() and not name.startswith("__") + and callable(models.__dict__[name])) + +parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') +parser.add_argument('--data_url', + metavar='DIR', + default='/cache/data_url', + help='path to dataset') +parser.add_argument('-a', '--arch', + metavar='ARCH', + default='resnet50', + choices=model_names, + help='model architecture: ' + + ' | '.join(model_names) + + ' (default: resnet18)') +parser.add_argument('-j', '--workers', + default=32, + type=int, + metavar='N', + help='number of data loading workers (default: 8)') +parser.add_argument('--epochs', + default=1, + type=int, + metavar='N', + help='number of total epochs to run') +parser.add_argument('--start-epoch', + default=0, + type=int, + metavar='N', + help='manual epoch number (useful on restarts)') +parser.add_argument('-b', '--batch-size', + default=BATCH_SIZE, + type=int, + metavar='N', + help='mini-batch size (default: 256), this is the total ' + 'batch size of all GPUs on the current node when ' + 'using Data Parallel or Distributed Data Parallel') +parser.add_argument('--lr', '--learning-rate', + default=0.2, + type=float, + metavar='LR', + help='initial learning rate', + dest='lr') +parser.add_argument('--momentum', + default=0.9, + type=float, + metavar='M', + help='momentum') +parser.add_argument('--wd', '--weight-decay', + default=1e-4, + type=float, + metavar='W', + help='weight decay (default: 1e-4)', + dest='weight_decay') +parser.add_argument('-p', '--print-freq', + default=10, + type=int, + metavar='N', + help='print frequency (default: 10)') +parser.add_argument('--resume', + default='', + type=str, + metavar='PATH', + help='path to latest checkpoint (default: none)') +parser.add_argument('-e', '--evaluate', + dest='evaluate', + action='store_true', + help='evaluate model on validation set') +parser.add_argument('--pretrained', + dest='pretrained', + action='store_true', + help='use pre-trained model') +parser.add_argument('--world-size', + default=-1, + type=int, + help='number of nodes for distributed training') +parser.add_argument('--rank', + default=-1, + type=int, + help='node rank for distributed training') +parser.add_argument('--dist-url', + default=None, + type=str, + help='url used to set up distributed training') +parser.add_argument('--dist-backend', + default='nccl', + type=str, + help='distributed backend') +parser.add_argument('--seed', + default=None, + type=int, + help='seed for initializing training. ') +parser.add_argument('--gpu', + default=None, + type=int, + help='GPU id to use.') +parser.add_argument('--npu', + default=None, + type=int, + help='NPU id to use.') +parser.add_argument('--multiprocessing-distributed', + action='store_true') +parser.add_argument('--warmup', + default=5, + type=int, + metavar='E', + help='number of warmup epochs') +parser.add_argument('--label-smoothing', + default=0.1, + type=float, + metavar='S', + help='label smoothing') +parser.add_argument('--optimizer-batch-size', + default=-1, + type=int, + metavar='N', + help= + 'size of a total batch size, for simulating bigger batches using gradient accumulation') +parser.add_argument('--static-loss-scale', + type=float, + default=1, + help= + 'Static loss scale, positive power of 2 values can improve fp16 convergence.') + +parser.add_argument('-t', '--fine-tuning', default=False, action='store_true', + help='transfer learning + fine tuning - train only the last FC layer') +parser.add_argument('--train_url', + default="/cache/training", + type=str, + help="setting dir of training output") +parser.add_argument('--pretrained_weight', default='', type=str, metavar='PATH', + help='path to pretrained weight') +parser.add_argument('--onnx', default=True, action='store_true', + help="convert pth model to onnx") + +CACHE_TRAINING_URL = "/cache/training" +best_acc1 = 0 + +def main(): + args = parser.parse_args() + if args.npu is None: + args.npu = 0 + global CALCULATE_DEVICE + CALCULATE_DEVICE = "npu:{}".format(args.npu) + torch.npu.set_device(CALCULATE_DEVICE) + print("use ", CALCULATE_DEVICE) + + if args.seed is not None: + random.seed(args.seed) + torch.manual_seed(args.seed) + cudnn.deterministic = True + warnings.warn('You have chosen to seed training. ' + 'This will turn on the CUDNN deterministic setting, ' + 'which can slow down your training considerably! ' + 'You may see unexpected behavior when restarting ' + 'from checkpoints.') + + if args.gpu is not None: + warnings.warn('You have chosen a specific GPU. This will completely ' + 'disable data parallelism.') + + if args.dist_url == "env://" and args.world_size == -1: + args.world_size = int(os.environ["WORLD_SIZE"]) + + args.distributed = args.world_size > 1 or args.multiprocessing_distributed + + ngpus_per_node = torch.cuda.device_count() + if args.multiprocessing_distributed: + # Since we have ngpus_per_node processes per node, the total world_size + # needs to be adjusted accordingly + args.world_size = ngpus_per_node * args.world_size + # Use torch.multiprocessing.spawn to launch distributed processes: the + # main_worker process function + mp.spawn(main_worker, nprocs=ngpus_per_node, args=(ngpus_per_node, args)) + else: + # Simply call main_worker function + main_worker(args.gpu, ngpus_per_node, args) + +def main_worker(gpu, ngpus_per_node, args): + global best_acc1 + args.gpu = gpu + + if args.gpu is not None: + print("Use GPU: {} for training".format(args.gpu)) + + if args.distributed: + if args.dist_url == "env://" and args.rank == -1: + args.rank = int(os.environ["RANK"]) + if args.multiprocessing_distributed: + # For multiprocessing distributed training, rank needs to be the + # global rank among all the processes + args.rank = args.rank * ngpus_per_node + gpu + dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + # create model + if args.pretrained: + print("=> using pre-trained model '{}'".format(args.arch)) + model = nvmodels.build_resnet('resnet50', 'classic', True) + CACHE_MODEL_URL = "/cache/model" + os.makedirs(CACHE_MODEL_URL, exist_ok=True) + mox.file.copy_parallel(args.pretrained_weight, os.path.join(CACHE_MODEL_URL, "checkpoint.pth.tar")) + pretrained_weight = os.path.join(CACHE_MODEL_URL, "checkpoint.pth.tar") + pretrained_dict = torch.load(pretrained_weight)["state_dict"] + pretrained_dict.pop('module.fc.weight') + pretrained_dict.pop('module.fc.bias') + model.load_state_dict(pretrained_dict, strict=False) + else: + print("=> creating model '{}'".format(args.arch)) + model = models.__dict__[args.arch](zero_init_residual=True) + + if args.fine_tuning: + print("=> transfer-learning mode + fine-tuning (train only the last FC layer)") + # Freeze Previous Layers(now we are using them as features extractor) + # Fine Tuning the last layer for the new task + if args.arch == "resnet50": + model.classifier = nn.Linear(1024, 10) + model.classifier.parameters() + else: + print("Error: Fine-tuning is not supported on this architecture") + exit(-1) + else: + model.parameters() + + for layer in model.modules(): + if isinstance(layer, nn.Linear): + torch.nn.init.kaiming_normal_(layer.weight, a=math.sqrt(5), ) + if args.distributed: + # For multiprocessing distributed, DistributedDataParallel constructor + # should always set the single device scope, otherwise, + # DistributedDataParallel will use all available devices. + if args.gpu is not None: + torch.cuda.set_device(args.gpu) + model.cuda(args.gpu) + # When using a single GPU per process and per + # DistributedDataParallel, we need to divide the batch size + # ourselves based on the total number of GPUs we have + args.batch_size = int(args.batch_size / ngpus_per_node) + args.workers = int((args.workers + ngpus_per_node - 1) / ngpus_per_node) + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu]) + else: + model.cuda() + # DistributedDataParallel will divide and allocate batch_size to all + # available GPUs if device_ids are not set + model = torch.nn.parallel.DistributedDataParallel(model) + elif args.gpu is not None: + torch.cuda.set_device(args.gpu) + model = model.cuda(args.gpu) + else: + # DataParallel will divide and allocate batch_size to all available GPUs + if args.arch.startswith('alexnet') or args.arch.startswith('vgg'): + model.features = torch.nn.DataParallel(model.features) + model.cuda() + else: + model = model.to(CALCULATE_DEVICE) + + lr_policy = lr_cosine_policy(args.lr, + args.warmup, + args.epochs) + + + # define loss function (criterion) and optimizer + loss = nn.CrossEntropyLoss + if args.label_smoothing > 0.0: + loss = lambda: LabelSmoothing(args.label_smoothing) + criterion = loss().to(CALCULATE_DEVICE) + optimizer = torch.optim.SGD([ + {'params': [param for name, param in model.named_parameters() if name[-4:] == 'bias'], 'weight_decay': 0.0}, + {'params': [param for name, param in model.named_parameters() if name[-4:] != 'bias'], 'weight_decay': args.weight_decay}], + args.lr, + momentum=args.momentum) + + model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=1024, verbosity=1) + + # optionally resume from a checkpoint + if args.resume: + if os.path.isfile(args.resume): + print("=> loading checkpoint '{}'".format(args.resume)) + if args.npu is not None: + checkpoint = torch.load(args.resume) + elif args.gpu is None: + checkpoint = torch.load(args.resume) + else: + # Map model to be loaded to specified single gpu. + loc = 'cuda:{}'.format(args.gpu) + checkpoint = torch.load(args.resume, map_location=loc) + args.start_epoch = checkpoint['epoch'] + best_acc1 = checkpoint['best_acc1'] + if args.npu is not None: + best_acc1 = best_acc1.to("npu:{}".format(args.npu)) + elif args.gpu is not None: + # best_acc1 may be from a checkpoint from a different GPU + best_acc1 = best_acc1.to(args.gpu) + model.load_state_dict(checkpoint['state_dict']) + print("=> loaded checkpoint '{}' (epoch {})" + .format(args.resume, checkpoint['epoch'])) + else: + print("=> no checkpoint found at '{}'".format(args.resume)) + + cudnn.benchmark = True + + real_path = '/cache/data_url' + if not os.path.exists(real_path): + os.makedirs(real_path) + mox.file.copy_parallel(args.data_url, real_path) + print("training data finish copy to %s." % real_path) + + traindir = os.path.join(real_path, 'train') + valdir = os.path.join(real_path, 'val') + normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]) + + train_dataset = datasets.ImageFolder( + traindir, + transforms.Compose([ + transforms.RandomResizedCrop(224), + transforms.RandomHorizontalFlip(), + transforms.ToTensor(), + normalize, + ])) + + if args.distributed: + train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) + else: + train_sampler = None + + train_loader = torch.utils.data.DataLoader( + train_dataset, batch_size=args.batch_size, shuffle=(train_sampler is None), + num_workers=args.workers, pin_memory=True, sampler=train_sampler, drop_last=True) + + val_loader = torch.utils.data.DataLoader( + datasets.ImageFolder(valdir, transforms.Compose([ + transforms.Resize(256), + transforms.CenterCrop(224), + transforms.ToTensor(), + normalize, + ])), + batch_size=args.batch_size, shuffle=True, + num_workers=args.workers, pin_memory=True) + + if args.evaluate: + validate(val_loader, model, criterion, args) + return + + for epoch in range(args.start_epoch, args.epochs): + if args.distributed: + train_sampler.set_epoch(epoch) + lr_policy(optimizer, 0, epoch) + # train for one epoch + train(train_loader, model, criterion, optimizer, epoch, args) + + # evaluate on validation set + acc1 = validate(val_loader, model, criterion, args) + + # remember best acc@1 and save checkpoint + is_best = acc1 > best_acc1 + best_acc1 = max(acc1, best_acc1) + file_name = "checkpoint_npu{}".format(args.npu) + modeltmp = model.cpu() + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': args.arch, + 'state_dict': modeltmp.state_dict(), + 'best_acc1': best_acc1, + }, is_best, file_name) + modeltmp.to(CALCULATE_DEVICE) + + if args.onnx: + convert_pth_to_onnx(args) + + # --------------modelarts modification---------- + mox.file.copy_parallel(CACHE_TRAINING_URL, args.train_url) + # --------------modelarts modification end---------- + +def convert_pth_to_onnx(args): + pth_pattern = os.path.join(CACHE_TRAINING_URL, f"checkpoint_npu{args.npu}.pth.tar") + pth_file_list = glob.glob(pth_pattern) + if not pth_file_list: + print(f"can't find pth {pth_pattern}") + return + pth_file = pth_file_list[0] + onnx_path = pth_file.split(".")[0] + '.onnx' + convert(pth_file, onnx_path) + + +def train(train_loader, model, criterion, optimizer, epoch, args): + if args.optimizer_batch_size < 0: + batch_size_multiplier = 1 + else: + tbs = 1 * args.batch_size + if args.optimizer_batch_size % tbs != 0: + print( + "Warning: simulated batch size {} is not divisible by actual batch size {}" + .format(args.optimizer_batch_size, tbs)) + batch_size_multiplier = int(args.optimizer_batch_size / tbs) + print("BSM: {}".format(batch_size_multiplier)) + + batch_time = AverageMeter('Time', ':6.3f') + data_time = AverageMeter('Data', ':6.3f') + losses = AverageMeter('Loss', ':.4e') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + progress = ProgressMeter( + len(train_loader), + [batch_time, data_time, losses, top1, top5], + prefix="Epoch: [{}]".format(epoch)) + + # switch to train mode + model.train() + optimizer.zero_grad() + end = time.time() + for i, (images, target) in enumerate(train_loader): + # measure data loading time + data_time.update(time.time() - end) + + if args.gpu is not None: + images = images.cuda(args.gpu, non_blocking=True) + + images = images.to(CALCULATE_DEVICE, non_blocking=True) + if args.label_smoothing == 0.0: + target = target.to(torch.int32).to(CALCULATE_DEVICE, non_blocking=True) + + # compute output + output = model(images) + loss = criterion(output, target) + + if args.label_smoothing > 0.0: + target = target.to(torch.int32).to(CALCULATE_DEVICE, non_blocking=True) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # compute gradient and do SGD step + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + optimizer_step = ((i + 1) % batch_size_multiplier) == 0 + if optimizer_step: + if batch_size_multiplier != 1: + for param_group in optimizer.param_groups: + for param in param_group['params']: + param.grad /= batch_size_multiplier + optimizer.step() + optimizer.zero_grad() + + # measure elapsed time + batch_time.update(time.time() - end) + end = time.time() + + if i % LOG_STEP == 0: + progress.display(i) + + if i == TRAIN_STEP: + break + + print("batch_size:", args.batch_size, 'Time: {:.3f}'.format(batch_time.avg), '* FPS@all {:.3f}'.format( + args.batch_size/(batch_time.avg+0.0001))) + +def validate(val_loader, model, criterion, args): + batch_time = AverageMeter('Time', ':6.3f') + losses = AverageMeter('Loss', ':.4e') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + progress = ProgressMeter( + len(val_loader), + [batch_time, losses, top1, top5], + prefix='Test: ') + + # switch to evaluate mode + model.eval() + + with torch.no_grad(): + end = time.time() + for i, (images, target) in enumerate(val_loader): + if args.gpu is not None: + images = images.cuda(args.gpu, non_blocking=True) + images = images.to(CALCULATE_DEVICE, non_blocking=True) + if args.label_smoothing == 0.0: + target = target.to(torch.int32).to(CALCULATE_DEVICE, non_blocking=True) + + # compute output + output = model(images) + loss = criterion(output, target) + + if args.label_smoothing > 0.0: + target = target.to(torch.int32).to(CALCULATE_DEVICE, non_blocking=True) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # measure elapsed time + batch_time.update(time.time() - end) + end = time.time() + + if i % LOG_STEP == 0: + progress.display(i) + + print(' * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}' + .format(top1=top1, top5=top5)) + return top1.avg + +def save_checkpoint(state, is_best, filename='checkpoint'): + if not os.path.exists(CACHE_TRAINING_URL): + os.makedirs(CACHE_TRAINING_URL) + + filename2 = os.path.join(CACHE_TRAINING_URL, filename + ".pth.tar") + torch.save(state, filename2) + if is_best: + shutil.copyfile(filename2, os.path.join(CACHE_TRAINING_URL, filename + 'model_best.pth.tar')) + +class AverageMeter(object): + """Computes and stores the average and current value""" + def __init__(self, name, fmt=':f'): + self.name = name + self.fmt = fmt + self.reset() + self.start_count_index = 10 + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + if self.count == 0: + self.batchsize = n + + self.val = val + self.count += n + if self.count > (self.start_count_index * self.batchsize): + self.sum += val * n + self.avg = self.sum / (self.count - self.start_count_index * self.batchsize) + + def __str__(self): + fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' + return fmtstr.format(**self.__dict__) + +class ProgressMeter(object): + def __init__(self, num_batches, meters, prefix=""): + self.batch_fmtstr = self._get_batch_fmtstr(num_batches) + self.meters = meters + self.prefix = prefix + + def display(self, batch): + entries = [self.prefix + self.batch_fmtstr.format(batch)] + entries += [str(meter) for meter in self.meters] + print('\t'.join(entries)) + + def _get_batch_fmtstr(self, num_batches): + num_digits = len(str(num_batches // 1)) + fmt = '{:' + str(num_digits) + 'd}' + return '[' + fmt + '/' + fmt.format(num_batches) + ']' + + +def adjust_learning_rate(optimizer, epoch, args): + """Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" + lr = args.lr * (0.1 ** (epoch // 30)) + for param_group in optimizer.param_groups: + param_group['lr'] = lr + + +def accuracy(output, target, topk=(1,)): + """Computes the accuracy over the k top predictions for the specified values of k""" + with torch.no_grad(): + maxk = max(topk) + batch_size = target.size(0) + + _, pred = output.topk(maxk, 1, True, True) + pred = pred.t() + correct = pred.eq(target.view(1, -1).expand_as(pred)) + + res = [] + for k in topk: + correct_k = correct[:k].view(-1).float().sum(0, keepdim=True) + res.append(correct_k.mul_(100.0 / batch_size)) + return res + +class LabelSmoothing(nn.Module): + """ + NLL loss with label smoothing. + """ + def __init__(self, smoothing=0.0): + """ + Constructor for the LabelSmoothing module. + :param smoothing: label smoothing factor + """ + super(LabelSmoothing, self).__init__() + self.confidence = 1.0 - smoothing + self.smoothing = smoothing + + def forward(self, x, target): + logprobs = torch.nn.functional.log_softmax(x, dim=-1).to("cpu") + nll_loss = -logprobs.gather(dim=-1, index=target.unsqueeze(1)) + nll_loss = nll_loss.squeeze(1) + smooth_loss = -logprobs.mean(dim=-1) + loss = self.confidence * nll_loss + self.smoothing * smooth_loss + return loss.mean().to(CALCULATE_DEVICE) + +def lr_policy(lr_fn, logger=None): + if logger is not None: + logger.register_metric('lr', + log.LR_METER(), + verbosity=dllogger.Verbosity.VERBOSE) + + def _alr(optimizer, iteration, epoch): + lr = lr_fn(iteration, epoch) + + if logger is not None: + logger.log_metric('lr', lr) + for param_group in optimizer.param_groups: + param_group['lr'] = lr + + return _alr + +def lr_cosine_policy(base_lr, warmup_length, epochs, logger=None): + def _lr_fn(iteration, epoch): + if epoch < warmup_length: + lr = base_lr * (epoch + 1) / warmup_length + else: + e = epoch - warmup_length + es = epochs - warmup_length + lr = 0.5 * (1 + np.cos(np.pi * e / es)) * base_lr + return lr + + return lr_policy(_lr_fn, logger=logger) + +if __name__ == '__main__': + main() diff --git a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/test/train_full_16p.sh b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/test/train_full_16p.sh index e355a2471f863f1efefaa4d44655a9c703bef532..fc18830eb3a8f2b14789a39e879a881fa03fce8f 100644 --- a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/test/train_full_16p.sh +++ b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/test/train_full_16p.sh @@ -1,171 +1,171 @@ -#!/bin/bash - -################基础配置参数,需要模型审视修改################## -# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE -# 网络名称,同目录名称 -Network="ResNet50_for_PyTorch" -# 训练batch_size -batch_size=4096 -# 训练使用的npu卡数 -export RANK_SIZE=16 -export RANK_ID_START=0 -# 数据集路径,保持为空,不需要修改 -data_path="" -conf_path="" -server_index="" -fix_node_ip="" - -# 训练epoch 90 -train_epochs=90 -# 加载数据进程数 -workers=128 - -# 参数校验,data_path为必传参数,其他参数的增删由模型自身决定;此处新增参数需在上面有定义并赋值 -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --conf_path* ]];then - conf_path=`echo ${para#*=}` - elif [[ $para == --server_index* ]];then - server_index=`echo ${para#*=}` - elif [[ $para == --fix_node_ip* ]];then - fix_node_ip=`echo ${para#*=}` - fi -done - -# 校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -one_node_ip=`find $conf_path -name "server_*0.info"|awk -F "server_" '{print $2}'|awk -F "_" '{print $1}'` -linux_num=`find $conf_path -name "server_*.info" |wc -l` - -export HCCL_IF_IP=$fix_node_ip -export MASTER_ADDR=$one_node_ip - -###############指定训练脚本执行路径############### -# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - - -#################创建日志输出目录,不需要修改################# - -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - export ASCEND_DEVICE_ID=$RANK_ID - echo "Device ID: $ASCEND_DEVICE_ID" - - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt - fi - - echo run process ${RANK_ID} - - #SOLVER.MAX_ITER 82000 \ - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 -done - -#################启动训练脚本################# -# 训练开始时间,不需要修改 -start_time=$(date +%s) -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi - -export NODE_RANK=${server_index} -export NPU_WORLD_SIZE=`awk 'BEGIN{printf "%.0f\n",8*'${linux_num}'}'` - -nohup python3.7 ./DistributedResnet50/main_apex_d76_npu.py \ - --data ${data_path} \ - --addr=$one_node_ip \ - --seed=49 \ - --workers=${workers} \ - --learning-rate=1.6 \ - --warmup=8 \ - --label-smoothing=0.1 \ - --mom=0.9 \ - --weight-decay=1.0e-04 \ - --static-loss-scale=128 \ - --print-freq=1 \ - --dist-url='tcp://127.0.0.1:50000' \ - --dist-backend='hccl' \ - --multiprocessing-distributed \ - --world-size=2 \ - --rank=0 \ - --benchmark=0 \ - --device='npu' \ - --epochs=${train_epochs} \ - --batch-size=${batch_size} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & - -wait - - -##################获取训练数据################ -# 训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -# 训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -# 结果打印,不需要修改 -echo "------------------ Final result ------------------" -# 输出性能FPS,需要模型审视修改 -grep "FPS@all" ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk '{print $11}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_fps.log -FPS=`cat ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${CaseName}_fps.log | awk '{a+=$1} END {if (NR != 0) printf("%.3f",a*2/NR)}'` -# 打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -# 输出训练精度,需要模型审视修改 -train_accuracy=`grep -a '* Acc@1' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` -# 打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -# 性能看护结果汇总 -# 获取性能数据,不需要修改 -# 吞吐量 -ActualFPS=${FPS} -# 单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -# 从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch: ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v Test|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -# 最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -# 关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +################基础配置参数,需要模型审视修改################## +# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE +# 网络名称,同目录名称 +Network="ResNet50_for_PyTorch" +# 训练batch_size +batch_size=4096 +# 训练使用的npu卡数 +export RANK_SIZE=16 +export RANK_ID_START=0 +# 数据集路径,保持为空,不需要修改 +data_path="" +conf_path="" +server_index="" +fix_node_ip="" + +# 训练epoch 90 +train_epochs=90 +# 加载数据进程数 +workers=128 + +# 参数校验,data_path为必传参数,其他参数的增删由模型自身决定;此处新增参数需在上面有定义并赋值 +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --conf_path* ]];then + conf_path=`echo ${para#*=}` + elif [[ $para == --server_index* ]];then + server_index=`echo ${para#*=}` + elif [[ $para == --fix_node_ip* ]];then + fix_node_ip=`echo ${para#*=}` + fi +done + +# 校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +one_node_ip=`find $conf_path -name "server_*0.info"|awk -F "server_" '{print $2}'|awk -F "_" '{print $1}'` +linux_num=`find $conf_path -name "server_*.info" |wc -l` + +export HCCL_IF_IP=$fix_node_ip +export MASTER_ADDR=$one_node_ip + +###############指定训练脚本执行路径############### +# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + + +#################创建日志输出目录,不需要修改################# + +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + export ASCEND_DEVICE_ID=$RANK_ID + echo "Device ID: $ASCEND_DEVICE_ID" + + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt + fi + + echo run process ${RANK_ID} + + #SOLVER.MAX_ITER 82000 \ + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 +done + +#################启动训练脚本################# +# 训练开始时间,不需要修改 +start_time=$(date +%s) +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +export NODE_RANK=${server_index} +export NPU_WORLD_SIZE=`awk 'BEGIN{printf "%.0f\n",8*'${linux_num}'}'` + +nohup python3.7 ./DistributedResnet50/main_apex_d76_npu.py \ + --data ${data_path} \ + --addr=$one_node_ip \ + --seed=49 \ + --workers=${workers} \ + --learning-rate=1.6 \ + --warmup=8 \ + --label-smoothing=0.1 \ + --mom=0.9 \ + --weight-decay=1.0e-04 \ + --static-loss-scale=128 \ + --print-freq=1 \ + --dist-url='tcp://127.0.0.1:50000' \ + --dist-backend='hccl' \ + --multiprocessing-distributed \ + --world-size=2 \ + --rank=0 \ + --benchmark=0 \ + --device='npu' \ + --epochs=${train_epochs} \ + --batch-size=${batch_size} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + +wait + + +##################获取训练数据################ +# 训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +# 训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +# 结果打印,不需要修改 +echo "------------------ Final result ------------------" +# 输出性能FPS,需要模型审视修改 +grep "FPS@all" ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk '{print $11}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_fps.log +FPS=`cat ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${CaseName}_fps.log | awk '{a+=$1} END {if (NR != 0) printf("%.3f",a*2/NR)}'` +# 打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +# 输出训练精度,需要模型审视修改 +train_accuracy=`grep -a '* Acc@1' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` +# 打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +# 性能看护结果汇总 +# 获取性能数据,不需要修改 +# 吞吐量 +ActualFPS=${FPS} +# 单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +# 从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch: ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v Test|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +# 最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +# 关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/test/train_performance_16p.sh b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/test/train_performance_16p.sh index d047e2847ebbd21127963122a1130fcd0d430ff9..6fef6a353e164956f495d8e850a6a2ce3db6c222 100644 --- a/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/test/train_performance_16p.sh +++ b/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch/test/train_performance_16p.sh @@ -1,156 +1,156 @@ -#!/bin/bash - -################基础配置参数,需要模型审视修改################## -# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE -# 网络名称,同目录名称 -Network="ResNet50_ID0095_for_PyTorch" -# 训练batch_size -batch_size=4096 -# 训练使用的npu卡数 -export RANK_SIZE=16 -# 数据集路径,保持为空,不需要修改 -data_path="" -conf_path="" -server_index="" -fix_node_ip="" - -# 训练epoch 90 -train_epochs=3 -# 加载数据进程数 -workers=128 - -# 参数校验,data_path为必传参数,其他参数的增删由模型自身决定;此处新增参数需在上面有定义并赋值 -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --conf_path* ]];then - conf_path=`echo ${para#*=}` - elif [[ $para == --server_index* ]];then - server_index=`echo ${para#*=}` - elif [[ $para == --fix_node_ip* ]];then - fix_node_ip=`echo ${para#*=}` - fi -done - -# 校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -one_node_ip=`find $conf_path -name "server_*0.info"|awk -F "server_" '{print $2}'|awk -F "_" '{print $1}'` -linux_num=`find $conf_path -name "server_*.info" |wc -l` - -export HCCL_IF_IP=$fix_node_ip -export MASTER_ADDR=$one_node_ip - -###############指定训练脚本执行路径############### -# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - - -#################创建日志输出目录,不需要修改################# -ASCEND_DEVICE_ID=0 -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -fi - - -#################启动训练脚本################# -# 训练开始时间,不需要修改 -start_time=$(date +%s) -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi - -export NODE_RANK=${server_index} -export NPU_WORLD_SIZE=`awk 'BEGIN{printf "%.0f\n",8*'${linux_num}'}'` - -nohup python3.7 ./DistributedResnet50/main_apex_d76_npu.py \ - --data ${data_path} \ - --addr=$one_node_ip \ - --seed=49 \ - --workers=${workers} \ - --learning-rate=1.6 \ - --warmup=8 \ - --label-smoothing=0.1 \ - --mom=0.9 \ - --weight-decay=1.0e-04 \ - --static-loss-scale=128 \ - --print-freq=1 \ - --dist-url='tcp://127.0.0.1:50000' \ - --dist-backend='hccl' \ - --multiprocessing-distributed \ - --world-size=2 \ - --rank=0 \ - --benchmark=0 \ - --device='npu' \ - --epochs=${train_epochs} \ - --batch-size=${batch_size} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & - -wait - - -##################获取训练数据################ -# 训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -# 训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -# 结果打印,不需要修改 -echo "------------------ Final result ------------------" -# 输出性能FPS,需要模型审视修改 -grep "FPS@all" ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk '{print $11}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_fps.log -FPS=`cat ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${CaseName}_fps.log | awk '{a+=$1} END {if (NR != 0) printf("%.3f",a*2/NR)}'` -# 打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -# 输出训练精度,需要模型审视修改 -train_accuracy=`grep -a '* Acc@1' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` -# 打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -# 性能看护结果汇总 -# 获取性能数据,不需要修改 -# 吞吐量 -ActualFPS=${FPS} -# 单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -# 从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch: ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v Test|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -# 最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -# 关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +################基础配置参数,需要模型审视修改################## +# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE +# 网络名称,同目录名称 +Network="ResNet50_ID0095_for_PyTorch" +# 训练batch_size +batch_size=4096 +# 训练使用的npu卡数 +export RANK_SIZE=16 +# 数据集路径,保持为空,不需要修改 +data_path="" +conf_path="" +server_index="" +fix_node_ip="" + +# 训练epoch 90 +train_epochs=3 +# 加载数据进程数 +workers=128 + +# 参数校验,data_path为必传参数,其他参数的增删由模型自身决定;此处新增参数需在上面有定义并赋值 +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --conf_path* ]];then + conf_path=`echo ${para#*=}` + elif [[ $para == --server_index* ]];then + server_index=`echo ${para#*=}` + elif [[ $para == --fix_node_ip* ]];then + fix_node_ip=`echo ${para#*=}` + fi +done + +# 校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +one_node_ip=`find $conf_path -name "server_*0.info"|awk -F "server_" '{print $2}'|awk -F "_" '{print $1}'` +linux_num=`find $conf_path -name "server_*.info" |wc -l` + +export HCCL_IF_IP=$fix_node_ip +export MASTER_ADDR=$one_node_ip + +###############指定训练脚本执行路径############### +# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + + +#################创建日志输出目录,不需要修改################# +ASCEND_DEVICE_ID=0 +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +fi + + +#################启动训练脚本################# +# 训练开始时间,不需要修改 +start_time=$(date +%s) +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +export NODE_RANK=${server_index} +export NPU_WORLD_SIZE=`awk 'BEGIN{printf "%.0f\n",8*'${linux_num}'}'` + +nohup python3.7 ./DistributedResnet50/main_apex_d76_npu.py \ + --data ${data_path} \ + --addr=$one_node_ip \ + --seed=49 \ + --workers=${workers} \ + --learning-rate=1.6 \ + --warmup=8 \ + --label-smoothing=0.1 \ + --mom=0.9 \ + --weight-decay=1.0e-04 \ + --static-loss-scale=128 \ + --print-freq=1 \ + --dist-url='tcp://127.0.0.1:50000' \ + --dist-backend='hccl' \ + --multiprocessing-distributed \ + --world-size=2 \ + --rank=0 \ + --benchmark=0 \ + --device='npu' \ + --epochs=${train_epochs} \ + --batch-size=${batch_size} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + +wait + + +##################获取训练数据################ +# 训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +# 训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +# 结果打印,不需要修改 +echo "------------------ Final result ------------------" +# 输出性能FPS,需要模型审视修改 +grep "FPS@all" ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk '{print $11}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_fps.log +FPS=`cat ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${CaseName}_fps.log | awk '{a+=$1} END {if (NR != 0) printf("%.3f",a*2/NR)}'` +# 打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +# 输出训练精度,需要模型审视修改 +train_accuracy=`grep -a '* Acc@1' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` +# 打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +# 性能看护结果汇总 +# 获取性能数据,不需要修改 +# 吞吐量 +ActualFPS=${FPS} +# 单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +# 从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch: ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v Test|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +# 最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +# 关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/classification/Shufflenetv2_for_PyTorch/test/train_performance_1p.sh b/PyTorch/built-in/cv/classification/Shufflenetv2_for_PyTorch/test/train_performance_1p.sh index 295d88c2de904d13e90ec5c5e27a572888877356..971514cdeb4b6a365752b3d9efac92e763bc94c6 100644 --- a/PyTorch/built-in/cv/classification/Shufflenetv2_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/built-in/cv/classification/Shufflenetv2_for_PyTorch/test/train_performance_1p.sh @@ -1,178 +1,178 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` - -#集合通信参数,不需要修改 -#保证rank table file 文件rank_table_8p.json存放在和test同级的configs目录下 -export RANK_SIZE=1 - -#RANK_TABLE_FILE=${cur_path}/../configs/rank_table_8p.json -RANK_ID_START=0 - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -export ASCEND_GLOBAL_LOG_LEVEL=3 - -#基础参数 需要模型审视修改 -#网络名称,同目录名称 -Network="Shufflenetv2_ID0099_for_PyTorch" -#训练epoch -train_epochs=2 -#训练batch_size -batch_size=1536 - -#TF2.X独有,不需要修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_8p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is 0 - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --autotune whether to enable autotune, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --autotune* ]];then - autotune=`echo ${para#*=}` - export autotune=$autotune - mv $install_path/fwkacllib/data/rl/Ascend910/custom $install_path/fwkacllib/data/rl/Ascend910/custom_bak - mv $install_path/fwkacllib/data/tiling/Ascend910/custom $install_path/fwkacllib/data/tiling/Ascend910/custom_bak - autotune_dump_path=${cur_path}/output/autotune_dump - mkdir -p ${autotune_dump_path}/GA - mkdir -p ${autotune_dump_path}/rl - cp -rf $install_path/fwkacllib/data/tiling/Ascend910/custom ${autotune_dump_path}/GA/ - cp -rf $install_path/fwkacllib/data/rl/Ascend910/custom ${autotune_dump_path}/RL/ - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path/../ -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - export DEVICE_ID=$RANK_ID - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - mkdir -p ${cur_path}/output/overflow_dump - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - mkdir -p ${cur_path}/output/overflow_dump - fi - over_dump_path=${cur_path}/output/overflow_dump - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - - python3 8p_main_med.py \ - --data=$data_path \ - --addr=$(hostname -I |awk '{print $1}') \ - --seed=49 \ - --workers=128 \ - --learning-rate=0.75 \ - --print-freq=10 \ - --eval-freq=5 \ - --arch=shufflenet_v2_x1_0 \ - --dist-url='tcp://127.0.0.1:50000' \ - --dist-backend='hccl' \ - --multiprocessing-distributed \ - --world-size=1 \ - --batch-size=1536 \ - --epochs=2 \ - --warm_up_epochs=1 \ - --rank=0 \ - --amp \ - --momentum=0 \ - --wd=3.0517578125e-05 \ - --device-list=0 \ - --benchmark 0 \ - > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & - -done -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) -echo "E2E Training Duration sec : $e2e_time" - -#cp -r ${cur_path}/train.log ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log - -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据 -FPS=`grep "FPS@all" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk 'END {print $7}'|tr -d ,| sed s/[[:space:]]//g` -ActualFPS=${FPS} - -temp1=`echo "1 * ${batch_size}"|bc` -TrainingTime=`echo "scale=2;${temp1} / ${ActualFPS}"|bc` - -ActualLoss=`grep "Loss" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk 'END {print $12}'` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` + +#集合通信参数,不需要修改 +#保证rank table file 文件rank_table_8p.json存放在和test同级的configs目录下 +export RANK_SIZE=1 + +#RANK_TABLE_FILE=${cur_path}/../configs/rank_table_8p.json +RANK_ID_START=0 + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +export ASCEND_GLOBAL_LOG_LEVEL=3 + +#基础参数 需要模型审视修改 +#网络名称,同目录名称 +Network="Shufflenetv2_ID0099_for_PyTorch" +#训练epoch +train_epochs=2 +#训练batch_size +batch_size=1536 + +#TF2.X独有,不需要修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_8p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is 0 + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --autotune whether to enable autotune, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --autotune* ]];then + autotune=`echo ${para#*=}` + export autotune=$autotune + mv $install_path/fwkacllib/data/rl/Ascend910/custom $install_path/fwkacllib/data/rl/Ascend910/custom_bak + mv $install_path/fwkacllib/data/tiling/Ascend910/custom $install_path/fwkacllib/data/tiling/Ascend910/custom_bak + autotune_dump_path=${cur_path}/output/autotune_dump + mkdir -p ${autotune_dump_path}/GA + mkdir -p ${autotune_dump_path}/rl + cp -rf $install_path/fwkacllib/data/tiling/Ascend910/custom ${autotune_dump_path}/GA/ + cp -rf $install_path/fwkacllib/data/rl/Ascend910/custom ${autotune_dump_path}/RL/ + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path/../ +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + export DEVICE_ID=$RANK_ID + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + mkdir -p ${cur_path}/output/overflow_dump + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + mkdir -p ${cur_path}/output/overflow_dump + fi + over_dump_path=${cur_path}/output/overflow_dump + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + + python3 8p_main_med.py \ + --data=$data_path \ + --addr=$(hostname -I |awk '{print $1}') \ + --seed=49 \ + --workers=128 \ + --learning-rate=0.75 \ + --print-freq=10 \ + --eval-freq=5 \ + --arch=shufflenet_v2_x1_0 \ + --dist-url='tcp://127.0.0.1:50000' \ + --dist-backend='hccl' \ + --multiprocessing-distributed \ + --world-size=1 \ + --batch-size=1536 \ + --epochs=2 \ + --warm_up_epochs=1 \ + --rank=0 \ + --amp \ + --momentum=0 \ + --wd=3.0517578125e-05 \ + --device-list=0 \ + --benchmark 0 \ + > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + +done +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) +echo "E2E Training Duration sec : $e2e_time" + +#cp -r ${cur_path}/train.log ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log + +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据 +FPS=`grep "FPS@all" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk 'END {print $7}'|tr -d ,| sed s/[[:space:]]//g` +ActualFPS=${FPS} + +temp1=`echo "1 * ${batch_size}"|bc` +TrainingTime=`echo "scale=2;${temp1} / ${ActualFPS}"|bc` + +ActualLoss=`grep "Loss" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk 'END {print $12}'` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/classification/Shufflenetv2_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/cv/classification/Shufflenetv2_for_PyTorch/test/train_performance_8p.sh index de67f1ede4b3c5ff2bcc9b2c4b8460b06976070d..39e8b6cd752b34aa6a67211bce45537704747884 100644 --- a/PyTorch/built-in/cv/classification/Shufflenetv2_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/cv/classification/Shufflenetv2_for_PyTorch/test/train_performance_8p.sh @@ -1,175 +1,175 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` - -#集合通信参数,不需要修改 -#保证rank table file 文件rank_table_8p.json存放在和test同级的configs目录下 -export RANK_SIZE=8 -batch_size=1024 -#RANK_TABLE_FILE=${cur_path}/../configs/rank_table_8p.json -RANK_ID_START=0 - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -export ASCEND_GLOBAL_LOG_LEVEL=3 - -#基础参数 需要模型审视修改 -#网络名称,同目录名称 -Network="Shufflenetv2_ID0099_for_PyTorch" -#训练epoch -train_epochs=2 -#device_id_list=0,1,2,3,4,5,6,7 -#TF2.X独有,不需要修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_8p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is 0 - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --autotune whether to enable autotune, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --autotune* ]];then - autotune=`echo ${para#*=}` - export autotune=$autotune - mv $install_path/fwkacllib/data/rl/Ascend910/custom $install_path/fwkacllib/data/rl/Ascend910/custom_bak - mv $install_path/fwkacllib/data/tiling/Ascend910/custom $install_path/fwkacllib/data/tiling/Ascend910/custom_bak - autotune_dump_path=${cur_path}/output/autotune_dump - mkdir -p ${autotune_dump_path}/GA - mkdir -p ${autotune_dump_path}/rl - cp -rf $install_path/fwkacllib/data/tiling/Ascend910/custom ${autotune_dump_path}/GA/ - cp -rf $install_path/fwkacllib/data/rl/Ascend910/custom ${autotune_dump_path}/RL/ - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录 -export SIll=1 -cd $cur_path/../ -for((RANK_ID=$RANK_ID_START;RANK_ID<$((SIll+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - export RANK_ID=$RANK_ID - export DEVICE_ID=$RANK_ID - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - mkdir -p ${cur_path}/output/overflow_dump - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - mkdir -p ${cur_path}/output/overflow_dump - fi - over_dump_path=${cur_path}/output/overflow_dump - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - - python3 8p_main_med.py \ - --data=$data_path \ - --addr=$(hostname -I |awk '{print $1}') \ - --seed=49 \ - --workers=128 \ - --learning-rate=0.75 \ - --print-freq=10 \ - --eval-freq=5 \ - --arch=shufflenet_v2_x1_0 \ - --dist-url='tcp://127.0.0.1:50000' \ - --dist-backend='hccl' \ - --multiprocessing-distributed \ - --world-size=1 \ - --batch-size=1024 \ - --epochs=2 \ - --warm_up_epochs=1 \ - --rank=0 \ - --amp \ - --momentum=0 \ - --wd=3.0517578125e-05 \ - --device-list=0 \ - --benchmark 0 \ - > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & - -done -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) -echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}${name_bind}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据 - -FPS=`grep "FPS@all" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk 'END {print $7}'|tr -d ,` -ActualFPS=`echo "8 * ${FPS}"|bc` -temp1=`echo "8 * ${batch_size}"|bc` -TrainingTime=`echo "scale=2;${temp1} / ${ActualFPS}"|bc` - -ActualLoss=`grep "Loss" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk 'END {print $12}'` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` + +#集合通信参数,不需要修改 +#保证rank table file 文件rank_table_8p.json存放在和test同级的configs目录下 +export RANK_SIZE=8 +batch_size=1024 +#RANK_TABLE_FILE=${cur_path}/../configs/rank_table_8p.json +RANK_ID_START=0 + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +export ASCEND_GLOBAL_LOG_LEVEL=3 + +#基础参数 需要模型审视修改 +#网络名称,同目录名称 +Network="Shufflenetv2_ID0099_for_PyTorch" +#训练epoch +train_epochs=2 +#device_id_list=0,1,2,3,4,5,6,7 +#TF2.X独有,不需要修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_8p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is 0 + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --autotune whether to enable autotune, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --autotune* ]];then + autotune=`echo ${para#*=}` + export autotune=$autotune + mv $install_path/fwkacllib/data/rl/Ascend910/custom $install_path/fwkacllib/data/rl/Ascend910/custom_bak + mv $install_path/fwkacllib/data/tiling/Ascend910/custom $install_path/fwkacllib/data/tiling/Ascend910/custom_bak + autotune_dump_path=${cur_path}/output/autotune_dump + mkdir -p ${autotune_dump_path}/GA + mkdir -p ${autotune_dump_path}/rl + cp -rf $install_path/fwkacllib/data/tiling/Ascend910/custom ${autotune_dump_path}/GA/ + cp -rf $install_path/fwkacllib/data/rl/Ascend910/custom ${autotune_dump_path}/RL/ + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录 +export SIll=1 +cd $cur_path/../ +for((RANK_ID=$RANK_ID_START;RANK_ID<$((SIll+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + export RANK_ID=$RANK_ID + export DEVICE_ID=$RANK_ID + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + mkdir -p ${cur_path}/output/overflow_dump + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + mkdir -p ${cur_path}/output/overflow_dump + fi + over_dump_path=${cur_path}/output/overflow_dump + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + + python3 8p_main_med.py \ + --data=$data_path \ + --addr=$(hostname -I |awk '{print $1}') \ + --seed=49 \ + --workers=128 \ + --learning-rate=0.75 \ + --print-freq=10 \ + --eval-freq=5 \ + --arch=shufflenet_v2_x1_0 \ + --dist-url='tcp://127.0.0.1:50000' \ + --dist-backend='hccl' \ + --multiprocessing-distributed \ + --world-size=1 \ + --batch-size=1024 \ + --epochs=2 \ + --warm_up_epochs=1 \ + --rank=0 \ + --amp \ + --momentum=0 \ + --wd=3.0517578125e-05 \ + --device-list=0 \ + --benchmark 0 \ + > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + +done +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) +echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}${name_bind}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据 + +FPS=`grep "FPS@all" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk 'END {print $7}'|tr -d ,` +ActualFPS=`echo "8 * ${FPS}"|bc` +temp1=`echo "8 * ${batch_size}"|bc` +TrainingTime=`echo "scale=2;${temp1} / ${ActualFPS}"|bc` + +ActualLoss=`grep "Loss" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk 'END {print $12}'` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/LICENSE b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/LICENSE old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Base-RCNN-C4.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Base-RCNN-C4.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Base-RCNN-DilatedC5.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Base-RCNN-DilatedC5.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Base-RCNN-FPN.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Base-RCNN-FPN.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Base-RetinaNet.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Base-RetinaNet.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/fast_rcnn_R_50_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/fast_rcnn_R_50_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_101_C4_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_101_C4_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_101_DC5_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_101_DC5_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_101_FPN_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_101_FPN_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_50_C4_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_50_C4_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_50_C4_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_50_C4_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_50_DC5_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_50_DC5_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_50_DC5_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_50_DC5_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_50_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_50_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_X_101_32x8d_FPN_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/faster_rcnn_X_101_32x8d_FPN_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/retinanet_R_101_FPN_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/retinanet_R_101_FPN_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/retinanet_R_50_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/retinanet_R_50_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/retinanet_R_50_FPN_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/retinanet_R_50_FPN_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/rpn_R_50_C4_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/rpn_R_50_C4_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/rpn_R_50_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Detection/rpn_R_50_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_101_C4_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_101_C4_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_101_DC5_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_101_DC5_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_C4_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_C4_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_C4_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_C4_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_DC5_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_DC5_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_DC5_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_DC5_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x_giou.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x_giou.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Keypoints/Base-Keypoint-RCNN-FPN.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Keypoints/Base-Keypoint-RCNN-FPN.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Keypoints/keypoint_rcnn_R_101_FPN_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Keypoints/keypoint_rcnn_R_101_FPN_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Keypoints/keypoint_rcnn_R_50_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Keypoints/keypoint_rcnn_R_50_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Keypoints/keypoint_rcnn_R_50_FPN_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Keypoints/keypoint_rcnn_R_50_FPN_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Keypoints/keypoint_rcnn_X_101_32x8d_FPN_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-Keypoints/keypoint_rcnn_X_101_32x8d_FPN_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-PanopticSegmentation/Base-Panoptic-FPN.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-PanopticSegmentation/Base-Panoptic-FPN.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-PanopticSegmentation/panoptic_fpn_R_101_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-PanopticSegmentation/panoptic_fpn_R_101_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-PanopticSegmentation/panoptic_fpn_R_50_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-PanopticSegmentation/panoptic_fpn_R_50_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-PanopticSegmentation/panoptic_fpn_R_50_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/COCO-PanopticSegmentation/panoptic_fpn_R_50_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Cityscapes/mask_rcnn_R_50_FPN.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Cityscapes/mask_rcnn_R_50_FPN.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Detectron1-Comparisons/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Detectron1-Comparisons/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Detectron1-Comparisons/faster_rcnn_R_50_FPN_noaug_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Detectron1-Comparisons/faster_rcnn_R_50_FPN_noaug_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Detectron1-Comparisons/keypoint_rcnn_R_50_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Detectron1-Comparisons/keypoint_rcnn_R_50_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Detectron1-Comparisons/mask_rcnn_R_50_FPN_noaug_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Detectron1-Comparisons/mask_rcnn_R_50_FPN_noaug_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/LVISv0.5-InstanceSegmentation/mask_rcnn_R_101_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/LVISv0.5-InstanceSegmentation/mask_rcnn_R_101_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/LVISv0.5-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/LVISv0.5-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/LVISv0.5-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/LVISv0.5-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/LVISv1-InstanceSegmentation/mask_rcnn_R_101_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/LVISv1-InstanceSegmentation/mask_rcnn_R_101_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/LVISv1-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/LVISv1-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/LVISv1-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/LVISv1-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/cascade_mask_rcnn_R_50_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/cascade_mask_rcnn_R_50_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/cascade_mask_rcnn_R_50_FPN_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/cascade_mask_rcnn_R_50_FPN_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/cascade_mask_rcnn_X_152_32x8d_FPN_IN5k_gn_dconv.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/cascade_mask_rcnn_X_152_32x8d_FPN_IN5k_gn_dconv.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/mask_rcnn_R_50_FPN_1x_cls_agnostic.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/mask_rcnn_R_50_FPN_1x_cls_agnostic.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/mask_rcnn_R_50_FPN_1x_dconv_c3-c5.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/mask_rcnn_R_50_FPN_1x_dconv_c3-c5.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/mask_rcnn_R_50_FPN_3x_dconv_c3-c5.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/mask_rcnn_R_50_FPN_3x_dconv_c3-c5.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/mask_rcnn_R_50_FPN_3x_gn.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/mask_rcnn_R_50_FPN_3x_gn.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/mask_rcnn_R_50_FPN_3x_syncbn.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/mask_rcnn_R_50_FPN_3x_syncbn.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/panoptic_fpn_R_101_dconv_cascade_gn_3x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/panoptic_fpn_R_101_dconv_cascade_gn_3x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/scratch_mask_rcnn_R_50_FPN_3x_gn.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/scratch_mask_rcnn_R_50_FPN_3x_gn.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/scratch_mask_rcnn_R_50_FPN_9x_gn.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/scratch_mask_rcnn_R_50_FPN_9x_gn.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/scratch_mask_rcnn_R_50_FPN_9x_syncbn.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/scratch_mask_rcnn_R_50_FPN_9x_syncbn.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/semantic_R_50_FPN_1x.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/Misc/semantic_R_50_FPN_1x.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/PascalVOC-Detection/faster_rcnn_R_50_C4.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/PascalVOC-Detection/faster_rcnn_R_50_C4.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/PascalVOC-Detection/faster_rcnn_R_50_FPN.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/PascalVOC-Detection/faster_rcnn_R_50_FPN.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/cascade_mask_rcnn_R_50_FPN_inference_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/cascade_mask_rcnn_R_50_FPN_inference_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/cascade_mask_rcnn_R_50_FPN_instant_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/cascade_mask_rcnn_R_50_FPN_instant_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/fast_rcnn_R_50_FPN_inference_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/fast_rcnn_R_50_FPN_inference_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/fast_rcnn_R_50_FPN_instant_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/fast_rcnn_R_50_FPN_instant_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/keypoint_rcnn_R_50_FPN_inference_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/keypoint_rcnn_R_50_FPN_inference_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/keypoint_rcnn_R_50_FPN_instant_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/keypoint_rcnn_R_50_FPN_instant_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/keypoint_rcnn_R_50_FPN_normalized_training_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/keypoint_rcnn_R_50_FPN_normalized_training_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/keypoint_rcnn_R_50_FPN_training_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/keypoint_rcnn_R_50_FPN_training_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_C4_GCV_instant_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_C4_GCV_instant_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_C4_inference_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_C4_inference_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_C4_instant_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_C4_instant_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_C4_training_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_C4_training_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_DC5_inference_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_DC5_inference_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_FPN_inference_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_FPN_inference_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_FPN_instant_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_FPN_instant_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_FPN_pred_boxes_training_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_FPN_pred_boxes_training_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_FPN_training_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/mask_rcnn_R_50_FPN_training_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/panoptic_fpn_R_50_inference_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/panoptic_fpn_R_50_inference_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/panoptic_fpn_R_50_instant_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/panoptic_fpn_R_50_instant_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/panoptic_fpn_R_50_training_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/panoptic_fpn_R_50_training_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/retinanet_R_50_FPN_inference_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/retinanet_R_50_FPN_inference_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/retinanet_R_50_FPN_instant_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/retinanet_R_50_FPN_instant_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/rpn_R_50_FPN_inference_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/rpn_R_50_FPN_inference_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/rpn_R_50_FPN_instant_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/rpn_R_50_FPN_instant_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/semantic_R_50_FPN_inference_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/semantic_R_50_FPN_inference_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/semantic_R_50_FPN_instant_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/semantic_R_50_FPN_instant_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/semantic_R_50_FPN_training_acc_test.yaml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/configs/quick_schedules/semantic_R_50_FPN_training_acc_test.yaml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/datasets/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/datasets/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/datasets/prepare_cocofied_lvis.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/datasets/prepare_cocofied_lvis.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/datasets/prepare_for_tests.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/datasets/prepare_for_tests.sh old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/datasets/prepare_panoptic_fpn.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/datasets/prepare_panoptic_fpn.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/demo/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/demo/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/demo/demo.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/demo/demo.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/demo/predictor.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/demo/predictor.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/checkpoint/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/checkpoint/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/checkpoint/c2_model_loading.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/checkpoint/c2_model_loading.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/checkpoint/catalog.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/checkpoint/catalog.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/checkpoint/detection_checkpoint.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/checkpoint/detection_checkpoint.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/config/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/config/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/config/compat.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/config/compat.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/config/config.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/config/config.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/config/defaults.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/config/defaults.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/build.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/build.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/catalog.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/catalog.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/common.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/common.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/dataset_mapper.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/dataset_mapper.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/builtin.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/builtin.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/builtin_meta.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/builtin_meta.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/cityscapes.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/cityscapes.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/coco.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/coco.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/lvis.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/lvis.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/lvis_v0_5_categories.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/lvis_v0_5_categories.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/lvis_v1_categories.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/lvis_v1_categories.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/pascal_voc.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/pascal_voc.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/register_coco.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/datasets/register_coco.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/detection_utils.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/detection_utils.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/samplers/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/samplers/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/samplers/distributed_sampler.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/samplers/distributed_sampler.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/samplers/grouped_batch_sampler.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/samplers/grouped_batch_sampler.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/transforms/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/transforms/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/transforms/augmentation.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/transforms/augmentation.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/transforms/augmentation_impl.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/transforms/augmentation_impl.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/transforms/transform.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/transforms/transform.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/engine/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/engine/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/engine/defaults.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/engine/defaults.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/engine/hooks.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/engine/hooks.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/engine/launch.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/engine/launch.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/engine/train_loop.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/engine/train_loop.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/cityscapes_evaluation.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/cityscapes_evaluation.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/coco_evaluation.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/coco_evaluation.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/evaluator.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/evaluator.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/fast_eval_api.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/fast_eval_api.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/lvis_evaluation.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/lvis_evaluation.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/panoptic_evaluation.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/panoptic_evaluation.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/pascal_voc_evaluation.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/pascal_voc_evaluation.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/rotated_coco_evaluation.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/rotated_coco_evaluation.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/sem_seg_evaluation.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/sem_seg_evaluation.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/testing.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/evaluation/testing.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/api.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/api.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/c10.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/c10.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/caffe2_export.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/caffe2_export.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/caffe2_inference.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/caffe2_inference.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/caffe2_modeling.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/caffe2_modeling.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/patcher.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/patcher.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/shared.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/shared.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/torchscript.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/export/torchscript.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/aspp.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/aspp.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/batch_norm.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/batch_norm.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/blocks.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/blocks.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/ROIAlign/ROIAlign.h b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/ROIAlign/ROIAlign.h old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/ROIAlign/ROIAlign_cpu.cpp b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/ROIAlign/ROIAlign_cpu.cpp old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/ROIAlign/ROIAlign_cuda.cu b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/ROIAlign/ROIAlign_cuda.cu old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated.h b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated.h old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated_cpu.cpp b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated_cpu.cpp old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated_cuda.cu b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated_cuda.cu old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/box_iou_rotated/box_iou_rotated.h b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/box_iou_rotated/box_iou_rotated.h old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/box_iou_rotated/box_iou_rotated_cpu.cpp b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/box_iou_rotated/box_iou_rotated_cpu.cpp old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/box_iou_rotated/box_iou_rotated_cuda.cu b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/box_iou_rotated/box_iou_rotated_cuda.cu old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/box_iou_rotated/box_iou_rotated_utils.h b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/box_iou_rotated/box_iou_rotated_utils.h old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/cocoeval/cocoeval.cpp b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/cocoeval/cocoeval.cpp old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/cocoeval/cocoeval.h b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/cocoeval/cocoeval.h old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/cuda_version.cu b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/cuda_version.cu old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/deformable/deform_conv.h b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/deformable/deform_conv.h old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/deformable/deform_conv_cuda.cu b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/deformable/deform_conv_cuda.cu old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/nms_rotated/nms_rotated.h b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/nms_rotated/nms_rotated.h old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/nms_rotated/nms_rotated_cpu.cpp b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/nms_rotated/nms_rotated_cpu.cpp old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/nms_rotated/nms_rotated_cuda.cu b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/nms_rotated/nms_rotated_cuda.cu old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/vision.cpp b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/csrc/vision.cpp old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/deform_conv.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/deform_conv.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/mask_ops.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/mask_ops.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/nms.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/nms.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/roi_align.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/roi_align.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/roi_align_rotated.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/roi_align_rotated.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/rotated_boxes.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/rotated_boxes.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/shape_spec.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/shape_spec.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/wrappers.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/layers/wrappers.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/model_zoo/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/model_zoo/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/model_zoo/model_zoo.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/model_zoo/model_zoo.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/anchor_generator.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/anchor_generator.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/backbone/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/backbone/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/backbone/backbone.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/backbone/backbone.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/backbone/build.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/backbone/build.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/backbone/fpn.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/backbone/fpn.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/backbone/resnet.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/backbone/resnet.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/box_regression.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/box_regression.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/matcher.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/matcher.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/meta_arch/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/meta_arch/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/meta_arch/build.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/meta_arch/build.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/meta_arch/panoptic_fpn.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/meta_arch/panoptic_fpn.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/meta_arch/rcnn.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/meta_arch/rcnn.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/meta_arch/retinanet.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/meta_arch/retinanet.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/meta_arch/semantic_seg.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/meta_arch/semantic_seg.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/poolers.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/poolers.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/postprocessing.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/postprocessing.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/proposal_generator/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/proposal_generator/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/proposal_generator/build.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/proposal_generator/build.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/proposal_generator/proposal_utils.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/proposal_generator/proposal_utils.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/proposal_generator/rpn.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/proposal_generator/rpn.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/proposal_generator/rrpn.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/proposal_generator/rrpn.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/box_head.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/box_head.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/cascade_rcnn.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/cascade_rcnn.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/fast_rcnn.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/fast_rcnn.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/keypoint_head.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/keypoint_head.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/mask_head.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/mask_head.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/roi_heads.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/roi_heads.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/rotated_fast_rcnn.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/roi_heads/rotated_fast_rcnn.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/sampling.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/sampling.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/test_time_augmentation.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/modeling/test_time_augmentation.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/solver/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/solver/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/solver/build.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/solver/build.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/solver/lr_scheduler.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/solver/lr_scheduler.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/boxes.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/boxes.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/image_list.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/image_list.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/instances.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/instances.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/keypoints.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/keypoints.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/masks.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/masks.py old mode 100755 new mode 100644 index a4d97d942eafbe3ea1bd71fad42b942e9aa5168d..3933471d084b42fc2e0e055d7452d1660e7dc0f1 --- a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/masks.py +++ b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/masks.py @@ -1,442 +1,442 @@ -# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import copy -import itertools -import numpy as np -from typing import Any, Iterator, List, Union -import pycocotools.mask as mask_util -import torch - -from detectron2.layers.roi_align import ROIAlign - -from .boxes import Boxes - - -def polygon_area(x, y): - # Using the shoelace formula - # https://stackoverflow.com/questions/24467972/calculate-area-of-polygon-given-x-y-coordinates - return 0.5 * np.abs(np.dot(x, np.roll(y, 1)) - np.dot(y, np.roll(x, 1))) - - -def polygons_to_bitmask(polygons: List[np.ndarray], height: int, width: int) -> np.ndarray: - """ - Args: - polygons (list[ndarray]): each array has shape (Nx2,) - height, width (int) - - Returns: - ndarray: a bool mask of shape (height, width) - """ - assert len(polygons) > 0, "COCOAPI does not support empty polygons" - rles = mask_util.frPyObjects(polygons, height, width) - rle = mask_util.merge(rles) - return mask_util.decode(rle).astype(np.bool) - - -def rasterize_polygons_within_box( - polygons: List[np.ndarray], box: np.ndarray, mask_size: int -) -> torch.Tensor: - """ - Rasterize the polygons into a mask image and - crop the mask content in the given box. - The cropped mask is resized to (mask_size, mask_size). - - This function is used when generating training targets for mask head in Mask R-CNN. - Given original ground-truth masks for an image, new ground-truth mask - training targets in the size of `mask_size x mask_size` - must be provided for each predicted box. This function will be called to - produce such targets. - - Args: - polygons (list[ndarray[float]]): a list of polygons, which represents an instance. - box: 4-element numpy array - mask_size (int): - - Returns: - Tensor: BoolTensor of shape (mask_size, mask_size) - """ - # 1. Shift the polygons w.r.t the boxes - w, h = box[2] - box[0], box[3] - box[1] - - polygons = copy.deepcopy(polygons) - for p in polygons: - p[0::2] = p[0::2] - box[0] - p[1::2] = p[1::2] - box[1] - - # 2. Rescale the polygons to the new box size - # max() to avoid division by small number - ratio_h = mask_size / max(h, 0.1) - ratio_w = mask_size / max(w, 0.1) - - if ratio_h == ratio_w: - for p in polygons: - p *= ratio_h - else: - for p in polygons: - p[0::2] *= ratio_w - p[1::2] *= ratio_h - - # 3. Rasterize the polygons with coco api - mask = polygons_to_bitmask(polygons, mask_size, mask_size) - mask = torch.from_numpy(mask) - return mask - - -class BitMasks: - """ - This class stores the segmentation masks for all objects in one image, in - the form of bitmaps. - - Attributes: - tensor: bool Tensor of N,H,W, representing N instances in the image. - """ - - def __init__(self, tensor: Union[torch.Tensor, np.ndarray]): - """ - Args: - tensor: bool Tensor of N,H,W, representing N instances in the image. - """ - device = tensor.device if isinstance(tensor, torch.Tensor) else torch.device("cpu") - tensor = torch.as_tensor(tensor, dtype=torch.bool, device=device) - assert tensor.dim() == 3, tensor.size() - self.image_size = tensor.shape[1:] - self.tensor = tensor - - def to(self, *args: Any, **kwargs: Any) -> "BitMasks": - return BitMasks(self.tensor.to(*args, **kwargs)) - - @property - def device(self) -> torch.device: - return self.tensor.device - - def __getitem__(self, item: Union[int, slice, torch.BoolTensor]) -> "BitMasks": - """ - Returns: - BitMasks: Create a new :class:`BitMasks` by indexing. - - The following usage are allowed: - - 1. `new_masks = masks[3]`: return a `BitMasks` which contains only one mask. - 2. `new_masks = masks[2:10]`: return a slice of masks. - 3. `new_masks = masks[vector]`, where vector is a torch.BoolTensor - with `length = len(masks)`. Nonzero elements in the vector will be selected. - - Note that the returned object might share storage with this object, - subject to Pytorch's indexing semantics. - """ - if isinstance(item, int): - return BitMasks(self.tensor[item].view(1, -1)) - - if item.dtype == torch.int32: - m = self.tensor[item.long()] - else: - m = self.tensor[item] - - assert m.dim() == 3, "Indexing on BitMasks with {} returns a tensor with shape {}!".format( - item, m.shape - ) - return BitMasks(m) - - def __iter__(self) -> torch.Tensor: - yield from self.tensor - - def __repr__(self) -> str: - s = self.__class__.__name__ + "(" - s += "num_instances={})".format(len(self.tensor)) - return s - - def __len__(self) -> int: - return self.tensor.shape[0] - - def nonempty(self) -> torch.Tensor: - """ - Find masks that are non-empty. - - Returns: - Tensor: a BoolTensor which represents - whether each mask is empty (False) or non-empty (True). - """ - return self.tensor.flatten(1).any(dim=1) - - @staticmethod - def from_polygon_masks( - polygon_masks: Union["PolygonMasks", List[List[np.ndarray]]], height: int, width: int - ) -> "BitMasks": - """ - Args: - polygon_masks (list[list[ndarray]] or PolygonMasks) - height, width (int) - """ - if isinstance(polygon_masks, PolygonMasks): - polygon_masks = polygon_masks.polygons - masks = [polygons_to_bitmask(p, height, width) for p in polygon_masks] - return BitMasks(torch.stack([torch.from_numpy(x) for x in masks])) - - def crop_and_resize(self, boxes: torch.Tensor, mask_size: int) -> torch.Tensor: - """ - Crop each bitmask by the given box, and resize results to (mask_size, mask_size). - This can be used to prepare training targets for Mask R-CNN. - It has less reconstruction error compared to rasterization with polygons. - However we observe no difference in accuracy, - but BitMasks requires more memory to store all the masks. - - Args: - boxes (Tensor): Nx4 tensor storing the boxes for each mask - mask_size (int): the size of the rasterized mask. - - Returns: - Tensor: - A bool tensor of shape (N, mask_size, mask_size), where - N is the number of predicted boxes for this image. - """ - assert len(boxes) == len(self), "{} != {}".format(len(boxes), len(self)) - device = self.tensor.device - - batch_inds = torch.arange(len(boxes), device=device).to(dtype=boxes.dtype)[:, None] - rois = torch.cat([batch_inds, boxes], dim=1) - bit_masks = self.tensor.to(dtype=torch.float32) - rois = rois.to(device=device) - - output = ( - ROIAlign((mask_size, mask_size), 1.0, 0, aligned=True) - .forward(bit_masks[:, None, :, :], rois) - .squeeze(1) - ) - output = output >= 0.5 - return output - - def get_bounding_boxes(self) -> None: - # not needed now - raise NotImplementedError - - @staticmethod - def cat(bitmasks_list: List["BitMasks"]) -> "BitMasks": - """ - Concatenates a list of BitMasks into a single BitMasks - - Arguments: - bitmasks_list (list[BitMasks]) - - Returns: - BitMasks: the concatenated BitMasks - """ - assert isinstance(bitmasks_list, (list, tuple)) - assert len(bitmasks_list) > 0 - assert all(isinstance(bitmask, BitMasks) for bitmask in bitmasks_list) - - cat_bitmasks = type(bitmasks_list[0])(torch.cat([bm.tensor for bm in bitmasks_list], dim=0)) - return cat_bitmasks - - -class PolygonMasks: - """ - This class stores the segmentation masks for all objects in one image, in the form of polygons. - - Attributes: - polygons: list[list[ndarray]]. Each ndarray is a float64 vector representing a polygon. - """ - - def __init__(self, polygons: List[List[Union[torch.Tensor, np.ndarray]]]): - """ - Arguments: - polygons (list[list[np.ndarray]]): The first - level of the list correspond to individual instances, - the second level to all the polygons that compose the - instance, and the third level to the polygon coordinates. - The third level array should have the format of - [x0, y0, x1, y1, ..., xn, yn] (n >= 3). - """ - assert isinstance(polygons, list), ( - "Cannot create PolygonMasks: Expect a list of list of polygons per image. " - "Got '{}' instead.".format(type(polygons)) - ) - - def _make_array(t: Union[torch.Tensor, np.ndarray]) -> np.ndarray: - # Use float64 for higher precision, because why not? - # Always put polygons on CPU (self.to is a no-op) since they - # are supposed to be small tensors. - # May need to change this assumption if GPU placement becomes useful - if isinstance(t, torch.Tensor): - t = t.cpu().numpy() - return np.asarray(t).astype("float64") - - def process_polygons( - polygons_per_instance: List[Union[torch.Tensor, np.ndarray]] - ) -> List[np.ndarray]: - assert isinstance(polygons_per_instance, list), ( - "Cannot create polygons: Expect a list of polygons per instance. " - "Got '{}' instead.".format(type(polygons_per_instance)) - ) - # transform the polygon to a tensor - polygons_per_instance = [_make_array(p) for p in polygons_per_instance] - for polygon in polygons_per_instance: - assert len(polygon) % 2 == 0 and len(polygon) >= 6 - return polygons_per_instance - - self.polygons: List[List[np.ndarray]] = [ - process_polygons(polygons_per_instance) for polygons_per_instance in polygons - ] - - def to(self, *args: Any, **kwargs: Any) -> "PolygonMasks": - return self - - @property - def device(self) -> torch.device: - return torch.device("cpu") - - def get_bounding_boxes(self) -> Boxes: - """ - Returns: - Boxes: tight bounding boxes around polygon masks. - """ - boxes = torch.zeros(len(self.polygons), 4, dtype=torch.float32) - for idx, polygons_per_instance in enumerate(self.polygons): - minxy = torch.as_tensor([float("inf"), float("inf")], dtype=torch.float32) - maxxy = torch.zeros(2, dtype=torch.float32) - for polygon in polygons_per_instance: - coords = torch.from_numpy(polygon).view(-1, 2).to(dtype=torch.float32) - minxy = torch.min(minxy, torch.min(coords, dim=0).values) - maxxy = torch.max(maxxy, torch.max(coords, dim=0).values) - boxes[idx, :2] = minxy - boxes[idx, 2:] = maxxy - return Boxes(boxes) - - def nonempty(self) -> torch.Tensor: - """ - Find masks that are non-empty. - - Returns: - Tensor: - a BoolTensor which represents whether each mask is empty (False) or not (True). - """ - keep = [1 if len(polygon) > 0 else 0 for polygon in self.polygons] - return torch.from_numpy(np.asarray(keep, dtype=np.bool)) - - def __getitem__(self, item: Union[int, slice, List[int], torch.BoolTensor]) -> "PolygonMasks": - """ - Support indexing over the instances and return a `PolygonMasks` object. - `item` can be: - - 1. An integer. It will return an object with only one instance. - 2. A slice. It will return an object with the selected instances. - 3. A list[int]. It will return an object with the selected instances, - correpsonding to the indices in the list. - 4. A vector mask of type BoolTensor, whose length is num_instances. - It will return an object with the instances whose mask is nonzero. - """ - if isinstance(item, int): - selected_polygons = [self.polygons[item]] - elif isinstance(item, slice): - selected_polygons = self.polygons[item] - elif isinstance(item, list): - selected_polygons = [self.polygons[i] for i in item] - elif isinstance(item, torch.Tensor): - # Polygons is a list, so we have to move the indices back to CPU. - if item.dtype == torch.bool: - assert item.dim() == 1, item.shape - item = item.nonzero().squeeze(1).cpu().numpy().tolist() - elif item.dtype in [torch.int32, torch.int64]: - item = item.cpu().numpy().tolist() - else: - raise ValueError("Unsupported tensor dtype={} for indexing!".format(item.dtype)) - selected_polygons = [self.polygons[i] for i in item] - return PolygonMasks(selected_polygons) - - def __iter__(self) -> Iterator[List[np.ndarray]]: - """ - Yields: - list[ndarray]: the polygons for one instance. - Each Tensor is a float64 vector representing a polygon. - """ - return iter(self.polygons) - - def __repr__(self) -> str: - s = self.__class__.__name__ + "(" - s += "num_instances={})".format(len(self.polygons)) - return s - - def __len__(self) -> int: - return len(self.polygons) - - def crop_and_resize(self, boxes: torch.Tensor, mask_size: int) -> torch.Tensor: - """ - Crop each mask by the given box, and resize results to (mask_size, mask_size). - This can be used to prepare training targets for Mask R-CNN. - - Args: - boxes (Tensor): Nx4 tensor storing the boxes for each mask - mask_size (int): the size of the rasterized mask. - - Returns: - Tensor: A bool tensor of shape (N, mask_size, mask_size), where - N is the number of predicted boxes for this image. - """ - assert len(boxes) == len(self), "{} != {}".format(len(boxes), len(self)) - - device = boxes.device - # Put boxes on the CPU, as the polygon representation is not efficient GPU-wise - # (several small tensors for representing a single instance mask) - boxes = boxes.to(torch.device("cpu")) - - results = [ - rasterize_polygons_within_box(poly, box.numpy(), mask_size) - for poly, box in zip(self.polygons, boxes) - ] - """ - poly: list[list[float]], the polygons for one instance - box: a tensor of shape (4,) - """ - if len(results) == 0: - return torch.empty(0, mask_size, mask_size, dtype=torch.bool, device=device) - return torch.stack(results, dim=0).to(device=device) - - def area(self): - """ - Computes area of the mask. - Only works with Polygons, using the shoelace formula: - https://stackoverflow.com/questions/24467972/calculate-area-of-polygon-given-x-y-coordinates - - Returns: - Tensor: a vector, area for each instance - """ - - area = [] - for polygons_per_instance in self.polygons: - area_per_instance = 0 - for p in polygons_per_instance: - area_per_instance += polygon_area(p[0::2], p[1::2]) - area.append(area_per_instance) - - return torch.tensor(area) - - @staticmethod - def cat(polymasks_list: List["PolygonMasks"]) -> "PolygonMasks": - """ - Concatenates a list of PolygonMasks into a single PolygonMasks - - Arguments: - polymasks_list (list[PolygonMasks]) - - Returns: - PolygonMasks: the concatenated PolygonMasks - """ - assert isinstance(polymasks_list, (list, tuple)) - assert len(polymasks_list) > 0 - assert all(isinstance(polymask, PolygonMasks) for polymask in polymasks_list) - - cat_polymasks = type(polymasks_list[0])( - list(itertools.chain.from_iterable(pm.polygons for pm in polymasks_list)) - ) - return cat_polymasks +# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import copy +import itertools +import numpy as np +from typing import Any, Iterator, List, Union +import pycocotools.mask as mask_util +import torch + +from detectron2.layers.roi_align import ROIAlign + +from .boxes import Boxes + + +def polygon_area(x, y): + # Using the shoelace formula + # https://stackoverflow.com/questions/24467972/calculate-area-of-polygon-given-x-y-coordinates + return 0.5 * np.abs(np.dot(x, np.roll(y, 1)) - np.dot(y, np.roll(x, 1))) + + +def polygons_to_bitmask(polygons: List[np.ndarray], height: int, width: int) -> np.ndarray: + """ + Args: + polygons (list[ndarray]): each array has shape (Nx2,) + height, width (int) + + Returns: + ndarray: a bool mask of shape (height, width) + """ + assert len(polygons) > 0, "COCOAPI does not support empty polygons" + rles = mask_util.frPyObjects(polygons, height, width) + rle = mask_util.merge(rles) + return mask_util.decode(rle).astype(np.bool) + + +def rasterize_polygons_within_box( + polygons: List[np.ndarray], box: np.ndarray, mask_size: int +) -> torch.Tensor: + """ + Rasterize the polygons into a mask image and + crop the mask content in the given box. + The cropped mask is resized to (mask_size, mask_size). + + This function is used when generating training targets for mask head in Mask R-CNN. + Given original ground-truth masks for an image, new ground-truth mask + training targets in the size of `mask_size x mask_size` + must be provided for each predicted box. This function will be called to + produce such targets. + + Args: + polygons (list[ndarray[float]]): a list of polygons, which represents an instance. + box: 4-element numpy array + mask_size (int): + + Returns: + Tensor: BoolTensor of shape (mask_size, mask_size) + """ + # 1. Shift the polygons w.r.t the boxes + w, h = box[2] - box[0], box[3] - box[1] + + polygons = copy.deepcopy(polygons) + for p in polygons: + p[0::2] = p[0::2] - box[0] + p[1::2] = p[1::2] - box[1] + + # 2. Rescale the polygons to the new box size + # max() to avoid division by small number + ratio_h = mask_size / max(h, 0.1) + ratio_w = mask_size / max(w, 0.1) + + if ratio_h == ratio_w: + for p in polygons: + p *= ratio_h + else: + for p in polygons: + p[0::2] *= ratio_w + p[1::2] *= ratio_h + + # 3. Rasterize the polygons with coco api + mask = polygons_to_bitmask(polygons, mask_size, mask_size) + mask = torch.from_numpy(mask) + return mask + + +class BitMasks: + """ + This class stores the segmentation masks for all objects in one image, in + the form of bitmaps. + + Attributes: + tensor: bool Tensor of N,H,W, representing N instances in the image. + """ + + def __init__(self, tensor: Union[torch.Tensor, np.ndarray]): + """ + Args: + tensor: bool Tensor of N,H,W, representing N instances in the image. + """ + device = tensor.device if isinstance(tensor, torch.Tensor) else torch.device("cpu") + tensor = torch.as_tensor(tensor, dtype=torch.bool, device=device) + assert tensor.dim() == 3, tensor.size() + self.image_size = tensor.shape[1:] + self.tensor = tensor + + def to(self, *args: Any, **kwargs: Any) -> "BitMasks": + return BitMasks(self.tensor.to(*args, **kwargs)) + + @property + def device(self) -> torch.device: + return self.tensor.device + + def __getitem__(self, item: Union[int, slice, torch.BoolTensor]) -> "BitMasks": + """ + Returns: + BitMasks: Create a new :class:`BitMasks` by indexing. + + The following usage are allowed: + + 1. `new_masks = masks[3]`: return a `BitMasks` which contains only one mask. + 2. `new_masks = masks[2:10]`: return a slice of masks. + 3. `new_masks = masks[vector]`, where vector is a torch.BoolTensor + with `length = len(masks)`. Nonzero elements in the vector will be selected. + + Note that the returned object might share storage with this object, + subject to Pytorch's indexing semantics. + """ + if isinstance(item, int): + return BitMasks(self.tensor[item].view(1, -1)) + + if item.dtype == torch.int32: + m = self.tensor[item.long()] + else: + m = self.tensor[item] + + assert m.dim() == 3, "Indexing on BitMasks with {} returns a tensor with shape {}!".format( + item, m.shape + ) + return BitMasks(m) + + def __iter__(self) -> torch.Tensor: + yield from self.tensor + + def __repr__(self) -> str: + s = self.__class__.__name__ + "(" + s += "num_instances={})".format(len(self.tensor)) + return s + + def __len__(self) -> int: + return self.tensor.shape[0] + + def nonempty(self) -> torch.Tensor: + """ + Find masks that are non-empty. + + Returns: + Tensor: a BoolTensor which represents + whether each mask is empty (False) or non-empty (True). + """ + return self.tensor.flatten(1).any(dim=1) + + @staticmethod + def from_polygon_masks( + polygon_masks: Union["PolygonMasks", List[List[np.ndarray]]], height: int, width: int + ) -> "BitMasks": + """ + Args: + polygon_masks (list[list[ndarray]] or PolygonMasks) + height, width (int) + """ + if isinstance(polygon_masks, PolygonMasks): + polygon_masks = polygon_masks.polygons + masks = [polygons_to_bitmask(p, height, width) for p in polygon_masks] + return BitMasks(torch.stack([torch.from_numpy(x) for x in masks])) + + def crop_and_resize(self, boxes: torch.Tensor, mask_size: int) -> torch.Tensor: + """ + Crop each bitmask by the given box, and resize results to (mask_size, mask_size). + This can be used to prepare training targets for Mask R-CNN. + It has less reconstruction error compared to rasterization with polygons. + However we observe no difference in accuracy, + but BitMasks requires more memory to store all the masks. + + Args: + boxes (Tensor): Nx4 tensor storing the boxes for each mask + mask_size (int): the size of the rasterized mask. + + Returns: + Tensor: + A bool tensor of shape (N, mask_size, mask_size), where + N is the number of predicted boxes for this image. + """ + assert len(boxes) == len(self), "{} != {}".format(len(boxes), len(self)) + device = self.tensor.device + + batch_inds = torch.arange(len(boxes), device=device).to(dtype=boxes.dtype)[:, None] + rois = torch.cat([batch_inds, boxes], dim=1) + bit_masks = self.tensor.to(dtype=torch.float32) + rois = rois.to(device=device) + + output = ( + ROIAlign((mask_size, mask_size), 1.0, 0, aligned=True) + .forward(bit_masks[:, None, :, :], rois) + .squeeze(1) + ) + output = output >= 0.5 + return output + + def get_bounding_boxes(self) -> None: + # not needed now + raise NotImplementedError + + @staticmethod + def cat(bitmasks_list: List["BitMasks"]) -> "BitMasks": + """ + Concatenates a list of BitMasks into a single BitMasks + + Arguments: + bitmasks_list (list[BitMasks]) + + Returns: + BitMasks: the concatenated BitMasks + """ + assert isinstance(bitmasks_list, (list, tuple)) + assert len(bitmasks_list) > 0 + assert all(isinstance(bitmask, BitMasks) for bitmask in bitmasks_list) + + cat_bitmasks = type(bitmasks_list[0])(torch.cat([bm.tensor for bm in bitmasks_list], dim=0)) + return cat_bitmasks + + +class PolygonMasks: + """ + This class stores the segmentation masks for all objects in one image, in the form of polygons. + + Attributes: + polygons: list[list[ndarray]]. Each ndarray is a float64 vector representing a polygon. + """ + + def __init__(self, polygons: List[List[Union[torch.Tensor, np.ndarray]]]): + """ + Arguments: + polygons (list[list[np.ndarray]]): The first + level of the list correspond to individual instances, + the second level to all the polygons that compose the + instance, and the third level to the polygon coordinates. + The third level array should have the format of + [x0, y0, x1, y1, ..., xn, yn] (n >= 3). + """ + assert isinstance(polygons, list), ( + "Cannot create PolygonMasks: Expect a list of list of polygons per image. " + "Got '{}' instead.".format(type(polygons)) + ) + + def _make_array(t: Union[torch.Tensor, np.ndarray]) -> np.ndarray: + # Use float64 for higher precision, because why not? + # Always put polygons on CPU (self.to is a no-op) since they + # are supposed to be small tensors. + # May need to change this assumption if GPU placement becomes useful + if isinstance(t, torch.Tensor): + t = t.cpu().numpy() + return np.asarray(t).astype("float64") + + def process_polygons( + polygons_per_instance: List[Union[torch.Tensor, np.ndarray]] + ) -> List[np.ndarray]: + assert isinstance(polygons_per_instance, list), ( + "Cannot create polygons: Expect a list of polygons per instance. " + "Got '{}' instead.".format(type(polygons_per_instance)) + ) + # transform the polygon to a tensor + polygons_per_instance = [_make_array(p) for p in polygons_per_instance] + for polygon in polygons_per_instance: + assert len(polygon) % 2 == 0 and len(polygon) >= 6 + return polygons_per_instance + + self.polygons: List[List[np.ndarray]] = [ + process_polygons(polygons_per_instance) for polygons_per_instance in polygons + ] + + def to(self, *args: Any, **kwargs: Any) -> "PolygonMasks": + return self + + @property + def device(self) -> torch.device: + return torch.device("cpu") + + def get_bounding_boxes(self) -> Boxes: + """ + Returns: + Boxes: tight bounding boxes around polygon masks. + """ + boxes = torch.zeros(len(self.polygons), 4, dtype=torch.float32) + for idx, polygons_per_instance in enumerate(self.polygons): + minxy = torch.as_tensor([float("inf"), float("inf")], dtype=torch.float32) + maxxy = torch.zeros(2, dtype=torch.float32) + for polygon in polygons_per_instance: + coords = torch.from_numpy(polygon).view(-1, 2).to(dtype=torch.float32) + minxy = torch.min(minxy, torch.min(coords, dim=0).values) + maxxy = torch.max(maxxy, torch.max(coords, dim=0).values) + boxes[idx, :2] = minxy + boxes[idx, 2:] = maxxy + return Boxes(boxes) + + def nonempty(self) -> torch.Tensor: + """ + Find masks that are non-empty. + + Returns: + Tensor: + a BoolTensor which represents whether each mask is empty (False) or not (True). + """ + keep = [1 if len(polygon) > 0 else 0 for polygon in self.polygons] + return torch.from_numpy(np.asarray(keep, dtype=np.bool)) + + def __getitem__(self, item: Union[int, slice, List[int], torch.BoolTensor]) -> "PolygonMasks": + """ + Support indexing over the instances and return a `PolygonMasks` object. + `item` can be: + + 1. An integer. It will return an object with only one instance. + 2. A slice. It will return an object with the selected instances. + 3. A list[int]. It will return an object with the selected instances, + correpsonding to the indices in the list. + 4. A vector mask of type BoolTensor, whose length is num_instances. + It will return an object with the instances whose mask is nonzero. + """ + if isinstance(item, int): + selected_polygons = [self.polygons[item]] + elif isinstance(item, slice): + selected_polygons = self.polygons[item] + elif isinstance(item, list): + selected_polygons = [self.polygons[i] for i in item] + elif isinstance(item, torch.Tensor): + # Polygons is a list, so we have to move the indices back to CPU. + if item.dtype == torch.bool: + assert item.dim() == 1, item.shape + item = item.nonzero().squeeze(1).cpu().numpy().tolist() + elif item.dtype in [torch.int32, torch.int64]: + item = item.cpu().numpy().tolist() + else: + raise ValueError("Unsupported tensor dtype={} for indexing!".format(item.dtype)) + selected_polygons = [self.polygons[i] for i in item] + return PolygonMasks(selected_polygons) + + def __iter__(self) -> Iterator[List[np.ndarray]]: + """ + Yields: + list[ndarray]: the polygons for one instance. + Each Tensor is a float64 vector representing a polygon. + """ + return iter(self.polygons) + + def __repr__(self) -> str: + s = self.__class__.__name__ + "(" + s += "num_instances={})".format(len(self.polygons)) + return s + + def __len__(self) -> int: + return len(self.polygons) + + def crop_and_resize(self, boxes: torch.Tensor, mask_size: int) -> torch.Tensor: + """ + Crop each mask by the given box, and resize results to (mask_size, mask_size). + This can be used to prepare training targets for Mask R-CNN. + + Args: + boxes (Tensor): Nx4 tensor storing the boxes for each mask + mask_size (int): the size of the rasterized mask. + + Returns: + Tensor: A bool tensor of shape (N, mask_size, mask_size), where + N is the number of predicted boxes for this image. + """ + assert len(boxes) == len(self), "{} != {}".format(len(boxes), len(self)) + + device = boxes.device + # Put boxes on the CPU, as the polygon representation is not efficient GPU-wise + # (several small tensors for representing a single instance mask) + boxes = boxes.to(torch.device("cpu")) + + results = [ + rasterize_polygons_within_box(poly, box.numpy(), mask_size) + for poly, box in zip(self.polygons, boxes) + ] + """ + poly: list[list[float]], the polygons for one instance + box: a tensor of shape (4,) + """ + if len(results) == 0: + return torch.empty(0, mask_size, mask_size, dtype=torch.bool, device=device) + return torch.stack(results, dim=0).to(device=device) + + def area(self): + """ + Computes area of the mask. + Only works with Polygons, using the shoelace formula: + https://stackoverflow.com/questions/24467972/calculate-area-of-polygon-given-x-y-coordinates + + Returns: + Tensor: a vector, area for each instance + """ + + area = [] + for polygons_per_instance in self.polygons: + area_per_instance = 0 + for p in polygons_per_instance: + area_per_instance += polygon_area(p[0::2], p[1::2]) + area.append(area_per_instance) + + return torch.tensor(area) + + @staticmethod + def cat(polymasks_list: List["PolygonMasks"]) -> "PolygonMasks": + """ + Concatenates a list of PolygonMasks into a single PolygonMasks + + Arguments: + polymasks_list (list[PolygonMasks]) + + Returns: + PolygonMasks: the concatenated PolygonMasks + """ + assert isinstance(polymasks_list, (list, tuple)) + assert len(polymasks_list) > 0 + assert all(isinstance(polymask, PolygonMasks) for polymask in polymasks_list) + + cat_polymasks = type(polymasks_list[0])( + list(itertools.chain.from_iterable(pm.polygons for pm in polymasks_list)) + ) + return cat_polymasks diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/rotated_boxes.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/structures/rotated_boxes.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/analysis.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/analysis.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/collect_env.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/collect_env.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/colormap.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/colormap.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/comm.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/comm.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/env.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/env.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/events.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/events.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/logger.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/logger.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/memory.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/memory.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/registry.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/registry.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/serialize.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/serialize.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/video_visualizer.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/video_visualizer.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/visualizer.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/utils/visualizer.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/linter.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/linter.sh old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/packaging/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/packaging/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/packaging/build_all_wheels.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/packaging/build_all_wheels.sh old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/packaging/build_wheel.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/packaging/build_wheel.sh old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/packaging/gen_install_table.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/packaging/gen_install_table.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/packaging/gen_wheel_index.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/packaging/gen_wheel_index.sh old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/packaging/pkg_helpers.bash b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/packaging/pkg_helpers.bash old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/parse_results.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/parse_results.sh old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/run_inference_tests.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/run_inference_tests.sh old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/run_instant_tests.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/dev/run_instant_tests.sh old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docker/Dockerfile b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docker/Dockerfile old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docker/Dockerfile-circleci b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docker/Dockerfile-circleci old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docker/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docker/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docker/docker-compose.yml b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docker/docker-compose.yml old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/.gitignore b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/.gitignore old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/Makefile b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/Makefile old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/_static/css/custom.css b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/_static/css/custom.css old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/conf.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/conf.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/notes/benchmarks.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/notes/benchmarks.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/notes/changelog.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/notes/changelog.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/notes/compatibility.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/notes/compatibility.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/notes/contributing.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/notes/contributing.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/builtin_datasets.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/builtin_datasets.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/configs.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/configs.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/data_loading.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/data_loading.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/datasets.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/datasets.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/deployment.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/deployment.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/evaluation.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/evaluation.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/extend.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/extend.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/getting_started.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/getting_started.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/install.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/install.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/models.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/models.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/training.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/training.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/write-models.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/docs/tutorials/write-models.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/eval.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/eval.sh old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/run.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/run.sh old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/run8p.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/run8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/run8p_for_faster_rcnn.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/run8p_for_faster_rcnn.sh old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/run_for_faster_rcnn.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/run_for_faster_rcnn.sh old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/setup.cfg b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/setup.cfg old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/setup.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/setup.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/test/train_full_1p.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/test/train_full_1p.sh index b5f6264a8e01104c3b8154af145e00acab7fc7c8..2d19be502ae68a82480272ff2b60e9410c740d23 100644 --- a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/test/train_full_1p.sh +++ b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/test/train_full_1p.sh @@ -1,181 +1,181 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd`/../ - -#集合通信参数,不需要修改 -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 - - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -export ASCEND_GLOBAL_LOG_LEVEL=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="Faster_Mask_RCNN_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=128 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.01 - -#TF2.X独有,需要模型审视修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -#precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_performance_1P.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/test/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/test/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/test/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/test/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/test/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt - fi - # 绑核,不需要的绑核的模型删除,需要的模型审视修改 - #let a=RANK_ID*12 - #let b=RANK_ID+1 - #let c=b*12-1 - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path - nohup python3 main.py \ - --video_path ${data_path}/hmdb51_jpg \ - --annotation_path ${data_path}/hmdb51_json/hmdb51_1.json \ - --result_path outputs \ - --dataset hmdb51 \ - --n_classes 51 \ - --n_pretrain_classes 700 \ - --pretrain_path ${data_path}/r3d18_K_200ep.pth \ - --ft_begin_module fc \ - --model resnet \ - --model_depth 18 \ - --batch_size 128 \ - --n_threads 16 \ - --checkpoint 5 \ - --amp_cfg \ - --opt_level O2 \ - --loss_scale_value 1024 \ - --device_list ${ASCEND_DEVICE_ID} \ - --n_epochs 1 \ - --manual_seed 1234 \ - --learning_rate 0.01 \ - --tensorboard > ${cur_path}/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -done -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep Fps $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v "\[1/" | grep -v "\[2/" | awk -F "Fps" '{print$2}' | awk '{print$1}' | awk '{sum+=$1} END {print"",sum/NR}'` -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep "Fps" $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|tail -2|head -1|awk '{print $17}'|sed 's/[()]//g' ` -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`echo "${batch_size} ${FPS}" | awk '{printf("%.2f",$1*1000/$2)}' ` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "Fps" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss" '{print$2}' | awk '{print$1}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd`/../ + +#集合通信参数,不需要修改 +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 + + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +export ASCEND_GLOBAL_LOG_LEVEL=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="Faster_Mask_RCNN_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=128 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.01 + +#TF2.X独有,需要模型审视修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +#precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_performance_1P.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/test/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/test/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/test/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/test/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/test/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/test/output/$ASCEND_DEVICE_ID/ckpt + fi + # 绑核,不需要的绑核的模型删除,需要的模型审视修改 + #let a=RANK_ID*12 + #let b=RANK_ID+1 + #let c=b*12-1 + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path + nohup python3 main.py \ + --video_path ${data_path}/hmdb51_jpg \ + --annotation_path ${data_path}/hmdb51_json/hmdb51_1.json \ + --result_path outputs \ + --dataset hmdb51 \ + --n_classes 51 \ + --n_pretrain_classes 700 \ + --pretrain_path ${data_path}/r3d18_K_200ep.pth \ + --ft_begin_module fc \ + --model resnet \ + --model_depth 18 \ + --batch_size 128 \ + --n_threads 16 \ + --checkpoint 5 \ + --amp_cfg \ + --opt_level O2 \ + --loss_scale_value 1024 \ + --device_list ${ASCEND_DEVICE_ID} \ + --n_epochs 1 \ + --manual_seed 1234 \ + --learning_rate 0.01 \ + --tensorboard > ${cur_path}/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +done +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep Fps $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v "\[1/" | grep -v "\[2/" | awk -F "Fps" '{print$2}' | awk '{print$1}' | awk '{sum+=$1} END {print"",sum/NR}'` +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep "Fps" $cur_path/test/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|tail -2|head -1|awk '{print $17}'|sed 's/[()]//g' ` +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`echo "${batch_size} ${FPS}" | awk '{printf("%.2f",$1*1000/$2)}' ` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "Fps" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss" '{print$2}' | awk '{print$1}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/test/train_performance_1p.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/test/train_performance_1p.sh index 807a85a8e11d8b84959ad0eb945dfef648f06e09..aee654686f5e4ab57a00f9eed1808da11ee93285 100644 --- a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/test/train_performance_1p.sh @@ -1,182 +1,182 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` - -#集合通信参数,不需要修改 -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 - - -# 数据集路径,保持为空,不需要修改 -data_path="" -test_path_dir="" - -#设置默认日志级别,不需要修改 -export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="Faster_Mask_RCNN_ID0101_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=8 -#训练step -train_steps=100 -#学习率 -learning_rate=0.01 - -#TF2.X独有,需要模型审视修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -#precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_performance_1P.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/test/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/test/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/test/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --test_path_dir* ]];then - test_path_dir=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt -fi - - -#修改参数 -sed -i "s|\"coco_2017_train\": (\"coco/train2017\", \"coco/annotations/instances_train2017.json\")|\"coco_2017_train\": (\"$data_path/coco/train2017\", \"$data_path/coco/annotations/instances_train2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py -sed -i "s|\"coco_2017_val\": (\"coco/val2017\", \"coco/annotations/instances_val2017.json\")|\"coco_2017_val\": (\"$data_path/coco/val2017\", \"$data_path/coco/annotations/instances_val2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py -sed -i "s|WEIGHTS: \"detectron2://ImageNetPretrained/MSRA/R-101.pkl\"|WEIGHTS: \"$data_path/R-101.pkl\"|g" $cur_path/../configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml -wait - -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" == x"true" ];then - sed -i "s|ret.append(hooks.EvalHook(cfg.TEST.EVAL_PERIOD, test_and_save_results))|#ret.append(hooks.EvalHook(cfg.TEST.EVAL_PERIOD, test_and_save_results))|g" $cur_path/../detectron2/engine/defaults.py -else - source ${test_path_dir}/env_npu.sh -fi - -cd $cur_path/../ - -python3 setup.py build develop > $cur_path/../log.txt - -#训练开始时间,不需要修改 -start_time=$(date +%s) -nohup python3 tools/train_net.py \ - --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml \ - AMP 1 \ - OPT_LEVEL O2 \ - LOSS_SCALE_VALUE 64 \ - MODEL.DEVICE npu:$ASCEND_DEVICE_ID \ - SOLVER.IMS_PER_BATCH $batch_size \ - SOLVER.MAX_ITER $train_steps \ - SEED 1234 \ - MODEL.RPN.NMS_THRESH 0.8 \ - MODEL.ROI_BOX_HEAD.POOLER_SAMPLING_RATIO 2 \ - MODEL.ROI_MASK_HEAD.POOLER_SAMPLING_RATIO 2 \ - DATALOADER.NUM_WORKERS 4 \ - SOLVER.BASE_LR 0.0025 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -#Time=`grep total_loss $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'time: ' '{print $2}'|awk '{print $1}'|awk 'NR>1'|awk '{sum+=$1} END {print sum/NR}'|sed s/[[:space:]]//g` -#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${Time}'}'` -FPS=`grep FPS $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=None -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据 -#吞吐量,不需要修改 -ActualFPS=${FPS} -#单迭代训练时长,不需要修改 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep total_loss $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'total_loss: ' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` + +#集合通信参数,不需要修改 +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 + + +# 数据集路径,保持为空,不需要修改 +data_path="" +test_path_dir="" + +#设置默认日志级别,不需要修改 +export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="Faster_Mask_RCNN_ID0101_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=8 +#训练step +train_steps=100 +#学习率 +learning_rate=0.01 + +#TF2.X独有,需要模型审视修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +#precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_performance_1P.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/test/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/test/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/test/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --test_path_dir* ]];then + test_path_dir=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt +fi + + +#修改参数 +sed -i "s|\"coco_2017_train\": (\"coco/train2017\", \"coco/annotations/instances_train2017.json\")|\"coco_2017_train\": (\"$data_path/coco/train2017\", \"$data_path/coco/annotations/instances_train2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py +sed -i "s|\"coco_2017_val\": (\"coco/val2017\", \"coco/annotations/instances_val2017.json\")|\"coco_2017_val\": (\"$data_path/coco/val2017\", \"$data_path/coco/annotations/instances_val2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py +sed -i "s|WEIGHTS: \"detectron2://ImageNetPretrained/MSRA/R-101.pkl\"|WEIGHTS: \"$data_path/R-101.pkl\"|g" $cur_path/../configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml +wait + +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" == x"true" ];then + sed -i "s|ret.append(hooks.EvalHook(cfg.TEST.EVAL_PERIOD, test_and_save_results))|#ret.append(hooks.EvalHook(cfg.TEST.EVAL_PERIOD, test_and_save_results))|g" $cur_path/../detectron2/engine/defaults.py +else + source ${test_path_dir}/env_npu.sh +fi + +cd $cur_path/../ + +python3 setup.py build develop > $cur_path/../log.txt + +#训练开始时间,不需要修改 +start_time=$(date +%s) +nohup python3 tools/train_net.py \ + --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml \ + AMP 1 \ + OPT_LEVEL O2 \ + LOSS_SCALE_VALUE 64 \ + MODEL.DEVICE npu:$ASCEND_DEVICE_ID \ + SOLVER.IMS_PER_BATCH $batch_size \ + SOLVER.MAX_ITER $train_steps \ + SEED 1234 \ + MODEL.RPN.NMS_THRESH 0.8 \ + MODEL.ROI_BOX_HEAD.POOLER_SAMPLING_RATIO 2 \ + MODEL.ROI_MASK_HEAD.POOLER_SAMPLING_RATIO 2 \ + DATALOADER.NUM_WORKERS 4 \ + SOLVER.BASE_LR 0.0025 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +#Time=`grep total_loss $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'time: ' '{print $2}'|awk '{print $1}'|awk 'NR>1'|awk '{sum+=$1} END {print sum/NR}'|sed s/[[:space:]]//g` +#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${Time}'}'` +FPS=`grep FPS $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=None +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据 +#吞吐量,不需要修改 +ActualFPS=${FPS} +#单迭代训练时长,不需要修改 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep total_loss $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'total_loss: ' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/test/train_performance_8p.sh index 448e69a2f228fc11bc442879c1dab29c3ef348b9..162088573c6b5f03f12560bd2c74ddb6a7b5fba8 100644 --- a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/test/train_performance_8p.sh @@ -1,170 +1,170 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` - -#集合通信参数,不需要修改 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="Faster_Mask_RCNN_ID0101_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=64 -#训练step -train_steps=100 -#学习率 -learning_rate=0.01 - -#TF2.X独有,需要模型审视修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -#precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_performance_1P.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/test/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/test/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/test/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt -fi - - -#修改参数 -sed -i "s|\"coco_2017_train\": (\"coco/train2017\", \"coco/annotations/instances_train2017.json\")|\"coco_2017_train\": (\"$data_path/coco/train2017\", \"$data_path/coco/annotations/instances_train2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py -sed -i "s|\"coco_2017_val\": (\"coco/val2017\", \"coco/annotations/instances_val2017.json\")|\"coco_2017_val\": (\"$data_path/coco/val2017\", \"$data_path/coco/annotations/instances_val2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py -sed -i "s|WEIGHTS: \"detectron2://ImageNetPretrained/MSRA/R-101.pkl\"|WEIGHTS: \"$data_path/R-101.pkl\"|g" $cur_path/../configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml -wait - -cd $cur_path/../ - -python3 setup.py build develop > $cur_path/../log.txt - -#训练开始时间,不需要修改 -start_time=$(date +%s) -nohup python3 tools/train_net.py \ - --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml \ - --device-ids 0 1 2 3 4 5 6 7 \ - --num-gpus 8 \ - AMP 1 \ - OPT_LEVEL O2 \ - LOSS_SCALE_VALUE 64 \ - SOLVER.IMS_PER_BATCH $batch_size \ - SOLVER.MAX_ITER $train_steps \ - SEED 1234 \ - MODEL.RPN.NMS_THRESH 0.8 \ - MODEL.ROI_BOX_HEAD.POOLER_SAMPLING_RATIO 2 \ - MODEL.ROI_MASK_HEAD.POOLER_SAMPLING_RATIO 2 \ - DATALOADER.NUM_WORKERS 8 \ - SOLVER.BASE_LR 0.02 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -##Time=`grep total_loss $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'time: ' '{print $2}'|awk '{print $1}'|awk 'NR>1'|awk '{sum+=$1} END {print sum/NR}'|sed s/[[:space:]]//g` -#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${Time}'}'` -FPS=`grep FPS $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=None -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据 -#吞吐量,不需要修改 -ActualFPS=${FPS} -#单迭代训练时长,不需要修改 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep total_loss $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'total_loss: ' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` + +#集合通信参数,不需要修改 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="Faster_Mask_RCNN_ID0101_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=64 +#训练step +train_steps=100 +#学习率 +learning_rate=0.01 + +#TF2.X独有,需要模型审视修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +#precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_performance_1P.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/test/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/test/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/test/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt +fi + + +#修改参数 +sed -i "s|\"coco_2017_train\": (\"coco/train2017\", \"coco/annotations/instances_train2017.json\")|\"coco_2017_train\": (\"$data_path/coco/train2017\", \"$data_path/coco/annotations/instances_train2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py +sed -i "s|\"coco_2017_val\": (\"coco/val2017\", \"coco/annotations/instances_val2017.json\")|\"coco_2017_val\": (\"$data_path/coco/val2017\", \"$data_path/coco/annotations/instances_val2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py +sed -i "s|WEIGHTS: \"detectron2://ImageNetPretrained/MSRA/R-101.pkl\"|WEIGHTS: \"$data_path/R-101.pkl\"|g" $cur_path/../configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml +wait + +cd $cur_path/../ + +python3 setup.py build develop > $cur_path/../log.txt + +#训练开始时间,不需要修改 +start_time=$(date +%s) +nohup python3 tools/train_net.py \ + --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml \ + --device-ids 0 1 2 3 4 5 6 7 \ + --num-gpus 8 \ + AMP 1 \ + OPT_LEVEL O2 \ + LOSS_SCALE_VALUE 64 \ + SOLVER.IMS_PER_BATCH $batch_size \ + SOLVER.MAX_ITER $train_steps \ + SEED 1234 \ + MODEL.RPN.NMS_THRESH 0.8 \ + MODEL.ROI_BOX_HEAD.POOLER_SAMPLING_RATIO 2 \ + MODEL.ROI_MASK_HEAD.POOLER_SAMPLING_RATIO 2 \ + DATALOADER.NUM_WORKERS 8 \ + SOLVER.BASE_LR 0.02 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +##Time=`grep total_loss $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'time: ' '{print $2}'|awk '{print $1}'|awk 'NR>1'|awk '{sum+=$1} END {print sum/NR}'|sed s/[[:space:]]//g` +#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${Time}'}'` +FPS=`grep FPS $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=None +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据 +#吞吐量,不需要修改 +ActualFPS=${FPS} +#单迭代训练时长,不需要修改 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep total_loss $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'total_loss: ' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/data/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/data/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/data/test_coco.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/data/test_coco.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/data/test_coco_evaluation.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/data/test_coco_evaluation.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/data/test_detection_utils.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/data/test_detection_utils.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/data/test_rotation_transform.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/data/test_rotation_transform.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/data/test_sampler.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/data/test_sampler.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/data/test_transforms.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/data/test_transforms.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/layers/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/layers/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/layers/test_mask_ops.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/layers/test_mask_ops.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/layers/test_nms.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/layers/test_nms.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/layers/test_nms_rotated.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/layers/test_nms_rotated.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/layers/test_roi_align.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/layers/test_roi_align.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/layers/test_roi_align_rotated.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/layers/test_roi_align_rotated.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_anchor_generator.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_anchor_generator.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_box2box_transform.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_box2box_transform.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_fast_rcnn.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_fast_rcnn.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_matcher.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_matcher.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_model_e2e.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_model_e2e.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_roi_heads.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_roi_heads.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_roi_pooler.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_roi_pooler.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_rpn.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/modeling/test_rpn.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/structures/__init__.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/structures/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/structures/test_boxes.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/structures/test_boxes.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/structures/test_imagelist.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/structures/test_imagelist.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/structures/test_instances.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/structures/test_instances.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/structures/test_rotated_boxes.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/structures/test_rotated_boxes.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/test_checkpoint.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/test_checkpoint.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/test_config.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/test_config.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/test_engine.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/test_engine.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/test_export_caffe2.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/test_export_caffe2.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/test_model_analysis.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/test_model_analysis.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/test_model_zoo.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/test_model_zoo.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/test_visualizer.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tests/test_visualizer.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/README.md b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/analyze_model.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/analyze_model.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/benchmark.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/benchmark.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/convert-torchvision-to-d2.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/convert-torchvision-to-d2.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/plain_train_net.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/plain_train_net.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/train_net.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/train_net.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/visualize_data.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/visualize_data.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/visualize_json_results.py b/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/tools/visualize_json_results.py old mode 100755 new mode 100644 diff --git a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/LICENSE b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/LICENSE index 4ba4fdcab3dbdb4d64ce4cccdfd990698b4d596a..a0e03103591c1158a839681f3c404ee9118b182e 100644 --- a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/LICENSE +++ b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/LICENSE @@ -1,29 +1,29 @@ -BSD 3-Clause License - -Copyright (c) 2017, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +BSD 3-Clause License + +Copyright (c) 2017, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/README.md b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/README.md index 39f21344a24d52f49a230714ce7eb3957e709312..9325120e108d5c505c53cf83d4b52c00c4db918f 100644 --- a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/README.md +++ b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/README.md @@ -1,61 +1,61 @@ -# Shape Robust Text Detection with Progressive Scale Expansion Network - -## Requirements -* NPU配套的run包安装(C20B030) -* Python 3.7.5 -* PyTorch(NPU版本) -* apex(NPU版本) -* pyclipper -* Polygon3 -* opencv-python 3.4 - -## 1P -1. 编辑 train_1p.sh device-list(NPU设备号) addr(本机ip地址) data-dir(数据集目录) remark(备注信息) -2. 运行 sh train_1p.sh -``` -python3 -W ignore train_8p_anycard.py \ - --lr 0.001\ - --dist-backend 'hccl' \ - --rank 0 \ - --workers 32 \ - --multiprocessing-distributed \ - --world-size 1 \ - --batch_size 16 \ - --device 'npu' \ - --opt-level 'O2' \ - --loss-scale 64 \ - --addr='XX.XXX.XXX.XXX' \ #修改本机ip地址 - --seed 16 \ - --n_epoch 600 \ - --data-dir '/home/w50015720/npu/PSENet_data' \ #修改数据集目录 - --port 8272 \ - --schedule 200 400 \ - --device-list '0' \ # 修改NPU设备号 - --remark 'test' # 修改备注信息 -``` -## 8P -1. 编辑 train_8p.sh device-list(NPU设备号) addr(本机ip地址) data-dir(数据集目录) remark(备注信息) -2. 运行 sh train_8p.sh - -``` -python3 -W ignore train_8p_anycard.py \ - --lr 0.008\ - --dist-backend 'hccl' \ - --rank 0 \ - --workers 32 \ - --multiprocessing-distributed \ - --world-size 1 \ - --batch_size 32 \ - --device 'npu' \ - --opt-level 'O2' \ - --loss-scale 64 \ - --addr='XX.XXX.XXX.XXX' \ #修改本机ip地址 - --seed 16 \ - --n_epoch 600 \ - --data-dir '/home/data/' \ #修改数据集目录 - --port 8271 \ - --schedule 200 400 \ - --device-list '0,1,2,3,4,5,6,7' \ # 修改NPU设备号 8卡 - --remark 'npu8pbatch32lr8' # 修改备注信息 -``` - +# Shape Robust Text Detection with Progressive Scale Expansion Network + +## Requirements +* NPU配套的run包安装(C20B030) +* Python 3.7.5 +* PyTorch(NPU版本) +* apex(NPU版本) +* pyclipper +* Polygon3 +* opencv-python 3.4 + +## 1P +1. 编辑 train_1p.sh device-list(NPU设备号) addr(本机ip地址) data-dir(数据集目录) remark(备注信息) +2. 运行 sh train_1p.sh +``` +python3 -W ignore train_8p_anycard.py \ + --lr 0.001\ + --dist-backend 'hccl' \ + --rank 0 \ + --workers 32 \ + --multiprocessing-distributed \ + --world-size 1 \ + --batch_size 16 \ + --device 'npu' \ + --opt-level 'O2' \ + --loss-scale 64 \ + --addr='XX.XXX.XXX.XXX' \ #修改本机ip地址 + --seed 16 \ + --n_epoch 600 \ + --data-dir '/home/w50015720/npu/PSENet_data' \ #修改数据集目录 + --port 8272 \ + --schedule 200 400 \ + --device-list '0' \ # 修改NPU设备号 + --remark 'test' # 修改备注信息 +``` +## 8P +1. 编辑 train_8p.sh device-list(NPU设备号) addr(本机ip地址) data-dir(数据集目录) remark(备注信息) +2. 运行 sh train_8p.sh + +``` +python3 -W ignore train_8p_anycard.py \ + --lr 0.008\ + --dist-backend 'hccl' \ + --rank 0 \ + --workers 32 \ + --multiprocessing-distributed \ + --world-size 1 \ + --batch_size 32 \ + --device 'npu' \ + --opt-level 'O2' \ + --loss-scale 64 \ + --addr='XX.XXX.XXX.XXX' \ #修改本机ip地址 + --seed 16 \ + --n_epoch 600 \ + --data-dir '/home/data/' \ #修改数据集目录 + --port 8271 \ + --schedule 200 400 \ + --device-list '0,1,2,3,4,5,6,7' \ # 修改NPU设备号 8卡 + --remark 'npu8pbatch32lr8' # 修改备注信息 +``` + diff --git a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/requirements.txt b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/requirements.txt index 3d66988238ab648957592fa0d284db227f4aa259..fef5b967029953c1fd2e1358900e017d295394c4 100644 --- a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/requirements.txt +++ b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/requirements.txt @@ -1,3 +1,3 @@ -pyclipper -Polygon3 +pyclipper +Polygon3 opencv-python \ No newline at end of file diff --git a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/train_ic15.py b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/train_ic15.py index 05dfb7a1ac3bcf628f80a8d66ab85442c28d47ce..1255f04c8ed5a27a4a6494383aae199336dd15f8 100644 --- a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/train_ic15.py +++ b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/train_ic15.py @@ -1,449 +1,449 @@ -# Copyright [yyyy] [name of copyright owner] -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import argparse -import os -import random -import sys -import time -import warnings - -import numpy as np -import torch -import torch.backends.cudnn as cudnn -import torch.distributed as dist -import torch.multiprocessing as mp -import torch.nn.parallel -import torch.npu -import torch.utils.data.distributed -from apex import amp - -import apex -import models -from data_loader import IC15Loader -from metrics import runningScore -from multi_epochs_dataloader import MultiEpochsDataLoader -from util import AverageMeter - - - -def ohem_single(score, gt_text, training_mask): - pos_num = (int)(np.sum(gt_text > 0.5)) - (int)(np.sum((gt_text > 0.5) & (training_mask <= 0.5))) - - if pos_num == 0: - selected_mask = training_mask - selected_mask = selected_mask.reshape(1, selected_mask.shape[0], selected_mask.shape[1]).astype('float32') - return selected_mask - - neg_num = (int)(np.sum(gt_text <= 0.5)) - neg_num = (int)(min(pos_num * 3, neg_num)) - - if neg_num == 0: - selected_mask = training_mask - selected_mask = selected_mask.reshape(1, selected_mask.shape[0], selected_mask.shape[1]).astype('float32') - return selected_mask - - neg_score = score[gt_text <= 0.5] - neg_score_sorted = np.sort(-neg_score) - threshold = -neg_score_sorted[neg_num - 1] - - selected_mask = ((score >= threshold) | (gt_text > 0.5)) & (training_mask > 0.5) - selected_mask = selected_mask.reshape(1, selected_mask.shape[0], selected_mask.shape[1]).astype('float32') - return selected_mask - - -def ohem_batch(scores, gt_texts, training_masks): - scores = scores.data.cpu().numpy() - gt_texts = gt_texts.data.cpu().numpy() - training_masks = training_masks.data.cpu().numpy() - selected_masks = [] - for i in range(scores.shape[0]): - selected_masks.append(ohem_single(scores[i, :, :], gt_texts[i, :, :], training_masks[i, :, :])) - selected_masks = np.concatenate(selected_masks, 0) - selected_masks = torch.from_numpy(selected_masks).float() - return selected_masks - - -def dice_loss(input, target, mask): - input = torch.sigmoid(input) - - input = input.reshape(input.size()[0], -1) - target = target.reshape(target.size()[0], -1) - mask = mask.reshape(mask.size()[0], -1) - - input = input * mask - target = target * mask - - a = torch.sum(input * target, 1) - b = torch.sum(input * input, 1) + 0.001 - c = torch.sum(target * target, 1) + 0.001 - d = (2 * a) / (b + c) - dice_loss = torch.mean(d) - return 1 - dice_loss - - -def cal_text_score(texts, gt_texts, training_masks, running_metric_text): - training_masks = training_masks.data.cpu().numpy() - pred_text = torch.sigmoid(texts).data.cpu().numpy() * training_masks - - pred_text[pred_text <= 0.5] = 0 - pred_text[pred_text > 0.5] = 1 - pred_text = pred_text.astype(np.int32) - gt_text = gt_texts.data.cpu().numpy() * training_masks - gt_text = gt_text.astype(np.int32) - running_metric_text.update(gt_text, pred_text) - score_text, _ = running_metric_text.get_scores() - return score_text - - -def cal_kernel_score(kernels, gt_kernels, gt_texts, training_masks, running_metric_kernel): - mask = (gt_texts * training_masks).data.cpu().numpy() - kernel = kernels[:, -1, :, :] - gt_kernel = gt_kernels[:, -1, :, :] - pred_kernel = torch.sigmoid(kernel).data.cpu().numpy() - pred_kernel[pred_kernel <= 0.5] = 0 - pred_kernel[pred_kernel > 0.5] = 1 - pred_kernel = (pred_kernel * mask).astype(np.int32) - gt_kernel = gt_kernel.data.cpu().numpy() - gt_kernel = (gt_kernel * mask).astype(np.int32) - running_metric_kernel.update(gt_kernel, pred_kernel) - score_kernel, _ = running_metric_kernel.get_scores() - return score_kernel - - -def train(train_loader, model, criterion, optimizer, epoch, args, npu_per_node): - model.train() - - losses = AverageMeter() - running_metric_text = runningScore(2) - running_metric_kernel = runningScore(2) - - epoch_time = time.time() - batch_time = time.time() - for batch_idx, (imgs, gt_texts, gt_kernels, training_masks) in enumerate(train_loader): - loc = 'npu:{}'.format(args.npu) - imgs = imgs.to(loc, non_blocking=True) - gt_texts = gt_texts.to(loc, non_blocking=True) - gt_kernels = gt_kernels.to(loc, non_blocking=True) - training_masks = training_masks.to(loc, non_blocking=True) - - outputs = model(imgs) - texts = torch.index_select(outputs, 1, torch.tensor([0]).to(loc)).squeeze() - kernels = torch.index_select(outputs, 1, torch.tensor([1, 2, 3, 4, 5, 6]).to(loc)) - - selected_masks = ohem_batch(texts, gt_texts, training_masks) - selected_masks = selected_masks.to(loc, non_blocking=True) - - loss_text = criterion(texts, gt_texts, selected_masks) - - loss_kernels = [] - mask0 = torch.sigmoid(texts).data.cpu().numpy() - mask1 = training_masks.data.cpu().numpy() - selected_masks = ((mask0 > 0.5) & (mask1 > 0.5)).astype('float32') - selected_masks = torch.from_numpy(selected_masks).float() - selected_masks = selected_masks.to(loc, non_blocking=True) - for i in range(6): - kernel_i = torch.index_select(kernels, 1, torch.tensor([i]).to(loc)).squeeze() - gt_kernel_i = torch.index_select(gt_kernels, 1, torch.tensor([i]).to(loc)).squeeze() - loss_kernel_i = criterion(kernel_i, gt_kernel_i, selected_masks) - loss_kernels.append(loss_kernel_i) - loss_kernel = sum(loss_kernels) / len(loss_kernels) - - loss = 0.7 * loss_text + 0.3 * loss_kernel - losses.update(loss.item(), imgs.size(0)) - - optimizer.zero_grad() - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - optimizer.step() - score_text = cal_text_score(texts, gt_texts, training_masks, running_metric_text) - score_kernel = cal_kernel_score(kernels, gt_kernels, gt_texts, training_masks, running_metric_kernel) - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % npu_per_node == 0): - batch_time = time.time() - batch_time - output_log = '(epoch: {epoch:0>3d} {batch:0>2d}/{size}) | FPS: {fps:5.3f} | Loss : {lossv:.4f} | Acc_t: {acc: .4f} | IOU_t: {iou_t: .4f} | IOU_k: {iou_k: .4f}'.format( - epoch=epoch + 1, - batch=batch_idx + 1, - size=len(train_loader), - fps=npu_per_node * args.batch_size / batch_time, - lossv=losses.val, - acc=score_text['Mean Acc'], - iou_t=score_text['Mean IoU'], - iou_k=score_kernel['Mean IoU']) - batch_time = time.time() - print(output_log) - epoch_time = time.time() - epoch_time - - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % npu_per_node == 0): - output_log = '{epoch:0>3d}/{n_epoch} | LR: {lr:.5f} | FPS: {fps:5.3f} | batch: {batch:.5f}s | Loss: {lossa:.4f} | Acc_t: {acc: .4f} | IOU_t: {iou_t: .4f} | IOU_k: {iou_k: .4f}'.format( - epoch=epoch + 1, - n_epoch=args.n_epoch, - lr=optimizer.param_groups[0]['lr'], - fps=npu_per_node * len(train_loader) * args.batch_size / epoch_time, - batch=epoch_time / len(train_loader), - lossa=losses.avg, - acc=score_text['Mean Acc'], - iou_t=score_text['Mean IoU'], - iou_k=score_kernel['Mean IoU']) - print(output_log) - sys.stdout.flush() - - return ( - losses.avg, score_text['Mean Acc'], score_kernel['Mean Acc'], score_text['Mean IoU'], score_kernel['Mean IoU']) - - -def adjust_learning_rate(args, optimizer, epoch): - global state - if epoch in args.schedule: - args.lr = args.lr * 0.1 - for param_group in optimizer.param_groups: - param_group['lr'] = args.lr - - -def save_checkpoint(state, checkpoint='checkpoint', filename='checkpoint.pth.tar'): - if not os.path.isdir(checkpoint): - os.makedirs(checkpoint) - filepath = os.path.join(checkpoint, filename) - torch.save(state, filepath) - - -def main(npu, npu_per_node, args): - args.npu = args.process_device_map[npu] - print("[npu id:", args.npu, "]", "+++++++++++++++++++++++++++ before set KERNEL_NAME_ID:", - os.environ['KERNEL_NAME_ID']) - os.environ['KERNEL_NAME_ID'] = str(npu) - print("[npu id:", args.npu, "]", "+++++++++++++++++++++++++++KERNEL_NAME_ID:", os.environ['KERNEL_NAME_ID']) - - if args.npu is not None: - print("[npu id:", args.npu, "]", "Use NPU: {} for training".format(args.npu)) - - if args.checkpoint == '': - args.checkpoint = "checkpoints/ic15_%s_bs_%d_ep_%d" % (args.arch, args.batch_size, args.n_epoch) - if args.pretrain: - if 'synth' in args.pretrain: - args.checkpoint += "_pretrain_synth" - else: - args.checkpoint += "_pretrain_ic17" - if args.distributed: - if args.multiprocessing_distributed: - args.rank = args.rank * npu_per_node + npu - if args.device == 'npu': - dist.init_process_group(backend=args.dist_backend, - world_size=args.world_size, rank=args.rank) - loc = 'npu:{}'.format(args.npu) - torch.npu.set_device(loc) - args.batch_size = int(args.batch_size / npu_per_node) - args.workers = int((args.workers + npu_per_node - 1) / npu_per_node) - - print("[npu id:", args.npu, "]", "===============main_worker()=================") - print("[npu id:", args.npu, "]", args) - print("[npu id:", args.npu, "]", "===============main_worker()=================") - - print('checkpoint path: %s' % args.checkpoint) - print('init lr: %.8f' % args.lr) - print('schedule: ', args.schedule) - sys.stdout.flush() - - if not os.path.isdir(args.checkpoint): - os.makedirs(args.checkpoint) - - kernel_num = 7 - min_scale = 0.4 - start_epoch = 0 - - my_data = IC15Loader(args=args, - is_transform=True, - img_size=args.img_size, - kernel_num=kernel_num, - min_scale=min_scale) - if args.distributed: - train_sampler = torch.utils.data.distributed.DistributedSampler(my_data) - else: - train_sampler = None - - train_loader = MultiEpochsDataLoader( - my_data, - batch_size=args.batch_size, - shuffle=(train_sampler is None), - num_workers=args.workers, - drop_last=True, - pin_memory=True, - sampler=train_sampler) - - print("[npu id:", args.npu, "]", "=> creating model '{}'".format(args.arch)) - if args.arch == "resnet50": - model = models.resnet50(pretrained=True, num_classes=kernel_num) - elif args.arch == "resnet101": - model = models.resnet101(pretrained=True, num_classes=kernel_num) - elif args.arch == "resnet152": - model = models.resnet152(pretrained=True, num_classes=kernel_num) - - model = model.to(loc) - - if args.combine_sgd: - optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), lr=args.lr, momentum=0.99, weight_decay=5e-4) - else: - optimizer = torch.optim.SGD(model.parameters(), lr=args.lr, momentum=0.99, weight_decay=5e-4) - - model, optimizer = amp.initialize(model, optimizer, - opt_level=args.opt_level, - keep_batchnorm_fp32=args.keep_batchnorm_fp32, - loss_scale=args.loss_scale, - combine_grad=args.combine_grad) - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.npu], broadcast_buffers=False) - - if args.pretrain: - print('Using pretrained model.') - assert os.path.isfile(args.pretrain), 'Error: no checkpoint directory found!' - checkpoint = torch.load(args.pretrain) - model.load_state_dict(checkpoint['state_dict']) - elif args.resume: - print('Resuming from checkpoint.') - assert os.path.isfile(args.resume), 'Error: no checkpoint directory found!' - checkpoint = torch.load(args.resume) - start_epoch = checkpoint['epoch'] - model.load_state_dict(checkpoint['state_dict']) - optimizer.load_state_dict(checkpoint['optimizer']) - amp.load_state_dict(checkpoint['amp']) - else: - print('Training from scratch.') - cudnn.benchmark = True - - best_model = {'loss': 0, 'acc': 0, 'iou': 0} - - for epoch in range(start_epoch, args.n_epoch): - if args.distributed: - train_sampler.set_epoch(epoch) - adjust_learning_rate(args, optimizer, epoch) - - train_loss, train_te_acc, train_ke_acc, train_te_iou, train_ke_iou = train(train_loader, model, dice_loss, - optimizer, epoch, - args, npu_per_node) - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % npu_per_node == 0): - if epoch > args.n_epoch - 6: - best_path = f'{args.remark}_{train_loss:.4f}_{train_te_acc:.4f}_{train_ke_iou:.4f}_{train_te_iou:.4f}_{epoch}.pth.tar' - save_checkpoint({ - 'epoch': epoch + 1, - 'state_dict': model.state_dict(), - 'lr': args.lr, - 'optimizer': optimizer.state_dict(), - 'amp': amp.state_dict(), - }, checkpoint='best', filename=best_path) - best_model['acc'] = train_te_acc - best_model['iou'] = train_te_iou - - -def device_id_to_process_device_map(device_list): - devices = device_list.split(",") - devices = [int(x) for x in devices] - devices.sort() - - process_device_map = dict() - for process_id, device_id in enumerate(devices): - process_device_map[process_id] = device_id - - return process_device_map - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Hyperparams') - parser.add_argument('--data-dir', nargs='?', type=str, default='PSENet_data', - help='point to the root data path of ICDAR') - parser.add_argument('--train_data', nargs='?', type=str, default='ICDAR2015', - help='indicate which dataset was used, ICDAR2015 or ICDAR2017') - parser.add_argument('--arch', nargs='?', type=str, default='resnet50') - parser.add_argument('--img_size', nargs='?', type=int, default=640, - help='Height of the input image') - parser.add_argument('--n_epoch', nargs='?', type=int, default=600, - help='# of the epochs') - parser.add_argument('--schedule', type=int, nargs='+', default=[200, 400], - help='Decrease learning rate at these epochs.') - parser.add_argument('--batch_size', nargs='?', type=int, default=16, - help='Batch Size') - parser.add_argument('--lr', nargs='?', type=float, default=1e-3, - help='Learning Rate') - parser.add_argument('--resume', nargs='?', type=str, default=None, - help='Path to previous saved model to restart from') - parser.add_argument('--pretrain', nargs='?', type=str, default=None, - help='Path to previous saved model to restart from') - parser.add_argument('--checkpoint', default='', type=str, metavar='PATH', - help='path to save checkpoint (default: checkpoint)') - parser.add_argument('--opt-level', type=str) - parser.add_argument('--keep-batchnorm-fp32', type=str, default=None) - parser.add_argument('--loss-scale', type=str, default=64) - parser.add_argument('--world-size', default=-1, type=int, - help='number of nodes for distributed training') - parser.add_argument('--seed', default=None, type=int, - help='seed for initializing training. ') - parser.add_argument('--device-list', default='0,1,2,3,4,5,6,7', type=str, help='device id list') - parser.add_argument('--multiprocessing-distributed', action='store_true', - help='Use multi-processing distributed training to launch ' - 'N processes per node, which has N NPUs. This is the ' - 'fastest way to use PyTorch for either single node or ' - 'multi node data parallel training') - parser.add_argument('--device', default='npu', type=str, - help='npu or gpu') - parser.add_argument('--dist-backend', default='nccl', type=str, - help='distributed backend') - parser.add_argument('--rank', default=-1, type=int, - help='node rank for distributed training') - parser.add_argument('--addr', default='10.136.181.127', type=str, - help='master addr') - parser.add_argument('--dist-url', default='env://', type=str, - help='url used to set up distributed training') - parser.add_argument('--port', default='8888', type=str) - parser.add_argument('-j', '--workers', default=32, type=int, metavar='N', - help='number of data loading workers (default: 4)') - parser.add_argument('--remark', default='', type=str, - help='remark. ') - parser.add_argument('--combine_grad', action='store_true', - help='whether to combine grad in apex') - parser.add_argument('--combine_sgd', action='store_true', - help='whether to use combined sgd instead of sgd') - - args = parser.parse_args() - - - if args.seed is not None: - random.seed(args.seed) - os.environ['PYTHONHASHSEED'] = str(args.seed) - np.random.seed(args.seed) - torch.manual_seed(args.seed) - torch.cuda.manual_seed(args.seed) - torch.cuda.manual_seed_all(args.seed) - cudnn.deterministic = True - torch.backends.cudnn.deterministic = True - torch.backends.cudnn.benchmark = False - - - args.distributed = args.world_size > 1 or args.multiprocessing_distributed - args.process_device_map = device_id_to_process_device_map(args.device_list) - - if args.device == 'npu': - npu_per_node = len(args.process_device_map) - else: - npu_per_node = torch.cuda.device_count() - - os.environ['MASTER_ADDR'] = args.addr - os.environ['MASTER_PORT'] = args.port - os.environ['KERNEL_NAME_ID'] = str(0) - print("+++++++++++++++++++++KERNEL_NAME_ID:", os.environ['KERNEL_NAME_ID']) - - args.world_size = npu_per_node * args.world_size - mp.spawn(main, nprocs=npu_per_node, args=(npu_per_node, args)) - +# Copyright [yyyy] [name of copyright owner] +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import argparse +import os +import random +import sys +import time +import warnings + +import numpy as np +import torch +import torch.backends.cudnn as cudnn +import torch.distributed as dist +import torch.multiprocessing as mp +import torch.nn.parallel +import torch.npu +import torch.utils.data.distributed +from apex import amp + +import apex +import models +from data_loader import IC15Loader +from metrics import runningScore +from multi_epochs_dataloader import MultiEpochsDataLoader +from util import AverageMeter + + + +def ohem_single(score, gt_text, training_mask): + pos_num = (int)(np.sum(gt_text > 0.5)) - (int)(np.sum((gt_text > 0.5) & (training_mask <= 0.5))) + + if pos_num == 0: + selected_mask = training_mask + selected_mask = selected_mask.reshape(1, selected_mask.shape[0], selected_mask.shape[1]).astype('float32') + return selected_mask + + neg_num = (int)(np.sum(gt_text <= 0.5)) + neg_num = (int)(min(pos_num * 3, neg_num)) + + if neg_num == 0: + selected_mask = training_mask + selected_mask = selected_mask.reshape(1, selected_mask.shape[0], selected_mask.shape[1]).astype('float32') + return selected_mask + + neg_score = score[gt_text <= 0.5] + neg_score_sorted = np.sort(-neg_score) + threshold = -neg_score_sorted[neg_num - 1] + + selected_mask = ((score >= threshold) | (gt_text > 0.5)) & (training_mask > 0.5) + selected_mask = selected_mask.reshape(1, selected_mask.shape[0], selected_mask.shape[1]).astype('float32') + return selected_mask + + +def ohem_batch(scores, gt_texts, training_masks): + scores = scores.data.cpu().numpy() + gt_texts = gt_texts.data.cpu().numpy() + training_masks = training_masks.data.cpu().numpy() + selected_masks = [] + for i in range(scores.shape[0]): + selected_masks.append(ohem_single(scores[i, :, :], gt_texts[i, :, :], training_masks[i, :, :])) + selected_masks = np.concatenate(selected_masks, 0) + selected_masks = torch.from_numpy(selected_masks).float() + return selected_masks + + +def dice_loss(input, target, mask): + input = torch.sigmoid(input) + + input = input.reshape(input.size()[0], -1) + target = target.reshape(target.size()[0], -1) + mask = mask.reshape(mask.size()[0], -1) + + input = input * mask + target = target * mask + + a = torch.sum(input * target, 1) + b = torch.sum(input * input, 1) + 0.001 + c = torch.sum(target * target, 1) + 0.001 + d = (2 * a) / (b + c) + dice_loss = torch.mean(d) + return 1 - dice_loss + + +def cal_text_score(texts, gt_texts, training_masks, running_metric_text): + training_masks = training_masks.data.cpu().numpy() + pred_text = torch.sigmoid(texts).data.cpu().numpy() * training_masks + + pred_text[pred_text <= 0.5] = 0 + pred_text[pred_text > 0.5] = 1 + pred_text = pred_text.astype(np.int32) + gt_text = gt_texts.data.cpu().numpy() * training_masks + gt_text = gt_text.astype(np.int32) + running_metric_text.update(gt_text, pred_text) + score_text, _ = running_metric_text.get_scores() + return score_text + + +def cal_kernel_score(kernels, gt_kernels, gt_texts, training_masks, running_metric_kernel): + mask = (gt_texts * training_masks).data.cpu().numpy() + kernel = kernels[:, -1, :, :] + gt_kernel = gt_kernels[:, -1, :, :] + pred_kernel = torch.sigmoid(kernel).data.cpu().numpy() + pred_kernel[pred_kernel <= 0.5] = 0 + pred_kernel[pred_kernel > 0.5] = 1 + pred_kernel = (pred_kernel * mask).astype(np.int32) + gt_kernel = gt_kernel.data.cpu().numpy() + gt_kernel = (gt_kernel * mask).astype(np.int32) + running_metric_kernel.update(gt_kernel, pred_kernel) + score_kernel, _ = running_metric_kernel.get_scores() + return score_kernel + + +def train(train_loader, model, criterion, optimizer, epoch, args, npu_per_node): + model.train() + + losses = AverageMeter() + running_metric_text = runningScore(2) + running_metric_kernel = runningScore(2) + + epoch_time = time.time() + batch_time = time.time() + for batch_idx, (imgs, gt_texts, gt_kernels, training_masks) in enumerate(train_loader): + loc = 'npu:{}'.format(args.npu) + imgs = imgs.to(loc, non_blocking=True) + gt_texts = gt_texts.to(loc, non_blocking=True) + gt_kernels = gt_kernels.to(loc, non_blocking=True) + training_masks = training_masks.to(loc, non_blocking=True) + + outputs = model(imgs) + texts = torch.index_select(outputs, 1, torch.tensor([0]).to(loc)).squeeze() + kernels = torch.index_select(outputs, 1, torch.tensor([1, 2, 3, 4, 5, 6]).to(loc)) + + selected_masks = ohem_batch(texts, gt_texts, training_masks) + selected_masks = selected_masks.to(loc, non_blocking=True) + + loss_text = criterion(texts, gt_texts, selected_masks) + + loss_kernels = [] + mask0 = torch.sigmoid(texts).data.cpu().numpy() + mask1 = training_masks.data.cpu().numpy() + selected_masks = ((mask0 > 0.5) & (mask1 > 0.5)).astype('float32') + selected_masks = torch.from_numpy(selected_masks).float() + selected_masks = selected_masks.to(loc, non_blocking=True) + for i in range(6): + kernel_i = torch.index_select(kernels, 1, torch.tensor([i]).to(loc)).squeeze() + gt_kernel_i = torch.index_select(gt_kernels, 1, torch.tensor([i]).to(loc)).squeeze() + loss_kernel_i = criterion(kernel_i, gt_kernel_i, selected_masks) + loss_kernels.append(loss_kernel_i) + loss_kernel = sum(loss_kernels) / len(loss_kernels) + + loss = 0.7 * loss_text + 0.3 * loss_kernel + losses.update(loss.item(), imgs.size(0)) + + optimizer.zero_grad() + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + optimizer.step() + score_text = cal_text_score(texts, gt_texts, training_masks, running_metric_text) + score_kernel = cal_kernel_score(kernels, gt_kernels, gt_texts, training_masks, running_metric_kernel) + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % npu_per_node == 0): + batch_time = time.time() - batch_time + output_log = '(epoch: {epoch:0>3d} {batch:0>2d}/{size}) | FPS: {fps:5.3f} | Loss : {lossv:.4f} | Acc_t: {acc: .4f} | IOU_t: {iou_t: .4f} | IOU_k: {iou_k: .4f}'.format( + epoch=epoch + 1, + batch=batch_idx + 1, + size=len(train_loader), + fps=npu_per_node * args.batch_size / batch_time, + lossv=losses.val, + acc=score_text['Mean Acc'], + iou_t=score_text['Mean IoU'], + iou_k=score_kernel['Mean IoU']) + batch_time = time.time() + print(output_log) + epoch_time = time.time() - epoch_time + + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % npu_per_node == 0): + output_log = '{epoch:0>3d}/{n_epoch} | LR: {lr:.5f} | FPS: {fps:5.3f} | batch: {batch:.5f}s | Loss: {lossa:.4f} | Acc_t: {acc: .4f} | IOU_t: {iou_t: .4f} | IOU_k: {iou_k: .4f}'.format( + epoch=epoch + 1, + n_epoch=args.n_epoch, + lr=optimizer.param_groups[0]['lr'], + fps=npu_per_node * len(train_loader) * args.batch_size / epoch_time, + batch=epoch_time / len(train_loader), + lossa=losses.avg, + acc=score_text['Mean Acc'], + iou_t=score_text['Mean IoU'], + iou_k=score_kernel['Mean IoU']) + print(output_log) + sys.stdout.flush() + + return ( + losses.avg, score_text['Mean Acc'], score_kernel['Mean Acc'], score_text['Mean IoU'], score_kernel['Mean IoU']) + + +def adjust_learning_rate(args, optimizer, epoch): + global state + if epoch in args.schedule: + args.lr = args.lr * 0.1 + for param_group in optimizer.param_groups: + param_group['lr'] = args.lr + + +def save_checkpoint(state, checkpoint='checkpoint', filename='checkpoint.pth.tar'): + if not os.path.isdir(checkpoint): + os.makedirs(checkpoint) + filepath = os.path.join(checkpoint, filename) + torch.save(state, filepath) + + +def main(npu, npu_per_node, args): + args.npu = args.process_device_map[npu] + print("[npu id:", args.npu, "]", "+++++++++++++++++++++++++++ before set KERNEL_NAME_ID:", + os.environ['KERNEL_NAME_ID']) + os.environ['KERNEL_NAME_ID'] = str(npu) + print("[npu id:", args.npu, "]", "+++++++++++++++++++++++++++KERNEL_NAME_ID:", os.environ['KERNEL_NAME_ID']) + + if args.npu is not None: + print("[npu id:", args.npu, "]", "Use NPU: {} for training".format(args.npu)) + + if args.checkpoint == '': + args.checkpoint = "checkpoints/ic15_%s_bs_%d_ep_%d" % (args.arch, args.batch_size, args.n_epoch) + if args.pretrain: + if 'synth' in args.pretrain: + args.checkpoint += "_pretrain_synth" + else: + args.checkpoint += "_pretrain_ic17" + if args.distributed: + if args.multiprocessing_distributed: + args.rank = args.rank * npu_per_node + npu + if args.device == 'npu': + dist.init_process_group(backend=args.dist_backend, + world_size=args.world_size, rank=args.rank) + loc = 'npu:{}'.format(args.npu) + torch.npu.set_device(loc) + args.batch_size = int(args.batch_size / npu_per_node) + args.workers = int((args.workers + npu_per_node - 1) / npu_per_node) + + print("[npu id:", args.npu, "]", "===============main_worker()=================") + print("[npu id:", args.npu, "]", args) + print("[npu id:", args.npu, "]", "===============main_worker()=================") + + print('checkpoint path: %s' % args.checkpoint) + print('init lr: %.8f' % args.lr) + print('schedule: ', args.schedule) + sys.stdout.flush() + + if not os.path.isdir(args.checkpoint): + os.makedirs(args.checkpoint) + + kernel_num = 7 + min_scale = 0.4 + start_epoch = 0 + + my_data = IC15Loader(args=args, + is_transform=True, + img_size=args.img_size, + kernel_num=kernel_num, + min_scale=min_scale) + if args.distributed: + train_sampler = torch.utils.data.distributed.DistributedSampler(my_data) + else: + train_sampler = None + + train_loader = MultiEpochsDataLoader( + my_data, + batch_size=args.batch_size, + shuffle=(train_sampler is None), + num_workers=args.workers, + drop_last=True, + pin_memory=True, + sampler=train_sampler) + + print("[npu id:", args.npu, "]", "=> creating model '{}'".format(args.arch)) + if args.arch == "resnet50": + model = models.resnet50(pretrained=True, num_classes=kernel_num) + elif args.arch == "resnet101": + model = models.resnet101(pretrained=True, num_classes=kernel_num) + elif args.arch == "resnet152": + model = models.resnet152(pretrained=True, num_classes=kernel_num) + + model = model.to(loc) + + if args.combine_sgd: + optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), lr=args.lr, momentum=0.99, weight_decay=5e-4) + else: + optimizer = torch.optim.SGD(model.parameters(), lr=args.lr, momentum=0.99, weight_decay=5e-4) + + model, optimizer = amp.initialize(model, optimizer, + opt_level=args.opt_level, + keep_batchnorm_fp32=args.keep_batchnorm_fp32, + loss_scale=args.loss_scale, + combine_grad=args.combine_grad) + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.npu], broadcast_buffers=False) + + if args.pretrain: + print('Using pretrained model.') + assert os.path.isfile(args.pretrain), 'Error: no checkpoint directory found!' + checkpoint = torch.load(args.pretrain) + model.load_state_dict(checkpoint['state_dict']) + elif args.resume: + print('Resuming from checkpoint.') + assert os.path.isfile(args.resume), 'Error: no checkpoint directory found!' + checkpoint = torch.load(args.resume) + start_epoch = checkpoint['epoch'] + model.load_state_dict(checkpoint['state_dict']) + optimizer.load_state_dict(checkpoint['optimizer']) + amp.load_state_dict(checkpoint['amp']) + else: + print('Training from scratch.') + cudnn.benchmark = True + + best_model = {'loss': 0, 'acc': 0, 'iou': 0} + + for epoch in range(start_epoch, args.n_epoch): + if args.distributed: + train_sampler.set_epoch(epoch) + adjust_learning_rate(args, optimizer, epoch) + + train_loss, train_te_acc, train_ke_acc, train_te_iou, train_ke_iou = train(train_loader, model, dice_loss, + optimizer, epoch, + args, npu_per_node) + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % npu_per_node == 0): + if epoch > args.n_epoch - 6: + best_path = f'{args.remark}_{train_loss:.4f}_{train_te_acc:.4f}_{train_ke_iou:.4f}_{train_te_iou:.4f}_{epoch}.pth.tar' + save_checkpoint({ + 'epoch': epoch + 1, + 'state_dict': model.state_dict(), + 'lr': args.lr, + 'optimizer': optimizer.state_dict(), + 'amp': amp.state_dict(), + }, checkpoint='best', filename=best_path) + best_model['acc'] = train_te_acc + best_model['iou'] = train_te_iou + + +def device_id_to_process_device_map(device_list): + devices = device_list.split(",") + devices = [int(x) for x in devices] + devices.sort() + + process_device_map = dict() + for process_id, device_id in enumerate(devices): + process_device_map[process_id] = device_id + + return process_device_map + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Hyperparams') + parser.add_argument('--data-dir', nargs='?', type=str, default='PSENet_data', + help='point to the root data path of ICDAR') + parser.add_argument('--train_data', nargs='?', type=str, default='ICDAR2015', + help='indicate which dataset was used, ICDAR2015 or ICDAR2017') + parser.add_argument('--arch', nargs='?', type=str, default='resnet50') + parser.add_argument('--img_size', nargs='?', type=int, default=640, + help='Height of the input image') + parser.add_argument('--n_epoch', nargs='?', type=int, default=600, + help='# of the epochs') + parser.add_argument('--schedule', type=int, nargs='+', default=[200, 400], + help='Decrease learning rate at these epochs.') + parser.add_argument('--batch_size', nargs='?', type=int, default=16, + help='Batch Size') + parser.add_argument('--lr', nargs='?', type=float, default=1e-3, + help='Learning Rate') + parser.add_argument('--resume', nargs='?', type=str, default=None, + help='Path to previous saved model to restart from') + parser.add_argument('--pretrain', nargs='?', type=str, default=None, + help='Path to previous saved model to restart from') + parser.add_argument('--checkpoint', default='', type=str, metavar='PATH', + help='path to save checkpoint (default: checkpoint)') + parser.add_argument('--opt-level', type=str) + parser.add_argument('--keep-batchnorm-fp32', type=str, default=None) + parser.add_argument('--loss-scale', type=str, default=64) + parser.add_argument('--world-size', default=-1, type=int, + help='number of nodes for distributed training') + parser.add_argument('--seed', default=None, type=int, + help='seed for initializing training. ') + parser.add_argument('--device-list', default='0,1,2,3,4,5,6,7', type=str, help='device id list') + parser.add_argument('--multiprocessing-distributed', action='store_true', + help='Use multi-processing distributed training to launch ' + 'N processes per node, which has N NPUs. This is the ' + 'fastest way to use PyTorch for either single node or ' + 'multi node data parallel training') + parser.add_argument('--device', default='npu', type=str, + help='npu or gpu') + parser.add_argument('--dist-backend', default='nccl', type=str, + help='distributed backend') + parser.add_argument('--rank', default=-1, type=int, + help='node rank for distributed training') + parser.add_argument('--addr', default='10.136.181.127', type=str, + help='master addr') + parser.add_argument('--dist-url', default='env://', type=str, + help='url used to set up distributed training') + parser.add_argument('--port', default='8888', type=str) + parser.add_argument('-j', '--workers', default=32, type=int, metavar='N', + help='number of data loading workers (default: 4)') + parser.add_argument('--remark', default='', type=str, + help='remark. ') + parser.add_argument('--combine_grad', action='store_true', + help='whether to combine grad in apex') + parser.add_argument('--combine_sgd', action='store_true', + help='whether to use combined sgd instead of sgd') + + args = parser.parse_args() + + + if args.seed is not None: + random.seed(args.seed) + os.environ['PYTHONHASHSEED'] = str(args.seed) + np.random.seed(args.seed) + torch.manual_seed(args.seed) + torch.cuda.manual_seed(args.seed) + torch.cuda.manual_seed_all(args.seed) + cudnn.deterministic = True + torch.backends.cudnn.deterministic = True + torch.backends.cudnn.benchmark = False + + + args.distributed = args.world_size > 1 or args.multiprocessing_distributed + args.process_device_map = device_id_to_process_device_map(args.device_list) + + if args.device == 'npu': + npu_per_node = len(args.process_device_map) + else: + npu_per_node = torch.cuda.device_count() + + os.environ['MASTER_ADDR'] = args.addr + os.environ['MASTER_PORT'] = args.port + os.environ['KERNEL_NAME_ID'] = str(0) + print("+++++++++++++++++++++KERNEL_NAME_ID:", os.environ['KERNEL_NAME_ID']) + + args.world_size = npu_per_node * args.world_size + mp.spawn(main, nprocs=npu_per_node, args=(npu_per_node, args)) + diff --git a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/train_ic15_8p.py b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/train_ic15_8p.py index 6b06a15d3da577854a5b998e1fb8ac61a4a0a914..1904aae875570055ae0f7c945e9aeb40bf512401 100644 --- a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/train_ic15_8p.py +++ b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/NPU/src/train_ic15_8p.py @@ -1,453 +1,453 @@ -# Copyright [yyyy] [name of copyright owner] -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import argparse -import os -import random -import sys -import time -import warnings - -import numpy as np -import torch -import torch.backends.cudnn as cudnn -import torch.distributed as dist -import torch.multiprocessing as mp -import torch.nn.parallel -import torch.npu -import torch.utils.data.distributed -from apex import amp - -import apex -import models -from data_loader import IC15Loader -from metrics import runningScore -from multi_epochs_dataloader import MultiEpochsDataLoader -from util import AverageMeter - - - -def ohem_single(score, gt_text, training_mask): - pos_num = (int)(np.sum(gt_text > 0.5)) - (int)(np.sum((gt_text > 0.5) & (training_mask <= 0.5))) - - if pos_num == 0: - selected_mask = training_mask - selected_mask = selected_mask.reshape(1, selected_mask.shape[0], selected_mask.shape[1]).astype('float32') - return selected_mask - - neg_num = (int)(np.sum(gt_text <= 0.5)) - neg_num = (int)(min(pos_num * 3, neg_num)) - - if neg_num == 0: - selected_mask = training_mask - selected_mask = selected_mask.reshape(1, selected_mask.shape[0], selected_mask.shape[1]).astype('float32') - return selected_mask - - neg_score = score[gt_text <= 0.5] - neg_score_sorted = np.sort(-neg_score) - threshold = -neg_score_sorted[neg_num - 1] - - selected_mask = ((score >= threshold) | (gt_text > 0.5)) & (training_mask > 0.5) - selected_mask = selected_mask.reshape(1, selected_mask.shape[0], selected_mask.shape[1]).astype('float32') - return selected_mask - - -def ohem_batch(scores, gt_texts, training_masks): - scores = scores.data.cpu().numpy() - gt_texts = gt_texts.data.cpu().numpy() - training_masks = training_masks.data.cpu().numpy() - selected_masks = [] - for i in range(scores.shape[0]): - selected_masks.append(ohem_single(scores[i, :, :], gt_texts[i, :, :], training_masks[i, :, :])) - selected_masks = np.concatenate(selected_masks, 0) - selected_masks = torch.from_numpy(selected_masks).float() - return selected_masks - - -def dice_loss(input, target, mask): - input = torch.sigmoid(input) - - input = input.reshape(input.size()[0], -1) - target = target.reshape(target.size()[0], -1) - mask = mask.reshape(mask.size()[0], -1) - - input = input * mask - target = target * mask - - a = torch.sum(input * target, 1) - b = torch.sum(input * input, 1) + 0.001 - c = torch.sum(target * target, 1) + 0.001 - d = (2 * a) / (b + c) - dice_loss = torch.mean(d) - return 1 - dice_loss - - -def cal_text_score(texts, gt_texts, training_masks, running_metric_text): - training_masks = training_masks.data.cpu().numpy() - pred_text = torch.sigmoid(texts).data.cpu().numpy() * training_masks - - pred_text[pred_text <= 0.5] = 0 - pred_text[pred_text > 0.5] = 1 - pred_text = pred_text.astype(np.int32) - gt_text = gt_texts.data.cpu().numpy() * training_masks - gt_text = gt_text.astype(np.int32) - running_metric_text.update(gt_text, pred_text) - score_text, _ = running_metric_text.get_scores() - return score_text - - -def cal_kernel_score(kernels, gt_kernels, gt_texts, training_masks, running_metric_kernel): - mask = (gt_texts * training_masks).data.cpu().numpy() - kernel = kernels[:, -1, :, :] - gt_kernel = gt_kernels[:, -1, :, :] - pred_kernel = torch.sigmoid(kernel).data.cpu().numpy() - pred_kernel[pred_kernel <= 0.5] = 0 - pred_kernel[pred_kernel > 0.5] = 1 - pred_kernel = (pred_kernel * mask).astype(np.int32) - gt_kernel = gt_kernel.data.cpu().numpy() - gt_kernel = (gt_kernel * mask).astype(np.int32) - running_metric_kernel.update(gt_kernel, pred_kernel) - score_kernel, _ = running_metric_kernel.get_scores() - return score_kernel - - -def train(train_loader, model, criterion, optimizer, epoch, args, npu_per_node): - model.train() - - losses = AverageMeter() - running_metric_text = runningScore(2) - running_metric_kernel = runningScore(2) - - epoch_time = time.time() - batch_time = time.time() - for batch_idx, (imgs, gt_texts, gt_kernels, training_masks) in enumerate(train_loader): - loc = 'npu:{}'.format(args.npu) - imgs = imgs.to(loc, non_blocking=True) - gt_texts = gt_texts.to(loc, non_blocking=True) - gt_kernels = gt_kernels.to(loc, non_blocking=True) - training_masks = training_masks.to(loc, non_blocking=True) - - outputs = model(imgs) - texts = torch.index_select(outputs, 1, torch.tensor([0]).to(loc)).squeeze() - kernels = torch.index_select(outputs, 1, torch.tensor([1, 2, 3, 4, 5, 6]).to(loc)) - - selected_masks = ohem_batch(texts, gt_texts, training_masks) - selected_masks = selected_masks.to(loc, non_blocking=True) - - loss_text = criterion(texts, gt_texts, selected_masks) - - loss_kernels = [] - mask0 = torch.sigmoid(texts).data.cpu().numpy() - mask1 = training_masks.data.cpu().numpy() - selected_masks = ((mask0 > 0.5) & (mask1 > 0.5)).astype('float32') - selected_masks = torch.from_numpy(selected_masks).float() - selected_masks = selected_masks.to(loc, non_blocking=True) - for i in range(6): - kernel_i = torch.index_select(kernels, 1, torch.tensor([i]).to(loc)).squeeze() - gt_kernel_i = torch.index_select(gt_kernels, 1, torch.tensor([i]).to(loc)).squeeze() - loss_kernel_i = criterion(kernel_i, gt_kernel_i, selected_masks) - loss_kernels.append(loss_kernel_i) - loss_kernel = sum(loss_kernels) / len(loss_kernels) - - loss = 0.7 * loss_text + 0.3 * loss_kernel - losses.update(loss.item(), imgs.size(0)) - - optimizer.zero_grad() - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - optimizer.step() - score_text = cal_text_score(texts, gt_texts, training_masks, running_metric_text) - score_kernel = cal_kernel_score(kernels, gt_kernels, gt_texts, training_masks, running_metric_kernel) - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % npu_per_node == 0): - batch_time = time.time() - batch_time - output_log = '(epoch: {epoch:0>3d} {batch:0>2d}/{size}) | FPS: {fps:5.3f} | Loss : {lossv:.4f} | Acc_t: {acc: .4f} | IOU_t: {iou_t: .4f} | IOU_k: {iou_k: .4f}'.format( - epoch=epoch + 1, - batch=batch_idx + 1, - size=len(train_loader), - fps=npu_per_node * args.batch_size / batch_time, - lossv=losses.val, - acc=score_text['Mean Acc'], - iou_t=score_text['Mean IoU'], - iou_k=score_kernel['Mean IoU']) - batch_time = time.time() - print(output_log) - epoch_time = time.time() - epoch_time - - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % npu_per_node == 0): - output_log = '{epoch:0>3d}/{n_epoch} | LR: {lr:.5f} | FPS: {fps:.3f} | batch: {batch:.5f}s | Loss: {lossa:.4f} | Acc_t: {acc: .4f} | IOU_t: {iou_t: .4f} | IOU_k: {iou_k: .4f}'.format( - epoch=epoch + 1, - n_epoch=args.n_epoch, - lr=optimizer.param_groups[0]['lr'], - fps=npu_per_node * len(train_loader) * args.batch_size / epoch_time, - batch=epoch_time / len(train_loader), - lossa=losses.avg, - acc=score_text['Mean Acc'], - iou_t=score_text['Mean IoU'], - iou_k=score_kernel['Mean IoU']) - print(output_log) - sys.stdout.flush() - - return ( - losses.avg, score_text['Mean Acc'], score_kernel['Mean Acc'], score_text['Mean IoU'], score_kernel['Mean IoU']) - - -def adjust_learning_rate(args, optimizer, epoch): - warmup_length = 5 - if epoch < warmup_length: - lr = args.lr * (epoch + 1) / warmup_length - else: - e = epoch - warmup_length - es = args.n_epoch - warmup_length - lr = 0.5 * (1 + np.cos(np.pi * e / es)) * args.lr - for param_group in optimizer.param_groups: - param_group['lr'] = lr - - -def save_checkpoint(state, checkpoint='checkpoint', filename='checkpoint.pth.tar'): - if not os.path.isdir(checkpoint): - os.makedirs(checkpoint) - filepath = os.path.join(checkpoint, filename) - torch.save(state, filepath) - - -def main(npu, npu_per_node, args): - args.npu = args.process_device_map[npu] - print("[npu id:", args.npu, "]", "+++++++++++++++++++++++++++ before set KERNEL_NAME_ID:", - os.environ['KERNEL_NAME_ID']) - os.environ['KERNEL_NAME_ID'] = str(npu) - print("[npu id:", args.npu, "]", "+++++++++++++++++++++++++++KERNEL_NAME_ID:", os.environ['KERNEL_NAME_ID']) - - if args.npu is not None: - print("[npu id:", args.npu, "]", "Use NPU: {} for training".format(args.npu)) - - if args.checkpoint == '': - args.checkpoint = "checkpoints/ic15_%s_bs_%d_ep_%d" % (args.arch, args.batch_size, args.n_epoch) - if args.pretrain: - if 'synth' in args.pretrain: - args.checkpoint += "_pretrain_synth" - else: - args.checkpoint += "_pretrain_ic17" - if args.distributed: - if args.multiprocessing_distributed: - args.rank = args.rank * npu_per_node + npu - if args.device == 'npu': - dist.init_process_group(backend=args.dist_backend, - world_size=args.world_size, rank=args.rank) - loc = 'npu:{}'.format(args.npu) - torch.npu.set_device(loc) - args.batch_size = int(args.batch_size / npu_per_node) - args.workers = int((args.workers + npu_per_node - 1) / npu_per_node) - - print("[npu id:", args.npu, "]", "===============main_worker()=================") - print("[npu id:", args.npu, "]", args) - print("[npu id:", args.npu, "]", "===============main_worker()=================") - - print('checkpoint path: %s' % args.checkpoint) - print('init lr: %.8f' % args.lr) - print('schedule: ', args.schedule) - sys.stdout.flush() - - if not os.path.isdir(args.checkpoint): - os.makedirs(args.checkpoint) - - kernel_num = 7 - min_scale = 0.4 - start_epoch = 0 - - my_data = IC15Loader(args=args, - is_transform=True, - img_size=args.img_size, - kernel_num=kernel_num, - min_scale=min_scale) - if args.distributed: - train_sampler = torch.utils.data.distributed.DistributedSampler(my_data) - else: - train_sampler = None - - train_loader = MultiEpochsDataLoader( - my_data, - batch_size=args.batch_size, - shuffle=(train_sampler is None), - num_workers=args.workers, - drop_last=True, - pin_memory=True, - sampler=train_sampler) - - print("[npu id:", args.npu, "]", "=> creating model '{}'".format(args.arch)) - if args.arch == "resnet50": - model = models.resnet50(pretrained=True, num_classes=kernel_num) - elif args.arch == "resnet101": - model = models.resnet101(pretrained=True, num_classes=kernel_num) - elif args.arch == "resnet152": - model = models.resnet152(pretrained=True, num_classes=kernel_num) - - model = model.to(loc) - - if args.combine_sgd: - optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), lr=args.lr, momentum=0.99, weight_decay=5e-4) - else: - optimizer = torch.optim.SGD(model.parameters(), lr=args.lr, momentum=0.99, weight_decay=5e-4) - - model, optimizer = amp.initialize(model, optimizer, - opt_level=args.opt_level, - keep_batchnorm_fp32=args.keep_batchnorm_fp32, - loss_scale=args.loss_scale, - combine_grad=args.combine_grad) - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.npu], broadcast_buffers=False) - - if args.pretrain: - print('Using pretrained model.') - assert os.path.isfile(args.pretrain), 'Error: no checkpoint directory found!' - checkpoint = torch.load(args.pretrain) - model.load_state_dict(checkpoint['state_dict']) - elif args.resume: - print('Resuming from checkpoint.') - assert os.path.isfile(args.resume), 'Error: no checkpoint directory found!' - checkpoint = torch.load(args.resume) - start_epoch = checkpoint['epoch'] - model.load_state_dict(checkpoint['state_dict']) - optimizer.load_state_dict(checkpoint['optimizer']) - amp.load_state_dict(checkpoint['amp']) - else: - print('Training from scratch.') - cudnn.benchmark = True - - best_model = {'loss': 0, 'acc': 0, 'iou': 0} - - for epoch in range(start_epoch, args.n_epoch): - if args.distributed: - train_sampler.set_epoch(epoch) - adjust_learning_rate(args, optimizer, epoch) - - train_loss, train_te_acc, train_ke_acc, train_te_iou, train_ke_iou = train(train_loader, model, dice_loss, - optimizer, epoch, - args, npu_per_node) - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % npu_per_node == 0): - if epoch > args.n_epoch - 6: - best_path = f'{args.remark}_{train_loss:.4f}_{train_te_acc:.4f}_{train_ke_iou:.4f}_{train_te_iou:.4f}_{epoch}.pth.tar' - save_checkpoint({ - 'epoch': epoch + 1, - 'state_dict': model.state_dict(), - 'lr': args.lr, - 'optimizer': optimizer.state_dict(), - 'amp': amp.state_dict(), - }, checkpoint='best', filename=best_path) - best_model['acc'] = train_te_acc - best_model['iou'] = train_te_iou - - -def device_id_to_process_device_map(device_list): - devices = device_list.split(",") - devices = [int(x) for x in devices] - devices.sort() - - process_device_map = dict() - for process_id, device_id in enumerate(devices): - process_device_map[process_id] = device_id - - return process_device_map - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Hyperparams') - parser.add_argument('--data-dir', nargs='?', type=str, default='PSENet_data', - help='point to the root data path of ICDAR') - parser.add_argument('--train_data', nargs='?', type=str, default='ICDAR2015', - help='indicate which dataset was used, ICDAR2015 or ICDAR2017') - parser.add_argument('--arch', nargs='?', type=str, default='resnet50') - parser.add_argument('--img_size', nargs='?', type=int, default=640, - help='Height of the input image') - parser.add_argument('--n_epoch', nargs='?', type=int, default=600, - help='# of the epochs') - parser.add_argument('--schedule', type=int, nargs='+', default=[200, 400], - help='Decrease learning rate at these epochs.') - parser.add_argument('--batch_size', nargs='?', type=int, default=16, - help='Batch Size') - parser.add_argument('--lr', nargs='?', type=float, default=1e-3, - help='Learning Rate') - parser.add_argument('--resume', nargs='?', type=str, default=None, - help='Path to previous saved model to restart from') - parser.add_argument('--pretrain', nargs='?', type=str, default=None, - help='Path to previous saved model to restart from') - parser.add_argument('--checkpoint', default='', type=str, metavar='PATH', - help='path to save checkpoint (default: checkpoint)') - parser.add_argument('--opt-level', type=str) - parser.add_argument('--keep-batchnorm-fp32', type=str, default=None) - parser.add_argument('--loss-scale', type=str, default=64) - parser.add_argument('--world-size', default=-1, type=int, - help='number of nodes for distributed training') - parser.add_argument('--seed', default=None, type=int, - help='seed for initializing training. ') - parser.add_argument('--device-list', default='0,1,2,3,4,5,6,7', type=str, help='device id list') - parser.add_argument('--multiprocessing-distributed', action='store_true', - help='Use multi-processing distributed training to launch ' - 'N processes per node, which has N NPUs. This is the ' - 'fastest way to use PyTorch for either single node or ' - 'multi node data parallel training') - parser.add_argument('--device', default='npu', type=str, - help='npu or gpu') - parser.add_argument('--dist-backend', default='nccl', type=str, - help='distributed backend') - parser.add_argument('--rank', default=-1, type=int, - help='node rank for distributed training') - parser.add_argument('--addr', default='10.136.181.127', type=str, - help='master addr') - parser.add_argument('--dist-url', default='env://', type=str, - help='url used to set up distributed training') - parser.add_argument('--port', default='8888', type=str) - parser.add_argument('-j', '--workers', default=32, type=int, metavar='N', - help='number of data loading workers (default: 4)') - parser.add_argument('--remark', default='', type=str, - help='remark. ') - parser.add_argument('--combine_grad', action='store_true', - help='whether to combine grad in apex') - parser.add_argument('--combine_sgd', action='store_true', - help='whether to use combined sgd instead of sgd') - - args = parser.parse_args() - - - if args.seed is not None: - random.seed(args.seed) - os.environ['PYTHONHASHSEED'] = str(args.seed) - np.random.seed(args.seed) - torch.manual_seed(args.seed) - torch.cuda.manual_seed(args.seed) - torch.cuda.manual_seed_all(args.seed) - cudnn.deterministic = True - torch.backends.cudnn.deterministic = True - torch.backends.cudnn.benchmark = False - - - args.distributed = args.world_size > 1 or args.multiprocessing_distributed - args.process_device_map = device_id_to_process_device_map(args.device_list) - - if args.device == 'npu': - npu_per_node = len(args.process_device_map) - else: - npu_per_node = torch.cuda.device_count() - - os.environ['MASTER_ADDR'] = args.addr - os.environ['MASTER_PORT'] = args.port - os.environ['KERNEL_NAME_ID'] = str(0) - print("+++++++++++++++++++++KERNEL_NAME_ID:", os.environ['KERNEL_NAME_ID']) - - args.world_size = npu_per_node * args.world_size - mp.spawn(main, nprocs=npu_per_node, args=(npu_per_node, args)) - +# Copyright [yyyy] [name of copyright owner] +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import argparse +import os +import random +import sys +import time +import warnings + +import numpy as np +import torch +import torch.backends.cudnn as cudnn +import torch.distributed as dist +import torch.multiprocessing as mp +import torch.nn.parallel +import torch.npu +import torch.utils.data.distributed +from apex import amp + +import apex +import models +from data_loader import IC15Loader +from metrics import runningScore +from multi_epochs_dataloader import MultiEpochsDataLoader +from util import AverageMeter + + + +def ohem_single(score, gt_text, training_mask): + pos_num = (int)(np.sum(gt_text > 0.5)) - (int)(np.sum((gt_text > 0.5) & (training_mask <= 0.5))) + + if pos_num == 0: + selected_mask = training_mask + selected_mask = selected_mask.reshape(1, selected_mask.shape[0], selected_mask.shape[1]).astype('float32') + return selected_mask + + neg_num = (int)(np.sum(gt_text <= 0.5)) + neg_num = (int)(min(pos_num * 3, neg_num)) + + if neg_num == 0: + selected_mask = training_mask + selected_mask = selected_mask.reshape(1, selected_mask.shape[0], selected_mask.shape[1]).astype('float32') + return selected_mask + + neg_score = score[gt_text <= 0.5] + neg_score_sorted = np.sort(-neg_score) + threshold = -neg_score_sorted[neg_num - 1] + + selected_mask = ((score >= threshold) | (gt_text > 0.5)) & (training_mask > 0.5) + selected_mask = selected_mask.reshape(1, selected_mask.shape[0], selected_mask.shape[1]).astype('float32') + return selected_mask + + +def ohem_batch(scores, gt_texts, training_masks): + scores = scores.data.cpu().numpy() + gt_texts = gt_texts.data.cpu().numpy() + training_masks = training_masks.data.cpu().numpy() + selected_masks = [] + for i in range(scores.shape[0]): + selected_masks.append(ohem_single(scores[i, :, :], gt_texts[i, :, :], training_masks[i, :, :])) + selected_masks = np.concatenate(selected_masks, 0) + selected_masks = torch.from_numpy(selected_masks).float() + return selected_masks + + +def dice_loss(input, target, mask): + input = torch.sigmoid(input) + + input = input.reshape(input.size()[0], -1) + target = target.reshape(target.size()[0], -1) + mask = mask.reshape(mask.size()[0], -1) + + input = input * mask + target = target * mask + + a = torch.sum(input * target, 1) + b = torch.sum(input * input, 1) + 0.001 + c = torch.sum(target * target, 1) + 0.001 + d = (2 * a) / (b + c) + dice_loss = torch.mean(d) + return 1 - dice_loss + + +def cal_text_score(texts, gt_texts, training_masks, running_metric_text): + training_masks = training_masks.data.cpu().numpy() + pred_text = torch.sigmoid(texts).data.cpu().numpy() * training_masks + + pred_text[pred_text <= 0.5] = 0 + pred_text[pred_text > 0.5] = 1 + pred_text = pred_text.astype(np.int32) + gt_text = gt_texts.data.cpu().numpy() * training_masks + gt_text = gt_text.astype(np.int32) + running_metric_text.update(gt_text, pred_text) + score_text, _ = running_metric_text.get_scores() + return score_text + + +def cal_kernel_score(kernels, gt_kernels, gt_texts, training_masks, running_metric_kernel): + mask = (gt_texts * training_masks).data.cpu().numpy() + kernel = kernels[:, -1, :, :] + gt_kernel = gt_kernels[:, -1, :, :] + pred_kernel = torch.sigmoid(kernel).data.cpu().numpy() + pred_kernel[pred_kernel <= 0.5] = 0 + pred_kernel[pred_kernel > 0.5] = 1 + pred_kernel = (pred_kernel * mask).astype(np.int32) + gt_kernel = gt_kernel.data.cpu().numpy() + gt_kernel = (gt_kernel * mask).astype(np.int32) + running_metric_kernel.update(gt_kernel, pred_kernel) + score_kernel, _ = running_metric_kernel.get_scores() + return score_kernel + + +def train(train_loader, model, criterion, optimizer, epoch, args, npu_per_node): + model.train() + + losses = AverageMeter() + running_metric_text = runningScore(2) + running_metric_kernel = runningScore(2) + + epoch_time = time.time() + batch_time = time.time() + for batch_idx, (imgs, gt_texts, gt_kernels, training_masks) in enumerate(train_loader): + loc = 'npu:{}'.format(args.npu) + imgs = imgs.to(loc, non_blocking=True) + gt_texts = gt_texts.to(loc, non_blocking=True) + gt_kernels = gt_kernels.to(loc, non_blocking=True) + training_masks = training_masks.to(loc, non_blocking=True) + + outputs = model(imgs) + texts = torch.index_select(outputs, 1, torch.tensor([0]).to(loc)).squeeze() + kernels = torch.index_select(outputs, 1, torch.tensor([1, 2, 3, 4, 5, 6]).to(loc)) + + selected_masks = ohem_batch(texts, gt_texts, training_masks) + selected_masks = selected_masks.to(loc, non_blocking=True) + + loss_text = criterion(texts, gt_texts, selected_masks) + + loss_kernels = [] + mask0 = torch.sigmoid(texts).data.cpu().numpy() + mask1 = training_masks.data.cpu().numpy() + selected_masks = ((mask0 > 0.5) & (mask1 > 0.5)).astype('float32') + selected_masks = torch.from_numpy(selected_masks).float() + selected_masks = selected_masks.to(loc, non_blocking=True) + for i in range(6): + kernel_i = torch.index_select(kernels, 1, torch.tensor([i]).to(loc)).squeeze() + gt_kernel_i = torch.index_select(gt_kernels, 1, torch.tensor([i]).to(loc)).squeeze() + loss_kernel_i = criterion(kernel_i, gt_kernel_i, selected_masks) + loss_kernels.append(loss_kernel_i) + loss_kernel = sum(loss_kernels) / len(loss_kernels) + + loss = 0.7 * loss_text + 0.3 * loss_kernel + losses.update(loss.item(), imgs.size(0)) + + optimizer.zero_grad() + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + optimizer.step() + score_text = cal_text_score(texts, gt_texts, training_masks, running_metric_text) + score_kernel = cal_kernel_score(kernels, gt_kernels, gt_texts, training_masks, running_metric_kernel) + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % npu_per_node == 0): + batch_time = time.time() - batch_time + output_log = '(epoch: {epoch:0>3d} {batch:0>2d}/{size}) | FPS: {fps:5.3f} | Loss : {lossv:.4f} | Acc_t: {acc: .4f} | IOU_t: {iou_t: .4f} | IOU_k: {iou_k: .4f}'.format( + epoch=epoch + 1, + batch=batch_idx + 1, + size=len(train_loader), + fps=npu_per_node * args.batch_size / batch_time, + lossv=losses.val, + acc=score_text['Mean Acc'], + iou_t=score_text['Mean IoU'], + iou_k=score_kernel['Mean IoU']) + batch_time = time.time() + print(output_log) + epoch_time = time.time() - epoch_time + + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % npu_per_node == 0): + output_log = '{epoch:0>3d}/{n_epoch} | LR: {lr:.5f} | FPS: {fps:.3f} | batch: {batch:.5f}s | Loss: {lossa:.4f} | Acc_t: {acc: .4f} | IOU_t: {iou_t: .4f} | IOU_k: {iou_k: .4f}'.format( + epoch=epoch + 1, + n_epoch=args.n_epoch, + lr=optimizer.param_groups[0]['lr'], + fps=npu_per_node * len(train_loader) * args.batch_size / epoch_time, + batch=epoch_time / len(train_loader), + lossa=losses.avg, + acc=score_text['Mean Acc'], + iou_t=score_text['Mean IoU'], + iou_k=score_kernel['Mean IoU']) + print(output_log) + sys.stdout.flush() + + return ( + losses.avg, score_text['Mean Acc'], score_kernel['Mean Acc'], score_text['Mean IoU'], score_kernel['Mean IoU']) + + +def adjust_learning_rate(args, optimizer, epoch): + warmup_length = 5 + if epoch < warmup_length: + lr = args.lr * (epoch + 1) / warmup_length + else: + e = epoch - warmup_length + es = args.n_epoch - warmup_length + lr = 0.5 * (1 + np.cos(np.pi * e / es)) * args.lr + for param_group in optimizer.param_groups: + param_group['lr'] = lr + + +def save_checkpoint(state, checkpoint='checkpoint', filename='checkpoint.pth.tar'): + if not os.path.isdir(checkpoint): + os.makedirs(checkpoint) + filepath = os.path.join(checkpoint, filename) + torch.save(state, filepath) + + +def main(npu, npu_per_node, args): + args.npu = args.process_device_map[npu] + print("[npu id:", args.npu, "]", "+++++++++++++++++++++++++++ before set KERNEL_NAME_ID:", + os.environ['KERNEL_NAME_ID']) + os.environ['KERNEL_NAME_ID'] = str(npu) + print("[npu id:", args.npu, "]", "+++++++++++++++++++++++++++KERNEL_NAME_ID:", os.environ['KERNEL_NAME_ID']) + + if args.npu is not None: + print("[npu id:", args.npu, "]", "Use NPU: {} for training".format(args.npu)) + + if args.checkpoint == '': + args.checkpoint = "checkpoints/ic15_%s_bs_%d_ep_%d" % (args.arch, args.batch_size, args.n_epoch) + if args.pretrain: + if 'synth' in args.pretrain: + args.checkpoint += "_pretrain_synth" + else: + args.checkpoint += "_pretrain_ic17" + if args.distributed: + if args.multiprocessing_distributed: + args.rank = args.rank * npu_per_node + npu + if args.device == 'npu': + dist.init_process_group(backend=args.dist_backend, + world_size=args.world_size, rank=args.rank) + loc = 'npu:{}'.format(args.npu) + torch.npu.set_device(loc) + args.batch_size = int(args.batch_size / npu_per_node) + args.workers = int((args.workers + npu_per_node - 1) / npu_per_node) + + print("[npu id:", args.npu, "]", "===============main_worker()=================") + print("[npu id:", args.npu, "]", args) + print("[npu id:", args.npu, "]", "===============main_worker()=================") + + print('checkpoint path: %s' % args.checkpoint) + print('init lr: %.8f' % args.lr) + print('schedule: ', args.schedule) + sys.stdout.flush() + + if not os.path.isdir(args.checkpoint): + os.makedirs(args.checkpoint) + + kernel_num = 7 + min_scale = 0.4 + start_epoch = 0 + + my_data = IC15Loader(args=args, + is_transform=True, + img_size=args.img_size, + kernel_num=kernel_num, + min_scale=min_scale) + if args.distributed: + train_sampler = torch.utils.data.distributed.DistributedSampler(my_data) + else: + train_sampler = None + + train_loader = MultiEpochsDataLoader( + my_data, + batch_size=args.batch_size, + shuffle=(train_sampler is None), + num_workers=args.workers, + drop_last=True, + pin_memory=True, + sampler=train_sampler) + + print("[npu id:", args.npu, "]", "=> creating model '{}'".format(args.arch)) + if args.arch == "resnet50": + model = models.resnet50(pretrained=True, num_classes=kernel_num) + elif args.arch == "resnet101": + model = models.resnet101(pretrained=True, num_classes=kernel_num) + elif args.arch == "resnet152": + model = models.resnet152(pretrained=True, num_classes=kernel_num) + + model = model.to(loc) + + if args.combine_sgd: + optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), lr=args.lr, momentum=0.99, weight_decay=5e-4) + else: + optimizer = torch.optim.SGD(model.parameters(), lr=args.lr, momentum=0.99, weight_decay=5e-4) + + model, optimizer = amp.initialize(model, optimizer, + opt_level=args.opt_level, + keep_batchnorm_fp32=args.keep_batchnorm_fp32, + loss_scale=args.loss_scale, + combine_grad=args.combine_grad) + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.npu], broadcast_buffers=False) + + if args.pretrain: + print('Using pretrained model.') + assert os.path.isfile(args.pretrain), 'Error: no checkpoint directory found!' + checkpoint = torch.load(args.pretrain) + model.load_state_dict(checkpoint['state_dict']) + elif args.resume: + print('Resuming from checkpoint.') + assert os.path.isfile(args.resume), 'Error: no checkpoint directory found!' + checkpoint = torch.load(args.resume) + start_epoch = checkpoint['epoch'] + model.load_state_dict(checkpoint['state_dict']) + optimizer.load_state_dict(checkpoint['optimizer']) + amp.load_state_dict(checkpoint['amp']) + else: + print('Training from scratch.') + cudnn.benchmark = True + + best_model = {'loss': 0, 'acc': 0, 'iou': 0} + + for epoch in range(start_epoch, args.n_epoch): + if args.distributed: + train_sampler.set_epoch(epoch) + adjust_learning_rate(args, optimizer, epoch) + + train_loss, train_te_acc, train_ke_acc, train_te_iou, train_ke_iou = train(train_loader, model, dice_loss, + optimizer, epoch, + args, npu_per_node) + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % npu_per_node == 0): + if epoch > args.n_epoch - 6: + best_path = f'{args.remark}_{train_loss:.4f}_{train_te_acc:.4f}_{train_ke_iou:.4f}_{train_te_iou:.4f}_{epoch}.pth.tar' + save_checkpoint({ + 'epoch': epoch + 1, + 'state_dict': model.state_dict(), + 'lr': args.lr, + 'optimizer': optimizer.state_dict(), + 'amp': amp.state_dict(), + }, checkpoint='best', filename=best_path) + best_model['acc'] = train_te_acc + best_model['iou'] = train_te_iou + + +def device_id_to_process_device_map(device_list): + devices = device_list.split(",") + devices = [int(x) for x in devices] + devices.sort() + + process_device_map = dict() + for process_id, device_id in enumerate(devices): + process_device_map[process_id] = device_id + + return process_device_map + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Hyperparams') + parser.add_argument('--data-dir', nargs='?', type=str, default='PSENet_data', + help='point to the root data path of ICDAR') + parser.add_argument('--train_data', nargs='?', type=str, default='ICDAR2015', + help='indicate which dataset was used, ICDAR2015 or ICDAR2017') + parser.add_argument('--arch', nargs='?', type=str, default='resnet50') + parser.add_argument('--img_size', nargs='?', type=int, default=640, + help='Height of the input image') + parser.add_argument('--n_epoch', nargs='?', type=int, default=600, + help='# of the epochs') + parser.add_argument('--schedule', type=int, nargs='+', default=[200, 400], + help='Decrease learning rate at these epochs.') + parser.add_argument('--batch_size', nargs='?', type=int, default=16, + help='Batch Size') + parser.add_argument('--lr', nargs='?', type=float, default=1e-3, + help='Learning Rate') + parser.add_argument('--resume', nargs='?', type=str, default=None, + help='Path to previous saved model to restart from') + parser.add_argument('--pretrain', nargs='?', type=str, default=None, + help='Path to previous saved model to restart from') + parser.add_argument('--checkpoint', default='', type=str, metavar='PATH', + help='path to save checkpoint (default: checkpoint)') + parser.add_argument('--opt-level', type=str) + parser.add_argument('--keep-batchnorm-fp32', type=str, default=None) + parser.add_argument('--loss-scale', type=str, default=64) + parser.add_argument('--world-size', default=-1, type=int, + help='number of nodes for distributed training') + parser.add_argument('--seed', default=None, type=int, + help='seed for initializing training. ') + parser.add_argument('--device-list', default='0,1,2,3,4,5,6,7', type=str, help='device id list') + parser.add_argument('--multiprocessing-distributed', action='store_true', + help='Use multi-processing distributed training to launch ' + 'N processes per node, which has N NPUs. This is the ' + 'fastest way to use PyTorch for either single node or ' + 'multi node data parallel training') + parser.add_argument('--device', default='npu', type=str, + help='npu or gpu') + parser.add_argument('--dist-backend', default='nccl', type=str, + help='distributed backend') + parser.add_argument('--rank', default=-1, type=int, + help='node rank for distributed training') + parser.add_argument('--addr', default='10.136.181.127', type=str, + help='master addr') + parser.add_argument('--dist-url', default='env://', type=str, + help='url used to set up distributed training') + parser.add_argument('--port', default='8888', type=str) + parser.add_argument('-j', '--workers', default=32, type=int, metavar='N', + help='number of data loading workers (default: 4)') + parser.add_argument('--remark', default='', type=str, + help='remark. ') + parser.add_argument('--combine_grad', action='store_true', + help='whether to combine grad in apex') + parser.add_argument('--combine_sgd', action='store_true', + help='whether to use combined sgd instead of sgd') + + args = parser.parse_args() + + + if args.seed is not None: + random.seed(args.seed) + os.environ['PYTHONHASHSEED'] = str(args.seed) + np.random.seed(args.seed) + torch.manual_seed(args.seed) + torch.cuda.manual_seed(args.seed) + torch.cuda.manual_seed_all(args.seed) + cudnn.deterministic = True + torch.backends.cudnn.deterministic = True + torch.backends.cudnn.benchmark = False + + + args.distributed = args.world_size > 1 or args.multiprocessing_distributed + args.process_device_map = device_id_to_process_device_map(args.device_list) + + if args.device == 'npu': + npu_per_node = len(args.process_device_map) + else: + npu_per_node = torch.cuda.device_count() + + os.environ['MASTER_ADDR'] = args.addr + os.environ['MASTER_PORT'] = args.port + os.environ['KERNEL_NAME_ID'] = str(0) + print("+++++++++++++++++++++KERNEL_NAME_ID:", os.environ['KERNEL_NAME_ID']) + + args.world_size = npu_per_node * args.world_size + mp.spawn(main, nprocs=npu_per_node, args=(npu_per_node, args)) + diff --git a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/README.md b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/README.md index 4d75995acfa0e5fab36f3b3af67fbc6bd76b4eab..05b6553c125f67e5524f28d0428e47585388d5d3 100644 --- a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/README.md +++ b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/README.md @@ -1,22 +1,22 @@ -# Shape Robust Text Detection with Progressive Scale Expansion Network - -## 准备数据集 -1. 下载并解压训练集和测试集图片数据 -2. 按顺序对文件夹进行组织 -``` -./data_dir -./data_dir/ICDAR -./data_dir/ICDAR/Challenge -./data_dir/ICDAR/Challenge/ch4_training_images -./data_dir/ICDAR/Challenge/ch4_training_localization_transcription_gt -./data_dir/ICDAR/Challenge/ch4_test_images -./data_dir/ICDAR/Challenge/ch4_test_localization_transcription_gt -``` - - -## NPU -进入NPU/src目录,查看相关README文件 - -## 模型测试 -进入NPU/test目录,查看相关README文件 - +# Shape Robust Text Detection with Progressive Scale Expansion Network + +## 准备数据集 +1. 下载并解压训练集和测试集图片数据 +2. 按顺序对文件夹进行组织 +``` +./data_dir +./data_dir/ICDAR +./data_dir/ICDAR/Challenge +./data_dir/ICDAR/Challenge/ch4_training_images +./data_dir/ICDAR/Challenge/ch4_training_localization_transcription_gt +./data_dir/ICDAR/Challenge/ch4_test_images +./data_dir/ICDAR/Challenge/ch4_test_localization_transcription_gt +``` + + +## NPU +进入NPU/src目录,查看相关README文件 + +## 模型测试 +进入NPU/test目录,查看相关README文件 + diff --git a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_full_1p.sh b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_full_1p.sh index d6807a08111f1af72d9ac4656efb3cd957e2a852..19d0be5c36c19e9078f6901933fd019551fc6cab 100644 --- a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_full_1p.sh +++ b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_full_1p.sh @@ -1,161 +1,161 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="PSENet_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=16 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - - - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -python3 ${cur_path}/../NPU/src/train_ic15.py \ - --lr 0.001 \ - --dist-backend 'hccl' \ - --rank 0 \ - --workers 32 \ - --multiprocessing-distributed \ - --world-size 1 \ - --batch_size $batch_size \ - --device npu \ - --opt-level O2 \ - --loss-scale 64 \ - --addr=$(hostname -I |awk '{print $1}') \ - --seed 16 \ - --n_epoch $train_epochs \ - --data-dir $data_path \ - --port 8272 \ - --schedule 200 400 \ - --device-list $ASCEND_DEVICE_ID \ - --remark 1p \ - --combine_grad \ - --combine_sgd > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - - - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep 'epoch' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'FPS:' '{print $2}'|awk '{print $1}'|awk 'NR>3'|awk '{sum+=$1} END {print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep 'epoch' $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}' |awk '{print $2}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="PSENet_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=16 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + + + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $cur_path/output ];then + rm -rf $cur_path/output/* + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +fi +wait + + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +python3 ${cur_path}/../NPU/src/train_ic15.py \ + --lr 0.001 \ + --dist-backend 'hccl' \ + --rank 0 \ + --workers 32 \ + --multiprocessing-distributed \ + --world-size 1 \ + --batch_size $batch_size \ + --device npu \ + --opt-level O2 \ + --loss-scale 64 \ + --addr=$(hostname -I |awk '{print $1}') \ + --seed 16 \ + --n_epoch $train_epochs \ + --data-dir $data_path \ + --port 8272 \ + --schedule 200 400 \ + --device-list $ASCEND_DEVICE_ID \ + --remark 1p \ + --combine_grad \ + --combine_sgd > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + + + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep 'epoch' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'FPS:' '{print $2}'|awk '{print $1}'|awk 'NR>3'|awk '{sum+=$1} END {print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep 'epoch' $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}' |awk '{print $2}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_full_8p.sh b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_full_8p.sh index 28acc0d3be204ee6857fdde5d1c73223efbc4c9a..a0155a31259d012d36211b82ffd687c8b6ccd431 100644 --- a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_full_8p.sh @@ -1,159 +1,159 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 -RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="PSENet_ID0102_for_PyTorch" -#训练epoch -train_epochs=600 -#训练batch_size -batch_size=32 -#训练step -train_steps= -#学习率 -learning_rate=0.045 - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - - - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -python3 ${cur_path}/../NPU/src/train_ic15_8p.py \ - --lr 0.004 \ - --rank 0 \ - --dist-backend 'hccl' \ - --workers 32 \ - --multiprocessing-distributed \ - --world-size 1 \ - --batch_size $batch_size \ - --device npu \ - --opt-level O2 \ - --loss-scale 64 \ - --addr=$(hostname -I |awk '{print $1}') \ - --seed 16 \ - --n_epoch $train_epochs \ - --data-dir $data_path \ - --port 8272 \ - --remark 8p \ - --device-list '0,1,2,3,4,5,6,7' \ - --combine_grad \ - --combine_sgd > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - - - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep 'epoch:' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'FPS:' '{print $2}'|awk '{print $1}'|awk 'NR>3'|awk '{sum+=$1} END {print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a 'Acc_t:' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk 'END {print}'|awk -F "Acc_t:" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep 'epoch:' $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}' |awk '{print $2}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 +RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="PSENet_ID0102_for_PyTorch" +#训练epoch +train_epochs=600 +#训练batch_size +batch_size=32 +#训练step +train_steps= +#学习率 +learning_rate=0.045 + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $cur_path/output ];then + rm -rf $cur_path/output/* + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +fi +wait + + + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +python3 ${cur_path}/../NPU/src/train_ic15_8p.py \ + --lr 0.004 \ + --rank 0 \ + --dist-backend 'hccl' \ + --workers 32 \ + --multiprocessing-distributed \ + --world-size 1 \ + --batch_size $batch_size \ + --device npu \ + --opt-level O2 \ + --loss-scale 64 \ + --addr=$(hostname -I |awk '{print $1}') \ + --seed 16 \ + --n_epoch $train_epochs \ + --data-dir $data_path \ + --port 8272 \ + --remark 8p \ + --device-list '0,1,2,3,4,5,6,7' \ + --combine_grad \ + --combine_sgd > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + + + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep 'epoch:' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'FPS:' '{print $2}'|awk '{print $1}'|awk 'NR>3'|awk '{sum+=$1} END {print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a 'Acc_t:' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk 'END {print}'|awk -F "Acc_t:" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep 'epoch:' $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}' |awk '{print $2}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_performance_1p.sh b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_performance_1p.sh index 0bc1242e53dd4ea5571b7e5d7be9eafbbb9839ff..301da8cd34c14951641911560e7c13ca8a556a35 100644 --- a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_performance_1p.sh @@ -1,160 +1,160 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="PSENet_ID0102_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=16 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - - - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -python3 ${cur_path}/../NPU/src/train_ic15.py \ - --lr 0.001 \ - --dist-backend 'hccl' \ - --rank 0 \ - --workers 32 \ - --multiprocessing-distributed \ - --world-size 1 \ - --batch_size $batch_size \ - --device npu \ - --opt-level O2 \ - --loss-scale 64 \ - --addr=$(hostname -I |awk '{print $1}') \ - --seed 16 \ - --n_epoch $train_epochs \ - --data-dir $data_path \ - --port 8272 \ - --schedule 200 400 \ - --device-list $ASCEND_DEVICE_ID \ - --remark 1p \ - --combine_grad \ - --combine_sgd > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - - - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep 'epoch' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'FPS:' '{print $2}'|awk '{print $1}'|awk 'NR>3'|awk '{sum+=$1} END {print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep 'epoch' $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}' |awk '{print $2}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="PSENet_ID0102_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=16 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + + + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $cur_path/output ];then + rm -rf $cur_path/output/* + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +fi +wait + + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +python3 ${cur_path}/../NPU/src/train_ic15.py \ + --lr 0.001 \ + --dist-backend 'hccl' \ + --rank 0 \ + --workers 32 \ + --multiprocessing-distributed \ + --world-size 1 \ + --batch_size $batch_size \ + --device npu \ + --opt-level O2 \ + --loss-scale 64 \ + --addr=$(hostname -I |awk '{print $1}') \ + --seed 16 \ + --n_epoch $train_epochs \ + --data-dir $data_path \ + --port 8272 \ + --schedule 200 400 \ + --device-list $ASCEND_DEVICE_ID \ + --remark 1p \ + --combine_grad \ + --combine_sgd > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + + + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep 'epoch' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'FPS:' '{print $2}'|awk '{print $1}'|awk 'NR>3'|awk '{sum+=$1} END {print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep 'epoch' $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}' |awk '{print $2}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_performance_8p.sh index fe8659d2dfbe783f4a8c8740fff870b138917409..e0e8b1d3b0dda358ed79764378ee49749a14b727 100644 --- a/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/cv/detection/PSENet_for_PyTorch/test/train_performance_8p.sh @@ -1,158 +1,158 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -#RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="PSENet_ID0102_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=32 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - - - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -python3 ${cur_path}/../NPU/src/train_ic15_8p.py \ - --lr 0.004 \ - --dist-backend 'hccl' \ - --rank 0 \ - --workers 32 \ - --multiprocessing-distributed \ - --world-size 1 \ - --batch_size $batch_size \ - --device npu \ - --opt-level O2 \ - --loss-scale 64 \ - --addr=$(hostname -I |awk '{print $1}') \ - --seed 16 \ - --n_epoch $train_epochs \ - --data-dir $data_path \ - --port 8272 \ - --remark 8p \ - --combine_grad \ - --combine_sgd > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - - - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep 'epoch:' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'FPS:' '{print $2}'|awk '{print $1}'|awk 'NR>3'|awk '{sum+=$1} END {print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep 'epoch:' $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}' |awk '{print $2}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +#RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="PSENet_ID0102_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=32 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $cur_path/output ];then + rm -rf $cur_path/output/* + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +fi +wait + + + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +python3 ${cur_path}/../NPU/src/train_ic15_8p.py \ + --lr 0.004 \ + --dist-backend 'hccl' \ + --rank 0 \ + --workers 32 \ + --multiprocessing-distributed \ + --world-size 1 \ + --batch_size $batch_size \ + --device npu \ + --opt-level O2 \ + --loss-scale 64 \ + --addr=$(hostname -I |awk '{print $1}') \ + --seed 16 \ + --n_epoch $train_epochs \ + --data-dir $data_path \ + --port 8272 \ + --remark 8p \ + --combine_grad \ + --combine_sgd > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + + + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep 'epoch:' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'FPS:' '{print $2}'|awk '{print $1}'|awk 'NR>3'|awk '{sum+=$1} END {print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep 'epoch:' $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}' |awk '{print $2}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/_functions.py b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/_functions.py index ebbcee0394ef6f8ec483427eab315707bd87005b..219b7ecd4ae35bc4b2c2478b0ecb56ff81b61aaf 100644 --- a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/_functions.py +++ b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/_functions.py @@ -1,93 +1,93 @@ -# Copyright (c) Open-MMLab. All rights reserved. -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -from torch.nn.parallel._functions import _get_stream - - -def scatter(input, devices, streams=None): - """Scatters tensor across multiple GPUs.""" - if streams is None: - streams = [None] * len(devices) - - if isinstance(input, list): - chunk_size = (len(input) - 1) // len(devices) + 1 - outputs = [ - scatter(input[i], [devices[i // chunk_size]], - [streams[i // chunk_size]]) for i in range(len(input)) - ] - return outputs - elif isinstance(input, torch.Tensor): - output = input.contiguous() - # TODO: copy to a pinned buffer first (if copying from CPU) - stream = streams[0] if output.numel() > 0 else None - if devices != [-1]: - with torch.cuda.device(devices[0]), torch.cuda.stream(stream): - output = output.cuda(devices[0], non_blocking=True) - else: - pass - - return output - else: - raise Exception(f'Unknown type {type(input)}.') - - -def synchronize_stream(output, devices, streams): - if isinstance(output, list): - chunk_size = len(output) // len(devices) - for i in range(len(devices)): - for j in range(chunk_size): - synchronize_stream(output[i * chunk_size + j], [devices[i]], - [streams[i]]) - elif isinstance(output, torch.Tensor): - if output.numel() != 0: - with torch.cuda.device(devices[0]): - main_stream = torch.cuda.current_stream() - main_stream.wait_stream(streams[0]) - output.record_stream(main_stream) - else: - raise Exception(f'Unknown type {type(output)}.') - - -def get_input_device(input): - if isinstance(input, list): - for item in input: - input_device = get_input_device(item) - if input_device != -1: - return input_device - return -1 - elif isinstance(input, torch.Tensor): - return input.get_device() if input.is_cuda else -1 - else: - raise Exception(f'Unknown type {type(input)}.') - - -class Scatter: - - @staticmethod - def forward(target_gpus, input): - input_device = get_input_device(input) - streams = None - if input_device == -1 and target_gpus != [-1]: - # Perform CPU to GPU copies in a background stream - streams = [_get_stream(device) for device in target_gpus] - - outputs = scatter(input, target_gpus, streams) - # Synchronize with the copy stream - if streams is not None: - synchronize_stream(outputs, target_gpus, streams) - +# Copyright (c) Open-MMLab. All rights reserved. +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +from torch.nn.parallel._functions import _get_stream + + +def scatter(input, devices, streams=None): + """Scatters tensor across multiple GPUs.""" + if streams is None: + streams = [None] * len(devices) + + if isinstance(input, list): + chunk_size = (len(input) - 1) // len(devices) + 1 + outputs = [ + scatter(input[i], [devices[i // chunk_size]], + [streams[i // chunk_size]]) for i in range(len(input)) + ] + return outputs + elif isinstance(input, torch.Tensor): + output = input.contiguous() + # TODO: copy to a pinned buffer first (if copying from CPU) + stream = streams[0] if output.numel() > 0 else None + if devices != [-1]: + with torch.cuda.device(devices[0]), torch.cuda.stream(stream): + output = output.cuda(devices[0], non_blocking=True) + else: + pass + + return output + else: + raise Exception(f'Unknown type {type(input)}.') + + +def synchronize_stream(output, devices, streams): + if isinstance(output, list): + chunk_size = len(output) // len(devices) + for i in range(len(devices)): + for j in range(chunk_size): + synchronize_stream(output[i * chunk_size + j], [devices[i]], + [streams[i]]) + elif isinstance(output, torch.Tensor): + if output.numel() != 0: + with torch.cuda.device(devices[0]): + main_stream = torch.cuda.current_stream() + main_stream.wait_stream(streams[0]) + output.record_stream(main_stream) + else: + raise Exception(f'Unknown type {type(output)}.') + + +def get_input_device(input): + if isinstance(input, list): + for item in input: + input_device = get_input_device(item) + if input_device != -1: + return input_device + return -1 + elif isinstance(input, torch.Tensor): + return input.get_device() if input.is_cuda else -1 + else: + raise Exception(f'Unknown type {type(input)}.') + + +class Scatter: + + @staticmethod + def forward(target_gpus, input): + input_device = get_input_device(input) + streams = None + if input_device == -1 and target_gpus != [-1]: + # Perform CPU to GPU copies in a background stream + streams = [_get_stream(device) for device in target_gpus] + + outputs = scatter(input, target_gpus, streams) + # Synchronize with the copy stream + if streams is not None: + synchronize_stream(outputs, target_gpus, streams) + return tuple(outputs) \ No newline at end of file diff --git a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/builder.py b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/builder.py index f61945bc98a5d71aedf2e375edb393dfdbaf634d..0ae11773f3eb4d451af6e091e9f4ae158d7c15ca 100644 --- a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/builder.py +++ b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/builder.py @@ -1,69 +1,69 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import copy -import inspect - -import torch -import apex - -from ...utils import Registry, build_from_cfg - -OPTIMIZERS = Registry('optimizer') -OPTIMIZER_BUILDERS = Registry('optimizer builder') - - -def register_torch_optimizers(): - torch_optimizers = [] - for module_name in dir(torch.optim): - if module_name.startswith('__'): - continue - _optim = getattr(torch.optim, module_name) - if inspect.isclass(_optim) and issubclass(_optim, - torch.optim.Optimizer): - OPTIMIZERS.register_module()(_optim) - torch_optimizers.append(module_name) - - # add npu optimizer from apex - for module_name in dir(apex.optimizers): - if module_name.startswith('__'): - continue - _optim = getattr(apex.optimizers, module_name) - if inspect.isclass(_optim) and issubclass(_optim, - torch.optim.Optimizer): - OPTIMIZERS.register_module()(_optim) - torch_optimizers.append(module_name) - - return torch_optimizers - - -TORCH_OPTIMIZERS = register_torch_optimizers() - - -def build_optimizer_constructor(cfg): - return build_from_cfg(cfg, OPTIMIZER_BUILDERS) - - -def build_optimizer(model, cfg): - optimizer_cfg = copy.deepcopy(cfg) - constructor_type = optimizer_cfg.pop('constructor', - 'DefaultOptimizerConstructor') - paramwise_cfg = optimizer_cfg.pop('paramwise_cfg', None) - optim_constructor = build_optimizer_constructor( - dict( - type=constructor_type, - optimizer_cfg=optimizer_cfg, - paramwise_cfg=paramwise_cfg)) - optimizer = optim_constructor(model) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import copy +import inspect + +import torch +import apex + +from ...utils import Registry, build_from_cfg + +OPTIMIZERS = Registry('optimizer') +OPTIMIZER_BUILDERS = Registry('optimizer builder') + + +def register_torch_optimizers(): + torch_optimizers = [] + for module_name in dir(torch.optim): + if module_name.startswith('__'): + continue + _optim = getattr(torch.optim, module_name) + if inspect.isclass(_optim) and issubclass(_optim, + torch.optim.Optimizer): + OPTIMIZERS.register_module()(_optim) + torch_optimizers.append(module_name) + + # add npu optimizer from apex + for module_name in dir(apex.optimizers): + if module_name.startswith('__'): + continue + _optim = getattr(apex.optimizers, module_name) + if inspect.isclass(_optim) and issubclass(_optim, + torch.optim.Optimizer): + OPTIMIZERS.register_module()(_optim) + torch_optimizers.append(module_name) + + return torch_optimizers + + +TORCH_OPTIMIZERS = register_torch_optimizers() + + +def build_optimizer_constructor(cfg): + return build_from_cfg(cfg, OPTIMIZER_BUILDERS) + + +def build_optimizer(model, cfg): + optimizer_cfg = copy.deepcopy(cfg) + constructor_type = optimizer_cfg.pop('constructor', + 'DefaultOptimizerConstructor') + paramwise_cfg = optimizer_cfg.pop('paramwise_cfg', None) + optim_constructor = build_optimizer_constructor( + dict( + type=constructor_type, + optimizer_cfg=optimizer_cfg, + paramwise_cfg=paramwise_cfg)) + optimizer = optim_constructor(model) return optimizer \ No newline at end of file diff --git a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/data_parallel.py b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/data_parallel.py index c9d1e953e2a6d01c06479e570a78de95b8a511d2..b3b45fa9bcfc46be14056c2c2c088766bcb08951 100644 --- a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/data_parallel.py +++ b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/data_parallel.py @@ -1,104 +1,104 @@ -# Copyright (c) Open-MMLab. All rights reserved. -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from itertools import chain - -from torch.nn.parallel import DataParallel - -from .scatter_gather import scatter_kwargs - - -class MMDataParallel(DataParallel): - """The DataParallel module that supports DataContainer. - - MMDataParallel has two main differences with PyTorch DataParallel: - - - It supports a custom type :class:`DataContainer` which allows more - flexible control of input data during both GPU and CPU inference. - - It implement two more APIs ``train_step()`` and ``val_step()``. - - Args: - module (:class:`nn.Module`): Module to be encapsulated. - device_ids (list[int]): Device IDS of modules to be scattered to. - Defaults to None when GPU is not available. - output_device (str | int): Device ID for output. Defaults to None. - dim (int): Dimension used to scatter the data. Defaults to 0. - """ - - def __init__(self, *args, dim=0, **kwargs): - super(MMDataParallel, self).__init__(*args, dim=dim, **kwargs) - self.dim = dim - - def forward(self, *inputs, **kwargs): - """Override the original forward function. - - The main difference lies in the CPU inference where the datas in - :class:`DataContainers` will still be gathered. - """ - if not self.device_ids: - # We add the following line thus the module could gather and - # convert data containers as those in GPU inference - inputs, kwargs = self.scatter(inputs, kwargs, [-1]) - return self.module(*inputs[0], **kwargs[0]) - else: - return super().forward(*inputs, **kwargs) - - def scatter(self, inputs, kwargs, device_ids): - return scatter_kwargs(inputs, kwargs, device_ids, dim=self.dim) - - def train_step(self, *inputs, **kwargs): - if not self.device_ids: - # We add the following line thus the module could gather and - # convert data containers as those in GPU inference - inputs, kwargs = self.scatter(inputs, kwargs, [-1]) - return self.module.train_step(*inputs[0], **kwargs[0]) - - assert len(self.device_ids) == 1, \ - ('MMDataParallel only supports single GPU training, if you need to' - ' train with multiple GPUs, please use MMDistributedDataParallel' - 'instead.') - - for t in chain(self.module.parameters(), self.module.buffers()): - if t.device != self.src_device_obj: - raise RuntimeError( - 'module must have its parameters and buffers ' - f'on device {self.src_device_obj} (device_ids[0]) but ' - f'found one of them on device: {t.device}') - - inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) - return self.module.train_step(*inputs[0], **kwargs[0]) - - def val_step(self, *inputs, **kwargs): - if not self.device_ids: - # We add the following line thus the module could gather and - # convert data containers as those in GPU inference - inputs, kwargs = self.scatter(inputs, kwargs, [-1]) - return self.module.val_step(*inputs, **kwargs) - - assert len(self.device_ids) == 1, \ - ('MMDataParallel only supports single GPU training, if you need to' - ' train with multiple GPUs, please use MMDistributedDataParallel' - ' instead.') - - for t in chain(self.module.parameters(), self.module.buffers()): - if t.device != self.src_device_obj: - raise RuntimeError( - 'module must have its parameters and buffers ' - f'on device {self.src_device_obj} (device_ids[0]) but ' - f'found one of them on device: {t.device}') - - inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) - return self.module.val_step(*inputs[0], **kwargs[0]) +# Copyright (c) Open-MMLab. All rights reserved. +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from itertools import chain + +from torch.nn.parallel import DataParallel + +from .scatter_gather import scatter_kwargs + + +class MMDataParallel(DataParallel): + """The DataParallel module that supports DataContainer. + + MMDataParallel has two main differences with PyTorch DataParallel: + + - It supports a custom type :class:`DataContainer` which allows more + flexible control of input data during both GPU and CPU inference. + - It implement two more APIs ``train_step()`` and ``val_step()``. + + Args: + module (:class:`nn.Module`): Module to be encapsulated. + device_ids (list[int]): Device IDS of modules to be scattered to. + Defaults to None when GPU is not available. + output_device (str | int): Device ID for output. Defaults to None. + dim (int): Dimension used to scatter the data. Defaults to 0. + """ + + def __init__(self, *args, dim=0, **kwargs): + super(MMDataParallel, self).__init__(*args, dim=dim, **kwargs) + self.dim = dim + + def forward(self, *inputs, **kwargs): + """Override the original forward function. + + The main difference lies in the CPU inference where the datas in + :class:`DataContainers` will still be gathered. + """ + if not self.device_ids: + # We add the following line thus the module could gather and + # convert data containers as those in GPU inference + inputs, kwargs = self.scatter(inputs, kwargs, [-1]) + return self.module(*inputs[0], **kwargs[0]) + else: + return super().forward(*inputs, **kwargs) + + def scatter(self, inputs, kwargs, device_ids): + return scatter_kwargs(inputs, kwargs, device_ids, dim=self.dim) + + def train_step(self, *inputs, **kwargs): + if not self.device_ids: + # We add the following line thus the module could gather and + # convert data containers as those in GPU inference + inputs, kwargs = self.scatter(inputs, kwargs, [-1]) + return self.module.train_step(*inputs[0], **kwargs[0]) + + assert len(self.device_ids) == 1, \ + ('MMDataParallel only supports single GPU training, if you need to' + ' train with multiple GPUs, please use MMDistributedDataParallel' + 'instead.') + + for t in chain(self.module.parameters(), self.module.buffers()): + if t.device != self.src_device_obj: + raise RuntimeError( + 'module must have its parameters and buffers ' + f'on device {self.src_device_obj} (device_ids[0]) but ' + f'found one of them on device: {t.device}') + + inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) + return self.module.train_step(*inputs[0], **kwargs[0]) + + def val_step(self, *inputs, **kwargs): + if not self.device_ids: + # We add the following line thus the module could gather and + # convert data containers as those in GPU inference + inputs, kwargs = self.scatter(inputs, kwargs, [-1]) + return self.module.val_step(*inputs, **kwargs) + + assert len(self.device_ids) == 1, \ + ('MMDataParallel only supports single GPU training, if you need to' + ' train with multiple GPUs, please use MMDistributedDataParallel' + ' instead.') + + for t in chain(self.module.parameters(), self.module.buffers()): + if t.device != self.src_device_obj: + raise RuntimeError( + 'module must have its parameters and buffers ' + f'on device {self.src_device_obj} (device_ids[0]) but ' + f'found one of them on device: {t.device}') + + inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) + return self.module.val_step(*inputs[0], **kwargs[0]) diff --git a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/dist_utils.py b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/dist_utils.py index 091b646869a1ac678cd1f6886e8d61592e33fdfd..efe19f5018306dcb0ba419157d5b1b40cfa339b9 100644 --- a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/dist_utils.py +++ b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/dist_utils.py @@ -1,185 +1,185 @@ -# Copyright (c) Open-MMLab. All rights reserved. -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import functools -import os -import subprocess -from collections import OrderedDict - -import torch -import torch.multiprocessing as mp -from torch import distributed as dist -from torch._utils import (_flatten_dense_tensors, _take_tensors, - _unflatten_dense_tensors) - -from mmcv.utils import TORCH_VERSION - - -def init_dist(launcher, backend='nccl', **kwargs): - if mp.get_start_method(allow_none=True) is None: - mp.set_start_method('spawn') - if launcher == 'pytorch': - _init_dist_pytorch(backend, **kwargs) - elif launcher == 'mpi': - _init_dist_mpi(backend, **kwargs) - elif launcher == 'slurm': - _init_dist_slurm(backend, **kwargs) - else: - raise ValueError(f'Invalid launcher type: {launcher}') - - -def _init_dist_pytorch(backend, **kwargs): - # TODO: use local_rank instead of rank % num_gpus - rank = int(os.environ['RANK']) - offset = 0 if os.getenv('NPUID', None) is None else int(os.environ['NPUID']) - num_gpus = int(os.environ['RANK_SIZE']) - torch.npu.set_device((rank + offset) % num_gpus) - dist.init_process_group(backend=backend, world_size=num_gpus, rank=rank) - - -def _init_dist_mpi(backend, **kwargs): - # TODO: use local_rank instead of rank % num_gpus - rank = int(os.environ['OMPI_COMM_WORLD_RANK']) - num_gpus = torch.cuda.device_count() - torch.cuda.set_device(rank % num_gpus) - dist.init_process_group(backend=backend, **kwargs) - - -def _init_dist_slurm(backend, port=None): - """Initialize slurm distributed training environment. - If argument ``port`` is not specified, then the master port will be system - environment variable ``MASTER_PORT``. If ``MASTER_PORT`` is not in system - environment variable, then a default port ``29500`` will be used. - Args: - backend (str): Backend of torch.distributed. - port (int, optional): Master port. Defaults to None. - """ - proc_id = int(os.environ['SLURM_PROCID']) - ntasks = int(os.environ['SLURM_NTASKS']) - node_list = os.environ['SLURM_NODELIST'] - num_gpus = torch.cuda.device_count() - torch.cuda.set_device(proc_id % num_gpus) - addr = subprocess.getoutput( - f'scontrol show hostname {node_list} | head -n1') - # specify master port - if port is not None: - os.environ['MASTER_PORT'] = str(port) - elif 'MASTER_PORT' in os.environ: - pass # use MASTER_PORT in the environment variable - else: - # 29500 is torch.distributed default port - os.environ['MASTER_PORT'] = '29500' - # use MASTER_ADDR in the environment variable if it already exists - if 'MASTER_ADDR' not in os.environ: - os.environ['MASTER_ADDR'] = addr - os.environ['WORLD_SIZE'] = str(ntasks) - os.environ['LOCAL_RANK'] = str(proc_id % num_gpus) - os.environ['RANK'] = str(proc_id) - dist.init_process_group(backend=backend) - - -def get_dist_info(): - if TORCH_VERSION < '1.0': - initialized = dist._initialized - else: - if dist.is_available(): - initialized = dist.is_initialized() - else: - initialized = False - if initialized: - rank = dist.get_rank() - world_size = dist.get_world_size() - else: - rank = 0 - world_size = 1 - return rank, world_size - - -def master_only(func): - - @functools.wraps(func) - def wrapper(*args, **kwargs): - rank, _ = get_dist_info() - if rank == 0: - return func(*args, **kwargs) - - return wrapper - - -def allreduce_params(params, coalesce=True, bucket_size_mb=-1): - """Allreduce parameters. - Args: - params (list[torch.Parameters]): List of parameters or buffers of a - model. - coalesce (bool, optional): Whether allreduce parameters as a whole. - Defaults to True. - bucket_size_mb (int, optional): Size of bucket, the unit is MB. - Defaults to -1. - """ - _, world_size = get_dist_info() - if world_size == 1: - return - params = [param.data for param in params] - if coalesce: - _allreduce_coalesced(params, world_size, bucket_size_mb) - else: - for tensor in params: - dist.all_reduce(tensor.div_(world_size)) - - -def allreduce_grads(params, coalesce=True, bucket_size_mb=-1): - """Allreduce gradients. - Args: - params (list[torch.Parameters]): List of parameters of a model - coalesce (bool, optional): Whether allreduce parameters as a whole. - Defaults to True. - bucket_size_mb (int, optional): Size of bucket, the unit is MB. - Defaults to -1. - """ - grads = [ - param.grad.data for param in params - if param.requires_grad and param.grad is not None - ] - _, world_size = get_dist_info() - if world_size == 1: - return - if coalesce: - _allreduce_coalesced(grads, world_size, bucket_size_mb) - else: - for tensor in grads: - dist.all_reduce(tensor.div_(world_size)) - - -def _allreduce_coalesced(tensors, world_size, bucket_size_mb=-1): - if bucket_size_mb > 0: - bucket_size_bytes = bucket_size_mb * 1024 * 1024 - buckets = _take_tensors(tensors, bucket_size_bytes) - else: - buckets = OrderedDict() - for tensor in tensors: - tp = tensor.type() - if tp not in buckets: - buckets[tp] = [] - buckets[tp].append(tensor) - buckets = buckets.values() - - for bucket in buckets: - flat_tensors = _flatten_dense_tensors(bucket) - dist.all_reduce(flat_tensors) - flat_tensors.div_(world_size) - for tensor, synced in zip( - bucket, _unflatten_dense_tensors(flat_tensors, bucket)): +# Copyright (c) Open-MMLab. All rights reserved. +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import functools +import os +import subprocess +from collections import OrderedDict + +import torch +import torch.multiprocessing as mp +from torch import distributed as dist +from torch._utils import (_flatten_dense_tensors, _take_tensors, + _unflatten_dense_tensors) + +from mmcv.utils import TORCH_VERSION + + +def init_dist(launcher, backend='nccl', **kwargs): + if mp.get_start_method(allow_none=True) is None: + mp.set_start_method('spawn') + if launcher == 'pytorch': + _init_dist_pytorch(backend, **kwargs) + elif launcher == 'mpi': + _init_dist_mpi(backend, **kwargs) + elif launcher == 'slurm': + _init_dist_slurm(backend, **kwargs) + else: + raise ValueError(f'Invalid launcher type: {launcher}') + + +def _init_dist_pytorch(backend, **kwargs): + # TODO: use local_rank instead of rank % num_gpus + rank = int(os.environ['RANK']) + offset = 0 if os.getenv('NPUID', None) is None else int(os.environ['NPUID']) + num_gpus = int(os.environ['RANK_SIZE']) + torch.npu.set_device((rank + offset) % num_gpus) + dist.init_process_group(backend=backend, world_size=num_gpus, rank=rank) + + +def _init_dist_mpi(backend, **kwargs): + # TODO: use local_rank instead of rank % num_gpus + rank = int(os.environ['OMPI_COMM_WORLD_RANK']) + num_gpus = torch.cuda.device_count() + torch.cuda.set_device(rank % num_gpus) + dist.init_process_group(backend=backend, **kwargs) + + +def _init_dist_slurm(backend, port=None): + """Initialize slurm distributed training environment. + If argument ``port`` is not specified, then the master port will be system + environment variable ``MASTER_PORT``. If ``MASTER_PORT`` is not in system + environment variable, then a default port ``29500`` will be used. + Args: + backend (str): Backend of torch.distributed. + port (int, optional): Master port. Defaults to None. + """ + proc_id = int(os.environ['SLURM_PROCID']) + ntasks = int(os.environ['SLURM_NTASKS']) + node_list = os.environ['SLURM_NODELIST'] + num_gpus = torch.cuda.device_count() + torch.cuda.set_device(proc_id % num_gpus) + addr = subprocess.getoutput( + f'scontrol show hostname {node_list} | head -n1') + # specify master port + if port is not None: + os.environ['MASTER_PORT'] = str(port) + elif 'MASTER_PORT' in os.environ: + pass # use MASTER_PORT in the environment variable + else: + # 29500 is torch.distributed default port + os.environ['MASTER_PORT'] = '29500' + # use MASTER_ADDR in the environment variable if it already exists + if 'MASTER_ADDR' not in os.environ: + os.environ['MASTER_ADDR'] = addr + os.environ['WORLD_SIZE'] = str(ntasks) + os.environ['LOCAL_RANK'] = str(proc_id % num_gpus) + os.environ['RANK'] = str(proc_id) + dist.init_process_group(backend=backend) + + +def get_dist_info(): + if TORCH_VERSION < '1.0': + initialized = dist._initialized + else: + if dist.is_available(): + initialized = dist.is_initialized() + else: + initialized = False + if initialized: + rank = dist.get_rank() + world_size = dist.get_world_size() + else: + rank = 0 + world_size = 1 + return rank, world_size + + +def master_only(func): + + @functools.wraps(func) + def wrapper(*args, **kwargs): + rank, _ = get_dist_info() + if rank == 0: + return func(*args, **kwargs) + + return wrapper + + +def allreduce_params(params, coalesce=True, bucket_size_mb=-1): + """Allreduce parameters. + Args: + params (list[torch.Parameters]): List of parameters or buffers of a + model. + coalesce (bool, optional): Whether allreduce parameters as a whole. + Defaults to True. + bucket_size_mb (int, optional): Size of bucket, the unit is MB. + Defaults to -1. + """ + _, world_size = get_dist_info() + if world_size == 1: + return + params = [param.data for param in params] + if coalesce: + _allreduce_coalesced(params, world_size, bucket_size_mb) + else: + for tensor in params: + dist.all_reduce(tensor.div_(world_size)) + + +def allreduce_grads(params, coalesce=True, bucket_size_mb=-1): + """Allreduce gradients. + Args: + params (list[torch.Parameters]): List of parameters of a model + coalesce (bool, optional): Whether allreduce parameters as a whole. + Defaults to True. + bucket_size_mb (int, optional): Size of bucket, the unit is MB. + Defaults to -1. + """ + grads = [ + param.grad.data for param in params + if param.requires_grad and param.grad is not None + ] + _, world_size = get_dist_info() + if world_size == 1: + return + if coalesce: + _allreduce_coalesced(grads, world_size, bucket_size_mb) + else: + for tensor in grads: + dist.all_reduce(tensor.div_(world_size)) + + +def _allreduce_coalesced(tensors, world_size, bucket_size_mb=-1): + if bucket_size_mb > 0: + bucket_size_bytes = bucket_size_mb * 1024 * 1024 + buckets = _take_tensors(tensors, bucket_size_bytes) + else: + buckets = OrderedDict() + for tensor in tensors: + tp = tensor.type() + if tp not in buckets: + buckets[tp] = [] + buckets[tp].append(tensor) + buckets = buckets.values() + + for bucket in buckets: + flat_tensors = _flatten_dense_tensors(bucket) + dist.all_reduce(flat_tensors) + flat_tensors.div_(world_size) + for tensor, synced in zip( + bucket, _unflatten_dense_tensors(flat_tensors, bucket)): tensor.copy_(synced) \ No newline at end of file diff --git a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/distributed.py b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/distributed.py index 86ca4b123eb718593037c0b2cd62cc19116c6f9b..1927a480731f6a0016d53a37ec2c64cb32da4a0a 100644 --- a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/distributed.py +++ b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/distributed.py @@ -1,119 +1,119 @@ -# Copyright (c) Open-MMLab. All rights reserved. -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -from torch.nn.parallel.distributed import (DistributedDataParallel, - _find_tensors) - -from mmcv import print_log -from mmcv.utils import TORCH_VERSION -from .scatter_gather import scatter_kwargs - - -class MMDistributedDataParallel(DistributedDataParallel): - """The DDP module that supports DataContainer. - - MMDDP has two main differences with PyTorch DDP: - - - It supports a custom type :class:`DataContainer` which allows more - flexible control of input data. - - It implement two APIs ``train_step()`` and ``val_step()``. - """ - - def scatter(self, inputs, kwargs, device_ids): - return scatter_kwargs(inputs, kwargs, device_ids, dim=self.dim) - - def train_step(self, *inputs, **kwargs): - """train_step() API for module wrapped by DistributedDataParallel. - - This method is basically the same as - ``DistributedDataParallel.forward()``, while replacing - ``self.module.forward()`` with ``self.module.train_step()``. - It is compatible with PyTorch 1.1 - 1.5. - """ - - # In PyTorch >= 1.7, ``reducer._rebuild_buckets()`` is moved from the - # end of backward to the beginning of forward. - if (TORCH_VERSION >= '1.7' and 'parrots' - not in TORCH_VERSION) and self.reducer._rebuild_buckets(): - print_log( - 'Reducer buckets have been rebuilt in this iteration.', - logger='mmcv') - - if getattr(self, 'require_forward_param_sync', True): - self._sync_params() - if self.device_ids and False: - inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) - if len(self.device_ids) == 1: - output = self.module.train_step(*inputs[0], **kwargs[0]) - else: - outputs = self.parallel_apply( - self._module_copies[:len(inputs)], inputs, kwargs) - output = self.gather(outputs, self.output_device) - else: - inputs, kwargs = self.scatter(inputs, kwargs, [-1]) - output = self.module.train_step(*inputs[0], **kwargs[0]) - - if torch.is_grad_enabled() and getattr( - self, 'require_backward_grad_sync', True): - if self.find_unused_parameters: - self.reducer.prepare_for_backward(list(_find_tensors(output))) - else: - self.reducer.prepare_for_backward([]) - else: - if TORCH_VERSION > '1.2': - self.require_forward_param_sync = False - return output - - def val_step(self, *inputs, **kwargs): - """val_step() API for module wrapped by DistributedDataParallel. - - This method is basically the same as - ``DistributedDataParallel.forward()``, while replacing - ``self.module.forward()`` with ``self.module.val_step()``. - It is compatible with PyTorch 1.1 - 1.5. - """ - # In PyTorch >= 1.7, ``reducer._rebuild_buckets()`` is moved from the - # end of backward to the beginning of forward. - if (TORCH_VERSION >= '1.7' and 'parrots' - not in TORCH_VERSION) and self.reducer._rebuild_buckets(): - print_log( - 'Reducer buckets have been rebuilt in this iteration.', - logger='mmcv') - - if getattr(self, 'require_forward_param_sync', True): - self._sync_params() - if self.device_ids: - inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) - if len(self.device_ids) == 1: - output = self.module.val_step(*inputs[0], **kwargs[0]) - else: - outputs = self.parallel_apply( - self._module_copies[:len(inputs)], inputs, kwargs) - output = self.gather(outputs, self.output_device) - else: - output = self.module.val_step(*inputs, **kwargs) - - if torch.is_grad_enabled() and getattr( - self, 'require_backward_grad_sync', True): - if self.find_unused_parameters: - self.reducer.prepare_for_backward(list(_find_tensors(output))) - else: - self.reducer.prepare_for_backward([]) - else: - if TORCH_VERSION > '1.2': - self.require_forward_param_sync = False - return output +# Copyright (c) Open-MMLab. All rights reserved. +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +from torch.nn.parallel.distributed import (DistributedDataParallel, + _find_tensors) + +from mmcv import print_log +from mmcv.utils import TORCH_VERSION +from .scatter_gather import scatter_kwargs + + +class MMDistributedDataParallel(DistributedDataParallel): + """The DDP module that supports DataContainer. + + MMDDP has two main differences with PyTorch DDP: + + - It supports a custom type :class:`DataContainer` which allows more + flexible control of input data. + - It implement two APIs ``train_step()`` and ``val_step()``. + """ + + def scatter(self, inputs, kwargs, device_ids): + return scatter_kwargs(inputs, kwargs, device_ids, dim=self.dim) + + def train_step(self, *inputs, **kwargs): + """train_step() API for module wrapped by DistributedDataParallel. + + This method is basically the same as + ``DistributedDataParallel.forward()``, while replacing + ``self.module.forward()`` with ``self.module.train_step()``. + It is compatible with PyTorch 1.1 - 1.5. + """ + + # In PyTorch >= 1.7, ``reducer._rebuild_buckets()`` is moved from the + # end of backward to the beginning of forward. + if (TORCH_VERSION >= '1.7' and 'parrots' + not in TORCH_VERSION) and self.reducer._rebuild_buckets(): + print_log( + 'Reducer buckets have been rebuilt in this iteration.', + logger='mmcv') + + if getattr(self, 'require_forward_param_sync', True): + self._sync_params() + if self.device_ids and False: + inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) + if len(self.device_ids) == 1: + output = self.module.train_step(*inputs[0], **kwargs[0]) + else: + outputs = self.parallel_apply( + self._module_copies[:len(inputs)], inputs, kwargs) + output = self.gather(outputs, self.output_device) + else: + inputs, kwargs = self.scatter(inputs, kwargs, [-1]) + output = self.module.train_step(*inputs[0], **kwargs[0]) + + if torch.is_grad_enabled() and getattr( + self, 'require_backward_grad_sync', True): + if self.find_unused_parameters: + self.reducer.prepare_for_backward(list(_find_tensors(output))) + else: + self.reducer.prepare_for_backward([]) + else: + if TORCH_VERSION > '1.2': + self.require_forward_param_sync = False + return output + + def val_step(self, *inputs, **kwargs): + """val_step() API for module wrapped by DistributedDataParallel. + + This method is basically the same as + ``DistributedDataParallel.forward()``, while replacing + ``self.module.forward()`` with ``self.module.val_step()``. + It is compatible with PyTorch 1.1 - 1.5. + """ + # In PyTorch >= 1.7, ``reducer._rebuild_buckets()`` is moved from the + # end of backward to the beginning of forward. + if (TORCH_VERSION >= '1.7' and 'parrots' + not in TORCH_VERSION) and self.reducer._rebuild_buckets(): + print_log( + 'Reducer buckets have been rebuilt in this iteration.', + logger='mmcv') + + if getattr(self, 'require_forward_param_sync', True): + self._sync_params() + if self.device_ids: + inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) + if len(self.device_ids) == 1: + output = self.module.val_step(*inputs[0], **kwargs[0]) + else: + outputs = self.parallel_apply( + self._module_copies[:len(inputs)], inputs, kwargs) + output = self.gather(outputs, self.output_device) + else: + output = self.module.val_step(*inputs, **kwargs) + + if torch.is_grad_enabled() and getattr( + self, 'require_backward_grad_sync', True): + if self.find_unused_parameters: + self.reducer.prepare_for_backward(list(_find_tensors(output))) + else: + self.reducer.prepare_for_backward([]) + else: + if TORCH_VERSION > '1.2': + self.require_forward_param_sync = False + return output diff --git a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/optimizer.py b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/optimizer.py index 9653c4e11b87b1c69866cd3b08984d43305a4469..5b574f66deb66760069519b3d87c6c4164d49cd9 100644 --- a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/optimizer.py +++ b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/mmcv_need/optimizer.py @@ -1,162 +1,162 @@ -# Copyright (c) Open-MMLab. All rights reserved. -import copy -from collections import defaultdict -from itertools import chain - -from torch.nn.utils import clip_grad - -from ..dist_utils import allreduce_grads -from ..fp16_utils import LossScaler, wrap_fp16_model -from .hook import HOOKS, Hook -from apex import amp - -@HOOKS.register_module() -class OptimizerHook(Hook): - - def __init__(self, grad_clip=None): - self.grad_clip = grad_clip - - def clip_grads(self, params): - params = list( - filter(lambda p: p.requires_grad and p.grad is not None, params)) - if len(params) > 0: - return clip_grad.clip_grad_norm_(params, **self.grad_clip) - - def after_train_iter(self, runner): - runner.optimizer.zero_grad() - with amp.scale_loss(runner.outputs['loss'], runner.optimizer) as scaled_loss: - scaled_loss.backward() - if self.grad_clip is not None: - grad_norm = self.clip_grads(runner.model.parameters()) - if grad_norm is not None: - # Add grad norm to the logger - runner.log_buffer.update({'grad_norm': float(grad_norm)}, - runner.outputs['num_samples']) - runner.optimizer.step() - - -@HOOKS.register_module() -class Fp16OptimizerHook(OptimizerHook): - """FP16 optimizer hook. - - The steps of fp16 optimizer is as follows. - 1. Scale the loss value. - 2. BP in the fp16 model. - 2. Copy gradients from fp16 model to fp32 weights. - 3. Update fp32 weights. - 4. Copy updated parameters from fp32 weights to fp16 model. - - Refer to https://arxiv.org/abs/1710.03740 for more details. - - Args: - loss_scale (float | str | dict): Scale factor multiplied with loss. - If loss_scale is a float, static loss scaling will be used with - the specified scale. If loss_scale is a string, it must be - 'dynamic', then dynamic loss scaling will be used. - It can also be a dict containing arguments of LossScaler. - Defaults to 512. - """ - - def __init__(self, - grad_clip=None, - coalesce=True, - bucket_size_mb=-1, - loss_scale=512., - distributed=True): - self.grad_clip = grad_clip - self.coalesce = coalesce - self.bucket_size_mb = bucket_size_mb - self.distributed = distributed - if loss_scale == 'dynamic': - self.loss_scaler = LossScaler(mode='dynamic') - elif isinstance(loss_scale, float): - self.loss_scaler = LossScaler(init_scale=loss_scale, mode='static') - elif isinstance(loss_scale, dict): - self.loss_scaler = LossScaler(**loss_scale) - else: - raise ValueError('loss_scale must be of type float, dict, or ' - f'"dynamic", got {loss_scale}') - - def before_run(self, runner): - """Preparing steps before Mixed Precision Training. - - 1. Make a master copy of fp32 weights for optimization. - 2. Convert the main model from fp32 to fp16. - """ - # keep a copy of fp32 weights - old_groups = runner.optimizer.param_groups - runner.optimizer.param_groups = copy.deepcopy( - runner.optimizer.param_groups) - state = defaultdict(dict) - p_map = { - old_p: p - for old_p, p in zip( - chain(*(g['params'] for g in old_groups)), - chain(*(g['params'] for g in runner.optimizer.param_groups))) - } - for k, v in runner.optimizer.state.items(): - state[p_map[k]] = v - runner.optimizer.state = state - # convert model to fp16 - wrap_fp16_model(runner.model) - - def copy_grads_to_fp32(self, fp16_net, fp32_weights): - """Copy gradients from fp16 model to fp32 weight copy.""" - for fp32_param, fp16_param in zip(fp32_weights, fp16_net.parameters()): - if fp16_param.grad is not None: - if fp32_param.grad is None: - fp32_param.grad = fp32_param.data.new(fp32_param.size()) - fp32_param.grad.copy_(fp16_param.grad) - - def copy_params_to_fp16(self, fp16_net, fp32_weights): - """Copy updated params from fp32 weight copy to fp16 model.""" - for fp16_param, fp32_param in zip(fp16_net.parameters(), fp32_weights): - fp16_param.data.copy_(fp32_param.data) - - def after_train_iter(self, runner): - """Backward optimization steps for Mixed Precision Training. For - dynamic loss scaling, please refer `loss_scalar.py` - - 1. Scale the loss by a scale factor. - 2. Backward the loss to obtain the gradients (fp16). - 3. Copy gradients from the model to the fp32 weight copy. - 4. Scale the gradients back and update the fp32 weight copy. - 5. Copy back the params from fp32 weight copy to the fp16 model. - """ - # clear grads of last iteration - runner.model.zero_grad() - runner.optimizer.zero_grad() - # scale the loss value - scaled_loss = runner.outputs['loss'] * self.loss_scaler.loss_scale - scaled_loss.backward() - # copy fp16 grads in the model to fp32 params in the optimizer - - fp32_weights = [] - for param_group in runner.optimizer.param_groups: - fp32_weights += param_group['params'] - self.copy_grads_to_fp32(runner.model, fp32_weights) - # allreduce grads - if self.distributed: - allreduce_grads(fp32_weights, self.coalesce, self.bucket_size_mb) - - has_overflow = self.loss_scaler.has_overflow(fp32_weights) - # if has overflow, skip this iteration - if not has_overflow: - # scale the gradients back - for param in fp32_weights: - if param.grad is not None: - param.grad.div_(self.loss_scaler.loss_scale) - if self.grad_clip is not None: - grad_norm = self.clip_grads(fp32_weights) - if grad_norm is not None: - # Add grad norm to the logger - runner.log_buffer.update({'grad_norm': float(grad_norm)}, - runner.outputs['num_samples']) - # update fp32 params - runner.optimizer.step() - # copy fp32 params to the fp16 model - self.copy_params_to_fp16(runner.model, fp32_weights) - self.loss_scaler.update_scale(has_overflow) - if has_overflow: - runner.logger.warning('Check overflow, downscale loss scale ' - f'to {self.loss_scaler.cur_scale}') +# Copyright (c) Open-MMLab. All rights reserved. +import copy +from collections import defaultdict +from itertools import chain + +from torch.nn.utils import clip_grad + +from ..dist_utils import allreduce_grads +from ..fp16_utils import LossScaler, wrap_fp16_model +from .hook import HOOKS, Hook +from apex import amp + +@HOOKS.register_module() +class OptimizerHook(Hook): + + def __init__(self, grad_clip=None): + self.grad_clip = grad_clip + + def clip_grads(self, params): + params = list( + filter(lambda p: p.requires_grad and p.grad is not None, params)) + if len(params) > 0: + return clip_grad.clip_grad_norm_(params, **self.grad_clip) + + def after_train_iter(self, runner): + runner.optimizer.zero_grad() + with amp.scale_loss(runner.outputs['loss'], runner.optimizer) as scaled_loss: + scaled_loss.backward() + if self.grad_clip is not None: + grad_norm = self.clip_grads(runner.model.parameters()) + if grad_norm is not None: + # Add grad norm to the logger + runner.log_buffer.update({'grad_norm': float(grad_norm)}, + runner.outputs['num_samples']) + runner.optimizer.step() + + +@HOOKS.register_module() +class Fp16OptimizerHook(OptimizerHook): + """FP16 optimizer hook. + + The steps of fp16 optimizer is as follows. + 1. Scale the loss value. + 2. BP in the fp16 model. + 2. Copy gradients from fp16 model to fp32 weights. + 3. Update fp32 weights. + 4. Copy updated parameters from fp32 weights to fp16 model. + + Refer to https://arxiv.org/abs/1710.03740 for more details. + + Args: + loss_scale (float | str | dict): Scale factor multiplied with loss. + If loss_scale is a float, static loss scaling will be used with + the specified scale. If loss_scale is a string, it must be + 'dynamic', then dynamic loss scaling will be used. + It can also be a dict containing arguments of LossScaler. + Defaults to 512. + """ + + def __init__(self, + grad_clip=None, + coalesce=True, + bucket_size_mb=-1, + loss_scale=512., + distributed=True): + self.grad_clip = grad_clip + self.coalesce = coalesce + self.bucket_size_mb = bucket_size_mb + self.distributed = distributed + if loss_scale == 'dynamic': + self.loss_scaler = LossScaler(mode='dynamic') + elif isinstance(loss_scale, float): + self.loss_scaler = LossScaler(init_scale=loss_scale, mode='static') + elif isinstance(loss_scale, dict): + self.loss_scaler = LossScaler(**loss_scale) + else: + raise ValueError('loss_scale must be of type float, dict, or ' + f'"dynamic", got {loss_scale}') + + def before_run(self, runner): + """Preparing steps before Mixed Precision Training. + + 1. Make a master copy of fp32 weights for optimization. + 2. Convert the main model from fp32 to fp16. + """ + # keep a copy of fp32 weights + old_groups = runner.optimizer.param_groups + runner.optimizer.param_groups = copy.deepcopy( + runner.optimizer.param_groups) + state = defaultdict(dict) + p_map = { + old_p: p + for old_p, p in zip( + chain(*(g['params'] for g in old_groups)), + chain(*(g['params'] for g in runner.optimizer.param_groups))) + } + for k, v in runner.optimizer.state.items(): + state[p_map[k]] = v + runner.optimizer.state = state + # convert model to fp16 + wrap_fp16_model(runner.model) + + def copy_grads_to_fp32(self, fp16_net, fp32_weights): + """Copy gradients from fp16 model to fp32 weight copy.""" + for fp32_param, fp16_param in zip(fp32_weights, fp16_net.parameters()): + if fp16_param.grad is not None: + if fp32_param.grad is None: + fp32_param.grad = fp32_param.data.new(fp32_param.size()) + fp32_param.grad.copy_(fp16_param.grad) + + def copy_params_to_fp16(self, fp16_net, fp32_weights): + """Copy updated params from fp32 weight copy to fp16 model.""" + for fp16_param, fp32_param in zip(fp16_net.parameters(), fp32_weights): + fp16_param.data.copy_(fp32_param.data) + + def after_train_iter(self, runner): + """Backward optimization steps for Mixed Precision Training. For + dynamic loss scaling, please refer `loss_scalar.py` + + 1. Scale the loss by a scale factor. + 2. Backward the loss to obtain the gradients (fp16). + 3. Copy gradients from the model to the fp32 weight copy. + 4. Scale the gradients back and update the fp32 weight copy. + 5. Copy back the params from fp32 weight copy to the fp16 model. + """ + # clear grads of last iteration + runner.model.zero_grad() + runner.optimizer.zero_grad() + # scale the loss value + scaled_loss = runner.outputs['loss'] * self.loss_scaler.loss_scale + scaled_loss.backward() + # copy fp16 grads in the model to fp32 params in the optimizer + + fp32_weights = [] + for param_group in runner.optimizer.param_groups: + fp32_weights += param_group['params'] + self.copy_grads_to_fp32(runner.model, fp32_weights) + # allreduce grads + if self.distributed: + allreduce_grads(fp32_weights, self.coalesce, self.bucket_size_mb) + + has_overflow = self.loss_scaler.has_overflow(fp32_weights) + # if has overflow, skip this iteration + if not has_overflow: + # scale the gradients back + for param in fp32_weights: + if param.grad is not None: + param.grad.div_(self.loss_scaler.loss_scale) + if self.grad_clip is not None: + grad_norm = self.clip_grads(fp32_weights) + if grad_norm is not None: + # Add grad norm to the logger + runner.log_buffer.update({'grad_norm': float(grad_norm)}, + runner.outputs['num_samples']) + # update fp32 params + runner.optimizer.step() + # copy fp32 params to the fp16 model + self.copy_params_to_fp16(runner.model, fp32_weights) + self.loss_scaler.update_scale(has_overflow) + if has_overflow: + runner.logger.warning('Check overflow, downscale loss scale ' + f'to {self.loss_scaler.cur_scale}') diff --git a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/modelzoo_level.txt b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/test/train_performance_8p.sh index 78e27659b85b98e87c06f94c769729ad29254fbe..8c64721a0f576429e27b422ce1a7e780506ff5fb 100644 --- a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/test/train_performance_8p.sh @@ -1,186 +1,186 @@ -#!/bin/bash -#export DYNAMIC_OP='ADD#MUL' -#export PYTHONPATH=/autotest/CI_daily/PyTorch_retinanet_precision:$PYTHONPATH -export LANG=en_US.UTF-8 - -path=$(python3 -c "import sys;print(sys.path[-1])") -python_path=$(echo $path | awk -F 'lib' '{print $1}') -chmod -R 777 $python_path - -#当前路径,不需要修改 -cur_path=`pwd` - -#集合通信参数,不需要修改 -#保证rank table file 文件rank_table_8p.json存放在和test同级的configs目录下 -RANK_SIZE=8 -batch_size=64 -#RANK_TABLE_FILE=${cur_path}/../configs/rank_table_8p.json -RANK_ID_START=0 - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -export ASCEND_GLOBAL_LOG_LEVEL=3 - -#基础参数 需要模型审视修改 -#网络名称,同目录名称 -Network="RetinaNet_ID0427_for_PyTorch" -#训练epoch -train_epochs=2 - -#TF2.X独有,不需要修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_8p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is 0 - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --autotune whether to enable autotune, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --autotune* ]];then - autotune=`echo ${para#*=}` - export autotune=$autotune - mv $install_path/fwkacllib/data/rl/Ascend910/custom $install_path/fwkacllib/data/rl/Ascend910/custom_bak - mv $install_path/fwkacllib/data/tiling/Ascend910/custom $install_path/fwkacllib/data/tiling/Ascend910/custom_bak - autotune_dump_path=${cur_path}/output/autotune_dump - mkdir -p ${autotune_dump_path}/GA - mkdir -p ${autotune_dump_path}/rl - cp -rf $install_path/fwkacllib/data/tiling/Ascend910/custom ${autotune_dump_path}/GA/ - cp -rf $install_path/fwkacllib/data/rl/Ascend910/custom ${autotune_dump_path}/RL/ - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --bind_core* ]]; then - bind_core=`echo ${para#*=}` - name_bind="_bindcore" - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -#autotune时,先开启autotune执行单P训练,不需要修改 -if [[ $autotune == True ]]; then - train_full_1p.sh --autotune=$autotune --data_path=$data_path - wait - autotune=False - export autotune=$autotune -fi -mkdir -p $cur_path/../data -ln -snf $data_path/coco $cur_path/../data/ -cp train_retinanet_8p.sh $cur_path/../ - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#设置性能执行1个epoch -sed -i '/optimizer_config/a\total_epochs = 1\' $cur_path/../configs/retinanet/retinanet_r50_fpn_1x_coco.py - -#进入训练脚本目录 -cd $cur_path/../ -SIll=1 -for((RANK_ID=$RANK_ID_START;RANK_ID<$((SIll+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $RANK_ID" - export RANK_ID=$RANK_ID - export ASCEND_DEVICE_ID=$RANK_ID - ASCEND_DEVICE_ID=$RANK_ID - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - bash train_retinanet_8p.sh > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 - - #python3 ./tools/train.py configs/retinanet/retinanet_r50_fpn_1x_coco.py \ - # --launcher pytorch \ - # --cfg-options optimizer.lr=0.038\ - # --seed 0 \ - # --gpu-ids 0 \ - # --no-validate \ - # --opt-level O1 \ - # > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -done -wait - -#还原 -sed -i "s|total_epochs = 1| |g" $cur_path/../configs/retinanet/retinanet_r50_fpn_1x_coco.py - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) -echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}${name_bind}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据 -grep "time:" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log > traintime.log -sed -i '1,10d' traintime.log -TrainingTime=`cat traintime.log | grep "time:" |awk '{sum+=$15} END {print sum/NR}'` -temp1=`echo "8 * ${batch_size}"|bc` -ActualFPS=`echo "scale=2;${temp1} / ${TrainingTime}"|bc` - -ActualLoss=`grep "loss:" traintime.log | awk 'END {print $23}'` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash +#export DYNAMIC_OP='ADD#MUL' +#export PYTHONPATH=/autotest/CI_daily/PyTorch_retinanet_precision:$PYTHONPATH +export LANG=en_US.UTF-8 + +path=$(python3 -c "import sys;print(sys.path[-1])") +python_path=$(echo $path | awk -F 'lib' '{print $1}') +chmod -R 777 $python_path + +#当前路径,不需要修改 +cur_path=`pwd` + +#集合通信参数,不需要修改 +#保证rank table file 文件rank_table_8p.json存放在和test同级的configs目录下 +RANK_SIZE=8 +batch_size=64 +#RANK_TABLE_FILE=${cur_path}/../configs/rank_table_8p.json +RANK_ID_START=0 + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +export ASCEND_GLOBAL_LOG_LEVEL=3 + +#基础参数 需要模型审视修改 +#网络名称,同目录名称 +Network="RetinaNet_ID0427_for_PyTorch" +#训练epoch +train_epochs=2 + +#TF2.X独有,不需要修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_8p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is 0 + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --autotune whether to enable autotune, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --autotune* ]];then + autotune=`echo ${para#*=}` + export autotune=$autotune + mv $install_path/fwkacllib/data/rl/Ascend910/custom $install_path/fwkacllib/data/rl/Ascend910/custom_bak + mv $install_path/fwkacllib/data/tiling/Ascend910/custom $install_path/fwkacllib/data/tiling/Ascend910/custom_bak + autotune_dump_path=${cur_path}/output/autotune_dump + mkdir -p ${autotune_dump_path}/GA + mkdir -p ${autotune_dump_path}/rl + cp -rf $install_path/fwkacllib/data/tiling/Ascend910/custom ${autotune_dump_path}/GA/ + cp -rf $install_path/fwkacllib/data/rl/Ascend910/custom ${autotune_dump_path}/RL/ + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --bind_core* ]]; then + bind_core=`echo ${para#*=}` + name_bind="_bindcore" + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +#autotune时,先开启autotune执行单P训练,不需要修改 +if [[ $autotune == True ]]; then + train_full_1p.sh --autotune=$autotune --data_path=$data_path + wait + autotune=False + export autotune=$autotune +fi +mkdir -p $cur_path/../data +ln -snf $data_path/coco $cur_path/../data/ +cp train_retinanet_8p.sh $cur_path/../ + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#设置性能执行1个epoch +sed -i '/optimizer_config/a\total_epochs = 1\' $cur_path/../configs/retinanet/retinanet_r50_fpn_1x_coco.py + +#进入训练脚本目录 +cd $cur_path/../ +SIll=1 +for((RANK_ID=$RANK_ID_START;RANK_ID<$((SIll+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $RANK_ID" + export RANK_ID=$RANK_ID + export ASCEND_DEVICE_ID=$RANK_ID + ASCEND_DEVICE_ID=$RANK_ID + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + bash train_retinanet_8p.sh > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 + + #python3 ./tools/train.py configs/retinanet/retinanet_r50_fpn_1x_coco.py \ + # --launcher pytorch \ + # --cfg-options optimizer.lr=0.038\ + # --seed 0 \ + # --gpu-ids 0 \ + # --no-validate \ + # --opt-level O1 \ + # > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +done +wait + +#还原 +sed -i "s|total_epochs = 1| |g" $cur_path/../configs/retinanet/retinanet_r50_fpn_1x_coco.py + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) +echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}${name_bind}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据 +grep "time:" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log > traintime.log +sed -i '1,10d' traintime.log +TrainingTime=`cat traintime.log | grep "time:" |awk '{sum+=$15} END {print sum/NR}'` +temp1=`echo "8 * ${batch_size}"|bc` +ActualFPS=`echo "scale=2;${temp1} / ${TrainingTime}"|bc` + +ActualLoss=`grep "loss:" traintime.log | awk 'END {print $23}'` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/test/train_retinanet_1p.sh b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/test/train_retinanet_1p.sh index e10b6ca629d50d75b00ac9139161b4d9abae7237..e78d4cc0ffdb69f0b5c542a11131ef333df3ad42 100644 --- a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/test/train_retinanet_1p.sh +++ b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/test/train_retinanet_1p.sh @@ -1,29 +1,29 @@ -#source pt_set_env.sh -rm -rf kernel_meta/ -/usr/local/Ascend/driver/tools/msnpureport -d 0 -g error -/usr/local/Ascend/driver/tools/msnpureport -d 4 -g error -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest - -export ASCEND_SLOG_PRINT_TO_STDOUT=0 -export ASCEND_GLOBAL_LOG_LEVEL=3 -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest -export PTCOPY_ENABLE=1 -export TASK_QUEUE_ENABLE=1 -export DYNAMIC_OP="ADD#MUL" -export COMBINED_ENABLE=1 -export DYNAMIC_COMPILE_ENABLE=0 -export EXPERIMENTAL_DYNAMIC_PARTITION=0 -export ASCEND_GLOBAL_EVENT_ENABLE=0 -#export HCCL_WHITELIST_DISABLE=1 -#export SCALAR_TO_HOST_MEM=1 -#export RANK_SIZE=8 -PORT=29500 ./tools/dist_train.sh configs/retinanet/retinanet_r50_fpn_1x_coco.py 1 --cfg-options optimizer.lr=0.005 --seed 0 --gpu-ids 0 --no-validate --opt-level O1 - - -#export RANK=0 -#python3.7 ./tools/train.py configs/retinanet/retinanet_r50_fpn_1x_coco.py \ -# --cfg-options \ -# optimizer.lr=0.005 \ -# --seed 0 \ -# --gpu-ids 0 \ +#source pt_set_env.sh +rm -rf kernel_meta/ +/usr/local/Ascend/driver/tools/msnpureport -d 0 -g error +/usr/local/Ascend/driver/tools/msnpureport -d 4 -g error +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest + +export ASCEND_SLOG_PRINT_TO_STDOUT=0 +export ASCEND_GLOBAL_LOG_LEVEL=3 +export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest +export PTCOPY_ENABLE=1 +export TASK_QUEUE_ENABLE=1 +export DYNAMIC_OP="ADD#MUL" +export COMBINED_ENABLE=1 +export DYNAMIC_COMPILE_ENABLE=0 +export EXPERIMENTAL_DYNAMIC_PARTITION=0 +export ASCEND_GLOBAL_EVENT_ENABLE=0 +#export HCCL_WHITELIST_DISABLE=1 +#export SCALAR_TO_HOST_MEM=1 +#export RANK_SIZE=8 +PORT=29500 ./tools/dist_train.sh configs/retinanet/retinanet_r50_fpn_1x_coco.py 1 --cfg-options optimizer.lr=0.005 --seed 0 --gpu-ids 0 --no-validate --opt-level O1 + + +#export RANK=0 +#python3.7 ./tools/train.py configs/retinanet/retinanet_r50_fpn_1x_coco.py \ +# --cfg-options \ +# optimizer.lr=0.005 \ +# --seed 0 \ +# --gpu-ids 0 \ # --opt-level O1 & \ No newline at end of file diff --git a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/test/train_retinanet_8p.sh b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/test/train_retinanet_8p.sh index 6bee47313b97dbe6a10541c7a93409942aedefe4..888349cb6dea18f1b6d365b4a2c0ad53b65ab2af 100644 --- a/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/test/train_retinanet_8p.sh +++ b/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch/test/train_retinanet_8p.sh @@ -1,47 +1,47 @@ -#source pt_set_env.sh -rm -rf kernel_meta/ -/usr/local/Ascend/driver/tools/msnpureport -d 0 -g error -/usr/local/Ascend/driver/tools/msnpureport -d 4 -g error -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest - -export ASCEND_SLOG_PRINT_TO_STDOUT=0 -export ASCEND_GLOBAL_LOG_LEVEL=3 -export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest -export PTCOPY_ENABLE=1 -export TASK_QUEUE_ENABLE=1 -export DYNAMIC_OP="ADD#MUL" -export COMBINED_ENABLE=1 -export DYNAMIC_COMPILE_ENABLE=0 -export EXPERIMENTAL_DYNAMIC_PARTITION=0 -export ASCEND_GLOBAL_EVENT_ENABLE=0 -#export HCCL_WHITELIST_DISABLE=1 -#export SCALAR_TO_HOST_MEM=1 -#export RANK_SIZE=8 -PORT=29500 ./tools/dist_train.sh configs/retinanet/retinanet_r50_fpn_1x_coco.py 8 --cfg-options optimizer.lr=0.04 --seed 0 --gpu-ids 0 --no-validate --opt-level O1 - -#KERNEL_NUM=$(($(nproc)/8)) -#for((RANK_ID=0;RANK_ID 1: - mp.spawn(train_8p, nprocs=config.npus, args=(config.npus, config)) - else: - print("config.npus should be greater than 1.") - raise RuntimeError - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - - - # model hyper-parameters - parser.add_argument('--image_size', type=int, default=224) - parser.add_argument('--t', type=int, default=3, help='t for Recurrent step of R2U_Net or R2AttU_Net') - - # training hyper-parameters - parser.add_argument('--img_ch', type=int, default=3) - parser.add_argument('--output_ch', type=int, default=1) - parser.add_argument('--num_epochs', type=int, default=100) - parser.add_argument('--num_epochs_decay', type=int, default=70) - parser.add_argument('--batch_size', type=int, default=16) - parser.add_argument('--num_workers', type=int, default=8*8) - parser.add_argument('--lr', type=float, default=0.0002*8) - parser.add_argument('--beta1', type=float, default=0.5) # momentum1 in Adam - parser.add_argument('--beta2', type=float, default=0.999) # momentum2 in Adam - parser.add_argument('--augmentation_prob', type=float, default=0.4) - - parser.add_argument('--log_step', type=int, default=2) - parser.add_argument('--val_step', type=int, default=2) - - # misc - parser.add_argument('--mode', type=str, default='train') - parser.add_argument('--model_type', type=str, default='U_Net', help='U_Net/R2U_Net/AttU_Net/R2AttU_Net') - parser.add_argument('--data_path', type=str, default='./dataset/') - parser.add_argument('--result_path', type=str, default='./result_8p') - - parser.add_argument('--npus', type=int, default=8) - parser.add_argument('--use_apex', type=int, default=1) - parser.add_argument('--apex_level', type=str, default="O2") - parser.add_argument('--loss_scale', type=float, default=128.) - parser.add_argument('--seed', type=int, default=12345) - parser.add_argument('--world_size', type=int, default=1) - parser.add_argument('--dist_backend', type=str, default="hccl") - parser.add_argument('--display_freq', type=int, default=-1) - - config = parser.parse_args() - main(config) +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import argparse +import os +import random +import numpy as np +import torch.multiprocessing as mp +import torch +from solver_8p import train_8p + +def seed_everything(seed): + random.seed(seed) + os.environ["PYTHONHASHSEED"] = str(seed) + np.random.seed(seed) + torch.manual_seed(seed) + +def main(config): + if config.model_type not in ['U_Net','R2U_Net','AttU_Net','R2AttU_Net']: + print('ERROR!! model_type should be selected in U_Net/R2U_Net/AttU_Net/R2AttU_Net') + print('Your input for model_type was %s'%config.model_type) + return + + # Create directories if not exist + config.result_path = os.path.join(config.result_path,config.model_type) + if not os.path.exists(config.result_path): + os.makedirs(config.result_path) + + config.train_path = os.path.join(config.data_path, "train") + config.valid_path = os.path.join(config.data_path, "valid") + print(config) + + seed_everything(config.seed) + os.environ["MASTER_ADDR"] = "localhost" + os.environ["MASTER_PORT"] = "29504" + if config.npus > 1: + mp.spawn(train_8p, nprocs=config.npus, args=(config.npus, config)) + else: + print("config.npus should be greater than 1.") + raise RuntimeError + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + + + # model hyper-parameters + parser.add_argument('--image_size', type=int, default=224) + parser.add_argument('--t', type=int, default=3, help='t for Recurrent step of R2U_Net or R2AttU_Net') + + # training hyper-parameters + parser.add_argument('--img_ch', type=int, default=3) + parser.add_argument('--output_ch', type=int, default=1) + parser.add_argument('--num_epochs', type=int, default=100) + parser.add_argument('--num_epochs_decay', type=int, default=70) + parser.add_argument('--batch_size', type=int, default=16) + parser.add_argument('--num_workers', type=int, default=8*8) + parser.add_argument('--lr', type=float, default=0.0002*8) + parser.add_argument('--beta1', type=float, default=0.5) # momentum1 in Adam + parser.add_argument('--beta2', type=float, default=0.999) # momentum2 in Adam + parser.add_argument('--augmentation_prob', type=float, default=0.4) + + parser.add_argument('--log_step', type=int, default=2) + parser.add_argument('--val_step', type=int, default=2) + + # misc + parser.add_argument('--mode', type=str, default='train') + parser.add_argument('--model_type', type=str, default='U_Net', help='U_Net/R2U_Net/AttU_Net/R2AttU_Net') + parser.add_argument('--data_path', type=str, default='./dataset/') + parser.add_argument('--result_path', type=str, default='./result_8p') + + parser.add_argument('--npus', type=int, default=8) + parser.add_argument('--use_apex', type=int, default=1) + parser.add_argument('--apex_level', type=str, default="O2") + parser.add_argument('--loss_scale', type=float, default=128.) + parser.add_argument('--seed', type=int, default=12345) + parser.add_argument('--world_size', type=int, default=1) + parser.add_argument('--dist_backend', type=str, default="hccl") + parser.add_argument('--display_freq', type=int, default=-1) + + config = parser.parse_args() + main(config) diff --git a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/misc.py b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/misc.py index 8e4f3a65b1091a33d7042ce763ce8a295f322b02..73e81baaca39f450144a2c67ab1143678bdbed1c 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/misc.py +++ b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/misc.py @@ -1,50 +1,50 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█'): - """ - Call in a loop to create terminal progress bar - @params: - iteration - Required : current iteration (Int) - total - Required : total iterations (Int) - prefix - Optional : prefix string (Str) - suffix - Optional : suffix string (Str) - decimals - Optional : positive number of decimals in percent complete (Int) - length - Optional : character length of bar (Int) - fill - Optional : bar fill character (Str) - """ - percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total))) - filledLength = int(length * iteration // total) - bar = fill * filledLength + '-' * (length - filledLength) - print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end = '\r') - # Print New Line on Complete - if iteration == total: +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█'): + """ + Call in a loop to create terminal progress bar + @params: + iteration - Required : current iteration (Int) + total - Required : total iterations (Int) + prefix - Optional : prefix string (Str) + suffix - Optional : suffix string (Str) + decimals - Optional : positive number of decimals in percent complete (Int) + length - Optional : character length of bar (Int) + fill - Optional : bar fill character (Str) + """ + percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total))) + filledLength = int(length * iteration // total) + bar = fill * filledLength + '-' * (length - filledLength) + print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end = '\r') + # Print New Line on Complete + if iteration == total: print() \ No newline at end of file diff --git a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/modelzoo_level.txt b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/network.py b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/network.py index eca56f55532f569eb45ed1b2add27078c8d669ba..674e9bd583c37ecabd4eb4e4dae0ac81c0a8f7d8 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/network.py +++ b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/network.py @@ -1,456 +1,456 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import torch -import torch.nn as nn -import torch.nn.functional as F -from torch.nn import init - -def init_weights(net, init_type='normal', gain=0.02): - def init_func(m): - classname = m.__class__.__name__ - if hasattr(m, 'weight') and (classname.find('Conv') != -1 or classname.find('Linear') != -1): - if init_type == 'normal': - init.normal_(m.weight.data, 0.0, gain) - elif init_type == 'xavier': - init.xavier_normal_(m.weight.data, gain=gain) - elif init_type == 'kaiming': - init.kaiming_normal_(m.weight.data, a=0, mode='fan_in') - elif init_type == 'orthogonal': - init.orthogonal_(m.weight.data, gain=gain) - else: - raise NotImplementedError('initialization method [%s] is not implemented' % init_type) - if hasattr(m, 'bias') and m.bias is not None: - init.constant_(m.bias.data, 0.0) - elif classname.find('BatchNorm2d') != -1: - init.normal_(m.weight.data, 1.0, gain) - init.constant_(m.bias.data, 0.0) - - print('initialize network with %s' % init_type) - net.apply(init_func) - -class conv_block(nn.Module): - def __init__(self,ch_in,ch_out): - super(conv_block,self).__init__() - self.conv = nn.Sequential( - nn.Conv2d(ch_in, ch_out, kernel_size=3,stride=1,padding=1,bias=True), - nn.BatchNorm2d(ch_out), - nn.ReLU(inplace=True), - nn.Conv2d(ch_out, ch_out, kernel_size=3,stride=1,padding=1,bias=True), - nn.BatchNorm2d(ch_out), - nn.ReLU(inplace=True) - ) - - - def forward(self,x): - x = self.conv(x) - return x - -class up_conv(nn.Module): - def __init__(self,ch_in,ch_out): - super(up_conv,self).__init__() - self.up = nn.Sequential( - nn.Upsample(scale_factor=2), - nn.Conv2d(ch_in,ch_out,kernel_size=3,stride=1,padding=1,bias=True), - nn.BatchNorm2d(ch_out), - nn.ReLU(inplace=True) - ) - - def forward(self,x): - x = self.up(x) - return x - -class Recurrent_block(nn.Module): - def __init__(self,ch_out,t=2): - super(Recurrent_block,self).__init__() - self.t = t - self.ch_out = ch_out - self.conv = nn.Sequential( - nn.Conv2d(ch_out,ch_out,kernel_size=3,stride=1,padding=1,bias=True), - nn.BatchNorm2d(ch_out), - nn.ReLU(inplace=True) - ) - - def forward(self,x): - for i in range(self.t): - - if i==0: - x1 = self.conv(x) - - x1 = self.conv(x+x1) - return x1 - -class RRCNN_block(nn.Module): - def __init__(self,ch_in,ch_out,t=2): - super(RRCNN_block,self).__init__() - self.RCNN = nn.Sequential( - Recurrent_block(ch_out,t=t), - Recurrent_block(ch_out,t=t) - ) - self.Conv_1x1 = nn.Conv2d(ch_in,ch_out,kernel_size=1,stride=1,padding=0) - - def forward(self,x): - x = self.Conv_1x1(x) - x1 = self.RCNN(x) - return x+x1 - - -class single_conv(nn.Module): - def __init__(self,ch_in,ch_out): - super(single_conv,self).__init__() - self.conv = nn.Sequential( - nn.Conv2d(ch_in, ch_out, kernel_size=3,stride=1,padding=1,bias=True), - nn.BatchNorm2d(ch_out), - nn.ReLU(inplace=True) - ) - - def forward(self,x): - x = self.conv(x) - return x - -class Attention_block(nn.Module): - def __init__(self,F_g,F_l,F_int): - super(Attention_block,self).__init__() - self.W_g = nn.Sequential( - nn.Conv2d(F_g, F_int, kernel_size=1,stride=1,padding=0,bias=True), - nn.BatchNorm2d(F_int) - ) - - self.W_x = nn.Sequential( - nn.Conv2d(F_l, F_int, kernel_size=1,stride=1,padding=0,bias=True), - nn.BatchNorm2d(F_int) - ) - - self.psi = nn.Sequential( - nn.Conv2d(F_int, 1, kernel_size=1,stride=1,padding=0,bias=True), - nn.BatchNorm2d(1), - nn.Sigmoid() - ) - - self.relu = nn.ReLU(inplace=True) - - def forward(self,g,x): - g1 = self.W_g(g) - x1 = self.W_x(x) - psi = self.relu(g1+x1) - psi = self.psi(psi) - - return x*psi - - -class U_Net(nn.Module): - def __init__(self,img_ch=3,output_ch=1): - super(U_Net,self).__init__() - - self.Maxpool = nn.MaxPool2d(kernel_size=2,stride=2) - - self.Conv1 = conv_block(ch_in=img_ch,ch_out=64) - self.Conv2 = conv_block(ch_in=64,ch_out=128) - self.Conv3 = conv_block(ch_in=128,ch_out=256) - self.Conv4 = conv_block(ch_in=256,ch_out=512) - self.Conv5 = conv_block(ch_in=512,ch_out=1024) - - self.Up5 = up_conv(ch_in=1024,ch_out=512) - self.Up_conv5 = conv_block(ch_in=1024, ch_out=512) - - self.Up4 = up_conv(ch_in=512,ch_out=256) - self.Up_conv4 = conv_block(ch_in=512, ch_out=256) - - self.Up3 = up_conv(ch_in=256,ch_out=128) - self.Up_conv3 = conv_block(ch_in=256, ch_out=128) - - self.Up2 = up_conv(ch_in=128,ch_out=64) - self.Up_conv2 = conv_block(ch_in=128, ch_out=64) - - self.Conv_1x1 = nn.Conv2d(64,output_ch,kernel_size=1,stride=1,padding=0) - - - def forward(self,x): - # encoding path - x1 = self.Conv1(x) - - x2 = self.Maxpool(x1) - x2 = self.Conv2(x2) - - x3 = self.Maxpool(x2) - x3 = self.Conv3(x3) - - x4 = self.Maxpool(x3) - x4 = self.Conv4(x4) - - x5 = self.Maxpool(x4) - x5 = self.Conv5(x5) - - # decoding + concat path - d5 = self.Up5(x5) - d5 = torch.cat((x4,d5),dim=1) - - d5 = self.Up_conv5(d5) - - d4 = self.Up4(d5) - d4 = torch.cat((x3,d4),dim=1) - d4 = self.Up_conv4(d4) - - d3 = self.Up3(d4) - d3 = torch.cat((x2,d3),dim=1) - d3 = self.Up_conv3(d3) - - d2 = self.Up2(d3) - d2 = torch.cat((x1,d2),dim=1) - d2 = self.Up_conv2(d2) - - d1 = self.Conv_1x1(d2) - - return d1 - - -class R2U_Net(nn.Module): - def __init__(self,img_ch=3,output_ch=1,t=2): - super(R2U_Net,self).__init__() - - self.Maxpool = nn.MaxPool2d(kernel_size=2,stride=2) - self.Upsample = nn.Upsample(scale_factor=2) - - self.RRCNN1 = RRCNN_block(ch_in=img_ch,ch_out=64,t=t) - - self.RRCNN2 = RRCNN_block(ch_in=64,ch_out=128,t=t) - - self.RRCNN3 = RRCNN_block(ch_in=128,ch_out=256,t=t) - - self.RRCNN4 = RRCNN_block(ch_in=256,ch_out=512,t=t) - - self.RRCNN5 = RRCNN_block(ch_in=512,ch_out=1024,t=t) - - - self.Up5 = up_conv(ch_in=1024,ch_out=512) - self.Up_RRCNN5 = RRCNN_block(ch_in=1024, ch_out=512,t=t) - - self.Up4 = up_conv(ch_in=512,ch_out=256) - self.Up_RRCNN4 = RRCNN_block(ch_in=512, ch_out=256,t=t) - - self.Up3 = up_conv(ch_in=256,ch_out=128) - self.Up_RRCNN3 = RRCNN_block(ch_in=256, ch_out=128,t=t) - - self.Up2 = up_conv(ch_in=128,ch_out=64) - self.Up_RRCNN2 = RRCNN_block(ch_in=128, ch_out=64,t=t) - - self.Conv_1x1 = nn.Conv2d(64,output_ch,kernel_size=1,stride=1,padding=0) - - - def forward(self,x): - # encoding path - x1 = self.RRCNN1(x) - - x2 = self.Maxpool(x1) - x2 = self.RRCNN2(x2) - - x3 = self.Maxpool(x2) - x3 = self.RRCNN3(x3) - - x4 = self.Maxpool(x3) - x4 = self.RRCNN4(x4) - - x5 = self.Maxpool(x4) - x5 = self.RRCNN5(x5) - - # decoding + concat path - d5 = self.Up5(x5) - d5 = torch.cat((x4,d5),dim=1) - d5 = self.Up_RRCNN5(d5) - - d4 = self.Up4(d5) - d4 = torch.cat((x3,d4),dim=1) - d4 = self.Up_RRCNN4(d4) - - d3 = self.Up3(d4) - d3 = torch.cat((x2,d3),dim=1) - d3 = self.Up_RRCNN3(d3) - - d2 = self.Up2(d3) - d2 = torch.cat((x1,d2),dim=1) - d2 = self.Up_RRCNN2(d2) - - d1 = self.Conv_1x1(d2) - - return d1 - - - -class AttU_Net(nn.Module): - def __init__(self,img_ch=3,output_ch=1): - super(AttU_Net,self).__init__() - - self.Maxpool = nn.MaxPool2d(kernel_size=2,stride=2) - - self.Conv1 = conv_block(ch_in=img_ch,ch_out=64) - self.Conv2 = conv_block(ch_in=64,ch_out=128) - self.Conv3 = conv_block(ch_in=128,ch_out=256) - self.Conv4 = conv_block(ch_in=256,ch_out=512) - self.Conv5 = conv_block(ch_in=512,ch_out=1024) - - self.Up5 = up_conv(ch_in=1024,ch_out=512) - self.Att5 = Attention_block(F_g=512,F_l=512,F_int=256) - self.Up_conv5 = conv_block(ch_in=1024, ch_out=512) - - self.Up4 = up_conv(ch_in=512,ch_out=256) - self.Att4 = Attention_block(F_g=256,F_l=256,F_int=128) - self.Up_conv4 = conv_block(ch_in=512, ch_out=256) - - self.Up3 = up_conv(ch_in=256,ch_out=128) - self.Att3 = Attention_block(F_g=128,F_l=128,F_int=64) - self.Up_conv3 = conv_block(ch_in=256, ch_out=128) - - self.Up2 = up_conv(ch_in=128,ch_out=64) - self.Att2 = Attention_block(F_g=64,F_l=64,F_int=32) - self.Up_conv2 = conv_block(ch_in=128, ch_out=64) - - self.Conv_1x1 = nn.Conv2d(64,output_ch,kernel_size=1,stride=1,padding=0) - - - def forward(self,x): - # encoding path - x1 = self.Conv1(x) - - x2 = self.Maxpool(x1) - x2 = self.Conv2(x2) - - x3 = self.Maxpool(x2) - x3 = self.Conv3(x3) - - x4 = self.Maxpool(x3) - x4 = self.Conv4(x4) - - x5 = self.Maxpool(x4) - x5 = self.Conv5(x5) - - # decoding + concat path - d5 = self.Up5(x5) - x4 = self.Att5(g=d5,x=x4) - d5 = torch.cat((x4,d5),dim=1) - d5 = self.Up_conv5(d5) - - d4 = self.Up4(d5) - x3 = self.Att4(g=d4,x=x3) - d4 = torch.cat((x3,d4),dim=1) - d4 = self.Up_conv4(d4) - - d3 = self.Up3(d4) - x2 = self.Att3(g=d3,x=x2) - d3 = torch.cat((x2,d3),dim=1) - d3 = self.Up_conv3(d3) - - d2 = self.Up2(d3) - x1 = self.Att2(g=d2,x=x1) - d2 = torch.cat((x1,d2),dim=1) - d2 = self.Up_conv2(d2) - - d1 = self.Conv_1x1(d2) - - return d1 - - -class R2AttU_Net(nn.Module): - def __init__(self,img_ch=3,output_ch=1,t=2): - super(R2AttU_Net,self).__init__() - - self.Maxpool = nn.MaxPool2d(kernel_size=2,stride=2) - self.Upsample = nn.Upsample(scale_factor=2) - - self.RRCNN1 = RRCNN_block(ch_in=img_ch,ch_out=64,t=t) - - self.RRCNN2 = RRCNN_block(ch_in=64,ch_out=128,t=t) - - self.RRCNN3 = RRCNN_block(ch_in=128,ch_out=256,t=t) - - self.RRCNN4 = RRCNN_block(ch_in=256,ch_out=512,t=t) - - self.RRCNN5 = RRCNN_block(ch_in=512,ch_out=1024,t=t) - - - self.Up5 = up_conv(ch_in=1024,ch_out=512) - self.Att5 = Attention_block(F_g=512,F_l=512,F_int=256) - self.Up_RRCNN5 = RRCNN_block(ch_in=1024, ch_out=512,t=t) - - self.Up4 = up_conv(ch_in=512,ch_out=256) - self.Att4 = Attention_block(F_g=256,F_l=256,F_int=128) - self.Up_RRCNN4 = RRCNN_block(ch_in=512, ch_out=256,t=t) - - self.Up3 = up_conv(ch_in=256,ch_out=128) - self.Att3 = Attention_block(F_g=128,F_l=128,F_int=64) - self.Up_RRCNN3 = RRCNN_block(ch_in=256, ch_out=128,t=t) - - self.Up2 = up_conv(ch_in=128,ch_out=64) - self.Att2 = Attention_block(F_g=64,F_l=64,F_int=32) - self.Up_RRCNN2 = RRCNN_block(ch_in=128, ch_out=64,t=t) - - self.Conv_1x1 = nn.Conv2d(64,output_ch,kernel_size=1,stride=1,padding=0) - - - def forward(self,x): - # encoding path - x1 = self.RRCNN1(x) - - x2 = self.Maxpool(x1) - x2 = self.RRCNN2(x2) - - x3 = self.Maxpool(x2) - x3 = self.RRCNN3(x3) - - x4 = self.Maxpool(x3) - x4 = self.RRCNN4(x4) - - x5 = self.Maxpool(x4) - x5 = self.RRCNN5(x5) - - # decoding + concat path - d5 = self.Up5(x5) - x4 = self.Att5(g=d5,x=x4) - d5 = torch.cat((x4,d5),dim=1) - d5 = self.Up_RRCNN5(d5) - - d4 = self.Up4(d5) - x3 = self.Att4(g=d4,x=x3) - d4 = torch.cat((x3,d4),dim=1) - d4 = self.Up_RRCNN4(d4) - - d3 = self.Up3(d4) - x2 = self.Att3(g=d3,x=x2) - d3 = torch.cat((x2,d3),dim=1) - d3 = self.Up_RRCNN3(d3) - - d2 = self.Up2(d3) - x1 = self.Att2(g=d2,x=x1) - d2 = torch.cat((x1,d2),dim=1) - d2 = self.Up_RRCNN2(d2) - - d1 = self.Conv_1x1(d2) - - return d1 +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import torch +import torch.nn as nn +import torch.nn.functional as F +from torch.nn import init + +def init_weights(net, init_type='normal', gain=0.02): + def init_func(m): + classname = m.__class__.__name__ + if hasattr(m, 'weight') and (classname.find('Conv') != -1 or classname.find('Linear') != -1): + if init_type == 'normal': + init.normal_(m.weight.data, 0.0, gain) + elif init_type == 'xavier': + init.xavier_normal_(m.weight.data, gain=gain) + elif init_type == 'kaiming': + init.kaiming_normal_(m.weight.data, a=0, mode='fan_in') + elif init_type == 'orthogonal': + init.orthogonal_(m.weight.data, gain=gain) + else: + raise NotImplementedError('initialization method [%s] is not implemented' % init_type) + if hasattr(m, 'bias') and m.bias is not None: + init.constant_(m.bias.data, 0.0) + elif classname.find('BatchNorm2d') != -1: + init.normal_(m.weight.data, 1.0, gain) + init.constant_(m.bias.data, 0.0) + + print('initialize network with %s' % init_type) + net.apply(init_func) + +class conv_block(nn.Module): + def __init__(self,ch_in,ch_out): + super(conv_block,self).__init__() + self.conv = nn.Sequential( + nn.Conv2d(ch_in, ch_out, kernel_size=3,stride=1,padding=1,bias=True), + nn.BatchNorm2d(ch_out), + nn.ReLU(inplace=True), + nn.Conv2d(ch_out, ch_out, kernel_size=3,stride=1,padding=1,bias=True), + nn.BatchNorm2d(ch_out), + nn.ReLU(inplace=True) + ) + + + def forward(self,x): + x = self.conv(x) + return x + +class up_conv(nn.Module): + def __init__(self,ch_in,ch_out): + super(up_conv,self).__init__() + self.up = nn.Sequential( + nn.Upsample(scale_factor=2), + nn.Conv2d(ch_in,ch_out,kernel_size=3,stride=1,padding=1,bias=True), + nn.BatchNorm2d(ch_out), + nn.ReLU(inplace=True) + ) + + def forward(self,x): + x = self.up(x) + return x + +class Recurrent_block(nn.Module): + def __init__(self,ch_out,t=2): + super(Recurrent_block,self).__init__() + self.t = t + self.ch_out = ch_out + self.conv = nn.Sequential( + nn.Conv2d(ch_out,ch_out,kernel_size=3,stride=1,padding=1,bias=True), + nn.BatchNorm2d(ch_out), + nn.ReLU(inplace=True) + ) + + def forward(self,x): + for i in range(self.t): + + if i==0: + x1 = self.conv(x) + + x1 = self.conv(x+x1) + return x1 + +class RRCNN_block(nn.Module): + def __init__(self,ch_in,ch_out,t=2): + super(RRCNN_block,self).__init__() + self.RCNN = nn.Sequential( + Recurrent_block(ch_out,t=t), + Recurrent_block(ch_out,t=t) + ) + self.Conv_1x1 = nn.Conv2d(ch_in,ch_out,kernel_size=1,stride=1,padding=0) + + def forward(self,x): + x = self.Conv_1x1(x) + x1 = self.RCNN(x) + return x+x1 + + +class single_conv(nn.Module): + def __init__(self,ch_in,ch_out): + super(single_conv,self).__init__() + self.conv = nn.Sequential( + nn.Conv2d(ch_in, ch_out, kernel_size=3,stride=1,padding=1,bias=True), + nn.BatchNorm2d(ch_out), + nn.ReLU(inplace=True) + ) + + def forward(self,x): + x = self.conv(x) + return x + +class Attention_block(nn.Module): + def __init__(self,F_g,F_l,F_int): + super(Attention_block,self).__init__() + self.W_g = nn.Sequential( + nn.Conv2d(F_g, F_int, kernel_size=1,stride=1,padding=0,bias=True), + nn.BatchNorm2d(F_int) + ) + + self.W_x = nn.Sequential( + nn.Conv2d(F_l, F_int, kernel_size=1,stride=1,padding=0,bias=True), + nn.BatchNorm2d(F_int) + ) + + self.psi = nn.Sequential( + nn.Conv2d(F_int, 1, kernel_size=1,stride=1,padding=0,bias=True), + nn.BatchNorm2d(1), + nn.Sigmoid() + ) + + self.relu = nn.ReLU(inplace=True) + + def forward(self,g,x): + g1 = self.W_g(g) + x1 = self.W_x(x) + psi = self.relu(g1+x1) + psi = self.psi(psi) + + return x*psi + + +class U_Net(nn.Module): + def __init__(self,img_ch=3,output_ch=1): + super(U_Net,self).__init__() + + self.Maxpool = nn.MaxPool2d(kernel_size=2,stride=2) + + self.Conv1 = conv_block(ch_in=img_ch,ch_out=64) + self.Conv2 = conv_block(ch_in=64,ch_out=128) + self.Conv3 = conv_block(ch_in=128,ch_out=256) + self.Conv4 = conv_block(ch_in=256,ch_out=512) + self.Conv5 = conv_block(ch_in=512,ch_out=1024) + + self.Up5 = up_conv(ch_in=1024,ch_out=512) + self.Up_conv5 = conv_block(ch_in=1024, ch_out=512) + + self.Up4 = up_conv(ch_in=512,ch_out=256) + self.Up_conv4 = conv_block(ch_in=512, ch_out=256) + + self.Up3 = up_conv(ch_in=256,ch_out=128) + self.Up_conv3 = conv_block(ch_in=256, ch_out=128) + + self.Up2 = up_conv(ch_in=128,ch_out=64) + self.Up_conv2 = conv_block(ch_in=128, ch_out=64) + + self.Conv_1x1 = nn.Conv2d(64,output_ch,kernel_size=1,stride=1,padding=0) + + + def forward(self,x): + # encoding path + x1 = self.Conv1(x) + + x2 = self.Maxpool(x1) + x2 = self.Conv2(x2) + + x3 = self.Maxpool(x2) + x3 = self.Conv3(x3) + + x4 = self.Maxpool(x3) + x4 = self.Conv4(x4) + + x5 = self.Maxpool(x4) + x5 = self.Conv5(x5) + + # decoding + concat path + d5 = self.Up5(x5) + d5 = torch.cat((x4,d5),dim=1) + + d5 = self.Up_conv5(d5) + + d4 = self.Up4(d5) + d4 = torch.cat((x3,d4),dim=1) + d4 = self.Up_conv4(d4) + + d3 = self.Up3(d4) + d3 = torch.cat((x2,d3),dim=1) + d3 = self.Up_conv3(d3) + + d2 = self.Up2(d3) + d2 = torch.cat((x1,d2),dim=1) + d2 = self.Up_conv2(d2) + + d1 = self.Conv_1x1(d2) + + return d1 + + +class R2U_Net(nn.Module): + def __init__(self,img_ch=3,output_ch=1,t=2): + super(R2U_Net,self).__init__() + + self.Maxpool = nn.MaxPool2d(kernel_size=2,stride=2) + self.Upsample = nn.Upsample(scale_factor=2) + + self.RRCNN1 = RRCNN_block(ch_in=img_ch,ch_out=64,t=t) + + self.RRCNN2 = RRCNN_block(ch_in=64,ch_out=128,t=t) + + self.RRCNN3 = RRCNN_block(ch_in=128,ch_out=256,t=t) + + self.RRCNN4 = RRCNN_block(ch_in=256,ch_out=512,t=t) + + self.RRCNN5 = RRCNN_block(ch_in=512,ch_out=1024,t=t) + + + self.Up5 = up_conv(ch_in=1024,ch_out=512) + self.Up_RRCNN5 = RRCNN_block(ch_in=1024, ch_out=512,t=t) + + self.Up4 = up_conv(ch_in=512,ch_out=256) + self.Up_RRCNN4 = RRCNN_block(ch_in=512, ch_out=256,t=t) + + self.Up3 = up_conv(ch_in=256,ch_out=128) + self.Up_RRCNN3 = RRCNN_block(ch_in=256, ch_out=128,t=t) + + self.Up2 = up_conv(ch_in=128,ch_out=64) + self.Up_RRCNN2 = RRCNN_block(ch_in=128, ch_out=64,t=t) + + self.Conv_1x1 = nn.Conv2d(64,output_ch,kernel_size=1,stride=1,padding=0) + + + def forward(self,x): + # encoding path + x1 = self.RRCNN1(x) + + x2 = self.Maxpool(x1) + x2 = self.RRCNN2(x2) + + x3 = self.Maxpool(x2) + x3 = self.RRCNN3(x3) + + x4 = self.Maxpool(x3) + x4 = self.RRCNN4(x4) + + x5 = self.Maxpool(x4) + x5 = self.RRCNN5(x5) + + # decoding + concat path + d5 = self.Up5(x5) + d5 = torch.cat((x4,d5),dim=1) + d5 = self.Up_RRCNN5(d5) + + d4 = self.Up4(d5) + d4 = torch.cat((x3,d4),dim=1) + d4 = self.Up_RRCNN4(d4) + + d3 = self.Up3(d4) + d3 = torch.cat((x2,d3),dim=1) + d3 = self.Up_RRCNN3(d3) + + d2 = self.Up2(d3) + d2 = torch.cat((x1,d2),dim=1) + d2 = self.Up_RRCNN2(d2) + + d1 = self.Conv_1x1(d2) + + return d1 + + + +class AttU_Net(nn.Module): + def __init__(self,img_ch=3,output_ch=1): + super(AttU_Net,self).__init__() + + self.Maxpool = nn.MaxPool2d(kernel_size=2,stride=2) + + self.Conv1 = conv_block(ch_in=img_ch,ch_out=64) + self.Conv2 = conv_block(ch_in=64,ch_out=128) + self.Conv3 = conv_block(ch_in=128,ch_out=256) + self.Conv4 = conv_block(ch_in=256,ch_out=512) + self.Conv5 = conv_block(ch_in=512,ch_out=1024) + + self.Up5 = up_conv(ch_in=1024,ch_out=512) + self.Att5 = Attention_block(F_g=512,F_l=512,F_int=256) + self.Up_conv5 = conv_block(ch_in=1024, ch_out=512) + + self.Up4 = up_conv(ch_in=512,ch_out=256) + self.Att4 = Attention_block(F_g=256,F_l=256,F_int=128) + self.Up_conv4 = conv_block(ch_in=512, ch_out=256) + + self.Up3 = up_conv(ch_in=256,ch_out=128) + self.Att3 = Attention_block(F_g=128,F_l=128,F_int=64) + self.Up_conv3 = conv_block(ch_in=256, ch_out=128) + + self.Up2 = up_conv(ch_in=128,ch_out=64) + self.Att2 = Attention_block(F_g=64,F_l=64,F_int=32) + self.Up_conv2 = conv_block(ch_in=128, ch_out=64) + + self.Conv_1x1 = nn.Conv2d(64,output_ch,kernel_size=1,stride=1,padding=0) + + + def forward(self,x): + # encoding path + x1 = self.Conv1(x) + + x2 = self.Maxpool(x1) + x2 = self.Conv2(x2) + + x3 = self.Maxpool(x2) + x3 = self.Conv3(x3) + + x4 = self.Maxpool(x3) + x4 = self.Conv4(x4) + + x5 = self.Maxpool(x4) + x5 = self.Conv5(x5) + + # decoding + concat path + d5 = self.Up5(x5) + x4 = self.Att5(g=d5,x=x4) + d5 = torch.cat((x4,d5),dim=1) + d5 = self.Up_conv5(d5) + + d4 = self.Up4(d5) + x3 = self.Att4(g=d4,x=x3) + d4 = torch.cat((x3,d4),dim=1) + d4 = self.Up_conv4(d4) + + d3 = self.Up3(d4) + x2 = self.Att3(g=d3,x=x2) + d3 = torch.cat((x2,d3),dim=1) + d3 = self.Up_conv3(d3) + + d2 = self.Up2(d3) + x1 = self.Att2(g=d2,x=x1) + d2 = torch.cat((x1,d2),dim=1) + d2 = self.Up_conv2(d2) + + d1 = self.Conv_1x1(d2) + + return d1 + + +class R2AttU_Net(nn.Module): + def __init__(self,img_ch=3,output_ch=1,t=2): + super(R2AttU_Net,self).__init__() + + self.Maxpool = nn.MaxPool2d(kernel_size=2,stride=2) + self.Upsample = nn.Upsample(scale_factor=2) + + self.RRCNN1 = RRCNN_block(ch_in=img_ch,ch_out=64,t=t) + + self.RRCNN2 = RRCNN_block(ch_in=64,ch_out=128,t=t) + + self.RRCNN3 = RRCNN_block(ch_in=128,ch_out=256,t=t) + + self.RRCNN4 = RRCNN_block(ch_in=256,ch_out=512,t=t) + + self.RRCNN5 = RRCNN_block(ch_in=512,ch_out=1024,t=t) + + + self.Up5 = up_conv(ch_in=1024,ch_out=512) + self.Att5 = Attention_block(F_g=512,F_l=512,F_int=256) + self.Up_RRCNN5 = RRCNN_block(ch_in=1024, ch_out=512,t=t) + + self.Up4 = up_conv(ch_in=512,ch_out=256) + self.Att4 = Attention_block(F_g=256,F_l=256,F_int=128) + self.Up_RRCNN4 = RRCNN_block(ch_in=512, ch_out=256,t=t) + + self.Up3 = up_conv(ch_in=256,ch_out=128) + self.Att3 = Attention_block(F_g=128,F_l=128,F_int=64) + self.Up_RRCNN3 = RRCNN_block(ch_in=256, ch_out=128,t=t) + + self.Up2 = up_conv(ch_in=128,ch_out=64) + self.Att2 = Attention_block(F_g=64,F_l=64,F_int=32) + self.Up_RRCNN2 = RRCNN_block(ch_in=128, ch_out=64,t=t) + + self.Conv_1x1 = nn.Conv2d(64,output_ch,kernel_size=1,stride=1,padding=0) + + + def forward(self,x): + # encoding path + x1 = self.RRCNN1(x) + + x2 = self.Maxpool(x1) + x2 = self.RRCNN2(x2) + + x3 = self.Maxpool(x2) + x3 = self.RRCNN3(x3) + + x4 = self.Maxpool(x3) + x4 = self.RRCNN4(x4) + + x5 = self.Maxpool(x4) + x5 = self.RRCNN5(x5) + + # decoding + concat path + d5 = self.Up5(x5) + x4 = self.Att5(g=d5,x=x4) + d5 = torch.cat((x4,d5),dim=1) + d5 = self.Up_RRCNN5(d5) + + d4 = self.Up4(d5) + x3 = self.Att4(g=d4,x=x3) + d4 = torch.cat((x3,d4),dim=1) + d4 = self.Up_RRCNN4(d4) + + d3 = self.Up3(d4) + x2 = self.Att3(g=d3,x=x2) + d3 = torch.cat((x2,d3),dim=1) + d3 = self.Up_RRCNN3(d3) + + d2 = self.Up2(d3) + x1 = self.Att2(g=d2,x=x1) + d2 = torch.cat((x1,d2),dim=1) + d2 = self.Up_RRCNN2(d2) + + d1 = self.Conv_1x1(d2) + + return d1 diff --git a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/pthtar2onx.py b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/pthtar2onx.py index ab023b10b422adaafd95bbb88cc2cd4f2cddbfb3..d77aeac03f457f9369df881872fa35a43fcd1fb2 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/pthtar2onx.py +++ b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/pthtar2onx.py @@ -1,55 +1,55 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import torch -import torch.onnx - -from collections import OrderedDict -from network import R2AttU_Net - - -def proc_nodes_module(checkpoint): - new_state_dict = OrderedDict() - for k, v in checkpoint.items(): - if (k[0:7] == "module."): - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - - -def convert(pth_file_path, onnx_file_path): - model_checkpoint = torch.load(pth_file_path, map_location='cpu') - - if list(model_checkpoint.keys())[0].startswith("module."): - model_checkpoint = proc_nodes_module(model_checkpoint) - - model = R2AttU_Net(img_ch=3,output_ch=1,t=2) - model.load_state_dict(model_checkpoint) - model.eval() - print(model) - - input_names = ["actual_input_1"] - output_names = ["output1"] - dummy_input = torch.randn(4, 3, 224, 224) - torch.onnx.export(model, dummy_input, onnx_file_path, input_names=input_names, output_names=output_names, - opset_version=11) - - -if __name__ == "__main__": - src_file_path = "checkpoint.pkl" - dst_file_path = "R2AttU_Net.onnx" +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import torch +import torch.onnx + +from collections import OrderedDict +from network import R2AttU_Net + + +def proc_nodes_module(checkpoint): + new_state_dict = OrderedDict() + for k, v in checkpoint.items(): + if (k[0:7] == "module."): + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + + +def convert(pth_file_path, onnx_file_path): + model_checkpoint = torch.load(pth_file_path, map_location='cpu') + + if list(model_checkpoint.keys())[0].startswith("module."): + model_checkpoint = proc_nodes_module(model_checkpoint) + + model = R2AttU_Net(img_ch=3,output_ch=1,t=2) + model.load_state_dict(model_checkpoint) + model.eval() + print(model) + + input_names = ["actual_input_1"] + output_names = ["output1"] + dummy_input = torch.randn(4, 3, 224, 224) + torch.onnx.export(model, dummy_input, onnx_file_path, input_names=input_names, output_names=output_names, + opset_version=11) + + +if __name__ == "__main__": + src_file_path = "checkpoint.pkl" + dst_file_path = "R2AttU_Net.onnx" convert(src_file_path, dst_file_path) \ No newline at end of file diff --git a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/solver_1p.py b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/solver_1p.py index 77b6f1d583d6b8daf45c85b8c97ee6a183832882..196e4e44c3018df07882c4de1ba7ff7da1b5e6f4 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/solver_1p.py +++ b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/solver_1p.py @@ -1,355 +1,355 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import os -import numpy as np -import time -import datetime -import torch -# import torchvision -from torch import optim -from torch.autograd import Variable -import torch.nn.functional as F -from evaluation import * -from network import U_Net,R2U_Net,AttU_Net,R2AttU_Net -from apex import amp -import apex - -class Solver(object): - def __init__(self, config, train_loader, valid_loader, test_loader): - - # Data loader - self.train_loader = train_loader - self.valid_loader = valid_loader - self.test_loader = test_loader - - # Models - self.unet = None - self.optimizer = None - self.img_ch = config.img_ch - self.output_ch = config.output_ch - self.criterion = torch.nn.BCELoss() - self.augmentation_prob = config.augmentation_prob - - # Hyper-parameters - self.lr = config.lr - self.beta1 = config.beta1 - self.beta2 = config.beta2 - - # Training settings - self.num_epochs = config.num_epochs - self.num_epochs_decay = config.num_epochs_decay - self.batch_size = config.batch_size - self.use_apex = config.use_apex - self.apex_level = config.apex_level - self.loss_scale = config.loss_scale - - # Step size - self.log_step = config.log_step - self.val_step = config.val_step - - # Path - self.result_path = config.result_path - self.mode = config.mode - - self.device = torch.device('npu' if torch.npu.is_available() else 'cpu') - self.model_type = config.model_type - self.test_model_path = config.test_model_path - self.t = config.t - self.pretrain = config.pretrain - self.pretrain_path = config.pretrain_path - self.build_model() - - def build_model(self): - """Build generator and discriminator.""" - if self.model_type =='U_Net': - self.unet = U_Net(img_ch=3,output_ch=1) - elif self.model_type =='R2U_Net': - self.unet = R2U_Net(img_ch=3,output_ch=1,t=self.t) - elif self.model_type =='AttU_Net': - self.unet = AttU_Net(img_ch=3,output_ch=1) - elif self.model_type == 'R2AttU_Net': - self.unet = R2AttU_Net(img_ch=3,output_ch=1,t=self.t) - - if self.pretrain: - self.unet.load_state_dict(torch.load(self.pretrain_path, map_location="cpu"), strict=False) - - self.unet.to(self.device) - if self.mode == "test": - return - # self.optimizer = optim.Adam(list(self.unet.parameters()), - # self.lr, [self.beta1, self.beta2]) - self.optimizer = apex.optimizers.NpuFusedAdam(list(self.unet.parameters()), - self.lr, [self.beta1, self.beta2]) - if self.use_apex: - self.unet, self.optimizer = amp.initialize(self.unet, self.optimizer, - opt_level=self.apex_level,loss_scale=self.loss_scale, combine_grad=True) - - # self.print_network(self.unet, self.model_type) - - def print_network(self, model, name): - """Print out the network information.""" - num_params = 0 - for p in model.parameters(): - num_params += p.numel() - print(model) - print(name) - print("The number of parameters: {}".format(num_params)) - - def to_data(self, x): - """Convert variable to tensor.""" - if torch.npu.is_available(): - x = x.cpu() - return x.data - - def update_lr(self, g_lr, d_lr): - for param_group in self.optimizer.param_groups: - param_group['lr'] = lr - - def reset_grad(self): - """Zero the gradient buffers.""" - self.unet.zero_grad() - - def compute_accuracy(self,SR,GT): - SR_flat = SR.view(-1) - GT_flat = GT.view(-1) - - acc = GT_flat.data.cpu()==(SR_flat.data.cpu()>0.5) - - def tensor2img(self,x): - img = (x[:,0,:,:]>x[:,1,:,:]).float() - img = img*255 - return img - - - def train(self): - """Train encoder, generator and discriminator.""" - - #====================================== Training ===========================================# - #===========================================================================================# - - unet_path = os.path.join(self.result_path, '%s-%d-%.4f-%d-%.4f.pkl' %(self.model_type,self.num_epochs,self.lr,self.num_epochs_decay,self.augmentation_prob)) - - # U-Net Train - # Train for Encoder - lr = self.lr - best_unet_score = 0. - - for epoch in range(self.num_epochs): - - self.unet.train(True) - epoch_loss = 0 - - acc = 0. # Accuracy - SE = 0. # Sensitivity (Recall) - SP = 0. # Specificity - PC = 0. # Precision - F1 = 0. # F1 Score - JS = 0. # Jaccard Similarity - DC = 0. # Dice Coefficient - length = 0 - threshold = 0.5 - steps = len(self.train_loader) - for i, (images, GT) in enumerate(self.train_loader): - # GT : Ground Truth - if i > 10: - start_time = time.time() - images = images.to(self.device) - GT = GT.to(self.device) - - # SR : Segmentation Result - SR = self.unet(images) - SR_probs = F.sigmoid(SR) - SR_flat = SR_probs.view(SR_probs.size(0),-1) - - GT_flat = GT.view(GT.size(0),-1) - loss = self.criterion(SR_flat,GT_flat) - epoch_loss += loss.item() - - # Backprop + optimize - self.reset_grad() - if self.use_apex: - with amp.scale_loss(loss, self.optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - self.optimizer.step() - - SR_ac = SR > threshold - GT_ac = GT == torch.max(GT) - acc += get_accuracy(SR_ac, GT_ac) - SE += get_sensitivity(SR_ac, GT_ac) - SP += get_specificity(SR_ac, GT_ac) - PC += get_precision(SR_ac, GT_ac) - F1 += get_F1(SR_ac, GT_ac) - JS += get_JS(SR_ac, GT_ac) - DC += get_DC(SR_ac, GT_ac) - length += 1 - - acc = acc/length - SE = SE/length - SP = SP/length - PC = PC/length - F1 = F1/length - JS = JS/length - DC = DC/length - - # Print the log info - print('Epoch [%d/%d], Loss: %.4f, [Training] Acc: %.4f, SE: %.4f, SP: %.4f, PC: %.4f, F1: %.4f, JS: %.4f, DC: %.4f, FPS: %.3f' % ( - epoch+1, self.num_epochs, \ - epoch_loss,acc,SE,SP,PC,F1,JS,DC, self.batch_size*(steps-10)/(time.time() - start_time))) - - - - # Decay learning rate - if (epoch+1) > (self.num_epochs - self.num_epochs_decay): - lr -= (self.lr / float(self.num_epochs_decay)) - for param_group in self.optimizer.param_groups: - param_group['lr'] = lr - print ('Decay learning rate to lr: {}.'.format(lr)) - - - #===================================== Validation ====================================# - self.unet.eval() - - acc = 0. # Accuracy - SE = 0. # Sensitivity (Recall) - SP = 0. # Specificity - PC = 0. # Precision - F1 = 0. # F1 Score - JS = 0. # Jaccard Similarity - DC = 0. # Dice Coefficient - length=0 - for i, (images, GT) in enumerate(self.valid_loader): - - images = images.to(self.device) - GT = GT.to(self.device) - SR = F.sigmoid(self.unet(images)) - - SR_ac = SR > threshold - GT_ac = GT == torch.max(GT) - acc += get_accuracy(SR_ac, GT_ac) - SE += get_sensitivity(SR_ac, GT_ac) - SP += get_specificity(SR_ac, GT_ac) - PC += get_precision(SR_ac, GT_ac) - F1 += get_F1(SR_ac, GT_ac) - JS += get_JS(SR_ac, GT_ac) - DC += get_DC(SR_ac, GT_ac) - - length += 1 - - acc = acc/length - SE = SE/length - SP = SP/length - PC = PC/length - F1 = F1/length - JS = JS/length - DC = DC/length - unet_score = JS + DC - - print('[Validation] Acc: %.4f, SE: %.4f, SP: %.4f, PC: %.4f, F1: %.4f, JS: %.4f, DC: %.4f'%(acc,SE,SP,PC,F1,JS,DC)) - - ''' - torchvision.utils.save_image(images.data.cpu(), - os.path.join(self.result_path, - '%s_valid_%d_image.png'%(self.model_type,epoch+1))) - torchvision.utils.save_image(SR.data.cpu(), - os.path.join(self.result_path, - '%s_valid_%d_SR.png'%(self.model_type,epoch+1))) - torchvision.utils.save_image(GT.data.cpu(), - os.path.join(self.result_path, - '%s_valid_%d_GT.png'%(self.model_type,epoch+1))) - ''' - - - # Save Best U-Net model - if unet_score > best_unet_score: - best_unet_score = unet_score - best_epoch = epoch - best_unet = self.unet.state_dict() - print('Best %s model score : %.4f'%(self.model_type,best_unet_score)) - torch.save(best_unet,unet_path) - - print("Validation Best ", [self.model_type,acc,SE,SP,PC,F1,JS,DC,self.lr,best_epoch,self.num_epochs,self.num_epochs_decay,self.augmentation_prob]) - - #===================================== Test ====================================# - def test(self): - threshold = 0.5 - pre_dict = torch.load(self.test_model_path) - new_dict = {} - if list(pre_dict.keys())[0].startswith("module"): - for key, value in pre_dict.items(): - name = key[7:] - new_dict[name] = value - else: - new_dict = pre_dict - self.unet.load_state_dict(new_dict) - self.unet.eval() - - acc = 0. # Accuracy - SE = 0. # Sensitivity (Recall) - SP = 0. # Specificity - PC = 0. # Precision - F1 = 0. # F1 Score - JS = 0. # Jaccard Similarity - DC = 0. # Dice Coefficient - length=0 - for i, (images, GT) in enumerate(self.test_loader): - - images = images.to(self.device) - GT = GT.to(self.device) - SR = F.sigmoid(self.unet(images)) - SR_ac = SR > threshold - GT_ac = GT == torch.max(GT) - acc += get_accuracy(SR_ac, GT_ac) - SE += get_sensitivity(SR_ac, GT_ac) - SP += get_specificity(SR_ac, GT_ac) - PC += get_precision(SR_ac, GT_ac) - F1 += get_F1(SR_ac, GT_ac) - JS += get_JS(SR_ac, GT_ac) - DC += get_DC(SR_ac, GT_ac) - - length += 1 - - acc = acc/length - SE = SE/length - SP = SP/length - PC = PC/length - F1 = F1/length - JS = JS/length - DC = DC/length - unet_score = JS + DC - print("Test finished, model checkpoint name:",self.test_model_path, " and acc: %.3f " % (acc)) - - - - - +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import os +import numpy as np +import time +import datetime +import torch +# import torchvision +from torch import optim +from torch.autograd import Variable +import torch.nn.functional as F +from evaluation import * +from network import U_Net,R2U_Net,AttU_Net,R2AttU_Net +from apex import amp +import apex + +class Solver(object): + def __init__(self, config, train_loader, valid_loader, test_loader): + + # Data loader + self.train_loader = train_loader + self.valid_loader = valid_loader + self.test_loader = test_loader + + # Models + self.unet = None + self.optimizer = None + self.img_ch = config.img_ch + self.output_ch = config.output_ch + self.criterion = torch.nn.BCELoss() + self.augmentation_prob = config.augmentation_prob + + # Hyper-parameters + self.lr = config.lr + self.beta1 = config.beta1 + self.beta2 = config.beta2 + + # Training settings + self.num_epochs = config.num_epochs + self.num_epochs_decay = config.num_epochs_decay + self.batch_size = config.batch_size + self.use_apex = config.use_apex + self.apex_level = config.apex_level + self.loss_scale = config.loss_scale + + # Step size + self.log_step = config.log_step + self.val_step = config.val_step + + # Path + self.result_path = config.result_path + self.mode = config.mode + + self.device = torch.device('npu' if torch.npu.is_available() else 'cpu') + self.model_type = config.model_type + self.test_model_path = config.test_model_path + self.t = config.t + self.pretrain = config.pretrain + self.pretrain_path = config.pretrain_path + self.build_model() + + def build_model(self): + """Build generator and discriminator.""" + if self.model_type =='U_Net': + self.unet = U_Net(img_ch=3,output_ch=1) + elif self.model_type =='R2U_Net': + self.unet = R2U_Net(img_ch=3,output_ch=1,t=self.t) + elif self.model_type =='AttU_Net': + self.unet = AttU_Net(img_ch=3,output_ch=1) + elif self.model_type == 'R2AttU_Net': + self.unet = R2AttU_Net(img_ch=3,output_ch=1,t=self.t) + + if self.pretrain: + self.unet.load_state_dict(torch.load(self.pretrain_path, map_location="cpu"), strict=False) + + self.unet.to(self.device) + if self.mode == "test": + return + # self.optimizer = optim.Adam(list(self.unet.parameters()), + # self.lr, [self.beta1, self.beta2]) + self.optimizer = apex.optimizers.NpuFusedAdam(list(self.unet.parameters()), + self.lr, [self.beta1, self.beta2]) + if self.use_apex: + self.unet, self.optimizer = amp.initialize(self.unet, self.optimizer, + opt_level=self.apex_level,loss_scale=self.loss_scale, combine_grad=True) + + # self.print_network(self.unet, self.model_type) + + def print_network(self, model, name): + """Print out the network information.""" + num_params = 0 + for p in model.parameters(): + num_params += p.numel() + print(model) + print(name) + print("The number of parameters: {}".format(num_params)) + + def to_data(self, x): + """Convert variable to tensor.""" + if torch.npu.is_available(): + x = x.cpu() + return x.data + + def update_lr(self, g_lr, d_lr): + for param_group in self.optimizer.param_groups: + param_group['lr'] = lr + + def reset_grad(self): + """Zero the gradient buffers.""" + self.unet.zero_grad() + + def compute_accuracy(self,SR,GT): + SR_flat = SR.view(-1) + GT_flat = GT.view(-1) + + acc = GT_flat.data.cpu()==(SR_flat.data.cpu()>0.5) + + def tensor2img(self,x): + img = (x[:,0,:,:]>x[:,1,:,:]).float() + img = img*255 + return img + + + def train(self): + """Train encoder, generator and discriminator.""" + + #====================================== Training ===========================================# + #===========================================================================================# + + unet_path = os.path.join(self.result_path, '%s-%d-%.4f-%d-%.4f.pkl' %(self.model_type,self.num_epochs,self.lr,self.num_epochs_decay,self.augmentation_prob)) + + # U-Net Train + # Train for Encoder + lr = self.lr + best_unet_score = 0. + + for epoch in range(self.num_epochs): + + self.unet.train(True) + epoch_loss = 0 + + acc = 0. # Accuracy + SE = 0. # Sensitivity (Recall) + SP = 0. # Specificity + PC = 0. # Precision + F1 = 0. # F1 Score + JS = 0. # Jaccard Similarity + DC = 0. # Dice Coefficient + length = 0 + threshold = 0.5 + steps = len(self.train_loader) + for i, (images, GT) in enumerate(self.train_loader): + # GT : Ground Truth + if i > 10: + start_time = time.time() + images = images.to(self.device) + GT = GT.to(self.device) + + # SR : Segmentation Result + SR = self.unet(images) + SR_probs = F.sigmoid(SR) + SR_flat = SR_probs.view(SR_probs.size(0),-1) + + GT_flat = GT.view(GT.size(0),-1) + loss = self.criterion(SR_flat,GT_flat) + epoch_loss += loss.item() + + # Backprop + optimize + self.reset_grad() + if self.use_apex: + with amp.scale_loss(loss, self.optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + self.optimizer.step() + + SR_ac = SR > threshold + GT_ac = GT == torch.max(GT) + acc += get_accuracy(SR_ac, GT_ac) + SE += get_sensitivity(SR_ac, GT_ac) + SP += get_specificity(SR_ac, GT_ac) + PC += get_precision(SR_ac, GT_ac) + F1 += get_F1(SR_ac, GT_ac) + JS += get_JS(SR_ac, GT_ac) + DC += get_DC(SR_ac, GT_ac) + length += 1 + + acc = acc/length + SE = SE/length + SP = SP/length + PC = PC/length + F1 = F1/length + JS = JS/length + DC = DC/length + + # Print the log info + print('Epoch [%d/%d], Loss: %.4f, [Training] Acc: %.4f, SE: %.4f, SP: %.4f, PC: %.4f, F1: %.4f, JS: %.4f, DC: %.4f, FPS: %.3f' % ( + epoch+1, self.num_epochs, \ + epoch_loss,acc,SE,SP,PC,F1,JS,DC, self.batch_size*(steps-10)/(time.time() - start_time))) + + + + # Decay learning rate + if (epoch+1) > (self.num_epochs - self.num_epochs_decay): + lr -= (self.lr / float(self.num_epochs_decay)) + for param_group in self.optimizer.param_groups: + param_group['lr'] = lr + print ('Decay learning rate to lr: {}.'.format(lr)) + + + #===================================== Validation ====================================# + self.unet.eval() + + acc = 0. # Accuracy + SE = 0. # Sensitivity (Recall) + SP = 0. # Specificity + PC = 0. # Precision + F1 = 0. # F1 Score + JS = 0. # Jaccard Similarity + DC = 0. # Dice Coefficient + length=0 + for i, (images, GT) in enumerate(self.valid_loader): + + images = images.to(self.device) + GT = GT.to(self.device) + SR = F.sigmoid(self.unet(images)) + + SR_ac = SR > threshold + GT_ac = GT == torch.max(GT) + acc += get_accuracy(SR_ac, GT_ac) + SE += get_sensitivity(SR_ac, GT_ac) + SP += get_specificity(SR_ac, GT_ac) + PC += get_precision(SR_ac, GT_ac) + F1 += get_F1(SR_ac, GT_ac) + JS += get_JS(SR_ac, GT_ac) + DC += get_DC(SR_ac, GT_ac) + + length += 1 + + acc = acc/length + SE = SE/length + SP = SP/length + PC = PC/length + F1 = F1/length + JS = JS/length + DC = DC/length + unet_score = JS + DC + + print('[Validation] Acc: %.4f, SE: %.4f, SP: %.4f, PC: %.4f, F1: %.4f, JS: %.4f, DC: %.4f'%(acc,SE,SP,PC,F1,JS,DC)) + + ''' + torchvision.utils.save_image(images.data.cpu(), + os.path.join(self.result_path, + '%s_valid_%d_image.png'%(self.model_type,epoch+1))) + torchvision.utils.save_image(SR.data.cpu(), + os.path.join(self.result_path, + '%s_valid_%d_SR.png'%(self.model_type,epoch+1))) + torchvision.utils.save_image(GT.data.cpu(), + os.path.join(self.result_path, + '%s_valid_%d_GT.png'%(self.model_type,epoch+1))) + ''' + + + # Save Best U-Net model + if unet_score > best_unet_score: + best_unet_score = unet_score + best_epoch = epoch + best_unet = self.unet.state_dict() + print('Best %s model score : %.4f'%(self.model_type,best_unet_score)) + torch.save(best_unet,unet_path) + + print("Validation Best ", [self.model_type,acc,SE,SP,PC,F1,JS,DC,self.lr,best_epoch,self.num_epochs,self.num_epochs_decay,self.augmentation_prob]) + + #===================================== Test ====================================# + def test(self): + threshold = 0.5 + pre_dict = torch.load(self.test_model_path) + new_dict = {} + if list(pre_dict.keys())[0].startswith("module"): + for key, value in pre_dict.items(): + name = key[7:] + new_dict[name] = value + else: + new_dict = pre_dict + self.unet.load_state_dict(new_dict) + self.unet.eval() + + acc = 0. # Accuracy + SE = 0. # Sensitivity (Recall) + SP = 0. # Specificity + PC = 0. # Precision + F1 = 0. # F1 Score + JS = 0. # Jaccard Similarity + DC = 0. # Dice Coefficient + length=0 + for i, (images, GT) in enumerate(self.test_loader): + + images = images.to(self.device) + GT = GT.to(self.device) + SR = F.sigmoid(self.unet(images)) + SR_ac = SR > threshold + GT_ac = GT == torch.max(GT) + acc += get_accuracy(SR_ac, GT_ac) + SE += get_sensitivity(SR_ac, GT_ac) + SP += get_specificity(SR_ac, GT_ac) + PC += get_precision(SR_ac, GT_ac) + F1 += get_F1(SR_ac, GT_ac) + JS += get_JS(SR_ac, GT_ac) + DC += get_DC(SR_ac, GT_ac) + + length += 1 + + acc = acc/length + SE = SE/length + SP = SP/length + PC = PC/length + F1 = F1/length + JS = JS/length + DC = DC/length + unet_score = JS + DC + print("Test finished, model checkpoint name:",self.test_model_path, " and acc: %.3f " % (acc)) + + + + + diff --git a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/solver_8p.py b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/solver_8p.py index 32366173763812c1ebb95964e4f915c8efabf6e5..7c8c86da350348dc15cfc1b5783558836f79cece 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/solver_8p.py +++ b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/solver_8p.py @@ -1,181 +1,181 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import os -import numpy as np -import time -import datetime -import torch -# import torchvision -from torch import optim -from torch.autograd import Variable -import torch.nn.functional as F -from evaluation import * -from network import U_Net,R2U_Net,AttU_Net,R2AttU_Net -import torch.distributed as dist -from data_loader import get_dist_loader, get_loader,ImageFolder -from apex import amp -import apex - -def train_8p(rank, npus, config): - rank = rank - dist.init_process_group(backend=config.dist_backend, world_size=config.npus, rank=rank) - torch.npu.set_device(rank) - model_unet = R2AttU_Net(img_ch=3, output_ch=1,t=config.t) - model_unet = model_unet.to("npu") - # optimizer = optim.Adam(list(model_unet.parameters()), config.lr, [config.beta1, config.beta2]) - optimizer = apex.optimizers.NpuFusedAdam(list(model_unet.parameters()), config.lr, [config.beta1, config.beta2]) - - if config.use_apex: - model_unet, optimizer = amp.initialize(model_unet, optimizer, - opt_level=config.apex_level,loss_scale=config.loss_scale, combine_grad=True) - model_unet = torch.nn.parallel.DistributedDataParallel(model_unet, device_ids=[rank], - broadcast_buffers=False) - - train_loader = get_dist_loader(image_path=config.train_path, - image_size=config.image_size, - batch_size=config.batch_size, - num_workers=config.num_workers, - mode='train', - augmentation_prob=config.augmentation_prob) - valid_loader = get_loader(image_path=config.valid_path, - image_size=config.image_size, - batch_size=config.batch_size, - num_workers=config.num_workers, - mode='valid', - augmentation_prob=0.) - criterion = torch.nn.BCELoss() - - lr = config.lr - best_unet_score = 0. - unet_path = os.path.join(config.result_path, '%d-%s-%d-%.4f-%d-%.4f.pkl' %(rank, - config.model_type,config.num_epochs,config.lr,config.num_epochs_decay,config.augmentation_prob)) - - for epoch in range(config.num_epochs): - model_unet.train(True) - epoch_loss = 0. - acc = 0. # Accuracy - length = 0 - threshold = 0.5 - steps = len(train_loader) - for i, (images, GT) in enumerate(train_loader): - # GT : Ground Truth - images = images.to("npu") - GT = GT.to("npu") - if i == 10: - start_time = time.time() - step_start_time = time.time() - # SR : Segmentation Result - SR = model_unet(images) - SR_probs = F.sigmoid(SR) - SR_flat = SR_probs.view(SR_probs.size(0),-1) - - GT_flat = GT.view(GT.size(0),-1) - loss = criterion(SR_flat,GT_flat) - epoch_loss += loss.item() - - # Backprop + optimize - model_unet.zero_grad() - if config.use_apex: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - if rank == 0: - print('Epoch [%d/%d], Step: %d, FPS: %.2f' % ( - epoch+1, config.num_epochs, i, config.npus*config.batch_size/(time.time() - step_start_time))) - SR_ac = SR > threshold - GT_ac = GT == torch.max(GT) - acc += get_accuracy(SR_ac, GT_ac) - length += 1 - - acc = acc/length - - # Print the log info - if rank == 0: - print('Rank %d , Epoch [%d/%d], Loss: %.4f, [Training] Acc: %.4f, FPS: %.2f' % ( - rank, epoch+1, config.num_epochs, epoch_loss, acc , config.batch_size*(steps-10)/(time.time() - start_time))) - # Decay learning rate - if (epoch+1) % 10 == 0: - lr = lr/2. - # lr -= (config.lr / float(config.num_epochs_decay)) - for param_group in optimizer.param_groups: - param_group['lr'] = lr - print ('Decay learning rate to lr: {}.'.format(lr)) - - - #===================================== Validation ====================================# - if rank == 0: - model_unet.eval() - - acc = 0. # Accuracy - length=0 - for i, (images, GT) in enumerate(valid_loader): - - images = images.to("npu") - GT = GT.to("npu") - SR = F.sigmoid(model_unet(images)) - SR_ac = SR > threshold - GT_ac = GT == torch.max(GT) - acc += get_accuracy(SR_ac, GT_ac) - - length += 1 - - acc = acc/length - - unet_score = acc#JS + DC - - print('[Validation] Rank: %d, Epoch %d,Acc: %.4f'%(rank, epoch, acc)) - - ''' - torchvision.utils.save_image(images.data.cpu(), - os.path.join(self.result_path, - '%s_valid_%d_image.png'%(self.model_type,epoch+1))) - torchvision.utils.save_image(SR.data.cpu(), - os.path.join(self.result_path, - '%s_valid_%d_SR.png'%(self.model_type,epoch+1))) - torchvision.utils.save_image(GT.data.cpu(), - os.path.join(self.result_path, - '%s_valid_%d_GT.png'%(self.model_type,epoch+1))) - ''' - - - # Save Best U-Net model - if unet_score > best_unet_score: - best_unet_score = unet_score - best_epoch = epoch - best_unet = model_unet.state_dict() - print('Best %s model score : %.4f'%(config.model_type,best_unet_score)) - torch.save(best_unet,unet_path) - print("Validation Best", [config.model_type,acc,config.lr,best_epoch,\ - config.num_epochs,config.num_epochs_decay,config.augmentation_prob]) +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import os +import numpy as np +import time +import datetime +import torch +# import torchvision +from torch import optim +from torch.autograd import Variable +import torch.nn.functional as F +from evaluation import * +from network import U_Net,R2U_Net,AttU_Net,R2AttU_Net +import torch.distributed as dist +from data_loader import get_dist_loader, get_loader,ImageFolder +from apex import amp +import apex + +def train_8p(rank, npus, config): + rank = rank + dist.init_process_group(backend=config.dist_backend, world_size=config.npus, rank=rank) + torch.npu.set_device(rank) + model_unet = R2AttU_Net(img_ch=3, output_ch=1,t=config.t) + model_unet = model_unet.to("npu") + # optimizer = optim.Adam(list(model_unet.parameters()), config.lr, [config.beta1, config.beta2]) + optimizer = apex.optimizers.NpuFusedAdam(list(model_unet.parameters()), config.lr, [config.beta1, config.beta2]) + + if config.use_apex: + model_unet, optimizer = amp.initialize(model_unet, optimizer, + opt_level=config.apex_level,loss_scale=config.loss_scale, combine_grad=True) + model_unet = torch.nn.parallel.DistributedDataParallel(model_unet, device_ids=[rank], + broadcast_buffers=False) + + train_loader = get_dist_loader(image_path=config.train_path, + image_size=config.image_size, + batch_size=config.batch_size, + num_workers=config.num_workers, + mode='train', + augmentation_prob=config.augmentation_prob) + valid_loader = get_loader(image_path=config.valid_path, + image_size=config.image_size, + batch_size=config.batch_size, + num_workers=config.num_workers, + mode='valid', + augmentation_prob=0.) + criterion = torch.nn.BCELoss() + + lr = config.lr + best_unet_score = 0. + unet_path = os.path.join(config.result_path, '%d-%s-%d-%.4f-%d-%.4f.pkl' %(rank, + config.model_type,config.num_epochs,config.lr,config.num_epochs_decay,config.augmentation_prob)) + + for epoch in range(config.num_epochs): + model_unet.train(True) + epoch_loss = 0. + acc = 0. # Accuracy + length = 0 + threshold = 0.5 + steps = len(train_loader) + for i, (images, GT) in enumerate(train_loader): + # GT : Ground Truth + images = images.to("npu") + GT = GT.to("npu") + if i == 10: + start_time = time.time() + step_start_time = time.time() + # SR : Segmentation Result + SR = model_unet(images) + SR_probs = F.sigmoid(SR) + SR_flat = SR_probs.view(SR_probs.size(0),-1) + + GT_flat = GT.view(GT.size(0),-1) + loss = criterion(SR_flat,GT_flat) + epoch_loss += loss.item() + + # Backprop + optimize + model_unet.zero_grad() + if config.use_apex: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + if rank == 0: + print('Epoch [%d/%d], Step: %d, FPS: %.2f' % ( + epoch+1, config.num_epochs, i, config.npus*config.batch_size/(time.time() - step_start_time))) + SR_ac = SR > threshold + GT_ac = GT == torch.max(GT) + acc += get_accuracy(SR_ac, GT_ac) + length += 1 + + acc = acc/length + + # Print the log info + if rank == 0: + print('Rank %d , Epoch [%d/%d], Loss: %.4f, [Training] Acc: %.4f, FPS: %.2f' % ( + rank, epoch+1, config.num_epochs, epoch_loss, acc , config.batch_size*(steps-10)/(time.time() - start_time))) + # Decay learning rate + if (epoch+1) % 10 == 0: + lr = lr/2. + # lr -= (config.lr / float(config.num_epochs_decay)) + for param_group in optimizer.param_groups: + param_group['lr'] = lr + print ('Decay learning rate to lr: {}.'.format(lr)) + + + #===================================== Validation ====================================# + if rank == 0: + model_unet.eval() + + acc = 0. # Accuracy + length=0 + for i, (images, GT) in enumerate(valid_loader): + + images = images.to("npu") + GT = GT.to("npu") + SR = F.sigmoid(model_unet(images)) + SR_ac = SR > threshold + GT_ac = GT == torch.max(GT) + acc += get_accuracy(SR_ac, GT_ac) + + length += 1 + + acc = acc/length + + unet_score = acc#JS + DC + + print('[Validation] Rank: %d, Epoch %d,Acc: %.4f'%(rank, epoch, acc)) + + ''' + torchvision.utils.save_image(images.data.cpu(), + os.path.join(self.result_path, + '%s_valid_%d_image.png'%(self.model_type,epoch+1))) + torchvision.utils.save_image(SR.data.cpu(), + os.path.join(self.result_path, + '%s_valid_%d_SR.png'%(self.model_type,epoch+1))) + torchvision.utils.save_image(GT.data.cpu(), + os.path.join(self.result_path, + '%s_valid_%d_GT.png'%(self.model_type,epoch+1))) + ''' + + + # Save Best U-Net model + if unet_score > best_unet_score: + best_unet_score = unet_score + best_epoch = epoch + best_unet = model_unet.state_dict() + print('Best %s model score : %.4f'%(config.model_type,best_unet_score)) + torch.save(best_unet,unet_path) + print("Validation Best", [config.model_type,acc,config.lr,best_epoch,\ + config.num_epochs,config.num_epochs_decay,config.augmentation_prob]) \ No newline at end of file diff --git a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/train.py b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/train.py index e605f787b4c349069ec3ed48b2a9630f2ba34146..0a1ebf8c6ed8ebee921f5e4422d2e26e84cc8e7b 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/train.py +++ b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/train.py @@ -1,334 +1,334 @@ -# -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -#from __future__ import print_function -import datetime -import os -import time -import sys - -import torch -import torch.utils.data -from torch import nn -import random -import numpy as np -import utils -import argparse -try: - import apex - from apex import amp -except ImportError: - amp = None -from evaluation import * -from data_loader import get_dist_loader, get_loader -from network import R2AttU_Net - - -def train_one_epoch(model_unet, criterion, optimizer, data_loader, device, epoch, config): - model_unet.train() - metric_logger = utils.MetricLogger(delimiter=" ") - - epoch_loss = 0. - acc = 0. # Accuracy - SE = 0. # Sensitivity (Recall) - SP = 0. # Specificity - PC = 0. # Precision - F1 = 0. # F1 Score - JS = 0. # Jaccard Similarity - DC = 0. # Dice Coefficient - length = 0 - threshold = 0.5 - steps = len(data_loader) - for i, (images, GT) in enumerate(data_loader): - # GT : Ground Truth - images = images.to(device) - GT = GT.to(device) - if i == 5: - start_time = time.time() - - # SR : Segmentation Result - SR = model_unet(images) - SR_probs = torch.nn.functional.sigmoid(SR) - SR_flat = SR_probs.view(SR_probs.size(0),-1) - - GT_flat = GT.view(GT.size(0),-1) - loss = criterion(SR_flat,GT_flat) - epoch_loss += loss.item() - - # Backprop + optimize - model_unet.zero_grad() - if config.use_apex: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - - SR_ac = SR > threshold - GT_ac = GT == torch.max(GT) - acc += get_accuracy(SR_ac, GT_ac) - SE += get_sensitivity(SR_ac, GT_ac) - SP += get_specificity(SR_ac, GT_ac) - PC += get_precision(SR_ac, GT_ac) - F1 += get_F1(SR_ac, GT_ac) - JS += get_JS(SR_ac, GT_ac) - DC += get_DC(SR_ac, GT_ac) - length += 1 - acc = acc/length - - batch_size = config.batch_size - fps = batch_size *(steps-5) / (time.time() - start_time) - metric_logger.update(loss=loss.item(), lr=optimizer.param_groups[0]["lr"]) - metric_logger.meters['acc'].update(acc, n=batch_size) - metric_logger.meters['img/s'].update(fps) - print("Traing, Epoch: %d, Loss: %.4f"%(epoch, loss.item())) - - return acc, fps - - -def evaluate(model_unet, criterion, valid_loader, device): - metric_logger = utils.MetricLogger(delimiter=" ") - model_unet.eval() - threshold = 0.5 - acc = 0. # Accuracy - SE = 0. # Sensitivity (Recall) - SP = 0. # Specificity - PC = 0. # Precision - F1 = 0. # F1 Score - JS = 0. # Jaccard Similarity - DC = 0. # Dice Coefficient - length=0 - for i, (images, GT) in enumerate(valid_loader): - - images = images.to(device) - GT = GT.to(device) - SR = torch.nn.functional.sigmoid(model_unet(images)) - SR_ac = SR > threshold - GT_ac = GT == torch.max(GT) - acc += get_accuracy(SR_ac, GT_ac) - SE += get_sensitivity(SR_ac, GT_ac) - SP += get_specificity(SR_ac, GT_ac) - PC += get_precision(SR_ac, GT_ac) - F1 += get_F1(SR_ac, GT_ac) - JS += get_JS(SR_ac, GT_ac) - DC += get_DC(SR_ac, GT_ac) - metric_logger.synchronize_between_processes(device) - - length += 1 - - acc = acc/length - SE = SE/length - SP = SP/length - PC = PC/length - F1 = F1/length - JS = JS/length - DC = DC/length - unet_score = acc#JS + DC - batch_size = images.shape[0] - metric_logger.meters['acc'].update(acc, n=batch_size) - return acc - -def init_distributed_mode(args): - if 'RANK_SIZE' in os.environ and 'RANK_ID' in os.environ: - args.rank_size = int(os.environ['RANK_SIZE']) - args.rank_id = int(os.environ['RANK_ID']) - args.device_id = args.rank_id - args.batch_size = int(args.batch_size / args.rank_size) - args.num_workers = int((args.num_workers) / args.rank_size) - else: - raise RuntimeError("init_distributed_mode failed.") - - torch.distributed.init_process_group(backend='hccl', - world_size=args.rank_size, rank=args.rank_id) -def main(config): - #设置环境变量 - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = '29688' - - #设置seed - random.seed(1234) - np.random.seed(1234) - torch.manual_seed(1234) - os.environ['PYTHONHASHSEED'] = str(1234) - - if config.use_apex: - if sys.version_info < (3, 0): - raise RuntimeError("Apex currently only supports Python 3. Aborting.") - if amp is None: - raise RuntimeError("Failed to import apex. Please install apex from https://www.github.com/nvidia/apex " - "to enable mixed-precision training.") - - # Create directories if not exist - if not os.path.exists(config.result_path): - os.makedirs(config.result_path) - - if config.distributed: - init_distributed_mode(config) - - config.is_master_node = not config.distributed or config.device_id == 0 - if config.is_master_node: - print(config) - - device = torch.device(f'npu:'+str(config.device_id)) - torch.npu.set_device(device) - - # Data loading code - print("Loading data") - config.train_path = os.path.join(config.data_path, "train") - config.valid_path = os.path.join(config.data_path, "valid") - print("Creating data loaders") - if config.distributed: - train_loader = get_dist_loader(image_path=config.train_path, - image_size=config.image_size, - batch_size=config.batch_size, - num_workers=config.num_workers, - mode='train', - augmentation_prob=config.augmentation_prob) - valid_loader = get_loader(image_path=config.valid_path, - image_size=config.image_size, - batch_size=config.batch_size, - num_workers=config.num_workers, - mode='valid', - augmentation_prob=0.) - else: - train_loader = get_loader(image_path=config.train_path, - image_size=config.image_size, - batch_size=config.batch_size, - num_workers=config.num_workers, - mode='train', - augmentation_prob=config.augmentation_prob) - valid_loader = get_loader(image_path=config.valid_path, - image_size=config.image_size, - batch_size=config.batch_size, - num_workers=config.num_workers, - mode='valid', - augmentation_prob=0.) - model_unet = R2AttU_Net(img_ch=3, output_ch=1,t=config.t) - model_unet = model_unet.to(device) - - criterion = torch.nn.BCELoss() - optimizer = apex.optimizers.NpuFusedAdam(list(model_unet.parameters()), - config.lr, [config.beta1, config.beta2]) - if config.use_apex: - model_unet, optimizer = amp.initialize(model_unet, optimizer, - opt_level=config.apex_level,loss_scale=config.loss_scale, combine_grad=True) - - model_without_ddp = model_unet - if config.distributed: - model_unet = torch.nn.parallel.DistributedDataParallel(model_unet, device_ids=[config.device_id]) - model_without_ddp = model_unet.module - - if config.is_master_node: - print("Start training") - start_time = time.time() - best_unet_score = 0. - lr = config.lr - for epoch in range(config.num_epochs): - acc, fps = train_one_epoch(model_unet, criterion, optimizer, train_loader, device, epoch, config) - - unet_score = evaluate(model_unet, criterion, valid_loader, device=device) - if config.is_master_node: - print("Traing, Epoch: %d, Avgacc: %.3f, FPS: %.2f"%(epoch, acc, fps)) - print('Test, Acc: %.3f'%(unet_score)) - if config.is_master_node and config.result_path: - checkpoint = { - 'model': model_without_ddp.state_dict(), - 'optimizer': optimizer.state_dict(), - 'epoch': epoch, - 'args': config} - utils.save_on_master( - checkpoint, - os.path.join(config.result_path, 'model_{}.pth'.format(epoch))) - if unet_score > best_unet_score: - best_unet_score = unet_score - utils.save_on_master( - checkpoint, - os.path.join(config.result_path, 'checkpoint.pth')) - if (epoch+1) % 10 == 0: - lr = lr/2. - # lr -= (config.lr / float(config.num_epochs_decay)) - for param_group in optimizer.param_groups: - param_group['lr'] = lr - print ('Decay learning rate to lr: {}.'.format(lr)) - - total_time = time.time() - start_time - total_time_str = str(datetime.timedelta(seconds=int(total_time))) - if config.is_master_node: - print('Training time {}'.format(total_time_str)) - exit() - - -def parse_args(): - parser = argparse.ArgumentParser() - - - # model hyper-parameters - parser.add_argument('--image_size', type=int, default=224) - parser.add_argument('--t', type=int, default=3, help='t for Recurrent step of R2U_Net or R2AttU_Net') - - # training hyper-parameters - parser.add_argument('--img_ch', type=int, default=3) - parser.add_argument('--output_ch', type=int, default=1) - parser.add_argument('--num_epochs', type=int, default=100) - parser.add_argument('--num_epochs_decay', type=int, default=70) - parser.add_argument('--batch_size', type=int, default=16) - parser.add_argument('--num_workers', type=int, default=8) - parser.add_argument('--lr', type=float, default=0.0002) - parser.add_argument('--beta1', type=float, default=0.5) # momentum1 in Adam - parser.add_argument('--beta2', type=float, default=0.999) # momentum2 in Adam - parser.add_argument('--augmentation_prob', type=float, default=0.4) - - parser.add_argument('--log_step', type=int, default=2) - parser.add_argument('--val_step', type=int, default=2) - - # misc - parser.add_argument('--mode', type=str, default='train') - parser.add_argument('--model_type', type=str, default='U_Net', help='U_Net/R2U_Net/AttU_Net/R2AttU_Net') - parser.add_argument('--test_model_path', type=str, default='./models') - parser.add_argument('--data_path', type=str, default='./dataset/train/') - parser.add_argument('--result_path', type=str, default='./result_1p') - - parser.add_argument('--device_id', type=int, default=0) - parser.add_argument('--use_apex', type=int, default=1) - parser.add_argument('--apex_level', type=str, default="O2") - parser.add_argument('--loss_scale', type=float, default=128.) - - parser.add_argument('--world_size', type=int, default=8) - parser.add_argument('--distributed', type=int, default=0, - help='Use multi-processing distributed training to launch.') - - config = parser.parse_args() - main(config) - -if __name__ == "__main__": - args = parse_args() - main(args) +# +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +#from __future__ import print_function +import datetime +import os +import time +import sys + +import torch +import torch.utils.data +from torch import nn +import random +import numpy as np +import utils +import argparse +try: + import apex + from apex import amp +except ImportError: + amp = None +from evaluation import * +from data_loader import get_dist_loader, get_loader +from network import R2AttU_Net + + +def train_one_epoch(model_unet, criterion, optimizer, data_loader, device, epoch, config): + model_unet.train() + metric_logger = utils.MetricLogger(delimiter=" ") + + epoch_loss = 0. + acc = 0. # Accuracy + SE = 0. # Sensitivity (Recall) + SP = 0. # Specificity + PC = 0. # Precision + F1 = 0. # F1 Score + JS = 0. # Jaccard Similarity + DC = 0. # Dice Coefficient + length = 0 + threshold = 0.5 + steps = len(data_loader) + for i, (images, GT) in enumerate(data_loader): + # GT : Ground Truth + images = images.to(device) + GT = GT.to(device) + if i == 5: + start_time = time.time() + + # SR : Segmentation Result + SR = model_unet(images) + SR_probs = torch.nn.functional.sigmoid(SR) + SR_flat = SR_probs.view(SR_probs.size(0),-1) + + GT_flat = GT.view(GT.size(0),-1) + loss = criterion(SR_flat,GT_flat) + epoch_loss += loss.item() + + # Backprop + optimize + model_unet.zero_grad() + if config.use_apex: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + + SR_ac = SR > threshold + GT_ac = GT == torch.max(GT) + acc += get_accuracy(SR_ac, GT_ac) + SE += get_sensitivity(SR_ac, GT_ac) + SP += get_specificity(SR_ac, GT_ac) + PC += get_precision(SR_ac, GT_ac) + F1 += get_F1(SR_ac, GT_ac) + JS += get_JS(SR_ac, GT_ac) + DC += get_DC(SR_ac, GT_ac) + length += 1 + acc = acc/length + + batch_size = config.batch_size + fps = batch_size *(steps-5) / (time.time() - start_time) + metric_logger.update(loss=loss.item(), lr=optimizer.param_groups[0]["lr"]) + metric_logger.meters['acc'].update(acc, n=batch_size) + metric_logger.meters['img/s'].update(fps) + print("Traing, Epoch: %d, Loss: %.4f"%(epoch, loss.item())) + + return acc, fps + + +def evaluate(model_unet, criterion, valid_loader, device): + metric_logger = utils.MetricLogger(delimiter=" ") + model_unet.eval() + threshold = 0.5 + acc = 0. # Accuracy + SE = 0. # Sensitivity (Recall) + SP = 0. # Specificity + PC = 0. # Precision + F1 = 0. # F1 Score + JS = 0. # Jaccard Similarity + DC = 0. # Dice Coefficient + length=0 + for i, (images, GT) in enumerate(valid_loader): + + images = images.to(device) + GT = GT.to(device) + SR = torch.nn.functional.sigmoid(model_unet(images)) + SR_ac = SR > threshold + GT_ac = GT == torch.max(GT) + acc += get_accuracy(SR_ac, GT_ac) + SE += get_sensitivity(SR_ac, GT_ac) + SP += get_specificity(SR_ac, GT_ac) + PC += get_precision(SR_ac, GT_ac) + F1 += get_F1(SR_ac, GT_ac) + JS += get_JS(SR_ac, GT_ac) + DC += get_DC(SR_ac, GT_ac) + metric_logger.synchronize_between_processes(device) + + length += 1 + + acc = acc/length + SE = SE/length + SP = SP/length + PC = PC/length + F1 = F1/length + JS = JS/length + DC = DC/length + unet_score = acc#JS + DC + batch_size = images.shape[0] + metric_logger.meters['acc'].update(acc, n=batch_size) + return acc + +def init_distributed_mode(args): + if 'RANK_SIZE' in os.environ and 'RANK_ID' in os.environ: + args.rank_size = int(os.environ['RANK_SIZE']) + args.rank_id = int(os.environ['RANK_ID']) + args.device_id = args.rank_id + args.batch_size = int(args.batch_size / args.rank_size) + args.num_workers = int((args.num_workers) / args.rank_size) + else: + raise RuntimeError("init_distributed_mode failed.") + + torch.distributed.init_process_group(backend='hccl', + world_size=args.rank_size, rank=args.rank_id) +def main(config): + #设置环境变量 + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '29688' + + #设置seed + random.seed(1234) + np.random.seed(1234) + torch.manual_seed(1234) + os.environ['PYTHONHASHSEED'] = str(1234) + + if config.use_apex: + if sys.version_info < (3, 0): + raise RuntimeError("Apex currently only supports Python 3. Aborting.") + if amp is None: + raise RuntimeError("Failed to import apex. Please install apex from https://www.github.com/nvidia/apex " + "to enable mixed-precision training.") + + # Create directories if not exist + if not os.path.exists(config.result_path): + os.makedirs(config.result_path) + + if config.distributed: + init_distributed_mode(config) + + config.is_master_node = not config.distributed or config.device_id == 0 + if config.is_master_node: + print(config) + + device = torch.device(f'npu:'+str(config.device_id)) + torch.npu.set_device(device) + + # Data loading code + print("Loading data") + config.train_path = os.path.join(config.data_path, "train") + config.valid_path = os.path.join(config.data_path, "valid") + print("Creating data loaders") + if config.distributed: + train_loader = get_dist_loader(image_path=config.train_path, + image_size=config.image_size, + batch_size=config.batch_size, + num_workers=config.num_workers, + mode='train', + augmentation_prob=config.augmentation_prob) + valid_loader = get_loader(image_path=config.valid_path, + image_size=config.image_size, + batch_size=config.batch_size, + num_workers=config.num_workers, + mode='valid', + augmentation_prob=0.) + else: + train_loader = get_loader(image_path=config.train_path, + image_size=config.image_size, + batch_size=config.batch_size, + num_workers=config.num_workers, + mode='train', + augmentation_prob=config.augmentation_prob) + valid_loader = get_loader(image_path=config.valid_path, + image_size=config.image_size, + batch_size=config.batch_size, + num_workers=config.num_workers, + mode='valid', + augmentation_prob=0.) + model_unet = R2AttU_Net(img_ch=3, output_ch=1,t=config.t) + model_unet = model_unet.to(device) + + criterion = torch.nn.BCELoss() + optimizer = apex.optimizers.NpuFusedAdam(list(model_unet.parameters()), + config.lr, [config.beta1, config.beta2]) + if config.use_apex: + model_unet, optimizer = amp.initialize(model_unet, optimizer, + opt_level=config.apex_level,loss_scale=config.loss_scale, combine_grad=True) + + model_without_ddp = model_unet + if config.distributed: + model_unet = torch.nn.parallel.DistributedDataParallel(model_unet, device_ids=[config.device_id]) + model_without_ddp = model_unet.module + + if config.is_master_node: + print("Start training") + start_time = time.time() + best_unet_score = 0. + lr = config.lr + for epoch in range(config.num_epochs): + acc, fps = train_one_epoch(model_unet, criterion, optimizer, train_loader, device, epoch, config) + + unet_score = evaluate(model_unet, criterion, valid_loader, device=device) + if config.is_master_node: + print("Traing, Epoch: %d, Avgacc: %.3f, FPS: %.2f"%(epoch, acc, fps)) + print('Test, Acc: %.3f'%(unet_score)) + if config.is_master_node and config.result_path: + checkpoint = { + 'model': model_without_ddp.state_dict(), + 'optimizer': optimizer.state_dict(), + 'epoch': epoch, + 'args': config} + utils.save_on_master( + checkpoint, + os.path.join(config.result_path, 'model_{}.pth'.format(epoch))) + if unet_score > best_unet_score: + best_unet_score = unet_score + utils.save_on_master( + checkpoint, + os.path.join(config.result_path, 'checkpoint.pth')) + if (epoch+1) % 10 == 0: + lr = lr/2. + # lr -= (config.lr / float(config.num_epochs_decay)) + for param_group in optimizer.param_groups: + param_group['lr'] = lr + print ('Decay learning rate to lr: {}.'.format(lr)) + + total_time = time.time() - start_time + total_time_str = str(datetime.timedelta(seconds=int(total_time))) + if config.is_master_node: + print('Training time {}'.format(total_time_str)) + exit() + + +def parse_args(): + parser = argparse.ArgumentParser() + + + # model hyper-parameters + parser.add_argument('--image_size', type=int, default=224) + parser.add_argument('--t', type=int, default=3, help='t for Recurrent step of R2U_Net or R2AttU_Net') + + # training hyper-parameters + parser.add_argument('--img_ch', type=int, default=3) + parser.add_argument('--output_ch', type=int, default=1) + parser.add_argument('--num_epochs', type=int, default=100) + parser.add_argument('--num_epochs_decay', type=int, default=70) + parser.add_argument('--batch_size', type=int, default=16) + parser.add_argument('--num_workers', type=int, default=8) + parser.add_argument('--lr', type=float, default=0.0002) + parser.add_argument('--beta1', type=float, default=0.5) # momentum1 in Adam + parser.add_argument('--beta2', type=float, default=0.999) # momentum2 in Adam + parser.add_argument('--augmentation_prob', type=float, default=0.4) + + parser.add_argument('--log_step', type=int, default=2) + parser.add_argument('--val_step', type=int, default=2) + + # misc + parser.add_argument('--mode', type=str, default='train') + parser.add_argument('--model_type', type=str, default='U_Net', help='U_Net/R2U_Net/AttU_Net/R2AttU_Net') + parser.add_argument('--test_model_path', type=str, default='./models') + parser.add_argument('--data_path', type=str, default='./dataset/train/') + parser.add_argument('--result_path', type=str, default='./result_1p') + + parser.add_argument('--device_id', type=int, default=0) + parser.add_argument('--use_apex', type=int, default=1) + parser.add_argument('--apex_level', type=str, default="O2") + parser.add_argument('--loss_scale', type=float, default=128.) + + parser.add_argument('--world_size', type=int, default=8) + parser.add_argument('--distributed', type=int, default=0, + help='Use multi-processing distributed training to launch.') + + config = parser.parse_args() + main(config) + +if __name__ == "__main__": + args = parse_args() + main(args) diff --git a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/train_1p.sh b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/train_1p.sh index cfba86757043558564dfad59a50d800784ec92d2..d2f3546ec3083d1d41f9b53c0e52dcc57ffa89c3 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/train_1p.sh +++ b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/train_1p.sh @@ -1,3 +1,3 @@ -source ./npu_env.sh -a='R2AttU_Net' +source ./npu_env.sh +a='R2AttU_Net' nohup python3 main_1p.py --model_type=$a --data_path="./dataset" > train_1p.log 2>&1 & \ No newline at end of file diff --git a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/train_8p.sh b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/train_8p.sh index cb10157b504bedda8054e1eb96c513d885030878..e8361c70a4b66a673719ae3d9698f4e99ea5d9c4 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/train_8p.sh +++ b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/train_8p.sh @@ -1,3 +1,3 @@ -source ./npu_env.sh -a='R2AttU_Net' +source ./npu_env.sh +a='R2AttU_Net' nohup python3 main_8p.py --model_type=$a --data_path="./dataset" > train_8p.log 2>&1 & \ No newline at end of file diff --git a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/utils.py b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/utils.py index 1f4811a91a7bf6b75ef4123523ad4085feecb5a1..e854750e9c6ff7f2a6c65790cb1695f903a16bf5 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/utils.py +++ b/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch/utils.py @@ -1,262 +1,262 @@ -# -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -#from __future__ import print_function -from collections import defaultdict, deque -import datetime -import time -import torch -import torch.distributed as dist - -import errno -import os - - -class SmoothedValue(object): - """Track a series of values and provide access to smoothed values over a - window or the global series average. - """ - - def __init__(self, window_size=20, fmt=None): - if fmt is None: - fmt = "{median:.4f} ({global_avg:.4f})" - self.deque = deque(maxlen=window_size) - self.total = 0.0 - self.count = 0 - self.fmt = fmt - - def update(self, value, n=1): - self.deque.append(value) - self.count += n - self.total += value * n - - def synchronize_between_processes(self, npu_device): - """ - Warning: does not synchronize the deque! - """ - if not is_dist_avail_and_initialized(): - return - t = torch.tensor([self.count, self.total], dtype=torch.float32, device=npu_device) - dist.barrier() - dist.all_reduce(t) - t = t.tolist() - self.count = int(t[0]) - self.total = t[1] - - @property - def median(self): - d = torch.tensor(list(self.deque)) - return d.median().item() - - @property - def avg(self): - d = torch.tensor(list(self.deque), dtype=torch.float32) - return d.mean().item() - - @property - def global_avg(self): - return self.total / self.count - - @property - def max(self): - return max(self.deque) - - @property - def value(self): - return self.deque[-1] - - def __str__(self): - return self.fmt.format( - median=self.median, - avg=self.avg, - global_avg=self.global_avg, - max=self.max, - value=self.value) - - -class MetricLogger(object): - def __init__(self, delimiter="\t"): - self.meters = defaultdict(SmoothedValue) - self.delimiter = delimiter - - def update(self, **kwargs): - for k, v in kwargs.items(): - if isinstance(v, torch.Tensor): - v = v.item() - assert isinstance(v, (float, int)) - self.meters[k].update(v) - - def __getattr__(self, attr): - if attr in self.meters: - return self.meters[attr] - if attr in self.__dict__: - return self.__dict__[attr] - raise AttributeError("'{}' object has no attribute '{}'".format( - type(self).__name__, attr)) - - def __str__(self): - loss_str = [] - for name, meter in self.meters.items(): - loss_str.append( - "{}: {}".format(name, str(meter)) - ) - return self.delimiter.join(loss_str) - - def synchronize_between_processes(self, device): - for meter in self.meters.values(): - meter.synchronize_between_processes(device) - - def add_meter(self, name, meter): - self.meters[name] = meter - - def log_every(self, iterable, args, header=None): - i = 0 - if not header: - header = '' - start_time = time.time() - end = time.time() - iter_time = SmoothedValue(fmt='{avg:.4f}') - data_time = SmoothedValue(fmt='{avg:.4f}') - space_fmt = ':' + str(len(str(len(iterable)))) + 'd' - if torch.npu.is_available(): - log_msg = self.delimiter.join([ - header, - '[{0' + space_fmt + '}/{1}]', - 'eta: {eta}', - '{meters}', - 'time: {time}', - 'data: {data}', - 'max mem: {memory:.0f}' - ]) - else: - log_msg = self.delimiter.join([ - header, - '[{0' + space_fmt + '}/{1}]', - 'eta: {eta}', - '{meters}', - 'time: {time}', - 'data: {data}' - ]) - MB = 1024.0 * 1024.0 - for obj in iterable: - data_time.update(time.time() - end) - yield obj - iter_time.update(time.time() - end) - if args.is_master_node and i % args.print_freq == 0: - eta_seconds = iter_time.global_avg * (len(iterable) - i) - eta_string = str(datetime.timedelta(seconds=int(eta_seconds))) - if torch.npu.is_available(): - print(log_msg.format( - i, len(iterable), eta=eta_string, - meters=str(self), - time=str(iter_time), data=str(data_time), - memory=0)) - else: - print(log_msg.format( - i, len(iterable), eta=eta_string, - meters=str(self), - time=str(iter_time), data=str(data_time))) - i += 1 - end = time.time() - total_time = time.time() - start_time - total_time_str = str(datetime.timedelta(seconds=int(total_time))) - print('{} Total time: {}'.format(header, total_time_str)) - - -def accuracy(output, target, topk=(1,)): - """Computes the accuracy over the k top predictions for the specified values of k""" - with torch.no_grad(): - maxk = max(topk) - batch_size = target.size(0) - - _, pred = output.topk(maxk, 1, True, True) - pred = pred.t() - correct = pred.eq(target[None]) - - res = [] - for k in topk: - correct_k = correct[:k].flatten().sum(dtype=torch.float32) - res.append(correct_k * (100.0 / batch_size)) - return res - - -def mkdir(path): - try: - os.makedirs(path) - except OSError as e: - if e.errno != errno.EEXIST: - raise - - -def setup_for_distributed(is_master): - """ - This function disables printing when not in master process - """ - import builtins as __builtin__ - builtin_print = __builtin__.print - - def print(*args, **kwargs): - force = kwargs.pop('force', False) - if is_master or force: - builtin_print(*args, **kwargs) - - __builtin__.print = print - - -def is_dist_avail_and_initialized(): - if not dist.is_available(): - return False - if not dist.is_initialized(): - return False - return True - - -def get_world_size(): - if not is_dist_avail_and_initialized(): - return 1 - return dist.get_world_size() - - -def get_rank(): - if not is_dist_avail_and_initialized(): - return 0 - return dist.get_rank() - - -def is_main_process(): - return get_rank() == 0 - - -def save_on_master(*args, **kwargs): - torch.save(*args, **kwargs) - - +# +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +#from __future__ import print_function +from collections import defaultdict, deque +import datetime +import time +import torch +import torch.distributed as dist + +import errno +import os + + +class SmoothedValue(object): + """Track a series of values and provide access to smoothed values over a + window or the global series average. + """ + + def __init__(self, window_size=20, fmt=None): + if fmt is None: + fmt = "{median:.4f} ({global_avg:.4f})" + self.deque = deque(maxlen=window_size) + self.total = 0.0 + self.count = 0 + self.fmt = fmt + + def update(self, value, n=1): + self.deque.append(value) + self.count += n + self.total += value * n + + def synchronize_between_processes(self, npu_device): + """ + Warning: does not synchronize the deque! + """ + if not is_dist_avail_and_initialized(): + return + t = torch.tensor([self.count, self.total], dtype=torch.float32, device=npu_device) + dist.barrier() + dist.all_reduce(t) + t = t.tolist() + self.count = int(t[0]) + self.total = t[1] + + @property + def median(self): + d = torch.tensor(list(self.deque)) + return d.median().item() + + @property + def avg(self): + d = torch.tensor(list(self.deque), dtype=torch.float32) + return d.mean().item() + + @property + def global_avg(self): + return self.total / self.count + + @property + def max(self): + return max(self.deque) + + @property + def value(self): + return self.deque[-1] + + def __str__(self): + return self.fmt.format( + median=self.median, + avg=self.avg, + global_avg=self.global_avg, + max=self.max, + value=self.value) + + +class MetricLogger(object): + def __init__(self, delimiter="\t"): + self.meters = defaultdict(SmoothedValue) + self.delimiter = delimiter + + def update(self, **kwargs): + for k, v in kwargs.items(): + if isinstance(v, torch.Tensor): + v = v.item() + assert isinstance(v, (float, int)) + self.meters[k].update(v) + + def __getattr__(self, attr): + if attr in self.meters: + return self.meters[attr] + if attr in self.__dict__: + return self.__dict__[attr] + raise AttributeError("'{}' object has no attribute '{}'".format( + type(self).__name__, attr)) + + def __str__(self): + loss_str = [] + for name, meter in self.meters.items(): + loss_str.append( + "{}: {}".format(name, str(meter)) + ) + return self.delimiter.join(loss_str) + + def synchronize_between_processes(self, device): + for meter in self.meters.values(): + meter.synchronize_between_processes(device) + + def add_meter(self, name, meter): + self.meters[name] = meter + + def log_every(self, iterable, args, header=None): + i = 0 + if not header: + header = '' + start_time = time.time() + end = time.time() + iter_time = SmoothedValue(fmt='{avg:.4f}') + data_time = SmoothedValue(fmt='{avg:.4f}') + space_fmt = ':' + str(len(str(len(iterable)))) + 'd' + if torch.npu.is_available(): + log_msg = self.delimiter.join([ + header, + '[{0' + space_fmt + '}/{1}]', + 'eta: {eta}', + '{meters}', + 'time: {time}', + 'data: {data}', + 'max mem: {memory:.0f}' + ]) + else: + log_msg = self.delimiter.join([ + header, + '[{0' + space_fmt + '}/{1}]', + 'eta: {eta}', + '{meters}', + 'time: {time}', + 'data: {data}' + ]) + MB = 1024.0 * 1024.0 + for obj in iterable: + data_time.update(time.time() - end) + yield obj + iter_time.update(time.time() - end) + if args.is_master_node and i % args.print_freq == 0: + eta_seconds = iter_time.global_avg * (len(iterable) - i) + eta_string = str(datetime.timedelta(seconds=int(eta_seconds))) + if torch.npu.is_available(): + print(log_msg.format( + i, len(iterable), eta=eta_string, + meters=str(self), + time=str(iter_time), data=str(data_time), + memory=0)) + else: + print(log_msg.format( + i, len(iterable), eta=eta_string, + meters=str(self), + time=str(iter_time), data=str(data_time))) + i += 1 + end = time.time() + total_time = time.time() - start_time + total_time_str = str(datetime.timedelta(seconds=int(total_time))) + print('{} Total time: {}'.format(header, total_time_str)) + + +def accuracy(output, target, topk=(1,)): + """Computes the accuracy over the k top predictions for the specified values of k""" + with torch.no_grad(): + maxk = max(topk) + batch_size = target.size(0) + + _, pred = output.topk(maxk, 1, True, True) + pred = pred.t() + correct = pred.eq(target[None]) + + res = [] + for k in topk: + correct_k = correct[:k].flatten().sum(dtype=torch.float32) + res.append(correct_k * (100.0 / batch_size)) + return res + + +def mkdir(path): + try: + os.makedirs(path) + except OSError as e: + if e.errno != errno.EEXIST: + raise + + +def setup_for_distributed(is_master): + """ + This function disables printing when not in master process + """ + import builtins as __builtin__ + builtin_print = __builtin__.print + + def print(*args, **kwargs): + force = kwargs.pop('force', False) + if is_master or force: + builtin_print(*args, **kwargs) + + __builtin__.print = print + + +def is_dist_avail_and_initialized(): + if not dist.is_available(): + return False + if not dist.is_initialized(): + return False + return True + + +def get_world_size(): + if not is_dist_avail_and_initialized(): + return 1 + return dist.get_world_size() + + +def get_rank(): + if not is_dist_avail_and_initialized(): + return 0 + return dist.get_rank() + + +def is_main_process(): + return get_rank() == 0 + + +def save_on_master(*args, **kwargs): + torch.save(*args, **kwargs) + + diff --git a/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/LICENSE b/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/LICENSE index 4ba4fdcab3dbdb4d64ce4cccdfd990698b4d596a..a0e03103591c1158a839681f3c404ee9118b182e 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/LICENSE +++ b/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/LICENSE @@ -1,29 +1,29 @@ -BSD 3-Clause License - -Copyright (c) 2017, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +BSD 3-Clause License + +Copyright (c) 2017, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/evaluation.py b/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/evaluation.py index 51b3948ca54bf3f9750ef9fca0c171b9f6666d6b..e368a1864747b2fc86ce010161abad8c8abffab7 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/evaluation.py +++ b/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/evaluation.py @@ -1,115 +1,115 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import torch - -# SR : Segmentation Result -# GT : Ground Truth - -def get_accuracy(SR,GT,threshold=0.5): - SR = SR > threshold - GT = GT == torch.max(GT) - corr = torch.sum(SR==GT) - tensor_size = SR.size(0)*SR.size(1)*SR.size(2)*SR.size(3) - acc = float(corr)/float(tensor_size) - - return acc - -def get_sensitivity(SR,GT,threshold=0.5): - # Sensitivity == Recall - # TP : True Positive - # FN : False Negative - SR = SR > threshold - GT = GT == torch.max(GT) - TP = SR & GT - FN = (~SR) & GT - - SE = float(torch.sum(TP))/(float(torch.sum(TP)+torch.sum(FN)) + 1e-6) - - return SE - -def get_specificity(SR,GT,threshold=0.5): - - # TN : True Negative - # FP : False Positive - SR = SR > threshold - GT = GT == torch.max(GT) - TN = (~SR) & (~GT) - FP = SR & (~GT) - - SP = float(torch.sum(TN))/(float(torch.sum(TN)+torch.sum(FP)) + 1e-6) - - return SP - -def get_precision(SR,GT,threshold=0.5): - - # TP : True Positive - # FP : False Positive - SR = SR > threshold - GT = GT == torch.max(GT) - TP = SR & GT - FP = SR & (~GT) - - PC = float(torch.sum(TP))/(float(torch.sum(TP)+torch.sum(FP)) + 1e-6) - - return PC - -def get_F1(SR,GT,threshold=0.5): - # Sensitivity == Recall - SE = get_sensitivity(SR,GT,threshold=threshold) - PC = get_precision(SR,GT,threshold=threshold) - - F1 = 2*SE*PC/(SE+PC + 1e-6) - - return F1 - -def get_JS(SR,GT,threshold=0.5): - # JS : Jaccard similarity - SR = SR > threshold - GT = GT == torch.max(GT) - Inter = torch.sum((SR & GT)) - Union = torch.sum((SR | GT)) - - JS = float(Inter)/(float(Union) + 1e-6) - - return JS - -def get_DC(SR,GT,threshold=0.5): - # DC : Dice Coefficient - SR = SR > threshold - GT = GT == torch.max(GT) - Inter = torch.sum((SR & GT)) - DC = float(2*Inter)/(float(torch.sum(SR)+torch.sum(GT)) + 1e-6) - - return DC - - - +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import torch + +# SR : Segmentation Result +# GT : Ground Truth + +def get_accuracy(SR,GT,threshold=0.5): + SR = SR > threshold + GT = GT == torch.max(GT) + corr = torch.sum(SR==GT) + tensor_size = SR.size(0)*SR.size(1)*SR.size(2)*SR.size(3) + acc = float(corr)/float(tensor_size) + + return acc + +def get_sensitivity(SR,GT,threshold=0.5): + # Sensitivity == Recall + # TP : True Positive + # FN : False Negative + SR = SR > threshold + GT = GT == torch.max(GT) + TP = SR & GT + FN = (~SR) & GT + + SE = float(torch.sum(TP))/(float(torch.sum(TP)+torch.sum(FN)) + 1e-6) + + return SE + +def get_specificity(SR,GT,threshold=0.5): + + # TN : True Negative + # FP : False Positive + SR = SR > threshold + GT = GT == torch.max(GT) + TN = (~SR) & (~GT) + FP = SR & (~GT) + + SP = float(torch.sum(TN))/(float(torch.sum(TN)+torch.sum(FP)) + 1e-6) + + return SP + +def get_precision(SR,GT,threshold=0.5): + + # TP : True Positive + # FP : False Positive + SR = SR > threshold + GT = GT == torch.max(GT) + TP = SR & GT + FP = SR & (~GT) + + PC = float(torch.sum(TP))/(float(torch.sum(TP)+torch.sum(FP)) + 1e-6) + + return PC + +def get_F1(SR,GT,threshold=0.5): + # Sensitivity == Recall + SE = get_sensitivity(SR,GT,threshold=threshold) + PC = get_precision(SR,GT,threshold=threshold) + + F1 = 2*SE*PC/(SE+PC + 1e-6) + + return F1 + +def get_JS(SR,GT,threshold=0.5): + # JS : Jaccard similarity + SR = SR > threshold + GT = GT == torch.max(GT) + Inter = torch.sum((SR & GT)) + Union = torch.sum((SR | GT)) + + JS = float(Inter)/(float(Union) + 1e-6) + + return JS + +def get_DC(SR,GT,threshold=0.5): + # DC : Dice Coefficient + SR = SR > threshold + GT = GT == torch.max(GT) + Inter = torch.sum((SR & GT)) + DC = float(2*Inter)/(float(torch.sum(SR)+torch.sum(GT)) + 1e-6) + + return DC + + + diff --git a/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/modelzoo_level.txt b/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/run_to_onnx.sh b/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/run_to_onnx.sh index 13cead0d88c21771601d33a435ef26d296c68a48..89099c047a904ff0b97638ed13a3480da3dbb873 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/run_to_onnx.sh +++ b/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/run_to_onnx.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash -source env.sh - +#!/usr/bin/env bash +source env.sh + python3.7 pthtar2onx.py \ No newline at end of file diff --git a/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/utils.py b/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/utils.py index 1f4811a91a7bf6b75ef4123523ad4085feecb5a1..e854750e9c6ff7f2a6c65790cb1695f903a16bf5 100644 --- a/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/utils.py +++ b/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch/utils.py @@ -1,262 +1,262 @@ -# -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -#from __future__ import print_function -from collections import defaultdict, deque -import datetime -import time -import torch -import torch.distributed as dist - -import errno -import os - - -class SmoothedValue(object): - """Track a series of values and provide access to smoothed values over a - window or the global series average. - """ - - def __init__(self, window_size=20, fmt=None): - if fmt is None: - fmt = "{median:.4f} ({global_avg:.4f})" - self.deque = deque(maxlen=window_size) - self.total = 0.0 - self.count = 0 - self.fmt = fmt - - def update(self, value, n=1): - self.deque.append(value) - self.count += n - self.total += value * n - - def synchronize_between_processes(self, npu_device): - """ - Warning: does not synchronize the deque! - """ - if not is_dist_avail_and_initialized(): - return - t = torch.tensor([self.count, self.total], dtype=torch.float32, device=npu_device) - dist.barrier() - dist.all_reduce(t) - t = t.tolist() - self.count = int(t[0]) - self.total = t[1] - - @property - def median(self): - d = torch.tensor(list(self.deque)) - return d.median().item() - - @property - def avg(self): - d = torch.tensor(list(self.deque), dtype=torch.float32) - return d.mean().item() - - @property - def global_avg(self): - return self.total / self.count - - @property - def max(self): - return max(self.deque) - - @property - def value(self): - return self.deque[-1] - - def __str__(self): - return self.fmt.format( - median=self.median, - avg=self.avg, - global_avg=self.global_avg, - max=self.max, - value=self.value) - - -class MetricLogger(object): - def __init__(self, delimiter="\t"): - self.meters = defaultdict(SmoothedValue) - self.delimiter = delimiter - - def update(self, **kwargs): - for k, v in kwargs.items(): - if isinstance(v, torch.Tensor): - v = v.item() - assert isinstance(v, (float, int)) - self.meters[k].update(v) - - def __getattr__(self, attr): - if attr in self.meters: - return self.meters[attr] - if attr in self.__dict__: - return self.__dict__[attr] - raise AttributeError("'{}' object has no attribute '{}'".format( - type(self).__name__, attr)) - - def __str__(self): - loss_str = [] - for name, meter in self.meters.items(): - loss_str.append( - "{}: {}".format(name, str(meter)) - ) - return self.delimiter.join(loss_str) - - def synchronize_between_processes(self, device): - for meter in self.meters.values(): - meter.synchronize_between_processes(device) - - def add_meter(self, name, meter): - self.meters[name] = meter - - def log_every(self, iterable, args, header=None): - i = 0 - if not header: - header = '' - start_time = time.time() - end = time.time() - iter_time = SmoothedValue(fmt='{avg:.4f}') - data_time = SmoothedValue(fmt='{avg:.4f}') - space_fmt = ':' + str(len(str(len(iterable)))) + 'd' - if torch.npu.is_available(): - log_msg = self.delimiter.join([ - header, - '[{0' + space_fmt + '}/{1}]', - 'eta: {eta}', - '{meters}', - 'time: {time}', - 'data: {data}', - 'max mem: {memory:.0f}' - ]) - else: - log_msg = self.delimiter.join([ - header, - '[{0' + space_fmt + '}/{1}]', - 'eta: {eta}', - '{meters}', - 'time: {time}', - 'data: {data}' - ]) - MB = 1024.0 * 1024.0 - for obj in iterable: - data_time.update(time.time() - end) - yield obj - iter_time.update(time.time() - end) - if args.is_master_node and i % args.print_freq == 0: - eta_seconds = iter_time.global_avg * (len(iterable) - i) - eta_string = str(datetime.timedelta(seconds=int(eta_seconds))) - if torch.npu.is_available(): - print(log_msg.format( - i, len(iterable), eta=eta_string, - meters=str(self), - time=str(iter_time), data=str(data_time), - memory=0)) - else: - print(log_msg.format( - i, len(iterable), eta=eta_string, - meters=str(self), - time=str(iter_time), data=str(data_time))) - i += 1 - end = time.time() - total_time = time.time() - start_time - total_time_str = str(datetime.timedelta(seconds=int(total_time))) - print('{} Total time: {}'.format(header, total_time_str)) - - -def accuracy(output, target, topk=(1,)): - """Computes the accuracy over the k top predictions for the specified values of k""" - with torch.no_grad(): - maxk = max(topk) - batch_size = target.size(0) - - _, pred = output.topk(maxk, 1, True, True) - pred = pred.t() - correct = pred.eq(target[None]) - - res = [] - for k in topk: - correct_k = correct[:k].flatten().sum(dtype=torch.float32) - res.append(correct_k * (100.0 / batch_size)) - return res - - -def mkdir(path): - try: - os.makedirs(path) - except OSError as e: - if e.errno != errno.EEXIST: - raise - - -def setup_for_distributed(is_master): - """ - This function disables printing when not in master process - """ - import builtins as __builtin__ - builtin_print = __builtin__.print - - def print(*args, **kwargs): - force = kwargs.pop('force', False) - if is_master or force: - builtin_print(*args, **kwargs) - - __builtin__.print = print - - -def is_dist_avail_and_initialized(): - if not dist.is_available(): - return False - if not dist.is_initialized(): - return False - return True - - -def get_world_size(): - if not is_dist_avail_and_initialized(): - return 1 - return dist.get_world_size() - - -def get_rank(): - if not is_dist_avail_and_initialized(): - return 0 - return dist.get_rank() - - -def is_main_process(): - return get_rank() == 0 - - -def save_on_master(*args, **kwargs): - torch.save(*args, **kwargs) - - +# +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +#from __future__ import print_function +from collections import defaultdict, deque +import datetime +import time +import torch +import torch.distributed as dist + +import errno +import os + + +class SmoothedValue(object): + """Track a series of values and provide access to smoothed values over a + window or the global series average. + """ + + def __init__(self, window_size=20, fmt=None): + if fmt is None: + fmt = "{median:.4f} ({global_avg:.4f})" + self.deque = deque(maxlen=window_size) + self.total = 0.0 + self.count = 0 + self.fmt = fmt + + def update(self, value, n=1): + self.deque.append(value) + self.count += n + self.total += value * n + + def synchronize_between_processes(self, npu_device): + """ + Warning: does not synchronize the deque! + """ + if not is_dist_avail_and_initialized(): + return + t = torch.tensor([self.count, self.total], dtype=torch.float32, device=npu_device) + dist.barrier() + dist.all_reduce(t) + t = t.tolist() + self.count = int(t[0]) + self.total = t[1] + + @property + def median(self): + d = torch.tensor(list(self.deque)) + return d.median().item() + + @property + def avg(self): + d = torch.tensor(list(self.deque), dtype=torch.float32) + return d.mean().item() + + @property + def global_avg(self): + return self.total / self.count + + @property + def max(self): + return max(self.deque) + + @property + def value(self): + return self.deque[-1] + + def __str__(self): + return self.fmt.format( + median=self.median, + avg=self.avg, + global_avg=self.global_avg, + max=self.max, + value=self.value) + + +class MetricLogger(object): + def __init__(self, delimiter="\t"): + self.meters = defaultdict(SmoothedValue) + self.delimiter = delimiter + + def update(self, **kwargs): + for k, v in kwargs.items(): + if isinstance(v, torch.Tensor): + v = v.item() + assert isinstance(v, (float, int)) + self.meters[k].update(v) + + def __getattr__(self, attr): + if attr in self.meters: + return self.meters[attr] + if attr in self.__dict__: + return self.__dict__[attr] + raise AttributeError("'{}' object has no attribute '{}'".format( + type(self).__name__, attr)) + + def __str__(self): + loss_str = [] + for name, meter in self.meters.items(): + loss_str.append( + "{}: {}".format(name, str(meter)) + ) + return self.delimiter.join(loss_str) + + def synchronize_between_processes(self, device): + for meter in self.meters.values(): + meter.synchronize_between_processes(device) + + def add_meter(self, name, meter): + self.meters[name] = meter + + def log_every(self, iterable, args, header=None): + i = 0 + if not header: + header = '' + start_time = time.time() + end = time.time() + iter_time = SmoothedValue(fmt='{avg:.4f}') + data_time = SmoothedValue(fmt='{avg:.4f}') + space_fmt = ':' + str(len(str(len(iterable)))) + 'd' + if torch.npu.is_available(): + log_msg = self.delimiter.join([ + header, + '[{0' + space_fmt + '}/{1}]', + 'eta: {eta}', + '{meters}', + 'time: {time}', + 'data: {data}', + 'max mem: {memory:.0f}' + ]) + else: + log_msg = self.delimiter.join([ + header, + '[{0' + space_fmt + '}/{1}]', + 'eta: {eta}', + '{meters}', + 'time: {time}', + 'data: {data}' + ]) + MB = 1024.0 * 1024.0 + for obj in iterable: + data_time.update(time.time() - end) + yield obj + iter_time.update(time.time() - end) + if args.is_master_node and i % args.print_freq == 0: + eta_seconds = iter_time.global_avg * (len(iterable) - i) + eta_string = str(datetime.timedelta(seconds=int(eta_seconds))) + if torch.npu.is_available(): + print(log_msg.format( + i, len(iterable), eta=eta_string, + meters=str(self), + time=str(iter_time), data=str(data_time), + memory=0)) + else: + print(log_msg.format( + i, len(iterable), eta=eta_string, + meters=str(self), + time=str(iter_time), data=str(data_time))) + i += 1 + end = time.time() + total_time = time.time() - start_time + total_time_str = str(datetime.timedelta(seconds=int(total_time))) + print('{} Total time: {}'.format(header, total_time_str)) + + +def accuracy(output, target, topk=(1,)): + """Computes the accuracy over the k top predictions for the specified values of k""" + with torch.no_grad(): + maxk = max(topk) + batch_size = target.size(0) + + _, pred = output.topk(maxk, 1, True, True) + pred = pred.t() + correct = pred.eq(target[None]) + + res = [] + for k in topk: + correct_k = correct[:k].flatten().sum(dtype=torch.float32) + res.append(correct_k * (100.0 / batch_size)) + return res + + +def mkdir(path): + try: + os.makedirs(path) + except OSError as e: + if e.errno != errno.EEXIST: + raise + + +def setup_for_distributed(is_master): + """ + This function disables printing when not in master process + """ + import builtins as __builtin__ + builtin_print = __builtin__.print + + def print(*args, **kwargs): + force = kwargs.pop('force', False) + if is_master or force: + builtin_print(*args, **kwargs) + + __builtin__.print = print + + +def is_dist_avail_and_initialized(): + if not dist.is_available(): + return False + if not dist.is_initialized(): + return False + return True + + +def get_world_size(): + if not is_dist_avail_and_initialized(): + return 1 + return dist.get_world_size() + + +def get_rank(): + if not is_dist_avail_and_initialized(): + return 0 + return dist.get_rank() + + +def is_main_process(): + return get_rank() == 0 + + +def save_on_master(*args, **kwargs): + torch.save(*args, **kwargs) + + diff --git a/PyTorch/built-in/nlp/Bert-Squad_ID0470_for_PyTorch/bert_base_config.json b/PyTorch/built-in/nlp/Bert-Squad_ID0470_for_PyTorch/bert_base_config.json index 3a28c2e64827d9ca3937da7ebb0ab5461aa69023..d794ee04ccfc69433c2ecb8979fb536607865245 100644 --- a/PyTorch/built-in/nlp/Bert-Squad_ID0470_for_PyTorch/bert_base_config.json +++ b/PyTorch/built-in/nlp/Bert-Squad_ID0470_for_PyTorch/bert_base_config.json @@ -1,13 +1,13 @@ -{ - "attention_probs_dropout_prob": 0.1, - "hidden_act": "gelu", - "hidden_dropout_prob": 0.1, - "hidden_size": 768, - "initializer_range": 0.02, - "intermediate_size": 3072, - "max_position_embeddings": 512, - "num_attention_heads": 12, - "num_hidden_layers": 12, - "type_vocab_size": 2, - "vocab_size": 30522 +{ + "attention_probs_dropout_prob": 0.1, + "hidden_act": "gelu", + "hidden_dropout_prob": 0.1, + "hidden_size": 768, + "initializer_range": 0.02, + "intermediate_size": 3072, + "max_position_embeddings": 512, + "num_attention_heads": 12, + "num_hidden_layers": 12, + "type_vocab_size": 2, + "vocab_size": 30522 } \ No newline at end of file diff --git a/PyTorch/built-in/nlp/CPM_Finetune_for_PyTorch/bpe_3w_new/readme.md b/PyTorch/built-in/nlp/CPM_Finetune_for_PyTorch/bpe_3w_new/readme.md index 37ff1ffc758431750720898894fec570c933a9f2..0b57ec0161b8866b8ddc1a2c8eeaafdad95cc089 100644 --- a/PyTorch/built-in/nlp/CPM_Finetune_for_PyTorch/bpe_3w_new/readme.md +++ b/PyTorch/built-in/nlp/CPM_Finetune_for_PyTorch/bpe_3w_new/readme.md @@ -1,2 +1,2 @@ -由于文件较大已删除,如需使用请到如下地址下载相应文件 +由于文件较大已删除,如需使用请到如下地址下载相应文件 - https://github.com/TsinghuaAI/CPM-1-Generate/tree/main/bpe_3w_new \ No newline at end of file diff --git a/PyTorch/built-in/nlp/CPM_Finetune_for_PyTorch/test/eval_1p.sh b/PyTorch/built-in/nlp/CPM_Finetune_for_PyTorch/test/eval_1p.sh index ef05fefbeffaa2dd68116cbc3cd5c721a07a8c73..64b5f1196a756ec6b5a14cc4775743baa2feaf9c 100644 --- a/PyTorch/built-in/nlp/CPM_Finetune_for_PyTorch/test/eval_1p.sh +++ b/PyTorch/built-in/nlp/CPM_Finetune_for_PyTorch/test/eval_1p.sh @@ -1,116 +1,116 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi -source ${test_path_dir}/env_npu.sh -# 数据集路径,保持为空,不需要修改 -DATA_DIR="" -CHECKPOINT_PATH="" - -#网络名称,同目录名称 -Network="CPM_large_1p" -#训练batch_size -batch_size=1 -#集合通信参数 -RANK_SIZE=1 -MPSIZE=1 -RESULTS_DIR="../results/" -MODEL_NAME="zeroshot-test" -TOKENIZER_PATH="bpe_3w_new/" -NLAYERS=32 -NHIDDEN=2560 -NATT=32 -MAXSEQLEN=1024 -ASCEND_DEVICE_ID=0 - -#创建DeviceID输出目录,不需要修改 -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -taskset -c 0-25 python3.7 -m torch.distributed.launch --master_port ${1-1122} --nproc_per_node ${RANK_SIZE} zero-shot_chid.py \ - --data_dir ${DATA_DIR} \ - --model-parallel-size ${MPSIZE} \ - --num-layers ${NLAYERS} \ - --hidden-size ${NHIDDEN} \ - --load ${CHECKPOINT_PATH} \ - --num-attention-heads ${NATT} \ - --seq-length ${MAXSEQLEN} \ - --max-position-embeddings 1024 \ - --tokenizer-type GPT2BPETokenizer \ - --fp16 \ - --out-seq-length 512 \ - --tokenizer-path ${TOKENIZER_PATH} \ - --vocab-size 30000 \ - --batch-size ${batch_size} \ - --seed 23333 \ - --results_dir ${RESULTS_DIR} \ - --model_name ${MODEL_NAME}> ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -wait - - - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" - -#输出性能FPS,需要模型审视修改 -FPS=`grep -a 'Test:' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk 'END {print}' |awk -F '[ ]' '{print $17}'` -FPS=${FPS#* } - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a 'Acc:' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |awk 'END {print}'|awk -F "Acc:" '{print $NF}'|awk -F " " '{print $1}'` -train_accuracy=${train_accuracy%*${train_accuracy:(-6)}} -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep -r "Test:" ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F 'Loss' '{print $NF}' | awk -F " " '{print $1}' >> ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}">> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi +source ${test_path_dir}/env_npu.sh +# 数据集路径,保持为空,不需要修改 +DATA_DIR="" +CHECKPOINT_PATH="" + +#网络名称,同目录名称 +Network="CPM_large_1p" +#训练batch_size +batch_size=1 +#集合通信参数 +RANK_SIZE=1 +MPSIZE=1 +RESULTS_DIR="../results/" +MODEL_NAME="zeroshot-test" +TOKENIZER_PATH="bpe_3w_new/" +NLAYERS=32 +NHIDDEN=2560 +NATT=32 +MAXSEQLEN=1024 +ASCEND_DEVICE_ID=0 + +#创建DeviceID输出目录,不需要修改 +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +taskset -c 0-25 python3.7 -m torch.distributed.launch --master_port ${1-1122} --nproc_per_node ${RANK_SIZE} zero-shot_chid.py \ + --data_dir ${DATA_DIR} \ + --model-parallel-size ${MPSIZE} \ + --num-layers ${NLAYERS} \ + --hidden-size ${NHIDDEN} \ + --load ${CHECKPOINT_PATH} \ + --num-attention-heads ${NATT} \ + --seq-length ${MAXSEQLEN} \ + --max-position-embeddings 1024 \ + --tokenizer-type GPT2BPETokenizer \ + --fp16 \ + --out-seq-length 512 \ + --tokenizer-path ${TOKENIZER_PATH} \ + --vocab-size 30000 \ + --batch-size ${batch_size} \ + --seed 23333 \ + --results_dir ${RESULTS_DIR} \ + --model_name ${MODEL_NAME}> ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +wait + + + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" + +#输出性能FPS,需要模型审视修改 +FPS=`grep -a 'Test:' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk 'END {print}' |awk -F '[ ]' '{print $17}'` +FPS=${FPS#* } + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a 'Acc:' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |awk 'END {print}'|awk -F "Acc:" '{print $NF}'|awk -F " " '{print $1}'` +train_accuracy=${train_accuracy%*${train_accuracy:(-6)}} +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep -r "Test:" ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F 'Loss' '{print $NF}' | awk -F " " '{print $1}' >> ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}">> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $test_path_dir/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/nlp/GRU_for_PyTorch/test/train_full_8p.sh b/PyTorch/built-in/nlp/GRU_for_PyTorch/test/train_full_8p.sh index 7339a821a71f2ff4ec35ae6884deb2c09a9583fe..7044c327eb0209854e52425aae803ac8f8969d99 100644 --- a/PyTorch/built-in/nlp/GRU_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/built-in/nlp/GRU_for_PyTorch/test/train_full_8p.sh @@ -1,178 +1,178 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 - - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="GRU_ID0104_for_PyTorch" -#训练epoch -train_epochs=10 -#训练batch_size -batch_size=4096 -#训练step -train_steps= -#学习率 -learning_rate= - - - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#执行训练脚本,以下传参不需要修改,其他需要模型审视修改 -#--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path -for i in $(seq 0 7) -do - python3 ${cur_path}/../gru_8p.py \ - --addr=$(hostname -I |awk '{print $1}') \ - --data-dir $data_path \ - --seed 123456 \ - --workers 160 \ - --print-freq 1 \ - --dist-url 'tcp://127.0.0.1:50000' \ - --dist-backend 'hccl' \ - --multiprocessing-distributed \ - --world-size 1 \ - --batch-size $batch_size \ - --epoch $train_epochs \ - --rank 0 \ - --npu $i \ - --device-list '0,1,2,3,4,5,6,7' \ - --amp \ - --bleu-npu 0 > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -done -wait - -###验证精度 -python3.7 ${cur_path}/../bleu_score.py \ - --workers 40 \ - --dist-url 'tcp://127.0.0.1:50000' \ - --data-dir $data_path \ - --world-size 1 \ - --npu 0 \ - --batch-size 512 \ - --epochs 10 \ - --rank 0 \ - --amp \ - --bleu-npu 0 \ - --ckptpath ./seq2seq-gru-model.pth.tar >> $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -#FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tail -1|awk '{print $NF}'` -FPS=`grep -a 'FPS' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a 'BLEU' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk 'END {print $4}'` - -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}'| tr -s '\n' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 + + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="GRU_ID0104_for_PyTorch" +#训练epoch +train_epochs=10 +#训练batch_size +batch_size=4096 +#训练step +train_steps= +#学习率 +learning_rate= + + + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $cur_path/output ];then + rm -rf $cur_path/output/* + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +fi +wait + + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#执行训练脚本,以下传参不需要修改,其他需要模型审视修改 +#--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path +for i in $(seq 0 7) +do + python3 ${cur_path}/../gru_8p.py \ + --addr=$(hostname -I |awk '{print $1}') \ + --data-dir $data_path \ + --seed 123456 \ + --workers 160 \ + --print-freq 1 \ + --dist-url 'tcp://127.0.0.1:50000' \ + --dist-backend 'hccl' \ + --multiprocessing-distributed \ + --world-size 1 \ + --batch-size $batch_size \ + --epoch $train_epochs \ + --rank 0 \ + --npu $i \ + --device-list '0,1,2,3,4,5,6,7' \ + --amp \ + --bleu-npu 0 > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +done +wait + +###验证精度 +python3.7 ${cur_path}/../bleu_score.py \ + --workers 40 \ + --dist-url 'tcp://127.0.0.1:50000' \ + --data-dir $data_path \ + --world-size 1 \ + --npu 0 \ + --batch-size 512 \ + --epochs 10 \ + --rank 0 \ + --amp \ + --bleu-npu 0 \ + --ckptpath ./seq2seq-gru-model.pth.tar >> $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +#FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|tail -1|awk '{print $NF}'` +FPS=`grep -a 'FPS' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a 'BLEU' ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk 'END {print $4}'` + +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'Loss' '{print $2}'|awk '{print $1}'| tr -s '\n' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/nlp/GRU_for_PyTorch/test/train_performance_1p.sh b/PyTorch/built-in/nlp/GRU_for_PyTorch/test/train_performance_1p.sh index 5ad15788e3c3d5ebfbc12164aeadc84023aaa711..84eddb91f6438e92fa3709512d255ab2a44cc6eb 100644 --- a/PyTorch/built-in/nlp/GRU_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/built-in/nlp/GRU_for_PyTorch/test/train_performance_1p.sh @@ -1,147 +1,147 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -#RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="GRU_ID0104_for_PyTorch" -#训练epoch -train_epochs=4 -#训练batch_size -batch_size=1536 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -python3 ${cur_path}/../gru_1p.py \ - --data-dir $data_path \ - --workers 32 \ - --dist-url 'tcp://127.0.0.1:50000' \ - --world-size 1 \ - --npu $ASCEND_DEVICE_ID \ - --batch-size $batch_size \ - --epochs $train_epochs \ - --rank 0 \ - --amp > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep npu|awk -F 'Loss' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +#RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="GRU_ID0104_for_PyTorch" +#训练epoch +train_epochs=4 +#训练batch_size +batch_size=1536 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $cur_path/output ];then + rm -rf $cur_path/output/* + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +fi +wait + + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +python3 ${cur_path}/../gru_1p.py \ + --data-dir $data_path \ + --workers 32 \ + --dist-url 'tcp://127.0.0.1:50000' \ + --world-size 1 \ + --npu $ASCEND_DEVICE_ID \ + --batch-size $batch_size \ + --epochs $train_epochs \ + --rank 0 \ + --amp > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep npu|awk -F 'Loss' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/nlp/GRU_for_PyTorch/test/train_performance_8p.sh b/PyTorch/built-in/nlp/GRU_for_PyTorch/test/train_performance_8p.sh index ddc94fbb5f8c295d3109f9cae328b04aa4c2290b..d941c6ce7b29b4aaab80cc26a699df471372dcaa 100644 --- a/PyTorch/built-in/nlp/GRU_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/built-in/nlp/GRU_for_PyTorch/test/train_performance_8p.sh @@ -1,181 +1,181 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 - -#集合通信参数,不需要修改 -export HCCL_WHITELIST_DISABLE=1 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 -# source env.sh -#RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="GRU_ID0104_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=12288 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.045 - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--amp" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -if [ $(uname -m) = "aarch64" ] -then - for i in $(seq 0 7) - do - let p_start=0+20*i - let p_end=19+20*i - taskset -c $p_start-$p_end python3 ${cur_path}/../gru_8p.py \ - --addr=$(hostname -I |awk '{print $1}') \ - --data-dir $data_path \ - --seed 123456 \ - --workers 20 \ - --print-freq 1 \ - --dist-url 'tcp://127.0.0.1:50000' \ - --dist-backend 'hccl' \ - --multiprocessing-distributed \ - --world-size 1 \ - --batch-size $batch_size \ - --epoch $train_epochs \ - --rank 0 \ - --npu $i \ - --device-list '0,1,2,3,4,5,6,7' \ - --amp > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & - done -else - for i in $(seq 0 7) - do - python3 ${cur_path}/../gru_8p.py \ - --addr=$(hostname -I |awk '{print $1}') \ - --data-dir $data_path \ - --seed 123456 \ - --workers 80 \ - --print-freq 1 \ - --dist-url 'tcp://127.0.0.1:50000' \ - --dist-backend 'hccl' \ - --multiprocessing-distributed \ - --world-size 1 \ - --batch-size 12288 \ - --epoch 10 \ - --rank 0 \ - --npu $i \ - --device-list '0,1,2,3,4,5,6,7' \ - --amp > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & - done -fi -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` - -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep npu |awk -F 'Loss' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 + +#集合通信参数,不需要修改 +export HCCL_WHITELIST_DISABLE=1 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 +# source env.sh +#RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +# export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="GRU_ID0104_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=12288 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.045 + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--amp" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path + +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $cur_path/output ];then + rm -rf $cur_path/output/* + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +fi +wait + + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +if [ $(uname -m) = "aarch64" ] +then + for i in $(seq 0 7) + do + let p_start=0+20*i + let p_end=19+20*i + taskset -c $p_start-$p_end python3 ${cur_path}/../gru_8p.py \ + --addr=$(hostname -I |awk '{print $1}') \ + --data-dir $data_path \ + --seed 123456 \ + --workers 20 \ + --print-freq 1 \ + --dist-url 'tcp://127.0.0.1:50000' \ + --dist-backend 'hccl' \ + --multiprocessing-distributed \ + --world-size 1 \ + --batch-size $batch_size \ + --epoch $train_epochs \ + --rank 0 \ + --npu $i \ + --device-list '0,1,2,3,4,5,6,7' \ + --amp > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & + done +else + for i in $(seq 0 7) + do + python3 ${cur_path}/../gru_8p.py \ + --addr=$(hostname -I |awk '{print $1}') \ + --data-dir $data_path \ + --seed 123456 \ + --workers 80 \ + --print-freq 1 \ + --dist-url 'tcp://127.0.0.1:50000' \ + --dist-backend 'hccl' \ + --multiprocessing-distributed \ + --world-size 1 \ + --batch-size 12288 \ + --epoch 10 \ + --rank 0 \ + --npu $i \ + --device-list '0,1,2,3,4,5,6,7' \ + --amp > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & + done +fi +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS ${cur_path}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $NF}'|awk '{sum+=$1} END {print sum/NR}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep -a '* Acc@1' train_0.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` + +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep npu |awk -F 'Loss' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/built-in/nlp/XLM_ID0740_for_PyTorch/test/train_full_1p.sh b/PyTorch/built-in/nlp/XLM_ID0740_for_PyTorch/test/train_full_1p.sh index 61320ed9e0e726c24f6ef7c5661f2001e702dd59..8afe3d063c525deb0226f671aa6b86eeec39086e 100644 --- a/PyTorch/built-in/nlp/XLM_ID0740_for_PyTorch/test/train_full_1p.sh +++ b/PyTorch/built-in/nlp/XLM_ID0740_for_PyTorch/test/train_full_1p.sh @@ -1,228 +1,228 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -export ASCEND_SLOG_PRINT_TO_STDOUT=1 -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID - -#集合通信参数,不需要修改 -export RANK_SIZE=1 -RANK_ID_START=0 - -export NNPU=1 - -export HCCL_WHITELIST_DISABLE=1 -export MASTER_ADDR=127.0.0.1 -export MASTER_PORT=23456 -export RANK=0 -export WORLD_SIZE=1 - - - -# 数据集路径,保持为空,不需要修改 -data_path="" -# 指定训练所使用的npu device卡id -device_id=0 -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="XLM_ID0740_for_PyTorch" -#训练epoch -train_epochs=180 -#训练batch_size -batch_size=16 -#训练step -#train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.495 - -#TF2.X独有,不需要修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False - -# 帮助信息,不h需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_1p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${test_path_dir}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${test_path_dir}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${test_path_dir}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi -# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi -###############指定训练脚本执行路径############### -# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - -#################创建日志输出目录,不需要修改################# -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt -fi - -#################启动训练脚本################# -# 训练开始时间,不需要修改 -start_time=$(date +%s) -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi - -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - - #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 - #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` - #cpustep=`expr $cpucount / 8` - #echo "taskset c steps:" $cpustep - #let a=RANK_ID*$cpustep - #let b=RANK_ID+1 - #let c=b*$cpustep-1 - nohup python3.7 ${cur_path}/train.py \ - --data_path $data_path/50k \ - --exp_name xlm_en_zh \ - --dump_path ./dumped \ - --lgs 'en-zh' \ - --clm_steps '' \ - --mlm_steps 'en,zh' \ - --emb_dim 1024 \ - --n_layers 12 \ - --n_heads 16 \ - --dropout 0.1 \ - --attention_dropout 0.1 \ - --gelu_activation true \ - --batch_size $batch_size \ - --bptt 256 \ - --optimizer npu_fused_adam_v2,lr=0.00005 \ - --epoch_size 300000 \ - --max_epoch $train_epochs \ - --validation_metrics _valid_mlm_ppl \ - --stopping_criterion _valid_mlm_ppl,8 \ - --fp16 true \ - --amp 2 \ - --seed 1 \ - --local_rank $ASCEND_DEVICE_ID \ - --max_epoch 1 > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & - -done -wait - -#恢复参数 -#sed -i "s|break|pass|g" train.py - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep "sent/s" ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "sent/s -" '{print $2}'|awk '{print $1}'|tail -n +2|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` -#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*'${perf}'}'` - - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep eval_accuracy ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v mlp_log|awk 'END {print $5}'| sed 's/,//g' |cut -c 1-5` -train_accuracy=`grep "vaild_en_mlm_acc" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "vaild_en_mlm_acc ->" '{print $2}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据 -#吞吐量,不需要修改 -ActualFPS=${FPS} -#单迭代训练时长,不需要修改 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "sent/s" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "MLM-en: " '{print $2}'|awk '{print $1}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +export ASCEND_SLOG_PRINT_TO_STDOUT=1 +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID + +#集合通信参数,不需要修改 +export RANK_SIZE=1 +RANK_ID_START=0 + +export NNPU=1 + +export HCCL_WHITELIST_DISABLE=1 +export MASTER_ADDR=127.0.0.1 +export MASTER_PORT=23456 +export RANK=0 +export WORLD_SIZE=1 + + + +# 数据集路径,保持为空,不需要修改 +data_path="" +# 指定训练所使用的npu device卡id +device_id=0 +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="XLM_ID0740_for_PyTorch" +#训练epoch +train_epochs=180 +#训练batch_size +batch_size=16 +#训练step +#train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.495 + +#TF2.X独有,不需要修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False + +# 帮助信息,不h需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_1p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${test_path_dir}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${test_path_dir}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${test_path_dir}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi +# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi +###############指定训练脚本执行路径############### +# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +#################创建日志输出目录,不需要修改################# +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt +fi + +#################启动训练脚本################# +# 训练开始时间,不需要修改 +start_time=$(date +%s) +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + + #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 + #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` + #cpustep=`expr $cpucount / 8` + #echo "taskset c steps:" $cpustep + #let a=RANK_ID*$cpustep + #let b=RANK_ID+1 + #let c=b*$cpustep-1 + nohup python3.7 ${cur_path}/train.py \ + --data_path $data_path/50k \ + --exp_name xlm_en_zh \ + --dump_path ./dumped \ + --lgs 'en-zh' \ + --clm_steps '' \ + --mlm_steps 'en,zh' \ + --emb_dim 1024 \ + --n_layers 12 \ + --n_heads 16 \ + --dropout 0.1 \ + --attention_dropout 0.1 \ + --gelu_activation true \ + --batch_size $batch_size \ + --bptt 256 \ + --optimizer npu_fused_adam_v2,lr=0.00005 \ + --epoch_size 300000 \ + --max_epoch $train_epochs \ + --validation_metrics _valid_mlm_ppl \ + --stopping_criterion _valid_mlm_ppl,8 \ + --fp16 true \ + --amp 2 \ + --seed 1 \ + --local_rank $ASCEND_DEVICE_ID \ + --max_epoch 1 > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + +done +wait + +#恢复参数 +#sed -i "s|break|pass|g" train.py + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep "sent/s" ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "sent/s -" '{print $2}'|awk '{print $1}'|tail -n +2|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` +#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*'${perf}'}'` + + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep eval_accuracy ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v mlp_log|awk 'END {print $5}'| sed 's/,//g' |cut -c 1-5` +train_accuracy=`grep "vaild_en_mlm_acc" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "vaild_en_mlm_acc ->" '{print $2}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据 +#吞吐量,不需要修改 +ActualFPS=${FPS} +#单迭代训练时长,不需要修改 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "sent/s" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "MLM-en: " '{print $2}'|awk '{print $1}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/nlp/XLM_ID0740_for_PyTorch/test/train_performance_1p.sh b/PyTorch/built-in/nlp/XLM_ID0740_for_PyTorch/test/train_performance_1p.sh index b370bf358876562611bf5a66f3708ca715df92e9..1539f380f91787d2030461a0309b873449bbb976 100644 --- a/PyTorch/built-in/nlp/XLM_ID0740_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/built-in/nlp/XLM_ID0740_for_PyTorch/test/train_performance_1p.sh @@ -1,238 +1,238 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -export ASCEND_SLOG_PRINT_TO_STDOUT=1 -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID - -#集合通信参数,不需要修改 -export RANK_SIZE=1 -RANK_ID_START=0 - - -export NNPU=1 - -export HCCL_WHITELIST_DISABLE=1 -export MASTER_ADDR=127.0.0.1 -export MASTER_PORT=23456 -export RANK=0 -export WORLD_SIZE=1 - - - -# 数据集路径,保持为空,不需要修改 -data_path="" -# 指定训练所使用的npu device卡id -device_id=0 -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="XLM_ID0740_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=16 -#训练step -#train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.495 - -#TF2.X独有,不需要修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False - -# 帮助信息,不h需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_1p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${test_path_dir}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${test_path_dir}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${test_path_dir}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi -# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - -###############指定训练脚本执行路径############### -# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - -#################创建日志输出目录,不需要修改################# -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt -fi - -#################启动训练脚本################# -# 训练开始时间,不需要修改 -start_time=$(date +%s) -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi - -#sed -i "s|./data|$data_path|g" examples/cats_and_dogs.py -#sed -i "s|epochs = 20|epochs = 1|g" examples/cats_and_dogs.py -sed -i "s|pass|break|g" train.py - -#python3 setup.py install -#mkdir -p checkpoints -#mkdir -p /root/.cache/torch/hub/checkpoints -#cp $data_path/fcn_* /root/.cache/torch/hub/checkpoints - -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - - #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 - #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` - #cpustep=`expr $cpucount / 8` - #echo "taskset c steps:" $cpustep - #let a=RANK_ID*$cpustep - #let b=RANK_ID+1 - #let c=b*$cpustep-1 - nohup python3.7 ${cur_path}/train.py \ - --data_path $data_path/50k \ - --exp_name xlm_en_zh \ - --dump_path ./dumped \ - --lgs 'en-zh' \ - --clm_steps '' \ - --mlm_steps 'en,zh' \ - --emb_dim 1024 \ - --n_layers 12 \ - --n_heads 16 \ - --dropout 0.1 \ - --attention_dropout 0.1 \ - --gelu_activation true \ - --batch_size $batch_size \ - --bptt 256 \ - --optimizer npu_fused_adam_v2,lr=0.00005 \ - --epoch_size 300000 \ - --max_epoch $train_epochs \ - --validation_metrics _valid_mlm_ppl \ - --stopping_criterion _valid_mlm_ppl,8 \ - --fp16 true \ - --amp 2 \ - --seed 1 \ - --local_rank $ASCEND_DEVICE_ID \ - --max_epoch 1 > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & - -done -wait - -#恢复参数 -sed -i "s|break|pass|g" train.py - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep "sent/s" ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "sent/s -" '{print $2}'|awk '{print $1}'|tail -n +2|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` -#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*'${perf}'}'` - - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep eval_accuracy ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v mlp_log|awk 'END {print $5}'| sed 's/,//g' |cut -c 1-5` -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -#echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据 -#吞吐量,不需要修改 -ActualFPS=${FPS} -#单迭代训练时长,不需要修改 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "sent/s" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "MLM-en: " '{print $2}'|awk '{print $1}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -#echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +export ASCEND_SLOG_PRINT_TO_STDOUT=1 +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID + +#集合通信参数,不需要修改 +export RANK_SIZE=1 +RANK_ID_START=0 + + +export NNPU=1 + +export HCCL_WHITELIST_DISABLE=1 +export MASTER_ADDR=127.0.0.1 +export MASTER_PORT=23456 +export RANK=0 +export WORLD_SIZE=1 + + + +# 数据集路径,保持为空,不需要修改 +data_path="" +# 指定训练所使用的npu device卡id +device_id=0 +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="XLM_ID0740_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=16 +#训练step +#train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.495 + +#TF2.X独有,不需要修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False + +# 帮助信息,不h需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_1p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${test_path_dir}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${test_path_dir}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${test_path_dir}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi +# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + +###############指定训练脚本执行路径############### +# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +#################创建日志输出目录,不需要修改################# +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID/ckpt +fi + +#################启动训练脚本################# +# 训练开始时间,不需要修改 +start_time=$(date +%s) +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +#sed -i "s|./data|$data_path|g" examples/cats_and_dogs.py +#sed -i "s|epochs = 20|epochs = 1|g" examples/cats_and_dogs.py +sed -i "s|pass|break|g" train.py + +#python3 setup.py install +#mkdir -p checkpoints +#mkdir -p /root/.cache/torch/hub/checkpoints +#cp $data_path/fcn_* /root/.cache/torch/hub/checkpoints + +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + + #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 + #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` + #cpustep=`expr $cpucount / 8` + #echo "taskset c steps:" $cpustep + #let a=RANK_ID*$cpustep + #let b=RANK_ID+1 + #let c=b*$cpustep-1 + nohup python3.7 ${cur_path}/train.py \ + --data_path $data_path/50k \ + --exp_name xlm_en_zh \ + --dump_path ./dumped \ + --lgs 'en-zh' \ + --clm_steps '' \ + --mlm_steps 'en,zh' \ + --emb_dim 1024 \ + --n_layers 12 \ + --n_heads 16 \ + --dropout 0.1 \ + --attention_dropout 0.1 \ + --gelu_activation true \ + --batch_size $batch_size \ + --bptt 256 \ + --optimizer npu_fused_adam_v2,lr=0.00005 \ + --epoch_size 300000 \ + --max_epoch $train_epochs \ + --validation_metrics _valid_mlm_ppl \ + --stopping_criterion _valid_mlm_ppl,8 \ + --fp16 true \ + --amp 2 \ + --seed 1 \ + --local_rank $ASCEND_DEVICE_ID \ + --max_epoch 1 > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + +done +wait + +#恢复参数 +sed -i "s|break|pass|g" train.py + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep "sent/s" ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "sent/s -" '{print $2}'|awk '{print $1}'|tail -n +2|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` +#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*'${perf}'}'` + + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep eval_accuracy ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v mlp_log|awk 'END {print $5}'| sed 's/,//g' |cut -c 1-5` +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +#echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据 +#吞吐量,不需要修改 +ActualFPS=${FPS} +#单迭代训练时长,不需要修改 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "sent/s" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "MLM-en: " '{print $2}'|awk '{print $1}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +#echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/built-in/nlp/mBART_ID2372_for_PyTorch/test/set_conda.sh b/PyTorch/built-in/nlp/mBART_ID2372_for_PyTorch/test/set_conda.sh index 55087d8622f46e055bb105a2acd1fe7006d4af07..febb0fa34937160c9ad16c92dcb67cd4005e2f57 100644 --- a/PyTorch/built-in/nlp/mBART_ID2372_for_PyTorch/test/set_conda.sh +++ b/PyTorch/built-in/nlp/mBART_ID2372_for_PyTorch/test/set_conda.sh @@ -1,2 +1,2 @@ -export PATH=/home/anaconda3/bin:$PATH +export PATH=/home/anaconda3/bin:$PATH export LD_LIBRARY_PATH=/home/anaconda3/lib:$LD_LIBRARY_PATH \ No newline at end of file diff --git a/PyTorch/built-in/others/WDL_for_PyTorch/LICENSE b/PyTorch/built-in/others/WDL_for_PyTorch/LICENSE index deeea2d8ccdb1354f351a6ea02ed456849d51422..b09cd7856d58590578ee1a4f3ad45d1310a97f87 100644 --- a/PyTorch/built-in/others/WDL_for_PyTorch/LICENSE +++ b/PyTorch/built-in/others/WDL_for_PyTorch/LICENSE @@ -1,201 +1,201 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/PyTorch/built-in/others/WDL_for_PyTorch/criteo_preprocess.py b/PyTorch/built-in/others/WDL_for_PyTorch/criteo_preprocess.py index a1c942a4275137a5918f0d24a412a24c4470fd16..ef2d419dcf06d3bec388b69a298421866c5b0345 100644 --- a/PyTorch/built-in/others/WDL_for_PyTorch/criteo_preprocess.py +++ b/PyTorch/built-in/others/WDL_for_PyTorch/criteo_preprocess.py @@ -1,54 +1,54 @@ -# -*- coding: utf-8 -*- - -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# less required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import sys -import os -import pandas as pd -from sklearn.model_selection import train_test_split -from sklearn.preprocessing import LabelEncoder, MinMaxScaler - - -if __name__ == '__main__': - data_path = os.path.abspath(sys.argv[1]) - - SPARSE_FEATURES_NUM = 27 - DENSE_FEATURES_NUM = 14 - - sparse_features = ['C' + str(i) for i in range(1, SPARSE_FEATURES_NUM)] - dense_features = ['I' + str(i) for i in range(1, DENSE_FEATURES_NUM)] - target = ['label'] - - name_column = target + dense_features + sparse_features - - data = pd.read_csv(data_path, names=name_column, sep='\t') - data[sparse_features] = data[sparse_features].fillna('-1', ) - data[dense_features] = data[dense_features].fillna(0, ) - - for feat in sparse_features: - print(feat) - lbe = LabelEncoder() - data[feat] = lbe.fit_transform(data[feat]) - mms = MinMaxScaler(feature_range=(0, 1)) - data[dense_features] = mms.fit_transform(data[dense_features]) - train, test = train_test_split(data, test_size=0.1, random_state=2020) - - pd.DataFrame(train, columns=name_column).to_pickle(os.path.dirname(data_path) + '/wdl_trainval.pkl') - pd.DataFrame(test, columns=name_column).to_pickle(os.path.dirname(data_path) + '/wdl_test.pkl') - - # the val dataset for inferring - infer_column = target + sparse_features + dense_features - pd.DataFrame(test, columns=infer_column).to_csv(os.path.dirname(data_path) + '/wdl_infer.txt', index=False) +# -*- coding: utf-8 -*- + +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# less required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import sys +import os +import pandas as pd +from sklearn.model_selection import train_test_split +from sklearn.preprocessing import LabelEncoder, MinMaxScaler + + +if __name__ == '__main__': + data_path = os.path.abspath(sys.argv[1]) + + SPARSE_FEATURES_NUM = 27 + DENSE_FEATURES_NUM = 14 + + sparse_features = ['C' + str(i) for i in range(1, SPARSE_FEATURES_NUM)] + dense_features = ['I' + str(i) for i in range(1, DENSE_FEATURES_NUM)] + target = ['label'] + + name_column = target + dense_features + sparse_features + + data = pd.read_csv(data_path, names=name_column, sep='\t') + data[sparse_features] = data[sparse_features].fillna('-1', ) + data[dense_features] = data[dense_features].fillna(0, ) + + for feat in sparse_features: + print(feat) + lbe = LabelEncoder() + data[feat] = lbe.fit_transform(data[feat]) + mms = MinMaxScaler(feature_range=(0, 1)) + data[dense_features] = mms.fit_transform(data[dense_features]) + train, test = train_test_split(data, test_size=0.1, random_state=2020) + + pd.DataFrame(train, columns=name_column).to_pickle(os.path.dirname(data_path) + '/wdl_trainval.pkl') + pd.DataFrame(test, columns=name_column).to_pickle(os.path.dirname(data_path) + '/wdl_test.pkl') + + # the val dataset for inferring + infer_column = target + sparse_features + dense_features + pd.DataFrame(test, columns=infer_column).to_csv(os.path.dirname(data_path) + '/wdl_infer.txt', index=False) diff --git a/PyTorch/built-in/others/WDL_for_PyTorch/infer/Dockerfile b/PyTorch/built-in/others/WDL_for_PyTorch/infer/Dockerfile index 499c927d66a694289181f04ae8c0e8ca8d5aaf9a..45963fec3c75661ef40ed69d3b29f536162dce91 100644 --- a/PyTorch/built-in/others/WDL_for_PyTorch/infer/Dockerfile +++ b/PyTorch/built-in/others/WDL_for_PyTorch/infer/Dockerfile @@ -1,30 +1,30 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# less required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -ARG FROM_IMAGE_NAME -FROM $FROM_IMAGE_NAME - -ARG SDK_PKG - -RUN ln -s /usr/local/python3.7.5/bin/python3.7 /usr/bin/python - -COPY requirements.txt . -RUN pip3.7 install -r requirements.txt - -COPY $SDK_PKG . -RUN ls -hrlt -RUN chmod +x ${SDK_PKG} && \ - ./${SDK_PKG} --install-path=/home/run --install && \ - bash -c "source ~/.bashrc" +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# less required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +ARG FROM_IMAGE_NAME +FROM $FROM_IMAGE_NAME + +ARG SDK_PKG + +RUN ln -s /usr/local/python3.7.5/bin/python3.7 /usr/bin/python + +COPY requirements.txt . +RUN pip3.7 install -r requirements.txt + +COPY $SDK_PKG . +RUN ls -hrlt +RUN chmod +x ${SDK_PKG} && \ + ./${SDK_PKG} --install-path=/home/run --install && \ + bash -c "source ~/.bashrc" diff --git a/PyTorch/built-in/others/WDL_for_PyTorch/infer/requirements.txt b/PyTorch/built-in/others/WDL_for_PyTorch/infer/requirements.txt index 614cfb822e968a89b2c13553bb2fc867ffa07fec..2377a25ade659e02764560acb9d13e8d472fc96c 100644 --- a/PyTorch/built-in/others/WDL_for_PyTorch/infer/requirements.txt +++ b/PyTorch/built-in/others/WDL_for_PyTorch/infer/requirements.txt @@ -1,4 +1,4 @@ -sklearn -pandas -tqdm +sklearn +pandas +tqdm numpy \ No newline at end of file diff --git a/PyTorch/built-in/others/WDL_for_PyTorch/modelzoo_level.txt b/PyTorch/built-in/others/WDL_for_PyTorch/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/built-in/others/WDL_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/built-in/others/WDL_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/built-in/others/WDL_for_PyTorch/requirements.txt b/PyTorch/built-in/others/WDL_for_PyTorch/requirements.txt index 0dda92456944604ae2c952524765cafa9722500e..83cfd38dfb33665b0293688c94f26d1e152d0751 100644 --- a/PyTorch/built-in/others/WDL_for_PyTorch/requirements.txt +++ b/PyTorch/built-in/others/WDL_for_PyTorch/requirements.txt @@ -1,4 +1,4 @@ -sklearn -pandas==1.3.3 -tqdm +sklearn +pandas==1.3.3 +tqdm numpy \ No newline at end of file diff --git a/PyTorch/built-in/others/WDL_for_PyTorch/run_classification_criteo_wdl.py b/PyTorch/built-in/others/WDL_for_PyTorch/run_classification_criteo_wdl.py index 077ebd6ff94bfa81509a9c9bea61a1c880e5825f..57bc0ed23b893da5cdf2e620f54603f88c3c7aaa 100644 --- a/PyTorch/built-in/others/WDL_for_PyTorch/run_classification_criteo_wdl.py +++ b/PyTorch/built-in/others/WDL_for_PyTorch/run_classification_criteo_wdl.py @@ -1,141 +1,141 @@ -# -*- coding: utf-8 -*- - -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# less required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - - -import os -import time -import random -import argparse - -import numpy as np -import pandas as pd - -import sklearn -import torch - -from sklearn.metrics import log_loss, roc_auc_score - -from deepctr_torch.inputs import SparseFeat, DenseFeat, get_feature_names -from deepctr_torch.models import WDL - - -def args_parser(): - parser = argparse.ArgumentParser(description='Wide&Deep') - parser.add_argument('--seed', default=1234, type=int, - help='seed for initializing training.') - parser.add_argument('--device_id', default=0, type=int, help='device id') - parser.add_argument('--rank', default=0, type=int, help='node rank for distributed training') - parser.add_argument('--dist', default=False, action='store_true', help='8p distributed training') - parser.add_argument('--device_num', default=1, type=int, - help='num of npu device for training') - parser.add_argument('--amp', default=False, action='store_true', - help='use amp to train the model') - parser.add_argument('--loss_scale', default=1024, type=float, - help='loss scale using in amp, default -1 means dynamic') - parser.add_argument('--opt_level', default='O1', type=str, - help='apex opt level') - parser.add_argument('--data_path', required=True, type=str, help='train data, and is to be') - parser.add_argument('--resume', default='', type=str, metavar='PATH', - help='path to latest checkpoint (default: none)') - parser.add_argument('--checkpoint_save_path', default='./', type=str, metavar='PATH', - help='path to save latest checkpoint') - parser.add_argument('--lr', default=0.0001, type=float, help='learning rate for training') - parser.add_argument('--batch_size', default=1024, type=int, help='batch size for training') - parser.add_argument('--eval_batch_size', default=16000, type=int, help='batch size for testing') - parser.add_argument('--epochs', default=3, type=int, help='epochs for training') - parser.add_argument('--start_epoch', default=0, type=int, metavar='N', help='record of the start epoch to run') - parser.add_argument('--sparse_embed_dim', default=4, type=int, help='The embedding dims for sparse features') - parser.add_argument('--steps', default=0, type=int, help='steps for training') - - parser_args, _ = parser.parse_known_args() - return parser_args - - -def fix_random(seed): - torch.manual_seed(seed) - torch.cuda.manual_seed(seed) - torch.cuda.manual_seed_all(seed) - np.random.seed(seed) - random.seed(seed) - - -if __name__ == "__main__": - args = args_parser() - print(args) - - fix_random(args.seed) - - sparse_features = ['C' + str(i) for i in range(1, 27)] - dense_features = ['I' + str(i) for i in range(1, 14)] - target = ['label'] - - # count #unique features for each sparse field,and record dense feature field name - start_time = time.time() - - data_trainval = pd.read_pickle(os.path.join(args.data_path, 'wdl_trainval.pkl')) - data_test = pd.read_pickle(os.path.join(args.data_path, 'wdl_test.pkl')) - - print('Data loaded in {}s'.format(time.time() - start_time)) - - sparse_nunique = [1460, 583, 10131227, 2202608, 305, 24, 12517, 633, 3, 93145, 5683, 8351593, 3194, 27, 14992, - 5461306, 10, 5652, 2173, 4, 7046547, 18, 15, 286181, 105, 142572] - fixlen_feature_columns = [SparseFeat(feat, sparse_nunique[idx], embedding_dim=args.sparse_embed_dim) - for idx, feat in enumerate(sparse_features)] + [DenseFeat(feat, 1, ) - for feat in dense_features] - print(fixlen_feature_columns) - - dnn_feature_columns = fixlen_feature_columns - linear_feature_columns = fixlen_feature_columns - - feature_names = get_feature_names( - linear_feature_columns + dnn_feature_columns) - - # generate input data for model - print('Generating input data for model...') - start_time = time.time() - train_model_input = {name: data_trainval[name].astype(float) for name in feature_names} - test_model_input = {name: data_test[name].astype(float) for name in feature_names} - print('Input data generated in {}s'.format(time.time() - start_time)) - - # Define Model,train,predict and evaluate - args.device_num = int(os.environ["RANK_SIZE"]) - if args.dist: - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = '29680' - - args.rank = args.device_id - torch.distributed.init_process_group(backend='hccl', world_size=args.device_num, rank=args.rank) - print('distributed train enabled') - - device = 'npu:' + str(args.device_id) - torch.npu.set_device(device) - print('train on: ', device) - - model = WDL(linear_feature_columns=linear_feature_columns, dnn_feature_columns=dnn_feature_columns, - task='binary', dnn_hidden_units=(512, 256, 128), dnn_dropout=0.5, device=device, l2_reg_linear=1e-4, - l2_reg_embedding=1e-4, dist=args.dist) - - model.compile("adam", "binary_crossentropy", - metrics=["binary_crossentropy", "auc"], lr=args.lr, args=args) - - history = model.fit(train_model_input, data_trainval[target].values, batch_size=args.batch_size, epochs=args.epochs, - verbose=2, - validation_split=0.3, args=args) - - pred_ans = model.predict(test_model_input, args.eval_batch_size) - print("test LogLoss", round(log_loss(data_test[target].values, pred_ans), 4)) - print("test AUC", round(roc_auc_score(data_test[target].values, pred_ans), 4)) +# -*- coding: utf-8 -*- + +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# less required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + + +import os +import time +import random +import argparse + +import numpy as np +import pandas as pd + +import sklearn +import torch + +from sklearn.metrics import log_loss, roc_auc_score + +from deepctr_torch.inputs import SparseFeat, DenseFeat, get_feature_names +from deepctr_torch.models import WDL + + +def args_parser(): + parser = argparse.ArgumentParser(description='Wide&Deep') + parser.add_argument('--seed', default=1234, type=int, + help='seed for initializing training.') + parser.add_argument('--device_id', default=0, type=int, help='device id') + parser.add_argument('--rank', default=0, type=int, help='node rank for distributed training') + parser.add_argument('--dist', default=False, action='store_true', help='8p distributed training') + parser.add_argument('--device_num', default=1, type=int, + help='num of npu device for training') + parser.add_argument('--amp', default=False, action='store_true', + help='use amp to train the model') + parser.add_argument('--loss_scale', default=1024, type=float, + help='loss scale using in amp, default -1 means dynamic') + parser.add_argument('--opt_level', default='O1', type=str, + help='apex opt level') + parser.add_argument('--data_path', required=True, type=str, help='train data, and is to be') + parser.add_argument('--resume', default='', type=str, metavar='PATH', + help='path to latest checkpoint (default: none)') + parser.add_argument('--checkpoint_save_path', default='./', type=str, metavar='PATH', + help='path to save latest checkpoint') + parser.add_argument('--lr', default=0.0001, type=float, help='learning rate for training') + parser.add_argument('--batch_size', default=1024, type=int, help='batch size for training') + parser.add_argument('--eval_batch_size', default=16000, type=int, help='batch size for testing') + parser.add_argument('--epochs', default=3, type=int, help='epochs for training') + parser.add_argument('--start_epoch', default=0, type=int, metavar='N', help='record of the start epoch to run') + parser.add_argument('--sparse_embed_dim', default=4, type=int, help='The embedding dims for sparse features') + parser.add_argument('--steps', default=0, type=int, help='steps for training') + + parser_args, _ = parser.parse_known_args() + return parser_args + + +def fix_random(seed): + torch.manual_seed(seed) + torch.cuda.manual_seed(seed) + torch.cuda.manual_seed_all(seed) + np.random.seed(seed) + random.seed(seed) + + +if __name__ == "__main__": + args = args_parser() + print(args) + + fix_random(args.seed) + + sparse_features = ['C' + str(i) for i in range(1, 27)] + dense_features = ['I' + str(i) for i in range(1, 14)] + target = ['label'] + + # count #unique features for each sparse field,and record dense feature field name + start_time = time.time() + + data_trainval = pd.read_pickle(os.path.join(args.data_path, 'wdl_trainval.pkl')) + data_test = pd.read_pickle(os.path.join(args.data_path, 'wdl_test.pkl')) + + print('Data loaded in {}s'.format(time.time() - start_time)) + + sparse_nunique = [1460, 583, 10131227, 2202608, 305, 24, 12517, 633, 3, 93145, 5683, 8351593, 3194, 27, 14992, + 5461306, 10, 5652, 2173, 4, 7046547, 18, 15, 286181, 105, 142572] + fixlen_feature_columns = [SparseFeat(feat, sparse_nunique[idx], embedding_dim=args.sparse_embed_dim) + for idx, feat in enumerate(sparse_features)] + [DenseFeat(feat, 1, ) + for feat in dense_features] + print(fixlen_feature_columns) + + dnn_feature_columns = fixlen_feature_columns + linear_feature_columns = fixlen_feature_columns + + feature_names = get_feature_names( + linear_feature_columns + dnn_feature_columns) + + # generate input data for model + print('Generating input data for model...') + start_time = time.time() + train_model_input = {name: data_trainval[name].astype(float) for name in feature_names} + test_model_input = {name: data_test[name].astype(float) for name in feature_names} + print('Input data generated in {}s'.format(time.time() - start_time)) + + # Define Model,train,predict and evaluate + args.device_num = int(os.environ["RANK_SIZE"]) + if args.dist: + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '29680' + + args.rank = args.device_id + torch.distributed.init_process_group(backend='hccl', world_size=args.device_num, rank=args.rank) + print('distributed train enabled') + + device = 'npu:' + str(args.device_id) + torch.npu.set_device(device) + print('train on: ', device) + + model = WDL(linear_feature_columns=linear_feature_columns, dnn_feature_columns=dnn_feature_columns, + task='binary', dnn_hidden_units=(512, 256, 128), dnn_dropout=0.5, device=device, l2_reg_linear=1e-4, + l2_reg_embedding=1e-4, dist=args.dist) + + model.compile("adam", "binary_crossentropy", + metrics=["binary_crossentropy", "auc"], lr=args.lr, args=args) + + history = model.fit(train_model_input, data_trainval[target].values, batch_size=args.batch_size, epochs=args.epochs, + verbose=2, + validation_split=0.3, args=args) + + pred_ans = model.predict(test_model_input, args.eval_batch_size) + print("test LogLoss", round(log_loss(data_test[target].values, pred_ans), 4)) + print("test AUC", round(roc_auc_score(data_test[target].values, pred_ans), 4)) diff --git a/PyTorch/contrib/CONTRIBUTING.md b/PyTorch/contrib/CONTRIBUTING.md index 886fae1007aa07d5711d863a1941c4cd7356bdb9..dc9d11e8ea435028f1e4dd85543104c7547b7469 100644 --- a/PyTorch/contrib/CONTRIBUTING.md +++ b/PyTorch/contrib/CONTRIBUTING.md @@ -1,314 +1,314 @@ - **介绍** - -Ascend ModelZoo,欢迎各位开发者 - - **贡献要求** - -开发者提交的模型包括源码、readme、参考模型license文件、测试用例和readme,并遵循以下标准 - -请贡献者在提交代码之前签署CLA协议,“个人签署”,[链接](https://clasign.osinfra.cn/sign/Z2l0ZWUlMkZhc2NlbmQ=) - -如您完成签署,可在自己提交的PR评论区输入/check-cla进行核实校验 - - **一、源码** - -1、训练及在线推理请使用python代码实现,Ascend平台离线推理请使用C++或python代码,符合第四部分编码规范 - -2、参考[sample](https://gitee.com/ascend/modelzoo/tree/master/built-in/TensorFlow/Official/nlp/Transformer_for_TensorFlow) - -3、贡献者模型代码目录规则:"modelzoo/contrib/框架/Research/应用领域(nlp、cv、audio等)/网络名_IDxxx_for_TensorFlow"(以tf为例,社区管理团队会在贡献完成进行整合) - -4、从其他开源迁移的代码,请增加License声明 - - **二、License规则** - -* TensorFlow - - 迁移场景 - - 1、迁移TensorFlow模型中若源项目已包含License文件则必须拷贝引用,否则在模型顶层目录下添加TensorFlow Apache 2.0 License [TensorFlow License链接](https://github.com/tensorflow/tensorflow/blob/master/LICENSE) - - 2、迁移TensorFlow框架开发的模型,需要在模型目录下每个源文件附上源社区TensorFlow Apache 2.0 License头部声明,并在其下追加新增完整华为公司License声明 - - ``` - # Copyright 2017 The TensorFlow Authors. All Rights Reserved. - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - # ============================================================================ - # Copyright 2021 Huawei Technologies Co., Ltd - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ``` - 开发场景 - - 1、基于TensorFlow框架开发模型,需在模型项目顶层目录下添加TensorFlow Apache 2.0 License [TensorFlow License链接](https://github.com/tensorflow/tensorflow/blob/master/LICENSE) - - 2、基于TensorFlow框架开发模型,需要在模型目录下每个源文件附上源社区华为公司Apache 2.0 License头部声明 - ``` - # Copyright 2021 Huawei Technologies Co., Ltd - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ``` -* PyTorch - - 迁移场景 - - 1、迁移PyTorch模型中若源项目录已包含PyTorch License文件则必须拷贝引用,否则在模型顶层目录下添加PyTorch BSD-3 License [PyTorch License链接](https://github.com/pytorch/examples/blob/master/LICENSE) - - 2、迁移PyTorch第三方框架开发的模型,需要在模型目录下每个源文件附上源社区PyTorch BSD-3 License头部声明,并在其下追加新增一行华为公司License声明 - ``` - # BSD 3-Clause License - # - # Copyright (c) 2017 xxxx - # All rights reserved. - # Copyright 2021 Huawei Technologies Co., Ltd - # - # Redistribution and use in source and binary forms, with or without - # modification, are permitted provided that the following conditions are met: - # - # * Redistributions of source code must retain the above copyright notice, this - # list of conditions and the following disclaimer. - # - # * Redistributions in binary form must reproduce the above copyright notice, - # this list of conditions and the following disclaimer in the documentation - # and/or other materials provided with the distribution. - # - # * Neither the name of the copyright holder nor the names of its - # contributors may be used to endorse or promote products derived from - # this software without specific prior written permission. - # - # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - # ============================================================================ - ``` - - 开发场景 - - 1、基于PyTorch框架开发模型,需在模型项目下添加PyTorch BSD-3 License [PyTorch License链接](https://github.com/pytorch/examples/blob/master/LICENSE) - - 2、基于PyTorch框架开发模型,需要在模型目录下每个源文件附上源社区华为公司Apache 2.0 License头部声明 - ``` - # Copyright 2021 Huawei Technologies Co., Ltd - # - # Licensed under the BSD 3-Clause License (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # https://opensource.org/licenses/BSD-3-Clause - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ``` - -* MindSpore/ACL - - 1、迁移或开发场景下MindSpore/ACL模型顶层目录下需要包含华为公司 License [华为公司 License链接](https://gitee.com/mindspore/mindspore/blob/master/LICENSE) - - 2、迁移或开发场景下MindSpore/ACL模型,需要在模型目录下每个源文件中添加区华为公司Apache 2.0 License头部声明 - ``` - # Copyright 2021 Huawei Technologies Co., Ltd - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - ``` - -> 关于License声明时间,应注意: 2021年新建的文件,应该是Copyright 2021 Huawei Technologies Co., Ltd 2020年创建年份,2020年修改年份,应该是Copyright 2020 Huawei Technologies Co., Ltd - - **三、readme** - -readme用于指导用户理解和部署样例,要包含如下内容: - -- 简介: - -1、模型的来源及原理; - -2、模型复现的步骤,含训练、eval、在线/离线推理等,入口请封装成`.sh`、`.py`; - -- 关键要求: - -1、模型的出处、对数据的要求、免责声明等,开源代码文件修改需要增加版权说明; - -2、模型转换得到的离线模型对输入数据的要求; - -3、环境变量设置,依赖的第三方软件包和库,以及安装方法; - -4、精度和性能达成要求:尽量达到原始模型水平; - -5、预训练checkpoint、结果checkpoint请提供归档OBS、网盘链接,如来自开源需明确来源地址 - -6、数据集说明 - -- [ ] 不允许直接提供数据集的下载链接,可使用词汇:用户自行准备好数据集,可选用“XXX”,“XXX”,“XXX” - - 例如:请用户自行准备好数据集,包含训练集和验证集两部分,可选用的数据集包括ImageNet2012,CIFAR10、Flower等,包含train和val两部分。 - -- [ ] 脚本中不允许提供链接下载数据集,如果开源脚本上存在对应的链接,请修改或者删除对应的脚本 - -训练ReadMe写作可参考下面两个链接: - -[Readme example1](https://gitee.com/ascend/modelzoo/blob/master/built-in/TensorFlow/Official/cv/image_classification/DenseNet121_ID0067_for_TensorFlow/README.md) - -[Readme example2](https://www.hiascend.com/zh/software/modelzoo/detail/C/093ed0219cb14f068af33784c62cf7ec) - -离线推理ReadMe写作可参考下面链接: - -[Readme example1](https://gitee.com/ascend/modelzoo/tree/master/contrib/ACL_TensorFlow/Research/cv/AdvancedEAST_ID0130_for_ACL/README.md) - - **四、自测试用例** - -提供模型的自测试用例和readme,提交PR需要门禁及模型测试用例通过,性能和精度检查通过 - -- 简介: - -1、不同于完整的训练过程和全量数据集的推理,自测试用例的目的是验证提交代码基本功能可用,执行时长控制在10min之内(推理或训练只需执行有限的图片或step); - -2、提交PR中训练用例入口`train_testcase.sh`, 在线推理用例入口`online_inference_testcase.sh`, 离线推理用例入口`offline_inference_testcase.sh`; - -3、提交PR后,会自动触发门禁流水,后台会根据用例入口shell,自动将代码分发到对应执行环境; - -4、Jenkins预置账号:登录账号请联系华为工程师/接口人获取,登录之后,可以查看到用例执行日志 - -5、如果提交失败,请查看日志,修复代码或其他问题后,在你当前的PR中,评论“compile”即可重新触发用例执行 - -- 关键要求: - -1、自测试用例命名严格按照上述简介2要求来书写,否则门禁会校验失败; - -2、用例应当包含功能、精度(Loss值)、性能检查,检查通过打印"Run testcase success!",失败则打印"Run testcase failed!"; - -3、执行环境已预装软件包和Python3.7.5环境,调用命令"python3"、"python3.7"、"python3.7.5"均可,安装第三方库依赖使用"pip3"、"pip3.7"均可; - -4、数据集和模型:小于500M的文件,建议使用`obsutil`命令下载(已预装),过大的文件,建议提交Issue,注明数据集和下载地址,会提前下载到执行环境上, - -已预置数据集&python第三方库: [Environments](https://gitee.com/ascend/modelzoo/blob/master/contrib/ENVIRONMENTS.md) - -5、环境和其他问题,请提交Issue跟踪; - -6、测试用例开发参考: -- [训练](https://gitee.com/ascend/modelzoo/tree/master/built-in/TensorFlow/Official/nlp/Transformer_for_TensorFlow) -- [离线推理](https://gitee.com/alexcheng88/modelzoo/tree/master/contrib/TensorFlow/Research/cv/efficientnet-b8/ATC_efficientnet-b8_tf_nkxiaolei) - - **五、PR提交** - -- 关键要求: - -1、请将modelzoo仓fork到个人分支,基于个人分支新增、修改和提交PR; - -2、PR标题:线上活动,请在标题注明[线上贡献];高校活动,请注明[xxx学校][高校贡献]; - -3、built-in用户根据网络状态必须配置modelzoo_level.txt文件,且文件内容包含三个关键字段:FuncStatus(OK-流程通过/ **NOK-流程失败,不允许模型代码提交主仓** );PerfStatus(OK-持平GPU/POK-0.5倍GPU/NOK-小于0.5倍GPU/PERFECT-1.2倍GPU);PrecisionStatus(OK-精度达标,POK-Loss拟合但精度未实施, **NOK-Loss不拟合,不允许模型代码提交主仓** );内容格式如下所示(注:“:”两侧无需空格,英文格式;): - -``` - FuncStatus:OK/NOK - PerfStatus:PERFECT/OK/POK/NOK - PrecisionStatus:OK/POK/NOK -``` -4、contrib用户根据网络状态必须配置modelzoo_level.txt文件,且文件内容包含关键字段:GPUStatus(OK-GPU复现/NOK-GPU未复现); NPUMigrationStatus(OK-自动迁移成功/POK-自动迁移失败, 手写规避成功/NOK-均失败); FuncStatus(OK-基础功能打通/NOK-基础功能失败,不允许模型代码提交到master); PrecisionStatus(OK-精度达标/POK-Loss拟合但精度未完全达标/NOK-精度不达标, 不允许模型代码提交到master); AutoTune(OK-性能持平或高于GPU/POK-性能有提升但低于GPU/NOK-性能无提升或者功能失败); PerfStatus(训练:PERFECT-性能1.2倍GPU/OK-性能持平GPU/POK-性能0.5倍GPU/NOK-性能小于0.5倍GPU;推理:OK-4*310单卡>GPU/NOK-其它); ModelConvert:OK/NOK(仅推理, OK-om转换成功/NOK-om转换失败); QuantStatus:OK/NOK(仅推理, OK-精度损失1%以内,性能有提升/POK-性能有提升但未达标/NOK-量化失败); - -样例:modelzoo_level.txt文件 - ------仅限训练----- - - -``` -GPUStatus:OK/NOK -NPUMigrationStatus:OK/POK/NOK -``` - - ------仅限推理----- - -``` -ModelConvert:OK/POK/NOK -QuantStatus:OK/POK/NOK -``` - ------通用部分----- - -``` -FuncStatus:OK/NOK -PrecisionStatus:OK/POK/NOK -AutoTune:OK/POK/NOK -PerfStatus:PERFECT/OK/POK/NOK -``` -5、网络名称命名规范:*_for_框架,注:*代表任意内容,如网络名称或网络名称+网络ID; - - **六、编程规范** - -- 规范标准 - -1、C++代码遵循google编程规范:Google C++ Coding Guidelines;单元测测试遵循规范: Googletest Primer。 - -2、Python代码遵循PEP8规范:Python PEP 8 Coding Style;单元测试遵循规范: pytest - -- 规范备注 - -1、优先使用string类型,避免使用char*; - -2、禁止使用printf,一律使用cout; - -3、内存管理尽量使用智能指针; - -4、不准在函数里调用exit; - -5、禁止使用IDE等工具自动生成代码; - -6、控制第三方库依赖,如果引入第三方依赖,则需要提供第三方依赖安装和使用指导书; - -7、一律使用英文注释,注释率30%--40%,鼓励自注释; - -8、函数头必须有注释,说明函数作用,入参、出参; - -9、统一错误码,通过错误码可以确认那个分支返回错误; - -10、禁止出现打印一堆无影响的错误级别的日志; + **介绍** + +Ascend ModelZoo,欢迎各位开发者 + + **贡献要求** + +开发者提交的模型包括源码、readme、参考模型license文件、测试用例和readme,并遵循以下标准 + +请贡献者在提交代码之前签署CLA协议,“个人签署”,[链接](https://clasign.osinfra.cn/sign/Z2l0ZWUlMkZhc2NlbmQ=) + +如您完成签署,可在自己提交的PR评论区输入/check-cla进行核实校验 + + **一、源码** + +1、训练及在线推理请使用python代码实现,Ascend平台离线推理请使用C++或python代码,符合第四部分编码规范 + +2、参考[sample](https://gitee.com/ascend/modelzoo/tree/master/built-in/TensorFlow/Official/nlp/Transformer_for_TensorFlow) + +3、贡献者模型代码目录规则:"modelzoo/contrib/框架/Research/应用领域(nlp、cv、audio等)/网络名_IDxxx_for_TensorFlow"(以tf为例,社区管理团队会在贡献完成进行整合) + +4、从其他开源迁移的代码,请增加License声明 + + **二、License规则** + +* TensorFlow + + 迁移场景 + + 1、迁移TensorFlow模型中若源项目已包含License文件则必须拷贝引用,否则在模型顶层目录下添加TensorFlow Apache 2.0 License [TensorFlow License链接](https://github.com/tensorflow/tensorflow/blob/master/LICENSE) + + 2、迁移TensorFlow框架开发的模型,需要在模型目录下每个源文件附上源社区TensorFlow Apache 2.0 License头部声明,并在其下追加新增完整华为公司License声明 + + ``` + # Copyright 2017 The TensorFlow Authors. All Rights Reserved. + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + # ============================================================================ + # Copyright 2021 Huawei Technologies Co., Ltd + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ``` + 开发场景 + + 1、基于TensorFlow框架开发模型,需在模型项目顶层目录下添加TensorFlow Apache 2.0 License [TensorFlow License链接](https://github.com/tensorflow/tensorflow/blob/master/LICENSE) + + 2、基于TensorFlow框架开发模型,需要在模型目录下每个源文件附上源社区华为公司Apache 2.0 License头部声明 + ``` + # Copyright 2021 Huawei Technologies Co., Ltd + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ``` +* PyTorch + + 迁移场景 + + 1、迁移PyTorch模型中若源项目录已包含PyTorch License文件则必须拷贝引用,否则在模型顶层目录下添加PyTorch BSD-3 License [PyTorch License链接](https://github.com/pytorch/examples/blob/master/LICENSE) + + 2、迁移PyTorch第三方框架开发的模型,需要在模型目录下每个源文件附上源社区PyTorch BSD-3 License头部声明,并在其下追加新增一行华为公司License声明 + ``` + # BSD 3-Clause License + # + # Copyright (c) 2017 xxxx + # All rights reserved. + # Copyright 2021 Huawei Technologies Co., Ltd + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are met: + # + # * Redistributions of source code must retain the above copyright notice, this + # list of conditions and the following disclaimer. + # + # * Redistributions in binary form must reproduce the above copyright notice, + # this list of conditions and the following disclaimer in the documentation + # and/or other materials provided with the distribution. + # + # * Neither the name of the copyright holder nor the names of its + # contributors may be used to endorse or promote products derived from + # this software without specific prior written permission. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + # ============================================================================ + ``` + + 开发场景 + + 1、基于PyTorch框架开发模型,需在模型项目下添加PyTorch BSD-3 License [PyTorch License链接](https://github.com/pytorch/examples/blob/master/LICENSE) + + 2、基于PyTorch框架开发模型,需要在模型目录下每个源文件附上源社区华为公司Apache 2.0 License头部声明 + ``` + # Copyright 2021 Huawei Technologies Co., Ltd + # + # Licensed under the BSD 3-Clause License (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # https://opensource.org/licenses/BSD-3-Clause + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ``` + +* MindSpore/ACL + + 1、迁移或开发场景下MindSpore/ACL模型顶层目录下需要包含华为公司 License [华为公司 License链接](https://gitee.com/mindspore/mindspore/blob/master/LICENSE) + + 2、迁移或开发场景下MindSpore/ACL模型,需要在模型目录下每个源文件中添加区华为公司Apache 2.0 License头部声明 + ``` + # Copyright 2021 Huawei Technologies Co., Ltd + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + ``` + +> 关于License声明时间,应注意: 2021年新建的文件,应该是Copyright 2021 Huawei Technologies Co., Ltd 2020年创建年份,2020年修改年份,应该是Copyright 2020 Huawei Technologies Co., Ltd + + **三、readme** + +readme用于指导用户理解和部署样例,要包含如下内容: + +- 简介: + +1、模型的来源及原理; + +2、模型复现的步骤,含训练、eval、在线/离线推理等,入口请封装成`.sh`、`.py`; + +- 关键要求: + +1、模型的出处、对数据的要求、免责声明等,开源代码文件修改需要增加版权说明; + +2、模型转换得到的离线模型对输入数据的要求; + +3、环境变量设置,依赖的第三方软件包和库,以及安装方法; + +4、精度和性能达成要求:尽量达到原始模型水平; + +5、预训练checkpoint、结果checkpoint请提供归档OBS、网盘链接,如来自开源需明确来源地址 + +6、数据集说明 + +- [ ] 不允许直接提供数据集的下载链接,可使用词汇:用户自行准备好数据集,可选用“XXX”,“XXX”,“XXX” + + 例如:请用户自行准备好数据集,包含训练集和验证集两部分,可选用的数据集包括ImageNet2012,CIFAR10、Flower等,包含train和val两部分。 + +- [ ] 脚本中不允许提供链接下载数据集,如果开源脚本上存在对应的链接,请修改或者删除对应的脚本 + +训练ReadMe写作可参考下面两个链接: + +[Readme example1](https://gitee.com/ascend/modelzoo/blob/master/built-in/TensorFlow/Official/cv/image_classification/DenseNet121_ID0067_for_TensorFlow/README.md) + +[Readme example2](https://www.hiascend.com/zh/software/modelzoo/detail/C/093ed0219cb14f068af33784c62cf7ec) + +离线推理ReadMe写作可参考下面链接: + +[Readme example1](https://gitee.com/ascend/modelzoo/tree/master/contrib/ACL_TensorFlow/Research/cv/AdvancedEAST_ID0130_for_ACL/README.md) + + **四、自测试用例** + +提供模型的自测试用例和readme,提交PR需要门禁及模型测试用例通过,性能和精度检查通过 + +- 简介: + +1、不同于完整的训练过程和全量数据集的推理,自测试用例的目的是验证提交代码基本功能可用,执行时长控制在10min之内(推理或训练只需执行有限的图片或step); + +2、提交PR中训练用例入口`train_testcase.sh`, 在线推理用例入口`online_inference_testcase.sh`, 离线推理用例入口`offline_inference_testcase.sh`; + +3、提交PR后,会自动触发门禁流水,后台会根据用例入口shell,自动将代码分发到对应执行环境; + +4、Jenkins预置账号:登录账号请联系华为工程师/接口人获取,登录之后,可以查看到用例执行日志 + +5、如果提交失败,请查看日志,修复代码或其他问题后,在你当前的PR中,评论“compile”即可重新触发用例执行 + +- 关键要求: + +1、自测试用例命名严格按照上述简介2要求来书写,否则门禁会校验失败; + +2、用例应当包含功能、精度(Loss值)、性能检查,检查通过打印"Run testcase success!",失败则打印"Run testcase failed!"; + +3、执行环境已预装软件包和Python3.7.5环境,调用命令"python3"、"python3.7"、"python3.7.5"均可,安装第三方库依赖使用"pip3"、"pip3.7"均可; + +4、数据集和模型:小于500M的文件,建议使用`obsutil`命令下载(已预装),过大的文件,建议提交Issue,注明数据集和下载地址,会提前下载到执行环境上, + +已预置数据集&python第三方库: [Environments](https://gitee.com/ascend/modelzoo/blob/master/contrib/ENVIRONMENTS.md) + +5、环境和其他问题,请提交Issue跟踪; + +6、测试用例开发参考: +- [训练](https://gitee.com/ascend/modelzoo/tree/master/built-in/TensorFlow/Official/nlp/Transformer_for_TensorFlow) +- [离线推理](https://gitee.com/alexcheng88/modelzoo/tree/master/contrib/TensorFlow/Research/cv/efficientnet-b8/ATC_efficientnet-b8_tf_nkxiaolei) + + **五、PR提交** + +- 关键要求: + +1、请将modelzoo仓fork到个人分支,基于个人分支新增、修改和提交PR; + +2、PR标题:线上活动,请在标题注明[线上贡献];高校活动,请注明[xxx学校][高校贡献]; + +3、built-in用户根据网络状态必须配置modelzoo_level.txt文件,且文件内容包含三个关键字段:FuncStatus(OK-流程通过/ **NOK-流程失败,不允许模型代码提交主仓** );PerfStatus(OK-持平GPU/POK-0.5倍GPU/NOK-小于0.5倍GPU/PERFECT-1.2倍GPU);PrecisionStatus(OK-精度达标,POK-Loss拟合但精度未实施, **NOK-Loss不拟合,不允许模型代码提交主仓** );内容格式如下所示(注:“:”两侧无需空格,英文格式;): + +``` + FuncStatus:OK/NOK + PerfStatus:PERFECT/OK/POK/NOK + PrecisionStatus:OK/POK/NOK +``` +4、contrib用户根据网络状态必须配置modelzoo_level.txt文件,且文件内容包含关键字段:GPUStatus(OK-GPU复现/NOK-GPU未复现); NPUMigrationStatus(OK-自动迁移成功/POK-自动迁移失败, 手写规避成功/NOK-均失败); FuncStatus(OK-基础功能打通/NOK-基础功能失败,不允许模型代码提交到master); PrecisionStatus(OK-精度达标/POK-Loss拟合但精度未完全达标/NOK-精度不达标, 不允许模型代码提交到master); AutoTune(OK-性能持平或高于GPU/POK-性能有提升但低于GPU/NOK-性能无提升或者功能失败); PerfStatus(训练:PERFECT-性能1.2倍GPU/OK-性能持平GPU/POK-性能0.5倍GPU/NOK-性能小于0.5倍GPU;推理:OK-4*310单卡>GPU/NOK-其它); ModelConvert:OK/NOK(仅推理, OK-om转换成功/NOK-om转换失败); QuantStatus:OK/NOK(仅推理, OK-精度损失1%以内,性能有提升/POK-性能有提升但未达标/NOK-量化失败); + +样例:modelzoo_level.txt文件 + +-----仅限训练----- + + +``` +GPUStatus:OK/NOK +NPUMigrationStatus:OK/POK/NOK +``` + + +-----仅限推理----- + +``` +ModelConvert:OK/POK/NOK +QuantStatus:OK/POK/NOK +``` + +-----通用部分----- + +``` +FuncStatus:OK/NOK +PrecisionStatus:OK/POK/NOK +AutoTune:OK/POK/NOK +PerfStatus:PERFECT/OK/POK/NOK +``` +5、网络名称命名规范:*_for_框架,注:*代表任意内容,如网络名称或网络名称+网络ID; + + **六、编程规范** + +- 规范标准 + +1、C++代码遵循google编程规范:Google C++ Coding Guidelines;单元测测试遵循规范: Googletest Primer。 + +2、Python代码遵循PEP8规范:Python PEP 8 Coding Style;单元测试遵循规范: pytest + +- 规范备注 + +1、优先使用string类型,避免使用char*; + +2、禁止使用printf,一律使用cout; + +3、内存管理尽量使用智能指针; + +4、不准在函数里调用exit; + +5、禁止使用IDE等工具自动生成代码; + +6、控制第三方库依赖,如果引入第三方依赖,则需要提供第三方依赖安装和使用指导书; + +7、一律使用英文注释,注释率30%--40%,鼓励自注释; + +8、函数头必须有注释,说明函数作用,入参、出参; + +9、统一错误码,通过错误码可以确认那个分支返回错误; + +10、禁止出现打印一堆无影响的错误级别的日志; diff --git a/PyTorch/contrib/audio/FastPitch/fastpitch/loss_function.py b/PyTorch/contrib/audio/FastPitch/fastpitch/loss_function.py index 9baf4a6c31ccb0e0e038190d55ce38a93d4ad3ee..0fe133abd4fdf5d8397ab2bdebbd96a61e443959 100644 --- a/PyTorch/contrib/audio/FastPitch/fastpitch/loss_function.py +++ b/PyTorch/contrib/audio/FastPitch/fastpitch/loss_function.py @@ -1,108 +1,108 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import torch -import torch.nn.functional as F -from torch import nn - -from common.utils import mask_from_lens -from fastpitch.attn_loss_function import AttentionCTCLoss - - -class FastPitchLoss(nn.Module): - def __init__(self, dur_predictor_loss_scale=1.0, - pitch_predictor_loss_scale=1.0, attn_loss_scale=1.0, - energy_predictor_loss_scale=0.1): - super(FastPitchLoss, self).__init__() - self.dur_predictor_loss_scale = dur_predictor_loss_scale - self.pitch_predictor_loss_scale = pitch_predictor_loss_scale - self.energy_predictor_loss_scale = energy_predictor_loss_scale - self.attn_loss_scale = attn_loss_scale - self.attn_ctc_loss = AttentionCTCLoss() - - def forward(self, model_out, targets, is_training=True, meta_agg='mean'): - (mel_out, dec_mask, dur_pred, log_dur_pred, pitch_pred, pitch_tgt, - energy_pred, energy_tgt, attn_soft, attn_hard, attn_dur, - attn_logprob) = model_out - - (mel_tgt, in_lens, out_lens) = targets - - dur_tgt = attn_dur - dur_lens = in_lens - - mel_tgt.requires_grad = False - # (B,H,T) => (B,T,H) - mel_tgt = mel_tgt.transpose(1, 2) - - dur_mask = mask_from_lens(dur_lens, max_len=dur_tgt.size(1)) - dur_mask_sum = dur_mask.sum() - - log_dur_tgt = torch.log(dur_tgt.float() + 1) - loss_fn = F.mse_loss - dur_pred_loss = loss_fn(log_dur_pred, log_dur_tgt, reduction='none') - dur_pred_loss = (dur_pred_loss * dur_mask).sum() / dur_mask_sum - - ldiff = mel_tgt.size(1) - mel_out.size(1) - mel_out = F.pad(mel_out, (0, 0, 0, ldiff, 0, 0), value=0.0) - - mel_mask = mel_tgt.ne(0).float() - mel_mask_sum = mel_mask.sum() - - loss_fn = F.mse_loss - mel_loss = loss_fn(mel_out, mel_tgt, reduction='none') - mel_loss = (mel_loss * mel_mask).sum() / mel_mask_sum - - ldiff = pitch_tgt.size(2) - pitch_pred.size(2) - pitch_pred = F.pad(pitch_pred, (0, ldiff, 0, 0, 0, 0), value=0.0) - pitch_loss = F.mse_loss(pitch_tgt, pitch_pred, reduction='none') - pitch_loss = (pitch_loss * dur_mask.unsqueeze(1)).sum() / dur_mask_sum - - if energy_pred is not None: - energy_pred = F.pad(energy_pred, (0, ldiff, 0, 0), value=0.0) - energy_loss = F.mse_loss(energy_tgt, energy_pred, reduction='none') - energy_loss = (energy_loss * dur_mask).sum() / dur_mask_sum - else: - energy_loss = 0 - - # Attention loss - attn_loss = self.attn_ctc_loss(attn_logprob, in_lens, out_lens) - - loss = (mel_loss - + dur_pred_loss * self.dur_predictor_loss_scale - + pitch_loss * self.pitch_predictor_loss_scale - + energy_loss * self.energy_predictor_loss_scale - + attn_loss * self.attn_loss_scale) - - meta = { - 'loss': loss.clone().detach(), - 'mel_loss': mel_loss.clone().detach(), - 'duration_predictor_loss': dur_pred_loss.clone().detach(), - 'pitch_loss': pitch_loss.clone().detach(), - 'energy_loss': energy_loss.clone().detach(), - 'attn_loss': attn_loss.clone().detach(), - 'dur_mask_sum': dur_mask_sum.clone().detach(), - 'mel_mask_sum': mel_mask_sum.clone().detach(), - 'dur_error': (torch.abs(dur_pred - dur_tgt).sum() - / dur_mask_sum).detach(), - } - - if energy_pred is not None: - meta['energy_loss'] = energy_loss.clone().detach() - - assert meta_agg in ('sum', 'mean') - if meta_agg == 'sum': - bsz = mel_out.size(0) - meta = {k: v * bsz for k, v in meta.items()} - return loss, meta +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import torch +import torch.nn.functional as F +from torch import nn + +from common.utils import mask_from_lens +from fastpitch.attn_loss_function import AttentionCTCLoss + + +class FastPitchLoss(nn.Module): + def __init__(self, dur_predictor_loss_scale=1.0, + pitch_predictor_loss_scale=1.0, attn_loss_scale=1.0, + energy_predictor_loss_scale=0.1): + super(FastPitchLoss, self).__init__() + self.dur_predictor_loss_scale = dur_predictor_loss_scale + self.pitch_predictor_loss_scale = pitch_predictor_loss_scale + self.energy_predictor_loss_scale = energy_predictor_loss_scale + self.attn_loss_scale = attn_loss_scale + self.attn_ctc_loss = AttentionCTCLoss() + + def forward(self, model_out, targets, is_training=True, meta_agg='mean'): + (mel_out, dec_mask, dur_pred, log_dur_pred, pitch_pred, pitch_tgt, + energy_pred, energy_tgt, attn_soft, attn_hard, attn_dur, + attn_logprob) = model_out + + (mel_tgt, in_lens, out_lens) = targets + + dur_tgt = attn_dur + dur_lens = in_lens + + mel_tgt.requires_grad = False + # (B,H,T) => (B,T,H) + mel_tgt = mel_tgt.transpose(1, 2) + + dur_mask = mask_from_lens(dur_lens, max_len=dur_tgt.size(1)) + dur_mask_sum = dur_mask.sum() + + log_dur_tgt = torch.log(dur_tgt.float() + 1) + loss_fn = F.mse_loss + dur_pred_loss = loss_fn(log_dur_pred, log_dur_tgt, reduction='none') + dur_pred_loss = (dur_pred_loss * dur_mask).sum() / dur_mask_sum + + ldiff = mel_tgt.size(1) - mel_out.size(1) + mel_out = F.pad(mel_out, (0, 0, 0, ldiff, 0, 0), value=0.0) + + mel_mask = mel_tgt.ne(0).float() + mel_mask_sum = mel_mask.sum() + + loss_fn = F.mse_loss + mel_loss = loss_fn(mel_out, mel_tgt, reduction='none') + mel_loss = (mel_loss * mel_mask).sum() / mel_mask_sum + + ldiff = pitch_tgt.size(2) - pitch_pred.size(2) + pitch_pred = F.pad(pitch_pred, (0, ldiff, 0, 0, 0, 0), value=0.0) + pitch_loss = F.mse_loss(pitch_tgt, pitch_pred, reduction='none') + pitch_loss = (pitch_loss * dur_mask.unsqueeze(1)).sum() / dur_mask_sum + + if energy_pred is not None: + energy_pred = F.pad(energy_pred, (0, ldiff, 0, 0), value=0.0) + energy_loss = F.mse_loss(energy_tgt, energy_pred, reduction='none') + energy_loss = (energy_loss * dur_mask).sum() / dur_mask_sum + else: + energy_loss = 0 + + # Attention loss + attn_loss = self.attn_ctc_loss(attn_logprob, in_lens, out_lens) + + loss = (mel_loss + + dur_pred_loss * self.dur_predictor_loss_scale + + pitch_loss * self.pitch_predictor_loss_scale + + energy_loss * self.energy_predictor_loss_scale + + attn_loss * self.attn_loss_scale) + + meta = { + 'loss': loss.clone().detach(), + 'mel_loss': mel_loss.clone().detach(), + 'duration_predictor_loss': dur_pred_loss.clone().detach(), + 'pitch_loss': pitch_loss.clone().detach(), + 'energy_loss': energy_loss.clone().detach(), + 'attn_loss': attn_loss.clone().detach(), + 'dur_mask_sum': dur_mask_sum.clone().detach(), + 'mel_mask_sum': mel_mask_sum.clone().detach(), + 'dur_error': (torch.abs(dur_pred - dur_tgt).sum() + / dur_mask_sum).detach(), + } + + if energy_pred is not None: + meta['energy_loss'] = energy_loss.clone().detach() + + assert meta_agg in ('sum', 'mean') + if meta_agg == 'sum': + bsz = mel_out.size(0) + meta = {k: v * bsz for k, v in meta.items()} + return loss, meta diff --git a/PyTorch/contrib/audio/baseline-rawnet/README.md b/PyTorch/contrib/audio/baseline-rawnet/README.md index ecd0232b7e518572e6567b012f2bc8e5778090fd..91569eb766f104a7839db4961633291f8cac3b51 100644 --- a/PyTorch/contrib/audio/baseline-rawnet/README.md +++ b/PyTorch/contrib/audio/baseline-rawnet/README.md @@ -1,128 +1,128 @@ -# RawNet2 - -This implements training of RawNet2 on the VoxCeleb1&2 datasets of YouTube. - -- Reference implementation: - -``` -url=https://github.com/Jungjee/RawNet -dir=RawNet-master/python/RawNet2 -``` - -## Baseline-RawNet2 Detail - -As of the current date, Ascend-Pytorch is still inefficient for contiguous operations. Therefore, RawNet2 is re-implemented using semantics such as custom OP. - -## Requirements - -- Install PyTorch ([pytorch.org](http://pytorch.org)) -- `pip install -r requirements.txt` - -## DataSet - -``` -url: http://www.robots.ox.ac.uk/~vgg/data/voxceleb/ -``` - -- The training datasets are VoxCeleb2, the evaluation dataset is VoxCeleb1H & VoxCeleb1E. The datasets are large. Please ensure sufficient hard disk space when downloading and decompressing. -- Besides, the data in the VoxCeleb2 downloaded from the url above is in the format of .m4a. If you do not use the dataset which is converted already, you should firstly run the `m4a2wav.py`. -- You need to follow directory structure of the `data` as below. If you connect to the prepared data folder, you don't need to build the following directory. - -``` -${RawNet}/DB/VoxCeleb1/ -├── dev_wav -│   ├── id10001 -│   │   ├── 1zcIwhmdeo4 -│   │   │   ├── 00001.wav -│   │   │   ├── 00002.wav -│   │   │   └── 00003.wav -│   │   ├── 5ssVY9a5X-M -│   │   │   ├── 00001.wav -│   │   │   ├── 00002.wav -│   │   │   ├── 00003.wav -│   │   │   └── 00003.wav -│   └── ... -├── eval_wav -│   ├── id10270 -│   │   ├── 5r0dWxy17C8 -│   │   │   ├── 00001.wav -│   │   │   ├── 00002.wav -│   │   │   ├── 00003.wav -│   │   │   ├── 00004.wav -│   │   │   └── 00005.wav -│   └── ... -│   ├── _z_BR0ERa9g -│   ├── 00001.wav -│   ├── 00002.wav -│   └── 00003.wav -├── val_trial.txt -└── veri_test.txt - -${RawNet}/DB/VoxCeleb2/ -└── wav - ├── id00012 - │   ├── 21Uxsk56VDQ - │   │   ├── 00001.wav - │   │   ├── ... - │   │   └── 00059.wav - │   ├── 00-qODbtozw - │   │   ├── ... - │   │   ├── 00079.wav - │   │   └── 00080.wav - ├── ... - │   └── zw-4DTjqIA0 - │   ├── 00108.wav - │   └── 00109.wav - └── id09272 - └── u7VNkYraCw0 - ├── ... - └── 00027.wav -``` - -- You need to follow directory structure of the `output` as below. - -``` -${RawNet}/train/train_${device_count}P -|-- DNNS/${name}/ -| |-- models -| | |--best_opt_eval.pt ## The best perfomance model is saved here -| | |--TA_${epoch}_${eer}.pt ##The other model is saved here -| |-- results -| |-- log -| | |-- eval_epoch${epoch}.txt ## The training log is saved here -| |-- prof -| |-- eers.txt ##The eers is saved here -| |-- f_params.txt ##The params of the model are saved here -``` - -## Training # - -- Note that the `output` folder under the `test` directory will also save the code running log. -- To run the model, you should cd to the directory of test -- To train a model, run `train_1p.py` or `train_8p.py`: - -```bash -# 1p train perf -nohup bash train_performance_1p.sh --data_path=xxx & - -# 8p train perf -nohup bash train_performance_8p.sh --data_path=xxx & - -# 1p train full -nohup bash train_full_1p.sh --data_path=xxx & - -# 8p train full -nohup bash train_full_8p.sh --data_path=xxx & - -``` - -## RawNet2 training result - -| eer(percentage) | FPS(aver) | Npu_nums | Epochs | AMP_Type | -| :-------------------------: | :-------: | :------: | :----: | :------: | -| 0.14 | 7760 | 1 | 1 | O2 | -| 0.038(aver) and 0.035(high) | 8573 | 8 | 20 | O2 | - -### **Testing** - -The testing data in the paper is about the VoxCeleb1H and VoxCeleb1E. And here we use the dataset of the VoxCeleb1H, and the target of the eer in the paper is 0.0489. +# RawNet2 + +This implements training of RawNet2 on the VoxCeleb1&2 datasets of YouTube. + +- Reference implementation: + +``` +url=https://github.com/Jungjee/RawNet +dir=RawNet-master/python/RawNet2 +``` + +## Baseline-RawNet2 Detail + +As of the current date, Ascend-Pytorch is still inefficient for contiguous operations. Therefore, RawNet2 is re-implemented using semantics such as custom OP. + +## Requirements + +- Install PyTorch ([pytorch.org](http://pytorch.org)) +- `pip install -r requirements.txt` + +## DataSet + +``` +url: http://www.robots.ox.ac.uk/~vgg/data/voxceleb/ +``` + +- The training datasets are VoxCeleb2, the evaluation dataset is VoxCeleb1H & VoxCeleb1E. The datasets are large. Please ensure sufficient hard disk space when downloading and decompressing. +- Besides, the data in the VoxCeleb2 downloaded from the url above is in the format of .m4a. If you do not use the dataset which is converted already, you should firstly run the `m4a2wav.py`. +- You need to follow directory structure of the `data` as below. If you connect to the prepared data folder, you don't need to build the following directory. + +``` +${RawNet}/DB/VoxCeleb1/ +├── dev_wav +│   ├── id10001 +│   │   ├── 1zcIwhmdeo4 +│   │   │   ├── 00001.wav +│   │   │   ├── 00002.wav +│   │   │   └── 00003.wav +│   │   ├── 5ssVY9a5X-M +│   │   │   ├── 00001.wav +│   │   │   ├── 00002.wav +│   │   │   ├── 00003.wav +│   │   │   └── 00003.wav +│   └── ... +├── eval_wav +│   ├── id10270 +│   │   ├── 5r0dWxy17C8 +│   │   │   ├── 00001.wav +│   │   │   ├── 00002.wav +│   │   │   ├── 00003.wav +│   │   │   ├── 00004.wav +│   │   │   └── 00005.wav +│   └── ... +│   ├── _z_BR0ERa9g +│   ├── 00001.wav +│   ├── 00002.wav +│   └── 00003.wav +├── val_trial.txt +└── veri_test.txt + +${RawNet}/DB/VoxCeleb2/ +└── wav + ├── id00012 + │   ├── 21Uxsk56VDQ + │   │   ├── 00001.wav + │   │   ├── ... + │   │   └── 00059.wav + │   ├── 00-qODbtozw + │   │   ├── ... + │   │   ├── 00079.wav + │   │   └── 00080.wav + ├── ... + │   └── zw-4DTjqIA0 + │   ├── 00108.wav + │   └── 00109.wav + └── id09272 + └── u7VNkYraCw0 + ├── ... + └── 00027.wav +``` + +- You need to follow directory structure of the `output` as below. + +``` +${RawNet}/train/train_${device_count}P +|-- DNNS/${name}/ +| |-- models +| | |--best_opt_eval.pt ## The best perfomance model is saved here +| | |--TA_${epoch}_${eer}.pt ##The other model is saved here +| |-- results +| |-- log +| | |-- eval_epoch${epoch}.txt ## The training log is saved here +| |-- prof +| |-- eers.txt ##The eers is saved here +| |-- f_params.txt ##The params of the model are saved here +``` + +## Training # + +- Note that the `output` folder under the `test` directory will also save the code running log. +- To run the model, you should cd to the directory of test +- To train a model, run `train_1p.py` or `train_8p.py`: + +```bash +# 1p train perf +nohup bash train_performance_1p.sh --data_path=xxx & + +# 8p train perf +nohup bash train_performance_8p.sh --data_path=xxx & + +# 1p train full +nohup bash train_full_1p.sh --data_path=xxx & + +# 8p train full +nohup bash train_full_8p.sh --data_path=xxx & + +``` + +## RawNet2 training result + +| eer(percentage) | FPS(aver) | Npu_nums | Epochs | AMP_Type | +| :-------------------------: | :-------: | :------: | :----: | :------: | +| 0.14 | 7760 | 1 | 1 | O2 | +| 0.038(aver) and 0.035(high) | 8573 | 8 | 20 | O2 | + +### **Testing** + +The testing data in the paper is about the VoxCeleb1H and VoxCeleb1E. And here we use the dataset of the VoxCeleb1H, and the target of the eer in the paper is 0.0489. diff --git a/PyTorch/contrib/audio/baseline-rawnet/modelzoo_level.txt b/PyTorch/contrib/audio/baseline-rawnet/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/audio/baseline-rawnet/modelzoo_level.txt +++ b/PyTorch/contrib/audio/baseline-rawnet/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/audio/baseline-rawnet/requirements.txt b/PyTorch/contrib/audio/baseline-rawnet/requirements.txt index 3e7d7460a222239c1e0a3accc0acb113793ba8bd..45427a860f53981a780ff5bc1af4feba7dc7f74c 100644 --- a/PyTorch/contrib/audio/baseline-rawnet/requirements.txt +++ b/PyTorch/contrib/audio/baseline-rawnet/requirements.txt @@ -1,9 +1,9 @@ -torch==1.5.0+ascend.post3 -apex==0.1+ascend.20210930 -torchvision==0.2.2.post3 -numpy==1.21.2 -Pillow==8.3.2 -scikit-learn==1.0 -scipy==1.7.1 -tqdm==4.62.3 +torch==1.5.0+ascend.post3 +apex==0.1+ascend.20210930 +torchvision==0.2.2.post3 +numpy==1.21.2 +Pillow==8.3.2 +scikit-learn==1.0 +scipy==1.7.1 +tqdm==4.62.3 SoundFile==0.10.3.post1 \ No newline at end of file diff --git a/PyTorch/contrib/audio/deepspeech/README.md b/PyTorch/contrib/audio/deepspeech/README.md index 8e331e892399f9ba6d369b44e01f09e5aa783881..dce744d6576242af34015739c9fa5d4b816a1d1b 100644 --- a/PyTorch/contrib/audio/deepspeech/README.md +++ b/PyTorch/contrib/audio/deepspeech/README.md @@ -1,89 +1,89 @@ - - -# deepspeech.pytorch - -This implements training of deepspeech on NPU mainly modified from [deepspeech.pytorch](https://github.com/SeanNaren/deepspeech.pytorch) - -## installation - -### From Source - -install this fork Warp-CTC bindings: - -```shell -### npu环境变量 -source {deepspeech_root}/scripts/env_new.sh -git clone https://github.com/SeanNaren/warp-ctc.git -cd warp-ctc -git checkout -b pytorch_bindings origin/pytorch_bindings -mkdir build; cd build; cmake ..; make -cd ../pytorch_binding && python3.7 setup.py install -``` - -install requirements - -```shell -pip3 install -r requirements.txt -``` - -If you plan to use Multi-GPU/Multi-node training, you'll need etcd. Below is the command to install on Ubuntu. - -```shell -sudo apt-get install etcd -sudo apt-get install sox -``` - -## Training - -### Download Dataset - -All you need is entering the data directory and execute the follow scripts - -```shell -cd data -python3.7 an4.py -``` - -### Training a Model - -#### 1p training - -```shell -# The result will be placed in the current directory 1p_train.log -bash run_1p.sh -``` - -#### 8p training - -```shell -# The result will be placed in the current directory 8p_train.log -bash run_8p.sh -``` - -### Performance - -```shell -### 1p performance, the log will be placed in the current directory 1p_train_performance.log -bash train_performance_1p.sh -### 8p performance, the log will be placed in the current directory 8p_train_performance.log -bash train_performance_8p.sh -``` - -## Testing/Inference - -To evaluate a trained model on a test set (has to be in the same format as the training set): - -```shell -# if you want to see the final precision, you can execute the follow scripts after execute 1p or 8p training scripts -bash eval.sh -``` - -## Result - -| | WER | CER | Epochs | APEX | FPS | -| :---: | :----: | :----: | :----: | :--: | :--: | -| NPU1P | 9.444 | 5.723 | 70 | O2 | 4 | -| NPU8P | 17.464 | 10.926 | 70 | O2 | 22 | -| GPU1P | 10.349 | 7.076 | 70 | O2 | 94 | -| GPU8P | 15.265 | 9.834 | 70 | O2 | 377 | - + + +# deepspeech.pytorch + +This implements training of deepspeech on NPU mainly modified from [deepspeech.pytorch](https://github.com/SeanNaren/deepspeech.pytorch) + +## installation + +### From Source + +install this fork Warp-CTC bindings: + +```shell +### npu环境变量 +source {deepspeech_root}/scripts/env_new.sh +git clone https://github.com/SeanNaren/warp-ctc.git +cd warp-ctc +git checkout -b pytorch_bindings origin/pytorch_bindings +mkdir build; cd build; cmake ..; make +cd ../pytorch_binding && python3.7 setup.py install +``` + +install requirements + +```shell +pip3 install -r requirements.txt +``` + +If you plan to use Multi-GPU/Multi-node training, you'll need etcd. Below is the command to install on Ubuntu. + +```shell +sudo apt-get install etcd +sudo apt-get install sox +``` + +## Training + +### Download Dataset + +All you need is entering the data directory and execute the follow scripts + +```shell +cd data +python3.7 an4.py +``` + +### Training a Model + +#### 1p training + +```shell +# The result will be placed in the current directory 1p_train.log +bash run_1p.sh +``` + +#### 8p training + +```shell +# The result will be placed in the current directory 8p_train.log +bash run_8p.sh +``` + +### Performance + +```shell +### 1p performance, the log will be placed in the current directory 1p_train_performance.log +bash train_performance_1p.sh +### 8p performance, the log will be placed in the current directory 8p_train_performance.log +bash train_performance_8p.sh +``` + +## Testing/Inference + +To evaluate a trained model on a test set (has to be in the same format as the training set): + +```shell +# if you want to see the final precision, you can execute the follow scripts after execute 1p or 8p training scripts +bash eval.sh +``` + +## Result + +| | WER | CER | Epochs | APEX | FPS | +| :---: | :----: | :----: | :----: | :--: | :--: | +| NPU1P | 9.444 | 5.723 | 70 | O2 | 4 | +| NPU8P | 17.464 | 10.926 | 70 | O2 | 22 | +| GPU1P | 10.349 | 7.076 | 70 | O2 | 94 | +| GPU8P | 15.265 | 9.834 | 70 | O2 | 377 | + diff --git a/PyTorch/contrib/audio/tdnn/README.md b/PyTorch/contrib/audio/tdnn/README.md index 83fd02c3f2e6e43b28570ec3119decc7a80dda87..3598158ca6fb2f059af7dd9ff1b56977ed3f5840 100644 --- a/PyTorch/contrib/audio/tdnn/README.md +++ b/PyTorch/contrib/audio/tdnn/README.md @@ -1,144 +1,144 @@ - - -## 概述 - -ECAPA-TDNN基于传统TDNN模型进行了改进,主要有三个方面的优化,分别是:增加了一维SE残差模块(1-Dimensional Squeeze-Excitation Res2Block);多层特征融合(Multi-layer feature aggregation and summation);通道和上下文相关的统计池化(Channel- and context-dependent statistics pooling) - - - -- 参考实现: -[https://github.com/speechbrain/speechbrain/tree/develop/templates/speaker_id](https://gitee.com/link?target=https%3A%2F%2Fgithub.com%2Fspeechbrain%2Fspeechbrain%2Ftree%2Fdevelop%2Ftemplates%2Fspeaker_id) - - - - - -## 支持特性 - -| 特性列表 | 是否支持 | -| ---------- | -------- | -| 分布式训练 | 是 | -| 混合精度 | 是 | -| 并行数据 | 是 | - -## 混合精度训练 - -昇腾910 AI处理器提供自动混合精度功能,模型使用 opt_level="O1", loss_scale=128, combine_grad=True的配置进行amp.initialize - -脚本已默认开启混合精度,设置如下。 - - ``` - parser.add_argument( - "--auto_mix_prec", - action="store_true", - help="This flag enables training with automatic mixed-precision.", - ) - ``` - - -

训练环境准备

- -CANN版本:5.0.2 - -昇腾torch版本:1.5.0 - -#### speechbrain环境配置 - -(详情请参考speechbrain官方文档安装方法。) - -1. 安装torch 1.5.0 - -2. 安装torchaudio,npu安装方法请参考 - - https://e.gitee.com/HUAWEI-ASCEND/dashboard?issue=I48AZM - -3. cd tdnn - - pip install -r requirement.txt - - pip install --editable . - - -

快速上手

- -- 数据集准备 - -模型训练使用rirs_noises、train-clean-5数据集,数据集请用户自行获取。 - -- 模型训练 - -选择合适的下载方式下载源码包。 - -Before training, modify the data_folder in these scripts. - -```bash -# training 1p loss -bash ./test/train_full_1p.sh --data_folder="" - -# training 1p performance -bash ./test/train_performance_1p.sh --data_folder="" - -# training 8p loss -bash ./test/train_full_8p.sh --data_folder="" - -# training 8p performance -bash ./test/train_performance_8p.sh --data_folder="" -``` - -``` -Log path: - test/output/train_full_1p.log # 1p training result log - test/output/train_performance_1p.log # 1p training performance result log - test/output/train_full_8p.log # 8p training result log - test/output/train_performance_8p.log # 8p training performance result log -``` - -## 训练结果 - -| acc | FPS | Npu_nums | Epochs | AMP_Type | -| :--------: | :----: | :------: | :----: | :------: | -| - | 8.25 | 1 | 1 | O1 | -| 0.9062 | 43.863 | 8 | 5 | O1 | - -

高级参考

- -### 脚本和示例代码 - -``` -├── README.md //代码说明文档 -├── speechbrain //框架支持文件 -├── templates/speaker_id -│ ├──test //测试脚本 -│ ├──custom_model.py //简易TDNN模块 -| ├──mini_librispeech_prepare.py //数据清单文件 -│ ├──run_1p.sh //单卡运行启动脚本 -│ ├──run_8p.sh //8卡运行启动脚本 -│ ├──train.py //网络训练与测试代码 -│ ├──train.yaml //网络训练参数脚本 -``` - -### 脚本参数 - -``` ---seed 制作参数对象seed ---rank_size 使用NPU卡数量,默认:1 ---number_of_epochs 训练epoch次数,默认:5 ---data_folder 数据集路径,默认:./data ---output_folder 结果输出保存的文件路径,默认:./results/speaker_id/ ---batch_size 每个NPU的batch size,默认:64 -``` - - -## 训练过程 - -1. 通过“模型训练”中的训练指令启动单卡或者多卡训练。单卡和多卡通过运行不同脚本,支持单卡、8卡网络训练。 - -2. 参考脚本的模型存储路径为results//save,训练脚本log中包括如下信息。 - -``` -Epoch: 1, lr: 1.00e-03 - train loss: 2.70 - valid loss: 3.39, valid error: 9.47e-01 -Epoch loaded: 1 - test loss: 3.43, test error: 9.54e-01 -``` -## 注意事项 - + + +## 概述 + +ECAPA-TDNN基于传统TDNN模型进行了改进,主要有三个方面的优化,分别是:增加了一维SE残差模块(1-Dimensional Squeeze-Excitation Res2Block);多层特征融合(Multi-layer feature aggregation and summation);通道和上下文相关的统计池化(Channel- and context-dependent statistics pooling) + + + +- 参考实现: +[https://github.com/speechbrain/speechbrain/tree/develop/templates/speaker_id](https://gitee.com/link?target=https%3A%2F%2Fgithub.com%2Fspeechbrain%2Fspeechbrain%2Ftree%2Fdevelop%2Ftemplates%2Fspeaker_id) + + + + + +## 支持特性 + +| 特性列表 | 是否支持 | +| ---------- | -------- | +| 分布式训练 | 是 | +| 混合精度 | 是 | +| 并行数据 | 是 | + +## 混合精度训练 + +昇腾910 AI处理器提供自动混合精度功能,模型使用 opt_level="O1", loss_scale=128, combine_grad=True的配置进行amp.initialize + +脚本已默认开启混合精度,设置如下。 + + ``` + parser.add_argument( + "--auto_mix_prec", + action="store_true", + help="This flag enables training with automatic mixed-precision.", + ) + ``` + + +

训练环境准备

+ +CANN版本:5.0.2 + +昇腾torch版本:1.5.0 + +#### speechbrain环境配置 + +(详情请参考speechbrain官方文档安装方法。) + +1. 安装torch 1.5.0 + +2. 安装torchaudio,npu安装方法请参考 + + https://e.gitee.com/HUAWEI-ASCEND/dashboard?issue=I48AZM + +3. cd tdnn + + pip install -r requirement.txt + + pip install --editable . + + +

快速上手

+ +- 数据集准备 + +模型训练使用rirs_noises、train-clean-5数据集,数据集请用户自行获取。 + +- 模型训练 + +选择合适的下载方式下载源码包。 + +Before training, modify the data_folder in these scripts. + +```bash +# training 1p loss +bash ./test/train_full_1p.sh --data_folder="" + +# training 1p performance +bash ./test/train_performance_1p.sh --data_folder="" + +# training 8p loss +bash ./test/train_full_8p.sh --data_folder="" + +# training 8p performance +bash ./test/train_performance_8p.sh --data_folder="" +``` + +``` +Log path: + test/output/train_full_1p.log # 1p training result log + test/output/train_performance_1p.log # 1p training performance result log + test/output/train_full_8p.log # 8p training result log + test/output/train_performance_8p.log # 8p training performance result log +``` + +## 训练结果 + +| acc | FPS | Npu_nums | Epochs | AMP_Type | +| :--------: | :----: | :------: | :----: | :------: | +| - | 8.25 | 1 | 1 | O1 | +| 0.9062 | 43.863 | 8 | 5 | O1 | + +

高级参考

+ +### 脚本和示例代码 + +``` +├── README.md //代码说明文档 +├── speechbrain //框架支持文件 +├── templates/speaker_id +│ ├──test //测试脚本 +│ ├──custom_model.py //简易TDNN模块 +| ├──mini_librispeech_prepare.py //数据清单文件 +│ ├──run_1p.sh //单卡运行启动脚本 +│ ├──run_8p.sh //8卡运行启动脚本 +│ ├──train.py //网络训练与测试代码 +│ ├──train.yaml //网络训练参数脚本 +``` + +### 脚本参数 + +``` +--seed 制作参数对象seed +--rank_size 使用NPU卡数量,默认:1 +--number_of_epochs 训练epoch次数,默认:5 +--data_folder 数据集路径,默认:./data +--output_folder 结果输出保存的文件路径,默认:./results/speaker_id/ +--batch_size 每个NPU的batch size,默认:64 +``` + + +## 训练过程 + +1. 通过“模型训练”中的训练指令启动单卡或者多卡训练。单卡和多卡通过运行不同脚本,支持单卡、8卡网络训练。 + +2. 参考脚本的模型存储路径为results//save,训练脚本log中包括如下信息。 + +``` +Epoch: 1, lr: 1.00e-03 - train loss: 2.70 - valid loss: 3.39, valid error: 9.47e-01 +Epoch loaded: 1 - test loss: 3.43, test error: 9.54e-01 +``` +## 注意事项 + **该模型为了固定shape,修改了1、/speechbrain/dataio/dataio.py read_audio函数 2、/speechbrain/templates/speaker_id/train.py prepare_features函数 3、/speechbrain/core.py _train_loader_specifics里的sampler。其中第三个修改是因为数据集不足固定shape,实际使用模型务必还原回去。** \ No newline at end of file diff --git a/PyTorch/contrib/audio/tdnn/modelzoo_level.txt b/PyTorch/contrib/audio/tdnn/modelzoo_level.txt index 484664c2399ae4109859a67aba6cb9facff03cf1..55a9add9fa74832ca908108d73946cd76281a9cd 100644 --- a/PyTorch/contrib/audio/tdnn/modelzoo_level.txt +++ b/PyTorch/contrib/audio/tdnn/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/audio/tdnn/speechbrain/lobes/models/MetricGAN.py b/PyTorch/contrib/audio/tdnn/speechbrain/lobes/models/MetricGAN.py index a7af8cccaabe473c6865e80a952067e7d38062ee..38c2b82d53f54c4df7ab251d5544b9870646a1a7 100644 --- a/PyTorch/contrib/audio/tdnn/speechbrain/lobes/models/MetricGAN.py +++ b/PyTorch/contrib/audio/tdnn/speechbrain/lobes/models/MetricGAN.py @@ -13,175 +13,175 @@ # limitations under the License. # -"""Generator and discriminator used in MetricGAN - -Authors: -* Szu-Wei Fu 2020 -""" -import torch -import speechbrain as sb -from torch import nn -from torch.nn.utils import spectral_norm - - -def xavier_init_layer( - in_size, out_size=None, spec_norm=True, layer_type=nn.Linear, **kwargs -): - "Create a layer with spectral norm, xavier uniform init and zero bias" - if out_size is None: - out_size = in_size - - layer = layer_type(in_size, out_size, **kwargs) - if spec_norm: - layer = spectral_norm(layer) - - # Perform initialization - nn.init.xavier_uniform_(layer.weight, gain=1.0) - nn.init.zeros_(layer.bias) - - return layer - - -def shifted_sigmoid(x): - return 1.2 / (1 + torch.exp(-(1 / 1.6) * x)) - - -class Learnable_sigmoid(nn.Module): - def __init__(self, in_features=257): - super().__init__() - self.slope = nn.Parameter(torch.ones(in_features)) - self.slope.requiresGrad = True # set requiresGrad to true! - - # self.scale = nn.Parameter(torch.ones(1)) - # self.scale.requiresGrad = True # set requiresGrad to true! - - def forward(self, x): - return 1.2 / (1 + torch.exp(-(self.slope) * x)) - - -class EnhancementGenerator(nn.Module): - """Simple LSTM for enhancement with custom initialization. - - Arguments - --------- - input_size : int - Size of the input tensor's last dimension. - hidden_size : int - Number of neurons to use in the LSTM layers. - num_layers : int - Number of layers to use in the LSTM. - dropout : int - Fraction of neurons to drop during training. - """ - - def __init__( - self, input_size=257, hidden_size=200, num_layers=2, dropout=0, - ): - super().__init__() - self.activation = nn.LeakyReLU(negative_slope=0.3) - - self.blstm = sb.nnet.RNN.LSTM( - input_size=input_size, - hidden_size=hidden_size, - num_layers=num_layers, - dropout=dropout, - bidirectional=True, - ) - """ - Use orthogonal init for recurrent layers, xavier uniform for input layers - Bias is 0 - """ - for name, param in self.blstm.named_parameters(): - if "bias" in name: - nn.init.zeros_(param) - elif "weight_ih" in name: - nn.init.xavier_uniform_(param) - elif "weight_hh" in name: - nn.init.orthogonal_(param) - - self.linear1 = xavier_init_layer(400, 300, spec_norm=False) - self.linear2 = xavier_init_layer(300, 257, spec_norm=False) - - self.Learnable_sigmoid = Learnable_sigmoid() - self.sigmoid = nn.Sigmoid() - - def forward(self, x, lengths): - out, _ = self.blstm(x, lengths=lengths) - - out = self.linear1(out) - out = self.activation(out) - - out = self.linear2(out) - out = self.Learnable_sigmoid(out) - - return out - - -class MetricDiscriminator(nn.Module): - """Metric estimator for enhancement training. - - Consists of: - * four 2d conv layers - * channel averaging - * three linear layers - - Arguments - --------- - kernel_size : tuple - The dimensions of the 2-d kernel used for convolution. - base_channels : int - Number of channels used in each conv layer. - """ - - def __init__( - self, kernel_size=(5, 5), base_channels=15, activation=nn.LeakyReLU, - ): - super().__init__() - - self.activation = activation(negative_slope=0.3) - - self.BN = nn.BatchNorm2d(num_features=2, momentum=0.01) - - self.conv1 = xavier_init_layer( - 2, base_channels, layer_type=nn.Conv2d, kernel_size=kernel_size - ) - self.conv2 = xavier_init_layer( - base_channels, layer_type=nn.Conv2d, kernel_size=kernel_size - ) - self.conv3 = xavier_init_layer( - base_channels, layer_type=nn.Conv2d, kernel_size=kernel_size - ) - self.conv4 = xavier_init_layer( - base_channels, layer_type=nn.Conv2d, kernel_size=kernel_size - ) - - self.Linear1 = xavier_init_layer(base_channels, out_size=50) - self.Linear2 = xavier_init_layer(in_size=50, out_size=10) - self.Linear3 = xavier_init_layer(in_size=10, out_size=1) - - def forward(self, x): - out = self.BN(x) - - out = self.conv1(out) - out = self.activation(out) - - out = self.conv2(out) - out = self.activation(out) - - out = self.conv3(out) - out = self.activation(out) - - out = self.conv4(out) - out = self.activation(out) - - out = torch.mean(out, (2, 3)) - - out = self.Linear1(out) - out = self.activation(out) - - out = self.Linear2(out) - out = self.activation(out) - - out = self.Linear3(out) - - return out +"""Generator and discriminator used in MetricGAN + +Authors: +* Szu-Wei Fu 2020 +""" +import torch +import speechbrain as sb +from torch import nn +from torch.nn.utils import spectral_norm + + +def xavier_init_layer( + in_size, out_size=None, spec_norm=True, layer_type=nn.Linear, **kwargs +): + "Create a layer with spectral norm, xavier uniform init and zero bias" + if out_size is None: + out_size = in_size + + layer = layer_type(in_size, out_size, **kwargs) + if spec_norm: + layer = spectral_norm(layer) + + # Perform initialization + nn.init.xavier_uniform_(layer.weight, gain=1.0) + nn.init.zeros_(layer.bias) + + return layer + + +def shifted_sigmoid(x): + return 1.2 / (1 + torch.exp(-(1 / 1.6) * x)) + + +class Learnable_sigmoid(nn.Module): + def __init__(self, in_features=257): + super().__init__() + self.slope = nn.Parameter(torch.ones(in_features)) + self.slope.requiresGrad = True # set requiresGrad to true! + + # self.scale = nn.Parameter(torch.ones(1)) + # self.scale.requiresGrad = True # set requiresGrad to true! + + def forward(self, x): + return 1.2 / (1 + torch.exp(-(self.slope) * x)) + + +class EnhancementGenerator(nn.Module): + """Simple LSTM for enhancement with custom initialization. + + Arguments + --------- + input_size : int + Size of the input tensor's last dimension. + hidden_size : int + Number of neurons to use in the LSTM layers. + num_layers : int + Number of layers to use in the LSTM. + dropout : int + Fraction of neurons to drop during training. + """ + + def __init__( + self, input_size=257, hidden_size=200, num_layers=2, dropout=0, + ): + super().__init__() + self.activation = nn.LeakyReLU(negative_slope=0.3) + + self.blstm = sb.nnet.RNN.LSTM( + input_size=input_size, + hidden_size=hidden_size, + num_layers=num_layers, + dropout=dropout, + bidirectional=True, + ) + """ + Use orthogonal init for recurrent layers, xavier uniform for input layers + Bias is 0 + """ + for name, param in self.blstm.named_parameters(): + if "bias" in name: + nn.init.zeros_(param) + elif "weight_ih" in name: + nn.init.xavier_uniform_(param) + elif "weight_hh" in name: + nn.init.orthogonal_(param) + + self.linear1 = xavier_init_layer(400, 300, spec_norm=False) + self.linear2 = xavier_init_layer(300, 257, spec_norm=False) + + self.Learnable_sigmoid = Learnable_sigmoid() + self.sigmoid = nn.Sigmoid() + + def forward(self, x, lengths): + out, _ = self.blstm(x, lengths=lengths) + + out = self.linear1(out) + out = self.activation(out) + + out = self.linear2(out) + out = self.Learnable_sigmoid(out) + + return out + + +class MetricDiscriminator(nn.Module): + """Metric estimator for enhancement training. + + Consists of: + * four 2d conv layers + * channel averaging + * three linear layers + + Arguments + --------- + kernel_size : tuple + The dimensions of the 2-d kernel used for convolution. + base_channels : int + Number of channels used in each conv layer. + """ + + def __init__( + self, kernel_size=(5, 5), base_channels=15, activation=nn.LeakyReLU, + ): + super().__init__() + + self.activation = activation(negative_slope=0.3) + + self.BN = nn.BatchNorm2d(num_features=2, momentum=0.01) + + self.conv1 = xavier_init_layer( + 2, base_channels, layer_type=nn.Conv2d, kernel_size=kernel_size + ) + self.conv2 = xavier_init_layer( + base_channels, layer_type=nn.Conv2d, kernel_size=kernel_size + ) + self.conv3 = xavier_init_layer( + base_channels, layer_type=nn.Conv2d, kernel_size=kernel_size + ) + self.conv4 = xavier_init_layer( + base_channels, layer_type=nn.Conv2d, kernel_size=kernel_size + ) + + self.Linear1 = xavier_init_layer(base_channels, out_size=50) + self.Linear2 = xavier_init_layer(in_size=50, out_size=10) + self.Linear3 = xavier_init_layer(in_size=10, out_size=1) + + def forward(self, x): + out = self.BN(x) + + out = self.conv1(out) + out = self.activation(out) + + out = self.conv2(out) + out = self.activation(out) + + out = self.conv3(out) + out = self.activation(out) + + out = self.conv4(out) + out = self.activation(out) + + out = torch.mean(out, (2, 3)) + + out = self.Linear1(out) + out = self.activation(out) + + out = self.Linear2(out) + out = self.activation(out) + + out = self.Linear3(out) + + return out diff --git a/PyTorch/contrib/audio/tdnn/speechbrain/nnet/loss/stoi_loss.py b/PyTorch/contrib/audio/tdnn/speechbrain/nnet/loss/stoi_loss.py index e98acf3a965807d4aac08b9fdf12375fc879904d..96e1fc5583acb7d22b430634da415dc02602f650 100644 --- a/PyTorch/contrib/audio/tdnn/speechbrain/nnet/loss/stoi_loss.py +++ b/PyTorch/contrib/audio/tdnn/speechbrain/nnet/loss/stoi_loss.py @@ -13,198 +13,198 @@ # limitations under the License. # -# ################################ -# From paper: "End-to-End Waveform Utterance Enhancement for Direct Evaluation -# Metrics Optimization by Fully Convolutional Neural Networks", TASLP, 2018 -# Authors: Szu-Wei, Fu 2020 -# ################################ - -import torch -import torchaudio -import numpy as np -from speechbrain.utils.torch_audio_backend import get_torchaudio_backend - -torchaudio_backend = get_torchaudio_backend() -torchaudio.set_audio_backend(torchaudio_backend) -smallVal = np.finfo("float").eps # To avoid divide by zero - - -def thirdoct(fs, nfft, num_bands, min_freq): - """Returns the 1/3 octave band matrix. - - Arguments - --------- - fs : int - Sampling rate. - nfft : int - FFT size. - num_bands : int - Number of 1/3 octave bands. - min_freq : int - Center frequency of the lowest 1/3 octave band. - - Returns - ------- - obm : tensor - Octave Band Matrix. - """ - - f = torch.linspace(0, fs, nfft + 1) - f = f[: int(nfft / 2) + 1] - k = torch.from_numpy(np.array(range(num_bands)).astype(float)) - cf = torch.pow(2.0 ** (1.0 / 3), k) * min_freq - freq_low = min_freq * torch.pow(2.0, (2 * k - 1) / 6) - freq_high = min_freq * torch.pow(2.0, (2 * k + 1) / 6) - obm = torch.zeros(num_bands, len(f)) # a verifier - - for i in range(len(cf)): - # Match 1/3 oct band freq with fft frequency bin - f_bin = torch.argmin(torch.square(f - freq_low[i])) - freq_low[i] = f[f_bin] - fl_ii = f_bin - f_bin = torch.argmin(torch.square(f - freq_high[i])) - freq_high[i] = f[f_bin] - fh_ii = f_bin - # Assign to the octave band matrix - obm[i, fl_ii:fh_ii] = 1 - return obm - - -def removeSilentFrames(x, y, dyn_range=40, N=256, K=128): - w = torch.unsqueeze(torch.from_numpy(np.hanning(256)), 0).to(torch.float) - - X1 = x[0 : int(x.shape[0]) // N * N].reshape(int(x.shape[0]) // N, N).T - X2 = ( - x[128 : (int(x.shape[0]) - 128) // N * N + 128] - .reshape((int(x.shape[0]) - 128) // N, N) - .T - ) - X = torch.zeros(N, X1.shape[1] + X2.shape[1]) - X[:, 0::2] = X1 - X[:, 1::2] = X2 - - energy = 20 * torch.log10( - torch.sqrt(torch.matmul(w ** 2, X ** 2)) / 16.0 + smallVal - ) - - Max_energy = torch.max(energy) - msk = torch.squeeze((energy - Max_energy + dyn_range > 0)) - - Y1 = y[0 : int(y.shape[0]) // N * N].reshape(int(y.shape[0]) // N, N).T - Y2 = ( - y[128 : (int(y.shape[0]) - 128) // N * N + 128] - .reshape((int(y.shape[0]) - 128) // N, N) - .T - ) - Y = torch.zeros(N, Y1.shape[1] + Y2.shape[1]) - Y[:, 0::2] = Y1 - Y[:, 1::2] = Y2 - - x_sil = w.T.repeat(1, X[:, msk].shape[-1]) * X[:, msk] - y_sil = w.T.repeat(1, X[:, msk].shape[-1]) * Y[:, msk] - - x_sil = torch.cat( - ( - x_sil[0:128, 0], - (x_sil[0:128, 1:] + x_sil[128:, 0:-1]).T.flatten(), - x_sil[128:256, -1], - ), - axis=0, - ) - y_sil = torch.cat( - ( - y_sil[0:128, 0], - (y_sil[0:128, 1:] + y_sil[128:, 0:-1]).T.flatten(), - y_sil[128:256, -1], - ), - axis=0, - ) - - return [x_sil, y_sil] - - -def stoi_loss(y_pred_batch, y_true_batch, lens, reduction="mean"): - """Compute the STOI score and return -1 * that score. - - This function can be used as a loss function for training - with SGD-based updates. - - Arguments - --------- - y_pred_batch : torch.Tensor - The degraded (enhanced) waveforms. - y_true_batch : torch.Tensor - The clean (reference) waveforms. - lens : torch.Tensor - The relative lengths of the waveforms within the batch. - reduction : str - The type of reduction ("mean" or "batch") to use. - - Example - ------- - >>> a = torch.sin(torch.arange(16000, dtype=torch.float32)).unsqueeze(0) - >>> b = a + 0.001 - >>> -stoi_loss(b, a, torch.ones(1)) - tensor(0.7...) - """ - - y_pred_batch = torch.squeeze(y_pred_batch, dim=-1) - y_true_batch = torch.squeeze(y_true_batch, dim=-1) - - batch_size = y_pred_batch.shape[0] - - fs = 16000 # Sampling rate - N = 30 # length of temporal envelope vectors - J = 15.0 # Number of one-third octave bands - - octave_band = thirdoct(fs=10000, nfft=512, num_bands=15, min_freq=150) - c = 5.62341325 # 10^(-Beta/20) with Beta = -15 - D = torch.zeros(batch_size) - resampler = torchaudio.transforms.Resample(fs, 10000) - for i in range(0, batch_size): # Run over mini-batches - y_true = y_true_batch[i, 0 : int(lens[i] * y_pred_batch.shape[1])] - y_pred = y_pred_batch[i, 0 : int(lens[i] * y_pred_batch.shape[1])] - - y_true, y_pred = resampler(y_true), resampler(y_pred) - - [y_sil_true, y_sil_pred] = removeSilentFrames(y_true, y_pred) - - stft_true = torchaudio.transforms.Spectrogram( - n_fft=512, win_length=256, hop_length=128, power=2 - )(y_sil_true) - stft_pred = torchaudio.transforms.Spectrogram( - n_fft=512, win_length=256, hop_length=128, power=2 - )(y_sil_pred) - - OCT_true = torch.sqrt(torch.matmul(octave_band, stft_true) + 1e-14) - OCT_pred = torch.sqrt(torch.matmul(octave_band, stft_pred) + 1e-14) - - M = int( - stft_pred.shape[-1] - (N - 1) - ) # number of temporal envelope vectors - - X = torch.zeros(15 * M, 30) - Y = torch.zeros(15 * M, 30) - for m in range(0, M): # Run over temporal envelope vectors - X[m * 15 : (m + 1) * 15, :] = OCT_true[:, m : m + N] - Y[m * 15 : (m + 1) * 15, :] = OCT_pred[:, m : m + N] - - alpha = torch.norm(X, dim=-1, keepdim=True) / ( - torch.norm(Y, dim=-1, keepdim=True) + smallVal - ) - - ay = Y * alpha - y = torch.min(ay, X + X * c) - - xn = X - torch.mean(X, dim=-1, keepdim=True) - xn = xn / (torch.norm(xn, dim=-1, keepdim=True) + smallVal) - - yn = y - torch.mean(y, dim=-1, keepdim=True) - yn = yn / (torch.norm(yn, dim=-1, keepdim=True) + smallVal) - d = torch.sum(xn * yn) - D[i] = d / (J * M) - - if reduction == "mean": - return -D.mean() - - return -D +# ################################ +# From paper: "End-to-End Waveform Utterance Enhancement for Direct Evaluation +# Metrics Optimization by Fully Convolutional Neural Networks", TASLP, 2018 +# Authors: Szu-Wei, Fu 2020 +# ################################ + +import torch +import torchaudio +import numpy as np +from speechbrain.utils.torch_audio_backend import get_torchaudio_backend + +torchaudio_backend = get_torchaudio_backend() +torchaudio.set_audio_backend(torchaudio_backend) +smallVal = np.finfo("float").eps # To avoid divide by zero + + +def thirdoct(fs, nfft, num_bands, min_freq): + """Returns the 1/3 octave band matrix. + + Arguments + --------- + fs : int + Sampling rate. + nfft : int + FFT size. + num_bands : int + Number of 1/3 octave bands. + min_freq : int + Center frequency of the lowest 1/3 octave band. + + Returns + ------- + obm : tensor + Octave Band Matrix. + """ + + f = torch.linspace(0, fs, nfft + 1) + f = f[: int(nfft / 2) + 1] + k = torch.from_numpy(np.array(range(num_bands)).astype(float)) + cf = torch.pow(2.0 ** (1.0 / 3), k) * min_freq + freq_low = min_freq * torch.pow(2.0, (2 * k - 1) / 6) + freq_high = min_freq * torch.pow(2.0, (2 * k + 1) / 6) + obm = torch.zeros(num_bands, len(f)) # a verifier + + for i in range(len(cf)): + # Match 1/3 oct band freq with fft frequency bin + f_bin = torch.argmin(torch.square(f - freq_low[i])) + freq_low[i] = f[f_bin] + fl_ii = f_bin + f_bin = torch.argmin(torch.square(f - freq_high[i])) + freq_high[i] = f[f_bin] + fh_ii = f_bin + # Assign to the octave band matrix + obm[i, fl_ii:fh_ii] = 1 + return obm + + +def removeSilentFrames(x, y, dyn_range=40, N=256, K=128): + w = torch.unsqueeze(torch.from_numpy(np.hanning(256)), 0).to(torch.float) + + X1 = x[0 : int(x.shape[0]) // N * N].reshape(int(x.shape[0]) // N, N).T + X2 = ( + x[128 : (int(x.shape[0]) - 128) // N * N + 128] + .reshape((int(x.shape[0]) - 128) // N, N) + .T + ) + X = torch.zeros(N, X1.shape[1] + X2.shape[1]) + X[:, 0::2] = X1 + X[:, 1::2] = X2 + + energy = 20 * torch.log10( + torch.sqrt(torch.matmul(w ** 2, X ** 2)) / 16.0 + smallVal + ) + + Max_energy = torch.max(energy) + msk = torch.squeeze((energy - Max_energy + dyn_range > 0)) + + Y1 = y[0 : int(y.shape[0]) // N * N].reshape(int(y.shape[0]) // N, N).T + Y2 = ( + y[128 : (int(y.shape[0]) - 128) // N * N + 128] + .reshape((int(y.shape[0]) - 128) // N, N) + .T + ) + Y = torch.zeros(N, Y1.shape[1] + Y2.shape[1]) + Y[:, 0::2] = Y1 + Y[:, 1::2] = Y2 + + x_sil = w.T.repeat(1, X[:, msk].shape[-1]) * X[:, msk] + y_sil = w.T.repeat(1, X[:, msk].shape[-1]) * Y[:, msk] + + x_sil = torch.cat( + ( + x_sil[0:128, 0], + (x_sil[0:128, 1:] + x_sil[128:, 0:-1]).T.flatten(), + x_sil[128:256, -1], + ), + axis=0, + ) + y_sil = torch.cat( + ( + y_sil[0:128, 0], + (y_sil[0:128, 1:] + y_sil[128:, 0:-1]).T.flatten(), + y_sil[128:256, -1], + ), + axis=0, + ) + + return [x_sil, y_sil] + + +def stoi_loss(y_pred_batch, y_true_batch, lens, reduction="mean"): + """Compute the STOI score and return -1 * that score. + + This function can be used as a loss function for training + with SGD-based updates. + + Arguments + --------- + y_pred_batch : torch.Tensor + The degraded (enhanced) waveforms. + y_true_batch : torch.Tensor + The clean (reference) waveforms. + lens : torch.Tensor + The relative lengths of the waveforms within the batch. + reduction : str + The type of reduction ("mean" or "batch") to use. + + Example + ------- + >>> a = torch.sin(torch.arange(16000, dtype=torch.float32)).unsqueeze(0) + >>> b = a + 0.001 + >>> -stoi_loss(b, a, torch.ones(1)) + tensor(0.7...) + """ + + y_pred_batch = torch.squeeze(y_pred_batch, dim=-1) + y_true_batch = torch.squeeze(y_true_batch, dim=-1) + + batch_size = y_pred_batch.shape[0] + + fs = 16000 # Sampling rate + N = 30 # length of temporal envelope vectors + J = 15.0 # Number of one-third octave bands + + octave_band = thirdoct(fs=10000, nfft=512, num_bands=15, min_freq=150) + c = 5.62341325 # 10^(-Beta/20) with Beta = -15 + D = torch.zeros(batch_size) + resampler = torchaudio.transforms.Resample(fs, 10000) + for i in range(0, batch_size): # Run over mini-batches + y_true = y_true_batch[i, 0 : int(lens[i] * y_pred_batch.shape[1])] + y_pred = y_pred_batch[i, 0 : int(lens[i] * y_pred_batch.shape[1])] + + y_true, y_pred = resampler(y_true), resampler(y_pred) + + [y_sil_true, y_sil_pred] = removeSilentFrames(y_true, y_pred) + + stft_true = torchaudio.transforms.Spectrogram( + n_fft=512, win_length=256, hop_length=128, power=2 + )(y_sil_true) + stft_pred = torchaudio.transforms.Spectrogram( + n_fft=512, win_length=256, hop_length=128, power=2 + )(y_sil_pred) + + OCT_true = torch.sqrt(torch.matmul(octave_band, stft_true) + 1e-14) + OCT_pred = torch.sqrt(torch.matmul(octave_band, stft_pred) + 1e-14) + + M = int( + stft_pred.shape[-1] - (N - 1) + ) # number of temporal envelope vectors + + X = torch.zeros(15 * M, 30) + Y = torch.zeros(15 * M, 30) + for m in range(0, M): # Run over temporal envelope vectors + X[m * 15 : (m + 1) * 15, :] = OCT_true[:, m : m + N] + Y[m * 15 : (m + 1) * 15, :] = OCT_pred[:, m : m + N] + + alpha = torch.norm(X, dim=-1, keepdim=True) / ( + torch.norm(Y, dim=-1, keepdim=True) + smallVal + ) + + ay = Y * alpha + y = torch.min(ay, X + X * c) + + xn = X - torch.mean(X, dim=-1, keepdim=True) + xn = xn / (torch.norm(xn, dim=-1, keepdim=True) + smallVal) + + yn = y - torch.mean(y, dim=-1, keepdim=True) + yn = yn / (torch.norm(yn, dim=-1, keepdim=True) + smallVal) + d = torch.sum(xn * yn) + D[i] = d / (J * M) + + if reduction == "mean": + return -D.mean() + + return -D diff --git a/PyTorch/contrib/audio/tdnn/templates/speaker_id/mini_librispeech_prepare.py b/PyTorch/contrib/audio/tdnn/templates/speaker_id/mini_librispeech_prepare.py index 7a59d8259d130f4afde972e05b3795404efecf5b..adb9e51765a581fc49f5a2340c3b1a32445da2b0 100644 --- a/PyTorch/contrib/audio/tdnn/templates/speaker_id/mini_librispeech_prepare.py +++ b/PyTorch/contrib/audio/tdnn/templates/speaker_id/mini_librispeech_prepare.py @@ -13,209 +13,209 @@ # limitations under the License. # -""" -Downloads and creates data manifest files for Mini LibriSpeech (spk-id). -For speaker-id, different sentences of the same speaker must appear in train, -validation, and test sets. In this case, these sets are thus derived from -splitting the original training set intothree chunks. - -Authors: - * Mirco Ravanelli, 2021 -""" - -import os -import json -import shutil -import random -import logging -from speechbrain.utils.data_utils import get_all_files, download_file -from speechbrain.dataio.dataio import read_audio - -logger = logging.getLogger(__name__) -MINILIBRI_TRAIN_URL = "http://www.openslr.org/resources/31/train-clean-5.tar.gz" -SAMPLERATE = 16000 - - -def prepare_mini_librispeech( - data_folder, - save_json_train, - save_json_valid, - save_json_test, - split_ratio=[80, 10, 10], - batch_size=32, -): - """ - Prepares the json files for the Mini Librispeech dataset. - - Downloads the dataset if it is not found in the `data_folder`. - - Arguments - --------- - data_folder : str - Path to the folder where the Mini Librispeech dataset is stored. - save_json_train : str - Path where the train data specification file will be saved. - save_json_valid : str - Path where the validation data specification file will be saved. - save_json_test : str - Path where the test data specification file will be saved. - split_ratio: list - List composed of three integers that sets split ratios for train, valid, - and test sets, respectively. For instance split_ratio=[80, 10, 10] will - assign 80% of the sentences to training, 10% for validation, and 10% - for test. - - Example - ------- - >>> data_folder = '/path/to/mini_librispeech' - >>> prepare_mini_librispeech(data_folder, 'train.json', 'valid.json', 'test.json') - """ - - # Check if this phase is already done (if so, skip it) - - if skip(save_json_train, save_json_valid, save_json_test): - logger.info("Preparation completed in previous run, skipping.") - return - - # If the dataset doesn't exist yet, download it - train_folder = os.path.join(data_folder, "LibriSpeech", "train-clean-5") - if not check_folders(train_folder): - download_mini_librispeech(data_folder) - - # List files and create manifest from list - logger.info( - f"Creating {save_json_train}, {save_json_valid}, and {save_json_test}" - ) - extension = [".flac"] - wav_list = get_all_files(train_folder, match_and=extension) - - # Random split the signal list into train, valid, and test sets. - data_split = split_sets(wav_list, split_ratio, batch_size) - - # Creating json files - create_json(data_split["train"], save_json_train) - create_json(data_split["valid"], save_json_valid) - create_json(data_split["test"], save_json_test) - - -def create_json(wav_list, json_file): - """ - Creates the json file given a list of wav files. - - Arguments - --------- - wav_list : list of str - The list of wav files. - json_file : str - The path of the output json file - """ - # Processing all the wav files in the list - json_dict = {} - for wav_file in wav_list: - - # Reading the signal (to retrieve duration in seconds) - signal = read_audio(wav_file) - duration = signal.shape[0] / SAMPLERATE - - # Manipulate path to get relative path and uttid - path_parts = wav_file.split(os.path.sep) - uttid, _ = os.path.splitext(path_parts[-1]) - relative_path = os.path.join("{data_root}", *path_parts[-5:]) - - # Getting speaker-id from utterance-id - spk_id = uttid.split("-")[0] - - # Create entry for this utterance - json_dict[uttid] = { - "wav": relative_path, - "length": duration, - "spk_id": spk_id, - } - - # Writing the dictionary to the json file - with open(json_file, mode="w") as json_f: - json.dump(json_dict, json_f, indent=2) - - logger.info(f"{json_file} successfully created!") - - -def skip(*filenames): - """ - Detects if the data preparation has been already done. - If the preparation has been done, we can skip it. - - Returns - ------- - bool - if True, the preparation phase can be skipped. - if False, it must be done. - """ - for filename in filenames: - if not os.path.isfile(filename): - return False - return True - - -def check_folders(*folders): - """Returns False if any passed folder does not exist.""" - for folder in folders: - if not os.path.exists(folder): - return False - return True - - -def split_sets(wav_list, split_ratio, batch_size): - """Randomly splits the wav list into training, validation, and test lists. - Note that a better approach is to make sure that all the classes have the - same proportion of samples (e.g, spk01 should have 80% of samples in - training, 10% validation, 10% test, the same for speaker2 etc.). This - is the approach followed in some recipes such as the Voxceleb one. For - simplicity, we here simply split the full list without necessarily respecting - the split ratio within each class. - - Arguments - --------- - wav_lst : list - list of all the signals in the dataset - split_ratio: list - List composed of three integers that sets split ratios for train, valid, - and test sets, respectively. For instance split_ratio=[80, 10, 10] will - assign 80% of the sentences to training, 10% for validation, and 10% - for test. - - Returns - ------ - dictionary containing train, valid, and test splits. - """ - # Random shuffle of the list - random.shuffle(wav_list) - tot_split = sum(split_ratio) - tot_snts = len(wav_list) - data_split = {} - splits = ["train", "valid"] - - # for i, split in enumerate(splits): - # n_snts = int(tot_snts * split_ratio[i] / tot_split) - # data_split[split] = wav_list[0:n_snts] - # del wav_list[0:n_snts] - # data_split["test"] = wav_list - - for i, split in enumerate(splits): - n_snts = int(tot_snts * split_ratio[i] / tot_split // batch_size * batch_size) - data_split[split] = wav_list[0:n_snts] - del wav_list[0:n_snts] - data_split["test"] = wav_list[0:n_snts] - return data_split - - -def download_mini_librispeech(destination): - """Download dataset and unpack it. - - Arguments - --------- - destination : str - Place to put dataset. - """ - train_archive = os.path.join(destination, "train-clean-5.tar.gz") - download_file(MINILIBRI_TRAIN_URL, train_archive) - shutil.unpack_archive(train_archive, destination) +""" +Downloads and creates data manifest files for Mini LibriSpeech (spk-id). +For speaker-id, different sentences of the same speaker must appear in train, +validation, and test sets. In this case, these sets are thus derived from +splitting the original training set intothree chunks. + +Authors: + * Mirco Ravanelli, 2021 +""" + +import os +import json +import shutil +import random +import logging +from speechbrain.utils.data_utils import get_all_files, download_file +from speechbrain.dataio.dataio import read_audio + +logger = logging.getLogger(__name__) +MINILIBRI_TRAIN_URL = "http://www.openslr.org/resources/31/train-clean-5.tar.gz" +SAMPLERATE = 16000 + + +def prepare_mini_librispeech( + data_folder, + save_json_train, + save_json_valid, + save_json_test, + split_ratio=[80, 10, 10], + batch_size=32, +): + """ + Prepares the json files for the Mini Librispeech dataset. + + Downloads the dataset if it is not found in the `data_folder`. + + Arguments + --------- + data_folder : str + Path to the folder where the Mini Librispeech dataset is stored. + save_json_train : str + Path where the train data specification file will be saved. + save_json_valid : str + Path where the validation data specification file will be saved. + save_json_test : str + Path where the test data specification file will be saved. + split_ratio: list + List composed of three integers that sets split ratios for train, valid, + and test sets, respectively. For instance split_ratio=[80, 10, 10] will + assign 80% of the sentences to training, 10% for validation, and 10% + for test. + + Example + ------- + >>> data_folder = '/path/to/mini_librispeech' + >>> prepare_mini_librispeech(data_folder, 'train.json', 'valid.json', 'test.json') + """ + + # Check if this phase is already done (if so, skip it) + + if skip(save_json_train, save_json_valid, save_json_test): + logger.info("Preparation completed in previous run, skipping.") + return + + # If the dataset doesn't exist yet, download it + train_folder = os.path.join(data_folder, "LibriSpeech", "train-clean-5") + if not check_folders(train_folder): + download_mini_librispeech(data_folder) + + # List files and create manifest from list + logger.info( + f"Creating {save_json_train}, {save_json_valid}, and {save_json_test}" + ) + extension = [".flac"] + wav_list = get_all_files(train_folder, match_and=extension) + + # Random split the signal list into train, valid, and test sets. + data_split = split_sets(wav_list, split_ratio, batch_size) + + # Creating json files + create_json(data_split["train"], save_json_train) + create_json(data_split["valid"], save_json_valid) + create_json(data_split["test"], save_json_test) + + +def create_json(wav_list, json_file): + """ + Creates the json file given a list of wav files. + + Arguments + --------- + wav_list : list of str + The list of wav files. + json_file : str + The path of the output json file + """ + # Processing all the wav files in the list + json_dict = {} + for wav_file in wav_list: + + # Reading the signal (to retrieve duration in seconds) + signal = read_audio(wav_file) + duration = signal.shape[0] / SAMPLERATE + + # Manipulate path to get relative path and uttid + path_parts = wav_file.split(os.path.sep) + uttid, _ = os.path.splitext(path_parts[-1]) + relative_path = os.path.join("{data_root}", *path_parts[-5:]) + + # Getting speaker-id from utterance-id + spk_id = uttid.split("-")[0] + + # Create entry for this utterance + json_dict[uttid] = { + "wav": relative_path, + "length": duration, + "spk_id": spk_id, + } + + # Writing the dictionary to the json file + with open(json_file, mode="w") as json_f: + json.dump(json_dict, json_f, indent=2) + + logger.info(f"{json_file} successfully created!") + + +def skip(*filenames): + """ + Detects if the data preparation has been already done. + If the preparation has been done, we can skip it. + + Returns + ------- + bool + if True, the preparation phase can be skipped. + if False, it must be done. + """ + for filename in filenames: + if not os.path.isfile(filename): + return False + return True + + +def check_folders(*folders): + """Returns False if any passed folder does not exist.""" + for folder in folders: + if not os.path.exists(folder): + return False + return True + + +def split_sets(wav_list, split_ratio, batch_size): + """Randomly splits the wav list into training, validation, and test lists. + Note that a better approach is to make sure that all the classes have the + same proportion of samples (e.g, spk01 should have 80% of samples in + training, 10% validation, 10% test, the same for speaker2 etc.). This + is the approach followed in some recipes such as the Voxceleb one. For + simplicity, we here simply split the full list without necessarily respecting + the split ratio within each class. + + Arguments + --------- + wav_lst : list + list of all the signals in the dataset + split_ratio: list + List composed of three integers that sets split ratios for train, valid, + and test sets, respectively. For instance split_ratio=[80, 10, 10] will + assign 80% of the sentences to training, 10% for validation, and 10% + for test. + + Returns + ------ + dictionary containing train, valid, and test splits. + """ + # Random shuffle of the list + random.shuffle(wav_list) + tot_split = sum(split_ratio) + tot_snts = len(wav_list) + data_split = {} + splits = ["train", "valid"] + + # for i, split in enumerate(splits): + # n_snts = int(tot_snts * split_ratio[i] / tot_split) + # data_split[split] = wav_list[0:n_snts] + # del wav_list[0:n_snts] + # data_split["test"] = wav_list + + for i, split in enumerate(splits): + n_snts = int(tot_snts * split_ratio[i] / tot_split // batch_size * batch_size) + data_split[split] = wav_list[0:n_snts] + del wav_list[0:n_snts] + data_split["test"] = wav_list[0:n_snts] + return data_split + + +def download_mini_librispeech(destination): + """Download dataset and unpack it. + + Arguments + --------- + destination : str + Place to put dataset. + """ + train_archive = os.path.join(destination, "train-clean-5.tar.gz") + download_file(MINILIBRI_TRAIN_URL, train_archive) + shutil.unpack_archive(train_archive, destination) diff --git a/PyTorch/contrib/audio/tdnn/templates/speaker_id/modelzoo_level.txt b/PyTorch/contrib/audio/tdnn/templates/speaker_id/modelzoo_level.txt index b8f3c5693dfc8cbc81345111dae9c4f739edb244..c7d1879e5eedecc37bb4bafa3a15ee16f7c25cda 100644 --- a/PyTorch/contrib/audio/tdnn/templates/speaker_id/modelzoo_level.txt +++ b/PyTorch/contrib/audio/tdnn/templates/speaker_id/modelzoo_level.txt @@ -1,6 +1,6 @@ -GPUStatus:OK -NPUMigrationStatus:OK -FuncStatus:OK -PrecisionStatus:OK -AutoTune:NOK +GPUStatus:OK +NPUMigrationStatus:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:NOK PerfStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/audio/tdnn/templates/speaker_id/test/train_full_8p.sh b/PyTorch/contrib/audio/tdnn/templates/speaker_id/test/train_full_8p.sh index 702c19b5d9ab11d5e7c59c0a7acb416ab3c08ddf..d7f81cce38a697d9a9b58f9a377605ba511c6f58 100644 --- a/PyTorch/contrib/audio/tdnn/templates/speaker_id/test/train_full_8p.sh +++ b/PyTorch/contrib/audio/tdnn/templates/speaker_id/test/train_full_8p.sh @@ -1,159 +1,159 @@ -##################基础配置参数,需要模型审视修改################## -# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE -# 删除之前结果 -rm -rf ../results - -#集合通信参数,不需要修改 -export RANK_SIZE=8 - -# 数据集路径,保持为空,不需要修改 -data_folder="" -#网络名称,同目录名称,需要模型审视修改 -Network="Tdnn" - -#训练batch_size,,需要模型审视修改 -batch_size=64 - -#训练epoch -train_epochs=15 -# 指定训练所使用的npu device卡id -device_id=0 - - -# 参数校验,data_folder为必传参数, 其他参数的增删由模型自身决定;此处若新增参数需在上面有定义并赋值; -for para in $* -do - if [[ $para == --workers* ]];then - workers=`echo ${para#*=}` - elif [[ $para == --data_folder* ]];then - data_folder=`echo ${para#*=}` - fi -done - -# 校验是否传入data_folder,不需要修改 -if [[ $data_folder == "" ]];then - echo "[Error] para \"data_folder\" must be config" - exit 1 -fi - -##################指定训练脚本执行路径################## -# cd到与test文件同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" - ln -s source dest -elif [ ${device_id} ]; then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - echo "[Error] device id must be confing" - exit 1 -fi - - - -#################指定训练脚本执行路径################## -# cd到与test文件同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ]; then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - -##################创建日志输出目录,不需要修改################## -ASCEND_DEVICE_ID=${device_id} -if [ -d ${test_path_dir}/output/$ASCEND_DEVICE_ID ];then - rm -rf ${test_path_dir}/output/$ASCEND_DEVICE_ID - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -fi - -##################启动训练脚本################## -# 训练开始时间,不需要修改 -start_time=$(date +%s) -# source 环境变量 -source ${test_path_dir}/env.sh -export WORLD_SIZE=8 -export MASTER_ADDR='127.0.0.1' -export MASTER_PORT='211225' - -for((RANK_ID=0;RANK_ID ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}_full_8p.log 2>&1 & - else - python3.7 train.py train.yaml \ - --distributed_launch \ - --distributed_backend=hccl \ - --local_rank ${RANK_ID} \ - --batch_size=$batch_size \ - --number_of_epochs=$train_epochs \ - --data_folder=$data_folder > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}_full_8p.log 2>&1 & - fi -done -wait - - -##################获取训练数据################## -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -# 结果打印,不需要修改 -echo "------------------ Final result ------------------" -# 输出性能FPS,需要模型审视修改 -FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}_full_8p.log|awk -F " " '{print $NF}'|awk 'END {print}'|cut -d ")" -f1` -# 打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -# 输出训练精度,需要模型审视修改 -train_accuracy=`grep "Epoch loaded:" ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}_full_8p.log|awk -F "test error:" '{print $NF}'|awk '{printf("%0.4f\n",1-$1)}'` -# 打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -# 性能看护结果汇总 -# 训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -# 获取性能数据,不需要修改 -# 吞吐量 -ActualFPS=${FPS} -# 单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -# 从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "npu id:" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${ASCEND_DEVICE_ID}_full_8p.log|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -# 最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -# 关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log - +##################基础配置参数,需要模型审视修改################## +# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE +# 删除之前结果 +rm -rf ../results + +#集合通信参数,不需要修改 +export RANK_SIZE=8 + +# 数据集路径,保持为空,不需要修改 +data_folder="" +#网络名称,同目录名称,需要模型审视修改 +Network="Tdnn" + +#训练batch_size,,需要模型审视修改 +batch_size=64 + +#训练epoch +train_epochs=15 +# 指定训练所使用的npu device卡id +device_id=0 + + +# 参数校验,data_folder为必传参数, 其他参数的增删由模型自身决定;此处若新增参数需在上面有定义并赋值; +for para in $* +do + if [[ $para == --workers* ]];then + workers=`echo ${para#*=}` + elif [[ $para == --data_folder* ]];then + data_folder=`echo ${para#*=}` + fi +done + +# 校验是否传入data_folder,不需要修改 +if [[ $data_folder == "" ]];then + echo "[Error] para \"data_folder\" must be config" + exit 1 +fi + +##################指定训练脚本执行路径################## +# cd到与test文件同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" + ln -s source dest +elif [ ${device_id} ]; then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + echo "[Error] device id must be confing" + exit 1 +fi + + + +#################指定训练脚本执行路径################## +# cd到与test文件同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ]; then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +##################创建日志输出目录,不需要修改################## +ASCEND_DEVICE_ID=${device_id} +if [ -d ${test_path_dir}/output/$ASCEND_DEVICE_ID ];then + rm -rf ${test_path_dir}/output/$ASCEND_DEVICE_ID + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +fi + +##################启动训练脚本################## +# 训练开始时间,不需要修改 +start_time=$(date +%s) +# source 环境变量 +source ${test_path_dir}/env.sh +export WORLD_SIZE=8 +export MASTER_ADDR='127.0.0.1' +export MASTER_PORT='211225' + +for((RANK_ID=0;RANK_ID ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}_full_8p.log 2>&1 & + else + python3.7 train.py train.yaml \ + --distributed_launch \ + --distributed_backend=hccl \ + --local_rank ${RANK_ID} \ + --batch_size=$batch_size \ + --number_of_epochs=$train_epochs \ + --data_folder=$data_folder > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}_full_8p.log 2>&1 & + fi +done +wait + + +##################获取训练数据################## +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +# 结果打印,不需要修改 +echo "------------------ Final result ------------------" +# 输出性能FPS,需要模型审视修改 +FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}_full_8p.log|awk -F " " '{print $NF}'|awk 'END {print}'|cut -d ")" -f1` +# 打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +# 输出训练精度,需要模型审视修改 +train_accuracy=`grep "Epoch loaded:" ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}_full_8p.log|awk -F "test error:" '{print $NF}'|awk '{printf("%0.4f\n",1-$1)}'` +# 打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +# 性能看护结果汇总 +# 训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +# 获取性能数据,不需要修改 +# 吞吐量 +ActualFPS=${FPS} +# 单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +# 从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "npu id:" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${ASCEND_DEVICE_ID}_full_8p.log|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +# 最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +# 关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log + diff --git a/PyTorch/contrib/audio/tdnn/templates/speaker_id/test/train_performance_8p.sh b/PyTorch/contrib/audio/tdnn/templates/speaker_id/test/train_performance_8p.sh index 3d8549d6cf017e9b85e706e1b232b6d1ed0c3ccf..94bd08c5aca12532ce26561196174cca52d4da7e 100644 --- a/PyTorch/contrib/audio/tdnn/templates/speaker_id/test/train_performance_8p.sh +++ b/PyTorch/contrib/audio/tdnn/templates/speaker_id/test/train_performance_8p.sh @@ -1,154 +1,154 @@ -##################基础配置参数,需要模型审视修改################## -# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE -# 删除之前结果 -rm -rf ../results - -#集合通信参数,不需要修改 -export RANK_SIZE=8 - -# 数据集路径,保持为空,不需要修改 -data_folder="" -#网络名称,同目录名称,需要模型审视修改 -Network="Tdnn" - -#训练batch_size,,需要模型审视修改 -batch_size=64 - -#训练epoch -train_epochs=2 -# 指定训练所使用的npu device卡id -device_id=0 - - -# 参数校验,data_folder为必传参数, 其他参数的增删由模型自身决定;此处若新增参数需在上面有定义并赋值; -for para in $* -do - if [[ $para == --workers* ]];then - workers=`echo ${para#*=}` - elif [[ $para == --data_folder* ]];then - data_folder=`echo ${para#*=}` - fi -done - -# 校验是否传入data_folder,不需要修改 -if [[ $data_folder == "" ]];then - echo "[Error] para \"data_folder\" must be config" - exit 1 -fi - -##################指定训练脚本执行路径################## -# cd到与test文件同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" - ln -s source dest -elif [ ${device_id} ]; then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - echo "[Error] device id must be confing" - exit 1 -fi - - - -#################指定训练脚本执行路径################## -# cd到与test文件同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ]; then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - -##################创建日志输出目录,不需要修改################## -ASCEND_DEVICE_ID=${device_id} -if [ -d ${test_path_dir}/output/$ASCEND_DEVICE_ID ];then - rm -rf ${test_path_dir}/output/$ASCEND_DEVICE_ID - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -fi - -##################启动训练脚本################## -# 训练开始时间,不需要修改 -start_time=$(date +%s) -# source 环境变量 -source ${test_path_dir}/env.sh -export WORLD_SIZE=8 -export MASTER_ADDR='127.0.0.1' -export MASTER_PORT='211225' - -for((RANK_ID=0;RANK_ID ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}_perf_8p.log 2>&1 & - else - python3.7 train.py train.yaml \ - --distributed_launch \ - --distributed_backend=hccl \ - --local_rank ${RANK_ID} \ - --batch_size=$batch_size \ - --number_of_epochs=$train_epochs \ - --data_folder=$data_folder > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}_perf_8p.log 2>&1 & - fi -done -wait - - -##################获取训练数据################## -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -# 结果打印,不需要修改 -echo "------------------ Final result ------------------" -# 输出性能FPS,需要模型审视修改 -FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}_perf_8p.log|awk -F "(" '{print $NF}'|awk 'END {print}'|cut -d ")" -f1` -# 打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -echo "E2E Training Duration sec : $e2e_time" - -# 性能看护结果汇总 -# 训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -# 获取性能数据,不需要修改 -# 吞吐量 -ActualFPS=${FPS} -# 单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -# 从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "npu id:" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${ASCEND_DEVICE_ID}_perf_8p.log|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -# 最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -# 关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log - +##################基础配置参数,需要模型审视修改################## +# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE +# 删除之前结果 +rm -rf ../results + +#集合通信参数,不需要修改 +export RANK_SIZE=8 + +# 数据集路径,保持为空,不需要修改 +data_folder="" +#网络名称,同目录名称,需要模型审视修改 +Network="Tdnn" + +#训练batch_size,,需要模型审视修改 +batch_size=64 + +#训练epoch +train_epochs=2 +# 指定训练所使用的npu device卡id +device_id=0 + + +# 参数校验,data_folder为必传参数, 其他参数的增删由模型自身决定;此处若新增参数需在上面有定义并赋值; +for para in $* +do + if [[ $para == --workers* ]];then + workers=`echo ${para#*=}` + elif [[ $para == --data_folder* ]];then + data_folder=`echo ${para#*=}` + fi +done + +# 校验是否传入data_folder,不需要修改 +if [[ $data_folder == "" ]];then + echo "[Error] para \"data_folder\" must be config" + exit 1 +fi + +##################指定训练脚本执行路径################## +# cd到与test文件同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" + ln -s source dest +elif [ ${device_id} ]; then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + echo "[Error] device id must be confing" + exit 1 +fi + + + +#################指定训练脚本执行路径################## +# cd到与test文件同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ]; then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +##################创建日志输出目录,不需要修改################## +ASCEND_DEVICE_ID=${device_id} +if [ -d ${test_path_dir}/output/$ASCEND_DEVICE_ID ];then + rm -rf ${test_path_dir}/output/$ASCEND_DEVICE_ID + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +fi + +##################启动训练脚本################## +# 训练开始时间,不需要修改 +start_time=$(date +%s) +# source 环境变量 +source ${test_path_dir}/env.sh +export WORLD_SIZE=8 +export MASTER_ADDR='127.0.0.1' +export MASTER_PORT='211225' + +for((RANK_ID=0;RANK_ID ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}_perf_8p.log 2>&1 & + else + python3.7 train.py train.yaml \ + --distributed_launch \ + --distributed_backend=hccl \ + --local_rank ${RANK_ID} \ + --batch_size=$batch_size \ + --number_of_epochs=$train_epochs \ + --data_folder=$data_folder > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}_perf_8p.log 2>&1 & + fi +done +wait + + +##################获取训练数据################## +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +# 结果打印,不需要修改 +echo "------------------ Final result ------------------" +# 输出性能FPS,需要模型审视修改 +FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}_perf_8p.log|awk -F "(" '{print $NF}'|awk 'END {print}'|cut -d ")" -f1` +# 打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +echo "E2E Training Duration sec : $e2e_time" + +# 性能看护结果汇总 +# 训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +# 获取性能数据,不需要修改 +# 吞吐量 +ActualFPS=${FPS} +# 单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +# 从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "npu id:" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${ASCEND_DEVICE_ID}_perf_8p.log|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +# 最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +# 关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log + diff --git a/PyTorch/contrib/cv/classification/3d_attention_net/train.py b/PyTorch/contrib/cv/classification/3d_attention_net/train.py index fa3c27864012e21389862c9ab4e4d78ca069351d..30cb7368f276e99eba819d745d4e262e09c0aa64 100644 --- a/PyTorch/contrib/cv/classification/3d_attention_net/train.py +++ b/PyTorch/contrib/cv/classification/3d_attention_net/train.py @@ -1,236 +1,236 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import print_function, division -from apex import amp -from apex.optimizers import NpuFusedSGD -import torch -import argparse -import torch.nn as nn -import torch.optim as optim -from torch.autograd import Variable -from torch.utils.data import Dataset, DataLoader -import numpy as np -import torchvision -from torchvision import transforms, datasets, models -import os -import cv2 -import time -import torch.npu -import torch.utils.data.distributed -from collections import OrderedDict -from torch.nn.parallel import DistributedDataParallel -from model.residual_attention_network import ResidualAttentionModel_92_32input_update as ResidualAttentionModel - -device = None -args = None -log_file = None - -def parse_args(): - parser = argparse.ArgumentParser(description='3D Attention Net') - parser.add_argument('--device_type', type=str) - parser.add_argument('--device_id', type=int) - parser.add_argument('--device_num', type=int) - parser.add_argument('--total_epochs', type=int) - parser.add_argument('--is_train', type=str) - parser.add_argument('--is_pretrain', type=str) - parser.add_argument('--num_classes', type=int) - parser.add_argument('--dist_url', type=str) - parser.add_argument('--train_batch_size', type=int) - parser.add_argument('--test_batch_size', type=int) - args = parser.parse_args() - return args - -# for test -def test(model, test_loader): - # Test - classes = ('plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck') - model.eval() - correct = 0 - total = 0 - class_correct = list(0. for i in range(10)) - class_total = list(0. for i in range(10)) - - for images, labels in test_loader: - images = Variable(images.to(device)) - labels = Variable(labels.to(device)) - outputs = model(images) - _, predicted = torch.max(outputs.data, 1) - total += labels.size(0) - correct += (predicted == labels.data).sum() - c = (predicted == labels.data).squeeze() - for i in range(len(labels.data)): - label = labels.data[i] - class_correct[label] += c[i] - class_total[label] += 1 - if args.device_id == 0: - print(f"Accuracy of the model(on device: {args.device_id}) on the test images: {100 * float(correct) / total} %") - write_log('Accuracy of the model on the test images: %d %%\n' % (100 * float(correct) / total)) - write_log(f'Accuracy of the model on the test images: {float(correct)/total} \n') - return float(correct) / total - -def write_log(output): - if log_file is not None: - log_file.write(output) - - -def main(): - global args - global device - args = parse_args() - print(args) - model_file = 'model_92_sgd.pkl' - train_batch_size = args.train_batch_size - test_batch_size = args.test_batch_size - lr = 0.1 - is_train = args.is_train == "True" - is_pretrain = args.is_pretrain == "True" - acc_best = 0 - total_epoch = args.total_epochs - distribute = args.device_num > 1 - if(args.device_type == "GPU"): - device = torch.device("cuda", args.device_id) - if distribute: - torch.cuda.set_device(args.device_id) - torch.distributed.init_process_group(backend="nccl", init_method=args.dist_url, world_size=args.device_num, rank=args.device_id) - else: - device = f"npu:{args.device_id}" - if distribute: - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = '49876' - torch.npu.set_device(device) - print("rank:",args.device_id) - torch.distributed.init_process_group(backend="hccl", world_size=args.device_num, rank=args.device_id) - - # Image Preprocessing - transform = transforms.Compose([ - transforms.RandomHorizontalFlip(), - transforms.RandomCrop((32, 32), padding=4), - transforms.ToTensor() - ]) - test_transform = transforms.Compose([ - transforms.ToTensor() - ]) - - train_dataset = datasets.CIFAR10(root='./data/', train=True, transform=transform, download=False) - test_dataset = datasets.CIFAR10(root='./data/', train=False, transform=test_transform) - train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) if distribute else None - train_loader = torch.utils.data.DataLoader(dataset=train_dataset, \ - batch_size=train_batch_size, \ - shuffle=(train_sampler is None), \ - num_workers=8, \ - pin_memory=False, \ - sampler = train_sampler if is_train else None, \ - drop_last = True) - test_loader = torch.utils.data.DataLoader(dataset=test_dataset, batch_size=test_batch_size, shuffle=False) - - model = ResidualAttentionModel(args.num_classes).to(device) - criterion = nn.CrossEntropyLoss().to(device) - optimizer = None - if args.device_type == "GPU": - optimizer = optim.SGD(model.parameters(), lr=lr, momentum=0.9, nesterov=True, weight_decay=0.0001) - else: - optimizer = NpuFusedSGD(model.parameters(), lr=lr, momentum=0.9, nesterov=True, weight_decay=0.0001) - model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=128.0) - if distribute: - if args.device_type == "GPU": - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.device_id]) - else: - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.device_id], broadcast_buffers=False) - global log_file - if args.device_id == 0: - log_file = open("train_log_file" if is_train else "test_log_file", mode="w+") - if is_train is True: - if is_pretrain == True: - base_weights = torch.load(model_file, map_location="cpu") - print('Loading base network...') - new_state_dict = OrderedDict() - for k, v in base_weights.items(): - if(k[0: 7] == "module."): - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - if "fc.weight" in new_state_dict: - print("pop fc layer weight") - new_state_dict.pop("fc.weight") - new_state_dict.pop("fc.bias") - model.load_state_dict(new_state_dict, strict=False) - - # Training - total_tims = 0 - total_samples = 0 - for epoch in range(total_epoch): - model.train() - tims = time.time() - epoch_samples = 0 - if train_sampler is not None: # is distributed - train_sampler.set_epoch(epoch) - for i, (images, labels) in enumerate(train_loader): - epoch_samples += images.shape[0] - if i == 5: - tims = time.time() - images = Variable(images.to(device)) - labels = Variable(labels.to(device)) - - # Forward + Backward + Optimize - optimizer.zero_grad() - outputs = model(images) - loss = criterion(outputs, labels) - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - optimizer.step() - - if (i+1) % 20 == 0 and args.device_id == 0: - print("Epoch [%d/%d], Iter [%d/%d] Loss: %.4f" %(epoch+1, total_epoch, i+1, len(train_loader), loss.item())) - write_log("Epoch [%d/%d], Iter [%d/%d] Loss: %.4f \n" %(epoch+1, total_epoch, i+1, len(train_loader), loss.item())) - total_tims += time.time() - tims - total_samples += epoch_samples - if args.device_id == 0: - print(f'the epoch {epoch+1} takes time:',time.time()-tims) - print(f"epoch {epoch+1} FPS: {(epoch_samples - 5 * train_batch_size)* args.device_num / (time.time()-tims)}") - print('evaluate test set:') - write_log(f'the epoch {epoch+1} takes time: {time.time()-tims} \n') - write_log(f"epoch {epoch+1} FPS: {(epoch_samples - 5 * train_batch_size)* args.device_num / (time.time()-tims)} \n") - acc = test(model, test_loader) - if acc > acc_best: - acc_best = acc - print('current best acc,', acc_best) - if args.device_id == 0: - torch.save(model.state_dict(), model_file) - # Decaying Learning Rate - if (epoch+1) / float(total_epoch) == 0.3 or (epoch+1) / float(total_epoch) == 0.6 or (epoch+1) / float(total_epoch) == 0.9: - lr /= 10 - print('reset learning rate to:', lr) - for param_group in optimizer.param_groups: - param_group['lr'] = lr - print(param_group['lr']) - # Save the Model - if args.device_id == 0: - torch.save(model.state_dict(), 'last_model_92_sgd.pkl') - elif args.device_id == 0: - base_weights = torch.load(model_file, map_location="cpu") - print('Loading base network...') - new_state_dict = OrderedDict() - for k, v in base_weights.items(): - if(k[0: 7] == "module."): - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - model.load_state_dict(new_state_dict) - test(model, test_loader) - -if __name__ == "__main__": - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import print_function, division +from apex import amp +from apex.optimizers import NpuFusedSGD +import torch +import argparse +import torch.nn as nn +import torch.optim as optim +from torch.autograd import Variable +from torch.utils.data import Dataset, DataLoader +import numpy as np +import torchvision +from torchvision import transforms, datasets, models +import os +import cv2 +import time +import torch.npu +import torch.utils.data.distributed +from collections import OrderedDict +from torch.nn.parallel import DistributedDataParallel +from model.residual_attention_network import ResidualAttentionModel_92_32input_update as ResidualAttentionModel + +device = None +args = None +log_file = None + +def parse_args(): + parser = argparse.ArgumentParser(description='3D Attention Net') + parser.add_argument('--device_type', type=str) + parser.add_argument('--device_id', type=int) + parser.add_argument('--device_num', type=int) + parser.add_argument('--total_epochs', type=int) + parser.add_argument('--is_train', type=str) + parser.add_argument('--is_pretrain', type=str) + parser.add_argument('--num_classes', type=int) + parser.add_argument('--dist_url', type=str) + parser.add_argument('--train_batch_size', type=int) + parser.add_argument('--test_batch_size', type=int) + args = parser.parse_args() + return args + +# for test +def test(model, test_loader): + # Test + classes = ('plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck') + model.eval() + correct = 0 + total = 0 + class_correct = list(0. for i in range(10)) + class_total = list(0. for i in range(10)) + + for images, labels in test_loader: + images = Variable(images.to(device)) + labels = Variable(labels.to(device)) + outputs = model(images) + _, predicted = torch.max(outputs.data, 1) + total += labels.size(0) + correct += (predicted == labels.data).sum() + c = (predicted == labels.data).squeeze() + for i in range(len(labels.data)): + label = labels.data[i] + class_correct[label] += c[i] + class_total[label] += 1 + if args.device_id == 0: + print(f"Accuracy of the model(on device: {args.device_id}) on the test images: {100 * float(correct) / total} %") + write_log('Accuracy of the model on the test images: %d %%\n' % (100 * float(correct) / total)) + write_log(f'Accuracy of the model on the test images: {float(correct)/total} \n') + return float(correct) / total + +def write_log(output): + if log_file is not None: + log_file.write(output) + + +def main(): + global args + global device + args = parse_args() + print(args) + model_file = 'model_92_sgd.pkl' + train_batch_size = args.train_batch_size + test_batch_size = args.test_batch_size + lr = 0.1 + is_train = args.is_train == "True" + is_pretrain = args.is_pretrain == "True" + acc_best = 0 + total_epoch = args.total_epochs + distribute = args.device_num > 1 + if(args.device_type == "GPU"): + device = torch.device("cuda", args.device_id) + if distribute: + torch.cuda.set_device(args.device_id) + torch.distributed.init_process_group(backend="nccl", init_method=args.dist_url, world_size=args.device_num, rank=args.device_id) + else: + device = f"npu:{args.device_id}" + if distribute: + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '49876' + torch.npu.set_device(device) + print("rank:",args.device_id) + torch.distributed.init_process_group(backend="hccl", world_size=args.device_num, rank=args.device_id) + + # Image Preprocessing + transform = transforms.Compose([ + transforms.RandomHorizontalFlip(), + transforms.RandomCrop((32, 32), padding=4), + transforms.ToTensor() + ]) + test_transform = transforms.Compose([ + transforms.ToTensor() + ]) + + train_dataset = datasets.CIFAR10(root='./data/', train=True, transform=transform, download=False) + test_dataset = datasets.CIFAR10(root='./data/', train=False, transform=test_transform) + train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) if distribute else None + train_loader = torch.utils.data.DataLoader(dataset=train_dataset, \ + batch_size=train_batch_size, \ + shuffle=(train_sampler is None), \ + num_workers=8, \ + pin_memory=False, \ + sampler = train_sampler if is_train else None, \ + drop_last = True) + test_loader = torch.utils.data.DataLoader(dataset=test_dataset, batch_size=test_batch_size, shuffle=False) + + model = ResidualAttentionModel(args.num_classes).to(device) + criterion = nn.CrossEntropyLoss().to(device) + optimizer = None + if args.device_type == "GPU": + optimizer = optim.SGD(model.parameters(), lr=lr, momentum=0.9, nesterov=True, weight_decay=0.0001) + else: + optimizer = NpuFusedSGD(model.parameters(), lr=lr, momentum=0.9, nesterov=True, weight_decay=0.0001) + model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=128.0) + if distribute: + if args.device_type == "GPU": + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.device_id]) + else: + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.device_id], broadcast_buffers=False) + global log_file + if args.device_id == 0: + log_file = open("train_log_file" if is_train else "test_log_file", mode="w+") + if is_train is True: + if is_pretrain == True: + base_weights = torch.load(model_file, map_location="cpu") + print('Loading base network...') + new_state_dict = OrderedDict() + for k, v in base_weights.items(): + if(k[0: 7] == "module."): + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + if "fc.weight" in new_state_dict: + print("pop fc layer weight") + new_state_dict.pop("fc.weight") + new_state_dict.pop("fc.bias") + model.load_state_dict(new_state_dict, strict=False) + + # Training + total_tims = 0 + total_samples = 0 + for epoch in range(total_epoch): + model.train() + tims = time.time() + epoch_samples = 0 + if train_sampler is not None: # is distributed + train_sampler.set_epoch(epoch) + for i, (images, labels) in enumerate(train_loader): + epoch_samples += images.shape[0] + if i == 5: + tims = time.time() + images = Variable(images.to(device)) + labels = Variable(labels.to(device)) + + # Forward + Backward + Optimize + optimizer.zero_grad() + outputs = model(images) + loss = criterion(outputs, labels) + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + optimizer.step() + + if (i+1) % 20 == 0 and args.device_id == 0: + print("Epoch [%d/%d], Iter [%d/%d] Loss: %.4f" %(epoch+1, total_epoch, i+1, len(train_loader), loss.item())) + write_log("Epoch [%d/%d], Iter [%d/%d] Loss: %.4f \n" %(epoch+1, total_epoch, i+1, len(train_loader), loss.item())) + total_tims += time.time() - tims + total_samples += epoch_samples + if args.device_id == 0: + print(f'the epoch {epoch+1} takes time:',time.time()-tims) + print(f"epoch {epoch+1} FPS: {(epoch_samples - 5 * train_batch_size)* args.device_num / (time.time()-tims)}") + print('evaluate test set:') + write_log(f'the epoch {epoch+1} takes time: {time.time()-tims} \n') + write_log(f"epoch {epoch+1} FPS: {(epoch_samples - 5 * train_batch_size)* args.device_num / (time.time()-tims)} \n") + acc = test(model, test_loader) + if acc > acc_best: + acc_best = acc + print('current best acc,', acc_best) + if args.device_id == 0: + torch.save(model.state_dict(), model_file) + # Decaying Learning Rate + if (epoch+1) / float(total_epoch) == 0.3 or (epoch+1) / float(total_epoch) == 0.6 or (epoch+1) / float(total_epoch) == 0.9: + lr /= 10 + print('reset learning rate to:', lr) + for param_group in optimizer.param_groups: + param_group['lr'] = lr + print(param_group['lr']) + # Save the Model + if args.device_id == 0: + torch.save(model.state_dict(), 'last_model_92_sgd.pkl') + elif args.device_id == 0: + base_weights = torch.load(model_file, map_location="cpu") + print('Loading base network...') + new_state_dict = OrderedDict() + for k, v in base_weights.items(): + if(k[0: 7] == "module."): + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + model.load_state_dict(new_state_dict) + test(model, test_loader) + +if __name__ == "__main__": + main() diff --git a/PyTorch/contrib/cv/classification/AlignedReID/modelzoo_level.txt b/PyTorch/contrib/cv/classification/AlignedReID/modelzoo_level.txt index 9e95396651cc4382fe60ee1ee053674f527a448c..27e6c78b37535fe4f5a17029546fe257ad164d34 100644 --- a/PyTorch/contrib/cv/classification/AlignedReID/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/AlignedReID/modelzoo_level.txt @@ -1,4 +1,4 @@ -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/Deit_Small/mixup.py b/PyTorch/contrib/cv/classification/Deit_Small/mixup.py index 3e3b35b157764a66f6bf1e733e0e4a1697cd40e5..dbc166e4f56ffc3c87d35967cb356753dccf6de5 100644 --- a/PyTorch/contrib/cv/classification/Deit_Small/mixup.py +++ b/PyTorch/contrib/cv/classification/Deit_Small/mixup.py @@ -1,330 +1,330 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -""" Mixup and Cutmix - -Papers: -mixup: Beyond Empirical Risk Minimization (https://arxiv.org/abs/1710.09412) - -CutMix: Regularization Strategy to Train Strong Classifiers with Localizable Features (https://arxiv.org/abs/1905.04899) - -Code Reference: -CutMix: https://github.com/clovaai/CutMix-PyTorch - -Hacked together by / Copyright 2020 Ross Wightman -""" -import numpy as np -import torch - - -def one_hot(x, num_classes, on_value=1., off_value=0., device='cuda'): - x = x.long().view(-1, 1) - return torch.full((x.size()[0], num_classes), off_value, device=device).scatter_(1, x, on_value) - - -def mixup_target(target, num_classes, lam=1., smoothing=0.0, device='cuda'): - off_value = smoothing / num_classes - on_value = 1. - smoothing + off_value - y1 = one_hot(target, num_classes, on_value=on_value, off_value=off_value, device=device) - y2 = one_hot(target.flip(0), num_classes, on_value=on_value, off_value=off_value, device=device) - return y1 * lam + y2 * (1. - lam) - - -def rand_bbox(img_shape, lam, margin=0., count=None): - """ Standard CutMix bounding-box - Generates a random square bbox based on lambda value. This impl includes - support for enforcing a border margin as percent of bbox dimensions. - - Args: - img_shape (tuple): Image shape as tuple - lam (float): Cutmix lambda value - margin (float): Percentage of bbox dimension to enforce as margin (reduce amount of box outside image) - count (int): Number of bbox to generate - """ - ratio = np.sqrt(1 - lam) - img_h, img_w = img_shape[-2:] - cut_h, cut_w = int(img_h * ratio), int(img_w * ratio) - margin_y, margin_x = int(margin * cut_h), int(margin * cut_w) - cy = np.random.randint(0 + margin_y, img_h - margin_y, size=count) - cx = np.random.randint(0 + margin_x, img_w - margin_x, size=count) - yl = np.clip(cy - cut_h // 2, 0, img_h) - yh = np.clip(cy + cut_h // 2, 0, img_h) - xl = np.clip(cx - cut_w // 2, 0, img_w) - xh = np.clip(cx + cut_w // 2, 0, img_w) - return yl, yh, xl, xh - - -def rand_bbox_minmax(img_shape, minmax, count=None): - """ Min-Max CutMix bounding-box - Inspired by Darknet cutmix impl, generates a random rectangular bbox - based on min/max percent values applied to each dimension of the input image. - - Typical defaults for minmax are usually in the .2-.3 for min and .8-.9 range for max. - - Args: - img_shape (tuple): Image shape as tuple - minmax (tuple or list): Min and max bbox ratios (as percent of image size) - count (int): Number of bbox to generate - """ - assert len(minmax) == 2 - img_h, img_w = img_shape[-2:] - cut_h = np.random.randint(int(img_h * minmax[0]), int(img_h * minmax[1]), size=count) - cut_w = np.random.randint(int(img_w * minmax[0]), int(img_w * minmax[1]), size=count) - yl = np.random.randint(0, img_h - cut_h, size=count) - xl = np.random.randint(0, img_w - cut_w, size=count) - yu = yl + cut_h - xu = xl + cut_w - return yl, yu, xl, xu - - -def cutmix_bbox_and_lam(img_shape, lam, ratio_minmax=None, correct_lam=True, count=None): - """ Generate bbox and apply lambda correction. - """ - if ratio_minmax is not None: - yl, yu, xl, xu = rand_bbox_minmax(img_shape, ratio_minmax, count=count) - else: - yl, yu, xl, xu = rand_bbox(img_shape, lam, count=count) - if correct_lam or ratio_minmax is not None: - bbox_area = (yu - yl) * (xu - xl) - lam = 1. - bbox_area / float(img_shape[-2] * img_shape[-1]) - return (yl, yu, xl, xu), lam - - -class Mixup: - """ Mixup/Cutmix that applies different params to each element or whole batch - - Args: - mixup_alpha (float): mixup alpha value, mixup is active if > 0. - cutmix_alpha (float): cutmix alpha value, cutmix is active if > 0. - cutmix_minmax (List[float]): cutmix min/max image ratio, cutmix is active and uses this vs alpha if not None. - prob (float): probability of applying mixup or cutmix per batch or element - switch_prob (float): probability of switching to cutmix instead of mixup when both are active - mode (str): how to apply mixup/cutmix params (per 'batch', 'pair' (pair of elements), 'elem' (element) - correct_lam (bool): apply lambda correction when cutmix bbox clipped by image borders - label_smoothing (float): apply label smoothing to the mixed target tensor - num_classes (int): number of classes for target - """ - def __init__(self, mixup_alpha=1., cutmix_alpha=0., cutmix_minmax=None, prob=1.0, switch_prob=0.5, - mode='batch', correct_lam=True, label_smoothing=0.1, num_classes=1000): - self.mixup_alpha = mixup_alpha - self.cutmix_alpha = cutmix_alpha - self.cutmix_minmax = cutmix_minmax - if self.cutmix_minmax is not None: - assert len(self.cutmix_minmax) == 2 - # force cutmix alpha == 1.0 when minmax active to keep logic simple & safe - self.cutmix_alpha = 1.0 - self.mix_prob = prob - self.switch_prob = switch_prob - self.label_smoothing = label_smoothing - self.num_classes = num_classes - self.mode = mode - self.correct_lam = correct_lam # correct lambda based on clipped area for cutmix - self.mixup_enabled = True # set to false to disable mixing (intended tp be set by train loop) - - def _params_per_elem(self, batch_size): - lam = np.ones(batch_size, dtype=np.float32) - use_cutmix = np.zeros(batch_size, dtype=np.bool) - if self.mixup_enabled: - if self.mixup_alpha > 0. and self.cutmix_alpha > 0.: - use_cutmix = np.random.rand(batch_size) < self.switch_prob - lam_mix = np.where( - use_cutmix, - np.random.beta(self.cutmix_alpha, self.cutmix_alpha, size=batch_size), - np.random.beta(self.mixup_alpha, self.mixup_alpha, size=batch_size)) - elif self.mixup_alpha > 0.: - lam_mix = np.random.beta(self.mixup_alpha, self.mixup_alpha, size=batch_size) - elif self.cutmix_alpha > 0.: - use_cutmix = np.ones(batch_size, dtype=np.bool) - lam_mix = np.random.beta(self.cutmix_alpha, self.cutmix_alpha, size=batch_size) - else: - assert False, "One of mixup_alpha > 0., cutmix_alpha > 0., cutmix_minmax not None should be true." - lam = np.where(np.random.rand(batch_size) < self.mix_prob, lam_mix.astype(np.float32), lam) - return lam, use_cutmix - - def _params_per_batch(self): - lam = 1. - use_cutmix = False - if self.mixup_enabled and np.random.rand() < self.mix_prob: - if self.mixup_alpha > 0. and self.cutmix_alpha > 0.: - use_cutmix = np.random.rand() < self.switch_prob - lam_mix = np.random.beta(self.cutmix_alpha, self.cutmix_alpha) if use_cutmix else \ - np.random.beta(self.mixup_alpha, self.mixup_alpha) - elif self.mixup_alpha > 0.: - lam_mix = np.random.beta(self.mixup_alpha, self.mixup_alpha) - elif self.cutmix_alpha > 0.: - use_cutmix = True - lam_mix = np.random.beta(self.cutmix_alpha, self.cutmix_alpha) - else: - assert False, "One of mixup_alpha > 0., cutmix_alpha > 0., cutmix_minmax not None should be true." - lam = float(lam_mix) - return lam, use_cutmix - - def _mix_elem(self, x): - batch_size = len(x) - lam_batch, use_cutmix = self._params_per_elem(batch_size) - x_orig = x.clone() # need to keep an unmodified original for mixing source - for i in range(batch_size): - j = batch_size - i - 1 - lam = lam_batch[i] - if lam != 1.: - if use_cutmix[i]: - (yl, yh, xl, xh), lam = cutmix_bbox_and_lam( - x[i].shape, lam, ratio_minmax=self.cutmix_minmax, correct_lam=self.correct_lam) - x[i][:, yl:yh, xl:xh] = x_orig[j][:, yl:yh, xl:xh] - lam_batch[i] = lam - else: - x[i] = x[i] * lam + x_orig[j] * (1 - lam) - return torch.tensor(lam_batch, device=x.device, dtype=x.dtype).unsqueeze(1) - - def _mix_pair(self, x): - batch_size = len(x) - lam_batch, use_cutmix = self._params_per_elem(batch_size // 2) - x_orig = x.clone() # need to keep an unmodified original for mixing source - for i in range(batch_size // 2): - j = batch_size - i - 1 - lam = lam_batch[i] - if lam != 1.: - if use_cutmix[i]: - (yl, yh, xl, xh), lam = cutmix_bbox_and_lam( - x[i].shape, lam, ratio_minmax=self.cutmix_minmax, correct_lam=self.correct_lam) - x[i][:, yl:yh, xl:xh] = x_orig[j][:, yl:yh, xl:xh] - x[j][:, yl:yh, xl:xh] = x_orig[i][:, yl:yh, xl:xh] - lam_batch[i] = lam - else: - x[i] = x[i] * lam + x_orig[j] * (1 - lam) - x[j] = x[j] * lam + x_orig[i] * (1 - lam) - lam_batch = np.concatenate((lam_batch, lam_batch[::-1])) - return torch.tensor(lam_batch, device=x.device, dtype=x.dtype).unsqueeze(1) - - def _mix_batch(self, x): - lam, use_cutmix = self._params_per_batch() - if lam == 1.: - return 1. - if use_cutmix: - (yl, yh, xl, xh), lam = cutmix_bbox_and_lam( - x.shape, lam, ratio_minmax=self.cutmix_minmax, correct_lam=self.correct_lam) - x[:, :, yl:yh, xl:xh] = x.flip(0)[:, :, yl:yh, xl:xh] - else: - x_flipped = x.flip(0).mul_(1. - lam) - x.mul_(lam).add_(x_flipped) - return lam - - def __call__(self, x, target): - assert len(x) % 2 == 0, 'Batch size should be even when using this' - if self.mode == 'elem': - lam = self._mix_elem(x) - elif self.mode == 'pair': - lam = self._mix_pair(x) - else: - lam = self._mix_batch(x) - target = mixup_target(target, self.num_classes, lam, self.label_smoothing,device='npu') - return x, target - - -class FastCollateMixup(Mixup): - """ Fast Collate w/ Mixup/Cutmix that applies different params to each element or whole batch - - A Mixup impl that's performed while collating the batches. - """ - - def _mix_elem_collate(self, output, batch, half=False): - batch_size = len(batch) - num_elem = batch_size // 2 if half else batch_size - assert len(output) == num_elem - lam_batch, use_cutmix = self._params_per_elem(num_elem) - for i in range(num_elem): - j = batch_size - i - 1 - lam = lam_batch[i] - mixed = batch[i][0] - if lam != 1.: - if use_cutmix[i]: - if not half: - mixed = mixed.copy() - (yl, yh, xl, xh), lam = cutmix_bbox_and_lam( - output.shape, lam, ratio_minmax=self.cutmix_minmax, correct_lam=self.correct_lam) - mixed[:, yl:yh, xl:xh] = batch[j][0][:, yl:yh, xl:xh] - lam_batch[i] = lam - else: - mixed = mixed.astype(np.float32) * lam + batch[j][0].astype(np.float32) * (1 - lam) - np.rint(mixed, out=mixed) - output[i] += torch.from_numpy(mixed.astype(np.uint8)) - if half: - lam_batch = np.concatenate((lam_batch, np.ones(num_elem))) - return torch.tensor(lam_batch).unsqueeze(1) - - def _mix_pair_collate(self, output, batch): - batch_size = len(batch) - lam_batch, use_cutmix = self._params_per_elem(batch_size // 2) - for i in range(batch_size // 2): - j = batch_size - i - 1 - lam = lam_batch[i] - mixed_i = batch[i][0] - mixed_j = batch[j][0] - assert 0 <= lam <= 1.0 - if lam < 1.: - if use_cutmix[i]: - (yl, yh, xl, xh), lam = cutmix_bbox_and_lam( - output.shape, lam, ratio_minmax=self.cutmix_minmax, correct_lam=self.correct_lam) - patch_i = mixed_i[:, yl:yh, xl:xh].copy() - mixed_i[:, yl:yh, xl:xh] = mixed_j[:, yl:yh, xl:xh] - mixed_j[:, yl:yh, xl:xh] = patch_i - lam_batch[i] = lam - else: - mixed_temp = mixed_i.astype(np.float32) * lam + mixed_j.astype(np.float32) * (1 - lam) - mixed_j = mixed_j.astype(np.float32) * lam + mixed_i.astype(np.float32) * (1 - lam) - mixed_i = mixed_temp - np.rint(mixed_j, out=mixed_j) - np.rint(mixed_i, out=mixed_i) - output[i] += torch.from_numpy(mixed_i.astype(np.uint8)) - output[j] += torch.from_numpy(mixed_j.astype(np.uint8)) - lam_batch = np.concatenate((lam_batch, lam_batch[::-1])) - return torch.tensor(lam_batch).unsqueeze(1) - - def _mix_batch_collate(self, output, batch): - batch_size = len(batch) - lam, use_cutmix = self._params_per_batch() - if use_cutmix: - (yl, yh, xl, xh), lam = cutmix_bbox_and_lam( - output.shape, lam, ratio_minmax=self.cutmix_minmax, correct_lam=self.correct_lam) - for i in range(batch_size): - j = batch_size - i - 1 - mixed = batch[i][0] - if lam != 1.: - if use_cutmix: - mixed = mixed.copy() # don't want to modify the original while iterating - mixed[:, yl:yh, xl:xh] = batch[j][0][:, yl:yh, xl:xh] - else: - mixed = mixed.astype(np.float32) * lam + batch[j][0].astype(np.float32) * (1 - lam) - np.rint(mixed, out=mixed) - output[i] += torch.from_numpy(mixed.astype(np.uint8)) - return lam - - def __call__(self, batch, _=None): - batch_size = len(batch) - assert batch_size % 2 == 0, 'Batch size should be even when using this' - half = 'half' in self.mode - if half: - batch_size //= 2 - output = torch.zeros((batch_size, *batch[0][0].shape), dtype=torch.uint8) - if self.mode == 'elem' or self.mode == 'half': - lam = self._mix_elem_collate(output, batch, half=half) - elif self.mode == 'pair': - lam = self._mix_pair_collate(output, batch) - else: - lam = self._mix_batch_collate(output, batch) - target = torch.tensor([b[1] for b in batch], dtype=torch.int64) - target = mixup_target(target, self.num_classes, lam, self.label_smoothing, device='cpu') - target = target[:batch_size] - return output, target - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +""" Mixup and Cutmix + +Papers: +mixup: Beyond Empirical Risk Minimization (https://arxiv.org/abs/1710.09412) + +CutMix: Regularization Strategy to Train Strong Classifiers with Localizable Features (https://arxiv.org/abs/1905.04899) + +Code Reference: +CutMix: https://github.com/clovaai/CutMix-PyTorch + +Hacked together by / Copyright 2020 Ross Wightman +""" +import numpy as np +import torch + + +def one_hot(x, num_classes, on_value=1., off_value=0., device='cuda'): + x = x.long().view(-1, 1) + return torch.full((x.size()[0], num_classes), off_value, device=device).scatter_(1, x, on_value) + + +def mixup_target(target, num_classes, lam=1., smoothing=0.0, device='cuda'): + off_value = smoothing / num_classes + on_value = 1. - smoothing + off_value + y1 = one_hot(target, num_classes, on_value=on_value, off_value=off_value, device=device) + y2 = one_hot(target.flip(0), num_classes, on_value=on_value, off_value=off_value, device=device) + return y1 * lam + y2 * (1. - lam) + + +def rand_bbox(img_shape, lam, margin=0., count=None): + """ Standard CutMix bounding-box + Generates a random square bbox based on lambda value. This impl includes + support for enforcing a border margin as percent of bbox dimensions. + + Args: + img_shape (tuple): Image shape as tuple + lam (float): Cutmix lambda value + margin (float): Percentage of bbox dimension to enforce as margin (reduce amount of box outside image) + count (int): Number of bbox to generate + """ + ratio = np.sqrt(1 - lam) + img_h, img_w = img_shape[-2:] + cut_h, cut_w = int(img_h * ratio), int(img_w * ratio) + margin_y, margin_x = int(margin * cut_h), int(margin * cut_w) + cy = np.random.randint(0 + margin_y, img_h - margin_y, size=count) + cx = np.random.randint(0 + margin_x, img_w - margin_x, size=count) + yl = np.clip(cy - cut_h // 2, 0, img_h) + yh = np.clip(cy + cut_h // 2, 0, img_h) + xl = np.clip(cx - cut_w // 2, 0, img_w) + xh = np.clip(cx + cut_w // 2, 0, img_w) + return yl, yh, xl, xh + + +def rand_bbox_minmax(img_shape, minmax, count=None): + """ Min-Max CutMix bounding-box + Inspired by Darknet cutmix impl, generates a random rectangular bbox + based on min/max percent values applied to each dimension of the input image. + + Typical defaults for minmax are usually in the .2-.3 for min and .8-.9 range for max. + + Args: + img_shape (tuple): Image shape as tuple + minmax (tuple or list): Min and max bbox ratios (as percent of image size) + count (int): Number of bbox to generate + """ + assert len(minmax) == 2 + img_h, img_w = img_shape[-2:] + cut_h = np.random.randint(int(img_h * minmax[0]), int(img_h * minmax[1]), size=count) + cut_w = np.random.randint(int(img_w * minmax[0]), int(img_w * minmax[1]), size=count) + yl = np.random.randint(0, img_h - cut_h, size=count) + xl = np.random.randint(0, img_w - cut_w, size=count) + yu = yl + cut_h + xu = xl + cut_w + return yl, yu, xl, xu + + +def cutmix_bbox_and_lam(img_shape, lam, ratio_minmax=None, correct_lam=True, count=None): + """ Generate bbox and apply lambda correction. + """ + if ratio_minmax is not None: + yl, yu, xl, xu = rand_bbox_minmax(img_shape, ratio_minmax, count=count) + else: + yl, yu, xl, xu = rand_bbox(img_shape, lam, count=count) + if correct_lam or ratio_minmax is not None: + bbox_area = (yu - yl) * (xu - xl) + lam = 1. - bbox_area / float(img_shape[-2] * img_shape[-1]) + return (yl, yu, xl, xu), lam + + +class Mixup: + """ Mixup/Cutmix that applies different params to each element or whole batch + + Args: + mixup_alpha (float): mixup alpha value, mixup is active if > 0. + cutmix_alpha (float): cutmix alpha value, cutmix is active if > 0. + cutmix_minmax (List[float]): cutmix min/max image ratio, cutmix is active and uses this vs alpha if not None. + prob (float): probability of applying mixup or cutmix per batch or element + switch_prob (float): probability of switching to cutmix instead of mixup when both are active + mode (str): how to apply mixup/cutmix params (per 'batch', 'pair' (pair of elements), 'elem' (element) + correct_lam (bool): apply lambda correction when cutmix bbox clipped by image borders + label_smoothing (float): apply label smoothing to the mixed target tensor + num_classes (int): number of classes for target + """ + def __init__(self, mixup_alpha=1., cutmix_alpha=0., cutmix_minmax=None, prob=1.0, switch_prob=0.5, + mode='batch', correct_lam=True, label_smoothing=0.1, num_classes=1000): + self.mixup_alpha = mixup_alpha + self.cutmix_alpha = cutmix_alpha + self.cutmix_minmax = cutmix_minmax + if self.cutmix_minmax is not None: + assert len(self.cutmix_minmax) == 2 + # force cutmix alpha == 1.0 when minmax active to keep logic simple & safe + self.cutmix_alpha = 1.0 + self.mix_prob = prob + self.switch_prob = switch_prob + self.label_smoothing = label_smoothing + self.num_classes = num_classes + self.mode = mode + self.correct_lam = correct_lam # correct lambda based on clipped area for cutmix + self.mixup_enabled = True # set to false to disable mixing (intended tp be set by train loop) + + def _params_per_elem(self, batch_size): + lam = np.ones(batch_size, dtype=np.float32) + use_cutmix = np.zeros(batch_size, dtype=np.bool) + if self.mixup_enabled: + if self.mixup_alpha > 0. and self.cutmix_alpha > 0.: + use_cutmix = np.random.rand(batch_size) < self.switch_prob + lam_mix = np.where( + use_cutmix, + np.random.beta(self.cutmix_alpha, self.cutmix_alpha, size=batch_size), + np.random.beta(self.mixup_alpha, self.mixup_alpha, size=batch_size)) + elif self.mixup_alpha > 0.: + lam_mix = np.random.beta(self.mixup_alpha, self.mixup_alpha, size=batch_size) + elif self.cutmix_alpha > 0.: + use_cutmix = np.ones(batch_size, dtype=np.bool) + lam_mix = np.random.beta(self.cutmix_alpha, self.cutmix_alpha, size=batch_size) + else: + assert False, "One of mixup_alpha > 0., cutmix_alpha > 0., cutmix_minmax not None should be true." + lam = np.where(np.random.rand(batch_size) < self.mix_prob, lam_mix.astype(np.float32), lam) + return lam, use_cutmix + + def _params_per_batch(self): + lam = 1. + use_cutmix = False + if self.mixup_enabled and np.random.rand() < self.mix_prob: + if self.mixup_alpha > 0. and self.cutmix_alpha > 0.: + use_cutmix = np.random.rand() < self.switch_prob + lam_mix = np.random.beta(self.cutmix_alpha, self.cutmix_alpha) if use_cutmix else \ + np.random.beta(self.mixup_alpha, self.mixup_alpha) + elif self.mixup_alpha > 0.: + lam_mix = np.random.beta(self.mixup_alpha, self.mixup_alpha) + elif self.cutmix_alpha > 0.: + use_cutmix = True + lam_mix = np.random.beta(self.cutmix_alpha, self.cutmix_alpha) + else: + assert False, "One of mixup_alpha > 0., cutmix_alpha > 0., cutmix_minmax not None should be true." + lam = float(lam_mix) + return lam, use_cutmix + + def _mix_elem(self, x): + batch_size = len(x) + lam_batch, use_cutmix = self._params_per_elem(batch_size) + x_orig = x.clone() # need to keep an unmodified original for mixing source + for i in range(batch_size): + j = batch_size - i - 1 + lam = lam_batch[i] + if lam != 1.: + if use_cutmix[i]: + (yl, yh, xl, xh), lam = cutmix_bbox_and_lam( + x[i].shape, lam, ratio_minmax=self.cutmix_minmax, correct_lam=self.correct_lam) + x[i][:, yl:yh, xl:xh] = x_orig[j][:, yl:yh, xl:xh] + lam_batch[i] = lam + else: + x[i] = x[i] * lam + x_orig[j] * (1 - lam) + return torch.tensor(lam_batch, device=x.device, dtype=x.dtype).unsqueeze(1) + + def _mix_pair(self, x): + batch_size = len(x) + lam_batch, use_cutmix = self._params_per_elem(batch_size // 2) + x_orig = x.clone() # need to keep an unmodified original for mixing source + for i in range(batch_size // 2): + j = batch_size - i - 1 + lam = lam_batch[i] + if lam != 1.: + if use_cutmix[i]: + (yl, yh, xl, xh), lam = cutmix_bbox_and_lam( + x[i].shape, lam, ratio_minmax=self.cutmix_minmax, correct_lam=self.correct_lam) + x[i][:, yl:yh, xl:xh] = x_orig[j][:, yl:yh, xl:xh] + x[j][:, yl:yh, xl:xh] = x_orig[i][:, yl:yh, xl:xh] + lam_batch[i] = lam + else: + x[i] = x[i] * lam + x_orig[j] * (1 - lam) + x[j] = x[j] * lam + x_orig[i] * (1 - lam) + lam_batch = np.concatenate((lam_batch, lam_batch[::-1])) + return torch.tensor(lam_batch, device=x.device, dtype=x.dtype).unsqueeze(1) + + def _mix_batch(self, x): + lam, use_cutmix = self._params_per_batch() + if lam == 1.: + return 1. + if use_cutmix: + (yl, yh, xl, xh), lam = cutmix_bbox_and_lam( + x.shape, lam, ratio_minmax=self.cutmix_minmax, correct_lam=self.correct_lam) + x[:, :, yl:yh, xl:xh] = x.flip(0)[:, :, yl:yh, xl:xh] + else: + x_flipped = x.flip(0).mul_(1. - lam) + x.mul_(lam).add_(x_flipped) + return lam + + def __call__(self, x, target): + assert len(x) % 2 == 0, 'Batch size should be even when using this' + if self.mode == 'elem': + lam = self._mix_elem(x) + elif self.mode == 'pair': + lam = self._mix_pair(x) + else: + lam = self._mix_batch(x) + target = mixup_target(target, self.num_classes, lam, self.label_smoothing,device='npu') + return x, target + + +class FastCollateMixup(Mixup): + """ Fast Collate w/ Mixup/Cutmix that applies different params to each element or whole batch + + A Mixup impl that's performed while collating the batches. + """ + + def _mix_elem_collate(self, output, batch, half=False): + batch_size = len(batch) + num_elem = batch_size // 2 if half else batch_size + assert len(output) == num_elem + lam_batch, use_cutmix = self._params_per_elem(num_elem) + for i in range(num_elem): + j = batch_size - i - 1 + lam = lam_batch[i] + mixed = batch[i][0] + if lam != 1.: + if use_cutmix[i]: + if not half: + mixed = mixed.copy() + (yl, yh, xl, xh), lam = cutmix_bbox_and_lam( + output.shape, lam, ratio_minmax=self.cutmix_minmax, correct_lam=self.correct_lam) + mixed[:, yl:yh, xl:xh] = batch[j][0][:, yl:yh, xl:xh] + lam_batch[i] = lam + else: + mixed = mixed.astype(np.float32) * lam + batch[j][0].astype(np.float32) * (1 - lam) + np.rint(mixed, out=mixed) + output[i] += torch.from_numpy(mixed.astype(np.uint8)) + if half: + lam_batch = np.concatenate((lam_batch, np.ones(num_elem))) + return torch.tensor(lam_batch).unsqueeze(1) + + def _mix_pair_collate(self, output, batch): + batch_size = len(batch) + lam_batch, use_cutmix = self._params_per_elem(batch_size // 2) + for i in range(batch_size // 2): + j = batch_size - i - 1 + lam = lam_batch[i] + mixed_i = batch[i][0] + mixed_j = batch[j][0] + assert 0 <= lam <= 1.0 + if lam < 1.: + if use_cutmix[i]: + (yl, yh, xl, xh), lam = cutmix_bbox_and_lam( + output.shape, lam, ratio_minmax=self.cutmix_minmax, correct_lam=self.correct_lam) + patch_i = mixed_i[:, yl:yh, xl:xh].copy() + mixed_i[:, yl:yh, xl:xh] = mixed_j[:, yl:yh, xl:xh] + mixed_j[:, yl:yh, xl:xh] = patch_i + lam_batch[i] = lam + else: + mixed_temp = mixed_i.astype(np.float32) * lam + mixed_j.astype(np.float32) * (1 - lam) + mixed_j = mixed_j.astype(np.float32) * lam + mixed_i.astype(np.float32) * (1 - lam) + mixed_i = mixed_temp + np.rint(mixed_j, out=mixed_j) + np.rint(mixed_i, out=mixed_i) + output[i] += torch.from_numpy(mixed_i.astype(np.uint8)) + output[j] += torch.from_numpy(mixed_j.astype(np.uint8)) + lam_batch = np.concatenate((lam_batch, lam_batch[::-1])) + return torch.tensor(lam_batch).unsqueeze(1) + + def _mix_batch_collate(self, output, batch): + batch_size = len(batch) + lam, use_cutmix = self._params_per_batch() + if use_cutmix: + (yl, yh, xl, xh), lam = cutmix_bbox_and_lam( + output.shape, lam, ratio_minmax=self.cutmix_minmax, correct_lam=self.correct_lam) + for i in range(batch_size): + j = batch_size - i - 1 + mixed = batch[i][0] + if lam != 1.: + if use_cutmix: + mixed = mixed.copy() # don't want to modify the original while iterating + mixed[:, yl:yh, xl:xh] = batch[j][0][:, yl:yh, xl:xh] + else: + mixed = mixed.astype(np.float32) * lam + batch[j][0].astype(np.float32) * (1 - lam) + np.rint(mixed, out=mixed) + output[i] += torch.from_numpy(mixed.astype(np.uint8)) + return lam + + def __call__(self, batch, _=None): + batch_size = len(batch) + assert batch_size % 2 == 0, 'Batch size should be even when using this' + half = 'half' in self.mode + if half: + batch_size //= 2 + output = torch.zeros((batch_size, *batch[0][0].shape), dtype=torch.uint8) + if self.mode == 'elem' or self.mode == 'half': + lam = self._mix_elem_collate(output, batch, half=half) + elif self.mode == 'pair': + lam = self._mix_pair_collate(output, batch) + else: + lam = self._mix_batch_collate(output, batch) + target = torch.tensor([b[1] for b in batch], dtype=torch.int64) + target = mixup_target(target, self.num_classes, lam, self.label_smoothing, device='cpu') + target = target[:batch_size] + return output, target + diff --git a/PyTorch/contrib/cv/classification/Deit_Small/npu_fused_adamw.py b/PyTorch/contrib/cv/classification/Deit_Small/npu_fused_adamw.py index bd9f5d6a4d21ab8b3f6b58c7f6a8bacda4fa3ce5..d52d4e2d5ee5644990a601b234cecd7697d242a0 100644 --- a/PyTorch/contrib/cv/classification/Deit_Small/npu_fused_adamw.py +++ b/PyTorch/contrib/cv/classification/Deit_Small/npu_fused_adamw.py @@ -1,257 +1,257 @@ -# Copyright (c) 2020, Huawei Technologies. -# Copyright (c) 2019, Facebook CORPORATION. -# All rights reserved. -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import math -from collections import defaultdict - -import torch -from torch.optim.optimizer import Optimizer - -from apex.contrib.combine_tensors import combine_npu - - -class NpuFusedAdamW(Optimizer): - """Implements AdamW algorithm. - - Currently NPU-only. Requires Apex to be installed via - ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--npu_float_status" ./``. - - This version of NPU fused AdamW implements 1 fusions. - - * A combine-tensor apply launch that batches the elementwise updates applied to all the model's parameters - into one or a few kernel launches. - - :class:`apex.optimizers.NpuFusedAdamW` may be used as a drop-in replacement for ``torch.optim.AdamW``:: - - opt = apex.optimizers.NpuFusedAdamW(model.parameters(), lr = ....) - ... - opt.step() - - :class:`apex.optimizers.FusedAdam` should be used with Amp. Currently, if you wish to use :class:`NpuFusedAdamW` - with Amp, only ``opt_level O1 and O2`` can be choosed:: - - opt = apex.optimizers.NpuFusedAdamW(model.parameters(), lr = ....) - model, opt = amp.initialize(model, opt, opt_level="O2") - ... - opt.step() - - - The original Adam algorithm was proposed in `Adam: A Method for Stochastic Optimization`_. - The AdamW variant was proposed in `Decoupled Weight Decay Regularization`_. - - Arguments: - params (iterable): iterable of parameters to optimize or dicts defining - parameter groups - lr (float, optional, default: 1e-3): learning rate - betas (Tuple[float, float], optional, default: (0.9, 0.999)): coefficients used - for computing running averages of gradient and its square - eps (float, optional, default: 1e-8): term added to the denominator to improve - numerical stability - weight_decay (float, optional, default: 1e-2): weight decay coefficient - amsgrad (boolean, optional, default: False): whether to use the AMSGrad variant of - this algorithm from the paper `On the Convergence of Adam and Beyond`_ - - .. _Adam\: A Method for Stochastic Optimization: - https://arxiv.org/abs/1412.6980 - .. _Decoupled Weight Decay Regularization: - https://arxiv.org/abs/1711.05101 - .. _On the Convergence of Adam and Beyond: - https://openreview.net/forum?id=ryQu7f-RZ - """ - - def __init__(self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, - weight_decay=1e-2, amsgrad=False): - if lr < 0.0: - raise ValueError("Invalid learning rate: {}".format(lr)) - if eps < 0.0: - raise ValueError("Invalid epsilon value: {}".format(eps)) - if betas[0] < 0.0 or betas[0] >= 1.0: - raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) - if betas[1] < 0.0 or betas[1] >= 1.0: - raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) - if weight_decay < 0.0: - raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) - defaults = dict(lr=lr, betas=betas, eps=eps, - weight_decay=weight_decay, amsgrad=amsgrad) - self.is_npu_fused_optimizer = True - super(NpuFusedAdamW, self).__init__(params, defaults) - - def __setstate__(self, state): - super(NpuFusedAdamW, self).__setstate__(state) - for group in self.param_groups: - group.setdefault('amsgrad', False) - - def _init_param_state(self, p, amsgrad): - state = self.state[p] - # State initialization - if len(state) == 0: - state['step'] = 0 - # Exponential moving average of gradient values - state['exp_avg'] = torch.zeros_like(p, memory_format=torch.preserve_format) - # Exponential moving average of squared gradient values - state['exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format) - if amsgrad: - # Maintains max of all exp. moving avg. of sq. grad. values - state['max_exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format) - else: - exp_avg_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) - exp_avg_tmp.copy_(state['exp_avg']) - state['exp_avg'] = exp_avg_tmp - - exp_avg_sq_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) - exp_avg_sq_tmp.copy_(state['exp_avg_sq']) - state['exp_avg_sq'] = exp_avg_sq_tmp - - if amsgrad: - max_exp_avg_sq_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) - max_exp_avg_sq_tmp.copy_(state['max_exp_avg_sq']) - state['max_exp_avg_sq'] = max_exp_avg_sq_tmp - - def _combine_group_param_states(self, group_index): - group = self.param_groups[group_index] - stash = self._amp_stash - group_params_list = stash.params_lists_indexed_by_group[group_index] - - amsgrad = group['amsgrad'] - - combined_param_states = [] - for params in group_params_list: - step_list = [] - exp_avg_list = [] - exp_avg_sq_list = [] - max_exp_avg_sq_list = [] - - for p in params: - if p.grad is None: - continue - grad = p.grad - if grad.is_sparse: - raise RuntimeError('NpuFusedAdamW does not support sparse gradients, ' - 'please consider SparseAdam instead') - - self._init_param_state(p, amsgrad) - state = self.state[p] - step_list.append(state['step']) - exp_avg_list.append(state['exp_avg']) - exp_avg_sq_list.append(state['exp_avg_sq']) - if amsgrad: - max_exp_avg_sq_list.append(state['max_exp_avg_sq']) - - combined_step = 0 - combined_exp_avg = None - combined_exp_avg_sq = None - combined_max_exp_avg_sq = None - - if len(exp_avg_list) > 0: - combined_step = step_list[0] - combined_exp_avg = combine_npu(exp_avg_list) - combined_exp_avg_sq = combine_npu(exp_avg_sq_list) - combined_max_exp_avg_sq = combine_npu(max_exp_avg_sq_list) - - combined_state = defaultdict(dict) - combined_state['step'] = combined_step - combined_state['exp_avg'] = combined_exp_avg - combined_state['exp_avg_sq'] = combined_exp_avg_sq - combined_state['max_exp_avg_sq'] = combined_max_exp_avg_sq - combined_param_states.append(combined_state) - stash.combined_param_states_indexed_by_group[group_index] = combined_param_states - - def _combine_param_states_by_group(self): - stash = self._amp_stash - if stash.param_states_are_combined_by_group: - return - - stash.combined_param_states_indexed_by_group = [] - for _ in self.param_groups: - stash.combined_param_states_indexed_by_group.append([]) - - for i, _ in enumerate(self.param_groups): - self._combine_group_param_states(i) - stash.param_states_are_combined_by_group = True - - def _group_step(self, group_index): - group = self.param_groups[group_index] - for p in group['params']: - if p.grad is None: - continue - - grad = p.grad - if grad.is_sparse: - raise RuntimeError('NpuFusedAdamW does not support sparse gradients, ' - 'please consider SparseAdam instead') - state_p = self.state[p] - state_p['step'] += 1 - - amsgrad = group['amsgrad'] - beta1, beta2 = group['betas'] - - stash = self._amp_stash - combined_group_params = stash.combined_params_indexed_by_group[group_index] - combined_group_grads = stash.combined_grads_indexed_by_group[group_index] - combined_group_param_states = stash.combined_param_states_indexed_by_group[group_index] - - for combined_param, combined_grad, combined_param_state in zip(combined_group_params, - combined_group_grads, - combined_group_param_states): - if combined_param is None or combined_grad is None: - continue - - # Perform stepweight decay. The fused method is used here to speed up the calculation - combined_param.mul_(1 - group['lr'] * group['weight_decay']) - - exp_avg, exp_avg_sq = combined_param_state['exp_avg'], combined_param_state['exp_avg_sq'] - if amsgrad: - max_exp_avg_sq = combined_param_state['max_exp_avg_sq'] - - combined_param_state['step'] += 1 - bias_correction1 = 1 - beta1 ** combined_param_state['step'] - bias_correction2 = 1 - beta2 ** combined_param_state['step'] - - # Decay the first and second moment running average coefficient - exp_avg.mul_(beta1).add_(combined_grad, alpha=1 - beta1) - exp_avg_sq.mul_(beta2).addcmul_(combined_grad, combined_grad, value=1 - beta2) - if amsgrad: - # Maintains the maximum of all 2nd moment running avg. till now - torch.max(max_exp_avg_sq, exp_avg_sq, out=max_exp_avg_sq) - # Use the max. for normalizing running avg. of gradient - denom = (max_exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group['eps']) - else: - denom = (exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group['eps']) - - step_size = group['lr'] / bias_correction1 - - combined_param.addcdiv_(exp_avg, denom, value=-step_size) - - @torch.no_grad() - def step(self, closure=None): - if not hasattr(self, "_amp_stash"): - raise RuntimeError('apex.optimizers.NpuFusedAdamW should be used with AMP.') - - self._check_already_combined_params_and_grads() - # combine params and grads first - self._combine_params_and_grads_by_group() - # then combine param states - self._combine_param_states_by_group() - - loss = None - if closure is not None: - with torch.enable_grad(): - loss = closure() - - for i, _ in enumerate(self.param_groups): - self._group_step(i) - - return loss +# Copyright (c) 2020, Huawei Technologies. +# Copyright (c) 2019, Facebook CORPORATION. +# All rights reserved. +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import math +from collections import defaultdict + +import torch +from torch.optim.optimizer import Optimizer + +from apex.contrib.combine_tensors import combine_npu + + +class NpuFusedAdamW(Optimizer): + """Implements AdamW algorithm. + + Currently NPU-only. Requires Apex to be installed via + ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--npu_float_status" ./``. + + This version of NPU fused AdamW implements 1 fusions. + + * A combine-tensor apply launch that batches the elementwise updates applied to all the model's parameters + into one or a few kernel launches. + + :class:`apex.optimizers.NpuFusedAdamW` may be used as a drop-in replacement for ``torch.optim.AdamW``:: + + opt = apex.optimizers.NpuFusedAdamW(model.parameters(), lr = ....) + ... + opt.step() + + :class:`apex.optimizers.FusedAdam` should be used with Amp. Currently, if you wish to use :class:`NpuFusedAdamW` + with Amp, only ``opt_level O1 and O2`` can be choosed:: + + opt = apex.optimizers.NpuFusedAdamW(model.parameters(), lr = ....) + model, opt = amp.initialize(model, opt, opt_level="O2") + ... + opt.step() + + + The original Adam algorithm was proposed in `Adam: A Method for Stochastic Optimization`_. + The AdamW variant was proposed in `Decoupled Weight Decay Regularization`_. + + Arguments: + params (iterable): iterable of parameters to optimize or dicts defining + parameter groups + lr (float, optional, default: 1e-3): learning rate + betas (Tuple[float, float], optional, default: (0.9, 0.999)): coefficients used + for computing running averages of gradient and its square + eps (float, optional, default: 1e-8): term added to the denominator to improve + numerical stability + weight_decay (float, optional, default: 1e-2): weight decay coefficient + amsgrad (boolean, optional, default: False): whether to use the AMSGrad variant of + this algorithm from the paper `On the Convergence of Adam and Beyond`_ + + .. _Adam\: A Method for Stochastic Optimization: + https://arxiv.org/abs/1412.6980 + .. _Decoupled Weight Decay Regularization: + https://arxiv.org/abs/1711.05101 + .. _On the Convergence of Adam and Beyond: + https://openreview.net/forum?id=ryQu7f-RZ + """ + + def __init__(self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, + weight_decay=1e-2, amsgrad=False): + if lr < 0.0: + raise ValueError("Invalid learning rate: {}".format(lr)) + if eps < 0.0: + raise ValueError("Invalid epsilon value: {}".format(eps)) + if betas[0] < 0.0 or betas[0] >= 1.0: + raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) + if betas[1] < 0.0 or betas[1] >= 1.0: + raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) + if weight_decay < 0.0: + raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) + defaults = dict(lr=lr, betas=betas, eps=eps, + weight_decay=weight_decay, amsgrad=amsgrad) + self.is_npu_fused_optimizer = True + super(NpuFusedAdamW, self).__init__(params, defaults) + + def __setstate__(self, state): + super(NpuFusedAdamW, self).__setstate__(state) + for group in self.param_groups: + group.setdefault('amsgrad', False) + + def _init_param_state(self, p, amsgrad): + state = self.state[p] + # State initialization + if len(state) == 0: + state['step'] = 0 + # Exponential moving average of gradient values + state['exp_avg'] = torch.zeros_like(p, memory_format=torch.preserve_format) + # Exponential moving average of squared gradient values + state['exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format) + if amsgrad: + # Maintains max of all exp. moving avg. of sq. grad. values + state['max_exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format) + else: + exp_avg_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) + exp_avg_tmp.copy_(state['exp_avg']) + state['exp_avg'] = exp_avg_tmp + + exp_avg_sq_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) + exp_avg_sq_tmp.copy_(state['exp_avg_sq']) + state['exp_avg_sq'] = exp_avg_sq_tmp + + if amsgrad: + max_exp_avg_sq_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) + max_exp_avg_sq_tmp.copy_(state['max_exp_avg_sq']) + state['max_exp_avg_sq'] = max_exp_avg_sq_tmp + + def _combine_group_param_states(self, group_index): + group = self.param_groups[group_index] + stash = self._amp_stash + group_params_list = stash.params_lists_indexed_by_group[group_index] + + amsgrad = group['amsgrad'] + + combined_param_states = [] + for params in group_params_list: + step_list = [] + exp_avg_list = [] + exp_avg_sq_list = [] + max_exp_avg_sq_list = [] + + for p in params: + if p.grad is None: + continue + grad = p.grad + if grad.is_sparse: + raise RuntimeError('NpuFusedAdamW does not support sparse gradients, ' + 'please consider SparseAdam instead') + + self._init_param_state(p, amsgrad) + state = self.state[p] + step_list.append(state['step']) + exp_avg_list.append(state['exp_avg']) + exp_avg_sq_list.append(state['exp_avg_sq']) + if amsgrad: + max_exp_avg_sq_list.append(state['max_exp_avg_sq']) + + combined_step = 0 + combined_exp_avg = None + combined_exp_avg_sq = None + combined_max_exp_avg_sq = None + + if len(exp_avg_list) > 0: + combined_step = step_list[0] + combined_exp_avg = combine_npu(exp_avg_list) + combined_exp_avg_sq = combine_npu(exp_avg_sq_list) + combined_max_exp_avg_sq = combine_npu(max_exp_avg_sq_list) + + combined_state = defaultdict(dict) + combined_state['step'] = combined_step + combined_state['exp_avg'] = combined_exp_avg + combined_state['exp_avg_sq'] = combined_exp_avg_sq + combined_state['max_exp_avg_sq'] = combined_max_exp_avg_sq + combined_param_states.append(combined_state) + stash.combined_param_states_indexed_by_group[group_index] = combined_param_states + + def _combine_param_states_by_group(self): + stash = self._amp_stash + if stash.param_states_are_combined_by_group: + return + + stash.combined_param_states_indexed_by_group = [] + for _ in self.param_groups: + stash.combined_param_states_indexed_by_group.append([]) + + for i, _ in enumerate(self.param_groups): + self._combine_group_param_states(i) + stash.param_states_are_combined_by_group = True + + def _group_step(self, group_index): + group = self.param_groups[group_index] + for p in group['params']: + if p.grad is None: + continue + + grad = p.grad + if grad.is_sparse: + raise RuntimeError('NpuFusedAdamW does not support sparse gradients, ' + 'please consider SparseAdam instead') + state_p = self.state[p] + state_p['step'] += 1 + + amsgrad = group['amsgrad'] + beta1, beta2 = group['betas'] + + stash = self._amp_stash + combined_group_params = stash.combined_params_indexed_by_group[group_index] + combined_group_grads = stash.combined_grads_indexed_by_group[group_index] + combined_group_param_states = stash.combined_param_states_indexed_by_group[group_index] + + for combined_param, combined_grad, combined_param_state in zip(combined_group_params, + combined_group_grads, + combined_group_param_states): + if combined_param is None or combined_grad is None: + continue + + # Perform stepweight decay. The fused method is used here to speed up the calculation + combined_param.mul_(1 - group['lr'] * group['weight_decay']) + + exp_avg, exp_avg_sq = combined_param_state['exp_avg'], combined_param_state['exp_avg_sq'] + if amsgrad: + max_exp_avg_sq = combined_param_state['max_exp_avg_sq'] + + combined_param_state['step'] += 1 + bias_correction1 = 1 - beta1 ** combined_param_state['step'] + bias_correction2 = 1 - beta2 ** combined_param_state['step'] + + # Decay the first and second moment running average coefficient + exp_avg.mul_(beta1).add_(combined_grad, alpha=1 - beta1) + exp_avg_sq.mul_(beta2).addcmul_(combined_grad, combined_grad, value=1 - beta2) + if amsgrad: + # Maintains the maximum of all 2nd moment running avg. till now + torch.max(max_exp_avg_sq, exp_avg_sq, out=max_exp_avg_sq) + # Use the max. for normalizing running avg. of gradient + denom = (max_exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group['eps']) + else: + denom = (exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group['eps']) + + step_size = group['lr'] / bias_correction1 + + combined_param.addcdiv_(exp_avg, denom, value=-step_size) + + @torch.no_grad() + def step(self, closure=None): + if not hasattr(self, "_amp_stash"): + raise RuntimeError('apex.optimizers.NpuFusedAdamW should be used with AMP.') + + self._check_already_combined_params_and_grads() + # combine params and grads first + self._combine_params_and_grads_by_group() + # then combine param states + self._combine_param_states_by_group() + + loss = None + if closure is not None: + with torch.enable_grad(): + loss = closure() + + for i, _ in enumerate(self.param_groups): + self._group_step(i) + + return loss diff --git a/PyTorch/contrib/cv/classification/DnCNN/.keep b/PyTorch/contrib/cv/classification/DnCNN/.keep old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/Dockerfile b/PyTorch/contrib/cv/classification/DnCNN/Dockerfile old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/README.md b/PyTorch/contrib/cv/classification/DnCNN/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/dataset.py b/PyTorch/contrib/cv/classification/DnCNN/dataset.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/demo.py b/PyTorch/contrib/cv/classification/DnCNN/demo.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/docker_start.sh b/PyTorch/contrib/cv/classification/DnCNN/docker_start.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/evalOnePic.py b/PyTorch/contrib/cv/classification/DnCNN/evalOnePic.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/models.py b/PyTorch/contrib/cv/classification/DnCNN/models.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/modelzoo_level.txt b/PyTorch/contrib/cv/classification/DnCNN/modelzoo_level.txt old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/pth2onnx.py b/PyTorch/contrib/cv/classification/DnCNN/pth2onnx.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/requirements.txt b/PyTorch/contrib/cv/classification/DnCNN/requirements.txt old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/scripts/demo.sh b/PyTorch/contrib/cv/classification/DnCNN/scripts/demo.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/scripts/eval.sh b/PyTorch/contrib/cv/classification/DnCNN/scripts/eval.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/scripts/pth2onnx.sh b/PyTorch/contrib/cv/classification/DnCNN/scripts/pth2onnx.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/scripts/set_npu_env.sh b/PyTorch/contrib/cv/classification/DnCNN/scripts/set_npu_env.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/scripts/train_1p.sh b/PyTorch/contrib/cv/classification/DnCNN/scripts/train_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/scripts/train_8p.sh b/PyTorch/contrib/cv/classification/DnCNN/scripts/train_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/test/demo.sh b/PyTorch/contrib/cv/classification/DnCNN/test/demo.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/test/pth2onnx.sh b/PyTorch/contrib/cv/classification/DnCNN/test/pth2onnx.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/test/train_eval_8p.sh b/PyTorch/contrib/cv/classification/DnCNN/test/train_eval_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/test/train_full_1p.sh b/PyTorch/contrib/cv/classification/DnCNN/test/train_full_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/test/train_full_8p.sh b/PyTorch/contrib/cv/classification/DnCNN/test/train_full_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/test/train_performance_1p.sh b/PyTorch/contrib/cv/classification/DnCNN/test/train_performance_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/test/train_performance_8p.sh b/PyTorch/contrib/cv/classification/DnCNN/test/train_performance_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/train_1p.py b/PyTorch/contrib/cv/classification/DnCNN/train_1p.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/train_8p.py b/PyTorch/contrib/cv/classification/DnCNN/train_8p.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/DnCNN/utils.py b/PyTorch/contrib/cv/classification/DnCNN/utils.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Efficient-3DCNNs_ID1230_for_PyTorch/modelzoo_level.txt b/PyTorch/contrib/cv/classification/Efficient-3DCNNs_ID1230_for_PyTorch/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/classification/Efficient-3DCNNs_ID1230_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/Efficient-3DCNNs_ID1230_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/ImageNet_val_split.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/ImageNet_val_split.py index 60d468b73e666df16329511c05fec52b730c8fca..31376e467a15774fb37fc01bad22e8e2b9e66796 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/ImageNet_val_split.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/ImageNet_val_split.py @@ -1,61 +1,61 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import sys -import os -import scipy -import shutil - - -def move_valimg(val_dir='./val', devkit_dir='./ILSVRC2012_devkit_t12'): - """ - move valimg to correspongding folders. - val_id(start from 1) -> ILSVRC_ID(start from 1) -> WIND - organize like: - /val - /n01440764 - images - /n01443537 - images - ..... - """ - # load synset, val ground truth and val images list - synset = scipy.io.loadmat(os.path.join(devkit_dir, 'data', 'meta.mat')) - - ground_truth = open(os.path.join(devkit_dir, 'data', 'ILSVRC2012_validation_ground_truth.txt')) - lines = ground_truth.readlines() - labels = [int(line[:-1]) for line in lines] - - root, _, filenames = next(os.walk(val_dir)) - for filename in filenames: - # val image name -> ILSVRC ID -> WIND - val_id = int(filename.split('.')[0].split('_')[-1]) - ILSVRC_ID = labels[val_id-1] - WIND = synset['synsets'][ILSVRC_ID-1][0][1][0] - print("val_id:%d, ILSVRC_ID:%d, WIND:%s" % (val_id, ILSVRC_ID, WIND)) - - # move val images - output_dir = os.path.join(root, WIND) - if os.path.isdir(output_dir): - pass - else: - os.mkdir(output_dir) - shutil.move(os.path.join(root, filename), os.path.join(output_dir, filename)) - -def main(val_path, devkit_path): - move_valimg(val_path, devkit_path) - -if __name__ == '__main__': - val_path = sys.argv[1] - devkit_path = sys.argv[2] +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +import os +import scipy +import shutil + + +def move_valimg(val_dir='./val', devkit_dir='./ILSVRC2012_devkit_t12'): + """ + move valimg to correspongding folders. + val_id(start from 1) -> ILSVRC_ID(start from 1) -> WIND + organize like: + /val + /n01440764 + images + /n01443537 + images + ..... + """ + # load synset, val ground truth and val images list + synset = scipy.io.loadmat(os.path.join(devkit_dir, 'data', 'meta.mat')) + + ground_truth = open(os.path.join(devkit_dir, 'data', 'ILSVRC2012_validation_ground_truth.txt')) + lines = ground_truth.readlines() + labels = [int(line[:-1]) for line in lines] + + root, _, filenames = next(os.walk(val_dir)) + for filename in filenames: + # val image name -> ILSVRC ID -> WIND + val_id = int(filename.split('.')[0].split('_')[-1]) + ILSVRC_ID = labels[val_id-1] + WIND = synset['synsets'][ILSVRC_ID-1][0][1][0] + print("val_id:%d, ILSVRC_ID:%d, WIND:%s" % (val_id, ILSVRC_ID, WIND)) + + # move val images + output_dir = os.path.join(root, WIND) + if os.path.isdir(output_dir): + pass + else: + os.mkdir(output_dir) + shutil.move(os.path.join(root, filename), os.path.join(output_dir, filename)) + +def main(val_path, devkit_path): + move_valimg(val_path, devkit_path) + +if __name__ == '__main__': + val_path = sys.argv[1] + devkit_path = sys.argv[2] main(val_path, devkit_path) \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/README.md b/PyTorch/contrib/cv/classification/EfficientNet-B1/README.md index 007a91b9f417fa4bd92d7adbe7bd7c0c862c6580..065d061eb2833c61e3cb58dbdacfcd54d9a2eb0c 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/README.md +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/README.md @@ -1,79 +1,79 @@ -# EfficientNet-B1 - -This implements training of Efficientnet-B1 on the ImageNet dataset, mainly modified from [pycls](https://github.com/facebookresearch/pycls). - -## EfficientNet-B1 Detail - -For details, see[pycls](https://github.com/facebookresearch/pycls). - - -## Requirements - -- Install PyTorch ([pytorch.org](http://pytorch.org)) -- apt install bc -- python3 -m pip install --upgrade Pillow -- git clone https://github.com/facebookresearch/pycls -- pip install -r requirements.txt -- Download the ImageNet2012 dataset - - train set:138GB - val set:6.3GB - ILSVRC2012_devkit_t12:2.45MB - - - Then, and move validation images to labeled subfolders, using ImageNet_val_split.py need download imageNet val and ILSVRC2012_devkit_t12 - - ```python - python3.7 ImageNet_val_split.py ./val ./ILSVRC2012_devkit_t12 - ``` - ``` - move valimg to correspongding folders. - official download the organize like: - /val - images - images - ...... - after the move the organize like: - - /val - /n01440764 - images - /n01443537 - images - ..... - ``` -## Training - -To train a model, run scripts with the desired model architecture and the path to the ImageNet dataset: - -```bash -# 1p training 1p -bash test/train_full_1p.sh --data_path=imageNet_root_path - -# 8p training 8p -bash test/train_full_8p.sh --data_path=imageNet_root_path - -# To ONNX -python3.7 Efficient-B1_pth2onnx.py ./Efficient-b1.onnx - -# eval default 8p, should support 1p -bash test/train_eval_8p.sh --data_path=imageNet_root_path - -# test performer -bash test/train_performance_1p.sh --data_path=imageNet_root_path -bash test/train_performance_8p.sh --data_path=imageNet_root_path - -# online inference demo -python3.7.5 demo.py - -``` - - -## EfficientNet-B1 training result - -| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | -| :----: | :--: | :------: | :----: | :------: | -| - | 451 | 1 | 100 | O2 | -| 74.445 | 2073 | 8 | 100 | O2 | - -FPS = BatchSize * num_devices / time_avg - +# EfficientNet-B1 + +This implements training of Efficientnet-B1 on the ImageNet dataset, mainly modified from [pycls](https://github.com/facebookresearch/pycls). + +## EfficientNet-B1 Detail + +For details, see[pycls](https://github.com/facebookresearch/pycls). + + +## Requirements + +- Install PyTorch ([pytorch.org](http://pytorch.org)) +- apt install bc +- python3 -m pip install --upgrade Pillow +- git clone https://github.com/facebookresearch/pycls +- pip install -r requirements.txt +- Download the ImageNet2012 dataset + + train set:138GB + val set:6.3GB + ILSVRC2012_devkit_t12:2.45MB + + - Then, and move validation images to labeled subfolders, using ImageNet_val_split.py need download imageNet val and ILSVRC2012_devkit_t12 + + ```python + python3.7 ImageNet_val_split.py ./val ./ILSVRC2012_devkit_t12 + ``` + ``` + move valimg to correspongding folders. + official download the organize like: + /val + images + images + ...... + after the move the organize like: + + /val + /n01440764 + images + /n01443537 + images + ..... + ``` +## Training + +To train a model, run scripts with the desired model architecture and the path to the ImageNet dataset: + +```bash +# 1p training 1p +bash test/train_full_1p.sh --data_path=imageNet_root_path + +# 8p training 8p +bash test/train_full_8p.sh --data_path=imageNet_root_path + +# To ONNX +python3.7 Efficient-B1_pth2onnx.py ./Efficient-b1.onnx + +# eval default 8p, should support 1p +bash test/train_eval_8p.sh --data_path=imageNet_root_path + +# test performer +bash test/train_performance_1p.sh --data_path=imageNet_root_path +bash test/train_performance_8p.sh --data_path=imageNet_root_path + +# online inference demo +python3.7.5 demo.py + +``` + + +## EfficientNet-B1 training result + +| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | +| :----: | :--: | :------: | :----: | :------: | +| - | 451 | 1 | 100 | O2 | +| 74.445 | 2073 | 8 | 100 | O2 | + +FPS = BatchSize * num_devices / time_avg + diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/anynet/R-110_nds_1gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/anynet/R-110_nds_1gpu.yaml index 74cdc86425e232c226b4bccf4b03f4531f5977f0..6eadd72f4373320d690aecb3460a2f71c1fcd449 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/anynet/R-110_nds_1gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/anynet/R-110_nds_1gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 10 -ANYNET: - STEM_TYPE: res_stem_cifar - STEM_W: 16 - BLOCK_TYPE: res_basic_block - DEPTHS: [18, 18, 18] - WIDTHS: [16, 32, 64] - STRIDES: [1, 2, 2] -BN: - USE_PRECISE_STATS: True - NUM_SAMPLES_PRECISE: 1024 -OPTIM: - BASE_LR: 0.1 - LR_POLICY: cos - MAX_EPOCH: 200 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0005 -TRAIN: - DATASET: cifar10 - SPLIT: train - BATCH_SIZE: 128 - IM_SIZE: 32 -TEST: - DATASET: cifar10 - SPLIT: test - BATCH_SIZE: 200 - IM_SIZE: 32 -NUM_GPUS: 1 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: False -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 10 +ANYNET: + STEM_TYPE: res_stem_cifar + STEM_W: 16 + BLOCK_TYPE: res_basic_block + DEPTHS: [18, 18, 18] + WIDTHS: [16, 32, 64] + STRIDES: [1, 2, 2] +BN: + USE_PRECISE_STATS: True + NUM_SAMPLES_PRECISE: 1024 +OPTIM: + BASE_LR: 0.1 + LR_POLICY: cos + MAX_EPOCH: 200 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0005 +TRAIN: + DATASET: cifar10 + SPLIT: train + BATCH_SIZE: 128 + IM_SIZE: 32 +TEST: + DATASET: cifar10 + SPLIT: test + BATCH_SIZE: 200 + IM_SIZE: 32 +NUM_GPUS: 1 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: False +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/anynet/R-56_nds_1gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/anynet/R-56_nds_1gpu.yaml index f03502a530fe8be9d545633f16e63c4acd0cc17b..1052cf8da16be2a4561f07c9e946ff82c07bbca1 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/anynet/R-56_nds_1gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/anynet/R-56_nds_1gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 10 -ANYNET: - STEM_TYPE: res_stem_cifar - STEM_W: 16 - BLOCK_TYPE: res_basic_block - DEPTHS: [9, 9, 9] - WIDTHS: [16, 32, 64] - STRIDES: [1, 2, 2] -BN: - USE_PRECISE_STATS: True - NUM_SAMPLES_PRECISE: 1024 -OPTIM: - BASE_LR: 0.1 - LR_POLICY: cos - MAX_EPOCH: 200 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0005 -TRAIN: - DATASET: cifar10 - SPLIT: train - BATCH_SIZE: 128 - IM_SIZE: 32 -TEST: - DATASET: cifar10 - SPLIT: test - BATCH_SIZE: 200 - IM_SIZE: 32 -NUM_GPUS: 1 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: False -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 10 +ANYNET: + STEM_TYPE: res_stem_cifar + STEM_W: 16 + BLOCK_TYPE: res_basic_block + DEPTHS: [9, 9, 9] + WIDTHS: [16, 32, 64] + STRIDES: [1, 2, 2] +BN: + USE_PRECISE_STATS: True + NUM_SAMPLES_PRECISE: 1024 +OPTIM: + BASE_LR: 0.1 + LR_POLICY: cos + MAX_EPOCH: 200 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0005 +TRAIN: + DATASET: cifar10 + SPLIT: train + BATCH_SIZE: 128 + IM_SIZE: 32 +TEST: + DATASET: cifar10 + SPLIT: test + BATCH_SIZE: 200 + IM_SIZE: 32 +NUM_GPUS: 1 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: False +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/anynet/V-56_nds_1gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/anynet/V-56_nds_1gpu.yaml index f360b943e2dd501d5cf0b36af4362e6e5996d173..615da0ba4e90b6f7474ee481eeb324b923f00bfa 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/anynet/V-56_nds_1gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/anynet/V-56_nds_1gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 10 -ANYNET: - STEM_TYPE: res_stem_cifar - STEM_W: 16 - BLOCK_TYPE: vanilla_block - DEPTHS: [9, 9, 9] - WIDTHS: [16, 32, 64] - STRIDES: [1, 2, 2] -BN: - USE_PRECISE_STATS: True - NUM_SAMPLES_PRECISE: 1024 -OPTIM: - BASE_LR: 0.1 - LR_POLICY: cos - MAX_EPOCH: 200 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0005 -TRAIN: - DATASET: cifar10 - SPLIT: train - BATCH_SIZE: 128 - IM_SIZE: 32 -TEST: - DATASET: cifar10 - SPLIT: test - BATCH_SIZE: 200 - IM_SIZE: 32 -NUM_GPUS: 1 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: False -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 10 +ANYNET: + STEM_TYPE: res_stem_cifar + STEM_W: 16 + BLOCK_TYPE: vanilla_block + DEPTHS: [9, 9, 9] + WIDTHS: [16, 32, 64] + STRIDES: [1, 2, 2] +BN: + USE_PRECISE_STATS: True + NUM_SAMPLES_PRECISE: 1024 +OPTIM: + BASE_LR: 0.1 + LR_POLICY: cos + MAX_EPOCH: 200 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0005 +TRAIN: + DATASET: cifar10 + SPLIT: train + BATCH_SIZE: 128 + IM_SIZE: 32 +TEST: + DATASET: cifar10 + SPLIT: test + BATCH_SIZE: 200 + IM_SIZE: 32 +NUM_GPUS: 1 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: False +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/resnet/R-110_nds_1gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/resnet/R-110_nds_1gpu.yaml index b9ba81d33afa469e22de2c4fa78e1a62572fd329..50948cbc4da8f60f493318d44a2f24fa008f9ff2 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/resnet/R-110_nds_1gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/resnet/R-110_nds_1gpu.yaml @@ -1,32 +1,32 @@ -MODEL: - TYPE: resnet - DEPTH: 110 - NUM_CLASSES: 10 -RESNET: - TRANS_FUN: basic_transform -BN: - USE_PRECISE_STATS: True - NUM_SAMPLES_PRECISE: 1024 -OPTIM: - BASE_LR: 0.1 - LR_POLICY: cos - MAX_EPOCH: 200 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0005 -TRAIN: - DATASET: cifar10 - SPLIT: train - BATCH_SIZE: 128 - IM_SIZE: 32 -TEST: - DATASET: cifar10 - SPLIT: test - BATCH_SIZE: 200 - IM_SIZE: 32 -NUM_GPUS: 1 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: False -OUT_DIR: . +MODEL: + TYPE: resnet + DEPTH: 110 + NUM_CLASSES: 10 +RESNET: + TRANS_FUN: basic_transform +BN: + USE_PRECISE_STATS: True + NUM_SAMPLES_PRECISE: 1024 +OPTIM: + BASE_LR: 0.1 + LR_POLICY: cos + MAX_EPOCH: 200 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0005 +TRAIN: + DATASET: cifar10 + SPLIT: train + BATCH_SIZE: 128 + IM_SIZE: 32 +TEST: + DATASET: cifar10 + SPLIT: test + BATCH_SIZE: 200 + IM_SIZE: 32 +NUM_GPUS: 1 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: False +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/resnet/R-56_nds_1gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/resnet/R-56_nds_1gpu.yaml index 8867c9ec3863dd15bf60cbd82160b73e27c4c666..afcf4901cf25efe929b75e9795c85a061680bb6e 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/resnet/R-56_nds_1gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/cifar/resnet/R-56_nds_1gpu.yaml @@ -1,32 +1,32 @@ -MODEL: - TYPE: resnet - DEPTH: 56 - NUM_CLASSES: 10 -RESNET: - TRANS_FUN: basic_transform -BN: - USE_PRECISE_STATS: True - NUM_SAMPLES_PRECISE: 1024 -OPTIM: - BASE_LR: 0.1 - LR_POLICY: cos - MAX_EPOCH: 200 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0005 -TRAIN: - DATASET: cifar10 - SPLIT: train - BATCH_SIZE: 128 - IM_SIZE: 32 -TEST: - DATASET: cifar10 - SPLIT: test - BATCH_SIZE: 200 - IM_SIZE: 32 -NUM_GPUS: 1 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: False -OUT_DIR: . +MODEL: + TYPE: resnet + DEPTH: 56 + NUM_CLASSES: 10 +RESNET: + TRANS_FUN: basic_transform +BN: + USE_PRECISE_STATS: True + NUM_SAMPLES_PRECISE: 1024 +OPTIM: + BASE_LR: 0.1 + LR_POLICY: cos + MAX_EPOCH: 200 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0005 +TRAIN: + DATASET: cifar10 + SPLIT: train + BATCH_SIZE: 128 + IM_SIZE: 32 +TEST: + DATASET: cifar10 + SPLIT: test + BATCH_SIZE: 200 + IM_SIZE: 32 +NUM_GPUS: 1 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: False +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-101-1x64d_step_1gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-101-1x64d_step_1gpu.yaml index cd102977a9c7247f7da7237feb2ab6e3545c45e7..a1c05a9120138e3c1364cca8586adfa270348158 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-101-1x64d_step_1gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-101-1x64d_step_1gpu.yaml @@ -1,39 +1,39 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 1000 -ANYNET: - STEM_TYPE: res_stem_in - STEM_W: 64 - BLOCK_TYPE: res_bottleneck_block - DEPTHS: [3, 4, 23, 3] - WIDTHS: [256, 512, 1024, 2048] - STRIDES: [1, 2, 2, 2] - BOT_MULS: [0.25, 0.25, 0.25, 0.25] - GROUP_WS: [64, 128, 256, 512] -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.0125 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 32 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 25 - IM_SIZE: 256 -NUM_GPUS: 1 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 1000 +ANYNET: + STEM_TYPE: res_stem_in + STEM_W: 64 + BLOCK_TYPE: res_bottleneck_block + DEPTHS: [3, 4, 23, 3] + WIDTHS: [256, 512, 1024, 2048] + STRIDES: [1, 2, 2, 2] + BOT_MULS: [0.25, 0.25, 0.25, 0.25] + GROUP_WS: [64, 128, 256, 512] +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.0125 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 32 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 25 + IM_SIZE: 256 +NUM_GPUS: 1 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-101-1x64d_step_2gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-101-1x64d_step_2gpu.yaml index e372857d2e312963701b27510e2aa09d12c23716..3ce5a54347e8f33209597cc1c175b5c49e5e250c 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-101-1x64d_step_2gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-101-1x64d_step_2gpu.yaml @@ -1,39 +1,39 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 1000 -ANYNET: - STEM_TYPE: res_stem_in - STEM_W: 64 - BLOCK_TYPE: res_bottleneck_block - DEPTHS: [3, 4, 23, 3] - WIDTHS: [256, 512, 1024, 2048] - STRIDES: [1, 2, 2, 2] - BOT_MULS: [0.25, 0.25, 0.25, 0.25] - GROUP_WS: [64, 128, 256, 512] -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.025 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 64 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 50 - IM_SIZE: 256 -NUM_GPUS: 2 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 1000 +ANYNET: + STEM_TYPE: res_stem_in + STEM_W: 64 + BLOCK_TYPE: res_bottleneck_block + DEPTHS: [3, 4, 23, 3] + WIDTHS: [256, 512, 1024, 2048] + STRIDES: [1, 2, 2, 2] + BOT_MULS: [0.25, 0.25, 0.25, 0.25] + GROUP_WS: [64, 128, 256, 512] +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.025 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 64 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 50 + IM_SIZE: 256 +NUM_GPUS: 2 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-101-1x64d_step_8gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-101-1x64d_step_8gpu.yaml index bf6bfa173f592b2f236839601f3f177f2be4782d..688dd1dc3e5e0b8fd33d7d11bca20a4b1a34f3ff 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-101-1x64d_step_8gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-101-1x64d_step_8gpu.yaml @@ -1,39 +1,39 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 1000 -ANYNET: - STEM_TYPE: res_stem_in - STEM_W: 64 - BLOCK_TYPE: res_bottleneck_block - DEPTHS: [3, 4, 23, 3] - WIDTHS: [256, 512, 1024, 2048] - STRIDES: [1, 2, 2, 2] - BOT_MULS: [0.25, 0.25, 0.25, 0.25] - GROUP_WS: [64, 128, 256, 512] -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.1 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 256 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 200 - IM_SIZE: 256 -NUM_GPUS: 8 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 1000 +ANYNET: + STEM_TYPE: res_stem_in + STEM_W: 64 + BLOCK_TYPE: res_bottleneck_block + DEPTHS: [3, 4, 23, 3] + WIDTHS: [256, 512, 1024, 2048] + STRIDES: [1, 2, 2, 2] + BOT_MULS: [0.25, 0.25, 0.25, 0.25] + GROUP_WS: [64, 128, 256, 512] +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.1 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 256 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 200 + IM_SIZE: 256 +NUM_GPUS: 8 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-50-1x64d_step_1gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-50-1x64d_step_1gpu.yaml index 993c43b5f4d28a5fd2772aeeccd99c022d32e6b9..a43a96606da528729c9a9d4a7c4b09daf7be0c40 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-50-1x64d_step_1gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-50-1x64d_step_1gpu.yaml @@ -1,39 +1,39 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 1000 -ANYNET: - STEM_TYPE: res_stem_in - STEM_W: 64 - BLOCK_TYPE: res_bottleneck_block - DEPTHS: [3, 4, 6, 3] - WIDTHS: [256, 512, 1024, 2048] - STRIDES: [1, 2, 2, 2] - BOT_MULS: [0.25, 0.25, 0.25, 0.25] - GROUP_WS: [64, 128, 256, 512] -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.0125 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 32 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 25 - IM_SIZE: 256 -NUM_GPUS: 1 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 1000 +ANYNET: + STEM_TYPE: res_stem_in + STEM_W: 64 + BLOCK_TYPE: res_bottleneck_block + DEPTHS: [3, 4, 6, 3] + WIDTHS: [256, 512, 1024, 2048] + STRIDES: [1, 2, 2, 2] + BOT_MULS: [0.25, 0.25, 0.25, 0.25] + GROUP_WS: [64, 128, 256, 512] +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.0125 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 32 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 25 + IM_SIZE: 256 +NUM_GPUS: 1 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-50-1x64d_step_2gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-50-1x64d_step_2gpu.yaml index 428e4cdb5d873e5e356e67040aca60b290ad0d0e..064992f3a362d22f8638305602cb2e3a4335355c 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-50-1x64d_step_2gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-50-1x64d_step_2gpu.yaml @@ -1,39 +1,39 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 1000 -ANYNET: - STEM_TYPE: res_stem_in - STEM_W: 64 - BLOCK_TYPE: res_bottleneck_block - DEPTHS: [3, 4, 6, 3] - WIDTHS: [256, 512, 1024, 2048] - STRIDES: [1, 2, 2, 2] - BOT_MULS: [0.25, 0.25, 0.25, 0.25] - GROUP_WS: [64, 128, 256, 512] -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.025 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 64 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 50 - IM_SIZE: 256 -NUM_GPUS: 2 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 1000 +ANYNET: + STEM_TYPE: res_stem_in + STEM_W: 64 + BLOCK_TYPE: res_bottleneck_block + DEPTHS: [3, 4, 6, 3] + WIDTHS: [256, 512, 1024, 2048] + STRIDES: [1, 2, 2, 2] + BOT_MULS: [0.25, 0.25, 0.25, 0.25] + GROUP_WS: [64, 128, 256, 512] +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.025 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 64 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 50 + IM_SIZE: 256 +NUM_GPUS: 2 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-50-1x64d_step_8gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-50-1x64d_step_8gpu.yaml index adae774a7400a44c8b41789b910c39ce5448f8f6..abe4b8c9ee2d1a96d2c4a61dcc453702afc6228c 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-50-1x64d_step_8gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/R-50-1x64d_step_8gpu.yaml @@ -1,39 +1,39 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 1000 -ANYNET: - STEM_TYPE: res_stem_in - STEM_W: 64 - BLOCK_TYPE: res_bottleneck_block - DEPTHS: [3, 4, 6, 3] - WIDTHS: [256, 512, 1024, 2048] - STRIDES: [1, 2, 2, 2] - BOT_MULS: [0.25, 0.25, 0.25, 0.25] - GROUP_WS: [64, 128, 256, 512] -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.1 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 256 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 200 - IM_SIZE: 256 -NUM_GPUS: 8 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 1000 +ANYNET: + STEM_TYPE: res_stem_in + STEM_W: 64 + BLOCK_TYPE: res_bottleneck_block + DEPTHS: [3, 4, 6, 3] + WIDTHS: [256, 512, 1024, 2048] + STRIDES: [1, 2, 2, 2] + BOT_MULS: [0.25, 0.25, 0.25, 0.25] + GROUP_WS: [64, 128, 256, 512] +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.1 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 256 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 200 + IM_SIZE: 256 +NUM_GPUS: 8 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-101-32x4d_step_1gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-101-32x4d_step_1gpu.yaml index 845ea5fe30cc70029669b65d6afc7db2e39d20cb..26b7b1f64e10f8d479c8024a8a0220f8412ba092 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-101-32x4d_step_1gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-101-32x4d_step_1gpu.yaml @@ -1,39 +1,39 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 1000 -ANYNET: - STEM_TYPE: res_stem_in - STEM_W: 64 - BLOCK_TYPE: res_bottleneck_block - DEPTHS: [3, 4, 23, 3] - WIDTHS: [256, 512, 1024, 2048] - STRIDES: [1, 2, 2, 2] - BOT_MULS: [0.5, 0.5, 0.5, 0.5] - GROUP_WS: [4, 8, 16, 32] -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.0125 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 32 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 25 - IM_SIZE: 256 -NUM_GPUS: 1 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 1000 +ANYNET: + STEM_TYPE: res_stem_in + STEM_W: 64 + BLOCK_TYPE: res_bottleneck_block + DEPTHS: [3, 4, 23, 3] + WIDTHS: [256, 512, 1024, 2048] + STRIDES: [1, 2, 2, 2] + BOT_MULS: [0.5, 0.5, 0.5, 0.5] + GROUP_WS: [4, 8, 16, 32] +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.0125 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 32 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 25 + IM_SIZE: 256 +NUM_GPUS: 1 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-101-32x4d_step_2gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-101-32x4d_step_2gpu.yaml index c4e15b8dfce21ef578cac98389bc3502c7c1d0df..317b4e88e2a57b9b140a67f6b87cc37818c1e172 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-101-32x4d_step_2gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-101-32x4d_step_2gpu.yaml @@ -1,39 +1,39 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 1000 -ANYNET: - STEM_TYPE: res_stem_in - STEM_W: 64 - BLOCK_TYPE: res_bottleneck_block - DEPTHS: [3, 4, 23, 3] - WIDTHS: [256, 512, 1024, 2048] - STRIDES: [1, 2, 2, 2] - BOT_MULS: [0.5, 0.5, 0.5, 0.5] - GROUP_WS: [4, 8, 16, 32] -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.025 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 64 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 50 - IM_SIZE: 256 -NUM_GPUS: 2 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 1000 +ANYNET: + STEM_TYPE: res_stem_in + STEM_W: 64 + BLOCK_TYPE: res_bottleneck_block + DEPTHS: [3, 4, 23, 3] + WIDTHS: [256, 512, 1024, 2048] + STRIDES: [1, 2, 2, 2] + BOT_MULS: [0.5, 0.5, 0.5, 0.5] + GROUP_WS: [4, 8, 16, 32] +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.025 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 64 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 50 + IM_SIZE: 256 +NUM_GPUS: 2 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-101-32x4d_step_8gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-101-32x4d_step_8gpu.yaml index 8969c2270cedbe3be27faf1163b52d601404f8fc..c4c0ff040b315e034e9b13dedafec704be33f198 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-101-32x4d_step_8gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-101-32x4d_step_8gpu.yaml @@ -1,39 +1,39 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 1000 -ANYNET: - STEM_TYPE: res_stem_in - STEM_W: 64 - BLOCK_TYPE: res_bottleneck_block - DEPTHS: [3, 4, 23, 3] - WIDTHS: [256, 512, 1024, 2048] - STRIDES: [1, 2, 2, 2] - BOT_MULS: [0.5, 0.5, 0.5, 0.5] - GROUP_WS: [4, 8, 16, 32] -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.1 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 256 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 200 - IM_SIZE: 256 -NUM_GPUS: 8 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 1000 +ANYNET: + STEM_TYPE: res_stem_in + STEM_W: 64 + BLOCK_TYPE: res_bottleneck_block + DEPTHS: [3, 4, 23, 3] + WIDTHS: [256, 512, 1024, 2048] + STRIDES: [1, 2, 2, 2] + BOT_MULS: [0.5, 0.5, 0.5, 0.5] + GROUP_WS: [4, 8, 16, 32] +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.1 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 256 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 200 + IM_SIZE: 256 +NUM_GPUS: 8 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-50-32x4d_step_1gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-50-32x4d_step_1gpu.yaml index 042570a12e307ec75824c6fa6e43f29fc41df050..2ad42223567bdd0f20a4290b471a1fed30fea940 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-50-32x4d_step_1gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-50-32x4d_step_1gpu.yaml @@ -1,39 +1,39 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 1000 -ANYNET: - STEM_TYPE: res_stem_in - STEM_W: 64 - BLOCK_TYPE: res_bottleneck_block - DEPTHS: [3, 4, 6, 3] - WIDTHS: [256, 512, 1024, 2048] - STRIDES: [1, 2, 2, 2] - BOT_MULS: [0.5, 0.5, 0.5, 0.5] - GROUP_WS: [4, 8, 16, 32] -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.0125 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 32 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 25 - IM_SIZE: 256 -NUM_GPUS: 1 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 1000 +ANYNET: + STEM_TYPE: res_stem_in + STEM_W: 64 + BLOCK_TYPE: res_bottleneck_block + DEPTHS: [3, 4, 6, 3] + WIDTHS: [256, 512, 1024, 2048] + STRIDES: [1, 2, 2, 2] + BOT_MULS: [0.5, 0.5, 0.5, 0.5] + GROUP_WS: [4, 8, 16, 32] +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.0125 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 32 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 25 + IM_SIZE: 256 +NUM_GPUS: 1 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-50-32x4d_step_2gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-50-32x4d_step_2gpu.yaml index df1123c51d5ca9db8bbe0e41ca527b8976c533bf..a899bb9513d9efeb779131e625647a2ace01231d 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-50-32x4d_step_2gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-50-32x4d_step_2gpu.yaml @@ -1,39 +1,39 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 1000 -ANYNET: - STEM_TYPE: res_stem_in - STEM_W: 64 - BLOCK_TYPE: res_bottleneck_block - DEPTHS: [3, 4, 6, 3] - WIDTHS: [256, 512, 1024, 2048] - STRIDES: [1, 2, 2, 2] - BOT_MULS: [0.5, 0.5, 0.5, 0.5] - GROUP_WS: [4, 8, 16, 32] -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.025 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 64 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 50 - IM_SIZE: 256 -NUM_GPUS: 2 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 1000 +ANYNET: + STEM_TYPE: res_stem_in + STEM_W: 64 + BLOCK_TYPE: res_bottleneck_block + DEPTHS: [3, 4, 6, 3] + WIDTHS: [256, 512, 1024, 2048] + STRIDES: [1, 2, 2, 2] + BOT_MULS: [0.5, 0.5, 0.5, 0.5] + GROUP_WS: [4, 8, 16, 32] +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.025 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 64 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 50 + IM_SIZE: 256 +NUM_GPUS: 2 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-50-32x4d_step_8gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-50-32x4d_step_8gpu.yaml index 9496b464c59c424a4e934d5470b979e367baccef..9746fac79a52a97c6f5227faaef45a6cd8f7f4f0 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-50-32x4d_step_8gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/anynet/X-50-32x4d_step_8gpu.yaml @@ -1,39 +1,39 @@ -MODEL: - TYPE: anynet - NUM_CLASSES: 1000 -ANYNET: - STEM_TYPE: res_stem_in - STEM_W: 64 - BLOCK_TYPE: res_bottleneck_block - DEPTHS: [3, 4, 6, 3] - WIDTHS: [256, 512, 1024, 2048] - STRIDES: [1, 2, 2, 2] - BOT_MULS: [0.5, 0.5, 0.5, 0.5] - GROUP_WS: [4, 8, 16, 32] -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.1 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 256 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 200 - IM_SIZE: 256 -NUM_GPUS: 8 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: anynet + NUM_CLASSES: 1000 +ANYNET: + STEM_TYPE: res_stem_in + STEM_W: 64 + BLOCK_TYPE: res_bottleneck_block + DEPTHS: [3, 4, 6, 3] + WIDTHS: [256, 512, 1024, 2048] + STRIDES: [1, 2, 2, 2] + BOT_MULS: [0.5, 0.5, 0.5, 0.5] + GROUP_WS: [4, 8, 16, 32] +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.1 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 256 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 200 + IM_SIZE: 256 +NUM_GPUS: 8 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-101-1x64d_step_1gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-101-1x64d_step_1gpu.yaml index f8e3c54657dfdbd8d403e65cc3bb114d66c06eac..757d69e49dd0505ebb625218d083d2c2870b618d 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-101-1x64d_step_1gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-101-1x64d_step_1gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: resnet - DEPTH: 101 - NUM_CLASSES: 1000 -RESNET: - TRANS_FUN: bottleneck_transform - NUM_GROUPS: 1 - WIDTH_PER_GROUP: 64 - STRIDE_1X1: False -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.0125 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 32 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 25 - IM_SIZE: 256 -NUM_GPUS: 1 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: resnet + DEPTH: 101 + NUM_CLASSES: 1000 +RESNET: + TRANS_FUN: bottleneck_transform + NUM_GROUPS: 1 + WIDTH_PER_GROUP: 64 + STRIDE_1X1: False +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.0125 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 32 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 25 + IM_SIZE: 256 +NUM_GPUS: 1 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-101-1x64d_step_2gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-101-1x64d_step_2gpu.yaml index c48ce042f083eca2f3e2a516d6c9d10d441d0282..e31acbc14638576c758b9f49074d9f4f899b054b 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-101-1x64d_step_2gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-101-1x64d_step_2gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: resnet - DEPTH: 101 - NUM_CLASSES: 1000 -RESNET: - TRANS_FUN: bottleneck_transform - NUM_GROUPS: 1 - WIDTH_PER_GROUP: 64 - STRIDE_1X1: False -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.025 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 64 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 50 - IM_SIZE: 256 -NUM_GPUS: 2 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: resnet + DEPTH: 101 + NUM_CLASSES: 1000 +RESNET: + TRANS_FUN: bottleneck_transform + NUM_GROUPS: 1 + WIDTH_PER_GROUP: 64 + STRIDE_1X1: False +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.025 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 64 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 50 + IM_SIZE: 256 +NUM_GPUS: 2 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-101-1x64d_step_8gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-101-1x64d_step_8gpu.yaml index 5f6cfa8394ee1f8db440ef2bcb538abeef0af73c..473a15b5fe6fc165b268e0c9e90f788f7617b1e4 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-101-1x64d_step_8gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-101-1x64d_step_8gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: resnet - DEPTH: 101 - NUM_CLASSES: 1000 -RESNET: - TRANS_FUN: bottleneck_transform - NUM_GROUPS: 1 - WIDTH_PER_GROUP: 64 - STRIDE_1X1: False -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.1 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 256 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 200 - IM_SIZE: 256 -NUM_GPUS: 8 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: resnet + DEPTH: 101 + NUM_CLASSES: 1000 +RESNET: + TRANS_FUN: bottleneck_transform + NUM_GROUPS: 1 + WIDTH_PER_GROUP: 64 + STRIDE_1X1: False +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.1 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 256 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 200 + IM_SIZE: 256 +NUM_GPUS: 8 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-50-1x64d_step_1gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-50-1x64d_step_1gpu.yaml index b1c97d7ddc7cdf6e9967a69ce0555493a8b7caba..327e5a59719752e9dace4b16d1fae544c7842c9e 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-50-1x64d_step_1gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-50-1x64d_step_1gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: resnet - DEPTH: 50 - NUM_CLASSES: 1000 -RESNET: - TRANS_FUN: bottleneck_transform - NUM_GROUPS: 1 - WIDTH_PER_GROUP: 64 - STRIDE_1X1: False -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.0125 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 32 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 25 - IM_SIZE: 256 -NUM_GPUS: 1 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: resnet + DEPTH: 50 + NUM_CLASSES: 1000 +RESNET: + TRANS_FUN: bottleneck_transform + NUM_GROUPS: 1 + WIDTH_PER_GROUP: 64 + STRIDE_1X1: False +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.0125 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 32 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 25 + IM_SIZE: 256 +NUM_GPUS: 1 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-50-1x64d_step_2gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-50-1x64d_step_2gpu.yaml index 973c3ffd4ece4bd1f6168831374c0b4f7a18b79d..1278d9c69c0a077b9eb3f3263bd87ce7d46bc468 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-50-1x64d_step_2gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-50-1x64d_step_2gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: resnet - DEPTH: 50 - NUM_CLASSES: 1000 -RESNET: - TRANS_FUN: bottleneck_transform - NUM_GROUPS: 1 - WIDTH_PER_GROUP: 64 - STRIDE_1X1: False -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.025 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 64 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 50 - IM_SIZE: 256 -NUM_GPUS: 2 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: resnet + DEPTH: 50 + NUM_CLASSES: 1000 +RESNET: + TRANS_FUN: bottleneck_transform + NUM_GROUPS: 1 + WIDTH_PER_GROUP: 64 + STRIDE_1X1: False +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.025 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 64 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 50 + IM_SIZE: 256 +NUM_GPUS: 2 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-50-1x64d_step_8gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-50-1x64d_step_8gpu.yaml index fabb4ec183de68a892b40623202801a9cdb1e5e3..e6739d7cab06f01818a3a661e7a751b4f43cd21d 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-50-1x64d_step_8gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/R-50-1x64d_step_8gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: resnet - DEPTH: 50 - NUM_CLASSES: 1000 -RESNET: - TRANS_FUN: bottleneck_transform - NUM_GROUPS: 1 - WIDTH_PER_GROUP: 64 - STRIDE_1X1: False -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.1 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 256 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 200 - IM_SIZE: 256 -NUM_GPUS: 8 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: resnet + DEPTH: 50 + NUM_CLASSES: 1000 +RESNET: + TRANS_FUN: bottleneck_transform + NUM_GROUPS: 1 + WIDTH_PER_GROUP: 64 + STRIDE_1X1: False +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.1 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 256 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 200 + IM_SIZE: 256 +NUM_GPUS: 8 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-101-32x4d_step_1gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-101-32x4d_step_1gpu.yaml index def7d1561f5d5ecd9e1af7a0cf3c9df088694052..91604235f804ea4755ac98a56510781ee3d1c85f 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-101-32x4d_step_1gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-101-32x4d_step_1gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: resnet - DEPTH: 101 - NUM_CLASSES: 1000 -RESNET: - TRANS_FUN: bottleneck_transform - NUM_GROUPS: 32 - WIDTH_PER_GROUP: 4 - STRIDE_1X1: False -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.0125 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 32 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 25 - IM_SIZE: 256 -NUM_GPUS: 1 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: resnet + DEPTH: 101 + NUM_CLASSES: 1000 +RESNET: + TRANS_FUN: bottleneck_transform + NUM_GROUPS: 32 + WIDTH_PER_GROUP: 4 + STRIDE_1X1: False +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.0125 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 32 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 25 + IM_SIZE: 256 +NUM_GPUS: 1 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-101-32x4d_step_2gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-101-32x4d_step_2gpu.yaml index 5b69a7b4e5d28a0f0a2b1c562223ced27bdfc250..f051c81b25470e8b52389a1db3e2baf9305a105d 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-101-32x4d_step_2gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-101-32x4d_step_2gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: resnet - DEPTH: 101 - NUM_CLASSES: 1000 -RESNET: - TRANS_FUN: bottleneck_transform - NUM_GROUPS: 32 - WIDTH_PER_GROUP: 4 - STRIDE_1X1: False -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.025 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 64 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 50 - IM_SIZE: 256 -NUM_GPUS: 2 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: resnet + DEPTH: 101 + NUM_CLASSES: 1000 +RESNET: + TRANS_FUN: bottleneck_transform + NUM_GROUPS: 32 + WIDTH_PER_GROUP: 4 + STRIDE_1X1: False +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.025 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 64 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 50 + IM_SIZE: 256 +NUM_GPUS: 2 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-101-32x4d_step_8gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-101-32x4d_step_8gpu.yaml index 60bcd42800929bd86469e0b27edda23d351f9578..c34fedbb03e1aaa8331b854284c1b40d221cc8b7 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-101-32x4d_step_8gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-101-32x4d_step_8gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: resnet - DEPTH: 101 - NUM_CLASSES: 1000 -RESNET: - TRANS_FUN: bottleneck_transform - NUM_GROUPS: 32 - WIDTH_PER_GROUP: 4 - STRIDE_1X1: False -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.1 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 256 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 200 - IM_SIZE: 256 -NUM_GPUS: 8 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: resnet + DEPTH: 101 + NUM_CLASSES: 1000 +RESNET: + TRANS_FUN: bottleneck_transform + NUM_GROUPS: 32 + WIDTH_PER_GROUP: 4 + STRIDE_1X1: False +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.1 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 256 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 200 + IM_SIZE: 256 +NUM_GPUS: 8 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-50-32x4d_step_1gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-50-32x4d_step_1gpu.yaml index a0449e8d8abbba4f94a0d29e87c61e3a1bab7fb4..130b619512cf483b3b0906b0bbd3584d641938a0 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-50-32x4d_step_1gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-50-32x4d_step_1gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: resnet - DEPTH: 50 - NUM_CLASSES: 1000 -RESNET: - TRANS_FUN: bottleneck_transform - NUM_GROUPS: 32 - WIDTH_PER_GROUP: 4 - STRIDE_1X1: False -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.0125 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 32 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 25 - IM_SIZE: 256 -NUM_GPUS: 1 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: resnet + DEPTH: 50 + NUM_CLASSES: 1000 +RESNET: + TRANS_FUN: bottleneck_transform + NUM_GROUPS: 32 + WIDTH_PER_GROUP: 4 + STRIDE_1X1: False +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.0125 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 32 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 25 + IM_SIZE: 256 +NUM_GPUS: 1 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-50-32x4d_step_2gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-50-32x4d_step_2gpu.yaml index 717365d00f1688bc1c5d59a0d7010a19905448e2..621d9f3a72e6e46debb31e1572f8ce186474cecf 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-50-32x4d_step_2gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-50-32x4d_step_2gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: resnet - DEPTH: 50 - NUM_CLASSES: 1000 -RESNET: - TRANS_FUN: bottleneck_transform - NUM_GROUPS: 32 - WIDTH_PER_GROUP: 4 - STRIDE_1X1: False -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.025 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 64 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 50 - IM_SIZE: 256 -NUM_GPUS: 2 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: resnet + DEPTH: 50 + NUM_CLASSES: 1000 +RESNET: + TRANS_FUN: bottleneck_transform + NUM_GROUPS: 32 + WIDTH_PER_GROUP: 4 + STRIDE_1X1: False +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.025 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 64 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 50 + IM_SIZE: 256 +NUM_GPUS: 2 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-50-32x4d_step_8gpu.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-50-32x4d_step_8gpu.yaml index 14cac7547c10f78ccaf3c19e6fe6c335a668242b..2a64873219a9ca75ebad4b29e420875d04805f7b 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-50-32x4d_step_8gpu.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/archive/imagenet/resnet/X-50-32x4d_step_8gpu.yaml @@ -1,36 +1,36 @@ -MODEL: - TYPE: resnet - DEPTH: 50 - NUM_CLASSES: 1000 -RESNET: - TRANS_FUN: bottleneck_transform - NUM_GROUPS: 32 - WIDTH_PER_GROUP: 4 - STRIDE_1X1: False -BN: - ZERO_INIT_FINAL_GAMMA: True -OPTIM: - BASE_LR: 0.1 - LR_POLICY: steps - STEPS: [0, 30, 60, 90] - LR_MULT: 0.1 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - NESTEROV: True - WEIGHT_DECAY: 0.0001 -TRAIN: - DATASET: imagenet - SPLIT: train - BATCH_SIZE: 256 - IM_SIZE: 224 -TEST: - DATASET: imagenet - SPLIT: val - BATCH_SIZE: 200 - IM_SIZE: 256 -NUM_GPUS: 8 -DATA_LOADER: - NUM_WORKERS: 4 -CUDNN: - BENCHMARK: True -OUT_DIR: . +MODEL: + TYPE: resnet + DEPTH: 50 + NUM_CLASSES: 1000 +RESNET: + TRANS_FUN: bottleneck_transform + NUM_GROUPS: 32 + WIDTH_PER_GROUP: 4 + STRIDE_1X1: False +BN: + ZERO_INIT_FINAL_GAMMA: True +OPTIM: + BASE_LR: 0.1 + LR_POLICY: steps + STEPS: [0, 30, 60, 90] + LR_MULT: 0.1 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + NESTEROV: True + WEIGHT_DECAY: 0.0001 +TRAIN: + DATASET: imagenet + SPLIT: train + BATCH_SIZE: 256 + IM_SIZE: 224 +TEST: + DATASET: imagenet + SPLIT: val + BATCH_SIZE: 200 + IM_SIZE: 256 +NUM_GPUS: 8 +DATA_LOADER: + NUM_WORKERS: 4 +CUDNN: + BENCHMARK: True +OUT_DIR: . diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_1npu_full.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_1npu_full.yaml index c8580e9cccdd7011faabb2106c8f9d40ad032ad6..973db49bdc297ba4af8d70e05cdfc5b7ceb17c38 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_1npu_full.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_1npu_full.yaml @@ -1,28 +1,28 @@ -MODEL: - TYPE: effnet - NUM_CLASSES: 1000 - ACTIVATION_FUN: silu -EN: - STEM_W: 32 - STRIDES: [1, 2, 2, 2, 1, 2, 1] - DEPTHS: [2, 3, 3, 4, 4, 5, 2] - WIDTHS: [16, 24, 40, 80, 112, 192, 320] - EXP_RATIOS: [1, 6, 6, 6, 6, 6, 6] - KERNELS: [3, 3, 5, 3, 5, 5, 3] - HEAD_W: 1280 -OPTIM: - LR_POLICY: cos - BASE_LR: 0.4 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - WEIGHT_DECAY: 1e-5 -TRAIN: - DATASET: imagenet - IM_SIZE: 240 - BATCH_SIZE: 256 -TEST: - DATASET: imagenet - IM_SIZE: 274 - BATCH_SIZE: 200 -NUM_GPUS: 1 +MODEL: + TYPE: effnet + NUM_CLASSES: 1000 + ACTIVATION_FUN: silu +EN: + STEM_W: 32 + STRIDES: [1, 2, 2, 2, 1, 2, 1] + DEPTHS: [2, 3, 3, 4, 4, 5, 2] + WIDTHS: [16, 24, 40, 80, 112, 192, 320] + EXP_RATIOS: [1, 6, 6, 6, 6, 6, 6] + KERNELS: [3, 3, 5, 3, 5, 5, 3] + HEAD_W: 1280 +OPTIM: + LR_POLICY: cos + BASE_LR: 0.4 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + WEIGHT_DECAY: 1e-5 +TRAIN: + DATASET: imagenet + IM_SIZE: 240 + BATCH_SIZE: 256 +TEST: + DATASET: imagenet + IM_SIZE: 274 + BATCH_SIZE: 200 +NUM_GPUS: 1 OUT_DIR: . \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_1npu_perf.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_1npu_perf.yaml index 33497cb51cec09825ecf17779e482ce770932f81..1cd1550453a8750b46c2d81ee62cde95aae888f7 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_1npu_perf.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_1npu_perf.yaml @@ -1,28 +1,28 @@ -MODEL: - TYPE: effnet - NUM_CLASSES: 1000 - ACTIVATION_FUN: silu -EN: - STEM_W: 32 - STRIDES: [1, 2, 2, 2, 1, 2, 1] - DEPTHS: [2, 3, 3, 4, 4, 5, 2] - WIDTHS: [16, 24, 40, 80, 112, 192, 320] - EXP_RATIOS: [1, 6, 6, 6, 6, 6, 6] - KERNELS: [3, 3, 5, 3, 5, 5, 3] - HEAD_W: 1280 -OPTIM: - LR_POLICY: cos - BASE_LR: 0.4 - MAX_EPOCH: 1 - MOMENTUM: 0.9 - WEIGHT_DECAY: 1e-5 -TRAIN: - DATASET: imagenet - IM_SIZE: 240 - BATCH_SIZE: 256 -TEST: - DATASET: imagenet - IM_SIZE: 274 - BATCH_SIZE: 200 -NUM_GPUS: 1 +MODEL: + TYPE: effnet + NUM_CLASSES: 1000 + ACTIVATION_FUN: silu +EN: + STEM_W: 32 + STRIDES: [1, 2, 2, 2, 1, 2, 1] + DEPTHS: [2, 3, 3, 4, 4, 5, 2] + WIDTHS: [16, 24, 40, 80, 112, 192, 320] + EXP_RATIOS: [1, 6, 6, 6, 6, 6, 6] + KERNELS: [3, 3, 5, 3, 5, 5, 3] + HEAD_W: 1280 +OPTIM: + LR_POLICY: cos + BASE_LR: 0.4 + MAX_EPOCH: 1 + MOMENTUM: 0.9 + WEIGHT_DECAY: 1e-5 +TRAIN: + DATASET: imagenet + IM_SIZE: 240 + BATCH_SIZE: 256 +TEST: + DATASET: imagenet + IM_SIZE: 274 + BATCH_SIZE: 200 +NUM_GPUS: 1 OUT_DIR: . \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_8npu_full.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_8npu_full.yaml index 989ace38859db0ef9047331e2ebb0e5cd808a82f..22bbe5937e28e0e1c75890b26da438f6a74a1daf 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_8npu_full.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_8npu_full.yaml @@ -1,28 +1,28 @@ -MODEL: - TYPE: effnet - NUM_CLASSES: 1000 - ACTIVATION_FUN: silu -EN: - STEM_W: 32 - STRIDES: [1, 2, 2, 2, 1, 2, 1] - DEPTHS: [2, 3, 3, 4, 4, 5, 2] - WIDTHS: [16, 24, 40, 80, 112, 192, 320] - EXP_RATIOS: [1, 6, 6, 6, 6, 6, 6] - KERNELS: [3, 3, 5, 3, 5, 5, 3] - HEAD_W: 1280 -OPTIM: - LR_POLICY: cos - BASE_LR: 0.4 - MAX_EPOCH: 100 - MOMENTUM: 0.9 - WEIGHT_DECAY: 1e-5 -TRAIN: - DATASET: imagenet - IM_SIZE: 240 - BATCH_SIZE: 1280 -TEST: - DATASET: imagenet - IM_SIZE: 274 - BATCH_SIZE: 800 -NUM_GPUS: 8 +MODEL: + TYPE: effnet + NUM_CLASSES: 1000 + ACTIVATION_FUN: silu +EN: + STEM_W: 32 + STRIDES: [1, 2, 2, 2, 1, 2, 1] + DEPTHS: [2, 3, 3, 4, 4, 5, 2] + WIDTHS: [16, 24, 40, 80, 112, 192, 320] + EXP_RATIOS: [1, 6, 6, 6, 6, 6, 6] + KERNELS: [3, 3, 5, 3, 5, 5, 3] + HEAD_W: 1280 +OPTIM: + LR_POLICY: cos + BASE_LR: 0.4 + MAX_EPOCH: 100 + MOMENTUM: 0.9 + WEIGHT_DECAY: 1e-5 +TRAIN: + DATASET: imagenet + IM_SIZE: 240 + BATCH_SIZE: 1280 +TEST: + DATASET: imagenet + IM_SIZE: 274 + BATCH_SIZE: 800 +NUM_GPUS: 8 OUT_DIR: . \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_8npu_perf.yaml b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_8npu_perf.yaml index 434bdc23b408510d813f447912dbe98fb2cf624d..91530e4977703ce226dac114a421d26ea793e1e2 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_8npu_perf.yaml +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/configs/dds_baselines/effnet/EN-B1_dds_8npu_perf.yaml @@ -1,28 +1,28 @@ -MODEL: - TYPE: effnet - NUM_CLASSES: 1000 - ACTIVATION_FUN: silu -EN: - STEM_W: 32 - STRIDES: [1, 2, 2, 2, 1, 2, 1] - DEPTHS: [2, 3, 3, 4, 4, 5, 2] - WIDTHS: [16, 24, 40, 80, 112, 192, 320] - EXP_RATIOS: [1, 6, 6, 6, 6, 6, 6] - KERNELS: [3, 3, 5, 3, 5, 5, 3] - HEAD_W: 1280 -OPTIM: - LR_POLICY: cos - BASE_LR: 0.4 - MAX_EPOCH: 1 - MOMENTUM: 0.9 - WEIGHT_DECAY: 1e-5 -TRAIN: - DATASET: imagenet - IM_SIZE: 240 - BATCH_SIZE: 1280 -TEST: - DATASET: imagenet - IM_SIZE: 274 - BATCH_SIZE: 800 -NUM_GPUS: 8 +MODEL: + TYPE: effnet + NUM_CLASSES: 1000 + ACTIVATION_FUN: silu +EN: + STEM_W: 32 + STRIDES: [1, 2, 2, 2, 1, 2, 1] + DEPTHS: [2, 3, 3, 4, 4, 5, 2] + WIDTHS: [16, 24, 40, 80, 112, 192, 320] + EXP_RATIOS: [1, 6, 6, 6, 6, 6, 6] + KERNELS: [3, 3, 5, 3, 5, 5, 3] + HEAD_W: 1280 +OPTIM: + LR_POLICY: cos + BASE_LR: 0.4 + MAX_EPOCH: 1 + MOMENTUM: 0.9 + WEIGHT_DECAY: 1e-5 +TRAIN: + DATASET: imagenet + IM_SIZE: 240 + BATCH_SIZE: 1280 +TEST: + DATASET: imagenet + IM_SIZE: 274 + BATCH_SIZE: 800 +NUM_GPUS: 8 OUT_DIR: . \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/demo.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/demo.py index ffbbd4b77787faf9f39714d487dd699455da4366..dcfc3292a779d8e192e5eda5178e969bdf5e5d82 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/demo.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/demo.py @@ -1,64 +1,64 @@ -#!/usr/bin/env python3 -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import numpy as np -import pycls.core.config as config -from pycls.core.config import cfg -import pycls.datasets.transforms as transforms -from pycls.models.effnet import EffNet - - -def build_model(): - config.merge_from_file('configs/dds_baselines/effnet/EN-B1_dds_8npu.yaml') - cfg.freeze() - model = EffNet() - checkpoint = torch.load('result/model.pyth') - model.load_state_dict(checkpoint["model_state"], False) - model.eval() - return model - - -def get_raw_data(): - from PIL import Image - from urllib.request import urlretrieve - IMAGE_URL = 'https://bbs-img.huaweicloud.com/blogs/img/thumb/1591951315139_8989_1363.png' - urlretrieve(IMAGE_URL, 'tmp.jpg') - img = Image.open("tmp.jpg") - img = img.convert('RGB') - return img - - -def pre_process(raw_data): - from torchvision import transforms - normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], - std=[0.229, 0.224, 0.225]) - transforms_list = transforms.Compose([ - transforms.Resize(274), - transforms.CenterCrop(240), - transforms.ToTensor(), - normalize - ]) - input_data = transforms_list(raw_data) - return input_data.unsqueeze(0) - - -if __name__ == '__main__': - raw_data = get_raw_data() - model = build_model() - input_tensor = pre_process(raw_data) - output_tensor = model(input_tensor) - _, pred = output_tensor.topk(1, 1, True, True) +#!/usr/bin/env python3 +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import numpy as np +import pycls.core.config as config +from pycls.core.config import cfg +import pycls.datasets.transforms as transforms +from pycls.models.effnet import EffNet + + +def build_model(): + config.merge_from_file('configs/dds_baselines/effnet/EN-B1_dds_8npu.yaml') + cfg.freeze() + model = EffNet() + checkpoint = torch.load('result/model.pyth') + model.load_state_dict(checkpoint["model_state"], False) + model.eval() + return model + + +def get_raw_data(): + from PIL import Image + from urllib.request import urlretrieve + IMAGE_URL = 'https://bbs-img.huaweicloud.com/blogs/img/thumb/1591951315139_8989_1363.png' + urlretrieve(IMAGE_URL, 'tmp.jpg') + img = Image.open("tmp.jpg") + img = img.convert('RGB') + return img + + +def pre_process(raw_data): + from torchvision import transforms + normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]) + transforms_list = transforms.Compose([ + transforms.Resize(274), + transforms.CenterCrop(240), + transforms.ToTensor(), + normalize + ]) + input_data = transforms_list(raw_data) + return input_data.unsqueeze(0) + + +if __name__ == '__main__': + raw_data = get_raw_data() + model = build_model() + input_tensor = pre_process(raw_data) + output_tensor = model(input_tensor) + _, pred = output_tensor.topk(1, 1, True, True) print("class: ", pred[0][0].item()) \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/benchmark.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/benchmark.py index 25b78e5cad331b4db212445ff82eede950081817..cbad8985085771a741762f428dc01fc81cdc4091 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/benchmark.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/benchmark.py @@ -1,167 +1,167 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - - -"""Benchmarking functions.""" - -import pycls.core.logging as logging -import pycls.core.net as net -import pycls.datasets.loader as loader -import torch -from apex import amp -from pycls.core.config import cfg -from pycls.core.timer import Timer -import pycls.core.optimizer as optim -import torch.npu - -logger = logging.get_logger(__name__) - - -@torch.no_grad() -def compute_time_eval(model): - """Computes precise model forward test time using dummy data.""" - # Use eval mode - model.eval() - # Generate a dummy mini-batch and copy data to GPU - im_size, batch_size = cfg.TRAIN.IM_SIZE, int(cfg.TEST.BATCH_SIZE / cfg.NUM_GPUS) - #inputs = torch.zeros(batch_size, 3, im_size, im_size).cuda(non_blocking=False) - inputs = torch.zeros(batch_size, 3, im_size, im_size).npu() - inputs = inputs.to(non_blocking=False) - # Compute precise forward pass time - timer = Timer() - total_iter = cfg.PREC_TIME.NUM_ITER + cfg.PREC_TIME.WARMUP_ITER - for cur_iter in range(total_iter): - # Reset the timers after the warmup phase - if cur_iter == cfg.PREC_TIME.WARMUP_ITER: - timer.reset() - # Forward - timer.tic() - model(inputs) - torch.npu.synchronize() - timer.toc() - return timer.average_time - - -def compute_time_train(model, loss_fun): - """Computes precise model forward + backward time using dummy data.""" - # Use train mode - model.train() - # Generate a dummy mini-batch and copy data to GPU - im_size, batch_size = cfg.TRAIN.IM_SIZE, int(cfg.TRAIN.BATCH_SIZE / cfg.NUM_GPUS) - inputs = torch.rand(batch_size, 3, im_size, im_size).npu() - inputs = inputs.to(non_blocking=False) - labels = torch.zeros(batch_size, dtype=torch.int32) - labels_one_hot = net.smooth_one_hot_labels(labels) - labels_one_hot = labels_one_hot.npu() - labels_one_hot = labels_one_hot.to(non_blocking=False) - # Cache BatchNorm2D running stats - bns = [m for m in model.modules() if isinstance(m, torch.nn.BatchNorm2d)] - bn_stats = [[bn.running_mean.clone(), bn.running_var.clone()] for bn in bns] - # Create a GradScaler for mixed precision training - #scaler = ApexScaler() - # Compute precise forward backward pass time - fw_timer, bw_timer = Timer(), Timer() - total_iter = cfg.PREC_TIME.NUM_ITER + cfg.PREC_TIME.WARMUP_ITER - for cur_iter in range(total_iter): - # Reset the timers after the warmup phase - if cur_iter == cfg.PREC_TIME.WARMUP_ITER: - fw_timer.reset() - bw_timer.reset() - # Forward - fw_timer.tic() - preds = model(inputs) - loss = loss_fun(preds, labels_one_hot) - torch.npu.synchronize() - fw_timer.toc() - # Backward - bw_timer.tic() - loss.backward() - torch.npu.synchronize() - bw_timer.toc() - # Restore BatchNorm2D running stats - for bn, (mean, var) in zip(bns, bn_stats): - bn.running_mean, bn.running_var = mean, var - return fw_timer.average_time, bw_timer.average_time - - -def compute_time_loader(data_loader): - """Computes loader time.""" - timer = Timer() - loader.shuffle(data_loader, 0) - data_loader_iterator = iter(data_loader) - total_iter = cfg.PREC_TIME.NUM_ITER + cfg.PREC_TIME.WARMUP_ITER - total_iter = min(total_iter, len(data_loader)) - for cur_iter in range(total_iter): - if cur_iter == cfg.PREC_TIME.WARMUP_ITER: - timer.reset() - timer.tic() - next(data_loader_iterator) - timer.toc() - return timer.average_time - - -def compute_time_model(model, loss_fun): - """Times model.""" - logger.info("Computing model timings only...") - # Compute timings - test_fw_time = compute_time_eval(model) - train_fw_time, train_bw_time = compute_time_train(model, loss_fun) - train_fw_bw_time = train_fw_time + train_bw_time - # Output iter timing - iter_times = { - "test_fw_time": test_fw_time, - "train_fw_time": train_fw_time, - "train_bw_time": train_bw_time, - "train_fw_bw_time": train_fw_bw_time, - } - logger.info(logging.dump_log_data(iter_times, "iter_times")) - - -def compute_time_full(model, loss_fun, train_loader, test_loader): - """Times model and data loader.""" - logger.info("Computing model and loader timings...") - # Compute timings - test_fw_time = compute_time_eval(model) - train_fw_time, train_bw_time = compute_time_train(model, loss_fun) - train_fw_bw_time = train_fw_time + train_bw_time - train_loader_time = compute_time_loader(train_loader) - # Output iter timing - iter_times = { - "test_fw_time": test_fw_time, - "train_fw_time": train_fw_time, - "train_bw_time": train_bw_time, - "train_fw_bw_time": train_fw_bw_time, - "train_loader_time": train_loader_time, - } - logger.info(logging.dump_log_data(iter_times, "iter_times")) - # Output epoch timing - epoch_times = { - "test_fw_time": test_fw_time * len(test_loader), - "train_fw_time": train_fw_time * len(train_loader), - "train_bw_time": train_bw_time * len(train_loader), - "train_fw_bw_time": train_fw_bw_time * len(train_loader), - "train_loader_time": train_loader_time * len(train_loader), - } - logger.info(logging.dump_log_data(epoch_times, "epoch_times")) - # Compute data loader overhead (assuming DATA_LOADER.NUM_WORKERS>1) - overhead = max(0, train_loader_time - train_fw_bw_time) / train_fw_bw_time - logger.info("Overhead of data loader is {:.2f}%".format(overhead * 100)) +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + + +"""Benchmarking functions.""" + +import pycls.core.logging as logging +import pycls.core.net as net +import pycls.datasets.loader as loader +import torch +from apex import amp +from pycls.core.config import cfg +from pycls.core.timer import Timer +import pycls.core.optimizer as optim +import torch.npu + +logger = logging.get_logger(__name__) + + +@torch.no_grad() +def compute_time_eval(model): + """Computes precise model forward test time using dummy data.""" + # Use eval mode + model.eval() + # Generate a dummy mini-batch and copy data to GPU + im_size, batch_size = cfg.TRAIN.IM_SIZE, int(cfg.TEST.BATCH_SIZE / cfg.NUM_GPUS) + #inputs = torch.zeros(batch_size, 3, im_size, im_size).cuda(non_blocking=False) + inputs = torch.zeros(batch_size, 3, im_size, im_size).npu() + inputs = inputs.to(non_blocking=False) + # Compute precise forward pass time + timer = Timer() + total_iter = cfg.PREC_TIME.NUM_ITER + cfg.PREC_TIME.WARMUP_ITER + for cur_iter in range(total_iter): + # Reset the timers after the warmup phase + if cur_iter == cfg.PREC_TIME.WARMUP_ITER: + timer.reset() + # Forward + timer.tic() + model(inputs) + torch.npu.synchronize() + timer.toc() + return timer.average_time + + +def compute_time_train(model, loss_fun): + """Computes precise model forward + backward time using dummy data.""" + # Use train mode + model.train() + # Generate a dummy mini-batch and copy data to GPU + im_size, batch_size = cfg.TRAIN.IM_SIZE, int(cfg.TRAIN.BATCH_SIZE / cfg.NUM_GPUS) + inputs = torch.rand(batch_size, 3, im_size, im_size).npu() + inputs = inputs.to(non_blocking=False) + labels = torch.zeros(batch_size, dtype=torch.int32) + labels_one_hot = net.smooth_one_hot_labels(labels) + labels_one_hot = labels_one_hot.npu() + labels_one_hot = labels_one_hot.to(non_blocking=False) + # Cache BatchNorm2D running stats + bns = [m for m in model.modules() if isinstance(m, torch.nn.BatchNorm2d)] + bn_stats = [[bn.running_mean.clone(), bn.running_var.clone()] for bn in bns] + # Create a GradScaler for mixed precision training + #scaler = ApexScaler() + # Compute precise forward backward pass time + fw_timer, bw_timer = Timer(), Timer() + total_iter = cfg.PREC_TIME.NUM_ITER + cfg.PREC_TIME.WARMUP_ITER + for cur_iter in range(total_iter): + # Reset the timers after the warmup phase + if cur_iter == cfg.PREC_TIME.WARMUP_ITER: + fw_timer.reset() + bw_timer.reset() + # Forward + fw_timer.tic() + preds = model(inputs) + loss = loss_fun(preds, labels_one_hot) + torch.npu.synchronize() + fw_timer.toc() + # Backward + bw_timer.tic() + loss.backward() + torch.npu.synchronize() + bw_timer.toc() + # Restore BatchNorm2D running stats + for bn, (mean, var) in zip(bns, bn_stats): + bn.running_mean, bn.running_var = mean, var + return fw_timer.average_time, bw_timer.average_time + + +def compute_time_loader(data_loader): + """Computes loader time.""" + timer = Timer() + loader.shuffle(data_loader, 0) + data_loader_iterator = iter(data_loader) + total_iter = cfg.PREC_TIME.NUM_ITER + cfg.PREC_TIME.WARMUP_ITER + total_iter = min(total_iter, len(data_loader)) + for cur_iter in range(total_iter): + if cur_iter == cfg.PREC_TIME.WARMUP_ITER: + timer.reset() + timer.tic() + next(data_loader_iterator) + timer.toc() + return timer.average_time + + +def compute_time_model(model, loss_fun): + """Times model.""" + logger.info("Computing model timings only...") + # Compute timings + test_fw_time = compute_time_eval(model) + train_fw_time, train_bw_time = compute_time_train(model, loss_fun) + train_fw_bw_time = train_fw_time + train_bw_time + # Output iter timing + iter_times = { + "test_fw_time": test_fw_time, + "train_fw_time": train_fw_time, + "train_bw_time": train_bw_time, + "train_fw_bw_time": train_fw_bw_time, + } + logger.info(logging.dump_log_data(iter_times, "iter_times")) + + +def compute_time_full(model, loss_fun, train_loader, test_loader): + """Times model and data loader.""" + logger.info("Computing model and loader timings...") + # Compute timings + test_fw_time = compute_time_eval(model) + train_fw_time, train_bw_time = compute_time_train(model, loss_fun) + train_fw_bw_time = train_fw_time + train_bw_time + train_loader_time = compute_time_loader(train_loader) + # Output iter timing + iter_times = { + "test_fw_time": test_fw_time, + "train_fw_time": train_fw_time, + "train_bw_time": train_bw_time, + "train_fw_bw_time": train_fw_bw_time, + "train_loader_time": train_loader_time, + } + logger.info(logging.dump_log_data(iter_times, "iter_times")) + # Output epoch timing + epoch_times = { + "test_fw_time": test_fw_time * len(test_loader), + "train_fw_time": train_fw_time * len(train_loader), + "train_bw_time": train_bw_time * len(train_loader), + "train_fw_bw_time": train_fw_bw_time * len(train_loader), + "train_loader_time": train_loader_time * len(train_loader), + } + logger.info(logging.dump_log_data(epoch_times, "epoch_times")) + # Compute data loader overhead (assuming DATA_LOADER.NUM_WORKERS>1) + overhead = max(0, train_loader_time - train_fw_bw_time) / train_fw_bw_time + logger.info("Overhead of data loader is {:.2f}%".format(overhead * 100)) diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/builders.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/builders.py index 8e2688e96a50b44e16e6d8f4eb49e2c411ec303b..a40983713d02bd2e981f76fbc5f3479986ddde87 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/builders.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/builders.py @@ -1,68 +1,68 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -"""Model and loss construction functions.""" - -from pycls.core.config import cfg -from pycls.core.net import SoftCrossEntropyLoss -from pycls.models.effnet import EffNet - - -# Supported models -_models = {"effnet": EffNet} - -# Supported loss functions -_loss_funs = {"cross_entropy": SoftCrossEntropyLoss} - - -def get_model(): - """Gets the model class specified in the config.""" - err_str = "Model type '{}' not supported" - assert cfg.MODEL.TYPE in _models.keys(), err_str.format(cfg.MODEL.TYPE) - return _models[cfg.MODEL.TYPE] - - -def get_loss_fun(): - """Gets the loss function class specified in the config.""" - err_str = "Loss function type '{}' not supported" - assert cfg.MODEL.LOSS_FUN in _loss_funs.keys(), err_str.format(cfg.TRAIN.LOSS) - return _loss_funs[cfg.MODEL.LOSS_FUN] - - -def build_model(): - """Builds the model.""" - return get_model()() - - -def build_loss_fun(): - """Build the loss function.""" - return get_loss_fun()() - - -def register_model(name, ctor): - """Registers a model dynamically.""" - _models[name] = ctor - - -def register_loss_fun(name, ctor): - """Registers a loss function dynamically.""" - _loss_funs[name] = ctor +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +"""Model and loss construction functions.""" + +from pycls.core.config import cfg +from pycls.core.net import SoftCrossEntropyLoss +from pycls.models.effnet import EffNet + + +# Supported models +_models = {"effnet": EffNet} + +# Supported loss functions +_loss_funs = {"cross_entropy": SoftCrossEntropyLoss} + + +def get_model(): + """Gets the model class specified in the config.""" + err_str = "Model type '{}' not supported" + assert cfg.MODEL.TYPE in _models.keys(), err_str.format(cfg.MODEL.TYPE) + return _models[cfg.MODEL.TYPE] + + +def get_loss_fun(): + """Gets the loss function class specified in the config.""" + err_str = "Loss function type '{}' not supported" + assert cfg.MODEL.LOSS_FUN in _loss_funs.keys(), err_str.format(cfg.TRAIN.LOSS) + return _loss_funs[cfg.MODEL.LOSS_FUN] + + +def build_model(): + """Builds the model.""" + return get_model()() + + +def build_loss_fun(): + """Build the loss function.""" + return get_loss_fun()() + + +def register_model(name, ctor): + """Registers a model dynamically.""" + _models[name] = ctor + + +def register_loss_fun(name, ctor): + """Registers a loss function dynamically.""" + _loss_funs[name] = ctor diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/distributed.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/distributed.py index 55a6652b47b65a7cf1855bca2d84428995b24249..3eb1dc083b9bb3935f6ebbd549c71bf328b579f3 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/distributed.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/distributed.py @@ -1,186 +1,186 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -"""Distributed helpers.""" - -import multiprocessing -import os -import random -import signal -import threading -import traceback -import torch.npu -import torch -from pycls.core.config import cfg - - -# Make work w recent PyTorch versions (https://github.com/pytorch/pytorch/issues/37377) -os.environ["MKL_THREADING_LAYER"] = "GNU" - - -def is_master_proc(): - """Determines if the current process is the master process. - - Master process is responsible for logging, writing and loading checkpoints. In - the multi GPU setting, we assign the master role to the rank 0 process. When - training using a single GPU, there is a single process which is considered master. - """ - return cfg.NUM_GPUS == 1 or torch.distributed.get_rank() == 0 - - -def init_process_group(proc_rank, world_size, port='29588'): - """Initializes the default process group.""" - # Set the GPU to use - print("begin init_process_group") - torch.npu.set_device(proc_rank) - print("[npu id:", proc_rank, "]", "Use NPU: {} for training".format(proc_rank)) - - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = '29588' - - - # Initialize the process group - torch.distributed.init_process_group( - backend=cfg.DIST_BACKEND, - world_size=world_size, - rank=proc_rank, - ) - print("after init_process_group") - - -def destroy_process_group(): - """Destroys the default process group.""" - torch.distributed.destroy_process_group() - - -def scaled_all_reduce(tensors): - """Performs the scaled all_reduce operation on the provided tensors. - - The input tensors are modified in-place. Currently supports only the sum - reduction operator. The reduced values are scaled by the inverse size of the - process group (equivalent to cfg.NUM_GPUS). - """ - # There is no need for reduction in the single-proc case - if cfg.NUM_GPUS == 1: - return tensors - # Queue the reductions - reductions = [] - for tensor in tensors: - reduction = torch.distributed.all_reduce(tensor, async_op=True) - reductions.append(reduction) - # Wait for reductions to finish - for reduction in reductions: - reduction.wait() - # Scale the results - for tensor in tensors: - tensor.mul_(1.0 / cfg.NUM_GPUS) - return tensors - - -class ChildException(Exception): - """Wraps an exception from a child process.""" - - def __init__(self, child_trace): - super(ChildException, self).__init__(child_trace) - - -class ErrorHandler(object): - """Multiprocessing error handler (based on fairseq's). - - Listens for errors in child processes and propagates the tracebacks to the parent. - """ - - def __init__(self, error_queue): - # Shared error queue - self.error_queue = error_queue - # Children processes sharing the error queue - self.children_pids = [] - # Start a thread listening to errors - self.error_listener = threading.Thread(target=self.listen, daemon=True) - self.error_listener.start() - # Register the signal handler - signal.signal(signal.SIGUSR1, self.signal_handler) - - def add_child(self, pid): - """Registers a child process.""" - self.children_pids.append(pid) - - def listen(self): - """Listens for errors in the error queue.""" - # Wait until there is an error in the queue - child_trace = self.error_queue.get() - # Put the error back for the signal handler - self.error_queue.put(child_trace) - # Invoke the signal handler - os.kill(os.getpid(), signal.SIGUSR1) - - def signal_handler(self, _sig_num, _stack_frame): - """Signal handler.""" - # Kill children processes - for pid in self.children_pids: - os.kill(pid, signal.SIGINT) - # Propagate the error from the child process - raise ChildException(self.error_queue.get()) - - -def run(proc_rank, world_size, port, error_queue, fun, fun_args, fun_kwargs): - """Runs a function from a child process.""" - try: - # Initialize the process group - init_process_group(proc_rank, world_size, port) - # Run the function - fun(*fun_args, **fun_kwargs) - except KeyboardInterrupt: - # Killed by the parent process - pass - except Exception: - # Propagate exception to the parent process - error_queue.put(traceback.format_exc()) - finally: - # Destroy the process group - destroy_process_group() - - -def multi_proc_run(num_proc, fun, fun_args=(), fun_kwargs=None): - """Runs a function in a multi-proc setting (unless num_proc == 1).""" - # There is no need for multi-proc in the single-proc case - fun_kwargs = fun_kwargs if fun_kwargs else {} - if num_proc == 1: - fun(*fun_args, **fun_kwargs) - return - # Handle errors from training subprocesses - error_queue = multiprocessing.SimpleQueue() - error_handler = ErrorHandler(error_queue) - # Get a random port to use (without using global random number generator) - port = random.Random().randint(cfg.PORT_RANGE[0], cfg.PORT_RANGE[1]) - # Run each training subprocess - ps = [] - for i in range(num_proc): - p_i = multiprocessing.Process( - target=run, args=(i, num_proc, port, error_queue, fun, fun_args, fun_kwargs) - ) - ps.append(p_i) - p_i.start() - error_handler.add_child(p_i.pid) - # Wait for each subprocess to finish - for p in ps: - p.join() +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +"""Distributed helpers.""" + +import multiprocessing +import os +import random +import signal +import threading +import traceback +import torch.npu +import torch +from pycls.core.config import cfg + + +# Make work w recent PyTorch versions (https://github.com/pytorch/pytorch/issues/37377) +os.environ["MKL_THREADING_LAYER"] = "GNU" + + +def is_master_proc(): + """Determines if the current process is the master process. + + Master process is responsible for logging, writing and loading checkpoints. In + the multi GPU setting, we assign the master role to the rank 0 process. When + training using a single GPU, there is a single process which is considered master. + """ + return cfg.NUM_GPUS == 1 or torch.distributed.get_rank() == 0 + + +def init_process_group(proc_rank, world_size, port='29588'): + """Initializes the default process group.""" + # Set the GPU to use + print("begin init_process_group") + torch.npu.set_device(proc_rank) + print("[npu id:", proc_rank, "]", "Use NPU: {} for training".format(proc_rank)) + + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '29588' + + + # Initialize the process group + torch.distributed.init_process_group( + backend=cfg.DIST_BACKEND, + world_size=world_size, + rank=proc_rank, + ) + print("after init_process_group") + + +def destroy_process_group(): + """Destroys the default process group.""" + torch.distributed.destroy_process_group() + + +def scaled_all_reduce(tensors): + """Performs the scaled all_reduce operation on the provided tensors. + + The input tensors are modified in-place. Currently supports only the sum + reduction operator. The reduced values are scaled by the inverse size of the + process group (equivalent to cfg.NUM_GPUS). + """ + # There is no need for reduction in the single-proc case + if cfg.NUM_GPUS == 1: + return tensors + # Queue the reductions + reductions = [] + for tensor in tensors: + reduction = torch.distributed.all_reduce(tensor, async_op=True) + reductions.append(reduction) + # Wait for reductions to finish + for reduction in reductions: + reduction.wait() + # Scale the results + for tensor in tensors: + tensor.mul_(1.0 / cfg.NUM_GPUS) + return tensors + + +class ChildException(Exception): + """Wraps an exception from a child process.""" + + def __init__(self, child_trace): + super(ChildException, self).__init__(child_trace) + + +class ErrorHandler(object): + """Multiprocessing error handler (based on fairseq's). + + Listens for errors in child processes and propagates the tracebacks to the parent. + """ + + def __init__(self, error_queue): + # Shared error queue + self.error_queue = error_queue + # Children processes sharing the error queue + self.children_pids = [] + # Start a thread listening to errors + self.error_listener = threading.Thread(target=self.listen, daemon=True) + self.error_listener.start() + # Register the signal handler + signal.signal(signal.SIGUSR1, self.signal_handler) + + def add_child(self, pid): + """Registers a child process.""" + self.children_pids.append(pid) + + def listen(self): + """Listens for errors in the error queue.""" + # Wait until there is an error in the queue + child_trace = self.error_queue.get() + # Put the error back for the signal handler + self.error_queue.put(child_trace) + # Invoke the signal handler + os.kill(os.getpid(), signal.SIGUSR1) + + def signal_handler(self, _sig_num, _stack_frame): + """Signal handler.""" + # Kill children processes + for pid in self.children_pids: + os.kill(pid, signal.SIGINT) + # Propagate the error from the child process + raise ChildException(self.error_queue.get()) + + +def run(proc_rank, world_size, port, error_queue, fun, fun_args, fun_kwargs): + """Runs a function from a child process.""" + try: + # Initialize the process group + init_process_group(proc_rank, world_size, port) + # Run the function + fun(*fun_args, **fun_kwargs) + except KeyboardInterrupt: + # Killed by the parent process + pass + except Exception: + # Propagate exception to the parent process + error_queue.put(traceback.format_exc()) + finally: + # Destroy the process group + destroy_process_group() + + +def multi_proc_run(num_proc, fun, fun_args=(), fun_kwargs=None): + """Runs a function in a multi-proc setting (unless num_proc == 1).""" + # There is no need for multi-proc in the single-proc case + fun_kwargs = fun_kwargs if fun_kwargs else {} + if num_proc == 1: + fun(*fun_args, **fun_kwargs) + return + # Handle errors from training subprocesses + error_queue = multiprocessing.SimpleQueue() + error_handler = ErrorHandler(error_queue) + # Get a random port to use (without using global random number generator) + port = random.Random().randint(cfg.PORT_RANGE[0], cfg.PORT_RANGE[1]) + # Run each training subprocess + ps = [] + for i in range(num_proc): + p_i = multiprocessing.Process( + target=run, args=(i, num_proc, port, error_queue, fun, fun_args, fun_kwargs) + ) + ps.append(p_i) + p_i.start() + error_handler.add_child(p_i.pid) + # Wait for each subprocess to finish + for p in ps: + p.join() diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/env.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/env.py index c0d31579a4faec62c630b88ca1a66168f790dfce..48a8164b31bd510231ee34260f183f7317e99ffa 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/env.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/env.py @@ -1,56 +1,56 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import random - -import numpy as np -import pycls.core.config as config -import pycls.core.distributed as dist -import pycls.core.logging as logging -import torch -from iopath.common.file_io import g_pathmgr -from pycls.core.config import cfg - - -logger = logging.get_logger(__name__) - - -def setup_env(): - """Sets up environment for training or testing.""" - if dist.is_master_proc(): - # Ensure that the output dir exists - g_pathmgr.mkdirs(cfg.OUT_DIR) - # Save the config - config.dump_cfg() - # Setup logging - logging.setup_logging() - # Log torch, cuda, and cudnn versions - version = [torch.__version__, torch.version.cuda, torch.backends.cudnn.version()] - logger.info("PyTorch Version: torch={}, cuda={}, cudnn={}".format(*version)) - # Log the config as both human readable and as a json - logger.info("Config:\n{}".format(cfg)) if cfg.VERBOSE else () - logger.info(logging.dump_log_data(cfg, "cfg", None)) - # Fix the RNG seeds (see RNG comment in core/config.py for discussion) - np.random.seed(cfg.RNG_SEED) - torch.manual_seed(cfg.RNG_SEED) - random.seed(cfg.RNG_SEED) - # Configure the CUDNN backend - torch.backends.cudnn.benchmark = cfg.CUDNN.BENCHMARK +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import random + +import numpy as np +import pycls.core.config as config +import pycls.core.distributed as dist +import pycls.core.logging as logging +import torch +from iopath.common.file_io import g_pathmgr +from pycls.core.config import cfg + + +logger = logging.get_logger(__name__) + + +def setup_env(): + """Sets up environment for training or testing.""" + if dist.is_master_proc(): + # Ensure that the output dir exists + g_pathmgr.mkdirs(cfg.OUT_DIR) + # Save the config + config.dump_cfg() + # Setup logging + logging.setup_logging() + # Log torch, cuda, and cudnn versions + version = [torch.__version__, torch.version.cuda, torch.backends.cudnn.version()] + logger.info("PyTorch Version: torch={}, cuda={}, cudnn={}".format(*version)) + # Log the config as both human readable and as a json + logger.info("Config:\n{}".format(cfg)) if cfg.VERBOSE else () + logger.info(logging.dump_log_data(cfg, "cfg", None)) + # Fix the RNG seeds (see RNG comment in core/config.py for discussion) + np.random.seed(cfg.RNG_SEED) + torch.manual_seed(cfg.RNG_SEED) + random.seed(cfg.RNG_SEED) + # Configure the CUDNN backend + torch.backends.cudnn.benchmark = cfg.CUDNN.BENCHMARK diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/io.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/io.py index 8bba8a2d45b9f41aa6e31a74b29a2fa15ec59dde..51a1f8292126ca611ec5e85811bdf558a502edd7 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/io.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/io.py @@ -1,93 +1,93 @@ -#!/usr/bin/env python3 - - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""IO utilities (adapted from Detectron)""" - -import logging -import os -import re -import sys -from urllib import request as urlrequest - -from iopath.common.file_io import g_pathmgr - - -logger = logging.getLogger(__name__) - -_PYCLS_BASE_URL = "https://dl.fbaipublicfiles.com/pycls" - - -def cache_url(url_or_file, cache_dir, base_url=_PYCLS_BASE_URL): - """Download the file specified by the URL to the cache_dir and return the path to - the cached file. If the argument is not a URL, simply return it as is. - """ - is_url = re.match(r"^(?:http)s?://", url_or_file, re.IGNORECASE) is not None - if not is_url: - return url_or_file - url = url_or_file - assert url.startswith(base_url), "url must start with: {}".format(base_url) - cache_file_path = url.replace(base_url, cache_dir) - if g_pathmgr.exists(cache_file_path): - return cache_file_path - cache_file_dir = os.path.dirname(cache_file_path) - if not g_pathmgr.exists(cache_file_dir): - g_pathmgr.mkdirs(cache_file_dir) - logger.info("Downloading remote file {} to {}".format(url, cache_file_path)) - download_url(url, cache_file_path) - return cache_file_path - - -def _progress_bar(count, total): - """Report download progress. Credit: - https://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console/27871113 - """ - bar_len = 60 - filled_len = int(round(bar_len * count / float(total))) - percents = round(100.0 * count / float(total), 1) - bar = "=" * filled_len + "-" * (bar_len - filled_len) - sys.stdout.write( - " [{}] {}% of {:.1f}MB file \r".format(bar, percents, total / 1024 / 1024) - ) - sys.stdout.flush() - if count >= total: - sys.stdout.write("\n") - - -def download_url(url, dst_file_path, chunk_size=8192, progress_hook=_progress_bar): - """Download url and write it to dst_file_path. Credit: - https://stackoverflow.com/questions/2028517/python-urllib2-progress-hook - """ - req = urlrequest.Request(url) - response = urlrequest.urlopen(req) - total_size = response.info().get("Content-Length").strip() - total_size = int(total_size) - bytes_so_far = 0 - with g_pathmgr.open(dst_file_path, "wb") as f: - while 1: - chunk = response.read(chunk_size) - bytes_so_far += len(chunk) - if not chunk: - break - if progress_hook: - progress_hook(bytes_so_far, total_size) - f.write(chunk) - return bytes_so_far +#!/usr/bin/env python3 + + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""IO utilities (adapted from Detectron)""" + +import logging +import os +import re +import sys +from urllib import request as urlrequest + +from iopath.common.file_io import g_pathmgr + + +logger = logging.getLogger(__name__) + +_PYCLS_BASE_URL = "https://dl.fbaipublicfiles.com/pycls" + + +def cache_url(url_or_file, cache_dir, base_url=_PYCLS_BASE_URL): + """Download the file specified by the URL to the cache_dir and return the path to + the cached file. If the argument is not a URL, simply return it as is. + """ + is_url = re.match(r"^(?:http)s?://", url_or_file, re.IGNORECASE) is not None + if not is_url: + return url_or_file + url = url_or_file + assert url.startswith(base_url), "url must start with: {}".format(base_url) + cache_file_path = url.replace(base_url, cache_dir) + if g_pathmgr.exists(cache_file_path): + return cache_file_path + cache_file_dir = os.path.dirname(cache_file_path) + if not g_pathmgr.exists(cache_file_dir): + g_pathmgr.mkdirs(cache_file_dir) + logger.info("Downloading remote file {} to {}".format(url, cache_file_path)) + download_url(url, cache_file_path) + return cache_file_path + + +def _progress_bar(count, total): + """Report download progress. Credit: + https://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console/27871113 + """ + bar_len = 60 + filled_len = int(round(bar_len * count / float(total))) + percents = round(100.0 * count / float(total), 1) + bar = "=" * filled_len + "-" * (bar_len - filled_len) + sys.stdout.write( + " [{}] {}% of {:.1f}MB file \r".format(bar, percents, total / 1024 / 1024) + ) + sys.stdout.flush() + if count >= total: + sys.stdout.write("\n") + + +def download_url(url, dst_file_path, chunk_size=8192, progress_hook=_progress_bar): + """Download url and write it to dst_file_path. Credit: + https://stackoverflow.com/questions/2028517/python-urllib2-progress-hook + """ + req = urlrequest.Request(url) + response = urlrequest.urlopen(req) + total_size = response.info().get("Content-Length").strip() + total_size = int(total_size) + bytes_so_far = 0 + with g_pathmgr.open(dst_file_path, "wb") as f: + while 1: + chunk = response.read(chunk_size) + bytes_so_far += len(chunk) + if not chunk: + break + if progress_hook: + progress_hook(bytes_so_far, total_size) + f.write(chunk) + return bytes_so_far diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/logging.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/logging.py index fc0f2aa70d519553c2ae2a1616444dfc4cb8d054..f5374e51c1e11079188782070ab7d3bd10cbcee1 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/logging.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/logging.py @@ -1,153 +1,153 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Logging.""" - -import builtins -import decimal -import logging -import os -import sys - -import pycls.core.distributed as dist -import simplejson -from iopath.common.file_io import g_pathmgr -from pycls.core.config import cfg - - -# Show filename and line number in logs -_FORMAT = "[%(filename)s: %(lineno)3d]: %(message)s" - -# Log file name (for cfg.LOG_DEST = 'file') -_LOG_FILE = "stdout.log" - -# Data output with dump_log_data(data, data_type) will be tagged w/ this -_TAG = "json_stats: " - -# Data output with dump_log_data(data, data_type) will have data[_TYPE]=data_type -_TYPE = "_type" - - -def _suppress_print(): - """Suppresses printing from the current process.""" - - def ignore(*_objects, _sep=" ", _end="\n", _file=sys.stdout, _flush=False): - pass - - builtins.print = ignore - - -def setup_logging(): - """Sets up the logging.""" - # Enable logging only for the master process - if dist.is_master_proc(): - # Clear the root logger to prevent any existing logging config - # (e.g. set by another module) from messing with our setup - logging.root.handlers = [] - # Construct logging configuration - logging_config = {"level": logging.INFO, "format": _FORMAT} - # Log either to stdout or to a file - if cfg.LOG_DEST == "stdout": - logging_config["stream"] = sys.stdout - else: - logging_config["filename"] = os.path.join(cfg.OUT_DIR, _LOG_FILE) - # Configure logging - logging.basicConfig(**logging_config) - else: - _suppress_print() - - -def get_logger(name): - """Retrieves the logger.""" - return logging.getLogger(name) - - -def dump_log_data(data, data_type, prec=4): - """Covert data (a dictionary) into tagged json string for logging.""" - data[_TYPE] = data_type - data = float_to_decimal(data, prec) - data_json = simplejson.dumps(data, sort_keys=True, use_decimal=True) - return "{:s}{:s}".format(_TAG, data_json) - - -def float_to_decimal(data, prec=4): - """Convert floats to decimals which allows for fixed width json.""" - if prec and isinstance(data, dict): - return {k: float_to_decimal(v, prec) for k, v in data.items()} - if prec and isinstance(data, float): - return decimal.Decimal(("{:." + str(prec) + "f}").format(data)) - else: - return data - - -def get_log_files(log_dir, name_filter="", log_file=_LOG_FILE): - """Get all log files in directory containing subdirs of trained models.""" - names = [n for n in sorted(g_pathmgr.ls(log_dir)) if name_filter in n] - files = [os.path.join(log_dir, n, log_file) for n in names] - f_n_ps = [(f, n) for (f, n) in zip(files, names) if g_pathmgr.exists(f)] - files, names = zip(*f_n_ps) if f_n_ps else ([], []) - return files, names - - -def load_log_data(log_file, data_types_to_skip=()): - """Loads log data into a dictionary of the form data[data_type][metric][index].""" - # Load log_file - assert g_pathmgr.exists(log_file), "Log file not found: {}".format(log_file) - with g_pathmgr.open(log_file, "r") as f: - lines = f.readlines() - # Extract and parse lines that start with _TAG and have a type specified - lines = [l[l.find(_TAG) + len(_TAG) :] for l in lines if _TAG in l] - lines = [simplejson.loads(l) for l in lines] - lines = [l for l in lines if _TYPE in l and not l[_TYPE] in data_types_to_skip] - # Generate data structure accessed by data[data_type][index][metric] - data_types = [l[_TYPE] for l in lines] - data = {t: [] for t in data_types} - for t, line in zip(data_types, lines): - del line[_TYPE] - data[t].append(line) - # Generate data structure accessed by data[data_type][metric][index] - for t in data: - metrics = sorted(data[t][0].keys()) - err_str = "Inconsistent metrics in log for _type={}: {}".format(t, metrics) - assert all(sorted(d.keys()) == metrics for d in data[t]), err_str - data[t] = {m: [d[m] for d in data[t]] for m in metrics} - return data - - -def sort_log_data(data): - """Sort each data[data_type][metric] by epoch or keep only first instance.""" - for t in data: - if "epoch" in data[t]: - assert "epoch_ind" not in data[t] and "epoch_max" not in data[t] - data[t]["epoch_ind"] = [int(e.split("/")[0]) for e in data[t]["epoch"]] - data[t]["epoch_max"] = [int(e.split("/")[1]) for e in data[t]["epoch"]] - epoch = data[t]["epoch_ind"] - if "iter" in data[t]: - assert "iter_ind" not in data[t] and "iter_max" not in data[t] - data[t]["iter_ind"] = [int(i.split("/")[0]) for i in data[t]["iter"]] - data[t]["iter_max"] = [int(i.split("/")[1]) for i in data[t]["iter"]] - itr = zip(epoch, data[t]["iter_ind"], data[t]["iter_max"]) - epoch = [e + (i_ind - 1) / i_max for e, i_ind, i_max in itr] - for m in data[t]: - data[t][m] = [v for _, v in sorted(zip(epoch, data[t][m]))] - else: - data[t] = {m: d[0] for m, d in data[t].items()} - return data +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Logging.""" + +import builtins +import decimal +import logging +import os +import sys + +import pycls.core.distributed as dist +import simplejson +from iopath.common.file_io import g_pathmgr +from pycls.core.config import cfg + + +# Show filename and line number in logs +_FORMAT = "[%(filename)s: %(lineno)3d]: %(message)s" + +# Log file name (for cfg.LOG_DEST = 'file') +_LOG_FILE = "stdout.log" + +# Data output with dump_log_data(data, data_type) will be tagged w/ this +_TAG = "json_stats: " + +# Data output with dump_log_data(data, data_type) will have data[_TYPE]=data_type +_TYPE = "_type" + + +def _suppress_print(): + """Suppresses printing from the current process.""" + + def ignore(*_objects, _sep=" ", _end="\n", _file=sys.stdout, _flush=False): + pass + + builtins.print = ignore + + +def setup_logging(): + """Sets up the logging.""" + # Enable logging only for the master process + if dist.is_master_proc(): + # Clear the root logger to prevent any existing logging config + # (e.g. set by another module) from messing with our setup + logging.root.handlers = [] + # Construct logging configuration + logging_config = {"level": logging.INFO, "format": _FORMAT} + # Log either to stdout or to a file + if cfg.LOG_DEST == "stdout": + logging_config["stream"] = sys.stdout + else: + logging_config["filename"] = os.path.join(cfg.OUT_DIR, _LOG_FILE) + # Configure logging + logging.basicConfig(**logging_config) + else: + _suppress_print() + + +def get_logger(name): + """Retrieves the logger.""" + return logging.getLogger(name) + + +def dump_log_data(data, data_type, prec=4): + """Covert data (a dictionary) into tagged json string for logging.""" + data[_TYPE] = data_type + data = float_to_decimal(data, prec) + data_json = simplejson.dumps(data, sort_keys=True, use_decimal=True) + return "{:s}{:s}".format(_TAG, data_json) + + +def float_to_decimal(data, prec=4): + """Convert floats to decimals which allows for fixed width json.""" + if prec and isinstance(data, dict): + return {k: float_to_decimal(v, prec) for k, v in data.items()} + if prec and isinstance(data, float): + return decimal.Decimal(("{:." + str(prec) + "f}").format(data)) + else: + return data + + +def get_log_files(log_dir, name_filter="", log_file=_LOG_FILE): + """Get all log files in directory containing subdirs of trained models.""" + names = [n for n in sorted(g_pathmgr.ls(log_dir)) if name_filter in n] + files = [os.path.join(log_dir, n, log_file) for n in names] + f_n_ps = [(f, n) for (f, n) in zip(files, names) if g_pathmgr.exists(f)] + files, names = zip(*f_n_ps) if f_n_ps else ([], []) + return files, names + + +def load_log_data(log_file, data_types_to_skip=()): + """Loads log data into a dictionary of the form data[data_type][metric][index].""" + # Load log_file + assert g_pathmgr.exists(log_file), "Log file not found: {}".format(log_file) + with g_pathmgr.open(log_file, "r") as f: + lines = f.readlines() + # Extract and parse lines that start with _TAG and have a type specified + lines = [l[l.find(_TAG) + len(_TAG) :] for l in lines if _TAG in l] + lines = [simplejson.loads(l) for l in lines] + lines = [l for l in lines if _TYPE in l and not l[_TYPE] in data_types_to_skip] + # Generate data structure accessed by data[data_type][index][metric] + data_types = [l[_TYPE] for l in lines] + data = {t: [] for t in data_types} + for t, line in zip(data_types, lines): + del line[_TYPE] + data[t].append(line) + # Generate data structure accessed by data[data_type][metric][index] + for t in data: + metrics = sorted(data[t][0].keys()) + err_str = "Inconsistent metrics in log for _type={}: {}".format(t, metrics) + assert all(sorted(d.keys()) == metrics for d in data[t]), err_str + data[t] = {m: [d[m] for d in data[t]] for m in metrics} + return data + + +def sort_log_data(data): + """Sort each data[data_type][metric] by epoch or keep only first instance.""" + for t in data: + if "epoch" in data[t]: + assert "epoch_ind" not in data[t] and "epoch_max" not in data[t] + data[t]["epoch_ind"] = [int(e.split("/")[0]) for e in data[t]["epoch"]] + data[t]["epoch_max"] = [int(e.split("/")[1]) for e in data[t]["epoch"]] + epoch = data[t]["epoch_ind"] + if "iter" in data[t]: + assert "iter_ind" not in data[t] and "iter_max" not in data[t] + data[t]["iter_ind"] = [int(i.split("/")[0]) for i in data[t]["iter"]] + data[t]["iter_max"] = [int(i.split("/")[1]) for i in data[t]["iter"]] + itr = zip(epoch, data[t]["iter_ind"], data[t]["iter_max"]) + epoch = [e + (i_ind - 1) / i_max for e, i_ind, i_max in itr] + for m in data[t]: + data[t][m] = [v for _, v in sorted(zip(epoch, data[t][m]))] + else: + data[t] = {m: d[0] for m, d in data[t].items()} + return data diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/plotting.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/plotting.py index 608f6ee442b3b8070e2bb9908be2e53e6489c657..bf7c18a6defe2040b9b5ae9ee25155e9986b66a2 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/plotting.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/plotting.py @@ -1,146 +1,146 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Plotting functions.""" - -import colorlover as cl -import matplotlib.pyplot as plt -import plotly.graph_objs as go -import plotly.offline as offline -import pycls.core.logging as logging - - -def get_plot_colors(max_colors, color_format="pyplot"): - """Generate colors for plotting.""" - colors = cl.scales["11"]["qual"]["Paired"] - if max_colors > len(colors): - colors = cl.to_rgb(cl.interp(colors, max_colors)) - if color_format == "pyplot": - return [[j / 255.0 for j in c] for c in cl.to_numeric(colors)] - return colors - - -def prepare_plot_data(log_files, names, metric="top1_err"): - """Load logs and extract data for plotting error curves.""" - plot_data = [] - for file, name in zip(log_files, names): - d, data = {}, logging.sort_log_data(logging.load_log_data(file)) - for phase in ["train", "test"]: - x = data[phase + "_epoch"]["epoch_ind"] - y = data[phase + "_epoch"][metric] - d["x_" + phase], d["y_" + phase] = x, y - d[phase + "_label"] = "[{:5.2f}] ".format(min(y) if y else 0) + name - plot_data.append(d) - assert len(plot_data) > 0, "No data to plot" - return plot_data - - -def plot_error_curves_plotly(log_files, names, filename, metric="top1_err"): - """Plot error curves using plotly and save to file.""" - plot_data = prepare_plot_data(log_files, names, metric) - colors = get_plot_colors(len(plot_data), "plotly") - # Prepare data for plots (3 sets, train duplicated w and w/o legend) - data = [] - for i, d in enumerate(plot_data): - s = str(i) - line_train = {"color": colors[i], "dash": "dashdot", "width": 1.5} - line_test = {"color": colors[i], "dash": "solid", "width": 1.5} - data.append( - go.Scatter( - x=d["x_train"], - y=d["y_train"], - mode="lines", - name=d["train_label"], - line=line_train, - legendgroup=s, - visible=True, - showlegend=False, - ) - ) - data.append( - go.Scatter( - x=d["x_test"], - y=d["y_test"], - mode="lines", - name=d["test_label"], - line=line_test, - legendgroup=s, - visible=True, - showlegend=True, - ) - ) - data.append( - go.Scatter( - x=d["x_train"], - y=d["y_train"], - mode="lines", - name=d["train_label"], - line=line_train, - legendgroup=s, - visible=False, - showlegend=True, - ) - ) - # Prepare layout w ability to toggle 'all', 'train', 'test' - titlefont = {"size": 18, "color": "#7f7f7f"} - vis = [[True, True, False], [False, False, True], [False, True, False]] - buttons = zip(["all", "train", "test"], [[{"visible": v}] for v in vis]) - buttons = [{"label": b, "args": v, "method": "update"} for b, v in buttons] - layout = go.Layout( - title=metric + " vs. epoch
[dash=train, solid=test]", - xaxis={"title": "epoch", "titlefont": titlefont}, - yaxis={"title": metric, "titlefont": titlefont}, - showlegend=True, - hoverlabel={"namelength": -1}, - updatemenus=[ - { - "buttons": buttons, - "direction": "down", - "showactive": True, - "x": 1.02, - "xanchor": "left", - "y": 1.08, - "yanchor": "top", - } - ], - ) - # Create plotly plot - offline.plot({"data": data, "layout": layout}, filename=filename) - - -def plot_error_curves_pyplot(log_files, names, filename=None, metric="top1_err"): - """Plot error curves using matplotlib.pyplot and save to file.""" - plot_data = prepare_plot_data(log_files, names, metric) - colors = get_plot_colors(len(names)) - for ind, d in enumerate(plot_data): - c, lbl = colors[ind], d["test_label"] - plt.plot(d["x_train"], d["y_train"], "--", c=c, alpha=0.8) - plt.plot(d["x_test"], d["y_test"], "-", c=c, alpha=0.8, label=lbl) - plt.title(metric + " vs. epoch\n[dash=train, solid=test]", fontsize=14) - plt.xlabel("epoch", fontsize=14) - plt.ylabel(metric, fontsize=14) - plt.grid(alpha=0.4) - plt.legend() - if filename: - plt.savefig(filename) - plt.clf() - else: - plt.show() +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Plotting functions.""" + +import colorlover as cl +import matplotlib.pyplot as plt +import plotly.graph_objs as go +import plotly.offline as offline +import pycls.core.logging as logging + + +def get_plot_colors(max_colors, color_format="pyplot"): + """Generate colors for plotting.""" + colors = cl.scales["11"]["qual"]["Paired"] + if max_colors > len(colors): + colors = cl.to_rgb(cl.interp(colors, max_colors)) + if color_format == "pyplot": + return [[j / 255.0 for j in c] for c in cl.to_numeric(colors)] + return colors + + +def prepare_plot_data(log_files, names, metric="top1_err"): + """Load logs and extract data for plotting error curves.""" + plot_data = [] + for file, name in zip(log_files, names): + d, data = {}, logging.sort_log_data(logging.load_log_data(file)) + for phase in ["train", "test"]: + x = data[phase + "_epoch"]["epoch_ind"] + y = data[phase + "_epoch"][metric] + d["x_" + phase], d["y_" + phase] = x, y + d[phase + "_label"] = "[{:5.2f}] ".format(min(y) if y else 0) + name + plot_data.append(d) + assert len(plot_data) > 0, "No data to plot" + return plot_data + + +def plot_error_curves_plotly(log_files, names, filename, metric="top1_err"): + """Plot error curves using plotly and save to file.""" + plot_data = prepare_plot_data(log_files, names, metric) + colors = get_plot_colors(len(plot_data), "plotly") + # Prepare data for plots (3 sets, train duplicated w and w/o legend) + data = [] + for i, d in enumerate(plot_data): + s = str(i) + line_train = {"color": colors[i], "dash": "dashdot", "width": 1.5} + line_test = {"color": colors[i], "dash": "solid", "width": 1.5} + data.append( + go.Scatter( + x=d["x_train"], + y=d["y_train"], + mode="lines", + name=d["train_label"], + line=line_train, + legendgroup=s, + visible=True, + showlegend=False, + ) + ) + data.append( + go.Scatter( + x=d["x_test"], + y=d["y_test"], + mode="lines", + name=d["test_label"], + line=line_test, + legendgroup=s, + visible=True, + showlegend=True, + ) + ) + data.append( + go.Scatter( + x=d["x_train"], + y=d["y_train"], + mode="lines", + name=d["train_label"], + line=line_train, + legendgroup=s, + visible=False, + showlegend=True, + ) + ) + # Prepare layout w ability to toggle 'all', 'train', 'test' + titlefont = {"size": 18, "color": "#7f7f7f"} + vis = [[True, True, False], [False, False, True], [False, True, False]] + buttons = zip(["all", "train", "test"], [[{"visible": v}] for v in vis]) + buttons = [{"label": b, "args": v, "method": "update"} for b, v in buttons] + layout = go.Layout( + title=metric + " vs. epoch
[dash=train, solid=test]", + xaxis={"title": "epoch", "titlefont": titlefont}, + yaxis={"title": metric, "titlefont": titlefont}, + showlegend=True, + hoverlabel={"namelength": -1}, + updatemenus=[ + { + "buttons": buttons, + "direction": "down", + "showactive": True, + "x": 1.02, + "xanchor": "left", + "y": 1.08, + "yanchor": "top", + } + ], + ) + # Create plotly plot + offline.plot({"data": data, "layout": layout}, filename=filename) + + +def plot_error_curves_pyplot(log_files, names, filename=None, metric="top1_err"): + """Plot error curves using matplotlib.pyplot and save to file.""" + plot_data = prepare_plot_data(log_files, names, metric) + colors = get_plot_colors(len(names)) + for ind, d in enumerate(plot_data): + c, lbl = colors[ind], d["test_label"] + plt.plot(d["x_train"], d["y_train"], "--", c=c, alpha=0.8) + plt.plot(d["x_test"], d["y_test"], "-", c=c, alpha=0.8, label=lbl) + plt.title(metric + " vs. epoch\n[dash=train, solid=test]", fontsize=14) + plt.xlabel("epoch", fontsize=14) + plt.ylabel(metric, fontsize=14) + plt.grid(alpha=0.4) + plt.legend() + if filename: + plt.savefig(filename) + plt.clf() + else: + plt.show() diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/sgd.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/sgd.py index d390654bc77c64f774d232635a2a6c544cf3d401..5f6800a198dd609f7f2100a23c4b01855b906622 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/sgd.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/sgd.py @@ -1,212 +1,212 @@ -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -from torch.optim.optimizer import Optimizer, required -from collections import defaultdict -from pycls.core.combine_tensors import combine_npu - -class NpuFusedSGD(Optimizer): - r"""Implements stochastic gradient descent (optionally with momentum). - - Currently NPU-only. Requires Apex to be installed via - ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--npu_float_status" ./``. - - This version of fused SGD implements 1 fusions. - - * A combine-tensor apply launch that batches the elementwise updates applied to all the model's parameters into one or a few kernel launches. - - :class:`apex.optimizers.NpuFusedSGD` may be used as a drop-in replacement for ``torch.optim.SGD``:: - - opt = apex.optimizers.NpuFusedSGD(model.parameters(), lr = ....) - ... - opt.step() - - :class:`apex.optimizers.FusedSGD` should be used with Amp. Currently, if you wish to use :class:`NpuFusedSGD` with Amp, - only ``opt_level O2`` can be choosed:: - - opt = apex.optimizers.NpuFusedSGD(model.parameters(), lr = ....) - model, opt = amp.initialize(model, opt, opt_level="O2") - ... - opt.step() - - Nesterov momentum is based on the formula from - `On the importance of initialization and momentum in deep learning`__. - - Args: - params (iterable): iterable of parameters to optimize or dicts defining - parameter groups - lr (float): learning rate - momentum (float, optional): momentum factor (default: 0) - weight_decay (float, optional): weight decay (L2 penalty) (default: 0) - dampening (float, optional): dampening for momentum (default: 0) - nesterov (bool, optional): enables Nesterov momentum (default: False) - - Example: - >>> optimizer = torch.optim.SGD(model.parameters(), lr=0.1, momentum=0.9) - >>> optimizer.zero_grad() - >>> loss_fn(model(input), target).backward() - >>> optimizer.step() - - __ http://www.cs.toronto.edu/%7Ehinton/absps/momentum.pdf - - .. note:: - The implementation of SGD with Momentum/Nesterov subtly differs from - Sutskever et. al. and implementations in some other frameworks. - - Considering the specific case of Momentum, the update can be written as - - .. math:: - \begin{aligned} - v_{t+1} & = \mu * v_{t} + g_{t+1}, \\ - p_{t+1} & = p_{t} - \text{lr} * v_{t+1}, - \end{aligned} - - where :math:`p`, :math:`g`, :math:`v` and :math:`\mu` denote the - parameters, gradient, velocity, and momentum respectively. - - This is in contrast to Sutskever et. al. and - other frameworks which employ an update of the form - - .. math:: - \begin{aligned} - v_{t+1} & = \mu * v_{t} + \text{lr} * g_{t+1}, \\ - p_{t+1} & = p_{t} - v_{t+1}. - \end{aligned} - - The Nesterov version is analogously modified. - """ - - def __init__(self, params, lr=required, momentum=0, dampening=0, - weight_decay=0, nesterov=False): - if lr is not required and lr < 0.0: - raise ValueError("Invalid learning rate: {}".format(lr)) - if momentum < 0.0: - raise ValueError("Invalid momentum value: {}".format(momentum)) - if weight_decay < 0.0: - raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) - - defaults = dict(lr=lr, momentum=momentum, dampening=dampening, - weight_decay=weight_decay, nesterov=nesterov) - if nesterov and (momentum <= 0 or dampening != 0): - raise ValueError("Nesterov momentum requires a momentum and zero dampening") - super(NpuFusedSGD, self).__init__(params, defaults) - - def __setstate__(self, state): - super(NpuFusedSGD, self).__setstate__(state) - for group in self.param_groups: - group.setdefault('nesterov', False) - - def combine_param_state_by_group(self, momentum_buffer_in_state_before): - if not hasattr(self, "_amp_stash"): - raise RuntimeError('apex.optimizers.NpuFusedSGD should be used with AMP.') - - momentum_buffer_in_state_before = True - - stash = self._amp_stash - if stash.param_state_combined: - return - - for group in self.param_groups: - weight_decay = group['weight_decay'] - momentum = group['momentum'] - if momentum == 0: - state_combined = defaultdict(dict) - state_combined['momentum_buffer'] = None - stash.param_state_combined_list.append(state_combined) - continue - - momentum_buffer_list = [] - for p in group['params']: - if p.grad is None: - continue - - d_p = p.grad - state = self.state[p] - if 'momentum_buffer' not in state: - momentum_buffer_in_state_before = False - if weight_decay != 0: - d_p = d_p.add(p, alpha=weight_decay) - state['momentum_buffer'] = torch.clone(d_p).detach() - else: - temp = torch.clone(d_p).detach() - temp.copy_(state['momentum_buffer']) - state['momentum_buffer'] = temp - - momentum_buffer_list.append(state['momentum_buffer']) - - momentum_buffer_combined = None - if len(momentum_buffer_list) > 0: - momentum_buffer_combined = combine_npu(momentum_buffer_list) - - state_combined = defaultdict(dict) - state_combined['momentum_buffer'] = momentum_buffer_combined - stash.param_state_combined_list.append(state_combined) - - stash.param_state_combined = True - - @torch.no_grad() - def step(self, closure=None): - """Performs a single optimization step. - - Arguments: - closure (callable, optional): A closure that reevaluates the model - and returns the loss. - """ - if not hasattr(self, "_amp_stash"): - raise RuntimeError('apex.optimizers.NpuFusedSGD should be used with AMP.') - - momentum_buffer_in_state_before = True - self._combine_params_and_grads_by_group() - self.combine_param_state_by_group(momentum_buffer_in_state_before) - - loss = None - if closure is not None: - with torch.enable_grad(): - loss = closure() - - stash = self._amp_stash - - for i, group in enumerate(self.param_groups): - weight_decay = group['weight_decay'] - momentum = group['momentum'] - dampening = group['dampening'] - nesterov = group['nesterov'] - - params_combined = stash.params_combined_list[i] - grads_combined = stash.grads_combined_list[i] - if params_combined is None or grads_combined is None: - continue - - if weight_decay != 0: - grads_combined = grads_combined.add(params_combined, alpha=weight_decay) - if momentum != 0: - param_state = stash.param_state_combined_list[i] - buf = param_state['momentum_buffer'] - if momentum_buffer_in_state_before: - buf.mul_(momentum).add_(grads_combined, alpha=1 - dampening) - - if nesterov: - grads_combined = grads_combined.add(buf, alpha=momentum) - else: - grads_combined = buf - - params_combined.add_(grads_combined, alpha=-group['lr']) - - return loss +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +from torch.optim.optimizer import Optimizer, required +from collections import defaultdict +from pycls.core.combine_tensors import combine_npu + +class NpuFusedSGD(Optimizer): + r"""Implements stochastic gradient descent (optionally with momentum). + + Currently NPU-only. Requires Apex to be installed via + ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--npu_float_status" ./``. + + This version of fused SGD implements 1 fusions. + + * A combine-tensor apply launch that batches the elementwise updates applied to all the model's parameters into one or a few kernel launches. + + :class:`apex.optimizers.NpuFusedSGD` may be used as a drop-in replacement for ``torch.optim.SGD``:: + + opt = apex.optimizers.NpuFusedSGD(model.parameters(), lr = ....) + ... + opt.step() + + :class:`apex.optimizers.FusedSGD` should be used with Amp. Currently, if you wish to use :class:`NpuFusedSGD` with Amp, + only ``opt_level O2`` can be choosed:: + + opt = apex.optimizers.NpuFusedSGD(model.parameters(), lr = ....) + model, opt = amp.initialize(model, opt, opt_level="O2") + ... + opt.step() + + Nesterov momentum is based on the formula from + `On the importance of initialization and momentum in deep learning`__. + + Args: + params (iterable): iterable of parameters to optimize or dicts defining + parameter groups + lr (float): learning rate + momentum (float, optional): momentum factor (default: 0) + weight_decay (float, optional): weight decay (L2 penalty) (default: 0) + dampening (float, optional): dampening for momentum (default: 0) + nesterov (bool, optional): enables Nesterov momentum (default: False) + + Example: + >>> optimizer = torch.optim.SGD(model.parameters(), lr=0.1, momentum=0.9) + >>> optimizer.zero_grad() + >>> loss_fn(model(input), target).backward() + >>> optimizer.step() + + __ http://www.cs.toronto.edu/%7Ehinton/absps/momentum.pdf + + .. note:: + The implementation of SGD with Momentum/Nesterov subtly differs from + Sutskever et. al. and implementations in some other frameworks. + + Considering the specific case of Momentum, the update can be written as + + .. math:: + \begin{aligned} + v_{t+1} & = \mu * v_{t} + g_{t+1}, \\ + p_{t+1} & = p_{t} - \text{lr} * v_{t+1}, + \end{aligned} + + where :math:`p`, :math:`g`, :math:`v` and :math:`\mu` denote the + parameters, gradient, velocity, and momentum respectively. + + This is in contrast to Sutskever et. al. and + other frameworks which employ an update of the form + + .. math:: + \begin{aligned} + v_{t+1} & = \mu * v_{t} + \text{lr} * g_{t+1}, \\ + p_{t+1} & = p_{t} - v_{t+1}. + \end{aligned} + + The Nesterov version is analogously modified. + """ + + def __init__(self, params, lr=required, momentum=0, dampening=0, + weight_decay=0, nesterov=False): + if lr is not required and lr < 0.0: + raise ValueError("Invalid learning rate: {}".format(lr)) + if momentum < 0.0: + raise ValueError("Invalid momentum value: {}".format(momentum)) + if weight_decay < 0.0: + raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) + + defaults = dict(lr=lr, momentum=momentum, dampening=dampening, + weight_decay=weight_decay, nesterov=nesterov) + if nesterov and (momentum <= 0 or dampening != 0): + raise ValueError("Nesterov momentum requires a momentum and zero dampening") + super(NpuFusedSGD, self).__init__(params, defaults) + + def __setstate__(self, state): + super(NpuFusedSGD, self).__setstate__(state) + for group in self.param_groups: + group.setdefault('nesterov', False) + + def combine_param_state_by_group(self, momentum_buffer_in_state_before): + if not hasattr(self, "_amp_stash"): + raise RuntimeError('apex.optimizers.NpuFusedSGD should be used with AMP.') + + momentum_buffer_in_state_before = True + + stash = self._amp_stash + if stash.param_state_combined: + return + + for group in self.param_groups: + weight_decay = group['weight_decay'] + momentum = group['momentum'] + if momentum == 0: + state_combined = defaultdict(dict) + state_combined['momentum_buffer'] = None + stash.param_state_combined_list.append(state_combined) + continue + + momentum_buffer_list = [] + for p in group['params']: + if p.grad is None: + continue + + d_p = p.grad + state = self.state[p] + if 'momentum_buffer' not in state: + momentum_buffer_in_state_before = False + if weight_decay != 0: + d_p = d_p.add(p, alpha=weight_decay) + state['momentum_buffer'] = torch.clone(d_p).detach() + else: + temp = torch.clone(d_p).detach() + temp.copy_(state['momentum_buffer']) + state['momentum_buffer'] = temp + + momentum_buffer_list.append(state['momentum_buffer']) + + momentum_buffer_combined = None + if len(momentum_buffer_list) > 0: + momentum_buffer_combined = combine_npu(momentum_buffer_list) + + state_combined = defaultdict(dict) + state_combined['momentum_buffer'] = momentum_buffer_combined + stash.param_state_combined_list.append(state_combined) + + stash.param_state_combined = True + + @torch.no_grad() + def step(self, closure=None): + """Performs a single optimization step. + + Arguments: + closure (callable, optional): A closure that reevaluates the model + and returns the loss. + """ + if not hasattr(self, "_amp_stash"): + raise RuntimeError('apex.optimizers.NpuFusedSGD should be used with AMP.') + + momentum_buffer_in_state_before = True + self._combine_params_and_grads_by_group() + self.combine_param_state_by_group(momentum_buffer_in_state_before) + + loss = None + if closure is not None: + with torch.enable_grad(): + loss = closure() + + stash = self._amp_stash + + for i, group in enumerate(self.param_groups): + weight_decay = group['weight_decay'] + momentum = group['momentum'] + dampening = group['dampening'] + nesterov = group['nesterov'] + + params_combined = stash.params_combined_list[i] + grads_combined = stash.grads_combined_list[i] + if params_combined is None or grads_combined is None: + continue + + if weight_decay != 0: + grads_combined = grads_combined.add(params_combined, alpha=weight_decay) + if momentum != 0: + param_state = stash.param_state_combined_list[i] + buf = param_state['momentum_buffer'] + if momentum_buffer_in_state_before: + buf.mul_(momentum).add_(grads_combined, alpha=1 - dampening) + + if nesterov: + grads_combined = grads_combined.add(buf, alpha=momentum) + else: + grads_combined = buf + + params_combined.add_(grads_combined, alpha=-group['lr']) + + return loss diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/timer.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/timer.py index f2c0c2284e0bed46d3f24b5edd65c003cd4de568..1478b7efaac7b4e00a9db6302d790f0dbcc51f9d 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/timer.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/core/timer.py @@ -1,53 +1,53 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Timer.""" - -import time - - -class Timer(object): - """A simple timer (adapted from Detectron).""" - - def __init__(self): - self.total_time = None - self.calls = None - self.start_time = None - self.diff = None - self.average_time = None - self.reset() - - def tic(self): - # using time.time as time.clock does not normalize for multithreading - self.start_time = time.time() - - def toc(self): - self.diff = time.time() - self.start_time - self.total_time += self.diff - self.calls += 1 - self.average_time = self.total_time / self.calls - - def reset(self): - self.total_time = 0.0 - self.calls = 0 - self.start_time = 0.0 - self.diff = 0.0 - self.average_time = 0.0 +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Timer.""" + +import time + + +class Timer(object): + """A simple timer (adapted from Detectron).""" + + def __init__(self): + self.total_time = None + self.calls = None + self.start_time = None + self.diff = None + self.average_time = None + self.reset() + + def tic(self): + # using time.time as time.clock does not normalize for multithreading + self.start_time = time.time() + + def toc(self): + self.diff = time.time() - self.start_time + self.total_time += self.diff + self.calls += 1 + self.average_time = self.total_time / self.calls + + def reset(self): + self.total_time = 0.0 + self.calls = 0 + self.start_time = 0.0 + self.diff = 0.0 + self.average_time = 0.0 diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/augment.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/augment.py index 4f29c66d77679562ed1fb2991e87ccf3caeff8c8..ba5e1426ed5276e63312be57621d68a4a265bb27 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/augment.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/augment.py @@ -1,248 +1,248 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -""" -Lightweight and simple implementation of AutoAugment and RandAugment. - -AutoAugment - https://arxiv.org/abs/1805.09501 -RandAugment - https://arxiv.org/abs/1909.13719 - -http://github.com/tensorflow/tpu/blob/master/models/official/efficientnet/autoaugment.py -Note that the official implementation varies substantially from the papers :-( - -Our AutoAugment policy should be fairly identical to the official AutoAugment policy. -The main difference is we set POSTERIZE_MIN = 1, which avoids degenerate (all 0) images. -Our RandAugment policy differs, and uses transforms that increase in intensity with -increasing magnitude. This allows for a more natural control of the magnitude. That is, -setting magnitude = 0 results in ops that leaves the image unchanged, if possible. -We also set the range of the magnitude to be 0 to 1 to avoid setting a "max level". - -Our implementation is inspired by and uses policies that are the similar to those in: -https://github.com/rwightman/pytorch-image-models/blob/master/timm/data/auto_augment.py -Specifically our implementation can be *numerically identical* as the implementation in -timm if using timm's "v0" policy for AutoAugment and "inc" transforms for RandAugment -and if we set POSTERIZE_MIN = 0 (although as noted our default is POSTERIZE_MIN = 1). -Note that magnitude in our code ranges from 0 to 1 (compared to 0 to 10 in timm). - -Specifically, given the same seeds, the functions from timm: - out_auto = auto_augment_transform("v0", {"interpolation": 2})(im) - out_rand = rand_augment_transform("rand-inc1-n2-m05", {"interpolation": 2})(im) -Are numerically equivalent to: - POSTERIZE_MIN = 0 - out_auto = auto_augment(im) - out_rand = rand_augment(im, prob=0.5, n_ops=2, magnitude=0.5) -Tested as of 10/07/2020. Can alter corresponding params for both and should match. - -Finally, the ops and augmentations can be visualized as follows: - from PIL import Image - import pycls.datasets.augment as augment - im = Image.open("scratch.jpg") - im_ops = augment.visualize_ops(im) - im_rand = augment.visualize_aug(im, augment=augment.rand_augment, magnitude=0.5) - im_auto = augment.visualize_aug(im, augment=augment.auto_augment) - im_ops.show() - im_auto.show() - im_rand.show() -""" - -import random - -import numpy as np -from PIL import Image, ImageEnhance, ImageOps - - -# Minimum value for posterize (0 in EfficientNet implementation) -POSTERIZE_MIN = 1 - -# Parameters for affine warping and rotation -WARP_PARAMS = {"fillcolor": (128, 128, 128), "resample": Image.BILINEAR} - - -def affine_warp(im, data): - """Applies affine transform to image.""" - return im.transform(im.size, Image.AFFINE, data, **WARP_PARAMS) - - -OP_FUNCTIONS = { - # Each op takes an image x and a level v and returns an augmented image. - "auto_contrast": lambda x, _: ImageOps.autocontrast(x), - "equalize": lambda x, _: ImageOps.equalize(x), - "invert": lambda x, _: ImageOps.invert(x), - "rotate": lambda x, v: x.rotate(v, **WARP_PARAMS), - "posterize": lambda x, v: ImageOps.posterize(x, max(POSTERIZE_MIN, int(v))), - "posterize_inc": lambda x, v: ImageOps.posterize(x, max(POSTERIZE_MIN, 4 - int(v))), - "solarize": lambda x, v: x.point(lambda i: i if i < int(v) else 255 - i), - "solarize_inc": lambda x, v: x.point(lambda i: i if i < 256 - v else 255 - i), - "solarize_add": lambda x, v: x.point(lambda i: min(255, v + i) if i < 128 else i), - "color": lambda x, v: ImageEnhance.Color(x).enhance(v), - "contrast": lambda x, v: ImageEnhance.Contrast(x).enhance(v), - "brightness": lambda x, v: ImageEnhance.Brightness(x).enhance(v), - "sharpness": lambda x, v: ImageEnhance.Sharpness(x).enhance(v), - "color_inc": lambda x, v: ImageEnhance.Color(x).enhance(1 + v), - "contrast_inc": lambda x, v: ImageEnhance.Contrast(x).enhance(1 + v), - "brightness_inc": lambda x, v: ImageEnhance.Brightness(x).enhance(1 + v), - "sharpness_inc": lambda x, v: ImageEnhance.Sharpness(x).enhance(1 + v), - "shear_x": lambda x, v: affine_warp(x, (1, v, 0, 0, 1, 0)), - "shear_y": lambda x, v: affine_warp(x, (1, 0, 0, v, 1, 0)), - "trans_x": lambda x, v: affine_warp(x, (1, 0, v * x.size[0], 0, 1, 0)), - "trans_y": lambda x, v: affine_warp(x, (1, 0, 0, 0, 1, v * x.size[1])), -} - - -OP_RANGES = { - # Ranges for each op in the form of a (min, max, negate). - "auto_contrast": (0, 1, False), - "equalize": (0, 1, False), - "invert": (0, 1, False), - "rotate": (0.0, 30.0, True), - "posterize": (0, 4, False), - "posterize_inc": (0, 4, False), - "solarize": (0, 256, False), - "solarize_inc": (0, 256, False), - "solarize_add": (0, 110, False), - "color": (0.1, 1.9, False), - "contrast": (0.1, 1.9, False), - "brightness": (0.1, 1.9, False), - "sharpness": (0.1, 1.9, False), - "color_inc": (0, 0.9, True), - "contrast_inc": (0, 0.9, True), - "brightness_inc": (0, 0.9, True), - "sharpness_inc": (0, 0.9, True), - "shear_x": (0.0, 0.3, True), - "shear_y": (0.0, 0.3, True), - "trans_x": (0.0, 0.45, True), - "trans_y": (0.0, 0.45, True), -} - - -AUTOAUG_POLICY = [ - # AutoAugment "policy_v0" in form of (op, prob, magnitude), where magnitude <= 1. - [("equalize", 0.8, 0.1), ("shear_y", 0.8, 0.4)], - [("color", 0.4, 0.9), ("equalize", 0.6, 0.3)], - [("color", 0.4, 0.1), ("rotate", 0.6, 0.8)], - [("solarize", 0.8, 0.3), ("equalize", 0.4, 0.7)], - [("solarize", 0.4, 0.2), ("solarize", 0.6, 0.2)], - [("color", 0.2, 0.0), ("equalize", 0.8, 0.8)], - [("equalize", 0.4, 0.8), ("solarize_add", 0.8, 0.3)], - [("shear_x", 0.2, 0.9), ("rotate", 0.6, 0.8)], - [("color", 0.6, 0.1), ("equalize", 1.0, 0.2)], - [("invert", 0.4, 0.9), ("rotate", 0.6, 0.0)], - [("equalize", 1.0, 0.9), ("shear_y", 0.6, 0.3)], - [("color", 0.4, 0.7), ("equalize", 0.6, 0.0)], - [("posterize", 0.4, 0.6), ("auto_contrast", 0.4, 0.7)], - [("solarize", 0.6, 0.8), ("color", 0.6, 0.9)], - [("solarize", 0.2, 0.4), ("rotate", 0.8, 0.9)], - [("rotate", 1.0, 0.7), ("trans_y", 0.8, 0.9)], - [("shear_x", 0.0, 0.0), ("solarize", 0.8, 0.4)], - [("shear_y", 0.8, 0.0), ("color", 0.6, 0.4)], - [("color", 1.0, 0.0), ("rotate", 0.6, 0.2)], - [("equalize", 0.8, 0.4), ("equalize", 0.0, 0.8)], - [("equalize", 1.0, 0.4), ("auto_contrast", 0.6, 0.2)], - [("shear_y", 0.4, 0.7), ("solarize_add", 0.6, 0.7)], - [("posterize", 0.8, 0.2), ("solarize", 0.6, 1.0)], - [("solarize", 0.6, 0.8), ("equalize", 0.6, 0.1)], - [("color", 0.8, 0.6), ("rotate", 0.4, 0.5)], -] - - -RANDAUG_OPS = [ - # RandAugment list of operations using "increasing" transforms. - "auto_contrast", - "equalize", - "invert", - "rotate", - "posterize_inc", - "solarize_inc", - "solarize_add", - "color_inc", - "contrast_inc", - "brightness_inc", - "sharpness_inc", - "shear_x", - "shear_y", - "trans_x", - "trans_y", -] - - -def apply_op(im, op, prob, magnitude): - """Apply the selected op to image with given probability and magnitude.""" - # The magnitude is converted to an absolute value v for an op (some ops use -v or v) - assert 0 <= magnitude <= 1 - assert op in OP_RANGES and op in OP_FUNCTIONS, "unknown op " + op - if prob < 1 and random.random() > prob: - return im - min_v, max_v, negate = OP_RANGES[op] - v = magnitude * (max_v - min_v) + min_v - v = -v if negate and random.random() > 0.5 else v - return OP_FUNCTIONS[op](im, v) - - -def rand_augment(im, magnitude, ops=None, n_ops=2, prob=1.0): - """Applies random augmentation to an image.""" - ops = ops if ops else RANDAUG_OPS - for op in np.random.choice(ops, int(n_ops)): - im = apply_op(im, op, prob, magnitude) - return im - - -def auto_augment(im, policy=None): - """Apply auto augmentation to an image.""" - policy = policy if policy else AUTOAUG_POLICY - for op, prob, magnitude in random.choice(policy): - im = apply_op(im, op, prob, magnitude) - return im - - -def make_augment(augment_str): - """Generate augmentation function from separated parameter string. - The parameter string augment_str may be either "AutoAugment" or "RandAugment". - Undocumented use allows for specifying extra params, e.g. "RandAugment_N2_M0.5".""" - params = augment_str.split("_") - names = {"N": "n_ops", "M": "magnitude", "P": "prob"} - assert params[0] in ["RandAugment", "AutoAugment"] - assert all(p[0] in names for p in params[1:]) - keys = [names[p[0]] for p in params[1:]] - vals = [float(p[1:]) for p in params[1:]] - augment = rand_augment if params[0] == "RandAugment" else auto_augment - return lambda im: augment(im, **dict(zip(keys, vals))) - - -def visualize_ops(im, ops=None, num_steps=10): - """Visualize ops by applying each op by varying amounts.""" - ops = ops if ops else RANDAUG_OPS - w, h, magnitudes = im.size[0], im.size[1], np.linspace(0, 1, num_steps) - output = Image.new("RGB", (w * num_steps, h * len(ops))) - for i, op in enumerate(ops): - for j, m in enumerate(magnitudes): - out = apply_op(im, op, prob=1.0, magnitude=m) - output.paste(out, (j * w, i * h)) - return output - - -def visualize_aug(im, augment=rand_augment, num_trials=10, **kwargs): - """Visualize augmentation by applying random augmentations.""" - w, h = im.size[0], im.size[1] - output = Image.new("RGB", (w * num_trials, h * num_trials)) - for i in range(num_trials): - for j in range(num_trials): - output.paste(augment(im, **kwargs), (j * w, i * h)) - return output +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Lightweight and simple implementation of AutoAugment and RandAugment. + +AutoAugment - https://arxiv.org/abs/1805.09501 +RandAugment - https://arxiv.org/abs/1909.13719 + +http://github.com/tensorflow/tpu/blob/master/models/official/efficientnet/autoaugment.py +Note that the official implementation varies substantially from the papers :-( + +Our AutoAugment policy should be fairly identical to the official AutoAugment policy. +The main difference is we set POSTERIZE_MIN = 1, which avoids degenerate (all 0) images. +Our RandAugment policy differs, and uses transforms that increase in intensity with +increasing magnitude. This allows for a more natural control of the magnitude. That is, +setting magnitude = 0 results in ops that leaves the image unchanged, if possible. +We also set the range of the magnitude to be 0 to 1 to avoid setting a "max level". + +Our implementation is inspired by and uses policies that are the similar to those in: +https://github.com/rwightman/pytorch-image-models/blob/master/timm/data/auto_augment.py +Specifically our implementation can be *numerically identical* as the implementation in +timm if using timm's "v0" policy for AutoAugment and "inc" transforms for RandAugment +and if we set POSTERIZE_MIN = 0 (although as noted our default is POSTERIZE_MIN = 1). +Note that magnitude in our code ranges from 0 to 1 (compared to 0 to 10 in timm). + +Specifically, given the same seeds, the functions from timm: + out_auto = auto_augment_transform("v0", {"interpolation": 2})(im) + out_rand = rand_augment_transform("rand-inc1-n2-m05", {"interpolation": 2})(im) +Are numerically equivalent to: + POSTERIZE_MIN = 0 + out_auto = auto_augment(im) + out_rand = rand_augment(im, prob=0.5, n_ops=2, magnitude=0.5) +Tested as of 10/07/2020. Can alter corresponding params for both and should match. + +Finally, the ops and augmentations can be visualized as follows: + from PIL import Image + import pycls.datasets.augment as augment + im = Image.open("scratch.jpg") + im_ops = augment.visualize_ops(im) + im_rand = augment.visualize_aug(im, augment=augment.rand_augment, magnitude=0.5) + im_auto = augment.visualize_aug(im, augment=augment.auto_augment) + im_ops.show() + im_auto.show() + im_rand.show() +""" + +import random + +import numpy as np +from PIL import Image, ImageEnhance, ImageOps + + +# Minimum value for posterize (0 in EfficientNet implementation) +POSTERIZE_MIN = 1 + +# Parameters for affine warping and rotation +WARP_PARAMS = {"fillcolor": (128, 128, 128), "resample": Image.BILINEAR} + + +def affine_warp(im, data): + """Applies affine transform to image.""" + return im.transform(im.size, Image.AFFINE, data, **WARP_PARAMS) + + +OP_FUNCTIONS = { + # Each op takes an image x and a level v and returns an augmented image. + "auto_contrast": lambda x, _: ImageOps.autocontrast(x), + "equalize": lambda x, _: ImageOps.equalize(x), + "invert": lambda x, _: ImageOps.invert(x), + "rotate": lambda x, v: x.rotate(v, **WARP_PARAMS), + "posterize": lambda x, v: ImageOps.posterize(x, max(POSTERIZE_MIN, int(v))), + "posterize_inc": lambda x, v: ImageOps.posterize(x, max(POSTERIZE_MIN, 4 - int(v))), + "solarize": lambda x, v: x.point(lambda i: i if i < int(v) else 255 - i), + "solarize_inc": lambda x, v: x.point(lambda i: i if i < 256 - v else 255 - i), + "solarize_add": lambda x, v: x.point(lambda i: min(255, v + i) if i < 128 else i), + "color": lambda x, v: ImageEnhance.Color(x).enhance(v), + "contrast": lambda x, v: ImageEnhance.Contrast(x).enhance(v), + "brightness": lambda x, v: ImageEnhance.Brightness(x).enhance(v), + "sharpness": lambda x, v: ImageEnhance.Sharpness(x).enhance(v), + "color_inc": lambda x, v: ImageEnhance.Color(x).enhance(1 + v), + "contrast_inc": lambda x, v: ImageEnhance.Contrast(x).enhance(1 + v), + "brightness_inc": lambda x, v: ImageEnhance.Brightness(x).enhance(1 + v), + "sharpness_inc": lambda x, v: ImageEnhance.Sharpness(x).enhance(1 + v), + "shear_x": lambda x, v: affine_warp(x, (1, v, 0, 0, 1, 0)), + "shear_y": lambda x, v: affine_warp(x, (1, 0, 0, v, 1, 0)), + "trans_x": lambda x, v: affine_warp(x, (1, 0, v * x.size[0], 0, 1, 0)), + "trans_y": lambda x, v: affine_warp(x, (1, 0, 0, 0, 1, v * x.size[1])), +} + + +OP_RANGES = { + # Ranges for each op in the form of a (min, max, negate). + "auto_contrast": (0, 1, False), + "equalize": (0, 1, False), + "invert": (0, 1, False), + "rotate": (0.0, 30.0, True), + "posterize": (0, 4, False), + "posterize_inc": (0, 4, False), + "solarize": (0, 256, False), + "solarize_inc": (0, 256, False), + "solarize_add": (0, 110, False), + "color": (0.1, 1.9, False), + "contrast": (0.1, 1.9, False), + "brightness": (0.1, 1.9, False), + "sharpness": (0.1, 1.9, False), + "color_inc": (0, 0.9, True), + "contrast_inc": (0, 0.9, True), + "brightness_inc": (0, 0.9, True), + "sharpness_inc": (0, 0.9, True), + "shear_x": (0.0, 0.3, True), + "shear_y": (0.0, 0.3, True), + "trans_x": (0.0, 0.45, True), + "trans_y": (0.0, 0.45, True), +} + + +AUTOAUG_POLICY = [ + # AutoAugment "policy_v0" in form of (op, prob, magnitude), where magnitude <= 1. + [("equalize", 0.8, 0.1), ("shear_y", 0.8, 0.4)], + [("color", 0.4, 0.9), ("equalize", 0.6, 0.3)], + [("color", 0.4, 0.1), ("rotate", 0.6, 0.8)], + [("solarize", 0.8, 0.3), ("equalize", 0.4, 0.7)], + [("solarize", 0.4, 0.2), ("solarize", 0.6, 0.2)], + [("color", 0.2, 0.0), ("equalize", 0.8, 0.8)], + [("equalize", 0.4, 0.8), ("solarize_add", 0.8, 0.3)], + [("shear_x", 0.2, 0.9), ("rotate", 0.6, 0.8)], + [("color", 0.6, 0.1), ("equalize", 1.0, 0.2)], + [("invert", 0.4, 0.9), ("rotate", 0.6, 0.0)], + [("equalize", 1.0, 0.9), ("shear_y", 0.6, 0.3)], + [("color", 0.4, 0.7), ("equalize", 0.6, 0.0)], + [("posterize", 0.4, 0.6), ("auto_contrast", 0.4, 0.7)], + [("solarize", 0.6, 0.8), ("color", 0.6, 0.9)], + [("solarize", 0.2, 0.4), ("rotate", 0.8, 0.9)], + [("rotate", 1.0, 0.7), ("trans_y", 0.8, 0.9)], + [("shear_x", 0.0, 0.0), ("solarize", 0.8, 0.4)], + [("shear_y", 0.8, 0.0), ("color", 0.6, 0.4)], + [("color", 1.0, 0.0), ("rotate", 0.6, 0.2)], + [("equalize", 0.8, 0.4), ("equalize", 0.0, 0.8)], + [("equalize", 1.0, 0.4), ("auto_contrast", 0.6, 0.2)], + [("shear_y", 0.4, 0.7), ("solarize_add", 0.6, 0.7)], + [("posterize", 0.8, 0.2), ("solarize", 0.6, 1.0)], + [("solarize", 0.6, 0.8), ("equalize", 0.6, 0.1)], + [("color", 0.8, 0.6), ("rotate", 0.4, 0.5)], +] + + +RANDAUG_OPS = [ + # RandAugment list of operations using "increasing" transforms. + "auto_contrast", + "equalize", + "invert", + "rotate", + "posterize_inc", + "solarize_inc", + "solarize_add", + "color_inc", + "contrast_inc", + "brightness_inc", + "sharpness_inc", + "shear_x", + "shear_y", + "trans_x", + "trans_y", +] + + +def apply_op(im, op, prob, magnitude): + """Apply the selected op to image with given probability and magnitude.""" + # The magnitude is converted to an absolute value v for an op (some ops use -v or v) + assert 0 <= magnitude <= 1 + assert op in OP_RANGES and op in OP_FUNCTIONS, "unknown op " + op + if prob < 1 and random.random() > prob: + return im + min_v, max_v, negate = OP_RANGES[op] + v = magnitude * (max_v - min_v) + min_v + v = -v if negate and random.random() > 0.5 else v + return OP_FUNCTIONS[op](im, v) + + +def rand_augment(im, magnitude, ops=None, n_ops=2, prob=1.0): + """Applies random augmentation to an image.""" + ops = ops if ops else RANDAUG_OPS + for op in np.random.choice(ops, int(n_ops)): + im = apply_op(im, op, prob, magnitude) + return im + + +def auto_augment(im, policy=None): + """Apply auto augmentation to an image.""" + policy = policy if policy else AUTOAUG_POLICY + for op, prob, magnitude in random.choice(policy): + im = apply_op(im, op, prob, magnitude) + return im + + +def make_augment(augment_str): + """Generate augmentation function from separated parameter string. + The parameter string augment_str may be either "AutoAugment" or "RandAugment". + Undocumented use allows for specifying extra params, e.g. "RandAugment_N2_M0.5".""" + params = augment_str.split("_") + names = {"N": "n_ops", "M": "magnitude", "P": "prob"} + assert params[0] in ["RandAugment", "AutoAugment"] + assert all(p[0] in names for p in params[1:]) + keys = [names[p[0]] for p in params[1:]] + vals = [float(p[1:]) for p in params[1:]] + augment = rand_augment if params[0] == "RandAugment" else auto_augment + return lambda im: augment(im, **dict(zip(keys, vals))) + + +def visualize_ops(im, ops=None, num_steps=10): + """Visualize ops by applying each op by varying amounts.""" + ops = ops if ops else RANDAUG_OPS + w, h, magnitudes = im.size[0], im.size[1], np.linspace(0, 1, num_steps) + output = Image.new("RGB", (w * num_steps, h * len(ops))) + for i, op in enumerate(ops): + for j, m in enumerate(magnitudes): + out = apply_op(im, op, prob=1.0, magnitude=m) + output.paste(out, (j * w, i * h)) + return output + + +def visualize_aug(im, augment=rand_augment, num_trials=10, **kwargs): + """Visualize augmentation by applying random augmentations.""" + w, h = im.size[0], im.size[1] + output = Image.new("RGB", (w * num_trials, h * num_trials)) + for i in range(num_trials): + for j in range(num_trials): + output.paste(augment(im, **kwargs), (j * w, i * h)) + return output diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/cifar10.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/cifar10.py index f2ed7434b2e6050b205406c4c75119016f497425..9922ca032af8bb394ca3eeebea25dc54d2a58668 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/cifar10.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/cifar10.py @@ -1,95 +1,95 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""CIFAR10 dataset.""" - -import os -import pickle - -import numpy as np -import pycls.core.logging as logging -import torch.utils.data -from iopath.common.file_io import g_pathmgr -from pycls.core.config import cfg - - -logger = logging.get_logger(__name__) - -# Per-channel mean and standard deviation values on CIFAR -_MEAN = [125.3, 123.0, 113.9] -_STD = [63.0, 62.1, 66.7] - - -class Cifar10(torch.utils.data.Dataset): - """CIFAR-10 dataset.""" - - def __init__(self, data_path, split): - assert g_pathmgr.exists(data_path), "Data path '{}' not found".format(data_path) - splits = ["train", "test"] - assert split in splits, "Split '{}' not supported for cifar".format(split) - logger.info("Constructing CIFAR-10 {}...".format(split)) - self._im_size = cfg.TRAIN.IM_SIZE - self._data_path, self._split = data_path, split - self._inputs, self._labels = self._load_data() - - def _load_data(self): - """Loads data into memory.""" - logger.info("{} data path: {}".format(self._split, self._data_path)) - # Compute data batch names - if self._split == "train": - batch_names = ["data_batch_{}".format(i) for i in range(1, 6)] - else: - batch_names = ["test_batch"] - # Load data batches - inputs, labels = [], [] - for batch_name in batch_names: - batch_path = os.path.join(self._data_path, batch_name) - with g_pathmgr.open(batch_path, "rb") as f: - data = pickle.load(f, encoding="bytes") - inputs.append(data[b"data"]) - labels += data[b"labels"] - # Combine and reshape the inputs - inputs = np.vstack(inputs).astype(np.float32) - inputs = inputs.reshape((-1, 3, self._im_size, self._im_size)) - return inputs, labels - - def _prepare_im(self, im): - """Prepares the image for network input.""" - for i in range(3): - # Perform per-channel normalization on CHW image - im[i] = (im[i] - _MEAN[i]) / _STD[i] - if self._split == "train": - # Randomly flip and crop center patch from CHW image - size = self._im_size - im = im[:, :, ::-1] if np.random.uniform() < 0.5 else im - im = np.pad(im, ((0, 0), (4, 4), (4, 4)), mode="constant") - y = np.random.randint(0, im.shape[1] - size) - x = np.random.randint(0, im.shape[2] - size) - im = im[:, y : (y + size), x : (x + size)] - return im - - def __getitem__(self, index): - im, label = self._inputs[index, ...].copy(), self._labels[index] - im = self._prepare_im(im) - return im, label - - def __len__(self): - return self._inputs.shape[0] +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""CIFAR10 dataset.""" + +import os +import pickle + +import numpy as np +import pycls.core.logging as logging +import torch.utils.data +from iopath.common.file_io import g_pathmgr +from pycls.core.config import cfg + + +logger = logging.get_logger(__name__) + +# Per-channel mean and standard deviation values on CIFAR +_MEAN = [125.3, 123.0, 113.9] +_STD = [63.0, 62.1, 66.7] + + +class Cifar10(torch.utils.data.Dataset): + """CIFAR-10 dataset.""" + + def __init__(self, data_path, split): + assert g_pathmgr.exists(data_path), "Data path '{}' not found".format(data_path) + splits = ["train", "test"] + assert split in splits, "Split '{}' not supported for cifar".format(split) + logger.info("Constructing CIFAR-10 {}...".format(split)) + self._im_size = cfg.TRAIN.IM_SIZE + self._data_path, self._split = data_path, split + self._inputs, self._labels = self._load_data() + + def _load_data(self): + """Loads data into memory.""" + logger.info("{} data path: {}".format(self._split, self._data_path)) + # Compute data batch names + if self._split == "train": + batch_names = ["data_batch_{}".format(i) for i in range(1, 6)] + else: + batch_names = ["test_batch"] + # Load data batches + inputs, labels = [], [] + for batch_name in batch_names: + batch_path = os.path.join(self._data_path, batch_name) + with g_pathmgr.open(batch_path, "rb") as f: + data = pickle.load(f, encoding="bytes") + inputs.append(data[b"data"]) + labels += data[b"labels"] + # Combine and reshape the inputs + inputs = np.vstack(inputs).astype(np.float32) + inputs = inputs.reshape((-1, 3, self._im_size, self._im_size)) + return inputs, labels + + def _prepare_im(self, im): + """Prepares the image for network input.""" + for i in range(3): + # Perform per-channel normalization on CHW image + im[i] = (im[i] - _MEAN[i]) / _STD[i] + if self._split == "train": + # Randomly flip and crop center patch from CHW image + size = self._im_size + im = im[:, :, ::-1] if np.random.uniform() < 0.5 else im + im = np.pad(im, ((0, 0), (4, 4), (4, 4)), mode="constant") + y = np.random.randint(0, im.shape[1] - size) + x = np.random.randint(0, im.shape[2] - size) + im = im[:, y : (y + size), x : (x + size)] + return im + + def __getitem__(self, index): + im, label = self._inputs[index, ...].copy(), self._labels[index] + im = self._prepare_im(im) + return im, label + + def __len__(self): + return self._inputs.shape[0] diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/imagenet.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/imagenet.py index 8234ec4a4032308941ca61f1148d8aed5bd058cf..31edfb723f19cb7c9329e73a4b4e16fba02af144 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/imagenet.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/imagenet.py @@ -1,116 +1,116 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""ImageNet dataset.""" - -import os -import re - -import cv2 -cv2.setNumThreads(1) -import numpy as np -import pycls.core.logging as logging -import pycls.datasets.transforms as transforms -import torch.utils.data -from pycls.core.config import cfg - - -logger = logging.get_logger(__name__) - -# Per-channel mean and standard deviation values on ImageNet (in RGB order) -# https://github.com/facebookarchive/fb.resnet.torch/blob/master/datasets/imagenet.lua -_MEAN = [0.485, 0.456, 0.406] -_STD = [0.229, 0.224, 0.225] - -# Constants for lighting normalization on ImageNet (in RGB order) -# https://github.com/facebookarchive/fb.resnet.torch/blob/master/datasets/imagenet.lua -_EIG_VALS = [[0.2175, 0.0188, 0.0045]] -_EIG_VECS = [ - [-0.5675, 0.7192, 0.4009], - [-0.5808, -0.0045, -0.8140], - [-0.5836, -0.6948, 0.4203], -] - - -class ImageNet(torch.utils.data.Dataset): - """ImageNet dataset.""" - - def __init__(self, data_path, split): - assert os.path.exists(data_path), "Data path '{}' not found".format(data_path) - splits = ["train", "val"] - assert split in splits, "Split '{}' not supported for ImageNet".format(split) - logger.info("Constructing ImageNet {}...".format(split)) - self._data_path, self._split = data_path, split - self._construct_imdb() - - def _construct_imdb(self): - """Constructs the imdb.""" - # Compile the split data path - split_path = os.path.join(self._data_path, self._split) - logger.info("{} data path: {}".format(self._split, split_path)) - # Images are stored per class in subdirs (format: n) - split_files = os.listdir(split_path) - self._class_ids = sorted(f for f in split_files if re.match(r"^n[0-9]+$", f)) - # Map ImageNet class ids to contiguous ids - self._class_id_cont_id = {v: i for i, v in enumerate(self._class_ids)} - # Construct the image db - self._imdb = [] - for class_id in self._class_ids: - cont_id = self._class_id_cont_id[class_id] - im_dir = os.path.join(split_path, class_id) - for im_name in os.listdir(im_dir): - im_path = os.path.join(im_dir, im_name) - self._imdb.append({"im_path": im_path, "class": cont_id}) - logger.info("Number of images: {}".format(len(self._imdb))) - logger.info("Number of classes: {}".format(len(self._class_ids))) - - def _prepare_im(self, im): - """Prepares the image for network input (HWC/BGR/int -> CHW/BGR/float).""" - # Convert HWC/BGR/int to HWC/RGB/float format for applying transforms - im = im[:, :, ::-1].astype(np.float32) / 255 - # Train and test setups differ - train_size, test_size = cfg.TRAIN.IM_SIZE, cfg.TEST.IM_SIZE - if self._split == "train": - # For training use random_sized_crop, horizontal_flip, augment, lighting - im = transforms.random_sized_crop(im, train_size) - im = transforms.horizontal_flip(im, prob=0.5) - im = transforms.augment(im, cfg.TRAIN.AUGMENT) - im = transforms.lighting(im, cfg.TRAIN.PCA_STD, _EIG_VALS, _EIG_VECS) - else: - # For testing use scale and center crop - im = transforms.scale_and_center_crop(im, test_size, train_size) - # For training and testing use color normalization - im = transforms.color_norm(im, _MEAN, _STD) - # Convert HWC/RGB/float to CHW/BGR/float format - im = np.ascontiguousarray(im[:, :, ::-1].transpose([2, 0, 1])) - return im - - def __getitem__(self, index): - # Load the image - im = cv2.imread(self._imdb[index]["im_path"]) - # Prepare the image for training / testing - im = self._prepare_im(im) - # Retrieve the label - label = self._imdb[index]["class"] - return im, label - - def __len__(self): - return len(self._imdb) +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""ImageNet dataset.""" + +import os +import re + +import cv2 +cv2.setNumThreads(1) +import numpy as np +import pycls.core.logging as logging +import pycls.datasets.transforms as transforms +import torch.utils.data +from pycls.core.config import cfg + + +logger = logging.get_logger(__name__) + +# Per-channel mean and standard deviation values on ImageNet (in RGB order) +# https://github.com/facebookarchive/fb.resnet.torch/blob/master/datasets/imagenet.lua +_MEAN = [0.485, 0.456, 0.406] +_STD = [0.229, 0.224, 0.225] + +# Constants for lighting normalization on ImageNet (in RGB order) +# https://github.com/facebookarchive/fb.resnet.torch/blob/master/datasets/imagenet.lua +_EIG_VALS = [[0.2175, 0.0188, 0.0045]] +_EIG_VECS = [ + [-0.5675, 0.7192, 0.4009], + [-0.5808, -0.0045, -0.8140], + [-0.5836, -0.6948, 0.4203], +] + + +class ImageNet(torch.utils.data.Dataset): + """ImageNet dataset.""" + + def __init__(self, data_path, split): + assert os.path.exists(data_path), "Data path '{}' not found".format(data_path) + splits = ["train", "val"] + assert split in splits, "Split '{}' not supported for ImageNet".format(split) + logger.info("Constructing ImageNet {}...".format(split)) + self._data_path, self._split = data_path, split + self._construct_imdb() + + def _construct_imdb(self): + """Constructs the imdb.""" + # Compile the split data path + split_path = os.path.join(self._data_path, self._split) + logger.info("{} data path: {}".format(self._split, split_path)) + # Images are stored per class in subdirs (format: n) + split_files = os.listdir(split_path) + self._class_ids = sorted(f for f in split_files if re.match(r"^n[0-9]+$", f)) + # Map ImageNet class ids to contiguous ids + self._class_id_cont_id = {v: i for i, v in enumerate(self._class_ids)} + # Construct the image db + self._imdb = [] + for class_id in self._class_ids: + cont_id = self._class_id_cont_id[class_id] + im_dir = os.path.join(split_path, class_id) + for im_name in os.listdir(im_dir): + im_path = os.path.join(im_dir, im_name) + self._imdb.append({"im_path": im_path, "class": cont_id}) + logger.info("Number of images: {}".format(len(self._imdb))) + logger.info("Number of classes: {}".format(len(self._class_ids))) + + def _prepare_im(self, im): + """Prepares the image for network input (HWC/BGR/int -> CHW/BGR/float).""" + # Convert HWC/BGR/int to HWC/RGB/float format for applying transforms + im = im[:, :, ::-1].astype(np.float32) / 255 + # Train and test setups differ + train_size, test_size = cfg.TRAIN.IM_SIZE, cfg.TEST.IM_SIZE + if self._split == "train": + # For training use random_sized_crop, horizontal_flip, augment, lighting + im = transforms.random_sized_crop(im, train_size) + im = transforms.horizontal_flip(im, prob=0.5) + im = transforms.augment(im, cfg.TRAIN.AUGMENT) + im = transforms.lighting(im, cfg.TRAIN.PCA_STD, _EIG_VALS, _EIG_VECS) + else: + # For testing use scale and center crop + im = transforms.scale_and_center_crop(im, test_size, train_size) + # For training and testing use color normalization + im = transforms.color_norm(im, _MEAN, _STD) + # Convert HWC/RGB/float to CHW/BGR/float format + im = np.ascontiguousarray(im[:, :, ::-1].transpose([2, 0, 1])) + return im + + def __getitem__(self, index): + # Load the image + im = cv2.imread(self._imdb[index]["im_path"]) + # Prepare the image for training / testing + im = self._prepare_im(im) + # Retrieve the label + label = self._imdb[index]["class"] + return im, label + + def __len__(self): + return len(self._imdb) diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/loader.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/loader.py index 72d411ddb141d9e752035d19d53da0aac4dbde33..6b772eccd4e825de41d28f091593cb6568af1889 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/loader.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/loader.py @@ -1,96 +1,96 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Data loader.""" - -import os - -import torch -from pycls.core.config import cfg -from pycls.datasets.cifar10 import Cifar10 -from pycls.datasets.imagenet import ImageNet -from torch.utils.data.distributed import DistributedSampler -from torch.utils.data.sampler import RandomSampler - - -# Supported datasets -_DATASETS = {"cifar10": Cifar10, "imagenet": ImageNet} - -# Default data directory (/path/pycls/pycls/datasets/data) -_DATA_DIR = "./pycls/datasets/data" - -# Relative data paths to default data directory -_PATHS = {"cifar10": "cifar10", "imagenet": "imagenet"} - - -def _construct_loader(dataset_name, split, batch_size, shuffle, drop_last): - """Constructs the data loader for the given dataset.""" - err_str = "Dataset '{}' not supported".format(dataset_name) - assert dataset_name in _DATASETS and dataset_name in _PATHS, err_str - # Retrieve the data path for the dataset - data_path = os.path.join(_DATA_DIR, _PATHS[dataset_name]) - # Construct the dataset - dataset = _DATASETS[dataset_name](data_path, split) - # Create a sampler for multi-process training - sampler = DistributedSampler(dataset) if cfg.NUM_GPUS > 1 else None - # Create a loader - loader = torch.utils.data.DataLoader( - dataset, - batch_size=batch_size, - shuffle=(False if sampler else shuffle), - sampler=sampler, - num_workers=cfg.DATA_LOADER.NUM_WORKERS, - pin_memory=cfg.DATA_LOADER.PIN_MEMORY, - drop_last=drop_last, - ) - return loader - - -def construct_train_loader(): - """Train loader wrapper.""" - return _construct_loader( - dataset_name=cfg.TRAIN.DATASET, - split=cfg.TRAIN.SPLIT, - batch_size=int(cfg.TRAIN.BATCH_SIZE / cfg.NUM_GPUS), - shuffle=True, - drop_last=True, - ) - - -def construct_test_loader(): - """Test loader wrapper.""" - return _construct_loader( - dataset_name=cfg.TEST.DATASET, - split=cfg.TEST.SPLIT, - batch_size=int(cfg.TEST.BATCH_SIZE / cfg.NUM_GPUS), - shuffle=False, - drop_last=False, - ) - - -def shuffle(loader, cur_epoch): - """"Shuffles the data.""" - err_str = "Sampler type '{}' not supported".format(type(loader.sampler)) - assert isinstance(loader.sampler, (RandomSampler, DistributedSampler)), err_str - # RandomSampler handles shuffling automatically - if isinstance(loader.sampler, DistributedSampler): - # DistributedSampler shuffles data based on epoch - loader.sampler.set_epoch(cur_epoch) +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Data loader.""" + +import os + +import torch +from pycls.core.config import cfg +from pycls.datasets.cifar10 import Cifar10 +from pycls.datasets.imagenet import ImageNet +from torch.utils.data.distributed import DistributedSampler +from torch.utils.data.sampler import RandomSampler + + +# Supported datasets +_DATASETS = {"cifar10": Cifar10, "imagenet": ImageNet} + +# Default data directory (/path/pycls/pycls/datasets/data) +_DATA_DIR = "./pycls/datasets/data" + +# Relative data paths to default data directory +_PATHS = {"cifar10": "cifar10", "imagenet": "imagenet"} + + +def _construct_loader(dataset_name, split, batch_size, shuffle, drop_last): + """Constructs the data loader for the given dataset.""" + err_str = "Dataset '{}' not supported".format(dataset_name) + assert dataset_name in _DATASETS and dataset_name in _PATHS, err_str + # Retrieve the data path for the dataset + data_path = os.path.join(_DATA_DIR, _PATHS[dataset_name]) + # Construct the dataset + dataset = _DATASETS[dataset_name](data_path, split) + # Create a sampler for multi-process training + sampler = DistributedSampler(dataset) if cfg.NUM_GPUS > 1 else None + # Create a loader + loader = torch.utils.data.DataLoader( + dataset, + batch_size=batch_size, + shuffle=(False if sampler else shuffle), + sampler=sampler, + num_workers=cfg.DATA_LOADER.NUM_WORKERS, + pin_memory=cfg.DATA_LOADER.PIN_MEMORY, + drop_last=drop_last, + ) + return loader + + +def construct_train_loader(): + """Train loader wrapper.""" + return _construct_loader( + dataset_name=cfg.TRAIN.DATASET, + split=cfg.TRAIN.SPLIT, + batch_size=int(cfg.TRAIN.BATCH_SIZE / cfg.NUM_GPUS), + shuffle=True, + drop_last=True, + ) + + +def construct_test_loader(): + """Test loader wrapper.""" + return _construct_loader( + dataset_name=cfg.TEST.DATASET, + split=cfg.TEST.SPLIT, + batch_size=int(cfg.TEST.BATCH_SIZE / cfg.NUM_GPUS), + shuffle=False, + drop_last=False, + ) + + +def shuffle(loader, cur_epoch): + """"Shuffles the data.""" + err_str = "Sampler type '{}' not supported".format(type(loader.sampler)) + assert isinstance(loader.sampler, (RandomSampler, DistributedSampler)), err_str + # RandomSampler handles shuffling automatically + if isinstance(loader.sampler, DistributedSampler): + # DistributedSampler shuffles data based on epoch + loader.sampler.set_epoch(cur_epoch) diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/transforms.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/transforms.py index 4af2bcddb7fa21c25ab71662475304d5af92e78f..cd63be489ad00fe1eeb51c18e8b26bc6304d3402 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/transforms.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/datasets/transforms.py @@ -1,94 +1,94 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Image transformations on HWC float images with RGB channel order.""" - -from math import ceil, sqrt - -import cv2 -import numpy as np -from PIL import Image -from pycls.datasets.augment import make_augment - - -def scale_and_center_crop(im, scale_size, crop_size): - """Performs scaling and center cropping (used for testing).""" - h, w = im.shape[:2] - if w < h and w != scale_size: - w, h = scale_size, int(h / w * scale_size) - im = cv2.resize(im, (w, h), interpolation=cv2.INTER_LINEAR) - elif h <= w and h != scale_size: - w, h = int(w / h * scale_size), scale_size - im = cv2.resize(im, (w, h), interpolation=cv2.INTER_LINEAR) - x = ceil((w - crop_size) / 2) - y = ceil((h - crop_size) / 2) - return im[y : (y + crop_size), x : (x + crop_size), :] - - -def random_sized_crop(im, size, area_frac=0.08, max_iter=10): - """Performs Inception-style cropping (used for training).""" - h, w = im.shape[:2] - area = h * w - for _ in range(max_iter): - target_area = np.random.uniform(area_frac, 1.0) * area - aspect_ratio = np.random.uniform(3.0 / 4.0, 4.0 / 3.0) - w_crop = round(sqrt(target_area * aspect_ratio)) - h_crop = round(sqrt(target_area / aspect_ratio)) - if np.random.uniform() < 0.5: - w_crop, h_crop = h_crop, w_crop - if h_crop <= h and w_crop <= w: - y = 0 if h_crop == h else np.random.randint(0, h - h_crop) - x = 0 if w_crop == w else np.random.randint(0, w - w_crop) - im = im[y : (y + h_crop), x : (x + w_crop), :] - return cv2.resize(im, (size, size), interpolation=cv2.INTER_LINEAR) - return scale_and_center_crop(im, size, size) - - -def horizontal_flip(im, prob=0.5): - """Performs horizontal flip (used for training).""" - return im[:, ::-1, :] if np.random.uniform() < prob else im - - -def augment(im, augment_str): - """Augments image (used for training).""" - if augment_str: - im = Image.fromarray((im * 255).astype(np.uint8)) - im = make_augment(augment_str)(im) - im = np.asarray(im).astype(np.float32) / 255 - return im - - -def lighting(im, alpha_std, eig_val, eig_vec): - """Performs AlexNet-style PCA jitter (used for training).""" - alpha = np.random.normal(0, alpha_std, size=(1, 3)) - alpha = np.repeat(alpha, 3, axis=0) - eig_val = np.repeat(np.array(eig_val), 3, axis=0) - rgb = np.sum(np.array(eig_vec) * alpha * eig_val, axis=1) - for i in range(3): - im[:, :, i] = im[:, :, i] + rgb[i] - return im - - -def color_norm(im, mean, std): - """Performs per-channel normalization (used for training and testing).""" - for i in range(3): - im[:, :, i] = (im[:, :, i] - mean[i]) / std[i] - return im +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Image transformations on HWC float images with RGB channel order.""" + +from math import ceil, sqrt + +import cv2 +import numpy as np +from PIL import Image +from pycls.datasets.augment import make_augment + + +def scale_and_center_crop(im, scale_size, crop_size): + """Performs scaling and center cropping (used for testing).""" + h, w = im.shape[:2] + if w < h and w != scale_size: + w, h = scale_size, int(h / w * scale_size) + im = cv2.resize(im, (w, h), interpolation=cv2.INTER_LINEAR) + elif h <= w and h != scale_size: + w, h = int(w / h * scale_size), scale_size + im = cv2.resize(im, (w, h), interpolation=cv2.INTER_LINEAR) + x = ceil((w - crop_size) / 2) + y = ceil((h - crop_size) / 2) + return im[y : (y + crop_size), x : (x + crop_size), :] + + +def random_sized_crop(im, size, area_frac=0.08, max_iter=10): + """Performs Inception-style cropping (used for training).""" + h, w = im.shape[:2] + area = h * w + for _ in range(max_iter): + target_area = np.random.uniform(area_frac, 1.0) * area + aspect_ratio = np.random.uniform(3.0 / 4.0, 4.0 / 3.0) + w_crop = round(sqrt(target_area * aspect_ratio)) + h_crop = round(sqrt(target_area / aspect_ratio)) + if np.random.uniform() < 0.5: + w_crop, h_crop = h_crop, w_crop + if h_crop <= h and w_crop <= w: + y = 0 if h_crop == h else np.random.randint(0, h - h_crop) + x = 0 if w_crop == w else np.random.randint(0, w - w_crop) + im = im[y : (y + h_crop), x : (x + w_crop), :] + return cv2.resize(im, (size, size), interpolation=cv2.INTER_LINEAR) + return scale_and_center_crop(im, size, size) + + +def horizontal_flip(im, prob=0.5): + """Performs horizontal flip (used for training).""" + return im[:, ::-1, :] if np.random.uniform() < prob else im + + +def augment(im, augment_str): + """Augments image (used for training).""" + if augment_str: + im = Image.fromarray((im * 255).astype(np.uint8)) + im = make_augment(augment_str)(im) + im = np.asarray(im).astype(np.float32) / 255 + return im + + +def lighting(im, alpha_std, eig_val, eig_vec): + """Performs AlexNet-style PCA jitter (used for training).""" + alpha = np.random.normal(0, alpha_std, size=(1, 3)) + alpha = np.repeat(alpha, 3, axis=0) + eig_val = np.repeat(np.array(eig_val), 3, axis=0) + rgb = np.sum(np.array(eig_vec) * alpha * eig_val, axis=1) + for i in range(3): + im[:, :, i] = im[:, :, i] + rgb[i] + return im + + +def color_norm(im, mean, std): + """Performs per-channel normalization (used for training and testing).""" + for i in range(3): + im[:, :, i] = (im[:, :, i] - mean[i]) / std[i] + return im diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/__init__.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/__init__.py index 1f38943d17290e09b00f8976fd0aae38990a7886..9995f91fe8876cf4fe8e6f96163d6dc61083d2ad 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/__init__.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/__init__.py @@ -1,10 +1,10 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -"""Expose model zoo constructors.""" - -from pycls.models.model_zoo import effnet, regnetx, regnety, resnet, resnext +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +"""Expose model zoo constructors.""" + +from pycls.models.model_zoo import effnet, regnetx, regnety, resnet, resnext diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/anynet.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/anynet.py index 3b34dc2c31fc0c6deb6ca808d7175052675f79d9..f25ef7fe227fc10fa3e36621c9ecbe2679ca3972 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/anynet.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/anynet.py @@ -1,375 +1,375 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""AnyNet models.""" - -from pycls.core.config import cfg -from pycls.models.blocks import ( - SE, - activation, - conv2d, - conv2d_cx, - gap2d, - gap2d_cx, - init_weights, - linear, - linear_cx, - norm2d, - norm2d_cx, - pool2d, - pool2d_cx, -) -from torch.nn import Module - - -def get_stem_fun(stem_type): - """Retrieves the stem function by name.""" - stem_funs = { - "res_stem_cifar": ResStemCifar, - "res_stem_in": ResStem, - "simple_stem_in": SimpleStem, - } - err_str = "Stem type '{}' not supported" - assert stem_type in stem_funs.keys(), err_str.format(stem_type) - return stem_funs[stem_type] - - -def get_block_fun(block_type): - """Retrieves the block function by name.""" - block_funs = { - "vanilla_block": VanillaBlock, - "res_basic_block": ResBasicBlock, - "res_bottleneck_block": ResBottleneckBlock, - } - err_str = "Block type '{}' not supported" - assert block_type in block_funs.keys(), err_str.format(block_type) - return block_funs[block_type] - - -class AnyHead(Module): - """AnyNet head: AvgPool, 1x1.""" - - def __init__(self, w_in, num_classes): - super(AnyHead, self).__init__() - self.avg_pool = gap2d(w_in) - self.fc = linear(w_in, num_classes, bias=True) - - def forward(self, x): - x = self.avg_pool(x) - x = x.view(x.size(0), -1) - x = self.fc(x) - return x - - @staticmethod - def complexity(cx, w_in, num_classes): - cx = gap2d_cx(cx, w_in) - cx = linear_cx(cx, w_in, num_classes, bias=True) - return cx - - -class VanillaBlock(Module): - """Vanilla block: [3x3 conv, BN, Relu] x2.""" - - def __init__(self, w_in, w_out, stride, _params): - super(VanillaBlock, self).__init__() - self.a = conv2d(w_in, w_out, 3, stride=stride) - self.a_bn = norm2d(w_out) - self.a_af = activation() - self.b = conv2d(w_out, w_out, 3) - self.b_bn = norm2d(w_out) - self.b_af = activation() - - def forward(self, x): - for layer in self.children(): - x = layer(x) - return x - - @staticmethod - def complexity(cx, w_in, w_out, stride, _params): - cx = conv2d_cx(cx, w_in, w_out, 3, stride=stride) - cx = norm2d_cx(cx, w_out) - cx = conv2d_cx(cx, w_out, w_out, 3) - cx = norm2d_cx(cx, w_out) - return cx - - -class BasicTransform(Module): - """Basic transformation: [3x3 conv, BN, Relu] x2.""" - - def __init__(self, w_in, w_out, stride, _params): - super(BasicTransform, self).__init__() - self.a = conv2d(w_in, w_out, 3, stride=stride) - self.a_bn = norm2d(w_out) - self.a_af = activation() - self.b = conv2d(w_out, w_out, 3) - self.b_bn = norm2d(w_out) - self.b_bn.final_bn = True - - def forward(self, x): - for layer in self.children(): - x = layer(x) - return x - - @staticmethod - def complexity(cx, w_in, w_out, stride, _params): - cx = conv2d_cx(cx, w_in, w_out, 3, stride=stride) - cx = norm2d_cx(cx, w_out) - cx = conv2d_cx(cx, w_out, w_out, 3) - cx = norm2d_cx(cx, w_out) - return cx - - -class ResBasicBlock(Module): - """Residual basic block: x + f(x), f = basic transform.""" - - def __init__(self, w_in, w_out, stride, params): - super(ResBasicBlock, self).__init__() - self.proj, self.bn = None, None - if (w_in != w_out) or (stride != 1): - self.proj = conv2d(w_in, w_out, 1, stride=stride) - self.bn = norm2d(w_out) - self.f = BasicTransform(w_in, w_out, stride, params) - self.af = activation() - - def forward(self, x): - x_p = self.bn(self.proj(x)) if self.proj else x - return self.af(x_p + self.f(x)) - - @staticmethod - def complexity(cx, w_in, w_out, stride, params): - if (w_in != w_out) or (stride != 1): - h, w = cx["h"], cx["w"] - cx = conv2d_cx(cx, w_in, w_out, 1, stride=stride) - cx = norm2d_cx(cx, w_out) - cx["h"], cx["w"] = h, w - cx = BasicTransform.complexity(cx, w_in, w_out, stride, params) - return cx - - -class BottleneckTransform(Module): - """Bottleneck transformation: 1x1, 3x3 [+SE], 1x1.""" - - def __init__(self, w_in, w_out, stride, params): - super(BottleneckTransform, self).__init__() - w_b = int(round(w_out * params["bot_mul"])) - w_se = int(round(w_in * params["se_r"])) - groups = w_b // params["group_w"] - self.a = conv2d(w_in, w_b, 1) - self.a_bn = norm2d(w_b) - self.a_af = activation() - self.b = conv2d(w_b, w_b, 3, stride=stride, groups=groups) - self.b_bn = norm2d(w_b) - self.b_af = activation() - self.se = SE(w_b, w_se) if w_se else None - self.c = conv2d(w_b, w_out, 1) - self.c_bn = norm2d(w_out) - self.c_bn.final_bn = True - - def forward(self, x): - for layer in self.children(): - x = layer(x) - return x - - @staticmethod - def complexity(cx, w_in, w_out, stride, params): - w_b = int(round(w_out * params["bot_mul"])) - w_se = int(round(w_in * params["se_r"])) - groups = w_b // params["group_w"] - cx = conv2d_cx(cx, w_in, w_b, 1) - cx = norm2d_cx(cx, w_b) - cx = conv2d_cx(cx, w_b, w_b, 3, stride=stride, groups=groups) - cx = norm2d_cx(cx, w_b) - cx = SE.complexity(cx, w_b, w_se) if w_se else cx - cx = conv2d_cx(cx, w_b, w_out, 1) - cx = norm2d_cx(cx, w_out) - return cx - - -class ResBottleneckBlock(Module): - """Residual bottleneck block: x + f(x), f = bottleneck transform.""" - - def __init__(self, w_in, w_out, stride, params): - super(ResBottleneckBlock, self).__init__() - self.proj, self.bn = None, None - if (w_in != w_out) or (stride != 1): - self.proj = conv2d(w_in, w_out, 1, stride=stride) - self.bn = norm2d(w_out) - self.f = BottleneckTransform(w_in, w_out, stride, params) - self.af = activation() - - def forward(self, x): - x_p = self.bn(self.proj(x)) if self.proj else x - return self.af(x_p + self.f(x)) - - @staticmethod - def complexity(cx, w_in, w_out, stride, params): - if (w_in != w_out) or (stride != 1): - h, w = cx["h"], cx["w"] - cx = conv2d_cx(cx, w_in, w_out, 1, stride=stride) - cx = norm2d_cx(cx, w_out) - cx["h"], cx["w"] = h, w - cx = BottleneckTransform.complexity(cx, w_in, w_out, stride, params) - return cx - - -class ResStemCifar(Module): - """ResNet stem for CIFAR: 3x3, BN, AF.""" - - def __init__(self, w_in, w_out): - super(ResStemCifar, self).__init__() - self.conv = conv2d(w_in, w_out, 3) - self.bn = norm2d(w_out) - self.af = activation() - - def forward(self, x): - for layer in self.children(): - x = layer(x) - return x - - @staticmethod - def complexity(cx, w_in, w_out): - cx = conv2d_cx(cx, w_in, w_out, 3) - cx = norm2d_cx(cx, w_out) - return cx - - -class ResStem(Module): - """ResNet stem for ImageNet: 7x7, BN, AF, MaxPool.""" - - def __init__(self, w_in, w_out): - super(ResStem, self).__init__() - self.conv = conv2d(w_in, w_out, 7, stride=2) - self.bn = norm2d(w_out) - self.af = activation() - self.pool = pool2d(w_out, 3, stride=2) - - def forward(self, x): - for layer in self.children(): - x = layer(x) - return x - - @staticmethod - def complexity(cx, w_in, w_out): - cx = conv2d_cx(cx, w_in, w_out, 7, stride=2) - cx = norm2d_cx(cx, w_out) - cx = pool2d_cx(cx, w_out, 3, stride=2) - return cx - - -class SimpleStem(Module): - """Simple stem for ImageNet: 3x3, BN, AF.""" - - def __init__(self, w_in, w_out): - super(SimpleStem, self).__init__() - self.conv = conv2d(w_in, w_out, 3, stride=2) - self.bn = norm2d(w_out) - self.af = activation() - - def forward(self, x): - for layer in self.children(): - x = layer(x) - return x - - @staticmethod - def complexity(cx, w_in, w_out): - cx = conv2d_cx(cx, w_in, w_out, 3, stride=2) - cx = norm2d_cx(cx, w_out) - return cx - - -class AnyStage(Module): - """AnyNet stage (sequence of blocks w/ the same output shape).""" - - def __init__(self, w_in, w_out, stride, d, block_fun, params): - super(AnyStage, self).__init__() - for i in range(d): - block = block_fun(w_in, w_out, stride, params) - self.add_module("b{}".format(i + 1), block) - stride, w_in = 1, w_out - - def forward(self, x): - for block in self.children(): - x = block(x) - return x - - @staticmethod - def complexity(cx, w_in, w_out, stride, d, block_fun, params): - for _ in range(d): - cx = block_fun.complexity(cx, w_in, w_out, stride, params) - stride, w_in = 1, w_out - return cx - - -class AnyNet(Module): - """AnyNet model.""" - - @staticmethod - def get_params(): - nones = [None for _ in cfg.ANYNET.DEPTHS] - return { - "stem_type": cfg.ANYNET.STEM_TYPE, - "stem_w": cfg.ANYNET.STEM_W, - "block_type": cfg.ANYNET.BLOCK_TYPE, - "depths": cfg.ANYNET.DEPTHS, - "widths": cfg.ANYNET.WIDTHS, - "strides": cfg.ANYNET.STRIDES, - "bot_muls": cfg.ANYNET.BOT_MULS if cfg.ANYNET.BOT_MULS else nones, - "group_ws": cfg.ANYNET.GROUP_WS if cfg.ANYNET.GROUP_WS else nones, - "se_r": cfg.ANYNET.SE_R if cfg.ANYNET.SE_ON else 0, - "num_classes": cfg.MODEL.NUM_CLASSES, - } - - def __init__(self, params=None): - super(AnyNet, self).__init__() - p = AnyNet.get_params() if not params else params - stem_fun = get_stem_fun(p["stem_type"]) - block_fun = get_block_fun(p["block_type"]) - self.stem = stem_fun(3, p["stem_w"]) - prev_w = p["stem_w"] - keys = ["depths", "widths", "strides", "bot_muls", "group_ws"] - for i, (d, w, s, b, g) in enumerate(zip(*[p[k] for k in keys])): - params = {"bot_mul": b, "group_w": g, "se_r": p["se_r"]} - stage = AnyStage(prev_w, w, s, d, block_fun, params) - self.add_module("s{}".format(i + 1), stage) - prev_w = w - self.head = AnyHead(prev_w, p["num_classes"]) - self.apply(init_weights) - - def forward(self, x): - for module in self.children(): - x = module(x) - return x - - @staticmethod - def complexity(cx, params=None): - """Computes model complexity (if you alter the model, make sure to update).""" - p = AnyNet.get_params() if not params else params - stem_fun = get_stem_fun(p["stem_type"]) - block_fun = get_block_fun(p["block_type"]) - cx = stem_fun.complexity(cx, 3, p["stem_w"]) - prev_w = p["stem_w"] - keys = ["depths", "widths", "strides", "bot_muls", "group_ws"] - for d, w, s, b, g in zip(*[p[k] for k in keys]): - params = {"bot_mul": b, "group_w": g, "se_r": p["se_r"]} - cx = AnyStage.complexity(cx, prev_w, w, s, d, block_fun, params) - prev_w = w - cx = AnyHead.complexity(cx, prev_w, p["num_classes"]) - return cx +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""AnyNet models.""" + +from pycls.core.config import cfg +from pycls.models.blocks import ( + SE, + activation, + conv2d, + conv2d_cx, + gap2d, + gap2d_cx, + init_weights, + linear, + linear_cx, + norm2d, + norm2d_cx, + pool2d, + pool2d_cx, +) +from torch.nn import Module + + +def get_stem_fun(stem_type): + """Retrieves the stem function by name.""" + stem_funs = { + "res_stem_cifar": ResStemCifar, + "res_stem_in": ResStem, + "simple_stem_in": SimpleStem, + } + err_str = "Stem type '{}' not supported" + assert stem_type in stem_funs.keys(), err_str.format(stem_type) + return stem_funs[stem_type] + + +def get_block_fun(block_type): + """Retrieves the block function by name.""" + block_funs = { + "vanilla_block": VanillaBlock, + "res_basic_block": ResBasicBlock, + "res_bottleneck_block": ResBottleneckBlock, + } + err_str = "Block type '{}' not supported" + assert block_type in block_funs.keys(), err_str.format(block_type) + return block_funs[block_type] + + +class AnyHead(Module): + """AnyNet head: AvgPool, 1x1.""" + + def __init__(self, w_in, num_classes): + super(AnyHead, self).__init__() + self.avg_pool = gap2d(w_in) + self.fc = linear(w_in, num_classes, bias=True) + + def forward(self, x): + x = self.avg_pool(x) + x = x.view(x.size(0), -1) + x = self.fc(x) + return x + + @staticmethod + def complexity(cx, w_in, num_classes): + cx = gap2d_cx(cx, w_in) + cx = linear_cx(cx, w_in, num_classes, bias=True) + return cx + + +class VanillaBlock(Module): + """Vanilla block: [3x3 conv, BN, Relu] x2.""" + + def __init__(self, w_in, w_out, stride, _params): + super(VanillaBlock, self).__init__() + self.a = conv2d(w_in, w_out, 3, stride=stride) + self.a_bn = norm2d(w_out) + self.a_af = activation() + self.b = conv2d(w_out, w_out, 3) + self.b_bn = norm2d(w_out) + self.b_af = activation() + + def forward(self, x): + for layer in self.children(): + x = layer(x) + return x + + @staticmethod + def complexity(cx, w_in, w_out, stride, _params): + cx = conv2d_cx(cx, w_in, w_out, 3, stride=stride) + cx = norm2d_cx(cx, w_out) + cx = conv2d_cx(cx, w_out, w_out, 3) + cx = norm2d_cx(cx, w_out) + return cx + + +class BasicTransform(Module): + """Basic transformation: [3x3 conv, BN, Relu] x2.""" + + def __init__(self, w_in, w_out, stride, _params): + super(BasicTransform, self).__init__() + self.a = conv2d(w_in, w_out, 3, stride=stride) + self.a_bn = norm2d(w_out) + self.a_af = activation() + self.b = conv2d(w_out, w_out, 3) + self.b_bn = norm2d(w_out) + self.b_bn.final_bn = True + + def forward(self, x): + for layer in self.children(): + x = layer(x) + return x + + @staticmethod + def complexity(cx, w_in, w_out, stride, _params): + cx = conv2d_cx(cx, w_in, w_out, 3, stride=stride) + cx = norm2d_cx(cx, w_out) + cx = conv2d_cx(cx, w_out, w_out, 3) + cx = norm2d_cx(cx, w_out) + return cx + + +class ResBasicBlock(Module): + """Residual basic block: x + f(x), f = basic transform.""" + + def __init__(self, w_in, w_out, stride, params): + super(ResBasicBlock, self).__init__() + self.proj, self.bn = None, None + if (w_in != w_out) or (stride != 1): + self.proj = conv2d(w_in, w_out, 1, stride=stride) + self.bn = norm2d(w_out) + self.f = BasicTransform(w_in, w_out, stride, params) + self.af = activation() + + def forward(self, x): + x_p = self.bn(self.proj(x)) if self.proj else x + return self.af(x_p + self.f(x)) + + @staticmethod + def complexity(cx, w_in, w_out, stride, params): + if (w_in != w_out) or (stride != 1): + h, w = cx["h"], cx["w"] + cx = conv2d_cx(cx, w_in, w_out, 1, stride=stride) + cx = norm2d_cx(cx, w_out) + cx["h"], cx["w"] = h, w + cx = BasicTransform.complexity(cx, w_in, w_out, stride, params) + return cx + + +class BottleneckTransform(Module): + """Bottleneck transformation: 1x1, 3x3 [+SE], 1x1.""" + + def __init__(self, w_in, w_out, stride, params): + super(BottleneckTransform, self).__init__() + w_b = int(round(w_out * params["bot_mul"])) + w_se = int(round(w_in * params["se_r"])) + groups = w_b // params["group_w"] + self.a = conv2d(w_in, w_b, 1) + self.a_bn = norm2d(w_b) + self.a_af = activation() + self.b = conv2d(w_b, w_b, 3, stride=stride, groups=groups) + self.b_bn = norm2d(w_b) + self.b_af = activation() + self.se = SE(w_b, w_se) if w_se else None + self.c = conv2d(w_b, w_out, 1) + self.c_bn = norm2d(w_out) + self.c_bn.final_bn = True + + def forward(self, x): + for layer in self.children(): + x = layer(x) + return x + + @staticmethod + def complexity(cx, w_in, w_out, stride, params): + w_b = int(round(w_out * params["bot_mul"])) + w_se = int(round(w_in * params["se_r"])) + groups = w_b // params["group_w"] + cx = conv2d_cx(cx, w_in, w_b, 1) + cx = norm2d_cx(cx, w_b) + cx = conv2d_cx(cx, w_b, w_b, 3, stride=stride, groups=groups) + cx = norm2d_cx(cx, w_b) + cx = SE.complexity(cx, w_b, w_se) if w_se else cx + cx = conv2d_cx(cx, w_b, w_out, 1) + cx = norm2d_cx(cx, w_out) + return cx + + +class ResBottleneckBlock(Module): + """Residual bottleneck block: x + f(x), f = bottleneck transform.""" + + def __init__(self, w_in, w_out, stride, params): + super(ResBottleneckBlock, self).__init__() + self.proj, self.bn = None, None + if (w_in != w_out) or (stride != 1): + self.proj = conv2d(w_in, w_out, 1, stride=stride) + self.bn = norm2d(w_out) + self.f = BottleneckTransform(w_in, w_out, stride, params) + self.af = activation() + + def forward(self, x): + x_p = self.bn(self.proj(x)) if self.proj else x + return self.af(x_p + self.f(x)) + + @staticmethod + def complexity(cx, w_in, w_out, stride, params): + if (w_in != w_out) or (stride != 1): + h, w = cx["h"], cx["w"] + cx = conv2d_cx(cx, w_in, w_out, 1, stride=stride) + cx = norm2d_cx(cx, w_out) + cx["h"], cx["w"] = h, w + cx = BottleneckTransform.complexity(cx, w_in, w_out, stride, params) + return cx + + +class ResStemCifar(Module): + """ResNet stem for CIFAR: 3x3, BN, AF.""" + + def __init__(self, w_in, w_out): + super(ResStemCifar, self).__init__() + self.conv = conv2d(w_in, w_out, 3) + self.bn = norm2d(w_out) + self.af = activation() + + def forward(self, x): + for layer in self.children(): + x = layer(x) + return x + + @staticmethod + def complexity(cx, w_in, w_out): + cx = conv2d_cx(cx, w_in, w_out, 3) + cx = norm2d_cx(cx, w_out) + return cx + + +class ResStem(Module): + """ResNet stem for ImageNet: 7x7, BN, AF, MaxPool.""" + + def __init__(self, w_in, w_out): + super(ResStem, self).__init__() + self.conv = conv2d(w_in, w_out, 7, stride=2) + self.bn = norm2d(w_out) + self.af = activation() + self.pool = pool2d(w_out, 3, stride=2) + + def forward(self, x): + for layer in self.children(): + x = layer(x) + return x + + @staticmethod + def complexity(cx, w_in, w_out): + cx = conv2d_cx(cx, w_in, w_out, 7, stride=2) + cx = norm2d_cx(cx, w_out) + cx = pool2d_cx(cx, w_out, 3, stride=2) + return cx + + +class SimpleStem(Module): + """Simple stem for ImageNet: 3x3, BN, AF.""" + + def __init__(self, w_in, w_out): + super(SimpleStem, self).__init__() + self.conv = conv2d(w_in, w_out, 3, stride=2) + self.bn = norm2d(w_out) + self.af = activation() + + def forward(self, x): + for layer in self.children(): + x = layer(x) + return x + + @staticmethod + def complexity(cx, w_in, w_out): + cx = conv2d_cx(cx, w_in, w_out, 3, stride=2) + cx = norm2d_cx(cx, w_out) + return cx + + +class AnyStage(Module): + """AnyNet stage (sequence of blocks w/ the same output shape).""" + + def __init__(self, w_in, w_out, stride, d, block_fun, params): + super(AnyStage, self).__init__() + for i in range(d): + block = block_fun(w_in, w_out, stride, params) + self.add_module("b{}".format(i + 1), block) + stride, w_in = 1, w_out + + def forward(self, x): + for block in self.children(): + x = block(x) + return x + + @staticmethod + def complexity(cx, w_in, w_out, stride, d, block_fun, params): + for _ in range(d): + cx = block_fun.complexity(cx, w_in, w_out, stride, params) + stride, w_in = 1, w_out + return cx + + +class AnyNet(Module): + """AnyNet model.""" + + @staticmethod + def get_params(): + nones = [None for _ in cfg.ANYNET.DEPTHS] + return { + "stem_type": cfg.ANYNET.STEM_TYPE, + "stem_w": cfg.ANYNET.STEM_W, + "block_type": cfg.ANYNET.BLOCK_TYPE, + "depths": cfg.ANYNET.DEPTHS, + "widths": cfg.ANYNET.WIDTHS, + "strides": cfg.ANYNET.STRIDES, + "bot_muls": cfg.ANYNET.BOT_MULS if cfg.ANYNET.BOT_MULS else nones, + "group_ws": cfg.ANYNET.GROUP_WS if cfg.ANYNET.GROUP_WS else nones, + "se_r": cfg.ANYNET.SE_R if cfg.ANYNET.SE_ON else 0, + "num_classes": cfg.MODEL.NUM_CLASSES, + } + + def __init__(self, params=None): + super(AnyNet, self).__init__() + p = AnyNet.get_params() if not params else params + stem_fun = get_stem_fun(p["stem_type"]) + block_fun = get_block_fun(p["block_type"]) + self.stem = stem_fun(3, p["stem_w"]) + prev_w = p["stem_w"] + keys = ["depths", "widths", "strides", "bot_muls", "group_ws"] + for i, (d, w, s, b, g) in enumerate(zip(*[p[k] for k in keys])): + params = {"bot_mul": b, "group_w": g, "se_r": p["se_r"]} + stage = AnyStage(prev_w, w, s, d, block_fun, params) + self.add_module("s{}".format(i + 1), stage) + prev_w = w + self.head = AnyHead(prev_w, p["num_classes"]) + self.apply(init_weights) + + def forward(self, x): + for module in self.children(): + x = module(x) + return x + + @staticmethod + def complexity(cx, params=None): + """Computes model complexity (if you alter the model, make sure to update).""" + p = AnyNet.get_params() if not params else params + stem_fun = get_stem_fun(p["stem_type"]) + block_fun = get_block_fun(p["block_type"]) + cx = stem_fun.complexity(cx, 3, p["stem_w"]) + prev_w = p["stem_w"] + keys = ["depths", "widths", "strides", "bot_muls", "group_ws"] + for d, w, s, b, g in zip(*[p[k] for k in keys]): + params = {"bot_mul": b, "group_w": g, "se_r": p["se_r"]} + cx = AnyStage.complexity(cx, prev_w, w, s, d, block_fun, params) + prev_w = w + cx = AnyHead.complexity(cx, prev_w, p["num_classes"]) + return cx diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/blocks.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/blocks.py index 6c7773d188f52dd082510047081c450b71d8a0bd..eb14c7d70767892b1666cee1e472984630823979 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/blocks.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/blocks.py @@ -1,201 +1,201 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Common model blocks.""" - -import numpy as np -import torch -import torch.nn as nn -from pycls.core.config import cfg -from torch.nn import Module - - -# ----------------------- Shortcuts for common torch.nn layers ----------------------- # - - -def conv2d(w_in, w_out, k, *, stride=1, groups=1, bias=False): - """Helper for building a conv2d layer.""" - assert k % 2 == 1, "Only odd size kernels supported to avoid padding issues." - s, p, g, b = stride, (k - 1) // 2, groups, bias - return nn.Conv2d(w_in, w_out, k, stride=s, padding=p, groups=g, bias=b) - - -def norm2d(w_in): - """Helper for building a norm2d layer.""" - return nn.BatchNorm2d(num_features=w_in, eps=cfg.BN.EPS, momentum=cfg.BN.MOM) - - -def pool2d(_w_in, k, *, stride=1): - """Helper for building a pool2d layer.""" - assert k % 2 == 1, "Only odd size kernels supported to avoid padding issues." - return nn.MaxPool2d(k, stride=stride, padding=(k - 1) // 2) - - -def gap2d(_w_in): - """Helper for building a gap2d layer.""" - return nn.AdaptiveAvgPool2d((1, 1)) - - -def linear(w_in, w_out, *, bias=False): - """Helper for building a linear layer.""" - return nn.Linear(w_in, w_out, bias=bias) - - -def activation(): - """Helper for building an activation layer.""" - activation_fun = cfg.MODEL.ACTIVATION_FUN.lower() - if activation_fun == "relu": - return nn.ReLU(inplace=cfg.MODEL.ACTIVATION_INPLACE) - elif activation_fun == "silu" or activation_fun == "swish": - try: - return torch.nn.SiLU() - except AttributeError: - return SiLU() - else: - raise AssertionError("Unknown MODEL.ACTIVATION_FUN: " + activation_fun) - - -# --------------------------- Complexity (cx) calculations --------------------------- # - - -def conv2d_cx(cx, w_in, w_out, k, *, stride=1, groups=1, bias=False): - """Accumulates complexity of conv2d into cx = (h, w, flops, params, acts).""" - assert k % 2 == 1, "Only odd size kernels supported to avoid padding issues." - h, w, flops, params, acts = cx["h"], cx["w"], cx["flops"], cx["params"], cx["acts"] - h, w = (h - 1) // stride + 1, (w - 1) // stride + 1 - flops += k * k * w_in * w_out * h * w // groups + (w_out if bias else 0) - params += k * k * w_in * w_out // groups + (w_out if bias else 0) - acts += w_out * h * w - return {"h": h, "w": w, "flops": flops, "params": params, "acts": acts} - - -def norm2d_cx(cx, w_in): - """Accumulates complexity of norm2d into cx = (h, w, flops, params, acts).""" - h, w, flops, params, acts = cx["h"], cx["w"], cx["flops"], cx["params"], cx["acts"] - params += 2 * w_in - return {"h": h, "w": w, "flops": flops, "params": params, "acts": acts} - - -def pool2d_cx(cx, w_in, k, *, stride=1): - """Accumulates complexity of pool2d into cx = (h, w, flops, params, acts).""" - assert k % 2 == 1, "Only odd size kernels supported to avoid padding issues." - h, w, flops, params, acts = cx["h"], cx["w"], cx["flops"], cx["params"], cx["acts"] - h, w = (h - 1) // stride + 1, (w - 1) // stride + 1 - acts += w_in * h * w - return {"h": h, "w": w, "flops": flops, "params": params, "acts": acts} - - -def gap2d_cx(cx, _w_in): - """Accumulates complexity of gap2d into cx = (h, w, flops, params, acts).""" - flops, params, acts = cx["flops"], cx["params"], cx["acts"] - return {"h": 1, "w": 1, "flops": flops, "params": params, "acts": acts} - - -def linear_cx(cx, w_in, w_out, *, bias=False): - """Accumulates complexity of linear into cx = (h, w, flops, params, acts).""" - h, w, flops, params, acts = cx["h"], cx["w"], cx["flops"], cx["params"], cx["acts"] - flops += w_in * w_out + (w_out if bias else 0) - params += w_in * w_out + (w_out if bias else 0) - acts += w_out - return {"h": h, "w": w, "flops": flops, "params": params, "acts": acts} - - -# ---------------------------------- Shared blocks ----------------------------------- # - - -class SiLU(Module): - """SiLU activation function (also known as Swish): x * sigmoid(x).""" - - # Note: will be part of Pytorch 1.7, at which point can remove this. - - def __init__(self): - super(SiLU, self).__init__() - - def forward(self, x): - return x * torch.sigmoid(x) - - -class SE(Module): - """Squeeze-and-Excitation (SE) block: AvgPool, FC, Act, FC, Sigmoid.""" - - def __init__(self, w_in, w_se): - super(SE, self).__init__() - self.avg_pool = gap2d(w_in) - self.f_ex = nn.Sequential( - conv2d(w_in, w_se, 1, bias=True), - activation(), - conv2d(w_se, w_in, 1, bias=True), - nn.Sigmoid(), - ) - - def forward(self, x): - return x * self.f_ex(self.avg_pool(x)) - - @staticmethod - def complexity(cx, w_in, w_se): - h, w = cx["h"], cx["w"] - cx = gap2d_cx(cx, w_in) - cx = conv2d_cx(cx, w_in, w_se, 1, bias=True) - cx = conv2d_cx(cx, w_se, w_in, 1, bias=True) - cx["h"], cx["w"] = h, w - return cx - - -# ---------------------------------- Miscellaneous ----------------------------------- # - - -def adjust_block_compatibility(ws, bs, gs): - """Adjusts the compatibility of widths, bottlenecks, and groups.""" - assert len(ws) == len(bs) == len(gs) - assert all(w > 0 and b > 0 and g > 0 for w, b, g in zip(ws, bs, gs)) - vs = [int(max(1, w * b)) for w, b in zip(ws, bs)] - gs = [int(min(g, v)) for g, v in zip(gs, vs)] - ms = [np.lcm(g, b) if b > 1 else g for g, b in zip(gs, bs)] - vs = [max(m, int(round(v / m) * m)) for v, m in zip(vs, ms)] - ws = [int(v / b) for v, b in zip(vs, bs)] - assert all(w * b % g == 0 for w, b, g in zip(ws, bs, gs)) - return ws, bs, gs - - -def init_weights(m): - """Performs ResNet-style weight initialization.""" - if isinstance(m, nn.Conv2d): - # Note that there is no bias due to BN - fan_out = m.kernel_size[0] * m.kernel_size[1] * m.out_channels - m.weight.data.normal_(mean=0.0, std=np.sqrt(2.0 / fan_out)) - elif isinstance(m, nn.BatchNorm2d): - zero_init_gamma = cfg.BN.ZERO_INIT_FINAL_GAMMA - zero_init_gamma = hasattr(m, "final_bn") and m.final_bn and zero_init_gamma - m.weight.data.fill_(0.0 if zero_init_gamma else 1.0) - m.bias.data.zero_() - elif isinstance(m, nn.Linear): - m.weight.data.normal_(mean=0.0, std=0.01) - m.bias.data.zero_() - - -def drop_connect(x, drop_ratio): - """Drop connect (adapted from DARTS).""" - keep_ratio = 1.0 - drop_ratio - mask = torch.empty([x.shape[0], 1, 1, 1], dtype=x.dtype, device=x.device) - mask.bernoulli_(keep_ratio) - x.div_(keep_ratio) - x.mul_(mask) - return x +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Common model blocks.""" + +import numpy as np +import torch +import torch.nn as nn +from pycls.core.config import cfg +from torch.nn import Module + + +# ----------------------- Shortcuts for common torch.nn layers ----------------------- # + + +def conv2d(w_in, w_out, k, *, stride=1, groups=1, bias=False): + """Helper for building a conv2d layer.""" + assert k % 2 == 1, "Only odd size kernels supported to avoid padding issues." + s, p, g, b = stride, (k - 1) // 2, groups, bias + return nn.Conv2d(w_in, w_out, k, stride=s, padding=p, groups=g, bias=b) + + +def norm2d(w_in): + """Helper for building a norm2d layer.""" + return nn.BatchNorm2d(num_features=w_in, eps=cfg.BN.EPS, momentum=cfg.BN.MOM) + + +def pool2d(_w_in, k, *, stride=1): + """Helper for building a pool2d layer.""" + assert k % 2 == 1, "Only odd size kernels supported to avoid padding issues." + return nn.MaxPool2d(k, stride=stride, padding=(k - 1) // 2) + + +def gap2d(_w_in): + """Helper for building a gap2d layer.""" + return nn.AdaptiveAvgPool2d((1, 1)) + + +def linear(w_in, w_out, *, bias=False): + """Helper for building a linear layer.""" + return nn.Linear(w_in, w_out, bias=bias) + + +def activation(): + """Helper for building an activation layer.""" + activation_fun = cfg.MODEL.ACTIVATION_FUN.lower() + if activation_fun == "relu": + return nn.ReLU(inplace=cfg.MODEL.ACTIVATION_INPLACE) + elif activation_fun == "silu" or activation_fun == "swish": + try: + return torch.nn.SiLU() + except AttributeError: + return SiLU() + else: + raise AssertionError("Unknown MODEL.ACTIVATION_FUN: " + activation_fun) + + +# --------------------------- Complexity (cx) calculations --------------------------- # + + +def conv2d_cx(cx, w_in, w_out, k, *, stride=1, groups=1, bias=False): + """Accumulates complexity of conv2d into cx = (h, w, flops, params, acts).""" + assert k % 2 == 1, "Only odd size kernels supported to avoid padding issues." + h, w, flops, params, acts = cx["h"], cx["w"], cx["flops"], cx["params"], cx["acts"] + h, w = (h - 1) // stride + 1, (w - 1) // stride + 1 + flops += k * k * w_in * w_out * h * w // groups + (w_out if bias else 0) + params += k * k * w_in * w_out // groups + (w_out if bias else 0) + acts += w_out * h * w + return {"h": h, "w": w, "flops": flops, "params": params, "acts": acts} + + +def norm2d_cx(cx, w_in): + """Accumulates complexity of norm2d into cx = (h, w, flops, params, acts).""" + h, w, flops, params, acts = cx["h"], cx["w"], cx["flops"], cx["params"], cx["acts"] + params += 2 * w_in + return {"h": h, "w": w, "flops": flops, "params": params, "acts": acts} + + +def pool2d_cx(cx, w_in, k, *, stride=1): + """Accumulates complexity of pool2d into cx = (h, w, flops, params, acts).""" + assert k % 2 == 1, "Only odd size kernels supported to avoid padding issues." + h, w, flops, params, acts = cx["h"], cx["w"], cx["flops"], cx["params"], cx["acts"] + h, w = (h - 1) // stride + 1, (w - 1) // stride + 1 + acts += w_in * h * w + return {"h": h, "w": w, "flops": flops, "params": params, "acts": acts} + + +def gap2d_cx(cx, _w_in): + """Accumulates complexity of gap2d into cx = (h, w, flops, params, acts).""" + flops, params, acts = cx["flops"], cx["params"], cx["acts"] + return {"h": 1, "w": 1, "flops": flops, "params": params, "acts": acts} + + +def linear_cx(cx, w_in, w_out, *, bias=False): + """Accumulates complexity of linear into cx = (h, w, flops, params, acts).""" + h, w, flops, params, acts = cx["h"], cx["w"], cx["flops"], cx["params"], cx["acts"] + flops += w_in * w_out + (w_out if bias else 0) + params += w_in * w_out + (w_out if bias else 0) + acts += w_out + return {"h": h, "w": w, "flops": flops, "params": params, "acts": acts} + + +# ---------------------------------- Shared blocks ----------------------------------- # + + +class SiLU(Module): + """SiLU activation function (also known as Swish): x * sigmoid(x).""" + + # Note: will be part of Pytorch 1.7, at which point can remove this. + + def __init__(self): + super(SiLU, self).__init__() + + def forward(self, x): + return x * torch.sigmoid(x) + + +class SE(Module): + """Squeeze-and-Excitation (SE) block: AvgPool, FC, Act, FC, Sigmoid.""" + + def __init__(self, w_in, w_se): + super(SE, self).__init__() + self.avg_pool = gap2d(w_in) + self.f_ex = nn.Sequential( + conv2d(w_in, w_se, 1, bias=True), + activation(), + conv2d(w_se, w_in, 1, bias=True), + nn.Sigmoid(), + ) + + def forward(self, x): + return x * self.f_ex(self.avg_pool(x)) + + @staticmethod + def complexity(cx, w_in, w_se): + h, w = cx["h"], cx["w"] + cx = gap2d_cx(cx, w_in) + cx = conv2d_cx(cx, w_in, w_se, 1, bias=True) + cx = conv2d_cx(cx, w_se, w_in, 1, bias=True) + cx["h"], cx["w"] = h, w + return cx + + +# ---------------------------------- Miscellaneous ----------------------------------- # + + +def adjust_block_compatibility(ws, bs, gs): + """Adjusts the compatibility of widths, bottlenecks, and groups.""" + assert len(ws) == len(bs) == len(gs) + assert all(w > 0 and b > 0 and g > 0 for w, b, g in zip(ws, bs, gs)) + vs = [int(max(1, w * b)) for w, b in zip(ws, bs)] + gs = [int(min(g, v)) for g, v in zip(gs, vs)] + ms = [np.lcm(g, b) if b > 1 else g for g, b in zip(gs, bs)] + vs = [max(m, int(round(v / m) * m)) for v, m in zip(vs, ms)] + ws = [int(v / b) for v, b in zip(vs, bs)] + assert all(w * b % g == 0 for w, b, g in zip(ws, bs, gs)) + return ws, bs, gs + + +def init_weights(m): + """Performs ResNet-style weight initialization.""" + if isinstance(m, nn.Conv2d): + # Note that there is no bias due to BN + fan_out = m.kernel_size[0] * m.kernel_size[1] * m.out_channels + m.weight.data.normal_(mean=0.0, std=np.sqrt(2.0 / fan_out)) + elif isinstance(m, nn.BatchNorm2d): + zero_init_gamma = cfg.BN.ZERO_INIT_FINAL_GAMMA + zero_init_gamma = hasattr(m, "final_bn") and m.final_bn and zero_init_gamma + m.weight.data.fill_(0.0 if zero_init_gamma else 1.0) + m.bias.data.zero_() + elif isinstance(m, nn.Linear): + m.weight.data.normal_(mean=0.0, std=0.01) + m.bias.data.zero_() + + +def drop_connect(x, drop_ratio): + """Drop connect (adapted from DARTS).""" + keep_ratio = 1.0 - drop_ratio + mask = torch.empty([x.shape[0], 1, 1, 1], dtype=x.dtype, device=x.device) + mask.bernoulli_(keep_ratio) + x.div_(keep_ratio) + x.mul_(mask) + return x diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/effnet.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/effnet.py index 53826fdae79fa23b0205b98123740f338dd21b4b..f58649ccde03d6778dba4dafd8f0c1344319389e 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/effnet.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/effnet.py @@ -1,211 +1,211 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""EfficientNet models.""" - -from pycls.core.config import cfg -from pycls.models.blocks import ( - SE, - activation, - conv2d, - conv2d_cx, - drop_connect, - gap2d, - gap2d_cx, - init_weights, - linear, - linear_cx, - norm2d, - norm2d_cx, -) -from torch.nn import Dropout, Module - - -class EffHead(Module): - """EfficientNet head: 1x1, BN, AF, AvgPool, Dropout, FC.""" - - def __init__(self, w_in, w_out, num_classes): - super(EffHead, self).__init__() - dropout_ratio = cfg.EN.DROPOUT_RATIO - self.conv = conv2d(w_in, w_out, 1) - self.conv_bn = norm2d(w_out) - self.conv_af = activation() - self.avg_pool = gap2d(w_out) - self.dropout = Dropout(p=dropout_ratio) if dropout_ratio > 0 else None - self.fc = linear(w_out, num_classes, bias=True) - - def forward(self, x): - x = self.conv_af(self.conv_bn(self.conv(x))) - x = self.avg_pool(x) - x = x.view(x.size(0), -1) - x = self.dropout(x) if self.dropout else x - x = self.fc(x) - return x - - @staticmethod - def complexity(cx, w_in, w_out, num_classes): - cx = conv2d_cx(cx, w_in, w_out, 1) - cx = norm2d_cx(cx, w_out) - cx = gap2d_cx(cx, w_out) - cx = linear_cx(cx, w_out, num_classes, bias=True) - return cx - - -class MBConv(Module): - """Mobile inverted bottleneck block with SE.""" - - def __init__(self, w_in, exp_r, k, stride, se_r, w_out): - # Expansion, kxk dwise, BN, AF, SE, 1x1, BN, skip_connection - super(MBConv, self).__init__() - self.exp = None - w_exp = int(w_in * exp_r) - if w_exp != w_in: - self.exp = conv2d(w_in, w_exp, 1) - self.exp_bn = norm2d(w_exp) - self.exp_af = activation() - self.dwise = conv2d(w_exp, w_exp, k, stride=stride, groups=w_exp) - self.dwise_bn = norm2d(w_exp) - self.dwise_af = activation() - self.se = SE(w_exp, int(w_in * se_r)) - self.lin_proj = conv2d(w_exp, w_out, 1) - self.lin_proj_bn = norm2d(w_out) - self.has_skip = stride == 1 and w_in == w_out - - def forward(self, x): - f_x = self.exp_af(self.exp_bn(self.exp(x))) if self.exp else x - f_x = self.dwise_af(self.dwise_bn(self.dwise(f_x))) - f_x = self.se(f_x) - f_x = self.lin_proj_bn(self.lin_proj(f_x)) - if self.has_skip: - if self.training and cfg.EN.DC_RATIO > 0.0: - f_x = drop_connect(f_x, cfg.EN.DC_RATIO) - f_x = x + f_x - return f_x - - @staticmethod - def complexity(cx, w_in, exp_r, k, stride, se_r, w_out): - w_exp = int(w_in * exp_r) - if w_exp != w_in: - cx = conv2d_cx(cx, w_in, w_exp, 1) - cx = norm2d_cx(cx, w_exp) - cx = conv2d_cx(cx, w_exp, w_exp, k, stride=stride, groups=w_exp) - cx = norm2d_cx(cx, w_exp) - cx = SE.complexity(cx, w_exp, int(w_in * se_r)) - cx = conv2d_cx(cx, w_exp, w_out, 1) - cx = norm2d_cx(cx, w_out) - return cx - - -class EffStage(Module): - """EfficientNet stage.""" - - def __init__(self, w_in, exp_r, k, stride, se_r, w_out, d): - super(EffStage, self).__init__() - for i in range(d): - block = MBConv(w_in, exp_r, k, stride, se_r, w_out) - self.add_module("b{}".format(i + 1), block) - stride, w_in = 1, w_out - - def forward(self, x): - for block in self.children(): - x = block(x) - return x - - @staticmethod - def complexity(cx, w_in, exp_r, k, stride, se_r, w_out, d): - for _ in range(d): - cx = MBConv.complexity(cx, w_in, exp_r, k, stride, se_r, w_out) - stride, w_in = 1, w_out - return cx - - -class StemIN(Module): - """EfficientNet stem for ImageNet: 3x3, BN, AF.""" - - def __init__(self, w_in, w_out): - super(StemIN, self).__init__() - self.conv = conv2d(w_in, w_out, 3, stride=2) - self.bn = norm2d(w_out) - self.af = activation() - - def forward(self, x): - for layer in self.children(): - x = layer(x) - return x - - @staticmethod - def complexity(cx, w_in, w_out): - cx = conv2d_cx(cx, w_in, w_out, 3, stride=2) - cx = norm2d_cx(cx, w_out) - return cx - - -class EffNet(Module): - """EfficientNet model.""" - - @staticmethod - def get_params(): - return { - "sw": cfg.EN.STEM_W, - "ds": cfg.EN.DEPTHS, - "ws": cfg.EN.WIDTHS, - "exp_rs": cfg.EN.EXP_RATIOS, - "se_r": cfg.EN.SE_R, - "ss": cfg.EN.STRIDES, - "ks": cfg.EN.KERNELS, - "hw": cfg.EN.HEAD_W, - "nc": cfg.MODEL.NUM_CLASSES, - } - - def __init__(self, params=None): - super(EffNet, self).__init__() - p = EffNet.get_params() if not params else params - vs = ["sw", "ds", "ws", "exp_rs", "se_r", "ss", "ks", "hw", "nc"] - sw, ds, ws, exp_rs, se_r, ss, ks, hw, nc = [p[v] for v in vs] - stage_params = list(zip(ds, ws, exp_rs, ss, ks)) - self.stem = StemIN(3, sw) - prev_w = sw - for i, (d, w, exp_r, stride, k) in enumerate(stage_params): - stage = EffStage(prev_w, exp_r, k, stride, se_r, w, d) - self.add_module("s{}".format(i + 1), stage) - prev_w = w - self.head = EffHead(prev_w, hw, nc) - self.apply(init_weights) - - def forward(self, x): - for module in self.children(): - x = module(x) - return x - - @staticmethod - def complexity(cx, params=None): - """Computes model complexity (if you alter the model, make sure to update).""" - p = EffNet.get_params() if not params else params - vs = ["sw", "ds", "ws", "exp_rs", "se_r", "ss", "ks", "hw", "nc"] - sw, ds, ws, exp_rs, se_r, ss, ks, hw, nc = [p[v] for v in vs] - stage_params = list(zip(ds, ws, exp_rs, ss, ks)) - cx = StemIN.complexity(cx, 3, sw) - prev_w = sw - for d, w, exp_r, stride, k in stage_params: - cx = EffStage.complexity(cx, prev_w, exp_r, k, stride, se_r, w, d) - prev_w = w - cx = EffHead.complexity(cx, prev_w, hw, nc) - return cx +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""EfficientNet models.""" + +from pycls.core.config import cfg +from pycls.models.blocks import ( + SE, + activation, + conv2d, + conv2d_cx, + drop_connect, + gap2d, + gap2d_cx, + init_weights, + linear, + linear_cx, + norm2d, + norm2d_cx, +) +from torch.nn import Dropout, Module + + +class EffHead(Module): + """EfficientNet head: 1x1, BN, AF, AvgPool, Dropout, FC.""" + + def __init__(self, w_in, w_out, num_classes): + super(EffHead, self).__init__() + dropout_ratio = cfg.EN.DROPOUT_RATIO + self.conv = conv2d(w_in, w_out, 1) + self.conv_bn = norm2d(w_out) + self.conv_af = activation() + self.avg_pool = gap2d(w_out) + self.dropout = Dropout(p=dropout_ratio) if dropout_ratio > 0 else None + self.fc = linear(w_out, num_classes, bias=True) + + def forward(self, x): + x = self.conv_af(self.conv_bn(self.conv(x))) + x = self.avg_pool(x) + x = x.view(x.size(0), -1) + x = self.dropout(x) if self.dropout else x + x = self.fc(x) + return x + + @staticmethod + def complexity(cx, w_in, w_out, num_classes): + cx = conv2d_cx(cx, w_in, w_out, 1) + cx = norm2d_cx(cx, w_out) + cx = gap2d_cx(cx, w_out) + cx = linear_cx(cx, w_out, num_classes, bias=True) + return cx + + +class MBConv(Module): + """Mobile inverted bottleneck block with SE.""" + + def __init__(self, w_in, exp_r, k, stride, se_r, w_out): + # Expansion, kxk dwise, BN, AF, SE, 1x1, BN, skip_connection + super(MBConv, self).__init__() + self.exp = None + w_exp = int(w_in * exp_r) + if w_exp != w_in: + self.exp = conv2d(w_in, w_exp, 1) + self.exp_bn = norm2d(w_exp) + self.exp_af = activation() + self.dwise = conv2d(w_exp, w_exp, k, stride=stride, groups=w_exp) + self.dwise_bn = norm2d(w_exp) + self.dwise_af = activation() + self.se = SE(w_exp, int(w_in * se_r)) + self.lin_proj = conv2d(w_exp, w_out, 1) + self.lin_proj_bn = norm2d(w_out) + self.has_skip = stride == 1 and w_in == w_out + + def forward(self, x): + f_x = self.exp_af(self.exp_bn(self.exp(x))) if self.exp else x + f_x = self.dwise_af(self.dwise_bn(self.dwise(f_x))) + f_x = self.se(f_x) + f_x = self.lin_proj_bn(self.lin_proj(f_x)) + if self.has_skip: + if self.training and cfg.EN.DC_RATIO > 0.0: + f_x = drop_connect(f_x, cfg.EN.DC_RATIO) + f_x = x + f_x + return f_x + + @staticmethod + def complexity(cx, w_in, exp_r, k, stride, se_r, w_out): + w_exp = int(w_in * exp_r) + if w_exp != w_in: + cx = conv2d_cx(cx, w_in, w_exp, 1) + cx = norm2d_cx(cx, w_exp) + cx = conv2d_cx(cx, w_exp, w_exp, k, stride=stride, groups=w_exp) + cx = norm2d_cx(cx, w_exp) + cx = SE.complexity(cx, w_exp, int(w_in * se_r)) + cx = conv2d_cx(cx, w_exp, w_out, 1) + cx = norm2d_cx(cx, w_out) + return cx + + +class EffStage(Module): + """EfficientNet stage.""" + + def __init__(self, w_in, exp_r, k, stride, se_r, w_out, d): + super(EffStage, self).__init__() + for i in range(d): + block = MBConv(w_in, exp_r, k, stride, se_r, w_out) + self.add_module("b{}".format(i + 1), block) + stride, w_in = 1, w_out + + def forward(self, x): + for block in self.children(): + x = block(x) + return x + + @staticmethod + def complexity(cx, w_in, exp_r, k, stride, se_r, w_out, d): + for _ in range(d): + cx = MBConv.complexity(cx, w_in, exp_r, k, stride, se_r, w_out) + stride, w_in = 1, w_out + return cx + + +class StemIN(Module): + """EfficientNet stem for ImageNet: 3x3, BN, AF.""" + + def __init__(self, w_in, w_out): + super(StemIN, self).__init__() + self.conv = conv2d(w_in, w_out, 3, stride=2) + self.bn = norm2d(w_out) + self.af = activation() + + def forward(self, x): + for layer in self.children(): + x = layer(x) + return x + + @staticmethod + def complexity(cx, w_in, w_out): + cx = conv2d_cx(cx, w_in, w_out, 3, stride=2) + cx = norm2d_cx(cx, w_out) + return cx + + +class EffNet(Module): + """EfficientNet model.""" + + @staticmethod + def get_params(): + return { + "sw": cfg.EN.STEM_W, + "ds": cfg.EN.DEPTHS, + "ws": cfg.EN.WIDTHS, + "exp_rs": cfg.EN.EXP_RATIOS, + "se_r": cfg.EN.SE_R, + "ss": cfg.EN.STRIDES, + "ks": cfg.EN.KERNELS, + "hw": cfg.EN.HEAD_W, + "nc": cfg.MODEL.NUM_CLASSES, + } + + def __init__(self, params=None): + super(EffNet, self).__init__() + p = EffNet.get_params() if not params else params + vs = ["sw", "ds", "ws", "exp_rs", "se_r", "ss", "ks", "hw", "nc"] + sw, ds, ws, exp_rs, se_r, ss, ks, hw, nc = [p[v] for v in vs] + stage_params = list(zip(ds, ws, exp_rs, ss, ks)) + self.stem = StemIN(3, sw) + prev_w = sw + for i, (d, w, exp_r, stride, k) in enumerate(stage_params): + stage = EffStage(prev_w, exp_r, k, stride, se_r, w, d) + self.add_module("s{}".format(i + 1), stage) + prev_w = w + self.head = EffHead(prev_w, hw, nc) + self.apply(init_weights) + + def forward(self, x): + for module in self.children(): + x = module(x) + return x + + @staticmethod + def complexity(cx, params=None): + """Computes model complexity (if you alter the model, make sure to update).""" + p = EffNet.get_params() if not params else params + vs = ["sw", "ds", "ws", "exp_rs", "se_r", "ss", "ks", "hw", "nc"] + sw, ds, ws, exp_rs, se_r, ss, ks, hw, nc = [p[v] for v in vs] + stage_params = list(zip(ds, ws, exp_rs, ss, ks)) + cx = StemIN.complexity(cx, 3, sw) + prev_w = sw + for d, w, exp_r, stride, k in stage_params: + cx = EffStage.complexity(cx, prev_w, exp_r, k, stride, se_r, w, d) + prev_w = w + cx = EffHead.complexity(cx, prev_w, hw, nc) + return cx diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/model_zoo.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/model_zoo.py index 301e3396deea1683f00f1e31a761213f5db1cde4..1391e1d00a70cf5fc85208585f82fed6b9de1693 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/model_zoo.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/model_zoo.py @@ -1,196 +1,196 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Model zoo.""" - -import os - -import pycls.core.builders as builders -import pycls.core.checkpoint as cp -from pycls.core.config import cfg, reset_cfg -from pycls.core.io import cache_url - - -# URL prefix for pretrained models -_URL_WEIGHTS = "https://dl.fbaipublicfiles.com/pycls" - -# URL prefix for model config files -_URL_CONFIGS = "https://raw.githubusercontent.com/facebookresearch/pycls/master/configs" - -# Model weights download cache directory -_DOWNLOAD_CACHE = "/tmp/pycls-download-cache" - -# Predefined model config files -_MODEL_ZOO_CONFIGS = { - "RegNetX-200MF": "dds_baselines/regnetx/RegNetX-200MF_dds_8gpu.yaml", - "RegNetX-400MF": "dds_baselines/regnetx/RegNetX-400MF_dds_8gpu.yaml", - "RegNetX-600MF": "dds_baselines/regnetx/RegNetX-600MF_dds_8gpu.yaml", - "RegNetX-800MF": "dds_baselines/regnetx/RegNetX-800MF_dds_8gpu.yaml", - "RegNetX-1.6GF": "dds_baselines/regnetx/RegNetX-1.6GF_dds_8gpu.yaml", - "RegNetX-3.2GF": "dds_baselines/regnetx/RegNetX-3.2GF_dds_8gpu.yaml", - "RegNetX-4.0GF": "dds_baselines/regnetx/RegNetX-4.0GF_dds_8gpu.yaml", - "RegNetX-6.4GF": "dds_baselines/regnetx/RegNetX-6.4GF_dds_8gpu.yaml", - "RegNetX-8.0GF": "dds_baselines/regnetx/RegNetX-8.0GF_dds_8gpu.yaml", - "RegNetX-12GF": "dds_baselines/regnetx/RegNetX-12GF_dds_8gpu.yaml", - "RegNetX-16GF": "dds_baselines/regnetx/RegNetX-16GF_dds_8gpu.yaml", - "RegNetX-32GF": "dds_baselines/regnetx/RegNetX-32GF_dds_8gpu.yaml", - "RegNetY-200MF": "dds_baselines/regnety/RegNetY-200MF_dds_8gpu.yaml", - "RegNetY-400MF": "dds_baselines/regnety/RegNetY-400MF_dds_8gpu.yaml", - "RegNetY-600MF": "dds_baselines/regnety/RegNetY-600MF_dds_8gpu.yaml", - "RegNetY-800MF": "dds_baselines/regnety/RegNetY-800MF_dds_8gpu.yaml", - "RegNetY-1.6GF": "dds_baselines/regnety/RegNetY-1.6GF_dds_8gpu.yaml", - "RegNetY-3.2GF": "dds_baselines/regnety/RegNetY-3.2GF_dds_8gpu.yaml", - "RegNetY-4.0GF": "dds_baselines/regnety/RegNetY-4.0GF_dds_8gpu.yaml", - "RegNetY-6.4GF": "dds_baselines/regnety/RegNetY-6.4GF_dds_8gpu.yaml", - "RegNetY-8.0GF": "dds_baselines/regnety/RegNetY-8.0GF_dds_8gpu.yaml", - "RegNetY-12GF": "dds_baselines/regnety/RegNetY-12GF_dds_8gpu.yaml", - "RegNetY-16GF": "dds_baselines/regnety/RegNetY-16GF_dds_8gpu.yaml", - "RegNetY-32GF": "dds_baselines/regnety/RegNetY-32GF_dds_8gpu.yaml", - "ResNet-50": "dds_baselines/resnet/R-50-1x64d_dds_8gpu.yaml", - "ResNet-101": "dds_baselines/resnet/R-101-1x64d_dds_8gpu.yaml", - "ResNet-152": "dds_baselines/resnet/R-152-1x64d_dds_8gpu.yaml", - "ResNeXt-50": "dds_baselines/resnext/X-50-32x4d_dds_8gpu.yaml", - "ResNeXt-101": "dds_baselines/resnext/X-101-32x4d_dds_8gpu.yaml", - "ResNeXt-152": "dds_baselines/resnext/X-152-32x4d_dds_8gpu.yaml", - "EfficientNet-B0": "dds_baselines/effnet/EN-B0_dds_8gpu.yaml", - "EfficientNet-B1": "dds_baselines/effnet/EN-B1_dds_8gpu.yaml", - "EfficientNet-B2": "dds_baselines/effnet/EN-B2_dds_8gpu.yaml", - "EfficientNet-B3": "dds_baselines/effnet/EN-B3_dds_8gpu.yaml", - "EfficientNet-B4": "dds_baselines/effnet/EN-B4_dds_8gpu.yaml", - "EfficientNet-B5": "dds_baselines/effnet/EN-B5_dds_8gpu.yaml", -} - -# Predefined model weight files -_MODEL_ZOO_WEIGHTS = { - "RegNetX-200MF": "dds_baselines/160905981/RegNetX-200MF_dds_8gpu.pyth", - "RegNetX-400MF": "dds_baselines/160905967/RegNetX-400MF_dds_8gpu.pyth", - "RegNetX-600MF": "dds_baselines/160906442/RegNetX-600MF_dds_8gpu.pyth", - "RegNetX-800MF": "dds_baselines/160906036/RegNetX-800MF_dds_8gpu.pyth", - "RegNetX-1.6GF": "dds_baselines/160990626/RegNetX-1.6GF_dds_8gpu.pyth", - "RegNetX-3.2GF": "dds_baselines/160906139/RegNetX-3.2GF_dds_8gpu.pyth", - "RegNetX-4.0GF": "dds_baselines/160906383/RegNetX-4.0GF_dds_8gpu.pyth", - "RegNetX-6.4GF": "dds_baselines/161116590/RegNetX-6.4GF_dds_8gpu.pyth", - "RegNetX-8.0GF": "dds_baselines/161107726/RegNetX-8.0GF_dds_8gpu.pyth", - "RegNetX-12GF": "dds_baselines/160906020/RegNetX-12GF_dds_8gpu.pyth", - "RegNetX-16GF": "dds_baselines/158460855/RegNetX-16GF_dds_8gpu.pyth", - "RegNetX-32GF": "dds_baselines/158188473/RegNetX-32GF_dds_8gpu.pyth", - "RegNetY-200MF": "dds_baselines/176245422/RegNetY-200MF_dds_8gpu.pyth", - "RegNetY-400MF": "dds_baselines/160906449/RegNetY-400MF_dds_8gpu.pyth", - "RegNetY-600MF": "dds_baselines/160981443/RegNetY-600MF_dds_8gpu.pyth", - "RegNetY-800MF": "dds_baselines/160906567/RegNetY-800MF_dds_8gpu.pyth", - "RegNetY-1.6GF": "dds_baselines/160906681/RegNetY-1.6GF_dds_8gpu.pyth", - "RegNetY-3.2GF": "dds_baselines/160906834/RegNetY-3.2GF_dds_8gpu.pyth", - "RegNetY-4.0GF": "dds_baselines/160906838/RegNetY-4.0GF_dds_8gpu.pyth", - "RegNetY-6.4GF": "dds_baselines/160907112/RegNetY-6.4GF_dds_8gpu.pyth", - "RegNetY-8.0GF": "dds_baselines/161160905/RegNetY-8.0GF_dds_8gpu.pyth", - "RegNetY-12GF": "dds_baselines/160907100/RegNetY-12GF_dds_8gpu.pyth", - "RegNetY-16GF": "dds_baselines/161303400/RegNetY-16GF_dds_8gpu.pyth", - "RegNetY-32GF": "dds_baselines/161277763/RegNetY-32GF_dds_8gpu.pyth", - "ResNet-50": "dds_baselines/161235311/R-50-1x64d_dds_8gpu.pyth", - "ResNet-101": "dds_baselines/161167170/R-101-1x64d_dds_8gpu.pyth", - "ResNet-152": "dds_baselines/161167467/R-152-1x64d_dds_8gpu.pyth", - "ResNeXt-50": "dds_baselines/161167411/X-50-32x4d_dds_8gpu.pyth", - "ResNeXt-101": "dds_baselines/161167590/X-101-32x4d_dds_8gpu.pyth", - "ResNeXt-152": "dds_baselines/162471172/X-152-32x4d_dds_8gpu.pyth", - "EfficientNet-B0": "dds_baselines/161305613/EN-B0_dds_8gpu.pyth", - "EfficientNet-B1": "dds_baselines/161304979/EN-B1_dds_8gpu.pyth", - "EfficientNet-B2": "dds_baselines/161305015/EN-B2_dds_8gpu.pyth", - "EfficientNet-B3": "dds_baselines/161305060/EN-B3_dds_8gpu.pyth", - "EfficientNet-B4": "dds_baselines/161305098/EN-B4_dds_8gpu.pyth", - "EfficientNet-B5": "dds_baselines/161305138/EN-B5_dds_8gpu.pyth", -} - - -def get_model_list(): - """Get list of all valid models in model zoo.""" - return _MODEL_ZOO_WEIGHTS.keys() - - -def get_config_file(name): - """Get file with model config (downloads if necessary).""" - err_str = "Model {} not found in the model zoo.".format(name) - assert name in _MODEL_ZOO_CONFIGS.keys(), err_str - config_url = os.path.join(_URL_CONFIGS, _MODEL_ZOO_CONFIGS[name]) - return cache_url(config_url, _DOWNLOAD_CACHE, _URL_CONFIGS) - - -def get_weights_file(name): - """Get file with model weights (downloads if necessary).""" - err_str = "Model {} not found in the model zoo.".format(name) - assert name in _MODEL_ZOO_WEIGHTS.keys(), err_str - weights_url = os.path.join(_URL_WEIGHTS, _MODEL_ZOO_WEIGHTS[name]) - return cache_url(weights_url, _DOWNLOAD_CACHE, _URL_WEIGHTS) - - -def get_model_info(name): - """Return model info (useful for debugging).""" - config_url = _MODEL_ZOO_CONFIGS[name] - weight_url = _MODEL_ZOO_WEIGHTS[name] - model_id = weight_url.split("/")[1] - config_url_full = os.path.join(_URL_CONFIGS, _MODEL_ZOO_CONFIGS[name]) - weight_url_full = os.path.join(_URL_WEIGHTS, _MODEL_ZOO_WEIGHTS[name]) - return config_url, weight_url, model_id, config_url_full, weight_url_full - - -def build_model(name, pretrained=False, cfg_list=()): - """Constructs a predefined model (note: loads global config as well).""" - # Load the config - reset_cfg() - config_file = get_config_file(name) - cfg.merge_from_file(config_file) - cfg.merge_from_list(cfg_list) - # Construct model - model = builders.build_model() - # Load pretrained weights - if pretrained: - weights_file = get_weights_file(name) - cp.load_checkpoint(weights_file, model) - return model - - -def regnetx(name, pretrained=False, cfg_list=()): - """Constructs a RegNetX model (note: loads global config as well).""" - name = name if "RegNetX-" in name else "RegNetX-" + name - return build_model(name, pretrained, cfg_list) - - -def regnety(name, pretrained=False, cfg_list=()): - """Constructs a RegNetY model (note: loads global config as well).""" - name = name if "RegNetY-" in name else "RegNetY-" + name - return build_model(name, pretrained, cfg_list) - - -def resnet(name, pretrained=False, cfg_list=()): - """Constructs a ResNet model (note: loads global config as well).""" - name = name if "ResNet-" in name else "ResNet-" + name - return build_model(name, pretrained, cfg_list) - - -def resnext(name, pretrained=False, cfg_list=()): - """Constructs a ResNeXt model (note: loads global config as well).""" - name = name if "ResNeXt-" in name else "ResNeXt-" + name - return build_model(name, pretrained, cfg_list) - - -def effnet(name, pretrained=False, cfg_list=()): - """Constructs an EfficientNet model (note: loads global config as well).""" - name = name if "EfficientNet-" in name else "EfficientNet-" + name - return build_model(name, pretrained, cfg_list) +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Model zoo.""" + +import os + +import pycls.core.builders as builders +import pycls.core.checkpoint as cp +from pycls.core.config import cfg, reset_cfg +from pycls.core.io import cache_url + + +# URL prefix for pretrained models +_URL_WEIGHTS = "https://dl.fbaipublicfiles.com/pycls" + +# URL prefix for model config files +_URL_CONFIGS = "https://raw.githubusercontent.com/facebookresearch/pycls/master/configs" + +# Model weights download cache directory +_DOWNLOAD_CACHE = "/tmp/pycls-download-cache" + +# Predefined model config files +_MODEL_ZOO_CONFIGS = { + "RegNetX-200MF": "dds_baselines/regnetx/RegNetX-200MF_dds_8gpu.yaml", + "RegNetX-400MF": "dds_baselines/regnetx/RegNetX-400MF_dds_8gpu.yaml", + "RegNetX-600MF": "dds_baselines/regnetx/RegNetX-600MF_dds_8gpu.yaml", + "RegNetX-800MF": "dds_baselines/regnetx/RegNetX-800MF_dds_8gpu.yaml", + "RegNetX-1.6GF": "dds_baselines/regnetx/RegNetX-1.6GF_dds_8gpu.yaml", + "RegNetX-3.2GF": "dds_baselines/regnetx/RegNetX-3.2GF_dds_8gpu.yaml", + "RegNetX-4.0GF": "dds_baselines/regnetx/RegNetX-4.0GF_dds_8gpu.yaml", + "RegNetX-6.4GF": "dds_baselines/regnetx/RegNetX-6.4GF_dds_8gpu.yaml", + "RegNetX-8.0GF": "dds_baselines/regnetx/RegNetX-8.0GF_dds_8gpu.yaml", + "RegNetX-12GF": "dds_baselines/regnetx/RegNetX-12GF_dds_8gpu.yaml", + "RegNetX-16GF": "dds_baselines/regnetx/RegNetX-16GF_dds_8gpu.yaml", + "RegNetX-32GF": "dds_baselines/regnetx/RegNetX-32GF_dds_8gpu.yaml", + "RegNetY-200MF": "dds_baselines/regnety/RegNetY-200MF_dds_8gpu.yaml", + "RegNetY-400MF": "dds_baselines/regnety/RegNetY-400MF_dds_8gpu.yaml", + "RegNetY-600MF": "dds_baselines/regnety/RegNetY-600MF_dds_8gpu.yaml", + "RegNetY-800MF": "dds_baselines/regnety/RegNetY-800MF_dds_8gpu.yaml", + "RegNetY-1.6GF": "dds_baselines/regnety/RegNetY-1.6GF_dds_8gpu.yaml", + "RegNetY-3.2GF": "dds_baselines/regnety/RegNetY-3.2GF_dds_8gpu.yaml", + "RegNetY-4.0GF": "dds_baselines/regnety/RegNetY-4.0GF_dds_8gpu.yaml", + "RegNetY-6.4GF": "dds_baselines/regnety/RegNetY-6.4GF_dds_8gpu.yaml", + "RegNetY-8.0GF": "dds_baselines/regnety/RegNetY-8.0GF_dds_8gpu.yaml", + "RegNetY-12GF": "dds_baselines/regnety/RegNetY-12GF_dds_8gpu.yaml", + "RegNetY-16GF": "dds_baselines/regnety/RegNetY-16GF_dds_8gpu.yaml", + "RegNetY-32GF": "dds_baselines/regnety/RegNetY-32GF_dds_8gpu.yaml", + "ResNet-50": "dds_baselines/resnet/R-50-1x64d_dds_8gpu.yaml", + "ResNet-101": "dds_baselines/resnet/R-101-1x64d_dds_8gpu.yaml", + "ResNet-152": "dds_baselines/resnet/R-152-1x64d_dds_8gpu.yaml", + "ResNeXt-50": "dds_baselines/resnext/X-50-32x4d_dds_8gpu.yaml", + "ResNeXt-101": "dds_baselines/resnext/X-101-32x4d_dds_8gpu.yaml", + "ResNeXt-152": "dds_baselines/resnext/X-152-32x4d_dds_8gpu.yaml", + "EfficientNet-B0": "dds_baselines/effnet/EN-B0_dds_8gpu.yaml", + "EfficientNet-B1": "dds_baselines/effnet/EN-B1_dds_8gpu.yaml", + "EfficientNet-B2": "dds_baselines/effnet/EN-B2_dds_8gpu.yaml", + "EfficientNet-B3": "dds_baselines/effnet/EN-B3_dds_8gpu.yaml", + "EfficientNet-B4": "dds_baselines/effnet/EN-B4_dds_8gpu.yaml", + "EfficientNet-B5": "dds_baselines/effnet/EN-B5_dds_8gpu.yaml", +} + +# Predefined model weight files +_MODEL_ZOO_WEIGHTS = { + "RegNetX-200MF": "dds_baselines/160905981/RegNetX-200MF_dds_8gpu.pyth", + "RegNetX-400MF": "dds_baselines/160905967/RegNetX-400MF_dds_8gpu.pyth", + "RegNetX-600MF": "dds_baselines/160906442/RegNetX-600MF_dds_8gpu.pyth", + "RegNetX-800MF": "dds_baselines/160906036/RegNetX-800MF_dds_8gpu.pyth", + "RegNetX-1.6GF": "dds_baselines/160990626/RegNetX-1.6GF_dds_8gpu.pyth", + "RegNetX-3.2GF": "dds_baselines/160906139/RegNetX-3.2GF_dds_8gpu.pyth", + "RegNetX-4.0GF": "dds_baselines/160906383/RegNetX-4.0GF_dds_8gpu.pyth", + "RegNetX-6.4GF": "dds_baselines/161116590/RegNetX-6.4GF_dds_8gpu.pyth", + "RegNetX-8.0GF": "dds_baselines/161107726/RegNetX-8.0GF_dds_8gpu.pyth", + "RegNetX-12GF": "dds_baselines/160906020/RegNetX-12GF_dds_8gpu.pyth", + "RegNetX-16GF": "dds_baselines/158460855/RegNetX-16GF_dds_8gpu.pyth", + "RegNetX-32GF": "dds_baselines/158188473/RegNetX-32GF_dds_8gpu.pyth", + "RegNetY-200MF": "dds_baselines/176245422/RegNetY-200MF_dds_8gpu.pyth", + "RegNetY-400MF": "dds_baselines/160906449/RegNetY-400MF_dds_8gpu.pyth", + "RegNetY-600MF": "dds_baselines/160981443/RegNetY-600MF_dds_8gpu.pyth", + "RegNetY-800MF": "dds_baselines/160906567/RegNetY-800MF_dds_8gpu.pyth", + "RegNetY-1.6GF": "dds_baselines/160906681/RegNetY-1.6GF_dds_8gpu.pyth", + "RegNetY-3.2GF": "dds_baselines/160906834/RegNetY-3.2GF_dds_8gpu.pyth", + "RegNetY-4.0GF": "dds_baselines/160906838/RegNetY-4.0GF_dds_8gpu.pyth", + "RegNetY-6.4GF": "dds_baselines/160907112/RegNetY-6.4GF_dds_8gpu.pyth", + "RegNetY-8.0GF": "dds_baselines/161160905/RegNetY-8.0GF_dds_8gpu.pyth", + "RegNetY-12GF": "dds_baselines/160907100/RegNetY-12GF_dds_8gpu.pyth", + "RegNetY-16GF": "dds_baselines/161303400/RegNetY-16GF_dds_8gpu.pyth", + "RegNetY-32GF": "dds_baselines/161277763/RegNetY-32GF_dds_8gpu.pyth", + "ResNet-50": "dds_baselines/161235311/R-50-1x64d_dds_8gpu.pyth", + "ResNet-101": "dds_baselines/161167170/R-101-1x64d_dds_8gpu.pyth", + "ResNet-152": "dds_baselines/161167467/R-152-1x64d_dds_8gpu.pyth", + "ResNeXt-50": "dds_baselines/161167411/X-50-32x4d_dds_8gpu.pyth", + "ResNeXt-101": "dds_baselines/161167590/X-101-32x4d_dds_8gpu.pyth", + "ResNeXt-152": "dds_baselines/162471172/X-152-32x4d_dds_8gpu.pyth", + "EfficientNet-B0": "dds_baselines/161305613/EN-B0_dds_8gpu.pyth", + "EfficientNet-B1": "dds_baselines/161304979/EN-B1_dds_8gpu.pyth", + "EfficientNet-B2": "dds_baselines/161305015/EN-B2_dds_8gpu.pyth", + "EfficientNet-B3": "dds_baselines/161305060/EN-B3_dds_8gpu.pyth", + "EfficientNet-B4": "dds_baselines/161305098/EN-B4_dds_8gpu.pyth", + "EfficientNet-B5": "dds_baselines/161305138/EN-B5_dds_8gpu.pyth", +} + + +def get_model_list(): + """Get list of all valid models in model zoo.""" + return _MODEL_ZOO_WEIGHTS.keys() + + +def get_config_file(name): + """Get file with model config (downloads if necessary).""" + err_str = "Model {} not found in the model zoo.".format(name) + assert name in _MODEL_ZOO_CONFIGS.keys(), err_str + config_url = os.path.join(_URL_CONFIGS, _MODEL_ZOO_CONFIGS[name]) + return cache_url(config_url, _DOWNLOAD_CACHE, _URL_CONFIGS) + + +def get_weights_file(name): + """Get file with model weights (downloads if necessary).""" + err_str = "Model {} not found in the model zoo.".format(name) + assert name in _MODEL_ZOO_WEIGHTS.keys(), err_str + weights_url = os.path.join(_URL_WEIGHTS, _MODEL_ZOO_WEIGHTS[name]) + return cache_url(weights_url, _DOWNLOAD_CACHE, _URL_WEIGHTS) + + +def get_model_info(name): + """Return model info (useful for debugging).""" + config_url = _MODEL_ZOO_CONFIGS[name] + weight_url = _MODEL_ZOO_WEIGHTS[name] + model_id = weight_url.split("/")[1] + config_url_full = os.path.join(_URL_CONFIGS, _MODEL_ZOO_CONFIGS[name]) + weight_url_full = os.path.join(_URL_WEIGHTS, _MODEL_ZOO_WEIGHTS[name]) + return config_url, weight_url, model_id, config_url_full, weight_url_full + + +def build_model(name, pretrained=False, cfg_list=()): + """Constructs a predefined model (note: loads global config as well).""" + # Load the config + reset_cfg() + config_file = get_config_file(name) + cfg.merge_from_file(config_file) + cfg.merge_from_list(cfg_list) + # Construct model + model = builders.build_model() + # Load pretrained weights + if pretrained: + weights_file = get_weights_file(name) + cp.load_checkpoint(weights_file, model) + return model + + +def regnetx(name, pretrained=False, cfg_list=()): + """Constructs a RegNetX model (note: loads global config as well).""" + name = name if "RegNetX-" in name else "RegNetX-" + name + return build_model(name, pretrained, cfg_list) + + +def regnety(name, pretrained=False, cfg_list=()): + """Constructs a RegNetY model (note: loads global config as well).""" + name = name if "RegNetY-" in name else "RegNetY-" + name + return build_model(name, pretrained, cfg_list) + + +def resnet(name, pretrained=False, cfg_list=()): + """Constructs a ResNet model (note: loads global config as well).""" + name = name if "ResNet-" in name else "ResNet-" + name + return build_model(name, pretrained, cfg_list) + + +def resnext(name, pretrained=False, cfg_list=()): + """Constructs a ResNeXt model (note: loads global config as well).""" + name = name if "ResNeXt-" in name else "ResNeXt-" + name + return build_model(name, pretrained, cfg_list) + + +def effnet(name, pretrained=False, cfg_list=()): + """Constructs an EfficientNet model (note: loads global config as well).""" + name = name if "EfficientNet-" in name else "EfficientNet-" + name + return build_model(name, pretrained, cfg_list) diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/regnet.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/regnet.py index 646336bbf572d23f759e103b0170eabaa880f593..271deeb4fa9be7aee39d5b39a9200c9b88753a2b 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/regnet.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/regnet.py @@ -1,83 +1,83 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""RegNet models.""" - -import numpy as np -import pycls.models.blocks as bk -from pycls.core.config import cfg -from pycls.models.anynet import AnyNet - - -def generate_regnet(w_a, w_0, w_m, d, q=8): - """Generates per stage widths and depths from RegNet parameters.""" - assert w_a >= 0 and w_0 > 0 and w_m > 1 and w_0 % q == 0 - # Generate continuous per-block ws - ws_cont = np.arange(d) * w_a + w_0 - # Generate quantized per-block ws - ks = np.round(np.log(ws_cont / w_0) / np.log(w_m)) - ws_all = w_0 * np.power(w_m, ks) - ws_all = np.round(np.divide(ws_all, q)).astype(int) * q - # Generate per stage ws and ds (assumes ws_all are sorted) - ws, ds = np.unique(ws_all, return_counts=True) - # Compute number of actual stages and total possible stages - num_stages, total_stages = len(ws), ks.max() + 1 - # Convert numpy arrays to lists and return - ws, ds, ws_all, ws_cont = (x.tolist() for x in (ws, ds, ws_all, ws_cont)) - return ws, ds, num_stages, total_stages, ws_all, ws_cont - - -class RegNet(AnyNet): - """RegNet model.""" - - @staticmethod - def get_params(): - """Convert RegNet to AnyNet parameter format.""" - # Generates per stage ws, ds, gs, bs, and ss from RegNet parameters - w_a, w_0, w_m, d = cfg.REGNET.WA, cfg.REGNET.W0, cfg.REGNET.WM, cfg.REGNET.DEPTH - ws, ds = generate_regnet(w_a, w_0, w_m, d)[0:2] - ss = [cfg.REGNET.STRIDE for _ in ws] - bs = [cfg.REGNET.BOT_MUL for _ in ws] - gs = [cfg.REGNET.GROUP_W for _ in ws] - ws, bs, gs = bk.adjust_block_compatibility(ws, bs, gs) - # Get AnyNet arguments defining the RegNet - return { - "stem_type": cfg.REGNET.STEM_TYPE, - "stem_w": cfg.REGNET.STEM_W, - "block_type": cfg.REGNET.BLOCK_TYPE, - "depths": ds, - "widths": ws, - "strides": ss, - "bot_muls": bs, - "group_ws": gs, - "se_r": cfg.REGNET.SE_R if cfg.REGNET.SE_ON else 0, - "num_classes": cfg.MODEL.NUM_CLASSES, - } - - def __init__(self): - params = RegNet.get_params() - super(RegNet, self).__init__(params) - - @staticmethod - def complexity(cx, params=None): - """Computes model complexity (if you alter the model, make sure to update).""" - params = RegNet.get_params() if not params else params - return AnyNet.complexity(cx, params) +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""RegNet models.""" + +import numpy as np +import pycls.models.blocks as bk +from pycls.core.config import cfg +from pycls.models.anynet import AnyNet + + +def generate_regnet(w_a, w_0, w_m, d, q=8): + """Generates per stage widths and depths from RegNet parameters.""" + assert w_a >= 0 and w_0 > 0 and w_m > 1 and w_0 % q == 0 + # Generate continuous per-block ws + ws_cont = np.arange(d) * w_a + w_0 + # Generate quantized per-block ws + ks = np.round(np.log(ws_cont / w_0) / np.log(w_m)) + ws_all = w_0 * np.power(w_m, ks) + ws_all = np.round(np.divide(ws_all, q)).astype(int) * q + # Generate per stage ws and ds (assumes ws_all are sorted) + ws, ds = np.unique(ws_all, return_counts=True) + # Compute number of actual stages and total possible stages + num_stages, total_stages = len(ws), ks.max() + 1 + # Convert numpy arrays to lists and return + ws, ds, ws_all, ws_cont = (x.tolist() for x in (ws, ds, ws_all, ws_cont)) + return ws, ds, num_stages, total_stages, ws_all, ws_cont + + +class RegNet(AnyNet): + """RegNet model.""" + + @staticmethod + def get_params(): + """Convert RegNet to AnyNet parameter format.""" + # Generates per stage ws, ds, gs, bs, and ss from RegNet parameters + w_a, w_0, w_m, d = cfg.REGNET.WA, cfg.REGNET.W0, cfg.REGNET.WM, cfg.REGNET.DEPTH + ws, ds = generate_regnet(w_a, w_0, w_m, d)[0:2] + ss = [cfg.REGNET.STRIDE for _ in ws] + bs = [cfg.REGNET.BOT_MUL for _ in ws] + gs = [cfg.REGNET.GROUP_W for _ in ws] + ws, bs, gs = bk.adjust_block_compatibility(ws, bs, gs) + # Get AnyNet arguments defining the RegNet + return { + "stem_type": cfg.REGNET.STEM_TYPE, + "stem_w": cfg.REGNET.STEM_W, + "block_type": cfg.REGNET.BLOCK_TYPE, + "depths": ds, + "widths": ws, + "strides": ss, + "bot_muls": bs, + "group_ws": gs, + "se_r": cfg.REGNET.SE_R if cfg.REGNET.SE_ON else 0, + "num_classes": cfg.MODEL.NUM_CLASSES, + } + + def __init__(self): + params = RegNet.get_params() + super(RegNet, self).__init__(params) + + @staticmethod + def complexity(cx, params=None): + """Computes model complexity (if you alter the model, make sure to update).""" + params = RegNet.get_params() if not params else params + return AnyNet.complexity(cx, params) diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/resnet.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/resnet.py index 5f3dbdde7b97cd2751534a657a0eaa58c2c60a84..2a26bbe8267eb14bb2c8f7e55c4e2aeef037d443 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/resnet.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/pycls/models/resnet.py @@ -1,301 +1,301 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""ResNe(X)t models.""" - -from pycls.core.config import cfg -from pycls.models.blocks import ( - activation, - conv2d, - conv2d_cx, - gap2d, - gap2d_cx, - init_weights, - linear, - linear_cx, - norm2d, - norm2d_cx, - pool2d, - pool2d_cx, -) -from torch.nn import Module - - -# Stage depths for ImageNet models -_IN_STAGE_DS = {50: (3, 4, 6, 3), 101: (3, 4, 23, 3), 152: (3, 8, 36, 3)} - - -def get_trans_fun(name): - """Retrieves the transformation function by name.""" - trans_funs = { - "basic_transform": BasicTransform, - "bottleneck_transform": BottleneckTransform, - } - err_str = "Transformation function '{}' not supported" - assert name in trans_funs.keys(), err_str.format(name) - return trans_funs[name] - - -class ResHead(Module): - """ResNet head: AvgPool, 1x1.""" - - def __init__(self, w_in, num_classes): - super(ResHead, self).__init__() - self.avg_pool = gap2d(w_in) - self.fc = linear(w_in, num_classes, bias=True) - - def forward(self, x): - x = self.avg_pool(x) - x = x.view(x.size(0), -1) - x = self.fc(x) - return x - - @staticmethod - def complexity(cx, w_in, num_classes): - cx = gap2d_cx(cx, w_in) - cx = linear_cx(cx, w_in, num_classes, bias=True) - return cx - - -class BasicTransform(Module): - """Basic transformation: 3x3, BN, AF, 3x3, BN.""" - - def __init__(self, w_in, w_out, stride, w_b=None, groups=1): - err_str = "Basic transform does not support w_b and groups options" - assert w_b is None and groups == 1, err_str - super(BasicTransform, self).__init__() - self.a = conv2d(w_in, w_out, 3, stride=stride) - self.a_bn = norm2d(w_out) - self.a_af = activation() - self.b = conv2d(w_out, w_out, 3) - self.b_bn = norm2d(w_out) - self.b_bn.final_bn = True - - def forward(self, x): - for layer in self.children(): - x = layer(x) - return x - - @staticmethod - def complexity(cx, w_in, w_out, stride, w_b=None, groups=1): - err_str = "Basic transform does not support w_b and groups options" - assert w_b is None and groups == 1, err_str - cx = conv2d_cx(cx, w_in, w_out, 3, stride=stride) - cx = norm2d_cx(cx, w_out) - cx = conv2d_cx(cx, w_out, w_out, 3) - cx = norm2d_cx(cx, w_out) - return cx - - -class BottleneckTransform(Module): - """Bottleneck transformation: 1x1, BN, AF, 3x3, BN, AF, 1x1, BN.""" - - def __init__(self, w_in, w_out, stride, w_b, groups): - super(BottleneckTransform, self).__init__() - # MSRA -> stride=2 is on 1x1; TH/C2 -> stride=2 is on 3x3 - (s1, s3) = (stride, 1) if cfg.RESNET.STRIDE_1X1 else (1, stride) - self.a = conv2d(w_in, w_b, 1, stride=s1) - self.a_bn = norm2d(w_b) - self.a_af = activation() - self.b = conv2d(w_b, w_b, 3, stride=s3, groups=groups) - self.b_bn = norm2d(w_b) - self.b_af = activation() - self.c = conv2d(w_b, w_out, 1) - self.c_bn = norm2d(w_out) - self.c_bn.final_bn = True - - def forward(self, x): - for layer in self.children(): - x = layer(x) - return x - - @staticmethod - def complexity(cx, w_in, w_out, stride, w_b, groups): - (s1, s3) = (stride, 1) if cfg.RESNET.STRIDE_1X1 else (1, stride) - cx = conv2d_cx(cx, w_in, w_b, 1, stride=s1) - cx = norm2d_cx(cx, w_b) - cx = conv2d_cx(cx, w_b, w_b, 3, stride=s3, groups=groups) - cx = norm2d_cx(cx, w_b) - cx = conv2d_cx(cx, w_b, w_out, 1) - cx = norm2d_cx(cx, w_out) - return cx - - -class ResBlock(Module): - """Residual block: x + f(x).""" - - def __init__(self, w_in, w_out, stride, trans_fun, w_b=None, groups=1): - super(ResBlock, self).__init__() - self.proj, self.bn = None, None - if (w_in != w_out) or (stride != 1): - self.proj = conv2d(w_in, w_out, 1, stride=stride) - self.bn = norm2d(w_out) - self.f = trans_fun(w_in, w_out, stride, w_b, groups) - self.af = activation() - - def forward(self, x): - x_p = self.bn(self.proj(x)) if self.proj else x - return self.af(x_p + self.f(x)) - - @staticmethod - def complexity(cx, w_in, w_out, stride, trans_fun, w_b, groups): - if (w_in != w_out) or (stride != 1): - h, w = cx["h"], cx["w"] - cx = conv2d_cx(cx, w_in, w_out, 1, stride=stride) - cx = norm2d_cx(cx, w_out) - cx["h"], cx["w"] = h, w - cx = trans_fun.complexity(cx, w_in, w_out, stride, w_b, groups) - return cx - - -class ResStage(Module): - """Stage of ResNet.""" - - def __init__(self, w_in, w_out, stride, d, w_b=None, groups=1): - super(ResStage, self).__init__() - for i in range(d): - b_stride = stride if i == 0 else 1 - b_w_in = w_in if i == 0 else w_out - trans_fun = get_trans_fun(cfg.RESNET.TRANS_FUN) - res_block = ResBlock(b_w_in, w_out, b_stride, trans_fun, w_b, groups) - self.add_module("b{}".format(i + 1), res_block) - - def forward(self, x): - for block in self.children(): - x = block(x) - return x - - @staticmethod - def complexity(cx, w_in, w_out, stride, d, w_b=None, groups=1): - for i in range(d): - b_stride = stride if i == 0 else 1 - b_w_in = w_in if i == 0 else w_out - trans_f = get_trans_fun(cfg.RESNET.TRANS_FUN) - cx = ResBlock.complexity(cx, b_w_in, w_out, b_stride, trans_f, w_b, groups) - return cx - - -class ResStemCifar(Module): - """ResNet stem for CIFAR: 3x3, BN, AF.""" - - def __init__(self, w_in, w_out): - super(ResStemCifar, self).__init__() - self.conv = conv2d(w_in, w_out, 3) - self.bn = norm2d(w_out) - self.af = activation() - - def forward(self, x): - for layer in self.children(): - x = layer(x) - return x - - @staticmethod - def complexity(cx, w_in, w_out): - cx = conv2d_cx(cx, w_in, w_out, 3) - cx = norm2d_cx(cx, w_out) - return cx - - -class ResStemIN(Module): - """ResNet stem for ImageNet: 7x7, BN, AF, MaxPool.""" - - def __init__(self, w_in, w_out): - super(ResStemIN, self).__init__() - self.conv = conv2d(w_in, w_out, 7, stride=2) - self.bn = norm2d(w_out) - self.af = activation() - self.pool = pool2d(w_out, 3, stride=2) - - def forward(self, x): - for layer in self.children(): - x = layer(x) - return x - - @staticmethod - def complexity(cx, w_in, w_out): - cx = conv2d_cx(cx, w_in, w_out, 7, stride=2) - cx = norm2d_cx(cx, w_out) - cx = pool2d_cx(cx, w_out, 3, stride=2) - return cx - - -class ResNet(Module): - """ResNet model.""" - - def __init__(self): - datasets = ["cifar10", "imagenet"] - err_str = "Dataset {} is not supported" - assert cfg.TRAIN.DATASET in datasets, err_str.format(cfg.TRAIN.DATASET) - assert cfg.TEST.DATASET in datasets, err_str.format(cfg.TEST.DATASET) - super(ResNet, self).__init__() - if "cifar" in cfg.TRAIN.DATASET: - self._construct_cifar() - else: - self._construct_imagenet() - self.apply(init_weights) - - def _construct_cifar(self): - err_str = "Model depth should be of the format 6n + 2 for cifar" - assert (cfg.MODEL.DEPTH - 2) % 6 == 0, err_str - d = int((cfg.MODEL.DEPTH - 2) / 6) - self.stem = ResStemCifar(3, 16) - self.s1 = ResStage(16, 16, stride=1, d=d) - self.s2 = ResStage(16, 32, stride=2, d=d) - self.s3 = ResStage(32, 64, stride=2, d=d) - self.head = ResHead(64, cfg.MODEL.NUM_CLASSES) - - def _construct_imagenet(self): - g, gw = cfg.RESNET.NUM_GROUPS, cfg.RESNET.WIDTH_PER_GROUP - (d1, d2, d3, d4) = _IN_STAGE_DS[cfg.MODEL.DEPTH] - w_b = gw * g - self.stem = ResStemIN(3, 64) - self.s1 = ResStage(64, 256, stride=1, d=d1, w_b=w_b, groups=g) - self.s2 = ResStage(256, 512, stride=2, d=d2, w_b=w_b * 2, groups=g) - self.s3 = ResStage(512, 1024, stride=2, d=d3, w_b=w_b * 4, groups=g) - self.s4 = ResStage(1024, 2048, stride=2, d=d4, w_b=w_b * 8, groups=g) - self.head = ResHead(2048, cfg.MODEL.NUM_CLASSES) - - def forward(self, x): - for module in self.children(): - x = module(x) - return x - - @staticmethod - def complexity(cx): - """Computes model complexity. If you alter the model, make sure to update.""" - if "cifar" in cfg.TRAIN.DATASET: - d = int((cfg.MODEL.DEPTH - 2) / 6) - cx = ResStemCifar.complexity(cx, 3, 16) - cx = ResStage.complexity(cx, 16, 16, stride=1, d=d) - cx = ResStage.complexity(cx, 16, 32, stride=2, d=d) - cx = ResStage.complexity(cx, 32, 64, stride=2, d=d) - cx = ResHead.complexity(cx, 64, cfg.MODEL.NUM_CLASSES) - else: - g, gw = cfg.RESNET.NUM_GROUPS, cfg.RESNET.WIDTH_PER_GROUP - (d1, d2, d3, d4) = _IN_STAGE_DS[cfg.MODEL.DEPTH] - w_b = gw * g - cx = ResStemIN.complexity(cx, 3, 64) - cx = ResStage.complexity(cx, 64, 256, 1, d=d1, w_b=w_b, groups=g) - cx = ResStage.complexity(cx, 256, 512, 2, d=d2, w_b=w_b * 2, groups=g) - cx = ResStage.complexity(cx, 512, 1024, 2, d=d3, w_b=w_b * 4, groups=g) - cx = ResStage.complexity(cx, 1024, 2048, 2, d=d4, w_b=w_b * 8, groups=g) - cx = ResHead.complexity(cx, 2048, cfg.MODEL.NUM_CLASSES) - return cx +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""ResNe(X)t models.""" + +from pycls.core.config import cfg +from pycls.models.blocks import ( + activation, + conv2d, + conv2d_cx, + gap2d, + gap2d_cx, + init_weights, + linear, + linear_cx, + norm2d, + norm2d_cx, + pool2d, + pool2d_cx, +) +from torch.nn import Module + + +# Stage depths for ImageNet models +_IN_STAGE_DS = {50: (3, 4, 6, 3), 101: (3, 4, 23, 3), 152: (3, 8, 36, 3)} + + +def get_trans_fun(name): + """Retrieves the transformation function by name.""" + trans_funs = { + "basic_transform": BasicTransform, + "bottleneck_transform": BottleneckTransform, + } + err_str = "Transformation function '{}' not supported" + assert name in trans_funs.keys(), err_str.format(name) + return trans_funs[name] + + +class ResHead(Module): + """ResNet head: AvgPool, 1x1.""" + + def __init__(self, w_in, num_classes): + super(ResHead, self).__init__() + self.avg_pool = gap2d(w_in) + self.fc = linear(w_in, num_classes, bias=True) + + def forward(self, x): + x = self.avg_pool(x) + x = x.view(x.size(0), -1) + x = self.fc(x) + return x + + @staticmethod + def complexity(cx, w_in, num_classes): + cx = gap2d_cx(cx, w_in) + cx = linear_cx(cx, w_in, num_classes, bias=True) + return cx + + +class BasicTransform(Module): + """Basic transformation: 3x3, BN, AF, 3x3, BN.""" + + def __init__(self, w_in, w_out, stride, w_b=None, groups=1): + err_str = "Basic transform does not support w_b and groups options" + assert w_b is None and groups == 1, err_str + super(BasicTransform, self).__init__() + self.a = conv2d(w_in, w_out, 3, stride=stride) + self.a_bn = norm2d(w_out) + self.a_af = activation() + self.b = conv2d(w_out, w_out, 3) + self.b_bn = norm2d(w_out) + self.b_bn.final_bn = True + + def forward(self, x): + for layer in self.children(): + x = layer(x) + return x + + @staticmethod + def complexity(cx, w_in, w_out, stride, w_b=None, groups=1): + err_str = "Basic transform does not support w_b and groups options" + assert w_b is None and groups == 1, err_str + cx = conv2d_cx(cx, w_in, w_out, 3, stride=stride) + cx = norm2d_cx(cx, w_out) + cx = conv2d_cx(cx, w_out, w_out, 3) + cx = norm2d_cx(cx, w_out) + return cx + + +class BottleneckTransform(Module): + """Bottleneck transformation: 1x1, BN, AF, 3x3, BN, AF, 1x1, BN.""" + + def __init__(self, w_in, w_out, stride, w_b, groups): + super(BottleneckTransform, self).__init__() + # MSRA -> stride=2 is on 1x1; TH/C2 -> stride=2 is on 3x3 + (s1, s3) = (stride, 1) if cfg.RESNET.STRIDE_1X1 else (1, stride) + self.a = conv2d(w_in, w_b, 1, stride=s1) + self.a_bn = norm2d(w_b) + self.a_af = activation() + self.b = conv2d(w_b, w_b, 3, stride=s3, groups=groups) + self.b_bn = norm2d(w_b) + self.b_af = activation() + self.c = conv2d(w_b, w_out, 1) + self.c_bn = norm2d(w_out) + self.c_bn.final_bn = True + + def forward(self, x): + for layer in self.children(): + x = layer(x) + return x + + @staticmethod + def complexity(cx, w_in, w_out, stride, w_b, groups): + (s1, s3) = (stride, 1) if cfg.RESNET.STRIDE_1X1 else (1, stride) + cx = conv2d_cx(cx, w_in, w_b, 1, stride=s1) + cx = norm2d_cx(cx, w_b) + cx = conv2d_cx(cx, w_b, w_b, 3, stride=s3, groups=groups) + cx = norm2d_cx(cx, w_b) + cx = conv2d_cx(cx, w_b, w_out, 1) + cx = norm2d_cx(cx, w_out) + return cx + + +class ResBlock(Module): + """Residual block: x + f(x).""" + + def __init__(self, w_in, w_out, stride, trans_fun, w_b=None, groups=1): + super(ResBlock, self).__init__() + self.proj, self.bn = None, None + if (w_in != w_out) or (stride != 1): + self.proj = conv2d(w_in, w_out, 1, stride=stride) + self.bn = norm2d(w_out) + self.f = trans_fun(w_in, w_out, stride, w_b, groups) + self.af = activation() + + def forward(self, x): + x_p = self.bn(self.proj(x)) if self.proj else x + return self.af(x_p + self.f(x)) + + @staticmethod + def complexity(cx, w_in, w_out, stride, trans_fun, w_b, groups): + if (w_in != w_out) or (stride != 1): + h, w = cx["h"], cx["w"] + cx = conv2d_cx(cx, w_in, w_out, 1, stride=stride) + cx = norm2d_cx(cx, w_out) + cx["h"], cx["w"] = h, w + cx = trans_fun.complexity(cx, w_in, w_out, stride, w_b, groups) + return cx + + +class ResStage(Module): + """Stage of ResNet.""" + + def __init__(self, w_in, w_out, stride, d, w_b=None, groups=1): + super(ResStage, self).__init__() + for i in range(d): + b_stride = stride if i == 0 else 1 + b_w_in = w_in if i == 0 else w_out + trans_fun = get_trans_fun(cfg.RESNET.TRANS_FUN) + res_block = ResBlock(b_w_in, w_out, b_stride, trans_fun, w_b, groups) + self.add_module("b{}".format(i + 1), res_block) + + def forward(self, x): + for block in self.children(): + x = block(x) + return x + + @staticmethod + def complexity(cx, w_in, w_out, stride, d, w_b=None, groups=1): + for i in range(d): + b_stride = stride if i == 0 else 1 + b_w_in = w_in if i == 0 else w_out + trans_f = get_trans_fun(cfg.RESNET.TRANS_FUN) + cx = ResBlock.complexity(cx, b_w_in, w_out, b_stride, trans_f, w_b, groups) + return cx + + +class ResStemCifar(Module): + """ResNet stem for CIFAR: 3x3, BN, AF.""" + + def __init__(self, w_in, w_out): + super(ResStemCifar, self).__init__() + self.conv = conv2d(w_in, w_out, 3) + self.bn = norm2d(w_out) + self.af = activation() + + def forward(self, x): + for layer in self.children(): + x = layer(x) + return x + + @staticmethod + def complexity(cx, w_in, w_out): + cx = conv2d_cx(cx, w_in, w_out, 3) + cx = norm2d_cx(cx, w_out) + return cx + + +class ResStemIN(Module): + """ResNet stem for ImageNet: 7x7, BN, AF, MaxPool.""" + + def __init__(self, w_in, w_out): + super(ResStemIN, self).__init__() + self.conv = conv2d(w_in, w_out, 7, stride=2) + self.bn = norm2d(w_out) + self.af = activation() + self.pool = pool2d(w_out, 3, stride=2) + + def forward(self, x): + for layer in self.children(): + x = layer(x) + return x + + @staticmethod + def complexity(cx, w_in, w_out): + cx = conv2d_cx(cx, w_in, w_out, 7, stride=2) + cx = norm2d_cx(cx, w_out) + cx = pool2d_cx(cx, w_out, 3, stride=2) + return cx + + +class ResNet(Module): + """ResNet model.""" + + def __init__(self): + datasets = ["cifar10", "imagenet"] + err_str = "Dataset {} is not supported" + assert cfg.TRAIN.DATASET in datasets, err_str.format(cfg.TRAIN.DATASET) + assert cfg.TEST.DATASET in datasets, err_str.format(cfg.TEST.DATASET) + super(ResNet, self).__init__() + if "cifar" in cfg.TRAIN.DATASET: + self._construct_cifar() + else: + self._construct_imagenet() + self.apply(init_weights) + + def _construct_cifar(self): + err_str = "Model depth should be of the format 6n + 2 for cifar" + assert (cfg.MODEL.DEPTH - 2) % 6 == 0, err_str + d = int((cfg.MODEL.DEPTH - 2) / 6) + self.stem = ResStemCifar(3, 16) + self.s1 = ResStage(16, 16, stride=1, d=d) + self.s2 = ResStage(16, 32, stride=2, d=d) + self.s3 = ResStage(32, 64, stride=2, d=d) + self.head = ResHead(64, cfg.MODEL.NUM_CLASSES) + + def _construct_imagenet(self): + g, gw = cfg.RESNET.NUM_GROUPS, cfg.RESNET.WIDTH_PER_GROUP + (d1, d2, d3, d4) = _IN_STAGE_DS[cfg.MODEL.DEPTH] + w_b = gw * g + self.stem = ResStemIN(3, 64) + self.s1 = ResStage(64, 256, stride=1, d=d1, w_b=w_b, groups=g) + self.s2 = ResStage(256, 512, stride=2, d=d2, w_b=w_b * 2, groups=g) + self.s3 = ResStage(512, 1024, stride=2, d=d3, w_b=w_b * 4, groups=g) + self.s4 = ResStage(1024, 2048, stride=2, d=d4, w_b=w_b * 8, groups=g) + self.head = ResHead(2048, cfg.MODEL.NUM_CLASSES) + + def forward(self, x): + for module in self.children(): + x = module(x) + return x + + @staticmethod + def complexity(cx): + """Computes model complexity. If you alter the model, make sure to update.""" + if "cifar" in cfg.TRAIN.DATASET: + d = int((cfg.MODEL.DEPTH - 2) / 6) + cx = ResStemCifar.complexity(cx, 3, 16) + cx = ResStage.complexity(cx, 16, 16, stride=1, d=d) + cx = ResStage.complexity(cx, 16, 32, stride=2, d=d) + cx = ResStage.complexity(cx, 32, 64, stride=2, d=d) + cx = ResHead.complexity(cx, 64, cfg.MODEL.NUM_CLASSES) + else: + g, gw = cfg.RESNET.NUM_GROUPS, cfg.RESNET.WIDTH_PER_GROUP + (d1, d2, d3, d4) = _IN_STAGE_DS[cfg.MODEL.DEPTH] + w_b = gw * g + cx = ResStemIN.complexity(cx, 3, 64) + cx = ResStage.complexity(cx, 64, 256, 1, d=d1, w_b=w_b, groups=g) + cx = ResStage.complexity(cx, 256, 512, 2, d=d2, w_b=w_b * 2, groups=g) + cx = ResStage.complexity(cx, 512, 1024, 2, d=d3, w_b=w_b * 4, groups=g) + cx = ResStage.complexity(cx, 1024, 2048, 2, d=d4, w_b=w_b * 8, groups=g) + cx = ResHead.complexity(cx, 2048, cfg.MODEL.NUM_CLASSES) + return cx diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/tools/test_net.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/tools/test_net.py index 626ee91bf4a87b8c102d864ca74010eada35ad24..c56c75efe7e957ac482c9791a4b8b71fe3ca9992 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/tools/test_net.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/tools/test_net.py @@ -1,40 +1,40 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -"""Test a trained classification model.""" -import sys -sys.path.append("./") -import pycls.core.config as config -import pycls.core.distributed as dist -import pycls.core.trainer as trainer -from pycls.core.config import cfg - - -def main(): - config.load_cfg_fom_args("Test a trained classification model.") - config.assert_and_infer_cfg() - cfg.freeze() - dist.multi_proc_run(num_proc=cfg.NUM_GPUS, fun=trainer.test_model) - - -if __name__ == "__main__": - main() +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +"""Test a trained classification model.""" +import sys +sys.path.append("./") +import pycls.core.config as config +import pycls.core.distributed as dist +import pycls.core.trainer as trainer +from pycls.core.config import cfg + + +def main(): + config.load_cfg_fom_args("Test a trained classification model.") + config.assert_and_infer_cfg() + cfg.freeze() + dist.multi_proc_run(num_proc=cfg.NUM_GPUS, fun=trainer.test_model) + + +if __name__ == "__main__": + main() diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/tools/time_net.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/tools/time_net.py index ac6495a1db816fc80c2b325216626a22acd8656a..6ae03883617385c7fa14134309cb632200f40c08 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/tools/time_net.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/tools/time_net.py @@ -1,39 +1,39 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -"""Compute model and loader timings.""" - -import pycls.core.config as config -import pycls.core.distributed as dist -import pycls.core.trainer as trainer -from pycls.core.config import cfg - - -def main(): - config.load_cfg_fom_args("Compute model and loader timings.") - config.assert_and_infer_cfg() - cfg.freeze() - dist.multi_proc_run(num_proc=cfg.NUM_GPUS, fun=trainer.time_model) - - -if __name__ == "__main__": - main() +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +"""Compute model and loader timings.""" + +import pycls.core.config as config +import pycls.core.distributed as dist +import pycls.core.trainer as trainer +from pycls.core.config import cfg + + +def main(): + config.load_cfg_fom_args("Compute model and loader timings.") + config.assert_and_infer_cfg() + cfg.freeze() + dist.multi_proc_run(num_proc=cfg.NUM_GPUS, fun=trainer.time_model) + + +if __name__ == "__main__": + main() diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B1/tools/train_net.py b/PyTorch/contrib/cv/classification/EfficientNet-B1/tools/train_net.py index 58be5ef71172d6df4feeed4e8cefa621dbabb929..b0277737d830dc3603f4043c7179c18f2dc53ff0 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B1/tools/train_net.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B1/tools/train_net.py @@ -1,106 +1,106 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - - -"""Train a classification model.""" -import sys -sys.path.append("./") -import pycls.core.config as config -import pycls.core.distributed as dist -import pycls.core.trainer as trainer -from pycls.core.config import cfg -import argparse,sys,os,torch -import torch - -def init_process_group(proc_rank, world_size, device_type="npu", port="29588"): - """Initializes the default process group.""" - - # Initialize the process group - print("==================================") - print('Begin init_process_group') - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = port - if device_type == "npu": - torch.distributed.init_process_group( - backend=cfg.DIST_BACKEND, - world_size=world_size, - rank=proc_rank - ) - elif device_type == "gpu": - torch.distributed.init_process_group( - backend=cfg.DIST_BACKEND, - init_method="tcp://{}:{}".format("127.0.0.1", port), - world_size=world_size, - rank=proc_rank - ) - - print("==================================") - print("Done init_process_group") - - # Set the GPU to use - #torch.cuda.set_device(proc_rank) - if device_type == "npu": - torch.npu.set_device(proc_rank) - elif device_type == "gpu": - torch.cuda.set_device(proc_rank) - print('Done set device', device_type, cfg.DIST_BACKEND, world_size, proc_rank) - -def main(): - """Load config from command line arguments and set any specified options.""" - parser = argparse.ArgumentParser(description="Config file options.") - parser.add_argument("--device", help="gpu or npu", default="npu", type=str) - parser.add_argument("--profperf", help="0 or 1", default=0, type=int) - help_s = "Config file location" - parser.add_argument("--cfg", dest="cfg_file", help=help_s, required=True, type=str) - parser.add_argument("--rank_id", dest="rank_id", default=0, type=int) - parser.add_argument("--device_id", dest="device_id", default=0, type=int) - help_s = "See pycls/core/config.py for all options" - parser.add_argument("opts", help=help_s, default=None, nargs=argparse.REMAINDER) - if len(sys.argv) == 1: - parser.print_help() - sys.exit(1) - args = parser.parse_args() - print(args) - - config.merge_from_file(args.cfg_file) - config._C.merge_from_list(args.opts) - config.assert_and_infer_cfg() - cfg.freeze() - - if cfg.NUM_GPUS > 1: - init_process_group(proc_rank=args.rank_id, world_size=cfg.NUM_GPUS, device_type=args.device) - elif args.device == "npu": - torch.npu.set_device(args.device_id) - elif args.device == "gpu": - torch.cuda.set_device(args.device_id) - - if args.device == "npu": - cur_device = torch.npu.current_device() - elif args.device == "gpu": - cur_device = torch.cuda.current_device() - print('cur_device: ', cur_device) - - trainer.train_model(args.device, args.profperf) - - -if __name__ == "__main__": - main() +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + + +"""Train a classification model.""" +import sys +sys.path.append("./") +import pycls.core.config as config +import pycls.core.distributed as dist +import pycls.core.trainer as trainer +from pycls.core.config import cfg +import argparse,sys,os,torch +import torch + +def init_process_group(proc_rank, world_size, device_type="npu", port="29588"): + """Initializes the default process group.""" + + # Initialize the process group + print("==================================") + print('Begin init_process_group') + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = port + if device_type == "npu": + torch.distributed.init_process_group( + backend=cfg.DIST_BACKEND, + world_size=world_size, + rank=proc_rank + ) + elif device_type == "gpu": + torch.distributed.init_process_group( + backend=cfg.DIST_BACKEND, + init_method="tcp://{}:{}".format("127.0.0.1", port), + world_size=world_size, + rank=proc_rank + ) + + print("==================================") + print("Done init_process_group") + + # Set the GPU to use + #torch.cuda.set_device(proc_rank) + if device_type == "npu": + torch.npu.set_device(proc_rank) + elif device_type == "gpu": + torch.cuda.set_device(proc_rank) + print('Done set device', device_type, cfg.DIST_BACKEND, world_size, proc_rank) + +def main(): + """Load config from command line arguments and set any specified options.""" + parser = argparse.ArgumentParser(description="Config file options.") + parser.add_argument("--device", help="gpu or npu", default="npu", type=str) + parser.add_argument("--profperf", help="0 or 1", default=0, type=int) + help_s = "Config file location" + parser.add_argument("--cfg", dest="cfg_file", help=help_s, required=True, type=str) + parser.add_argument("--rank_id", dest="rank_id", default=0, type=int) + parser.add_argument("--device_id", dest="device_id", default=0, type=int) + help_s = "See pycls/core/config.py for all options" + parser.add_argument("opts", help=help_s, default=None, nargs=argparse.REMAINDER) + if len(sys.argv) == 1: + parser.print_help() + sys.exit(1) + args = parser.parse_args() + print(args) + + config.merge_from_file(args.cfg_file) + config._C.merge_from_list(args.opts) + config.assert_and_infer_cfg() + cfg.freeze() + + if cfg.NUM_GPUS > 1: + init_process_group(proc_rank=args.rank_id, world_size=cfg.NUM_GPUS, device_type=args.device) + elif args.device == "npu": + torch.npu.set_device(args.device_id) + elif args.device == "gpu": + torch.cuda.set_device(args.device_id) + + if args.device == "npu": + cur_device = torch.npu.current_device() + elif args.device == "gpu": + cur_device = torch.cuda.current_device() + print('cur_device: ', cur_device) + + trainer.train_model(args.device, args.profperf) + + +if __name__ == "__main__": + main() diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B3/modelzoo_level.txt b/PyTorch/contrib/cv/classification/EfficientNet-B3/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B3/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/EfficientNet-B3/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/config.py b/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/config.py index 8bef12be1a1c99e8c056e77e80ac73faf2bf60a6..5cfeb0d2aeb590064287bcde0e2ae718cca5ae90 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/config.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/config.py @@ -1,429 +1,429 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -"""Configuration file (powered by YACS).""" - -import argparse,sys,os,torch -from iopath.common.file_io import g_pathmgr -from pycls.core.io import cache_url -from yacs.config import CfgNode as CfgNode - -# Global config object (example usage: from core.config import cfg) -_C = CfgNode() -cfg = _C - - -# ---------------------------------- Model options ----------------------------------- # -_C.MODEL = CfgNode() - -# Model type -_C.MODEL.TYPE = "" - -# Number of weight layers -_C.MODEL.DEPTH = 0 - -# Number of classes -_C.MODEL.NUM_CLASSES = 10 - -# Loss function (see pycls/models/loss.py for options) -_C.MODEL.LOSS_FUN = "cross_entropy" - -# Activation function (relu or silu/swish) -_C.MODEL.ACTIVATION_FUN = "relu" - -# Perform activation inplace if implemented -_C.MODEL.ACTIVATION_INPLACE = True - - -# ---------------------------------- ResNet options ---------------------------------- # -_C.RESNET = CfgNode() - -# Transformation function (see pycls/models/resnet.py for options) -_C.RESNET.TRANS_FUN = "basic_transform" - -# Number of groups to use (1 -> ResNet; > 1 -> ResNeXt) -_C.RESNET.NUM_GROUPS = 1 - -# Width of each group (64 -> ResNet; 4 -> ResNeXt) -_C.RESNET.WIDTH_PER_GROUP = 64 - -# Apply stride to 1x1 conv (True -> MSRA; False -> fb.torch) -_C.RESNET.STRIDE_1X1 = True - - -# ---------------------------------- AnyNet options ---------------------------------- # -_C.ANYNET = CfgNode() - -# Stem type -_C.ANYNET.STEM_TYPE = "simple_stem_in" - -# Stem width -_C.ANYNET.STEM_W = 32 - -# Block type -_C.ANYNET.BLOCK_TYPE = "res_bottleneck_block" - -# Depth for each stage (number of blocks in the stage) -_C.ANYNET.DEPTHS = [] - -# Width for each stage (width of each block in the stage) -_C.ANYNET.WIDTHS = [] - -# Strides for each stage (applies to the first block of each stage) -_C.ANYNET.STRIDES = [] - -# Bottleneck multipliers for each stage (applies to bottleneck block) -_C.ANYNET.BOT_MULS = [] - -# Group widths for each stage (applies to bottleneck block) -_C.ANYNET.GROUP_WS = [] - -# Whether SE is enabled for res_bottleneck_block -_C.ANYNET.SE_ON = False - -# SE ratio -_C.ANYNET.SE_R = 0.25 - - -# ---------------------------------- RegNet options ---------------------------------- # -_C.REGNET = CfgNode() - -# Stem type -_C.REGNET.STEM_TYPE = "simple_stem_in" - -# Stem width -_C.REGNET.STEM_W = 32 - -# Block type -_C.REGNET.BLOCK_TYPE = "res_bottleneck_block" - -# Stride of each stage -_C.REGNET.STRIDE = 2 - -# Squeeze-and-Excitation (RegNetY) -_C.REGNET.SE_ON = False -_C.REGNET.SE_R = 0.25 - -# Depth -_C.REGNET.DEPTH = 10 - -# Initial width -_C.REGNET.W0 = 32 - -# Slope -_C.REGNET.WA = 5.0 - -# Quantization -_C.REGNET.WM = 2.5 - -# Group width -_C.REGNET.GROUP_W = 16 - -# Bottleneck multiplier (bm = 1 / b from the paper) -_C.REGNET.BOT_MUL = 1.0 - - -# ------------------------------- EfficientNet options ------------------------------- # -_C.EN = CfgNode() - -# Stem width -_C.EN.STEM_W = 32 - -# Depth for each stage (number of blocks in the stage) -_C.EN.DEPTHS = [] - -# Width for each stage (width of each block in the stage) -_C.EN.WIDTHS = [] - -# Expansion ratios for MBConv blocks in each stage -_C.EN.EXP_RATIOS = [] - -# Squeeze-and-Excitation (SE) ratio -_C.EN.SE_R = 0.25 - -# Strides for each stage (applies to the first block of each stage) -_C.EN.STRIDES = [] - -# Kernel sizes for each stage -_C.EN.KERNELS = [] - -# Head width -_C.EN.HEAD_W = 1280 - -# Drop connect ratio -_C.EN.DC_RATIO = 0.0 - -# Dropout ratio -_C.EN.DROPOUT_RATIO = 0.0 - - -# -------------------------------- Batch norm options -------------------------------- # -_C.BN = CfgNode() - -# BN epsilon -_C.BN.EPS = 1e-5 - -# BN momentum (BN momentum in PyTorch = 1 - BN momentum in Caffe2) -_C.BN.MOM = 0.1 - -# Precise BN stats -_C.BN.USE_PRECISE_STATS = True -_C.BN.NUM_SAMPLES_PRECISE = 8192 - -# Initialize the gamma of the final BN of each block to zero -_C.BN.ZERO_INIT_FINAL_GAMMA = False - -# Use a different weight decay for BN layers -_C.BN.USE_CUSTOM_WEIGHT_DECAY = False -_C.BN.CUSTOM_WEIGHT_DECAY = 0.0 - - -# -------------------------------- Optimizer options --------------------------------- # -_C.OPTIM = CfgNode() - -# Learning rate ranges from BASE_LR to MIN_LR*BASE_LR according to the LR_POLICY -_C.OPTIM.BASE_LR = 0.1 -_C.OPTIM.MIN_LR = 0.0 - -# Learning rate policy select from {'cos', 'exp', 'lin', 'steps'} -_C.OPTIM.LR_POLICY = "cos" - -# Steps for 'steps' policy (in epochs) -_C.OPTIM.STEPS = [] - -# Learning rate multiplier for 'steps' policy -_C.OPTIM.LR_MULT = 0.1 - -# Maximal number of epochs -_C.OPTIM.MAX_EPOCH = 200 - -# Momentum -_C.OPTIM.MOMENTUM = 0.9 - -# Momentum dampening -_C.OPTIM.DAMPENING = 0.0 - -# Nesterov momentum -_C.OPTIM.NESTEROV = True - -# L2 regularization -_C.OPTIM.WEIGHT_DECAY = 5e-4 - -# Start the warm up from OPTIM.BASE_LR * OPTIM.WARMUP_FACTOR -_C.OPTIM.WARMUP_FACTOR = 0.1 - -# Gradually warm up the OPTIM.BASE_LR over this number of epochs -_C.OPTIM.WARMUP_EPOCHS = 0 - - -# --------------------------------- Training options --------------------------------- # -_C.TRAIN = CfgNode() - -# Dataset and split -_C.TRAIN.DATASET = "" -_C.TRAIN.SPLIT = "train" - -# Total mini-batch size -_C.TRAIN.BATCH_SIZE = 128 - -# Image size -_C.TRAIN.IM_SIZE = 224 - -# Resume training from the latest checkpoint in the output directory -_C.TRAIN.AUTO_RESUME = True - -# Weights to start training from -_C.TRAIN.WEIGHTS = "" -_C.TRAIN.PRETRAINED = "" - -# If True train using mixed precision -_C.TRAIN.MIXED_PRECISION = False - -# Label smoothing value in 0 to 1 where (0 gives no smoothing) -_C.TRAIN.LABEL_SMOOTHING = 0.0 - -# Batch mixup regularization value in 0 to 1 (0 gives no mixup) -_C.TRAIN.MIXUP_ALPHA = 0.0 - -# Standard deviation for AlexNet-style PCA jitter (0 gives no PCA jitter) -_C.TRAIN.PCA_STD = 0.1 - -# Data augmentation to use ("", "AutoAugment", "RandAugment_N2_M0.5", etc.) -_C.TRAIN.AUGMENT = "" - - -# --------------------------------- Testing options ---------------------------------- # -_C.TEST = CfgNode() - -# Dataset and split -_C.TEST.DATASET = "" -_C.TEST.SPLIT = "val" - -# Total mini-batch size -_C.TEST.BATCH_SIZE = 200 - -# Image size -_C.TEST.IM_SIZE = 256 - -# Weights to use for testing -_C.TEST.WEIGHTS = "" - - -# ------------------------------- Data loader options -------------------------------- # -_C.DATA_LOADER = CfgNode() - -# Number of data loader workers per process -_C.DATA_LOADER.NUM_WORKERS = 8 - -# Load data to pinned host memory -_C.DATA_LOADER.PIN_MEMORY = True - - -# ---------------------------------- CUDNN options ----------------------------------- # -_C.CUDNN = CfgNode() - -# Perform benchmarking to select fastest CUDNN algorithms (best for fixed input sizes) -_C.CUDNN.BENCHMARK = True - - -# ------------------------------- Precise time options ------------------------------- # -_C.PREC_TIME = CfgNode() - -# Number of iterations to warm up the caches -_C.PREC_TIME.WARMUP_ITER = 3 - -# Number of iterations to compute avg time -_C.PREC_TIME.NUM_ITER = 30 - - -# ----------------------------------- Misc options ----------------------------------- # -# Optional description of a config -_C.DESC = "" - -# If True output additional info to log -_C.VERBOSE = True - -# Number of GPUs to use (applies to both training and testing) -_C.NUM_GPUS = 1 - -# Output directory -_C.OUT_DIR = "/tmp" - -# Config destination (in OUT_DIR) -_C.CFG_DEST = "config.yaml" - -# Note that non-determinism is still be present due to non-deterministic GPU ops -_C.RNG_SEED = 1 - -# Log destination ('stdout' or 'file') -_C.LOG_DEST = "stdout" - -# Log period in iters -_C.LOG_PERIOD = 10 - -# Distributed backend -_C.DIST_BACKEND = "hccl" - -# Hostname and port range for multi-process groups (actual port selected randomly) -_C.HOST = "localhost" -_C.PORT_RANGE = [10000, 65000] - -# Models weights referred to by URL are downloaded to this local cache -_C.DOWNLOAD_CACHE = "/tmp/pycls-download-cache" - -# ---------------------------------- Default config ---------------------------------- # -_CFG_DEFAULT = _C.clone() -_CFG_DEFAULT.freeze() - - -# --------------------------------- Deprecated keys ---------------------------------- # -_C.register_deprecated_key("MEM") -_C.register_deprecated_key("MEM.RELU_INPLACE") -_C.register_deprecated_key("OPTIM.GAMMA") -_C.register_deprecated_key("PREC_TIME.BATCH_SIZE") -_C.register_deprecated_key("PREC_TIME.ENABLED") -_C.register_deprecated_key("PORT") -_C.register_deprecated_key("TRAIN.EVAL_PERIOD") -_C.register_deprecated_key("TRAIN.CHECKPOINT_PERIOD") - -# --------------------------------- Model Arts ---------------------------------- # -_C.data_url = "" -_C.train_url = "" - -def assert_and_infer_cfg(cache_urls=True): - """Checks config values invariants.""" - err_str = "The first lr step must start at 0" - assert not _C.OPTIM.STEPS or _C.OPTIM.STEPS[0] == 0, err_str - data_splits = ["train", "val", "test"] - err_str = "Data split '{}' not supported" - assert _C.TRAIN.SPLIT in data_splits, err_str.format(_C.TRAIN.SPLIT) - assert _C.TEST.SPLIT in data_splits, err_str.format(_C.TEST.SPLIT) - err_str = "Mini-batch size should be a multiple of NUM_GPUS." - assert _C.TRAIN.BATCH_SIZE % _C.NUM_GPUS == 0, err_str - assert _C.TEST.BATCH_SIZE % _C.NUM_GPUS == 0, err_str - err_str = "Log destination '{}' not supported" - assert _C.LOG_DEST in ["stdout", "file"], err_str.format(_C.LOG_DEST) - if cache_urls: - cache_cfg_urls() - - -def cache_cfg_urls(): - """Download URLs in config, cache them, and rewrite cfg to use cached file.""" - _C.TRAIN.WEIGHTS = cache_url(_C.TRAIN.WEIGHTS, _C.DOWNLOAD_CACHE) - _C.TEST.WEIGHTS = cache_url(_C.TEST.WEIGHTS, _C.DOWNLOAD_CACHE) - - -def merge_from_file(cfg_file): - with g_pathmgr.open(cfg_file, "r") as f: - cfg = _C.load_cfg(f) - _C.merge_from_other_cfg(cfg) - - -def dump_cfg(): - """Dumps the config to the output directory.""" - cfg_file = os.path.join(_C.OUT_DIR, _C.CFG_DEST) - with g_pathmgr.open(cfg_file, "w") as f: - _C.dump(stream=f) - - -def load_cfg(out_dir, cfg_dest="config.yaml"): - """Loads config from specified output directory.""" - cfg_file = os.path.join(out_dir, cfg_dest) - merge_from_file(cfg_file) - - -def reset_cfg(): - """Reset config to initial state.""" - cfg.merge_from_other_cfg(_CFG_DEFAULT) - - -def load_cfg_fom_args(description="Config file options."): - """Load config from command line arguments and set any specified options.""" - parser = argparse.ArgumentParser(description=description) - help_s = "Config file location" - parser.add_argument("--cfg", dest="cfg_file", help=help_s, required=True, type=str) - help_s = "See pycls/core/config.py for all options" - # modelarts modification - parser.add_argument('--train_url', - default="/cache/training", - type=str, - help="setting dir of training output") - parser.add_argument('--data_url', - metavar='DIR', - default='/cache/data_url', - help='path to dataset') - parser.add_argument('--onnx', default=True, action='store_true', - help="convert pth model to onnx") - parser.add_argument("opts", help=help_s, default=None, nargs=argparse.REMAINDER) - - if len(sys.argv) == 1: - parser.print_help() - sys.exit(1) - args = parser.parse_args() - merge_from_file(args.cfg_file) - _C.merge_from_list(args.opts) - +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +"""Configuration file (powered by YACS).""" + +import argparse,sys,os,torch +from iopath.common.file_io import g_pathmgr +from pycls.core.io import cache_url +from yacs.config import CfgNode as CfgNode + +# Global config object (example usage: from core.config import cfg) +_C = CfgNode() +cfg = _C + + +# ---------------------------------- Model options ----------------------------------- # +_C.MODEL = CfgNode() + +# Model type +_C.MODEL.TYPE = "" + +# Number of weight layers +_C.MODEL.DEPTH = 0 + +# Number of classes +_C.MODEL.NUM_CLASSES = 10 + +# Loss function (see pycls/models/loss.py for options) +_C.MODEL.LOSS_FUN = "cross_entropy" + +# Activation function (relu or silu/swish) +_C.MODEL.ACTIVATION_FUN = "relu" + +# Perform activation inplace if implemented +_C.MODEL.ACTIVATION_INPLACE = True + + +# ---------------------------------- ResNet options ---------------------------------- # +_C.RESNET = CfgNode() + +# Transformation function (see pycls/models/resnet.py for options) +_C.RESNET.TRANS_FUN = "basic_transform" + +# Number of groups to use (1 -> ResNet; > 1 -> ResNeXt) +_C.RESNET.NUM_GROUPS = 1 + +# Width of each group (64 -> ResNet; 4 -> ResNeXt) +_C.RESNET.WIDTH_PER_GROUP = 64 + +# Apply stride to 1x1 conv (True -> MSRA; False -> fb.torch) +_C.RESNET.STRIDE_1X1 = True + + +# ---------------------------------- AnyNet options ---------------------------------- # +_C.ANYNET = CfgNode() + +# Stem type +_C.ANYNET.STEM_TYPE = "simple_stem_in" + +# Stem width +_C.ANYNET.STEM_W = 32 + +# Block type +_C.ANYNET.BLOCK_TYPE = "res_bottleneck_block" + +# Depth for each stage (number of blocks in the stage) +_C.ANYNET.DEPTHS = [] + +# Width for each stage (width of each block in the stage) +_C.ANYNET.WIDTHS = [] + +# Strides for each stage (applies to the first block of each stage) +_C.ANYNET.STRIDES = [] + +# Bottleneck multipliers for each stage (applies to bottleneck block) +_C.ANYNET.BOT_MULS = [] + +# Group widths for each stage (applies to bottleneck block) +_C.ANYNET.GROUP_WS = [] + +# Whether SE is enabled for res_bottleneck_block +_C.ANYNET.SE_ON = False + +# SE ratio +_C.ANYNET.SE_R = 0.25 + + +# ---------------------------------- RegNet options ---------------------------------- # +_C.REGNET = CfgNode() + +# Stem type +_C.REGNET.STEM_TYPE = "simple_stem_in" + +# Stem width +_C.REGNET.STEM_W = 32 + +# Block type +_C.REGNET.BLOCK_TYPE = "res_bottleneck_block" + +# Stride of each stage +_C.REGNET.STRIDE = 2 + +# Squeeze-and-Excitation (RegNetY) +_C.REGNET.SE_ON = False +_C.REGNET.SE_R = 0.25 + +# Depth +_C.REGNET.DEPTH = 10 + +# Initial width +_C.REGNET.W0 = 32 + +# Slope +_C.REGNET.WA = 5.0 + +# Quantization +_C.REGNET.WM = 2.5 + +# Group width +_C.REGNET.GROUP_W = 16 + +# Bottleneck multiplier (bm = 1 / b from the paper) +_C.REGNET.BOT_MUL = 1.0 + + +# ------------------------------- EfficientNet options ------------------------------- # +_C.EN = CfgNode() + +# Stem width +_C.EN.STEM_W = 32 + +# Depth for each stage (number of blocks in the stage) +_C.EN.DEPTHS = [] + +# Width for each stage (width of each block in the stage) +_C.EN.WIDTHS = [] + +# Expansion ratios for MBConv blocks in each stage +_C.EN.EXP_RATIOS = [] + +# Squeeze-and-Excitation (SE) ratio +_C.EN.SE_R = 0.25 + +# Strides for each stage (applies to the first block of each stage) +_C.EN.STRIDES = [] + +# Kernel sizes for each stage +_C.EN.KERNELS = [] + +# Head width +_C.EN.HEAD_W = 1280 + +# Drop connect ratio +_C.EN.DC_RATIO = 0.0 + +# Dropout ratio +_C.EN.DROPOUT_RATIO = 0.0 + + +# -------------------------------- Batch norm options -------------------------------- # +_C.BN = CfgNode() + +# BN epsilon +_C.BN.EPS = 1e-5 + +# BN momentum (BN momentum in PyTorch = 1 - BN momentum in Caffe2) +_C.BN.MOM = 0.1 + +# Precise BN stats +_C.BN.USE_PRECISE_STATS = True +_C.BN.NUM_SAMPLES_PRECISE = 8192 + +# Initialize the gamma of the final BN of each block to zero +_C.BN.ZERO_INIT_FINAL_GAMMA = False + +# Use a different weight decay for BN layers +_C.BN.USE_CUSTOM_WEIGHT_DECAY = False +_C.BN.CUSTOM_WEIGHT_DECAY = 0.0 + + +# -------------------------------- Optimizer options --------------------------------- # +_C.OPTIM = CfgNode() + +# Learning rate ranges from BASE_LR to MIN_LR*BASE_LR according to the LR_POLICY +_C.OPTIM.BASE_LR = 0.1 +_C.OPTIM.MIN_LR = 0.0 + +# Learning rate policy select from {'cos', 'exp', 'lin', 'steps'} +_C.OPTIM.LR_POLICY = "cos" + +# Steps for 'steps' policy (in epochs) +_C.OPTIM.STEPS = [] + +# Learning rate multiplier for 'steps' policy +_C.OPTIM.LR_MULT = 0.1 + +# Maximal number of epochs +_C.OPTIM.MAX_EPOCH = 200 + +# Momentum +_C.OPTIM.MOMENTUM = 0.9 + +# Momentum dampening +_C.OPTIM.DAMPENING = 0.0 + +# Nesterov momentum +_C.OPTIM.NESTEROV = True + +# L2 regularization +_C.OPTIM.WEIGHT_DECAY = 5e-4 + +# Start the warm up from OPTIM.BASE_LR * OPTIM.WARMUP_FACTOR +_C.OPTIM.WARMUP_FACTOR = 0.1 + +# Gradually warm up the OPTIM.BASE_LR over this number of epochs +_C.OPTIM.WARMUP_EPOCHS = 0 + + +# --------------------------------- Training options --------------------------------- # +_C.TRAIN = CfgNode() + +# Dataset and split +_C.TRAIN.DATASET = "" +_C.TRAIN.SPLIT = "train" + +# Total mini-batch size +_C.TRAIN.BATCH_SIZE = 128 + +# Image size +_C.TRAIN.IM_SIZE = 224 + +# Resume training from the latest checkpoint in the output directory +_C.TRAIN.AUTO_RESUME = True + +# Weights to start training from +_C.TRAIN.WEIGHTS = "" +_C.TRAIN.PRETRAINED = "" + +# If True train using mixed precision +_C.TRAIN.MIXED_PRECISION = False + +# Label smoothing value in 0 to 1 where (0 gives no smoothing) +_C.TRAIN.LABEL_SMOOTHING = 0.0 + +# Batch mixup regularization value in 0 to 1 (0 gives no mixup) +_C.TRAIN.MIXUP_ALPHA = 0.0 + +# Standard deviation for AlexNet-style PCA jitter (0 gives no PCA jitter) +_C.TRAIN.PCA_STD = 0.1 + +# Data augmentation to use ("", "AutoAugment", "RandAugment_N2_M0.5", etc.) +_C.TRAIN.AUGMENT = "" + + +# --------------------------------- Testing options ---------------------------------- # +_C.TEST = CfgNode() + +# Dataset and split +_C.TEST.DATASET = "" +_C.TEST.SPLIT = "val" + +# Total mini-batch size +_C.TEST.BATCH_SIZE = 200 + +# Image size +_C.TEST.IM_SIZE = 256 + +# Weights to use for testing +_C.TEST.WEIGHTS = "" + + +# ------------------------------- Data loader options -------------------------------- # +_C.DATA_LOADER = CfgNode() + +# Number of data loader workers per process +_C.DATA_LOADER.NUM_WORKERS = 8 + +# Load data to pinned host memory +_C.DATA_LOADER.PIN_MEMORY = True + + +# ---------------------------------- CUDNN options ----------------------------------- # +_C.CUDNN = CfgNode() + +# Perform benchmarking to select fastest CUDNN algorithms (best for fixed input sizes) +_C.CUDNN.BENCHMARK = True + + +# ------------------------------- Precise time options ------------------------------- # +_C.PREC_TIME = CfgNode() + +# Number of iterations to warm up the caches +_C.PREC_TIME.WARMUP_ITER = 3 + +# Number of iterations to compute avg time +_C.PREC_TIME.NUM_ITER = 30 + + +# ----------------------------------- Misc options ----------------------------------- # +# Optional description of a config +_C.DESC = "" + +# If True output additional info to log +_C.VERBOSE = True + +# Number of GPUs to use (applies to both training and testing) +_C.NUM_GPUS = 1 + +# Output directory +_C.OUT_DIR = "/tmp" + +# Config destination (in OUT_DIR) +_C.CFG_DEST = "config.yaml" + +# Note that non-determinism is still be present due to non-deterministic GPU ops +_C.RNG_SEED = 1 + +# Log destination ('stdout' or 'file') +_C.LOG_DEST = "stdout" + +# Log period in iters +_C.LOG_PERIOD = 10 + +# Distributed backend +_C.DIST_BACKEND = "hccl" + +# Hostname and port range for multi-process groups (actual port selected randomly) +_C.HOST = "localhost" +_C.PORT_RANGE = [10000, 65000] + +# Models weights referred to by URL are downloaded to this local cache +_C.DOWNLOAD_CACHE = "/tmp/pycls-download-cache" + +# ---------------------------------- Default config ---------------------------------- # +_CFG_DEFAULT = _C.clone() +_CFG_DEFAULT.freeze() + + +# --------------------------------- Deprecated keys ---------------------------------- # +_C.register_deprecated_key("MEM") +_C.register_deprecated_key("MEM.RELU_INPLACE") +_C.register_deprecated_key("OPTIM.GAMMA") +_C.register_deprecated_key("PREC_TIME.BATCH_SIZE") +_C.register_deprecated_key("PREC_TIME.ENABLED") +_C.register_deprecated_key("PORT") +_C.register_deprecated_key("TRAIN.EVAL_PERIOD") +_C.register_deprecated_key("TRAIN.CHECKPOINT_PERIOD") + +# --------------------------------- Model Arts ---------------------------------- # +_C.data_url = "" +_C.train_url = "" + +def assert_and_infer_cfg(cache_urls=True): + """Checks config values invariants.""" + err_str = "The first lr step must start at 0" + assert not _C.OPTIM.STEPS or _C.OPTIM.STEPS[0] == 0, err_str + data_splits = ["train", "val", "test"] + err_str = "Data split '{}' not supported" + assert _C.TRAIN.SPLIT in data_splits, err_str.format(_C.TRAIN.SPLIT) + assert _C.TEST.SPLIT in data_splits, err_str.format(_C.TEST.SPLIT) + err_str = "Mini-batch size should be a multiple of NUM_GPUS." + assert _C.TRAIN.BATCH_SIZE % _C.NUM_GPUS == 0, err_str + assert _C.TEST.BATCH_SIZE % _C.NUM_GPUS == 0, err_str + err_str = "Log destination '{}' not supported" + assert _C.LOG_DEST in ["stdout", "file"], err_str.format(_C.LOG_DEST) + if cache_urls: + cache_cfg_urls() + + +def cache_cfg_urls(): + """Download URLs in config, cache them, and rewrite cfg to use cached file.""" + _C.TRAIN.WEIGHTS = cache_url(_C.TRAIN.WEIGHTS, _C.DOWNLOAD_CACHE) + _C.TEST.WEIGHTS = cache_url(_C.TEST.WEIGHTS, _C.DOWNLOAD_CACHE) + + +def merge_from_file(cfg_file): + with g_pathmgr.open(cfg_file, "r") as f: + cfg = _C.load_cfg(f) + _C.merge_from_other_cfg(cfg) + + +def dump_cfg(): + """Dumps the config to the output directory.""" + cfg_file = os.path.join(_C.OUT_DIR, _C.CFG_DEST) + with g_pathmgr.open(cfg_file, "w") as f: + _C.dump(stream=f) + + +def load_cfg(out_dir, cfg_dest="config.yaml"): + """Loads config from specified output directory.""" + cfg_file = os.path.join(out_dir, cfg_dest) + merge_from_file(cfg_file) + + +def reset_cfg(): + """Reset config to initial state.""" + cfg.merge_from_other_cfg(_CFG_DEFAULT) + + +def load_cfg_fom_args(description="Config file options."): + """Load config from command line arguments and set any specified options.""" + parser = argparse.ArgumentParser(description=description) + help_s = "Config file location" + parser.add_argument("--cfg", dest="cfg_file", help=help_s, required=True, type=str) + help_s = "See pycls/core/config.py for all options" + # modelarts modification + parser.add_argument('--train_url', + default="/cache/training", + type=str, + help="setting dir of training output") + parser.add_argument('--data_url', + metavar='DIR', + default='/cache/data_url', + help='path to dataset') + parser.add_argument('--onnx', default=True, action='store_true', + help="convert pth model to onnx") + parser.add_argument("opts", help=help_s, default=None, nargs=argparse.REMAINDER) + + if len(sys.argv) == 1: + parser.print_help() + sys.exit(1) + args = parser.parse_args() + merge_from_file(args.cfg_file) + _C.merge_from_list(args.opts) + diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/loader.py b/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/loader.py index b94e82d09f81640a2e6b2df4af9408e61e9ce408..4bf77a6c88939de6ed1506c1f27212c0c812a50d 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/loader.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/loader.py @@ -1,98 +1,98 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -"""Data loader.""" - -import os - -import torch -from pycls.core.config import cfg -from pycls.datasets.cifar10 import Cifar10 -from pycls.datasets.imagenet import ImageNet -from torch.utils.data.distributed import DistributedSampler -from torch.utils.data.sampler import RandomSampler - -import argparse -import moxing as mox - -# Supported datasets -_DATASETS = {"cifar10": Cifar10, "imagenet2012": ImageNet} - -# Default data directory (/path/pycls/pycls/datasets/data) -#_DATA_DIR = os.path.join(os.path.dirname(__file__), "data") - -# Relative data paths to default data directory -_PATHS = {"cifar10": "cifar10", "imagenet2012": "imagenet2012"} - -def _construct_loader(args, dataset_name, split, batch_size, shuffle, drop_last): - """Constructs the data loader for the given dataset.""" - err_str = "Dataset '{}' not supported".format(dataset_name) - assert dataset_name in _DATASETS and dataset_name in _PATHS, err_str - # Retrieve the data path for the dataset - #data_path = os.path.join(_DATA_DIR, _PATHS[dataset_name]) - # modelarts modification - real_path = '/cache/data_url' - if not os.path.exists(real_path): - os.makedirs(real_path) - print(args) - mox.file.copy_parallel(args.data_url, real_path) - print("training data finish copy to %s." % real_path) - data_path = os.path.join(real_path, _PATHS[dataset_name]) - print("real_path:",real_path) - print("real_path 子文件:", os.listdir(real_path)) - print("data_path:",data_path) - print("data_path 子文件:", os.listdir(data_path)) - # modelarts modification - # Construct the dataset - dataset = _DATASETS[dataset_name](data_path, split) - # Create a sampler for multi-process training - sampler = DistributedSampler(dataset) if cfg.NUM_GPUS > 1 else None - # Create a loader - loader = torch.utils.data.DataLoader( - dataset, - batch_size=batch_size, - shuffle=(False if sampler else shuffle), - sampler=sampler, - num_workers=cfg.DATA_LOADER.NUM_WORKERS, - pin_memory=cfg.DATA_LOADER.PIN_MEMORY, - drop_last=drop_last, - ) - return loader - - -def construct_train_loader(args): - """Train loader wrapper.""" - return _construct_loader( - args, - dataset_name=cfg.TRAIN.DATASET, - split=cfg.TRAIN.SPLIT, - batch_size=int(cfg.TRAIN.BATCH_SIZE / cfg.NUM_GPUS), - shuffle=True, - drop_last=True, - ) - - -def construct_test_loader(args): - """Test loader wrapper.""" - return _construct_loader( - args, - dataset_name=cfg.TEST.DATASET, - split=cfg.TEST.SPLIT, - batch_size=int(cfg.TEST.BATCH_SIZE / cfg.NUM_GPUS), - shuffle=False, - drop_last=False, - ) - - -def shuffle(loader, cur_epoch): - """"Shuffles the data.""" - err_str = "Sampler type '{}' not supported".format(type(loader.sampler)) - assert isinstance(loader.sampler, (RandomSampler, DistributedSampler)), err_str - # RandomSampler handles shuffling automatically - if isinstance(loader.sampler, DistributedSampler): - # DistributedSampler shuffles data based on epoch - loader.sampler.set_epoch(cur_epoch) +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +"""Data loader.""" + +import os + +import torch +from pycls.core.config import cfg +from pycls.datasets.cifar10 import Cifar10 +from pycls.datasets.imagenet import ImageNet +from torch.utils.data.distributed import DistributedSampler +from torch.utils.data.sampler import RandomSampler + +import argparse +import moxing as mox + +# Supported datasets +_DATASETS = {"cifar10": Cifar10, "imagenet2012": ImageNet} + +# Default data directory (/path/pycls/pycls/datasets/data) +#_DATA_DIR = os.path.join(os.path.dirname(__file__), "data") + +# Relative data paths to default data directory +_PATHS = {"cifar10": "cifar10", "imagenet2012": "imagenet2012"} + +def _construct_loader(args, dataset_name, split, batch_size, shuffle, drop_last): + """Constructs the data loader for the given dataset.""" + err_str = "Dataset '{}' not supported".format(dataset_name) + assert dataset_name in _DATASETS and dataset_name in _PATHS, err_str + # Retrieve the data path for the dataset + #data_path = os.path.join(_DATA_DIR, _PATHS[dataset_name]) + # modelarts modification + real_path = '/cache/data_url' + if not os.path.exists(real_path): + os.makedirs(real_path) + print(args) + mox.file.copy_parallel(args.data_url, real_path) + print("training data finish copy to %s." % real_path) + data_path = os.path.join(real_path, _PATHS[dataset_name]) + print("real_path:",real_path) + print("real_path 子文件:", os.listdir(real_path)) + print("data_path:",data_path) + print("data_path 子文件:", os.listdir(data_path)) + # modelarts modification + # Construct the dataset + dataset = _DATASETS[dataset_name](data_path, split) + # Create a sampler for multi-process training + sampler = DistributedSampler(dataset) if cfg.NUM_GPUS > 1 else None + # Create a loader + loader = torch.utils.data.DataLoader( + dataset, + batch_size=batch_size, + shuffle=(False if sampler else shuffle), + sampler=sampler, + num_workers=cfg.DATA_LOADER.NUM_WORKERS, + pin_memory=cfg.DATA_LOADER.PIN_MEMORY, + drop_last=drop_last, + ) + return loader + + +def construct_train_loader(args): + """Train loader wrapper.""" + return _construct_loader( + args, + dataset_name=cfg.TRAIN.DATASET, + split=cfg.TRAIN.SPLIT, + batch_size=int(cfg.TRAIN.BATCH_SIZE / cfg.NUM_GPUS), + shuffle=True, + drop_last=True, + ) + + +def construct_test_loader(args): + """Test loader wrapper.""" + return _construct_loader( + args, + dataset_name=cfg.TEST.DATASET, + split=cfg.TEST.SPLIT, + batch_size=int(cfg.TEST.BATCH_SIZE / cfg.NUM_GPUS), + shuffle=False, + drop_last=False, + ) + + +def shuffle(loader, cur_epoch): + """"Shuffles the data.""" + err_str = "Sampler type '{}' not supported".format(type(loader.sampler)) + assert isinstance(loader.sampler, (RandomSampler, DistributedSampler)), err_str + # RandomSampler handles shuffling automatically + if isinstance(loader.sampler, DistributedSampler): + # DistributedSampler shuffles data based on epoch + loader.sampler.set_epoch(cur_epoch) diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/train_net.py b/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/train_net.py index 862b2d3ba8ad16af6b15fea4699d29bbc0021312..14485f09e82a96b44d47647547eeee65cc5d87da 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/train_net.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/train_net.py @@ -1,106 +1,106 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Train a classification model.""" -import argparse,sys,os,torch -sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../')) - -import pycls.core.config as config -import pycls.core.distributed as dist -import pycls.core.trainer as trainer -import pycls.datasets.loader as data_loader - -from pycls.core.config import cfg - -def init_process_group(proc_rank, world_size, device_id, port='29588'): - """Initializes the default process group.""" - - # Initialize the process group - print('Initialize the process group') - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = '29588' - torch.distributed.init_process_group( - backend=cfg.DIST_BACKEND, - #init_method="tcp://{}:{}".format(cfg.HOST, port), - world_size=world_size, - rank=proc_rank, - #rank=0 - ) - print("init_process_group done") - - # Set the GPU to use - #torch.cuda.set_device(proc_rank) - torch.npu.set_device(device_id) - print('set_device done.', cfg.DIST_BACKEND, world_size, proc_rank) - -def main(): - config.load_cfg_fom_args("Train a classification model.") - config.assert_and_infer_cfg() - cfg.freeze() - - dist.multi_proc_run(num_proc=cfg.NUM_GPUS, fun=trainer.train_model) - - -if __name__ == "__main__": - """Load config from command line arguments and set any specified options.""" - parser = argparse.ArgumentParser(description="Config file options.") - help_s = "Config file location" - parser.add_argument("--cfg", dest="cfg_file", help=help_s, required=True, type=str) - parser.add_argument("--rank_id", dest="rank_id", default=0, type=int) - parser.add_argument("--device_id", dest="device_id", default=0, type=int) - help_s = "See pycls/core/config.py for all options" - parser.add_argument("opts", help=help_s, default=None, nargs=argparse.REMAINDER) - print("===============1================") - # modelarts modification - parser.add_argument('--data_url', - metavar='DIR', - default='/cache/data_url', - help='path to dataset') - parser.add_argument('--train_url', - default="/cache/training", - type=str, - help="setting dir of training output") - parser.add_argument('--onnx', default=True, action='store_true', - help="convert pth model to onnx") - parser.add_argument('--npu', - default=None, - type=int, - help='NPU id to use.') - print("===============2================") - if len(sys.argv) == 1: - parser.print_help() - sys.exit(1) - args = parser.parse_args() - print(args) - print("args.data_url:",args.data_url) - print('cur dir:', os.listdir('./')) - config.merge_from_file(args.cfg_file) - config._C.merge_from_list(args.opts) - config.assert_and_infer_cfg() - cfg.freeze() - - init_process_group(proc_rank=args.rank_id, world_size=cfg.NUM_GPUS, device_id=args.device_id) - cur_device = torch.npu.current_device() - print('cur_device: ', cur_device) - - trainer.train_model(args) - trainer.convert_pth_to_onnx(args) - +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Train a classification model.""" +import argparse,sys,os,torch +sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../')) + +import pycls.core.config as config +import pycls.core.distributed as dist +import pycls.core.trainer as trainer +import pycls.datasets.loader as data_loader + +from pycls.core.config import cfg + +def init_process_group(proc_rank, world_size, device_id, port='29588'): + """Initializes the default process group.""" + + # Initialize the process group + print('Initialize the process group') + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '29588' + torch.distributed.init_process_group( + backend=cfg.DIST_BACKEND, + #init_method="tcp://{}:{}".format(cfg.HOST, port), + world_size=world_size, + rank=proc_rank, + #rank=0 + ) + print("init_process_group done") + + # Set the GPU to use + #torch.cuda.set_device(proc_rank) + torch.npu.set_device(device_id) + print('set_device done.', cfg.DIST_BACKEND, world_size, proc_rank) + +def main(): + config.load_cfg_fom_args("Train a classification model.") + config.assert_and_infer_cfg() + cfg.freeze() + + dist.multi_proc_run(num_proc=cfg.NUM_GPUS, fun=trainer.train_model) + + +if __name__ == "__main__": + """Load config from command line arguments and set any specified options.""" + parser = argparse.ArgumentParser(description="Config file options.") + help_s = "Config file location" + parser.add_argument("--cfg", dest="cfg_file", help=help_s, required=True, type=str) + parser.add_argument("--rank_id", dest="rank_id", default=0, type=int) + parser.add_argument("--device_id", dest="device_id", default=0, type=int) + help_s = "See pycls/core/config.py for all options" + parser.add_argument("opts", help=help_s, default=None, nargs=argparse.REMAINDER) + print("===============1================") + # modelarts modification + parser.add_argument('--data_url', + metavar='DIR', + default='/cache/data_url', + help='path to dataset') + parser.add_argument('--train_url', + default="/cache/training", + type=str, + help="setting dir of training output") + parser.add_argument('--onnx', default=True, action='store_true', + help="convert pth model to onnx") + parser.add_argument('--npu', + default=None, + type=int, + help='NPU id to use.') + print("===============2================") + if len(sys.argv) == 1: + parser.print_help() + sys.exit(1) + args = parser.parse_args() + print(args) + print("args.data_url:",args.data_url) + print('cur dir:', os.listdir('./')) + config.merge_from_file(args.cfg_file) + config._C.merge_from_list(args.opts) + config.assert_and_infer_cfg() + cfg.freeze() + + init_process_group(proc_rank=args.rank_id, world_size=cfg.NUM_GPUS, device_id=args.device_id) + cur_device = torch.npu.current_device() + print('cur_device: ', cur_device) + + trainer.train_model(args) + trainer.convert_pth_to_onnx(args) + diff --git a/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/trainer.py b/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/trainer.py index 8c838dce87455d2d9362144a66a7bc80833811ff..34c479386eceab795813d3ca0ff3edbd12277256 100644 --- a/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/trainer.py +++ b/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch/modelasrts/trainer.py @@ -1,306 +1,306 @@ -#!/usr/bin/env python3 - -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Tools for training and testing a model.""" -import numpy as np -import pycls.core.benchmark as benchmark -import pycls.core.builders as builders -import pycls.core.checkpoint as cp -import pycls.core.distributed as dist -import pycls.core.env as env -import pycls.core.logging as logging -import pycls.core.meters as meters -import pycls.core.net as net -import pycls.core.optimizer as optim -import pycls.datasets.loader as data_loader -import torch -import torch.npu - -from pycls.core.net import unwrap_model -import glob -from apex import amp -from pycls.core.config import cfg -from pycls.core.cuda import ApexScaler -import os -import shutil - -import moxing as mox - -import torch.onnx -from collections import OrderedDict -from pycls.models.effnet import EffNet -from iopath.common.file_io import g_pathmgr -import pycls.core.config as config - -logger = logging.get_logger(__name__) - -cur_step = 0 -CACHE_TRAINING_URL = "/cache/training/" -CACHE_DATA_URL = "/cache/data_url" -CACHE_MODEL_URL = "/cache/model" - -def setup_model(): - - """Sets up a model for training or testing and log the results.""" - # Build the model - model = builders.build_model() - logger.info("Model:\n{}".format(model)) if cfg.VERBOSE else () - # Log model complexity - logger.info(logging.dump_log_data(net.complexity(model), "complexity")) - # Transfer the model to the current GPU device - err_str = "Cannot use more GPU devices than available" - #assert cfg.NUM_GPUS <= torch.cuda.device_count(), err_str - assert cfg.NUM_GPUS <= torch.npu.device_count(), err_str - cur_device = torch.npu.current_device() - model = model.to(cur_device) - optimizer = optim.construct_optimizer(model) - model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=128) - if cfg.NUM_GPUS > 1: - #Make model replica operate on the current device - ddp = torch.nn.parallel.DistributedDataParallel - model = ddp(model, device_ids=[cur_device], broadcast_buffers=False) - - return model,optimizer - - -def train_epoch(loader, model, loss_fun, optimizer, scaler, meter, cur_epoch): - """Performs one epoch of training.""" - # Shuffle the data - data_loader.shuffle(loader, cur_epoch) - # Update the learning rate - lr = optim.get_epoch_lr(cur_epoch) - optim.set_lr(optimizer, lr) - # Enable training mode - model.train() - meter.reset() - meter.iter_tic() - for cur_iter, (inputs, labels) in enumerate(loader): - # Transfer the data to the current GPU device - inputs = inputs.npu() - labels = labels.to(torch.int32).npu() - labels = labels.to(non_blocking=False) - # Convert labels to smoothed one-hot vector - p_labels = labels[:] - labels_one_hot = net.smooth_one_hot_labels(labels).npu() - # Apply mixup to the batch (no effect if mixup alpha is 0) - inputs, labels_one_hot, labels = net.mixup(inputs, labels_one_hot) - # Perform the forward pass and compute the loss - preds = model(inputs) - loss = loss_fun(preds, labels_one_hot) - # Perform the backward pass and update the parameters - optimizer.zero_grad() - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - optimizer.step() - # Compute the errors - top1_err, top5_err = meters.topk_errors(preds, p_labels, [1, 5]) - # Combine the errors across the GPUs (no reduction if 1 GPU used) - # Combine the stats across the GPUs (no reduction if 1 GPU used) - # loss, top1_err, top5_err = dist.scaled_all_reduce([loss, top1_err, top5_err]) - # Copy the stats from GPU to CPU (sync point) - loss, top1_err, top5_err = loss.item(), top1_err.item(), top5_err.item() - meter.iter_toc() - # Update and log stats - mb_size = inputs.size(0) * cfg.NUM_GPUS - meter.update_stats(top1_err, top5_err, loss, lr, mb_size) - meter.log_iter_stats(cur_epoch, cur_iter) - meter.iter_tic() - # Log epoch stats - meter.log_epoch_stats(cur_epoch) - -@torch.no_grad() -def test_epoch(loader, model, meter, cur_epoch): - """Evaluates the model on the test set.""" - # Enable eval mode - model.eval() - meter.reset() - meter.iter_tic() - for cur_iter, (inputs, labels) in enumerate(loader): - # Transfer the data to the current GPU device - inputs = inputs.npu() - labels = labels.to(torch.int32).npu() - labels = labels.to(non_blocking=False) - # Compute the predictions - preds = model(inputs) - # Compute the errors - top1_err, top5_err = meters.topk_errors(preds, labels, [1, 5]) - # Combine the errors across the GPUs (no reduction if 1 GPU used) - top1_err, top5_err = dist.scaled_all_reduce([top1_err, top5_err]) - # Copy the errors from GPU to CPU (sync point) - top1_err, top5_err = top1_err.item(), top5_err.item() - meter.iter_toc() - # Update and log stats - meter.update_stats(top1_err, top5_err, inputs.size(0) * cfg.NUM_GPUS) - meter.log_iter_stats(cur_epoch, cur_iter) - meter.iter_tic() - # Log epoch stats - meter.log_epoch_stats(cur_epoch) - -def train_model(args): - """Trains the model.""" - # Setup training/testing environment - env.setup_env() - # Construct the model, loss_fun, and optimizer - model,optimizer = setup_model() - loss_fun = builders.build_loss_fun().npu() - # Load checkpoint or initial weights - start_epoch = 0 - if cfg.TRAIN.PRETRAINED: - cp.pretrained_load_checkpoint(cfg.TRAIN.PRETRAINED, model) - logger.info("Loaded pretrained initial weights from: {}".format(cfg.TRAIN.PRETRAINED)) - elif cfg.TRAIN.AUTO_RESUME and cp.has_checkpoint(): - file = cp.get_last_checkpoint() - epoch = cp.load_checkpoint(file, model, optimizer) - logger.info("Loaded checkpoint from: {}".format(file)) - start_epoch = epoch + 1 - elif cfg.TRAIN.WEIGHTS: - #cp.load_checkpoint(cfg.TRAIN.WEIGHTS, model) - CACHE_MODEL_URL = "/cache/model" - os.makedirs(CACHE_MODEL_URL, exist_ok=True) - mox.file.copy_parallel(cfg.TRAIN.WEIGHTS, os.path.join(CACHE_MODEL_URL, "model.pyth")) - pretrained_weight = os.path.join(CACHE_MODEL_URL, "model.pyth") - cp.load_checkpoint(pretrained_weight, model) - logger.info("Loaded initial weights from: {}".format(cfg.TRAIN.WEIGHTS)) - # Create data loaders and meters - train_loader = data_loader.construct_train_loader(args) - test_loader = data_loader.construct_test_loader(args) - # modelarts modification - ''' - real_path = '/cache/data_url' - if not os.path.exists(real_path): - os.makedirs(real_path) - mox.file.copy_parallel(args.data_url, real_path) - print("training data finish copy to %s." % real_path) - train_loader = os.path.join(args.data, 'train') - test_loader = os.path.join(real_path, 'val') - ''' - # modelarts modification - train_meter = meters.TrainMeter(len(train_loader)) - test_meter = meters.TestMeter(len(test_loader)) - # Create a GradScaler for mixed precision training - scaler = ApexScaler() - # Compute model and loader timings - if start_epoch == 0 and cfg.PREC_TIME.NUM_ITER > 0: - benchmark.compute_time_full(model, loss_fun, train_loader, test_loader) - # Perform the training loop - logger.info("Start epoch: {}".format(start_epoch + 1)) - best_err = np.inf - - for cur_epoch in range(start_epoch, cfg.OPTIM.MAX_EPOCH): - # Train for one epoch - params = (train_loader, model, loss_fun, optimizer, scaler, train_meter) - train_epoch(*params, cur_epoch) - # Compute precise BN stats - if cfg.BN.USE_PRECISE_STATS: - net.compute_precise_bn_stats(model, train_loader) - # Evaluate the model - test_epoch(test_loader, model, test_meter, cur_epoch) - # Check if checkpoint is best so far (note: should checkpoint meters as well) - stats = test_meter.get_epoch_stats(cur_epoch) - best = stats["top1_err"] <= best_err - best_err = min(stats["top1_err"], best_err) - # Save a checkpoint - file = cp.save_checkpoint(model, optimizer, cur_epoch, best) - logger.info("Wrote checkpoint to: {}".format(file)) - - # --------------modelarts modification---------- - if args.onnx: - convert_pth_to_onnx(args) - mox.file.copy_parallel(CACHE_TRAINING_URL, args.train_url) - # --------------modelarts modification end---------- - -def test_model(): - """Evaluates a trained model.""" - # Setup training/testing environment - env.setup_env() - # Construct the model - model,optimizer = setup_model() - # Load model weights - cp.load_checkpoint(cfg.TEST.WEIGHTS, model) - logger.info("Loaded model weights from: {}".format(cfg.TEST.WEIGHTS)) - # Create data loaders and meters - test_loader = data_loader.construct_test_loader() - test_meter = meters.TestMeter(len(test_loader)) - # Evaluate the model - test_epoch(test_loader, model, test_meter, 0) - - -def time_model(): - """Times model.""" - # Setup training/testing environment - env.setup_env() - # Construct the model and loss_fun - model = setup_model() - loss_fun = builders.build_loss_fun().npu() - # Compute model and loader timings - benchmark.compute_time_model(model, loss_fun) - - -def time_model_and_loader(): - """Times model and data loader.""" - # Setup training/testing environment - env.setup_env() - # Construct the model and loss_fun - model = setup_model() - loss_fun = builders.build_loss_fun().npu() - # Create data loaders - train_loader = data_loader.construct_train_loader() - test_loader = data_loader.construct_test_loader() - # Compute model and loader timings - benchmark.compute_time_full(model, loss_fun, train_loader, test_loader) - -def convert_pth_to_onnx(args): - os.makedirs(CACHE_TRAINING_URL, exist_ok=True) - shutil.copy(os.path.join(cfg.OUT_DIR, 'model.pyth'), CACHE_TRAINING_URL) - pth_pattern = os.path.join(CACHE_TRAINING_URL, 'model.pyth') - pth_file_list = glob.glob(pth_pattern) - if not pth_file_list: - print("can't find pth {pth_pattern}") - pth_file = pth_file_list[0] - onnx_path = pth_file.split(".")[0] + '.onnx' - convert(pth_file, onnx_path) - -def proc_node_module(checkpoint, attr_name): - new_model_state = OrderedDict() - for k, v in checkpoint[attr_name].items(): - if(k[0: 7] == "module."): - name = k[7:] - else: - name = k[0:] - new_model_state[name] = v - return new_model_state - -def convert(pth_file_path, onnx_file_path): - """Sets up a model for training or testing and log the results.""" - loc = 'cpu' - with g_pathmgr.open(pth_file_path, "rb") as f: - checkpoint = torch.load(f, map_location=loc) - cfg_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../configs/dds_baselines/effnet/EN-B5_dds_1npu_full.yaml") - config.merge_from_file(cfg_file) - cfg.freeze() - model = EffNet().to(loc) - checkpoint['model_state'] = proc_node_module(checkpoint, 'model_state') - model.load_state_dict(checkpoint["model_state"], False) - model = model.to(loc) - input_names = ["actual_input_1"] - output_names = ["output1"] - dummy_input = torch.randn(1, 3, 456, 456).to(loc) +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tools for training and testing a model.""" +import numpy as np +import pycls.core.benchmark as benchmark +import pycls.core.builders as builders +import pycls.core.checkpoint as cp +import pycls.core.distributed as dist +import pycls.core.env as env +import pycls.core.logging as logging +import pycls.core.meters as meters +import pycls.core.net as net +import pycls.core.optimizer as optim +import pycls.datasets.loader as data_loader +import torch +import torch.npu + +from pycls.core.net import unwrap_model +import glob +from apex import amp +from pycls.core.config import cfg +from pycls.core.cuda import ApexScaler +import os +import shutil + +import moxing as mox + +import torch.onnx +from collections import OrderedDict +from pycls.models.effnet import EffNet +from iopath.common.file_io import g_pathmgr +import pycls.core.config as config + +logger = logging.get_logger(__name__) + +cur_step = 0 +CACHE_TRAINING_URL = "/cache/training/" +CACHE_DATA_URL = "/cache/data_url" +CACHE_MODEL_URL = "/cache/model" + +def setup_model(): + + """Sets up a model for training or testing and log the results.""" + # Build the model + model = builders.build_model() + logger.info("Model:\n{}".format(model)) if cfg.VERBOSE else () + # Log model complexity + logger.info(logging.dump_log_data(net.complexity(model), "complexity")) + # Transfer the model to the current GPU device + err_str = "Cannot use more GPU devices than available" + #assert cfg.NUM_GPUS <= torch.cuda.device_count(), err_str + assert cfg.NUM_GPUS <= torch.npu.device_count(), err_str + cur_device = torch.npu.current_device() + model = model.to(cur_device) + optimizer = optim.construct_optimizer(model) + model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=128) + if cfg.NUM_GPUS > 1: + #Make model replica operate on the current device + ddp = torch.nn.parallel.DistributedDataParallel + model = ddp(model, device_ids=[cur_device], broadcast_buffers=False) + + return model,optimizer + + +def train_epoch(loader, model, loss_fun, optimizer, scaler, meter, cur_epoch): + """Performs one epoch of training.""" + # Shuffle the data + data_loader.shuffle(loader, cur_epoch) + # Update the learning rate + lr = optim.get_epoch_lr(cur_epoch) + optim.set_lr(optimizer, lr) + # Enable training mode + model.train() + meter.reset() + meter.iter_tic() + for cur_iter, (inputs, labels) in enumerate(loader): + # Transfer the data to the current GPU device + inputs = inputs.npu() + labels = labels.to(torch.int32).npu() + labels = labels.to(non_blocking=False) + # Convert labels to smoothed one-hot vector + p_labels = labels[:] + labels_one_hot = net.smooth_one_hot_labels(labels).npu() + # Apply mixup to the batch (no effect if mixup alpha is 0) + inputs, labels_one_hot, labels = net.mixup(inputs, labels_one_hot) + # Perform the forward pass and compute the loss + preds = model(inputs) + loss = loss_fun(preds, labels_one_hot) + # Perform the backward pass and update the parameters + optimizer.zero_grad() + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + optimizer.step() + # Compute the errors + top1_err, top5_err = meters.topk_errors(preds, p_labels, [1, 5]) + # Combine the errors across the GPUs (no reduction if 1 GPU used) + # Combine the stats across the GPUs (no reduction if 1 GPU used) + # loss, top1_err, top5_err = dist.scaled_all_reduce([loss, top1_err, top5_err]) + # Copy the stats from GPU to CPU (sync point) + loss, top1_err, top5_err = loss.item(), top1_err.item(), top5_err.item() + meter.iter_toc() + # Update and log stats + mb_size = inputs.size(0) * cfg.NUM_GPUS + meter.update_stats(top1_err, top5_err, loss, lr, mb_size) + meter.log_iter_stats(cur_epoch, cur_iter) + meter.iter_tic() + # Log epoch stats + meter.log_epoch_stats(cur_epoch) + +@torch.no_grad() +def test_epoch(loader, model, meter, cur_epoch): + """Evaluates the model on the test set.""" + # Enable eval mode + model.eval() + meter.reset() + meter.iter_tic() + for cur_iter, (inputs, labels) in enumerate(loader): + # Transfer the data to the current GPU device + inputs = inputs.npu() + labels = labels.to(torch.int32).npu() + labels = labels.to(non_blocking=False) + # Compute the predictions + preds = model(inputs) + # Compute the errors + top1_err, top5_err = meters.topk_errors(preds, labels, [1, 5]) + # Combine the errors across the GPUs (no reduction if 1 GPU used) + top1_err, top5_err = dist.scaled_all_reduce([top1_err, top5_err]) + # Copy the errors from GPU to CPU (sync point) + top1_err, top5_err = top1_err.item(), top5_err.item() + meter.iter_toc() + # Update and log stats + meter.update_stats(top1_err, top5_err, inputs.size(0) * cfg.NUM_GPUS) + meter.log_iter_stats(cur_epoch, cur_iter) + meter.iter_tic() + # Log epoch stats + meter.log_epoch_stats(cur_epoch) + +def train_model(args): + """Trains the model.""" + # Setup training/testing environment + env.setup_env() + # Construct the model, loss_fun, and optimizer + model,optimizer = setup_model() + loss_fun = builders.build_loss_fun().npu() + # Load checkpoint or initial weights + start_epoch = 0 + if cfg.TRAIN.PRETRAINED: + cp.pretrained_load_checkpoint(cfg.TRAIN.PRETRAINED, model) + logger.info("Loaded pretrained initial weights from: {}".format(cfg.TRAIN.PRETRAINED)) + elif cfg.TRAIN.AUTO_RESUME and cp.has_checkpoint(): + file = cp.get_last_checkpoint() + epoch = cp.load_checkpoint(file, model, optimizer) + logger.info("Loaded checkpoint from: {}".format(file)) + start_epoch = epoch + 1 + elif cfg.TRAIN.WEIGHTS: + #cp.load_checkpoint(cfg.TRAIN.WEIGHTS, model) + CACHE_MODEL_URL = "/cache/model" + os.makedirs(CACHE_MODEL_URL, exist_ok=True) + mox.file.copy_parallel(cfg.TRAIN.WEIGHTS, os.path.join(CACHE_MODEL_URL, "model.pyth")) + pretrained_weight = os.path.join(CACHE_MODEL_URL, "model.pyth") + cp.load_checkpoint(pretrained_weight, model) + logger.info("Loaded initial weights from: {}".format(cfg.TRAIN.WEIGHTS)) + # Create data loaders and meters + train_loader = data_loader.construct_train_loader(args) + test_loader = data_loader.construct_test_loader(args) + # modelarts modification + ''' + real_path = '/cache/data_url' + if not os.path.exists(real_path): + os.makedirs(real_path) + mox.file.copy_parallel(args.data_url, real_path) + print("training data finish copy to %s." % real_path) + train_loader = os.path.join(args.data, 'train') + test_loader = os.path.join(real_path, 'val') + ''' + # modelarts modification + train_meter = meters.TrainMeter(len(train_loader)) + test_meter = meters.TestMeter(len(test_loader)) + # Create a GradScaler for mixed precision training + scaler = ApexScaler() + # Compute model and loader timings + if start_epoch == 0 and cfg.PREC_TIME.NUM_ITER > 0: + benchmark.compute_time_full(model, loss_fun, train_loader, test_loader) + # Perform the training loop + logger.info("Start epoch: {}".format(start_epoch + 1)) + best_err = np.inf + + for cur_epoch in range(start_epoch, cfg.OPTIM.MAX_EPOCH): + # Train for one epoch + params = (train_loader, model, loss_fun, optimizer, scaler, train_meter) + train_epoch(*params, cur_epoch) + # Compute precise BN stats + if cfg.BN.USE_PRECISE_STATS: + net.compute_precise_bn_stats(model, train_loader) + # Evaluate the model + test_epoch(test_loader, model, test_meter, cur_epoch) + # Check if checkpoint is best so far (note: should checkpoint meters as well) + stats = test_meter.get_epoch_stats(cur_epoch) + best = stats["top1_err"] <= best_err + best_err = min(stats["top1_err"], best_err) + # Save a checkpoint + file = cp.save_checkpoint(model, optimizer, cur_epoch, best) + logger.info("Wrote checkpoint to: {}".format(file)) + + # --------------modelarts modification---------- + if args.onnx: + convert_pth_to_onnx(args) + mox.file.copy_parallel(CACHE_TRAINING_URL, args.train_url) + # --------------modelarts modification end---------- + +def test_model(): + """Evaluates a trained model.""" + # Setup training/testing environment + env.setup_env() + # Construct the model + model,optimizer = setup_model() + # Load model weights + cp.load_checkpoint(cfg.TEST.WEIGHTS, model) + logger.info("Loaded model weights from: {}".format(cfg.TEST.WEIGHTS)) + # Create data loaders and meters + test_loader = data_loader.construct_test_loader() + test_meter = meters.TestMeter(len(test_loader)) + # Evaluate the model + test_epoch(test_loader, model, test_meter, 0) + + +def time_model(): + """Times model.""" + # Setup training/testing environment + env.setup_env() + # Construct the model and loss_fun + model = setup_model() + loss_fun = builders.build_loss_fun().npu() + # Compute model and loader timings + benchmark.compute_time_model(model, loss_fun) + + +def time_model_and_loader(): + """Times model and data loader.""" + # Setup training/testing environment + env.setup_env() + # Construct the model and loss_fun + model = setup_model() + loss_fun = builders.build_loss_fun().npu() + # Create data loaders + train_loader = data_loader.construct_train_loader() + test_loader = data_loader.construct_test_loader() + # Compute model and loader timings + benchmark.compute_time_full(model, loss_fun, train_loader, test_loader) + +def convert_pth_to_onnx(args): + os.makedirs(CACHE_TRAINING_URL, exist_ok=True) + shutil.copy(os.path.join(cfg.OUT_DIR, 'model.pyth'), CACHE_TRAINING_URL) + pth_pattern = os.path.join(CACHE_TRAINING_URL, 'model.pyth') + pth_file_list = glob.glob(pth_pattern) + if not pth_file_list: + print("can't find pth {pth_pattern}") + pth_file = pth_file_list[0] + onnx_path = pth_file.split(".")[0] + '.onnx' + convert(pth_file, onnx_path) + +def proc_node_module(checkpoint, attr_name): + new_model_state = OrderedDict() + for k, v in checkpoint[attr_name].items(): + if(k[0: 7] == "module."): + name = k[7:] + else: + name = k[0:] + new_model_state[name] = v + return new_model_state + +def convert(pth_file_path, onnx_file_path): + """Sets up a model for training or testing and log the results.""" + loc = 'cpu' + with g_pathmgr.open(pth_file_path, "rb") as f: + checkpoint = torch.load(f, map_location=loc) + cfg_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../configs/dds_baselines/effnet/EN-B5_dds_1npu_full.yaml") + config.merge_from_file(cfg_file) + cfg.freeze() + model = EffNet().to(loc) + checkpoint['model_state'] = proc_node_module(checkpoint, 'model_state') + model.load_state_dict(checkpoint["model_state"], False) + model = model.to(loc) + input_names = ["actual_input_1"] + output_names = ["output1"] + dummy_input = torch.randn(1, 3, 456, 456).to(loc) torch.onnx.export(model, dummy_input, onnx_file_path, input_names = input_names, output_names = output_names, opset_version=11) \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/GENet_for_Pytorch/LICENSE b/PyTorch/contrib/cv/classification/GENet_for_Pytorch/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/PyTorch/contrib/cv/classification/GENet_for_Pytorch/LICENSE +++ b/PyTorch/contrib/cv/classification/GENet_for_Pytorch/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/GENet_for_Pytorch/README.md b/PyTorch/contrib/cv/classification/GENet_for_Pytorch/README.md index 3a09b50b40d753d58f86cc14dc7a9ac75e2c6df5..05e2f31ba924106e50f850408b068a858967caaf 100644 --- a/PyTorch/contrib/cv/classification/GENet_for_Pytorch/README.md +++ b/PyTorch/contrib/cv/classification/GENet_for_Pytorch/README.md @@ -1,59 +1,59 @@ -# GENet - -This implements training of GENET on the cifar10 dataset, mainly modified from [pytorch/examples](https://github.com/BayesWatch/pytorch-GENet). - -## GENet Details - -The configuration process and operation method of GENet are described in detail below. - -## SoftWare Package -CANN 5.0.2 - -## Requirements - -- Install PyTorch ([pytorch.org](http://pytorch.org)) -- `pip install -r requirements.txt` -- Download the cifar10 dataset by referring the original [repository](https://github.com/BayesWatch/pytorch-GENet) - - You can also without downloading them in advance. The cifar10 interface provided by torchvision will automatically download them for you. - -## Training - -To train a model, run `train.py` with the desired model architecture and the path to the cifar10 dataset. -Note: assuming that your dataset path is:**/opt/gpu/cifar10-batches-py/**, the real_data_path should be **/opt/gpu/** - -```bash -# training 1p accuracy -bash ./test/train_full_1p.sh --data_path=real_data_path - -# training 1p performance -bash ./test/train_performance_1p.sh --data_path=real_data_path - -# training 1p with pretrained model -bash ./test/train_finetune_1p.sh --data_path=real_data_path - -# training 8p accuracy -bash ./test/train_full_8p.sh --data_path=real_data_path - -# training 8p performance -bash ./test/train_performance_8p.sh --data_path=real_data_path - -# evaluating 8p performance -bash ./test/train_eval_8p.sh --data_path=real_data_path -``` -### Remarks: -All bash instructions output log files correctly. - -### Log path: -**training detail log:** - test/output/devie_id/train_${device_id}.log -**8p training performance result log:** test/output/devie_id/GENet_bs128_8p_perf.log -**8p training accuracy result log :** test/output/devie_id/GENet_bs128_8p_acc.log - -## GENET training result - -| Acc@1 | FPS | Device Type| Device Nums | Epochs | AMP_Type | -| :------: | :------: | :------: | :------: | :------: |:------: -| 94.73 | 1894.827 | NPU | 1 | 300 | O2 | -| 95.23 | 7858.025 |NPU |8 | 300 | O2 | -| 94.76 | 1350.074 |GPU |1 | 300 | O2 | +# GENet + +This implements training of GENET on the cifar10 dataset, mainly modified from [pytorch/examples](https://github.com/BayesWatch/pytorch-GENet). + +## GENet Details + +The configuration process and operation method of GENet are described in detail below. + +## SoftWare Package +CANN 5.0.2 + +## Requirements + +- Install PyTorch ([pytorch.org](http://pytorch.org)) +- `pip install -r requirements.txt` +- Download the cifar10 dataset by referring the original [repository](https://github.com/BayesWatch/pytorch-GENet) + - You can also without downloading them in advance. The cifar10 interface provided by torchvision will automatically download them for you. + +## Training + +To train a model, run `train.py` with the desired model architecture and the path to the cifar10 dataset. +Note: assuming that your dataset path is:**/opt/gpu/cifar10-batches-py/**, the real_data_path should be **/opt/gpu/** + +```bash +# training 1p accuracy +bash ./test/train_full_1p.sh --data_path=real_data_path + +# training 1p performance +bash ./test/train_performance_1p.sh --data_path=real_data_path + +# training 1p with pretrained model +bash ./test/train_finetune_1p.sh --data_path=real_data_path + +# training 8p accuracy +bash ./test/train_full_8p.sh --data_path=real_data_path + +# training 8p performance +bash ./test/train_performance_8p.sh --data_path=real_data_path + +# evaluating 8p performance +bash ./test/train_eval_8p.sh --data_path=real_data_path +``` +### Remarks: +All bash instructions output log files correctly. + +### Log path: +**training detail log:** + test/output/devie_id/train_${device_id}.log +**8p training performance result log:** test/output/devie_id/GENet_bs128_8p_perf.log +**8p training accuracy result log :** test/output/devie_id/GENet_bs128_8p_acc.log + +## GENET training result + +| Acc@1 | FPS | Device Type| Device Nums | Epochs | AMP_Type | +| :------: | :------: | :------: | :------: | :------: |:------: +| 94.73 | 1894.827 | NPU | 1 | 300 | O2 | +| 95.23 | 7858.025 |NPU |8 | 300 | O2 | +| 94.76 | 1350.074 |GPU |1 | 300 | O2 | | 94.81 | 6536.289 |GPU |8 | 300 | O2 | \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/GENet_for_Pytorch/modelzoo_level.txt b/PyTorch/contrib/cv/classification/GENet_for_Pytorch/modelzoo_level.txt index 19bb24fce376e3e5b3c73914daa4c57db1ab7d74..24cbc51bb95d445da366254d926b471ffada7b4a 100644 --- a/PyTorch/contrib/cv/classification/GENet_for_Pytorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/GENet_for_Pytorch/modelzoo_level.txt @@ -1,6 +1,6 @@ -GPUStatus:OK -NPUMigrationStatus:OK -FuncStatus:OK -PrecisionStatus:POK -AutoTune:OK -PerfStatus:OK +GPUStatus:OK +NPUMigrationStatus:OK +FuncStatus:OK +PrecisionStatus:POK +AutoTune:OK +PerfStatus:OK diff --git a/PyTorch/contrib/cv/classification/GhostNet/LICENSE b/PyTorch/contrib/cv/classification/GhostNet/LICENSE index 4ba4fdcab3dbdb4d64ce4cccdfd990698b4d596a..a0e03103591c1158a839681f3c404ee9118b182e 100644 --- a/PyTorch/contrib/cv/classification/GhostNet/LICENSE +++ b/PyTorch/contrib/cv/classification/GhostNet/LICENSE @@ -1,29 +1,29 @@ -BSD 3-Clause License - -Copyright (c) 2017, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +BSD 3-Clause License + +Copyright (c) 2017, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/GhostNet/ghostnet/ghostnet_pytorch/ghostnet.py b/PyTorch/contrib/cv/classification/GhostNet/ghostnet/ghostnet_pytorch/ghostnet.py index eaedf42a5aaad2e9829040f0951635af1ced86ad..887f6318e6ed0135ae006e93e22fea247f22a19e 100644 --- a/PyTorch/contrib/cv/classification/GhostNet/ghostnet/ghostnet_pytorch/ghostnet.py +++ b/PyTorch/contrib/cv/classification/GhostNet/ghostnet/ghostnet_pytorch/ghostnet.py @@ -1,260 +1,260 @@ -# 2020.06.09-Changed for building GhostNet -# Huawei Technologies Co., Ltd. -""" -Creates a GhostNet Model as defined in: -GhostNet: More Features from Cheap Operations By Kai Han, Yunhe Wang, Qi Tian, Jianyuan Guo, Chunjing Xu, Chang Xu. -https://arxiv.org/abs/1911.11907 -Modified from https://github.com/d-li14/mobilenetv3.pytorch and https://github.com/rwightman/pytorch-image-models -""" -import torch -import torch.nn as nn -import torch.nn.functional as F -import math - - -__all__ = ['ghost_net'] - - -def _make_divisible(v, divisor, min_value=None): - """ - This function is taken from the original tf repo. - It ensures that all layers have a channel number that is divisible by 8 - It can be seen here: - https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py - """ - if min_value is None: - min_value = divisor - new_v = max(min_value, int(v + divisor / 2) // divisor * divisor) - # Make sure that round down does not go down by more than 10%. - if new_v < 0.9 * v: - new_v += divisor - return new_v - - -def hard_sigmoid(x, inplace: bool = False): - if inplace: - return x.add_(3.).clamp_(0., 6.).div_(6.) - else: - return F.relu6(x + 3.) / 6. - - -class SqueezeExcite(nn.Module): - def __init__(self, in_chs, se_ratio=0.25, reduced_base_chs=None, - act_layer=nn.ReLU, gate_fn=hard_sigmoid, divisor=4, **_): - super(SqueezeExcite, self).__init__() - self.gate_fn = gate_fn - reduced_chs = _make_divisible((reduced_base_chs or in_chs) * se_ratio, divisor) - self.avg_pool = nn.AdaptiveAvgPool2d(1) - self.conv_reduce = nn.Conv2d(in_chs, reduced_chs, 1, bias=True) - self.act1 = act_layer(inplace=True) - self.conv_expand = nn.Conv2d(reduced_chs, in_chs, 1, bias=True) - - def forward(self, x): - x_se = self.avg_pool(x) - x_se = self.conv_reduce(x_se) - x_se = self.act1(x_se) - x_se = self.conv_expand(x_se) - x = x * self.gate_fn(x_se) - return x - - -class ConvBnAct(nn.Module): - def __init__(self, in_chs, out_chs, kernel_size, - stride=1, act_layer=nn.ReLU): - super(ConvBnAct, self).__init__() - self.conv = nn.Conv2d(in_chs, out_chs, kernel_size, stride, kernel_size//2, bias=False) - self.bn1 = nn.BatchNorm2d(out_chs) - self.act1 = act_layer(inplace=True) - - def forward(self, x): - x = self.conv(x) - x = self.bn1(x) - x = self.act1(x) - return x - - -class GhostModule(nn.Module): - def __init__(self, inp, oup, kernel_size=1, ratio=2, dw_size=3, stride=1, relu=True): - super(GhostModule, self).__init__() - self.oup = oup - init_channels = math.ceil(oup / ratio) - new_channels = init_channels*(ratio-1) - - self.primary_conv = nn.Sequential( - nn.Conv2d(inp, init_channels, kernel_size, stride, kernel_size//2, bias=False), - nn.BatchNorm2d(init_channels), - nn.ReLU(inplace=True) if relu else nn.Sequential(), - ) - - self.cheap_operation = nn.Sequential( - nn.Conv2d(init_channels, new_channels, dw_size, 1, dw_size//2, groups=init_channels, bias=False), - nn.BatchNorm2d(new_channels), - nn.ReLU(inplace=True) if relu else nn.Sequential(), - ) - - def forward(self, x): - x1 = self.primary_conv(x) - x2 = self.cheap_operation(x1) - out = torch.cat([x1,x2], dim=1) - # For avoiding OOM, refine raw code now: return out[:,:self.oup,:,:] - return out - - -class GhostBottleneck(nn.Module): - """ Ghost bottleneck w/ optional SE""" - - def __init__(self, in_chs, mid_chs, out_chs, dw_kernel_size=3, - stride=1, act_layer=nn.ReLU, se_ratio=0.): - super(GhostBottleneck, self).__init__() - has_se = se_ratio is not None and se_ratio > 0. - self.stride = stride - - # Point-wise expansion - self.ghost1 = GhostModule(in_chs, mid_chs, relu=True) - - # Depth-wise convolution - if self.stride > 1: - self.conv_dw = nn.Conv2d(mid_chs, mid_chs, dw_kernel_size, stride=stride, - padding=(dw_kernel_size-1)//2, - groups=mid_chs, bias=False) - self.bn_dw = nn.BatchNorm2d(mid_chs) - - # Squeeze-and-excitation - if has_se: - self.se = SqueezeExcite(mid_chs, se_ratio=se_ratio) - else: - self.se = None - - # Point-wise linear projection - self.ghost2 = GhostModule(mid_chs, out_chs, relu=False) - - # shortcut - if (in_chs == out_chs and self.stride == 1): - self.shortcut = nn.Sequential() - else: - self.shortcut = nn.Sequential( - nn.Conv2d(in_chs, in_chs, dw_kernel_size, stride=stride, - padding=(dw_kernel_size-1)//2, groups=in_chs, bias=False), - nn.BatchNorm2d(in_chs), - nn.Conv2d(in_chs, out_chs, 1, stride=1, padding=0, bias=False), - nn.BatchNorm2d(out_chs), - ) - - - def forward(self, x): - residual = x - - # 1st ghost bottleneck - x = self.ghost1(x) - - # Depth-wise convolution - if self.stride > 1: - x = self.conv_dw(x) - x = self.bn_dw(x) - - # Squeeze-and-excitation - if self.se is not None: - x = self.se(x) - - # 2nd ghost bottleneck - x = self.ghost2(x) - - x += self.shortcut(residual) - return x - - -class GhostNet(nn.Module): - def __init__(self, cfgs, num_classes=1000, width=1.0, dropout=0.2): - super(GhostNet, self).__init__() - # setting of inverted residual blocks - self.cfgs = cfgs - self.dropout = dropout - - # building first layer - output_channel = _make_divisible(16 * width, 4) - self.conv_stem = nn.Conv2d(3, output_channel, 3, 2, 1, bias=False) - self.bn1 = nn.BatchNorm2d(output_channel) - self.act1 = nn.ReLU(inplace=True) - input_channel = output_channel - - # building inverted residual blocks - stages = [] - block = GhostBottleneck - for cfg in self.cfgs: - layers = [] - for k, exp_size, c, se_ratio, s in cfg: - output_channel = _make_divisible(c * width, 4) - hidden_channel = _make_divisible(exp_size * width, 4) - layers.append(block(input_channel, hidden_channel, output_channel, k, s, - se_ratio=se_ratio)) - input_channel = output_channel - stages.append(nn.Sequential(*layers)) - - output_channel = _make_divisible(exp_size * width, 4) - stages.append(nn.Sequential(ConvBnAct(input_channel, output_channel, 1))) - input_channel = output_channel - - self.blocks = nn.Sequential(*stages) - - # building last several layers - output_channel = 1280 - self.global_pool = nn.AdaptiveAvgPool2d((1, 1)) - self.conv_head = nn.Conv2d(input_channel, output_channel, 1, 1, 0, bias=True) - self.act2 = nn.ReLU(inplace=True) - self.classifier = nn.Linear(output_channel, num_classes) - - def forward(self, x): - x = self.conv_stem(x) - x = self.bn1(x) - x = self.act1(x) - x = self.blocks(x) - x = self.global_pool(x) - x = self.conv_head(x) - x = self.act2(x) - x = x.view(x.size(0), -1) - if self.dropout > 0.: - x = F.dropout(x, p=self.dropout, training=self.training) - x = self.classifier(x) - return x - - -def ghostnet(**kwargs): - """ - Constructs a GhostNet model - """ - cfgs = [ - # k, t, c, SE, s - # stage1 - [[3, 16, 16, 0, 1]], - # stage2 - [[3, 48, 24, 0, 2]], - [[3, 72, 24, 0, 1]], - # stage3 - [[5, 72, 40, 0.25, 2]], - [[5, 120, 40, 0.25, 1]], - # stage4 - [[3, 240, 80, 0, 2]], - [[3, 200, 80, 0, 1], - [3, 184, 80, 0, 1], - [3, 184, 80, 0, 1], - [3, 480, 112, 0.25, 1], - [3, 672, 112, 0.25, 1] - ], - # stage5 - [[5, 672, 160, 0.25, 2]], - [[5, 960, 160, 0, 1], - [5, 960, 160, 0.25, 1], - [5, 960, 160, 0, 1], - [5, 960, 160, 0.25, 1] - ] - ] - return GhostNet(cfgs, **kwargs) - - -if __name__=='__main__': - model = ghostnet() - model.eval() - print(model) - input = torch.randn(32,3,320,256) - y = model(input) +# 2020.06.09-Changed for building GhostNet +# Huawei Technologies Co., Ltd. +""" +Creates a GhostNet Model as defined in: +GhostNet: More Features from Cheap Operations By Kai Han, Yunhe Wang, Qi Tian, Jianyuan Guo, Chunjing Xu, Chang Xu. +https://arxiv.org/abs/1911.11907 +Modified from https://github.com/d-li14/mobilenetv3.pytorch and https://github.com/rwightman/pytorch-image-models +""" +import torch +import torch.nn as nn +import torch.nn.functional as F +import math + + +__all__ = ['ghost_net'] + + +def _make_divisible(v, divisor, min_value=None): + """ + This function is taken from the original tf repo. + It ensures that all layers have a channel number that is divisible by 8 + It can be seen here: + https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py + """ + if min_value is None: + min_value = divisor + new_v = max(min_value, int(v + divisor / 2) // divisor * divisor) + # Make sure that round down does not go down by more than 10%. + if new_v < 0.9 * v: + new_v += divisor + return new_v + + +def hard_sigmoid(x, inplace: bool = False): + if inplace: + return x.add_(3.).clamp_(0., 6.).div_(6.) + else: + return F.relu6(x + 3.) / 6. + + +class SqueezeExcite(nn.Module): + def __init__(self, in_chs, se_ratio=0.25, reduced_base_chs=None, + act_layer=nn.ReLU, gate_fn=hard_sigmoid, divisor=4, **_): + super(SqueezeExcite, self).__init__() + self.gate_fn = gate_fn + reduced_chs = _make_divisible((reduced_base_chs or in_chs) * se_ratio, divisor) + self.avg_pool = nn.AdaptiveAvgPool2d(1) + self.conv_reduce = nn.Conv2d(in_chs, reduced_chs, 1, bias=True) + self.act1 = act_layer(inplace=True) + self.conv_expand = nn.Conv2d(reduced_chs, in_chs, 1, bias=True) + + def forward(self, x): + x_se = self.avg_pool(x) + x_se = self.conv_reduce(x_se) + x_se = self.act1(x_se) + x_se = self.conv_expand(x_se) + x = x * self.gate_fn(x_se) + return x + + +class ConvBnAct(nn.Module): + def __init__(self, in_chs, out_chs, kernel_size, + stride=1, act_layer=nn.ReLU): + super(ConvBnAct, self).__init__() + self.conv = nn.Conv2d(in_chs, out_chs, kernel_size, stride, kernel_size//2, bias=False) + self.bn1 = nn.BatchNorm2d(out_chs) + self.act1 = act_layer(inplace=True) + + def forward(self, x): + x = self.conv(x) + x = self.bn1(x) + x = self.act1(x) + return x + + +class GhostModule(nn.Module): + def __init__(self, inp, oup, kernel_size=1, ratio=2, dw_size=3, stride=1, relu=True): + super(GhostModule, self).__init__() + self.oup = oup + init_channels = math.ceil(oup / ratio) + new_channels = init_channels*(ratio-1) + + self.primary_conv = nn.Sequential( + nn.Conv2d(inp, init_channels, kernel_size, stride, kernel_size//2, bias=False), + nn.BatchNorm2d(init_channels), + nn.ReLU(inplace=True) if relu else nn.Sequential(), + ) + + self.cheap_operation = nn.Sequential( + nn.Conv2d(init_channels, new_channels, dw_size, 1, dw_size//2, groups=init_channels, bias=False), + nn.BatchNorm2d(new_channels), + nn.ReLU(inplace=True) if relu else nn.Sequential(), + ) + + def forward(self, x): + x1 = self.primary_conv(x) + x2 = self.cheap_operation(x1) + out = torch.cat([x1,x2], dim=1) + # For avoiding OOM, refine raw code now: return out[:,:self.oup,:,:] + return out + + +class GhostBottleneck(nn.Module): + """ Ghost bottleneck w/ optional SE""" + + def __init__(self, in_chs, mid_chs, out_chs, dw_kernel_size=3, + stride=1, act_layer=nn.ReLU, se_ratio=0.): + super(GhostBottleneck, self).__init__() + has_se = se_ratio is not None and se_ratio > 0. + self.stride = stride + + # Point-wise expansion + self.ghost1 = GhostModule(in_chs, mid_chs, relu=True) + + # Depth-wise convolution + if self.stride > 1: + self.conv_dw = nn.Conv2d(mid_chs, mid_chs, dw_kernel_size, stride=stride, + padding=(dw_kernel_size-1)//2, + groups=mid_chs, bias=False) + self.bn_dw = nn.BatchNorm2d(mid_chs) + + # Squeeze-and-excitation + if has_se: + self.se = SqueezeExcite(mid_chs, se_ratio=se_ratio) + else: + self.se = None + + # Point-wise linear projection + self.ghost2 = GhostModule(mid_chs, out_chs, relu=False) + + # shortcut + if (in_chs == out_chs and self.stride == 1): + self.shortcut = nn.Sequential() + else: + self.shortcut = nn.Sequential( + nn.Conv2d(in_chs, in_chs, dw_kernel_size, stride=stride, + padding=(dw_kernel_size-1)//2, groups=in_chs, bias=False), + nn.BatchNorm2d(in_chs), + nn.Conv2d(in_chs, out_chs, 1, stride=1, padding=0, bias=False), + nn.BatchNorm2d(out_chs), + ) + + + def forward(self, x): + residual = x + + # 1st ghost bottleneck + x = self.ghost1(x) + + # Depth-wise convolution + if self.stride > 1: + x = self.conv_dw(x) + x = self.bn_dw(x) + + # Squeeze-and-excitation + if self.se is not None: + x = self.se(x) + + # 2nd ghost bottleneck + x = self.ghost2(x) + + x += self.shortcut(residual) + return x + + +class GhostNet(nn.Module): + def __init__(self, cfgs, num_classes=1000, width=1.0, dropout=0.2): + super(GhostNet, self).__init__() + # setting of inverted residual blocks + self.cfgs = cfgs + self.dropout = dropout + + # building first layer + output_channel = _make_divisible(16 * width, 4) + self.conv_stem = nn.Conv2d(3, output_channel, 3, 2, 1, bias=False) + self.bn1 = nn.BatchNorm2d(output_channel) + self.act1 = nn.ReLU(inplace=True) + input_channel = output_channel + + # building inverted residual blocks + stages = [] + block = GhostBottleneck + for cfg in self.cfgs: + layers = [] + for k, exp_size, c, se_ratio, s in cfg: + output_channel = _make_divisible(c * width, 4) + hidden_channel = _make_divisible(exp_size * width, 4) + layers.append(block(input_channel, hidden_channel, output_channel, k, s, + se_ratio=se_ratio)) + input_channel = output_channel + stages.append(nn.Sequential(*layers)) + + output_channel = _make_divisible(exp_size * width, 4) + stages.append(nn.Sequential(ConvBnAct(input_channel, output_channel, 1))) + input_channel = output_channel + + self.blocks = nn.Sequential(*stages) + + # building last several layers + output_channel = 1280 + self.global_pool = nn.AdaptiveAvgPool2d((1, 1)) + self.conv_head = nn.Conv2d(input_channel, output_channel, 1, 1, 0, bias=True) + self.act2 = nn.ReLU(inplace=True) + self.classifier = nn.Linear(output_channel, num_classes) + + def forward(self, x): + x = self.conv_stem(x) + x = self.bn1(x) + x = self.act1(x) + x = self.blocks(x) + x = self.global_pool(x) + x = self.conv_head(x) + x = self.act2(x) + x = x.view(x.size(0), -1) + if self.dropout > 0.: + x = F.dropout(x, p=self.dropout, training=self.training) + x = self.classifier(x) + return x + + +def ghostnet(**kwargs): + """ + Constructs a GhostNet model + """ + cfgs = [ + # k, t, c, SE, s + # stage1 + [[3, 16, 16, 0, 1]], + # stage2 + [[3, 48, 24, 0, 2]], + [[3, 72, 24, 0, 1]], + # stage3 + [[5, 72, 40, 0.25, 2]], + [[5, 120, 40, 0.25, 1]], + # stage4 + [[3, 240, 80, 0, 2]], + [[3, 200, 80, 0, 1], + [3, 184, 80, 0, 1], + [3, 184, 80, 0, 1], + [3, 480, 112, 0.25, 1], + [3, 672, 112, 0.25, 1] + ], + # stage5 + [[5, 672, 160, 0.25, 2]], + [[5, 960, 160, 0, 1], + [5, 960, 160, 0.25, 1], + [5, 960, 160, 0, 1], + [5, 960, 160, 0.25, 1] + ] + ] + return GhostNet(cfgs, **kwargs) + + +if __name__=='__main__': + model = ghostnet() + model.eval() + print(model) + input = torch.randn(32,3,320,256) + y = model(input) print(y.size()) \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/GhostNet/modelarts/train_start.py b/PyTorch/contrib/cv/classification/GhostNet/modelarts/train_start.py index 4335340a1458eabf210cd37febbd2c6e92c0d9d0..d0a33069ef6c28b5ba401cc6f44174a008a17bc3 100644 --- a/PyTorch/contrib/cv/classification/GhostNet/modelarts/train_start.py +++ b/PyTorch/contrib/cv/classification/GhostNet/modelarts/train_start.py @@ -1,778 +1,778 @@ -#!/usr/bin/env python -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -""" ImageNet Training Script -This is intended to be a lean and easily modifiable ImageNet training script that reproduces ImageNet -training results with some of the latest networks and training techniques. It favours canonical PyTorch -and standard Python style over trying to be able to 'do it all.' That said, it offers quite a few speed -and training result improvements over the usual PyTorch example scripts. Repurpose as you see fit. -This script was started from an early version of the PyTorch ImageNet example -(https://github.com/pytorch/examples/tree/master/imagenet) -NVIDIA CUDA specific speedups adopted from NVIDIA Apex examples -(https://github.com/NVIDIA/apex/tree/master/examples/imagenet) -Hacked together by / Copyright 2020 Ross Wightman (https://github.com/rwightman) -""" -import argparse -import time -import yaml -import os -import logging -from collections import OrderedDict -from contextlib import suppress -from datetime import datetime -import glob -import shutil - -import torch -import torch.nn as nn -import torchvision.utils -from torch.nn.parallel import DistributedDataParallel as NativeDDP -import torch.onnx - -from timm.data import create_dataset, create_loader, resolve_data_config, Mixup, FastCollateMixup, AugMixDataset -from timm.data import create_loader, resolve_data_config, Mixup, FastCollateMixup, AugMixDataset -from timm.models import create_model, resume_checkpoint, load_checkpoint, convert_splitbn_model -from timm.utils import * -from timm.loss import LabelSmoothingCrossEntropy, SoftTargetCrossEntropy, JsdCrossEntropy -from timm.optim import create_optimizer -from timm.scheduler import create_scheduler -from timm.utils import ApexScaler, NativeScaler -from ghostnet.ghostnet_pytorch.ghostnet import ghostnet -import torch.npu - -# modelarts modification -import moxing as mox - -CALCULATE_DEVICE = "npu:0" - -try: - from apex import amp - from apex.parallel import DistributedDataParallel as ApexDDP - from apex.parallel import convert_syncbn_model - - has_apex = True -except ImportError: - has_apex = False - -has_native_amp = False -try: - if getattr(torch.cuda.amp, 'autocast') is not None: - has_native_amp = True -except AttributeError: - pass - -torch.backends.cudnn.benchmark = True -_logger = logging.getLogger('train') - -# The first arg parser parses out only the --config argument, this argument is used to -# load a yaml file containing key-values that override the defaults for the main parser below -config_parser = parser = argparse.ArgumentParser(description='Training Config', add_help=False) -parser.add_argument('-c', '--config', default='', type=str, metavar='FILE', - help='YAML config file specifying default arguments') -parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') -# Dataset / Model parameters -parser.add_argument('data_dir', metavar='DIR', - help='path to dataset') -parser.add_argument('--dataset', '-d', metavar='NAME', default='', - help='dataset type (default: ImageFolder/ImageTar if empty)') -parser.add_argument('--train-split', metavar='NAME', default='train', - help='dataset train split (default: train)') -parser.add_argument('--val-split', metavar='NAME', default='validation', - help='dataset validation split (default: validation)') -parser.add_argument('--model', default='resnet101', type=str, metavar='MODEL', - help='Name of model to train (default: "countception"') -parser.add_argument('--pretrained', action='store_true', default=False, - help='Start with pretrained version of specified network (if avail)') -parser.add_argument('--initial-checkpoint', default='', type=str, metavar='PATH', - help='Initialize model from this checkpoint (default: none)') -parser.add_argument('--resume', default='', type=str, metavar='PATH', - help='Resume full model and optimizer state from checkpoint (default: none)') -parser.add_argument('--no-resume-opt', action='store_true', default=False, - help='prevent resume of optimizer state when resuming model') -parser.add_argument('--num-classes', type=int, default=None, metavar='N', - help='number of label classes (Model default if None)') -parser.add_argument('--gp', default=None, type=str, metavar='POOL', - help='Global pool type, one of (fast, avg, max, avgmax, avgmaxc). Model default if None.') -parser.add_argument('--img-size', type=int, default=None, metavar='N', - help='Image patch size (default: None => model default)') -parser.add_argument('--input-size', default=None, nargs=3, type=int, - metavar='N N N', - help='Input all image dimensions (d h w, e.g. --input-size 3 224 224), uses model default if empty') -parser.add_argument('--crop-pct', default=None, type=float, - metavar='N', help='Input image center crop percent (for validation only)') -parser.add_argument('--mean', type=float, nargs='+', default=None, metavar='MEAN', - help='Override mean pixel value of dataset') -parser.add_argument('--std', type=float, nargs='+', default=None, metavar='STD', - help='Override std deviation of of dataset') -parser.add_argument('--interpolation', default='', type=str, metavar='NAME', - help='Image resize interpolation type (overrides model)') -parser.add_argument('-b', '--batch-size', type=int, default=1024, metavar='N', - help='input batch size for training (default: 32)') -parser.add_argument('-vb', '--validation-batch-size-multiplier', type=int, default=1, metavar='N', - help='ratio of validation batch size to training batch size (default: 1)') - -# Optimizer parameters -parser.add_argument('--opt', default='sgd', type=str, metavar='OPTIMIZER', - help='Optimizer (default: "sgd"') -parser.add_argument('--opt-eps', default=None, type=float, metavar='EPSILON', - help='Optimizer Epsilon (default: None, use opt default)') -parser.add_argument('--opt-betas', default=None, type=float, nargs='+', metavar='BETA', - help='Optimizer Betas (default: None, use opt default)') -parser.add_argument('--momentum', type=float, default=0.9, metavar='M', - help='Optimizer momentum (default: 0.9)') -parser.add_argument('--weight-decay', type=float, default=0.0001, - help='weight decay (default: 0.0001)') -parser.add_argument('--clip-grad', type=float, default=None, metavar='NORM', - help='Clip gradient norm (default: None, no clipping)') - -# Learning rate schedule parameters -parser.add_argument('--sched', default='step', type=str, metavar='SCHEDULER', - help='LR scheduler (default: "step"') -parser.add_argument('--lr', type=float, default=0.4, metavar='LR', - help='learning rate (default: 0.01)') -parser.add_argument('--lr-noise', type=float, nargs='+', default=None, metavar='pct, pct', - help='learning rate noise on/off epoch percentages') -parser.add_argument('--lr-noise-pct', type=float, default=0.67, metavar='PERCENT', - help='learning rate noise limit percent (default: 0.67)') -parser.add_argument('--lr-noise-std', type=float, default=1.0, metavar='STDDEV', - help='learning rate noise std-dev (default: 1.0)') -parser.add_argument('--lr-cycle-mul', type=float, default=1.0, metavar='MULT', - help='learning rate cycle len multiplier (default: 1.0)') -parser.add_argument('--lr-cycle-limit', type=int, default=1, metavar='N', - help='learning rate cycle limit') -parser.add_argument('--warmup-lr', type=float, default=0.0001, metavar='LR', - help='warmup learning rate (default: 0.0001)') -parser.add_argument('--min-lr', type=float, default=1e-5, metavar='LR', - help='lower lr bound for cyclic schedulers that hit 0 (1e-5)') -parser.add_argument('--epochs', type=int, default=200, metavar='N', - help='number of epochs to train (default: 2)') -parser.add_argument('--start-epoch', default=None, type=int, metavar='N', - help='manual epoch number (useful on restarts)') -parser.add_argument('--decay-epochs', type=float, default=30, metavar='N', - help='epoch interval to decay LR') -parser.add_argument('--warmup-epochs', type=int, default=3, metavar='N', - help='epochs to warmup LR, if scheduler supports') -parser.add_argument('--cooldown-epochs', type=int, default=0, metavar='N', - help='epochs to cooldown LR at min_lr, after cyclic schedule ends') -parser.add_argument('--patience-epochs', type=int, default=0, metavar='N', - help='patience epochs for Plateau LR scheduler (default: 10') -parser.add_argument('--decay-rate', '--dr', type=float, default=0.1, metavar='RATE', - help='LR decay rate (default: 0.1)') - -# Augmentation & regularization parameters -parser.add_argument('--no-aug', action='store_true', default=False, - help='Disable all training augmentation, override other train aug args') -parser.add_argument('--scale', type=float, nargs='+', default=[0.08, 1.0], metavar='PCT', - help='Random resize scale (default: 0.08 1.0)') -parser.add_argument('--ratio', type=float, nargs='+', default=[3. / 4., 4. / 3.], metavar='RATIO', - help='Random resize aspect ratio (default: 0.75 1.33)') -parser.add_argument('--hflip', type=float, default=0.5, - help='Horizontal flip training aug probability') -parser.add_argument('--vflip', type=float, default=0., - help='Vertical flip training aug probability') -parser.add_argument('--color-jitter', type=float, default=0.4, metavar='PCT', - help='Color jitter factor (default: 0.4)') -parser.add_argument('--aug-splits', type=int, default=0, - help='Number of augmentation splits (default: 0, valid: 0 or >=2)') -parser.add_argument('--jsd', action='store_true', default=False, - help='Enable Jensen-Shannon Divergence + CE loss. Use with `--aug-splits`.') -parser.add_argument('--recount', type=int, default=1, - help='Random erase count (default: 1)') -parser.add_argument('--resplit', action='store_true', default=False, - help='Do not random erase first (clean) augmentation split') -parser.add_argument('--mixup', type=float, default=0.0, - help='mixup alpha, mixup enabled if > 0. (default: 0.)') -parser.add_argument('--cutmix', type=float, default=0.0, - help='cutmix alpha, cutmix enabled if > 0. (default: 0.)') -parser.add_argument('--cutmix-minmax', type=float, nargs='+', default=None, - help='cutmix min/max ratio, overrides alpha and enables cutmix if set (default: None)') -parser.add_argument('--mixup-prob', type=float, default=1.0, - help='Probability of performing mixup or cutmix when either/both is enabled') -parser.add_argument('--mixup-switch-prob', type=float, default=0.5, - help='Probability of switching to cutmix when both mixup and cutmix enabled') -parser.add_argument('--mixup-mode', type=str, default='batch', - help='How to apply mixup/cutmix params. Per "batch", "pair", or "elem"') -parser.add_argument('--mixup-off-epoch', default=0, type=int, metavar='N', - help='Turn off mixup after this epoch, disabled if 0 (default: 0)') -parser.add_argument('--smoothing', type=float, default=0.1, - help='Label smoothing (default: 0.1)') -parser.add_argument('--train-interpolation', type=str, default='random', - help='Training interpolation (random, bilinear, bicubic default: "random")') -parser.add_argument('--drop', type=float, default=0.2, metavar='PCT', - help='Dropout rate (default: 0.)') -parser.add_argument('--drop-path', type=float, default=None, metavar='PCT', - help='Drop path rate (default: None)') -parser.add_argument('--drop-block', type=float, default=None, metavar='PCT', - help='Drop block rate (default: None)') -parser.add_argument('--bn-tf', action='store_true', default=False, - help='Use Tensorflow BatchNorm defaults for models that support it (default: False)') -parser.add_argument('--bn-momentum', type=float, default=None, - help='BatchNorm momentum override (if not None)') -parser.add_argument('--bn-eps', type=float, default=None, - help='BatchNorm epsilon override (if not None)') -parser.add_argument('--sync-bn', action='store_true', - help='Enable NVIDIA Apex or Torch synchronized BatchNorm.') -parser.add_argument('--dist-bn', type=str, default='', - help='Distribute BatchNorm stats between nodes after each epoch ("broadcast", "reduce", or "")') -parser.add_argument('--split-bn', action='store_true', - help='Enable separate BN layers per augmentation split.') -# Misc -parser.add_argument('--seed', type=int, default=42, metavar='S', - help='random seed (default: 42)') -parser.add_argument('--log-interval', type=int, default=50, metavar='N', - help='how many batches to wait before logging training status') -parser.add_argument('--recovery-interval', type=int, default=0, metavar='N', - help='how many batches to wait before writing recovery checkpoint') -parser.add_argument('--checkpoint-hist', type=int, default=10, metavar='N', - help='number of checkpoints to keep (default: 10)') -parser.add_argument('-j', '--workers', type=int, default=4, metavar='N', - help='how many training processes to use (default: 1)') -parser.add_argument('--save-images', action='store_true', default=False, - help='save images of input bathes every log interval for debugging') -parser.add_argument('--amp', action='store_true', default=False, - help='use NVIDIA Apex AMP or Native AMP for mixed precision training') -parser.add_argument('--apex-amp', action='store_true', default=False, - help='Use NVIDIA Apex AMP mixed precision') -parser.add_argument('--native-amp', action='store_true', default=False, - help='Use Native Torch AMP mixed precision') -parser.add_argument('--channels-last', action='store_true', default=False, - help='Use channels_last memory layout') -parser.add_argument('--pin-mem', action='store_true', default=False, - help='Pin CPU memory in DataLoader for more efficient (sometimes) transfer to GPU.') -parser.add_argument('--no-prefetcher', action='store_true', default=True, - help='disable fast prefetcher') -parser.add_argument('--output', default='', type=str, metavar='PATH', - help='path to output folder (default: none, current dir)') -parser.add_argument('--eval-metric', default='top1', type=str, metavar='EVAL_METRIC', - help='Best metric (default: "top1"') -parser.add_argument('--tta', type=int, default=0, metavar='N', - help='Test/inference time augmentation (oversampling) factor. 0=None (default: 0)') -parser.add_argument("--local_rank", default=0, type=int) -parser.add_argument('--use-multi-epochs-loader', action='store_true', default=False, - help='use the multi-epochs-loader to save time at the beginning of every epoch') -parser.add_argument('--torchscript', dest='torchscript', action='store_true', - help='convert model torchscript for inference') -parser.add_argument('--width', type=float, default=1.0, - help='Width ratio (default: 1.0)') -parser.add_argument('--dist-url', default='tcp://127.0.0.1:50000', type=str, - help='url used to set up pretained training') -parser.add_argument('--dist-backend', default='nccl', type=str, - help='distributed backend') -parser.add_argument('--npu', default=None, type=int, - help='NPU id to use.') -#modelarts -parser.add_argument('--modelarts_mod', action='store_true', default=False, - help='Enable modelarts mode loss function to train') -parser.add_argument('--train_url', - default="/cache/training", - type=str, - help="setting dir of training output") -parser.add_argument('--pretrained_weight', default='', type=str, metavar='PATH', - help='path to pretrained weight') -parser.add_argument('--onnx', default=True, action='store_true', - help="convert pth model to onnx") -parser.add_argument('--data_url', - type=str, - default='/cache/data_url', - help='the training data') - -CACHE_TRAINING_URL = "/cache/training" -def _parse_args(): - # Do we have a config file to parse? - args_config, remaining = config_parser.parse_known_args() - if args_config.config: - with open(args_config.config, 'r') as f: - cfg = yaml.safe_load(f) - parser.set_defaults(**cfg) - # The main arg parser parses the rest of the args, the usual - # defaults will have been overridden if config file specified. - args = parser.parse_args(remaining) - print(args) - # Cache the args as a text string to save them in the output dir later - args_text = yaml.safe_dump(args.__dict__, default_flow_style=False) - return args, args_text - - -def main(): - setup_default_logging() - args, args_text = _parse_args() - - args.prefetcher = not args.no_prefetcher - args.distributed = False - if args.npu is None: - args.npu = 0 - CALCULATE_DEVICE = "npu:{}".format(args.npu) - torch.npu.set_device(CALCULATE_DEVICE) - print("use ", CALCULATE_DEVICE) - - if 'WORLD_SIZE' in os.environ: - args.distributed = int(os.environ['WORLD_SIZE']) > 1 - args.device = 'npu:0' - args.world_size = 1 - args.rank = 0 # global rank - _logger.info('Training with a single process on 1 NPUs.') - assert args.rank >= 0 - - # resolve AMP arguments based on PyTorch / Apex availability - use_amp = None - if args.amp: - # for backwards compat, `--amp` arg tries apex before native amp - if has_apex: - args.apex_amp = True - elif has_native_amp: - args.native_amp = True - if args.apex_amp and has_apex: - use_amp = 'apex' - elif args.native_amp and has_native_amp: - use_amp = 'native' - elif args.apex_amp or args.native_amp: - _logger.warning("Neither APEX or native Torch AMP is available, using float32. " - "Install NVIDA apex or upgrade to PyTorch 1.6") - - torch.manual_seed(args.seed + args.rank) - model = ghostnet(num_classes=args.num_classes, width=args.width, dropout=args.drop) - - if args.pretrained: - CACHE_MODEL_URL = "/cache/model" - os.makedirs(CACHE_MODEL_URL, exist_ok=True) - mox.file.copy_parallel(args.pretrained_weight, os.path.join(CACHE_MODEL_URL, "model_best.pth.tar")) - pretrained_weight = os.path.join(CACHE_MODEL_URL, "model_best.pth.tar") - pretrained_dict = torch.load(pretrained_weight)["state_dict"] - pretrained_model = {k.replace('module.', ''): v for k, v in pretrained_dict.items()} - if "classifier.weight" in pretrained_model: - pretrained_model.pop('classifier.weight') - pretrained_model.pop('classifier.bias') - model.load_state_dict(pretrained_model, strict=False) - - for param in model.parameters(): - param.requires_grad = False - - for param in model.classifier.parameters(): - param.requires_grad = True - - if args.num_classes is None: - assert hasattr(model, 'num_classes'), 'Model must have `num_classes` attr if not set on cmd line/config.' - args.num_classes = model.num_classes # FIXME handle model default vs config num_classes more elegantly - - if args.local_rank == 0: - _logger.info('Model %s created, param count: %d' % - (args.model, sum([m.numel() for m in model.parameters()]))) - - data_config = resolve_data_config(vars(args), model=model, verbose=args.local_rank == 0) - - # setup augmentation batch splits for contrastive loss or split bn - num_aug_splits = 0 - if args.aug_splits > 0: - assert args.aug_splits > 1, 'A split of 1 makes no sense' - num_aug_splits = args.aug_splits - - # enable split bn (separate bn stats per batch-portion) - if args.split_bn: - assert num_aug_splits > 1 or args.resplit - model = convert_splitbn_model(model, max(num_aug_splits, 2)) - - # move model to GPU, enable channels last layout if set - model = model.to(CALCULATE_DEVICE) - if args.channels_last: - model = model.to(memory_format=torch.channels_last) - - if args.torchscript: - assert not use_amp == 'apex', 'Cannot use APEX AMP with torchscripted model' - assert not args.sync_bn, 'Cannot use SyncBatchNorm with torchscripted model' - model = torch.jit.script(model) - - optimizer = create_optimizer(args, model) - - # setup automatic mixed-precision (AMP) loss scaling and op casting - amp_autocast = suppress # do nothing - loss_scaler = None - if use_amp == 'apex': - model, optimizer = amp.initialize(model, optimizer, opt_level='O2', loss_scale=128) - loss_scaler = ApexScaler() - if args.local_rank == 0: - _logger.info('Using NVIDIA APEX AMP. Training in mixed precision.') - elif use_amp == 'native': - amp_autocast = torch.cuda.amp.autocast - loss_scaler = NativeScaler() - if args.local_rank == 0: - _logger.info('Using native Torch AMP. Training in mixed precision.') - else: - if args.local_rank == 0: - _logger.info('AMP not enabled. Training in float32.') - - # optionally resume from a checkpoint - resume_epoch = None - if args.resume: - resume_epoch = resume_checkpoint( - model, args.resume, - optimizer=None if args.no_resume_opt else optimizer, - loss_scaler=None if args.no_resume_opt else loss_scaler, - log_info=args.local_rank == 0) - - # setup exponential moving average of model weights, SWA could be used here too - model_ema = None - # setup learning rate schedule and starting epoch - lr_scheduler, num_epochs = create_scheduler(args, optimizer) - start_epoch = 0 - if args.start_epoch is not None: - # a specified start_epoch will always override the resume epoch - start_epoch = args.start_epoch - elif resume_epoch is not None: - start_epoch = resume_epoch - if lr_scheduler is not None and start_epoch > 0: - lr_scheduler.step(start_epoch) - - if args.local_rank == 0: - _logger.info('Scheduled epochs: {}'.format(num_epochs)) - - # create the train and eval datasets - real_path = '/cache/data_url' - if not os.path.exists(real_path): - os.makedirs(real_path) - mox.file.copy_parallel(args.data_url, real_path) - print("training data finish copy to %s." % real_path) - dataset_train = create_dataset( - args.dataset, root=real_path, split=args.train_split, is_training=True, batch_size=args.batch_size) - dataset_eval = create_dataset( - args.dataset, root=real_path, split=args.val_split, is_training=False, batch_size=args.batch_size) - # setup mixup / cutmix - collate_fn = None - mixup_fn = None - mixup_active = args.mixup > 0 or args.cutmix > 0. or args.cutmix_minmax is not None - if mixup_active: - mixup_args = dict( - mixup_alpha=args.mixup, cutmix_alpha=args.cutmix, cutmix_minmax=args.cutmix_minmax, - prob=args.mixup_prob, switch_prob=args.mixup_switch_prob, mode=args.mixup_mode, - label_smoothing=args.smoothing, num_classes=args.num_classes) - if args.prefetcher: - assert not num_aug_splits # collate conflict (need to support deinterleaving in collate mixup) - collate_fn = FastCollateMixup(**mixup_args) - else: - mixup_fn = Mixup(**mixup_args) - - # wrap dataset in AugMix helper - if num_aug_splits > 1: - dataset_train = AugMixDataset(dataset_train, num_splits=num_aug_splits) - - # create data loaders w/ augmentation pipeiine - train_interpolation = args.train_interpolation - if args.no_aug or not train_interpolation: - train_interpolation = data_config['interpolation'] - loader_train = create_loader( - dataset_train, - input_size=data_config['input_size'], - batch_size=args.batch_size, - is_training=True, - use_prefetcher=not args.no_prefetcher, - no_aug=args.no_aug, - re_count=args.recount, - re_split=args.resplit, - scale=args.scale, - ratio=args.ratio, - hflip=args.hflip, - vflip=args.vflip, - color_jitter=args.color_jitter, - num_aug_splits=num_aug_splits, - interpolation=train_interpolation, - mean=data_config['mean'], - std=data_config['std'], - num_workers=args.workers, - collate_fn=collate_fn, - pin_memory=args.pin_mem, - use_multi_epochs_loader=args.use_multi_epochs_loader - ) - - loader_eval = create_loader( - dataset_eval, - input_size=data_config['input_size'], - batch_size=args.validation_batch_size_multiplier * args.batch_size, - is_training=False, - use_prefetcher=not args.no_prefetcher, - interpolation=data_config['interpolation'], - mean=data_config['mean'], - std=data_config['std'], - num_workers=args.workers, - crop_pct=data_config['crop_pct'], - pin_memory=args.pin_mem, - ) - - # setup loss function - if args.jsd: - #assert num_aug_splits > 1 # JSD only valid with aug splits set - train_loss_fn = JsdCrossEntropy(num_splits=num_aug_splits, smoothing=args.smoothing).to(CALCULATE_DEVICE) - elif mixup_active: - # smoothing is handled with mixup target transform - train_loss_fn = SoftTargetCrossEntropy().to(CALCULATE_DEVICE) - elif args.smoothing: - train_loss_fn = LabelSmoothingCrossEntropy(smoothing=args.smoothing).to(CALCULATE_DEVICE) - else: - train_loss_fn = nn.CrossEntropyLoss().to(CALCULATE_DEVICE) - if args.modelarts_mod: - train_loss_fn = nn.CrossEntropyLoss().to(CALCULATE_DEVICE) - - validate_loss_fn = nn.CrossEntropyLoss().to(CALCULATE_DEVICE) - # setup checkpoint saver and eval metric tracking - eval_metric = args.eval_metric - best_metric = None - best_epoch = None - saver = None - output_dir = '' - if args.local_rank == 0: - output_base = args.output if args.output else './output' - exp_name = '-'.join([ - datetime.now().strftime("%Y%m%d-%H%M%S"), - args.model, - str(data_config['input_size'][-1]) - ]) - output_dir = get_outdir(output_base, 'train', exp_name) - decreasing = True if eval_metric == 'loss' else False - saver = CheckpointSaver( - model=model, optimizer=optimizer, args=args, amp_scaler=loss_scaler, - checkpoint_dir=output_dir, recovery_dir=output_dir, decreasing=decreasing, max_history=args.checkpoint_hist) - - with open(os.path.join(output_dir, 'args.yaml'), 'w') as f: - f.write(args_text) - - try: - for epoch in range(start_epoch, num_epochs): - - train_metrics = train_one_epoch( - epoch, model, loader_train, optimizer, train_loss_fn, args, - lr_scheduler=lr_scheduler, saver=saver, output_dir=output_dir, - amp_autocast=amp_autocast, loss_scaler=loss_scaler, mixup_fn=mixup_fn) - - eval_metrics = validate(model, loader_eval, validate_loss_fn, args, amp_autocast=amp_autocast) - - if lr_scheduler is not None: - # step LR for next epoch - lr_scheduler.step(epoch + 1, eval_metrics[eval_metric]) - - update_summary( - epoch, train_metrics, eval_metrics, os.path.join(output_dir, 'summary.csv'), - write_header=best_metric is None) - - if saver is not None: - # save proper checkpoint with eval metric - save_metric = eval_metrics[eval_metric] - best_metric, best_epoch = saver.save_checkpoint(epoch, metric=save_metric) - - except KeyboardInterrupt: - pass - if best_metric is not None: - _logger.info('*** Best metric: {0} (epoch {1})'.format(best_metric, best_epoch)) - - if args.onnx: - os.makedirs(CACHE_TRAINING_URL, exist_ok=True) - print("abspath:",os.path.abspath(output_dir)) - print("output_dir:",os.listdir(output_dir)) - shutil.copy(os.path.join(os.path.abspath(output_dir), 'model_best.pth.tar'), CACHE_TRAINING_URL) - pth_pattern = os.path.join(CACHE_TRAINING_URL, 'model_best.pth.tar') - print("pth_pattern:",os.path.abspath(pth_pattern)) - pth_file_list = glob.glob(pth_pattern) - if not pth_file_list: - print(f"can't find pth {pth_pattern}") - pth_file = pth_file_list[0] - onnx_path = pth_file.split(".")[0] + '.onnx' - convert(pth_file, onnx_path) - # --------------modelarts modification---------- - mox.file.copy_parallel(CACHE_TRAINING_URL, args.train_url) - # --------------modelarts modification end---------- - print("CACHE_TRAINING_URL:",os.listdir(CACHE_TRAINING_URL)) - -def train_one_epoch( - epoch, model, loader, optimizer, loss_fn, args, - lr_scheduler=None, saver=None, output_dir='', amp_autocast=suppress, - loss_scaler=None, mixup_fn=None): - if args.mixup_off_epoch and epoch >= args.mixup_off_epoch: - if args.prefetcher and loader.mixup_enabled: - loader.mixup_enabled = False - elif mixup_fn is not None: - mixup_fn.mixup_enabled = False - - second_order = hasattr(optimizer, 'is_second_order') and optimizer.is_second_order - batch_time_m = AverageMeter() - data_time_m = AverageMeter() - losses_m = AverageMeter(start_count_index=0) - - model.train() - - end = time.time() - last_idx = len(loader) - 1 - num_updates = epoch * len(loader) - for batch_idx, (input, target) in enumerate(loader): - last_batch = batch_idx == last_idx - data_time_m.update(time.time() - end) - if not args.prefetcher: - input, target = input.npu(), target.npu() - if mixup_fn is not None: - input, target = mixup_fn(input, target) - if args.channels_last: - input = input.contiguous(memory_format=torch.channels_last) - - with amp_autocast(): - output = model(input) - target = target.to(torch.int32) - loss = loss_fn(output, target) - - losses_m.update(loss.item(), input.size(0)) - - optimizer.zero_grad() - if loss_scaler is not None: - loss_scaler( - loss, optimizer, clip_grad=args.clip_grad, parameters=model.parameters(), create_graph=second_order) - else: - loss.backward(create_graph=second_order) - if args.clip_grad is not None: - torch.nn.utils.clip_grad_norm_(model.parameters(), args.clip_grad) - optimizer.step() - - num_updates += 1 - batch_time_m.update(time.time() - end) - if last_batch or batch_idx % args.log_interval == 0: - lrl = [param_group['lr'] for param_group in optimizer.param_groups] - lr = sum(lrl) / len(lrl) - - if args.local_rank == 0: - if batch_time_m.avg > 0: - _logger.info( - 'Train: {} [{:>4d}/{} ({:>3.0f}%)] ' - 'Loss: {loss.val:>9.6f} ({loss.avg:>6.4f}) ' - 'Time: {batch_time.val:.3f}s, {rate:>7.2f}/s ' - '({batch_time.avg:.3f}s, {rate_avg:>7.2f}/s) ' - 'LR: {lr:.3e} ' - 'Data: {data_time.val:.3f} ({data_time.avg:.3f})' - 'fps: {fps:.3f} ' - 'Batch_Size:{batch_size:.1f} '.format( - epoch, - batch_idx, len(loader), - 100. * batch_idx / last_idx, - loss=losses_m, - batch_time=batch_time_m, - rate=input.size(0) * args.world_size / batch_time_m.val, - rate_avg=input.size(0) * args.world_size / batch_time_m.avg, - lr=lr, - data_time=data_time_m, - fps=args.batch_size / batch_time_m.avg, - batch_size=args.batch_size)) - - if args.save_images and output_dir: - torchvision.utils.save_image( - input, - os.path.join(output_dir, 'train-batch-%d.jpg' % batch_idx), - padding=0, - normalize=True) - - if saver is not None and args.recovery_interval and ( - last_batch or (batch_idx + 1) % args.recovery_interval == 0): - saver.save_recovery(epoch, batch_idx=batch_idx) - - if lr_scheduler is not None: - lr_scheduler.step_update(num_updates=num_updates, metric=losses_m.avg) - - end = time.time() - # end for - - if hasattr(optimizer, 'sync_lookahead'): - optimizer.sync_lookahead() - - return OrderedDict([('loss', losses_m.avg)]) - - -def validate(model, loader, loss_fn, args, amp_autocast=suppress, log_suffix=''): - batch_time_m = AverageMeter() - losses_m = AverageMeter(start_count_index=0) - top1_m = AverageMeter(start_count_index=0) - top5_m = AverageMeter(start_count_index=0) - model.eval() - - end = time.time() - last_idx = len(loader) - 1 - with torch.no_grad(): - for batch_idx, (input, target) in enumerate(loader): - last_batch = batch_idx == last_idx - if args.no_prefetcher: - input = input.npu() - target = target.npu() - if args.channels_last: - input = input.contiguous(memory_format=torch.channels_last) - - with amp_autocast(): - output = model(input) - if isinstance(output, (tuple, list)): - output = output[0] - - # augmentation reduction - reduce_factor = args.tta - if reduce_factor > 1: - output = output.unfold(0, reduce_factor, reduce_factor).mean(dim=2) - target = target[0:target.size(0):reduce_factor] - - target = target.to(torch.int32) - loss = loss_fn(output, target) - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - - reduced_loss = loss.data - - losses_m.update(reduced_loss.item(), input.size(0)) - top1_m.update(acc1.item(), output.size(0)) - top5_m.update(acc5.item(), output.size(0)) - - batch_time_m.update(time.time() - end) - end = time.time() - if args.local_rank == 0 and (last_batch or batch_idx % args.log_interval == 0): - if batch_time_m.avg > 0: - log_name = 'Test' + log_suffix - _logger.info( - '{0}: [{1:>4d}/{2}] ' - 'Time: {batch_time.val:.3f} ({batch_time.avg:.3f}) ' - 'Loss: {loss.val:>7.4f} ({loss.avg:>6.4f}) ' - 'Acc@1: {top1.val:>7.4f} ({top1.avg:>7.4f}) ' - 'Acc@5: {top5.val:>7.4f} ({top5.avg:>7.4f})' - 'fps: {fps:.3f} ' - 'Batch_Size:{batch_size:.1f} '.format( - log_name, batch_idx, last_idx, batch_time=batch_time_m, - loss=losses_m, top1=top1_m, top5=top5_m, fps=args.batch_size / batch_time_m.avg, - batch_size=args.batch_size)) - - metrics = OrderedDict([('loss', losses_m.avg), ('top1', top1_m.avg), ('top5', top5_m.avg)]) - - return metrics - -def proc_node_module(checkpoint, attr_name): - new_model_state = OrderedDict() - for k, v in checkpoint[attr_name].items(): - if(k[0: 7] == "module."): - name = k[7:] - else: - name = k[0:] - new_model_state[name] = v - return new_model_state - -def convert(pth_file_path, onnx_file_path): - args, args_text = _parse_args() - checkpoint = torch.load(pth_file_path, map_location='cpu') - checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') - model = ghostnet(num_classes=args.num_classes, width=args.width, dropout=args.drop) - model.load_state_dict(checkpoint['state_dict'], False) - model.eval() - - input_names = ["image"] - output_names = ["output1"] - dummy_input = torch.randn(2, 3, 224, 224) - torch.onnx.export(model, dummy_input, onnx_file_path, input_names=input_names, output_names=output_names, opset_version=11) - -if __name__ == '__main__': - main() - +#!/usr/bin/env python +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" ImageNet Training Script +This is intended to be a lean and easily modifiable ImageNet training script that reproduces ImageNet +training results with some of the latest networks and training techniques. It favours canonical PyTorch +and standard Python style over trying to be able to 'do it all.' That said, it offers quite a few speed +and training result improvements over the usual PyTorch example scripts. Repurpose as you see fit. +This script was started from an early version of the PyTorch ImageNet example +(https://github.com/pytorch/examples/tree/master/imagenet) +NVIDIA CUDA specific speedups adopted from NVIDIA Apex examples +(https://github.com/NVIDIA/apex/tree/master/examples/imagenet) +Hacked together by / Copyright 2020 Ross Wightman (https://github.com/rwightman) +""" +import argparse +import time +import yaml +import os +import logging +from collections import OrderedDict +from contextlib import suppress +from datetime import datetime +import glob +import shutil + +import torch +import torch.nn as nn +import torchvision.utils +from torch.nn.parallel import DistributedDataParallel as NativeDDP +import torch.onnx + +from timm.data import create_dataset, create_loader, resolve_data_config, Mixup, FastCollateMixup, AugMixDataset +from timm.data import create_loader, resolve_data_config, Mixup, FastCollateMixup, AugMixDataset +from timm.models import create_model, resume_checkpoint, load_checkpoint, convert_splitbn_model +from timm.utils import * +from timm.loss import LabelSmoothingCrossEntropy, SoftTargetCrossEntropy, JsdCrossEntropy +from timm.optim import create_optimizer +from timm.scheduler import create_scheduler +from timm.utils import ApexScaler, NativeScaler +from ghostnet.ghostnet_pytorch.ghostnet import ghostnet +import torch.npu + +# modelarts modification +import moxing as mox + +CALCULATE_DEVICE = "npu:0" + +try: + from apex import amp + from apex.parallel import DistributedDataParallel as ApexDDP + from apex.parallel import convert_syncbn_model + + has_apex = True +except ImportError: + has_apex = False + +has_native_amp = False +try: + if getattr(torch.cuda.amp, 'autocast') is not None: + has_native_amp = True +except AttributeError: + pass + +torch.backends.cudnn.benchmark = True +_logger = logging.getLogger('train') + +# The first arg parser parses out only the --config argument, this argument is used to +# load a yaml file containing key-values that override the defaults for the main parser below +config_parser = parser = argparse.ArgumentParser(description='Training Config', add_help=False) +parser.add_argument('-c', '--config', default='', type=str, metavar='FILE', + help='YAML config file specifying default arguments') +parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') +# Dataset / Model parameters +parser.add_argument('data_dir', metavar='DIR', + help='path to dataset') +parser.add_argument('--dataset', '-d', metavar='NAME', default='', + help='dataset type (default: ImageFolder/ImageTar if empty)') +parser.add_argument('--train-split', metavar='NAME', default='train', + help='dataset train split (default: train)') +parser.add_argument('--val-split', metavar='NAME', default='validation', + help='dataset validation split (default: validation)') +parser.add_argument('--model', default='resnet101', type=str, metavar='MODEL', + help='Name of model to train (default: "countception"') +parser.add_argument('--pretrained', action='store_true', default=False, + help='Start with pretrained version of specified network (if avail)') +parser.add_argument('--initial-checkpoint', default='', type=str, metavar='PATH', + help='Initialize model from this checkpoint (default: none)') +parser.add_argument('--resume', default='', type=str, metavar='PATH', + help='Resume full model and optimizer state from checkpoint (default: none)') +parser.add_argument('--no-resume-opt', action='store_true', default=False, + help='prevent resume of optimizer state when resuming model') +parser.add_argument('--num-classes', type=int, default=None, metavar='N', + help='number of label classes (Model default if None)') +parser.add_argument('--gp', default=None, type=str, metavar='POOL', + help='Global pool type, one of (fast, avg, max, avgmax, avgmaxc). Model default if None.') +parser.add_argument('--img-size', type=int, default=None, metavar='N', + help='Image patch size (default: None => model default)') +parser.add_argument('--input-size', default=None, nargs=3, type=int, + metavar='N N N', + help='Input all image dimensions (d h w, e.g. --input-size 3 224 224), uses model default if empty') +parser.add_argument('--crop-pct', default=None, type=float, + metavar='N', help='Input image center crop percent (for validation only)') +parser.add_argument('--mean', type=float, nargs='+', default=None, metavar='MEAN', + help='Override mean pixel value of dataset') +parser.add_argument('--std', type=float, nargs='+', default=None, metavar='STD', + help='Override std deviation of of dataset') +parser.add_argument('--interpolation', default='', type=str, metavar='NAME', + help='Image resize interpolation type (overrides model)') +parser.add_argument('-b', '--batch-size', type=int, default=1024, metavar='N', + help='input batch size for training (default: 32)') +parser.add_argument('-vb', '--validation-batch-size-multiplier', type=int, default=1, metavar='N', + help='ratio of validation batch size to training batch size (default: 1)') + +# Optimizer parameters +parser.add_argument('--opt', default='sgd', type=str, metavar='OPTIMIZER', + help='Optimizer (default: "sgd"') +parser.add_argument('--opt-eps', default=None, type=float, metavar='EPSILON', + help='Optimizer Epsilon (default: None, use opt default)') +parser.add_argument('--opt-betas', default=None, type=float, nargs='+', metavar='BETA', + help='Optimizer Betas (default: None, use opt default)') +parser.add_argument('--momentum', type=float, default=0.9, metavar='M', + help='Optimizer momentum (default: 0.9)') +parser.add_argument('--weight-decay', type=float, default=0.0001, + help='weight decay (default: 0.0001)') +parser.add_argument('--clip-grad', type=float, default=None, metavar='NORM', + help='Clip gradient norm (default: None, no clipping)') + +# Learning rate schedule parameters +parser.add_argument('--sched', default='step', type=str, metavar='SCHEDULER', + help='LR scheduler (default: "step"') +parser.add_argument('--lr', type=float, default=0.4, metavar='LR', + help='learning rate (default: 0.01)') +parser.add_argument('--lr-noise', type=float, nargs='+', default=None, metavar='pct, pct', + help='learning rate noise on/off epoch percentages') +parser.add_argument('--lr-noise-pct', type=float, default=0.67, metavar='PERCENT', + help='learning rate noise limit percent (default: 0.67)') +parser.add_argument('--lr-noise-std', type=float, default=1.0, metavar='STDDEV', + help='learning rate noise std-dev (default: 1.0)') +parser.add_argument('--lr-cycle-mul', type=float, default=1.0, metavar='MULT', + help='learning rate cycle len multiplier (default: 1.0)') +parser.add_argument('--lr-cycle-limit', type=int, default=1, metavar='N', + help='learning rate cycle limit') +parser.add_argument('--warmup-lr', type=float, default=0.0001, metavar='LR', + help='warmup learning rate (default: 0.0001)') +parser.add_argument('--min-lr', type=float, default=1e-5, metavar='LR', + help='lower lr bound for cyclic schedulers that hit 0 (1e-5)') +parser.add_argument('--epochs', type=int, default=200, metavar='N', + help='number of epochs to train (default: 2)') +parser.add_argument('--start-epoch', default=None, type=int, metavar='N', + help='manual epoch number (useful on restarts)') +parser.add_argument('--decay-epochs', type=float, default=30, metavar='N', + help='epoch interval to decay LR') +parser.add_argument('--warmup-epochs', type=int, default=3, metavar='N', + help='epochs to warmup LR, if scheduler supports') +parser.add_argument('--cooldown-epochs', type=int, default=0, metavar='N', + help='epochs to cooldown LR at min_lr, after cyclic schedule ends') +parser.add_argument('--patience-epochs', type=int, default=0, metavar='N', + help='patience epochs for Plateau LR scheduler (default: 10') +parser.add_argument('--decay-rate', '--dr', type=float, default=0.1, metavar='RATE', + help='LR decay rate (default: 0.1)') + +# Augmentation & regularization parameters +parser.add_argument('--no-aug', action='store_true', default=False, + help='Disable all training augmentation, override other train aug args') +parser.add_argument('--scale', type=float, nargs='+', default=[0.08, 1.0], metavar='PCT', + help='Random resize scale (default: 0.08 1.0)') +parser.add_argument('--ratio', type=float, nargs='+', default=[3. / 4., 4. / 3.], metavar='RATIO', + help='Random resize aspect ratio (default: 0.75 1.33)') +parser.add_argument('--hflip', type=float, default=0.5, + help='Horizontal flip training aug probability') +parser.add_argument('--vflip', type=float, default=0., + help='Vertical flip training aug probability') +parser.add_argument('--color-jitter', type=float, default=0.4, metavar='PCT', + help='Color jitter factor (default: 0.4)') +parser.add_argument('--aug-splits', type=int, default=0, + help='Number of augmentation splits (default: 0, valid: 0 or >=2)') +parser.add_argument('--jsd', action='store_true', default=False, + help='Enable Jensen-Shannon Divergence + CE loss. Use with `--aug-splits`.') +parser.add_argument('--recount', type=int, default=1, + help='Random erase count (default: 1)') +parser.add_argument('--resplit', action='store_true', default=False, + help='Do not random erase first (clean) augmentation split') +parser.add_argument('--mixup', type=float, default=0.0, + help='mixup alpha, mixup enabled if > 0. (default: 0.)') +parser.add_argument('--cutmix', type=float, default=0.0, + help='cutmix alpha, cutmix enabled if > 0. (default: 0.)') +parser.add_argument('--cutmix-minmax', type=float, nargs='+', default=None, + help='cutmix min/max ratio, overrides alpha and enables cutmix if set (default: None)') +parser.add_argument('--mixup-prob', type=float, default=1.0, + help='Probability of performing mixup or cutmix when either/both is enabled') +parser.add_argument('--mixup-switch-prob', type=float, default=0.5, + help='Probability of switching to cutmix when both mixup and cutmix enabled') +parser.add_argument('--mixup-mode', type=str, default='batch', + help='How to apply mixup/cutmix params. Per "batch", "pair", or "elem"') +parser.add_argument('--mixup-off-epoch', default=0, type=int, metavar='N', + help='Turn off mixup after this epoch, disabled if 0 (default: 0)') +parser.add_argument('--smoothing', type=float, default=0.1, + help='Label smoothing (default: 0.1)') +parser.add_argument('--train-interpolation', type=str, default='random', + help='Training interpolation (random, bilinear, bicubic default: "random")') +parser.add_argument('--drop', type=float, default=0.2, metavar='PCT', + help='Dropout rate (default: 0.)') +parser.add_argument('--drop-path', type=float, default=None, metavar='PCT', + help='Drop path rate (default: None)') +parser.add_argument('--drop-block', type=float, default=None, metavar='PCT', + help='Drop block rate (default: None)') +parser.add_argument('--bn-tf', action='store_true', default=False, + help='Use Tensorflow BatchNorm defaults for models that support it (default: False)') +parser.add_argument('--bn-momentum', type=float, default=None, + help='BatchNorm momentum override (if not None)') +parser.add_argument('--bn-eps', type=float, default=None, + help='BatchNorm epsilon override (if not None)') +parser.add_argument('--sync-bn', action='store_true', + help='Enable NVIDIA Apex or Torch synchronized BatchNorm.') +parser.add_argument('--dist-bn', type=str, default='', + help='Distribute BatchNorm stats between nodes after each epoch ("broadcast", "reduce", or "")') +parser.add_argument('--split-bn', action='store_true', + help='Enable separate BN layers per augmentation split.') +# Misc +parser.add_argument('--seed', type=int, default=42, metavar='S', + help='random seed (default: 42)') +parser.add_argument('--log-interval', type=int, default=50, metavar='N', + help='how many batches to wait before logging training status') +parser.add_argument('--recovery-interval', type=int, default=0, metavar='N', + help='how many batches to wait before writing recovery checkpoint') +parser.add_argument('--checkpoint-hist', type=int, default=10, metavar='N', + help='number of checkpoints to keep (default: 10)') +parser.add_argument('-j', '--workers', type=int, default=4, metavar='N', + help='how many training processes to use (default: 1)') +parser.add_argument('--save-images', action='store_true', default=False, + help='save images of input bathes every log interval for debugging') +parser.add_argument('--amp', action='store_true', default=False, + help='use NVIDIA Apex AMP or Native AMP for mixed precision training') +parser.add_argument('--apex-amp', action='store_true', default=False, + help='Use NVIDIA Apex AMP mixed precision') +parser.add_argument('--native-amp', action='store_true', default=False, + help='Use Native Torch AMP mixed precision') +parser.add_argument('--channels-last', action='store_true', default=False, + help='Use channels_last memory layout') +parser.add_argument('--pin-mem', action='store_true', default=False, + help='Pin CPU memory in DataLoader for more efficient (sometimes) transfer to GPU.') +parser.add_argument('--no-prefetcher', action='store_true', default=True, + help='disable fast prefetcher') +parser.add_argument('--output', default='', type=str, metavar='PATH', + help='path to output folder (default: none, current dir)') +parser.add_argument('--eval-metric', default='top1', type=str, metavar='EVAL_METRIC', + help='Best metric (default: "top1"') +parser.add_argument('--tta', type=int, default=0, metavar='N', + help='Test/inference time augmentation (oversampling) factor. 0=None (default: 0)') +parser.add_argument("--local_rank", default=0, type=int) +parser.add_argument('--use-multi-epochs-loader', action='store_true', default=False, + help='use the multi-epochs-loader to save time at the beginning of every epoch') +parser.add_argument('--torchscript', dest='torchscript', action='store_true', + help='convert model torchscript for inference') +parser.add_argument('--width', type=float, default=1.0, + help='Width ratio (default: 1.0)') +parser.add_argument('--dist-url', default='tcp://127.0.0.1:50000', type=str, + help='url used to set up pretained training') +parser.add_argument('--dist-backend', default='nccl', type=str, + help='distributed backend') +parser.add_argument('--npu', default=None, type=int, + help='NPU id to use.') +#modelarts +parser.add_argument('--modelarts_mod', action='store_true', default=False, + help='Enable modelarts mode loss function to train') +parser.add_argument('--train_url', + default="/cache/training", + type=str, + help="setting dir of training output") +parser.add_argument('--pretrained_weight', default='', type=str, metavar='PATH', + help='path to pretrained weight') +parser.add_argument('--onnx', default=True, action='store_true', + help="convert pth model to onnx") +parser.add_argument('--data_url', + type=str, + default='/cache/data_url', + help='the training data') + +CACHE_TRAINING_URL = "/cache/training" +def _parse_args(): + # Do we have a config file to parse? + args_config, remaining = config_parser.parse_known_args() + if args_config.config: + with open(args_config.config, 'r') as f: + cfg = yaml.safe_load(f) + parser.set_defaults(**cfg) + # The main arg parser parses the rest of the args, the usual + # defaults will have been overridden if config file specified. + args = parser.parse_args(remaining) + print(args) + # Cache the args as a text string to save them in the output dir later + args_text = yaml.safe_dump(args.__dict__, default_flow_style=False) + return args, args_text + + +def main(): + setup_default_logging() + args, args_text = _parse_args() + + args.prefetcher = not args.no_prefetcher + args.distributed = False + if args.npu is None: + args.npu = 0 + CALCULATE_DEVICE = "npu:{}".format(args.npu) + torch.npu.set_device(CALCULATE_DEVICE) + print("use ", CALCULATE_DEVICE) + + if 'WORLD_SIZE' in os.environ: + args.distributed = int(os.environ['WORLD_SIZE']) > 1 + args.device = 'npu:0' + args.world_size = 1 + args.rank = 0 # global rank + _logger.info('Training with a single process on 1 NPUs.') + assert args.rank >= 0 + + # resolve AMP arguments based on PyTorch / Apex availability + use_amp = None + if args.amp: + # for backwards compat, `--amp` arg tries apex before native amp + if has_apex: + args.apex_amp = True + elif has_native_amp: + args.native_amp = True + if args.apex_amp and has_apex: + use_amp = 'apex' + elif args.native_amp and has_native_amp: + use_amp = 'native' + elif args.apex_amp or args.native_amp: + _logger.warning("Neither APEX or native Torch AMP is available, using float32. " + "Install NVIDA apex or upgrade to PyTorch 1.6") + + torch.manual_seed(args.seed + args.rank) + model = ghostnet(num_classes=args.num_classes, width=args.width, dropout=args.drop) + + if args.pretrained: + CACHE_MODEL_URL = "/cache/model" + os.makedirs(CACHE_MODEL_URL, exist_ok=True) + mox.file.copy_parallel(args.pretrained_weight, os.path.join(CACHE_MODEL_URL, "model_best.pth.tar")) + pretrained_weight = os.path.join(CACHE_MODEL_URL, "model_best.pth.tar") + pretrained_dict = torch.load(pretrained_weight)["state_dict"] + pretrained_model = {k.replace('module.', ''): v for k, v in pretrained_dict.items()} + if "classifier.weight" in pretrained_model: + pretrained_model.pop('classifier.weight') + pretrained_model.pop('classifier.bias') + model.load_state_dict(pretrained_model, strict=False) + + for param in model.parameters(): + param.requires_grad = False + + for param in model.classifier.parameters(): + param.requires_grad = True + + if args.num_classes is None: + assert hasattr(model, 'num_classes'), 'Model must have `num_classes` attr if not set on cmd line/config.' + args.num_classes = model.num_classes # FIXME handle model default vs config num_classes more elegantly + + if args.local_rank == 0: + _logger.info('Model %s created, param count: %d' % + (args.model, sum([m.numel() for m in model.parameters()]))) + + data_config = resolve_data_config(vars(args), model=model, verbose=args.local_rank == 0) + + # setup augmentation batch splits for contrastive loss or split bn + num_aug_splits = 0 + if args.aug_splits > 0: + assert args.aug_splits > 1, 'A split of 1 makes no sense' + num_aug_splits = args.aug_splits + + # enable split bn (separate bn stats per batch-portion) + if args.split_bn: + assert num_aug_splits > 1 or args.resplit + model = convert_splitbn_model(model, max(num_aug_splits, 2)) + + # move model to GPU, enable channels last layout if set + model = model.to(CALCULATE_DEVICE) + if args.channels_last: + model = model.to(memory_format=torch.channels_last) + + if args.torchscript: + assert not use_amp == 'apex', 'Cannot use APEX AMP with torchscripted model' + assert not args.sync_bn, 'Cannot use SyncBatchNorm with torchscripted model' + model = torch.jit.script(model) + + optimizer = create_optimizer(args, model) + + # setup automatic mixed-precision (AMP) loss scaling and op casting + amp_autocast = suppress # do nothing + loss_scaler = None + if use_amp == 'apex': + model, optimizer = amp.initialize(model, optimizer, opt_level='O2', loss_scale=128) + loss_scaler = ApexScaler() + if args.local_rank == 0: + _logger.info('Using NVIDIA APEX AMP. Training in mixed precision.') + elif use_amp == 'native': + amp_autocast = torch.cuda.amp.autocast + loss_scaler = NativeScaler() + if args.local_rank == 0: + _logger.info('Using native Torch AMP. Training in mixed precision.') + else: + if args.local_rank == 0: + _logger.info('AMP not enabled. Training in float32.') + + # optionally resume from a checkpoint + resume_epoch = None + if args.resume: + resume_epoch = resume_checkpoint( + model, args.resume, + optimizer=None if args.no_resume_opt else optimizer, + loss_scaler=None if args.no_resume_opt else loss_scaler, + log_info=args.local_rank == 0) + + # setup exponential moving average of model weights, SWA could be used here too + model_ema = None + # setup learning rate schedule and starting epoch + lr_scheduler, num_epochs = create_scheduler(args, optimizer) + start_epoch = 0 + if args.start_epoch is not None: + # a specified start_epoch will always override the resume epoch + start_epoch = args.start_epoch + elif resume_epoch is not None: + start_epoch = resume_epoch + if lr_scheduler is not None and start_epoch > 0: + lr_scheduler.step(start_epoch) + + if args.local_rank == 0: + _logger.info('Scheduled epochs: {}'.format(num_epochs)) + + # create the train and eval datasets + real_path = '/cache/data_url' + if not os.path.exists(real_path): + os.makedirs(real_path) + mox.file.copy_parallel(args.data_url, real_path) + print("training data finish copy to %s." % real_path) + dataset_train = create_dataset( + args.dataset, root=real_path, split=args.train_split, is_training=True, batch_size=args.batch_size) + dataset_eval = create_dataset( + args.dataset, root=real_path, split=args.val_split, is_training=False, batch_size=args.batch_size) + # setup mixup / cutmix + collate_fn = None + mixup_fn = None + mixup_active = args.mixup > 0 or args.cutmix > 0. or args.cutmix_minmax is not None + if mixup_active: + mixup_args = dict( + mixup_alpha=args.mixup, cutmix_alpha=args.cutmix, cutmix_minmax=args.cutmix_minmax, + prob=args.mixup_prob, switch_prob=args.mixup_switch_prob, mode=args.mixup_mode, + label_smoothing=args.smoothing, num_classes=args.num_classes) + if args.prefetcher: + assert not num_aug_splits # collate conflict (need to support deinterleaving in collate mixup) + collate_fn = FastCollateMixup(**mixup_args) + else: + mixup_fn = Mixup(**mixup_args) + + # wrap dataset in AugMix helper + if num_aug_splits > 1: + dataset_train = AugMixDataset(dataset_train, num_splits=num_aug_splits) + + # create data loaders w/ augmentation pipeiine + train_interpolation = args.train_interpolation + if args.no_aug or not train_interpolation: + train_interpolation = data_config['interpolation'] + loader_train = create_loader( + dataset_train, + input_size=data_config['input_size'], + batch_size=args.batch_size, + is_training=True, + use_prefetcher=not args.no_prefetcher, + no_aug=args.no_aug, + re_count=args.recount, + re_split=args.resplit, + scale=args.scale, + ratio=args.ratio, + hflip=args.hflip, + vflip=args.vflip, + color_jitter=args.color_jitter, + num_aug_splits=num_aug_splits, + interpolation=train_interpolation, + mean=data_config['mean'], + std=data_config['std'], + num_workers=args.workers, + collate_fn=collate_fn, + pin_memory=args.pin_mem, + use_multi_epochs_loader=args.use_multi_epochs_loader + ) + + loader_eval = create_loader( + dataset_eval, + input_size=data_config['input_size'], + batch_size=args.validation_batch_size_multiplier * args.batch_size, + is_training=False, + use_prefetcher=not args.no_prefetcher, + interpolation=data_config['interpolation'], + mean=data_config['mean'], + std=data_config['std'], + num_workers=args.workers, + crop_pct=data_config['crop_pct'], + pin_memory=args.pin_mem, + ) + + # setup loss function + if args.jsd: + #assert num_aug_splits > 1 # JSD only valid with aug splits set + train_loss_fn = JsdCrossEntropy(num_splits=num_aug_splits, smoothing=args.smoothing).to(CALCULATE_DEVICE) + elif mixup_active: + # smoothing is handled with mixup target transform + train_loss_fn = SoftTargetCrossEntropy().to(CALCULATE_DEVICE) + elif args.smoothing: + train_loss_fn = LabelSmoothingCrossEntropy(smoothing=args.smoothing).to(CALCULATE_DEVICE) + else: + train_loss_fn = nn.CrossEntropyLoss().to(CALCULATE_DEVICE) + if args.modelarts_mod: + train_loss_fn = nn.CrossEntropyLoss().to(CALCULATE_DEVICE) + + validate_loss_fn = nn.CrossEntropyLoss().to(CALCULATE_DEVICE) + # setup checkpoint saver and eval metric tracking + eval_metric = args.eval_metric + best_metric = None + best_epoch = None + saver = None + output_dir = '' + if args.local_rank == 0: + output_base = args.output if args.output else './output' + exp_name = '-'.join([ + datetime.now().strftime("%Y%m%d-%H%M%S"), + args.model, + str(data_config['input_size'][-1]) + ]) + output_dir = get_outdir(output_base, 'train', exp_name) + decreasing = True if eval_metric == 'loss' else False + saver = CheckpointSaver( + model=model, optimizer=optimizer, args=args, amp_scaler=loss_scaler, + checkpoint_dir=output_dir, recovery_dir=output_dir, decreasing=decreasing, max_history=args.checkpoint_hist) + + with open(os.path.join(output_dir, 'args.yaml'), 'w') as f: + f.write(args_text) + + try: + for epoch in range(start_epoch, num_epochs): + + train_metrics = train_one_epoch( + epoch, model, loader_train, optimizer, train_loss_fn, args, + lr_scheduler=lr_scheduler, saver=saver, output_dir=output_dir, + amp_autocast=amp_autocast, loss_scaler=loss_scaler, mixup_fn=mixup_fn) + + eval_metrics = validate(model, loader_eval, validate_loss_fn, args, amp_autocast=amp_autocast) + + if lr_scheduler is not None: + # step LR for next epoch + lr_scheduler.step(epoch + 1, eval_metrics[eval_metric]) + + update_summary( + epoch, train_metrics, eval_metrics, os.path.join(output_dir, 'summary.csv'), + write_header=best_metric is None) + + if saver is not None: + # save proper checkpoint with eval metric + save_metric = eval_metrics[eval_metric] + best_metric, best_epoch = saver.save_checkpoint(epoch, metric=save_metric) + + except KeyboardInterrupt: + pass + if best_metric is not None: + _logger.info('*** Best metric: {0} (epoch {1})'.format(best_metric, best_epoch)) + + if args.onnx: + os.makedirs(CACHE_TRAINING_URL, exist_ok=True) + print("abspath:",os.path.abspath(output_dir)) + print("output_dir:",os.listdir(output_dir)) + shutil.copy(os.path.join(os.path.abspath(output_dir), 'model_best.pth.tar'), CACHE_TRAINING_URL) + pth_pattern = os.path.join(CACHE_TRAINING_URL, 'model_best.pth.tar') + print("pth_pattern:",os.path.abspath(pth_pattern)) + pth_file_list = glob.glob(pth_pattern) + if not pth_file_list: + print(f"can't find pth {pth_pattern}") + pth_file = pth_file_list[0] + onnx_path = pth_file.split(".")[0] + '.onnx' + convert(pth_file, onnx_path) + # --------------modelarts modification---------- + mox.file.copy_parallel(CACHE_TRAINING_URL, args.train_url) + # --------------modelarts modification end---------- + print("CACHE_TRAINING_URL:",os.listdir(CACHE_TRAINING_URL)) + +def train_one_epoch( + epoch, model, loader, optimizer, loss_fn, args, + lr_scheduler=None, saver=None, output_dir='', amp_autocast=suppress, + loss_scaler=None, mixup_fn=None): + if args.mixup_off_epoch and epoch >= args.mixup_off_epoch: + if args.prefetcher and loader.mixup_enabled: + loader.mixup_enabled = False + elif mixup_fn is not None: + mixup_fn.mixup_enabled = False + + second_order = hasattr(optimizer, 'is_second_order') and optimizer.is_second_order + batch_time_m = AverageMeter() + data_time_m = AverageMeter() + losses_m = AverageMeter(start_count_index=0) + + model.train() + + end = time.time() + last_idx = len(loader) - 1 + num_updates = epoch * len(loader) + for batch_idx, (input, target) in enumerate(loader): + last_batch = batch_idx == last_idx + data_time_m.update(time.time() - end) + if not args.prefetcher: + input, target = input.npu(), target.npu() + if mixup_fn is not None: + input, target = mixup_fn(input, target) + if args.channels_last: + input = input.contiguous(memory_format=torch.channels_last) + + with amp_autocast(): + output = model(input) + target = target.to(torch.int32) + loss = loss_fn(output, target) + + losses_m.update(loss.item(), input.size(0)) + + optimizer.zero_grad() + if loss_scaler is not None: + loss_scaler( + loss, optimizer, clip_grad=args.clip_grad, parameters=model.parameters(), create_graph=second_order) + else: + loss.backward(create_graph=second_order) + if args.clip_grad is not None: + torch.nn.utils.clip_grad_norm_(model.parameters(), args.clip_grad) + optimizer.step() + + num_updates += 1 + batch_time_m.update(time.time() - end) + if last_batch or batch_idx % args.log_interval == 0: + lrl = [param_group['lr'] for param_group in optimizer.param_groups] + lr = sum(lrl) / len(lrl) + + if args.local_rank == 0: + if batch_time_m.avg > 0: + _logger.info( + 'Train: {} [{:>4d}/{} ({:>3.0f}%)] ' + 'Loss: {loss.val:>9.6f} ({loss.avg:>6.4f}) ' + 'Time: {batch_time.val:.3f}s, {rate:>7.2f}/s ' + '({batch_time.avg:.3f}s, {rate_avg:>7.2f}/s) ' + 'LR: {lr:.3e} ' + 'Data: {data_time.val:.3f} ({data_time.avg:.3f})' + 'fps: {fps:.3f} ' + 'Batch_Size:{batch_size:.1f} '.format( + epoch, + batch_idx, len(loader), + 100. * batch_idx / last_idx, + loss=losses_m, + batch_time=batch_time_m, + rate=input.size(0) * args.world_size / batch_time_m.val, + rate_avg=input.size(0) * args.world_size / batch_time_m.avg, + lr=lr, + data_time=data_time_m, + fps=args.batch_size / batch_time_m.avg, + batch_size=args.batch_size)) + + if args.save_images and output_dir: + torchvision.utils.save_image( + input, + os.path.join(output_dir, 'train-batch-%d.jpg' % batch_idx), + padding=0, + normalize=True) + + if saver is not None and args.recovery_interval and ( + last_batch or (batch_idx + 1) % args.recovery_interval == 0): + saver.save_recovery(epoch, batch_idx=batch_idx) + + if lr_scheduler is not None: + lr_scheduler.step_update(num_updates=num_updates, metric=losses_m.avg) + + end = time.time() + # end for + + if hasattr(optimizer, 'sync_lookahead'): + optimizer.sync_lookahead() + + return OrderedDict([('loss', losses_m.avg)]) + + +def validate(model, loader, loss_fn, args, amp_autocast=suppress, log_suffix=''): + batch_time_m = AverageMeter() + losses_m = AverageMeter(start_count_index=0) + top1_m = AverageMeter(start_count_index=0) + top5_m = AverageMeter(start_count_index=0) + model.eval() + + end = time.time() + last_idx = len(loader) - 1 + with torch.no_grad(): + for batch_idx, (input, target) in enumerate(loader): + last_batch = batch_idx == last_idx + if args.no_prefetcher: + input = input.npu() + target = target.npu() + if args.channels_last: + input = input.contiguous(memory_format=torch.channels_last) + + with amp_autocast(): + output = model(input) + if isinstance(output, (tuple, list)): + output = output[0] + + # augmentation reduction + reduce_factor = args.tta + if reduce_factor > 1: + output = output.unfold(0, reduce_factor, reduce_factor).mean(dim=2) + target = target[0:target.size(0):reduce_factor] + + target = target.to(torch.int32) + loss = loss_fn(output, target) + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + + reduced_loss = loss.data + + losses_m.update(reduced_loss.item(), input.size(0)) + top1_m.update(acc1.item(), output.size(0)) + top5_m.update(acc5.item(), output.size(0)) + + batch_time_m.update(time.time() - end) + end = time.time() + if args.local_rank == 0 and (last_batch or batch_idx % args.log_interval == 0): + if batch_time_m.avg > 0: + log_name = 'Test' + log_suffix + _logger.info( + '{0}: [{1:>4d}/{2}] ' + 'Time: {batch_time.val:.3f} ({batch_time.avg:.3f}) ' + 'Loss: {loss.val:>7.4f} ({loss.avg:>6.4f}) ' + 'Acc@1: {top1.val:>7.4f} ({top1.avg:>7.4f}) ' + 'Acc@5: {top5.val:>7.4f} ({top5.avg:>7.4f})' + 'fps: {fps:.3f} ' + 'Batch_Size:{batch_size:.1f} '.format( + log_name, batch_idx, last_idx, batch_time=batch_time_m, + loss=losses_m, top1=top1_m, top5=top5_m, fps=args.batch_size / batch_time_m.avg, + batch_size=args.batch_size)) + + metrics = OrderedDict([('loss', losses_m.avg), ('top1', top1_m.avg), ('top5', top5_m.avg)]) + + return metrics + +def proc_node_module(checkpoint, attr_name): + new_model_state = OrderedDict() + for k, v in checkpoint[attr_name].items(): + if(k[0: 7] == "module."): + name = k[7:] + else: + name = k[0:] + new_model_state[name] = v + return new_model_state + +def convert(pth_file_path, onnx_file_path): + args, args_text = _parse_args() + checkpoint = torch.load(pth_file_path, map_location='cpu') + checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') + model = ghostnet(num_classes=args.num_classes, width=args.width, dropout=args.drop) + model.load_state_dict(checkpoint['state_dict'], False) + model.eval() + + input_names = ["image"] + output_names = ["output1"] + dummy_input = torch.randn(2, 3, 224, 224) + torch.onnx.export(model, dummy_input, onnx_file_path, input_names=input_names, output_names=output_names, opset_version=11) + +if __name__ == '__main__': + main() + diff --git a/PyTorch/contrib/cv/classification/GhostNet/pthtar2onx.py b/PyTorch/contrib/cv/classification/GhostNet/pthtar2onx.py index bada64a75e5dc83e8a519293c46053c60c009c84..5d6c9459ad130b15514084e23def49b2aa70c06b 100644 --- a/PyTorch/contrib/cv/classification/GhostNet/pthtar2onx.py +++ b/PyTorch/contrib/cv/classification/GhostNet/pthtar2onx.py @@ -1,47 +1,47 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import torch -import torch.onnx - -from collections import OrderedDict -from ghostnet.ghostnet_pytorch.ghostnet import ghostnet - -def proc_nodes_module(checkpoint, AttrName): - new_state_dict = OrderedDict() - for k, v in checkpoint[AttrName].items(): - if (k[0:7] == "module."): - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - -def convert(): - checkpoint = torch.load("model_best.pth.tar", map_location='cpu') - checkpoint['state_dict'] = proc_nodes_module(checkpoint, 'state_dict') - - model = ghostnet() - model.load_state_dict(checkpoint['state_dict'], strict=False) - model.eval() - - input_names = ["image"] - output_names = ["output1"] - dummy_input = torch.randn(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, "ghostnet_b.onnx", input_names=input_names, output_names=output_names, opset_version=11) - - -if __name__ == "__main__": - convert() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import torch +import torch.onnx + +from collections import OrderedDict +from ghostnet.ghostnet_pytorch.ghostnet import ghostnet + +def proc_nodes_module(checkpoint, AttrName): + new_state_dict = OrderedDict() + for k, v in checkpoint[AttrName].items(): + if (k[0:7] == "module."): + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + +def convert(): + checkpoint = torch.load("model_best.pth.tar", map_location='cpu') + checkpoint['state_dict'] = proc_nodes_module(checkpoint, 'state_dict') + + model = ghostnet() + model.load_state_dict(checkpoint['state_dict'], strict=False) + model.eval() + + input_names = ["image"] + output_names = ["output1"] + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, "ghostnet_b.onnx", input_names=input_names, output_names=output_names, opset_version=11) + + +if __name__ == "__main__": + convert() diff --git a/PyTorch/contrib/cv/classification/GhostNet/requirements.txt b/PyTorch/contrib/cv/classification/GhostNet/requirements.txt index 30a76bac06b0edf95756ac1d337bbd951967cf40..2d29a27ced7a4e86323fada114fb2dfa7157dd2a 100644 --- a/PyTorch/contrib/cv/classification/GhostNet/requirements.txt +++ b/PyTorch/contrib/cv/classification/GhostNet/requirements.txt @@ -1,3 +1,3 @@ -torch>=1.4.0 -torchvision>=0.5.0 -pyyaml +torch>=1.4.0 +torchvision>=0.5.0 +pyyaml diff --git a/PyTorch/contrib/cv/classification/GhostNet/setup.cfg b/PyTorch/contrib/cv/classification/GhostNet/setup.cfg index b1ddcb2b793f98f4995bcb47b130f1c5d8a69f7f..6289c6c3a16da8a53297b8aa7b59a85277b5116e 100644 --- a/PyTorch/contrib/cv/classification/GhostNet/setup.cfg +++ b/PyTorch/contrib/cv/classification/GhostNet/setup.cfg @@ -1,5 +1,5 @@ -[dist_conda] - -conda_name_differences = 'torch:pytorch' -channels = pytorch -noarch = True +[dist_conda] + +conda_name_differences = 'torch:pytorch' +channels = pytorch +noarch = True diff --git a/PyTorch/contrib/cv/classification/GhostNet/setup.py b/PyTorch/contrib/cv/classification/GhostNet/setup.py index d0a9cfba3c9b18aad53a3a648c3c3af3c95e791b..882ed467a35a73aa99239d50eedea9c6cb7ce2fb 100644 --- a/PyTorch/contrib/cv/classification/GhostNet/setup.py +++ b/PyTorch/contrib/cv/classification/GhostNet/setup.py @@ -1,48 +1,48 @@ -""" Setup -""" -from setuptools import setup, find_packages -from codecs import open -from os import path - -here = path.abspath(path.dirname(__file__)) - -# Get the long description from the README file -with open(path.join(here, 'README.md'), encoding='utf-8') as f: - long_description = f.read() - -exec(open('timm/version.py').read()) -setup( - name='timm', - version=__version__, - description='(Unofficial) PyTorch Image Models', - long_description=long_description, - long_description_content_type='text/markdown', - url='https://github.com/rwightman/pytorch-image-models', - author='Ross Wightman', - author_email='hello@rwightman.com', - classifiers=[ - # How mature is this project? Common values are - # 3 - Alpha - # 4 - Beta - # 5 - Production/Stable - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Education', - 'Intended Audience :: Science/Research', - 'License :: OSI Approved :: Apache Software License', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Topic :: Scientific/Engineering', - 'Topic :: Scientific/Engineering :: Artificial Intelligence', - 'Topic :: Software Development', - 'Topic :: Software Development :: Libraries', - 'Topic :: Software Development :: Libraries :: Python Modules', - ], - - # Note that this is a string of words separated by whitespace, not a list. - keywords='pytorch pretrained models efficientnet mobilenetv3 mnasnet', - packages=find_packages(exclude=['convert', 'tests', 'results']), - include_package_data=True, - install_requires=['torch >= 1.4', 'torchvision'], - python_requires='>=3.6', -) +""" Setup +""" +from setuptools import setup, find_packages +from codecs import open +from os import path + +here = path.abspath(path.dirname(__file__)) + +# Get the long description from the README file +with open(path.join(here, 'README.md'), encoding='utf-8') as f: + long_description = f.read() + +exec(open('timm/version.py').read()) +setup( + name='timm', + version=__version__, + description='(Unofficial) PyTorch Image Models', + long_description=long_description, + long_description_content_type='text/markdown', + url='https://github.com/rwightman/pytorch-image-models', + author='Ross Wightman', + author_email='hello@rwightman.com', + classifiers=[ + # How mature is this project? Common values are + # 3 - Alpha + # 4 - Beta + # 5 - Production/Stable + 'Development Status :: 3 - Alpha', + 'Intended Audience :: Education', + 'Intended Audience :: Science/Research', + 'License :: OSI Approved :: Apache Software License', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Topic :: Scientific/Engineering', + 'Topic :: Scientific/Engineering :: Artificial Intelligence', + 'Topic :: Software Development', + 'Topic :: Software Development :: Libraries', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], + + # Note that this is a string of words separated by whitespace, not a list. + keywords='pytorch pretrained models efficientnet mobilenetv3 mnasnet', + packages=find_packages(exclude=['convert', 'tests', 'results']), + include_package_data=True, + install_requires=['torch >= 1.4', 'torchvision'], + python_requires='>=3.6', +) diff --git a/PyTorch/contrib/cv/classification/GhostNet/timm/loss/asymmetric_loss.py b/PyTorch/contrib/cv/classification/GhostNet/timm/loss/asymmetric_loss.py index 96a977882b9fa534990bfb1c8321e4c822c602ca..a8b10f9c797c2cb3b2652302717b592dada216f3 100644 --- a/PyTorch/contrib/cv/classification/GhostNet/timm/loss/asymmetric_loss.py +++ b/PyTorch/contrib/cv/classification/GhostNet/timm/loss/asymmetric_loss.py @@ -1,97 +1,97 @@ -import torch -import torch.nn as nn - - -class AsymmetricLossMultiLabel(nn.Module): - def __init__(self, gamma_neg=4, gamma_pos=1, clip=0.05, eps=1e-8, disable_torch_grad_focal_loss=False): - super(AsymmetricLossMultiLabel, self).__init__() - - self.gamma_neg = gamma_neg - self.gamma_pos = gamma_pos - self.clip = clip - self.disable_torch_grad_focal_loss = disable_torch_grad_focal_loss - self.eps = eps - - def forward(self, x, y): - """" - Parameters - ---------- - x: input logits - y: targets (multi-label binarized vector) - """ - - # Calculating Probabilities - x_sigmoid = torch.sigmoid(x) - xs_pos = x_sigmoid - xs_neg = 1 - x_sigmoid - - # Asymmetric Clipping - if self.clip is not None and self.clip > 0: - xs_neg = (xs_neg + self.clip).clamp(max=1) - - # Basic CE calculation - los_pos = y * torch.log(xs_pos.clamp(min=self.eps)) - los_neg = (1 - y) * torch.log(xs_neg.clamp(min=self.eps)) - loss = los_pos + los_neg - - # Asymmetric Focusing - if self.gamma_neg > 0 or self.gamma_pos > 0: - if self.disable_torch_grad_focal_loss: - torch._C.set_grad_enabled(False) - pt0 = xs_pos * y - pt1 = xs_neg * (1 - y) # pt = p if t > 0 else 1-p - pt = pt0 + pt1 - one_sided_gamma = self.gamma_pos * y + self.gamma_neg * (1 - y) - one_sided_w = torch.pow(1 - pt, one_sided_gamma) - if self.disable_torch_grad_focal_loss: - torch._C.set_grad_enabled(True) - loss *= one_sided_w - - return -loss.sum() - - -class AsymmetricLossSingleLabel(nn.Module): - def __init__(self, gamma_pos=1, gamma_neg=4, eps: float = 0.1, reduction='mean'): - super(AsymmetricLossSingleLabel, self).__init__() - - self.eps = eps - self.logsoftmax = nn.LogSoftmax(dim=-1) - self.targets_classes = [] # prevent gpu repeated memory allocation - self.gamma_pos = gamma_pos - self.gamma_neg = gamma_neg - self.reduction = reduction - - def forward(self, inputs, target, reduction=None): - """" - Parameters - ---------- - x: input logits - y: targets (1-hot vector) - """ - - num_classes = inputs.size()[-1] - log_preds = self.logsoftmax(inputs) - self.targets_classes = torch.zeros_like(inputs).scatter_(1, target.long().unsqueeze(1), 1) - - # ASL weights - targets = self.targets_classes - anti_targets = 1 - targets - xs_pos = torch.exp(log_preds) - xs_neg = 1 - xs_pos - xs_pos = xs_pos * targets - xs_neg = xs_neg * anti_targets - asymmetric_w = torch.pow(1 - xs_pos - xs_neg, - self.gamma_pos * targets + self.gamma_neg * anti_targets) - log_preds = log_preds * asymmetric_w - - if self.eps > 0: # label smoothing - self.targets_classes.mul_(1 - self.eps).add_(self.eps / num_classes) - - # loss calculation - loss = - self.targets_classes.mul(log_preds) - - loss = loss.sum(dim=-1) - if self.reduction == 'mean': - loss = loss.mean() - - return loss +import torch +import torch.nn as nn + + +class AsymmetricLossMultiLabel(nn.Module): + def __init__(self, gamma_neg=4, gamma_pos=1, clip=0.05, eps=1e-8, disable_torch_grad_focal_loss=False): + super(AsymmetricLossMultiLabel, self).__init__() + + self.gamma_neg = gamma_neg + self.gamma_pos = gamma_pos + self.clip = clip + self.disable_torch_grad_focal_loss = disable_torch_grad_focal_loss + self.eps = eps + + def forward(self, x, y): + """" + Parameters + ---------- + x: input logits + y: targets (multi-label binarized vector) + """ + + # Calculating Probabilities + x_sigmoid = torch.sigmoid(x) + xs_pos = x_sigmoid + xs_neg = 1 - x_sigmoid + + # Asymmetric Clipping + if self.clip is not None and self.clip > 0: + xs_neg = (xs_neg + self.clip).clamp(max=1) + + # Basic CE calculation + los_pos = y * torch.log(xs_pos.clamp(min=self.eps)) + los_neg = (1 - y) * torch.log(xs_neg.clamp(min=self.eps)) + loss = los_pos + los_neg + + # Asymmetric Focusing + if self.gamma_neg > 0 or self.gamma_pos > 0: + if self.disable_torch_grad_focal_loss: + torch._C.set_grad_enabled(False) + pt0 = xs_pos * y + pt1 = xs_neg * (1 - y) # pt = p if t > 0 else 1-p + pt = pt0 + pt1 + one_sided_gamma = self.gamma_pos * y + self.gamma_neg * (1 - y) + one_sided_w = torch.pow(1 - pt, one_sided_gamma) + if self.disable_torch_grad_focal_loss: + torch._C.set_grad_enabled(True) + loss *= one_sided_w + + return -loss.sum() + + +class AsymmetricLossSingleLabel(nn.Module): + def __init__(self, gamma_pos=1, gamma_neg=4, eps: float = 0.1, reduction='mean'): + super(AsymmetricLossSingleLabel, self).__init__() + + self.eps = eps + self.logsoftmax = nn.LogSoftmax(dim=-1) + self.targets_classes = [] # prevent gpu repeated memory allocation + self.gamma_pos = gamma_pos + self.gamma_neg = gamma_neg + self.reduction = reduction + + def forward(self, inputs, target, reduction=None): + """" + Parameters + ---------- + x: input logits + y: targets (1-hot vector) + """ + + num_classes = inputs.size()[-1] + log_preds = self.logsoftmax(inputs) + self.targets_classes = torch.zeros_like(inputs).scatter_(1, target.long().unsqueeze(1), 1) + + # ASL weights + targets = self.targets_classes + anti_targets = 1 - targets + xs_pos = torch.exp(log_preds) + xs_neg = 1 - xs_pos + xs_pos = xs_pos * targets + xs_neg = xs_neg * anti_targets + asymmetric_w = torch.pow(1 - xs_pos - xs_neg, + self.gamma_pos * targets + self.gamma_neg * anti_targets) + log_preds = log_preds * asymmetric_w + + if self.eps > 0: # label smoothing + self.targets_classes.mul_(1 - self.eps).add_(self.eps / num_classes) + + # loss calculation + loss = - self.targets_classes.mul(log_preds) + + loss = loss.sum(dim=-1) + if self.reduction == 'mean': + loss = loss.mean() + + return loss diff --git a/PyTorch/contrib/cv/classification/GoogleNet_ID1623_for_PyTorch/modelzoo_level.txt b/PyTorch/contrib/cv/classification/GoogleNet_ID1623_for_PyTorch/modelzoo_level.txt index 484664c2399ae4109859a67aba6cb9facff03cf1..55a9add9fa74832ca908108d73946cd76281a9cd 100644 --- a/PyTorch/contrib/cv/classification/GoogleNet_ID1623_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/GoogleNet_ID1623_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/InceptionV4_ID1778_for_PyTorch/infer/README.md b/PyTorch/contrib/cv/classification/InceptionV4_ID1778_for_PyTorch/infer/README.md index 1d61885fec1287177de1df7f2d84e75182a91c35..543986bf797a9f4d50dd45e2bc998373210c03f3 100644 --- a/PyTorch/contrib/cv/classification/InceptionV4_ID1778_for_PyTorch/infer/README.md +++ b/PyTorch/contrib/cv/classification/InceptionV4_ID1778_for_PyTorch/infer/README.md @@ -1,381 +1,381 @@ -# 交付件基本信息 - -**发布者(Publisher)**:Huawei - -**应用领域(Application Domain)**:Image Classification - -**版本(Version)**:1.2 - -**修改时间(Modified)**:2021.09.10 - -**大小(Size)**:onnx/163MB \(om\) - -**框架(Framework)**:PyTorch (1.5.0) - -**模型格式(Model Format)**:pth.tar/onnx/om - -**精度(Precision)**:O2(训练)、FP16(推理) - -**处理器(Processor)**:昇腾910/昇腾310 - -**应用级别(Categories)**:Released - -**描述(Description):**基于Pytorch框架的InceptionV4图像分类网络模型训练并保存模型,通过ATC工具转换,可在昇腾AI设备上运行 - -**CANN 版本**: CANN 5.0.2 B058 - -**Python 版本**: Python 3.7.5 - -**操作系统版本**: Ubuntu 18.04 - -# 推理 - -### 操作步骤 - -1. 单击“下载模型脚本”和“下载模型”,下载所需软件包。 - - - - ![img](https://r.huaweistatic.com/s/ascendstatic/lst/modelZooImg/public_sys-resources/note_3.0-zh-cn.png) - - - 下载模型脚本:下载训练和推理的脚本文件。 - - 下载模型:下载模型文件。 - - - -2. 将源码上传至推理服务器任意目录并解压(如:“/home/test”)。 - - - - ``` - # 在环境上执行 - unzip InceptionV4_ID1778_for_PyTorch.zip - cd {code_unzip_path}/InceptionV4_ID1778_for_PyTorch/infer - ``` - - ![img](https://r.huaweistatic.com/s/ascendstatic/lst/modelZooImg/public_sys-resources/note_3.0-zh-cn.png) - - - code_unzip_path:代码解压目录,以“/home/test”为例。 - - version:为模型版本。 - - - - - -3. 数据准备。 - - - - 由于后续推理均在容器中进行,因此需要把用于推理的图片、数据集、模型文件、代码等均映射到容器中 - - ``` - /home/data - ├── imagenet_val # 推理图片用于精度测试的数据集 - │ ├── ILSVRC2012_val_00016652.JPEG - │ └── ILSVRC2012_val_00024989.JPEG - ``` - - - - - -4. 文件格式转换 - - ``` - find ./ -name "*.sh" | xargs dos2unix - ``` - - - -5. 启动容器 - - - 进入到代码根目录,执行以下命令,启动容器。 - - **bash scripts/docker_start_infer.sh** *infer_image* *data_path* - - | 参数 | 说明 | - | ------------- | ----------------------------- | - | *infer_image* | 推理镜像名称,根据实际写入。 | - | *data_path* | 数据路径。如:“/home/test/”。 | - - 启动容器时会将推理芯片和数据路径挂载到容器中。 - - ``` - # 切换到代码跟目录下 - cd /home/path/to/InceptionV4_ID1778_for_PyTorch/ - bash scripts/docker_start_infer.sh infer:21.0.1 /home/path/to/path - ``` - -## 模型转换 - -### 前提条件 - -已进入推理容器环境。具体操作请参见“准备容器环境”。 - -### 操作步骤 - -1. 准备onnx模型文件。 - - - - onnx模型为在昇腾910服务器上导出的模型,导出onnx模型的详细步骤请参见“模型训练”。 - - 将模型文件保存在/path/to/InceptionV4_ID1778_for_PyTorch/infer/data 路径下 - - - -2. 执行以下命令,进行模型转换。 - - - - 模型转换时,可选择不同的AIPP配置文件进行转换。转换详细信息可查看转换脚本和对应的AIPP配置文件,转换命令如下。 - - **bash convert/onnx2om.sh** model_path output_model_name - - | 参数 | 说明 | - | ----------------- | ------------------------------------------------- | - | model_path | 转换脚本onnx文件路径。 | - | output_model_name | 生成的OM文件名,转换脚本会在此基础上添加.om后缀。 | - - 转换示例如下所示。 - - ``` - bash convert/onnx2om.sh ./data/InceptionV4_npu_1.onnx data/InceptionV4-pt - ``` - -## mxBase推理 - -### 前提条件 - -已进入推理容器环境。具体操作请参见“准备容器环境”。 - -### 操作步骤 - -1. 配置环境变量。 - - ``` - export ASCEND_HOME=/usr/local/Ascend - export ASCEND_VERSION=nnrt/latest - export ARCH_PATTERN=. - export LD_LIBRARY_PATH=${MX_SDK_HOME}/lib/modelpostprocessors:${LD_LIBRARY_PATH} - ``` - - - -2. 修改配置文件。 - - - - 可根据实际情况修改,配置文件位于“mxbase/src/main.cpp”中,可修改参数如下。 - - 若使用迁移学习生成的模型进行推理,请修改CLASS_NUM为迁移学习训练任务数据集的类别数量。如:修改CLASS_NUM=1001;om的模型路径;labelPath的路径 - - ``` - ... - namespace { - - const uint32_t CLASS_NUM = 1001; // 推理类别总数 - } - int main(int argc, char* argv[]){ - .... - initParam.labelPath = "../data/imagenet1000_clsidx_to_labels.names"; - initParam.topk = 5; - initParam.softmax = false; - initParam.checkTensor = true; - initParam.modelPath = "../data/inception-pt.om"; - .... - } - ... - ``` - - - -3. 编译工程。 - - ``` - cd /home/path/to/InceptionV4_ID1778_for_PyTorch/infer/mxbase - bash build.sh - ``` - -4. 运行推理服务 - - - - **./build/inceptionv4 *image_path* - - | 参数 | 说明 | - | ---------- | ---------------------------------------------- | - | image_path | 推理图片所在文件的路径。如:“../data/images”。 | - - - -5. 观察结果。 - - 分类结果会以*.txt的格式保存在result文件中。 - - ![image-20210929155913474](./image/image-20210929155913474.png) - - - -## MindX SDK 推理 - -### 前提条件 - -已进入推理容器环境。具体操作请参见“准备容器环境”。 - -### 操作步骤 - -1. 修改配置文件。可根据实际情况修改pipeline文件。 - - ``` - vim ../data/inceptionv4_opencv.pipeline - ``` - - 以inceptionv4_opencv.pipeline文件为例,作简要说明。 - - ``` - { - "im_inceptionv4": { - "stream_config": { - "deviceId": "0" # 指定推理卡,要与挂载到容器中的卡一致 - }, - "appsrc0": { - "props": { - "blocksize": "409600" - }, - "factory": "appsrc", - "next": "mxpi_imagedecoder0" - }, - ""mxpi_imagedecoder0"": { - "props": { - "handleMethod": "opencv" - }, - "factory": "mxpi_imagedecoder", - "next": "mxpi_imageresize0" - }, - "mxpi_imageresize0": { - "props": { - "handleMethod": "opencv", - "resizeHeight": "355", - "resizeWidth": "355", - "resizeType": "Resizer_Stretch" - }, - "factory": "mxpi_imageresize", - "next": "mxpi_opencvcentercrop0" - }, - "mxpi_opencvcentercrop0": { - "props": { - "dataSource": "mxpi_imageresize0", - "cropHeight": "299", - "cropWidth": "299" - }, - "factory": "mxpi_opencvcentercrop", - "next": "mxpi_tensorinfer0" - }, - - "mxpi_tensorinfer0": { - "props": { - "dataSource": "mxpi_opencvcentercrop0", - "modelPath": "../data/inceptionV4_pt_cfg.om", #模型存放路径 - "waitingTime": "2000", - "outputDeviceId": "-1" - }, - "factory": "mxpi_tensorinfer", - "next": "mxpi_classpostprocessor0" - }, - "mxpi_classpostprocessor0": { - "props": { - "dataSource": "mxpi_tensorinfer0", - "postProcessConfigPath": "../data/inceptionv4_aipp.cfg", #后处理的配置文件 - "labelPath": "../data/imagenet1000_clsidx_to_labels.names", #标签路径 - "postProcessLibPath": "../../../../mxVision-2.0.2/lib/modelpostprocessors/libresnet50postprocess.so" #后处理模块 - }, - "factory": "mxpi_classpostprocessor", - "next": "mxpi_dataserialize0" - }, - - .... - } - } - ``` - - - -2. 运行推理服务。 - - ``` - cd infer/sdk - bash run.sh /path/to/testImageDir /path/to/saveResultDir - ``` - - setp 1、查看推理结果。 - - 若设置推理结果路径为“infer/sdk/result”,示例如下所示。 - - ``` - root@97a4c6ab6482:/home/path/to/InceptionV4_ID1778_for_PyTorch/infer/sdk/result# ll - -rw-r--r-- 1 root root 21 Aug 24 07:09 ILSVRC2012_val_00042663_1.txt - -rw-r--r-- 1 root root 21 Aug 24 07:09 ILSVRC2012_val_00042820_1.txt - -rw-r--r-- 1 root root 21 Aug 24 07:09 ILSVRC2012_val_00042855_1.txt - -rw-r--r-- 1 root root 21 Aug 24 07:09 ILSVRC2012_val_00043055_1.txt - -rw-r--r-- 1 root root 21 Aug 24 07:09 ILSVRC2012_val_00043439_1.txt - -rw-r--r-- 1 root root 21 Aug 24 07:09 ILSVRC2012_val_00044460_1.txt - ``` - -3. 性能统计 - - step 1、打开性能统计开关。将“enable_ps”参数设置为true,“ps_interval_time”参数设置为6 - - **vi** */home/HwHiAiUser/mxManufacture/config/sdk.conf* - - ``` - # MindX SDK configuration file - - # whether to enable performance statistics, default is false [dynamic config] - - enable_ps=true - ... - ps_interval_time=6 - ... - ``` - - step 2、执行run.sh脚本。 - - ``` - cd infer/sdk - bash run.sh /path/to/testImageDir /path/to/saveResultDir - ``` - - step 3、在日志目录 “/home/HwHiAiUser/mxManufacture/logs/” 查看性能统计结果。 - - ``` - performance—statistics.log.e2e.xxx - performance—statistics.log.plugin.xxx - performance—statistics.log.tpr.xxx - ``` - - 其中e2e日志统计端到端时间,plugin日志统计单插件时间。 - -4. 执行精度测试。 - - 精度结果是在imageNet上进行的,使用classification_task_metric.py 进行测试。修改classification_task_metric.py - -``` -python3.7 classfication_task_metric.py result/ ./val_label.txt . ./result.json" -``` - -参数 1 : prediction file path -参数 2 : ground truth file -参数 3 : result store path -参数 4 : json file name - -查看精度结果。 - -``` -cat result.json -``` - - - -![image-20210929111906059](./image/image-20210929111906059.png) +# 交付件基本信息 + +**发布者(Publisher)**:Huawei + +**应用领域(Application Domain)**:Image Classification + +**版本(Version)**:1.2 + +**修改时间(Modified)**:2021.09.10 + +**大小(Size)**:onnx/163MB \(om\) + +**框架(Framework)**:PyTorch (1.5.0) + +**模型格式(Model Format)**:pth.tar/onnx/om + +**精度(Precision)**:O2(训练)、FP16(推理) + +**处理器(Processor)**:昇腾910/昇腾310 + +**应用级别(Categories)**:Released + +**描述(Description):**基于Pytorch框架的InceptionV4图像分类网络模型训练并保存模型,通过ATC工具转换,可在昇腾AI设备上运行 + +**CANN 版本**: CANN 5.0.2 B058 + +**Python 版本**: Python 3.7.5 + +**操作系统版本**: Ubuntu 18.04 + +# 推理 + +### 操作步骤 + +1. 单击“下载模型脚本”和“下载模型”,下载所需软件包。 + + + + ![img](https://r.huaweistatic.com/s/ascendstatic/lst/modelZooImg/public_sys-resources/note_3.0-zh-cn.png) + + - 下载模型脚本:下载训练和推理的脚本文件。 + - 下载模型:下载模型文件。 + + + +2. 将源码上传至推理服务器任意目录并解压(如:“/home/test”)。 + + + + ``` + # 在环境上执行 + unzip InceptionV4_ID1778_for_PyTorch.zip + cd {code_unzip_path}/InceptionV4_ID1778_for_PyTorch/infer + ``` + + ![img](https://r.huaweistatic.com/s/ascendstatic/lst/modelZooImg/public_sys-resources/note_3.0-zh-cn.png) + + - code_unzip_path:代码解压目录,以“/home/test”为例。 + - version:为模型版本。 + + + + + +3. 数据准备。 + + + + 由于后续推理均在容器中进行,因此需要把用于推理的图片、数据集、模型文件、代码等均映射到容器中 + + ``` + /home/data + ├── imagenet_val # 推理图片用于精度测试的数据集 + │ ├── ILSVRC2012_val_00016652.JPEG + │ └── ILSVRC2012_val_00024989.JPEG + ``` + + + + + +4. 文件格式转换 + + ``` + find ./ -name "*.sh" | xargs dos2unix + ``` + + + +5. 启动容器 + + + 进入到代码根目录,执行以下命令,启动容器。 + + **bash scripts/docker_start_infer.sh** *infer_image* *data_path* + + | 参数 | 说明 | + | ------------- | ----------------------------- | + | *infer_image* | 推理镜像名称,根据实际写入。 | + | *data_path* | 数据路径。如:“/home/test/”。 | + + 启动容器时会将推理芯片和数据路径挂载到容器中。 + + ``` + # 切换到代码跟目录下 + cd /home/path/to/InceptionV4_ID1778_for_PyTorch/ + bash scripts/docker_start_infer.sh infer:21.0.1 /home/path/to/path + ``` + +## 模型转换 + +### 前提条件 + +已进入推理容器环境。具体操作请参见“准备容器环境”。 + +### 操作步骤 + +1. 准备onnx模型文件。 + + + + onnx模型为在昇腾910服务器上导出的模型,导出onnx模型的详细步骤请参见“模型训练”。 + + 将模型文件保存在/path/to/InceptionV4_ID1778_for_PyTorch/infer/data 路径下 + + + +2. 执行以下命令,进行模型转换。 + + + + 模型转换时,可选择不同的AIPP配置文件进行转换。转换详细信息可查看转换脚本和对应的AIPP配置文件,转换命令如下。 + + **bash convert/onnx2om.sh** model_path output_model_name + + | 参数 | 说明 | + | ----------------- | ------------------------------------------------- | + | model_path | 转换脚本onnx文件路径。 | + | output_model_name | 生成的OM文件名,转换脚本会在此基础上添加.om后缀。 | + + 转换示例如下所示。 + + ``` + bash convert/onnx2om.sh ./data/InceptionV4_npu_1.onnx data/InceptionV4-pt + ``` + +## mxBase推理 + +### 前提条件 + +已进入推理容器环境。具体操作请参见“准备容器环境”。 + +### 操作步骤 + +1. 配置环境变量。 + + ``` + export ASCEND_HOME=/usr/local/Ascend + export ASCEND_VERSION=nnrt/latest + export ARCH_PATTERN=. + export LD_LIBRARY_PATH=${MX_SDK_HOME}/lib/modelpostprocessors:${LD_LIBRARY_PATH} + ``` + + + +2. 修改配置文件。 + + + + 可根据实际情况修改,配置文件位于“mxbase/src/main.cpp”中,可修改参数如下。 + + 若使用迁移学习生成的模型进行推理,请修改CLASS_NUM为迁移学习训练任务数据集的类别数量。如:修改CLASS_NUM=1001;om的模型路径;labelPath的路径 + + ``` + ... + namespace { + + const uint32_t CLASS_NUM = 1001; // 推理类别总数 + } + int main(int argc, char* argv[]){ + .... + initParam.labelPath = "../data/imagenet1000_clsidx_to_labels.names"; + initParam.topk = 5; + initParam.softmax = false; + initParam.checkTensor = true; + initParam.modelPath = "../data/inception-pt.om"; + .... + } + ... + ``` + + + +3. 编译工程。 + + ``` + cd /home/path/to/InceptionV4_ID1778_for_PyTorch/infer/mxbase + bash build.sh + ``` + +4. 运行推理服务 + + + + **./build/inceptionv4 *image_path* + + | 参数 | 说明 | + | ---------- | ---------------------------------------------- | + | image_path | 推理图片所在文件的路径。如:“../data/images”。 | + + + +5. 观察结果。 + + 分类结果会以*.txt的格式保存在result文件中。 + + ![image-20210929155913474](./image/image-20210929155913474.png) + + + +## MindX SDK 推理 + +### 前提条件 + +已进入推理容器环境。具体操作请参见“准备容器环境”。 + +### 操作步骤 + +1. 修改配置文件。可根据实际情况修改pipeline文件。 + + ``` + vim ../data/inceptionv4_opencv.pipeline + ``` + + 以inceptionv4_opencv.pipeline文件为例,作简要说明。 + + ``` + { + "im_inceptionv4": { + "stream_config": { + "deviceId": "0" # 指定推理卡,要与挂载到容器中的卡一致 + }, + "appsrc0": { + "props": { + "blocksize": "409600" + }, + "factory": "appsrc", + "next": "mxpi_imagedecoder0" + }, + ""mxpi_imagedecoder0"": { + "props": { + "handleMethod": "opencv" + }, + "factory": "mxpi_imagedecoder", + "next": "mxpi_imageresize0" + }, + "mxpi_imageresize0": { + "props": { + "handleMethod": "opencv", + "resizeHeight": "355", + "resizeWidth": "355", + "resizeType": "Resizer_Stretch" + }, + "factory": "mxpi_imageresize", + "next": "mxpi_opencvcentercrop0" + }, + "mxpi_opencvcentercrop0": { + "props": { + "dataSource": "mxpi_imageresize0", + "cropHeight": "299", + "cropWidth": "299" + }, + "factory": "mxpi_opencvcentercrop", + "next": "mxpi_tensorinfer0" + }, + + "mxpi_tensorinfer0": { + "props": { + "dataSource": "mxpi_opencvcentercrop0", + "modelPath": "../data/inceptionV4_pt_cfg.om", #模型存放路径 + "waitingTime": "2000", + "outputDeviceId": "-1" + }, + "factory": "mxpi_tensorinfer", + "next": "mxpi_classpostprocessor0" + }, + "mxpi_classpostprocessor0": { + "props": { + "dataSource": "mxpi_tensorinfer0", + "postProcessConfigPath": "../data/inceptionv4_aipp.cfg", #后处理的配置文件 + "labelPath": "../data/imagenet1000_clsidx_to_labels.names", #标签路径 + "postProcessLibPath": "../../../../mxVision-2.0.2/lib/modelpostprocessors/libresnet50postprocess.so" #后处理模块 + }, + "factory": "mxpi_classpostprocessor", + "next": "mxpi_dataserialize0" + }, + + .... + } + } + ``` + + + +2. 运行推理服务。 + + ``` + cd infer/sdk + bash run.sh /path/to/testImageDir /path/to/saveResultDir + ``` + + setp 1、查看推理结果。 + + 若设置推理结果路径为“infer/sdk/result”,示例如下所示。 + + ``` + root@97a4c6ab6482:/home/path/to/InceptionV4_ID1778_for_PyTorch/infer/sdk/result# ll + -rw-r--r-- 1 root root 21 Aug 24 07:09 ILSVRC2012_val_00042663_1.txt + -rw-r--r-- 1 root root 21 Aug 24 07:09 ILSVRC2012_val_00042820_1.txt + -rw-r--r-- 1 root root 21 Aug 24 07:09 ILSVRC2012_val_00042855_1.txt + -rw-r--r-- 1 root root 21 Aug 24 07:09 ILSVRC2012_val_00043055_1.txt + -rw-r--r-- 1 root root 21 Aug 24 07:09 ILSVRC2012_val_00043439_1.txt + -rw-r--r-- 1 root root 21 Aug 24 07:09 ILSVRC2012_val_00044460_1.txt + ``` + +3. 性能统计 + + step 1、打开性能统计开关。将“enable_ps”参数设置为true,“ps_interval_time”参数设置为6 + + **vi** */home/HwHiAiUser/mxManufacture/config/sdk.conf* + + ``` + # MindX SDK configuration file + + # whether to enable performance statistics, default is false [dynamic config] + + enable_ps=true + ... + ps_interval_time=6 + ... + ``` + + step 2、执行run.sh脚本。 + + ``` + cd infer/sdk + bash run.sh /path/to/testImageDir /path/to/saveResultDir + ``` + + step 3、在日志目录 “/home/HwHiAiUser/mxManufacture/logs/” 查看性能统计结果。 + + ``` + performance—statistics.log.e2e.xxx + performance—statistics.log.plugin.xxx + performance—statistics.log.tpr.xxx + ``` + + 其中e2e日志统计端到端时间,plugin日志统计单插件时间。 + +4. 执行精度测试。 + + 精度结果是在imageNet上进行的,使用classification_task_metric.py 进行测试。修改classification_task_metric.py + +``` +python3.7 classfication_task_metric.py result/ ./val_label.txt . ./result.json" +``` + +参数 1 : prediction file path +参数 2 : ground truth file +参数 3 : result store path +参数 4 : json file name + +查看精度结果。 + +``` +cat result.json +``` + + + +![image-20210929111906059](./image/image-20210929111906059.png) diff --git a/PyTorch/contrib/cv/classification/InceptionV4_ID1778_for_PyTorch/infer/sdk/classification_task_metric.py b/PyTorch/contrib/cv/classification/InceptionV4_ID1778_for_PyTorch/infer/sdk/classification_task_metric.py index 22385f773a97d0cee63f966357f2a49034ba6239..3987002029518061fc4eaf1777488f10439d8df2 100644 --- a/PyTorch/contrib/cv/classification/InceptionV4_ID1778_for_PyTorch/infer/sdk/classification_task_metric.py +++ b/PyTorch/contrib/cv/classification/InceptionV4_ID1778_for_PyTorch/infer/sdk/classification_task_metric.py @@ -1,188 +1,188 @@ -#coding = utf-8 -#Copyright 2020 Huawei Technologies Co., Ltd -# -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -#http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - img_name = temp[0].split(".")[0] - img_lab = temp[1] - img_gt_dict[img_name] = img_lab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, cls_ind in enumerate(temp): - data_vec[ind] = np.int32(cls_ind) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - res_cnt = 0 - n_labels = "" - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - - ret = load_statistical_predict_result(filepath) - #print("img_name:{}, filepath:{}, ret:{} ".format(img_name, filepath, ret)) - prediction = ret[0] - n_labels = ret[1] - - gt = img_gt_dict[img_name] - #print("gt:", gt) - if n_labels == 1000: - real_label = int(gt) - elif n_labels == 1001: - real_label = int(gt) + 1 - else: - real_label = int(gt) - 1 - - res_cnt = min(len(prediction), topn) - for i in range(res_cnt): - if str(real_label) == str(int(prediction[i])): - count_hit[i] += 1 - break - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(res_cnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Please enter target file folder | groud truth file | result folder | result json file name, such as" - "Such as: python3.7 classfication_task_metric.py result/ ./val_label.txt . ./result.json") - exit(1) - - if not os.path.exists(folder_davinci_target): - print("target file folder does not exist.") - exit() - - if not os.path.exists(annotation_file_path): - - print("Ground truth file does not exist.") - exit() - - if not os.path.exists(result_json_path): - print("Result folder doesn't exist.") - exit() - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) +#coding = utf-8 +#Copyright 2020 Huawei Technologies Co., Ltd +# +#Licensed under the Apache License, Version 2.0 (the "License"); +#you may not use this file except in compliance with the License. +#You may obtain a copy of the License at +# +#http://www.apache.org/licenses/LICENSE-2.0 +# +#Unless required by applicable law or agreed to in writing, software +#distributed under the License is distributed on an "AS IS" BASIS, +#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#See the License for the specific language governing permissions and +#limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + img_name = temp[0].split(".")[0] + img_lab = temp[1] + img_gt_dict[img_name] = img_lab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, cls_ind in enumerate(temp): + data_vec[ind] = np.int32(cls_ind) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + res_cnt = 0 + n_labels = "" + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + + ret = load_statistical_predict_result(filepath) + #print("img_name:{}, filepath:{}, ret:{} ".format(img_name, filepath, ret)) + prediction = ret[0] + n_labels = ret[1] + + gt = img_gt_dict[img_name] + #print("gt:", gt) + if n_labels == 1000: + real_label = int(gt) + elif n_labels == 1001: + real_label = int(gt) + 1 + else: + real_label = int(gt) - 1 + + res_cnt = min(len(prediction), topn) + for i in range(res_cnt): + if str(real_label) == str(int(prediction[i])): + count_hit[i] += 1 + break + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(res_cnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Please enter target file folder | groud truth file | result folder | result json file name, such as" + "Such as: python3.7 classfication_task_metric.py result/ ./val_label.txt . ./result.json") + exit(1) + + if not os.path.exists(folder_davinci_target): + print("target file folder does not exist.") + exit() + + if not os.path.exists(annotation_file_path): + + print("Ground truth file does not exist.") + exit() + + if not os.path.exists(result_json_path): + print("Result folder doesn't exist.") + exit() + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) diff --git a/PyTorch/contrib/cv/classification/MGN/README.md b/PyTorch/contrib/cv/classification/MGN/README.md index 4cb4c8a500c3e7db591323fe5a264ecc5c9e88b1..65b55576c8fed9e263569697817cca6ab430a6e5 100644 --- a/PyTorch/contrib/cv/classification/MGN/README.md +++ b/PyTorch/contrib/cv/classification/MGN/README.md @@ -1,58 +1,58 @@ -# MGN - -This implements training of MGN on the Market-1501 dataset, mainly modified from [GNAYUOHZ/ReID-MGN](https://github.com/GNAYUOHZ/ReID-MGN). - -## MGN Detail - -As of the current date, Ascend-Pytorch is still inefficient for contiguous operations.Therefore, MGN is re-implemented using semantics such as custom OP. - - -## Requirements - -- Install PyTorch ([pytorch.org](http://pytorch.org)) - -- `pip install -r requirements.txt` - -- Download the Market-1501 dataset from https://paperswithcode.com/dataset/market-1501 - - - ~~~shell - unzip Market-1501-v15.09.15.zip - ~~~ - -## Training - -To train a model, run `main.py` with the desired model architecture and the path to the market dataset: - -```bash -# training 1p accuracy -bash test/train_full_1p.sh --data_path=real_data_path - -# training 1p performance -bash test/train_performance_1p.sh --data_path=real_data_path - -# training 8p accuracy -bash test/train_full_8p.sh --data_path=real_data_path - -# training 8p performance -bash test/train_performance_8p.sh --data_path=real_data_path - -# finetune -bash test/train_finetune_1p.sh --data_path=real_data_path --weights=real_weight_path - -# Online inference demo -python demo.py --data_path real_data_path - -# To ONNX -python pthtar2onnx.py -``` - -## MGN training result - - -| | mAP | AMP_Type | Epochs | FPS | -| :----: | :---: | :------: | :----: | :-----: | -| 1p-GPU | - | O2 | 1 | 71.408 | -| 1p-NPU | - | O2 | 1 | 29.408 | -| 8p-GPU | 93.35 | O2 | 500 | 771.818 | -| 8p-NPU | 93.83 | O2 | 500 | 200.024 | - +# MGN + +This implements training of MGN on the Market-1501 dataset, mainly modified from [GNAYUOHZ/ReID-MGN](https://github.com/GNAYUOHZ/ReID-MGN). + +## MGN Detail + +As of the current date, Ascend-Pytorch is still inefficient for contiguous operations.Therefore, MGN is re-implemented using semantics such as custom OP. + + +## Requirements + +- Install PyTorch ([pytorch.org](http://pytorch.org)) + +- `pip install -r requirements.txt` + +- Download the Market-1501 dataset from https://paperswithcode.com/dataset/market-1501 + + - ~~~shell + unzip Market-1501-v15.09.15.zip + ~~~ + +## Training + +To train a model, run `main.py` with the desired model architecture and the path to the market dataset: + +```bash +# training 1p accuracy +bash test/train_full_1p.sh --data_path=real_data_path + +# training 1p performance +bash test/train_performance_1p.sh --data_path=real_data_path + +# training 8p accuracy +bash test/train_full_8p.sh --data_path=real_data_path + +# training 8p performance +bash test/train_performance_8p.sh --data_path=real_data_path + +# finetune +bash test/train_finetune_1p.sh --data_path=real_data_path --weights=real_weight_path + +# Online inference demo +python demo.py --data_path real_data_path + +# To ONNX +python pthtar2onnx.py +``` + +## MGN training result + + +| | mAP | AMP_Type | Epochs | FPS | +| :----: | :---: | :------: | :----: | :-----: | +| 1p-GPU | - | O2 | 1 | 71.408 | +| 1p-NPU | - | O2 | 1 | 29.408 | +| 8p-GPU | 93.35 | O2 | 500 | 771.818 | +| 8p-NPU | 93.83 | O2 | 500 | 200.024 | + diff --git a/PyTorch/contrib/cv/classification/MnasNet/infer/convert/aipp.aipconfig b/PyTorch/contrib/cv/classification/MnasNet/infer/convert/aipp.aipconfig old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MnasNet/infer/convert/onnx2om.sh b/PyTorch/contrib/cv/classification/MnasNet/infer/convert/onnx2om.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MnasNet/infer/mxbase/CMakeLists.txt b/PyTorch/contrib/cv/classification/MnasNet/infer/mxbase/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MnasNet/infer/mxbase/Mnasnet.cpp b/PyTorch/contrib/cv/classification/MnasNet/infer/mxbase/Mnasnet.cpp old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MnasNet/infer/mxbase/Mnasnet.h b/PyTorch/contrib/cv/classification/MnasNet/infer/mxbase/Mnasnet.h old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MnasNet/infer/mxbase/build.sh b/PyTorch/contrib/cv/classification/MnasNet/infer/mxbase/build.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MnasNet/infer/mxbase/main.cpp b/PyTorch/contrib/cv/classification/MnasNet/infer/mxbase/main.cpp old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MnasNet/infer/mxbase/run.sh b/PyTorch/contrib/cv/classification/MnasNet/infer/mxbase/run.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MnasNet/infer/sdk/main.py b/PyTorch/contrib/cv/classification/MnasNet/infer/sdk/main.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MnasNet/infer/sdk/mnasnet_aipp.cfg b/PyTorch/contrib/cv/classification/MnasNet/infer/sdk/mnasnet_aipp.cfg old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MnasNet/infer/sdk/mnasnet_opencv.pipeline b/PyTorch/contrib/cv/classification/MnasNet/infer/sdk/mnasnet_opencv.pipeline old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MnasNet/infer/sdk/run.sh b/PyTorch/contrib/cv/classification/MnasNet/infer/sdk/run.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MnasNet/infer/util/classification_task_metric.py b/PyTorch/contrib/cv/classification/MnasNet/infer/util/classification_task_metric.py old mode 100755 new mode 100644 index 972b7fa0ecf66c8ce762023c63110f15b07a9fd4..089aee8a40a3c6db2ea5b0eaada954a329b7426a --- a/PyTorch/contrib/cv/classification/MnasNet/infer/util/classification_task_metric.py +++ b/PyTorch/contrib/cv/classification/MnasNet/infer/util/classification_task_metric.py @@ -1,186 +1,186 @@ -# coding = utf-8 -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import json -import numpy as np -import time - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def gen_file_name(img_name): - full_name = img_name.split('/')[-1] - index = full_name.rfind('.') - return full_name[:index] - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if (gtfile != LABEL_FILE): - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - ret = gt["image"]["annotations"][0]["category_id"] - img_gt_dict[gen_file_name(gtfile)] = ret - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - temp = line.strip().split(" ") - img_name = temp[0].split(".")[0] - img_lab = temp[1] - img_gt_dict[img_name] = img_lab - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label, in_type, color - """ - with open(filepath, 'r')as f: - data = f.readline() - temp = data.strip().split(" ") - n_label = len(temp) - data_vec = np.zeros((n_label), dtype=np.float32) - in_type = '' - color = '' - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, cls_ind in enumerate(temp): - data_vec[ind] = np.int32(cls_ind) - return data_vec, n_label, in_type, color - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - res_cnt = 0 - n_labels = "" - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - - ret = load_statistical_predict_result(filepath) - - prediction = ret[0] - n_labels = ret[1] - gt = img_gt_dict[img_name] - if n_labels == 1000: - real_label = int(gt) - elif n_labels == 1001: - real_label = int(gt) + 1 - else: - real_label = int(gt) - 1 - - res_cnt = min(len(prediction), topn) - for i in range(res_cnt): - if str(real_label) == str(int(prediction[i])): - count_hit[i] += 1 - break - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - if count == 0: - accuracy = 0 - else: - accuracy = np.cumsum(count_hit) / count - for i in range(res_cnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - start = time.time() - try: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - except IndexError: - print("Please enter target file folder | groud truth file | result folder | result json file name, such as" - "Such as: python3.7 classfication_task_metric.py result/ ./val_label.txt . ./result.json") - exit(1) - - if not os.path.exists(folder_davinci_target): - print("target file folder does not exist.") - exit() - - if not os.path.exists(annotation_file_path): - - print("Ground truth file does not exist.") - exit() - - if not os.path.exists(result_json_path): - print("Result folder doesn't exist.") - exit() - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - - elapsed = (time.time() - start) +# coding = utf-8 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import json +import numpy as np +import time + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def gen_file_name(img_name): + full_name = img_name.split('/')[-1] + index = full_name.rfind('.') + return full_name[:index] + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if (gtfile != LABEL_FILE): + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + ret = gt["image"]["annotations"][0]["category_id"] + img_gt_dict[gen_file_name(gtfile)] = ret + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + temp = line.strip().split(" ") + img_name = temp[0].split(".")[0] + img_lab = temp[1] + img_gt_dict[img_name] = img_lab + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label, in_type, color + """ + with open(filepath, 'r')as f: + data = f.readline() + temp = data.strip().split(" ") + n_label = len(temp) + data_vec = np.zeros((n_label), dtype=np.float32) + in_type = '' + color = '' + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, cls_ind in enumerate(temp): + data_vec[ind] = np.int32(cls_ind) + return data_vec, n_label, in_type, color + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + res_cnt = 0 + n_labels = "" + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + + ret = load_statistical_predict_result(filepath) + + prediction = ret[0] + n_labels = ret[1] + gt = img_gt_dict[img_name] + if n_labels == 1000: + real_label = int(gt) + elif n_labels == 1001: + real_label = int(gt) + 1 + else: + real_label = int(gt) - 1 + + res_cnt = min(len(prediction), topn) + for i in range(res_cnt): + if str(real_label) == str(int(prediction[i])): + count_hit[i] += 1 + break + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + if count == 0: + accuracy = 0 + else: + accuracy = np.cumsum(count_hit) / count + for i in range(res_cnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + start = time.time() + try: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + except IndexError: + print("Please enter target file folder | groud truth file | result folder | result json file name, such as" + "Such as: python3.7 classfication_task_metric.py result/ ./val_label.txt . ./result.json") + exit(1) + + if not os.path.exists(folder_davinci_target): + print("target file folder does not exist.") + exit() + + if not os.path.exists(annotation_file_path): + + print("Ground truth file does not exist.") + exit() + + if not os.path.exists(result_json_path): + print("Result folder doesn't exist.") + exit() + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + + elapsed = (time.time() - start) diff --git a/PyTorch/contrib/cv/classification/MnasNet/modelArts/pth2onnx.py b/PyTorch/contrib/cv/classification/MnasNet/modelArts/pth2onnx.py index 2dece3cb8d3d2e38128ec503a8668ba578147aa6..f86ce4b281b092af31e7c18d31ab6863a2cc6ad4 100644 --- a/PyTorch/contrib/cv/classification/MnasNet/modelArts/pth2onnx.py +++ b/PyTorch/contrib/cv/classification/MnasNet/modelArts/pth2onnx.py @@ -1,98 +1,98 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import os -import random -import shutil -import time -import warnings -import math -import glob -import numpy as np -import sys - -import torch -import torch.npu -import torch.nn as nn -from collections import OrderedDict -import torch.onnx -sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../')) -import mnasnet - -# modelarts modification -import moxing as mox - - -CACHE_TRAINING_URL = "/cache/training" -CACHE_MODEL_URL = "/cache/model" - -def proc_node_module(checkpoint, AttrName): - new_state_dict = OrderedDict() - for k, v in checkpoint[AttrName].items(): - if k[0:7] == "module.": - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - - -def convert(pth_file, onnx_path, class_num, train_url, npu): - - loc = 'npu:{}'.format(npu) - checkpoint = torch.load(pth_file, map_location=loc) - - checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') - model = mnasnet.mnasnet1_0(num_classes=class_num) - - model.to(loc) - model.load_state_dict(checkpoint['state_dict']) - model.eval() - input_names = ["actual_input_1"] - output_names = ["output1"] - dummy_input = torch.randn(16, 3, 224, 224) - dummy_input = dummy_input.to(loc, non_blocking=False) - torch.onnx.export(model, dummy_input, onnx_path, input_names=input_names, output_names=output_names, opset_version=11) - mox.file.copy_parallel(onnx_path, train_url + 'model.onnx') - -def convert_pth_to_onnx(config_args): - mox.file.copy_parallel(config_args.is_best_name, os.path.join(CACHE_MODEL_URL, "checkpoint.pth.tar")) - pth_pattern = os.path.join(CACHE_MODEL_URL, 'checkpoint.pth.tar') - pth_file_list = glob.glob(pth_pattern) - if not pth_file_list: - print(f"can't find pth {pth_pattern}") - return - pth_file = pth_file_list[0] - onnx_path = pth_file.split(".")[0] + '.onnx' - convert(pth_file, onnx_path, config_args.class_num, config_args.train_url, config_args.npu) -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') - # modelarts - parser.add_argument('--data_url', metavar='DIR', default='/cache/data_url', help='path to dataset') - parser.add_argument('--train_url', default="/cache/training", - type=str, - help="setting dir of training output") - parser.add_argument('--onnx', default=True, action='store_true', - help="convert pth model to onnx") - parser.add_argument('--class_num', default=1000, type=int, - help='number of class') - parser.add_argument('-a', '--arch', metavar='ARCH', default='mnasnet1_0') - parser.add_argument('--is_best_name', dest='is_best_name', - help=' weight dir') - args = parser.parse_args() - print('===========================') - print(args) - print('===========================') +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import os +import random +import shutil +import time +import warnings +import math +import glob +import numpy as np +import sys + +import torch +import torch.npu +import torch.nn as nn +from collections import OrderedDict +import torch.onnx +sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../')) +import mnasnet + +# modelarts modification +import moxing as mox + + +CACHE_TRAINING_URL = "/cache/training" +CACHE_MODEL_URL = "/cache/model" + +def proc_node_module(checkpoint, AttrName): + new_state_dict = OrderedDict() + for k, v in checkpoint[AttrName].items(): + if k[0:7] == "module.": + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + + +def convert(pth_file, onnx_path, class_num, train_url, npu): + + loc = 'npu:{}'.format(npu) + checkpoint = torch.load(pth_file, map_location=loc) + + checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') + model = mnasnet.mnasnet1_0(num_classes=class_num) + + model.to(loc) + model.load_state_dict(checkpoint['state_dict']) + model.eval() + input_names = ["actual_input_1"] + output_names = ["output1"] + dummy_input = torch.randn(16, 3, 224, 224) + dummy_input = dummy_input.to(loc, non_blocking=False) + torch.onnx.export(model, dummy_input, onnx_path, input_names=input_names, output_names=output_names, opset_version=11) + mox.file.copy_parallel(onnx_path, train_url + 'model.onnx') + +def convert_pth_to_onnx(config_args): + mox.file.copy_parallel(config_args.is_best_name, os.path.join(CACHE_MODEL_URL, "checkpoint.pth.tar")) + pth_pattern = os.path.join(CACHE_MODEL_URL, 'checkpoint.pth.tar') + pth_file_list = glob.glob(pth_pattern) + if not pth_file_list: + print(f"can't find pth {pth_pattern}") + return + pth_file = pth_file_list[0] + onnx_path = pth_file.split(".")[0] + '.onnx' + convert(pth_file, onnx_path, config_args.class_num, config_args.train_url, config_args.npu) +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') + # modelarts + parser.add_argument('--data_url', metavar='DIR', default='/cache/data_url', help='path to dataset') + parser.add_argument('--train_url', default="/cache/training", + type=str, + help="setting dir of training output") + parser.add_argument('--onnx', default=True, action='store_true', + help="convert pth model to onnx") + parser.add_argument('--class_num', default=1000, type=int, + help='number of class') + parser.add_argument('-a', '--arch', metavar='ARCH', default='mnasnet1_0') + parser.add_argument('--is_best_name', dest='is_best_name', + help=' weight dir') + args = parser.parse_args() + print('===========================') + print(args) + print('===========================') convert_pth_to_onnx(args) \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/MnasNet/modelArts/train-modelarts.py b/PyTorch/contrib/cv/classification/MnasNet/modelArts/train-modelarts.py index 26ad841ce203b8aaef0dabdfd61f163c9cf31029..9f090b46b41f14c95f67da7b68e15fbf75691ed8 100644 --- a/PyTorch/contrib/cv/classification/MnasNet/modelArts/train-modelarts.py +++ b/PyTorch/contrib/cv/classification/MnasNet/modelArts/train-modelarts.py @@ -1,735 +1,735 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import os -import random -import shutil -import time -import warnings -import math -import glob -import numpy as np -import sys - -import torch -import torch.npu -import torch.nn as nn -import torch.nn.parallel -import torch.backends.cudnn as cudnn -import torch.distributed as dist -import torch.nn.functional as F -import torch.optim -import torch.utils.data -import torch.utils.data.distributed -import torchvision.transforms as transforms -import torchvision.datasets as datasets -import torchvision.models as models -from collections import OrderedDict -import torch.onnx -import pth2onnx -sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../')) -import mnasnet - -# modelarts modification -import moxing as mox - - -try: - from apex.parallel import DistributedDataParallel as DDP - from apex.fp16_utils import * - from apex import amp, optimizers -except ImportError: - raise ImportError("Please install apex from https://www.github.com/nvidia/apex to run this example.") - - -parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') -parser.add_argument('--data', metavar='DIR', - help='path to dataset') -parser.add_argument('--device', default='npu', type=str, help='npu or gpu') -parser.add_argument('--device-list', default='0,1,2,3,4,5,6,7', type=str, help='device id list') -parser.add_argument('-a', '--arch', metavar='ARCH', default='resnet18') -parser.add_argument('-j', '--workers', default=4, type=int, metavar='N', - help='number of data loading workers (default: 4)') -parser.add_argument('--epochs', default=90, type=int, metavar='N', - help='number of total epochs to run') -parser.add_argument('--start-epoch', default=0, type=int, metavar='N', - help='manual epoch number (useful on restarts)') -parser.add_argument('-b', '--batch-size', default=256, type=int, - metavar='N', - help='mini-batch size (default: 256), this is the total ' - 'batch size of all NPUs on the current node when ' - 'using Data Parallel or Distributed Data Parallel') - -parser.add_argument('--label-smoothing', '--ls', default=0.1, type=float) - -parser.add_argument('--lr', '--learning-rate', default=0.1, type=float, - metavar='LR', help='initial learning rate', dest='lr') -parser.add_argument('--momentum', default=0.9, type=float, metavar='M', - help='momentum') -parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, - metavar='W', help='weight decay (default: 1e-4)', - dest='weight_decay') -parser.add_argument('-p', '--print-freq', default=10, type=int, - metavar='N', help='print frequency (default: 10)') -parser.add_argument('--resume', default='', type=str, metavar='PATH', - help='path to latest checkpoint (default: none)') -parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', - help='evaluate model on validation set') -parser.add_argument('--pretrained', dest='pretrained', action='store_true', - help='use pre-trained model') -parser.add_argument('--world-size', default=-1, type=int, - help='number of nodes for distributed training') -parser.add_argument('--rank', default=-1, type=int, - help='node rank for distributed training') -parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str, - help='url used to set up distributed training') -parser.add_argument('--dist-backend', default='nccl', type=str, - help='distributed backend') -parser.add_argument('--seed', default=1, type=int, - help='seed for initializing training. ') -parser.add_argument('--npu', default=0, type=int, - help='NPU id to use.') -parser.add_argument('--warmup', default=0, type=int, - help='Warmup epochs.') -parser.add_argument('--local_rank', default=0, type=int, - help="rank id of process") -parser.add_argument('--run-prof', action='store_true', help='only for prof') -parser.add_argument('--multiprocessing-distributed', action='store_true', - help='Use multi-processing distributed training to launch ' - 'N processes per node, which has N NPUs. This is the ' - 'fastest way to use PyTorch for either single node or ' - 'multi node data parallel training') - -parser.add_argument('--pretrained_weight', dest='pretrained_weight', - help='pretrained weight dir') - - -# modelarts -parser.add_argument('--data_url', metavar='DIR', default='/cache/data_url', help='path to dataset') -parser.add_argument('--train_url', default="/cache/training", - type=str, - help="setting dir of training output") -parser.add_argument('--onnx', default=True, action='store_true', - help="convert pth model to onnx") -parser.add_argument('--class_num', default=1000, type=int, - help='number of class') - - -best_acc1 = 0 -CALCULATE_DEVICE = "npu:0" -CACHE_TRAINING_URL = "/cache/training" -is_best_name = "checkpoint.pth.tar" -def main(): - args = parser.parse_args() - print('===========================') - print(args) - print('===========================') - - if args.npu is None: - args.npu = 0 - global CALCULATE_DEVICE - if 'npu' in CALCULATE_DEVICE: - torch.npu.set_device(CALCULATE_DEVICE) - - if args.seed is not None: - random.seed(args.seed) - torch.manual_seed(args.seed) - cudnn.deterministic = True - warnings.warn('You have chosen to seed training. ' - 'This will turn on the CUDNN deterministic setting, ' - 'which can slow down your training considerably! ' - 'You may see unexpected behavior when restarting ' - 'from checkpoints.') - - if args.npu is not None: - warnings.warn('You have chosen a specific NPU. This will completely ' - 'disable data parallelism.') - - if args.dist_url == "env://" and args.world_size == -1: - args.world_size = int(os.environ["WORLD_SIZE"]) - - args.distributed = args.world_size > 1 or args.multiprocessing_distributed - - # ngpus_per_node = torch.cuda.device_count() - args.process_device_map = device_id_to_process_device_map(args.device_list) - if args.device == 'npu': - ngpus_per_node = len(args.process_device_map) - else: - ngpus_per_node = torch.cuda.device_count() - - if args.multiprocessing_distributed: - # Since we have ngpus_per_node processes per node, the total world_size - # needs to be adjusted accordingly - args.world_size = ngpus_per_node * args.world_size - # Use torch.multiprocessing.spawn to launch distributed processes: the - # main_worker process function - main_worker(args.local_rank, ngpus_per_node, args) - else: - # Simply call main_worker function - main_worker(args.npu, ngpus_per_node, args) - - - -def main_worker(npu, ngpus_per_node, args): - global best_acc1 - # args.npu = npu - - # args.npu = args.process_device_map[npu] - - if args.npu is not None: - print("Use NPU: {} for training".format(args.npu)) - - if args.distributed: - if args.dist_url == "env://" and args.rank == -1: - args.rank = int(os.environ["RANK"]) - if args.multiprocessing_distributed: - # For multiprocessing distributed training, rank needs to be the - # global rank among all the processes - args.rank = args.rank * ngpus_per_node + npu - if args.device == 'npu': - os.environ['MASTER_ADDR'] = '127.0.0.1' # args.addr - os.environ['MASTER_PORT'] = '29688' - dist.init_process_group(backend=args.dist_backend, # init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - else: - dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - # dist.init_process_group(backend=args.dist_backend, world_size=args.world_size, rank=args.rank) - # create model - if args.pretrained: - print("=> using pre-trained model '{}'".format(args.arch)) - CACHE_MODEL_URL = "/cache/model" - # ------------------modelarts modification---------------------- - os.makedirs(CACHE_MODEL_URL, exist_ok=True) - mox.file.copy_parallel(args.pretrained_weight, os.path.join(CACHE_MODEL_URL, "checkpoint.pth")) - # ------------------modelarts modification--------------------- - pth = os.path.join(CACHE_MODEL_URL, "checkpoint.pth") - - pretrained_dict = torch.load(pth, map_location="cpu") - - model = mnasnet.mnasnet1_0(num_classes=args.class_num) - if "classifier.1.weight" in pretrained_dict: - pretrained_dict.pop("classifier.1.weight") - pretrained_dict.pop("classifier.1.bias") - if "module.classifier.1.weight" in pretrained_dict: - pretrained_dict.pop("module.classifier.1.weight") - pretrained_dict.pop("module.classifier.1.bias") - model.load_state_dict(pretrained_dict, strict=False) - - else: - print("=> creating model '{}'".format('mansnet')) - model = mnasnet.mnasnet1_0(num_classes=args.class_num) - # model = models.__dict__[args.arch]() - - args.loss_scale = 128 - - loc = 'npu:{}'.format(args.npu) - torch.npu.set_device(loc) - - args.batch_size = int(args.batch_size / ngpus_per_node) - - - # -------modelarts modification------- - real_path = '/cache/data_url' - if not os.path.exists(real_path): - os.makedirs(real_path) - mox.file.copy_parallel(args.data_url, real_path) - print("training data finish copy to %s." % real_path) - # ---------modelarts modification----- - # Data loading code - traindir = os.path.join(real_path, 'train') - valdir = os.path.join(real_path, 'val') - normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], - std=[0.229, 0.224, 0.225]) - - train_dataset = datasets.ImageFolder( - traindir, - transforms.Compose([ - transforms.RandomResizedCrop(224), - transforms.RandomHorizontalFlip(), - transforms.ToTensor(), #Too slow - normalize, - ])) - val_dataset = datasets.ImageFolder(valdir, transforms.Compose([ - transforms.Resize(256), - transforms.CenterCrop(224), - transforms.ToTensor(), - normalize, - ])) - - train_sampler = None - val_sampler = None - if args.distributed: - train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) - # val_sampler = torch.utils.data.distributed.DistributedSampler(val_dataset) - - train_loader = torch.utils.data.DataLoader( - train_dataset, batch_size=args.batch_size, shuffle=(train_sampler is None), - num_workers=args.workers, - pin_memory=False, - sampler=train_sampler, - # collate_fn=fast_collate, - drop_last=True) - - val_loader = torch.utils.data.DataLoader( - val_dataset, - batch_size=args.batch_size, shuffle=False, - num_workers=args.workers, pin_memory=False, - sampler=val_sampler, - # collate_fn=fast_collate, - drop_last=True) - - model = model.to(loc) - # define loss function (criterion) and optimizer - # criterion = nn.CrossEntropyLoss().to(loc) - criterion = LabelSmoothingCrossEntropy().to(loc) - - optimizer = torch.optim.SGD(model.parameters(), args.lr, - momentum=args.momentum, - weight_decay=args.weight_decay, - nesterov=True) - lr_schedule = CosineWithWarmup(optimizer, args.warmup, 0.1, args.epochs) - - model, optimizer = amp.initialize(model, optimizer, opt_level="O1", loss_scale=args.loss_scale) - if args.multiprocessing_distributed: - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.npu], broadcast_buffers=False) - - # optionally resume from a checkpoint - if args.resume: - if os.path.isfile(args.resume): - print("=> loading checkpoint '{}'".format(args.resume)) - checkpoint = torch.load(args.resume, map_location=loc) - args.start_epoch = checkpoint['epoch'] - best_acc1 = checkpoint['best_acc1'] - model.load_state_dict(checkpoint['state_dict']) - optimizer.load_state_dict(checkpoint['optimizer']) - amp.load_state_dict(checkpoint['amp']) - print("=> loaded checkpoint '{}' (epoch {})" - .format(args.resume, checkpoint['epoch'])) - else: - print("=> no checkpoint found at '{}'".format(args.resume)) - - cudnn.benchmark = True - - if args.evaluate: - validate(val_loader, model, criterion, args) - return - - for epoch in range(args.start_epoch, args.epochs): - if args.distributed: - train_sampler.set_epoch(epoch) - lr_schedule.step(epoch) - if args.rank == 0: - print('lr = ', lr_schedule.get_lr()[0]) - file = open('log.txt', 'a') - print('lr = ', lr_schedule.get_lr()[0], file=file) - file.close() - - if args.run_prof: - runprof(train_loader, model, criterion, optimizer, epoch, args) - print('output to output.prof') - return - - # train for one epoch - train(train_loader, model, criterion, optimizer, epoch, args) - - # evaluate on validation set - acc1 = validate(val_loader, model, criterion, args) - - # remember best acc@1 and save checkpoint - is_best = acc1 >= best_acc1 - best_acc1 = max(acc1, best_acc1) - - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': args.arch, - 'state_dict': model.state_dict(), - 'best_acc1': best_acc1, - 'optimizer': optimizer.state_dict(), - 'amp': amp.state_dict(), - }, is_best, args) - - if args.onnx: - pth2onnx.convert_pth_to_onnx(args) - # --------------modelarts modification---------- - mox.file.copy_parallel(CACHE_TRAINING_URL, args.train_url) - # --------------modelarts modification end---------- - -def train(train_loader, model, criterion, optimizer, epoch, args): - batch_time = AverageMeter('Time', ':6.3f') - data_time = AverageMeter('Data', ':6.3f') - losses = AverageMeter('Loss', ':.4e') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - FPS = AverageMeter('FPS', ':6.2f') - progress = ProgressMeter( - len(train_loader), - [batch_time, data_time, losses, top1, top5, FPS], - prefix="Epoch: [{}]".format(epoch), - fpath='./log.txt') - - # switch to train mode - model.train() - - end = time.time() - # prefetcher = data_prefetcher(train_loader) - # images, target = prefetcher.next() - # i = -1 - # while images is not None: - for i, (images, target) in enumerate(train_loader): - # i += 1 - # measure data loading time - data_time.update(time.time() - end) - - loc = 'npu:{}'.format(args.npu) - target = target.to(torch.int32) - images, target = images.to(loc, non_blocking=False), target.to(loc, non_blocking=False) - - # compute output - output = model(images) - loss = criterion(output, target) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # compute gradient and do SGD step - optimizer.zero_grad() - #loss.backward() - - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - - optimizer.step() - # measure elapsed time - batch_time_nw = time.time() - end; - if i >= 5: - batch_time.update(batch_time_nw) - if i >= 2: - batch_size = images.size(0) - FPS.update(batch_size / batch_time_nw * args.world_size) - - end = time.time() - if i % args.print_freq == 0 and args.rank == 0: - progress.display(i) - # images, target = prefetcher.next() - print('NPU: {}, solve {} batchs'.format(args.rank, i)) - - -def validate(val_loader, model, criterion, args): - batch_time = AverageMeter('Time', ':6.3f') - losses = AverageMeter('Loss', ':.4e') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - progress = ProgressMeter( - len(val_loader), - [batch_time, losses, top1, top5], - prefix='Test: ', - fpath='./log.txt') - - # switch to evaluate mode - model.eval() - - with torch.no_grad(): - end = time.time() - - # prefetcher = data_prefetcher(val_loader) - # images, target = prefetcher.next() - # i = -1 - # while images is not None: - for i, (images, target) in enumerate(val_loader): - # i += 1 - loc = 'npu:{}'.format(args.npu) - target = target.to(torch.int32) - images, target = images.to(loc, non_blocking=False), target.to(loc, non_blocking=False) - - # compute output - output = model(images) - loss = criterion(output, target) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # measure elapsed time - batch_time.update(time.time() - end) - end = time.time() - - if i % args.print_freq == 0 and args.rank == 0: - progress.display(i) - # images, target = prefetcher.next() - - print(' * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}' - .format(top1=top1, top5=top5)) - file = open('log.txt', 'a') - print(' * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}' - .format(top1=top1, top5=top5), - file=file) - file.close() - return top1.avg - - -def runprof(train_loader, model, criterion, optimizer, epoch, args): - # switch to train mode - model.train() - prefetcher = data_prefetcher(train_loader) - images, target = prefetcher.next() - i = -1 - while images is not None: - i += 1 - if args.npu is not None: - images = images.cuda(args.npu, non_blocking=True) - - if 'npu' in CALCULATE_DEVICE: - target = target.to(torch.int32) - images, target = images.to(CALCULATE_DEVICE, non_blocking=True), target.to(CALCULATE_DEVICE, non_blocking=True) - - if i >= 5: - with torch.autograd.profiler.profile(use_cuda=True) as prof: - out = model(images) - loss = criterion(out, target) - optimizer.zero_grad() - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - optimizer.step() - prof.export_chrome_trace("output.prof") - return - else: - output = model(images) - loss = criterion(output, target) - optimizer.zero_grad() - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - optimizer.step() - images, target = prefetcher.next() - - -def save_checkpoint(state, is_best, args, filename='checkpoint.pth.tar'): - if not os.path.exists(CACHE_TRAINING_URL): - os.makedirs(CACHE_TRAINING_URL, 0o755) - - checkpoint_save_path = os.path.join(CACHE_TRAINING_URL, filename) - torch.save(state, checkpoint_save_path) - if is_best: - # shutil.copyfile(filename, 'model_best.pth.tar') - args.is_best_name = args.train_url + 'model_best_acc%.4f_epoch%d.pth.tar' % (state['best_acc1'], state['epoch']) - mox.file.copy_parallel(checkpoint_save_path, args.is_best_name) - - -class LabelSmoothingCrossEntropy(nn.Module): - def __init__(self, eps=0.1, reduction='mean'): - super(LabelSmoothingCrossEntropy, self).__init__() - self.eps = eps - self.reduction = reduction - - def forward(self, output, target): - c = output.size()[-1] - log_preds = F.log_softmax(output, dim=-1) - if self.reduction == 'sum': - loss = -log_preds.sum() - else: - loss = -log_preds.sum(dim=-1) - if self.reduction == 'mean': - loss = loss.mean() - return loss * self.eps / c + (1 - self.eps) * F.nll_loss(log_preds, target, reduction=self.reduction) - - -class AverageMeter(object): - """Computes and stores the average and current value""" - - def __init__(self, name, fmt=':f'): - self.name = name - self.fmt = fmt - self.reset() - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - - def update(self, val, n=1): - self.val = val - self.sum += val * n - self.count += n - self.avg = self.sum / self.count - - def __str__(self): - fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' - return fmtstr.format(**self.__dict__) - - -class ProgressMeter(object): - def __init__(self, num_batches, meters, prefix="", fpath=None): - self.batch_fmtstr = self._get_batch_fmtstr(num_batches) - self.meters = meters - self.prefix = prefix - if fpath is not None: - self.file = open(fpath, 'a') - - def display(self, batch): - entries = [self.prefix + self.batch_fmtstr.format(batch)] - entries += [str(meter) for meter in self.meters] - print('\t'.join(entries)) - if self.file is not None: - self.file.write('\t'.join(entries)) - self.file.write('\n') - self.file.flush() - - def _get_batch_fmtstr(self, num_batches): - num_digits = len(str(num_batches // 1)) - fmt = '{:' + str(num_digits) + 'd}' - return '[' + fmt + '/' + fmt.format(num_batches) + ']' - - def close(self): - if self.file is not None: - self.file.close() - - -class CosineWithWarmup(torch.optim.lr_scheduler._LRScheduler): - """ Implements a schedule where the first few epochs are linear warmup, and - then there's cosine annealing after that.""" - - def __init__(self, optimizer: torch.optim.Optimizer, warmup_len: int, - warmup_start_multiplier: float, max_epochs: int, - last_epoch: int = -1): - if warmup_len < 0: - raise ValueError("Warmup can't be less than 0.") - self.warmup_len = warmup_len - if not (0.0 <= warmup_start_multiplier <= 1.0): - raise ValueError( - "Warmup start multiplier must be within [0.0, 1.0].") - self.warmup_start_multiplier = warmup_start_multiplier - if max_epochs < 1 or max_epochs < warmup_len: - raise ValueError("Max epochs must be longer than warm-up.") - self.max_epochs = max_epochs - self.cosine_len = self.max_epochs - self.warmup_len - self.eta_min = 0.0 # Final LR multiplier of cosine annealing - super().__init__(optimizer, last_epoch) - - def get_lr(self): - if self.last_epoch > self.max_epochs: - raise ValueError( - "Epoch may not be greater than max_epochs={}.".format( - self.max_epochs)) - if self.last_epoch < self.warmup_len or self.cosine_len == 0: - # We're in warm-up, increase LR linearly. End multiplier is implicit 1.0. - slope = (1.0 - self.warmup_start_multiplier) / self.warmup_len - lr_multiplier = self.warmup_start_multiplier + slope * self.last_epoch - else: - # We're in the cosine annealing part. Note that the implementation - # is different from the paper in that there's no additive part and - # the "low" LR is not limited by eta_min. Instead, eta_min is - # treated as a multiplier as well. The paper implementation is - # designed for SGDR. - cosine_epoch = self.last_epoch - self.warmup_len - lr_multiplier = self.eta_min + (1.0 - self.eta_min) * ( - 1 + math.cos(math.pi * cosine_epoch / self.cosine_len)) / 2 - assert lr_multiplier >= 0.0 - return [base_lr * lr_multiplier for base_lr in self.base_lrs] - - -def accuracy(output, target, topk=(1,)): - """Computes the accuracy over the k top predictions for the specified values of k""" - with torch.no_grad(): - maxk = max(topk) - batch_size = target.size(0) - - _, pred = output.topk(maxk, 1, True, True) - pred = pred.t() - correct = pred.eq(target.view(1, -1).expand_as(pred)) - - res = [] - for k in topk: - correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True) - res.append(correct_k.mul_(100.0 / batch_size)) - return res - - -def device_id_to_process_device_map(device_list): - devices = device_list.split(",") - devices = [int(x) for x in devices] - devices.sort() - - process_device_map = dict() - for process_id, device_id in enumerate(devices): - process_device_map[process_id] = device_id - - return process_device_map - - -def fast_collate(batch): - imgs = [img[0] for img in batch] - targets = torch.tensor([target[1] for target in batch], dtype=torch.int64) - w = imgs[0].size[0] - h = imgs[0].size[1] - tensor = torch.zeros((len(imgs), 3, h, w), dtype=torch.uint8) - for i, img in enumerate(imgs): - nump_array = np.asarray(img, dtype=np.uint8) - tens = torch.from_numpy(nump_array) - if (nump_array.ndim < 3): - nump_array = np.expand_dims(nump_array, axis=-1) - nump_array = np.rollaxis(nump_array, 2) - - tensor[i] += torch.from_numpy(nump_array) - - return tensor, targets - - -class data_prefetcher(): - def __init__(self, loader): - self.loader = iter(loader) - self.stream = torch.npu.Stream() - self.mean = torch.tensor([0.485 * 255, 0.456 * 255, 0.406 * 255]).npu().view(1, 3, 1, 1) - self.std = torch.tensor([0.229 * 255, 0.224 * 255, 0.225 * 255]).npu().view(1, 3, 1, 1) - # With Amp, it isn't necessary to manually convert data to half. - # if args.fp16: - # self.mean = self.mean.half() - # self.std = self.std.half() - self.preload() - - def preload(self): - try: - self.next_input, self.next_target = next(self.loader) - except StopIteration: - self.next_input = None - self.next_target = None - return - with torch.npu.stream(self.stream): - self.next_input = self.next_input.npu(non_blocking=True) - self.next_target = self.next_target.npu(non_blocking=True) - # With Amp, it isn't necessary to manually convert data to half. - # if args.fp16: - # self.next_input = self.next_input.half() - # else: - self.next_input = self.next_input.float() - self.next_input = self.next_input.sub_(self.mean).div_(self.std) - - def next(self): - torch.npu.current_stream().wait_stream(self.stream) - input = self.next_input - target = self.next_target - self.preload() - return input, target - -if __name__ == '__main__': - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import os +import random +import shutil +import time +import warnings +import math +import glob +import numpy as np +import sys + +import torch +import torch.npu +import torch.nn as nn +import torch.nn.parallel +import torch.backends.cudnn as cudnn +import torch.distributed as dist +import torch.nn.functional as F +import torch.optim +import torch.utils.data +import torch.utils.data.distributed +import torchvision.transforms as transforms +import torchvision.datasets as datasets +import torchvision.models as models +from collections import OrderedDict +import torch.onnx +import pth2onnx +sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../')) +import mnasnet + +# modelarts modification +import moxing as mox + + +try: + from apex.parallel import DistributedDataParallel as DDP + from apex.fp16_utils import * + from apex import amp, optimizers +except ImportError: + raise ImportError("Please install apex from https://www.github.com/nvidia/apex to run this example.") + + +parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') +parser.add_argument('--data', metavar='DIR', + help='path to dataset') +parser.add_argument('--device', default='npu', type=str, help='npu or gpu') +parser.add_argument('--device-list', default='0,1,2,3,4,5,6,7', type=str, help='device id list') +parser.add_argument('-a', '--arch', metavar='ARCH', default='resnet18') +parser.add_argument('-j', '--workers', default=4, type=int, metavar='N', + help='number of data loading workers (default: 4)') +parser.add_argument('--epochs', default=90, type=int, metavar='N', + help='number of total epochs to run') +parser.add_argument('--start-epoch', default=0, type=int, metavar='N', + help='manual epoch number (useful on restarts)') +parser.add_argument('-b', '--batch-size', default=256, type=int, + metavar='N', + help='mini-batch size (default: 256), this is the total ' + 'batch size of all NPUs on the current node when ' + 'using Data Parallel or Distributed Data Parallel') + +parser.add_argument('--label-smoothing', '--ls', default=0.1, type=float) + +parser.add_argument('--lr', '--learning-rate', default=0.1, type=float, + metavar='LR', help='initial learning rate', dest='lr') +parser.add_argument('--momentum', default=0.9, type=float, metavar='M', + help='momentum') +parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, + metavar='W', help='weight decay (default: 1e-4)', + dest='weight_decay') +parser.add_argument('-p', '--print-freq', default=10, type=int, + metavar='N', help='print frequency (default: 10)') +parser.add_argument('--resume', default='', type=str, metavar='PATH', + help='path to latest checkpoint (default: none)') +parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', + help='evaluate model on validation set') +parser.add_argument('--pretrained', dest='pretrained', action='store_true', + help='use pre-trained model') +parser.add_argument('--world-size', default=-1, type=int, + help='number of nodes for distributed training') +parser.add_argument('--rank', default=-1, type=int, + help='node rank for distributed training') +parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str, + help='url used to set up distributed training') +parser.add_argument('--dist-backend', default='nccl', type=str, + help='distributed backend') +parser.add_argument('--seed', default=1, type=int, + help='seed for initializing training. ') +parser.add_argument('--npu', default=0, type=int, + help='NPU id to use.') +parser.add_argument('--warmup', default=0, type=int, + help='Warmup epochs.') +parser.add_argument('--local_rank', default=0, type=int, + help="rank id of process") +parser.add_argument('--run-prof', action='store_true', help='only for prof') +parser.add_argument('--multiprocessing-distributed', action='store_true', + help='Use multi-processing distributed training to launch ' + 'N processes per node, which has N NPUs. This is the ' + 'fastest way to use PyTorch for either single node or ' + 'multi node data parallel training') + +parser.add_argument('--pretrained_weight', dest='pretrained_weight', + help='pretrained weight dir') + + +# modelarts +parser.add_argument('--data_url', metavar='DIR', default='/cache/data_url', help='path to dataset') +parser.add_argument('--train_url', default="/cache/training", + type=str, + help="setting dir of training output") +parser.add_argument('--onnx', default=True, action='store_true', + help="convert pth model to onnx") +parser.add_argument('--class_num', default=1000, type=int, + help='number of class') + + +best_acc1 = 0 +CALCULATE_DEVICE = "npu:0" +CACHE_TRAINING_URL = "/cache/training" +is_best_name = "checkpoint.pth.tar" +def main(): + args = parser.parse_args() + print('===========================') + print(args) + print('===========================') + + if args.npu is None: + args.npu = 0 + global CALCULATE_DEVICE + if 'npu' in CALCULATE_DEVICE: + torch.npu.set_device(CALCULATE_DEVICE) + + if args.seed is not None: + random.seed(args.seed) + torch.manual_seed(args.seed) + cudnn.deterministic = True + warnings.warn('You have chosen to seed training. ' + 'This will turn on the CUDNN deterministic setting, ' + 'which can slow down your training considerably! ' + 'You may see unexpected behavior when restarting ' + 'from checkpoints.') + + if args.npu is not None: + warnings.warn('You have chosen a specific NPU. This will completely ' + 'disable data parallelism.') + + if args.dist_url == "env://" and args.world_size == -1: + args.world_size = int(os.environ["WORLD_SIZE"]) + + args.distributed = args.world_size > 1 or args.multiprocessing_distributed + + # ngpus_per_node = torch.cuda.device_count() + args.process_device_map = device_id_to_process_device_map(args.device_list) + if args.device == 'npu': + ngpus_per_node = len(args.process_device_map) + else: + ngpus_per_node = torch.cuda.device_count() + + if args.multiprocessing_distributed: + # Since we have ngpus_per_node processes per node, the total world_size + # needs to be adjusted accordingly + args.world_size = ngpus_per_node * args.world_size + # Use torch.multiprocessing.spawn to launch distributed processes: the + # main_worker process function + main_worker(args.local_rank, ngpus_per_node, args) + else: + # Simply call main_worker function + main_worker(args.npu, ngpus_per_node, args) + + + +def main_worker(npu, ngpus_per_node, args): + global best_acc1 + # args.npu = npu + + # args.npu = args.process_device_map[npu] + + if args.npu is not None: + print("Use NPU: {} for training".format(args.npu)) + + if args.distributed: + if args.dist_url == "env://" and args.rank == -1: + args.rank = int(os.environ["RANK"]) + if args.multiprocessing_distributed: + # For multiprocessing distributed training, rank needs to be the + # global rank among all the processes + args.rank = args.rank * ngpus_per_node + npu + if args.device == 'npu': + os.environ['MASTER_ADDR'] = '127.0.0.1' # args.addr + os.environ['MASTER_PORT'] = '29688' + dist.init_process_group(backend=args.dist_backend, # init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + else: + dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + # dist.init_process_group(backend=args.dist_backend, world_size=args.world_size, rank=args.rank) + # create model + if args.pretrained: + print("=> using pre-trained model '{}'".format(args.arch)) + CACHE_MODEL_URL = "/cache/model" + # ------------------modelarts modification---------------------- + os.makedirs(CACHE_MODEL_URL, exist_ok=True) + mox.file.copy_parallel(args.pretrained_weight, os.path.join(CACHE_MODEL_URL, "checkpoint.pth")) + # ------------------modelarts modification--------------------- + pth = os.path.join(CACHE_MODEL_URL, "checkpoint.pth") + + pretrained_dict = torch.load(pth, map_location="cpu") + + model = mnasnet.mnasnet1_0(num_classes=args.class_num) + if "classifier.1.weight" in pretrained_dict: + pretrained_dict.pop("classifier.1.weight") + pretrained_dict.pop("classifier.1.bias") + if "module.classifier.1.weight" in pretrained_dict: + pretrained_dict.pop("module.classifier.1.weight") + pretrained_dict.pop("module.classifier.1.bias") + model.load_state_dict(pretrained_dict, strict=False) + + else: + print("=> creating model '{}'".format('mansnet')) + model = mnasnet.mnasnet1_0(num_classes=args.class_num) + # model = models.__dict__[args.arch]() + + args.loss_scale = 128 + + loc = 'npu:{}'.format(args.npu) + torch.npu.set_device(loc) + + args.batch_size = int(args.batch_size / ngpus_per_node) + + + # -------modelarts modification------- + real_path = '/cache/data_url' + if not os.path.exists(real_path): + os.makedirs(real_path) + mox.file.copy_parallel(args.data_url, real_path) + print("training data finish copy to %s." % real_path) + # ---------modelarts modification----- + # Data loading code + traindir = os.path.join(real_path, 'train') + valdir = os.path.join(real_path, 'val') + normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]) + + train_dataset = datasets.ImageFolder( + traindir, + transforms.Compose([ + transforms.RandomResizedCrop(224), + transforms.RandomHorizontalFlip(), + transforms.ToTensor(), #Too slow + normalize, + ])) + val_dataset = datasets.ImageFolder(valdir, transforms.Compose([ + transforms.Resize(256), + transforms.CenterCrop(224), + transforms.ToTensor(), + normalize, + ])) + + train_sampler = None + val_sampler = None + if args.distributed: + train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) + # val_sampler = torch.utils.data.distributed.DistributedSampler(val_dataset) + + train_loader = torch.utils.data.DataLoader( + train_dataset, batch_size=args.batch_size, shuffle=(train_sampler is None), + num_workers=args.workers, + pin_memory=False, + sampler=train_sampler, + # collate_fn=fast_collate, + drop_last=True) + + val_loader = torch.utils.data.DataLoader( + val_dataset, + batch_size=args.batch_size, shuffle=False, + num_workers=args.workers, pin_memory=False, + sampler=val_sampler, + # collate_fn=fast_collate, + drop_last=True) + + model = model.to(loc) + # define loss function (criterion) and optimizer + # criterion = nn.CrossEntropyLoss().to(loc) + criterion = LabelSmoothingCrossEntropy().to(loc) + + optimizer = torch.optim.SGD(model.parameters(), args.lr, + momentum=args.momentum, + weight_decay=args.weight_decay, + nesterov=True) + lr_schedule = CosineWithWarmup(optimizer, args.warmup, 0.1, args.epochs) + + model, optimizer = amp.initialize(model, optimizer, opt_level="O1", loss_scale=args.loss_scale) + if args.multiprocessing_distributed: + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.npu], broadcast_buffers=False) + + # optionally resume from a checkpoint + if args.resume: + if os.path.isfile(args.resume): + print("=> loading checkpoint '{}'".format(args.resume)) + checkpoint = torch.load(args.resume, map_location=loc) + args.start_epoch = checkpoint['epoch'] + best_acc1 = checkpoint['best_acc1'] + model.load_state_dict(checkpoint['state_dict']) + optimizer.load_state_dict(checkpoint['optimizer']) + amp.load_state_dict(checkpoint['amp']) + print("=> loaded checkpoint '{}' (epoch {})" + .format(args.resume, checkpoint['epoch'])) + else: + print("=> no checkpoint found at '{}'".format(args.resume)) + + cudnn.benchmark = True + + if args.evaluate: + validate(val_loader, model, criterion, args) + return + + for epoch in range(args.start_epoch, args.epochs): + if args.distributed: + train_sampler.set_epoch(epoch) + lr_schedule.step(epoch) + if args.rank == 0: + print('lr = ', lr_schedule.get_lr()[0]) + file = open('log.txt', 'a') + print('lr = ', lr_schedule.get_lr()[0], file=file) + file.close() + + if args.run_prof: + runprof(train_loader, model, criterion, optimizer, epoch, args) + print('output to output.prof') + return + + # train for one epoch + train(train_loader, model, criterion, optimizer, epoch, args) + + # evaluate on validation set + acc1 = validate(val_loader, model, criterion, args) + + # remember best acc@1 and save checkpoint + is_best = acc1 >= best_acc1 + best_acc1 = max(acc1, best_acc1) + + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': args.arch, + 'state_dict': model.state_dict(), + 'best_acc1': best_acc1, + 'optimizer': optimizer.state_dict(), + 'amp': amp.state_dict(), + }, is_best, args) + + if args.onnx: + pth2onnx.convert_pth_to_onnx(args) + # --------------modelarts modification---------- + mox.file.copy_parallel(CACHE_TRAINING_URL, args.train_url) + # --------------modelarts modification end---------- + +def train(train_loader, model, criterion, optimizer, epoch, args): + batch_time = AverageMeter('Time', ':6.3f') + data_time = AverageMeter('Data', ':6.3f') + losses = AverageMeter('Loss', ':.4e') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + FPS = AverageMeter('FPS', ':6.2f') + progress = ProgressMeter( + len(train_loader), + [batch_time, data_time, losses, top1, top5, FPS], + prefix="Epoch: [{}]".format(epoch), + fpath='./log.txt') + + # switch to train mode + model.train() + + end = time.time() + # prefetcher = data_prefetcher(train_loader) + # images, target = prefetcher.next() + # i = -1 + # while images is not None: + for i, (images, target) in enumerate(train_loader): + # i += 1 + # measure data loading time + data_time.update(time.time() - end) + + loc = 'npu:{}'.format(args.npu) + target = target.to(torch.int32) + images, target = images.to(loc, non_blocking=False), target.to(loc, non_blocking=False) + + # compute output + output = model(images) + loss = criterion(output, target) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # compute gradient and do SGD step + optimizer.zero_grad() + #loss.backward() + + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + + optimizer.step() + # measure elapsed time + batch_time_nw = time.time() - end; + if i >= 5: + batch_time.update(batch_time_nw) + if i >= 2: + batch_size = images.size(0) + FPS.update(batch_size / batch_time_nw * args.world_size) + + end = time.time() + if i % args.print_freq == 0 and args.rank == 0: + progress.display(i) + # images, target = prefetcher.next() + print('NPU: {}, solve {} batchs'.format(args.rank, i)) + + +def validate(val_loader, model, criterion, args): + batch_time = AverageMeter('Time', ':6.3f') + losses = AverageMeter('Loss', ':.4e') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + progress = ProgressMeter( + len(val_loader), + [batch_time, losses, top1, top5], + prefix='Test: ', + fpath='./log.txt') + + # switch to evaluate mode + model.eval() + + with torch.no_grad(): + end = time.time() + + # prefetcher = data_prefetcher(val_loader) + # images, target = prefetcher.next() + # i = -1 + # while images is not None: + for i, (images, target) in enumerate(val_loader): + # i += 1 + loc = 'npu:{}'.format(args.npu) + target = target.to(torch.int32) + images, target = images.to(loc, non_blocking=False), target.to(loc, non_blocking=False) + + # compute output + output = model(images) + loss = criterion(output, target) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # measure elapsed time + batch_time.update(time.time() - end) + end = time.time() + + if i % args.print_freq == 0 and args.rank == 0: + progress.display(i) + # images, target = prefetcher.next() + + print(' * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}' + .format(top1=top1, top5=top5)) + file = open('log.txt', 'a') + print(' * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}' + .format(top1=top1, top5=top5), + file=file) + file.close() + return top1.avg + + +def runprof(train_loader, model, criterion, optimizer, epoch, args): + # switch to train mode + model.train() + prefetcher = data_prefetcher(train_loader) + images, target = prefetcher.next() + i = -1 + while images is not None: + i += 1 + if args.npu is not None: + images = images.cuda(args.npu, non_blocking=True) + + if 'npu' in CALCULATE_DEVICE: + target = target.to(torch.int32) + images, target = images.to(CALCULATE_DEVICE, non_blocking=True), target.to(CALCULATE_DEVICE, non_blocking=True) + + if i >= 5: + with torch.autograd.profiler.profile(use_cuda=True) as prof: + out = model(images) + loss = criterion(out, target) + optimizer.zero_grad() + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + optimizer.step() + prof.export_chrome_trace("output.prof") + return + else: + output = model(images) + loss = criterion(output, target) + optimizer.zero_grad() + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + optimizer.step() + images, target = prefetcher.next() + + +def save_checkpoint(state, is_best, args, filename='checkpoint.pth.tar'): + if not os.path.exists(CACHE_TRAINING_URL): + os.makedirs(CACHE_TRAINING_URL, 0o755) + + checkpoint_save_path = os.path.join(CACHE_TRAINING_URL, filename) + torch.save(state, checkpoint_save_path) + if is_best: + # shutil.copyfile(filename, 'model_best.pth.tar') + args.is_best_name = args.train_url + 'model_best_acc%.4f_epoch%d.pth.tar' % (state['best_acc1'], state['epoch']) + mox.file.copy_parallel(checkpoint_save_path, args.is_best_name) + + +class LabelSmoothingCrossEntropy(nn.Module): + def __init__(self, eps=0.1, reduction='mean'): + super(LabelSmoothingCrossEntropy, self).__init__() + self.eps = eps + self.reduction = reduction + + def forward(self, output, target): + c = output.size()[-1] + log_preds = F.log_softmax(output, dim=-1) + if self.reduction == 'sum': + loss = -log_preds.sum() + else: + loss = -log_preds.sum(dim=-1) + if self.reduction == 'mean': + loss = loss.mean() + return loss * self.eps / c + (1 - self.eps) * F.nll_loss(log_preds, target, reduction=self.reduction) + + +class AverageMeter(object): + """Computes and stores the average and current value""" + + def __init__(self, name, fmt=':f'): + self.name = name + self.fmt = fmt + self.reset() + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + self.val = val + self.sum += val * n + self.count += n + self.avg = self.sum / self.count + + def __str__(self): + fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' + return fmtstr.format(**self.__dict__) + + +class ProgressMeter(object): + def __init__(self, num_batches, meters, prefix="", fpath=None): + self.batch_fmtstr = self._get_batch_fmtstr(num_batches) + self.meters = meters + self.prefix = prefix + if fpath is not None: + self.file = open(fpath, 'a') + + def display(self, batch): + entries = [self.prefix + self.batch_fmtstr.format(batch)] + entries += [str(meter) for meter in self.meters] + print('\t'.join(entries)) + if self.file is not None: + self.file.write('\t'.join(entries)) + self.file.write('\n') + self.file.flush() + + def _get_batch_fmtstr(self, num_batches): + num_digits = len(str(num_batches // 1)) + fmt = '{:' + str(num_digits) + 'd}' + return '[' + fmt + '/' + fmt.format(num_batches) + ']' + + def close(self): + if self.file is not None: + self.file.close() + + +class CosineWithWarmup(torch.optim.lr_scheduler._LRScheduler): + """ Implements a schedule where the first few epochs are linear warmup, and + then there's cosine annealing after that.""" + + def __init__(self, optimizer: torch.optim.Optimizer, warmup_len: int, + warmup_start_multiplier: float, max_epochs: int, + last_epoch: int = -1): + if warmup_len < 0: + raise ValueError("Warmup can't be less than 0.") + self.warmup_len = warmup_len + if not (0.0 <= warmup_start_multiplier <= 1.0): + raise ValueError( + "Warmup start multiplier must be within [0.0, 1.0].") + self.warmup_start_multiplier = warmup_start_multiplier + if max_epochs < 1 or max_epochs < warmup_len: + raise ValueError("Max epochs must be longer than warm-up.") + self.max_epochs = max_epochs + self.cosine_len = self.max_epochs - self.warmup_len + self.eta_min = 0.0 # Final LR multiplier of cosine annealing + super().__init__(optimizer, last_epoch) + + def get_lr(self): + if self.last_epoch > self.max_epochs: + raise ValueError( + "Epoch may not be greater than max_epochs={}.".format( + self.max_epochs)) + if self.last_epoch < self.warmup_len or self.cosine_len == 0: + # We're in warm-up, increase LR linearly. End multiplier is implicit 1.0. + slope = (1.0 - self.warmup_start_multiplier) / self.warmup_len + lr_multiplier = self.warmup_start_multiplier + slope * self.last_epoch + else: + # We're in the cosine annealing part. Note that the implementation + # is different from the paper in that there's no additive part and + # the "low" LR is not limited by eta_min. Instead, eta_min is + # treated as a multiplier as well. The paper implementation is + # designed for SGDR. + cosine_epoch = self.last_epoch - self.warmup_len + lr_multiplier = self.eta_min + (1.0 - self.eta_min) * ( + 1 + math.cos(math.pi * cosine_epoch / self.cosine_len)) / 2 + assert lr_multiplier >= 0.0 + return [base_lr * lr_multiplier for base_lr in self.base_lrs] + + +def accuracy(output, target, topk=(1,)): + """Computes the accuracy over the k top predictions for the specified values of k""" + with torch.no_grad(): + maxk = max(topk) + batch_size = target.size(0) + + _, pred = output.topk(maxk, 1, True, True) + pred = pred.t() + correct = pred.eq(target.view(1, -1).expand_as(pred)) + + res = [] + for k in topk: + correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True) + res.append(correct_k.mul_(100.0 / batch_size)) + return res + + +def device_id_to_process_device_map(device_list): + devices = device_list.split(",") + devices = [int(x) for x in devices] + devices.sort() + + process_device_map = dict() + for process_id, device_id in enumerate(devices): + process_device_map[process_id] = device_id + + return process_device_map + + +def fast_collate(batch): + imgs = [img[0] for img in batch] + targets = torch.tensor([target[1] for target in batch], dtype=torch.int64) + w = imgs[0].size[0] + h = imgs[0].size[1] + tensor = torch.zeros((len(imgs), 3, h, w), dtype=torch.uint8) + for i, img in enumerate(imgs): + nump_array = np.asarray(img, dtype=np.uint8) + tens = torch.from_numpy(nump_array) + if (nump_array.ndim < 3): + nump_array = np.expand_dims(nump_array, axis=-1) + nump_array = np.rollaxis(nump_array, 2) + + tensor[i] += torch.from_numpy(nump_array) + + return tensor, targets + + +class data_prefetcher(): + def __init__(self, loader): + self.loader = iter(loader) + self.stream = torch.npu.Stream() + self.mean = torch.tensor([0.485 * 255, 0.456 * 255, 0.406 * 255]).npu().view(1, 3, 1, 1) + self.std = torch.tensor([0.229 * 255, 0.224 * 255, 0.225 * 255]).npu().view(1, 3, 1, 1) + # With Amp, it isn't necessary to manually convert data to half. + # if args.fp16: + # self.mean = self.mean.half() + # self.std = self.std.half() + self.preload() + + def preload(self): + try: + self.next_input, self.next_target = next(self.loader) + except StopIteration: + self.next_input = None + self.next_target = None + return + with torch.npu.stream(self.stream): + self.next_input = self.next_input.npu(non_blocking=True) + self.next_target = self.next_target.npu(non_blocking=True) + # With Amp, it isn't necessary to manually convert data to half. + # if args.fp16: + # self.next_input = self.next_input.half() + # else: + self.next_input = self.next_input.float() + self.next_input = self.next_input.sub_(self.mean).div_(self.std) + + def next(self): + torch.npu.current_stream().wait_stream(self.stream) + input = self.next_input + target = self.next_target + self.preload() + return input, target + +if __name__ == '__main__': + main() diff --git a/PyTorch/contrib/cv/classification/MobileNet/Dockerfile b/PyTorch/contrib/cv/classification/MobileNet/Dockerfile old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/LICENSE b/PyTorch/contrib/cv/classification/MobileNet/LICENSE old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/README.md b/PyTorch/contrib/cv/classification/MobileNet/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/demo.py b/PyTorch/contrib/cv/classification/MobileNet/demo.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/docker_start.sh b/PyTorch/contrib/cv/classification/MobileNet/docker_start.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/mobilenet.py b/PyTorch/contrib/cv/classification/MobileNet/mobilenet.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/modelzoo_level.txt b/PyTorch/contrib/cv/classification/MobileNet/modelzoo_level.txt old mode 100755 new mode 100644 index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 --- a/PyTorch/contrib/cv/classification/MobileNet/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/MobileNet/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/MobileNet/pthtar2onnx.py b/PyTorch/contrib/cv/classification/MobileNet/pthtar2onnx.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/requirements.txt b/PyTorch/contrib/cv/classification/MobileNet/requirements.txt old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/scripts/eval.sh b/PyTorch/contrib/cv/classification/MobileNet/scripts/eval.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/scripts/run_2onnx.sh b/PyTorch/contrib/cv/classification/MobileNet/scripts/run_2onnx.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/scripts/run_demo.sh b/PyTorch/contrib/cv/classification/MobileNet/scripts/run_demo.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/scripts/train_1p.sh b/PyTorch/contrib/cv/classification/MobileNet/scripts/train_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/scripts/train_8p.sh b/PyTorch/contrib/cv/classification/MobileNet/scripts/train_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/test/env_npu.sh b/PyTorch/contrib/cv/classification/MobileNet/test/env_npu.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/test/run_2onnx.sh b/PyTorch/contrib/cv/classification/MobileNet/test/run_2onnx.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/test/run_demo.sh b/PyTorch/contrib/cv/classification/MobileNet/test/run_demo.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/test/train_eval_8p.sh b/PyTorch/contrib/cv/classification/MobileNet/test/train_eval_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/test/train_full_1p.sh b/PyTorch/contrib/cv/classification/MobileNet/test/train_full_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/test/train_full_8p.sh b/PyTorch/contrib/cv/classification/MobileNet/test/train_full_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/test/train_performance_1p.sh b/PyTorch/contrib/cv/classification/MobileNet/test/train_performance_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/MobileNet/test/train_performance_8p.sh b/PyTorch/contrib/cv/classification/MobileNet/test/train_performance_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/OSNet/README.md b/PyTorch/contrib/cv/classification/OSNet/README.md index 25282368758f9ef3c8c1fc56b28bc62a2906c33f..d3978104b1af8d287f53d6ed92150293bb47a4cb 100644 --- a/PyTorch/contrib/cv/classification/OSNet/README.md +++ b/PyTorch/contrib/cv/classification/OSNet/README.md @@ -1,72 +1,72 @@ -# OSNet - -This implements training of OSNet on the Market-1501 dataset, mainly modified from [KaiyangZhou/deep-person-reid](https://github.com/KaiyangZhou/deep-person-reid). - -## OSNet Detail - -As of the current date, Ascend-Pytorch is still inefficient for contiguous operations.Therefore, OSNet is re-implemented using semantics such as custom OP. - - -## Requirements - -- Install PyTorch ([pytorch.org](http://pytorch.org)) - - -- `pip install -r requirements.txt` - -- Install torchreid - - - ~~~python - python setup.py develop - ~~~ - -- Download the Market-1501 dataset from https://paperswithcode.com/dataset/market-1501 - - - ~~~shell - unzip Market-1501-v15.09.15.zip - ~~~ - -- Move Market-1501 dataset to 'reid-data' path - - - ~~~shell - mkdir path_to_osnet/reid-data/ - mv Market-1501-v15.09.15 path_to_osnet/reid-data/market1501 - ~~~ -## Training - -To train a model, run `main.py` with the desired model architecture and the path to the ImageNet dataset: - -```bash -# training 1p accuracy -bash test/train_full_1p.sh - -# training 1p performance -bash test/train_performance_1p.sh - -# training 8p accuracy -bash test/train_full_8p.sh - -# training 8p performance -bash test/train_performance_8p.sh - -# finetuning -bash test/train_finetune_1p.sh --data_path=real_data_path --weight=real_weight_path - -# Online inference demo -python demo.py -## 备注: 识别前后图片保存到 `inference/` 文件夹下 - -# To ONNX -python pthtar2onnx.py -``` - -## OSNet training result - - -| | mAP | AMP_Type | Epochs | FPS | -| :----: | :--: | :------: | :----: | :------: | -| 1p-GPU | - | O2 | 1 | 371.383 | -| 1p-NPU | - | O2 | 1 | 366.464 | -| 8p-GPU | 80.3 | O2 | 350 | 1045.535 | -| 8p-NPU | 80.2 | O2 | 350 | 1091.358 | - +# OSNet + +This implements training of OSNet on the Market-1501 dataset, mainly modified from [KaiyangZhou/deep-person-reid](https://github.com/KaiyangZhou/deep-person-reid). + +## OSNet Detail + +As of the current date, Ascend-Pytorch is still inefficient for contiguous operations.Therefore, OSNet is re-implemented using semantics such as custom OP. + + +## Requirements + +- Install PyTorch ([pytorch.org](http://pytorch.org)) + + +- `pip install -r requirements.txt` + +- Install torchreid + + - ~~~python + python setup.py develop + ~~~ + +- Download the Market-1501 dataset from https://paperswithcode.com/dataset/market-1501 + + - ~~~shell + unzip Market-1501-v15.09.15.zip + ~~~ + +- Move Market-1501 dataset to 'reid-data' path + + - ~~~shell + mkdir path_to_osnet/reid-data/ + mv Market-1501-v15.09.15 path_to_osnet/reid-data/market1501 + ~~~ +## Training + +To train a model, run `main.py` with the desired model architecture and the path to the ImageNet dataset: + +```bash +# training 1p accuracy +bash test/train_full_1p.sh + +# training 1p performance +bash test/train_performance_1p.sh + +# training 8p accuracy +bash test/train_full_8p.sh + +# training 8p performance +bash test/train_performance_8p.sh + +# finetuning +bash test/train_finetune_1p.sh --data_path=real_data_path --weight=real_weight_path + +# Online inference demo +python demo.py +## 备注: 识别前后图片保存到 `inference/` 文件夹下 + +# To ONNX +python pthtar2onnx.py +``` + +## OSNet training result + + +| | mAP | AMP_Type | Epochs | FPS | +| :----: | :--: | :------: | :----: | :------: | +| 1p-GPU | - | O2 | 1 | 371.383 | +| 1p-NPU | - | O2 | 1 | 366.464 | +| 8p-GPU | 80.3 | O2 | 350 | 1045.535 | +| 8p-NPU | 80.2 | O2 | 350 | 1091.358 | + diff --git a/PyTorch/contrib/cv/classification/OSNet/main.py b/PyTorch/contrib/cv/classification/OSNet/main.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/OSNet/torchreid/metrics/rank_cylib/__init__.py b/PyTorch/contrib/cv/classification/OSNet/torchreid/metrics/rank_cylib/__init__.py index ec62d364d8b38dbbf3b84560aa33dccabf2ca1a7..f3bbfaaf4fd8806d74ba09433bd0b9d3dbee28d4 100644 --- a/PyTorch/contrib/cv/classification/OSNet/torchreid/metrics/rank_cylib/__init__.py +++ b/PyTorch/contrib/cv/classification/OSNet/torchreid/metrics/rank_cylib/__init__.py @@ -1,47 +1,47 @@ -""" -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - - -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the BSD 3-Clause License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://spdx.org/licenses/BSD-3-Clause.html - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. +""" +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the BSD 3-Clause License (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://spdx.org/licenses/BSD-3-Clause.html + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. """ \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/PCB/README.md b/PyTorch/contrib/cv/classification/PCB/README.md index 1ea64639bac4bb35baec79266531e0cdc0c4c6a2..5bbfba757ea60c5dc5627687b1838750196655c2 100644 --- a/PyTorch/contrib/cv/classification/PCB/README.md +++ b/PyTorch/contrib/cv/classification/PCB/README.md @@ -1,61 +1,61 @@ -# PCB - -This implements training of PCB on the Market-1501 dataset, mainly modified from [syfafterzy/PCB_RPP_for_reID](https://github.com/syfafterzy/PCB_RPP_for_reID). - -## PCB Detail - -As of the current date, Ascend-Pytorch is still inefficient for contiguous operations.Therefore, PCB is re-implemented using semantics such as custom OP. - - -## Requirements - -- Install PyTorch ([pytorch.org](http://pytorch.org)) - - - ~~~ - PyTorch版本:CANN 5.0.T205 PT>=20210618 - ~~~ - -- `pip install -r requirements.txt` - -- Download the Market-1501 dataset from https://paperswithcode.com/dataset/market-1501 - - - ~~~shell - unzip Market-1501-v15.09.15.zip - ~~~ - -## Training - -To train a model, run `main.py` with the desired model architecture and the path to the ImageNet dataset: - -```bash -# training 1p accuracy -bash scripts/train_full_1p.sh --data_path=real_data_path - -# training 1p performance -bash scripts/train_performance_1p.sh --data_path=real_data_path - -# training 8p accuracy -bash scripts/train_full_8p.sh --data_path=real_data_path - -# training 8p performance -bash scripts/train_performance_8p.sh --data_path=real_data_path - -# Online inference demo -python demo.py --data_path real_data_path --device npu -## 备注: 识别前后图片保存到 `inference/` 文件夹下 - -# To ONNX -python pthtar2onnx.py - -``` - -## PCB training result - - -| | mAP | AMP_Type | Epochs | FPS | -| :----: | :--: | :------: | :----: | :------: | -| 1p-GPU | - | O2 | 1 | 568.431 | -| 1p-NPU | - | O2 | 1 | 571.723 | -| 8p-GPU | 77.2 | O2 | 60 | 3600.983 | -| 8p-NPU | 77.5 | O2 | 60 | 2750.401 | - +# PCB + +This implements training of PCB on the Market-1501 dataset, mainly modified from [syfafterzy/PCB_RPP_for_reID](https://github.com/syfafterzy/PCB_RPP_for_reID). + +## PCB Detail + +As of the current date, Ascend-Pytorch is still inefficient for contiguous operations.Therefore, PCB is re-implemented using semantics such as custom OP. + + +## Requirements + +- Install PyTorch ([pytorch.org](http://pytorch.org)) + + - ~~~ + PyTorch版本:CANN 5.0.T205 PT>=20210618 + ~~~ + +- `pip install -r requirements.txt` + +- Download the Market-1501 dataset from https://paperswithcode.com/dataset/market-1501 + + - ~~~shell + unzip Market-1501-v15.09.15.zip + ~~~ + +## Training + +To train a model, run `main.py` with the desired model architecture and the path to the ImageNet dataset: + +```bash +# training 1p accuracy +bash scripts/train_full_1p.sh --data_path=real_data_path + +# training 1p performance +bash scripts/train_performance_1p.sh --data_path=real_data_path + +# training 8p accuracy +bash scripts/train_full_8p.sh --data_path=real_data_path + +# training 8p performance +bash scripts/train_performance_8p.sh --data_path=real_data_path + +# Online inference demo +python demo.py --data_path real_data_path --device npu +## 备注: 识别前后图片保存到 `inference/` 文件夹下 + +# To ONNX +python pthtar2onnx.py + +``` + +## PCB training result + + +| | mAP | AMP_Type | Epochs | FPS | +| :----: | :--: | :------: | :----: | :------: | +| 1p-GPU | - | O2 | 1 | 568.431 | +| 1p-NPU | - | O2 | 1 | 571.723 | +| 8p-GPU | 77.2 | O2 | 60 | 3600.983 | +| 8p-NPU | 77.5 | O2 | 60 | 2750.401 | + diff --git a/PyTorch/contrib/cv/classification/PCB/README_raw.md b/PyTorch/contrib/cv/classification/PCB/README_raw.md index fb1ecd0cbc8ea48dd783d712cc9b6ad8d5548b0b..4cad0051b786313fd28ce14850cb45befdfeda20 100644 --- a/PyTorch/contrib/cv/classification/PCB/README_raw.md +++ b/PyTorch/contrib/cv/classification/PCB/README_raw.md @@ -1,51 +1,51 @@ -# Part-based Convolutional Baseline for Person Retrieval and the Refined Part Pooling - -Code for the paper [Beyond Part Models: Person Retrieval with Refined Part Pooling (and A Strong Convolutional Baseline)](https://arxiv.org/pdf/1711.09349.pdf). - -**This code is ONLY** released for academic use. - -## Preparation - - -**Prerequisite: Python 2.7 and Pytorch 0.3+** - -1. Install [Pytorch](https://pytorch.org/) - -2. Download dataset - a. Market-1501 [BaiduYun](https://pan.baidu.com/s/1ntIi2Op?errno=0&errmsg=Auth%20Login%20Sucess&&bduss=&ssnerror=0&traceid=) - b. DukeMTMC-reID[BaiduYun](https://pan.baidu.com/share/init?surl=jS0XM7Var5nQGcbf9xUztw) (password:bhbh) - c. Move them to ```~/datasets/Market-1501/(DukeMTMC-reID)``` - - -## train PCB - - -```sh train_PCB.sh``` -With Pytorch 0.4.0, we shall get about 93.0% rank-1 accuracy and 78.0% mAP on Market-1501. - - -## train RPP - - -```sh train_RPP.sh``` -With Pytorch 0.4.0, we shall get about 93.5% rank-1 accuracy and 81.5% mAP on Market-1501. - - -## Citiaion - - -Please cite this paper in your publications if it helps your research: - - -``` -@inproceedings{sun2018PCB, - author = {Yifan Sun and - Liang Zheng and - Yi Yang and - Qi Tian and - Shengjin Wang}, - title = {Beyond Part Models: Person Retrieval with Refined Part Pooling (and A Strong Convolutional Baseline)}, - booktitle = {ECCV}, - year = {2018}, -} -``` +# Part-based Convolutional Baseline for Person Retrieval and the Refined Part Pooling + +Code for the paper [Beyond Part Models: Person Retrieval with Refined Part Pooling (and A Strong Convolutional Baseline)](https://arxiv.org/pdf/1711.09349.pdf). + +**This code is ONLY** released for academic use. + +## Preparation + + +**Prerequisite: Python 2.7 and Pytorch 0.3+** + +1. Install [Pytorch](https://pytorch.org/) + +2. Download dataset + a. Market-1501 [BaiduYun](https://pan.baidu.com/s/1ntIi2Op?errno=0&errmsg=Auth%20Login%20Sucess&&bduss=&ssnerror=0&traceid=) + b. DukeMTMC-reID[BaiduYun](https://pan.baidu.com/share/init?surl=jS0XM7Var5nQGcbf9xUztw) (password:bhbh) + c. Move them to ```~/datasets/Market-1501/(DukeMTMC-reID)``` + + +## train PCB + + +```sh train_PCB.sh``` +With Pytorch 0.4.0, we shall get about 93.0% rank-1 accuracy and 78.0% mAP on Market-1501. + + +## train RPP + + +```sh train_RPP.sh``` +With Pytorch 0.4.0, we shall get about 93.5% rank-1 accuracy and 81.5% mAP on Market-1501. + + +## Citiaion + + +Please cite this paper in your publications if it helps your research: + + +``` +@inproceedings{sun2018PCB, + author = {Yifan Sun and + Liang Zheng and + Yi Yang and + Qi Tian and + Shengjin Wang}, + title = {Beyond Part Models: Person Retrieval with Refined Part Pooling (and A Strong Convolutional Baseline)}, + booktitle = {ECCV}, + year = {2018}, +} +``` diff --git a/PyTorch/contrib/cv/classification/RegNetY-1.6GF/utils/progress/setup.py b/PyTorch/contrib/cv/classification/RegNetY-1.6GF/utils/progress/setup.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/RegNetY-1.6GF/utils/progress/test_progress.py b/PyTorch/contrib/cv/classification/RegNetY-1.6GF/utils/progress/test_progress.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/RepVGG/arch.PNG b/PyTorch/contrib/cv/classification/RepVGG/arch.PNG deleted file mode 100644 index a17a7ac3926baf8c1108dee5bbcdaad2e2bf6a53..0000000000000000000000000000000000000000 Binary files a/PyTorch/contrib/cv/classification/RepVGG/arch.PNG and /dev/null differ diff --git a/PyTorch/contrib/cv/classification/RepVGG/speed_acc.PNG b/PyTorch/contrib/cv/classification/RepVGG/speed_acc.PNG deleted file mode 100644 index b785cfc6f159049a89281a940a894bbe0f542f68..0000000000000000000000000000000000000000 Binary files a/PyTorch/contrib/cv/classification/RepVGG/speed_acc.PNG and /dev/null differ diff --git a/PyTorch/contrib/cv/classification/RepVGG/table.PNG b/PyTorch/contrib/cv/classification/RepVGG/table.PNG deleted file mode 100644 index 242979935344fde11954ab33778132918a1a802f..0000000000000000000000000000000000000000 Binary files a/PyTorch/contrib/cv/classification/RepVGG/table.PNG and /dev/null differ diff --git a/PyTorch/contrib/cv/classification/ResNeXt-50-32x4d_ID1624_for_PyTorch/modelzoo_level.txt b/PyTorch/contrib/cv/classification/ResNeXt-50-32x4d_ID1624_for_PyTorch/modelzoo_level.txt index 5afcef9188bf9d39f1e34b45bd91324c6093137a..3117fffc3be7f5c479f10f09ba38a25c47739a00 100644 --- a/PyTorch/contrib/cv/classification/ResNeXt-50-32x4d_ID1624_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/ResNeXt-50-32x4d_ID1624_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/LICENSE b/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/LICENSE index 48eadfa5dfed22d5fdc95dfef2ca0625bc71338c..dfcc682b4b265c524b676eea5c382472c09f42c4 100644 --- a/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/LICENSE +++ b/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/LICENSE @@ -1,29 +1,29 @@ -BSD 3-Clause License - -Copyright (c) 2017, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +BSD 3-Clause License + +Copyright (c) 2017, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/README.md b/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/README.md index 8b557e9a40453be00dea57388ff47cbd92dceed2..c668ce4dedb2535b4c990e3064c13c9fd64c059f 100644 --- a/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/README.md +++ b/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/README.md @@ -1,50 +1,50 @@ -# ResNeXt-101-32x8d - -This implements training of ResNeXt-101-32x8d on the ImageNet dataset, mainly modified from [pytorch/examples](https://github.com/pytorch/examples/tree/master/imagenet). - -## ResNeXt-101-32x8d Detail - -As of the current date, Ascend-Pytorch is still inefficient for contiguous operations.Therefore, ResNeXt-101-32x8d is re-implemented using semantics such as custom OP. - - -## Requirements - -- Install PyTorch ([pytorch.org](http://pytorch.org)) -- `pip install -r requirements.txt` -- Download the ImageNet dataset from http://www.image-net.org/ - - Then, and move validation images to labeled subfolders, using [the following shell script](https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh) - -## Training - -To train a model, run `main.py` with the desired model architecture and the path to the ImageNet dataset: - -# 1p training 1p -bash ./test/train_full_1p.sh --data_path=xxx # training accuracy - -bash ./test/train_performance_1p.sh --data_path=xxx # training performance - -# 8p training 8p -bash ./test/train_full_8p.sh --data_path=xxx # training accuracy - -bash ./test/train_performance_8p.sh --data_path=xxx # training performance - -# eval default 8p, should support 1p -bash ./test/train_eval_8p.sh --data_path=xxx - -# O2 online inference demo -source scripts/set_npu_env.sh -python3.7.5 demo.py - -# O2 To ONNX -source scripts/set_npu_env.sh -python3.7.5 pthtar2onnx.py - - -``` - -## ResNeXt-101-32x8d training result - -| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | -| :------: | :------: | :------: | :------: | :------: | -| - | 345 | 1 | 1 | O2 | -| 79.173 | 2673 | 8 | 90 | O2 | +# ResNeXt-101-32x8d + +This implements training of ResNeXt-101-32x8d on the ImageNet dataset, mainly modified from [pytorch/examples](https://github.com/pytorch/examples/tree/master/imagenet). + +## ResNeXt-101-32x8d Detail + +As of the current date, Ascend-Pytorch is still inefficient for contiguous operations.Therefore, ResNeXt-101-32x8d is re-implemented using semantics such as custom OP. + + +## Requirements + +- Install PyTorch ([pytorch.org](http://pytorch.org)) +- `pip install -r requirements.txt` +- Download the ImageNet dataset from http://www.image-net.org/ + - Then, and move validation images to labeled subfolders, using [the following shell script](https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh) + +## Training + +To train a model, run `main.py` with the desired model architecture and the path to the ImageNet dataset: + +# 1p training 1p +bash ./test/train_full_1p.sh --data_path=xxx # training accuracy + +bash ./test/train_performance_1p.sh --data_path=xxx # training performance + +# 8p training 8p +bash ./test/train_full_8p.sh --data_path=xxx # training accuracy + +bash ./test/train_performance_8p.sh --data_path=xxx # training performance + +# eval default 8p, should support 1p +bash ./test/train_eval_8p.sh --data_path=xxx + +# O2 online inference demo +source scripts/set_npu_env.sh +python3.7.5 demo.py + +# O2 To ONNX +source scripts/set_npu_env.sh +python3.7.5 pthtar2onnx.py + + +``` + +## ResNeXt-101-32x8d training result + +| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | +| :------: | :------: | :------: | :------: | :------: | +| - | 345 | 1 | 1 | O2 | +| 79.173 | 2673 | 8 | 90 | O2 | diff --git a/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/demo.py b/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/demo.py index 52524242c67de7b77a8aa06dcec0d72e4883de55..aca3a3d39725aab089a0dae04cf05d936f51d068 100644 --- a/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/demo.py +++ b/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/demo.py @@ -1,73 +1,73 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import argparse -import torch -import torchvision -from torchvision import datasets, transforms -import models.resnet_0_6_0 as resnet_0_6_0 -from collections import OrderedDict - -def proc_node_module(checkpoint, attr_name): - new_state_dict = OrderedDict() - for k, v in checkpoint[attr_name].items(): - if(k[0: 7] == "module."): - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - -def get_raw_data(): - from PIL import Image - from urllib.request import urlretrieve - IMAGE_URL = 'https://bbs-img.huaweicloud.com/blogs/img/thumb/1591951315139_8989_1363.png' - urlretrieve(IMAGE_URL, 'tmp.jpg') - img = Image.open("tmp.jpg") - img = img.convert('RGB') - return img - -def test(): - loc = 'npu:0' - loc_cpu = 'cpu' - torch.npu.set_device(loc) - checkpoint = torch.load("./checkpoint.pth.tar", map_location=loc) - checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') - model = resnet_0_6_0.resnext101_32x8d() - model = model.to(loc) - model.load_state_dict(checkpoint['state_dict']) - model.eval() - - normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], - std=[0.229, 0.224, 0.225]) - rd = get_raw_data() - data_transfrom = transforms.Compose([ - transforms.Resize(256), - transforms.CenterCrop(224), - transforms.ToTensor(), - normalize]) - - inputs = data_transfrom(rd) - inputs = inputs.unsqueeze(0) - inputs = inputs.to(loc) - output = model(inputs) - output = output.to(loc_cpu) - - _, pred = output.topk(1, 1, True, True) - result = torch.argmax(output, 1) - print("class: ", pred[0][0].item()) - print(result) - -if __name__ == "__main__": +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import argparse +import torch +import torchvision +from torchvision import datasets, transforms +import models.resnet_0_6_0 as resnet_0_6_0 +from collections import OrderedDict + +def proc_node_module(checkpoint, attr_name): + new_state_dict = OrderedDict() + for k, v in checkpoint[attr_name].items(): + if(k[0: 7] == "module."): + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + +def get_raw_data(): + from PIL import Image + from urllib.request import urlretrieve + IMAGE_URL = 'https://bbs-img.huaweicloud.com/blogs/img/thumb/1591951315139_8989_1363.png' + urlretrieve(IMAGE_URL, 'tmp.jpg') + img = Image.open("tmp.jpg") + img = img.convert('RGB') + return img + +def test(): + loc = 'npu:0' + loc_cpu = 'cpu' + torch.npu.set_device(loc) + checkpoint = torch.load("./checkpoint.pth.tar", map_location=loc) + checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') + model = resnet_0_6_0.resnext101_32x8d() + model = model.to(loc) + model.load_state_dict(checkpoint['state_dict']) + model.eval() + + normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]) + rd = get_raw_data() + data_transfrom = transforms.Compose([ + transforms.Resize(256), + transforms.CenterCrop(224), + transforms.ToTensor(), + normalize]) + + inputs = data_transfrom(rd) + inputs = inputs.unsqueeze(0) + inputs = inputs.to(loc) + output = model(inputs) + output = output.to(loc_cpu) + + _, pred = output.topk(1, 1, True, True) + result = torch.argmax(output, 1) + print("class: ", pred[0][0].item()) + print(result) + +if __name__ == "__main__": test() \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/main.py b/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/main.py index 8273d29d996b9ab65df5444047979f1c09249813..2eae3c6dc7276974225bb5e6838fe30febc7191c 100644 --- a/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/main.py +++ b/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/main.py @@ -1,672 +1,672 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import warnings -import argparse -import os -import random -import shutil -import time -import warnings -import torch -import numpy as np -import apex -from apex import amp -import torch.nn as nn -import torch.nn.parallel -import torch.npu -import torch.backends.cudnn as cudnn -import torch.distributed as dist -import torch.optim -import torch.multiprocessing as mp -import torch.utils.data -import torch.utils.data.distributed -import torchvision.transforms as transforms -import torchvision.datasets as datasets -import models.resnet_0_6_0 as resnet_0_6_0 - -warnings.filterwarnings('ignore') -parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') -parser.add_argument('data', metavar='DIR', - help='path to dataset') -parser.add_argument('-j', '--workers', default=4, type=int, metavar='N', - help='number of data loading workers (default: 4)') -parser.add_argument('--epochs', default=90, type=int, metavar='N', - help='number of total epochs to run') -parser.add_argument('--start-epoch', default=0, type=int, metavar='N', - help='manual epoch number (useful on restarts)') -parser.add_argument('-b', '--batch-size', default=256, type=int, - metavar='N', - help='mini-batch size (default: 256), this is the total ' - 'batch size of all GPUs on the current node when ' - 'using Data Parallel or Distributed Data Parallel') -parser.add_argument('--lr', '--learning-rate', default=0.1, type=float, - metavar='LR', help='initial learning rate', dest='lr') -parser.add_argument('--momentum', default=0.9, type=float, metavar='M', - help='momentum') -parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, - metavar='W', help='weight decay (default: 1e-4)', - dest='weight_decay') -parser.add_argument('-p', '--print-freq', default=10, type=int, - metavar='N', help='print frequency (default: 10)') -parser.add_argument('--resume', default=None, type=str, metavar='PATH', - help='path to latest checkpoint (default: none)') -parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', - help='evaluate model on validation set') -parser.add_argument('--pretrained', dest='pretrained', action='store_true', - help='use pre-trained model') -parser.add_argument('--world-size', default=-1, type=int, - help='number of nodes for distributed training') -parser.add_argument('--rank', default=-1, type=int, - help='node rank for distributed training') -parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str, - help='url used to set up distributed training') -parser.add_argument('--dist-backend', default='nccl', type=str, - help='distributed backend') -parser.add_argument('--seed', default=None, type=int, - help='seed for initializing training. ') -parser.add_argument('--gpu', default=None, type=int, - help='GPU id to use.') -parser.add_argument('--multiprocessing-distributed', action='store_true', - help='Use multi-processing distributed training to launch ' - 'N processes per node, which has N GPUs. This is the ' - 'fastest way to use PyTorch for either single node or ' - 'multi node data parallel training') -## for ascend 910 -parser.add_argument('--device', default='npu', type=str, help='npu or gpu') -parser.add_argument('--addr', default='10.136.181.115', - type=str, help='master addr') -parser.add_argument('--device_list', default='0,1,2,3,4,5,6,7', - type=str, help='device id list') -parser.add_argument('--amp', default=False, action='store_true', - help='use amp to train the model') -parser.add_argument('--loss-scale', default=1024., type=float, - help='loss scale using in amp, default -1 means dynamic') -parser.add_argument('--opt-level', default='O2', type=str, - help='loss scale using in amp, default -1 means dynamic') -parser.add_argument('--prof', default=False, action='store_true', - help='use profiling to evaluate the performance of model') -parser.add_argument('--warm_up_epochs', default=5, type=int, - help='warm up') -best_acc1 = 0 - - -def device_id_to_process_device_map(device_list): - devices = device_list.split(",") - devices = [int(x) for x in devices] - devices.sort() - - process_device_map = dict() - for process_id, device_id in enumerate(devices): - process_device_map[process_id] = device_id - - return process_device_map - - -def main(): - args = parser.parse_args() - - os.environ['MASTER_ADDR'] = args.addr - os.environ['MASTER_PORT'] = '29688' - - if args.seed is not None: - random.seed(args.seed) - torch.manual_seed(args.seed) - cudnn.deterministic = True - warnings.warn('You have chosen to seed training. ' - 'This will turn on the CUDNN deterministic setting, ' - 'which can slow down your training considerably! ' - 'You may see unexpected behavior when restarting ' - 'from checkpoints.') - - if args.gpu is not None: - warnings.warn('You have chosen a specific GPU. This will completely ' - 'disable data parallelism.') - - if args.dist_url == "env://" and args.world_size == -1: - args.world_size = int(os.environ["WORLD_SIZE"]) - - args.distributed = args.world_size > 1 or args.multiprocessing_distributed - - args.process_device_map = device_id_to_process_device_map(args.device_list) - - if args.device == 'npu': - ngpus_per_node = len(args.process_device_map) - else: - if args.distributed: - ngpus_per_node = torch.cuda.device_count() - else: - ngpus_per_node = 1 - print('ngpus_per_node:', ngpus_per_node) - if args.multiprocessing_distributed: - # Since we have ngpus_per_node processes per node, the total world_size - # needs to be adjusted accordingly - args.world_size = ngpus_per_node * args.world_size - # Use torch.multiprocessing.spawn to launch distributed processes: the - # main_worker process function - #mp.spawn(main_worker, nprocs=ngpus_per_node, args=(ngpus_per_node, args)) - main_worker(args.gpu, ngpus_per_node, args) - - else: - # Simply call main_worker function - main_worker(args.gpu, ngpus_per_node, args) - - -def main_worker(gpu, ngpus_per_node, args): - global best_acc1 - args.gpu = args.process_device_map[gpu] - - if args.distributed: - args.gpu = args.rank - if args.dist_url == "env://" and args.rank == -1: - args.rank = int(os.environ["RANK"]) - if args.multiprocessing_distributed: - # For multiprocessing distributed training, rank needs to be the - # global rank among all the processes - args.rank = args.rank * ngpus_per_node + gpu - - if args.device == 'npu': - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = '29688' - loc = 'npu:{}'.format(args.gpu) - torch.npu.set_device(loc) - dist.init_process_group(backend=args.dist_backend, # init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - else: - dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - # create model - if args.pretrained: - print("=> using pre-trained model resnext101_32x8d") - model = resnet_0_6_0.resnext101_32x8d(pretrained=False, progress=True) - print("Load my train models...") - pretrained_dict = \ - torch.load("checkpoint.pth.tar", map_location="cpu")["state_dict"] - model.load_state_dict({k.replace('module.', ''): v for k, v in pretrained_dict.items()}, strict=False) - if "fc.weight" in pretrained_dict: - pretrained_dict.pop('fc.weight') - pretrained_dict.pop('fc.bias') - if "module.fc.weight" in pretrained_dict: - pretrained_dict.pop('module.fc.weight') - pretrained_dict.pop('module.fc.bias') - for param in model.parameters(): - param.requires_grad = False - model.fc = nn.Linear(2048, 1000) - model.load_state_dict(pretrained_dict, strict=False) - else: - print("=> creating model resnext101_32x8d") - model = resnet_0_6_0.resnext101_32x8d() - - if args.distributed: - # For multiprocessing distributed, DistributedDataParallel constructor - # should always set the single device scope, otherwise, - # DistributedDataParallel will use all available devices. - if args.gpu is not None: - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - model = model.to(loc) - else: - torch.cuda.set_device(args.gpu) - model.cuda(args.gpu) - - # When using a single GPU per process and per - # DistributedDataParallel, we need to divide the batch size - # ourselves based on the total number of GPUs we have - args.batch_size = int(args.batch_size / args.world_size) - args.workers = int((args.workers + ngpus_per_node - 1) / ngpus_per_node) - else: - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - model = model.to(loc) - else: - model.cuda() - # DistributedDataParallel will divide and allocate batch_size to all - # available GPUs if device_ids are not set - print("[gpu id:", args.gpu, "]", - "============================test args.gpu is not None else==========================") - elif args.gpu is not None: - print("[gpu id:", args.gpu, "]", - "============================test elif args.gpu is not None:==========================") - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - torch.npu.set_device(args.gpu) - model = model.to(loc) - else: - torch.cuda.set_device(args.gpu) - model = model.cuda(args.gpu) - - else: - # DataParallel will divide and allocate batch_size to all available GPUs - print("[gpu id:", args.gpu, "]", "============================test 1==========================") - print("[gpu id:", args.gpu, "]", "============================test 3==========================") - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - else: - print("before : model = torch.nn.DataParallel(model).cuda()") - - # define loss function (criterion) and optimizer - optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), args.lr, - momentum=args.momentum, - weight_decay=args.weight_decay) - - - if args.amp: - model, optimizer = amp.initialize( - model, optimizer, opt_level=args.opt_level, loss_scale=args.loss_scale) - - if args.distributed: - # For multiprocessing distributed, DistributedDataParallel constructor - # should always set the single device scope, otherwise, - # DistributedDataParallel will use all available devices. - if args.gpu is not None: - # When using a single GPU per process and per - # DistributedDataParallel, we need to divide the batch size - # ourselves based on the total number of GPUs we have - if args.pretrained: - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu], broadcast_buffers=False, - find_unused_parameters=True) - else: - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu], broadcast_buffers=False) - else: - print("[gpu id:", args.gpu, "]", - "============================test args.gpu is not None else==========================") - model = torch.nn.parallel.DistributedDataParallel(model) - elif args.gpu is not None: - print("[gpu id:", args.gpu, "]", - "============================test elif args.gpu is not None:==========================") - else: - # DataParallel will divide and allocate batch_size to all available GPUs - print("[gpu id:", args.gpu, "]", "============================test 1==========================") - print("[gpu id:", args.gpu, "]", "============================test 3==========================") - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - model = torch.nn.DataParallel(model).to(loc) - else: - model = torch.nn.DataParallel(model).cuda() - print(torch.npu.synchronize(), "-- A 2.0 ------") - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - criterion = nn.CrossEntropyLoss().to(loc) - else: - criterion = nn.CrossEntropyLoss().cuda(args.gpu) - - # optionally resume from a checkpoint - if args.resume: - if os.path.isfile(args.resume): - print("=> loading checkpoint '{}'".format(args.resume)) - if args.gpu is None: - checkpoint = torch.load(args.resume) - else: - # Map model to be loaded to specified single gpu. - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - else: - loc = 'cuda:{}'.format(args.gpu) - checkpoint = torch.load(args.resume, map_location=loc) - args.start_epoch = checkpoint['epoch'] - best_acc1 = checkpoint['best_acc1'] - if args.gpu is not None: - # best_acc1 may be from a checkpoint from a different GPU - best_acc1 = best_acc1.to(args.gpu) - model.load_state_dict(checkpoint['state_dict']) - optimizer.load_state_dict(checkpoint['optimizer']) - if args.amp: - amp.load_state_dict(checkpoint['amp']) - print("=> loaded checkpoint '{}' (epoch {})" - .format(args.resume, checkpoint['epoch'])) - else: - print("=> no checkpoint found at '{}'".format(args.resume)) - - cudnn.benchmark = True - - # Data loading code - traindir = os.path.join(args.data, 'train') - valdir = os.path.join(args.data, 'val') - normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], - std=[0.229, 0.224, 0.225]) - - train_dataset = datasets.ImageFolder( - traindir, - transforms.Compose([ - transforms.RandomResizedCrop(224), - transforms.RandomHorizontalFlip(), - transforms.ToTensor(), - normalize, - ])) - - if args.distributed: - train_sampler = torch.utils.data.distributed.DistributedSampler( - train_dataset) - else: - train_sampler = None - - train_loader = torch.utils.data.DataLoader( - train_dataset, batch_size=args.batch_size, shuffle=( - train_sampler is None), - num_workers=args.workers, pin_memory=False, sampler=train_sampler, drop_last=True) - - val_loader = torch.utils.data.DataLoader( - datasets.ImageFolder(valdir, transforms.Compose([ - transforms.Resize(256), - transforms.CenterCrop(224), - transforms.ToTensor(), - normalize, - ])), - batch_size=args.batch_size, shuffle=True, - num_workers=args.workers, pin_memory=False, drop_last=True) - - if args.evaluate: - validate(val_loader, model, criterion, args, ngpus_per_node) - return - - if args.prof: - profiling(train_loader, model, criterion, optimizer, args) - return - - start_time = time.time() - for epoch in range(args.start_epoch, args.epochs): - if args.distributed: - train_sampler.set_epoch(epoch) - - adjust_learning_rate(optimizer, epoch, args) - - # train for one epoch - train(train_loader, model, criterion, optimizer, epoch, args, ngpus_per_node) - - # evaluate on validation set - acc1 = validate(val_loader, model, criterion, args, ngpus_per_node) - - # remember best acc@1 and save checkpoint - is_best = acc1 > best_acc1 - best_acc1 = max(acc1, best_acc1) - if args.device == 'npu' and args.gpu == 0 and epoch == 89: - print("Complete 90 epoch training, take time:{}h".format(round((time.time() - start_time) / 3600.0, 2))) - - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - - ############## npu modify begin ############# - if args.amp: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': 'resnext101_32x8d', - 'state_dict': model.state_dict(), - 'best_acc1': best_acc1, - 'optimizer': optimizer.state_dict(), - 'amp': amp.state_dict(), - }, is_best) - else: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': 'resnext101_32x8d', - 'state_dict': model.state_dict(), - 'best_acc1': best_acc1, - 'optimizer': optimizer.state_dict(), - }, is_best) - ############## npu modify end ############# - - -def profiling(data_loader, model, criterion, optimizer, args): - # switch to train mode - model.train() - - def update(model, images, target, optimizer): - output = model(images) - loss = criterion(output, target) - if args.amp: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.zero_grad() - optimizer.step() - - for step, (images, target) in enumerate(data_loader): - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - images = images.to(loc, non_blocking=True).to(torch.float) - target = target.to(torch.int32).to(loc, non_blocking=True) - else: - images = images.cuda(args.gpu, non_blocking=True) - target = target.cuda(args.gpu, non_blocking=True) - - if step < 5: - update(model, images, target, optimizer) - else: - if args.device == 'npu': - with torch.autograd.profiler.profile(use_npu=True) as prof: - update(model, images, target, optimizer) - else: - with torch.autograd.profiler.profile(use_cuda=True) as prof: - update(model, images, target, optimizer) - break - - prof.export_chrome_trace("output.prof") - - -def train(train_loader, model, criterion, optimizer, epoch, args, ngpus_per_node): - batch_time = AverageMeter('Time', ':6.3f') - data_time = AverageMeter('Data', ':6.3f') - losses = AverageMeter('Loss', ':.4e') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - progress = ProgressMeter( - len(train_loader), - [batch_time, data_time, losses, top1, top5], - prefix="Epoch: [{}]".format(epoch)) - - # switch to train mode - model.train() - - end = time.time() - for i, (images, target) in enumerate(train_loader): - # measure data loading time - data_time.update(time.time() - end) - - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - images = images.to(loc, non_blocking=True).to(torch.float) - target = target.to(torch.int32).to(loc, non_blocking=True) - else: - images = images.cuda(args.gpu, non_blocking=True) - target = target.cuda(args.gpu, non_blocking=True) - - # compute output - output = model(images) - loss = criterion(output, target) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # compute gradient and do SGD step - optimizer.zero_grad() - if args.amp: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - if args.device == 'npu': - torch.npu.synchronize() - - # measure elapsed time - cost_time = time.time() - end - batch_time.update(cost_time) - end = time.time() - - if i % args.print_freq == 0: - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - progress.display(i) - - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - print("[npu id:", args.gpu, "]", "batch_size:", args.world_size * args.batch_size, - 'Time: {:.3f}'.format(batch_time.avg), '* FPS@all {:.3f}'.format( - args.batch_size * args.world_size / batch_time.avg)) - - -def validate(val_loader, model, criterion, args, ngpus_per_node): - batch_time = AverageMeter('Time', ':6.3f') - losses = AverageMeter('Loss', ':.4e') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - progress = ProgressMeter( - len(val_loader), - [batch_time, losses, top1, top5], - prefix='Test: ') - - # switch to evaluate mode - model.eval() - - with torch.no_grad(): - end = time.time() - for i, (images, target) in enumerate(val_loader): - if args.gpu is not None: - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - images = images.to(loc).to(torch.float) - else: - images = images.cuda(args.gpu, non_blocking=True) - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - target = target.to(torch.int32).to(loc, non_blocking=True) - else: - target = target.cuda(args.gpu, non_blocking=True) - - # compute output - output = model(images) - loss = criterion(output, target) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # measure elapsed time - cost_time = time.time() - end - batch_time.update(cost_time) - end = time.time() - - if i % args.print_freq == 0: - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - progress.display(i) - - if i % args.print_freq == 0: - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - print("[gpu id:", args.gpu, "]", '[AVG-ACC] * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}' - .format(top1=top1, top5=top5)) - - return top1.avg - - -def save_checkpoint(state, is_best, filename='checkpoint.pth.tar'): - torch.save(state, filename) - if is_best: - shutil.copyfile(filename, 'model_best.pth.tar') - - -class AverageMeter(object): - """Computes and stores the average and current value""" - - def __init__(self, name, fmt=':f', start_count_index=2): - self.name = name - self.fmt = fmt - self.reset() - self.start_count_index = start_count_index - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - - def update(self, val, n=1): - if self.count == 0: - self.N = n - - self.val = val - self.count += n - if self.count > (self.start_count_index * self.N): - self.sum += val * n - self.avg = self.sum / (self.count - self.start_count_index * self.N) - - def __str__(self): - fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' - return fmtstr.format(**self.__dict__) - - -class ProgressMeter(object): - - def __init__(self, num_batches, meters, prefix=""): - self.batch_fmtstr = self._get_batch_fmtstr(num_batches) - self.meters = meters - self.prefix = prefix - - def display(self, batch): - entries = [self.prefix + self.batch_fmtstr.format(batch)] - entries += [str(meter) for meter in self.meters] - print('\t'.join(entries)) - - def _get_batch_fmtstr(self, num_batches): - num_digits = len(str(num_batches // 1)) - fmt = '{:' + str(num_digits) + 'd}' - return '[' + fmt + '/' + fmt.format(num_batches) + ']' - - -def adjust_learning_rate(optimizer, epoch, args): - """Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" - # lr = args.lr * (0.1 ** (epoch // (args.epochs//3 - 3))) - - if args.warm_up_epochs > 0 and epoch < args.warm_up_epochs: - lr = args.lr * ((epoch + 1) / (args.warm_up_epochs + 1)) - else: - alpha = 0 - cosine_decay = 0.5 * ( - 1 + np.cos(np.pi * (epoch - args.warm_up_epochs) / (args.epochs - args.warm_up_epochs))) - decayed = (1 - alpha) * cosine_decay + alpha - lr = args.lr * decayed - - print("=> Epoch[%d] Setting lr: %.4f" % (epoch, lr)) - for param_group in optimizer.param_groups: - param_group['lr'] = lr - - -def accuracy(output, target, topk=(1,)): - """Computes the accuracy over the k top predictions for the specified values of k""" - with torch.no_grad(): - maxk = max(topk) - batch_size = target.size(0) - - _, pred = output.topk(maxk, 1, True, True) - pred = pred.t() - correct = pred.eq(target.view(1, -1).expand_as(pred)) - - res = [] - for k in topk: - correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True) - res.append(correct_k.mul_(100.0 / batch_size)) - return res - - -if __name__ == '__main__': - main() +# -*- coding: utf-8 -*- +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import warnings +import argparse +import os +import random +import shutil +import time +import warnings +import torch +import numpy as np +import apex +from apex import amp +import torch.nn as nn +import torch.nn.parallel +import torch.npu +import torch.backends.cudnn as cudnn +import torch.distributed as dist +import torch.optim +import torch.multiprocessing as mp +import torch.utils.data +import torch.utils.data.distributed +import torchvision.transforms as transforms +import torchvision.datasets as datasets +import models.resnet_0_6_0 as resnet_0_6_0 + +warnings.filterwarnings('ignore') +parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') +parser.add_argument('data', metavar='DIR', + help='path to dataset') +parser.add_argument('-j', '--workers', default=4, type=int, metavar='N', + help='number of data loading workers (default: 4)') +parser.add_argument('--epochs', default=90, type=int, metavar='N', + help='number of total epochs to run') +parser.add_argument('--start-epoch', default=0, type=int, metavar='N', + help='manual epoch number (useful on restarts)') +parser.add_argument('-b', '--batch-size', default=256, type=int, + metavar='N', + help='mini-batch size (default: 256), this is the total ' + 'batch size of all GPUs on the current node when ' + 'using Data Parallel or Distributed Data Parallel') +parser.add_argument('--lr', '--learning-rate', default=0.1, type=float, + metavar='LR', help='initial learning rate', dest='lr') +parser.add_argument('--momentum', default=0.9, type=float, metavar='M', + help='momentum') +parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, + metavar='W', help='weight decay (default: 1e-4)', + dest='weight_decay') +parser.add_argument('-p', '--print-freq', default=10, type=int, + metavar='N', help='print frequency (default: 10)') +parser.add_argument('--resume', default=None, type=str, metavar='PATH', + help='path to latest checkpoint (default: none)') +parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', + help='evaluate model on validation set') +parser.add_argument('--pretrained', dest='pretrained', action='store_true', + help='use pre-trained model') +parser.add_argument('--world-size', default=-1, type=int, + help='number of nodes for distributed training') +parser.add_argument('--rank', default=-1, type=int, + help='node rank for distributed training') +parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str, + help='url used to set up distributed training') +parser.add_argument('--dist-backend', default='nccl', type=str, + help='distributed backend') +parser.add_argument('--seed', default=None, type=int, + help='seed for initializing training. ') +parser.add_argument('--gpu', default=None, type=int, + help='GPU id to use.') +parser.add_argument('--multiprocessing-distributed', action='store_true', + help='Use multi-processing distributed training to launch ' + 'N processes per node, which has N GPUs. This is the ' + 'fastest way to use PyTorch for either single node or ' + 'multi node data parallel training') +## for ascend 910 +parser.add_argument('--device', default='npu', type=str, help='npu or gpu') +parser.add_argument('--addr', default='10.136.181.115', + type=str, help='master addr') +parser.add_argument('--device_list', default='0,1,2,3,4,5,6,7', + type=str, help='device id list') +parser.add_argument('--amp', default=False, action='store_true', + help='use amp to train the model') +parser.add_argument('--loss-scale', default=1024., type=float, + help='loss scale using in amp, default -1 means dynamic') +parser.add_argument('--opt-level', default='O2', type=str, + help='loss scale using in amp, default -1 means dynamic') +parser.add_argument('--prof', default=False, action='store_true', + help='use profiling to evaluate the performance of model') +parser.add_argument('--warm_up_epochs', default=5, type=int, + help='warm up') +best_acc1 = 0 + + +def device_id_to_process_device_map(device_list): + devices = device_list.split(",") + devices = [int(x) for x in devices] + devices.sort() + + process_device_map = dict() + for process_id, device_id in enumerate(devices): + process_device_map[process_id] = device_id + + return process_device_map + + +def main(): + args = parser.parse_args() + + os.environ['MASTER_ADDR'] = args.addr + os.environ['MASTER_PORT'] = '29688' + + if args.seed is not None: + random.seed(args.seed) + torch.manual_seed(args.seed) + cudnn.deterministic = True + warnings.warn('You have chosen to seed training. ' + 'This will turn on the CUDNN deterministic setting, ' + 'which can slow down your training considerably! ' + 'You may see unexpected behavior when restarting ' + 'from checkpoints.') + + if args.gpu is not None: + warnings.warn('You have chosen a specific GPU. This will completely ' + 'disable data parallelism.') + + if args.dist_url == "env://" and args.world_size == -1: + args.world_size = int(os.environ["WORLD_SIZE"]) + + args.distributed = args.world_size > 1 or args.multiprocessing_distributed + + args.process_device_map = device_id_to_process_device_map(args.device_list) + + if args.device == 'npu': + ngpus_per_node = len(args.process_device_map) + else: + if args.distributed: + ngpus_per_node = torch.cuda.device_count() + else: + ngpus_per_node = 1 + print('ngpus_per_node:', ngpus_per_node) + if args.multiprocessing_distributed: + # Since we have ngpus_per_node processes per node, the total world_size + # needs to be adjusted accordingly + args.world_size = ngpus_per_node * args.world_size + # Use torch.multiprocessing.spawn to launch distributed processes: the + # main_worker process function + #mp.spawn(main_worker, nprocs=ngpus_per_node, args=(ngpus_per_node, args)) + main_worker(args.gpu, ngpus_per_node, args) + + else: + # Simply call main_worker function + main_worker(args.gpu, ngpus_per_node, args) + + +def main_worker(gpu, ngpus_per_node, args): + global best_acc1 + args.gpu = args.process_device_map[gpu] + + if args.distributed: + args.gpu = args.rank + if args.dist_url == "env://" and args.rank == -1: + args.rank = int(os.environ["RANK"]) + if args.multiprocessing_distributed: + # For multiprocessing distributed training, rank needs to be the + # global rank among all the processes + args.rank = args.rank * ngpus_per_node + gpu + + if args.device == 'npu': + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '29688' + loc = 'npu:{}'.format(args.gpu) + torch.npu.set_device(loc) + dist.init_process_group(backend=args.dist_backend, # init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + else: + dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + # create model + if args.pretrained: + print("=> using pre-trained model resnext101_32x8d") + model = resnet_0_6_0.resnext101_32x8d(pretrained=False, progress=True) + print("Load my train models...") + pretrained_dict = \ + torch.load("checkpoint.pth.tar", map_location="cpu")["state_dict"] + model.load_state_dict({k.replace('module.', ''): v for k, v in pretrained_dict.items()}, strict=False) + if "fc.weight" in pretrained_dict: + pretrained_dict.pop('fc.weight') + pretrained_dict.pop('fc.bias') + if "module.fc.weight" in pretrained_dict: + pretrained_dict.pop('module.fc.weight') + pretrained_dict.pop('module.fc.bias') + for param in model.parameters(): + param.requires_grad = False + model.fc = nn.Linear(2048, 1000) + model.load_state_dict(pretrained_dict, strict=False) + else: + print("=> creating model resnext101_32x8d") + model = resnet_0_6_0.resnext101_32x8d() + + if args.distributed: + # For multiprocessing distributed, DistributedDataParallel constructor + # should always set the single device scope, otherwise, + # DistributedDataParallel will use all available devices. + if args.gpu is not None: + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + model = model.to(loc) + else: + torch.cuda.set_device(args.gpu) + model.cuda(args.gpu) + + # When using a single GPU per process and per + # DistributedDataParallel, we need to divide the batch size + # ourselves based on the total number of GPUs we have + args.batch_size = int(args.batch_size / args.world_size) + args.workers = int((args.workers + ngpus_per_node - 1) / ngpus_per_node) + else: + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + model = model.to(loc) + else: + model.cuda() + # DistributedDataParallel will divide and allocate batch_size to all + # available GPUs if device_ids are not set + print("[gpu id:", args.gpu, "]", + "============================test args.gpu is not None else==========================") + elif args.gpu is not None: + print("[gpu id:", args.gpu, "]", + "============================test elif args.gpu is not None:==========================") + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + torch.npu.set_device(args.gpu) + model = model.to(loc) + else: + torch.cuda.set_device(args.gpu) + model = model.cuda(args.gpu) + + else: + # DataParallel will divide and allocate batch_size to all available GPUs + print("[gpu id:", args.gpu, "]", "============================test 1==========================") + print("[gpu id:", args.gpu, "]", "============================test 3==========================") + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + else: + print("before : model = torch.nn.DataParallel(model).cuda()") + + # define loss function (criterion) and optimizer + optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), args.lr, + momentum=args.momentum, + weight_decay=args.weight_decay) + + + if args.amp: + model, optimizer = amp.initialize( + model, optimizer, opt_level=args.opt_level, loss_scale=args.loss_scale) + + if args.distributed: + # For multiprocessing distributed, DistributedDataParallel constructor + # should always set the single device scope, otherwise, + # DistributedDataParallel will use all available devices. + if args.gpu is not None: + # When using a single GPU per process and per + # DistributedDataParallel, we need to divide the batch size + # ourselves based on the total number of GPUs we have + if args.pretrained: + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu], broadcast_buffers=False, + find_unused_parameters=True) + else: + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu], broadcast_buffers=False) + else: + print("[gpu id:", args.gpu, "]", + "============================test args.gpu is not None else==========================") + model = torch.nn.parallel.DistributedDataParallel(model) + elif args.gpu is not None: + print("[gpu id:", args.gpu, "]", + "============================test elif args.gpu is not None:==========================") + else: + # DataParallel will divide and allocate batch_size to all available GPUs + print("[gpu id:", args.gpu, "]", "============================test 1==========================") + print("[gpu id:", args.gpu, "]", "============================test 3==========================") + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + model = torch.nn.DataParallel(model).to(loc) + else: + model = torch.nn.DataParallel(model).cuda() + print(torch.npu.synchronize(), "-- A 2.0 ------") + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + criterion = nn.CrossEntropyLoss().to(loc) + else: + criterion = nn.CrossEntropyLoss().cuda(args.gpu) + + # optionally resume from a checkpoint + if args.resume: + if os.path.isfile(args.resume): + print("=> loading checkpoint '{}'".format(args.resume)) + if args.gpu is None: + checkpoint = torch.load(args.resume) + else: + # Map model to be loaded to specified single gpu. + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + else: + loc = 'cuda:{}'.format(args.gpu) + checkpoint = torch.load(args.resume, map_location=loc) + args.start_epoch = checkpoint['epoch'] + best_acc1 = checkpoint['best_acc1'] + if args.gpu is not None: + # best_acc1 may be from a checkpoint from a different GPU + best_acc1 = best_acc1.to(args.gpu) + model.load_state_dict(checkpoint['state_dict']) + optimizer.load_state_dict(checkpoint['optimizer']) + if args.amp: + amp.load_state_dict(checkpoint['amp']) + print("=> loaded checkpoint '{}' (epoch {})" + .format(args.resume, checkpoint['epoch'])) + else: + print("=> no checkpoint found at '{}'".format(args.resume)) + + cudnn.benchmark = True + + # Data loading code + traindir = os.path.join(args.data, 'train') + valdir = os.path.join(args.data, 'val') + normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]) + + train_dataset = datasets.ImageFolder( + traindir, + transforms.Compose([ + transforms.RandomResizedCrop(224), + transforms.RandomHorizontalFlip(), + transforms.ToTensor(), + normalize, + ])) + + if args.distributed: + train_sampler = torch.utils.data.distributed.DistributedSampler( + train_dataset) + else: + train_sampler = None + + train_loader = torch.utils.data.DataLoader( + train_dataset, batch_size=args.batch_size, shuffle=( + train_sampler is None), + num_workers=args.workers, pin_memory=False, sampler=train_sampler, drop_last=True) + + val_loader = torch.utils.data.DataLoader( + datasets.ImageFolder(valdir, transforms.Compose([ + transforms.Resize(256), + transforms.CenterCrop(224), + transforms.ToTensor(), + normalize, + ])), + batch_size=args.batch_size, shuffle=True, + num_workers=args.workers, pin_memory=False, drop_last=True) + + if args.evaluate: + validate(val_loader, model, criterion, args, ngpus_per_node) + return + + if args.prof: + profiling(train_loader, model, criterion, optimizer, args) + return + + start_time = time.time() + for epoch in range(args.start_epoch, args.epochs): + if args.distributed: + train_sampler.set_epoch(epoch) + + adjust_learning_rate(optimizer, epoch, args) + + # train for one epoch + train(train_loader, model, criterion, optimizer, epoch, args, ngpus_per_node) + + # evaluate on validation set + acc1 = validate(val_loader, model, criterion, args, ngpus_per_node) + + # remember best acc@1 and save checkpoint + is_best = acc1 > best_acc1 + best_acc1 = max(acc1, best_acc1) + if args.device == 'npu' and args.gpu == 0 and epoch == 89: + print("Complete 90 epoch training, take time:{}h".format(round((time.time() - start_time) / 3600.0, 2))) + + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + + ############## npu modify begin ############# + if args.amp: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': 'resnext101_32x8d', + 'state_dict': model.state_dict(), + 'best_acc1': best_acc1, + 'optimizer': optimizer.state_dict(), + 'amp': amp.state_dict(), + }, is_best) + else: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': 'resnext101_32x8d', + 'state_dict': model.state_dict(), + 'best_acc1': best_acc1, + 'optimizer': optimizer.state_dict(), + }, is_best) + ############## npu modify end ############# + + +def profiling(data_loader, model, criterion, optimizer, args): + # switch to train mode + model.train() + + def update(model, images, target, optimizer): + output = model(images) + loss = criterion(output, target) + if args.amp: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.zero_grad() + optimizer.step() + + for step, (images, target) in enumerate(data_loader): + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + images = images.to(loc, non_blocking=True).to(torch.float) + target = target.to(torch.int32).to(loc, non_blocking=True) + else: + images = images.cuda(args.gpu, non_blocking=True) + target = target.cuda(args.gpu, non_blocking=True) + + if step < 5: + update(model, images, target, optimizer) + else: + if args.device == 'npu': + with torch.autograd.profiler.profile(use_npu=True) as prof: + update(model, images, target, optimizer) + else: + with torch.autograd.profiler.profile(use_cuda=True) as prof: + update(model, images, target, optimizer) + break + + prof.export_chrome_trace("output.prof") + + +def train(train_loader, model, criterion, optimizer, epoch, args, ngpus_per_node): + batch_time = AverageMeter('Time', ':6.3f') + data_time = AverageMeter('Data', ':6.3f') + losses = AverageMeter('Loss', ':.4e') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + progress = ProgressMeter( + len(train_loader), + [batch_time, data_time, losses, top1, top5], + prefix="Epoch: [{}]".format(epoch)) + + # switch to train mode + model.train() + + end = time.time() + for i, (images, target) in enumerate(train_loader): + # measure data loading time + data_time.update(time.time() - end) + + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + images = images.to(loc, non_blocking=True).to(torch.float) + target = target.to(torch.int32).to(loc, non_blocking=True) + else: + images = images.cuda(args.gpu, non_blocking=True) + target = target.cuda(args.gpu, non_blocking=True) + + # compute output + output = model(images) + loss = criterion(output, target) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # compute gradient and do SGD step + optimizer.zero_grad() + if args.amp: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + if args.device == 'npu': + torch.npu.synchronize() + + # measure elapsed time + cost_time = time.time() - end + batch_time.update(cost_time) + end = time.time() + + if i % args.print_freq == 0: + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + progress.display(i) + + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + print("[npu id:", args.gpu, "]", "batch_size:", args.world_size * args.batch_size, + 'Time: {:.3f}'.format(batch_time.avg), '* FPS@all {:.3f}'.format( + args.batch_size * args.world_size / batch_time.avg)) + + +def validate(val_loader, model, criterion, args, ngpus_per_node): + batch_time = AverageMeter('Time', ':6.3f') + losses = AverageMeter('Loss', ':.4e') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + progress = ProgressMeter( + len(val_loader), + [batch_time, losses, top1, top5], + prefix='Test: ') + + # switch to evaluate mode + model.eval() + + with torch.no_grad(): + end = time.time() + for i, (images, target) in enumerate(val_loader): + if args.gpu is not None: + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + images = images.to(loc).to(torch.float) + else: + images = images.cuda(args.gpu, non_blocking=True) + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + target = target.to(torch.int32).to(loc, non_blocking=True) + else: + target = target.cuda(args.gpu, non_blocking=True) + + # compute output + output = model(images) + loss = criterion(output, target) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # measure elapsed time + cost_time = time.time() - end + batch_time.update(cost_time) + end = time.time() + + if i % args.print_freq == 0: + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + progress.display(i) + + if i % args.print_freq == 0: + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + print("[gpu id:", args.gpu, "]", '[AVG-ACC] * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}' + .format(top1=top1, top5=top5)) + + return top1.avg + + +def save_checkpoint(state, is_best, filename='checkpoint.pth.tar'): + torch.save(state, filename) + if is_best: + shutil.copyfile(filename, 'model_best.pth.tar') + + +class AverageMeter(object): + """Computes and stores the average and current value""" + + def __init__(self, name, fmt=':f', start_count_index=2): + self.name = name + self.fmt = fmt + self.reset() + self.start_count_index = start_count_index + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + if self.count == 0: + self.N = n + + self.val = val + self.count += n + if self.count > (self.start_count_index * self.N): + self.sum += val * n + self.avg = self.sum / (self.count - self.start_count_index * self.N) + + def __str__(self): + fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' + return fmtstr.format(**self.__dict__) + + +class ProgressMeter(object): + + def __init__(self, num_batches, meters, prefix=""): + self.batch_fmtstr = self._get_batch_fmtstr(num_batches) + self.meters = meters + self.prefix = prefix + + def display(self, batch): + entries = [self.prefix + self.batch_fmtstr.format(batch)] + entries += [str(meter) for meter in self.meters] + print('\t'.join(entries)) + + def _get_batch_fmtstr(self, num_batches): + num_digits = len(str(num_batches // 1)) + fmt = '{:' + str(num_digits) + 'd}' + return '[' + fmt + '/' + fmt.format(num_batches) + ']' + + +def adjust_learning_rate(optimizer, epoch, args): + """Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" + # lr = args.lr * (0.1 ** (epoch // (args.epochs//3 - 3))) + + if args.warm_up_epochs > 0 and epoch < args.warm_up_epochs: + lr = args.lr * ((epoch + 1) / (args.warm_up_epochs + 1)) + else: + alpha = 0 + cosine_decay = 0.5 * ( + 1 + np.cos(np.pi * (epoch - args.warm_up_epochs) / (args.epochs - args.warm_up_epochs))) + decayed = (1 - alpha) * cosine_decay + alpha + lr = args.lr * decayed + + print("=> Epoch[%d] Setting lr: %.4f" % (epoch, lr)) + for param_group in optimizer.param_groups: + param_group['lr'] = lr + + +def accuracy(output, target, topk=(1,)): + """Computes the accuracy over the k top predictions for the specified values of k""" + with torch.no_grad(): + maxk = max(topk) + batch_size = target.size(0) + + _, pred = output.topk(maxk, 1, True, True) + pred = pred.t() + correct = pred.eq(target.view(1, -1).expand_as(pred)) + + res = [] + for k in topk: + correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True) + res.append(correct_k.mul_(100.0 / batch_size)) + return res + + +if __name__ == '__main__': + main() diff --git a/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/modelzoo_level.txt b/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/pthtar2onnx.py b/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/pthtar2onnx.py index dca390378c2c425a65447c2e03add404adf5b733..df34ce630fca0072666293e61af49417c45a2c7d 100644 --- a/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/pthtar2onnx.py +++ b/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/pthtar2onnx.py @@ -1,49 +1,49 @@ -""" -Copyright 2020 Huawei Technologies Co., Ltd -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import torch -import torchvision -import models.resnet_0_6_0 as resnet_0_6_0 -import torch.onnx -from collections import OrderedDict - - -def proc_node_module(checkpoint, AttrName): - new_state_dict = OrderedDict() - for k, v in checkpoint[AttrName].items(): - if(k[0:7] == "module."): - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - - -def convert(): - checkpoint = torch.load("./checkpoint.pth.tar", map_location='cpu') - checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') - model = resnet_0_6_0.resnext101_32x8d() - model.load_state_dict(checkpoint['state_dict']) - model.eval() - print(model) - - input_names = ["actual_input_1"] - output_names = ["output1"] - dummy_input = torch.randn(16, 3, 224, 224) - torch.onnx.export(model, dummy_input, "resnext101_32x8d_npu_16.onnx" - , input_names=input_names, output_names=output_names - , opset_version=11) - - -if __name__ == "__main__": - convert() +""" +Copyright 2020 Huawei Technologies Co., Ltd +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at +http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import torch +import torchvision +import models.resnet_0_6_0 as resnet_0_6_0 +import torch.onnx +from collections import OrderedDict + + +def proc_node_module(checkpoint, AttrName): + new_state_dict = OrderedDict() + for k, v in checkpoint[AttrName].items(): + if(k[0:7] == "module."): + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + + +def convert(): + checkpoint = torch.load("./checkpoint.pth.tar", map_location='cpu') + checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') + model = resnet_0_6_0.resnext101_32x8d() + model.load_state_dict(checkpoint['state_dict']) + model.eval() + print(model) + + input_names = ["actual_input_1"] + output_names = ["output1"] + dummy_input = torch.randn(16, 3, 224, 224) + torch.onnx.export(model, dummy_input, "resnext101_32x8d_npu_16.onnx" + , input_names=input_names, output_names=output_names + , opset_version=11) + + +if __name__ == "__main__": + convert() diff --git a/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/requirements.txt b/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/requirements.txt index 7f2fa08f376ac735f3c61579352a67ef3adb404a..fcf09628836e14b8082e329b646e56fadf7a9f81 100644 --- a/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/requirements.txt +++ b/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch/requirements.txt @@ -1,4 +1,4 @@ -#torch==1.5.0 -#apex -torchvision==0.2.0 -onnx +#torch==1.5.0 +#apex +torchvision==0.2.0 +onnx diff --git a/PyTorch/contrib/cv/classification/ResNet101_ID1595_for_PyTorch/modelzoo_level.txt b/PyTorch/contrib/cv/classification/ResNet101_ID1595_for_PyTorch/modelzoo_level.txt index 484664c2399ae4109859a67aba6cb9facff03cf1..55a9add9fa74832ca908108d73946cd76281a9cd 100644 --- a/PyTorch/contrib/cv/classification/ResNet101_ID1595_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/ResNet101_ID1595_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/ResNet18_ID1593_for_PyTorch/modelzoo_level.txt b/PyTorch/contrib/cv/classification/ResNet18_ID1593_for_PyTorch/modelzoo_level.txt index 484664c2399ae4109859a67aba6cb9facff03cf1..55a9add9fa74832ca908108d73946cd76281a9cd 100644 --- a/PyTorch/contrib/cv/classification/ResNet18_ID1593_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/ResNet18_ID1593_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/ResNet34_ID1594_for_PyTorch/modelzoo_level.txt b/PyTorch/contrib/cv/classification/ResNet34_ID1594_for_PyTorch/modelzoo_level.txt index 484664c2399ae4109859a67aba6cb9facff03cf1..55a9add9fa74832ca908108d73946cd76281a9cd 100644 --- a/PyTorch/contrib/cv/classification/ResNet34_ID1594_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/ResNet34_ID1594_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/SE-ResNet-50/main.py b/PyTorch/contrib/cv/classification/SE-ResNet-50/main.py index 8c630559585b07359077ec072740b5de6b262d28..b478f19182ba7bb1ca19b4093c8ac263988c39ff 100644 --- a/PyTorch/contrib/cv/classification/SE-ResNet-50/main.py +++ b/PyTorch/contrib/cv/classification/SE-ResNet-50/main.py @@ -1,652 +1,652 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import warnings -warnings.filterwarnings('ignore') -import argparse -import os -import random -import shutil -import time -import warnings -import torch -import numpy as np -import apex -from apex import amp -import torch.nn as nn -import torch.nn.parallel -import torch.npu -import torch.backends.cudnn as cudnn -import torch.distributed as dist -import torch.optim -import torch.multiprocessing as mp -import torch.utils.data -import torch.utils.data.distributed -import torchvision.transforms as transforms -import torchvision.datasets as datasets -import senet - -parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') -parser.add_argument('data', metavar='DIR', - help='path to dataset') -parser.add_argument('-j', '--workers', default=4, type=int, metavar='N', - help='number of data loading workers (default: 4)') -parser.add_argument('--epochs', default=90, type=int, metavar='N', - help='number of total epochs to run') -parser.add_argument('--start-epoch', default=0, type=int, metavar='N', - help='manual epoch number (useful on restarts)') -parser.add_argument('-b', '--batch-size', default=256, type=int, - metavar='N', - help='mini-batch size (default: 256), this is the total ' - 'batch size of all GPUs on the current node when ' - 'using Data Parallel or Distributed Data Parallel') -parser.add_argument('--lr', '--learning-rate', default=0.1, type=float, - metavar='LR', help='initial learning rate', dest='lr') -parser.add_argument('--momentum', default=0.9, type=float, metavar='M', - help='momentum') -parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, - metavar='W', help='weight decay (default: 1e-4)', - dest='weight_decay') -parser.add_argument('-p', '--print-freq', default=10, type=int, - metavar='N', help='print frequency (default: 10)') -parser.add_argument('--resume', default='./checkpoint.pth.tar', type=str, metavar='PATH', - help='path to latest checkpoint (default: none)') -parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', - help='evaluate model on validation set') -parser.add_argument('--pretrained', dest='pretrained', action='store_true', - help='use pre-trained model') -parser.add_argument('--world-size', default=-1, type=int, - help='number of nodes for distributed training') -parser.add_argument('--rank', default=-1, type=int, - help='node rank for distributed training') -parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str, - help='url used to set up distributed training') -parser.add_argument('--dist-backend', default='nccl', type=str, - help='distributed backend') -parser.add_argument('--seed', default=None, type=int, - help='seed for initializing training. ') -parser.add_argument('--gpu', default=None, type=int, - help='GPU id to use.') -parser.add_argument('--multiprocessing-distributed', action='store_true', - help='Use multi-processing distributed training to launch ' - 'N processes per node, which has N GPUs. This is the ' - 'fastest way to use PyTorch for either single node or ' - 'multi node data parallel training') -## for ascend 910 -parser.add_argument('--device', default='npu', type=str, help='npu or gpu') -parser.add_argument('--addr', default='10.136.181.115', - type=str, help='master addr') -parser.add_argument('--device_list', default='0,1,2,3,4,5,6,7', - type=str, help='device id list') -parser.add_argument('--amp', default=False, action='store_true', - help='use amp to train the model') -parser.add_argument('--loss-scale', default=1024., type=float, - help='loss scale using in amp, default -1 means dynamic') -parser.add_argument('--opt-level', default='O2', type=str, - help='loss scale using in amp, default -1 means dynamic') -parser.add_argument('--prof', default=False, action='store_true', - help='use profiling to evaluate the performance of model') -parser.add_argument('--warm_up_epochs', default=5, type=int, - help='warm up') -best_acc1 = 0 - - -def device_id_to_process_device_map(device_list): - devices = device_list.split(",") - devices = [int(x) for x in devices] - devices.sort() - - process_device_map = dict() - for process_id, device_id in enumerate(devices): - process_device_map[process_id] = device_id - - return process_device_map - - -def main(): - args = parser.parse_args() - print(args.device_list) - - os.environ['MASTER_ADDR'] = args.addr - os.environ['MASTER_PORT'] = '29688' - - if args.seed is not None: - random.seed(args.seed) - torch.manual_seed(args.seed) - cudnn.deterministic = True - warnings.warn('You have chosen to seed training. ' - 'This will turn on the CUDNN deterministic setting, ' - 'which can slow down your training considerably! ' - 'You may see unexpected behavior when restarting ' - 'from checkpoints.') - - if args.gpu is not None: - warnings.warn('You have chosen a specific GPU. This will completely ' - 'disable data parallelism.') - - if args.dist_url == "env://" and args.world_size == -1: - args.world_size = int(os.environ["WORLD_SIZE"]) - - args.distributed = args.world_size > 1 or args.multiprocessing_distributed - - args.process_device_map = device_id_to_process_device_map(args.device_list) - - if args.device == 'npu': - ngpus_per_node = len(args.process_device_map) - else: - if args.distributed: - ngpus_per_node = torch.cuda.device_count() - else: - ngpus_per_node = 1 - print('ngpus_per_node:', ngpus_per_node) - if args.multiprocessing_distributed: - # Since we have ngpus_per_node processes per node, the total world_size - # needs to be adjusted accordingly - args.world_size = ngpus_per_node * args.world_size - # Use torch.multiprocessing.spawn to launch distributed processes: the - # main_worker process function - mp.spawn(main_worker, nprocs=ngpus_per_node, - args=(ngpus_per_node, args)) - else: - # Simply call main_worker function - main_worker(args.gpu, ngpus_per_node, args) - - -def main_worker(gpu, ngpus_per_node, args): - global best_acc1 - args.gpu = args.process_device_map[gpu] - - if args.gpu is not None: - print("Use GPU: {} for training".format(args.gpu)) - - if args.distributed: - if args.dist_url == "env://" and args.rank == -1: - args.rank = int(os.environ["RANK"]) - if args.multiprocessing_distributed: - # For multiprocessing distributed training, rank needs to be the - # global rank among all the processes - args.rank = args.rank * ngpus_per_node + gpu - - if args.device == 'npu': - dist.init_process_group(backend=args.dist_backend, # init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - else: - dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - # create model - if args.pretrained: - print("=> using pre-trained model se_resnet50") - model = senet.se_resnet50(pretrained=True) - else: - print("=> creating model se_resnet50") - model = senet.se_resnet50() - - if args.distributed: - # For multiprocessing distributed, DistributedDataParallel constructor - # should always set the single device scope, otherwise, - # DistributedDataParallel will use all available devices. - if args.gpu is not None: - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - torch.npu.set_device(loc) - model = model.to(loc) - else: - torch.cuda.set_device(args.gpu) - model.cuda(args.gpu) - - # When using a single GPU per process and per - # DistributedDataParallel, we need to divide the batch size - # ourselves based on the total number of GPUs we have - args.batch_size = int(args.batch_size / args.world_size) - args.workers = int((args.workers + ngpus_per_node - 1) / ngpus_per_node) - else: - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - model = model.to(loc) - else: - model.cuda() - # DistributedDataParallel will divide and allocate batch_size to all - # available GPUs if device_ids are not set - print("[gpu id:", args.gpu, "]", - "============================test args.gpu is not None else==========================") - elif args.gpu is not None: - print("[gpu id:", args.gpu, "]", - "============================test elif args.gpu is not None:==========================") - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - torch.npu.set_device(args.gpu) - model = model.to(loc) - else: - torch.cuda.set_device(args.gpu) - model = model.cuda(args.gpu) - - else: - # DataParallel will divide and allocate batch_size to all available GPUs - print("[gpu id:", args.gpu, "]", "============================test 1==========================") - print("[gpu id:", args.gpu, "]", "============================test 3==========================") - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - else: - print("before : model = torch.nn.DataParallel(model).cuda()") - - # define loss function (criterion) and optimizer - optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), args.lr, - momentum=args.momentum, - weight_decay=args.weight_decay) - - if args.amp: - model, optimizer = amp.initialize( - model, optimizer, opt_level=args.opt_level, loss_scale=args.loss_scale) - - if args.distributed: - # For multiprocessing distributed, DistributedDataParallel constructor - # should always set the single device scope, otherwise, - # DistributedDataParallel will use all available devices. - if args.gpu is not None: - # When using a single GPU per process and per - # DistributedDataParallel, we need to divide the batch size - # ourselves based on the total number of GPUs we have - if args.pretrained: - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu], broadcast_buffers=False, - find_unused_parameters=True) - else: - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu], broadcast_buffers=False) - else: - print("[gpu id:", args.gpu, "]", - "============================test args.gpu is not None else==========================") - model = torch.nn.parallel.DistributedDataParallel(model) - elif args.gpu is not None: - print("[gpu id:", args.gpu, "]", - "============================test elif args.gpu is not None:==========================") - else: - # DataParallel will divide and allocate batch_size to all available GPUs - print("[gpu id:", args.gpu, "]", "============================test 1==========================") - print("[gpu id:", args.gpu, "]", "============================test 3==========================") - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - model = torch.nn.DataParallel(model).to(loc) - else: - model = torch.nn.DataParallel(model).cuda() - - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - criterion = nn.CrossEntropyLoss().to(loc) - else: - criterion = nn.CrossEntropyLoss().cuda(args.gpu) - - # optionally resume from a checkpoint - if args.resume: - if os.path.isfile(args.resume): - print("=> loading checkpoint '{}'".format(args.resume)) - if args.gpu is None: - checkpoint = torch.load(args.resume) - else: - # Map model to be loaded to specified single gpu. - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - else: - loc = 'cuda:{}'.format(args.gpu) - checkpoint = torch.load(args.resume, map_location=loc) - args.start_epoch = checkpoint['epoch'] - best_acc1 = checkpoint['best_acc1'] - if args.gpu is not None: - # best_acc1 may be from a checkpoint from a different GPU - best_acc1 = best_acc1.to(args.gpu) - model.load_state_dict(checkpoint['state_dict']) - optimizer.load_state_dict(checkpoint['optimizer']) - if args.amp: - amp.load_state_dict(checkpoint['amp']) - print("=> loaded checkpoint '{}' (epoch {})" - .format(args.resume, checkpoint['epoch'])) - else: - print("=> no checkpoint found at '{}'".format(args.resume)) - - cudnn.benchmark = True - - # Data loading code - traindir = os.path.join(args.data, 'train') - valdir = os.path.join(args.data, 'val') - normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], - std=[0.229, 0.224, 0.225]) - - train_dataset = datasets.ImageFolder( - traindir, - transforms.Compose([ - transforms.RandomResizedCrop(224), - transforms.RandomHorizontalFlip(), - transforms.ToTensor(), - normalize, - ])) - - if args.distributed: - train_sampler = torch.utils.data.distributed.DistributedSampler( - train_dataset) - else: - train_sampler = None - - train_loader = torch.utils.data.DataLoader( - train_dataset, batch_size=args.batch_size, shuffle=( - train_sampler is None), - num_workers=args.workers, pin_memory=False, sampler=train_sampler, drop_last=True) - - val_loader = torch.utils.data.DataLoader( - datasets.ImageFolder(valdir, transforms.Compose([ - transforms.Resize(256), - transforms.CenterCrop(224), - transforms.ToTensor(), - normalize, - ])), - batch_size=args.batch_size, shuffle=True, - num_workers=args.workers, pin_memory=False, drop_last=True) - - if args.evaluate: - validate(val_loader, model, criterion, args, ngpus_per_node) - return - - if args.prof: - profiling(train_loader, model, criterion, optimizer, args) - return - - start_time = time.time() - for epoch in range(args.start_epoch, args.epochs): - if args.distributed: - train_sampler.set_epoch(epoch) - - adjust_learning_rate(optimizer, epoch, args) - - # train for one epoch - train(train_loader, model, criterion, optimizer, epoch, args, ngpus_per_node) - - # evaluate on validation set - acc1 = validate(val_loader, model, criterion, args, ngpus_per_node) - - # remember best acc@1 and save checkpoint - is_best = acc1 > best_acc1 - best_acc1 = max(acc1, best_acc1) - if args.device == 'npu' and args.gpu == 0 and epoch == 89: - print("Complete 90 epoch training, take time:{}h".format(round((time.time() - start_time) / 3600.0, 2))) - - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - - ############## npu modify begin ############# - if args.amp: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': 'resnext101_32x8d', - 'state_dict': model.state_dict(), - 'best_acc1': best_acc1, - 'optimizer': optimizer.state_dict(), - 'amp': amp.state_dict(), - }, is_best) - else: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': 'resnext101_32x8d', - 'state_dict': model.state_dict(), - 'best_acc1': best_acc1, - 'optimizer': optimizer.state_dict(), - }, is_best) - ############## npu modify end ############# - - -def profiling(data_loader, model, criterion, optimizer, args): - # switch to train mode - model.train() - - def update(model, images, target, optimizer): - output = model(images) - loss = criterion(output, target) - if args.amp: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.zero_grad() - optimizer.step() - - for step, (images, target) in enumerate(data_loader): - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - images = images.to(loc, non_blocking=True).to(torch.float) - target = target.to(torch.int32).to(loc, non_blocking=True) - else: - images = images.cuda(args.gpu, non_blocking=True) - target = target.cuda(args.gpu, non_blocking=True) - - if step < 5: - update(model, images, target, optimizer) - else: - if args.device == 'npu': - with torch.autograd.profiler.profile(use_npu=True) as prof: - update(model, images, target, optimizer) - else: - with torch.autograd.profiler.profile(use_cuda=True) as prof: - update(model, images, target, optimizer) - break - - prof.export_chrome_trace("output.prof") - - -def train(train_loader, model, criterion, optimizer, epoch, args, ngpus_per_node): - batch_time = AverageMeter('Time', ':6.3f') - data_time = AverageMeter('Data', ':6.3f') - losses = AverageMeter('Loss', ':.4e') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - progress = ProgressMeter( - len(train_loader), - [batch_time, data_time, losses, top1, top5], - prefix="Epoch: [{}]".format(epoch)) - - # switch to train mode - model.train() - - end = time.time() - for i, (images, target) in enumerate(train_loader): - # measure data loading time - data_time.update(time.time() - end) - - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - images = images.to(loc, non_blocking=True).to(torch.float) - target = target.to(torch.int32).to(loc, non_blocking=True) - else: - images = images.cuda(args.gpu, non_blocking=True) - target = target.cuda(args.gpu, non_blocking=True) - - # compute output - output = model(images) - loss = criterion(output, target) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # compute gradient and do SGD step - optimizer.zero_grad() - if args.amp: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - if args.device == 'npu': - torch.npu.synchronize() - - # measure elapsed time - cost_time = time.time() - end - batch_time.update(cost_time) - end = time.time() - - if i % args.print_freq == 0: - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - progress.display(i) - - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - print("[npu id:", args.gpu, "]", "batch_size:", args.world_size * args.batch_size, - 'Time: {:.3f}'.format(batch_time.avg), '* FPS@all {:.3f}'.format( - args.batch_size * args.world_size / batch_time.avg)) - - -def validate(val_loader, model, criterion, args, ngpus_per_node): - batch_time = AverageMeter('Time', ':6.3f') - losses = AverageMeter('Loss', ':.4e') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - progress = ProgressMeter( - len(val_loader), - [batch_time, losses, top1, top5], - prefix='Test: ') - - # switch to evaluate mode - model.eval() - - with torch.no_grad(): - end = time.time() - for i, (images, target) in enumerate(val_loader): - if args.gpu is not None: - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - images = images.to(loc).to(torch.float) - else: - images = images.cuda(args.gpu, non_blocking=True) - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - target = target.to(torch.int32).to(loc, non_blocking=True) - else: - target = target.cuda(args.gpu, non_blocking=True) - - # compute output - output = model(images) - loss = criterion(output, target) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # measure elapsed time - cost_time = time.time() - end - batch_time.update(cost_time) - end = time.time() - - if i % args.print_freq == 0: - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - progress.display(i) - - print("[gpu id:", args.gpu, "]", '[AVG-ACC] * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}' - .format(top1=top1, top5=top5)) - - return top1.avg - - -def save_checkpoint(state, is_best, filename='checkpoint.pth.tar'): - torch.save(state, filename) - if is_best: - shutil.copyfile(filename, 'model_best.pth.tar') - - -class AverageMeter(object): - """Computes and stores the average and current value""" - - def __init__(self, name, fmt=':f', start_count_index=2): - self.name = name - self.fmt = fmt - self.reset() - self.start_count_index = start_count_index - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - - def update(self, val, n=1): - if self.count == 0: - self.N = n - - self.val = val - self.count += n - if self.count > (self.start_count_index * self.N): - self.sum += val * n - self.avg = self.sum / (self.count - self.start_count_index * self.N) - - def __str__(self): - fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' - return fmtstr.format(**self.__dict__) - - -class ProgressMeter(object): - - def __init__(self, num_batches, meters, prefix=""): - self.batch_fmtstr = self._get_batch_fmtstr(num_batches) - self.meters = meters - self.prefix = prefix - - def display(self, batch): - entries = [self.prefix + self.batch_fmtstr.format(batch)] - entries += [str(meter) for meter in self.meters] - print('\t'.join(entries)) - - def _get_batch_fmtstr(self, num_batches): - num_digits = len(str(num_batches // 1)) - fmt = '{:' + str(num_digits) + 'd}' - return '[' + fmt + '/' + fmt.format(num_batches) + ']' - - -def adjust_learning_rate(optimizer, epoch, args): - """Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" - # lr = args.lr * (0.1 ** (epoch // (args.epochs//3 - 3))) - - if args.warm_up_epochs > 0 and epoch < args.warm_up_epochs: - lr = args.lr * ((epoch + 1) / (args.warm_up_epochs + 1)) - else: - alpha = 0 - cosine_decay = 0.5 * ( - 1 + np.cos(np.pi * (epoch - args.warm_up_epochs) / (args.epochs - args.warm_up_epochs))) - decayed = (1 - alpha) * cosine_decay + alpha - lr = args.lr * decayed - - print("=> Epoch[%d] Setting lr: %.4f" % (epoch, lr)) - for param_group in optimizer.param_groups: - param_group['lr'] = lr - - -def accuracy(output, target, topk=(1,)): - """Computes the accuracy over the k top predictions for the specified values of k""" - with torch.no_grad(): - maxk = max(topk) - batch_size = target.size(0) - - _, pred = output.topk(maxk, 1, True, True) - pred = pred.t() - correct = pred.eq(target.view(1, -1).expand_as(pred)) - - res = [] - for k in topk: - correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True) - res.append(correct_k.mul_(100.0 / batch_size)) - return res - - -if __name__ == '__main__': - main() +# -*- coding: utf-8 -*- +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import warnings +warnings.filterwarnings('ignore') +import argparse +import os +import random +import shutil +import time +import warnings +import torch +import numpy as np +import apex +from apex import amp +import torch.nn as nn +import torch.nn.parallel +import torch.npu +import torch.backends.cudnn as cudnn +import torch.distributed as dist +import torch.optim +import torch.multiprocessing as mp +import torch.utils.data +import torch.utils.data.distributed +import torchvision.transforms as transforms +import torchvision.datasets as datasets +import senet + +parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') +parser.add_argument('data', metavar='DIR', + help='path to dataset') +parser.add_argument('-j', '--workers', default=4, type=int, metavar='N', + help='number of data loading workers (default: 4)') +parser.add_argument('--epochs', default=90, type=int, metavar='N', + help='number of total epochs to run') +parser.add_argument('--start-epoch', default=0, type=int, metavar='N', + help='manual epoch number (useful on restarts)') +parser.add_argument('-b', '--batch-size', default=256, type=int, + metavar='N', + help='mini-batch size (default: 256), this is the total ' + 'batch size of all GPUs on the current node when ' + 'using Data Parallel or Distributed Data Parallel') +parser.add_argument('--lr', '--learning-rate', default=0.1, type=float, + metavar='LR', help='initial learning rate', dest='lr') +parser.add_argument('--momentum', default=0.9, type=float, metavar='M', + help='momentum') +parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, + metavar='W', help='weight decay (default: 1e-4)', + dest='weight_decay') +parser.add_argument('-p', '--print-freq', default=10, type=int, + metavar='N', help='print frequency (default: 10)') +parser.add_argument('--resume', default='./checkpoint.pth.tar', type=str, metavar='PATH', + help='path to latest checkpoint (default: none)') +parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', + help='evaluate model on validation set') +parser.add_argument('--pretrained', dest='pretrained', action='store_true', + help='use pre-trained model') +parser.add_argument('--world-size', default=-1, type=int, + help='number of nodes for distributed training') +parser.add_argument('--rank', default=-1, type=int, + help='node rank for distributed training') +parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str, + help='url used to set up distributed training') +parser.add_argument('--dist-backend', default='nccl', type=str, + help='distributed backend') +parser.add_argument('--seed', default=None, type=int, + help='seed for initializing training. ') +parser.add_argument('--gpu', default=None, type=int, + help='GPU id to use.') +parser.add_argument('--multiprocessing-distributed', action='store_true', + help='Use multi-processing distributed training to launch ' + 'N processes per node, which has N GPUs. This is the ' + 'fastest way to use PyTorch for either single node or ' + 'multi node data parallel training') +## for ascend 910 +parser.add_argument('--device', default='npu', type=str, help='npu or gpu') +parser.add_argument('--addr', default='10.136.181.115', + type=str, help='master addr') +parser.add_argument('--device_list', default='0,1,2,3,4,5,6,7', + type=str, help='device id list') +parser.add_argument('--amp', default=False, action='store_true', + help='use amp to train the model') +parser.add_argument('--loss-scale', default=1024., type=float, + help='loss scale using in amp, default -1 means dynamic') +parser.add_argument('--opt-level', default='O2', type=str, + help='loss scale using in amp, default -1 means dynamic') +parser.add_argument('--prof', default=False, action='store_true', + help='use profiling to evaluate the performance of model') +parser.add_argument('--warm_up_epochs', default=5, type=int, + help='warm up') +best_acc1 = 0 + + +def device_id_to_process_device_map(device_list): + devices = device_list.split(",") + devices = [int(x) for x in devices] + devices.sort() + + process_device_map = dict() + for process_id, device_id in enumerate(devices): + process_device_map[process_id] = device_id + + return process_device_map + + +def main(): + args = parser.parse_args() + print(args.device_list) + + os.environ['MASTER_ADDR'] = args.addr + os.environ['MASTER_PORT'] = '29688' + + if args.seed is not None: + random.seed(args.seed) + torch.manual_seed(args.seed) + cudnn.deterministic = True + warnings.warn('You have chosen to seed training. ' + 'This will turn on the CUDNN deterministic setting, ' + 'which can slow down your training considerably! ' + 'You may see unexpected behavior when restarting ' + 'from checkpoints.') + + if args.gpu is not None: + warnings.warn('You have chosen a specific GPU. This will completely ' + 'disable data parallelism.') + + if args.dist_url == "env://" and args.world_size == -1: + args.world_size = int(os.environ["WORLD_SIZE"]) + + args.distributed = args.world_size > 1 or args.multiprocessing_distributed + + args.process_device_map = device_id_to_process_device_map(args.device_list) + + if args.device == 'npu': + ngpus_per_node = len(args.process_device_map) + else: + if args.distributed: + ngpus_per_node = torch.cuda.device_count() + else: + ngpus_per_node = 1 + print('ngpus_per_node:', ngpus_per_node) + if args.multiprocessing_distributed: + # Since we have ngpus_per_node processes per node, the total world_size + # needs to be adjusted accordingly + args.world_size = ngpus_per_node * args.world_size + # Use torch.multiprocessing.spawn to launch distributed processes: the + # main_worker process function + mp.spawn(main_worker, nprocs=ngpus_per_node, + args=(ngpus_per_node, args)) + else: + # Simply call main_worker function + main_worker(args.gpu, ngpus_per_node, args) + + +def main_worker(gpu, ngpus_per_node, args): + global best_acc1 + args.gpu = args.process_device_map[gpu] + + if args.gpu is not None: + print("Use GPU: {} for training".format(args.gpu)) + + if args.distributed: + if args.dist_url == "env://" and args.rank == -1: + args.rank = int(os.environ["RANK"]) + if args.multiprocessing_distributed: + # For multiprocessing distributed training, rank needs to be the + # global rank among all the processes + args.rank = args.rank * ngpus_per_node + gpu + + if args.device == 'npu': + dist.init_process_group(backend=args.dist_backend, # init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + else: + dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + # create model + if args.pretrained: + print("=> using pre-trained model se_resnet50") + model = senet.se_resnet50(pretrained=True) + else: + print("=> creating model se_resnet50") + model = senet.se_resnet50() + + if args.distributed: + # For multiprocessing distributed, DistributedDataParallel constructor + # should always set the single device scope, otherwise, + # DistributedDataParallel will use all available devices. + if args.gpu is not None: + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + torch.npu.set_device(loc) + model = model.to(loc) + else: + torch.cuda.set_device(args.gpu) + model.cuda(args.gpu) + + # When using a single GPU per process and per + # DistributedDataParallel, we need to divide the batch size + # ourselves based on the total number of GPUs we have + args.batch_size = int(args.batch_size / args.world_size) + args.workers = int((args.workers + ngpus_per_node - 1) / ngpus_per_node) + else: + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + model = model.to(loc) + else: + model.cuda() + # DistributedDataParallel will divide and allocate batch_size to all + # available GPUs if device_ids are not set + print("[gpu id:", args.gpu, "]", + "============================test args.gpu is not None else==========================") + elif args.gpu is not None: + print("[gpu id:", args.gpu, "]", + "============================test elif args.gpu is not None:==========================") + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + torch.npu.set_device(args.gpu) + model = model.to(loc) + else: + torch.cuda.set_device(args.gpu) + model = model.cuda(args.gpu) + + else: + # DataParallel will divide and allocate batch_size to all available GPUs + print("[gpu id:", args.gpu, "]", "============================test 1==========================") + print("[gpu id:", args.gpu, "]", "============================test 3==========================") + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + else: + print("before : model = torch.nn.DataParallel(model).cuda()") + + # define loss function (criterion) and optimizer + optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), args.lr, + momentum=args.momentum, + weight_decay=args.weight_decay) + + if args.amp: + model, optimizer = amp.initialize( + model, optimizer, opt_level=args.opt_level, loss_scale=args.loss_scale) + + if args.distributed: + # For multiprocessing distributed, DistributedDataParallel constructor + # should always set the single device scope, otherwise, + # DistributedDataParallel will use all available devices. + if args.gpu is not None: + # When using a single GPU per process and per + # DistributedDataParallel, we need to divide the batch size + # ourselves based on the total number of GPUs we have + if args.pretrained: + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu], broadcast_buffers=False, + find_unused_parameters=True) + else: + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu], broadcast_buffers=False) + else: + print("[gpu id:", args.gpu, "]", + "============================test args.gpu is not None else==========================") + model = torch.nn.parallel.DistributedDataParallel(model) + elif args.gpu is not None: + print("[gpu id:", args.gpu, "]", + "============================test elif args.gpu is not None:==========================") + else: + # DataParallel will divide and allocate batch_size to all available GPUs + print("[gpu id:", args.gpu, "]", "============================test 1==========================") + print("[gpu id:", args.gpu, "]", "============================test 3==========================") + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + model = torch.nn.DataParallel(model).to(loc) + else: + model = torch.nn.DataParallel(model).cuda() + + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + criterion = nn.CrossEntropyLoss().to(loc) + else: + criterion = nn.CrossEntropyLoss().cuda(args.gpu) + + # optionally resume from a checkpoint + if args.resume: + if os.path.isfile(args.resume): + print("=> loading checkpoint '{}'".format(args.resume)) + if args.gpu is None: + checkpoint = torch.load(args.resume) + else: + # Map model to be loaded to specified single gpu. + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + else: + loc = 'cuda:{}'.format(args.gpu) + checkpoint = torch.load(args.resume, map_location=loc) + args.start_epoch = checkpoint['epoch'] + best_acc1 = checkpoint['best_acc1'] + if args.gpu is not None: + # best_acc1 may be from a checkpoint from a different GPU + best_acc1 = best_acc1.to(args.gpu) + model.load_state_dict(checkpoint['state_dict']) + optimizer.load_state_dict(checkpoint['optimizer']) + if args.amp: + amp.load_state_dict(checkpoint['amp']) + print("=> loaded checkpoint '{}' (epoch {})" + .format(args.resume, checkpoint['epoch'])) + else: + print("=> no checkpoint found at '{}'".format(args.resume)) + + cudnn.benchmark = True + + # Data loading code + traindir = os.path.join(args.data, 'train') + valdir = os.path.join(args.data, 'val') + normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]) + + train_dataset = datasets.ImageFolder( + traindir, + transforms.Compose([ + transforms.RandomResizedCrop(224), + transforms.RandomHorizontalFlip(), + transforms.ToTensor(), + normalize, + ])) + + if args.distributed: + train_sampler = torch.utils.data.distributed.DistributedSampler( + train_dataset) + else: + train_sampler = None + + train_loader = torch.utils.data.DataLoader( + train_dataset, batch_size=args.batch_size, shuffle=( + train_sampler is None), + num_workers=args.workers, pin_memory=False, sampler=train_sampler, drop_last=True) + + val_loader = torch.utils.data.DataLoader( + datasets.ImageFolder(valdir, transforms.Compose([ + transforms.Resize(256), + transforms.CenterCrop(224), + transforms.ToTensor(), + normalize, + ])), + batch_size=args.batch_size, shuffle=True, + num_workers=args.workers, pin_memory=False, drop_last=True) + + if args.evaluate: + validate(val_loader, model, criterion, args, ngpus_per_node) + return + + if args.prof: + profiling(train_loader, model, criterion, optimizer, args) + return + + start_time = time.time() + for epoch in range(args.start_epoch, args.epochs): + if args.distributed: + train_sampler.set_epoch(epoch) + + adjust_learning_rate(optimizer, epoch, args) + + # train for one epoch + train(train_loader, model, criterion, optimizer, epoch, args, ngpus_per_node) + + # evaluate on validation set + acc1 = validate(val_loader, model, criterion, args, ngpus_per_node) + + # remember best acc@1 and save checkpoint + is_best = acc1 > best_acc1 + best_acc1 = max(acc1, best_acc1) + if args.device == 'npu' and args.gpu == 0 and epoch == 89: + print("Complete 90 epoch training, take time:{}h".format(round((time.time() - start_time) / 3600.0, 2))) + + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + + ############## npu modify begin ############# + if args.amp: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': 'resnext101_32x8d', + 'state_dict': model.state_dict(), + 'best_acc1': best_acc1, + 'optimizer': optimizer.state_dict(), + 'amp': amp.state_dict(), + }, is_best) + else: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': 'resnext101_32x8d', + 'state_dict': model.state_dict(), + 'best_acc1': best_acc1, + 'optimizer': optimizer.state_dict(), + }, is_best) + ############## npu modify end ############# + + +def profiling(data_loader, model, criterion, optimizer, args): + # switch to train mode + model.train() + + def update(model, images, target, optimizer): + output = model(images) + loss = criterion(output, target) + if args.amp: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.zero_grad() + optimizer.step() + + for step, (images, target) in enumerate(data_loader): + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + images = images.to(loc, non_blocking=True).to(torch.float) + target = target.to(torch.int32).to(loc, non_blocking=True) + else: + images = images.cuda(args.gpu, non_blocking=True) + target = target.cuda(args.gpu, non_blocking=True) + + if step < 5: + update(model, images, target, optimizer) + else: + if args.device == 'npu': + with torch.autograd.profiler.profile(use_npu=True) as prof: + update(model, images, target, optimizer) + else: + with torch.autograd.profiler.profile(use_cuda=True) as prof: + update(model, images, target, optimizer) + break + + prof.export_chrome_trace("output.prof") + + +def train(train_loader, model, criterion, optimizer, epoch, args, ngpus_per_node): + batch_time = AverageMeter('Time', ':6.3f') + data_time = AverageMeter('Data', ':6.3f') + losses = AverageMeter('Loss', ':.4e') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + progress = ProgressMeter( + len(train_loader), + [batch_time, data_time, losses, top1, top5], + prefix="Epoch: [{}]".format(epoch)) + + # switch to train mode + model.train() + + end = time.time() + for i, (images, target) in enumerate(train_loader): + # measure data loading time + data_time.update(time.time() - end) + + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + images = images.to(loc, non_blocking=True).to(torch.float) + target = target.to(torch.int32).to(loc, non_blocking=True) + else: + images = images.cuda(args.gpu, non_blocking=True) + target = target.cuda(args.gpu, non_blocking=True) + + # compute output + output = model(images) + loss = criterion(output, target) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # compute gradient and do SGD step + optimizer.zero_grad() + if args.amp: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + if args.device == 'npu': + torch.npu.synchronize() + + # measure elapsed time + cost_time = time.time() - end + batch_time.update(cost_time) + end = time.time() + + if i % args.print_freq == 0: + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + progress.display(i) + + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + print("[npu id:", args.gpu, "]", "batch_size:", args.world_size * args.batch_size, + 'Time: {:.3f}'.format(batch_time.avg), '* FPS@all {:.3f}'.format( + args.batch_size * args.world_size / batch_time.avg)) + + +def validate(val_loader, model, criterion, args, ngpus_per_node): + batch_time = AverageMeter('Time', ':6.3f') + losses = AverageMeter('Loss', ':.4e') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + progress = ProgressMeter( + len(val_loader), + [batch_time, losses, top1, top5], + prefix='Test: ') + + # switch to evaluate mode + model.eval() + + with torch.no_grad(): + end = time.time() + for i, (images, target) in enumerate(val_loader): + if args.gpu is not None: + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + images = images.to(loc).to(torch.float) + else: + images = images.cuda(args.gpu, non_blocking=True) + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + target = target.to(torch.int32).to(loc, non_blocking=True) + else: + target = target.cuda(args.gpu, non_blocking=True) + + # compute output + output = model(images) + loss = criterion(output, target) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # measure elapsed time + cost_time = time.time() - end + batch_time.update(cost_time) + end = time.time() + + if i % args.print_freq == 0: + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + progress.display(i) + + print("[gpu id:", args.gpu, "]", '[AVG-ACC] * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}' + .format(top1=top1, top5=top5)) + + return top1.avg + + +def save_checkpoint(state, is_best, filename='checkpoint.pth.tar'): + torch.save(state, filename) + if is_best: + shutil.copyfile(filename, 'model_best.pth.tar') + + +class AverageMeter(object): + """Computes and stores the average and current value""" + + def __init__(self, name, fmt=':f', start_count_index=2): + self.name = name + self.fmt = fmt + self.reset() + self.start_count_index = start_count_index + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + if self.count == 0: + self.N = n + + self.val = val + self.count += n + if self.count > (self.start_count_index * self.N): + self.sum += val * n + self.avg = self.sum / (self.count - self.start_count_index * self.N) + + def __str__(self): + fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' + return fmtstr.format(**self.__dict__) + + +class ProgressMeter(object): + + def __init__(self, num_batches, meters, prefix=""): + self.batch_fmtstr = self._get_batch_fmtstr(num_batches) + self.meters = meters + self.prefix = prefix + + def display(self, batch): + entries = [self.prefix + self.batch_fmtstr.format(batch)] + entries += [str(meter) for meter in self.meters] + print('\t'.join(entries)) + + def _get_batch_fmtstr(self, num_batches): + num_digits = len(str(num_batches // 1)) + fmt = '{:' + str(num_digits) + 'd}' + return '[' + fmt + '/' + fmt.format(num_batches) + ']' + + +def adjust_learning_rate(optimizer, epoch, args): + """Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" + # lr = args.lr * (0.1 ** (epoch // (args.epochs//3 - 3))) + + if args.warm_up_epochs > 0 and epoch < args.warm_up_epochs: + lr = args.lr * ((epoch + 1) / (args.warm_up_epochs + 1)) + else: + alpha = 0 + cosine_decay = 0.5 * ( + 1 + np.cos(np.pi * (epoch - args.warm_up_epochs) / (args.epochs - args.warm_up_epochs))) + decayed = (1 - alpha) * cosine_decay + alpha + lr = args.lr * decayed + + print("=> Epoch[%d] Setting lr: %.4f" % (epoch, lr)) + for param_group in optimizer.param_groups: + param_group['lr'] = lr + + +def accuracy(output, target, topk=(1,)): + """Computes the accuracy over the k top predictions for the specified values of k""" + with torch.no_grad(): + maxk = max(topk) + batch_size = target.size(0) + + _, pred = output.topk(maxk, 1, True, True) + pred = pred.t() + correct = pred.eq(target.view(1, -1).expand_as(pred)) + + res = [] + for k in topk: + correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True) + res.append(correct_k.mul_(100.0 / batch_size)) + return res + + +if __name__ == '__main__': + main() diff --git a/PyTorch/contrib/cv/classification/SE-ResNet-50/se_module.py b/PyTorch/contrib/cv/classification/SE-ResNet-50/se_module.py index b1638c0c67d9c175732a6551c5e494d46e70a08c..8b066534e58d3cc802450d608b8dcdd80ab0b1d1 100644 --- a/PyTorch/contrib/cv/classification/SE-ResNet-50/se_module.py +++ b/PyTorch/contrib/cv/classification/SE-ResNet-50/se_module.py @@ -1,34 +1,34 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -from torch import nn - - -class SELayer(nn.Module): - def __init__(self, channel, reduction=16): - super(SELayer, self).__init__() - self.avg_pool = nn.AdaptiveAvgPool2d(1) - self.fc = nn.Sequential( - nn.Linear(channel, channel // reduction, bias=False), - nn.ReLU(inplace=True), - nn.Linear(channel // reduction, channel, bias=False), - nn.Sigmoid() - ) - - def forward(self, x): - b, c, _, _ = x.size() - y = self.avg_pool(x).view(b, c) - y = self.fc(y).view(b, c, 1, 1) +# -*- coding: utf-8 -*- +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +from torch import nn + + +class SELayer(nn.Module): + def __init__(self, channel, reduction=16): + super(SELayer, self).__init__() + self.avg_pool = nn.AdaptiveAvgPool2d(1) + self.fc = nn.Sequential( + nn.Linear(channel, channel // reduction, bias=False), + nn.ReLU(inplace=True), + nn.Linear(channel // reduction, channel, bias=False), + nn.Sigmoid() + ) + + def forward(self, x): + b, c, _, _ = x.size() + y = self.avg_pool(x).view(b, c) + y = self.fc(y).view(b, c, 1, 1) return x * y.expand_as(x) \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/SE-ResNet-50/senet.py b/PyTorch/contrib/cv/classification/SE-ResNet-50/senet.py index 01f3c76f3ac0279b047c21240480e73c07bbfaeb..6dc5047cfce1c64e94e0cc9b1ec26fa0d6b4b4a8 100644 --- a/PyTorch/contrib/cv/classification/SE-ResNet-50/senet.py +++ b/PyTorch/contrib/cv/classification/SE-ResNet-50/senet.py @@ -1,300 +1,300 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch.nn as nn -from torch.hub import load_state_dict_from_url -from torchvision.models import ResNet -from se_module import SELayer - - -def conv3x3(in_planes, out_planes, stride=1): - return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=False) - - -class SEBasicBlock(nn.Module): - expansion = 1 - - def __init__(self, inplanes, planes, stride=1, downsample=None, groups=1, - base_width=64, dilation=1, norm_layer=None, - *, reduction=16): - super(SEBasicBlock, self).__init__() - self.conv1 = conv3x3(inplanes, planes, stride) - self.bn1 = nn.BatchNorm2d(planes) - self.relu = nn.ReLU(inplace=True) - self.conv2 = conv3x3(planes, planes, 1) - self.bn2 = nn.BatchNorm2d(planes) - self.se = SELayer(planes, reduction) - self.downsample = downsample - self.stride = stride - - def forward(self, x): - residual = x - out = self.conv1(x) - out = self.bn1(out) - out = self.relu(out) - - out = self.conv2(out) - out = self.bn2(out) - out = self.se(out) - - if self.downsample is not None: - residual = self.downsample(x) - - out += residual - out = self.relu(out) - - return out - - -class SEBottleneck(nn.Module): - expansion = 4 - - def __init__(self, inplanes, planes, stride=1, downsample=None, groups=1, - base_width=64, dilation=1, norm_layer=None, - *, reduction=16): - super(SEBottleneck, self).__init__() - self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False) - self.bn1 = nn.BatchNorm2d(planes) - self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, - padding=1, bias=False) - self.bn2 = nn.BatchNorm2d(planes) - self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False) - self.bn3 = nn.BatchNorm2d(planes * 4) - self.relu = nn.ReLU(inplace=True) - self.se = SELayer(planes * 4, reduction) - self.downsample = downsample - self.stride = stride - - def forward(self, x): - residual = x - - out = self.conv1(x) - out = self.bn1(out) - out = self.relu(out) - - out = self.conv2(out) - out = self.bn2(out) - out = self.relu(out) - - out = self.conv3(out) - out = self.bn3(out) - out = self.se(out) - - if self.downsample is not None: - residual = self.downsample(x) - - out += residual - out = self.relu(out) - - return out - - -def se_resnet18(num_classes=1_000): - """Constructs a ResNet-18 model. - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(SEBasicBlock, [2, 2, 2, 2], num_classes=num_classes) - model.avgpool = nn.AdaptiveAvgPool2d(1) - return model - - -def se_resnet34(num_classes=1_000): - """Constructs a ResNet-34 model. - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(SEBasicBlock, [3, 4, 6, 3], num_classes=num_classes) - model.avgpool = nn.AdaptiveAvgPool2d(1) - return model - - -def se_resnet50(num_classes=1_000, pretrained=False): - """Constructs a ResNet-50 model. - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(SEBottleneck, [3, 4, 6, 3], num_classes=num_classes) - model.avgpool = nn.AdaptiveAvgPool2d(1) - if pretrained: - model.load_state_dict(load_state_dict_from_url( - "https://github.com/moskomule/senet.pytorch/releases/download/archive/seresnet50-60a8950a85b2b.pkl")) - return model - - -def se_resnet101(num_classes=1_000): - """Constructs a ResNet-101 model. - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(SEBottleneck, [3, 4, 23, 3], num_classes=num_classes) - model.avgpool = nn.AdaptiveAvgPool2d(1) - return model - - -def se_resnet152(num_classes=1_000): - """Constructs a ResNet-152 model. - Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - """ - model = ResNet(SEBottleneck, [3, 8, 36, 3], num_classes=num_classes) - model.avgpool = nn.AdaptiveAvgPool2d(1) - return model - - -class CifarSEBasicBlock(nn.Module): - def __init__(self, inplanes, planes, stride=1, reduction=16): - super(CifarSEBasicBlock, self).__init__() - self.conv1 = conv3x3(inplanes, planes, stride) - self.bn1 = nn.BatchNorm2d(planes) - self.relu = nn.ReLU(inplace=True) - self.conv2 = conv3x3(planes, planes) - self.bn2 = nn.BatchNorm2d(planes) - self.se = SELayer(planes, reduction) - if inplanes != planes: - self.downsample = nn.Sequential(nn.Conv2d(inplanes, planes, kernel_size=1, stride=stride, bias=False), - nn.BatchNorm2d(planes)) - else: - self.downsample = lambda x: x - self.stride = stride - - def forward(self, x): - residual = self.downsample(x) - out = self.conv1(x) - out = self.bn1(out) - out = self.relu(out) - - out = self.conv2(out) - out = self.bn2(out) - out = self.se(out) - - out += residual - out = self.relu(out) - - return out - - -class CifarSEResNet(nn.Module): - def __init__(self, block, n_size, num_classes=10, reduction=16): - super(CifarSEResNet, self).__init__() - self.inplane = 16 - self.conv1 = nn.Conv2d( - 3, self.inplane, kernel_size=3, stride=1, padding=1, bias=False) - self.bn1 = nn.BatchNorm2d(self.inplane) - self.relu = nn.ReLU(inplace=True) - self.layer1 = self._make_layer( - block, 16, blocks=n_size, stride=1, reduction=reduction) - self.layer2 = self._make_layer( - block, 32, blocks=n_size, stride=2, reduction=reduction) - self.layer3 = self._make_layer( - block, 64, blocks=n_size, stride=2, reduction=reduction) - self.avgpool = nn.AdaptiveAvgPool2d(1) - self.fc = nn.Linear(64, num_classes) - self.initialize() - - def initialize(self): - for m in self.modules(): - if isinstance(m, nn.Conv2d): - nn.init.kaiming_normal_(m.weight) - elif isinstance(m, nn.BatchNorm2d): - nn.init.constant_(m.weight, 1) - nn.init.constant_(m.bias, 0) - - def _make_layer(self, block, planes, blocks, stride, reduction): - strides = [stride] + [1] * (blocks - 1) - layers = [] - for stride in strides: - layers.append(block(self.inplane, planes, stride, reduction)) - self.inplane = planes - - return nn.Sequential(*layers) - - def forward(self, x): - x = self.conv1(x) - x = self.bn1(x) - x = self.relu(x) - - x = self.layer1(x) - x = self.layer2(x) - x = self.layer3(x) - - x = self.avgpool(x) - x = x.view(x.size(0), -1) - x = self.fc(x) - - return x - - -class CifarSEPreActResNet(CifarSEResNet): - def __init__(self, block, n_size, num_classes=10, reduction=16): - super(CifarSEPreActResNet, self).__init__( - block, n_size, num_classes, reduction) - self.bn1 = nn.BatchNorm2d(self.inplane) - self.initialize() - - def forward(self, x): - x = self.conv1(x) - x = self.layer1(x) - x = self.layer2(x) - x = self.layer3(x) - - x = self.bn1(x) - x = self.relu(x) - - x = self.avgpool(x) - x = x.view(x.size(0), -1) - x = self.fc(x) - - -def se_resnet20(**kwargs): - """Constructs a ResNet-18 model. - """ - model = CifarSEResNet(CifarSEBasicBlock, 3, **kwargs) - return model - - -def se_resnet32(**kwargs): - """Constructs a ResNet-34 model. - """ - model = CifarSEResNet(CifarSEBasicBlock, 5, **kwargs) - return model - - -def se_resnet56(**kwargs): - """Constructs a ResNet-34 model. - """ - model = CifarSEResNet(CifarSEBasicBlock, 9, **kwargs) - return model - - -def se_preactresnet20(**kwargs): - """Constructs a ResNet-18 model. - """ - model = CifarSEPreActResNet(CifarSEBasicBlock, 3, **kwargs) - return model - - -def se_preactresnet32(**kwargs): - """Constructs a ResNet-34 model. - """ - model = CifarSEPreActResNet(CifarSEBasicBlock, 5, **kwargs) - return model - - -def se_preactresnet56(**kwargs): - """Constructs a ResNet-34 model. - """ - model = CifarSEPreActResNet(CifarSEBasicBlock, 9, **kwargs) +# -*- coding: utf-8 -*- +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch.nn as nn +from torch.hub import load_state_dict_from_url +from torchvision.models import ResNet +from se_module import SELayer + + +def conv3x3(in_planes, out_planes, stride=1): + return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=False) + + +class SEBasicBlock(nn.Module): + expansion = 1 + + def __init__(self, inplanes, planes, stride=1, downsample=None, groups=1, + base_width=64, dilation=1, norm_layer=None, + *, reduction=16): + super(SEBasicBlock, self).__init__() + self.conv1 = conv3x3(inplanes, planes, stride) + self.bn1 = nn.BatchNorm2d(planes) + self.relu = nn.ReLU(inplace=True) + self.conv2 = conv3x3(planes, planes, 1) + self.bn2 = nn.BatchNorm2d(planes) + self.se = SELayer(planes, reduction) + self.downsample = downsample + self.stride = stride + + def forward(self, x): + residual = x + out = self.conv1(x) + out = self.bn1(out) + out = self.relu(out) + + out = self.conv2(out) + out = self.bn2(out) + out = self.se(out) + + if self.downsample is not None: + residual = self.downsample(x) + + out += residual + out = self.relu(out) + + return out + + +class SEBottleneck(nn.Module): + expansion = 4 + + def __init__(self, inplanes, planes, stride=1, downsample=None, groups=1, + base_width=64, dilation=1, norm_layer=None, + *, reduction=16): + super(SEBottleneck, self).__init__() + self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False) + self.bn1 = nn.BatchNorm2d(planes) + self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, + padding=1, bias=False) + self.bn2 = nn.BatchNorm2d(planes) + self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False) + self.bn3 = nn.BatchNorm2d(planes * 4) + self.relu = nn.ReLU(inplace=True) + self.se = SELayer(planes * 4, reduction) + self.downsample = downsample + self.stride = stride + + def forward(self, x): + residual = x + + out = self.conv1(x) + out = self.bn1(out) + out = self.relu(out) + + out = self.conv2(out) + out = self.bn2(out) + out = self.relu(out) + + out = self.conv3(out) + out = self.bn3(out) + out = self.se(out) + + if self.downsample is not None: + residual = self.downsample(x) + + out += residual + out = self.relu(out) + + return out + + +def se_resnet18(num_classes=1_000): + """Constructs a ResNet-18 model. + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(SEBasicBlock, [2, 2, 2, 2], num_classes=num_classes) + model.avgpool = nn.AdaptiveAvgPool2d(1) + return model + + +def se_resnet34(num_classes=1_000): + """Constructs a ResNet-34 model. + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(SEBasicBlock, [3, 4, 6, 3], num_classes=num_classes) + model.avgpool = nn.AdaptiveAvgPool2d(1) + return model + + +def se_resnet50(num_classes=1_000, pretrained=False): + """Constructs a ResNet-50 model. + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(SEBottleneck, [3, 4, 6, 3], num_classes=num_classes) + model.avgpool = nn.AdaptiveAvgPool2d(1) + if pretrained: + model.load_state_dict(load_state_dict_from_url( + "https://github.com/moskomule/senet.pytorch/releases/download/archive/seresnet50-60a8950a85b2b.pkl")) + return model + + +def se_resnet101(num_classes=1_000): + """Constructs a ResNet-101 model. + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(SEBottleneck, [3, 4, 23, 3], num_classes=num_classes) + model.avgpool = nn.AdaptiveAvgPool2d(1) + return model + + +def se_resnet152(num_classes=1_000): + """Constructs a ResNet-152 model. + Args: + pretrained (bool): If True, returns a model pre-trained on ImageNet + """ + model = ResNet(SEBottleneck, [3, 8, 36, 3], num_classes=num_classes) + model.avgpool = nn.AdaptiveAvgPool2d(1) + return model + + +class CifarSEBasicBlock(nn.Module): + def __init__(self, inplanes, planes, stride=1, reduction=16): + super(CifarSEBasicBlock, self).__init__() + self.conv1 = conv3x3(inplanes, planes, stride) + self.bn1 = nn.BatchNorm2d(planes) + self.relu = nn.ReLU(inplace=True) + self.conv2 = conv3x3(planes, planes) + self.bn2 = nn.BatchNorm2d(planes) + self.se = SELayer(planes, reduction) + if inplanes != planes: + self.downsample = nn.Sequential(nn.Conv2d(inplanes, planes, kernel_size=1, stride=stride, bias=False), + nn.BatchNorm2d(planes)) + else: + self.downsample = lambda x: x + self.stride = stride + + def forward(self, x): + residual = self.downsample(x) + out = self.conv1(x) + out = self.bn1(out) + out = self.relu(out) + + out = self.conv2(out) + out = self.bn2(out) + out = self.se(out) + + out += residual + out = self.relu(out) + + return out + + +class CifarSEResNet(nn.Module): + def __init__(self, block, n_size, num_classes=10, reduction=16): + super(CifarSEResNet, self).__init__() + self.inplane = 16 + self.conv1 = nn.Conv2d( + 3, self.inplane, kernel_size=3, stride=1, padding=1, bias=False) + self.bn1 = nn.BatchNorm2d(self.inplane) + self.relu = nn.ReLU(inplace=True) + self.layer1 = self._make_layer( + block, 16, blocks=n_size, stride=1, reduction=reduction) + self.layer2 = self._make_layer( + block, 32, blocks=n_size, stride=2, reduction=reduction) + self.layer3 = self._make_layer( + block, 64, blocks=n_size, stride=2, reduction=reduction) + self.avgpool = nn.AdaptiveAvgPool2d(1) + self.fc = nn.Linear(64, num_classes) + self.initialize() + + def initialize(self): + for m in self.modules(): + if isinstance(m, nn.Conv2d): + nn.init.kaiming_normal_(m.weight) + elif isinstance(m, nn.BatchNorm2d): + nn.init.constant_(m.weight, 1) + nn.init.constant_(m.bias, 0) + + def _make_layer(self, block, planes, blocks, stride, reduction): + strides = [stride] + [1] * (blocks - 1) + layers = [] + for stride in strides: + layers.append(block(self.inplane, planes, stride, reduction)) + self.inplane = planes + + return nn.Sequential(*layers) + + def forward(self, x): + x = self.conv1(x) + x = self.bn1(x) + x = self.relu(x) + + x = self.layer1(x) + x = self.layer2(x) + x = self.layer3(x) + + x = self.avgpool(x) + x = x.view(x.size(0), -1) + x = self.fc(x) + + return x + + +class CifarSEPreActResNet(CifarSEResNet): + def __init__(self, block, n_size, num_classes=10, reduction=16): + super(CifarSEPreActResNet, self).__init__( + block, n_size, num_classes, reduction) + self.bn1 = nn.BatchNorm2d(self.inplane) + self.initialize() + + def forward(self, x): + x = self.conv1(x) + x = self.layer1(x) + x = self.layer2(x) + x = self.layer3(x) + + x = self.bn1(x) + x = self.relu(x) + + x = self.avgpool(x) + x = x.view(x.size(0), -1) + x = self.fc(x) + + +def se_resnet20(**kwargs): + """Constructs a ResNet-18 model. + """ + model = CifarSEResNet(CifarSEBasicBlock, 3, **kwargs) + return model + + +def se_resnet32(**kwargs): + """Constructs a ResNet-34 model. + """ + model = CifarSEResNet(CifarSEBasicBlock, 5, **kwargs) + return model + + +def se_resnet56(**kwargs): + """Constructs a ResNet-34 model. + """ + model = CifarSEResNet(CifarSEBasicBlock, 9, **kwargs) + return model + + +def se_preactresnet20(**kwargs): + """Constructs a ResNet-18 model. + """ + model = CifarSEPreActResNet(CifarSEBasicBlock, 3, **kwargs) + return model + + +def se_preactresnet32(**kwargs): + """Constructs a ResNet-34 model. + """ + model = CifarSEPreActResNet(CifarSEBasicBlock, 5, **kwargs) + return model + + +def se_preactresnet56(**kwargs): + """Constructs a ResNet-34 model. + """ + model = CifarSEPreActResNet(CifarSEBasicBlock, 9, **kwargs) return model \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/SENet154/README.md b/PyTorch/contrib/cv/classification/SENet154/README.md old mode 100755 new mode 100644 index 3a719047ecd6d3461515e8e96844517619330e8f..3b0c8b7ca85cf10b84440bf4e2e25a020ec39387 --- a/PyTorch/contrib/cv/classification/SENet154/README.md +++ b/PyTorch/contrib/cv/classification/SENet154/README.md @@ -1,71 +1,71 @@ -# SENet154 - -This implements training of SENet154 on the ImageNet dataset. - -Code of SENet is mainly migrated and adjusted from [GitHub](https://github.com/Cadene/pretrained-models.pytorch#senet). - -## SENet154 Detail - -SENet involves group convolution, which may cause error on NPU platforms where group convolution is not well-supported. - -Label smoothing is required for qualified model accuracy. - -## Requirements -- pytorch_ascend, apex_ascend -- munch package, which can be installed via `pip install munch` -- Download the ImageNet dataset from http://www.image-net.org/ - - Then, and move validation images to labeled subfolders, using [the following shell script](https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh) - -## Training - -### 单卡训练流程 -1. 安装环境 -2. 修改参数 - 1. `--data DIR`:ImageNet数据集的存储目录,训练集与验证集分别位于DIR/train和DIR/val - 1. `--log-file FILENAME`:自定义日志文件名 - 2. `--device DEVICE`:所使用的单卡训练设备,如cuda:0或npu:0 - 3. `--opt-level L`:apex混合精度优化等级,支持O2(默认)或O1 - 4. `--loss-scale S`:apex混合精度使用的loss scale,默认为128 - 5. `--scheduler`:训练使用的学习率调整器,支持`step`(对应StepLR)和`cosine`(对应CosineAnnealingLR) -3. 开始训练 - ``` - bash ./test/train_full_1p.sh --data_path=数据集路径 # 精度训练 - bash ./test/train_performance_1p.sh --data_path=数据集路径 # 性能训练 - ``` - -### 多卡训练流程 -1. 安装环境 -2. 修改参数 - 1. `--device DEVICE`:所使用的多卡训练设备类别,支持cuda和npu - 2. `--distributed`:开启分布式训练模式 - 3. `--num-devices N`:参与训练的设备个数,设备ID依次为DEVICE:0 ... DEVICE:(N-1) - 4. `--batch-size N`:分配个每个设备的batch大小 -3. 开始训练 - ``` - bash ./test/train_full_1p.sh --data_path=数据集路径 # 精度训练 - bash ./test/train_performance_1p.sh --data_path=数据集路径 # 性能训练 - ``` - -### 训练结果 -日志保存在 ./test/output/device-id 路径下 - -最终训练模型输出至./model.pth,训练过程中生成的存档点位于./models文件夹下 - -Profile结果输出至./output.prof - -## SENet154 Training Result -$E$为当前一轮的Epoch序号,从0开始 - -### GPU 8p -|Epochs|Learning rate |Optimization type|FPS |Acc@1 |Acc@5 | -|:----:|:------------------------------------:|:---------------:|:-----:|:----:|:----:| -|120 |$0.6\times 0.1^{\lfloor E/30 \rfloor}$|O2 |955.433|79.130|94.058| -|120 |$1\times 0.45^{\lfloor E/10 \rfloor}$ |O2 |954.725|78.341|93.945| -|120 |$0.6\times 0.93^{E}$ |O2 |949.309|78.100|94.010| -|120 |$0.3\times (1+\cos{\frac{E\pi}{120}})$|O2 |951.374|80.161|94.879| - -### NPU 8p -|Epochs|Learning rate |Optimization type|FPS |Acc@1 |Acc@5 | -|:----:|:------------------------------------:|:---------------:|:------:|:----:|:----:| -|120 |$0.6\times 0.1^{\lfloor E/30 \rfloor}$|O2 |1524.537|78.599|93.849| +# SENet154 + +This implements training of SENet154 on the ImageNet dataset. + +Code of SENet is mainly migrated and adjusted from [GitHub](https://github.com/Cadene/pretrained-models.pytorch#senet). + +## SENet154 Detail + +SENet involves group convolution, which may cause error on NPU platforms where group convolution is not well-supported. + +Label smoothing is required for qualified model accuracy. + +## Requirements +- pytorch_ascend, apex_ascend +- munch package, which can be installed via `pip install munch` +- Download the ImageNet dataset from http://www.image-net.org/ + - Then, and move validation images to labeled subfolders, using [the following shell script](https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh) + +## Training + +### 单卡训练流程 +1. 安装环境 +2. 修改参数 + 1. `--data DIR`:ImageNet数据集的存储目录,训练集与验证集分别位于DIR/train和DIR/val + 1. `--log-file FILENAME`:自定义日志文件名 + 2. `--device DEVICE`:所使用的单卡训练设备,如cuda:0或npu:0 + 3. `--opt-level L`:apex混合精度优化等级,支持O2(默认)或O1 + 4. `--loss-scale S`:apex混合精度使用的loss scale,默认为128 + 5. `--scheduler`:训练使用的学习率调整器,支持`step`(对应StepLR)和`cosine`(对应CosineAnnealingLR) +3. 开始训练 + ``` + bash ./test/train_full_1p.sh --data_path=数据集路径 # 精度训练 + bash ./test/train_performance_1p.sh --data_path=数据集路径 # 性能训练 + ``` + +### 多卡训练流程 +1. 安装环境 +2. 修改参数 + 1. `--device DEVICE`:所使用的多卡训练设备类别,支持cuda和npu + 2. `--distributed`:开启分布式训练模式 + 3. `--num-devices N`:参与训练的设备个数,设备ID依次为DEVICE:0 ... DEVICE:(N-1) + 4. `--batch-size N`:分配个每个设备的batch大小 +3. 开始训练 + ``` + bash ./test/train_full_1p.sh --data_path=数据集路径 # 精度训练 + bash ./test/train_performance_1p.sh --data_path=数据集路径 # 性能训练 + ``` + +### 训练结果 +日志保存在 ./test/output/device-id 路径下 + +最终训练模型输出至./model.pth,训练过程中生成的存档点位于./models文件夹下 + +Profile结果输出至./output.prof + +## SENet154 Training Result +$E$为当前一轮的Epoch序号,从0开始 + +### GPU 8p +|Epochs|Learning rate |Optimization type|FPS |Acc@1 |Acc@5 | +|:----:|:------------------------------------:|:---------------:|:-----:|:----:|:----:| +|120 |$0.6\times 0.1^{\lfloor E/30 \rfloor}$|O2 |955.433|79.130|94.058| +|120 |$1\times 0.45^{\lfloor E/10 \rfloor}$ |O2 |954.725|78.341|93.945| +|120 |$0.6\times 0.93^{E}$ |O2 |949.309|78.100|94.010| +|120 |$0.3\times (1+\cos{\frac{E\pi}{120}})$|O2 |951.374|80.161|94.879| + +### NPU 8p +|Epochs|Learning rate |Optimization type|FPS |Acc@1 |Acc@5 | +|:----:|:------------------------------------:|:---------------:|:------:|:----:|:----:| +|120 |$0.6\times 0.1^{\lfloor E/30 \rfloor}$|O2 |1524.537|78.599|93.849| |120 |$0.3\times (1+\cos{\frac{E\pi}{120}})$|O2 |1522.120|80.048|94.799| \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/SENet154/checkpoint.py b/PyTorch/contrib/cv/classification/SENet154/checkpoint.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/data.py b/PyTorch/contrib/cv/classification/SENet154/data.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/demo.py b/PyTorch/contrib/cv/classification/SENet154/demo.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/lsr.py b/PyTorch/contrib/cv/classification/SENet154/lsr.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/modelzoo_level.txt b/PyTorch/contrib/cv/classification/SENet154/modelzoo_level.txt old mode 100755 new mode 100644 index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 --- a/PyTorch/contrib/cv/classification/SENet154/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/SENet154/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/SENet154/pth2onnx.py b/PyTorch/contrib/cv/classification/SENet154/pth2onnx.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/senet.py b/PyTorch/contrib/cv/classification/SENet154/senet.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/test/env_npu.sh b/PyTorch/contrib/cv/classification/SENet154/test/env_npu.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/test/run_2onnx.sh b/PyTorch/contrib/cv/classification/SENet154/test/run_2onnx.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/test/run_demo.sh b/PyTorch/contrib/cv/classification/SENet154/test/run_demo.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/test/train_eval_8p.sh b/PyTorch/contrib/cv/classification/SENet154/test/train_eval_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/test/train_full_1p.sh b/PyTorch/contrib/cv/classification/SENet154/test/train_full_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/test/train_full_8p.sh b/PyTorch/contrib/cv/classification/SENet154/test/train_full_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/test/train_performance_1p.sh b/PyTorch/contrib/cv/classification/SENet154/test/train_performance_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/test/train_performance_8p.sh b/PyTorch/contrib/cv/classification/SENet154/test/train_performance_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/train.py b/PyTorch/contrib/cv/classification/SENet154/train.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SENet154/utils.py b/PyTorch/contrib/cv/classification/SENet154/utils.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/Dockerfile b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/Dockerfile old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/LICENSE b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/LICENSE old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/README.md b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/README.md old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/demo.py b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/demo.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/docker_start.sh b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/docker_start.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/main.py b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/main.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/modelzoo_level.txt b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/modelzoo_level.txt old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/pthtar2onnx.py b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/pthtar2onnx.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/requirements.txt b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/requirements.txt old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/scripts/eval.sh b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/scripts/eval.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/scripts/npu_set_env.sh b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/scripts/npu_set_env.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/scripts/train_1p.sh b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/scripts/train_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/scripts/train_8p.sh b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/scripts/train_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/senet.py b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/senet.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/test/env_npu.sh b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/test/env_npu.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/test/train_eval_8p.sh b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/test/train_eval_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/test/train_full_1p.sh b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/test/train_full_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/test/train_full_8p.sh b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/test/train_full_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/test/train_performance_1p.sh b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/test/train_performance_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/test/train_performance_8p.sh b/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d/test/train_performance_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/ShuffleNetV1_ID1625_for_PyTorch/Dockerfile b/PyTorch/contrib/cv/classification/ShuffleNetV1_ID1625_for_PyTorch/Dockerfile index 7e712fe1a166790798f57a2f2762c47394beb625..30a31af55804dd79571d2a36e6107a844cb7e549 100644 --- a/PyTorch/contrib/cv/classification/ShuffleNetV1_ID1625_for_PyTorch/Dockerfile +++ b/PyTorch/contrib/cv/classification/ShuffleNetV1_ID1625_for_PyTorch/Dockerfile @@ -1,5 +1,5 @@ -ARG FROM_IMAGE_NAME -FROM $FROM_IMAGE_NAME - -COPY requirements.txt . +ARG FROM_IMAGE_NAME +FROM $FROM_IMAGE_NAME + +COPY requirements.txt . RUN pip3.7 install -r requirements.txt \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/ShuffleNetV1_ID1625_for_PyTorch/docker_start.sh b/PyTorch/contrib/cv/classification/ShuffleNetV1_ID1625_for_PyTorch/docker_start.sh index 46ce9a02ec0532d6db324beaee7f7eab501b4565..944bca3cdac8e3f2d47ceb0e2b6eb181a405de11 100644 --- a/PyTorch/contrib/cv/classification/ShuffleNetV1_ID1625_for_PyTorch/docker_start.sh +++ b/PyTorch/contrib/cv/classification/ShuffleNetV1_ID1625_for_PyTorch/docker_start.sh @@ -1,25 +1,25 @@ -#!/bin/bash - -docker_image=$1 -data_dir=$2 -model_dir=$3 - -docker run -it --ipc=host \ - --device=/dev/davinci0 \ - --device=/dev/davinci1 \ - --device=/dev/davinci2 \ - --device=/dev/davinci3 \ - --device=/dev/davinci4 \ - --device=/dev/davinci5 \ - --device=/dev/davinci6 \ - --device=/dev/davinci7 \ - --device=/dev/davinci_manager \ - --device=/dev/devmm_svm --device=/dev/hisi_hdc \ - -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ - -v /usr/local/Ascend/add-ons/:/usr/local/Ascend/add-ons/ \ - -v ${model_dir}:${model_dir} \ - -v ${data_dir}:${data_dir} \ - -v /var/log/npu/conf/slog/slog.conf:/var/log/npu/conf/slog/slog.conf \ - -v /var/log/npu/slog/:/var/log/npu/slog -v /var/log/npu/profiling/:/var/log/npu/profiling \ - -v /var/log/npu/dump/:/var/log/npu/dump -v /var/log/npu/:/usr/slog ${docker_image} \ +#!/bin/bash + +docker_image=$1 +data_dir=$2 +model_dir=$3 + +docker run -it --ipc=host \ + --device=/dev/davinci0 \ + --device=/dev/davinci1 \ + --device=/dev/davinci2 \ + --device=/dev/davinci3 \ + --device=/dev/davinci4 \ + --device=/dev/davinci5 \ + --device=/dev/davinci6 \ + --device=/dev/davinci7 \ + --device=/dev/davinci_manager \ + --device=/dev/devmm_svm --device=/dev/hisi_hdc \ + -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ + -v /usr/local/Ascend/add-ons/:/usr/local/Ascend/add-ons/ \ + -v ${model_dir}:${model_dir} \ + -v ${data_dir}:${data_dir} \ + -v /var/log/npu/conf/slog/slog.conf:/var/log/npu/conf/slog/slog.conf \ + -v /var/log/npu/slog/:/var/log/npu/slog -v /var/log/npu/profiling/:/var/log/npu/profiling \ + -v /var/log/npu/dump/:/var/log/npu/dump -v /var/log/npu/:/usr/slog ${docker_image} \ /bin/bash \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/ShuffleNetV1_ID1625_for_PyTorch/modelzoo_level.txt b/PyTorch/contrib/cv/classification/ShuffleNetV1_ID1625_for_PyTorch/modelzoo_level.txt index 5afcef9188bf9d39f1e34b45bd91324c6093137a..3117fffc3be7f5c479f10f09ba38a25c47739a00 100644 --- a/PyTorch/contrib/cv/classification/ShuffleNetV1_ID1625_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/ShuffleNetV1_ID1625_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/ShuffleNetV2Plus_ID1626_for_PyTorch/README.md b/PyTorch/contrib/cv/classification/ShuffleNetV2Plus_ID1626_for_PyTorch/README.md index 8e6c6f3a8684d96a14ae038746a5f9c6eb8fdd0f..f9b639886e4534148bc8225ccc412a0c2d1ca9ee 100644 --- a/PyTorch/contrib/cv/classification/ShuffleNetV2Plus_ID1626_for_PyTorch/README.md +++ b/PyTorch/contrib/cv/classification/ShuffleNetV2Plus_ID1626_for_PyTorch/README.md @@ -1,56 +1,56 @@ -# ShuffleNetV2Plus (size=Small) - -## ImageNet training with PyTorch - -This implements training of ShuffleNetV1 on the ImageNet dataset, mainly modified from [Github](https://github.com/pytorch/examples/tree/master/imagenet). - -## ShuffleNetV2Plus Detail - -Base version of the model from [the paper author's code on Github](https://github.com/megvii-model/ShuffleNet-Series/tree/master/ShuffleNetV2%2B). -The training script is adapted from [the ShuffleNetV2 script on Gitee](https://gitee.com/ascend/modelzoo/tree/master/built-in/PyTorch/Official/cv/image_classification/Shufflenetv2_for_PyTorch). - -## Requirements - -- pytorch_ascend, apex_ascend, tochvision -- Download the ImageNet dataset from http://www.image-net.org/ - - Then, and move validation images to labeled subfolders, using [the following shell script](https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh). - -## Training -一、训练流程: - -单卡训练流程: - - 1.安装环境 - 2.修改参数device_id(单卡训练所使用的device id),为训练配置device_id,比如device_id=0 - 3.开始训练 - bash ./test/train_full_1p.sh --data_path=数据集路径 # 精度训练 - bash ./test/train_performance_1p.sh --data_path=数据集路径 # 性能训练 - - -多卡训练流程 - - 1.安装环境 - 2.修改参数device_id_list(多卡训练所使用的device id列表),为训练配置device_id,例如device_id=0,1,2,3,4,5,6,7 - 3.执行train_full_8p.sh开始训练 - bash ./test/train_full_8p.sh --data_path=数据集路径 # 精度训练 - bash ./test/train_performance_8p.sh --data_path=数据集路径 # 性能训练 - -二、测试结果 - -训练日志路径:网络脚本test下output文件夹内。例如: - - test/output/devie_id/train_${device_id}.log # 训练脚本原生日志 - test/output/devie_id/ShuffleNetV1_bs8192_8p_perf.log # 8p性能训练结果日志 - test/output/devie_id/ShuffleNetV1_bs8192_8p_acc.log # 8p精度训练结果日志 - -训练模型:训练生成的模型默认会写入到和test文件同一目录下。当训练正常结束时,checkpoint.pth.tar为最终结果。 - - - -## ShufflenetV2Plus training result - -| Acc@1 | FPS | Npu_nums| Epochs | Type | -| :------: | :------: | :------ | :------: | :------: | -| 73.132 | 6306 | 8 | 360 | O2 | - +# ShuffleNetV2Plus (size=Small) + +## ImageNet training with PyTorch + +This implements training of ShuffleNetV1 on the ImageNet dataset, mainly modified from [Github](https://github.com/pytorch/examples/tree/master/imagenet). + +## ShuffleNetV2Plus Detail + +Base version of the model from [the paper author's code on Github](https://github.com/megvii-model/ShuffleNet-Series/tree/master/ShuffleNetV2%2B). +The training script is adapted from [the ShuffleNetV2 script on Gitee](https://gitee.com/ascend/modelzoo/tree/master/built-in/PyTorch/Official/cv/image_classification/Shufflenetv2_for_PyTorch). + +## Requirements + +- pytorch_ascend, apex_ascend, tochvision +- Download the ImageNet dataset from http://www.image-net.org/ + - Then, and move validation images to labeled subfolders, using [the following shell script](https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh). + +## Training +一、训练流程: + +单卡训练流程: + + 1.安装环境 + 2.修改参数device_id(单卡训练所使用的device id),为训练配置device_id,比如device_id=0 + 3.开始训练 + bash ./test/train_full_1p.sh --data_path=数据集路径 # 精度训练 + bash ./test/train_performance_1p.sh --data_path=数据集路径 # 性能训练 + + +多卡训练流程 + + 1.安装环境 + 2.修改参数device_id_list(多卡训练所使用的device id列表),为训练配置device_id,例如device_id=0,1,2,3,4,5,6,7 + 3.执行train_full_8p.sh开始训练 + bash ./test/train_full_8p.sh --data_path=数据集路径 # 精度训练 + bash ./test/train_performance_8p.sh --data_path=数据集路径 # 性能训练 + +二、测试结果 + +训练日志路径:网络脚本test下output文件夹内。例如: + + test/output/devie_id/train_${device_id}.log # 训练脚本原生日志 + test/output/devie_id/ShuffleNetV1_bs8192_8p_perf.log # 8p性能训练结果日志 + test/output/devie_id/ShuffleNetV1_bs8192_8p_acc.log # 8p精度训练结果日志 + +训练模型:训练生成的模型默认会写入到和test文件同一目录下。当训练正常结束时,checkpoint.pth.tar为最终结果。 + + + +## ShufflenetV2Plus training result + +| Acc@1 | FPS | Npu_nums| Epochs | Type | +| :------: | :------: | :------ | :------: | :------: | +| 73.132 | 6306 | 8 | 360 | O2 | + 备注:由于模型开发中发现NPU上clamp算子反向错误,以上结果为使用自行编写的clamp函数训练获得。见blocks.py中的注释掉的函数clamp。 \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/ShuffleNetV2Plus_ID1626_for_PyTorch/blocks.py b/PyTorch/contrib/cv/classification/ShuffleNetV2Plus_ID1626_for_PyTorch/blocks.py index 5619d2624d2235e7a5ac3f8401bfccae4cf8c903..044cd05d70d3322580abd7deb46897da17379e48 100644 --- a/PyTorch/contrib/cv/classification/ShuffleNetV2Plus_ID1626_for_PyTorch/blocks.py +++ b/PyTorch/contrib/cv/classification/ShuffleNetV2Plus_ID1626_for_PyTorch/blocks.py @@ -1,249 +1,249 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - - -import torch -import torch.nn as nn - -try: - from .channel_shuffle import ChannelShuffle -except: - from channel_shuffle import ChannelShuffle - -''' -def clamp(x, low=0, high=6): - low_mask = x < low - high_mask = x > high - keep_mask = ~(low_mask|high_mask) - out = x * keep_mask.to(x) + high * high_mask.to(x) + low * low_mask.to(x) - return out -''' - -class SELayer(nn.Module): - - def __init__(self, inplanes, isTensor=True): - super(SELayer, self).__init__() - if isTensor: - # if the input is (N, C, H, W) - self.SE_opr = nn.Sequential( - nn.AdaptiveAvgPool2d(1), - nn.Conv2d(inplanes, inplanes // 4, kernel_size=1, stride=1, bias=False), - nn.BatchNorm2d(inplanes // 4), - nn.ReLU(inplace=True), - nn.Conv2d(inplanes // 4, inplanes, kernel_size=1, stride=1, bias=False), - ) - else: - # if the input is (N, C) - self.SE_opr = nn.Sequential( - nn.AdaptiveAvgPool2d(1), - nn.Linear(inplanes, inplanes // 4, bias=False), - nn.BatchNorm1d(inplanes // 4), - nn.ReLU(inplace=True), - nn.Linear(inplanes // 4, inplanes, bias=False), - ) - - def forward(self, x): - atten = self.SE_opr(x) - #atten = clamp(atten + 3.0, 0.0, 6.0) / 6.0 - atten = torch.clamp(atten + 3, 0, 6) / 6 - return x * atten - - -class HS(nn.Module): - - def __init__(self): - super(HS, self).__init__() - - def forward(self, inputs): - clip = torch.clamp(inputs + 3, 0, 6) / 6 - #clip = clamp(inputs + 3.0, 0.0, 6.0) / 6.0 - return inputs * clip - - - -class Shufflenet(nn.Module): - - def __init__(self, inp, oup, base_mid_channels, *, ksize, stride, activation, useSE): - super(Shufflenet, self).__init__() - self.stride = stride - assert stride in [1, 2] - assert ksize in [3, 5, 7] - assert base_mid_channels == oup//2 - - self.base_mid_channel = base_mid_channels - self.ksize = ksize - pad = ksize // 2 - self.pad = pad - self.inp = inp - - outputs = oup - inp - - branch_main = [ - # pw - nn.Conv2d(inp, base_mid_channels, 1, 1, 0, bias=False), - nn.BatchNorm2d(base_mid_channels), - None, - # dw - nn.Conv2d(base_mid_channels, base_mid_channels, ksize, stride, pad, groups=base_mid_channels, bias=False), - nn.BatchNorm2d(base_mid_channels), - # pw-linear - nn.Conv2d(base_mid_channels, outputs, 1, 1, 0, bias=False), - nn.BatchNorm2d(outputs), - None, - ] - if activation == 'ReLU': - assert useSE == False - '''This model should not have SE with ReLU''' - branch_main[2] = nn.ReLU(inplace=True) - branch_main[-1] = nn.ReLU(inplace=True) - else: - branch_main[2] = HS() - branch_main[-1] = HS() - if useSE: - branch_main.append(SELayer(outputs)) - self.branch_main = nn.Sequential(*branch_main) - - if stride == 2: - branch_proj = [ - # dw - nn.Conv2d(inp, inp, ksize, stride, pad, groups=inp, bias=False), - nn.BatchNorm2d(inp), - # pw-linear - nn.Conv2d(inp, inp, 1, 1, 0, bias=False), - nn.BatchNorm2d(inp), - None, - ] - if activation == 'ReLU': - branch_proj[-1] = nn.ReLU(inplace=True) - else: - branch_proj[-1] = HS() - self.branch_proj = nn.Sequential(*branch_proj) - else: - self.branch_proj = None - - self.channel_shuffle = ChannelShuffle(inp*2) - - def forward(self, old_x): - if self.stride==1: - x_proj, x = self.channel_shuffle(old_x) - return torch.cat((x_proj, self.branch_main(x)), 1) - elif self.stride==2: - x_proj = old_x - x = old_x - - x1 = self.branch_proj(x_proj) - x2 = self.branch_main(x) - - return torch.cat((x1, x2), 1) - -class Shuffle_Xception(nn.Module): - - def __init__(self, inp, oup, base_mid_channels, *, stride, activation, useSE): - super(Shuffle_Xception, self).__init__() - - assert stride in [1, 2] - assert base_mid_channels == oup//2 - - self.base_mid_channel = base_mid_channels - self.stride = stride - self.ksize = 3 - self.pad = 1 - self.inp = inp - outputs = oup - inp - - branch_main = [ - # dw - nn.Conv2d(inp, inp, 3, stride, 1, groups=inp, bias=False), - nn.BatchNorm2d(inp), - # pw - nn.Conv2d(inp, base_mid_channels, 1, 1, 0, bias=False), - nn.BatchNorm2d(base_mid_channels), - None, - # dw - nn.Conv2d(base_mid_channels, base_mid_channels, 3, stride, 1, groups=base_mid_channels, bias=False), - nn.BatchNorm2d(base_mid_channels), - # pw - nn.Conv2d(base_mid_channels, base_mid_channels, 1, 1, 0, bias=False), - nn.BatchNorm2d(base_mid_channels), - None, - # dw - nn.Conv2d(base_mid_channels, base_mid_channels, 3, stride, 1, groups=base_mid_channels, bias=False), - nn.BatchNorm2d(base_mid_channels), - # pw - nn.Conv2d(base_mid_channels, outputs, 1, 1, 0, bias=False), - nn.BatchNorm2d(outputs), - None, - ] - - if activation == 'ReLU': - branch_main[4] = nn.ReLU(inplace=True) - branch_main[9] = nn.ReLU(inplace=True) - branch_main[14] = nn.ReLU(inplace=True) - else: - branch_main[4] = HS() - branch_main[9] = HS() - branch_main[14] = HS() - assert None not in branch_main - - if useSE: - assert activation != 'ReLU' - branch_main.append(SELayer(outputs)) - - self.branch_main = nn.Sequential(*branch_main) - - if self.stride == 2: - branch_proj = [ - # dw - nn.Conv2d(inp, inp, 3, stride, 1, groups=inp, bias=False), - nn.BatchNorm2d(inp), - # pw-linear - nn.Conv2d(inp, inp, 1, 1, 0, bias=False), - nn.BatchNorm2d(inp), - None, - ] - if activation == 'ReLU': - branch_proj[-1] = nn.ReLU(inplace=True) - else: - branch_proj[-1] = HS() - self.branch_proj = nn.Sequential(*branch_proj) - - self.channel_shuffle = ChannelShuffle(inp*2) - - def forward(self, old_x): - if self.stride==1: - x_proj, x = self.channel_shuffle(old_x) - return torch.cat((x_proj, self.branch_main(x)), 1) - elif self.stride==2: - x_proj = old_x - x = old_x - return torch.cat((self.branch_proj(x_proj), self.branch_main(x)), 1) - +# BSD 3-Clause License +# +# Copyright (c) 2017 +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + + +import torch +import torch.nn as nn + +try: + from .channel_shuffle import ChannelShuffle +except: + from channel_shuffle import ChannelShuffle + +''' +def clamp(x, low=0, high=6): + low_mask = x < low + high_mask = x > high + keep_mask = ~(low_mask|high_mask) + out = x * keep_mask.to(x) + high * high_mask.to(x) + low * low_mask.to(x) + return out +''' + +class SELayer(nn.Module): + + def __init__(self, inplanes, isTensor=True): + super(SELayer, self).__init__() + if isTensor: + # if the input is (N, C, H, W) + self.SE_opr = nn.Sequential( + nn.AdaptiveAvgPool2d(1), + nn.Conv2d(inplanes, inplanes // 4, kernel_size=1, stride=1, bias=False), + nn.BatchNorm2d(inplanes // 4), + nn.ReLU(inplace=True), + nn.Conv2d(inplanes // 4, inplanes, kernel_size=1, stride=1, bias=False), + ) + else: + # if the input is (N, C) + self.SE_opr = nn.Sequential( + nn.AdaptiveAvgPool2d(1), + nn.Linear(inplanes, inplanes // 4, bias=False), + nn.BatchNorm1d(inplanes // 4), + nn.ReLU(inplace=True), + nn.Linear(inplanes // 4, inplanes, bias=False), + ) + + def forward(self, x): + atten = self.SE_opr(x) + #atten = clamp(atten + 3.0, 0.0, 6.0) / 6.0 + atten = torch.clamp(atten + 3, 0, 6) / 6 + return x * atten + + +class HS(nn.Module): + + def __init__(self): + super(HS, self).__init__() + + def forward(self, inputs): + clip = torch.clamp(inputs + 3, 0, 6) / 6 + #clip = clamp(inputs + 3.0, 0.0, 6.0) / 6.0 + return inputs * clip + + + +class Shufflenet(nn.Module): + + def __init__(self, inp, oup, base_mid_channels, *, ksize, stride, activation, useSE): + super(Shufflenet, self).__init__() + self.stride = stride + assert stride in [1, 2] + assert ksize in [3, 5, 7] + assert base_mid_channels == oup//2 + + self.base_mid_channel = base_mid_channels + self.ksize = ksize + pad = ksize // 2 + self.pad = pad + self.inp = inp + + outputs = oup - inp + + branch_main = [ + # pw + nn.Conv2d(inp, base_mid_channels, 1, 1, 0, bias=False), + nn.BatchNorm2d(base_mid_channels), + None, + # dw + nn.Conv2d(base_mid_channels, base_mid_channels, ksize, stride, pad, groups=base_mid_channels, bias=False), + nn.BatchNorm2d(base_mid_channels), + # pw-linear + nn.Conv2d(base_mid_channels, outputs, 1, 1, 0, bias=False), + nn.BatchNorm2d(outputs), + None, + ] + if activation == 'ReLU': + assert useSE == False + '''This model should not have SE with ReLU''' + branch_main[2] = nn.ReLU(inplace=True) + branch_main[-1] = nn.ReLU(inplace=True) + else: + branch_main[2] = HS() + branch_main[-1] = HS() + if useSE: + branch_main.append(SELayer(outputs)) + self.branch_main = nn.Sequential(*branch_main) + + if stride == 2: + branch_proj = [ + # dw + nn.Conv2d(inp, inp, ksize, stride, pad, groups=inp, bias=False), + nn.BatchNorm2d(inp), + # pw-linear + nn.Conv2d(inp, inp, 1, 1, 0, bias=False), + nn.BatchNorm2d(inp), + None, + ] + if activation == 'ReLU': + branch_proj[-1] = nn.ReLU(inplace=True) + else: + branch_proj[-1] = HS() + self.branch_proj = nn.Sequential(*branch_proj) + else: + self.branch_proj = None + + self.channel_shuffle = ChannelShuffle(inp*2) + + def forward(self, old_x): + if self.stride==1: + x_proj, x = self.channel_shuffle(old_x) + return torch.cat((x_proj, self.branch_main(x)), 1) + elif self.stride==2: + x_proj = old_x + x = old_x + + x1 = self.branch_proj(x_proj) + x2 = self.branch_main(x) + + return torch.cat((x1, x2), 1) + +class Shuffle_Xception(nn.Module): + + def __init__(self, inp, oup, base_mid_channels, *, stride, activation, useSE): + super(Shuffle_Xception, self).__init__() + + assert stride in [1, 2] + assert base_mid_channels == oup//2 + + self.base_mid_channel = base_mid_channels + self.stride = stride + self.ksize = 3 + self.pad = 1 + self.inp = inp + outputs = oup - inp + + branch_main = [ + # dw + nn.Conv2d(inp, inp, 3, stride, 1, groups=inp, bias=False), + nn.BatchNorm2d(inp), + # pw + nn.Conv2d(inp, base_mid_channels, 1, 1, 0, bias=False), + nn.BatchNorm2d(base_mid_channels), + None, + # dw + nn.Conv2d(base_mid_channels, base_mid_channels, 3, stride, 1, groups=base_mid_channels, bias=False), + nn.BatchNorm2d(base_mid_channels), + # pw + nn.Conv2d(base_mid_channels, base_mid_channels, 1, 1, 0, bias=False), + nn.BatchNorm2d(base_mid_channels), + None, + # dw + nn.Conv2d(base_mid_channels, base_mid_channels, 3, stride, 1, groups=base_mid_channels, bias=False), + nn.BatchNorm2d(base_mid_channels), + # pw + nn.Conv2d(base_mid_channels, outputs, 1, 1, 0, bias=False), + nn.BatchNorm2d(outputs), + None, + ] + + if activation == 'ReLU': + branch_main[4] = nn.ReLU(inplace=True) + branch_main[9] = nn.ReLU(inplace=True) + branch_main[14] = nn.ReLU(inplace=True) + else: + branch_main[4] = HS() + branch_main[9] = HS() + branch_main[14] = HS() + assert None not in branch_main + + if useSE: + assert activation != 'ReLU' + branch_main.append(SELayer(outputs)) + + self.branch_main = nn.Sequential(*branch_main) + + if self.stride == 2: + branch_proj = [ + # dw + nn.Conv2d(inp, inp, 3, stride, 1, groups=inp, bias=False), + nn.BatchNorm2d(inp), + # pw-linear + nn.Conv2d(inp, inp, 1, 1, 0, bias=False), + nn.BatchNorm2d(inp), + None, + ] + if activation == 'ReLU': + branch_proj[-1] = nn.ReLU(inplace=True) + else: + branch_proj[-1] = HS() + self.branch_proj = nn.Sequential(*branch_proj) + + self.channel_shuffle = ChannelShuffle(inp*2) + + def forward(self, old_x): + if self.stride==1: + x_proj, x = self.channel_shuffle(old_x) + return torch.cat((x_proj, self.branch_main(x)), 1) + elif self.stride==2: + x_proj = old_x + x = old_x + return torch.cat((self.branch_proj(x_proj), self.branch_main(x)), 1) + diff --git a/PyTorch/contrib/cv/classification/ShuffleNetV2Plus_ID1626_for_PyTorch/channel_shuffle.py b/PyTorch/contrib/cv/classification/ShuffleNetV2Plus_ID1626_for_PyTorch/channel_shuffle.py index bda735f26f138fc412e020e4e69269cda732aeee..69d46a643aab83720d89c5424b70b50bc22f404e 100644 --- a/PyTorch/contrib/cv/classification/ShuffleNetV2Plus_ID1626_for_PyTorch/channel_shuffle.py +++ b/PyTorch/contrib/cv/classification/ShuffleNetV2Plus_ID1626_for_PyTorch/channel_shuffle.py @@ -1,156 +1,156 @@ -# Copyright (c) 2020, Huawei Technologies.All rights reserved. -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import numpy as np -import torch -import torch.nn as nn - - -class ChannelShuffle(nn.Module): - r"""Applies an NPU compatible channel shuffle operation. - - The origin implement is https://github.com/pytorch/vision/blob/master/torchvision/models/shufflenetv2.py#L21 - - In order to avoid contiguous operation which is not efficient on npu, we replaced the original operation - with a rewrite of the same semantics. Two discontinuous operations are replaced, transpose and chunk. - - .. note:: - Only group=2 is implemented, modify other group scenarios yourself. - - Args: - in_channels (int): The total number of channels in the input tensors - groups (int): The number of shuffle groups. Default: 2 - split_shuffle (bool): Whether to execute the chunk after shuffle. Default: True - - Shape: - - Input: :math:`(N, C_{in}, L_{in})`, `(N, C_{in}, L_{in})` - - Output: :math:`(N, C_{out}, L_{out})` - - Examples:: - >>> x1 = torch.randn(2,32,7,7) - >>> x2 = torch.randn(2,32,7,7) - >>> m = ChannelShuffle(64, split_shuffle=True) - >>> output = m(x1, x2) - - """ - - def __init__(self, in_channels, groups=2): - super(ChannelShuffle, self).__init__() - self.group_len = in_channels // groups - - # init out_channels - self.out_channels = np.array(list(range(in_channels))).reshape(groups, self.group_len).transpose(1, 0).flatten() - self.out_channels = torch.from_numpy(self.out_channels).long() - - # init index used in fp & bp - # Only group=2 is implemented, modify other group scenarios yourself. - self.fp_index1 = self.out_channels[:self.group_len] - self.fp_index2 = self.out_channels[self.group_len:] - self.bp_index = torch.tensor(list(range(0, in_channels, 2)) + list(range(1, in_channels, 2))) - - self.checked = False - - def check_self(self, x): - r"""Check device equipment between tensors. - """ - if self.bp_index.device == x.device: - self.checked = True - return - - device = x.device - if str(device).startswith('npu'): - self.fp_index1 = self.fp_index1.int() - self.fp_index2 = self.fp_index2.int() - self.bp_index = self.bp_index.int() - - self.fp_index1 = self.fp_index1.to(device) - self.fp_index2 = self.fp_index2.to(device) - self.bp_index = self.bp_index.to(device) - - - def forward(self, x): - if not self.checked: - self.check_self(x) - if self.training: - return IndexSelectHalfImplementation.apply(x, self.fp_index1, self.fp_index2, self.bp_index) - else: - return IndexSelectHalfImplementationForward(x, self.fp_index1, self.fp_index2, self.bp_index) - -def IndexSelectHalfImplementationForward(x, fp_index1, fp_index2, bp_index): - return x.index_select(1, fp_index1), x.index_select(1, fp_index2) - -class IndexSelectHalfImplementation(torch.autograd.Function): - @staticmethod - def forward(ctx, x, fp_index1, fp_index2, bp_index): - ctx.bp_index = bp_index - return x.index_select(1, fp_index1), x.index_select(1, fp_index2) - - @staticmethod - def backward(ctx, grad_output1, grad_output2): - grad_output = torch.cat([grad_output1, grad_output2], 1) - out = grad_output.index_select(1, ctx.bp_index) - return out, None, None, None, None - -def channel_shuffle_torchvision(x, groups=2): - # type: (torch.Tensor, int) -> torch.Tensor - batchsize, num_channels, height, width = x.data.size() - channels_per_group = num_channels // groups - - # reshape - x = x.view(batchsize, groups, - channels_per_group, height, width) - - x = torch.transpose(x, 1, 2).contiguous() - - # flatten - x = x.view(batchsize, -1, height, width) - - return x.chunk(2, 1) - -def channel_shuffle_megvii(x): - batchsize, num_channels, height, width = x.data.size() - assert (num_channels % 4 == 0) - x = x.reshape(batchsize * num_channels // 2, 2, height * width) - x = x.permute(1, 0, 2) - x = x.reshape(2, -1, num_channels // 2, height, width) - return x[0], x[1] - -if __name__ == '__main__': - device = 'cpu' - - if device.startswith('npu'): - torch.npu.set_device(device) - - channels = 8 - BZ = 2 - H = 1 - W = 1 - - # x = torch.randn(BZ, channels, H, W) - x = torch.arange(BZ*channels*H*W).reshape(BZ, channels, H, W) - print(x) - cs_model = ChannelShuffle(channels) - - x = x.to(device) - cs_model = cs_model.to(device) - - output1 = channel_shuffle_megvii(x) - print(output1[0]) - output2 = channel_shuffle_torchvision(x) - print(output2[0]) - output3 = cs_model(x) - print('output1-output2',sum((i-j).abs().sum() for i, j in zip(output1, output2))) - print('output2-output3',sum((i-j).abs().sum() for i, j in zip(output2, output3))) - print('output1-output3',sum((i-j).abs().sum() for i, j in zip(output1, output3))) - +# Copyright (c) 2020, Huawei Technologies.All rights reserved. +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +import torch +import torch.nn as nn + + +class ChannelShuffle(nn.Module): + r"""Applies an NPU compatible channel shuffle operation. + + The origin implement is https://github.com/pytorch/vision/blob/master/torchvision/models/shufflenetv2.py#L21 + + In order to avoid contiguous operation which is not efficient on npu, we replaced the original operation + with a rewrite of the same semantics. Two discontinuous operations are replaced, transpose and chunk. + + .. note:: + Only group=2 is implemented, modify other group scenarios yourself. + + Args: + in_channels (int): The total number of channels in the input tensors + groups (int): The number of shuffle groups. Default: 2 + split_shuffle (bool): Whether to execute the chunk after shuffle. Default: True + + Shape: + - Input: :math:`(N, C_{in}, L_{in})`, `(N, C_{in}, L_{in})` + - Output: :math:`(N, C_{out}, L_{out})` + + Examples:: + >>> x1 = torch.randn(2,32,7,7) + >>> x2 = torch.randn(2,32,7,7) + >>> m = ChannelShuffle(64, split_shuffle=True) + >>> output = m(x1, x2) + + """ + + def __init__(self, in_channels, groups=2): + super(ChannelShuffle, self).__init__() + self.group_len = in_channels // groups + + # init out_channels + self.out_channels = np.array(list(range(in_channels))).reshape(groups, self.group_len).transpose(1, 0).flatten() + self.out_channels = torch.from_numpy(self.out_channels).long() + + # init index used in fp & bp + # Only group=2 is implemented, modify other group scenarios yourself. + self.fp_index1 = self.out_channels[:self.group_len] + self.fp_index2 = self.out_channels[self.group_len:] + self.bp_index = torch.tensor(list(range(0, in_channels, 2)) + list(range(1, in_channels, 2))) + + self.checked = False + + def check_self(self, x): + r"""Check device equipment between tensors. + """ + if self.bp_index.device == x.device: + self.checked = True + return + + device = x.device + if str(device).startswith('npu'): + self.fp_index1 = self.fp_index1.int() + self.fp_index2 = self.fp_index2.int() + self.bp_index = self.bp_index.int() + + self.fp_index1 = self.fp_index1.to(device) + self.fp_index2 = self.fp_index2.to(device) + self.bp_index = self.bp_index.to(device) + + + def forward(self, x): + if not self.checked: + self.check_self(x) + if self.training: + return IndexSelectHalfImplementation.apply(x, self.fp_index1, self.fp_index2, self.bp_index) + else: + return IndexSelectHalfImplementationForward(x, self.fp_index1, self.fp_index2, self.bp_index) + +def IndexSelectHalfImplementationForward(x, fp_index1, fp_index2, bp_index): + return x.index_select(1, fp_index1), x.index_select(1, fp_index2) + +class IndexSelectHalfImplementation(torch.autograd.Function): + @staticmethod + def forward(ctx, x, fp_index1, fp_index2, bp_index): + ctx.bp_index = bp_index + return x.index_select(1, fp_index1), x.index_select(1, fp_index2) + + @staticmethod + def backward(ctx, grad_output1, grad_output2): + grad_output = torch.cat([grad_output1, grad_output2], 1) + out = grad_output.index_select(1, ctx.bp_index) + return out, None, None, None, None + +def channel_shuffle_torchvision(x, groups=2): + # type: (torch.Tensor, int) -> torch.Tensor + batchsize, num_channels, height, width = x.data.size() + channels_per_group = num_channels // groups + + # reshape + x = x.view(batchsize, groups, + channels_per_group, height, width) + + x = torch.transpose(x, 1, 2).contiguous() + + # flatten + x = x.view(batchsize, -1, height, width) + + return x.chunk(2, 1) + +def channel_shuffle_megvii(x): + batchsize, num_channels, height, width = x.data.size() + assert (num_channels % 4 == 0) + x = x.reshape(batchsize * num_channels // 2, 2, height * width) + x = x.permute(1, 0, 2) + x = x.reshape(2, -1, num_channels // 2, height, width) + return x[0], x[1] + +if __name__ == '__main__': + device = 'cpu' + + if device.startswith('npu'): + torch.npu.set_device(device) + + channels = 8 + BZ = 2 + H = 1 + W = 1 + + # x = torch.randn(BZ, channels, H, W) + x = torch.arange(BZ*channels*H*W).reshape(BZ, channels, H, W) + print(x) + cs_model = ChannelShuffle(channels) + + x = x.to(device) + cs_model = cs_model.to(device) + + output1 = channel_shuffle_megvii(x) + print(output1[0]) + output2 = channel_shuffle_torchvision(x) + print(output2[0]) + output3 = cs_model(x) + print('output1-output2',sum((i-j).abs().sum() for i, j in zip(output1, output2))) + print('output2-output3',sum((i-j).abs().sum() for i, j in zip(output2, output3))) + print('output1-output3',sum((i-j).abs().sum() for i, j in zip(output1, output3))) + diff --git a/PyTorch/contrib/cv/classification/SkresNet50/scripts/eval.sh b/PyTorch/contrib/cv/classification/SkresNet50/scripts/eval.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SkresNet50/scripts/npu_setenv.sh b/PyTorch/contrib/cv/classification/SkresNet50/scripts/npu_setenv.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SkresNet50/scripts/train_1p.sh b/PyTorch/contrib/cv/classification/SkresNet50/scripts/train_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SkresNet50/scripts/train_8p.sh b/PyTorch/contrib/cv/classification/SkresNet50/scripts/train_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SkresNet50/utils/progress/setup.py b/PyTorch/contrib/cv/classification/SkresNet50/utils/progress/setup.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/SkresNet50/utils/progress/test_progress.py b/PyTorch/contrib/cv/classification/SkresNet50/utils/progress/test_progress.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/TNT/npu_fused_adamw.py b/PyTorch/contrib/cv/classification/TNT/npu_fused_adamw.py index 8a8e3f5a8de82a0a7ebfc6bb41393e09ec5b78be..df662e48c114ef6406b9e5fc7bc50d4475deaa96 100644 --- a/PyTorch/contrib/cv/classification/TNT/npu_fused_adamw.py +++ b/PyTorch/contrib/cv/classification/TNT/npu_fused_adamw.py @@ -1,257 +1,257 @@ -# Copyright (c) 2020, Huawei Technologies. -# Copyright (c) 2019, Facebook CORPORATION. -# All rights reserved. -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import math -from collections import defaultdict - -import torch -from torch.optim.optimizer import Optimizer - -from apex.contrib.combine_tensors import combine_npu - - -class NpuFusedAdamW(Optimizer): - """Implements AdamW algorithm. - - Currently NPU-only. Requires Apex to be installed via - ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--npu_float_status" ./``. - - This version of NPU fused AdamW implements 1 fusions. - - * A combine-tensor apply launch that batches the elementwise updates applied to all the model's parameters - into one or a few kernel launches. - - :class:`apex.optimizers.NpuFusedAdamW` may be used as a drop-in replacement for ``torch.optim.AdamW``:: - - opt = apex.optimizers.NpuFusedAdamW(model.parameters(), lr = ....) - ... - opt.step() - - :class:`apex.optimizers.FusedAdamW` should be used with Amp. Currently, if you wish to use :class:`NpuFusedAdamW` - with Amp, only ``opt_level O1 and O2`` can be choosed:: - - opt = apex.optimizers.NpuFusedAdamW(model.parameters(), lr = ....) - model, opt = amp.initialize(model, opt, opt_level="O2") - ... - opt.step() - - - The original Adam algorithm was proposed in `Adam: A Method for Stochastic Optimization`_. - The AdamW variant was proposed in `Decoupled Weight Decay Regularization`_. - - Arguments: - params (iterable): iterable of parameters to optimize or dicts defining - parameter groups - lr (float, optional, default: 1e-3): learning rate - betas (Tuple[float, float], optional, default: (0.9, 0.999)): coefficients used - for computing running averages of gradient and its square - eps (float, optional, default: 1e-8): term added to the denominator to improve - numerical stability - weight_decay (float, optional, default: 1e-2): weight decay coefficient - amsgrad (boolean, optional, default: False): whether to use the AMSGrad variant of - this algorithm from the paper `On the Convergence of Adam and Beyond`_ - - .. _Adam\: A Method for Stochastic Optimization: - https://arxiv.org/abs/1412.6980 - .. _Decoupled Weight Decay Regularization: - https://arxiv.org/abs/1711.05101 - .. _On the Convergence of Adam and Beyond: - https://openreview.net/forum?id=ryQu7f-RZ - """ - - def __init__(self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, - weight_decay=1e-2, amsgrad=False): - if lr < 0.0: - raise ValueError("Invalid learning rate: {}".format(lr)) - if eps < 0.0: - raise ValueError("Invalid epsilon value: {}".format(eps)) - if betas[0] < 0.0 or betas[0] >= 1.0: - raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) - if betas[1] < 0.0 or betas[1] >= 1.0: - raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) - if weight_decay < 0.0: - raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) - defaults = dict(lr=lr, betas=betas, eps=eps, - weight_decay=weight_decay, amsgrad=amsgrad) - self.is_npu_fused_optimizer = True - super(NpuFusedAdamW, self).__init__(params, defaults) - - def __setstate__(self, state): - super(NpuFusedAdamW, self).__setstate__(state) - for group in self.param_groups: - group.setdefault('amsgrad', False) - - def _init_param_state(self, p, amsgrad): - state = self.state[p] - # State initialization - if len(state) == 0: - state['step'] = 0 - # Exponential moving average of gradient values - state['exp_avg'] = torch.zeros_like(p, memory_format=torch.preserve_format) - # Exponential moving average of squared gradient values - state['exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format) - if amsgrad: - # Maintains max of all exp. moving avg. of sq. grad. values - state['max_exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format) - else: - exp_avg_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) - exp_avg_tmp.copy_(state['exp_avg']) - state['exp_avg'] = exp_avg_tmp - - exp_avg_sq_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) - exp_avg_sq_tmp.copy_(state['exp_avg_sq']) - state['exp_avg_sq'] = exp_avg_sq_tmp - - if amsgrad: - max_exp_avg_sq_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) - max_exp_avg_sq_tmp.copy_(state['max_exp_avg_sq']) - state['max_exp_avg_sq'] = max_exp_avg_sq_tmp - - def _combine_group_param_states(self, group_index): - group = self.param_groups[group_index] - stash = self._amp_stash - group_params_list = stash.params_lists_indexed_by_group[group_index] - - amsgrad = group['amsgrad'] - - combined_param_states = [] - for params in group_params_list: - step_list = [] - exp_avg_list = [] - exp_avg_sq_list = [] - max_exp_avg_sq_list = [] - - for p in params: - if p.grad is None: - continue - grad = p.grad - if grad.is_sparse: - raise RuntimeError('NpuFusedAdamW does not support sparse gradients, ' - 'please consider SparseAdam instead') - - self._init_param_state(p, amsgrad) - state = self.state[p] - step_list.append(state['step']) - exp_avg_list.append(state['exp_avg']) - exp_avg_sq_list.append(state['exp_avg_sq']) - if amsgrad: - max_exp_avg_sq_list.append(state['max_exp_avg_sq']) - - combined_step = 0 - combined_exp_avg = None - combined_exp_avg_sq = None - combined_max_exp_avg_sq = None - - if len(exp_avg_list) > 0: - combined_step = step_list[0] - combined_exp_avg = combine_npu(exp_avg_list) - combined_exp_avg_sq = combine_npu(exp_avg_sq_list) - combined_max_exp_avg_sq = combine_npu(max_exp_avg_sq_list) - - combined_state = defaultdict(dict) - combined_state['step'] = combined_step - combined_state['exp_avg'] = combined_exp_avg - combined_state['exp_avg_sq'] = combined_exp_avg_sq - combined_state['max_exp_avg_sq'] = combined_max_exp_avg_sq - combined_param_states.append(combined_state) - stash.combined_param_states_indexed_by_group[group_index] = combined_param_states - - def _combine_param_states_by_group(self): - stash = self._amp_stash - if stash.param_states_are_combined_by_group: - return - - stash.combined_param_states_indexed_by_group = [] - for _ in self.param_groups: - stash.combined_param_states_indexed_by_group.append([]) - - for i, _ in enumerate(self.param_groups): - self._combine_group_param_states(i) - stash.param_states_are_combined_by_group = True - - def _group_step(self, group_index): - group = self.param_groups[group_index] - for p in group['params']: - if p.grad is None: - continue - - grad = p.grad - if grad.is_sparse: - raise RuntimeError('NpuFusedAdamW does not support sparse gradients, ' - 'please consider SparseAdam instead') - state_p = self.state[p] - state_p['step'] += 1 - - amsgrad = group['amsgrad'] - beta1, beta2 = group['betas'] - - stash = self._amp_stash - combined_group_params = stash.combined_params_indexed_by_group[group_index] - combined_group_grads = stash.combined_grads_indexed_by_group[group_index] - combined_group_param_states = stash.combined_param_states_indexed_by_group[group_index] - - for combined_param, combined_grad, combined_param_state in zip(combined_group_params, - combined_group_grads, - combined_group_param_states): - if combined_param is None or combined_grad is None: - continue - - # Perform stepweight decay. The fused method is used here to speed up the calculation - combined_param.mul_(1 - group['lr'] * group['weight_decay']) - - exp_avg, exp_avg_sq = combined_param_state['exp_avg'], combined_param_state['exp_avg_sq'] - if amsgrad: - max_exp_avg_sq = combined_param_state['max_exp_avg_sq'] - - combined_param_state['step'] += 1 - bias_correction1 = 1 - beta1 ** combined_param_state['step'] - bias_correction2 = 1 - beta2 ** combined_param_state['step'] - - # Decay the first and second moment running average coefficient - exp_avg.mul_(beta1).add_(combined_grad, alpha=1 - beta1) - exp_avg_sq.mul_(beta2).addcmul_(combined_grad, combined_grad, value=1 - beta2) - if amsgrad: - # Maintains the maximum of all 2nd moment running avg. till now - torch.max(max_exp_avg_sq, exp_avg_sq, out=max_exp_avg_sq) - # Use the max. for normalizing running avg. of gradient - denom = (max_exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group['eps']) - else: - denom = (exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group['eps']) - - step_size = group['lr'] / bias_correction1 - - combined_param.addcdiv_(exp_avg, denom, value=-step_size) - - @torch.no_grad() - def step(self, closure=None): - if not hasattr(self, "_amp_stash"): - raise RuntimeError('apex.optimizers.NpuFusedAdamW should be used with AMP.') - - self._check_already_combined_params_and_grads() - # combine params and grads first - self._combine_params_and_grads_by_group() - # then combine param states - self._combine_param_states_by_group() - - loss = None - if closure is not None: - with torch.enable_grad(): - loss = closure() - - for i, _ in enumerate(self.param_groups): - self._group_step(i) - - return loss +# Copyright (c) 2020, Huawei Technologies. +# Copyright (c) 2019, Facebook CORPORATION. +# All rights reserved. +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import math +from collections import defaultdict + +import torch +from torch.optim.optimizer import Optimizer + +from apex.contrib.combine_tensors import combine_npu + + +class NpuFusedAdamW(Optimizer): + """Implements AdamW algorithm. + + Currently NPU-only. Requires Apex to be installed via + ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--npu_float_status" ./``. + + This version of NPU fused AdamW implements 1 fusions. + + * A combine-tensor apply launch that batches the elementwise updates applied to all the model's parameters + into one or a few kernel launches. + + :class:`apex.optimizers.NpuFusedAdamW` may be used as a drop-in replacement for ``torch.optim.AdamW``:: + + opt = apex.optimizers.NpuFusedAdamW(model.parameters(), lr = ....) + ... + opt.step() + + :class:`apex.optimizers.FusedAdamW` should be used with Amp. Currently, if you wish to use :class:`NpuFusedAdamW` + with Amp, only ``opt_level O1 and O2`` can be choosed:: + + opt = apex.optimizers.NpuFusedAdamW(model.parameters(), lr = ....) + model, opt = amp.initialize(model, opt, opt_level="O2") + ... + opt.step() + + + The original Adam algorithm was proposed in `Adam: A Method for Stochastic Optimization`_. + The AdamW variant was proposed in `Decoupled Weight Decay Regularization`_. + + Arguments: + params (iterable): iterable of parameters to optimize or dicts defining + parameter groups + lr (float, optional, default: 1e-3): learning rate + betas (Tuple[float, float], optional, default: (0.9, 0.999)): coefficients used + for computing running averages of gradient and its square + eps (float, optional, default: 1e-8): term added to the denominator to improve + numerical stability + weight_decay (float, optional, default: 1e-2): weight decay coefficient + amsgrad (boolean, optional, default: False): whether to use the AMSGrad variant of + this algorithm from the paper `On the Convergence of Adam and Beyond`_ + + .. _Adam\: A Method for Stochastic Optimization: + https://arxiv.org/abs/1412.6980 + .. _Decoupled Weight Decay Regularization: + https://arxiv.org/abs/1711.05101 + .. _On the Convergence of Adam and Beyond: + https://openreview.net/forum?id=ryQu7f-RZ + """ + + def __init__(self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, + weight_decay=1e-2, amsgrad=False): + if lr < 0.0: + raise ValueError("Invalid learning rate: {}".format(lr)) + if eps < 0.0: + raise ValueError("Invalid epsilon value: {}".format(eps)) + if betas[0] < 0.0 or betas[0] >= 1.0: + raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) + if betas[1] < 0.0 or betas[1] >= 1.0: + raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) + if weight_decay < 0.0: + raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) + defaults = dict(lr=lr, betas=betas, eps=eps, + weight_decay=weight_decay, amsgrad=amsgrad) + self.is_npu_fused_optimizer = True + super(NpuFusedAdamW, self).__init__(params, defaults) + + def __setstate__(self, state): + super(NpuFusedAdamW, self).__setstate__(state) + for group in self.param_groups: + group.setdefault('amsgrad', False) + + def _init_param_state(self, p, amsgrad): + state = self.state[p] + # State initialization + if len(state) == 0: + state['step'] = 0 + # Exponential moving average of gradient values + state['exp_avg'] = torch.zeros_like(p, memory_format=torch.preserve_format) + # Exponential moving average of squared gradient values + state['exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format) + if amsgrad: + # Maintains max of all exp. moving avg. of sq. grad. values + state['max_exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format) + else: + exp_avg_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) + exp_avg_tmp.copy_(state['exp_avg']) + state['exp_avg'] = exp_avg_tmp + + exp_avg_sq_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) + exp_avg_sq_tmp.copy_(state['exp_avg_sq']) + state['exp_avg_sq'] = exp_avg_sq_tmp + + if amsgrad: + max_exp_avg_sq_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) + max_exp_avg_sq_tmp.copy_(state['max_exp_avg_sq']) + state['max_exp_avg_sq'] = max_exp_avg_sq_tmp + + def _combine_group_param_states(self, group_index): + group = self.param_groups[group_index] + stash = self._amp_stash + group_params_list = stash.params_lists_indexed_by_group[group_index] + + amsgrad = group['amsgrad'] + + combined_param_states = [] + for params in group_params_list: + step_list = [] + exp_avg_list = [] + exp_avg_sq_list = [] + max_exp_avg_sq_list = [] + + for p in params: + if p.grad is None: + continue + grad = p.grad + if grad.is_sparse: + raise RuntimeError('NpuFusedAdamW does not support sparse gradients, ' + 'please consider SparseAdam instead') + + self._init_param_state(p, amsgrad) + state = self.state[p] + step_list.append(state['step']) + exp_avg_list.append(state['exp_avg']) + exp_avg_sq_list.append(state['exp_avg_sq']) + if amsgrad: + max_exp_avg_sq_list.append(state['max_exp_avg_sq']) + + combined_step = 0 + combined_exp_avg = None + combined_exp_avg_sq = None + combined_max_exp_avg_sq = None + + if len(exp_avg_list) > 0: + combined_step = step_list[0] + combined_exp_avg = combine_npu(exp_avg_list) + combined_exp_avg_sq = combine_npu(exp_avg_sq_list) + combined_max_exp_avg_sq = combine_npu(max_exp_avg_sq_list) + + combined_state = defaultdict(dict) + combined_state['step'] = combined_step + combined_state['exp_avg'] = combined_exp_avg + combined_state['exp_avg_sq'] = combined_exp_avg_sq + combined_state['max_exp_avg_sq'] = combined_max_exp_avg_sq + combined_param_states.append(combined_state) + stash.combined_param_states_indexed_by_group[group_index] = combined_param_states + + def _combine_param_states_by_group(self): + stash = self._amp_stash + if stash.param_states_are_combined_by_group: + return + + stash.combined_param_states_indexed_by_group = [] + for _ in self.param_groups: + stash.combined_param_states_indexed_by_group.append([]) + + for i, _ in enumerate(self.param_groups): + self._combine_group_param_states(i) + stash.param_states_are_combined_by_group = True + + def _group_step(self, group_index): + group = self.param_groups[group_index] + for p in group['params']: + if p.grad is None: + continue + + grad = p.grad + if grad.is_sparse: + raise RuntimeError('NpuFusedAdamW does not support sparse gradients, ' + 'please consider SparseAdam instead') + state_p = self.state[p] + state_p['step'] += 1 + + amsgrad = group['amsgrad'] + beta1, beta2 = group['betas'] + + stash = self._amp_stash + combined_group_params = stash.combined_params_indexed_by_group[group_index] + combined_group_grads = stash.combined_grads_indexed_by_group[group_index] + combined_group_param_states = stash.combined_param_states_indexed_by_group[group_index] + + for combined_param, combined_grad, combined_param_state in zip(combined_group_params, + combined_group_grads, + combined_group_param_states): + if combined_param is None or combined_grad is None: + continue + + # Perform stepweight decay. The fused method is used here to speed up the calculation + combined_param.mul_(1 - group['lr'] * group['weight_decay']) + + exp_avg, exp_avg_sq = combined_param_state['exp_avg'], combined_param_state['exp_avg_sq'] + if amsgrad: + max_exp_avg_sq = combined_param_state['max_exp_avg_sq'] + + combined_param_state['step'] += 1 + bias_correction1 = 1 - beta1 ** combined_param_state['step'] + bias_correction2 = 1 - beta2 ** combined_param_state['step'] + + # Decay the first and second moment running average coefficient + exp_avg.mul_(beta1).add_(combined_grad, alpha=1 - beta1) + exp_avg_sq.mul_(beta2).addcmul_(combined_grad, combined_grad, value=1 - beta2) + if amsgrad: + # Maintains the maximum of all 2nd moment running avg. till now + torch.max(max_exp_avg_sq, exp_avg_sq, out=max_exp_avg_sq) + # Use the max. for normalizing running avg. of gradient + denom = (max_exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group['eps']) + else: + denom = (exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group['eps']) + + step_size = group['lr'] / bias_correction1 + + combined_param.addcdiv_(exp_avg, denom, value=-step_size) + + @torch.no_grad() + def step(self, closure=None): + if not hasattr(self, "_amp_stash"): + raise RuntimeError('apex.optimizers.NpuFusedAdamW should be used with AMP.') + + self._check_already_combined_params_and_grads() + # combine params and grads first + self._combine_params_and_grads_by_group() + # then combine param states + self._combine_param_states_by_group() + + loss = None + if closure is not None: + with torch.enable_grad(): + loss = closure() + + for i, _ in enumerate(self.param_groups): + self._group_step(i) + + return loss diff --git a/PyTorch/contrib/cv/classification/VOLO/README.md b/PyTorch/contrib/cv/classification/VOLO/README.md index c752a0a80415d147bea0949296044ec4dfb4f03f..1dfba0b42eb7c0ce64d903f900d29eb607b096c2 100644 --- a/PyTorch/contrib/cv/classification/VOLO/README.md +++ b/PyTorch/contrib/cv/classification/VOLO/README.md @@ -1,64 +1,64 @@ -# VOLO - -This implements training of volo_d1 on the ImageNet-2012 dataset and token labeling, mainly modified from [sail-sg/volo](https://github.com/sail-sg/volo). - -## VOLO Detail - -There is an error of Col2im operator on NPU, and make it compute with the CPU. - - Because lacking of Roi_align on NPU, the function is re-implemented . - -if there is an error about `OP:ROIAlign`, please modify `/usr/local/Ascend/ascend-toolkit/5.0.x/x-linux/opp/op_impl/built-in/ai_core/tbe/impl/roi_align.py:line 2287` - -``` -#ori -with tik_instance.for_range(0, pool_h) as p_h: - with tik_instance.for_range(0, pool_w, thread_num=2) as p_w: -#right -with tik_instance.for_range(0, pool_h) as p_h: - with tik_instance.for_range(0, pool_w, thread_num=min(2, pool_w)) as p_w: -``` - -## Requirements - -- Install PyTorch ([pytorch.org](http://pytorch.org)) -- `pip install -r requirements.txt` -- Download the Imagenet-2012 dataset. Refer to the original repository https://github.com/rwightman/pytorch-image-models -- Download the token label data, please refer to the [sail-sg/volo](https://github.com/sail-sg/volo). - - -## Training - -To train a model, run `main.py` with the desired model architecture and the path to the Imagenet-2012 dataset, and : - -```bash -Modify the data_dir path/to/imagenet and label path/to/label_top5_train_nfnet in the shell file. -# training 1p accuracy -bash test/train_full_1p.sh - -# training 1p performance -bash test/train_performance_1p.sh - -# training 8p accuracy -bash test/train_full_8p.sh - -# training 8p performance -bash test/train_performance_8p.sh - -# finetune -bash test/train_finetune_1p.sh - -# Online inference demo -python demo.py --checkpoint real_checkpoint_path -``` - -## Volo training result - - -| | top1 | AMP_Type | Epochs | FPS | -| :----: | :---: | :------: | :----: | :-----: | -| 1p-GPU | - | O2 | 1 | 152.37 | -| 1p-NPU | - | O2 | 1 | 23.26 | -| 8p-GPU | 82.83 | O2 | 100 | 1080.81 | -| 8p-NPU | 81.79 | O2 | 100 | 180.31 | - +# VOLO + +This implements training of volo_d1 on the ImageNet-2012 dataset and token labeling, mainly modified from [sail-sg/volo](https://github.com/sail-sg/volo). + +## VOLO Detail + +There is an error of Col2im operator on NPU, and make it compute with the CPU. + + Because lacking of Roi_align on NPU, the function is re-implemented . + +if there is an error about `OP:ROIAlign`, please modify `/usr/local/Ascend/ascend-toolkit/5.0.x/x-linux/opp/op_impl/built-in/ai_core/tbe/impl/roi_align.py:line 2287` + +``` +#ori +with tik_instance.for_range(0, pool_h) as p_h: + with tik_instance.for_range(0, pool_w, thread_num=2) as p_w: +#right +with tik_instance.for_range(0, pool_h) as p_h: + with tik_instance.for_range(0, pool_w, thread_num=min(2, pool_w)) as p_w: +``` + +## Requirements + +- Install PyTorch ([pytorch.org](http://pytorch.org)) +- `pip install -r requirements.txt` +- Download the Imagenet-2012 dataset. Refer to the original repository https://github.com/rwightman/pytorch-image-models +- Download the token label data, please refer to the [sail-sg/volo](https://github.com/sail-sg/volo). + + +## Training + +To train a model, run `main.py` with the desired model architecture and the path to the Imagenet-2012 dataset, and : + +```bash +Modify the data_dir path/to/imagenet and label path/to/label_top5_train_nfnet in the shell file. +# training 1p accuracy +bash test/train_full_1p.sh + +# training 1p performance +bash test/train_performance_1p.sh + +# training 8p accuracy +bash test/train_full_8p.sh + +# training 8p performance +bash test/train_performance_8p.sh + +# finetune +bash test/train_finetune_1p.sh + +# Online inference demo +python demo.py --checkpoint real_checkpoint_path +``` + +## Volo training result + + +| | top1 | AMP_Type | Epochs | FPS | +| :----: | :---: | :------: | :----: | :-----: | +| 1p-GPU | - | O2 | 1 | 152.37 | +| 1p-NPU | - | O2 | 1 | 23.26 | +| 8p-GPU | 82.83 | O2 | 100 | 1080.81 | +| 8p-NPU | 81.79 | O2 | 100 | 180.31 | + diff --git a/PyTorch/contrib/cv/classification/VOLO/demo.py b/PyTorch/contrib/cv/classification/VOLO/demo.py index 07041b9dfe6e7aa6945526366ab424363964dc0e..7175a52cb14886a9dbfa39447fd02940d81ca1e2 100644 --- a/PyTorch/contrib/cv/classification/VOLO/demo.py +++ b/PyTorch/contrib/cv/classification/VOLO/demo.py @@ -1,137 +1,137 @@ -""" -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the BSD 3-Clause License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://spdx.org/licenses/BSD-3-Clause.html - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" -import argparse -import torch -import torchvision -from torchvision import datasets, transforms -from collections import OrderedDict - -from timm.models import create_model -from timm.data.transforms import _pil_interp, RandomResizedCropAndInterpolation, ToNumpy, ToTensor - -DEFAULT_CROP_PCT = 0.875 - -parser = argparse.ArgumentParser(description='ImageNet Training') -parser.add_argument('--checkpoint', type=str, default='', - help='checkpoint path') -args = parser.parse_args() - -def proc_node_module(checkpoint, attr_name): - new_state_dict = OrderedDict() - for k, v in checkpoint[attr_name].items(): - if(k[0: 7] == "module."): - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - -def get_raw_data(): - from PIL import Image - from urllib.request import urlretrieve - IMAGE_URL = 'https://bbs-img.huaweicloud.com/blogs/img/thumb/1591951315139_8989_1363.png' - urlretrieve(IMAGE_URL, 'tmp.jpg') - img = Image.open("tmp.jpg") - img = img.convert('RGB') - return img - -def test(): - loc = 'npu:0' - loc_cpu = 'cpu' - torch.npu.set_device(loc) - if args.checkpoint == '': - print("please give the checkpoint path using --checkpoint param") - exit(0) - checkpoint = torch.load(args.checkpoint, map_location=loc) - checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') - - model = create_model( - 'volo_d1', - pretrained=False, - num_classes=None, - drop_rate=0.0, - drop_connect_rate=None, # DEPRECATED, use drop_path - drop_path_rate=0.0, - drop_block_rate=None, - global_pool=None, - bn_tf=False, - bn_momentum=None, - bn_eps=None, - scriptable=False, - checkpoint_path='', - img_size=224) - - model = model.to(loc) - model.load_state_dict(checkpoint['state_dict']) - model.eval() - - crop_pct = DEFAULT_CROP_PCT - img_size = 224 - scale_size = int(math.floor(img_size / crop_pct)) - interpolation = 'bilinear' - tfl = [ - transforms.Resize(scale_size, _pil_interp(interpolation)), - transforms.CenterCrop(img_size), - ] - tfl += [ToNumpy()] - data_transfrom = transforms.Compose(tfl) - - rd = get_raw_data() - - inputs = data_transfrom(rd) - inputs = inputs.unsqueeze(0) - inputs = inputs.to(loc) - output = model(inputs) - output = output.to(loc_cpu) - - _, pred = output.topk(1, 1, True, True) - result = torch.argmax(output, 1) - print("class: ", pred[0][0].item()) - print(result) - -if __name__ == "__main__": +""" +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the BSD 3-Clause License (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://spdx.org/licenses/BSD-3-Clause.html + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import argparse +import torch +import torchvision +from torchvision import datasets, transforms +from collections import OrderedDict + +from timm.models import create_model +from timm.data.transforms import _pil_interp, RandomResizedCropAndInterpolation, ToNumpy, ToTensor + +DEFAULT_CROP_PCT = 0.875 + +parser = argparse.ArgumentParser(description='ImageNet Training') +parser.add_argument('--checkpoint', type=str, default='', + help='checkpoint path') +args = parser.parse_args() + +def proc_node_module(checkpoint, attr_name): + new_state_dict = OrderedDict() + for k, v in checkpoint[attr_name].items(): + if(k[0: 7] == "module."): + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + +def get_raw_data(): + from PIL import Image + from urllib.request import urlretrieve + IMAGE_URL = 'https://bbs-img.huaweicloud.com/blogs/img/thumb/1591951315139_8989_1363.png' + urlretrieve(IMAGE_URL, 'tmp.jpg') + img = Image.open("tmp.jpg") + img = img.convert('RGB') + return img + +def test(): + loc = 'npu:0' + loc_cpu = 'cpu' + torch.npu.set_device(loc) + if args.checkpoint == '': + print("please give the checkpoint path using --checkpoint param") + exit(0) + checkpoint = torch.load(args.checkpoint, map_location=loc) + checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') + + model = create_model( + 'volo_d1', + pretrained=False, + num_classes=None, + drop_rate=0.0, + drop_connect_rate=None, # DEPRECATED, use drop_path + drop_path_rate=0.0, + drop_block_rate=None, + global_pool=None, + bn_tf=False, + bn_momentum=None, + bn_eps=None, + scriptable=False, + checkpoint_path='', + img_size=224) + + model = model.to(loc) + model.load_state_dict(checkpoint['state_dict']) + model.eval() + + crop_pct = DEFAULT_CROP_PCT + img_size = 224 + scale_size = int(math.floor(img_size / crop_pct)) + interpolation = 'bilinear' + tfl = [ + transforms.Resize(scale_size, _pil_interp(interpolation)), + transforms.CenterCrop(img_size), + ] + tfl += [ToNumpy()] + data_transfrom = transforms.Compose(tfl) + + rd = get_raw_data() + + inputs = data_transfrom(rd) + inputs = inputs.unsqueeze(0) + inputs = inputs.to(loc) + output = model(inputs) + output = output.to(loc_cpu) + + _, pred = output.topk(1, 1, True, True) + result = torch.argmax(output, 1) + print("class: ", pred[0][0].item()) + print(result) + +if __name__ == "__main__": test() \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/VOLO/loss/__init__.py b/PyTorch/contrib/cv/classification/VOLO/loss/__init__.py index 1eab72cf3aceed4c70528224ee52c7bec3cdadff..658c84ebfab5a3f436a69ec43701e8a0372be5ca 100644 --- a/PyTorch/contrib/cv/classification/VOLO/loss/__init__.py +++ b/PyTorch/contrib/cv/classification/VOLO/loss/__init__.py @@ -1,47 +1,47 @@ -""" -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the BSD 3-Clause License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://spdx.org/licenses/BSD-3-Clause.html - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" +""" +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the BSD 3-Clause License (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://spdx.org/licenses/BSD-3-Clause.html + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" from .cross_entropy import TokenLabelGTCrossEntropy, TokenLabelSoftTargetCrossEntropy, TokenLabelCrossEntropy \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/VOLO/models/__init__.py b/PyTorch/contrib/cv/classification/VOLO/models/__init__.py index fb1a0823dc0367759cb3f657d9fd48318517dbeb..658c948f3447a70ea47de99d5b5e04a283d57742 100644 --- a/PyTorch/contrib/cv/classification/VOLO/models/__init__.py +++ b/PyTorch/contrib/cv/classification/VOLO/models/__init__.py @@ -1,48 +1,48 @@ - -""" -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the BSD 3-Clause License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://spdx.org/licenses/BSD-3-Clause.html - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" + +""" +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the BSD 3-Clause License (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://spdx.org/licenses/BSD-3-Clause.html + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" from .volo import * \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/VOLO/prof_demo.sh b/PyTorch/contrib/cv/classification/VOLO/prof_demo.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/VOLO/test/train_full_8p.sh b/PyTorch/contrib/cv/classification/VOLO/test/train_full_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/VOLO/test/train_performance_8p.sh b/PyTorch/contrib/cv/classification/VOLO/test/train_performance_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/VOLO/timm/loss/asymmetric_loss.py b/PyTorch/contrib/cv/classification/VOLO/timm/loss/asymmetric_loss.py index d3a0d8650f81e0d79e6dc4321355f120ae0f4a3b..726f9410e43a3462675e9e92ce7cbb768be1a7ed 100644 --- a/PyTorch/contrib/cv/classification/VOLO/timm/loss/asymmetric_loss.py +++ b/PyTorch/contrib/cv/classification/VOLO/timm/loss/asymmetric_loss.py @@ -1,143 +1,143 @@ -""" -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the BSD 3-Clause License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://spdx.org/licenses/BSD-3-Clause.html - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" -import torch -import torch.nn as nn - - -class AsymmetricLossMultiLabel(nn.Module): - def __init__(self, gamma_neg=4, gamma_pos=1, clip=0.05, eps=1e-8, disable_torch_grad_focal_loss=False): - super(AsymmetricLossMultiLabel, self).__init__() - - self.gamma_neg = gamma_neg - self.gamma_pos = gamma_pos - self.clip = clip - self.disable_torch_grad_focal_loss = disable_torch_grad_focal_loss - self.eps = eps - - def forward(self, x, y): - """" - Parameters - ---------- - x: input logits - y: targets (multi-label binarized vector) - """ - - # Calculating Probabilities - x_sigmoid = torch.sigmoid(x) - xs_pos = x_sigmoid - xs_neg = 1 - x_sigmoid - - # Asymmetric Clipping - if self.clip is not None and self.clip > 0: - xs_neg = (xs_neg + self.clip).clamp(max=1) - - # Basic CE calculation - los_pos = y * torch.log(xs_pos.clamp(min=self.eps)) - los_neg = (1 - y) * torch.log(xs_neg.clamp(min=self.eps)) - loss = los_pos + los_neg - - # Asymmetric Focusing - if self.gamma_neg > 0 or self.gamma_pos > 0: - if self.disable_torch_grad_focal_loss: - torch._C.set_grad_enabled(False) - pt0 = xs_pos * y - pt1 = xs_neg * (1 - y) # pt = p if t > 0 else 1-p - pt = pt0 + pt1 - one_sided_gamma = self.gamma_pos * y + self.gamma_neg * (1 - y) - one_sided_w = torch.pow(1 - pt, one_sided_gamma) - if self.disable_torch_grad_focal_loss: - torch._C.set_grad_enabled(True) - loss *= one_sided_w - - return -loss.sum() - - -class AsymmetricLossSingleLabel(nn.Module): - def __init__(self, gamma_pos=1, gamma_neg=4, eps: float = 0.1, reduction='mean'): - super(AsymmetricLossSingleLabel, self).__init__() - - self.eps = eps - self.logsoftmax = nn.LogSoftmax(dim=-1) - self.targets_classes = [] # prevent gpu repeated memory allocation - self.gamma_pos = gamma_pos - self.gamma_neg = gamma_neg - self.reduction = reduction - - def forward(self, inputs, target, reduction=None): - """" - Parameters - ---------- - x: input logits - y: targets (1-hot vector) - """ - - num_classes = inputs.size()[-1] - log_preds = self.logsoftmax(inputs) - self.targets_classes = torch.zeros_like(inputs).scatter_(1, target.long().unsqueeze(1), 1) - - # ASL weights - targets = self.targets_classes - anti_targets = 1 - targets - xs_pos = torch.exp(log_preds) - xs_neg = 1 - xs_pos - xs_pos = xs_pos * targets - xs_neg = xs_neg * anti_targets - asymmetric_w = torch.pow(1 - xs_pos - xs_neg, - self.gamma_pos * targets + self.gamma_neg * anti_targets) - log_preds = log_preds * asymmetric_w - - if self.eps > 0: # label smoothing - self.targets_classes.mul_(1 - self.eps).add_(self.eps / num_classes) - - # loss calculation - loss = - self.targets_classes.mul(log_preds) - - loss = loss.sum(dim=-1) - if self.reduction == 'mean': - loss = loss.mean() - - return loss +""" +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the BSD 3-Clause License (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://spdx.org/licenses/BSD-3-Clause.html + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import torch +import torch.nn as nn + + +class AsymmetricLossMultiLabel(nn.Module): + def __init__(self, gamma_neg=4, gamma_pos=1, clip=0.05, eps=1e-8, disable_torch_grad_focal_loss=False): + super(AsymmetricLossMultiLabel, self).__init__() + + self.gamma_neg = gamma_neg + self.gamma_pos = gamma_pos + self.clip = clip + self.disable_torch_grad_focal_loss = disable_torch_grad_focal_loss + self.eps = eps + + def forward(self, x, y): + """" + Parameters + ---------- + x: input logits + y: targets (multi-label binarized vector) + """ + + # Calculating Probabilities + x_sigmoid = torch.sigmoid(x) + xs_pos = x_sigmoid + xs_neg = 1 - x_sigmoid + + # Asymmetric Clipping + if self.clip is not None and self.clip > 0: + xs_neg = (xs_neg + self.clip).clamp(max=1) + + # Basic CE calculation + los_pos = y * torch.log(xs_pos.clamp(min=self.eps)) + los_neg = (1 - y) * torch.log(xs_neg.clamp(min=self.eps)) + loss = los_pos + los_neg + + # Asymmetric Focusing + if self.gamma_neg > 0 or self.gamma_pos > 0: + if self.disable_torch_grad_focal_loss: + torch._C.set_grad_enabled(False) + pt0 = xs_pos * y + pt1 = xs_neg * (1 - y) # pt = p if t > 0 else 1-p + pt = pt0 + pt1 + one_sided_gamma = self.gamma_pos * y + self.gamma_neg * (1 - y) + one_sided_w = torch.pow(1 - pt, one_sided_gamma) + if self.disable_torch_grad_focal_loss: + torch._C.set_grad_enabled(True) + loss *= one_sided_w + + return -loss.sum() + + +class AsymmetricLossSingleLabel(nn.Module): + def __init__(self, gamma_pos=1, gamma_neg=4, eps: float = 0.1, reduction='mean'): + super(AsymmetricLossSingleLabel, self).__init__() + + self.eps = eps + self.logsoftmax = nn.LogSoftmax(dim=-1) + self.targets_classes = [] # prevent gpu repeated memory allocation + self.gamma_pos = gamma_pos + self.gamma_neg = gamma_neg + self.reduction = reduction + + def forward(self, inputs, target, reduction=None): + """" + Parameters + ---------- + x: input logits + y: targets (1-hot vector) + """ + + num_classes = inputs.size()[-1] + log_preds = self.logsoftmax(inputs) + self.targets_classes = torch.zeros_like(inputs).scatter_(1, target.long().unsqueeze(1), 1) + + # ASL weights + targets = self.targets_classes + anti_targets = 1 - targets + xs_pos = torch.exp(log_preds) + xs_neg = 1 - xs_pos + xs_pos = xs_pos * targets + xs_neg = xs_neg * anti_targets + asymmetric_w = torch.pow(1 - xs_pos - xs_neg, + self.gamma_pos * targets + self.gamma_neg * anti_targets) + log_preds = log_preds * asymmetric_w + + if self.eps > 0: # label smoothing + self.targets_classes.mul_(1 - self.eps).add_(self.eps / num_classes) + + # loss calculation + loss = - self.targets_classes.mul(log_preds) + + loss = loss.sum(dim=-1) + if self.reduction == 'mean': + loss = loss.mean() + + return loss diff --git a/PyTorch/contrib/cv/classification/VOLO/tlt/__init__.py b/PyTorch/contrib/cv/classification/VOLO/tlt/__init__.py index a53b3e9888443e3fa26623b6c3de76b7b139151b..39dd95c737d325e40f517425d9cca3ffc0ee96d6 100644 --- a/PyTorch/contrib/cv/classification/VOLO/tlt/__init__.py +++ b/PyTorch/contrib/cv/classification/VOLO/tlt/__init__.py @@ -1,47 +1,47 @@ -""" -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the BSD 3-Clause License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://spdx.org/licenses/BSD-3-Clause.html - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" +""" +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the BSD 3-Clause License (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://spdx.org/licenses/BSD-3-Clause.html + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" from .utils import load_pretrained_weights \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/VOLO/tlt/data/random_augment_label.py b/PyTorch/contrib/cv/classification/VOLO/tlt/data/random_augment_label.py index a6a95782e13a32b75485215b72716c0105872e63..005494f1609acb9eb14a935125e59755771312a9 100644 --- a/PyTorch/contrib/cv/classification/VOLO/tlt/data/random_augment_label.py +++ b/PyTorch/contrib/cv/classification/VOLO/tlt/data/random_augment_label.py @@ -1,606 +1,606 @@ -""" -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the BSD 3-Clause License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://spdx.org/licenses/BSD-3-Clause.html - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" -""" -Adapted from https://github.com/rwightman/pytorch-image-models/blob/master/timm/data/auto_augment.py and modified for token labeling -AutoAugment, RandAugment -""" -import random -import math -import re -from PIL import Image, ImageOps, ImageEnhance, ImageChops -import PIL -import numpy as np -from scipy import ndimage -import torch - -_PIL_VER = tuple([int(x) for x in PIL.__version__.split('.')[:2]]) - -_FILL = (128, 128, 128) - - - -# This signifies the max integer that the controller RNN could predict for the -# augmentation scheme. -_MAX_LEVEL = 10. - -_HPARAMS_DEFAULT = dict( - translate_const=250, - img_mean=_FILL, -) - -_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC) - - -def _interpolation(kwargs): - interpolation = kwargs.pop('resample', Image.BILINEAR) - if isinstance(interpolation, (list, tuple)): - return random.choice(interpolation) - else: - return interpolation - -def affine_label(label, matrix): - - # label: 2, k, H, W - # label[0] value, label[1] index - a,b,c,d,e,f = matrix - affine_matrix = [[1,0,0,0],[0,a,b,c],[0,d,e,f]] - value = ndimage.affine_transform(label[0],matrix=affine_matrix, order=0, mode="constant") - index = ndimage.affine_transform(label[1],matrix=affine_matrix, order=0, mode="nearest") - - return torch.from_numpy(np.stack([value, index],axis=0)) - -def _check_args_tf(kwargs): - if 'fillcolor' in kwargs and _PIL_VER < (5, 0): - kwargs.pop('fillcolor') - kwargs['resample'] = _interpolation(kwargs) - - -def shear_x(img, factor, **kwargs): - _check_args_tf(kwargs) - return img.transform(img.size, Image.AFFINE, (1, factor, 0, 0, 1, 0), **kwargs) - -def shear_y_label(label, factor): - return affine_label(label, (1, factor, 0, 0, 1, 0)) - - -def shear_y(img, factor, **kwargs): - _check_args_tf(kwargs) - return img.transform(img.size, Image.AFFINE, (1, 0, 0, factor, 1, 0), **kwargs) - -def shear_x_label(label, factor): - return affine_label(label, (1, 0, 0, factor, 1, 0)) - -def translate_x_rel(img, pct, **kwargs): - pixels = pct * img.size[0] - _check_args_tf(kwargs) - return img.transform(img.size, Image.AFFINE, (1, 0, pixels, 0, 1, 0), **kwargs) - -def translate_y_rel_label(label, pct): - pixels = pct * label.size(2) - return affine_label(label, (1, 0, pixels, 0, 1, 0)) - - -def translate_y_rel(img, pct, **kwargs): - pixels = pct * img.size[1] - _check_args_tf(kwargs) - return img.transform(img.size, Image.AFFINE, (1, 0, 0, 0, 1, pixels), **kwargs) - -def translate_x_rel_label(label, pct): - pixels = pct * label.size(3) - return affine_label(label, (1, 0, 0, 0, 1, pixels)) - - -def translate_x_abs(img, pixels, **kwargs): - _check_args_tf(kwargs) - return img.transform(img.size, Image.AFFINE, (1, 0, pixels, 0, 1, 0), **kwargs) - - -def translate_y_abs(img, pixels, **kwargs): - _check_args_tf(kwargs) - return img.transform(img.size, Image.AFFINE, (1, 0, 0, 0, 1, pixels), **kwargs) - - -def rotate(img, degrees, **kwargs): - _check_args_tf(kwargs) - if _PIL_VER >= (5, 2): - return img.rotate(degrees, **kwargs) - elif _PIL_VER >= (5, 0): - w, h = img.size - post_trans = (0, 0) - rotn_center = (w / 2.0, h / 2.0) - angle = -math.radians(degrees) - matrix = [ - round(math.cos(angle), 15), - round(math.sin(angle), 15), - 0.0, - round(-math.sin(angle), 15), - round(math.cos(angle), 15), - 0.0, - ] - - def transform(x, y, matrix): - (a, b, c, d, e, f) = matrix - return a * x + b * y + c, d * x + e * y + f - - matrix[2], matrix[5] = transform( - -rotn_center[0] - post_trans[0], -rotn_center[1] - post_trans[1], matrix - ) - matrix[2] += rotn_center[0] - matrix[5] += rotn_center[1] - return img.transform(img.size, Image.AFFINE, matrix, **kwargs) - else: - return img.rotate(degrees, resample=kwargs['resample']) - -def rotate_label(label, degrees): - _,_, w, h = label.size() - post_trans = (0, 0) - rotn_center = (w / 2.0, h / 2.0) - angle = math.radians(degrees) - matrix = [ - round(math.cos(angle), 15), - round(math.sin(angle), 15), - 0.0, - round(-math.sin(angle), 15), - round(math.cos(angle), 15), - 0.0, - ] - - def transform(x, y, matrix): - (a, b, c, d, e, f) = matrix - return a * x + b * y + c, d * x + e * y + f - - matrix[2], matrix[5] = transform( - -rotn_center[0] - post_trans[0], -rotn_center[1] - post_trans[1], matrix - ) - matrix[2] += rotn_center[0] - matrix[5] += rotn_center[1] - return affine_label(label, matrix) - - -def auto_contrast(img, **__): - return ImageOps.autocontrast(img) - - -def invert(img, **__): - return ImageOps.invert(img) - - -def equalize(img, **__): - return ImageOps.equalize(img) - - -def solarize(img, thresh, **__): - return ImageOps.solarize(img, thresh) - - -def solarize_add(img, add, thresh=128, **__): - lut = [] - for i in range(256): - if i < thresh: - lut.append(min(255, i + add)) - else: - lut.append(i) - if img.mode in ("L", "RGB"): - if img.mode == "RGB" and len(lut) == 256: - lut = lut + lut + lut - return img.point(lut) - else: - return img - - -def posterize(img, bits_to_keep, **__): - if bits_to_keep >= 8: - return img - return ImageOps.posterize(img, bits_to_keep) - - -def contrast(img, factor, **__): - return ImageEnhance.Contrast(img).enhance(factor) - - -def color(img, factor, **__): - return ImageEnhance.Color(img).enhance(factor) - - -def brightness(img, factor, **__): - return ImageEnhance.Brightness(img).enhance(factor) - - -def sharpness(img, factor, **__): - return ImageEnhance.Sharpness(img).enhance(factor) - - -def _randomly_negate(v): - """With 50% prob, negate the value""" - return -v if random.random() > 0.5 else v - - -def _rotate_level_to_arg(level, _hparams): - # range [-30, 30] - level = (level / _MAX_LEVEL) * 30. - level = _randomly_negate(level) - return level, - - -def _enhance_level_to_arg(level, _hparams): - # range [0.1, 1.9] - return (level / _MAX_LEVEL) * 1.8 + 0.1, - - -def _enhance_increasing_level_to_arg(level, _hparams): - # the 'no change' level is 1.0, moving away from that towards 0. or 2.0 increases the enhancement blend - # range [0.1, 1.9] - level = (level / _MAX_LEVEL) * .9 - level = 1.0 + _randomly_negate(level) - return level, - - -def _shear_level_to_arg(level, _hparams): - # range [-0.3, 0.3] - level = (level / _MAX_LEVEL) * 0.3 - level = _randomly_negate(level) - return level, - - -def _translate_abs_level_to_arg(level, hparams): - translate_const = hparams['translate_const'] - level = (level / _MAX_LEVEL) * float(translate_const) - level = _randomly_negate(level) - return level, - - -def _translate_rel_level_to_arg(level, hparams): - # default range [-0.45, 0.45] - translate_pct = hparams.get('translate_pct', 0.45) - level = (level / _MAX_LEVEL) * translate_pct - level = _randomly_negate(level) - return level, - - -def _posterize_level_to_arg(level, _hparams): - # As per Tensorflow TPU EfficientNet impl - # range [0, 4], 'keep 0 up to 4 MSB of original image' - # intensity/severity of augmentation decreases with level - return int((level / _MAX_LEVEL) * 4), - - -def _posterize_increasing_level_to_arg(level, hparams): - # As per Tensorflow models research and UDA impl - # range [4, 0], 'keep 4 down to 0 MSB of original image', - # intensity/severity of augmentation increases with level - return 4 - _posterize_level_to_arg(level, hparams)[0], - - -def _posterize_original_level_to_arg(level, _hparams): - # As per original AutoAugment paper description - # range [4, 8], 'keep 4 up to 8 MSB of image' - # intensity/severity of augmentation decreases with level - return int((level / _MAX_LEVEL) * 4) + 4, - - -def _solarize_level_to_arg(level, _hparams): - # range [0, 256] - # intensity/severity of augmentation decreases with level - return int((level / _MAX_LEVEL) * 256), - - -def _solarize_increasing_level_to_arg(level, _hparams): - # range [0, 256] - # intensity/severity of augmentation increases with level - return 256 - _solarize_level_to_arg(level, _hparams)[0], - - -def _solarize_add_level_to_arg(level, _hparams): - # range [0, 110] - return int((level / _MAX_LEVEL) * 110), - -class AugmentOp: - - def __init__(self, name, prob=0.5, magnitude=10, hparams=None): - hparams = hparams or _HPARAMS_DEFAULT - self.name = name - self.aug_fn = NAME_TO_OP[name] - self.label_fn = NAME_TO_LABELOP[name] - self.level_fn = LEVEL_TO_ARG[name] - self.prob = prob - self.magnitude = magnitude - self.hparams = hparams.copy() - self.kwargs = dict( - fillcolor=hparams['img_mean'] if 'img_mean' in hparams else _FILL, - resample=hparams['interpolation'] if 'interpolation' in hparams else _RANDOM_INTERPOLATION, - ) - - # If magnitude_std is > 0, we introduce some randomness - # in the usually fixed policy and sample magnitude from a normal distribution - # with mean `magnitude` and std-dev of `magnitude_std`. - # NOTE This is my own hack, being tested, not in papers or reference impls. - self.magnitude_std = self.hparams.get('magnitude_std', 0) - - def __call__(self, img, label): - if self.prob < 1.0 and random.random() > self.prob: - return img, label - magnitude = self.magnitude - if self.magnitude_std and self.magnitude_std > 0: - magnitude = random.gauss(magnitude, self.magnitude_std) - magnitude = min(_MAX_LEVEL, max(0, magnitude)) # clip to valid range - level_args = self.level_fn(magnitude, self.hparams) if self.level_fn is not None else tuple() - if self.label_fn is not None: - - aug_label = self.label_fn(label, *level_args) - else: - aug_label = label - return self.aug_fn(img, *level_args, **self.kwargs), aug_label - -LEVEL_TO_ARG = { - 'AutoContrast': None, - 'Equalize': None, - 'Invert': None, - 'Rotate': _rotate_level_to_arg, - # There are several variations of the posterize level scaling in various Tensorflow/Google repositories/papers - 'Posterize': _posterize_level_to_arg, - 'PosterizeIncreasing': _posterize_increasing_level_to_arg, - 'PosterizeOriginal': _posterize_original_level_to_arg, - 'Solarize': _solarize_level_to_arg, - 'SolarizeIncreasing': _solarize_increasing_level_to_arg, - 'SolarizeAdd': _solarize_add_level_to_arg, - 'Color': _enhance_level_to_arg, - 'ColorIncreasing': _enhance_increasing_level_to_arg, - 'Contrast': _enhance_level_to_arg, - 'ContrastIncreasing': _enhance_increasing_level_to_arg, - 'Brightness': _enhance_level_to_arg, - 'BrightnessIncreasing': _enhance_increasing_level_to_arg, - 'Sharpness': _enhance_level_to_arg, - 'SharpnessIncreasing': _enhance_increasing_level_to_arg, - 'ShearX': _shear_level_to_arg, - 'ShearY': _shear_level_to_arg, - 'TranslateX': _translate_abs_level_to_arg, - 'TranslateY': _translate_abs_level_to_arg, - 'TranslateXRel': _translate_rel_level_to_arg, - 'TranslateYRel': _translate_rel_level_to_arg, -} - - -NAME_TO_OP = { - 'AutoContrast': auto_contrast, - 'Equalize': equalize, - 'Invert': invert, - 'Rotate': rotate, - 'Posterize': posterize, - 'PosterizeIncreasing': posterize, - 'PosterizeOriginal': posterize, - 'Solarize': solarize, - 'SolarizeIncreasing': solarize, - 'SolarizeAdd': solarize_add, - 'Color': color, - 'ColorIncreasing': color, - 'Contrast': contrast, - 'ContrastIncreasing': contrast, - 'Brightness': brightness, - 'BrightnessIncreasing': brightness, - 'Sharpness': sharpness, - 'SharpnessIncreasing': sharpness, - 'ShearX': shear_x, - 'ShearY': shear_y, - 'TranslateX': translate_x_abs, - 'TranslateY': translate_y_abs, - 'TranslateXRel': translate_x_rel, - 'TranslateYRel': translate_y_rel, -} -# Remove TranslateX and TranslateY here since it is actually not used in random aug -# Only spatial op should be applied to the label map -NAME_TO_LABELOP = { - 'AutoContrast': None, - 'Equalize': None, - 'Invert': None, - 'Rotate': rotate_label, - 'Posterize': None, - 'PosterizeIncreasing': None, - 'PosterizeOriginal': None, - 'Solarize': None, - 'SolarizeIncreasing': None, - 'SolarizeAdd': None, - 'Color': None, - 'ColorIncreasing': None, - 'Contrast': None, - 'ContrastIncreasing': None, - 'Brightness': None, - 'BrightnessIncreasing': None, - 'Sharpness': None, - 'SharpnessIncreasing': None, - 'ShearX': shear_x_label, - 'ShearY': shear_y_label, - 'TranslateX': None, - 'TranslateY': None, - 'TranslateXRel': translate_x_rel_label, - 'TranslateYRel': translate_y_rel_label, -} - - -_RAND_TRANSFORMS = [ - 'AutoContrast', - 'Equalize', - 'Invert', - 'Rotate', - 'Posterize', - 'Solarize', - 'SolarizeAdd', - 'Color', - 'Contrast', - 'Brightness', - 'Sharpness', - 'ShearX', - 'ShearY', - 'TranslateXRel', - 'TranslateYRel', - #'Cutout' -] - - -_RAND_INCREASING_TRANSFORMS = [ - 'AutoContrast', - 'Equalize', - 'Invert', - 'Rotate', - 'PosterizeIncreasing', - 'SolarizeIncreasing', - 'SolarizeAdd', - 'ColorIncreasing', - 'ContrastIncreasing', - 'BrightnessIncreasing', - 'SharpnessIncreasing', - 'ShearX', - 'ShearY', - 'TranslateXRel', - 'TranslateYRel', - #'Cutout' -] - - - -# These experimental weights are based loosely on the relative improvements mentioned in paper. -# They may not result in increased performance, but could likely be tuned to so. -_RAND_CHOICE_WEIGHTS_0 = { - 'Rotate': 0.3, - 'ShearX': 0.2, - 'ShearY': 0.2, - 'TranslateXRel': 0.1, - 'TranslateYRel': 0.1, - 'Color': .025, - 'Sharpness': 0.025, - 'AutoContrast': 0.025, - 'Solarize': .005, - 'SolarizeAdd': .005, - 'Contrast': .005, - 'Brightness': .005, - 'Equalize': .005, - 'Posterize': 0, - 'Invert': 0, -} - - -def _select_rand_weights(weight_idx=0, transforms=None): - transforms = transforms or _RAND_TRANSFORMS - assert weight_idx == 0 # only one set of weights currently - rand_weights = _RAND_CHOICE_WEIGHTS_0 - probs = [rand_weights[k] for k in transforms] - probs /= np.sum(probs) - return probs - - -def rand_augment_ops(magnitude=10, hparams=None, transforms=None): - hparams = hparams or _HPARAMS_DEFAULT - transforms = transforms or _RAND_TRANSFORMS - return [AugmentOp( - name, prob=0.5, magnitude=magnitude, hparams=hparams) for name in transforms] - - -class RandAugment: - ''' - Apply RandAug on both image and dense label map - ''' - def __init__(self, ops, num_layers=2, choice_weights=None): - self.ops = ops - self.num_layers = num_layers - self.choice_weights = choice_weights - - def __call__(self, img, label): - # no replacement when using weighted choice - ops = np.random.choice( - self.ops, self.num_layers, replace=self.choice_weights is None, p=self.choice_weights) - for op in ops: - img, label = op(img, label) - return img, label - - -def rand_augment_transform(config_str, hparams): - """ - Create a RandAugment transform with label - :param config_str: String defining configuration of random augmentation. Consists of multiple sections separated by - dashes ('-'). The first section defines the specific variant of rand augment (currently only 'rand'). The remaining - sections, not order sepecific determine - 'm' - integer magnitude of rand augment - 'n' - integer num layers (number of transform ops selected per image) - 'w' - integer probabiliy weight index (index of a set of weights to influence choice of op) - 'mstd' - float std deviation of magnitude noise applied - 'inc' - integer (bool), use augmentations that increase in severity with magnitude (default: 0) - Ex 'rand-m9-n3-mstd0.5' results in RandAugment with magnitude 9, num_layers 3, magnitude_std 0.5 - 'rand-mstd1-w0' results in magnitude_std 1.0, weights 0, default magnitude of 10 and num_layers 2 - - :param hparams: Other hparams (kwargs) for the RandAugmentation scheme - - :return: A PyTorch compatible Transform - """ - magnitude = _MAX_LEVEL # default to _MAX_LEVEL for magnitude (currently 10) - num_layers = 2 # default to 2 ops per image - weight_idx = None # default to no probability weights for op choice - transforms = _RAND_TRANSFORMS - config = config_str.split('-') - assert config[0] == 'rand' - config = config[1:] - for c in config: - cs = re.split(r'(\d.*)', c) - if len(cs) < 2: - continue - key, val = cs[:2] - if key == 'mstd': - # noise param injected via hparams for now - hparams.setdefault('magnitude_std', float(val)) - elif key == 'inc': - if bool(val): - transforms = _RAND_INCREASING_TRANSFORMS - elif key == 'm': - magnitude = int(val) - elif key == 'n': - num_layers = int(val) - elif key == 'w': - weight_idx = int(val) - else: - assert False, 'Unknown RandAugment config section' - ra_ops = rand_augment_ops(magnitude=magnitude, hparams=hparams, transforms=transforms) - choice_weights = None if weight_idx is None else _select_rand_weights(weight_idx) - return RandAugment(ra_ops, num_layers, choice_weights=choice_weights) - +""" +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the BSD 3-Clause License (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://spdx.org/licenses/BSD-3-Clause.html + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +""" +Adapted from https://github.com/rwightman/pytorch-image-models/blob/master/timm/data/auto_augment.py and modified for token labeling +AutoAugment, RandAugment +""" +import random +import math +import re +from PIL import Image, ImageOps, ImageEnhance, ImageChops +import PIL +import numpy as np +from scipy import ndimage +import torch + +_PIL_VER = tuple([int(x) for x in PIL.__version__.split('.')[:2]]) + +_FILL = (128, 128, 128) + + + +# This signifies the max integer that the controller RNN could predict for the +# augmentation scheme. +_MAX_LEVEL = 10. + +_HPARAMS_DEFAULT = dict( + translate_const=250, + img_mean=_FILL, +) + +_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC) + + +def _interpolation(kwargs): + interpolation = kwargs.pop('resample', Image.BILINEAR) + if isinstance(interpolation, (list, tuple)): + return random.choice(interpolation) + else: + return interpolation + +def affine_label(label, matrix): + + # label: 2, k, H, W + # label[0] value, label[1] index + a,b,c,d,e,f = matrix + affine_matrix = [[1,0,0,0],[0,a,b,c],[0,d,e,f]] + value = ndimage.affine_transform(label[0],matrix=affine_matrix, order=0, mode="constant") + index = ndimage.affine_transform(label[1],matrix=affine_matrix, order=0, mode="nearest") + + return torch.from_numpy(np.stack([value, index],axis=0)) + +def _check_args_tf(kwargs): + if 'fillcolor' in kwargs and _PIL_VER < (5, 0): + kwargs.pop('fillcolor') + kwargs['resample'] = _interpolation(kwargs) + + +def shear_x(img, factor, **kwargs): + _check_args_tf(kwargs) + return img.transform(img.size, Image.AFFINE, (1, factor, 0, 0, 1, 0), **kwargs) + +def shear_y_label(label, factor): + return affine_label(label, (1, factor, 0, 0, 1, 0)) + + +def shear_y(img, factor, **kwargs): + _check_args_tf(kwargs) + return img.transform(img.size, Image.AFFINE, (1, 0, 0, factor, 1, 0), **kwargs) + +def shear_x_label(label, factor): + return affine_label(label, (1, 0, 0, factor, 1, 0)) + +def translate_x_rel(img, pct, **kwargs): + pixels = pct * img.size[0] + _check_args_tf(kwargs) + return img.transform(img.size, Image.AFFINE, (1, 0, pixels, 0, 1, 0), **kwargs) + +def translate_y_rel_label(label, pct): + pixels = pct * label.size(2) + return affine_label(label, (1, 0, pixels, 0, 1, 0)) + + +def translate_y_rel(img, pct, **kwargs): + pixels = pct * img.size[1] + _check_args_tf(kwargs) + return img.transform(img.size, Image.AFFINE, (1, 0, 0, 0, 1, pixels), **kwargs) + +def translate_x_rel_label(label, pct): + pixels = pct * label.size(3) + return affine_label(label, (1, 0, 0, 0, 1, pixels)) + + +def translate_x_abs(img, pixels, **kwargs): + _check_args_tf(kwargs) + return img.transform(img.size, Image.AFFINE, (1, 0, pixels, 0, 1, 0), **kwargs) + + +def translate_y_abs(img, pixels, **kwargs): + _check_args_tf(kwargs) + return img.transform(img.size, Image.AFFINE, (1, 0, 0, 0, 1, pixels), **kwargs) + + +def rotate(img, degrees, **kwargs): + _check_args_tf(kwargs) + if _PIL_VER >= (5, 2): + return img.rotate(degrees, **kwargs) + elif _PIL_VER >= (5, 0): + w, h = img.size + post_trans = (0, 0) + rotn_center = (w / 2.0, h / 2.0) + angle = -math.radians(degrees) + matrix = [ + round(math.cos(angle), 15), + round(math.sin(angle), 15), + 0.0, + round(-math.sin(angle), 15), + round(math.cos(angle), 15), + 0.0, + ] + + def transform(x, y, matrix): + (a, b, c, d, e, f) = matrix + return a * x + b * y + c, d * x + e * y + f + + matrix[2], matrix[5] = transform( + -rotn_center[0] - post_trans[0], -rotn_center[1] - post_trans[1], matrix + ) + matrix[2] += rotn_center[0] + matrix[5] += rotn_center[1] + return img.transform(img.size, Image.AFFINE, matrix, **kwargs) + else: + return img.rotate(degrees, resample=kwargs['resample']) + +def rotate_label(label, degrees): + _,_, w, h = label.size() + post_trans = (0, 0) + rotn_center = (w / 2.0, h / 2.0) + angle = math.radians(degrees) + matrix = [ + round(math.cos(angle), 15), + round(math.sin(angle), 15), + 0.0, + round(-math.sin(angle), 15), + round(math.cos(angle), 15), + 0.0, + ] + + def transform(x, y, matrix): + (a, b, c, d, e, f) = matrix + return a * x + b * y + c, d * x + e * y + f + + matrix[2], matrix[5] = transform( + -rotn_center[0] - post_trans[0], -rotn_center[1] - post_trans[1], matrix + ) + matrix[2] += rotn_center[0] + matrix[5] += rotn_center[1] + return affine_label(label, matrix) + + +def auto_contrast(img, **__): + return ImageOps.autocontrast(img) + + +def invert(img, **__): + return ImageOps.invert(img) + + +def equalize(img, **__): + return ImageOps.equalize(img) + + +def solarize(img, thresh, **__): + return ImageOps.solarize(img, thresh) + + +def solarize_add(img, add, thresh=128, **__): + lut = [] + for i in range(256): + if i < thresh: + lut.append(min(255, i + add)) + else: + lut.append(i) + if img.mode in ("L", "RGB"): + if img.mode == "RGB" and len(lut) == 256: + lut = lut + lut + lut + return img.point(lut) + else: + return img + + +def posterize(img, bits_to_keep, **__): + if bits_to_keep >= 8: + return img + return ImageOps.posterize(img, bits_to_keep) + + +def contrast(img, factor, **__): + return ImageEnhance.Contrast(img).enhance(factor) + + +def color(img, factor, **__): + return ImageEnhance.Color(img).enhance(factor) + + +def brightness(img, factor, **__): + return ImageEnhance.Brightness(img).enhance(factor) + + +def sharpness(img, factor, **__): + return ImageEnhance.Sharpness(img).enhance(factor) + + +def _randomly_negate(v): + """With 50% prob, negate the value""" + return -v if random.random() > 0.5 else v + + +def _rotate_level_to_arg(level, _hparams): + # range [-30, 30] + level = (level / _MAX_LEVEL) * 30. + level = _randomly_negate(level) + return level, + + +def _enhance_level_to_arg(level, _hparams): + # range [0.1, 1.9] + return (level / _MAX_LEVEL) * 1.8 + 0.1, + + +def _enhance_increasing_level_to_arg(level, _hparams): + # the 'no change' level is 1.0, moving away from that towards 0. or 2.0 increases the enhancement blend + # range [0.1, 1.9] + level = (level / _MAX_LEVEL) * .9 + level = 1.0 + _randomly_negate(level) + return level, + + +def _shear_level_to_arg(level, _hparams): + # range [-0.3, 0.3] + level = (level / _MAX_LEVEL) * 0.3 + level = _randomly_negate(level) + return level, + + +def _translate_abs_level_to_arg(level, hparams): + translate_const = hparams['translate_const'] + level = (level / _MAX_LEVEL) * float(translate_const) + level = _randomly_negate(level) + return level, + + +def _translate_rel_level_to_arg(level, hparams): + # default range [-0.45, 0.45] + translate_pct = hparams.get('translate_pct', 0.45) + level = (level / _MAX_LEVEL) * translate_pct + level = _randomly_negate(level) + return level, + + +def _posterize_level_to_arg(level, _hparams): + # As per Tensorflow TPU EfficientNet impl + # range [0, 4], 'keep 0 up to 4 MSB of original image' + # intensity/severity of augmentation decreases with level + return int((level / _MAX_LEVEL) * 4), + + +def _posterize_increasing_level_to_arg(level, hparams): + # As per Tensorflow models research and UDA impl + # range [4, 0], 'keep 4 down to 0 MSB of original image', + # intensity/severity of augmentation increases with level + return 4 - _posterize_level_to_arg(level, hparams)[0], + + +def _posterize_original_level_to_arg(level, _hparams): + # As per original AutoAugment paper description + # range [4, 8], 'keep 4 up to 8 MSB of image' + # intensity/severity of augmentation decreases with level + return int((level / _MAX_LEVEL) * 4) + 4, + + +def _solarize_level_to_arg(level, _hparams): + # range [0, 256] + # intensity/severity of augmentation decreases with level + return int((level / _MAX_LEVEL) * 256), + + +def _solarize_increasing_level_to_arg(level, _hparams): + # range [0, 256] + # intensity/severity of augmentation increases with level + return 256 - _solarize_level_to_arg(level, _hparams)[0], + + +def _solarize_add_level_to_arg(level, _hparams): + # range [0, 110] + return int((level / _MAX_LEVEL) * 110), + +class AugmentOp: + + def __init__(self, name, prob=0.5, magnitude=10, hparams=None): + hparams = hparams or _HPARAMS_DEFAULT + self.name = name + self.aug_fn = NAME_TO_OP[name] + self.label_fn = NAME_TO_LABELOP[name] + self.level_fn = LEVEL_TO_ARG[name] + self.prob = prob + self.magnitude = magnitude + self.hparams = hparams.copy() + self.kwargs = dict( + fillcolor=hparams['img_mean'] if 'img_mean' in hparams else _FILL, + resample=hparams['interpolation'] if 'interpolation' in hparams else _RANDOM_INTERPOLATION, + ) + + # If magnitude_std is > 0, we introduce some randomness + # in the usually fixed policy and sample magnitude from a normal distribution + # with mean `magnitude` and std-dev of `magnitude_std`. + # NOTE This is my own hack, being tested, not in papers or reference impls. + self.magnitude_std = self.hparams.get('magnitude_std', 0) + + def __call__(self, img, label): + if self.prob < 1.0 and random.random() > self.prob: + return img, label + magnitude = self.magnitude + if self.magnitude_std and self.magnitude_std > 0: + magnitude = random.gauss(magnitude, self.magnitude_std) + magnitude = min(_MAX_LEVEL, max(0, magnitude)) # clip to valid range + level_args = self.level_fn(magnitude, self.hparams) if self.level_fn is not None else tuple() + if self.label_fn is not None: + + aug_label = self.label_fn(label, *level_args) + else: + aug_label = label + return self.aug_fn(img, *level_args, **self.kwargs), aug_label + +LEVEL_TO_ARG = { + 'AutoContrast': None, + 'Equalize': None, + 'Invert': None, + 'Rotate': _rotate_level_to_arg, + # There are several variations of the posterize level scaling in various Tensorflow/Google repositories/papers + 'Posterize': _posterize_level_to_arg, + 'PosterizeIncreasing': _posterize_increasing_level_to_arg, + 'PosterizeOriginal': _posterize_original_level_to_arg, + 'Solarize': _solarize_level_to_arg, + 'SolarizeIncreasing': _solarize_increasing_level_to_arg, + 'SolarizeAdd': _solarize_add_level_to_arg, + 'Color': _enhance_level_to_arg, + 'ColorIncreasing': _enhance_increasing_level_to_arg, + 'Contrast': _enhance_level_to_arg, + 'ContrastIncreasing': _enhance_increasing_level_to_arg, + 'Brightness': _enhance_level_to_arg, + 'BrightnessIncreasing': _enhance_increasing_level_to_arg, + 'Sharpness': _enhance_level_to_arg, + 'SharpnessIncreasing': _enhance_increasing_level_to_arg, + 'ShearX': _shear_level_to_arg, + 'ShearY': _shear_level_to_arg, + 'TranslateX': _translate_abs_level_to_arg, + 'TranslateY': _translate_abs_level_to_arg, + 'TranslateXRel': _translate_rel_level_to_arg, + 'TranslateYRel': _translate_rel_level_to_arg, +} + + +NAME_TO_OP = { + 'AutoContrast': auto_contrast, + 'Equalize': equalize, + 'Invert': invert, + 'Rotate': rotate, + 'Posterize': posterize, + 'PosterizeIncreasing': posterize, + 'PosterizeOriginal': posterize, + 'Solarize': solarize, + 'SolarizeIncreasing': solarize, + 'SolarizeAdd': solarize_add, + 'Color': color, + 'ColorIncreasing': color, + 'Contrast': contrast, + 'ContrastIncreasing': contrast, + 'Brightness': brightness, + 'BrightnessIncreasing': brightness, + 'Sharpness': sharpness, + 'SharpnessIncreasing': sharpness, + 'ShearX': shear_x, + 'ShearY': shear_y, + 'TranslateX': translate_x_abs, + 'TranslateY': translate_y_abs, + 'TranslateXRel': translate_x_rel, + 'TranslateYRel': translate_y_rel, +} +# Remove TranslateX and TranslateY here since it is actually not used in random aug +# Only spatial op should be applied to the label map +NAME_TO_LABELOP = { + 'AutoContrast': None, + 'Equalize': None, + 'Invert': None, + 'Rotate': rotate_label, + 'Posterize': None, + 'PosterizeIncreasing': None, + 'PosterizeOriginal': None, + 'Solarize': None, + 'SolarizeIncreasing': None, + 'SolarizeAdd': None, + 'Color': None, + 'ColorIncreasing': None, + 'Contrast': None, + 'ContrastIncreasing': None, + 'Brightness': None, + 'BrightnessIncreasing': None, + 'Sharpness': None, + 'SharpnessIncreasing': None, + 'ShearX': shear_x_label, + 'ShearY': shear_y_label, + 'TranslateX': None, + 'TranslateY': None, + 'TranslateXRel': translate_x_rel_label, + 'TranslateYRel': translate_y_rel_label, +} + + +_RAND_TRANSFORMS = [ + 'AutoContrast', + 'Equalize', + 'Invert', + 'Rotate', + 'Posterize', + 'Solarize', + 'SolarizeAdd', + 'Color', + 'Contrast', + 'Brightness', + 'Sharpness', + 'ShearX', + 'ShearY', + 'TranslateXRel', + 'TranslateYRel', + #'Cutout' +] + + +_RAND_INCREASING_TRANSFORMS = [ + 'AutoContrast', + 'Equalize', + 'Invert', + 'Rotate', + 'PosterizeIncreasing', + 'SolarizeIncreasing', + 'SolarizeAdd', + 'ColorIncreasing', + 'ContrastIncreasing', + 'BrightnessIncreasing', + 'SharpnessIncreasing', + 'ShearX', + 'ShearY', + 'TranslateXRel', + 'TranslateYRel', + #'Cutout' +] + + + +# These experimental weights are based loosely on the relative improvements mentioned in paper. +# They may not result in increased performance, but could likely be tuned to so. +_RAND_CHOICE_WEIGHTS_0 = { + 'Rotate': 0.3, + 'ShearX': 0.2, + 'ShearY': 0.2, + 'TranslateXRel': 0.1, + 'TranslateYRel': 0.1, + 'Color': .025, + 'Sharpness': 0.025, + 'AutoContrast': 0.025, + 'Solarize': .005, + 'SolarizeAdd': .005, + 'Contrast': .005, + 'Brightness': .005, + 'Equalize': .005, + 'Posterize': 0, + 'Invert': 0, +} + + +def _select_rand_weights(weight_idx=0, transforms=None): + transforms = transforms or _RAND_TRANSFORMS + assert weight_idx == 0 # only one set of weights currently + rand_weights = _RAND_CHOICE_WEIGHTS_0 + probs = [rand_weights[k] for k in transforms] + probs /= np.sum(probs) + return probs + + +def rand_augment_ops(magnitude=10, hparams=None, transforms=None): + hparams = hparams or _HPARAMS_DEFAULT + transforms = transforms or _RAND_TRANSFORMS + return [AugmentOp( + name, prob=0.5, magnitude=magnitude, hparams=hparams) for name in transforms] + + +class RandAugment: + ''' + Apply RandAug on both image and dense label map + ''' + def __init__(self, ops, num_layers=2, choice_weights=None): + self.ops = ops + self.num_layers = num_layers + self.choice_weights = choice_weights + + def __call__(self, img, label): + # no replacement when using weighted choice + ops = np.random.choice( + self.ops, self.num_layers, replace=self.choice_weights is None, p=self.choice_weights) + for op in ops: + img, label = op(img, label) + return img, label + + +def rand_augment_transform(config_str, hparams): + """ + Create a RandAugment transform with label + :param config_str: String defining configuration of random augmentation. Consists of multiple sections separated by + dashes ('-'). The first section defines the specific variant of rand augment (currently only 'rand'). The remaining + sections, not order sepecific determine + 'm' - integer magnitude of rand augment + 'n' - integer num layers (number of transform ops selected per image) + 'w' - integer probabiliy weight index (index of a set of weights to influence choice of op) + 'mstd' - float std deviation of magnitude noise applied + 'inc' - integer (bool), use augmentations that increase in severity with magnitude (default: 0) + Ex 'rand-m9-n3-mstd0.5' results in RandAugment with magnitude 9, num_layers 3, magnitude_std 0.5 + 'rand-mstd1-w0' results in magnitude_std 1.0, weights 0, default magnitude of 10 and num_layers 2 + + :param hparams: Other hparams (kwargs) for the RandAugmentation scheme + + :return: A PyTorch compatible Transform + """ + magnitude = _MAX_LEVEL # default to _MAX_LEVEL for magnitude (currently 10) + num_layers = 2 # default to 2 ops per image + weight_idx = None # default to no probability weights for op choice + transforms = _RAND_TRANSFORMS + config = config_str.split('-') + assert config[0] == 'rand' + config = config[1:] + for c in config: + cs = re.split(r'(\d.*)', c) + if len(cs) < 2: + continue + key, val = cs[:2] + if key == 'mstd': + # noise param injected via hparams for now + hparams.setdefault('magnitude_std', float(val)) + elif key == 'inc': + if bool(val): + transforms = _RAND_INCREASING_TRANSFORMS + elif key == 'm': + magnitude = int(val) + elif key == 'n': + num_layers = int(val) + elif key == 'w': + weight_idx = int(val) + else: + assert False, 'Unknown RandAugment config section' + ra_ops = rand_augment_ops(magnitude=magnitude, hparams=hparams, transforms=transforms) + choice_weights = None if weight_idx is None else _select_rand_weights(weight_idx) + return RandAugment(ra_ops, num_layers, choice_weights=choice_weights) + diff --git a/PyTorch/contrib/cv/classification/VOLO/tlt/loss/__init__.py b/PyTorch/contrib/cv/classification/VOLO/tlt/loss/__init__.py index 47166af5c809572250d0a7d76e2a8605b90c6540..e1019595216dc26960fcbae2e3c6154a075eda43 100644 --- a/PyTorch/contrib/cv/classification/VOLO/tlt/loss/__init__.py +++ b/PyTorch/contrib/cv/classification/VOLO/tlt/loss/__init__.py @@ -1,47 +1,47 @@ -""" -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the BSD 3-Clause License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://spdx.org/licenses/BSD-3-Clause.html - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" +""" +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the BSD 3-Clause License (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://spdx.org/licenses/BSD-3-Clause.html + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" from .cross_entropy import TokenLabelCrossEntropy,TokenLabelSoftTargetCrossEntropy \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/VOLO/tlt/utils/__init__.py b/PyTorch/contrib/cv/classification/VOLO/tlt/utils/__init__.py index a53b3e9888443e3fa26623b6c3de76b7b139151b..39dd95c737d325e40f517425d9cca3ffc0ee96d6 100644 --- a/PyTorch/contrib/cv/classification/VOLO/tlt/utils/__init__.py +++ b/PyTorch/contrib/cv/classification/VOLO/tlt/utils/__init__.py @@ -1,47 +1,47 @@ -""" -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the BSD 3-Clause License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://spdx.org/licenses/BSD-3-Clause.html - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" +""" +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the BSD 3-Clause License (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://spdx.org/licenses/BSD-3-Clause.html + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" from .utils import load_pretrained_weights \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/VOLO/utils/__init__.py b/PyTorch/contrib/cv/classification/VOLO/utils/__init__.py index a53b3e9888443e3fa26623b6c3de76b7b139151b..39dd95c737d325e40f517425d9cca3ffc0ee96d6 100644 --- a/PyTorch/contrib/cv/classification/VOLO/utils/__init__.py +++ b/PyTorch/contrib/cv/classification/VOLO/utils/__init__.py @@ -1,47 +1,47 @@ -""" -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the BSD 3-Clause License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://spdx.org/licenses/BSD-3-Clause.html - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" +""" +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the BSD 3-Clause License (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://spdx.org/licenses/BSD-3-Clause.html + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" from .utils import load_pretrained_weights \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/Vgg16_ID1630_for_PyTorch/modelzoo_level.txt b/PyTorch/contrib/cv/classification/Vgg16_ID1630_for_PyTorch/modelzoo_level.txt index 5afcef9188bf9d39f1e34b45bd91324c6093137a..3117fffc3be7f5c479f10f09ba38a25c47739a00 100644 --- a/PyTorch/contrib/cv/classification/Vgg16_ID1630_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/Vgg16_ID1630_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/Vgg19_ID1631_for_PyTorch/modelzoo_level.txt b/PyTorch/contrib/cv/classification/Vgg19_ID1631_for_PyTorch/modelzoo_level.txt index 5afcef9188bf9d39f1e34b45bd91324c6093137a..3117fffc3be7f5c479f10f09ba38a25c47739a00 100644 --- a/PyTorch/contrib/cv/classification/Vgg19_ID1631_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/Vgg19_ID1631_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/README.md b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/README.md index 57d445ce4f69ffbe6eddeb7336e7eae0a8ac5d81..f2705c491b57bcb719d4d6381bdd7d9db6679c80 100644 --- a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/README.md +++ b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/README.md @@ -1,55 +1,55 @@ -# Vit_small_patch16_224 - -This implements training of vit_small_patch16_224 on the ImageNet-2012 dataset, mainly modified from [rwightman/pytorch-image-models](https://github.com/rwightman/pytorch-image-models). - -## Vit_small_patch16_224 Detail - -As of the current date, Ascend-Pytorch is still inefficient for contiguous operations.Therefore, vit_small_patch16_224 is re-implemented using semantics such as custom OP. - - -## Requirements - -- Install PyTorch ([pytorch.org](http://pytorch.org)) - -- `pip install -r requirements.txt` - -- Download the Imagenet-2012 dataset. Refer to the original repository https://github.com/rwightman/pytorch-image-models - - -## Training - -To train a model, run `train.py` with the desired model architecture and the path to the Imagenet-2012 dataset: - -```bash -# training 1p accuracy -bash test/train_full_1p.sh --data_path=real_data_path - -# training 1p performance -bash test/train_performance_1p.sh --data_path=real_data_path - -# training 8p accuracy -bash test/train_full_8p.sh --data_path=real_data_path - -# training 8p performance -bash test/train_performance_8p.sh --data_path=real_data_path - -# finetune -bash test/train_finetune_1p.sh --data_path=real_data_path --weight=real_weight_path - -# Online inference demo -python demo.py --checkpoint real_checkpoint_path - -# To ONNX -python pthtar2onnx.py -``` - -## Vit_small_patch16_224 training result - - -| | top1 | AMP_Type | Epochs | FPS | -| :----: | :---: | :------: | :----: | :-----: | -| 1p-GPU | - | O2 | 1 | 586.67 | -| 1p-NPU | - | O2 | 1 | 304.06 | -| 8p-GPU | 67.65 | O2 | 100 | 4556.28 | -| 8p-NPU | 67.67 | O2 | 100 | 2373.80 | - +# Vit_small_patch16_224 + +This implements training of vit_small_patch16_224 on the ImageNet-2012 dataset, mainly modified from [rwightman/pytorch-image-models](https://github.com/rwightman/pytorch-image-models). + +## Vit_small_patch16_224 Detail + +As of the current date, Ascend-Pytorch is still inefficient for contiguous operations.Therefore, vit_small_patch16_224 is re-implemented using semantics such as custom OP. + + +## Requirements + +- Install PyTorch ([pytorch.org](http://pytorch.org)) + +- `pip install -r requirements.txt` + +- Download the Imagenet-2012 dataset. Refer to the original repository https://github.com/rwightman/pytorch-image-models + + +## Training + +To train a model, run `train.py` with the desired model architecture and the path to the Imagenet-2012 dataset: + +```bash +# training 1p accuracy +bash test/train_full_1p.sh --data_path=real_data_path + +# training 1p performance +bash test/train_performance_1p.sh --data_path=real_data_path + +# training 8p accuracy +bash test/train_full_8p.sh --data_path=real_data_path + +# training 8p performance +bash test/train_performance_8p.sh --data_path=real_data_path + +# finetune +bash test/train_finetune_1p.sh --data_path=real_data_path --weight=real_weight_path + +# Online inference demo +python demo.py --checkpoint real_checkpoint_path + +# To ONNX +python pthtar2onnx.py +``` + +## Vit_small_patch16_224 training result + + +| | top1 | AMP_Type | Epochs | FPS | +| :----: | :---: | :------: | :----: | :-----: | +| 1p-GPU | - | O2 | 1 | 586.67 | +| 1p-NPU | - | O2 | 1 | 304.06 | +| 8p-GPU | 67.65 | O2 | 100 | 4556.28 | +| 8p-NPU | 67.67 | O2 | 100 | 2373.80 | + diff --git a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/demo.py b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/demo.py index fcad4e7d2ad11596dac9955bcc46f7eb8da7df3e..87fd6c849b7af4f31bf60c31cfa507129e032fb7 100644 --- a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/demo.py +++ b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/demo.py @@ -1,85 +1,85 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import argparse -import torch -import torchvision -from torchvision import datasets, transforms -from collections import OrderedDict - -from timm.models import create_model - -parser = argparse.ArgumentParser(description='ImageNet Training') -parser.add_argument('--checkpoint', type=str, default='', - help='checkpoint path') -args = parser.parse_args() - -def proc_node_module(checkpoint, attr_name): - new_state_dict = OrderedDict() - for k, v in checkpoint[attr_name].items(): - if(k[0: 7] == "module."): - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - -def get_raw_data(): - from PIL import Image - from urllib.request import urlretrieve - IMAGE_URL = 'https://bbs-img.huaweicloud.com/blogs/img/thumb/1591951315139_8989_1363.png' - urlretrieve(IMAGE_URL, 'tmp.jpg') - img = Image.open("tmp.jpg") - img = img.convert('RGB') - return img - -def test(): - loc = 'npu:0' - loc_cpu = 'cpu' - torch.npu.set_device(loc) - if args.checkpoint == '': - print("please give the checkpoint path using --checkpoint param") - exit(0) - checkpoint = torch.load(args.checkpoint, map_location=loc) - checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') - - model = create_model('vit_small_patch16_224', pretrained=False) - - model = model.to(loc) - model.load_state_dict(checkpoint['state_dict']) - model.eval() - - normalize = transforms.Normalize(mean=[0.5, 0.5, 0.5], - std=[0.5, 0.5, 0.5]) - rd = get_raw_data() - data_transfrom = transforms.Compose([ - transforms.RandomResizedCrop(224,interpolation=3), - transforms.RandomHorizontalFlip(), - transforms.ToTensor(), - normalize, - ]) - - inputs = data_transfrom(rd) - inputs = inputs.unsqueeze(0) - inputs = inputs.to(loc) - output = model(inputs) - output = output.to(loc_cpu) - - _, pred = output.topk(1, 1, True, True) - result = torch.argmax(output, 1) - print("class: ", pred[0][0].item()) - print(result) - -if __name__ == "__main__": +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import argparse +import torch +import torchvision +from torchvision import datasets, transforms +from collections import OrderedDict + +from timm.models import create_model + +parser = argparse.ArgumentParser(description='ImageNet Training') +parser.add_argument('--checkpoint', type=str, default='', + help='checkpoint path') +args = parser.parse_args() + +def proc_node_module(checkpoint, attr_name): + new_state_dict = OrderedDict() + for k, v in checkpoint[attr_name].items(): + if(k[0: 7] == "module."): + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + +def get_raw_data(): + from PIL import Image + from urllib.request import urlretrieve + IMAGE_URL = 'https://bbs-img.huaweicloud.com/blogs/img/thumb/1591951315139_8989_1363.png' + urlretrieve(IMAGE_URL, 'tmp.jpg') + img = Image.open("tmp.jpg") + img = img.convert('RGB') + return img + +def test(): + loc = 'npu:0' + loc_cpu = 'cpu' + torch.npu.set_device(loc) + if args.checkpoint == '': + print("please give the checkpoint path using --checkpoint param") + exit(0) + checkpoint = torch.load(args.checkpoint, map_location=loc) + checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') + + model = create_model('vit_small_patch16_224', pretrained=False) + + model = model.to(loc) + model.load_state_dict(checkpoint['state_dict']) + model.eval() + + normalize = transforms.Normalize(mean=[0.5, 0.5, 0.5], + std=[0.5, 0.5, 0.5]) + rd = get_raw_data() + data_transfrom = transforms.Compose([ + transforms.RandomResizedCrop(224,interpolation=3), + transforms.RandomHorizontalFlip(), + transforms.ToTensor(), + normalize, + ]) + + inputs = data_transfrom(rd) + inputs = inputs.unsqueeze(0) + inputs = inputs.to(loc) + output = model(inputs) + output = output.to(loc_cpu) + + _, pred = output.topk(1, 1, True, True) + result = torch.argmax(output, 1) + print("class: ", pred[0][0].item()) + print(result) + +if __name__ == "__main__": test() \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/distributed_train.sh b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/distributed_train.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/distributed_train_npu.sh b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/distributed_train_npu.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/pthtar2onnx.py b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/pthtar2onnx.py index d55c4c20c5d82404c50fc22b67773b9551f3e27d..ad98950f302d57c7c6a5b6a0a8e641ab9d3c65d6 100644 --- a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/pthtar2onnx.py +++ b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/pthtar2onnx.py @@ -1,62 +1,62 @@ -""" -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the BSD 3-Clause License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://spdx.org/licenses/BSD-3-Clause.html - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import torch -import timm - -def pth2onnx(model, output_file): - model.eval() - input_names = ["image"] - output_names = ["class"] - dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} - dummy_input = torch.randn(1, 3, 224, 224) - torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, opset_version=11, verbose=True) - print("save to %s" % output_file) - -if __name__ == "__main__": - model = timm.create_model('vit_small_patch16_224', pretrained=False) - pth2onnx(model, "vit_small_patch16_224.onnx") +""" +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the BSD 3-Clause License (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://spdx.org/licenses/BSD-3-Clause.html + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import torch +import timm + +def pth2onnx(model, output_file): + model.eval() + input_names = ["image"] + output_names = ["class"] + dynamic_axes = {'image': {0: '-1'}, 'class': {0: '-1'}} + dummy_input = torch.randn(1, 3, 224, 224) + torch.onnx.export(model, dummy_input, output_file, input_names = input_names, dynamic_axes = dynamic_axes, output_names = output_names, opset_version=11, verbose=True) + print("save to %s" % output_file) + +if __name__ == "__main__": + model = timm.create_model('vit_small_patch16_224', pretrained=False) + pth2onnx(model, "vit_small_patch16_224.onnx") diff --git a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/timm/loss/asymmetric_loss.py b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/timm/loss/asymmetric_loss.py index d3a0d8650f81e0d79e6dc4321355f120ae0f4a3b..726f9410e43a3462675e9e92ce7cbb768be1a7ed 100644 --- a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/timm/loss/asymmetric_loss.py +++ b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/timm/loss/asymmetric_loss.py @@ -1,143 +1,143 @@ -""" -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the BSD 3-Clause License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://spdx.org/licenses/BSD-3-Clause.html - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" -import torch -import torch.nn as nn - - -class AsymmetricLossMultiLabel(nn.Module): - def __init__(self, gamma_neg=4, gamma_pos=1, clip=0.05, eps=1e-8, disable_torch_grad_focal_loss=False): - super(AsymmetricLossMultiLabel, self).__init__() - - self.gamma_neg = gamma_neg - self.gamma_pos = gamma_pos - self.clip = clip - self.disable_torch_grad_focal_loss = disable_torch_grad_focal_loss - self.eps = eps - - def forward(self, x, y): - """" - Parameters - ---------- - x: input logits - y: targets (multi-label binarized vector) - """ - - # Calculating Probabilities - x_sigmoid = torch.sigmoid(x) - xs_pos = x_sigmoid - xs_neg = 1 - x_sigmoid - - # Asymmetric Clipping - if self.clip is not None and self.clip > 0: - xs_neg = (xs_neg + self.clip).clamp(max=1) - - # Basic CE calculation - los_pos = y * torch.log(xs_pos.clamp(min=self.eps)) - los_neg = (1 - y) * torch.log(xs_neg.clamp(min=self.eps)) - loss = los_pos + los_neg - - # Asymmetric Focusing - if self.gamma_neg > 0 or self.gamma_pos > 0: - if self.disable_torch_grad_focal_loss: - torch._C.set_grad_enabled(False) - pt0 = xs_pos * y - pt1 = xs_neg * (1 - y) # pt = p if t > 0 else 1-p - pt = pt0 + pt1 - one_sided_gamma = self.gamma_pos * y + self.gamma_neg * (1 - y) - one_sided_w = torch.pow(1 - pt, one_sided_gamma) - if self.disable_torch_grad_focal_loss: - torch._C.set_grad_enabled(True) - loss *= one_sided_w - - return -loss.sum() - - -class AsymmetricLossSingleLabel(nn.Module): - def __init__(self, gamma_pos=1, gamma_neg=4, eps: float = 0.1, reduction='mean'): - super(AsymmetricLossSingleLabel, self).__init__() - - self.eps = eps - self.logsoftmax = nn.LogSoftmax(dim=-1) - self.targets_classes = [] # prevent gpu repeated memory allocation - self.gamma_pos = gamma_pos - self.gamma_neg = gamma_neg - self.reduction = reduction - - def forward(self, inputs, target, reduction=None): - """" - Parameters - ---------- - x: input logits - y: targets (1-hot vector) - """ - - num_classes = inputs.size()[-1] - log_preds = self.logsoftmax(inputs) - self.targets_classes = torch.zeros_like(inputs).scatter_(1, target.long().unsqueeze(1), 1) - - # ASL weights - targets = self.targets_classes - anti_targets = 1 - targets - xs_pos = torch.exp(log_preds) - xs_neg = 1 - xs_pos - xs_pos = xs_pos * targets - xs_neg = xs_neg * anti_targets - asymmetric_w = torch.pow(1 - xs_pos - xs_neg, - self.gamma_pos * targets + self.gamma_neg * anti_targets) - log_preds = log_preds * asymmetric_w - - if self.eps > 0: # label smoothing - self.targets_classes.mul_(1 - self.eps).add_(self.eps / num_classes) - - # loss calculation - loss = - self.targets_classes.mul(log_preds) - - loss = loss.sum(dim=-1) - if self.reduction == 'mean': - loss = loss.mean() - - return loss +""" +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the BSD 3-Clause License (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://spdx.org/licenses/BSD-3-Clause.html + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import torch +import torch.nn as nn + + +class AsymmetricLossMultiLabel(nn.Module): + def __init__(self, gamma_neg=4, gamma_pos=1, clip=0.05, eps=1e-8, disable_torch_grad_focal_loss=False): + super(AsymmetricLossMultiLabel, self).__init__() + + self.gamma_neg = gamma_neg + self.gamma_pos = gamma_pos + self.clip = clip + self.disable_torch_grad_focal_loss = disable_torch_grad_focal_loss + self.eps = eps + + def forward(self, x, y): + """" + Parameters + ---------- + x: input logits + y: targets (multi-label binarized vector) + """ + + # Calculating Probabilities + x_sigmoid = torch.sigmoid(x) + xs_pos = x_sigmoid + xs_neg = 1 - x_sigmoid + + # Asymmetric Clipping + if self.clip is not None and self.clip > 0: + xs_neg = (xs_neg + self.clip).clamp(max=1) + + # Basic CE calculation + los_pos = y * torch.log(xs_pos.clamp(min=self.eps)) + los_neg = (1 - y) * torch.log(xs_neg.clamp(min=self.eps)) + loss = los_pos + los_neg + + # Asymmetric Focusing + if self.gamma_neg > 0 or self.gamma_pos > 0: + if self.disable_torch_grad_focal_loss: + torch._C.set_grad_enabled(False) + pt0 = xs_pos * y + pt1 = xs_neg * (1 - y) # pt = p if t > 0 else 1-p + pt = pt0 + pt1 + one_sided_gamma = self.gamma_pos * y + self.gamma_neg * (1 - y) + one_sided_w = torch.pow(1 - pt, one_sided_gamma) + if self.disable_torch_grad_focal_loss: + torch._C.set_grad_enabled(True) + loss *= one_sided_w + + return -loss.sum() + + +class AsymmetricLossSingleLabel(nn.Module): + def __init__(self, gamma_pos=1, gamma_neg=4, eps: float = 0.1, reduction='mean'): + super(AsymmetricLossSingleLabel, self).__init__() + + self.eps = eps + self.logsoftmax = nn.LogSoftmax(dim=-1) + self.targets_classes = [] # prevent gpu repeated memory allocation + self.gamma_pos = gamma_pos + self.gamma_neg = gamma_neg + self.reduction = reduction + + def forward(self, inputs, target, reduction=None): + """" + Parameters + ---------- + x: input logits + y: targets (1-hot vector) + """ + + num_classes = inputs.size()[-1] + log_preds = self.logsoftmax(inputs) + self.targets_classes = torch.zeros_like(inputs).scatter_(1, target.long().unsqueeze(1), 1) + + # ASL weights + targets = self.targets_classes + anti_targets = 1 - targets + xs_pos = torch.exp(log_preds) + xs_neg = 1 - xs_pos + xs_pos = xs_pos * targets + xs_neg = xs_neg * anti_targets + asymmetric_w = torch.pow(1 - xs_pos - xs_neg, + self.gamma_pos * targets + self.gamma_neg * anti_targets) + log_preds = log_preds * asymmetric_w + + if self.eps > 0: # label smoothing + self.targets_classes.mul_(1 - self.eps).add_(self.eps / num_classes) + + # loss calculation + loss = - self.targets_classes.mul(log_preds) + + loss = loss.sum(dim=-1) + if self.reduction == 'mean': + loss = loss.mean() + + return loss diff --git a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/timm/optim/npu_fused_adamp.py b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/timm/optim/npu_fused_adamp.py index fc0bca28aac9ddacc2437bbbbbae7f8a0ee5e772..7f6a8f0c2fe96fd7aff72e5a473068cfa3f2bd40 100644 --- a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/timm/optim/npu_fused_adamp.py +++ b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/timm/optim/npu_fused_adamp.py @@ -1,298 +1,298 @@ -""" -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the BSD 3-Clause License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://spdx.org/licenses/BSD-3-Clause.html - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import math -from collections import defaultdict - -import torch -from torch.optim.optimizer import Optimizer -from apex.contrib.combine_tensors import combine_npu - - -class NpuFusedAdamP(Optimizer): - """Implements AdamP algorithm. - - Currently NPU-only. Requires Apex to be installed via - ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--npu_float_status" ./``. - - This version of NPU fused AdamP implements 1 fusions. - - * A combine-tensor apply launch that batches the elementwise updates applied to all the model's parameters - into one or a few kernel launches. - - :class:`apex.optimizers.NpuFusedAdamP` may be used as a drop-in replacement for ``torch.optim.AdamP``:: - - opt = apex.optimizers.NpuFusedAdamP(model.parameters(), lr = ....) - ... - opt.step() - - :class:`apex.optimizers.FusedAdam` should be used with Amp. Currently, if you wish to use :class:`NpuFusedAdamP` - with Amp, only ``opt_level O1 and O2`` can be choosed:: - - opt = apex.optimizers.NpuFusedAdamP(model.parameters(), lr = ....) - model, opt = amp.initialize(model, opt, opt_level="O2") - ... - opt.step() - - - The original Adam algorithm was proposed in `Adam: A Method for Stochastic Optimization`_. - The AdamP variant was proposed in `Decoupled Weight Decay Regularization`_. - - Arguments: - params (iterable): iterable of parameters to optimize or dicts defining - parameter groups - lr (float, optional, default: 1e-3): learning rate - betas (Tuple[float, float], optional, default: (0.9, 0.999)): coefficients used - for computing running averages of gradient and its square - eps (float, optional, default: 1e-8): term added to the denominator to improve - numerical stability - weight_decay (float, optional, default: 1e-2): weight decay coefficient - amsgrad (boolean, optional, default: False): whether to use the AMSGrad variant of - this algorithm from the paper `On the Convergence of Adam and Beyond`_ - - .. _Adam\: A Method for Stochastic Optimization: - https://arxiv.org/abs/1412.6980 - .. _Decoupled Weight Decay Regularization: - https://arxiv.org/abs/1711.05101 - .. _On the Convergence of Adam and Beyond: - https://openreview.net/forum?id=ryQu7f-RZ - """ - - def __init__(self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, - weight_decay=0, delta=0.1, wd_ratio=0.1, nesterov=False): - defaults = dict(lr=lr, betas=betas, eps=eps, weight_decay=weight_decay, - delta=delta, wd_ratio=wd_ratio, nesterov=nesterov) - self.is_npu_fused_optimizer = True - super(NpuFusedAdamP, self).__init__(params, defaults) - - def __setstate__(self, state): - super(NpuFusedAdamP, self).__setstate__(state) - for group in self.param_groups: - group.setdefault('nesterov', False) - - def _channel_view(self, x): - return x.view(x.size(0), -1) - - def _layer_view(self, x): - return x.view(1, -1) - - def _cosine_similarity(self, x, y, eps, view_func): - x = view_func(x) - y = view_func(y) - - x_norm = x.norm(dim=1).add_(eps) - y_norm = y.norm(dim=1).add_(eps) - dot = (x * y).sum(dim=1) - - return dot.abs() / x_norm / y_norm - - def _projection(self, p, grad, perturb, delta, wd_ratio, eps): - wd = 1 - expand_size = [-1] + [1] * (len(p.shape) - 1) - for view_func in [self._channel_view, self._layer_view]: - - cosine_sim = self._cosine_similarity(grad, p, eps, view_func) - - if cosine_sim.max() < delta / math.sqrt(view_func(p).size(1)): - p_n = p / view_func(p).norm(dim=1).view(expand_size).add_(eps) - perturb -= p_n * view_func(p_n * perturb).sum(dim=1).view(expand_size) - wd = wd_ratio - - return perturb, wd - - return perturb, wd - - def _init_param_state(self, p): - state = self.state[p] - # State initialization - if len(state) == 0: - state['step'] = 0 - # Exponential moving average of gradient values - state['exp_avg'] = torch.zeros_like(p, memory_format=torch.preserve_format) - # Exponential moving average of squared gradient values - state['exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format) - else: - exp_avg_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) - exp_avg_tmp.copy_(state['exp_avg']) - state['exp_avg'] = exp_avg_tmp - - exp_avg_sq_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) - exp_avg_sq_tmp.copy_(state['exp_avg_sq']) - state['exp_avg_sq'] = exp_avg_sq_tmp - - def _combine_group_param_states(self, group_index): - group = self.param_groups[group_index] - stash = self._amp_stash - group_params_list = stash.params_lists_indexed_by_group[group_index] - - combined_param_states = [] - for params in group_params_list: - step_list = [] - exp_avg_list = [] - exp_avg_sq_list = [] - max_exp_avg_sq_list = [] - - for p in params: - if p.grad is None: - continue - grad = p.grad - if grad.is_sparse: - raise RuntimeError('NpuFusedAdamP does not support sparse gradients, ' - 'please consider SparseAdam instead') - - self._init_param_state(p) - state = self.state[p] - step_list.append(state['step']) - exp_avg_list.append(state['exp_avg']) - exp_avg_sq_list.append(state['exp_avg_sq']) - - combined_step = 0 - combined_exp_avg = None - combined_exp_avg_sq = None - combined_max_exp_avg_sq = None - - if len(exp_avg_list) > 0: - combined_step = step_list[0] - combined_exp_avg = combine_npu(exp_avg_list) - combined_exp_avg_sq = combine_npu(exp_avg_sq_list) - combined_max_exp_avg_sq = combine_npu(max_exp_avg_sq_list) - - combined_state = defaultdict(dict) - combined_state['step'] = combined_step - combined_state['exp_avg'] = combined_exp_avg - combined_state['exp_avg_sq'] = combined_exp_avg_sq - combined_state['max_exp_avg_sq'] = combined_max_exp_avg_sq - combined_param_states.append(combined_state) - stash.combined_param_states_indexed_by_group[group_index] = combined_param_states - - def _combine_param_states_by_group(self): - stash = self._amp_stash - if stash.param_states_are_combined_by_group: - return - - stash.combined_param_states_indexed_by_group = [] - for _ in self.param_groups: - stash.combined_param_states_indexed_by_group.append([]) - - for i, _ in enumerate(self.param_groups): - self._combine_group_param_states(i) - stash.param_states_are_combined_by_group = True - - def _group_step(self, group_index): - group = self.param_groups[group_index] - for p in group['params']: - if p.grad is None: - continue - - grad = p.grad.data - state = self.state[p] - state['step'] += 1 - - - beta1, beta2 = group['betas'] - nesterov = group['nesterov'] - - stash = self._amp_stash - combined_group_params = stash.combined_params_indexed_by_group[group_index] - combined_group_grads = stash.combined_grads_indexed_by_group[group_index] - combined_group_param_states = stash.combined_param_states_indexed_by_group[group_index] - - for combined_param, combined_grad, combined_param_state in zip(combined_group_params, - combined_group_grads, - combined_group_param_states): - if combined_param is None or combined_grad is None: - continue - - exp_avg, exp_avg_sq = combined_param_state['exp_avg'], combined_param_state['exp_avg_sq'] - - combined_param_state['step'] += 1 - bias_correction1 = 1 - beta1 ** combined_param_state['step'] - bias_correction2 = 1 - beta2 ** combined_param_state['step'] - - # Decay the first and second moment running average coefficient - exp_avg.mul_(beta1).add_(combined_grad, alpha=1 - beta1) - exp_avg_sq.mul_(beta2).addcmul_(combined_grad, combined_grad, value=1 - beta2) - denom = (exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group['eps']) - step_size = group['lr'] / bias_correction1 - - if nesterov: - perturb = (beta1 * exp_avg + (1 - beta1) * combined_grad) / denom - else: - perturb = exp_avg / denom - - # Projection - wd_ratio = 1 - if len(combined_param.shape) > 1: - perturb, wd_ratio = self._projection(combined_param, combined_grad, perturb, group['delta'], group['wd_ratio'], group['eps']) - - # Weight decay - if group['weight_decay'] > 0: - combined_param.mul_(1 - group['lr'] * group['weight_decay'] * wd_ratio) - - # Step - combined_param.add_(-step_size, perturb) - - @torch.no_grad() - def step(self, closure=None): - if not hasattr(self, "_amp_stash"): - raise RuntimeError('apex.optimizers.NpuFusedAdamP should be used with AMP.') - - self._check_already_combined_params_and_grads() - # combine params and grads first - self._combine_params_and_grads_by_group() - # then combine param states - self._combine_param_states_by_group() - - loss = None - if closure is not None: - with torch.enable_grad(): - loss = closure() - - for i, _ in enumerate(self.param_groups): - self._group_step(i) - - return loss +""" +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the BSD 3-Clause License (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://spdx.org/licenses/BSD-3-Clause.html + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import math +from collections import defaultdict + +import torch +from torch.optim.optimizer import Optimizer +from apex.contrib.combine_tensors import combine_npu + + +class NpuFusedAdamP(Optimizer): + """Implements AdamP algorithm. + + Currently NPU-only. Requires Apex to be installed via + ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--npu_float_status" ./``. + + This version of NPU fused AdamP implements 1 fusions. + + * A combine-tensor apply launch that batches the elementwise updates applied to all the model's parameters + into one or a few kernel launches. + + :class:`apex.optimizers.NpuFusedAdamP` may be used as a drop-in replacement for ``torch.optim.AdamP``:: + + opt = apex.optimizers.NpuFusedAdamP(model.parameters(), lr = ....) + ... + opt.step() + + :class:`apex.optimizers.FusedAdam` should be used with Amp. Currently, if you wish to use :class:`NpuFusedAdamP` + with Amp, only ``opt_level O1 and O2`` can be choosed:: + + opt = apex.optimizers.NpuFusedAdamP(model.parameters(), lr = ....) + model, opt = amp.initialize(model, opt, opt_level="O2") + ... + opt.step() + + + The original Adam algorithm was proposed in `Adam: A Method for Stochastic Optimization`_. + The AdamP variant was proposed in `Decoupled Weight Decay Regularization`_. + + Arguments: + params (iterable): iterable of parameters to optimize or dicts defining + parameter groups + lr (float, optional, default: 1e-3): learning rate + betas (Tuple[float, float], optional, default: (0.9, 0.999)): coefficients used + for computing running averages of gradient and its square + eps (float, optional, default: 1e-8): term added to the denominator to improve + numerical stability + weight_decay (float, optional, default: 1e-2): weight decay coefficient + amsgrad (boolean, optional, default: False): whether to use the AMSGrad variant of + this algorithm from the paper `On the Convergence of Adam and Beyond`_ + + .. _Adam\: A Method for Stochastic Optimization: + https://arxiv.org/abs/1412.6980 + .. _Decoupled Weight Decay Regularization: + https://arxiv.org/abs/1711.05101 + .. _On the Convergence of Adam and Beyond: + https://openreview.net/forum?id=ryQu7f-RZ + """ + + def __init__(self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, + weight_decay=0, delta=0.1, wd_ratio=0.1, nesterov=False): + defaults = dict(lr=lr, betas=betas, eps=eps, weight_decay=weight_decay, + delta=delta, wd_ratio=wd_ratio, nesterov=nesterov) + self.is_npu_fused_optimizer = True + super(NpuFusedAdamP, self).__init__(params, defaults) + + def __setstate__(self, state): + super(NpuFusedAdamP, self).__setstate__(state) + for group in self.param_groups: + group.setdefault('nesterov', False) + + def _channel_view(self, x): + return x.view(x.size(0), -1) + + def _layer_view(self, x): + return x.view(1, -1) + + def _cosine_similarity(self, x, y, eps, view_func): + x = view_func(x) + y = view_func(y) + + x_norm = x.norm(dim=1).add_(eps) + y_norm = y.norm(dim=1).add_(eps) + dot = (x * y).sum(dim=1) + + return dot.abs() / x_norm / y_norm + + def _projection(self, p, grad, perturb, delta, wd_ratio, eps): + wd = 1 + expand_size = [-1] + [1] * (len(p.shape) - 1) + for view_func in [self._channel_view, self._layer_view]: + + cosine_sim = self._cosine_similarity(grad, p, eps, view_func) + + if cosine_sim.max() < delta / math.sqrt(view_func(p).size(1)): + p_n = p / view_func(p).norm(dim=1).view(expand_size).add_(eps) + perturb -= p_n * view_func(p_n * perturb).sum(dim=1).view(expand_size) + wd = wd_ratio + + return perturb, wd + + return perturb, wd + + def _init_param_state(self, p): + state = self.state[p] + # State initialization + if len(state) == 0: + state['step'] = 0 + # Exponential moving average of gradient values + state['exp_avg'] = torch.zeros_like(p, memory_format=torch.preserve_format) + # Exponential moving average of squared gradient values + state['exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format) + else: + exp_avg_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) + exp_avg_tmp.copy_(state['exp_avg']) + state['exp_avg'] = exp_avg_tmp + + exp_avg_sq_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) + exp_avg_sq_tmp.copy_(state['exp_avg_sq']) + state['exp_avg_sq'] = exp_avg_sq_tmp + + def _combine_group_param_states(self, group_index): + group = self.param_groups[group_index] + stash = self._amp_stash + group_params_list = stash.params_lists_indexed_by_group[group_index] + + combined_param_states = [] + for params in group_params_list: + step_list = [] + exp_avg_list = [] + exp_avg_sq_list = [] + max_exp_avg_sq_list = [] + + for p in params: + if p.grad is None: + continue + grad = p.grad + if grad.is_sparse: + raise RuntimeError('NpuFusedAdamP does not support sparse gradients, ' + 'please consider SparseAdam instead') + + self._init_param_state(p) + state = self.state[p] + step_list.append(state['step']) + exp_avg_list.append(state['exp_avg']) + exp_avg_sq_list.append(state['exp_avg_sq']) + + combined_step = 0 + combined_exp_avg = None + combined_exp_avg_sq = None + combined_max_exp_avg_sq = None + + if len(exp_avg_list) > 0: + combined_step = step_list[0] + combined_exp_avg = combine_npu(exp_avg_list) + combined_exp_avg_sq = combine_npu(exp_avg_sq_list) + combined_max_exp_avg_sq = combine_npu(max_exp_avg_sq_list) + + combined_state = defaultdict(dict) + combined_state['step'] = combined_step + combined_state['exp_avg'] = combined_exp_avg + combined_state['exp_avg_sq'] = combined_exp_avg_sq + combined_state['max_exp_avg_sq'] = combined_max_exp_avg_sq + combined_param_states.append(combined_state) + stash.combined_param_states_indexed_by_group[group_index] = combined_param_states + + def _combine_param_states_by_group(self): + stash = self._amp_stash + if stash.param_states_are_combined_by_group: + return + + stash.combined_param_states_indexed_by_group = [] + for _ in self.param_groups: + stash.combined_param_states_indexed_by_group.append([]) + + for i, _ in enumerate(self.param_groups): + self._combine_group_param_states(i) + stash.param_states_are_combined_by_group = True + + def _group_step(self, group_index): + group = self.param_groups[group_index] + for p in group['params']: + if p.grad is None: + continue + + grad = p.grad.data + state = self.state[p] + state['step'] += 1 + + + beta1, beta2 = group['betas'] + nesterov = group['nesterov'] + + stash = self._amp_stash + combined_group_params = stash.combined_params_indexed_by_group[group_index] + combined_group_grads = stash.combined_grads_indexed_by_group[group_index] + combined_group_param_states = stash.combined_param_states_indexed_by_group[group_index] + + for combined_param, combined_grad, combined_param_state in zip(combined_group_params, + combined_group_grads, + combined_group_param_states): + if combined_param is None or combined_grad is None: + continue + + exp_avg, exp_avg_sq = combined_param_state['exp_avg'], combined_param_state['exp_avg_sq'] + + combined_param_state['step'] += 1 + bias_correction1 = 1 - beta1 ** combined_param_state['step'] + bias_correction2 = 1 - beta2 ** combined_param_state['step'] + + # Decay the first and second moment running average coefficient + exp_avg.mul_(beta1).add_(combined_grad, alpha=1 - beta1) + exp_avg_sq.mul_(beta2).addcmul_(combined_grad, combined_grad, value=1 - beta2) + denom = (exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group['eps']) + step_size = group['lr'] / bias_correction1 + + if nesterov: + perturb = (beta1 * exp_avg + (1 - beta1) * combined_grad) / denom + else: + perturb = exp_avg / denom + + # Projection + wd_ratio = 1 + if len(combined_param.shape) > 1: + perturb, wd_ratio = self._projection(combined_param, combined_grad, perturb, group['delta'], group['wd_ratio'], group['eps']) + + # Weight decay + if group['weight_decay'] > 0: + combined_param.mul_(1 - group['lr'] * group['weight_decay'] * wd_ratio) + + # Step + combined_param.add_(-step_size, perturb) + + @torch.no_grad() + def step(self, closure=None): + if not hasattr(self, "_amp_stash"): + raise RuntimeError('apex.optimizers.NpuFusedAdamP should be used with AMP.') + + self._check_already_combined_params_and_grads() + # combine params and grads first + self._combine_params_and_grads_by_group() + # then combine param states + self._combine_param_states_by_group() + + loss = None + if closure is not None: + with torch.enable_grad(): + loss = closure() + + for i, _ in enumerate(self.param_groups): + self._group_step(i) + + return loss diff --git a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/timm/optim/npu_fused_adamw.py b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/timm/optim/npu_fused_adamw.py index 043a281b3106cdbbea33ddd72b4edeb36d87e02a..87896fce404d5d897522f0364c114747194e1006 100644 --- a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/timm/optim/npu_fused_adamw.py +++ b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/timm/optim/npu_fused_adamw.py @@ -1,289 +1,289 @@ -""" -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Copyright 2020 Huawei Technologies Co., Ltd - -Licensed under the BSD 3-Clause License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://spdx.org/licenses/BSD-3-Clause.html - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -import math -from collections import defaultdict - -import torch -from torch.optim.optimizer import Optimizer - -from apex.contrib.combine_tensors import combine_npu - - -class NpuFusedAdamW(Optimizer): - """Implements AdamW algorithm. - - Currently NPU-only. Requires Apex to be installed via - ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--npu_float_status" ./``. - - This version of NPU fused AdamW implements 1 fusions. - - * A combine-tensor apply launch that batches the elementwise updates applied to all the model's parameters - into one or a few kernel launches. - - :class:`apex.optimizers.NpuFusedAdamW` may be used as a drop-in replacement for ``torch.optim.AdamW``:: - - opt = apex.optimizers.NpuFusedAdamW(model.parameters(), lr = ....) - ... - opt.step() - - :class:`apex.optimizers.FusedAdam` should be used with Amp. Currently, if you wish to use :class:`NpuFusedAdamW` - with Amp, only ``opt_level O1 and O2`` can be choosed:: - - opt = apex.optimizers.NpuFusedAdamW(model.parameters(), lr = ....) - model, opt = amp.initialize(model, opt, opt_level="O2") - ... - opt.step() - - - The original Adam algorithm was proposed in `Adam: A Method for Stochastic Optimization`_. - The AdamW variant was proposed in `Decoupled Weight Decay Regularization`_. - - Arguments: - params (iterable): iterable of parameters to optimize or dicts defining - parameter groups - lr (float, optional): learning rate (default: 1e-3) - betas (Tuple[float, float], optional): coefficients used for computing - running averages of gradient and its square (default: (0.9, 0.999)) - eps (float, optional): term added to the denominator to improve - numerical stability (default: 1e-8) - weight_decay (float, optional): weight decay coefficient (default: 1e-2) - amsgrad (boolean, optional): whether to use the AMSGrad variant of this - algorithm from the paper `On the Convergence of Adam and Beyond`_ - (default: False) - - .. _Adam\: A Method for Stochastic Optimization: - https://arxiv.org/abs/1412.6980 - .. _Decoupled Weight Decay Regularization: - https://arxiv.org/abs/1711.05101 - .. _On the Convergence of Adam and Beyond: - https://openreview.net/forum?id=ryQu7f-RZ - """ - - def __init__(self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, - weight_decay=1e-2, amsgrad=False): - if lr < 0.0: - raise ValueError("Invalid learning rate: {}".format(lr)) - if eps < 0.0: - raise ValueError("Invalid epsilon value: {}".format(eps)) - if betas[0] < 0.0 or betas[0] >= 1.0: - raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) - if betas[1] < 0.0 or betas[1] >= 1.0: - raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) - if weight_decay < 0.0: - raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) - defaults = dict(lr=lr, betas=betas, eps=eps, - weight_decay=weight_decay, amsgrad=amsgrad) - self.is_npu_fused_optimizer = True - super(NpuFusedAdamW, self).__init__(params, defaults) - - def __setstate__(self, state): - super(NpuFusedAdamW, self).__setstate__(state) - for group in self.param_groups: - group.setdefault('amsgrad', False) - - def _init_param_state(self, p, amsgrad): - state = self.state[p] - # State initialization - if len(state) == 0: - state['step'] = 0 - # Exponential moving average of gradient values - state['exp_avg'] = torch.zeros_like(p, memory_format=torch.preserve_format) - # Exponential moving average of squared gradient values - state['exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format) - if amsgrad: - # Maintains max of all exp. moving avg. of sq. grad. values - state['max_exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format) - else: - exp_avg_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) - exp_avg_tmp.copy_(state['exp_avg']) - state['exp_avg'] = exp_avg_tmp - - exp_avg_sq_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) - exp_avg_sq_tmp.copy_(state['exp_avg_sq']) - state['exp_avg_sq'] = exp_avg_sq_tmp - - if amsgrad: - max_exp_avg_sq_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) - max_exp_avg_sq_tmp.copy_(state['max_exp_avg_sq']) - state['max_exp_avg_sq'] = max_exp_avg_sq_tmp - - def _combine_group_param_states(self, group_index): - group = self.param_groups[group_index] - stash = self._amp_stash - group_params_list = stash.params_lists_indexed_by_group[group_index] - - amsgrad = group['amsgrad'] - - combined_param_states = [] - for params in group_params_list: - step_list = [] - exp_avg_list = [] - exp_avg_sq_list = [] - max_exp_avg_sq_list = [] - - for p in params: - if p.grad is None: - continue - grad = p.grad - if grad.is_sparse: - raise RuntimeError('NpuFusedAdamW does not support sparse gradients, ' - 'please consider SparseAdam instead') - - self._init_param_state(p, amsgrad) - state = self.state[p] - step_list.append(state['step']) - exp_avg_list.append(state['exp_avg']) - exp_avg_sq_list.append(state['exp_avg_sq']) - if amsgrad: - max_exp_avg_sq_list.append(state['max_exp_avg_sq']) - - combined_step = 0 - combined_exp_avg = None - combined_exp_avg_sq = None - combined_max_exp_avg_sq = None - - if len(exp_avg_list) > 0: - combined_step = step_list[0] - combined_exp_avg = combine_npu(exp_avg_list) - combined_exp_avg_sq = combine_npu(exp_avg_sq_list) - combined_max_exp_avg_sq = combine_npu(max_exp_avg_sq_list) - - combined_state = defaultdict(dict) - combined_state['step'] = combined_step - combined_state['exp_avg'] = combined_exp_avg - combined_state['exp_avg_sq'] = combined_exp_avg_sq - combined_state['max_exp_avg_sq'] = combined_max_exp_avg_sq - combined_param_states.append(combined_state) - stash.combined_param_states_indexed_by_group[group_index] = combined_param_states - - def _combine_param_states_by_group(self): - stash = self._amp_stash - if stash.param_states_are_combined_by_group: - return - - stash.combined_param_states_indexed_by_group = [] - for _ in self.param_groups: - stash.combined_param_states_indexed_by_group.append([]) - - for i, _ in enumerate(self.param_groups): - self._combine_group_param_states(i) - stash.param_states_are_combined_by_group = True - - def _group_step(self, group_index): - group = self.param_groups[group_index] - for p in group['params']: - if p.grad is None: - continue - - grad = p.grad - if grad.is_sparse: - raise RuntimeError('NpuFusedAdamW does not support sparse gradients, ' - 'please consider SparseAdam instead') - state_p = self.state[p] - state_p['step'] += 1 - - amsgrad = group['amsgrad'] - beta1, beta2 = group['betas'] - - stash = self._amp_stash - combined_group_params = stash.combined_params_indexed_by_group[group_index] - combined_group_grads = stash.combined_grads_indexed_by_group[group_index] - combined_group_param_states = stash.combined_param_states_indexed_by_group[group_index] - - for combined_param, combined_grad, combined_param_state in zip(combined_group_params, - combined_group_grads, - combined_group_param_states): - if combined_param is None or combined_grad is None: - continue - - # Perform stepweight decay. The fused method is used here to speed up the calculation - combined_param.mul_(1 - group['lr'] * group['weight_decay']) - - exp_avg, exp_avg_sq = combined_param_state['exp_avg'], combined_param_state['exp_avg_sq'] - if amsgrad: - max_exp_avg_sq = combined_param_state['max_exp_avg_sq'] - - combined_param_state['step'] += 1 - bias_correction1 = 1 - beta1 ** combined_param_state['step'] - bias_correction2 = 1 - beta2 ** combined_param_state['step'] - - # Decay the first and second moment running average coefficient - exp_avg.mul_(beta1).add_(combined_grad, alpha=1 - beta1) - exp_avg_sq.mul_(beta2).addcmul_(combined_grad, combined_grad, value=1 - beta2) - if amsgrad: - # Maintains the maximum of all 2nd moment running avg. till now - torch.max(max_exp_avg_sq, exp_avg_sq, out=max_exp_avg_sq) - # Use the max. for normalizing running avg. of gradient - denom = (max_exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group['eps']) - else: - denom = (exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group['eps']) - - step_size = group['lr'] / bias_correction1 - - combined_param.addcdiv_(exp_avg, denom, value=-step_size) - - @torch.no_grad() - def step(self, closure=None): - if not hasattr(self, "_amp_stash"): - raise RuntimeError('apex.optimizers.NpuFusedAdamW should be used with AMP.') - - self._check_already_combined_params_and_grads() - # combine params and grads first - self._combine_params_and_grads_by_group() - # then combine param states - self._combine_param_states_by_group() - - loss = None - if closure is not None: - with torch.enable_grad(): - loss = closure() - - for i, _ in enumerate(self.param_groups): - self._group_step(i) - - return loss +""" +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Copyright 2020 Huawei Technologies Co., Ltd + +Licensed under the BSD 3-Clause License (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +https://spdx.org/licenses/BSD-3-Clause.html + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import math +from collections import defaultdict + +import torch +from torch.optim.optimizer import Optimizer + +from apex.contrib.combine_tensors import combine_npu + + +class NpuFusedAdamW(Optimizer): + """Implements AdamW algorithm. + + Currently NPU-only. Requires Apex to be installed via + ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--npu_float_status" ./``. + + This version of NPU fused AdamW implements 1 fusions. + + * A combine-tensor apply launch that batches the elementwise updates applied to all the model's parameters + into one or a few kernel launches. + + :class:`apex.optimizers.NpuFusedAdamW` may be used as a drop-in replacement for ``torch.optim.AdamW``:: + + opt = apex.optimizers.NpuFusedAdamW(model.parameters(), lr = ....) + ... + opt.step() + + :class:`apex.optimizers.FusedAdam` should be used with Amp. Currently, if you wish to use :class:`NpuFusedAdamW` + with Amp, only ``opt_level O1 and O2`` can be choosed:: + + opt = apex.optimizers.NpuFusedAdamW(model.parameters(), lr = ....) + model, opt = amp.initialize(model, opt, opt_level="O2") + ... + opt.step() + + + The original Adam algorithm was proposed in `Adam: A Method for Stochastic Optimization`_. + The AdamW variant was proposed in `Decoupled Weight Decay Regularization`_. + + Arguments: + params (iterable): iterable of parameters to optimize or dicts defining + parameter groups + lr (float, optional): learning rate (default: 1e-3) + betas (Tuple[float, float], optional): coefficients used for computing + running averages of gradient and its square (default: (0.9, 0.999)) + eps (float, optional): term added to the denominator to improve + numerical stability (default: 1e-8) + weight_decay (float, optional): weight decay coefficient (default: 1e-2) + amsgrad (boolean, optional): whether to use the AMSGrad variant of this + algorithm from the paper `On the Convergence of Adam and Beyond`_ + (default: False) + + .. _Adam\: A Method for Stochastic Optimization: + https://arxiv.org/abs/1412.6980 + .. _Decoupled Weight Decay Regularization: + https://arxiv.org/abs/1711.05101 + .. _On the Convergence of Adam and Beyond: + https://openreview.net/forum?id=ryQu7f-RZ + """ + + def __init__(self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, + weight_decay=1e-2, amsgrad=False): + if lr < 0.0: + raise ValueError("Invalid learning rate: {}".format(lr)) + if eps < 0.0: + raise ValueError("Invalid epsilon value: {}".format(eps)) + if betas[0] < 0.0 or betas[0] >= 1.0: + raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) + if betas[1] < 0.0 or betas[1] >= 1.0: + raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) + if weight_decay < 0.0: + raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) + defaults = dict(lr=lr, betas=betas, eps=eps, + weight_decay=weight_decay, amsgrad=amsgrad) + self.is_npu_fused_optimizer = True + super(NpuFusedAdamW, self).__init__(params, defaults) + + def __setstate__(self, state): + super(NpuFusedAdamW, self).__setstate__(state) + for group in self.param_groups: + group.setdefault('amsgrad', False) + + def _init_param_state(self, p, amsgrad): + state = self.state[p] + # State initialization + if len(state) == 0: + state['step'] = 0 + # Exponential moving average of gradient values + state['exp_avg'] = torch.zeros_like(p, memory_format=torch.preserve_format) + # Exponential moving average of squared gradient values + state['exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format) + if amsgrad: + # Maintains max of all exp. moving avg. of sq. grad. values + state['max_exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format) + else: + exp_avg_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) + exp_avg_tmp.copy_(state['exp_avg']) + state['exp_avg'] = exp_avg_tmp + + exp_avg_sq_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) + exp_avg_sq_tmp.copy_(state['exp_avg_sq']) + state['exp_avg_sq'] = exp_avg_sq_tmp + + if amsgrad: + max_exp_avg_sq_tmp = torch.zeros_like(p, memory_format=torch.preserve_format) + max_exp_avg_sq_tmp.copy_(state['max_exp_avg_sq']) + state['max_exp_avg_sq'] = max_exp_avg_sq_tmp + + def _combine_group_param_states(self, group_index): + group = self.param_groups[group_index] + stash = self._amp_stash + group_params_list = stash.params_lists_indexed_by_group[group_index] + + amsgrad = group['amsgrad'] + + combined_param_states = [] + for params in group_params_list: + step_list = [] + exp_avg_list = [] + exp_avg_sq_list = [] + max_exp_avg_sq_list = [] + + for p in params: + if p.grad is None: + continue + grad = p.grad + if grad.is_sparse: + raise RuntimeError('NpuFusedAdamW does not support sparse gradients, ' + 'please consider SparseAdam instead') + + self._init_param_state(p, amsgrad) + state = self.state[p] + step_list.append(state['step']) + exp_avg_list.append(state['exp_avg']) + exp_avg_sq_list.append(state['exp_avg_sq']) + if amsgrad: + max_exp_avg_sq_list.append(state['max_exp_avg_sq']) + + combined_step = 0 + combined_exp_avg = None + combined_exp_avg_sq = None + combined_max_exp_avg_sq = None + + if len(exp_avg_list) > 0: + combined_step = step_list[0] + combined_exp_avg = combine_npu(exp_avg_list) + combined_exp_avg_sq = combine_npu(exp_avg_sq_list) + combined_max_exp_avg_sq = combine_npu(max_exp_avg_sq_list) + + combined_state = defaultdict(dict) + combined_state['step'] = combined_step + combined_state['exp_avg'] = combined_exp_avg + combined_state['exp_avg_sq'] = combined_exp_avg_sq + combined_state['max_exp_avg_sq'] = combined_max_exp_avg_sq + combined_param_states.append(combined_state) + stash.combined_param_states_indexed_by_group[group_index] = combined_param_states + + def _combine_param_states_by_group(self): + stash = self._amp_stash + if stash.param_states_are_combined_by_group: + return + + stash.combined_param_states_indexed_by_group = [] + for _ in self.param_groups: + stash.combined_param_states_indexed_by_group.append([]) + + for i, _ in enumerate(self.param_groups): + self._combine_group_param_states(i) + stash.param_states_are_combined_by_group = True + + def _group_step(self, group_index): + group = self.param_groups[group_index] + for p in group['params']: + if p.grad is None: + continue + + grad = p.grad + if grad.is_sparse: + raise RuntimeError('NpuFusedAdamW does not support sparse gradients, ' + 'please consider SparseAdam instead') + state_p = self.state[p] + state_p['step'] += 1 + + amsgrad = group['amsgrad'] + beta1, beta2 = group['betas'] + + stash = self._amp_stash + combined_group_params = stash.combined_params_indexed_by_group[group_index] + combined_group_grads = stash.combined_grads_indexed_by_group[group_index] + combined_group_param_states = stash.combined_param_states_indexed_by_group[group_index] + + for combined_param, combined_grad, combined_param_state in zip(combined_group_params, + combined_group_grads, + combined_group_param_states): + if combined_param is None or combined_grad is None: + continue + + # Perform stepweight decay. The fused method is used here to speed up the calculation + combined_param.mul_(1 - group['lr'] * group['weight_decay']) + + exp_avg, exp_avg_sq = combined_param_state['exp_avg'], combined_param_state['exp_avg_sq'] + if amsgrad: + max_exp_avg_sq = combined_param_state['max_exp_avg_sq'] + + combined_param_state['step'] += 1 + bias_correction1 = 1 - beta1 ** combined_param_state['step'] + bias_correction2 = 1 - beta2 ** combined_param_state['step'] + + # Decay the first and second moment running average coefficient + exp_avg.mul_(beta1).add_(combined_grad, alpha=1 - beta1) + exp_avg_sq.mul_(beta2).addcmul_(combined_grad, combined_grad, value=1 - beta2) + if amsgrad: + # Maintains the maximum of all 2nd moment running avg. till now + torch.max(max_exp_avg_sq, exp_avg_sq, out=max_exp_avg_sq) + # Use the max. for normalizing running avg. of gradient + denom = (max_exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group['eps']) + else: + denom = (exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group['eps']) + + step_size = group['lr'] / bias_correction1 + + combined_param.addcdiv_(exp_avg, denom, value=-step_size) + + @torch.no_grad() + def step(self, closure=None): + if not hasattr(self, "_amp_stash"): + raise RuntimeError('apex.optimizers.NpuFusedAdamW should be used with AMP.') + + self._check_already_combined_params_and_grads() + # combine params and grads first + self._combine_params_and_grads_by_group() + # then combine param states + self._combine_param_states_by_group() + + loss = None + if closure is not None: + with torch.enable_grad(): + loss = closure() + + for i, _ in enumerate(self.param_groups): + self._group_step(i) + + return loss diff --git a/PyTorch/contrib/cv/classification/Vit_small_patch16_224/train.py b/PyTorch/contrib/cv/classification/Vit_small_patch16_224/train.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/VoVNet39/test/train_eval_8p.sh b/PyTorch/contrib/cv/classification/VoVNet39/test/train_eval_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/VoVNet39/test/train_finetune_1p.sh b/PyTorch/contrib/cv/classification/VoVNet39/test/train_finetune_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/VoVNet39/test/train_full_8p.sh b/PyTorch/contrib/cv/classification/VoVNet39/test/train_full_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/VoVNet39/test/train_performance_1p.sh b/PyTorch/contrib/cv/classification/VoVNet39/test/train_performance_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/VoVNet39/test/train_performance_8p.sh b/PyTorch/contrib/cv/classification/VoVNet39/test/train_performance_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/Dockerfile b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/Dockerfile index 16a84a07a12d6f9beb7ec418ac01964421d38163..5889f351145fc5d4aa1a7a1b210cc33304226580 100644 --- a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/Dockerfile +++ b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/Dockerfile @@ -1,22 +1,22 @@ -ARG FROM_IMAGE_NAME -FROM ${FROM_IMAGE_NAME} - -ARG SDK_PKG - -RUN ln -s /usr/local/python3.7.5/bin/python3.7 /usr/bin/python - -RUN apt-get update && \ - apt-get install libglib2.0-dev -y || \ - rm -rf /var/lib/dpkg/info && \ - mkdir /var/lib/dpkg/info && \ - apt-get install libglib2.0-dev -y && \ - pip install pytest-runner==5.3.0 -COPY sdk/requirements.txt . -RUN pip3.7 install -r requirements.txt - -# pip install sdk_run -COPY $SDK_PKG . -RUN ls -hrlt -RUN chmod +x ${SDK_PKG} && \ - ./${SDK_PKG} --install && \ +ARG FROM_IMAGE_NAME +FROM ${FROM_IMAGE_NAME} + +ARG SDK_PKG + +RUN ln -s /usr/local/python3.7.5/bin/python3.7 /usr/bin/python + +RUN apt-get update && \ + apt-get install libglib2.0-dev -y || \ + rm -rf /var/lib/dpkg/info && \ + mkdir /var/lib/dpkg/info && \ + apt-get install libglib2.0-dev -y && \ + pip install pytest-runner==5.3.0 +COPY sdk/requirements.txt . +RUN pip3.7 install -r requirements.txt + +# pip install sdk_run +COPY $SDK_PKG . +RUN ls -hrlt +RUN chmod +x ${SDK_PKG} && \ + ./${SDK_PKG} --install && \ bash -c "source ~/.bashrc" \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/convert/xception_pt_aipp.config b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/convert/xception_pt_aipp.config index 5c8ab6938007edf566beff150883d61b4e0f2984..649639850c2f7bd6367fbb8a3befb29c0df6a82f 100644 --- a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/convert/xception_pt_aipp.config +++ b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/convert/xception_pt_aipp.config @@ -1,16 +1,16 @@ -aipp_op { - aipp_mode: static - input_format : RGB888_U8 - csc_switch : false - rbuv_swap_switch : true - - mean_chn_0 : 0 - mean_chn_1 : 0 - mean_chn_2 : 0 - min_chn_0 : 127.5 - min_chn_1 : 127.5 - min_chn_2 : 127.5 - var_reci_chn_0 : 0.007843137254902 - var_reci_chn_1 : 0.007843137254902 - var_reci_chn_2 : 0.007843137254902 -} +aipp_op { + aipp_mode: static + input_format : RGB888_U8 + csc_switch : false + rbuv_swap_switch : true + + mean_chn_0 : 0 + mean_chn_1 : 0 + mean_chn_2 : 0 + min_chn_0 : 127.5 + min_chn_1 : 127.5 + min_chn_2 : 127.5 + var_reci_chn_0 : 0.007843137254902 + var_reci_chn_1 : 0.007843137254902 + var_reci_chn_2 : 0.007843137254902 +} diff --git a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/models/xception_aipp.cfg b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/models/xception_aipp.cfg index d01feefc8eb9859daa5cc76a4570d91c5371a3e5..75bba4acb3d512f91e3caa928c2969c66f0303c7 100644 --- a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/models/xception_aipp.cfg +++ b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/models/xception_aipp.cfg @@ -1,3 +1,3 @@ -CLASS_NUM=1000 -SOFTMAX=True +CLASS_NUM=1000 +SOFTMAX=True TOP_K=5 \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/CMakeLists.txt b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/CMakeLists.txt index 53ff21c352aa0c3d77c69dad849176c13cc4673a..77b66042819ff3af8f26d215aa80fa4d8dc8f92b 100644 --- a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/CMakeLists.txt +++ b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/CMakeLists.txt @@ -1,52 +1,52 @@ -cmake_minimum_required(VERSION 3.10.0) -project(xception) - -set(TARGET xception) - -add_definitions(-DENABLE_DVPP_INTERFACE) -add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) -add_definitions(-Dgoogle=mindxsdk_private) -add_compile_options(-std=c++11 -fPIE -fstack-protector-all -fPIC -Wall) -add_link_options(-Wl,-z,relro,-z,now,-z,noexecstack -s -pie) - -# Check environment variable -if(NOT DEFINED ENV{ASCEND_HOME}) - message(FATAL_ERROR "please define environment variable:ASCEND_HOME") -endif() -if(NOT DEFINED ENV{ASCEND_VERSION}) - message(WARNING "please define environment variable:ASCEND_VERSION") -endif() -if(NOT DEFINED ENV{ARCH_PATTERN}) - message(WARNING "please define environment variable:ARCH_PATTERN") -endif() -set(ACL_INC_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/include) -set(ACL_LIB_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/lib64) - -set(MXBASE_ROOT_DIR $ENV{MX_SDK_HOME}) -set(MXBASE_INC ${MXBASE_ROOT_DIR}/include) -set(MXBASE_LIB_DIR ${MXBASE_ROOT_DIR}/lib) -set(MXBASE_POST_LIB_DIR ${MXBASE_ROOT_DIR}/lib/modelpostprocessors) -set(MXBASE_POST_PROCESS_DIR ${MXBASE_ROOT_DIR}/include/MxBase/postprocess/include) - -if(DEFINED ENV{MXSDK_OPENSOURCE_DIR}) - set(OPENSOURCE_DIR $ENV{MXSDK_OPENSOURCE_DIR}) -else() - set(OPENSOURCE_DIR ${MXBASE_ROOT_DIR}/opensource) -endif() -include_directories(/home/data/ics_yu/mxVision-2.0.2/lib/modelpostprocessors/) -include_directories(${ACL_INC_DIR}) -include_directories(${OPENSOURCE_DIR}/include) -include_directories(${OPENSOURCE_DIR}/include/opencv4) - -include_directories(${MXBASE_INC}) -include_directories(${MXBASE_POST_PROCESS_DIR}) - -link_directories(${ACL_LIB_DIR}) -link_directories(${OPENSOURCE_DIR}/lib) -link_directories(${MXBASE_LIB_DIR}) -link_directories(${MXBASE_POST_LIB_DIR}) - -add_executable(${TARGET} main.cpp XceptionClassify.cpp) -target_link_libraries(${TARGET} glog cpprest mxbase resnet50postprocess opencv_world stdc++fs) - -install(TARGETS ${TARGET} RUNTIME DESTINATION ${PROJECT_SOURCE_DIR}/) +cmake_minimum_required(VERSION 3.10.0) +project(xception) + +set(TARGET xception) + +add_definitions(-DENABLE_DVPP_INTERFACE) +add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) +add_definitions(-Dgoogle=mindxsdk_private) +add_compile_options(-std=c++11 -fPIE -fstack-protector-all -fPIC -Wall) +add_link_options(-Wl,-z,relro,-z,now,-z,noexecstack -s -pie) + +# Check environment variable +if(NOT DEFINED ENV{ASCEND_HOME}) + message(FATAL_ERROR "please define environment variable:ASCEND_HOME") +endif() +if(NOT DEFINED ENV{ASCEND_VERSION}) + message(WARNING "please define environment variable:ASCEND_VERSION") +endif() +if(NOT DEFINED ENV{ARCH_PATTERN}) + message(WARNING "please define environment variable:ARCH_PATTERN") +endif() +set(ACL_INC_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/include) +set(ACL_LIB_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/lib64) + +set(MXBASE_ROOT_DIR $ENV{MX_SDK_HOME}) +set(MXBASE_INC ${MXBASE_ROOT_DIR}/include) +set(MXBASE_LIB_DIR ${MXBASE_ROOT_DIR}/lib) +set(MXBASE_POST_LIB_DIR ${MXBASE_ROOT_DIR}/lib/modelpostprocessors) +set(MXBASE_POST_PROCESS_DIR ${MXBASE_ROOT_DIR}/include/MxBase/postprocess/include) + +if(DEFINED ENV{MXSDK_OPENSOURCE_DIR}) + set(OPENSOURCE_DIR $ENV{MXSDK_OPENSOURCE_DIR}) +else() + set(OPENSOURCE_DIR ${MXBASE_ROOT_DIR}/opensource) +endif() +include_directories(/home/data/ics_yu/mxVision-2.0.2/lib/modelpostprocessors/) +include_directories(${ACL_INC_DIR}) +include_directories(${OPENSOURCE_DIR}/include) +include_directories(${OPENSOURCE_DIR}/include/opencv4) + +include_directories(${MXBASE_INC}) +include_directories(${MXBASE_POST_PROCESS_DIR}) + +link_directories(${ACL_LIB_DIR}) +link_directories(${OPENSOURCE_DIR}/lib) +link_directories(${MXBASE_LIB_DIR}) +link_directories(${MXBASE_POST_LIB_DIR}) + +add_executable(${TARGET} main.cpp XceptionClassify.cpp) +target_link_libraries(${TARGET} glog cpprest mxbase resnet50postprocess opencv_world stdc++fs) + +install(TARGETS ${TARGET} RUNTIME DESTINATION ${PROJECT_SOURCE_DIR}/) diff --git a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/XceptionClassify.cpp b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/XceptionClassify.cpp index 929bd67d85952f104c3a1aece707c2f6c21ec953..61acb36242dc692ea7edf7a7231c54462140bbc8 100644 --- a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/XceptionClassify.cpp +++ b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/XceptionClassify.cpp @@ -1,250 +1,250 @@ -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "XceptionClassify.h" -#include "MxBase/DeviceManager/DeviceManager.h" -#include "MxBase/Log/Log.h" - -using namespace MxBase; -namespace { -const uint32_t YUV_BYTE_NU = 3; -const uint32_t YUV_BYTE_DE = 2; -const uint32_t VPC_H_ALIGN = 2; -} - -APP_ERROR XceptionClassify::Init(const InitParam &initParam) -{ - deviceId_ = initParam.deviceId; - APP_ERROR ret = MxBase::DeviceManager::GetInstance()->InitDevices(); - if (ret != APP_ERR_OK) { - LogError << "Init devices failed, ret=" << ret << "."; - return ret; - } - ret = MxBase::TensorContext::GetInstance()->SetContext(initParam.deviceId); - if (ret != APP_ERR_OK) { - LogError << "Set context failed, ret=" << ret << "."; - return ret; - } - dvppWrapper_ = std::make_shared(); - ret = dvppWrapper_->Init(); - if (ret != APP_ERR_OK) { - LogError << "DvppWrapper init failed, ret=" << ret << "."; - return ret; - } - model_ = std::make_shared(); - ret = model_->Init(initParam.modelPath, modelDesc_); - if (ret != APP_ERR_OK) { - LogError << "ModelInferenceProcessor init failed, ret=" << ret << "."; - return ret; - } - MxBase::ConfigData configData; - const std::string softmax = initParam.softmax ? "true" : "false"; - const std::string checkTensor = initParam.checkTensor ? "true" : "false"; - - configData.SetJsonValue("CLASS_NUM", std::to_string(initParam.classNum)); - configData.SetJsonValue("TOP_K", std::to_string(initParam.topk)); - configData.SetJsonValue("SOFTMAX", softmax); - configData.SetJsonValue("CHECK_MODEL", checkTensor); - - auto jsonStr = configData.GetCfgJson().serialize(); - std::map> config; - config["postProcessConfigContent"] = std::make_shared(jsonStr); - config["labelPath"] = std::make_shared(initParam.labelPath); - - post_ = std::make_shared(); - ret = post_->Init(config); - if (ret != APP_ERR_OK) { - LogError << "Resnet50PostProcess init failed, ret=" << ret << "."; - return ret; - } - return APP_ERR_OK; -} - -APP_ERROR XceptionClassify::DeInit() -{ - dvppWrapper_->DeInit(); - model_->DeInit(); - post_->DeInit(); - MxBase::DeviceManager::GetInstance()->DestroyDevices(); - return APP_ERR_OK; -} - -void XceptionClassify::ReadImage(const std::string &imgPath, cv::Mat &imageMat) -{ - imageMat = cv::imread(imgPath, cv::IMREAD_COLOR); -} - -void XceptionClassify::CenterCropImage(cv::Mat &img, cv::Mat &cropImg) -{ - float central_fraction = 0.75; - int crop_x = img.cols * central_fraction; - int crop_y = img.rows * central_fraction; - int crop_x1 = (img.cols - crop_x) / 2; - int crop_y1 = (img.rows - crop_y) / 2; - - cv::Rect myROI(crop_x1, crop_y1, crop_x, crop_y); - LogInfo << "images crop_x1: " << crop_x1 << ", crop_x: " << crop_x << ", crop_y1: " << crop_y1 << ", crop_y: " << crop_y; - cropImg = img(myROI); -} - -void XceptionClassify::Resize(const cv::Mat &srcImageMat, cv::Mat &dstImageMat) -{ - static constexpr uint32_t resizeHeight = 299; - static constexpr uint32_t resizeWidth = 299; - - cv::resize(srcImageMat, dstImageMat, cv::Size(resizeWidth, resizeHeight)); -} - -APP_ERROR XceptionClassify::CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase) -{ - const uint32_t dataSize = imageMat.cols * imageMat.rows * YUV444_RGB_WIDTH_NU; - MemoryData memoryDataDst(dataSize, MemoryData::MEMORY_DEVICE, deviceId_); - MemoryData memoryDataSrc(imageMat.data, dataSize, MemoryData::MEMORY_HOST_MALLOC); - - APP_ERROR ret = MemoryHelper::MxbsMallocAndCopy(memoryDataDst, memoryDataSrc); - if (ret != APP_ERR_OK) { - LogError << GetError(ret) << "Memory malloc failed."; - return ret; - } - std::vector shape = {imageMat.rows * YUV444_RGB_WIDTH_NU, static_cast(imageMat.cols)}; - tensorBase = TensorBase(memoryDataDst, false, shape, TENSOR_DTYPE_UINT8); - return APP_ERR_OK; -} - -APP_ERROR XceptionClassify::Inference(const std::vector &inputs, std::vector &outputs) -{ - auto dtypes = model_->GetOutputDataType(); - for (size_t i = 0; i < modelDesc_.outputTensors.size(); ++i) { - std::vector shape = {}; - for (size_t j = 0; j < modelDesc_.outputTensors[i].tensorDims.size(); ++j) { - shape.push_back((uint32_t)modelDesc_.outputTensors[i].tensorDims[j]); - } - TensorBase tensor(shape, dtypes[i], MemoryData::MemoryType::MEMORY_DEVICE, deviceId_); - APP_ERROR ret = TensorBase::TensorBaseMalloc(tensor); - if (ret != APP_ERR_OK) { - LogError << "TensorBaseMalloc failed, ret=" << ret << "."; - return ret; - } - outputs.push_back(tensor); - } - DynamicInfo dynamicInfo = {}; - dynamicInfo.dynamicType = DynamicType::STATIC_BATCH; - auto startTime = std::chrono::high_resolution_clock::now(); // search for learning - APP_ERROR ret = model_->ModelInference(inputs, outputs, dynamicInfo); - auto endTime = std::chrono::high_resolution_clock::now(); - double costMs = std::chrono::duration(endTime - startTime).count(); - g_inferCost.push_back(costMs); - if (ret != APP_ERR_OK) { - LogError << "ModelInference failed, ret=" << ret << "."; - return ret; - } - return APP_ERR_OK; -} - -APP_ERROR XceptionClassify::PostProcess(const std::vector &inputs, std::vector> &clsInfos) -{ - - APP_ERROR ret = post_->Process(inputs, clsInfos); - - if (ret != APP_ERR_OK) { - LogError << "Process failed, ret=" << ret << "."; - return ret; - } - return APP_ERR_OK; -} - -APP_ERROR XceptionClassify::SaveInferResult(const std::string &imagePath, std::vector> &batchClsInfos) -{ - uint32_t batchIndex = 0; - LogInfo << "image path: " << imagePath; - std::string fileName = imagePath.substr(imagePath.find_last_of("/") + 1); - size_t dot = fileName.find_last_of("."); - - std::string resultPathName = "result"; - if (access(resultPathName.c_str(), 0) != 0) { - APP_ERROR ret = mkdir(resultPathName.c_str(), S_IRUSR | S_IWUSR | S_IXUSR); - if (ret != 0) { - LogError << "Failed to create result directory: " << resultPathName << ", ret = " << ret; - return APP_ERR_COMM_FAILURE; - } - } - std::string resFileName = "result/" + fileName.substr(0,dot) + "_1.txt"; - LogInfo << "file path for saving result: " << resFileName; - std::ofstream tfile(resFileName); - if (tfile.fail()) { - LogError << "Failed to open result file"; - return APP_ERR_COMM_FAILURE; - } - - for (auto clsInfos : batchClsInfos) { - std::string resultStr = ""; - for (auto clsInfo : clsInfos) { - LogDebug << "batchIndex: " << batchIndex << " className: " << clsInfo.className - << " confidence: " << clsInfo.confidence << " classIndex: " << clsInfo.classId; - resultStr += std::to_string(clsInfo.classId) + " "; - } - tfile << resultStr << std::endl; - batchIndex += 1; - } - tfile.close(); - return APP_ERR_OK; -} - -APP_ERROR XceptionClassify::Process(const std::string &imgPath) -{ - cv::Mat imageMat; - - ReadImage(imgPath, imageMat); - CenterCropImage(imageMat, imageMat); - Resize(imageMat, imageMat); - - std::vector inputs = {}; - std::vector outputs = {}; - TensorBase tensorBase; - - APP_ERROR ret = CVMatToTensorBase(imageMat, tensorBase); - if (ret != APP_ERR_OK) { - LogError << "CVMatToTensorBase failed, ret=" << ret << "."; - return ret; - } - - inputs.push_back(tensorBase); - - ret = Inference(inputs, outputs); - if (ret != APP_ERR_OK) { - LogError << "Inference failed, ret=" << ret << "."; - return ret; - } - - std::vector> BatchClsInfos = {}; - ret = PostProcess(outputs, BatchClsInfos); - if (ret != APP_ERR_OK) { - LogError << "PostProcess failed, ret=" << ret << "."; - return ret; - } - - ret = SaveInferResult(imgPath, BatchClsInfos); - if (ret != APP_ERR_OK) { - LogError << "Save results failed, ret: " << ret << "."; - return ret; - } - - imageMat.release(); - return APP_ERR_OK; -} - +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "XceptionClassify.h" +#include "MxBase/DeviceManager/DeviceManager.h" +#include "MxBase/Log/Log.h" + +using namespace MxBase; +namespace { +const uint32_t YUV_BYTE_NU = 3; +const uint32_t YUV_BYTE_DE = 2; +const uint32_t VPC_H_ALIGN = 2; +} + +APP_ERROR XceptionClassify::Init(const InitParam &initParam) +{ + deviceId_ = initParam.deviceId; + APP_ERROR ret = MxBase::DeviceManager::GetInstance()->InitDevices(); + if (ret != APP_ERR_OK) { + LogError << "Init devices failed, ret=" << ret << "."; + return ret; + } + ret = MxBase::TensorContext::GetInstance()->SetContext(initParam.deviceId); + if (ret != APP_ERR_OK) { + LogError << "Set context failed, ret=" << ret << "."; + return ret; + } + dvppWrapper_ = std::make_shared(); + ret = dvppWrapper_->Init(); + if (ret != APP_ERR_OK) { + LogError << "DvppWrapper init failed, ret=" << ret << "."; + return ret; + } + model_ = std::make_shared(); + ret = model_->Init(initParam.modelPath, modelDesc_); + if (ret != APP_ERR_OK) { + LogError << "ModelInferenceProcessor init failed, ret=" << ret << "."; + return ret; + } + MxBase::ConfigData configData; + const std::string softmax = initParam.softmax ? "true" : "false"; + const std::string checkTensor = initParam.checkTensor ? "true" : "false"; + + configData.SetJsonValue("CLASS_NUM", std::to_string(initParam.classNum)); + configData.SetJsonValue("TOP_K", std::to_string(initParam.topk)); + configData.SetJsonValue("SOFTMAX", softmax); + configData.SetJsonValue("CHECK_MODEL", checkTensor); + + auto jsonStr = configData.GetCfgJson().serialize(); + std::map> config; + config["postProcessConfigContent"] = std::make_shared(jsonStr); + config["labelPath"] = std::make_shared(initParam.labelPath); + + post_ = std::make_shared(); + ret = post_->Init(config); + if (ret != APP_ERR_OK) { + LogError << "Resnet50PostProcess init failed, ret=" << ret << "."; + return ret; + } + return APP_ERR_OK; +} + +APP_ERROR XceptionClassify::DeInit() +{ + dvppWrapper_->DeInit(); + model_->DeInit(); + post_->DeInit(); + MxBase::DeviceManager::GetInstance()->DestroyDevices(); + return APP_ERR_OK; +} + +void XceptionClassify::ReadImage(const std::string &imgPath, cv::Mat &imageMat) +{ + imageMat = cv::imread(imgPath, cv::IMREAD_COLOR); +} + +void XceptionClassify::CenterCropImage(cv::Mat &img, cv::Mat &cropImg) +{ + float central_fraction = 0.75; + int crop_x = img.cols * central_fraction; + int crop_y = img.rows * central_fraction; + int crop_x1 = (img.cols - crop_x) / 2; + int crop_y1 = (img.rows - crop_y) / 2; + + cv::Rect myROI(crop_x1, crop_y1, crop_x, crop_y); + LogInfo << "images crop_x1: " << crop_x1 << ", crop_x: " << crop_x << ", crop_y1: " << crop_y1 << ", crop_y: " << crop_y; + cropImg = img(myROI); +} + +void XceptionClassify::Resize(const cv::Mat &srcImageMat, cv::Mat &dstImageMat) +{ + static constexpr uint32_t resizeHeight = 299; + static constexpr uint32_t resizeWidth = 299; + + cv::resize(srcImageMat, dstImageMat, cv::Size(resizeWidth, resizeHeight)); +} + +APP_ERROR XceptionClassify::CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase) +{ + const uint32_t dataSize = imageMat.cols * imageMat.rows * YUV444_RGB_WIDTH_NU; + MemoryData memoryDataDst(dataSize, MemoryData::MEMORY_DEVICE, deviceId_); + MemoryData memoryDataSrc(imageMat.data, dataSize, MemoryData::MEMORY_HOST_MALLOC); + + APP_ERROR ret = MemoryHelper::MxbsMallocAndCopy(memoryDataDst, memoryDataSrc); + if (ret != APP_ERR_OK) { + LogError << GetError(ret) << "Memory malloc failed."; + return ret; + } + std::vector shape = {imageMat.rows * YUV444_RGB_WIDTH_NU, static_cast(imageMat.cols)}; + tensorBase = TensorBase(memoryDataDst, false, shape, TENSOR_DTYPE_UINT8); + return APP_ERR_OK; +} + +APP_ERROR XceptionClassify::Inference(const std::vector &inputs, std::vector &outputs) +{ + auto dtypes = model_->GetOutputDataType(); + for (size_t i = 0; i < modelDesc_.outputTensors.size(); ++i) { + std::vector shape = {}; + for (size_t j = 0; j < modelDesc_.outputTensors[i].tensorDims.size(); ++j) { + shape.push_back((uint32_t)modelDesc_.outputTensors[i].tensorDims[j]); + } + TensorBase tensor(shape, dtypes[i], MemoryData::MemoryType::MEMORY_DEVICE, deviceId_); + APP_ERROR ret = TensorBase::TensorBaseMalloc(tensor); + if (ret != APP_ERR_OK) { + LogError << "TensorBaseMalloc failed, ret=" << ret << "."; + return ret; + } + outputs.push_back(tensor); + } + DynamicInfo dynamicInfo = {}; + dynamicInfo.dynamicType = DynamicType::STATIC_BATCH; + auto startTime = std::chrono::high_resolution_clock::now(); // search for learning + APP_ERROR ret = model_->ModelInference(inputs, outputs, dynamicInfo); + auto endTime = std::chrono::high_resolution_clock::now(); + double costMs = std::chrono::duration(endTime - startTime).count(); + g_inferCost.push_back(costMs); + if (ret != APP_ERR_OK) { + LogError << "ModelInference failed, ret=" << ret << "."; + return ret; + } + return APP_ERR_OK; +} + +APP_ERROR XceptionClassify::PostProcess(const std::vector &inputs, std::vector> &clsInfos) +{ + + APP_ERROR ret = post_->Process(inputs, clsInfos); + + if (ret != APP_ERR_OK) { + LogError << "Process failed, ret=" << ret << "."; + return ret; + } + return APP_ERR_OK; +} + +APP_ERROR XceptionClassify::SaveInferResult(const std::string &imagePath, std::vector> &batchClsInfos) +{ + uint32_t batchIndex = 0; + LogInfo << "image path: " << imagePath; + std::string fileName = imagePath.substr(imagePath.find_last_of("/") + 1); + size_t dot = fileName.find_last_of("."); + + std::string resultPathName = "result"; + if (access(resultPathName.c_str(), 0) != 0) { + APP_ERROR ret = mkdir(resultPathName.c_str(), S_IRUSR | S_IWUSR | S_IXUSR); + if (ret != 0) { + LogError << "Failed to create result directory: " << resultPathName << ", ret = " << ret; + return APP_ERR_COMM_FAILURE; + } + } + std::string resFileName = "result/" + fileName.substr(0,dot) + "_1.txt"; + LogInfo << "file path for saving result: " << resFileName; + std::ofstream tfile(resFileName); + if (tfile.fail()) { + LogError << "Failed to open result file"; + return APP_ERR_COMM_FAILURE; + } + + for (auto clsInfos : batchClsInfos) { + std::string resultStr = ""; + for (auto clsInfo : clsInfos) { + LogDebug << "batchIndex: " << batchIndex << " className: " << clsInfo.className + << " confidence: " << clsInfo.confidence << " classIndex: " << clsInfo.classId; + resultStr += std::to_string(clsInfo.classId) + " "; + } + tfile << resultStr << std::endl; + batchIndex += 1; + } + tfile.close(); + return APP_ERR_OK; +} + +APP_ERROR XceptionClassify::Process(const std::string &imgPath) +{ + cv::Mat imageMat; + + ReadImage(imgPath, imageMat); + CenterCropImage(imageMat, imageMat); + Resize(imageMat, imageMat); + + std::vector inputs = {}; + std::vector outputs = {}; + TensorBase tensorBase; + + APP_ERROR ret = CVMatToTensorBase(imageMat, tensorBase); + if (ret != APP_ERR_OK) { + LogError << "CVMatToTensorBase failed, ret=" << ret << "."; + return ret; + } + + inputs.push_back(tensorBase); + + ret = Inference(inputs, outputs); + if (ret != APP_ERR_OK) { + LogError << "Inference failed, ret=" << ret << "."; + return ret; + } + + std::vector> BatchClsInfos = {}; + ret = PostProcess(outputs, BatchClsInfos); + if (ret != APP_ERR_OK) { + LogError << "PostProcess failed, ret=" << ret << "."; + return ret; + } + + ret = SaveInferResult(imgPath, BatchClsInfos); + if (ret != APP_ERR_OK) { + LogError << "Save results failed, ret: " << ret << "."; + return ret; + } + + imageMat.release(); + return APP_ERR_OK; +} + diff --git a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/XceptionClassify.h b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/XceptionClassify.h index 4a857b681301df4a354bd67990eb43a618fa9ee5..6d37dae3c6d43d296064958d51b5ce91f8f9205e 100644 --- a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/XceptionClassify.h +++ b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/XceptionClassify.h @@ -1,58 +1,58 @@ -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef MXBASE_XCEPTIONCLASSIFY_H -#define MXBASE_XCEPTIONCLASSIFY_H - -#include -#include "MxBase/DvppWrapper/DvppWrapper.h" -#include "MxBase/ModelInfer/ModelInferenceProcessor.h" -#include "ClassPostProcessors/Resnet50PostProcess.h" -#include "MxBase/Tensor/TensorContext/TensorContext.h" - -extern std::vector g_inferCost; - -struct InitParam { - uint32_t deviceId; - std::string labelPath; - uint32_t classNum; - uint32_t topk; - bool softmax; - bool checkTensor; - std::string modelPath; -}; - -class XceptionClassify { -public: - APP_ERROR Init(const InitParam &initParam); - APP_ERROR DeInit(); - void ReadImage(const std::string &imgPath, cv::Mat &imageMat); - void Resize(const cv::Mat &srcImageMat, cv::Mat &dstImageMat); - void CenterCropImage(cv::Mat &img, cv::Mat &cropImg); - APP_ERROR CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase); - APP_ERROR Inference(const std::vector &inputs, std::vector &outputs); - APP_ERROR PostProcess(const std::vector &inputs,std::vector> &clsInfos); - APP_ERROR SaveInferResult(const std::string &imgPath,std::vector> &batchClsInfos); - APP_ERROR Process(const std::string &imgPath); -private: - std::shared_ptr dvppWrapper_; - std::shared_ptr model_; - std::shared_ptr post_; - MxBase::ModelDesc modelDesc_; - uint32_t deviceId_ = 0; -}; -#endif +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef MXBASE_XCEPTIONCLASSIFY_H +#define MXBASE_XCEPTIONCLASSIFY_H + +#include +#include "MxBase/DvppWrapper/DvppWrapper.h" +#include "MxBase/ModelInfer/ModelInferenceProcessor.h" +#include "ClassPostProcessors/Resnet50PostProcess.h" +#include "MxBase/Tensor/TensorContext/TensorContext.h" + +extern std::vector g_inferCost; + +struct InitParam { + uint32_t deviceId; + std::string labelPath; + uint32_t classNum; + uint32_t topk; + bool softmax; + bool checkTensor; + std::string modelPath; +}; + +class XceptionClassify { +public: + APP_ERROR Init(const InitParam &initParam); + APP_ERROR DeInit(); + void ReadImage(const std::string &imgPath, cv::Mat &imageMat); + void Resize(const cv::Mat &srcImageMat, cv::Mat &dstImageMat); + void CenterCropImage(cv::Mat &img, cv::Mat &cropImg); + APP_ERROR CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase); + APP_ERROR Inference(const std::vector &inputs, std::vector &outputs); + APP_ERROR PostProcess(const std::vector &inputs,std::vector> &clsInfos); + APP_ERROR SaveInferResult(const std::string &imgPath,std::vector> &batchClsInfos); + APP_ERROR Process(const std::string &imgPath); +private: + std::shared_ptr dvppWrapper_; + std::shared_ptr model_; + std::shared_ptr post_; + MxBase::ModelDesc modelDesc_; + uint32_t deviceId_ = 0; +}; +#endif diff --git a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/main.cpp b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/main.cpp index 2f231330e235f09f3bc538d73de9ec648ddb69f1..b616fe29208fd1f8102acd56ce913401f63b8581 100644 --- a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/main.cpp +++ b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/mxbase/main.cpp @@ -1,69 +1,69 @@ -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include "XceptionClassify.h" -#include "MxBase/Log/Log.h" - -namespace fs = std::experimental::filesystem; -namespace { -const uint32_t CLASS_NUM = 1000; -} -std::vector g_inferCost; - -int main(int argc, char* argv[]) -{ - if (argc <= 1) { - LogWarn << "Please input image path, such as './build/xception ./image_dir'."; - return APP_ERR_OK; - } - - InitParam initParam = {}; - initParam.deviceId = 0; - initParam.classNum = CLASS_NUM; - initParam.labelPath = "../sdk/models/imagenet1000_clsidx_to_labels.names"; - initParam.topk = 5; - initParam.softmax = true; - initParam.checkTensor = true; - initParam.modelPath = "../sdk/models/xception_pt_pytorch.om"; - auto xception = std::make_shared(); - APP_ERROR ret = xception->Init(initParam); - if (ret != APP_ERR_OK) { - LogError << "XceptionClassify init failed, ret=" << ret << "."; - return ret; - } - - std::string imgDir = argv[1]; - for (auto & entry : fs::directory_iterator(imgDir)) { - LogInfo << "read image path " << entry.path(); - ret = xception->Process(entry.path()); - if (ret != APP_ERR_OK) { - LogError << "XceptionClassify process failed, ret=" << ret << "."; - xception->DeInit(); - return ret; - } - } - xception->DeInit(); - double costSum = 0; - for (unsigned int i = 0; i < g_inferCost.size(); i++) { - costSum += g_inferCost[i]; - } - LogInfo << "Infer images sum " << g_inferCost.size() << ", cost total time: " << costSum << " ms."; - LogInfo << "The throughput: " << g_inferCost.size() * 1000 / costSum << " images/sec."; - return APP_ERR_OK; -} +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "XceptionClassify.h" +#include "MxBase/Log/Log.h" + +namespace fs = std::experimental::filesystem; +namespace { +const uint32_t CLASS_NUM = 1000; +} +std::vector g_inferCost; + +int main(int argc, char* argv[]) +{ + if (argc <= 1) { + LogWarn << "Please input image path, such as './build/xception ./image_dir'."; + return APP_ERR_OK; + } + + InitParam initParam = {}; + initParam.deviceId = 0; + initParam.classNum = CLASS_NUM; + initParam.labelPath = "../sdk/models/imagenet1000_clsidx_to_labels.names"; + initParam.topk = 5; + initParam.softmax = true; + initParam.checkTensor = true; + initParam.modelPath = "../sdk/models/xception_pt_pytorch.om"; + auto xception = std::make_shared(); + APP_ERROR ret = xception->Init(initParam); + if (ret != APP_ERR_OK) { + LogError << "XceptionClassify init failed, ret=" << ret << "."; + return ret; + } + + std::string imgDir = argv[1]; + for (auto & entry : fs::directory_iterator(imgDir)) { + LogInfo << "read image path " << entry.path(); + ret = xception->Process(entry.path()); + if (ret != APP_ERR_OK) { + LogError << "XceptionClassify process failed, ret=" << ret << "."; + xception->DeInit(); + return ret; + } + } + xception->DeInit(); + double costSum = 0; + for (unsigned int i = 0; i < g_inferCost.size(); i++) { + costSum += g_inferCost[i]; + } + LogInfo << "Infer images sum " << g_inferCost.size() << ", cost total time: " << costSum << " ms."; + LogInfo << "The throughput: " << g_inferCost.size() * 1000 / costSum << " images/sec."; + return APP_ERR_OK; +} diff --git a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/sdk/main_xception_opencv.py b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/sdk/main_xception_opencv.py index 7b970e106cc8b5331232b049a18d68342a83b337..3f88491da4540d39c321b57e64e5730b89e54040 100644 --- a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/sdk/main_xception_opencv.py +++ b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/sdk/main_xception_opencv.py @@ -1,95 +1,95 @@ -# Copyright 2021 Huawei Technologies Co., Ltd. - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from StreamManagerApi import StreamManagerApi, MxDataInput -import os -import cv2 -import json -import numpy as np -import MxpiDataType_pb2 as MxpiDataType -import datetime -import sys - -def run(): - # init stream manager - stream_manager_api = StreamManagerApi() - ret = stream_manager_api.InitManager() - if ret != 0: - print("Failed to init Stream manager, ret=%s" % str(ret)) - return - - # create streams by pipeline config file - with open("./pipeline/xception_opencv.pipeline", 'rb') as f: - pipeline_str = f.read() - ret = stream_manager_api.CreateMultipleStreams(pipeline_str) - - if ret != 0: - print("Failed to create Stream, ret=%s" % str(ret)) - return - - # Construct the input of the stream - data_input = MxDataInput() - - dir_name = './val_union/' - res_dir_name = 'xception_npu_result' - - file_list = os.listdir(dir_name) - if not os.path.exists(res_dir_name): - os.makedirs(res_dir_name) - for file_name in file_list: - print(file_name) - file_path = os.path.join(dir_name, file_name) - if not file_name.lower().endswith((".JPEG", ".jpeg", "JPG", "jpg")): - continue - portion = os.path.splitext(file_name) - with open(file_path, 'rb') as f: - data_input.data = f.read() - - empty_data = [] - - stream_name = b'im_xception' - in_plugin_id = 0 - uniqueId = stream_manager_api.SendData(stream_name, in_plugin_id, data_input) - if uniqueId < 0: - print("Failed to send data to stream.") - exit() - # Obtain the inference result by specifying stream_name and uniqueId. - start_time = datetime.datetime.now() - infer_result = stream_manager_api.GetResult(stream_name, uniqueId) - end_time = datetime.datetime.now() - print('sdk run time: {}'.format((end_time - start_time).microseconds)) - if infer_result.errorCode != 0: - print("GetResultWithUniqueId error. errorCode=%d, errorMsg=%s" % ( - infer_result.errorCode, infer_result.data.decode())) - exit() - # print the infer result - print(infer_result.data.decode()) - - load_dict = json.loads(infer_result.data.decode()) - if load_dict.get('MxpiClass') is None: - with open(res_dir_name + "/" + file_name[:-5] + '.txt', 'w') as f_write: - f_write.write("") - continue - res_vec = load_dict['MxpiClass'] - - with open(res_dir_name + "/" + file_name[:-5] + '_1.txt', 'w') as f_write: - list1 = [str(item.get("classId")) + " " for item in res_vec] - f_write.writelines(list1) - f_write.write('\n') - - # destroy streams - stream_manager_api.DestroyAllStreams() - -if __name__ == '__main__': - run() +# Copyright 2021 Huawei Technologies Co., Ltd. + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from StreamManagerApi import StreamManagerApi, MxDataInput +import os +import cv2 +import json +import numpy as np +import MxpiDataType_pb2 as MxpiDataType +import datetime +import sys + +def run(): + # init stream manager + stream_manager_api = StreamManagerApi() + ret = stream_manager_api.InitManager() + if ret != 0: + print("Failed to init Stream manager, ret=%s" % str(ret)) + return + + # create streams by pipeline config file + with open("./pipeline/xception_opencv.pipeline", 'rb') as f: + pipeline_str = f.read() + ret = stream_manager_api.CreateMultipleStreams(pipeline_str) + + if ret != 0: + print("Failed to create Stream, ret=%s" % str(ret)) + return + + # Construct the input of the stream + data_input = MxDataInput() + + dir_name = './val_union/' + res_dir_name = 'xception_npu_result' + + file_list = os.listdir(dir_name) + if not os.path.exists(res_dir_name): + os.makedirs(res_dir_name) + for file_name in file_list: + print(file_name) + file_path = os.path.join(dir_name, file_name) + if not file_name.lower().endswith((".JPEG", ".jpeg", "JPG", "jpg")): + continue + portion = os.path.splitext(file_name) + with open(file_path, 'rb') as f: + data_input.data = f.read() + + empty_data = [] + + stream_name = b'im_xception' + in_plugin_id = 0 + uniqueId = stream_manager_api.SendData(stream_name, in_plugin_id, data_input) + if uniqueId < 0: + print("Failed to send data to stream.") + exit() + # Obtain the inference result by specifying stream_name and uniqueId. + start_time = datetime.datetime.now() + infer_result = stream_manager_api.GetResult(stream_name, uniqueId) + end_time = datetime.datetime.now() + print('sdk run time: {}'.format((end_time - start_time).microseconds)) + if infer_result.errorCode != 0: + print("GetResultWithUniqueId error. errorCode=%d, errorMsg=%s" % ( + infer_result.errorCode, infer_result.data.decode())) + exit() + # print the infer result + print(infer_result.data.decode()) + + load_dict = json.loads(infer_result.data.decode()) + if load_dict.get('MxpiClass') is None: + with open(res_dir_name + "/" + file_name[:-5] + '.txt', 'w') as f_write: + f_write.write("") + continue + res_vec = load_dict['MxpiClass'] + + with open(res_dir_name + "/" + file_name[:-5] + '_1.txt', 'w') as f_write: + list1 = [str(item.get("classId")) + " " for item in res_vec] + f_write.writelines(list1) + f_write.write('\n') + + # destroy streams + stream_manager_api.DestroyAllStreams() + +if __name__ == '__main__': + run() diff --git a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/sdk/pipeline/xception_opencv.pipeline b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/sdk/pipeline/xception_opencv.pipeline index 2944e83d0252d21f6b14a68488cab850de492d1f..e89cf88bc0520b39bb97a1f52c86741d8eac59bb 100644 --- a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/sdk/pipeline/xception_opencv.pipeline +++ b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/sdk/pipeline/xception_opencv.pipeline @@ -1,73 +1,73 @@ -{ - "im_xception": { - "stream_config": { - "deviceId": "0" - }, - "appsrc1": { - "props": { - "blocksize": "409600" - }, - "factory": "appsrc", - "next": "mxpi_imagedecoder0" - }, - "mxpi_imagedecoder0": { - "props": { - "handleMethod": "opencv" - }, - "factory": "mxpi_imagedecoder", - "next": "mxpi_imageresize0" - }, - "mxpi_imageresize0": { - "props": { - "handleMethod": "opencv", - "resizeType": "Resizer_Stretch", - "resizeHeight": "355", - "resizeWidth": "355" - }, - "factory": "mxpi_imageresize", - "next": "mxpi_opencvcentercrop0" - }, - "mxpi_opencvcentercrop0": { - "props": { - "dataSource": "mxpi_imageresize0", - "cropHeight": "299", - "cropWidth": "299" - }, - "factory": "mxpi_opencvcentercrop", - "next": "mxpi_tensorinfer0" - }, - "mxpi_tensorinfer0": { - "props": { - "dataSource": "mxpi_opencvcentercrop0", - "modelPath": "../models/xception_pt_pytorch.om", - "waitingTime": "2000", - "outputDeviceId": "-1" - }, - "factory": "mxpi_tensorinfer", - "next": "mxpi_classpostprocessor0" - }, - "mxpi_classpostprocessor0": { - "props": { - "dataSource": "mxpi_tensorinfer0", - "postProcessConfigPath": "../models/xception_aipp.cfg", - "labelPath": "../models/imagenet1000_clsidx_to_labels.names", - "postProcessLibPath": "/usr/local/sdk_home/mxManufacture/lib/modelpostprocessors/libresnet50postprocess.so" - }, - "factory": "mxpi_classpostprocessor", - "next": "mxpi_dataserialize0" - }, - "mxpi_dataserialize0": { - "props": { - "outputDataKeys": "mxpi_classpostprocessor0" - }, - "factory": "mxpi_dataserialize", - "next": "appsink0" - }, - "appsink0": { - "props": { - "blocksize": "4096000" - }, - "factory": "appsink" - } - } -} +{ + "im_xception": { + "stream_config": { + "deviceId": "0" + }, + "appsrc1": { + "props": { + "blocksize": "409600" + }, + "factory": "appsrc", + "next": "mxpi_imagedecoder0" + }, + "mxpi_imagedecoder0": { + "props": { + "handleMethod": "opencv" + }, + "factory": "mxpi_imagedecoder", + "next": "mxpi_imageresize0" + }, + "mxpi_imageresize0": { + "props": { + "handleMethod": "opencv", + "resizeType": "Resizer_Stretch", + "resizeHeight": "355", + "resizeWidth": "355" + }, + "factory": "mxpi_imageresize", + "next": "mxpi_opencvcentercrop0" + }, + "mxpi_opencvcentercrop0": { + "props": { + "dataSource": "mxpi_imageresize0", + "cropHeight": "299", + "cropWidth": "299" + }, + "factory": "mxpi_opencvcentercrop", + "next": "mxpi_tensorinfer0" + }, + "mxpi_tensorinfer0": { + "props": { + "dataSource": "mxpi_opencvcentercrop0", + "modelPath": "../models/xception_pt_pytorch.om", + "waitingTime": "2000", + "outputDeviceId": "-1" + }, + "factory": "mxpi_tensorinfer", + "next": "mxpi_classpostprocessor0" + }, + "mxpi_classpostprocessor0": { + "props": { + "dataSource": "mxpi_tensorinfer0", + "postProcessConfigPath": "../models/xception_aipp.cfg", + "labelPath": "../models/imagenet1000_clsidx_to_labels.names", + "postProcessLibPath": "/usr/local/sdk_home/mxManufacture/lib/modelpostprocessors/libresnet50postprocess.so" + }, + "factory": "mxpi_classpostprocessor", + "next": "mxpi_dataserialize0" + }, + "mxpi_dataserialize0": { + "props": { + "outputDataKeys": "mxpi_classpostprocessor0" + }, + "factory": "mxpi_dataserialize", + "next": "appsink0" + }, + "appsink0": { + "props": { + "blocksize": "4096000" + }, + "factory": "appsink" + } + } +} diff --git a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/utils/classification_task_metric.py b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/utils/classification_task_metric.py index 127542b272ad16eea79b90f39a370e0ad6000913..a12fd3a1c12d76850cbca6a5486f40590a441b34 100644 --- a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/utils/classification_task_metric.py +++ b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/infer/utils/classification_task_metric.py @@ -1,162 +1,162 @@ -# coding=utf-8 -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import json -import os -import sys - -import numpy as np - -np.set_printoptions(threshold=sys.maxsize) - -LABEL_FILE = "HiAI_label.json" - - -def cre_groundtruth_dict(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - for gtfile in os.listdir(gtfile_path): - if gtfile != LABEL_FILE: - with open(os.path.join(gtfile_path, gtfile), 'r') as f: - gt = json.load(f) - image_name = os.path.splitext(gtfile.split('/')[-1]) - img_gt_dict[image_name] = gt["image"]["annotations"][0]["category_id"] - return img_gt_dict - - -def cre_groundtruth_dict_fromtxt(gtfile_path): - """ - :param filename: file contains the imagename and label number - :return: dictionary key imagename, value is label number - """ - img_gt_dict = {} - with open(gtfile_path, 'r')as f: - for line in f.readlines(): - image_line_info = line.strip().split(" ") - img_name = image_line_info[0].split(".")[0] - img_gt_dict[img_name] = image_line_info[1] - return img_gt_dict - - -def load_statistical_predict_result(filepath): - """ - function: - the prediction esult file data extraction - input: - result file:filepath - output: - n_label:numble of label - data_vec: the probabilitie of prediction in the 1000 - :return: probabilities, numble of label - """ - with open(filepath, 'r')as f: - label_info = f.readline().strip().split(" ") - data_vec = np.zeros((len(label_info)), dtype=np.float32) - n_label = len(label_info) - if n_label == 0: - in_type = f.readline() - color = f.readline() - else: - for ind, cls_ind in enumerate(label_info): - data_vec[ind] = np.int(cls_ind) - return data_vec, n_label - - -def create_visualization_statistical_result(prediction_file_path, - result_store_path, json_file_name, - img_gt_dict, topn=5): - """ - :param prediction_file_path: - :param result_store_path: - :param json_file_name: - :param img_gt_dict: - :param topn: - :return: - """ - writer = open(os.path.join(result_store_path, json_file_name), 'w') - table_dict = {} - table_dict["title"] = "Overall statistical evaluation" - table_dict["value"] = [] - - count = 0 - res_cnt = 0 - n_labels = "" - count_hit = np.zeros(topn) - for tfile_name in os.listdir(prediction_file_path): - count += 1 - temp = tfile_name.split('.')[0] - index = temp.rfind('_') - img_name = temp[:index] - filepath = os.path.join(prediction_file_path, tfile_name) - prediction, n_labels = load_statistical_predict_result(filepath) - - if n_labels == 1001: - real_label = int(img_gt_dict[img_name]) + 1 - else: - real_label = int(img_gt_dict[img_name]) - - res_cnt = min(len(prediction), topn) - for i in range(res_cnt): - if real_label == int(prediction[i]): - count_hit[i] += 1 - break - if 'value' not in table_dict.keys(): - print("the item value does not exist!") - else: - table_dict["value"].extend( - [{"key": "Number of images", "value": str(count)}, - {"key": "Number of classes", "value": str(n_labels)}]) - accuracy = np.cumsum(count_hit) / count if count else 0 - for i in range(res_cnt): - table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", - "value": str( - round(accuracy[i] * 100, 2)) + '%'}) - json.dump(table_dict, writer) - writer.close() - - -if __name__ == '__main__': - if len(sys.argv) == 5: - # txt file path - folder_davinci_target = sys.argv[1] - # annotation files path, "val_label.txt" - annotation_file_path = sys.argv[2] - # the path to store the results json path - result_json_path = sys.argv[3] - # result json file name - json_file_name = sys.argv[4] - else: - print("Please enter target file result folder | ground truth label file | result json file folder | " - "result json file name, such as ./result val_label.txt . result.json") - exit(1) - - if not os.path.exists(folder_davinci_target): - print("Target file folder does not exist.") - - if not os.path.exists(annotation_file_path): - print("Ground truth file does not exist.") - - if not os.path.exists(result_json_path): - print("Result folder doesn't exist.") - - img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) - create_visualization_statistical_result(folder_davinci_target, - result_json_path, json_file_name, - img_label_dict, topn=5) - +# coding=utf-8 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import json +import os +import sys + +import numpy as np + +np.set_printoptions(threshold=sys.maxsize) + +LABEL_FILE = "HiAI_label.json" + + +def cre_groundtruth_dict(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + for gtfile in os.listdir(gtfile_path): + if gtfile != LABEL_FILE: + with open(os.path.join(gtfile_path, gtfile), 'r') as f: + gt = json.load(f) + image_name = os.path.splitext(gtfile.split('/')[-1]) + img_gt_dict[image_name] = gt["image"]["annotations"][0]["category_id"] + return img_gt_dict + + +def cre_groundtruth_dict_fromtxt(gtfile_path): + """ + :param filename: file contains the imagename and label number + :return: dictionary key imagename, value is label number + """ + img_gt_dict = {} + with open(gtfile_path, 'r')as f: + for line in f.readlines(): + image_line_info = line.strip().split(" ") + img_name = image_line_info[0].split(".")[0] + img_gt_dict[img_name] = image_line_info[1] + return img_gt_dict + + +def load_statistical_predict_result(filepath): + """ + function: + the prediction esult file data extraction + input: + result file:filepath + output: + n_label:numble of label + data_vec: the probabilitie of prediction in the 1000 + :return: probabilities, numble of label + """ + with open(filepath, 'r')as f: + label_info = f.readline().strip().split(" ") + data_vec = np.zeros((len(label_info)), dtype=np.float32) + n_label = len(label_info) + if n_label == 0: + in_type = f.readline() + color = f.readline() + else: + for ind, cls_ind in enumerate(label_info): + data_vec[ind] = np.int(cls_ind) + return data_vec, n_label + + +def create_visualization_statistical_result(prediction_file_path, + result_store_path, json_file_name, + img_gt_dict, topn=5): + """ + :param prediction_file_path: + :param result_store_path: + :param json_file_name: + :param img_gt_dict: + :param topn: + :return: + """ + writer = open(os.path.join(result_store_path, json_file_name), 'w') + table_dict = {} + table_dict["title"] = "Overall statistical evaluation" + table_dict["value"] = [] + + count = 0 + res_cnt = 0 + n_labels = "" + count_hit = np.zeros(topn) + for tfile_name in os.listdir(prediction_file_path): + count += 1 + temp = tfile_name.split('.')[0] + index = temp.rfind('_') + img_name = temp[:index] + filepath = os.path.join(prediction_file_path, tfile_name) + prediction, n_labels = load_statistical_predict_result(filepath) + + if n_labels == 1001: + real_label = int(img_gt_dict[img_name]) + 1 + else: + real_label = int(img_gt_dict[img_name]) + + res_cnt = min(len(prediction), topn) + for i in range(res_cnt): + if real_label == int(prediction[i]): + count_hit[i] += 1 + break + if 'value' not in table_dict.keys(): + print("the item value does not exist!") + else: + table_dict["value"].extend( + [{"key": "Number of images", "value": str(count)}, + {"key": "Number of classes", "value": str(n_labels)}]) + accuracy = np.cumsum(count_hit) / count if count else 0 + for i in range(res_cnt): + table_dict["value"].append({"key": "Top" + str(i + 1) + " accuracy", + "value": str( + round(accuracy[i] * 100, 2)) + '%'}) + json.dump(table_dict, writer) + writer.close() + + +if __name__ == '__main__': + if len(sys.argv) == 5: + # txt file path + folder_davinci_target = sys.argv[1] + # annotation files path, "val_label.txt" + annotation_file_path = sys.argv[2] + # the path to store the results json path + result_json_path = sys.argv[3] + # result json file name + json_file_name = sys.argv[4] + else: + print("Please enter target file result folder | ground truth label file | result json file folder | " + "result json file name, such as ./result val_label.txt . result.json") + exit(1) + + if not os.path.exists(folder_davinci_target): + print("Target file folder does not exist.") + + if not os.path.exists(annotation_file_path): + print("Ground truth file does not exist.") + + if not os.path.exists(result_json_path): + print("Result folder doesn't exist.") + + img_label_dict = cre_groundtruth_dict_fromtxt(annotation_file_path) + create_visualization_statistical_result(folder_davinci_target, + result_json_path, json_file_name, + img_label_dict, topn=5) + diff --git a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/modelarts/train_start_xception.py b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/modelarts/train_start_xception.py index 9da0dbeec19a9f790d737f1c5bacbd593bb9cf96..3bac77ecee403b7a51e58a4de725dde59838ff8e 100644 --- a/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/modelarts/train_start_xception.py +++ b/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch/modelarts/train_start_xception.py @@ -1,596 +1,596 @@ -# Copyright (c) 2021, -# All rights reserved. -# -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import os -import glob -import random -import shutil -import sys -import time -import warnings - -import torch -import numpy as np -from apex import amp - -import torch.nn as nn -import torch.nn.parallel -import torch.backends.cudnn as cudnn -import torch.distributed as dist -import torch.optim -import torch.multiprocessing as mp -import torch.utils.data -import torch.utils.data.distributed -import torchvision.transforms as transforms -import torchvision.datasets as datasets -import torchvision.models as models - -sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../')) -from pthtar2onx import convert -from xception import xception -import moxing as mox - -model_names = sorted(name for name in models.__dict__ - if name.islower() and not name.startswith("__") - and callable(models.__dict__[name])) - -parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') -parser.add_argument('--data_url', metavar='DIR', default='/cache/data_url', - help='path to dataset') -parser.add_argument('-a', '--arch', - metavar='ARCH', - default='xception', - choices=model_names, - help='model architecture: ' + - ' | '.join(model_names) + - ' (default: xception)') -parser.add_argument('-j', '--workers', default=4, type=int, metavar='N', - help='number of data loading workers (default: 4)') -parser.add_argument('--epochs', default=3, type=int, metavar='N', - help='number of total epochs to run') -parser.add_argument('--start-epoch', default=0, type=int, metavar='N', - help='manual epoch number (useful on restarts)') -parser.add_argument('-b', '--batch-size', default=64, type=int, - metavar='N', - help='mini-batch size (default: 256), this is the total ' - 'batch size of all GPUs on the current node when ' - 'using Data Parallel or Distributed Data Parallel') -parser.add_argument('--lr', '--learning-rate', default=0.1, type=float, - metavar='LR', help='initial learning rate', dest='lr') -parser.add_argument('--momentum', default=0.9, type=float, metavar='M', - help='momentum') -parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, - metavar='W', help='weight decay (default: 1e-4)', - dest='weight_decay') -parser.add_argument('-p', '--print-freq', default=10, type=int, - metavar='N', help='print frequency (default: 10)') -parser.add_argument('--resume', default='', type=str, metavar='PATH', - help='path to latest checkpoint (default: none)') -parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', - help='evaluate model on validation set') -parser.add_argument('--pretrained', dest='pretrained', action='store_true', - help='use pre-trained model') -parser.add_argument('--pretrained_weight', default='', type=str, metavar='PATH', - help='path to pretrained weight') -parser.add_argument('--world-size', default=-1, type=int, - help='number of nodes for distributed training') -parser.add_argument('--rank', default=-1, type=int, - help='node rank for distributed training') -parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str, - help='url used to set up distributed training') -parser.add_argument('--dist-backend', default='nccl', type=str, - help='distributed backend') -parser.add_argument('--seed', default=None, type=int, - help='seed for initializing training. ') -parser.add_argument('--gpu', default=None, type=int, - help='GPU id to use.') -parser.add_argument('--multiprocessing-distributed', action='store_true', - help='Use multi-processing distributed training to launch ' - 'N processes per node, which has N GPUs. This is the ' - 'fastest way to use PyTorch for either single node or ' - 'multi node data parallel training') -parser.add_argument('--npu', default=0, type=int, - help='NPU id to use.') -parser.add_argument('--addr', default='10.136.181.115', - type=str, help='master addr') -parser.add_argument('--device_list', default='0,1,2,3,4,5,6,7', - type=str, help='device id list') -parser.add_argument('--warm_up_epochs', default=0, type=int, - help='warm up') -parser.add_argument('--amp', default=False, action='store_true', - help='use amp to train the model') -parser.add_argument('--loss-scale', default=1024., type=float, - help='loss scale using in amp, default -1 means dynamic') -parser.add_argument('--opt-level', default='O2', type=str, - help='loss scale using in amp, default -1 means dynamic') -parser.add_argument('--prof', default=False, action='store_true', - help='use profiling to evaluate the performance of model') -parser.add_argument('--label-smoothing', - default=0.0, - type=float, - metavar='S', - help='label smoothing') -parser.add_argument('--train_url', - default="/cache/training", - type=str, - help="setting dir of training output") -parser.add_argument('--onnx', default=True, action='store_true', - help="convert pth model to onnx") - -best_acc1 = 0 -CACHE_TRAINING_URL = "/cache/training" - -def main(): - args = parser.parse_args() - print(args.device_list) - - os.environ['MASTER_ADDR'] = args.addr - os.environ['MASTER_PORT'] = '29688' - - if args.npu is None: - args.npu = 0 - global CALCULATE_DEVICE - global best_acc1 - - #-----modelarts modification----------------- - CALCULATE_DEVICE = "npu:{}".format(args.npu) - #-----modelarts modification----------------- - torch.npu.set_device(CALCULATE_DEVICE) - - if args.seed is not None: - random.seed(args.seed) - torch.manual_seed(args.seed) - cudnn.deterministic = True - warnings.warn('You have chosen to seed training. ' - 'This will turn on the CUDNN deterministic setting, ' - 'which can slow down your training considerably! ' - 'You may see unexpected behavior when restarting ' - 'from checkpoints.') - - if args.gpu is not None: - warnings.warn('You have chosen a specific GPU. This will completely ' - 'disable data parallelism.') - - if args.dist_url == "env://" and args.world_size == -1: - args.world_size = int(os.environ["WORLD_SIZE"]) - - args.distributed = args.world_size > 1 or args.multiprocessing_distributed - - ngpus_per_node = torch.npu.device_count() - - print('ngpus_per_node:',ngpus_per_node) - - - if args.multiprocessing_distributed: - # Since we have ngpus_per_node processes per node, the total world_size - # needs to be adjusted accordingly - args.world_size = ngpus_per_node * args.world_size - # Use torch.multiprocessing.spawn to launch distributed processes: the - # main_worker process function - mp.spawn(main_worker, nprocs=ngpus_per_node, - args=(ngpus_per_node, args)) - else: - # Simply call main_worker function - main_worker(args.gpu, ngpus_per_node, args) - - -def main_worker(gpu, ngpus_per_node, args): - global best_acc1 - args.gpu = gpu - - if args.gpu is not None: - print("Use NPU: {} for training".format(args.gpu)) - - if args.distributed: - if args.dist_url == "env://" and args.rank == -1: - args.rank = int(os.environ["RANK"]) - if args.multiprocessing_distributed: - # For multiprocessing distributed training, rank needs to be the - # global rank among all the processes - args.rank = args.rank * ngpus_per_node + gpu - - dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - # create model - if args.pretrained: - print("=> using pre-trained model '{}'".format(args.arch)) - model = xception() - CACHE_MODEL_URL = "/cache/model" - # ------------------modelarts modification---------------------- - os.makedirs(CACHE_MODEL_URL, exist_ok=True) - mox.file.copy_parallel(args.pretrained_weight, os.path.join(CACHE_MODEL_URL, "checkpoint.pth.tar")) - # ------------------modelarts modification--------------------- - pretrained_weight = os.path.join(CACHE_MODEL_URL, "checkpoint.pth.tar") - pretrained_dict = torch.load(pretrained_weight, map_location="cpu")["state_dict"] - if "fc.weight" in pretrained_dict: - pretrained_dict.pop("fc.weight") - pretrained_dict.pop("fc.bias") - - model.load_state_dict(pretrained_dict, strict=False) - - else: - print("=> creating model '{}'".format(args.arch)) - model = xception() - - if args.distributed: - # For multiprocessing distributed, DistributedDataParallel constructor - # should always set the single device scope, otherwise, - # DistributedDataParallel will use all available devices. - if args.gpu is not None: - torch.cuda.set_device(args.gpu) - model.cuda(args.gpu) - - # When using a single GPU per process and per - # DistributedDataParallel, we need to divide the batch size - # ourselves based on the total number of GPUs we have - args.batch_size = int(args.batch_size / args.world_size) - args.workers = int((args.workers + ngpus_per_node - 1) / ngpus_per_node) - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu]) - else: - model.cuda() - # DistributedDataParallel will divide and allocate batch_size to all - # available GPUs if device_ids are not set - model = torch.nn.parallel.DistributedDataParallel(model) - elif args.gpu is not None: - torch.cuda.set_device(args.gpu) - model = model.cuda(args.gpu) - - else: - model = model.to(CALCULATE_DEVICE) - - # define loss function (criterion) and optimizer - criterion = nn.CrossEntropyLoss().to(CALCULATE_DEVICE) - - optimizer = torch.optim.SGD(model.parameters(), args.lr, - momentum=args.momentum, - weight_decay=args.weight_decay) - - if args.amp: - model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, loss_scale=args.loss_scale) - - # optionally resume from a checkpoint - if args.resume : - if os.path.isfile(args.resume): - print("=> loading checkpoint '{}'".format(args.resume)) - checkpoint = torch.load(args.resume, map_location=CALCULATE_DEVICE) - args.start_epoch = checkpoint['epoch'] - best_acc1 = checkpoint['best_acc1'] - model.load_state_dict(checkpoint['state_dict']) - optimizer.load_state_dict(checkpoint['optimizer']) - if args.amp: - amp.load_state_dict(checkpoint['amp']) - print("=> loaded checkpoint '{}' (epoch {})" - .format(args.resume, checkpoint['epoch'])) - else: - print("=> no checkpoint found at '{}'".format(args.resume)) - - cudnn.benchmark = True - - # -------modelarts modification------- - real_path = '/cache/data_url' - if not os.path.exists(real_path): - os.makedirs(real_path) - mox.file.copy_parallel(args.data_url, real_path) - print("training data finish copy to %s." % real_path) - # ---------modelarts modification----- - - # Data loading code - traindir = os.path.join(real_path, 'train') - valdir = os.path.join(real_path, 'val') - normalize = transforms.Normalize(mean=[0.5, 0.5, 0.5], - std=[0.5, 0.5, 0.5]) - - train_dataset = datasets.ImageFolder( - traindir, - transforms.Compose([ - transforms.RandomResizedCrop(299), - transforms.RandomHorizontalFlip(), - transforms.ToTensor(), - normalize, - ])) - - if args.distributed: - train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) - else: - train_sampler = None - - train_loader = torch.utils.data.DataLoader( - train_dataset, batch_size=args.batch_size, shuffle=(train_sampler is None), - num_workers=args.workers, pin_memory=False, sampler=train_sampler, drop_last=True) - - val_loader = torch.utils.data.DataLoader( - datasets.ImageFolder(valdir, transforms.Compose([ - transforms.Resize(342), - transforms.CenterCrop(299), - transforms.ToTensor(), - normalize, - ])), - batch_size=args.batch_size, shuffle=True, - num_workers=args.workers, pin_memory=False, drop_last=True) - - if args.evaluate: - validate(val_loader, model, criterion, args) - return - - start_time = time.time() - for epoch in range(args.start_epoch, args.epochs): - if args.distributed: - train_sampler.set_epoch(epoch) - - adjust_learning_rate(optimizer, epoch, args) - - # train for one epoch - train(train_loader, model, criterion, optimizer, epoch, args) - - # evaluate on validation set - acc1 = validate(val_loader, model, criterion, args) - - # remember best acc@1 and save checkpoint - is_best = acc1 > best_acc1 - best_acc1 = max(acc1, best_acc1) - - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - if args.amp: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': args.arch, - 'state_dict': model.state_dict(), - 'best_acc1': best_acc1, - 'optimizer': optimizer.state_dict(), - 'amp': amp.state_dict(), - }, is_best) - else: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': args.arch, - 'state_dict': model.state_dict(), - 'best_acc1': best_acc1, - 'optimizer': optimizer.state_dict(), - }, is_best) - - if args.onnx: - convert_pth_to_onnx(args) - - # --------------modelarts modification---------- - mox.file.copy_parallel(CACHE_TRAINING_URL, args.train_url) - # --------------modelarts modification end---------- - -def convert_pth_to_onnx(config_args): - pth_pattern = os.path.join(CACHE_TRAINING_URL, 'checkpoint.pth.tar') - pth_file_list = glob.glob(pth_pattern) - if not pth_file_list: - print(f"can't find pth {pth_pattern}") - return - pth_file = pth_file_list[0] - onnx_path = pth_file.split(".")[0] + '.onnx' - convert(pth_file, onnx_path) - -def train(train_loader, model, criterion, optimizer, epoch, args): - batch_time = AverageMeter('Time', ':6.3f') - data_time = AverageMeter('Data', ':6.3f') - losses = AverageMeter('Loss', ':.4e') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - progress = ProgressMeter( - len(train_loader), - [batch_time, data_time, losses, top1, top5], - prefix="Epoch: [{}]".format(epoch)) - - # switch to train mode - model.train() - - end = time.time() - for i, (images, target) in enumerate(train_loader): - # measure data loading time - data_time.update(time.time() - end) - - images = images.to(CALCULATE_DEVICE, non_blocking=False).to(torch.float) - target = target.to(torch.int32).to(CALCULATE_DEVICE, non_blocking=False) - - # compute output - output = model(images) - loss = criterion(output, target) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # compute gradient and do SGD step - optimizer.zero_grad() - if args.amp: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - - # torch.npu.synchronize() - - # measure elapsed time - cost_time = time.time() - end - batch_time.update(cost_time) - end = time.time() - - if i % args.print_freq == 0: - progress.display(i) - - print('* FPS@all {:.3f}'.format(args.batch_size / (batch_time.avg + 0.001))) - - -def validate(val_loader, model, criterion, args): - batch_time = AverageMeter('Time', ':6.3f') - losses = AverageMeter('Loss', ':.4e') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - progress = ProgressMeter( - len(val_loader), - [batch_time, losses, top1, top5], - prefix='Test: ') - - # switch to evaluate mode - model.eval() - - with torch.no_grad(): - end = time.time() - for i, (images, target) in enumerate(val_loader): - - images = images.to(CALCULATE_DEVICE, non_blocking=False).to(torch.float) - target = target.to(torch.int32).to(CALCULATE_DEVICE, non_blocking=False) - - # compute output - output = model(images) - loss = criterion(output, target) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # measure elapsed time - cost_time = time.time() - end - batch_time.update(cost_time) - end = time.time() - - if i % args.print_freq == 0: - progress.display(i) - - print(' * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}'.format(top1=top1, top5=top5)) - - return top1.avg - - -def save_checkpoint(state, is_best, filename='checkpoint.pth.tar'): - if not os.path.exists(CACHE_TRAINING_URL): - os.makedirs(CACHE_TRAINING_URL, 0o755) - - checkpoint_save_path = os.path.join(CACHE_TRAINING_URL, filename) - torch.save(state, checkpoint_save_path) - if is_best: - shutil.copyfile(checkpoint_save_path, CACHE_TRAINING_URL + "/" + 'model_best_acc%.4f_epoch%d.pth.tar' % (state['best_acc1'], state['epoch'])) - - -class AverageMeter(object): - """Computes and stores the average and current value""" - - def __init__(self, name, fmt=':f', start_count_index=2): - self.name = name - self.fmt = fmt - self.reset() - self.start_count_index = start_count_index - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - - def update(self, val, n=1): - if self.count == 0: - self.N = n - - self.val = val - self.count += n - if self.count > (self.start_count_index * self.N): - self.sum += val * n - self.avg = self.sum / (self.count - self.start_count_index * self.N) - - def __str__(self): - fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' - return fmtstr.format(**self.__dict__) - -class ProgressMeter(object): - def __init__(self, num_batches, meters, prefix=""): - self.batch_fmtstr = self._get_batch_fmtstr(num_batches) - self.meters = meters - self.prefix = prefix - - def display(self, batch): - entries = [self.prefix + self.batch_fmtstr.format(batch)] - entries += [str(meter) for meter in self.meters] - print('\t'.join(entries)) - - def _get_batch_fmtstr(self, num_batches): - num_digits = len(str(num_batches // 1)) - fmt = '{:' + str(num_digits) + 'd}' - return '[' + fmt + '/' + fmt.format(num_batches) + ']' - - -def adjust_learning_rate(optimizer, epoch, args): - """Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" - - if args.warm_up_epochs > 0 and epoch < args.warm_up_epochs: - lr = args.lr * ((epoch + 1) / (args.warm_up_epochs + 1)) - else: - alpha = 0 - cosine_decay = 0.5 * ( - 1 + np.cos(np.pi * (epoch - args.warm_up_epochs) / (args.epochs - args.warm_up_epochs))) - decayed = (1 - alpha) * cosine_decay + alpha - lr = args.lr * decayed - - print("=> Epoch[%d] Setting lr: %.4f" % (epoch, lr)) - for param_group in optimizer.param_groups: - param_group['lr'] = lr - - -def accuracy(output, target, topk=(1,)): - """Computes the accuracy over the k top predictions for the specified values of k""" - with torch.no_grad(): - maxk = max(topk) - batch_size = target.size(0) - - _, pred = output.topk(maxk, 1, True, True) - pred = pred.t() - correct = pred.eq(target.view(1, -1).expand_as(pred)) - - res = [] - for k in topk: - correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True) - res.append(correct_k.mul_(100.0 / batch_size)) - return res - -class LabelSmoothing(nn.Module): - """ - NLL loss with label smoothing. - """ - def __init__(self, loc, smoothing=0.0): - """ - Constructor for the LabelSmoothing module. - - :param smoothing: label smoothing factor - """ - super(LabelSmoothing, self).__init__() - self.confidence = 1.0 - smoothing - self.smoothing = smoothing - self.device = loc - - def forward(self, x, target): - target = target.to(torch.int64) - - logprobs = torch.nn.functional.log_softmax(x, dim=-1) - nll_loss = -logprobs.gather(dim=-1, index=target.unsqueeze(1).to(torch.int64)) - nll_loss = nll_loss.squeeze(1) - smooth_loss = -logprobs.mean(dim=-1) - loss = self.confidence * nll_loss + self.smoothing * smooth_loss - return loss.mean() - -if __name__ == '__main__': - main() +# Copyright (c) 2021, +# All rights reserved. +# +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import os +import glob +import random +import shutil +import sys +import time +import warnings + +import torch +import numpy as np +from apex import amp + +import torch.nn as nn +import torch.nn.parallel +import torch.backends.cudnn as cudnn +import torch.distributed as dist +import torch.optim +import torch.multiprocessing as mp +import torch.utils.data +import torch.utils.data.distributed +import torchvision.transforms as transforms +import torchvision.datasets as datasets +import torchvision.models as models + +sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../')) +from pthtar2onx import convert +from xception import xception +import moxing as mox + +model_names = sorted(name for name in models.__dict__ + if name.islower() and not name.startswith("__") + and callable(models.__dict__[name])) + +parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') +parser.add_argument('--data_url', metavar='DIR', default='/cache/data_url', + help='path to dataset') +parser.add_argument('-a', '--arch', + metavar='ARCH', + default='xception', + choices=model_names, + help='model architecture: ' + + ' | '.join(model_names) + + ' (default: xception)') +parser.add_argument('-j', '--workers', default=4, type=int, metavar='N', + help='number of data loading workers (default: 4)') +parser.add_argument('--epochs', default=3, type=int, metavar='N', + help='number of total epochs to run') +parser.add_argument('--start-epoch', default=0, type=int, metavar='N', + help='manual epoch number (useful on restarts)') +parser.add_argument('-b', '--batch-size', default=64, type=int, + metavar='N', + help='mini-batch size (default: 256), this is the total ' + 'batch size of all GPUs on the current node when ' + 'using Data Parallel or Distributed Data Parallel') +parser.add_argument('--lr', '--learning-rate', default=0.1, type=float, + metavar='LR', help='initial learning rate', dest='lr') +parser.add_argument('--momentum', default=0.9, type=float, metavar='M', + help='momentum') +parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, + metavar='W', help='weight decay (default: 1e-4)', + dest='weight_decay') +parser.add_argument('-p', '--print-freq', default=10, type=int, + metavar='N', help='print frequency (default: 10)') +parser.add_argument('--resume', default='', type=str, metavar='PATH', + help='path to latest checkpoint (default: none)') +parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', + help='evaluate model on validation set') +parser.add_argument('--pretrained', dest='pretrained', action='store_true', + help='use pre-trained model') +parser.add_argument('--pretrained_weight', default='', type=str, metavar='PATH', + help='path to pretrained weight') +parser.add_argument('--world-size', default=-1, type=int, + help='number of nodes for distributed training') +parser.add_argument('--rank', default=-1, type=int, + help='node rank for distributed training') +parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str, + help='url used to set up distributed training') +parser.add_argument('--dist-backend', default='nccl', type=str, + help='distributed backend') +parser.add_argument('--seed', default=None, type=int, + help='seed for initializing training. ') +parser.add_argument('--gpu', default=None, type=int, + help='GPU id to use.') +parser.add_argument('--multiprocessing-distributed', action='store_true', + help='Use multi-processing distributed training to launch ' + 'N processes per node, which has N GPUs. This is the ' + 'fastest way to use PyTorch for either single node or ' + 'multi node data parallel training') +parser.add_argument('--npu', default=0, type=int, + help='NPU id to use.') +parser.add_argument('--addr', default='10.136.181.115', + type=str, help='master addr') +parser.add_argument('--device_list', default='0,1,2,3,4,5,6,7', + type=str, help='device id list') +parser.add_argument('--warm_up_epochs', default=0, type=int, + help='warm up') +parser.add_argument('--amp', default=False, action='store_true', + help='use amp to train the model') +parser.add_argument('--loss-scale', default=1024., type=float, + help='loss scale using in amp, default -1 means dynamic') +parser.add_argument('--opt-level', default='O2', type=str, + help='loss scale using in amp, default -1 means dynamic') +parser.add_argument('--prof', default=False, action='store_true', + help='use profiling to evaluate the performance of model') +parser.add_argument('--label-smoothing', + default=0.0, + type=float, + metavar='S', + help='label smoothing') +parser.add_argument('--train_url', + default="/cache/training", + type=str, + help="setting dir of training output") +parser.add_argument('--onnx', default=True, action='store_true', + help="convert pth model to onnx") + +best_acc1 = 0 +CACHE_TRAINING_URL = "/cache/training" + +def main(): + args = parser.parse_args() + print(args.device_list) + + os.environ['MASTER_ADDR'] = args.addr + os.environ['MASTER_PORT'] = '29688' + + if args.npu is None: + args.npu = 0 + global CALCULATE_DEVICE + global best_acc1 + + #-----modelarts modification----------------- + CALCULATE_DEVICE = "npu:{}".format(args.npu) + #-----modelarts modification----------------- + torch.npu.set_device(CALCULATE_DEVICE) + + if args.seed is not None: + random.seed(args.seed) + torch.manual_seed(args.seed) + cudnn.deterministic = True + warnings.warn('You have chosen to seed training. ' + 'This will turn on the CUDNN deterministic setting, ' + 'which can slow down your training considerably! ' + 'You may see unexpected behavior when restarting ' + 'from checkpoints.') + + if args.gpu is not None: + warnings.warn('You have chosen a specific GPU. This will completely ' + 'disable data parallelism.') + + if args.dist_url == "env://" and args.world_size == -1: + args.world_size = int(os.environ["WORLD_SIZE"]) + + args.distributed = args.world_size > 1 or args.multiprocessing_distributed + + ngpus_per_node = torch.npu.device_count() + + print('ngpus_per_node:',ngpus_per_node) + + + if args.multiprocessing_distributed: + # Since we have ngpus_per_node processes per node, the total world_size + # needs to be adjusted accordingly + args.world_size = ngpus_per_node * args.world_size + # Use torch.multiprocessing.spawn to launch distributed processes: the + # main_worker process function + mp.spawn(main_worker, nprocs=ngpus_per_node, + args=(ngpus_per_node, args)) + else: + # Simply call main_worker function + main_worker(args.gpu, ngpus_per_node, args) + + +def main_worker(gpu, ngpus_per_node, args): + global best_acc1 + args.gpu = gpu + + if args.gpu is not None: + print("Use NPU: {} for training".format(args.gpu)) + + if args.distributed: + if args.dist_url == "env://" and args.rank == -1: + args.rank = int(os.environ["RANK"]) + if args.multiprocessing_distributed: + # For multiprocessing distributed training, rank needs to be the + # global rank among all the processes + args.rank = args.rank * ngpus_per_node + gpu + + dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + # create model + if args.pretrained: + print("=> using pre-trained model '{}'".format(args.arch)) + model = xception() + CACHE_MODEL_URL = "/cache/model" + # ------------------modelarts modification---------------------- + os.makedirs(CACHE_MODEL_URL, exist_ok=True) + mox.file.copy_parallel(args.pretrained_weight, os.path.join(CACHE_MODEL_URL, "checkpoint.pth.tar")) + # ------------------modelarts modification--------------------- + pretrained_weight = os.path.join(CACHE_MODEL_URL, "checkpoint.pth.tar") + pretrained_dict = torch.load(pretrained_weight, map_location="cpu")["state_dict"] + if "fc.weight" in pretrained_dict: + pretrained_dict.pop("fc.weight") + pretrained_dict.pop("fc.bias") + + model.load_state_dict(pretrained_dict, strict=False) + + else: + print("=> creating model '{}'".format(args.arch)) + model = xception() + + if args.distributed: + # For multiprocessing distributed, DistributedDataParallel constructor + # should always set the single device scope, otherwise, + # DistributedDataParallel will use all available devices. + if args.gpu is not None: + torch.cuda.set_device(args.gpu) + model.cuda(args.gpu) + + # When using a single GPU per process and per + # DistributedDataParallel, we need to divide the batch size + # ourselves based on the total number of GPUs we have + args.batch_size = int(args.batch_size / args.world_size) + args.workers = int((args.workers + ngpus_per_node - 1) / ngpus_per_node) + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu]) + else: + model.cuda() + # DistributedDataParallel will divide and allocate batch_size to all + # available GPUs if device_ids are not set + model = torch.nn.parallel.DistributedDataParallel(model) + elif args.gpu is not None: + torch.cuda.set_device(args.gpu) + model = model.cuda(args.gpu) + + else: + model = model.to(CALCULATE_DEVICE) + + # define loss function (criterion) and optimizer + criterion = nn.CrossEntropyLoss().to(CALCULATE_DEVICE) + + optimizer = torch.optim.SGD(model.parameters(), args.lr, + momentum=args.momentum, + weight_decay=args.weight_decay) + + if args.amp: + model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, loss_scale=args.loss_scale) + + # optionally resume from a checkpoint + if args.resume : + if os.path.isfile(args.resume): + print("=> loading checkpoint '{}'".format(args.resume)) + checkpoint = torch.load(args.resume, map_location=CALCULATE_DEVICE) + args.start_epoch = checkpoint['epoch'] + best_acc1 = checkpoint['best_acc1'] + model.load_state_dict(checkpoint['state_dict']) + optimizer.load_state_dict(checkpoint['optimizer']) + if args.amp: + amp.load_state_dict(checkpoint['amp']) + print("=> loaded checkpoint '{}' (epoch {})" + .format(args.resume, checkpoint['epoch'])) + else: + print("=> no checkpoint found at '{}'".format(args.resume)) + + cudnn.benchmark = True + + # -------modelarts modification------- + real_path = '/cache/data_url' + if not os.path.exists(real_path): + os.makedirs(real_path) + mox.file.copy_parallel(args.data_url, real_path) + print("training data finish copy to %s." % real_path) + # ---------modelarts modification----- + + # Data loading code + traindir = os.path.join(real_path, 'train') + valdir = os.path.join(real_path, 'val') + normalize = transforms.Normalize(mean=[0.5, 0.5, 0.5], + std=[0.5, 0.5, 0.5]) + + train_dataset = datasets.ImageFolder( + traindir, + transforms.Compose([ + transforms.RandomResizedCrop(299), + transforms.RandomHorizontalFlip(), + transforms.ToTensor(), + normalize, + ])) + + if args.distributed: + train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) + else: + train_sampler = None + + train_loader = torch.utils.data.DataLoader( + train_dataset, batch_size=args.batch_size, shuffle=(train_sampler is None), + num_workers=args.workers, pin_memory=False, sampler=train_sampler, drop_last=True) + + val_loader = torch.utils.data.DataLoader( + datasets.ImageFolder(valdir, transforms.Compose([ + transforms.Resize(342), + transforms.CenterCrop(299), + transforms.ToTensor(), + normalize, + ])), + batch_size=args.batch_size, shuffle=True, + num_workers=args.workers, pin_memory=False, drop_last=True) + + if args.evaluate: + validate(val_loader, model, criterion, args) + return + + start_time = time.time() + for epoch in range(args.start_epoch, args.epochs): + if args.distributed: + train_sampler.set_epoch(epoch) + + adjust_learning_rate(optimizer, epoch, args) + + # train for one epoch + train(train_loader, model, criterion, optimizer, epoch, args) + + # evaluate on validation set + acc1 = validate(val_loader, model, criterion, args) + + # remember best acc@1 and save checkpoint + is_best = acc1 > best_acc1 + best_acc1 = max(acc1, best_acc1) + + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + if args.amp: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': args.arch, + 'state_dict': model.state_dict(), + 'best_acc1': best_acc1, + 'optimizer': optimizer.state_dict(), + 'amp': amp.state_dict(), + }, is_best) + else: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': args.arch, + 'state_dict': model.state_dict(), + 'best_acc1': best_acc1, + 'optimizer': optimizer.state_dict(), + }, is_best) + + if args.onnx: + convert_pth_to_onnx(args) + + # --------------modelarts modification---------- + mox.file.copy_parallel(CACHE_TRAINING_URL, args.train_url) + # --------------modelarts modification end---------- + +def convert_pth_to_onnx(config_args): + pth_pattern = os.path.join(CACHE_TRAINING_URL, 'checkpoint.pth.tar') + pth_file_list = glob.glob(pth_pattern) + if not pth_file_list: + print(f"can't find pth {pth_pattern}") + return + pth_file = pth_file_list[0] + onnx_path = pth_file.split(".")[0] + '.onnx' + convert(pth_file, onnx_path) + +def train(train_loader, model, criterion, optimizer, epoch, args): + batch_time = AverageMeter('Time', ':6.3f') + data_time = AverageMeter('Data', ':6.3f') + losses = AverageMeter('Loss', ':.4e') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + progress = ProgressMeter( + len(train_loader), + [batch_time, data_time, losses, top1, top5], + prefix="Epoch: [{}]".format(epoch)) + + # switch to train mode + model.train() + + end = time.time() + for i, (images, target) in enumerate(train_loader): + # measure data loading time + data_time.update(time.time() - end) + + images = images.to(CALCULATE_DEVICE, non_blocking=False).to(torch.float) + target = target.to(torch.int32).to(CALCULATE_DEVICE, non_blocking=False) + + # compute output + output = model(images) + loss = criterion(output, target) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # compute gradient and do SGD step + optimizer.zero_grad() + if args.amp: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + + # torch.npu.synchronize() + + # measure elapsed time + cost_time = time.time() - end + batch_time.update(cost_time) + end = time.time() + + if i % args.print_freq == 0: + progress.display(i) + + print('* FPS@all {:.3f}'.format(args.batch_size / (batch_time.avg + 0.001))) + + +def validate(val_loader, model, criterion, args): + batch_time = AverageMeter('Time', ':6.3f') + losses = AverageMeter('Loss', ':.4e') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + progress = ProgressMeter( + len(val_loader), + [batch_time, losses, top1, top5], + prefix='Test: ') + + # switch to evaluate mode + model.eval() + + with torch.no_grad(): + end = time.time() + for i, (images, target) in enumerate(val_loader): + + images = images.to(CALCULATE_DEVICE, non_blocking=False).to(torch.float) + target = target.to(torch.int32).to(CALCULATE_DEVICE, non_blocking=False) + + # compute output + output = model(images) + loss = criterion(output, target) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # measure elapsed time + cost_time = time.time() - end + batch_time.update(cost_time) + end = time.time() + + if i % args.print_freq == 0: + progress.display(i) + + print(' * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}'.format(top1=top1, top5=top5)) + + return top1.avg + + +def save_checkpoint(state, is_best, filename='checkpoint.pth.tar'): + if not os.path.exists(CACHE_TRAINING_URL): + os.makedirs(CACHE_TRAINING_URL, 0o755) + + checkpoint_save_path = os.path.join(CACHE_TRAINING_URL, filename) + torch.save(state, checkpoint_save_path) + if is_best: + shutil.copyfile(checkpoint_save_path, CACHE_TRAINING_URL + "/" + 'model_best_acc%.4f_epoch%d.pth.tar' % (state['best_acc1'], state['epoch'])) + + +class AverageMeter(object): + """Computes and stores the average and current value""" + + def __init__(self, name, fmt=':f', start_count_index=2): + self.name = name + self.fmt = fmt + self.reset() + self.start_count_index = start_count_index + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + if self.count == 0: + self.N = n + + self.val = val + self.count += n + if self.count > (self.start_count_index * self.N): + self.sum += val * n + self.avg = self.sum / (self.count - self.start_count_index * self.N) + + def __str__(self): + fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' + return fmtstr.format(**self.__dict__) + +class ProgressMeter(object): + def __init__(self, num_batches, meters, prefix=""): + self.batch_fmtstr = self._get_batch_fmtstr(num_batches) + self.meters = meters + self.prefix = prefix + + def display(self, batch): + entries = [self.prefix + self.batch_fmtstr.format(batch)] + entries += [str(meter) for meter in self.meters] + print('\t'.join(entries)) + + def _get_batch_fmtstr(self, num_batches): + num_digits = len(str(num_batches // 1)) + fmt = '{:' + str(num_digits) + 'd}' + return '[' + fmt + '/' + fmt.format(num_batches) + ']' + + +def adjust_learning_rate(optimizer, epoch, args): + """Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" + + if args.warm_up_epochs > 0 and epoch < args.warm_up_epochs: + lr = args.lr * ((epoch + 1) / (args.warm_up_epochs + 1)) + else: + alpha = 0 + cosine_decay = 0.5 * ( + 1 + np.cos(np.pi * (epoch - args.warm_up_epochs) / (args.epochs - args.warm_up_epochs))) + decayed = (1 - alpha) * cosine_decay + alpha + lr = args.lr * decayed + + print("=> Epoch[%d] Setting lr: %.4f" % (epoch, lr)) + for param_group in optimizer.param_groups: + param_group['lr'] = lr + + +def accuracy(output, target, topk=(1,)): + """Computes the accuracy over the k top predictions for the specified values of k""" + with torch.no_grad(): + maxk = max(topk) + batch_size = target.size(0) + + _, pred = output.topk(maxk, 1, True, True) + pred = pred.t() + correct = pred.eq(target.view(1, -1).expand_as(pred)) + + res = [] + for k in topk: + correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True) + res.append(correct_k.mul_(100.0 / batch_size)) + return res + +class LabelSmoothing(nn.Module): + """ + NLL loss with label smoothing. + """ + def __init__(self, loc, smoothing=0.0): + """ + Constructor for the LabelSmoothing module. + + :param smoothing: label smoothing factor + """ + super(LabelSmoothing, self).__init__() + self.confidence = 1.0 - smoothing + self.smoothing = smoothing + self.device = loc + + def forward(self, x, target): + target = target.to(torch.int64) + + logprobs = torch.nn.functional.log_softmax(x, dim=-1) + nll_loss = -logprobs.gather(dim=-1, index=target.unsqueeze(1).to(torch.int64)) + nll_loss = nll_loss.squeeze(1) + smooth_loss = -logprobs.mean(dim=-1) + loss = self.confidence * nll_loss + self.smoothing * smooth_loss + return loss.mean() + +if __name__ == '__main__': + main() diff --git a/PyTorch/contrib/cv/classification/csp_resnext50-mish/benchmark.py b/PyTorch/contrib/cv/classification/csp_resnext50-mish/benchmark.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/csp_resnext50-mish/timm/loss/asymmetric_loss.py b/PyTorch/contrib/cv/classification/csp_resnext50-mish/timm/loss/asymmetric_loss.py index 96a977882b9fa534990bfb1c8321e4c822c602ca..a8b10f9c797c2cb3b2652302717b592dada216f3 100644 --- a/PyTorch/contrib/cv/classification/csp_resnext50-mish/timm/loss/asymmetric_loss.py +++ b/PyTorch/contrib/cv/classification/csp_resnext50-mish/timm/loss/asymmetric_loss.py @@ -1,97 +1,97 @@ -import torch -import torch.nn as nn - - -class AsymmetricLossMultiLabel(nn.Module): - def __init__(self, gamma_neg=4, gamma_pos=1, clip=0.05, eps=1e-8, disable_torch_grad_focal_loss=False): - super(AsymmetricLossMultiLabel, self).__init__() - - self.gamma_neg = gamma_neg - self.gamma_pos = gamma_pos - self.clip = clip - self.disable_torch_grad_focal_loss = disable_torch_grad_focal_loss - self.eps = eps - - def forward(self, x, y): - """" - Parameters - ---------- - x: input logits - y: targets (multi-label binarized vector) - """ - - # Calculating Probabilities - x_sigmoid = torch.sigmoid(x) - xs_pos = x_sigmoid - xs_neg = 1 - x_sigmoid - - # Asymmetric Clipping - if self.clip is not None and self.clip > 0: - xs_neg = (xs_neg + self.clip).clamp(max=1) - - # Basic CE calculation - los_pos = y * torch.log(xs_pos.clamp(min=self.eps)) - los_neg = (1 - y) * torch.log(xs_neg.clamp(min=self.eps)) - loss = los_pos + los_neg - - # Asymmetric Focusing - if self.gamma_neg > 0 or self.gamma_pos > 0: - if self.disable_torch_grad_focal_loss: - torch._C.set_grad_enabled(False) - pt0 = xs_pos * y - pt1 = xs_neg * (1 - y) # pt = p if t > 0 else 1-p - pt = pt0 + pt1 - one_sided_gamma = self.gamma_pos * y + self.gamma_neg * (1 - y) - one_sided_w = torch.pow(1 - pt, one_sided_gamma) - if self.disable_torch_grad_focal_loss: - torch._C.set_grad_enabled(True) - loss *= one_sided_w - - return -loss.sum() - - -class AsymmetricLossSingleLabel(nn.Module): - def __init__(self, gamma_pos=1, gamma_neg=4, eps: float = 0.1, reduction='mean'): - super(AsymmetricLossSingleLabel, self).__init__() - - self.eps = eps - self.logsoftmax = nn.LogSoftmax(dim=-1) - self.targets_classes = [] # prevent gpu repeated memory allocation - self.gamma_pos = gamma_pos - self.gamma_neg = gamma_neg - self.reduction = reduction - - def forward(self, inputs, target, reduction=None): - """" - Parameters - ---------- - x: input logits - y: targets (1-hot vector) - """ - - num_classes = inputs.size()[-1] - log_preds = self.logsoftmax(inputs) - self.targets_classes = torch.zeros_like(inputs).scatter_(1, target.long().unsqueeze(1), 1) - - # ASL weights - targets = self.targets_classes - anti_targets = 1 - targets - xs_pos = torch.exp(log_preds) - xs_neg = 1 - xs_pos - xs_pos = xs_pos * targets - xs_neg = xs_neg * anti_targets - asymmetric_w = torch.pow(1 - xs_pos - xs_neg, - self.gamma_pos * targets + self.gamma_neg * anti_targets) - log_preds = log_preds * asymmetric_w - - if self.eps > 0: # label smoothing - self.targets_classes.mul_(1 - self.eps).add_(self.eps / num_classes) - - # loss calculation - loss = - self.targets_classes.mul(log_preds) - - loss = loss.sum(dim=-1) - if self.reduction == 'mean': - loss = loss.mean() - - return loss +import torch +import torch.nn as nn + + +class AsymmetricLossMultiLabel(nn.Module): + def __init__(self, gamma_neg=4, gamma_pos=1, clip=0.05, eps=1e-8, disable_torch_grad_focal_loss=False): + super(AsymmetricLossMultiLabel, self).__init__() + + self.gamma_neg = gamma_neg + self.gamma_pos = gamma_pos + self.clip = clip + self.disable_torch_grad_focal_loss = disable_torch_grad_focal_loss + self.eps = eps + + def forward(self, x, y): + """" + Parameters + ---------- + x: input logits + y: targets (multi-label binarized vector) + """ + + # Calculating Probabilities + x_sigmoid = torch.sigmoid(x) + xs_pos = x_sigmoid + xs_neg = 1 - x_sigmoid + + # Asymmetric Clipping + if self.clip is not None and self.clip > 0: + xs_neg = (xs_neg + self.clip).clamp(max=1) + + # Basic CE calculation + los_pos = y * torch.log(xs_pos.clamp(min=self.eps)) + los_neg = (1 - y) * torch.log(xs_neg.clamp(min=self.eps)) + loss = los_pos + los_neg + + # Asymmetric Focusing + if self.gamma_neg > 0 or self.gamma_pos > 0: + if self.disable_torch_grad_focal_loss: + torch._C.set_grad_enabled(False) + pt0 = xs_pos * y + pt1 = xs_neg * (1 - y) # pt = p if t > 0 else 1-p + pt = pt0 + pt1 + one_sided_gamma = self.gamma_pos * y + self.gamma_neg * (1 - y) + one_sided_w = torch.pow(1 - pt, one_sided_gamma) + if self.disable_torch_grad_focal_loss: + torch._C.set_grad_enabled(True) + loss *= one_sided_w + + return -loss.sum() + + +class AsymmetricLossSingleLabel(nn.Module): + def __init__(self, gamma_pos=1, gamma_neg=4, eps: float = 0.1, reduction='mean'): + super(AsymmetricLossSingleLabel, self).__init__() + + self.eps = eps + self.logsoftmax = nn.LogSoftmax(dim=-1) + self.targets_classes = [] # prevent gpu repeated memory allocation + self.gamma_pos = gamma_pos + self.gamma_neg = gamma_neg + self.reduction = reduction + + def forward(self, inputs, target, reduction=None): + """" + Parameters + ---------- + x: input logits + y: targets (1-hot vector) + """ + + num_classes = inputs.size()[-1] + log_preds = self.logsoftmax(inputs) + self.targets_classes = torch.zeros_like(inputs).scatter_(1, target.long().unsqueeze(1), 1) + + # ASL weights + targets = self.targets_classes + anti_targets = 1 - targets + xs_pos = torch.exp(log_preds) + xs_neg = 1 - xs_pos + xs_pos = xs_pos * targets + xs_neg = xs_neg * anti_targets + asymmetric_w = torch.pow(1 - xs_pos - xs_neg, + self.gamma_pos * targets + self.gamma_neg * anti_targets) + log_preds = log_preds * asymmetric_w + + if self.eps > 0: # label smoothing + self.targets_classes.mul_(1 - self.eps).add_(self.eps / num_classes) + + # loss calculation + loss = - self.targets_classes.mul(log_preds) + + loss = loss.sum(dim=-1) + if self.reduction == 'mean': + loss = loss.mean() + + return loss diff --git a/PyTorch/contrib/cv/classification/csp_resnext50-mish/train-1p.py b/PyTorch/contrib/cv/classification/csp_resnext50-mish/train-1p.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/csp_resnext50-mish/train-8p.py b/PyTorch/contrib/cv/classification/csp_resnext50-mish/train-8p.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/csp_resnext50-mish/validate.py b/PyTorch/contrib/cv/classification/csp_resnext50-mish/validate.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/classification/pointnetCNN/LICENSE b/PyTorch/contrib/cv/classification/pointnetCNN/LICENSE index 657549b86065a3d34c7dd038edee91cedb8cb05a..dcc65541a1b5f985560b92c275b8328469d50742 100644 --- a/PyTorch/contrib/cv/classification/pointnetCNN/LICENSE +++ b/PyTorch/contrib/cv/classification/pointnetCNN/LICENSE @@ -1,30 +1,30 @@ -BSD 3-Clause License - -Copyright (c) 2017, -All rights reserved. -Copyright 2020 Huawei Technologies Co., Ltd - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +BSD 3-Clause License + +Copyright (c) 2017, +All rights reserved. +Copyright 2020 Huawei Technologies Co., Ltd + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/pointnetCNN/README.md b/PyTorch/contrib/cv/classification/pointnetCNN/README.md index 0199ef0f24f0c1e053d49753b47eea4840c705a5..907e6f516e23590162abc936005bc183bd35dc75 100644 --- a/PyTorch/contrib/cv/classification/pointnetCNN/README.md +++ b/PyTorch/contrib/cv/classification/pointnetCNN/README.md @@ -1,48 +1,48 @@ -# PointNetCNN - -This implements training of PointNetCNN on the modelnet40_ply_hdf5_2048 dataset. - -## PointNetCNN Detail - - - -## Requirements - -- `pip install -r requirements.txt` -- Download the dataset from https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/PointNetCNN/modelnet40_ply_hdf5_2048.zip and unzip it to ./data - -## Training - -To train a model, run `train_pytorch.py` - -```bash -# training 1p accuracy -bash ./test/train_full_1p.sh --data_path=./data/modelnet40_ply_hdf5_2048/ - -# training 1p performance -bash ./test/train_performance_1p.sh --data_path=./data/modelnet40_ply_hdf5_2048/ - -# training 8p accuracy -bash ./test/train_full_8p.sh --data_path=./data/modelnet40_ply_hdf5_2048/ - -# training 8p performance -bash ./test/train_performance_8p.sh --data_path=./data/modelnet40_ply_hdf5_2048/ - - -# finetuning 1p -bash test/train_finetune_1p.sh --data_path=./data/modelnet40_ply_hdf5_2048/ -``` - -Log path: - ./test/output/1/train_1.log # 8p training performance and loss log - ./test/output/1/train_1.log # 1p training performance and loss log - - - - -## PointNetCNN training result - -| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | -| :------: | :------: | :------: | :------: | :------: | -| - | 20 | 1 | 1 | O1 | -| - | 160 | 8 | 250 | O1 | +# PointNetCNN + +This implements training of PointNetCNN on the modelnet40_ply_hdf5_2048 dataset. + +## PointNetCNN Detail + + + +## Requirements + +- `pip install -r requirements.txt` +- Download the dataset from https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E6%8E%A8%E7%90%86/cv/classfication/PointNetCNN/modelnet40_ply_hdf5_2048.zip and unzip it to ./data + +## Training + +To train a model, run `train_pytorch.py` + +```bash +# training 1p accuracy +bash ./test/train_full_1p.sh --data_path=./data/modelnet40_ply_hdf5_2048/ + +# training 1p performance +bash ./test/train_performance_1p.sh --data_path=./data/modelnet40_ply_hdf5_2048/ + +# training 8p accuracy +bash ./test/train_full_8p.sh --data_path=./data/modelnet40_ply_hdf5_2048/ + +# training 8p performance +bash ./test/train_performance_8p.sh --data_path=./data/modelnet40_ply_hdf5_2048/ + + +# finetuning 1p +bash test/train_finetune_1p.sh --data_path=./data/modelnet40_ply_hdf5_2048/ +``` + +Log path: + ./test/output/1/train_1.log # 8p training performance and loss log + ./test/output/1/train_1.log # 1p training performance and loss log + + + + +## PointNetCNN training result + +| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | +| :------: | :------: | :------: | :------: | :------: | +| - | 20 | 1 | 1 | O1 | +| - | 160 | 8 | 250 | O1 | diff --git a/PyTorch/contrib/cv/classification/pointnetCNN/modelzoo_level.txt b/PyTorch/contrib/cv/classification/pointnetCNN/modelzoo_level.txt index a17c8f95fa388fbc6d253e2cd7cfd0b73b734073..a829ab59b97a1022dd6fc33b59b7ae0d55009432 100644 --- a/PyTorch/contrib/cv/classification/pointnetCNN/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/pointnetCNN/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/pointnetCNN/requirements.txt b/PyTorch/contrib/cv/classification/pointnetCNN/requirements.txt index 366725ddde2a0d4ce60c5008cd07757edb8a383b..04d04ad3fea859e240bdff5cf5d67fb646d3d751 100644 --- a/PyTorch/contrib/cv/classification/pointnetCNN/requirements.txt +++ b/PyTorch/contrib/cv/classification/pointnetCNN/requirements.txt @@ -1,4 +1,4 @@ -torch == 1.5.0 -h5py -scipy -sklearn +torch == 1.5.0 +h5py +scipy +sklearn diff --git a/PyTorch/contrib/cv/classification/vit_base_patch32_224/LICENSE b/PyTorch/contrib/cv/classification/vit_base_patch32_224/LICENSE index 4ba4fdcab3dbdb4d64ce4cccdfd990698b4d596a..a0e03103591c1158a839681f3c404ee9118b182e 100644 --- a/PyTorch/contrib/cv/classification/vit_base_patch32_224/LICENSE +++ b/PyTorch/contrib/cv/classification/vit_base_patch32_224/LICENSE @@ -1,29 +1,29 @@ -BSD 3-Clause License - -Copyright (c) 2017, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +BSD 3-Clause License + +Copyright (c) 2017, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/vit_base_patch32_224/README.md b/PyTorch/contrib/cv/classification/vit_base_patch32_224/README.md index 3a818ad9fb59402c7bbb96051f4bba3633dc7373..34984ac0d020f08fda86db10d0309fcb2ad77ced 100644 --- a/PyTorch/contrib/cv/classification/vit_base_patch32_224/README.md +++ b/PyTorch/contrib/cv/classification/vit_base_patch32_224/README.md @@ -1,31 +1,31 @@ -## Vit_base_patch32_224
-This implements training of Vit_base_patch32_224 on the ImageNet dataset
-## Vit_base_patch32_224 Detail
-This model is one of open-source models by rwightman. See the source code at https://github.com/rwightman/pytorch-image-models/tree/master/timm.
-The whole model has achieved the requirement of accuracy and performance.
-## requirement
-Install PyTorch
-```pip install timm```
-```torchvision==0.5.0(x86) && torchvision==0.2.0(arm)``` -Please prepare the dataset by yourself, including training set and verification set. The optional dataset includes imagenet2012, including train and val. -## Training
-To train a model, run ```vit_train.py``` with the desired model architecture and the path to the ImageNet dataset:
-```bash -# training 1p performance -bash test/train_performance_1p.sh --data_path=real_data_path - -# training 8p accuracy -bash test/train_full_8p.sh --data_path=real_data_path - -# training 8p performance -bash test/train_performance_8p.sh --data_path=real_data_path - -# finetuning 1p -bash test/train_finetune_1p.sh --data_path=real_data_path --model-path=real_pre_train_model_path -``` -Log path: output/devie_id/train_${device_id}.log
-## Vit_base_patch32_224 Detail
-| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | -| :------: | :------: | :------: | :------: | :------: | -| - | 96.8 | 1 | 1 | O1 | +## Vit_base_patch32_224
+This implements training of Vit_base_patch32_224 on the ImageNet dataset
+## Vit_base_patch32_224 Detail
+This model is one of open-source models by rwightman. See the source code at https://github.com/rwightman/pytorch-image-models/tree/master/timm.
+The whole model has achieved the requirement of accuracy and performance.
+## requirement
+Install PyTorch
+```pip install timm```
+```torchvision==0.5.0(x86) && torchvision==0.2.0(arm)``` +Please prepare the dataset by yourself, including training set and verification set. The optional dataset includes imagenet2012, including train and val. +## Training
+To train a model, run ```vit_train.py``` with the desired model architecture and the path to the ImageNet dataset:
+```bash +# training 1p performance +bash test/train_performance_1p.sh --data_path=real_data_path + +# training 8p accuracy +bash test/train_full_8p.sh --data_path=real_data_path + +# training 8p performance +bash test/train_performance_8p.sh --data_path=real_data_path + +# finetuning 1p +bash test/train_finetune_1p.sh --data_path=real_data_path --model-path=real_pre_train_model_path +``` +Log path: output/devie_id/train_${device_id}.log
+## Vit_base_patch32_224 Detail
+| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | +| :------: | :------: | :------: | :------: | :------: | +| - | 96.8 | 1 | 1 | O1 | | 80.64 | 2981 | 8 | 8 | O1 | \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/vit_base_patch32_224/modelzoo_level.txt b/PyTorch/contrib/cv/classification/vit_base_patch32_224/modelzoo_level.txt index 41bdc0f3b06335fa8e0bed2287baad4eaa28ceae..810a09268cf30040cffd446a4242b3fec735ee66 100644 --- a/PyTorch/contrib/cv/classification/vit_base_patch32_224/modelzoo_level.txt +++ b/PyTorch/contrib/cv/classification/vit_base_patch32_224/modelzoo_level.txt @@ -1,5 +1,5 @@ -GPUStatus:OK -NPUMigrationStatus:OK -FuncStatus:OK -PrecisionStatus:OK +GPUStatus:OK +NPUMigrationStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/vit_base_patch32_224/requirements.txt b/PyTorch/contrib/cv/classification/vit_base_patch32_224/requirements.txt index bd9dc1313f5b68f0ae9a7e96db0bbe77e5dca143..c08eaabc347c993998951b302256f01c727d4c78 100644 --- a/PyTorch/contrib/cv/classification/vit_base_patch32_224/requirements.txt +++ b/PyTorch/contrib/cv/classification/vit_base_patch32_224/requirements.txt @@ -1,5 +1,5 @@ -#torch=1.5.0 -#torchvision>=0.5.0 -#torchvision>=0.2.0 -pyyaml +#torch=1.5.0 +#torchvision>=0.5.0 +#torchvision>=0.2.0 +pyyaml timm \ No newline at end of file diff --git a/PyTorch/contrib/cv/classification/vit_base_patch32_224/vit_train.py b/PyTorch/contrib/cv/classification/vit_base_patch32_224/vit_train.py index 277732b7abbed3862b302284fe64cddc206998e1..86884921f94c61053ebd84385e40a83ae51959ea 100644 --- a/PyTorch/contrib/cv/classification/vit_base_patch32_224/vit_train.py +++ b/PyTorch/contrib/cv/classification/vit_base_patch32_224/vit_train.py @@ -1,903 +1,903 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import argparse -import os -import random -import shutil -import time -import warnings -import torch -import numpy as np -import apex -from apex import amp -import torch.nn as nn -import torch.nn.parallel -import torch.npu -import torch.backends.cudnn as cudnn -import torch.distributed as dist -import torch.optim -import torch.multiprocessing as mp -import torch.utils.data -import torch.utils.data.distributed -import torchvision.transforms as transforms -import torchvision.datasets as datasets -import timm -from timm.utils import ApexScaler -from timm.data import create_dataset,create_loader,resolve_data_config,Mixup, FastCollateMixup, AugMixDataset -from timm.models import model_parameters, create_model -from collections import OrderedDict - -parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') -parser.add_argument('data_dir', metavar='DIR', - help='path to dataset') -parser.add_argument('--dataset', '-d', metavar='NAME', default='', - help='dataset type (default: ImageFolder/ImageTar if empty)') -parser.add_argument('-j', '--workers', default=4, type=int, metavar='N', - help='number of data loading workers (default: 4)') -parser.add_argument('--epochs', default=90, type=int, metavar='N', - help='number of total epochs to run') -parser.add_argument('--start-epoch', default=0, type=int, metavar='N', - help='manual epoch number (useful on restarts)') -parser.add_argument('-b', '--batch-size', default=256, type=int, - metavar='N', - help='mini-batch size (default: 256), this is the total ' - 'batch size of all GPUs on the current node when ' - 'using Data Parallel or Distributed Data Parallel') -parser.add_argument('--lr', '--learning-rate', default=0.1, type=float, - metavar='LR', help='initial learning rate', dest='lr') -parser.add_argument('--momentum', default=0.9, type=float, metavar='M', - help='momentum') -parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, - metavar='W', help='weight decay (default: 1e-4)', - dest='weight_decay') -parser.add_argument('-p', '--print-freq', default=10, type=int, - metavar='N', help='print frequency (default: 10)') -parser.add_argument('--resume', default='', type=str, metavar='PATH', - help='path to latest checkpoint (default: none)') -parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', - help='evaluate model on validation set') -parser.add_argument('--pretrained', dest='pretrained', action='store_true', - help='use pre-trained model') -parser.add_argument('--world-size', default=-1, type=int, - help='number of nodes for distributed training') -parser.add_argument('--rank', default=-1, type=int, - help='node rank for distributed training') -parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str, - help='url used to set up distributed training') -parser.add_argument('--dist-backend', default='nccl', type=str, - help='distributed backend') -parser.add_argument('--seed', default=None, type=int, - help='seed for initializing training. ') -parser.add_argument('--gpu', default=None, type=int, - help='GPU id to use.') -parser.add_argument('--multiprocessing-distributed', action='store_true', - help='Use multi-processing distributed training to launch ' - 'N processes per node, which has N GPUs. This is the ' - 'fastest way to use PyTorch for either single node or ' - 'multi node data parallel training') -parser.add_argument('--num-classes', default=1000, type=int, - help='The number of classes.') -## for ascend 910 -parser.add_argument('--device', default='npu', type=str, help='npu or gpu') -parser.add_argument('--addr', default='10.136.181.115', - type=str, help='master addr') -parser.add_argument('--device_list', default='0,1,2,3,4,5,6,7', - type=str, help='device id list') -parser.add_argument('--warm_up_epochs', default=0, type=int, - help='warm up') -parser.add_argument('--amp', default=False, action='store_true', - help='use amp to train the model') -parser.add_argument('--loss-scale', default=8, type=float, - help='loss scale using in amp, default -1 means dynamic') -parser.add_argument('--opt-level', default='O2', type=str, - help='loss scale using in amp, default -1 means dynamic') -parser.add_argument('--prof', default=False, action='store_true', - help='use profiling to evaluate the performance of model') - -#Additional parameters from author -parser.add_argument('--train-split', metavar='NAME', default='train', - help='dataset train split (default: train)') -parser.add_argument('--val-split', metavar='NAME', default='val', - help='dataset validation split (default: validation)') -parser.add_argument('--model', default='resnet50', type=str, metavar='MODEL', - help='Name of model to train (default: "resnet50"') -parser.add_argument('--initial-checkpoint', default='', type=str, metavar='PATH', - help='Initialize model from this checkpoint (default: none)') -parser.add_argument('--no-resume-opt', action='store_true', default=False, - help='prevent resume of optimizer state when resuming model') -parser.add_argument('--gp', default=None, type=str, metavar='POOL', - help='Global pool type, one of (fast, avg, max, avgmax, avgmaxc). Model default if None.') -parser.add_argument('--img-size', type=int, default=None, metavar='N', - help='Image patch size (default: None => model default)') -parser.add_argument('--input-size', default=None, nargs=3, type=int, - metavar='N N N', help='Input all image dimensions (d h w, e.g. --input-size 3 224 224), uses model default if empty') -parser.add_argument('--crop-pct', default=None, type=float, - metavar='N', help='Input image center crop percent (for validation only)') -parser.add_argument('--mean', type=float, nargs='+', default=None, metavar='MEAN', - help='Override mean pixel value of dataset') -parser.add_argument('--std', type=float, nargs='+', default=None, metavar='STD', - help='Override std deviation of of dataset') -parser.add_argument('--interpolation', default='', type=str, metavar='NAME', - help='Image resize interpolation type (overrides model)') -parser.add_argument('-vb', '--validation-batch-size', type=int, default=None, metavar='N', - help='validation batch size override (default: None)') - -# Optimizer parameters -parser.add_argument('--opt', default='sgd', type=str, metavar='OPTIMIZER', - help='Optimizer (default: "sgd"') -parser.add_argument('--opt-eps', default=None, type=float, metavar='EPSILON', - help='Optimizer Epsilon (default: None, use opt default)') -parser.add_argument('--opt-betas', default=None, type=float, nargs='+', metavar='BETA', - help='Optimizer Betas (default: None, use opt default)') -parser.add_argument('--clip-grad', type=float, default=None, metavar='NORM', - help='Clip gradient norm (default: None, no clipping)') -parser.add_argument('--clip-mode', type=str, default='norm', - help='Gradient clipping mode. One of ("norm", "value", "agc")') - - -# Learning rate schedule parameters -parser.add_argument('--sched', default='cosine', type=str, metavar='SCHEDULER', - help='LR scheduler (default: "step"') -parser.add_argument('--lr-noise', type=float, nargs='+', default=None, metavar='pct, pct', - help='learning rate noise on/off epoch percentages') -parser.add_argument('--lr-noise-pct', type=float, default=0.67, metavar='PERCENT', - help='learning rate noise limit percent (default: 0.67)') -parser.add_argument('--lr-noise-std', type=float, default=1.0, metavar='STDDEV', - help='learning rate noise std-dev (default: 1.0)') -parser.add_argument('--lr-cycle-mul', type=float, default=1.0, metavar='MULT', - help='learning rate cycle len multiplier (default: 1.0)') -parser.add_argument('--lr-cycle-decay', type=float, default=0.5, metavar='MULT', - help='amount to decay each learning rate cycle (default: 0.5)') -parser.add_argument('--lr-cycle-limit', type=int, default=1, metavar='N', - help='learning rate cycle limit, cycles enabled if > 1') -parser.add_argument('--lr-k-decay', type=float, default=1.0, - help='learning rate k-decay for cosine/poly (default: 1.0)') -parser.add_argument('--warmup-lr', type=float, default=0.0001, metavar='LR', - help='warmup learning rate (default: 0.0001)') -parser.add_argument('--min-lr', type=float, default=1e-6, metavar='LR', - help='lower lr bound for cyclic schedulers that hit 0 (1e-5)') -parser.add_argument('--epoch-repeats', type=float, default=0., metavar='N', - help='epoch repeat multiplier (number of times to repeat dataset epoch per train epoch).') -parser.add_argument('--decay-epochs', type=float, default=100, metavar='N', - help='epoch interval to decay LR') -parser.add_argument('--warmup-epochs', type=int, default=3, metavar='N', - help='epochs to warmup LR, if scheduler supports') -parser.add_argument('--cooldown-epochs', type=int, default=10, metavar='N', - help='epochs to cooldown LR at min_lr, after cyclic schedule ends') -parser.add_argument('--patience-epochs', type=int, default=10, metavar='N', - help='patience epochs for Plateau LR scheduler (default: 10') -parser.add_argument('--decay-rate', '--dr', type=float, default=0.1, metavar='RATE', - help='LR decay rate (default: 0.1)') - -# Augmentation & regularization parameters -parser.add_argument('--no-aug', action='store_true', default=False, - help='Disable all training augmentation, override other train aug args') -parser.add_argument('--scale', type=float, nargs='+', default=[0.08, 1.0], metavar='PCT', - help='Random resize scale (default: 0.08 1.0)') -parser.add_argument('--ratio', type=float, nargs='+', default=[3./4., 4./3.], metavar='RATIO', - help='Random resize aspect ratio (default: 0.75 1.33)') -parser.add_argument('--hflip', type=float, default=0.5, - help='Horizontal flip training aug probability') -parser.add_argument('--vflip', type=float, default=0., - help='Vertical flip training aug probability') -parser.add_argument('--color-jitter', type=float, default=0.4, metavar='PCT', - help='Color jitter factor (default: 0.4)') -parser.add_argument('--aa', type=str, default=None, metavar='NAME', - help='Use AutoAugment policy. "v0" or "original". (default: None)'), -parser.add_argument('--aug-repeats', type=int, default=0, - help='Number of augmentation repetitions (distributed training only) (default: 0)') -parser.add_argument('--aug-splits', type=int, default=0, - help='Number of augmentation splits (default: 0, valid: 0 or >=2)') -parser.add_argument('--jsd-loss', action='store_true', default=False, - help='Enable Jensen-Shannon Divergence + CE loss. Use with `--aug-splits`.') -parser.add_argument('--bce-loss', action='store_true', default=False, - help='Enable BCE loss w/ Mixup/CutMix use.') -parser.add_argument('--reprob', type=float, default=0., metavar='PCT', - help='Random erase prob (default: 0.)') -parser.add_argument('--remode', type=str, default='pixel', - help='Random erase mode (default: "pixel")') -parser.add_argument('--recount', type=int, default=1, - help='Random erase count (default: 1)') -parser.add_argument('--resplit', action='store_true', default=False, - help='Do not random erase first (clean) augmentation split') -parser.add_argument('--mixup', type=float, default=0.0, - help='mixup alpha, mixup enabled if > 0. (default: 0.)') -parser.add_argument('--cutmix', type=float, default=0.0, - help='cutmix alpha, cutmix enabled if > 0. (default: 0.)') -parser.add_argument('--cutmix-minmax', type=float, nargs='+', default=None, - help='cutmix min/max ratio, overrides alpha and enables cutmix if set (default: None)') -parser.add_argument('--mixup-prob', type=float, default=1.0, - help='Probability of performing mixup or cutmix when either/both is enabled') -parser.add_argument('--mixup-switch-prob', type=float, default=0.5, - help='Probability of switching to cutmix when both mixup and cutmix enabled') -parser.add_argument('--mixup-mode', type=str, default='batch', - help='How to apply mixup/cutmix params. Per "batch", "pair", or "elem"') -parser.add_argument('--mixup-off-epoch', default=0, type=int, metavar='N', - help='Turn off mixup after this epoch, disabled if 0 (default: 0)') -parser.add_argument('--smoothing', type=float, default=0.1, - help='Label smoothing (default: 0.1)') -parser.add_argument('--train-interpolation', type=str, default='random', - help='Training interpolation (random, bilinear, bicubic default: "random")') -parser.add_argument('--drop', type=float, default=0.0, metavar='PCT', - help='Dropout rate (default: 0.)') -parser.add_argument('--drop-connect', type=float, default=None, metavar='PCT', - help='Drop connect rate, DEPRECATED, use drop-path (default: None)') -parser.add_argument('--drop-path', type=float, default=None, metavar='PCT', - help='Drop path rate (default: None)') -parser.add_argument('--drop-block', type=float, default=None, metavar='PCT', - help='Drop block rate (default: None)') - -# Batch norm parameters (only works with gen_efficientnet based models currently) -parser.add_argument('--bn-tf', action='store_true', default=False, - help='Use Tensorflow BatchNorm defaults for models that support it (default: False)') -parser.add_argument('--bn-momentum', type=float, default=None, - help='BatchNorm momentum override (if not None)') -parser.add_argument('--bn-eps', type=float, default=None, - help='BatchNorm epsilon override (if not None)') -parser.add_argument('--sync-bn', action='store_true', - help='Enable NVIDIA Apex or Torch synchronized BatchNorm.') -parser.add_argument('--dist-bn', type=str, default='reduce', - help='Distribute BatchNorm stats between nodes after each epoch ("broadcast", "reduce", or "")') -parser.add_argument('--split-bn', action='store_true', - help='Enable separate BN layers per augmentation split.') - -# Model Exponential Moving Average -parser.add_argument('--model-ema', action='store_true', default=False, - help='Enable tracking moving average of model weights') -parser.add_argument('--model-ema-force-cpu', action='store_true', default=False, - help='Force ema to be tracked on CPU, rank=0 node only. Disables EMA validation.') -parser.add_argument('--model-ema-decay', type=float, default=0.9998, - help='decay factor for model weights moving average (default: 0.9998)') - -# Misc -parser.add_argument('--log-interval', type=int, default=50, metavar='N', - help='how many batches to wait before logging training status') -parser.add_argument('--recovery-interval', type=int, default=0, metavar='N', - help='how many batches to wait before writing recovery checkpoint') -parser.add_argument('--checkpoint-hist', type=int, default=10, metavar='N', - help='number of checkpoints to keep (default: 10)') -parser.add_argument('--save-images', action='store_true', default=False, - help='save images of input bathes every log interval for debugging') -parser.add_argument('--apex-amp', action='store_true', default=False, - help='Use NVIDIA Apex AMP mixed precision') -parser.add_argument('--native-amp', action='store_true', default=False, - help='Use Native Torch AMP mixed precision') -parser.add_argument('--channels-last', action='store_true', default=False, - help='Use channels_last memory layout') -parser.add_argument('--pin-mem', action='store_true', default=False, - help='Pin CPU memory in DataLoader for more efficient (sometimes) transfer to GPU.') -parser.add_argument('--no-prefetcher', action='store_true', default=False, - help='disable fast prefetcher') -parser.add_argument('--output', default='', type=str, metavar='PATH', - help='path to output folder (default: none, current dir)') -parser.add_argument('--experiment', default='', type=str, metavar='NAME', - help='name of train experiment, name of sub-folder for output') -parser.add_argument('--eval-metric', default='top1', type=str, metavar='EVAL_METRIC', - help='Best metric (default: "top1"') -parser.add_argument('--tta', type=int, default=0, metavar='N', - help='Test/inference time augmentation (oversampling) factor. 0=None (default: 0)') -parser.add_argument("--local_rank", default=0, type=int) -parser.add_argument('--use-multi-epochs-loader', action='store_true', default=False, - help='use the multi-epochs-loader to save time at the beginning of every epoch') -parser.add_argument('--torchscript', dest='torchscript', action='store_true', - help='convert model torchscript for inference') -parser.add_argument('--log-wandb', action='store_true', default=False, - help='log training and validation metrics to wandb') -parser.add_argument('--model-path',type=str) -best_acc1 = 0 - - -def device_id_to_process_device_map(device_list): - devices = device_list.split(",") - devices = [int(x) for x in devices] - devices.sort() - - process_device_map = dict() - for process_id, device_id in enumerate(devices): - process_device_map[process_id] = device_id - - return process_device_map - -def proc_nodes_module(checkpoint,AttrName): - new_state_dict = OrderedDict() - for k, v in checkpoint[AttrName].items(): - if "module." in k: - name = k.replace("module.", "") - else: - name = k - new_state_dict[name] = v - return new_state_dict - - -def main(): - - args = parser.parse_args() - print(args.device_list) - - os.environ['MASTER_ADDR'] = args.addr - os.environ['MASTER_PORT'] = '29688' - - if args.seed is not None: - random.seed(args.seed) - torch.manual_seed(args.seed) - cudnn.deterministic = True - warnings.warn('You have chosen to seed training. ' - 'This will turn on the CUDNN deterministic setting, ' - 'which can slow down your training considerably! ' - 'You may see unexpected behavior when restarting ' - 'from checkpoints.') - - if args.gpu is not None: - warnings.warn('You have chosen a specific GPU. This will completely ' - 'disable data parallelism.') - - if args.dist_url == "env://" and args.world_size == -1: - args.world_size = int(os.environ["WORLD_SIZE"]) - - args.distributed = args.world_size > 1 or args.multiprocessing_distributed - - args.process_device_map = device_id_to_process_device_map(args.device_list) - - if args.device == 'npu': - ngpus_per_node = len(args.process_device_map) - else: - if args.distributed: - ngpus_per_node = torch.cuda.device_count() - else: - ngpus_per_node = 1 - print('ngpus_per_node:', ngpus_per_node) - if args.multiprocessing_distributed: - # Since we have ngpus_per_node processes per node, the total world_size - # needs to be adjusted accordingly - args.world_size = ngpus_per_node * args.world_size - # Use torch.multiprocessing.spawn to launch distributed processes: the - # main_worker process function - mp.spawn(main_worker, nprocs=ngpus_per_node, - args=(ngpus_per_node, args)) - else: - # Simply call main_worker function - main_worker(args.gpu, ngpus_per_node, args) - - -def main_worker(gpu, ngpus_per_node, args): - global best_acc1 - args.gpu = args.process_device_map[gpu] - - if args.gpu is not None: - print("Use GPU: {} for training".format(args.gpu)) - print("Is distributed train available?",dist.is_available()) - if args.distributed: - if args.dist_url == "env://" and args.rank == -1: - print("According to url") - args.rank = int(os.environ["RANK"]) - print("endif") - if args.multiprocessing_distributed: - # For multiprocessing distributed training, rank needs to be the - # global rank among all the processes - args.rank = args.rank * ngpus_per_node + gpu - - if args.device == 'npu': - print("enter npu dis") - dist.init_process_group(backend=args.dist_backend, # init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - print("leave npu dist") - else: - dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - # create model - if args.pretrained: - print("=> using pre-trained model vit_base_patch32") - model = create_model( - "vit_base_patch32_224_in21k", - pretrained=args.pretrained, - num_classes=1000, - drop_rate=args.drop, - drop_connect_rate=args.drop_connect, # DEPRECATED, use drop_path - drop_path_rate=args.drop_path, - drop_block_rate=args.drop_block, - global_pool=args.gp, - bn_tf=args.bn_tf, - bn_momentum=args.bn_momentum, - bn_eps=args.bn_eps, - scriptable=args.torchscript, - checkpoint_path=args.initial_checkpoint) - data_config = resolve_data_config(vars(args), model=model, verbose=args.local_rank == 0) - #model = timm.create_model("vit_base_patch32_224_in21k",pretrained=True,num_classes=1000) - #print("loading model of yours...") - #pretrained_dict = torch.load("./model_best.pth.tar", map_location="cpu")["state_dict"] - #model.load_state_dict({k.replace('module.',''):v for k, v in pretrained_dict.items()}) - #if "fc.weight" in pretrained_dict: - # pretrained_dict.pop('fc.weight') - # pretrained_dict.pop('fc.bias') - #model.load_state_dict(pretrained_dict, strict=False) - else: - print("=> creating model vit_base_patch32") - model = model = timm.create_model("vit_base_patch32_224",num_classes=1000) - pretrained_dict = torch.load(args.model_path, map_location="cpu") - pretrained_dict['state_dict']=proc_nodes_module(pretrained_dict,'state_dict') - model.load_state_dict(pretrained_dict['state_dict']) - model.head = nn.Linear(768, args.num_classes) if args.num_classes > 0 else nn.Identity() - - - if args.distributed: - # For multiprocessing distributed, DistributedDataParallel constructor - # should always set the single device scope, otherwise, - # DistributedDataParallel will use all available devices. - if args.gpu is not None: - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - torch.npu.set_device(loc) - model = model.to(loc) - else: - torch.cuda.set_device(args.gpu) - model.cuda(args.gpu) - - # When using a single GPU per process and per - # DistributedDataParallel, we need to divide the batch size - # ourselves based on the total number of GPUs we have - args.batch_size = int(args.batch_size / args.world_size) - args.workers = int((args.workers + ngpus_per_node - 1) / ngpus_per_node) - else: - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - model = model.to(loc) - else: - model.cuda() - # DistributedDataParallel will divide and allocate batch_size to all - # available GPUs if device_ids are not set - print("[gpu id:", args.gpu, "]", - "============================test args.gpu is not None else==========================") - elif args.gpu is not None: - print("[gpu id:", args.gpu, "]", - "============================test elif args.gpu is not None:==========================") - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - torch.npu.set_device(args.gpu) - model = model.to(loc) - else: - torch.cuda.set_device(args.gpu) - model = model.cuda(args.gpu) - - else: - # DataParallel will divide and allocate batch_size to all available GPUs - print("[gpu id:", args.gpu, "]", "============================test 1==========================") - print("[gpu id:", args.gpu, "]", "============================test 3==========================") - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - else: - print("before : model = torch.nn.DataParallel(model).cuda()") - - # define loss function (criterion) and optimizer - #optimizer = torch.optim.SGD(model.parameters(), lr=args.lr, - # momentum=args.momentum, - # weight_decay=args.weight_decay,nesterov=True) - optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), args.lr, - momentum=args.momentum, - weight_decay=args.weight_decay) - - - if args.amp: - model, optimizer = amp.initialize( - model, optimizer, opt_level='O1',combine_grad=True) - loss_scaler=ApexScaler() - - if args.distributed: - # For multiprocessing distributed, DistributedDataParallel constructor - # should always set the single device scope, otherwise, - # DistributedDataParallel will use all available devices. - if args.gpu is not None: - # When using a single GPU per process and per - # DistributedDataParallel, we need to divide the batch size - # ourselves based on the total number of GPUs we have - if args.pretrained: - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu], broadcast_buffers=False, - find_unused_parameters=True) - else: - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu], broadcast_buffers=False) - else: - print("[gpu id:", args.gpu, "]", - "============================test args.gpu is not None else==========================") - model = torch.nn.parallel.DistributedDataParallel(model) - elif args.gpu is not None: - print("[gpu id:", args.gpu, "]", - "============================test elif args.gpu is not None:==========================") - else: - # DataParallel will divide and allocate batch_size to all available GPUs - print("[gpu id:", args.gpu, "]", "============================test 1==========================") - print("[gpu id:", args.gpu, "]", "============================test 3==========================") - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - model = torch.nn.DataParallel(model).to(loc) - else: - model = torch.nn.DataParallel(model).cuda() - - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - criterion = nn.CrossEntropyLoss().to(loc) - else: - criterion = nn.CrossEntropyLoss().cuda(args.gpu) - - # optionally resume from a checkpoint - if args.resume: - if os.path.isfile(args.resume): - print("=> loading checkpoint '{}'".format(args.resume)) - if args.gpu is None: - checkpoint = torch.load(args.resume) - else: - # Map model to be loaded to specified single gpu. - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - else: - loc = 'cuda:{}'.format(args.gpu) - checkpoint = torch.load(args.resume, map_location=loc) - args.start_epoch = checkpoint['epoch'] - best_acc1 = checkpoint['best_acc1'] - if args.gpu is not None: - # best_acc1 may be from a checkpoint from a different GPU - best_acc1 = best_acc1.to(args.gpu) - model.load_state_dict(checkpoint['state_dict']) - optimizer.load_state_dict(checkpoint['optimizer']) - if args.amp: - amp.load_state_dict(checkpoint['amp']) - print("=> loaded checkpoint '{}' (epoch {})" - .format(args.resume, checkpoint['epoch'])) - else: - print("=> no checkpoint found at '{}'".format(args.resume)) - - cudnn.benchmark = True - - # Data loading code - traindir = os.path.join(args.data_dir, 'train') - valdir = os.path.join(args.data_dir, 'val') - normalize = transforms.Normalize(mean=[0.5, 0.5, 0.5], - std=[0.5, 0.5, 0.5]) - - train_dataset = datasets.ImageFolder( - traindir, - transforms.Compose([ - transforms.RandomResizedCrop(224,interpolation=3), - transforms.RandomHorizontalFlip(), - transforms.ToTensor(), - normalize, - ])) - - if args.distributed: - train_sampler = torch.utils.data.distributed.DistributedSampler( - train_dataset) - else: - train_sampler = None - - train_loader = torch.utils.data.DataLoader( - train_dataset, batch_size=args.batch_size, shuffle=( - train_sampler is None), - num_workers=args.workers, pin_memory=False, sampler=train_sampler, drop_last=True) - - val_loader = torch.utils.data.DataLoader( - datasets.ImageFolder(valdir, transforms.Compose([ - transforms.Resize(256,interpolation=3), - transforms.CenterCrop(224), - transforms.ToTensor(), - normalize, - ])), - batch_size=args.batch_size, shuffle=True, - num_workers=args.workers, pin_memory=False, drop_last=True) - if args.evaluate: - validate(val_loader, model, criterion, args, ngpus_per_node) - return - - if args.prof: - profiling(train_loader, model, criterion, optimizer, args) - return - - start_time = time.time() - for epoch in range(args.start_epoch, args.epochs): - if args.distributed: - train_sampler.set_epoch(epoch) - # if args.distributed and hasattr(train_loader.sampler, 'set_epoch'): - # train_loader.sampler.set_epoch(epoch) - - adjust_learning_rate(optimizer, epoch, args) - - # train for one epoch - train(train_loader, model, criterion, optimizer, epoch, args, ngpus_per_node,loss_scaler) - - # evaluate on validation set - acc1 = validate(val_loader, model, criterion, args, ngpus_per_node) - - # remember best acc@1 and save checkpoint - is_best = acc1 > best_acc1 - best_acc1 = max(acc1, best_acc1) - if args.device == 'npu' and args.gpu == 0 and epoch == 89: - print("Complete 90 epoch training, take time:{}h".format(round((time.time() - start_time) / 3600.0, 2))) - - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - - ############## npu modify begin ############# - if args.amp: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': 'wide_resnet50_2', - 'state_dict': model.state_dict(), - 'best_acc1': best_acc1, - 'optimizer': optimizer.state_dict(), - 'amp': amp.state_dict(), - }, is_best) - else: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': 'wide_resnet50_2', - 'state_dict': model.state_dict(), - 'best_acc1': best_acc1, - 'optimizer': optimizer.state_dict(), - }, is_best) - ############## npu modify end ############# - - -def profiling(data_loader, model, criterion, optimizer, args): - # switch to train mode - model.train() - - def update(model, images, target, optimizer): - output = model(images) - loss = criterion(output, target) - if args.amp: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.zero_grad() - optimizer.step() - - for step, (images, target) in enumerate(data_loader): - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - images = images.to(loc, non_blocking=True).to(torch.float) - target = target.to(torch.int32).to(loc, non_blocking=True) - else: - images = images.cuda(args.gpu, non_blocking=True) - target = target.cuda(args.gpu, non_blocking=True) - - if step < 5: - update(model, images, target, optimizer) - else: - if args.device == 'npu': - with torch.autograd.profiler.profile(use_npu=True) as prof: - update(model, images, target, optimizer) - else: - with torch.autograd.profiler.profile(use_cuda=True) as prof: - update(model, images, target, optimizer) - break - - prof.export_chrome_trace("output.prof") - - -def train(train_loader, model, criterion, optimizer, epoch, args, ngpus_per_node,loss_scaler): - batch_time = AverageMeter('Time', ':6.3f') - data_time = AverageMeter('Data', ':6.3f') - losses = AverageMeter('Loss', ':.4e') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - progress = ProgressMeter( - len(train_loader), - [batch_time, data_time, losses, top1, top5], - prefix="Epoch: [{}]".format(epoch)) - second_order = hasattr(optimizer, 'is_second_order') and optimizer.is_second_order - # switch to train mode - model.train() - - end = time.time() - for i, (images, target) in enumerate(train_loader): - # measure data loading time - data_time.update(time.time() - end) - - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - images = images.to(loc, non_blocking=True).to(torch.float) - target = target.to(torch.int32).to(loc, non_blocking=True) - else: - images = images.cuda(args.gpu, non_blocking=True) - target = target.cuda(args.gpu, non_blocking=True) - - # compute output - output = model(images) - loss = criterion(output, target) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # compute gradient and do SGD step - optimizer.zero_grad() - if args.amp: - loss_scaler( - loss, optimizer, - clip_grad=args.clip_grad, clip_mode=args.clip_mode, - parameters=model_parameters(model, exclude_head='agc' in args.clip_mode), - create_graph=second_order) - else: - loss.backward() - optimizer.step() - if args.device == 'npu': - torch.npu.synchronize() - - # measure elapsed time - cost_time = time.time() - end - batch_time.update(cost_time) - end = time.time() - - if i % args.print_freq == 0: - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - progress.display(i) - - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - if batch_time.avg: - print("[npu id:", args.gpu, "]", "batch_size:", args.world_size * args.batch_size, - 'Time: {:.3f}'.format(batch_time.avg), '* FPS@all {:.3f}'.format( - args.batch_size * args.world_size / batch_time.avg)) - - -def validate(val_loader, model, criterion, args, ngpus_per_node): - batch_time = AverageMeter('Time', ':6.3f') - losses = AverageMeter('Loss', ':.4e') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - progress = ProgressMeter( - len(val_loader), - [batch_time, losses, top1, top5], - prefix='Test: ') - - # switch to evaluate mode - model.eval() - - with torch.no_grad(): - end = time.time() - for i, (images, target) in enumerate(val_loader): - if args.gpu is not None: - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - images = images.to(loc).to(torch.float) - else: - images = images.cuda(args.gpu, non_blocking=True) - if args.device == 'npu': - loc = 'npu:{}'.format(args.gpu) - target = target.to(torch.int32).to(loc, non_blocking=True) - else: - target = target.cuda(args.gpu, non_blocking=True) - - # compute output - output = model(images) - loss = criterion(output, target) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # measure elapsed time - cost_time = time.time() - end - batch_time.update(cost_time) - end = time.time() - - if i % args.print_freq == 0: - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - progress.display(i) - - if i % args.print_freq == 0: - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - print("[gpu id:", args.gpu, "]", '[AVG-ACC] * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}' - .format(top1=top1, top5=top5)) - - return top1.avg - - -def save_checkpoint(state, is_best, filename='checkpoint.pth.tar'): - torch.save(state, filename) - if is_best: - shutil.copyfile(filename, 'model_best.pth.tar') - - -class AverageMeter(object): - """Computes and stores the average and current value""" - - def __init__(self, name, fmt=':f', start_count_index=2): - self.name = name - self.fmt = fmt - self.reset() - self.start_count_index = start_count_index - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - - def update(self, val, n=1): - if self.count == 0: - self.N = n - - self.val = val - self.count += n - if self.count > (self.start_count_index * self.N): - self.sum += val * n - self.avg = self.sum / (self.count - self.start_count_index * self.N) - - def __str__(self): - fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' - return fmtstr.format(**self.__dict__) - - -class ProgressMeter(object): - - def __init__(self, num_batches, meters, prefix=""): - self.batch_fmtstr = self._get_batch_fmtstr(num_batches) - self.meters = meters - self.prefix = prefix - - def display(self, batch): - entries = [self.prefix + self.batch_fmtstr.format(batch)] - entries += [str(meter) for meter in self.meters] - print('\t'.join(entries)) - - def _get_batch_fmtstr(self, num_batches): - num_digits = len(str(num_batches // 1)) - fmt = '{:' + str(num_digits) + 'd}' - return '[' + fmt + '/' + fmt.format(num_batches) + ']' - - -def adjust_learning_rate(optimizer, epoch, args): - """Sets the learning rate to the initial LR decayed by cosine method""" - - if args.warm_up_epochs > 0 and epoch < args.warm_up_epochs: - lr = args.lr * ((epoch + 1) / (args.warm_up_epochs + 1)) - else: - alpha = 0 - cosine_decay = 0.5 * ( - 1 + np.cos(np.pi * (epoch - args.warm_up_epochs) / (args.epochs - args.warm_up_epochs))) - decayed = (1 - alpha) * cosine_decay + alpha - lr = args.lr * decayed - - print("=> Epoch[%d] Setting lr: %.4f" % (epoch, lr)) - for param_group in optimizer.param_groups: - param_group['lr'] = lr - - -def accuracy(output, target, topk=(1,)): - """Computes the accuracy over the k top predictions for the specified values of k""" - with torch.no_grad(): - maxk = max(topk) - batch_size = target.size(0) - - _, pred = output.topk(maxk, 1, True, True) - pred = pred.t() - correct = pred.eq(target.view(1, -1).expand_as(pred)) - - res = [] - for k in topk: - correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True) - res.append(correct_k.mul_(100.0 / batch_size)) - return res - - -if __name__ == '__main__': - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import argparse +import os +import random +import shutil +import time +import warnings +import torch +import numpy as np +import apex +from apex import amp +import torch.nn as nn +import torch.nn.parallel +import torch.npu +import torch.backends.cudnn as cudnn +import torch.distributed as dist +import torch.optim +import torch.multiprocessing as mp +import torch.utils.data +import torch.utils.data.distributed +import torchvision.transforms as transforms +import torchvision.datasets as datasets +import timm +from timm.utils import ApexScaler +from timm.data import create_dataset,create_loader,resolve_data_config,Mixup, FastCollateMixup, AugMixDataset +from timm.models import model_parameters, create_model +from collections import OrderedDict + +parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') +parser.add_argument('data_dir', metavar='DIR', + help='path to dataset') +parser.add_argument('--dataset', '-d', metavar='NAME', default='', + help='dataset type (default: ImageFolder/ImageTar if empty)') +parser.add_argument('-j', '--workers', default=4, type=int, metavar='N', + help='number of data loading workers (default: 4)') +parser.add_argument('--epochs', default=90, type=int, metavar='N', + help='number of total epochs to run') +parser.add_argument('--start-epoch', default=0, type=int, metavar='N', + help='manual epoch number (useful on restarts)') +parser.add_argument('-b', '--batch-size', default=256, type=int, + metavar='N', + help='mini-batch size (default: 256), this is the total ' + 'batch size of all GPUs on the current node when ' + 'using Data Parallel or Distributed Data Parallel') +parser.add_argument('--lr', '--learning-rate', default=0.1, type=float, + metavar='LR', help='initial learning rate', dest='lr') +parser.add_argument('--momentum', default=0.9, type=float, metavar='M', + help='momentum') +parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, + metavar='W', help='weight decay (default: 1e-4)', + dest='weight_decay') +parser.add_argument('-p', '--print-freq', default=10, type=int, + metavar='N', help='print frequency (default: 10)') +parser.add_argument('--resume', default='', type=str, metavar='PATH', + help='path to latest checkpoint (default: none)') +parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', + help='evaluate model on validation set') +parser.add_argument('--pretrained', dest='pretrained', action='store_true', + help='use pre-trained model') +parser.add_argument('--world-size', default=-1, type=int, + help='number of nodes for distributed training') +parser.add_argument('--rank', default=-1, type=int, + help='node rank for distributed training') +parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str, + help='url used to set up distributed training') +parser.add_argument('--dist-backend', default='nccl', type=str, + help='distributed backend') +parser.add_argument('--seed', default=None, type=int, + help='seed for initializing training. ') +parser.add_argument('--gpu', default=None, type=int, + help='GPU id to use.') +parser.add_argument('--multiprocessing-distributed', action='store_true', + help='Use multi-processing distributed training to launch ' + 'N processes per node, which has N GPUs. This is the ' + 'fastest way to use PyTorch for either single node or ' + 'multi node data parallel training') +parser.add_argument('--num-classes', default=1000, type=int, + help='The number of classes.') +## for ascend 910 +parser.add_argument('--device', default='npu', type=str, help='npu or gpu') +parser.add_argument('--addr', default='10.136.181.115', + type=str, help='master addr') +parser.add_argument('--device_list', default='0,1,2,3,4,5,6,7', + type=str, help='device id list') +parser.add_argument('--warm_up_epochs', default=0, type=int, + help='warm up') +parser.add_argument('--amp', default=False, action='store_true', + help='use amp to train the model') +parser.add_argument('--loss-scale', default=8, type=float, + help='loss scale using in amp, default -1 means dynamic') +parser.add_argument('--opt-level', default='O2', type=str, + help='loss scale using in amp, default -1 means dynamic') +parser.add_argument('--prof', default=False, action='store_true', + help='use profiling to evaluate the performance of model') + +#Additional parameters from author +parser.add_argument('--train-split', metavar='NAME', default='train', + help='dataset train split (default: train)') +parser.add_argument('--val-split', metavar='NAME', default='val', + help='dataset validation split (default: validation)') +parser.add_argument('--model', default='resnet50', type=str, metavar='MODEL', + help='Name of model to train (default: "resnet50"') +parser.add_argument('--initial-checkpoint', default='', type=str, metavar='PATH', + help='Initialize model from this checkpoint (default: none)') +parser.add_argument('--no-resume-opt', action='store_true', default=False, + help='prevent resume of optimizer state when resuming model') +parser.add_argument('--gp', default=None, type=str, metavar='POOL', + help='Global pool type, one of (fast, avg, max, avgmax, avgmaxc). Model default if None.') +parser.add_argument('--img-size', type=int, default=None, metavar='N', + help='Image patch size (default: None => model default)') +parser.add_argument('--input-size', default=None, nargs=3, type=int, + metavar='N N N', help='Input all image dimensions (d h w, e.g. --input-size 3 224 224), uses model default if empty') +parser.add_argument('--crop-pct', default=None, type=float, + metavar='N', help='Input image center crop percent (for validation only)') +parser.add_argument('--mean', type=float, nargs='+', default=None, metavar='MEAN', + help='Override mean pixel value of dataset') +parser.add_argument('--std', type=float, nargs='+', default=None, metavar='STD', + help='Override std deviation of of dataset') +parser.add_argument('--interpolation', default='', type=str, metavar='NAME', + help='Image resize interpolation type (overrides model)') +parser.add_argument('-vb', '--validation-batch-size', type=int, default=None, metavar='N', + help='validation batch size override (default: None)') + +# Optimizer parameters +parser.add_argument('--opt', default='sgd', type=str, metavar='OPTIMIZER', + help='Optimizer (default: "sgd"') +parser.add_argument('--opt-eps', default=None, type=float, metavar='EPSILON', + help='Optimizer Epsilon (default: None, use opt default)') +parser.add_argument('--opt-betas', default=None, type=float, nargs='+', metavar='BETA', + help='Optimizer Betas (default: None, use opt default)') +parser.add_argument('--clip-grad', type=float, default=None, metavar='NORM', + help='Clip gradient norm (default: None, no clipping)') +parser.add_argument('--clip-mode', type=str, default='norm', + help='Gradient clipping mode. One of ("norm", "value", "agc")') + + +# Learning rate schedule parameters +parser.add_argument('--sched', default='cosine', type=str, metavar='SCHEDULER', + help='LR scheduler (default: "step"') +parser.add_argument('--lr-noise', type=float, nargs='+', default=None, metavar='pct, pct', + help='learning rate noise on/off epoch percentages') +parser.add_argument('--lr-noise-pct', type=float, default=0.67, metavar='PERCENT', + help='learning rate noise limit percent (default: 0.67)') +parser.add_argument('--lr-noise-std', type=float, default=1.0, metavar='STDDEV', + help='learning rate noise std-dev (default: 1.0)') +parser.add_argument('--lr-cycle-mul', type=float, default=1.0, metavar='MULT', + help='learning rate cycle len multiplier (default: 1.0)') +parser.add_argument('--lr-cycle-decay', type=float, default=0.5, metavar='MULT', + help='amount to decay each learning rate cycle (default: 0.5)') +parser.add_argument('--lr-cycle-limit', type=int, default=1, metavar='N', + help='learning rate cycle limit, cycles enabled if > 1') +parser.add_argument('--lr-k-decay', type=float, default=1.0, + help='learning rate k-decay for cosine/poly (default: 1.0)') +parser.add_argument('--warmup-lr', type=float, default=0.0001, metavar='LR', + help='warmup learning rate (default: 0.0001)') +parser.add_argument('--min-lr', type=float, default=1e-6, metavar='LR', + help='lower lr bound for cyclic schedulers that hit 0 (1e-5)') +parser.add_argument('--epoch-repeats', type=float, default=0., metavar='N', + help='epoch repeat multiplier (number of times to repeat dataset epoch per train epoch).') +parser.add_argument('--decay-epochs', type=float, default=100, metavar='N', + help='epoch interval to decay LR') +parser.add_argument('--warmup-epochs', type=int, default=3, metavar='N', + help='epochs to warmup LR, if scheduler supports') +parser.add_argument('--cooldown-epochs', type=int, default=10, metavar='N', + help='epochs to cooldown LR at min_lr, after cyclic schedule ends') +parser.add_argument('--patience-epochs', type=int, default=10, metavar='N', + help='patience epochs for Plateau LR scheduler (default: 10') +parser.add_argument('--decay-rate', '--dr', type=float, default=0.1, metavar='RATE', + help='LR decay rate (default: 0.1)') + +# Augmentation & regularization parameters +parser.add_argument('--no-aug', action='store_true', default=False, + help='Disable all training augmentation, override other train aug args') +parser.add_argument('--scale', type=float, nargs='+', default=[0.08, 1.0], metavar='PCT', + help='Random resize scale (default: 0.08 1.0)') +parser.add_argument('--ratio', type=float, nargs='+', default=[3./4., 4./3.], metavar='RATIO', + help='Random resize aspect ratio (default: 0.75 1.33)') +parser.add_argument('--hflip', type=float, default=0.5, + help='Horizontal flip training aug probability') +parser.add_argument('--vflip', type=float, default=0., + help='Vertical flip training aug probability') +parser.add_argument('--color-jitter', type=float, default=0.4, metavar='PCT', + help='Color jitter factor (default: 0.4)') +parser.add_argument('--aa', type=str, default=None, metavar='NAME', + help='Use AutoAugment policy. "v0" or "original". (default: None)'), +parser.add_argument('--aug-repeats', type=int, default=0, + help='Number of augmentation repetitions (distributed training only) (default: 0)') +parser.add_argument('--aug-splits', type=int, default=0, + help='Number of augmentation splits (default: 0, valid: 0 or >=2)') +parser.add_argument('--jsd-loss', action='store_true', default=False, + help='Enable Jensen-Shannon Divergence + CE loss. Use with `--aug-splits`.') +parser.add_argument('--bce-loss', action='store_true', default=False, + help='Enable BCE loss w/ Mixup/CutMix use.') +parser.add_argument('--reprob', type=float, default=0., metavar='PCT', + help='Random erase prob (default: 0.)') +parser.add_argument('--remode', type=str, default='pixel', + help='Random erase mode (default: "pixel")') +parser.add_argument('--recount', type=int, default=1, + help='Random erase count (default: 1)') +parser.add_argument('--resplit', action='store_true', default=False, + help='Do not random erase first (clean) augmentation split') +parser.add_argument('--mixup', type=float, default=0.0, + help='mixup alpha, mixup enabled if > 0. (default: 0.)') +parser.add_argument('--cutmix', type=float, default=0.0, + help='cutmix alpha, cutmix enabled if > 0. (default: 0.)') +parser.add_argument('--cutmix-minmax', type=float, nargs='+', default=None, + help='cutmix min/max ratio, overrides alpha and enables cutmix if set (default: None)') +parser.add_argument('--mixup-prob', type=float, default=1.0, + help='Probability of performing mixup or cutmix when either/both is enabled') +parser.add_argument('--mixup-switch-prob', type=float, default=0.5, + help='Probability of switching to cutmix when both mixup and cutmix enabled') +parser.add_argument('--mixup-mode', type=str, default='batch', + help='How to apply mixup/cutmix params. Per "batch", "pair", or "elem"') +parser.add_argument('--mixup-off-epoch', default=0, type=int, metavar='N', + help='Turn off mixup after this epoch, disabled if 0 (default: 0)') +parser.add_argument('--smoothing', type=float, default=0.1, + help='Label smoothing (default: 0.1)') +parser.add_argument('--train-interpolation', type=str, default='random', + help='Training interpolation (random, bilinear, bicubic default: "random")') +parser.add_argument('--drop', type=float, default=0.0, metavar='PCT', + help='Dropout rate (default: 0.)') +parser.add_argument('--drop-connect', type=float, default=None, metavar='PCT', + help='Drop connect rate, DEPRECATED, use drop-path (default: None)') +parser.add_argument('--drop-path', type=float, default=None, metavar='PCT', + help='Drop path rate (default: None)') +parser.add_argument('--drop-block', type=float, default=None, metavar='PCT', + help='Drop block rate (default: None)') + +# Batch norm parameters (only works with gen_efficientnet based models currently) +parser.add_argument('--bn-tf', action='store_true', default=False, + help='Use Tensorflow BatchNorm defaults for models that support it (default: False)') +parser.add_argument('--bn-momentum', type=float, default=None, + help='BatchNorm momentum override (if not None)') +parser.add_argument('--bn-eps', type=float, default=None, + help='BatchNorm epsilon override (if not None)') +parser.add_argument('--sync-bn', action='store_true', + help='Enable NVIDIA Apex or Torch synchronized BatchNorm.') +parser.add_argument('--dist-bn', type=str, default='reduce', + help='Distribute BatchNorm stats between nodes after each epoch ("broadcast", "reduce", or "")') +parser.add_argument('--split-bn', action='store_true', + help='Enable separate BN layers per augmentation split.') + +# Model Exponential Moving Average +parser.add_argument('--model-ema', action='store_true', default=False, + help='Enable tracking moving average of model weights') +parser.add_argument('--model-ema-force-cpu', action='store_true', default=False, + help='Force ema to be tracked on CPU, rank=0 node only. Disables EMA validation.') +parser.add_argument('--model-ema-decay', type=float, default=0.9998, + help='decay factor for model weights moving average (default: 0.9998)') + +# Misc +parser.add_argument('--log-interval', type=int, default=50, metavar='N', + help='how many batches to wait before logging training status') +parser.add_argument('--recovery-interval', type=int, default=0, metavar='N', + help='how many batches to wait before writing recovery checkpoint') +parser.add_argument('--checkpoint-hist', type=int, default=10, metavar='N', + help='number of checkpoints to keep (default: 10)') +parser.add_argument('--save-images', action='store_true', default=False, + help='save images of input bathes every log interval for debugging') +parser.add_argument('--apex-amp', action='store_true', default=False, + help='Use NVIDIA Apex AMP mixed precision') +parser.add_argument('--native-amp', action='store_true', default=False, + help='Use Native Torch AMP mixed precision') +parser.add_argument('--channels-last', action='store_true', default=False, + help='Use channels_last memory layout') +parser.add_argument('--pin-mem', action='store_true', default=False, + help='Pin CPU memory in DataLoader for more efficient (sometimes) transfer to GPU.') +parser.add_argument('--no-prefetcher', action='store_true', default=False, + help='disable fast prefetcher') +parser.add_argument('--output', default='', type=str, metavar='PATH', + help='path to output folder (default: none, current dir)') +parser.add_argument('--experiment', default='', type=str, metavar='NAME', + help='name of train experiment, name of sub-folder for output') +parser.add_argument('--eval-metric', default='top1', type=str, metavar='EVAL_METRIC', + help='Best metric (default: "top1"') +parser.add_argument('--tta', type=int, default=0, metavar='N', + help='Test/inference time augmentation (oversampling) factor. 0=None (default: 0)') +parser.add_argument("--local_rank", default=0, type=int) +parser.add_argument('--use-multi-epochs-loader', action='store_true', default=False, + help='use the multi-epochs-loader to save time at the beginning of every epoch') +parser.add_argument('--torchscript', dest='torchscript', action='store_true', + help='convert model torchscript for inference') +parser.add_argument('--log-wandb', action='store_true', default=False, + help='log training and validation metrics to wandb') +parser.add_argument('--model-path',type=str) +best_acc1 = 0 + + +def device_id_to_process_device_map(device_list): + devices = device_list.split(",") + devices = [int(x) for x in devices] + devices.sort() + + process_device_map = dict() + for process_id, device_id in enumerate(devices): + process_device_map[process_id] = device_id + + return process_device_map + +def proc_nodes_module(checkpoint,AttrName): + new_state_dict = OrderedDict() + for k, v in checkpoint[AttrName].items(): + if "module." in k: + name = k.replace("module.", "") + else: + name = k + new_state_dict[name] = v + return new_state_dict + + +def main(): + + args = parser.parse_args() + print(args.device_list) + + os.environ['MASTER_ADDR'] = args.addr + os.environ['MASTER_PORT'] = '29688' + + if args.seed is not None: + random.seed(args.seed) + torch.manual_seed(args.seed) + cudnn.deterministic = True + warnings.warn('You have chosen to seed training. ' + 'This will turn on the CUDNN deterministic setting, ' + 'which can slow down your training considerably! ' + 'You may see unexpected behavior when restarting ' + 'from checkpoints.') + + if args.gpu is not None: + warnings.warn('You have chosen a specific GPU. This will completely ' + 'disable data parallelism.') + + if args.dist_url == "env://" and args.world_size == -1: + args.world_size = int(os.environ["WORLD_SIZE"]) + + args.distributed = args.world_size > 1 or args.multiprocessing_distributed + + args.process_device_map = device_id_to_process_device_map(args.device_list) + + if args.device == 'npu': + ngpus_per_node = len(args.process_device_map) + else: + if args.distributed: + ngpus_per_node = torch.cuda.device_count() + else: + ngpus_per_node = 1 + print('ngpus_per_node:', ngpus_per_node) + if args.multiprocessing_distributed: + # Since we have ngpus_per_node processes per node, the total world_size + # needs to be adjusted accordingly + args.world_size = ngpus_per_node * args.world_size + # Use torch.multiprocessing.spawn to launch distributed processes: the + # main_worker process function + mp.spawn(main_worker, nprocs=ngpus_per_node, + args=(ngpus_per_node, args)) + else: + # Simply call main_worker function + main_worker(args.gpu, ngpus_per_node, args) + + +def main_worker(gpu, ngpus_per_node, args): + global best_acc1 + args.gpu = args.process_device_map[gpu] + + if args.gpu is not None: + print("Use GPU: {} for training".format(args.gpu)) + print("Is distributed train available?",dist.is_available()) + if args.distributed: + if args.dist_url == "env://" and args.rank == -1: + print("According to url") + args.rank = int(os.environ["RANK"]) + print("endif") + if args.multiprocessing_distributed: + # For multiprocessing distributed training, rank needs to be the + # global rank among all the processes + args.rank = args.rank * ngpus_per_node + gpu + + if args.device == 'npu': + print("enter npu dis") + dist.init_process_group(backend=args.dist_backend, # init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + print("leave npu dist") + else: + dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + # create model + if args.pretrained: + print("=> using pre-trained model vit_base_patch32") + model = create_model( + "vit_base_patch32_224_in21k", + pretrained=args.pretrained, + num_classes=1000, + drop_rate=args.drop, + drop_connect_rate=args.drop_connect, # DEPRECATED, use drop_path + drop_path_rate=args.drop_path, + drop_block_rate=args.drop_block, + global_pool=args.gp, + bn_tf=args.bn_tf, + bn_momentum=args.bn_momentum, + bn_eps=args.bn_eps, + scriptable=args.torchscript, + checkpoint_path=args.initial_checkpoint) + data_config = resolve_data_config(vars(args), model=model, verbose=args.local_rank == 0) + #model = timm.create_model("vit_base_patch32_224_in21k",pretrained=True,num_classes=1000) + #print("loading model of yours...") + #pretrained_dict = torch.load("./model_best.pth.tar", map_location="cpu")["state_dict"] + #model.load_state_dict({k.replace('module.',''):v for k, v in pretrained_dict.items()}) + #if "fc.weight" in pretrained_dict: + # pretrained_dict.pop('fc.weight') + # pretrained_dict.pop('fc.bias') + #model.load_state_dict(pretrained_dict, strict=False) + else: + print("=> creating model vit_base_patch32") + model = model = timm.create_model("vit_base_patch32_224",num_classes=1000) + pretrained_dict = torch.load(args.model_path, map_location="cpu") + pretrained_dict['state_dict']=proc_nodes_module(pretrained_dict,'state_dict') + model.load_state_dict(pretrained_dict['state_dict']) + model.head = nn.Linear(768, args.num_classes) if args.num_classes > 0 else nn.Identity() + + + if args.distributed: + # For multiprocessing distributed, DistributedDataParallel constructor + # should always set the single device scope, otherwise, + # DistributedDataParallel will use all available devices. + if args.gpu is not None: + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + torch.npu.set_device(loc) + model = model.to(loc) + else: + torch.cuda.set_device(args.gpu) + model.cuda(args.gpu) + + # When using a single GPU per process and per + # DistributedDataParallel, we need to divide the batch size + # ourselves based on the total number of GPUs we have + args.batch_size = int(args.batch_size / args.world_size) + args.workers = int((args.workers + ngpus_per_node - 1) / ngpus_per_node) + else: + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + model = model.to(loc) + else: + model.cuda() + # DistributedDataParallel will divide and allocate batch_size to all + # available GPUs if device_ids are not set + print("[gpu id:", args.gpu, "]", + "============================test args.gpu is not None else==========================") + elif args.gpu is not None: + print("[gpu id:", args.gpu, "]", + "============================test elif args.gpu is not None:==========================") + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + torch.npu.set_device(args.gpu) + model = model.to(loc) + else: + torch.cuda.set_device(args.gpu) + model = model.cuda(args.gpu) + + else: + # DataParallel will divide and allocate batch_size to all available GPUs + print("[gpu id:", args.gpu, "]", "============================test 1==========================") + print("[gpu id:", args.gpu, "]", "============================test 3==========================") + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + else: + print("before : model = torch.nn.DataParallel(model).cuda()") + + # define loss function (criterion) and optimizer + #optimizer = torch.optim.SGD(model.parameters(), lr=args.lr, + # momentum=args.momentum, + # weight_decay=args.weight_decay,nesterov=True) + optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), args.lr, + momentum=args.momentum, + weight_decay=args.weight_decay) + + + if args.amp: + model, optimizer = amp.initialize( + model, optimizer, opt_level='O1',combine_grad=True) + loss_scaler=ApexScaler() + + if args.distributed: + # For multiprocessing distributed, DistributedDataParallel constructor + # should always set the single device scope, otherwise, + # DistributedDataParallel will use all available devices. + if args.gpu is not None: + # When using a single GPU per process and per + # DistributedDataParallel, we need to divide the batch size + # ourselves based on the total number of GPUs we have + if args.pretrained: + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu], broadcast_buffers=False, + find_unused_parameters=True) + else: + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu], broadcast_buffers=False) + else: + print("[gpu id:", args.gpu, "]", + "============================test args.gpu is not None else==========================") + model = torch.nn.parallel.DistributedDataParallel(model) + elif args.gpu is not None: + print("[gpu id:", args.gpu, "]", + "============================test elif args.gpu is not None:==========================") + else: + # DataParallel will divide and allocate batch_size to all available GPUs + print("[gpu id:", args.gpu, "]", "============================test 1==========================") + print("[gpu id:", args.gpu, "]", "============================test 3==========================") + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + model = torch.nn.DataParallel(model).to(loc) + else: + model = torch.nn.DataParallel(model).cuda() + + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + criterion = nn.CrossEntropyLoss().to(loc) + else: + criterion = nn.CrossEntropyLoss().cuda(args.gpu) + + # optionally resume from a checkpoint + if args.resume: + if os.path.isfile(args.resume): + print("=> loading checkpoint '{}'".format(args.resume)) + if args.gpu is None: + checkpoint = torch.load(args.resume) + else: + # Map model to be loaded to specified single gpu. + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + else: + loc = 'cuda:{}'.format(args.gpu) + checkpoint = torch.load(args.resume, map_location=loc) + args.start_epoch = checkpoint['epoch'] + best_acc1 = checkpoint['best_acc1'] + if args.gpu is not None: + # best_acc1 may be from a checkpoint from a different GPU + best_acc1 = best_acc1.to(args.gpu) + model.load_state_dict(checkpoint['state_dict']) + optimizer.load_state_dict(checkpoint['optimizer']) + if args.amp: + amp.load_state_dict(checkpoint['amp']) + print("=> loaded checkpoint '{}' (epoch {})" + .format(args.resume, checkpoint['epoch'])) + else: + print("=> no checkpoint found at '{}'".format(args.resume)) + + cudnn.benchmark = True + + # Data loading code + traindir = os.path.join(args.data_dir, 'train') + valdir = os.path.join(args.data_dir, 'val') + normalize = transforms.Normalize(mean=[0.5, 0.5, 0.5], + std=[0.5, 0.5, 0.5]) + + train_dataset = datasets.ImageFolder( + traindir, + transforms.Compose([ + transforms.RandomResizedCrop(224,interpolation=3), + transforms.RandomHorizontalFlip(), + transforms.ToTensor(), + normalize, + ])) + + if args.distributed: + train_sampler = torch.utils.data.distributed.DistributedSampler( + train_dataset) + else: + train_sampler = None + + train_loader = torch.utils.data.DataLoader( + train_dataset, batch_size=args.batch_size, shuffle=( + train_sampler is None), + num_workers=args.workers, pin_memory=False, sampler=train_sampler, drop_last=True) + + val_loader = torch.utils.data.DataLoader( + datasets.ImageFolder(valdir, transforms.Compose([ + transforms.Resize(256,interpolation=3), + transforms.CenterCrop(224), + transforms.ToTensor(), + normalize, + ])), + batch_size=args.batch_size, shuffle=True, + num_workers=args.workers, pin_memory=False, drop_last=True) + if args.evaluate: + validate(val_loader, model, criterion, args, ngpus_per_node) + return + + if args.prof: + profiling(train_loader, model, criterion, optimizer, args) + return + + start_time = time.time() + for epoch in range(args.start_epoch, args.epochs): + if args.distributed: + train_sampler.set_epoch(epoch) + # if args.distributed and hasattr(train_loader.sampler, 'set_epoch'): + # train_loader.sampler.set_epoch(epoch) + + adjust_learning_rate(optimizer, epoch, args) + + # train for one epoch + train(train_loader, model, criterion, optimizer, epoch, args, ngpus_per_node,loss_scaler) + + # evaluate on validation set + acc1 = validate(val_loader, model, criterion, args, ngpus_per_node) + + # remember best acc@1 and save checkpoint + is_best = acc1 > best_acc1 + best_acc1 = max(acc1, best_acc1) + if args.device == 'npu' and args.gpu == 0 and epoch == 89: + print("Complete 90 epoch training, take time:{}h".format(round((time.time() - start_time) / 3600.0, 2))) + + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + + ############## npu modify begin ############# + if args.amp: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': 'wide_resnet50_2', + 'state_dict': model.state_dict(), + 'best_acc1': best_acc1, + 'optimizer': optimizer.state_dict(), + 'amp': amp.state_dict(), + }, is_best) + else: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': 'wide_resnet50_2', + 'state_dict': model.state_dict(), + 'best_acc1': best_acc1, + 'optimizer': optimizer.state_dict(), + }, is_best) + ############## npu modify end ############# + + +def profiling(data_loader, model, criterion, optimizer, args): + # switch to train mode + model.train() + + def update(model, images, target, optimizer): + output = model(images) + loss = criterion(output, target) + if args.amp: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.zero_grad() + optimizer.step() + + for step, (images, target) in enumerate(data_loader): + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + images = images.to(loc, non_blocking=True).to(torch.float) + target = target.to(torch.int32).to(loc, non_blocking=True) + else: + images = images.cuda(args.gpu, non_blocking=True) + target = target.cuda(args.gpu, non_blocking=True) + + if step < 5: + update(model, images, target, optimizer) + else: + if args.device == 'npu': + with torch.autograd.profiler.profile(use_npu=True) as prof: + update(model, images, target, optimizer) + else: + with torch.autograd.profiler.profile(use_cuda=True) as prof: + update(model, images, target, optimizer) + break + + prof.export_chrome_trace("output.prof") + + +def train(train_loader, model, criterion, optimizer, epoch, args, ngpus_per_node,loss_scaler): + batch_time = AverageMeter('Time', ':6.3f') + data_time = AverageMeter('Data', ':6.3f') + losses = AverageMeter('Loss', ':.4e') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + progress = ProgressMeter( + len(train_loader), + [batch_time, data_time, losses, top1, top5], + prefix="Epoch: [{}]".format(epoch)) + second_order = hasattr(optimizer, 'is_second_order') and optimizer.is_second_order + # switch to train mode + model.train() + + end = time.time() + for i, (images, target) in enumerate(train_loader): + # measure data loading time + data_time.update(time.time() - end) + + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + images = images.to(loc, non_blocking=True).to(torch.float) + target = target.to(torch.int32).to(loc, non_blocking=True) + else: + images = images.cuda(args.gpu, non_blocking=True) + target = target.cuda(args.gpu, non_blocking=True) + + # compute output + output = model(images) + loss = criterion(output, target) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # compute gradient and do SGD step + optimizer.zero_grad() + if args.amp: + loss_scaler( + loss, optimizer, + clip_grad=args.clip_grad, clip_mode=args.clip_mode, + parameters=model_parameters(model, exclude_head='agc' in args.clip_mode), + create_graph=second_order) + else: + loss.backward() + optimizer.step() + if args.device == 'npu': + torch.npu.synchronize() + + # measure elapsed time + cost_time = time.time() - end + batch_time.update(cost_time) + end = time.time() + + if i % args.print_freq == 0: + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + progress.display(i) + + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + if batch_time.avg: + print("[npu id:", args.gpu, "]", "batch_size:", args.world_size * args.batch_size, + 'Time: {:.3f}'.format(batch_time.avg), '* FPS@all {:.3f}'.format( + args.batch_size * args.world_size / batch_time.avg)) + + +def validate(val_loader, model, criterion, args, ngpus_per_node): + batch_time = AverageMeter('Time', ':6.3f') + losses = AverageMeter('Loss', ':.4e') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + progress = ProgressMeter( + len(val_loader), + [batch_time, losses, top1, top5], + prefix='Test: ') + + # switch to evaluate mode + model.eval() + + with torch.no_grad(): + end = time.time() + for i, (images, target) in enumerate(val_loader): + if args.gpu is not None: + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + images = images.to(loc).to(torch.float) + else: + images = images.cuda(args.gpu, non_blocking=True) + if args.device == 'npu': + loc = 'npu:{}'.format(args.gpu) + target = target.to(torch.int32).to(loc, non_blocking=True) + else: + target = target.cuda(args.gpu, non_blocking=True) + + # compute output + output = model(images) + loss = criterion(output, target) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # measure elapsed time + cost_time = time.time() - end + batch_time.update(cost_time) + end = time.time() + + if i % args.print_freq == 0: + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + progress.display(i) + + if i % args.print_freq == 0: + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + print("[gpu id:", args.gpu, "]", '[AVG-ACC] * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}' + .format(top1=top1, top5=top5)) + + return top1.avg + + +def save_checkpoint(state, is_best, filename='checkpoint.pth.tar'): + torch.save(state, filename) + if is_best: + shutil.copyfile(filename, 'model_best.pth.tar') + + +class AverageMeter(object): + """Computes and stores the average and current value""" + + def __init__(self, name, fmt=':f', start_count_index=2): + self.name = name + self.fmt = fmt + self.reset() + self.start_count_index = start_count_index + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + if self.count == 0: + self.N = n + + self.val = val + self.count += n + if self.count > (self.start_count_index * self.N): + self.sum += val * n + self.avg = self.sum / (self.count - self.start_count_index * self.N) + + def __str__(self): + fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' + return fmtstr.format(**self.__dict__) + + +class ProgressMeter(object): + + def __init__(self, num_batches, meters, prefix=""): + self.batch_fmtstr = self._get_batch_fmtstr(num_batches) + self.meters = meters + self.prefix = prefix + + def display(self, batch): + entries = [self.prefix + self.batch_fmtstr.format(batch)] + entries += [str(meter) for meter in self.meters] + print('\t'.join(entries)) + + def _get_batch_fmtstr(self, num_batches): + num_digits = len(str(num_batches // 1)) + fmt = '{:' + str(num_digits) + 'd}' + return '[' + fmt + '/' + fmt.format(num_batches) + ']' + + +def adjust_learning_rate(optimizer, epoch, args): + """Sets the learning rate to the initial LR decayed by cosine method""" + + if args.warm_up_epochs > 0 and epoch < args.warm_up_epochs: + lr = args.lr * ((epoch + 1) / (args.warm_up_epochs + 1)) + else: + alpha = 0 + cosine_decay = 0.5 * ( + 1 + np.cos(np.pi * (epoch - args.warm_up_epochs) / (args.epochs - args.warm_up_epochs))) + decayed = (1 - alpha) * cosine_decay + alpha + lr = args.lr * decayed + + print("=> Epoch[%d] Setting lr: %.4f" % (epoch, lr)) + for param_group in optimizer.param_groups: + param_group['lr'] = lr + + +def accuracy(output, target, topk=(1,)): + """Computes the accuracy over the k top predictions for the specified values of k""" + with torch.no_grad(): + maxk = max(topk) + batch_size = target.size(0) + + _, pred = output.topk(maxk, 1, True, True) + pred = pred.t() + correct = pred.eq(target.view(1, -1).expand_as(pred)) + + res = [] + for k in topk: + correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True) + res.append(correct_k.mul_(100.0 / batch_size)) + return res + + +if __name__ == '__main__': + main() diff --git a/PyTorch/contrib/cv/detection/CascadedMaskRCNN/detectron2/structures/masks.py b/PyTorch/contrib/cv/detection/CascadedMaskRCNN/detectron2/structures/masks.py index a4d97d942eafbe3ea1bd71fad42b942e9aa5168d..3933471d084b42fc2e0e055d7452d1660e7dc0f1 100644 --- a/PyTorch/contrib/cv/detection/CascadedMaskRCNN/detectron2/structures/masks.py +++ b/PyTorch/contrib/cv/detection/CascadedMaskRCNN/detectron2/structures/masks.py @@ -1,442 +1,442 @@ -# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import copy -import itertools -import numpy as np -from typing import Any, Iterator, List, Union -import pycocotools.mask as mask_util -import torch - -from detectron2.layers.roi_align import ROIAlign - -from .boxes import Boxes - - -def polygon_area(x, y): - # Using the shoelace formula - # https://stackoverflow.com/questions/24467972/calculate-area-of-polygon-given-x-y-coordinates - return 0.5 * np.abs(np.dot(x, np.roll(y, 1)) - np.dot(y, np.roll(x, 1))) - - -def polygons_to_bitmask(polygons: List[np.ndarray], height: int, width: int) -> np.ndarray: - """ - Args: - polygons (list[ndarray]): each array has shape (Nx2,) - height, width (int) - - Returns: - ndarray: a bool mask of shape (height, width) - """ - assert len(polygons) > 0, "COCOAPI does not support empty polygons" - rles = mask_util.frPyObjects(polygons, height, width) - rle = mask_util.merge(rles) - return mask_util.decode(rle).astype(np.bool) - - -def rasterize_polygons_within_box( - polygons: List[np.ndarray], box: np.ndarray, mask_size: int -) -> torch.Tensor: - """ - Rasterize the polygons into a mask image and - crop the mask content in the given box. - The cropped mask is resized to (mask_size, mask_size). - - This function is used when generating training targets for mask head in Mask R-CNN. - Given original ground-truth masks for an image, new ground-truth mask - training targets in the size of `mask_size x mask_size` - must be provided for each predicted box. This function will be called to - produce such targets. - - Args: - polygons (list[ndarray[float]]): a list of polygons, which represents an instance. - box: 4-element numpy array - mask_size (int): - - Returns: - Tensor: BoolTensor of shape (mask_size, mask_size) - """ - # 1. Shift the polygons w.r.t the boxes - w, h = box[2] - box[0], box[3] - box[1] - - polygons = copy.deepcopy(polygons) - for p in polygons: - p[0::2] = p[0::2] - box[0] - p[1::2] = p[1::2] - box[1] - - # 2. Rescale the polygons to the new box size - # max() to avoid division by small number - ratio_h = mask_size / max(h, 0.1) - ratio_w = mask_size / max(w, 0.1) - - if ratio_h == ratio_w: - for p in polygons: - p *= ratio_h - else: - for p in polygons: - p[0::2] *= ratio_w - p[1::2] *= ratio_h - - # 3. Rasterize the polygons with coco api - mask = polygons_to_bitmask(polygons, mask_size, mask_size) - mask = torch.from_numpy(mask) - return mask - - -class BitMasks: - """ - This class stores the segmentation masks for all objects in one image, in - the form of bitmaps. - - Attributes: - tensor: bool Tensor of N,H,W, representing N instances in the image. - """ - - def __init__(self, tensor: Union[torch.Tensor, np.ndarray]): - """ - Args: - tensor: bool Tensor of N,H,W, representing N instances in the image. - """ - device = tensor.device if isinstance(tensor, torch.Tensor) else torch.device("cpu") - tensor = torch.as_tensor(tensor, dtype=torch.bool, device=device) - assert tensor.dim() == 3, tensor.size() - self.image_size = tensor.shape[1:] - self.tensor = tensor - - def to(self, *args: Any, **kwargs: Any) -> "BitMasks": - return BitMasks(self.tensor.to(*args, **kwargs)) - - @property - def device(self) -> torch.device: - return self.tensor.device - - def __getitem__(self, item: Union[int, slice, torch.BoolTensor]) -> "BitMasks": - """ - Returns: - BitMasks: Create a new :class:`BitMasks` by indexing. - - The following usage are allowed: - - 1. `new_masks = masks[3]`: return a `BitMasks` which contains only one mask. - 2. `new_masks = masks[2:10]`: return a slice of masks. - 3. `new_masks = masks[vector]`, where vector is a torch.BoolTensor - with `length = len(masks)`. Nonzero elements in the vector will be selected. - - Note that the returned object might share storage with this object, - subject to Pytorch's indexing semantics. - """ - if isinstance(item, int): - return BitMasks(self.tensor[item].view(1, -1)) - - if item.dtype == torch.int32: - m = self.tensor[item.long()] - else: - m = self.tensor[item] - - assert m.dim() == 3, "Indexing on BitMasks with {} returns a tensor with shape {}!".format( - item, m.shape - ) - return BitMasks(m) - - def __iter__(self) -> torch.Tensor: - yield from self.tensor - - def __repr__(self) -> str: - s = self.__class__.__name__ + "(" - s += "num_instances={})".format(len(self.tensor)) - return s - - def __len__(self) -> int: - return self.tensor.shape[0] - - def nonempty(self) -> torch.Tensor: - """ - Find masks that are non-empty. - - Returns: - Tensor: a BoolTensor which represents - whether each mask is empty (False) or non-empty (True). - """ - return self.tensor.flatten(1).any(dim=1) - - @staticmethod - def from_polygon_masks( - polygon_masks: Union["PolygonMasks", List[List[np.ndarray]]], height: int, width: int - ) -> "BitMasks": - """ - Args: - polygon_masks (list[list[ndarray]] or PolygonMasks) - height, width (int) - """ - if isinstance(polygon_masks, PolygonMasks): - polygon_masks = polygon_masks.polygons - masks = [polygons_to_bitmask(p, height, width) for p in polygon_masks] - return BitMasks(torch.stack([torch.from_numpy(x) for x in masks])) - - def crop_and_resize(self, boxes: torch.Tensor, mask_size: int) -> torch.Tensor: - """ - Crop each bitmask by the given box, and resize results to (mask_size, mask_size). - This can be used to prepare training targets for Mask R-CNN. - It has less reconstruction error compared to rasterization with polygons. - However we observe no difference in accuracy, - but BitMasks requires more memory to store all the masks. - - Args: - boxes (Tensor): Nx4 tensor storing the boxes for each mask - mask_size (int): the size of the rasterized mask. - - Returns: - Tensor: - A bool tensor of shape (N, mask_size, mask_size), where - N is the number of predicted boxes for this image. - """ - assert len(boxes) == len(self), "{} != {}".format(len(boxes), len(self)) - device = self.tensor.device - - batch_inds = torch.arange(len(boxes), device=device).to(dtype=boxes.dtype)[:, None] - rois = torch.cat([batch_inds, boxes], dim=1) - bit_masks = self.tensor.to(dtype=torch.float32) - rois = rois.to(device=device) - - output = ( - ROIAlign((mask_size, mask_size), 1.0, 0, aligned=True) - .forward(bit_masks[:, None, :, :], rois) - .squeeze(1) - ) - output = output >= 0.5 - return output - - def get_bounding_boxes(self) -> None: - # not needed now - raise NotImplementedError - - @staticmethod - def cat(bitmasks_list: List["BitMasks"]) -> "BitMasks": - """ - Concatenates a list of BitMasks into a single BitMasks - - Arguments: - bitmasks_list (list[BitMasks]) - - Returns: - BitMasks: the concatenated BitMasks - """ - assert isinstance(bitmasks_list, (list, tuple)) - assert len(bitmasks_list) > 0 - assert all(isinstance(bitmask, BitMasks) for bitmask in bitmasks_list) - - cat_bitmasks = type(bitmasks_list[0])(torch.cat([bm.tensor for bm in bitmasks_list], dim=0)) - return cat_bitmasks - - -class PolygonMasks: - """ - This class stores the segmentation masks for all objects in one image, in the form of polygons. - - Attributes: - polygons: list[list[ndarray]]. Each ndarray is a float64 vector representing a polygon. - """ - - def __init__(self, polygons: List[List[Union[torch.Tensor, np.ndarray]]]): - """ - Arguments: - polygons (list[list[np.ndarray]]): The first - level of the list correspond to individual instances, - the second level to all the polygons that compose the - instance, and the third level to the polygon coordinates. - The third level array should have the format of - [x0, y0, x1, y1, ..., xn, yn] (n >= 3). - """ - assert isinstance(polygons, list), ( - "Cannot create PolygonMasks: Expect a list of list of polygons per image. " - "Got '{}' instead.".format(type(polygons)) - ) - - def _make_array(t: Union[torch.Tensor, np.ndarray]) -> np.ndarray: - # Use float64 for higher precision, because why not? - # Always put polygons on CPU (self.to is a no-op) since they - # are supposed to be small tensors. - # May need to change this assumption if GPU placement becomes useful - if isinstance(t, torch.Tensor): - t = t.cpu().numpy() - return np.asarray(t).astype("float64") - - def process_polygons( - polygons_per_instance: List[Union[torch.Tensor, np.ndarray]] - ) -> List[np.ndarray]: - assert isinstance(polygons_per_instance, list), ( - "Cannot create polygons: Expect a list of polygons per instance. " - "Got '{}' instead.".format(type(polygons_per_instance)) - ) - # transform the polygon to a tensor - polygons_per_instance = [_make_array(p) for p in polygons_per_instance] - for polygon in polygons_per_instance: - assert len(polygon) % 2 == 0 and len(polygon) >= 6 - return polygons_per_instance - - self.polygons: List[List[np.ndarray]] = [ - process_polygons(polygons_per_instance) for polygons_per_instance in polygons - ] - - def to(self, *args: Any, **kwargs: Any) -> "PolygonMasks": - return self - - @property - def device(self) -> torch.device: - return torch.device("cpu") - - def get_bounding_boxes(self) -> Boxes: - """ - Returns: - Boxes: tight bounding boxes around polygon masks. - """ - boxes = torch.zeros(len(self.polygons), 4, dtype=torch.float32) - for idx, polygons_per_instance in enumerate(self.polygons): - minxy = torch.as_tensor([float("inf"), float("inf")], dtype=torch.float32) - maxxy = torch.zeros(2, dtype=torch.float32) - for polygon in polygons_per_instance: - coords = torch.from_numpy(polygon).view(-1, 2).to(dtype=torch.float32) - minxy = torch.min(minxy, torch.min(coords, dim=0).values) - maxxy = torch.max(maxxy, torch.max(coords, dim=0).values) - boxes[idx, :2] = minxy - boxes[idx, 2:] = maxxy - return Boxes(boxes) - - def nonempty(self) -> torch.Tensor: - """ - Find masks that are non-empty. - - Returns: - Tensor: - a BoolTensor which represents whether each mask is empty (False) or not (True). - """ - keep = [1 if len(polygon) > 0 else 0 for polygon in self.polygons] - return torch.from_numpy(np.asarray(keep, dtype=np.bool)) - - def __getitem__(self, item: Union[int, slice, List[int], torch.BoolTensor]) -> "PolygonMasks": - """ - Support indexing over the instances and return a `PolygonMasks` object. - `item` can be: - - 1. An integer. It will return an object with only one instance. - 2. A slice. It will return an object with the selected instances. - 3. A list[int]. It will return an object with the selected instances, - correpsonding to the indices in the list. - 4. A vector mask of type BoolTensor, whose length is num_instances. - It will return an object with the instances whose mask is nonzero. - """ - if isinstance(item, int): - selected_polygons = [self.polygons[item]] - elif isinstance(item, slice): - selected_polygons = self.polygons[item] - elif isinstance(item, list): - selected_polygons = [self.polygons[i] for i in item] - elif isinstance(item, torch.Tensor): - # Polygons is a list, so we have to move the indices back to CPU. - if item.dtype == torch.bool: - assert item.dim() == 1, item.shape - item = item.nonzero().squeeze(1).cpu().numpy().tolist() - elif item.dtype in [torch.int32, torch.int64]: - item = item.cpu().numpy().tolist() - else: - raise ValueError("Unsupported tensor dtype={} for indexing!".format(item.dtype)) - selected_polygons = [self.polygons[i] for i in item] - return PolygonMasks(selected_polygons) - - def __iter__(self) -> Iterator[List[np.ndarray]]: - """ - Yields: - list[ndarray]: the polygons for one instance. - Each Tensor is a float64 vector representing a polygon. - """ - return iter(self.polygons) - - def __repr__(self) -> str: - s = self.__class__.__name__ + "(" - s += "num_instances={})".format(len(self.polygons)) - return s - - def __len__(self) -> int: - return len(self.polygons) - - def crop_and_resize(self, boxes: torch.Tensor, mask_size: int) -> torch.Tensor: - """ - Crop each mask by the given box, and resize results to (mask_size, mask_size). - This can be used to prepare training targets for Mask R-CNN. - - Args: - boxes (Tensor): Nx4 tensor storing the boxes for each mask - mask_size (int): the size of the rasterized mask. - - Returns: - Tensor: A bool tensor of shape (N, mask_size, mask_size), where - N is the number of predicted boxes for this image. - """ - assert len(boxes) == len(self), "{} != {}".format(len(boxes), len(self)) - - device = boxes.device - # Put boxes on the CPU, as the polygon representation is not efficient GPU-wise - # (several small tensors for representing a single instance mask) - boxes = boxes.to(torch.device("cpu")) - - results = [ - rasterize_polygons_within_box(poly, box.numpy(), mask_size) - for poly, box in zip(self.polygons, boxes) - ] - """ - poly: list[list[float]], the polygons for one instance - box: a tensor of shape (4,) - """ - if len(results) == 0: - return torch.empty(0, mask_size, mask_size, dtype=torch.bool, device=device) - return torch.stack(results, dim=0).to(device=device) - - def area(self): - """ - Computes area of the mask. - Only works with Polygons, using the shoelace formula: - https://stackoverflow.com/questions/24467972/calculate-area-of-polygon-given-x-y-coordinates - - Returns: - Tensor: a vector, area for each instance - """ - - area = [] - for polygons_per_instance in self.polygons: - area_per_instance = 0 - for p in polygons_per_instance: - area_per_instance += polygon_area(p[0::2], p[1::2]) - area.append(area_per_instance) - - return torch.tensor(area) - - @staticmethod - def cat(polymasks_list: List["PolygonMasks"]) -> "PolygonMasks": - """ - Concatenates a list of PolygonMasks into a single PolygonMasks - - Arguments: - polymasks_list (list[PolygonMasks]) - - Returns: - PolygonMasks: the concatenated PolygonMasks - """ - assert isinstance(polymasks_list, (list, tuple)) - assert len(polymasks_list) > 0 - assert all(isinstance(polymask, PolygonMasks) for polymask in polymasks_list) - - cat_polymasks = type(polymasks_list[0])( - list(itertools.chain.from_iterable(pm.polygons for pm in polymasks_list)) - ) - return cat_polymasks +# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import copy +import itertools +import numpy as np +from typing import Any, Iterator, List, Union +import pycocotools.mask as mask_util +import torch + +from detectron2.layers.roi_align import ROIAlign + +from .boxes import Boxes + + +def polygon_area(x, y): + # Using the shoelace formula + # https://stackoverflow.com/questions/24467972/calculate-area-of-polygon-given-x-y-coordinates + return 0.5 * np.abs(np.dot(x, np.roll(y, 1)) - np.dot(y, np.roll(x, 1))) + + +def polygons_to_bitmask(polygons: List[np.ndarray], height: int, width: int) -> np.ndarray: + """ + Args: + polygons (list[ndarray]): each array has shape (Nx2,) + height, width (int) + + Returns: + ndarray: a bool mask of shape (height, width) + """ + assert len(polygons) > 0, "COCOAPI does not support empty polygons" + rles = mask_util.frPyObjects(polygons, height, width) + rle = mask_util.merge(rles) + return mask_util.decode(rle).astype(np.bool) + + +def rasterize_polygons_within_box( + polygons: List[np.ndarray], box: np.ndarray, mask_size: int +) -> torch.Tensor: + """ + Rasterize the polygons into a mask image and + crop the mask content in the given box. + The cropped mask is resized to (mask_size, mask_size). + + This function is used when generating training targets for mask head in Mask R-CNN. + Given original ground-truth masks for an image, new ground-truth mask + training targets in the size of `mask_size x mask_size` + must be provided for each predicted box. This function will be called to + produce such targets. + + Args: + polygons (list[ndarray[float]]): a list of polygons, which represents an instance. + box: 4-element numpy array + mask_size (int): + + Returns: + Tensor: BoolTensor of shape (mask_size, mask_size) + """ + # 1. Shift the polygons w.r.t the boxes + w, h = box[2] - box[0], box[3] - box[1] + + polygons = copy.deepcopy(polygons) + for p in polygons: + p[0::2] = p[0::2] - box[0] + p[1::2] = p[1::2] - box[1] + + # 2. Rescale the polygons to the new box size + # max() to avoid division by small number + ratio_h = mask_size / max(h, 0.1) + ratio_w = mask_size / max(w, 0.1) + + if ratio_h == ratio_w: + for p in polygons: + p *= ratio_h + else: + for p in polygons: + p[0::2] *= ratio_w + p[1::2] *= ratio_h + + # 3. Rasterize the polygons with coco api + mask = polygons_to_bitmask(polygons, mask_size, mask_size) + mask = torch.from_numpy(mask) + return mask + + +class BitMasks: + """ + This class stores the segmentation masks for all objects in one image, in + the form of bitmaps. + + Attributes: + tensor: bool Tensor of N,H,W, representing N instances in the image. + """ + + def __init__(self, tensor: Union[torch.Tensor, np.ndarray]): + """ + Args: + tensor: bool Tensor of N,H,W, representing N instances in the image. + """ + device = tensor.device if isinstance(tensor, torch.Tensor) else torch.device("cpu") + tensor = torch.as_tensor(tensor, dtype=torch.bool, device=device) + assert tensor.dim() == 3, tensor.size() + self.image_size = tensor.shape[1:] + self.tensor = tensor + + def to(self, *args: Any, **kwargs: Any) -> "BitMasks": + return BitMasks(self.tensor.to(*args, **kwargs)) + + @property + def device(self) -> torch.device: + return self.tensor.device + + def __getitem__(self, item: Union[int, slice, torch.BoolTensor]) -> "BitMasks": + """ + Returns: + BitMasks: Create a new :class:`BitMasks` by indexing. + + The following usage are allowed: + + 1. `new_masks = masks[3]`: return a `BitMasks` which contains only one mask. + 2. `new_masks = masks[2:10]`: return a slice of masks. + 3. `new_masks = masks[vector]`, where vector is a torch.BoolTensor + with `length = len(masks)`. Nonzero elements in the vector will be selected. + + Note that the returned object might share storage with this object, + subject to Pytorch's indexing semantics. + """ + if isinstance(item, int): + return BitMasks(self.tensor[item].view(1, -1)) + + if item.dtype == torch.int32: + m = self.tensor[item.long()] + else: + m = self.tensor[item] + + assert m.dim() == 3, "Indexing on BitMasks with {} returns a tensor with shape {}!".format( + item, m.shape + ) + return BitMasks(m) + + def __iter__(self) -> torch.Tensor: + yield from self.tensor + + def __repr__(self) -> str: + s = self.__class__.__name__ + "(" + s += "num_instances={})".format(len(self.tensor)) + return s + + def __len__(self) -> int: + return self.tensor.shape[0] + + def nonempty(self) -> torch.Tensor: + """ + Find masks that are non-empty. + + Returns: + Tensor: a BoolTensor which represents + whether each mask is empty (False) or non-empty (True). + """ + return self.tensor.flatten(1).any(dim=1) + + @staticmethod + def from_polygon_masks( + polygon_masks: Union["PolygonMasks", List[List[np.ndarray]]], height: int, width: int + ) -> "BitMasks": + """ + Args: + polygon_masks (list[list[ndarray]] or PolygonMasks) + height, width (int) + """ + if isinstance(polygon_masks, PolygonMasks): + polygon_masks = polygon_masks.polygons + masks = [polygons_to_bitmask(p, height, width) for p in polygon_masks] + return BitMasks(torch.stack([torch.from_numpy(x) for x in masks])) + + def crop_and_resize(self, boxes: torch.Tensor, mask_size: int) -> torch.Tensor: + """ + Crop each bitmask by the given box, and resize results to (mask_size, mask_size). + This can be used to prepare training targets for Mask R-CNN. + It has less reconstruction error compared to rasterization with polygons. + However we observe no difference in accuracy, + but BitMasks requires more memory to store all the masks. + + Args: + boxes (Tensor): Nx4 tensor storing the boxes for each mask + mask_size (int): the size of the rasterized mask. + + Returns: + Tensor: + A bool tensor of shape (N, mask_size, mask_size), where + N is the number of predicted boxes for this image. + """ + assert len(boxes) == len(self), "{} != {}".format(len(boxes), len(self)) + device = self.tensor.device + + batch_inds = torch.arange(len(boxes), device=device).to(dtype=boxes.dtype)[:, None] + rois = torch.cat([batch_inds, boxes], dim=1) + bit_masks = self.tensor.to(dtype=torch.float32) + rois = rois.to(device=device) + + output = ( + ROIAlign((mask_size, mask_size), 1.0, 0, aligned=True) + .forward(bit_masks[:, None, :, :], rois) + .squeeze(1) + ) + output = output >= 0.5 + return output + + def get_bounding_boxes(self) -> None: + # not needed now + raise NotImplementedError + + @staticmethod + def cat(bitmasks_list: List["BitMasks"]) -> "BitMasks": + """ + Concatenates a list of BitMasks into a single BitMasks + + Arguments: + bitmasks_list (list[BitMasks]) + + Returns: + BitMasks: the concatenated BitMasks + """ + assert isinstance(bitmasks_list, (list, tuple)) + assert len(bitmasks_list) > 0 + assert all(isinstance(bitmask, BitMasks) for bitmask in bitmasks_list) + + cat_bitmasks = type(bitmasks_list[0])(torch.cat([bm.tensor for bm in bitmasks_list], dim=0)) + return cat_bitmasks + + +class PolygonMasks: + """ + This class stores the segmentation masks for all objects in one image, in the form of polygons. + + Attributes: + polygons: list[list[ndarray]]. Each ndarray is a float64 vector representing a polygon. + """ + + def __init__(self, polygons: List[List[Union[torch.Tensor, np.ndarray]]]): + """ + Arguments: + polygons (list[list[np.ndarray]]): The first + level of the list correspond to individual instances, + the second level to all the polygons that compose the + instance, and the third level to the polygon coordinates. + The third level array should have the format of + [x0, y0, x1, y1, ..., xn, yn] (n >= 3). + """ + assert isinstance(polygons, list), ( + "Cannot create PolygonMasks: Expect a list of list of polygons per image. " + "Got '{}' instead.".format(type(polygons)) + ) + + def _make_array(t: Union[torch.Tensor, np.ndarray]) -> np.ndarray: + # Use float64 for higher precision, because why not? + # Always put polygons on CPU (self.to is a no-op) since they + # are supposed to be small tensors. + # May need to change this assumption if GPU placement becomes useful + if isinstance(t, torch.Tensor): + t = t.cpu().numpy() + return np.asarray(t).astype("float64") + + def process_polygons( + polygons_per_instance: List[Union[torch.Tensor, np.ndarray]] + ) -> List[np.ndarray]: + assert isinstance(polygons_per_instance, list), ( + "Cannot create polygons: Expect a list of polygons per instance. " + "Got '{}' instead.".format(type(polygons_per_instance)) + ) + # transform the polygon to a tensor + polygons_per_instance = [_make_array(p) for p in polygons_per_instance] + for polygon in polygons_per_instance: + assert len(polygon) % 2 == 0 and len(polygon) >= 6 + return polygons_per_instance + + self.polygons: List[List[np.ndarray]] = [ + process_polygons(polygons_per_instance) for polygons_per_instance in polygons + ] + + def to(self, *args: Any, **kwargs: Any) -> "PolygonMasks": + return self + + @property + def device(self) -> torch.device: + return torch.device("cpu") + + def get_bounding_boxes(self) -> Boxes: + """ + Returns: + Boxes: tight bounding boxes around polygon masks. + """ + boxes = torch.zeros(len(self.polygons), 4, dtype=torch.float32) + for idx, polygons_per_instance in enumerate(self.polygons): + minxy = torch.as_tensor([float("inf"), float("inf")], dtype=torch.float32) + maxxy = torch.zeros(2, dtype=torch.float32) + for polygon in polygons_per_instance: + coords = torch.from_numpy(polygon).view(-1, 2).to(dtype=torch.float32) + minxy = torch.min(minxy, torch.min(coords, dim=0).values) + maxxy = torch.max(maxxy, torch.max(coords, dim=0).values) + boxes[idx, :2] = minxy + boxes[idx, 2:] = maxxy + return Boxes(boxes) + + def nonempty(self) -> torch.Tensor: + """ + Find masks that are non-empty. + + Returns: + Tensor: + a BoolTensor which represents whether each mask is empty (False) or not (True). + """ + keep = [1 if len(polygon) > 0 else 0 for polygon in self.polygons] + return torch.from_numpy(np.asarray(keep, dtype=np.bool)) + + def __getitem__(self, item: Union[int, slice, List[int], torch.BoolTensor]) -> "PolygonMasks": + """ + Support indexing over the instances and return a `PolygonMasks` object. + `item` can be: + + 1. An integer. It will return an object with only one instance. + 2. A slice. It will return an object with the selected instances. + 3. A list[int]. It will return an object with the selected instances, + correpsonding to the indices in the list. + 4. A vector mask of type BoolTensor, whose length is num_instances. + It will return an object with the instances whose mask is nonzero. + """ + if isinstance(item, int): + selected_polygons = [self.polygons[item]] + elif isinstance(item, slice): + selected_polygons = self.polygons[item] + elif isinstance(item, list): + selected_polygons = [self.polygons[i] for i in item] + elif isinstance(item, torch.Tensor): + # Polygons is a list, so we have to move the indices back to CPU. + if item.dtype == torch.bool: + assert item.dim() == 1, item.shape + item = item.nonzero().squeeze(1).cpu().numpy().tolist() + elif item.dtype in [torch.int32, torch.int64]: + item = item.cpu().numpy().tolist() + else: + raise ValueError("Unsupported tensor dtype={} for indexing!".format(item.dtype)) + selected_polygons = [self.polygons[i] for i in item] + return PolygonMasks(selected_polygons) + + def __iter__(self) -> Iterator[List[np.ndarray]]: + """ + Yields: + list[ndarray]: the polygons for one instance. + Each Tensor is a float64 vector representing a polygon. + """ + return iter(self.polygons) + + def __repr__(self) -> str: + s = self.__class__.__name__ + "(" + s += "num_instances={})".format(len(self.polygons)) + return s + + def __len__(self) -> int: + return len(self.polygons) + + def crop_and_resize(self, boxes: torch.Tensor, mask_size: int) -> torch.Tensor: + """ + Crop each mask by the given box, and resize results to (mask_size, mask_size). + This can be used to prepare training targets for Mask R-CNN. + + Args: + boxes (Tensor): Nx4 tensor storing the boxes for each mask + mask_size (int): the size of the rasterized mask. + + Returns: + Tensor: A bool tensor of shape (N, mask_size, mask_size), where + N is the number of predicted boxes for this image. + """ + assert len(boxes) == len(self), "{} != {}".format(len(boxes), len(self)) + + device = boxes.device + # Put boxes on the CPU, as the polygon representation is not efficient GPU-wise + # (several small tensors for representing a single instance mask) + boxes = boxes.to(torch.device("cpu")) + + results = [ + rasterize_polygons_within_box(poly, box.numpy(), mask_size) + for poly, box in zip(self.polygons, boxes) + ] + """ + poly: list[list[float]], the polygons for one instance + box: a tensor of shape (4,) + """ + if len(results) == 0: + return torch.empty(0, mask_size, mask_size, dtype=torch.bool, device=device) + return torch.stack(results, dim=0).to(device=device) + + def area(self): + """ + Computes area of the mask. + Only works with Polygons, using the shoelace formula: + https://stackoverflow.com/questions/24467972/calculate-area-of-polygon-given-x-y-coordinates + + Returns: + Tensor: a vector, area for each instance + """ + + area = [] + for polygons_per_instance in self.polygons: + area_per_instance = 0 + for p in polygons_per_instance: + area_per_instance += polygon_area(p[0::2], p[1::2]) + area.append(area_per_instance) + + return torch.tensor(area) + + @staticmethod + def cat(polymasks_list: List["PolygonMasks"]) -> "PolygonMasks": + """ + Concatenates a list of PolygonMasks into a single PolygonMasks + + Arguments: + polymasks_list (list[PolygonMasks]) + + Returns: + PolygonMasks: the concatenated PolygonMasks + """ + assert isinstance(polymasks_list, (list, tuple)) + assert len(polymasks_list) > 0 + assert all(isinstance(polymask, PolygonMasks) for polymask in polymasks_list) + + cat_polymasks = type(polymasks_list[0])( + list(itertools.chain.from_iterable(pm.polygons for pm in polymasks_list)) + ) + return cat_polymasks diff --git a/PyTorch/contrib/cv/detection/CenterFace/LICENSE b/PyTorch/contrib/cv/detection/CenterFace/LICENSE index 4ba4fdcab3dbdb4d64ce4cccdfd990698b4d596a..a0e03103591c1158a839681f3c404ee9118b182e 100644 --- a/PyTorch/contrib/cv/detection/CenterFace/LICENSE +++ b/PyTorch/contrib/cv/detection/CenterFace/LICENSE @@ -1,29 +1,29 @@ -BSD 3-Clause License - -Copyright (c) 2017, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +BSD 3-Clause License + +Copyright (c) 2017, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/CenterFace/modelzoo_level.txt b/PyTorch/contrib/cv/detection/CenterFace/modelzoo_level.txt index 484664c2399ae4109859a67aba6cb9facff03cf1..55a9add9fa74832ca908108d73946cd76281a9cd 100644 --- a/PyTorch/contrib/cv/detection/CenterFace/modelzoo_level.txt +++ b/PyTorch/contrib/cv/detection/CenterFace/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/CenterFace/src/8p_npu_main.py b/PyTorch/contrib/cv/detection/CenterFace/src/8p_npu_main.py index 1244c6f2c82a62f9e0ef915b6a112d51c67917e5..4dc05e1ea2784d5b6b956444ce568106b2090a75 100644 --- a/PyTorch/contrib/cv/detection/CenterFace/src/8p_npu_main.py +++ b/PyTorch/contrib/cv/detection/CenterFace/src/8p_npu_main.py @@ -1,127 +1,127 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import _init_paths - -import os - -import torch -import torch.utils.data -from opts_pose import opts -from models.model import create_model, load_model, save_model -from models.data_parallel import DataParallel -from datasets.dataset_factory import get_dataset -from trains.train_factory import train_factory -from datasets.sample.multi_pose import Multiposebatch -from apex import amp -import torch.npu -import torch.distributed as dist -from torch.nn.parallel import DistributedDataParallel as DDP - - -def main(opt, qtepoch=[0,]): - - torch.manual_seed(opt.seed) - torch.backends.cudnn.benchmark = not opt.not_cuda_benchmark and not opt.test - Dataset = get_dataset(opt.dataset, opt.task) - opt = opts().update_dataset_info_and_set_heads(opt, Dataset) - if opt.local_rank ==0: - print(opt) - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = opt.port - device_id = int(opt.device_list.split(',')[int(opt.local_rank)]) - opt.device = 'npu:{}'.format(device_id) - - torch.npu.set_device(opt.device) - - dist.init_process_group(backend='hccl', world_size=opt.world_size, rank=opt.local_rank) - print('process{},device:{}'.format(opt.local_rank,opt.device)) - print('Creating model...') - model = create_model(opt.arch, opt.heads, opt.head_conv) - model = model.to(opt.device) - if opt.pretrained: - checkpoint = torch.load(opt.pretrained_weight_path, map_location='cpu') - if 'module.' in list(checkpoint['state_dict'].keys())[0]: - checkpoint['state_dict'] = {k.replace('module.', ''): v for k, v in checkpoint['state_dict'].items()} - model.load_state_dict(checkpoint['state_dict'], strict=False) - - optimizer = torch.optim.Adam(model.parameters(), opt.lr) - model, optimizer = amp.initialize(model, optimizer, opt_level="O1",loss_scale=19.0) - start_epoch = 0 - if opt.load_model != '': - model, optimizer, start_epoch = load_model( - model, opt.load_model, optimizer, opt.resume, opt.lr, opt.lr_step) - print('start_epoch:{}'.format(start_epoch)) - Trainer = train_factory[opt.task] - trainer = Trainer(opt, model, optimizer) - trainer.set_device(opt.device_list, opt.chunk_sizes, opt.device) - print('Setting up data...') - train_sampler = torch.utils.data.distributed.DistributedSampler(Dataset(opt, 'train')) - train_loader = torch.utils.data.DataLoader( - Dataset(opt, 'train'), - batch_size=opt.batch_size, - shuffle=(train_sampler is None), - num_workers=opt.num_workers, - sampler=train_sampler, - pin_memory=True, - drop_last=True, - collate_fn=Multiposebatch - ) - - print('Starting training...') - best = 1e10 - for epoch in range(start_epoch + 1, opt.num_epochs + 1): - qtepoch.append(epoch) - train_sampler.set_epoch(epoch) - mark = epoch if opt.save_all else 'last' - log_dict_train, _ = trainer.train(epoch, train_loader) - if opt.local_rank == 0: - str1 ='epoch:{}|'.format(epoch) - for k, v in log_dict_train.items(): - str2 ='{} {:8f}|'.format(k,v) - str1 = str1 +str2 - print(str1) - if opt.val_intervals > 0 and epoch % opt.val_intervals == 0: - save_model(os.path.join(opt.save_dir, 'model_{}.pth'.format(mark)), - epoch, model, optimizer) - - print('best:{} metric:{} epotchs:{}'.format(best,log_dict_train[opt.metric],epoch)) - - if log_dict_train[opt.metric] < best: - best = log_dict_train[opt.metric] - save_model(os.path.join(opt.save_dir, 'model_best.pth'), - epoch, model) - else: - save_model(os.path.join(opt.save_dir, 'model_last.pth'), - epoch, model, optimizer) - - - if epoch in opt.lr_step: - - if opt.local_rank == 0: - save_model(os.path.join(opt.save_dir, 'model_{}.pth'.format(epoch)), epoch, model, optimizer) - lr = opt.lr * (0.1 ** (opt.lr_step.index(epoch) + 1)) - if opt.local_rank == 0: - print('Drop LR to', lr) - for param_group in optimizer.param_groups: - param_group['lr'] = lr - - -if __name__ == '__main__': - opt = opts().parse() - main(opt) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import _init_paths + +import os + +import torch +import torch.utils.data +from opts_pose import opts +from models.model import create_model, load_model, save_model +from models.data_parallel import DataParallel +from datasets.dataset_factory import get_dataset +from trains.train_factory import train_factory +from datasets.sample.multi_pose import Multiposebatch +from apex import amp +import torch.npu +import torch.distributed as dist +from torch.nn.parallel import DistributedDataParallel as DDP + + +def main(opt, qtepoch=[0,]): + + torch.manual_seed(opt.seed) + torch.backends.cudnn.benchmark = not opt.not_cuda_benchmark and not opt.test + Dataset = get_dataset(opt.dataset, opt.task) + opt = opts().update_dataset_info_and_set_heads(opt, Dataset) + if opt.local_rank ==0: + print(opt) + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = opt.port + device_id = int(opt.device_list.split(',')[int(opt.local_rank)]) + opt.device = 'npu:{}'.format(device_id) + + torch.npu.set_device(opt.device) + + dist.init_process_group(backend='hccl', world_size=opt.world_size, rank=opt.local_rank) + print('process{},device:{}'.format(opt.local_rank,opt.device)) + print('Creating model...') + model = create_model(opt.arch, opt.heads, opt.head_conv) + model = model.to(opt.device) + if opt.pretrained: + checkpoint = torch.load(opt.pretrained_weight_path, map_location='cpu') + if 'module.' in list(checkpoint['state_dict'].keys())[0]: + checkpoint['state_dict'] = {k.replace('module.', ''): v for k, v in checkpoint['state_dict'].items()} + model.load_state_dict(checkpoint['state_dict'], strict=False) + + optimizer = torch.optim.Adam(model.parameters(), opt.lr) + model, optimizer = amp.initialize(model, optimizer, opt_level="O1",loss_scale=19.0) + start_epoch = 0 + if opt.load_model != '': + model, optimizer, start_epoch = load_model( + model, opt.load_model, optimizer, opt.resume, opt.lr, opt.lr_step) + print('start_epoch:{}'.format(start_epoch)) + Trainer = train_factory[opt.task] + trainer = Trainer(opt, model, optimizer) + trainer.set_device(opt.device_list, opt.chunk_sizes, opt.device) + print('Setting up data...') + train_sampler = torch.utils.data.distributed.DistributedSampler(Dataset(opt, 'train')) + train_loader = torch.utils.data.DataLoader( + Dataset(opt, 'train'), + batch_size=opt.batch_size, + shuffle=(train_sampler is None), + num_workers=opt.num_workers, + sampler=train_sampler, + pin_memory=True, + drop_last=True, + collate_fn=Multiposebatch + ) + + print('Starting training...') + best = 1e10 + for epoch in range(start_epoch + 1, opt.num_epochs + 1): + qtepoch.append(epoch) + train_sampler.set_epoch(epoch) + mark = epoch if opt.save_all else 'last' + log_dict_train, _ = trainer.train(epoch, train_loader) + if opt.local_rank == 0: + str1 ='epoch:{}|'.format(epoch) + for k, v in log_dict_train.items(): + str2 ='{} {:8f}|'.format(k,v) + str1 = str1 +str2 + print(str1) + if opt.val_intervals > 0 and epoch % opt.val_intervals == 0: + save_model(os.path.join(opt.save_dir, 'model_{}.pth'.format(mark)), + epoch, model, optimizer) + + print('best:{} metric:{} epotchs:{}'.format(best,log_dict_train[opt.metric],epoch)) + + if log_dict_train[opt.metric] < best: + best = log_dict_train[opt.metric] + save_model(os.path.join(opt.save_dir, 'model_best.pth'), + epoch, model) + else: + save_model(os.path.join(opt.save_dir, 'model_last.pth'), + epoch, model, optimizer) + + + if epoch in opt.lr_step: + + if opt.local_rank == 0: + save_model(os.path.join(opt.save_dir, 'model_{}.pth'.format(epoch)), epoch, model, optimizer) + lr = opt.lr * (0.1 ** (opt.lr_step.index(epoch) + 1)) + if opt.local_rank == 0: + print('Drop LR to', lr) + for param_group in optimizer.param_groups: + param_group['lr'] = lr + + +if __name__ == '__main__': + opt = opts().parse() + main(opt) diff --git a/PyTorch/contrib/cv/detection/CenterFace/src/test/env_npu.sh b/PyTorch/contrib/cv/detection/CenterFace/src/test/env_npu.sh index 0ea66b3bc64619af088c962decb46161f26d4455..2b12ee99de31bca6c2e1120b98be597251e695d1 100644 --- a/PyTorch/contrib/cv/detection/CenterFace/src/test/env_npu.sh +++ b/PyTorch/contrib/cv/detection/CenterFace/src/test/env_npu.sh @@ -1,68 +1,68 @@ -#!/bin/bash -export install_path=/usr/local/Ascend - -if [ -d ${install_path}/toolkit ]; then - export LD_LIBRARY_PATH=/usr/include/hdf5/lib/:/usr/local/:/usr/local/lib/:/usr/lib/:${install_path}/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons:${path_lib}:${LD_LIBRARY_PATH} - export PATH=${install_path}/fwkacllib/ccec_compiler/bin:${install_path}/fwkacllib/bin:$PATH - export PYTHONPATH=${install_path}/fwkacllib/python/site-packages:${install_path}/tfplugin/python/site-packages:${install_path}/toolkit/python/site-packages:$PYTHONPATH - export PYTHONPATH=/usr/local/python3.7.5/lib/python3.7/site-packages:$PYTHONPATH - export ASCEND_OPP_PATH=${install_path}/opp -else - if [ -d ${install_path}/nnae/latest ];then - export LD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:${install_path}/nnae/latest/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH - export PATH=$PATH:${install_path}/nnae/latest/fwkacllib/ccec_compiler/bin/:${install_path}/nnae/latest/toolkit/tools/ide_daemon/bin/ - export ASCEND_OPP_PATH=${install_path}/nnae/latest/opp/ - export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so - export PYTHONPATH=${install_path}/nnae/latest/fwkacllib/python/site-packages/:${install_path}/nnae/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:${install_path}/nnae/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH - export ASCEND_AICPU_PATH=${install_path}/nnae/latest - else - export LD_LIBRARY_PATH=/usr/local/:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64-linux-gnu:$LD_LIBRARY_PATH - export PATH=$PATH:${install_path}/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin/:${install_path}/ascend-toolkit/latest/toolkit/tools/ide_daemon/bin/ - export ASCEND_OPP_PATH=${install_path}/ascend-toolkit/latest/opp/ - export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so - export PYTHONPATH=${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/:${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH - export ASCEND_AICPU_PATH=${install_path}/ascend-toolkit/latest - fi -fi - - -#将Host日志输出到串口,0-关闭/1-开启 -export ASCEND_SLOG_PRINT_TO_STDOUT=0 -#设置默认日志级别,0-debug/1-info/2-warning/3-error -export ASCEND_GLOBAL_LOG_LEVEL=3 -#设置Event日志开启标志,0-关闭/1-开启 -export ASCEND_GLOBAL_EVENT_ENABLE=0 -#设置是否开启taskque,0-关闭/1-开启 -export TASK_QUEUE_ENABLE=1 -#设置是否开启PTCopy,0-关闭/1-开启 -export PTCOPY_ENABLE=1 -#设置是否开启combined标志,0-关闭/1-开启 -export COMBINED_ENABLE=1 -#设置特殊场景是否需要重新编译,不需要修改 -export DYNAMIC_OP="ADD#MUL" -#HCCL白名单开关,1-关闭/0-开启 -export HCCL_WHITELIST_DISABLE=1 -export HCCL_IF_IP=$(hostname -I |awk '{print $1}') - -ulimit -SHn 512000 - -path_lib=$(python3.7 -c """ -import sys -import re -result='' -for index in range(len(sys.path)): - match_sit = re.search('-packages', sys.path[index]) - if match_sit is not None: - match_lib = re.search('lib', sys.path[index]) - - if match_lib is not None: - end=match_lib.span()[1] - result += sys.path[index][0:end] + ':' - - result+=sys.path[index] + '/torch/lib:' -print(result)""" -) - -echo ${path_lib} - -export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib/:${path_lib}:$LD_LIBRARY_PATH +#!/bin/bash +export install_path=/usr/local/Ascend + +if [ -d ${install_path}/toolkit ]; then + export LD_LIBRARY_PATH=/usr/include/hdf5/lib/:/usr/local/:/usr/local/lib/:/usr/lib/:${install_path}/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons:${path_lib}:${LD_LIBRARY_PATH} + export PATH=${install_path}/fwkacllib/ccec_compiler/bin:${install_path}/fwkacllib/bin:$PATH + export PYTHONPATH=${install_path}/fwkacllib/python/site-packages:${install_path}/tfplugin/python/site-packages:${install_path}/toolkit/python/site-packages:$PYTHONPATH + export PYTHONPATH=/usr/local/python3.7.5/lib/python3.7/site-packages:$PYTHONPATH + export ASCEND_OPP_PATH=${install_path}/opp +else + if [ -d ${install_path}/nnae/latest ];then + export LD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:${install_path}/nnae/latest/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH + export PATH=$PATH:${install_path}/nnae/latest/fwkacllib/ccec_compiler/bin/:${install_path}/nnae/latest/toolkit/tools/ide_daemon/bin/ + export ASCEND_OPP_PATH=${install_path}/nnae/latest/opp/ + export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so + export PYTHONPATH=${install_path}/nnae/latest/fwkacllib/python/site-packages/:${install_path}/nnae/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:${install_path}/nnae/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH + export ASCEND_AICPU_PATH=${install_path}/nnae/latest + else + export LD_LIBRARY_PATH=/usr/local/:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64-linux-gnu:$LD_LIBRARY_PATH + export PATH=$PATH:${install_path}/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin/:${install_path}/ascend-toolkit/latest/toolkit/tools/ide_daemon/bin/ + export ASCEND_OPP_PATH=${install_path}/ascend-toolkit/latest/opp/ + export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so + export PYTHONPATH=${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/:${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH + export ASCEND_AICPU_PATH=${install_path}/ascend-toolkit/latest + fi +fi + + +#将Host日志输出到串口,0-关闭/1-开启 +export ASCEND_SLOG_PRINT_TO_STDOUT=0 +#设置默认日志级别,0-debug/1-info/2-warning/3-error +export ASCEND_GLOBAL_LOG_LEVEL=3 +#设置Event日志开启标志,0-关闭/1-开启 +export ASCEND_GLOBAL_EVENT_ENABLE=0 +#设置是否开启taskque,0-关闭/1-开启 +export TASK_QUEUE_ENABLE=1 +#设置是否开启PTCopy,0-关闭/1-开启 +export PTCOPY_ENABLE=1 +#设置是否开启combined标志,0-关闭/1-开启 +export COMBINED_ENABLE=1 +#设置特殊场景是否需要重新编译,不需要修改 +export DYNAMIC_OP="ADD#MUL" +#HCCL白名单开关,1-关闭/0-开启 +export HCCL_WHITELIST_DISABLE=1 +export HCCL_IF_IP=$(hostname -I |awk '{print $1}') + +ulimit -SHn 512000 + +path_lib=$(python3.7 -c """ +import sys +import re +result='' +for index in range(len(sys.path)): + match_sit = re.search('-packages', sys.path[index]) + if match_sit is not None: + match_lib = re.search('lib', sys.path[index]) + + if match_lib is not None: + end=match_lib.span()[1] + result += sys.path[index][0:end] + ':' + + result+=sys.path[index] + '/torch/lib:' +print(result)""" +) + +echo ${path_lib} + +export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib/:${path_lib}:$LD_LIBRARY_PATH diff --git a/PyTorch/contrib/cv/detection/CenterNet/modelzoo_level.txt b/PyTorch/contrib/cv/detection/CenterNet/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/detection/CenterNet/modelzoo_level.txt +++ b/PyTorch/contrib/cv/detection/CenterNet/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/detectors/base_detector.py b/PyTorch/contrib/cv/detection/CenterNet/src/lib/detectors/base_detector.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/detectors/ctdet.py b/PyTorch/contrib/cv/detection/CenterNet/src/lib/detectors/ctdet.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/detectors/ddd.py b/PyTorch/contrib/cv/detection/CenterNet/src/lib/detectors/ddd.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/detectors/exdet.py b/PyTorch/contrib/cv/detection/CenterNet/src/lib/detectors/exdet.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/detectors/multi_pose.py b/PyTorch/contrib/cv/detection/CenterNet/src/lib/detectors/multi_pose.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/models/networks/DCNv2/make.sh b/PyTorch/contrib/cv/detection/CenterNet/src/lib/models/networks/DCNv2/make.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/models/networks/dcn/modules/deform_conv.py b/PyTorch/contrib/cv/detection/CenterNet/src/lib/models/networks/dcn/modules/deform_conv.py index 7850c278e65ea707d7e63436edc5dd9a52379bdc..4c1f102339d84f22e54aacbb983f859c785bd5d8 100644 --- a/PyTorch/contrib/cv/detection/CenterNet/src/lib/models/networks/dcn/modules/deform_conv.py +++ b/PyTorch/contrib/cv/detection/CenterNet/src/lib/models/networks/dcn/modules/deform_conv.py @@ -1,235 +1,235 @@ -# Copyright (c) 2020, Huawei Technologies.All rights reserved. -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import torch.nn as nn -from torch.autograd import Function -from torch.nn.modules.utils import _pair, _single -import math - - -class ModulatedDeformConv2dFunction(Function): - - @staticmethod - def forward(ctx, - input_tensor, - offset_ori, - mask, - weight, - bias=None, - with_bias=False, - stride=1, - padding=0, - dilation=1, - groups=1, - deformable_groups=1, - sort_index_for_npu_fp=None, - sort_index_for_npu_bp=None, - ): - - input_tensor = input_tensor.float() - offset_ori = offset_ori.float() - mask = mask.float() - - ctx.stride = stride - ctx.padding = padding - ctx.dilation = dilation - ctx.groups = groups - ctx.deformable_groups = deformable_groups - ctx.sort_index_for_npu_bp = sort_index_for_npu_bp - ctx.with_bias = with_bias - - offset = offset_ori.index_select(1, sort_index_for_npu_fp) - offset_all = torch.cat([offset, mask], dim=1) - output, offset_out = torch.npu_deformable_conv2d( - input_tensor, weight, offset_all, bias, - kernel_size=[weight.shape[3], weight.shape[2]], - stride=[1, 1, ctx.stride, ctx.stride], - padding=[ctx.padding, ctx.padding, ctx.padding, ctx.padding], - dilation=[1, 1, ctx.dilation, ctx.dilation], - groups=ctx.groups, deformable_groups=ctx.deformable_groups, - modulated=True) - if weight.requires_grad or mask.requires_grad or offset.requires_grad \ - or input_tensor.requires_grad: - ctx.save_for_backward(input_tensor, weight, offset_out, offset_all) - return output - - @staticmethod - def backward(ctx, grad_output): - input_tensor, weight, offset_out, offset_all = ctx.saved_tensors - grad_input, grad_weight, grad_offset_all, grad_bias = torch.npu_deformable_conv2dbk( - input_tensor, grad_output, offset_out, weight, offset_all, - kernel_size=[weight.shape[3], weight.shape[2]], - stride=[1, 1, ctx.stride, ctx.stride], - padding=[ctx.padding, ctx.padding, ctx.padding, ctx.padding], - dilation=[1, 1, ctx.dilation, ctx.dilation], - groups=ctx.groups, deformable_groups=ctx.deformable_groups, modulated=True) - grad_offset = grad_offset_all.index_select(1, ctx.sort_index_for_npu_bp) - grad_mask = grad_offset_all[:, grad_offset.shape[1]:, :, :] - if not ctx.with_bias: - grad_bias = None - - return (grad_input, grad_offset, grad_mask, grad_weight, grad_bias, - None, None, None, None, None, None, None, None) - - -class ModulatedDeformConv(nn.Module): - - def __init__(self, - in_channels, - out_channels, - kernel_size, - stride=1, - padding=0, - dilation=1, - groups=1, - deformable_groups=1, - bias=True, - pack=True, - ): - - r"""Applies an NPU based Modulated Deformable 2D convolution operation. - - Paper link: - [Deformable ConvNets v2: More Deformable, Better Results](https://arxiv.org/abs/1811.11168) - - Reference implementation link: - https://github.com/open-mmlab/mmcv/blob/master/mmcv/ops/modulated_deform_conv.py - - The implementation of this ModulatedDeformConv is mainly based - on the implementation of mmcv for design and reconstruction. - Through the modular ModulatedDeformConvFunction, the forward and reverse are customized, - and the input is reconstructed in combination with the NPU underlying operator IR, - and finally the function is completed. - - It is worth mentioning that deformconv (DCNv1) is also implemented - by setting modulated = False. Due to the difference between input - and initialization, there is no additional implementation here. - - - .. note:: - ModulatedDeformConv only implements operations under fp32 data types. - Notice, conv_ Weight and bias of offset must be initialized to 0. - - Args: - in_channels (int): Number of channels in the input image. - out_channels (int): Number of channels produced by the convolution. - kernel_size(int, tuple): Size of the convolving kernel. - stride(int, tuple): Stride of the convolution. Default: 1. - padding (int or tuple): Zero-padding added to both sides of the input. - Default: 0. - dilation (int or tuple): Spacing between kernel elements. Default: 1. - groups (int): Number of blocked connections from input. - channels to output channels. Default: 1. - deform_groups (int): Number of deformable group partitions. - bias (bool): If True, adds a learnable bias to the output. Default: False. - pack (bool): If True, conv_offset and mask will be included in this module. Default: True. - - Examples:: - >>> m = ModulatedDeformConv(32, 32, 1) - >>> input_tensor = torch.randn(2, 32, 5, 5) - >>> output = m(input_tensor) - """ - - super(ModulatedDeformConv, self).__init__() - - self.in_channels = in_channels - self.out_channels = out_channels - self.kernel_size = _pair(kernel_size) - self.stride = stride - self.padding = padding - self.dilation = dilation - self.groups = groups - self.deformable_groups = deformable_groups - self.with_bias = bias - self.pack = pack - - self.weight = nn.Parameter( - torch.Tensor(out_channels, in_channels // groups, *self.kernel_size)) - if bias: - self.bias = nn.Parameter(torch.Tensor(out_channels)) - else: - self.bias = torch.zeros(self.weight.shape[0]) - - if self.pack: - self.conv_offset = nn.Conv2d( - self.in_channels, - self.deformable_groups * 3 * self.kernel_size[0] * - self.kernel_size[1], - kernel_size=self.kernel_size, - stride=_pair(self.stride), - padding=_pair(self.padding), - bias=True) - - self.split_num = self.deformable_groups * 2 * self.kernel_size[0] * self.kernel_size[1] - sort_index_for_npu = list(range(self.split_num)) - sort_index_for_npu_fp = sort_index_for_npu[1::2] + sort_index_for_npu[::2] - sort_index_for_npu_bp_dict = {i: idx for idx, i in enumerate(sort_index_for_npu_fp)} - sort_index_for_npu_bp = [sort_index_for_npu_bp_dict[i] for i in sort_index_for_npu] - self.sort_index_for_npu_fp = torch.IntTensor(sort_index_for_npu_fp) - self.sort_index_for_npu_bp = torch.IntTensor(sort_index_for_npu_bp) - self.sort_index_for_npu_todevice = False - - self.init_param() - - def init_param(self): - n = self.in_channels - for k in self.kernel_size: - n *= k - stdv = 1. / math.sqrt(n) - self.weight.data.uniform_(-stdv, stdv) - if self.bias is not None: - self.bias.data.zero_() - - if self.pack: - self.conv_offset.weight.data.zero_() - self.conv_offset.bias.data.zero_() - - def forward(self, x): - if self.pack: - out = self.conv_offset(x) - offset = out[:, :self.split_num, ...] - mask = torch.sigmoid(out[:, self.split_num:, ...]) - else: - x, offset, mask = x - - if not self.sort_index_for_npu_todevice: - self.sort_index_for_npu_fp = self.sort_index_for_npu_fp.to(x.device) - self.sort_index_for_npu_bp = self.sort_index_for_npu_bp.to(x.device) - self.bias = self.bias.to(x.device) - self.sort_index_for_npu_todevice = True - - return ModulatedDeformConv2dFunction.apply( - x, offset, mask, self.weight, self.bias, self.with_bias, - self.stride, self.padding, self.dilation, - self.groups, self.deformable_groups, - self.sort_index_for_npu_fp, - self.sort_index_for_npu_bp, - ) - - -DCNv2 = ModulatedDeformConv - -if __name__ == "__main__": - x = torch.randn(2, 32, 7, 7) - model = DCNv2(32, 32, 3, 2, 1) - - torch.npu.set_device(0) - x = x.npu() - model = model.npu() - - o = model(x) - l = o.sum() - l.backward() - print(l) +# Copyright (c) 2020, Huawei Technologies.All rights reserved. +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import torch.nn as nn +from torch.autograd import Function +from torch.nn.modules.utils import _pair, _single +import math + + +class ModulatedDeformConv2dFunction(Function): + + @staticmethod + def forward(ctx, + input_tensor, + offset_ori, + mask, + weight, + bias=None, + with_bias=False, + stride=1, + padding=0, + dilation=1, + groups=1, + deformable_groups=1, + sort_index_for_npu_fp=None, + sort_index_for_npu_bp=None, + ): + + input_tensor = input_tensor.float() + offset_ori = offset_ori.float() + mask = mask.float() + + ctx.stride = stride + ctx.padding = padding + ctx.dilation = dilation + ctx.groups = groups + ctx.deformable_groups = deformable_groups + ctx.sort_index_for_npu_bp = sort_index_for_npu_bp + ctx.with_bias = with_bias + + offset = offset_ori.index_select(1, sort_index_for_npu_fp) + offset_all = torch.cat([offset, mask], dim=1) + output, offset_out = torch.npu_deformable_conv2d( + input_tensor, weight, offset_all, bias, + kernel_size=[weight.shape[3], weight.shape[2]], + stride=[1, 1, ctx.stride, ctx.stride], + padding=[ctx.padding, ctx.padding, ctx.padding, ctx.padding], + dilation=[1, 1, ctx.dilation, ctx.dilation], + groups=ctx.groups, deformable_groups=ctx.deformable_groups, + modulated=True) + if weight.requires_grad or mask.requires_grad or offset.requires_grad \ + or input_tensor.requires_grad: + ctx.save_for_backward(input_tensor, weight, offset_out, offset_all) + return output + + @staticmethod + def backward(ctx, grad_output): + input_tensor, weight, offset_out, offset_all = ctx.saved_tensors + grad_input, grad_weight, grad_offset_all, grad_bias = torch.npu_deformable_conv2dbk( + input_tensor, grad_output, offset_out, weight, offset_all, + kernel_size=[weight.shape[3], weight.shape[2]], + stride=[1, 1, ctx.stride, ctx.stride], + padding=[ctx.padding, ctx.padding, ctx.padding, ctx.padding], + dilation=[1, 1, ctx.dilation, ctx.dilation], + groups=ctx.groups, deformable_groups=ctx.deformable_groups, modulated=True) + grad_offset = grad_offset_all.index_select(1, ctx.sort_index_for_npu_bp) + grad_mask = grad_offset_all[:, grad_offset.shape[1]:, :, :] + if not ctx.with_bias: + grad_bias = None + + return (grad_input, grad_offset, grad_mask, grad_weight, grad_bias, + None, None, None, None, None, None, None, None) + + +class ModulatedDeformConv(nn.Module): + + def __init__(self, + in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + dilation=1, + groups=1, + deformable_groups=1, + bias=True, + pack=True, + ): + + r"""Applies an NPU based Modulated Deformable 2D convolution operation. + + Paper link: + [Deformable ConvNets v2: More Deformable, Better Results](https://arxiv.org/abs/1811.11168) + + Reference implementation link: + https://github.com/open-mmlab/mmcv/blob/master/mmcv/ops/modulated_deform_conv.py + + The implementation of this ModulatedDeformConv is mainly based + on the implementation of mmcv for design and reconstruction. + Through the modular ModulatedDeformConvFunction, the forward and reverse are customized, + and the input is reconstructed in combination with the NPU underlying operator IR, + and finally the function is completed. + + It is worth mentioning that deformconv (DCNv1) is also implemented + by setting modulated = False. Due to the difference between input + and initialization, there is no additional implementation here. + + + .. note:: + ModulatedDeformConv only implements operations under fp32 data types. + Notice, conv_ Weight and bias of offset must be initialized to 0. + + Args: + in_channels (int): Number of channels in the input image. + out_channels (int): Number of channels produced by the convolution. + kernel_size(int, tuple): Size of the convolving kernel. + stride(int, tuple): Stride of the convolution. Default: 1. + padding (int or tuple): Zero-padding added to both sides of the input. + Default: 0. + dilation (int or tuple): Spacing between kernel elements. Default: 1. + groups (int): Number of blocked connections from input. + channels to output channels. Default: 1. + deform_groups (int): Number of deformable group partitions. + bias (bool): If True, adds a learnable bias to the output. Default: False. + pack (bool): If True, conv_offset and mask will be included in this module. Default: True. + + Examples:: + >>> m = ModulatedDeformConv(32, 32, 1) + >>> input_tensor = torch.randn(2, 32, 5, 5) + >>> output = m(input_tensor) + """ + + super(ModulatedDeformConv, self).__init__() + + self.in_channels = in_channels + self.out_channels = out_channels + self.kernel_size = _pair(kernel_size) + self.stride = stride + self.padding = padding + self.dilation = dilation + self.groups = groups + self.deformable_groups = deformable_groups + self.with_bias = bias + self.pack = pack + + self.weight = nn.Parameter( + torch.Tensor(out_channels, in_channels // groups, *self.kernel_size)) + if bias: + self.bias = nn.Parameter(torch.Tensor(out_channels)) + else: + self.bias = torch.zeros(self.weight.shape[0]) + + if self.pack: + self.conv_offset = nn.Conv2d( + self.in_channels, + self.deformable_groups * 3 * self.kernel_size[0] * + self.kernel_size[1], + kernel_size=self.kernel_size, + stride=_pair(self.stride), + padding=_pair(self.padding), + bias=True) + + self.split_num = self.deformable_groups * 2 * self.kernel_size[0] * self.kernel_size[1] + sort_index_for_npu = list(range(self.split_num)) + sort_index_for_npu_fp = sort_index_for_npu[1::2] + sort_index_for_npu[::2] + sort_index_for_npu_bp_dict = {i: idx for idx, i in enumerate(sort_index_for_npu_fp)} + sort_index_for_npu_bp = [sort_index_for_npu_bp_dict[i] for i in sort_index_for_npu] + self.sort_index_for_npu_fp = torch.IntTensor(sort_index_for_npu_fp) + self.sort_index_for_npu_bp = torch.IntTensor(sort_index_for_npu_bp) + self.sort_index_for_npu_todevice = False + + self.init_param() + + def init_param(self): + n = self.in_channels + for k in self.kernel_size: + n *= k + stdv = 1. / math.sqrt(n) + self.weight.data.uniform_(-stdv, stdv) + if self.bias is not None: + self.bias.data.zero_() + + if self.pack: + self.conv_offset.weight.data.zero_() + self.conv_offset.bias.data.zero_() + + def forward(self, x): + if self.pack: + out = self.conv_offset(x) + offset = out[:, :self.split_num, ...] + mask = torch.sigmoid(out[:, self.split_num:, ...]) + else: + x, offset, mask = x + + if not self.sort_index_for_npu_todevice: + self.sort_index_for_npu_fp = self.sort_index_for_npu_fp.to(x.device) + self.sort_index_for_npu_bp = self.sort_index_for_npu_bp.to(x.device) + self.bias = self.bias.to(x.device) + self.sort_index_for_npu_todevice = True + + return ModulatedDeformConv2dFunction.apply( + x, offset, mask, self.weight, self.bias, self.with_bias, + self.stride, self.padding, self.dilation, + self.groups, self.deformable_groups, + self.sort_index_for_npu_fp, + self.sort_index_for_npu_bp, + ) + + +DCNv2 = ModulatedDeformConv + +if __name__ == "__main__": + x = torch.randn(2, 32, 7, 7) + model = DCNv2(32, 32, 3, 2, 1) + + torch.npu.set_device(0) + x = x.npu() + model = model.npu() + + o = model(x) + l = o.sum() + l.backward() + print(l) diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/opts.py b/PyTorch/contrib/cv/detection/CenterNet/src/lib/opts.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/trains/base_trainer.py b/PyTorch/contrib/cv/detection/CenterNet/src/lib/trains/base_trainer.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/trains/ctdet.py b/PyTorch/contrib/cv/detection/CenterNet/src/lib/trains/ctdet.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/trains/ddd.py b/PyTorch/contrib/cv/detection/CenterNet/src/lib/trains/ddd.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/trains/exdet.py b/PyTorch/contrib/cv/detection/CenterNet/src/lib/trains/exdet.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/trains/multi_pose.py b/PyTorch/contrib/cv/detection/CenterNet/src/lib/trains/multi_pose.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/utils/__init__.py b/PyTorch/contrib/cv/detection/CenterNet/src/lib/utils/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/lib/utils/image.py b/PyTorch/contrib/cv/detection/CenterNet/src/lib/utils/image.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/main.py b/PyTorch/contrib/cv/detection/CenterNet/src/main.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/test.py b/PyTorch/contrib/cv/detection/CenterNet/src/test.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/src/tools/reval.py b/PyTorch/contrib/cv/detection/CenterNet/src/tools/reval.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/CenterNet/test/modelzoo_level.txt b/PyTorch/contrib/cv/detection/CenterNet/test/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/detection/CenterNet/test/modelzoo_level.txt +++ b/PyTorch/contrib/cv/detection/CenterNet/test/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/FCOS/README_raw.md b/PyTorch/contrib/cv/detection/FCOS/README_raw.md index 0b2c85262737aa6cae68a33d50ac113fd5603384..a58b943634f87935df007bbee3554ac38555064d 100644 --- a/PyTorch/contrib/cv/detection/FCOS/README_raw.md +++ b/PyTorch/contrib/cv/detection/FCOS/README_raw.md @@ -1,157 +1,157 @@ -# Warning -- 当前README为原生mmdetection自带的,请参考[README_raw.md](https://gitee.com/ascend/modelzoo/blob/master/contrib/PyTorch/Research/cv/image_object_detection/FCOS/README_raw.md)来进行FCOS模型训练 - - - -
- -
- -**News**: We released the technical report on [ArXiv](https://arxiv.org/abs/1906.07155). - -Documentation: https://mmdetection.readthedocs.io/ - -## Introduction - -MMDetection is an open source object detection toolbox based on PyTorch. It is -a part of the OpenMMLab project developed by [Multimedia Laboratory, CUHK](http://mmlab.ie.cuhk.edu.hk/). - -The master branch works with **PyTorch 1.3 to 1.6**. -The old v1.x branch works with PyTorch 1.1 to 1.4, but v2.0 is strongly recommended for faster speed, higher performance, better design and more friendly usage. - -![demo image](resources/coco_test_12510.jpg) - -### Major features - -- **Modular Design** - - We decompose the detection framework into different components and one can easily construct a customized object detection framework by combining different modules. - -- **Support of multiple frameworks out of box** - - The toolbox directly supports popular and contemporary detection frameworks, *e.g.* Faster RCNN, Mask RCNN, RetinaNet, etc. - -- **High efficiency** - - All basic bbox and mask operations run on GPUs. The training speed is faster than or comparable to other codebases, including [Detectron2](https://github.com/facebookresearch/detectron2), [maskrcnn-benchmark](https://github.com/facebookresearch/maskrcnn-benchmark) and [SimpleDet](https://github.com/TuSimple/simpledet). - -- **State of the art** - - The toolbox stems from the codebase developed by the *MMDet* team, who won [COCO Detection Challenge](http://cocodataset.org/#detection-leaderboard) in 2018, and we keep pushing it forward. - -Apart from MMDetection, we also released a library [mmcv](https://github.com/open-mmlab/mmcv) for computer vision research, which is heavily depended on by this toolbox. - -## License - -This project is released under the [Apache 2.0 license](LICENSE). - -## Changelog - -v2.6.0 was released in 1/11/2020. -Please refer to [changelog.md](docs/changelog.md) for details and release history. -A comparison between v1.x and v2.0 codebases can be found in [compatibility.md](docs/compatibility.md). - -## Benchmark and model zoo - -Results and models are available in the [model zoo](docs/model_zoo.md). - -Supported backbones: -- [x] ResNet -- [x] ResNeXt -- [x] VGG -- [x] HRNet -- [x] RegNet -- [x] Res2Net -- [x] ResNeSt - -Supported methods: -- [x] [RPN](configs/rpn) -- [x] [Fast R-CNN](configs/fast_rcnn) -- [x] [Faster R-CNN](configs/faster_rcnn) -- [x] [Mask R-CNN](configs/mask_rcnn) -- [x] [Cascade R-CNN](configs/cascade_rcnn) -- [x] [Cascade Mask R-CNN](configs/cascade_rcnn) -- [x] [SSD](configs/ssd) -- [x] [RetinaNet](configs/retinanet) -- [x] [GHM](configs/ghm) -- [x] [Mask Scoring R-CNN](configs/ms_rcnn) -- [x] [Double-Head R-CNN](configs/double_heads) -- [x] [Hybrid Task Cascade](configs/htc) -- [x] [Libra R-CNN](configs/libra_rcnn) -- [x] [Guided Anchoring](configs/guided_anchoring) -- [x] [FCOS](configs/fcos) -- [x] [RepPoints](configs/reppoints) -- [x] [Foveabox](configs/foveabox) -- [x] [FreeAnchor](configs/free_anchor) -- [x] [NAS-FPN](configs/nas_fpn) -- [x] [ATSS](configs/atss) -- [x] [FSAF](configs/fsaf) -- [x] [PAFPN](configs/pafpn) -- [x] [Dynamic R-CNN](configs/dynamic_rcnn) -- [x] [PointRend](configs/point_rend) -- [x] [CARAFE](configs/carafe/README.md) -- [x] [DCNv2](configs/dcn/README.md) -- [x] [Group Normalization](configs/gn/README.md) -- [x] [Weight Standardization](configs/gn+ws/README.md) -- [x] [OHEM](configs/faster_rcnn/faster_rcnn_r50_fpn_ohem_1x_coco.py) -- [x] [Soft-NMS](configs/faster_rcnn/faster_rcnn_r50_fpn_soft_nms_1x_coco.py) -- [x] [Generalized Attention](configs/empirical_attention/README.md) -- [x] [GCNet](configs/gcnet/README.md) -- [x] [Mixed Precision (FP16) Training](configs/fp16/README.md) -- [x] [InstaBoost](configs/instaboost/README.md) -- [x] [GRoIE](configs/groie/README.md) -- [x] [DetectoRS](configs/detectors/README.md) -- [x] [Generalized Focal Loss](configs/gfl/README.md) -- [x] [CornerNet](configs/cornernet/README.md) -- [x] [Side-Aware Boundary Localization](configs/sabl/README.md) -- [x] [YOLOv3](configs/yolo/README.md) -- [x] [PAA](configs/paa/README.md) -- [x] [YOLACT](configs/yolact/README.md) -- [x] [CentripetalNet](configs/centripetalnet/README.md) -- [x] [VFNet](configs/vfnet/README.md) - -Some other methods are also supported in [projects using MMDetection](./docs/projects.md). - -## Installation - -Please refer to [get_started.md](docs/get_started.md) for installation. - -## Getting Started - -Please see [get_started.md](docs/get_started.md) for the basic usage of MMDetection. -We provide [colab tutorial](demo/MMDet_Tutorial.ipynb), and full guidance for quick run [with existing dataset](docs/1_exist_data_model.md) and [with new dataset](docs/2_new_data_model.md) for beginners. -There are also tutorials for [finetuning models](docs/tutorials/finetune.md), [adding new dataset](docs/tutorials/new_dataset.md), [designing data pipeline](docs/tutorials/data_pipeline.md), [customizing models](docs/tutorials/customize_models.md), [customizing runtime settings](docs/tutorials/customize_runtime.md) and [useful tools](docs/useful_tools.md). - -Please refer to [FAQ](docs/faq.md) for frequently asked questions. - -## Contributing - -We appreciate all contributions to improve MMDetection. Please refer to [CONTRIBUTING.md](.github/CONTRIBUTING.md) for the contributing guideline. - -## Acknowledgement - -MMDetection is an open source project that is contributed by researchers and engineers from various colleges and companies. We appreciate all the contributors who implement their methods or add new features, as well as users who give valuable feedbacks. -We wish that the toolbox and benchmark could serve the growing research community by providing a flexible toolkit to reimplement existing methods and develop their own new detectors. - -## Citation - -If you use this toolbox or benchmark in your research, please cite this project. - -``` -@article{mmdetection, - title = {{MMDetection}: Open MMLab Detection Toolbox and Benchmark}, - author = {Chen, Kai and Wang, Jiaqi and Pang, Jiangmiao and Cao, Yuhang and - Xiong, Yu and Li, Xiaoxiao and Sun, Shuyang and Feng, Wansen and - Liu, Ziwei and Xu, Jiarui and Zhang, Zheng and Cheng, Dazhi and - Zhu, Chenchen and Cheng, Tianheng and Zhao, Qijie and Li, Buyu and - Lu, Xin and Zhu, Rui and Wu, Yue and Dai, Jifeng and Wang, Jingdong - and Shi, Jianping and Ouyang, Wanli and Loy, Chen Change and Lin, Dahua}, - journal= {arXiv preprint arXiv:1906.07155}, - year={2019} -} -``` - -## Contact - -This repo is currently maintained by Kai Chen ([@hellock](http://github.com/hellock)), Yuhang Cao ([@yhcao6](https://github.com/yhcao6)), Wenwei Zhang ([@ZwwWayne](https://github.com/ZwwWayne)), -Jiarui Xu ([@xvjiarui](https://github.com/xvjiarui)). Other core developers include Jiangmiao Pang ([@OceanPang](https://github.com/OceanPang)) and Jiaqi Wang ([@myownskyW7](https://github.com/myownskyW7)). +# Warning +- 当前README为原生mmdetection自带的,请参考[README_raw.md](https://gitee.com/ascend/modelzoo/blob/master/contrib/PyTorch/Research/cv/image_object_detection/FCOS/README_raw.md)来进行FCOS模型训练 + + + +
+ +
+ +**News**: We released the technical report on [ArXiv](https://arxiv.org/abs/1906.07155). + +Documentation: https://mmdetection.readthedocs.io/ + +## Introduction + +MMDetection is an open source object detection toolbox based on PyTorch. It is +a part of the OpenMMLab project developed by [Multimedia Laboratory, CUHK](http://mmlab.ie.cuhk.edu.hk/). + +The master branch works with **PyTorch 1.3 to 1.6**. +The old v1.x branch works with PyTorch 1.1 to 1.4, but v2.0 is strongly recommended for faster speed, higher performance, better design and more friendly usage. + +![demo image](resources/coco_test_12510.jpg) + +### Major features + +- **Modular Design** + + We decompose the detection framework into different components and one can easily construct a customized object detection framework by combining different modules. + +- **Support of multiple frameworks out of box** + + The toolbox directly supports popular and contemporary detection frameworks, *e.g.* Faster RCNN, Mask RCNN, RetinaNet, etc. + +- **High efficiency** + + All basic bbox and mask operations run on GPUs. The training speed is faster than or comparable to other codebases, including [Detectron2](https://github.com/facebookresearch/detectron2), [maskrcnn-benchmark](https://github.com/facebookresearch/maskrcnn-benchmark) and [SimpleDet](https://github.com/TuSimple/simpledet). + +- **State of the art** + + The toolbox stems from the codebase developed by the *MMDet* team, who won [COCO Detection Challenge](http://cocodataset.org/#detection-leaderboard) in 2018, and we keep pushing it forward. + +Apart from MMDetection, we also released a library [mmcv](https://github.com/open-mmlab/mmcv) for computer vision research, which is heavily depended on by this toolbox. + +## License + +This project is released under the [Apache 2.0 license](LICENSE). + +## Changelog + +v2.6.0 was released in 1/11/2020. +Please refer to [changelog.md](docs/changelog.md) for details and release history. +A comparison between v1.x and v2.0 codebases can be found in [compatibility.md](docs/compatibility.md). + +## Benchmark and model zoo + +Results and models are available in the [model zoo](docs/model_zoo.md). + +Supported backbones: +- [x] ResNet +- [x] ResNeXt +- [x] VGG +- [x] HRNet +- [x] RegNet +- [x] Res2Net +- [x] ResNeSt + +Supported methods: +- [x] [RPN](configs/rpn) +- [x] [Fast R-CNN](configs/fast_rcnn) +- [x] [Faster R-CNN](configs/faster_rcnn) +- [x] [Mask R-CNN](configs/mask_rcnn) +- [x] [Cascade R-CNN](configs/cascade_rcnn) +- [x] [Cascade Mask R-CNN](configs/cascade_rcnn) +- [x] [SSD](configs/ssd) +- [x] [RetinaNet](configs/retinanet) +- [x] [GHM](configs/ghm) +- [x] [Mask Scoring R-CNN](configs/ms_rcnn) +- [x] [Double-Head R-CNN](configs/double_heads) +- [x] [Hybrid Task Cascade](configs/htc) +- [x] [Libra R-CNN](configs/libra_rcnn) +- [x] [Guided Anchoring](configs/guided_anchoring) +- [x] [FCOS](configs/fcos) +- [x] [RepPoints](configs/reppoints) +- [x] [Foveabox](configs/foveabox) +- [x] [FreeAnchor](configs/free_anchor) +- [x] [NAS-FPN](configs/nas_fpn) +- [x] [ATSS](configs/atss) +- [x] [FSAF](configs/fsaf) +- [x] [PAFPN](configs/pafpn) +- [x] [Dynamic R-CNN](configs/dynamic_rcnn) +- [x] [PointRend](configs/point_rend) +- [x] [CARAFE](configs/carafe/README.md) +- [x] [DCNv2](configs/dcn/README.md) +- [x] [Group Normalization](configs/gn/README.md) +- [x] [Weight Standardization](configs/gn+ws/README.md) +- [x] [OHEM](configs/faster_rcnn/faster_rcnn_r50_fpn_ohem_1x_coco.py) +- [x] [Soft-NMS](configs/faster_rcnn/faster_rcnn_r50_fpn_soft_nms_1x_coco.py) +- [x] [Generalized Attention](configs/empirical_attention/README.md) +- [x] [GCNet](configs/gcnet/README.md) +- [x] [Mixed Precision (FP16) Training](configs/fp16/README.md) +- [x] [InstaBoost](configs/instaboost/README.md) +- [x] [GRoIE](configs/groie/README.md) +- [x] [DetectoRS](configs/detectors/README.md) +- [x] [Generalized Focal Loss](configs/gfl/README.md) +- [x] [CornerNet](configs/cornernet/README.md) +- [x] [Side-Aware Boundary Localization](configs/sabl/README.md) +- [x] [YOLOv3](configs/yolo/README.md) +- [x] [PAA](configs/paa/README.md) +- [x] [YOLACT](configs/yolact/README.md) +- [x] [CentripetalNet](configs/centripetalnet/README.md) +- [x] [VFNet](configs/vfnet/README.md) + +Some other methods are also supported in [projects using MMDetection](./docs/projects.md). + +## Installation + +Please refer to [get_started.md](docs/get_started.md) for installation. + +## Getting Started + +Please see [get_started.md](docs/get_started.md) for the basic usage of MMDetection. +We provide [colab tutorial](demo/MMDet_Tutorial.ipynb), and full guidance for quick run [with existing dataset](docs/1_exist_data_model.md) and [with new dataset](docs/2_new_data_model.md) for beginners. +There are also tutorials for [finetuning models](docs/tutorials/finetune.md), [adding new dataset](docs/tutorials/new_dataset.md), [designing data pipeline](docs/tutorials/data_pipeline.md), [customizing models](docs/tutorials/customize_models.md), [customizing runtime settings](docs/tutorials/customize_runtime.md) and [useful tools](docs/useful_tools.md). + +Please refer to [FAQ](docs/faq.md) for frequently asked questions. + +## Contributing + +We appreciate all contributions to improve MMDetection. Please refer to [CONTRIBUTING.md](.github/CONTRIBUTING.md) for the contributing guideline. + +## Acknowledgement + +MMDetection is an open source project that is contributed by researchers and engineers from various colleges and companies. We appreciate all the contributors who implement their methods or add new features, as well as users who give valuable feedbacks. +We wish that the toolbox and benchmark could serve the growing research community by providing a flexible toolkit to reimplement existing methods and develop their own new detectors. + +## Citation + +If you use this toolbox or benchmark in your research, please cite this project. + +``` +@article{mmdetection, + title = {{MMDetection}: Open MMLab Detection Toolbox and Benchmark}, + author = {Chen, Kai and Wang, Jiaqi and Pang, Jiangmiao and Cao, Yuhang and + Xiong, Yu and Li, Xiaoxiao and Sun, Shuyang and Feng, Wansen and + Liu, Ziwei and Xu, Jiarui and Zhang, Zheng and Cheng, Dazhi and + Zhu, Chenchen and Cheng, Tianheng and Zhao, Qijie and Li, Buyu and + Lu, Xin and Zhu, Rui and Wu, Yue and Dai, Jifeng and Wang, Jingdong + and Shi, Jianping and Ouyang, Wanli and Loy, Chen Change and Lin, Dahua}, + journal= {arXiv preprint arXiv:1906.07155}, + year={2019} +} +``` + +## Contact + +This repo is currently maintained by Kai Chen ([@hellock](http://github.com/hellock)), Yuhang Cao ([@yhcao6](https://github.com/yhcao6)), Wenwei Zhang ([@ZwwWayne](https://github.com/ZwwWayne)), +Jiarui Xu ([@xvjiarui](https://github.com/xvjiarui)). Other core developers include Jiangmiao Pang ([@OceanPang](https://github.com/OceanPang)) and Jiaqi Wang ([@myownskyW7](https://github.com/myownskyW7)). diff --git a/PyTorch/contrib/cv/detection/FCOS/infer/convert/fcos_aipp.cfg b/PyTorch/contrib/cv/detection/FCOS/infer/convert/fcos_aipp.cfg index 6ad5dc2c5988175025c112a796089f01eeb29bb5..73eb52fe14cd900e66427c5d0956cb43510577f5 100644 --- a/PyTorch/contrib/cv/detection/FCOS/infer/convert/fcos_aipp.cfg +++ b/PyTorch/contrib/cv/detection/FCOS/infer/convert/fcos_aipp.cfg @@ -1,16 +1,16 @@ -aipp_op { - aipp_mode: static - input_format: RGB888_U8 - related_input_rank: 0 - csc_switch: false - rbuv_swap_switch: false - - mean_chn_0: 103 - mean_chn_1: 116 - mean_chn_2: 123 - var_reci_chn_0: 1.0 - var_reci_chn_1: 1.0 - var_reci_chn_2: 1.0 - - -} +aipp_op { + aipp_mode: static + input_format: RGB888_U8 + related_input_rank: 0 + csc_switch: false + rbuv_swap_switch: false + + mean_chn_0: 103 + mean_chn_1: 116 + mean_chn_2: 123 + var_reci_chn_0: 1.0 + var_reci_chn_1: 1.0 + var_reci_chn_2: 1.0 + + +} diff --git a/PyTorch/contrib/cv/detection/FCOS/infer/docker_start_infer.sh b/PyTorch/contrib/cv/detection/FCOS/infer/docker_start_infer.sh index 07b61defd1489b9c21337b7d7ac6c911bf422e78..022ff222968145977df53c32a26d31fde5429d39 100644 --- a/PyTorch/contrib/cv/detection/FCOS/infer/docker_start_infer.sh +++ b/PyTorch/contrib/cv/detection/FCOS/infer/docker_start_infer.sh @@ -1,48 +1,48 @@ -#!/bin/bash - -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -docker_image=$1 -data_dir=$2 - -function show_help() { - echo "Usage: docker_start.sh docker_image data_dir" -} - -function param_check() { - if [ -z "${docker_image}" ]; then - echo "please input docker_image" - show_help - exit 1 - fi - - if [ -z "${data_dir}" ]; then - echo "please input data_dir" - show_help - exit 1 - fi -} - -param_check - -docker run -it \ - --device=/dev/davinci0 \ - --device=/dev/davinci_manager \ - --device=/dev/devmm_svm \ - --device=/dev/hisi_hdc \ - -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ - -v ${data_dir}:${data_dir} \ - ${docker_image} \ +#!/bin/bash + +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +docker_image=$1 +data_dir=$2 + +function show_help() { + echo "Usage: docker_start.sh docker_image data_dir" +} + +function param_check() { + if [ -z "${docker_image}" ]; then + echo "please input docker_image" + show_help + exit 1 + fi + + if [ -z "${data_dir}" ]; then + echo "please input data_dir" + show_help + exit 1 + fi +} + +param_check + +docker run -it \ + --device=/dev/davinci0 \ + --device=/dev/davinci_manager \ + --device=/dev/devmm_svm \ + --device=/dev/hisi_hdc \ + -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ + -v ${data_dir}:${data_dir} \ + ${docker_image} \ /bin/bash \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/FCOS/infer/mxbase/CMakeLists.txt b/PyTorch/contrib/cv/detection/FCOS/infer/mxbase/CMakeLists.txt index a690071accd34528776dc5ffe080fdb5a5b339b8..732aa7ab6d0b958959b598d0bc5e9efe19cba08e 100644 --- a/PyTorch/contrib/cv/detection/FCOS/infer/mxbase/CMakeLists.txt +++ b/PyTorch/contrib/cv/detection/FCOS/infer/mxbase/CMakeLists.txt @@ -1,52 +1,52 @@ -cmake_minimum_required(VERSION 3.14.0) -project(fcos) -set(TARGET fcos) - -add_definitions(-DENABLE_DVPP_INTERFACE) -add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) -add_definitions(-Dgoogle=mindxsdk_private) -add_compile_options(-std=c++11 -fPIE -fstack-protector-all -fPIC -Wall) -add_link_options(-Wl,-z,relro,-z,now,-z,noexecstack -s -pie) - -# Check environment variable -if(NOT DEFINED ENV{ASCEND_HOME}) - message(FATAL_ERROR "please define environment variable:ASCEND_HOME") -endif() -if(NOT DEFINED ENV{ASCEND_VERSION}) - message(WARNING "please define environment variable:ASCEND_VERSION") -endif() -if(NOT DEFINED ENV{ARCH_PATTERN}) - message(WARNING "please define environment variable:ARCH_PATTERN") -endif() - -set(ACL_INC_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/include) -set(ACL_LIB_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/lib64) - -set(MXBASE_ROOT_DIR $ENV{MX_SDK_HOME}) -set(MXBASE_INC ${MXBASE_ROOT_DIR}/include) -set(MXBASE_LIB_DIR ${MXBASE_ROOT_DIR}/lib) -set(MXBASE_POST_LIB_DIR ${MXBASE_ROOT_DIR}/lib/modelpostprocessors) -set(MXBASE_POST_PROCESS_DIR ${MXBASE_ROOT_DIR}/include/MxBase/postprocess/include) - - -if(DEFINED ENV{MXSDK_OPENSOURCE_DIR}) - set(OPENSOURCE_DIR $ENV{MXSDK_OPENSOURCE_DIR}) -else() - set(OPENSOURCE_DIR ${MXBASE_ROOT_DIR}/opensource) -endif() -include_directories(${ACL_INC_DIR}) -include_directories(${OPENSOURCE_DIR}/include) -include_directories(${OPENSOURCE_DIR}/include/opencv4) - -include_directories(${MXBASE_INC}) -include_directories(${MXBASE_POST_PROCESS_DIR}) -link_directories(${ACL_LIB_DIR}) -link_directories(${OPENSOURCE_DIR}/lib) -link_directories(${MXBASE_LIB_DIR}) -link_directories(${MXBASE_POST_LIB_DIR}) - -add_executable(${TARGET} ./src/main.cpp ./src/fcos.cpp) - -target_link_libraries(${TARGET} glog cpprest mxbase opencv_world stdc++fs) - +cmake_minimum_required(VERSION 3.14.0) +project(fcos) +set(TARGET fcos) + +add_definitions(-DENABLE_DVPP_INTERFACE) +add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) +add_definitions(-Dgoogle=mindxsdk_private) +add_compile_options(-std=c++11 -fPIE -fstack-protector-all -fPIC -Wall) +add_link_options(-Wl,-z,relro,-z,now,-z,noexecstack -s -pie) + +# Check environment variable +if(NOT DEFINED ENV{ASCEND_HOME}) + message(FATAL_ERROR "please define environment variable:ASCEND_HOME") +endif() +if(NOT DEFINED ENV{ASCEND_VERSION}) + message(WARNING "please define environment variable:ASCEND_VERSION") +endif() +if(NOT DEFINED ENV{ARCH_PATTERN}) + message(WARNING "please define environment variable:ARCH_PATTERN") +endif() + +set(ACL_INC_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/include) +set(ACL_LIB_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/lib64) + +set(MXBASE_ROOT_DIR $ENV{MX_SDK_HOME}) +set(MXBASE_INC ${MXBASE_ROOT_DIR}/include) +set(MXBASE_LIB_DIR ${MXBASE_ROOT_DIR}/lib) +set(MXBASE_POST_LIB_DIR ${MXBASE_ROOT_DIR}/lib/modelpostprocessors) +set(MXBASE_POST_PROCESS_DIR ${MXBASE_ROOT_DIR}/include/MxBase/postprocess/include) + + +if(DEFINED ENV{MXSDK_OPENSOURCE_DIR}) + set(OPENSOURCE_DIR $ENV{MXSDK_OPENSOURCE_DIR}) +else() + set(OPENSOURCE_DIR ${MXBASE_ROOT_DIR}/opensource) +endif() +include_directories(${ACL_INC_DIR}) +include_directories(${OPENSOURCE_DIR}/include) +include_directories(${OPENSOURCE_DIR}/include/opencv4) + +include_directories(${MXBASE_INC}) +include_directories(${MXBASE_POST_PROCESS_DIR}) +link_directories(${ACL_LIB_DIR}) +link_directories(${OPENSOURCE_DIR}/lib) +link_directories(${MXBASE_LIB_DIR}) +link_directories(${MXBASE_POST_LIB_DIR}) + +add_executable(${TARGET} ./src/main.cpp ./src/fcos.cpp) + +target_link_libraries(${TARGET} glog cpprest mxbase opencv_world stdc++fs) + install(TARGETS ${TARGET} RUNTIME DESTINATION ${PROJECT_SOURCE_DIR}/) \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/FCOS/infer/mxbase/src/fcos.cpp b/PyTorch/contrib/cv/detection/FCOS/infer/mxbase/src/fcos.cpp index 9a3594115852f4f89825c98cba0ea63aef54017f..7b88e0267325a6b52e3506d8eeb584f976ca7528 100644 --- a/PyTorch/contrib/cv/detection/FCOS/infer/mxbase/src/fcos.cpp +++ b/PyTorch/contrib/cv/detection/FCOS/infer/mxbase/src/fcos.cpp @@ -1,313 +1,313 @@ -/* - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "fcos.h" -#include "MxBase/DeviceManager/DeviceManager.h" -#include "MxBase/DvppWrapper/DvppWrapper.h" -#include "MxBase/Log/Log.h" - -using namespace MxBase; - -std::vector classes = {"person", "bicycle", "car", "motorcycle", "airplane", "bus", - "train", "truck", "boat", "traffic light", "fire hydrant", - "stop sign", "parking meter", "bench", "bird", "cat", "dog", - "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", - "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", - "skis", "snowboard", "sports ball", "kite", "baseball bat", - "baseball glove", "skateboard", "surfboard", "tennis racket", - "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", - "banana", "apple", "sandwich", "orange", "broccoli", "carrot", - "hot dog", "pizza", "donut", "cake", "chair", "couch", - "potted plant", "bed", "dining table", "toilet", "tv", "laptop", - "mouse", "remote", "keyboard", "cell phone", "microwave", - "oven", "toaster", "sink", "refrigerator", "book", "clock", - "vase", "scissors", "teddy bear", "hair drier", "toothbrush"}; - -APP_ERROR FCOS::Init(const InitParam& initParam) { - // Equipment initialization - APP_ERROR ret = MxBase::DeviceManager::GetInstance()->InitDevices(); - if (ret != APP_ERR_OK) { - LogError << "Init devices failed, ret=" << ret << "."; - return ret; - } - // Context initialization - ret = MxBase::TensorContext::GetInstance()->SetContext(initParam.deviceId); - if (ret != APP_ERR_OK) { - LogError << "Set context failed, ret=" << ret << "."; - return ret; - } - - // Load model - model_ = std::make_shared(); - ret = model_->Init(initParam.modelPath, modelDesc_); - if (ret != APP_ERR_OK) { - LogError << "ModelInferenceProcessor init failed, ret=" << ret << "."; - return ret; - } - return APP_ERR_OK; -} - -APP_ERROR FCOS::DeInit() { - model_->DeInit(); - MxBase::DeviceManager::GetInstance()->DestroyDevices(); - return APP_ERR_OK; -} - -std::vector FCOS::GetFileList(const std::string &dirPath) { - /* - This function is getting data from dataset on the path. - - :param dirpath: a string of dataset path - :return: a collection of file paths - - */ - struct dirent *ptr; - DIR *dir = opendir(dirPath.c_str()); - std::vector files; - while ((ptr = readdir(dir)) != NULL) { - if (ptr->d_name[0] == '.') continue; - files.push_back(ptr->d_name); - } - closedir(dir); - return files; -} - -APP_ERROR FCOS::ReadImage(const std::string& imgPath, cv::Mat& imageMat, int& height, int& width) { - imageMat = cv::imread(imgPath, cv::IMREAD_COLOR); - width = imageMat.cols; - height = imageMat.rows; - - return APP_ERR_OK; -} - -APP_ERROR FCOS::ResizeImage(const cv::Mat& srcImageMat, cv::Mat& dstImageMat) { - float resizeHeight = 800; - float resizeWidth = 1333; - float scale = std::min(resizeWidth / srcImageMat.cols, resizeHeight / srcImageMat.rows); - int new_width = srcImageMat.cols * scale; - int new_height = srcImageMat.rows * scale; - const int average = 2; - int pad_w = resizeWidth - new_width; - int pad_h = resizeHeight - new_height; - int pad_left = pad_w / average; - int pad_right = pad_w - pad_left; - int pad_top = pad_h / average; - int pad_bottom = pad_h - pad_top; - - cv::resize(srcImageMat, dstImageMat, cv::Size(new_width,new_height), 0, 0, cv::INTER_CUBIC); //指定常量像素填充 - cv::copyMakeBorder(dstImageMat, dstImageMat, pad_top, pad_bottom, pad_left, pad_right, - cv::BorderTypes::BORDER_CONSTANT, cv::Scalar(0, 0, 0)); - - return APP_ERR_OK; -} - -APP_ERROR FCOS::CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase) -{ - const uint32_t dataSize = imageMat.cols * imageMat.rows * YUV444_RGB_WIDTH_NU; - MemoryData memoryDataDst(dataSize, MemoryData::MEMORY_DEVICE, deviceId_); - MemoryData memoryDataSrc(imageMat.data, dataSize, MemoryData::MEMORY_HOST_MALLOC); - - APP_ERROR ret = MemoryHelper::MxbsMallocAndCopy(memoryDataDst, memoryDataSrc); - if (ret != APP_ERR_OK) { - LogError << GetError(ret) << "Memory malloc failed."; - return ret; - } - - std::vector shape = {imageMat.rows * YUV444_RGB_WIDTH_NU, static_cast(imageMat.cols)}; - tensorBase = TensorBase(memoryDataDst, false, shape, TENSOR_DTYPE_UINT8); - return APP_ERR_OK; -} - - -APP_ERROR FCOS::Inference(const std::vector& inputs, std::vector& outputs) { - auto dtypes = model_->GetOutputDataType(); - for (size_t i = 0; i < modelDesc_.outputTensors.size(); ++i) { - std::vector shape = {}; - for (size_t j = 0; j < modelDesc_.outputTensors[i].tensorDims.size(); ++j) { - shape.push_back((uint32_t)modelDesc_.outputTensors[i].tensorDims[j]); - } - TensorBase tensor(shape, dtypes[i], MemoryData::MemoryType::MEMORY_DEVICE, deviceId_); - APP_ERROR ret = TensorBase::TensorBaseMalloc(tensor); - if (ret != APP_ERR_OK) { - LogError << "TensorBaseMalloc failed, ret=" << ret << "."; - return ret; - } - outputs.push_back(tensor); - } - DynamicInfo dynamicInfo = {}; - dynamicInfo.dynamicType = DynamicType::STATIC_BATCH; - APP_ERROR ret = model_->ModelInference(inputs, outputs, dynamicInfo); - if (ret != APP_ERR_OK) { - LogError << "ModelInference failed, ret=" << ret << "."; - return ret; - } - return APP_ERR_OK; -} - -APP_ERROR FCOS::PostProcess(const std::string& imgPath, std::vector& inputs, - const std::string &resultPath, int& height, int& width, const std::string& name, - std::string &showPath, float& PROB_THRES) { - MxBase::TensorBase& tensor = inputs[1]; //1*100 - int ret = tensor.ToHost(); - if (ret != APP_ERR_OK) { - LogError << GetError(ret) << "Tensor_1 deploy to host failed."; - return ret; - } - std::vector shape = tensor.GetShape(); - - auto labels = reinterpret_cast(tensor.GetBuffer()); //1*100 - - int label[100] = {0}; - for(int i = 0; i < 100; i++){ - label[i] = labels[i]; - } - - tensor = inputs[0]; //1*100*5 - ret = tensor.ToHost(); - if (ret != APP_ERR_OK) { - LogError << GetError(ret) << "Tensor_0 deploy to host failed."; - return ret; - } - - auto bbox = reinterpret_cast(tensor.GetBuffer()); - - // get infer coordinates - float image_size_w = width; - float image_size_h = height; - float net_input_width = 1333; - float net_input_height = 800; - float scale = std::min(net_input_width / image_size_w, net_input_height / image_size_h); - - int pad_w = net_input_width - image_size_w * scale; - int pad_h = net_input_height - image_size_h * scale; - int pad_left = pad_w / 2; - int pad_right = pad_w -pad_left; - int pad_top = pad_h / 2; - int pad_bottom = pad_h -pad_top; - - float prob_thres = PROB_THRES; - float ppbox[100][5] = {0}; - - for (int j = 0; j < 100; j++) { - ppbox[j][0] = (bbox[j][0]-pad_left)/scale; - ppbox[j][1] = (bbox[j][1]-pad_top)/scale; - ppbox[j][2] = (bbox[j][2]-pad_right)/scale; - ppbox[j][3] = (bbox[j][3]-pad_bottom)/scale; - ppbox[j][4] = bbox[j][4]; - - if (ppbox[j][0]<0) ppbox[j][0] = 0; - if (ppbox[j][1]<0) ppbox[j][1] = 0; - if (ppbox[j][2]>image_size_w) ppbox[j][2] = image_size_w; - if (ppbox[j][3]>image_size_h) ppbox[j][3] = image_size_h; - - } - - std::ofstream out(resultPath); - cv::Mat imgCur = cv::imread(imgPath); - for (int j = 0;j<100;j++) { - if (float(ppbox[j][4])80 ) { - continue; - } - - std::string class_name = classes[int(label[j])]; - std::string det_results_str = ""; - std::ostringstream oss; - oss< dirFileList = GetFileList(dirPath); - std::vector names, paths; - int i = 0; - for (auto imgFile : dirFileList) { - std::string imgPath = dirPath + "/" + imgFile; - std::string name = imgFile.substr(0, imgFile.find(".")); - std::string subresultPath = resultPath+"/"+name+".txt"; - cv::Mat imageMat; - int height, width; - APP_ERROR ret = ReadImage(imgPath, imageMat, height, width); - if (ret != APP_ERR_OK) { - LogError << "ReadImage failed, ret=" << ret << "."; - return ret; - } - ResizeImage(imageMat, imageMat); - TensorBase tensorBase; - ret = CVMatToTensorBase(imageMat, tensorBase); - if (ret != APP_ERR_OK) { - LogError << "CVMatToTensorBase failed, ret=" << ret << "."; - return ret; - } - std::vector inputs = {}; - std::vector outputs = {}; - inputs.push_back(tensorBase); - ret = Inference(inputs, outputs); - if (ret != APP_ERR_OK) { - LogError << "Inference failed, ret=" << ret << "."; - return ret; - } - ret = PostProcess(imgPath, outputs, subresultPath, height, width,name,showPath,PROB_THRES); - if (ret != APP_ERR_OK) { - LogError << "PostProcess failed, ret=" << ret << "."; - return ret; - } - i++; - LogInfo< +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "fcos.h" +#include "MxBase/DeviceManager/DeviceManager.h" +#include "MxBase/DvppWrapper/DvppWrapper.h" +#include "MxBase/Log/Log.h" + +using namespace MxBase; + +std::vector classes = {"person", "bicycle", "car", "motorcycle", "airplane", "bus", + "train", "truck", "boat", "traffic light", "fire hydrant", + "stop sign", "parking meter", "bench", "bird", "cat", "dog", + "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", + "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", + "skis", "snowboard", "sports ball", "kite", "baseball bat", + "baseball glove", "skateboard", "surfboard", "tennis racket", + "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", + "banana", "apple", "sandwich", "orange", "broccoli", "carrot", + "hot dog", "pizza", "donut", "cake", "chair", "couch", + "potted plant", "bed", "dining table", "toilet", "tv", "laptop", + "mouse", "remote", "keyboard", "cell phone", "microwave", + "oven", "toaster", "sink", "refrigerator", "book", "clock", + "vase", "scissors", "teddy bear", "hair drier", "toothbrush"}; + +APP_ERROR FCOS::Init(const InitParam& initParam) { + // Equipment initialization + APP_ERROR ret = MxBase::DeviceManager::GetInstance()->InitDevices(); + if (ret != APP_ERR_OK) { + LogError << "Init devices failed, ret=" << ret << "."; + return ret; + } + // Context initialization + ret = MxBase::TensorContext::GetInstance()->SetContext(initParam.deviceId); + if (ret != APP_ERR_OK) { + LogError << "Set context failed, ret=" << ret << "."; + return ret; + } + + // Load model + model_ = std::make_shared(); + ret = model_->Init(initParam.modelPath, modelDesc_); + if (ret != APP_ERR_OK) { + LogError << "ModelInferenceProcessor init failed, ret=" << ret << "."; + return ret; + } + return APP_ERR_OK; +} + +APP_ERROR FCOS::DeInit() { + model_->DeInit(); + MxBase::DeviceManager::GetInstance()->DestroyDevices(); + return APP_ERR_OK; +} + +std::vector FCOS::GetFileList(const std::string &dirPath) { + /* + This function is getting data from dataset on the path. + + :param dirpath: a string of dataset path + :return: a collection of file paths + + */ + struct dirent *ptr; + DIR *dir = opendir(dirPath.c_str()); + std::vector files; + while ((ptr = readdir(dir)) != NULL) { + if (ptr->d_name[0] == '.') continue; + files.push_back(ptr->d_name); + } + closedir(dir); + return files; +} + +APP_ERROR FCOS::ReadImage(const std::string& imgPath, cv::Mat& imageMat, int& height, int& width) { + imageMat = cv::imread(imgPath, cv::IMREAD_COLOR); + width = imageMat.cols; + height = imageMat.rows; + + return APP_ERR_OK; +} + +APP_ERROR FCOS::ResizeImage(const cv::Mat& srcImageMat, cv::Mat& dstImageMat) { + float resizeHeight = 800; + float resizeWidth = 1333; + float scale = std::min(resizeWidth / srcImageMat.cols, resizeHeight / srcImageMat.rows); + int new_width = srcImageMat.cols * scale; + int new_height = srcImageMat.rows * scale; + const int average = 2; + int pad_w = resizeWidth - new_width; + int pad_h = resizeHeight - new_height; + int pad_left = pad_w / average; + int pad_right = pad_w - pad_left; + int pad_top = pad_h / average; + int pad_bottom = pad_h - pad_top; + + cv::resize(srcImageMat, dstImageMat, cv::Size(new_width,new_height), 0, 0, cv::INTER_CUBIC); //指定常量像素填充 + cv::copyMakeBorder(dstImageMat, dstImageMat, pad_top, pad_bottom, pad_left, pad_right, + cv::BorderTypes::BORDER_CONSTANT, cv::Scalar(0, 0, 0)); + + return APP_ERR_OK; +} + +APP_ERROR FCOS::CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase) +{ + const uint32_t dataSize = imageMat.cols * imageMat.rows * YUV444_RGB_WIDTH_NU; + MemoryData memoryDataDst(dataSize, MemoryData::MEMORY_DEVICE, deviceId_); + MemoryData memoryDataSrc(imageMat.data, dataSize, MemoryData::MEMORY_HOST_MALLOC); + + APP_ERROR ret = MemoryHelper::MxbsMallocAndCopy(memoryDataDst, memoryDataSrc); + if (ret != APP_ERR_OK) { + LogError << GetError(ret) << "Memory malloc failed."; + return ret; + } + + std::vector shape = {imageMat.rows * YUV444_RGB_WIDTH_NU, static_cast(imageMat.cols)}; + tensorBase = TensorBase(memoryDataDst, false, shape, TENSOR_DTYPE_UINT8); + return APP_ERR_OK; +} + + +APP_ERROR FCOS::Inference(const std::vector& inputs, std::vector& outputs) { + auto dtypes = model_->GetOutputDataType(); + for (size_t i = 0; i < modelDesc_.outputTensors.size(); ++i) { + std::vector shape = {}; + for (size_t j = 0; j < modelDesc_.outputTensors[i].tensorDims.size(); ++j) { + shape.push_back((uint32_t)modelDesc_.outputTensors[i].tensorDims[j]); + } + TensorBase tensor(shape, dtypes[i], MemoryData::MemoryType::MEMORY_DEVICE, deviceId_); + APP_ERROR ret = TensorBase::TensorBaseMalloc(tensor); + if (ret != APP_ERR_OK) { + LogError << "TensorBaseMalloc failed, ret=" << ret << "."; + return ret; + } + outputs.push_back(tensor); + } + DynamicInfo dynamicInfo = {}; + dynamicInfo.dynamicType = DynamicType::STATIC_BATCH; + APP_ERROR ret = model_->ModelInference(inputs, outputs, dynamicInfo); + if (ret != APP_ERR_OK) { + LogError << "ModelInference failed, ret=" << ret << "."; + return ret; + } + return APP_ERR_OK; +} + +APP_ERROR FCOS::PostProcess(const std::string& imgPath, std::vector& inputs, + const std::string &resultPath, int& height, int& width, const std::string& name, + std::string &showPath, float& PROB_THRES) { + MxBase::TensorBase& tensor = inputs[1]; //1*100 + int ret = tensor.ToHost(); + if (ret != APP_ERR_OK) { + LogError << GetError(ret) << "Tensor_1 deploy to host failed."; + return ret; + } + std::vector shape = tensor.GetShape(); + + auto labels = reinterpret_cast(tensor.GetBuffer()); //1*100 + + int label[100] = {0}; + for(int i = 0; i < 100; i++){ + label[i] = labels[i]; + } + + tensor = inputs[0]; //1*100*5 + ret = tensor.ToHost(); + if (ret != APP_ERR_OK) { + LogError << GetError(ret) << "Tensor_0 deploy to host failed."; + return ret; + } + + auto bbox = reinterpret_cast(tensor.GetBuffer()); + + // get infer coordinates + float image_size_w = width; + float image_size_h = height; + float net_input_width = 1333; + float net_input_height = 800; + float scale = std::min(net_input_width / image_size_w, net_input_height / image_size_h); + + int pad_w = net_input_width - image_size_w * scale; + int pad_h = net_input_height - image_size_h * scale; + int pad_left = pad_w / 2; + int pad_right = pad_w -pad_left; + int pad_top = pad_h / 2; + int pad_bottom = pad_h -pad_top; + + float prob_thres = PROB_THRES; + float ppbox[100][5] = {0}; + + for (int j = 0; j < 100; j++) { + ppbox[j][0] = (bbox[j][0]-pad_left)/scale; + ppbox[j][1] = (bbox[j][1]-pad_top)/scale; + ppbox[j][2] = (bbox[j][2]-pad_right)/scale; + ppbox[j][3] = (bbox[j][3]-pad_bottom)/scale; + ppbox[j][4] = bbox[j][4]; + + if (ppbox[j][0]<0) ppbox[j][0] = 0; + if (ppbox[j][1]<0) ppbox[j][1] = 0; + if (ppbox[j][2]>image_size_w) ppbox[j][2] = image_size_w; + if (ppbox[j][3]>image_size_h) ppbox[j][3] = image_size_h; + + } + + std::ofstream out(resultPath); + cv::Mat imgCur = cv::imread(imgPath); + for (int j = 0;j<100;j++) { + if (float(ppbox[j][4])80 ) { + continue; + } + + std::string class_name = classes[int(label[j])]; + std::string det_results_str = ""; + std::ostringstream oss; + oss< dirFileList = GetFileList(dirPath); + std::vector names, paths; + int i = 0; + for (auto imgFile : dirFileList) { + std::string imgPath = dirPath + "/" + imgFile; + std::string name = imgFile.substr(0, imgFile.find(".")); + std::string subresultPath = resultPath+"/"+name+".txt"; + cv::Mat imageMat; + int height, width; + APP_ERROR ret = ReadImage(imgPath, imageMat, height, width); + if (ret != APP_ERR_OK) { + LogError << "ReadImage failed, ret=" << ret << "."; + return ret; + } + ResizeImage(imageMat, imageMat); + TensorBase tensorBase; + ret = CVMatToTensorBase(imageMat, tensorBase); + if (ret != APP_ERR_OK) { + LogError << "CVMatToTensorBase failed, ret=" << ret << "."; + return ret; + } + std::vector inputs = {}; + std::vector outputs = {}; + inputs.push_back(tensorBase); + ret = Inference(inputs, outputs); + if (ret != APP_ERR_OK) { + LogError << "Inference failed, ret=" << ret << "."; + return ret; + } + ret = PostProcess(imgPath, outputs, subresultPath, height, width,name,showPath,PROB_THRES); + if (ret != APP_ERR_OK) { + LogError << "PostProcess failed, ret=" << ret << "."; + return ret; + } + i++; + LogInfo< -#include "MxBase/ModelInfer/ModelInferenceProcessor.h" -#include "MxBase/PostProcessBases/PostProcessDataType.h" -#include "MxBase/Tensor/TensorContext/TensorContext.h" - -struct InitParam { - uint32_t deviceId; - std::string modelPath; -}; - -class FCOS { -public: - - APP_ERROR Init(const InitParam &initParam); - APP_ERROR DeInit(); - APP_ERROR ReadImage(const std::string &imgPath, cv::Mat &imageMat, int& height, int& width); - APP_ERROR ResizeImage(const cv::Mat &srcImageMat, cv::Mat &dstImageMat); - APP_ERROR CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase); - APP_ERROR VectorToTensorBase(int* transMat, MxBase::TensorBase& tensorBase); - APP_ERROR Inference(const std::vector &inputs, std::vector &outputs); - APP_ERROR PostProcess(const std::string& imgPath, std::vector &inputs, - const std::string &subresultPath,int& height, int& width,const std::string& name, - std::string &showPath,float& PROB_THRES); - APP_ERROR Process(const std::string &dirPath, std::string &resultPath,std::string &showPath,float& PROB_THRES); - -private: - std::shared_ptr model_; - std::vector GetFileList(const std::string &dirPath); - MxBase::ModelDesc modelDesc_; - const int device_id = 0; - uint32_t deviceId_ = device_id; -}; -#endif +/* + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FCOS_H +#define FCOS_H + +#include +#include "MxBase/ModelInfer/ModelInferenceProcessor.h" +#include "MxBase/PostProcessBases/PostProcessDataType.h" +#include "MxBase/Tensor/TensorContext/TensorContext.h" + +struct InitParam { + uint32_t deviceId; + std::string modelPath; +}; + +class FCOS { +public: + + APP_ERROR Init(const InitParam &initParam); + APP_ERROR DeInit(); + APP_ERROR ReadImage(const std::string &imgPath, cv::Mat &imageMat, int& height, int& width); + APP_ERROR ResizeImage(const cv::Mat &srcImageMat, cv::Mat &dstImageMat); + APP_ERROR CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase); + APP_ERROR VectorToTensorBase(int* transMat, MxBase::TensorBase& tensorBase); + APP_ERROR Inference(const std::vector &inputs, std::vector &outputs); + APP_ERROR PostProcess(const std::string& imgPath, std::vector &inputs, + const std::string &subresultPath,int& height, int& width,const std::string& name, + std::string &showPath,float& PROB_THRES); + APP_ERROR Process(const std::string &dirPath, std::string &resultPath,std::string &showPath,float& PROB_THRES); + +private: + std::shared_ptr model_; + std::vector GetFileList(const std::string &dirPath); + MxBase::ModelDesc modelDesc_; + const int device_id = 0; + uint32_t deviceId_ = device_id; +}; +#endif diff --git a/PyTorch/contrib/cv/detection/FCOS/infer/mxbase/src/main.cpp b/PyTorch/contrib/cv/detection/FCOS/infer/mxbase/src/main.cpp index 6acf366700e8ece4c5653fe7204001ad31124e7b..d3a1d13c09e80f31f455ee95eb74d134c66c1a07 100644 --- a/PyTorch/contrib/cv/detection/FCOS/infer/mxbase/src/main.cpp +++ b/PyTorch/contrib/cv/detection/FCOS/infer/mxbase/src/main.cpp @@ -1,45 +1,45 @@ -/* - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "MxBase/Log/Log.h" -#include "fcos.h" - -int main() { - InitParam initParam = {}; - initParam.deviceId = 0; - initParam.modelPath = "../../data/model/fcos.om"; - FCOS fcos; - APP_ERROR ret = fcos.Init(initParam); - if (ret != APP_ERR_OK) { - LogError << "FCOS init failed, ret=" << ret << "."; - return ret; - } - - std::string imgPath = "../../data/input/COCO2017/val2017"; - std::string resultPath = "../data/infer_result"; - std::string showPath = "../data/show_result"; - float PROB_THRES = 0.05; - - ret = fcos.Process(imgPath,resultPath,showPath,PROB_THRES); - if (ret != APP_ERR_OK) { - LogError << "FCOS process failed, ret=" << ret << "."; - fcos.DeInit(); - return ret; - } - - fcos.DeInit(); - return APP_ERR_OK; -} +/* + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MxBase/Log/Log.h" +#include "fcos.h" + +int main() { + InitParam initParam = {}; + initParam.deviceId = 0; + initParam.modelPath = "../../data/model/fcos.om"; + FCOS fcos; + APP_ERROR ret = fcos.Init(initParam); + if (ret != APP_ERR_OK) { + LogError << "FCOS init failed, ret=" << ret << "."; + return ret; + } + + std::string imgPath = "../../data/input/COCO2017/val2017"; + std::string resultPath = "../data/infer_result"; + std::string showPath = "../data/show_result"; + float PROB_THRES = 0.05; + + ret = fcos.Process(imgPath,resultPath,showPath,PROB_THRES); + if (ret != APP_ERR_OK) { + LogError << "FCOS process failed, ret=" << ret << "."; + fcos.DeInit(); + return ret; + } + + fcos.DeInit(); + return APP_ERR_OK; +} diff --git a/PyTorch/contrib/cv/detection/FCOS/infer/sdk/fcos_opencv_all.py b/PyTorch/contrib/cv/detection/FCOS/infer/sdk/fcos_opencv_all.py index 2108426f9fe5c4dd60f15408878161638ec5640d..92551e0984479401b7c5ba901816f76fc2854625 100644 --- a/PyTorch/contrib/cv/detection/FCOS/infer/sdk/fcos_opencv_all.py +++ b/PyTorch/contrib/cv/detection/FCOS/infer/sdk/fcos_opencv_all.py @@ -1,289 +1,289 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import argparse -import base64 -import json -import os - -import cv2 -import numpy as np -from StreamManagerApi import MxDataInput -from StreamManagerApi import StreamManagerApi -from skimage import io - - -def parse_arg(): - parser = argparse.ArgumentParser(description="FCOS infer") - parser.add_argument("--dataset", default="../data/input/COCO2017/val2017") - parser.add_argument("--pipeline", default="../data/config/fcos.pipeline") - parser.add_argument("--test_annotation", - default="../data/input/COCO2017/coco2017.info") - parser.add_argument("--det_results_path", default="./data/infer_result") - parser.add_argument("--show_results_path", default="./data/show_result") - parser.add_argument("--net_input_width", default=1333) - parser.add_argument("--net_input_height", default=800) - parser.add_argument("--prob_thres", default=0.05) - parser.add_argument( - "--ifShowDetObj", - default="True", - action="store_true", - help="if input the para means True, neither False.") - - flags = parser.parse_args() - return flags - - -def get_dataset(path): - """ - This function is getting data from dataset on the path. - - :param path: a string of dataset path - - """ - for root, dirs, files in os.walk(path): - for file_name in files: - if file_name.endswith('jpg') or file_name.endswith('JPG'): - yield os.path.join(path, file_name) - break - - -def get_stream_manager(pipeline_path): - """ - This function is using stream_manager_api. - - :param pipeline_path: a string of pipeline path - :return: a stream manager - - """ - stream_manager_api = StreamManagerApi() - ret = stream_manager_api.InitManager() - if ret != 0: - print("Failed to init Stream manager, ret=%s" % str(ret)) - exit() - - with open(pipeline_path, 'rb') as f: - pipeline_content = f.read() - - ret = stream_manager_api.CreateMultipleStreams(pipeline_content) - if ret != 0: - print("Failed to create stream, ret=%s" % str(ret)) - exit() - return stream_manager_api - - -def do_infer_image(stream_manager_api, image_path): - """ - This function is executing the inference of images. - - :param stream_manager_api: a stream manager - :param image_path: a string of image path - :return: bbox, labels - - bbox,labels: (1,100,5),(1,100) - The model has two output tensors: - bbox:(x0, y0, x1, y1,confidence) - #the upper left and lower right coordinates of the detection boxes - labels: probability of 80 classes - """ - stream_name = b'im_fcos' - data_input = MxDataInput() - with open(image_path, 'rb') as f: - data_input.data = f.read() - - unique_id = stream_manager_api.SendData(stream_name, 0, data_input) - if unique_id < 0: - print("Failed to send data to stream.") - exit() - - infer_result = stream_manager_api.GetResult(stream_name, unique_id) - if infer_result.errorCode != 0: - print(f"GetResult error. errorCode={infer_result.errorCode}," - f"errorMsg={infer_result.data.decode()}") - exit() - - infer_result_json = json.loads(infer_result.data.decode()) - content = json.loads(infer_result_json['metaData'][0]['content']) - # print the infer result - print(infer_result.data.decode()) - infer_result_json = json.loads(infer_result.data.decode()) - content = json.loads(infer_result_json['metaData'][0]['content']) - tensor_vec = content['tensorPackageVec'][0]['tensorVec'][0] - data_str = tensor_vec['dataStr'] - tensor_shape = tensor_vec['tensorShape'] - bbox = np.frombuffer(base64.b64decode(data_str), dtype=np.float32) - bbox = np.reshape(bbox, tensor_shape[1:]) - # [bbox,labels] (1,100,5);(1,100) - - print("---------------------------bbox---------------------------") - print(bbox) - print() - print(bbox.shape) - print("-----------------------------------------------------------------") - - tensor_vec = content['tensorPackageVec'][0]['tensorVec'][1] - data_str = tensor_vec['dataStr'] - tensor_shape = tensor_vec['tensorShape'] - labels = np.frombuffer(base64.b64decode(data_str), dtype=np.int64) - labels = np.reshape(labels, tensor_shape[1:]) - print("---------------------------labels---------------------------") - print(labels) - print() - print(labels.shape) - print("-----------------------------------------------------------------") - return bbox, labels - - -CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', - 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', - 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', - 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', - 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', - 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', - 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', - 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', - 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', - 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', - 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', - 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] - - -def coco_postprocess(bbox: np.ndarray, image_size, - net_input_width, net_input_height): - """ - This function is postprocessing for FCOS output. - - Before calling this function, reshape the raw output of FCOS to - following form - numpy.ndarray: - [x0, y0, x1, y1, confidence, probability of 80 classes] - shape: (100,) - The postprocessing restore the bounding rectangles of FCOS output - to origin scale and filter with non-maximum suppression. - - :param bbox: a numpy array of the FCOS output - :param image_path: a string of image path - :return: three list for best bound, class and score - """ - w = image_size[0] - h = image_size[1] - scale = min(net_input_width / w, net_input_height / h) - - pad_w = net_input_width - w * scale - pad_h = net_input_height - h * scale - pad_left = pad_w // 2 - pad_top = pad_h // 2 - - # cal predict box on the image src - pbox = bbox - - pbox[:, 0] = (bbox[:, 0] - pad_left) / scale - pbox[:, 1] = (bbox[:, 1] - pad_top) / scale - pbox[:, 2] = (bbox[:, 2] - pad_left) / scale - pbox[:, 3] = (bbox[:, 3] - pad_top) / scale - - # make pbboxes value in valid range - pbox[:, 0] = np.maximum(pbox[:, 0], 0) - pbox[:, 1] = np.maximum(pbox[:, 1], 0) - pbox[:, 2] = np.minimum(pbox[:, 2], w) - pbox[:, 3] = np.minimum(pbox[:, 3], h) - - return pbox - - -def main(args): - i = 0 - path = args.dataset - print(args.ifShowDetObj, type(args.ifShowDetObj)) - det_results_path = args.det_results_path - show_results_path = args.show_results_path - os.makedirs(det_results_path, exist_ok=True) - os.makedirs(show_results_path, exist_ok=True) - stream_manager_api = get_stream_manager(args.pipeline) - img_size_dict = dict() - with open(args.test_annotation)as f: - for line in f.readlines(): - temp = line.split(" ") - img_file_path = temp[1] - img_name = temp[1].split("/")[-1].split(".")[0] - img_width = int(temp[2]) - img_height = int(temp[3]) - img_size_dict[img_name] = (img_width, img_height, img_file_path) - - for img_path in get_dataset(path): - image_1 = io.imread(img_path) - if len(image_1.shape) == 3: - if image_1.shape[2] != 3: - continue - file_name1 = os.path.basename(img_path) - file_name = file_name1.split('.')[0] - print(file_name1) - delete_img_name = ['000000374551.jpg', '000000003661.jpg', - '000000309391.jpg', '000000070254.jpg'] - if file_name1 in delete_img_name: - continue - - bbox, labels = do_infer_image(stream_manager_api, img_path) - - res_buff = [] - res_buff.append(bbox) - labels = np.reshape(labels, [100, 1]) - res_buff.append(labels) - res_tensor = np.concatenate(res_buff, axis=1) - current_img_size = img_size_dict[file_name] - print("[TEST]---------------------------concat{} imgsize{}".format( - len(res_tensor), current_img_size)) - predbox = coco_postprocess( - res_tensor, current_img_size, args.net_input_width, args.net_input_height) - - if args.ifShowDetObj == True: - imgCur = cv2.imread(img_path) - - det_results_str = '' - for idx, class_ind in enumerate(predbox[:, 5]): - if float(predbox[idx][4]) < float(args.prob_thres): - continue - # skip negative class index - if class_ind < 0 or class_ind > 80: - continue - - class_name = CLASSES[int(class_ind)] - det_results_str += "{} {} {} {} {} {}\n".format(class_name, str(predbox[idx][4]), predbox[idx][0], - predbox[idx][1], predbox[idx][2], predbox[idx][3]) - if args.ifShowDetObj == True: - imgCur = cv2.rectangle(imgCur, (int(predbox[idx][0]), int(predbox[idx][1])), - (int(predbox[idx][2]), int(predbox[idx][3])), (0, 255, 0), 1) - imgCur = cv2.putText(imgCur, class_name+'|'+str(predbox[idx][4]), - (int(predbox[idx][0]), int(predbox[idx][1])), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1) - # Image, text content, coordinates, font, size, color and font thickness. - - if args.ifShowDetObj == True: - print(os.path.join(show_results_path, file_name + '.jpg')) - cv2.imwrite(os.path.join(show_results_path, file_name + - '.jpg'), imgCur, [int(cv2.IMWRITE_JPEG_QUALITY), 70]) - - det_results_file = os.path.join(det_results_path, file_name + ".txt") - with open(det_results_file, "w") as detf: - detf.write(det_results_str) - print(det_results_str) - i = i+1 - print(i) - - stream_manager_api.DestroyAllStreams() - - -if __name__ == "__main__": - args = parse_arg() - main(args) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import argparse +import base64 +import json +import os + +import cv2 +import numpy as np +from StreamManagerApi import MxDataInput +from StreamManagerApi import StreamManagerApi +from skimage import io + + +def parse_arg(): + parser = argparse.ArgumentParser(description="FCOS infer") + parser.add_argument("--dataset", default="../data/input/COCO2017/val2017") + parser.add_argument("--pipeline", default="../data/config/fcos.pipeline") + parser.add_argument("--test_annotation", + default="../data/input/COCO2017/coco2017.info") + parser.add_argument("--det_results_path", default="./data/infer_result") + parser.add_argument("--show_results_path", default="./data/show_result") + parser.add_argument("--net_input_width", default=1333) + parser.add_argument("--net_input_height", default=800) + parser.add_argument("--prob_thres", default=0.05) + parser.add_argument( + "--ifShowDetObj", + default="True", + action="store_true", + help="if input the para means True, neither False.") + + flags = parser.parse_args() + return flags + + +def get_dataset(path): + """ + This function is getting data from dataset on the path. + + :param path: a string of dataset path + + """ + for root, dirs, files in os.walk(path): + for file_name in files: + if file_name.endswith('jpg') or file_name.endswith('JPG'): + yield os.path.join(path, file_name) + break + + +def get_stream_manager(pipeline_path): + """ + This function is using stream_manager_api. + + :param pipeline_path: a string of pipeline path + :return: a stream manager + + """ + stream_manager_api = StreamManagerApi() + ret = stream_manager_api.InitManager() + if ret != 0: + print("Failed to init Stream manager, ret=%s" % str(ret)) + exit() + + with open(pipeline_path, 'rb') as f: + pipeline_content = f.read() + + ret = stream_manager_api.CreateMultipleStreams(pipeline_content) + if ret != 0: + print("Failed to create stream, ret=%s" % str(ret)) + exit() + return stream_manager_api + + +def do_infer_image(stream_manager_api, image_path): + """ + This function is executing the inference of images. + + :param stream_manager_api: a stream manager + :param image_path: a string of image path + :return: bbox, labels + + bbox,labels: (1,100,5),(1,100) + The model has two output tensors: + bbox:(x0, y0, x1, y1,confidence) + #the upper left and lower right coordinates of the detection boxes + labels: probability of 80 classes + """ + stream_name = b'im_fcos' + data_input = MxDataInput() + with open(image_path, 'rb') as f: + data_input.data = f.read() + + unique_id = stream_manager_api.SendData(stream_name, 0, data_input) + if unique_id < 0: + print("Failed to send data to stream.") + exit() + + infer_result = stream_manager_api.GetResult(stream_name, unique_id) + if infer_result.errorCode != 0: + print(f"GetResult error. errorCode={infer_result.errorCode}," + f"errorMsg={infer_result.data.decode()}") + exit() + + infer_result_json = json.loads(infer_result.data.decode()) + content = json.loads(infer_result_json['metaData'][0]['content']) + # print the infer result + print(infer_result.data.decode()) + infer_result_json = json.loads(infer_result.data.decode()) + content = json.loads(infer_result_json['metaData'][0]['content']) + tensor_vec = content['tensorPackageVec'][0]['tensorVec'][0] + data_str = tensor_vec['dataStr'] + tensor_shape = tensor_vec['tensorShape'] + bbox = np.frombuffer(base64.b64decode(data_str), dtype=np.float32) + bbox = np.reshape(bbox, tensor_shape[1:]) + # [bbox,labels] (1,100,5);(1,100) + + print("---------------------------bbox---------------------------") + print(bbox) + print() + print(bbox.shape) + print("-----------------------------------------------------------------") + + tensor_vec = content['tensorPackageVec'][0]['tensorVec'][1] + data_str = tensor_vec['dataStr'] + tensor_shape = tensor_vec['tensorShape'] + labels = np.frombuffer(base64.b64decode(data_str), dtype=np.int64) + labels = np.reshape(labels, tensor_shape[1:]) + print("---------------------------labels---------------------------") + print(labels) + print() + print(labels.shape) + print("-----------------------------------------------------------------") + return bbox, labels + + +CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', + 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', + 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', + 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', + 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', + 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', + 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', + 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', + 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', + 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', + 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', + 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] + + +def coco_postprocess(bbox: np.ndarray, image_size, + net_input_width, net_input_height): + """ + This function is postprocessing for FCOS output. + + Before calling this function, reshape the raw output of FCOS to + following form + numpy.ndarray: + [x0, y0, x1, y1, confidence, probability of 80 classes] + shape: (100,) + The postprocessing restore the bounding rectangles of FCOS output + to origin scale and filter with non-maximum suppression. + + :param bbox: a numpy array of the FCOS output + :param image_path: a string of image path + :return: three list for best bound, class and score + """ + w = image_size[0] + h = image_size[1] + scale = min(net_input_width / w, net_input_height / h) + + pad_w = net_input_width - w * scale + pad_h = net_input_height - h * scale + pad_left = pad_w // 2 + pad_top = pad_h // 2 + + # cal predict box on the image src + pbox = bbox + + pbox[:, 0] = (bbox[:, 0] - pad_left) / scale + pbox[:, 1] = (bbox[:, 1] - pad_top) / scale + pbox[:, 2] = (bbox[:, 2] - pad_left) / scale + pbox[:, 3] = (bbox[:, 3] - pad_top) / scale + + # make pbboxes value in valid range + pbox[:, 0] = np.maximum(pbox[:, 0], 0) + pbox[:, 1] = np.maximum(pbox[:, 1], 0) + pbox[:, 2] = np.minimum(pbox[:, 2], w) + pbox[:, 3] = np.minimum(pbox[:, 3], h) + + return pbox + + +def main(args): + i = 0 + path = args.dataset + print(args.ifShowDetObj, type(args.ifShowDetObj)) + det_results_path = args.det_results_path + show_results_path = args.show_results_path + os.makedirs(det_results_path, exist_ok=True) + os.makedirs(show_results_path, exist_ok=True) + stream_manager_api = get_stream_manager(args.pipeline) + img_size_dict = dict() + with open(args.test_annotation)as f: + for line in f.readlines(): + temp = line.split(" ") + img_file_path = temp[1] + img_name = temp[1].split("/")[-1].split(".")[0] + img_width = int(temp[2]) + img_height = int(temp[3]) + img_size_dict[img_name] = (img_width, img_height, img_file_path) + + for img_path in get_dataset(path): + image_1 = io.imread(img_path) + if len(image_1.shape) == 3: + if image_1.shape[2] != 3: + continue + file_name1 = os.path.basename(img_path) + file_name = file_name1.split('.')[0] + print(file_name1) + delete_img_name = ['000000374551.jpg', '000000003661.jpg', + '000000309391.jpg', '000000070254.jpg'] + if file_name1 in delete_img_name: + continue + + bbox, labels = do_infer_image(stream_manager_api, img_path) + + res_buff = [] + res_buff.append(bbox) + labels = np.reshape(labels, [100, 1]) + res_buff.append(labels) + res_tensor = np.concatenate(res_buff, axis=1) + current_img_size = img_size_dict[file_name] + print("[TEST]---------------------------concat{} imgsize{}".format( + len(res_tensor), current_img_size)) + predbox = coco_postprocess( + res_tensor, current_img_size, args.net_input_width, args.net_input_height) + + if args.ifShowDetObj == True: + imgCur = cv2.imread(img_path) + + det_results_str = '' + for idx, class_ind in enumerate(predbox[:, 5]): + if float(predbox[idx][4]) < float(args.prob_thres): + continue + # skip negative class index + if class_ind < 0 or class_ind > 80: + continue + + class_name = CLASSES[int(class_ind)] + det_results_str += "{} {} {} {} {} {}\n".format(class_name, str(predbox[idx][4]), predbox[idx][0], + predbox[idx][1], predbox[idx][2], predbox[idx][3]) + if args.ifShowDetObj == True: + imgCur = cv2.rectangle(imgCur, (int(predbox[idx][0]), int(predbox[idx][1])), + (int(predbox[idx][2]), int(predbox[idx][3])), (0, 255, 0), 1) + imgCur = cv2.putText(imgCur, class_name+'|'+str(predbox[idx][4]), + (int(predbox[idx][0]), int(predbox[idx][1])), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1) + # Image, text content, coordinates, font, size, color and font thickness. + + if args.ifShowDetObj == True: + print(os.path.join(show_results_path, file_name + '.jpg')) + cv2.imwrite(os.path.join(show_results_path, file_name + + '.jpg'), imgCur, [int(cv2.IMWRITE_JPEG_QUALITY), 70]) + + det_results_file = os.path.join(det_results_path, file_name + ".txt") + with open(det_results_file, "w") as detf: + detf.write(det_results_str) + print(det_results_str) + i = i+1 + print(i) + + stream_manager_api.DestroyAllStreams() + + +if __name__ == "__main__": + args = parse_arg() + main(args) diff --git a/PyTorch/contrib/cv/detection/FCOS/infer/util/coco_eval.py b/PyTorch/contrib/cv/detection/FCOS/infer/util/coco_eval.py index 9ffdd575d3a923036698837ada5260ad1bcde18e..d5376996c9d9349c5ee0bec7334d5379e812aaaf 100644 --- a/PyTorch/contrib/cv/detection/FCOS/infer/util/coco_eval.py +++ b/PyTorch/contrib/cv/detection/FCOS/infer/util/coco_eval.py @@ -1,96 +1,96 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License.import argparse - -import numpy as np -import argparse -from pycocotools.coco import COCO -from pycocotools.cocoeval import COCOeval - -CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', - 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', - 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', - 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', - 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', - 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', - 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', - 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', - 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', - 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', - 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', - 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] - -def coco_evaluation(annotation_json, result_json): - cocoGt = COCO(annotation_json) - cocoDt = cocoGt.loadRes(result_json) - iou_thrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True) - iou_type = 'bbox' - - cocoEval = COCOeval(cocoGt, cocoDt, iou_type) - cocoEval.params.catIds = cocoGt.getCatIds(catNms=CLASSES) - cocoEval.params.imgIds = cocoGt.getImgIds() - delete_id=[3661,70254,309391,374551,190007] - for did in delete_id: - cocoEval.params.imgIds.remove(did) - - cocoEval.params.maxDets = [100, 300, 1000] # proposal number for evaluating recalls/mAPs. - cocoEval.params.iouThrs = iou_thrs - - cocoEval.evaluate() - cocoEval.accumulate() - cocoEval.summarize() - - # mapping of cocoEval.stats - coco_metric_names = { - 'mAP': 0, - 'mAP_50': 1, - 'mAP_75': 2, - 'mAP_s': 3, - 'mAP_m': 4, - 'mAP_l': 5, - 'AR@100': 6, - 'AR@300': 7, - 'AR@1000': 8, - 'AR_s@1000': 9, - 'AR_m@1000': 10, - 'AR_l@1000': 11 - } - - metric_items = ['mAP', 'mAP_50', 'mAP_75', 'mAP_s', 'mAP_m', 'mAP_l'] - eval_results = {} - - for metric_item in metric_items: - key = f'bbox_{metric_item}' - val = float( - f'{cocoEval.stats[coco_metric_names[metric_item]]:.3f}' - ) - eval_results[key] = val - ap = cocoEval.stats[:6] - eval_results['bbox_mAP_copypaste'] = ( - f'{ap[0]:.3f} {ap[1]:.3f} {ap[2]:.3f} {ap[3]:.3f} ' - f'{ap[4]:.3f} {ap[5]:.3f}') - - return eval_results - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--ground_truth", default="../data/input/COCO2017/annotations/instances_val2017.json") - parser.add_argument("--detection_result", default="coco_detection_result.json") - args = parser.parse_args() - result = coco_evaluation(args.ground_truth, args.detection_result) - print(result) - with open('./coco_detection_result.txt', 'w') as f: - for key, value in result.items(): +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.import argparse + +import numpy as np +import argparse +from pycocotools.coco import COCO +from pycocotools.cocoeval import COCOeval + +CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', + 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', + 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', + 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', + 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', + 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', + 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', + 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', + 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', + 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', + 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', + 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] + +def coco_evaluation(annotation_json, result_json): + cocoGt = COCO(annotation_json) + cocoDt = cocoGt.loadRes(result_json) + iou_thrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True) + iou_type = 'bbox' + + cocoEval = COCOeval(cocoGt, cocoDt, iou_type) + cocoEval.params.catIds = cocoGt.getCatIds(catNms=CLASSES) + cocoEval.params.imgIds = cocoGt.getImgIds() + delete_id=[3661,70254,309391,374551,190007] + for did in delete_id: + cocoEval.params.imgIds.remove(did) + + cocoEval.params.maxDets = [100, 300, 1000] # proposal number for evaluating recalls/mAPs. + cocoEval.params.iouThrs = iou_thrs + + cocoEval.evaluate() + cocoEval.accumulate() + cocoEval.summarize() + + # mapping of cocoEval.stats + coco_metric_names = { + 'mAP': 0, + 'mAP_50': 1, + 'mAP_75': 2, + 'mAP_s': 3, + 'mAP_m': 4, + 'mAP_l': 5, + 'AR@100': 6, + 'AR@300': 7, + 'AR@1000': 8, + 'AR_s@1000': 9, + 'AR_m@1000': 10, + 'AR_l@1000': 11 + } + + metric_items = ['mAP', 'mAP_50', 'mAP_75', 'mAP_s', 'mAP_m', 'mAP_l'] + eval_results = {} + + for metric_item in metric_items: + key = f'bbox_{metric_item}' + val = float( + f'{cocoEval.stats[coco_metric_names[metric_item]]:.3f}' + ) + eval_results[key] = val + ap = cocoEval.stats[:6] + eval_results['bbox_mAP_copypaste'] = ( + f'{ap[0]:.3f} {ap[1]:.3f} {ap[2]:.3f} {ap[3]:.3f} ' + f'{ap[4]:.3f} {ap[5]:.3f}') + + return eval_results + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--ground_truth", default="../data/input/COCO2017/annotations/instances_val2017.json") + parser.add_argument("--detection_result", default="coco_detection_result.json") + args = parser.parse_args() + result = coco_evaluation(args.ground_truth, args.detection_result) + print(result) + with open('./coco_detection_result.txt', 'w') as f: + for key, value in result.items(): f.write(key + ': ' + str(value) + '\n') \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/FCOS/infer/util/txt_to_json.py b/PyTorch/contrib/cv/detection/FCOS/infer/util/txt_to_json.py index 9895c2156520ca6361030fd98c44c524864d98b2..5044a128f5c9a61f33082b99412e8b84f960c22d 100644 --- a/PyTorch/contrib/cv/detection/FCOS/infer/util/txt_to_json.py +++ b/PyTorch/contrib/cv/detection/FCOS/infer/util/txt_to_json.py @@ -1,112 +1,112 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import glob -import os -import sys -import argparse -import mmcv - -CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', - 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', - 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', - 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', - 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', - 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', - 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', - 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', - 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', - 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', - 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', - 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] - -cat_ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, -24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, -48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, -72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90] - -''' - 0,0 ------> x (width) - | - | (Left,Top) - | *_________ - | | | - | | - y |_________| - (height) * - (Right,Bottom) -''' - -def file_lines_to_list(path): - # open txt file lines to a list - with open(path) as f: - content = f.readlines() - # remove whitespace characters like `\n` at the end of each line - content = [x.strip() for x in content] - return content - - -def error(msg): - print(msg) - sys.exit(0) - - -def get_predict_list(file_path, gt_classes): - dr_files_list = glob.glob(file_path + '/*.txt') - dr_files_list.sort() - - bounding_boxes = [] - for txt_file in dr_files_list: - file_id = txt_file.split(".txt", 1)[0] - file_id = os.path.basename(os.path.normpath(file_id)) - lines = file_lines_to_list(txt_file) - for line in lines: - try: - sl = line.split() - if len(sl) > 6: - class_name = sl[0] + ' ' + sl[1] - scores, left, top, right, bottom = sl[2:] - else: - class_name, scores, left, top, right, bottom = sl - if float(scores) < 0.05: - continue - except ValueError: - error_msg = "Error: File " + txt_file + " wrong format.\n" - error_msg += " Expected: \n" - error_msg += " Received: " + line - error(error_msg) - - left = float(left) - right = float(right) - top = float(top) - bottom = float(bottom) - bbox = [left, top, right-left, bottom-top] - bounding_boxes.append({"image_id": int(file_id), "bbox": bbox, - "score": float(scores), "category_id": cat_ids[CLASSES.index(class_name)]}) - - return bounding_boxes - - - -if __name__ == '__main__': - parser = argparse.ArgumentParser('mAp calculate') - parser.add_argument('--npu_txt_path', default="../sdk/data/infer_result/", - help='the path of the predict result') - parser.add_argument("--json_output_file", default="coco_detection_result") - args = parser.parse_args() - - res_bbox = get_predict_list(args.npu_txt_path, CLASSES) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import glob +import os +import sys +import argparse +import mmcv + +CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', + 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', + 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', + 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', + 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', + 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', + 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', + 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', + 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', + 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', + 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', + 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] + +cat_ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, +24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, +48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, +72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90] + +''' + 0,0 ------> x (width) + | + | (Left,Top) + | *_________ + | | | + | | + y |_________| + (height) * + (Right,Bottom) +''' + +def file_lines_to_list(path): + # open txt file lines to a list + with open(path) as f: + content = f.readlines() + # remove whitespace characters like `\n` at the end of each line + content = [x.strip() for x in content] + return content + + +def error(msg): + print(msg) + sys.exit(0) + + +def get_predict_list(file_path, gt_classes): + dr_files_list = glob.glob(file_path + '/*.txt') + dr_files_list.sort() + + bounding_boxes = [] + for txt_file in dr_files_list: + file_id = txt_file.split(".txt", 1)[0] + file_id = os.path.basename(os.path.normpath(file_id)) + lines = file_lines_to_list(txt_file) + for line in lines: + try: + sl = line.split() + if len(sl) > 6: + class_name = sl[0] + ' ' + sl[1] + scores, left, top, right, bottom = sl[2:] + else: + class_name, scores, left, top, right, bottom = sl + if float(scores) < 0.05: + continue + except ValueError: + error_msg = "Error: File " + txt_file + " wrong format.\n" + error_msg += " Expected: \n" + error_msg += " Received: " + line + error(error_msg) + + left = float(left) + right = float(right) + top = float(top) + bottom = float(bottom) + bbox = [left, top, right-left, bottom-top] + bounding_boxes.append({"image_id": int(file_id), "bbox": bbox, + "score": float(scores), "category_id": cat_ids[CLASSES.index(class_name)]}) + + return bounding_boxes + + + +if __name__ == '__main__': + parser = argparse.ArgumentParser('mAp calculate') + parser.add_argument('--npu_txt_path', default="../sdk/data/infer_result/", + help='the path of the predict result') + parser.add_argument("--json_output_file", default="coco_detection_result") + args = parser.parse_args() + + res_bbox = get_predict_list(args.npu_txt_path, CLASSES) mmcv.dump(res_bbox, args.json_output_file + '.json') \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/FCOS/mmcv_need/base_runner.py b/PyTorch/contrib/cv/detection/FCOS/mmcv_need/base_runner.py index 02c2d21c80a781114d195d3a51ded7b2c956456a..e7027b1a3797420cad21a0076268e07c55839a38 100644 --- a/PyTorch/contrib/cv/detection/FCOS/mmcv_need/base_runner.py +++ b/PyTorch/contrib/cv/detection/FCOS/mmcv_need/base_runner.py @@ -1,474 +1,474 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import logging -import os.path as osp -import warnings -from abc import ABCMeta, abstractmethod - -import torch -from torch.optim import Optimizer - -import mmcv -from ..parallel import is_module_wrapper -from .checkpoint import load_checkpoint -from .dist_utils import get_dist_info -from .hooks import HOOKS, Hook, IterTimerHook -from .log_buffer import LogBuffer -from .priority import get_priority -from .utils import get_time_str - - -class BaseRunner(metaclass=ABCMeta): - """The base class of Runner, a training helper for PyTorch. - - All subclasses should implement the following APIs: - - - ``run()`` - - ``train()`` - - ``val()`` - - ``save_checkpoint()`` - - Args: - model (:obj:`torch.nn.Module`): The model to be run. - batch_processor (callable): A callable method that process a data - batch. The interface of this method should be - `batch_processor(model, data, train_mode) -> dict` - optimizer (dict or :obj:`torch.optim.Optimizer`): It can be either an - optimizer (in most cases) or a dict of optimizers (in models that - requires more than one optimizer, e.g., GAN). - work_dir (str, optional): The working directory to save checkpoints - and logs. Defaults to None. - logger (:obj:`logging.Logger`): Logger used during training. - Defaults to None. (The default value is just for backward - compatibility) - meta (dict | None): A dict records some import information such as - environment info and seed, which will be logged in logger hook. - Defaults to None. - max_epochs (int, optional): Total training epochs. - max_iters (int, optional): Total training iterations. - """ - - def __init__(self, - model, - batch_processor=None, - optimizer=None, - work_dir=None, - logger=None, - meta=None, - max_iters=None, - max_epochs=None, - samples_per_gpu=2, # added by jyl - num_of_gpus=8): # added by jyl - if batch_processor is not None: - if not callable(batch_processor): - raise TypeError('batch_processor must be callable, ' - f'but got {type(batch_processor)}') - warnings.warn('batch_processor is deprecated, please implement ' - 'train_step() and val_step() in the model instead.') - # raise an error is `batch_processor` is not None and - # `model.train_step()` exists. - if is_module_wrapper(model): - _model = model.module - else: - _model = model - if hasattr(_model, 'train_step') or hasattr(_model, 'val_step'): - raise RuntimeError( - 'batch_processor and model.train_step()/model.val_step() ' - 'cannot be both available.') - else: - assert hasattr(model, 'train_step') - - # check the type of `optimizer` - if isinstance(optimizer, dict): - for name, optim in optimizer.items(): - if not isinstance(optim, Optimizer): - raise TypeError( - f'optimizer must be a dict of torch.optim.Optimizers, ' - f'but optimizer["{name}"] is a {type(optim)}') - elif not isinstance(optimizer, Optimizer) and optimizer is not None: - raise TypeError( - f'optimizer must be a torch.optim.Optimizer object ' - f'or dict or None, but got {type(optimizer)}') - - # check the type of `logger` - if not isinstance(logger, logging.Logger): - raise TypeError(f'logger must be a logging.Logger object, ' - f'but got {type(logger)}') - - # check the type of `meta` - if meta is not None and not isinstance(meta, dict): - raise TypeError( - f'meta must be a dict or None, but got {type(meta)}') - - self.model = model - self.batch_processor = batch_processor - self.optimizer = optimizer - self.logger = logger - self.meta = meta - self.samples_per_gpu = samples_per_gpu # added by jyl - self.num_of_gpus = num_of_gpus # added by jyl - - # create work_dir - if mmcv.is_str(work_dir): - self.work_dir = osp.abspath(work_dir) - mmcv.mkdir_or_exist(self.work_dir) - elif work_dir is None: - self.work_dir = None - else: - raise TypeError('"work_dir" must be a str or None') - - # get model name from the model class - if hasattr(self.model, 'module'): - self._model_name = self.model.module.__class__.__name__ - else: - self._model_name = self.model.__class__.__name__ - - self._rank, self._world_size = get_dist_info() - self.timestamp = get_time_str() - self.mode = None - self._hooks = [] - self._epoch = 0 - self._iter = 0 - self._inner_iter = 0 - - if max_epochs is not None and max_iters is not None: - raise ValueError( - 'Only one of `max_epochs` or `max_iters` can be set.') - - self._max_epochs = max_epochs - self._max_iters = max_iters - # TODO: Redesign LogBuffer, it is not flexible and elegant enough - self.log_buffer = LogBuffer() - - self.iter_timer_hook = IterTimerHook() # added by jyl - - @property - def model_name(self): - """str: Name of the model, usually the module class name.""" - return self._model_name - - @property - def rank(self): - """int: Rank of current process. (distributed training)""" - return self._rank - - @property - def world_size(self): - """int: Number of processes participating in the job. - (distributed training)""" - return self._world_size - - @property - def hooks(self): - """list[:obj:`Hook`]: A list of registered hooks.""" - return self._hooks - - @property - def epoch(self): - """int: Current epoch.""" - return self._epoch - - @property - def iter(self): - """int: Current iteration.""" - return self._iter - - @property - def inner_iter(self): - """int: Iteration in an epoch.""" - return self._inner_iter - - @property - def max_epochs(self): - """int: Maximum training epochs.""" - return self._max_epochs - - @property - def max_iters(self): - """int: Maximum training iterations.""" - return self._max_iters - - @abstractmethod - def train(self): - pass - - @abstractmethod - def val(self): - pass - - @abstractmethod - def run(self, data_loaders, workflow, **kwargs): - pass - - @abstractmethod - def save_checkpoint(self, - out_dir, - filename_tmpl, - save_optimizer=True, - meta=None, - create_symlink=True): - pass - - def current_lr(self): - """Get current learning rates. - - Returns: - list[float] | dict[str, list[float]]: Current learning rates of all - param groups. If the runner has a dict of optimizers, this - method will return a dict. - """ - if isinstance(self.optimizer, torch.optim.Optimizer): - lr = [group['lr'] for group in self.optimizer.param_groups] - elif isinstance(self.optimizer, dict): - lr = dict() - for name, optim in self.optimizer.items(): - lr[name] = [group['lr'] for group in optim.param_groups] - else: - raise RuntimeError( - 'lr is not applicable because optimizer does not exist.') - return lr - - def current_momentum(self): - """Get current momentums. - - Returns: - list[float] | dict[str, list[float]]: Current momentums of all - param groups. If the runner has a dict of optimizers, this - method will return a dict. - """ - - def _get_momentum(optimizer): - momentums = [] - for group in optimizer.param_groups: - if 'momentum' in group.keys(): - momentums.append(group['momentum']) - elif 'betas' in group.keys(): - momentums.append(group['betas'][0]) - else: - momentums.append(0) - return momentums - - if self.optimizer is None: - raise RuntimeError( - 'momentum is not applicable because optimizer does not exist.') - elif isinstance(self.optimizer, torch.optim.Optimizer): - momentums = _get_momentum(self.optimizer) - elif isinstance(self.optimizer, dict): - momentums = dict() - for name, optim in self.optimizer.items(): - momentums[name] = _get_momentum(optim) - return momentums - - def register_hook(self, hook, priority='NORMAL'): - """Register a hook into the hook list. - - The hook will be inserted into a priority queue, with the specified - priority (See :class:`Priority` for details of priorities). - For hooks with the same priority, they will be triggered in the same - order as they are registered. - - Args: - hook (:obj:`Hook`): The hook to be registered. - priority (int or str or :obj:`Priority`): Hook priority. - Lower value means higher priority. - """ - assert isinstance(hook, Hook) - if hasattr(hook, 'priority'): - raise ValueError('"priority" is a reserved attribute for hooks') - priority = get_priority(priority) - hook.priority = priority - # insert the hook to a sorted list - inserted = False - for i in range(len(self._hooks) - 1, -1, -1): - if priority >= self._hooks[i].priority: - self._hooks.insert(i + 1, hook) - inserted = True - break - if not inserted: - self._hooks.insert(0, hook) - - def register_hook_from_cfg(self, hook_cfg): - """Register a hook from its cfg. - - Args: - hook_cfg (dict): Hook config. It should have at least keys 'type' - and 'priority' indicating its type and priority. - - Notes: - The specific hook class to register should not use 'type' and - 'priority' arguments during initialization. - """ - hook_cfg = hook_cfg.copy() - priority = hook_cfg.pop('priority', 'NORMAL') - hook = mmcv.build_from_cfg(hook_cfg, HOOKS) - self.register_hook(hook, priority=priority) - - def call_hook(self, fn_name): - """Call all hooks. - - Args: - fn_name (str): The function name in each hook to be called, such as - "before_train_epoch". - """ - for hook in self._hooks: - getattr(hook, fn_name)(self) - - def load_checkpoint(self, filename, map_location='cpu', strict=False): - self.logger.info('load checkpoint from %s', filename) - return load_checkpoint(self.model, filename, map_location, strict, - self.logger) - - def resume(self, - checkpoint, - resume_optimizer=True, - map_location='default'): - if map_location == 'default': - if torch.cuda.is_available(): - device_id = torch.cuda.current_device() - checkpoint = self.load_checkpoint( - checkpoint, - map_location=lambda storage, loc: storage.cuda(device_id)) - else: - checkpoint = self.load_checkpoint(checkpoint) - else: - checkpoint = self.load_checkpoint( - checkpoint, map_location=map_location) - - self._epoch = checkpoint['meta']['epoch'] - self._iter = checkpoint['meta']['iter'] - if 'optimizer' in checkpoint and resume_optimizer: - if isinstance(self.optimizer, Optimizer): - self.optimizer.load_state_dict(checkpoint['optimizer']) - elif isinstance(self.optimizer, dict): - for k in self.optimizer.keys(): - self.optimizer[k].load_state_dict( - checkpoint['optimizer'][k]) - else: - raise TypeError( - 'Optimizer should be dict or torch.optim.Optimizer ' - f'but got {type(self.optimizer)}') - - self.logger.info('resumed epoch %d, iter %d', self.epoch, self.iter) - - def register_lr_hook(self, lr_config): - if isinstance(lr_config, dict): - assert 'policy' in lr_config - policy_type = lr_config.pop('policy') - # If the type of policy is all in lower case, e.g., 'cyclic', - # then its first letter will be capitalized, e.g., to be 'Cyclic'. - # This is for the convenient usage of Lr updater. - # Since this is not applicable for ` - # CosineAnnealingLrUpdater`, - # the string will not be changed if it contains capital letters. - if policy_type == policy_type.lower(): - policy_type = policy_type.title() - hook_type = policy_type + 'LrUpdaterHook' - lr_config['type'] = hook_type - hook = mmcv.build_from_cfg(lr_config, HOOKS) - else: - hook = lr_config - self.register_hook(hook) - - def register_momentum_hook(self, momentum_config): - if momentum_config is None: - return - if isinstance(momentum_config, dict): - assert 'policy' in momentum_config - policy_type = momentum_config.pop('policy') - # If the type of policy is all in lower case, e.g., 'cyclic', - # then its first letter will be capitalized, e.g., to be 'Cyclic'. - # This is for the convenient usage of momentum updater. - # Since this is not applicable for - # `CosineAnnealingMomentumUpdater`, - # the string will not be changed if it contains capital letters. - if policy_type == policy_type.lower(): - policy_type = policy_type.title() - hook_type = policy_type + 'MomentumUpdaterHook' - momentum_config['type'] = hook_type - hook = mmcv.build_from_cfg(momentum_config, HOOKS) - else: - hook = momentum_config - self.register_hook(hook) - - def register_optimizer_hook(self, optimizer_config): - if optimizer_config is None: - return - if isinstance(optimizer_config, dict): - optimizer_config.setdefault('type', 'OptimizerHook') - hook = mmcv.build_from_cfg(optimizer_config, HOOKS) - else: - hook = optimizer_config - self.register_hook(hook) - - def register_checkpoint_hook(self, checkpoint_config): - if checkpoint_config is None: - return - if isinstance(checkpoint_config, dict): - checkpoint_config.setdefault('type', 'CheckpointHook') - hook = mmcv.build_from_cfg(checkpoint_config, HOOKS) - else: - hook = checkpoint_config - self.register_hook(hook) - - def register_logger_hooks(self, log_config): - if log_config is None: - return - log_interval = log_config['interval'] - for info in log_config['hooks']: - logger_hook = mmcv.build_from_cfg( - info, HOOKS, default_args=dict(interval=log_interval)) - self.register_hook(logger_hook, priority='VERY_LOW') - - def register_training_hooks(self, - lr_config, - optimizer_config=None, - checkpoint_config=None, - log_config=None, - momentum_config=None): - """Register default hooks for training. - - Default hooks include: - - - LrUpdaterHook - - MomentumUpdaterHook - - OptimizerStepperHook - - CheckpointSaverHook - - IterTimerHook - - LoggerHook(s) - """ - self.register_lr_hook(lr_config) - self.register_momentum_hook(momentum_config) - self.register_optimizer_hook(optimizer_config) - self.register_checkpoint_hook(checkpoint_config) - # self.register_hook(IterTimerHook()) # changed by jyl - self.register_hook(self.iter_timer_hook) - self.register_logger_hooks(log_config) +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import logging +import os.path as osp +import warnings +from abc import ABCMeta, abstractmethod + +import torch +from torch.optim import Optimizer + +import mmcv +from ..parallel import is_module_wrapper +from .checkpoint import load_checkpoint +from .dist_utils import get_dist_info +from .hooks import HOOKS, Hook, IterTimerHook +from .log_buffer import LogBuffer +from .priority import get_priority +from .utils import get_time_str + + +class BaseRunner(metaclass=ABCMeta): + """The base class of Runner, a training helper for PyTorch. + + All subclasses should implement the following APIs: + + - ``run()`` + - ``train()`` + - ``val()`` + - ``save_checkpoint()`` + + Args: + model (:obj:`torch.nn.Module`): The model to be run. + batch_processor (callable): A callable method that process a data + batch. The interface of this method should be + `batch_processor(model, data, train_mode) -> dict` + optimizer (dict or :obj:`torch.optim.Optimizer`): It can be either an + optimizer (in most cases) or a dict of optimizers (in models that + requires more than one optimizer, e.g., GAN). + work_dir (str, optional): The working directory to save checkpoints + and logs. Defaults to None. + logger (:obj:`logging.Logger`): Logger used during training. + Defaults to None. (The default value is just for backward + compatibility) + meta (dict | None): A dict records some import information such as + environment info and seed, which will be logged in logger hook. + Defaults to None. + max_epochs (int, optional): Total training epochs. + max_iters (int, optional): Total training iterations. + """ + + def __init__(self, + model, + batch_processor=None, + optimizer=None, + work_dir=None, + logger=None, + meta=None, + max_iters=None, + max_epochs=None, + samples_per_gpu=2, # added by jyl + num_of_gpus=8): # added by jyl + if batch_processor is not None: + if not callable(batch_processor): + raise TypeError('batch_processor must be callable, ' + f'but got {type(batch_processor)}') + warnings.warn('batch_processor is deprecated, please implement ' + 'train_step() and val_step() in the model instead.') + # raise an error is `batch_processor` is not None and + # `model.train_step()` exists. + if is_module_wrapper(model): + _model = model.module + else: + _model = model + if hasattr(_model, 'train_step') or hasattr(_model, 'val_step'): + raise RuntimeError( + 'batch_processor and model.train_step()/model.val_step() ' + 'cannot be both available.') + else: + assert hasattr(model, 'train_step') + + # check the type of `optimizer` + if isinstance(optimizer, dict): + for name, optim in optimizer.items(): + if not isinstance(optim, Optimizer): + raise TypeError( + f'optimizer must be a dict of torch.optim.Optimizers, ' + f'but optimizer["{name}"] is a {type(optim)}') + elif not isinstance(optimizer, Optimizer) and optimizer is not None: + raise TypeError( + f'optimizer must be a torch.optim.Optimizer object ' + f'or dict or None, but got {type(optimizer)}') + + # check the type of `logger` + if not isinstance(logger, logging.Logger): + raise TypeError(f'logger must be a logging.Logger object, ' + f'but got {type(logger)}') + + # check the type of `meta` + if meta is not None and not isinstance(meta, dict): + raise TypeError( + f'meta must be a dict or None, but got {type(meta)}') + + self.model = model + self.batch_processor = batch_processor + self.optimizer = optimizer + self.logger = logger + self.meta = meta + self.samples_per_gpu = samples_per_gpu # added by jyl + self.num_of_gpus = num_of_gpus # added by jyl + + # create work_dir + if mmcv.is_str(work_dir): + self.work_dir = osp.abspath(work_dir) + mmcv.mkdir_or_exist(self.work_dir) + elif work_dir is None: + self.work_dir = None + else: + raise TypeError('"work_dir" must be a str or None') + + # get model name from the model class + if hasattr(self.model, 'module'): + self._model_name = self.model.module.__class__.__name__ + else: + self._model_name = self.model.__class__.__name__ + + self._rank, self._world_size = get_dist_info() + self.timestamp = get_time_str() + self.mode = None + self._hooks = [] + self._epoch = 0 + self._iter = 0 + self._inner_iter = 0 + + if max_epochs is not None and max_iters is not None: + raise ValueError( + 'Only one of `max_epochs` or `max_iters` can be set.') + + self._max_epochs = max_epochs + self._max_iters = max_iters + # TODO: Redesign LogBuffer, it is not flexible and elegant enough + self.log_buffer = LogBuffer() + + self.iter_timer_hook = IterTimerHook() # added by jyl + + @property + def model_name(self): + """str: Name of the model, usually the module class name.""" + return self._model_name + + @property + def rank(self): + """int: Rank of current process. (distributed training)""" + return self._rank + + @property + def world_size(self): + """int: Number of processes participating in the job. + (distributed training)""" + return self._world_size + + @property + def hooks(self): + """list[:obj:`Hook`]: A list of registered hooks.""" + return self._hooks + + @property + def epoch(self): + """int: Current epoch.""" + return self._epoch + + @property + def iter(self): + """int: Current iteration.""" + return self._iter + + @property + def inner_iter(self): + """int: Iteration in an epoch.""" + return self._inner_iter + + @property + def max_epochs(self): + """int: Maximum training epochs.""" + return self._max_epochs + + @property + def max_iters(self): + """int: Maximum training iterations.""" + return self._max_iters + + @abstractmethod + def train(self): + pass + + @abstractmethod + def val(self): + pass + + @abstractmethod + def run(self, data_loaders, workflow, **kwargs): + pass + + @abstractmethod + def save_checkpoint(self, + out_dir, + filename_tmpl, + save_optimizer=True, + meta=None, + create_symlink=True): + pass + + def current_lr(self): + """Get current learning rates. + + Returns: + list[float] | dict[str, list[float]]: Current learning rates of all + param groups. If the runner has a dict of optimizers, this + method will return a dict. + """ + if isinstance(self.optimizer, torch.optim.Optimizer): + lr = [group['lr'] for group in self.optimizer.param_groups] + elif isinstance(self.optimizer, dict): + lr = dict() + for name, optim in self.optimizer.items(): + lr[name] = [group['lr'] for group in optim.param_groups] + else: + raise RuntimeError( + 'lr is not applicable because optimizer does not exist.') + return lr + + def current_momentum(self): + """Get current momentums. + + Returns: + list[float] | dict[str, list[float]]: Current momentums of all + param groups. If the runner has a dict of optimizers, this + method will return a dict. + """ + + def _get_momentum(optimizer): + momentums = [] + for group in optimizer.param_groups: + if 'momentum' in group.keys(): + momentums.append(group['momentum']) + elif 'betas' in group.keys(): + momentums.append(group['betas'][0]) + else: + momentums.append(0) + return momentums + + if self.optimizer is None: + raise RuntimeError( + 'momentum is not applicable because optimizer does not exist.') + elif isinstance(self.optimizer, torch.optim.Optimizer): + momentums = _get_momentum(self.optimizer) + elif isinstance(self.optimizer, dict): + momentums = dict() + for name, optim in self.optimizer.items(): + momentums[name] = _get_momentum(optim) + return momentums + + def register_hook(self, hook, priority='NORMAL'): + """Register a hook into the hook list. + + The hook will be inserted into a priority queue, with the specified + priority (See :class:`Priority` for details of priorities). + For hooks with the same priority, they will be triggered in the same + order as they are registered. + + Args: + hook (:obj:`Hook`): The hook to be registered. + priority (int or str or :obj:`Priority`): Hook priority. + Lower value means higher priority. + """ + assert isinstance(hook, Hook) + if hasattr(hook, 'priority'): + raise ValueError('"priority" is a reserved attribute for hooks') + priority = get_priority(priority) + hook.priority = priority + # insert the hook to a sorted list + inserted = False + for i in range(len(self._hooks) - 1, -1, -1): + if priority >= self._hooks[i].priority: + self._hooks.insert(i + 1, hook) + inserted = True + break + if not inserted: + self._hooks.insert(0, hook) + + def register_hook_from_cfg(self, hook_cfg): + """Register a hook from its cfg. + + Args: + hook_cfg (dict): Hook config. It should have at least keys 'type' + and 'priority' indicating its type and priority. + + Notes: + The specific hook class to register should not use 'type' and + 'priority' arguments during initialization. + """ + hook_cfg = hook_cfg.copy() + priority = hook_cfg.pop('priority', 'NORMAL') + hook = mmcv.build_from_cfg(hook_cfg, HOOKS) + self.register_hook(hook, priority=priority) + + def call_hook(self, fn_name): + """Call all hooks. + + Args: + fn_name (str): The function name in each hook to be called, such as + "before_train_epoch". + """ + for hook in self._hooks: + getattr(hook, fn_name)(self) + + def load_checkpoint(self, filename, map_location='cpu', strict=False): + self.logger.info('load checkpoint from %s', filename) + return load_checkpoint(self.model, filename, map_location, strict, + self.logger) + + def resume(self, + checkpoint, + resume_optimizer=True, + map_location='default'): + if map_location == 'default': + if torch.cuda.is_available(): + device_id = torch.cuda.current_device() + checkpoint = self.load_checkpoint( + checkpoint, + map_location=lambda storage, loc: storage.cuda(device_id)) + else: + checkpoint = self.load_checkpoint(checkpoint) + else: + checkpoint = self.load_checkpoint( + checkpoint, map_location=map_location) + + self._epoch = checkpoint['meta']['epoch'] + self._iter = checkpoint['meta']['iter'] + if 'optimizer' in checkpoint and resume_optimizer: + if isinstance(self.optimizer, Optimizer): + self.optimizer.load_state_dict(checkpoint['optimizer']) + elif isinstance(self.optimizer, dict): + for k in self.optimizer.keys(): + self.optimizer[k].load_state_dict( + checkpoint['optimizer'][k]) + else: + raise TypeError( + 'Optimizer should be dict or torch.optim.Optimizer ' + f'but got {type(self.optimizer)}') + + self.logger.info('resumed epoch %d, iter %d', self.epoch, self.iter) + + def register_lr_hook(self, lr_config): + if isinstance(lr_config, dict): + assert 'policy' in lr_config + policy_type = lr_config.pop('policy') + # If the type of policy is all in lower case, e.g., 'cyclic', + # then its first letter will be capitalized, e.g., to be 'Cyclic'. + # This is for the convenient usage of Lr updater. + # Since this is not applicable for ` + # CosineAnnealingLrUpdater`, + # the string will not be changed if it contains capital letters. + if policy_type == policy_type.lower(): + policy_type = policy_type.title() + hook_type = policy_type + 'LrUpdaterHook' + lr_config['type'] = hook_type + hook = mmcv.build_from_cfg(lr_config, HOOKS) + else: + hook = lr_config + self.register_hook(hook) + + def register_momentum_hook(self, momentum_config): + if momentum_config is None: + return + if isinstance(momentum_config, dict): + assert 'policy' in momentum_config + policy_type = momentum_config.pop('policy') + # If the type of policy is all in lower case, e.g., 'cyclic', + # then its first letter will be capitalized, e.g., to be 'Cyclic'. + # This is for the convenient usage of momentum updater. + # Since this is not applicable for + # `CosineAnnealingMomentumUpdater`, + # the string will not be changed if it contains capital letters. + if policy_type == policy_type.lower(): + policy_type = policy_type.title() + hook_type = policy_type + 'MomentumUpdaterHook' + momentum_config['type'] = hook_type + hook = mmcv.build_from_cfg(momentum_config, HOOKS) + else: + hook = momentum_config + self.register_hook(hook) + + def register_optimizer_hook(self, optimizer_config): + if optimizer_config is None: + return + if isinstance(optimizer_config, dict): + optimizer_config.setdefault('type', 'OptimizerHook') + hook = mmcv.build_from_cfg(optimizer_config, HOOKS) + else: + hook = optimizer_config + self.register_hook(hook) + + def register_checkpoint_hook(self, checkpoint_config): + if checkpoint_config is None: + return + if isinstance(checkpoint_config, dict): + checkpoint_config.setdefault('type', 'CheckpointHook') + hook = mmcv.build_from_cfg(checkpoint_config, HOOKS) + else: + hook = checkpoint_config + self.register_hook(hook) + + def register_logger_hooks(self, log_config): + if log_config is None: + return + log_interval = log_config['interval'] + for info in log_config['hooks']: + logger_hook = mmcv.build_from_cfg( + info, HOOKS, default_args=dict(interval=log_interval)) + self.register_hook(logger_hook, priority='VERY_LOW') + + def register_training_hooks(self, + lr_config, + optimizer_config=None, + checkpoint_config=None, + log_config=None, + momentum_config=None): + """Register default hooks for training. + + Default hooks include: + + - LrUpdaterHook + - MomentumUpdaterHook + - OptimizerStepperHook + - CheckpointSaverHook + - IterTimerHook + - LoggerHook(s) + """ + self.register_lr_hook(lr_config) + self.register_momentum_hook(momentum_config) + self.register_optimizer_hook(optimizer_config) + self.register_checkpoint_hook(checkpoint_config) + # self.register_hook(IterTimerHook()) # changed by jyl + self.register_hook(self.iter_timer_hook) + self.register_logger_hooks(log_config) diff --git a/PyTorch/contrib/cv/detection/FCOS/mmcv_need/epoch_based_runner.py b/PyTorch/contrib/cv/detection/FCOS/mmcv_need/epoch_based_runner.py index 33e5ab36f2c05cb21f223dc34dd81647c8062120..0700575b0f36a6a2f9527422486a0e3d629620d3 100644 --- a/PyTorch/contrib/cv/detection/FCOS/mmcv_need/epoch_based_runner.py +++ b/PyTorch/contrib/cv/detection/FCOS/mmcv_need/epoch_based_runner.py @@ -1,223 +1,223 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - -import os.path as osp -import platform -import shutil -import time -import warnings -import sys # myy add - -import torch - -import mmcv -from .base_runner import BaseRunner -from .builder import RUNNERS -from .checkpoint import save_checkpoint -from .utils import get_host_info - - -@RUNNERS.register_module() -class EpochBasedRunner(BaseRunner): - """Epoch-based Runner. - - This runner train models epoch by epoch. - """ - - def run_iter(self, data_batch, train_mode, **kwargs): - if self.batch_processor is not None: - outputs = self.batch_processor( - self.model, data_batch, train_mode=train_mode, **kwargs) - elif train_mode: - outputs = self.model.train_step(data_batch, self.optimizer, - **kwargs) - else: - outputs = self.model.val_step(data_batch, self.optimizer, **kwargs) - if not isinstance(outputs, dict): - raise TypeError('"batch_processor()" or "model.train_step()"' - 'and "model.val_step()" must return a dict') - if 'log_vars' in outputs: - self.log_buffer.update(outputs['log_vars'], outputs['num_samples']) - self.outputs = outputs - - def train(self, data_loader, **kwargs): - self.model.train() - self.mode = 'train' - self.data_loader = data_loader - self._max_iters = self._max_epochs * len(self.data_loader) - self.call_hook('before_train_epoch') - time.sleep(2) # Prevent possible deadlock during epoch transition - for i, data_batch in enumerate(self.data_loader): - self._inner_iter = i - # if i==50: - # with torch.autograd.profiler.profile(use_npu=True) as prof: - # self.call_hook('before_train_iter') - # self.run_iter(data_batch, train_mode=True) - # self.call_hook('after_train_iter') - # prof.export_chrome_trace("output.prof") - # else: - self.call_hook('before_train_iter') - self.run_iter(data_batch, train_mode=True) - self.call_hook('after_train_iter') - self._iter += 1 - # added by jyl - self.logger.info('FPS: ' + str(self.samples_per_gpu * self.num_of_gpus / self.iter_timer_hook.time_all * (len(self.data_loader) - 5))) - - self.call_hook('after_train_epoch') - self._epoch += 1 - - def val(self, data_loader, **kwargs): - self.model.eval() - self.mode = 'val' - self.data_loader = data_loader - self.call_hook('before_val_epoch') - time.sleep(2) # Prevent possible deadlock during epoch transition - for i, data_batch in enumerate(self.data_loader): - self._inner_iter = i - self.call_hook('before_val_iter') - with torch.no_grad(): - self.run_iter(data_batch, train_mode=False) - self.call_hook('after_val_iter') - - self.call_hook('after_val_epoch') - - def run(self, data_loaders, workflow, max_epochs=None, **kwargs): - """Start running. - - Args: - data_loaders (list[:obj:`DataLoader`]): Dataloaders for training - and validation. - workflow (list[tuple]): A list of (phase, epochs) to specify the - running order and epochs. E.g, [('train', 2), ('val', 1)] means - running 2 epochs for training and 1 epoch for validation, - iteratively. - """ - assert isinstance(data_loaders, list) - assert mmcv.is_list_of(workflow, tuple) - assert len(data_loaders) == len(workflow) - if max_epochs is not None: - warnings.warn( - 'setting max_epochs in run is deprecated, ' - 'please set max_epochs in runner_config', DeprecationWarning) - self._max_epochs = max_epochs - - assert self._max_epochs is not None, ( - 'max_epochs must be specified during instantiation') - - for i, flow in enumerate(workflow): - mode, epochs = flow - if mode == 'train': - self._max_iters = self._max_epochs * len(data_loaders[i]) - break - - work_dir = self.work_dir if self.work_dir is not None else 'NONE' - self.logger.info('Start running, host: %s, work_dir: %s', - get_host_info(), work_dir) - self.logger.info('workflow: %s, max: %d epochs', workflow, - self._max_epochs) - self.call_hook('before_run') - - while self.epoch < self._max_epochs: - for i, flow in enumerate(workflow): - mode, epochs = flow - if isinstance(mode, str): # self.train() - if not hasattr(self, mode): - raise ValueError( - f'runner has no method named "{mode}" to run an ' - 'epoch') - epoch_runner = getattr(self, mode) - else: - raise TypeError( - 'mode in workflow must be a str, but got {}'.format( - type(mode))) - - for _ in range(epochs): - if mode == 'train' and self.epoch >= self._max_epochs: - break - epoch_runner(data_loaders[i], **kwargs) - - time.sleep(1) # wait for some hooks like loggers to finish - self.call_hook('after_run') - - def save_checkpoint(self, - out_dir, - filename_tmpl='epoch_{}.pth', - save_optimizer=True, - meta=None, - create_symlink=True): - """Save the checkpoint. - - Args: - out_dir (str): The directory that checkpoints are saved. - filename_tmpl (str, optional): The checkpoint filename template, - which contains a placeholder for the epoch number. - Defaults to 'epoch_{}.pth'. - save_optimizer (bool, optional): Whether to save the optimizer to - the checkpoint. Defaults to True. - meta (dict, optional): The meta information to be saved in the - checkpoint. Defaults to None. - create_symlink (bool, optional): Whether to create a symlink - "latest.pth" to point to the latest checkpoint. - Defaults to True. - """ - if meta is None: - meta = dict(epoch=self.epoch + 1, iter=self.iter) - elif isinstance(meta, dict): - meta.update(epoch=self.epoch + 1, iter=self.iter) - else: - raise TypeError( - f'meta should be a dict or None, but got {type(meta)}') - if self.meta is not None: - meta.update(self.meta) - - filename = filename_tmpl.format(self.epoch + 1) - filepath = osp.join(out_dir, filename) - optimizer = self.optimizer if save_optimizer else None - save_checkpoint(self.model, filepath, optimizer=optimizer, meta=meta) - # in some environments, `os.symlink` is not supported, you may need to - # set `create_symlink` to False - if create_symlink: - dst_file = osp.join(out_dir, 'latest.pth') - if platform.system() != 'Windows': - mmcv.symlink(filename, dst_file) - else: - shutil.copy(filepath, dst_file) - - -@RUNNERS.register_module() -class Runner(EpochBasedRunner): - """Deprecated name of EpochBasedRunner.""" - - def __init__(self, *args, **kwargs): - warnings.warn( - 'Runner was deprecated, please use EpochBasedRunner instead') - super().__init__(*args, **kwargs) +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + +import os.path as osp +import platform +import shutil +import time +import warnings +import sys # myy add + +import torch + +import mmcv +from .base_runner import BaseRunner +from .builder import RUNNERS +from .checkpoint import save_checkpoint +from .utils import get_host_info + + +@RUNNERS.register_module() +class EpochBasedRunner(BaseRunner): + """Epoch-based Runner. + + This runner train models epoch by epoch. + """ + + def run_iter(self, data_batch, train_mode, **kwargs): + if self.batch_processor is not None: + outputs = self.batch_processor( + self.model, data_batch, train_mode=train_mode, **kwargs) + elif train_mode: + outputs = self.model.train_step(data_batch, self.optimizer, + **kwargs) + else: + outputs = self.model.val_step(data_batch, self.optimizer, **kwargs) + if not isinstance(outputs, dict): + raise TypeError('"batch_processor()" or "model.train_step()"' + 'and "model.val_step()" must return a dict') + if 'log_vars' in outputs: + self.log_buffer.update(outputs['log_vars'], outputs['num_samples']) + self.outputs = outputs + + def train(self, data_loader, **kwargs): + self.model.train() + self.mode = 'train' + self.data_loader = data_loader + self._max_iters = self._max_epochs * len(self.data_loader) + self.call_hook('before_train_epoch') + time.sleep(2) # Prevent possible deadlock during epoch transition + for i, data_batch in enumerate(self.data_loader): + self._inner_iter = i + # if i==50: + # with torch.autograd.profiler.profile(use_npu=True) as prof: + # self.call_hook('before_train_iter') + # self.run_iter(data_batch, train_mode=True) + # self.call_hook('after_train_iter') + # prof.export_chrome_trace("output.prof") + # else: + self.call_hook('before_train_iter') + self.run_iter(data_batch, train_mode=True) + self.call_hook('after_train_iter') + self._iter += 1 + # added by jyl + self.logger.info('FPS: ' + str(self.samples_per_gpu * self.num_of_gpus / self.iter_timer_hook.time_all * (len(self.data_loader) - 5))) + + self.call_hook('after_train_epoch') + self._epoch += 1 + + def val(self, data_loader, **kwargs): + self.model.eval() + self.mode = 'val' + self.data_loader = data_loader + self.call_hook('before_val_epoch') + time.sleep(2) # Prevent possible deadlock during epoch transition + for i, data_batch in enumerate(self.data_loader): + self._inner_iter = i + self.call_hook('before_val_iter') + with torch.no_grad(): + self.run_iter(data_batch, train_mode=False) + self.call_hook('after_val_iter') + + self.call_hook('after_val_epoch') + + def run(self, data_loaders, workflow, max_epochs=None, **kwargs): + """Start running. + + Args: + data_loaders (list[:obj:`DataLoader`]): Dataloaders for training + and validation. + workflow (list[tuple]): A list of (phase, epochs) to specify the + running order and epochs. E.g, [('train', 2), ('val', 1)] means + running 2 epochs for training and 1 epoch for validation, + iteratively. + """ + assert isinstance(data_loaders, list) + assert mmcv.is_list_of(workflow, tuple) + assert len(data_loaders) == len(workflow) + if max_epochs is not None: + warnings.warn( + 'setting max_epochs in run is deprecated, ' + 'please set max_epochs in runner_config', DeprecationWarning) + self._max_epochs = max_epochs + + assert self._max_epochs is not None, ( + 'max_epochs must be specified during instantiation') + + for i, flow in enumerate(workflow): + mode, epochs = flow + if mode == 'train': + self._max_iters = self._max_epochs * len(data_loaders[i]) + break + + work_dir = self.work_dir if self.work_dir is not None else 'NONE' + self.logger.info('Start running, host: %s, work_dir: %s', + get_host_info(), work_dir) + self.logger.info('workflow: %s, max: %d epochs', workflow, + self._max_epochs) + self.call_hook('before_run') + + while self.epoch < self._max_epochs: + for i, flow in enumerate(workflow): + mode, epochs = flow + if isinstance(mode, str): # self.train() + if not hasattr(self, mode): + raise ValueError( + f'runner has no method named "{mode}" to run an ' + 'epoch') + epoch_runner = getattr(self, mode) + else: + raise TypeError( + 'mode in workflow must be a str, but got {}'.format( + type(mode))) + + for _ in range(epochs): + if mode == 'train' and self.epoch >= self._max_epochs: + break + epoch_runner(data_loaders[i], **kwargs) + + time.sleep(1) # wait for some hooks like loggers to finish + self.call_hook('after_run') + + def save_checkpoint(self, + out_dir, + filename_tmpl='epoch_{}.pth', + save_optimizer=True, + meta=None, + create_symlink=True): + """Save the checkpoint. + + Args: + out_dir (str): The directory that checkpoints are saved. + filename_tmpl (str, optional): The checkpoint filename template, + which contains a placeholder for the epoch number. + Defaults to 'epoch_{}.pth'. + save_optimizer (bool, optional): Whether to save the optimizer to + the checkpoint. Defaults to True. + meta (dict, optional): The meta information to be saved in the + checkpoint. Defaults to None. + create_symlink (bool, optional): Whether to create a symlink + "latest.pth" to point to the latest checkpoint. + Defaults to True. + """ + if meta is None: + meta = dict(epoch=self.epoch + 1, iter=self.iter) + elif isinstance(meta, dict): + meta.update(epoch=self.epoch + 1, iter=self.iter) + else: + raise TypeError( + f'meta should be a dict or None, but got {type(meta)}') + if self.meta is not None: + meta.update(self.meta) + + filename = filename_tmpl.format(self.epoch + 1) + filepath = osp.join(out_dir, filename) + optimizer = self.optimizer if save_optimizer else None + save_checkpoint(self.model, filepath, optimizer=optimizer, meta=meta) + # in some environments, `os.symlink` is not supported, you may need to + # set `create_symlink` to False + if create_symlink: + dst_file = osp.join(out_dir, 'latest.pth') + if platform.system() != 'Windows': + mmcv.symlink(filename, dst_file) + else: + shutil.copy(filepath, dst_file) + + +@RUNNERS.register_module() +class Runner(EpochBasedRunner): + """Deprecated name of EpochBasedRunner.""" + + def __init__(self, *args, **kwargs): + warnings.warn( + 'Runner was deprecated, please use EpochBasedRunner instead') + super().__init__(*args, **kwargs) diff --git a/PyTorch/contrib/cv/detection/FCOS/mmcv_need/iter_timer.py b/PyTorch/contrib/cv/detection/FCOS/mmcv_need/iter_timer.py index 0e89820c66ad1523cb15b18344711f719e867a3e..899293cb13c8272cb496ca2cee5f5416adf985a1 100644 --- a/PyTorch/contrib/cv/detection/FCOS/mmcv_need/iter_timer.py +++ b/PyTorch/contrib/cv/detection/FCOS/mmcv_need/iter_timer.py @@ -1,56 +1,56 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - -import time - -from .hook import HOOKS, Hook - - -@HOOKS.register_module() -class IterTimerHook(Hook): - - def before_epoch(self, runner): - self.t = time.time() - self.skip_step = 0 # added by jyl - self.time_all = 0 # added by jyl - - def before_iter(self, runner): - runner.log_buffer.update({'data_time': time.time() - self.t}) - - def after_iter(self, runner): - # runner.log_buffer.update({'time': time.time() - self.t}) # annoated by jyl - cur_time = time.time() # added by jyl - runner.log_buffer.update({'time': cur_time - self.t}) # added by jyl - if self.skip_step >= 5: # added by jyl - self.time_all += cur_time - self.t # added by jyl - self.skip_step += 1 # added by jyl - self.t = time.time() +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + +import time + +from .hook import HOOKS, Hook + + +@HOOKS.register_module() +class IterTimerHook(Hook): + + def before_epoch(self, runner): + self.t = time.time() + self.skip_step = 0 # added by jyl + self.time_all = 0 # added by jyl + + def before_iter(self, runner): + runner.log_buffer.update({'data_time': time.time() - self.t}) + + def after_iter(self, runner): + # runner.log_buffer.update({'time': time.time() - self.t}) # annoated by jyl + cur_time = time.time() # added by jyl + runner.log_buffer.update({'time': cur_time - self.t}) # added by jyl + if self.skip_step >= 5: # added by jyl + self.time_all += cur_time - self.t # added by jyl + self.skip_step += 1 # added by jyl + self.t = time.time() diff --git a/PyTorch/contrib/cv/detection/FCOS/modelarts/fcos_r50_caffe_fpn_4x4_1x_coco_new.py b/PyTorch/contrib/cv/detection/FCOS/modelarts/fcos_r50_caffe_fpn_4x4_1x_coco_new.py index b1acab0f4356720c8447b225a8c4013659763f95..917c30db9139c692470688c02ee34ea24e0b22a4 100644 --- a/PyTorch/contrib/cv/detection/FCOS/modelarts/fcos_r50_caffe_fpn_4x4_1x_coco_new.py +++ b/PyTorch/contrib/cv/detection/FCOS/modelarts/fcos_r50_caffe_fpn_4x4_1x_coco_new.py @@ -1,138 +1,138 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -_base_ = [ - '../_base_/datasets/coco_detection.py', - '../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py' -] -# model settings -model = dict( - type='FCOS', - pretrained='open-mmlab://detectron/resnet50_caffe',#'open-mmlab://detectron/resnet50_caffe''torchvision://resnet50' myy change resnet50_caffe to resnet50 - backbone=dict( - type='ResNet', - depth=50, - num_stages=4, - out_indices=(0, 1, 2, 3), - frozen_stages=1, - norm_cfg=dict(type='BN', requires_grad=False), - norm_eval=True, - style='caffe'), - neck=dict( - type='FPN', - in_channels=[256, 512, 1024, 2048], - out_channels=256, - start_level=1, - add_extra_convs=True, - extra_convs_on_inputs=False, # use P5 - num_outs=5, - relu_before_extra_convs=True), - bbox_head=dict( - type='FCOSHead', - num_classes=5, #change class number - in_channels=256, - stacked_convs=4, - feat_channels=256, - strides=[8, 16, 32, 64, 128], - norm_cfg=None, - loss_cls=dict( - type='FocalLoss', - use_sigmoid=True, - gamma=2.0, - alpha=0.25, - loss_weight=1.0), - loss_bbox=dict(type='IoULoss', loss_weight=1.0), - loss_centerness=dict( - type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0))) - -classes = ('person', 'car', 'cat', 'dog', 'train') #change class name - -# training and testing settings -train_cfg = dict( - assigner=dict( - type='MaxIoUAssigner', - pos_iou_thr=0.5, - neg_iou_thr=0.4, - min_pos_iou=0, - ignore_iof_thr=-1), - allowed_border=-1, - pos_weight=-1, - debug=False) -test_cfg = dict( - nms_pre=1000, - min_bbox_size=0, - score_thr=0.05, - nms=dict(type='nms', iou_threshold=0.5), - max_per_img=100) -img_norm_cfg = dict( - mean=[102.9801, 115.9465, 122.7717], std=[1.0, 1.0, 1.0], to_rgb=False) -train_pipeline = [ - dict(type='LoadImageFromFile'), - dict(type='LoadAnnotations', with_bbox=True), - dict(type='Resize', img_scale=(1333, 800), keep_ratio=True), - dict(type='RandomFlip', flip_ratio=0.5), - dict(type='Normalize', **img_norm_cfg), - dict(type='Pad', size_divisor=1344), # change 32 to 1344 - dict(type='DefaultFormatBundle'), - dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']), -] -test_pipeline = [ - dict(type='LoadImageFromFile'), - dict( - type='MultiScaleFlipAug', - img_scale=(1333, 800), - flip=False, - transforms=[ - dict(type='Resize', keep_ratio=True), - dict(type='RandomFlip'), - dict(type='Normalize', **img_norm_cfg), - dict(type='Pad', size_divisor=1344), # change 32 toto 1344 - dict(type='ImageToTensor', keys=['img']), - dict(type='Collect', keys=['img']), - ]) -] - -data = dict( - samples_per_gpu=2, # change 4 to 2 - workers_per_gpu=4, - train=dict(pipeline=train_pipeline,classes=classes), - val=dict(pipeline=test_pipeline,classes=classes), - test=dict(pipeline=test_pipeline,classes=classes)) -# optimizer -optimizer = dict( - lr=0.01, paramwise_cfg=dict(bias_lr_mult=2., bias_decay_mult=0.)) -optimizer_config = dict( - _delete_=True, grad_clip=dict(max_norm=35, norm_type=2)) -# learning policy -lr_config = dict( - policy='step', - warmup='constant', - warmup_iters=500, - warmup_ratio=1.0 / 3, - step=[8, 11]) -total_epochs = 12 -# add for print log -log_config = dict( - interval=50, - hooks=[ - dict(type='TextLoggerHook'), - # dict(type='TensorboardLoggerHook') -]) - -amp = True # add for apex -dist_params = dict(backend='hccl') # add for npu - - - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +_base_ = [ + '../_base_/datasets/coco_detection.py', + '../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py' +] +# model settings +model = dict( + type='FCOS', + pretrained='open-mmlab://detectron/resnet50_caffe',#'open-mmlab://detectron/resnet50_caffe''torchvision://resnet50' myy change resnet50_caffe to resnet50 + backbone=dict( + type='ResNet', + depth=50, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type='BN', requires_grad=False), + norm_eval=True, + style='caffe'), + neck=dict( + type='FPN', + in_channels=[256, 512, 1024, 2048], + out_channels=256, + start_level=1, + add_extra_convs=True, + extra_convs_on_inputs=False, # use P5 + num_outs=5, + relu_before_extra_convs=True), + bbox_head=dict( + type='FCOSHead', + num_classes=5, #change class number + in_channels=256, + stacked_convs=4, + feat_channels=256, + strides=[8, 16, 32, 64, 128], + norm_cfg=None, + loss_cls=dict( + type='FocalLoss', + use_sigmoid=True, + gamma=2.0, + alpha=0.25, + loss_weight=1.0), + loss_bbox=dict(type='IoULoss', loss_weight=1.0), + loss_centerness=dict( + type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0))) + +classes = ('person', 'car', 'cat', 'dog', 'train') #change class name + +# training and testing settings +train_cfg = dict( + assigner=dict( + type='MaxIoUAssigner', + pos_iou_thr=0.5, + neg_iou_thr=0.4, + min_pos_iou=0, + ignore_iof_thr=-1), + allowed_border=-1, + pos_weight=-1, + debug=False) +test_cfg = dict( + nms_pre=1000, + min_bbox_size=0, + score_thr=0.05, + nms=dict(type='nms', iou_threshold=0.5), + max_per_img=100) +img_norm_cfg = dict( + mean=[102.9801, 115.9465, 122.7717], std=[1.0, 1.0, 1.0], to_rgb=False) +train_pipeline = [ + dict(type='LoadImageFromFile'), + dict(type='LoadAnnotations', with_bbox=True), + dict(type='Resize', img_scale=(1333, 800), keep_ratio=True), + dict(type='RandomFlip', flip_ratio=0.5), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size_divisor=1344), # change 32 to 1344 + dict(type='DefaultFormatBundle'), + dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']), +] +test_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='MultiScaleFlipAug', + img_scale=(1333, 800), + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='RandomFlip'), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size_divisor=1344), # change 32 toto 1344 + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] + +data = dict( + samples_per_gpu=2, # change 4 to 2 + workers_per_gpu=4, + train=dict(pipeline=train_pipeline,classes=classes), + val=dict(pipeline=test_pipeline,classes=classes), + test=dict(pipeline=test_pipeline,classes=classes)) +# optimizer +optimizer = dict( + lr=0.01, paramwise_cfg=dict(bias_lr_mult=2., bias_decay_mult=0.)) +optimizer_config = dict( + _delete_=True, grad_clip=dict(max_norm=35, norm_type=2)) +# learning policy +lr_config = dict( + policy='step', + warmup='constant', + warmup_iters=500, + warmup_ratio=1.0 / 3, + step=[8, 11]) +total_epochs = 12 +# add for print log +log_config = dict( + interval=50, + hooks=[ + dict(type='TextLoggerHook'), + # dict(type='TensorboardLoggerHook') +]) + +amp = True # add for apex +dist_params = dict(backend='hccl') # add for npu + + + + diff --git a/PyTorch/contrib/cv/detection/FCOS/scripts/train_1p.sh b/PyTorch/contrib/cv/detection/FCOS/scripts/train_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/FCOS/scripts/train_8p.sh b/PyTorch/contrib/cv/detection/FCOS/scripts/train_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/FCOS/tools/dist_train.sh b/PyTorch/contrib/cv/detection/FCOS/tools/dist_train.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/FOTS/LICENSE b/PyTorch/contrib/cv/detection/FOTS/LICENSE index 185404d5515c393add9ecfbdd7cd83596e8a4b26..5b4cf39445b7b24f2e5d38062c3b9cca89ad8a90 100644 --- a/PyTorch/contrib/cv/detection/FOTS/LICENSE +++ b/PyTorch/contrib/cv/detection/FOTS/LICENSE @@ -1,204 +1,204 @@ -Copyright 2018-2019 Open-MMLab. All rights reserved. -Copyright 2021 Huawei Technologies Co., Ltd - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2018-2019 Open-MMLab. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Copyright 2018-2019 Open-MMLab. All rights reserved. +Copyright 2021 Huawei Technologies Co., Ltd + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2019 Open-MMLab. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/PyTorch/contrib/cv/detection/FOTS/README.md b/PyTorch/contrib/cv/detection/FOTS/README.md index e1dd7e515c082bbb51181613c2d9a027e4e3f982..73e72d2fddf3caf9561ca0813f92791a1652aa03 100644 --- a/PyTorch/contrib/cv/detection/FOTS/README.md +++ b/PyTorch/contrib/cv/detection/FOTS/README.md @@ -1,60 +1,60 @@ -# FOTS: Fast Oriented Text Spotting with a Unified Network text detection branch reimplementation (PyTorch) -# − 参考实现: - ``` - url=https://github.com/Wovchena/text-detection-fots.pytorch - ``` - -## FOTS Detail - -A unified end-to-end trainable Fast Oriented TextSpotting (FOTS) network for simultaneous detection andrecognition, sharing computation and visual information among the two complementary tasks. - - -## Requirements - -- Install PyTorch ([pytorch.org](http://pytorch.org)) -- Install packages required -- Prepare dataset: 1. SynthText for pretrain - 2. ICDAR2015 for finetune - -## Training - -To train a model, run `train.py` with the desired model architecture -1. pretrain with SynthText for 9 epochs -2. finetune with ICDAR2015 for 583 epochs - -```bash -# training 1p pretrain accuracy -bash ./test/train_full_pretrain_1p.sh - -# training 1p finetune accuracy -bash ./test/train_full_finetune_1p.sh - -# training 1p performance -bash ./test/train_performance_1p.sh - -# training 8p pretrain accuracy -bash ./test/train_full_pretrain_8p.sh - -# training 8p finetune accuracy -bash ./test/train_full_finetune_8p.sh - -# training 8p performance -bash ./test/train_performance_8p.sh - -#test 8p accuracy -bash ./test/test_8p.sh - -#test 1p accuracy -bash ./test/test_1p.sh -``` - -Log path: - FOTS/*.log - - -## FOTS training result - -| Acc@1 | Recall | Hmean | FPS | Npu_nums | Epochs | AMP_Type | -| :------: | :------: | :------: | :------: | :------: | :------: | :------: | -| - | - | - | 16.101 | 1 | 20 | O2 | +# FOTS: Fast Oriented Text Spotting with a Unified Network text detection branch reimplementation (PyTorch) +# − 参考实现: + ``` + url=https://github.com/Wovchena/text-detection-fots.pytorch + ``` + +## FOTS Detail + +A unified end-to-end trainable Fast Oriented TextSpotting (FOTS) network for simultaneous detection andrecognition, sharing computation and visual information among the two complementary tasks. + + +## Requirements + +- Install PyTorch ([pytorch.org](http://pytorch.org)) +- Install packages required +- Prepare dataset: 1. SynthText for pretrain + 2. ICDAR2015 for finetune + +## Training + +To train a model, run `train.py` with the desired model architecture +1. pretrain with SynthText for 9 epochs +2. finetune with ICDAR2015 for 583 epochs + +```bash +# training 1p pretrain accuracy +bash ./test/train_full_pretrain_1p.sh + +# training 1p finetune accuracy +bash ./test/train_full_finetune_1p.sh + +# training 1p performance +bash ./test/train_performance_1p.sh + +# training 8p pretrain accuracy +bash ./test/train_full_pretrain_8p.sh + +# training 8p finetune accuracy +bash ./test/train_full_finetune_8p.sh + +# training 8p performance +bash ./test/train_performance_8p.sh + +#test 8p accuracy +bash ./test/test_8p.sh + +#test 1p accuracy +bash ./test/test_1p.sh +``` + +Log path: + FOTS/*.log + + +## FOTS training result + +| Acc@1 | Recall | Hmean | FPS | Npu_nums | Epochs | AMP_Type | +| :------: | :------: | :------: | :------: | :------: | :------: | :------: | +| - | - | - | 16.101 | 1 | 20 | O2 | | 85.046 | 78.864 | 81.838 | 77.614 | 8 | 583 | O2 | \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/FOTS/requirments.txt b/PyTorch/contrib/cv/detection/FOTS/requirments.txt index 1dadf1794e53f2e75a9a13d9aa3dd7fefa6f61df..b46f8737697217f54cfcd4db129722fd570427a4 100644 --- a/PyTorch/contrib/cv/detection/FOTS/requirments.txt +++ b/PyTorch/contrib/cv/detection/FOTS/requirments.txt @@ -1,5 +1,5 @@ -torch==1.5.0 -shapely==1.6.4.post2 -opencv-python==3.4.3.18 -tqdm==4.31.1 +torch==1.5.0 +shapely==1.6.4.post2 +opencv-python==3.4.3.18 +tqdm==4.31.1 Polygon3 \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/data/config/fsaf.pipeline b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/data/config/fsaf.pipeline old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/docker_start_infer.sh b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/docker_start_infer.sh index 07b61defd1489b9c21337b7d7ac6c911bf422e78..022ff222968145977df53c32a26d31fde5429d39 100644 --- a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/docker_start_infer.sh +++ b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/docker_start_infer.sh @@ -1,48 +1,48 @@ -#!/bin/bash - -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -docker_image=$1 -data_dir=$2 - -function show_help() { - echo "Usage: docker_start.sh docker_image data_dir" -} - -function param_check() { - if [ -z "${docker_image}" ]; then - echo "please input docker_image" - show_help - exit 1 - fi - - if [ -z "${data_dir}" ]; then - echo "please input data_dir" - show_help - exit 1 - fi -} - -param_check - -docker run -it \ - --device=/dev/davinci0 \ - --device=/dev/davinci_manager \ - --device=/dev/devmm_svm \ - --device=/dev/hisi_hdc \ - -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ - -v ${data_dir}:${data_dir} \ - ${docker_image} \ +#!/bin/bash + +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +docker_image=$1 +data_dir=$2 + +function show_help() { + echo "Usage: docker_start.sh docker_image data_dir" +} + +function param_check() { + if [ -z "${docker_image}" ]; then + echo "please input docker_image" + show_help + exit 1 + fi + + if [ -z "${data_dir}" ]; then + echo "please input data_dir" + show_help + exit 1 + fi +} + +param_check + +docker run -it \ + --device=/dev/davinci0 \ + --device=/dev/davinci_manager \ + --device=/dev/devmm_svm \ + --device=/dev/hisi_hdc \ + -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ + -v ${data_dir}:${data_dir} \ + ${docker_image} \ /bin/bash \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/CMakeLists.txt b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/CMakeLists.txt old mode 100755 new mode 100644 index d6916791922570cb48fd6195f749ba511cd0f1d9..f03048071a7d2e36730588b52a1c262a8ced8aca --- a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/CMakeLists.txt +++ b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/CMakeLists.txt @@ -1,57 +1,57 @@ -cmake_minimum_required(VERSION 3.14.0) - -project(fsaf) - -set(TARGET fsaf) - -SET(CMAKE_BUILD_TYPE "Debug") -SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") -SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall") - -add_definitions(-DENABLE_DVPP_INTERFACE) -add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) -add_definitions(-Dgoogle=mindxsdk_private) -add_compile_options(-std=c++11 -fPIE -fstack-protector-all -fPIC -Wall) -add_link_options(-Wl,-z,relro,-z,now,-z,noexecstack -s -pie) - -# Check environment variable -if(NOT DEFINED ENV{ASCEND_HOME}) - message(FATAL_ERROR "please define environment variable:ASCEND_HOME") -endif() -if(NOT DEFINED ENV{ASCEND_VERSION}) - message(WARNING "please define environment variable:ASCEND_VERSION") -endif() -if(NOT DEFINED ENV{ARCH_PATTERN}) - message(WARNING "please define environment variable:ARCH_PATTERN") -endif() - -set(ACL_INC_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/include) -set(ACL_LIB_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/lib64) - -set(MXBASE_ROOT_DIR $ENV{MX_SDK_HOME}) -set(MXBASE_INC ${MXBASE_ROOT_DIR}/include) -set(MXBASE_LIB_DIR ${MXBASE_ROOT_DIR}/lib) -set(MXBASE_POST_LIB_DIR ${MXBASE_ROOT_DIR}/lib/modelpostprocessors) -set(MXBASE_POST_PROCESS_DIR ${MXBASE_ROOT_DIR}/include/MxBase/postprocess/include) - - -if(DEFINED ENV{MXSDK_OPENSOURCE_DIR}) - set(OPENSOURCE_DIR $ENV{MXSDK_OPENSOURCE_DIR}) -else() - set(OPENSOURCE_DIR ${MXBASE_ROOT_DIR}/opensource) -endif() -include_directories(${ACL_INC_DIR}) -include_directories(${OPENSOURCE_DIR}/include) -include_directories(${OPENSOURCE_DIR}/include/opencv4) - -include_directories(${MXBASE_INC}) -include_directories(${MXBASE_POST_PROCESS_DIR}) -link_directories(${ACL_LIB_DIR}) -link_directories(${OPENSOURCE_DIR}/lib) -link_directories(${MXBASE_LIB_DIR}) -link_directories(${MXBASE_POST_LIB_DIR}) - -add_executable(${TARGET} ./src/main.cpp ./src/fsaf.cpp) -target_link_libraries(${TARGET} glog cpprest mxbase opencv_world stdc++fs) - -install(TARGETS ${TARGET} RUNTIME DESTINATION ${PROJECT_SOURCE_DIR}/) +cmake_minimum_required(VERSION 3.14.0) + +project(fsaf) + +set(TARGET fsaf) + +SET(CMAKE_BUILD_TYPE "Debug") +SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") +SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall") + +add_definitions(-DENABLE_DVPP_INTERFACE) +add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) +add_definitions(-Dgoogle=mindxsdk_private) +add_compile_options(-std=c++11 -fPIE -fstack-protector-all -fPIC -Wall) +add_link_options(-Wl,-z,relro,-z,now,-z,noexecstack -s -pie) + +# Check environment variable +if(NOT DEFINED ENV{ASCEND_HOME}) + message(FATAL_ERROR "please define environment variable:ASCEND_HOME") +endif() +if(NOT DEFINED ENV{ASCEND_VERSION}) + message(WARNING "please define environment variable:ASCEND_VERSION") +endif() +if(NOT DEFINED ENV{ARCH_PATTERN}) + message(WARNING "please define environment variable:ARCH_PATTERN") +endif() + +set(ACL_INC_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/include) +set(ACL_LIB_DIR $ENV{ASCEND_HOME}/$ENV{ASCEND_VERSION}/$ENV{ARCH_PATTERN}/acllib/lib64) + +set(MXBASE_ROOT_DIR $ENV{MX_SDK_HOME}) +set(MXBASE_INC ${MXBASE_ROOT_DIR}/include) +set(MXBASE_LIB_DIR ${MXBASE_ROOT_DIR}/lib) +set(MXBASE_POST_LIB_DIR ${MXBASE_ROOT_DIR}/lib/modelpostprocessors) +set(MXBASE_POST_PROCESS_DIR ${MXBASE_ROOT_DIR}/include/MxBase/postprocess/include) + + +if(DEFINED ENV{MXSDK_OPENSOURCE_DIR}) + set(OPENSOURCE_DIR $ENV{MXSDK_OPENSOURCE_DIR}) +else() + set(OPENSOURCE_DIR ${MXBASE_ROOT_DIR}/opensource) +endif() +include_directories(${ACL_INC_DIR}) +include_directories(${OPENSOURCE_DIR}/include) +include_directories(${OPENSOURCE_DIR}/include/opencv4) + +include_directories(${MXBASE_INC}) +include_directories(${MXBASE_POST_PROCESS_DIR}) +link_directories(${ACL_LIB_DIR}) +link_directories(${OPENSOURCE_DIR}/lib) +link_directories(${MXBASE_LIB_DIR}) +link_directories(${MXBASE_POST_LIB_DIR}) + +add_executable(${TARGET} ./src/main.cpp ./src/fsaf.cpp) +target_link_libraries(${TARGET} glog cpprest mxbase opencv_world stdc++fs) + +install(TARGETS ${TARGET} RUNTIME DESTINATION ${PROJECT_SOURCE_DIR}/) diff --git a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/build.sh b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/build.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/src/fsaf.cpp b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/src/fsaf.cpp old mode 100755 new mode 100644 index 36b7c50fb852b488d86275a4e9af48438e048082..7ad6a695100d6d2126071e6a8464c0d6913216ba --- a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/src/fsaf.cpp +++ b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/src/fsaf.cpp @@ -1,427 +1,427 @@ -/* - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "fsaf.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "MxBase/DeviceManager/DeviceManager.h" -#include "MxBase/DvppWrapper/DvppWrapper.h" -#include "MxBase/Log/Log.h" - -using namespace MxBase; - -// Complete all initialization work. When you are going to -// use FSAF class, you should invoke this method immediately. -// -// you need construct InitParam object for Init. -APP_ERROR FSAF::Init(const InitParam& initParam) { - // initialize device - APP_ERROR ret = MxBase::DeviceManager::GetInstance()->InitDevices(); - if (ret != APP_ERR_OK) { - LogError << "Init devices failed, ret=" << ret << "."; - return ret; - } - // initialize context - ret = MxBase::TensorContext::GetInstance()->SetContext(initParam.deviceId); - if (ret != APP_ERR_OK) { - LogError << "Set context failed, ret=" << ret << "."; - return ret; - } - - // load model - model_ = std::make_shared(); - ret = model_->Init(initParam.modelPath, modelDesc_); - if (ret != APP_ERR_OK) { - LogError << "ModelInferenceProcessor init failed, ret=" << ret << "."; - return ret; - } - - return APP_ERR_OK; -} - -APP_ERROR FSAF::DeInit() { - model_->DeInit(); - MxBase::DeviceManager::GetInstance()->DestroyDevices(); - return APP_ERR_OK; -} - -// Get all files under a directory. -// Parameters: -// dirPath: the directory path -// Return: -// a vector of filename, including the suffix. -std::vector FSAF::GetFileList(const std::string &dirPath) { - struct dirent *ptr; - DIR *dir = opendir(dirPath.c_str()); - std::vector files; - while ((ptr = readdir(dir)) != NULL) { - if (ptr->d_name[0] == '.') { - continue; - } - files.push_back(ptr->d_name); - } - closedir(dir); - return files; -} - -// Read image from a image path. -// Parameters: -// imgPath: string of image path -// imageMat: opencv Mat object, for storging image as matrix -// height: int, storge the image height -// width: int, storge the image width -// Return: -// APP_ERROR object, if read image successfully, return APP_ERR_OK. -APP_ERROR FSAF::ReadImage(const std::string& imgPath, cv::Mat& imageMat, int& height, int& width) { - imageMat = cv::imread(imgPath, cv::IMREAD_COLOR); - - // BGR -> RGB - cv::cvtColor(imageMat, imageMat, cv::COLOR_BGR2RGB); - - width = imageMat.cols; - height = imageMat.rows; - - return APP_ERR_OK; -} - -// Resize image to fix size. -// We use RightDown padding style. -// Parameters: -// srcImageMat: source opencv Mat object, image matrix -// dstImageMat: storge destination opencv Mat object -// resizedImageInfo: contain infomation about the image, including before and after scaling -//Return: -// APP_ERROR object, if resize image successfully, return APP_ERR_OK. -APP_ERROR FSAF::ResizeImage(const cv::Mat& srcImageMat, cv::Mat& dstImageMat, - MxBase::ResizedImageInfo& resizedImageInfo) { - float resizeHeight = 800; - float resizeWidth = 1216; - float scale = std::min(resizeWidth / srcImageMat.cols, resizeHeight / srcImageMat.rows); - int new_width = srcImageMat.cols * scale; - int new_height = srcImageMat.rows * scale; - - // calculate the padding - int pad_w = resizeWidth - new_width; - int pad_h = resizeHeight - new_height; - - resizedImageInfo.heightOriginal = srcImageMat.rows; - resizedImageInfo.heightResize = resizeHeight; - resizedImageInfo.widthOriginal = srcImageMat.cols; - resizedImageInfo.widthResize = resizeWidth; - resizedImageInfo.resizeType = RESIZER_MS_KEEP_ASPECT_RATIO; - - // invoke opencv method to resize and pad - cv::resize(srcImageMat, dstImageMat, cv::Size(new_width, new_height), 0, 0, cv::INTER_CUBIC); - cv::copyMakeBorder(dstImageMat, dstImageMat, 0, pad_h, 0, pad_w, - cv::BorderTypes::BORDER_CONSTANT, cv::Scalar(0, 0, 0)); - - return APP_ERR_OK; -} - -APP_ERROR FSAF::Normalize(const cv::Mat &srcImageMat, cv::Mat &dstImageMat) -{ - constexpr size_t ALPHA_AND_BETA_SIZE = 3; - cv::Mat float32Mat; - srcImageMat.convertTo(float32Mat, CV_32FC3); - - std::vector tmp; - cv::split(float32Mat, tmp); - - const std::vector mean = {103.53, 116.28, 123.675}; - const std::vector std = {57.375, 57.120, 58.395}; - for (size_t i = 0; i < ALPHA_AND_BETA_SIZE; ++i) { - tmp[i].convertTo(tmp[i], CV_32FC3, 1 / std[i], - mean[i] / std[i]); - } - cv::merge(tmp, dstImageMat); - return APP_ERR_OK; -} - -// Convert Mat to Tensor. -// Parameters: -// imageMat: input image matrix -// tensorBase: storge image as tensor -// Return: -// APP_ERROR object, if convert image successfully, return APP_ERR_OK. -APP_ERROR FSAF::CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase) { - // calculate the data size: width * height * depth - const uint32_t dataSize = imageMat.cols * imageMat.rows * imageMat.channels(); - // allocate memory - MemoryData memoryDataDst(dataSize, MemoryData::MEMORY_DEVICE, deviceId_); - MemoryData memoryDataSrc(imageMat.data, dataSize, MemoryData::MEMORY_HOST_MALLOC); - - APP_ERROR ret = MemoryHelper::MxbsMallocAndCopy(memoryDataDst, memoryDataSrc); - if (ret != APP_ERR_OK) { - LogError << GetError(ret) << "Memory malloc failed."; - return ret; - } - // get tensor shape - // std::vector shape = {imageMat.rows * YUV444_RGB_WIDTH_NU, static_cast(imageMat.cols)}; - std::vector shape = { - static_cast(imageMat.rows), - static_cast(imageMat.cols), - static_cast(imageMat.channels())}; - - // tensorBase = TensorBase(memoryDataDst, false, shape, TENSOR_DTYPE_UINT8); - tensorBase = TensorBase(memoryDataDst, false, shape, TENSOR_DTYPE_FLOAT32); - return APP_ERR_OK; -} - -// Model inference. -// Parameters: -// inputs: input image tensor -// outputs: result tensor of inference result -// Return: -// APP_ERROR object, if convert image successfully, return APP_ERR_OK. -APP_ERROR FSAF::Inference(const std::vector& inputs, std::vector& outputs) { - auto dtypes = model_->GetOutputDataType(); - - // modelDesc_ get the output tensor size through Init() - for (size_t i = 0; i < modelDesc_.outputTensors.size(); ++i) { - std::vector shape = {}; - for (size_t j = 0; j < modelDesc_.outputTensors[i].tensorDims.size(); ++j) { - shape.push_back((uint32_t)modelDesc_.outputTensors[i].tensorDims[j]); - } - TensorBase tensor(shape, dtypes[i], MemoryData::MemoryType::MEMORY_DEVICE, deviceId_); - APP_ERROR ret = TensorBase::TensorBaseMalloc(tensor); - if (ret != APP_ERR_OK) { - LogError << "TensorBaseMalloc failed, ret=" << ret << "."; - return ret; - } - outputs.push_back(tensor); - } - - DynamicInfo dynamicInfo = {}; - dynamicInfo.dynamicType = DynamicType::STATIC_BATCH; - - // infer the result according to the input tensor - APP_ERROR ret = model_->ModelInference(inputs, outputs, dynamicInfo); - if (ret != APP_ERR_OK) { - LogError << "ModelInference failed, ret=" << ret << "."; - return ret; - } - - return APP_ERR_OK; -} - -// Post process for inference result. -// Scale the bbox to the origin image size. -// Parameters: -// imgPath: input image path -// inputs: tensor of image after inference -// resultPath: the path of storaging infer_result -// height, width: image's height and width -// name: image name, not including suffix -// showPath: the path of storaging visualizition result -// Return: -// APP_ERROR object, if post process image successfully, return APP_ERR_OK. -APP_ERROR FSAF::PostProcess(const std::string& imgPath, std::vector& inputs, - const std::string &resultPath, int& height, int& width, const std::string& name, std::string &showPath) { - // object num - int tensor_size = 100; - - MxBase::TensorBase& tensor = inputs[1]; // 1*100 - - int ret = tensor.ToHost(); - if (ret != APP_ERR_OK) { - LogError << GetError(ret) << "Tensor_1 deploy to host failed."; - return ret; - } - std::vector shape = tensor.GetShape(); - - auto labels = reinterpret_cast(tensor.GetBuffer()); // 1*100 - - std::cout << "---------------------------labels---------------------------" << std::endl; - int label[tensor_size] = {0}; - for(int i = 0; i < tensor_size; i++){ - std::cout << labels[i] << " "; - label[i] = labels[i]; - } - - tensor = inputs[0]; // 1*100*5 - ret = tensor.ToHost(); - if (ret != APP_ERR_OK) { - LogError << GetError(ret) << "Tensor_0 deploy to host failed."; - return ret; - } - - auto bbox = reinterpret_cast(tensor.GetBuffer()); - std::cout << "\n---------------------------bboxes--------------------------" << std::endl; - for(int i = 0; i < tensor_size; i++){ - std::cout << bbox[i][0] << ", " << bbox[i][1] << ", " << bbox[i][2] << ", " - << bbox[i][3] << ", " << bbox[i][4] << std::endl; - } - - // get infer coordinates - float image_size_w = width; - float image_size_h = height; - float net_input_width = 1216; - float net_input_height = 800; - float scale = std::min(net_input_width / (float)width, net_input_height / (float)height); - - int new_width = image_size_w * scale; - - float n_scale = (float)new_width / image_size_w; - - // probability threshold and all classes for label - float prob_thres = 0.05; - std::vector classes = {"person", "bicycle", "car", "motorcycle", "airplane", "bus", - "train", "truck", "boat", "traffic light", "fire hydrant", - "stop sign", "parking meter", "bench", "bird", "cat", "dog", - "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", - "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", - "skis", "snowboard", "sports ball", "kite", "baseball bat", - "baseball glove", "skateboard", "surfboard", "tennis racket", - "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", - "banana", "apple", "sandwich", "orange", "broccoli", "carrot", - "hot dog", "pizza", "donut", "cake", "chair", "couch", - "potted plant", "bed", "dining table", "toilet", "tv", "laptop", - "mouse", "remote", "keyboard", "cell phone", "microwave", - "oven", "toaster", "sink", "refrigerator", "book", "clock", - "vase", "scissors", "teddy bear", "hair drier", "toothbrush"}; - - // storge bbox after post processing - float ppbox[tensor_size][5] = {0}; - - for (int j = 0; j < tensor_size; ++j) { - // scale bbox - ppbox[j][0] = (bbox[j][0]) / n_scale; - ppbox[j][1] = (bbox[j][1]) / n_scale; - ppbox[j][2] = (bbox[j][2]) / n_scale; - ppbox[j][3] = (bbox[j][3]) / n_scale; - ppbox[j][4] = bbox[j][4]; - // limit bbox in a valid range - ppbox[j][0] = std::max((float)0, ppbox[j][0]); - ppbox[j][1] = std::max((float)0, ppbox[j][1]); - ppbox[j][2] = std::min(image_size_w, ppbox[j][2]); - ppbox[j][3] = std::min(image_size_h, ppbox[j][3]); - } - - std::ofstream out(resultPath); - cv::Mat imgCur = cv::imread(imgPath); - - for (int j = 0; j < tensor_size; ++j) { - if(float(ppbox[j][4]) < float(prob_thres)) { - continue; - } - if(label[j] < 0 || label[j] > 80) { - continue; - } - - // standard the output result - std::string class_name = classes[int(label[j])]; - std::string det_results_str = ""; - std::ostringstream oss; - oss << ppbox[j][4]; - std::string confidence(oss.str()); - char strff1[21], strff2[21], strff3[21], strff4[21], strff0[21]; - memset(strff1, 0, sizeof(strff1)); - memset(strff2, 0, sizeof(strff2)); - memset(strff3, 0, sizeof(strff3)); - memset(strff4, 0, sizeof(strff4)); - memset(strff0, 0, sizeof(strff0)); - // print ppbox to char* - sprintf(strff0, "%.8f", ppbox[j][0]); - sprintf(strff1, "%.8f", ppbox[j][1]); - sprintf(strff2, "%.8f", ppbox[j][2]); - sprintf(strff3, "%.8f", ppbox[j][3]); - sprintf(strff4, "%.8f", ppbox[j][4]); - det_results_str = det_results_str + class_name + " " + strff4 + " " + strff0 + " " + strff1 + " " - + strff2 + " " + strff3 + "\n"; - - out << det_results_str; - std::cout << det_results_str; - // visualization on the origin image - cv::Point p3((ppbox[j][0]), (ppbox[j][1])); - cv::Point p4((ppbox[j][2]), (ppbox[j][3])); - cv::Scalar colorRectangle1(0, 255, 1); - int thicknessRectangle1 = 1; - cv::rectangle(imgCur, p3, p4, colorRectangle1, thicknessRectangle1); - cv::putText(imgCur, class_name + "|" + confidence, p3, cv::FONT_HERSHEY_SIMPLEX, - 0.5, colorRectangle1, 1, 1, false); - } - out.close(); - cv::imwrite(showPath + "/" + name + ".jpg", imgCur); - - return APP_ERR_OK; -} - -// Primary method for process all images. -APP_ERROR FSAF::Process(const std::string &dirPath, std::string &resultPath, std::string &showPath) { - std::vector dirFileList = GetFileList(dirPath); - std::vector names, paths; - // for debug counting - int i = 0; - // process every image - for(auto imgFile : dirFileList) { - std::string imgPath = dirPath + "/" + imgFile; - std::string name = imgFile.substr(0, imgFile.find(".")); - std::string subresultPath = resultPath + "/" + name + ".txt"; - - cv::Mat imageMat; - int height = 0; - int width = 0; - // get image infomation - APP_ERROR ret = ReadImage(imgPath, imageMat, height, width); - if (ret != APP_ERR_OK) { - LogError << "ReadImage failed, ret=" << ret << "."; - return ret; - } - // resize image and pad it - ResizedImageInfo resizedImageInfo; - ResizeImage(imageMat, imageMat, resizedImageInfo); - - // convert image matrix to tensor - TensorBase tensorBase; - ret = CVMatToTensorBase(imageMat, tensorBase); - if (ret != APP_ERR_OK) { - LogError << "CVMatToTensorBase failed, ret=" << ret << "."; - return ret; - } - - std::vector inputs = {}; - std::vector outputs = {}; - inputs.push_back(tensorBase); - // infer and get output tensor - ret = Inference(inputs, outputs); - if (ret != APP_ERR_OK) { - LogError << "Inference failed, ret=" << ret << "."; - return ret; - } - // post process the bbox to the origin image, - // and implement visualizition. - ret = PostProcess(imgPath, outputs, subresultPath, height, width, name, showPath); - if (ret != APP_ERR_OK) { - LogError << "PostProcess failed, ret=" << ret << "."; - return ret; - } - // add count - i++; - std::cout << i << std::endl; - } - - return APP_ERR_OK; - -} +/* + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "fsaf.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "MxBase/DeviceManager/DeviceManager.h" +#include "MxBase/DvppWrapper/DvppWrapper.h" +#include "MxBase/Log/Log.h" + +using namespace MxBase; + +// Complete all initialization work. When you are going to +// use FSAF class, you should invoke this method immediately. +// +// you need construct InitParam object for Init. +APP_ERROR FSAF::Init(const InitParam& initParam) { + // initialize device + APP_ERROR ret = MxBase::DeviceManager::GetInstance()->InitDevices(); + if (ret != APP_ERR_OK) { + LogError << "Init devices failed, ret=" << ret << "."; + return ret; + } + // initialize context + ret = MxBase::TensorContext::GetInstance()->SetContext(initParam.deviceId); + if (ret != APP_ERR_OK) { + LogError << "Set context failed, ret=" << ret << "."; + return ret; + } + + // load model + model_ = std::make_shared(); + ret = model_->Init(initParam.modelPath, modelDesc_); + if (ret != APP_ERR_OK) { + LogError << "ModelInferenceProcessor init failed, ret=" << ret << "."; + return ret; + } + + return APP_ERR_OK; +} + +APP_ERROR FSAF::DeInit() { + model_->DeInit(); + MxBase::DeviceManager::GetInstance()->DestroyDevices(); + return APP_ERR_OK; +} + +// Get all files under a directory. +// Parameters: +// dirPath: the directory path +// Return: +// a vector of filename, including the suffix. +std::vector FSAF::GetFileList(const std::string &dirPath) { + struct dirent *ptr; + DIR *dir = opendir(dirPath.c_str()); + std::vector files; + while ((ptr = readdir(dir)) != NULL) { + if (ptr->d_name[0] == '.') { + continue; + } + files.push_back(ptr->d_name); + } + closedir(dir); + return files; +} + +// Read image from a image path. +// Parameters: +// imgPath: string of image path +// imageMat: opencv Mat object, for storging image as matrix +// height: int, storge the image height +// width: int, storge the image width +// Return: +// APP_ERROR object, if read image successfully, return APP_ERR_OK. +APP_ERROR FSAF::ReadImage(const std::string& imgPath, cv::Mat& imageMat, int& height, int& width) { + imageMat = cv::imread(imgPath, cv::IMREAD_COLOR); + + // BGR -> RGB + cv::cvtColor(imageMat, imageMat, cv::COLOR_BGR2RGB); + + width = imageMat.cols; + height = imageMat.rows; + + return APP_ERR_OK; +} + +// Resize image to fix size. +// We use RightDown padding style. +// Parameters: +// srcImageMat: source opencv Mat object, image matrix +// dstImageMat: storge destination opencv Mat object +// resizedImageInfo: contain infomation about the image, including before and after scaling +//Return: +// APP_ERROR object, if resize image successfully, return APP_ERR_OK. +APP_ERROR FSAF::ResizeImage(const cv::Mat& srcImageMat, cv::Mat& dstImageMat, + MxBase::ResizedImageInfo& resizedImageInfo) { + float resizeHeight = 800; + float resizeWidth = 1216; + float scale = std::min(resizeWidth / srcImageMat.cols, resizeHeight / srcImageMat.rows); + int new_width = srcImageMat.cols * scale; + int new_height = srcImageMat.rows * scale; + + // calculate the padding + int pad_w = resizeWidth - new_width; + int pad_h = resizeHeight - new_height; + + resizedImageInfo.heightOriginal = srcImageMat.rows; + resizedImageInfo.heightResize = resizeHeight; + resizedImageInfo.widthOriginal = srcImageMat.cols; + resizedImageInfo.widthResize = resizeWidth; + resizedImageInfo.resizeType = RESIZER_MS_KEEP_ASPECT_RATIO; + + // invoke opencv method to resize and pad + cv::resize(srcImageMat, dstImageMat, cv::Size(new_width, new_height), 0, 0, cv::INTER_CUBIC); + cv::copyMakeBorder(dstImageMat, dstImageMat, 0, pad_h, 0, pad_w, + cv::BorderTypes::BORDER_CONSTANT, cv::Scalar(0, 0, 0)); + + return APP_ERR_OK; +} + +APP_ERROR FSAF::Normalize(const cv::Mat &srcImageMat, cv::Mat &dstImageMat) +{ + constexpr size_t ALPHA_AND_BETA_SIZE = 3; + cv::Mat float32Mat; + srcImageMat.convertTo(float32Mat, CV_32FC3); + + std::vector tmp; + cv::split(float32Mat, tmp); + + const std::vector mean = {103.53, 116.28, 123.675}; + const std::vector std = {57.375, 57.120, 58.395}; + for (size_t i = 0; i < ALPHA_AND_BETA_SIZE; ++i) { + tmp[i].convertTo(tmp[i], CV_32FC3, 1 / std[i], - mean[i] / std[i]); + } + cv::merge(tmp, dstImageMat); + return APP_ERR_OK; +} + +// Convert Mat to Tensor. +// Parameters: +// imageMat: input image matrix +// tensorBase: storge image as tensor +// Return: +// APP_ERROR object, if convert image successfully, return APP_ERR_OK. +APP_ERROR FSAF::CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase) { + // calculate the data size: width * height * depth + const uint32_t dataSize = imageMat.cols * imageMat.rows * imageMat.channels(); + // allocate memory + MemoryData memoryDataDst(dataSize, MemoryData::MEMORY_DEVICE, deviceId_); + MemoryData memoryDataSrc(imageMat.data, dataSize, MemoryData::MEMORY_HOST_MALLOC); + + APP_ERROR ret = MemoryHelper::MxbsMallocAndCopy(memoryDataDst, memoryDataSrc); + if (ret != APP_ERR_OK) { + LogError << GetError(ret) << "Memory malloc failed."; + return ret; + } + // get tensor shape + // std::vector shape = {imageMat.rows * YUV444_RGB_WIDTH_NU, static_cast(imageMat.cols)}; + std::vector shape = { + static_cast(imageMat.rows), + static_cast(imageMat.cols), + static_cast(imageMat.channels())}; + + // tensorBase = TensorBase(memoryDataDst, false, shape, TENSOR_DTYPE_UINT8); + tensorBase = TensorBase(memoryDataDst, false, shape, TENSOR_DTYPE_FLOAT32); + return APP_ERR_OK; +} + +// Model inference. +// Parameters: +// inputs: input image tensor +// outputs: result tensor of inference result +// Return: +// APP_ERROR object, if convert image successfully, return APP_ERR_OK. +APP_ERROR FSAF::Inference(const std::vector& inputs, std::vector& outputs) { + auto dtypes = model_->GetOutputDataType(); + + // modelDesc_ get the output tensor size through Init() + for (size_t i = 0; i < modelDesc_.outputTensors.size(); ++i) { + std::vector shape = {}; + for (size_t j = 0; j < modelDesc_.outputTensors[i].tensorDims.size(); ++j) { + shape.push_back((uint32_t)modelDesc_.outputTensors[i].tensorDims[j]); + } + TensorBase tensor(shape, dtypes[i], MemoryData::MemoryType::MEMORY_DEVICE, deviceId_); + APP_ERROR ret = TensorBase::TensorBaseMalloc(tensor); + if (ret != APP_ERR_OK) { + LogError << "TensorBaseMalloc failed, ret=" << ret << "."; + return ret; + } + outputs.push_back(tensor); + } + + DynamicInfo dynamicInfo = {}; + dynamicInfo.dynamicType = DynamicType::STATIC_BATCH; + + // infer the result according to the input tensor + APP_ERROR ret = model_->ModelInference(inputs, outputs, dynamicInfo); + if (ret != APP_ERR_OK) { + LogError << "ModelInference failed, ret=" << ret << "."; + return ret; + } + + return APP_ERR_OK; +} + +// Post process for inference result. +// Scale the bbox to the origin image size. +// Parameters: +// imgPath: input image path +// inputs: tensor of image after inference +// resultPath: the path of storaging infer_result +// height, width: image's height and width +// name: image name, not including suffix +// showPath: the path of storaging visualizition result +// Return: +// APP_ERROR object, if post process image successfully, return APP_ERR_OK. +APP_ERROR FSAF::PostProcess(const std::string& imgPath, std::vector& inputs, + const std::string &resultPath, int& height, int& width, const std::string& name, std::string &showPath) { + // object num + int tensor_size = 100; + + MxBase::TensorBase& tensor = inputs[1]; // 1*100 + + int ret = tensor.ToHost(); + if (ret != APP_ERR_OK) { + LogError << GetError(ret) << "Tensor_1 deploy to host failed."; + return ret; + } + std::vector shape = tensor.GetShape(); + + auto labels = reinterpret_cast(tensor.GetBuffer()); // 1*100 + + std::cout << "---------------------------labels---------------------------" << std::endl; + int label[tensor_size] = {0}; + for(int i = 0; i < tensor_size; i++){ + std::cout << labels[i] << " "; + label[i] = labels[i]; + } + + tensor = inputs[0]; // 1*100*5 + ret = tensor.ToHost(); + if (ret != APP_ERR_OK) { + LogError << GetError(ret) << "Tensor_0 deploy to host failed."; + return ret; + } + + auto bbox = reinterpret_cast(tensor.GetBuffer()); + std::cout << "\n---------------------------bboxes--------------------------" << std::endl; + for(int i = 0; i < tensor_size; i++){ + std::cout << bbox[i][0] << ", " << bbox[i][1] << ", " << bbox[i][2] << ", " + << bbox[i][3] << ", " << bbox[i][4] << std::endl; + } + + // get infer coordinates + float image_size_w = width; + float image_size_h = height; + float net_input_width = 1216; + float net_input_height = 800; + float scale = std::min(net_input_width / (float)width, net_input_height / (float)height); + + int new_width = image_size_w * scale; + + float n_scale = (float)new_width / image_size_w; + + // probability threshold and all classes for label + float prob_thres = 0.05; + std::vector classes = {"person", "bicycle", "car", "motorcycle", "airplane", "bus", + "train", "truck", "boat", "traffic light", "fire hydrant", + "stop sign", "parking meter", "bench", "bird", "cat", "dog", + "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", + "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", + "skis", "snowboard", "sports ball", "kite", "baseball bat", + "baseball glove", "skateboard", "surfboard", "tennis racket", + "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", + "banana", "apple", "sandwich", "orange", "broccoli", "carrot", + "hot dog", "pizza", "donut", "cake", "chair", "couch", + "potted plant", "bed", "dining table", "toilet", "tv", "laptop", + "mouse", "remote", "keyboard", "cell phone", "microwave", + "oven", "toaster", "sink", "refrigerator", "book", "clock", + "vase", "scissors", "teddy bear", "hair drier", "toothbrush"}; + + // storge bbox after post processing + float ppbox[tensor_size][5] = {0}; + + for (int j = 0; j < tensor_size; ++j) { + // scale bbox + ppbox[j][0] = (bbox[j][0]) / n_scale; + ppbox[j][1] = (bbox[j][1]) / n_scale; + ppbox[j][2] = (bbox[j][2]) / n_scale; + ppbox[j][3] = (bbox[j][3]) / n_scale; + ppbox[j][4] = bbox[j][4]; + // limit bbox in a valid range + ppbox[j][0] = std::max((float)0, ppbox[j][0]); + ppbox[j][1] = std::max((float)0, ppbox[j][1]); + ppbox[j][2] = std::min(image_size_w, ppbox[j][2]); + ppbox[j][3] = std::min(image_size_h, ppbox[j][3]); + } + + std::ofstream out(resultPath); + cv::Mat imgCur = cv::imread(imgPath); + + for (int j = 0; j < tensor_size; ++j) { + if(float(ppbox[j][4]) < float(prob_thres)) { + continue; + } + if(label[j] < 0 || label[j] > 80) { + continue; + } + + // standard the output result + std::string class_name = classes[int(label[j])]; + std::string det_results_str = ""; + std::ostringstream oss; + oss << ppbox[j][4]; + std::string confidence(oss.str()); + char strff1[21], strff2[21], strff3[21], strff4[21], strff0[21]; + memset(strff1, 0, sizeof(strff1)); + memset(strff2, 0, sizeof(strff2)); + memset(strff3, 0, sizeof(strff3)); + memset(strff4, 0, sizeof(strff4)); + memset(strff0, 0, sizeof(strff0)); + // print ppbox to char* + sprintf(strff0, "%.8f", ppbox[j][0]); + sprintf(strff1, "%.8f", ppbox[j][1]); + sprintf(strff2, "%.8f", ppbox[j][2]); + sprintf(strff3, "%.8f", ppbox[j][3]); + sprintf(strff4, "%.8f", ppbox[j][4]); + det_results_str = det_results_str + class_name + " " + strff4 + " " + strff0 + " " + strff1 + " " + + strff2 + " " + strff3 + "\n"; + + out << det_results_str; + std::cout << det_results_str; + // visualization on the origin image + cv::Point p3((ppbox[j][0]), (ppbox[j][1])); + cv::Point p4((ppbox[j][2]), (ppbox[j][3])); + cv::Scalar colorRectangle1(0, 255, 1); + int thicknessRectangle1 = 1; + cv::rectangle(imgCur, p3, p4, colorRectangle1, thicknessRectangle1); + cv::putText(imgCur, class_name + "|" + confidence, p3, cv::FONT_HERSHEY_SIMPLEX, + 0.5, colorRectangle1, 1, 1, false); + } + out.close(); + cv::imwrite(showPath + "/" + name + ".jpg", imgCur); + + return APP_ERR_OK; +} + +// Primary method for process all images. +APP_ERROR FSAF::Process(const std::string &dirPath, std::string &resultPath, std::string &showPath) { + std::vector dirFileList = GetFileList(dirPath); + std::vector names, paths; + // for debug counting + int i = 0; + // process every image + for(auto imgFile : dirFileList) { + std::string imgPath = dirPath + "/" + imgFile; + std::string name = imgFile.substr(0, imgFile.find(".")); + std::string subresultPath = resultPath + "/" + name + ".txt"; + + cv::Mat imageMat; + int height = 0; + int width = 0; + // get image infomation + APP_ERROR ret = ReadImage(imgPath, imageMat, height, width); + if (ret != APP_ERR_OK) { + LogError << "ReadImage failed, ret=" << ret << "."; + return ret; + } + // resize image and pad it + ResizedImageInfo resizedImageInfo; + ResizeImage(imageMat, imageMat, resizedImageInfo); + + // convert image matrix to tensor + TensorBase tensorBase; + ret = CVMatToTensorBase(imageMat, tensorBase); + if (ret != APP_ERR_OK) { + LogError << "CVMatToTensorBase failed, ret=" << ret << "."; + return ret; + } + + std::vector inputs = {}; + std::vector outputs = {}; + inputs.push_back(tensorBase); + // infer and get output tensor + ret = Inference(inputs, outputs); + if (ret != APP_ERR_OK) { + LogError << "Inference failed, ret=" << ret << "."; + return ret; + } + // post process the bbox to the origin image, + // and implement visualizition. + ret = PostProcess(imgPath, outputs, subresultPath, height, width, name, showPath); + if (ret != APP_ERR_OK) { + LogError << "PostProcess failed, ret=" << ret << "."; + return ret; + } + // add count + i++; + std::cout << i << std::endl; + } + + return APP_ERR_OK; + +} diff --git a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/src/fsaf.h b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/src/fsaf.h old mode 100755 new mode 100644 index 8f20a8db67955250538d95660e6cfd3ef0ff1e33..571154919db9b742592df337a9f87d3aa8ebc870 --- a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/src/fsaf.h +++ b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/src/fsaf.h @@ -1,65 +1,65 @@ -/* - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UNET_SEGMENTATION_H -#define UNET_SEGMENTATION_H - -#include - -#include "MxBase/ModelInfer/ModelInferenceProcessor.h" -#include "MxBase/PostProcessBases/PostProcessDataType.h" -#include "MxBase/Tensor/TensorContext/TensorContext.h" - -// parameters struct for initialize Model -struct InitParam { - // npu device id - uint32_t deviceId; - // model path of .om - std::string modelPath; -}; - -// FSAF Model class -// Example: -// ... -// FSAF fsaf; -// APP_ERROR ret = fsaf.Init(initParam); -// ret = fsaf.Process(imgPath,resultPath,showPath); -// ... -// fsaf.DeInit(); -class FSAF { -public: - APP_ERROR Init(const InitParam &initParam); - APP_ERROR DeInit(); - APP_ERROR ReadImage(const std::string &imgPath, cv::Mat &imageMat, int& height, int& width); - APP_ERROR ResizeImage(const cv::Mat &srcImageMat, cv::Mat &dstImageMat, - MxBase::ResizedImageInfo &resziedImageInfo); - APP_ERROR CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase); - APP_ERROR VectorToTensorBase(int* transMat, MxBase::TensorBase& tensorBase); - APP_ERROR Inference(const std::vector &inputs, std::vector &outputs); - APP_ERROR PostProcess(const std::string& imgPath, std::vector &inputs, - const std::string &subresultPath,int& height, int& width,const std::string& name,std::string &showPath); - APP_ERROR Process(const std::string &dirPath, std::string &resultPath, std::string &showPath); - APP_ERROR Normalize(const cv::Mat &srcImageMat, cv::Mat &dstImageMat); - -private: - std::shared_ptr model_; - MxBase::ModelDesc modelDesc_; - uint32_t deviceId_ = 0; - - std::vector GetFileList(const std::string &dirPath); -}; - -#endif +/* + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UNET_SEGMENTATION_H +#define UNET_SEGMENTATION_H + +#include + +#include "MxBase/ModelInfer/ModelInferenceProcessor.h" +#include "MxBase/PostProcessBases/PostProcessDataType.h" +#include "MxBase/Tensor/TensorContext/TensorContext.h" + +// parameters struct for initialize Model +struct InitParam { + // npu device id + uint32_t deviceId; + // model path of .om + std::string modelPath; +}; + +// FSAF Model class +// Example: +// ... +// FSAF fsaf; +// APP_ERROR ret = fsaf.Init(initParam); +// ret = fsaf.Process(imgPath,resultPath,showPath); +// ... +// fsaf.DeInit(); +class FSAF { +public: + APP_ERROR Init(const InitParam &initParam); + APP_ERROR DeInit(); + APP_ERROR ReadImage(const std::string &imgPath, cv::Mat &imageMat, int& height, int& width); + APP_ERROR ResizeImage(const cv::Mat &srcImageMat, cv::Mat &dstImageMat, + MxBase::ResizedImageInfo &resziedImageInfo); + APP_ERROR CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase); + APP_ERROR VectorToTensorBase(int* transMat, MxBase::TensorBase& tensorBase); + APP_ERROR Inference(const std::vector &inputs, std::vector &outputs); + APP_ERROR PostProcess(const std::string& imgPath, std::vector &inputs, + const std::string &subresultPath,int& height, int& width,const std::string& name,std::string &showPath); + APP_ERROR Process(const std::string &dirPath, std::string &resultPath, std::string &showPath); + APP_ERROR Normalize(const cv::Mat &srcImageMat, cv::Mat &dstImageMat); + +private: + std::shared_ptr model_; + MxBase::ModelDesc modelDesc_; + uint32_t deviceId_ = 0; + + std::vector GetFileList(const std::string &dirPath); +}; + +#endif diff --git a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/src/main.cpp b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/src/main.cpp old mode 100755 new mode 100644 index 141ab3f167070a2dfe448b92cccef71ec32ab01c..4d85ce5862a41e4651f90526ee791dff095daaff --- a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/src/main.cpp +++ b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/mxbase/src/main.cpp @@ -1,53 +1,53 @@ -/* - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "fsaf.h" - -#include "MxBase/Log/Log.h" - -int main() { - // config the parameters for fsaf model - InitParam initParam = {}; - initParam.deviceId = 0; - initParam.modelPath = "../../data/model/fsaf.om"; - - // declare and initialize the fsaf model - FSAF fsaf; - APP_ERROR ret = fsaf.Init(initParam); - if (ret != APP_ERR_OK) { - LogError << "FSAF init failed, ret=" << ret << "."; - return ret; - } - - // coco2017 validation set for object detection - std::string imgPath = "../../data/input/val2017"; - - // directories for saving result - std::string outputPath = "../output/"; - std::string resultPath = outputPath + "infer_result"; - std::string showPath = outputPath + "show_result"; - - // call the process of fsaf model - ret = fsaf.Process(imgPath, resultPath, showPath); - if (ret != APP_ERR_OK) { - LogError << "FSAF process failed, ret=" << ret << "."; - fsaf.DeInit(); - return ret; - } - - fsaf.DeInit(); - return APP_ERR_OK; -} +/* + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "fsaf.h" + +#include "MxBase/Log/Log.h" + +int main() { + // config the parameters for fsaf model + InitParam initParam = {}; + initParam.deviceId = 0; + initParam.modelPath = "../../data/model/fsaf.om"; + + // declare and initialize the fsaf model + FSAF fsaf; + APP_ERROR ret = fsaf.Init(initParam); + if (ret != APP_ERR_OK) { + LogError << "FSAF init failed, ret=" << ret << "."; + return ret; + } + + // coco2017 validation set for object detection + std::string imgPath = "../../data/input/val2017"; + + // directories for saving result + std::string outputPath = "../output/"; + std::string resultPath = outputPath + "infer_result"; + std::string showPath = outputPath + "show_result"; + + // call the process of fsaf model + ret = fsaf.Process(imgPath, resultPath, showPath); + if (ret != APP_ERR_OK) { + LogError << "FSAF process failed, ret=" << ret << "."; + fsaf.DeInit(); + return ret; + } + + fsaf.DeInit(); + return APP_ERR_OK; +} diff --git a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/sdk/run.sh b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/sdk/run.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/util/coco_eval.py b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/util/coco_eval.py old mode 100755 new mode 100644 index 92e70605ac1f99b0befcb4270abc4bcc4da3d181..47904787ce72531e2f5c510c1cf6bfa5330cffff --- a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/util/coco_eval.py +++ b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/util/coco_eval.py @@ -1,97 +1,97 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License.import argparse - -import argparse -import numpy as np -from pycocotools.coco import COCO -from pycocotools.cocoeval import COCOeval - -CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', - 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', - 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', - 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', - 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', - 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', - 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', - 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', - 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', - 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', - 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', - 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] - -def coco_evaluation(annotation_json, result_json): - cocoGt = COCO(annotation_json) - cocoDt = cocoGt.loadRes(result_json) - iou_thrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True) - iou_type = 'bbox' - - cocoEval = COCOeval(cocoGt, cocoDt, iou_type) - cocoEval.params.catIds = cocoGt.getCatIds(catNms=CLASSES) - cocoEval.params.imgIds = cocoGt.getImgIds() - delete_id=[3661,70254,309391,374551,190007] - for did in delete_id: - cocoEval.params.imgIds.remove(did) - - cocoEval.params.maxDets = [100, 300, 1000] # proposal number for evaluating recalls/mAPs. - cocoEval.params.iouThrs = iou_thrs - - cocoEval.evaluate() - cocoEval.accumulate() - cocoEval.summarize() - - # mapping of cocoEval.stats - coco_metric_names = { - 'mAP': 0, - 'mAP_50': 1, - 'mAP_75': 2, - 'mAP_s': 3, - 'mAP_m': 4, - 'mAP_l': 5, - 'AR@100': 6, - 'AR@300': 7, - 'AR@1000': 8, - 'AR_s@1000': 9, - 'AR_m@1000': 10, - 'AR_l@1000': 11 - } - - metric_items = ['mAP', 'mAP_50', 'mAP_75', 'mAP_s', 'mAP_m', 'mAP_l'] - eval_results = {} - - for metric_item in metric_items: - key = f'bbox_{metric_item}' - val = float( - f'{cocoEval.stats[coco_metric_names[metric_item]]:.3f}' - ) - eval_results[key] = val - ap = cocoEval.stats[:6] - eval_results['bbox_mAP_copypaste'] = ( - f'{ap[0]:.3f} {ap[1]:.3f} {ap[2]:.3f} {ap[3]:.3f} ' - f'{ap[4]:.3f} {ap[5]:.3f}') - - return eval_results - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument("--ground_truth_file", default="../data/input/annotations/instances_val2017.json") - parser.add_argument("--detection_result_file", default="../sdk/output/coco_detection_result.json") - parser.add_argument("--eval_result_file", default="../sdk/output/eval_map_result.txt") - args = parser.parse_args() - result = coco_evaluation(args.ground_truth_file, args.detection_result_file) - print(result) - with open(args.eval_result_file, 'w') as f: - for key, value in result.items(): +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.import argparse + +import argparse +import numpy as np +from pycocotools.coco import COCO +from pycocotools.cocoeval import COCOeval + +CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', + 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', + 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', + 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', + 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', + 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', + 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', + 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', + 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', + 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', + 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', + 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] + +def coco_evaluation(annotation_json, result_json): + cocoGt = COCO(annotation_json) + cocoDt = cocoGt.loadRes(result_json) + iou_thrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True) + iou_type = 'bbox' + + cocoEval = COCOeval(cocoGt, cocoDt, iou_type) + cocoEval.params.catIds = cocoGt.getCatIds(catNms=CLASSES) + cocoEval.params.imgIds = cocoGt.getImgIds() + delete_id=[3661,70254,309391,374551,190007] + for did in delete_id: + cocoEval.params.imgIds.remove(did) + + cocoEval.params.maxDets = [100, 300, 1000] # proposal number for evaluating recalls/mAPs. + cocoEval.params.iouThrs = iou_thrs + + cocoEval.evaluate() + cocoEval.accumulate() + cocoEval.summarize() + + # mapping of cocoEval.stats + coco_metric_names = { + 'mAP': 0, + 'mAP_50': 1, + 'mAP_75': 2, + 'mAP_s': 3, + 'mAP_m': 4, + 'mAP_l': 5, + 'AR@100': 6, + 'AR@300': 7, + 'AR@1000': 8, + 'AR_s@1000': 9, + 'AR_m@1000': 10, + 'AR_l@1000': 11 + } + + metric_items = ['mAP', 'mAP_50', 'mAP_75', 'mAP_s', 'mAP_m', 'mAP_l'] + eval_results = {} + + for metric_item in metric_items: + key = f'bbox_{metric_item}' + val = float( + f'{cocoEval.stats[coco_metric_names[metric_item]]:.3f}' + ) + eval_results[key] = val + ap = cocoEval.stats[:6] + eval_results['bbox_mAP_copypaste'] = ( + f'{ap[0]:.3f} {ap[1]:.3f} {ap[2]:.3f} {ap[3]:.3f} ' + f'{ap[4]:.3f} {ap[5]:.3f}') + + return eval_results + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--ground_truth_file", default="../data/input/annotations/instances_val2017.json") + parser.add_argument("--detection_result_file", default="../sdk/output/coco_detection_result.json") + parser.add_argument("--eval_result_file", default="../sdk/output/eval_map_result.txt") + args = parser.parse_args() + result = coco_evaluation(args.ground_truth_file, args.detection_result_file) + print(result) + with open(args.eval_result_file, 'w') as f: + for key, value in result.items(): f.write(key + ': ' + str(value) + '\n') \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/util/txt_to_json.py b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/util/txt_to_json.py old mode 100755 new mode 100644 index f713ec1c85067431d490c9bf88b9820d61e78cc6..31fe719e3ce4c70b133c6c1210100cd51cc878e0 --- a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/util/txt_to_json.py +++ b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/infer/util/txt_to_json.py @@ -1,113 +1,113 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License.import argparse - -import glob -import os -import sys -import argparse -import mmcv - -''' - 0,0 ------> x (width) - | - | (Left,Top) - | *_________ - | | | - | | - y |_________| - (height) * - (Right,Bottom) -''' -CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', - 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', - 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', - 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', - 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', - 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', - 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', - 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', - 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', - 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', - 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', - 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] - -cat_ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, -24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, -48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, -72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90] - - -def file_lines_to_list(path): - # open txt file lines to a list - with open(path) as f: - content = f.readlines() - # remove whitespace characters like `\n` at the end of each line - content = [x.strip() for x in content] - return content - - -def error(msg): - print(msg) - sys.exit(0) - - -def get_predict_list(file_path, gt_classes): - dr_files_list = glob.glob(file_path + '/*.txt') - dr_files_list.sort() - - bounding_boxes = [] - for txt_file in dr_files_list: - file_id = txt_file.split(".txt", 1)[0] - file_id = os.path.basename(os.path.normpath(file_id)) - lines = file_lines_to_list(txt_file) - for line in lines: - try: - sl = line.split() - if len(sl) > 6: - class_name = sl[0] + ' ' + sl[1] - scores, left, top, right, bottom = sl[2:] - else: - class_name, scores, left, top, right, bottom = sl - if float(scores) < 0.05: - continue - except ValueError: - error_msg = "Error: File " + txt_file + " wrong format.\n" - error_msg += " Expected: \n" - error_msg += " Received: " + line - error(error_msg) - - # bbox = left + " " + top + " " + right + " " + bottom - left = float(left) - right = float(right) - top = float(top) - bottom = float(bottom) - bbox = [left, top, right-left, bottom-top] - bounding_boxes.append({"image_id": int(file_id), "bbox": bbox, - "score": float(scores), "category_id": cat_ids[CLASSES.index(class_name)]}) - # sort detection-results by decreasing scores - # bounding_boxes.sort(key=lambda x: float(x['score']), reverse=True) - return bounding_boxes - - -if __name__ == '__main__': - parser = argparse.ArgumentParser('mAp calculate') - parser.add_argument('--infer_result_path', default="../sdk/output/infer_result/", - help='the path of the predict result') - parser.add_argument("--json_output_filename", default="../sdk/output/coco_detection_result") - args = parser.parse_args() - - res_bbox = get_predict_list(args.infer_result_path, CLASSES) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.import argparse + +import glob +import os +import sys +import argparse +import mmcv + +''' + 0,0 ------> x (width) + | + | (Left,Top) + | *_________ + | | | + | | + y |_________| + (height) * + (Right,Bottom) +''' +CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', + 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', + 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', + 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', + 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', + 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', + 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', + 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', + 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', + 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', + 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', + 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] + +cat_ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, +24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, +48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, +72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90] + + +def file_lines_to_list(path): + # open txt file lines to a list + with open(path) as f: + content = f.readlines() + # remove whitespace characters like `\n` at the end of each line + content = [x.strip() for x in content] + return content + + +def error(msg): + print(msg) + sys.exit(0) + + +def get_predict_list(file_path, gt_classes): + dr_files_list = glob.glob(file_path + '/*.txt') + dr_files_list.sort() + + bounding_boxes = [] + for txt_file in dr_files_list: + file_id = txt_file.split(".txt", 1)[0] + file_id = os.path.basename(os.path.normpath(file_id)) + lines = file_lines_to_list(txt_file) + for line in lines: + try: + sl = line.split() + if len(sl) > 6: + class_name = sl[0] + ' ' + sl[1] + scores, left, top, right, bottom = sl[2:] + else: + class_name, scores, left, top, right, bottom = sl + if float(scores) < 0.05: + continue + except ValueError: + error_msg = "Error: File " + txt_file + " wrong format.\n" + error_msg += " Expected: \n" + error_msg += " Received: " + line + error(error_msg) + + # bbox = left + " " + top + " " + right + " " + bottom + left = float(left) + right = float(right) + top = float(top) + bottom = float(bottom) + bbox = [left, top, right-left, bottom-top] + bounding_boxes.append({"image_id": int(file_id), "bbox": bbox, + "score": float(scores), "category_id": cat_ids[CLASSES.index(class_name)]}) + # sort detection-results by decreasing scores + # bounding_boxes.sort(key=lambda x: float(x['score']), reverse=True) + return bounding_boxes + + +if __name__ == '__main__': + parser = argparse.ArgumentParser('mAp calculate') + parser.add_argument('--infer_result_path', default="../sdk/output/infer_result/", + help='the path of the predict result') + parser.add_argument("--json_output_filename", default="../sdk/output/coco_detection_result") + args = parser.parse_args() + + res_bbox = get_predict_list(args.infer_result_path, CLASSES) mmcv.dump(res_bbox, args.json_output_filename + '.json') \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/mmdetection/tools/dist_train.sh b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/mmdetection/tools/dist_train.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/mmdetection/tools/slurm_test.sh b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/mmdetection/tools/slurm_test.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/mmdetection/tools/slurm_train.sh b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/mmdetection/tools/slurm_train.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/scripts/train_8p.sh b/PyTorch/contrib/cv/detection/FSAF_for_Pytorch/scripts/train_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/FaceBoxes/README.md b/PyTorch/contrib/cv/detection/FaceBoxes/README.md index ef40a2e1a1e7038d8a2ee634ec1e22a49de6ba86..b3677532f3fac69acf1ac19bb44f7ba5b188c556 100644 --- a/PyTorch/contrib/cv/detection/FaceBoxes/README.md +++ b/PyTorch/contrib/cv/detection/FaceBoxes/README.md @@ -1,117 +1,117 @@ -# FaceBoxes - -本项目实现了FaceBoxes从GPU到NPU上训练的迁移,源开源代码仓[FaceBoxes.Pytorch](https://github.com/zisianw/FaceBoxes.PyTorch) - -## FaceBoxes Detail - -本项目对于FaceBoxes.Pytorch做出了如下更改: - -1. 将设备从Nvidia GPU迁移到Huawei NPU上。 -2. 在源代码的基础上添加了Apex混合精度进行优化。 -3. 在模型迁移到NPU上后一些不支持或性能较低的算子放到CPU上进行规避。 -4. 针对测试结果添加了新的评估脚本。 - -## Requirements - -```bash -pip install -r requirements.txt -``` - -- NPU 配套的run包安装 -- Python3.7.5 -- PyTorch(NPU版本) -- Apex(NPU版本) - -### 导入环境变量 - -```bash -source scripts/npu_set_env.sh -``` - -### 编译 - -```bash -git clone https://github.com/Levi0223/FDDB_Evaluation.git -cd FDDB_Evaluation -python3 setup.py build_ext --inplace -mv ../convert.py ../split.py ./ -``` - -### 准备数据集 -数据集下载参考源代码仓 - -1. 下载[WIDER_FACE](https://github.com/zisianw/FaceBoxes.PyTorch)数据集,将图片放在这个目录下(数据集包含32203张图片): - - ```bash - $FaceBoxes_ROOT/data/WIDER_FACE/images/ - ``` - - 下载转换后的[标注文件](https://github.com/zisianw/FaceBoxes.PyTorch),将他们放在这个目录下: - - ```bash - $FaceBoxes_ROOT/data/WIDER_FACE/annotations/ - ``` - - 最终数据集目录结构如下: - - ![输入图片说明](https://images.gitee.com/uploads/images/2021/0927/121855_9a16b40b_6515416.png "屏幕截图.png") - -2. 下载[FDDB](https://github.com/zisianw/FaceBoxes.PyTorch)数据集,将图片放在这个目录下(数据集包含2845张图片): - - ```bash - $FaceBoxes_ROOT/data/FDDB/images/ - ``` - - 最终数据集目录结构如下: - - ![输入图片说明](https://images.gitee.com/uploads/images/2021/0927/121924_9f00b12c_6515416.png "屏幕截图.png") - -## Trainning - -### 单卡性能评估 - -```bash -### 输出单卡FPS -bash scripts/train_performance_1p.sh -``` - -### 单卡训练 - -```bash -### 单卡全量训练 -bash scripts/train_1p.sh -## 日志文件在当前目录下的1p_train.log -``` - -### 多卡性能评估 - -```bash -### 输出多卡FPS -bash scripts/train_performance_8p.sh -``` - -### 多卡训练 - -```bash -### 多卡全量训练 -bash scripts/train_8p.sh -## 日志文件在当前目录下的8p_train.log -``` - -### Test - -```bash -### 测试训练得到的权重文件,生成FDDB_dets.txt -bash test.sh -## 日志文件在当前目录下的test.log -### 解析FDDB_dets.txt文件,打印最终精度 -bash eval.sh -``` - -## Performance - -| | AP | APEX | lOSS_SCALE | EPOCH | -| :-----: | :----: | :--: | :--------: | :---: | -| **GPU** | 0.9440 | O2 | 128 | 300 | -| **NPU** | 0.9396 | O2 | 128 | 300 | - +# FaceBoxes + +本项目实现了FaceBoxes从GPU到NPU上训练的迁移,源开源代码仓[FaceBoxes.Pytorch](https://github.com/zisianw/FaceBoxes.PyTorch) + +## FaceBoxes Detail + +本项目对于FaceBoxes.Pytorch做出了如下更改: + +1. 将设备从Nvidia GPU迁移到Huawei NPU上。 +2. 在源代码的基础上添加了Apex混合精度进行优化。 +3. 在模型迁移到NPU上后一些不支持或性能较低的算子放到CPU上进行规避。 +4. 针对测试结果添加了新的评估脚本。 + +## Requirements + +```bash +pip install -r requirements.txt +``` + +- NPU 配套的run包安装 +- Python3.7.5 +- PyTorch(NPU版本) +- Apex(NPU版本) + +### 导入环境变量 + +```bash +source scripts/npu_set_env.sh +``` + +### 编译 + +```bash +git clone https://github.com/Levi0223/FDDB_Evaluation.git +cd FDDB_Evaluation +python3 setup.py build_ext --inplace +mv ../convert.py ../split.py ./ +``` + +### 准备数据集 +数据集下载参考源代码仓 + +1. 下载[WIDER_FACE](https://github.com/zisianw/FaceBoxes.PyTorch)数据集,将图片放在这个目录下(数据集包含32203张图片): + + ```bash + $FaceBoxes_ROOT/data/WIDER_FACE/images/ + ``` + + 下载转换后的[标注文件](https://github.com/zisianw/FaceBoxes.PyTorch),将他们放在这个目录下: + + ```bash + $FaceBoxes_ROOT/data/WIDER_FACE/annotations/ + ``` + + 最终数据集目录结构如下: + + ![输入图片说明](https://images.gitee.com/uploads/images/2021/0927/121855_9a16b40b_6515416.png "屏幕截图.png") + +2. 下载[FDDB](https://github.com/zisianw/FaceBoxes.PyTorch)数据集,将图片放在这个目录下(数据集包含2845张图片): + + ```bash + $FaceBoxes_ROOT/data/FDDB/images/ + ``` + + 最终数据集目录结构如下: + + ![输入图片说明](https://images.gitee.com/uploads/images/2021/0927/121924_9f00b12c_6515416.png "屏幕截图.png") + +## Trainning + +### 单卡性能评估 + +```bash +### 输出单卡FPS +bash scripts/train_performance_1p.sh +``` + +### 单卡训练 + +```bash +### 单卡全量训练 +bash scripts/train_1p.sh +## 日志文件在当前目录下的1p_train.log +``` + +### 多卡性能评估 + +```bash +### 输出多卡FPS +bash scripts/train_performance_8p.sh +``` + +### 多卡训练 + +```bash +### 多卡全量训练 +bash scripts/train_8p.sh +## 日志文件在当前目录下的8p_train.log +``` + +### Test + +```bash +### 测试训练得到的权重文件,生成FDDB_dets.txt +bash test.sh +## 日志文件在当前目录下的test.log +### 解析FDDB_dets.txt文件,打印最终精度 +bash eval.sh +``` + +## Performance + +| | AP | APEX | lOSS_SCALE | EPOCH | +| :-----: | :----: | :--: | :--------: | :---: | +| **GPU** | 0.9440 | O2 | 128 | 300 | +| **NPU** | 0.9396 | O2 | 128 | 300 | + diff --git a/PyTorch/contrib/cv/detection/FaceBoxes/README_raw.md b/PyTorch/contrib/cv/detection/FaceBoxes/README_raw.md index c36af43fb8d9445d151b82a3ff34bc1e60184e40..3ae1866b888230654a79c13e77ef820a1e8fab22 100644 --- a/PyTorch/contrib/cv/detection/FaceBoxes/README_raw.md +++ b/PyTorch/contrib/cv/detection/FaceBoxes/README_raw.md @@ -1,92 +1,92 @@ -# FaceBoxes in PyTorch - -[![License](https://img.shields.io/badge/license-BSD-blue.svg)](LICENSE) - -By [Zisian Wong](https://github.com/zisianw), [Shifeng Zhang](http://www.cbsr.ia.ac.cn/users/sfzhang/) - -A [PyTorch](https://pytorch.org/) implementation of [FaceBoxes: A CPU Real-time Face Detector with High Accuracy](https://arxiv.org/abs/1708.05234). The official code in Caffe can be found [here](https://github.com/sfzhang15/FaceBoxes). - -## Performance -| Dataset | Original Caffe | PyTorch Implementation | -|:-|:-:|:-:| -| AFW | 98.98 % | 98.55% | -| PASCAL | 96.77 % | 97.05% | -| FDDB | 95.90 % | 96.00% | - -## Citation -Please cite the paper in your publications if it helps your research: - - @inproceedings{zhang2017faceboxes, - title = {Faceboxes: A CPU Real-time Face Detector with High Accuracy}, - author = {Zhang, Shifeng and Zhu, Xiangyu and Lei, Zhen and Shi, Hailin and Wang, Xiaobo and Li, Stan Z.}, - booktitle = {IJCB}, - year = {2017} - } - -### Contents -- [Installation](#installation) -- [Training](#training) -- [Evaluation](#evaluation) -- [References](#references) - -## Installation -1. Install [PyTorch](https://pytorch.org/) >= v1.0.0 following official instruction. - -2. Clone this repository. We will call the cloned directory as `$FaceBoxes_ROOT`. -```Shell -git clone https://github.com/zisianw/FaceBoxes.PyTorch.git -``` - -3. Compile the nms: -```Shell -./make.sh -``` - -_Note: Codes are based on Python 3+._ - -## Training -1. Download [WIDER FACE](https://github.com/zisianw/FaceBoxes.PyTorch) dataset, place the images under this directory: - ```Shell - $FaceBoxes_ROOT/data/WIDER_FACE/images - ``` -2. Convert WIDER FACE annotations to VOC format or download [our converted annotations](https://github.com/zisianw/FaceBoxes.PyTorch), place them under this directory: - ```Shell - $FaceBoxes_ROOT/data/WIDER_FACE/annotations - ``` - -3. Train the model using WIDER FACE: - ```Shell - cd $FaceBoxes_ROOT/ - python3 train.py - ``` - -If you do not wish to train the model, you can download [our pre-trained model](https://github.com/zisianw/FaceBoxes.PyTorch) and save it in `$FaceBoxes_ROOT/weights`. - - -## Evaluation -1. Download the images of [AFW](https://github.com/zisianw/FaceBoxes.PyTorch), [PASCAL Face](https://github.com/zisianw/FaceBoxes.PyTorch) and [FDDB]( -https://github.com/zisianw/FaceBoxes.PyTorch) to: -```Shell -$FaceBoxes_ROOT/data/AFW/images/ -$FaceBoxes_ROOT/data/PASCAL/images/ -$FaceBoxes_ROOT/data/FDDB/images/ -``` - -2. Evaluate the trained model using: -```Shell -# dataset choices = ['AFW', 'PASCAL', 'FDDB'] -python3 test.py --dataset FDDB -# evaluate using cpu -python3 test.py --cpu -# visualize detection results -python3 test.py -s --vis_thres 0.3 -``` - -3. Download [eval_tool](https://github.com/sfzhang15/face-eval) to evaluate the performance. - -## References -- [Official release (Caffe)](https://github.com/sfzhang15/FaceBoxes) -- A huge thank you to SSD ports in PyTorch that have been helpful: - * [ssd.pytorch](https://github.com/amdegroot/ssd.pytorch), [RFBNet](https://github.com/ruinmessi/RFBNet) - - _Note: If you can not download the converted annotations, the provided images and the trained model through the above links, you can download them through [BaiduYun](https://pan.baidu.com/s/1HoW3wbldnbmgW2PS4i4Irw)._ +# FaceBoxes in PyTorch + +[![License](https://img.shields.io/badge/license-BSD-blue.svg)](LICENSE) + +By [Zisian Wong](https://github.com/zisianw), [Shifeng Zhang](http://www.cbsr.ia.ac.cn/users/sfzhang/) + +A [PyTorch](https://pytorch.org/) implementation of [FaceBoxes: A CPU Real-time Face Detector with High Accuracy](https://arxiv.org/abs/1708.05234). The official code in Caffe can be found [here](https://github.com/sfzhang15/FaceBoxes). + +## Performance +| Dataset | Original Caffe | PyTorch Implementation | +|:-|:-:|:-:| +| AFW | 98.98 % | 98.55% | +| PASCAL | 96.77 % | 97.05% | +| FDDB | 95.90 % | 96.00% | + +## Citation +Please cite the paper in your publications if it helps your research: + + @inproceedings{zhang2017faceboxes, + title = {Faceboxes: A CPU Real-time Face Detector with High Accuracy}, + author = {Zhang, Shifeng and Zhu, Xiangyu and Lei, Zhen and Shi, Hailin and Wang, Xiaobo and Li, Stan Z.}, + booktitle = {IJCB}, + year = {2017} + } + +### Contents +- [Installation](#installation) +- [Training](#training) +- [Evaluation](#evaluation) +- [References](#references) + +## Installation +1. Install [PyTorch](https://pytorch.org/) >= v1.0.0 following official instruction. + +2. Clone this repository. We will call the cloned directory as `$FaceBoxes_ROOT`. +```Shell +git clone https://github.com/zisianw/FaceBoxes.PyTorch.git +``` + +3. Compile the nms: +```Shell +./make.sh +``` + +_Note: Codes are based on Python 3+._ + +## Training +1. Download [WIDER FACE](https://github.com/zisianw/FaceBoxes.PyTorch) dataset, place the images under this directory: + ```Shell + $FaceBoxes_ROOT/data/WIDER_FACE/images + ``` +2. Convert WIDER FACE annotations to VOC format or download [our converted annotations](https://github.com/zisianw/FaceBoxes.PyTorch), place them under this directory: + ```Shell + $FaceBoxes_ROOT/data/WIDER_FACE/annotations + ``` + +3. Train the model using WIDER FACE: + ```Shell + cd $FaceBoxes_ROOT/ + python3 train.py + ``` + +If you do not wish to train the model, you can download [our pre-trained model](https://github.com/zisianw/FaceBoxes.PyTorch) and save it in `$FaceBoxes_ROOT/weights`. + + +## Evaluation +1. Download the images of [AFW](https://github.com/zisianw/FaceBoxes.PyTorch), [PASCAL Face](https://github.com/zisianw/FaceBoxes.PyTorch) and [FDDB]( +https://github.com/zisianw/FaceBoxes.PyTorch) to: +```Shell +$FaceBoxes_ROOT/data/AFW/images/ +$FaceBoxes_ROOT/data/PASCAL/images/ +$FaceBoxes_ROOT/data/FDDB/images/ +``` + +2. Evaluate the trained model using: +```Shell +# dataset choices = ['AFW', 'PASCAL', 'FDDB'] +python3 test.py --dataset FDDB +# evaluate using cpu +python3 test.py --cpu +# visualize detection results +python3 test.py -s --vis_thres 0.3 +``` + +3. Download [eval_tool](https://github.com/sfzhang15/face-eval) to evaluate the performance. + +## References +- [Official release (Caffe)](https://github.com/sfzhang15/FaceBoxes) +- A huge thank you to SSD ports in PyTorch that have been helpful: + * [ssd.pytorch](https://github.com/amdegroot/ssd.pytorch), [RFBNet](https://github.com/ruinmessi/RFBNet) + + _Note: If you can not download the converted annotations, the provided images and the trained model through the above links, you can download them through [BaiduYun](https://pan.baidu.com/s/1HoW3wbldnbmgW2PS4i4Irw)._ diff --git a/PyTorch/contrib/cv/detection/GFocalV2/test/train_finetune_1p.sh b/PyTorch/contrib/cv/detection/GFocalV2/test/train_finetune_1p.sh index 68fe36b8b3753849b65b9e204523945bcc15f7e3..cc995eaca336a4c860b8cb7d76639d792a9a1a3e 100644 --- a/PyTorch/contrib/cv/detection/GFocalV2/test/train_finetune_1p.sh +++ b/PyTorch/contrib/cv/detection/GFocalV2/test/train_finetune_1p.sh @@ -1,136 +1,136 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` - -#集合通信参数,不需要修改 -export RANK_SIZE=1 - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#网络名称,同目录名称,需要模型审视修改 -Network="GFocal" - -#训练batch_size,,需要模型审视修改 -batch_size=8 -device_id=0 -checkpoint="./work_dirs/gfocal_r50_fpn_1x/latest.pth" -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --device_id* ]];then - device_id=`echo ${para#*=}` - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --checkpoint* ]];then - checkpoint=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#创建DeviceID输出目录,不需要修改 -if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID -fi - -#非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${cur_path}/test/env_npu.sh -fi - -#执行训练脚本,以下传参不需要修改,其他需要模型审视修改 -export NPUID=0 -export RANK=0 -python3.7 ./tools/train.py configs/gfocal/gfocal_r50_fpn_1x.py \ - --cfg-options \ - optimizer.lr=0.005 total_epochs=1 data_root=$data_path \ - --seed 0 \ - --gpu-ids 0 \ - --opt-level O1 \ - --checkpoint $checkpoint > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep -a 'FPS' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "FPS: " '{print $NF}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a 'bbox_mAP' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "bbox_mAP: " '{print $NF}'|awk -F "," '{print $1}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要模型审视修改 -grep Epoch: $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep eta:|awk -F "loss: " '{print $NF}' | awk -F "," '{print $1}' >> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` + +#集合通信参数,不需要修改 +export RANK_SIZE=1 + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#网络名称,同目录名称,需要模型审视修改 +Network="GFocal" + +#训练batch_size,,需要模型审视修改 +batch_size=8 +device_id=0 +checkpoint="./work_dirs/gfocal_r50_fpn_1x/latest.pth" +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --device_id* ]];then + device_id=`echo ${para#*=}` + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --checkpoint* ]];then + checkpoint=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#创建DeviceID输出目录,不需要修改 +if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID +fi + +#非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${cur_path}/test/env_npu.sh +fi + +#执行训练脚本,以下传参不需要修改,其他需要模型审视修改 +export NPUID=0 +export RANK=0 +python3.7 ./tools/train.py configs/gfocal/gfocal_r50_fpn_1x.py \ + --cfg-options \ + optimizer.lr=0.005 total_epochs=1 data_root=$data_path \ + --seed 0 \ + --gpu-ids 0 \ + --opt-level O1 \ + --checkpoint $checkpoint > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep -a 'FPS' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "FPS: " '{print $NF}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a 'bbox_mAP' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "bbox_mAP: " '{print $NF}'|awk -F "," '{print $1}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要模型审视修改 +grep Epoch: $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep eta:|awk -F "loss: " '{print $NF}' | awk -F "," '{print $1}' >> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/Pointnetplus/README.md b/PyTorch/contrib/cv/detection/Pointnetplus/README.md index 3885666ce38e368d980041a12c4651785e3eb03a..74370c2a9b07455b86db2458046ea1088db8fbf9 100644 --- a/PyTorch/contrib/cv/detection/Pointnetplus/README.md +++ b/PyTorch/contrib/cv/detection/Pointnetplus/README.md @@ -1,49 +1,49 @@ -# Pointnetplus - -This implements training of Pointnetplus on the ImageNet dataset, mainly modified from [pytorch/examples](https://github.com/yanx27/Pointnet_Pointnet2_pytorch). - -## Pointnetplus Detail - -As of the current date, Ascend-Pytorch is still inefficient for contiguous operations.Therefore, Pointnetplus is re-implemented using semantics such as custom OP. - - -## Requirements - -- Install PyTorch ([pytorch.org](http://pytorch.org)) -- `pip3 install -r requirements.txt` -- Download the ImageNet dataset from (https://shapenet.cs.stanford.edu/media/modelnet40_normal_resampled.zip) - -## Training - -To train a model, run `train_classification_xP.py` with the desired model architecture and the path to the ImageNet dataset: - then add [24,512,32,3],[24,1,128,259] transpose op to white list .pth is "/usr/local/Ascend/ascend-toolkit/latest/arm64-linux/opp/op_impl/built-in/ai_core/tbe/impl/dynamic/transpose.py" -```bash -# training 1p accuracy -bash ./test/train_full_1p.sh --data=real_data_path - -# training 1p performance -bash ./test/train_performance_1p.sh --data=real_data_path - -# training 8p accuracy -bash ./test/train_full_8p.sh --data=real_data_path - -# training 8p performance -bash ./test/train_performance_8p.sh --data=real_data_path - -# finetuning 1p -bash test/train_finetune_1p.sh --data=real_data_path --model_pth=real_pre_train_model_path -``` - -Log path: - test/output/devie_id/train_${ASCEND_DEVICE_ID}_${Network}.log # training detail log - test/output/devie_id/train_${ASCEND_DEVICE_ID}_${Network}.log # 8p training performance result log - test/output/devie_id/Pointnetplus_bs24_1p_acc.log # 8p training accuracy result log - - - -## WideResnet50_2 training result - -| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | -| :------: | :------: | :------: | :------: | :------: | -| - | 10.04 | 1 | 1 | O2 | +# Pointnetplus + +This implements training of Pointnetplus on the ImageNet dataset, mainly modified from [pytorch/examples](https://github.com/yanx27/Pointnet_Pointnet2_pytorch). + +## Pointnetplus Detail + +As of the current date, Ascend-Pytorch is still inefficient for contiguous operations.Therefore, Pointnetplus is re-implemented using semantics such as custom OP. + + +## Requirements + +- Install PyTorch ([pytorch.org](http://pytorch.org)) +- `pip3 install -r requirements.txt` +- Download the ImageNet dataset from (https://shapenet.cs.stanford.edu/media/modelnet40_normal_resampled.zip) + +## Training + +To train a model, run `train_classification_xP.py` with the desired model architecture and the path to the ImageNet dataset: + then add [24,512,32,3],[24,1,128,259] transpose op to white list .pth is "/usr/local/Ascend/ascend-toolkit/latest/arm64-linux/opp/op_impl/built-in/ai_core/tbe/impl/dynamic/transpose.py" +```bash +# training 1p accuracy +bash ./test/train_full_1p.sh --data=real_data_path + +# training 1p performance +bash ./test/train_performance_1p.sh --data=real_data_path + +# training 8p accuracy +bash ./test/train_full_8p.sh --data=real_data_path + +# training 8p performance +bash ./test/train_performance_8p.sh --data=real_data_path + +# finetuning 1p +bash test/train_finetune_1p.sh --data=real_data_path --model_pth=real_pre_train_model_path +``` + +Log path: + test/output/devie_id/train_${ASCEND_DEVICE_ID}_${Network}.log # training detail log + test/output/devie_id/train_${ASCEND_DEVICE_ID}_${Network}.log # 8p training performance result log + test/output/devie_id/Pointnetplus_bs24_1p_acc.log # 8p training accuracy result log + + + +## WideResnet50_2 training result + +| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | +| :------: | :------: | :------: | :------: | :------: | +| - | 10.04 | 1 | 1 | O2 | | 92.0 | 64.1 | 8 | 200 | O2 | \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/Pointnetplus/finetune.py b/PyTorch/contrib/cv/detection/Pointnetplus/finetune.py index d429106fc708e6ea8d138ac6ea334ec643334706..ade55c9fb235bc11f5431f5ec9343e3ca52b50bb 100644 --- a/PyTorch/contrib/cv/detection/Pointnetplus/finetune.py +++ b/PyTorch/contrib/cv/detection/Pointnetplus/finetune.py @@ -1,74 +1,74 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import torch -import numpy as np -import argparse -from tqdm import tqdm -import models.provider -from models.ModelNetDataLoader import ModelNetDataLoader -import models.pointnet2_cls_ssg as models - -def inplace_relu(m): - classname = m.__class__.__name__ - if classname.find('ReLU') != -1: - m.inplace=True - -def parse_args(): - '''PARAMETERS''' - parser = argparse.ArgumentParser('training') - parser.add_argument('--batch_size', type=int, default=24, help='batch size in training') - parser.add_argument('--num_category', default=40, type=int, choices=[10, 40], help='training on ModelNet10/40') - parser.add_argument('--epoch', default=2, type=int, help='number of epoch in training') - parser.add_argument('--num_points', type=int, default=1024, help='Point Number') - parser.add_argument('--use_normals', action='store_true', default=False, help='use normals') - parser.add_argument('--process_data', action='store_true', default=True, help='save data offline') - parser.add_argument('--use_uniform_sample', action='store_true', default=False, help='use uniform sampiling') - parser.add_argument('--device', type=str,default='cpu',help='which device to use') - parser.add_argument('--data',type=str, default='./modelnet40_normal_resampled', help='data_path') - parser.add_argument('--num_class',type=int,default=41,help='num of class') - parser.add_argument('--num_point', type=int, default=1024, help='Point Number') - parser.add_argument('--model_pth', type=str, default='./log/classification/pointnet2_cls_ssg/checkpoints/', help='Point Number') - parser.add_argument('--worker', type=int, default=1, help='number ofs workers') - - return parser.parse_args() - -def main(args): - test_dataset = ModelNetDataLoader(root=args.data, args=args, split='test', process_data=args.process_data) - testDataLoader = torch.utils.data.DataLoader(test_dataset, batch_size=args.batch_size, shuffle=False, num_workers=args.worker) - model_dict = torch.load(str(args.model_pth)+'best_model.pth', map_location='cpu')['model_state_dict'] - model_dict.pop('fc3.weight') - model_dict.pop('fc3.bias') - classifier = models.get_model(args.num_class, normal_channel=args.use_normals) - classifier.apply(inplace_relu) - if args.device !='cpu': - classifier = classifier.npu() - classifier.load_state_dict(model_dict, strict=False) - - for epoch in range(args.epoch): - for batch_id,(points, target) in tqdm(enumerate(testDataLoader, 0), total=len(testDataLoader)): - points = points.transpose(2, 1) - if args.device !='cpu': - points, target = points.npu(), target.npu() - pred, trans_feat = classifier(points) - pred_choice = pred.data.max(1)[1] - print("output class is",pred_choice) - -if __name__ == '__main__': - args = parse_args() - main(args) - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import torch +import numpy as np +import argparse +from tqdm import tqdm +import models.provider +from models.ModelNetDataLoader import ModelNetDataLoader +import models.pointnet2_cls_ssg as models + +def inplace_relu(m): + classname = m.__class__.__name__ + if classname.find('ReLU') != -1: + m.inplace=True + +def parse_args(): + '''PARAMETERS''' + parser = argparse.ArgumentParser('training') + parser.add_argument('--batch_size', type=int, default=24, help='batch size in training') + parser.add_argument('--num_category', default=40, type=int, choices=[10, 40], help='training on ModelNet10/40') + parser.add_argument('--epoch', default=2, type=int, help='number of epoch in training') + parser.add_argument('--num_points', type=int, default=1024, help='Point Number') + parser.add_argument('--use_normals', action='store_true', default=False, help='use normals') + parser.add_argument('--process_data', action='store_true', default=True, help='save data offline') + parser.add_argument('--use_uniform_sample', action='store_true', default=False, help='use uniform sampiling') + parser.add_argument('--device', type=str,default='cpu',help='which device to use') + parser.add_argument('--data',type=str, default='./modelnet40_normal_resampled', help='data_path') + parser.add_argument('--num_class',type=int,default=41,help='num of class') + parser.add_argument('--num_point', type=int, default=1024, help='Point Number') + parser.add_argument('--model_pth', type=str, default='./log/classification/pointnet2_cls_ssg/checkpoints/', help='Point Number') + parser.add_argument('--worker', type=int, default=1, help='number ofs workers') + + return parser.parse_args() + +def main(args): + test_dataset = ModelNetDataLoader(root=args.data, args=args, split='test', process_data=args.process_data) + testDataLoader = torch.utils.data.DataLoader(test_dataset, batch_size=args.batch_size, shuffle=False, num_workers=args.worker) + model_dict = torch.load(str(args.model_pth)+'best_model.pth', map_location='cpu')['model_state_dict'] + model_dict.pop('fc3.weight') + model_dict.pop('fc3.bias') + classifier = models.get_model(args.num_class, normal_channel=args.use_normals) + classifier.apply(inplace_relu) + if args.device !='cpu': + classifier = classifier.npu() + classifier.load_state_dict(model_dict, strict=False) + + for epoch in range(args.epoch): + for batch_id,(points, target) in tqdm(enumerate(testDataLoader, 0), total=len(testDataLoader)): + points = points.transpose(2, 1) + if args.device !='cpu': + points, target = points.npu(), target.npu() + pred, trans_feat = classifier(points) + pred_choice = pred.data.max(1)[1] + print("output class is",pred_choice) + +if __name__ == '__main__': + args = parse_args() + main(args) + + diff --git a/PyTorch/contrib/cv/detection/Pointnetplus/modelzoo_level.txt b/PyTorch/contrib/cv/detection/Pointnetplus/modelzoo_level.txt index dd917ea530560d786765ef72fa9d4c05b10a170e..08016761e0d79f535349f23e5caf5783de1deea4 100644 --- a/PyTorch/contrib/cv/detection/Pointnetplus/modelzoo_level.txt +++ b/PyTorch/contrib/cv/detection/Pointnetplus/modelzoo_level.txt @@ -1,5 +1,5 @@ -GPUStatus:OK -NPUMigrationStatus:OK -FuncStatus:OK -PrecisionStatus:OK +GPUStatus:OK +NPUMigrationStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:NOK \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/Pointnetplus/pointnetplus_pth2onnx.py b/PyTorch/contrib/cv/detection/Pointnetplus/pointnetplus_pth2onnx.py index bb92b279f8849a1865e791bc60a632c473db756f..4728535261abf781fb2c64b17a541e62015b5fad 100644 --- a/PyTorch/contrib/cv/detection/Pointnetplus/pointnetplus_pth2onnx.py +++ b/PyTorch/contrib/cv/detection/Pointnetplus/pointnetplus_pth2onnx.py @@ -1,104 +1,104 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from collections import OrderedDict -import torch -import torch.onnx -import argparse -import sys -sys.path.append('./models/models') -import pointnet2_cls_ssg as pointnet2_cls -from pointnet2_utils import farthest_point_sample -from pointnet2_utils import sample_and_group - - -def parse_args(): - '''PARAMETERS''' - parser = argparse.ArgumentParser('off_line_pred') - parser.add_argument('--target_model', type=int, default=1, - required=True, help='target trans_models') - parser.add_argument('--pth_dir', type=str, default='', - required=False, help='target trans_models') - parser.add_argument('--batch_size', type=int, default=1, - required=False, help='batch size') - return parser.parse_args() - - -def proc_node_module(checkpoint, AttrName): - new_state_dict = OrderedDict() - for k, v in checkpoint[AttrName].items(): - if k[0:7] == "module.": - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict - - -def model_convert(dir): - experiment_dir = dir - dummy_input = torch.randn(args.batch_size, 3, 1024) - checkpoint = torch.load(str(experiment_dir) + '/best_model.pth',map_location = 'cpu') - checkpoint['model_state_dict'] = proc_node_module(checkpoint,'model_state_dict') - model = pointnet2_cls.get_model_part1(normal_channel=False) - model.load_state_dict(checkpoint['model_state_dict']) - model.eval() - npoint = 512 - radius = 0.2 - nsample = 32 - points = None - test_input = dummy_input.permute(0, 2, 1) - centroid = farthest_point_sample(test_input, npoint) - new_xyz, new_points = sample_and_group(npoint, radius, nsample, test_input, points, centroid) - new_points = new_points.permute(0, 3, 2, 1) - input_names = ["xyz", "samp_points"] - output_names = ["l1_xyz", "l1_point"] - torch.onnx.export(model, (new_xyz, new_points), - "Pointnetplus_part1_bs{}.onnx".format(args.batch_size), - input_names=input_names, verbose=True, output_names=output_names, opset_version=11) - - -def model_convert2(dir): - experiment_dir = dir - dummy_xyz_input = torch.randn(args.batch_size, 3, 512) - dummy_point_input = torch.randn(args.batch_size, 128, 512) - checkpoint = torch.load(str(experiment_dir) + '/best_model.pth',map_location = 'cpu') - checkpoint['model_state_dict'] = proc_node_module(checkpoint,'model_state_dict') - model = pointnet2_cls.get_model_part2(normal_channel=False) - model.load_state_dict(checkpoint['model_state_dict']) - model.eval() - npoint = 128 - radius = 0.4 - nsample = 64 - points = None - test_input = dummy_xyz_input.permute(0, 2, 1) - test_points = dummy_point_input.permute(0, 2, 1) - centroid = farthest_point_sample(test_input, npoint) - new_xyz, new_points = sample_and_group(npoint, radius, nsample, test_input, test_points, centroid) - new_points = new_points.permute(0, 3, 2, 1) - new_xyz = new_xyz.permute(0, 2, 1) - input_names = ["l1_xyz", "l1_points"] - output_names = ["class", "l3_point"] - - torch.onnx.export(model, (new_xyz, new_points), - "Pointnetplus_part2_bs{}.onnx".format(args.batch_size), - input_names=input_names, verbose=True, output_names=output_names, opset_version=11) - - -if __name__ == '__main__': - args = parse_args() - if(args.target_model == 1): - model_convert(args.pth_dir) - else: - model_convert2(args.pth_dir) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from collections import OrderedDict +import torch +import torch.onnx +import argparse +import sys +sys.path.append('./models/models') +import pointnet2_cls_ssg as pointnet2_cls +from pointnet2_utils import farthest_point_sample +from pointnet2_utils import sample_and_group + + +def parse_args(): + '''PARAMETERS''' + parser = argparse.ArgumentParser('off_line_pred') + parser.add_argument('--target_model', type=int, default=1, + required=True, help='target trans_models') + parser.add_argument('--pth_dir', type=str, default='', + required=False, help='target trans_models') + parser.add_argument('--batch_size', type=int, default=1, + required=False, help='batch size') + return parser.parse_args() + + +def proc_node_module(checkpoint, AttrName): + new_state_dict = OrderedDict() + for k, v in checkpoint[AttrName].items(): + if k[0:7] == "module.": + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + + +def model_convert(dir): + experiment_dir = dir + dummy_input = torch.randn(args.batch_size, 3, 1024) + checkpoint = torch.load(str(experiment_dir) + '/best_model.pth',map_location = 'cpu') + checkpoint['model_state_dict'] = proc_node_module(checkpoint,'model_state_dict') + model = pointnet2_cls.get_model_part1(normal_channel=False) + model.load_state_dict(checkpoint['model_state_dict']) + model.eval() + npoint = 512 + radius = 0.2 + nsample = 32 + points = None + test_input = dummy_input.permute(0, 2, 1) + centroid = farthest_point_sample(test_input, npoint) + new_xyz, new_points = sample_and_group(npoint, radius, nsample, test_input, points, centroid) + new_points = new_points.permute(0, 3, 2, 1) + input_names = ["xyz", "samp_points"] + output_names = ["l1_xyz", "l1_point"] + torch.onnx.export(model, (new_xyz, new_points), + "Pointnetplus_part1_bs{}.onnx".format(args.batch_size), + input_names=input_names, verbose=True, output_names=output_names, opset_version=11) + + +def model_convert2(dir): + experiment_dir = dir + dummy_xyz_input = torch.randn(args.batch_size, 3, 512) + dummy_point_input = torch.randn(args.batch_size, 128, 512) + checkpoint = torch.load(str(experiment_dir) + '/best_model.pth',map_location = 'cpu') + checkpoint['model_state_dict'] = proc_node_module(checkpoint,'model_state_dict') + model = pointnet2_cls.get_model_part2(normal_channel=False) + model.load_state_dict(checkpoint['model_state_dict']) + model.eval() + npoint = 128 + radius = 0.4 + nsample = 64 + points = None + test_input = dummy_xyz_input.permute(0, 2, 1) + test_points = dummy_point_input.permute(0, 2, 1) + centroid = farthest_point_sample(test_input, npoint) + new_xyz, new_points = sample_and_group(npoint, radius, nsample, test_input, test_points, centroid) + new_points = new_points.permute(0, 3, 2, 1) + new_xyz = new_xyz.permute(0, 2, 1) + input_names = ["l1_xyz", "l1_points"] + output_names = ["class", "l3_point"] + + torch.onnx.export(model, (new_xyz, new_points), + "Pointnetplus_part2_bs{}.onnx".format(args.batch_size), + input_names=input_names, verbose=True, output_names=output_names, opset_version=11) + + +if __name__ == '__main__': + args = parse_args() + if(args.target_model == 1): + model_convert(args.pth_dir) + else: + model_convert2(args.pth_dir) diff --git a/PyTorch/contrib/cv/detection/Pointnetplus/requirements.txt b/PyTorch/contrib/cv/detection/Pointnetplus/requirements.txt index d9fdcd1a8753a518f8423fc1b0d7555d7aa2333e..309763d470004b757237e3a619fe97ba33408dc3 100644 --- a/PyTorch/contrib/cv/detection/Pointnetplus/requirements.txt +++ b/PyTorch/contrib/cv/detection/Pointnetplus/requirements.txt @@ -1,6 +1,6 @@ -apex -numpy==4.62.3 -torch==1.5.0 -torchvision==0.6.0 -onnx +apex +numpy==4.62.3 +torch==1.5.0 +torchvision==0.6.0 +onnx tqdm==4.62.3 \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/README.md b/PyTorch/contrib/cv/detection/Pyramidbox/README.md index d11beb2f2613928a41c9e894f6fed1a3c1c1918b..17b9e57acdfc1523505a5d65857c2b02a9914a92 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/README.md +++ b/PyTorch/contrib/cv/detection/Pyramidbox/README.md @@ -1,138 +1,138 @@ -## Pyramidbox - -​ A Context-assisted Single Shot Face Detector. - - - -### Requirements - -``` -根据requirements.txt安装依赖环境 -- Download the WIDER_FACE dataset from http://shuoyang1213.me/WIDERFACE/ -``` - - - -在代码仓下创建WIDER_FACE目录,存放数据集文件 - -``` -|-WIDER_FACE - |-wider_face_split - |-wider_face_test.mat - |-wider_face_test_filelist.txt - |-wider_face_train.mat - |-wider_face_train_bbx_gt.txt - |-wider_face_val.mat - |-wider_face_val_bbx_gt.txt - |-WIDER_train - |-images - |-0--Parade - |-1--Handshaking - ... - |-WIDER_val - |-images - |-0--Parade - |-1--Handshaking - ... -``` - - - -参照原代码仓README下载vgg权重,放在weights目录下 - -``` -|-Pyramidbox - |-weights - |-vgg16_reducedfc.pth -``` - - - -### prepare - -运行prepare_wider_data.py - -``` -python prepare_wider_data.py --data_path='数据集路径' -``` - - - -### Training - -单卡训练 - -``` -python train.py --batch_size=8 --lr=5e-4 -``` - -多卡训练 - -``` -python -m torch.distributed.launch --nproc_per_node=8 train.py --world_size=8 --batch_size=8 --lr=5e-4 --multinpu=True --device_list='0,1,2,3,4,5,6,7' -``` - - - -### Test - -在运行wider_test.py前,应先做以下修改: - -``` -1、修改第53行 -sys.path.append("/home/wch/Pyramidbox/") #根据代码仓实际所在位置进行修改 -``` - -修改后,运行wider_test.py - -``` -python tools/wider_test.py --model="/home/wch/Pyramidbox/weights/pyramidbox.pth" --data_path='数据集路径' -#model参数根据模型权重文件保存位置进行修改 -``` - -运行以下脚本,评估精度 - -``` -cd evaluate -python setup.py build_ext --inplace -python evaluation.py --pred ../output/pyramidbox1_val/ --gt '数据集路径/wider_face_split' -``` - - - -### 启动脚本 - -8卡训练,并显示性能和精度 - -``` -bash ./test/train_full_8p.sh --data_path='数据集路径' -``` - -测试单卡训练性能 - -``` -bash ./test/train_performance_1p.sh --data_path='数据集路径' -``` - -测试多卡训练性能 - -``` -bash ./test/train_performance_8p.sh --data_path='数据集路径' -``` - -模型迁移脚本,注意脚本中的resume参数只能指定为保存的“pyramidbox_checkpoint.pth”权重 - -``` -bash ./test/train_finetune_1p.sh --data_path='数据集路径' -``` - -精度数据 - -``` -==================== Results ==================== -Easy Val AP: 0.9519612346942784 -Medium Val AP: 0.9446576258551937 -Hard Val AP: 0.9053749943031708 -================================================= -``` - +## Pyramidbox + +​ A Context-assisted Single Shot Face Detector. + + + +### Requirements + +``` +根据requirements.txt安装依赖环境 +- Download the WIDER_FACE dataset from http://shuoyang1213.me/WIDERFACE/ +``` + + + +在代码仓下创建WIDER_FACE目录,存放数据集文件 + +``` +|-WIDER_FACE + |-wider_face_split + |-wider_face_test.mat + |-wider_face_test_filelist.txt + |-wider_face_train.mat + |-wider_face_train_bbx_gt.txt + |-wider_face_val.mat + |-wider_face_val_bbx_gt.txt + |-WIDER_train + |-images + |-0--Parade + |-1--Handshaking + ... + |-WIDER_val + |-images + |-0--Parade + |-1--Handshaking + ... +``` + + + +参照原代码仓README下载vgg权重,放在weights目录下 + +``` +|-Pyramidbox + |-weights + |-vgg16_reducedfc.pth +``` + + + +### prepare + +运行prepare_wider_data.py + +``` +python prepare_wider_data.py --data_path='数据集路径' +``` + + + +### Training + +单卡训练 + +``` +python train.py --batch_size=8 --lr=5e-4 +``` + +多卡训练 + +``` +python -m torch.distributed.launch --nproc_per_node=8 train.py --world_size=8 --batch_size=8 --lr=5e-4 --multinpu=True --device_list='0,1,2,3,4,5,6,7' +``` + + + +### Test + +在运行wider_test.py前,应先做以下修改: + +``` +1、修改第53行 +sys.path.append("/home/wch/Pyramidbox/") #根据代码仓实际所在位置进行修改 +``` + +修改后,运行wider_test.py + +``` +python tools/wider_test.py --model="/home/wch/Pyramidbox/weights/pyramidbox.pth" --data_path='数据集路径' +#model参数根据模型权重文件保存位置进行修改 +``` + +运行以下脚本,评估精度 + +``` +cd evaluate +python setup.py build_ext --inplace +python evaluation.py --pred ../output/pyramidbox1_val/ --gt '数据集路径/wider_face_split' +``` + + + +### 启动脚本 + +8卡训练,并显示性能和精度 + +``` +bash ./test/train_full_8p.sh --data_path='数据集路径' +``` + +测试单卡训练性能 + +``` +bash ./test/train_performance_1p.sh --data_path='数据集路径' +``` + +测试多卡训练性能 + +``` +bash ./test/train_performance_8p.sh --data_path='数据集路径' +``` + +模型迁移脚本,注意脚本中的resume参数只能指定为保存的“pyramidbox_checkpoint.pth”权重 + +``` +bash ./test/train_finetune_1p.sh --data_path='数据集路径' +``` + +精度数据 + +``` +==================== Results ==================== +Easy Val AP: 0.9519612346942784 +Medium Val AP: 0.9446576258551937 +Hard Val AP: 0.9053749943031708 +================================================= +``` + diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/README_raw.md b/PyTorch/contrib/cv/detection/Pyramidbox/README_raw.md index 9adcd839ae7bbd38696d2b0c875528e59362f1b4..94496c1511e40a88c3f8da3f61d9b8855f40577e 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/README_raw.md +++ b/PyTorch/contrib/cv/detection/Pyramidbox/README_raw.md @@ -1,72 +1,72 @@ -## PyramidBox: A Context-assisted Single Shot Face Detector.## -[A PyTorch Implementation of PyramidBox](https://arxiv.org/abs/1803.07737) - - -### Description -I train pyramidbox with pytorch and the result approaches the original paper result,the pretrained model can be downloaded in [vgg](https://pan.baidu.com/s/1Q-YqoxJyqvln6KTcIck1tQ),the final model can be downloaded in [Pyramidbox](https://pan.baidu.com/s/1VtzgB9srkJY4SUtVM3n8tw).the AP in WIDER FACE as following: - -| | Easy MAP | Medium MAP | hard MAP | -| -------- | ---------|------------| --------- | -| origin paper| 0.960 | 0.948 | 0.888 | -| this repo | 0.948 | 0.938 | 0.880 | - -the AP in AFW,PASCAL,FDDB as following: - -| AFW | PASCAL | FDDB | -| --------- |-----------| ---------| -| 99.65 | 99.02 | 0.983 | - -the gap is small with origin paper,I train 120k batch_size 4 which is different from paper,which maybe cause the gap,if you have more gpu ,the final result maybe better. - -### Requirement -* pytorch 0.3 -* opencv -* numpy -* easydict - -### Prepare data -1. download WIDER face dataset -2. modify data/config.py -3. ``` python prepare_wider_data.py``` - - -### Train -``` -python train.py --batch_size 4 - --lr 5e-4 -``` - -### Evalution -according to yourself dataset path,modify data/config.py -1. Evaluate on AFW. -``` -python tools/afw_test.py -``` -2. Evaluate on FDDB -``` -python tools/fddb_test.py -``` -3. Evaluate on PASCAL face -``` -python tools/pascal_test.py -``` -4. test on WIDER FACE -``` -python tools/wider_test.py -``` -### Demo -you can test yourself image -``` -python demo.py -``` - -### Result -
-demo -demo -
- -### References -* [PyramidBox: A Context-assisted Single Shot Face Detector](https://arxiv.org/abs/1803.07737) -* [PyramidBox model](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/face_detection) -* [ssd.pytorch](https://github.com/amdegroot/ssd.pytorch) +## PyramidBox: A Context-assisted Single Shot Face Detector.## +[A PyTorch Implementation of PyramidBox](https://arxiv.org/abs/1803.07737) + + +### Description +I train pyramidbox with pytorch and the result approaches the original paper result,the pretrained model can be downloaded in [vgg](https://pan.baidu.com/s/1Q-YqoxJyqvln6KTcIck1tQ),the final model can be downloaded in [Pyramidbox](https://pan.baidu.com/s/1VtzgB9srkJY4SUtVM3n8tw).the AP in WIDER FACE as following: + +| | Easy MAP | Medium MAP | hard MAP | +| -------- | ---------|------------| --------- | +| origin paper| 0.960 | 0.948 | 0.888 | +| this repo | 0.948 | 0.938 | 0.880 | + +the AP in AFW,PASCAL,FDDB as following: + +| AFW | PASCAL | FDDB | +| --------- |-----------| ---------| +| 99.65 | 99.02 | 0.983 | + +the gap is small with origin paper,I train 120k batch_size 4 which is different from paper,which maybe cause the gap,if you have more gpu ,the final result maybe better. + +### Requirement +* pytorch 0.3 +* opencv +* numpy +* easydict + +### Prepare data +1. download WIDER face dataset +2. modify data/config.py +3. ``` python prepare_wider_data.py``` + + +### Train +``` +python train.py --batch_size 4 + --lr 5e-4 +``` + +### Evalution +according to yourself dataset path,modify data/config.py +1. Evaluate on AFW. +``` +python tools/afw_test.py +``` +2. Evaluate on FDDB +``` +python tools/fddb_test.py +``` +3. Evaluate on PASCAL face +``` +python tools/pascal_test.py +``` +4. test on WIDER FACE +``` +python tools/wider_test.py +``` +### Demo +you can test yourself image +``` +python demo.py +``` + +### Result +
+demo +demo +
+ +### References +* [PyramidBox: A Context-assisted Single Shot Face Detector](https://arxiv.org/abs/1803.07737) +* [PyramidBox model](https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/face_detection) +* [ssd.pytorch](https://github.com/amdegroot/ssd.pytorch) diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/data/config.py b/PyTorch/contrib/cv/detection/Pyramidbox/data/config.py index 10a42e3329ac64db39fca5aebee792fab019f2f6..5cead837e5760bcb9ea1acb480febb4bce2a894f 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/data/config.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/data/config.py @@ -1,87 +1,87 @@ -#-*- coding:utf-8 -*- -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - -import os -from easydict import EasyDict -import numpy as np - - -_C = EasyDict() -cfg = _C -# data augument config -_C.expand_prob = 0.5 -_C.expand_max_ratio = 4 -_C.hue_prob = 0.5 -_C.hue_delta = 18 -_C.contrast_prob = 0.5 -_C.contrast_delta = 0.5 -_C.saturation_prob = 0.5 -_C.saturation_delta = 0.5 -_C.brightness_prob = 0.5 -_C.brightness_delta = 0.125 -_C.data_anchor_sampling_prob = 0.5 -_C.min_face_size = 6.0 -_C.apply_distort = True -_C.apply_expand = False -_C.img_mean = np.array([104., 117., 123.])[:, np.newaxis, np.newaxis].astype( - 'float32') -_C.resize_width = 640 -_C.resize_height = 640 -_C.scale = 1 / 127.0 -_C.anchor_sampling = True -_C.filter_min_face = True - -# train config -_C.LR_STEPS = (80000,100000,120000) -_C.MAX_STEPS = 150000 -_C.EPOCHES = 100 - -# anchor config -_C.FEATURE_MAPS = [160, 80, 40, 20, 10, 5] -_C.INPUT_SIZE = 640 -_C.STEPS = [4, 8, 16, 32, 64, 128] -_C.ANCHOR_SIZES = [16, 32, 64, 128, 256, 512] -_C.CLIP = False -_C.VARIANCE = [0.1, 0.2] - -# loss config -_C.NUM_CLASSES = 2 -_C.OVERLAP_THRESH = 0.35 -_C.NEG_POS_RATIOS = 3 - - -# detection config -_C.NMS_THRESH = 0.3 -_C.TOP_K = 5000 -_C.KEEP_TOP_K = 750 -_C.CONF_THRESH = 0.05 - - -# dataset config -#_C.HOME = '/home/wch/Pyramidbox/' - -# face config -_C.FACE = EasyDict() -_C.FACE.TRAIN_FILE = 'data/face_train.txt' -_C.FACE.VAL_FILE = 'data/face_val.txt' -_C.FACE.FDDB_DIR = '/home/data/lj/FDDB' -_C.FACE.WIDER_DIR = '/home/wch/Pyramidbox/WIDER_FACE/' -_C.FACE.AFW_DIR = '/home/data/lj/AFW' -_C.FACE.PASCAL_DIR = '/home/data/lj/PASCAL_FACE' -_C.FACE.OVERLAP_THRESH = 0.35 - +#-*- coding:utf-8 -*- +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + +import os +from easydict import EasyDict +import numpy as np + + +_C = EasyDict() +cfg = _C +# data augument config +_C.expand_prob = 0.5 +_C.expand_max_ratio = 4 +_C.hue_prob = 0.5 +_C.hue_delta = 18 +_C.contrast_prob = 0.5 +_C.contrast_delta = 0.5 +_C.saturation_prob = 0.5 +_C.saturation_delta = 0.5 +_C.brightness_prob = 0.5 +_C.brightness_delta = 0.125 +_C.data_anchor_sampling_prob = 0.5 +_C.min_face_size = 6.0 +_C.apply_distort = True +_C.apply_expand = False +_C.img_mean = np.array([104., 117., 123.])[:, np.newaxis, np.newaxis].astype( + 'float32') +_C.resize_width = 640 +_C.resize_height = 640 +_C.scale = 1 / 127.0 +_C.anchor_sampling = True +_C.filter_min_face = True + +# train config +_C.LR_STEPS = (80000,100000,120000) +_C.MAX_STEPS = 150000 +_C.EPOCHES = 100 + +# anchor config +_C.FEATURE_MAPS = [160, 80, 40, 20, 10, 5] +_C.INPUT_SIZE = 640 +_C.STEPS = [4, 8, 16, 32, 64, 128] +_C.ANCHOR_SIZES = [16, 32, 64, 128, 256, 512] +_C.CLIP = False +_C.VARIANCE = [0.1, 0.2] + +# loss config +_C.NUM_CLASSES = 2 +_C.OVERLAP_THRESH = 0.35 +_C.NEG_POS_RATIOS = 3 + + +# detection config +_C.NMS_THRESH = 0.3 +_C.TOP_K = 5000 +_C.KEEP_TOP_K = 750 +_C.CONF_THRESH = 0.05 + + +# dataset config +#_C.HOME = '/home/wch/Pyramidbox/' + +# face config +_C.FACE = EasyDict() +_C.FACE.TRAIN_FILE = 'data/face_train.txt' +_C.FACE.VAL_FILE = 'data/face_val.txt' +_C.FACE.FDDB_DIR = '/home/data/lj/FDDB' +_C.FACE.WIDER_DIR = '/home/wch/Pyramidbox/WIDER_FACE/' +_C.FACE.AFW_DIR = '/home/data/lj/AFW' +_C.FACE.PASCAL_DIR = '/home/data/lj/PASCAL_FACE' +_C.FACE.OVERLAP_THRESH = 0.35 + diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/data/widerface.py b/PyTorch/contrib/cv/detection/Pyramidbox/data/widerface.py index 5b6b67835f65f8202d613dbf2f6897b66dc46cfa..e81a461df6cf845db9bf191376035e3a3749a23c 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/data/widerface.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/data/widerface.py @@ -1,172 +1,172 @@ -#-*- coding:utf-8 -*- -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import torch -from PIL import Image, ImageDraw -import torch.utils.data as data -import numpy as np -import random -from utils.augmentations import preprocess - - -class WIDERDetection(data.Dataset): - """docstring for WIDERDetection""" - - def __init__(self, list_file, mode='train'): - super(WIDERDetection, self).__init__() - self.mode = mode - self.fnames = [] - self.boxes = [] - self.labels = [] - - with open(list_file) as f: - lines = f.readlines() - - for line in lines: - line = line.strip().split() - num_faces = int(line[1]) - box = [] - label = [] - for i in range(num_faces): - x = float(line[2 + 5 * i]) - y = float(line[3 + 5 * i]) - w = float(line[4 + 5 * i]) - h = float(line[5 + 5 * i]) - c = int(line[6 + 5 * i]) - if w <= 0 or h <= 0: - continue - box.append([x, y, x + w, y + h]) - label.append(c) - if len(box) > 0: - self.fnames.append(line[0]) - self.boxes.append(box) - self.labels.append(label) - - self.num_samples = len(self.boxes) - - def __len__(self): - return self.num_samples - - def __getitem__(self, index): - img, face_target,head_target = self.pull_item(index) - return img, face_target,head_target - - def pull_item(self, index): - while True: - image_path = self.fnames[index] - img = Image.open(image_path) - if img.mode == 'L': - img = img.convert('RGB') - - im_width, im_height = img.size - boxes = self.annotransform( - np.array(self.boxes[index]), im_width, im_height) - label = np.array(self.labels[index]) - bbox_labels = np.hstack((label[:, np.newaxis], boxes)).tolist() - img, sample_labels = preprocess( - img, bbox_labels, self.mode, image_path) - sample_labels = np.array(sample_labels) - if len(sample_labels) > 0: - face_target = np.hstack( - (sample_labels[:, 1:], sample_labels[:, 0][:, np.newaxis])) - - assert (face_target[:, 2] > face_target[:, 0]).any() - assert (face_target[:, 3] > face_target[:, 1]).any() - - #img = img.astype(np.float32) - face_box = face_target[:, :-1] - head_box = self.expand_bboxes(face_box) - head_target = np.hstack((head_box, face_target[ - :, -1][:, np.newaxis])) - break - else: - index = random.randrange(0, self.num_samples) - - - #img = Image.fromarray(img) - ''' - draw = ImageDraw.Draw(img) - w,h = img.size - for bbox in sample_labels: - bbox = (bbox[1:] * np.array([w, h, w, h])).tolist() - - draw.rectangle(bbox,outline='red') - img.save('image.jpg') - ''' - return torch.from_numpy(img), face_target, head_target - - - def annotransform(self, boxes, im_width, im_height): - boxes[:, 0] /= im_width - boxes[:, 1] /= im_height - boxes[:, 2] /= im_width - boxes[:, 3] /= im_height - return boxes - - def expand_bboxes(self, - bboxes, - expand_left=2., - expand_up=2., - expand_right=2., - expand_down=2.): - expand_bboxes = [] - for bbox in bboxes: - xmin = bbox[0] - ymin = bbox[1] - xmax = bbox[2] - ymax = bbox[3] - w = xmax - xmin - h = ymax - ymin - ex_xmin = max(xmin - w / expand_left, 0.) - ex_ymin = max(ymin - h / expand_up, 0.) - ex_xmax = max(xmax + w / expand_right, 0.) - ex_ymax = max(ymax + h / expand_down, 0.) - expand_bboxes.append([ex_xmin, ex_ymin, ex_xmax, ex_ymax]) - expand_bboxes = np.array(expand_bboxes) - return expand_bboxes - -def detection_collate(batch): - """Custom collate fn for dealing with batches of images that have a different - number of associated object annotations (bounding boxes). - - Arguments: - batch: (tuple) A tuple of tensor images and lists of annotations - - Return: - A tuple containing: - 1) (tensor) batch of images stacked on their 0 dim - 2) (list of tensors) annotations for a given image are stacked on - 0 dim - """ - face_targets = [] - head_targets = [] - - imgs = [] - for sample in batch: - imgs.append(sample[0]) - face_targets.append(torch.FloatTensor(sample[1])) - head_targets.append(torch.FloatTensor(sample[2])) - return torch.stack(imgs, 0), face_targets,head_targets - - - -if __name__ == '__main__': - from config import cfg - dataset = WIDERDetection(cfg.FACE.TRAIN_FILE) - #for i in range(len(dataset)): - dataset.pull_item(14) +#-*- coding:utf-8 -*- +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import torch +from PIL import Image, ImageDraw +import torch.utils.data as data +import numpy as np +import random +from utils.augmentations import preprocess + + +class WIDERDetection(data.Dataset): + """docstring for WIDERDetection""" + + def __init__(self, list_file, mode='train'): + super(WIDERDetection, self).__init__() + self.mode = mode + self.fnames = [] + self.boxes = [] + self.labels = [] + + with open(list_file) as f: + lines = f.readlines() + + for line in lines: + line = line.strip().split() + num_faces = int(line[1]) + box = [] + label = [] + for i in range(num_faces): + x = float(line[2 + 5 * i]) + y = float(line[3 + 5 * i]) + w = float(line[4 + 5 * i]) + h = float(line[5 + 5 * i]) + c = int(line[6 + 5 * i]) + if w <= 0 or h <= 0: + continue + box.append([x, y, x + w, y + h]) + label.append(c) + if len(box) > 0: + self.fnames.append(line[0]) + self.boxes.append(box) + self.labels.append(label) + + self.num_samples = len(self.boxes) + + def __len__(self): + return self.num_samples + + def __getitem__(self, index): + img, face_target,head_target = self.pull_item(index) + return img, face_target,head_target + + def pull_item(self, index): + while True: + image_path = self.fnames[index] + img = Image.open(image_path) + if img.mode == 'L': + img = img.convert('RGB') + + im_width, im_height = img.size + boxes = self.annotransform( + np.array(self.boxes[index]), im_width, im_height) + label = np.array(self.labels[index]) + bbox_labels = np.hstack((label[:, np.newaxis], boxes)).tolist() + img, sample_labels = preprocess( + img, bbox_labels, self.mode, image_path) + sample_labels = np.array(sample_labels) + if len(sample_labels) > 0: + face_target = np.hstack( + (sample_labels[:, 1:], sample_labels[:, 0][:, np.newaxis])) + + assert (face_target[:, 2] > face_target[:, 0]).any() + assert (face_target[:, 3] > face_target[:, 1]).any() + + #img = img.astype(np.float32) + face_box = face_target[:, :-1] + head_box = self.expand_bboxes(face_box) + head_target = np.hstack((head_box, face_target[ + :, -1][:, np.newaxis])) + break + else: + index = random.randrange(0, self.num_samples) + + + #img = Image.fromarray(img) + ''' + draw = ImageDraw.Draw(img) + w,h = img.size + for bbox in sample_labels: + bbox = (bbox[1:] * np.array([w, h, w, h])).tolist() + + draw.rectangle(bbox,outline='red') + img.save('image.jpg') + ''' + return torch.from_numpy(img), face_target, head_target + + + def annotransform(self, boxes, im_width, im_height): + boxes[:, 0] /= im_width + boxes[:, 1] /= im_height + boxes[:, 2] /= im_width + boxes[:, 3] /= im_height + return boxes + + def expand_bboxes(self, + bboxes, + expand_left=2., + expand_up=2., + expand_right=2., + expand_down=2.): + expand_bboxes = [] + for bbox in bboxes: + xmin = bbox[0] + ymin = bbox[1] + xmax = bbox[2] + ymax = bbox[3] + w = xmax - xmin + h = ymax - ymin + ex_xmin = max(xmin - w / expand_left, 0.) + ex_ymin = max(ymin - h / expand_up, 0.) + ex_xmax = max(xmax + w / expand_right, 0.) + ex_ymax = max(ymax + h / expand_down, 0.) + expand_bboxes.append([ex_xmin, ex_ymin, ex_xmax, ex_ymax]) + expand_bboxes = np.array(expand_bboxes) + return expand_bboxes + +def detection_collate(batch): + """Custom collate fn for dealing with batches of images that have a different + number of associated object annotations (bounding boxes). + + Arguments: + batch: (tuple) A tuple of tensor images and lists of annotations + + Return: + A tuple containing: + 1) (tensor) batch of images stacked on their 0 dim + 2) (list of tensors) annotations for a given image are stacked on + 0 dim + """ + face_targets = [] + head_targets = [] + + imgs = [] + for sample in batch: + imgs.append(sample[0]) + face_targets.append(torch.FloatTensor(sample[1])) + head_targets.append(torch.FloatTensor(sample[2])) + return torch.stack(imgs, 0), face_targets,head_targets + + + +if __name__ == '__main__': + from config import cfg + dataset = WIDERDetection(cfg.FACE.TRAIN_FILE) + #for i in range(len(dataset)): + dataset.pull_item(14) diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/demo.py b/PyTorch/contrib/cv/detection/Pyramidbox/demo.py index 53ee7dbbd64a70c25f504e138cfd0ff8821e12fc..44a9271b12266d07da5ae6ded8b60591b64d04f4 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/demo.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/demo.py @@ -1,141 +1,141 @@ -#-*- coding:utf-8 -*- -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - - -import os -import argparse -import torch -import torch.nn as nn -import torch.backends.cudnn as cudnn -from torch.autograd import Variable - -import torch.npu -import cv2 -import time -import numpy as np -from PIL import Image - -from data.config import cfg -from pyramidbox import build_net -from utils.augmentations import to_chw_bgr - -parser = argparse.ArgumentParser(description='pyramidbox demo') -parser.add_argument('--save_dir', - type=str, default='tmp/', - help='Directory for detect result') -parser.add_argument('--model', - type=str, default='/home/wch/Pyramidbox.pytorch-master/weights/pyramidbox_120000_99.02.pth', - help='trained model') -parser.add_argument('--thresh', - default=0.4, type=float, - help='Final confidence threshold') -args = parser.parse_args() - - -if not os.path.exists(args.save_dir): - os.makedirs(args.save_dir) - -use_npu = torch.npu.is_available() - -if use_npu: - device=f'npu:0' - torch.npu.set_device(device) - - -def detect(net, img_path, thresh): - img = Image.open(img_path) - if img.mode == 'L': - img = img.convert('RGB') - - img = np.array(img) - height, width, _ = img.shape - max_im_shrink = np.sqrt( - 1200 * 1100 / (img.shape[0] * img.shape[1])) - image = cv2.resize(img, None, None, fx=max_im_shrink, - fy=max_im_shrink, interpolation=cv2.INTER_LINEAR) - - x = to_chw_bgr(image) - x = x.astype('float32') - x -= cfg.img_mean - x = x[[2, 1, 0], :, :] - #x = x * cfg.scale - - x = Variable(torch.from_numpy(x).unsqueeze(0)) - if use_npu: - x = x.npu() - t1 = time.time() - y = net(x) - detections = y.data - scale = torch.Tensor([img.shape[1], img.shape[0], - img.shape[1], img.shape[0]]) - - for i in range(detections.size(1)): - j = 0 - while detections[0, i, j, 0] >= thresh: - score = detections[0, i, j, 0] - pt = (detections[0, i, j, 1:] * scale).cpu().numpy().astype(int) - left_up, right_bottom = (pt[0], pt[1]), (pt[2], pt[3]) - j += 1 - cv2.rectangle(img, left_up, right_bottom, (0, 0, 255), 2) - conf = "{:.2f}".format(score) - text_size, baseline = cv2.getTextSize( - conf, cv2.FONT_HERSHEY_SIMPLEX, 0.3, 1) - p1 = (left_up[0], left_up[1] - text_size[1]) - cv2.rectangle(img, (p1[0] - 2 // 2, p1[1] - 2 - baseline), - (p1[0] + text_size[0], p1[1] + text_size[1]), [255, 0, 0], -1) - cv2.putText(img, conf, (p1[0], p1[ - 1] + baseline), cv2.FONT_HERSHEY_SIMPLEX, 0.3, (255, 255, 255), 1, 8) - - t2 = time.time() - print('detect:{} timer:{}'.format(img_path, t2 - t1)) - - cv2.imwrite(os.path.join(args.save_dir, os.path.basename(img_path)), img) - - -if __name__ == '__main__': - net = build_net('test', cfg.NUM_CLASSES) - net.load_state_dict(torch.load(args.model,map_location=lambda storage, loc: storage)) - net.eval() - - if use_npu: - net.npu() - cudnn.benckmark = True - - img_path = './img' - img_list = [os.path.join(img_path, x) - for x in os.listdir(img_path) if x.endswith('jpg')] - for path in img_list: - detect(net, path, args.thresh) +#-*- coding:utf-8 -*- +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + + +import os +import argparse +import torch +import torch.nn as nn +import torch.backends.cudnn as cudnn +from torch.autograd import Variable + +import torch.npu +import cv2 +import time +import numpy as np +from PIL import Image + +from data.config import cfg +from pyramidbox import build_net +from utils.augmentations import to_chw_bgr + +parser = argparse.ArgumentParser(description='pyramidbox demo') +parser.add_argument('--save_dir', + type=str, default='tmp/', + help='Directory for detect result') +parser.add_argument('--model', + type=str, default='/home/wch/Pyramidbox.pytorch-master/weights/pyramidbox_120000_99.02.pth', + help='trained model') +parser.add_argument('--thresh', + default=0.4, type=float, + help='Final confidence threshold') +args = parser.parse_args() + + +if not os.path.exists(args.save_dir): + os.makedirs(args.save_dir) + +use_npu = torch.npu.is_available() + +if use_npu: + device=f'npu:0' + torch.npu.set_device(device) + + +def detect(net, img_path, thresh): + img = Image.open(img_path) + if img.mode == 'L': + img = img.convert('RGB') + + img = np.array(img) + height, width, _ = img.shape + max_im_shrink = np.sqrt( + 1200 * 1100 / (img.shape[0] * img.shape[1])) + image = cv2.resize(img, None, None, fx=max_im_shrink, + fy=max_im_shrink, interpolation=cv2.INTER_LINEAR) + + x = to_chw_bgr(image) + x = x.astype('float32') + x -= cfg.img_mean + x = x[[2, 1, 0], :, :] + #x = x * cfg.scale + + x = Variable(torch.from_numpy(x).unsqueeze(0)) + if use_npu: + x = x.npu() + t1 = time.time() + y = net(x) + detections = y.data + scale = torch.Tensor([img.shape[1], img.shape[0], + img.shape[1], img.shape[0]]) + + for i in range(detections.size(1)): + j = 0 + while detections[0, i, j, 0] >= thresh: + score = detections[0, i, j, 0] + pt = (detections[0, i, j, 1:] * scale).cpu().numpy().astype(int) + left_up, right_bottom = (pt[0], pt[1]), (pt[2], pt[3]) + j += 1 + cv2.rectangle(img, left_up, right_bottom, (0, 0, 255), 2) + conf = "{:.2f}".format(score) + text_size, baseline = cv2.getTextSize( + conf, cv2.FONT_HERSHEY_SIMPLEX, 0.3, 1) + p1 = (left_up[0], left_up[1] - text_size[1]) + cv2.rectangle(img, (p1[0] - 2 // 2, p1[1] - 2 - baseline), + (p1[0] + text_size[0], p1[1] + text_size[1]), [255, 0, 0], -1) + cv2.putText(img, conf, (p1[0], p1[ + 1] + baseline), cv2.FONT_HERSHEY_SIMPLEX, 0.3, (255, 255, 255), 1, 8) + + t2 = time.time() + print('detect:{} timer:{}'.format(img_path, t2 - t1)) + + cv2.imwrite(os.path.join(args.save_dir, os.path.basename(img_path)), img) + + +if __name__ == '__main__': + net = build_net('test', cfg.NUM_CLASSES) + net.load_state_dict(torch.load(args.model,map_location=lambda storage, loc: storage)) + net.eval() + + if use_npu: + net.npu() + cudnn.benckmark = True + + img_path = './img' + img_list = [os.path.join(img_path, x) + for x in os.listdir(img_path) if x.endswith('jpg')] + for path in img_list: + detect(net, path, args.thresh) diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/layers/__init__.py b/PyTorch/contrib/cv/detection/Pyramidbox/layers/__init__.py index 1c1dae6697759d04d081f0430b13b014fca73da1..f58076f3a350eb20c90909108b22a3f78f3e400f 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/layers/__init__.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/layers/__init__.py @@ -1,9 +1,9 @@ -#-*- coding:utf-8 -*- - -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - - -from .functions import * -from .modules import * +#-*- coding:utf-8 -*- + +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + + +from .functions import * +from .modules import * diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/layers/bbox_utils.py b/PyTorch/contrib/cv/detection/Pyramidbox/layers/bbox_utils.py index 6381fc9ea2928f0b771db757117a95bb0c158f6f..fb7a1987be428f2fabac8fcd96fdc1a2ea2d16a0 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/layers/bbox_utils.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/layers/bbox_utils.py @@ -1,339 +1,339 @@ -#-*- coding:utf-8 -*- -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - - -import torch -import torch.npu - -def point_form(boxes): - """ Convert prior_boxes to (xmin, ymin, xmax, ymax) - representation for comparison to point form ground truth data. - Args: - boxes: (tensor) center-size default boxes from priorbox layers. - Return: - boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes. - """ - return torch.cat((boxes[:, :2] - boxes[:, 2:] / 2, # xmin, ymin - boxes[:, :2] + boxes[:, 2:] / 2), 1) # xmax, ymax - - -def center_size(boxes): - """ Convert prior_boxes to (cx, cy, w, h) - representation for comparison to center-size form ground truth data. - Args: - boxes: (tensor) point_form boxes - Return: - boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes. - """ - return torch.cat([(boxes[:, 2:] + boxes[:, :2]) / 2, # cx, cy - boxes[:, 2:] - boxes[:, :2]], 1) # w, h - - -def intersect(box_a, box_b): - """ We resize both tensors to [A,B,2] without new malloc: - [A,2] -> [A,1,2] -> [A,B,2] - [B,2] -> [1,B,2] -> [A,B,2] - Then we compute the area of intersect between box_a and box_b. - Args: - box_a: (tensor) bounding boxes, Shape: [A,4]. - box_b: (tensor) bounding boxes, Shape: [B,4]. - Return: - (tensor) intersection area, Shape: [A,B]. - """ - A = box_a.size(0) - B = box_b.size(0) - max_xy = torch.min(box_a[:, 2:].unsqueeze(1).expand(A, B, 2), - box_b[:, 2:].unsqueeze(0).expand(A, B, 2)) - min_xy = torch.max(box_a[:, :2].unsqueeze(1).expand(A, B, 2), - box_b[:, :2].unsqueeze(0).expand(A, B, 2)) - inter = torch.clamp((max_xy - min_xy), min=0) - return inter[:, :, 0] * inter[:, :, 1] - - -def jaccard(box_a, box_b): - """Compute the jaccard overlap of two sets of boxes. The jaccard overlap - is simply the intersection over union of two boxes. Here we operate on - ground truth boxes and default boxes. - E.g.: - A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) - Args: - box_a: (tensor) Ground truth bounding boxes, Shape: [num_objects,4] - box_b: (tensor) Prior boxes from priorbox layers, Shape: [num_priors,4] - Return: - jaccard overlap: (tensor) Shape: [box_a.size(0), box_b.size(0)] - """ - #when run in npu ,box_b is still in cpu - #box_b = box_b.npu() - inter = intersect(box_a, box_b) - area_a = ((box_a[:, 2] - box_a[:, 0]) * - (box_a[:, 3] - box_a[:, 1])).unsqueeze(1).expand_as(inter) # [A,B] - area_b = ((box_b[:, 2] - box_b[:, 0]) * - (box_b[:, 3] - box_b[:, 1])).unsqueeze(0).expand_as(inter) # [A,B] - union = area_a + area_b - inter - return inter / union # [A,B] - - -def match(threshold, truths, priors, variances, labels, loc_t, conf_t, idx): - """Match each prior box with the ground truth box of the highest jaccard - overlap, encode the bounding boxes, then return the matched indices - corresponding to both confidence and location preds. - Args: - threshold: (float) The overlap threshold used when mathing boxes. - truths: (tensor) Ground truth boxes, Shape: [num_obj, num_priors]. - priors: (tensor) Prior boxes from priorbox layers, Shape: [n_priors,4]. - variances: (tensor) Variances corresponding to each prior coord, - Shape: [num_priors, 4]. - labels: (tensor) All the class labels for the image, Shape: [num_obj]. - loc_t: (tensor) Tensor to be filled w/ endcoded location targets. - conf_t: (tensor) Tensor to be filled w/ matched indices for conf preds. - idx: (int) current batch index - Return: - The matched indices corresponding to 1)location and 2)confidence preds. - """ - # jaccard index - overlaps = jaccard( - truths, - point_form(priors) - ) - # (Bipartite Matching) - # [1,num_objects] best prior for each ground truth - best_prior_overlap, best_prior_idx = overlaps.max(1, keepdim=True) - # [1,num_priors] best ground truth for each prior - best_truth_overlap, best_truth_idx = overlaps.max( - 0, keepdim=True) # 0-2000 - best_truth_idx.squeeze_(0) - best_truth_overlap.squeeze_(0) - best_prior_idx.squeeze_(1) - best_prior_overlap.squeeze_(1) - best_truth_overlap.index_fill_(0, best_prior_idx, 2) # ensure best prior - # TODO refactor: index best_prior_idx with long tensor - # ensure every gt matches with its prior of max overlap - for j in range(best_prior_idx.size(0)): - best_truth_idx[best_prior_idx[j]] = j - _th1, _th2, _th3 = threshold # _th1 = 0.1 ,_th2 = 0.35,_th3 = 0.5 - - N = (torch.sum(best_prior_overlap >= _th2) + - torch.sum(best_prior_overlap >= _th3)) // 2 - matches = truths[best_truth_idx] # Shape: [num_priors,4] - conf = labels[best_truth_idx] # Shape: [num_priors] - conf[best_truth_overlap < _th2] = 0 # label as background - - best_truth_overlap_clone = best_truth_overlap.clone() - add_idx = best_truth_overlap_clone.gt( - _th1).eq(best_truth_overlap_clone.lt(_th2)) - best_truth_overlap_clone[1 - add_idx] = 0 - stage2_overlap, stage2_idx = best_truth_overlap_clone.sort(descending=True) - - stage2_overlap = stage2_overlap.gt(_th1) - - if N > 0: - N = torch.sum(stage2_overlap[:N]) if torch.sum( - stage2_overlap[:N]) < N else N - conf[stage2_idx[:N]] += 1 - - loc = encode(matches, priors, variances) - loc_t[idx] = loc # [num_priors,4] encoded offsets to learn - conf_t[idx] = conf # [num_priors] top class label for each prior - - -def match_ssd(threshold, truths, priors, variances, labels, loc_t, conf_t, idx): - """Match each prior box with the ground truth box of the highest jaccard - overlap, encode the bounding boxes, then return the matched indices - corresponding to both confidence and location preds. - Args: - threshold: (float) The overlap threshold used when mathing boxes. - truths: (tensor) Ground truth boxes, Shape: [num_obj, num_priors]. - priors: (tensor) Prior boxes from priorbox layers, Shape: [n_priors,4]. - variances: (tensor) Variances corresponding to each prior coord, - Shape: [num_priors, 4]. - labels: (tensor) All the class labels for the image, Shape: [num_obj]. - loc_t: (tensor) Tensor to be filled w/ endcoded location targets. - conf_t: (tensor) Tensor to be filled w/ matched indices for conf preds. - idx: (int) current batch index - Return: - The matched indices corresponding to 1)location and 2)confidence preds. - """ - # jaccard index - overlaps = jaccard(truths,point_form(priors)) - # (Bipartite Matching) - # [1,num_objects] best prior for each ground truth - best_prior_overlap, best_prior_idx = overlaps.max(1, keepdim=True) - # [1,num_priors] best ground truth for each prior - best_truth_overlap, best_truth_idx = overlaps.max( - 0, keepdim=True) # 0-2000 - best_truth_idx.squeeze_(0) - best_truth_overlap.squeeze_(0) - best_prior_idx.squeeze_(1) - best_prior_overlap.squeeze_(1) - best_truth_overlap.index_fill_(0, best_prior_idx, 2) # ensure best prior - # TODO refactor: index best_prior_idx with long tensor - # ensure every gt matches with its prior of max overlap - for j in range(best_prior_idx.size(0)): - best_truth_idx[best_prior_idx[j]] = j - matches = truths[best_truth_idx] # Shape: [num_priors,4] - conf = labels[best_truth_idx] # Shape: [num_priors] - conf[best_truth_overlap < threshold] = 0 # label as background - loc = encode(matches, priors, variances) - loc_t[idx] = loc # [num_priors,4] encoded offsets to learn - conf_t[idx] = conf # [num_priors] top class label for each prior - - -def encode(matched, priors, variances): - """Encode the variances from the priorbox layers into the ground truth boxes - we have matched (based on jaccard overlap) with the prior boxes. - Args: - matched: (tensor) Coords of ground truth for each prior in point-form - Shape: [num_priors, 4]. - priors: (tensor) Prior boxes in center-offset form - Shape: [num_priors,4]. - variances: (list[float]) Variances of priorboxes - Return: - encoded boxes (tensor), Shape: [num_priors, 4] - """ - - # dist b/t match center and prior's center - g_cxcy = (matched[:, :2] + matched[:, 2:]) / 2 - priors[:, :2] - # encode variance - g_cxcy /= (variances[0] * priors[:, 2:]) - # match wh / prior wh - g_wh = (matched[:, 2:] - matched[:, :2]) / priors[:, 2:] - #g_wh = torch.log(g_wh) / variances[1] - g_wh = torch.log(g_wh) / variances[1] - # return target for smooth_l1_loss - return torch.cat([g_cxcy, g_wh], 1) # [num_priors,4] - - -# Adapted from https://github.com/Hakuyume/chainer-ssd -def decode(loc, priors, variances): - """Decode locations from predictions using priors to undo - the encoding we did for offset regression at train time. - Args: - loc (tensor): location predictions for loc layers, - Shape: [num_priors,4] - priors (tensor): Prior boxes in center-offset form. - Shape: [num_priors,4]. - variances: (list[float]) Variances of priorboxes - Return: - decoded bounding box predictions - """ - - boxes = torch.cat(( - priors[:, :2] + loc[:, :2] * variances[0] * priors[:, 2:], - priors[:, 2:] * torch.exp(loc[:, 2:] * variances[1])), 1) - boxes[:, :2] -= boxes[:, 2:] / 2 - boxes[:, 2:] += boxes[:, :2] - return boxes - - -def log_sum_exp(x): - """Utility function for computing log_sum_exp while determining - This will be used to determine unaveraged confidence loss across - all examples in a batch. - Args: - x (Variable(tensor)): conf_preds from conf layers - """ - x_max = x.data.max() - return torch.log(torch.sum(torch.exp(x - x_max), 1, keepdim=True)) + x_max - - -# Original author: Francisco Massa: -# https://github.com/fmassa/object-detection.torch -# Ported to PyTorch by Max deGroot (02/01/2017) -def nms(boxes, scores, overlap=0.5, top_k=200): - """Apply non-maximum suppression at test time to avoid detecting too many - overlapping bounding boxes for a given object. - Args: - boxes: (tensor) The location preds for the img, Shape: [num_priors,4]. - scores: (tensor) The class predscores for the img, Shape:[num_priors]. - overlap: (float) The overlap thresh for suppressing unnecessary boxes. - top_k: (int) The Maximum number of box preds to consider. - Return: - The indices of the kept boxes with respect to num_priors. - """ - - keep = scores.new(scores.size(0)).zero_().long() - if boxes.numel() == 0: - return keep - x1 = boxes[:, 0] - y1 = boxes[:, 1] - x2 = boxes[:, 2] - y2 = boxes[:, 3] - area = torch.mul(x2 - x1, y2 - y1) - v, idx = scores.sort(0) # sort in ascending order - # I = I[v >= 0.01] - idx = idx[-top_k:] # indices of the top-k largest vals - xx1 = boxes.new() - yy1 = boxes.new() - xx2 = boxes.new() - yy2 = boxes.new() - w = boxes.new() - h = boxes.new() - - # keep = torch.Tensor() - count = 0 - while idx.numel() > 0: - i = idx[-1] # index of current largest val - # keep.append(i) - keep[count] = i - count += 1 - if idx.size(0) == 1: - break - idx = idx[:-1] # remove kept element from view - #add code--------------------------------------- - idx= torch.autograd.Variable(idx, requires_grad=False) - idx = idx.data - x1 = torch.autograd.Variable(x1, requires_grad=False) - x1 = x1.data - y1 = torch.autograd.Variable(y1, requires_grad=False) - y1 = y1.data - x2 = torch.autograd.Variable(x2, requires_grad=False) - x2 = x2.data - y2 = torch.autograd.Variable(y2, requires_grad=False) - y2 = y2.data - #add code end-------------------------------------- - # load bboxes of next highest vals - torch.index_select(x1, 0, idx, out=xx1) - torch.index_select(y1, 0, idx, out=yy1) - torch.index_select(x2, 0, idx, out=xx2) - torch.index_select(y2, 0, idx, out=yy2) - # store element-wise max with next highest score - xx1 = torch.clamp(xx1, min=x1[i]) - yy1 = torch.clamp(yy1, min=y1[i]) - xx2 = torch.clamp(xx2, max=x2[i]) - yy2 = torch.clamp(yy2, max=y2[i]) - w.resize_as_(xx2) - h.resize_as_(yy2) - w = xx2 - xx1 - h = yy2 - yy1 - # check sizes of xx1 and xx2.. after each iteration - w = torch.clamp(w, min=0.0) - h = torch.clamp(h, min=0.0) - inter = w * h - #add code--------------------------------- - area = torch.autograd.Variable(area, requires_grad=False) - area = area.data - idx= torch.autograd.Variable(idx, requires_grad=False) - idx = idx.data - #add code end ----------------------------------- - # IoU = i / (area(a) + area(b) - i) - rem_areas = torch.index_select(area, 0, idx) # load remaining areas) - union = (rem_areas - inter) + area[i] - IoU = inter / union # store result in iou - # keep only elements with an IoU <= overlap - idx = idx[IoU.le(overlap)] - return keep, count +#-*- coding:utf-8 -*- +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + + +import torch +import torch.npu + +def point_form(boxes): + """ Convert prior_boxes to (xmin, ymin, xmax, ymax) + representation for comparison to point form ground truth data. + Args: + boxes: (tensor) center-size default boxes from priorbox layers. + Return: + boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes. + """ + return torch.cat((boxes[:, :2] - boxes[:, 2:] / 2, # xmin, ymin + boxes[:, :2] + boxes[:, 2:] / 2), 1) # xmax, ymax + + +def center_size(boxes): + """ Convert prior_boxes to (cx, cy, w, h) + representation for comparison to center-size form ground truth data. + Args: + boxes: (tensor) point_form boxes + Return: + boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes. + """ + return torch.cat([(boxes[:, 2:] + boxes[:, :2]) / 2, # cx, cy + boxes[:, 2:] - boxes[:, :2]], 1) # w, h + + +def intersect(box_a, box_b): + """ We resize both tensors to [A,B,2] without new malloc: + [A,2] -> [A,1,2] -> [A,B,2] + [B,2] -> [1,B,2] -> [A,B,2] + Then we compute the area of intersect between box_a and box_b. + Args: + box_a: (tensor) bounding boxes, Shape: [A,4]. + box_b: (tensor) bounding boxes, Shape: [B,4]. + Return: + (tensor) intersection area, Shape: [A,B]. + """ + A = box_a.size(0) + B = box_b.size(0) + max_xy = torch.min(box_a[:, 2:].unsqueeze(1).expand(A, B, 2), + box_b[:, 2:].unsqueeze(0).expand(A, B, 2)) + min_xy = torch.max(box_a[:, :2].unsqueeze(1).expand(A, B, 2), + box_b[:, :2].unsqueeze(0).expand(A, B, 2)) + inter = torch.clamp((max_xy - min_xy), min=0) + return inter[:, :, 0] * inter[:, :, 1] + + +def jaccard(box_a, box_b): + """Compute the jaccard overlap of two sets of boxes. The jaccard overlap + is simply the intersection over union of two boxes. Here we operate on + ground truth boxes and default boxes. + E.g.: + A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) + Args: + box_a: (tensor) Ground truth bounding boxes, Shape: [num_objects,4] + box_b: (tensor) Prior boxes from priorbox layers, Shape: [num_priors,4] + Return: + jaccard overlap: (tensor) Shape: [box_a.size(0), box_b.size(0)] + """ + #when run in npu ,box_b is still in cpu + #box_b = box_b.npu() + inter = intersect(box_a, box_b) + area_a = ((box_a[:, 2] - box_a[:, 0]) * + (box_a[:, 3] - box_a[:, 1])).unsqueeze(1).expand_as(inter) # [A,B] + area_b = ((box_b[:, 2] - box_b[:, 0]) * + (box_b[:, 3] - box_b[:, 1])).unsqueeze(0).expand_as(inter) # [A,B] + union = area_a + area_b - inter + return inter / union # [A,B] + + +def match(threshold, truths, priors, variances, labels, loc_t, conf_t, idx): + """Match each prior box with the ground truth box of the highest jaccard + overlap, encode the bounding boxes, then return the matched indices + corresponding to both confidence and location preds. + Args: + threshold: (float) The overlap threshold used when mathing boxes. + truths: (tensor) Ground truth boxes, Shape: [num_obj, num_priors]. + priors: (tensor) Prior boxes from priorbox layers, Shape: [n_priors,4]. + variances: (tensor) Variances corresponding to each prior coord, + Shape: [num_priors, 4]. + labels: (tensor) All the class labels for the image, Shape: [num_obj]. + loc_t: (tensor) Tensor to be filled w/ endcoded location targets. + conf_t: (tensor) Tensor to be filled w/ matched indices for conf preds. + idx: (int) current batch index + Return: + The matched indices corresponding to 1)location and 2)confidence preds. + """ + # jaccard index + overlaps = jaccard( + truths, + point_form(priors) + ) + # (Bipartite Matching) + # [1,num_objects] best prior for each ground truth + best_prior_overlap, best_prior_idx = overlaps.max(1, keepdim=True) + # [1,num_priors] best ground truth for each prior + best_truth_overlap, best_truth_idx = overlaps.max( + 0, keepdim=True) # 0-2000 + best_truth_idx.squeeze_(0) + best_truth_overlap.squeeze_(0) + best_prior_idx.squeeze_(1) + best_prior_overlap.squeeze_(1) + best_truth_overlap.index_fill_(0, best_prior_idx, 2) # ensure best prior + # TODO refactor: index best_prior_idx with long tensor + # ensure every gt matches with its prior of max overlap + for j in range(best_prior_idx.size(0)): + best_truth_idx[best_prior_idx[j]] = j + _th1, _th2, _th3 = threshold # _th1 = 0.1 ,_th2 = 0.35,_th3 = 0.5 + + N = (torch.sum(best_prior_overlap >= _th2) + + torch.sum(best_prior_overlap >= _th3)) // 2 + matches = truths[best_truth_idx] # Shape: [num_priors,4] + conf = labels[best_truth_idx] # Shape: [num_priors] + conf[best_truth_overlap < _th2] = 0 # label as background + + best_truth_overlap_clone = best_truth_overlap.clone() + add_idx = best_truth_overlap_clone.gt( + _th1).eq(best_truth_overlap_clone.lt(_th2)) + best_truth_overlap_clone[1 - add_idx] = 0 + stage2_overlap, stage2_idx = best_truth_overlap_clone.sort(descending=True) + + stage2_overlap = stage2_overlap.gt(_th1) + + if N > 0: + N = torch.sum(stage2_overlap[:N]) if torch.sum( + stage2_overlap[:N]) < N else N + conf[stage2_idx[:N]] += 1 + + loc = encode(matches, priors, variances) + loc_t[idx] = loc # [num_priors,4] encoded offsets to learn + conf_t[idx] = conf # [num_priors] top class label for each prior + + +def match_ssd(threshold, truths, priors, variances, labels, loc_t, conf_t, idx): + """Match each prior box with the ground truth box of the highest jaccard + overlap, encode the bounding boxes, then return the matched indices + corresponding to both confidence and location preds. + Args: + threshold: (float) The overlap threshold used when mathing boxes. + truths: (tensor) Ground truth boxes, Shape: [num_obj, num_priors]. + priors: (tensor) Prior boxes from priorbox layers, Shape: [n_priors,4]. + variances: (tensor) Variances corresponding to each prior coord, + Shape: [num_priors, 4]. + labels: (tensor) All the class labels for the image, Shape: [num_obj]. + loc_t: (tensor) Tensor to be filled w/ endcoded location targets. + conf_t: (tensor) Tensor to be filled w/ matched indices for conf preds. + idx: (int) current batch index + Return: + The matched indices corresponding to 1)location and 2)confidence preds. + """ + # jaccard index + overlaps = jaccard(truths,point_form(priors)) + # (Bipartite Matching) + # [1,num_objects] best prior for each ground truth + best_prior_overlap, best_prior_idx = overlaps.max(1, keepdim=True) + # [1,num_priors] best ground truth for each prior + best_truth_overlap, best_truth_idx = overlaps.max( + 0, keepdim=True) # 0-2000 + best_truth_idx.squeeze_(0) + best_truth_overlap.squeeze_(0) + best_prior_idx.squeeze_(1) + best_prior_overlap.squeeze_(1) + best_truth_overlap.index_fill_(0, best_prior_idx, 2) # ensure best prior + # TODO refactor: index best_prior_idx with long tensor + # ensure every gt matches with its prior of max overlap + for j in range(best_prior_idx.size(0)): + best_truth_idx[best_prior_idx[j]] = j + matches = truths[best_truth_idx] # Shape: [num_priors,4] + conf = labels[best_truth_idx] # Shape: [num_priors] + conf[best_truth_overlap < threshold] = 0 # label as background + loc = encode(matches, priors, variances) + loc_t[idx] = loc # [num_priors,4] encoded offsets to learn + conf_t[idx] = conf # [num_priors] top class label for each prior + + +def encode(matched, priors, variances): + """Encode the variances from the priorbox layers into the ground truth boxes + we have matched (based on jaccard overlap) with the prior boxes. + Args: + matched: (tensor) Coords of ground truth for each prior in point-form + Shape: [num_priors, 4]. + priors: (tensor) Prior boxes in center-offset form + Shape: [num_priors,4]. + variances: (list[float]) Variances of priorboxes + Return: + encoded boxes (tensor), Shape: [num_priors, 4] + """ + + # dist b/t match center and prior's center + g_cxcy = (matched[:, :2] + matched[:, 2:]) / 2 - priors[:, :2] + # encode variance + g_cxcy /= (variances[0] * priors[:, 2:]) + # match wh / prior wh + g_wh = (matched[:, 2:] - matched[:, :2]) / priors[:, 2:] + #g_wh = torch.log(g_wh) / variances[1] + g_wh = torch.log(g_wh) / variances[1] + # return target for smooth_l1_loss + return torch.cat([g_cxcy, g_wh], 1) # [num_priors,4] + + +# Adapted from https://github.com/Hakuyume/chainer-ssd +def decode(loc, priors, variances): + """Decode locations from predictions using priors to undo + the encoding we did for offset regression at train time. + Args: + loc (tensor): location predictions for loc layers, + Shape: [num_priors,4] + priors (tensor): Prior boxes in center-offset form. + Shape: [num_priors,4]. + variances: (list[float]) Variances of priorboxes + Return: + decoded bounding box predictions + """ + + boxes = torch.cat(( + priors[:, :2] + loc[:, :2] * variances[0] * priors[:, 2:], + priors[:, 2:] * torch.exp(loc[:, 2:] * variances[1])), 1) + boxes[:, :2] -= boxes[:, 2:] / 2 + boxes[:, 2:] += boxes[:, :2] + return boxes + + +def log_sum_exp(x): + """Utility function for computing log_sum_exp while determining + This will be used to determine unaveraged confidence loss across + all examples in a batch. + Args: + x (Variable(tensor)): conf_preds from conf layers + """ + x_max = x.data.max() + return torch.log(torch.sum(torch.exp(x - x_max), 1, keepdim=True)) + x_max + + +# Original author: Francisco Massa: +# https://github.com/fmassa/object-detection.torch +# Ported to PyTorch by Max deGroot (02/01/2017) +def nms(boxes, scores, overlap=0.5, top_k=200): + """Apply non-maximum suppression at test time to avoid detecting too many + overlapping bounding boxes for a given object. + Args: + boxes: (tensor) The location preds for the img, Shape: [num_priors,4]. + scores: (tensor) The class predscores for the img, Shape:[num_priors]. + overlap: (float) The overlap thresh for suppressing unnecessary boxes. + top_k: (int) The Maximum number of box preds to consider. + Return: + The indices of the kept boxes with respect to num_priors. + """ + + keep = scores.new(scores.size(0)).zero_().long() + if boxes.numel() == 0: + return keep + x1 = boxes[:, 0] + y1 = boxes[:, 1] + x2 = boxes[:, 2] + y2 = boxes[:, 3] + area = torch.mul(x2 - x1, y2 - y1) + v, idx = scores.sort(0) # sort in ascending order + # I = I[v >= 0.01] + idx = idx[-top_k:] # indices of the top-k largest vals + xx1 = boxes.new() + yy1 = boxes.new() + xx2 = boxes.new() + yy2 = boxes.new() + w = boxes.new() + h = boxes.new() + + # keep = torch.Tensor() + count = 0 + while idx.numel() > 0: + i = idx[-1] # index of current largest val + # keep.append(i) + keep[count] = i + count += 1 + if idx.size(0) == 1: + break + idx = idx[:-1] # remove kept element from view + #add code--------------------------------------- + idx= torch.autograd.Variable(idx, requires_grad=False) + idx = idx.data + x1 = torch.autograd.Variable(x1, requires_grad=False) + x1 = x1.data + y1 = torch.autograd.Variable(y1, requires_grad=False) + y1 = y1.data + x2 = torch.autograd.Variable(x2, requires_grad=False) + x2 = x2.data + y2 = torch.autograd.Variable(y2, requires_grad=False) + y2 = y2.data + #add code end-------------------------------------- + # load bboxes of next highest vals + torch.index_select(x1, 0, idx, out=xx1) + torch.index_select(y1, 0, idx, out=yy1) + torch.index_select(x2, 0, idx, out=xx2) + torch.index_select(y2, 0, idx, out=yy2) + # store element-wise max with next highest score + xx1 = torch.clamp(xx1, min=x1[i]) + yy1 = torch.clamp(yy1, min=y1[i]) + xx2 = torch.clamp(xx2, max=x2[i]) + yy2 = torch.clamp(yy2, max=y2[i]) + w.resize_as_(xx2) + h.resize_as_(yy2) + w = xx2 - xx1 + h = yy2 - yy1 + # check sizes of xx1 and xx2.. after each iteration + w = torch.clamp(w, min=0.0) + h = torch.clamp(h, min=0.0) + inter = w * h + #add code--------------------------------- + area = torch.autograd.Variable(area, requires_grad=False) + area = area.data + idx= torch.autograd.Variable(idx, requires_grad=False) + idx = idx.data + #add code end ----------------------------------- + # IoU = i / (area(a) + area(b) - i) + rem_areas = torch.index_select(area, 0, idx) # load remaining areas) + union = (rem_areas - inter) + area[i] + IoU = inter / union # store result in iou + # keep only elements with an IoU <= overlap + idx = idx[IoU.le(overlap)] + return keep, count diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/layers/functions/__init__.py b/PyTorch/contrib/cv/detection/Pyramidbox/layers/functions/__init__.py index 5d4c8d36bbd7d73676d51d087aa928ec2328bc64..d8d93bae0453c74f51fe56dee8098a1ef816f0e0 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/layers/functions/__init__.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/layers/functions/__init__.py @@ -1,5 +1,5 @@ -from .prior_box import PriorBox -from .detection import Detect - -__all__=['Detect','PriorBox'] - +from .prior_box import PriorBox +from .detection import Detect + +__all__=['Detect','PriorBox'] + diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/layers/functions/detection.py b/PyTorch/contrib/cv/detection/Pyramidbox/layers/functions/detection.py index a37ae6bb94dbfa4dc57588f8648f8b1e749ebfb6..b68c7fb405e0bbccacd1c6d7f113cf66120a7fab 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/layers/functions/detection.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/layers/functions/detection.py @@ -1,82 +1,82 @@ -#-*- coding:utf-8 -*- -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - -import torch - -from ..bbox_utils import decode, nms -from torch.autograd import Function - - -class Detect(Function): - """At test time, Detect is the final layer of SSD. Decode location preds, - apply non-maximum suppression to location predictions based on conf - scores and threshold to a top_k number of output predictions for both - confidence score and locations. - """ - - def __init__(self, cfg): - self.num_classes = cfg.NUM_CLASSES - self.top_k = cfg.TOP_K - self.nms_thresh = cfg.NMS_THRESH - self.conf_thresh = cfg.CONF_THRESH - self.variance = cfg.VARIANCE - - def forward(self, loc_data, conf_data, prior_data): - """ - Args: - loc_data: (tensor) Loc preds from loc layers - Shape: [batch,num_priors*4] - conf_data: (tensor) Shape: Conf preds from conf layers - Shape: [batch*num_priors,num_classes] - prior_data: (tensor) Prior boxes and variances from priorbox layers - Shape: [1,num_priors,4] - """ - #print('loc_data device:{}'.format(loc_data.device)) - #print('conf_data device:{}'.format(conf_data.device)) - #print('prior_data device:{}'.format(prior_data.device)) - num = loc_data.size(0) - num_priors = prior_data.size(0) - - conf_preds = conf_data.view( - num, num_priors, self.num_classes).transpose(2, 1) - batch_priors = prior_data.view(-1, num_priors, - 4).expand(num, num_priors, 4) - batch_priors = batch_priors.contiguous().view(-1, 4) - - decoded_boxes = decode(loc_data.view(-1, 4), - batch_priors, self.variance) - decoded_boxes = decoded_boxes.view(num, num_priors, 4) - - output = torch.zeros(num, self.num_classes, self.top_k, 5) - - for i in range(num): - boxes = decoded_boxes[i].clone() - conf_scores = conf_preds[i].clone() - for cl in range(1, self.num_classes): - c_mask = conf_scores[cl].gt(self.conf_thresh) - scores = conf_scores[cl][c_mask] - #change code - if scores.numel() == 0: - continue - l_mask = c_mask.unsqueeze(1).expand_as(boxes) - boxes_ = boxes[l_mask].view(-1, 4) - ids, count = nms(boxes_, scores, self.nms_thresh, self.top_k) - output[i, cl, :count] = torch.cat((scores[ids[:count]].unsqueeze(1), - boxes_[ids[:count]]), 1) - - return output +#-*- coding:utf-8 -*- +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + +import torch + +from ..bbox_utils import decode, nms +from torch.autograd import Function + + +class Detect(Function): + """At test time, Detect is the final layer of SSD. Decode location preds, + apply non-maximum suppression to location predictions based on conf + scores and threshold to a top_k number of output predictions for both + confidence score and locations. + """ + + def __init__(self, cfg): + self.num_classes = cfg.NUM_CLASSES + self.top_k = cfg.TOP_K + self.nms_thresh = cfg.NMS_THRESH + self.conf_thresh = cfg.CONF_THRESH + self.variance = cfg.VARIANCE + + def forward(self, loc_data, conf_data, prior_data): + """ + Args: + loc_data: (tensor) Loc preds from loc layers + Shape: [batch,num_priors*4] + conf_data: (tensor) Shape: Conf preds from conf layers + Shape: [batch*num_priors,num_classes] + prior_data: (tensor) Prior boxes and variances from priorbox layers + Shape: [1,num_priors,4] + """ + #print('loc_data device:{}'.format(loc_data.device)) + #print('conf_data device:{}'.format(conf_data.device)) + #print('prior_data device:{}'.format(prior_data.device)) + num = loc_data.size(0) + num_priors = prior_data.size(0) + + conf_preds = conf_data.view( + num, num_priors, self.num_classes).transpose(2, 1) + batch_priors = prior_data.view(-1, num_priors, + 4).expand(num, num_priors, 4) + batch_priors = batch_priors.contiguous().view(-1, 4) + + decoded_boxes = decode(loc_data.view(-1, 4), + batch_priors, self.variance) + decoded_boxes = decoded_boxes.view(num, num_priors, 4) + + output = torch.zeros(num, self.num_classes, self.top_k, 5) + + for i in range(num): + boxes = decoded_boxes[i].clone() + conf_scores = conf_preds[i].clone() + for cl in range(1, self.num_classes): + c_mask = conf_scores[cl].gt(self.conf_thresh) + scores = conf_scores[cl][c_mask] + #change code + if scores.numel() == 0: + continue + l_mask = c_mask.unsqueeze(1).expand_as(boxes) + boxes_ = boxes[l_mask].view(-1, 4) + ids, count = nms(boxes_, scores, self.nms_thresh, self.top_k) + output[i, cl, :count] = torch.cat((scores[ids[:count]].unsqueeze(1), + boxes_[ids[:count]]), 1) + + return output diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/layers/functions/prior_box.py b/PyTorch/contrib/cv/detection/Pyramidbox/layers/functions/prior_box.py index 48bd01be69ac66cfbb9f083fb56759247bf2de4f..b09f5707e04a6d8005dfa63e06e4718722d11ace 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/layers/functions/prior_box.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/layers/functions/prior_box.py @@ -1,73 +1,73 @@ -#-*- coding:utf-8 -*- -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - -import torch -from itertools import product as product -import math - - -class PriorBox(object): - """Compute priorbox coordinates in center-offset form for each source - feature map. - """ - - def __init__(self, input_size, feature_maps,cfg): - super(PriorBox, self).__init__() - self.imh = input_size[0] - self.imw = input_size[1] - - # number of priors for feature map location (either 4 or 6) - self.variance = cfg.VARIANCE or [0.1] - #self.feature_maps = cfg.FEATURE_MAPS - self.min_sizes = cfg.ANCHOR_SIZES - self.steps = cfg.STEPS - self.clip = cfg.CLIP - for v in self.variance: - if v <= 0: - raise ValueError('Variances must be greater than 0') - self.feature_maps = feature_maps - - - def forward(self): - mean = [] - for k in range(len(self.feature_maps)): - feath = self.feature_maps[k][0] - featw = self.feature_maps[k][1] - for i, j in product(range(feath), range(featw)): - f_kw = self.imw / self.steps[k] - f_kh = self.imh / self.steps[k] - - cx = (j + 0.5) / f_kw - cy = (i + 0.5) / f_kh - - s_kw = self.min_sizes[k] / self.imw - s_kh = self.min_sizes[k] / self.imh - - mean += [cx, cy, s_kw, s_kh] - - output = torch.Tensor(mean).view(-1, 4) - if self.clip: - output.clamp_(max=1, min=0) - return output - - -if __name__ == '__main__': - from data.config import cfg - p = PriorBox([640, 640], cfg) - out = p.forward() - print(out.size()) +#-*- coding:utf-8 -*- +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + +import torch +from itertools import product as product +import math + + +class PriorBox(object): + """Compute priorbox coordinates in center-offset form for each source + feature map. + """ + + def __init__(self, input_size, feature_maps,cfg): + super(PriorBox, self).__init__() + self.imh = input_size[0] + self.imw = input_size[1] + + # number of priors for feature map location (either 4 or 6) + self.variance = cfg.VARIANCE or [0.1] + #self.feature_maps = cfg.FEATURE_MAPS + self.min_sizes = cfg.ANCHOR_SIZES + self.steps = cfg.STEPS + self.clip = cfg.CLIP + for v in self.variance: + if v <= 0: + raise ValueError('Variances must be greater than 0') + self.feature_maps = feature_maps + + + def forward(self): + mean = [] + for k in range(len(self.feature_maps)): + feath = self.feature_maps[k][0] + featw = self.feature_maps[k][1] + for i, j in product(range(feath), range(featw)): + f_kw = self.imw / self.steps[k] + f_kh = self.imh / self.steps[k] + + cx = (j + 0.5) / f_kw + cy = (i + 0.5) / f_kh + + s_kw = self.min_sizes[k] / self.imw + s_kh = self.min_sizes[k] / self.imh + + mean += [cx, cy, s_kw, s_kh] + + output = torch.Tensor(mean).view(-1, 4) + if self.clip: + output.clamp_(max=1, min=0) + return output + + +if __name__ == '__main__': + from data.config import cfg + p = PriorBox([640, 640], cfg) + out = p.forward() + print(out.size()) diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/layers/modules/__init__.py b/PyTorch/contrib/cv/detection/Pyramidbox/layers/modules/__init__.py index d1433bff7ffa09ad46d4a46e8c28bc2b170ef072..9abf8e13503525d87011d79acb5a2dc0bf4b7673 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/layers/modules/__init__.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/layers/modules/__init__.py @@ -1,12 +1,12 @@ -#-*- coding:utf-8 -*- - -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - - -from .l2norm import L2Norm -from .multibox_loss import MultiBoxLoss - -__all__ = ['L2Norm', 'MultiBoxLoss'] - +#-*- coding:utf-8 -*- + +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + + +from .l2norm import L2Norm +from .multibox_loss import MultiBoxLoss + +__all__ = ['L2Norm', 'MultiBoxLoss'] + diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/layers/modules/l2norm.py b/PyTorch/contrib/cv/detection/Pyramidbox/layers/modules/l2norm.py index 0c77185ed8c281ec7a78d139e8d426d5b8dd562b..ca04e0bb3fbe4c17a434b353f5c40fb1a683bfa6 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/layers/modules/l2norm.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/layers/modules/l2norm.py @@ -1,48 +1,48 @@ -#-*- coding:utf-8 -*- -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - - -import torch -import torch.nn as nn -import torch.nn.init as init -from torch.autograd import Function -from torch.autograd import Variable - - - -class L2Norm(nn.Module): - def __init__(self,n_channels, scale): - super(L2Norm,self).__init__() - self.n_channels = n_channels - self.gamma = scale or None - self.eps = 1e-10 - self.weight = nn.Parameter(torch.Tensor(self.n_channels)) - self.reset_parameters() - - def reset_parameters(self): - init.constant_(self.weight,self.gamma) - - def forward(self, x): - norm = x.pow(2).sum(dim=1, keepdim=True).sqrt()+self.eps - #x /= norm - x = torch.div(x,norm) - out = self.weight.unsqueeze(0).unsqueeze(2).unsqueeze(3).expand_as(x) * x - return out - - +#-*- coding:utf-8 -*- +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + + +import torch +import torch.nn as nn +import torch.nn.init as init +from torch.autograd import Function +from torch.autograd import Variable + + + +class L2Norm(nn.Module): + def __init__(self,n_channels, scale): + super(L2Norm,self).__init__() + self.n_channels = n_channels + self.gamma = scale or None + self.eps = 1e-10 + self.weight = nn.Parameter(torch.Tensor(self.n_channels)) + self.reset_parameters() + + def reset_parameters(self): + init.constant_(self.weight,self.gamma) + + def forward(self, x): + norm = x.pow(2).sum(dim=1, keepdim=True).sqrt()+self.eps + #x /= norm + x = torch.div(x,norm) + out = self.weight.unsqueeze(0).unsqueeze(2).unsqueeze(3).expand_as(x) * x + return out + + \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/layers/modules/multibox_loss.py b/PyTorch/contrib/cv/detection/Pyramidbox/layers/modules/multibox_loss.py index 18d2ddff33f4363036e76534623577de44221e0d..9b8b1d1078825ed8bc36fb8de90f7ffff1628262 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/layers/modules/multibox_loss.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/layers/modules/multibox_loss.py @@ -1,159 +1,159 @@ -#-*- coding:utf-8 -*- -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - -import math -import torch -import torch.nn as nn -import torch.nn.functional as F -from torch.autograd import Variable -import torch.npu - -from ..bbox_utils import match, log_sum_exp, match_ssd - - -class MultiBoxLoss(nn.Module): - """SSD Weighted Loss Function - Compute Targets: - 1) Produce Confidence Target Indices by matching ground truth boxes - with (default) 'priorboxes' that have jaccard index > threshold parameter - (default threshold: 0.5). - 2) Produce localization target by 'encoding' variance into offsets of ground - truth boxes and their matched 'priorboxes'. - 3) Hard negative mining to filter the excessive number of negative examples - that comes with using a large number of default bounding boxes. - (default negative:positive ratio 3:1) - Objective Loss: - L(x,c,l,g) = (Lconf(x, c) + αLloc(x,l,g)) / N - Where, Lconf is the CrossEntropy Loss and Lloc is the SmoothL1 Loss - weighted by α which is set to 1 by cross val. - Args: - c: class confidences, - l: predicted boxes, - g: ground truth boxes - N: number of matched default boxes - See: https://arxiv.org/pdf/1512.02325.pdf for more details. - """ - - def __init__(self, - cfg, - use_npu=True, - use_head_loss=False): - super(MultiBoxLoss, self).__init__() - self.use_npu = use_npu - self.num_classes = cfg.NUM_CLASSES - self.negpos_ratio = cfg.NEG_POS_RATIOS - self.variance = cfg.VARIANCE - self.use_head_loss = use_head_loss - self.threshold = cfg.FACE.OVERLAP_THRESH - self.match = match_ssd - - def forward(self, - predictions, - targets): - """Multibox Loss - Args: - predictions (tuple): A tuple containing loc preds, conf preds, - and prior boxes from SSD net. - conf shape: torch.size(batch_size,num_priors,num_classes) - loc shape: torch.size(batch_size,num_priors,4) - priors shape: torch.size(num_priors,4) - - targets (tensor): Ground truth boxes and labels for a batch, - shape: [batch_size,num_objs,5] (last idx is the label). - """ - if self.use_head_loss: - _, _, loc_data, conf_data, priors = predictions - else: - loc_data, conf_data, _, _, priors = predictions - loc_data = loc_data.cpu() - conf_data = conf_data.cpu() - priors = priors.cpu() - num = loc_data.size(0) - priors = priors[:loc_data.size(1), :] - num_priors = (priors.size(0)) - num_classes = self.num_classes - # match priors (default boxes) and ground truth boxes - loc_t = torch.Tensor(num, num_priors, 4) - conf_t = torch.LongTensor(num, num_priors) - for idx in range(num): - truths = targets[idx][:, :-1].data - labels = targets[idx][:, -1].data - defaults = priors.data - self.match(self.threshold, truths, defaults, self.variance, labels, - loc_t, conf_t, idx) - # wrap targets - loc_t = Variable(loc_t, requires_grad=False) - conf_t = Variable(conf_t, requires_grad=False) - - pos = conf_t > 0 - num_pos = pos.sum(dim=1, keepdim=True) - # Localization Loss (Smooth L1) - # Shape: [batch,num_priors,4] - pos_idx = pos.unsqueeze(pos.dim()).expand_as(loc_data) - loc_p = loc_data[pos_idx].view(-1, 4) - loc_t = loc_t[pos_idx].view(-1, 4) - loss_l = F.smooth_l1_loss(loc_p, loc_t, size_average=False) - batch_conf = conf_data.view(-1, self.num_classes) - loss_c = log_sum_exp(batch_conf) - \ - batch_conf.gather(1, conf_t.view(-1, 1)) - - # Hard Negative Mining - loss_c =loss_c.cpu() - pos1 = pos.view(-1,1) - loss_c[pos1] = 0 # filter out pos boxes for now - loss_c = loss_c.view(num, -1) - _, loss_idx = loss_c.sort(1, descending=True) - _, idx_rank = loss_idx.sort(1) - - num_pos = pos.long().sum(1, keepdim=True) - num_neg = torch.clamp(self.negpos_ratio * - num_pos, max=pos.size(1) - 1) - neg = idx_rank < num_neg.expand_as(idx_rank) - - # Confidence Loss Including Positive and Negative Examples - conf_data = conf_data.cpu() - pos_idx = pos.unsqueeze(2).expand_as(conf_data) - neg_idx = neg.unsqueeze(2).expand_as(conf_data) - conf_p = conf_data[(pos_idx + neg_idx).gt(0) - ].view(-1, self.num_classes) - targets_weighted = conf_t[(pos + neg).gt(0)] - loss_c = F.cross_entropy(conf_p, targets_weighted, size_average=False) - - # Sum of losses: L(x,c,l,g) = (Lconf(x, c) + αLloc(x,l,g)) / N - N = num_pos.data.sum() if num_pos.data.sum() > 0 else num - loss_l /= N - loss_c /= N - return loss_l, loss_c +#-*- coding:utf-8 -*- +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + +import math +import torch +import torch.nn as nn +import torch.nn.functional as F +from torch.autograd import Variable +import torch.npu + +from ..bbox_utils import match, log_sum_exp, match_ssd + + +class MultiBoxLoss(nn.Module): + """SSD Weighted Loss Function + Compute Targets: + 1) Produce Confidence Target Indices by matching ground truth boxes + with (default) 'priorboxes' that have jaccard index > threshold parameter + (default threshold: 0.5). + 2) Produce localization target by 'encoding' variance into offsets of ground + truth boxes and their matched 'priorboxes'. + 3) Hard negative mining to filter the excessive number of negative examples + that comes with using a large number of default bounding boxes. + (default negative:positive ratio 3:1) + Objective Loss: + L(x,c,l,g) = (Lconf(x, c) + αLloc(x,l,g)) / N + Where, Lconf is the CrossEntropy Loss and Lloc is the SmoothL1 Loss + weighted by α which is set to 1 by cross val. + Args: + c: class confidences, + l: predicted boxes, + g: ground truth boxes + N: number of matched default boxes + See: https://arxiv.org/pdf/1512.02325.pdf for more details. + """ + + def __init__(self, + cfg, + use_npu=True, + use_head_loss=False): + super(MultiBoxLoss, self).__init__() + self.use_npu = use_npu + self.num_classes = cfg.NUM_CLASSES + self.negpos_ratio = cfg.NEG_POS_RATIOS + self.variance = cfg.VARIANCE + self.use_head_loss = use_head_loss + self.threshold = cfg.FACE.OVERLAP_THRESH + self.match = match_ssd + + def forward(self, + predictions, + targets): + """Multibox Loss + Args: + predictions (tuple): A tuple containing loc preds, conf preds, + and prior boxes from SSD net. + conf shape: torch.size(batch_size,num_priors,num_classes) + loc shape: torch.size(batch_size,num_priors,4) + priors shape: torch.size(num_priors,4) + + targets (tensor): Ground truth boxes and labels for a batch, + shape: [batch_size,num_objs,5] (last idx is the label). + """ + if self.use_head_loss: + _, _, loc_data, conf_data, priors = predictions + else: + loc_data, conf_data, _, _, priors = predictions + loc_data = loc_data.cpu() + conf_data = conf_data.cpu() + priors = priors.cpu() + num = loc_data.size(0) + priors = priors[:loc_data.size(1), :] + num_priors = (priors.size(0)) + num_classes = self.num_classes + # match priors (default boxes) and ground truth boxes + loc_t = torch.Tensor(num, num_priors, 4) + conf_t = torch.LongTensor(num, num_priors) + for idx in range(num): + truths = targets[idx][:, :-1].data + labels = targets[idx][:, -1].data + defaults = priors.data + self.match(self.threshold, truths, defaults, self.variance, labels, + loc_t, conf_t, idx) + # wrap targets + loc_t = Variable(loc_t, requires_grad=False) + conf_t = Variable(conf_t, requires_grad=False) + + pos = conf_t > 0 + num_pos = pos.sum(dim=1, keepdim=True) + # Localization Loss (Smooth L1) + # Shape: [batch,num_priors,4] + pos_idx = pos.unsqueeze(pos.dim()).expand_as(loc_data) + loc_p = loc_data[pos_idx].view(-1, 4) + loc_t = loc_t[pos_idx].view(-1, 4) + loss_l = F.smooth_l1_loss(loc_p, loc_t, size_average=False) + batch_conf = conf_data.view(-1, self.num_classes) + loss_c = log_sum_exp(batch_conf) - \ + batch_conf.gather(1, conf_t.view(-1, 1)) + + # Hard Negative Mining + loss_c =loss_c.cpu() + pos1 = pos.view(-1,1) + loss_c[pos1] = 0 # filter out pos boxes for now + loss_c = loss_c.view(num, -1) + _, loss_idx = loss_c.sort(1, descending=True) + _, idx_rank = loss_idx.sort(1) + + num_pos = pos.long().sum(1, keepdim=True) + num_neg = torch.clamp(self.negpos_ratio * + num_pos, max=pos.size(1) - 1) + neg = idx_rank < num_neg.expand_as(idx_rank) + + # Confidence Loss Including Positive and Negative Examples + conf_data = conf_data.cpu() + pos_idx = pos.unsqueeze(2).expand_as(conf_data) + neg_idx = neg.unsqueeze(2).expand_as(conf_data) + conf_p = conf_data[(pos_idx + neg_idx).gt(0) + ].view(-1, self.num_classes) + targets_weighted = conf_t[(pos + neg).gt(0)] + loss_c = F.cross_entropy(conf_p, targets_weighted, size_average=False) + + # Sum of losses: L(x,c,l,g) = (Lconf(x, c) + αLloc(x,l,g)) / N + N = num_pos.data.sum() if num_pos.data.sum() > 0 else num + loss_l /= N + loss_c /= N + return loss_l, loss_c diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/modelzoo_level.txt b/PyTorch/contrib/cv/detection/Pyramidbox/modelzoo_level.txt index 7eeb8d729d7fb2dd94b91dcf79f8eabd5cfc5b77..a3e2322b3a5f07f4e0cccb874f54cc3d63326fc4 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/modelzoo_level.txt +++ b/PyTorch/contrib/cv/detection/Pyramidbox/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PerfStatus:OK +PrecisionStatus:OK diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/prepare_wider_data.py b/PyTorch/contrib/cv/detection/Pyramidbox/prepare_wider_data.py index 59b5d3872b8ef13008c6b12f7ad33d759bcea495..03b9eec1eb2660823be64d0d014506af7ec21d90 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/prepare_wider_data.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/prepare_wider_data.py @@ -1,121 +1,121 @@ -#-*- coding:utf-8 -*- -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - -import argparse -import os -from data.config import cfg -#import cv2 - -parser = argparse.ArgumentParser( - description='Pyramidbox face Detector Training With Pytorch') -parser.add_argument('--data_path', - default=None, type=str, - help='data_path') -args = parser.parse_args() - -train_list_file = os.path.join(args.data_path, 'wider_face_split', - 'wider_face_train_bbx_gt.txt') -val_list_file = os.path.join(args.data_path, 'wider_face_split', - 'wider_face_val_bbx_gt.txt') - -WIDER_TRAIN = os.path.join(args.data_path, 'WIDER_train', 'images') -WIDER_VAL = os.path.join(args.data_path, 'WIDER_val', 'images') - - -def parse_wider_file(root, file): - with open(file, 'r') as fr: - lines = fr.readlines() - face_count = [] - img_paths = [] - face_loc = [] - img_faces = [] - count = 0 - flag = False - for k, line in enumerate(lines): - line = line.strip().strip('\n') - if count > 0: - line = line.split(' ') - count -= 1 - loc = [int(line[0]), int(line[1]), int(line[2]), int(line[3])] - face_loc += [loc] - if flag: - face_count += [int(line)] - flag = False - count = int(line) - if 'jpg' in line: - img_paths += [os.path.join(root, line)] - flag = True - - total_face = 0 - for k in face_count: - face_ = [] - for x in range(total_face, total_face + k): - face_.append(face_loc[x]) - img_faces += [face_] - total_face += k - return img_paths, img_faces - - -def wider_data_file(): - img_paths, bbox = parse_wider_file(WIDER_TRAIN, train_list_file) - fw = open(cfg.FACE.TRAIN_FILE, 'w') - for index in range(len(img_paths)): - path = img_paths[index] - boxes = bbox[index] - fw.write(path) - fw.write(' {}'.format(len(boxes))) - for box in boxes: - data = ' {} {} {} {} {}'.format(box[0], box[1], box[2], box[3], 1) - fw.write(data) - fw.write('\n') - fw.close() - - img_paths, bbox = parse_wider_file(WIDER_VAL, val_list_file) - fw = open(cfg.FACE.VAL_FILE, 'w') - for index in range(len(img_paths)): - path = img_paths[index] - boxes = bbox[index] - fw.write(path) - fw.write(' {}'.format(len(boxes))) - for box in boxes: - data = ' {} {} {} {} {}'.format(box[0], box[1], box[2], box[3], 1) - fw.write(data) - fw.write('\n') - fw.close() - - -if __name__ == '__main__': - wider_data_file() +#-*- coding:utf-8 -*- +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + +import argparse +import os +from data.config import cfg +#import cv2 + +parser = argparse.ArgumentParser( + description='Pyramidbox face Detector Training With Pytorch') +parser.add_argument('--data_path', + default=None, type=str, + help='data_path') +args = parser.parse_args() + +train_list_file = os.path.join(args.data_path, 'wider_face_split', + 'wider_face_train_bbx_gt.txt') +val_list_file = os.path.join(args.data_path, 'wider_face_split', + 'wider_face_val_bbx_gt.txt') + +WIDER_TRAIN = os.path.join(args.data_path, 'WIDER_train', 'images') +WIDER_VAL = os.path.join(args.data_path, 'WIDER_val', 'images') + + +def parse_wider_file(root, file): + with open(file, 'r') as fr: + lines = fr.readlines() + face_count = [] + img_paths = [] + face_loc = [] + img_faces = [] + count = 0 + flag = False + for k, line in enumerate(lines): + line = line.strip().strip('\n') + if count > 0: + line = line.split(' ') + count -= 1 + loc = [int(line[0]), int(line[1]), int(line[2]), int(line[3])] + face_loc += [loc] + if flag: + face_count += [int(line)] + flag = False + count = int(line) + if 'jpg' in line: + img_paths += [os.path.join(root, line)] + flag = True + + total_face = 0 + for k in face_count: + face_ = [] + for x in range(total_face, total_face + k): + face_.append(face_loc[x]) + img_faces += [face_] + total_face += k + return img_paths, img_faces + + +def wider_data_file(): + img_paths, bbox = parse_wider_file(WIDER_TRAIN, train_list_file) + fw = open(cfg.FACE.TRAIN_FILE, 'w') + for index in range(len(img_paths)): + path = img_paths[index] + boxes = bbox[index] + fw.write(path) + fw.write(' {}'.format(len(boxes))) + for box in boxes: + data = ' {} {} {} {} {}'.format(box[0], box[1], box[2], box[3], 1) + fw.write(data) + fw.write('\n') + fw.close() + + img_paths, bbox = parse_wider_file(WIDER_VAL, val_list_file) + fw = open(cfg.FACE.VAL_FILE, 'w') + for index in range(len(img_paths)): + path = img_paths[index] + boxes = bbox[index] + fw.write(path) + fw.write(' {}'.format(len(boxes))) + for box in boxes: + data = ' {} {} {} {} {}'.format(box[0], box[1], box[2], box[3], 1) + fw.write(data) + fw.write('\n') + fw.close() + + +if __name__ == '__main__': + wider_data_file() diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/pyramidbox.py b/PyTorch/contrib/cv/detection/Pyramidbox/pyramidbox.py index 048fabf22016662110259873202f68273cf4df9d..f8ebd2e0fd56a2fd50a134d4c426b713de707133 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/pyramidbox.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/pyramidbox.py @@ -1,434 +1,434 @@ -#-*- coding:utf-8 -*- -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import time -import torch -import torch.nn as nn -import torch.nn.init as init -from torch.autograd import Function -import torch.nn.functional as F -from torch.autograd import Variable -import os -from layers import * -from data.config import cfg -import numpy as np -import torch.npu -class conv_bn(nn.Module): - """docstring for conv""" - - def __init__(self, - in_plane, - out_plane, - kernel_size, - stride, - padding): - super(conv_bn, self).__init__() - self.conv1 = nn.Conv2d(in_plane, out_plane, - kernel_size=kernel_size, stride=stride, padding=padding) - self.bn1 = nn.BatchNorm2d(out_plane) - - def forward(self, x): - x = self.conv1(x) - return self.bn1(x) - - - -class CPM(nn.Module): - """docstring for CPM""" - - def __init__(self, in_plane): - super(CPM, self).__init__() - self.branch1 = conv_bn(in_plane, 1024, 1, 1, 0) - self.branch2a = conv_bn(in_plane, 256, 1, 1, 0) - self.branch2b = conv_bn(256, 256, 3, 1, 1) - self.branch2c = conv_bn(256, 1024, 1, 1, 0) - - self.ssh_1 = nn.Conv2d(1024, 256, kernel_size=3, stride=1, padding=1) - self.ssh_dimred = nn.Conv2d( - 1024, 128, kernel_size=3, stride=1, padding=1) - self.ssh_2 = nn.Conv2d(128, 128, kernel_size=3, stride=1, padding=1) - self.ssh_3a = nn.Conv2d(128, 128, kernel_size=3, stride=1, padding=1) - self.ssh_3b = nn.Conv2d(128, 128, kernel_size=3, stride=1, padding=1) - - def forward(self, x): - out_residual = self.branch1(x) - x = F.relu(self.branch2a(x), inplace=True) - x = F.relu(self.branch2b(x), inplace=True) - x = self.branch2c(x) - rescomb = F.relu(x + out_residual, inplace=True) - ssh1 = self.ssh_1(rescomb) - ssh_dimred = F.relu(self.ssh_dimred(rescomb), inplace=True) - ssh_2 = self.ssh_2(ssh_dimred) - ssh_3a = F.relu(self.ssh_3a(ssh_dimred), inplace=True) - ssh_3b = self.ssh_3b(ssh_3a) - - ssh_out = torch.cat([ssh1, ssh_2, ssh_3b], dim=1) - ssh_out = F.relu(ssh_out, inplace=True) - return ssh_out - - -class PyramidBox(nn.Module): - """docstring for PyramidBox""" - - def __init__(self, - phase, - base, - extras, - lfpn_cpm, - head, - num_classes): - super(PyramidBox, self).__init__() - - self.vgg = nn.ModuleList(base) - self.extras = nn.ModuleList(extras) - self.bn64 = nn.BatchNorm2d(64) - self.L2Norm3_3 = L2Norm(256, 10) - self.L2Norm4_3 = L2Norm(512, 8) - self.L2Norm5_3 = L2Norm(512, 5) - - self.lfpn_topdown = nn.ModuleList(lfpn_cpm[0]) - self.lfpn_later = nn.ModuleList(lfpn_cpm[1]) - self.cpm = nn.ModuleList(lfpn_cpm[2]) - - self.loc_layers = nn.ModuleList(head[0]) - self.conf_layers = nn.ModuleList(head[1]) - - - - self.is_infer = False - if phase == 'test': - self.softmax = nn.Softmax(dim=-1) - self.detect = Detect(cfg) - self.is_infer = True - - def _upsample_prod(self, x, y): - _, _, H, W = y.size() - return F.interpolate(x, size=(H, W), mode='bilinear') * y - - def forward(self, x): - - use_npu = False - size = x.size()[2:] - bn_index = 0 - for k in range(16): - x = self.vgg[k](x) - if isinstance(self.vgg[k], nn.Conv2d): - if k == 2: - x = self.bn64(x) - conv3_3 = x - for k in range(16, 23): - x = self.vgg[k](x) - conv4_3 = x - for k in range(23, 30): - x = self.vgg[k](x) - - conv5_3 = x - - for k in range(30, len(self.vgg)): - x = self.vgg[k](x) - - convfc_7 = x - - for k in range(2): - x = F.relu(self.extras[k](x), inplace=True)#.npu() - conv6_2 = x - - for k in range(2, 4): - x = F.relu(self.extras[k](x), inplace=True)#.npu() - - conv7_2 = x - - x = F.relu(self.lfpn_topdown[0](convfc_7), inplace=True) - lfpn2_on_conv5 = F.relu(self._upsample_prod( - x, self.lfpn_later[0](conv5_3)), inplace=True) - - x = F.relu(self.lfpn_topdown[1](lfpn2_on_conv5), inplace=True) - lfpn1_on_conv4 = F.relu(self._upsample_prod( - x, self.lfpn_later[1](conv4_3)), inplace=True) - - - x = F.relu(self.lfpn_topdown[2](lfpn1_on_conv4), inplace=True) - lfpn0_on_conv3 = F.relu(self._upsample_prod( - x, self.lfpn_later[2](conv3_3)), inplace=True) - l2norm3 = self.L2Norm3_3(lfpn0_on_conv3) - l2norm4 = self.L2Norm4_3(lfpn1_on_conv4) - l2norm5 = self.L2Norm5_3(lfpn2_on_conv5) - - ssh_conv3_norm = self.cpm[0](l2norm3) - ssh_conv4_norm = self.cpm[1](l2norm4) - ssh_conv5_norm = self.cpm[2](l2norm5) - - ssh_convfc7 = self.cpm[3](convfc_7) - ssh_conv6 = self.cpm[4](conv6_2) - ssh_conv7 = self.cpm[5](conv7_2) - face_locs, face_confs = [], [] - head_locs, head_confs = [], [] - - N = ssh_conv3_norm.size(0) - - - mbox_loc = self.loc_layers[0](ssh_conv3_norm) - - face_loc, head_loc = torch.chunk(mbox_loc, 2, dim=1) - - face_loc = face_loc.permute(0, 2, 3, 1).contiguous().view(N, -1, 4) - if not self.is_infer: - head_loc = head_loc.permute(0, 2, 3, 1).contiguous().view(N, -1, 4) - - mbox_conf = self.conf_layers[0](ssh_conv3_norm) - - face_conf1 = mbox_conf[:, 3:4, :, :] - face_conf3_maxin, _ = torch.max(mbox_conf[:, 0:3, :, :], dim=1, keepdim=True) - - face_conf = torch.cat((face_conf3_maxin, face_conf1), dim=1) - face_conf = face_conf.permute(0, 2, 3, 1).contiguous().view(N, -1, 2) - if not self.is_infer: - head_conf3_maxin, _ = torch.max(mbox_conf[:, 4:7, :, :], dim=1, keepdim=True) - head_conf1 = mbox_conf[:, 7:, :, :] - - head_conf = torch.cat((head_conf3_maxin, head_conf1), dim=1) - head_conf = head_conf.permute(0, 2, 3, 1).contiguous().view(N, -1, 2) - - face_locs.append(face_loc) - face_confs.append(face_conf) - if not self.is_infer: - head_locs.append(head_loc) - head_confs.append(head_conf) - - - inputs = [ssh_conv4_norm, ssh_conv5_norm, - ssh_convfc7, ssh_conv6, ssh_conv7] - - feature_maps = [] - feat_size = ssh_conv3_norm.size()[2:] - feature_maps.append([feat_size[0], feat_size[1]]) - - for i, feat in enumerate(inputs): - - feat_size = feat.size()[2:] - feature_maps.append([feat_size[0], feat_size[1]]) - mbox_loc = self.loc_layers[i + 1](feat) - - face_loc, head_loc = torch.chunk(mbox_loc, 2, dim=1) - - face_loc = face_loc.permute(0, 2, 3, 1).contiguous().view(N, -1, 4) - if not self.is_infer: - head_loc = head_loc.permute(0, 2, 3, 1).contiguous().view(N, -1, 4) - - mbox_conf = self.conf_layers[i + 1](feat) - - face_conf1 = mbox_conf[:, 0:1, :, :] - face_conf3_maxin, _ = torch.max( - mbox_conf[:, 1:4, :, :], dim=1, keepdim=True) - - face_conf = torch.cat((face_conf1, face_conf3_maxin), dim=1) - - face_conf = face_conf.permute( - 0, 2, 3, 1).contiguous().view(N, -1, 2) - - if not self.is_infer: - head_conf = mbox_conf[:, 4:, :, :].permute( - 0, 2, 3, 1).contiguous().view(N, -1, 2) - - face_locs.append(face_loc) - face_confs.append(face_conf) - - if not self.is_infer: - head_locs.append(head_loc) - head_confs.append(head_conf) - - face_mbox_loc = torch.cat(face_locs, dim=1) - face_mbox_conf = torch.cat(face_confs, dim=1) - - if not self.is_infer: - head_mbox_loc = torch.cat(head_locs, dim=1) - head_mbox_conf = torch.cat(head_confs, dim=1) - - - priors_boxes = PriorBox(size, feature_maps, cfg) - with torch.no_grad(): - priors = Variable(priors_boxes.forward()) - - if not self.is_infer: - output = (face_mbox_loc, face_mbox_conf, - head_mbox_loc, head_mbox_conf, priors) - else: - face_mbox_loc = face_mbox_loc.cpu() - face_mbox_conf = face_mbox_conf.cpu() - output = self.detect.forward(face_mbox_loc, - self.softmax(face_mbox_conf), - priors).cpu() - return output - - def load_weights(self, base_file): - other, ext = os.path.splitext(base_file) - if ext == '.pkl' or '.pth': - print('Loading weights into state dict...') - mdata = torch.load(base_file, - map_location=lambda storage, loc: storage) - weights = mdata['weight'] - epoch = mdata['epoch'] - self.load_state_dict(weights) - print('Finished!') - else: - print('Sorry only .pth and .pkl files supported.') - return epoch - - def xavier(self, param): - with torch.no_grad(): - init.xavier_uniform(param) - - def weights_init(self, m): - if isinstance(m, nn.Conv2d): - - self.xavier(m.weight) - if 'bias' in m.state_dict().keys(): - m.bias.data.zero_() - - if isinstance(m, nn.ConvTranspose2d): - self.xavier(m.weight.data) - if 'bias' in m.state_dict().keys(): - m.bias.data.zero_() - - if isinstance(m, nn.BatchNorm2d): - m.weight.data[...] = 1 - m.bias.data.zero_() - - -vgg_cfg = [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 'M', 512, 512, 512, 'M', - 512, 512, 512, 'M'] - -extras_cfg = [256, 'S', 512, 128, 'S', 256] - -lfpn_cpm_cfg = [256, 512, 512, 1024, 512, 256] - -multibox_cfg = [512, 512, 512, 512, 512, 512] - - -def vgg(cfg, i, batch_norm=False): - layers = [] - in_channels = i - for v in cfg: - if v == 'M': - layers += [nn.MaxPool2d(kernel_size=2, stride=2)] - elif v == 'C': - layers += [nn.MaxPool2d(kernel_size=2, stride=2, ceil_mode=True)] - else: - conv2d = nn.Conv2d(in_channels, v, kernel_size=3, padding=1) - if batch_norm: - layers += [conv2d, nn.BatchNorm2d(v), nn.ReLU(inplace=True)] - else: - layers += [conv2d, nn.ReLU(inplace=True)] - in_channels = v - conv6 = nn.Conv2d(512, 1024, kernel_size=3, padding=6, dilation=6) - conv7 = nn.Conv2d(1024, 1024, kernel_size=1) - layers += [conv6, - nn.ReLU(inplace=True), conv7, nn.ReLU(inplace=True)] - return layers - - -def add_extras(cfg, i, batch_norm=False): - # Extra layers added to VGG for feature scaling - layers = [] - in_channels = i - flag = False - for k, v in enumerate(cfg): - if in_channels != 'S': - if v == 'S': - layers += [nn.Conv2d(in_channels, cfg[k + 1], - kernel_size=(1, 3)[flag], stride=2, padding=1)] - else: - layers += [nn.Conv2d(in_channels, v, kernel_size=(1, 3)[flag])] - flag = not flag - in_channels = v - return layers - - -def add_lfpn_cpm(cfg): - lfpn_topdown_layers = [] - lfpn_latlayer = [] - cpm_layers = [] - - for k, v in enumerate(cfg): - cpm_layers.append(CPM(v)) - - fpn_list = cfg[::-1][2:] - for k, v in enumerate(fpn_list[:-1]): - lfpn_latlayer.append(nn.Conv2d( - fpn_list[k + 1], fpn_list[k + 1], kernel_size=1, stride=1, padding=0)) - lfpn_topdown_layers.append(nn.Conv2d( - v, fpn_list[k + 1], kernel_size=1, stride=1, padding=0)) - - return (lfpn_topdown_layers, lfpn_latlayer, cpm_layers) - - -def multibox(vgg, extra_layers): - loc_layers = [] - conf_layers = [] - vgg_source = [21, 28, -2] - i = 0 - loc_layers += [nn.Conv2d(multibox_cfg[i], - 8, kernel_size=3, padding=1)] - conf_layers += [nn.Conv2d(multibox_cfg[i], - 8, kernel_size=3, padding=1)] - i += 1 - for k, v in enumerate(vgg_source): - loc_layers += [nn.Conv2d(multibox_cfg[i], - 8, kernel_size=3, padding=1)] - conf_layers += [nn.Conv2d(multibox_cfg[i], - 6, kernel_size=3, padding=1)] - i += 1 - for k, v in enumerate(extra_layers[1::2], 2): - loc_layers += [nn.Conv2d(multibox_cfg[i], - 8, kernel_size=3, padding=1)] - conf_layers += [nn.Conv2d(multibox_cfg[i], - 6, kernel_size=3, padding=1)] - i += 1 - return vgg, extra_layers, (loc_layers, conf_layers) - - -def build_net(phase, num_classes=2): - base_, extras_, head_ = multibox( - vgg(vgg_cfg, 3), add_extras((extras_cfg), 1024)) - lfpn_cpm = add_lfpn_cpm(lfpn_cpm_cfg) - return PyramidBox(phase, base_, extras_, lfpn_cpm, head_, num_classes) - - -if __name__ == '__main__': - inputs = Variable(torch.randn(1, 3, 640, 640)) - net = build_net('train', num_classes=2) - print(net) - out = net(inputs) +#-*- coding:utf-8 -*- +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import time +import torch +import torch.nn as nn +import torch.nn.init as init +from torch.autograd import Function +import torch.nn.functional as F +from torch.autograd import Variable +import os +from layers import * +from data.config import cfg +import numpy as np +import torch.npu +class conv_bn(nn.Module): + """docstring for conv""" + + def __init__(self, + in_plane, + out_plane, + kernel_size, + stride, + padding): + super(conv_bn, self).__init__() + self.conv1 = nn.Conv2d(in_plane, out_plane, + kernel_size=kernel_size, stride=stride, padding=padding) + self.bn1 = nn.BatchNorm2d(out_plane) + + def forward(self, x): + x = self.conv1(x) + return self.bn1(x) + + + +class CPM(nn.Module): + """docstring for CPM""" + + def __init__(self, in_plane): + super(CPM, self).__init__() + self.branch1 = conv_bn(in_plane, 1024, 1, 1, 0) + self.branch2a = conv_bn(in_plane, 256, 1, 1, 0) + self.branch2b = conv_bn(256, 256, 3, 1, 1) + self.branch2c = conv_bn(256, 1024, 1, 1, 0) + + self.ssh_1 = nn.Conv2d(1024, 256, kernel_size=3, stride=1, padding=1) + self.ssh_dimred = nn.Conv2d( + 1024, 128, kernel_size=3, stride=1, padding=1) + self.ssh_2 = nn.Conv2d(128, 128, kernel_size=3, stride=1, padding=1) + self.ssh_3a = nn.Conv2d(128, 128, kernel_size=3, stride=1, padding=1) + self.ssh_3b = nn.Conv2d(128, 128, kernel_size=3, stride=1, padding=1) + + def forward(self, x): + out_residual = self.branch1(x) + x = F.relu(self.branch2a(x), inplace=True) + x = F.relu(self.branch2b(x), inplace=True) + x = self.branch2c(x) + rescomb = F.relu(x + out_residual, inplace=True) + ssh1 = self.ssh_1(rescomb) + ssh_dimred = F.relu(self.ssh_dimred(rescomb), inplace=True) + ssh_2 = self.ssh_2(ssh_dimred) + ssh_3a = F.relu(self.ssh_3a(ssh_dimred), inplace=True) + ssh_3b = self.ssh_3b(ssh_3a) + + ssh_out = torch.cat([ssh1, ssh_2, ssh_3b], dim=1) + ssh_out = F.relu(ssh_out, inplace=True) + return ssh_out + + +class PyramidBox(nn.Module): + """docstring for PyramidBox""" + + def __init__(self, + phase, + base, + extras, + lfpn_cpm, + head, + num_classes): + super(PyramidBox, self).__init__() + + self.vgg = nn.ModuleList(base) + self.extras = nn.ModuleList(extras) + self.bn64 = nn.BatchNorm2d(64) + self.L2Norm3_3 = L2Norm(256, 10) + self.L2Norm4_3 = L2Norm(512, 8) + self.L2Norm5_3 = L2Norm(512, 5) + + self.lfpn_topdown = nn.ModuleList(lfpn_cpm[0]) + self.lfpn_later = nn.ModuleList(lfpn_cpm[1]) + self.cpm = nn.ModuleList(lfpn_cpm[2]) + + self.loc_layers = nn.ModuleList(head[0]) + self.conf_layers = nn.ModuleList(head[1]) + + + + self.is_infer = False + if phase == 'test': + self.softmax = nn.Softmax(dim=-1) + self.detect = Detect(cfg) + self.is_infer = True + + def _upsample_prod(self, x, y): + _, _, H, W = y.size() + return F.interpolate(x, size=(H, W), mode='bilinear') * y + + def forward(self, x): + + use_npu = False + size = x.size()[2:] + bn_index = 0 + for k in range(16): + x = self.vgg[k](x) + if isinstance(self.vgg[k], nn.Conv2d): + if k == 2: + x = self.bn64(x) + conv3_3 = x + for k in range(16, 23): + x = self.vgg[k](x) + conv4_3 = x + for k in range(23, 30): + x = self.vgg[k](x) + + conv5_3 = x + + for k in range(30, len(self.vgg)): + x = self.vgg[k](x) + + convfc_7 = x + + for k in range(2): + x = F.relu(self.extras[k](x), inplace=True)#.npu() + conv6_2 = x + + for k in range(2, 4): + x = F.relu(self.extras[k](x), inplace=True)#.npu() + + conv7_2 = x + + x = F.relu(self.lfpn_topdown[0](convfc_7), inplace=True) + lfpn2_on_conv5 = F.relu(self._upsample_prod( + x, self.lfpn_later[0](conv5_3)), inplace=True) + + x = F.relu(self.lfpn_topdown[1](lfpn2_on_conv5), inplace=True) + lfpn1_on_conv4 = F.relu(self._upsample_prod( + x, self.lfpn_later[1](conv4_3)), inplace=True) + + + x = F.relu(self.lfpn_topdown[2](lfpn1_on_conv4), inplace=True) + lfpn0_on_conv3 = F.relu(self._upsample_prod( + x, self.lfpn_later[2](conv3_3)), inplace=True) + l2norm3 = self.L2Norm3_3(lfpn0_on_conv3) + l2norm4 = self.L2Norm4_3(lfpn1_on_conv4) + l2norm5 = self.L2Norm5_3(lfpn2_on_conv5) + + ssh_conv3_norm = self.cpm[0](l2norm3) + ssh_conv4_norm = self.cpm[1](l2norm4) + ssh_conv5_norm = self.cpm[2](l2norm5) + + ssh_convfc7 = self.cpm[3](convfc_7) + ssh_conv6 = self.cpm[4](conv6_2) + ssh_conv7 = self.cpm[5](conv7_2) + face_locs, face_confs = [], [] + head_locs, head_confs = [], [] + + N = ssh_conv3_norm.size(0) + + + mbox_loc = self.loc_layers[0](ssh_conv3_norm) + + face_loc, head_loc = torch.chunk(mbox_loc, 2, dim=1) + + face_loc = face_loc.permute(0, 2, 3, 1).contiguous().view(N, -1, 4) + if not self.is_infer: + head_loc = head_loc.permute(0, 2, 3, 1).contiguous().view(N, -1, 4) + + mbox_conf = self.conf_layers[0](ssh_conv3_norm) + + face_conf1 = mbox_conf[:, 3:4, :, :] + face_conf3_maxin, _ = torch.max(mbox_conf[:, 0:3, :, :], dim=1, keepdim=True) + + face_conf = torch.cat((face_conf3_maxin, face_conf1), dim=1) + face_conf = face_conf.permute(0, 2, 3, 1).contiguous().view(N, -1, 2) + if not self.is_infer: + head_conf3_maxin, _ = torch.max(mbox_conf[:, 4:7, :, :], dim=1, keepdim=True) + head_conf1 = mbox_conf[:, 7:, :, :] + + head_conf = torch.cat((head_conf3_maxin, head_conf1), dim=1) + head_conf = head_conf.permute(0, 2, 3, 1).contiguous().view(N, -1, 2) + + face_locs.append(face_loc) + face_confs.append(face_conf) + if not self.is_infer: + head_locs.append(head_loc) + head_confs.append(head_conf) + + + inputs = [ssh_conv4_norm, ssh_conv5_norm, + ssh_convfc7, ssh_conv6, ssh_conv7] + + feature_maps = [] + feat_size = ssh_conv3_norm.size()[2:] + feature_maps.append([feat_size[0], feat_size[1]]) + + for i, feat in enumerate(inputs): + + feat_size = feat.size()[2:] + feature_maps.append([feat_size[0], feat_size[1]]) + mbox_loc = self.loc_layers[i + 1](feat) + + face_loc, head_loc = torch.chunk(mbox_loc, 2, dim=1) + + face_loc = face_loc.permute(0, 2, 3, 1).contiguous().view(N, -1, 4) + if not self.is_infer: + head_loc = head_loc.permute(0, 2, 3, 1).contiguous().view(N, -1, 4) + + mbox_conf = self.conf_layers[i + 1](feat) + + face_conf1 = mbox_conf[:, 0:1, :, :] + face_conf3_maxin, _ = torch.max( + mbox_conf[:, 1:4, :, :], dim=1, keepdim=True) + + face_conf = torch.cat((face_conf1, face_conf3_maxin), dim=1) + + face_conf = face_conf.permute( + 0, 2, 3, 1).contiguous().view(N, -1, 2) + + if not self.is_infer: + head_conf = mbox_conf[:, 4:, :, :].permute( + 0, 2, 3, 1).contiguous().view(N, -1, 2) + + face_locs.append(face_loc) + face_confs.append(face_conf) + + if not self.is_infer: + head_locs.append(head_loc) + head_confs.append(head_conf) + + face_mbox_loc = torch.cat(face_locs, dim=1) + face_mbox_conf = torch.cat(face_confs, dim=1) + + if not self.is_infer: + head_mbox_loc = torch.cat(head_locs, dim=1) + head_mbox_conf = torch.cat(head_confs, dim=1) + + + priors_boxes = PriorBox(size, feature_maps, cfg) + with torch.no_grad(): + priors = Variable(priors_boxes.forward()) + + if not self.is_infer: + output = (face_mbox_loc, face_mbox_conf, + head_mbox_loc, head_mbox_conf, priors) + else: + face_mbox_loc = face_mbox_loc.cpu() + face_mbox_conf = face_mbox_conf.cpu() + output = self.detect.forward(face_mbox_loc, + self.softmax(face_mbox_conf), + priors).cpu() + return output + + def load_weights(self, base_file): + other, ext = os.path.splitext(base_file) + if ext == '.pkl' or '.pth': + print('Loading weights into state dict...') + mdata = torch.load(base_file, + map_location=lambda storage, loc: storage) + weights = mdata['weight'] + epoch = mdata['epoch'] + self.load_state_dict(weights) + print('Finished!') + else: + print('Sorry only .pth and .pkl files supported.') + return epoch + + def xavier(self, param): + with torch.no_grad(): + init.xavier_uniform(param) + + def weights_init(self, m): + if isinstance(m, nn.Conv2d): + + self.xavier(m.weight) + if 'bias' in m.state_dict().keys(): + m.bias.data.zero_() + + if isinstance(m, nn.ConvTranspose2d): + self.xavier(m.weight.data) + if 'bias' in m.state_dict().keys(): + m.bias.data.zero_() + + if isinstance(m, nn.BatchNorm2d): + m.weight.data[...] = 1 + m.bias.data.zero_() + + +vgg_cfg = [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 'M', 512, 512, 512, 'M', + 512, 512, 512, 'M'] + +extras_cfg = [256, 'S', 512, 128, 'S', 256] + +lfpn_cpm_cfg = [256, 512, 512, 1024, 512, 256] + +multibox_cfg = [512, 512, 512, 512, 512, 512] + + +def vgg(cfg, i, batch_norm=False): + layers = [] + in_channels = i + for v in cfg: + if v == 'M': + layers += [nn.MaxPool2d(kernel_size=2, stride=2)] + elif v == 'C': + layers += [nn.MaxPool2d(kernel_size=2, stride=2, ceil_mode=True)] + else: + conv2d = nn.Conv2d(in_channels, v, kernel_size=3, padding=1) + if batch_norm: + layers += [conv2d, nn.BatchNorm2d(v), nn.ReLU(inplace=True)] + else: + layers += [conv2d, nn.ReLU(inplace=True)] + in_channels = v + conv6 = nn.Conv2d(512, 1024, kernel_size=3, padding=6, dilation=6) + conv7 = nn.Conv2d(1024, 1024, kernel_size=1) + layers += [conv6, + nn.ReLU(inplace=True), conv7, nn.ReLU(inplace=True)] + return layers + + +def add_extras(cfg, i, batch_norm=False): + # Extra layers added to VGG for feature scaling + layers = [] + in_channels = i + flag = False + for k, v in enumerate(cfg): + if in_channels != 'S': + if v == 'S': + layers += [nn.Conv2d(in_channels, cfg[k + 1], + kernel_size=(1, 3)[flag], stride=2, padding=1)] + else: + layers += [nn.Conv2d(in_channels, v, kernel_size=(1, 3)[flag])] + flag = not flag + in_channels = v + return layers + + +def add_lfpn_cpm(cfg): + lfpn_topdown_layers = [] + lfpn_latlayer = [] + cpm_layers = [] + + for k, v in enumerate(cfg): + cpm_layers.append(CPM(v)) + + fpn_list = cfg[::-1][2:] + for k, v in enumerate(fpn_list[:-1]): + lfpn_latlayer.append(nn.Conv2d( + fpn_list[k + 1], fpn_list[k + 1], kernel_size=1, stride=1, padding=0)) + lfpn_topdown_layers.append(nn.Conv2d( + v, fpn_list[k + 1], kernel_size=1, stride=1, padding=0)) + + return (lfpn_topdown_layers, lfpn_latlayer, cpm_layers) + + +def multibox(vgg, extra_layers): + loc_layers = [] + conf_layers = [] + vgg_source = [21, 28, -2] + i = 0 + loc_layers += [nn.Conv2d(multibox_cfg[i], + 8, kernel_size=3, padding=1)] + conf_layers += [nn.Conv2d(multibox_cfg[i], + 8, kernel_size=3, padding=1)] + i += 1 + for k, v in enumerate(vgg_source): + loc_layers += [nn.Conv2d(multibox_cfg[i], + 8, kernel_size=3, padding=1)] + conf_layers += [nn.Conv2d(multibox_cfg[i], + 6, kernel_size=3, padding=1)] + i += 1 + for k, v in enumerate(extra_layers[1::2], 2): + loc_layers += [nn.Conv2d(multibox_cfg[i], + 8, kernel_size=3, padding=1)] + conf_layers += [nn.Conv2d(multibox_cfg[i], + 6, kernel_size=3, padding=1)] + i += 1 + return vgg, extra_layers, (loc_layers, conf_layers) + + +def build_net(phase, num_classes=2): + base_, extras_, head_ = multibox( + vgg(vgg_cfg, 3), add_extras((extras_cfg), 1024)) + lfpn_cpm = add_lfpn_cpm(lfpn_cpm_cfg) + return PyramidBox(phase, base_, extras_, lfpn_cpm, head_, num_classes) + + +if __name__ == '__main__': + inputs = Variable(torch.randn(1, 3, 640, 640)) + net = build_net('train', num_classes=2) + print(net) + out = net(inputs) diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/requirements.txt b/PyTorch/contrib/cv/detection/Pyramidbox/requirements.txt index 570522f1dbe893f9ea9b5b92d490be7e6729a1e4..cc42ce9b3fe7d10a57d89ff98154f33342fe4263 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/requirements.txt +++ b/PyTorch/contrib/cv/detection/Pyramidbox/requirements.txt @@ -1,26 +1,26 @@ -apex 0.1+ascend.20210825 -backcall -certifi -Cython -easydict -ipython -matplotlib-inline -mpmath -numpy -opencv-python -parso -pexpect -pickleshare -Pillow -scipy -six -sympy -te -tensor-fused-plugin 0.1+ascend -topi 0.4.0 -torch 1.5.0+ascend.post3.20210825 -torchvision 0.6.0a0+b68adcf -tqdm -traitlets -urllib3 +apex 0.1+ascend.20210825 +backcall +certifi +Cython +easydict +ipython +matplotlib-inline +mpmath +numpy +opencv-python +parso +pexpect +pickleshare +Pillow +scipy +six +sympy +te +tensor-fused-plugin 0.1+ascend +topi 0.4.0 +torch 1.5.0+ascend.post3.20210825 +torchvision 0.6.0a0+b68adcf +tqdm +traitlets +urllib3 wcwidth \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/tools/afw_test.py b/PyTorch/contrib/cv/detection/Pyramidbox/tools/afw_test.py index 0402237e25bf5fd714f3775b32170ac40db0b69c..291c9342b9cf43472b2b98cf0fc196cc5adf7fd1 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/tools/afw_test.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/tools/afw_test.py @@ -1,140 +1,140 @@ -#-*- coding:utf-8 -*- -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - -import os -import torch -import argparse -import torch.nn as nn -import torch.utils.data as data -import torch.backends.cudnn as cudnn -import torchvision.transforms as transforms -import os.path as osp - -import cv2 -import time -import numpy as np -from PIL import Image - -from data.config import cfg -from pyramidbox import build_net -from torch.autograd import Variable -from utils.augmentations import to_chw_bgr - - -parser = argparse.ArgumentParser(description='pyramidbox evaluatuon afw') -parser.add_argument('--model', - type=str,default='weights/pyramidbox.pth', help='trained model') -parser.add_argument('--thresh', - default=0.1, type=float, - help='Final confidence threshold') -args = parser.parse_args() - -use_cuda = torch.cuda.is_available() - -if use_cuda: - torch.set_default_tensor_type('torch.cuda.FloatTensor') -else: - torch.set_default_tensor_type('torch.FloatTensor') - -AFW_IMG_DIR = os.path.join(cfg.FACE.AFW_DIR, 'images') -AFW_RESULT_DIR = os.path.join(cfg.FACE.AFW_DIR, 'pyramidbox') -AFW_RESULT_IMG_DIR = os.path.join(AFW_RESULT_DIR, 'images') - -if not os.path.exists(AFW_RESULT_IMG_DIR): - os.makedirs(AFW_RESULT_IMG_DIR) - - -def detect_face(net, img, thresh): - height, width, _ = img.shape - im_shrink = 640.0 / max(height, width) - image = cv2.resize(img, None, None, fx=im_shrink, - fy=im_shrink, interpolation=cv2.INTER_LINEAR).copy() - - x = to_chw_bgr(image) - x = x.astype('float32') - x -= cfg.img_mean - x = x[[2, 1, 0], :, :] - - x = Variable(torch.from_numpy(x).unsqueeze(0)) - if use_cuda: - x = x.cuda() - - y = net(x) - detections = y.data - scale = torch.Tensor([img.shape[1], img.shape[0], - img.shape[1], img.shape[0]]) - - bboxes = [] - for i in range(detections.size(1)): - j = 0 - while detections[0, i, j, 0] >= thresh: - box = [] - score = detections[0, i, j, 0] - pt = (detections[0, i, j, 1:] * scale).cpu().numpy().astype(np.int) - j += 1 - box += [pt[0], pt[1], pt[2], pt[3], score] - box[1] += 0.2 * (box[3] - box[1] + 1) - bboxes += [box] - - return bboxes - - -if __name__ == '__main__': - net = build_net('test', cfg.NUM_CLASSES) - net.load_state_dict(torch.load(args.model)) - net.eval() - - if use_cuda: - net.cuda() - cudnn.benckmark = True - - #transform = S3FDBasicTransform(cfg.INPUT_SIZE, cfg.MEANS) - - counter = 0 - txt_out = os.path.join(AFW_RESULT_DIR, 'pyramidbox_dets.txt') - txt_in = os.path.join('./tools/afw_img_list.txt') - - fout = open(txt_out, 'w') - fin = open(txt_in, 'r') - - for line in fin.readlines(): - line = line.strip() - img_file = os.path.join(AFW_IMG_DIR, line + '.jpg') - out_file = os.path.join(AFW_RESULT_IMG_DIR, line + '.jpg') - counter += 1 - t1 = time.time() - #img = cv2.imread(img_file, cv2.IMREAD_COLOR) - img = Image.open(img_file) - if img.mode == 'L': - img = img.convert('RGB') - img = np.array(img) - bboxes = detect_face(net, img, args.thresh) - t2 = time.time() - print('Detect %04d th image costs %.4f' % (counter, t2 - t1)) - for bbox in bboxes: - x1, y1, x2, y2, score = bbox - fout.write('{:s} {:.3f} {:.1f} {:.1f} {:.1f} {:.1f}\n'.format( - line, score, x1, y1, x2, y2)) - for bbox in bboxes: - x1, y1, x2, y2, score = bbox - x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2) - cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2) - cv2.imwrite(out_file, img) - - fout.close() - fin.close() +#-*- coding:utf-8 -*- +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + +import os +import torch +import argparse +import torch.nn as nn +import torch.utils.data as data +import torch.backends.cudnn as cudnn +import torchvision.transforms as transforms +import os.path as osp + +import cv2 +import time +import numpy as np +from PIL import Image + +from data.config import cfg +from pyramidbox import build_net +from torch.autograd import Variable +from utils.augmentations import to_chw_bgr + + +parser = argparse.ArgumentParser(description='pyramidbox evaluatuon afw') +parser.add_argument('--model', + type=str,default='weights/pyramidbox.pth', help='trained model') +parser.add_argument('--thresh', + default=0.1, type=float, + help='Final confidence threshold') +args = parser.parse_args() + +use_cuda = torch.cuda.is_available() + +if use_cuda: + torch.set_default_tensor_type('torch.cuda.FloatTensor') +else: + torch.set_default_tensor_type('torch.FloatTensor') + +AFW_IMG_DIR = os.path.join(cfg.FACE.AFW_DIR, 'images') +AFW_RESULT_DIR = os.path.join(cfg.FACE.AFW_DIR, 'pyramidbox') +AFW_RESULT_IMG_DIR = os.path.join(AFW_RESULT_DIR, 'images') + +if not os.path.exists(AFW_RESULT_IMG_DIR): + os.makedirs(AFW_RESULT_IMG_DIR) + + +def detect_face(net, img, thresh): + height, width, _ = img.shape + im_shrink = 640.0 / max(height, width) + image = cv2.resize(img, None, None, fx=im_shrink, + fy=im_shrink, interpolation=cv2.INTER_LINEAR).copy() + + x = to_chw_bgr(image) + x = x.astype('float32') + x -= cfg.img_mean + x = x[[2, 1, 0], :, :] + + x = Variable(torch.from_numpy(x).unsqueeze(0)) + if use_cuda: + x = x.cuda() + + y = net(x) + detections = y.data + scale = torch.Tensor([img.shape[1], img.shape[0], + img.shape[1], img.shape[0]]) + + bboxes = [] + for i in range(detections.size(1)): + j = 0 + while detections[0, i, j, 0] >= thresh: + box = [] + score = detections[0, i, j, 0] + pt = (detections[0, i, j, 1:] * scale).cpu().numpy().astype(np.int) + j += 1 + box += [pt[0], pt[1], pt[2], pt[3], score] + box[1] += 0.2 * (box[3] - box[1] + 1) + bboxes += [box] + + return bboxes + + +if __name__ == '__main__': + net = build_net('test', cfg.NUM_CLASSES) + net.load_state_dict(torch.load(args.model)) + net.eval() + + if use_cuda: + net.cuda() + cudnn.benckmark = True + + #transform = S3FDBasicTransform(cfg.INPUT_SIZE, cfg.MEANS) + + counter = 0 + txt_out = os.path.join(AFW_RESULT_DIR, 'pyramidbox_dets.txt') + txt_in = os.path.join('./tools/afw_img_list.txt') + + fout = open(txt_out, 'w') + fin = open(txt_in, 'r') + + for line in fin.readlines(): + line = line.strip() + img_file = os.path.join(AFW_IMG_DIR, line + '.jpg') + out_file = os.path.join(AFW_RESULT_IMG_DIR, line + '.jpg') + counter += 1 + t1 = time.time() + #img = cv2.imread(img_file, cv2.IMREAD_COLOR) + img = Image.open(img_file) + if img.mode == 'L': + img = img.convert('RGB') + img = np.array(img) + bboxes = detect_face(net, img, args.thresh) + t2 = time.time() + print('Detect %04d th image costs %.4f' % (counter, t2 - t1)) + for bbox in bboxes: + x1, y1, x2, y2, score = bbox + fout.write('{:s} {:.3f} {:.1f} {:.1f} {:.1f} {:.1f}\n'.format( + line, score, x1, y1, x2, y2)) + for bbox in bboxes: + x1, y1, x2, y2, score = bbox + x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2) + cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2) + cv2.imwrite(out_file, img) + + fout.close() + fin.close() diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/tools/fddb_test.py b/PyTorch/contrib/cv/detection/Pyramidbox/tools/fddb_test.py index 4958a67effa71bea4f164cfca2c66d39b7382901..1fede8bd71a2a02b6f23b97ae4b5d28f2a434299 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/tools/fddb_test.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/tools/fddb_test.py @@ -1,156 +1,156 @@ -#-*- coding:utf-8 -*- -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - -import os -import sys -import torch -import argparse -import torch.nn as nn -import torch.utils.data as data -import torch.backends.cudnn as cudnn -import torchvision.transforms as transforms - -import cv2 -import time -import numpy as np -from PIL import Image - -from data.config import cfg -from pyramidbox import build_net -from torch.autograd import Variable -from utils.augmentations import to_chw_bgr - -parser = argparse.ArgumentParser(description='pyramidbox evaluatuon fddb') -parser.add_argument('--model', - type=str, - default='weights/pyramidbox.pth', help='trained model') -parser.add_argument('--thresh', - default=0.1, type=float, - help='Final confidence threshold') -args = parser.parse_args() - - -use_cuda = torch.cuda.is_available() - -if use_cuda: - torch.set_default_tensor_type('torch.cuda.FloatTensor') -else: - torch.set_default_tensor_type('torch.FloatTensor') - - -FDDB_IMG_DIR = os.path.join(cfg.FACE.FDDB_DIR, 'images') -FDDB_FOLD_DIR = os.path.join(cfg.FACE.FDDB_DIR, 'FDDB-folds') -FDDB_RESULT_DIR = os.path.join(cfg.FACE.FDDB_DIR, 'pyramidbox') -FDDB_RESULT_IMG_DIR = os.path.join(FDDB_RESULT_DIR, 'images') - -if not os.path.exists(FDDB_RESULT_IMG_DIR): - os.makedirs(FDDB_RESULT_IMG_DIR) - - -def detect_face(net, img, thresh): - height, width, _ = img.shape - x = to_chw_bgr(img) - x = x.astype('float32') - x -= cfg.img_mean - x = x[[2, 1, 0], :, :] - - x = Variable(torch.from_numpy(x).unsqueeze(0)) - if use_cuda: - x = x.cuda() - - y = net(x) - detections = y.data - scale = torch.Tensor([img.shape[1], img.shape[0], - img.shape[1], img.shape[0]]) - - bboxes = [] - for i in range(detections.size(1)): - j = 0 - while detections[0, i, j, 0] >= thresh: - box = [] - score = detections[0, i, j, 0] - pt = (detections[0, i, j, 1:] * scale).cpu().numpy().astype(np.int) - j += 1 - box += [pt[0], pt[1], pt[2] - pt[0], pt[3] - pt[1], score] - bboxes += [box] - - return bboxes - - -if __name__ == '__main__': - net = build_net('test', cfg.NUM_CLASSES) - net.load_state_dict(torch.load(args.model)) - net.eval() - - if use_cuda: - net.cuda() - cudnn.benckmark = True - - #transform = S3FDBasicTransform(cfg.INPUT_SIZE, cfg.MEANS) - - counter = 0 - - for i in range(10): - txt_in = os.path.join(FDDB_FOLD_DIR, 'FDDB-fold-%02d.txt' % (i + 1)) - txt_out = os.path.join(FDDB_RESULT_DIR, 'fold-%02d-out.txt' % (i + 1)) - answer_in = os.path.join( - FDDB_FOLD_DIR, 'FDDB-fold-%02d-ellipseList.txt' % (i + 1)) - with open(txt_in, 'r') as fr: - lines = fr.readlines() - fout = open(txt_out, 'w') - ain = open(answer_in, 'r') - for line in lines: - line = line.strip() - img_file = os.path.join(FDDB_IMG_DIR, line + '.jpg') - out_file = os.path.join( - FDDB_RESULT_IMG_DIR, line.replace('/', '_') + '.jpg') - counter += 1 - t1 = time.time() - #img = cv2.imread(img_file, cv2.IMREAD_COLOR) - img = Image.open(img_file) - if img.mode == 'L': - img = img.convert('RGB') - img = np.array(img) - bboxes = detect_face(net, img, args.thresh) - t2 = time.time() - print('Detect %04d th image costs %.4f' % (counter, t2 - t1)) - fout.write('%s\n' % line) - fout.write('%d\n' % len(bboxes)) - for bbox in bboxes: - x1, y1, w, h, score = bbox - fout.write('%d %d %d %d %lf\n' % (x1, y1, w, h, score)) - ain.readline() - n = int(ain.readline().strip()) - for i in range(n): - line = ain.readline().strip() - line_data = [float(_) for _ in line.split(' ')[:5]] - major_axis_radius, minor_axis_radius, angle, center_x, center_y = line_data - angle = angle / 3.1415926 * 180. - center_x, center_y = int(center_x), int(center_y) - major_axis_radius, minor_axis_radius = int( - major_axis_radius), int(minor_axis_radius) - cv2.ellipse(img, (center_x, center_y), (major_axis_radius, - minor_axis_radius), angle, 0, 360, (255, 0, 0), 2) - - for bbox in bboxes: - x1, y1, w, h, score = bbox - x1, y1, x2, y2 = int(x1), int(y1), int(x1 + w), int(y1 + h) - cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2) - cv2.imwrite(out_file, img) - fout.close() - ain.close() +#-*- coding:utf-8 -*- +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + +import os +import sys +import torch +import argparse +import torch.nn as nn +import torch.utils.data as data +import torch.backends.cudnn as cudnn +import torchvision.transforms as transforms + +import cv2 +import time +import numpy as np +from PIL import Image + +from data.config import cfg +from pyramidbox import build_net +from torch.autograd import Variable +from utils.augmentations import to_chw_bgr + +parser = argparse.ArgumentParser(description='pyramidbox evaluatuon fddb') +parser.add_argument('--model', + type=str, + default='weights/pyramidbox.pth', help='trained model') +parser.add_argument('--thresh', + default=0.1, type=float, + help='Final confidence threshold') +args = parser.parse_args() + + +use_cuda = torch.cuda.is_available() + +if use_cuda: + torch.set_default_tensor_type('torch.cuda.FloatTensor') +else: + torch.set_default_tensor_type('torch.FloatTensor') + + +FDDB_IMG_DIR = os.path.join(cfg.FACE.FDDB_DIR, 'images') +FDDB_FOLD_DIR = os.path.join(cfg.FACE.FDDB_DIR, 'FDDB-folds') +FDDB_RESULT_DIR = os.path.join(cfg.FACE.FDDB_DIR, 'pyramidbox') +FDDB_RESULT_IMG_DIR = os.path.join(FDDB_RESULT_DIR, 'images') + +if not os.path.exists(FDDB_RESULT_IMG_DIR): + os.makedirs(FDDB_RESULT_IMG_DIR) + + +def detect_face(net, img, thresh): + height, width, _ = img.shape + x = to_chw_bgr(img) + x = x.astype('float32') + x -= cfg.img_mean + x = x[[2, 1, 0], :, :] + + x = Variable(torch.from_numpy(x).unsqueeze(0)) + if use_cuda: + x = x.cuda() + + y = net(x) + detections = y.data + scale = torch.Tensor([img.shape[1], img.shape[0], + img.shape[1], img.shape[0]]) + + bboxes = [] + for i in range(detections.size(1)): + j = 0 + while detections[0, i, j, 0] >= thresh: + box = [] + score = detections[0, i, j, 0] + pt = (detections[0, i, j, 1:] * scale).cpu().numpy().astype(np.int) + j += 1 + box += [pt[0], pt[1], pt[2] - pt[0], pt[3] - pt[1], score] + bboxes += [box] + + return bboxes + + +if __name__ == '__main__': + net = build_net('test', cfg.NUM_CLASSES) + net.load_state_dict(torch.load(args.model)) + net.eval() + + if use_cuda: + net.cuda() + cudnn.benckmark = True + + #transform = S3FDBasicTransform(cfg.INPUT_SIZE, cfg.MEANS) + + counter = 0 + + for i in range(10): + txt_in = os.path.join(FDDB_FOLD_DIR, 'FDDB-fold-%02d.txt' % (i + 1)) + txt_out = os.path.join(FDDB_RESULT_DIR, 'fold-%02d-out.txt' % (i + 1)) + answer_in = os.path.join( + FDDB_FOLD_DIR, 'FDDB-fold-%02d-ellipseList.txt' % (i + 1)) + with open(txt_in, 'r') as fr: + lines = fr.readlines() + fout = open(txt_out, 'w') + ain = open(answer_in, 'r') + for line in lines: + line = line.strip() + img_file = os.path.join(FDDB_IMG_DIR, line + '.jpg') + out_file = os.path.join( + FDDB_RESULT_IMG_DIR, line.replace('/', '_') + '.jpg') + counter += 1 + t1 = time.time() + #img = cv2.imread(img_file, cv2.IMREAD_COLOR) + img = Image.open(img_file) + if img.mode == 'L': + img = img.convert('RGB') + img = np.array(img) + bboxes = detect_face(net, img, args.thresh) + t2 = time.time() + print('Detect %04d th image costs %.4f' % (counter, t2 - t1)) + fout.write('%s\n' % line) + fout.write('%d\n' % len(bboxes)) + for bbox in bboxes: + x1, y1, w, h, score = bbox + fout.write('%d %d %d %d %lf\n' % (x1, y1, w, h, score)) + ain.readline() + n = int(ain.readline().strip()) + for i in range(n): + line = ain.readline().strip() + line_data = [float(_) for _ in line.split(' ')[:5]] + major_axis_radius, minor_axis_radius, angle, center_x, center_y = line_data + angle = angle / 3.1415926 * 180. + center_x, center_y = int(center_x), int(center_y) + major_axis_radius, minor_axis_radius = int( + major_axis_radius), int(minor_axis_radius) + cv2.ellipse(img, (center_x, center_y), (major_axis_radius, + minor_axis_radius), angle, 0, 360, (255, 0, 0), 2) + + for bbox in bboxes: + x1, y1, w, h, score = bbox + x1, y1, x2, y2 = int(x1), int(y1), int(x1 + w), int(y1 + h) + cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2) + cv2.imwrite(out_file, img) + fout.close() + ain.close() diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/tools/pascal_test.py b/PyTorch/contrib/cv/detection/Pyramidbox/tools/pascal_test.py index c8f6a5429b4a58c0d775d18733609f9123d964c9..0a2f7b999add55d923f00e9f0079cdd4ae65c3ec 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/tools/pascal_test.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/tools/pascal_test.py @@ -1,140 +1,140 @@ -#-*- coding:utf-8 -*- -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - -import os -import torch -import argparse -import torch.nn as nn -import torch.utils.data as data -import torch.backends.cudnn as cudnn -import torchvision.transforms as transforms -import os.path as osp - -import cv2 -import time -import numpy as np -from PIL import Image - -from data.config import cfg -from pyramidbox import build_net -from torch.autograd import Variable -from utils.augmentations import to_chw_bgr - -parser = argparse.ArgumentParser(description='pyramidbox evaluatuon pascal') -parser.add_argument('--model', - type=str,default='weights/pyramidbox.pth', - help='trained model') -parser.add_argument('--thresh', - default=0.1, type=float, - help='Final confidence threshold') -args = parser.parse_args() - -use_cuda = torch.cuda.is_available() - -if use_cuda: - torch.set_default_tensor_type('torch.cuda.FloatTensor') -else: - torch.set_default_tensor_type('torch.FloatTensor') - -PASCAL_IMG_DIR = os.path.join(cfg.FACE.PASCAL_DIR, 'images') -PASCAL_RESULT_DIR = os.path.join(cfg.FACE.PASCAL_DIR, 'pyramidbox') -PASCAL_RESULT_IMG_DIR = os.path.join(PASCAL_RESULT_DIR, 'images') - -if not os.path.exists(PASCAL_RESULT_IMG_DIR): - os.makedirs(PASCAL_RESULT_IMG_DIR) - - -def detect_face(net, img, thresh): - height, width, _ = img.shape - im_shrink = 640.0 / max(height, width) - image = cv2.resize(img, None, None, fx=im_shrink, - fy=im_shrink, interpolation=cv2.INTER_LINEAR).copy() - - x = to_chw_bgr(image) - x = x.astype('float32') - x -= cfg.img_mean - x = x[[2, 1, 0], :, :] - - x = Variable(torch.from_numpy(x).unsqueeze(0)) - if use_cuda: - x = x.cuda() - - y = net(x) - detections = y.data - scale = torch.Tensor([img.shape[1], img.shape[0], - img.shape[1], img.shape[0]]) - - bboxes = [] - for i in range(detections.size(1)): - j = 0 - while detections[0, i, j, 0] >= thresh: - box = [] - score = detections[0, i, j, 0] - pt = (detections[0, i, j, 1:] * scale).cpu().numpy().astype(np.int) - j += 1 - box += [pt[0], pt[1], pt[2], pt[3], score] - box[1] += 0.2 * (box[3] - box[1] + 1) - bboxes += [box] - - return bboxes - - -if __name__ == '__main__': - net = build_net('test', cfg.NUM_CLASSES) - net.load_state_dict(torch.load(args.model)) - net.eval() - - if use_cuda: - net.cuda() - cudnn.benckmark = True - - #transform = S3FDBasicTransform(cfg.INPUT_SIZE, cfg.MEANS) - - counter = 0 - txt_out = os.path.join(PASCAL_RESULT_DIR, 'pyramidbox_dets.txt') - txt_in = os.path.join('./tools/pascal_img_list.txt') - - fout = open(txt_out, 'w') - fin = open(txt_in, 'r') - - for line in fin.readlines(): - line = line.strip() - img_file = os.path.join(PASCAL_IMG_DIR, line) - out_file = os.path.join(PASCAL_RESULT_IMG_DIR, line) - counter += 1 - t1 = time.time() - #img = cv2.imread(img_file, cv2.IMREAD_COLOR) - img = Image.open(img_file) - if img.mode == 'L': - img = img.convert('RGB') - img = np.array(img) - bboxes = detect_face(net, img, args.thresh) - t2 = time.time() - print('Detect %04d th image costs %.4f' % (counter, t2 - t1)) - for bbox in bboxes: - x1, y1, x2, y2, score = bbox - fout.write('{:s} {:.3f} {:.1f} {:.1f} {:.1f} {:.1f}\n'.format( - line, score, x1, y1, x2, y2)) - for bbox in bboxes: - x1, y1, x2, y2, score = bbox - x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2) - cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2) - cv2.imwrite(out_file, img) - - fout.close() - fin.close() +#-*- coding:utf-8 -*- +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + +import os +import torch +import argparse +import torch.nn as nn +import torch.utils.data as data +import torch.backends.cudnn as cudnn +import torchvision.transforms as transforms +import os.path as osp + +import cv2 +import time +import numpy as np +from PIL import Image + +from data.config import cfg +from pyramidbox import build_net +from torch.autograd import Variable +from utils.augmentations import to_chw_bgr + +parser = argparse.ArgumentParser(description='pyramidbox evaluatuon pascal') +parser.add_argument('--model', + type=str,default='weights/pyramidbox.pth', + help='trained model') +parser.add_argument('--thresh', + default=0.1, type=float, + help='Final confidence threshold') +args = parser.parse_args() + +use_cuda = torch.cuda.is_available() + +if use_cuda: + torch.set_default_tensor_type('torch.cuda.FloatTensor') +else: + torch.set_default_tensor_type('torch.FloatTensor') + +PASCAL_IMG_DIR = os.path.join(cfg.FACE.PASCAL_DIR, 'images') +PASCAL_RESULT_DIR = os.path.join(cfg.FACE.PASCAL_DIR, 'pyramidbox') +PASCAL_RESULT_IMG_DIR = os.path.join(PASCAL_RESULT_DIR, 'images') + +if not os.path.exists(PASCAL_RESULT_IMG_DIR): + os.makedirs(PASCAL_RESULT_IMG_DIR) + + +def detect_face(net, img, thresh): + height, width, _ = img.shape + im_shrink = 640.0 / max(height, width) + image = cv2.resize(img, None, None, fx=im_shrink, + fy=im_shrink, interpolation=cv2.INTER_LINEAR).copy() + + x = to_chw_bgr(image) + x = x.astype('float32') + x -= cfg.img_mean + x = x[[2, 1, 0], :, :] + + x = Variable(torch.from_numpy(x).unsqueeze(0)) + if use_cuda: + x = x.cuda() + + y = net(x) + detections = y.data + scale = torch.Tensor([img.shape[1], img.shape[0], + img.shape[1], img.shape[0]]) + + bboxes = [] + for i in range(detections.size(1)): + j = 0 + while detections[0, i, j, 0] >= thresh: + box = [] + score = detections[0, i, j, 0] + pt = (detections[0, i, j, 1:] * scale).cpu().numpy().astype(np.int) + j += 1 + box += [pt[0], pt[1], pt[2], pt[3], score] + box[1] += 0.2 * (box[3] - box[1] + 1) + bboxes += [box] + + return bboxes + + +if __name__ == '__main__': + net = build_net('test', cfg.NUM_CLASSES) + net.load_state_dict(torch.load(args.model)) + net.eval() + + if use_cuda: + net.cuda() + cudnn.benckmark = True + + #transform = S3FDBasicTransform(cfg.INPUT_SIZE, cfg.MEANS) + + counter = 0 + txt_out = os.path.join(PASCAL_RESULT_DIR, 'pyramidbox_dets.txt') + txt_in = os.path.join('./tools/pascal_img_list.txt') + + fout = open(txt_out, 'w') + fin = open(txt_in, 'r') + + for line in fin.readlines(): + line = line.strip() + img_file = os.path.join(PASCAL_IMG_DIR, line) + out_file = os.path.join(PASCAL_RESULT_IMG_DIR, line) + counter += 1 + t1 = time.time() + #img = cv2.imread(img_file, cv2.IMREAD_COLOR) + img = Image.open(img_file) + if img.mode == 'L': + img = img.convert('RGB') + img = np.array(img) + bboxes = detect_face(net, img, args.thresh) + t2 = time.time() + print('Detect %04d th image costs %.4f' % (counter, t2 - t1)) + for bbox in bboxes: + x1, y1, x2, y2, score = bbox + fout.write('{:s} {:.3f} {:.1f} {:.1f} {:.1f} {:.1f}\n'.format( + line, score, x1, y1, x2, y2)) + for bbox in bboxes: + x1, y1, x2, y2, score = bbox + x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2) + cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2) + cv2.imwrite(out_file, img) + + fout.close() + fin.close() diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/tools/wider_test.py b/PyTorch/contrib/cv/detection/Pyramidbox/tools/wider_test.py index d79f4c8e0864f3bd3b17bc236b327c0c1d998eba..942d87bb7048de7b5900000de63ea918f2dac238 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/tools/wider_test.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/tools/wider_test.py @@ -1,283 +1,283 @@ -#-*- coding:utf-8 -*- -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - -import os -import torch -import argparse -import torch.nn as nn -import torch.utils.data as data -import torch.backends.cudnn as cudnn -import torchvision.transforms as transforms -import os.path as osp -import time -import cv2 -import time -import numpy as np -from PIL import Image -import scipy.io as sio - -import sys -#sys.path.append("/home/wch/Pyramidbox/") -from data.config import cfg -from pyramidbox import build_net -from torch.autograd import Variable -from utils.augmentations import to_chw_bgr -import torch.npu - -parser = argparse.ArgumentParser(description='pyramidbox evaluatuon wider') -parser.add_argument('--model', type=str, - default="weights/pyramidbox.pth", help='trained model') -parser.add_argument('--thresh', default=0.05, type=float, - help='Final confidence threshold') -parser.add_argument('--data_path', - default=None, type=str, - help='data_path') -args = parser.parse_args() - - -use_npu = torch.npu.is_available() - -def detect_face(net, img, shrink): - if shrink != 1: - img = cv2.resize(img, None, None, fx=shrink, fy=shrink, - interpolation=cv2.INTER_LINEAR) - - x = to_chw_bgr(img) - x = x.astype('float32') - x -= cfg.img_mean - x = x[[2, 1, 0], :, :] - image_x = x.shape[1] - image_y = x.shape[2] - if image_x <2500 and image_y<2500: - x0 = torch.Tensor(x[0]) - x1 = torch.Tensor(x[1]) - x2 = torch.Tensor(x[2]) - pad = nn.ZeroPad2d(padding=(0,2500-image_y,0,2500-image_x)) - x0 = pad(x0) - x1 = pad(x1) - x2 = pad(x2) - x0 =np.array(x0) - x1 =np.array(x1) - x2 =np.array(x2) - x = np.array([x0,x1,x2]) - x = Variable(torch.from_numpy(x).unsqueeze(0)) - - if use_npu: - x = x.npu() - y = net(x) - detections = y.data - detections = detections.cpu().numpy() - - det_conf = detections[0, 1, :, 0] - if image_x < 2500 and image_y < 2500: - det_xmin = 2500 * detections[0, 1, :, 1] / shrink - det_ymin = 2500 * detections[0, 1, :, 2] / shrink - det_xmax = 2500 * detections[0, 1, :, 3] / shrink - det_ymax = 2500 * detections[0, 1, :, 4] / shrink - else: - det_xmin = img.shape[1] * detections[0, 1, :, 1] / shrink - det_ymin = img.shape[0] * detections[0, 1, :, 2] / shrink - det_xmax = img.shape[1] * detections[0, 1, :, 3] / shrink - det_ymax = img.shape[0] * detections[0, 1, :, 4] / shrink - det = np.column_stack((det_xmin, det_ymin, det_xmax, det_ymax, det_conf)) - - keep_index = np.where(det[:, 4] >= args.thresh)[0] - det = det[keep_index, :] - return det - - -def flip_test(net, image, shrink): - image_f = cv2.flip(image, 1) - det_f = detect_face(net, image_f, shrink) - det_t = np.zeros(det_f.shape) - det_t[:, 0] = image.shape[1] - det_f[:, 2] - det_t[:, 1] = det_f[:, 1] - det_t[:, 2] = image.shape[1] - det_f[:, 0] - det_t[:, 3] = det_f[:, 3] - det_t[:, 4] = det_f[:, 4] - return det_t - - -def multi_scale_test(net, image, max_im_shrink): - # shrink detecting and shrink only detect big face - st = 0.5 if max_im_shrink >= 0.75 else 0.5 * max_im_shrink - det_s = detect_face(net, image, st) - index = np.where(np.maximum( - det_s[:, 2] - det_s[:, 0] + 1, det_s[:, 3] - det_s[:, 1] + 1) > 30)[0] - det_s = det_s[index, :] - - # enlarge one times - bt = min(2, max_im_shrink) if max_im_shrink > 1 else ( - st + max_im_shrink) / 2 - det_b = detect_face(net, image, bt) - - # enlarge small image x times for small face - if max_im_shrink > 2: - bt *= 2 - while bt < max_im_shrink: - det_b = np.row_stack((det_b, detect_face(net, image, bt))) - bt *= 2 - det_b = np.row_stack((det_b, detect_face(net, image, max_im_shrink))) - - # enlarge only detect small face - if bt > 1: - index = np.where(np.minimum( - det_b[:, 2] - det_b[:, 0] + 1, det_b[:, 3] - det_b[:, 1] + 1) < 100)[0] - det_b = det_b[index, :] - else: - index = np.where(np.maximum( - det_b[:, 2] - det_b[:, 0] + 1, det_b[:, 3] - det_b[:, 1] + 1) > 30)[0] - det_b = det_b[index, :] - - return det_s, det_b - - -def bbox_vote(det): - order = det[:, 4].ravel().argsort()[::-1] - det = det[order, :] - while det.shape[0] > 0: - # IOU - area = (det[:, 2] - det[:, 0] + 1) * (det[:, 3] - det[:, 1] + 1) - xx1 = np.maximum(det[0, 0], det[:, 0]) - yy1 = np.maximum(det[0, 1], det[:, 1]) - xx2 = np.minimum(det[0, 2], det[:, 2]) - yy2 = np.minimum(det[0, 3], det[:, 3]) - w = np.maximum(0.0, xx2 - xx1 + 1) - h = np.maximum(0.0, yy2 - yy1 + 1) - inter = w * h - o = inter / (area[0] + area[:] - inter) - - # get needed merge det and delete these det - merge_index = np.where(o >= 0.3)[0] - det_accu = det[merge_index, :] - det = np.delete(det, merge_index, 0) - - if merge_index.shape[0] <= 1: - continue - det_accu[:, 0:4] = det_accu[:, 0:4] * np.tile(det_accu[:, -1:], (1, 4)) - max_score = np.max(det_accu[:, 4]) - det_accu_sum = np.zeros((1, 5)) - det_accu_sum[:, 0:4] = np.sum( - det_accu[:, 0:4], axis=0) / np.sum(det_accu[:, -1:]) - det_accu_sum[:, 4] = max_score - try: - dets = np.row_stack((dets, det_accu_sum)) - except: - dets = det_accu_sum - - try: - dets = dets[0:750, :] - except: - dets = det - - return dets - - -def get_data(): - subset = 'val' - if subset is 'val': - wider_face = sio.loadmat(args.data_path+'wider_face_split/wider_face_val.mat') - else: - wider_face = sio.loadmat(args.data_path+'wider_face_split/wider_face_test.mat') - event_list = wider_face['event_list'] - file_list = wider_face['file_list'] - del wider_face - - imgs_path = os.path.join( - args.data_path, 'WIDER_{}'.format(subset), 'images') - save_path = 'output/pyramidbox1_{}'.format(subset) - - return event_list, file_list, imgs_path, save_path - -if __name__ == '__main__': - event_list, file_list, imgs_path, save_path = get_data() - cfg.USE_NMS = False - net = build_net('test', cfg.NUM_CLASSES) - net.load_state_dict(torch.load(args.model,map_location='cpu')) - - - net.eval() - - if use_npu: - net.npu() - cudnn.benckmark = True - - counter = 0 - print('start in ........') - for index, event in enumerate(event_list): - filelist = file_list[index][0] - path = os.path.join(save_path, str(event[0][0])) - if not os.path.exists(path): - os.makedirs(path) - - for num, file in enumerate(filelist): - im_name = file[0][0] - in_file = os.path.join(imgs_path, event[0][0], str(im_name[:]) + '.jpg') - img = Image.open(in_file) - if img.mode == 'L': - img = img.convert('RGB') - img = np.array(img) - max_im_shrink = np.sqrt( - 1700 * 1000 / (img.shape[0] * img.shape[1])) - - shrink = max_im_shrink if max_im_shrink < 1 else 1 - counter += 1 - - t1 = time.time() - det0 = detect_face(net, img, shrink) - det1 = flip_test(net, img, shrink) # flip test - [det2, det3] = multi_scale_test(net, img, max_im_shrink) - det = np.row_stack((det0, det1, det2, det3)) - if det.shape[0] ==1: - dets =det - else: - dets = bbox_vote(det) - - t2 = time.time() - print('Detect %04d th image costs %.4f' % (counter, t2 - t1)) - - fout = open(osp.join(save_path, str(event[0][ - 0]), im_name + '.txt'), 'w') - fout.write('{:s}\n'.format(str(event[0][0]) + '/' + im_name + '.jpg')) - fout.write('{:d}\n'.format(dets.shape[0])) - for i in range(dets.shape[0]): - xmin = dets[i][0] - ymin = dets[i][1] - xmax = dets[i][2] - ymax = dets[i][3] - score = dets[i][4] - fout.write('{:.1f} {:.1f} {:.1f} {:.1f} {:.3f}\n'. - format(xmin, ymin, (xmax - xmin + 1), (ymax - ymin + 1), score)) +#-*- coding:utf-8 -*- +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function + +import os +import torch +import argparse +import torch.nn as nn +import torch.utils.data as data +import torch.backends.cudnn as cudnn +import torchvision.transforms as transforms +import os.path as osp +import time +import cv2 +import time +import numpy as np +from PIL import Image +import scipy.io as sio + +import sys +#sys.path.append("/home/wch/Pyramidbox/") +from data.config import cfg +from pyramidbox import build_net +from torch.autograd import Variable +from utils.augmentations import to_chw_bgr +import torch.npu + +parser = argparse.ArgumentParser(description='pyramidbox evaluatuon wider') +parser.add_argument('--model', type=str, + default="weights/pyramidbox.pth", help='trained model') +parser.add_argument('--thresh', default=0.05, type=float, + help='Final confidence threshold') +parser.add_argument('--data_path', + default=None, type=str, + help='data_path') +args = parser.parse_args() + + +use_npu = torch.npu.is_available() + +def detect_face(net, img, shrink): + if shrink != 1: + img = cv2.resize(img, None, None, fx=shrink, fy=shrink, + interpolation=cv2.INTER_LINEAR) + + x = to_chw_bgr(img) + x = x.astype('float32') + x -= cfg.img_mean + x = x[[2, 1, 0], :, :] + image_x = x.shape[1] + image_y = x.shape[2] + if image_x <2500 and image_y<2500: + x0 = torch.Tensor(x[0]) + x1 = torch.Tensor(x[1]) + x2 = torch.Tensor(x[2]) + pad = nn.ZeroPad2d(padding=(0,2500-image_y,0,2500-image_x)) + x0 = pad(x0) + x1 = pad(x1) + x2 = pad(x2) + x0 =np.array(x0) + x1 =np.array(x1) + x2 =np.array(x2) + x = np.array([x0,x1,x2]) + x = Variable(torch.from_numpy(x).unsqueeze(0)) + + if use_npu: + x = x.npu() + y = net(x) + detections = y.data + detections = detections.cpu().numpy() + + det_conf = detections[0, 1, :, 0] + if image_x < 2500 and image_y < 2500: + det_xmin = 2500 * detections[0, 1, :, 1] / shrink + det_ymin = 2500 * detections[0, 1, :, 2] / shrink + det_xmax = 2500 * detections[0, 1, :, 3] / shrink + det_ymax = 2500 * detections[0, 1, :, 4] / shrink + else: + det_xmin = img.shape[1] * detections[0, 1, :, 1] / shrink + det_ymin = img.shape[0] * detections[0, 1, :, 2] / shrink + det_xmax = img.shape[1] * detections[0, 1, :, 3] / shrink + det_ymax = img.shape[0] * detections[0, 1, :, 4] / shrink + det = np.column_stack((det_xmin, det_ymin, det_xmax, det_ymax, det_conf)) + + keep_index = np.where(det[:, 4] >= args.thresh)[0] + det = det[keep_index, :] + return det + + +def flip_test(net, image, shrink): + image_f = cv2.flip(image, 1) + det_f = detect_face(net, image_f, shrink) + det_t = np.zeros(det_f.shape) + det_t[:, 0] = image.shape[1] - det_f[:, 2] + det_t[:, 1] = det_f[:, 1] + det_t[:, 2] = image.shape[1] - det_f[:, 0] + det_t[:, 3] = det_f[:, 3] + det_t[:, 4] = det_f[:, 4] + return det_t + + +def multi_scale_test(net, image, max_im_shrink): + # shrink detecting and shrink only detect big face + st = 0.5 if max_im_shrink >= 0.75 else 0.5 * max_im_shrink + det_s = detect_face(net, image, st) + index = np.where(np.maximum( + det_s[:, 2] - det_s[:, 0] + 1, det_s[:, 3] - det_s[:, 1] + 1) > 30)[0] + det_s = det_s[index, :] + + # enlarge one times + bt = min(2, max_im_shrink) if max_im_shrink > 1 else ( + st + max_im_shrink) / 2 + det_b = detect_face(net, image, bt) + + # enlarge small image x times for small face + if max_im_shrink > 2: + bt *= 2 + while bt < max_im_shrink: + det_b = np.row_stack((det_b, detect_face(net, image, bt))) + bt *= 2 + det_b = np.row_stack((det_b, detect_face(net, image, max_im_shrink))) + + # enlarge only detect small face + if bt > 1: + index = np.where(np.minimum( + det_b[:, 2] - det_b[:, 0] + 1, det_b[:, 3] - det_b[:, 1] + 1) < 100)[0] + det_b = det_b[index, :] + else: + index = np.where(np.maximum( + det_b[:, 2] - det_b[:, 0] + 1, det_b[:, 3] - det_b[:, 1] + 1) > 30)[0] + det_b = det_b[index, :] + + return det_s, det_b + + +def bbox_vote(det): + order = det[:, 4].ravel().argsort()[::-1] + det = det[order, :] + while det.shape[0] > 0: + # IOU + area = (det[:, 2] - det[:, 0] + 1) * (det[:, 3] - det[:, 1] + 1) + xx1 = np.maximum(det[0, 0], det[:, 0]) + yy1 = np.maximum(det[0, 1], det[:, 1]) + xx2 = np.minimum(det[0, 2], det[:, 2]) + yy2 = np.minimum(det[0, 3], det[:, 3]) + w = np.maximum(0.0, xx2 - xx1 + 1) + h = np.maximum(0.0, yy2 - yy1 + 1) + inter = w * h + o = inter / (area[0] + area[:] - inter) + + # get needed merge det and delete these det + merge_index = np.where(o >= 0.3)[0] + det_accu = det[merge_index, :] + det = np.delete(det, merge_index, 0) + + if merge_index.shape[0] <= 1: + continue + det_accu[:, 0:4] = det_accu[:, 0:4] * np.tile(det_accu[:, -1:], (1, 4)) + max_score = np.max(det_accu[:, 4]) + det_accu_sum = np.zeros((1, 5)) + det_accu_sum[:, 0:4] = np.sum( + det_accu[:, 0:4], axis=0) / np.sum(det_accu[:, -1:]) + det_accu_sum[:, 4] = max_score + try: + dets = np.row_stack((dets, det_accu_sum)) + except: + dets = det_accu_sum + + try: + dets = dets[0:750, :] + except: + dets = det + + return dets + + +def get_data(): + subset = 'val' + if subset is 'val': + wider_face = sio.loadmat(args.data_path+'wider_face_split/wider_face_val.mat') + else: + wider_face = sio.loadmat(args.data_path+'wider_face_split/wider_face_test.mat') + event_list = wider_face['event_list'] + file_list = wider_face['file_list'] + del wider_face + + imgs_path = os.path.join( + args.data_path, 'WIDER_{}'.format(subset), 'images') + save_path = 'output/pyramidbox1_{}'.format(subset) + + return event_list, file_list, imgs_path, save_path + +if __name__ == '__main__': + event_list, file_list, imgs_path, save_path = get_data() + cfg.USE_NMS = False + net = build_net('test', cfg.NUM_CLASSES) + net.load_state_dict(torch.load(args.model,map_location='cpu')) + + + net.eval() + + if use_npu: + net.npu() + cudnn.benckmark = True + + counter = 0 + print('start in ........') + for index, event in enumerate(event_list): + filelist = file_list[index][0] + path = os.path.join(save_path, str(event[0][0])) + if not os.path.exists(path): + os.makedirs(path) + + for num, file in enumerate(filelist): + im_name = file[0][0] + in_file = os.path.join(imgs_path, event[0][0], str(im_name[:]) + '.jpg') + img = Image.open(in_file) + if img.mode == 'L': + img = img.convert('RGB') + img = np.array(img) + max_im_shrink = np.sqrt( + 1700 * 1000 / (img.shape[0] * img.shape[1])) + + shrink = max_im_shrink if max_im_shrink < 1 else 1 + counter += 1 + + t1 = time.time() + det0 = detect_face(net, img, shrink) + det1 = flip_test(net, img, shrink) # flip test + [det2, det3] = multi_scale_test(net, img, max_im_shrink) + det = np.row_stack((det0, det1, det2, det3)) + if det.shape[0] ==1: + dets =det + else: + dets = bbox_vote(det) + + t2 = time.time() + print('Detect %04d th image costs %.4f' % (counter, t2 - t1)) + + fout = open(osp.join(save_path, str(event[0][ + 0]), im_name + '.txt'), 'w') + fout.write('{:s}\n'.format(str(event[0][0]) + '/' + im_name + '.jpg')) + fout.write('{:d}\n'.format(dets.shape[0])) + for i in range(dets.shape[0]): + xmin = dets[i][0] + ymin = dets[i][1] + xmax = dets[i][2] + ymax = dets[i][3] + score = dets[i][4] + fout.write('{:.1f} {:.1f} {:.1f} {:.1f} {:.3f}\n'. + format(xmin, ymin, (xmax - xmin + 1), (ymax - ymin + 1), score)) diff --git a/PyTorch/contrib/cv/detection/Pyramidbox/train.py b/PyTorch/contrib/cv/detection/Pyramidbox/train.py index 65ba8997939c79990f9fa65a7379c2c74961c664..6307c7210fa51305824da6377aabb65a2175dc85 100644 --- a/PyTorch/contrib/cv/detection/Pyramidbox/train.py +++ b/PyTorch/contrib/cv/detection/Pyramidbox/train.py @@ -1,361 +1,361 @@ -#-*- coding:utf-8 -*- -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function - - -import torch.nn as nn -import torch.optim as optim -import torch.nn.init as init -import torch.utils.data as data - -import os -import time -import torch -import argparse - -import numpy as np -from torch.autograd import Variable -import torch.backends.cudnn as cudnn -import torch.npu -from data.config import cfg -from pyramidbox import build_net -from layers.modules import MultiBoxLoss -from data.widerface import WIDERDetection, detection_collate -from torch.nn.parallel import DistributedDataParallel as DDP -import apex -from apex import amp -import torch.distributed as dist -import torch.multiprocessing as mp - -parser = argparse.ArgumentParser( - description='Pyramidbox face Detector Training With Pytorch') -train_set = parser.add_mutually_exclusive_group() -parser.add_argument('--basenet', - default='vgg16_reducedfc.pth', - help='Pretrained base model') -parser.add_argument('--batch_size', - default=16, type=int, - help='Batch size for training') -parser.add_argument('--resume', - default=None, type=str, - help='Checkpoint state_dict file to resume training from') -parser.add_argument('--num_workers', - default=4, type=int, - help='Number of workers used in dataloading') -parser.add_argument('--npu', - default=True, type=bool, - help='Use NPU to train model') -parser.add_argument('--performance', - default=False, type=bool, - help='performance to train') -parser.add_argument('--lr', '--learning-rate', - default=1e-3, type=float, - help='initial learning rate') -parser.add_argument('--momentum', - default=0.9, type=float, - help='Momentum value for optim') -parser.add_argument('--weight_decay', - default=5e-4, type=float, - help='Weight decay for SGD') -parser.add_argument('--gamma', - default=0.1, type=float, - help='Gamma update for SGD') -parser.add_argument('--multinpu', - default=False, type=bool, - help='Use mutil Gpu training') -parser.add_argument('--save_folder', - default='weights/', - help='Directory for saving checkpoint models') -parser.add_argument('--local_rank', - default=-1, type=int, - help='rank for current process') -parser.add_argument('--world_size', default=-1, type=int, - help='number of distributed processes') -parser.add_argument('--device_list', default='0', type=str, - help='NPU id to use.') -args = parser.parse_args() - -if args.npu: - if args.multinpu: - device_id = int(args.device_list.split(',')[args.local_rank]) - device = 'npu:{}'.format(device_id) - else: - device = 'npu:0' - torch.npu.set_device(device) - -if not os.path.exists(args.save_folder): - os.makedirs(args.save_folder) - -train_dataset = WIDERDetection(cfg.FACE.TRAIN_FILE, mode='train') - -val_dataset = WIDERDetection(cfg.FACE.VAL_FILE, mode='val') -val_batchsize = 1 -val_loader = data.DataLoader(val_dataset, val_batchsize, - num_workers=1, - shuffle=False, - collate_fn=detection_collate, - pin_memory=True) - -min_loss = np.inf -def train(): - # torch.set_num_threads(1) - iteration = 0 - start_epoch = 0 - step_index = 0 - per_epoch_size = len(train_dataset) // args.batch_size - if args.local_rank==0 or args.multinpu==False: - print('------build_net start-------') - pyramidbox = build_net('train', cfg.NUM_CLASSES) - if args.local_rank==0 or args.multinpu==False: - print('------build_net end-------') - net = pyramidbox - if args.multinpu: - train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) - train_loader = torch.utils.data.DataLoader( - dataset=train_dataset, - batch_size=args.batch_size, - shuffle=(train_sampler is None), - num_workers=args.num_workers, - pin_memory=False, - sampler=train_sampler, - collate_fn=detection_collate, - drop_last=True) - else: - train_loader = data.DataLoader(train_dataset, args.batch_size, - num_workers=args.num_workers, - shuffle=False, - collate_fn=detection_collate, - pin_memory=True) - if args.resume: - print('Resuming training, loading {}...'.format(args.resume)) - start_epoch = net.load_weights(args.resume) - iteration = start_epoch * per_epoch_size - else: - vgg_weights = torch.load(args.save_folder + args.basenet) - if args.local_rank==0 or args.multinpu==False: - print('Load base network....') - net.vgg.load_state_dict(vgg_weights) - - if args.local_rank==0 or args.multinpu==False: - print('load base network end--------') - if not args.resume: - if args.local_rank==0 or args.multinpu==False: - print('Initializing weights...') - pyramidbox.bn64.apply(pyramidbox.weights_init) - pyramidbox.extras.apply(pyramidbox.weights_init) - pyramidbox.lfpn_topdown.apply(pyramidbox.weights_init) - pyramidbox.lfpn_later.apply(pyramidbox.weights_init) - pyramidbox.cpm.apply(pyramidbox.weights_init) - pyramidbox.loc_layers.apply(pyramidbox.weights_init) - pyramidbox.conf_layers.apply(pyramidbox.weights_init) - - optimizer = optim.SGD(net.parameters(), lr=args.lr, momentum=args.momentum, - weight_decay=args.weight_decay) - - if args.npu: - net.npu() - net, optimizer = amp.initialize(net, optimizer, opt_level="O1",loss_scale=64.0)#,combine_grad=True) - if args.multinpu: - device_id = int(args.device_list.split(',')[args.local_rank]) - device = 'npu:{}'.format(device_id) - net = DDP(net, device_ids=[device_id],broadcast_buffers=False) - cudnn.benckmark = True - criterion1 = MultiBoxLoss(cfg, args.npu) - criterion2 = MultiBoxLoss(cfg, args.npu, use_head_loss=True) - if args.local_rank==0 or args.multinpu==False: - print('Loading wider dataset...') - print('Using the specified args:') - print(args) - warmup_steps = 1000 - net.train() - if args.local_rank==0 or args.multinpu==False: - print('start train--------') - for epoch in range(start_epoch, cfg.EPOCHES): - if args.multinpu: - train_sampler.set_epoch(epoch) - losses = 0 - for batch_idx, (images, face_targets, head_targets) in enumerate(train_loader): - - if args.npu: - images = Variable(images.npu()) - with torch.no_grad(): - face_targets = [Variable(ann) for ann in face_targets] - head_targets = [Variable(ann) for ann in head_targets] - else: - images = Variable(images) - with torch.no_grad(): - face_targets = [Variable(ann) for ann in face_targets] - head_targets = [Variable(ann) for ann in head_targets] - adjust_learning_rate(optimizer,iteration,warmup_steps,15000) - t0 = time.time() - out = net(images) - optimizer.zero_grad() - face_loss_l, face_loss_c = criterion1(out, face_targets) - head_loss_l, head_loss_c = criterion2(out, head_targets) - loss = face_loss_l + face_loss_c + head_loss_l + head_loss_c - losses += loss.item() - if args.npu: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - t1 = time.time() - face_loss = (face_loss_l + face_loss_c).item() - head_loss = (head_loss_l + head_loss_c).item() - - if args.performance: - if iteration == 50: - t50_0 = time.time() - if iteration == 100: - t100_0 = time.time() - if args.multinpu: - if args.local_rank==0: - print('cost time:{} batch_size:{} num_gpu:{} FPS:{}'.format(t100_0-t50_0,args.batch_size,args.world_size,(50*args.batch_size*args.world_size)/(t100_0-t50_0))) - else: - print('cost time:{} batch_size:{} FPS:{}'.format(t100_0-t50_0,args.batch_size,(50*args.batch_size)/(t100_0-t50_0))) - if iteration == 110: - break - iteration += 1 - continue - if iteration % 10 == 0 and (args.local_rank==0 or args.multinpu==False): - loss_ = losses / (batch_idx + 1) - print('Timer: {:.4f} sec.'.format(t1 - t0)) - print('epoch ' + repr(epoch) + ' iter ' + - repr(iteration) + ' || Loss:%.4f' % (loss_)) - print('->> face Loss: {:.4f} || head loss : {:.4f}'.format( - face_loss, head_loss)) - print('->> lr: {}'.format(optimizer.param_groups[0]['lr'])) - if args.multinpu: - print('iter:{} cost time:{} batch_size:{} num_gpu:{} FPS:{}'.format(iteration,t1-t0,args.batch_size,args.world_size,(args.batch_size*args.world_size)/(t1-t0))) - else: - print('iter:{} cost time:{} batch_size:{} FPS:{}'.format(iteration,t1-t0,args.batch_size,args.batch_size/(t1-t0))) - if iteration != 0 and iteration % 2000 == 0 and (args.local_rank==0 or args.multinpu==False): - print('Saving state, iter:', iteration) - file = 'pyramidbox_' + repr(iteration) + '.pth' - torch.save(pyramidbox.state_dict(), - os.path.join(args.save_folder, file)) - iteration += 1 - if args.performance: - break - if epoch>50 and epoch%5==0: - val(epoch, net, pyramidbox, criterion1, criterion2) - net.train() - -def val(epoch, - net, - pyramidbox, - criterion1, - criterion2): - net.eval() - face_losses = 0 - head_losses = 0 - step = 0 - t1 = time.time() - for batch_idx, (images, face_targets, head_targets) in enumerate(val_loader): - if args.npu: - images = Variable(images.npu()) - with torch.no_grad(): - face_targets = [Variable(ann) for ann in face_targets] - head_targets = [Variable(ann) for ann in head_targets] - - else: - images = Variable(images) - with torch.no_grad(): - face_targets = [Variable(ann) - for ann in face_targets] - head_targets = [Variable(ann) - for ann in head_targets] - - out = net(images) - face_loss_l, face_loss_c = criterion1(out, face_targets) - head_loss_l, head_loss_c = criterion2(out, head_targets) - - face_losses += (face_loss_l + face_loss_c).item() - head_losses += (head_loss_l + head_loss_c).item() - step += 1 - - tloss = face_losses / step - - t2 = time.time() - if args.local_rank==0: - print('test Timer:{:.4f} .sec'.format(t2 - t1)) - print('epoch ' + repr(epoch) + ' || Loss:%.4f' % (tloss)) - - global min_loss - if tloss < min_loss and args.local_rank==0: - print('Saving best state,epoch', epoch) - torch.save(pyramidbox.state_dict(), os.path.join( - args.save_folder, 'pyramidbox.pth')) - min_loss = tloss - - states = { - 'epoch': epoch, - 'weight': pyramidbox.state_dict(), - } - if args.local_rank==0: - torch.save(states, os.path.join( - args.save_folder, 'pyramidbox_checkpoint.pth')) - - -def lr_warmup(optimizer,step,base_lr,warmup_steps): - if not step > face Loss: {:.4f} || head loss : {:.4f}'.format( + face_loss, head_loss)) + print('->> lr: {}'.format(optimizer.param_groups[0]['lr'])) + if args.multinpu: + print('iter:{} cost time:{} batch_size:{} num_gpu:{} FPS:{}'.format(iteration,t1-t0,args.batch_size,args.world_size,(args.batch_size*args.world_size)/(t1-t0))) + else: + print('iter:{} cost time:{} batch_size:{} FPS:{}'.format(iteration,t1-t0,args.batch_size,args.batch_size/(t1-t0))) + if iteration != 0 and iteration % 2000 == 0 and (args.local_rank==0 or args.multinpu==False): + print('Saving state, iter:', iteration) + file = 'pyramidbox_' + repr(iteration) + '.pth' + torch.save(pyramidbox.state_dict(), + os.path.join(args.save_folder, file)) + iteration += 1 + if args.performance: + break + if epoch>50 and epoch%5==0: + val(epoch, net, pyramidbox, criterion1, criterion2) + net.train() + +def val(epoch, + net, + pyramidbox, + criterion1, + criterion2): + net.eval() + face_losses = 0 + head_losses = 0 + step = 0 + t1 = time.time() + for batch_idx, (images, face_targets, head_targets) in enumerate(val_loader): + if args.npu: + images = Variable(images.npu()) + with torch.no_grad(): + face_targets = [Variable(ann) for ann in face_targets] + head_targets = [Variable(ann) for ann in head_targets] + + else: + images = Variable(images) + with torch.no_grad(): + face_targets = [Variable(ann) + for ann in face_targets] + head_targets = [Variable(ann) + for ann in head_targets] + + out = net(images) + face_loss_l, face_loss_c = criterion1(out, face_targets) + head_loss_l, head_loss_c = criterion2(out, head_targets) + + face_losses += (face_loss_l + face_loss_c).item() + head_losses += (head_loss_l + head_loss_c).item() + step += 1 + + tloss = face_losses / step + + t2 = time.time() + if args.local_rank==0: + print('test Timer:{:.4f} .sec'.format(t2 - t1)) + print('epoch ' + repr(epoch) + ' || Loss:%.4f' % (tloss)) + + global min_loss + if tloss < min_loss and args.local_rank==0: + print('Saving best state,epoch', epoch) + torch.save(pyramidbox.state_dict(), os.path.join( + args.save_folder, 'pyramidbox.pth')) + min_loss = tloss + + states = { + 'epoch': epoch, + 'weight': pyramidbox.state_dict(), + } + if args.local_rank==0: + torch.save(states, os.path.join( + args.save_folder, 'pyramidbox_checkpoint.pth')) + + +def lr_warmup(optimizer,step,base_lr,warmup_steps): + if not step 0.5: - img = random_brightness(img) - img = random_contrast(img) - img = random_saturation(img) - img = random_hue(img) - else: - img = random_brightness(img) - img = random_saturation(img) - img = random_hue(img) - img = random_contrast(img) - return img - - -def meet_emit_constraint(src_bbox, sample_bbox): - center_x = (src_bbox.xmax + src_bbox.xmin) / 2 - center_y = (src_bbox.ymax + src_bbox.ymin) / 2 - if center_x >= sample_bbox.xmin and \ - center_x <= sample_bbox.xmax and \ - center_y >= sample_bbox.ymin and \ - center_y <= sample_bbox.ymax: - return True - return False - - -def project_bbox(object_bbox, sample_bbox): - if object_bbox.xmin >= sample_bbox.xmax or \ - object_bbox.xmax <= sample_bbox.xmin or \ - object_bbox.ymin >= sample_bbox.ymax or \ - object_bbox.ymax <= sample_bbox.ymin: - return False - else: - proj_bbox = bbox(0, 0, 0, 0) - sample_width = sample_bbox.xmax - sample_bbox.xmin - sample_height = sample_bbox.ymax - sample_bbox.ymin - proj_bbox.xmin = (object_bbox.xmin - sample_bbox.xmin) / sample_width - proj_bbox.ymin = (object_bbox.ymin - sample_bbox.ymin) / sample_height - proj_bbox.xmax = (object_bbox.xmax - sample_bbox.xmin) / sample_width - proj_bbox.ymax = (object_bbox.ymax - sample_bbox.ymin) / sample_height - proj_bbox = clip_bbox(proj_bbox) - if bbox_area(proj_bbox) > 0: - return proj_bbox - else: - return False - - -def transform_labels(bbox_labels, sample_bbox): - sample_labels = [] - for i in range(len(bbox_labels)): - sample_label = [] - object_bbox = bbox(bbox_labels[i][1], bbox_labels[i][2], - bbox_labels[i][3], bbox_labels[i][4]) - if not meet_emit_constraint(object_bbox, sample_bbox): - continue - proj_bbox = project_bbox(object_bbox, sample_bbox) - if proj_bbox: - sample_label.append(bbox_labels[i][0]) - sample_label.append(float(proj_bbox.xmin)) - sample_label.append(float(proj_bbox.ymin)) - sample_label.append(float(proj_bbox.xmax)) - sample_label.append(float(proj_bbox.ymax)) - sample_label = sample_label + bbox_labels[i][5:] - sample_labels.append(sample_label) - return sample_labels - - -def expand_image(img, bbox_labels, img_width, img_height): - prob = np.random.uniform(0, 1) - if prob < cfg.expand_prob: - if cfg.expand_max_ratio - 1 >= 0.01: - expand_ratio = np.random.uniform(1, cfg.expand_max_ratio) - height = int(img_height * expand_ratio) - width = int(img_width * expand_ratio) - h_off = math.floor(np.random.uniform(0, height - img_height)) - w_off = math.floor(np.random.uniform(0, width - img_width)) - expand_bbox = bbox(-w_off / img_width, -h_off / img_height, - (width - w_off) / img_width, - (height - h_off) / img_height) - expand_img = np.ones((height, width, 3)) - expand_img = np.uint8(expand_img * np.squeeze(cfg.img_mean)) - expand_img = Image.fromarray(expand_img) - expand_img.paste(img, (int(w_off), int(h_off))) - bbox_labels = transform_labels(bbox_labels, expand_bbox) - return expand_img, bbox_labels, width, height - return img, bbox_labels, img_width, img_height - - -def clip_bbox(src_bbox): - src_bbox.xmin = max(min(src_bbox.xmin, 1.0), 0.0) - src_bbox.ymin = max(min(src_bbox.ymin, 1.0), 0.0) - src_bbox.xmax = max(min(src_bbox.xmax, 1.0), 0.0) - src_bbox.ymax = max(min(src_bbox.ymax, 1.0), 0.0) - return src_bbox - - -def bbox_area(src_bbox): - if src_bbox.xmax < src_bbox.xmin or src_bbox.ymax < src_bbox.ymin: - return 0. - else: - width = src_bbox.xmax - src_bbox.xmin - height = src_bbox.ymax - src_bbox.ymin - return width * height - - -def intersect_bbox(bbox1, bbox2): - if bbox2.xmin > bbox1.xmax or bbox2.xmax < bbox1.xmin or \ - bbox2.ymin > bbox1.ymax or bbox2.ymax < bbox1.ymin: - intersection_box = bbox(0.0, 0.0, 0.0, 0.0) - else: - intersection_box = bbox( - max(bbox1.xmin, bbox2.xmin), - max(bbox1.ymin, bbox2.ymin), - min(bbox1.xmax, bbox2.xmax), min(bbox1.ymax, bbox2.ymax)) - return intersection_box - - -def bbox_coverage(bbox1, bbox2): - inter_box = intersect_bbox(bbox1, bbox2) - intersect_size = bbox_area(inter_box) - - if intersect_size > 0: - bbox1_size = bbox_area(bbox1) - return intersect_size / bbox1_size - else: - return 0. - - -def generate_batch_random_samples(batch_sampler, bbox_labels, image_width, - image_height, scale_array, resize_width, - resize_height): - sampled_bbox = [] - for sampler in batch_sampler: - found = 0 - for i in range(sampler.max_trial): - if found >= sampler.max_sample: - break - sample_bbox = data_anchor_sampling( - sampler, bbox_labels, image_width, image_height, scale_array, - resize_width, resize_height) - if sample_bbox == 0: - break - if satisfy_sample_constraint(sampler, sample_bbox, bbox_labels): - sampled_bbox.append(sample_bbox) - found = found + 1 - return sampled_bbox - - -def data_anchor_sampling(sampler, bbox_labels, image_width, image_height, - scale_array, resize_width, resize_height): - num_gt = len(bbox_labels) - # np.random.randint range: [low, high) - rand_idx = np.random.randint(0, num_gt) if num_gt != 0 else 0 - - if num_gt != 0: - norm_xmin = bbox_labels[rand_idx][1] - norm_ymin = bbox_labels[rand_idx][2] - norm_xmax = bbox_labels[rand_idx][3] - norm_ymax = bbox_labels[rand_idx][4] - - xmin = norm_xmin * image_width - ymin = norm_ymin * image_height - wid = image_width * (norm_xmax - norm_xmin) - hei = image_height * (norm_ymax - norm_ymin) - range_size = 0 - - area = wid * hei - for scale_ind in range(0, len(scale_array) - 1): - if area > scale_array[scale_ind] ** 2 and area < \ - scale_array[scale_ind + 1] ** 2: - range_size = scale_ind + 1 - break - - if area > scale_array[len(scale_array) - 2]**2: - range_size = len(scale_array) - 2 - scale_choose = 0.0 - if range_size == 0: - rand_idx_size = 0 - else: - # np.random.randint range: [low, high) - rng_rand_size = np.random.randint(0, range_size + 1) - rand_idx_size = rng_rand_size % (range_size + 1) - - if rand_idx_size == range_size: - min_resize_val = scale_array[rand_idx_size] / 2.0 - max_resize_val = min(2.0 * scale_array[rand_idx_size], - 2 * math.sqrt(wid * hei)) - scale_choose = random.uniform(min_resize_val, max_resize_val) - else: - min_resize_val = scale_array[rand_idx_size] / 2.0 - max_resize_val = 2.0 * scale_array[rand_idx_size] - scale_choose = random.uniform(min_resize_val, max_resize_val) - - sample_bbox_size = wid * resize_width / scale_choose - - w_off_orig = 0.0 - h_off_orig = 0.0 - if sample_bbox_size < max(image_height, image_width): - if wid <= sample_bbox_size: - w_off_orig = np.random.uniform(xmin + wid - sample_bbox_size, - xmin) - else: - w_off_orig = np.random.uniform(xmin, - xmin + wid - sample_bbox_size) - - if hei <= sample_bbox_size: - h_off_orig = np.random.uniform(ymin + hei - sample_bbox_size, - ymin) - else: - h_off_orig = np.random.uniform(ymin, - ymin + hei - sample_bbox_size) - - else: - w_off_orig = np.random.uniform(image_width - sample_bbox_size, 0.0) - h_off_orig = np.random.uniform( - image_height - sample_bbox_size, 0.0) - - w_off_orig = math.floor(w_off_orig) - h_off_orig = math.floor(h_off_orig) - - # Figure out top left coordinates. - w_off = 0.0 - h_off = 0.0 - w_off = float(w_off_orig / image_width) - h_off = float(h_off_orig / image_height) - - sampled_bbox = bbox(w_off, h_off, - w_off + float(sample_bbox_size / image_width), - h_off + float(sample_bbox_size / image_height)) - - return sampled_bbox - else: - return 0 - - -def jaccard_overlap(sample_bbox, object_bbox): - if sample_bbox.xmin >= object_bbox.xmax or \ - sample_bbox.xmax <= object_bbox.xmin or \ - sample_bbox.ymin >= object_bbox.ymax or \ - sample_bbox.ymax <= object_bbox.ymin: - return 0 - intersect_xmin = max(sample_bbox.xmin, object_bbox.xmin) - intersect_ymin = max(sample_bbox.ymin, object_bbox.ymin) - intersect_xmax = min(sample_bbox.xmax, object_bbox.xmax) - intersect_ymax = min(sample_bbox.ymax, object_bbox.ymax) - intersect_size = (intersect_xmax - intersect_xmin) * ( - intersect_ymax - intersect_ymin) - sample_bbox_size = bbox_area(sample_bbox) - object_bbox_size = bbox_area(object_bbox) - overlap = intersect_size / ( - sample_bbox_size + object_bbox_size - intersect_size) - return overlap - - -def satisfy_sample_constraint(sampler, sample_bbox, bbox_labels): - if sampler.min_jaccard_overlap == 0 and sampler.max_jaccard_overlap == 0: - has_jaccard_overlap = False - else: - has_jaccard_overlap = True - if sampler.min_object_coverage == 0 and sampler.max_object_coverage == 0: - has_object_coverage = False - else: - has_object_coverage = True - - if not has_jaccard_overlap and not has_object_coverage: - return True - found = False - for i in range(len(bbox_labels)): - object_bbox = bbox(bbox_labels[i][1], bbox_labels[i][2], - bbox_labels[i][3], bbox_labels[i][4]) - if has_jaccard_overlap: - overlap = jaccard_overlap(sample_bbox, object_bbox) - if sampler.min_jaccard_overlap != 0 and \ - overlap < sampler.min_jaccard_overlap: - continue - if sampler.max_jaccard_overlap != 0 and \ - overlap > sampler.max_jaccard_overlap: - continue - found = True - if has_object_coverage: - object_coverage = bbox_coverage(object_bbox, sample_bbox) - if sampler.min_object_coverage != 0 and \ - object_coverage < sampler.min_object_coverage: - continue - if sampler.max_object_coverage != 0 and \ - object_coverage > sampler.max_object_coverage: - continue - found = True - if found: - return True - return found - - -def crop_image_sampling(img, bbox_labels, sample_bbox, image_width, - image_height, resize_width, resize_height, - min_face_size): - # no clipping here - xmin = int(sample_bbox.xmin * image_width) - xmax = int(sample_bbox.xmax * image_width) - ymin = int(sample_bbox.ymin * image_height) - ymax = int(sample_bbox.ymax * image_height) - w_off = xmin - h_off = ymin - width = xmax - xmin - height = ymax - ymin - - cross_xmin = max(0.0, float(w_off)) - cross_ymin = max(0.0, float(h_off)) - cross_xmax = min(float(w_off + width - 1.0), float(image_width)) - cross_ymax = min(float(h_off + height - 1.0), float(image_height)) - cross_width = cross_xmax - cross_xmin - cross_height = cross_ymax - cross_ymin - - roi_xmin = 0 if w_off >= 0 else abs(w_off) - roi_ymin = 0 if h_off >= 0 else abs(h_off) - roi_width = cross_width - roi_height = cross_height - - roi_y1 = int(roi_ymin) - roi_y2 = int(roi_ymin + roi_height) - roi_x1 = int(roi_xmin) - roi_x2 = int(roi_xmin + roi_width) - - cross_y1 = int(cross_ymin) - cross_y2 = int(cross_ymin + cross_height) - cross_x1 = int(cross_xmin) - cross_x2 = int(cross_xmin + cross_width) - - sample_img = np.zeros((height, width, 3)) - # print(sample_img.shape) - sample_img[roi_y1 : roi_y2, roi_x1 : roi_x2] = \ - img[cross_y1: cross_y2, cross_x1: cross_x2] - sample_img = cv2.resize( - sample_img, (resize_width, resize_height), interpolation=cv2.INTER_AREA) - - resize_val = resize_width - sample_labels = transform_labels_sampling(bbox_labels, sample_bbox, - resize_val, min_face_size) - return sample_img, sample_labels - - -def transform_labels_sampling(bbox_labels, sample_bbox, resize_val, - min_face_size): - sample_labels = [] - for i in range(len(bbox_labels)): - sample_label = [] - object_bbox = bbox(bbox_labels[i][1], bbox_labels[i][2], - bbox_labels[i][3], bbox_labels[i][4]) - if not meet_emit_constraint(object_bbox, sample_bbox): - continue - proj_bbox = project_bbox(object_bbox, sample_bbox) - if proj_bbox: - real_width = float((proj_bbox.xmax - proj_bbox.xmin) * resize_val) - real_height = float((proj_bbox.ymax - proj_bbox.ymin) * resize_val) - if real_width * real_height < float(min_face_size * min_face_size): - continue - else: - sample_label.append(bbox_labels[i][0]) - sample_label.append(float(proj_bbox.xmin)) - sample_label.append(float(proj_bbox.ymin)) - sample_label.append(float(proj_bbox.xmax)) - sample_label.append(float(proj_bbox.ymax)) - sample_label = sample_label + bbox_labels[i][5:] - sample_labels.append(sample_label) - - return sample_labels - - -def generate_sample(sampler, image_width, image_height): - scale = np.random.uniform(sampler.min_scale, sampler.max_scale) - aspect_ratio = np.random.uniform(sampler.min_aspect_ratio, - sampler.max_aspect_ratio) - aspect_ratio = max(aspect_ratio, (scale**2.0)) - aspect_ratio = min(aspect_ratio, 1 / (scale**2.0)) - - bbox_width = scale * (aspect_ratio**0.5) - bbox_height = scale / (aspect_ratio**0.5) - - # guarantee a squared image patch after cropping - if sampler.use_square: - if image_height < image_width: - bbox_width = bbox_height * image_height / image_width - else: - bbox_height = bbox_width * image_width / image_height - - xmin_bound = 1 - bbox_width - ymin_bound = 1 - bbox_height - xmin = np.random.uniform(0, xmin_bound) - ymin = np.random.uniform(0, ymin_bound) - xmax = xmin + bbox_width - ymax = ymin + bbox_height - sampled_bbox = bbox(xmin, ymin, xmax, ymax) - return sampled_bbox - - -def generate_batch_samples(batch_sampler, bbox_labels, image_width, - image_height): - sampled_bbox = [] - for sampler in batch_sampler: - found = 0 - for i in range(sampler.max_trial): - if found >= sampler.max_sample: - break - sample_bbox = generate_sample(sampler, image_width, image_height) - if satisfy_sample_constraint(sampler, sample_bbox, bbox_labels): - sampled_bbox.append(sample_bbox) - found = found + 1 - return sampled_bbox - - -def crop_image(img, bbox_labels, sample_bbox, image_width, image_height, - resize_width, resize_height, min_face_size): - sample_bbox = clip_bbox(sample_bbox) - xmin = int(sample_bbox.xmin * image_width) - xmax = int(sample_bbox.xmax * image_width) - ymin = int(sample_bbox.ymin * image_height) - ymax = int(sample_bbox.ymax * image_height) - - sample_img = img[ymin:ymax, xmin:xmax] - resize_val = resize_width - sample_labels = transform_labels_sampling(bbox_labels, sample_bbox, - resize_val, min_face_size) - return sample_img, sample_labels - - -def to_chw_bgr(image): - """ - Transpose image from HWC to CHW and from RBG to BGR. - Args: - image (np.array): an image with HWC and RBG layout. - """ - # HWC to CHW - if len(image.shape) == 3: - image = np.swapaxes(image, 1, 2) - image = np.swapaxes(image, 1, 0) - # RBG to BGR - image = image[[2, 1, 0], :, :] - return image - - -def anchor_crop_image_sampling(img, - bbox_labels, - scale_array, - img_width, - img_height): - mean = np.array([104, 117, 123], dtype=np.float32) - maxSize = 12000 # max size - infDistance = 9999999 - bbox_labels = np.array(bbox_labels) - scale = np.array([img_width, img_height, img_width, img_height]) - - boxes = bbox_labels[:, 1:5] * scale - labels = bbox_labels[:, 0] - - boxArea = (boxes[:, 2] - boxes[:, 0] + 1) * (boxes[:, 3] - boxes[:, 1] + 1) - # argsort = np.argsort(boxArea) - # rand_idx = random.randint(min(len(argsort),6)) - # print('rand idx',rand_idx) - rand_idx = np.random.randint(len(boxArea)) - rand_Side = boxArea[rand_idx] ** 0.5 - # rand_Side = min(boxes[rand_idx,2] - boxes[rand_idx,0] + 1, - # boxes[rand_idx,3] - boxes[rand_idx,1] + 1) - - distance = infDistance - anchor_idx = 5 - for i, anchor in enumerate(scale_array): - if abs(anchor - rand_Side) < distance: - distance = abs(anchor - rand_Side) - anchor_idx = i - - target_anchor = random.choice(scale_array[0:min(anchor_idx + 1, 5) + 1]) - ratio = float(target_anchor) / rand_Side - ratio = ratio * (2**random.uniform(-1, 1)) - - if int(img_height * ratio * img_width * ratio) > maxSize * maxSize: - ratio = (maxSize * maxSize / (img_height * img_width))**0.5 - - interp_methods = [cv2.INTER_LINEAR, cv2.INTER_CUBIC, - cv2.INTER_AREA, cv2.INTER_NEAREST, cv2.INTER_LANCZOS4] - interp_method = random.choice(interp_methods) - image = cv2.resize(img, None, None, fx=ratio, - fy=ratio, interpolation=interp_method) - - boxes[:, 0] *= ratio - boxes[:, 1] *= ratio - boxes[:, 2] *= ratio - boxes[:, 3] *= ratio - - height, width, _ = image.shape - - sample_boxes = [] - - xmin = boxes[rand_idx, 0] - ymin = boxes[rand_idx, 1] - bw = (boxes[rand_idx, 2] - boxes[rand_idx, 0] + 1) - bh = (boxes[rand_idx, 3] - boxes[rand_idx, 1] + 1) - - w = h = 640 - - for _ in range(50): - if w < max(height, width): - if bw <= w: - w_off = random.uniform(xmin + bw - w, xmin) - else: - w_off = random.uniform(xmin, xmin + bw - w) - - if bh <= h: - h_off = random.uniform(ymin + bh - h, ymin) - else: - h_off = random.uniform(ymin, ymin + bh - h) - else: - w_off = random.uniform(width - w, 0) - h_off = random.uniform(height - h, 0) - - w_off = math.floor(w_off) - h_off = math.floor(h_off) - - # convert to integer rect x1,y1,x2,y2 - rect = np.array( - [int(w_off), int(h_off), int(w_off + w), int(h_off + h)]) - - # keep overlap with gt box IF center in sampled patch - centers = (boxes[:, :2] + boxes[:, 2:]) / 2.0 - # mask in all gt boxes that above and to the left of centers - m1 = (rect[0] <= boxes[:, 0]) * (rect[1] <= boxes[:, 1]) - # mask in all gt boxes that under and to the right of centers - m2 = (rect[2] >= boxes[:, 2]) * (rect[3] >= boxes[:, 3]) - # mask in that both m1 and m2 are true - mask = m1 * m2 - - overlap = jaccard_numpy(boxes, rect) - # have any valid boxes? try again if not - if not mask.any() and not overlap.max() > 0.7: - continue - else: - sample_boxes.append(rect) - - sampled_labels = [] - - if len(sample_boxes) > 0: - choice_idx = np.random.randint(len(sample_boxes)) - choice_box = sample_boxes[choice_idx] - # print('crop the box :',choice_box) - centers = (boxes[:, :2] + boxes[:, 2:]) / 2.0 - m1 = (choice_box[0] < centers[:, 0]) * \ - (choice_box[1] < centers[:, 1]) - m2 = (choice_box[2] > centers[:, 0]) * \ - (choice_box[3] > centers[:, 1]) - mask = m1 * m2 - current_boxes = boxes[mask, :].copy() - current_labels = labels[mask] - current_boxes[:, :2] -= choice_box[:2] - current_boxes[:, 2:] -= choice_box[:2] - - if choice_box[0] < 0 or choice_box[1] < 0: - new_img_width = width if choice_box[ - 0] >= 0 else width - choice_box[0] - new_img_height = height if choice_box[ - 1] >= 0 else height - choice_box[1] - image_pad = np.zeros( - (new_img_height, new_img_width, 3), dtype=float) - image_pad[:, :, :] = mean - start_left = 0 if choice_box[0] >= 0 else -choice_box[0] - start_top = 0 if choice_box[1] >= 0 else -choice_box[1] - image_pad[start_top:, start_left:, :] = image - - choice_box_w = choice_box[2] - choice_box[0] - choice_box_h = choice_box[3] - choice_box[1] - - start_left = choice_box[0] if choice_box[0] >= 0 else 0 - start_top = choice_box[1] if choice_box[1] >= 0 else 0 - end_right = start_left + choice_box_w - end_bottom = start_top + choice_box_h - current_image = image_pad[ - start_top:end_bottom, start_left:end_right, :].copy() - image_height, image_width, _ = current_image.shape - if cfg.filter_min_face: - bbox_w = current_boxes[:, 2] - current_boxes[:, 0] - bbox_h = current_boxes[:, 3] - current_boxes[:, 1] - bbox_area = bbox_w * bbox_h - mask = bbox_area > (cfg.min_face_size * cfg.min_face_size) - current_boxes = current_boxes[mask] - current_labels = current_labels[mask] - for i in range(len(current_boxes)): - sample_label = [] - sample_label.append(current_labels[i]) - sample_label.append(current_boxes[i][0] / image_width) - sample_label.append(current_boxes[i][1] / image_height) - sample_label.append(current_boxes[i][2] / image_width) - sample_label.append(current_boxes[i][3] / image_height) - sampled_labels += [sample_label] - sampled_labels = np.array(sampled_labels) - else: - current_boxes /= np.array([image_width, - image_height, image_width, image_height]) - sampled_labels = np.hstack( - (current_labels[:, np.newaxis], current_boxes)) - - return current_image, sampled_labels - - current_image = image[choice_box[1]:choice_box[ - 3], choice_box[0]:choice_box[2], :].copy() - image_height, image_width, _ = current_image.shape - - if cfg.filter_min_face: - bbox_w = current_boxes[:, 2] - current_boxes[:, 0] - bbox_h = current_boxes[:, 3] - current_boxes[:, 1] - bbox_area = bbox_w * bbox_h - mask = bbox_area > (cfg.min_face_size * cfg.min_face_size) - current_boxes = current_boxes[mask] - current_labels = current_labels[mask] - for i in range(len(current_boxes)): - sample_label = [] - sample_label.append(current_labels[i]) - sample_label.append(current_boxes[i][0] / image_width) - sample_label.append(current_boxes[i][1] / image_height) - sample_label.append(current_boxes[i][2] / image_width) - sample_label.append(current_boxes[i][3] / image_height) - sampled_labels += [sample_label] - sampled_labels = np.array(sampled_labels) - else: - current_boxes /= np.array([image_width, - image_height, image_width, image_height]) - sampled_labels = np.hstack( - (current_labels[:, np.newaxis], current_boxes)) - - return current_image, sampled_labels - else: - image_height, image_width, _ = image.shape - if cfg.filter_min_face: - bbox_w = boxes[:, 2] - boxes[:, 0] - bbox_h = boxes[:, 3] - boxes[:, 1] - bbox_area = bbox_w * bbox_h - mask = bbox_area > (cfg.min_face_size * cfg.min_face_size) - boxes = boxes[mask] - labels = labels[mask] - for i in range(len(boxes)): - sample_label = [] - sample_label.append(labels[i]) - sample_label.append(boxes[i][0] / image_width) - sample_label.append(boxes[i][1] / image_height) - sample_label.append(boxes[i][2] / image_width) - sample_label.append(boxes[i][3] / image_height) - sampled_labels += [sample_label] - sampled_labels = np.array(sampled_labels) - else: - boxes /= np.array([image_width, image_height, - image_width, image_height]) - sampled_labels = np.hstack( - (labels[:, np.newaxis], boxes)) - - return image, sampled_labels - - -def preprocess(img, bbox_labels, mode, image_path): - img_width, img_height = img.size - sampled_labels = bbox_labels - if mode == 'train': - if cfg.apply_distort: - img = distort_image(img) - if cfg.apply_expand: - img, bbox_labels, img_width, img_height = expand_image( - img, bbox_labels, img_width, img_height) - - batch_sampler = [] - prob = np.random.uniform(0., 1.) - if prob > cfg.data_anchor_sampling_prob and cfg.anchor_sampling: - scale_array = np.array([16, 32, 64, 128, 256, 512]) - ''' - batch_sampler.append( - sampler(1, 50, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.6, 0.0, True)) - sampled_bbox = generate_batch_random_samples( - batch_sampler, bbox_labels, img_width, img_height, scale_array, - cfg.resize_width, cfg.resize_height) - ''' - img = np.array(img) - img, sampled_labels = anchor_crop_image_sampling( - img, bbox_labels, scale_array, img_width, img_height) - ''' - if len(sampled_bbox) > 0: - idx = int(np.random.uniform(0, len(sampled_bbox))) - img, sampled_labels = crop_image_sampling( - img, bbox_labels, sampled_bbox[idx], img_width, img_height, - cfg.resize_width, cfg.resize_height, cfg.min_face_size) - ''' - img = img.astype('uint8') - img = Image.fromarray(img) - else: - batch_sampler.append(sampler(1, 50, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, - 0.0, True)) - batch_sampler.append(sampler(1, 50, 0.3, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, - 0.0, True)) - batch_sampler.append(sampler(1, 50, 0.3, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, - 0.0, True)) - batch_sampler.append(sampler(1, 50, 0.3, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, - 0.0, True)) - batch_sampler.append(sampler(1, 50, 0.3, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, - 0.0, True)) - sampled_bbox = generate_batch_samples( - batch_sampler, bbox_labels, img_width, img_height) - - img = np.array(img) - if len(sampled_bbox) > 0: - idx = int(np.random.uniform(0, len(sampled_bbox))) - img, sampled_labels = crop_image( - img, bbox_labels, sampled_bbox[idx], img_width, img_height, - cfg.resize_width, cfg.resize_height, cfg.min_face_size) - - img = Image.fromarray(img) - - interp_mode = [ - Image.BILINEAR, Image.HAMMING, Image.NEAREST, Image.BICUBIC, - Image.LANCZOS - ] - interp_indx = np.random.randint(0, 5) - - img = img.resize((cfg.resize_width, cfg.resize_height), - resample=interp_mode[interp_indx]) - - img = np.array(img) - - if mode == 'train': - mirror = int(np.random.uniform(0, 2)) - if mirror == 1: - img = img[:, ::-1, :] - for i in six.moves.xrange(len(sampled_labels)): - tmp = sampled_labels[i][1] - sampled_labels[i][1] = 1 - sampled_labels[i][3] - sampled_labels[i][3] = 1 - tmp - - #img = Image.fromarray(img) - img = to_chw_bgr(img) - img = img.astype('float32') - img -= cfg.img_mean - img = img[[2, 1, 0], :, :] # to RGB - #img = img * cfg.scale - - return img, sampled_labels +#-*- coding:utf-8 -*- +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + + +import torch +from torchvision import transforms +import cv2 +import numpy as np +import types +from PIL import Image, ImageEnhance, ImageDraw +import math +import six +from data.config import cfg +import random + + +class sampler(): + + def __init__(self, + max_sample, + max_trial, + min_scale, + max_scale, + min_aspect_ratio, + max_aspect_ratio, + min_jaccard_overlap, + max_jaccard_overlap, + min_object_coverage, + max_object_coverage, + use_square=False): + self.max_sample = max_sample + self.max_trial = max_trial + self.min_scale = min_scale + self.max_scale = max_scale + self.min_aspect_ratio = min_aspect_ratio + self.max_aspect_ratio = max_aspect_ratio + self.min_jaccard_overlap = min_jaccard_overlap + self.max_jaccard_overlap = max_jaccard_overlap + self.min_object_coverage = min_object_coverage + self.max_object_coverage = max_object_coverage + self.use_square = use_square + + +def intersect(box_a, box_b): + max_xy = np.minimum(box_a[:, 2:], box_b[2:]) + min_xy = np.maximum(box_a[:, :2], box_b[:2]) + inter = np.clip((max_xy - min_xy), a_min=0, a_max=np.inf) + return inter[:, 0] * inter[:, 1] + + +def jaccard_numpy(box_a, box_b): + """Compute the jaccard overlap of two sets of boxes. The jaccard overlap + is simply the intersection over union of two boxes. + E.g.: + A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) + Args: + box_a: Multiple bounding boxes, Shape: [num_boxes,4] + box_b: Single bounding box, Shape: [4] + Return: + jaccard overlap: Shape: [box_a.shape[0], box_a.shape[1]] + """ + inter = intersect(box_a, box_b) + area_a = ((box_a[:, 2] - box_a[:, 0]) * + (box_a[:, 3] - box_a[:, 1])) # [A,B] + area_b = ((box_b[2] - box_b[0]) * + (box_b[3] - box_b[1])) # [A,B] + union = area_a + area_b - inter + return inter / union # [A,B] + + +class bbox(): + + def __init__(self, xmin, ymin, xmax, ymax): + self.xmin = xmin + self.ymin = ymin + self.xmax = xmax + self.ymax = ymax + + +def random_brightness(img): + prob = np.random.uniform(0, 1) + if prob < cfg.brightness_prob: + delta = np.random.uniform(-cfg.brightness_delta, + cfg.brightness_delta) + 1 + img = ImageEnhance.Brightness(img).enhance(delta) + return img + + +def random_contrast(img): + prob = np.random.uniform(0, 1) + if prob < cfg.contrast_prob: + delta = np.random.uniform(-cfg.contrast_delta, + cfg.contrast_delta) + 1 + img = ImageEnhance.Contrast(img).enhance(delta) + return img + + +def random_saturation(img): + prob = np.random.uniform(0, 1) + if prob < cfg.saturation_prob: + delta = np.random.uniform(-cfg.saturation_delta, + cfg.saturation_delta) + 1 + img = ImageEnhance.Color(img).enhance(delta) + return img + + +def random_hue(img): + prob = np.random.uniform(0, 1) + if prob < cfg.hue_prob: + delta = np.random.uniform(-cfg.hue_delta, cfg.hue_delta) + img_hsv = np.array(img.convert('HSV')) + img_hsv[:, :, 0] = img_hsv[:, :, 0] + delta + img = Image.fromarray(img_hsv, mode='HSV').convert('RGB') + return img + + +def distort_image(img): + prob = np.random.uniform(0, 1) + # Apply different distort order + if prob > 0.5: + img = random_brightness(img) + img = random_contrast(img) + img = random_saturation(img) + img = random_hue(img) + else: + img = random_brightness(img) + img = random_saturation(img) + img = random_hue(img) + img = random_contrast(img) + return img + + +def meet_emit_constraint(src_bbox, sample_bbox): + center_x = (src_bbox.xmax + src_bbox.xmin) / 2 + center_y = (src_bbox.ymax + src_bbox.ymin) / 2 + if center_x >= sample_bbox.xmin and \ + center_x <= sample_bbox.xmax and \ + center_y >= sample_bbox.ymin and \ + center_y <= sample_bbox.ymax: + return True + return False + + +def project_bbox(object_bbox, sample_bbox): + if object_bbox.xmin >= sample_bbox.xmax or \ + object_bbox.xmax <= sample_bbox.xmin or \ + object_bbox.ymin >= sample_bbox.ymax or \ + object_bbox.ymax <= sample_bbox.ymin: + return False + else: + proj_bbox = bbox(0, 0, 0, 0) + sample_width = sample_bbox.xmax - sample_bbox.xmin + sample_height = sample_bbox.ymax - sample_bbox.ymin + proj_bbox.xmin = (object_bbox.xmin - sample_bbox.xmin) / sample_width + proj_bbox.ymin = (object_bbox.ymin - sample_bbox.ymin) / sample_height + proj_bbox.xmax = (object_bbox.xmax - sample_bbox.xmin) / sample_width + proj_bbox.ymax = (object_bbox.ymax - sample_bbox.ymin) / sample_height + proj_bbox = clip_bbox(proj_bbox) + if bbox_area(proj_bbox) > 0: + return proj_bbox + else: + return False + + +def transform_labels(bbox_labels, sample_bbox): + sample_labels = [] + for i in range(len(bbox_labels)): + sample_label = [] + object_bbox = bbox(bbox_labels[i][1], bbox_labels[i][2], + bbox_labels[i][3], bbox_labels[i][4]) + if not meet_emit_constraint(object_bbox, sample_bbox): + continue + proj_bbox = project_bbox(object_bbox, sample_bbox) + if proj_bbox: + sample_label.append(bbox_labels[i][0]) + sample_label.append(float(proj_bbox.xmin)) + sample_label.append(float(proj_bbox.ymin)) + sample_label.append(float(proj_bbox.xmax)) + sample_label.append(float(proj_bbox.ymax)) + sample_label = sample_label + bbox_labels[i][5:] + sample_labels.append(sample_label) + return sample_labels + + +def expand_image(img, bbox_labels, img_width, img_height): + prob = np.random.uniform(0, 1) + if prob < cfg.expand_prob: + if cfg.expand_max_ratio - 1 >= 0.01: + expand_ratio = np.random.uniform(1, cfg.expand_max_ratio) + height = int(img_height * expand_ratio) + width = int(img_width * expand_ratio) + h_off = math.floor(np.random.uniform(0, height - img_height)) + w_off = math.floor(np.random.uniform(0, width - img_width)) + expand_bbox = bbox(-w_off / img_width, -h_off / img_height, + (width - w_off) / img_width, + (height - h_off) / img_height) + expand_img = np.ones((height, width, 3)) + expand_img = np.uint8(expand_img * np.squeeze(cfg.img_mean)) + expand_img = Image.fromarray(expand_img) + expand_img.paste(img, (int(w_off), int(h_off))) + bbox_labels = transform_labels(bbox_labels, expand_bbox) + return expand_img, bbox_labels, width, height + return img, bbox_labels, img_width, img_height + + +def clip_bbox(src_bbox): + src_bbox.xmin = max(min(src_bbox.xmin, 1.0), 0.0) + src_bbox.ymin = max(min(src_bbox.ymin, 1.0), 0.0) + src_bbox.xmax = max(min(src_bbox.xmax, 1.0), 0.0) + src_bbox.ymax = max(min(src_bbox.ymax, 1.0), 0.0) + return src_bbox + + +def bbox_area(src_bbox): + if src_bbox.xmax < src_bbox.xmin or src_bbox.ymax < src_bbox.ymin: + return 0. + else: + width = src_bbox.xmax - src_bbox.xmin + height = src_bbox.ymax - src_bbox.ymin + return width * height + + +def intersect_bbox(bbox1, bbox2): + if bbox2.xmin > bbox1.xmax or bbox2.xmax < bbox1.xmin or \ + bbox2.ymin > bbox1.ymax or bbox2.ymax < bbox1.ymin: + intersection_box = bbox(0.0, 0.0, 0.0, 0.0) + else: + intersection_box = bbox( + max(bbox1.xmin, bbox2.xmin), + max(bbox1.ymin, bbox2.ymin), + min(bbox1.xmax, bbox2.xmax), min(bbox1.ymax, bbox2.ymax)) + return intersection_box + + +def bbox_coverage(bbox1, bbox2): + inter_box = intersect_bbox(bbox1, bbox2) + intersect_size = bbox_area(inter_box) + + if intersect_size > 0: + bbox1_size = bbox_area(bbox1) + return intersect_size / bbox1_size + else: + return 0. + + +def generate_batch_random_samples(batch_sampler, bbox_labels, image_width, + image_height, scale_array, resize_width, + resize_height): + sampled_bbox = [] + for sampler in batch_sampler: + found = 0 + for i in range(sampler.max_trial): + if found >= sampler.max_sample: + break + sample_bbox = data_anchor_sampling( + sampler, bbox_labels, image_width, image_height, scale_array, + resize_width, resize_height) + if sample_bbox == 0: + break + if satisfy_sample_constraint(sampler, sample_bbox, bbox_labels): + sampled_bbox.append(sample_bbox) + found = found + 1 + return sampled_bbox + + +def data_anchor_sampling(sampler, bbox_labels, image_width, image_height, + scale_array, resize_width, resize_height): + num_gt = len(bbox_labels) + # np.random.randint range: [low, high) + rand_idx = np.random.randint(0, num_gt) if num_gt != 0 else 0 + + if num_gt != 0: + norm_xmin = bbox_labels[rand_idx][1] + norm_ymin = bbox_labels[rand_idx][2] + norm_xmax = bbox_labels[rand_idx][3] + norm_ymax = bbox_labels[rand_idx][4] + + xmin = norm_xmin * image_width + ymin = norm_ymin * image_height + wid = image_width * (norm_xmax - norm_xmin) + hei = image_height * (norm_ymax - norm_ymin) + range_size = 0 + + area = wid * hei + for scale_ind in range(0, len(scale_array) - 1): + if area > scale_array[scale_ind] ** 2 and area < \ + scale_array[scale_ind + 1] ** 2: + range_size = scale_ind + 1 + break + + if area > scale_array[len(scale_array) - 2]**2: + range_size = len(scale_array) - 2 + scale_choose = 0.0 + if range_size == 0: + rand_idx_size = 0 + else: + # np.random.randint range: [low, high) + rng_rand_size = np.random.randint(0, range_size + 1) + rand_idx_size = rng_rand_size % (range_size + 1) + + if rand_idx_size == range_size: + min_resize_val = scale_array[rand_idx_size] / 2.0 + max_resize_val = min(2.0 * scale_array[rand_idx_size], + 2 * math.sqrt(wid * hei)) + scale_choose = random.uniform(min_resize_val, max_resize_val) + else: + min_resize_val = scale_array[rand_idx_size] / 2.0 + max_resize_val = 2.0 * scale_array[rand_idx_size] + scale_choose = random.uniform(min_resize_val, max_resize_val) + + sample_bbox_size = wid * resize_width / scale_choose + + w_off_orig = 0.0 + h_off_orig = 0.0 + if sample_bbox_size < max(image_height, image_width): + if wid <= sample_bbox_size: + w_off_orig = np.random.uniform(xmin + wid - sample_bbox_size, + xmin) + else: + w_off_orig = np.random.uniform(xmin, + xmin + wid - sample_bbox_size) + + if hei <= sample_bbox_size: + h_off_orig = np.random.uniform(ymin + hei - sample_bbox_size, + ymin) + else: + h_off_orig = np.random.uniform(ymin, + ymin + hei - sample_bbox_size) + + else: + w_off_orig = np.random.uniform(image_width - sample_bbox_size, 0.0) + h_off_orig = np.random.uniform( + image_height - sample_bbox_size, 0.0) + + w_off_orig = math.floor(w_off_orig) + h_off_orig = math.floor(h_off_orig) + + # Figure out top left coordinates. + w_off = 0.0 + h_off = 0.0 + w_off = float(w_off_orig / image_width) + h_off = float(h_off_orig / image_height) + + sampled_bbox = bbox(w_off, h_off, + w_off + float(sample_bbox_size / image_width), + h_off + float(sample_bbox_size / image_height)) + + return sampled_bbox + else: + return 0 + + +def jaccard_overlap(sample_bbox, object_bbox): + if sample_bbox.xmin >= object_bbox.xmax or \ + sample_bbox.xmax <= object_bbox.xmin or \ + sample_bbox.ymin >= object_bbox.ymax or \ + sample_bbox.ymax <= object_bbox.ymin: + return 0 + intersect_xmin = max(sample_bbox.xmin, object_bbox.xmin) + intersect_ymin = max(sample_bbox.ymin, object_bbox.ymin) + intersect_xmax = min(sample_bbox.xmax, object_bbox.xmax) + intersect_ymax = min(sample_bbox.ymax, object_bbox.ymax) + intersect_size = (intersect_xmax - intersect_xmin) * ( + intersect_ymax - intersect_ymin) + sample_bbox_size = bbox_area(sample_bbox) + object_bbox_size = bbox_area(object_bbox) + overlap = intersect_size / ( + sample_bbox_size + object_bbox_size - intersect_size) + return overlap + + +def satisfy_sample_constraint(sampler, sample_bbox, bbox_labels): + if sampler.min_jaccard_overlap == 0 and sampler.max_jaccard_overlap == 0: + has_jaccard_overlap = False + else: + has_jaccard_overlap = True + if sampler.min_object_coverage == 0 and sampler.max_object_coverage == 0: + has_object_coverage = False + else: + has_object_coverage = True + + if not has_jaccard_overlap and not has_object_coverage: + return True + found = False + for i in range(len(bbox_labels)): + object_bbox = bbox(bbox_labels[i][1], bbox_labels[i][2], + bbox_labels[i][3], bbox_labels[i][4]) + if has_jaccard_overlap: + overlap = jaccard_overlap(sample_bbox, object_bbox) + if sampler.min_jaccard_overlap != 0 and \ + overlap < sampler.min_jaccard_overlap: + continue + if sampler.max_jaccard_overlap != 0 and \ + overlap > sampler.max_jaccard_overlap: + continue + found = True + if has_object_coverage: + object_coverage = bbox_coverage(object_bbox, sample_bbox) + if sampler.min_object_coverage != 0 and \ + object_coverage < sampler.min_object_coverage: + continue + if sampler.max_object_coverage != 0 and \ + object_coverage > sampler.max_object_coverage: + continue + found = True + if found: + return True + return found + + +def crop_image_sampling(img, bbox_labels, sample_bbox, image_width, + image_height, resize_width, resize_height, + min_face_size): + # no clipping here + xmin = int(sample_bbox.xmin * image_width) + xmax = int(sample_bbox.xmax * image_width) + ymin = int(sample_bbox.ymin * image_height) + ymax = int(sample_bbox.ymax * image_height) + w_off = xmin + h_off = ymin + width = xmax - xmin + height = ymax - ymin + + cross_xmin = max(0.0, float(w_off)) + cross_ymin = max(0.0, float(h_off)) + cross_xmax = min(float(w_off + width - 1.0), float(image_width)) + cross_ymax = min(float(h_off + height - 1.0), float(image_height)) + cross_width = cross_xmax - cross_xmin + cross_height = cross_ymax - cross_ymin + + roi_xmin = 0 if w_off >= 0 else abs(w_off) + roi_ymin = 0 if h_off >= 0 else abs(h_off) + roi_width = cross_width + roi_height = cross_height + + roi_y1 = int(roi_ymin) + roi_y2 = int(roi_ymin + roi_height) + roi_x1 = int(roi_xmin) + roi_x2 = int(roi_xmin + roi_width) + + cross_y1 = int(cross_ymin) + cross_y2 = int(cross_ymin + cross_height) + cross_x1 = int(cross_xmin) + cross_x2 = int(cross_xmin + cross_width) + + sample_img = np.zeros((height, width, 3)) + # print(sample_img.shape) + sample_img[roi_y1 : roi_y2, roi_x1 : roi_x2] = \ + img[cross_y1: cross_y2, cross_x1: cross_x2] + sample_img = cv2.resize( + sample_img, (resize_width, resize_height), interpolation=cv2.INTER_AREA) + + resize_val = resize_width + sample_labels = transform_labels_sampling(bbox_labels, sample_bbox, + resize_val, min_face_size) + return sample_img, sample_labels + + +def transform_labels_sampling(bbox_labels, sample_bbox, resize_val, + min_face_size): + sample_labels = [] + for i in range(len(bbox_labels)): + sample_label = [] + object_bbox = bbox(bbox_labels[i][1], bbox_labels[i][2], + bbox_labels[i][3], bbox_labels[i][4]) + if not meet_emit_constraint(object_bbox, sample_bbox): + continue + proj_bbox = project_bbox(object_bbox, sample_bbox) + if proj_bbox: + real_width = float((proj_bbox.xmax - proj_bbox.xmin) * resize_val) + real_height = float((proj_bbox.ymax - proj_bbox.ymin) * resize_val) + if real_width * real_height < float(min_face_size * min_face_size): + continue + else: + sample_label.append(bbox_labels[i][0]) + sample_label.append(float(proj_bbox.xmin)) + sample_label.append(float(proj_bbox.ymin)) + sample_label.append(float(proj_bbox.xmax)) + sample_label.append(float(proj_bbox.ymax)) + sample_label = sample_label + bbox_labels[i][5:] + sample_labels.append(sample_label) + + return sample_labels + + +def generate_sample(sampler, image_width, image_height): + scale = np.random.uniform(sampler.min_scale, sampler.max_scale) + aspect_ratio = np.random.uniform(sampler.min_aspect_ratio, + sampler.max_aspect_ratio) + aspect_ratio = max(aspect_ratio, (scale**2.0)) + aspect_ratio = min(aspect_ratio, 1 / (scale**2.0)) + + bbox_width = scale * (aspect_ratio**0.5) + bbox_height = scale / (aspect_ratio**0.5) + + # guarantee a squared image patch after cropping + if sampler.use_square: + if image_height < image_width: + bbox_width = bbox_height * image_height / image_width + else: + bbox_height = bbox_width * image_width / image_height + + xmin_bound = 1 - bbox_width + ymin_bound = 1 - bbox_height + xmin = np.random.uniform(0, xmin_bound) + ymin = np.random.uniform(0, ymin_bound) + xmax = xmin + bbox_width + ymax = ymin + bbox_height + sampled_bbox = bbox(xmin, ymin, xmax, ymax) + return sampled_bbox + + +def generate_batch_samples(batch_sampler, bbox_labels, image_width, + image_height): + sampled_bbox = [] + for sampler in batch_sampler: + found = 0 + for i in range(sampler.max_trial): + if found >= sampler.max_sample: + break + sample_bbox = generate_sample(sampler, image_width, image_height) + if satisfy_sample_constraint(sampler, sample_bbox, bbox_labels): + sampled_bbox.append(sample_bbox) + found = found + 1 + return sampled_bbox + + +def crop_image(img, bbox_labels, sample_bbox, image_width, image_height, + resize_width, resize_height, min_face_size): + sample_bbox = clip_bbox(sample_bbox) + xmin = int(sample_bbox.xmin * image_width) + xmax = int(sample_bbox.xmax * image_width) + ymin = int(sample_bbox.ymin * image_height) + ymax = int(sample_bbox.ymax * image_height) + + sample_img = img[ymin:ymax, xmin:xmax] + resize_val = resize_width + sample_labels = transform_labels_sampling(bbox_labels, sample_bbox, + resize_val, min_face_size) + return sample_img, sample_labels + + +def to_chw_bgr(image): + """ + Transpose image from HWC to CHW and from RBG to BGR. + Args: + image (np.array): an image with HWC and RBG layout. + """ + # HWC to CHW + if len(image.shape) == 3: + image = np.swapaxes(image, 1, 2) + image = np.swapaxes(image, 1, 0) + # RBG to BGR + image = image[[2, 1, 0], :, :] + return image + + +def anchor_crop_image_sampling(img, + bbox_labels, + scale_array, + img_width, + img_height): + mean = np.array([104, 117, 123], dtype=np.float32) + maxSize = 12000 # max size + infDistance = 9999999 + bbox_labels = np.array(bbox_labels) + scale = np.array([img_width, img_height, img_width, img_height]) + + boxes = bbox_labels[:, 1:5] * scale + labels = bbox_labels[:, 0] + + boxArea = (boxes[:, 2] - boxes[:, 0] + 1) * (boxes[:, 3] - boxes[:, 1] + 1) + # argsort = np.argsort(boxArea) + # rand_idx = random.randint(min(len(argsort),6)) + # print('rand idx',rand_idx) + rand_idx = np.random.randint(len(boxArea)) + rand_Side = boxArea[rand_idx] ** 0.5 + # rand_Side = min(boxes[rand_idx,2] - boxes[rand_idx,0] + 1, + # boxes[rand_idx,3] - boxes[rand_idx,1] + 1) + + distance = infDistance + anchor_idx = 5 + for i, anchor in enumerate(scale_array): + if abs(anchor - rand_Side) < distance: + distance = abs(anchor - rand_Side) + anchor_idx = i + + target_anchor = random.choice(scale_array[0:min(anchor_idx + 1, 5) + 1]) + ratio = float(target_anchor) / rand_Side + ratio = ratio * (2**random.uniform(-1, 1)) + + if int(img_height * ratio * img_width * ratio) > maxSize * maxSize: + ratio = (maxSize * maxSize / (img_height * img_width))**0.5 + + interp_methods = [cv2.INTER_LINEAR, cv2.INTER_CUBIC, + cv2.INTER_AREA, cv2.INTER_NEAREST, cv2.INTER_LANCZOS4] + interp_method = random.choice(interp_methods) + image = cv2.resize(img, None, None, fx=ratio, + fy=ratio, interpolation=interp_method) + + boxes[:, 0] *= ratio + boxes[:, 1] *= ratio + boxes[:, 2] *= ratio + boxes[:, 3] *= ratio + + height, width, _ = image.shape + + sample_boxes = [] + + xmin = boxes[rand_idx, 0] + ymin = boxes[rand_idx, 1] + bw = (boxes[rand_idx, 2] - boxes[rand_idx, 0] + 1) + bh = (boxes[rand_idx, 3] - boxes[rand_idx, 1] + 1) + + w = h = 640 + + for _ in range(50): + if w < max(height, width): + if bw <= w: + w_off = random.uniform(xmin + bw - w, xmin) + else: + w_off = random.uniform(xmin, xmin + bw - w) + + if bh <= h: + h_off = random.uniform(ymin + bh - h, ymin) + else: + h_off = random.uniform(ymin, ymin + bh - h) + else: + w_off = random.uniform(width - w, 0) + h_off = random.uniform(height - h, 0) + + w_off = math.floor(w_off) + h_off = math.floor(h_off) + + # convert to integer rect x1,y1,x2,y2 + rect = np.array( + [int(w_off), int(h_off), int(w_off + w), int(h_off + h)]) + + # keep overlap with gt box IF center in sampled patch + centers = (boxes[:, :2] + boxes[:, 2:]) / 2.0 + # mask in all gt boxes that above and to the left of centers + m1 = (rect[0] <= boxes[:, 0]) * (rect[1] <= boxes[:, 1]) + # mask in all gt boxes that under and to the right of centers + m2 = (rect[2] >= boxes[:, 2]) * (rect[3] >= boxes[:, 3]) + # mask in that both m1 and m2 are true + mask = m1 * m2 + + overlap = jaccard_numpy(boxes, rect) + # have any valid boxes? try again if not + if not mask.any() and not overlap.max() > 0.7: + continue + else: + sample_boxes.append(rect) + + sampled_labels = [] + + if len(sample_boxes) > 0: + choice_idx = np.random.randint(len(sample_boxes)) + choice_box = sample_boxes[choice_idx] + # print('crop the box :',choice_box) + centers = (boxes[:, :2] + boxes[:, 2:]) / 2.0 + m1 = (choice_box[0] < centers[:, 0]) * \ + (choice_box[1] < centers[:, 1]) + m2 = (choice_box[2] > centers[:, 0]) * \ + (choice_box[3] > centers[:, 1]) + mask = m1 * m2 + current_boxes = boxes[mask, :].copy() + current_labels = labels[mask] + current_boxes[:, :2] -= choice_box[:2] + current_boxes[:, 2:] -= choice_box[:2] + + if choice_box[0] < 0 or choice_box[1] < 0: + new_img_width = width if choice_box[ + 0] >= 0 else width - choice_box[0] + new_img_height = height if choice_box[ + 1] >= 0 else height - choice_box[1] + image_pad = np.zeros( + (new_img_height, new_img_width, 3), dtype=float) + image_pad[:, :, :] = mean + start_left = 0 if choice_box[0] >= 0 else -choice_box[0] + start_top = 0 if choice_box[1] >= 0 else -choice_box[1] + image_pad[start_top:, start_left:, :] = image + + choice_box_w = choice_box[2] - choice_box[0] + choice_box_h = choice_box[3] - choice_box[1] + + start_left = choice_box[0] if choice_box[0] >= 0 else 0 + start_top = choice_box[1] if choice_box[1] >= 0 else 0 + end_right = start_left + choice_box_w + end_bottom = start_top + choice_box_h + current_image = image_pad[ + start_top:end_bottom, start_left:end_right, :].copy() + image_height, image_width, _ = current_image.shape + if cfg.filter_min_face: + bbox_w = current_boxes[:, 2] - current_boxes[:, 0] + bbox_h = current_boxes[:, 3] - current_boxes[:, 1] + bbox_area = bbox_w * bbox_h + mask = bbox_area > (cfg.min_face_size * cfg.min_face_size) + current_boxes = current_boxes[mask] + current_labels = current_labels[mask] + for i in range(len(current_boxes)): + sample_label = [] + sample_label.append(current_labels[i]) + sample_label.append(current_boxes[i][0] / image_width) + sample_label.append(current_boxes[i][1] / image_height) + sample_label.append(current_boxes[i][2] / image_width) + sample_label.append(current_boxes[i][3] / image_height) + sampled_labels += [sample_label] + sampled_labels = np.array(sampled_labels) + else: + current_boxes /= np.array([image_width, + image_height, image_width, image_height]) + sampled_labels = np.hstack( + (current_labels[:, np.newaxis], current_boxes)) + + return current_image, sampled_labels + + current_image = image[choice_box[1]:choice_box[ + 3], choice_box[0]:choice_box[2], :].copy() + image_height, image_width, _ = current_image.shape + + if cfg.filter_min_face: + bbox_w = current_boxes[:, 2] - current_boxes[:, 0] + bbox_h = current_boxes[:, 3] - current_boxes[:, 1] + bbox_area = bbox_w * bbox_h + mask = bbox_area > (cfg.min_face_size * cfg.min_face_size) + current_boxes = current_boxes[mask] + current_labels = current_labels[mask] + for i in range(len(current_boxes)): + sample_label = [] + sample_label.append(current_labels[i]) + sample_label.append(current_boxes[i][0] / image_width) + sample_label.append(current_boxes[i][1] / image_height) + sample_label.append(current_boxes[i][2] / image_width) + sample_label.append(current_boxes[i][3] / image_height) + sampled_labels += [sample_label] + sampled_labels = np.array(sampled_labels) + else: + current_boxes /= np.array([image_width, + image_height, image_width, image_height]) + sampled_labels = np.hstack( + (current_labels[:, np.newaxis], current_boxes)) + + return current_image, sampled_labels + else: + image_height, image_width, _ = image.shape + if cfg.filter_min_face: + bbox_w = boxes[:, 2] - boxes[:, 0] + bbox_h = boxes[:, 3] - boxes[:, 1] + bbox_area = bbox_w * bbox_h + mask = bbox_area > (cfg.min_face_size * cfg.min_face_size) + boxes = boxes[mask] + labels = labels[mask] + for i in range(len(boxes)): + sample_label = [] + sample_label.append(labels[i]) + sample_label.append(boxes[i][0] / image_width) + sample_label.append(boxes[i][1] / image_height) + sample_label.append(boxes[i][2] / image_width) + sample_label.append(boxes[i][3] / image_height) + sampled_labels += [sample_label] + sampled_labels = np.array(sampled_labels) + else: + boxes /= np.array([image_width, image_height, + image_width, image_height]) + sampled_labels = np.hstack( + (labels[:, np.newaxis], boxes)) + + return image, sampled_labels + + +def preprocess(img, bbox_labels, mode, image_path): + img_width, img_height = img.size + sampled_labels = bbox_labels + if mode == 'train': + if cfg.apply_distort: + img = distort_image(img) + if cfg.apply_expand: + img, bbox_labels, img_width, img_height = expand_image( + img, bbox_labels, img_width, img_height) + + batch_sampler = [] + prob = np.random.uniform(0., 1.) + if prob > cfg.data_anchor_sampling_prob and cfg.anchor_sampling: + scale_array = np.array([16, 32, 64, 128, 256, 512]) + ''' + batch_sampler.append( + sampler(1, 50, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.6, 0.0, True)) + sampled_bbox = generate_batch_random_samples( + batch_sampler, bbox_labels, img_width, img_height, scale_array, + cfg.resize_width, cfg.resize_height) + ''' + img = np.array(img) + img, sampled_labels = anchor_crop_image_sampling( + img, bbox_labels, scale_array, img_width, img_height) + ''' + if len(sampled_bbox) > 0: + idx = int(np.random.uniform(0, len(sampled_bbox))) + img, sampled_labels = crop_image_sampling( + img, bbox_labels, sampled_bbox[idx], img_width, img_height, + cfg.resize_width, cfg.resize_height, cfg.min_face_size) + ''' + img = img.astype('uint8') + img = Image.fromarray(img) + else: + batch_sampler.append(sampler(1, 50, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, + 0.0, True)) + batch_sampler.append(sampler(1, 50, 0.3, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, + 0.0, True)) + batch_sampler.append(sampler(1, 50, 0.3, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, + 0.0, True)) + batch_sampler.append(sampler(1, 50, 0.3, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, + 0.0, True)) + batch_sampler.append(sampler(1, 50, 0.3, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, + 0.0, True)) + sampled_bbox = generate_batch_samples( + batch_sampler, bbox_labels, img_width, img_height) + + img = np.array(img) + if len(sampled_bbox) > 0: + idx = int(np.random.uniform(0, len(sampled_bbox))) + img, sampled_labels = crop_image( + img, bbox_labels, sampled_bbox[idx], img_width, img_height, + cfg.resize_width, cfg.resize_height, cfg.min_face_size) + + img = Image.fromarray(img) + + interp_mode = [ + Image.BILINEAR, Image.HAMMING, Image.NEAREST, Image.BICUBIC, + Image.LANCZOS + ] + interp_indx = np.random.randint(0, 5) + + img = img.resize((cfg.resize_width, cfg.resize_height), + resample=interp_mode[interp_indx]) + + img = np.array(img) + + if mode == 'train': + mirror = int(np.random.uniform(0, 2)) + if mirror == 1: + img = img[:, ::-1, :] + for i in six.moves.xrange(len(sampled_labels)): + tmp = sampled_labels[i][1] + sampled_labels[i][1] = 1 - sampled_labels[i][3] + sampled_labels[i][3] = 1 - tmp + + #img = Image.fromarray(img) + img = to_chw_bgr(img) + img = img.astype('float32') + img -= cfg.img_mean + img = img[[2, 1, 0], :, :] # to RGB + #img = img * cfg.scale + + return img, sampled_labels diff --git a/PyTorch/contrib/cv/detection/RefineDet/README.md b/PyTorch/contrib/cv/detection/RefineDet/README.md index 9acc3e968d317ce8d1f20180ced4ce247e722926..b3fba97b024ea603c5b983721db33801ea333e36 100644 --- a/PyTorch/contrib/cv/detection/RefineDet/README.md +++ b/PyTorch/contrib/cv/detection/RefineDet/README.md @@ -1,49 +1,49 @@ -#RefineDet模型PyTorch 训练指导 - -## 1 环境准备 - -1.安装必要的依赖 - -pip install -r requirements.txt - -2.获取数据集 - -``` -sh data/scripts/VOC2007.sh -sh data/scripts/VOC2012.sh -``` -下载好的数据集位于 ./data/VOCdevkit - - -## 2 训练 - -路径要写到 VOCdevkit - -``` -# npu env -source test/env_npu.sh - -# 1p train perf -bash test/train_performance_1p.sh --data_path=xxx - -# 路径要写到 VOCdevkit -# 例如 - -bash test/train_performance_1p.sh --data_path=./data/VOCdevkit - -# 8p train perf -bash test/train_performance_8p.sh --data_path=xxx - -# 8p train full -bash test/train_full_8p.sh --data_path=xxx - -# 8p eval -bash test/train_eval_8p.sh --data_path=xxx - -# finetuning -bash test/train_finetune_1p.sh --data_path=xxx - -# online inference demo -python3.7 demo.py - +#RefineDet模型PyTorch 训练指导 + +## 1 环境准备 + +1.安装必要的依赖 + +pip install -r requirements.txt + +2.获取数据集 + +``` +sh data/scripts/VOC2007.sh +sh data/scripts/VOC2012.sh +``` +下载好的数据集位于 ./data/VOCdevkit + + +## 2 训练 + +路径要写到 VOCdevkit + +``` +# npu env +source test/env_npu.sh + +# 1p train perf +bash test/train_performance_1p.sh --data_path=xxx + +# 路径要写到 VOCdevkit +# 例如 + +bash test/train_performance_1p.sh --data_path=./data/VOCdevkit + +# 8p train perf +bash test/train_performance_8p.sh --data_path=xxx + +# 8p train full +bash test/train_full_8p.sh --data_path=xxx + +# 8p eval +bash test/train_eval_8p.sh --data_path=xxx + +# finetuning +bash test/train_finetune_1p.sh --data_path=xxx + +# online inference demo +python3.7 demo.py + ``` \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/RefineDet/demo.py b/PyTorch/contrib/cv/detection/RefineDet/demo.py index e1d12a5a1a6f2c3f91aec02b4b3d10c0f849d449..bce020fc3693c9c620b9083be0beea62f9a74aed 100644 --- a/PyTorch/contrib/cv/detection/RefineDet/demo.py +++ b/PyTorch/contrib/cv/detection/RefineDet/demo.py @@ -1,22 +1,22 @@ -#!/bin/bash -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -from models.refinedet import build_refinedet -torch.npu.set_device('npu:0') -net = build_refinedet('test', 320, 21, batch_norm=True).npu() -input = torch.randn(size=(1, 3, 320, 320)).npu() -out = net(input) +#!/bin/bash +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +from models.refinedet import build_refinedet +torch.npu.set_device('npu:0') +net = build_refinedet('test', 320, 21, batch_norm=True).npu() +input = torch.randn(size=(1, 3, 320, 320)).npu() +out = net(input) print(out) \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/RefineDet/eval_refinedet.py b/PyTorch/contrib/cv/detection/RefineDet/eval_refinedet.py index 42bb8f17b29f5c65f937f722bf5421d0354e59ad..e960f367b07b4762eacc80e41d618a38a88d48d1 100644 --- a/PyTorch/contrib/cv/detection/RefineDet/eval_refinedet.py +++ b/PyTorch/contrib/cv/detection/RefineDet/eval_refinedet.py @@ -1,466 +1,466 @@ -#!/bin/bash -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Adapted from: - @longcw faster_rcnn_pytorch: https://github.com/longcw/faster_rcnn_pytorch - @rbgirshick py-faster-rcnn https://github.com/rbgirshick/py-faster-rcnn - Licensed under The MIT License [see LICENSE for details] -""" - -from __future__ import print_function -import torch -import torch.nn as nn -import torch.backends.cudnn as cudnn -from torch.autograd import Variable -from data import VOCAnnotationTransform, VOCDetection, BaseTransform -from data import VOC_CLASSES as labelmap -from data import voc_refinedet, detection_collate_test -import torch.utils.data as data - -from models.refinedet import build_refinedet - -import sys -import os -import time -import argparse -import numpy as np -import pickle -import cv2 -from apex import amp - -cfg = voc_refinedet['320'] - -if sys.version_info[0] == 2: - import xml.etree.cElementTree as ET -else: - import xml.etree.ElementTree as ET - -def str2bool(v): - return v.lower() in ("yes", "true", "t", "1") - -class Timer(object): - """A simple timer.""" - def __init__(self): - self.total_time = 0. - self.calls = 0 - self.start_time = 0. - self.diff = 0. - self.average_time = 0. - - def tic(self): - self.start_time = time.time() - - def toc(self, average=True): - self.diff = time.time() - self.start_time - self.total_time += self.diff - self.calls += 1 - self.average_time = self.total_time / self.calls - if average: - return self.average_time - else: - return self.diff - - -def parse_rec(filename): - """ Parse a PASCAL VOC xml file """ - tree = ET.parse(filename) - objects = [] - for obj in tree.findall('object'): - obj_struct = {} - obj_struct['name'] = obj.find('name').text - obj_struct['pose'] = obj.find('pose').text - obj_struct['truncated'] = int(obj.find('truncated').text) - obj_struct['difficult'] = int(obj.find('difficult').text) - bbox = obj.find('bndbox') - obj_struct['bbox'] = [int(bbox.find('xmin').text) - 1, - int(bbox.find('ymin').text) - 1, - int(bbox.find('xmax').text) - 1, - int(bbox.find('ymax').text) - 1] - objects.append(obj_struct) - - return objects - - -def get_output_dir(name, phase): - """Return the directory where experimental artifacts are placed. - If the directory does not exist, it is created. - A canonical path is built using the name from an imdb and a network - (if not None). - """ - filedir = os.path.join(name, phase) - if not os.path.exists(filedir): - os.makedirs(filedir) - return filedir - - -def get_voc_results_file_template(image_set, cls): - filename = 'det_' + image_set + '_%s.txt' % (cls) - filedir = os.path.join(devkit_path, 'results') - if not os.path.exists(filedir): - os.makedirs(filedir) - path = os.path.join(filedir, filename) - return path - - -def write_voc_results_file(all_boxes, dataset, set_type='test'): - for cls_ind, cls in enumerate(labelmap): - print('Writing {:s} VOC results file'.format(cls)) - filename = get_voc_results_file_template(set_type, cls) - with open(filename, 'wt') as f: - for im_ind, index in enumerate(dataset.ids): - dets = all_boxes[cls_ind+1][im_ind] - if dets == []: - continue - # the VOCdevkit expects 1-based indices - for k in range(dets.shape[0]): - f.write('{:s} {:.3f} {:.1f} {:.1f} {:.1f} {:.1f}\n'. - format(index[1], dets[k, -1], - dets[k, 0] + 1, dets[k, 1] + 1, - dets[k, 2] + 1, dets[k, 3] + 1)) - - -def do_python_eval(output_dir='output', use_07=True, set_type='test'): - cachedir = os.path.join(devkit_path, 'annotations_cache') - aps = [] - # The PASCAL VOC metric changed in 2010 - use_07_metric = use_07 - print('VOC07 metric? ' + ('Yes' if use_07_metric else 'No')) - if not os.path.isdir(output_dir): - os.mkdir(output_dir) - for i, cls in enumerate(labelmap): - filename = get_voc_results_file_template(set_type, cls) - rec, prec, ap = voc_eval( - filename, annopath, imgsetpath.format(set_type), cls, cachedir, - ovthresh=0.5, use_07_metric=use_07_metric) - aps += [ap] - print('AP for {} = {:.4f}'.format(cls, ap)) - with open(os.path.join(output_dir, cls + '_pr.pkl'), 'wb') as f: - pickle.dump({'rec': rec, 'prec': prec, 'ap': ap}, f) - mAp = np.mean(aps) - print('Mean AP on ' + set_type + ' set = {:.4f}'.format(mAp)) - return mAp.item() - - -def voc_ap(rec, prec, use_07_metric=True): - """ ap = voc_ap(rec, prec, [use_07_metric]) - Compute VOC AP given precision and recall. - If use_07_metric is true, uses the - VOC 07 11 point method (default:True). - """ - if use_07_metric: - # 11 point metric - ap = 0. - for t in np.arange(0., 1.1, 0.1): - if np.sum(rec >= t) == 0: - p = 0 - else: - p = np.max(prec[rec >= t]) - ap = ap + p / 11. - else: - # correct AP calculation - # first append sentinel values at the end - mrec = np.concatenate(([0.], rec, [1.])) - mpre = np.concatenate(([0.], prec, [0.])) - - # compute the precision envelope - for i in range(mpre.size - 1, 0, -1): - mpre[i - 1] = np.maximum(mpre[i - 1], mpre[i]) - - # to calculate area under PR curve, look for points - # where X axis (recall) changes value - i = np.where(mrec[1:] != mrec[:-1])[0] - - # and sum (\Delta recall) * prec - ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1]) - return ap - - -def voc_eval(detpath, - annopath, - imagesetfile, - classname, - cachedir, - ovthresh=0.5, - use_07_metric=True): - """rec, prec, ap = voc_eval(detpath, - annopath, - imagesetfile, - classname, - [ovthresh], - [use_07_metric]) -Top level function that does the PASCAL VOC evaluation. -detpath: Path to detections - detpath.format(classname) should produce the detection results file. -annopath: Path to annotations - annopath.format(imagename) should be the xml annotations file. -imagesetfile: Text file containing the list of images, one image per line. -classname: Category name (duh) -cachedir: Directory for caching the annotations -[ovthresh]: Overlap threshold (default = 0.5) -[use_07_metric]: Whether to use VOC07's 11 point AP computation - (default True) -""" -# assumes detections are in detpath.format(classname) -# assumes annotations are in annopath.format(imagename) -# assumes imagesetfile is a text file with each line an image name -# cachedir caches the annotations in a pickle file -# first load gt - if not os.path.isdir(cachedir): - os.mkdir(cachedir) - cachefile = os.path.join(cachedir, 'annots.pkl') - # read list of images - with open(imagesetfile, 'r') as f: - lines = f.readlines() - imagenames = [x.strip() for x in lines] - if not os.path.isfile(cachefile): - # load annots - recs = {} - for i, imagename in enumerate(imagenames): - recs[imagename] = parse_rec(annopath % (imagename)) - if i % 100 == 0: - print('Reading annotation for {:d}/{:d}'.format( - i + 1, len(imagenames))) - # save - print('Saving cached annotations to {:s}'.format(cachefile)) - with open(cachefile, 'wb') as f: - pickle.dump(recs, f) - else: - # load - with open(cachefile, 'rb') as f: - recs = pickle.load(f) - - # extract gt objects for this class - class_recs = {} - npos = 0 - for imagename in imagenames: - R = [obj for obj in recs[imagename] if obj['name'] == classname] - bbox = np.array([x['bbox'] for x in R]) - difficult = np.array([x['difficult'] for x in R]).astype(np.bool) - det = [False] * len(R) - npos = npos + sum(~difficult) - class_recs[imagename] = {'bbox': bbox, - 'difficult': difficult, - 'det': det} - - # read dets - detfile = detpath.format(classname) - with open(detfile, 'r') as f: - lines = f.readlines() - if any(lines) == 1: - - splitlines = [x.strip().split(' ') for x in lines] - image_ids = [x[0] for x in splitlines] - confidence = np.array([float(x[1]) for x in splitlines]) - BB = np.array([[float(z) for z in x[2:]] for x in splitlines]) - - # sort by confidence - sorted_ind = np.argsort(-confidence) - sorted_scores = np.sort(-confidence) - BB = BB[sorted_ind, :] - image_ids = [image_ids[x] for x in sorted_ind] - - # go down dets and mark TPs and FPs - nd = len(image_ids) - tp = np.zeros(nd) - fp = np.zeros(nd) - for d in range(nd): - R = class_recs[image_ids[d]] - bb = BB[d, :].astype(float) - ovmax = -np.inf - BBGT = R['bbox'].astype(float) - if BBGT.size > 0: - # compute overlaps - # intersection - ixmin = np.maximum(BBGT[:, 0], bb[0]) - iymin = np.maximum(BBGT[:, 1], bb[1]) - ixmax = np.minimum(BBGT[:, 2], bb[2]) - iymax = np.minimum(BBGT[:, 3], bb[3]) - iw = np.maximum(ixmax - ixmin, 0.) - ih = np.maximum(iymax - iymin, 0.) - inters = iw * ih - uni = ((bb[2] - bb[0]) * (bb[3] - bb[1]) + - (BBGT[:, 2] - BBGT[:, 0]) * - (BBGT[:, 3] - BBGT[:, 1]) - inters) - overlaps = inters / uni - ovmax = np.max(overlaps) - jmax = np.argmax(overlaps) - - if ovmax > ovthresh: - if not R['difficult'][jmax]: - if not R['det'][jmax]: - tp[d] = 1. - R['det'][jmax] = 1 - else: - fp[d] = 1. - else: - fp[d] = 1. - - # compute precision recall - fp = np.cumsum(fp) - tp = np.cumsum(tp) - rec = tp / float(npos) - # avoid divide by zero in case the first detection matches a difficult - # ground truth - prec = tp / np.maximum(tp + fp, np.finfo(np.float64).eps) - ap = voc_ap(rec, prec, use_07_metric) - else: - rec = -1. - prec = -1. - ap = -1. - - return rec, prec, ap - - -def test_net(save_folder, net, cuda, dataset, dataloador, transform, top_k, - im_size=300, thresh=0.05, set_type='test'): - num_images = len(dataset) - # all detections are collected into: - # all_boxes[cls][image] = N x 5 array of detections in - # (x1, y1, x2, y2, score) - all_boxes = [[[] for _ in range(num_images)] - for _ in range(len(labelmap)+1)] - - # timers - _t = {'im_detect': Timer(), 'misc': Timer()} - output_dir = get_output_dir('ssd300_120000', set_type) - det_file = os.path.join(output_dir, 'detections.pkl') - - detection_list, h_list, w_list = [], [], [] - for i, item in enumerate(dataloador): - # im, gt, h, w = dataset.pull_item(i) - # print(im.shape,h,w) - - x, _, h, w = item - bs, _, _, _ = x.size() - # print(x.size()) - # x = Variable(im.unsqueeze(0)) - if cfg['cuda']: - x = x.cuda() - elif cfg['npu']: - x = x.npu() - _t['im_detect'].tic() - detections = net(x).data - detect_time = _t['im_detect'].toc(average=False) - detection_list.append(detections.cpu()) - h_list.extend(h) - w_list.extend(w) - print('im_detect: {:d}/{:d} {:.3f}s'.format(i + 1, - len(dataloador), detect_time)) - # skip j = 0, because it's the background class - strat_time = time.time() - detections = torch.cat(detection_list, dim=0) - for idx in range(detections.size(0)): - h, w = h_list[idx], w_list[idx] - for j in range(1, detections.size(1)): - #dets = detections[0, j, :] - dets = detections[idx, j, :] - mask = dets[:, 0].gt(0.).expand(5, dets.size(0)).t() - dets = torch.masked_select(dets, mask).view(-1, 5) - if dets.size(0) == 0: - continue - boxes = dets[:, 1:] - boxes[:, 0] *= w - boxes[:, 2] *= w - boxes[:, 1] *= h - boxes[:, 3] *= h - scores = dets[:, 0].cpu().numpy() - cls_dets = np.hstack((boxes.cpu().numpy(), - scores[:, np.newaxis])).astype(np.float32, - copy=False) - # all_boxes[j][i] = cls_dets - all_boxes[j][idx] = cls_dets - end_time = time.time() - print('spend time: %.3fs'%(end_time-strat_time)) - - with open(det_file, 'wb') as f: - pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL) - - print('Evaluating detections') - mAp = evaluate_detections(all_boxes, output_dir, dataset, set_type=set_type) - return mAp - - -def evaluate_detections(box_list, output_dir, dataset, set_type='test'): - write_voc_results_file(box_list, dataset, set_type=set_type) - mAp = do_python_eval(output_dir, set_type=set_type) - return mAp - - - - -if __name__ == '__main__': - pth_path, data_path = sys.argv[1:3] - if not os.path.exists(cfg['save_folder']): - os.makedirs(cfg['save_folder']) - - if torch.cuda.is_available(): - if cfg['cuda']: - torch.set_default_tensor_type('torch.cuda.FloatTensor') - if not cfg['cuda']: - print("WARNING: It looks like you have a CUDA device, but aren't using \ - CUDA. Run with --cuda for optimal eval speed.") - torch.set_default_tensor_type('torch.FloatTensor') - else: - torch.set_default_tensor_type('torch.FloatTensor') - - annopath = os.path.join(data_path, 'VOC2007', 'Annotations', '%s.xml') - imgpath = os.path.join(data_path, 'VOC2007', 'JPEGImages', '%s.jpg') - imgsetpath = os.path.join(data_path, 'VOC2007', 'ImageSets', - 'Main', '{:s}.txt') - YEAR = '2007' - devkit_path = data_path + 'VOC' + YEAR - dataset_mean = (104, 117, 123) - # load net - num_classes = len(labelmap) + 1 # +1 for background - net = build_refinedet('test', int(cfg['input_size']), num_classes, batch_norm=True) # initialize SSD - - - - # load data - set_type = 'test' - dataset = VOCDetection(root=data_path, - image_sets=[('2007', set_type)], - transform=BaseTransform(int(cfg['input_size']), dataset_mean), - target_transform=VOCAnnotationTransform(), - dataset_name='VOC07test') - - if cfg['cuda']: - net = net.cuda() - cudnn.benchmark = True - elif cfg['npu']: - net = net.npu() - cudnn.benchmark = True - - if cfg['amp']: - net = amp.initialize(net, opt_level='O1', loss_scale=128) - - - net.eval() - data_loader = data.DataLoader(dataset, - batch_size=128, - num_workers=16, - shuffle=False, - collate_fn=detection_collate_test, - pin_memory=True) - save_path = './RefineDet320_bn/RefineDet320_VOC_231.pth' - save_path = pth_path - net.load_state_dict(torch.load(save_path, map_location='cpu')) - print('Finished loading model! ' + save_path) - - # evaluation - with torch.no_grad(): - mAp = test_net(cfg['save_folder'], net, cfg['cuda'], dataset, data_loader, - BaseTransform(int(cfg['input_size']), dataset_mean), cfg['top_k'], int(cfg['input_size']), - thresh=cfg['confidence_threshold']) +#!/bin/bash +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Adapted from: + @longcw faster_rcnn_pytorch: https://github.com/longcw/faster_rcnn_pytorch + @rbgirshick py-faster-rcnn https://github.com/rbgirshick/py-faster-rcnn + Licensed under The MIT License [see LICENSE for details] +""" + +from __future__ import print_function +import torch +import torch.nn as nn +import torch.backends.cudnn as cudnn +from torch.autograd import Variable +from data import VOCAnnotationTransform, VOCDetection, BaseTransform +from data import VOC_CLASSES as labelmap +from data import voc_refinedet, detection_collate_test +import torch.utils.data as data + +from models.refinedet import build_refinedet + +import sys +import os +import time +import argparse +import numpy as np +import pickle +import cv2 +from apex import amp + +cfg = voc_refinedet['320'] + +if sys.version_info[0] == 2: + import xml.etree.cElementTree as ET +else: + import xml.etree.ElementTree as ET + +def str2bool(v): + return v.lower() in ("yes", "true", "t", "1") + +class Timer(object): + """A simple timer.""" + def __init__(self): + self.total_time = 0. + self.calls = 0 + self.start_time = 0. + self.diff = 0. + self.average_time = 0. + + def tic(self): + self.start_time = time.time() + + def toc(self, average=True): + self.diff = time.time() - self.start_time + self.total_time += self.diff + self.calls += 1 + self.average_time = self.total_time / self.calls + if average: + return self.average_time + else: + return self.diff + + +def parse_rec(filename): + """ Parse a PASCAL VOC xml file """ + tree = ET.parse(filename) + objects = [] + for obj in tree.findall('object'): + obj_struct = {} + obj_struct['name'] = obj.find('name').text + obj_struct['pose'] = obj.find('pose').text + obj_struct['truncated'] = int(obj.find('truncated').text) + obj_struct['difficult'] = int(obj.find('difficult').text) + bbox = obj.find('bndbox') + obj_struct['bbox'] = [int(bbox.find('xmin').text) - 1, + int(bbox.find('ymin').text) - 1, + int(bbox.find('xmax').text) - 1, + int(bbox.find('ymax').text) - 1] + objects.append(obj_struct) + + return objects + + +def get_output_dir(name, phase): + """Return the directory where experimental artifacts are placed. + If the directory does not exist, it is created. + A canonical path is built using the name from an imdb and a network + (if not None). + """ + filedir = os.path.join(name, phase) + if not os.path.exists(filedir): + os.makedirs(filedir) + return filedir + + +def get_voc_results_file_template(image_set, cls): + filename = 'det_' + image_set + '_%s.txt' % (cls) + filedir = os.path.join(devkit_path, 'results') + if not os.path.exists(filedir): + os.makedirs(filedir) + path = os.path.join(filedir, filename) + return path + + +def write_voc_results_file(all_boxes, dataset, set_type='test'): + for cls_ind, cls in enumerate(labelmap): + print('Writing {:s} VOC results file'.format(cls)) + filename = get_voc_results_file_template(set_type, cls) + with open(filename, 'wt') as f: + for im_ind, index in enumerate(dataset.ids): + dets = all_boxes[cls_ind+1][im_ind] + if dets == []: + continue + # the VOCdevkit expects 1-based indices + for k in range(dets.shape[0]): + f.write('{:s} {:.3f} {:.1f} {:.1f} {:.1f} {:.1f}\n'. + format(index[1], dets[k, -1], + dets[k, 0] + 1, dets[k, 1] + 1, + dets[k, 2] + 1, dets[k, 3] + 1)) + + +def do_python_eval(output_dir='output', use_07=True, set_type='test'): + cachedir = os.path.join(devkit_path, 'annotations_cache') + aps = [] + # The PASCAL VOC metric changed in 2010 + use_07_metric = use_07 + print('VOC07 metric? ' + ('Yes' if use_07_metric else 'No')) + if not os.path.isdir(output_dir): + os.mkdir(output_dir) + for i, cls in enumerate(labelmap): + filename = get_voc_results_file_template(set_type, cls) + rec, prec, ap = voc_eval( + filename, annopath, imgsetpath.format(set_type), cls, cachedir, + ovthresh=0.5, use_07_metric=use_07_metric) + aps += [ap] + print('AP for {} = {:.4f}'.format(cls, ap)) + with open(os.path.join(output_dir, cls + '_pr.pkl'), 'wb') as f: + pickle.dump({'rec': rec, 'prec': prec, 'ap': ap}, f) + mAp = np.mean(aps) + print('Mean AP on ' + set_type + ' set = {:.4f}'.format(mAp)) + return mAp.item() + + +def voc_ap(rec, prec, use_07_metric=True): + """ ap = voc_ap(rec, prec, [use_07_metric]) + Compute VOC AP given precision and recall. + If use_07_metric is true, uses the + VOC 07 11 point method (default:True). + """ + if use_07_metric: + # 11 point metric + ap = 0. + for t in np.arange(0., 1.1, 0.1): + if np.sum(rec >= t) == 0: + p = 0 + else: + p = np.max(prec[rec >= t]) + ap = ap + p / 11. + else: + # correct AP calculation + # first append sentinel values at the end + mrec = np.concatenate(([0.], rec, [1.])) + mpre = np.concatenate(([0.], prec, [0.])) + + # compute the precision envelope + for i in range(mpre.size - 1, 0, -1): + mpre[i - 1] = np.maximum(mpre[i - 1], mpre[i]) + + # to calculate area under PR curve, look for points + # where X axis (recall) changes value + i = np.where(mrec[1:] != mrec[:-1])[0] + + # and sum (\Delta recall) * prec + ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1]) + return ap + + +def voc_eval(detpath, + annopath, + imagesetfile, + classname, + cachedir, + ovthresh=0.5, + use_07_metric=True): + """rec, prec, ap = voc_eval(detpath, + annopath, + imagesetfile, + classname, + [ovthresh], + [use_07_metric]) +Top level function that does the PASCAL VOC evaluation. +detpath: Path to detections + detpath.format(classname) should produce the detection results file. +annopath: Path to annotations + annopath.format(imagename) should be the xml annotations file. +imagesetfile: Text file containing the list of images, one image per line. +classname: Category name (duh) +cachedir: Directory for caching the annotations +[ovthresh]: Overlap threshold (default = 0.5) +[use_07_metric]: Whether to use VOC07's 11 point AP computation + (default True) +""" +# assumes detections are in detpath.format(classname) +# assumes annotations are in annopath.format(imagename) +# assumes imagesetfile is a text file with each line an image name +# cachedir caches the annotations in a pickle file +# first load gt + if not os.path.isdir(cachedir): + os.mkdir(cachedir) + cachefile = os.path.join(cachedir, 'annots.pkl') + # read list of images + with open(imagesetfile, 'r') as f: + lines = f.readlines() + imagenames = [x.strip() for x in lines] + if not os.path.isfile(cachefile): + # load annots + recs = {} + for i, imagename in enumerate(imagenames): + recs[imagename] = parse_rec(annopath % (imagename)) + if i % 100 == 0: + print('Reading annotation for {:d}/{:d}'.format( + i + 1, len(imagenames))) + # save + print('Saving cached annotations to {:s}'.format(cachefile)) + with open(cachefile, 'wb') as f: + pickle.dump(recs, f) + else: + # load + with open(cachefile, 'rb') as f: + recs = pickle.load(f) + + # extract gt objects for this class + class_recs = {} + npos = 0 + for imagename in imagenames: + R = [obj for obj in recs[imagename] if obj['name'] == classname] + bbox = np.array([x['bbox'] for x in R]) + difficult = np.array([x['difficult'] for x in R]).astype(np.bool) + det = [False] * len(R) + npos = npos + sum(~difficult) + class_recs[imagename] = {'bbox': bbox, + 'difficult': difficult, + 'det': det} + + # read dets + detfile = detpath.format(classname) + with open(detfile, 'r') as f: + lines = f.readlines() + if any(lines) == 1: + + splitlines = [x.strip().split(' ') for x in lines] + image_ids = [x[0] for x in splitlines] + confidence = np.array([float(x[1]) for x in splitlines]) + BB = np.array([[float(z) for z in x[2:]] for x in splitlines]) + + # sort by confidence + sorted_ind = np.argsort(-confidence) + sorted_scores = np.sort(-confidence) + BB = BB[sorted_ind, :] + image_ids = [image_ids[x] for x in sorted_ind] + + # go down dets and mark TPs and FPs + nd = len(image_ids) + tp = np.zeros(nd) + fp = np.zeros(nd) + for d in range(nd): + R = class_recs[image_ids[d]] + bb = BB[d, :].astype(float) + ovmax = -np.inf + BBGT = R['bbox'].astype(float) + if BBGT.size > 0: + # compute overlaps + # intersection + ixmin = np.maximum(BBGT[:, 0], bb[0]) + iymin = np.maximum(BBGT[:, 1], bb[1]) + ixmax = np.minimum(BBGT[:, 2], bb[2]) + iymax = np.minimum(BBGT[:, 3], bb[3]) + iw = np.maximum(ixmax - ixmin, 0.) + ih = np.maximum(iymax - iymin, 0.) + inters = iw * ih + uni = ((bb[2] - bb[0]) * (bb[3] - bb[1]) + + (BBGT[:, 2] - BBGT[:, 0]) * + (BBGT[:, 3] - BBGT[:, 1]) - inters) + overlaps = inters / uni + ovmax = np.max(overlaps) + jmax = np.argmax(overlaps) + + if ovmax > ovthresh: + if not R['difficult'][jmax]: + if not R['det'][jmax]: + tp[d] = 1. + R['det'][jmax] = 1 + else: + fp[d] = 1. + else: + fp[d] = 1. + + # compute precision recall + fp = np.cumsum(fp) + tp = np.cumsum(tp) + rec = tp / float(npos) + # avoid divide by zero in case the first detection matches a difficult + # ground truth + prec = tp / np.maximum(tp + fp, np.finfo(np.float64).eps) + ap = voc_ap(rec, prec, use_07_metric) + else: + rec = -1. + prec = -1. + ap = -1. + + return rec, prec, ap + + +def test_net(save_folder, net, cuda, dataset, dataloador, transform, top_k, + im_size=300, thresh=0.05, set_type='test'): + num_images = len(dataset) + # all detections are collected into: + # all_boxes[cls][image] = N x 5 array of detections in + # (x1, y1, x2, y2, score) + all_boxes = [[[] for _ in range(num_images)] + for _ in range(len(labelmap)+1)] + + # timers + _t = {'im_detect': Timer(), 'misc': Timer()} + output_dir = get_output_dir('ssd300_120000', set_type) + det_file = os.path.join(output_dir, 'detections.pkl') + + detection_list, h_list, w_list = [], [], [] + for i, item in enumerate(dataloador): + # im, gt, h, w = dataset.pull_item(i) + # print(im.shape,h,w) + + x, _, h, w = item + bs, _, _, _ = x.size() + # print(x.size()) + # x = Variable(im.unsqueeze(0)) + if cfg['cuda']: + x = x.cuda() + elif cfg['npu']: + x = x.npu() + _t['im_detect'].tic() + detections = net(x).data + detect_time = _t['im_detect'].toc(average=False) + detection_list.append(detections.cpu()) + h_list.extend(h) + w_list.extend(w) + print('im_detect: {:d}/{:d} {:.3f}s'.format(i + 1, + len(dataloador), detect_time)) + # skip j = 0, because it's the background class + strat_time = time.time() + detections = torch.cat(detection_list, dim=0) + for idx in range(detections.size(0)): + h, w = h_list[idx], w_list[idx] + for j in range(1, detections.size(1)): + #dets = detections[0, j, :] + dets = detections[idx, j, :] + mask = dets[:, 0].gt(0.).expand(5, dets.size(0)).t() + dets = torch.masked_select(dets, mask).view(-1, 5) + if dets.size(0) == 0: + continue + boxes = dets[:, 1:] + boxes[:, 0] *= w + boxes[:, 2] *= w + boxes[:, 1] *= h + boxes[:, 3] *= h + scores = dets[:, 0].cpu().numpy() + cls_dets = np.hstack((boxes.cpu().numpy(), + scores[:, np.newaxis])).astype(np.float32, + copy=False) + # all_boxes[j][i] = cls_dets + all_boxes[j][idx] = cls_dets + end_time = time.time() + print('spend time: %.3fs'%(end_time-strat_time)) + + with open(det_file, 'wb') as f: + pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL) + + print('Evaluating detections') + mAp = evaluate_detections(all_boxes, output_dir, dataset, set_type=set_type) + return mAp + + +def evaluate_detections(box_list, output_dir, dataset, set_type='test'): + write_voc_results_file(box_list, dataset, set_type=set_type) + mAp = do_python_eval(output_dir, set_type=set_type) + return mAp + + + + +if __name__ == '__main__': + pth_path, data_path = sys.argv[1:3] + if not os.path.exists(cfg['save_folder']): + os.makedirs(cfg['save_folder']) + + if torch.cuda.is_available(): + if cfg['cuda']: + torch.set_default_tensor_type('torch.cuda.FloatTensor') + if not cfg['cuda']: + print("WARNING: It looks like you have a CUDA device, but aren't using \ + CUDA. Run with --cuda for optimal eval speed.") + torch.set_default_tensor_type('torch.FloatTensor') + else: + torch.set_default_tensor_type('torch.FloatTensor') + + annopath = os.path.join(data_path, 'VOC2007', 'Annotations', '%s.xml') + imgpath = os.path.join(data_path, 'VOC2007', 'JPEGImages', '%s.jpg') + imgsetpath = os.path.join(data_path, 'VOC2007', 'ImageSets', + 'Main', '{:s}.txt') + YEAR = '2007' + devkit_path = data_path + 'VOC' + YEAR + dataset_mean = (104, 117, 123) + # load net + num_classes = len(labelmap) + 1 # +1 for background + net = build_refinedet('test', int(cfg['input_size']), num_classes, batch_norm=True) # initialize SSD + + + + # load data + set_type = 'test' + dataset = VOCDetection(root=data_path, + image_sets=[('2007', set_type)], + transform=BaseTransform(int(cfg['input_size']), dataset_mean), + target_transform=VOCAnnotationTransform(), + dataset_name='VOC07test') + + if cfg['cuda']: + net = net.cuda() + cudnn.benchmark = True + elif cfg['npu']: + net = net.npu() + cudnn.benchmark = True + + if cfg['amp']: + net = amp.initialize(net, opt_level='O1', loss_scale=128) + + + net.eval() + data_loader = data.DataLoader(dataset, + batch_size=128, + num_workers=16, + shuffle=False, + collate_fn=detection_collate_test, + pin_memory=True) + save_path = './RefineDet320_bn/RefineDet320_VOC_231.pth' + save_path = pth_path + net.load_state_dict(torch.load(save_path, map_location='cpu')) + print('Finished loading model! ' + save_path) + + # evaluation + with torch.no_grad(): + mAp = test_net(cfg['save_folder'], net, cfg['cuda'], dataset, data_loader, + BaseTransform(int(cfg['input_size']), dataset_mean), cfg['top_k'], int(cfg['input_size']), + thresh=cfg['confidence_threshold']) diff --git a/PyTorch/contrib/cv/detection/RefineDet/models/timeAcc.py b/PyTorch/contrib/cv/detection/RefineDet/models/timeAcc.py index 3c81c2329ccb89b0d6fde50d3565f1418bbc9c18..91507f0850c6a73de3ca62c277b70e79b35695bd 100644 --- a/PyTorch/contrib/cv/detection/RefineDet/models/timeAcc.py +++ b/PyTorch/contrib/cv/detection/RefineDet/models/timeAcc.py @@ -1,43 +1,43 @@ -#!/bin/bash -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -class AverageMeter(object): - """Computes and stores the average and current value""" - - def __init__(self, name, fmt=':f', start_count_index=20): - self.name = name - self.fmt = fmt - self.reset() - self.start_count_index = start_count_index - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - - def update(self, val, n=1): - if self.count == 0: - self.N = n - - self.val = val - self.count += n - if self.count > (self.start_count_index * self.N): - self.sum += val * n - self.avg = self.sum / (self.count - self.start_count_index * self.N) - - def __str__(self): - fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' +#!/bin/bash +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class AverageMeter(object): + """Computes and stores the average and current value""" + + def __init__(self, name, fmt=':f', start_count_index=20): + self.name = name + self.fmt = fmt + self.reset() + self.start_count_index = start_count_index + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + if self.count == 0: + self.N = n + + self.val = val + self.count += n + if self.count > (self.start_count_index * self.N): + self.sum += val * n + self.avg = self.sum / (self.count - self.start_count_index * self.N) + + def __str__(self): + fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' return fmtstr.format(**self.__dict__) \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/RefineDet/modelzoo_level.txt b/PyTorch/contrib/cv/detection/RefineDet/modelzoo_level.txt index a17c8f95fa388fbc6d253e2cd7cfd0b73b734073..a829ab59b97a1022dd6fc33b59b7ae0d55009432 100644 --- a/PyTorch/contrib/cv/detection/RefineDet/modelzoo_level.txt +++ b/PyTorch/contrib/cv/detection/RefineDet/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/RefineDet/requirements.txt b/PyTorch/contrib/cv/detection/RefineDet/requirements.txt index 8b4a0d1903fad4657f9ca923c594109c5581dd24..9e1c0e66604f932c9a93457c02c0025ea8439c04 100644 --- a/PyTorch/contrib/cv/detection/RefineDet/requirements.txt +++ b/PyTorch/contrib/cv/detection/RefineDet/requirements.txt @@ -1,10 +1,10 @@ -torch==1.5.0+ascend.post3 -apex==0.1+ascend -future==0.18.2 -numpy==1.21.2 -opencv-python==4.5.3.56 -torchvision==0.2.2 -pillow==8.3.2 -six==1.16.0 -decorator==4.4.2 +torch==1.5.0+ascend.post3 +apex==0.1+ascend +future==0.18.2 +numpy==1.21.2 +opencv-python==4.5.3.56 +torchvision==0.2.2 +pillow==8.3.2 +six==1.16.0 +decorator==4.4.2 sympy==1.4 \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/RefineDet/train_1p.py b/PyTorch/contrib/cv/detection/RefineDet/train_1p.py index fcc73899b3e61e459ed09350bd6504a91ecf7dfb..3a72f5378558e7e011ee2296bf126a4bc06afb5f 100644 --- a/PyTorch/contrib/cv/detection/RefineDet/train_1p.py +++ b/PyTorch/contrib/cv/detection/RefineDet/train_1p.py @@ -1,284 +1,284 @@ -#!/bin/bash -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# coding=utf-8 -from models.timeAcc import AverageMeter -from data import VOC_CLASSES as labelmap -from data import VOCAnnotationTransform, VOCDetection, BaseTransform -from data import * -from utils.augmentations import SSDAugmentation -from layers.modules import RefineDetMultiBoxLoss -from models.refinedet import build_refinedet -from apex import amp -import apex -import os -import sys -import time -import torch -import torch.nn as nn -import torch.optim as optim -import torch.backends.cudnn as cudnn -import torch.nn.init as init -import torch.utils.data as data -import numpy as np -import argparse -from utils.logging import Logger -from torch.hub import load_state_dict_from_url -import torch.npu -CALCULATE_DEVICE = "npu" - -def str2bool(v): - return v.lower() in ("yes", "true", "t", "1") - -if sys.version_info[0] == 2: - import xml.etree.cElementTree as ET -else: - import xml.etree.ElementTree as ET -parser = argparse.ArgumentParser( - description='Single Shot MultiBox Detector Training With Pytorch') -train_set = parser.add_mutually_exclusive_group() -parser.add_argument('--dataset', default='VOC', choices=['VOC', 'COCO'], - type=str, help='VOC or COCO') -parser.add_argument('--input_size', default='320', choices=['320', '512'], - type=str, help='RefineDet320 or RefineDet512') -parser.add_argument('--dataset_root', default='/home/ljh/refinedet/data/VOCdevkit/', - help='Dataset root directory path') -parser.add_argument('--basenet', default='weights/vgg16_reducedfc.pth', - help='Pretrained base model') -parser.add_argument('--batch_size', default=32, type=int, - help='Batch size for training') -parser.add_argument('--resume', default=None, type=str, - help='Checkpoint state_dict file to resume training from') -parser.add_argument('--start_epoch', default=0, type=int, - help='Resume training at this epoch') -parser.add_argument('--num_epochs', default=232, type=int, - help='Total train epoch') -parser.add_argument('--num_workers', default=14, type=int, - help='Number of workers used in dataloading') -parser.add_argument('--cuda', default=False, type=str2bool, - help='Use CUDA to train model') -parser.add_argument('--npu', default=True, type=str2bool, - help='Use NPU to train model') -parser.add_argument('--lr', '--learning-rate', default=0.00095, type=float, - help='initial learning rate') -parser.add_argument('--momentum', default=0.9, type=float, - help='Momentum value for optim') -parser.add_argument('--weight_decay', default=5e-4, type=float, - help='Weight decay for SGD') -parser.add_argument('--gamma', default=0.1, type=float, - help='Gamma update for SGD') -parser.add_argument('--visdom', default=False, type=str2bool, - help='Use visdom for loss visualization') -parser.add_argument('--save_folder', default='weights/', - help='Directory for saving checkpoint models') -parser.add_argument('--local_rank', default=-1, type=int, - help='node rank for distributed training') -parser.add_argument('--finetune', default=None, type=str, - help='pretrained weight path') -parser.add_argument('--train_1p', default=False, type=str2bool, - help='node rank for distributed training') -parser.add_argument('--device_id', default=0, type=str, - help='device_id') -parser.add_argument('--amp', default=True, type=str2bool, - help='whether to use amp') -parser.add_argument('--num_classes', default=-1, type=int, - help='num classes') -args = parser.parse_args() - - -if torch.cuda.is_available(): - if args.cuda: - torch.set_default_tensor_type('torch.cuda.FloatTensor') - if not args.cuda: - print("WARNING: It looks like you have a CUDA device, but aren't " + - "using CUDA.\nRun with --cuda for optimal training speed.") - torch.set_default_tensor_type('torch.FloatTensor') -else: - torch.set_default_tensor_type('torch.FloatTensor') - -if not os.path.exists(args.save_folder): - os.mkdir(args.save_folder) - -sys.stdout = Logger(os.path.join(args.save_folder, 'log.txt')) - -def train(): - torch.npu.set_device('npu:' + str(args.device_id)) - - if args.dataset == 'VOC': - '''if args.dataset_root == COCO_ROOT: - parser.error('Must specify dataset if specifying dataset_root')''' - cfg = voc_refinedet[args.input_size] - dataset = VOCDetection(root=args.dataset_root, - transform=SSDAugmentation(cfg['min_dim'], MEANS)) # cfg['min_dim'] = 320 - - if args.finetune: - print('finetune numclass %d'%args.num_classes) - refinedet_net = build_refinedet('train', cfg['min_dim'], args.num_classes, batch_norm=True) - else: - refinedet_net = build_refinedet('train', cfg['min_dim'], cfg['num_classes'], batch_norm=True) - net = refinedet_net - if args.cuda: - net = net.cuda() - if args.npu: - net = net.npu() - if args.resume: - print('Resuming training, loading {}...'.format(args.resume)) - refinedet_net.load_weights(args.resume) - else: - print('Loading vgg...') - vgg_weights = load_state_dict_from_url('https://download.pytorch.org/models/vgg16_bn-6c64b313.pth', - progress=True) - from collections import OrderedDict - new_vgg_weights = OrderedDict() - for k, v in vgg_weights.items(): - fc, num, wb = k.split('.') - if fc == 'classifier': - continue - new_k = num + '.' + wb - new_vgg_weights[new_k] = v - refinedet_net.vgg.load_state_dict(new_vgg_weights, strict=False) - if not args.resume: - print('Initializing weights...') - refinedet_net.extras.apply(weights_init) - refinedet_net.arm_loc.apply(weights_init) - refinedet_net.arm_conf.apply(weights_init) - refinedet_net.odm_loc.apply(weights_init) - refinedet_net.odm_conf.apply(weights_init) - refinedet_net.tcb0.apply(weights_init) - refinedet_net.tcb1.apply(weights_init) - refinedet_net.tcb2.apply(weights_init) - optimizer = apex.optimizers.NpuFusedSGD(net.parameters(), lr=args.lr, momentum=args.momentum, - weight_decay=args.weight_decay) - arm_criterion = RefineDetMultiBoxLoss(2, 0.5, True, 0, True, 3, 0.5, - False, args.cuda, npu_device=CALCULATE_DEVICE) - if args.finetune: - stat_dict = torch.load(args.finetune, map_location='cpu') - for k in stat_dict.keys(): - if 'odm_conf' in k: - stat_dict.pop(k) - net.load_state_dict(stat_dict, strict=False) - odm_criterion = RefineDetMultiBoxLoss(args.num_classes, 0.5, True, 0, True, 3, 0.5, - False, args.cuda, use_ARM=True, npu_device=CALCULATE_DEVICE) - else: - odm_criterion = RefineDetMultiBoxLoss(cfg['num_classes'], 0.5, True, 0, True, 3, 0.5, - False, args.cuda, use_ARM=True, npu_device=CALCULATE_DEVICE) - if args.amp: - net, optimizer = amp.initialize(net, optimizer, opt_level='O1', loss_scale=128, combine_grad=True) - if args.cuda: - net = torch.nn.DataParallel(refinedet_net) - cudnn.benchmark = True - net.train() - arm_loc_loss = 0 - arm_conf_loss = 0 - odm_loc_loss = 0 - odm_conf_loss = 0 - print('Loading the dataset...') - epoch_size = len(dataset) // args.batch_size - if len(dataset) % args.batch_size != 0: - epoch_size += 1 - print('Training RefineDet on:', dataset.name) - print('Using the specified args:') - print(args) - step_index = 0 - data_loader = data.DataLoader(dataset, args.batch_size, - num_workers=args.num_workers, - shuffle=True, collate_fn=detection_collate, - pin_memory=True, - drop_last=True) - - if args.resume: - strat_iter = args.start_epoch * epoch_size - for step in cfg['lr_steps']: - if strat_iter > step: - step_index += 1 - adjust_learning_rate(optimizer, args.gamma, step_index) - - for epoch in range(args.start_epoch, args.num_epochs): - avg_time = AverageMeter('iter_time') - print('\n' + 'epoch ' + str(epoch)) - print('================================train model on trainval set================================') - for iteration, (images, targets) in zip(range(epoch * epoch_size, (epoch + 1) * epoch_size), data_loader): - if iteration in cfg['lr_steps']: - step_index += 1 - adjust_learning_rate(optimizer, args.gamma, step_index) - - if args.cuda: - images = images.cuda() - targets = [ann.cuda() for ann in targets] - elif args.npu: - images = images.to(CALCULATE_DEVICE) - targets = [ann.to(CALCULATE_DEVICE) for ann in targets] - else: - images = images - targets = [ann for ann in targets] - t0 = time.time() - out = net(images) - optimizer.zero_grad() - arm_loss_l, arm_loss_c = arm_criterion(out, targets) - odm_loss_l, odm_loss_c = odm_criterion(out, targets) - arm_loss = arm_loss_l + arm_loss_c - odm_loss = odm_loss_l + odm_loss_c - loss = arm_loss + odm_loss - if args.amp: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - t1 = time.time() - arm_loc_loss += arm_loss_l.item() - arm_conf_loss += arm_loss_c.item() - odm_loc_loss += odm_loss_l.item() - odm_conf_loss += odm_loss_c.item() - avg_time.update(t1 - t0) - if iteration % 10 == 0: - print('iter ' + repr( \ - iteration) + ' || ARM_L Loss: %.4f ARM_C Loss: %.4f ODM_L Loss: %.4f ODM_C Loss: %.4f ||' \ - % (arm_loss_l.item(), arm_loss_c.item(), odm_loss_l.item(), odm_loss_c.item()), end=' ') - print('timer: %.4f sec.' % (t1 - t0)) - - print('batch_size = ' + str(args.batch_size) + ' || num_devices = ' + '1' + ' || time_avg = %.4f' % avg_time.avg) - print('FPS = %.4f' % (args.batch_size / avg_time.avg)) - print('Saving state, iter:' + str(epoch_size * (epoch + 1) - 1) + ' , epoch:' + str(epoch)) - save_path = args.save_folder + '/RefineDet{}_{}_{}.pth'.format(args.input_size, args.dataset, epoch) - torch.save(refinedet_net.state_dict(), save_path) - -def adjust_learning_rate(optimizer, gamma, step): - """Sets the learning rate to the initial LR decayed by 10 at every - specified step - # Adapted from PyTorch Imagenet example: - # https://github.com/pytorch/examples/blob/master/imagenet/main.py - """ - lr = args.lr * (gamma ** (step)) - for param_group in optimizer.param_groups: - param_group['lr'] = lr - -def xavier(param): - init.xavier_uniform_(param) - -def weights_init(m): - if isinstance(m, nn.Conv2d): - with torch.no_grad(): - init.xavier_uniform_(m.weight) - with torch.no_grad(): - m.bias.zero_() - elif isinstance(m, nn.ConvTranspose2d): - xavier(m.weight.data) - with torch.no_grad(): - m.bias.zero_() -if __name__ == '__main__': - train() - - +#!/bin/bash +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# coding=utf-8 +from models.timeAcc import AverageMeter +from data import VOC_CLASSES as labelmap +from data import VOCAnnotationTransform, VOCDetection, BaseTransform +from data import * +from utils.augmentations import SSDAugmentation +from layers.modules import RefineDetMultiBoxLoss +from models.refinedet import build_refinedet +from apex import amp +import apex +import os +import sys +import time +import torch +import torch.nn as nn +import torch.optim as optim +import torch.backends.cudnn as cudnn +import torch.nn.init as init +import torch.utils.data as data +import numpy as np +import argparse +from utils.logging import Logger +from torch.hub import load_state_dict_from_url +import torch.npu +CALCULATE_DEVICE = "npu" + +def str2bool(v): + return v.lower() in ("yes", "true", "t", "1") + +if sys.version_info[0] == 2: + import xml.etree.cElementTree as ET +else: + import xml.etree.ElementTree as ET +parser = argparse.ArgumentParser( + description='Single Shot MultiBox Detector Training With Pytorch') +train_set = parser.add_mutually_exclusive_group() +parser.add_argument('--dataset', default='VOC', choices=['VOC', 'COCO'], + type=str, help='VOC or COCO') +parser.add_argument('--input_size', default='320', choices=['320', '512'], + type=str, help='RefineDet320 or RefineDet512') +parser.add_argument('--dataset_root', default='/home/ljh/refinedet/data/VOCdevkit/', + help='Dataset root directory path') +parser.add_argument('--basenet', default='weights/vgg16_reducedfc.pth', + help='Pretrained base model') +parser.add_argument('--batch_size', default=32, type=int, + help='Batch size for training') +parser.add_argument('--resume', default=None, type=str, + help='Checkpoint state_dict file to resume training from') +parser.add_argument('--start_epoch', default=0, type=int, + help='Resume training at this epoch') +parser.add_argument('--num_epochs', default=232, type=int, + help='Total train epoch') +parser.add_argument('--num_workers', default=14, type=int, + help='Number of workers used in dataloading') +parser.add_argument('--cuda', default=False, type=str2bool, + help='Use CUDA to train model') +parser.add_argument('--npu', default=True, type=str2bool, + help='Use NPU to train model') +parser.add_argument('--lr', '--learning-rate', default=0.00095, type=float, + help='initial learning rate') +parser.add_argument('--momentum', default=0.9, type=float, + help='Momentum value for optim') +parser.add_argument('--weight_decay', default=5e-4, type=float, + help='Weight decay for SGD') +parser.add_argument('--gamma', default=0.1, type=float, + help='Gamma update for SGD') +parser.add_argument('--visdom', default=False, type=str2bool, + help='Use visdom for loss visualization') +parser.add_argument('--save_folder', default='weights/', + help='Directory for saving checkpoint models') +parser.add_argument('--local_rank', default=-1, type=int, + help='node rank for distributed training') +parser.add_argument('--finetune', default=None, type=str, + help='pretrained weight path') +parser.add_argument('--train_1p', default=False, type=str2bool, + help='node rank for distributed training') +parser.add_argument('--device_id', default=0, type=str, + help='device_id') +parser.add_argument('--amp', default=True, type=str2bool, + help='whether to use amp') +parser.add_argument('--num_classes', default=-1, type=int, + help='num classes') +args = parser.parse_args() + + +if torch.cuda.is_available(): + if args.cuda: + torch.set_default_tensor_type('torch.cuda.FloatTensor') + if not args.cuda: + print("WARNING: It looks like you have a CUDA device, but aren't " + + "using CUDA.\nRun with --cuda for optimal training speed.") + torch.set_default_tensor_type('torch.FloatTensor') +else: + torch.set_default_tensor_type('torch.FloatTensor') + +if not os.path.exists(args.save_folder): + os.mkdir(args.save_folder) + +sys.stdout = Logger(os.path.join(args.save_folder, 'log.txt')) + +def train(): + torch.npu.set_device('npu:' + str(args.device_id)) + + if args.dataset == 'VOC': + '''if args.dataset_root == COCO_ROOT: + parser.error('Must specify dataset if specifying dataset_root')''' + cfg = voc_refinedet[args.input_size] + dataset = VOCDetection(root=args.dataset_root, + transform=SSDAugmentation(cfg['min_dim'], MEANS)) # cfg['min_dim'] = 320 + + if args.finetune: + print('finetune numclass %d'%args.num_classes) + refinedet_net = build_refinedet('train', cfg['min_dim'], args.num_classes, batch_norm=True) + else: + refinedet_net = build_refinedet('train', cfg['min_dim'], cfg['num_classes'], batch_norm=True) + net = refinedet_net + if args.cuda: + net = net.cuda() + if args.npu: + net = net.npu() + if args.resume: + print('Resuming training, loading {}...'.format(args.resume)) + refinedet_net.load_weights(args.resume) + else: + print('Loading vgg...') + vgg_weights = load_state_dict_from_url('https://download.pytorch.org/models/vgg16_bn-6c64b313.pth', + progress=True) + from collections import OrderedDict + new_vgg_weights = OrderedDict() + for k, v in vgg_weights.items(): + fc, num, wb = k.split('.') + if fc == 'classifier': + continue + new_k = num + '.' + wb + new_vgg_weights[new_k] = v + refinedet_net.vgg.load_state_dict(new_vgg_weights, strict=False) + if not args.resume: + print('Initializing weights...') + refinedet_net.extras.apply(weights_init) + refinedet_net.arm_loc.apply(weights_init) + refinedet_net.arm_conf.apply(weights_init) + refinedet_net.odm_loc.apply(weights_init) + refinedet_net.odm_conf.apply(weights_init) + refinedet_net.tcb0.apply(weights_init) + refinedet_net.tcb1.apply(weights_init) + refinedet_net.tcb2.apply(weights_init) + optimizer = apex.optimizers.NpuFusedSGD(net.parameters(), lr=args.lr, momentum=args.momentum, + weight_decay=args.weight_decay) + arm_criterion = RefineDetMultiBoxLoss(2, 0.5, True, 0, True, 3, 0.5, + False, args.cuda, npu_device=CALCULATE_DEVICE) + if args.finetune: + stat_dict = torch.load(args.finetune, map_location='cpu') + for k in stat_dict.keys(): + if 'odm_conf' in k: + stat_dict.pop(k) + net.load_state_dict(stat_dict, strict=False) + odm_criterion = RefineDetMultiBoxLoss(args.num_classes, 0.5, True, 0, True, 3, 0.5, + False, args.cuda, use_ARM=True, npu_device=CALCULATE_DEVICE) + else: + odm_criterion = RefineDetMultiBoxLoss(cfg['num_classes'], 0.5, True, 0, True, 3, 0.5, + False, args.cuda, use_ARM=True, npu_device=CALCULATE_DEVICE) + if args.amp: + net, optimizer = amp.initialize(net, optimizer, opt_level='O1', loss_scale=128, combine_grad=True) + if args.cuda: + net = torch.nn.DataParallel(refinedet_net) + cudnn.benchmark = True + net.train() + arm_loc_loss = 0 + arm_conf_loss = 0 + odm_loc_loss = 0 + odm_conf_loss = 0 + print('Loading the dataset...') + epoch_size = len(dataset) // args.batch_size + if len(dataset) % args.batch_size != 0: + epoch_size += 1 + print('Training RefineDet on:', dataset.name) + print('Using the specified args:') + print(args) + step_index = 0 + data_loader = data.DataLoader(dataset, args.batch_size, + num_workers=args.num_workers, + shuffle=True, collate_fn=detection_collate, + pin_memory=True, + drop_last=True) + + if args.resume: + strat_iter = args.start_epoch * epoch_size + for step in cfg['lr_steps']: + if strat_iter > step: + step_index += 1 + adjust_learning_rate(optimizer, args.gamma, step_index) + + for epoch in range(args.start_epoch, args.num_epochs): + avg_time = AverageMeter('iter_time') + print('\n' + 'epoch ' + str(epoch)) + print('================================train model on trainval set================================') + for iteration, (images, targets) in zip(range(epoch * epoch_size, (epoch + 1) * epoch_size), data_loader): + if iteration in cfg['lr_steps']: + step_index += 1 + adjust_learning_rate(optimizer, args.gamma, step_index) + + if args.cuda: + images = images.cuda() + targets = [ann.cuda() for ann in targets] + elif args.npu: + images = images.to(CALCULATE_DEVICE) + targets = [ann.to(CALCULATE_DEVICE) for ann in targets] + else: + images = images + targets = [ann for ann in targets] + t0 = time.time() + out = net(images) + optimizer.zero_grad() + arm_loss_l, arm_loss_c = arm_criterion(out, targets) + odm_loss_l, odm_loss_c = odm_criterion(out, targets) + arm_loss = arm_loss_l + arm_loss_c + odm_loss = odm_loss_l + odm_loss_c + loss = arm_loss + odm_loss + if args.amp: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + t1 = time.time() + arm_loc_loss += arm_loss_l.item() + arm_conf_loss += arm_loss_c.item() + odm_loc_loss += odm_loss_l.item() + odm_conf_loss += odm_loss_c.item() + avg_time.update(t1 - t0) + if iteration % 10 == 0: + print('iter ' + repr( \ + iteration) + ' || ARM_L Loss: %.4f ARM_C Loss: %.4f ODM_L Loss: %.4f ODM_C Loss: %.4f ||' \ + % (arm_loss_l.item(), arm_loss_c.item(), odm_loss_l.item(), odm_loss_c.item()), end=' ') + print('timer: %.4f sec.' % (t1 - t0)) + + print('batch_size = ' + str(args.batch_size) + ' || num_devices = ' + '1' + ' || time_avg = %.4f' % avg_time.avg) + print('FPS = %.4f' % (args.batch_size / avg_time.avg)) + print('Saving state, iter:' + str(epoch_size * (epoch + 1) - 1) + ' , epoch:' + str(epoch)) + save_path = args.save_folder + '/RefineDet{}_{}_{}.pth'.format(args.input_size, args.dataset, epoch) + torch.save(refinedet_net.state_dict(), save_path) + +def adjust_learning_rate(optimizer, gamma, step): + """Sets the learning rate to the initial LR decayed by 10 at every + specified step + # Adapted from PyTorch Imagenet example: + # https://github.com/pytorch/examples/blob/master/imagenet/main.py + """ + lr = args.lr * (gamma ** (step)) + for param_group in optimizer.param_groups: + param_group['lr'] = lr + +def xavier(param): + init.xavier_uniform_(param) + +def weights_init(m): + if isinstance(m, nn.Conv2d): + with torch.no_grad(): + init.xavier_uniform_(m.weight) + with torch.no_grad(): + m.bias.zero_() + elif isinstance(m, nn.ConvTranspose2d): + xavier(m.weight.data) + with torch.no_grad(): + m.bias.zero_() +if __name__ == '__main__': + train() + + diff --git a/PyTorch/contrib/cv/detection/RefineDet/train_8p.py b/PyTorch/contrib/cv/detection/RefineDet/train_8p.py index b18c84cf9bc47160ad7069bd6ac875535d2c2466..94aeb972652ab46e0ed3f3a2df17c2b3f05292ac 100644 --- a/PyTorch/contrib/cv/detection/RefineDet/train_8p.py +++ b/PyTorch/contrib/cv/detection/RefineDet/train_8p.py @@ -1,294 +1,294 @@ -#!/bin/bash -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# coding=utf-8 -import torchvision -from models.timeAcc import AverageMeter -from data import VOC_CLASSES as labelmap -from data import VOCAnnotationTransform, VOCDetection, BaseTransform -from data import * -from utils.augmentations import SSDAugmentation -from layers.modules import RefineDetMultiBoxLoss -from models.refinedet import build_refinedet -from apex import amp -import apex -from torch.hub import load_state_dict_from_url -import os -import sys -import time -import torch -import torch.nn as nn -import torch.optim as optim -import torch.backends.cudnn as cudnn -import torch.nn.init as init -import torch.utils.data as data -import numpy as np -import argparse -from utils.logging import Logger -import torch.npu -import torch.distributed as dist -import torch.multiprocessing as mp -CALCULATE_DEVICE = "npu" -def str2bool(v): - return v.lower() in ("yes", "true", "t", "1") -if sys.version_info[0] == 2: - import xml.etree.cElementTree as ET -else: - import xml.etree.ElementTree as ET -parser = argparse.ArgumentParser( - description='Single Shot MultiBox Detector Training With Pytorch') -train_set = parser.add_mutually_exclusive_group() -parser.add_argument('--dataset', default='VOC', choices=['VOC', 'COCO'], - type=str, help='VOC or COCO') -parser.add_argument('--input_size', default='320', choices=['320', '512'], - type=str, help='RefineDet320 or RefineDet512') -parser.add_argument('--data_path', default='./data/VOCdevkit', - help='Dataset root directory path') -parser.add_argument('--dataset_root', default='./data/VOCdevkit', - help='Dataset root directory path') -parser.add_argument('--basenet', default='weights/vgg16_reducedfc.pth', - help='Pretrained base model') -parser.add_argument('--batch_size', default=32, type=int, - help='Batch size for training') -parser.add_argument('--resume', default=None, type=str, - help='Checkpoint state_dict file to resume training from') -parser.add_argument('--start_epoch', default=0, type=int, - help='Resume training at this epoch') -parser.add_argument('--num_epochs', default=232, type=int, - help='Total train epoch') -parser.add_argument('--num_workers', default=8, type=int, - help='Number of workers used in dataloading') -parser.add_argument('--cuda', default=False, type=str2bool, - help='Use CUDA to train model') -parser.add_argument('--npu', default=True, type=str2bool, - help='Use NPU to train model') -parser.add_argument('--lr', '--learning-rate', default=0.00095, type=float, - help='initial learning rate') -parser.add_argument('--momentum', default=0.9, type=float, - help='Momentum value for optim') -parser.add_argument('--weight_decay', default=5e-4, type=float, - help='Weight decay for SGD') -parser.add_argument('--gamma', default=0.1, type=float, - help='Gamma update for SGD') -parser.add_argument('--visdom', default=False, type=str2bool, - help='Use visdom for loss visualization') -parser.add_argument('--save_folder', default='weights/', - help='Directory for saving checkpoint models') -parser.add_argument('--local_rank', default=0, type=int, - help='node rank for distributed training') -parser.add_argument('--world_size', default=8, type=int) -parser.add_argument('--bn', default=False, type=str2bool, - help='whether to use BN') -parser.add_argument('--amp', default=True, type=str2bool, - help='whether to use amp') -args = parser.parse_args() - -if torch.cuda.is_available(): - if args.cuda: - torch.set_default_tensor_type('torch.cuda.FloatTensor') - if not args.cuda: - print("WARNING: It looks like you have a CUDA device, but aren't " + - "using CUDA.\nRun with --cuda for optimal training speed.") - torch.set_default_tensor_type('torch.FloatTensor') -else: - torch.set_default_tensor_type('torch.FloatTensor') - -if args.local_rank == 0 and os.path.exists(args.save_folder)==False: - os.mkdir(args.save_folder) - -sys.stdout = Logger(os.path.join(args.save_folder, 'log.txt')) - - - -def init_dist(backend='hccl', **kwargs): - os.environ['MASTER_ADDR'] = "127.0.0.1" - os.environ['MASTER_PORT'] = '29530' - rank = int(args.local_rank) - num_npus = torch.npu.device_count() - dist.init_process_group(backend=backend, world_size=args.world_size, rank=rank) - print(args.world_size, rank) - torch.npu.set_device(rank % num_npus) - torch.backends.cudnn.benchmark = True - args.lr = args.lr * 8 - print('lr = ', args.lr) - -def train(): - import warnings - warnings.filterwarnings('ignore', category=Warning) - init_dist() - if args.dataset == 'VOC': - '''if args.dataset_root == COCO_ROOT: - parser.error('Must specify dataset if specifying dataset_root')''' - cfg = voc_refinedet[args.input_size] - dataset = VOCDetection(root=args.dataset_root, - transform=SSDAugmentation(cfg['min_dim'], - MEANS)) - refinedet_net = build_refinedet('train', cfg['min_dim'], cfg['num_classes'], batch_norm=args.bn) - net = refinedet_net - if args.npu: - net = net.npu() - optimizer = apex.optimizers.NpuFusedSGD(net.parameters(), lr=args.lr, momentum=args.momentum, - weight_decay=args.weight_decay) - arm_criterion = RefineDetMultiBoxLoss(2, 0.5, True, 0, True, 3, 0.5, - False, args.cuda, npu_device=CALCULATE_DEVICE) - odm_criterion = RefineDetMultiBoxLoss(cfg['num_classes'], 0.5, True, 0, True, 3, 0.5, - False, args.cuda, use_ARM=True, npu_device=CALCULATE_DEVICE) - if args.amp: - net, optimizer = amp.initialize(net, optimizer, opt_level='O1', loss_scale=128, combine_grad=True) - if torch.npu.device_count() > 1: - print('ddp') - net = nn.parallel.DistributedDataParallel(net, device_ids=[args.local_rank], broadcast_buffers=False) - if args.resume: - print('Resuming training, loading {}...'.format(args.resume)) - refinedet_net.load_weights(args.resume) - else: - print('Loading vgg...') - vgg_weights = load_state_dict_from_url('https://download.pytorch.org/models/vgg16_bn-6c64b313.pth', - progress=True) - from collections import OrderedDict - new_vgg_weights = OrderedDict() - for k, v in vgg_weights.items(): - fc, num, wb = k.split('.') - if fc == 'classifier': - continue - new_k = num + '.' + wb - new_vgg_weights[new_k] = v - refinedet_net.vgg.load_state_dict(new_vgg_weights, strict=False) - if not args.resume: - print('Initializing weights...') - refinedet_net.extras.apply(weights_init) - refinedet_net.arm_loc.apply(weights_init) - refinedet_net.arm_conf.apply(weights_init) - refinedet_net.odm_loc.apply(weights_init) - refinedet_net.odm_conf.apply(weights_init) - refinedet_net.tcb0.apply(weights_init) - refinedet_net.tcb1.apply(weights_init) - refinedet_net.tcb2.apply(weights_init) - - net.train() - arm_loc_loss = 0 - arm_conf_loss = 0 - odm_loc_loss = 0 - odm_conf_loss = 0 - epoch_size = len(dataset) // args.batch_size // args.world_size - if args.local_rank == 0: - print('Training RefineDet on:', dataset.name) - print('Using the specified args:') - print(args) - step_index = 0 - train_sampler = torch.utils.data.DistributedSampler(dataset) - data_loader = data.DataLoader(dataset=dataset, - batch_size=args.batch_size, - shuffle=False, - num_workers=args.num_workers, - pin_memory=False, - sampler=train_sampler, - collate_fn=detection_collate, - drop_last=True) - iteration = 0 - if args.resume: - iteration = args.start_epoch * epoch_size - for epoch_step in cfg['lr_step_epoch']: - if args.start_epoch > epoch_step: - step_index += 1 - adjust_learning_rate(optimizer, args.gamma, step_index) - for epoch in range(args.start_epoch, args.num_epochs): - train_sampler.set_epoch(epoch) - if epoch in cfg['lr_step_epoch']: - step_index += 1 - adjust_learning_rate(optimizer, args.gamma, step_index) - avg_time = AverageMeter('iter_time') - if args.local_rank == 0: - print('\n' + 'epoch ' + str(epoch)) - print('================================train model on trainval set================================') - for images, targets in data_loader: - if args.cuda: - images = images.cuda() - targets = [ann.cuda() for ann in targets] - elif args.npu: - images = images.to(CALCULATE_DEVICE) - targets = [ann.to(CALCULATE_DEVICE) for ann in targets] - else: - images = images - targets = [ann for ann in targets] - - t0 = time.time() - out = net(images) - optimizer.zero_grad() - arm_loss_l, arm_loss_c = arm_criterion(out, targets) - odm_loss_l, odm_loss_c = odm_criterion(out, targets) - arm_loss = arm_loss_l + arm_loss_c - odm_loss = odm_loss_l + odm_loss_c - loss = arm_loss + odm_loss - if args.amp: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - t1 = time.time() - arm_loc_loss += arm_loss_l.item() - arm_conf_loss += arm_loss_c.item() - odm_loc_loss += odm_loss_l.item() - odm_conf_loss += odm_loss_c.item() - avg_time.update(t1 - t0) - if iteration % 10 == 0 and args.local_rank == 0: - print('iter ' + repr( - iteration) + ' || ARM_L Loss: %.4f ARM_C Loss: %.4f ODM_L Loss: %.4f ODM_C Loss: %.4f ||'\ - % (arm_loss_l.item(), arm_loss_c.item(), odm_loss_l.item(), odm_loss_c.item()), end=' ') - print('timer: %.4f sec.' % (t1 - t0)) - iteration += 1 - if args.local_rank == 0: - print('batch_size = ' + str(args.batch_size) + ' || num_devices = ' + str( - torch.npu.device_count()) + ' || time_avg = %.4f' % avg_time.avg) - print('FPS = %.4f' % (args.batch_size * torch.npu.device_count() / avg_time.avg)) - print('Saving state, iter:' + str(iteration) + ' , epoch:' + str(epoch)) - save_path = args.save_folder + '/RefineDet{}_{}_{}.pth'.format(args.input_size, args.dataset, epoch) - torch.save(refinedet_net.state_dict(), save_path) - - -def adjust_learning_rate(optimizer, gamma, step): - """Sets the learning rate to the initial LR decayed by 10 at every - specified step - # Adapted from PyTorch Imagenet example: - # https://github.com/pytorch/examples/blob/master/imagenet/main.py - """ - lr = args.lr * (gamma ** (step)) - for param_group in optimizer.param_groups: - param_group['lr'] = lr - - -def xavier(param): - init.xavier_uniform_(param) - - -def weights_init(m): - if isinstance(m, nn.Conv2d): - with torch.no_grad(): - init.xavier_uniform_(m.weight) - with torch.no_grad(): - m.bias.zero_() - - - elif isinstance(m, nn.ConvTranspose2d): - xavier(m.weight.data) - with torch.no_grad(): - m.bias.zero_() - -if __name__ == '__main__': - - train() - - +#!/bin/bash +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# coding=utf-8 +import torchvision +from models.timeAcc import AverageMeter +from data import VOC_CLASSES as labelmap +from data import VOCAnnotationTransform, VOCDetection, BaseTransform +from data import * +from utils.augmentations import SSDAugmentation +from layers.modules import RefineDetMultiBoxLoss +from models.refinedet import build_refinedet +from apex import amp +import apex +from torch.hub import load_state_dict_from_url +import os +import sys +import time +import torch +import torch.nn as nn +import torch.optim as optim +import torch.backends.cudnn as cudnn +import torch.nn.init as init +import torch.utils.data as data +import numpy as np +import argparse +from utils.logging import Logger +import torch.npu +import torch.distributed as dist +import torch.multiprocessing as mp +CALCULATE_DEVICE = "npu" +def str2bool(v): + return v.lower() in ("yes", "true", "t", "1") +if sys.version_info[0] == 2: + import xml.etree.cElementTree as ET +else: + import xml.etree.ElementTree as ET +parser = argparse.ArgumentParser( + description='Single Shot MultiBox Detector Training With Pytorch') +train_set = parser.add_mutually_exclusive_group() +parser.add_argument('--dataset', default='VOC', choices=['VOC', 'COCO'], + type=str, help='VOC or COCO') +parser.add_argument('--input_size', default='320', choices=['320', '512'], + type=str, help='RefineDet320 or RefineDet512') +parser.add_argument('--data_path', default='./data/VOCdevkit', + help='Dataset root directory path') +parser.add_argument('--dataset_root', default='./data/VOCdevkit', + help='Dataset root directory path') +parser.add_argument('--basenet', default='weights/vgg16_reducedfc.pth', + help='Pretrained base model') +parser.add_argument('--batch_size', default=32, type=int, + help='Batch size for training') +parser.add_argument('--resume', default=None, type=str, + help='Checkpoint state_dict file to resume training from') +parser.add_argument('--start_epoch', default=0, type=int, + help='Resume training at this epoch') +parser.add_argument('--num_epochs', default=232, type=int, + help='Total train epoch') +parser.add_argument('--num_workers', default=8, type=int, + help='Number of workers used in dataloading') +parser.add_argument('--cuda', default=False, type=str2bool, + help='Use CUDA to train model') +parser.add_argument('--npu', default=True, type=str2bool, + help='Use NPU to train model') +parser.add_argument('--lr', '--learning-rate', default=0.00095, type=float, + help='initial learning rate') +parser.add_argument('--momentum', default=0.9, type=float, + help='Momentum value for optim') +parser.add_argument('--weight_decay', default=5e-4, type=float, + help='Weight decay for SGD') +parser.add_argument('--gamma', default=0.1, type=float, + help='Gamma update for SGD') +parser.add_argument('--visdom', default=False, type=str2bool, + help='Use visdom for loss visualization') +parser.add_argument('--save_folder', default='weights/', + help='Directory for saving checkpoint models') +parser.add_argument('--local_rank', default=0, type=int, + help='node rank for distributed training') +parser.add_argument('--world_size', default=8, type=int) +parser.add_argument('--bn', default=False, type=str2bool, + help='whether to use BN') +parser.add_argument('--amp', default=True, type=str2bool, + help='whether to use amp') +args = parser.parse_args() + +if torch.cuda.is_available(): + if args.cuda: + torch.set_default_tensor_type('torch.cuda.FloatTensor') + if not args.cuda: + print("WARNING: It looks like you have a CUDA device, but aren't " + + "using CUDA.\nRun with --cuda for optimal training speed.") + torch.set_default_tensor_type('torch.FloatTensor') +else: + torch.set_default_tensor_type('torch.FloatTensor') + +if args.local_rank == 0 and os.path.exists(args.save_folder)==False: + os.mkdir(args.save_folder) + +sys.stdout = Logger(os.path.join(args.save_folder, 'log.txt')) + + + +def init_dist(backend='hccl', **kwargs): + os.environ['MASTER_ADDR'] = "127.0.0.1" + os.environ['MASTER_PORT'] = '29530' + rank = int(args.local_rank) + num_npus = torch.npu.device_count() + dist.init_process_group(backend=backend, world_size=args.world_size, rank=rank) + print(args.world_size, rank) + torch.npu.set_device(rank % num_npus) + torch.backends.cudnn.benchmark = True + args.lr = args.lr * 8 + print('lr = ', args.lr) + +def train(): + import warnings + warnings.filterwarnings('ignore', category=Warning) + init_dist() + if args.dataset == 'VOC': + '''if args.dataset_root == COCO_ROOT: + parser.error('Must specify dataset if specifying dataset_root')''' + cfg = voc_refinedet[args.input_size] + dataset = VOCDetection(root=args.dataset_root, + transform=SSDAugmentation(cfg['min_dim'], + MEANS)) + refinedet_net = build_refinedet('train', cfg['min_dim'], cfg['num_classes'], batch_norm=args.bn) + net = refinedet_net + if args.npu: + net = net.npu() + optimizer = apex.optimizers.NpuFusedSGD(net.parameters(), lr=args.lr, momentum=args.momentum, + weight_decay=args.weight_decay) + arm_criterion = RefineDetMultiBoxLoss(2, 0.5, True, 0, True, 3, 0.5, + False, args.cuda, npu_device=CALCULATE_DEVICE) + odm_criterion = RefineDetMultiBoxLoss(cfg['num_classes'], 0.5, True, 0, True, 3, 0.5, + False, args.cuda, use_ARM=True, npu_device=CALCULATE_DEVICE) + if args.amp: + net, optimizer = amp.initialize(net, optimizer, opt_level='O1', loss_scale=128, combine_grad=True) + if torch.npu.device_count() > 1: + print('ddp') + net = nn.parallel.DistributedDataParallel(net, device_ids=[args.local_rank], broadcast_buffers=False) + if args.resume: + print('Resuming training, loading {}...'.format(args.resume)) + refinedet_net.load_weights(args.resume) + else: + print('Loading vgg...') + vgg_weights = load_state_dict_from_url('https://download.pytorch.org/models/vgg16_bn-6c64b313.pth', + progress=True) + from collections import OrderedDict + new_vgg_weights = OrderedDict() + for k, v in vgg_weights.items(): + fc, num, wb = k.split('.') + if fc == 'classifier': + continue + new_k = num + '.' + wb + new_vgg_weights[new_k] = v + refinedet_net.vgg.load_state_dict(new_vgg_weights, strict=False) + if not args.resume: + print('Initializing weights...') + refinedet_net.extras.apply(weights_init) + refinedet_net.arm_loc.apply(weights_init) + refinedet_net.arm_conf.apply(weights_init) + refinedet_net.odm_loc.apply(weights_init) + refinedet_net.odm_conf.apply(weights_init) + refinedet_net.tcb0.apply(weights_init) + refinedet_net.tcb1.apply(weights_init) + refinedet_net.tcb2.apply(weights_init) + + net.train() + arm_loc_loss = 0 + arm_conf_loss = 0 + odm_loc_loss = 0 + odm_conf_loss = 0 + epoch_size = len(dataset) // args.batch_size // args.world_size + if args.local_rank == 0: + print('Training RefineDet on:', dataset.name) + print('Using the specified args:') + print(args) + step_index = 0 + train_sampler = torch.utils.data.DistributedSampler(dataset) + data_loader = data.DataLoader(dataset=dataset, + batch_size=args.batch_size, + shuffle=False, + num_workers=args.num_workers, + pin_memory=False, + sampler=train_sampler, + collate_fn=detection_collate, + drop_last=True) + iteration = 0 + if args.resume: + iteration = args.start_epoch * epoch_size + for epoch_step in cfg['lr_step_epoch']: + if args.start_epoch > epoch_step: + step_index += 1 + adjust_learning_rate(optimizer, args.gamma, step_index) + for epoch in range(args.start_epoch, args.num_epochs): + train_sampler.set_epoch(epoch) + if epoch in cfg['lr_step_epoch']: + step_index += 1 + adjust_learning_rate(optimizer, args.gamma, step_index) + avg_time = AverageMeter('iter_time') + if args.local_rank == 0: + print('\n' + 'epoch ' + str(epoch)) + print('================================train model on trainval set================================') + for images, targets in data_loader: + if args.cuda: + images = images.cuda() + targets = [ann.cuda() for ann in targets] + elif args.npu: + images = images.to(CALCULATE_DEVICE) + targets = [ann.to(CALCULATE_DEVICE) for ann in targets] + else: + images = images + targets = [ann for ann in targets] + + t0 = time.time() + out = net(images) + optimizer.zero_grad() + arm_loss_l, arm_loss_c = arm_criterion(out, targets) + odm_loss_l, odm_loss_c = odm_criterion(out, targets) + arm_loss = arm_loss_l + arm_loss_c + odm_loss = odm_loss_l + odm_loss_c + loss = arm_loss + odm_loss + if args.amp: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + t1 = time.time() + arm_loc_loss += arm_loss_l.item() + arm_conf_loss += arm_loss_c.item() + odm_loc_loss += odm_loss_l.item() + odm_conf_loss += odm_loss_c.item() + avg_time.update(t1 - t0) + if iteration % 10 == 0 and args.local_rank == 0: + print('iter ' + repr( + iteration) + ' || ARM_L Loss: %.4f ARM_C Loss: %.4f ODM_L Loss: %.4f ODM_C Loss: %.4f ||'\ + % (arm_loss_l.item(), arm_loss_c.item(), odm_loss_l.item(), odm_loss_c.item()), end=' ') + print('timer: %.4f sec.' % (t1 - t0)) + iteration += 1 + if args.local_rank == 0: + print('batch_size = ' + str(args.batch_size) + ' || num_devices = ' + str( + torch.npu.device_count()) + ' || time_avg = %.4f' % avg_time.avg) + print('FPS = %.4f' % (args.batch_size * torch.npu.device_count() / avg_time.avg)) + print('Saving state, iter:' + str(iteration) + ' , epoch:' + str(epoch)) + save_path = args.save_folder + '/RefineDet{}_{}_{}.pth'.format(args.input_size, args.dataset, epoch) + torch.save(refinedet_net.state_dict(), save_path) + + +def adjust_learning_rate(optimizer, gamma, step): + """Sets the learning rate to the initial LR decayed by 10 at every + specified step + # Adapted from PyTorch Imagenet example: + # https://github.com/pytorch/examples/blob/master/imagenet/main.py + """ + lr = args.lr * (gamma ** (step)) + for param_group in optimizer.param_groups: + param_group['lr'] = lr + + +def xavier(param): + init.xavier_uniform_(param) + + +def weights_init(m): + if isinstance(m, nn.Conv2d): + with torch.no_grad(): + init.xavier_uniform_(m.weight) + with torch.no_grad(): + m.bias.zero_() + + + elif isinstance(m, nn.ConvTranspose2d): + xavier(m.weight.data) + with torch.no_grad(): + m.bias.zero_() + +if __name__ == '__main__': + + train() + + diff --git a/PyTorch/contrib/cv/detection/RefineDet/utils/augmentations.py b/PyTorch/contrib/cv/detection/RefineDet/utils/augmentations.py index d84874a8638b440184f53a2a4555b9d2a1949b51..dfbb0e36d400001e174a40a3bd6115d1ed39b7e9 100644 --- a/PyTorch/contrib/cv/detection/RefineDet/utils/augmentations.py +++ b/PyTorch/contrib/cv/detection/RefineDet/utils/augmentations.py @@ -1,433 +1,433 @@ -#!/bin/bash -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -from torchvision import transforms -import cv2 -import numpy as np -import types -from numpy import random -np.warnings.filterwarnings('ignore', category=np.VisibleDeprecationWarning) - - -def intersect(box_a, box_b): - max_xy = np.minimum(box_a[:, 2:], box_b[2:]) - min_xy = np.maximum(box_a[:, :2], box_b[:2]) - inter = np.clip((max_xy - min_xy), a_min=0, a_max=np.inf) - return inter[:, 0] * inter[:, 1] - - -def jaccard_numpy(box_a, box_b): - """Compute the jaccard overlap of two sets of boxes. The jaccard overlap - is simply the intersection over union of two boxes. - E.g.: - A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) - Args: - box_a: Multiple bounding boxes, Shape: [num_boxes,4] - box_b: Single bounding box, Shape: [4] - Return: - jaccard overlap: Shape: [box_a.shape[0], box_a.shape[1]] - """ - inter = intersect(box_a, box_b) - area_a = ((box_a[:, 2]-box_a[:, 0]) * - (box_a[:, 3]-box_a[:, 1])) # [A,B] - area_b = ((box_b[2]-box_b[0]) * - (box_b[3]-box_b[1])) # [A,B] - union = area_a + area_b - inter - return inter / union # [A,B] - - -class Compose(object): - """Composes several augmentations together. - Args: - transforms (List[Transform]): list of transforms to compose. - Example: - >>> augmentations.Compose([ - >>> transforms.CenterCrop(10), - >>> transforms.ToTensor(), - >>> ]) - """ - - def __init__(self, transforms): - self.transforms = transforms - - def __call__(self, img, boxes=None, labels=None): - for t in self.transforms: - img, boxes, labels = t(img, boxes, labels) - return img, boxes, labels - - -class Lambda(object): - """Applies a lambda as a transform.""" - - def __init__(self, lambd): - assert isinstance(lambd, types.LambdaType) - self.lambd = lambd - - def __call__(self, img, boxes=None, labels=None): - return self.lambd(img, boxes, labels) - - -class ConvertFromInts(object): - def __call__(self, image, boxes=None, labels=None): - return image.astype(np.float32), boxes, labels - - -class SubtractMeans(object): - def __init__(self, mean): - self.mean = np.array(mean, dtype=np.float32) - - def __call__(self, image, boxes=None, labels=None): - image = image.astype(np.float32) - image -= self.mean - return image.astype(np.float32), boxes, labels - - -class ToAbsoluteCoords(object): - def __call__(self, image, boxes=None, labels=None): - height, width, channels = image.shape - boxes[:, 0] *= width - boxes[:, 2] *= width - boxes[:, 1] *= height - boxes[:, 3] *= height - - return image, boxes, labels - - -class ToPercentCoords(object): - def __call__(self, image, boxes=None, labels=None): - height, width, channels = image.shape - boxes[:, 0] /= width - boxes[:, 2] /= width - boxes[:, 1] /= height - boxes[:, 3] /= height - - return image, boxes, labels - - -class Resize(object): - def __init__(self, size=300): - self.size = size - - def __call__(self, image, boxes=None, labels=None): - image = cv2.resize(image, (self.size, - self.size)) - return image, boxes, labels - - -class RandomSaturation(object): - def __init__(self, lower=0.5, upper=1.5): - self.lower = lower - self.upper = upper - assert self.upper >= self.lower, "contrast upper must be >= lower." - assert self.lower >= 0, "contrast lower must be non-negative." - - def __call__(self, image, boxes=None, labels=None): - if random.randint(2): - image[:, :, 1] *= random.uniform(self.lower, self.upper) - - return image, boxes, labels - - -class RandomHue(object): - def __init__(self, delta=18.0): - assert delta >= 0.0 and delta <= 360.0 - self.delta = delta - - def __call__(self, image, boxes=None, labels=None): - if random.randint(2): - image[:, :, 0] += random.uniform(-self.delta, self.delta) - image[:, :, 0][image[:, :, 0] > 360.0] -= 360.0 - image[:, :, 0][image[:, :, 0] < 0.0] += 360.0 - return image, boxes, labels - - -class RandomLightingNoise(object): - def __init__(self): - self.perms = ((0, 1, 2), (0, 2, 1), - (1, 0, 2), (1, 2, 0), - (2, 0, 1), (2, 1, 0)) - - def __call__(self, image, boxes=None, labels=None): - if random.randint(2): - swap = self.perms[random.randint(len(self.perms))] - shuffle = SwapChannels(swap) # shuffle channels - image = shuffle(image) - return image, boxes, labels - - -class ConvertColor(object): - def __init__(self, current='BGR', transform='HSV'): - self.transform = transform - self.current = current - - def __call__(self, image, boxes=None, labels=None): - if self.current == 'BGR' and self.transform == 'HSV': - image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) - elif self.current == 'HSV' and self.transform == 'BGR': - image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR) - else: - raise NotImplementedError - return image, boxes, labels - - -class RandomContrast(object): - def __init__(self, lower=0.5, upper=1.5): - self.lower = lower - self.upper = upper - assert self.upper >= self.lower, "contrast upper must be >= lower." - assert self.lower >= 0, "contrast lower must be non-negative." - - # expects float image - def __call__(self, image, boxes=None, labels=None): - if random.randint(2): - alpha = random.uniform(self.lower, self.upper) - image *= alpha - return image, boxes, labels - - -class RandomBrightness(object): - def __init__(self, delta=32): - assert delta >= 0.0 - assert delta <= 255.0 - self.delta = delta - - def __call__(self, image, boxes=None, labels=None): - if random.randint(2): - delta = random.uniform(-self.delta, self.delta) - image += delta - return image, boxes, labels - - -class ToCV2Image(object): - def __call__(self, tensor, boxes=None, labels=None): - return tensor.cpu().numpy().astype(np.float32).transpose((1, 2, 0)), boxes, labels - - -class ToTensor(object): - def __call__(self, cvimage, boxes=None, labels=None): - return torch.from_numpy(cvimage.astype(np.float32)).permute(2, 0, 1), boxes, labels - - -class RandomSampleCrop(object): - """Crop - Arguments: - img (Image): the image being input during training - boxes (Tensor): the original bounding boxes in pt form - labels (Tensor): the class labels for each bbox - mode (float tuple): the min and max jaccard overlaps - Return: - (img, boxes, classes) - img (Image): the cropped image - boxes (Tensor): the adjusted bounding boxes in pt form - labels (Tensor): the class labels for each bbox - """ - def __init__(self): - self.sample_options = ( - # using entire original input image - None, - # sample a patch s.t. MIN jaccard w/ obj in .1,.3,.4,.7,.9 - (0.1, None), - (0.3, None), - (0.7, None), - (0.9, None), - # randomly sample a patch - (None, None), - ) - - def __call__(self, image, boxes=None, labels=None): - height, width, _ = image.shape - while True: - # randomly choose a mode - mode = random.choice(self.sample_options) - if mode is None: - return image, boxes, labels - - min_iou, max_iou = mode - if min_iou is None: - min_iou = float('-inf') - if max_iou is None: - max_iou = float('inf') - - # max trails (50) - for _ in range(50): - current_image = image - - w = random.uniform(0.3 * width, width) - h = random.uniform(0.3 * height, height) - - # aspect ratio constraint b/t .5 & 2 - if h / w < 0.5 or h / w > 2: - continue - - left = random.uniform(width - w) - top = random.uniform(height - h) - - # convert to integer rect x1,y1,x2,y2 - rect = np.array([int(left), int(top), int(left+w), int(top+h)]) - - # calculate IoU (jaccard overlap) b/t the cropped and gt boxes - overlap = jaccard_numpy(boxes, rect) # boxes tensor x,y的绝对坐标 rect 剪裁的 x,y 坐标 - - # is min and max overlap constraint satisfied? if not try again - if overlap.min() < min_iou and max_iou < overlap.max(): - continue - - # cut the crop from the image - current_image = current_image[rect[1]:rect[3], rect[0]:rect[2], - :] - - # keep overlap with gt box IF center in sampled patch - centers = (boxes[:, :2] + boxes[:, 2:]) / 2.0 - - # mask in all gt boxes that above and to the left of centers - m1 = (rect[0] < centers[:, 0]) * (rect[1] < centers[:, 1]) - - # mask in all gt boxes that under and to the right of centers - m2 = (rect[2] > centers[:, 0]) * (rect[3] > centers[:, 1]) - - # mask in that both m1 and m2 are true - mask = m1 * m2 - - # have any valid boxes? try again if not - if not mask.any(): - continue - - # take only matching gt boxes - current_boxes = boxes[mask, :].copy() - - # take only matching gt labels - current_labels = labels[mask] - - # should we use the box left and top corner or the crop's - current_boxes[:, :2] = np.maximum(current_boxes[:, :2], - rect[:2]) - # adjust to crop (by substracting crop's left,top) - current_boxes[:, :2] -= rect[:2] - - current_boxes[:, 2:] = np.minimum(current_boxes[:, 2:], - rect[2:]) - # adjust to crop (by substracting crop's left,top) - current_boxes[:, 2:] -= rect[:2] - - return current_image, current_boxes, current_labels - - -class Expand(object): - def __init__(self, mean): - self.mean = mean - - def __call__(self, image, boxes, labels): - if random.randint(2): - return image, boxes, labels - - height, width, depth = image.shape - ratio = random.uniform(1, 4) - left = random.uniform(0, width*ratio - width) - top = random.uniform(0, height*ratio - height) - - expand_image = np.zeros( - (int(height*ratio), int(width*ratio), depth), - dtype=image.dtype) - expand_image[:, :, :] = self.mean - expand_image[int(top):int(top + height), - int(left):int(left + width)] = image - image = expand_image - - boxes = boxes.copy() - boxes[:, :2] += (int(left), int(top)) - boxes[:, 2:] += (int(left), int(top)) - - return image, boxes, labels - - -class RandomMirror(object): - def __call__(self, image, boxes, classes): - _, width, _ = image.shape - if random.randint(2): - image = image[:, ::-1] - boxes = boxes.copy() - boxes[:, 0::2] = width - boxes[:, 2::-2] - return image, boxes, classes - - -class SwapChannels(object): - """Transforms a tensorized image by swapping the channels in the order - specified in the swap tuple. - Args: - swaps (int triple): final order of channels - eg: (2, 1, 0) - """ - - def __init__(self, swaps): - self.swaps = swaps - - def __call__(self, image): - """ - Args: - image (Tensor): image tensor to be transformed - Return: - a tensor with channels swapped according to swap - """ - # if torch.is_tensor(image): - # image = image.data.cpu().numpy() - # else: - # image = np.array(image) - image = image[:, :, self.swaps] - return image - - -class PhotometricDistort(object): - def __init__(self): - self.pd = [ - RandomContrast(), - ConvertColor(transform='HSV'), - RandomSaturation(), - RandomHue(), - ConvertColor(current='HSV', transform='BGR'), - RandomContrast() - ] - self.rand_brightness = RandomBrightness() - self.rand_light_noise = RandomLightingNoise() - - def __call__(self, image, boxes, labels): - im = image.copy() - im, boxes, labels = self.rand_brightness(im, boxes, labels) - if random.randint(2): - distort = Compose(self.pd[:-1]) - else: - distort = Compose(self.pd[1:]) - im, boxes, labels = distort(im, boxes, labels) - return self.rand_light_noise(im, boxes, labels) - - -class SSDAugmentation(object): - def __init__(self, size=300, mean=(104, 117, 123)): - self.mean = mean - self.size = size - self.augment = Compose([ - ConvertFromInts(), # int 转化为 float32 - ToAbsoluteCoords(), - PhotometricDistort(), - Expand(self.mean), - RandomSampleCrop(), - RandomMirror(), - ToPercentCoords(), - Resize(self.size), - SubtractMeans(self.mean) - ]) - - def __call__(self, img, boxes, labels): - return self.augment(img, boxes, labels) +#!/bin/bash +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +from torchvision import transforms +import cv2 +import numpy as np +import types +from numpy import random +np.warnings.filterwarnings('ignore', category=np.VisibleDeprecationWarning) + + +def intersect(box_a, box_b): + max_xy = np.minimum(box_a[:, 2:], box_b[2:]) + min_xy = np.maximum(box_a[:, :2], box_b[:2]) + inter = np.clip((max_xy - min_xy), a_min=0, a_max=np.inf) + return inter[:, 0] * inter[:, 1] + + +def jaccard_numpy(box_a, box_b): + """Compute the jaccard overlap of two sets of boxes. The jaccard overlap + is simply the intersection over union of two boxes. + E.g.: + A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) + Args: + box_a: Multiple bounding boxes, Shape: [num_boxes,4] + box_b: Single bounding box, Shape: [4] + Return: + jaccard overlap: Shape: [box_a.shape[0], box_a.shape[1]] + """ + inter = intersect(box_a, box_b) + area_a = ((box_a[:, 2]-box_a[:, 0]) * + (box_a[:, 3]-box_a[:, 1])) # [A,B] + area_b = ((box_b[2]-box_b[0]) * + (box_b[3]-box_b[1])) # [A,B] + union = area_a + area_b - inter + return inter / union # [A,B] + + +class Compose(object): + """Composes several augmentations together. + Args: + transforms (List[Transform]): list of transforms to compose. + Example: + >>> augmentations.Compose([ + >>> transforms.CenterCrop(10), + >>> transforms.ToTensor(), + >>> ]) + """ + + def __init__(self, transforms): + self.transforms = transforms + + def __call__(self, img, boxes=None, labels=None): + for t in self.transforms: + img, boxes, labels = t(img, boxes, labels) + return img, boxes, labels + + +class Lambda(object): + """Applies a lambda as a transform.""" + + def __init__(self, lambd): + assert isinstance(lambd, types.LambdaType) + self.lambd = lambd + + def __call__(self, img, boxes=None, labels=None): + return self.lambd(img, boxes, labels) + + +class ConvertFromInts(object): + def __call__(self, image, boxes=None, labels=None): + return image.astype(np.float32), boxes, labels + + +class SubtractMeans(object): + def __init__(self, mean): + self.mean = np.array(mean, dtype=np.float32) + + def __call__(self, image, boxes=None, labels=None): + image = image.astype(np.float32) + image -= self.mean + return image.astype(np.float32), boxes, labels + + +class ToAbsoluteCoords(object): + def __call__(self, image, boxes=None, labels=None): + height, width, channels = image.shape + boxes[:, 0] *= width + boxes[:, 2] *= width + boxes[:, 1] *= height + boxes[:, 3] *= height + + return image, boxes, labels + + +class ToPercentCoords(object): + def __call__(self, image, boxes=None, labels=None): + height, width, channels = image.shape + boxes[:, 0] /= width + boxes[:, 2] /= width + boxes[:, 1] /= height + boxes[:, 3] /= height + + return image, boxes, labels + + +class Resize(object): + def __init__(self, size=300): + self.size = size + + def __call__(self, image, boxes=None, labels=None): + image = cv2.resize(image, (self.size, + self.size)) + return image, boxes, labels + + +class RandomSaturation(object): + def __init__(self, lower=0.5, upper=1.5): + self.lower = lower + self.upper = upper + assert self.upper >= self.lower, "contrast upper must be >= lower." + assert self.lower >= 0, "contrast lower must be non-negative." + + def __call__(self, image, boxes=None, labels=None): + if random.randint(2): + image[:, :, 1] *= random.uniform(self.lower, self.upper) + + return image, boxes, labels + + +class RandomHue(object): + def __init__(self, delta=18.0): + assert delta >= 0.0 and delta <= 360.0 + self.delta = delta + + def __call__(self, image, boxes=None, labels=None): + if random.randint(2): + image[:, :, 0] += random.uniform(-self.delta, self.delta) + image[:, :, 0][image[:, :, 0] > 360.0] -= 360.0 + image[:, :, 0][image[:, :, 0] < 0.0] += 360.0 + return image, boxes, labels + + +class RandomLightingNoise(object): + def __init__(self): + self.perms = ((0, 1, 2), (0, 2, 1), + (1, 0, 2), (1, 2, 0), + (2, 0, 1), (2, 1, 0)) + + def __call__(self, image, boxes=None, labels=None): + if random.randint(2): + swap = self.perms[random.randint(len(self.perms))] + shuffle = SwapChannels(swap) # shuffle channels + image = shuffle(image) + return image, boxes, labels + + +class ConvertColor(object): + def __init__(self, current='BGR', transform='HSV'): + self.transform = transform + self.current = current + + def __call__(self, image, boxes=None, labels=None): + if self.current == 'BGR' and self.transform == 'HSV': + image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) + elif self.current == 'HSV' and self.transform == 'BGR': + image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR) + else: + raise NotImplementedError + return image, boxes, labels + + +class RandomContrast(object): + def __init__(self, lower=0.5, upper=1.5): + self.lower = lower + self.upper = upper + assert self.upper >= self.lower, "contrast upper must be >= lower." + assert self.lower >= 0, "contrast lower must be non-negative." + + # expects float image + def __call__(self, image, boxes=None, labels=None): + if random.randint(2): + alpha = random.uniform(self.lower, self.upper) + image *= alpha + return image, boxes, labels + + +class RandomBrightness(object): + def __init__(self, delta=32): + assert delta >= 0.0 + assert delta <= 255.0 + self.delta = delta + + def __call__(self, image, boxes=None, labels=None): + if random.randint(2): + delta = random.uniform(-self.delta, self.delta) + image += delta + return image, boxes, labels + + +class ToCV2Image(object): + def __call__(self, tensor, boxes=None, labels=None): + return tensor.cpu().numpy().astype(np.float32).transpose((1, 2, 0)), boxes, labels + + +class ToTensor(object): + def __call__(self, cvimage, boxes=None, labels=None): + return torch.from_numpy(cvimage.astype(np.float32)).permute(2, 0, 1), boxes, labels + + +class RandomSampleCrop(object): + """Crop + Arguments: + img (Image): the image being input during training + boxes (Tensor): the original bounding boxes in pt form + labels (Tensor): the class labels for each bbox + mode (float tuple): the min and max jaccard overlaps + Return: + (img, boxes, classes) + img (Image): the cropped image + boxes (Tensor): the adjusted bounding boxes in pt form + labels (Tensor): the class labels for each bbox + """ + def __init__(self): + self.sample_options = ( + # using entire original input image + None, + # sample a patch s.t. MIN jaccard w/ obj in .1,.3,.4,.7,.9 + (0.1, None), + (0.3, None), + (0.7, None), + (0.9, None), + # randomly sample a patch + (None, None), + ) + + def __call__(self, image, boxes=None, labels=None): + height, width, _ = image.shape + while True: + # randomly choose a mode + mode = random.choice(self.sample_options) + if mode is None: + return image, boxes, labels + + min_iou, max_iou = mode + if min_iou is None: + min_iou = float('-inf') + if max_iou is None: + max_iou = float('inf') + + # max trails (50) + for _ in range(50): + current_image = image + + w = random.uniform(0.3 * width, width) + h = random.uniform(0.3 * height, height) + + # aspect ratio constraint b/t .5 & 2 + if h / w < 0.5 or h / w > 2: + continue + + left = random.uniform(width - w) + top = random.uniform(height - h) + + # convert to integer rect x1,y1,x2,y2 + rect = np.array([int(left), int(top), int(left+w), int(top+h)]) + + # calculate IoU (jaccard overlap) b/t the cropped and gt boxes + overlap = jaccard_numpy(boxes, rect) # boxes tensor x,y的绝对坐标 rect 剪裁的 x,y 坐标 + + # is min and max overlap constraint satisfied? if not try again + if overlap.min() < min_iou and max_iou < overlap.max(): + continue + + # cut the crop from the image + current_image = current_image[rect[1]:rect[3], rect[0]:rect[2], + :] + + # keep overlap with gt box IF center in sampled patch + centers = (boxes[:, :2] + boxes[:, 2:]) / 2.0 + + # mask in all gt boxes that above and to the left of centers + m1 = (rect[0] < centers[:, 0]) * (rect[1] < centers[:, 1]) + + # mask in all gt boxes that under and to the right of centers + m2 = (rect[2] > centers[:, 0]) * (rect[3] > centers[:, 1]) + + # mask in that both m1 and m2 are true + mask = m1 * m2 + + # have any valid boxes? try again if not + if not mask.any(): + continue + + # take only matching gt boxes + current_boxes = boxes[mask, :].copy() + + # take only matching gt labels + current_labels = labels[mask] + + # should we use the box left and top corner or the crop's + current_boxes[:, :2] = np.maximum(current_boxes[:, :2], + rect[:2]) + # adjust to crop (by substracting crop's left,top) + current_boxes[:, :2] -= rect[:2] + + current_boxes[:, 2:] = np.minimum(current_boxes[:, 2:], + rect[2:]) + # adjust to crop (by substracting crop's left,top) + current_boxes[:, 2:] -= rect[:2] + + return current_image, current_boxes, current_labels + + +class Expand(object): + def __init__(self, mean): + self.mean = mean + + def __call__(self, image, boxes, labels): + if random.randint(2): + return image, boxes, labels + + height, width, depth = image.shape + ratio = random.uniform(1, 4) + left = random.uniform(0, width*ratio - width) + top = random.uniform(0, height*ratio - height) + + expand_image = np.zeros( + (int(height*ratio), int(width*ratio), depth), + dtype=image.dtype) + expand_image[:, :, :] = self.mean + expand_image[int(top):int(top + height), + int(left):int(left + width)] = image + image = expand_image + + boxes = boxes.copy() + boxes[:, :2] += (int(left), int(top)) + boxes[:, 2:] += (int(left), int(top)) + + return image, boxes, labels + + +class RandomMirror(object): + def __call__(self, image, boxes, classes): + _, width, _ = image.shape + if random.randint(2): + image = image[:, ::-1] + boxes = boxes.copy() + boxes[:, 0::2] = width - boxes[:, 2::-2] + return image, boxes, classes + + +class SwapChannels(object): + """Transforms a tensorized image by swapping the channels in the order + specified in the swap tuple. + Args: + swaps (int triple): final order of channels + eg: (2, 1, 0) + """ + + def __init__(self, swaps): + self.swaps = swaps + + def __call__(self, image): + """ + Args: + image (Tensor): image tensor to be transformed + Return: + a tensor with channels swapped according to swap + """ + # if torch.is_tensor(image): + # image = image.data.cpu().numpy() + # else: + # image = np.array(image) + image = image[:, :, self.swaps] + return image + + +class PhotometricDistort(object): + def __init__(self): + self.pd = [ + RandomContrast(), + ConvertColor(transform='HSV'), + RandomSaturation(), + RandomHue(), + ConvertColor(current='HSV', transform='BGR'), + RandomContrast() + ] + self.rand_brightness = RandomBrightness() + self.rand_light_noise = RandomLightingNoise() + + def __call__(self, image, boxes, labels): + im = image.copy() + im, boxes, labels = self.rand_brightness(im, boxes, labels) + if random.randint(2): + distort = Compose(self.pd[:-1]) + else: + distort = Compose(self.pd[1:]) + im, boxes, labels = distort(im, boxes, labels) + return self.rand_light_noise(im, boxes, labels) + + +class SSDAugmentation(object): + def __init__(self, size=300, mean=(104, 117, 123)): + self.mean = mean + self.size = size + self.augment = Compose([ + ConvertFromInts(), # int 转化为 float32 + ToAbsoluteCoords(), + PhotometricDistort(), + Expand(self.mean), + RandomSampleCrop(), + RandomMirror(), + ToPercentCoords(), + Resize(self.size), + SubtractMeans(self.mean) + ]) + + def __call__(self, img, boxes, labels): + return self.augment(img, boxes, labels) diff --git a/PyTorch/contrib/cv/detection/RefineDet/utils/logging.py b/PyTorch/contrib/cv/detection/RefineDet/utils/logging.py index 50e75733a1ba3228c15f1b45bc95212ee28f12c8..838d1cf2605203721904775fc50df9d5e07ad657 100644 --- a/PyTorch/contrib/cv/detection/RefineDet/utils/logging.py +++ b/PyTorch/contrib/cv/detection/RefineDet/utils/logging.py @@ -1,54 +1,54 @@ -#!/bin/bash -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import absolute_import -import os -import sys - -from .osutils import mkdir_if_missing - - -class Logger(object): - def __init__(self, fpath=None): - self.console = sys.stdout - self.file = None - if fpath is not None: - mkdir_if_missing(os.path.dirname(fpath)) - self.file = open(fpath, 'w') - - def __del__(self): - self.close() - - def __enter__(self): - pass - - def __exit__(self, *args): - self.close() - - def write(self, msg): - self.console.write(msg) - if self.file is not None: - self.file.write(msg) - - def flush(self): - self.console.flush() - if self.file is not None: - self.file.flush() - os.fsync(self.file.fileno()) - - def close(self): - self.console.close() - if self.file is not None: - self.file.close() +#!/bin/bash +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import +import os +import sys + +from .osutils import mkdir_if_missing + + +class Logger(object): + def __init__(self, fpath=None): + self.console = sys.stdout + self.file = None + if fpath is not None: + mkdir_if_missing(os.path.dirname(fpath)) + self.file = open(fpath, 'w') + + def __del__(self): + self.close() + + def __enter__(self): + pass + + def __exit__(self, *args): + self.close() + + def write(self, msg): + self.console.write(msg) + if self.file is not None: + self.file.write(msg) + + def flush(self): + self.console.flush() + if self.file is not None: + self.file.flush() + os.fsync(self.file.fileno()) + + def close(self): + self.console.close() + if self.file is not None: + self.file.close() diff --git a/PyTorch/contrib/cv/detection/RefineDet/utils/osutils.py b/PyTorch/contrib/cv/detection/RefineDet/utils/osutils.py index b91a51f7b33df39ccf67b8e5505d795cb71a2295..d1537c4e52ee8fadef5bc05b1f11b2f93be7edc8 100644 --- a/PyTorch/contrib/cv/detection/RefineDet/utils/osutils.py +++ b/PyTorch/contrib/cv/detection/RefineDet/utils/osutils.py @@ -1,26 +1,26 @@ -#!/bin/bash -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import absolute_import -import os -import errno - - -def mkdir_if_missing(dir_path): - try: - os.makedirs(dir_path) - except OSError as e: - if e.errno != errno.EEXIST: - raise +#!/bin/bash +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import +import os +import errno + + +def mkdir_if_missing(dir_path): + try: + os.makedirs(dir_path) + except OSError as e: + if e.errno != errno.EEXIST: + raise diff --git a/PyTorch/contrib/cv/detection/Retinaface/modelzoo_level.txt b/PyTorch/contrib/cv/detection/Retinaface/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/detection/Retinaface/modelzoo_level.txt +++ b/PyTorch/contrib/cv/detection/Retinaface/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/SOLOv1/mmcv/README.rst b/PyTorch/contrib/cv/detection/SOLOv1/mmcv/README.rst deleted file mode 100644 index 663f6677e1a59bb4f39294670c97ac3d760b341c..0000000000000000000000000000000000000000 --- a/PyTorch/contrib/cv/detection/SOLOv1/mmcv/README.rst +++ /dev/null @@ -1,54 +0,0 @@ -MMCV -==== - -.. image:: https://travis-ci.com/open-mmlab/mmcv.svg?branch=master - :target: https://travis-ci.com/open-mmlab/mmcv - -.. image:: https://codecov.io/gh/open-mmlab/mmcv/branch/master/graph/badge.svg - :target: https://codecov.io/gh/open-mmlab/mmcv - -.. image:: https://img.shields.io/github/license/open-mmlab/mmcv.svg - :target: https://github.com/open-mmlab/mmcv/blob/master/LICENSE - - -Introduction ------------- - -MMCV is a foundational python library for computer vision research and supports many -research projects in MMLAB, such as `MMDetection `_ -and `MMAction `_. - -It provides the following functionalities. - -- Universal IO APIs -- Image processing -- Video processing -- Image and annotation visualization -- Useful utilities (progress bar, timer, ...) -- PyTorch runner with hooking mechanism -- Various CNN architectures - -See the `documentation `_ for more features and usage. - - -Installation ------------- - -Try and start with - -.. code:: - - pip install mmcv - - -or install from source - -.. code:: - - git clone https://github.com/open-mmlab/mmcv.git - cd mmcv - pip install -e . - -Note: If you would like to use :code:`opencv-python-headless` instead of :code:`opencv-python`, -e.g., in a minimum container environment or servers without GUI, -you can first install it before installing MMCV to skip the installation of :code:`opencv-python`. \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/SOLOv2/mmcv/README.rst b/PyTorch/contrib/cv/detection/SOLOv2/mmcv/README.rst deleted file mode 100644 index 663f6677e1a59bb4f39294670c97ac3d760b341c..0000000000000000000000000000000000000000 --- a/PyTorch/contrib/cv/detection/SOLOv2/mmcv/README.rst +++ /dev/null @@ -1,54 +0,0 @@ -MMCV -==== - -.. image:: https://travis-ci.com/open-mmlab/mmcv.svg?branch=master - :target: https://travis-ci.com/open-mmlab/mmcv - -.. image:: https://codecov.io/gh/open-mmlab/mmcv/branch/master/graph/badge.svg - :target: https://codecov.io/gh/open-mmlab/mmcv - -.. image:: https://img.shields.io/github/license/open-mmlab/mmcv.svg - :target: https://github.com/open-mmlab/mmcv/blob/master/LICENSE - - -Introduction ------------- - -MMCV is a foundational python library for computer vision research and supports many -research projects in MMLAB, such as `MMDetection `_ -and `MMAction `_. - -It provides the following functionalities. - -- Universal IO APIs -- Image processing -- Video processing -- Image and annotation visualization -- Useful utilities (progress bar, timer, ...) -- PyTorch runner with hooking mechanism -- Various CNN architectures - -See the `documentation `_ for more features and usage. - - -Installation ------------- - -Try and start with - -.. code:: - - pip install mmcv - - -or install from source - -.. code:: - - git clone https://github.com/open-mmlab/mmcv.git - cd mmcv - pip install -e . - -Note: If you would like to use :code:`opencv-python-headless` instead of :code:`opencv-python`, -e.g., in a minimum container environment or servers without GUI, -you can first install it before installing MMCV to skip the installation of :code:`opencv-python`. \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/Dockerfile b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/Dockerfile old mode 100755 new mode 100644 index 7e712fe1a166790798f57a2f2762c47394beb625..30a31af55804dd79571d2a36e6107a844cb7e549 --- a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/Dockerfile +++ b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/Dockerfile @@ -1,5 +1,5 @@ -ARG FROM_IMAGE_NAME -FROM $FROM_IMAGE_NAME - -COPY requirements.txt . +ARG FROM_IMAGE_NAME +FROM $FROM_IMAGE_NAME + +COPY requirements.txt . RUN pip3.7 install -r requirements.txt \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/LICENSE b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/LICENSE old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/README.md b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/README.md old mode 100755 new mode 100644 index 9eeb1a53abc21d0e2307fe830dfc22226893f993..87658addb0a99c52277a41d088d3ea31544322ee --- a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/README.md +++ b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/README.md @@ -1,88 +1,88 @@ -## Requirements -```angular2html -pytorch==1.5 -apex -pandas -opencv-python -``` - -## 下载数据集 -```angular2html -wget http://pjreddie.com/media/files/VOCtrainval_11-May-2012.tar -wget http://pjreddie.com/media/files/VOCtrainval_06-Nov-2007.tar -wget http://pjreddie.com/media/files/VOCtest_06-Nov-2007.tar - -将3个数据集放在目录 VOC0712下,目录结构为: - VOC0712 - | - |———————— VOC2007_trainval - | |——————Annotations - | |——————ImageSets - | |——————JPEGImages - | |——————SegmentationClass - | |——————SegmentationObject - |———————— VOC2012_trainval - | |——————Annotations - | |——————ImageSets - | |——————JPEGImages - | |——————SegmentationClass - | |——————SegmentationObject - |———————— VOC2007_test - |——————Annotations - |——————ImageSets - |——————JPEGImages - |——————SegmentationClass - |——————SegmentationObject -``` -## 下载预训练模型到 models 目录下 -``` -wget -P models https://storage.googleapis.com/models-hao/mb2-imagenet-71_8.pth -``` -## 训练 -```angular2html -# 1p train perf -# 是否正确输出了性能log文件 -bash test/train_performance_1p.sh --data_path xxx - -# 1p train full -# 是否正确输出了性能精度log文件,是否正确保存了模型文件 -bash test/train_full_1p.sh --data_path xxx - -# 8p train perf -# 是否正确输出了性能log文件 -bash test/train_performance_8p.sh --data_path xxx - -# 8p train full -# 是否正确输出了性能精度log文件,是否正确保存了模型文件 -bash test/train_full_8p.sh --data_path xxx - -# finetuning -# 是否正确执行迁移学习 -bash test/train_finetune_1p.sh --data_path xxx - -# online inference demo -# 是否正确输出预测结果,请确保输入固定tensor多次运行的输出结果一致 -python3.7.5 demo.py -``` -### 一些参数说明 -```angular2html ---data_path 数据集路径 ---base_net 预训练模型存放路径 ---num_epochs 训练epoch ---validation_epochs 验证epoch ---checkpoint_folder 模型保存路径 ---eval_dir 模型验证时产生文件的存放路径 ---device 使用的设备,npu或gpu ---gpu 设备卡号,单卡时使用 ---device_list 默认为 '0,1,2,3,4,5,6,7',多卡时使用 -``` -## evaluate -```angular2html -bash scripts/eval.sh -``` -### 一些参数说明 -```angular2html ---dataset 测试数据集 ---eval_dir 模型验证时产生文件的存放路径 ---lable_file 类别文件,训练时会在模型保存文件夹生成 -``` +## Requirements +```angular2html +pytorch==1.5 +apex +pandas +opencv-python +``` + +## 下载数据集 +```angular2html +wget http://pjreddie.com/media/files/VOCtrainval_11-May-2012.tar +wget http://pjreddie.com/media/files/VOCtrainval_06-Nov-2007.tar +wget http://pjreddie.com/media/files/VOCtest_06-Nov-2007.tar + +将3个数据集放在目录 VOC0712下,目录结构为: + VOC0712 + | + |———————— VOC2007_trainval + | |——————Annotations + | |——————ImageSets + | |——————JPEGImages + | |——————SegmentationClass + | |——————SegmentationObject + |———————— VOC2012_trainval + | |——————Annotations + | |——————ImageSets + | |——————JPEGImages + | |——————SegmentationClass + | |——————SegmentationObject + |———————— VOC2007_test + |——————Annotations + |——————ImageSets + |——————JPEGImages + |——————SegmentationClass + |——————SegmentationObject +``` +## 下载预训练模型到 models 目录下 +``` +wget -P models https://storage.googleapis.com/models-hao/mb2-imagenet-71_8.pth +``` +## 训练 +```angular2html +# 1p train perf +# 是否正确输出了性能log文件 +bash test/train_performance_1p.sh --data_path xxx + +# 1p train full +# 是否正确输出了性能精度log文件,是否正确保存了模型文件 +bash test/train_full_1p.sh --data_path xxx + +# 8p train perf +# 是否正确输出了性能log文件 +bash test/train_performance_8p.sh --data_path xxx + +# 8p train full +# 是否正确输出了性能精度log文件,是否正确保存了模型文件 +bash test/train_full_8p.sh --data_path xxx + +# finetuning +# 是否正确执行迁移学习 +bash test/train_finetune_1p.sh --data_path xxx + +# online inference demo +# 是否正确输出预测结果,请确保输入固定tensor多次运行的输出结果一致 +python3.7.5 demo.py +``` +### 一些参数说明 +```angular2html +--data_path 数据集路径 +--base_net 预训练模型存放路径 +--num_epochs 训练epoch +--validation_epochs 验证epoch +--checkpoint_folder 模型保存路径 +--eval_dir 模型验证时产生文件的存放路径 +--device 使用的设备,npu或gpu +--gpu 设备卡号,单卡时使用 +--device_list 默认为 '0,1,2,3,4,5,6,7',多卡时使用 +``` +## evaluate +```angular2html +bash scripts/eval.sh +``` +### 一些参数说明 +```angular2html +--dataset 测试数据集 +--eval_dir 模型验证时产生文件的存放路径 +--lable_file 类别文件,训练时会在模型保存文件夹生成 +``` diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/README_raw.md b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/README_raw.md old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/convert_to_caffe2_models.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/convert_to_caffe2_models.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/demo.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/demo.py old mode 100755 new mode 100644 index 582d0d536e8c28923379491069ac577966fbe7b7..f082419b38eb4792bca698dd9b26303b57699fcf --- a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/demo.py +++ b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/demo.py @@ -1,103 +1,103 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import argparse -import sys -import torch -import cv2 - -from vision.utils.misc import Timer -from vision.ssd.vgg_ssd import create_vgg_ssd, create_vgg_ssd_predictor -from vision.ssd.mobilenetv1_ssd import create_mobilenetv1_ssd, create_mobilenetv1_ssd_predictor -from vision.ssd.mobilenetv1_ssd_lite import create_mobilenetv1_ssd_lite, create_mobilenetv1_ssd_lite_predictor -from vision.ssd.squeezenet_ssd_lite import create_squeezenet_ssd_lite, create_squeezenet_ssd_lite_predictor -from vision.ssd.mobilenet_v2_ssd_lite import create_mobilenetv2_ssd_lite, create_mobilenetv2_ssd_lite_predictor -from vision.ssd.mobilenetv3_ssd_lite import create_mobilenetv3_large_ssd_lite, create_mobilenetv3_small_ssd_lite - -parser = argparse.ArgumentParser() -parser.add_argument('--net', default="mb2-ssd-lite", - help="The network architecture, it should be of mb1-ssd, mb1-ssd-lite, mb2-ssd-lite or vgg16-ssd.") -parser.add_argument("--trained_model", default="models/1p/mb2-ssd-lite-Epoch-0-Loss-12.09216200136671.pth", type=str) -parser.add_argument('--img', default="demo.jpg", help="image file") -parser.add_argument("--label_file", default="models/1p/voc-model-labels.txt", type=str, help="The label file path.") -parser.add_argument('--device', default='npu', type=str, help='npu or gpu') -parser.add_argument('--gpu', default=0, type=int, - help='GPU id to use.') -parser.add_argument("--nms_method", type=str, default="hard") -parser.add_argument('--mb2_width_mult', default=1.0, type=float, - help='Width Multiplifier for MobilenetV2') -timer = Timer() -if __name__ == '__main__': - args = parser.parse_args() - if args.device == 'npu': - args.device = 'npu:{}'.format(args.gpu) - torch.npu.set_device(args.device) - elif args.device == 'gpu': - args.device = 'cuda:{}'.format(args.gpu) - torch.backends.cudnn.benchmark = True - - if args.net == 'vgg16-ssd': - create_net = create_vgg_ssd - create_predictor = lambda net: create_vgg_ssd_predictor(net, nms_method=args.nms_method, device=args.device) - elif args.net == 'mb1-ssd': - create_net = create_mobilenetv1_ssd - create_predictor = lambda net: create_mobilenetv1_ssd_predictor(net, nms_method=args.nms_method, - device=args.device) - elif args.net == 'mb1-ssd-lite': - create_net = create_mobilenetv1_ssd_lite - create_predictor = lambda net: create_mobilenetv1_ssd_lite_predictor(net, nms_method=args.nms_method, - device=args.device) - elif args.net == 'sq-ssd-lite': - create_net = create_squeezenet_ssd_lite - create_predictor = lambda net: create_squeezenet_ssd_lite_predictor(net, nms_method=args.nms_method, - device=args.device) - elif args.net == 'mb2-ssd-lite': - create_net = lambda num: create_mobilenetv2_ssd_lite(num, width_mult=args.mb2_width_mult, device=args.device) - create_predictor = lambda net: create_mobilenetv2_ssd_lite_predictor(net, nms_method=args.nms_method, - device=args.device) - elif args.net == 'mb3-large-ssd-lite': - create_net = lambda num: create_mobilenetv3_large_ssd_lite(num) - create_predictor = lambda net: create_mobilenetv2_ssd_lite_predictor(net, nms_method=args.nms_method, - device=args.device) - elif args.net == 'mb3-small-ssd-lite': - create_net = lambda num: create_mobilenetv3_small_ssd_lite(num) - create_predictor = lambda net: create_mobilenetv2_ssd_lite_predictor(net, nms_method=args.nms_method, - device=args.device) - else: - parser.print_help(sys.stderr) - sys.exit(1) - - # create model - class_names = [name.strip() for name in open(args.label_file).readlines()] - net = create_net(len(class_names)) - timer.start("Load Model") - pretrained_dic = torch.load(args.trained_model, map_location='cpu')['state_dict'] - pretrained_dic = {k.replace('module.', ''): v for k, v in pretrained_dic.items()} - net.load_state_dict(pretrained_dic) - - net = net.to(args.device) - print(f'It took {timer.end("Load Model")} seconds to load the model.') - - # create predictor - predictor = create_predictor(net) - - # load imge - image = cv2.imread(args.img) - image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) - boxes, labels, probs = predictor.predict(image) - print('\n') - print('boxes: ', boxes) - print('lables: ', labels) - print('probs: ', probs) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import argparse +import sys +import torch +import cv2 + +from vision.utils.misc import Timer +from vision.ssd.vgg_ssd import create_vgg_ssd, create_vgg_ssd_predictor +from vision.ssd.mobilenetv1_ssd import create_mobilenetv1_ssd, create_mobilenetv1_ssd_predictor +from vision.ssd.mobilenetv1_ssd_lite import create_mobilenetv1_ssd_lite, create_mobilenetv1_ssd_lite_predictor +from vision.ssd.squeezenet_ssd_lite import create_squeezenet_ssd_lite, create_squeezenet_ssd_lite_predictor +from vision.ssd.mobilenet_v2_ssd_lite import create_mobilenetv2_ssd_lite, create_mobilenetv2_ssd_lite_predictor +from vision.ssd.mobilenetv3_ssd_lite import create_mobilenetv3_large_ssd_lite, create_mobilenetv3_small_ssd_lite + +parser = argparse.ArgumentParser() +parser.add_argument('--net', default="mb2-ssd-lite", + help="The network architecture, it should be of mb1-ssd, mb1-ssd-lite, mb2-ssd-lite or vgg16-ssd.") +parser.add_argument("--trained_model", default="models/1p/mb2-ssd-lite-Epoch-0-Loss-12.09216200136671.pth", type=str) +parser.add_argument('--img', default="demo.jpg", help="image file") +parser.add_argument("--label_file", default="models/1p/voc-model-labels.txt", type=str, help="The label file path.") +parser.add_argument('--device', default='npu', type=str, help='npu or gpu') +parser.add_argument('--gpu', default=0, type=int, + help='GPU id to use.') +parser.add_argument("--nms_method", type=str, default="hard") +parser.add_argument('--mb2_width_mult', default=1.0, type=float, + help='Width Multiplifier for MobilenetV2') +timer = Timer() +if __name__ == '__main__': + args = parser.parse_args() + if args.device == 'npu': + args.device = 'npu:{}'.format(args.gpu) + torch.npu.set_device(args.device) + elif args.device == 'gpu': + args.device = 'cuda:{}'.format(args.gpu) + torch.backends.cudnn.benchmark = True + + if args.net == 'vgg16-ssd': + create_net = create_vgg_ssd + create_predictor = lambda net: create_vgg_ssd_predictor(net, nms_method=args.nms_method, device=args.device) + elif args.net == 'mb1-ssd': + create_net = create_mobilenetv1_ssd + create_predictor = lambda net: create_mobilenetv1_ssd_predictor(net, nms_method=args.nms_method, + device=args.device) + elif args.net == 'mb1-ssd-lite': + create_net = create_mobilenetv1_ssd_lite + create_predictor = lambda net: create_mobilenetv1_ssd_lite_predictor(net, nms_method=args.nms_method, + device=args.device) + elif args.net == 'sq-ssd-lite': + create_net = create_squeezenet_ssd_lite + create_predictor = lambda net: create_squeezenet_ssd_lite_predictor(net, nms_method=args.nms_method, + device=args.device) + elif args.net == 'mb2-ssd-lite': + create_net = lambda num: create_mobilenetv2_ssd_lite(num, width_mult=args.mb2_width_mult, device=args.device) + create_predictor = lambda net: create_mobilenetv2_ssd_lite_predictor(net, nms_method=args.nms_method, + device=args.device) + elif args.net == 'mb3-large-ssd-lite': + create_net = lambda num: create_mobilenetv3_large_ssd_lite(num) + create_predictor = lambda net: create_mobilenetv2_ssd_lite_predictor(net, nms_method=args.nms_method, + device=args.device) + elif args.net == 'mb3-small-ssd-lite': + create_net = lambda num: create_mobilenetv3_small_ssd_lite(num) + create_predictor = lambda net: create_mobilenetv2_ssd_lite_predictor(net, nms_method=args.nms_method, + device=args.device) + else: + parser.print_help(sys.stderr) + sys.exit(1) + + # create model + class_names = [name.strip() for name in open(args.label_file).readlines()] + net = create_net(len(class_names)) + timer.start("Load Model") + pretrained_dic = torch.load(args.trained_model, map_location='cpu')['state_dict'] + pretrained_dic = {k.replace('module.', ''): v for k, v in pretrained_dic.items()} + net.load_state_dict(pretrained_dic) + + net = net.to(args.device) + print(f'It took {timer.end("Load Model")} seconds to load the model.') + + # create predictor + predictor = create_predictor(net) + + # load imge + image = cv2.imread(args.img) + image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) + boxes, labels, probs = predictor.predict(image) + print('\n') + print('boxes: ', boxes) + print('lables: ', labels) + print('probs: ', probs) diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/docker_start.sh b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/docker_start.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/draw_eval_results.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/draw_eval_results.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/eval_ssd.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/eval_ssd.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/extract_tf_weights.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/extract_tf_weights.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/modelzoo_level.txt b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/modelzoo_level.txt old mode 100755 new mode 100644 index 405b26618a0c92027927a9c583a4b47f640bcf7b..c45626e398eabe6022fe7b2e148f0ffce6400d6e --- a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/modelzoo_level.txt +++ b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:POK +FuncStatus:OK +PerfStatus:POK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/open_images_downloader.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/open_images_downloader.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/prune_alexnet.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/prune_alexnet.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/requirements.txt b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/requirements.txt old mode 100755 new mode 100644 index 38281151344fe0631267a2578d2779d745c2e7a3..9f9c71f54c4037e60ccda37bdf7f177dc1a86297 --- a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/requirements.txt +++ b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/requirements.txt @@ -1,5 +1,5 @@ -torch==1.5.0 -apex -torchvision==0.6.0 -Pandas +torch==1.5.0 +apex +torchvision==0.6.0 +Pandas opencv-python \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/run_ssd_example.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/run_ssd_example.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/run_ssd_live_caffe2.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/run_ssd_live_caffe2.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/run_ssd_live_demo.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/run_ssd_live_demo.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/scripts/eval.sh b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/scripts/eval.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/scripts/set_npu_env.sh b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/scripts/set_npu_env.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/scripts/train_1p.sh b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/scripts/train_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/scripts/train_8p.sh b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/scripts/train_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/test/env_npu.sh b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/test/env_npu.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/test/train_finetune_1p.sh b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/test/train_finetune_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/test/train_full_1p.sh b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/test/train_full_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/test/train_full_8p.sh b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/test/train_full_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/test/train_performance_1p.sh b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/test/train_performance_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/test/train_performance_8p.sh b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/test/train_performance_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/train_ssd.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/train_ssd.py old mode 100755 new mode 100644 index 248d41ef2728de73fd66a50f0141c6d1efeabc98..5da35feb7006a21940524507ccc7343197f92335 --- a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/train_ssd.py +++ b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/train_ssd.py @@ -1,493 +1,493 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import argparse -import os -import logging -import pathlib -import sys -import itertools -import apex -import torch -from torch.utils.data import DataLoader, ConcatDataset -from torch.optim.lr_scheduler import CosineAnnealingLR, MultiStepLR, LambdaLR - -from vision.utils.misc import Timer, freeze_net_layers, store_labels -from vision.ssd.ssd import MatchPrior -from vision.ssd.mobilenetv3_ssd_lite import create_mobilenetv3_large_ssd_lite, create_mobilenetv3_small_ssd_lite -from vision.ssd.mobilenetv1_ssd import create_mobilenetv1_ssd, create_mobilenetv1_ssd_predictor -from vision.ssd.mobilenetv1_ssd_lite import create_mobilenetv1_ssd_lite, create_mobilenetv1_ssd_lite_predictor -from vision.ssd.squeezenet_ssd_lite import create_squeezenet_ssd_lite, create_squeezenet_ssd_lite_predictor -from vision.ssd.mobilenet_v2_ssd_lite import create_mobilenetv2_ssd_lite, create_mobilenetv2_ssd_lite_predictor -from vision.ssd.vgg_ssd import create_vgg_ssd, create_vgg_ssd_predictor -from vision.datasets.voc_dataset import VOCDataset -from vision.datasets.open_images import OpenImagesDataset -from vision.nn.multibox_loss import MultiboxLoss -from vision.ssd.config import vgg_ssd_config -from vision.ssd.config import mobilenetv1_ssd_config -from vision.ssd.config import squeezenet_ssd_config -from vision.ssd.data_preprocessing import TrainAugmentation, TestTransform -from eval_ssd import predicate -from vision.utils.misc import str2bool -from apex import amp - -parser = argparse.ArgumentParser( - description='Single Shot MultiBox Detector Training With Pytorch') - -# dataset setting -parser.add_argument("--dataset_type", default="voc", type=str, - help='Specify dataset type. Currently support voc and open_images.') -parser.add_argument('--data_path', default='') -parser.add_argument('--datasets', default=[], help='Dataset directory path') -parser.add_argument('--validation_dataset', help='Dataset directory path') -parser.add_argument('--balance_data', action='store_true', - help="Balance training data by down-sampling more frequent labels.") - -# Params for loading pretrained basenet or checkpoints. -parser.add_argument('--base_net', default='', - help='Pretrained base model') -parser.add_argument('--pretrained_ssd', default='', help='Pre-trained base model') -parser.add_argument('--resume', default=None, type=str, - help='Checkpoint state_dict file to resume training from') -parser.add_argument('--net', default="vgg16-ssd", - help="The network architecture, it can be mb1-ssd, mb1-lite-ssd, mb2-ssd-lite, mb3-large-ssd-lite, mb3-small-ssd-lite or vgg16-ssd.") -parser.add_argument('--freeze_base_net', action='store_true', - help="Freeze base net layers.") -parser.add_argument('--freeze_net', action='store_true', - help="Freeze all the layers except the prediction head.") -parser.add_argument('--mb2_width_mult', default=1.0, type=float, - help='Width Multiplifier for MobilenetV2') - -# Params for SGD -parser.add_argument('--lr', '--learning-rate', default=1e-3, type=float, - help='initial learning rate') -parser.add_argument('--momentum', default=0.9, type=float, - help='Momentum value for optim') -parser.add_argument('--weight_decay', default=5e-4, type=float, - help='Weight decay for SGD') -parser.add_argument('--gamma', default=0.1, type=float, - help='Gamma update for SGD') -parser.add_argument('--base_net_lr', default=None, type=float, - help='initial learning rate for base net.') -parser.add_argument('--extra_layers_lr', default=None, type=float, - help='initial learning rate for the layers not in base net and prediction heads.') - -# Scheduler -parser.add_argument('--scheduler', default="multi-step", type=str, - help="Scheduler for SGD. It can one of multi-step and cosine") - -# Params for Multi-step Scheduler -parser.add_argument('--milestones', default="80,100", type=str, - help="milestones for MultiStepLR") - -# Params for Cosine Annealing -parser.add_argument('--t_max', default=120, type=float, - help='T_max value for Cosine Annealing Scheduler.') - -# Train params -parser.add_argument('--batch_size', default=32, type=int, - help='Batch size for training') -parser.add_argument('--num_epochs', default=120, type=int, - help='the number epochs') -parser.add_argument('--num_workers', default=4, type=int, - help='Number of workers used in dataloading') -parser.add_argument('--validation_epochs', default=5, type=int, - help='the number epochs') -parser.add_argument('--debug_steps', default=100, type=int, - help='Set the debug log output frequency.') -parser.add_argument('--checkpoint_folder', default='models/', - help='Directory for saving checkpoint models') -# eval params -parser.add_argument("--nms_method", type=str, default="hard") -parser.add_argument("--use_2007_metric", type=str2bool, default=True) -parser.add_argument("--iou_threshold", type=float, default=0.5, help="The threshold of Intersection over Union.") -parser.add_argument("--eval_dir", default="eval_results", type=str, help="The directory to store evaluation results.") - -# distributed setting -parser.add_argument('--distributed', default=False, action='store_true', - help='Use multi-processing distributed training to launch ') -parser.add_argument('--seed', default=None, type=int, - help='seed for initializing training. ') -parser.add_argument('--device', default='gpu', type=str, help='npu or gpu') -parser.add_argument('--gpu', default=0, type=int, - help='GPU id to use.') -parser.add_argument('--device_list', default='0,1,2,3,4,5,6,7', type=str, help='device id list') -parser.add_argument('--world_size', default=-1, type=int, - help='number of nodes for distributed training') -parser.add_argument('--rank', default=-1, type=int, - help='node rank for distributed training') -parser.add_argument('--dist_url', default='', type=str, - help='url used to set up distributed training') -parser.add_argument('--dist_backend', default='nccl', type=str, - help='distributed backend, nccl for GPU, hccl for NPU') -parser.add_argument('--addr', default='127.0.0.1', type=str, help='master addr') -parser.add_argument('--port', default='29688', type=str, help='master port') - -# apex setting -parser.add_argument('--amp', default=False, action='store_true', - help='use amp to train the model') -parser.add_argument('--opt_level', default='O2', type=str, help='apex optimize level') -parser.add_argument('--loss_scale_value', default=128.0, type=int, help='static loss scale value') - -# learning rate setting -parser.add_argument('--warm_up', default=False, action='store_true', help='use warm_up or not') -parser.add_argument('--warm_up_epochs', default=5, type=int, help='warm up epochs') -parser.add_argument('--stay_lr', default=-1, type=int, help='Epoch with constant learning rate') - -logging.basicConfig(stream=sys.stdout, level=logging.INFO, - format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') - - -def device_id_to_process_device_map(device_list): - devices = device_list.split(",") - devices = [int(x) for x in devices] - devices.sort() - - process_device_map = dict() - for process_id, device_id in enumerate(devices): - process_device_map[process_id] = device_id - - return process_device_map - - -def train(loader, net, criterion, optimizer, args, timer, debug_steps=100, epoch=-1): - net.train(True) - running_loss = 0.0 - running_regression_loss = 0.0 - running_classification_loss = 0.0 - timer.start('batch_time') - timer.start('multi_step_time') - multi_step = 0 - for i, data in enumerate(loader): - images, boxes, labels = data - boxes, labels = boxes.to(args.device), labels.to(args.device) - optimizer.zero_grad() - confidence, locations = net.forward(images) - regression_loss, classification_loss = criterion(confidence, locations, labels, boxes) # TODO CHANGE BOXES - loss = (regression_loss + classification_loss) - if args.amp: - with amp.scale_loss(loss, optimizer) as scale_loss: - scale_loss.backward() - else: - loss.backward() - optimizer.step() - - running_loss += loss.item() - running_regression_loss += regression_loss.item() - running_classification_loss += classification_loss.item() - multi_step += 1 - if (i % debug_steps == 0 or i == len(loader) - 1) and (not args.distributed or args.rank == 0): - avg_loss = running_loss / (i + 1) - avg_reg_loss = running_regression_loss / (i + 1) - avg_clf_loss = running_classification_loss / (i + 1) - multi_step_time = timer.end('multi_step_time') - logging.info( - f"Epoch: {epoch}, Step: {i}, " + - f"multi_step_time: {multi_step_time:.4f}, " + - f"step_avg_time: {multi_step_time / multi_step:.4f}, " + - f"Average Regression Loss {avg_reg_loss:.4f}, " + - f"Average Classification Loss: {avg_clf_loss:.4f}, " + - f"Average Loss: {avg_loss:.4f}" - ) - multi_step = 0 - timer.start('multi_step_time') - if not args.distributed or args.rank == 0: - batch_time = timer.end('batch_time') - logging.info(f"Epoch: {epoch}, " + - f"batch_time: {batch_time:.4f}, " + - f"FPS: {args.batch_size * args.ngpu * len(loader) / batch_time:.4f} ") - - -def test(loader, net, criterion, args, epoch=-1): - net.eval() - running_loss = 0.0 - running_regression_loss = 0.0 - running_classification_loss = 0.0 - num = 0 - for i, data in enumerate(loader): - images, boxes, labels = data - num += 1 - with torch.no_grad(): - confidence, locations = net(images) - regression_loss, classification_loss = criterion(confidence.cpu(), locations.cpu(), labels, boxes) - loss = regression_loss + classification_loss - running_loss += loss.item() - running_regression_loss += regression_loss.item() - running_classification_loss += classification_loss.item() - if not args.distributed or args.rank == 0: - logging.info( - f"Epoch: {epoch}, Step: {i}, " + - f"Average Regression Loss {running_regression_loss / (i + 1):.4f}, " + - f"Average Classification Loss: {running_classification_loss / (i + 1):.4f}, " + - f"Average Loss: {running_loss / (i + 1):.4f}" - ) - return running_loss / num, running_regression_loss / num, running_classification_loss / num - - -def main_worker(gpu, timer, args): - args.gpu = args.process_device_map[gpu] - print(args.gpu) - if args.distributed: - if args.device == 'npu': - torch.distributed.init_process_group(backend=args.dist_backend, - world_size=args.ngpu, - rank=args.rank) - else: - torch.distributed.init_process_group(backend=args.dist_backend, - init_method="env://", - world_size=args.ngpu, - rank=args.rank) - if args.device == 'npu': - args.device = 'npu:{}'.format(args.gpu) - print(args.device) - torch.npu.set_device(args.device) - logging.info('use NPU, {}'.format(args.device)) - elif args.device == 'gpu': - args.device = 'cuda:{}'.format(args.gpu) - torch.backends.cudnn.benchmark = True - logging.info('use GPU, {}'.format(args.device)) - - if args.net == 'vgg16-ssd': - create_net = create_vgg_ssd - create_predictor = lambda net: create_vgg_ssd_predictor(net, nms_method=args.nms_method, device=args.device) - config = vgg_ssd_config - elif args.net == 'mb1-ssd': - create_net = create_mobilenetv1_ssd - create_predictor = lambda net: create_mobilenetv1_ssd_predictor(net, nms_method=args.nms_method, - device=args.device) - config = mobilenetv1_ssd_config - elif args.net == 'mb1-ssd-lite': - create_net = create_mobilenetv1_ssd_lite - create_predictor = lambda net: create_mobilenetv1_ssd_lite_predictor(net, nms_method=args.nms_method, - device=args.device) - config = mobilenetv1_ssd_config - elif args.net == 'sq-ssd-lite': - create_net = create_squeezenet_ssd_lite - create_predictor = lambda net: create_squeezenet_ssd_lite_predictor(net, nms_method=args.nms_method, - device=args.device) - config = squeezenet_ssd_config - elif args.net == 'mb2-ssd-lite': - create_net = lambda num: create_mobilenetv2_ssd_lite(num, width_mult=args.mb2_width_mult, device=args.device) - create_predictor = lambda net: create_mobilenetv2_ssd_lite_predictor(net, nms_method=args.nms_method, - device=args.device) - config = mobilenetv1_ssd_config - elif args.net == 'mb3-large-ssd-lite': - create_net = lambda num: create_mobilenetv3_large_ssd_lite(num) - create_predictor = lambda net: create_mobilenetv2_ssd_lite_predictor(net, nms_method=args.nms_method, - device=args.device) - config = mobilenetv1_ssd_config - elif args.net == 'mb3-small-ssd-lite': - create_net = lambda num: create_mobilenetv3_small_ssd_lite(num) - create_predictor = lambda net: create_mobilenetv2_ssd_lite_predictor(net, nms_method=args.nms_method, - device=args.device) - config = mobilenetv1_ssd_config - else: - logging.fatal("The net type is wrong.") - parser.print_help(sys.stderr) - sys.exit(1) - train_transform = TrainAugmentation(config.image_size, config.image_mean, config.image_std) - target_transform = MatchPrior(config.priors, config.center_variance, - config.size_variance, 0.5) - - test_transform = TestTransform(config.image_size, config.image_mean, config.image_std) - logging.info("Prepare training datasets.") - datasets = [] - for dataset_path in args.datasets: - if args.dataset_type == 'voc': - dataset = VOCDataset(dataset_path, transform=train_transform, - target_transform=target_transform) - label_file = os.path.join(args.checkpoint_folder, "voc-model-labels.txt") - store_labels(label_file, dataset.class_names) - num_classes = len(dataset.class_names) - elif args.dataset_type == 'open_images': - dataset = OpenImagesDataset(dataset_path, - transform=train_transform, target_transform=target_transform, - dataset_type="train", balance_data=args.balance_data) - label_file = os.path.join(args.checkpoint_folder, "open-images-model-labels.txt") - store_labels(label_file, dataset.class_names) - logging.info(dataset) - num_classes = len(dataset.class_names) - - else: - raise ValueError(f"Dataset type {args.dataset_type} is not supported.") - datasets.append(dataset) - logging.info(f"Stored labels into file {label_file}.") - train_dataset = ConcatDataset(datasets) - logging.info("Train dataset size: {}".format(len(train_dataset))) - - if args.distributed: - train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) - train_loader = DataLoader(train_dataset, - args.batch_size, - num_workers=args.num_workers, - sampler=train_sampler if args.distributed else None, - shuffle=False if args.distributed else True) - logging.info("Prepare Validation datasets.") - if args.dataset_type == "voc": - val_dataset = VOCDataset(args.validation_dataset, transform=test_transform, - target_transform=target_transform, is_test=True) - elif args.dataset_type == 'open_images': - val_dataset = OpenImagesDataset(dataset_path, - transform=test_transform, target_transform=target_transform, - dataset_type="test") - logging.info(val_dataset) - logging.info("validation dataset size: {}".format(len(val_dataset))) - - val_loader = DataLoader(val_dataset, args.batch_size, - num_workers=args.num_workers, - shuffle=False) - - logging.info("Build network.") - net = create_net(num_classes) - min_loss = -10000.0 - last_epoch = -1 - - base_net_lr = args.base_net_lr if args.base_net_lr is not None else args.lr - extra_layers_lr = args.extra_layers_lr if args.extra_layers_lr is not None else args.lr - if args.freeze_base_net: - logging.info("Freeze base net.") - freeze_net_layers(net.base_net) - params = itertools.chain(net.source_layer_add_ons.parameters(), net.extras.parameters(), - net.regression_headers.parameters(), net.classification_headers.parameters()) - params = [ - {'params': itertools.chain( - net.source_layer_add_ons.parameters(), - net.extras.parameters() - ), 'lr': extra_layers_lr}, - {'params': itertools.chain( - net.regression_headers.parameters(), - net.classification_headers.parameters() - )} - ] - elif args.freeze_net: - freeze_net_layers(net.base_net) - freeze_net_layers(net.source_layer_add_ons) - freeze_net_layers(net.extras) - params = itertools.chain(net.regression_headers.parameters(), net.classification_headers.parameters()) - logging.info("Freeze all the layers except prediction heads.") - else: - params = [ - {'params': net.base_net.parameters(), 'lr': base_net_lr}, - {'params': itertools.chain( - net.source_layer_add_ons.parameters(), - net.extras.parameters() - ), 'lr': extra_layers_lr}, - {'params': itertools.chain( - net.regression_headers.parameters(), - net.classification_headers.parameters() - )} - ] - net.to(args.device) - criterion = MultiboxLoss(config.priors, iou_threshold=0.5, neg_pos_ratio=3, - center_variance=0.1, size_variance=0.2, device=args.device) - # npu: NpuFusedSGD - if 'npu' in args.device: - optimizer = apex.optimizers.NpuFusedSGD(params, lr=args.lr, momentum=args.momentum, - weight_decay=args.weight_decay) - else: - optimizer = torch.optim.SGD(params, lr=args.lr, momentum=args.momentum, - weight_decay=args.weight_decay) - timer.start("Load Model") - if args.resume: - logging.info(f"Resume from the model {args.resume}") - checkpoint = torch.load(args.resume, map_location='cpu') - pretrained_dic = {k.replace('module.', ''): v for k, v in checkpoint['state_dict'].items()} - net.load_state_dict(pretrained_dic) - optimizer.load_state_dict(checkpoint['optimizer']) - last_epoch = checkpoint['epoch'] - elif args.base_net: - logging.info(f"Init from base net {args.base_net}") - net.init_from_base_net(args.base_net) - elif args.pretrained_ssd: - logging.info(f"Init from pretrained ssd {args.pretrained_ssd}") - net.init_from_pretrained_ssd(args.pretrained_ssd) - logging.info(f'Took {timer.end("Load Model"):.2f} seconds to load the model.') - - if args.amp: - net, optimizer = amp.initialize(net, optimizer, opt_level=args.opt_level, loss_scale=args.loss_scale_value) - if args.distributed: - net = torch.nn.parallel.DistributedDataParallel(net, device_ids=[args.rank], - broadcast_buffers=False if 'npu' in args.device else True) - logging.info(f"Learning rate: {args.lr}, Base net learning rate: {base_net_lr}, " - + f"Extra Layers learning rate: {extra_layers_lr}.") - - if args.scheduler == 'multi-step': - logging.info("Uses MultiStepLR scheduler.") - milestones = [int(v.strip()) for v in args.milestones.split(",")] - scheduler = MultiStepLR(optimizer, milestones=milestones, - gamma=0.1, last_epoch=last_epoch) - elif args.scheduler == 'cosine': - logging.info("Uses CosineAnnealingLR scheduler.") - scheduler = CosineAnnealingLR(optimizer, args.t_max, last_epoch=last_epoch) - else: - logging.fatal(f"Unsupported Scheduler: {args.scheduler}.") - parser.print_help(sys.stderr) - sys.exit(1) - if args.warm_up: - warm_up_scheduler = LambdaLR(optimizer, lr_lambda=lambda epoch: epoch / args.warm_up_epochs) - - logging.info(f"Start training from epoch {last_epoch + 1}.") - for epoch in range(last_epoch + 1, args.num_epochs): - if args.distributed: - train_sampler.set_epoch(epoch) - if args.warm_up and epoch < args.warm_up_epochs: - warm_up_scheduler.step() - else: - scheduler.step() - train(train_loader, net, criterion, optimizer, args, timer, - debug_steps=args.debug_steps, epoch=epoch) - if (epoch % args.validation_epochs == 0 or epoch == args.num_epochs - 1) and ( - not args.distributed or args.rank == 0): - val_loss, val_regression_loss, val_classification_loss = test(val_loader, net, criterion, args, epoch) - logging.info( - f"Epoch: {epoch}, " + - f"Validation Regression Loss {val_regression_loss:.4f}, " + - f"Validation Classification Loss: {val_classification_loss:.4f}, " + - f"Validation Loss: {val_loss:.4f}" - ) - model_path = os.path.join(args.checkpoint_folder, f"{args.net}-Epoch-{epoch}-Loss-{val_loss}.pth") - torch.save({'state_dict': net.state_dict(), 'epoch': epoch, 'optimizer': optimizer.state_dict()}, - model_path) - logging.info(f"Saved model {model_path}") - - # 默认只测最后一轮的精度 - predictor = create_predictor(net) - val_dataset = VOCDataset(args.validation_dataset, is_test=True) - accuracy = predicate(val_dataset, predictor, args, dataset.class_names) - logging.info(f'epoch: {epoch}, accuracy: {accuracy}') - - -if __name__ == '__main__': - timer = Timer() - args = parser.parse_args() - if args.device == 'npu': - os.environ['MASTER_ADDR'] = args.addr - os.environ['MASTER_PORT'] = args.port - - logging.info(args) - args.process_device_map = device_id_to_process_device_map(args.device_list) - - if not os.path.exists(args.eval_dir): - os.makedirs(args.eval_dir) - if not os.path.exists(args.checkpoint_folder): - os.makedirs(args.checkpoint_folder) - args.datasets = [os.path.join(args.data_path, 'VOC2007_trainval'), os.path.join(args.data_path, 'VOC2012_trainval')] - args.validation_dataset = os.path.join(args.data_path, 'VOC2007_test') - if args.distributed: - args.ngpu = int(os.environ['RANK_SIZE']) - main_worker(args.rank, timer, args) - else: - args.ngpu = 1 - main_worker(args.gpu, timer, args) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import argparse +import os +import logging +import pathlib +import sys +import itertools +import apex +import torch +from torch.utils.data import DataLoader, ConcatDataset +from torch.optim.lr_scheduler import CosineAnnealingLR, MultiStepLR, LambdaLR + +from vision.utils.misc import Timer, freeze_net_layers, store_labels +from vision.ssd.ssd import MatchPrior +from vision.ssd.mobilenetv3_ssd_lite import create_mobilenetv3_large_ssd_lite, create_mobilenetv3_small_ssd_lite +from vision.ssd.mobilenetv1_ssd import create_mobilenetv1_ssd, create_mobilenetv1_ssd_predictor +from vision.ssd.mobilenetv1_ssd_lite import create_mobilenetv1_ssd_lite, create_mobilenetv1_ssd_lite_predictor +from vision.ssd.squeezenet_ssd_lite import create_squeezenet_ssd_lite, create_squeezenet_ssd_lite_predictor +from vision.ssd.mobilenet_v2_ssd_lite import create_mobilenetv2_ssd_lite, create_mobilenetv2_ssd_lite_predictor +from vision.ssd.vgg_ssd import create_vgg_ssd, create_vgg_ssd_predictor +from vision.datasets.voc_dataset import VOCDataset +from vision.datasets.open_images import OpenImagesDataset +from vision.nn.multibox_loss import MultiboxLoss +from vision.ssd.config import vgg_ssd_config +from vision.ssd.config import mobilenetv1_ssd_config +from vision.ssd.config import squeezenet_ssd_config +from vision.ssd.data_preprocessing import TrainAugmentation, TestTransform +from eval_ssd import predicate +from vision.utils.misc import str2bool +from apex import amp + +parser = argparse.ArgumentParser( + description='Single Shot MultiBox Detector Training With Pytorch') + +# dataset setting +parser.add_argument("--dataset_type", default="voc", type=str, + help='Specify dataset type. Currently support voc and open_images.') +parser.add_argument('--data_path', default='') +parser.add_argument('--datasets', default=[], help='Dataset directory path') +parser.add_argument('--validation_dataset', help='Dataset directory path') +parser.add_argument('--balance_data', action='store_true', + help="Balance training data by down-sampling more frequent labels.") + +# Params for loading pretrained basenet or checkpoints. +parser.add_argument('--base_net', default='', + help='Pretrained base model') +parser.add_argument('--pretrained_ssd', default='', help='Pre-trained base model') +parser.add_argument('--resume', default=None, type=str, + help='Checkpoint state_dict file to resume training from') +parser.add_argument('--net', default="vgg16-ssd", + help="The network architecture, it can be mb1-ssd, mb1-lite-ssd, mb2-ssd-lite, mb3-large-ssd-lite, mb3-small-ssd-lite or vgg16-ssd.") +parser.add_argument('--freeze_base_net', action='store_true', + help="Freeze base net layers.") +parser.add_argument('--freeze_net', action='store_true', + help="Freeze all the layers except the prediction head.") +parser.add_argument('--mb2_width_mult', default=1.0, type=float, + help='Width Multiplifier for MobilenetV2') + +# Params for SGD +parser.add_argument('--lr', '--learning-rate', default=1e-3, type=float, + help='initial learning rate') +parser.add_argument('--momentum', default=0.9, type=float, + help='Momentum value for optim') +parser.add_argument('--weight_decay', default=5e-4, type=float, + help='Weight decay for SGD') +parser.add_argument('--gamma', default=0.1, type=float, + help='Gamma update for SGD') +parser.add_argument('--base_net_lr', default=None, type=float, + help='initial learning rate for base net.') +parser.add_argument('--extra_layers_lr', default=None, type=float, + help='initial learning rate for the layers not in base net and prediction heads.') + +# Scheduler +parser.add_argument('--scheduler', default="multi-step", type=str, + help="Scheduler for SGD. It can one of multi-step and cosine") + +# Params for Multi-step Scheduler +parser.add_argument('--milestones', default="80,100", type=str, + help="milestones for MultiStepLR") + +# Params for Cosine Annealing +parser.add_argument('--t_max', default=120, type=float, + help='T_max value for Cosine Annealing Scheduler.') + +# Train params +parser.add_argument('--batch_size', default=32, type=int, + help='Batch size for training') +parser.add_argument('--num_epochs', default=120, type=int, + help='the number epochs') +parser.add_argument('--num_workers', default=4, type=int, + help='Number of workers used in dataloading') +parser.add_argument('--validation_epochs', default=5, type=int, + help='the number epochs') +parser.add_argument('--debug_steps', default=100, type=int, + help='Set the debug log output frequency.') +parser.add_argument('--checkpoint_folder', default='models/', + help='Directory for saving checkpoint models') +# eval params +parser.add_argument("--nms_method", type=str, default="hard") +parser.add_argument("--use_2007_metric", type=str2bool, default=True) +parser.add_argument("--iou_threshold", type=float, default=0.5, help="The threshold of Intersection over Union.") +parser.add_argument("--eval_dir", default="eval_results", type=str, help="The directory to store evaluation results.") + +# distributed setting +parser.add_argument('--distributed', default=False, action='store_true', + help='Use multi-processing distributed training to launch ') +parser.add_argument('--seed', default=None, type=int, + help='seed for initializing training. ') +parser.add_argument('--device', default='gpu', type=str, help='npu or gpu') +parser.add_argument('--gpu', default=0, type=int, + help='GPU id to use.') +parser.add_argument('--device_list', default='0,1,2,3,4,5,6,7', type=str, help='device id list') +parser.add_argument('--world_size', default=-1, type=int, + help='number of nodes for distributed training') +parser.add_argument('--rank', default=-1, type=int, + help='node rank for distributed training') +parser.add_argument('--dist_url', default='', type=str, + help='url used to set up distributed training') +parser.add_argument('--dist_backend', default='nccl', type=str, + help='distributed backend, nccl for GPU, hccl for NPU') +parser.add_argument('--addr', default='127.0.0.1', type=str, help='master addr') +parser.add_argument('--port', default='29688', type=str, help='master port') + +# apex setting +parser.add_argument('--amp', default=False, action='store_true', + help='use amp to train the model') +parser.add_argument('--opt_level', default='O2', type=str, help='apex optimize level') +parser.add_argument('--loss_scale_value', default=128.0, type=int, help='static loss scale value') + +# learning rate setting +parser.add_argument('--warm_up', default=False, action='store_true', help='use warm_up or not') +parser.add_argument('--warm_up_epochs', default=5, type=int, help='warm up epochs') +parser.add_argument('--stay_lr', default=-1, type=int, help='Epoch with constant learning rate') + +logging.basicConfig(stream=sys.stdout, level=logging.INFO, + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') + + +def device_id_to_process_device_map(device_list): + devices = device_list.split(",") + devices = [int(x) for x in devices] + devices.sort() + + process_device_map = dict() + for process_id, device_id in enumerate(devices): + process_device_map[process_id] = device_id + + return process_device_map + + +def train(loader, net, criterion, optimizer, args, timer, debug_steps=100, epoch=-1): + net.train(True) + running_loss = 0.0 + running_regression_loss = 0.0 + running_classification_loss = 0.0 + timer.start('batch_time') + timer.start('multi_step_time') + multi_step = 0 + for i, data in enumerate(loader): + images, boxes, labels = data + boxes, labels = boxes.to(args.device), labels.to(args.device) + optimizer.zero_grad() + confidence, locations = net.forward(images) + regression_loss, classification_loss = criterion(confidence, locations, labels, boxes) # TODO CHANGE BOXES + loss = (regression_loss + classification_loss) + if args.amp: + with amp.scale_loss(loss, optimizer) as scale_loss: + scale_loss.backward() + else: + loss.backward() + optimizer.step() + + running_loss += loss.item() + running_regression_loss += regression_loss.item() + running_classification_loss += classification_loss.item() + multi_step += 1 + if (i % debug_steps == 0 or i == len(loader) - 1) and (not args.distributed or args.rank == 0): + avg_loss = running_loss / (i + 1) + avg_reg_loss = running_regression_loss / (i + 1) + avg_clf_loss = running_classification_loss / (i + 1) + multi_step_time = timer.end('multi_step_time') + logging.info( + f"Epoch: {epoch}, Step: {i}, " + + f"multi_step_time: {multi_step_time:.4f}, " + + f"step_avg_time: {multi_step_time / multi_step:.4f}, " + + f"Average Regression Loss {avg_reg_loss:.4f}, " + + f"Average Classification Loss: {avg_clf_loss:.4f}, " + + f"Average Loss: {avg_loss:.4f}" + ) + multi_step = 0 + timer.start('multi_step_time') + if not args.distributed or args.rank == 0: + batch_time = timer.end('batch_time') + logging.info(f"Epoch: {epoch}, " + + f"batch_time: {batch_time:.4f}, " + + f"FPS: {args.batch_size * args.ngpu * len(loader) / batch_time:.4f} ") + + +def test(loader, net, criterion, args, epoch=-1): + net.eval() + running_loss = 0.0 + running_regression_loss = 0.0 + running_classification_loss = 0.0 + num = 0 + for i, data in enumerate(loader): + images, boxes, labels = data + num += 1 + with torch.no_grad(): + confidence, locations = net(images) + regression_loss, classification_loss = criterion(confidence.cpu(), locations.cpu(), labels, boxes) + loss = regression_loss + classification_loss + running_loss += loss.item() + running_regression_loss += regression_loss.item() + running_classification_loss += classification_loss.item() + if not args.distributed or args.rank == 0: + logging.info( + f"Epoch: {epoch}, Step: {i}, " + + f"Average Regression Loss {running_regression_loss / (i + 1):.4f}, " + + f"Average Classification Loss: {running_classification_loss / (i + 1):.4f}, " + + f"Average Loss: {running_loss / (i + 1):.4f}" + ) + return running_loss / num, running_regression_loss / num, running_classification_loss / num + + +def main_worker(gpu, timer, args): + args.gpu = args.process_device_map[gpu] + print(args.gpu) + if args.distributed: + if args.device == 'npu': + torch.distributed.init_process_group(backend=args.dist_backend, + world_size=args.ngpu, + rank=args.rank) + else: + torch.distributed.init_process_group(backend=args.dist_backend, + init_method="env://", + world_size=args.ngpu, + rank=args.rank) + if args.device == 'npu': + args.device = 'npu:{}'.format(args.gpu) + print(args.device) + torch.npu.set_device(args.device) + logging.info('use NPU, {}'.format(args.device)) + elif args.device == 'gpu': + args.device = 'cuda:{}'.format(args.gpu) + torch.backends.cudnn.benchmark = True + logging.info('use GPU, {}'.format(args.device)) + + if args.net == 'vgg16-ssd': + create_net = create_vgg_ssd + create_predictor = lambda net: create_vgg_ssd_predictor(net, nms_method=args.nms_method, device=args.device) + config = vgg_ssd_config + elif args.net == 'mb1-ssd': + create_net = create_mobilenetv1_ssd + create_predictor = lambda net: create_mobilenetv1_ssd_predictor(net, nms_method=args.nms_method, + device=args.device) + config = mobilenetv1_ssd_config + elif args.net == 'mb1-ssd-lite': + create_net = create_mobilenetv1_ssd_lite + create_predictor = lambda net: create_mobilenetv1_ssd_lite_predictor(net, nms_method=args.nms_method, + device=args.device) + config = mobilenetv1_ssd_config + elif args.net == 'sq-ssd-lite': + create_net = create_squeezenet_ssd_lite + create_predictor = lambda net: create_squeezenet_ssd_lite_predictor(net, nms_method=args.nms_method, + device=args.device) + config = squeezenet_ssd_config + elif args.net == 'mb2-ssd-lite': + create_net = lambda num: create_mobilenetv2_ssd_lite(num, width_mult=args.mb2_width_mult, device=args.device) + create_predictor = lambda net: create_mobilenetv2_ssd_lite_predictor(net, nms_method=args.nms_method, + device=args.device) + config = mobilenetv1_ssd_config + elif args.net == 'mb3-large-ssd-lite': + create_net = lambda num: create_mobilenetv3_large_ssd_lite(num) + create_predictor = lambda net: create_mobilenetv2_ssd_lite_predictor(net, nms_method=args.nms_method, + device=args.device) + config = mobilenetv1_ssd_config + elif args.net == 'mb3-small-ssd-lite': + create_net = lambda num: create_mobilenetv3_small_ssd_lite(num) + create_predictor = lambda net: create_mobilenetv2_ssd_lite_predictor(net, nms_method=args.nms_method, + device=args.device) + config = mobilenetv1_ssd_config + else: + logging.fatal("The net type is wrong.") + parser.print_help(sys.stderr) + sys.exit(1) + train_transform = TrainAugmentation(config.image_size, config.image_mean, config.image_std) + target_transform = MatchPrior(config.priors, config.center_variance, + config.size_variance, 0.5) + + test_transform = TestTransform(config.image_size, config.image_mean, config.image_std) + logging.info("Prepare training datasets.") + datasets = [] + for dataset_path in args.datasets: + if args.dataset_type == 'voc': + dataset = VOCDataset(dataset_path, transform=train_transform, + target_transform=target_transform) + label_file = os.path.join(args.checkpoint_folder, "voc-model-labels.txt") + store_labels(label_file, dataset.class_names) + num_classes = len(dataset.class_names) + elif args.dataset_type == 'open_images': + dataset = OpenImagesDataset(dataset_path, + transform=train_transform, target_transform=target_transform, + dataset_type="train", balance_data=args.balance_data) + label_file = os.path.join(args.checkpoint_folder, "open-images-model-labels.txt") + store_labels(label_file, dataset.class_names) + logging.info(dataset) + num_classes = len(dataset.class_names) + + else: + raise ValueError(f"Dataset type {args.dataset_type} is not supported.") + datasets.append(dataset) + logging.info(f"Stored labels into file {label_file}.") + train_dataset = ConcatDataset(datasets) + logging.info("Train dataset size: {}".format(len(train_dataset))) + + if args.distributed: + train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) + train_loader = DataLoader(train_dataset, + args.batch_size, + num_workers=args.num_workers, + sampler=train_sampler if args.distributed else None, + shuffle=False if args.distributed else True) + logging.info("Prepare Validation datasets.") + if args.dataset_type == "voc": + val_dataset = VOCDataset(args.validation_dataset, transform=test_transform, + target_transform=target_transform, is_test=True) + elif args.dataset_type == 'open_images': + val_dataset = OpenImagesDataset(dataset_path, + transform=test_transform, target_transform=target_transform, + dataset_type="test") + logging.info(val_dataset) + logging.info("validation dataset size: {}".format(len(val_dataset))) + + val_loader = DataLoader(val_dataset, args.batch_size, + num_workers=args.num_workers, + shuffle=False) + + logging.info("Build network.") + net = create_net(num_classes) + min_loss = -10000.0 + last_epoch = -1 + + base_net_lr = args.base_net_lr if args.base_net_lr is not None else args.lr + extra_layers_lr = args.extra_layers_lr if args.extra_layers_lr is not None else args.lr + if args.freeze_base_net: + logging.info("Freeze base net.") + freeze_net_layers(net.base_net) + params = itertools.chain(net.source_layer_add_ons.parameters(), net.extras.parameters(), + net.regression_headers.parameters(), net.classification_headers.parameters()) + params = [ + {'params': itertools.chain( + net.source_layer_add_ons.parameters(), + net.extras.parameters() + ), 'lr': extra_layers_lr}, + {'params': itertools.chain( + net.regression_headers.parameters(), + net.classification_headers.parameters() + )} + ] + elif args.freeze_net: + freeze_net_layers(net.base_net) + freeze_net_layers(net.source_layer_add_ons) + freeze_net_layers(net.extras) + params = itertools.chain(net.regression_headers.parameters(), net.classification_headers.parameters()) + logging.info("Freeze all the layers except prediction heads.") + else: + params = [ + {'params': net.base_net.parameters(), 'lr': base_net_lr}, + {'params': itertools.chain( + net.source_layer_add_ons.parameters(), + net.extras.parameters() + ), 'lr': extra_layers_lr}, + {'params': itertools.chain( + net.regression_headers.parameters(), + net.classification_headers.parameters() + )} + ] + net.to(args.device) + criterion = MultiboxLoss(config.priors, iou_threshold=0.5, neg_pos_ratio=3, + center_variance=0.1, size_variance=0.2, device=args.device) + # npu: NpuFusedSGD + if 'npu' in args.device: + optimizer = apex.optimizers.NpuFusedSGD(params, lr=args.lr, momentum=args.momentum, + weight_decay=args.weight_decay) + else: + optimizer = torch.optim.SGD(params, lr=args.lr, momentum=args.momentum, + weight_decay=args.weight_decay) + timer.start("Load Model") + if args.resume: + logging.info(f"Resume from the model {args.resume}") + checkpoint = torch.load(args.resume, map_location='cpu') + pretrained_dic = {k.replace('module.', ''): v for k, v in checkpoint['state_dict'].items()} + net.load_state_dict(pretrained_dic) + optimizer.load_state_dict(checkpoint['optimizer']) + last_epoch = checkpoint['epoch'] + elif args.base_net: + logging.info(f"Init from base net {args.base_net}") + net.init_from_base_net(args.base_net) + elif args.pretrained_ssd: + logging.info(f"Init from pretrained ssd {args.pretrained_ssd}") + net.init_from_pretrained_ssd(args.pretrained_ssd) + logging.info(f'Took {timer.end("Load Model"):.2f} seconds to load the model.') + + if args.amp: + net, optimizer = amp.initialize(net, optimizer, opt_level=args.opt_level, loss_scale=args.loss_scale_value) + if args.distributed: + net = torch.nn.parallel.DistributedDataParallel(net, device_ids=[args.rank], + broadcast_buffers=False if 'npu' in args.device else True) + logging.info(f"Learning rate: {args.lr}, Base net learning rate: {base_net_lr}, " + + f"Extra Layers learning rate: {extra_layers_lr}.") + + if args.scheduler == 'multi-step': + logging.info("Uses MultiStepLR scheduler.") + milestones = [int(v.strip()) for v in args.milestones.split(",")] + scheduler = MultiStepLR(optimizer, milestones=milestones, + gamma=0.1, last_epoch=last_epoch) + elif args.scheduler == 'cosine': + logging.info("Uses CosineAnnealingLR scheduler.") + scheduler = CosineAnnealingLR(optimizer, args.t_max, last_epoch=last_epoch) + else: + logging.fatal(f"Unsupported Scheduler: {args.scheduler}.") + parser.print_help(sys.stderr) + sys.exit(1) + if args.warm_up: + warm_up_scheduler = LambdaLR(optimizer, lr_lambda=lambda epoch: epoch / args.warm_up_epochs) + + logging.info(f"Start training from epoch {last_epoch + 1}.") + for epoch in range(last_epoch + 1, args.num_epochs): + if args.distributed: + train_sampler.set_epoch(epoch) + if args.warm_up and epoch < args.warm_up_epochs: + warm_up_scheduler.step() + else: + scheduler.step() + train(train_loader, net, criterion, optimizer, args, timer, + debug_steps=args.debug_steps, epoch=epoch) + if (epoch % args.validation_epochs == 0 or epoch == args.num_epochs - 1) and ( + not args.distributed or args.rank == 0): + val_loss, val_regression_loss, val_classification_loss = test(val_loader, net, criterion, args, epoch) + logging.info( + f"Epoch: {epoch}, " + + f"Validation Regression Loss {val_regression_loss:.4f}, " + + f"Validation Classification Loss: {val_classification_loss:.4f}, " + + f"Validation Loss: {val_loss:.4f}" + ) + model_path = os.path.join(args.checkpoint_folder, f"{args.net}-Epoch-{epoch}-Loss-{val_loss}.pth") + torch.save({'state_dict': net.state_dict(), 'epoch': epoch, 'optimizer': optimizer.state_dict()}, + model_path) + logging.info(f"Saved model {model_path}") + + # 默认只测最后一轮的精度 + predictor = create_predictor(net) + val_dataset = VOCDataset(args.validation_dataset, is_test=True) + accuracy = predicate(val_dataset, predictor, args, dataset.class_names) + logging.info(f'epoch: {epoch}, accuracy: {accuracy}') + + +if __name__ == '__main__': + timer = Timer() + args = parser.parse_args() + if args.device == 'npu': + os.environ['MASTER_ADDR'] = args.addr + os.environ['MASTER_PORT'] = args.port + + logging.info(args) + args.process_device_map = device_id_to_process_device_map(args.device_list) + + if not os.path.exists(args.eval_dir): + os.makedirs(args.eval_dir) + if not os.path.exists(args.checkpoint_folder): + os.makedirs(args.checkpoint_folder) + args.datasets = [os.path.join(args.data_path, 'VOC2007_trainval'), os.path.join(args.data_path, 'VOC2012_trainval')] + args.validation_dataset = os.path.join(args.data_path, 'VOC2007_test') + if args.distributed: + args.ngpu = int(os.environ['RANK_SIZE']) + main_worker(args.rank, timer, args) + else: + args.ngpu = 1 + main_worker(args.gpu, timer, args) diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/translate_tf_mobilenetv1.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/translate_tf_mobilenetv1.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/datasets/collation.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/datasets/collation.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/datasets/generate_vocdata.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/datasets/generate_vocdata.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/datasets/open_images.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/datasets/open_images.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/datasets/voc_dataset.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/datasets/voc_dataset.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/alexnet.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/alexnet.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/mobilenet.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/mobilenet.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/mobilenet_v2.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/mobilenet_v2.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/mobilenetv3.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/mobilenetv3.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/multibox_loss.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/multibox_loss.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/scaled_l2_norm.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/scaled_l2_norm.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/squeezenet.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/squeezenet.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/vgg.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/nn/vgg.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/prunning/prunner.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/prunning/prunner.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/config/mobilenetv1_ssd_config.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/config/mobilenetv1_ssd_config.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/config/squeezenet_ssd_config.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/config/squeezenet_ssd_config.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/config/vgg_ssd_config.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/config/vgg_ssd_config.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/data_preprocessing.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/data_preprocessing.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/fpn_mobilenetv1_ssd.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/fpn_mobilenetv1_ssd.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/fpn_ssd.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/fpn_ssd.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/mobilenet_v2_ssd_lite.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/mobilenet_v2_ssd_lite.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/mobilenetv1_ssd.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/mobilenetv1_ssd.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/mobilenetv1_ssd_lite.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/mobilenetv1_ssd_lite.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/mobilenetv3_ssd_lite.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/mobilenetv3_ssd_lite.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/predictor.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/predictor.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/squeezenet_ssd_lite.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/squeezenet_ssd_lite.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/ssd.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/ssd.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/vgg_ssd.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/ssd/vgg_ssd.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/test/test_vgg_ssd.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/test/test_vgg_ssd.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/transforms/transforms.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/transforms/transforms.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/utils/__init__.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/utils/__init__.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/utils/box_utils.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/utils/box_utils.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/utils/box_utils_numpy.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/utils/box_utils_numpy.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/utils/measurements.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/utils/measurements.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/utils/misc.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/utils/misc.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/utils/model_book.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/vision/utils/model_book.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-MobilenetV2/visual_tf_models.py b/PyTorch/contrib/cv/detection/SSD-MobilenetV2/visual_tf_models.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD-Resnet/README.md b/PyTorch/contrib/cv/detection/SSD-Resnet/README.md index aab3735567d0be24dd0c9d65b38b3e3669d8c903..96ba50816f429f14c4f6ce1a9a068ba743141a9f 100644 --- a/PyTorch/contrib/cv/detection/SSD-Resnet/README.md +++ b/PyTorch/contrib/cv/detection/SSD-Resnet/README.md @@ -1,61 +1,61 @@ -# #SSD-Resnet34 - -This implements training of SSD-Resnet34 on the 2017 COCO dataset. - - - -## #SSD-Resnet34 Detail - -On the basis of resnet34, a part of the feature layer is added for single target detection. - -## Requirements - -* Install Pytorch==1.5.0 and torchvision - -* Install requirements.txt - -* Steps to download pretrain-pth - - ``` - wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E8%AE%AD%E7%BB%83/cv/image_object_detection/SSD-ResNet34/resnet34-333f7ec4.pth - ``` - -* Steps to download data - - ``` - source download_dataset.sh - ``` - - - -# Training - -### To train a model, run `training.py` with the desired model architecture and the path to the coco dataset: - -``` -# training 1p accuracy -cd ./test -bash train_full_1p.sh --data_path=real_data_path -# training 1p performance -cd ./test -bash train_performance_1p.sh --data_path=real_data_path -# training 8p accuracy -cd ./test -bash train_full_8p.sh --data_path=real_data_path -# training 8p performance -cd ./test -bash train_performance_8p.sh --data_path=real_data_path -#test 8p accuracy -bash test/train_eval_8p.sh --data_path=real_data_path --checkpoint_path=real_pre_train_model_path -``` - -Log path: -test/output/{device_id}/train_{device_id}.log -test/output/{device_id}/train_performance_{device_id}.log - -## SSD-Resnet34 training result - -| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | -| ------ | ---- | -------- | ------ | -------- | -| - | 265 | 1 | 1 | O2 | +# #SSD-Resnet34 + +This implements training of SSD-Resnet34 on the 2017 COCO dataset. + + + +## #SSD-Resnet34 Detail + +On the basis of resnet34, a part of the feature layer is added for single target detection. + +## Requirements + +* Install Pytorch==1.5.0 and torchvision + +* Install requirements.txt + +* Steps to download pretrain-pth + + ``` + wget https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E9%AA%8C%E6%94%B6-%E8%AE%AD%E7%BB%83/cv/image_object_detection/SSD-ResNet34/resnet34-333f7ec4.pth + ``` + +* Steps to download data + + ``` + source download_dataset.sh + ``` + + + +# Training + +### To train a model, run `training.py` with the desired model architecture and the path to the coco dataset: + +``` +# training 1p accuracy +cd ./test +bash train_full_1p.sh --data_path=real_data_path +# training 1p performance +cd ./test +bash train_performance_1p.sh --data_path=real_data_path +# training 8p accuracy +cd ./test +bash train_full_8p.sh --data_path=real_data_path +# training 8p performance +cd ./test +bash train_performance_8p.sh --data_path=real_data_path +#test 8p accuracy +bash test/train_eval_8p.sh --data_path=real_data_path --checkpoint_path=real_pre_train_model_path +``` + +Log path: +test/output/{device_id}/train_{device_id}.log +test/output/{device_id}/train_performance_{device_id}.log + +## SSD-Resnet34 training result + +| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | +| ------ | ---- | -------- | ------ | -------- | +| - | 265 | 1 | 1 | O2 | | 0.2301 | 1700 | 8 | 90 | O2 | \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/SSD-Resnet/demo.py b/PyTorch/contrib/cv/detection/SSD-Resnet/demo.py index 5b2972956ba607caa4c7389434129293c4d254c7..4ac02fdea47926b6631d02f75102184ed3ed9ae5 100644 --- a/PyTorch/contrib/cv/detection/SSD-Resnet/demo.py +++ b/PyTorch/contrib/cv/detection/SSD-Resnet/demo.py @@ -1,489 +1,489 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from base_model import Loss -import sys -import os -from opt_loss import OptLoss -from mlperf_logger import configure_logger, log_start, log_end, log_event, set_seeds, get_rank, barrier -from mlperf_logging.mllog import constants -import torch -from torch.autograd import Variable -import time -import numpy as np -import io -from bisect import bisect # for lr_scheduler -from apex import amp -from ssd300 import SSD300 -from master_params import create_flat_master -from parse_config import parse_args, validate_arguments, validate_group_bn -from data.build_pipeline import prebuild_pipeline, build_pipeline -from box_coder import dboxes300_coco, build_ssd300_coder -from async_evaluator import AsyncEvaluator -from eval import coco_eval -from apex.optimizers import NpuFusedSGD -import gc -from torch.nn.parallel import DistributedDataParallel -# necessary pytorch imports -import torch.utils.data.distributed -import torch.distributed as dist - -# Apex imports -try: - import apex_C - import apex - from apex.parallel.LARC import LARC - from apex.parallel import DistributedDataParallel as DDP - from apex.fp16_utils import * - from apex.multi_tensor_apply import multi_tensor_applier - #import amp_C -except ImportError: - raise ImportError("Please install APEX from https://github.com/nvidia/apex") - -from contextlib import redirect_stdout - -import logging - - -class Logger(object): - logfile = "" - - def __init__(self, filename=""): - self.logfile = filename - self.terminal = sys.stdout - # self.log = open(filename, "a") - return - - def write(self, message): - self.terminal.write(message) - if self.logfile != "": - try: - self.log = open(self.logfile, "a") - self.log.write(message) - self.log.close() - except: - pass - - def flush(self): - pass - - -def print_message(rank, *print_args): - if rank == 0: - print(*print_args) - -def load_checkpoint(model, checkpoint): - print("loading model checkpoint", checkpoint) - od = torch.load(checkpoint) - # remove proceeding 'module' from checkpoint - saved_model = od["model"] - for k in list(saved_model.keys()): - if k.startswith('module.'): - saved_model[k[7:]] = saved_model.pop(k) - if k.startswith('mbox.'): - saved_model.pop(k) - model.load_state_dict(saved_model,strict=False) - -def check_async_evals(args, evaluator, threshold): - finished = 0 - # Note: only one rank does COCOEval, so we need to check there if we've - # finished -- we'll broadcast that to a "finished" tensor to determine - # if we should stop - # Note2: ssd_print contains a barrier() call, implemented with all_reduce - # If we conditional on rank 0, then an ssd_print all_reduce matches with - # the finished all_reduce and all hell breaks loose. - if args.rank == 0: - for epoch, current_accuracy in evaluator.finished_tasks().items(): - # Note: Move to per-iter check - # EVAL_START should be prior to the accuracy/score evaluation but adding the missing EVAL_START here for now - log_start(key=constants.EVAL_START, metadata={'epoch_num' : epoch}) - log_event(key=constants.EVAL_ACCURACY, - value=current_accuracy, - metadata={'epoch_num' : epoch}) - log_end(key=constants.EVAL_STOP, metadata={'epoch_num' : epoch}) - if current_accuracy >= threshold: - finished = 1 - - # handle the non-distributed case -- don't need to bcast, just take local result - if not args.distributed: - return finished == 1 - - # Now we know from all ranks if they're done - reduce result - # Note: Already caught the non-distributed case above, can assume broadcast is available - with torch.no_grad(): - finish_tensor = torch.tensor([finished], dtype=torch.int32, device=torch.device('npu')) - # torch.distributed.all_reduce(finish_tensor) - torch.distributed.broadcast(finish_tensor, src=0) - - # >= 1 ranks has seen final accuracy - if finish_tensor.item() >= 1: - return True - - # Default case: No results, or no accuracte enough results - return False - -def lr_warmup(optim, warmup_iter, iter_num, epoch, base_lr, args): - if iter_num < warmup_iter: - warmup_step = base_lr / (warmup_iter * (2 ** args.warmup_factor)) - new_lr = base_lr - (warmup_iter - iter_num) * warmup_step - - for param_group in optim.param_groups: - param_group['lr'] = new_lr - -def setup_distributed(args): - # Setup multi-GPU if necessary - - args.distributed = False - if 'WORLD_SIZE' in os.environ: - args.distributed = int(os.environ['WORLD_SIZE']) > 1 - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = '29688' - if args.distributed: - torch.npu.set_device(args.local_rank) - torch.distributed.init_process_group(backend='hccl', - world_size=int(os.environ['WORLD_SIZE']), - rank=args.local_rank, - ) - args.local_seed = set_seeds(args) - # start timing here - if args.distributed: - args.N_gpu = torch.distributed.get_world_size() - args.rank = torch.distributed.get_rank() - else: - args.N_gpu = 1 - args.rank = 0 - - validate_group_bn(args.bn_group) - - return args - -def train300_mlperf_coco(args): - - - args = setup_distributed(args) - - # Build the model - model_options = { - 'use_nhwc' : args.nhwc, - 'pad_input' : args.pad_input, - 'bn_group' : args.bn_group, - } - - ssd300 = SSD300(args, args.num_classes, **model_options) - if args.checkpoint is not None: - load_checkpoint(ssd300, args.checkpoint) - - ssd300.train() - ssd300.npu() - dboxes = dboxes300_coco() - # Note: No reason not to use optimised loss - #loss_func = OptLoss() - loss_func = Loss(dboxes) - loss_func.npu() - - # Create optimizer. This must also be done after network_to_half. - global_batch_size = (args.N_gpu * args.batch_size) - log_event(key=constants.MODEL_BN_SPAN, value=args.bn_group*args.batch_size) - log_event(key=constants.GLOBAL_BATCH_SIZE, value=global_batch_size) - - # mlperf only allows base_lr scaled by an integer - base_lr = 2.5e-3 - requested_lr_multiplier = args.lr / base_lr - adjusted_multiplier = max(1, round(requested_lr_multiplier * global_batch_size / 32)) - - current_lr = base_lr * adjusted_multiplier - current_momentum = 0.9 - current_weight_decay = args.wd - static_loss_scale = args.loss_scale - - - optim = apex.optimizers.NpuFusedSGD(ssd300.parameters(), - lr=current_lr, - momentum=current_momentum, - weight_decay=current_weight_decay) - ssd300, optim = amp.initialize(ssd300, optim, opt_level='O2', loss_scale=static_loss_scale,combine_grad=True) - # Parallelize. Need to do this after network_to_half. - if args.distributed: - if args.delay_allreduce: - print_message(args.local_rank, "Delaying allreduces to the end of backward()") - ssd300 = DistributedDataParallel(ssd300, device_ids=[args.local_rank]) - - log_event(key=constants.OPT_BASE_LR, value=current_lr) - log_event(key=constants.OPT_LR_DECAY_BOUNDARY_EPOCHS, value=args.lr_decay_epochs) - log_event(key=constants.OPT_LR_DECAY_STEPS, value=args.lr_decay_epochs) - log_event(key=constants.OPT_WEIGHT_DECAY, value=current_weight_decay) - if args.warmup is not None: - log_event(key=constants.OPT_LR_WARMUP_STEPS, value=args.warmup) - log_event(key=constants.OPT_LR_WARMUP_FACTOR, value=args.warmup_factor) - - # Model is completely finished -- need to create separate copies, preserve parameters across - # them, and jit - ssd300_eval = SSD300(args, args.num_classes, **model_options).npu() - - if args.use_fp16: - convert_network(ssd300_eval, torch.half) - - # Get the existant state from the train model - # * if we use distributed, then we want .module - train_model = ssd300.module if args.distributed else ssd300 - ssd300_eval.load_state_dict(train_model.state_dict()) - ssd300_eval.eval() - - - print_message(args.local_rank, "epoch", "nbatch", "loss") - - iter_num = args.iteration - avg_loss = 0.0 - - start_elapsed_time = time.time() - last_printed_iter = args.iteration - num_elapsed_samples = 0 - - input_c = 4 if args.pad_input else 3 - example_shape = [args.batch_size, 300, 300, input_c] if args.nhwc else [args.batch_size, input_c, 300, 300] - example_input = torch.randn(*example_shape).npu() - - if args.use_fp16: - example_input = example_input.half() - - if args.jit: - # DDP has some Python-side control flow. If we JIT the entire DDP-wrapped module, - # the resulting ScriptModule will elide this control flow, resulting in allreduce - # hooks not being called. If we're running distributed, we need to extract and JIT - # the wrapped .module. - # Replacing a DDP-ed ssd300 with a script_module might also cause the AccumulateGrad hooks - # to go out of scope, and therefore silently disappear. - module_to_jit = ssd300.module if args.distributed else ssd300 - if args.distributed: - ssd300.module = torch.jit.trace(module_to_jit, example_input, check_trace=False) - else: - ssd300 = torch.jit.trace(module_to_jit, example_input, check_trace=False) - # JIT the eval model too - ssd300_eval = torch.jit.trace(ssd300_eval, example_input, check_trace=False) - - # do a dummy fprop & bprop to make sure cudnnFind etc. are timed here - ploc, plabel = ssd300(example_input) - - # produce a single dummy "loss" to make things easier - loss = ploc[0,0,0] + plabel[0,0,0] - dloss = torch.randn_like(loss) - # Cause cudnnFind for dgrad, wgrad to run - loss.backward(dloss) - - # Necessary import in init - #from pycocotools.coco import COCO - - encoder = build_ssd300_coder() - - evaluator = AsyncEvaluator(num_threads=1) - - log_end(key=constants.INIT_STOP) - - ##### END INIT - - # This is the first place we touch anything related to data - ##### START DATA TOUCHING - barrier() - log_start(key=constants.RUN_START) - barrier() - - train_pipe = prebuild_pipeline(args) - - train_loader, epoch_size = build_pipeline(args, training=True, pipe=train_pipe) - if args.rank == 0: - print("epoch size is: ", epoch_size, " images") - - val_loader, inv_map, cocoGt = build_pipeline(args, training=False) - if args.profile_gc_off: - gc.disable() - gc.collect() - - ##### END DATA TOUCHING - i_eval = 0 - block_start_epoch = 1 - log_start(key=constants.BLOCK_START, - metadata={'first_epoch_num': block_start_epoch, - 'epoch_count': args.evaluation[i_eval]}) - for epoch in range(args.epochs): - optim.zero_grad() - - - if epoch in args.evaluation: - # Get the existant state from the train model - # * if we use distributed, then we want .module - train_model = ssd300.module if args.distributed else ssd300 - - if args.distributed and args.allreduce_running_stats: - if args.rank == 0: print("averaging bn running means and vars") - # make sure every node has the same running bn stats before - # using them to evaluate, or saving the model for inference - world_size = float(torch.distributed.get_world_size()) - for bn_name, bn_buf in train_model.named_buffers(recurse=True): - if ('running_mean' in bn_name) or ('running_var' in bn_name): - torch.distributed.all_reduce(bn_buf, op=dist.ReduceOp.SUM) - bn_buf /= world_size - - if args.rank == 0: - if args.save: - print("saving model...") - if not os.path.isdir('./models'): - os.mkdir('./models') - torch.save({"model" : ssd300.state_dict()}, "./models/iter_{}.pt".format(iter_num)) - - ssd300_eval.load_state_dict(train_model.state_dict()) - # Note: No longer returns, evaluation is abstracted away inside evaluator - coco_eval(args, - ssd300_eval, - val_loader, - cocoGt, - encoder, - inv_map, - epoch, - iter_num, - evaluator=evaluator) - log_end(key=constants.BLOCK_STOP, metadata={'first_epoch_num': block_start_epoch}) - if epoch != max(args.evaluation): - i_eval += 1 - block_start_epoch = epoch + 1 - log_start(key=constants.BLOCK_START, - metadata={'first_epoch_num': block_start_epoch, - 'epoch_count': (args.evaluation[i_eval] - - args.evaluation[i_eval - 1])}) - - if epoch in args.lr_decay_epochs: - current_lr *= args.lr_decay_factor - print_message(args.rank, "lr decay step #" + str(bisect(args.lr_decay_epochs, epoch))) - for param_group in optim.param_groups: - param_group['lr'] = current_lr - - log_start(key=constants.EPOCH_START, - metadata={'epoch_num': epoch + 1, - 'current_iter_nufm': iter_num}) - - for i, data in enumerate(train_loader): - (img, bbox, label, _) = data - img = img.npu() - bbox = bbox.npu() - label = label.npu() - if args.profile_start is not None and iter_num == args.profile_start: - torch.npu.profiler.start() - torch.npu.synchronize() - if args.profile_nvtx: - torch.autograd._enable_profiler(torch.autograd.ProfilerState.NVTX) - - if args.profile is not None and iter_num == args.profile: - if args.profile_start is not None and iter_num >=args.profile_start: - # we turned npu and nvtx profiling on, better turn it off too - if args.profile_nvtx: - torch.autograd._disable_profiler() - torch.npu.profiler.stop() - return - - if args.warmup is not None: - lr_warmup(optim, args.warmup, iter_num, epoch, current_lr, args) - - if (img is None) or (bbox is None) or (label is None): - print("No labels in batch") - continue - - ploc, plabel = ssd300(img) - ploc, plabel = ploc.float(), plabel.float() - - N = img.shape[0] - bbox.requires_grad = False - label.requires_grad = False - # reshape (N*8732X4 -> Nx8732x4) and transpose (Nx8732x4 -> Nx4x8732) - bbox = bbox.view(N, -1, 4).transpose(1,2).contiguous() - # reshape (N*8732 -> Nx8732) and cast to Long - label = label.view(N, -1).long() - loss = loss_func(ploc, plabel, bbox, label) - - if np.isfinite(loss.item()): - avg_loss = 0.999*avg_loss + 0.001*loss.item() - else: - print("model exploded (corrupted by Inf or Nan)") - sys.exit() - - num_elapsed_samples += N - # if args.rank == 0 and iter_num % args.print_interval == 0: - if args.rank == 0 and iter_num % args.print_interval == 0: - end_elapsed_time = time.time() - elapsed_time = end_elapsed_time - start_elapsed_time - - avg_samples_per_sec = num_elapsed_samples * args.N_gpu / elapsed_time - - print("Epoch:{:4d}, Iteration: {:6d}, Loss function: {:5.3f}, Average Loss: {:.3f}, avg. samples / sec: {:.2f}"\ - .format(epoch, iter_num, loss.item(), avg_loss, avg_samples_per_sec), end="\n") - - last_printed_iter = iter_num - start_elapsed_time = time.time() - num_elapsed_samples = 0 - - - with amp.scale_loss(loss, optim) as scaled_loss: - scaled_loss.backward() - - - optim.step() - - - # Likely a decent skew here, let's take this opportunity to set the - # gradients to None. After DALI integration, playing with the - # placement of this is worth trying. - - optim.zero_grad() - - # Don't check every iteration due to cost of broadcast - if iter_num % 20 == 0: - finished = check_async_evals(args, evaluator, args.threshold) - - if finished: - return True - - iter_num += 1 - - #train_loader.reset() - log_end(key=constants.EPOCH_STOP, metadata={'epoch_num': epoch + 1}) - - return False - -def main(): - # torch.multiprocessing.set_start_method('spawn') - configure_logger(constants.SSD) - log_start(key=constants.INIT_START, log_all_ranks=True) - args = parse_args() - sys.stdout = Logger("test/output/%s/%s_%s.log"%(args.device_id,args.tag,args.device_id)) - sys.stderr = Logger("test/output/%s/%s_%s.log"%(args.device_id,args.tag,args.device_id))#1p - if args.local_rank == 0: - print(args) - - # make sure the epoch lists are in sorted order - args.evaluation.sort() - args.lr_decay_epochs.sort() - - validate_arguments(args) - - torch.set_num_threads(1) - torch.backends.cudnn.benchmark = not args.profile_cudnn_get - - success = train300_mlperf_coco(args) - status = 'success' if success else 'aborted' - - # end timing here - log_end(key=constants.RUN_STOP, metadata={'status': status}) - - -if __name__ == "__main__": - - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from base_model import Loss +import sys +import os +from opt_loss import OptLoss +from mlperf_logger import configure_logger, log_start, log_end, log_event, set_seeds, get_rank, barrier +from mlperf_logging.mllog import constants +import torch +from torch.autograd import Variable +import time +import numpy as np +import io +from bisect import bisect # for lr_scheduler +from apex import amp +from ssd300 import SSD300 +from master_params import create_flat_master +from parse_config import parse_args, validate_arguments, validate_group_bn +from data.build_pipeline import prebuild_pipeline, build_pipeline +from box_coder import dboxes300_coco, build_ssd300_coder +from async_evaluator import AsyncEvaluator +from eval import coco_eval +from apex.optimizers import NpuFusedSGD +import gc +from torch.nn.parallel import DistributedDataParallel +# necessary pytorch imports +import torch.utils.data.distributed +import torch.distributed as dist + +# Apex imports +try: + import apex_C + import apex + from apex.parallel.LARC import LARC + from apex.parallel import DistributedDataParallel as DDP + from apex.fp16_utils import * + from apex.multi_tensor_apply import multi_tensor_applier + #import amp_C +except ImportError: + raise ImportError("Please install APEX from https://github.com/nvidia/apex") + +from contextlib import redirect_stdout + +import logging + + +class Logger(object): + logfile = "" + + def __init__(self, filename=""): + self.logfile = filename + self.terminal = sys.stdout + # self.log = open(filename, "a") + return + + def write(self, message): + self.terminal.write(message) + if self.logfile != "": + try: + self.log = open(self.logfile, "a") + self.log.write(message) + self.log.close() + except: + pass + + def flush(self): + pass + + +def print_message(rank, *print_args): + if rank == 0: + print(*print_args) + +def load_checkpoint(model, checkpoint): + print("loading model checkpoint", checkpoint) + od = torch.load(checkpoint) + # remove proceeding 'module' from checkpoint + saved_model = od["model"] + for k in list(saved_model.keys()): + if k.startswith('module.'): + saved_model[k[7:]] = saved_model.pop(k) + if k.startswith('mbox.'): + saved_model.pop(k) + model.load_state_dict(saved_model,strict=False) + +def check_async_evals(args, evaluator, threshold): + finished = 0 + # Note: only one rank does COCOEval, so we need to check there if we've + # finished -- we'll broadcast that to a "finished" tensor to determine + # if we should stop + # Note2: ssd_print contains a barrier() call, implemented with all_reduce + # If we conditional on rank 0, then an ssd_print all_reduce matches with + # the finished all_reduce and all hell breaks loose. + if args.rank == 0: + for epoch, current_accuracy in evaluator.finished_tasks().items(): + # Note: Move to per-iter check + # EVAL_START should be prior to the accuracy/score evaluation but adding the missing EVAL_START here for now + log_start(key=constants.EVAL_START, metadata={'epoch_num' : epoch}) + log_event(key=constants.EVAL_ACCURACY, + value=current_accuracy, + metadata={'epoch_num' : epoch}) + log_end(key=constants.EVAL_STOP, metadata={'epoch_num' : epoch}) + if current_accuracy >= threshold: + finished = 1 + + # handle the non-distributed case -- don't need to bcast, just take local result + if not args.distributed: + return finished == 1 + + # Now we know from all ranks if they're done - reduce result + # Note: Already caught the non-distributed case above, can assume broadcast is available + with torch.no_grad(): + finish_tensor = torch.tensor([finished], dtype=torch.int32, device=torch.device('npu')) + # torch.distributed.all_reduce(finish_tensor) + torch.distributed.broadcast(finish_tensor, src=0) + + # >= 1 ranks has seen final accuracy + if finish_tensor.item() >= 1: + return True + + # Default case: No results, or no accuracte enough results + return False + +def lr_warmup(optim, warmup_iter, iter_num, epoch, base_lr, args): + if iter_num < warmup_iter: + warmup_step = base_lr / (warmup_iter * (2 ** args.warmup_factor)) + new_lr = base_lr - (warmup_iter - iter_num) * warmup_step + + for param_group in optim.param_groups: + param_group['lr'] = new_lr + +def setup_distributed(args): + # Setup multi-GPU if necessary + + args.distributed = False + if 'WORLD_SIZE' in os.environ: + args.distributed = int(os.environ['WORLD_SIZE']) > 1 + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '29688' + if args.distributed: + torch.npu.set_device(args.local_rank) + torch.distributed.init_process_group(backend='hccl', + world_size=int(os.environ['WORLD_SIZE']), + rank=args.local_rank, + ) + args.local_seed = set_seeds(args) + # start timing here + if args.distributed: + args.N_gpu = torch.distributed.get_world_size() + args.rank = torch.distributed.get_rank() + else: + args.N_gpu = 1 + args.rank = 0 + + validate_group_bn(args.bn_group) + + return args + +def train300_mlperf_coco(args): + + + args = setup_distributed(args) + + # Build the model + model_options = { + 'use_nhwc' : args.nhwc, + 'pad_input' : args.pad_input, + 'bn_group' : args.bn_group, + } + + ssd300 = SSD300(args, args.num_classes, **model_options) + if args.checkpoint is not None: + load_checkpoint(ssd300, args.checkpoint) + + ssd300.train() + ssd300.npu() + dboxes = dboxes300_coco() + # Note: No reason not to use optimised loss + #loss_func = OptLoss() + loss_func = Loss(dboxes) + loss_func.npu() + + # Create optimizer. This must also be done after network_to_half. + global_batch_size = (args.N_gpu * args.batch_size) + log_event(key=constants.MODEL_BN_SPAN, value=args.bn_group*args.batch_size) + log_event(key=constants.GLOBAL_BATCH_SIZE, value=global_batch_size) + + # mlperf only allows base_lr scaled by an integer + base_lr = 2.5e-3 + requested_lr_multiplier = args.lr / base_lr + adjusted_multiplier = max(1, round(requested_lr_multiplier * global_batch_size / 32)) + + current_lr = base_lr * adjusted_multiplier + current_momentum = 0.9 + current_weight_decay = args.wd + static_loss_scale = args.loss_scale + + + optim = apex.optimizers.NpuFusedSGD(ssd300.parameters(), + lr=current_lr, + momentum=current_momentum, + weight_decay=current_weight_decay) + ssd300, optim = amp.initialize(ssd300, optim, opt_level='O2', loss_scale=static_loss_scale,combine_grad=True) + # Parallelize. Need to do this after network_to_half. + if args.distributed: + if args.delay_allreduce: + print_message(args.local_rank, "Delaying allreduces to the end of backward()") + ssd300 = DistributedDataParallel(ssd300, device_ids=[args.local_rank]) + + log_event(key=constants.OPT_BASE_LR, value=current_lr) + log_event(key=constants.OPT_LR_DECAY_BOUNDARY_EPOCHS, value=args.lr_decay_epochs) + log_event(key=constants.OPT_LR_DECAY_STEPS, value=args.lr_decay_epochs) + log_event(key=constants.OPT_WEIGHT_DECAY, value=current_weight_decay) + if args.warmup is not None: + log_event(key=constants.OPT_LR_WARMUP_STEPS, value=args.warmup) + log_event(key=constants.OPT_LR_WARMUP_FACTOR, value=args.warmup_factor) + + # Model is completely finished -- need to create separate copies, preserve parameters across + # them, and jit + ssd300_eval = SSD300(args, args.num_classes, **model_options).npu() + + if args.use_fp16: + convert_network(ssd300_eval, torch.half) + + # Get the existant state from the train model + # * if we use distributed, then we want .module + train_model = ssd300.module if args.distributed else ssd300 + ssd300_eval.load_state_dict(train_model.state_dict()) + ssd300_eval.eval() + + + print_message(args.local_rank, "epoch", "nbatch", "loss") + + iter_num = args.iteration + avg_loss = 0.0 + + start_elapsed_time = time.time() + last_printed_iter = args.iteration + num_elapsed_samples = 0 + + input_c = 4 if args.pad_input else 3 + example_shape = [args.batch_size, 300, 300, input_c] if args.nhwc else [args.batch_size, input_c, 300, 300] + example_input = torch.randn(*example_shape).npu() + + if args.use_fp16: + example_input = example_input.half() + + if args.jit: + # DDP has some Python-side control flow. If we JIT the entire DDP-wrapped module, + # the resulting ScriptModule will elide this control flow, resulting in allreduce + # hooks not being called. If we're running distributed, we need to extract and JIT + # the wrapped .module. + # Replacing a DDP-ed ssd300 with a script_module might also cause the AccumulateGrad hooks + # to go out of scope, and therefore silently disappear. + module_to_jit = ssd300.module if args.distributed else ssd300 + if args.distributed: + ssd300.module = torch.jit.trace(module_to_jit, example_input, check_trace=False) + else: + ssd300 = torch.jit.trace(module_to_jit, example_input, check_trace=False) + # JIT the eval model too + ssd300_eval = torch.jit.trace(ssd300_eval, example_input, check_trace=False) + + # do a dummy fprop & bprop to make sure cudnnFind etc. are timed here + ploc, plabel = ssd300(example_input) + + # produce a single dummy "loss" to make things easier + loss = ploc[0,0,0] + plabel[0,0,0] + dloss = torch.randn_like(loss) + # Cause cudnnFind for dgrad, wgrad to run + loss.backward(dloss) + + # Necessary import in init + #from pycocotools.coco import COCO + + encoder = build_ssd300_coder() + + evaluator = AsyncEvaluator(num_threads=1) + + log_end(key=constants.INIT_STOP) + + ##### END INIT + + # This is the first place we touch anything related to data + ##### START DATA TOUCHING + barrier() + log_start(key=constants.RUN_START) + barrier() + + train_pipe = prebuild_pipeline(args) + + train_loader, epoch_size = build_pipeline(args, training=True, pipe=train_pipe) + if args.rank == 0: + print("epoch size is: ", epoch_size, " images") + + val_loader, inv_map, cocoGt = build_pipeline(args, training=False) + if args.profile_gc_off: + gc.disable() + gc.collect() + + ##### END DATA TOUCHING + i_eval = 0 + block_start_epoch = 1 + log_start(key=constants.BLOCK_START, + metadata={'first_epoch_num': block_start_epoch, + 'epoch_count': args.evaluation[i_eval]}) + for epoch in range(args.epochs): + optim.zero_grad() + + + if epoch in args.evaluation: + # Get the existant state from the train model + # * if we use distributed, then we want .module + train_model = ssd300.module if args.distributed else ssd300 + + if args.distributed and args.allreduce_running_stats: + if args.rank == 0: print("averaging bn running means and vars") + # make sure every node has the same running bn stats before + # using them to evaluate, or saving the model for inference + world_size = float(torch.distributed.get_world_size()) + for bn_name, bn_buf in train_model.named_buffers(recurse=True): + if ('running_mean' in bn_name) or ('running_var' in bn_name): + torch.distributed.all_reduce(bn_buf, op=dist.ReduceOp.SUM) + bn_buf /= world_size + + if args.rank == 0: + if args.save: + print("saving model...") + if not os.path.isdir('./models'): + os.mkdir('./models') + torch.save({"model" : ssd300.state_dict()}, "./models/iter_{}.pt".format(iter_num)) + + ssd300_eval.load_state_dict(train_model.state_dict()) + # Note: No longer returns, evaluation is abstracted away inside evaluator + coco_eval(args, + ssd300_eval, + val_loader, + cocoGt, + encoder, + inv_map, + epoch, + iter_num, + evaluator=evaluator) + log_end(key=constants.BLOCK_STOP, metadata={'first_epoch_num': block_start_epoch}) + if epoch != max(args.evaluation): + i_eval += 1 + block_start_epoch = epoch + 1 + log_start(key=constants.BLOCK_START, + metadata={'first_epoch_num': block_start_epoch, + 'epoch_count': (args.evaluation[i_eval] - + args.evaluation[i_eval - 1])}) + + if epoch in args.lr_decay_epochs: + current_lr *= args.lr_decay_factor + print_message(args.rank, "lr decay step #" + str(bisect(args.lr_decay_epochs, epoch))) + for param_group in optim.param_groups: + param_group['lr'] = current_lr + + log_start(key=constants.EPOCH_START, + metadata={'epoch_num': epoch + 1, + 'current_iter_nufm': iter_num}) + + for i, data in enumerate(train_loader): + (img, bbox, label, _) = data + img = img.npu() + bbox = bbox.npu() + label = label.npu() + if args.profile_start is not None and iter_num == args.profile_start: + torch.npu.profiler.start() + torch.npu.synchronize() + if args.profile_nvtx: + torch.autograd._enable_profiler(torch.autograd.ProfilerState.NVTX) + + if args.profile is not None and iter_num == args.profile: + if args.profile_start is not None and iter_num >=args.profile_start: + # we turned npu and nvtx profiling on, better turn it off too + if args.profile_nvtx: + torch.autograd._disable_profiler() + torch.npu.profiler.stop() + return + + if args.warmup is not None: + lr_warmup(optim, args.warmup, iter_num, epoch, current_lr, args) + + if (img is None) or (bbox is None) or (label is None): + print("No labels in batch") + continue + + ploc, plabel = ssd300(img) + ploc, plabel = ploc.float(), plabel.float() + + N = img.shape[0] + bbox.requires_grad = False + label.requires_grad = False + # reshape (N*8732X4 -> Nx8732x4) and transpose (Nx8732x4 -> Nx4x8732) + bbox = bbox.view(N, -1, 4).transpose(1,2).contiguous() + # reshape (N*8732 -> Nx8732) and cast to Long + label = label.view(N, -1).long() + loss = loss_func(ploc, plabel, bbox, label) + + if np.isfinite(loss.item()): + avg_loss = 0.999*avg_loss + 0.001*loss.item() + else: + print("model exploded (corrupted by Inf or Nan)") + sys.exit() + + num_elapsed_samples += N + # if args.rank == 0 and iter_num % args.print_interval == 0: + if args.rank == 0 and iter_num % args.print_interval == 0: + end_elapsed_time = time.time() + elapsed_time = end_elapsed_time - start_elapsed_time + + avg_samples_per_sec = num_elapsed_samples * args.N_gpu / elapsed_time + + print("Epoch:{:4d}, Iteration: {:6d}, Loss function: {:5.3f}, Average Loss: {:.3f}, avg. samples / sec: {:.2f}"\ + .format(epoch, iter_num, loss.item(), avg_loss, avg_samples_per_sec), end="\n") + + last_printed_iter = iter_num + start_elapsed_time = time.time() + num_elapsed_samples = 0 + + + with amp.scale_loss(loss, optim) as scaled_loss: + scaled_loss.backward() + + + optim.step() + + + # Likely a decent skew here, let's take this opportunity to set the + # gradients to None. After DALI integration, playing with the + # placement of this is worth trying. + + optim.zero_grad() + + # Don't check every iteration due to cost of broadcast + if iter_num % 20 == 0: + finished = check_async_evals(args, evaluator, args.threshold) + + if finished: + return True + + iter_num += 1 + + #train_loader.reset() + log_end(key=constants.EPOCH_STOP, metadata={'epoch_num': epoch + 1}) + + return False + +def main(): + # torch.multiprocessing.set_start_method('spawn') + configure_logger(constants.SSD) + log_start(key=constants.INIT_START, log_all_ranks=True) + args = parse_args() + sys.stdout = Logger("test/output/%s/%s_%s.log"%(args.device_id,args.tag,args.device_id)) + sys.stderr = Logger("test/output/%s/%s_%s.log"%(args.device_id,args.tag,args.device_id))#1p + if args.local_rank == 0: + print(args) + + # make sure the epoch lists are in sorted order + args.evaluation.sort() + args.lr_decay_epochs.sort() + + validate_arguments(args) + + torch.set_num_threads(1) + torch.backends.cudnn.benchmark = not args.profile_cudnn_get + + success = train300_mlperf_coco(args) + status = 'success' if success else 'aborted' + + # end timing here + log_end(key=constants.RUN_STOP, metadata={'status': status}) + + +if __name__ == "__main__": + + main() diff --git a/PyTorch/contrib/cv/detection/SSD-Resnet/new.py b/PyTorch/contrib/cv/detection/SSD-Resnet/new.py index adebc268d6ea5f037f44d8257f79a3d474cf6b86..72f9d053b534e0cb0dc0f9bc1ad9a8805aa93a01 100644 --- a/PyTorch/contrib/cv/detection/SSD-Resnet/new.py +++ b/PyTorch/contrib/cv/detection/SSD-Resnet/new.py @@ -1,52 +1,52 @@ -# Copyright 2021 Huawei Technologies Co., Ltd - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import sys -#sys.path.append('/share/home/litaotao/yzc/training_results_v0.7-master/NVIDIA/benchmarks/ssd/implementations/pytorch/')# -import os -#from base_model import Loss -from opt_loss import OptLoss -from mlperf_logger import configure_logger, log_start, log_end, log_event, set_seeds, get_rank, barrier -from mlperf_logging.mllog import constants -import torch -from torch.autograd import Variable -import time -import numpy as np -import io -from bisect import bisect # for lr_scheduler - -from ssd300 import SSD300 -from master_params import create_flat_master -from parse_config import parse_args, validate_arguments, validate_group_bn - -from async_evaluator import AsyncEvaluator -from eval import coco_eval - -#import sys -import gc -from data.native_pipeline import build_train_pipe -# necessary pytorch imports -import torch.utils.data.distributed -import torch.distributed as dist -configure_logger(constants.SSD) -log_start(key=constants.INIT_START, log_all_ranks=True) -args = parse_args() -# make sure the epoch lists are in sorted order -args.evaluation.sort() -args.lr_decay_epochs.sort() - -validate_arguments(args) - -torch.set_num_threads(1) -torch.backends.cudnn.benchmark = not args.profile_cudnn_get +# Copyright 2021 Huawei Technologies Co., Ltd + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +#sys.path.append('/share/home/litaotao/yzc/training_results_v0.7-master/NVIDIA/benchmarks/ssd/implementations/pytorch/')# +import os +#from base_model import Loss +from opt_loss import OptLoss +from mlperf_logger import configure_logger, log_start, log_end, log_event, set_seeds, get_rank, barrier +from mlperf_logging.mllog import constants +import torch +from torch.autograd import Variable +import time +import numpy as np +import io +from bisect import bisect # for lr_scheduler + +from ssd300 import SSD300 +from master_params import create_flat_master +from parse_config import parse_args, validate_arguments, validate_group_bn + +from async_evaluator import AsyncEvaluator +from eval import coco_eval + +#import sys +import gc +from data.native_pipeline import build_train_pipe +# necessary pytorch imports +import torch.utils.data.distributed +import torch.distributed as dist +configure_logger(constants.SSD) +log_start(key=constants.INIT_START, log_all_ranks=True) +args = parse_args() +# make sure the epoch lists are in sorted order +args.evaluation.sort() +args.lr_decay_epochs.sort() + +validate_arguments(args) + +torch.set_num_threads(1) +torch.backends.cudnn.benchmark = not args.profile_cudnn_get build_train_pipe(args) \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/SSD-Resnet/nms.py b/PyTorch/contrib/cv/detection/SSD-Resnet/nms.py index b6aa5577213272de7563a74808c1905af9e060e9..7a81227046624372527c6f326a998a7b26002b38 100644 --- a/PyTorch/contrib/cv/detection/SSD-Resnet/nms.py +++ b/PyTorch/contrib/cv/detection/SSD-Resnet/nms.py @@ -1,146 +1,146 @@ -# Copyright (c) 2020, Huawei Technologies.All rights reserved. -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch - - -def npu_multiclass_nms(multi_bboxes, - multi_scores, - score_thr=0.05, - nms_thr=0.45, - max_num=50, - score_factors=None): - """NMS for multi-class bboxes using npu api. - - Origin implement from mmdetection is - https://github.com/open-mmlab/mmdetection/blob/master/mmdet/core/post_processing/bbox_nms.py#L7 - - This interface is similar to the original interface, but not exactly the same. - - Args: - multi_bboxes (Tensor): shape (n, #class, 4) or (n, 4) - multi_scores (Tensor): shape (n, #class+1), where the last column - contains scores of the background class, but this will be ignored. - On npu, in order to keep the semantics unblocked, we will unify the dimensions - score_thr (float): bbox threshold, bboxes with scores lower than it - will not be considered. - nms_thr (float): NMS IoU threshold. In the original implementation, a dictionary of {"iou_threshold": 0.45} - was passed, which is simplified here. - max_num (int): if there are more than max_num bboxes after NMS, - only top max_num will be kept; if there are less than max_num bboxes after NMS, - the output will zero pad to max_num. On the NPU, the memory needs to be requested in advance, - so the current max_num cannot be set to -1 at present - score_factors (Tensor): The factors multiplied to scores before applying NMS - - Returns: - tuple: (bboxes, labels), tensors of shape (k, 5) and (k, 1). Labels are 0-based. - """ - - num_classes = multi_scores.size(1) - 1 - num_boxes = multi_scores.size(0) - if score_factors is not None: - multi_scores = multi_scores[:, :-1] * score_factors[:, None] - else: - multi_scores = multi_scores[:, :-1] - multi_bboxes = multi_bboxes.reshape(1, num_boxes, multi_bboxes.numel() // 4 // num_boxes, 4) - multi_scores = multi_scores.reshape(1, num_boxes, num_classes) - - nmsed_boxes, nmsed_scores, nmsed_classes, nmsed_num = torch.npu_batch_nms(multi_bboxes.half(), multi_scores.half(), - score_thr, nms_thr, - max_num, max_num) - - nmsed_boxes = nmsed_boxes.reshape(nmsed_boxes.shape[1:]) - nmsed_scores = nmsed_scores.reshape(nmsed_scores.shape[1]) - nmsed_classes = nmsed_classes.reshape(nmsed_classes.shape[1]) - - return torch.cat([nmsed_boxes, nmsed_scores[:, None]], -1), nmsed_classes - - -def npu_batched_multiclass_nms( - multi_bboxes, - multi_scores, - score_thr=0.05, - nms_thr=0.45, - max_num=50, - score_factors=None): - """NMS for batched multi-class bboxes using npu api. - - Origin implement from mmdetection is - https://github.com/open-mmlab/mmdetection/blob/master/mmdet/core/post_processing/bbox_nms.py#L7 - - This interface is similar to the original interface, but not exactly the same. - This interface implements the nms method under batch. - - Args: - multi_bboxes (Tensor): shape (bs, n, #class, 4) or (bs, n, 4) - multi_scores (Tensor): shape (bs, n, #class+1), where the last column - contains scores of the background class, but this will be ignored. - On npu, in order to keep the semantics unblocked, we will unify the dimensions - score_thr (float): bbox threshold, bboxes with scores lower than it - will not be considered. - nms_thr (float): NMS IoU threshold. In the original implementation, a dictionary of {"iou_threshold": 0.45} - was passed, which is simplified here. - max_num (int): if there are more than max_num bboxes after NMS, - only top max_num will be kept; if there are less than max_num bboxes after NMS, - the output will zero pad to max_num. On the NPU, the memory needs to be requested in advance, - so the current max_num cannot be set to -1 at present - score_factors (Tensor): The factors multiplied to scores before applying NMS - - Returns: - tuple: (bboxes, labels), tensors of shape (bs, k, 5) and (bs, k, 1). Labels are 0-based. - """ - - num_classes = multi_scores.size(2) - 1 - num_boxes = multi_scores.size(1) - batch_size = multi_scores.size(0) - if score_factors is not None: - multi_scores = multi_scores[..., :-1] * score_factors[..., None] - else: - multi_scores = multi_scores[..., :-1] - multi_bboxes = multi_bboxes.reshape(batch_size, num_boxes, multi_bboxes.numel() // 4 // num_boxes // batch_size, 4) - multi_scores = multi_scores.reshape(batch_size, num_boxes, num_classes) - - nmsed_boxes, nmsed_scores, nmsed_classes, nmsed_num = torch.npu_batch_nms(multi_bboxes.half(), multi_scores.half(), - score_thr, nms_thr, - max_num, max_num) - - return torch.cat([nmsed_boxes, nmsed_scores[..., None]], -1), nmsed_classes - - -if __name__ == '__main__': - print('test npu_multiclass_nms') - boxes = torch.randint(1, 255, size=(1000, 4)) - scores = torch.randn(1000, 81) - - torch.npu.set_device(0) - boxes = boxes.npu().half() - scores = scores.npu().half() - - det_bboxes, det_labels = npu_multiclass_nms(boxes, scores) - print(det_bboxes.shape) - print(det_labels.shape) - - - print('test npu_batched_multiclass_nms') - boxes = torch.randint(1, 255, size=(4, 200, 80, 4)) - scores = torch.randn(4, 200, 81) - - torch.npu.set_device(0) - boxes = boxes.npu().half() - scores = scores.npu().half() - - det_bboxes, det_labels = npu_batched_multiclass_nms(boxes, scores) - print(det_bboxes.shape) - print(det_labels.shape) - +# Copyright (c) 2020, Huawei Technologies.All rights reserved. +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch + + +def npu_multiclass_nms(multi_bboxes, + multi_scores, + score_thr=0.05, + nms_thr=0.45, + max_num=50, + score_factors=None): + """NMS for multi-class bboxes using npu api. + + Origin implement from mmdetection is + https://github.com/open-mmlab/mmdetection/blob/master/mmdet/core/post_processing/bbox_nms.py#L7 + + This interface is similar to the original interface, but not exactly the same. + + Args: + multi_bboxes (Tensor): shape (n, #class, 4) or (n, 4) + multi_scores (Tensor): shape (n, #class+1), where the last column + contains scores of the background class, but this will be ignored. + On npu, in order to keep the semantics unblocked, we will unify the dimensions + score_thr (float): bbox threshold, bboxes with scores lower than it + will not be considered. + nms_thr (float): NMS IoU threshold. In the original implementation, a dictionary of {"iou_threshold": 0.45} + was passed, which is simplified here. + max_num (int): if there are more than max_num bboxes after NMS, + only top max_num will be kept; if there are less than max_num bboxes after NMS, + the output will zero pad to max_num. On the NPU, the memory needs to be requested in advance, + so the current max_num cannot be set to -1 at present + score_factors (Tensor): The factors multiplied to scores before applying NMS + + Returns: + tuple: (bboxes, labels), tensors of shape (k, 5) and (k, 1). Labels are 0-based. + """ + + num_classes = multi_scores.size(1) - 1 + num_boxes = multi_scores.size(0) + if score_factors is not None: + multi_scores = multi_scores[:, :-1] * score_factors[:, None] + else: + multi_scores = multi_scores[:, :-1] + multi_bboxes = multi_bboxes.reshape(1, num_boxes, multi_bboxes.numel() // 4 // num_boxes, 4) + multi_scores = multi_scores.reshape(1, num_boxes, num_classes) + + nmsed_boxes, nmsed_scores, nmsed_classes, nmsed_num = torch.npu_batch_nms(multi_bboxes.half(), multi_scores.half(), + score_thr, nms_thr, + max_num, max_num) + + nmsed_boxes = nmsed_boxes.reshape(nmsed_boxes.shape[1:]) + nmsed_scores = nmsed_scores.reshape(nmsed_scores.shape[1]) + nmsed_classes = nmsed_classes.reshape(nmsed_classes.shape[1]) + + return torch.cat([nmsed_boxes, nmsed_scores[:, None]], -1), nmsed_classes + + +def npu_batched_multiclass_nms( + multi_bboxes, + multi_scores, + score_thr=0.05, + nms_thr=0.45, + max_num=50, + score_factors=None): + """NMS for batched multi-class bboxes using npu api. + + Origin implement from mmdetection is + https://github.com/open-mmlab/mmdetection/blob/master/mmdet/core/post_processing/bbox_nms.py#L7 + + This interface is similar to the original interface, but not exactly the same. + This interface implements the nms method under batch. + + Args: + multi_bboxes (Tensor): shape (bs, n, #class, 4) or (bs, n, 4) + multi_scores (Tensor): shape (bs, n, #class+1), where the last column + contains scores of the background class, but this will be ignored. + On npu, in order to keep the semantics unblocked, we will unify the dimensions + score_thr (float): bbox threshold, bboxes with scores lower than it + will not be considered. + nms_thr (float): NMS IoU threshold. In the original implementation, a dictionary of {"iou_threshold": 0.45} + was passed, which is simplified here. + max_num (int): if there are more than max_num bboxes after NMS, + only top max_num will be kept; if there are less than max_num bboxes after NMS, + the output will zero pad to max_num. On the NPU, the memory needs to be requested in advance, + so the current max_num cannot be set to -1 at present + score_factors (Tensor): The factors multiplied to scores before applying NMS + + Returns: + tuple: (bboxes, labels), tensors of shape (bs, k, 5) and (bs, k, 1). Labels are 0-based. + """ + + num_classes = multi_scores.size(2) - 1 + num_boxes = multi_scores.size(1) + batch_size = multi_scores.size(0) + if score_factors is not None: + multi_scores = multi_scores[..., :-1] * score_factors[..., None] + else: + multi_scores = multi_scores[..., :-1] + multi_bboxes = multi_bboxes.reshape(batch_size, num_boxes, multi_bboxes.numel() // 4 // num_boxes // batch_size, 4) + multi_scores = multi_scores.reshape(batch_size, num_boxes, num_classes) + + nmsed_boxes, nmsed_scores, nmsed_classes, nmsed_num = torch.npu_batch_nms(multi_bboxes.half(), multi_scores.half(), + score_thr, nms_thr, + max_num, max_num) + + return torch.cat([nmsed_boxes, nmsed_scores[..., None]], -1), nmsed_classes + + +if __name__ == '__main__': + print('test npu_multiclass_nms') + boxes = torch.randint(1, 255, size=(1000, 4)) + scores = torch.randn(1000, 81) + + torch.npu.set_device(0) + boxes = boxes.npu().half() + scores = scores.npu().half() + + det_bboxes, det_labels = npu_multiclass_nms(boxes, scores) + print(det_bboxes.shape) + print(det_labels.shape) + + + print('test npu_batched_multiclass_nms') + boxes = torch.randint(1, 255, size=(4, 200, 80, 4)) + scores = torch.randn(4, 200, 81) + + torch.npu.set_device(0) + boxes = boxes.npu().half() + scores = scores.npu().half() + + det_bboxes, det_labels = npu_batched_multiclass_nms(boxes, scores) + print(det_bboxes.shape) + print(det_labels.shape) + diff --git a/PyTorch/contrib/cv/detection/SSD/scripts/eval.sh b/PyTorch/contrib/cv/detection/SSD/scripts/eval.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD/scripts/eval_1p.sh b/PyTorch/contrib/cv/detection/SSD/scripts/eval_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD/scripts/npu_set_env.sh b/PyTorch/contrib/cv/detection/SSD/scripts/npu_set_env.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD/scripts/train_1p.sh b/PyTorch/contrib/cv/detection/SSD/scripts/train_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD/scripts/train_8p.sh b/PyTorch/contrib/cv/detection/SSD/scripts/train_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD/setup.py b/PyTorch/contrib/cv/detection/SSD/setup.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD/tools/dist_test.sh b/PyTorch/contrib/cv/detection/SSD/tools/dist_test.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD/tools/dist_train.sh b/PyTorch/contrib/cv/detection/SSD/tools/dist_train.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD/tools/slurm_test.sh b/PyTorch/contrib/cv/detection/SSD/tools/slurm_test.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SSD/tools/slurm_train.sh b/PyTorch/contrib/cv/detection/SSD/tools/slurm_train.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/README_raw.md b/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/README_raw.md index e04900eef2309f7d6afb4d59c8f547f7decc294f..51554173ec816781571193ff9685371666e98d87 100644 --- a/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/README_raw.md +++ b/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/README_raw.md @@ -1,52 +1,52 @@ -# SimCLR_for_Pytorch - -This project enables the SimCLR model could be trained on NPU, and remains the similar precision compared to the results -of the GPU. - - -## Requirements - -- NPU配套的run包安装(建议安装 20.2.0.rc1 版本,请用以下脚本确认版本号,不确保其他版本能正常训练/测评) - - ```sh - ll /usr/local/Ascend/ascend-toolkit/latest - ``` - -- Python v3.7.5 -- PyTorch v1.5 (NPU版本) -- Apex (NPU版本) - - -## Training - -To train a model, run `xxx.sh` with the desired model architecture and the path to the CIFAR10 dataset: - -```bash -# training 1p accuracy -bash ./test/train_full_1p.sh --data_path=real_data_path - -# training 1p performance -bash ./test/train_performance_1p.sh --data_path=real_data_path - -# training 8p accuracy -bash ./test/train_full_8p.sh --data_path=real_data_path - -# training 8p performance -bash ./test/train_performance_8p.sh --data_path=real_data_path - -# finetuning 1p -bash test/train_finetune_1p.sh --data_path=real_data_path --pth_path=real_pre_train_model_path -``` - -Log path: - test/output/devie_id/train_${device_id}.log # training detail log - - -## SimCLR Training Results - -| Acc@1 | FPS | # of NPU/GPU | Epochs | Opt-Level | Loss Scale | -| :------: | :------: | :------: | :------: | :------: | :------: | -| ------ | 1767.030 | 1P GPU | 100 | O2 | 128.0 | -| 60.352 | 2098.001 | 1P NPU | 100 | O2 | 128.0 | -| 55.859 | 5227.504 | 8P GPU | 100 | O2 | 128.0 | -| 58.594 | 9747.414 | 8P NPU | 100 | O2 | 128.0 | +# SimCLR_for_Pytorch + +This project enables the SimCLR model could be trained on NPU, and remains the similar precision compared to the results +of the GPU. + + +## Requirements + +- NPU配套的run包安装(建议安装 20.2.0.rc1 版本,请用以下脚本确认版本号,不确保其他版本能正常训练/测评) + + ```sh + ll /usr/local/Ascend/ascend-toolkit/latest + ``` + +- Python v3.7.5 +- PyTorch v1.5 (NPU版本) +- Apex (NPU版本) + + +## Training + +To train a model, run `xxx.sh` with the desired model architecture and the path to the CIFAR10 dataset: + +```bash +# training 1p accuracy +bash ./test/train_full_1p.sh --data_path=real_data_path + +# training 1p performance +bash ./test/train_performance_1p.sh --data_path=real_data_path + +# training 8p accuracy +bash ./test/train_full_8p.sh --data_path=real_data_path + +# training 8p performance +bash ./test/train_performance_8p.sh --data_path=real_data_path + +# finetuning 1p +bash test/train_finetune_1p.sh --data_path=real_data_path --pth_path=real_pre_train_model_path +``` + +Log path: + test/output/devie_id/train_${device_id}.log # training detail log + + +## SimCLR Training Results + +| Acc@1 | FPS | # of NPU/GPU | Epochs | Opt-Level | Loss Scale | +| :------: | :------: | :------: | :------: | :------: | :------: | +| ------ | 1767.030 | 1P GPU | 100 | O2 | 128.0 | +| 60.352 | 2098.001 | 1P NPU | 100 | O2 | 128.0 | +| 55.859 | 5227.504 | 8P GPU | 100 | O2 | 128.0 | +| 58.594 | 9747.414 | 8P NPU | 100 | O2 | 128.0 | diff --git a/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/main_1p.py b/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/main_1p.py index 1152709ee94e90167a7b8a6bca1307e33886c034..4f1a016a0c2ebf80dead3933c5346f9878a01906 100644 --- a/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/main_1p.py +++ b/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/main_1p.py @@ -1,270 +1,270 @@ -"""MIT License""" -# Copyright (c) 2020 Thalles Silva -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# ============================================================================ -import time -import argparse -import torch -import torch.npu -import torch.nn.functional as F -import torch.utils.data -import torch.backends.cudnn as cudnn -from torchvision import models -from utils import accuracy -from models.resnet_simclr import ResNetSimCLR - -from apex import amp -from data_aug.contrastive_learning_dataset import ContrastiveLearningDataset -from multi_epochs_dataloader import MultiEpochsDataLoader -import apex -from apex.optimizers import NpuFusedAdam - - -torch.manual_seed(0) - -model_names = sorted(name for name in models.__dict__ - if name.islower() and not name.startswith("__") - and callable(models.__dict__[name])) - -parser = argparse.ArgumentParser(description='PyTorch SimCLR') -parser.add_argument('data', metavar='DIR', - help='path to dataset') -parser.add_argument('--dataset_name', default='cifar10', - help='dataset name', choices=['stl10', 'cifar10']) -parser.add_argument('-a', '--arch', metavar='ARCH', default='resnet18', - choices=model_names, - help='model architecture: ' + - ' | '.join(model_names) + - ' (default: resnet50)') -parser.add_argument('-j', '--workers', default=9, type=int, metavar='N', - help='number of data loading workers (default: 9)') -parser.add_argument('--epochs', default=100, type=int, metavar='N', - help='number of total epochs to run') -parser.add_argument('-b', '--batch_size', default=256, type=int, - metavar='N', - help='mini-batch size (default: 256), this is the total ' - 'batch size of all GPUs on the current node when ' - 'using Data Parallel or Distributed Data Parallel') -parser.add_argument('--lr', '--learning_rate', default=0.0003, type=float, - metavar='LR', help='initial learning rate', dest='lr') -parser.add_argument('--wd', '--weight_decay', default=1e-4, type=float, - metavar='W', help='weight decay (default: 1e-4)', - dest='weight_decay') -parser.add_argument('--out_dim', default=128, type=int, - help='feature dimension (default: 128)') -parser.add_argument('--log_every_n_steps', default=10, type=int, - help='Log every n steps') -parser.add_argument('--temperature', default=0.07, type=float, - help='softmax temperature (default: 0.07)') -parser.add_argument('--n_views', default=2, type=int, metavar='N', - help='Number of views for contrastive learning training.') -parser.add_argument('--rank', default=0, type=int, - help='node rank for distributed training') -parser.add_argument('--npu', default=0, type=int, - help='NPU id to use.') -parser.add_argument('--npus_per_node', default=1, type=int, - help='number of NPUs per node.') -parser.add_argument('--pretrained', dest='pretrained', action='store_true', - help='use pre-trained model') -parser.add_argument('--pth_path', default='', type=str, metavar='PATH', - help='path to pretrained checkpoint (default: none)') -parser.add_argument('--device_id', type=int, default=0, help="device id") - - -def main(): - print('Part1 : prepare for parameters <==> Begin') - args = parser.parse_args() - main_worker(args.npu, args.npus_per_node, args) - - -def info_nce_loss(args, features): - - labels = torch.cat([torch.arange(args.batch_size) for i in range(args.n_views)], dim=0).npu() - labels = (labels.unsqueeze(0) == labels.unsqueeze(1)).float() - labels = labels.npu() - - features = F.normalize(features, dim=1).npu() - - similarity_matrix = torch.matmul(features, features.T).npu() - - # discard the main diagonal from both: labels and similarities matrix - mask = torch.eye(labels.shape[0], dtype=torch.bool).npu() - labels = labels[~mask].view(labels.shape[0], -1).npu() - similarity_matrix = similarity_matrix[~mask].view(similarity_matrix.shape[0], -1).npu() - - # select and combine multiple positives - positives = similarity_matrix[labels.bool()].view(labels.shape[0], -1).npu() - - # select only the negatives the negatives - negatives = similarity_matrix[~labels.bool()].view(similarity_matrix.shape[0], -1).npu() - - logits = torch.cat([positives, negatives], dim=1).npu() - labels = torch.zeros(logits.shape[0], dtype=torch.long).npu() - - logits = logits / args.temperature - return logits, labels - - -def train(args, train_loader, model, criterion, optimizer, epoch_counter, npus_per_node, best_acc): - fps = AverageMeter() - - top1 = [0] - top5 = [0] - end = time.time() - for i, (images, _) in enumerate(train_loader): - images = torch.cat(images, dim=0) - images = images.npu() - - out = model(images).npu() - logits, labels = info_nce_loss(args, out) - loss = criterion(logits, labels) - optimizer.zero_grad() - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - optimizer.step() - - time_step = time.time() - end - fps.update(args.batch_size / time_step) - end = time.time() - - if i % args.log_every_n_steps == 0 and args.rank % npus_per_node == 0: - top1, top5 = accuracy(logits, labels, topk=(1, 5)) - if top1[0] > best_acc: - best_acc = top1[0] - print('Train Epoch: {0} Step: {1}/{2} Loss {loss:.4f} ' - '[AVG-ACC] * Acc@1 {top1:.3f} Acc@5 {top5:.3f} best_acc {best_acc:.3f} ' - 'LR {lr:.7f} FPS {fps:.7f}'.format( - epoch_counter, i, len(train_loader), loss=loss.item(), - top1=top1[0], top5=top5[0], best_acc=best_acc, - lr=optimizer.param_groups[0]['lr'], fps=fps.avg)) - - if (epoch_counter+1) % 5 == 0: - save_checkpoint({ - 'epoch': epoch_counter, - 'arch': model.state_dict(), - 'state_dict': model.state_dict(), - 'optimizer': optimizer.state_dict(), - }) - - -def save_checkpoint(state, filename='checkpoint.pth.tar'): - torch.save(state, filename) - - -def main_worker(npu, npus_per_node, args): - local_rank = 0 - args.npu = npu - assert args.n_views == 2, "Only two view training is supported. Please use --n-views 2." - args.rank = args.rank * npus_per_node + npu - print(args) - args.device_id = args.device_id + local_rank - print("device_id = ", args.device_id) - device = torch.device(f'npu:{args.device_id}') - torch.npu.set_device(device) - - # create model - if args.pretrained: - print("=> using pre-trained model ResNetSimCLR") - model = ResNetSimCLR(base_model=args.arch, out_dim=args.out_dim) - print("loading model of yours...") - if args.pth_path: - print("load pth you give") - pretrained_dict = torch.load(args.pth_path, map_location="cpu")["state_dict"] - else: - pretrained_dict = torch.load("./checkpoint.pth.tar", map_location="cpu")["state_dict"] - model.load_state_dict(pretrained_dict, strict=False) - else: - print("=> creating model ResNetSimCLR") - model = ResNetSimCLR(base_model=args.arch, out_dim=args.out_dim) - - print('Part1 : prepare for parameters <==> Done') - print('Part2 : Load Network <==> Begin') - - cudnn.deterministic = True - cudnn.benchmark = True - model = model.to(device) - - optimizer = NpuFusedAdam( - model.parameters(), - args.lr, - weight_decay=args.weight_decay - ) - - model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=128.0, combine_grad=True) - criterion = torch.nn.CrossEntropyLoss().to(device) - - print('Part2 : Load Network <==> Done') - print('Part3 : Load Dataset <==> Begin') - - dataset = ContrastiveLearningDataset(args.data) - train_dataset = dataset.get_dataset(args.dataset_name, args.n_views) - print(f'workers nums:{args.workers}') - print(f'device nums:{npus_per_node}') - - train_loader, train_loader_len, train_sampler = get_pytorch_train_loader(train_dataset, - args.batch_size, - workers=args.workers) - scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=len(train_loader), eta_min=0, - last_epoch=-1) - if args.rank % npus_per_node == 0: - print('Part3 : Load Dataset <==> Done') - print('Part4 : Train and Test <==> Begin') - - for epoch_counter in range(args.epochs): - best_acc = 0 - train(args, train_loader, model, criterion, optimizer, epoch_counter, npus_per_node, best_acc) - if epoch_counter >= 10: - scheduler.step() - print('Part4 : Train and Test <==> Done') - - -def get_pytorch_train_loader(train_dataset, batch_size, workers, _worker_init_fn=None): - train_sampler = None - - dataloader_fn = MultiEpochsDataLoader # torch.utils.data.DataLoader - train_loader = dataloader_fn( - train_dataset, batch_size=batch_size, shuffle=(train_sampler is None), - num_workers=workers, worker_init_fn=_worker_init_fn, pin_memory=True, sampler=train_sampler, - drop_last=True) - return train_loader, len(train_loader), train_sampler - - -class AverageMeter(object): - """Computes and stores the average and current value""" - - def __init__(self): - self.reset() - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - - def update(self, val, n=1): - self.val = val - self.sum += val * n - self.count += n - self.avg = self.sum / self.count - - -if __name__ == '__main__': - main() +"""MIT License""" +# Copyright (c) 2020 Thalles Silva +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# ============================================================================ +import time +import argparse +import torch +import torch.npu +import torch.nn.functional as F +import torch.utils.data +import torch.backends.cudnn as cudnn +from torchvision import models +from utils import accuracy +from models.resnet_simclr import ResNetSimCLR + +from apex import amp +from data_aug.contrastive_learning_dataset import ContrastiveLearningDataset +from multi_epochs_dataloader import MultiEpochsDataLoader +import apex +from apex.optimizers import NpuFusedAdam + + +torch.manual_seed(0) + +model_names = sorted(name for name in models.__dict__ + if name.islower() and not name.startswith("__") + and callable(models.__dict__[name])) + +parser = argparse.ArgumentParser(description='PyTorch SimCLR') +parser.add_argument('data', metavar='DIR', + help='path to dataset') +parser.add_argument('--dataset_name', default='cifar10', + help='dataset name', choices=['stl10', 'cifar10']) +parser.add_argument('-a', '--arch', metavar='ARCH', default='resnet18', + choices=model_names, + help='model architecture: ' + + ' | '.join(model_names) + + ' (default: resnet50)') +parser.add_argument('-j', '--workers', default=9, type=int, metavar='N', + help='number of data loading workers (default: 9)') +parser.add_argument('--epochs', default=100, type=int, metavar='N', + help='number of total epochs to run') +parser.add_argument('-b', '--batch_size', default=256, type=int, + metavar='N', + help='mini-batch size (default: 256), this is the total ' + 'batch size of all GPUs on the current node when ' + 'using Data Parallel or Distributed Data Parallel') +parser.add_argument('--lr', '--learning_rate', default=0.0003, type=float, + metavar='LR', help='initial learning rate', dest='lr') +parser.add_argument('--wd', '--weight_decay', default=1e-4, type=float, + metavar='W', help='weight decay (default: 1e-4)', + dest='weight_decay') +parser.add_argument('--out_dim', default=128, type=int, + help='feature dimension (default: 128)') +parser.add_argument('--log_every_n_steps', default=10, type=int, + help='Log every n steps') +parser.add_argument('--temperature', default=0.07, type=float, + help='softmax temperature (default: 0.07)') +parser.add_argument('--n_views', default=2, type=int, metavar='N', + help='Number of views for contrastive learning training.') +parser.add_argument('--rank', default=0, type=int, + help='node rank for distributed training') +parser.add_argument('--npu', default=0, type=int, + help='NPU id to use.') +parser.add_argument('--npus_per_node', default=1, type=int, + help='number of NPUs per node.') +parser.add_argument('--pretrained', dest='pretrained', action='store_true', + help='use pre-trained model') +parser.add_argument('--pth_path', default='', type=str, metavar='PATH', + help='path to pretrained checkpoint (default: none)') +parser.add_argument('--device_id', type=int, default=0, help="device id") + + +def main(): + print('Part1 : prepare for parameters <==> Begin') + args = parser.parse_args() + main_worker(args.npu, args.npus_per_node, args) + + +def info_nce_loss(args, features): + + labels = torch.cat([torch.arange(args.batch_size) for i in range(args.n_views)], dim=0).npu() + labels = (labels.unsqueeze(0) == labels.unsqueeze(1)).float() + labels = labels.npu() + + features = F.normalize(features, dim=1).npu() + + similarity_matrix = torch.matmul(features, features.T).npu() + + # discard the main diagonal from both: labels and similarities matrix + mask = torch.eye(labels.shape[0], dtype=torch.bool).npu() + labels = labels[~mask].view(labels.shape[0], -1).npu() + similarity_matrix = similarity_matrix[~mask].view(similarity_matrix.shape[0], -1).npu() + + # select and combine multiple positives + positives = similarity_matrix[labels.bool()].view(labels.shape[0], -1).npu() + + # select only the negatives the negatives + negatives = similarity_matrix[~labels.bool()].view(similarity_matrix.shape[0], -1).npu() + + logits = torch.cat([positives, negatives], dim=1).npu() + labels = torch.zeros(logits.shape[0], dtype=torch.long).npu() + + logits = logits / args.temperature + return logits, labels + + +def train(args, train_loader, model, criterion, optimizer, epoch_counter, npus_per_node, best_acc): + fps = AverageMeter() + + top1 = [0] + top5 = [0] + end = time.time() + for i, (images, _) in enumerate(train_loader): + images = torch.cat(images, dim=0) + images = images.npu() + + out = model(images).npu() + logits, labels = info_nce_loss(args, out) + loss = criterion(logits, labels) + optimizer.zero_grad() + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + optimizer.step() + + time_step = time.time() - end + fps.update(args.batch_size / time_step) + end = time.time() + + if i % args.log_every_n_steps == 0 and args.rank % npus_per_node == 0: + top1, top5 = accuracy(logits, labels, topk=(1, 5)) + if top1[0] > best_acc: + best_acc = top1[0] + print('Train Epoch: {0} Step: {1}/{2} Loss {loss:.4f} ' + '[AVG-ACC] * Acc@1 {top1:.3f} Acc@5 {top5:.3f} best_acc {best_acc:.3f} ' + 'LR {lr:.7f} FPS {fps:.7f}'.format( + epoch_counter, i, len(train_loader), loss=loss.item(), + top1=top1[0], top5=top5[0], best_acc=best_acc, + lr=optimizer.param_groups[0]['lr'], fps=fps.avg)) + + if (epoch_counter+1) % 5 == 0: + save_checkpoint({ + 'epoch': epoch_counter, + 'arch': model.state_dict(), + 'state_dict': model.state_dict(), + 'optimizer': optimizer.state_dict(), + }) + + +def save_checkpoint(state, filename='checkpoint.pth.tar'): + torch.save(state, filename) + + +def main_worker(npu, npus_per_node, args): + local_rank = 0 + args.npu = npu + assert args.n_views == 2, "Only two view training is supported. Please use --n-views 2." + args.rank = args.rank * npus_per_node + npu + print(args) + args.device_id = args.device_id + local_rank + print("device_id = ", args.device_id) + device = torch.device(f'npu:{args.device_id}') + torch.npu.set_device(device) + + # create model + if args.pretrained: + print("=> using pre-trained model ResNetSimCLR") + model = ResNetSimCLR(base_model=args.arch, out_dim=args.out_dim) + print("loading model of yours...") + if args.pth_path: + print("load pth you give") + pretrained_dict = torch.load(args.pth_path, map_location="cpu")["state_dict"] + else: + pretrained_dict = torch.load("./checkpoint.pth.tar", map_location="cpu")["state_dict"] + model.load_state_dict(pretrained_dict, strict=False) + else: + print("=> creating model ResNetSimCLR") + model = ResNetSimCLR(base_model=args.arch, out_dim=args.out_dim) + + print('Part1 : prepare for parameters <==> Done') + print('Part2 : Load Network <==> Begin') + + cudnn.deterministic = True + cudnn.benchmark = True + model = model.to(device) + + optimizer = NpuFusedAdam( + model.parameters(), + args.lr, + weight_decay=args.weight_decay + ) + + model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=128.0, combine_grad=True) + criterion = torch.nn.CrossEntropyLoss().to(device) + + print('Part2 : Load Network <==> Done') + print('Part3 : Load Dataset <==> Begin') + + dataset = ContrastiveLearningDataset(args.data) + train_dataset = dataset.get_dataset(args.dataset_name, args.n_views) + print(f'workers nums:{args.workers}') + print(f'device nums:{npus_per_node}') + + train_loader, train_loader_len, train_sampler = get_pytorch_train_loader(train_dataset, + args.batch_size, + workers=args.workers) + scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=len(train_loader), eta_min=0, + last_epoch=-1) + if args.rank % npus_per_node == 0: + print('Part3 : Load Dataset <==> Done') + print('Part4 : Train and Test <==> Begin') + + for epoch_counter in range(args.epochs): + best_acc = 0 + train(args, train_loader, model, criterion, optimizer, epoch_counter, npus_per_node, best_acc) + if epoch_counter >= 10: + scheduler.step() + print('Part4 : Train and Test <==> Done') + + +def get_pytorch_train_loader(train_dataset, batch_size, workers, _worker_init_fn=None): + train_sampler = None + + dataloader_fn = MultiEpochsDataLoader # torch.utils.data.DataLoader + train_loader = dataloader_fn( + train_dataset, batch_size=batch_size, shuffle=(train_sampler is None), + num_workers=workers, worker_init_fn=_worker_init_fn, pin_memory=True, sampler=train_sampler, + drop_last=True) + return train_loader, len(train_loader), train_sampler + + +class AverageMeter(object): + """Computes and stores the average and current value""" + + def __init__(self): + self.reset() + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + self.val = val + self.sum += val * n + self.count += n + self.avg = self.sum / self.count + + +if __name__ == '__main__': + main() diff --git a/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/main_8p.py b/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/main_8p.py index 3f93c0d9ef883024ea2a0548765c06055915fd04..81952e8a491b536c6d1c322543516ed7d6f02802 100644 --- a/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/main_8p.py +++ b/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/main_8p.py @@ -1,330 +1,330 @@ -"""MIT License""" -# Copyright (c) 2020 Thalles Silva -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# ============================================================================ -import os -import time -import argparse -import torch -import torch.npu -import torch.nn.functional as F -import torch.multiprocessing as mp -import torch.backends.cudnn as cudnn -from torchvision import models -from utils import accuracy -from models.resnet_simclr import ResNetSimCLR - -from apex import amp -from data_aug.contrastive_learning_dataset import ContrastiveLearningDataset -from multi_epochs_dataloader import MultiEpochsDataLoader -import apex -from apex.optimizers import NpuFusedAdam -import socket - -torch.manual_seed(0) - -model_names = sorted(name for name in models.__dict__ - if name.islower() and not name.startswith("__") - and callable(models.__dict__[name])) - -parser = argparse.ArgumentParser(description='PyTorch SimCLR') -parser.add_argument('data', metavar='DIR', - help='path to dataset') -parser.add_argument('--dataset_name', default='cifar10', - help='dataset name', choices=['stl10', 'cifar10']) -parser.add_argument('-a', '--arch', metavar='ARCH', default='resnet18', - choices=model_names, - help='model architecture: ' + - ' | '.join(model_names) + - ' (default: resnet50)') -parser.add_argument('-j', '--workers', default=9, type=int, metavar='N', - help='number of data loading workers (default: 9)') -parser.add_argument('--epochs', default=100, type=int, metavar='N', - help='number of total epochs to run') -parser.add_argument('-b', '--batch_size', default=256, type=int, - metavar='N', - help='mini-batch size (default: 256), this is the total ' - 'batch size of all GPUs on the current node when ' - 'using Data Parallel or Distributed Data Parallel') -parser.add_argument('--lr', '--learning_rate', default=0.0012, type=float, - metavar='LR', help='initial learning rate', dest='lr') -parser.add_argument('--wd', '--weight_decay', default=1e-4, type=float, - metavar='W', help='weight decay (default: 1e-4)', - dest='weight_decay') -parser.add_argument('--out_dim', default=128, type=int, - help='feature dimension (default: 128)') -parser.add_argument('--log_every_n_steps', default=10, type=int, - help='Log every n steps') -parser.add_argument('--temperature', default=0.07, type=float, - help='softmax temperature (default: 0.07)') -parser.add_argument('--n_views', default=2, type=int, metavar='N', - help='Number of views for contrastive learning training.') -parser.add_argument('--rank', default=0, type=int, - help='node rank for distributed training') -parser.add_argument('--npu', default=0, type=int, - help='NPU id to use.') -parser.add_argument('--pretrained', dest='pretrained', action='store_true', - help='use pre-trained model') -parser.add_argument('--pth_path', default='', type=str, metavar='PATH', - help='path to pretrained checkpoint (default: none)') -parser.add_argument('--distributed', action='store_true', - help='Use multi-processing distributed training to launch ' - 'N processes per node, which has N GPUs.') -parser.add_argument('--nodes', type=int, default=1) -parser.add_argument('--device_id', type=int, default=0, help="device id") -parser.add_argument('--device_list', type=str, default="0,1,2,3,4,5,6,7", help="device id list") - - -def get_host_ip(): - """ - 查询本机ip地址 - :return: ip - """ - try: - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - s.connect(('8.8.8.8', 80)) - ip = s.getsockname()[0] - finally: - s.close() - - return ip - - -def device_id_to_process_device_map(device_list): - devices = device_list.split(",") - devices = [int(x) for x in devices] - devices.sort() - - process_device_map = dict() - for process_id, device_id in enumerate(devices): - process_device_map[process_id] = device_id - - return process_device_map - - -def main(): - print('Part1 : prepare for parameters <==> Begin') - args = parser.parse_args() - os.environ["MASTER_ADDR"] = get_host_ip() - os.environ["MASTER_PORT"] = "29688" - args.process_device_map = device_id_to_process_device_map(args.device_list) - if args.device_list != '': - npus_per_node = len(args.device_list.split(',')) - elif args.device_num != -1: - npus_per_node = args.device_num - elif args.device == 'npu': - npus_per_node = torch.npu.device_count() - else: - npus_per_node = torch.cuda.device_count() - - print('npus_per_node:', npus_per_node) - - if args.distributed: - mp.spawn(main_worker, nprocs=npus_per_node, args=(npus_per_node, args)) - else: - # Simply call main_worker function - main_worker(args.npu, npus_per_node, args) - - -def main_worker(npu, npus_per_node, args): - local_rank = 0 - args.npu = args.process_device_map[npu] - if args.distributed: - args.rank = args.rank * npus_per_node + npu - torch.distributed.init_process_group(backend="hccl", - world_size=args.nodes * npus_per_node, - rank=args.rank) - local_rank = torch.distributed.get_rank() - args.is_master_node = not args.distributed or local_rank == 0 - if args.is_master_node: - print(args) - args.device_id = args.device_id + local_rank - print("device_id = ", args.device_id) - device = torch.device(f'npu:{args.device_id}') - torch.npu.set_device(device) - - # create model - if args.pretrained: - print("=> using pre-trained model ResNetSimCLR") - model = ResNetSimCLR(base_model=args.arch, out_dim=args.out_dim) - print("loading model of yours...") - if args.pth_path: - print("load pth you give") - pretrained_dict = torch.load(args.pth_path, map_location="cpu")["state_dict"] - else: - pretrained_dict = torch.load("./checkpoint.pth.tar", map_location="cpu")["state_dict"] - model.load_state_dict(pretrained_dict, strict=False) - else: - print("=> creating model ResNetSimCLR") - model = ResNetSimCLR(base_model=args.arch, out_dim=args.out_dim) - - print('rank', args.rank, ' using npu...') - if args.rank % npus_per_node == 0: - print('Part1 : prepare for parameters <==> Done') - print('Part2 : Load Network <==> Begin') - - cudnn.deterministic = True - cudnn.benchmark = True - model = model.to(device) - optimizer = NpuFusedAdam( - model.parameters(), - args.lr, - weight_decay=args.weight_decay - ) - model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=128.0, combine_grad=True) - if args.distributed: - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[local_rank], - broadcast_buffers=False) - criterion = torch.nn.CrossEntropyLoss().to(device) - - if args.rank % npus_per_node == 0: - print('Part2 : Load Network <==> Done') - print('Part3 : Load Dataset <==> Begin') - - dataset = ContrastiveLearningDataset(args.data) - train_dataset = dataset.get_dataset(args.dataset_name, args.n_views) - print(f'workers nums:{args.workers}') - print(f'device nums:{npus_per_node}') - - train_loader, train_loader_len, train_sampler = get_pytorch_train_loader(train_dataset, - args.batch_size, - workers=args.workers) - scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=len(train_loader), eta_min=0, - last_epoch=-1) - if args.rank % npus_per_node == 0: - print('Part3 : Load Dataset <==> Done') - print('Part4 : Train and Test <==> Begin') - - for epoch_counter in range(args.epochs): - if args.distributed: - train_sampler.set_epoch(epoch_counter) - best_acc = 0 - train(args, train_loader, model, criterion, optimizer, epoch_counter, npus_per_node, best_acc) - if epoch_counter >= 10: - scheduler.step() - print('Part4 : Train and Test <==> Done') - - -def info_nce_loss(args, features): - labels = torch.cat([torch.arange(args.batch_size) for i in range(args.n_views)], dim=0) - labels = (labels.unsqueeze(0) == labels.unsqueeze(1)).float() - labels = labels.npu() - features = F.normalize(features, dim=1) - similarity_matrix = torch.matmul(features, features.T) - - # discard the main diagonal from both: labels and similarities matrix - mask = torch.eye(labels.shape[0], dtype=torch.bool).npu() - labels = labels[~mask].view(labels.shape[0], -1) - similarity_matrix = similarity_matrix[~mask].view(similarity_matrix.shape[0], -1) - - # select and combine multiple positives - positives = similarity_matrix[labels.bool()].view(labels.shape[0], -1) - - # select only the negatives the negatives - negatives = similarity_matrix[~labels.bool()].view(similarity_matrix.shape[0], -1) - - logits = torch.cat([positives, negatives], dim=1) - labels = torch.zeros(logits.shape[0], dtype=torch.long).npu() - logits = logits / args.temperature - return logits, labels - - -def train(args, train_loader, model, criterion, optimizer, epoch_counter, npus_per_node, best_acc): - fps = AverageMeter() - - top1 = [0] - top5 = [0] - - end = time.time() - for i, (images, _) in enumerate(train_loader): - images = torch.cat(images, dim=0) - images = images.npu() - - out = model(images) - logits, labels = info_nce_loss(args, out) - loss = criterion(logits, labels) - optimizer.zero_grad() - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - optimizer.step() - - time_step = time.time() - end - fps.update(args.batch_size * npus_per_node / time_step) - torch.npu.synchronize() - end = time.time() - - if i % args.log_every_n_steps == 0 and args.is_master_node: - top1, top5 = accuracy(logits, labels, topk=(1, 5)) - if top1[0] > best_acc: - best_acc = top1[0] - - print('Train Epoch: {0} Step: {1}/{2} Loss {loss:.4f} Time {time:.4f}' - '[AVG-ACC] * Acc@1 {top1:.3f} Acc@5 {top5:.3f} best_acc {best_acc:.3f} ' - 'LR {lr:.7f} FPS {fps:.7f} '.format( - epoch_counter, i, len(train_loader), loss=loss.item(), time=time_step, - top1=top1[0], top5=top5[0], best_acc=best_acc, - lr=optimizer.param_groups[0]['lr'], fps=fps.avg)) - - if (epoch_counter+1) % 5 == 0: - save_checkpoint({ - 'epoch': epoch_counter, - 'arch': model.state_dict(), - 'state_dict': model.state_dict(), - 'optimizer': optimizer.state_dict(), - }) - - -def save_checkpoint(state, filename='checkpoint.pth.tar'): - torch.save(state, filename) - - -def get_pytorch_train_loader(train_dataset, batch_size, workers, _worker_init_fn=None): - train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) - - dataloader_fn = MultiEpochsDataLoader # torch.utils.data.DataLoader - train_loader = dataloader_fn( - train_dataset, batch_size=batch_size, shuffle=(train_sampler is None), - num_workers=workers, worker_init_fn=_worker_init_fn, pin_memory=False, sampler=train_sampler, - drop_last=True) - return train_loader, len(train_loader), train_sampler - - -class AverageMeter(object): - """Computes and stores the average and current value""" - - def __init__(self): - self.reset() - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - - def update(self, val, n=1): - self.val = val - self.sum += val * n - self.count += n - self.avg = self.sum / self.count - - -if __name__ == '__main__': - main() +"""MIT License""" +# Copyright (c) 2020 Thalles Silva +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# ============================================================================ +import os +import time +import argparse +import torch +import torch.npu +import torch.nn.functional as F +import torch.multiprocessing as mp +import torch.backends.cudnn as cudnn +from torchvision import models +from utils import accuracy +from models.resnet_simclr import ResNetSimCLR + +from apex import amp +from data_aug.contrastive_learning_dataset import ContrastiveLearningDataset +from multi_epochs_dataloader import MultiEpochsDataLoader +import apex +from apex.optimizers import NpuFusedAdam +import socket + +torch.manual_seed(0) + +model_names = sorted(name for name in models.__dict__ + if name.islower() and not name.startswith("__") + and callable(models.__dict__[name])) + +parser = argparse.ArgumentParser(description='PyTorch SimCLR') +parser.add_argument('data', metavar='DIR', + help='path to dataset') +parser.add_argument('--dataset_name', default='cifar10', + help='dataset name', choices=['stl10', 'cifar10']) +parser.add_argument('-a', '--arch', metavar='ARCH', default='resnet18', + choices=model_names, + help='model architecture: ' + + ' | '.join(model_names) + + ' (default: resnet50)') +parser.add_argument('-j', '--workers', default=9, type=int, metavar='N', + help='number of data loading workers (default: 9)') +parser.add_argument('--epochs', default=100, type=int, metavar='N', + help='number of total epochs to run') +parser.add_argument('-b', '--batch_size', default=256, type=int, + metavar='N', + help='mini-batch size (default: 256), this is the total ' + 'batch size of all GPUs on the current node when ' + 'using Data Parallel or Distributed Data Parallel') +parser.add_argument('--lr', '--learning_rate', default=0.0012, type=float, + metavar='LR', help='initial learning rate', dest='lr') +parser.add_argument('--wd', '--weight_decay', default=1e-4, type=float, + metavar='W', help='weight decay (default: 1e-4)', + dest='weight_decay') +parser.add_argument('--out_dim', default=128, type=int, + help='feature dimension (default: 128)') +parser.add_argument('--log_every_n_steps', default=10, type=int, + help='Log every n steps') +parser.add_argument('--temperature', default=0.07, type=float, + help='softmax temperature (default: 0.07)') +parser.add_argument('--n_views', default=2, type=int, metavar='N', + help='Number of views for contrastive learning training.') +parser.add_argument('--rank', default=0, type=int, + help='node rank for distributed training') +parser.add_argument('--npu', default=0, type=int, + help='NPU id to use.') +parser.add_argument('--pretrained', dest='pretrained', action='store_true', + help='use pre-trained model') +parser.add_argument('--pth_path', default='', type=str, metavar='PATH', + help='path to pretrained checkpoint (default: none)') +parser.add_argument('--distributed', action='store_true', + help='Use multi-processing distributed training to launch ' + 'N processes per node, which has N GPUs.') +parser.add_argument('--nodes', type=int, default=1) +parser.add_argument('--device_id', type=int, default=0, help="device id") +parser.add_argument('--device_list', type=str, default="0,1,2,3,4,5,6,7", help="device id list") + + +def get_host_ip(): + """ + 查询本机ip地址 + :return: ip + """ + try: + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.connect(('8.8.8.8', 80)) + ip = s.getsockname()[0] + finally: + s.close() + + return ip + + +def device_id_to_process_device_map(device_list): + devices = device_list.split(",") + devices = [int(x) for x in devices] + devices.sort() + + process_device_map = dict() + for process_id, device_id in enumerate(devices): + process_device_map[process_id] = device_id + + return process_device_map + + +def main(): + print('Part1 : prepare for parameters <==> Begin') + args = parser.parse_args() + os.environ["MASTER_ADDR"] = get_host_ip() + os.environ["MASTER_PORT"] = "29688" + args.process_device_map = device_id_to_process_device_map(args.device_list) + if args.device_list != '': + npus_per_node = len(args.device_list.split(',')) + elif args.device_num != -1: + npus_per_node = args.device_num + elif args.device == 'npu': + npus_per_node = torch.npu.device_count() + else: + npus_per_node = torch.cuda.device_count() + + print('npus_per_node:', npus_per_node) + + if args.distributed: + mp.spawn(main_worker, nprocs=npus_per_node, args=(npus_per_node, args)) + else: + # Simply call main_worker function + main_worker(args.npu, npus_per_node, args) + + +def main_worker(npu, npus_per_node, args): + local_rank = 0 + args.npu = args.process_device_map[npu] + if args.distributed: + args.rank = args.rank * npus_per_node + npu + torch.distributed.init_process_group(backend="hccl", + world_size=args.nodes * npus_per_node, + rank=args.rank) + local_rank = torch.distributed.get_rank() + args.is_master_node = not args.distributed or local_rank == 0 + if args.is_master_node: + print(args) + args.device_id = args.device_id + local_rank + print("device_id = ", args.device_id) + device = torch.device(f'npu:{args.device_id}') + torch.npu.set_device(device) + + # create model + if args.pretrained: + print("=> using pre-trained model ResNetSimCLR") + model = ResNetSimCLR(base_model=args.arch, out_dim=args.out_dim) + print("loading model of yours...") + if args.pth_path: + print("load pth you give") + pretrained_dict = torch.load(args.pth_path, map_location="cpu")["state_dict"] + else: + pretrained_dict = torch.load("./checkpoint.pth.tar", map_location="cpu")["state_dict"] + model.load_state_dict(pretrained_dict, strict=False) + else: + print("=> creating model ResNetSimCLR") + model = ResNetSimCLR(base_model=args.arch, out_dim=args.out_dim) + + print('rank', args.rank, ' using npu...') + if args.rank % npus_per_node == 0: + print('Part1 : prepare for parameters <==> Done') + print('Part2 : Load Network <==> Begin') + + cudnn.deterministic = True + cudnn.benchmark = True + model = model.to(device) + optimizer = NpuFusedAdam( + model.parameters(), + args.lr, + weight_decay=args.weight_decay + ) + model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=128.0, combine_grad=True) + if args.distributed: + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[local_rank], + broadcast_buffers=False) + criterion = torch.nn.CrossEntropyLoss().to(device) + + if args.rank % npus_per_node == 0: + print('Part2 : Load Network <==> Done') + print('Part3 : Load Dataset <==> Begin') + + dataset = ContrastiveLearningDataset(args.data) + train_dataset = dataset.get_dataset(args.dataset_name, args.n_views) + print(f'workers nums:{args.workers}') + print(f'device nums:{npus_per_node}') + + train_loader, train_loader_len, train_sampler = get_pytorch_train_loader(train_dataset, + args.batch_size, + workers=args.workers) + scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=len(train_loader), eta_min=0, + last_epoch=-1) + if args.rank % npus_per_node == 0: + print('Part3 : Load Dataset <==> Done') + print('Part4 : Train and Test <==> Begin') + + for epoch_counter in range(args.epochs): + if args.distributed: + train_sampler.set_epoch(epoch_counter) + best_acc = 0 + train(args, train_loader, model, criterion, optimizer, epoch_counter, npus_per_node, best_acc) + if epoch_counter >= 10: + scheduler.step() + print('Part4 : Train and Test <==> Done') + + +def info_nce_loss(args, features): + labels = torch.cat([torch.arange(args.batch_size) for i in range(args.n_views)], dim=0) + labels = (labels.unsqueeze(0) == labels.unsqueeze(1)).float() + labels = labels.npu() + features = F.normalize(features, dim=1) + similarity_matrix = torch.matmul(features, features.T) + + # discard the main diagonal from both: labels and similarities matrix + mask = torch.eye(labels.shape[0], dtype=torch.bool).npu() + labels = labels[~mask].view(labels.shape[0], -1) + similarity_matrix = similarity_matrix[~mask].view(similarity_matrix.shape[0], -1) + + # select and combine multiple positives + positives = similarity_matrix[labels.bool()].view(labels.shape[0], -1) + + # select only the negatives the negatives + negatives = similarity_matrix[~labels.bool()].view(similarity_matrix.shape[0], -1) + + logits = torch.cat([positives, negatives], dim=1) + labels = torch.zeros(logits.shape[0], dtype=torch.long).npu() + logits = logits / args.temperature + return logits, labels + + +def train(args, train_loader, model, criterion, optimizer, epoch_counter, npus_per_node, best_acc): + fps = AverageMeter() + + top1 = [0] + top5 = [0] + + end = time.time() + for i, (images, _) in enumerate(train_loader): + images = torch.cat(images, dim=0) + images = images.npu() + + out = model(images) + logits, labels = info_nce_loss(args, out) + loss = criterion(logits, labels) + optimizer.zero_grad() + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + optimizer.step() + + time_step = time.time() - end + fps.update(args.batch_size * npus_per_node / time_step) + torch.npu.synchronize() + end = time.time() + + if i % args.log_every_n_steps == 0 and args.is_master_node: + top1, top5 = accuracy(logits, labels, topk=(1, 5)) + if top1[0] > best_acc: + best_acc = top1[0] + + print('Train Epoch: {0} Step: {1}/{2} Loss {loss:.4f} Time {time:.4f}' + '[AVG-ACC] * Acc@1 {top1:.3f} Acc@5 {top5:.3f} best_acc {best_acc:.3f} ' + 'LR {lr:.7f} FPS {fps:.7f} '.format( + epoch_counter, i, len(train_loader), loss=loss.item(), time=time_step, + top1=top1[0], top5=top5[0], best_acc=best_acc, + lr=optimizer.param_groups[0]['lr'], fps=fps.avg)) + + if (epoch_counter+1) % 5 == 0: + save_checkpoint({ + 'epoch': epoch_counter, + 'arch': model.state_dict(), + 'state_dict': model.state_dict(), + 'optimizer': optimizer.state_dict(), + }) + + +def save_checkpoint(state, filename='checkpoint.pth.tar'): + torch.save(state, filename) + + +def get_pytorch_train_loader(train_dataset, batch_size, workers, _worker_init_fn=None): + train_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) + + dataloader_fn = MultiEpochsDataLoader # torch.utils.data.DataLoader + train_loader = dataloader_fn( + train_dataset, batch_size=batch_size, shuffle=(train_sampler is None), + num_workers=workers, worker_init_fn=_worker_init_fn, pin_memory=False, sampler=train_sampler, + drop_last=True) + return train_loader, len(train_loader), train_sampler + + +class AverageMeter(object): + """Computes and stores the average and current value""" + + def __init__(self): + self.reset() + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + self.val = val + self.sum += val * n + self.count += n + self.avg = self.sum / self.count + + +if __name__ == '__main__': + main() diff --git a/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/modelzoo_level.txt b/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/modelzoo_level.txt index 5b3e2194dbccbe34708e1e09ed7cb8b6f0a81796..13f1a4a78a9b6dad37a3a150f11efe1ec094bbee 100644 --- a/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/modelzoo_level.txt @@ -1,8 +1,8 @@ -GPUStatus:OK -NPUMigrationStatus:POK -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK -PerfStatus:PERFECT -ModelConvert:NOK +GPUStatus:OK +NPUMigrationStatus:POK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK +PerfStatus:PERFECT +ModelConvert:NOK QuantStatus:NOK \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/multi_epochs_dataloader.py b/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/multi_epochs_dataloader.py index 49b9ae910a987752af23c44d4235d54e1a74334d..256ccca3c96ab7e44d267217f714a3b8d7228522 100644 --- a/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/multi_epochs_dataloader.py +++ b/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch/multi_epochs_dataloader.py @@ -1,46 +1,46 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import torch - - -class MultiEpochsDataLoader(torch.utils.data.DataLoader): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self._DataLoader__initialized = False - self.batch_sampler = _RepeatSampler(self.batch_sampler) - self._DataLoader__initialized = True - self.iterator = super().__iter__() - - def __len__(self): - return len(self.batch_sampler.sampler) - - def __iter__(self): - for _ in range(len(self)): - yield next(self.iterator) - - -class _RepeatSampler(object): - """ Sampler that repeats forever. - Args: - sampler (Sampler) - """ - - def __init__(self, sampler): - self.sampler = sampler - - def __iter__(self): - while True: - yield from iter(self.sampler) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import torch + + +class MultiEpochsDataLoader(torch.utils.data.DataLoader): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self._DataLoader__initialized = False + self.batch_sampler = _RepeatSampler(self.batch_sampler) + self._DataLoader__initialized = True + self.iterator = super().__iter__() + + def __len__(self): + return len(self.batch_sampler.sampler) + + def __iter__(self): + for _ in range(len(self)): + yield next(self.iterator) + + +class _RepeatSampler(object): + """ Sampler that repeats forever. + Args: + sampler (Sampler) + """ + + def __init__(self, sampler): + self.sampler = sampler + + def __iter__(self): + while True: + yield from iter(self.sampler) diff --git a/PyTorch/contrib/cv/detection/StyleGAN2-ADA/README.md b/PyTorch/contrib/cv/detection/StyleGAN2-ADA/README.md index e6570405aeb0b1afc70e2f81fa99b3afea489b0c..60eeb9406cb55b01595b669dfa51767c550e19c1 100644 --- a/PyTorch/contrib/cv/detection/StyleGAN2-ADA/README.md +++ b/PyTorch/contrib/cv/detection/StyleGAN2-ADA/README.md @@ -1,64 +1,64 @@ -# Stylegan2-ADA-Pytorch模型PyTorch离线推理指导 - -## 1 环境准备 - -1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 - -``` -pip install -r requirements.txt -``` - - -2.获取,修改与安装开源模型代码 - -``` -(torch 1.7.0以上版本)git clone https://github.com/NVlabs/stylegan2-ada-pytorch.git model -(torch 1.5.0)git clone https://github.com/Hypersus/utils-for-stylegan2-ada-pytorch.git model -``` - - -3.获取权重文件 - -将权重文件G_ema_bs8_8p_kimg1000.pkl放到当前工作目录 - -4.数据集 -执行`python stylegan2-ada-pytorch_preprocess.py`,默认生成`batch_size=1`的一条输入,保存在`./input`目录下 - - - -5.获取msame工具 -将msame放到当前工作目录 - - - -## 2 离线推理 - -310上执行,执行时使npu-smi info查看设备状态,确保device空闲 - -``` -bash test/pth2om.sh -bash test/eval_acc_perf.sh -``` - **评测结果:** - -bs1在310上推理的性能 - -``` -Inference average time : 207.61 ms -Inference average time without first time: 207.59 ms -``` - -bs1 310单卡吞吐率:1000/(207.61/4)=19.27fps - -bs1在T4上推理的性能 - -``` -Inference average time : 317.90 ms -``` - - - -| 模型 | T4性能 | 310性能 | -| :-----------------------: | :------: | :------: | -| stylegan2-ada-pytorch bs1 | 12.58fps | 19.27fps | - +# Stylegan2-ADA-Pytorch模型PyTorch离线推理指导 + +## 1 环境准备 + +1.安装必要的依赖,测试环境可能已经安装其中的一些不同版本的库了,故手动测试时不推荐使用该命令安装 + +``` +pip install -r requirements.txt +``` + + +2.获取,修改与安装开源模型代码 + +``` +(torch 1.7.0以上版本)git clone https://github.com/NVlabs/stylegan2-ada-pytorch.git model +(torch 1.5.0)git clone https://github.com/Hypersus/utils-for-stylegan2-ada-pytorch.git model +``` + + +3.获取权重文件 + +将权重文件G_ema_bs8_8p_kimg1000.pkl放到当前工作目录 + +4.数据集 +执行`python stylegan2-ada-pytorch_preprocess.py`,默认生成`batch_size=1`的一条输入,保存在`./input`目录下 + + + +5.获取msame工具 +将msame放到当前工作目录 + + + +## 2 离线推理 + +310上执行,执行时使npu-smi info查看设备状态,确保device空闲 + +``` +bash test/pth2om.sh +bash test/eval_acc_perf.sh +``` + **评测结果:** + +bs1在310上推理的性能 + +``` +Inference average time : 207.61 ms +Inference average time without first time: 207.59 ms +``` + +bs1 310单卡吞吐率:1000/(207.61/4)=19.27fps + +bs1在T4上推理的性能 + +``` +Inference average time : 317.90 ms +``` + + + +| 模型 | T4性能 | 310性能 | +| :-----------------------: | :------: | :------: | +| stylegan2-ada-pytorch bs1 | 12.58fps | 19.27fps | + diff --git a/PyTorch/contrib/cv/detection/StyleGAN2-ADA/perf_gpu.py b/PyTorch/contrib/cv/detection/StyleGAN2-ADA/perf_gpu.py index 58c4ecd8b1dd43d487c06d8ebd25c028f5bb3ad7..cfb3a59f73596b0a3fc5678b2e09fa933987056d 100644 --- a/PyTorch/contrib/cv/detection/StyleGAN2-ADA/perf_gpu.py +++ b/PyTorch/contrib/cv/detection/StyleGAN2-ADA/perf_gpu.py @@ -1,122 +1,122 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the License); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - -import os -import sys -import time - -sys.path.append('./model') -import numpy as np -import torch -import pickle -import argparse -import PIL.Image -import functools - - -def save_image_grid(img, fname, drange, grid_size): - lo, hi = drange - img = np.asarray(img, dtype=np.float32) - img = (img - lo) * (255 / (hi - lo)) - img = np.rint(img).clip(0, 255).astype(np.uint8) - - gw, gh = grid_size - _N, C, H, W = img.shape - img = img.reshape(gh, gw, C, H, W) - img = img.transpose(0, 3, 1, 4, 2) - img = img.reshape(gh * H, gw * W, C) - - assert C in [1, 3] - if C == 1: - PIL.Image.fromarray(img[:, :, 0], 'L').save(fname) - if C == 3: - PIL.Image.fromarray(img, 'RGB').save(fname) - - -def main(args): - pkl_file = args.pkl_file - bs = args.batch_size - input_path = args.input_path - image_path = args.image_path - device = 'cuda:0' if torch.cuda.is_available() else 'cpu' - - grid_size = (1, 1) - input_path = os.path.join(input_path, 'bs{}'.format(bs)) - input_files = os.listdir(input_path) - input_files.sort() - image_path = os.path.join(image_path, 'bs{}_pkl'.format(bs)) - os.makedirs(image_path, exist_ok=True) - # load model - start = time.time() - with open(pkl_file, 'rb') as f: - G = pickle.load(f)['G_ema'].to(device) - - G.forward = functools.partial(G.forward, force_fp32=True) - for i in range(len(input_files)): - input_file = input_files[i] - input_file = os.path.join(input_path, input_file) - input_file = np.fromfile(input_file, dtype=np.float32) - z = torch.tensor(input_file).reshape(-1, G.z_dim).to(device) - c = torch.empty(bs, 0).to(device) - image = G(z, c) - image = image.reshape(-1, 3, 512, 512) - image = image.cpu() - save_image_grid(image, os.path.join(image_path, f'gen_image_{i:04d}') + '.png', drange=[-1, 1], - grid_size=grid_size) - - end = time.time() - print(f'Inference average time : {((end - start) * 1000 / len(input_files)):.2f} ms') - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--pkl_file', type=str, default='./G_ema_bs8_8p_kimg1000.pkl') - parser.add_argument('--input_path', type=str, default='./input') - parser.add_argument('--image_path', type=str, default='./results') - parser.add_argument('--batch_size', type=int, default=1) - args = parser.parse_args() - - main(args) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the License); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + +import os +import sys +import time + +sys.path.append('./model') +import numpy as np +import torch +import pickle +import argparse +import PIL.Image +import functools + + +def save_image_grid(img, fname, drange, grid_size): + lo, hi = drange + img = np.asarray(img, dtype=np.float32) + img = (img - lo) * (255 / (hi - lo)) + img = np.rint(img).clip(0, 255).astype(np.uint8) + + gw, gh = grid_size + _N, C, H, W = img.shape + img = img.reshape(gh, gw, C, H, W) + img = img.transpose(0, 3, 1, 4, 2) + img = img.reshape(gh * H, gw * W, C) + + assert C in [1, 3] + if C == 1: + PIL.Image.fromarray(img[:, :, 0], 'L').save(fname) + if C == 3: + PIL.Image.fromarray(img, 'RGB').save(fname) + + +def main(args): + pkl_file = args.pkl_file + bs = args.batch_size + input_path = args.input_path + image_path = args.image_path + device = 'cuda:0' if torch.cuda.is_available() else 'cpu' + + grid_size = (1, 1) + input_path = os.path.join(input_path, 'bs{}'.format(bs)) + input_files = os.listdir(input_path) + input_files.sort() + image_path = os.path.join(image_path, 'bs{}_pkl'.format(bs)) + os.makedirs(image_path, exist_ok=True) + # load model + start = time.time() + with open(pkl_file, 'rb') as f: + G = pickle.load(f)['G_ema'].to(device) + + G.forward = functools.partial(G.forward, force_fp32=True) + for i in range(len(input_files)): + input_file = input_files[i] + input_file = os.path.join(input_path, input_file) + input_file = np.fromfile(input_file, dtype=np.float32) + z = torch.tensor(input_file).reshape(-1, G.z_dim).to(device) + c = torch.empty(bs, 0).to(device) + image = G(z, c) + image = image.reshape(-1, 3, 512, 512) + image = image.cpu() + save_image_grid(image, os.path.join(image_path, f'gen_image_{i:04d}') + '.png', drange=[-1, 1], + grid_size=grid_size) + + end = time.time() + print(f'Inference average time : {((end - start) * 1000 / len(input_files)):.2f} ms') + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--pkl_file', type=str, default='./G_ema_bs8_8p_kimg1000.pkl') + parser.add_argument('--input_path', type=str, default='./input') + parser.add_argument('--image_path', type=str, default='./results') + parser.add_argument('--batch_size', type=int, default=1) + args = parser.parse_args() + + main(args) diff --git a/PyTorch/contrib/cv/detection/StyleGAN2-ADA/requirements.txt b/PyTorch/contrib/cv/detection/StyleGAN2-ADA/requirements.txt index 3f021068343754dc45f33593e811ed9e93702ed9..017e9b5007a423ec1c830e2caac83953a7716ece 100644 --- a/PyTorch/contrib/cv/detection/StyleGAN2-ADA/requirements.txt +++ b/PyTorch/contrib/cv/detection/StyleGAN2-ADA/requirements.txt @@ -1,5 +1,5 @@ -requests -scipy -numpy -Pillow +requests +scipy +numpy +Pillow torch==1.5.0 \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/StyleGAN2-ADA/stylegan2-ada-pytorch_postprocess.py b/PyTorch/contrib/cv/detection/StyleGAN2-ADA/stylegan2-ada-pytorch_postprocess.py index 69bc1a47de649557643d2eca9fd3241c2b06c0db..d301391b97182b6c09e89f46ab1d44143e9925c8 100644 --- a/PyTorch/contrib/cv/detection/StyleGAN2-ADA/stylegan2-ada-pytorch_postprocess.py +++ b/PyTorch/contrib/cv/detection/StyleGAN2-ADA/stylegan2-ada-pytorch_postprocess.py @@ -1,78 +1,78 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the License); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - -import torch -import os -import numpy as np -import argparse -from perf_gpu import save_image_grid - - -def test_om(args): - bin_path = args.bin_path - image_path = args.image_path - bin_list = os.listdir(bin_path) - bin_list.sort() - for i in range(len(bin_list)): - images = np.fromfile(os.path.join(bin_path, bin_list[i]), dtype=np.float32) - images = torch.Tensor(images) - images = images.reshape(-1, 3, 512, 512) - bs = images.shape[0] - grid_size = (4, 4) if bs == 16 else (1, 1) - save_path = os.path.join(image_path, "bs{}_om".format(bs)) - os.makedirs(save_path, exist_ok=True) - save_image_grid(images, os.path.join(save_path, f'gen_image_{i:04d}') + ".png", drange=[-1, 1], - grid_size=grid_size) - - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument('--bin_path', type=str, required=True) - parser.add_argument('--image_path', type=str, default='./results') - args = parser.parse_args() - - test_om(args) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the License); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + +import torch +import os +import numpy as np +import argparse +from perf_gpu import save_image_grid + + +def test_om(args): + bin_path = args.bin_path + image_path = args.image_path + bin_list = os.listdir(bin_path) + bin_list.sort() + for i in range(len(bin_list)): + images = np.fromfile(os.path.join(bin_path, bin_list[i]), dtype=np.float32) + images = torch.Tensor(images) + images = images.reshape(-1, 3, 512, 512) + bs = images.shape[0] + grid_size = (4, 4) if bs == 16 else (1, 1) + save_path = os.path.join(image_path, "bs{}_om".format(bs)) + os.makedirs(save_path, exist_ok=True) + save_image_grid(images, os.path.join(save_path, f'gen_image_{i:04d}') + ".png", drange=[-1, 1], + grid_size=grid_size) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--bin_path', type=str, required=True) + parser.add_argument('--image_path', type=str, default='./results') + args = parser.parse_args() + + test_om(args) diff --git a/PyTorch/contrib/cv/detection/StyleGAN2-ADA/stylegan2-ada-pytorch_preprocess.py b/PyTorch/contrib/cv/detection/StyleGAN2-ADA/stylegan2-ada-pytorch_preprocess.py index fee1140fa65b9c8b528f4723886be37d87122382..9c90a9be83e63d837a1686572b9ef94c76fbfc2e 100644 --- a/PyTorch/contrib/cv/detection/StyleGAN2-ADA/stylegan2-ada-pytorch_preprocess.py +++ b/PyTorch/contrib/cv/detection/StyleGAN2-ADA/stylegan2-ada-pytorch_preprocess.py @@ -1,81 +1,81 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the License); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - -import os -import torch -import argparse - - -def main(args): - # set up option - z_dim = 512 - c_dim = 0 - bs = args.batch_size - num = args.num_input - save_path = args.save_path - - # create save path dir - save_path = os.path.join(save_path, "bs{}".format(bs)) - os.makedirs(save_path, exist_ok=True) - - # generate input - for i in range(num): - z = torch.randn([bs, z_dim]) - c = torch.empty([bs, c_dim]) - input = torch.cat((z, c), 1).numpy() - input.tofile(os.path.join(save_path, f'input_bs{bs}_{i:04d}.bin')) - - -# ---------------------------------------------------------------------------- -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument('--num_input', type=int, default=1) - parser.add_argument('--batch_size', type=int, default=1) - parser.add_argument('--save_path', type=str, default='./input') - args = parser.parse_args() - main(args) -# ---------------------------------------------------------------------------- +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the License); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + +import os +import torch +import argparse + + +def main(args): + # set up option + z_dim = 512 + c_dim = 0 + bs = args.batch_size + num = args.num_input + save_path = args.save_path + + # create save path dir + save_path = os.path.join(save_path, "bs{}".format(bs)) + os.makedirs(save_path, exist_ok=True) + + # generate input + for i in range(num): + z = torch.randn([bs, z_dim]) + c = torch.empty([bs, c_dim]) + input = torch.cat((z, c), 1).numpy() + input.tofile(os.path.join(save_path, f'input_bs{bs}_{i:04d}.bin')) + + +# ---------------------------------------------------------------------------- +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--num_input', type=int, default=1) + parser.add_argument('--batch_size', type=int, default=1) + parser.add_argument('--save_path', type=str, default='./input') + args = parser.parse_args() + main(args) +# ---------------------------------------------------------------------------- diff --git a/PyTorch/contrib/cv/detection/TextSnake/Dockerfile b/PyTorch/contrib/cv/detection/TextSnake/Dockerfile index 7e712fe1a166790798f57a2f2762c47394beb625..30a31af55804dd79571d2a36e6107a844cb7e549 100644 --- a/PyTorch/contrib/cv/detection/TextSnake/Dockerfile +++ b/PyTorch/contrib/cv/detection/TextSnake/Dockerfile @@ -1,5 +1,5 @@ -ARG FROM_IMAGE_NAME -FROM $FROM_IMAGE_NAME - -COPY requirements.txt . +ARG FROM_IMAGE_NAME +FROM $FROM_IMAGE_NAME + +COPY requirements.txt . RUN pip3.7 install -r requirements.txt \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/TextSnake/dataset/ctw.py b/PyTorch/contrib/cv/detection/TextSnake/dataset/ctw.py index 4e1ad12a819e98036586f198d3873933f1892331..eb1309d6c1e79cfb4dad830ae04bfca945f5568e 100644 --- a/PyTorch/contrib/cv/detection/TextSnake/dataset/ctw.py +++ b/PyTorch/contrib/cv/detection/TextSnake/dataset/ctw.py @@ -1,31 +1,31 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ============================================================================ \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/TextSnake/dataset/total_text/Evaluation_Protocol/ComputePrecisionRecall.m b/PyTorch/contrib/cv/detection/TextSnake/dataset/total_text/Evaluation_Protocol/ComputePrecisionRecall.m index 216a349259cbd1242be2db46f694fc497fbb3733..3df883ab2bd83034b6f957cec4d0f8ed7e138ed5 100644 --- a/PyTorch/contrib/cv/detection/TextSnake/dataset/total_text/Evaluation_Protocol/ComputePrecisionRecall.m +++ b/PyTorch/contrib/cv/detection/TextSnake/dataset/total_text/Evaluation_Protocol/ComputePrecisionRecall.m @@ -1,161 +1,161 @@ -function [ precision, recall ] = ComputePrecisionRecall( tau, sigma, tp,tr,k,fsc_k ) -%COMPUTEPRECISIONRECALL Summary of this function goes here -% Detailed explanation goes here - -if nargin == 2 - tr = 0.8; % recall threshold - tp = 0.4; % precision threshold - k = 2; % min number of matches, used in penalizing split & merge - fsc_k = 0.8;% penalize value of split or merge -end - -tot_gt = 0; -recall_accum = 0; - -tot_detected = 0; -precision_accum = 0; - -num_images = numel(tau); -assert(num_images == numel(sigma)); - -flag_gt = cell(1, num_images); -flag_det = cell(1, num_images); - -for ifile=1:num_images - - [num_gt, num_detected] = size( sigma{ifile} ); - tot_gt = tot_gt + num_gt; - tot_detected = tot_detected + num_detected; - - % ----- mark unprocessed - flag_gt{ifile} = zeros(num_gt, 1); - flag_det{ifile} = zeros(num_detected, 1); - - % --------------------------------------- - % check one-to-one match - % --------------------------------------- - for i_gt=1:num_gt - - num_detected_in_sigma = numel( find( sigma{ifile}(i_gt,:)>tr) ); - num_detected_in_tau = numel( find( tau{ifile}(i_gt,:)>tp) ); - - if num_detected_in_sigma == 1 && num_detected_in_tau == 1 - recall_accum = recall_accum + 1.0; - precision_accum = precision_accum + 1.0; - - % Mark the ground truth and detection, do not process twice - flag_gt{ifile}(i_gt) = 1; - idx_det = sigma{ifile}(i_gt,:)>tr; - flag_det{ifile}(idx_det) = 1; - end - end - - % --------------------------------------- - % check one-to-many match (split) - % one gt with many detected rectangles - % --------------------------------------- - for i_gt=1:num_gt - - if flag_gt{ifile}(i_gt) > 0 - continue; - end - - num_nonzero_in_sigma = sum( sigma{ifile}(i_gt,:)>0 ); - if num_nonzero_in_sigma >= k - - % ------------------------------------------------------------- - % Search the possible "many" partners for this "one" rectangle - % ------------------------------------------------------------- - - % ----- satisfy 1st condition - % only select unprocessed data - idx_detected_in_tau = find( (tau{ifile}(i_gt,:)'>=tp) & (flag_det{ifile}==0) ); - num_detected_in_tau = numel( idx_detected_in_tau ); - - if num_detected_in_tau == 1 - % Only one of the many-rectangles qualified -> - % This match degraded to a one-to-one match - if ( (tau{ifile}(i_gt, idx_detected_in_tau) >= tp) && ... - (sigma{ifile}(i_gt, idx_detected_in_tau) >= tr) ) - recall_accum = recall_accum + 1.0; - precision_accum = precision_accum + 1.0; - end - else - % satisfy 2nd condition - if sum( sigma{ifile}(i_gt,idx_detected_in_tau) ) >= tr - - % Mark the "one" rectangle - flag_gt{ifile}(i_gt) = 1; - - % Mark all the "many" rectangles - flag_det{ifile}(idx_detected_in_tau) = 1; - - recall_accum = recall_accum + fsc_k; - precision_accum = precision_accum + num_detected_in_tau * fsc_k; - - end - end - - end - - % No match - recall_accum = recall_accum + 0; - precision_accum = precision_accum + 0; - - end - - % --------------------------------------- - % check many-to-one match (merge) - % one detected rectangle with many gt - % --------------------------------------- - for i_test=1:num_detected - - if flag_det{ifile}(i_test) > 0 - continue; - end - - num_nonzero_in_tau = sum( tau{ifile}(:,i_test)>0 ); - if num_nonzero_in_tau >= k - - % satisfy 1st condition - % only select unprocessed data - idx_detected_in_sigma = find( (sigma{ifile}(:,i_test)>=tr) & (flag_gt{ifile}==0) ); - num_detected_in_sigma = numel( idx_detected_in_sigma ); - - if num_detected_in_sigma == 1 - % Only one of the many-rectangles qualified -> - % This match degraded to a one-to-one match - if ( (tau{ifile}(idx_detected_in_sigma, i_test) >= tp) && ... - (sigma{ifile}(idx_detected_in_sigma, i_test) >= tr) ) - recall_accum = recall_accum + 1.0; - precision_accum = precision_accum + 1.0; - end - else - % satisfy 2nd condition - if sum( tau{ifile}(idx_detected_in_sigma,i_test) ) >= tp - % Mark the "one" rectangle - flag_det{ifile}(i_test) = 1; - - % Mark all the "many" rectangles - flag_gt{ifile}(idx_detected_in_sigma) = 1; - - recall_accum = recall_accum + num_detected_in_sigma*fsc_k; - precision_accum = precision_accum + fsc_k; -% recall_accum = recall_accum + num_detected_in_sigma; -% precision_accum = precision_accum + 1.0; - end - end - - end - - % No match - recall_accum = recall_accum + 0; - precision_accum = precision_accum + 0; - end - -end -recall = recall_accum / tot_gt; -precision = precision_accum / tot_detected; - -end - +function [ precision, recall ] = ComputePrecisionRecall( tau, sigma, tp,tr,k,fsc_k ) +%COMPUTEPRECISIONRECALL Summary of this function goes here +% Detailed explanation goes here + +if nargin == 2 + tr = 0.8; % recall threshold + tp = 0.4; % precision threshold + k = 2; % min number of matches, used in penalizing split & merge + fsc_k = 0.8;% penalize value of split or merge +end + +tot_gt = 0; +recall_accum = 0; + +tot_detected = 0; +precision_accum = 0; + +num_images = numel(tau); +assert(num_images == numel(sigma)); + +flag_gt = cell(1, num_images); +flag_det = cell(1, num_images); + +for ifile=1:num_images + + [num_gt, num_detected] = size( sigma{ifile} ); + tot_gt = tot_gt + num_gt; + tot_detected = tot_detected + num_detected; + + % ----- mark unprocessed + flag_gt{ifile} = zeros(num_gt, 1); + flag_det{ifile} = zeros(num_detected, 1); + + % --------------------------------------- + % check one-to-one match + % --------------------------------------- + for i_gt=1:num_gt + + num_detected_in_sigma = numel( find( sigma{ifile}(i_gt,:)>tr) ); + num_detected_in_tau = numel( find( tau{ifile}(i_gt,:)>tp) ); + + if num_detected_in_sigma == 1 && num_detected_in_tau == 1 + recall_accum = recall_accum + 1.0; + precision_accum = precision_accum + 1.0; + + % Mark the ground truth and detection, do not process twice + flag_gt{ifile}(i_gt) = 1; + idx_det = sigma{ifile}(i_gt,:)>tr; + flag_det{ifile}(idx_det) = 1; + end + end + + % --------------------------------------- + % check one-to-many match (split) + % one gt with many detected rectangles + % --------------------------------------- + for i_gt=1:num_gt + + if flag_gt{ifile}(i_gt) > 0 + continue; + end + + num_nonzero_in_sigma = sum( sigma{ifile}(i_gt,:)>0 ); + if num_nonzero_in_sigma >= k + + % ------------------------------------------------------------- + % Search the possible "many" partners for this "one" rectangle + % ------------------------------------------------------------- + + % ----- satisfy 1st condition + % only select unprocessed data + idx_detected_in_tau = find( (tau{ifile}(i_gt,:)'>=tp) & (flag_det{ifile}==0) ); + num_detected_in_tau = numel( idx_detected_in_tau ); + + if num_detected_in_tau == 1 + % Only one of the many-rectangles qualified -> + % This match degraded to a one-to-one match + if ( (tau{ifile}(i_gt, idx_detected_in_tau) >= tp) && ... + (sigma{ifile}(i_gt, idx_detected_in_tau) >= tr) ) + recall_accum = recall_accum + 1.0; + precision_accum = precision_accum + 1.0; + end + else + % satisfy 2nd condition + if sum( sigma{ifile}(i_gt,idx_detected_in_tau) ) >= tr + + % Mark the "one" rectangle + flag_gt{ifile}(i_gt) = 1; + + % Mark all the "many" rectangles + flag_det{ifile}(idx_detected_in_tau) = 1; + + recall_accum = recall_accum + fsc_k; + precision_accum = precision_accum + num_detected_in_tau * fsc_k; + + end + end + + end + + % No match + recall_accum = recall_accum + 0; + precision_accum = precision_accum + 0; + + end + + % --------------------------------------- + % check many-to-one match (merge) + % one detected rectangle with many gt + % --------------------------------------- + for i_test=1:num_detected + + if flag_det{ifile}(i_test) > 0 + continue; + end + + num_nonzero_in_tau = sum( tau{ifile}(:,i_test)>0 ); + if num_nonzero_in_tau >= k + + % satisfy 1st condition + % only select unprocessed data + idx_detected_in_sigma = find( (sigma{ifile}(:,i_test)>=tr) & (flag_gt{ifile}==0) ); + num_detected_in_sigma = numel( idx_detected_in_sigma ); + + if num_detected_in_sigma == 1 + % Only one of the many-rectangles qualified -> + % This match degraded to a one-to-one match + if ( (tau{ifile}(idx_detected_in_sigma, i_test) >= tp) && ... + (sigma{ifile}(idx_detected_in_sigma, i_test) >= tr) ) + recall_accum = recall_accum + 1.0; + precision_accum = precision_accum + 1.0; + end + else + % satisfy 2nd condition + if sum( tau{ifile}(idx_detected_in_sigma,i_test) ) >= tp + % Mark the "one" rectangle + flag_det{ifile}(i_test) = 1; + + % Mark all the "many" rectangles + flag_gt{ifile}(idx_detected_in_sigma) = 1; + + recall_accum = recall_accum + num_detected_in_sigma*fsc_k; + precision_accum = precision_accum + fsc_k; +% recall_accum = recall_accum + num_detected_in_sigma; +% precision_accum = precision_accum + 1.0; + end + end + + end + + % No match + recall_accum = recall_accum + 0; + precision_accum = precision_accum + 0; + end + +end +recall = recall_accum / tot_gt; +precision = precision_accum / tot_detected; + +end + diff --git a/PyTorch/contrib/cv/detection/TextSnake/modelzoo_level.txt b/PyTorch/contrib/cv/detection/TextSnake/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/detection/TextSnake/modelzoo_level.txt +++ b/PyTorch/contrib/cv/detection/TextSnake/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/YOLACT/layers/modules/multibox_loss.py b/PyTorch/contrib/cv/detection/YOLACT/layers/modules/multibox_loss.py index 3f97991c39e9c1a85a1e03044cee923a3a0c2b66..86006e7d4d856f8d4a77379e5e6db153f8f63828 100644 --- a/PyTorch/contrib/cv/detection/YOLACT/layers/modules/multibox_loss.py +++ b/PyTorch/contrib/cv/detection/YOLACT/layers/modules/multibox_loss.py @@ -1,737 +1,737 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -# -*- coding: utf-8 -*- -import torch -import torch.nn as nn -import torch.nn.functional as F -from torch.autograd import Variable -from ..box_utils import match, log_sum_exp, decode, center_size, crop, elemwise_mask_iou, elemwise_box_iou - -from data import cfg, mask_type, activation_func - -class MultiBoxLoss(nn.Module): - """SSD Weighted Loss Function - Compute Targets: - 1) Produce Confidence Target Indices by matching ground truth boxes - with (default) 'priorboxes' that have jaccard index > threshold parameter - (default threshold: 0.5). - - 2) Produce localization target by 'encoding' variance into offsets of ground - truth boxes and their matched 'priorboxes'. - - 3) Hard negative mining to filter the excessive number of negative examples - that comes with using a large number of default bounding boxes. - (default negative:positive ratio 3:1) - - Objective Loss: - L(x,c,l,g) = (Lconf(x, c) + αLloc(x,l,g)) / N - Where, Lconf is the CrossEntropy Loss and Lloc is the SmoothL1 Loss - weighted by α which is set to 1 by cross val. - Args: - c: class confidences, - l: predicted boxes, - g: ground truth boxes - N: number of matched default boxes - See: https://arxiv.org/pdf/1512.02325.pdf for more details. - """ - - def __init__(self, num_classes, pos_threshold, neg_threshold, negpos_ratio): - super(MultiBoxLoss, self).__init__() - self.num_classes = num_classes - - self.pos_threshold = pos_threshold - self.neg_threshold = neg_threshold - self.negpos_ratio = negpos_ratio - - # If you output a proto mask with this area, your l1 loss will be l1_alpha - # Note that the area is relative (so 1 would be the entire image) - self.l1_expected_area = 20*20/70/70 - self.l1_alpha = 0.1 - - if cfg.use_class_balanced_conf: - self.class_instances = None - self.total_instances = 0 - - def forward(self, net, predictions, wrapper, wrapper_mask): - """Multibox Loss - Args: - predictions (tuple): A tuple containing loc preds, conf preds, - mask preds, and prior boxes from SSD net. - loc shape: torch.size(batch_size,num_priors,4) - conf shape: torch.size(batch_size,num_priors,num_classes) - masks shape: torch.size(batch_size,num_priors,mask_dim) - priors shape: torch.size(num_priors,4) - proto* shape: torch.size(batch_size,mask_h,mask_w,mask_dim) - - targets (list): Ground truth boxes and labels for a batch, - shape: [batch_size][num_objs,5] (last idx is the label). - - masks (list): Ground truth masks for each object in each image, - shape: [batch_size][num_objs,im_height,im_width] - - num_crowds (list): Number of crowd annotations per batch. The crowd - annotations should be the last num_crowds elements of targets and masks. - - * Only if mask_type == lincomb - """ - - targets, masks, num_crowds = wrapper.get_args(wrapper_mask) - targets = targets[0] - masks = masks[0] - num_crowds = num_crowds[0] - loc_data = predictions['loc'] - conf_data = predictions['conf'] - mask_data = predictions['mask'] - priors = predictions['priors'] - - if cfg.mask_type == mask_type.lincomb: - proto_data = predictions['proto'] - - score_data = predictions['score'] if cfg.use_mask_scoring else None - inst_data = predictions['inst'] if cfg.use_instance_coeff else None - - labels = [None] * len(targets) # Used in sem segm loss - - batch_size = loc_data.size(0) - num_priors = priors.size(0) - num_classes = self.num_classes - - # Match priors (default boxes) and ground truth boxes - # These tensors will be created with the same device as loc_data - loc_t = loc_data.new(batch_size, num_priors, 4) - gt_box_t = loc_data.new(batch_size, num_priors, 4) - conf_t = loc_data.new(batch_size, num_priors).long() - idx_t = loc_data.new(batch_size, num_priors).long() - - if cfg.use_class_existence_loss: - class_existence_t = loc_data.new(batch_size, num_classes-1) - - for idx in range(batch_size): - truths = targets[idx][:, :-1].data - labels[idx] = targets[idx][:, -1].data.long() - - if cfg.use_class_existence_loss: - # Construct a one-hot vector for each object and collapse it into an existence vector with max - # Also it's fine to include the crowd annotations here - class_existence_t[idx, :] = torch.eye(num_classes-1, device=conf_t.get_device())[labels[idx]].max(dim=0)[0] - - # Split the crowd annotations because they come bundled in - cur_crowds = num_crowds[idx] - if cur_crowds > 0: - split = lambda x: (x[-cur_crowds:], x[:-cur_crowds]) - crowd_boxes, truths = split(truths) - - # We don't use the crowd labels or masks - _, labels[idx] = split(labels[idx]) - _, masks[idx] = split(masks[idx]) - else: - crowd_boxes = None - - - match(self.pos_threshold, self.neg_threshold, - truths, priors.data, labels[idx], crowd_boxes, - loc_t, conf_t, idx_t, idx, loc_data[idx]) - - gt_box_t[idx, :, :] = truths[idx_t[idx]] - - # wrap targets - loc_t = Variable(loc_t, requires_grad=False) - conf_t = Variable(conf_t, requires_grad=False) - idx_t = Variable(idx_t, requires_grad=False) - - pos = conf_t > 0 - num_pos = pos.sum(dim=1, keepdim=True) - - # Shape: [batch,num_priors,4] - pos_idx = pos.unsqueeze(pos.dim()).expand_as(loc_data) - - losses = {} - - # Localization Loss (Smooth L1) - if cfg.train_boxes: - loc_p = loc_data.view(-1, 4) - loc_t = loc_t.view(-1, 4) - losses['B'] = F.smooth_l1_loss(loc_p, loc_t, reduction='none') * cfg.bbox_alpha - losses['B'][pos_idx.view(-1, 4) == False] = 0 - losses['B'] = losses['B'].sum() - - if cfg.train_masks: - if cfg.mask_type == mask_type.direct: - if cfg.use_gt_bboxes: - pos_masks = [] - for idx in range(batch_size): - pos_masks.append(masks[idx][idx_t[idx, pos[idx]]]) - masks_t = torch.cat(pos_masks, 0) - masks_p = mask_data[pos, :].view(-1, cfg.mask_dim) - losses['M'] = F.binary_cross_entropy(torch.clamp(masks_p, 0, 1), masks_t, reduction='sum') * cfg.mask_alpha - else: - losses['M'] = self.direct_mask_loss(pos_idx, idx_t, loc_data, mask_data, priors, masks) - elif cfg.mask_type == mask_type.lincomb: - ret = self.lincomb_mask_loss(pos, idx_t, loc_data, mask_data, priors, proto_data, masks, gt_box_t, score_data, inst_data, labels) - if cfg.use_maskiou: - loss, maskiou_targets = ret - else: - loss = ret - losses.update(loss) - - if cfg.mask_proto_loss is not None: - if cfg.mask_proto_loss == 'l1': - losses['P'] = torch.mean(torch.abs(proto_data)) / self.l1_expected_area * self.l1_alpha - elif cfg.mask_proto_loss == 'disj': - losses['P'] = -torch.mean(torch.max(F.log_softmax(proto_data, dim=-1), dim=-1)[0]) - - # Confidence loss - if cfg.use_focal_loss: - if cfg.use_sigmoid_focal_loss: - losses['C'] = self.focal_conf_sigmoid_loss(conf_data, conf_t) - elif cfg.use_objectness_score: - losses['C'] = self.focal_conf_objectness_loss(conf_data, conf_t) - else: - losses['C'] = self.focal_conf_loss(conf_data, conf_t) - else: - if cfg.use_objectness_score: - losses['C'] = self.conf_objectness_loss(conf_data, conf_t, batch_size, loc_p, loc_t, priors) - else: - losses['C'] = self.ohem_conf_loss(conf_data, conf_t, pos, batch_size) - - # Mask IoU Loss - if cfg.use_maskiou and maskiou_targets is not None: - losses['I'] = self.mask_iou_loss(net, maskiou_targets) - - # These losses also don't depend on anchors - if cfg.use_class_existence_loss: - losses['E'] = self.class_existence_loss(predictions['classes'], class_existence_t) - if cfg.use_semantic_segmentation_loss: - losses['S'] = self.semantic_segmentation_loss(predictions['segm'], masks, labels) - - # Divide all losses by the number of positives. - # Don't do it for loss[P] because that doesn't depend on the anchors. - total_num_pos = num_pos.data.sum().float() - for k in losses: - if k not in ('P', 'E', 'S'): - losses[k] /= total_num_pos - else: - losses[k] /= batch_size - - # Loss Key: - # - B: Box Localization Loss - # - C: Class Confidence Loss - # - M: Mask Loss - # - P: Prototype Loss - # - D: Coefficient Diversity Loss - # - E: Class Existence Loss - # - S: Semantic Segmentation Loss - return losses - - def class_existence_loss(self, class_data, class_existence_t): - return cfg.class_existence_alpha * F.binary_cross_entropy_with_logits(class_data, class_existence_t, reduction='sum') - - def semantic_segmentation_loss(self, segment_data, mask_t, class_t, interpolation_mode='bilinear'): - # Note num_classes here is without the background class so cfg.num_classes-1 - batch_size, num_classes, mask_h, mask_w = segment_data.size() - loss_s = 0 - - for idx in range(batch_size): - cur_segment = segment_data[idx] - cur_class_t = class_t[idx] - - with torch.no_grad(): - downsampled_masks = F.interpolate(mask_t[idx].unsqueeze(0), (mask_h, mask_w), - mode=interpolation_mode, align_corners=False).squeeze(0) - downsampled_masks = downsampled_masks.gt(0.5).float() - - # Construct Semantic Segmentation - segment_t = torch.zeros_like(cur_segment, requires_grad=False) - for obj_idx in range(downsampled_masks.size(0)): - segment_t[cur_class_t[obj_idx]] = torch.max(segment_t[cur_class_t[obj_idx]].float(), downsampled_masks[obj_idx]) - - loss_s += F.binary_cross_entropy_with_logits(cur_segment, segment_t, reduction='sum') - - return loss_s / mask_h / mask_w * cfg.semantic_segmentation_alpha - - - def ohem_conf_loss(self, conf_data, conf_t, pos, num): - # Compute max conf across batch for hard negative mining - batch_conf = conf_data.view(-1, self.num_classes) - if cfg.ohem_use_most_confident: - # i.e. max(softmax) along classes > 0 - batch_conf = F.softmax(batch_conf, dim=1) - loss_c, _ = batch_conf[:, 1:].max(dim=1) - else: - # i.e. -softmax(class 0 confidence) - loss_c = log_sum_exp(batch_conf) - batch_conf[:, 0] - - # Hard Negative Mining - loss_c = loss_c.view(num, -1) - loss_c[pos] = 0 # filter out pos boxes - loss_c[conf_t < 0] = 0 # filter out neutrals (conf_t = -1) - _, loss_idx = loss_c.sort(1, descending=True) - _, idx_rank = loss_idx.sort(1) - num_pos = pos.long().sum(1, keepdim=True) - num_neg = torch.clamp(self.negpos_ratio*num_pos, max=pos.size(1)-1) - neg = idx_rank < num_neg.expand_as(idx_rank) - - # Just in case there aren't enough negatives, don't start using positives as negatives - neg[pos] = 0 - neg[conf_t < 0] = 0 # Filter out neutrals - - # Confidence Loss Including Positive and Negative Examples - pos_idx = pos.unsqueeze(2).expand_as(conf_data) - neg_idx = neg.unsqueeze(2).expand_as(conf_data) - tensor_gt = (pos + neg).gt(0) - conf_p = conf_data.view(-1, self.num_classes) - targets_weighted = conf_t.view(-1) - loss_c = F.cross_entropy(conf_p, targets_weighted, reduction='none') - loss_c = loss_c[tensor_gt.view(-1) == True] - - if cfg.use_class_balanced_conf: - # Lazy initialization - if self.class_instances is None: - self.class_instances = torch.zeros(self.num_classes, device=targets_weighted.device) - - classes, counts = targets_weighted.unique(return_counts=True) - - for _cls, _cnt in zip(classes.cpu().numpy(), counts.cpu().numpy()): - self.class_instances[_cls] += _cnt - - self.total_instances += targets_weighted.size(0) - - weighting = 1 - (self.class_instances[targets_weighted] / self.total_instances) - weighting = torch.clamp(weighting, min=1/self.num_classes) - - # If you do the math, the average weight of self.class_instances is this - avg_weight = (self.num_classes - 1) / self.num_classes - - loss_c = (loss_c * weighting).sum() / avg_weight - else: - loss_c = loss_c.sum() - - return cfg.conf_alpha * loss_c - - def focal_conf_loss(self, conf_data, conf_t): - """ - Focal loss as described in https://arxiv.org/pdf/1708.02002.pdf - Adapted from https://github.com/clcarwin/focal_loss_pytorch/blob/master/focalloss.py - Note that this uses softmax and not the original sigmoid from the paper. - """ - conf_t = conf_t.view(-1) # [batch_size*num_priors] - conf_data = conf_data.view(-1, conf_data.size(-1)) # [batch_size*num_priors, num_classes] - - # Ignore neutral samples (class < 0) - keep = (conf_t >= 0).float() - conf_t[conf_t < 0] = 0 # so that gather doesn't drum up a fuss - - logpt = F.log_softmax(conf_data, dim=-1) - logpt = logpt.gather(1, conf_t.unsqueeze(-1)) - logpt = logpt.view(-1) - pt = logpt.exp() - - # I adapted the alpha_t calculation here from - # https://github.com/pytorch/pytorch/blob/master/modules/detectron/softmax_focal_loss_op.cu - # You'd think you want all the alphas to sum to one, but in the original implementation they - # just give background an alpha of 1-alpha and each forground an alpha of alpha. - background = (conf_t == 0).float() - at = (1 - cfg.focal_loss_alpha) * background + cfg.focal_loss_alpha * (1 - background) - - loss = -at * (1 - pt) ** cfg.focal_loss_gamma * logpt - - # See comment above for keep - return cfg.conf_alpha * (loss * keep).sum() - - def focal_conf_sigmoid_loss(self, conf_data, conf_t): - """ - Focal loss but using sigmoid like the original paper. - Note: To make things mesh easier, the network still predicts 81 class confidences in this mode. - Because retinanet originally only predicts 80, we simply just don't use conf_data[..., 0] - """ - num_classes = conf_data.size(-1) - - conf_t = conf_t.view(-1) # [batch_size*num_priors] - conf_data = conf_data.view(-1, num_classes) # [batch_size*num_priors, num_classes] - - # Ignore neutral samples (class < 0) - keep = (conf_t >= 0).float() - conf_t[conf_t < 0] = 0 # can't mask with -1, so filter that out - - # Compute a one-hot embedding of conf_t - # From https://github.com/kuangliu/pytorch-retinanet/blob/master/utils.py - conf_one_t = torch.eye(num_classes, device=conf_t.get_device())[conf_t] - conf_pm_t = conf_one_t * 2 - 1 # -1 if background, +1 if forground for specific class - - logpt = F.logsigmoid(conf_data * conf_pm_t) # note: 1 - sigmoid(x) = sigmoid(-x) - pt = logpt.exp() - - at = cfg.focal_loss_alpha * conf_one_t + (1 - cfg.focal_loss_alpha) * (1 - conf_one_t) - at[..., 0] = 0 # Set alpha for the background class to 0 because sigmoid focal loss doesn't use it - - loss = -at * (1 - pt) ** cfg.focal_loss_gamma * logpt - loss = keep * loss.sum(dim=-1) - - return cfg.conf_alpha * loss.sum() - - def focal_conf_objectness_loss(self, conf_data, conf_t): - """ - Instead of using softmax, use class[0] to be the objectness score and do sigmoid focal loss on that. - Then for the rest of the classes, softmax them and apply CE for only the positive examples. - - If class[0] = 1 implies forground and class[0] = 0 implies background then you achieve something - similar during test-time to softmax by setting class[1:] = softmax(class[1:]) * class[0] and invert class[0]. - """ - - conf_t = conf_t.view(-1) # [batch_size*num_priors] - conf_data = conf_data.view(-1, conf_data.size(-1)) # [batch_size*num_priors, num_classes] - - # Ignore neutral samples (class < 0) - keep = (conf_t >= 0).float() - conf_t[conf_t < 0] = 0 # so that gather doesn't drum up a fuss - - background = (conf_t == 0).float() - at = (1 - cfg.focal_loss_alpha) * background + cfg.focal_loss_alpha * (1 - background) - - logpt = F.logsigmoid(conf_data[:, 0]) * (1 - background) + F.logsigmoid(-conf_data[:, 0]) * background - pt = logpt.exp() - - obj_loss = -at * (1 - pt) ** cfg.focal_loss_gamma * logpt - - # All that was the objectiveness loss--now time for the class confidence loss - pos_mask = conf_t > 0 - conf_data_pos = (conf_data[:, 1:])[pos_mask] # Now this has just 80 classes - conf_t_pos = conf_t[pos_mask] - 1 # So subtract 1 here - - class_loss = F.cross_entropy(conf_data_pos, conf_t_pos, reduction='sum') - - return cfg.conf_alpha * (class_loss + (obj_loss * keep).sum()) - - def conf_objectness_loss(self, conf_data, conf_t, batch_size, loc_p, loc_t, priors): - """ - Instead of using softmax, use class[0] to be p(obj) * p(IoU) as in YOLO. - Then for the rest of the classes, softmax them and apply CE for only the positive examples. - """ - - conf_t = conf_t.view(-1) # [batch_size*num_priors] - conf_data = conf_data.view(-1, conf_data.size(-1)) # [batch_size*num_priors, num_classes] - - pos_mask = (conf_t > 0) - neg_mask = (conf_t == 0) - - obj_data = conf_data[:, 0] - obj_data_pos = obj_data[pos_mask] - obj_data_neg = obj_data[neg_mask] - - # Don't be confused, this is just binary cross entropy similified - obj_neg_loss = - F.logsigmoid(-obj_data_neg).sum() - - with torch.no_grad(): - pos_priors = priors.unsqueeze(0).expand(batch_size, -1, -1).reshape(-1, 4)[pos_mask, :] - - boxes_pred = decode(loc_p, pos_priors, cfg.use_yolo_regressors) - boxes_targ = decode(loc_t, pos_priors, cfg.use_yolo_regressors) - - iou_targets = elemwise_box_iou(boxes_pred, boxes_targ) - - obj_pos_loss = - iou_targets * F.logsigmoid(obj_data_pos) - (1 - iou_targets) * F.logsigmoid(-obj_data_pos) - obj_pos_loss = obj_pos_loss.sum() - - # All that was the objectiveness loss--now time for the class confidence loss - conf_data_pos = (conf_data[:, 1:])[pos_mask] # Now this has just 80 classes - conf_t_pos = conf_t[pos_mask] - 1 # So subtract 1 here - - class_loss = F.cross_entropy(conf_data_pos, conf_t_pos, reduction='sum') - - return cfg.conf_alpha * (class_loss + obj_pos_loss + obj_neg_loss) - - - def direct_mask_loss(self, pos_idx, idx_t, loc_data, mask_data, priors, masks): - """ Crops the gt masks using the predicted bboxes, scales them down, and outputs the BCE loss. """ - loss_m = 0 - for idx in range(mask_data.size(0)): - with torch.no_grad(): - cur_pos_idx = pos_idx[idx, :, :] - cur_pos_idx_squeezed = cur_pos_idx[:, 1] - - # Shape: [num_priors, 4], decoded predicted bboxes - pos_bboxes = decode(loc_data[idx, :, :], priors.data, cfg.use_yolo_regressors) - pos_bboxes = pos_bboxes[cur_pos_idx].view(-1, 4).clamp(0, 1) - pos_lookup = idx_t[idx, cur_pos_idx_squeezed] - - cur_masks = masks[idx] - pos_masks = cur_masks[pos_lookup, :, :] - - # Convert bboxes to absolute coordinates - num_pos, img_height, img_width = pos_masks.size() - - # Take care of all the bad behavior that can be caused by out of bounds coordinates - x1, x2 = sanitize_coordinates(pos_bboxes[:, 0], pos_bboxes[:, 2], img_width) - y1, y2 = sanitize_coordinates(pos_bboxes[:, 1], pos_bboxes[:, 3], img_height) - - # Crop each gt mask with the predicted bbox and rescale to the predicted mask size - # Note that each bounding box crop is a different size so I don't think we can vectorize this - scaled_masks = [] - for jdx in range(num_pos): - tmp_mask = pos_masks[jdx, y1[jdx]:y2[jdx], x1[jdx]:x2[jdx]] - - # Restore any dimensions we've left out because our bbox was 1px wide - while tmp_mask.dim() < 2: - tmp_mask = tmp_mask.unsqueeze(0) - - new_mask = F.adaptive_avg_pool2d(tmp_mask.unsqueeze(0), cfg.mask_size) - scaled_masks.append(new_mask.view(1, -1)) - - mask_t = torch.cat(scaled_masks, 0).gt(0.5).float() # Threshold downsampled mask - - pos_mask_data = mask_data[idx, cur_pos_idx_squeezed, :] - loss_m += F.binary_cross_entropy(torch.clamp(pos_mask_data, 0, 1), mask_t, reduction='sum') * cfg.mask_alpha - - return loss_m - - - def coeff_diversity_loss(self, coeffs, instance_t): - """ - coeffs should be size [num_pos, num_coeffs] - instance_t should be size [num_pos] and be values from 0 to num_instances-1 - """ - num_pos = coeffs.size(0) - instance_t = instance_t.view(-1) # juuuust to make sure - - coeffs_norm = F.normalize(coeffs, dim=1) - cos_sim = coeffs_norm @ coeffs_norm.t() - - inst_eq = (instance_t[:, None].expand_as(cos_sim) == instance_t[None, :].expand_as(cos_sim)).float() - - # Rescale to be between 0 and 1 - cos_sim = (cos_sim + 1) / 2 - - # If they're the same instance, use cosine distance, else use cosine similarity - loss = (1 - cos_sim) * inst_eq + cos_sim * (1 - inst_eq) - - # Only divide by num_pos once because we're summing over a num_pos x num_pos tensor - # and all the losses will be divided by num_pos at the end, so just one extra time. - return cfg.mask_proto_coeff_diversity_alpha * loss.sum() / num_pos - - - def lincomb_mask_loss(self, pos, idx_t, loc_data, mask_data, priors, proto_data, masks, gt_box_t, score_data, inst_data, labels, interpolation_mode='bilinear'): - mask_h = proto_data.size(1) - mask_w = proto_data.size(2) - - process_gt_bboxes = cfg.mask_proto_normalize_emulate_roi_pooling or cfg.mask_proto_crop - - if cfg.mask_proto_remove_empty_masks: - # Make sure to store a copy of this because we edit it to get rid of all-zero masks - pos = pos.clone() - - loss_m = 0 - loss_d = 0 # Coefficient diversity loss - - maskiou_t_list = [] - maskiou_net_input_list = [] - label_t_list = [] - - for idx in range(mask_data.size(0)): - with torch.no_grad(): - downsampled_masks = F.interpolate(masks[idx].unsqueeze(0), (mask_h, mask_w), - mode=interpolation_mode, align_corners=False).squeeze(0) - downsampled_masks = downsampled_masks.permute(1, 2, 0).contiguous() - - if cfg.mask_proto_binarize_downsampled_gt: - downsampled_masks = downsampled_masks.gt(0.5).float() - - if cfg.mask_proto_remove_empty_masks: - # Get rid of gt masks that are so small they get downsampled away - very_small_masks = (downsampled_masks.sum(dim=(0,1)) <= 0.0001) - for i in range(very_small_masks.size(0)): - if very_small_masks[i]: - pos[idx, idx_t[idx] == i] = 0 - - if cfg.mask_proto_reweight_mask_loss: - # Ensure that the gt is binary - if not cfg.mask_proto_binarize_downsampled_gt: - bin_gt = downsampled_masks.gt(0.5).float() - else: - bin_gt = downsampled_masks - - gt_foreground_norm = bin_gt / (torch.sum(bin_gt, dim=(0,1), keepdim=True) + 0.0001) - gt_background_norm = (1-bin_gt) / (torch.sum(1-bin_gt, dim=(0,1), keepdim=True) + 0.0001) - - mask_reweighting = gt_foreground_norm * cfg.mask_proto_reweight_coeff + gt_background_norm - mask_reweighting *= mask_h * mask_w - - cur_pos = pos[idx] - pos_idx_t = idx_t[idx, cur_pos] - - if process_gt_bboxes: - # Note: this is in point-form - if cfg.mask_proto_crop_with_pred_box: - pos_gt_box_t = decode(loc_data[idx, :, :], priors.data, cfg.use_yolo_regressors)[cur_pos] - else: - pos_gt_box_t = gt_box_t[idx, cur_pos] - - if pos_idx_t.size(0) == 0: - continue - - proto_masks = proto_data[idx] - proto_coef = mask_data[idx, cur_pos, :] - if cfg.use_mask_scoring: - mask_scores = score_data[idx, cur_pos, :] - - if cfg.mask_proto_coeff_diversity_loss: - if inst_data is not None: - div_coeffs = inst_data[idx, cur_pos, :] - else: - div_coeffs = proto_coef - - loss_d += self.coeff_diversity_loss(div_coeffs, pos_idx_t) - - # If we have over the allowed number of masks, select a random sample - old_num_pos = proto_coef.size(0) - if old_num_pos > cfg.masks_to_train: - perm = torch.randperm(proto_coef.size(0)) - select = perm[:cfg.masks_to_train] - - proto_coef = proto_coef[select, :] - pos_idx_t = pos_idx_t[select] - - if process_gt_bboxes: - pos_gt_box_t = pos_gt_box_t[select, :] - if cfg.use_mask_scoring: - mask_scores = mask_scores[select, :] - - num_pos = proto_coef.size(0) - mask_t = downsampled_masks[:, :, pos_idx_t] - label_t = labels[idx][pos_idx_t] - - # Size: [mask_h, mask_w, num_pos] - #pred_masks = proto_masks @ proto_coef.t() - pred_masks = torch.matmul(proto_masks, proto_coef.T) - pred_masks = cfg.mask_proto_mask_activation(pred_masks) - - if cfg.mask_proto_double_loss: - if cfg.mask_proto_mask_activation == activation_func.sigmoid: - pre_loss = F.binary_cross_entropy(torch.clamp(pred_masks, 0, 1), mask_t, reduction='sum') - else: - pre_loss = F.smooth_l1_loss(pred_masks, mask_t, reduction='sum') - - loss_m += cfg.mask_proto_double_loss_alpha * pre_loss - - if cfg.mask_proto_crop: - pred_masks = crop(pred_masks, pos_gt_box_t) - - if cfg.mask_proto_mask_activation == activation_func.sigmoid: - pre_loss = F.binary_cross_entropy(torch.clamp(pred_masks, 0, 1), mask_t, reduction='none') - else: - pre_loss = F.smooth_l1_loss(pred_masks, mask_t, reduction='none') - - if cfg.mask_proto_normalize_mask_loss_by_sqrt_area: - gt_area = torch.sum(mask_t, dim=(0, 1), keepdim=True) - pre_loss = pre_loss / (torch.sqrt(gt_area) + 0.0001) - - if cfg.mask_proto_reweight_mask_loss: - pre_loss = pre_loss * mask_reweighting[:, :, pos_idx_t] - - if cfg.mask_proto_normalize_emulate_roi_pooling: - weight = mask_h * mask_w if cfg.mask_proto_crop else 1 - pos_gt_csize = center_size(pos_gt_box_t) - gt_box_width = pos_gt_csize[:, 2] * mask_w - gt_box_height = pos_gt_csize[:, 3] * mask_h - pre_loss = pre_loss.sum(dim=(0, 1)) / gt_box_width / gt_box_height * weight - - # If the number of masks were limited scale the loss accordingly - if old_num_pos > num_pos: - pre_loss *= old_num_pos / num_pos - - loss_m += torch.sum(pre_loss) - - if cfg.use_maskiou: - if cfg.discard_mask_area > 0: - gt_mask_area = torch.sum(mask_t, dim=(0, 1)) - select = gt_mask_area > cfg.discard_mask_area - - if torch.sum(select) < 1: - continue - - pos_gt_box_t = pos_gt_box_t[select, :] - pred_masks = pred_masks[:, :, select] - mask_t = mask_t[:, :, select] - label_t = label_t[select] - - maskiou_net_input = pred_masks.permute(2, 0, 1).contiguous().unsqueeze(1) - pred_masks = pred_masks.gt(0.5).float() - maskiou_t = self._mask_iou(pred_masks, mask_t) - - maskiou_net_input_list.append(maskiou_net_input) - maskiou_t_list.append(maskiou_t) - label_t_list.append(label_t) - - losses = {'M': loss_m * cfg.mask_alpha / mask_h / mask_w} - - if cfg.mask_proto_coeff_diversity_loss: - losses['D'] = loss_d - - if cfg.use_maskiou: - # discard_mask_area discarded every mask in the batch, so nothing to do here - if len(maskiou_t_list) == 0: - return losses, None - - maskiou_t = torch.cat(maskiou_t_list) - label_t = torch.cat(label_t_list) - maskiou_net_input = torch.cat(maskiou_net_input_list) - - num_samples = maskiou_t.size(0) - if cfg.maskious_to_train > 0 and num_samples > cfg.maskious_to_train: - perm = torch.randperm(num_samples) - select = perm[:cfg.masks_to_train] - maskiou_t = maskiou_t[select] - label_t = label_t[select] - maskiou_net_input = maskiou_net_input[select] - - return losses, [maskiou_net_input, maskiou_t, label_t] - - return losses - - def _mask_iou(self, mask1, mask2): - intersection = torch.sum(mask1*mask2, dim=(0, 1)) - area1 = torch.sum(mask1, dim=(0, 1)) - area2 = torch.sum(mask2, dim=(0, 1)) - union = (area1 + area2) - intersection - ret = intersection / union - return ret - - def mask_iou_loss(self, net, maskiou_targets): - maskiou_net_input, maskiou_t, label_t = maskiou_targets - - maskiou_p = net.maskiou_net(maskiou_net_input) - - label_t = label_t[:, None] - maskiou_p = torch.gather(maskiou_p, dim=1, index=label_t).view(-1) - - loss_i = F.smooth_l1_loss(maskiou_p, maskiou_t, reduction='sum') - - return loss_i * cfg.maskiou_alpha +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +# -*- coding: utf-8 -*- +import torch +import torch.nn as nn +import torch.nn.functional as F +from torch.autograd import Variable +from ..box_utils import match, log_sum_exp, decode, center_size, crop, elemwise_mask_iou, elemwise_box_iou + +from data import cfg, mask_type, activation_func + +class MultiBoxLoss(nn.Module): + """SSD Weighted Loss Function + Compute Targets: + 1) Produce Confidence Target Indices by matching ground truth boxes + with (default) 'priorboxes' that have jaccard index > threshold parameter + (default threshold: 0.5). + + 2) Produce localization target by 'encoding' variance into offsets of ground + truth boxes and their matched 'priorboxes'. + + 3) Hard negative mining to filter the excessive number of negative examples + that comes with using a large number of default bounding boxes. + (default negative:positive ratio 3:1) + + Objective Loss: + L(x,c,l,g) = (Lconf(x, c) + αLloc(x,l,g)) / N + Where, Lconf is the CrossEntropy Loss and Lloc is the SmoothL1 Loss + weighted by α which is set to 1 by cross val. + Args: + c: class confidences, + l: predicted boxes, + g: ground truth boxes + N: number of matched default boxes + See: https://arxiv.org/pdf/1512.02325.pdf for more details. + """ + + def __init__(self, num_classes, pos_threshold, neg_threshold, negpos_ratio): + super(MultiBoxLoss, self).__init__() + self.num_classes = num_classes + + self.pos_threshold = pos_threshold + self.neg_threshold = neg_threshold + self.negpos_ratio = negpos_ratio + + # If you output a proto mask with this area, your l1 loss will be l1_alpha + # Note that the area is relative (so 1 would be the entire image) + self.l1_expected_area = 20*20/70/70 + self.l1_alpha = 0.1 + + if cfg.use_class_balanced_conf: + self.class_instances = None + self.total_instances = 0 + + def forward(self, net, predictions, wrapper, wrapper_mask): + """Multibox Loss + Args: + predictions (tuple): A tuple containing loc preds, conf preds, + mask preds, and prior boxes from SSD net. + loc shape: torch.size(batch_size,num_priors,4) + conf shape: torch.size(batch_size,num_priors,num_classes) + masks shape: torch.size(batch_size,num_priors,mask_dim) + priors shape: torch.size(num_priors,4) + proto* shape: torch.size(batch_size,mask_h,mask_w,mask_dim) + + targets (list): Ground truth boxes and labels for a batch, + shape: [batch_size][num_objs,5] (last idx is the label). + + masks (list): Ground truth masks for each object in each image, + shape: [batch_size][num_objs,im_height,im_width] + + num_crowds (list): Number of crowd annotations per batch. The crowd + annotations should be the last num_crowds elements of targets and masks. + + * Only if mask_type == lincomb + """ + + targets, masks, num_crowds = wrapper.get_args(wrapper_mask) + targets = targets[0] + masks = masks[0] + num_crowds = num_crowds[0] + loc_data = predictions['loc'] + conf_data = predictions['conf'] + mask_data = predictions['mask'] + priors = predictions['priors'] + + if cfg.mask_type == mask_type.lincomb: + proto_data = predictions['proto'] + + score_data = predictions['score'] if cfg.use_mask_scoring else None + inst_data = predictions['inst'] if cfg.use_instance_coeff else None + + labels = [None] * len(targets) # Used in sem segm loss + + batch_size = loc_data.size(0) + num_priors = priors.size(0) + num_classes = self.num_classes + + # Match priors (default boxes) and ground truth boxes + # These tensors will be created with the same device as loc_data + loc_t = loc_data.new(batch_size, num_priors, 4) + gt_box_t = loc_data.new(batch_size, num_priors, 4) + conf_t = loc_data.new(batch_size, num_priors).long() + idx_t = loc_data.new(batch_size, num_priors).long() + + if cfg.use_class_existence_loss: + class_existence_t = loc_data.new(batch_size, num_classes-1) + + for idx in range(batch_size): + truths = targets[idx][:, :-1].data + labels[idx] = targets[idx][:, -1].data.long() + + if cfg.use_class_existence_loss: + # Construct a one-hot vector for each object and collapse it into an existence vector with max + # Also it's fine to include the crowd annotations here + class_existence_t[idx, :] = torch.eye(num_classes-1, device=conf_t.get_device())[labels[idx]].max(dim=0)[0] + + # Split the crowd annotations because they come bundled in + cur_crowds = num_crowds[idx] + if cur_crowds > 0: + split = lambda x: (x[-cur_crowds:], x[:-cur_crowds]) + crowd_boxes, truths = split(truths) + + # We don't use the crowd labels or masks + _, labels[idx] = split(labels[idx]) + _, masks[idx] = split(masks[idx]) + else: + crowd_boxes = None + + + match(self.pos_threshold, self.neg_threshold, + truths, priors.data, labels[idx], crowd_boxes, + loc_t, conf_t, idx_t, idx, loc_data[idx]) + + gt_box_t[idx, :, :] = truths[idx_t[idx]] + + # wrap targets + loc_t = Variable(loc_t, requires_grad=False) + conf_t = Variable(conf_t, requires_grad=False) + idx_t = Variable(idx_t, requires_grad=False) + + pos = conf_t > 0 + num_pos = pos.sum(dim=1, keepdim=True) + + # Shape: [batch,num_priors,4] + pos_idx = pos.unsqueeze(pos.dim()).expand_as(loc_data) + + losses = {} + + # Localization Loss (Smooth L1) + if cfg.train_boxes: + loc_p = loc_data.view(-1, 4) + loc_t = loc_t.view(-1, 4) + losses['B'] = F.smooth_l1_loss(loc_p, loc_t, reduction='none') * cfg.bbox_alpha + losses['B'][pos_idx.view(-1, 4) == False] = 0 + losses['B'] = losses['B'].sum() + + if cfg.train_masks: + if cfg.mask_type == mask_type.direct: + if cfg.use_gt_bboxes: + pos_masks = [] + for idx in range(batch_size): + pos_masks.append(masks[idx][idx_t[idx, pos[idx]]]) + masks_t = torch.cat(pos_masks, 0) + masks_p = mask_data[pos, :].view(-1, cfg.mask_dim) + losses['M'] = F.binary_cross_entropy(torch.clamp(masks_p, 0, 1), masks_t, reduction='sum') * cfg.mask_alpha + else: + losses['M'] = self.direct_mask_loss(pos_idx, idx_t, loc_data, mask_data, priors, masks) + elif cfg.mask_type == mask_type.lincomb: + ret = self.lincomb_mask_loss(pos, idx_t, loc_data, mask_data, priors, proto_data, masks, gt_box_t, score_data, inst_data, labels) + if cfg.use_maskiou: + loss, maskiou_targets = ret + else: + loss = ret + losses.update(loss) + + if cfg.mask_proto_loss is not None: + if cfg.mask_proto_loss == 'l1': + losses['P'] = torch.mean(torch.abs(proto_data)) / self.l1_expected_area * self.l1_alpha + elif cfg.mask_proto_loss == 'disj': + losses['P'] = -torch.mean(torch.max(F.log_softmax(proto_data, dim=-1), dim=-1)[0]) + + # Confidence loss + if cfg.use_focal_loss: + if cfg.use_sigmoid_focal_loss: + losses['C'] = self.focal_conf_sigmoid_loss(conf_data, conf_t) + elif cfg.use_objectness_score: + losses['C'] = self.focal_conf_objectness_loss(conf_data, conf_t) + else: + losses['C'] = self.focal_conf_loss(conf_data, conf_t) + else: + if cfg.use_objectness_score: + losses['C'] = self.conf_objectness_loss(conf_data, conf_t, batch_size, loc_p, loc_t, priors) + else: + losses['C'] = self.ohem_conf_loss(conf_data, conf_t, pos, batch_size) + + # Mask IoU Loss + if cfg.use_maskiou and maskiou_targets is not None: + losses['I'] = self.mask_iou_loss(net, maskiou_targets) + + # These losses also don't depend on anchors + if cfg.use_class_existence_loss: + losses['E'] = self.class_existence_loss(predictions['classes'], class_existence_t) + if cfg.use_semantic_segmentation_loss: + losses['S'] = self.semantic_segmentation_loss(predictions['segm'], masks, labels) + + # Divide all losses by the number of positives. + # Don't do it for loss[P] because that doesn't depend on the anchors. + total_num_pos = num_pos.data.sum().float() + for k in losses: + if k not in ('P', 'E', 'S'): + losses[k] /= total_num_pos + else: + losses[k] /= batch_size + + # Loss Key: + # - B: Box Localization Loss + # - C: Class Confidence Loss + # - M: Mask Loss + # - P: Prototype Loss + # - D: Coefficient Diversity Loss + # - E: Class Existence Loss + # - S: Semantic Segmentation Loss + return losses + + def class_existence_loss(self, class_data, class_existence_t): + return cfg.class_existence_alpha * F.binary_cross_entropy_with_logits(class_data, class_existence_t, reduction='sum') + + def semantic_segmentation_loss(self, segment_data, mask_t, class_t, interpolation_mode='bilinear'): + # Note num_classes here is without the background class so cfg.num_classes-1 + batch_size, num_classes, mask_h, mask_w = segment_data.size() + loss_s = 0 + + for idx in range(batch_size): + cur_segment = segment_data[idx] + cur_class_t = class_t[idx] + + with torch.no_grad(): + downsampled_masks = F.interpolate(mask_t[idx].unsqueeze(0), (mask_h, mask_w), + mode=interpolation_mode, align_corners=False).squeeze(0) + downsampled_masks = downsampled_masks.gt(0.5).float() + + # Construct Semantic Segmentation + segment_t = torch.zeros_like(cur_segment, requires_grad=False) + for obj_idx in range(downsampled_masks.size(0)): + segment_t[cur_class_t[obj_idx]] = torch.max(segment_t[cur_class_t[obj_idx]].float(), downsampled_masks[obj_idx]) + + loss_s += F.binary_cross_entropy_with_logits(cur_segment, segment_t, reduction='sum') + + return loss_s / mask_h / mask_w * cfg.semantic_segmentation_alpha + + + def ohem_conf_loss(self, conf_data, conf_t, pos, num): + # Compute max conf across batch for hard negative mining + batch_conf = conf_data.view(-1, self.num_classes) + if cfg.ohem_use_most_confident: + # i.e. max(softmax) along classes > 0 + batch_conf = F.softmax(batch_conf, dim=1) + loss_c, _ = batch_conf[:, 1:].max(dim=1) + else: + # i.e. -softmax(class 0 confidence) + loss_c = log_sum_exp(batch_conf) - batch_conf[:, 0] + + # Hard Negative Mining + loss_c = loss_c.view(num, -1) + loss_c[pos] = 0 # filter out pos boxes + loss_c[conf_t < 0] = 0 # filter out neutrals (conf_t = -1) + _, loss_idx = loss_c.sort(1, descending=True) + _, idx_rank = loss_idx.sort(1) + num_pos = pos.long().sum(1, keepdim=True) + num_neg = torch.clamp(self.negpos_ratio*num_pos, max=pos.size(1)-1) + neg = idx_rank < num_neg.expand_as(idx_rank) + + # Just in case there aren't enough negatives, don't start using positives as negatives + neg[pos] = 0 + neg[conf_t < 0] = 0 # Filter out neutrals + + # Confidence Loss Including Positive and Negative Examples + pos_idx = pos.unsqueeze(2).expand_as(conf_data) + neg_idx = neg.unsqueeze(2).expand_as(conf_data) + tensor_gt = (pos + neg).gt(0) + conf_p = conf_data.view(-1, self.num_classes) + targets_weighted = conf_t.view(-1) + loss_c = F.cross_entropy(conf_p, targets_weighted, reduction='none') + loss_c = loss_c[tensor_gt.view(-1) == True] + + if cfg.use_class_balanced_conf: + # Lazy initialization + if self.class_instances is None: + self.class_instances = torch.zeros(self.num_classes, device=targets_weighted.device) + + classes, counts = targets_weighted.unique(return_counts=True) + + for _cls, _cnt in zip(classes.cpu().numpy(), counts.cpu().numpy()): + self.class_instances[_cls] += _cnt + + self.total_instances += targets_weighted.size(0) + + weighting = 1 - (self.class_instances[targets_weighted] / self.total_instances) + weighting = torch.clamp(weighting, min=1/self.num_classes) + + # If you do the math, the average weight of self.class_instances is this + avg_weight = (self.num_classes - 1) / self.num_classes + + loss_c = (loss_c * weighting).sum() / avg_weight + else: + loss_c = loss_c.sum() + + return cfg.conf_alpha * loss_c + + def focal_conf_loss(self, conf_data, conf_t): + """ + Focal loss as described in https://arxiv.org/pdf/1708.02002.pdf + Adapted from https://github.com/clcarwin/focal_loss_pytorch/blob/master/focalloss.py + Note that this uses softmax and not the original sigmoid from the paper. + """ + conf_t = conf_t.view(-1) # [batch_size*num_priors] + conf_data = conf_data.view(-1, conf_data.size(-1)) # [batch_size*num_priors, num_classes] + + # Ignore neutral samples (class < 0) + keep = (conf_t >= 0).float() + conf_t[conf_t < 0] = 0 # so that gather doesn't drum up a fuss + + logpt = F.log_softmax(conf_data, dim=-1) + logpt = logpt.gather(1, conf_t.unsqueeze(-1)) + logpt = logpt.view(-1) + pt = logpt.exp() + + # I adapted the alpha_t calculation here from + # https://github.com/pytorch/pytorch/blob/master/modules/detectron/softmax_focal_loss_op.cu + # You'd think you want all the alphas to sum to one, but in the original implementation they + # just give background an alpha of 1-alpha and each forground an alpha of alpha. + background = (conf_t == 0).float() + at = (1 - cfg.focal_loss_alpha) * background + cfg.focal_loss_alpha * (1 - background) + + loss = -at * (1 - pt) ** cfg.focal_loss_gamma * logpt + + # See comment above for keep + return cfg.conf_alpha * (loss * keep).sum() + + def focal_conf_sigmoid_loss(self, conf_data, conf_t): + """ + Focal loss but using sigmoid like the original paper. + Note: To make things mesh easier, the network still predicts 81 class confidences in this mode. + Because retinanet originally only predicts 80, we simply just don't use conf_data[..., 0] + """ + num_classes = conf_data.size(-1) + + conf_t = conf_t.view(-1) # [batch_size*num_priors] + conf_data = conf_data.view(-1, num_classes) # [batch_size*num_priors, num_classes] + + # Ignore neutral samples (class < 0) + keep = (conf_t >= 0).float() + conf_t[conf_t < 0] = 0 # can't mask with -1, so filter that out + + # Compute a one-hot embedding of conf_t + # From https://github.com/kuangliu/pytorch-retinanet/blob/master/utils.py + conf_one_t = torch.eye(num_classes, device=conf_t.get_device())[conf_t] + conf_pm_t = conf_one_t * 2 - 1 # -1 if background, +1 if forground for specific class + + logpt = F.logsigmoid(conf_data * conf_pm_t) # note: 1 - sigmoid(x) = sigmoid(-x) + pt = logpt.exp() + + at = cfg.focal_loss_alpha * conf_one_t + (1 - cfg.focal_loss_alpha) * (1 - conf_one_t) + at[..., 0] = 0 # Set alpha for the background class to 0 because sigmoid focal loss doesn't use it + + loss = -at * (1 - pt) ** cfg.focal_loss_gamma * logpt + loss = keep * loss.sum(dim=-1) + + return cfg.conf_alpha * loss.sum() + + def focal_conf_objectness_loss(self, conf_data, conf_t): + """ + Instead of using softmax, use class[0] to be the objectness score and do sigmoid focal loss on that. + Then for the rest of the classes, softmax them and apply CE for only the positive examples. + + If class[0] = 1 implies forground and class[0] = 0 implies background then you achieve something + similar during test-time to softmax by setting class[1:] = softmax(class[1:]) * class[0] and invert class[0]. + """ + + conf_t = conf_t.view(-1) # [batch_size*num_priors] + conf_data = conf_data.view(-1, conf_data.size(-1)) # [batch_size*num_priors, num_classes] + + # Ignore neutral samples (class < 0) + keep = (conf_t >= 0).float() + conf_t[conf_t < 0] = 0 # so that gather doesn't drum up a fuss + + background = (conf_t == 0).float() + at = (1 - cfg.focal_loss_alpha) * background + cfg.focal_loss_alpha * (1 - background) + + logpt = F.logsigmoid(conf_data[:, 0]) * (1 - background) + F.logsigmoid(-conf_data[:, 0]) * background + pt = logpt.exp() + + obj_loss = -at * (1 - pt) ** cfg.focal_loss_gamma * logpt + + # All that was the objectiveness loss--now time for the class confidence loss + pos_mask = conf_t > 0 + conf_data_pos = (conf_data[:, 1:])[pos_mask] # Now this has just 80 classes + conf_t_pos = conf_t[pos_mask] - 1 # So subtract 1 here + + class_loss = F.cross_entropy(conf_data_pos, conf_t_pos, reduction='sum') + + return cfg.conf_alpha * (class_loss + (obj_loss * keep).sum()) + + def conf_objectness_loss(self, conf_data, conf_t, batch_size, loc_p, loc_t, priors): + """ + Instead of using softmax, use class[0] to be p(obj) * p(IoU) as in YOLO. + Then for the rest of the classes, softmax them and apply CE for only the positive examples. + """ + + conf_t = conf_t.view(-1) # [batch_size*num_priors] + conf_data = conf_data.view(-1, conf_data.size(-1)) # [batch_size*num_priors, num_classes] + + pos_mask = (conf_t > 0) + neg_mask = (conf_t == 0) + + obj_data = conf_data[:, 0] + obj_data_pos = obj_data[pos_mask] + obj_data_neg = obj_data[neg_mask] + + # Don't be confused, this is just binary cross entropy similified + obj_neg_loss = - F.logsigmoid(-obj_data_neg).sum() + + with torch.no_grad(): + pos_priors = priors.unsqueeze(0).expand(batch_size, -1, -1).reshape(-1, 4)[pos_mask, :] + + boxes_pred = decode(loc_p, pos_priors, cfg.use_yolo_regressors) + boxes_targ = decode(loc_t, pos_priors, cfg.use_yolo_regressors) + + iou_targets = elemwise_box_iou(boxes_pred, boxes_targ) + + obj_pos_loss = - iou_targets * F.logsigmoid(obj_data_pos) - (1 - iou_targets) * F.logsigmoid(-obj_data_pos) + obj_pos_loss = obj_pos_loss.sum() + + # All that was the objectiveness loss--now time for the class confidence loss + conf_data_pos = (conf_data[:, 1:])[pos_mask] # Now this has just 80 classes + conf_t_pos = conf_t[pos_mask] - 1 # So subtract 1 here + + class_loss = F.cross_entropy(conf_data_pos, conf_t_pos, reduction='sum') + + return cfg.conf_alpha * (class_loss + obj_pos_loss + obj_neg_loss) + + + def direct_mask_loss(self, pos_idx, idx_t, loc_data, mask_data, priors, masks): + """ Crops the gt masks using the predicted bboxes, scales them down, and outputs the BCE loss. """ + loss_m = 0 + for idx in range(mask_data.size(0)): + with torch.no_grad(): + cur_pos_idx = pos_idx[idx, :, :] + cur_pos_idx_squeezed = cur_pos_idx[:, 1] + + # Shape: [num_priors, 4], decoded predicted bboxes + pos_bboxes = decode(loc_data[idx, :, :], priors.data, cfg.use_yolo_regressors) + pos_bboxes = pos_bboxes[cur_pos_idx].view(-1, 4).clamp(0, 1) + pos_lookup = idx_t[idx, cur_pos_idx_squeezed] + + cur_masks = masks[idx] + pos_masks = cur_masks[pos_lookup, :, :] + + # Convert bboxes to absolute coordinates + num_pos, img_height, img_width = pos_masks.size() + + # Take care of all the bad behavior that can be caused by out of bounds coordinates + x1, x2 = sanitize_coordinates(pos_bboxes[:, 0], pos_bboxes[:, 2], img_width) + y1, y2 = sanitize_coordinates(pos_bboxes[:, 1], pos_bboxes[:, 3], img_height) + + # Crop each gt mask with the predicted bbox and rescale to the predicted mask size + # Note that each bounding box crop is a different size so I don't think we can vectorize this + scaled_masks = [] + for jdx in range(num_pos): + tmp_mask = pos_masks[jdx, y1[jdx]:y2[jdx], x1[jdx]:x2[jdx]] + + # Restore any dimensions we've left out because our bbox was 1px wide + while tmp_mask.dim() < 2: + tmp_mask = tmp_mask.unsqueeze(0) + + new_mask = F.adaptive_avg_pool2d(tmp_mask.unsqueeze(0), cfg.mask_size) + scaled_masks.append(new_mask.view(1, -1)) + + mask_t = torch.cat(scaled_masks, 0).gt(0.5).float() # Threshold downsampled mask + + pos_mask_data = mask_data[idx, cur_pos_idx_squeezed, :] + loss_m += F.binary_cross_entropy(torch.clamp(pos_mask_data, 0, 1), mask_t, reduction='sum') * cfg.mask_alpha + + return loss_m + + + def coeff_diversity_loss(self, coeffs, instance_t): + """ + coeffs should be size [num_pos, num_coeffs] + instance_t should be size [num_pos] and be values from 0 to num_instances-1 + """ + num_pos = coeffs.size(0) + instance_t = instance_t.view(-1) # juuuust to make sure + + coeffs_norm = F.normalize(coeffs, dim=1) + cos_sim = coeffs_norm @ coeffs_norm.t() + + inst_eq = (instance_t[:, None].expand_as(cos_sim) == instance_t[None, :].expand_as(cos_sim)).float() + + # Rescale to be between 0 and 1 + cos_sim = (cos_sim + 1) / 2 + + # If they're the same instance, use cosine distance, else use cosine similarity + loss = (1 - cos_sim) * inst_eq + cos_sim * (1 - inst_eq) + + # Only divide by num_pos once because we're summing over a num_pos x num_pos tensor + # and all the losses will be divided by num_pos at the end, so just one extra time. + return cfg.mask_proto_coeff_diversity_alpha * loss.sum() / num_pos + + + def lincomb_mask_loss(self, pos, idx_t, loc_data, mask_data, priors, proto_data, masks, gt_box_t, score_data, inst_data, labels, interpolation_mode='bilinear'): + mask_h = proto_data.size(1) + mask_w = proto_data.size(2) + + process_gt_bboxes = cfg.mask_proto_normalize_emulate_roi_pooling or cfg.mask_proto_crop + + if cfg.mask_proto_remove_empty_masks: + # Make sure to store a copy of this because we edit it to get rid of all-zero masks + pos = pos.clone() + + loss_m = 0 + loss_d = 0 # Coefficient diversity loss + + maskiou_t_list = [] + maskiou_net_input_list = [] + label_t_list = [] + + for idx in range(mask_data.size(0)): + with torch.no_grad(): + downsampled_masks = F.interpolate(masks[idx].unsqueeze(0), (mask_h, mask_w), + mode=interpolation_mode, align_corners=False).squeeze(0) + downsampled_masks = downsampled_masks.permute(1, 2, 0).contiguous() + + if cfg.mask_proto_binarize_downsampled_gt: + downsampled_masks = downsampled_masks.gt(0.5).float() + + if cfg.mask_proto_remove_empty_masks: + # Get rid of gt masks that are so small they get downsampled away + very_small_masks = (downsampled_masks.sum(dim=(0,1)) <= 0.0001) + for i in range(very_small_masks.size(0)): + if very_small_masks[i]: + pos[idx, idx_t[idx] == i] = 0 + + if cfg.mask_proto_reweight_mask_loss: + # Ensure that the gt is binary + if not cfg.mask_proto_binarize_downsampled_gt: + bin_gt = downsampled_masks.gt(0.5).float() + else: + bin_gt = downsampled_masks + + gt_foreground_norm = bin_gt / (torch.sum(bin_gt, dim=(0,1), keepdim=True) + 0.0001) + gt_background_norm = (1-bin_gt) / (torch.sum(1-bin_gt, dim=(0,1), keepdim=True) + 0.0001) + + mask_reweighting = gt_foreground_norm * cfg.mask_proto_reweight_coeff + gt_background_norm + mask_reweighting *= mask_h * mask_w + + cur_pos = pos[idx] + pos_idx_t = idx_t[idx, cur_pos] + + if process_gt_bboxes: + # Note: this is in point-form + if cfg.mask_proto_crop_with_pred_box: + pos_gt_box_t = decode(loc_data[idx, :, :], priors.data, cfg.use_yolo_regressors)[cur_pos] + else: + pos_gt_box_t = gt_box_t[idx, cur_pos] + + if pos_idx_t.size(0) == 0: + continue + + proto_masks = proto_data[idx] + proto_coef = mask_data[idx, cur_pos, :] + if cfg.use_mask_scoring: + mask_scores = score_data[idx, cur_pos, :] + + if cfg.mask_proto_coeff_diversity_loss: + if inst_data is not None: + div_coeffs = inst_data[idx, cur_pos, :] + else: + div_coeffs = proto_coef + + loss_d += self.coeff_diversity_loss(div_coeffs, pos_idx_t) + + # If we have over the allowed number of masks, select a random sample + old_num_pos = proto_coef.size(0) + if old_num_pos > cfg.masks_to_train: + perm = torch.randperm(proto_coef.size(0)) + select = perm[:cfg.masks_to_train] + + proto_coef = proto_coef[select, :] + pos_idx_t = pos_idx_t[select] + + if process_gt_bboxes: + pos_gt_box_t = pos_gt_box_t[select, :] + if cfg.use_mask_scoring: + mask_scores = mask_scores[select, :] + + num_pos = proto_coef.size(0) + mask_t = downsampled_masks[:, :, pos_idx_t] + label_t = labels[idx][pos_idx_t] + + # Size: [mask_h, mask_w, num_pos] + #pred_masks = proto_masks @ proto_coef.t() + pred_masks = torch.matmul(proto_masks, proto_coef.T) + pred_masks = cfg.mask_proto_mask_activation(pred_masks) + + if cfg.mask_proto_double_loss: + if cfg.mask_proto_mask_activation == activation_func.sigmoid: + pre_loss = F.binary_cross_entropy(torch.clamp(pred_masks, 0, 1), mask_t, reduction='sum') + else: + pre_loss = F.smooth_l1_loss(pred_masks, mask_t, reduction='sum') + + loss_m += cfg.mask_proto_double_loss_alpha * pre_loss + + if cfg.mask_proto_crop: + pred_masks = crop(pred_masks, pos_gt_box_t) + + if cfg.mask_proto_mask_activation == activation_func.sigmoid: + pre_loss = F.binary_cross_entropy(torch.clamp(pred_masks, 0, 1), mask_t, reduction='none') + else: + pre_loss = F.smooth_l1_loss(pred_masks, mask_t, reduction='none') + + if cfg.mask_proto_normalize_mask_loss_by_sqrt_area: + gt_area = torch.sum(mask_t, dim=(0, 1), keepdim=True) + pre_loss = pre_loss / (torch.sqrt(gt_area) + 0.0001) + + if cfg.mask_proto_reweight_mask_loss: + pre_loss = pre_loss * mask_reweighting[:, :, pos_idx_t] + + if cfg.mask_proto_normalize_emulate_roi_pooling: + weight = mask_h * mask_w if cfg.mask_proto_crop else 1 + pos_gt_csize = center_size(pos_gt_box_t) + gt_box_width = pos_gt_csize[:, 2] * mask_w + gt_box_height = pos_gt_csize[:, 3] * mask_h + pre_loss = pre_loss.sum(dim=(0, 1)) / gt_box_width / gt_box_height * weight + + # If the number of masks were limited scale the loss accordingly + if old_num_pos > num_pos: + pre_loss *= old_num_pos / num_pos + + loss_m += torch.sum(pre_loss) + + if cfg.use_maskiou: + if cfg.discard_mask_area > 0: + gt_mask_area = torch.sum(mask_t, dim=(0, 1)) + select = gt_mask_area > cfg.discard_mask_area + + if torch.sum(select) < 1: + continue + + pos_gt_box_t = pos_gt_box_t[select, :] + pred_masks = pred_masks[:, :, select] + mask_t = mask_t[:, :, select] + label_t = label_t[select] + + maskiou_net_input = pred_masks.permute(2, 0, 1).contiguous().unsqueeze(1) + pred_masks = pred_masks.gt(0.5).float() + maskiou_t = self._mask_iou(pred_masks, mask_t) + + maskiou_net_input_list.append(maskiou_net_input) + maskiou_t_list.append(maskiou_t) + label_t_list.append(label_t) + + losses = {'M': loss_m * cfg.mask_alpha / mask_h / mask_w} + + if cfg.mask_proto_coeff_diversity_loss: + losses['D'] = loss_d + + if cfg.use_maskiou: + # discard_mask_area discarded every mask in the batch, so nothing to do here + if len(maskiou_t_list) == 0: + return losses, None + + maskiou_t = torch.cat(maskiou_t_list) + label_t = torch.cat(label_t_list) + maskiou_net_input = torch.cat(maskiou_net_input_list) + + num_samples = maskiou_t.size(0) + if cfg.maskious_to_train > 0 and num_samples > cfg.maskious_to_train: + perm = torch.randperm(num_samples) + select = perm[:cfg.masks_to_train] + maskiou_t = maskiou_t[select] + label_t = label_t[select] + maskiou_net_input = maskiou_net_input[select] + + return losses, [maskiou_net_input, maskiou_t, label_t] + + return losses + + def _mask_iou(self, mask1, mask2): + intersection = torch.sum(mask1*mask2, dim=(0, 1)) + area1 = torch.sum(mask1, dim=(0, 1)) + area2 = torch.sum(mask2, dim=(0, 1)) + union = (area1 + area2) - intersection + ret = intersection / union + return ret + + def mask_iou_loss(self, net, maskiou_targets): + maskiou_net_input, maskiou_t, label_t = maskiou_targets + + maskiou_p = net.maskiou_net(maskiou_net_input) + + label_t = label_t[:, None] + maskiou_p = torch.gather(maskiou_p, dim=1, index=label_t).view(-1) + + loss_i = F.smooth_l1_loss(maskiou_p, maskiou_t, reduction='sum') + + return loss_i * cfg.maskiou_alpha diff --git a/PyTorch/contrib/cv/detection/YOLACT/modelzoo_level.txt b/PyTorch/contrib/cv/detection/YOLACT/modelzoo_level.txt index 282c3ff3b30404101a02cc86c5bfeb6308d198e7..c5c4a9d8001fae97c66831abcfdbe02dd6261c37 100644 --- a/PyTorch/contrib/cv/detection/YOLACT/modelzoo_level.txt +++ b/PyTorch/contrib/cv/detection/YOLACT/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PrecisionStatus:OK +FuncStatus:OK +PrecisionStatus:OK PerfStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/YOLACT/yolact.py b/PyTorch/contrib/cv/detection/YOLACT/yolact.py index e65f748d32a040c69ff12a17c19f62cde71fce6f..3174bde53609bcc463b977ab43dc7c3e3ec70e29 100644 --- a/PyTorch/contrib/cv/detection/YOLACT/yolact.py +++ b/PyTorch/contrib/cv/detection/YOLACT/yolact.py @@ -1,754 +1,754 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import torch, torchvision -import torch.nn as nn -import torch.nn.functional as F -from torchvision.models.resnet import Bottleneck -import numpy as np -from itertools import product -from math import sqrt -from typing import List -from collections import defaultdict - -from data.config import cfg, mask_type -from layers import Detect -from layers.interpolate import InterpolateModule -from backbone import construct_backbone - -import torch.backends.cudnn as cudnn -from utils import timer -from utils.functions import MovingAverage, make_net - -# This is required for Pytorch 1.0.1 on Windows to initialize Cuda on some driver versions. -# See the bug report here: https://github.com/pytorch/pytorch/issues/17108 - -# As of March 10, 2019, Pytorch DataParallel still doesn't support JIT Script Modules -use_jit = False -if not use_jit: - print('Multiple GPUs detected! Turning off JIT.') - -ScriptModuleWrapper = torch.jit.ScriptModule if use_jit else nn.Module -script_method_wrapper = torch.jit.script_method if use_jit else lambda fn, _rcn=None: fn - - - -class Concat(nn.Module): - def __init__(self, nets, extra_params): - super().__init__() - - self.nets = nn.ModuleList(nets) - self.extra_params = extra_params - - def forward(self, x): - # Concat each along the channel dimension - return torch.cat([net(x) for net in self.nets], dim=1, **self.extra_params) - -prior_cache = defaultdict(lambda: None) - -class PredictionModule(nn.Module): - """ - The (c) prediction module adapted from DSSD: - https://arxiv.org/pdf/1701.06659.pdf - - Note that this is slightly different to the module in the paper - because the Bottleneck block actually has a 3x3 convolution in - the middle instead of a 1x1 convolution. Though, I really can't - be arsed to implement it myself, and, who knows, this might be - better. - - Args: - - in_channels: The input feature size. - - out_channels: The output feature size (must be a multiple of 4). - - aspect_ratios: A list of lists of priorbox aspect ratios (one list per scale). - - scales: A list of priorbox scales relative to this layer's convsize. - For instance: If this layer has convouts of size 30x30 for - an image of size 600x600, the 'default' (scale - of 1) for this layer would produce bounding - boxes with an area of 20x20px. If the scale is - .5 on the other hand, this layer would consider - bounding boxes with area 10x10px, etc. - - parent: If parent is a PredictionModule, this module will use all the layers - from parent instead of from this module. - """ - - def __init__(self, in_channels, out_channels=1024, aspect_ratios=[[1]], scales=[1], parent=None, index=0): - super().__init__() - - self.num_classes = cfg.num_classes - self.mask_dim = cfg.mask_dim # Defined by Yolact - self.num_priors = sum(len(x)*len(scales) for x in aspect_ratios) - self.parent = [parent] # Don't include this in the state dict - self.index = index - self.num_heads = cfg.num_heads # Defined by Yolact - - if cfg.mask_proto_split_prototypes_by_head and cfg.mask_type == mask_type.lincomb: - self.mask_dim = self.mask_dim // self.num_heads - - if cfg.mask_proto_prototypes_as_features: - in_channels += self.mask_dim - - if parent is None: - if cfg.extra_head_net is None: - out_channels = in_channels - else: - self.upfeature, out_channels = make_net(in_channels, cfg.extra_head_net) - - if cfg.use_prediction_module: - self.block = Bottleneck(out_channels, out_channels // 4) - self.conv = nn.Conv2d(out_channels, out_channels, kernel_size=1, bias=True) - self.bn = nn.BatchNorm2d(out_channels) - - self.bbox_layer = nn.Conv2d(out_channels, self.num_priors * 4, **cfg.head_layer_params) - self.conf_layer = nn.Conv2d(out_channels, self.num_priors * self.num_classes, **cfg.head_layer_params) - self.mask_layer = nn.Conv2d(out_channels, self.num_priors * self.mask_dim, **cfg.head_layer_params) - - if cfg.use_mask_scoring: - self.score_layer = nn.Conv2d(out_channels, self.num_priors, **cfg.head_layer_params) - - if cfg.use_instance_coeff: - self.inst_layer = nn.Conv2d(out_channels, self.num_priors * cfg.num_instance_coeffs, **cfg.head_layer_params) - - # What is this ugly lambda doing in the middle of all this clean prediction module code? - def make_extra(num_layers): - if num_layers == 0: - return lambda x: x - else: - # Looks more complicated than it is. This just creates an array of num_layers alternating conv-relu - return nn.Sequential(*sum([[ - nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=1), - nn.ReLU(inplace=True) - ] for _ in range(num_layers)], [])) - - self.bbox_extra, self.conf_extra, self.mask_extra = [make_extra(x) for x in cfg.extra_layers] - - if cfg.mask_type == mask_type.lincomb and cfg.mask_proto_coeff_gate: - self.gate_layer = nn.Conv2d(out_channels, self.num_priors * self.mask_dim, kernel_size=3, padding=1) - - self.aspect_ratios = aspect_ratios - self.scales = scales - - self.priors = None - self.last_conv_size = None - self.last_img_size = None - - def forward(self, x): - """ - Args: - - x: The convOut from a layer in the backbone network - Size: [batch_size, in_channels, conv_h, conv_w]) - - Returns a tuple (bbox_coords, class_confs, mask_output, prior_boxes) with sizes - - bbox_coords: [batch_size, conv_h*conv_w*num_priors, 4] - - class_confs: [batch_size, conv_h*conv_w*num_priors, num_classes] - - mask_output: [batch_size, conv_h*conv_w*num_priors, mask_dim] - - prior_boxes: [conv_h*conv_w*num_priors, 4] - """ - # In case we want to use another module's layers - src = self if self.parent[0] is None else self.parent[0] - - conv_h = x.size(2) - conv_w = x.size(3) - - if cfg.extra_head_net is not None: - x = src.upfeature(x) - - if cfg.use_prediction_module: - # The two branches of PM design (c) - a = src.block(x) - - b = src.conv(x) - b = src.bn(b) - b = F.relu(b) - - # TODO: Possibly switch this out for a product - x = a + b - - bbox_x = src.bbox_extra(x) - conf_x = src.conf_extra(x) - mask_x = src.mask_extra(x) - - bbox = src.bbox_layer(bbox_x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, 4) - conf = src.conf_layer(conf_x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, self.num_classes) - - if cfg.eval_mask_branch: - mask = src.mask_layer(mask_x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, self.mask_dim) - else: - mask = torch.zeros(x.size(0), bbox.size(1), self.mask_dim, device=bbox.device) - - if cfg.use_mask_scoring: - score = src.score_layer(x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, 1) - - if cfg.use_instance_coeff: - inst = src.inst_layer(x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, cfg.num_instance_coeffs) - - # See box_utils.decode for an explanation of this - if cfg.use_yolo_regressors: - bbox[:, :, :2] = torch.sigmoid(bbox[:, :, :2]) - 0.5 - bbox[:, :, 0] /= conv_w - bbox[:, :, 1] /= conv_h - - if cfg.eval_mask_branch: - if cfg.mask_type == mask_type.direct: - mask = torch.sigmoid(mask) - elif cfg.mask_type == mask_type.lincomb: - mask = cfg.mask_proto_coeff_activation(mask) - - if cfg.mask_proto_coeff_gate: - gate = src.gate_layer(x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, self.mask_dim) - mask = mask * torch.sigmoid(gate) - - if cfg.mask_proto_split_prototypes_by_head and cfg.mask_type == mask_type.lincomb: - mask = F.pad(mask, (self.index * self.mask_dim, (self.num_heads - self.index - 1) * self.mask_dim), mode='constant', value=0) - - priors = self.make_priors(conv_h, conv_w, x.device) - - preds = { 'loc': bbox, 'conf': conf, 'mask': mask, 'priors': priors } - - if cfg.use_mask_scoring: - preds['score'] = score - - if cfg.use_instance_coeff: - preds['inst'] = inst - - return preds - - def make_priors(self, conv_h, conv_w, device): - """ Note that priors are [x,y,width,height] where (x,y) is the center of the box. """ - global prior_cache - size = (conv_h, conv_w) - - with timer.env('makepriors'): - if self.last_img_size != (cfg._tmp_img_w, cfg._tmp_img_h): - prior_data = [] - - # Iteration order is important (it has to sync up with the convout) - for j, i in product(range(conv_h), range(conv_w)): - # +0.5 because priors are in center-size notation - x = (i + 0.5) / conv_w - y = (j + 0.5) / conv_h - - for ars in self.aspect_ratios: - for scale in self.scales: - for ar in ars: - if not cfg.backbone.preapply_sqrt: - ar = sqrt(ar) - - if cfg.backbone.use_pixel_scales: - w = scale * ar / cfg.max_size - h = scale / ar / cfg.max_size - else: - w = scale * ar / conv_w - h = scale / ar / conv_h - - # This is for backward compatability with a bug where I made everything square by accident - if cfg.backbone.use_square_anchors: - h = w - - prior_data += [x, y, w, h] - - self.priors = torch.Tensor(prior_data).to(device).view(-1, 4).detach() - self.priors.requires_grad = False - self.last_img_size = (cfg._tmp_img_w, cfg._tmp_img_h) - self.last_conv_size = (conv_w, conv_h) - prior_cache[size] = None - elif self.priors.device != device: - # This whole weird situation is so that DataParalell doesn't copy the priors each iteration - if prior_cache[size] is None: - prior_cache[size] = {} - - if device not in prior_cache[size]: - prior_cache[size][device] = self.priors.to(device) - - self.priors = prior_cache[size][device] - - return self.priors - -class FPN(ScriptModuleWrapper): - """ - Implements a general version of the FPN introduced in - https://arxiv.org/pdf/1612.03144.pdf - - Parameters (in cfg.fpn): - - num_features (int): The number of output features in the fpn layers. - - interpolation_mode (str): The mode to pass to F.interpolate. - - num_downsample (int): The number of downsampled layers to add onto the selected layers. - These extra layers are downsampled from the last selected layer. - - Args: - - in_channels (list): For each conv layer you supply in the forward pass, - how many features will it have? - """ - __constants__ = ['interpolation_mode', 'num_downsample', 'use_conv_downsample', 'relu_pred_layers', - 'lat_layers', 'pred_layers', 'downsample_layers', 'relu_downsample_layers'] - - def __init__(self, in_channels): - super().__init__() - - self.lat_layers = nn.ModuleList([ - nn.Conv2d(x, cfg.fpn.num_features, kernel_size=1) - for x in reversed(in_channels) - ]) - - # This is here for backwards compatability - padding = 1 if cfg.fpn.pad else 0 - self.pred_layers = nn.ModuleList([ - nn.Conv2d(cfg.fpn.num_features, cfg.fpn.num_features, kernel_size=3, padding=padding) - for _ in in_channels - ]) - - if cfg.fpn.use_conv_downsample: - self.downsample_layers = nn.ModuleList([ - nn.Conv2d(cfg.fpn.num_features, cfg.fpn.num_features, kernel_size=3, padding=1, stride=2) - for _ in range(cfg.fpn.num_downsample) - ]) - - self.interpolation_mode = cfg.fpn.interpolation_mode - self.num_downsample = cfg.fpn.num_downsample - self.use_conv_downsample = cfg.fpn.use_conv_downsample - self.relu_downsample_layers = cfg.fpn.relu_downsample_layers - self.relu_pred_layers = cfg.fpn.relu_pred_layers - - @script_method_wrapper - def forward(self, convouts:List[torch.Tensor]): - """ - Args: - - convouts (list): A list of convouts for the corresponding layers in in_channels. - Returns: - - A list of FPN convouts in the same order as x with extra downsample layers if requested. - """ - - out = [] - x = torch.zeros(1, device=convouts[0].device) - for i in range(len(convouts)): - out.append(x) - - # For backward compatability, the conv layers are stored in reverse but the input and output is - # given in the correct order. Thus, use j=-i-1 for the input and output and i for the conv layers. - j = len(convouts) - for lat_layer in self.lat_layers: - j -= 1 - - if j < len(convouts) - 1: - _, _, h, w = convouts[j].size() - x = F.interpolate(x, size=(h, w), mode=self.interpolation_mode, align_corners=False) - - x = x + lat_layer(convouts[j]) - out[j] = x - - # This janky second loop is here because TorchScript. - j = len(convouts) - for pred_layer in self.pred_layers: - j -= 1 - out[j] = pred_layer(out[j]) - - if self.relu_pred_layers: - F.relu(out[j], inplace=True) - - cur_idx = len(out) - - # In the original paper, this takes care of P6 - if self.use_conv_downsample: - for downsample_layer in self.downsample_layers: - out.append(downsample_layer(out[-1])) - else: - for idx in range(self.num_downsample): - # Note: this is an untested alternative to out.append(out[-1][:, :, ::2, ::2]). Thanks TorchScript. - out.append(nn.functional.max_pool2d(out[-1], 1, stride=2)) - - if self.relu_downsample_layers: - for idx in range(len(out) - cur_idx): - out[idx] = F.relu(out[idx + cur_idx], inplace=False) - - return out - -class FastMaskIoUNet(ScriptModuleWrapper): - - def __init__(self): - super().__init__() - input_channels = 1 - last_layer = [(cfg.num_classes-1, 1, {})] - self.maskiou_net, _ = make_net(input_channels, cfg.maskiou_net + last_layer, include_last_relu=True) - - def forward(self, x): - x = self.maskiou_net(x) - maskiou_p = F.max_pool2d(x, kernel_size=x.size()[2:]).squeeze(-1).squeeze(-1) - - return maskiou_p - - - -class Yolact(nn.Module): - """ - - - ██╗ ██╗ ██████╗ ██╗ █████╗ ██████╗████████╗ - ╚██╗ ██╔╝██╔═══██╗██║ ██╔══██╗██╔════╝╚══██╔══╝ - ╚████╔╝ ██║ ██║██║ ███████║██║ ██║ - ╚██╔╝ ██║ ██║██║ ██╔══██║██║ ██║ - ██║ ╚██████╔╝███████╗██║ ██║╚██████╗ ██║ - ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ - - - You can set the arguments by changing them in the backbone config object in config.py. - - Parameters (in cfg.backbone): - - selected_layers: The indices of the conv layers to use for prediction. - - pred_scales: A list with len(selected_layers) containing tuples of scales (see PredictionModule) - - pred_aspect_ratios: A list of lists of aspect ratios with len(selected_layers) (see PredictionModule) - """ - - def __init__(self): - super().__init__() - - self.backbone = construct_backbone(cfg.backbone) #backbone: resnetbackbone. backbone_modules:{list:104}. bn1:{BatchNorm2d} - - if cfg.freeze_bn: # it's true - self.freeze_bn() - - # Compute mask_dim here and add it back to the config. Make sure Yolact's constructor is called early! - if cfg.mask_type == mask_type.direct: - cfg.mask_dim = cfg.mask_size**2 - elif cfg.mask_type == mask_type.lincomb: # the module will execute this branch - if cfg.mask_proto_use_grid: - self.grid = torch.Tensor(np.load(cfg.mask_proto_grid_file)) - self.num_grids = self.grid.size(0) - else: # the module will execute this branch - self.num_grids = 0 - - self.proto_src = cfg.mask_proto_src - - if self.proto_src is None: in_channels = 3 - elif cfg.fpn is not None: in_channels = cfg.fpn.num_features - else: in_channels = self.backbone.channels[self.proto_src] - in_channels += self.num_grids - #in_channels will be 256 - # The include_last_relu=false here is because we might want to change it to another function - self.proto_net, cfg.mask_dim = make_net(in_channels, cfg.mask_proto_net, include_last_relu=False) - - if cfg.mask_proto_bias: - cfg.mask_dim += 1 - - - self.selected_layers = cfg.backbone.selected_layers - src_channels = self.backbone.channels - - if cfg.use_maskiou: #false - self.maskiou_net = FastMaskIoUNet() - - if cfg.fpn is not None: #true - # Some hacky rewiring to accomodate the FPN - self.fpn = FPN([src_channels[i] for i in self.selected_layers]) - self.selected_layers = list(range(len(self.selected_layers) + cfg.fpn.num_downsample)) - src_channels = [cfg.fpn.num_features] * len(self.selected_layers) - - - self.prediction_layers = nn.ModuleList() - cfg.num_heads = len(self.selected_layers) - - for idx, layer_idx in enumerate(self.selected_layers): - # If we're sharing prediction module weights, have every module's parent be the first one - parent = None - if cfg.share_prediction_module and idx > 0: #cfg.share_prediction_module is True - parent = self.prediction_layers[0] - - pred = PredictionModule(src_channels[layer_idx], src_channels[layer_idx], - aspect_ratios = cfg.backbone.pred_aspect_ratios[idx], - scales = cfg.backbone.pred_scales[idx], - parent = parent, - index = idx) - self.prediction_layers.append(pred) - - # Extra parameters for the extra losses - if cfg.use_class_existence_loss: #false - # This comes from the smallest layer selected - # Also note that cfg.num_classes includes background - self.class_existence_fc = nn.Linear(src_channels[-1], cfg.num_classes - 1) - - if cfg.use_semantic_segmentation_loss: #true - self.semantic_seg_conv = nn.Conv2d(src_channels[0], cfg.num_classes-1, kernel_size=1) - - # For use in evaluation - self.detect = Detect(cfg.num_classes, bkg_label=0, top_k=cfg.nms_top_k, - conf_thresh=cfg.nms_conf_thresh, nms_thresh=cfg.nms_thresh) - - def save_weights(self, path): - """ Saves the model's weights using compression because the file sizes were getting too big. """ - torch.save(self.state_dict(), path) - - def load_weights(self, path, useCuda = True): - """ Loads weights from a compressed save file. """ - state_dict = torch.load(path) if useCuda else torch.load(path, map_location=torch.device('cpu')) - - # For backward compatability, remove these (the new variable is called layers) - for key in list(state_dict.keys()): - if key.startswith('backbone.layer') and not key.startswith('backbone.layers'): - del state_dict[key] - - # Also for backward compatibility with v1.0 weights, do this check - if key.startswith('fpn.downsample_layers.'): - if cfg.fpn is not None and int(key.split('.')[2]) >= cfg.fpn.num_downsample: - del state_dict[key] - self.load_state_dict(state_dict) - - def init_weights(self, backbone_path): - """ Initialize weights for training. """ - # Initialize the backbone with the pretrained weights. - self.backbone.init_backbone(backbone_path) - - conv_constants = getattr(nn.Conv2d(1, 1, 1), '__constants__') - - # Quick lambda to test if one list contains the other - def all_in(x, y): - for _x in x: - if _x not in y: - return False - return True - - # Initialize the rest of the conv layers with xavier - for name, module in self.named_modules(): - # See issue #127 for why we need such a complicated condition if the module is a WeakScriptModuleProxy - # Broke in 1.3 (see issue #175), WeakScriptModuleProxy was turned into just ScriptModule. - # Broke in 1.4 (see issue #292), where RecursiveScriptModule is the new star of the show. - # Note that this might break with future pytorch updates, so let me know if it does - is_script_conv = False - if 'Script' in type(module).__name__: - # 1.4 workaround: now there's an original_name member so just use that - if hasattr(module, 'original_name'): - is_script_conv = 'Conv' in module.original_name - # 1.3 workaround: check if this has the same constants as a conv module - else: - is_script_conv = ( - all_in(module.__dict__['_constants_set'], conv_constants) - and all_in(conv_constants, module.__dict__['_constants_set'])) - - is_conv_layer = isinstance(module, nn.Conv2d) or is_script_conv - - if is_conv_layer and module not in self.backbone.backbone_modules: - nn.init.xavier_uniform_(module.weight.data) - - if module.bias is not None: - if cfg.use_focal_loss and 'conf_layer' in name: - if not cfg.use_sigmoid_focal_loss: - # Initialize the last layer as in the focal loss paper. - # Because we use softmax and not sigmoid, I had to derive an alternate expression - # on a notecard. Define pi to be the probability of outputting a foreground detection. - # Then let z = sum(exp(x)) - exp(x_0). Finally let c be the number of foreground classes. - # Chugging through the math, this gives us - # x_0 = log(z * (1 - pi) / pi) where 0 is the background class - # x_i = log(z / c) for all i > 0 - # For simplicity (and because we have a degree of freedom here), set z = 1. Then we have - # x_0 = log((1 - pi) / pi) note: don't split up the log for numerical stability - # x_i = -log(c) for all i > 0 - module.bias.data[0] = np.log((1 - cfg.focal_loss_init_pi) / cfg.focal_loss_init_pi) - module.bias.data[1:] = -np.log(module.bias.size(0) - 1) - else: - module.bias.data[0] = -np.log(cfg.focal_loss_init_pi / (1 - cfg.focal_loss_init_pi)) - module.bias.data[1:] = -np.log((1 - cfg.focal_loss_init_pi) / cfg.focal_loss_init_pi) - else: - module.bias.data.zero_() - - def train(self, mode=True): - super().train(mode) - - if cfg.freeze_bn: - self.freeze_bn() - - def freeze_bn(self, enable=False): - """ Adapted from https://discuss.pytorch.org/t/how-to-train-with-frozen-batchnorm/12106/8 """ - for module in self.modules(): - if isinstance(module, nn.BatchNorm2d): - module.train() if enable else module.eval() - - module.weight.requires_grad = enable - module.bias.requires_grad = enable - - def forward(self, x): - """ The input should be of size [batch_size, 3, img_h, img_w] """ - _, _, img_h, img_w = x.size() - cfg._tmp_img_h = img_h - cfg._tmp_img_w = img_w - - with timer.env('backbone'): - outs = self.backbone(x) - - if cfg.fpn is not None: - with timer.env('fpn'): - # Use backbone.selected_layers because we overwrote self.selected_layers - outs = [outs[i] for i in cfg.backbone.selected_layers] - outs = self.fpn(outs) - - proto_out = None - if cfg.mask_type == mask_type.lincomb and cfg.eval_mask_branch: - with timer.env('proto'): - proto_x = x if self.proto_src is None else outs[self.proto_src] - - if self.num_grids > 0: - grids = self.grid.repeat(proto_x.size(0), 1, 1, 1) - proto_x = torch.cat([proto_x, grids], dim=1) - - proto_out = self.proto_net(proto_x) - proto_out = cfg.mask_proto_prototype_activation(proto_out) - - if cfg.mask_proto_prototypes_as_features: - # Clone here because we don't want to permute this, though idk if contiguous makes this unnecessary - proto_downsampled = proto_out.clone() - - if cfg.mask_proto_prototypes_as_features_no_grad: - proto_downsampled = proto_out.detach() - - # Move the features last so the multiplication is easy - proto_out = proto_out.permute(0, 2, 3, 1).contiguous() - - if cfg.mask_proto_bias: - bias_shape = [x for x in proto_out.size()] - bias_shape[-1] = 1 - proto_out = torch.cat([proto_out, torch.ones(*bias_shape)], -1) - - - with timer.env('pred_heads'): - pred_outs = { 'loc': [], 'conf': [], 'mask': [], 'priors': [] } - - if cfg.use_mask_scoring: - pred_outs['score'] = [] - - if cfg.use_instance_coeff: - pred_outs['inst'] = [] - - for idx, pred_layer in zip(self.selected_layers, self.prediction_layers): - pred_x = outs[idx] - - if cfg.mask_type == mask_type.lincomb and cfg.mask_proto_prototypes_as_features: - # Scale the prototypes down to the current prediction layer's size and add it as inputs - proto_downsampled = F.interpolate(proto_downsampled, size=outs[idx].size()[2:], mode='bilinear', align_corners=False) - pred_x = torch.cat([pred_x, proto_downsampled], dim=1) - - # A hack for the way dataparallel works - if cfg.share_prediction_module and pred_layer is not self.prediction_layers[0]: - pred_layer.parent = [self.prediction_layers[0]] - - p = pred_layer(pred_x) - - for k, v in p.items(): - pred_outs[k].append(v) - - for k, v in pred_outs.items(): - pred_outs[k] = torch.cat(v, -2) - - if proto_out is not None: - pred_outs['proto'] = proto_out - - if self.training: - # For the extra loss functions - if cfg.use_class_existence_loss: - pred_outs['classes'] = self.class_existence_fc(outs[-1].mean(dim=(2, 3))) - - if cfg.use_semantic_segmentation_loss: - pred_outs['segm'] = self.semantic_seg_conv(outs[0]) - - return pred_outs - else: - if cfg.use_mask_scoring: - pred_outs['score'] = torch.sigmoid(pred_outs['score']) - - if cfg.use_focal_loss: - if cfg.use_sigmoid_focal_loss: - # Note: even though conf[0] exists, this mode doesn't train it so don't use it - pred_outs['conf'] = torch.sigmoid(pred_outs['conf']) - if cfg.use_mask_scoring: - pred_outs['conf'] *= pred_outs['score'] - elif cfg.use_objectness_score: - # See focal_loss_sigmoid in multibox_loss.py for details - objectness = torch.sigmoid(pred_outs['conf'][:, :, 0]) - pred_outs['conf'][:, :, 1:] = objectness[:, :, None] * F.softmax(pred_outs['conf'][:, :, 1:], -1) - pred_outs['conf'][:, :, 0 ] = 1 - objectness - else: - pred_outs['conf'] = F.softmax(pred_outs['conf'], -1) - else: - - if cfg.use_objectness_score: - objectness = torch.sigmoid(pred_outs['conf'][:, :, 0]) - - pred_outs['conf'][:, :, 1:] = (objectness > 0.10)[..., None] \ - * F.softmax(pred_outs['conf'][:, :, 1:], dim=-1) - - else: - pred_outs['conf'] = F.softmax(pred_outs['conf'], -1) - - return self.detect(pred_outs) - - - - -# Some testing code -if __name__ == '__main__': - from utils.functions import init_console - init_console() - - # Use the first argument to set the config if you want - import sys - if len(sys.argv) > 1: - from data.config import set_cfg - set_cfg(sys.argv[1]) - - net = Yolact() - net.train() - net.init_weights(backbone_path='weights/' + cfg.backbone.path) - - # GPU - net = net.cuda() - torch.set_default_tensor_type('torch.cuda.FloatTensor') - - x = torch.zeros((1, 3, cfg.max_size, cfg.max_size)) - y = net(x) - - for p in net.prediction_layers: - print(p.last_conv_size) - - print() - for k, a in y.items(): - print(k + ': ', a.size(), torch.sum(a)) - exit() - - net(x) - # timer.disable('pass2') - avg = MovingAverage() - try: - while True: - timer.reset() - with timer.env('everything else'): - net(x) - avg.add(timer.total_time()) - print('\033[2J') # Moves console cursor to 0,0 - timer.print_stats() - print('Avg fps: %.2f\tAvg ms: %.2f ' % (1/avg.get_avg(), avg.get_avg()*1000)) - except KeyboardInterrupt: - pass +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import torch, torchvision +import torch.nn as nn +import torch.nn.functional as F +from torchvision.models.resnet import Bottleneck +import numpy as np +from itertools import product +from math import sqrt +from typing import List +from collections import defaultdict + +from data.config import cfg, mask_type +from layers import Detect +from layers.interpolate import InterpolateModule +from backbone import construct_backbone + +import torch.backends.cudnn as cudnn +from utils import timer +from utils.functions import MovingAverage, make_net + +# This is required for Pytorch 1.0.1 on Windows to initialize Cuda on some driver versions. +# See the bug report here: https://github.com/pytorch/pytorch/issues/17108 + +# As of March 10, 2019, Pytorch DataParallel still doesn't support JIT Script Modules +use_jit = False +if not use_jit: + print('Multiple GPUs detected! Turning off JIT.') + +ScriptModuleWrapper = torch.jit.ScriptModule if use_jit else nn.Module +script_method_wrapper = torch.jit.script_method if use_jit else lambda fn, _rcn=None: fn + + + +class Concat(nn.Module): + def __init__(self, nets, extra_params): + super().__init__() + + self.nets = nn.ModuleList(nets) + self.extra_params = extra_params + + def forward(self, x): + # Concat each along the channel dimension + return torch.cat([net(x) for net in self.nets], dim=1, **self.extra_params) + +prior_cache = defaultdict(lambda: None) + +class PredictionModule(nn.Module): + """ + The (c) prediction module adapted from DSSD: + https://arxiv.org/pdf/1701.06659.pdf + + Note that this is slightly different to the module in the paper + because the Bottleneck block actually has a 3x3 convolution in + the middle instead of a 1x1 convolution. Though, I really can't + be arsed to implement it myself, and, who knows, this might be + better. + + Args: + - in_channels: The input feature size. + - out_channels: The output feature size (must be a multiple of 4). + - aspect_ratios: A list of lists of priorbox aspect ratios (one list per scale). + - scales: A list of priorbox scales relative to this layer's convsize. + For instance: If this layer has convouts of size 30x30 for + an image of size 600x600, the 'default' (scale + of 1) for this layer would produce bounding + boxes with an area of 20x20px. If the scale is + .5 on the other hand, this layer would consider + bounding boxes with area 10x10px, etc. + - parent: If parent is a PredictionModule, this module will use all the layers + from parent instead of from this module. + """ + + def __init__(self, in_channels, out_channels=1024, aspect_ratios=[[1]], scales=[1], parent=None, index=0): + super().__init__() + + self.num_classes = cfg.num_classes + self.mask_dim = cfg.mask_dim # Defined by Yolact + self.num_priors = sum(len(x)*len(scales) for x in aspect_ratios) + self.parent = [parent] # Don't include this in the state dict + self.index = index + self.num_heads = cfg.num_heads # Defined by Yolact + + if cfg.mask_proto_split_prototypes_by_head and cfg.mask_type == mask_type.lincomb: + self.mask_dim = self.mask_dim // self.num_heads + + if cfg.mask_proto_prototypes_as_features: + in_channels += self.mask_dim + + if parent is None: + if cfg.extra_head_net is None: + out_channels = in_channels + else: + self.upfeature, out_channels = make_net(in_channels, cfg.extra_head_net) + + if cfg.use_prediction_module: + self.block = Bottleneck(out_channels, out_channels // 4) + self.conv = nn.Conv2d(out_channels, out_channels, kernel_size=1, bias=True) + self.bn = nn.BatchNorm2d(out_channels) + + self.bbox_layer = nn.Conv2d(out_channels, self.num_priors * 4, **cfg.head_layer_params) + self.conf_layer = nn.Conv2d(out_channels, self.num_priors * self.num_classes, **cfg.head_layer_params) + self.mask_layer = nn.Conv2d(out_channels, self.num_priors * self.mask_dim, **cfg.head_layer_params) + + if cfg.use_mask_scoring: + self.score_layer = nn.Conv2d(out_channels, self.num_priors, **cfg.head_layer_params) + + if cfg.use_instance_coeff: + self.inst_layer = nn.Conv2d(out_channels, self.num_priors * cfg.num_instance_coeffs, **cfg.head_layer_params) + + # What is this ugly lambda doing in the middle of all this clean prediction module code? + def make_extra(num_layers): + if num_layers == 0: + return lambda x: x + else: + # Looks more complicated than it is. This just creates an array of num_layers alternating conv-relu + return nn.Sequential(*sum([[ + nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=1), + nn.ReLU(inplace=True) + ] for _ in range(num_layers)], [])) + + self.bbox_extra, self.conf_extra, self.mask_extra = [make_extra(x) for x in cfg.extra_layers] + + if cfg.mask_type == mask_type.lincomb and cfg.mask_proto_coeff_gate: + self.gate_layer = nn.Conv2d(out_channels, self.num_priors * self.mask_dim, kernel_size=3, padding=1) + + self.aspect_ratios = aspect_ratios + self.scales = scales + + self.priors = None + self.last_conv_size = None + self.last_img_size = None + + def forward(self, x): + """ + Args: + - x: The convOut from a layer in the backbone network + Size: [batch_size, in_channels, conv_h, conv_w]) + + Returns a tuple (bbox_coords, class_confs, mask_output, prior_boxes) with sizes + - bbox_coords: [batch_size, conv_h*conv_w*num_priors, 4] + - class_confs: [batch_size, conv_h*conv_w*num_priors, num_classes] + - mask_output: [batch_size, conv_h*conv_w*num_priors, mask_dim] + - prior_boxes: [conv_h*conv_w*num_priors, 4] + """ + # In case we want to use another module's layers + src = self if self.parent[0] is None else self.parent[0] + + conv_h = x.size(2) + conv_w = x.size(3) + + if cfg.extra_head_net is not None: + x = src.upfeature(x) + + if cfg.use_prediction_module: + # The two branches of PM design (c) + a = src.block(x) + + b = src.conv(x) + b = src.bn(b) + b = F.relu(b) + + # TODO: Possibly switch this out for a product + x = a + b + + bbox_x = src.bbox_extra(x) + conf_x = src.conf_extra(x) + mask_x = src.mask_extra(x) + + bbox = src.bbox_layer(bbox_x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, 4) + conf = src.conf_layer(conf_x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, self.num_classes) + + if cfg.eval_mask_branch: + mask = src.mask_layer(mask_x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, self.mask_dim) + else: + mask = torch.zeros(x.size(0), bbox.size(1), self.mask_dim, device=bbox.device) + + if cfg.use_mask_scoring: + score = src.score_layer(x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, 1) + + if cfg.use_instance_coeff: + inst = src.inst_layer(x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, cfg.num_instance_coeffs) + + # See box_utils.decode for an explanation of this + if cfg.use_yolo_regressors: + bbox[:, :, :2] = torch.sigmoid(bbox[:, :, :2]) - 0.5 + bbox[:, :, 0] /= conv_w + bbox[:, :, 1] /= conv_h + + if cfg.eval_mask_branch: + if cfg.mask_type == mask_type.direct: + mask = torch.sigmoid(mask) + elif cfg.mask_type == mask_type.lincomb: + mask = cfg.mask_proto_coeff_activation(mask) + + if cfg.mask_proto_coeff_gate: + gate = src.gate_layer(x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, self.mask_dim) + mask = mask * torch.sigmoid(gate) + + if cfg.mask_proto_split_prototypes_by_head and cfg.mask_type == mask_type.lincomb: + mask = F.pad(mask, (self.index * self.mask_dim, (self.num_heads - self.index - 1) * self.mask_dim), mode='constant', value=0) + + priors = self.make_priors(conv_h, conv_w, x.device) + + preds = { 'loc': bbox, 'conf': conf, 'mask': mask, 'priors': priors } + + if cfg.use_mask_scoring: + preds['score'] = score + + if cfg.use_instance_coeff: + preds['inst'] = inst + + return preds + + def make_priors(self, conv_h, conv_w, device): + """ Note that priors are [x,y,width,height] where (x,y) is the center of the box. """ + global prior_cache + size = (conv_h, conv_w) + + with timer.env('makepriors'): + if self.last_img_size != (cfg._tmp_img_w, cfg._tmp_img_h): + prior_data = [] + + # Iteration order is important (it has to sync up with the convout) + for j, i in product(range(conv_h), range(conv_w)): + # +0.5 because priors are in center-size notation + x = (i + 0.5) / conv_w + y = (j + 0.5) / conv_h + + for ars in self.aspect_ratios: + for scale in self.scales: + for ar in ars: + if not cfg.backbone.preapply_sqrt: + ar = sqrt(ar) + + if cfg.backbone.use_pixel_scales: + w = scale * ar / cfg.max_size + h = scale / ar / cfg.max_size + else: + w = scale * ar / conv_w + h = scale / ar / conv_h + + # This is for backward compatability with a bug where I made everything square by accident + if cfg.backbone.use_square_anchors: + h = w + + prior_data += [x, y, w, h] + + self.priors = torch.Tensor(prior_data).to(device).view(-1, 4).detach() + self.priors.requires_grad = False + self.last_img_size = (cfg._tmp_img_w, cfg._tmp_img_h) + self.last_conv_size = (conv_w, conv_h) + prior_cache[size] = None + elif self.priors.device != device: + # This whole weird situation is so that DataParalell doesn't copy the priors each iteration + if prior_cache[size] is None: + prior_cache[size] = {} + + if device not in prior_cache[size]: + prior_cache[size][device] = self.priors.to(device) + + self.priors = prior_cache[size][device] + + return self.priors + +class FPN(ScriptModuleWrapper): + """ + Implements a general version of the FPN introduced in + https://arxiv.org/pdf/1612.03144.pdf + + Parameters (in cfg.fpn): + - num_features (int): The number of output features in the fpn layers. + - interpolation_mode (str): The mode to pass to F.interpolate. + - num_downsample (int): The number of downsampled layers to add onto the selected layers. + These extra layers are downsampled from the last selected layer. + + Args: + - in_channels (list): For each conv layer you supply in the forward pass, + how many features will it have? + """ + __constants__ = ['interpolation_mode', 'num_downsample', 'use_conv_downsample', 'relu_pred_layers', + 'lat_layers', 'pred_layers', 'downsample_layers', 'relu_downsample_layers'] + + def __init__(self, in_channels): + super().__init__() + + self.lat_layers = nn.ModuleList([ + nn.Conv2d(x, cfg.fpn.num_features, kernel_size=1) + for x in reversed(in_channels) + ]) + + # This is here for backwards compatability + padding = 1 if cfg.fpn.pad else 0 + self.pred_layers = nn.ModuleList([ + nn.Conv2d(cfg.fpn.num_features, cfg.fpn.num_features, kernel_size=3, padding=padding) + for _ in in_channels + ]) + + if cfg.fpn.use_conv_downsample: + self.downsample_layers = nn.ModuleList([ + nn.Conv2d(cfg.fpn.num_features, cfg.fpn.num_features, kernel_size=3, padding=1, stride=2) + for _ in range(cfg.fpn.num_downsample) + ]) + + self.interpolation_mode = cfg.fpn.interpolation_mode + self.num_downsample = cfg.fpn.num_downsample + self.use_conv_downsample = cfg.fpn.use_conv_downsample + self.relu_downsample_layers = cfg.fpn.relu_downsample_layers + self.relu_pred_layers = cfg.fpn.relu_pred_layers + + @script_method_wrapper + def forward(self, convouts:List[torch.Tensor]): + """ + Args: + - convouts (list): A list of convouts for the corresponding layers in in_channels. + Returns: + - A list of FPN convouts in the same order as x with extra downsample layers if requested. + """ + + out = [] + x = torch.zeros(1, device=convouts[0].device) + for i in range(len(convouts)): + out.append(x) + + # For backward compatability, the conv layers are stored in reverse but the input and output is + # given in the correct order. Thus, use j=-i-1 for the input and output and i for the conv layers. + j = len(convouts) + for lat_layer in self.lat_layers: + j -= 1 + + if j < len(convouts) - 1: + _, _, h, w = convouts[j].size() + x = F.interpolate(x, size=(h, w), mode=self.interpolation_mode, align_corners=False) + + x = x + lat_layer(convouts[j]) + out[j] = x + + # This janky second loop is here because TorchScript. + j = len(convouts) + for pred_layer in self.pred_layers: + j -= 1 + out[j] = pred_layer(out[j]) + + if self.relu_pred_layers: + F.relu(out[j], inplace=True) + + cur_idx = len(out) + + # In the original paper, this takes care of P6 + if self.use_conv_downsample: + for downsample_layer in self.downsample_layers: + out.append(downsample_layer(out[-1])) + else: + for idx in range(self.num_downsample): + # Note: this is an untested alternative to out.append(out[-1][:, :, ::2, ::2]). Thanks TorchScript. + out.append(nn.functional.max_pool2d(out[-1], 1, stride=2)) + + if self.relu_downsample_layers: + for idx in range(len(out) - cur_idx): + out[idx] = F.relu(out[idx + cur_idx], inplace=False) + + return out + +class FastMaskIoUNet(ScriptModuleWrapper): + + def __init__(self): + super().__init__() + input_channels = 1 + last_layer = [(cfg.num_classes-1, 1, {})] + self.maskiou_net, _ = make_net(input_channels, cfg.maskiou_net + last_layer, include_last_relu=True) + + def forward(self, x): + x = self.maskiou_net(x) + maskiou_p = F.max_pool2d(x, kernel_size=x.size()[2:]).squeeze(-1).squeeze(-1) + + return maskiou_p + + + +class Yolact(nn.Module): + """ + + + ██╗ ██╗ ██████╗ ██╗ █████╗ ██████╗████████╗ + ╚██╗ ██╔╝██╔═══██╗██║ ██╔══██╗██╔════╝╚══██╔══╝ + ╚████╔╝ ██║ ██║██║ ███████║██║ ██║ + ╚██╔╝ ██║ ██║██║ ██╔══██║██║ ██║ + ██║ ╚██████╔╝███████╗██║ ██║╚██████╗ ██║ + ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ + + + You can set the arguments by changing them in the backbone config object in config.py. + + Parameters (in cfg.backbone): + - selected_layers: The indices of the conv layers to use for prediction. + - pred_scales: A list with len(selected_layers) containing tuples of scales (see PredictionModule) + - pred_aspect_ratios: A list of lists of aspect ratios with len(selected_layers) (see PredictionModule) + """ + + def __init__(self): + super().__init__() + + self.backbone = construct_backbone(cfg.backbone) #backbone: resnetbackbone. backbone_modules:{list:104}. bn1:{BatchNorm2d} + + if cfg.freeze_bn: # it's true + self.freeze_bn() + + # Compute mask_dim here and add it back to the config. Make sure Yolact's constructor is called early! + if cfg.mask_type == mask_type.direct: + cfg.mask_dim = cfg.mask_size**2 + elif cfg.mask_type == mask_type.lincomb: # the module will execute this branch + if cfg.mask_proto_use_grid: + self.grid = torch.Tensor(np.load(cfg.mask_proto_grid_file)) + self.num_grids = self.grid.size(0) + else: # the module will execute this branch + self.num_grids = 0 + + self.proto_src = cfg.mask_proto_src + + if self.proto_src is None: in_channels = 3 + elif cfg.fpn is not None: in_channels = cfg.fpn.num_features + else: in_channels = self.backbone.channels[self.proto_src] + in_channels += self.num_grids + #in_channels will be 256 + # The include_last_relu=false here is because we might want to change it to another function + self.proto_net, cfg.mask_dim = make_net(in_channels, cfg.mask_proto_net, include_last_relu=False) + + if cfg.mask_proto_bias: + cfg.mask_dim += 1 + + + self.selected_layers = cfg.backbone.selected_layers + src_channels = self.backbone.channels + + if cfg.use_maskiou: #false + self.maskiou_net = FastMaskIoUNet() + + if cfg.fpn is not None: #true + # Some hacky rewiring to accomodate the FPN + self.fpn = FPN([src_channels[i] for i in self.selected_layers]) + self.selected_layers = list(range(len(self.selected_layers) + cfg.fpn.num_downsample)) + src_channels = [cfg.fpn.num_features] * len(self.selected_layers) + + + self.prediction_layers = nn.ModuleList() + cfg.num_heads = len(self.selected_layers) + + for idx, layer_idx in enumerate(self.selected_layers): + # If we're sharing prediction module weights, have every module's parent be the first one + parent = None + if cfg.share_prediction_module and idx > 0: #cfg.share_prediction_module is True + parent = self.prediction_layers[0] + + pred = PredictionModule(src_channels[layer_idx], src_channels[layer_idx], + aspect_ratios = cfg.backbone.pred_aspect_ratios[idx], + scales = cfg.backbone.pred_scales[idx], + parent = parent, + index = idx) + self.prediction_layers.append(pred) + + # Extra parameters for the extra losses + if cfg.use_class_existence_loss: #false + # This comes from the smallest layer selected + # Also note that cfg.num_classes includes background + self.class_existence_fc = nn.Linear(src_channels[-1], cfg.num_classes - 1) + + if cfg.use_semantic_segmentation_loss: #true + self.semantic_seg_conv = nn.Conv2d(src_channels[0], cfg.num_classes-1, kernel_size=1) + + # For use in evaluation + self.detect = Detect(cfg.num_classes, bkg_label=0, top_k=cfg.nms_top_k, + conf_thresh=cfg.nms_conf_thresh, nms_thresh=cfg.nms_thresh) + + def save_weights(self, path): + """ Saves the model's weights using compression because the file sizes were getting too big. """ + torch.save(self.state_dict(), path) + + def load_weights(self, path, useCuda = True): + """ Loads weights from a compressed save file. """ + state_dict = torch.load(path) if useCuda else torch.load(path, map_location=torch.device('cpu')) + + # For backward compatability, remove these (the new variable is called layers) + for key in list(state_dict.keys()): + if key.startswith('backbone.layer') and not key.startswith('backbone.layers'): + del state_dict[key] + + # Also for backward compatibility with v1.0 weights, do this check + if key.startswith('fpn.downsample_layers.'): + if cfg.fpn is not None and int(key.split('.')[2]) >= cfg.fpn.num_downsample: + del state_dict[key] + self.load_state_dict(state_dict) + + def init_weights(self, backbone_path): + """ Initialize weights for training. """ + # Initialize the backbone with the pretrained weights. + self.backbone.init_backbone(backbone_path) + + conv_constants = getattr(nn.Conv2d(1, 1, 1), '__constants__') + + # Quick lambda to test if one list contains the other + def all_in(x, y): + for _x in x: + if _x not in y: + return False + return True + + # Initialize the rest of the conv layers with xavier + for name, module in self.named_modules(): + # See issue #127 for why we need such a complicated condition if the module is a WeakScriptModuleProxy + # Broke in 1.3 (see issue #175), WeakScriptModuleProxy was turned into just ScriptModule. + # Broke in 1.4 (see issue #292), where RecursiveScriptModule is the new star of the show. + # Note that this might break with future pytorch updates, so let me know if it does + is_script_conv = False + if 'Script' in type(module).__name__: + # 1.4 workaround: now there's an original_name member so just use that + if hasattr(module, 'original_name'): + is_script_conv = 'Conv' in module.original_name + # 1.3 workaround: check if this has the same constants as a conv module + else: + is_script_conv = ( + all_in(module.__dict__['_constants_set'], conv_constants) + and all_in(conv_constants, module.__dict__['_constants_set'])) + + is_conv_layer = isinstance(module, nn.Conv2d) or is_script_conv + + if is_conv_layer and module not in self.backbone.backbone_modules: + nn.init.xavier_uniform_(module.weight.data) + + if module.bias is not None: + if cfg.use_focal_loss and 'conf_layer' in name: + if not cfg.use_sigmoid_focal_loss: + # Initialize the last layer as in the focal loss paper. + # Because we use softmax and not sigmoid, I had to derive an alternate expression + # on a notecard. Define pi to be the probability of outputting a foreground detection. + # Then let z = sum(exp(x)) - exp(x_0). Finally let c be the number of foreground classes. + # Chugging through the math, this gives us + # x_0 = log(z * (1 - pi) / pi) where 0 is the background class + # x_i = log(z / c) for all i > 0 + # For simplicity (and because we have a degree of freedom here), set z = 1. Then we have + # x_0 = log((1 - pi) / pi) note: don't split up the log for numerical stability + # x_i = -log(c) for all i > 0 + module.bias.data[0] = np.log((1 - cfg.focal_loss_init_pi) / cfg.focal_loss_init_pi) + module.bias.data[1:] = -np.log(module.bias.size(0) - 1) + else: + module.bias.data[0] = -np.log(cfg.focal_loss_init_pi / (1 - cfg.focal_loss_init_pi)) + module.bias.data[1:] = -np.log((1 - cfg.focal_loss_init_pi) / cfg.focal_loss_init_pi) + else: + module.bias.data.zero_() + + def train(self, mode=True): + super().train(mode) + + if cfg.freeze_bn: + self.freeze_bn() + + def freeze_bn(self, enable=False): + """ Adapted from https://discuss.pytorch.org/t/how-to-train-with-frozen-batchnorm/12106/8 """ + for module in self.modules(): + if isinstance(module, nn.BatchNorm2d): + module.train() if enable else module.eval() + + module.weight.requires_grad = enable + module.bias.requires_grad = enable + + def forward(self, x): + """ The input should be of size [batch_size, 3, img_h, img_w] """ + _, _, img_h, img_w = x.size() + cfg._tmp_img_h = img_h + cfg._tmp_img_w = img_w + + with timer.env('backbone'): + outs = self.backbone(x) + + if cfg.fpn is not None: + with timer.env('fpn'): + # Use backbone.selected_layers because we overwrote self.selected_layers + outs = [outs[i] for i in cfg.backbone.selected_layers] + outs = self.fpn(outs) + + proto_out = None + if cfg.mask_type == mask_type.lincomb and cfg.eval_mask_branch: + with timer.env('proto'): + proto_x = x if self.proto_src is None else outs[self.proto_src] + + if self.num_grids > 0: + grids = self.grid.repeat(proto_x.size(0), 1, 1, 1) + proto_x = torch.cat([proto_x, grids], dim=1) + + proto_out = self.proto_net(proto_x) + proto_out = cfg.mask_proto_prototype_activation(proto_out) + + if cfg.mask_proto_prototypes_as_features: + # Clone here because we don't want to permute this, though idk if contiguous makes this unnecessary + proto_downsampled = proto_out.clone() + + if cfg.mask_proto_prototypes_as_features_no_grad: + proto_downsampled = proto_out.detach() + + # Move the features last so the multiplication is easy + proto_out = proto_out.permute(0, 2, 3, 1).contiguous() + + if cfg.mask_proto_bias: + bias_shape = [x for x in proto_out.size()] + bias_shape[-1] = 1 + proto_out = torch.cat([proto_out, torch.ones(*bias_shape)], -1) + + + with timer.env('pred_heads'): + pred_outs = { 'loc': [], 'conf': [], 'mask': [], 'priors': [] } + + if cfg.use_mask_scoring: + pred_outs['score'] = [] + + if cfg.use_instance_coeff: + pred_outs['inst'] = [] + + for idx, pred_layer in zip(self.selected_layers, self.prediction_layers): + pred_x = outs[idx] + + if cfg.mask_type == mask_type.lincomb and cfg.mask_proto_prototypes_as_features: + # Scale the prototypes down to the current prediction layer's size and add it as inputs + proto_downsampled = F.interpolate(proto_downsampled, size=outs[idx].size()[2:], mode='bilinear', align_corners=False) + pred_x = torch.cat([pred_x, proto_downsampled], dim=1) + + # A hack for the way dataparallel works + if cfg.share_prediction_module and pred_layer is not self.prediction_layers[0]: + pred_layer.parent = [self.prediction_layers[0]] + + p = pred_layer(pred_x) + + for k, v in p.items(): + pred_outs[k].append(v) + + for k, v in pred_outs.items(): + pred_outs[k] = torch.cat(v, -2) + + if proto_out is not None: + pred_outs['proto'] = proto_out + + if self.training: + # For the extra loss functions + if cfg.use_class_existence_loss: + pred_outs['classes'] = self.class_existence_fc(outs[-1].mean(dim=(2, 3))) + + if cfg.use_semantic_segmentation_loss: + pred_outs['segm'] = self.semantic_seg_conv(outs[0]) + + return pred_outs + else: + if cfg.use_mask_scoring: + pred_outs['score'] = torch.sigmoid(pred_outs['score']) + + if cfg.use_focal_loss: + if cfg.use_sigmoid_focal_loss: + # Note: even though conf[0] exists, this mode doesn't train it so don't use it + pred_outs['conf'] = torch.sigmoid(pred_outs['conf']) + if cfg.use_mask_scoring: + pred_outs['conf'] *= pred_outs['score'] + elif cfg.use_objectness_score: + # See focal_loss_sigmoid in multibox_loss.py for details + objectness = torch.sigmoid(pred_outs['conf'][:, :, 0]) + pred_outs['conf'][:, :, 1:] = objectness[:, :, None] * F.softmax(pred_outs['conf'][:, :, 1:], -1) + pred_outs['conf'][:, :, 0 ] = 1 - objectness + else: + pred_outs['conf'] = F.softmax(pred_outs['conf'], -1) + else: + + if cfg.use_objectness_score: + objectness = torch.sigmoid(pred_outs['conf'][:, :, 0]) + + pred_outs['conf'][:, :, 1:] = (objectness > 0.10)[..., None] \ + * F.softmax(pred_outs['conf'][:, :, 1:], dim=-1) + + else: + pred_outs['conf'] = F.softmax(pred_outs['conf'], -1) + + return self.detect(pred_outs) + + + + +# Some testing code +if __name__ == '__main__': + from utils.functions import init_console + init_console() + + # Use the first argument to set the config if you want + import sys + if len(sys.argv) > 1: + from data.config import set_cfg + set_cfg(sys.argv[1]) + + net = Yolact() + net.train() + net.init_weights(backbone_path='weights/' + cfg.backbone.path) + + # GPU + net = net.cuda() + torch.set_default_tensor_type('torch.cuda.FloatTensor') + + x = torch.zeros((1, 3, cfg.max_size, cfg.max_size)) + y = net(x) + + for p in net.prediction_layers: + print(p.last_conv_size) + + print() + for k, a in y.items(): + print(k + ': ', a.size(), torch.sum(a)) + exit() + + net(x) + # timer.disable('pass2') + avg = MovingAverage() + try: + while True: + timer.reset() + with timer.env('everything else'): + net(x) + avg.add(timer.total_time()) + print('\033[2J') # Moves console cursor to 0,0 + timer.print_stats() + print('Avg fps: %.2f\tAvg ms: %.2f ' % (1/avg.get_avg(), avg.get_avg()*1000)) + except KeyboardInterrupt: + pass diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/LICENSE b/PyTorch/contrib/cv/detection/YOLACT_plus/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/LICENSE +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/README.md b/PyTorch/contrib/cv/detection/YOLACT_plus/README.md index a6ecf3f43000245a3f07a14ae65388f4fcffe1a8..6bf6a4c468cd5e008e774db6bf399fb4c5e21853 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/README.md +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/README.md @@ -1,49 +1,49 @@ -# YOLACT++ - -This implements training of Yolact++ on the COCO2017 dataset, mainly modified from [yolact++](https://github.com/dbolya/yolact). - -## YOLACT++ Detail - -## Requirements - -- Install PyTorch ([pytorch.org](http://pytorch.org)) -- `pip install -r requirements.txt` -- Download the dataset by -- `sh data/scripts/COCO.sh` -- Download an imagenet-pretrained model and put it in ./weights. - - For Resnet101, download resnet101_reducedfc.pth. - - For Resnet50, download resnet50-19c8e357.pth. - - For Darknet53, download darknet53.pth. - -## Training - -To train a model, run `train.py` with the desired model architecture and the path to dataset: - -```bash -# training 1p accuracy -bash ./test/train_full_1p.sh --data_path=data_path - -# training 1p performance -bash ./test/train_performance_1p.sh --data_path=data_path - -# training 8p accuracy -bash ./test/train_full_8p.sh --data_path=data_path - -# training 8p performance -bash ./test/train_performance_8p.sh --data_path=data_path - -#test 8p accuracy -bash test/train_eval_1p.sh --$pth_path=pth_path -``` - -Log path: - ${YOLACT_ROOT}/test/output/0/train_0.log # training detail log - - - -## Yolact++ training result - -| 名称 | 精度 | FPS | AMP_Type | -| :------: | :------: | :------: | :------: | -| NPU-1p | - | 3.153 | O0 | -| NPU-8p | 33.49 | 14.677 | O0 | +# YOLACT++ + +This implements training of Yolact++ on the COCO2017 dataset, mainly modified from [yolact++](https://github.com/dbolya/yolact). + +## YOLACT++ Detail + +## Requirements + +- Install PyTorch ([pytorch.org](http://pytorch.org)) +- `pip install -r requirements.txt` +- Download the dataset by +- `sh data/scripts/COCO.sh` +- Download an imagenet-pretrained model and put it in ./weights. + - For Resnet101, download resnet101_reducedfc.pth. + - For Resnet50, download resnet50-19c8e357.pth. + - For Darknet53, download darknet53.pth. + +## Training + +To train a model, run `train.py` with the desired model architecture and the path to dataset: + +```bash +# training 1p accuracy +bash ./test/train_full_1p.sh --data_path=data_path + +# training 1p performance +bash ./test/train_performance_1p.sh --data_path=data_path + +# training 8p accuracy +bash ./test/train_full_8p.sh --data_path=data_path + +# training 8p performance +bash ./test/train_performance_8p.sh --data_path=data_path + +#test 8p accuracy +bash test/train_eval_1p.sh --$pth_path=pth_path +``` + +Log path: + ${YOLACT_ROOT}/test/output/0/train_0.log # training detail log + + + +## Yolact++ training result + +| 名称 | 精度 | FPS | AMP_Type | +| :------: | :------: | :------: | :------: | +| NPU-1p | - | 3.153 | O0 | +| NPU-8p | 33.49 | 14.677 | O0 | diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/backbone.py b/PyTorch/contrib/cv/detection/YOLACT_plus/backbone.py index a3cf652028f1ed08c925fd68dc0fc8fef5bec9d5..15da87a98a63fb68bdeae2a261192a9277059ca4 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/backbone.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/backbone.py @@ -1,474 +1,474 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import torch -import torch.nn as nn -import pickle - -from collections import OrderedDict - -try: - from deform_conv import DCNv2 as DCN -except ImportError: - def DCN(*args, **kwdargs): - raise Exception('DCN could not be imported. If you want to use YOLACT++ models, compile DCN. Check the README for instructions.') - -class Bottleneck(nn.Module): - """ Adapted from torchvision.models.resnet """ - expansion = 4 - - def __init__(self, inplanes, planes, stride=1, downsample=None, norm_layer=nn.BatchNorm2d, dilation=1, use_dcn=False): - super(Bottleneck, self).__init__() - self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False, dilation=dilation) - self.bn1 = norm_layer(planes) - if use_dcn: - self.conv2 = DCN(planes, planes, kernel_size=3, stride=stride, - padding=dilation, dilation=dilation, deformable_groups=1) - self.conv2.bias.data.zero_() - self.conv2.conv_offset_mask.weight.data.zero_() - self.conv2.conv_offset_mask.bias.data.zero_() - else: - self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, - padding=dilation, bias=False, dilation=dilation) - self.bn2 = norm_layer(planes) - self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False, dilation=dilation) - self.bn3 = norm_layer(planes * 4) - self.relu = nn.ReLU(inplace=True) - self.downsample = downsample - self.stride = stride - - def forward(self, x): - residual = x - - out = self.conv1(x) - out = self.bn1(out) - out = self.relu(out) - - out = self.conv2(out) - out = self.bn2(out) - out = self.relu(out) - - out = self.conv3(out) - out = self.bn3(out) - - if self.downsample is not None: - residual = self.downsample(x) - - out += residual - out = self.relu(out) - - return out - - -class ResNetBackbone(nn.Module): - """ Adapted from torchvision.models.resnet """ - - def __init__(self, layers, dcn_layers=[0, 0, 0, 0], dcn_interval=1, atrous_layers=[], block=Bottleneck, norm_layer=nn.BatchNorm2d): - super().__init__() - - # These will be populated by _make_layer - self.num_base_layers = len(layers) - self.layers = nn.ModuleList() - self.channels = [] - self.norm_layer = norm_layer - self.dilation = 1 - self.atrous_layers = atrous_layers - - # From torchvision.models.resnet.Resnet - self.inplanes = 64 - - self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, bias=False) - self.bn1 = norm_layer(64) - self.relu = nn.ReLU(inplace=True) - self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) - - self._make_layer(block, 64, layers[0], dcn_layers=dcn_layers[0], dcn_interval=dcn_interval) - self._make_layer(block, 128, layers[1], stride=2, dcn_layers=dcn_layers[1], dcn_interval=dcn_interval) - self._make_layer(block, 256, layers[2], stride=2, dcn_layers=dcn_layers[2], dcn_interval=dcn_interval) - self._make_layer(block, 512, layers[3], stride=2, dcn_layers=dcn_layers[3], dcn_interval=dcn_interval) - - # This contains every module that should be initialized by loading in pretrained weights. - # Any extra layers added onto this that won't be initialized by init_backbone will not be - # in this list. That way, Yolact::init_weights knows which backbone weights to initialize - # with xavier, and which ones to leave alone. - self.backbone_modules = [m for m in self.modules() if isinstance(m, nn.Conv2d)] - - - def _make_layer(self, block, planes, blocks, stride=1, dcn_layers=0, dcn_interval=1): - """ Here one layer means a string of n Bottleneck blocks. """ - downsample = None - - # This is actually just to create the connection between layers, and not necessarily to - # downsample. Even if the second condition is met, it only downsamples when stride != 1 - if stride != 1 or self.inplanes != planes * block.expansion: - if len(self.layers) in self.atrous_layers: - self.dilation += 1 - stride = 1 - - downsample = nn.Sequential( - nn.Conv2d(self.inplanes, planes * block.expansion, - kernel_size=1, stride=stride, bias=False, - dilation=self.dilation), - self.norm_layer(planes * block.expansion), - ) - - layers = [] - use_dcn = (dcn_layers >= blocks) - layers.append(block(self.inplanes, planes, stride, downsample, self.norm_layer, self.dilation, use_dcn=use_dcn)) - self.inplanes = planes * block.expansion - for i in range(1, blocks): - use_dcn = ((i+dcn_layers) >= blocks) and (i % dcn_interval == 0) - layers.append(block(self.inplanes, planes, norm_layer=self.norm_layer, use_dcn=use_dcn)) - layer = nn.Sequential(*layers) - - self.channels.append(planes * block.expansion) - self.layers.append(layer) - - return layer - - def forward(self, x): - """ Returns a list of convouts for each layer. """ - - x = self.conv1(x) - x = self.bn1(x) - x = self.relu(x) - x = self.maxpool(x) - - outs = [] - for layer in self.layers: - x = layer(x) - outs.append(x) - - return tuple(outs) - - def init_backbone(self, path): - """ Initializes the backbone weights for training. """ - state_dict = torch.load(path) - - # Replace layer1 -> layers.0 etc. - keys = list(state_dict) - for key in keys: - if key.startswith('layer'): - idx = int(key[5]) - new_key = 'layers.' + str(idx-1) + key[6:] - state_dict[new_key] = state_dict.pop(key) - - # Note: Using strict=False is berry scary. Triple check this. - self.load_state_dict(state_dict, strict=False) - - def add_layer(self, conv_channels=1024, downsample=2, depth=1, block=Bottleneck): - """ Add a downsample layer to the backbone as per what SSD does. """ - self._make_layer(block, conv_channels // block.expansion, blocks=depth, stride=downsample) - - - - -class ResNetBackboneGN(ResNetBackbone): - - def __init__(self, layers, num_groups=32): - super().__init__(layers, norm_layer=lambda x: nn.GroupNorm(num_groups, x)) - - def init_backbone(self, path): - """ The path here comes from detectron. So we load it differently. """ - with open(path, 'rb') as f: - state_dict = pickle.load(f, encoding='latin1') # From the detectron source - state_dict = state_dict['blobs'] - - our_state_dict_keys = list(self.state_dict().keys()) - new_state_dict = {} - - gn_trans = lambda x: ('gn_s' if x == 'weight' else 'gn_b') - layeridx2res = lambda x: 'res' + str(int(x)+2) - block2branch = lambda x: 'branch2' + ('a', 'b', 'c')[int(x[-1:])-1] - - # Transcribe each Detectron weights name to a Yolact weights name - for key in our_state_dict_keys: - parts = key.split('.') - transcribed_key = '' - - if (parts[0] == 'conv1'): - transcribed_key = 'conv1_w' - elif (parts[0] == 'bn1'): - transcribed_key = 'conv1_' + gn_trans(parts[1]) - elif (parts[0] == 'layers'): - if int(parts[1]) >= self.num_base_layers: continue - - transcribed_key = layeridx2res(parts[1]) - transcribed_key += '_' + parts[2] + '_' - - if parts[3] == 'downsample': - transcribed_key += 'branch1_' - - if parts[4] == '0': - transcribed_key += 'w' - else: - transcribed_key += gn_trans(parts[5]) - else: - transcribed_key += block2branch(parts[3]) + '_' - - if 'conv' in parts[3]: - transcribed_key += 'w' - else: - transcribed_key += gn_trans(parts[4]) - - new_state_dict[key] = torch.Tensor(state_dict[transcribed_key]) - - # strict=False because we may have extra unitialized layers at this point - self.load_state_dict(new_state_dict, strict=False) - - - - - - - -def darknetconvlayer(in_channels, out_channels, *args, **kwdargs): - """ - Implements a conv, activation, then batch norm. - Arguments are passed into the conv layer. - """ - return nn.Sequential( - nn.Conv2d(in_channels, out_channels, *args, **kwdargs, bias=False), - nn.BatchNorm2d(out_channels), - # Darknet uses 0.1 here. - # See https://github.com/pjreddie/darknet/blob/680d3bde1924c8ee2d1c1dea54d3e56a05ca9a26/src/activations.h#L39 - nn.LeakyReLU(0.1, inplace=True) - ) - -class DarkNetBlock(nn.Module): - """ Note: channels is the lesser of the two. The output will be expansion * channels. """ - - expansion = 2 - - def __init__(self, in_channels, channels): - super().__init__() - - self.conv1 = darknetconvlayer(in_channels, channels, kernel_size=1) - self.conv2 = darknetconvlayer(channels, channels * self.expansion, kernel_size=3, padding=1) - - def forward(self, x): - return self.conv2(self.conv1(x)) + x - - - - -class DarkNetBackbone(nn.Module): - """ - An implementation of YOLOv3's Darnet53 in - https://pjreddie.com/media/files/papers/YOLOv3.pdf - - This is based off of the implementation of Resnet above. - """ - - def __init__(self, layers=[1, 2, 8, 8, 4], block=DarkNetBlock): - super().__init__() - - # These will be populated by _make_layer - self.num_base_layers = len(layers) - self.layers = nn.ModuleList() - self.channels = [] - - self._preconv = darknetconvlayer(3, 32, kernel_size=3, padding=1) - self.in_channels = 32 - - self._make_layer(block, 32, layers[0]) - self._make_layer(block, 64, layers[1]) - self._make_layer(block, 128, layers[2]) - self._make_layer(block, 256, layers[3]) - self._make_layer(block, 512, layers[4]) - - # This contains every module that should be initialized by loading in pretrained weights. - # Any extra layers added onto this that won't be initialized by init_backbone will not be - # in this list. That way, Yolact::init_weights knows which backbone weights to initialize - # with xavier, and which ones to leave alone. - self.backbone_modules = [m for m in self.modules() if isinstance(m, nn.Conv2d)] - - def _make_layer(self, block, channels, num_blocks, stride=2): - """ Here one layer means a string of n blocks. """ - layer_list = [] - - # The downsample layer - layer_list.append( - darknetconvlayer(self.in_channels, channels * block.expansion, - kernel_size=3, padding=1, stride=stride)) - - # Each block inputs channels and outputs channels * expansion - self.in_channels = channels * block.expansion - layer_list += [block(self.in_channels, channels) for _ in range(num_blocks)] - - self.channels.append(self.in_channels) - self.layers.append(nn.Sequential(*layer_list)) - - def forward(self, x): - """ Returns a list of convouts for each layer. """ - - x = self._preconv(x) - - outs = [] - for layer in self.layers: - x = layer(x) - outs.append(x) - - return tuple(outs) - - def add_layer(self, conv_channels=1024, stride=2, depth=1, block=DarkNetBlock): - """ Add a downsample layer to the backbone as per what SSD does. """ - self._make_layer(block, conv_channels // block.expansion, num_blocks=depth, stride=stride) - - def init_backbone(self, path): - """ Initializes the backbone weights for training. """ - # Note: Using strict=False is berry scary. Triple check this. - self.load_state_dict(torch.load(path), strict=False) - - - - - -class VGGBackbone(nn.Module): - """ - Args: - - cfg: A list of layers given as lists. Layers can be either 'M' signifying - a max pooling layer, a number signifying that many feature maps in - a conv layer, or a tuple of 'M' or a number and a kwdargs dict to pass - into the function that creates the layer (e.g. nn.MaxPool2d for 'M'). - - extra_args: A list of lists of arguments to pass into add_layer. - - norm_layers: Layers indices that need to pass through an l2norm layer. - """ - - def __init__(self, cfg, extra_args=[], norm_layers=[]): - super().__init__() - - self.channels = [] - self.layers = nn.ModuleList() - self.in_channels = 3 - self.extra_args = list(reversed(extra_args)) # So I can use it as a stack - - # Keeps track of what the corresponding key will be in the state dict of the - # pretrained model. For instance, layers.0.2 for us is 2 for the pretrained - # model but layers.1.1 is 5. - self.total_layer_count = 0 - self.state_dict_lookup = {} - - for idx, layer_cfg in enumerate(cfg): - self._make_layer(layer_cfg) - - self.norms = nn.ModuleList([nn.BatchNorm2d(self.channels[l]) for l in norm_layers]) - self.norm_lookup = {l: idx for idx, l in enumerate(norm_layers)} - - # These modules will be initialized by init_backbone, - # so don't overwrite their initialization later. - self.backbone_modules = [m for m in self.modules() if isinstance(m, nn.Conv2d)] - - def _make_layer(self, cfg): - """ - Each layer is a sequence of conv layers usually preceded by a max pooling. - Adapted from torchvision.models.vgg.make_layers. - """ - - layers = [] - - for v in cfg: - # VGG in SSD requires some special layers, so allow layers to be tuples of - # (, kwdargs dict) - args = None - if isinstance(v, tuple): - args = v[1] - v = v[0] - - # v should be either M or a number - if v == 'M': - # Set default arguments - if args is None: - args = {'kernel_size': 2, 'stride': 2} - - layers.append(nn.MaxPool2d(**args)) - else: - # See the comment in __init__ for an explanation of this - cur_layer_idx = self.total_layer_count + len(layers) - self.state_dict_lookup[cur_layer_idx] = '%d.%d' % (len(self.layers), len(layers)) - - # Set default arguments - if args is None: - args = {'kernel_size': 3, 'padding': 1} - - # Add the layers - layers.append(nn.Conv2d(self.in_channels, v, **args)) - layers.append(nn.ReLU(inplace=True)) - self.in_channels = v - - self.total_layer_count += len(layers) - self.channels.append(self.in_channels) - self.layers.append(nn.Sequential(*layers)) - - def forward(self, x): - """ Returns a list of convouts for each layer. """ - outs = [] - - for idx, layer in enumerate(self.layers): - x = layer(x) - - # Apply an l2norm module to the selected layers - # Note that this differs from the original implemenetation - if idx in self.norm_lookup: - x = self.norms[self.norm_lookup[idx]](x) - outs.append(x) - - return tuple(outs) - - def transform_key(self, k): - """ Transform e.g. features.24.bias to layers.4.1.bias """ - vals = k.split('.') - layerIdx = self.state_dict_lookup[int(vals[0])] - return 'layers.%s.%s' % (layerIdx, vals[1]) - - def init_backbone(self, path): - """ Initializes the backbone weights for training. """ - state_dict = torch.load(path) - state_dict = OrderedDict([(self.transform_key(k), v) for k,v in state_dict.items()]) - - self.load_state_dict(state_dict, strict=False) - - def add_layer(self, conv_channels=128, downsample=2): - """ Add a downsample layer to the backbone as per what SSD does. """ - if len(self.extra_args) > 0: - conv_channels, downsample = self.extra_args.pop() - - padding = 1 if downsample > 1 else 0 - - layer = nn.Sequential( - nn.Conv2d(self.in_channels, conv_channels, kernel_size=1), - nn.ReLU(inplace=True), - nn.Conv2d(conv_channels, conv_channels*2, kernel_size=3, stride=downsample, padding=padding), - nn.ReLU(inplace=True) - ) - - self.in_channels = conv_channels*2 - self.channels.append(self.in_channels) - self.layers.append(layer) - - - - -def construct_backbone(cfg): - """ Constructs a backbone given a backbone config object (see config.py). """ - backbone = cfg.type(*cfg.args) - - # Add downsampling layers until we reach the number we need - num_layers = max(cfg.selected_layers) + 1 - - while len(backbone.layers) < num_layers: - backbone.add_layer() - - return backbone +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import torch +import torch.nn as nn +import pickle + +from collections import OrderedDict + +try: + from deform_conv import DCNv2 as DCN +except ImportError: + def DCN(*args, **kwdargs): + raise Exception('DCN could not be imported. If you want to use YOLACT++ models, compile DCN. Check the README for instructions.') + +class Bottleneck(nn.Module): + """ Adapted from torchvision.models.resnet """ + expansion = 4 + + def __init__(self, inplanes, planes, stride=1, downsample=None, norm_layer=nn.BatchNorm2d, dilation=1, use_dcn=False): + super(Bottleneck, self).__init__() + self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False, dilation=dilation) + self.bn1 = norm_layer(planes) + if use_dcn: + self.conv2 = DCN(planes, planes, kernel_size=3, stride=stride, + padding=dilation, dilation=dilation, deformable_groups=1) + self.conv2.bias.data.zero_() + self.conv2.conv_offset_mask.weight.data.zero_() + self.conv2.conv_offset_mask.bias.data.zero_() + else: + self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, + padding=dilation, bias=False, dilation=dilation) + self.bn2 = norm_layer(planes) + self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False, dilation=dilation) + self.bn3 = norm_layer(planes * 4) + self.relu = nn.ReLU(inplace=True) + self.downsample = downsample + self.stride = stride + + def forward(self, x): + residual = x + + out = self.conv1(x) + out = self.bn1(out) + out = self.relu(out) + + out = self.conv2(out) + out = self.bn2(out) + out = self.relu(out) + + out = self.conv3(out) + out = self.bn3(out) + + if self.downsample is not None: + residual = self.downsample(x) + + out += residual + out = self.relu(out) + + return out + + +class ResNetBackbone(nn.Module): + """ Adapted from torchvision.models.resnet """ + + def __init__(self, layers, dcn_layers=[0, 0, 0, 0], dcn_interval=1, atrous_layers=[], block=Bottleneck, norm_layer=nn.BatchNorm2d): + super().__init__() + + # These will be populated by _make_layer + self.num_base_layers = len(layers) + self.layers = nn.ModuleList() + self.channels = [] + self.norm_layer = norm_layer + self.dilation = 1 + self.atrous_layers = atrous_layers + + # From torchvision.models.resnet.Resnet + self.inplanes = 64 + + self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, bias=False) + self.bn1 = norm_layer(64) + self.relu = nn.ReLU(inplace=True) + self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) + + self._make_layer(block, 64, layers[0], dcn_layers=dcn_layers[0], dcn_interval=dcn_interval) + self._make_layer(block, 128, layers[1], stride=2, dcn_layers=dcn_layers[1], dcn_interval=dcn_interval) + self._make_layer(block, 256, layers[2], stride=2, dcn_layers=dcn_layers[2], dcn_interval=dcn_interval) + self._make_layer(block, 512, layers[3], stride=2, dcn_layers=dcn_layers[3], dcn_interval=dcn_interval) + + # This contains every module that should be initialized by loading in pretrained weights. + # Any extra layers added onto this that won't be initialized by init_backbone will not be + # in this list. That way, Yolact::init_weights knows which backbone weights to initialize + # with xavier, and which ones to leave alone. + self.backbone_modules = [m for m in self.modules() if isinstance(m, nn.Conv2d)] + + + def _make_layer(self, block, planes, blocks, stride=1, dcn_layers=0, dcn_interval=1): + """ Here one layer means a string of n Bottleneck blocks. """ + downsample = None + + # This is actually just to create the connection between layers, and not necessarily to + # downsample. Even if the second condition is met, it only downsamples when stride != 1 + if stride != 1 or self.inplanes != planes * block.expansion: + if len(self.layers) in self.atrous_layers: + self.dilation += 1 + stride = 1 + + downsample = nn.Sequential( + nn.Conv2d(self.inplanes, planes * block.expansion, + kernel_size=1, stride=stride, bias=False, + dilation=self.dilation), + self.norm_layer(planes * block.expansion), + ) + + layers = [] + use_dcn = (dcn_layers >= blocks) + layers.append(block(self.inplanes, planes, stride, downsample, self.norm_layer, self.dilation, use_dcn=use_dcn)) + self.inplanes = planes * block.expansion + for i in range(1, blocks): + use_dcn = ((i+dcn_layers) >= blocks) and (i % dcn_interval == 0) + layers.append(block(self.inplanes, planes, norm_layer=self.norm_layer, use_dcn=use_dcn)) + layer = nn.Sequential(*layers) + + self.channels.append(planes * block.expansion) + self.layers.append(layer) + + return layer + + def forward(self, x): + """ Returns a list of convouts for each layer. """ + + x = self.conv1(x) + x = self.bn1(x) + x = self.relu(x) + x = self.maxpool(x) + + outs = [] + for layer in self.layers: + x = layer(x) + outs.append(x) + + return tuple(outs) + + def init_backbone(self, path): + """ Initializes the backbone weights for training. """ + state_dict = torch.load(path) + + # Replace layer1 -> layers.0 etc. + keys = list(state_dict) + for key in keys: + if key.startswith('layer'): + idx = int(key[5]) + new_key = 'layers.' + str(idx-1) + key[6:] + state_dict[new_key] = state_dict.pop(key) + + # Note: Using strict=False is berry scary. Triple check this. + self.load_state_dict(state_dict, strict=False) + + def add_layer(self, conv_channels=1024, downsample=2, depth=1, block=Bottleneck): + """ Add a downsample layer to the backbone as per what SSD does. """ + self._make_layer(block, conv_channels // block.expansion, blocks=depth, stride=downsample) + + + + +class ResNetBackboneGN(ResNetBackbone): + + def __init__(self, layers, num_groups=32): + super().__init__(layers, norm_layer=lambda x: nn.GroupNorm(num_groups, x)) + + def init_backbone(self, path): + """ The path here comes from detectron. So we load it differently. """ + with open(path, 'rb') as f: + state_dict = pickle.load(f, encoding='latin1') # From the detectron source + state_dict = state_dict['blobs'] + + our_state_dict_keys = list(self.state_dict().keys()) + new_state_dict = {} + + gn_trans = lambda x: ('gn_s' if x == 'weight' else 'gn_b') + layeridx2res = lambda x: 'res' + str(int(x)+2) + block2branch = lambda x: 'branch2' + ('a', 'b', 'c')[int(x[-1:])-1] + + # Transcribe each Detectron weights name to a Yolact weights name + for key in our_state_dict_keys: + parts = key.split('.') + transcribed_key = '' + + if (parts[0] == 'conv1'): + transcribed_key = 'conv1_w' + elif (parts[0] == 'bn1'): + transcribed_key = 'conv1_' + gn_trans(parts[1]) + elif (parts[0] == 'layers'): + if int(parts[1]) >= self.num_base_layers: continue + + transcribed_key = layeridx2res(parts[1]) + transcribed_key += '_' + parts[2] + '_' + + if parts[3] == 'downsample': + transcribed_key += 'branch1_' + + if parts[4] == '0': + transcribed_key += 'w' + else: + transcribed_key += gn_trans(parts[5]) + else: + transcribed_key += block2branch(parts[3]) + '_' + + if 'conv' in parts[3]: + transcribed_key += 'w' + else: + transcribed_key += gn_trans(parts[4]) + + new_state_dict[key] = torch.Tensor(state_dict[transcribed_key]) + + # strict=False because we may have extra unitialized layers at this point + self.load_state_dict(new_state_dict, strict=False) + + + + + + + +def darknetconvlayer(in_channels, out_channels, *args, **kwdargs): + """ + Implements a conv, activation, then batch norm. + Arguments are passed into the conv layer. + """ + return nn.Sequential( + nn.Conv2d(in_channels, out_channels, *args, **kwdargs, bias=False), + nn.BatchNorm2d(out_channels), + # Darknet uses 0.1 here. + # See https://github.com/pjreddie/darknet/blob/680d3bde1924c8ee2d1c1dea54d3e56a05ca9a26/src/activations.h#L39 + nn.LeakyReLU(0.1, inplace=True) + ) + +class DarkNetBlock(nn.Module): + """ Note: channels is the lesser of the two. The output will be expansion * channels. """ + + expansion = 2 + + def __init__(self, in_channels, channels): + super().__init__() + + self.conv1 = darknetconvlayer(in_channels, channels, kernel_size=1) + self.conv2 = darknetconvlayer(channels, channels * self.expansion, kernel_size=3, padding=1) + + def forward(self, x): + return self.conv2(self.conv1(x)) + x + + + + +class DarkNetBackbone(nn.Module): + """ + An implementation of YOLOv3's Darnet53 in + https://pjreddie.com/media/files/papers/YOLOv3.pdf + + This is based off of the implementation of Resnet above. + """ + + def __init__(self, layers=[1, 2, 8, 8, 4], block=DarkNetBlock): + super().__init__() + + # These will be populated by _make_layer + self.num_base_layers = len(layers) + self.layers = nn.ModuleList() + self.channels = [] + + self._preconv = darknetconvlayer(3, 32, kernel_size=3, padding=1) + self.in_channels = 32 + + self._make_layer(block, 32, layers[0]) + self._make_layer(block, 64, layers[1]) + self._make_layer(block, 128, layers[2]) + self._make_layer(block, 256, layers[3]) + self._make_layer(block, 512, layers[4]) + + # This contains every module that should be initialized by loading in pretrained weights. + # Any extra layers added onto this that won't be initialized by init_backbone will not be + # in this list. That way, Yolact::init_weights knows which backbone weights to initialize + # with xavier, and which ones to leave alone. + self.backbone_modules = [m for m in self.modules() if isinstance(m, nn.Conv2d)] + + def _make_layer(self, block, channels, num_blocks, stride=2): + """ Here one layer means a string of n blocks. """ + layer_list = [] + + # The downsample layer + layer_list.append( + darknetconvlayer(self.in_channels, channels * block.expansion, + kernel_size=3, padding=1, stride=stride)) + + # Each block inputs channels and outputs channels * expansion + self.in_channels = channels * block.expansion + layer_list += [block(self.in_channels, channels) for _ in range(num_blocks)] + + self.channels.append(self.in_channels) + self.layers.append(nn.Sequential(*layer_list)) + + def forward(self, x): + """ Returns a list of convouts for each layer. """ + + x = self._preconv(x) + + outs = [] + for layer in self.layers: + x = layer(x) + outs.append(x) + + return tuple(outs) + + def add_layer(self, conv_channels=1024, stride=2, depth=1, block=DarkNetBlock): + """ Add a downsample layer to the backbone as per what SSD does. """ + self._make_layer(block, conv_channels // block.expansion, num_blocks=depth, stride=stride) + + def init_backbone(self, path): + """ Initializes the backbone weights for training. """ + # Note: Using strict=False is berry scary. Triple check this. + self.load_state_dict(torch.load(path), strict=False) + + + + + +class VGGBackbone(nn.Module): + """ + Args: + - cfg: A list of layers given as lists. Layers can be either 'M' signifying + a max pooling layer, a number signifying that many feature maps in + a conv layer, or a tuple of 'M' or a number and a kwdargs dict to pass + into the function that creates the layer (e.g. nn.MaxPool2d for 'M'). + - extra_args: A list of lists of arguments to pass into add_layer. + - norm_layers: Layers indices that need to pass through an l2norm layer. + """ + + def __init__(self, cfg, extra_args=[], norm_layers=[]): + super().__init__() + + self.channels = [] + self.layers = nn.ModuleList() + self.in_channels = 3 + self.extra_args = list(reversed(extra_args)) # So I can use it as a stack + + # Keeps track of what the corresponding key will be in the state dict of the + # pretrained model. For instance, layers.0.2 for us is 2 for the pretrained + # model but layers.1.1 is 5. + self.total_layer_count = 0 + self.state_dict_lookup = {} + + for idx, layer_cfg in enumerate(cfg): + self._make_layer(layer_cfg) + + self.norms = nn.ModuleList([nn.BatchNorm2d(self.channels[l]) for l in norm_layers]) + self.norm_lookup = {l: idx for idx, l in enumerate(norm_layers)} + + # These modules will be initialized by init_backbone, + # so don't overwrite their initialization later. + self.backbone_modules = [m for m in self.modules() if isinstance(m, nn.Conv2d)] + + def _make_layer(self, cfg): + """ + Each layer is a sequence of conv layers usually preceded by a max pooling. + Adapted from torchvision.models.vgg.make_layers. + """ + + layers = [] + + for v in cfg: + # VGG in SSD requires some special layers, so allow layers to be tuples of + # (, kwdargs dict) + args = None + if isinstance(v, tuple): + args = v[1] + v = v[0] + + # v should be either M or a number + if v == 'M': + # Set default arguments + if args is None: + args = {'kernel_size': 2, 'stride': 2} + + layers.append(nn.MaxPool2d(**args)) + else: + # See the comment in __init__ for an explanation of this + cur_layer_idx = self.total_layer_count + len(layers) + self.state_dict_lookup[cur_layer_idx] = '%d.%d' % (len(self.layers), len(layers)) + + # Set default arguments + if args is None: + args = {'kernel_size': 3, 'padding': 1} + + # Add the layers + layers.append(nn.Conv2d(self.in_channels, v, **args)) + layers.append(nn.ReLU(inplace=True)) + self.in_channels = v + + self.total_layer_count += len(layers) + self.channels.append(self.in_channels) + self.layers.append(nn.Sequential(*layers)) + + def forward(self, x): + """ Returns a list of convouts for each layer. """ + outs = [] + + for idx, layer in enumerate(self.layers): + x = layer(x) + + # Apply an l2norm module to the selected layers + # Note that this differs from the original implemenetation + if idx in self.norm_lookup: + x = self.norms[self.norm_lookup[idx]](x) + outs.append(x) + + return tuple(outs) + + def transform_key(self, k): + """ Transform e.g. features.24.bias to layers.4.1.bias """ + vals = k.split('.') + layerIdx = self.state_dict_lookup[int(vals[0])] + return 'layers.%s.%s' % (layerIdx, vals[1]) + + def init_backbone(self, path): + """ Initializes the backbone weights for training. """ + state_dict = torch.load(path) + state_dict = OrderedDict([(self.transform_key(k), v) for k,v in state_dict.items()]) + + self.load_state_dict(state_dict, strict=False) + + def add_layer(self, conv_channels=128, downsample=2): + """ Add a downsample layer to the backbone as per what SSD does. """ + if len(self.extra_args) > 0: + conv_channels, downsample = self.extra_args.pop() + + padding = 1 if downsample > 1 else 0 + + layer = nn.Sequential( + nn.Conv2d(self.in_channels, conv_channels, kernel_size=1), + nn.ReLU(inplace=True), + nn.Conv2d(conv_channels, conv_channels*2, kernel_size=3, stride=downsample, padding=padding), + nn.ReLU(inplace=True) + ) + + self.in_channels = conv_channels*2 + self.channels.append(self.in_channels) + self.layers.append(layer) + + + + +def construct_backbone(cfg): + """ Constructs a backbone given a backbone config object (see config.py). """ + backbone = cfg.type(*cfg.args) + + # Add downsampling layers until we reach the number we need + num_layers = max(cfg.selected_layers) + 1 + + while len(backbone.layers) < num_layers: + backbone.add_layer() + + return backbone diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/data/__init__.py b/PyTorch/contrib/cv/detection/YOLACT_plus/data/__init__.py index 65b2da8e8896a90e57ab5b2a9f77fb49a91dcc27..67c0f019a0d1207c72eca1ab1026c6a6aedba262 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/data/__init__.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/data/__init__.py @@ -1,6 +1,6 @@ -from .config import * -from .coco import * - -import torch -import cv2 -import numpy as np +from .config import * +from .coco import * + +import torch +import cv2 +import numpy as np diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/data/coco.py b/PyTorch/contrib/cv/detection/YOLACT_plus/data/coco.py index 8dd0f1c27903a42bec8529aefd1f7bbe7e013664..35f42e56240acf6f24e306ad33a8219ea5eb0543 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/data/coco.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/data/coco.py @@ -1,311 +1,311 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import os -import os.path as osp -import sys -import torch -import torch.utils.data as data -import torch.nn.functional as F -import cv2 -import numpy as np -from .config import cfg -from pycocotools import mask as maskUtils -import random - -def get_label_map(): - if cfg.dataset.label_map is None: - return {x+1: x+1 for x in range(len(cfg.dataset.class_names))} - else: - return cfg.dataset.label_map - -class COCOAnnotationTransform(object): - """Transforms a COCO annotation into a Tensor of bbox coords and label index - Initilized with a dictionary lookup of classnames to indexes - """ - def __init__(self): - self.label_map = get_label_map() - - def __call__(self, target, width, height): - """ - Args: - target (dict): COCO target json annotation as a python dict - height (int): height - width (int): width - Returns: - a list containing lists of bounding boxes [bbox coords, class idx] - """ - scale = np.array([width, height, width, height]) - res = [] - for obj in target: - if 'bbox' in obj: - bbox = obj['bbox'] - label_idx = obj['category_id'] - if label_idx >= 0: - label_idx = self.label_map[label_idx] - 1 - final_box = list(np.array([bbox[0], bbox[1], bbox[0]+bbox[2], bbox[1]+bbox[3]])/scale) - final_box.append(label_idx) - res += [final_box] # [xmin, ymin, xmax, ymax, label_idx] - else: - print("No bbox found for object ", obj) - - return res - - -class COCODetection(data.Dataset): - """`MS Coco Detection `_ Dataset. - Args: - root (string): Root directory where images are downloaded to. - 这里即为image_path,数据集图像路径 - - set_name (string): Name of the specific set of COCO images. - 自定义,用于标记 - - transform (callable, optional): A function/transform that augments the - raw images` - 图像增强方法 - - target_transform (callable, optional): A function/transform that takes - in the target (bbox) and transforms it. - 将数据集中的目标检测框(bounding box)等封装为一个专门的数据结构 - - prep_crowds (bool): Whether or not to prepare crowds for the evaluation step. - ? - """ - - def __init__(self, image_path, info_file, transform=None, - target_transform=None, - dataset_name='MS COCO', has_gt=True): - #has_gt中的gt代表ground truth,在监督学习中,数据是有标注的,以(x, t)的形式出现,其中x是输入数据,t是标注. - # 正确的t标注是ground truth, 错误的标记则不是。(也有人将所有标注数据都叫做ground truth) - - # Do this here because we have too many things named COCO - from pycocotools.coco import COCO - - if target_transform is None: - target_transform = COCOAnnotationTransform() - - self.root = image_path - self.coco = COCO(info_file) #加载标注文件, 其中COCO对象属性有1、anns :所有标注;2、catToImgs:{种类:[图像list]}的映射字典; - # 3、cats:图片中包含物体的种类;4、dataset:内含信息、许可、标注等;5、imgToAnns:{图像:[标注list]}的映射字典;6、imgs:全部图像 - - self.ids = list(self.coco.imgToAnns.keys()) - if len(self.ids) == 0 or not has_gt: #显然这个if块内语句基本不可能执行 - self.ids = list(self.coco.imgs.keys()) - - self.transform = transform #默认情况下,训练数据使用:SSDAugmentation,验证数据使用:baseTransform - self.target_transform = COCOAnnotationTransform() #82行的if块毫无意义 - - self.name = dataset_name - self.has_gt = has_gt - - def __getitem__(self, index): - """ - Args: - index (int): Index - Returns: - tuple: Tuple (image, (target, masks, num_crowds)). - target is the object returned by ``coco.loadAnns``. - """ - im, gt, masks, h, w, num_crowds = self.pull_item(index) - return (index, im), (gt, masks, num_crowds) - - def __len__(self): - return len(self.ids) - - def pull_item(self, index): - """ - Args: - index (int): Index - Returns: - tuple: Tuple (image, target, masks, height, width, crowd). - target is the object returned by ``coco.loadAnns``. - Note that if no crowd annotations exist, crowd will be None - """ - img_id = self.ids[index] - - if self.has_gt: - ann_ids = self.coco.getAnnIds(imgIds=img_id) - - # Target has {'segmentation', 'area', iscrowd', 'image_id', 'bbox', 'category_id'} - target = [x for x in self.coco.loadAnns(ann_ids) if x['image_id'] == img_id] - else: - target = [] - - # Separate out crowd annotations. These are annotations that signify a large crowd of - # objects of said class, where there is no annotation for each individual object. Both - # during testing and training, consider these crowds as neutral. - crowd = [x for x in target if ('iscrowd' in x and x['iscrowd'])] - target = [x for x in target if not ('iscrowd' in x and x['iscrowd'])] - num_crowds = len(crowd) - - for x in crowd: - x['category_id'] = -1 - - # This is so we ensure that all crowd annotations are at the end of the array - target += crowd - - # The split here is to have compatibility with both COCO2014 and 2017 annotations. - # In 2014, images have the pattern COCO_{train/val}2014_%012d.jpg, while in 2017 it's %012d.jpg. - # Our script downloads the images as %012d.jpg so convert accordingly. - file_name = self.coco.loadImgs(img_id)[0]['file_name'] - - if file_name.startswith('COCO'): - file_name = file_name.split('_')[-1] - - path = osp.join(self.root, file_name) - assert osp.exists(path), 'Image path does not exist: {}'.format(path) - - img = cv2.imread(path) - height, width, _ = img.shape - - if len(target) > 0: - # Pool all the masks for this image into one [num_objects,height,width] matrix - masks = [self.coco.annToMask(obj).reshape(-1) for obj in target] - masks = np.vstack(masks) - masks = masks.reshape(-1, height, width) - - if self.target_transform is not None and len(target) > 0: - target = self.target_transform(target, width, height) - - if self.transform is not None: - if len(target) > 0: - target = np.array(target) - img, masks, boxes, labels = self.transform(img, masks, target[:, :4], - {'num_crowds': num_crowds, 'labels': target[:, 4]}) - - # I stored num_crowds in labels so I didn't have to modify the entirety of augmentations - num_crowds = labels['num_crowds'] - labels = labels['labels'] - - target = np.hstack((boxes, np.expand_dims(labels, axis=1))) - else: - img, _, _, _ = self.transform(img, np.zeros((1, height, width), dtype=np.float), np.array([[0, 0, 1, 1]]), - {'num_crowds': 0, 'labels': np.array([0])}) - masks = None - target = None - - if target.shape[0] == 0: - print('Warning: Augmentation output an example with no ground truth. Resampling...') - return self.pull_item(random.randint(0, len(self.ids)-1)) - - return torch.from_numpy(img).permute(2, 0, 1), target, masks, height, width, num_crowds - - def pull_image(self, index): - '''Returns the original image object at index in PIL form - - Note: not using self.__getitem__(), as any transformations passed in - could mess up this functionality. - - Argument: - index (int): index of img to show - Return: - cv2 img - ''' - img_id = self.ids[index] - path = self.coco.loadImgs(img_id)[0]['file_name'] - return cv2.imread(osp.join(self.root, path), cv2.IMREAD_COLOR) - - def pull_anno(self, index): - '''Returns the original annotation of image at index - - Note: not using self.__getitem__(), as any transformations passed in - could mess up this functionality. - - Argument: - index (int): index of img to get annotation of - Return: - list: [img_id, [(label, bbox coords),...]] - eg: ('001718', [('dog', (96, 13, 438, 332))]) - ''' - img_id = self.ids[index] - ann_ids = self.coco.getAnnIds(imgIds=img_id) - return self.coco.loadAnns(ann_ids) - - def __repr__(self): - fmt_str = 'Dataset ' + self.__class__.__name__ + '\n' - fmt_str += ' Number of datapoints: {}\n'.format(self.__len__()) - fmt_str += ' Root Location: {}\n'.format(self.root) - tmp = ' Transforms (if any): ' - fmt_str += '{0}{1}\n'.format(tmp, self.transform.__repr__().replace('\n', '\n' + ' ' * len(tmp))) - tmp = ' Target Transforms (if any): ' - fmt_str += '{0}{1}'.format(tmp, self.target_transform.__repr__().replace('\n', '\n' + ' ' * len(tmp))) - return fmt_str - -def enforce_size(img, targets, masks, num_crowds, new_w, new_h): - """ Ensures that the image is the given size without distorting aspect ratio. """ - with torch.no_grad(): - _, h, w = img.size() - - if h == new_h and w == new_w: - return img, targets, masks, num_crowds - - # Resize the image so that it fits within new_w, new_h - w_prime = new_w - h_prime = h * new_w / w - - if h_prime > new_h: - w_prime *= new_h / h_prime - h_prime = new_h - - w_prime = int(w_prime) - h_prime = int(h_prime) - - # Do all the resizing - img = F.interpolate(img.unsqueeze(0), (h_prime, w_prime), mode='bilinear', align_corners=False) - img.squeeze_(0) - - # Act like each object is a color channel - masks = F.interpolate(masks.unsqueeze(0), (h_prime, w_prime), mode='bilinear', align_corners=False) - masks.squeeze_(0) - - # Scale bounding boxes (this will put them in the top left corner in the case of padding) - targets[:, [0, 2]] *= (w_prime / new_w) - targets[:, [1, 3]] *= (h_prime / new_h) - - # Finally, pad everything to be the new_w, new_h - pad_dims = (0, new_w - w_prime, 0, new_h - h_prime) - img = F.pad( img, pad_dims, mode='constant', value=0) - masks = F.pad(masks, pad_dims, mode='constant', value=0) - - return img, targets, masks, num_crowds - - - - -def detection_collate(batch): - """Custom collate fn for dealing with batches of images that have a different - number of associated object annotations (bounding boxes). - - Arguments: - batch: (tuple) A tuple of tensor images and (lists of annotations, masks) - - Return: - A tuple containing: - 1) (tensor) batch of images stacked on their 0 dim - 2) (list, list, list) annotations for a given image are stacked - on 0 dim. The output gt is a tuple of annotations and masks. - """ - targets = [] - imgs = [] - masks = [] - num_crowds = [] - - for sample in batch: - imgs.append(sample[0]) - targets.append(torch.FloatTensor(sample[1][0])) - masks.append(torch.FloatTensor(sample[1][1])) - num_crowds.append(sample[1][2]) - - return imgs, (targets, masks, num_crowds) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import os +import os.path as osp +import sys +import torch +import torch.utils.data as data +import torch.nn.functional as F +import cv2 +import numpy as np +from .config import cfg +from pycocotools import mask as maskUtils +import random + +def get_label_map(): + if cfg.dataset.label_map is None: + return {x+1: x+1 for x in range(len(cfg.dataset.class_names))} + else: + return cfg.dataset.label_map + +class COCOAnnotationTransform(object): + """Transforms a COCO annotation into a Tensor of bbox coords and label index + Initilized with a dictionary lookup of classnames to indexes + """ + def __init__(self): + self.label_map = get_label_map() + + def __call__(self, target, width, height): + """ + Args: + target (dict): COCO target json annotation as a python dict + height (int): height + width (int): width + Returns: + a list containing lists of bounding boxes [bbox coords, class idx] + """ + scale = np.array([width, height, width, height]) + res = [] + for obj in target: + if 'bbox' in obj: + bbox = obj['bbox'] + label_idx = obj['category_id'] + if label_idx >= 0: + label_idx = self.label_map[label_idx] - 1 + final_box = list(np.array([bbox[0], bbox[1], bbox[0]+bbox[2], bbox[1]+bbox[3]])/scale) + final_box.append(label_idx) + res += [final_box] # [xmin, ymin, xmax, ymax, label_idx] + else: + print("No bbox found for object ", obj) + + return res + + +class COCODetection(data.Dataset): + """`MS Coco Detection `_ Dataset. + Args: + root (string): Root directory where images are downloaded to. + 这里即为image_path,数据集图像路径 + + set_name (string): Name of the specific set of COCO images. + 自定义,用于标记 + + transform (callable, optional): A function/transform that augments the + raw images` + 图像增强方法 + + target_transform (callable, optional): A function/transform that takes + in the target (bbox) and transforms it. + 将数据集中的目标检测框(bounding box)等封装为一个专门的数据结构 + + prep_crowds (bool): Whether or not to prepare crowds for the evaluation step. + ? + """ + + def __init__(self, image_path, info_file, transform=None, + target_transform=None, + dataset_name='MS COCO', has_gt=True): + #has_gt中的gt代表ground truth,在监督学习中,数据是有标注的,以(x, t)的形式出现,其中x是输入数据,t是标注. + # 正确的t标注是ground truth, 错误的标记则不是。(也有人将所有标注数据都叫做ground truth) + + # Do this here because we have too many things named COCO + from pycocotools.coco import COCO + + if target_transform is None: + target_transform = COCOAnnotationTransform() + + self.root = image_path + self.coco = COCO(info_file) #加载标注文件, 其中COCO对象属性有1、anns :所有标注;2、catToImgs:{种类:[图像list]}的映射字典; + # 3、cats:图片中包含物体的种类;4、dataset:内含信息、许可、标注等;5、imgToAnns:{图像:[标注list]}的映射字典;6、imgs:全部图像 + + self.ids = list(self.coco.imgToAnns.keys()) + if len(self.ids) == 0 or not has_gt: #显然这个if块内语句基本不可能执行 + self.ids = list(self.coco.imgs.keys()) + + self.transform = transform #默认情况下,训练数据使用:SSDAugmentation,验证数据使用:baseTransform + self.target_transform = COCOAnnotationTransform() #82行的if块毫无意义 + + self.name = dataset_name + self.has_gt = has_gt + + def __getitem__(self, index): + """ + Args: + index (int): Index + Returns: + tuple: Tuple (image, (target, masks, num_crowds)). + target is the object returned by ``coco.loadAnns``. + """ + im, gt, masks, h, w, num_crowds = self.pull_item(index) + return (index, im), (gt, masks, num_crowds) + + def __len__(self): + return len(self.ids) + + def pull_item(self, index): + """ + Args: + index (int): Index + Returns: + tuple: Tuple (image, target, masks, height, width, crowd). + target is the object returned by ``coco.loadAnns``. + Note that if no crowd annotations exist, crowd will be None + """ + img_id = self.ids[index] + + if self.has_gt: + ann_ids = self.coco.getAnnIds(imgIds=img_id) + + # Target has {'segmentation', 'area', iscrowd', 'image_id', 'bbox', 'category_id'} + target = [x for x in self.coco.loadAnns(ann_ids) if x['image_id'] == img_id] + else: + target = [] + + # Separate out crowd annotations. These are annotations that signify a large crowd of + # objects of said class, where there is no annotation for each individual object. Both + # during testing and training, consider these crowds as neutral. + crowd = [x for x in target if ('iscrowd' in x and x['iscrowd'])] + target = [x for x in target if not ('iscrowd' in x and x['iscrowd'])] + num_crowds = len(crowd) + + for x in crowd: + x['category_id'] = -1 + + # This is so we ensure that all crowd annotations are at the end of the array + target += crowd + + # The split here is to have compatibility with both COCO2014 and 2017 annotations. + # In 2014, images have the pattern COCO_{train/val}2014_%012d.jpg, while in 2017 it's %012d.jpg. + # Our script downloads the images as %012d.jpg so convert accordingly. + file_name = self.coco.loadImgs(img_id)[0]['file_name'] + + if file_name.startswith('COCO'): + file_name = file_name.split('_')[-1] + + path = osp.join(self.root, file_name) + assert osp.exists(path), 'Image path does not exist: {}'.format(path) + + img = cv2.imread(path) + height, width, _ = img.shape + + if len(target) > 0: + # Pool all the masks for this image into one [num_objects,height,width] matrix + masks = [self.coco.annToMask(obj).reshape(-1) for obj in target] + masks = np.vstack(masks) + masks = masks.reshape(-1, height, width) + + if self.target_transform is not None and len(target) > 0: + target = self.target_transform(target, width, height) + + if self.transform is not None: + if len(target) > 0: + target = np.array(target) + img, masks, boxes, labels = self.transform(img, masks, target[:, :4], + {'num_crowds': num_crowds, 'labels': target[:, 4]}) + + # I stored num_crowds in labels so I didn't have to modify the entirety of augmentations + num_crowds = labels['num_crowds'] + labels = labels['labels'] + + target = np.hstack((boxes, np.expand_dims(labels, axis=1))) + else: + img, _, _, _ = self.transform(img, np.zeros((1, height, width), dtype=np.float), np.array([[0, 0, 1, 1]]), + {'num_crowds': 0, 'labels': np.array([0])}) + masks = None + target = None + + if target.shape[0] == 0: + print('Warning: Augmentation output an example with no ground truth. Resampling...') + return self.pull_item(random.randint(0, len(self.ids)-1)) + + return torch.from_numpy(img).permute(2, 0, 1), target, masks, height, width, num_crowds + + def pull_image(self, index): + '''Returns the original image object at index in PIL form + + Note: not using self.__getitem__(), as any transformations passed in + could mess up this functionality. + + Argument: + index (int): index of img to show + Return: + cv2 img + ''' + img_id = self.ids[index] + path = self.coco.loadImgs(img_id)[0]['file_name'] + return cv2.imread(osp.join(self.root, path), cv2.IMREAD_COLOR) + + def pull_anno(self, index): + '''Returns the original annotation of image at index + + Note: not using self.__getitem__(), as any transformations passed in + could mess up this functionality. + + Argument: + index (int): index of img to get annotation of + Return: + list: [img_id, [(label, bbox coords),...]] + eg: ('001718', [('dog', (96, 13, 438, 332))]) + ''' + img_id = self.ids[index] + ann_ids = self.coco.getAnnIds(imgIds=img_id) + return self.coco.loadAnns(ann_ids) + + def __repr__(self): + fmt_str = 'Dataset ' + self.__class__.__name__ + '\n' + fmt_str += ' Number of datapoints: {}\n'.format(self.__len__()) + fmt_str += ' Root Location: {}\n'.format(self.root) + tmp = ' Transforms (if any): ' + fmt_str += '{0}{1}\n'.format(tmp, self.transform.__repr__().replace('\n', '\n' + ' ' * len(tmp))) + tmp = ' Target Transforms (if any): ' + fmt_str += '{0}{1}'.format(tmp, self.target_transform.__repr__().replace('\n', '\n' + ' ' * len(tmp))) + return fmt_str + +def enforce_size(img, targets, masks, num_crowds, new_w, new_h): + """ Ensures that the image is the given size without distorting aspect ratio. """ + with torch.no_grad(): + _, h, w = img.size() + + if h == new_h and w == new_w: + return img, targets, masks, num_crowds + + # Resize the image so that it fits within new_w, new_h + w_prime = new_w + h_prime = h * new_w / w + + if h_prime > new_h: + w_prime *= new_h / h_prime + h_prime = new_h + + w_prime = int(w_prime) + h_prime = int(h_prime) + + # Do all the resizing + img = F.interpolate(img.unsqueeze(0), (h_prime, w_prime), mode='bilinear', align_corners=False) + img.squeeze_(0) + + # Act like each object is a color channel + masks = F.interpolate(masks.unsqueeze(0), (h_prime, w_prime), mode='bilinear', align_corners=False) + masks.squeeze_(0) + + # Scale bounding boxes (this will put them in the top left corner in the case of padding) + targets[:, [0, 2]] *= (w_prime / new_w) + targets[:, [1, 3]] *= (h_prime / new_h) + + # Finally, pad everything to be the new_w, new_h + pad_dims = (0, new_w - w_prime, 0, new_h - h_prime) + img = F.pad( img, pad_dims, mode='constant', value=0) + masks = F.pad(masks, pad_dims, mode='constant', value=0) + + return img, targets, masks, num_crowds + + + + +def detection_collate(batch): + """Custom collate fn for dealing with batches of images that have a different + number of associated object annotations (bounding boxes). + + Arguments: + batch: (tuple) A tuple of tensor images and (lists of annotations, masks) + + Return: + A tuple containing: + 1) (tensor) batch of images stacked on their 0 dim + 2) (list, list, list) annotations for a given image are stacked + on 0 dim. The output gt is a tuple of annotations and masks. + """ + targets = [] + imgs = [] + masks = [] + num_crowds = [] + + for sample in batch: + imgs.append(sample[0]) + targets.append(torch.FloatTensor(sample[1][0])) + masks.append(torch.FloatTensor(sample[1][1])) + num_crowds.append(sample[1][2]) + + return imgs, (targets, masks, num_crowds) diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/data/config.py b/PyTorch/contrib/cv/detection/YOLACT_plus/data/config.py index 2d66aec919716495e34e25612a0dbb4772be68e4..ee30bae3ba05640a1fbc21f2eb4a180bb937b28f 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/data/config.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/data/config.py @@ -1,842 +1,842 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -from backbone import ResNetBackbone, VGGBackbone, ResNetBackboneGN, DarkNetBackbone -from math import sqrt -import torch - -# for making bounding boxes pretty -COLORS = ((244, 67, 54), - (233, 30, 99), - (156, 39, 176), - (103, 58, 183), - ( 63, 81, 181), - ( 33, 150, 243), - ( 3, 169, 244), - ( 0, 188, 212), - ( 0, 150, 136), - ( 76, 175, 80), - (139, 195, 74), - (205, 220, 57), - (255, 235, 59), - (255, 193, 7), - (255, 152, 0), - (255, 87, 34), - (121, 85, 72), - (158, 158, 158), - ( 96, 125, 139)) - - -# These are in BGR and are for ImageNet -MEANS = (103.94, 116.78, 123.68) -STD = (57.38, 57.12, 58.40) - -COCO_CLASSES = ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', - 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', - 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', - 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', - 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', - 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', - 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', - 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', - 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', - 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', - 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', - 'scissors', 'teddy bear', 'hair drier', 'toothbrush') - -COCO_LABEL_MAP = { 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, - 9: 9, 10: 10, 11: 11, 13: 12, 14: 13, 15: 14, 16: 15, 17: 16, - 18: 17, 19: 18, 20: 19, 21: 20, 22: 21, 23: 22, 24: 23, 25: 24, - 27: 25, 28: 26, 31: 27, 32: 28, 33: 29, 34: 30, 35: 31, 36: 32, - 37: 33, 38: 34, 39: 35, 40: 36, 41: 37, 42: 38, 43: 39, 44: 40, - 46: 41, 47: 42, 48: 43, 49: 44, 50: 45, 51: 46, 52: 47, 53: 48, - 54: 49, 55: 50, 56: 51, 57: 52, 58: 53, 59: 54, 60: 55, 61: 56, - 62: 57, 63: 58, 64: 59, 65: 60, 67: 61, 70: 62, 72: 63, 73: 64, - 74: 65, 75: 66, 76: 67, 77: 68, 78: 69, 79: 70, 80: 71, 81: 72, - 82: 73, 84: 74, 85: 75, 86: 76, 87: 77, 88: 78, 89: 79, 90: 80} - - - -# ----------------------- CONFIG CLASS ----------------------- # - -class Config(object): - """ - Holds the configuration for anything you want it to. - To get the currently active config, call get_cfg(). - - To use, just do cfg.x instead of cfg['x']. - I made this because doing cfg['x'] all the time is dumb. - """ - - def __init__(self, config_dict): - for key, val in config_dict.items(): - self.__setattr__(key, val) - - def copy(self, new_config_dict={}): - """ - Copies this config into a new config object, making - the changes given by new_config_dict. - """ - - ret = Config(vars(self)) - - for key, val in new_config_dict.items(): - ret.__setattr__(key, val) - - return ret - - def replace(self, new_config_dict): - """ - Copies new_config_dict into this config object. - Note: new_config_dict can also be a config object. - """ - if isinstance(new_config_dict, Config): - new_config_dict = vars(new_config_dict) - - for key, val in new_config_dict.items(): - self.__setattr__(key, val) - - def print(self): - for k, v in vars(self).items(): - print(k, ' = ', v) - - - - - -# ----------------------- DATASETS ----------------------- # - -dataset_base = Config({ - 'name': 'Base Dataset', - - # Training images and annotations - 'train_images': './data/coco/images/', - 'train_info': 'path_to_annotation_file', - - # Validation images and annotations. - 'valid_images': './data/coco/images/', - 'valid_info': 'path_to_annotation_file', - - # Whether or not to load GT. If this is False, eval.py quantitative evaluation won't work. - 'has_gt': True, - - # A list of names for each of you classes. - 'class_names': COCO_CLASSES, - - # COCO class ids aren't sequential, so this is a bandage fix. If your ids aren't sequential, - # provide a map from category_id -> index in class_names + 1 (the +1 is there because it's 1-indexed). - # If not specified, this just assumes category ids start at 1 and increase sequentially. - 'label_map': None -}) - -coco2014_dataset = dataset_base.copy({ - 'name': 'COCO 2014', - - 'train_info': './data/coco/annotations/instances_train2014.json', - 'valid_info': './data/coco/annotations/instances_val2014.json', - - 'label_map': COCO_LABEL_MAP -}) - -coco2017_dataset = dataset_base.copy({ - 'name': 'COCO 2017', - - 'train_info': './data/coco/annotations/instances_train2017.json', - 'valid_info': './data/coco/annotations/instances_val2017.json', - - 'label_map': COCO_LABEL_MAP -}) - -coco2017_testdev_dataset = dataset_base.copy({ - 'name': 'COCO 2017 Test-Dev', - - 'valid_info': './data/coco/annotations/image_info_test-dev2017.json', - 'has_gt': False, - - 'label_map': COCO_LABEL_MAP -}) - -PASCAL_CLASSES = ("aeroplane", "bicycle", "bird", "boat", "bottle", - "bus", "car", "cat", "chair", "cow", "diningtable", - "dog", "horse", "motorbike", "person", "pottedplant", - "sheep", "sofa", "train", "tvmonitor") - -pascal_sbd_dataset = dataset_base.copy({ - 'name': 'Pascal SBD 2012', - - 'train_images': './data/sbd/img', - 'valid_images': './data/sbd/img', - - 'train_info': './data/sbd/pascal_sbd_train.json', - 'valid_info': './data/sbd/pascal_sbd_val.json', - - 'class_names': PASCAL_CLASSES, -}) - - - - - -# ----------------------- TRANSFORMS ----------------------- # - -resnet_transform = Config({ - 'channel_order': 'RGB', - 'normalize': True, - 'subtract_means': False, - 'to_float': False, -}) - -vgg_transform = Config({ - # Note that though vgg is traditionally BGR, - # the channel order of vgg_reducedfc.pth is RGB. - 'channel_order': 'RGB', - 'normalize': False, - 'subtract_means': True, - 'to_float': False, -}) - -darknet_transform = Config({ - 'channel_order': 'RGB', - 'normalize': False, - 'subtract_means': False, - 'to_float': True, -}) - - - - - -# ----------------------- BACKBONES ----------------------- # - -backbone_base = Config({ - 'name': 'Base Backbone', - 'path': 'path/to/pretrained/weights', - 'type': object, - 'args': tuple(), - 'transform': resnet_transform, - - 'selected_layers': list(), - 'pred_scales': list(), - 'pred_aspect_ratios': list(), - - 'use_pixel_scales': False, - 'preapply_sqrt': True, - 'use_square_anchors': False, -}) - -resnet101_backbone = backbone_base.copy({ - 'name': 'ResNet101', - 'path': 'resnet101_reducedfc.pth', - 'type': ResNetBackbone, - 'args': ([3, 4, 23, 3],), - 'transform': resnet_transform, - - 'selected_layers': list(range(2, 8)), - 'pred_scales': [[1]]*6, - 'pred_aspect_ratios': [ [[0.66685089, 1.7073535, 0.87508774, 1.16524493, 0.49059086]] ] * 6, -}) - -resnet101_gn_backbone = backbone_base.copy({ - 'name': 'ResNet101_GN', - 'path': 'R-101-GN.pkl', - 'type': ResNetBackboneGN, - 'args': ([3, 4, 23, 3],), - 'transform': resnet_transform, - - 'selected_layers': list(range(2, 8)), - 'pred_scales': [[1]]*6, - 'pred_aspect_ratios': [ [[0.66685089, 1.7073535, 0.87508774, 1.16524493, 0.49059086]] ] * 6, -}) - -resnet101_dcn_inter3_backbone = resnet101_backbone.copy({ - 'name': 'ResNet101_DCN_Interval3', - 'args': ([3, 4, 23, 3], [0, 4, 23, 3], 3), -}) - -resnet50_backbone = resnet101_backbone.copy({ - 'name': 'ResNet50', - 'path': 'resnet50-19c8e357.pth', - 'type': ResNetBackbone, - 'args': ([3, 4, 6, 3],), - 'transform': resnet_transform, -}) - -resnet50_dcnv2_backbone = resnet50_backbone.copy({ - 'name': 'ResNet50_DCNv2', - 'args': ([3, 4, 6, 3], [0, 4, 6, 3]), -}) - -darknet53_backbone = backbone_base.copy({ - 'name': 'DarkNet53', - 'path': 'darknet53.pth', - 'type': DarkNetBackbone, - 'args': ([1, 2, 8, 8, 4],), - 'transform': darknet_transform, - - 'selected_layers': list(range(3, 9)), - 'pred_scales': [[3.5, 4.95], [3.6, 4.90], [3.3, 4.02], [2.7, 3.10], [2.1, 2.37], [1.8, 1.92]], - 'pred_aspect_ratios': [ [[1, sqrt(2), 1/sqrt(2), sqrt(3), 1/sqrt(3)][:n], [1]] for n in [3, 5, 5, 5, 3, 3] ], -}) - -vgg16_arch = [[64, 64], - [ 'M', 128, 128], - [ 'M', 256, 256, 256], - [('M', {'kernel_size': 2, 'stride': 2, 'ceil_mode': True}), 512, 512, 512], - [ 'M', 512, 512, 512], - [('M', {'kernel_size': 3, 'stride': 1, 'padding': 1}), - (1024, {'kernel_size': 3, 'padding': 6, 'dilation': 6}), - (1024, {'kernel_size': 1})]] - -vgg16_backbone = backbone_base.copy({ - 'name': 'VGG16', - 'path': 'vgg16_reducedfc.pth', - 'type': VGGBackbone, - 'args': (vgg16_arch, [(256, 2), (128, 2), (128, 1), (128, 1)], [3]), - 'transform': vgg_transform, - - 'selected_layers': [3] + list(range(5, 10)), - 'pred_scales': [[5, 4]]*6, - 'pred_aspect_ratios': [ [[1], [1, sqrt(2), 1/sqrt(2), sqrt(3), 1/sqrt(3)][:n]] for n in [3, 5, 5, 5, 3, 3] ], -}) - - - - - -# ----------------------- MASK BRANCH TYPES ----------------------- # - -mask_type = Config({ - # Direct produces masks directly as the output of each pred module. - # This is denoted as fc-mask in the paper. - # Parameters: mask_size, use_gt_bboxes - 'direct': 0, - - # Lincomb produces coefficients as the output of each pred module then uses those coefficients - # to linearly combine features from a prototype network to create image-sized masks. - # Parameters: - # - masks_to_train (int): Since we're producing (near) full image masks, it'd take too much - # vram to backprop on every single mask. Thus we select only a subset. - # - mask_proto_src (int): The input layer to the mask prototype generation network. This is an - # index in backbone.layers. Use to use the image itself instead. - # - mask_proto_net (list): A list of layers in the mask proto network with the last one - # being where the masks are taken from. Each conv layer is in - # the form (num_features, kernel_size, **kwdargs). An empty - # list means to use the source for prototype masks. If the - # kernel_size is negative, this creates a deconv layer instead. - # If the kernel_size is negative and the num_features is None, - # this creates a simple bilinear interpolation layer instead. - # - mask_proto_bias (bool): Whether to include an extra coefficient that corresponds to a proto - # mask of all ones. - # - mask_proto_prototype_activation (func): The activation to apply to each prototype mask. - # - mask_proto_mask_activation (func): After summing the prototype masks with the predicted - # coeffs, what activation to apply to the final mask. - # - mask_proto_coeff_activation (func): The activation to apply to the mask coefficients. - # - mask_proto_crop (bool): If True, crop the mask with the predicted bbox during training. - # - mask_proto_crop_expand (float): If cropping, the percent to expand the cropping bbox by - # in each direction. This is to make the model less reliant - # on perfect bbox predictions. - # - mask_proto_loss (str [l1|disj]): If not None, apply an l1 or disjunctive regularization - # loss directly to the prototype masks. - # - mask_proto_binarize_downsampled_gt (bool): Binarize GT after dowsnampling during training? - # - mask_proto_normalize_mask_loss_by_sqrt_area (bool): Whether to normalize mask loss by sqrt(sum(gt)) - # - mask_proto_reweight_mask_loss (bool): Reweight mask loss such that background is divided by - # #background and foreground is divided by #foreground. - # - mask_proto_grid_file (str): The path to the grid file to use with the next option. - # This should be a numpy.dump file with shape [numgrids, h, w] - # where h and w are w.r.t. the mask_proto_src convout. - # - mask_proto_use_grid (bool): Whether to add extra grid features to the proto_net input. - # - mask_proto_coeff_gate (bool): Add an extra set of sigmoided coefficients that is multiplied - # into the predicted coefficients in order to "gate" them. - # - mask_proto_prototypes_as_features (bool): For each prediction module, downsample the prototypes - # to the convout size of that module and supply the prototypes as input - # in addition to the already supplied backbone features. - # - mask_proto_prototypes_as_features_no_grad (bool): If the above is set, don't backprop gradients to - # to the prototypes from the network head. - # - mask_proto_remove_empty_masks (bool): Remove masks that are downsampled to 0 during loss calculations. - # - mask_proto_reweight_coeff (float): The coefficient to multiple the forground pixels with if reweighting. - # - mask_proto_coeff_diversity_loss (bool): Apply coefficient diversity loss on the coefficients so that the same - # instance has similar coefficients. - # - mask_proto_coeff_diversity_alpha (float): The weight to use for the coefficient diversity loss. - # - mask_proto_normalize_emulate_roi_pooling (bool): Normalize the mask loss to emulate roi pooling's affect on loss. - # - mask_proto_double_loss (bool): Whether to use the old loss in addition to any special new losses. - # - mask_proto_double_loss_alpha (float): The alpha to weight the above loss. - # - mask_proto_split_prototypes_by_head (bool): If true, this will give each prediction head its own prototypes. - # - mask_proto_crop_with_pred_box (bool): Whether to crop with the predicted box or the gt box. - 'lincomb': 1, -}) - - - - - -# ----------------------- ACTIVATION FUNCTIONS ----------------------- # - -activation_func = Config({ - 'tanh': torch.tanh, - 'sigmoid': torch.sigmoid, - 'softmax': lambda x: torch.nn.functional.softmax(x, dim=-1), - 'relu': lambda x: torch.nn.functional.relu(x, inplace=True), - 'none': lambda x: x, -}) - - - - - -# ----------------------- FPN DEFAULTS ----------------------- # - -fpn_base = Config({ - # The number of features to have in each FPN layer - 'num_features': 256, - - # The upsampling mode used - 'interpolation_mode': 'bilinear', - - # The number of extra layers to be produced by downsampling starting at P5 - 'num_downsample': 1, - - # Whether to down sample with a 3x3 stride 2 conv layer instead of just a stride 2 selection - 'use_conv_downsample': False, - - # Whether to pad the pred layers with 1 on each side (I forgot to add this at the start) - # This is just here for backwards compatibility - 'pad': True, - - # Whether to add relu to the downsampled layers. - 'relu_downsample_layers': False, - - # Whether to add relu to the regular layers - 'relu_pred_layers': True, -}) - - - - - -# ----------------------- CONFIG DEFAULTS ----------------------- # - -coco_base_config = Config({ - 'dataset': coco2014_dataset, - 'num_classes': 81, # This should include the background class - - 'max_iter': 400000, - - # The maximum number of detections for evaluation - 'max_num_detections': 100, - - # dw' = momentum * dw - lr * (grad + decay * w) - 'lr': 1e-3, - 'momentum': 0.9, - 'decay': 5e-4, - - # For each lr step, what to multiply the lr with - 'gamma': 0.1, - 'lr_steps': (280000, 360000, 400000), - - # Initial learning rate to linearly warmup from (if until > 0) - 'lr_warmup_init': 1e-4, - - # If > 0 then increase the lr linearly from warmup_init to lr each iter for until iters - 'lr_warmup_until': 500, - - # The terms to scale the respective loss by - 'conf_alpha': 1, - 'bbox_alpha': 1.5, - 'mask_alpha': 0.4 / 256 * 140 * 140, # Some funky equation. Don't worry about it. - - # Eval.py sets this if you just want to run YOLACT as a detector - 'eval_mask_branch': True, - - # Top_k examples to consider for NMS - 'nms_top_k': 200, - # Examples with confidence less than this are not considered by NMS - 'nms_conf_thresh': 0.05, - # Boxes with IoU overlap greater than this threshold will be culled during NMS - 'nms_thresh': 0.5, - - # See mask_type for details. - 'mask_type': mask_type.direct, - 'mask_size': 16, - 'masks_to_train': 100, - 'mask_proto_src': None, - 'mask_proto_net': [(256, 3, {}), (256, 3, {})], - 'mask_proto_bias': False, - 'mask_proto_prototype_activation': activation_func.relu, - 'mask_proto_mask_activation': activation_func.sigmoid, - 'mask_proto_coeff_activation': activation_func.tanh, - 'mask_proto_crop': True, - 'mask_proto_crop_expand': 0, - 'mask_proto_loss': None, - 'mask_proto_binarize_downsampled_gt': True, - 'mask_proto_normalize_mask_loss_by_sqrt_area': False, - 'mask_proto_reweight_mask_loss': False, - 'mask_proto_grid_file': 'data/grid.npy', - 'mask_proto_use_grid': False, - 'mask_proto_coeff_gate': False, - 'mask_proto_prototypes_as_features': False, - 'mask_proto_prototypes_as_features_no_grad': False, - 'mask_proto_remove_empty_masks': False, - 'mask_proto_reweight_coeff': 1, - 'mask_proto_coeff_diversity_loss': False, - 'mask_proto_coeff_diversity_alpha': 1, - 'mask_proto_normalize_emulate_roi_pooling': False, - 'mask_proto_double_loss': False, - 'mask_proto_double_loss_alpha': 1, - 'mask_proto_split_prototypes_by_head': False, - 'mask_proto_crop_with_pred_box': False, - - # SSD data augmentation parameters - # Randomize hue, vibrance, etc. - 'augment_photometric_distort': True, - # Have a chance to scale down the image and pad (to emulate smaller detections) - 'augment_expand': True, - # Potentialy sample a random crop from the image and put it in a random place - 'augment_random_sample_crop': True, - # Mirror the image with a probability of 1/2 - 'augment_random_mirror': True, - # Flip the image vertically with a probability of 1/2 - 'augment_random_flip': False, - # With uniform probability, rotate the image [0,90,180,270] degrees - 'augment_random_rot90': False, - - # Discard detections with width and height smaller than this (in absolute width and height) - 'discard_box_width': 4 / 550, - 'discard_box_height': 4 / 550, - - # If using batchnorm anywhere in the backbone, freeze the batchnorm layer during training. - # Note: any additional batch norm layers after the backbone will not be frozen. - 'freeze_bn': False, - - # Set this to a config object if you want an FPN (inherit from fpn_base). See fpn_base for details. - 'fpn': None, - - # Use the same weights for each network head - 'share_prediction_module': False, - - # For hard negative mining, instead of using the negatives that are leastl confidently background, - # use negatives that are most confidently not background. - 'ohem_use_most_confident': False, - - # Use focal loss as described in https://arxiv.org/pdf/1708.02002.pdf instead of OHEM - 'use_focal_loss': False, - 'focal_loss_alpha': 0.25, - 'focal_loss_gamma': 2, - - # The initial bias toward forground objects, as specified in the focal loss paper - 'focal_loss_init_pi': 0.01, - - # Keeps track of the average number of examples for each class, and weights the loss for that class accordingly. - 'use_class_balanced_conf': False, - - # Whether to use sigmoid focal loss instead of softmax, all else being the same. - 'use_sigmoid_focal_loss': False, - - # Use class[0] to be the objectness score and class[1:] to be the softmax predicted class. - # Note: at the moment this is only implemented if use_focal_loss is on. - 'use_objectness_score': False, - - # Adds a global pool + fc layer to the smallest selected layer that predicts the existence of each of the 80 classes. - # This branch is only evaluated during training time and is just there for multitask learning. - 'use_class_existence_loss': False, - 'class_existence_alpha': 1, - - # Adds a 1x1 convolution directly to the biggest selected layer that predicts a semantic segmentations for each of the 80 classes. - # This branch is only evaluated during training time and is just there for multitask learning. - 'use_semantic_segmentation_loss': False, - 'semantic_segmentation_alpha': 1, - - # Adds another branch to the netwok to predict Mask IoU. - 'use_mask_scoring': False, - 'mask_scoring_alpha': 1, - - # Match gt boxes using the Box2Pix change metric instead of the standard IoU metric. - # Note that the threshold you set for iou_threshold should be negative with this setting on. - 'use_change_matching': False, - - # Uses the same network format as mask_proto_net, except this time it's for adding extra head layers before the final - # prediction in prediction modules. If this is none, no extra layers will be added. - 'extra_head_net': None, - - # What params should the final head layers have (the ones that predict box, confidence, and mask coeffs) - 'head_layer_params': {'kernel_size': 3, 'padding': 1}, - - # Add extra layers between the backbone and the network heads - # The order is (bbox, conf, mask) - 'extra_layers': (0, 0, 0), - - # During training, to match detections with gt, first compute the maximum gt IoU for each prior. - # Then, any of those priors whose maximum overlap is over the positive threshold, mark as positive. - # For any priors whose maximum is less than the negative iou threshold, mark them as negative. - # The rest are neutral and not used in calculating the loss. - 'positive_iou_threshold': 0.5, - 'negative_iou_threshold': 0.5, - - # When using ohem, the ratio between positives and negatives (3 means 3 negatives to 1 positive) - 'ohem_negpos_ratio': 3, - - # If less than 1, anchors treated as a negative that have a crowd iou over this threshold with - # the crowd boxes will be treated as a neutral. - 'crowd_iou_threshold': 1, - - # This is filled in at runtime by Yolact's __init__, so don't touch it - 'mask_dim': None, - - # Input image size. - 'max_size': 300, - - # Whether or not to do post processing on the cpu at test time - 'force_cpu_nms': True, - - # Whether to use mask coefficient cosine similarity nms instead of bbox iou nms - 'use_coeff_nms': False, - - # Whether or not to have a separate branch whose sole purpose is to act as the coefficients for coeff_diversity_loss - # Remember to turn on coeff_diversity_loss, or these extra coefficients won't do anything! - # To see their effect, also remember to turn on use_coeff_nms. - 'use_instance_coeff': False, - 'num_instance_coeffs': 64, - - # Whether or not to tie the mask loss / box loss to 0 - 'train_masks': True, - 'train_boxes': True, - # If enabled, the gt masks will be cropped using the gt bboxes instead of the predicted ones. - # This speeds up training time considerably but results in much worse mAP at test time. - 'use_gt_bboxes': False, - - # Whether or not to preserve aspect ratio when resizing the image. - # If True, this will resize all images to be max_size^2 pixels in area while keeping aspect ratio. - # If False, all images are resized to max_size x max_size - 'preserve_aspect_ratio': False, - - # Whether or not to use the prediction module (c) from DSSD - 'use_prediction_module': False, - - # Whether or not to use the predicted coordinate scheme from Yolo v2 - 'use_yolo_regressors': False, - - # For training, bboxes are considered "positive" if their anchors have a 0.5 IoU overlap - # or greater with a ground truth box. If this is true, instead of using the anchor boxes - # for this IoU computation, the matching function will use the predicted bbox coordinates. - # Don't turn this on if you're not using yolo regressors! - 'use_prediction_matching': False, - - # A list of settings to apply after the specified iteration. Each element of the list should look like - # (iteration, config_dict) where config_dict is a dictionary you'd pass into a config object's init. - 'delayed_settings': [], - - # Use command-line arguments to set this. - 'no_jit': False, - - 'backbone': None, - 'name': 'base_config', - - # Fast Mask Re-scoring Network - # Inspried by Mask Scoring R-CNN (https://arxiv.org/abs/1903.00241) - # Do not crop out the mask with bbox but slide a convnet on the image-size mask, - # then use global pooling to get the final mask score - 'use_maskiou': False, - - # Archecture for the mask iou network. A (num_classes-1, 1, {}) layer is appended to the end. - 'maskiou_net': [], - - # Discard predicted masks whose area is less than this - 'discard_mask_area': -1, - - 'maskiou_alpha': 1.0, - 'rescore_mask': False, - 'rescore_bbox': False, - 'maskious_to_train': -1, -}) - - - - - -# ----------------------- YOLACT v1.0 CONFIGS ----------------------- # - -yolact_base_config = coco_base_config.copy({ - 'name': 'yolact_base', - - # Dataset stuff - 'dataset': coco2017_dataset, - 'num_classes': len(coco2017_dataset.class_names) + 1, - - # Image Size - 'max_size': 550, - - # Training params - 'lr_steps': (280000, 600000, 700000, 750000), - 'max_iter': 1200000, - - # Backbone Settings - 'backbone': resnet101_backbone.copy({ - 'selected_layers': list(range(1, 4)), - 'use_pixel_scales': True, - 'preapply_sqrt': False, - 'use_square_anchors': True, # This is for backward compatability with a bug - - 'pred_aspect_ratios': [ [[1, 1/2, 2]] ]*5, - 'pred_scales': [[24], [48], [96], [192], [384]], - }), - - # FPN Settings - 'fpn': fpn_base.copy({ - 'use_conv_downsample': True, - 'num_downsample': 2, - }), - - # Mask Settings - 'mask_type': mask_type.lincomb, - 'mask_alpha': 6.125, - 'mask_proto_src': 0, - 'mask_proto_net': [(256, 3, {'padding': 1})] * 3 + [(None, -2, {}), (256, 3, {'padding': 1})] + [(32, 1, {})], - 'mask_proto_normalize_emulate_roi_pooling': True, - - # Other stuff - 'share_prediction_module': True, - 'extra_head_net': [(256, 3, {'padding': 1})], - - 'positive_iou_threshold': 0.5, - 'negative_iou_threshold': 0.4, - - 'crowd_iou_threshold': 0.7, - - 'use_semantic_segmentation_loss': True, -}) - -yolact_im400_config = yolact_base_config.copy({ - 'name': 'yolact_im400', - - 'max_size': 400, - 'backbone': yolact_base_config.backbone.copy({ - 'pred_scales': [[int(x[0] / yolact_base_config.max_size * 400)] for x in yolact_base_config.backbone.pred_scales], - }), -}) - -yolact_im700_config = yolact_base_config.copy({ - 'name': 'yolact_im700', - - 'masks_to_train': 300, - 'max_size': 700, - 'backbone': yolact_base_config.backbone.copy({ - 'pred_scales': [[int(x[0] / yolact_base_config.max_size * 700)] for x in yolact_base_config.backbone.pred_scales], - }), -}) - -yolact_darknet53_config = yolact_base_config.copy({ - 'name': 'yolact_darknet53', - - 'backbone': darknet53_backbone.copy({ - 'selected_layers': list(range(2, 5)), - - 'pred_scales': yolact_base_config.backbone.pred_scales, - 'pred_aspect_ratios': yolact_base_config.backbone.pred_aspect_ratios, - 'use_pixel_scales': True, - 'preapply_sqrt': False, - 'use_square_anchors': True, # This is for backward compatability with a bug - }), -}) - -yolact_resnet50_config = yolact_base_config.copy({ - 'name': 'yolact_resnet50', - - 'backbone': resnet50_backbone.copy({ - 'selected_layers': list(range(1, 4)), - - 'pred_scales': yolact_base_config.backbone.pred_scales, - 'pred_aspect_ratios': yolact_base_config.backbone.pred_aspect_ratios, - 'use_pixel_scales': True, - 'preapply_sqrt': False, - 'use_square_anchors': True, # This is for backward compatability with a bug - }), -}) - - -yolact_resnet50_pascal_config = yolact_resnet50_config.copy({ - 'name': None, # Will default to yolact_resnet50_pascal - - # Dataset stuff - 'dataset': pascal_sbd_dataset, - 'num_classes': len(pascal_sbd_dataset.class_names) + 1, - - 'max_iter': 120000, - 'lr_steps': (60000, 100000), - - 'backbone': yolact_resnet50_config.backbone.copy({ - 'pred_scales': [[32], [64], [128], [256], [512]], - 'use_square_anchors': False, - }) -}) - -# ----------------------- YOLACT++ CONFIGS ----------------------- # - -yolact_plus_base_config = yolact_base_config.copy({ - 'name': 'yolact_plus_base', - - 'backbone': resnet101_dcn_inter3_backbone.copy({ - 'selected_layers': list(range(1, 4)), - - 'pred_aspect_ratios': [ [[1, 1/2, 2]] ]*5, - 'pred_scales': [[i * 2 ** (j / 3.0) for j in range(3)] for i in [24, 48, 96, 192, 384]], - 'use_pixel_scales': True, - 'preapply_sqrt': False, - 'use_square_anchors': False, - }), - - 'use_maskiou': False, - 'maskiou_net': [(8, 3, {'stride': 2}), (16, 3, {'stride': 2}), (32, 3, {'stride': 2}), (64, 3, {'stride': 2}), (128, 3, {'stride': 2})], - 'maskiou_alpha': 25, - 'rescore_bbox': False, - 'rescore_mask': True, - - 'discard_mask_area': 5*5, -}) - -yolact_plus_resnet50_config = yolact_plus_base_config.copy({ - 'name': 'yolact_plus_resnet50', - - 'backbone': resnet50_dcnv2_backbone.copy({ - 'selected_layers': list(range(1, 4)), - - 'pred_aspect_ratios': [ [[1, 1/2, 2]] ]*5, - 'pred_scales': [[i * 2 ** (j / 3.0) for j in range(3)] for i in [24, 48, 96, 192, 384]], - 'use_pixel_scales': True, - 'preapply_sqrt': False, - 'use_square_anchors': False, - }), -}) -yolact_plus_resnet50_inf_config = yolact_plus_resnet50_config.copy({ - 'use_maskiou': True -}) - -# Default config -cfg = yolact_base_config.copy() - -def set_cfg(config_name:str): - """ Sets the active config. Works even if cfg is already imported! """ - global cfg - - # Note this is not just an eval because I'm lazy, but also because it can - # be used like ssd300_config.copy({'max_size': 400}) for extreme fine-tuning - cfg.replace(eval(config_name)) - - if cfg.name is None: - cfg.name = config_name.split('_config')[0] - -def set_dataset(dataset_name:str): - """ Sets the dataset of the current config. """ - cfg.dataset = eval(dataset_name) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +from backbone import ResNetBackbone, VGGBackbone, ResNetBackboneGN, DarkNetBackbone +from math import sqrt +import torch + +# for making bounding boxes pretty +COLORS = ((244, 67, 54), + (233, 30, 99), + (156, 39, 176), + (103, 58, 183), + ( 63, 81, 181), + ( 33, 150, 243), + ( 3, 169, 244), + ( 0, 188, 212), + ( 0, 150, 136), + ( 76, 175, 80), + (139, 195, 74), + (205, 220, 57), + (255, 235, 59), + (255, 193, 7), + (255, 152, 0), + (255, 87, 34), + (121, 85, 72), + (158, 158, 158), + ( 96, 125, 139)) + + +# These are in BGR and are for ImageNet +MEANS = (103.94, 116.78, 123.68) +STD = (57.38, 57.12, 58.40) + +COCO_CLASSES = ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', + 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', + 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', + 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', + 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', + 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', + 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', + 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', + 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', + 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', + 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', + 'scissors', 'teddy bear', 'hair drier', 'toothbrush') + +COCO_LABEL_MAP = { 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, + 9: 9, 10: 10, 11: 11, 13: 12, 14: 13, 15: 14, 16: 15, 17: 16, + 18: 17, 19: 18, 20: 19, 21: 20, 22: 21, 23: 22, 24: 23, 25: 24, + 27: 25, 28: 26, 31: 27, 32: 28, 33: 29, 34: 30, 35: 31, 36: 32, + 37: 33, 38: 34, 39: 35, 40: 36, 41: 37, 42: 38, 43: 39, 44: 40, + 46: 41, 47: 42, 48: 43, 49: 44, 50: 45, 51: 46, 52: 47, 53: 48, + 54: 49, 55: 50, 56: 51, 57: 52, 58: 53, 59: 54, 60: 55, 61: 56, + 62: 57, 63: 58, 64: 59, 65: 60, 67: 61, 70: 62, 72: 63, 73: 64, + 74: 65, 75: 66, 76: 67, 77: 68, 78: 69, 79: 70, 80: 71, 81: 72, + 82: 73, 84: 74, 85: 75, 86: 76, 87: 77, 88: 78, 89: 79, 90: 80} + + + +# ----------------------- CONFIG CLASS ----------------------- # + +class Config(object): + """ + Holds the configuration for anything you want it to. + To get the currently active config, call get_cfg(). + + To use, just do cfg.x instead of cfg['x']. + I made this because doing cfg['x'] all the time is dumb. + """ + + def __init__(self, config_dict): + for key, val in config_dict.items(): + self.__setattr__(key, val) + + def copy(self, new_config_dict={}): + """ + Copies this config into a new config object, making + the changes given by new_config_dict. + """ + + ret = Config(vars(self)) + + for key, val in new_config_dict.items(): + ret.__setattr__(key, val) + + return ret + + def replace(self, new_config_dict): + """ + Copies new_config_dict into this config object. + Note: new_config_dict can also be a config object. + """ + if isinstance(new_config_dict, Config): + new_config_dict = vars(new_config_dict) + + for key, val in new_config_dict.items(): + self.__setattr__(key, val) + + def print(self): + for k, v in vars(self).items(): + print(k, ' = ', v) + + + + + +# ----------------------- DATASETS ----------------------- # + +dataset_base = Config({ + 'name': 'Base Dataset', + + # Training images and annotations + 'train_images': './data/coco/images/', + 'train_info': 'path_to_annotation_file', + + # Validation images and annotations. + 'valid_images': './data/coco/images/', + 'valid_info': 'path_to_annotation_file', + + # Whether or not to load GT. If this is False, eval.py quantitative evaluation won't work. + 'has_gt': True, + + # A list of names for each of you classes. + 'class_names': COCO_CLASSES, + + # COCO class ids aren't sequential, so this is a bandage fix. If your ids aren't sequential, + # provide a map from category_id -> index in class_names + 1 (the +1 is there because it's 1-indexed). + # If not specified, this just assumes category ids start at 1 and increase sequentially. + 'label_map': None +}) + +coco2014_dataset = dataset_base.copy({ + 'name': 'COCO 2014', + + 'train_info': './data/coco/annotations/instances_train2014.json', + 'valid_info': './data/coco/annotations/instances_val2014.json', + + 'label_map': COCO_LABEL_MAP +}) + +coco2017_dataset = dataset_base.copy({ + 'name': 'COCO 2017', + + 'train_info': './data/coco/annotations/instances_train2017.json', + 'valid_info': './data/coco/annotations/instances_val2017.json', + + 'label_map': COCO_LABEL_MAP +}) + +coco2017_testdev_dataset = dataset_base.copy({ + 'name': 'COCO 2017 Test-Dev', + + 'valid_info': './data/coco/annotations/image_info_test-dev2017.json', + 'has_gt': False, + + 'label_map': COCO_LABEL_MAP +}) + +PASCAL_CLASSES = ("aeroplane", "bicycle", "bird", "boat", "bottle", + "bus", "car", "cat", "chair", "cow", "diningtable", + "dog", "horse", "motorbike", "person", "pottedplant", + "sheep", "sofa", "train", "tvmonitor") + +pascal_sbd_dataset = dataset_base.copy({ + 'name': 'Pascal SBD 2012', + + 'train_images': './data/sbd/img', + 'valid_images': './data/sbd/img', + + 'train_info': './data/sbd/pascal_sbd_train.json', + 'valid_info': './data/sbd/pascal_sbd_val.json', + + 'class_names': PASCAL_CLASSES, +}) + + + + + +# ----------------------- TRANSFORMS ----------------------- # + +resnet_transform = Config({ + 'channel_order': 'RGB', + 'normalize': True, + 'subtract_means': False, + 'to_float': False, +}) + +vgg_transform = Config({ + # Note that though vgg is traditionally BGR, + # the channel order of vgg_reducedfc.pth is RGB. + 'channel_order': 'RGB', + 'normalize': False, + 'subtract_means': True, + 'to_float': False, +}) + +darknet_transform = Config({ + 'channel_order': 'RGB', + 'normalize': False, + 'subtract_means': False, + 'to_float': True, +}) + + + + + +# ----------------------- BACKBONES ----------------------- # + +backbone_base = Config({ + 'name': 'Base Backbone', + 'path': 'path/to/pretrained/weights', + 'type': object, + 'args': tuple(), + 'transform': resnet_transform, + + 'selected_layers': list(), + 'pred_scales': list(), + 'pred_aspect_ratios': list(), + + 'use_pixel_scales': False, + 'preapply_sqrt': True, + 'use_square_anchors': False, +}) + +resnet101_backbone = backbone_base.copy({ + 'name': 'ResNet101', + 'path': 'resnet101_reducedfc.pth', + 'type': ResNetBackbone, + 'args': ([3, 4, 23, 3],), + 'transform': resnet_transform, + + 'selected_layers': list(range(2, 8)), + 'pred_scales': [[1]]*6, + 'pred_aspect_ratios': [ [[0.66685089, 1.7073535, 0.87508774, 1.16524493, 0.49059086]] ] * 6, +}) + +resnet101_gn_backbone = backbone_base.copy({ + 'name': 'ResNet101_GN', + 'path': 'R-101-GN.pkl', + 'type': ResNetBackboneGN, + 'args': ([3, 4, 23, 3],), + 'transform': resnet_transform, + + 'selected_layers': list(range(2, 8)), + 'pred_scales': [[1]]*6, + 'pred_aspect_ratios': [ [[0.66685089, 1.7073535, 0.87508774, 1.16524493, 0.49059086]] ] * 6, +}) + +resnet101_dcn_inter3_backbone = resnet101_backbone.copy({ + 'name': 'ResNet101_DCN_Interval3', + 'args': ([3, 4, 23, 3], [0, 4, 23, 3], 3), +}) + +resnet50_backbone = resnet101_backbone.copy({ + 'name': 'ResNet50', + 'path': 'resnet50-19c8e357.pth', + 'type': ResNetBackbone, + 'args': ([3, 4, 6, 3],), + 'transform': resnet_transform, +}) + +resnet50_dcnv2_backbone = resnet50_backbone.copy({ + 'name': 'ResNet50_DCNv2', + 'args': ([3, 4, 6, 3], [0, 4, 6, 3]), +}) + +darknet53_backbone = backbone_base.copy({ + 'name': 'DarkNet53', + 'path': 'darknet53.pth', + 'type': DarkNetBackbone, + 'args': ([1, 2, 8, 8, 4],), + 'transform': darknet_transform, + + 'selected_layers': list(range(3, 9)), + 'pred_scales': [[3.5, 4.95], [3.6, 4.90], [3.3, 4.02], [2.7, 3.10], [2.1, 2.37], [1.8, 1.92]], + 'pred_aspect_ratios': [ [[1, sqrt(2), 1/sqrt(2), sqrt(3), 1/sqrt(3)][:n], [1]] for n in [3, 5, 5, 5, 3, 3] ], +}) + +vgg16_arch = [[64, 64], + [ 'M', 128, 128], + [ 'M', 256, 256, 256], + [('M', {'kernel_size': 2, 'stride': 2, 'ceil_mode': True}), 512, 512, 512], + [ 'M', 512, 512, 512], + [('M', {'kernel_size': 3, 'stride': 1, 'padding': 1}), + (1024, {'kernel_size': 3, 'padding': 6, 'dilation': 6}), + (1024, {'kernel_size': 1})]] + +vgg16_backbone = backbone_base.copy({ + 'name': 'VGG16', + 'path': 'vgg16_reducedfc.pth', + 'type': VGGBackbone, + 'args': (vgg16_arch, [(256, 2), (128, 2), (128, 1), (128, 1)], [3]), + 'transform': vgg_transform, + + 'selected_layers': [3] + list(range(5, 10)), + 'pred_scales': [[5, 4]]*6, + 'pred_aspect_ratios': [ [[1], [1, sqrt(2), 1/sqrt(2), sqrt(3), 1/sqrt(3)][:n]] for n in [3, 5, 5, 5, 3, 3] ], +}) + + + + + +# ----------------------- MASK BRANCH TYPES ----------------------- # + +mask_type = Config({ + # Direct produces masks directly as the output of each pred module. + # This is denoted as fc-mask in the paper. + # Parameters: mask_size, use_gt_bboxes + 'direct': 0, + + # Lincomb produces coefficients as the output of each pred module then uses those coefficients + # to linearly combine features from a prototype network to create image-sized masks. + # Parameters: + # - masks_to_train (int): Since we're producing (near) full image masks, it'd take too much + # vram to backprop on every single mask. Thus we select only a subset. + # - mask_proto_src (int): The input layer to the mask prototype generation network. This is an + # index in backbone.layers. Use to use the image itself instead. + # - mask_proto_net (list): A list of layers in the mask proto network with the last one + # being where the masks are taken from. Each conv layer is in + # the form (num_features, kernel_size, **kwdargs). An empty + # list means to use the source for prototype masks. If the + # kernel_size is negative, this creates a deconv layer instead. + # If the kernel_size is negative and the num_features is None, + # this creates a simple bilinear interpolation layer instead. + # - mask_proto_bias (bool): Whether to include an extra coefficient that corresponds to a proto + # mask of all ones. + # - mask_proto_prototype_activation (func): The activation to apply to each prototype mask. + # - mask_proto_mask_activation (func): After summing the prototype masks with the predicted + # coeffs, what activation to apply to the final mask. + # - mask_proto_coeff_activation (func): The activation to apply to the mask coefficients. + # - mask_proto_crop (bool): If True, crop the mask with the predicted bbox during training. + # - mask_proto_crop_expand (float): If cropping, the percent to expand the cropping bbox by + # in each direction. This is to make the model less reliant + # on perfect bbox predictions. + # - mask_proto_loss (str [l1|disj]): If not None, apply an l1 or disjunctive regularization + # loss directly to the prototype masks. + # - mask_proto_binarize_downsampled_gt (bool): Binarize GT after dowsnampling during training? + # - mask_proto_normalize_mask_loss_by_sqrt_area (bool): Whether to normalize mask loss by sqrt(sum(gt)) + # - mask_proto_reweight_mask_loss (bool): Reweight mask loss such that background is divided by + # #background and foreground is divided by #foreground. + # - mask_proto_grid_file (str): The path to the grid file to use with the next option. + # This should be a numpy.dump file with shape [numgrids, h, w] + # where h and w are w.r.t. the mask_proto_src convout. + # - mask_proto_use_grid (bool): Whether to add extra grid features to the proto_net input. + # - mask_proto_coeff_gate (bool): Add an extra set of sigmoided coefficients that is multiplied + # into the predicted coefficients in order to "gate" them. + # - mask_proto_prototypes_as_features (bool): For each prediction module, downsample the prototypes + # to the convout size of that module and supply the prototypes as input + # in addition to the already supplied backbone features. + # - mask_proto_prototypes_as_features_no_grad (bool): If the above is set, don't backprop gradients to + # to the prototypes from the network head. + # - mask_proto_remove_empty_masks (bool): Remove masks that are downsampled to 0 during loss calculations. + # - mask_proto_reweight_coeff (float): The coefficient to multiple the forground pixels with if reweighting. + # - mask_proto_coeff_diversity_loss (bool): Apply coefficient diversity loss on the coefficients so that the same + # instance has similar coefficients. + # - mask_proto_coeff_diversity_alpha (float): The weight to use for the coefficient diversity loss. + # - mask_proto_normalize_emulate_roi_pooling (bool): Normalize the mask loss to emulate roi pooling's affect on loss. + # - mask_proto_double_loss (bool): Whether to use the old loss in addition to any special new losses. + # - mask_proto_double_loss_alpha (float): The alpha to weight the above loss. + # - mask_proto_split_prototypes_by_head (bool): If true, this will give each prediction head its own prototypes. + # - mask_proto_crop_with_pred_box (bool): Whether to crop with the predicted box or the gt box. + 'lincomb': 1, +}) + + + + + +# ----------------------- ACTIVATION FUNCTIONS ----------------------- # + +activation_func = Config({ + 'tanh': torch.tanh, + 'sigmoid': torch.sigmoid, + 'softmax': lambda x: torch.nn.functional.softmax(x, dim=-1), + 'relu': lambda x: torch.nn.functional.relu(x, inplace=True), + 'none': lambda x: x, +}) + + + + + +# ----------------------- FPN DEFAULTS ----------------------- # + +fpn_base = Config({ + # The number of features to have in each FPN layer + 'num_features': 256, + + # The upsampling mode used + 'interpolation_mode': 'bilinear', + + # The number of extra layers to be produced by downsampling starting at P5 + 'num_downsample': 1, + + # Whether to down sample with a 3x3 stride 2 conv layer instead of just a stride 2 selection + 'use_conv_downsample': False, + + # Whether to pad the pred layers with 1 on each side (I forgot to add this at the start) + # This is just here for backwards compatibility + 'pad': True, + + # Whether to add relu to the downsampled layers. + 'relu_downsample_layers': False, + + # Whether to add relu to the regular layers + 'relu_pred_layers': True, +}) + + + + + +# ----------------------- CONFIG DEFAULTS ----------------------- # + +coco_base_config = Config({ + 'dataset': coco2014_dataset, + 'num_classes': 81, # This should include the background class + + 'max_iter': 400000, + + # The maximum number of detections for evaluation + 'max_num_detections': 100, + + # dw' = momentum * dw - lr * (grad + decay * w) + 'lr': 1e-3, + 'momentum': 0.9, + 'decay': 5e-4, + + # For each lr step, what to multiply the lr with + 'gamma': 0.1, + 'lr_steps': (280000, 360000, 400000), + + # Initial learning rate to linearly warmup from (if until > 0) + 'lr_warmup_init': 1e-4, + + # If > 0 then increase the lr linearly from warmup_init to lr each iter for until iters + 'lr_warmup_until': 500, + + # The terms to scale the respective loss by + 'conf_alpha': 1, + 'bbox_alpha': 1.5, + 'mask_alpha': 0.4 / 256 * 140 * 140, # Some funky equation. Don't worry about it. + + # Eval.py sets this if you just want to run YOLACT as a detector + 'eval_mask_branch': True, + + # Top_k examples to consider for NMS + 'nms_top_k': 200, + # Examples with confidence less than this are not considered by NMS + 'nms_conf_thresh': 0.05, + # Boxes with IoU overlap greater than this threshold will be culled during NMS + 'nms_thresh': 0.5, + + # See mask_type for details. + 'mask_type': mask_type.direct, + 'mask_size': 16, + 'masks_to_train': 100, + 'mask_proto_src': None, + 'mask_proto_net': [(256, 3, {}), (256, 3, {})], + 'mask_proto_bias': False, + 'mask_proto_prototype_activation': activation_func.relu, + 'mask_proto_mask_activation': activation_func.sigmoid, + 'mask_proto_coeff_activation': activation_func.tanh, + 'mask_proto_crop': True, + 'mask_proto_crop_expand': 0, + 'mask_proto_loss': None, + 'mask_proto_binarize_downsampled_gt': True, + 'mask_proto_normalize_mask_loss_by_sqrt_area': False, + 'mask_proto_reweight_mask_loss': False, + 'mask_proto_grid_file': 'data/grid.npy', + 'mask_proto_use_grid': False, + 'mask_proto_coeff_gate': False, + 'mask_proto_prototypes_as_features': False, + 'mask_proto_prototypes_as_features_no_grad': False, + 'mask_proto_remove_empty_masks': False, + 'mask_proto_reweight_coeff': 1, + 'mask_proto_coeff_diversity_loss': False, + 'mask_proto_coeff_diversity_alpha': 1, + 'mask_proto_normalize_emulate_roi_pooling': False, + 'mask_proto_double_loss': False, + 'mask_proto_double_loss_alpha': 1, + 'mask_proto_split_prototypes_by_head': False, + 'mask_proto_crop_with_pred_box': False, + + # SSD data augmentation parameters + # Randomize hue, vibrance, etc. + 'augment_photometric_distort': True, + # Have a chance to scale down the image and pad (to emulate smaller detections) + 'augment_expand': True, + # Potentialy sample a random crop from the image and put it in a random place + 'augment_random_sample_crop': True, + # Mirror the image with a probability of 1/2 + 'augment_random_mirror': True, + # Flip the image vertically with a probability of 1/2 + 'augment_random_flip': False, + # With uniform probability, rotate the image [0,90,180,270] degrees + 'augment_random_rot90': False, + + # Discard detections with width and height smaller than this (in absolute width and height) + 'discard_box_width': 4 / 550, + 'discard_box_height': 4 / 550, + + # If using batchnorm anywhere in the backbone, freeze the batchnorm layer during training. + # Note: any additional batch norm layers after the backbone will not be frozen. + 'freeze_bn': False, + + # Set this to a config object if you want an FPN (inherit from fpn_base). See fpn_base for details. + 'fpn': None, + + # Use the same weights for each network head + 'share_prediction_module': False, + + # For hard negative mining, instead of using the negatives that are leastl confidently background, + # use negatives that are most confidently not background. + 'ohem_use_most_confident': False, + + # Use focal loss as described in https://arxiv.org/pdf/1708.02002.pdf instead of OHEM + 'use_focal_loss': False, + 'focal_loss_alpha': 0.25, + 'focal_loss_gamma': 2, + + # The initial bias toward forground objects, as specified in the focal loss paper + 'focal_loss_init_pi': 0.01, + + # Keeps track of the average number of examples for each class, and weights the loss for that class accordingly. + 'use_class_balanced_conf': False, + + # Whether to use sigmoid focal loss instead of softmax, all else being the same. + 'use_sigmoid_focal_loss': False, + + # Use class[0] to be the objectness score and class[1:] to be the softmax predicted class. + # Note: at the moment this is only implemented if use_focal_loss is on. + 'use_objectness_score': False, + + # Adds a global pool + fc layer to the smallest selected layer that predicts the existence of each of the 80 classes. + # This branch is only evaluated during training time and is just there for multitask learning. + 'use_class_existence_loss': False, + 'class_existence_alpha': 1, + + # Adds a 1x1 convolution directly to the biggest selected layer that predicts a semantic segmentations for each of the 80 classes. + # This branch is only evaluated during training time and is just there for multitask learning. + 'use_semantic_segmentation_loss': False, + 'semantic_segmentation_alpha': 1, + + # Adds another branch to the netwok to predict Mask IoU. + 'use_mask_scoring': False, + 'mask_scoring_alpha': 1, + + # Match gt boxes using the Box2Pix change metric instead of the standard IoU metric. + # Note that the threshold you set for iou_threshold should be negative with this setting on. + 'use_change_matching': False, + + # Uses the same network format as mask_proto_net, except this time it's for adding extra head layers before the final + # prediction in prediction modules. If this is none, no extra layers will be added. + 'extra_head_net': None, + + # What params should the final head layers have (the ones that predict box, confidence, and mask coeffs) + 'head_layer_params': {'kernel_size': 3, 'padding': 1}, + + # Add extra layers between the backbone and the network heads + # The order is (bbox, conf, mask) + 'extra_layers': (0, 0, 0), + + # During training, to match detections with gt, first compute the maximum gt IoU for each prior. + # Then, any of those priors whose maximum overlap is over the positive threshold, mark as positive. + # For any priors whose maximum is less than the negative iou threshold, mark them as negative. + # The rest are neutral and not used in calculating the loss. + 'positive_iou_threshold': 0.5, + 'negative_iou_threshold': 0.5, + + # When using ohem, the ratio between positives and negatives (3 means 3 negatives to 1 positive) + 'ohem_negpos_ratio': 3, + + # If less than 1, anchors treated as a negative that have a crowd iou over this threshold with + # the crowd boxes will be treated as a neutral. + 'crowd_iou_threshold': 1, + + # This is filled in at runtime by Yolact's __init__, so don't touch it + 'mask_dim': None, + + # Input image size. + 'max_size': 300, + + # Whether or not to do post processing on the cpu at test time + 'force_cpu_nms': True, + + # Whether to use mask coefficient cosine similarity nms instead of bbox iou nms + 'use_coeff_nms': False, + + # Whether or not to have a separate branch whose sole purpose is to act as the coefficients for coeff_diversity_loss + # Remember to turn on coeff_diversity_loss, or these extra coefficients won't do anything! + # To see their effect, also remember to turn on use_coeff_nms. + 'use_instance_coeff': False, + 'num_instance_coeffs': 64, + + # Whether or not to tie the mask loss / box loss to 0 + 'train_masks': True, + 'train_boxes': True, + # If enabled, the gt masks will be cropped using the gt bboxes instead of the predicted ones. + # This speeds up training time considerably but results in much worse mAP at test time. + 'use_gt_bboxes': False, + + # Whether or not to preserve aspect ratio when resizing the image. + # If True, this will resize all images to be max_size^2 pixels in area while keeping aspect ratio. + # If False, all images are resized to max_size x max_size + 'preserve_aspect_ratio': False, + + # Whether or not to use the prediction module (c) from DSSD + 'use_prediction_module': False, + + # Whether or not to use the predicted coordinate scheme from Yolo v2 + 'use_yolo_regressors': False, + + # For training, bboxes are considered "positive" if their anchors have a 0.5 IoU overlap + # or greater with a ground truth box. If this is true, instead of using the anchor boxes + # for this IoU computation, the matching function will use the predicted bbox coordinates. + # Don't turn this on if you're not using yolo regressors! + 'use_prediction_matching': False, + + # A list of settings to apply after the specified iteration. Each element of the list should look like + # (iteration, config_dict) where config_dict is a dictionary you'd pass into a config object's init. + 'delayed_settings': [], + + # Use command-line arguments to set this. + 'no_jit': False, + + 'backbone': None, + 'name': 'base_config', + + # Fast Mask Re-scoring Network + # Inspried by Mask Scoring R-CNN (https://arxiv.org/abs/1903.00241) + # Do not crop out the mask with bbox but slide a convnet on the image-size mask, + # then use global pooling to get the final mask score + 'use_maskiou': False, + + # Archecture for the mask iou network. A (num_classes-1, 1, {}) layer is appended to the end. + 'maskiou_net': [], + + # Discard predicted masks whose area is less than this + 'discard_mask_area': -1, + + 'maskiou_alpha': 1.0, + 'rescore_mask': False, + 'rescore_bbox': False, + 'maskious_to_train': -1, +}) + + + + + +# ----------------------- YOLACT v1.0 CONFIGS ----------------------- # + +yolact_base_config = coco_base_config.copy({ + 'name': 'yolact_base', + + # Dataset stuff + 'dataset': coco2017_dataset, + 'num_classes': len(coco2017_dataset.class_names) + 1, + + # Image Size + 'max_size': 550, + + # Training params + 'lr_steps': (280000, 600000, 700000, 750000), + 'max_iter': 1200000, + + # Backbone Settings + 'backbone': resnet101_backbone.copy({ + 'selected_layers': list(range(1, 4)), + 'use_pixel_scales': True, + 'preapply_sqrt': False, + 'use_square_anchors': True, # This is for backward compatability with a bug + + 'pred_aspect_ratios': [ [[1, 1/2, 2]] ]*5, + 'pred_scales': [[24], [48], [96], [192], [384]], + }), + + # FPN Settings + 'fpn': fpn_base.copy({ + 'use_conv_downsample': True, + 'num_downsample': 2, + }), + + # Mask Settings + 'mask_type': mask_type.lincomb, + 'mask_alpha': 6.125, + 'mask_proto_src': 0, + 'mask_proto_net': [(256, 3, {'padding': 1})] * 3 + [(None, -2, {}), (256, 3, {'padding': 1})] + [(32, 1, {})], + 'mask_proto_normalize_emulate_roi_pooling': True, + + # Other stuff + 'share_prediction_module': True, + 'extra_head_net': [(256, 3, {'padding': 1})], + + 'positive_iou_threshold': 0.5, + 'negative_iou_threshold': 0.4, + + 'crowd_iou_threshold': 0.7, + + 'use_semantic_segmentation_loss': True, +}) + +yolact_im400_config = yolact_base_config.copy({ + 'name': 'yolact_im400', + + 'max_size': 400, + 'backbone': yolact_base_config.backbone.copy({ + 'pred_scales': [[int(x[0] / yolact_base_config.max_size * 400)] for x in yolact_base_config.backbone.pred_scales], + }), +}) + +yolact_im700_config = yolact_base_config.copy({ + 'name': 'yolact_im700', + + 'masks_to_train': 300, + 'max_size': 700, + 'backbone': yolact_base_config.backbone.copy({ + 'pred_scales': [[int(x[0] / yolact_base_config.max_size * 700)] for x in yolact_base_config.backbone.pred_scales], + }), +}) + +yolact_darknet53_config = yolact_base_config.copy({ + 'name': 'yolact_darknet53', + + 'backbone': darknet53_backbone.copy({ + 'selected_layers': list(range(2, 5)), + + 'pred_scales': yolact_base_config.backbone.pred_scales, + 'pred_aspect_ratios': yolact_base_config.backbone.pred_aspect_ratios, + 'use_pixel_scales': True, + 'preapply_sqrt': False, + 'use_square_anchors': True, # This is for backward compatability with a bug + }), +}) + +yolact_resnet50_config = yolact_base_config.copy({ + 'name': 'yolact_resnet50', + + 'backbone': resnet50_backbone.copy({ + 'selected_layers': list(range(1, 4)), + + 'pred_scales': yolact_base_config.backbone.pred_scales, + 'pred_aspect_ratios': yolact_base_config.backbone.pred_aspect_ratios, + 'use_pixel_scales': True, + 'preapply_sqrt': False, + 'use_square_anchors': True, # This is for backward compatability with a bug + }), +}) + + +yolact_resnet50_pascal_config = yolact_resnet50_config.copy({ + 'name': None, # Will default to yolact_resnet50_pascal + + # Dataset stuff + 'dataset': pascal_sbd_dataset, + 'num_classes': len(pascal_sbd_dataset.class_names) + 1, + + 'max_iter': 120000, + 'lr_steps': (60000, 100000), + + 'backbone': yolact_resnet50_config.backbone.copy({ + 'pred_scales': [[32], [64], [128], [256], [512]], + 'use_square_anchors': False, + }) +}) + +# ----------------------- YOLACT++ CONFIGS ----------------------- # + +yolact_plus_base_config = yolact_base_config.copy({ + 'name': 'yolact_plus_base', + + 'backbone': resnet101_dcn_inter3_backbone.copy({ + 'selected_layers': list(range(1, 4)), + + 'pred_aspect_ratios': [ [[1, 1/2, 2]] ]*5, + 'pred_scales': [[i * 2 ** (j / 3.0) for j in range(3)] for i in [24, 48, 96, 192, 384]], + 'use_pixel_scales': True, + 'preapply_sqrt': False, + 'use_square_anchors': False, + }), + + 'use_maskiou': False, + 'maskiou_net': [(8, 3, {'stride': 2}), (16, 3, {'stride': 2}), (32, 3, {'stride': 2}), (64, 3, {'stride': 2}), (128, 3, {'stride': 2})], + 'maskiou_alpha': 25, + 'rescore_bbox': False, + 'rescore_mask': True, + + 'discard_mask_area': 5*5, +}) + +yolact_plus_resnet50_config = yolact_plus_base_config.copy({ + 'name': 'yolact_plus_resnet50', + + 'backbone': resnet50_dcnv2_backbone.copy({ + 'selected_layers': list(range(1, 4)), + + 'pred_aspect_ratios': [ [[1, 1/2, 2]] ]*5, + 'pred_scales': [[i * 2 ** (j / 3.0) for j in range(3)] for i in [24, 48, 96, 192, 384]], + 'use_pixel_scales': True, + 'preapply_sqrt': False, + 'use_square_anchors': False, + }), +}) +yolact_plus_resnet50_inf_config = yolact_plus_resnet50_config.copy({ + 'use_maskiou': True +}) + +# Default config +cfg = yolact_base_config.copy() + +def set_cfg(config_name:str): + """ Sets the active config. Works even if cfg is already imported! """ + global cfg + + # Note this is not just an eval because I'm lazy, but also because it can + # be used like ssd300_config.copy({'max_size': 400}) for extreme fine-tuning + cfg.replace(eval(config_name)) + + if cfg.name is None: + cfg.name = config_name.split('_config')[0] + +def set_dataset(dataset_name:str): + """ Sets the dataset of the current config. """ + cfg.dataset = eval(dataset_name) + diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/data/scripts/COCO.sh b/PyTorch/contrib/cv/detection/YOLACT_plus/data/scripts/COCO.sh index da03b184e476f515c5a2c75954e25de98181f997..799cb135fbdf5c0546601af8556837d8e2faea60 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/data/scripts/COCO.sh +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/data/scripts/COCO.sh @@ -1,70 +1,70 @@ -#!/bin/bash - -start=`date +%s` - -# handle optional download dir -if [ -z "$1" ] - then - # navigate to ./data - echo "navigating to ./data/ ..." - mkdir -p ./data - cd ./data/ - mkdir -p ./coco - cd ./coco - mkdir -p ./images - mkdir -p ./annotations - else - # check if specified dir is valid - if [ ! -d $1 ]; then - echo $1 " is not a valid directory" - exit 0 - fi - echo "navigating to " $1 " ..." - cd $1 -fi - -if [ ! -d images ] - then - mkdir -p ./images -fi - -# Download the image data. -cd ./images -echo "Downloading MSCOCO train images ..." -curl -LO http://images.cocodataset.org/zips/train2017.zip -echo "Downloading MSCOCO val images ..." -curl -LO http://images.cocodataset.org/zips/val2017.zip - -cd ../ -if [ ! -d annotations ] - then - mkdir -p ./annotations -fi - -# Download the annotation data. -cd ./annotations -echo "Downloading MSCOCO train/val annotations ..." -curl -LO http://images.cocodataset.org/annotations/annotations_trainval2014.zip -curl -LO http://images.cocodataset.org/annotations/annotations_trainval2017.zip -echo "Finished downloading. Now extracting ..." - -# Unzip data -echo "Extracting train images ..." -unzip -qqjd ../images ../images/train2017.zip -echo "Extracting val images ..." -unzip -qqjd ../images ../images/val2017.zip -echo "Extracting annotations ..." -unzip -qqd .. ./annotations_trainval2014.zip -unzip -qqd .. ./annotations_trainval2017.zip - -echo "Removing zip files ..." -rm ../images/train2017.zip -rm ../images/val2017.zip -rm ./annotations_trainval2014.zip -rm ./annotations_trainval2017.zip - - -end=`date +%s` -runtime=$((end-start)) - -echo "Completed in " $runtime " seconds" +#!/bin/bash + +start=`date +%s` + +# handle optional download dir +if [ -z "$1" ] + then + # navigate to ./data + echo "navigating to ./data/ ..." + mkdir -p ./data + cd ./data/ + mkdir -p ./coco + cd ./coco + mkdir -p ./images + mkdir -p ./annotations + else + # check if specified dir is valid + if [ ! -d $1 ]; then + echo $1 " is not a valid directory" + exit 0 + fi + echo "navigating to " $1 " ..." + cd $1 +fi + +if [ ! -d images ] + then + mkdir -p ./images +fi + +# Download the image data. +cd ./images +echo "Downloading MSCOCO train images ..." +curl -LO http://images.cocodataset.org/zips/train2017.zip +echo "Downloading MSCOCO val images ..." +curl -LO http://images.cocodataset.org/zips/val2017.zip + +cd ../ +if [ ! -d annotations ] + then + mkdir -p ./annotations +fi + +# Download the annotation data. +cd ./annotations +echo "Downloading MSCOCO train/val annotations ..." +curl -LO http://images.cocodataset.org/annotations/annotations_trainval2014.zip +curl -LO http://images.cocodataset.org/annotations/annotations_trainval2017.zip +echo "Finished downloading. Now extracting ..." + +# Unzip data +echo "Extracting train images ..." +unzip -qqjd ../images ../images/train2017.zip +echo "Extracting val images ..." +unzip -qqjd ../images ../images/val2017.zip +echo "Extracting annotations ..." +unzip -qqd .. ./annotations_trainval2014.zip +unzip -qqd .. ./annotations_trainval2017.zip + +echo "Removing zip files ..." +rm ../images/train2017.zip +rm ../images/val2017.zip +rm ./annotations_trainval2014.zip +rm ./annotations_trainval2017.zip + + +end=`date +%s` +runtime=$((end-start)) + +echo "Completed in " $runtime " seconds" diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/data/scripts/COCO_test.sh b/PyTorch/contrib/cv/detection/YOLACT_plus/data/scripts/COCO_test.sh index 56d337b4d9cf4c90c89b99d429ebda742a9e570d..c876e57edd3010a17e3bddfbb66a0f9fd2c06c06 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/data/scripts/COCO_test.sh +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/data/scripts/COCO_test.sh @@ -1,62 +1,62 @@ -#!/bin/bash - -start=`date +%s` - -# handle optional download dir -if [ -z "$1" ] - then - # navigate to ./data - echo "navigating to ./data/ ..." - mkdir -p ./data - cd ./data/ - mkdir -p ./coco - cd ./coco - mkdir -p ./images - mkdir -p ./annotations - else - # check if specified dir is valid - if [ ! -d $1 ]; then - echo $1 " is not a valid directory" - exit 0 - fi - echo "navigating to " $1 " ..." - cd $1 -fi - -if [ ! -d images ] - then - mkdir -p ./images -fi - -# Download the image data. -cd ./images -echo "Downloading MSCOCO test images ..." -curl -LO http://images.cocodataset.org/zips/test2017.zip - -cd ../ -if [ ! -d annotations ] - then - mkdir -p ./annotations -fi - -# Download the annotation data. -cd ./annotations -echo "Downloading MSCOCO test info ..." -curl -LO http://images.cocodataset.org/annotations/image_info_test2017.zip -echo "Finished downloading. Now extracting ..." - -# Unzip data -echo "Extracting train images ..." -unzip -qqjd ../images ../images/test2017.zip -echo "Extracting info ..." -unzip -qqd .. ./image_info_test2017.zip - -echo "Removing zip files ..." -rm ../images/test2017.zip -rm ./image_info_test2017.zip - - -end=`date +%s` -runtime=$((end-start)) - -echo "Completed in " $runtime " seconds" +#!/bin/bash + +start=`date +%s` + +# handle optional download dir +if [ -z "$1" ] + then + # navigate to ./data + echo "navigating to ./data/ ..." + mkdir -p ./data + cd ./data/ + mkdir -p ./coco + cd ./coco + mkdir -p ./images + mkdir -p ./annotations + else + # check if specified dir is valid + if [ ! -d $1 ]; then + echo $1 " is not a valid directory" + exit 0 + fi + echo "navigating to " $1 " ..." + cd $1 +fi + +if [ ! -d images ] + then + mkdir -p ./images +fi + +# Download the image data. +cd ./images +echo "Downloading MSCOCO test images ..." +curl -LO http://images.cocodataset.org/zips/test2017.zip + +cd ../ +if [ ! -d annotations ] + then + mkdir -p ./annotations +fi + +# Download the annotation data. +cd ./annotations +echo "Downloading MSCOCO test info ..." +curl -LO http://images.cocodataset.org/annotations/image_info_test2017.zip +echo "Finished downloading. Now extracting ..." + +# Unzip data +echo "Extracting train images ..." +unzip -qqjd ../images ../images/test2017.zip +echo "Extracting info ..." +unzip -qqd .. ./image_info_test2017.zip + +echo "Removing zip files ..." +rm ../images/test2017.zip +rm ./image_info_test2017.zip + + +end=`date +%s` +runtime=$((end-start)) + +echo "Completed in " $runtime " seconds" diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/data/scripts/mix_sets.py b/PyTorch/contrib/cv/detection/YOLACT_plus/data/scripts/mix_sets.py index 96e1a875890cdf265d0f4411b73e917093d43c5d..5f70eacb53ccace83f917e483e456fc8731594b0 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/data/scripts/mix_sets.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/data/scripts/mix_sets.py @@ -1,74 +1,74 @@ -import json -import os -import sys -from collections import defaultdict - -usage_text = """ -This script creates a coco annotation file by mixing one or more existing annotation files. - -Usage: python data/scripts/mix_sets.py output_name [set1 range1 [set2 range2 [...]]] - -To use, specify the output annotation name and any number of set + range pairs, where the sets -are in the form instances_.json and ranges are python-evalable ranges. The resulting -json will be spit out as instances_.json in the same folder as the input sets. - -For instance, - python data/scripts/mix_sets.py trainval35k train2014 : val2014 :-5000 - -This will create an instance_trainval35k.json file with all images and corresponding annotations -from train2014 and the first 35000 images from val2014. - -You can also specify only one set: - python data/scripts/mix_sets.py minival5k val2014 -5000: - -This will take the last 5k images from val2014 and put it in instances_minival5k.json. -""" - -annotations_path = 'data/coco/annotations/instances_%s.json' -fields_to_combine = ('images', 'annotations') -fields_to_steal = ('info', 'categories', 'licenses') - -if __name__ == '__main__': - if len(sys.argv) < 4 or len(sys.argv) % 2 != 0: - print(usage_text) - exit() - - out_name = sys.argv[1] - sets = sys.argv[2:] - sets = [(sets[2*i], sets[2*i+1]) for i in range(len(sets)//2)] - - out = {x: [] for x in fields_to_combine} - - for idx, (set_name, range_str) in enumerate(sets): - print('Loading set %s...' % set_name) - with open(annotations_path % set_name, 'r') as f: - set_json = json.load(f) - - # "Steal" some fields that don't need to be combined from the first set - if idx == 0: - for field in fields_to_steal: - out[field] = set_json[field] - - print('Building image index...') - image_idx = {x['id']: x for x in set_json['images']} - - print('Collecting annotations...') - anns_idx = defaultdict(lambda: []) - - for ann in set_json['annotations']: - anns_idx[ann['image_id']].append(ann) - - export_ids = list(image_idx.keys()) - export_ids.sort() - export_ids = eval('export_ids[%s]' % range_str, {}, {'export_ids': export_ids}) - - print('Adding %d images...' % len(export_ids)) - for _id in export_ids: - out['images'].append(image_idx[_id]) - out['annotations'] += anns_idx[_id] - - print('Done.\n') - - print('Saving result...') - with open(annotations_path % (out_name), 'w') as out_file: - json.dump(out, out_file) +import json +import os +import sys +from collections import defaultdict + +usage_text = """ +This script creates a coco annotation file by mixing one or more existing annotation files. + +Usage: python data/scripts/mix_sets.py output_name [set1 range1 [set2 range2 [...]]] + +To use, specify the output annotation name and any number of set + range pairs, where the sets +are in the form instances_.json and ranges are python-evalable ranges. The resulting +json will be spit out as instances_.json in the same folder as the input sets. + +For instance, + python data/scripts/mix_sets.py trainval35k train2014 : val2014 :-5000 + +This will create an instance_trainval35k.json file with all images and corresponding annotations +from train2014 and the first 35000 images from val2014. + +You can also specify only one set: + python data/scripts/mix_sets.py minival5k val2014 -5000: + +This will take the last 5k images from val2014 and put it in instances_minival5k.json. +""" + +annotations_path = 'data/coco/annotations/instances_%s.json' +fields_to_combine = ('images', 'annotations') +fields_to_steal = ('info', 'categories', 'licenses') + +if __name__ == '__main__': + if len(sys.argv) < 4 or len(sys.argv) % 2 != 0: + print(usage_text) + exit() + + out_name = sys.argv[1] + sets = sys.argv[2:] + sets = [(sets[2*i], sets[2*i+1]) for i in range(len(sets)//2)] + + out = {x: [] for x in fields_to_combine} + + for idx, (set_name, range_str) in enumerate(sets): + print('Loading set %s...' % set_name) + with open(annotations_path % set_name, 'r') as f: + set_json = json.load(f) + + # "Steal" some fields that don't need to be combined from the first set + if idx == 0: + for field in fields_to_steal: + out[field] = set_json[field] + + print('Building image index...') + image_idx = {x['id']: x for x in set_json['images']} + + print('Collecting annotations...') + anns_idx = defaultdict(lambda: []) + + for ann in set_json['annotations']: + anns_idx[ann['image_id']].append(ann) + + export_ids = list(image_idx.keys()) + export_ids.sort() + export_ids = eval('export_ids[%s]' % range_str, {}, {'export_ids': export_ids}) + + print('Adding %d images...' % len(export_ids)) + for _id in export_ids: + out['images'].append(image_idx[_id]) + out['annotations'] += anns_idx[_id] + + print('Done.\n') + + print('Saving result...') + with open(annotations_path % (out_name), 'w') as out_file: + json.dump(out, out_file) diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/deform_conv.py b/PyTorch/contrib/cv/detection/YOLACT_plus/deform_conv.py index bcf59fae04c35c6fc615afdf11077bcb50e52f4e..b1ed2c6203317008d838bcbab6e39650d7bb3849 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/deform_conv.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/deform_conv.py @@ -1,235 +1,235 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import torch -import torch.nn as nn -from torch.autograd import Function -from torch.nn.modules.utils import _pair, _single -import math - - -class ModulatedDeformConv2dFunction(Function): - - @staticmethod - def forward(ctx, - input_tensor, - offset_ori, - mask, - weight, - bias=None, - with_bias=False, - stride=1, - padding=0, - dilation=1, - groups=1, - deformable_groups=1, - sort_index_for_npu_fp=None, - sort_index_for_npu_bp=None, - ): - - input_tensor = input_tensor.float() - offset_ori = offset_ori.float() - mask = mask.float() - - ctx.stride = stride - ctx.padding = padding - ctx.dilation = dilation - ctx.groups = groups - ctx.deformable_groups = deformable_groups - ctx.sort_index_for_npu_bp = sort_index_for_npu_bp - ctx.with_bias = with_bias - - offset = offset_ori.index_select(1, sort_index_for_npu_fp) - offset_all = torch.cat([offset, mask], dim=1) - output, offset_out = torch.npu_deformable_conv2d( - input_tensor, weight, offset_all, bias, - kernel_size=[weight.shape[3], weight.shape[2]], - stride=[1, 1, ctx.stride, ctx.stride], - padding=[ctx.padding, ctx.padding, ctx.padding, ctx.padding], - dilation=[1, 1, ctx.dilation, ctx.dilation], - groups=ctx.groups, deformable_groups=ctx.deformable_groups, - modulated=True) - if weight.requires_grad or mask.requires_grad or offset.requires_grad \ - or input_tensor.requires_grad: - ctx.save_for_backward(input_tensor, weight, offset_out, offset_all) - return output - - @staticmethod - def backward(ctx, grad_output): - input_tensor, weight, offset_out, offset_all = ctx.saved_tensors - grad_input, grad_weight, grad_offset_all, grad_bias = torch.npu_deformable_conv2dbk( - input_tensor, grad_output, offset_out, weight, offset_all, - kernel_size=[weight.shape[3], weight.shape[2]], - stride=[1, 1, ctx.stride, ctx.stride], - padding=[ctx.padding, ctx.padding, ctx.padding, ctx.padding], - dilation=[1, 1, ctx.dilation, ctx.dilation], - groups=ctx.groups, deformable_groups=ctx.deformable_groups, modulated=True) - grad_offset = grad_offset_all.index_select(1, ctx.sort_index_for_npu_bp) - grad_mask = grad_offset_all[:, grad_offset.shape[1]:, :, :] - if not ctx.with_bias: - grad_bias = None - - return (grad_input, grad_offset, grad_mask, grad_weight, grad_bias, - None, None, None, None, None, None, None, None) - - -class ModulatedDeformConv(nn.Module): - - def __init__(self, - in_channels, - out_channels, - kernel_size, - stride=1, - padding=0, - dilation=1, - groups=1, - deformable_groups=1, - bias=True, - pack=True, - ): - - r"""Applies an NPU based Modulated Deformable 2D convolution operation. - - Paper link: - [Deformable ConvNets v2: More Deformable, Better Results](https://arxiv.org/abs/1811.11168) - - Reference implementation link: - https://github.com/open-mmlab/mmcv/blob/master/mmcv/ops/modulated_deform_conv.py - - The implementation of this ModulatedDeformConv is mainly based - on the implementation of mmcv for design and reconstruction. - - In ModulatedDeformConvFunction, the forward and backward are customized, - and the input tensor is reconstructed ito match the NPU based function. - - It is worth mentioning that DeformConv(DCNv1) is also implemented - by setting modulated==False. Due to the difference between input - and initialization, there is no additional implementation here. - - .. note:: - ModulatedDeformConv only implements operations under fp32 data types. - Notice, weight and bias in conv_offset must be initialized to 0. - - Args: - in_channels (int): Number of channels in the input image. - out_channels (int): Number of channels produced by the convolution. - kernel_size(int, tuple): Size of the convolving kernel. - stride(int, tuple): Stride of the convolution. Default: 1. - padding (int or tuple): Zero-padding added to both sides of the input. - Default: 0. - dilation (int or tuple): Spacing between kernel elements. Default: 1. - groups (int): Number of blocked connections from input. - channels to output channels. Default: 1. - deform_groups (int): Number of deformable group partitions. - bias (bool): If True, adds a learnable bias to the output. Default: False. - pack (bool): If True, conv_offset and mask will be included in this module. Default: True. - - Examples:: - >>> m = ModulatedDeformConv(32, 32, 1) - >>> input_tensor = torch.randn(2, 32, 5, 5) - >>> output = m(input_tensor) - """ - - super(ModulatedDeformConv, self).__init__() - - self.in_channels = in_channels - self.out_channels = out_channels - self.kernel_size = _pair(kernel_size) - self.stride = stride - self.padding = padding - self.dilation = dilation - self.groups = groups - self.deformable_groups = deformable_groups - self.with_bias = bias - self.pack = pack - - self.weight = nn.Parameter( - torch.Tensor(out_channels, in_channels // groups, *self.kernel_size)) - if bias: - self.bias = nn.Parameter(torch.Tensor(out_channels)) - else: - self.bias = torch.zeros(self.weight.shape[0]) - - if self.pack: - self.conv_offset_mask = nn.Conv2d( - self.in_channels, - self.deformable_groups * 3 * self.kernel_size[0] * - self.kernel_size[1], - kernel_size=self.kernel_size, - stride=_pair(self.stride), - padding=_pair(self.padding), - bias=True) - - self.split_num = self.deformable_groups * 2 * self.kernel_size[0] * self.kernel_size[1] - sort_index_for_npu = list(range(self.split_num)) - sort_index_for_npu_fp = sort_index_for_npu[1::2] + sort_index_for_npu[::2] - sort_index_for_npu_bp_dict = {i: idx for idx, i in enumerate(sort_index_for_npu_fp)} - sort_index_for_npu_bp = [sort_index_for_npu_bp_dict[i] for i in sort_index_for_npu] - self.sort_index_for_npu_fp = torch.IntTensor(sort_index_for_npu_fp) - self.sort_index_for_npu_bp = torch.IntTensor(sort_index_for_npu_bp) - self.sort_index_for_npu_todevice = False - - self.init_param() - - def init_param(self): - n = self.in_channels - for k in self.kernel_size: - n *= k - stdv = 1. / math.sqrt(n) - self.weight.data.uniform_(-stdv, stdv) - if self.bias is not None: - self.bias.data.zero_() - - if self.pack: - self.conv_offset_mask.weight.data.zero_() - self.conv_offset_mask.bias.data.zero_() - - def forward(self, x): - if self.pack: - out = self.conv_offset_mask(x) - offset = out[:, :self.split_num, ...] - mask = torch.sigmoid(out[:, self.split_num:, ...]) - else: - x, offset, mask = x - - if not self.sort_index_for_npu_todevice: - self.sort_index_for_npu_fp = self.sort_index_for_npu_fp.to(x.device) - self.sort_index_for_npu_bp = self.sort_index_for_npu_bp.to(x.device) - self.bias = self.bias.to(x.device) - self.sort_index_for_npu_todevice = True - - return ModulatedDeformConv2dFunction.apply( - x, offset, mask, self.weight, self.bias, self.with_bias, - self.stride, self.padding, self.dilation, - self.groups, self.deformable_groups, - self.sort_index_for_npu_fp, - self.sort_index_for_npu_bp, - ) - - -DCNv2 = ModulatedDeformConv - -if __name__ == "__main__": - x = torch.randn(2, 32, 7, 7) - model = DCNv2(32, 32, 3, 2, 1) - - torch.npu.set_device(0) - x = x.npu() - model = model.npu() - - o = model(x) - l = o.sum() - l.backward() - print(l) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import torch +import torch.nn as nn +from torch.autograd import Function +from torch.nn.modules.utils import _pair, _single +import math + + +class ModulatedDeformConv2dFunction(Function): + + @staticmethod + def forward(ctx, + input_tensor, + offset_ori, + mask, + weight, + bias=None, + with_bias=False, + stride=1, + padding=0, + dilation=1, + groups=1, + deformable_groups=1, + sort_index_for_npu_fp=None, + sort_index_for_npu_bp=None, + ): + + input_tensor = input_tensor.float() + offset_ori = offset_ori.float() + mask = mask.float() + + ctx.stride = stride + ctx.padding = padding + ctx.dilation = dilation + ctx.groups = groups + ctx.deformable_groups = deformable_groups + ctx.sort_index_for_npu_bp = sort_index_for_npu_bp + ctx.with_bias = with_bias + + offset = offset_ori.index_select(1, sort_index_for_npu_fp) + offset_all = torch.cat([offset, mask], dim=1) + output, offset_out = torch.npu_deformable_conv2d( + input_tensor, weight, offset_all, bias, + kernel_size=[weight.shape[3], weight.shape[2]], + stride=[1, 1, ctx.stride, ctx.stride], + padding=[ctx.padding, ctx.padding, ctx.padding, ctx.padding], + dilation=[1, 1, ctx.dilation, ctx.dilation], + groups=ctx.groups, deformable_groups=ctx.deformable_groups, + modulated=True) + if weight.requires_grad or mask.requires_grad or offset.requires_grad \ + or input_tensor.requires_grad: + ctx.save_for_backward(input_tensor, weight, offset_out, offset_all) + return output + + @staticmethod + def backward(ctx, grad_output): + input_tensor, weight, offset_out, offset_all = ctx.saved_tensors + grad_input, grad_weight, grad_offset_all, grad_bias = torch.npu_deformable_conv2dbk( + input_tensor, grad_output, offset_out, weight, offset_all, + kernel_size=[weight.shape[3], weight.shape[2]], + stride=[1, 1, ctx.stride, ctx.stride], + padding=[ctx.padding, ctx.padding, ctx.padding, ctx.padding], + dilation=[1, 1, ctx.dilation, ctx.dilation], + groups=ctx.groups, deformable_groups=ctx.deformable_groups, modulated=True) + grad_offset = grad_offset_all.index_select(1, ctx.sort_index_for_npu_bp) + grad_mask = grad_offset_all[:, grad_offset.shape[1]:, :, :] + if not ctx.with_bias: + grad_bias = None + + return (grad_input, grad_offset, grad_mask, grad_weight, grad_bias, + None, None, None, None, None, None, None, None) + + +class ModulatedDeformConv(nn.Module): + + def __init__(self, + in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + dilation=1, + groups=1, + deformable_groups=1, + bias=True, + pack=True, + ): + + r"""Applies an NPU based Modulated Deformable 2D convolution operation. + + Paper link: + [Deformable ConvNets v2: More Deformable, Better Results](https://arxiv.org/abs/1811.11168) + + Reference implementation link: + https://github.com/open-mmlab/mmcv/blob/master/mmcv/ops/modulated_deform_conv.py + + The implementation of this ModulatedDeformConv is mainly based + on the implementation of mmcv for design and reconstruction. + + In ModulatedDeformConvFunction, the forward and backward are customized, + and the input tensor is reconstructed ito match the NPU based function. + + It is worth mentioning that DeformConv(DCNv1) is also implemented + by setting modulated==False. Due to the difference between input + and initialization, there is no additional implementation here. + + .. note:: + ModulatedDeformConv only implements operations under fp32 data types. + Notice, weight and bias in conv_offset must be initialized to 0. + + Args: + in_channels (int): Number of channels in the input image. + out_channels (int): Number of channels produced by the convolution. + kernel_size(int, tuple): Size of the convolving kernel. + stride(int, tuple): Stride of the convolution. Default: 1. + padding (int or tuple): Zero-padding added to both sides of the input. + Default: 0. + dilation (int or tuple): Spacing between kernel elements. Default: 1. + groups (int): Number of blocked connections from input. + channels to output channels. Default: 1. + deform_groups (int): Number of deformable group partitions. + bias (bool): If True, adds a learnable bias to the output. Default: False. + pack (bool): If True, conv_offset and mask will be included in this module. Default: True. + + Examples:: + >>> m = ModulatedDeformConv(32, 32, 1) + >>> input_tensor = torch.randn(2, 32, 5, 5) + >>> output = m(input_tensor) + """ + + super(ModulatedDeformConv, self).__init__() + + self.in_channels = in_channels + self.out_channels = out_channels + self.kernel_size = _pair(kernel_size) + self.stride = stride + self.padding = padding + self.dilation = dilation + self.groups = groups + self.deformable_groups = deformable_groups + self.with_bias = bias + self.pack = pack + + self.weight = nn.Parameter( + torch.Tensor(out_channels, in_channels // groups, *self.kernel_size)) + if bias: + self.bias = nn.Parameter(torch.Tensor(out_channels)) + else: + self.bias = torch.zeros(self.weight.shape[0]) + + if self.pack: + self.conv_offset_mask = nn.Conv2d( + self.in_channels, + self.deformable_groups * 3 * self.kernel_size[0] * + self.kernel_size[1], + kernel_size=self.kernel_size, + stride=_pair(self.stride), + padding=_pair(self.padding), + bias=True) + + self.split_num = self.deformable_groups * 2 * self.kernel_size[0] * self.kernel_size[1] + sort_index_for_npu = list(range(self.split_num)) + sort_index_for_npu_fp = sort_index_for_npu[1::2] + sort_index_for_npu[::2] + sort_index_for_npu_bp_dict = {i: idx for idx, i in enumerate(sort_index_for_npu_fp)} + sort_index_for_npu_bp = [sort_index_for_npu_bp_dict[i] for i in sort_index_for_npu] + self.sort_index_for_npu_fp = torch.IntTensor(sort_index_for_npu_fp) + self.sort_index_for_npu_bp = torch.IntTensor(sort_index_for_npu_bp) + self.sort_index_for_npu_todevice = False + + self.init_param() + + def init_param(self): + n = self.in_channels + for k in self.kernel_size: + n *= k + stdv = 1. / math.sqrt(n) + self.weight.data.uniform_(-stdv, stdv) + if self.bias is not None: + self.bias.data.zero_() + + if self.pack: + self.conv_offset_mask.weight.data.zero_() + self.conv_offset_mask.bias.data.zero_() + + def forward(self, x): + if self.pack: + out = self.conv_offset_mask(x) + offset = out[:, :self.split_num, ...] + mask = torch.sigmoid(out[:, self.split_num:, ...]) + else: + x, offset, mask = x + + if not self.sort_index_for_npu_todevice: + self.sort_index_for_npu_fp = self.sort_index_for_npu_fp.to(x.device) + self.sort_index_for_npu_bp = self.sort_index_for_npu_bp.to(x.device) + self.bias = self.bias.to(x.device) + self.sort_index_for_npu_todevice = True + + return ModulatedDeformConv2dFunction.apply( + x, offset, mask, self.weight, self.bias, self.with_bias, + self.stride, self.padding, self.dilation, + self.groups, self.deformable_groups, + self.sort_index_for_npu_fp, + self.sort_index_for_npu_bp, + ) + + +DCNv2 = ModulatedDeformConv + +if __name__ == "__main__": + x = torch.randn(2, 32, 7, 7) + model = DCNv2(32, 32, 3, 2, 1) + + torch.npu.set_device(0) + x = x.npu() + model = model.npu() + + o = model(x) + l = o.sum() + l.backward() + print(l) diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/eval.py b/PyTorch/contrib/cv/detection/YOLACT_plus/eval.py index 72264fd183a8743cae7b6c773509fa5fc4222be1..b57372aacaf16eb51559224fec25b00f8b7cf061 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/eval.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/eval.py @@ -1,1158 +1,1158 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -from data import COCODetection, get_label_map, MEANS, COLORS -from yolact import Yolact -from utils.augmentations import BaseTransform, FastBaseTransform, Resize -from utils.functions import MovingAverage, ProgressBar -from layers.box_utils import jaccard, center_size, mask_iou -from utils import timer -from utils.functions import SavePath -from layers.output_utils import postprocess, undo_image_transformation -import pycocotools - -from data import cfg, set_cfg, set_dataset -from tqdm import tqdm -import numpy as np -import torch -import torch.backends.cudnn as cudnn -from torch.autograd import Variable -import argparse -import time -import random -import cProfile -import pickle -import json -import os -from collections import defaultdict -from pathlib import Path -from collections import OrderedDict -from PIL import Image - -import matplotlib.pyplot as plt -import cv2 - -def str2bool(v): - if v.lower() in ('yes', 'true', 't', 'y', '1'): - return True - elif v.lower() in ('no', 'false', 'f', 'n', '0'): - return False - else: - raise argparse.ArgumentTypeError('Boolean value expected.') - -def parse_args(argv=None): - parser = argparse.ArgumentParser( - description='YOLACT COCO Evaluation') - parser.add_argument('--trained_model', - default='weights/ssd300_mAP_77.43_v2.pth', type=str, - help='Trained state_dict file path to open. If "interrupt", this will open the interrupt file.') - parser.add_argument('--data_path', default=None, type=str, - help='data path') - parser.add_argument('--top_k', default=5, type=int, - help='Further restrict the number of predictions to parse') - parser.add_argument('--cuda', default=True, type=str2bool, - help='Use cuda to evaulate model') - parser.add_argument('--fast_nms', default=True, type=str2bool, - help='Whether to use a faster, but not entirely correct version of NMS.') - parser.add_argument('--cross_class_nms', default=False, type=str2bool, - help='Whether compute NMS cross-class or per-class.') - parser.add_argument('--display_masks', default=True, type=str2bool, - help='Whether or not to display masks over bounding boxes') - parser.add_argument('--display_bboxes', default=True, type=str2bool, - help='Whether or not to display bboxes around masks') - parser.add_argument('--display_text', default=True, type=str2bool, - help='Whether or not to display text (class [score])') - parser.add_argument('--display_scores', default=True, type=str2bool, - help='Whether or not to display scores in addition to classes') - parser.add_argument('--display', dest='display', action='store_true', - help='Display qualitative results instead of quantitative ones.') - parser.add_argument('--shuffle', dest='shuffle', action='store_true', - help='Shuffles the images when displaying them. Doesn\'t have much of an effect when display is off though.') - parser.add_argument('--ap_data_file', default='results/ap_data.pkl', type=str, - help='In quantitative mode, the file to save detections before calculating mAP.') - parser.add_argument('--resume', dest='resume', action='store_true', - help='If display not set, this resumes mAP calculations from the ap_data_file.') - parser.add_argument('--max_images', default=-1, type=int, - help='The maximum number of images from the dataset to consider. Use -1 for all.') - parser.add_argument('--output_coco_json', dest='output_coco_json', action='store_true', - help='If display is not set, instead of processing IoU values, this just dumps detections into the coco json file.') - parser.add_argument('--bbox_det_file', default='results/bbox_detections.json', type=str, - help='The output file for coco bbox results if --coco_results is set.') - parser.add_argument('--mask_det_file', default='results/mask_detections.json', type=str, - help='The output file for coco mask results if --coco_results is set.') - parser.add_argument('--config', default='yolact_plus_resnet50_config', - help='The config object to use.') - parser.add_argument('--output_web_json', dest='output_web_json', action='store_true', - help='If display is not set, instead of processing IoU values, this dumps detections for usage with the detections viewer web thingy.') - parser.add_argument('--web_det_path', default='web/dets/', type=str, - help='If output_web_json is set, this is the path to dump detections into.') - parser.add_argument('--no_bar', dest='no_bar', action='store_true', - help='Do not output the status bar. This is useful for when piping to a file.') - parser.add_argument('--display_lincomb', default=False, type=str2bool, - help='If the config uses lincomb masks, output a visualization of how those masks are created.') - parser.add_argument('--benchmark', default=False, dest='benchmark', action='store_true', - help='Equivalent to running display mode but without displaying an image.') - parser.add_argument('--no_sort', default=False, dest='no_sort', action='store_true', - help='Do not sort images by hashed image ID.') - parser.add_argument('--seed', default=None, type=int, - help='The seed to pass into random.seed. Note: this is only really for the shuffle and does not (I think) affect cuda stuff.') - parser.add_argument('--mask_proto_debug', default=False, dest='mask_proto_debug', action='store_true', - help='Outputs stuff for scripts/compute_mask.py.') - parser.add_argument('--no_crop', default=False, dest='crop', action='store_false', - help='Do not crop output masks with the predicted bounding box.') - parser.add_argument('--image', default=None, type=str, - help='A path to an image to use for display.') - parser.add_argument('--images', default=None, type=str, - help='An input folder of images and output folder to save detected images. Should be in the format input->output.') - parser.add_argument('--video', default=None, type=str, - help='A path to a video to evaluate on. Passing in a number will use that index webcam.') - parser.add_argument('--video_multiframe', default=1, type=int, - help='The number of frames to evaluate in parallel to make videos play at higher fps.') - parser.add_argument('--score_threshold', default=0, type=float, - help='Detections with a score under this threshold will not be considered. This currently only works in display mode.') - parser.add_argument('--dataset', default=None, type=str, - help='If specified, override the dataset specified in the config with this one (example: coco2017_dataset).') - parser.add_argument('--detect', default=False, dest='detect', action='store_true', - help='Don\'t evauluate the mask branch at all and only do object detection. This only works for --display and --benchmark.') - parser.add_argument('--display_fps', default=False, dest='display_fps', action='store_true', - help='When displaying / saving video, draw the FPS on the frame') - parser.add_argument('--emulate_playback', default=False, dest='emulate_playback', action='store_true', - help='When saving a video, emulate the framerate that you\'d get running in real-time mode.') - parser.add_argument('--rank_id', default=0, type=int) - parser.set_defaults(no_bar=False, display=False, resume=False, output_coco_json=False, output_web_json=False, shuffle=False, - benchmark=False, no_sort=False, no_hash=False, mask_proto_debug=False, crop=True, detect=False, display_fps=False, - emulate_playback=False) - - global args - args = parser.parse_args(argv) - - if args.output_web_json: - args.output_coco_json = True - - if args.seed is not None: - random.seed(args.seed) - -iou_thresholds = [x / 100 for x in range(50, 100, 5)] -coco_cats = {} # Call prep_coco_cats to fill this -coco_cats_inv = {} -color_cache = defaultdict(lambda: {}) - -def prep_display(dets_out, img, h, w, undo_transform=True, class_color=False, mask_alpha=0.45, fps_str=''): - """ - Note: If undo_transform=False then im_h and im_w are allowed to be None. - """ - if undo_transform: - img_numpy = undo_image_transformation(img, w, h) - if args.cuda: - img_gpu = torch.Tensor(img_numpy).npu() - else: - img_gpu = torch.Tensor(img_numpy) - print('img_shape:', img_gpu) - else: - img_gpu = img / 255.0 - h, w, _ = img.shape - print('h, w, _ :', img.shape) - - with timer.env('Postprocess'): - save = cfg.rescore_bbox - cfg.rescore_bbox = True - t = postprocess(dets_out, w, h, visualize_lincomb = args.display_lincomb, - crop_masks = args.crop, - score_threshold = args.score_threshold) - cfg.rescore_bbox = save - - with timer.env('Copy'): - idx = t[1].argsort(0, descending=True)[:args.top_k] - - if cfg.eval_mask_branch: - # Masks are drawn on the GPU, so don't copy - masks = t[3][idx] - classes, scores, boxes = [x[idx].cpu().numpy() for x in t[:3]] - - num_dets_to_consider = min(args.top_k, classes.shape[0]) - for j in range(num_dets_to_consider): - if scores[j] < args.score_threshold: - num_dets_to_consider = j - break - - # Quick and dirty lambda for selecting the color for a particular index - # Also keeps track of a per-gpu color cache for maximum speed - def get_color(j, on_gpu=None): - global color_cache - color_idx = (classes[j] * 5 if class_color else j * 5) % len(COLORS) - - if on_gpu is not None and color_idx in color_cache[on_gpu]: - return color_cache[on_gpu][color_idx] - else: - color = COLORS[color_idx] - if not undo_transform: - # The image might come in as RGB or BRG, depending - color = (color[2], color[1], color[0]) - if on_gpu is not None: - color = torch.Tensor(color).to(on_gpu).float() / 255. - color_cache[on_gpu][color_idx] = color - return color - - # First, draw the masks on the GPU where we can do it really fast - # Beware: very fast but possibly unintelligible mask-drawing code ahead - # I wish I had access to OpenGL or Vulkan but alas, I guess Pytorch tensor operations will have to suffice - if args.display_masks and cfg.eval_mask_branch and num_dets_to_consider > 0: - # After this, mask is of size [num_dets, h, w, 1] - masks = masks[:num_dets_to_consider, :, :, None] - - # Prepare the RGB images for each mask given their color (size [num_dets, h, w, 1]) - colors = torch.cat([get_color(j, on_gpu=img_gpu.device.index).view(1, 1, 1, 3) for j in range(num_dets_to_consider)], dim=0) - masks_color = masks.repeat(1, 1, 1, 3) * colors * mask_alpha - - # This is 1 everywhere except for 1-mask_alpha where the mask is - inv_alph_masks = masks * (-mask_alpha) + 1 - - # I did the math for this on pen and paper. This whole block should be equivalent to: - # for j in range(num_dets_to_consider): - # img_gpu = img_gpu * inv_alph_masks[j] + masks_color[j] - masks_color_summand = masks_color[0] - if num_dets_to_consider > 1: - inv_alph_cumul = inv_alph_masks[:(num_dets_to_consider-1)].cumprod(dim=0) - masks_color_cumul = masks_color[1:] * inv_alph_cumul - masks_color_summand += masks_color_cumul.sum(dim=0) - - img_gpu = img_gpu * inv_alph_masks.prod(dim=0) + masks_color_summand - - if args.display_fps: - # Draw the box for the fps on the GPU - font_face = cv2.FONT_HERSHEY_DUPLEX - font_scale = 0.6 - font_thickness = 1 - - text_w, text_h = cv2.getTextSize(fps_str, font_face, font_scale, font_thickness)[0] - - img_gpu[0:text_h+8, 0:text_w+8] *= 0.6 # 1 - Box alpha - - - # Then draw the stuff that needs to be done on the cpu - # Note, make sure this is a uint8 tensor or opencv will not anti alias text for whatever reason - img_numpy = (img_gpu * 255).byte().cpu().numpy() - - if args.display_fps: - # Draw the text on the CPU - text_pt = (4, text_h + 2) - text_color = [255, 255, 255] - - cv2.putText(img_numpy, fps_str, text_pt, font_face, font_scale, text_color, font_thickness, cv2.LINE_AA) - - if num_dets_to_consider == 0: - return img_numpy - - if args.display_text or args.display_bboxes: - for j in reversed(range(num_dets_to_consider)): - x1, y1, x2, y2 = boxes[j, :] - color = get_color(j) - score = scores[j] - - if args.display_bboxes: - cv2.rectangle(img_numpy, (x1, y1), (x2, y2), color, 1) - - if args.display_text: - _class = cfg.dataset.class_names[classes[j]] - text_str = '%s: %.2f' % (_class, score) if args.display_scores else _class - - font_face = cv2.FONT_HERSHEY_DUPLEX - font_scale = 0.6 - font_thickness = 1 - - text_w, text_h = cv2.getTextSize(text_str, font_face, font_scale, font_thickness)[0] - - text_pt = (x1, y1 - 3) - text_color = [255, 255, 255] - - cv2.rectangle(img_numpy, (x1, y1), (x1 + text_w, y1 - text_h - 4), color, -1) - cv2.putText(img_numpy, text_str, text_pt, font_face, font_scale, text_color, font_thickness, cv2.LINE_AA) - - - return img_numpy - -def prep_benchmark(dets_out, h, w): - with timer.env('Postprocess'): - t = postprocess(dets_out, w, h, crop_masks=args.crop, score_threshold=args.score_threshold) - - with timer.env('Copy'): - classes, scores, boxes, masks = [x[:args.top_k] for x in t] - if isinstance(scores, list): - box_scores = scores[0].cpu().numpy() - mask_scores = scores[1].cpu().numpy() - else: - scores = scores.cpu().numpy() - classes = classes.cpu().numpy() - boxes = boxes.cpu().numpy() - masks = masks.cpu().numpy() - - with timer.env('Sync'): - # Just in case - torch.npu.synchronize() - -def prep_coco_cats(): - """ Prepare inverted table for category id lookup given a coco cats object. """ - for coco_cat_id, transformed_cat_id_p1 in get_label_map().items(): - transformed_cat_id = transformed_cat_id_p1 - 1 - coco_cats[transformed_cat_id] = coco_cat_id - coco_cats_inv[coco_cat_id] = transformed_cat_id - - -def get_coco_cat(transformed_cat_id): - """ transformed_cat_id is [0,80) as indices in cfg.dataset.class_names """ - return coco_cats[transformed_cat_id] - -def get_transformed_cat(coco_cat_id): - """ transformed_cat_id is [0,80) as indices in cfg.dataset.class_names """ - return coco_cats_inv[coco_cat_id] - - -class Detections: - - def __init__(self): - self.bbox_data = [] - self.mask_data = [] - - def add_bbox(self, image_id:int, category_id:int, bbox:list, score:float): - """ Note that bbox should be a list or tuple of (x1, y1, x2, y2) """ - bbox = [bbox[0], bbox[1], bbox[2]-bbox[0], bbox[3]-bbox[1]] - - # Round to the nearest 10th to avoid huge file sizes, as COCO suggests - bbox = [round(float(x)*10)/10 for x in bbox] - - self.bbox_data.append({ - 'image_id': int(image_id), - 'category_id': get_coco_cat(int(category_id)), - 'bbox': bbox, - 'score': float(score) - }) - - def add_mask(self, image_id:int, category_id:int, segmentation:np.ndarray, score:float): - """ The segmentation should be the full mask, the size of the image and with size [h, w]. """ - rle = pycocotools.mask.encode(np.asfortranarray(segmentation.astype(np.uint8))) - rle['counts'] = rle['counts'].decode('ascii') # json.dump doesn't like bytes strings - - self.mask_data.append({ - 'image_id': int(image_id), - 'category_id': get_coco_cat(int(category_id)), - 'segmentation': rle, - 'score': float(score) - }) - - def dump(self): - dump_arguments = [ - (self.bbox_data, args.bbox_det_file), - (self.mask_data, args.mask_det_file) - ] - - for data, path in dump_arguments: - with open(path, 'w') as f: - json.dump(data, f) - - def dump_web(self): - """ Dumps it in the format for my web app. Warning: bad code ahead! """ - config_outs = ['preserve_aspect_ratio', 'use_prediction_module', - 'use_yolo_regressors', 'use_prediction_matching', - 'train_masks'] - - output = { - 'info' : { - 'Config': {key: getattr(cfg, key) for key in config_outs}, - } - } - - image_ids = list(set([x['image_id'] for x in self.bbox_data])) - image_ids.sort() - image_lookup = {_id: idx for idx, _id in enumerate(image_ids)} - - output['images'] = [{'image_id': image_id, 'dets': []} for image_id in image_ids] - - # These should already be sorted by score with the way prep_metrics works. - for bbox, mask in zip(self.bbox_data, self.mask_data): - image_obj = output['images'][image_lookup[bbox['image_id']]] - image_obj['dets'].append({ - 'score': bbox['score'], - 'bbox': bbox['bbox'], - 'category': cfg.dataset.class_names[get_transformed_cat(bbox['category_id'])], - 'mask': mask['segmentation'], - }) - - with open(os.path.join(args.web_det_path, '%s.json' % cfg.name), 'w') as f: - json.dump(output, f) - - - - -def _mask_iou(mask1, mask2, iscrowd=False): - with timer.env('Mask IoU'): - ret = mask_iou(mask1, mask2, iscrowd) - return ret.cpu() - -def _bbox_iou(bbox1, bbox2, iscrowd=False): - with timer.env('BBox IoU'): - ret = jaccard(bbox1, bbox2, iscrowd) - return ret.cpu() - -def prep_metrics(ap_data, dets, img, gt, gt_masks, h, w, num_crowd, image_id, detections:Detections=None): - """ Returns a list of APs for this image, with each element being for a class """ - if not args.output_coco_json: - with timer.env('Prepare gt'): - gt_boxes = torch.Tensor(gt[:, :4]) if args.cuda else torch.Tensor(gt[:, :4]) - gt_boxes[:, [0, 2]] *= w - gt_boxes[:, [1, 3]] *= h - gt_classes = list(gt[:, 4].astype(int)) - gt_masks = torch.Tensor(gt_masks).view(-1, h*w) if args.cuda else torch.Tensor(gt_masks).view(-1, h*w) - - if num_crowd > 0: - split = lambda x: (x[-num_crowd:], x[:-num_crowd]) - crowd_boxes , gt_boxes = split(gt_boxes) - crowd_masks , gt_masks = split(gt_masks) - crowd_classes, gt_classes = split(gt_classes) - - with timer.env('Postprocess'): - classes, scores, boxes, masks = postprocess(dets, w, h, crop_masks=args.crop, score_threshold=args.score_threshold) - - if classes.size(0) == 0: - return - - classes = list(classes.cpu().numpy().astype(int)) - if isinstance(scores, list): - box_scores = list(scores[0].cpu().numpy().astype(float)) - mask_scores = list(scores[1].cpu().numpy().astype(float)) - else: - scores = list(scores.cpu().numpy().astype(float)) - box_scores = scores - mask_scores = scores - # if args.cuda: - # masks = masks.view(-1, h*w).npu() - # boxes = boxes.npu() - # else: - masks = masks.view(-1, h*w) - - - if args.output_coco_json: - with timer.env('JSON Output'): - boxes = boxes.cpu().numpy() - masks = masks.view(-1, h, w).cpu().numpy() - for i in range(masks.shape[0]): - # Make sure that the bounding box actually makes sense and a mask was produced - if (boxes[i, 3] - boxes[i, 1]) * (boxes[i, 2] - boxes[i, 0]) > 0: - detections.add_bbox(image_id, classes[i], boxes[i,:], box_scores[i]) - detections.add_mask(image_id, classes[i], masks[i,:,:], mask_scores[i]) - return - - with timer.env('Eval Setup'): - num_pred = len(classes) - num_gt = len(gt_classes) - - mask_iou_cache = _mask_iou(masks, gt_masks) - bbox_iou_cache = _bbox_iou(boxes.float(), gt_boxes.float()) - - if num_crowd > 0: - crowd_mask_iou_cache = _mask_iou(masks, crowd_masks, iscrowd=True) - crowd_bbox_iou_cache = _bbox_iou(boxes.float(), crowd_boxes.float(), iscrowd=True) - else: - crowd_mask_iou_cache = None - crowd_bbox_iou_cache = None - - box_indices = sorted(range(num_pred), key=lambda i: -box_scores[i]) - mask_indices = sorted(box_indices, key=lambda i: -mask_scores[i]) - - iou_types = [ - ('box', lambda i,j: bbox_iou_cache[i, j].item(), - lambda i,j: crowd_bbox_iou_cache[i,j].item(), - lambda i: box_scores[i], box_indices), - ('mask', lambda i,j: mask_iou_cache[i, j].item(), - lambda i,j: crowd_mask_iou_cache[i,j].item(), - lambda i: mask_scores[i], mask_indices) - ] - - timer.start('Main loop') - for _class in set(classes + gt_classes): - ap_per_iou = [] - num_gt_for_class = sum([1 for x in gt_classes if x == _class]) - - for iouIdx in range(len(iou_thresholds)): - iou_threshold = iou_thresholds[iouIdx] - - for iou_type, iou_func, crowd_func, score_func, indices in iou_types: - gt_used = [False] * len(gt_classes) - - ap_obj = ap_data[iou_type][iouIdx][_class] - ap_obj.add_gt_positives(num_gt_for_class) - - for i in indices: - if classes[i] != _class: - continue - - max_iou_found = iou_threshold - max_match_idx = -1 - for j in range(num_gt): - if gt_used[j] or gt_classes[j] != _class: - continue - - iou = iou_func(i, j) - - if iou > max_iou_found: - max_iou_found = iou - max_match_idx = j - - if max_match_idx >= 0: - gt_used[max_match_idx] = True - ap_obj.push(score_func(i), True) - else: - # If the detection matches a crowd, we can just ignore it - matched_crowd = False - - if num_crowd > 0: - for j in range(len(crowd_classes)): - if crowd_classes[j] != _class: - continue - - iou = crowd_func(i, j) - - if iou > iou_threshold: - matched_crowd = True - break - - # All this crowd code so that we can make sure that our eval code gives the - # same result as COCOEval. There aren't even that many crowd annotations to - # begin with, but accuracy is of the utmost importance. - if not matched_crowd: - ap_obj.push(score_func(i), False) - timer.stop('Main loop') - - -class APDataObject: - """ - Stores all the information necessary to calculate the AP for one IoU and one class. - Note: I type annotated this because why not. - """ - - def __init__(self): - self.data_points = [] - self.num_gt_positives = 0 - - def push(self, score:float, is_true:bool): - self.data_points.append((score, is_true)) - - def add_gt_positives(self, num_positives:int): - """ Call this once per image. """ - self.num_gt_positives += num_positives - - def is_empty(self) -> bool: - return len(self.data_points) == 0 and self.num_gt_positives == 0 - - def get_ap(self) -> float: - """ Warning: result not cached. """ - - if self.num_gt_positives == 0: - return 0 - - # Sort descending by score - self.data_points.sort(key=lambda x: -x[0]) - - precisions = [] - recalls = [] - num_true = 0 - num_false = 0 - - # Compute the precision-recall curve. The x axis is recalls and the y axis precisions. - for datum in self.data_points: - # datum[1] is whether the detection a true or false positive - if datum[1]: num_true += 1 - else: num_false += 1 - - precision = num_true / (num_true + num_false) - recall = num_true / self.num_gt_positives - - precisions.append(precision) - recalls.append(recall) - - # Smooth the curve by computing [max(precisions[i:]) for i in range(len(precisions))] - # Basically, remove any temporary dips from the curve. - # At least that's what I think, idk. COCOEval did it so I do too. - for i in range(len(precisions)-1, 0, -1): - if precisions[i] > precisions[i-1]: - precisions[i-1] = precisions[i] - - # Compute the integral of precision(recall) d_recall from recall=0->1 using fixed-length riemann summation with 101 bars. - y_range = [0] * 101 # idx 0 is recall == 0.0 and idx 100 is recall == 1.00 - x_range = np.array([x / 100 for x in range(101)]) - recalls = np.array(recalls) - - # I realize this is weird, but all it does is find the nearest precision(x) for a given x in x_range. - # Basically, if the closest recall we have to 0.01 is 0.009 this sets precision(0.01) = precision(0.009). - # I approximate the integral this way, because that's how COCOEval does it. - indices = np.searchsorted(recalls, x_range, side='left') - for bar_idx, precision_idx in enumerate(indices): - if precision_idx < len(precisions): - y_range[bar_idx] = precisions[precision_idx] - - # Finally compute the riemann sum to get our integral. - # avg([precision(x) for x in 0:0.01:1]) - return sum(y_range) / len(y_range) - -def badhash(x): - """ - Just a quick and dirty hash function for doing a deterministic shuffle based on image_id. - - Source: - https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key - """ - x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF - x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF - x = ((x >> 16) ^ x) & 0xFFFFFFFF - return x - -def evalimage(net:Yolact, path:str, save_path:str=None): - if args.cuda: - frame = torch.from_numpy(cv2.imread(path)).npu().float() - else: - frame = torch.from_numpy(cv2.imread(path)).float() - print('frame: ', frame) - batch = FastBaseTransform()(frame.unsqueeze(0)) - print('batch_pred:', batch) - print('batch_shape:', batch.shape) - preds = net(batch) - - img_numpy = prep_display(preds, frame, None, None, undo_transform=False) - - if save_path is None: - img_numpy = img_numpy[:, :, (2, 1, 0)] - - if save_path is None: - plt.imshow(img_numpy) - plt.title(path) - plt.show() - else: - cv2.imwrite(save_path, img_numpy) - -def evalimages(net:Yolact, input_folder:str, output_folder:str): - if not os.path.exists(output_folder): - os.mkdir(output_folder) - - print() - for p in Path(input_folder).glob('*'): - path = str(p) - name = os.path.basename(path) - name = '.'.join(name.split('.')[:-1]) + '.png' - out_path = os.path.join(output_folder, name) - - evalimage(net, path, out_path) - print(path + ' -> ' + out_path) - print('Done.') - -from multiprocessing.pool import ThreadPool -from queue import Queue - -class CustomDataParallel(torch.nn.DataParallel): - """ A Custom Data Parallel class that properly gathers lists of dictionaries. """ - def gather(self, outputs, output_device): - # Note that I don't actually want to convert everything to the output_device - return sum(outputs, []) - -def evalvideo(net:Yolact, path:str, out_path:str=None): - # If the path is a digit, parse it as a webcam index - is_webcam = path.isdigit() - - # If the input image size is constant, this make things faster (hence why we can use it in a video setting). - cudnn.benchmark = True - - if is_webcam: - vid = cv2.VideoCapture(int(path)) - else: - vid = cv2.VideoCapture(path) - - if not vid.isOpened(): - print('Could not open video "%s"' % path) - exit(-1) - - target_fps = round(vid.get(cv2.CAP_PROP_FPS)) - frame_width = round(vid.get(cv2.CAP_PROP_FRAME_WIDTH)) - frame_height = round(vid.get(cv2.CAP_PROP_FRAME_HEIGHT)) - - if is_webcam: - num_frames = float('inf') - else: - num_frames = round(vid.get(cv2.CAP_PROP_FRAME_COUNT)) - - net = CustomDataParallel(net).npu() - transform = torch.nn.DataParallel(FastBaseTransform()).npu() - frame_times = MovingAverage(100) - fps = 0 - frame_time_target = 1 / target_fps - running = True - fps_str = '' - vid_done = False - frames_displayed = 0 - - if out_path is not None: - out = cv2.VideoWriter(out_path, cv2.VideoWriter_fourcc(*"mp4v"), target_fps, (frame_width, frame_height)) - - def cleanup_and_exit(): - print() - pool.terminate() - vid.release() - if out_path is not None: - out.release() - cv2.destroyAllWindows() - exit() - - def get_next_frame(vid): - frames = [] - for idx in range(args.video_multiframe): - frame = vid.read()[1] - if frame is None: - return frames - frames.append(frame) - return frames - - def transform_frame(frames): - with torch.no_grad(): - frames = [torch.from_numpy(frame).npu().float() for frame in frames] - return frames, transform(torch.stack(frames, 0)) - - def eval_network(inp): - with torch.no_grad(): - frames, imgs = inp - num_extra = 0 - while imgs.size(0) < args.video_multiframe: - imgs = torch.cat([imgs, imgs[0].unsqueeze(0)], dim=0) - num_extra += 1 - out = net(imgs) - if num_extra > 0: - out = out[:-num_extra] - return frames, out - - def prep_frame(inp, fps_str): - with torch.no_grad(): - frame, preds = inp - return prep_display(preds, frame, None, None, undo_transform=False, class_color=True, fps_str=fps_str) - - frame_buffer = Queue() - video_fps = 0 - - # All this timing code to make sure that - def play_video(): - try: - nonlocal frame_buffer, running, video_fps, is_webcam, num_frames, frames_displayed, vid_done - - video_frame_times = MovingAverage(100) - frame_time_stabilizer = frame_time_target - last_time = None - stabilizer_step = 0.0005 - progress_bar = ProgressBar(30, num_frames) - - while running: - frame_time_start = time.time() - - if not frame_buffer.empty(): - next_time = time.time() - if last_time is not None: - video_frame_times.add(next_time - last_time) - video_fps = 1 / video_frame_times.get_avg() - if out_path is None: - cv2.imshow(path, frame_buffer.get()) - else: - out.write(frame_buffer.get()) - frames_displayed += 1 - last_time = next_time - - if out_path is not None: - if video_frame_times.get_avg() == 0: - fps = 0 - else: - fps = 1 / video_frame_times.get_avg() - progress = frames_displayed / num_frames * 100 - progress_bar.set_val(frames_displayed) - - print('\rProcessing Frames %s %6d / %6d (%5.2f%%) %5.2f fps ' - % (repr(progress_bar), frames_displayed, num_frames, progress, fps), end='') - - - # This is split because you don't want savevideo to require cv2 display functionality (see #197) - if out_path is None and cv2.waitKey(1) == 27: - # Press Escape to close - running = False - if not (frames_displayed < num_frames): - running = False - - if not vid_done: - buffer_size = frame_buffer.qsize() - if buffer_size < args.video_multiframe: - frame_time_stabilizer += stabilizer_step - elif buffer_size > args.video_multiframe: - frame_time_stabilizer -= stabilizer_step - if frame_time_stabilizer < 0: - frame_time_stabilizer = 0 - - new_target = frame_time_stabilizer if is_webcam else max(frame_time_stabilizer, frame_time_target) - else: - new_target = frame_time_target - - next_frame_target = max(2 * new_target - video_frame_times.get_avg(), 0) - target_time = frame_time_start + next_frame_target - 0.001 # Let's just subtract a millisecond to be safe - - if out_path is None or args.emulate_playback: - # This gives more accurate timing than if sleeping the whole amount at once - while time.time() < target_time: - time.sleep(0.001) - else: - # Let's not starve the main thread, now - time.sleep(0.001) - except: - # See issue #197 for why this is necessary - import traceback - traceback.print_exc() - - - extract_frame = lambda x, i: (x[0][i] if x[1][i]['detection'] is None else x[0][i].to(x[1][i]['detection']['box'].device), [x[1][i]]) - - # Prime the network on the first frame because I do some thread unsafe things otherwise - print('Initializing model... ', end='') - first_batch = eval_network(transform_frame(get_next_frame(vid))) - print('Done.') - - # For each frame the sequence of functions it needs to go through to be processed (in reversed order) - sequence = [prep_frame, eval_network, transform_frame] - pool = ThreadPool(processes=len(sequence) + args.video_multiframe + 2) - pool.apply_async(play_video) - active_frames = [{'value': extract_frame(first_batch, i), 'idx': 0} for i in range(len(first_batch[0]))] - - print() - if out_path is None: print('Press Escape to close.') - try: - while vid.isOpened() and running: - # Hard limit on frames in buffer so we don't run out of memory >.> - while frame_buffer.qsize() > 100: - time.sleep(0.001) - - start_time = time.time() - - # Start loading the next frames from the disk - if not vid_done: - next_frames = pool.apply_async(get_next_frame, args=(vid,)) - else: - next_frames = None - - if not (vid_done and len(active_frames) == 0): - # For each frame in our active processing queue, dispatch a job - # for that frame using the current function in the sequence - for frame in active_frames: - _args = [frame['value']] - if frame['idx'] == 0: - _args.append(fps_str) - frame['value'] = pool.apply_async(sequence[frame['idx']], args=_args) - - # For each frame whose job was the last in the sequence (i.e. for all final outputs) - for frame in active_frames: - if frame['idx'] == 0: - frame_buffer.put(frame['value'].get()) - - # Remove the finished frames from the processing queue - active_frames = [x for x in active_frames if x['idx'] > 0] - - # Finish evaluating every frame in the processing queue and advanced their position in the sequence - for frame in list(reversed(active_frames)): - frame['value'] = frame['value'].get() - frame['idx'] -= 1 - - if frame['idx'] == 0: - # Split this up into individual threads for prep_frame since it doesn't support batch size - active_frames += [{'value': extract_frame(frame['value'], i), 'idx': 0} for i in range(1, len(frame['value'][0]))] - frame['value'] = extract_frame(frame['value'], 0) - - # Finish loading in the next frames and add them to the processing queue - if next_frames is not None: - frames = next_frames.get() - if len(frames) == 0: - vid_done = True - else: - active_frames.append({'value': frames, 'idx': len(sequence)-1}) - - # Compute FPS - frame_times.add(time.time() - start_time) - fps = args.video_multiframe / frame_times.get_avg() - else: - fps = 0 - - fps_str = 'Processing FPS: %.2f | Video Playback FPS: %.2f | Frames in Buffer: %d' % (fps, video_fps, frame_buffer.qsize()) - if not args.display_fps: - print('\r' + fps_str + ' ', end='') - - except KeyboardInterrupt: - print('\nStopping...') - - cleanup_and_exit() - -def evaluate(net:Yolact, dataset, train_mode=False, trainCuda = True): - net.detect.use_fast_nms = args.fast_nms - net.detect.use_cross_class_nms = args.cross_class_nms - cfg.mask_proto_debug = args.mask_proto_debug - - # TODO Currently we do not support Fast Mask Re-scroing in evalimage, evalimages, and evalvideo - if args.image is not None: - if ':' in args.image: - inp, out = args.image.split(':') - evalimage(net, inp, out) - else: - evalimage(net, args.image) - return - elif args.images is not None: - inp, out = args.images.split(':') - evalimages(net, inp, out) - return - elif args.video is not None: - if ':' in args.video: - inp, out = args.video.split(':') - evalvideo(net, inp, out) - else: - evalvideo(net, args.video) - return - - frame_times = MovingAverage() - dataset_size = len(dataset) if args.max_images < 0 else min(args.max_images, len(dataset)) - progress_bar = ProgressBar(30, dataset_size) - - print() - - if not args.display and not args.benchmark: - # For each class and iou, stores tuples (score, isPositive) - # Index ap_data[type][iouIdx][classIdx] - ap_data = { - 'box' : [[APDataObject() for _ in cfg.dataset.class_names] for _ in iou_thresholds], - 'mask': [[APDataObject() for _ in cfg.dataset.class_names] for _ in iou_thresholds] - } - detections = Detections() - else: - timer.disable('Load Data') - - dataset_indices = list(range(len(dataset))) - - if args.shuffle: - random.shuffle(dataset_indices) - elif not args.no_sort: - # Do a deterministic shuffle based on the image ids - # - # I do this because on python 3.5 dictionary key order is *random*, while in 3.6 it's - # the order of insertion. That means on python 3.6, the images come in the order they are in - # in the annotations file. For some reason, the first images in the annotations file are - # the hardest. To combat this, I use a hard-coded hash function based on the image ids - # to shuffle the indices we use. That way, no matter what python version or how pycocotools - # handles the data, we get the same result every time. - hashed = [badhash(x) for x in dataset.ids] - dataset_indices.sort(key=lambda x: hashed[x]) - - dataset_indices = dataset_indices[:dataset_size] - - try: - # Main eval loop - for it, image_idx in enumerate(tqdm(dataset_indices)): - timer.reset() - - with timer.env('Load Data'): - img, gt, gt_masks, h, w, num_crowd = dataset.pull_item(image_idx) - # Test flag, do not upvote - if cfg.mask_proto_debug: - with open('scripts/info.txt', 'w') as f: - f.write(str(dataset.ids[image_idx])) - np.save('scripts/gt.npy', gt_masks) - - batch = Variable(img.unsqueeze(0)) - if args.cuda: - if train_mode: - batch = batch.npu() if trainCuda else batch - else: - batch = batch.npu() - - with timer.env('Network Extra'): - preds = net(batch) - if preds is not None and preds[0] is not None: - if preds[0]['box'] is not None: - preds[0]['box'] = preds[0]['box'].cpu() - if preds[0]['mask'] is not None: - preds[0]['mask'] = preds[0]['mask'].cpu() - if preds[0]['class'] is not None: - preds[0]['class'] = preds[0]['class'].cpu() - if preds[0]['score'] is not None: - preds[0]['score'] = preds[0]['score'].cpu() - if preds[0]['proto'] is not None: - preds[0]['proto'] = preds[0]['proto'].cpu() - - # Perform the meat of the operation here depending on our mode. - if args.display: - img_numpy = prep_display(preds, img, h, w) - elif args.benchmark: - prep_benchmark(preds, h, w) - else: - prep_metrics(ap_data, preds, img, gt, gt_masks, h, w, num_crowd, dataset.ids[image_idx], detections) - - # First couple of images take longer because we're constructing the graph. - # Since that's technically initialization, don't include those in the FPS calculations. - if it > 1: - frame_times.add(timer.total_time()) - - if args.display: - if it > 1: - print('Avg FPS: %.4f' % (1 / frame_times.get_avg())) - plt.imshow(img_numpy) - plt.title(str(dataset.ids[image_idx])) - plt.show() - elif not args.no_bar: - if it > 1: fps = 1 / frame_times.get_avg() - else: fps = 0 - progress = (it+1) / dataset_size * 100 - progress_bar.set_val(it+1) - print('\rProcessing Images %s %6d / %6d (%5.2f%%) %5.2f fps ' - % (repr(progress_bar), it+1, dataset_size, progress, fps), end='') - - - - if not args.display and not args.benchmark: - print() - if args.output_coco_json: - print('Dumping detections...') - if args.output_web_json: - detections.dump_web() - else: - detections.dump() - else: - if not train_mode: - print('Saving data...') - with open(args.ap_data_file, 'wb') as f: - pickle.dump(ap_data, f) - - return calc_map(ap_data) - elif args.benchmark: - print() - print() - print('Stats for the last frame:') - timer.print_stats() - avg_seconds = frame_times.get_avg() - print('Average: %5.2f fps, %5.2f ms' % (1 / frame_times.get_avg(), 1000*avg_seconds)) - - except KeyboardInterrupt: - print('Stopping...') - - -def calc_map(ap_data): - print('Calculating mAP...') - aps = [{'box': [], 'mask': []} for _ in iou_thresholds] - - for _class in range(len(cfg.dataset.class_names)): - for iou_idx in range(len(iou_thresholds)): - for iou_type in ('box', 'mask'): - ap_obj = ap_data[iou_type][iou_idx][_class] - - if not ap_obj.is_empty(): - aps[iou_idx][iou_type].append(ap_obj.get_ap()) - - all_maps = {'box': OrderedDict(), 'mask': OrderedDict()} - - # Looking back at it, this code is really hard to read :/ - for iou_type in ('box', 'mask'): - all_maps[iou_type]['all'] = 0 # Make this first in the ordereddict - for i, threshold in enumerate(iou_thresholds): - mAP = sum(aps[i][iou_type]) / len(aps[i][iou_type]) * 100 if len(aps[i][iou_type]) > 0 else 0 - all_maps[iou_type][int(threshold*100)] = mAP - all_maps[iou_type]['all'] = (sum(all_maps[iou_type].values()) / (len(all_maps[iou_type].values())-1)) - - print_maps(all_maps) - - # Put in a prettier format so we can serialize it to json during training - all_maps = {k: {j: round(u, 2) for j, u in v.items()} for k, v in all_maps.items()} - return all_maps - -def print_maps(all_maps): - # Warning: hacky - make_row = lambda vals: (' %5s |' * len(vals)) % tuple(vals) - make_sep = lambda n: ('-------+' * n) - - print() - print(make_row([''] + [('.%d ' % x if isinstance(x, int) else x + ' ') for x in all_maps['box'].keys()])) - print(make_sep(len(all_maps['box']) + 1)) - for iou_type in ('box', 'mask'): - print(make_row([iou_type] + ['%.2f' % x if x < 100 else '%.1f' % x for x in all_maps[iou_type].values()])) - print(make_sep(len(all_maps['box']) + 1)) - print() - - - -if __name__ == '__main__': - parse_args() - - if args.config is not None: - set_cfg(args.config) - - if args.trained_model == 'interrupt': - - args.trained_model = SavePath.get_interrupt('weights/') - elif args.trained_model == 'latest': - args.trained_model = SavePath.get_latest('weights/', cfg.name) - - if args.config is None: - model_path = SavePath.from_str(args.trained_model) - # TODO: Bad practice? Probably want to do a name lookup instead. - args.config = model_path.model_name + '_config' - print('Config not specified. Parsed %s from the file name.\n' % args.config) - set_cfg(args.config) - - if args.detect: - cfg.eval_mask_branch = False - - if args.dataset is not None: - set_dataset(args.dataset) - - if args.data_path: - cfg.dataset.valid_images = args.data_path + '/images/' - cfg.dataset.valid_info = args.data_path + '/annotations/instances_val2017.json' - - with torch.no_grad(): - if not os.path.exists('results'): - os.makedirs('results') - - if args.cuda: - cudnn.fastest = True - args.device = torch.device(f'npu:{args.rank_id}') - torch.npu.set_device(args.device) - #torch.set_default_tensor_type('torch.npu.FloatTensor') - else: - torch.set_default_tensor_type('torch.FloatTensor') - - if args.resume and not args.display: - with open(args.ap_data_file, 'rb') as f: - ap_data = pickle.load(f) - calc_map(ap_data) - exit() - - if args.image is None and args.video is None and args.images is None: - dataset = COCODetection(cfg.dataset.valid_images, cfg.dataset.valid_info, - transform=BaseTransform(), has_gt=cfg.dataset.has_gt) - prep_coco_cats() - else: - dataset = None - - print('Loading model...', end='') - net = Yolact() - net.load_weights(args.trained_model) - net.eval() - print(' Done.') - - if args.cuda: - net = net.npu() - - evaluate(net, dataset) - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +from data import COCODetection, get_label_map, MEANS, COLORS +from yolact import Yolact +from utils.augmentations import BaseTransform, FastBaseTransform, Resize +from utils.functions import MovingAverage, ProgressBar +from layers.box_utils import jaccard, center_size, mask_iou +from utils import timer +from utils.functions import SavePath +from layers.output_utils import postprocess, undo_image_transformation +import pycocotools + +from data import cfg, set_cfg, set_dataset +from tqdm import tqdm +import numpy as np +import torch +import torch.backends.cudnn as cudnn +from torch.autograd import Variable +import argparse +import time +import random +import cProfile +import pickle +import json +import os +from collections import defaultdict +from pathlib import Path +from collections import OrderedDict +from PIL import Image + +import matplotlib.pyplot as plt +import cv2 + +def str2bool(v): + if v.lower() in ('yes', 'true', 't', 'y', '1'): + return True + elif v.lower() in ('no', 'false', 'f', 'n', '0'): + return False + else: + raise argparse.ArgumentTypeError('Boolean value expected.') + +def parse_args(argv=None): + parser = argparse.ArgumentParser( + description='YOLACT COCO Evaluation') + parser.add_argument('--trained_model', + default='weights/ssd300_mAP_77.43_v2.pth', type=str, + help='Trained state_dict file path to open. If "interrupt", this will open the interrupt file.') + parser.add_argument('--data_path', default=None, type=str, + help='data path') + parser.add_argument('--top_k', default=5, type=int, + help='Further restrict the number of predictions to parse') + parser.add_argument('--cuda', default=True, type=str2bool, + help='Use cuda to evaulate model') + parser.add_argument('--fast_nms', default=True, type=str2bool, + help='Whether to use a faster, but not entirely correct version of NMS.') + parser.add_argument('--cross_class_nms', default=False, type=str2bool, + help='Whether compute NMS cross-class or per-class.') + parser.add_argument('--display_masks', default=True, type=str2bool, + help='Whether or not to display masks over bounding boxes') + parser.add_argument('--display_bboxes', default=True, type=str2bool, + help='Whether or not to display bboxes around masks') + parser.add_argument('--display_text', default=True, type=str2bool, + help='Whether or not to display text (class [score])') + parser.add_argument('--display_scores', default=True, type=str2bool, + help='Whether or not to display scores in addition to classes') + parser.add_argument('--display', dest='display', action='store_true', + help='Display qualitative results instead of quantitative ones.') + parser.add_argument('--shuffle', dest='shuffle', action='store_true', + help='Shuffles the images when displaying them. Doesn\'t have much of an effect when display is off though.') + parser.add_argument('--ap_data_file', default='results/ap_data.pkl', type=str, + help='In quantitative mode, the file to save detections before calculating mAP.') + parser.add_argument('--resume', dest='resume', action='store_true', + help='If display not set, this resumes mAP calculations from the ap_data_file.') + parser.add_argument('--max_images', default=-1, type=int, + help='The maximum number of images from the dataset to consider. Use -1 for all.') + parser.add_argument('--output_coco_json', dest='output_coco_json', action='store_true', + help='If display is not set, instead of processing IoU values, this just dumps detections into the coco json file.') + parser.add_argument('--bbox_det_file', default='results/bbox_detections.json', type=str, + help='The output file for coco bbox results if --coco_results is set.') + parser.add_argument('--mask_det_file', default='results/mask_detections.json', type=str, + help='The output file for coco mask results if --coco_results is set.') + parser.add_argument('--config', default='yolact_plus_resnet50_config', + help='The config object to use.') + parser.add_argument('--output_web_json', dest='output_web_json', action='store_true', + help='If display is not set, instead of processing IoU values, this dumps detections for usage with the detections viewer web thingy.') + parser.add_argument('--web_det_path', default='web/dets/', type=str, + help='If output_web_json is set, this is the path to dump detections into.') + parser.add_argument('--no_bar', dest='no_bar', action='store_true', + help='Do not output the status bar. This is useful for when piping to a file.') + parser.add_argument('--display_lincomb', default=False, type=str2bool, + help='If the config uses lincomb masks, output a visualization of how those masks are created.') + parser.add_argument('--benchmark', default=False, dest='benchmark', action='store_true', + help='Equivalent to running display mode but without displaying an image.') + parser.add_argument('--no_sort', default=False, dest='no_sort', action='store_true', + help='Do not sort images by hashed image ID.') + parser.add_argument('--seed', default=None, type=int, + help='The seed to pass into random.seed. Note: this is only really for the shuffle and does not (I think) affect cuda stuff.') + parser.add_argument('--mask_proto_debug', default=False, dest='mask_proto_debug', action='store_true', + help='Outputs stuff for scripts/compute_mask.py.') + parser.add_argument('--no_crop', default=False, dest='crop', action='store_false', + help='Do not crop output masks with the predicted bounding box.') + parser.add_argument('--image', default=None, type=str, + help='A path to an image to use for display.') + parser.add_argument('--images', default=None, type=str, + help='An input folder of images and output folder to save detected images. Should be in the format input->output.') + parser.add_argument('--video', default=None, type=str, + help='A path to a video to evaluate on. Passing in a number will use that index webcam.') + parser.add_argument('--video_multiframe', default=1, type=int, + help='The number of frames to evaluate in parallel to make videos play at higher fps.') + parser.add_argument('--score_threshold', default=0, type=float, + help='Detections with a score under this threshold will not be considered. This currently only works in display mode.') + parser.add_argument('--dataset', default=None, type=str, + help='If specified, override the dataset specified in the config with this one (example: coco2017_dataset).') + parser.add_argument('--detect', default=False, dest='detect', action='store_true', + help='Don\'t evauluate the mask branch at all and only do object detection. This only works for --display and --benchmark.') + parser.add_argument('--display_fps', default=False, dest='display_fps', action='store_true', + help='When displaying / saving video, draw the FPS on the frame') + parser.add_argument('--emulate_playback', default=False, dest='emulate_playback', action='store_true', + help='When saving a video, emulate the framerate that you\'d get running in real-time mode.') + parser.add_argument('--rank_id', default=0, type=int) + parser.set_defaults(no_bar=False, display=False, resume=False, output_coco_json=False, output_web_json=False, shuffle=False, + benchmark=False, no_sort=False, no_hash=False, mask_proto_debug=False, crop=True, detect=False, display_fps=False, + emulate_playback=False) + + global args + args = parser.parse_args(argv) + + if args.output_web_json: + args.output_coco_json = True + + if args.seed is not None: + random.seed(args.seed) + +iou_thresholds = [x / 100 for x in range(50, 100, 5)] +coco_cats = {} # Call prep_coco_cats to fill this +coco_cats_inv = {} +color_cache = defaultdict(lambda: {}) + +def prep_display(dets_out, img, h, w, undo_transform=True, class_color=False, mask_alpha=0.45, fps_str=''): + """ + Note: If undo_transform=False then im_h and im_w are allowed to be None. + """ + if undo_transform: + img_numpy = undo_image_transformation(img, w, h) + if args.cuda: + img_gpu = torch.Tensor(img_numpy).npu() + else: + img_gpu = torch.Tensor(img_numpy) + print('img_shape:', img_gpu) + else: + img_gpu = img / 255.0 + h, w, _ = img.shape + print('h, w, _ :', img.shape) + + with timer.env('Postprocess'): + save = cfg.rescore_bbox + cfg.rescore_bbox = True + t = postprocess(dets_out, w, h, visualize_lincomb = args.display_lincomb, + crop_masks = args.crop, + score_threshold = args.score_threshold) + cfg.rescore_bbox = save + + with timer.env('Copy'): + idx = t[1].argsort(0, descending=True)[:args.top_k] + + if cfg.eval_mask_branch: + # Masks are drawn on the GPU, so don't copy + masks = t[3][idx] + classes, scores, boxes = [x[idx].cpu().numpy() for x in t[:3]] + + num_dets_to_consider = min(args.top_k, classes.shape[0]) + for j in range(num_dets_to_consider): + if scores[j] < args.score_threshold: + num_dets_to_consider = j + break + + # Quick and dirty lambda for selecting the color for a particular index + # Also keeps track of a per-gpu color cache for maximum speed + def get_color(j, on_gpu=None): + global color_cache + color_idx = (classes[j] * 5 if class_color else j * 5) % len(COLORS) + + if on_gpu is not None and color_idx in color_cache[on_gpu]: + return color_cache[on_gpu][color_idx] + else: + color = COLORS[color_idx] + if not undo_transform: + # The image might come in as RGB or BRG, depending + color = (color[2], color[1], color[0]) + if on_gpu is not None: + color = torch.Tensor(color).to(on_gpu).float() / 255. + color_cache[on_gpu][color_idx] = color + return color + + # First, draw the masks on the GPU where we can do it really fast + # Beware: very fast but possibly unintelligible mask-drawing code ahead + # I wish I had access to OpenGL or Vulkan but alas, I guess Pytorch tensor operations will have to suffice + if args.display_masks and cfg.eval_mask_branch and num_dets_to_consider > 0: + # After this, mask is of size [num_dets, h, w, 1] + masks = masks[:num_dets_to_consider, :, :, None] + + # Prepare the RGB images for each mask given their color (size [num_dets, h, w, 1]) + colors = torch.cat([get_color(j, on_gpu=img_gpu.device.index).view(1, 1, 1, 3) for j in range(num_dets_to_consider)], dim=0) + masks_color = masks.repeat(1, 1, 1, 3) * colors * mask_alpha + + # This is 1 everywhere except for 1-mask_alpha where the mask is + inv_alph_masks = masks * (-mask_alpha) + 1 + + # I did the math for this on pen and paper. This whole block should be equivalent to: + # for j in range(num_dets_to_consider): + # img_gpu = img_gpu * inv_alph_masks[j] + masks_color[j] + masks_color_summand = masks_color[0] + if num_dets_to_consider > 1: + inv_alph_cumul = inv_alph_masks[:(num_dets_to_consider-1)].cumprod(dim=0) + masks_color_cumul = masks_color[1:] * inv_alph_cumul + masks_color_summand += masks_color_cumul.sum(dim=0) + + img_gpu = img_gpu * inv_alph_masks.prod(dim=0) + masks_color_summand + + if args.display_fps: + # Draw the box for the fps on the GPU + font_face = cv2.FONT_HERSHEY_DUPLEX + font_scale = 0.6 + font_thickness = 1 + + text_w, text_h = cv2.getTextSize(fps_str, font_face, font_scale, font_thickness)[0] + + img_gpu[0:text_h+8, 0:text_w+8] *= 0.6 # 1 - Box alpha + + + # Then draw the stuff that needs to be done on the cpu + # Note, make sure this is a uint8 tensor or opencv will not anti alias text for whatever reason + img_numpy = (img_gpu * 255).byte().cpu().numpy() + + if args.display_fps: + # Draw the text on the CPU + text_pt = (4, text_h + 2) + text_color = [255, 255, 255] + + cv2.putText(img_numpy, fps_str, text_pt, font_face, font_scale, text_color, font_thickness, cv2.LINE_AA) + + if num_dets_to_consider == 0: + return img_numpy + + if args.display_text or args.display_bboxes: + for j in reversed(range(num_dets_to_consider)): + x1, y1, x2, y2 = boxes[j, :] + color = get_color(j) + score = scores[j] + + if args.display_bboxes: + cv2.rectangle(img_numpy, (x1, y1), (x2, y2), color, 1) + + if args.display_text: + _class = cfg.dataset.class_names[classes[j]] + text_str = '%s: %.2f' % (_class, score) if args.display_scores else _class + + font_face = cv2.FONT_HERSHEY_DUPLEX + font_scale = 0.6 + font_thickness = 1 + + text_w, text_h = cv2.getTextSize(text_str, font_face, font_scale, font_thickness)[0] + + text_pt = (x1, y1 - 3) + text_color = [255, 255, 255] + + cv2.rectangle(img_numpy, (x1, y1), (x1 + text_w, y1 - text_h - 4), color, -1) + cv2.putText(img_numpy, text_str, text_pt, font_face, font_scale, text_color, font_thickness, cv2.LINE_AA) + + + return img_numpy + +def prep_benchmark(dets_out, h, w): + with timer.env('Postprocess'): + t = postprocess(dets_out, w, h, crop_masks=args.crop, score_threshold=args.score_threshold) + + with timer.env('Copy'): + classes, scores, boxes, masks = [x[:args.top_k] for x in t] + if isinstance(scores, list): + box_scores = scores[0].cpu().numpy() + mask_scores = scores[1].cpu().numpy() + else: + scores = scores.cpu().numpy() + classes = classes.cpu().numpy() + boxes = boxes.cpu().numpy() + masks = masks.cpu().numpy() + + with timer.env('Sync'): + # Just in case + torch.npu.synchronize() + +def prep_coco_cats(): + """ Prepare inverted table for category id lookup given a coco cats object. """ + for coco_cat_id, transformed_cat_id_p1 in get_label_map().items(): + transformed_cat_id = transformed_cat_id_p1 - 1 + coco_cats[transformed_cat_id] = coco_cat_id + coco_cats_inv[coco_cat_id] = transformed_cat_id + + +def get_coco_cat(transformed_cat_id): + """ transformed_cat_id is [0,80) as indices in cfg.dataset.class_names """ + return coco_cats[transformed_cat_id] + +def get_transformed_cat(coco_cat_id): + """ transformed_cat_id is [0,80) as indices in cfg.dataset.class_names """ + return coco_cats_inv[coco_cat_id] + + +class Detections: + + def __init__(self): + self.bbox_data = [] + self.mask_data = [] + + def add_bbox(self, image_id:int, category_id:int, bbox:list, score:float): + """ Note that bbox should be a list or tuple of (x1, y1, x2, y2) """ + bbox = [bbox[0], bbox[1], bbox[2]-bbox[0], bbox[3]-bbox[1]] + + # Round to the nearest 10th to avoid huge file sizes, as COCO suggests + bbox = [round(float(x)*10)/10 for x in bbox] + + self.bbox_data.append({ + 'image_id': int(image_id), + 'category_id': get_coco_cat(int(category_id)), + 'bbox': bbox, + 'score': float(score) + }) + + def add_mask(self, image_id:int, category_id:int, segmentation:np.ndarray, score:float): + """ The segmentation should be the full mask, the size of the image and with size [h, w]. """ + rle = pycocotools.mask.encode(np.asfortranarray(segmentation.astype(np.uint8))) + rle['counts'] = rle['counts'].decode('ascii') # json.dump doesn't like bytes strings + + self.mask_data.append({ + 'image_id': int(image_id), + 'category_id': get_coco_cat(int(category_id)), + 'segmentation': rle, + 'score': float(score) + }) + + def dump(self): + dump_arguments = [ + (self.bbox_data, args.bbox_det_file), + (self.mask_data, args.mask_det_file) + ] + + for data, path in dump_arguments: + with open(path, 'w') as f: + json.dump(data, f) + + def dump_web(self): + """ Dumps it in the format for my web app. Warning: bad code ahead! """ + config_outs = ['preserve_aspect_ratio', 'use_prediction_module', + 'use_yolo_regressors', 'use_prediction_matching', + 'train_masks'] + + output = { + 'info' : { + 'Config': {key: getattr(cfg, key) for key in config_outs}, + } + } + + image_ids = list(set([x['image_id'] for x in self.bbox_data])) + image_ids.sort() + image_lookup = {_id: idx for idx, _id in enumerate(image_ids)} + + output['images'] = [{'image_id': image_id, 'dets': []} for image_id in image_ids] + + # These should already be sorted by score with the way prep_metrics works. + for bbox, mask in zip(self.bbox_data, self.mask_data): + image_obj = output['images'][image_lookup[bbox['image_id']]] + image_obj['dets'].append({ + 'score': bbox['score'], + 'bbox': bbox['bbox'], + 'category': cfg.dataset.class_names[get_transformed_cat(bbox['category_id'])], + 'mask': mask['segmentation'], + }) + + with open(os.path.join(args.web_det_path, '%s.json' % cfg.name), 'w') as f: + json.dump(output, f) + + + + +def _mask_iou(mask1, mask2, iscrowd=False): + with timer.env('Mask IoU'): + ret = mask_iou(mask1, mask2, iscrowd) + return ret.cpu() + +def _bbox_iou(bbox1, bbox2, iscrowd=False): + with timer.env('BBox IoU'): + ret = jaccard(bbox1, bbox2, iscrowd) + return ret.cpu() + +def prep_metrics(ap_data, dets, img, gt, gt_masks, h, w, num_crowd, image_id, detections:Detections=None): + """ Returns a list of APs for this image, with each element being for a class """ + if not args.output_coco_json: + with timer.env('Prepare gt'): + gt_boxes = torch.Tensor(gt[:, :4]) if args.cuda else torch.Tensor(gt[:, :4]) + gt_boxes[:, [0, 2]] *= w + gt_boxes[:, [1, 3]] *= h + gt_classes = list(gt[:, 4].astype(int)) + gt_masks = torch.Tensor(gt_masks).view(-1, h*w) if args.cuda else torch.Tensor(gt_masks).view(-1, h*w) + + if num_crowd > 0: + split = lambda x: (x[-num_crowd:], x[:-num_crowd]) + crowd_boxes , gt_boxes = split(gt_boxes) + crowd_masks , gt_masks = split(gt_masks) + crowd_classes, gt_classes = split(gt_classes) + + with timer.env('Postprocess'): + classes, scores, boxes, masks = postprocess(dets, w, h, crop_masks=args.crop, score_threshold=args.score_threshold) + + if classes.size(0) == 0: + return + + classes = list(classes.cpu().numpy().astype(int)) + if isinstance(scores, list): + box_scores = list(scores[0].cpu().numpy().astype(float)) + mask_scores = list(scores[1].cpu().numpy().astype(float)) + else: + scores = list(scores.cpu().numpy().astype(float)) + box_scores = scores + mask_scores = scores + # if args.cuda: + # masks = masks.view(-1, h*w).npu() + # boxes = boxes.npu() + # else: + masks = masks.view(-1, h*w) + + + if args.output_coco_json: + with timer.env('JSON Output'): + boxes = boxes.cpu().numpy() + masks = masks.view(-1, h, w).cpu().numpy() + for i in range(masks.shape[0]): + # Make sure that the bounding box actually makes sense and a mask was produced + if (boxes[i, 3] - boxes[i, 1]) * (boxes[i, 2] - boxes[i, 0]) > 0: + detections.add_bbox(image_id, classes[i], boxes[i,:], box_scores[i]) + detections.add_mask(image_id, classes[i], masks[i,:,:], mask_scores[i]) + return + + with timer.env('Eval Setup'): + num_pred = len(classes) + num_gt = len(gt_classes) + + mask_iou_cache = _mask_iou(masks, gt_masks) + bbox_iou_cache = _bbox_iou(boxes.float(), gt_boxes.float()) + + if num_crowd > 0: + crowd_mask_iou_cache = _mask_iou(masks, crowd_masks, iscrowd=True) + crowd_bbox_iou_cache = _bbox_iou(boxes.float(), crowd_boxes.float(), iscrowd=True) + else: + crowd_mask_iou_cache = None + crowd_bbox_iou_cache = None + + box_indices = sorted(range(num_pred), key=lambda i: -box_scores[i]) + mask_indices = sorted(box_indices, key=lambda i: -mask_scores[i]) + + iou_types = [ + ('box', lambda i,j: bbox_iou_cache[i, j].item(), + lambda i,j: crowd_bbox_iou_cache[i,j].item(), + lambda i: box_scores[i], box_indices), + ('mask', lambda i,j: mask_iou_cache[i, j].item(), + lambda i,j: crowd_mask_iou_cache[i,j].item(), + lambda i: mask_scores[i], mask_indices) + ] + + timer.start('Main loop') + for _class in set(classes + gt_classes): + ap_per_iou = [] + num_gt_for_class = sum([1 for x in gt_classes if x == _class]) + + for iouIdx in range(len(iou_thresholds)): + iou_threshold = iou_thresholds[iouIdx] + + for iou_type, iou_func, crowd_func, score_func, indices in iou_types: + gt_used = [False] * len(gt_classes) + + ap_obj = ap_data[iou_type][iouIdx][_class] + ap_obj.add_gt_positives(num_gt_for_class) + + for i in indices: + if classes[i] != _class: + continue + + max_iou_found = iou_threshold + max_match_idx = -1 + for j in range(num_gt): + if gt_used[j] or gt_classes[j] != _class: + continue + + iou = iou_func(i, j) + + if iou > max_iou_found: + max_iou_found = iou + max_match_idx = j + + if max_match_idx >= 0: + gt_used[max_match_idx] = True + ap_obj.push(score_func(i), True) + else: + # If the detection matches a crowd, we can just ignore it + matched_crowd = False + + if num_crowd > 0: + for j in range(len(crowd_classes)): + if crowd_classes[j] != _class: + continue + + iou = crowd_func(i, j) + + if iou > iou_threshold: + matched_crowd = True + break + + # All this crowd code so that we can make sure that our eval code gives the + # same result as COCOEval. There aren't even that many crowd annotations to + # begin with, but accuracy is of the utmost importance. + if not matched_crowd: + ap_obj.push(score_func(i), False) + timer.stop('Main loop') + + +class APDataObject: + """ + Stores all the information necessary to calculate the AP for one IoU and one class. + Note: I type annotated this because why not. + """ + + def __init__(self): + self.data_points = [] + self.num_gt_positives = 0 + + def push(self, score:float, is_true:bool): + self.data_points.append((score, is_true)) + + def add_gt_positives(self, num_positives:int): + """ Call this once per image. """ + self.num_gt_positives += num_positives + + def is_empty(self) -> bool: + return len(self.data_points) == 0 and self.num_gt_positives == 0 + + def get_ap(self) -> float: + """ Warning: result not cached. """ + + if self.num_gt_positives == 0: + return 0 + + # Sort descending by score + self.data_points.sort(key=lambda x: -x[0]) + + precisions = [] + recalls = [] + num_true = 0 + num_false = 0 + + # Compute the precision-recall curve. The x axis is recalls and the y axis precisions. + for datum in self.data_points: + # datum[1] is whether the detection a true or false positive + if datum[1]: num_true += 1 + else: num_false += 1 + + precision = num_true / (num_true + num_false) + recall = num_true / self.num_gt_positives + + precisions.append(precision) + recalls.append(recall) + + # Smooth the curve by computing [max(precisions[i:]) for i in range(len(precisions))] + # Basically, remove any temporary dips from the curve. + # At least that's what I think, idk. COCOEval did it so I do too. + for i in range(len(precisions)-1, 0, -1): + if precisions[i] > precisions[i-1]: + precisions[i-1] = precisions[i] + + # Compute the integral of precision(recall) d_recall from recall=0->1 using fixed-length riemann summation with 101 bars. + y_range = [0] * 101 # idx 0 is recall == 0.0 and idx 100 is recall == 1.00 + x_range = np.array([x / 100 for x in range(101)]) + recalls = np.array(recalls) + + # I realize this is weird, but all it does is find the nearest precision(x) for a given x in x_range. + # Basically, if the closest recall we have to 0.01 is 0.009 this sets precision(0.01) = precision(0.009). + # I approximate the integral this way, because that's how COCOEval does it. + indices = np.searchsorted(recalls, x_range, side='left') + for bar_idx, precision_idx in enumerate(indices): + if precision_idx < len(precisions): + y_range[bar_idx] = precisions[precision_idx] + + # Finally compute the riemann sum to get our integral. + # avg([precision(x) for x in 0:0.01:1]) + return sum(y_range) / len(y_range) + +def badhash(x): + """ + Just a quick and dirty hash function for doing a deterministic shuffle based on image_id. + + Source: + https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key + """ + x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF + x = (((x >> 16) ^ x) * 0x045d9f3b) & 0xFFFFFFFF + x = ((x >> 16) ^ x) & 0xFFFFFFFF + return x + +def evalimage(net:Yolact, path:str, save_path:str=None): + if args.cuda: + frame = torch.from_numpy(cv2.imread(path)).npu().float() + else: + frame = torch.from_numpy(cv2.imread(path)).float() + print('frame: ', frame) + batch = FastBaseTransform()(frame.unsqueeze(0)) + print('batch_pred:', batch) + print('batch_shape:', batch.shape) + preds = net(batch) + + img_numpy = prep_display(preds, frame, None, None, undo_transform=False) + + if save_path is None: + img_numpy = img_numpy[:, :, (2, 1, 0)] + + if save_path is None: + plt.imshow(img_numpy) + plt.title(path) + plt.show() + else: + cv2.imwrite(save_path, img_numpy) + +def evalimages(net:Yolact, input_folder:str, output_folder:str): + if not os.path.exists(output_folder): + os.mkdir(output_folder) + + print() + for p in Path(input_folder).glob('*'): + path = str(p) + name = os.path.basename(path) + name = '.'.join(name.split('.')[:-1]) + '.png' + out_path = os.path.join(output_folder, name) + + evalimage(net, path, out_path) + print(path + ' -> ' + out_path) + print('Done.') + +from multiprocessing.pool import ThreadPool +from queue import Queue + +class CustomDataParallel(torch.nn.DataParallel): + """ A Custom Data Parallel class that properly gathers lists of dictionaries. """ + def gather(self, outputs, output_device): + # Note that I don't actually want to convert everything to the output_device + return sum(outputs, []) + +def evalvideo(net:Yolact, path:str, out_path:str=None): + # If the path is a digit, parse it as a webcam index + is_webcam = path.isdigit() + + # If the input image size is constant, this make things faster (hence why we can use it in a video setting). + cudnn.benchmark = True + + if is_webcam: + vid = cv2.VideoCapture(int(path)) + else: + vid = cv2.VideoCapture(path) + + if not vid.isOpened(): + print('Could not open video "%s"' % path) + exit(-1) + + target_fps = round(vid.get(cv2.CAP_PROP_FPS)) + frame_width = round(vid.get(cv2.CAP_PROP_FRAME_WIDTH)) + frame_height = round(vid.get(cv2.CAP_PROP_FRAME_HEIGHT)) + + if is_webcam: + num_frames = float('inf') + else: + num_frames = round(vid.get(cv2.CAP_PROP_FRAME_COUNT)) + + net = CustomDataParallel(net).npu() + transform = torch.nn.DataParallel(FastBaseTransform()).npu() + frame_times = MovingAverage(100) + fps = 0 + frame_time_target = 1 / target_fps + running = True + fps_str = '' + vid_done = False + frames_displayed = 0 + + if out_path is not None: + out = cv2.VideoWriter(out_path, cv2.VideoWriter_fourcc(*"mp4v"), target_fps, (frame_width, frame_height)) + + def cleanup_and_exit(): + print() + pool.terminate() + vid.release() + if out_path is not None: + out.release() + cv2.destroyAllWindows() + exit() + + def get_next_frame(vid): + frames = [] + for idx in range(args.video_multiframe): + frame = vid.read()[1] + if frame is None: + return frames + frames.append(frame) + return frames + + def transform_frame(frames): + with torch.no_grad(): + frames = [torch.from_numpy(frame).npu().float() for frame in frames] + return frames, transform(torch.stack(frames, 0)) + + def eval_network(inp): + with torch.no_grad(): + frames, imgs = inp + num_extra = 0 + while imgs.size(0) < args.video_multiframe: + imgs = torch.cat([imgs, imgs[0].unsqueeze(0)], dim=0) + num_extra += 1 + out = net(imgs) + if num_extra > 0: + out = out[:-num_extra] + return frames, out + + def prep_frame(inp, fps_str): + with torch.no_grad(): + frame, preds = inp + return prep_display(preds, frame, None, None, undo_transform=False, class_color=True, fps_str=fps_str) + + frame_buffer = Queue() + video_fps = 0 + + # All this timing code to make sure that + def play_video(): + try: + nonlocal frame_buffer, running, video_fps, is_webcam, num_frames, frames_displayed, vid_done + + video_frame_times = MovingAverage(100) + frame_time_stabilizer = frame_time_target + last_time = None + stabilizer_step = 0.0005 + progress_bar = ProgressBar(30, num_frames) + + while running: + frame_time_start = time.time() + + if not frame_buffer.empty(): + next_time = time.time() + if last_time is not None: + video_frame_times.add(next_time - last_time) + video_fps = 1 / video_frame_times.get_avg() + if out_path is None: + cv2.imshow(path, frame_buffer.get()) + else: + out.write(frame_buffer.get()) + frames_displayed += 1 + last_time = next_time + + if out_path is not None: + if video_frame_times.get_avg() == 0: + fps = 0 + else: + fps = 1 / video_frame_times.get_avg() + progress = frames_displayed / num_frames * 100 + progress_bar.set_val(frames_displayed) + + print('\rProcessing Frames %s %6d / %6d (%5.2f%%) %5.2f fps ' + % (repr(progress_bar), frames_displayed, num_frames, progress, fps), end='') + + + # This is split because you don't want savevideo to require cv2 display functionality (see #197) + if out_path is None and cv2.waitKey(1) == 27: + # Press Escape to close + running = False + if not (frames_displayed < num_frames): + running = False + + if not vid_done: + buffer_size = frame_buffer.qsize() + if buffer_size < args.video_multiframe: + frame_time_stabilizer += stabilizer_step + elif buffer_size > args.video_multiframe: + frame_time_stabilizer -= stabilizer_step + if frame_time_stabilizer < 0: + frame_time_stabilizer = 0 + + new_target = frame_time_stabilizer if is_webcam else max(frame_time_stabilizer, frame_time_target) + else: + new_target = frame_time_target + + next_frame_target = max(2 * new_target - video_frame_times.get_avg(), 0) + target_time = frame_time_start + next_frame_target - 0.001 # Let's just subtract a millisecond to be safe + + if out_path is None or args.emulate_playback: + # This gives more accurate timing than if sleeping the whole amount at once + while time.time() < target_time: + time.sleep(0.001) + else: + # Let's not starve the main thread, now + time.sleep(0.001) + except: + # See issue #197 for why this is necessary + import traceback + traceback.print_exc() + + + extract_frame = lambda x, i: (x[0][i] if x[1][i]['detection'] is None else x[0][i].to(x[1][i]['detection']['box'].device), [x[1][i]]) + + # Prime the network on the first frame because I do some thread unsafe things otherwise + print('Initializing model... ', end='') + first_batch = eval_network(transform_frame(get_next_frame(vid))) + print('Done.') + + # For each frame the sequence of functions it needs to go through to be processed (in reversed order) + sequence = [prep_frame, eval_network, transform_frame] + pool = ThreadPool(processes=len(sequence) + args.video_multiframe + 2) + pool.apply_async(play_video) + active_frames = [{'value': extract_frame(first_batch, i), 'idx': 0} for i in range(len(first_batch[0]))] + + print() + if out_path is None: print('Press Escape to close.') + try: + while vid.isOpened() and running: + # Hard limit on frames in buffer so we don't run out of memory >.> + while frame_buffer.qsize() > 100: + time.sleep(0.001) + + start_time = time.time() + + # Start loading the next frames from the disk + if not vid_done: + next_frames = pool.apply_async(get_next_frame, args=(vid,)) + else: + next_frames = None + + if not (vid_done and len(active_frames) == 0): + # For each frame in our active processing queue, dispatch a job + # for that frame using the current function in the sequence + for frame in active_frames: + _args = [frame['value']] + if frame['idx'] == 0: + _args.append(fps_str) + frame['value'] = pool.apply_async(sequence[frame['idx']], args=_args) + + # For each frame whose job was the last in the sequence (i.e. for all final outputs) + for frame in active_frames: + if frame['idx'] == 0: + frame_buffer.put(frame['value'].get()) + + # Remove the finished frames from the processing queue + active_frames = [x for x in active_frames if x['idx'] > 0] + + # Finish evaluating every frame in the processing queue and advanced their position in the sequence + for frame in list(reversed(active_frames)): + frame['value'] = frame['value'].get() + frame['idx'] -= 1 + + if frame['idx'] == 0: + # Split this up into individual threads for prep_frame since it doesn't support batch size + active_frames += [{'value': extract_frame(frame['value'], i), 'idx': 0} for i in range(1, len(frame['value'][0]))] + frame['value'] = extract_frame(frame['value'], 0) + + # Finish loading in the next frames and add them to the processing queue + if next_frames is not None: + frames = next_frames.get() + if len(frames) == 0: + vid_done = True + else: + active_frames.append({'value': frames, 'idx': len(sequence)-1}) + + # Compute FPS + frame_times.add(time.time() - start_time) + fps = args.video_multiframe / frame_times.get_avg() + else: + fps = 0 + + fps_str = 'Processing FPS: %.2f | Video Playback FPS: %.2f | Frames in Buffer: %d' % (fps, video_fps, frame_buffer.qsize()) + if not args.display_fps: + print('\r' + fps_str + ' ', end='') + + except KeyboardInterrupt: + print('\nStopping...') + + cleanup_and_exit() + +def evaluate(net:Yolact, dataset, train_mode=False, trainCuda = True): + net.detect.use_fast_nms = args.fast_nms + net.detect.use_cross_class_nms = args.cross_class_nms + cfg.mask_proto_debug = args.mask_proto_debug + + # TODO Currently we do not support Fast Mask Re-scroing in evalimage, evalimages, and evalvideo + if args.image is not None: + if ':' in args.image: + inp, out = args.image.split(':') + evalimage(net, inp, out) + else: + evalimage(net, args.image) + return + elif args.images is not None: + inp, out = args.images.split(':') + evalimages(net, inp, out) + return + elif args.video is not None: + if ':' in args.video: + inp, out = args.video.split(':') + evalvideo(net, inp, out) + else: + evalvideo(net, args.video) + return + + frame_times = MovingAverage() + dataset_size = len(dataset) if args.max_images < 0 else min(args.max_images, len(dataset)) + progress_bar = ProgressBar(30, dataset_size) + + print() + + if not args.display and not args.benchmark: + # For each class and iou, stores tuples (score, isPositive) + # Index ap_data[type][iouIdx][classIdx] + ap_data = { + 'box' : [[APDataObject() for _ in cfg.dataset.class_names] for _ in iou_thresholds], + 'mask': [[APDataObject() for _ in cfg.dataset.class_names] for _ in iou_thresholds] + } + detections = Detections() + else: + timer.disable('Load Data') + + dataset_indices = list(range(len(dataset))) + + if args.shuffle: + random.shuffle(dataset_indices) + elif not args.no_sort: + # Do a deterministic shuffle based on the image ids + # + # I do this because on python 3.5 dictionary key order is *random*, while in 3.6 it's + # the order of insertion. That means on python 3.6, the images come in the order they are in + # in the annotations file. For some reason, the first images in the annotations file are + # the hardest. To combat this, I use a hard-coded hash function based on the image ids + # to shuffle the indices we use. That way, no matter what python version or how pycocotools + # handles the data, we get the same result every time. + hashed = [badhash(x) for x in dataset.ids] + dataset_indices.sort(key=lambda x: hashed[x]) + + dataset_indices = dataset_indices[:dataset_size] + + try: + # Main eval loop + for it, image_idx in enumerate(tqdm(dataset_indices)): + timer.reset() + + with timer.env('Load Data'): + img, gt, gt_masks, h, w, num_crowd = dataset.pull_item(image_idx) + # Test flag, do not upvote + if cfg.mask_proto_debug: + with open('scripts/info.txt', 'w') as f: + f.write(str(dataset.ids[image_idx])) + np.save('scripts/gt.npy', gt_masks) + + batch = Variable(img.unsqueeze(0)) + if args.cuda: + if train_mode: + batch = batch.npu() if trainCuda else batch + else: + batch = batch.npu() + + with timer.env('Network Extra'): + preds = net(batch) + if preds is not None and preds[0] is not None: + if preds[0]['box'] is not None: + preds[0]['box'] = preds[0]['box'].cpu() + if preds[0]['mask'] is not None: + preds[0]['mask'] = preds[0]['mask'].cpu() + if preds[0]['class'] is not None: + preds[0]['class'] = preds[0]['class'].cpu() + if preds[0]['score'] is not None: + preds[0]['score'] = preds[0]['score'].cpu() + if preds[0]['proto'] is not None: + preds[0]['proto'] = preds[0]['proto'].cpu() + + # Perform the meat of the operation here depending on our mode. + if args.display: + img_numpy = prep_display(preds, img, h, w) + elif args.benchmark: + prep_benchmark(preds, h, w) + else: + prep_metrics(ap_data, preds, img, gt, gt_masks, h, w, num_crowd, dataset.ids[image_idx], detections) + + # First couple of images take longer because we're constructing the graph. + # Since that's technically initialization, don't include those in the FPS calculations. + if it > 1: + frame_times.add(timer.total_time()) + + if args.display: + if it > 1: + print('Avg FPS: %.4f' % (1 / frame_times.get_avg())) + plt.imshow(img_numpy) + plt.title(str(dataset.ids[image_idx])) + plt.show() + elif not args.no_bar: + if it > 1: fps = 1 / frame_times.get_avg() + else: fps = 0 + progress = (it+1) / dataset_size * 100 + progress_bar.set_val(it+1) + print('\rProcessing Images %s %6d / %6d (%5.2f%%) %5.2f fps ' + % (repr(progress_bar), it+1, dataset_size, progress, fps), end='') + + + + if not args.display and not args.benchmark: + print() + if args.output_coco_json: + print('Dumping detections...') + if args.output_web_json: + detections.dump_web() + else: + detections.dump() + else: + if not train_mode: + print('Saving data...') + with open(args.ap_data_file, 'wb') as f: + pickle.dump(ap_data, f) + + return calc_map(ap_data) + elif args.benchmark: + print() + print() + print('Stats for the last frame:') + timer.print_stats() + avg_seconds = frame_times.get_avg() + print('Average: %5.2f fps, %5.2f ms' % (1 / frame_times.get_avg(), 1000*avg_seconds)) + + except KeyboardInterrupt: + print('Stopping...') + + +def calc_map(ap_data): + print('Calculating mAP...') + aps = [{'box': [], 'mask': []} for _ in iou_thresholds] + + for _class in range(len(cfg.dataset.class_names)): + for iou_idx in range(len(iou_thresholds)): + for iou_type in ('box', 'mask'): + ap_obj = ap_data[iou_type][iou_idx][_class] + + if not ap_obj.is_empty(): + aps[iou_idx][iou_type].append(ap_obj.get_ap()) + + all_maps = {'box': OrderedDict(), 'mask': OrderedDict()} + + # Looking back at it, this code is really hard to read :/ + for iou_type in ('box', 'mask'): + all_maps[iou_type]['all'] = 0 # Make this first in the ordereddict + for i, threshold in enumerate(iou_thresholds): + mAP = sum(aps[i][iou_type]) / len(aps[i][iou_type]) * 100 if len(aps[i][iou_type]) > 0 else 0 + all_maps[iou_type][int(threshold*100)] = mAP + all_maps[iou_type]['all'] = (sum(all_maps[iou_type].values()) / (len(all_maps[iou_type].values())-1)) + + print_maps(all_maps) + + # Put in a prettier format so we can serialize it to json during training + all_maps = {k: {j: round(u, 2) for j, u in v.items()} for k, v in all_maps.items()} + return all_maps + +def print_maps(all_maps): + # Warning: hacky + make_row = lambda vals: (' %5s |' * len(vals)) % tuple(vals) + make_sep = lambda n: ('-------+' * n) + + print() + print(make_row([''] + [('.%d ' % x if isinstance(x, int) else x + ' ') for x in all_maps['box'].keys()])) + print(make_sep(len(all_maps['box']) + 1)) + for iou_type in ('box', 'mask'): + print(make_row([iou_type] + ['%.2f' % x if x < 100 else '%.1f' % x for x in all_maps[iou_type].values()])) + print(make_sep(len(all_maps['box']) + 1)) + print() + + + +if __name__ == '__main__': + parse_args() + + if args.config is not None: + set_cfg(args.config) + + if args.trained_model == 'interrupt': + + args.trained_model = SavePath.get_interrupt('weights/') + elif args.trained_model == 'latest': + args.trained_model = SavePath.get_latest('weights/', cfg.name) + + if args.config is None: + model_path = SavePath.from_str(args.trained_model) + # TODO: Bad practice? Probably want to do a name lookup instead. + args.config = model_path.model_name + '_config' + print('Config not specified. Parsed %s from the file name.\n' % args.config) + set_cfg(args.config) + + if args.detect: + cfg.eval_mask_branch = False + + if args.dataset is not None: + set_dataset(args.dataset) + + if args.data_path: + cfg.dataset.valid_images = args.data_path + '/images/' + cfg.dataset.valid_info = args.data_path + '/annotations/instances_val2017.json' + + with torch.no_grad(): + if not os.path.exists('results'): + os.makedirs('results') + + if args.cuda: + cudnn.fastest = True + args.device = torch.device(f'npu:{args.rank_id}') + torch.npu.set_device(args.device) + #torch.set_default_tensor_type('torch.npu.FloatTensor') + else: + torch.set_default_tensor_type('torch.FloatTensor') + + if args.resume and not args.display: + with open(args.ap_data_file, 'rb') as f: + ap_data = pickle.load(f) + calc_map(ap_data) + exit() + + if args.image is None and args.video is None and args.images is None: + dataset = COCODetection(cfg.dataset.valid_images, cfg.dataset.valid_info, + transform=BaseTransform(), has_gt=cfg.dataset.has_gt) + prep_coco_cats() + else: + dataset = None + + print('Loading model...', end='') + net = Yolact() + net.load_weights(args.trained_model) + net.eval() + print(' Done.') + + if args.cuda: + net = net.npu() + + evaluate(net, dataset) + + diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/__init__.py b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/__init__.py index 59dfcbd639b692434275a446f1081315497fa99e..53a3f4b5160995d93bc7911e808b3045d74362c9 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/__init__.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/__init__.py @@ -1,2 +1,2 @@ -from .functions import * -from .modules import * +from .functions import * +from .modules import * diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/box_utils.py b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/box_utils.py index 6f84f55ab056f2d402bb4dc6eb2bb16975e80a35..7114b7b120806d342148939e2e6b8ecd6bd65740 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/box_utils.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/box_utils.py @@ -1,403 +1,403 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -# -*- coding: utf-8 -*- -import torch -from utils import timer - -from data import cfg - -@torch.jit.script -def point_form(boxes): - """ Convert prior_boxes to (xmin, ymin, xmax, ymax) - representation for comparison to point form ground truth data. - Args: - boxes: (tensor) center-size default boxes from priorbox layers. - Return: - boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes. - """ - return torch.cat((boxes[:, :2] - boxes[:, 2:]/2, # xmin, ymin - boxes[:, :2] + boxes[:, 2:]/2), 1) # xmax, ymax - - -@torch.jit.script -def center_size(boxes): - """ Convert prior_boxes to (cx, cy, w, h) - representation for comparison to center-size form ground truth data. - Args: - boxes: (tensor) point_form boxes - Return: - boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes. - """ - return torch.cat(( (boxes[:, 2:] + boxes[:, :2])/2, # cx, cy - boxes[:, 2:] - boxes[:, :2] ), 1) # w, h - -@torch.jit.script -def intersect(box_a, box_b): - """ We resize both tensors to [A,B,2] without new malloc: - [A,2] -> [A,1,2] -> [A,B,2] - [B,2] -> [1,B,2] -> [A,B,2] - Then we compute the area of intersect between box_a and box_b. - Args: - box_a: (tensor) bounding boxes, Shape: [n,A,4]. - box_b: (tensor) bounding boxes, Shape: [n,B,4]. - Return: - (tensor) intersection area, Shape: [n,A,B]. - """ - n = box_a.size(0) - A = box_a.size(1) - B = box_b.size(1) - max_xy = torch.min(box_a[:, :, 2:].unsqueeze(2).expand(n, A, B, 2), - box_b[:, :, 2:].unsqueeze(1).expand(n, A, B, 2)) - min_xy = torch.max(box_a[:, :, :2].unsqueeze(2).expand(n, A, B, 2), - box_b[:, :, :2].unsqueeze(1).expand(n, A, B, 2)) - return torch.clamp(max_xy - min_xy, min=0).prod(3) # inter - - -def jaccard(box_a, box_b, iscrowd:bool=False): - """Compute the jaccard overlap of two sets of boxes. The jaccard overlap - is simply the intersection over union of two boxes. Here we operate on - ground truth boxes and default boxes. If iscrowd=True, put the crowd in box_b. - E.g.: - A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) - Args: - box_a: (tensor) Ground truth bounding boxes, Shape: [num_objects,4] - box_b: (tensor) Prior boxes from priorbox layers, Shape: [num_priors,4] - Return: - jaccard overlap: (tensor) Shape: [box_a.size(0), box_b.size(0)] - """ - use_batch = True - if box_a.dim() == 2: - use_batch = False - box_a = box_a[None, ...] - box_b = box_b[None, ...] - - inter = intersect(box_a, box_b) - area_a = ((box_a[:, :, 2]-box_a[:, :, 0]) * - (box_a[:, :, 3]-box_a[:, :, 1])).unsqueeze(2).expand_as(inter) # [A,B] - area_b = ((box_b[:, :, 2]-box_b[:, :, 0]) * - (box_b[:, :, 3]-box_b[:, :, 1])).unsqueeze(1).expand_as(inter) # [A,B] - union = area_a + area_b - inter - - out = inter / area_a if iscrowd else inter / union - return out if use_batch else out.squeeze(0) - -def elemwise_box_iou(box_a, box_b): - """ Does the same as above but instead of pairwise, elementwise along the inner dimension. """ - max_xy = torch.min(box_a[:, 2:], box_b[:, 2:]) - min_xy = torch.max(box_a[:, :2], box_b[:, :2]) - inter = torch.clamp((max_xy - min_xy), min=0) - inter = inter[:, 0] * inter[:, 1] - - area_a = (box_a[:, 2] - box_a[:, 0]) * (box_a[:, 3] - box_a[:, 1]) - area_b = (box_b[:, 2] - box_b[:, 0]) * (box_b[:, 3] - box_b[:, 1]) - - union = area_a + area_b - inter - union = torch.clamp(union, min=0.1) - - # Return value is [n] for inputs [n, 4] - return torch.clamp(inter / union, max=1) - -def mask_iou(masks_a, masks_b, iscrowd=False): - """ - Computes the pariwise mask IoU between two sets of masks of size [a, h, w] and [b, h, w]. - The output is of size [a, b]. - - Wait I thought this was "box_utils", why am I putting this in here? - """ - - masks_a = masks_a.view(masks_a.size(0), -1) - masks_b = masks_b.view(masks_b.size(0), -1) - - intersection = masks_a @ masks_b.t() - area_a = masks_a.sum(dim=1).unsqueeze(1) - area_b = masks_b.sum(dim=1).unsqueeze(0) - - return intersection / (area_a + area_b - intersection) if not iscrowd else intersection / area_a - -def elemwise_mask_iou(masks_a, masks_b): - """ Does the same as above but instead of pairwise, elementwise along the outer dimension. """ - masks_a = masks_a.view(-1, masks_a.size(-1)) - masks_b = masks_b.view(-1, masks_b.size(-1)) - - intersection = (masks_a * masks_b).sum(dim=0) - area_a = masks_a.sum(dim=0) - area_b = masks_b.sum(dim=0) - - # Return value is [n] for inputs [h, w, n] - return torch.clamp(intersection / torch.clamp(area_a + area_b - intersection, min=0.1), max=1) - - - -def change(gt, priors): - """ - Compute the d_change metric proposed in Box2Pix: - https://lmb.informatik.uni-freiburg.de/Publications/2018/UB18/paper-box2pix.pdf - - Input should be in point form (xmin, ymin, xmax, ymax). - - Output is of shape [num_gt, num_priors] - Note this returns -change so it can be a drop in replacement for - """ - num_priors = priors.size(0) - num_gt = gt.size(0) - - gt_w = (gt[:, 2] - gt[:, 0])[:, None].expand(num_gt, num_priors) - gt_h = (gt[:, 3] - gt[:, 1])[:, None].expand(num_gt, num_priors) - - gt_mat = gt[:, None, :].expand(num_gt, num_priors, 4) - pr_mat = priors[None, :, :].expand(num_gt, num_priors, 4) - - diff = gt_mat - pr_mat - diff[:, :, 0] /= gt_w - diff[:, :, 2] /= gt_w - diff[:, :, 1] /= gt_h - diff[:, :, 3] /= gt_h - - return -torch.sqrt( (diff ** 2).sum(dim=2) ) - - - - -def match(pos_thresh, neg_thresh, truths, priors, labels, crowd_boxes, loc_t, conf_t, idx_t, idx, loc_data): - """Match each prior box with the ground truth box of the highest jaccard - overlap, encode the bounding boxes, then return the matched indices - corresponding to both confidence and location preds. - Args: - pos_thresh: (float) IoU > pos_thresh ==> positive. - neg_thresh: (float) IoU < neg_thresh ==> negative. - truths: (tensor) Ground truth boxes, Shape: [num_obj, num_priors]. - priors: (tensor) Prior boxes from priorbox layers, Shape: [n_priors,4]. - labels: (tensor) All the class labels for the image, Shape: [num_obj]. - crowd_boxes: (tensor) All the crowd box annotations or None if there are none. - loc_t: (tensor) Tensor to be filled w/ endcoded location targets. - conf_t: (tensor) Tensor to be filled w/ matched indices for conf preds. Note: -1 means neutral. - idx_t: (tensor) Tensor to be filled w/ the index of the matched gt box for each prior. - idx: (int) current batch index. - loc_data: (tensor) The predicted bbox regression coordinates for this batch. - Return: - The matched indices corresponding to 1)location and 2)confidence preds. - """ - decoded_priors = decode(loc_data, priors, cfg.use_yolo_regressors) if cfg.use_prediction_matching else point_form(priors) - - # Size [num_objects, num_priors] - overlaps = jaccard(truths, decoded_priors) if not cfg.use_change_matching else change(truths, decoded_priors) - - # Size [num_priors] best ground truth for each prior - best_truth_overlap, best_truth_idx = overlaps.max(0) - - # We want to ensure that each gt gets used at least once so that we don't - # waste any training data. In order to do that, find the max overlap anchor - # with each gt, and force that anchor to use that gt. - for _ in range(overlaps.size(0)): - # Find j, the gt with the highest overlap with a prior - # In effect, this will loop through overlaps.size(0) in a "smart" order, - # always choosing the highest overlap first. - best_prior_overlap, best_prior_idx = overlaps.max(1) - j = best_prior_overlap.max(0)[1] - - # Find i, the highest overlap anchor with this gt - i = best_prior_idx[j] - - # Set all other overlaps with i to be -1 so that no other gt uses it - overlaps[:, i] = -1 - # Set all other overlaps with j to be -1 so that this loop never uses j again - overlaps[j, :] = -1 - - # Overwrite i's score to be 2 so it doesn't get thresholded ever - best_truth_overlap[i] = 2 - # Set the gt to be used for i to be j, overwriting whatever was there - best_truth_idx[i] = j - - matches = truths[best_truth_idx] # Shape: [num_priors,4] - conf = labels[best_truth_idx] + 1 # Shape: [num_priors] - - conf[best_truth_overlap < pos_thresh] = -1 # label as neutral - conf[best_truth_overlap < neg_thresh] = 0 # label as background - - # Deal with crowd annotations for COCO - if crowd_boxes is not None and cfg.crowd_iou_threshold < 1: - # Size [num_priors, num_crowds] - crowd_overlaps = jaccard(decoded_priors, crowd_boxes, iscrowd=True) - # Size [num_priors] - best_crowd_overlap, best_crowd_idx = crowd_overlaps.max(1) - # Set non-positives with crowd iou of over the threshold to be neutral. - conf[(conf <= 0) & (best_crowd_overlap > cfg.crowd_iou_threshold)] = -1 - - loc = encode(matches, priors, cfg.use_yolo_regressors) - loc_t[idx] = loc # [num_priors,4] encoded offsets to learn - conf_t[idx] = conf # [num_priors] top class label for each prior - idx_t[idx] = best_truth_idx # [num_priors] indices for lookup - -@torch.jit.script -def encode(matched, priors, use_yolo_regressors:bool=False): - """ - Encode bboxes matched with each prior into the format - produced by the network. See decode for more details on - this format. Note that encode(decode(x, p), p) = x. - - Args: - - matched: A tensor of bboxes in point form with shape [num_priors, 4] - - priors: The tensor of all priors with shape [num_priors, 4] - Return: A tensor with encoded relative coordinates in the format - outputted by the network (see decode). Size: [num_priors, 4] - """ - - if use_yolo_regressors: - # Exactly the reverse of what we did in decode - # In fact encode(decode(x, p), p) should be x - boxes = center_size(matched) - - loc = torch.cat(( - boxes[:, :2] - priors[:, :2], - torch.log(boxes[:, 2:] / priors[:, 2:]) - ), 1) - else: - variances = [0.1, 0.2] - - # dist b/t match center and prior's center - g_cxcy = (matched[:, :2] + matched[:, 2:])/2 - priors[:, :2] - # encode variance - g_cxcy /= (variances[0] * priors[:, 2:]) - # match wh / prior wh - g_wh = (matched[:, 2:] - matched[:, :2]) / priors[:, 2:] - g_wh = torch.log(g_wh) / variances[1] - # return target for smooth_l1_loss - loc = torch.cat([g_cxcy, g_wh], 1) # [num_priors,4] - - return loc - -@torch.jit.script -def decode(loc, priors, use_yolo_regressors:bool=False): - """ - Decode predicted bbox coordinates using the same scheme - employed by Yolov2: https://arxiv.org/pdf/1612.08242.pdf - - b_x = (sigmoid(pred_x) - .5) / conv_w + prior_x - b_y = (sigmoid(pred_y) - .5) / conv_h + prior_y - b_w = prior_w * exp(loc_w) - b_h = prior_h * exp(loc_h) - - Note that loc is inputed as [(s(x)-.5)/conv_w, (s(y)-.5)/conv_h, w, h] - while priors are inputed as [x, y, w, h] where each coordinate - is relative to size of the image (even sigmoid(x)). We do this - in the network by dividing by the 'cell size', which is just - the size of the convouts. - - Also note that prior_x and prior_y are center coordinates which - is why we have to subtract .5 from sigmoid(pred_x and pred_y). - - Args: - - loc: The predicted bounding boxes of size [num_priors, 4] - - priors: The priorbox coords with size [num_priors, 4] - - Returns: A tensor of decoded relative coordinates in point form - form with size [num_priors, 4] - """ - - if use_yolo_regressors: - # Decoded boxes in center-size notation - boxes = torch.cat(( - loc[:, :2] + priors[:, :2], - priors[:, 2:] * torch.exp(loc[:, 2:]) - ), 1) - - boxes = point_form(boxes) - else: - variances = [0.1, 0.2] - - boxes = torch.cat(( - priors[:, :2] + loc[:, :2] * variances[0] * priors[:, 2:], - priors[:, 2:] * torch.exp(loc[:, 2:] * variances[1])), 1) - boxes[:, :2] -= boxes[:, 2:] / 2 - boxes[:, 2:] += boxes[:, :2] - - return boxes - - - -def log_sum_exp(x): - """Utility function for computing log_sum_exp while determining - This will be used to determine unaveraged confidence loss across - all examples in a batch. - Args: - x (Variable(tensor)): conf_preds from conf layers - """ - x_max = x.data.max() - return torch.log(torch.sum(torch.exp(x-x_max), 1)) + x_max - - -@torch.jit.script -def sanitize_coordinates(_x1, _x2, img_size:int, padding:int=0, cast:bool=True): - """ - Sanitizes the input coordinates so that x1 < x2, x1 != x2, x1 >= 0, and x2 <= image_size. - Also converts from relative to absolute coordinates and casts the results to long tensors. - - If cast is false, the result won't be cast to longs. - Warning: this does things in-place behind the scenes so copy if necessary. - """ - _x1 = _x1 * img_size - _x2 = _x2 * img_size - if cast: - _x1 = _x1.long() - _x2 = _x2.long() - x1 = torch.min(_x1, _x2) - x2 = torch.max(_x1, _x2) - x1 = torch.clamp(x1-padding, min=0) - x2 = torch.clamp(x2+padding, max=img_size) - - return x1, x2 - - -@torch.jit.script -def crop(masks, boxes, padding:int=1): - """ - "Crop" predicted masks by zeroing out everything not in the predicted bbox. - Vectorized by Chong (thanks Chong). - - Args: - - masks should be a size [h, w, n] tensor of masks - - boxes should be a size [n, 4] tensor of bbox coords in relative point form - """ - h, w, n = masks.size() - x1, x2 = sanitize_coordinates(boxes[:, 0], boxes[:, 2], w, padding, cast=False) - y1, y2 = sanitize_coordinates(boxes[:, 1], boxes[:, 3], h, padding, cast=False) - - rows = torch.arange(w, device=masks.device, dtype=x1.dtype).view(1, -1, 1).expand(h, w, n) - cols = torch.arange(h, device=masks.device, dtype=x1.dtype).view(-1, 1, 1).expand(h, w, n) - - masks_left = rows >= x1.view(1, 1, -1) - masks_right = rows < x2.view(1, 1, -1) - masks_up = cols >= y1.view(1, 1, -1) - masks_down = cols < y2.view(1, 1, -1) - - crop_mask = masks_left * masks_right * masks_up * masks_down - - return masks * crop_mask.float() - - -def index2d(src, idx): - """ - Indexes a tensor by a 2d index. - - In effect, this does - out[i, j] = src[i, idx[i, j]] - - Both src and idx should have the same size. - """ - - offs = torch.arange(idx.size(0), device=idx.device)[:, None].expand_as(idx) - idx = idx + offs * idx.size(1) - - return src.view(-1)[idx.view(-1)].view(idx.size()) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# -*- coding: utf-8 -*- +import torch +from utils import timer + +from data import cfg + +@torch.jit.script +def point_form(boxes): + """ Convert prior_boxes to (xmin, ymin, xmax, ymax) + representation for comparison to point form ground truth data. + Args: + boxes: (tensor) center-size default boxes from priorbox layers. + Return: + boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes. + """ + return torch.cat((boxes[:, :2] - boxes[:, 2:]/2, # xmin, ymin + boxes[:, :2] + boxes[:, 2:]/2), 1) # xmax, ymax + + +@torch.jit.script +def center_size(boxes): + """ Convert prior_boxes to (cx, cy, w, h) + representation for comparison to center-size form ground truth data. + Args: + boxes: (tensor) point_form boxes + Return: + boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes. + """ + return torch.cat(( (boxes[:, 2:] + boxes[:, :2])/2, # cx, cy + boxes[:, 2:] - boxes[:, :2] ), 1) # w, h + +@torch.jit.script +def intersect(box_a, box_b): + """ We resize both tensors to [A,B,2] without new malloc: + [A,2] -> [A,1,2] -> [A,B,2] + [B,2] -> [1,B,2] -> [A,B,2] + Then we compute the area of intersect between box_a and box_b. + Args: + box_a: (tensor) bounding boxes, Shape: [n,A,4]. + box_b: (tensor) bounding boxes, Shape: [n,B,4]. + Return: + (tensor) intersection area, Shape: [n,A,B]. + """ + n = box_a.size(0) + A = box_a.size(1) + B = box_b.size(1) + max_xy = torch.min(box_a[:, :, 2:].unsqueeze(2).expand(n, A, B, 2), + box_b[:, :, 2:].unsqueeze(1).expand(n, A, B, 2)) + min_xy = torch.max(box_a[:, :, :2].unsqueeze(2).expand(n, A, B, 2), + box_b[:, :, :2].unsqueeze(1).expand(n, A, B, 2)) + return torch.clamp(max_xy - min_xy, min=0).prod(3) # inter + + +def jaccard(box_a, box_b, iscrowd:bool=False): + """Compute the jaccard overlap of two sets of boxes. The jaccard overlap + is simply the intersection over union of two boxes. Here we operate on + ground truth boxes and default boxes. If iscrowd=True, put the crowd in box_b. + E.g.: + A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) + Args: + box_a: (tensor) Ground truth bounding boxes, Shape: [num_objects,4] + box_b: (tensor) Prior boxes from priorbox layers, Shape: [num_priors,4] + Return: + jaccard overlap: (tensor) Shape: [box_a.size(0), box_b.size(0)] + """ + use_batch = True + if box_a.dim() == 2: + use_batch = False + box_a = box_a[None, ...] + box_b = box_b[None, ...] + + inter = intersect(box_a, box_b) + area_a = ((box_a[:, :, 2]-box_a[:, :, 0]) * + (box_a[:, :, 3]-box_a[:, :, 1])).unsqueeze(2).expand_as(inter) # [A,B] + area_b = ((box_b[:, :, 2]-box_b[:, :, 0]) * + (box_b[:, :, 3]-box_b[:, :, 1])).unsqueeze(1).expand_as(inter) # [A,B] + union = area_a + area_b - inter + + out = inter / area_a if iscrowd else inter / union + return out if use_batch else out.squeeze(0) + +def elemwise_box_iou(box_a, box_b): + """ Does the same as above but instead of pairwise, elementwise along the inner dimension. """ + max_xy = torch.min(box_a[:, 2:], box_b[:, 2:]) + min_xy = torch.max(box_a[:, :2], box_b[:, :2]) + inter = torch.clamp((max_xy - min_xy), min=0) + inter = inter[:, 0] * inter[:, 1] + + area_a = (box_a[:, 2] - box_a[:, 0]) * (box_a[:, 3] - box_a[:, 1]) + area_b = (box_b[:, 2] - box_b[:, 0]) * (box_b[:, 3] - box_b[:, 1]) + + union = area_a + area_b - inter + union = torch.clamp(union, min=0.1) + + # Return value is [n] for inputs [n, 4] + return torch.clamp(inter / union, max=1) + +def mask_iou(masks_a, masks_b, iscrowd=False): + """ + Computes the pariwise mask IoU between two sets of masks of size [a, h, w] and [b, h, w]. + The output is of size [a, b]. + + Wait I thought this was "box_utils", why am I putting this in here? + """ + + masks_a = masks_a.view(masks_a.size(0), -1) + masks_b = masks_b.view(masks_b.size(0), -1) + + intersection = masks_a @ masks_b.t() + area_a = masks_a.sum(dim=1).unsqueeze(1) + area_b = masks_b.sum(dim=1).unsqueeze(0) + + return intersection / (area_a + area_b - intersection) if not iscrowd else intersection / area_a + +def elemwise_mask_iou(masks_a, masks_b): + """ Does the same as above but instead of pairwise, elementwise along the outer dimension. """ + masks_a = masks_a.view(-1, masks_a.size(-1)) + masks_b = masks_b.view(-1, masks_b.size(-1)) + + intersection = (masks_a * masks_b).sum(dim=0) + area_a = masks_a.sum(dim=0) + area_b = masks_b.sum(dim=0) + + # Return value is [n] for inputs [h, w, n] + return torch.clamp(intersection / torch.clamp(area_a + area_b - intersection, min=0.1), max=1) + + + +def change(gt, priors): + """ + Compute the d_change metric proposed in Box2Pix: + https://lmb.informatik.uni-freiburg.de/Publications/2018/UB18/paper-box2pix.pdf + + Input should be in point form (xmin, ymin, xmax, ymax). + + Output is of shape [num_gt, num_priors] + Note this returns -change so it can be a drop in replacement for + """ + num_priors = priors.size(0) + num_gt = gt.size(0) + + gt_w = (gt[:, 2] - gt[:, 0])[:, None].expand(num_gt, num_priors) + gt_h = (gt[:, 3] - gt[:, 1])[:, None].expand(num_gt, num_priors) + + gt_mat = gt[:, None, :].expand(num_gt, num_priors, 4) + pr_mat = priors[None, :, :].expand(num_gt, num_priors, 4) + + diff = gt_mat - pr_mat + diff[:, :, 0] /= gt_w + diff[:, :, 2] /= gt_w + diff[:, :, 1] /= gt_h + diff[:, :, 3] /= gt_h + + return -torch.sqrt( (diff ** 2).sum(dim=2) ) + + + + +def match(pos_thresh, neg_thresh, truths, priors, labels, crowd_boxes, loc_t, conf_t, idx_t, idx, loc_data): + """Match each prior box with the ground truth box of the highest jaccard + overlap, encode the bounding boxes, then return the matched indices + corresponding to both confidence and location preds. + Args: + pos_thresh: (float) IoU > pos_thresh ==> positive. + neg_thresh: (float) IoU < neg_thresh ==> negative. + truths: (tensor) Ground truth boxes, Shape: [num_obj, num_priors]. + priors: (tensor) Prior boxes from priorbox layers, Shape: [n_priors,4]. + labels: (tensor) All the class labels for the image, Shape: [num_obj]. + crowd_boxes: (tensor) All the crowd box annotations or None if there are none. + loc_t: (tensor) Tensor to be filled w/ endcoded location targets. + conf_t: (tensor) Tensor to be filled w/ matched indices for conf preds. Note: -1 means neutral. + idx_t: (tensor) Tensor to be filled w/ the index of the matched gt box for each prior. + idx: (int) current batch index. + loc_data: (tensor) The predicted bbox regression coordinates for this batch. + Return: + The matched indices corresponding to 1)location and 2)confidence preds. + """ + decoded_priors = decode(loc_data, priors, cfg.use_yolo_regressors) if cfg.use_prediction_matching else point_form(priors) + + # Size [num_objects, num_priors] + overlaps = jaccard(truths, decoded_priors) if not cfg.use_change_matching else change(truths, decoded_priors) + + # Size [num_priors] best ground truth for each prior + best_truth_overlap, best_truth_idx = overlaps.max(0) + + # We want to ensure that each gt gets used at least once so that we don't + # waste any training data. In order to do that, find the max overlap anchor + # with each gt, and force that anchor to use that gt. + for _ in range(overlaps.size(0)): + # Find j, the gt with the highest overlap with a prior + # In effect, this will loop through overlaps.size(0) in a "smart" order, + # always choosing the highest overlap first. + best_prior_overlap, best_prior_idx = overlaps.max(1) + j = best_prior_overlap.max(0)[1] + + # Find i, the highest overlap anchor with this gt + i = best_prior_idx[j] + + # Set all other overlaps with i to be -1 so that no other gt uses it + overlaps[:, i] = -1 + # Set all other overlaps with j to be -1 so that this loop never uses j again + overlaps[j, :] = -1 + + # Overwrite i's score to be 2 so it doesn't get thresholded ever + best_truth_overlap[i] = 2 + # Set the gt to be used for i to be j, overwriting whatever was there + best_truth_idx[i] = j + + matches = truths[best_truth_idx] # Shape: [num_priors,4] + conf = labels[best_truth_idx] + 1 # Shape: [num_priors] + + conf[best_truth_overlap < pos_thresh] = -1 # label as neutral + conf[best_truth_overlap < neg_thresh] = 0 # label as background + + # Deal with crowd annotations for COCO + if crowd_boxes is not None and cfg.crowd_iou_threshold < 1: + # Size [num_priors, num_crowds] + crowd_overlaps = jaccard(decoded_priors, crowd_boxes, iscrowd=True) + # Size [num_priors] + best_crowd_overlap, best_crowd_idx = crowd_overlaps.max(1) + # Set non-positives with crowd iou of over the threshold to be neutral. + conf[(conf <= 0) & (best_crowd_overlap > cfg.crowd_iou_threshold)] = -1 + + loc = encode(matches, priors, cfg.use_yolo_regressors) + loc_t[idx] = loc # [num_priors,4] encoded offsets to learn + conf_t[idx] = conf # [num_priors] top class label for each prior + idx_t[idx] = best_truth_idx # [num_priors] indices for lookup + +@torch.jit.script +def encode(matched, priors, use_yolo_regressors:bool=False): + """ + Encode bboxes matched with each prior into the format + produced by the network. See decode for more details on + this format. Note that encode(decode(x, p), p) = x. + + Args: + - matched: A tensor of bboxes in point form with shape [num_priors, 4] + - priors: The tensor of all priors with shape [num_priors, 4] + Return: A tensor with encoded relative coordinates in the format + outputted by the network (see decode). Size: [num_priors, 4] + """ + + if use_yolo_regressors: + # Exactly the reverse of what we did in decode + # In fact encode(decode(x, p), p) should be x + boxes = center_size(matched) + + loc = torch.cat(( + boxes[:, :2] - priors[:, :2], + torch.log(boxes[:, 2:] / priors[:, 2:]) + ), 1) + else: + variances = [0.1, 0.2] + + # dist b/t match center and prior's center + g_cxcy = (matched[:, :2] + matched[:, 2:])/2 - priors[:, :2] + # encode variance + g_cxcy /= (variances[0] * priors[:, 2:]) + # match wh / prior wh + g_wh = (matched[:, 2:] - matched[:, :2]) / priors[:, 2:] + g_wh = torch.log(g_wh) / variances[1] + # return target for smooth_l1_loss + loc = torch.cat([g_cxcy, g_wh], 1) # [num_priors,4] + + return loc + +@torch.jit.script +def decode(loc, priors, use_yolo_regressors:bool=False): + """ + Decode predicted bbox coordinates using the same scheme + employed by Yolov2: https://arxiv.org/pdf/1612.08242.pdf + + b_x = (sigmoid(pred_x) - .5) / conv_w + prior_x + b_y = (sigmoid(pred_y) - .5) / conv_h + prior_y + b_w = prior_w * exp(loc_w) + b_h = prior_h * exp(loc_h) + + Note that loc is inputed as [(s(x)-.5)/conv_w, (s(y)-.5)/conv_h, w, h] + while priors are inputed as [x, y, w, h] where each coordinate + is relative to size of the image (even sigmoid(x)). We do this + in the network by dividing by the 'cell size', which is just + the size of the convouts. + + Also note that prior_x and prior_y are center coordinates which + is why we have to subtract .5 from sigmoid(pred_x and pred_y). + + Args: + - loc: The predicted bounding boxes of size [num_priors, 4] + - priors: The priorbox coords with size [num_priors, 4] + + Returns: A tensor of decoded relative coordinates in point form + form with size [num_priors, 4] + """ + + if use_yolo_regressors: + # Decoded boxes in center-size notation + boxes = torch.cat(( + loc[:, :2] + priors[:, :2], + priors[:, 2:] * torch.exp(loc[:, 2:]) + ), 1) + + boxes = point_form(boxes) + else: + variances = [0.1, 0.2] + + boxes = torch.cat(( + priors[:, :2] + loc[:, :2] * variances[0] * priors[:, 2:], + priors[:, 2:] * torch.exp(loc[:, 2:] * variances[1])), 1) + boxes[:, :2] -= boxes[:, 2:] / 2 + boxes[:, 2:] += boxes[:, :2] + + return boxes + + + +def log_sum_exp(x): + """Utility function for computing log_sum_exp while determining + This will be used to determine unaveraged confidence loss across + all examples in a batch. + Args: + x (Variable(tensor)): conf_preds from conf layers + """ + x_max = x.data.max() + return torch.log(torch.sum(torch.exp(x-x_max), 1)) + x_max + + +@torch.jit.script +def sanitize_coordinates(_x1, _x2, img_size:int, padding:int=0, cast:bool=True): + """ + Sanitizes the input coordinates so that x1 < x2, x1 != x2, x1 >= 0, and x2 <= image_size. + Also converts from relative to absolute coordinates and casts the results to long tensors. + + If cast is false, the result won't be cast to longs. + Warning: this does things in-place behind the scenes so copy if necessary. + """ + _x1 = _x1 * img_size + _x2 = _x2 * img_size + if cast: + _x1 = _x1.long() + _x2 = _x2.long() + x1 = torch.min(_x1, _x2) + x2 = torch.max(_x1, _x2) + x1 = torch.clamp(x1-padding, min=0) + x2 = torch.clamp(x2+padding, max=img_size) + + return x1, x2 + + +@torch.jit.script +def crop(masks, boxes, padding:int=1): + """ + "Crop" predicted masks by zeroing out everything not in the predicted bbox. + Vectorized by Chong (thanks Chong). + + Args: + - masks should be a size [h, w, n] tensor of masks + - boxes should be a size [n, 4] tensor of bbox coords in relative point form + """ + h, w, n = masks.size() + x1, x2 = sanitize_coordinates(boxes[:, 0], boxes[:, 2], w, padding, cast=False) + y1, y2 = sanitize_coordinates(boxes[:, 1], boxes[:, 3], h, padding, cast=False) + + rows = torch.arange(w, device=masks.device, dtype=x1.dtype).view(1, -1, 1).expand(h, w, n) + cols = torch.arange(h, device=masks.device, dtype=x1.dtype).view(-1, 1, 1).expand(h, w, n) + + masks_left = rows >= x1.view(1, 1, -1) + masks_right = rows < x2.view(1, 1, -1) + masks_up = cols >= y1.view(1, 1, -1) + masks_down = cols < y2.view(1, 1, -1) + + crop_mask = masks_left * masks_right * masks_up * masks_down + + return masks * crop_mask.float() + + +def index2d(src, idx): + """ + Indexes a tensor by a 2d index. + + In effect, this does + out[i, j] = src[i, idx[i, j]] + + Both src and idx should have the same size. + """ + + offs = torch.arange(idx.size(0), device=idx.device)[:, None].expand_as(idx) + idx = idx + offs * idx.size(1) + + return src.view(-1)[idx.view(-1)].view(idx.size()) diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/functions/__init__.py b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/functions/__init__.py index d370fa2fea2b086c018856f60040a8457f6b1b97..56ef07f464ffa8a96de17e3a4f6bf512a5018865 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/functions/__init__.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/functions/__init__.py @@ -1,4 +1,4 @@ -from .detection import Detect - - -__all__ = ['Detect'] +from .detection import Detect + + +__all__ = ['Detect'] diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/functions/detection.py b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/functions/detection.py index c1fbea9366897a8d0b7ef71d63b1ad1ecf688f33..277684228e94293cf27a4e127008a07827a2dc9c 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/functions/detection.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/functions/detection.py @@ -1,242 +1,242 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch -import torch.nn.functional as F -from ..box_utils import decode, jaccard, index2d -from utils import timer - -from data import cfg, mask_type - -import numpy as np - - -class Detect(object): - """At test time, Detect is the final layer of SSD. Decode location preds, - apply non-maximum suppression to location predictions based on conf - scores and threshold to a top_k number of output predictions for both - confidence score and locations, as the predicted masks. - """ - # TODO: Refactor this whole class away. It needs to go. - - def __init__(self, num_classes, bkg_label, top_k, conf_thresh, nms_thresh): - self.num_classes = num_classes - self.background_label = bkg_label - self.top_k = top_k - # Parameters used in nms. - self.nms_thresh = nms_thresh - if nms_thresh <= 0: - raise ValueError('nms_threshold must be non negative.') - self.conf_thresh = conf_thresh - - self.use_cross_class_nms = False - self.use_fast_nms = False - - def __call__(self, predictions): - """ - Args: - loc_data: (tensor) Loc preds from loc layers - Shape: [batch, num_priors, 4] - conf_data: (tensor) Shape: Conf preds from conf layers - Shape: [batch, num_priors, num_classes] - mask_data: (tensor) Mask preds from mask layers - Shape: [batch, num_priors, mask_dim] - prior_data: (tensor) Prior boxes and variances from priorbox layers - Shape: [num_priors, 4] - proto_data: (tensor) If using mask_type.lincomb, the prototype masks - Shape: [batch, mask_h, mask_w, mask_dim] - - Returns: - output of shape (batch_size, top_k, 1 + 1 + 4 + mask_dim) - These outputs are in the order: class idx, confidence, bbox coords, and mask. - - Note that the outputs are sorted only if cross_class_nms is False - """ - - loc_data = predictions['loc'] - conf_data = predictions['conf'] - mask_data = predictions['mask'] - prior_data = predictions['priors'] - - proto_data = predictions['proto'] if 'proto' in predictions else None - inst_data = predictions['inst'] if 'inst' in predictions else None - - out = [] - - with timer.env('Detect'): - batch_size = loc_data.size(0) - num_priors = prior_data.size(0) - - conf_preds = conf_data.view(batch_size, num_priors, self.num_classes).transpose(2, 1).contiguous() - - for batch_idx in range(batch_size): - decoded_boxes = decode(loc_data[batch_idx], prior_data) - result = self.detect(batch_idx, conf_preds, decoded_boxes, mask_data, inst_data) - - if result is not None and proto_data is not None: - result['proto'] = proto_data[batch_idx] - - out.append(result) - - return out - - - def detect(self, batch_idx, conf_preds, decoded_boxes, mask_data, inst_data): - """ Perform nms for only the max scoring class that isn't background (class 0) """ - cur_scores = conf_preds[batch_idx, 1:, :] - conf_scores, _ = torch.max(cur_scores, dim=0) - - keep = (conf_scores > self.conf_thresh) - scores = cur_scores[:, keep] - boxes = decoded_boxes[keep, :] - masks = mask_data[batch_idx, keep, :] - - if inst_data is not None: - inst = inst_data[batch_idx, keep, :] - - if scores.size(1) == 0: - return None - - if self.use_fast_nms: - if self.use_cross_class_nms: - boxes, masks, classes, scores = self.cc_fast_nms(boxes, masks, scores, self.nms_thresh, self.top_k) - else: - boxes, masks, classes, scores = self.fast_nms(boxes, masks, scores, self.nms_thresh, self.top_k) - else: - boxes, masks, classes, scores = self.traditional_nms(boxes, masks, scores, self.nms_thresh, self.conf_thresh) - - if self.use_cross_class_nms: - print('Warning: Cross Class Traditional NMS is not implemented.') - - return {'box': boxes, 'mask': masks, 'class': classes, 'score': scores} - - - def cc_fast_nms(self, boxes, masks, scores, iou_threshold:float=0.5, top_k:int=200): - # Collapse all the classes into 1 - scores, classes = scores.max(dim=0) - - _, idx = scores.sort(0, descending=True) - idx = idx[:top_k] - - boxes_idx = boxes[idx] - - # Compute the pairwise IoU between the boxes - iou = jaccard(boxes_idx, boxes_idx) - - # Zero out the lower triangle of the cosine similarity matrix and diagonal - iou.triu_(diagonal=1) - - # Now that everything in the diagonal and below is zeroed out, if we take the max - # of the IoU matrix along the columns, each column will represent the maximum IoU - # between this element and every element with a higher score than this element. - iou_max, _ = torch.max(iou, dim=0) - - # Now just filter out the ones greater than the threshold, i.e., only keep boxes that - # don't have a higher scoring box that would supress it in normal NMS. - idx_out = idx[iou_max <= iou_threshold] - - return boxes[idx_out], masks[idx_out], classes[idx_out], scores[idx_out] - - def fast_nms(self, boxes, masks, scores, iou_threshold:float=0.5, top_k:int=200, second_threshold:bool=False): - scores, idx = scores.sort(1, descending=True) - - idx = idx[:, :top_k].contiguous() - scores = scores[:, :top_k] - - num_classes, num_dets = idx.size() - - boxes = boxes[idx.view(-1), :].view(num_classes, num_dets, 4) - masks = masks[idx.view(-1), :].view(num_classes, num_dets, -1) - - iou = jaccard(boxes, boxes) - iou.triu_(diagonal=1) - iou_max, _ = iou.max(dim=1) - - # Now just filter out the ones higher than the threshold - keep = (iou_max <= iou_threshold) - - # We should also only keep detections over the confidence threshold, but at the cost of - # maxing out your detection count for every image, you can just not do that. Because we - # have such a minimal amount of computation per detection (matrix mulitplication only), - # this increase doesn't affect us much (+0.2 mAP for 34 -> 33 fps), so we leave it out. - # However, when you implement this in your method, you should do this second threshold. - if second_threshold: - keep *= (scores > self.conf_thresh) - - # Assign each kept detection to its corresponding class - classes = torch.arange(num_classes, device=boxes.device)[:, None].expand_as(keep) - classes = classes[keep] - - boxes = boxes[keep] - masks = masks[keep] - scores = scores[keep] - - # Only keep the top cfg.max_num_detections highest scores across all classes - scores, idx = scores.sort(0, descending=True) - idx = idx[:cfg.max_num_detections] - scores = scores[:cfg.max_num_detections] - - classes = classes[idx] - boxes = boxes[idx] - masks = masks[idx] - - return boxes, masks, classes, scores - - def traditional_nms(self, boxes, masks, scores, iou_threshold=0.5, conf_thresh=0.05): - import pyximport - pyximport.install(setup_args={"include_dirs":np.get_include()}, reload_support=True) - - from utils.cython_nms import nms as cnms - - num_classes = scores.size(0) - - idx_lst = [] - cls_lst = [] - scr_lst = [] - - # Multiplying by max_size is necessary because of how cnms computes its area and intersections - boxes = boxes * cfg.max_size - - for _cls in range(num_classes): - cls_scores = scores[_cls, :] - conf_mask = cls_scores > conf_thresh - idx = torch.arange(cls_scores.size(0), device=boxes.device) - - cls_scores = cls_scores[conf_mask] - idx = idx[conf_mask] - - if cls_scores.size(0) == 0: - continue - - preds = torch.cat([boxes[conf_mask], cls_scores[:, None]], dim=1).detach().numpy() - keep = cnms(preds, iou_threshold) - keep = torch.Tensor(keep, device=boxes.device).long() - - idx_lst.append(idx[keep]) - cls_lst.append(keep * 0 + _cls) - scr_lst.append(cls_scores[keep]) - - idx = torch.cat(idx_lst, dim=0) - classes = torch.cat(cls_lst, dim=0) - scores = torch.cat(scr_lst, dim=0) - - scores, idx2 = scores.sort(0, descending=True) - idx2 = idx2[:cfg.max_num_detections] - scores = scores[:cfg.max_num_detections] - - idx = idx[idx2] - classes = classes[idx2] - - # Undo the multiplication above - return boxes[idx] / cfg.max_size, masks[idx], classes, scores +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch +import torch.nn.functional as F +from ..box_utils import decode, jaccard, index2d +from utils import timer + +from data import cfg, mask_type + +import numpy as np + + +class Detect(object): + """At test time, Detect is the final layer of SSD. Decode location preds, + apply non-maximum suppression to location predictions based on conf + scores and threshold to a top_k number of output predictions for both + confidence score and locations, as the predicted masks. + """ + # TODO: Refactor this whole class away. It needs to go. + + def __init__(self, num_classes, bkg_label, top_k, conf_thresh, nms_thresh): + self.num_classes = num_classes + self.background_label = bkg_label + self.top_k = top_k + # Parameters used in nms. + self.nms_thresh = nms_thresh + if nms_thresh <= 0: + raise ValueError('nms_threshold must be non negative.') + self.conf_thresh = conf_thresh + + self.use_cross_class_nms = False + self.use_fast_nms = False + + def __call__(self, predictions): + """ + Args: + loc_data: (tensor) Loc preds from loc layers + Shape: [batch, num_priors, 4] + conf_data: (tensor) Shape: Conf preds from conf layers + Shape: [batch, num_priors, num_classes] + mask_data: (tensor) Mask preds from mask layers + Shape: [batch, num_priors, mask_dim] + prior_data: (tensor) Prior boxes and variances from priorbox layers + Shape: [num_priors, 4] + proto_data: (tensor) If using mask_type.lincomb, the prototype masks + Shape: [batch, mask_h, mask_w, mask_dim] + + Returns: + output of shape (batch_size, top_k, 1 + 1 + 4 + mask_dim) + These outputs are in the order: class idx, confidence, bbox coords, and mask. + + Note that the outputs are sorted only if cross_class_nms is False + """ + + loc_data = predictions['loc'] + conf_data = predictions['conf'] + mask_data = predictions['mask'] + prior_data = predictions['priors'] + + proto_data = predictions['proto'] if 'proto' in predictions else None + inst_data = predictions['inst'] if 'inst' in predictions else None + + out = [] + + with timer.env('Detect'): + batch_size = loc_data.size(0) + num_priors = prior_data.size(0) + + conf_preds = conf_data.view(batch_size, num_priors, self.num_classes).transpose(2, 1).contiguous() + + for batch_idx in range(batch_size): + decoded_boxes = decode(loc_data[batch_idx], prior_data) + result = self.detect(batch_idx, conf_preds, decoded_boxes, mask_data, inst_data) + + if result is not None and proto_data is not None: + result['proto'] = proto_data[batch_idx] + + out.append(result) + + return out + + + def detect(self, batch_idx, conf_preds, decoded_boxes, mask_data, inst_data): + """ Perform nms for only the max scoring class that isn't background (class 0) """ + cur_scores = conf_preds[batch_idx, 1:, :] + conf_scores, _ = torch.max(cur_scores, dim=0) + + keep = (conf_scores > self.conf_thresh) + scores = cur_scores[:, keep] + boxes = decoded_boxes[keep, :] + masks = mask_data[batch_idx, keep, :] + + if inst_data is not None: + inst = inst_data[batch_idx, keep, :] + + if scores.size(1) == 0: + return None + + if self.use_fast_nms: + if self.use_cross_class_nms: + boxes, masks, classes, scores = self.cc_fast_nms(boxes, masks, scores, self.nms_thresh, self.top_k) + else: + boxes, masks, classes, scores = self.fast_nms(boxes, masks, scores, self.nms_thresh, self.top_k) + else: + boxes, masks, classes, scores = self.traditional_nms(boxes, masks, scores, self.nms_thresh, self.conf_thresh) + + if self.use_cross_class_nms: + print('Warning: Cross Class Traditional NMS is not implemented.') + + return {'box': boxes, 'mask': masks, 'class': classes, 'score': scores} + + + def cc_fast_nms(self, boxes, masks, scores, iou_threshold:float=0.5, top_k:int=200): + # Collapse all the classes into 1 + scores, classes = scores.max(dim=0) + + _, idx = scores.sort(0, descending=True) + idx = idx[:top_k] + + boxes_idx = boxes[idx] + + # Compute the pairwise IoU between the boxes + iou = jaccard(boxes_idx, boxes_idx) + + # Zero out the lower triangle of the cosine similarity matrix and diagonal + iou.triu_(diagonal=1) + + # Now that everything in the diagonal and below is zeroed out, if we take the max + # of the IoU matrix along the columns, each column will represent the maximum IoU + # between this element and every element with a higher score than this element. + iou_max, _ = torch.max(iou, dim=0) + + # Now just filter out the ones greater than the threshold, i.e., only keep boxes that + # don't have a higher scoring box that would supress it in normal NMS. + idx_out = idx[iou_max <= iou_threshold] + + return boxes[idx_out], masks[idx_out], classes[idx_out], scores[idx_out] + + def fast_nms(self, boxes, masks, scores, iou_threshold:float=0.5, top_k:int=200, second_threshold:bool=False): + scores, idx = scores.sort(1, descending=True) + + idx = idx[:, :top_k].contiguous() + scores = scores[:, :top_k] + + num_classes, num_dets = idx.size() + + boxes = boxes[idx.view(-1), :].view(num_classes, num_dets, 4) + masks = masks[idx.view(-1), :].view(num_classes, num_dets, -1) + + iou = jaccard(boxes, boxes) + iou.triu_(diagonal=1) + iou_max, _ = iou.max(dim=1) + + # Now just filter out the ones higher than the threshold + keep = (iou_max <= iou_threshold) + + # We should also only keep detections over the confidence threshold, but at the cost of + # maxing out your detection count for every image, you can just not do that. Because we + # have such a minimal amount of computation per detection (matrix mulitplication only), + # this increase doesn't affect us much (+0.2 mAP for 34 -> 33 fps), so we leave it out. + # However, when you implement this in your method, you should do this second threshold. + if second_threshold: + keep *= (scores > self.conf_thresh) + + # Assign each kept detection to its corresponding class + classes = torch.arange(num_classes, device=boxes.device)[:, None].expand_as(keep) + classes = classes[keep] + + boxes = boxes[keep] + masks = masks[keep] + scores = scores[keep] + + # Only keep the top cfg.max_num_detections highest scores across all classes + scores, idx = scores.sort(0, descending=True) + idx = idx[:cfg.max_num_detections] + scores = scores[:cfg.max_num_detections] + + classes = classes[idx] + boxes = boxes[idx] + masks = masks[idx] + + return boxes, masks, classes, scores + + def traditional_nms(self, boxes, masks, scores, iou_threshold=0.5, conf_thresh=0.05): + import pyximport + pyximport.install(setup_args={"include_dirs":np.get_include()}, reload_support=True) + + from utils.cython_nms import nms as cnms + + num_classes = scores.size(0) + + idx_lst = [] + cls_lst = [] + scr_lst = [] + + # Multiplying by max_size is necessary because of how cnms computes its area and intersections + boxes = boxes * cfg.max_size + + for _cls in range(num_classes): + cls_scores = scores[_cls, :] + conf_mask = cls_scores > conf_thresh + idx = torch.arange(cls_scores.size(0), device=boxes.device) + + cls_scores = cls_scores[conf_mask] + idx = idx[conf_mask] + + if cls_scores.size(0) == 0: + continue + + preds = torch.cat([boxes[conf_mask], cls_scores[:, None]], dim=1).detach().numpy() + keep = cnms(preds, iou_threshold) + keep = torch.Tensor(keep, device=boxes.device).long() + + idx_lst.append(idx[keep]) + cls_lst.append(keep * 0 + _cls) + scr_lst.append(cls_scores[keep]) + + idx = torch.cat(idx_lst, dim=0) + classes = torch.cat(cls_lst, dim=0) + scores = torch.cat(scr_lst, dim=0) + + scores, idx2 = scores.sort(0, descending=True) + idx2 = idx2[:cfg.max_num_detections] + scores = scores[:cfg.max_num_detections] + + idx = idx[idx2] + classes = classes[idx2] + + # Undo the multiplication above + return boxes[idx] / cfg.max_size, masks[idx], classes, scores diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/interpolate.py b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/interpolate.py index 4ee3f067bc4a44d83f9296c4cb9b7f9b521b0db5..19cacf8d15f7d2768240cdeeb0ad80b633ee639d 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/interpolate.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/interpolate.py @@ -1,31 +1,31 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch.nn as nn -import torch.nn.functional as F - -class InterpolateModule(nn.Module): - """ - This is a module version of F.interpolate (rip nn.Upsampling). - Any arguments you give it just get passed along for the ride. - """ - - def __init__(self, *args, **kwdargs): - super().__init__() - - self.args = args - self.kwdargs = kwdargs - - def forward(self, x): - return F.interpolate(x, *self.args, **self.kwdargs) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch.nn as nn +import torch.nn.functional as F + +class InterpolateModule(nn.Module): + """ + This is a module version of F.interpolate (rip nn.Upsampling). + Any arguments you give it just get passed along for the ride. + """ + + def __init__(self, *args, **kwdargs): + super().__init__() + + self.args = args + self.kwdargs = kwdargs + + def forward(self, x): + return F.interpolate(x, *self.args, **self.kwdargs) diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/modules/__init__.py b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/modules/__init__.py index 028f5306fb0fa0ca29fe51782841da6fc1658dc7..cf24bddbf283f233d0b93fc074a2bac2f5c044a9 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/modules/__init__.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/modules/__init__.py @@ -1,3 +1,3 @@ -from .multibox_loss import MultiBoxLoss - -__all__ = ['MultiBoxLoss'] +from .multibox_loss import MultiBoxLoss + +__all__ = ['MultiBoxLoss'] diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/modules/multibox_loss.py b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/modules/multibox_loss.py index 3abe7e0b07226210dc0abdb86c2192d105996bf9..12a98e8242181b67a5af5515c1bf76d342c10e78 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/modules/multibox_loss.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/modules/multibox_loss.py @@ -1,721 +1,721 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -# -*- coding: utf-8 -*- -import torch -import torch.nn as nn -import torch.nn.functional as F -from torch.autograd import Variable -from ..box_utils import match, log_sum_exp, decode, center_size, crop, elemwise_mask_iou, elemwise_box_iou - -from data import cfg, mask_type, activation_func - - -class MultiBoxLoss(nn.Module): - """SSD Weighted Loss Function - Compute Targets: - 1) Produce Confidence Target Indices by matching ground truth boxes - with (default) 'priorboxes' that have jaccard index > threshold parameter - (default threshold: 0.5). - - 2) Produce localization target by 'encoding' variance into offsets of ground - truth boxes and their matched 'priorboxes'. - - 3) Hard negative mining to filter the excessive number of negative examples - that comes with using a large number of default bounding boxes. - (default negative:positive ratio 3:1) - - Objective Loss: - L(x,c,l,g) = (Lconf(x, c) + αLloc(x,l,g)) / N - Where, Lconf is the CrossEntropy Loss and Lloc is the SmoothL1 Loss - weighted by α which is set to 1 by cross val. - Args: - c: class confidences, - l: predicted boxes, - g: ground truth boxes - N: number of matched default boxes - See: https://arxiv.org/pdf/1512.02325.pdf for more details. - """ - - def __init__(self, num_classes, pos_threshold, neg_threshold, negpos_ratio): - super(MultiBoxLoss, self).__init__() - self.num_classes = num_classes - - self.pos_threshold = pos_threshold - self.neg_threshold = neg_threshold - self.negpos_ratio = negpos_ratio - - # If you output a proto mask with this area, your l1 loss will be l1_alpha - # Note that the area is relative (so 1 would be the entire image) - self.l1_expected_area = 20 * 20 / 70 / 70 - self.l1_alpha = 0.1 - - if cfg.use_class_balanced_conf: - self.class_instances = None - self.total_instances = 0 - - def forward(self, net, predictions, wrapper, wrapper_mask): - """Multibox Loss - Args: - predictions (tuple): A tuple containing loc preds, conf preds, - mask preds, and prior boxes from SSD net. - loc shape: torch.size(batch_size,num_priors,4) - conf shape: torch.size(batch_size,num_priors,num_classes) - masks shape: torch.size(batch_size,num_priors,mask_dim) - priors shape: torch.size(num_priors,4) - proto* shape: torch.size(batch_size,mask_h,mask_w,mask_dim) - - targets (list): Ground truth boxes and labels for a batch, - shape: [batch_size][num_objs,5] (last idx is the label). - - masks (list): Ground truth masks for each object in each image, - shape: [batch_size][num_objs,im_height,im_width] - - num_crowds (list): Number of crowd annotations per batch. The crowd - annotations should be the last num_crowds elements of targets and masks. - - * Only if mask_type == lincomb - """ - - targets, masks, num_crowds = wrapper.get_args(wrapper_mask) - targets = targets[0] - masks = masks[0] - num_crowds = num_crowds[0] - loc_data = predictions['loc'] - conf_data = predictions['conf'] - mask_data = predictions['mask'] - priors = predictions['priors'] - - if cfg.mask_type == mask_type.lincomb: - proto_data = predictions['proto'] - - score_data = predictions['score'] if cfg.use_mask_scoring else None - inst_data = predictions['inst'] if cfg.use_instance_coeff else None - - labels = [None] * len(targets) # Used in sem segm loss - - batch_size = loc_data.size(0) - num_priors = priors.size(0) - num_classes = self.num_classes - - # Match priors (default boxes) and ground truth boxes - # These tensors will be created with the same device as loc_data - loc_t = loc_data.new(batch_size, num_priors, 4) - gt_box_t = loc_data.new(batch_size, num_priors, 4) - conf_t = loc_data.new(batch_size, num_priors).long() - idx_t = loc_data.new(batch_size, num_priors).long() - - if cfg.use_class_existence_loss: - class_existence_t = loc_data.new(batch_size, num_classes - 1) - - for idx in range(batch_size): - truths = targets[idx][:, :-1].data - labels[idx] = targets[idx][:, -1].data.long() - - if cfg.use_class_existence_loss: - # Construct a one-hot vector for each object and collapse it into an existence vector with max - # Also it's fine to include the crowd annotations here - class_existence_t[idx, :] = \ - torch.eye(num_classes - 1, device=conf_t.get_device())[labels[idx]].max(dim=0)[0] - - # Split the crowd annotations because they come bundled in - cur_crowds = num_crowds[idx] - if cur_crowds > 0: - split = lambda x: (x[-cur_crowds:], x[:-cur_crowds]) - crowd_boxes, truths = split(truths) - - # We don't use the crowd labels or masks - _, labels[idx] = split(labels[idx]) - _, masks[idx] = split(masks[idx]) - else: - crowd_boxes = None - - match(self.pos_threshold, self.neg_threshold, - truths, priors.data, labels[idx], crowd_boxes, - loc_t, conf_t, idx_t, idx, loc_data[idx]) - - gt_box_t[idx, :, :] = truths[idx_t[idx]] - - # wrap targets - loc_t = Variable(loc_t, requires_grad=False) - conf_t = Variable(conf_t, requires_grad=False) - idx_t = Variable(idx_t, requires_grad=False) - - pos = conf_t > 0 - num_pos = pos.sum(dim=1, keepdim=True) - - # Shape: [batch,num_priors,4] - pos_idx = pos.unsqueeze(pos.dim()).expand_as(loc_data) - - losses = {} - - # Localization Loss (Smooth L1) - if cfg.train_boxes: - # loc_p = loc_data[pos_idx].view(-1, 4) - # loc_t = loc_t[pos_idx].view(-1, 4) - # losses['B'] = F.smooth_l1_loss(loc_p, loc_t, reduction='sum') * cfg.bbox_alpha - loc_p = loc_data.view(-1, 4) - loc_t = loc_t.view(-1, 4) - losses['B'] = F.smooth_l1_loss(loc_p, loc_t, reduction='none') * cfg.bbox_alpha - losses['B'][pos_idx.view(-1, 4) == False] = 0 - losses['B'] = losses['B'].sum() - - if cfg.train_masks: - if cfg.mask_type == mask_type.direct: - if cfg.use_gt_bboxes: - pos_masks = [] - for idx in range(batch_size): - pos_masks.append(masks[idx][idx_t[idx, pos[idx]]]) - masks_t = torch.cat(pos_masks, 0) - masks_p = mask_data[pos, :].view(-1, cfg.mask_dim) - losses['M'] = F.binary_cross_entropy(torch.clamp(masks_p, 0, 1), masks_t, - reduction='sum') * cfg.mask_alpha - else: - losses['M'] = self.direct_mask_loss(pos_idx, idx_t, loc_data, mask_data, priors, masks) - elif cfg.mask_type == mask_type.lincomb: - ret = self.lincomb_mask_loss(pos, idx_t, loc_data, mask_data, priors, proto_data, masks, gt_box_t, - score_data, inst_data, labels) - if cfg.use_maskiou: - loss, maskiou_targets = ret - else: - loss = ret - losses.update(loss) - - if cfg.mask_proto_loss is not None: - if cfg.mask_proto_loss == 'l1': - losses['P'] = torch.mean(torch.abs(proto_data)) / self.l1_expected_area * self.l1_alpha - elif cfg.mask_proto_loss == 'disj': - losses['P'] = -torch.mean(torch.max(F.log_softmax(proto_data, dim=-1), dim=-1)[0]) - - # Confidence loss - if cfg.use_focal_loss: - if cfg.use_sigmoid_focal_loss: - losses['C'] = self.focal_conf_sigmoid_loss(conf_data, conf_t) - elif cfg.use_objectness_score: - losses['C'] = self.focal_conf_objectness_loss(conf_data, conf_t) - else: - losses['C'] = self.focal_conf_loss(conf_data, conf_t) - else: - if cfg.use_objectness_score: - losses['C'] = self.conf_objectness_loss(conf_data, conf_t, batch_size, loc_p, loc_t, priors) - else: - losses['C'] = self.ohem_conf_loss(conf_data, conf_t, pos, batch_size) - - # Mask IoU Loss - if cfg.use_maskiou and maskiou_targets is not None: - losses['I'] = self.mask_iou_loss(net, maskiou_targets) - - # These losses also don't depend on anchors - if cfg.use_class_existence_loss: - losses['E'] = self.class_existence_loss(predictions['classes'], class_existence_t) - if cfg.use_semantic_segmentation_loss: - losses['S'] = self.semantic_segmentation_loss(predictions['segm'], masks, labels) - - # Divide all losses by the number of positives. - # Don't do it for loss[P] because that doesn't depend on the anchors. - total_num_pos = num_pos.data.sum().float() - for k in losses: - if k not in ('P', 'E', 'S'): - losses[k] /= total_num_pos - else: - losses[k] /= batch_size - - # Loss Key: - # - B: Box Localization Loss - # - C: Class Confidence Loss - # - M: Mask Loss - # - P: Prototype Loss - # - D: Coefficient Diversity Loss - # - E: Class Existence Loss - # - S: Semantic Segmentation Loss - return losses - - def class_existence_loss(self, class_data, class_existence_t): - return cfg.class_existence_alpha * F.binary_cross_entropy_with_logits(class_data, class_existence_t, - reduction='sum') - - def semantic_segmentation_loss(self, segment_data, mask_t, class_t, interpolation_mode='bilinear'): - # Note num_classes here is without the background class so cfg.num_classes-1 - batch_size, num_classes, mask_h, mask_w = segment_data.size() - loss_s = 0 - - for idx in range(batch_size): - cur_segment = segment_data[idx] - cur_class_t = class_t[idx] - - with torch.no_grad(): - downsampled_masks = F.interpolate(mask_t[idx].unsqueeze(0), (mask_h, mask_w), - mode=interpolation_mode, align_corners=False).squeeze(0) - downsampled_masks = downsampled_masks.gt(0.5).float() - - # Construct Semantic Segmentation - segment_t = torch.zeros_like(cur_segment, requires_grad=False) - for obj_idx in range(downsampled_masks.size(0)): - segment_t[cur_class_t[obj_idx]] = torch.max(segment_t[cur_class_t[obj_idx]].float(), - downsampled_masks[obj_idx]) - - loss_s += F.binary_cross_entropy_with_logits(cur_segment, segment_t, reduction='sum') - - return loss_s / mask_h / mask_w * cfg.semantic_segmentation_alpha - - def ohem_conf_loss(self, conf_data, conf_t, pos, num): - # Compute max conf across batch for hard negative mining - batch_conf = conf_data.view(-1, self.num_classes) - if cfg.ohem_use_most_confident: - # i.e. max(softmax) along classes > 0 - batch_conf = F.softmax(batch_conf, dim=1) - loss_c, _ = batch_conf[:, 1:].max(dim=1) - else: - # i.e. -softmax(class 0 confidence) - loss_c = log_sum_exp(batch_conf) - batch_conf[:, 0] - - # Hard Negative Mining - loss_c = loss_c.view(num, -1) - loss_c[pos] = 0 # filter out pos boxes - loss_c[conf_t < 0] = 0 # filter out neutrals (conf_t = -1) - _, loss_idx = loss_c.sort(1, descending=True) - _, idx_rank = loss_idx.sort(1) - num_pos = pos.long().sum(1, keepdim=True) - num_neg = torch.clamp(self.negpos_ratio * num_pos, max=pos.size(1) - 1) - neg = idx_rank < num_neg.expand_as(idx_rank) - - # Just in case there aren't enough negatives, don't start using positives as negatives - neg[pos] = 0 - neg[conf_t < 0] = 0 # Filter out neutrals - - # Confidence Loss Including Positive and Negative Examples - # pos_idx = pos.unsqueeze(2).expand_as(conf_data) - # neg_idx = neg.unsqueeze(2).expand_as(conf_data) - - # conf_p = conf_data[(pos_idx+neg_idx).gt(0)].view(-1, self.num_classes) - # targets_weighted = conf_t[(pos+neg).gt(0)] - ## loss_c = F.cross_entropy(conf_p, targets_weighted, reduction='none') - loss_c = F.cross_entropy(conf_data.view(-1, self.num_classes), conf_t.view(-1), reduction='none').view(-1, - 57744) - loss_c[(pos + neg).gt(0) == False] = 0 - - if cfg.use_class_balanced_conf: - # Lazy initialization - if self.class_instances is None: - self.class_instances = torch.zeros(self.num_classes, device=targets_weighted.device) - - classes, counts = targets_weighted.unique(return_counts=True) - - for _cls, _cnt in zip(classes.cpu().numpy(), counts.cpu().numpy()): - self.class_instances[_cls] += _cnt - - self.total_instances += targets_weighted.size(0) - - weighting = 1 - (self.class_instances[targets_weighted] / self.total_instances) - weighting = torch.clamp(weighting, min=1 / self.num_classes) - - # If you do the math, the average weight of self.class_instances is this - avg_weight = (self.num_classes - 1) / self.num_classes - - loss_c = (loss_c * weighting).sum() / avg_weight - else: - loss_c = loss_c.sum() - - return cfg.conf_alpha * loss_c - - def focal_conf_loss(self, conf_data, conf_t): - """ - Focal loss as described in https://arxiv.org/pdf/1708.02002.pdf - Adapted from https://github.com/clcarwin/focal_loss_pytorch/blob/master/focalloss.py - Note that this uses softmax and not the original sigmoid from the paper. - """ - conf_t = conf_t.view(-1) # [batch_size*num_priors] - conf_data = conf_data.view(-1, conf_data.size(-1)) # [batch_size*num_priors, num_classes] - - # Ignore neutral samples (class < 0) - keep = (conf_t >= 0).float() - conf_t[conf_t < 0] = 0 # so that gather doesn't drum up a fuss - - logpt = F.log_softmax(conf_data, dim=-1) - logpt = logpt.gather(1, conf_t.unsqueeze(-1)) - logpt = logpt.view(-1) - pt = logpt.exp() - - # I adapted the alpha_t calculation here from - # https://github.com/pytorch/pytorch/blob/master/modules/detectron/softmax_focal_loss_op.cu - # You'd think you want all the alphas to sum to one, but in the original implementation they - # just give background an alpha of 1-alpha and each forground an alpha of alpha. - background = (conf_t == 0).float() - at = (1 - cfg.focal_loss_alpha) * background + cfg.focal_loss_alpha * (1 - background) - - loss = -at * (1 - pt) ** cfg.focal_loss_gamma * logpt - - # See comment above for keep - return cfg.conf_alpha * (loss * keep).sum() - - def focal_conf_sigmoid_loss(self, conf_data, conf_t): - """ - Focal loss but using sigmoid like the original paper. - Note: To make things mesh easier, the network still predicts 81 class confidences in this mode. - Because retinanet originally only predicts 80, we simply just don't use conf_data[..., 0] - """ - num_classes = conf_data.size(-1) - - conf_t = conf_t.view(-1) # [batch_size*num_priors] - conf_data = conf_data.view(-1, num_classes) # [batch_size*num_priors, num_classes] - - # Ignore neutral samples (class < 0) - keep = (conf_t >= 0).float() - conf_t[conf_t < 0] = 0 # can't mask with -1, so filter that out - - # Compute a one-hot embedding of conf_t - # From https://github.com/kuangliu/pytorch-retinanet/blob/master/utils.py - conf_one_t = torch.eye(num_classes, device=conf_t.get_device())[conf_t] - conf_pm_t = conf_one_t * 2 - 1 # -1 if background, +1 if forground for specific class - - logpt = F.logsigmoid(conf_data * conf_pm_t) # note: 1 - sigmoid(x) = sigmoid(-x) - pt = logpt.exp() - - at = cfg.focal_loss_alpha * conf_one_t + (1 - cfg.focal_loss_alpha) * (1 - conf_one_t) - at[..., 0] = 0 # Set alpha for the background class to 0 because sigmoid focal loss doesn't use it - - loss = -at * (1 - pt) ** cfg.focal_loss_gamma * logpt - loss = keep * loss.sum(dim=-1) - - return cfg.conf_alpha * loss.sum() - - def focal_conf_objectness_loss(self, conf_data, conf_t): - """ - Instead of using softmax, use class[0] to be the objectness score and do sigmoid focal loss on that. - Then for the rest of the classes, softmax them and apply CE for only the positive examples. - - If class[0] = 1 implies forground and class[0] = 0 implies background then you achieve something - similar during test-time to softmax by setting class[1:] = softmax(class[1:]) * class[0] and invert class[0]. - """ - - conf_t = conf_t.view(-1) # [batch_size*num_priors] - conf_data = conf_data.view(-1, conf_data.size(-1)) # [batch_size*num_priors, num_classes] - - # Ignore neutral samples (class < 0) - keep = (conf_t >= 0).float() - conf_t[conf_t < 0] = 0 # so that gather doesn't drum up a fuss - - background = (conf_t == 0).float() - at = (1 - cfg.focal_loss_alpha) * background + cfg.focal_loss_alpha * (1 - background) - - logpt = F.logsigmoid(conf_data[:, 0]) * (1 - background) + F.logsigmoid(-conf_data[:, 0]) * background - pt = logpt.exp() - - obj_loss = -at * (1 - pt) ** cfg.focal_loss_gamma * logpt - - # All that was the objectiveness loss--now time for the class confidence loss - pos_mask = conf_t > 0 - conf_data_pos = (conf_data[:, 1:])[pos_mask] # Now this has just 80 classes - conf_t_pos = conf_t[pos_mask] - 1 # So subtract 1 here - - class_loss = F.cross_entropy(conf_data_pos, conf_t_pos, reduction='sum') - - return cfg.conf_alpha * (class_loss + (obj_loss * keep).sum()) - - def conf_objectness_loss(self, conf_data, conf_t, batch_size, loc_p, loc_t, priors): - """ - Instead of using softmax, use class[0] to be p(obj) * p(IoU) as in YOLO. - Then for the rest of the classes, softmax them and apply CE for only the positive examples. - """ - - conf_t = conf_t.view(-1) # [batch_size*num_priors] - conf_data = conf_data.view(-1, conf_data.size(-1)) # [batch_size*num_priors, num_classes] - - pos_mask = (conf_t > 0) - neg_mask = (conf_t == 0) - - obj_data = conf_data[:, 0] - obj_data_pos = obj_data[pos_mask] - obj_data_neg = obj_data[neg_mask] - - # Don't be confused, this is just binary cross entropy similified - obj_neg_loss = - F.logsigmoid(-obj_data_neg).sum() - - with torch.no_grad(): - pos_priors = priors.unsqueeze(0).expand(batch_size, -1, -1).reshape(-1, 4)[pos_mask, :] - - boxes_pred = decode(loc_p, pos_priors, cfg.use_yolo_regressors) - boxes_targ = decode(loc_t, pos_priors, cfg.use_yolo_regressors) - - iou_targets = elemwise_box_iou(boxes_pred, boxes_targ) - - obj_pos_loss = - iou_targets * F.logsigmoid(obj_data_pos) - (1 - iou_targets) * F.logsigmoid(-obj_data_pos) - obj_pos_loss = obj_pos_loss.sum() - - # All that was the objectiveness loss--now time for the class confidence loss - conf_data_pos = (conf_data[:, 1:])[pos_mask] # Now this has just 80 classes - conf_t_pos = conf_t[pos_mask] - 1 # So subtract 1 here - - class_loss = F.cross_entropy(conf_data_pos, conf_t_pos, reduction='sum') - - return cfg.conf_alpha * (class_loss + obj_pos_loss + obj_neg_loss) - - def direct_mask_loss(self, pos_idx, idx_t, loc_data, mask_data, priors, masks): - """ Crops the gt masks using the predicted bboxes, scales them down, and outputs the BCE loss. """ - loss_m = 0 - for idx in range(mask_data.size(0)): - with torch.no_grad(): - cur_pos_idx = pos_idx[idx, :, :] - cur_pos_idx_squeezed = cur_pos_idx[:, 1] - - # Shape: [num_priors, 4], decoded predicted bboxes - pos_bboxes = decode(loc_data[idx, :, :], priors.data, cfg.use_yolo_regressors) - pos_bboxes = pos_bboxes[cur_pos_idx].view(-1, 4).clamp(0, 1) - pos_lookup = idx_t[idx, cur_pos_idx_squeezed] - - cur_masks = masks[idx] - pos_masks = cur_masks[pos_lookup, :, :] - - # Convert bboxes to absolute coordinates - num_pos, img_height, img_width = pos_masks.size() - - # Take care of all the bad behavior that can be caused by out of bounds coordinates - x1, x2 = sanitize_coordinates(pos_bboxes[:, 0], pos_bboxes[:, 2], img_width) - y1, y2 = sanitize_coordinates(pos_bboxes[:, 1], pos_bboxes[:, 3], img_height) - - # Crop each gt mask with the predicted bbox and rescale to the predicted mask size - # Note that each bounding box crop is a different size so I don't think we can vectorize this - scaled_masks = [] - for jdx in range(num_pos): - tmp_mask = pos_masks[jdx, y1[jdx]:y2[jdx], x1[jdx]:x2[jdx]] - - # Restore any dimensions we've left out because our bbox was 1px wide - while tmp_mask.dim() < 2: - tmp_mask = tmp_mask.unsqueeze(0) - - new_mask = F.adaptive_avg_pool2d(tmp_mask.unsqueeze(0), cfg.mask_size) - scaled_masks.append(new_mask.view(1, -1)) - - mask_t = torch.cat(scaled_masks, 0).gt(0.5).float() # Threshold downsampled mask - - pos_mask_data = mask_data[idx, cur_pos_idx_squeezed, :] - loss_m += F.binary_cross_entropy(torch.clamp(pos_mask_data, 0, 1), mask_t, reduction='sum') * cfg.mask_alpha - - return loss_m - - def coeff_diversity_loss(self, coeffs, instance_t): - """ - coeffs should be size [num_pos, num_coeffs] - instance_t should be size [num_pos] and be values from 0 to num_instances-1 - """ - num_pos = coeffs.size(0) - instance_t = instance_t.view(-1) # juuuust to make sure - - coeffs_norm = F.normalize(coeffs, dim=1) - cos_sim = coeffs_norm @ coeffs_norm.t() - - inst_eq = (instance_t[:, None].expand_as(cos_sim) == instance_t[None, :].expand_as(cos_sim)).float() - - # Rescale to be between 0 and 1 - cos_sim = (cos_sim + 1) / 2 - - # If they're the same instance, use cosine distance, else use cosine similarity - loss = (1 - cos_sim) * inst_eq + cos_sim * (1 - inst_eq) - - # Only divide by num_pos once because we're summing over a num_pos x num_pos tensor - # and all the losses will be divided by num_pos at the end, so just one extra time. - return cfg.mask_proto_coeff_diversity_alpha * loss.sum() / num_pos - - def lincomb_mask_loss(self, pos, idx_t, loc_data, mask_data, priors, proto_data, masks, gt_box_t, score_data, - inst_data, labels, interpolation_mode='bilinear'): - mask_h = proto_data.size(1) - mask_w = proto_data.size(2) - - process_gt_bboxes = cfg.mask_proto_normalize_emulate_roi_pooling or cfg.mask_proto_crop - - if cfg.mask_proto_remove_empty_masks: - # Make sure to store a copy of this because we edit it to get rid of all-zero masks - pos = pos.clone() - - loss_m = 0 - loss_d = 0 # Coefficient diversity loss - - maskiou_t_list = [] - maskiou_net_input_list = [] - label_t_list = [] - - for idx in range(mask_data.size(0)): - with torch.no_grad(): - downsampled_masks = F.interpolate(masks[idx].unsqueeze(0), (mask_h, mask_w), - mode=interpolation_mode, align_corners=False).squeeze(0) - downsampled_masks = downsampled_masks.permute(1, 2, 0).contiguous() - if cfg.mask_proto_binarize_downsampled_gt: - downsampled_masks = downsampled_masks.gt(0.5).float() - - if cfg.mask_proto_remove_empty_masks: - # Get rid of gt masks that are so small they get downsampled away - very_small_masks = (downsampled_masks.sum(dim=(0, 1)) <= 0.0001) - for i in range(very_small_masks.size(0)): - if very_small_masks[i]: - pos[idx, idx_t[idx] == i] = 0 - if cfg.mask_proto_reweight_mask_loss: - # Ensure that the gt is binary - if not cfg.mask_proto_binarize_downsampled_gt: - bin_gt = downsampled_masks.gt(0.5).float() - else: - bin_gt = downsampled_masks - - gt_foreground_norm = bin_gt / (torch.sum(bin_gt, dim=(0, 1), keepdim=True) + 0.0001) - gt_background_norm = (1 - bin_gt) / (torch.sum(1 - bin_gt, dim=(0, 1), keepdim=True) + 0.0001) - - mask_reweighting = gt_foreground_norm * cfg.mask_proto_reweight_coeff + gt_background_norm - mask_reweighting *= mask_h * mask_w - - cur_pos = pos[idx] - pos_idx_t = idx_t[idx, cur_pos] - if process_gt_bboxes: - # Note: this is in point-form - if cfg.mask_proto_crop_with_pred_box: - pos_gt_box_t = decode(loc_data[idx, :, :], priors.data, cfg.use_yolo_regressors)[cur_pos] - else: - pos_gt_box_t = gt_box_t[idx, cur_pos] - if pos_idx_t.size(0) == 0: - continue - - proto_masks = proto_data[idx] - proto_coef = mask_data[idx, cur_pos, :] - if cfg.use_mask_scoring: - mask_scores = score_data[idx, cur_pos, :] - if cfg.mask_proto_coeff_diversity_loss: - if inst_data is not None: - div_coeffs = inst_data[idx, cur_pos, :] - else: - div_coeffs = proto_coef - - loss_d += self.coeff_diversity_loss(div_coeffs, pos_idx_t) - - # If we have over the allowed number of masks, select a random sample - old_num_pos = proto_coef.size(0) - if old_num_pos > cfg.masks_to_train: - perm = torch.randperm(proto_coef.size(0)) - select = perm[:cfg.masks_to_train] - - proto_coef = proto_coef[select, :] - pos_idx_t = pos_idx_t[select] - - if process_gt_bboxes: - pos_gt_box_t = pos_gt_box_t[select, :] - if cfg.use_mask_scoring: - mask_scores = mask_scores[select, :] - - num_pos = proto_coef.size(0) - mask_t = downsampled_masks[:, :, pos_idx_t] - label_t = labels[idx][pos_idx_t] - # Size: [mask_h, mask_w, num_pos] - pred_masks = proto_masks @ proto_coef.t() - pred_masks = cfg.mask_proto_mask_activation(pred_masks) - if cfg.mask_proto_double_loss: - if cfg.mask_proto_mask_activation == activation_func.sigmoid: - pre_loss = F.binary_cross_entropy(torch.clamp(pred_masks, 0, 1), mask_t, reduction='sum') - else: - pre_loss = F.smooth_l1_loss(pred_masks, mask_t, reduction='sum') - - loss_m += cfg.mask_proto_double_loss_alpha * pre_loss - - if cfg.mask_proto_crop: - pred_masks = crop(pred_masks, pos_gt_box_t) - - if cfg.mask_proto_mask_activation == activation_func.sigmoid: - pre_loss = F.binary_cross_entropy(torch.clamp(pred_masks, 0, 1), mask_t, reduction='none') - else: - pre_loss = F.smooth_l1_loss(pred_masks, mask_t, reduction='none') - - if cfg.mask_proto_normalize_mask_loss_by_sqrt_area: - gt_area = torch.sum(mask_t, dim=(0, 1), keepdim=True) - pre_loss = pre_loss / (torch.sqrt(gt_area) + 0.0001) - - if cfg.mask_proto_reweight_mask_loss: - pre_loss = pre_loss * mask_reweighting[:, :, pos_idx_t] - - if cfg.mask_proto_normalize_emulate_roi_pooling: - weight = mask_h * mask_w if cfg.mask_proto_crop else 1 - pos_gt_csize = center_size(pos_gt_box_t) - gt_box_width = pos_gt_csize[:, 2] * mask_w - gt_box_height = pos_gt_csize[:, 3] * mask_h - pre_loss = pre_loss.sum(dim=(0, 1)) / gt_box_width / gt_box_height * weight - - # If the number of masks were limited scale the loss accordingly - if old_num_pos > num_pos: - pre_loss *= old_num_pos / num_pos - - loss_m += torch.sum(pre_loss) - - if cfg.use_maskiou: - if cfg.discard_mask_area > 0: - gt_mask_area = torch.sum(mask_t, dim=(0, 1)) - - select = gt_mask_area > cfg.discard_mask_area - - if torch.sum(select) < 1: - continue - - - pos_gt_box_t = pos_gt_box_t[select, :] - pred_masks = pred_masks[:, :, select] - mask_t = mask_t[:, :, select] - label_t = label_t[select] - - maskiou_net_input = pred_masks.permute(2, 0, 1).contiguous().unsqueeze(1) - pred_masks = pred_masks.gt(0.5).float() - maskiou_t = self._mask_iou(pred_masks, mask_t) - - maskiou_net_input_list.append(maskiou_net_input) - maskiou_t_list.append(maskiou_t) - label_t_list.append(label_t) - - losses = {'M': loss_m * cfg.mask_alpha / mask_h / mask_w} - - if cfg.mask_proto_coeff_diversity_loss: - losses['D'] = loss_d - - if cfg.use_maskiou: - # discard_mask_area discarded every mask in the batch, so nothing to do here - if len(maskiou_t_list) == 0: - return losses, None - - maskiou_t = torch.cat(maskiou_t_list) - label_t = torch.cat(label_t_list) - maskiou_net_input = torch.cat(maskiou_net_input_list) - - num_samples = maskiou_t.size(0) - if cfg.maskious_to_train > 0 and num_samples > cfg.maskious_to_train: - perm = torch.randperm(num_samples) - select = perm[:cfg.masks_to_train] - maskiou_t = maskiou_t[select] - label_t = label_t[select] - maskiou_net_input = maskiou_net_input[select] - - return losses, [maskiou_net_input, maskiou_t, label_t] - - return losses - - def _mask_iou(self, mask1, mask2): - intersection = torch.sum(mask1 * mask2, dim=(0, 1)) - area1 = torch.sum(mask1, dim=(0, 1)) - area2 = torch.sum(mask2, dim=(0, 1)) - union = (area1 + area2) - intersection - ret = intersection / union - return ret - - def mask_iou_loss(self, net, maskiou_targets): - maskiou_net_input, maskiou_t, label_t = maskiou_targets - - maskiou_p = net.maskiou_net(maskiou_net_input) - - label_t = label_t[:, None] - maskiou_p = torch.gather(maskiou_p, dim=1, index=label_t).view(-1) - - loss_i = F.smooth_l1_loss(maskiou_p, maskiou_t, reduction='sum') - - return loss_i * cfg.maskiou_alpha +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# -*- coding: utf-8 -*- +import torch +import torch.nn as nn +import torch.nn.functional as F +from torch.autograd import Variable +from ..box_utils import match, log_sum_exp, decode, center_size, crop, elemwise_mask_iou, elemwise_box_iou + +from data import cfg, mask_type, activation_func + + +class MultiBoxLoss(nn.Module): + """SSD Weighted Loss Function + Compute Targets: + 1) Produce Confidence Target Indices by matching ground truth boxes + with (default) 'priorboxes' that have jaccard index > threshold parameter + (default threshold: 0.5). + + 2) Produce localization target by 'encoding' variance into offsets of ground + truth boxes and their matched 'priorboxes'. + + 3) Hard negative mining to filter the excessive number of negative examples + that comes with using a large number of default bounding boxes. + (default negative:positive ratio 3:1) + + Objective Loss: + L(x,c,l,g) = (Lconf(x, c) + αLloc(x,l,g)) / N + Where, Lconf is the CrossEntropy Loss and Lloc is the SmoothL1 Loss + weighted by α which is set to 1 by cross val. + Args: + c: class confidences, + l: predicted boxes, + g: ground truth boxes + N: number of matched default boxes + See: https://arxiv.org/pdf/1512.02325.pdf for more details. + """ + + def __init__(self, num_classes, pos_threshold, neg_threshold, negpos_ratio): + super(MultiBoxLoss, self).__init__() + self.num_classes = num_classes + + self.pos_threshold = pos_threshold + self.neg_threshold = neg_threshold + self.negpos_ratio = negpos_ratio + + # If you output a proto mask with this area, your l1 loss will be l1_alpha + # Note that the area is relative (so 1 would be the entire image) + self.l1_expected_area = 20 * 20 / 70 / 70 + self.l1_alpha = 0.1 + + if cfg.use_class_balanced_conf: + self.class_instances = None + self.total_instances = 0 + + def forward(self, net, predictions, wrapper, wrapper_mask): + """Multibox Loss + Args: + predictions (tuple): A tuple containing loc preds, conf preds, + mask preds, and prior boxes from SSD net. + loc shape: torch.size(batch_size,num_priors,4) + conf shape: torch.size(batch_size,num_priors,num_classes) + masks shape: torch.size(batch_size,num_priors,mask_dim) + priors shape: torch.size(num_priors,4) + proto* shape: torch.size(batch_size,mask_h,mask_w,mask_dim) + + targets (list): Ground truth boxes and labels for a batch, + shape: [batch_size][num_objs,5] (last idx is the label). + + masks (list): Ground truth masks for each object in each image, + shape: [batch_size][num_objs,im_height,im_width] + + num_crowds (list): Number of crowd annotations per batch. The crowd + annotations should be the last num_crowds elements of targets and masks. + + * Only if mask_type == lincomb + """ + + targets, masks, num_crowds = wrapper.get_args(wrapper_mask) + targets = targets[0] + masks = masks[0] + num_crowds = num_crowds[0] + loc_data = predictions['loc'] + conf_data = predictions['conf'] + mask_data = predictions['mask'] + priors = predictions['priors'] + + if cfg.mask_type == mask_type.lincomb: + proto_data = predictions['proto'] + + score_data = predictions['score'] if cfg.use_mask_scoring else None + inst_data = predictions['inst'] if cfg.use_instance_coeff else None + + labels = [None] * len(targets) # Used in sem segm loss + + batch_size = loc_data.size(0) + num_priors = priors.size(0) + num_classes = self.num_classes + + # Match priors (default boxes) and ground truth boxes + # These tensors will be created with the same device as loc_data + loc_t = loc_data.new(batch_size, num_priors, 4) + gt_box_t = loc_data.new(batch_size, num_priors, 4) + conf_t = loc_data.new(batch_size, num_priors).long() + idx_t = loc_data.new(batch_size, num_priors).long() + + if cfg.use_class_existence_loss: + class_existence_t = loc_data.new(batch_size, num_classes - 1) + + for idx in range(batch_size): + truths = targets[idx][:, :-1].data + labels[idx] = targets[idx][:, -1].data.long() + + if cfg.use_class_existence_loss: + # Construct a one-hot vector for each object and collapse it into an existence vector with max + # Also it's fine to include the crowd annotations here + class_existence_t[idx, :] = \ + torch.eye(num_classes - 1, device=conf_t.get_device())[labels[idx]].max(dim=0)[0] + + # Split the crowd annotations because they come bundled in + cur_crowds = num_crowds[idx] + if cur_crowds > 0: + split = lambda x: (x[-cur_crowds:], x[:-cur_crowds]) + crowd_boxes, truths = split(truths) + + # We don't use the crowd labels or masks + _, labels[idx] = split(labels[idx]) + _, masks[idx] = split(masks[idx]) + else: + crowd_boxes = None + + match(self.pos_threshold, self.neg_threshold, + truths, priors.data, labels[idx], crowd_boxes, + loc_t, conf_t, idx_t, idx, loc_data[idx]) + + gt_box_t[idx, :, :] = truths[idx_t[idx]] + + # wrap targets + loc_t = Variable(loc_t, requires_grad=False) + conf_t = Variable(conf_t, requires_grad=False) + idx_t = Variable(idx_t, requires_grad=False) + + pos = conf_t > 0 + num_pos = pos.sum(dim=1, keepdim=True) + + # Shape: [batch,num_priors,4] + pos_idx = pos.unsqueeze(pos.dim()).expand_as(loc_data) + + losses = {} + + # Localization Loss (Smooth L1) + if cfg.train_boxes: + # loc_p = loc_data[pos_idx].view(-1, 4) + # loc_t = loc_t[pos_idx].view(-1, 4) + # losses['B'] = F.smooth_l1_loss(loc_p, loc_t, reduction='sum') * cfg.bbox_alpha + loc_p = loc_data.view(-1, 4) + loc_t = loc_t.view(-1, 4) + losses['B'] = F.smooth_l1_loss(loc_p, loc_t, reduction='none') * cfg.bbox_alpha + losses['B'][pos_idx.view(-1, 4) == False] = 0 + losses['B'] = losses['B'].sum() + + if cfg.train_masks: + if cfg.mask_type == mask_type.direct: + if cfg.use_gt_bboxes: + pos_masks = [] + for idx in range(batch_size): + pos_masks.append(masks[idx][idx_t[idx, pos[idx]]]) + masks_t = torch.cat(pos_masks, 0) + masks_p = mask_data[pos, :].view(-1, cfg.mask_dim) + losses['M'] = F.binary_cross_entropy(torch.clamp(masks_p, 0, 1), masks_t, + reduction='sum') * cfg.mask_alpha + else: + losses['M'] = self.direct_mask_loss(pos_idx, idx_t, loc_data, mask_data, priors, masks) + elif cfg.mask_type == mask_type.lincomb: + ret = self.lincomb_mask_loss(pos, idx_t, loc_data, mask_data, priors, proto_data, masks, gt_box_t, + score_data, inst_data, labels) + if cfg.use_maskiou: + loss, maskiou_targets = ret + else: + loss = ret + losses.update(loss) + + if cfg.mask_proto_loss is not None: + if cfg.mask_proto_loss == 'l1': + losses['P'] = torch.mean(torch.abs(proto_data)) / self.l1_expected_area * self.l1_alpha + elif cfg.mask_proto_loss == 'disj': + losses['P'] = -torch.mean(torch.max(F.log_softmax(proto_data, dim=-1), dim=-1)[0]) + + # Confidence loss + if cfg.use_focal_loss: + if cfg.use_sigmoid_focal_loss: + losses['C'] = self.focal_conf_sigmoid_loss(conf_data, conf_t) + elif cfg.use_objectness_score: + losses['C'] = self.focal_conf_objectness_loss(conf_data, conf_t) + else: + losses['C'] = self.focal_conf_loss(conf_data, conf_t) + else: + if cfg.use_objectness_score: + losses['C'] = self.conf_objectness_loss(conf_data, conf_t, batch_size, loc_p, loc_t, priors) + else: + losses['C'] = self.ohem_conf_loss(conf_data, conf_t, pos, batch_size) + + # Mask IoU Loss + if cfg.use_maskiou and maskiou_targets is not None: + losses['I'] = self.mask_iou_loss(net, maskiou_targets) + + # These losses also don't depend on anchors + if cfg.use_class_existence_loss: + losses['E'] = self.class_existence_loss(predictions['classes'], class_existence_t) + if cfg.use_semantic_segmentation_loss: + losses['S'] = self.semantic_segmentation_loss(predictions['segm'], masks, labels) + + # Divide all losses by the number of positives. + # Don't do it for loss[P] because that doesn't depend on the anchors. + total_num_pos = num_pos.data.sum().float() + for k in losses: + if k not in ('P', 'E', 'S'): + losses[k] /= total_num_pos + else: + losses[k] /= batch_size + + # Loss Key: + # - B: Box Localization Loss + # - C: Class Confidence Loss + # - M: Mask Loss + # - P: Prototype Loss + # - D: Coefficient Diversity Loss + # - E: Class Existence Loss + # - S: Semantic Segmentation Loss + return losses + + def class_existence_loss(self, class_data, class_existence_t): + return cfg.class_existence_alpha * F.binary_cross_entropy_with_logits(class_data, class_existence_t, + reduction='sum') + + def semantic_segmentation_loss(self, segment_data, mask_t, class_t, interpolation_mode='bilinear'): + # Note num_classes here is without the background class so cfg.num_classes-1 + batch_size, num_classes, mask_h, mask_w = segment_data.size() + loss_s = 0 + + for idx in range(batch_size): + cur_segment = segment_data[idx] + cur_class_t = class_t[idx] + + with torch.no_grad(): + downsampled_masks = F.interpolate(mask_t[idx].unsqueeze(0), (mask_h, mask_w), + mode=interpolation_mode, align_corners=False).squeeze(0) + downsampled_masks = downsampled_masks.gt(0.5).float() + + # Construct Semantic Segmentation + segment_t = torch.zeros_like(cur_segment, requires_grad=False) + for obj_idx in range(downsampled_masks.size(0)): + segment_t[cur_class_t[obj_idx]] = torch.max(segment_t[cur_class_t[obj_idx]].float(), + downsampled_masks[obj_idx]) + + loss_s += F.binary_cross_entropy_with_logits(cur_segment, segment_t, reduction='sum') + + return loss_s / mask_h / mask_w * cfg.semantic_segmentation_alpha + + def ohem_conf_loss(self, conf_data, conf_t, pos, num): + # Compute max conf across batch for hard negative mining + batch_conf = conf_data.view(-1, self.num_classes) + if cfg.ohem_use_most_confident: + # i.e. max(softmax) along classes > 0 + batch_conf = F.softmax(batch_conf, dim=1) + loss_c, _ = batch_conf[:, 1:].max(dim=1) + else: + # i.e. -softmax(class 0 confidence) + loss_c = log_sum_exp(batch_conf) - batch_conf[:, 0] + + # Hard Negative Mining + loss_c = loss_c.view(num, -1) + loss_c[pos] = 0 # filter out pos boxes + loss_c[conf_t < 0] = 0 # filter out neutrals (conf_t = -1) + _, loss_idx = loss_c.sort(1, descending=True) + _, idx_rank = loss_idx.sort(1) + num_pos = pos.long().sum(1, keepdim=True) + num_neg = torch.clamp(self.negpos_ratio * num_pos, max=pos.size(1) - 1) + neg = idx_rank < num_neg.expand_as(idx_rank) + + # Just in case there aren't enough negatives, don't start using positives as negatives + neg[pos] = 0 + neg[conf_t < 0] = 0 # Filter out neutrals + + # Confidence Loss Including Positive and Negative Examples + # pos_idx = pos.unsqueeze(2).expand_as(conf_data) + # neg_idx = neg.unsqueeze(2).expand_as(conf_data) + + # conf_p = conf_data[(pos_idx+neg_idx).gt(0)].view(-1, self.num_classes) + # targets_weighted = conf_t[(pos+neg).gt(0)] + ## loss_c = F.cross_entropy(conf_p, targets_weighted, reduction='none') + loss_c = F.cross_entropy(conf_data.view(-1, self.num_classes), conf_t.view(-1), reduction='none').view(-1, + 57744) + loss_c[(pos + neg).gt(0) == False] = 0 + + if cfg.use_class_balanced_conf: + # Lazy initialization + if self.class_instances is None: + self.class_instances = torch.zeros(self.num_classes, device=targets_weighted.device) + + classes, counts = targets_weighted.unique(return_counts=True) + + for _cls, _cnt in zip(classes.cpu().numpy(), counts.cpu().numpy()): + self.class_instances[_cls] += _cnt + + self.total_instances += targets_weighted.size(0) + + weighting = 1 - (self.class_instances[targets_weighted] / self.total_instances) + weighting = torch.clamp(weighting, min=1 / self.num_classes) + + # If you do the math, the average weight of self.class_instances is this + avg_weight = (self.num_classes - 1) / self.num_classes + + loss_c = (loss_c * weighting).sum() / avg_weight + else: + loss_c = loss_c.sum() + + return cfg.conf_alpha * loss_c + + def focal_conf_loss(self, conf_data, conf_t): + """ + Focal loss as described in https://arxiv.org/pdf/1708.02002.pdf + Adapted from https://github.com/clcarwin/focal_loss_pytorch/blob/master/focalloss.py + Note that this uses softmax and not the original sigmoid from the paper. + """ + conf_t = conf_t.view(-1) # [batch_size*num_priors] + conf_data = conf_data.view(-1, conf_data.size(-1)) # [batch_size*num_priors, num_classes] + + # Ignore neutral samples (class < 0) + keep = (conf_t >= 0).float() + conf_t[conf_t < 0] = 0 # so that gather doesn't drum up a fuss + + logpt = F.log_softmax(conf_data, dim=-1) + logpt = logpt.gather(1, conf_t.unsqueeze(-1)) + logpt = logpt.view(-1) + pt = logpt.exp() + + # I adapted the alpha_t calculation here from + # https://github.com/pytorch/pytorch/blob/master/modules/detectron/softmax_focal_loss_op.cu + # You'd think you want all the alphas to sum to one, but in the original implementation they + # just give background an alpha of 1-alpha and each forground an alpha of alpha. + background = (conf_t == 0).float() + at = (1 - cfg.focal_loss_alpha) * background + cfg.focal_loss_alpha * (1 - background) + + loss = -at * (1 - pt) ** cfg.focal_loss_gamma * logpt + + # See comment above for keep + return cfg.conf_alpha * (loss * keep).sum() + + def focal_conf_sigmoid_loss(self, conf_data, conf_t): + """ + Focal loss but using sigmoid like the original paper. + Note: To make things mesh easier, the network still predicts 81 class confidences in this mode. + Because retinanet originally only predicts 80, we simply just don't use conf_data[..., 0] + """ + num_classes = conf_data.size(-1) + + conf_t = conf_t.view(-1) # [batch_size*num_priors] + conf_data = conf_data.view(-1, num_classes) # [batch_size*num_priors, num_classes] + + # Ignore neutral samples (class < 0) + keep = (conf_t >= 0).float() + conf_t[conf_t < 0] = 0 # can't mask with -1, so filter that out + + # Compute a one-hot embedding of conf_t + # From https://github.com/kuangliu/pytorch-retinanet/blob/master/utils.py + conf_one_t = torch.eye(num_classes, device=conf_t.get_device())[conf_t] + conf_pm_t = conf_one_t * 2 - 1 # -1 if background, +1 if forground for specific class + + logpt = F.logsigmoid(conf_data * conf_pm_t) # note: 1 - sigmoid(x) = sigmoid(-x) + pt = logpt.exp() + + at = cfg.focal_loss_alpha * conf_one_t + (1 - cfg.focal_loss_alpha) * (1 - conf_one_t) + at[..., 0] = 0 # Set alpha for the background class to 0 because sigmoid focal loss doesn't use it + + loss = -at * (1 - pt) ** cfg.focal_loss_gamma * logpt + loss = keep * loss.sum(dim=-1) + + return cfg.conf_alpha * loss.sum() + + def focal_conf_objectness_loss(self, conf_data, conf_t): + """ + Instead of using softmax, use class[0] to be the objectness score and do sigmoid focal loss on that. + Then for the rest of the classes, softmax them and apply CE for only the positive examples. + + If class[0] = 1 implies forground and class[0] = 0 implies background then you achieve something + similar during test-time to softmax by setting class[1:] = softmax(class[1:]) * class[0] and invert class[0]. + """ + + conf_t = conf_t.view(-1) # [batch_size*num_priors] + conf_data = conf_data.view(-1, conf_data.size(-1)) # [batch_size*num_priors, num_classes] + + # Ignore neutral samples (class < 0) + keep = (conf_t >= 0).float() + conf_t[conf_t < 0] = 0 # so that gather doesn't drum up a fuss + + background = (conf_t == 0).float() + at = (1 - cfg.focal_loss_alpha) * background + cfg.focal_loss_alpha * (1 - background) + + logpt = F.logsigmoid(conf_data[:, 0]) * (1 - background) + F.logsigmoid(-conf_data[:, 0]) * background + pt = logpt.exp() + + obj_loss = -at * (1 - pt) ** cfg.focal_loss_gamma * logpt + + # All that was the objectiveness loss--now time for the class confidence loss + pos_mask = conf_t > 0 + conf_data_pos = (conf_data[:, 1:])[pos_mask] # Now this has just 80 classes + conf_t_pos = conf_t[pos_mask] - 1 # So subtract 1 here + + class_loss = F.cross_entropy(conf_data_pos, conf_t_pos, reduction='sum') + + return cfg.conf_alpha * (class_loss + (obj_loss * keep).sum()) + + def conf_objectness_loss(self, conf_data, conf_t, batch_size, loc_p, loc_t, priors): + """ + Instead of using softmax, use class[0] to be p(obj) * p(IoU) as in YOLO. + Then for the rest of the classes, softmax them and apply CE for only the positive examples. + """ + + conf_t = conf_t.view(-1) # [batch_size*num_priors] + conf_data = conf_data.view(-1, conf_data.size(-1)) # [batch_size*num_priors, num_classes] + + pos_mask = (conf_t > 0) + neg_mask = (conf_t == 0) + + obj_data = conf_data[:, 0] + obj_data_pos = obj_data[pos_mask] + obj_data_neg = obj_data[neg_mask] + + # Don't be confused, this is just binary cross entropy similified + obj_neg_loss = - F.logsigmoid(-obj_data_neg).sum() + + with torch.no_grad(): + pos_priors = priors.unsqueeze(0).expand(batch_size, -1, -1).reshape(-1, 4)[pos_mask, :] + + boxes_pred = decode(loc_p, pos_priors, cfg.use_yolo_regressors) + boxes_targ = decode(loc_t, pos_priors, cfg.use_yolo_regressors) + + iou_targets = elemwise_box_iou(boxes_pred, boxes_targ) + + obj_pos_loss = - iou_targets * F.logsigmoid(obj_data_pos) - (1 - iou_targets) * F.logsigmoid(-obj_data_pos) + obj_pos_loss = obj_pos_loss.sum() + + # All that was the objectiveness loss--now time for the class confidence loss + conf_data_pos = (conf_data[:, 1:])[pos_mask] # Now this has just 80 classes + conf_t_pos = conf_t[pos_mask] - 1 # So subtract 1 here + + class_loss = F.cross_entropy(conf_data_pos, conf_t_pos, reduction='sum') + + return cfg.conf_alpha * (class_loss + obj_pos_loss + obj_neg_loss) + + def direct_mask_loss(self, pos_idx, idx_t, loc_data, mask_data, priors, masks): + """ Crops the gt masks using the predicted bboxes, scales them down, and outputs the BCE loss. """ + loss_m = 0 + for idx in range(mask_data.size(0)): + with torch.no_grad(): + cur_pos_idx = pos_idx[idx, :, :] + cur_pos_idx_squeezed = cur_pos_idx[:, 1] + + # Shape: [num_priors, 4], decoded predicted bboxes + pos_bboxes = decode(loc_data[idx, :, :], priors.data, cfg.use_yolo_regressors) + pos_bboxes = pos_bboxes[cur_pos_idx].view(-1, 4).clamp(0, 1) + pos_lookup = idx_t[idx, cur_pos_idx_squeezed] + + cur_masks = masks[idx] + pos_masks = cur_masks[pos_lookup, :, :] + + # Convert bboxes to absolute coordinates + num_pos, img_height, img_width = pos_masks.size() + + # Take care of all the bad behavior that can be caused by out of bounds coordinates + x1, x2 = sanitize_coordinates(pos_bboxes[:, 0], pos_bboxes[:, 2], img_width) + y1, y2 = sanitize_coordinates(pos_bboxes[:, 1], pos_bboxes[:, 3], img_height) + + # Crop each gt mask with the predicted bbox and rescale to the predicted mask size + # Note that each bounding box crop is a different size so I don't think we can vectorize this + scaled_masks = [] + for jdx in range(num_pos): + tmp_mask = pos_masks[jdx, y1[jdx]:y2[jdx], x1[jdx]:x2[jdx]] + + # Restore any dimensions we've left out because our bbox was 1px wide + while tmp_mask.dim() < 2: + tmp_mask = tmp_mask.unsqueeze(0) + + new_mask = F.adaptive_avg_pool2d(tmp_mask.unsqueeze(0), cfg.mask_size) + scaled_masks.append(new_mask.view(1, -1)) + + mask_t = torch.cat(scaled_masks, 0).gt(0.5).float() # Threshold downsampled mask + + pos_mask_data = mask_data[idx, cur_pos_idx_squeezed, :] + loss_m += F.binary_cross_entropy(torch.clamp(pos_mask_data, 0, 1), mask_t, reduction='sum') * cfg.mask_alpha + + return loss_m + + def coeff_diversity_loss(self, coeffs, instance_t): + """ + coeffs should be size [num_pos, num_coeffs] + instance_t should be size [num_pos] and be values from 0 to num_instances-1 + """ + num_pos = coeffs.size(0) + instance_t = instance_t.view(-1) # juuuust to make sure + + coeffs_norm = F.normalize(coeffs, dim=1) + cos_sim = coeffs_norm @ coeffs_norm.t() + + inst_eq = (instance_t[:, None].expand_as(cos_sim) == instance_t[None, :].expand_as(cos_sim)).float() + + # Rescale to be between 0 and 1 + cos_sim = (cos_sim + 1) / 2 + + # If they're the same instance, use cosine distance, else use cosine similarity + loss = (1 - cos_sim) * inst_eq + cos_sim * (1 - inst_eq) + + # Only divide by num_pos once because we're summing over a num_pos x num_pos tensor + # and all the losses will be divided by num_pos at the end, so just one extra time. + return cfg.mask_proto_coeff_diversity_alpha * loss.sum() / num_pos + + def lincomb_mask_loss(self, pos, idx_t, loc_data, mask_data, priors, proto_data, masks, gt_box_t, score_data, + inst_data, labels, interpolation_mode='bilinear'): + mask_h = proto_data.size(1) + mask_w = proto_data.size(2) + + process_gt_bboxes = cfg.mask_proto_normalize_emulate_roi_pooling or cfg.mask_proto_crop + + if cfg.mask_proto_remove_empty_masks: + # Make sure to store a copy of this because we edit it to get rid of all-zero masks + pos = pos.clone() + + loss_m = 0 + loss_d = 0 # Coefficient diversity loss + + maskiou_t_list = [] + maskiou_net_input_list = [] + label_t_list = [] + + for idx in range(mask_data.size(0)): + with torch.no_grad(): + downsampled_masks = F.interpolate(masks[idx].unsqueeze(0), (mask_h, mask_w), + mode=interpolation_mode, align_corners=False).squeeze(0) + downsampled_masks = downsampled_masks.permute(1, 2, 0).contiguous() + if cfg.mask_proto_binarize_downsampled_gt: + downsampled_masks = downsampled_masks.gt(0.5).float() + + if cfg.mask_proto_remove_empty_masks: + # Get rid of gt masks that are so small they get downsampled away + very_small_masks = (downsampled_masks.sum(dim=(0, 1)) <= 0.0001) + for i in range(very_small_masks.size(0)): + if very_small_masks[i]: + pos[idx, idx_t[idx] == i] = 0 + if cfg.mask_proto_reweight_mask_loss: + # Ensure that the gt is binary + if not cfg.mask_proto_binarize_downsampled_gt: + bin_gt = downsampled_masks.gt(0.5).float() + else: + bin_gt = downsampled_masks + + gt_foreground_norm = bin_gt / (torch.sum(bin_gt, dim=(0, 1), keepdim=True) + 0.0001) + gt_background_norm = (1 - bin_gt) / (torch.sum(1 - bin_gt, dim=(0, 1), keepdim=True) + 0.0001) + + mask_reweighting = gt_foreground_norm * cfg.mask_proto_reweight_coeff + gt_background_norm + mask_reweighting *= mask_h * mask_w + + cur_pos = pos[idx] + pos_idx_t = idx_t[idx, cur_pos] + if process_gt_bboxes: + # Note: this is in point-form + if cfg.mask_proto_crop_with_pred_box: + pos_gt_box_t = decode(loc_data[idx, :, :], priors.data, cfg.use_yolo_regressors)[cur_pos] + else: + pos_gt_box_t = gt_box_t[idx, cur_pos] + if pos_idx_t.size(0) == 0: + continue + + proto_masks = proto_data[idx] + proto_coef = mask_data[idx, cur_pos, :] + if cfg.use_mask_scoring: + mask_scores = score_data[idx, cur_pos, :] + if cfg.mask_proto_coeff_diversity_loss: + if inst_data is not None: + div_coeffs = inst_data[idx, cur_pos, :] + else: + div_coeffs = proto_coef + + loss_d += self.coeff_diversity_loss(div_coeffs, pos_idx_t) + + # If we have over the allowed number of masks, select a random sample + old_num_pos = proto_coef.size(0) + if old_num_pos > cfg.masks_to_train: + perm = torch.randperm(proto_coef.size(0)) + select = perm[:cfg.masks_to_train] + + proto_coef = proto_coef[select, :] + pos_idx_t = pos_idx_t[select] + + if process_gt_bboxes: + pos_gt_box_t = pos_gt_box_t[select, :] + if cfg.use_mask_scoring: + mask_scores = mask_scores[select, :] + + num_pos = proto_coef.size(0) + mask_t = downsampled_masks[:, :, pos_idx_t] + label_t = labels[idx][pos_idx_t] + # Size: [mask_h, mask_w, num_pos] + pred_masks = proto_masks @ proto_coef.t() + pred_masks = cfg.mask_proto_mask_activation(pred_masks) + if cfg.mask_proto_double_loss: + if cfg.mask_proto_mask_activation == activation_func.sigmoid: + pre_loss = F.binary_cross_entropy(torch.clamp(pred_masks, 0, 1), mask_t, reduction='sum') + else: + pre_loss = F.smooth_l1_loss(pred_masks, mask_t, reduction='sum') + + loss_m += cfg.mask_proto_double_loss_alpha * pre_loss + + if cfg.mask_proto_crop: + pred_masks = crop(pred_masks, pos_gt_box_t) + + if cfg.mask_proto_mask_activation == activation_func.sigmoid: + pre_loss = F.binary_cross_entropy(torch.clamp(pred_masks, 0, 1), mask_t, reduction='none') + else: + pre_loss = F.smooth_l1_loss(pred_masks, mask_t, reduction='none') + + if cfg.mask_proto_normalize_mask_loss_by_sqrt_area: + gt_area = torch.sum(mask_t, dim=(0, 1), keepdim=True) + pre_loss = pre_loss / (torch.sqrt(gt_area) + 0.0001) + + if cfg.mask_proto_reweight_mask_loss: + pre_loss = pre_loss * mask_reweighting[:, :, pos_idx_t] + + if cfg.mask_proto_normalize_emulate_roi_pooling: + weight = mask_h * mask_w if cfg.mask_proto_crop else 1 + pos_gt_csize = center_size(pos_gt_box_t) + gt_box_width = pos_gt_csize[:, 2] * mask_w + gt_box_height = pos_gt_csize[:, 3] * mask_h + pre_loss = pre_loss.sum(dim=(0, 1)) / gt_box_width / gt_box_height * weight + + # If the number of masks were limited scale the loss accordingly + if old_num_pos > num_pos: + pre_loss *= old_num_pos / num_pos + + loss_m += torch.sum(pre_loss) + + if cfg.use_maskiou: + if cfg.discard_mask_area > 0: + gt_mask_area = torch.sum(mask_t, dim=(0, 1)) + + select = gt_mask_area > cfg.discard_mask_area + + if torch.sum(select) < 1: + continue + + + pos_gt_box_t = pos_gt_box_t[select, :] + pred_masks = pred_masks[:, :, select] + mask_t = mask_t[:, :, select] + label_t = label_t[select] + + maskiou_net_input = pred_masks.permute(2, 0, 1).contiguous().unsqueeze(1) + pred_masks = pred_masks.gt(0.5).float() + maskiou_t = self._mask_iou(pred_masks, mask_t) + + maskiou_net_input_list.append(maskiou_net_input) + maskiou_t_list.append(maskiou_t) + label_t_list.append(label_t) + + losses = {'M': loss_m * cfg.mask_alpha / mask_h / mask_w} + + if cfg.mask_proto_coeff_diversity_loss: + losses['D'] = loss_d + + if cfg.use_maskiou: + # discard_mask_area discarded every mask in the batch, so nothing to do here + if len(maskiou_t_list) == 0: + return losses, None + + maskiou_t = torch.cat(maskiou_t_list) + label_t = torch.cat(label_t_list) + maskiou_net_input = torch.cat(maskiou_net_input_list) + + num_samples = maskiou_t.size(0) + if cfg.maskious_to_train > 0 and num_samples > cfg.maskious_to_train: + perm = torch.randperm(num_samples) + select = perm[:cfg.masks_to_train] + maskiou_t = maskiou_t[select] + label_t = label_t[select] + maskiou_net_input = maskiou_net_input[select] + + return losses, [maskiou_net_input, maskiou_t, label_t] + + return losses + + def _mask_iou(self, mask1, mask2): + intersection = torch.sum(mask1 * mask2, dim=(0, 1)) + area1 = torch.sum(mask1, dim=(0, 1)) + area2 = torch.sum(mask2, dim=(0, 1)) + union = (area1 + area2) - intersection + ret = intersection / union + return ret + + def mask_iou_loss(self, net, maskiou_targets): + maskiou_net_input, maskiou_t, label_t = maskiou_targets + + maskiou_p = net.maskiou_net(maskiou_net_input) + + label_t = label_t[:, None] + maskiou_p = torch.gather(maskiou_p, dim=1, index=label_t).view(-1) + + loss_i = F.smooth_l1_loss(maskiou_p, maskiou_t, reduction='sum') + + return loss_i * cfg.maskiou_alpha diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/output_utils.py b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/output_utils.py index f84c02899d578889003174a39ee69ca0201d45cd..dbda93adba3a5800e6c6d0a09fde22af4bfa208e 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/layers/output_utils.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/layers/output_utils.py @@ -1,200 +1,200 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -""" Contains functions used to sanitize and prepare the output of Yolact. """ - - -import torch -import torch.nn as nn -import torch.nn.functional as F -import numpy as np -import cv2 - -from data import cfg, mask_type, MEANS, STD, activation_func -from utils.augmentations import Resize -from utils import timer -from .box_utils import crop, sanitize_coordinates - -def postprocess(det_output, w, h, batch_idx=0, interpolation_mode='bilinear', - visualize_lincomb=False, crop_masks=True, score_threshold=0): - """ - Postprocesses the output of Yolact on testing mode into a format that makes sense, - accounting for all the possible configuration settings. - - Args: - - det_output: The lost of dicts that Detect outputs. - - w: The real with of the image. - - h: The real height of the image. - - batch_idx: If you have multiple images for this batch, the image's index in the batch. - - interpolation_mode: Can be 'nearest' | 'area' | 'bilinear' (see torch.nn.functional.interpolate) - - Returns 4 torch Tensors (in the following order): - - classes [num_det]: The class idx for each detection. - - scores [num_det]: The confidence score for each detection. - - boxes [num_det, 4]: The bounding box for each detection in absolute point form. - - masks [num_det, h, w]: Full image masks for each detection. - """ - - dets = det_output[batch_idx] - - if dets is None: - return [torch.Tensor()] * 4 # Warning, this is 4 copies of the same thing - - if score_threshold > 0: - keep = dets['score'] > score_threshold - - for k in dets: - if k != 'proto': - dets[k] = dets[k][keep] - - if dets['score'].size(0) == 0: - return [torch.Tensor()] * 4 - - # Actually extract everything from dets now - classes = dets['class'] - boxes = dets['box'] - scores = dets['score'] - masks = dets['mask'] - - if cfg.mask_type == mask_type.lincomb and cfg.eval_mask_branch: - # At this points masks is only the coefficients - proto_data = dets['proto'] - - # Test flag, do not upvote - if cfg.mask_proto_debug: - np.save('scripts/proto.npy', proto_data.cpu().numpy()) - - if visualize_lincomb: - display_lincomb(proto_data, masks) - - masks = proto_data @ masks.t() - masks = cfg.mask_proto_mask_activation(masks) - - # Crop masks before upsampling because you know why - if crop_masks: - masks = crop(masks, boxes) - - # Permute into the correct output shape [num_dets, proto_h, proto_w] - masks = masks.permute(2, 0, 1).contiguous() - - if cfg.use_maskiou: - with timer.env('maskiou_net'): - with torch.no_grad(): - maskiou_p = net.maskiou_net(masks.unsqueeze(1)) - maskiou_p = torch.gather(maskiou_p, dim=1, index=classes.unsqueeze(1)).squeeze(1) - if cfg.rescore_mask: - if cfg.rescore_bbox: - scores = scores * maskiou_p - else: - scores = [scores, scores * maskiou_p] - - # Scale masks up to the full image - masks = F.interpolate(masks.unsqueeze(0), (h, w), mode=interpolation_mode, align_corners=False).squeeze(0) - - # Binarize the masks - masks.gt_(0.5) - - - boxes[:, 0], boxes[:, 2] = sanitize_coordinates(boxes[:, 0], boxes[:, 2], w, cast=False) - boxes[:, 1], boxes[:, 3] = sanitize_coordinates(boxes[:, 1], boxes[:, 3], h, cast=False) - boxes = boxes.long() - - if cfg.mask_type == mask_type.direct and cfg.eval_mask_branch: - # Upscale masks - full_masks = torch.zeros(masks.size(0), h, w) - - for jdx in range(masks.size(0)): - x1, y1, x2, y2 = boxes[jdx, :] - - mask_w = x2 - x1 - mask_h = y2 - y1 - - # Just in case - if mask_w * mask_h <= 0 or mask_w < 0: - continue - - mask = masks[jdx, :].view(1, 1, cfg.mask_size, cfg.mask_size) - mask = F.interpolate(mask, (mask_h, mask_w), mode=interpolation_mode, align_corners=False) - mask = mask.gt(0.5).float() - full_masks[jdx, y1:y2, x1:x2] = mask - - masks = full_masks - - return classes, scores, boxes, masks - - - - - -def undo_image_transformation(img, w, h): - """ - Takes a transformed image tensor and returns a numpy ndarray that is untransformed. - Arguments w and h are the original height and width of the image. - """ - img_numpy = img.permute(1, 2, 0).cpu().numpy() - img_numpy = img_numpy[:, :, (2, 1, 0)] # To BRG - - if cfg.backbone.transform.normalize: - img_numpy = (img_numpy * np.array(STD) + np.array(MEANS)) / 255.0 - elif cfg.backbone.transform.subtract_means: - img_numpy = (img_numpy / 255.0 + np.array(MEANS) / 255.0).astype(np.float32) - - img_numpy = img_numpy[:, :, (2, 1, 0)] # To RGB - img_numpy = np.clip(img_numpy, 0, 1) - - return cv2.resize(img_numpy, (w,h)) - - -def display_lincomb(proto_data, masks): - out_masks = torch.matmul(proto_data, masks.t()) - # out_masks = cfg.mask_proto_mask_activation(out_masks) - - for kdx in range(1): - jdx = kdx + 0 - import matplotlib.pyplot as plt - coeffs = masks[jdx, :].cpu().numpy() - idx = np.argsort(-np.abs(coeffs)) - # plt.bar(list(range(idx.shape[0])), coeffs[idx]) - # plt.show() - - coeffs_sort = coeffs[idx] - arr_h, arr_w = (4,8) - proto_h, proto_w, _ = proto_data.size() - arr_img = np.zeros([proto_h*arr_h, proto_w*arr_w]) - arr_run = np.zeros([proto_h*arr_h, proto_w*arr_w]) - test = torch.sum(proto_data, -1).cpu().numpy() - - for y in range(arr_h): - for x in range(arr_w): - i = arr_w * y + x - - if i == 0: - running_total = proto_data[:, :, idx[i]].cpu().numpy() * coeffs_sort[i] - else: - running_total += proto_data[:, :, idx[i]].cpu().numpy() * coeffs_sort[i] - - running_total_nonlin = running_total - if cfg.mask_proto_mask_activation == activation_func.sigmoid: - running_total_nonlin = (1/(1+np.exp(-running_total_nonlin))) - - arr_img[y*proto_h:(y+1)*proto_h, x*proto_w:(x+1)*proto_w] = (proto_data[:, :, idx[i]] / torch.max(proto_data[:, :, idx[i]])).cpu().numpy() * coeffs_sort[i] - arr_run[y*proto_h:(y+1)*proto_h, x*proto_w:(x+1)*proto_w] = (running_total_nonlin > 0.5).astype(np.float) - plt.imshow(arr_img) - plt.show() - # plt.imshow(arr_run) - # plt.show() - # plt.imshow(test) - # plt.show() - plt.imshow(out_masks[:, :, jdx].cpu().numpy()) - plt.show() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +""" Contains functions used to sanitize and prepare the output of Yolact. """ + + +import torch +import torch.nn as nn +import torch.nn.functional as F +import numpy as np +import cv2 + +from data import cfg, mask_type, MEANS, STD, activation_func +from utils.augmentations import Resize +from utils import timer +from .box_utils import crop, sanitize_coordinates + +def postprocess(det_output, w, h, batch_idx=0, interpolation_mode='bilinear', + visualize_lincomb=False, crop_masks=True, score_threshold=0): + """ + Postprocesses the output of Yolact on testing mode into a format that makes sense, + accounting for all the possible configuration settings. + + Args: + - det_output: The lost of dicts that Detect outputs. + - w: The real with of the image. + - h: The real height of the image. + - batch_idx: If you have multiple images for this batch, the image's index in the batch. + - interpolation_mode: Can be 'nearest' | 'area' | 'bilinear' (see torch.nn.functional.interpolate) + + Returns 4 torch Tensors (in the following order): + - classes [num_det]: The class idx for each detection. + - scores [num_det]: The confidence score for each detection. + - boxes [num_det, 4]: The bounding box for each detection in absolute point form. + - masks [num_det, h, w]: Full image masks for each detection. + """ + + dets = det_output[batch_idx] + + if dets is None: + return [torch.Tensor()] * 4 # Warning, this is 4 copies of the same thing + + if score_threshold > 0: + keep = dets['score'] > score_threshold + + for k in dets: + if k != 'proto': + dets[k] = dets[k][keep] + + if dets['score'].size(0) == 0: + return [torch.Tensor()] * 4 + + # Actually extract everything from dets now + classes = dets['class'] + boxes = dets['box'] + scores = dets['score'] + masks = dets['mask'] + + if cfg.mask_type == mask_type.lincomb and cfg.eval_mask_branch: + # At this points masks is only the coefficients + proto_data = dets['proto'] + + # Test flag, do not upvote + if cfg.mask_proto_debug: + np.save('scripts/proto.npy', proto_data.cpu().numpy()) + + if visualize_lincomb: + display_lincomb(proto_data, masks) + + masks = proto_data @ masks.t() + masks = cfg.mask_proto_mask_activation(masks) + + # Crop masks before upsampling because you know why + if crop_masks: + masks = crop(masks, boxes) + + # Permute into the correct output shape [num_dets, proto_h, proto_w] + masks = masks.permute(2, 0, 1).contiguous() + + if cfg.use_maskiou: + with timer.env('maskiou_net'): + with torch.no_grad(): + maskiou_p = net.maskiou_net(masks.unsqueeze(1)) + maskiou_p = torch.gather(maskiou_p, dim=1, index=classes.unsqueeze(1)).squeeze(1) + if cfg.rescore_mask: + if cfg.rescore_bbox: + scores = scores * maskiou_p + else: + scores = [scores, scores * maskiou_p] + + # Scale masks up to the full image + masks = F.interpolate(masks.unsqueeze(0), (h, w), mode=interpolation_mode, align_corners=False).squeeze(0) + + # Binarize the masks + masks.gt_(0.5) + + + boxes[:, 0], boxes[:, 2] = sanitize_coordinates(boxes[:, 0], boxes[:, 2], w, cast=False) + boxes[:, 1], boxes[:, 3] = sanitize_coordinates(boxes[:, 1], boxes[:, 3], h, cast=False) + boxes = boxes.long() + + if cfg.mask_type == mask_type.direct and cfg.eval_mask_branch: + # Upscale masks + full_masks = torch.zeros(masks.size(0), h, w) + + for jdx in range(masks.size(0)): + x1, y1, x2, y2 = boxes[jdx, :] + + mask_w = x2 - x1 + mask_h = y2 - y1 + + # Just in case + if mask_w * mask_h <= 0 or mask_w < 0: + continue + + mask = masks[jdx, :].view(1, 1, cfg.mask_size, cfg.mask_size) + mask = F.interpolate(mask, (mask_h, mask_w), mode=interpolation_mode, align_corners=False) + mask = mask.gt(0.5).float() + full_masks[jdx, y1:y2, x1:x2] = mask + + masks = full_masks + + return classes, scores, boxes, masks + + + + + +def undo_image_transformation(img, w, h): + """ + Takes a transformed image tensor and returns a numpy ndarray that is untransformed. + Arguments w and h are the original height and width of the image. + """ + img_numpy = img.permute(1, 2, 0).cpu().numpy() + img_numpy = img_numpy[:, :, (2, 1, 0)] # To BRG + + if cfg.backbone.transform.normalize: + img_numpy = (img_numpy * np.array(STD) + np.array(MEANS)) / 255.0 + elif cfg.backbone.transform.subtract_means: + img_numpy = (img_numpy / 255.0 + np.array(MEANS) / 255.0).astype(np.float32) + + img_numpy = img_numpy[:, :, (2, 1, 0)] # To RGB + img_numpy = np.clip(img_numpy, 0, 1) + + return cv2.resize(img_numpy, (w,h)) + + +def display_lincomb(proto_data, masks): + out_masks = torch.matmul(proto_data, masks.t()) + # out_masks = cfg.mask_proto_mask_activation(out_masks) + + for kdx in range(1): + jdx = kdx + 0 + import matplotlib.pyplot as plt + coeffs = masks[jdx, :].cpu().numpy() + idx = np.argsort(-np.abs(coeffs)) + # plt.bar(list(range(idx.shape[0])), coeffs[idx]) + # plt.show() + + coeffs_sort = coeffs[idx] + arr_h, arr_w = (4,8) + proto_h, proto_w, _ = proto_data.size() + arr_img = np.zeros([proto_h*arr_h, proto_w*arr_w]) + arr_run = np.zeros([proto_h*arr_h, proto_w*arr_w]) + test = torch.sum(proto_data, -1).cpu().numpy() + + for y in range(arr_h): + for x in range(arr_w): + i = arr_w * y + x + + if i == 0: + running_total = proto_data[:, :, idx[i]].cpu().numpy() * coeffs_sort[i] + else: + running_total += proto_data[:, :, idx[i]].cpu().numpy() * coeffs_sort[i] + + running_total_nonlin = running_total + if cfg.mask_proto_mask_activation == activation_func.sigmoid: + running_total_nonlin = (1/(1+np.exp(-running_total_nonlin))) + + arr_img[y*proto_h:(y+1)*proto_h, x*proto_w:(x+1)*proto_w] = (proto_data[:, :, idx[i]] / torch.max(proto_data[:, :, idx[i]])).cpu().numpy() * coeffs_sort[i] + arr_run[y*proto_h:(y+1)*proto_h, x*proto_w:(x+1)*proto_w] = (running_total_nonlin > 0.5).astype(np.float) + plt.imshow(arr_img) + plt.show() + # plt.imshow(arr_run) + # plt.show() + # plt.imshow(test) + # plt.show() + plt.imshow(out_masks[:, :, jdx].cpu().numpy()) + plt.show() diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/modelzoo_level.txt b/PyTorch/contrib/cv/detection/YOLACT_plus/modelzoo_level.txt index 0bfa93c4ef64e409485139f9c4153f9d3f660a34..59d0003ba877b641b70b96d465943c6acb16ef7e 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/modelzoo_level.txt +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/modelzoo_level.txt @@ -1,6 +1,6 @@ -GPUStatus:OK -NPUMigrationStatus:OK -FuncStatus:OK -PrecisionStatus:OK -AutoTune:POK +GPUStatus:OK +NPUMigrationStatus:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:POK PerfStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/augment_bbox.py b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/augment_bbox.py index 8688f4f2806fc99dc5c2c36c19dc2a2c8b35e12f..d823a92822d0589d7341ac2f0079222f9fcdc8cb 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/augment_bbox.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/augment_bbox.py @@ -1,184 +1,184 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import os.path as osp -import json, pickle -import sys -from math import sqrt -from itertools import product -import torch -from numpy import random - -import numpy as np - - -max_image_size = 550 -augment_idx = 0 -dump_file = 'weights/bboxes_aug.pkl' -box_file = 'weights/bboxes.pkl' - -def augment_boxes(bboxes): - bboxes_rel = [] - for box in bboxes: - bboxes_rel.append(prep_box(box)) - bboxes_rel = np.concatenate(bboxes_rel, axis=0) - - with open(dump_file, 'wb') as f: - pickle.dump(bboxes_rel, f) - -def prep_box(box_list): - global augment_idx - boxes = np.array([box_list[2:]], dtype=np.float32) - - # Image width and height - width, height = box_list[:2] - - # To point form - boxes[:, 2:] += boxes[:, :2] - - - # Expand - ratio = random.uniform(1, 4) - left = random.uniform(0, width*ratio - width) - top = random.uniform(0, height*ratio - height) - - height *= ratio - width *= ratio - - boxes[:, :2] += (int(left), int(top)) - boxes[:, 2:] += (int(left), int(top)) - - - # RandomSampleCrop - height, width, boxes = random_sample_crop(height, width, boxes) - - - # RandomMirror - if random.randint(0, 2): - boxes[:, 0::2] = width - boxes[:, 2::-2] - - - # Resize - boxes[:, [0, 2]] *= (max_image_size / width) - boxes[:, [1, 3]] *= (max_image_size / height) - width = height = max_image_size - - - # ToPercentCoords - boxes[:, [0, 2]] /= width - boxes[:, [1, 3]] /= height - - if augment_idx % 50000 == 0: - print('Current idx: %d' % augment_idx) - - augment_idx += 1 - - return boxes - - - - -sample_options = ( - # using entire original input image - None, - # sample a patch s.t. MIN jaccard w/ obj in .1,.3,.4,.7,.9 - (0.1, None), - (0.3, None), - (0.7, None), - (0.9, None), - # randomly sample a patch - (None, None), -) - -def intersect(box_a, box_b): - max_xy = np.minimum(box_a[:, 2:], box_b[2:]) - min_xy = np.maximum(box_a[:, :2], box_b[:2]) - inter = np.clip((max_xy - min_xy), a_min=0, a_max=np.inf) - return inter[:, 0] * inter[:, 1] - - -def jaccard_numpy(box_a, box_b): - """Compute the jaccard overlap of two sets of boxes. The jaccard overlap - is simply the intersection over union of two boxes. - E.g.: - A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) - Args: - box_a: Multiple bounding boxes, Shape: [num_boxes,4] - box_b: Single bounding box, Shape: [4] - Return: - jaccard overlap: Shape: [box_a.shape[0], box_a.shape[1]] - """ - inter = intersect(box_a, box_b) - area_a = ((box_a[:, 2]-box_a[:, 0]) * - (box_a[:, 3]-box_a[:, 1])) # [A,B] - area_b = ((box_b[2]-box_b[0]) * - (box_b[3]-box_b[1])) # [A,B] - union = area_a + area_b - inter - return inter / union # [A,B] - - -def random_sample_crop(height, width, boxes=None): - global sample_options - - while True: - # randomly choose a mode - mode = random.choice(sample_options) - if mode is None: - return height, width, boxes - - min_iou, max_iou = mode - if min_iou is None: - min_iou = float('-inf') - if max_iou is None: - max_iou = float('inf') - - for _ in range(50): - w = random.uniform(0.3 * width, width) - h = random.uniform(0.3 * height, height) - - if h / w < 0.5 or h / w > 2: - continue - - left = random.uniform(0, width - w) - top = random.uniform(0, height - h) - - rect = np.array([int(left), int(top), int(left+w), int(top+h)]) - overlap = jaccard_numpy(boxes, rect) - if overlap.min() < min_iou and max_iou < overlap.max(): - continue - - centers = (boxes[:, :2] + boxes[:, 2:]) / 2.0 - - m1 = (rect[0] < centers[:, 0]) * (rect[1] < centers[:, 1]) - m2 = (rect[2] > centers[:, 0]) * (rect[3] > centers[:, 1]) - mask = m1 * m2 - - if not mask.any(): - continue - - current_boxes = boxes[mask, :].copy() - current_boxes[:, :2] = np.maximum(current_boxes[:, :2], rect[:2]) - current_boxes[:, :2] -= rect[:2] - current_boxes[:, 2:] = np.minimum(current_boxes[:, 2:], rect[2:]) - current_boxes[:, 2:] -= rect[:2] - - return h, w, current_boxes - - -if __name__ == '__main__': - - with open(box_file, 'rb') as f: - bboxes = pickle.load(f) - - augment_boxes(bboxes) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import os.path as osp +import json, pickle +import sys +from math import sqrt +from itertools import product +import torch +from numpy import random + +import numpy as np + + +max_image_size = 550 +augment_idx = 0 +dump_file = 'weights/bboxes_aug.pkl' +box_file = 'weights/bboxes.pkl' + +def augment_boxes(bboxes): + bboxes_rel = [] + for box in bboxes: + bboxes_rel.append(prep_box(box)) + bboxes_rel = np.concatenate(bboxes_rel, axis=0) + + with open(dump_file, 'wb') as f: + pickle.dump(bboxes_rel, f) + +def prep_box(box_list): + global augment_idx + boxes = np.array([box_list[2:]], dtype=np.float32) + + # Image width and height + width, height = box_list[:2] + + # To point form + boxes[:, 2:] += boxes[:, :2] + + + # Expand + ratio = random.uniform(1, 4) + left = random.uniform(0, width*ratio - width) + top = random.uniform(0, height*ratio - height) + + height *= ratio + width *= ratio + + boxes[:, :2] += (int(left), int(top)) + boxes[:, 2:] += (int(left), int(top)) + + + # RandomSampleCrop + height, width, boxes = random_sample_crop(height, width, boxes) + + + # RandomMirror + if random.randint(0, 2): + boxes[:, 0::2] = width - boxes[:, 2::-2] + + + # Resize + boxes[:, [0, 2]] *= (max_image_size / width) + boxes[:, [1, 3]] *= (max_image_size / height) + width = height = max_image_size + + + # ToPercentCoords + boxes[:, [0, 2]] /= width + boxes[:, [1, 3]] /= height + + if augment_idx % 50000 == 0: + print('Current idx: %d' % augment_idx) + + augment_idx += 1 + + return boxes + + + + +sample_options = ( + # using entire original input image + None, + # sample a patch s.t. MIN jaccard w/ obj in .1,.3,.4,.7,.9 + (0.1, None), + (0.3, None), + (0.7, None), + (0.9, None), + # randomly sample a patch + (None, None), +) + +def intersect(box_a, box_b): + max_xy = np.minimum(box_a[:, 2:], box_b[2:]) + min_xy = np.maximum(box_a[:, :2], box_b[:2]) + inter = np.clip((max_xy - min_xy), a_min=0, a_max=np.inf) + return inter[:, 0] * inter[:, 1] + + +def jaccard_numpy(box_a, box_b): + """Compute the jaccard overlap of two sets of boxes. The jaccard overlap + is simply the intersection over union of two boxes. + E.g.: + A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) + Args: + box_a: Multiple bounding boxes, Shape: [num_boxes,4] + box_b: Single bounding box, Shape: [4] + Return: + jaccard overlap: Shape: [box_a.shape[0], box_a.shape[1]] + """ + inter = intersect(box_a, box_b) + area_a = ((box_a[:, 2]-box_a[:, 0]) * + (box_a[:, 3]-box_a[:, 1])) # [A,B] + area_b = ((box_b[2]-box_b[0]) * + (box_b[3]-box_b[1])) # [A,B] + union = area_a + area_b - inter + return inter / union # [A,B] + + +def random_sample_crop(height, width, boxes=None): + global sample_options + + while True: + # randomly choose a mode + mode = random.choice(sample_options) + if mode is None: + return height, width, boxes + + min_iou, max_iou = mode + if min_iou is None: + min_iou = float('-inf') + if max_iou is None: + max_iou = float('inf') + + for _ in range(50): + w = random.uniform(0.3 * width, width) + h = random.uniform(0.3 * height, height) + + if h / w < 0.5 or h / w > 2: + continue + + left = random.uniform(0, width - w) + top = random.uniform(0, height - h) + + rect = np.array([int(left), int(top), int(left+w), int(top+h)]) + overlap = jaccard_numpy(boxes, rect) + if overlap.min() < min_iou and max_iou < overlap.max(): + continue + + centers = (boxes[:, :2] + boxes[:, 2:]) / 2.0 + + m1 = (rect[0] < centers[:, 0]) * (rect[1] < centers[:, 1]) + m2 = (rect[2] > centers[:, 0]) * (rect[3] > centers[:, 1]) + mask = m1 * m2 + + if not mask.any(): + continue + + current_boxes = boxes[mask, :].copy() + current_boxes[:, :2] = np.maximum(current_boxes[:, :2], rect[:2]) + current_boxes[:, :2] -= rect[:2] + current_boxes[:, 2:] = np.minimum(current_boxes[:, 2:], rect[2:]) + current_boxes[:, 2:] -= rect[:2] + + return h, w, current_boxes + + +if __name__ == '__main__': + + with open(box_file, 'rb') as f: + bboxes = pickle.load(f) + + augment_boxes(bboxes) diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/bbox_recall.py b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/bbox_recall.py index b9d2565ff51ce110e73f842cd4308e427f23f287..3a2745760cbea5fae74858f27d90ce0db75106cb 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/bbox_recall.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/bbox_recall.py @@ -1,195 +1,195 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -""" -This script compiles all the bounding boxes in the training data and -clusters them for each convout resolution on which they're used. - -Run this script from the Yolact root directory. -""" - -import os.path as osp -import json, pickle -import sys -from math import sqrt -from itertools import product -import torch -import random - -import numpy as np - -dump_file = 'weights/bboxes.pkl' -aug_file = 'weights/bboxes_aug.pkl' - -use_augmented_boxes = True - - -def intersect(box_a, box_b): - """ We resize both tensors to [A,B,2] without new malloc: - [A,2] -> [A,1,2] -> [A,B,2] - [B,2] -> [1,B,2] -> [A,B,2] - Then we compute the area of intersect between box_a and box_b. - Args: - box_a: (tensor) bounding boxes, Shape: [A,4]. - box_b: (tensor) bounding boxes, Shape: [B,4]. - Return: - (tensor) intersection area, Shape: [A,B]. - """ - A = box_a.size(0) - B = box_b.size(0) - max_xy = torch.min(box_a[:, 2:].unsqueeze(1).expand(A, B, 2), - box_b[:, 2:].unsqueeze(0).expand(A, B, 2)) - min_xy = torch.max(box_a[:, :2].unsqueeze(1).expand(A, B, 2), - box_b[:, :2].unsqueeze(0).expand(A, B, 2)) - inter = torch.clamp((max_xy - min_xy), min=0) - return inter[:, :, 0] * inter[:, :, 1] - - -def jaccard(box_a, box_b, iscrowd=False): - """Compute the jaccard overlap of two sets of boxes. The jaccard overlap - is simply the intersection over union of two boxes. Here we operate on - ground truth boxes and default boxes. If iscrowd=True, put the crowd in box_b. - E.g.: - A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) - Args: - box_a: (tensor) Ground truth bounding boxes, Shape: [num_objects,4] - box_b: (tensor) Prior boxes from priorbox layers, Shape: [num_priors,4] - Return: - jaccard overlap: (tensor) Shape: [box_a.size(0), box_b.size(0)] - """ - inter = intersect(box_a, box_b) - area_a = ((box_a[:, 2]-box_a[:, 0]) * - (box_a[:, 3]-box_a[:, 1])).unsqueeze(1).expand_as(inter) # [A,B] - area_b = ((box_b[:, 2]-box_b[:, 0]) * - (box_b[:, 3]-box_b[:, 1])).unsqueeze(0).expand_as(inter) # [A,B] - union = area_a + area_b - inter - - if iscrowd: - return inter / area_a - else: - return inter / union # [A,B] - -# Also convert to point form -def to_relative(bboxes): - return np.concatenate((bboxes[:, 2:4] / bboxes[:, :2], (bboxes[:, 2:4] + bboxes[:, 4:]) / bboxes[:, :2]), axis=1) - - -def make_priors(conv_size, scales, aspect_ratios): - prior_data = [] - conv_h = conv_size[0] - conv_w = conv_size[1] - - # Iteration order is important (it has to sync up with the convout) - for j, i in product(range(conv_h), range(conv_w)): - x = (i + 0.5) / conv_w - y = (j + 0.5) / conv_h - - for scale, ars in zip(scales, aspect_ratios): - for ar in ars: - w = scale * ar / conv_w - h = scale / ar / conv_h - - # Point form - prior_data += [x - w/2, y - h/2, x + w/2, y + h/2] - - return np.array(prior_data).reshape(-1, 4) - -# fixed_ssd_config -# scales = [[3.5, 4.95], [3.6, 4.90], [3.3, 4.02], [2.7, 3.10], [2.1, 2.37], [2.1, 2.37], [1.8, 1.92]] -# aspect_ratios = [ [[1, sqrt(2), 1/sqrt(2), sqrt(3), 1/sqrt(3)][:n], [1]] for n in [3, 5, 5, 5, 3, 3, 3] ] -# conv_sizes = [(35, 35), (18, 18), (9, 9), (5, 5), (3, 3), (2, 2)] - -scales = [[1.68, 2.91], - [2.95, 2.22, 0.84], - [2.23, 2.17, 3.12], - [0.76, 1.94, 2.72], - [2.10, 2.65], - [1.80, 1.92]] -aspect_ratios = [[[0.72, 0.96], [0.68, 1.17]], - [[1.28, 0.66], [0.63, 1.23], [0.89, 1.40]], - [[2.05, 1.24], [0.57, 0.83], [0.61, 1.15]], - [[1.00, 2.21], [0.47, 1.60], [1.44, 0.79]], - [[1.00, 1.41, 0.71, 1.73, 0.58], [1.08]], - [[1.00, 1.41, 0.71, 1.73, 0.58], [1.00]]] -conv_sizes = [(35, 35), (18, 18), (9, 9), (5, 5), (3, 3), (2, 2)] - -# yrm33_config -# scales = [ [5.3] ] * 5 -# aspect_ratios = [ [[1, 1/sqrt(2), sqrt(2)]] ]*5 -# conv_sizes = [(136, 136), (67, 67), (33, 33), (16, 16), (8, 8)] - - -SMALL = 0 -MEDIUM = 1 -LARGE = 2 - -if __name__ == '__main__': - - with open(dump_file, 'rb') as f: - bboxes = pickle.load(f) - - sizes = [] - smalls = [] - for i in range(len(bboxes)): - area = bboxes[i][4] * bboxes[i][5] - if area < 32 ** 2: - sizes.append(SMALL) - smalls.append(area) - elif area < 96 ** 2: - sizes.append(MEDIUM) - else: - sizes.append(LARGE) - - # Each box is in the form [im_w, im_h, pos_x, pos_y, size_x, size_y] - - if use_augmented_boxes: - with open(aug_file, 'rb') as f: - bboxes_rel = pickle.load(f) - else: - bboxes_rel = to_relative(np.array(bboxes)) - - - with torch.no_grad(): - sizes = torch.Tensor(sizes) - - anchors = [make_priors(cs, s, ar) for cs, s, ar in zip(conv_sizes, scales, aspect_ratios)] - anchors = np.concatenate(anchors, axis=0) - anchors = torch.Tensor(anchors).cuda() - - bboxes_rel = torch.Tensor(bboxes_rel).cuda() - perGTAnchorMax = torch.zeros(bboxes_rel.shape[0]).cuda() - - chunk_size = 1000 - for i in range((bboxes_rel.size(0) // chunk_size) + 1): - start = i * chunk_size - end = min((i + 1) * chunk_size, bboxes_rel.size(0)) - - ious = jaccard(bboxes_rel[start:end, :], anchors) - maxes, maxidx = torch.max(ious, dim=1) - - perGTAnchorMax[start:end] = maxes - - - hits = (perGTAnchorMax > 0.5).float() - - print('Total recall: %.2f' % (torch.sum(hits) / hits.size(0) * 100)) - print() - - for i, metric in zip(range(3), ('small', 'medium', 'large')): - _hits = hits[sizes == i] - _size = (1 if _hits.size(0) == 0 else _hits.size(0)) - print(metric + ' recall: %.2f' % ((torch.sum(_hits) / _size) * 100)) - - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +""" +This script compiles all the bounding boxes in the training data and +clusters them for each convout resolution on which they're used. + +Run this script from the Yolact root directory. +""" + +import os.path as osp +import json, pickle +import sys +from math import sqrt +from itertools import product +import torch +import random + +import numpy as np + +dump_file = 'weights/bboxes.pkl' +aug_file = 'weights/bboxes_aug.pkl' + +use_augmented_boxes = True + + +def intersect(box_a, box_b): + """ We resize both tensors to [A,B,2] without new malloc: + [A,2] -> [A,1,2] -> [A,B,2] + [B,2] -> [1,B,2] -> [A,B,2] + Then we compute the area of intersect between box_a and box_b. + Args: + box_a: (tensor) bounding boxes, Shape: [A,4]. + box_b: (tensor) bounding boxes, Shape: [B,4]. + Return: + (tensor) intersection area, Shape: [A,B]. + """ + A = box_a.size(0) + B = box_b.size(0) + max_xy = torch.min(box_a[:, 2:].unsqueeze(1).expand(A, B, 2), + box_b[:, 2:].unsqueeze(0).expand(A, B, 2)) + min_xy = torch.max(box_a[:, :2].unsqueeze(1).expand(A, B, 2), + box_b[:, :2].unsqueeze(0).expand(A, B, 2)) + inter = torch.clamp((max_xy - min_xy), min=0) + return inter[:, :, 0] * inter[:, :, 1] + + +def jaccard(box_a, box_b, iscrowd=False): + """Compute the jaccard overlap of two sets of boxes. The jaccard overlap + is simply the intersection over union of two boxes. Here we operate on + ground truth boxes and default boxes. If iscrowd=True, put the crowd in box_b. + E.g.: + A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) + Args: + box_a: (tensor) Ground truth bounding boxes, Shape: [num_objects,4] + box_b: (tensor) Prior boxes from priorbox layers, Shape: [num_priors,4] + Return: + jaccard overlap: (tensor) Shape: [box_a.size(0), box_b.size(0)] + """ + inter = intersect(box_a, box_b) + area_a = ((box_a[:, 2]-box_a[:, 0]) * + (box_a[:, 3]-box_a[:, 1])).unsqueeze(1).expand_as(inter) # [A,B] + area_b = ((box_b[:, 2]-box_b[:, 0]) * + (box_b[:, 3]-box_b[:, 1])).unsqueeze(0).expand_as(inter) # [A,B] + union = area_a + area_b - inter + + if iscrowd: + return inter / area_a + else: + return inter / union # [A,B] + +# Also convert to point form +def to_relative(bboxes): + return np.concatenate((bboxes[:, 2:4] / bboxes[:, :2], (bboxes[:, 2:4] + bboxes[:, 4:]) / bboxes[:, :2]), axis=1) + + +def make_priors(conv_size, scales, aspect_ratios): + prior_data = [] + conv_h = conv_size[0] + conv_w = conv_size[1] + + # Iteration order is important (it has to sync up with the convout) + for j, i in product(range(conv_h), range(conv_w)): + x = (i + 0.5) / conv_w + y = (j + 0.5) / conv_h + + for scale, ars in zip(scales, aspect_ratios): + for ar in ars: + w = scale * ar / conv_w + h = scale / ar / conv_h + + # Point form + prior_data += [x - w/2, y - h/2, x + w/2, y + h/2] + + return np.array(prior_data).reshape(-1, 4) + +# fixed_ssd_config +# scales = [[3.5, 4.95], [3.6, 4.90], [3.3, 4.02], [2.7, 3.10], [2.1, 2.37], [2.1, 2.37], [1.8, 1.92]] +# aspect_ratios = [ [[1, sqrt(2), 1/sqrt(2), sqrt(3), 1/sqrt(3)][:n], [1]] for n in [3, 5, 5, 5, 3, 3, 3] ] +# conv_sizes = [(35, 35), (18, 18), (9, 9), (5, 5), (3, 3), (2, 2)] + +scales = [[1.68, 2.91], + [2.95, 2.22, 0.84], + [2.23, 2.17, 3.12], + [0.76, 1.94, 2.72], + [2.10, 2.65], + [1.80, 1.92]] +aspect_ratios = [[[0.72, 0.96], [0.68, 1.17]], + [[1.28, 0.66], [0.63, 1.23], [0.89, 1.40]], + [[2.05, 1.24], [0.57, 0.83], [0.61, 1.15]], + [[1.00, 2.21], [0.47, 1.60], [1.44, 0.79]], + [[1.00, 1.41, 0.71, 1.73, 0.58], [1.08]], + [[1.00, 1.41, 0.71, 1.73, 0.58], [1.00]]] +conv_sizes = [(35, 35), (18, 18), (9, 9), (5, 5), (3, 3), (2, 2)] + +# yrm33_config +# scales = [ [5.3] ] * 5 +# aspect_ratios = [ [[1, 1/sqrt(2), sqrt(2)]] ]*5 +# conv_sizes = [(136, 136), (67, 67), (33, 33), (16, 16), (8, 8)] + + +SMALL = 0 +MEDIUM = 1 +LARGE = 2 + +if __name__ == '__main__': + + with open(dump_file, 'rb') as f: + bboxes = pickle.load(f) + + sizes = [] + smalls = [] + for i in range(len(bboxes)): + area = bboxes[i][4] * bboxes[i][5] + if area < 32 ** 2: + sizes.append(SMALL) + smalls.append(area) + elif area < 96 ** 2: + sizes.append(MEDIUM) + else: + sizes.append(LARGE) + + # Each box is in the form [im_w, im_h, pos_x, pos_y, size_x, size_y] + + if use_augmented_boxes: + with open(aug_file, 'rb') as f: + bboxes_rel = pickle.load(f) + else: + bboxes_rel = to_relative(np.array(bboxes)) + + + with torch.no_grad(): + sizes = torch.Tensor(sizes) + + anchors = [make_priors(cs, s, ar) for cs, s, ar in zip(conv_sizes, scales, aspect_ratios)] + anchors = np.concatenate(anchors, axis=0) + anchors = torch.Tensor(anchors).cuda() + + bboxes_rel = torch.Tensor(bboxes_rel).cuda() + perGTAnchorMax = torch.zeros(bboxes_rel.shape[0]).cuda() + + chunk_size = 1000 + for i in range((bboxes_rel.size(0) // chunk_size) + 1): + start = i * chunk_size + end = min((i + 1) * chunk_size, bboxes_rel.size(0)) + + ious = jaccard(bboxes_rel[start:end, :], anchors) + maxes, maxidx = torch.max(ious, dim=1) + + perGTAnchorMax[start:end] = maxes + + + hits = (perGTAnchorMax > 0.5).float() + + print('Total recall: %.2f' % (torch.sum(hits) / hits.size(0) * 100)) + print() + + for i, metric in zip(range(3), ('small', 'medium', 'large')): + _hits = hits[sizes == i] + _size = (1 if _hits.size(0) == 0 else _hits.size(0)) + print(metric + ' recall: %.2f' % ((torch.sum(_hits) / _size) * 100)) + + + diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/cluster_bbox_sizes.py b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/cluster_bbox_sizes.py index 95ba75de62454930d7e0c7aa7c40d03481a8ceeb..e1ad776af225bdff87fc39443b9509f3c3933dc0 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/cluster_bbox_sizes.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/cluster_bbox_sizes.py @@ -1,83 +1,83 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -""" -This script compiles all the bounding boxes in the training data and -clusters them for each convout resolution on which they're used. - -Run this script from the Yolact root directory. -""" - -import os.path as osp -import json, pickle -import sys - -import numpy as np -import sklearn.cluster as cluster - -dump_file = 'weights/bboxes.pkl' -max_size = 550 - -num_scale_clusters = 5 -num_aspect_ratio_clusters = 3 - -def to_relative(bboxes): - return bboxes[:, 2:4] / bboxes[:, :2] - -def process(bboxes): - return to_relative(bboxes) * max_size - -if __name__ == '__main__': - - with open(dump_file, 'rb') as f: - bboxes = pickle.load(f) - - bboxes = np.array(bboxes) - bboxes = process(bboxes) - bboxes = bboxes[(bboxes[:, 0] > 1) * (bboxes[:, 1] > 1)] - - scale = np.sqrt(bboxes[:, 0] * bboxes[:, 1]).reshape(-1, 1) - - clusterer = cluster.KMeans(num_scale_clusters, random_state=99, n_jobs=4) - assignments = clusterer.fit_predict(scale) - counts = np.bincount(assignments) - - cluster_centers = clusterer.cluster_centers_ - - center_indices = list(range(num_scale_clusters)) - center_indices.sort(key=lambda x: cluster_centers[x, 0]) - - for idx in center_indices: - center = cluster_centers[idx, 0] - boxes_for_center = bboxes[assignments == idx] - aspect_ratios = (boxes_for_center[:,0] / boxes_for_center[:,1]).reshape(-1, 1) - - c = cluster.KMeans(num_aspect_ratio_clusters, random_state=idx, n_jobs=4) - ca = c.fit_predict(aspect_ratios) - cc = np.bincount(ca) - - c = list(c.cluster_centers_.reshape(-1)) - cidx = list(range(num_aspect_ratio_clusters)) - cidx.sort(key=lambda x: -cc[x]) - - # import code - # code.interact(local=locals()) - - print('%.3f (%d) aspect ratios:' % (center, counts[idx])) - for idx in cidx: - print('\t%.2f (%d)' % (c[idx], cc[idx])) - print() - # exit() - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +""" +This script compiles all the bounding boxes in the training data and +clusters them for each convout resolution on which they're used. + +Run this script from the Yolact root directory. +""" + +import os.path as osp +import json, pickle +import sys + +import numpy as np +import sklearn.cluster as cluster + +dump_file = 'weights/bboxes.pkl' +max_size = 550 + +num_scale_clusters = 5 +num_aspect_ratio_clusters = 3 + +def to_relative(bboxes): + return bboxes[:, 2:4] / bboxes[:, :2] + +def process(bboxes): + return to_relative(bboxes) * max_size + +if __name__ == '__main__': + + with open(dump_file, 'rb') as f: + bboxes = pickle.load(f) + + bboxes = np.array(bboxes) + bboxes = process(bboxes) + bboxes = bboxes[(bboxes[:, 0] > 1) * (bboxes[:, 1] > 1)] + + scale = np.sqrt(bboxes[:, 0] * bboxes[:, 1]).reshape(-1, 1) + + clusterer = cluster.KMeans(num_scale_clusters, random_state=99, n_jobs=4) + assignments = clusterer.fit_predict(scale) + counts = np.bincount(assignments) + + cluster_centers = clusterer.cluster_centers_ + + center_indices = list(range(num_scale_clusters)) + center_indices.sort(key=lambda x: cluster_centers[x, 0]) + + for idx in center_indices: + center = cluster_centers[idx, 0] + boxes_for_center = bboxes[assignments == idx] + aspect_ratios = (boxes_for_center[:,0] / boxes_for_center[:,1]).reshape(-1, 1) + + c = cluster.KMeans(num_aspect_ratio_clusters, random_state=idx, n_jobs=4) + ca = c.fit_predict(aspect_ratios) + cc = np.bincount(ca) + + c = list(c.cluster_centers_.reshape(-1)) + cidx = list(range(num_aspect_ratio_clusters)) + cidx.sort(key=lambda x: -cc[x]) + + # import code + # code.interact(local=locals()) + + print('%.3f (%d) aspect ratios:' % (center, counts[idx])) + for idx in cidx: + print('\t%.2f (%d)' % (c[idx], cc[idx])) + print() + # exit() + + diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/compute_masks.py b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/compute_masks.py index b48358395892af9dd0e813280b18512ff8653288..4153ccd48e90922b1523f3198ccc897379b8de9e 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/compute_masks.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/compute_masks.py @@ -1,108 +1,108 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import numpy as np -import matplotlib.pyplot as plt -import cv2 -import torch -import torch.nn.functional as F - -COLORS = ((255, 0, 0, 128), (0, 255, 0, 128), (0, 0, 255, 128), - (0, 255, 255, 128), (255, 0, 255, 128), (255, 255, 0, 128)) - -def mask_iou(mask1, mask2): - """ - Inputs inputs are matricies of size _ x N. Output is size _1 x _2. - Note: if iscrowd is True, then mask2 should be the crowd. - """ - intersection = torch.matmul(mask1, mask2.t()) - area1 = torch.sum(mask1, dim=1).view(1, -1) - area2 = torch.sum(mask2, dim=1).view(1, -1) - union = (area1.t() + area2) - intersection - - return intersection / union - -def paint_mask(img_numpy, mask, color): - h, w, _ = img_numpy.shape - img_numpy = img_numpy.copy() - - mask = np.tile(mask.reshape(h, w, 1), (1, 1, 3)) - color_np = np.array(color[:3]).reshape(1, 1, 3) - color_np = np.tile(color_np, (h, w, 1)) - mask_color = mask * color_np - - mask_alpha = 0.3 - - # Blend image and mask - image_crop = img_numpy * mask - img_numpy *= (1-mask) - img_numpy += image_crop * (1-mask_alpha) + mask_color * mask_alpha - - return img_numpy - -# Inverse sigmoid -def logit(x): - return np.log(x / (1-x + 0.0001) + 0.0001) - -def sigmoid(x): - return 1 / (1 + np.exp(-x)) - -img_fmt = '../data/coco/images/%012d.jpg' -with open('info.txt', 'r') as f: - img_id = int(f.read()) - -img = plt.imread(img_fmt % img_id).astype(np.float32) -h, w, _ = img.shape - -gt_masks = np.load('gt.npy').astype(np.float32).transpose(1, 2, 0) -proto_masks = np.load('proto.npy').astype(np.float32) - -proto_masks = torch.Tensor(proto_masks).permute(2, 0, 1).contiguous().unsqueeze(0) -proto_masks = F.interpolate(proto_masks, (h, w), mode='bilinear', align_corners=False).squeeze(0) -proto_masks = proto_masks.permute(1, 2, 0).numpy() - -# # A x = b -ls_A = proto_masks.reshape(-1, proto_masks.shape[-1]) -ls_b = gt_masks.reshape(-1, gt_masks.shape[-1]) - -# x is size [256, num_gt] -x = np.linalg.lstsq(ls_A, ls_b, rcond=None)[0] - -approximated_masks = (np.matmul(proto_masks, x) > 0.5).astype(np.float32) - -num_gt = approximated_masks.shape[2] -ious = mask_iou(torch.Tensor(approximated_masks.reshape(-1, num_gt).T), - torch.Tensor(gt_masks.reshape(-1, num_gt).T)) - -ious = [int(ious[i, i].item() * 100) for i in range(num_gt)] -ious.sort(key=lambda x: -x) - -print(ious) - -gt_img = img.copy() - -for i in range(num_gt): - gt_img = paint_mask(gt_img, gt_masks[:, :, i], COLORS[i % len(COLORS)]) - -plt.imshow(gt_img / 255) -plt.title('GT') -plt.show() - -for i in range(num_gt): - img = paint_mask(img, approximated_masks[:, :, i], COLORS[i % len(COLORS)]) - -plt.imshow(img / 255) -plt.title('Approximated') -plt.show() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import numpy as np +import matplotlib.pyplot as plt +import cv2 +import torch +import torch.nn.functional as F + +COLORS = ((255, 0, 0, 128), (0, 255, 0, 128), (0, 0, 255, 128), + (0, 255, 255, 128), (255, 0, 255, 128), (255, 255, 0, 128)) + +def mask_iou(mask1, mask2): + """ + Inputs inputs are matricies of size _ x N. Output is size _1 x _2. + Note: if iscrowd is True, then mask2 should be the crowd. + """ + intersection = torch.matmul(mask1, mask2.t()) + area1 = torch.sum(mask1, dim=1).view(1, -1) + area2 = torch.sum(mask2, dim=1).view(1, -1) + union = (area1.t() + area2) - intersection + + return intersection / union + +def paint_mask(img_numpy, mask, color): + h, w, _ = img_numpy.shape + img_numpy = img_numpy.copy() + + mask = np.tile(mask.reshape(h, w, 1), (1, 1, 3)) + color_np = np.array(color[:3]).reshape(1, 1, 3) + color_np = np.tile(color_np, (h, w, 1)) + mask_color = mask * color_np + + mask_alpha = 0.3 + + # Blend image and mask + image_crop = img_numpy * mask + img_numpy *= (1-mask) + img_numpy += image_crop * (1-mask_alpha) + mask_color * mask_alpha + + return img_numpy + +# Inverse sigmoid +def logit(x): + return np.log(x / (1-x + 0.0001) + 0.0001) + +def sigmoid(x): + return 1 / (1 + np.exp(-x)) + +img_fmt = '../data/coco/images/%012d.jpg' +with open('info.txt', 'r') as f: + img_id = int(f.read()) + +img = plt.imread(img_fmt % img_id).astype(np.float32) +h, w, _ = img.shape + +gt_masks = np.load('gt.npy').astype(np.float32).transpose(1, 2, 0) +proto_masks = np.load('proto.npy').astype(np.float32) + +proto_masks = torch.Tensor(proto_masks).permute(2, 0, 1).contiguous().unsqueeze(0) +proto_masks = F.interpolate(proto_masks, (h, w), mode='bilinear', align_corners=False).squeeze(0) +proto_masks = proto_masks.permute(1, 2, 0).numpy() + +# # A x = b +ls_A = proto_masks.reshape(-1, proto_masks.shape[-1]) +ls_b = gt_masks.reshape(-1, gt_masks.shape[-1]) + +# x is size [256, num_gt] +x = np.linalg.lstsq(ls_A, ls_b, rcond=None)[0] + +approximated_masks = (np.matmul(proto_masks, x) > 0.5).astype(np.float32) + +num_gt = approximated_masks.shape[2] +ious = mask_iou(torch.Tensor(approximated_masks.reshape(-1, num_gt).T), + torch.Tensor(gt_masks.reshape(-1, num_gt).T)) + +ious = [int(ious[i, i].item() * 100) for i in range(num_gt)] +ious.sort(key=lambda x: -x) + +print(ious) + +gt_img = img.copy() + +for i in range(num_gt): + gt_img = paint_mask(gt_img, gt_masks[:, :, i], COLORS[i % len(COLORS)]) + +plt.imshow(gt_img / 255) +plt.title('GT') +plt.show() + +for i in range(num_gt): + img = paint_mask(img, approximated_masks[:, :, i], COLORS[i % len(COLORS)]) + +plt.imshow(img / 255) +plt.title('Approximated') +plt.show() diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/convert_darknet.py b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/convert_darknet.py index 1c2c40f12522e8297d7a1a2997e89d74cc78a169..d68d59f96a973cfc8893d60b16e1f7ec9bd4ae33 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/convert_darknet.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/convert_darknet.py @@ -1,63 +1,63 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -from backbone import DarkNetBackbone -import h5py -import torch - -f = h5py.File('darknet53.h5', 'r') -m = f['model_weights'] - -yolo_keys = list(m.keys()) -yolo_keys = [x for x in yolo_keys if len(m[x].keys()) > 0] -yolo_keys.sort() - -sd = DarkNetBackbone().state_dict() - -sd_keys = list(sd.keys()) -sd_keys.sort() - -# Note this won't work if there are 10 elements in some list but whatever that doesn't happen -layer_keys = list(set(['.'.join(x.split('.')[:-2]) for x in sd_keys])) -layer_keys.sort() - -# print([x for x in sd_keys if x.startswith(layer_keys[0])]) - -mapping = { - '.0.weight' : ('conv2d_%d', 'kernel:0'), - '.1.bias' : ('batch_normalization_%d', 'beta:0'), - '.1.weight' : ('batch_normalization_%d', 'gamma:0'), - '.1.running_var' : ('batch_normalization_%d', 'moving_variance:0'), - '.1.running_mean': ('batch_normalization_%d', 'moving_mean:0'), - '.1.num_batches_tracked': None, -} - -for i, layer_key in zip(range(1, len(layer_keys) + 1), layer_keys): - # This is pretty inefficient but I don't care - for weight_key in [x for x in sd_keys if x.startswith(layer_key)]: - diff = weight_key[len(layer_key):] - - if mapping[diff] is not None: - yolo_key = mapping[diff][0] % i - sub_key = mapping[diff][1] - - yolo_weight = torch.Tensor(m[yolo_key][yolo_key][sub_key].value) - if (len(yolo_weight.size()) == 4): - yolo_weight = yolo_weight.permute(3, 2, 0, 1).contiguous() - - sd[weight_key] = yolo_weight - -torch.save(sd, 'weights/darknet53.pth') - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +from backbone import DarkNetBackbone +import h5py +import torch + +f = h5py.File('darknet53.h5', 'r') +m = f['model_weights'] + +yolo_keys = list(m.keys()) +yolo_keys = [x for x in yolo_keys if len(m[x].keys()) > 0] +yolo_keys.sort() + +sd = DarkNetBackbone().state_dict() + +sd_keys = list(sd.keys()) +sd_keys.sort() + +# Note this won't work if there are 10 elements in some list but whatever that doesn't happen +layer_keys = list(set(['.'.join(x.split('.')[:-2]) for x in sd_keys])) +layer_keys.sort() + +# print([x for x in sd_keys if x.startswith(layer_keys[0])]) + +mapping = { + '.0.weight' : ('conv2d_%d', 'kernel:0'), + '.1.bias' : ('batch_normalization_%d', 'beta:0'), + '.1.weight' : ('batch_normalization_%d', 'gamma:0'), + '.1.running_var' : ('batch_normalization_%d', 'moving_variance:0'), + '.1.running_mean': ('batch_normalization_%d', 'moving_mean:0'), + '.1.num_batches_tracked': None, +} + +for i, layer_key in zip(range(1, len(layer_keys) + 1), layer_keys): + # This is pretty inefficient but I don't care + for weight_key in [x for x in sd_keys if x.startswith(layer_key)]: + diff = weight_key[len(layer_key):] + + if mapping[diff] is not None: + yolo_key = mapping[diff][0] % i + sub_key = mapping[diff][1] + + yolo_weight = torch.Tensor(m[yolo_key][yolo_key][sub_key].value) + if (len(yolo_weight.size()) == 4): + yolo_weight = yolo_weight.permute(3, 2, 0, 1).contiguous() + + sd[weight_key] = yolo_weight + +torch.save(sd, 'weights/darknet53.pth') + diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/convert_sbd.py b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/convert_sbd.py index a1c940061a328d9bbebf506a99cbcd08acbdbbfc..61f049a3662cbb9beb1874019ff8384194202361 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/convert_sbd.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/convert_sbd.py @@ -1,88 +1,88 @@ -import scipy.io, scipy.ndimage -import os.path, json -import pycocotools.mask -import numpy as np - -def mask2bbox(mask): - rows = np.any(mask, axis=1) - cols = np.any(mask, axis=0) - rmin, rmax = np.where(rows)[0][[0, -1]] - cmin, cmax = np.where(cols)[0][[0, -1]] - - return cmin, rmin, cmax - cmin, rmax - rmin - - - -inst_path = './inst/' -img_path = './img/' -img_name_fmt = '%s.jpg' -ann_name_fmt = '%s.mat' - -image_id = 1 -ann_id = 1 - -types = ['train', 'val'] - -for t in types: - with open('%s.txt' % t, 'r') as f: - names = f.read().strip().split('\n') - - images = [] - annotations = [] - - for name in names: - img_name = img_name_fmt % name - - ann_path = os.path.join(inst_path, ann_name_fmt % name) - ann = scipy.io.loadmat(ann_path)['GTinst'][0][0] - - classes = [int(x[0]) for x in ann[2]] - seg = ann[0] - - for idx in range(len(classes)): - mask = (seg == (idx + 1)).astype(np.float) - - rle = pycocotools.mask.encode(np.asfortranarray(mask.astype(np.uint8))) - rle['counts'] = rle['counts'].decode('ascii') - - annotations.append({ - 'id': ann_id, - 'image_id': image_id, - 'category_id': classes[idx], - 'segmentation': rle, - 'area': float(mask.sum()), - 'bbox': [int(x) for x in mask2bbox(mask)], - 'iscrowd': 0 - }) - - ann_id += 1 - - img_name = img_name_fmt % name - img = scipy.ndimage.imread(os.path.join(img_path, img_name)) - - images.append({ - 'id': image_id, - 'width': img.shape[1], - 'height': img.shape[0], - 'file_name': img_name - }) - - image_id += 1 - - info = { - 'year': 2012, - 'version': 1, - 'description': 'Pascal SBD', - } - - categories = [{'id': x+1} for x in range(20)] - - with open('pascal_sbd_%s.json' % t, 'w') as f: - json.dump({ - 'info': info, - 'images': images, - 'annotations': annotations, - 'licenses': {}, - 'categories': categories - }, f) - +import scipy.io, scipy.ndimage +import os.path, json +import pycocotools.mask +import numpy as np + +def mask2bbox(mask): + rows = np.any(mask, axis=1) + cols = np.any(mask, axis=0) + rmin, rmax = np.where(rows)[0][[0, -1]] + cmin, cmax = np.where(cols)[0][[0, -1]] + + return cmin, rmin, cmax - cmin, rmax - rmin + + + +inst_path = './inst/' +img_path = './img/' +img_name_fmt = '%s.jpg' +ann_name_fmt = '%s.mat' + +image_id = 1 +ann_id = 1 + +types = ['train', 'val'] + +for t in types: + with open('%s.txt' % t, 'r') as f: + names = f.read().strip().split('\n') + + images = [] + annotations = [] + + for name in names: + img_name = img_name_fmt % name + + ann_path = os.path.join(inst_path, ann_name_fmt % name) + ann = scipy.io.loadmat(ann_path)['GTinst'][0][0] + + classes = [int(x[0]) for x in ann[2]] + seg = ann[0] + + for idx in range(len(classes)): + mask = (seg == (idx + 1)).astype(np.float) + + rle = pycocotools.mask.encode(np.asfortranarray(mask.astype(np.uint8))) + rle['counts'] = rle['counts'].decode('ascii') + + annotations.append({ + 'id': ann_id, + 'image_id': image_id, + 'category_id': classes[idx], + 'segmentation': rle, + 'area': float(mask.sum()), + 'bbox': [int(x) for x in mask2bbox(mask)], + 'iscrowd': 0 + }) + + ann_id += 1 + + img_name = img_name_fmt % name + img = scipy.ndimage.imread(os.path.join(img_path, img_name)) + + images.append({ + 'id': image_id, + 'width': img.shape[1], + 'height': img.shape[0], + 'file_name': img_name + }) + + image_id += 1 + + info = { + 'year': 2012, + 'version': 1, + 'description': 'Pascal SBD', + } + + categories = [{'id': x+1} for x in range(20)] + + with open('pascal_sbd_%s.json' % t, 'w') as f: + json.dump({ + 'info': info, + 'images': images, + 'annotations': annotations, + 'licenses': {}, + 'categories': categories + }, f) + diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/eval.sh b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/eval.sh index c038b910949ac851b17518894b334f4882a88be4..fbd5a429dd3d69c3b35a5f6331e590aa9081d1f3 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/eval.sh +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/eval.sh @@ -1,14 +1,14 @@ -#!/bin/bash -#SBATCH -p GPU-small -#SBATCH -t 2:00:00 -#SBATCH --gres=gpu:p100:1 -#SBATCH --no-requeue - -# Usage: ./eval.sh weights extra_args - -module load python/3.6.4_gcc5_np1.14.5 -module load cuda/9.0 - -cd $SCRATCH/yolact - -python3 eval.py --trained_model=$1 --no_bar $2 > logs/eval/$(basename -- $1).log 2>&1 +#!/bin/bash +#SBATCH -p GPU-small +#SBATCH -t 2:00:00 +#SBATCH --gres=gpu:p100:1 +#SBATCH --no-requeue + +# Usage: ./eval.sh weights extra_args + +module load python/3.6.4_gcc5_np1.14.5 +module load cuda/9.0 + +cd $SCRATCH/yolact + +python3 eval.py --trained_model=$1 --no_bar $2 > logs/eval/$(basename -- $1).log 2>&1 diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/make_grid.py b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/make_grid.py index fd24ca8120c6bdc0a5f1ea9c1b68e700d9c1804a..4039e106c3b1bf191ca90f9ef5e9ee29c7b72672 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/make_grid.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/make_grid.py @@ -1,218 +1,218 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import numpy as np -import math, random - -import matplotlib.pyplot as plt -from matplotlib.widgets import Slider, Button - - -fig, ax = plt.subplots() -plt.subplots_adjust(bottom=0.24) -im_handle = None - -save_path = 'grid.npy' - -center_x, center_y = (0.5, 0.5) -grid_w, grid_h = (35, 35) -spacing = 0 -scale = 4 -angle = 0 -grid = None - -all_grids = [] -unique = False - -# A hack -disable_render = False - -def render(): - if disable_render: - return - - x = np.tile(np.array(list(range(grid_w)), dtype=np.float).reshape(1, grid_w), [grid_h, 1]) - grid_w * center_x - y = np.tile(np.array(list(range(grid_h)), dtype=np.float).reshape(grid_h, 1), [1, grid_w]) - grid_h * center_y - - x /= scale - y /= scale - - a1 = angle + math.pi / 3 - a2 = -angle + math.pi / 3 - a3 = angle - - z1 = x * math.sin(a1) + y * math.cos(a1) - z2 = x * math.sin(a2) - y * math.cos(a2) - z3 = x * math.sin(a3) + y * math.cos(a3) - - s1 = np.square(np.sin(z1)) - s2 = np.square(np.sin(z2)) - s3 = np.square(np.sin(z3)) - - line_1 = np.exp(s1 * spacing) * s1 - line_2 = np.exp(s2 * spacing) * s2 - line_3 = np.exp(s3 * spacing) * s3 - - global grid - grid = np.clip(1 - (line_1 + line_2 + line_3) / 3, 0, 1) - - global im_handle - if im_handle is None: - im_handle = plt.imshow(grid) - else: - im_handle.set_data(grid) - fig.canvas.draw_idle() - -def update_scale(val): - global scale - scale = val - - render() - -def update_angle(val): - global angle - angle = val - - render() - -def update_centerx(val): - global center_x - center_x = val - - render() - -def update_centery(val): - global center_y - center_y = val - - render() - -def update_spacing(val): - global spacing - spacing = val - - render() - -def randomize(val): - global center_x, center_y, spacing, scale, angle, disable_render - - center_x, center_y = (random.uniform(0, 1), random.uniform(0, 1)) - spacing = random.uniform(-0.2, 2) - scale = 4 * math.exp(random.uniform(-1, 1)) - angle = random.uniform(-math.pi, math.pi) - - disable_render = True - - scale_slider.set_val(scale) - angle_slider.set_val(angle) - centx_slider.set_val(center_x) - centy_slider.set_val(center_y) - spaci_slider.set_val(spacing) - - disable_render = False - - render() - -def add(val): - all_grids.append(grid) - - global unique - if not unique: - unique = test_uniqueness(np.stack(all_grids)) - - export_len_text.set_text('Num Grids: ' + str(len(all_grids))) - fig.canvas.draw_idle() - -def add_randomize(val): - add(val) - randomize(val) - -def export(val): - np.save(save_path, np.stack(all_grids)) - print('Saved %d grids to "%s"' % (len(all_grids), save_path)) - - global unique - unique = False - all_grids.clear() - - export_len_text.set_text('Num Grids: ' + str(len(all_grids))) - fig.canvas.draw_idle() - -def test_uniqueness(grids): - # Grids shape [ngrids, h, w] - grids = grids.reshape((-1, grid_h, grid_w)) - - for y in range(grid_h): - for x in range(grid_h): - pixel_features = grids[:, y, x] - - # l1 distance for this pixel with every other - l1_dist = np.sum(np.abs(grids - np.tile(pixel_features, grid_h*grid_w).reshape((-1, grid_h, grid_w))), axis=0) - - # Equal if l1 distance is really small. Note that this will include this pixel - num_equal = np.sum((l1_dist < 0.0001).astype(np.int32)) - - if num_equal > 1: - print('Pixel at (%d, %d) has %d other pixel%s with the same representation.' % (x, y, num_equal-1, '' if num_equal==2 else 's')) - return False - - print('Each pixel has a distinct representation.') - return True - - - -render() - -axis = plt.axes([0.22, 0.19, 0.59, 0.03], facecolor='lightgoldenrodyellow') -scale_slider = Slider(axis, 'Scale', 0.1, 20, valinit=scale, valstep=0.1) -scale_slider.on_changed(update_scale) - -axis = plt.axes([0.22, 0.15, 0.59, 0.03], facecolor='lightgoldenrodyellow') -angle_slider = Slider(axis, 'Angle', -math.pi, math.pi, valinit=angle, valstep=0.1) -angle_slider.on_changed(update_angle) - -axis = plt.axes([0.22, 0.11, 0.59, 0.03], facecolor='lightgoldenrodyellow') -centx_slider = Slider(axis, 'Center X', 0, 1, valinit=center_x, valstep=0.05) -centx_slider.on_changed(update_centerx) - -axis = plt.axes([0.22, 0.07, 0.59, 0.03], facecolor='lightgoldenrodyellow') -centy_slider = Slider(axis, 'Center Y', 0, 1, valinit=center_y, valstep=0.05) -centy_slider.on_changed(update_centery) - -axis = plt.axes([0.22, 0.03, 0.59, 0.03], facecolor='lightgoldenrodyellow') -spaci_slider = Slider(axis, 'Spacing', -1, 2, valinit=spacing, valstep=0.05) -spaci_slider.on_changed(update_spacing) - -axis = plt.axes([0.8, 0.54, 0.15, 0.05], facecolor='lightgoldenrodyellow') -rando_button = Button(axis, 'Randomize') -rando_button.on_clicked(randomize) - -axis = plt.axes([0.8, 0.48, 0.15, 0.05], facecolor='lightgoldenrodyellow') -addgr_button = Button(axis, 'Add') -addgr_button.on_clicked(add) - -# Likely not a good way to do this but whatever -export_len_text = plt.text(0, 3, 'Num Grids: 0') - -axis = plt.axes([0.8, 0.42, 0.15, 0.05], facecolor='lightgoldenrodyellow') -addra_button = Button(axis, 'Add / Rand') -addra_button.on_clicked(add_randomize) - -axis = plt.axes([0.8, 0.36, 0.15, 0.05], facecolor='lightgoldenrodyellow') -saveg_button = Button(axis, 'Save') -saveg_button.on_clicked(export) - - - -plt.show() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import numpy as np +import math, random + +import matplotlib.pyplot as plt +from matplotlib.widgets import Slider, Button + + +fig, ax = plt.subplots() +plt.subplots_adjust(bottom=0.24) +im_handle = None + +save_path = 'grid.npy' + +center_x, center_y = (0.5, 0.5) +grid_w, grid_h = (35, 35) +spacing = 0 +scale = 4 +angle = 0 +grid = None + +all_grids = [] +unique = False + +# A hack +disable_render = False + +def render(): + if disable_render: + return + + x = np.tile(np.array(list(range(grid_w)), dtype=np.float).reshape(1, grid_w), [grid_h, 1]) - grid_w * center_x + y = np.tile(np.array(list(range(grid_h)), dtype=np.float).reshape(grid_h, 1), [1, grid_w]) - grid_h * center_y + + x /= scale + y /= scale + + a1 = angle + math.pi / 3 + a2 = -angle + math.pi / 3 + a3 = angle + + z1 = x * math.sin(a1) + y * math.cos(a1) + z2 = x * math.sin(a2) - y * math.cos(a2) + z3 = x * math.sin(a3) + y * math.cos(a3) + + s1 = np.square(np.sin(z1)) + s2 = np.square(np.sin(z2)) + s3 = np.square(np.sin(z3)) + + line_1 = np.exp(s1 * spacing) * s1 + line_2 = np.exp(s2 * spacing) * s2 + line_3 = np.exp(s3 * spacing) * s3 + + global grid + grid = np.clip(1 - (line_1 + line_2 + line_3) / 3, 0, 1) + + global im_handle + if im_handle is None: + im_handle = plt.imshow(grid) + else: + im_handle.set_data(grid) + fig.canvas.draw_idle() + +def update_scale(val): + global scale + scale = val + + render() + +def update_angle(val): + global angle + angle = val + + render() + +def update_centerx(val): + global center_x + center_x = val + + render() + +def update_centery(val): + global center_y + center_y = val + + render() + +def update_spacing(val): + global spacing + spacing = val + + render() + +def randomize(val): + global center_x, center_y, spacing, scale, angle, disable_render + + center_x, center_y = (random.uniform(0, 1), random.uniform(0, 1)) + spacing = random.uniform(-0.2, 2) + scale = 4 * math.exp(random.uniform(-1, 1)) + angle = random.uniform(-math.pi, math.pi) + + disable_render = True + + scale_slider.set_val(scale) + angle_slider.set_val(angle) + centx_slider.set_val(center_x) + centy_slider.set_val(center_y) + spaci_slider.set_val(spacing) + + disable_render = False + + render() + +def add(val): + all_grids.append(grid) + + global unique + if not unique: + unique = test_uniqueness(np.stack(all_grids)) + + export_len_text.set_text('Num Grids: ' + str(len(all_grids))) + fig.canvas.draw_idle() + +def add_randomize(val): + add(val) + randomize(val) + +def export(val): + np.save(save_path, np.stack(all_grids)) + print('Saved %d grids to "%s"' % (len(all_grids), save_path)) + + global unique + unique = False + all_grids.clear() + + export_len_text.set_text('Num Grids: ' + str(len(all_grids))) + fig.canvas.draw_idle() + +def test_uniqueness(grids): + # Grids shape [ngrids, h, w] + grids = grids.reshape((-1, grid_h, grid_w)) + + for y in range(grid_h): + for x in range(grid_h): + pixel_features = grids[:, y, x] + + # l1 distance for this pixel with every other + l1_dist = np.sum(np.abs(grids - np.tile(pixel_features, grid_h*grid_w).reshape((-1, grid_h, grid_w))), axis=0) + + # Equal if l1 distance is really small. Note that this will include this pixel + num_equal = np.sum((l1_dist < 0.0001).astype(np.int32)) + + if num_equal > 1: + print('Pixel at (%d, %d) has %d other pixel%s with the same representation.' % (x, y, num_equal-1, '' if num_equal==2 else 's')) + return False + + print('Each pixel has a distinct representation.') + return True + + + +render() + +axis = plt.axes([0.22, 0.19, 0.59, 0.03], facecolor='lightgoldenrodyellow') +scale_slider = Slider(axis, 'Scale', 0.1, 20, valinit=scale, valstep=0.1) +scale_slider.on_changed(update_scale) + +axis = plt.axes([0.22, 0.15, 0.59, 0.03], facecolor='lightgoldenrodyellow') +angle_slider = Slider(axis, 'Angle', -math.pi, math.pi, valinit=angle, valstep=0.1) +angle_slider.on_changed(update_angle) + +axis = plt.axes([0.22, 0.11, 0.59, 0.03], facecolor='lightgoldenrodyellow') +centx_slider = Slider(axis, 'Center X', 0, 1, valinit=center_x, valstep=0.05) +centx_slider.on_changed(update_centerx) + +axis = plt.axes([0.22, 0.07, 0.59, 0.03], facecolor='lightgoldenrodyellow') +centy_slider = Slider(axis, 'Center Y', 0, 1, valinit=center_y, valstep=0.05) +centy_slider.on_changed(update_centery) + +axis = plt.axes([0.22, 0.03, 0.59, 0.03], facecolor='lightgoldenrodyellow') +spaci_slider = Slider(axis, 'Spacing', -1, 2, valinit=spacing, valstep=0.05) +spaci_slider.on_changed(update_spacing) + +axis = plt.axes([0.8, 0.54, 0.15, 0.05], facecolor='lightgoldenrodyellow') +rando_button = Button(axis, 'Randomize') +rando_button.on_clicked(randomize) + +axis = plt.axes([0.8, 0.48, 0.15, 0.05], facecolor='lightgoldenrodyellow') +addgr_button = Button(axis, 'Add') +addgr_button.on_clicked(add) + +# Likely not a good way to do this but whatever +export_len_text = plt.text(0, 3, 'Num Grids: 0') + +axis = plt.axes([0.8, 0.42, 0.15, 0.05], facecolor='lightgoldenrodyellow') +addra_button = Button(axis, 'Add / Rand') +addra_button.on_clicked(add_randomize) + +axis = plt.axes([0.8, 0.36, 0.15, 0.05], facecolor='lightgoldenrodyellow') +saveg_button = Button(axis, 'Save') +saveg_button.on_clicked(export) + + + +plt.show() diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/optimize_bboxes.py b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/optimize_bboxes.py index 4e7916ee1a271f6603e055cb850ca97300ed4305..5db9ef67e988e00d321e235fc8aaca06be6f244e 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/optimize_bboxes.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/optimize_bboxes.py @@ -1,218 +1,218 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -""" -Instead of clustering bbox widths and heights, this script -directly optimizes average IoU across the training set given -the specified number of anchor boxes. - -Run this script from the Yolact root directory. -""" - -import pickle -import random -from itertools import product -from math import sqrt - -import numpy as np -import torch -from scipy.optimize import minimize - -dump_file = 'weights/bboxes.pkl' -aug_file = 'weights/bboxes_aug.pkl' - -use_augmented_boxes = True - - -def intersect(box_a, box_b): - """ We resize both tensors to [A,B,2] without new malloc: - [A,2] -> [A,1,2] -> [A,B,2] - [B,2] -> [1,B,2] -> [A,B,2] - Then we compute the area of intersect between box_a and box_b. - Args: - box_a: (tensor) bounding boxes, Shape: [A,4]. - box_b: (tensor) bounding boxes, Shape: [B,4]. - Return: - (tensor) intersection area, Shape: [A,B]. - """ - A = box_a.size(0) - B = box_b.size(0) - max_xy = torch.min(box_a[:, 2:].unsqueeze(1).expand(A, B, 2), - box_b[:, 2:].unsqueeze(0).expand(A, B, 2)) - min_xy = torch.max(box_a[:, :2].unsqueeze(1).expand(A, B, 2), - box_b[:, :2].unsqueeze(0).expand(A, B, 2)) - inter = torch.clamp((max_xy - min_xy), min=0) - return inter[:, :, 0] * inter[:, :, 1] - - -def jaccard(box_a, box_b, iscrowd=False): - """Compute the jaccard overlap of two sets of boxes. The jaccard overlap - is simply the intersection over union of two boxes. Here we operate on - ground truth boxes and default boxes. If iscrowd=True, put the crowd in box_b. - E.g.: - A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) - Args: - box_a: (tensor) Ground truth bounding boxes, Shape: [num_objects,4] - box_b: (tensor) Prior boxes from priorbox layers, Shape: [num_priors,4] - Return: - jaccard overlap: (tensor) Shape: [box_a.size(0), box_b.size(0)] - """ - inter = intersect(box_a, box_b) - area_a = ((box_a[:, 2]-box_a[:, 0]) * - (box_a[:, 3]-box_a[:, 1])).unsqueeze(1).expand_as(inter) # [A,B] - area_b = ((box_b[:, 2]-box_b[:, 0]) * - (box_b[:, 3]-box_b[:, 1])).unsqueeze(0).expand_as(inter) # [A,B] - union = area_a + area_b - inter - - if iscrowd: - return inter / area_a - else: - return inter / union # [A,B] - -# Also convert to point form -def to_relative(bboxes): - return np.concatenate((bboxes[:, 2:4] / bboxes[:, :2], (bboxes[:, 2:4] + bboxes[:, 4:]) / bboxes[:, :2]), axis=1) - - -def make_priors(conv_size, scales, aspect_ratios): - prior_data = [] - conv_h = conv_size[0] - conv_w = conv_size[1] - - # Iteration order is important (it has to sync up with the convout) - for j, i in product(range(conv_h), range(conv_w)): - x = (i + 0.5) / conv_w - y = (j + 0.5) / conv_h - - for scale, ars in zip(scales, aspect_ratios): - for ar in ars: - w = scale * ar / conv_w - h = scale / ar / conv_h - - # Point form - prior_data += [x - w/2, y - h/2, x + w/2, y + h/2] - return torch.Tensor(prior_data).view(-1, 4).cuda() - - - -scales = [[1.68, 2.91], [2.95, 2.22, 0.84], [2.17, 2.22, 3.22], [0.76, 2.06, 2.81], [5.33, 2.79], [13.69]] -aspect_ratios = [[[0.72, 0.96], [0.68, 1.17]], [[1.30, 0.66], [0.63, 1.23], [0.87, 1.41]], [[1.96, 1.23], [0.58, 0.84], [0.61, 1.15]], [[19.79, 2.21], [0.47, 1.76], [1.38, 0.79]], [[4.79, 17.96], [1.04]], [[14.82]]] -conv_sizes = [(35, 35), (18, 18), (9, 9), (5, 5), (3, 3), (2, 2)] - -optimize_scales = False - -batch_idx = 0 - - -def compute_hits(bboxes, anchors, iou_threshold=0.5): - ious = jaccard(bboxes, anchors) - perGTAnchorMax, _ = torch.max(ious, dim=1) - - return (perGTAnchorMax > iou_threshold) - -def compute_recall(hits, base_hits): - hits = (hits | base_hits).float() - return torch.sum(hits) / hits.size(0) - - -def step(x, x_func, bboxes, base_hits, optim_idx): - # This should set the scale and aspect ratio - x_func(x, scales[optim_idx], aspect_ratios[optim_idx]) - - anchors = make_priors(conv_sizes[optim_idx], scales[optim_idx], aspect_ratios[optim_idx]) - - return -float(compute_recall(compute_hits(bboxes, anchors), base_hits).cpu()) - - -def optimize(full_bboxes, optim_idx, batch_size=5000): - global batch_idx, scales, aspect_ratios, conv_sizes - - start = batch_idx * batch_size - end = min((batch_idx + 1) * batch_size, full_bboxes.size(0)) - - if batch_idx > (full_bboxes.size(0) // batch_size): - batch_idx = 0 - - bboxes = full_bboxes[start:end, :] - - anchor_base = [ - make_priors(conv_sizes[idx], scales[idx], aspect_ratios[idx]) - for idx in range(len(conv_sizes)) if idx != optim_idx] - base_hits = compute_hits(bboxes, torch.cat(anchor_base, dim=0)) - - - def set_x(x, scales, aspect_ratios): - if optimize_scales: - for i in range(len(scales)): - scales[i] = max(x[i], 0) - else: - k = 0 - for i in range(len(aspect_ratios)): - for j in range(len(aspect_ratios[i])): - aspect_ratios[i][j] = x[k] - k += 1 - - - res = minimize(step, x0=scales[optim_idx] if optimize_scales else sum(aspect_ratios[optim_idx], []), method='Powell', - args = (set_x, bboxes, base_hits, optim_idx),) - - -def pretty_str(x:list): - if isinstance(x, list): - return '[' + ', '.join([pretty_str(y) for y in x]) + ']' - elif isinstance(x, np.ndarray): - return pretty_str(list(x)) - else: - return '%.2f' % x - -if __name__ == '__main__': - - if use_augmented_boxes: - with open(aug_file, 'rb') as f: - bboxes = pickle.load(f) - else: - # Load widths and heights from a dump file. Obtain this with - # python3 scripts/save_bboxes.py - with open(dump_file, 'rb') as f: - bboxes = pickle.load(f) - - bboxes = np.array(bboxes) - bboxes = to_relative(bboxes) - - with torch.no_grad(): - bboxes = torch.Tensor(bboxes).cuda() - - def print_out(): - if optimize_scales: - print('Scales: ' + pretty_str(scales)) - else: - print('Aspect Ratios: ' + pretty_str(aspect_ratios)) - - for p in range(10): - print('(Sub Iteration) ', end='') - for i in range(len(conv_sizes)): - print('%d ' % i, end='', flush=True) - optimize(bboxes, i) - print('Done', end='\r') - - print('(Iteration %d) ' % p, end='') - print_out() - print() - - optimize_scales = not optimize_scales - - print('scales = ' + pretty_str(scales)) - print('aspect_ratios = ' + pretty_str(aspect_ratios)) - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +""" +Instead of clustering bbox widths and heights, this script +directly optimizes average IoU across the training set given +the specified number of anchor boxes. + +Run this script from the Yolact root directory. +""" + +import pickle +import random +from itertools import product +from math import sqrt + +import numpy as np +import torch +from scipy.optimize import minimize + +dump_file = 'weights/bboxes.pkl' +aug_file = 'weights/bboxes_aug.pkl' + +use_augmented_boxes = True + + +def intersect(box_a, box_b): + """ We resize both tensors to [A,B,2] without new malloc: + [A,2] -> [A,1,2] -> [A,B,2] + [B,2] -> [1,B,2] -> [A,B,2] + Then we compute the area of intersect between box_a and box_b. + Args: + box_a: (tensor) bounding boxes, Shape: [A,4]. + box_b: (tensor) bounding boxes, Shape: [B,4]. + Return: + (tensor) intersection area, Shape: [A,B]. + """ + A = box_a.size(0) + B = box_b.size(0) + max_xy = torch.min(box_a[:, 2:].unsqueeze(1).expand(A, B, 2), + box_b[:, 2:].unsqueeze(0).expand(A, B, 2)) + min_xy = torch.max(box_a[:, :2].unsqueeze(1).expand(A, B, 2), + box_b[:, :2].unsqueeze(0).expand(A, B, 2)) + inter = torch.clamp((max_xy - min_xy), min=0) + return inter[:, :, 0] * inter[:, :, 1] + + +def jaccard(box_a, box_b, iscrowd=False): + """Compute the jaccard overlap of two sets of boxes. The jaccard overlap + is simply the intersection over union of two boxes. Here we operate on + ground truth boxes and default boxes. If iscrowd=True, put the crowd in box_b. + E.g.: + A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) + Args: + box_a: (tensor) Ground truth bounding boxes, Shape: [num_objects,4] + box_b: (tensor) Prior boxes from priorbox layers, Shape: [num_priors,4] + Return: + jaccard overlap: (tensor) Shape: [box_a.size(0), box_b.size(0)] + """ + inter = intersect(box_a, box_b) + area_a = ((box_a[:, 2]-box_a[:, 0]) * + (box_a[:, 3]-box_a[:, 1])).unsqueeze(1).expand_as(inter) # [A,B] + area_b = ((box_b[:, 2]-box_b[:, 0]) * + (box_b[:, 3]-box_b[:, 1])).unsqueeze(0).expand_as(inter) # [A,B] + union = area_a + area_b - inter + + if iscrowd: + return inter / area_a + else: + return inter / union # [A,B] + +# Also convert to point form +def to_relative(bboxes): + return np.concatenate((bboxes[:, 2:4] / bboxes[:, :2], (bboxes[:, 2:4] + bboxes[:, 4:]) / bboxes[:, :2]), axis=1) + + +def make_priors(conv_size, scales, aspect_ratios): + prior_data = [] + conv_h = conv_size[0] + conv_w = conv_size[1] + + # Iteration order is important (it has to sync up with the convout) + for j, i in product(range(conv_h), range(conv_w)): + x = (i + 0.5) / conv_w + y = (j + 0.5) / conv_h + + for scale, ars in zip(scales, aspect_ratios): + for ar in ars: + w = scale * ar / conv_w + h = scale / ar / conv_h + + # Point form + prior_data += [x - w/2, y - h/2, x + w/2, y + h/2] + return torch.Tensor(prior_data).view(-1, 4).cuda() + + + +scales = [[1.68, 2.91], [2.95, 2.22, 0.84], [2.17, 2.22, 3.22], [0.76, 2.06, 2.81], [5.33, 2.79], [13.69]] +aspect_ratios = [[[0.72, 0.96], [0.68, 1.17]], [[1.30, 0.66], [0.63, 1.23], [0.87, 1.41]], [[1.96, 1.23], [0.58, 0.84], [0.61, 1.15]], [[19.79, 2.21], [0.47, 1.76], [1.38, 0.79]], [[4.79, 17.96], [1.04]], [[14.82]]] +conv_sizes = [(35, 35), (18, 18), (9, 9), (5, 5), (3, 3), (2, 2)] + +optimize_scales = False + +batch_idx = 0 + + +def compute_hits(bboxes, anchors, iou_threshold=0.5): + ious = jaccard(bboxes, anchors) + perGTAnchorMax, _ = torch.max(ious, dim=1) + + return (perGTAnchorMax > iou_threshold) + +def compute_recall(hits, base_hits): + hits = (hits | base_hits).float() + return torch.sum(hits) / hits.size(0) + + +def step(x, x_func, bboxes, base_hits, optim_idx): + # This should set the scale and aspect ratio + x_func(x, scales[optim_idx], aspect_ratios[optim_idx]) + + anchors = make_priors(conv_sizes[optim_idx], scales[optim_idx], aspect_ratios[optim_idx]) + + return -float(compute_recall(compute_hits(bboxes, anchors), base_hits).cpu()) + + +def optimize(full_bboxes, optim_idx, batch_size=5000): + global batch_idx, scales, aspect_ratios, conv_sizes + + start = batch_idx * batch_size + end = min((batch_idx + 1) * batch_size, full_bboxes.size(0)) + + if batch_idx > (full_bboxes.size(0) // batch_size): + batch_idx = 0 + + bboxes = full_bboxes[start:end, :] + + anchor_base = [ + make_priors(conv_sizes[idx], scales[idx], aspect_ratios[idx]) + for idx in range(len(conv_sizes)) if idx != optim_idx] + base_hits = compute_hits(bboxes, torch.cat(anchor_base, dim=0)) + + + def set_x(x, scales, aspect_ratios): + if optimize_scales: + for i in range(len(scales)): + scales[i] = max(x[i], 0) + else: + k = 0 + for i in range(len(aspect_ratios)): + for j in range(len(aspect_ratios[i])): + aspect_ratios[i][j] = x[k] + k += 1 + + + res = minimize(step, x0=scales[optim_idx] if optimize_scales else sum(aspect_ratios[optim_idx], []), method='Powell', + args = (set_x, bboxes, base_hits, optim_idx),) + + +def pretty_str(x:list): + if isinstance(x, list): + return '[' + ', '.join([pretty_str(y) for y in x]) + ']' + elif isinstance(x, np.ndarray): + return pretty_str(list(x)) + else: + return '%.2f' % x + +if __name__ == '__main__': + + if use_augmented_boxes: + with open(aug_file, 'rb') as f: + bboxes = pickle.load(f) + else: + # Load widths and heights from a dump file. Obtain this with + # python3 scripts/save_bboxes.py + with open(dump_file, 'rb') as f: + bboxes = pickle.load(f) + + bboxes = np.array(bboxes) + bboxes = to_relative(bboxes) + + with torch.no_grad(): + bboxes = torch.Tensor(bboxes).cuda() + + def print_out(): + if optimize_scales: + print('Scales: ' + pretty_str(scales)) + else: + print('Aspect Ratios: ' + pretty_str(aspect_ratios)) + + for p in range(10): + print('(Sub Iteration) ', end='') + for i in range(len(conv_sizes)): + print('%d ' % i, end='', flush=True) + optimize(bboxes, i) + print('Done', end='\r') + + print('(Iteration %d) ' % p, end='') + print_out() + print() + + optimize_scales = not optimize_scales + + print('scales = ' + pretty_str(scales)) + print('aspect_ratios = ' + pretty_str(aspect_ratios)) + + diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/parse_eval.py b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/parse_eval.py index c6788ba07f6e77a751a34953489ee1d5b51d5d46..481ae586f89c3896414944b29a2bacfae364b6f0 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/parse_eval.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/parse_eval.py @@ -1,63 +1,63 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import re, sys, os -import matplotlib.pyplot as plt -from matplotlib._color_data import XKCD_COLORS - -with open(sys.argv[1], 'r') as f: - txt = f.read() - -txt, overall = txt.split('overall performance') - -class_names = [] -mAP_overall = [] -mAP_small = [] -mAP_medium = [] -mAP_large = [] - -for class_result in txt.split('evaluate category: ')[1:]: - lines = class_result.split('\n') - class_names.append(lines[0]) - - def grabMAP(string): - return float(string.split('] = ')[1]) * 100 - - mAP_overall.append(grabMAP(lines[ 7])) - mAP_small .append(grabMAP(lines[10])) - mAP_medium .append(grabMAP(lines[11])) - mAP_large .append(grabMAP(lines[12])) - -mAP_map = { - 'small': mAP_small, - 'medium': mAP_medium, - 'large': mAP_large, -} - -if len(sys.argv) > 2: - bars = plt.bar(class_names, mAP_map[sys.argv[2]]) - plt.title(sys.argv[2] + ' mAP per class') -else: - bars = plt.bar(class_names, mAP_overall) - plt.title('overall mAP per class') - -colors = list(XKCD_COLORS.values()) - -for idx, bar in enumerate(bars): - # Mmm pseudorandom colors - char_sum = sum([ord(char) for char in class_names[idx]]) - bar.set_color(colors[char_sum % len(colors)]) - -plt.xticks(rotation='vertical') -plt.show() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import re, sys, os +import matplotlib.pyplot as plt +from matplotlib._color_data import XKCD_COLORS + +with open(sys.argv[1], 'r') as f: + txt = f.read() + +txt, overall = txt.split('overall performance') + +class_names = [] +mAP_overall = [] +mAP_small = [] +mAP_medium = [] +mAP_large = [] + +for class_result in txt.split('evaluate category: ')[1:]: + lines = class_result.split('\n') + class_names.append(lines[0]) + + def grabMAP(string): + return float(string.split('] = ')[1]) * 100 + + mAP_overall.append(grabMAP(lines[ 7])) + mAP_small .append(grabMAP(lines[10])) + mAP_medium .append(grabMAP(lines[11])) + mAP_large .append(grabMAP(lines[12])) + +mAP_map = { + 'small': mAP_small, + 'medium': mAP_medium, + 'large': mAP_large, +} + +if len(sys.argv) > 2: + bars = plt.bar(class_names, mAP_map[sys.argv[2]]) + plt.title(sys.argv[2] + ' mAP per class') +else: + bars = plt.bar(class_names, mAP_overall) + plt.title('overall mAP per class') + +colors = list(XKCD_COLORS.values()) + +for idx, bar in enumerate(bars): + # Mmm pseudorandom colors + char_sum = sum([ord(char) for char in class_names[idx]]) + bar.set_color(colors[char_sum % len(colors)]) + +plt.xticks(rotation='vertical') +plt.show() diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/plot_loss.py b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/plot_loss.py index 415d1041d6f28035c5d590270d6ddfccd3f342c4..0442bc633b43cfe85aa295b65cd19ebde7855e97 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/plot_loss.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/plot_loss.py @@ -1,92 +1,92 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import re, sys, os -import matplotlib.pyplot as plt - -from utils.functions import MovingAverage - -with open(sys.argv[1], 'r') as f: - inp = f.read() - -patterns = { - 'train': re.compile(r'\[\s*(?P\d+)\]\s*(?P\d+) \|\| B: (?P\S+) \| C: (?P\S+) \| M: (?P\S+) \|( S: (?P\S+) \|)? T: (?P\S+)'), - 'val': re.compile(r'\s*(?P[a-z]+) \|\s*(?P\S+)') -} -data = {key: [] for key in patterns} - -for line in inp.split('\n'): - for key, pattern in patterns.items(): - f = pattern.search(line) - - if f is not None: - datum = f.groupdict() - for k, v in datum.items(): - if v is not None: - try: - v = float(v) - except ValueError: - pass - datum[k] = v - - if key == 'val': - datum = (datum, data['train'][-1]) - data[key].append(datum) - break - - -def smoother(y, interval=100): - avg = MovingAverage(interval) - - for i in range(len(y)): - avg.append(y[i]) - y[i] = avg.get_avg() - - return y - -def plot_train(data): - plt.title(os.path.basename(sys.argv[1]) + ' Training Loss') - plt.xlabel('Iteration') - plt.ylabel('Loss') - - loss_names = ['BBox Loss', 'Conf Loss', 'Mask Loss'] - - x = [x['iteration'] for x in data] - plt.plot(x, smoother([y['b'] for y in data])) - plt.plot(x, smoother([y['c'] for y in data])) - plt.plot(x, smoother([y['m'] for y in data])) - - if data[0]['s'] is not None: - plt.plot(x, smoother([y['s'] for y in data])) - loss_names.append('Segmentation Loss') - - plt.legend(loss_names) - plt.show() - -def plot_val(data): - plt.title(os.path.basename(sys.argv[1]) + ' Validation mAP') - plt.xlabel('Epoch') - plt.ylabel('mAP') - - x = [x[1]['epoch'] for x in data if x[0]['type'] == 'box'] - plt.plot(x, [x[0]['all'] for x in data if x[0]['type'] == 'box']) - plt.plot(x, [x[0]['all'] for x in data if x[0]['type'] == 'mask']) - - plt.legend(['BBox mAP', 'Mask mAP']) - plt.show() - -if len(sys.argv) > 2 and sys.argv[2] == 'val': - plot_val(data['val']) -else: - plot_train(data['train']) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import re, sys, os +import matplotlib.pyplot as plt + +from utils.functions import MovingAverage + +with open(sys.argv[1], 'r') as f: + inp = f.read() + +patterns = { + 'train': re.compile(r'\[\s*(?P\d+)\]\s*(?P\d+) \|\| B: (?P\S+) \| C: (?P\S+) \| M: (?P\S+) \|( S: (?P\S+) \|)? T: (?P\S+)'), + 'val': re.compile(r'\s*(?P[a-z]+) \|\s*(?P\S+)') +} +data = {key: [] for key in patterns} + +for line in inp.split('\n'): + for key, pattern in patterns.items(): + f = pattern.search(line) + + if f is not None: + datum = f.groupdict() + for k, v in datum.items(): + if v is not None: + try: + v = float(v) + except ValueError: + pass + datum[k] = v + + if key == 'val': + datum = (datum, data['train'][-1]) + data[key].append(datum) + break + + +def smoother(y, interval=100): + avg = MovingAverage(interval) + + for i in range(len(y)): + avg.append(y[i]) + y[i] = avg.get_avg() + + return y + +def plot_train(data): + plt.title(os.path.basename(sys.argv[1]) + ' Training Loss') + plt.xlabel('Iteration') + plt.ylabel('Loss') + + loss_names = ['BBox Loss', 'Conf Loss', 'Mask Loss'] + + x = [x['iteration'] for x in data] + plt.plot(x, smoother([y['b'] for y in data])) + plt.plot(x, smoother([y['c'] for y in data])) + plt.plot(x, smoother([y['m'] for y in data])) + + if data[0]['s'] is not None: + plt.plot(x, smoother([y['s'] for y in data])) + loss_names.append('Segmentation Loss') + + plt.legend(loss_names) + plt.show() + +def plot_val(data): + plt.title(os.path.basename(sys.argv[1]) + ' Validation mAP') + plt.xlabel('Epoch') + plt.ylabel('mAP') + + x = [x[1]['epoch'] for x in data if x[0]['type'] == 'box'] + plt.plot(x, [x[0]['all'] for x in data if x[0]['type'] == 'box']) + plt.plot(x, [x[0]['all'] for x in data if x[0]['type'] == 'mask']) + + plt.legend(['BBox mAP', 'Mask mAP']) + plt.show() + +if len(sys.argv) > 2 and sys.argv[2] == 'val': + plot_val(data['val']) +else: + plot_train(data['train']) diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/resume.sh b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/resume.sh index 336af0552f9b6efb02b33020607a379bd4fdf89e..d4857876bdf69b0a1d7b0e0e08697d1552b623dc 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/resume.sh +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/resume.sh @@ -1,14 +1,14 @@ -#!/bin/bash -#SBATCH -p GPU-shared -#SBATCH -t 48:00:00 -#SBATCH --gres=gpu:p100:1 -#SBATCH --no-requeue - -# Usage: ./resume.sh config batch_size resume_file - -module load python/3.6.4_gcc5_np1.14.5 -module load cuda/9.0 - -cd $SCRATCH/yolact - -python3 train.py --config $1 --batch_size $2 --resume=$3 --save_interval 5000 --start_iter=-1 >>logs/$1_log 2>&1 +#!/bin/bash +#SBATCH -p GPU-shared +#SBATCH -t 48:00:00 +#SBATCH --gres=gpu:p100:1 +#SBATCH --no-requeue + +# Usage: ./resume.sh config batch_size resume_file + +module load python/3.6.4_gcc5_np1.14.5 +module load cuda/9.0 + +cd $SCRATCH/yolact + +python3 train.py --config $1 --batch_size $2 --resume=$3 --save_interval 5000 --start_iter=-1 >>logs/$1_log 2>&1 diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/save_bboxes.py b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/save_bboxes.py index 0218314152fe17b9cb6a357d802284c7921eb949..64aee2eb36dabfc0ae760f445cf24ce9b9236f45 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/save_bboxes.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/save_bboxes.py @@ -1,47 +1,47 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -""" This script transforms and saves bbox coordinates into a pickle object for easy loading. """ - - -import os.path as osp -import json, pickle -import sys - -import numpy as np - -COCO_ROOT = osp.join('.', 'data/coco/') - -annotation_file = 'instances_train2017.json' -annotation_path = osp.join(COCO_ROOT, 'annotations/', annotation_file) - -dump_file = 'weights/bboxes.pkl' - -with open(annotation_path, 'r') as f: - annotations_json = json.load(f) - -annotations = annotations_json['annotations'] -images = annotations_json['images'] -images = {image['id']: image for image in images} -bboxes = [] - -for ann in annotations: - image = images[ann['image_id']] - w,h = (image['width'], image['height']) - - if 'bbox' in ann: - bboxes.append([w, h] + ann['bbox']) - -with open(dump_file, 'wb') as f: - pickle.dump(bboxes, f) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +""" This script transforms and saves bbox coordinates into a pickle object for easy loading. """ + + +import os.path as osp +import json, pickle +import sys + +import numpy as np + +COCO_ROOT = osp.join('.', 'data/coco/') + +annotation_file = 'instances_train2017.json' +annotation_path = osp.join(COCO_ROOT, 'annotations/', annotation_file) + +dump_file = 'weights/bboxes.pkl' + +with open(annotation_path, 'r') as f: + annotations_json = json.load(f) + +annotations = annotations_json['annotations'] +images = annotations_json['images'] +images = {image['id']: image for image in images} +bboxes = [] + +for ann in annotations: + image = images[ann['image_id']] + w,h = (image['width'], image['height']) + + if 'bbox' in ann: + bboxes.append([w, h] + ann['bbox']) + +with open(dump_file, 'wb') as f: + pickle.dump(bboxes, f) diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/train.sh b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/train.sh index 36dff27c5069ea7e9224d953f1aad5ad99124393..b526d93c92bc6b4c262d622be05abf342fece9d0 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/train.sh +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/train.sh @@ -1,14 +1,14 @@ -#!/bin/bash -#SBATCH -p GPU-shared -#SBATCH -t 48:00:00 -#SBATCH --gres=gpu:p100:1 -#SBATCH --no-requeue - -# Usage: ./train.sh config batch_size - -module load python/3.6.4_gcc5_np1.14.5 -module load cuda/9.0 - -cd $SCRATCH/yolact - -python3 train.py --config $1 --batch_size $2 --save_interval 5000 &>logs/$1_log +#!/bin/bash +#SBATCH -p GPU-shared +#SBATCH -t 48:00:00 +#SBATCH --gres=gpu:p100:1 +#SBATCH --no-requeue + +# Usage: ./train.sh config batch_size + +module load python/3.6.4_gcc5_np1.14.5 +module load cuda/9.0 + +cd $SCRATCH/yolact + +python3 train.py --config $1 --batch_size $2 --save_interval 5000 &>logs/$1_log diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/unpack_statedict.py b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/unpack_statedict.py index 7f1fa5f47b7bceddab7695e15005286d0b2530e4..41b7314c35cc74bb61035b804a683ae9b8c3559b 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/unpack_statedict.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/scripts/unpack_statedict.py @@ -1,30 +1,30 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch -import sys, os - -# Usage python scripts/unpack_statedict.py path_to_pth out_folder/ -# Make sure to include that slash after your out folder, since I can't -# be arsed to do path concatenation so I'd rather type out this comment - -print('Loading state dict...') -state = torch.load(sys.argv[1]) - -if not os.path.exists(sys.argv[2]): - os.mkdir(sys.argv[2]) - -print('Saving stuff...') -for key, val in state.items(): - torch.save(val, sys.argv[2] + key) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch +import sys, os + +# Usage python scripts/unpack_statedict.py path_to_pth out_folder/ +# Make sure to include that slash after your out folder, since I can't +# be arsed to do path concatenation so I'd rather type out this comment + +print('Loading state dict...') +state = torch.load(sys.argv[1]) + +if not os.path.exists(sys.argv[2]): + os.mkdir(sys.argv[2]) + +print('Saving stuff...') +for key, val in state.items(): + torch.save(val, sys.argv[2] + key) diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/test/env_npu.sh b/PyTorch/contrib/cv/detection/YOLACT_plus/test/env_npu.sh index 3d4584311c99e1d5945db268a6e50b25cf844d39..d7213fd06e5ba36e8ecb005b9ad1b64da6357227 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/test/env_npu.sh +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/test/env_npu.sh @@ -1,75 +1,75 @@ -#!/bin/bash -export install_path=/usr/local/Ascend - -if [ -d ${install_path}/toolkit ]; then - export LD_LIBRARY_PATH=${install_path}/fwkacllib/lib64/:/usr/include/hdf5/lib/:/usr/local/:/usr/local/lib/:/usr/lib/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons:${path_lib}:${LD_LIBRARY_PATH} - export PATH=${install_path}/fwkacllib/ccec_compiler/bin:${install_path}/fwkacllib/bin:$PATH - export PYTHONPATH=${install_path}/fwkacllib/python/site-packages:${install_path}/tfplugin/python/site-packages:${install_path}/toolkit/python/site-packages:$PYTHONPATH - export PYTHONPATH=/usr/local/python3.7.5/lib/python3.7/site-packages:$PYTHONPATH - export ASCEND_OPP_PATH=${install_path}/opp -else - if [ -d ${install_path}/nnae/latest ];then - export LD_LIBRARY_PATH=${install_path}/nnae/latest/fwkacllib/lib64/:/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH - export PATH=$PATH:${install_path}/nnae/latest/fwkacllib/ccec_compiler/bin/:${install_path}/nnae/latest/toolkit/tools/ide_daemon/bin/ - export ASCEND_OPP_PATH=${install_path}/nnae/latest/opp/ - export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so - export PYTHONPATH=${install_path}/nnae/latest/fwkacllib/python/site-packages/:${install_path}/nnae/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:${install_path}/nnae/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH - export ASCEND_AICPU_PATH=${install_path}/nnae/latest - else - export LD_LIBRARY_PATH=${install_path}/ascend-toolkit/latest/fwkacllib/lib64/:/usr/local/:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64-linux-gnu:$LD_LIBRARY_PATH - export PATH=$PATH:${install_path}/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin/:${install_path}/ascend-toolkit/latest/toolkit/tools/ide_daemon/bin/ - export ASCEND_OPP_PATH=${install_path}/ascend-toolkit/latest/opp/ - export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so - export PYTHONPATH=${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/:${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH - export ASCEND_AICPU_PATH=${install_path}/ascend-toolkit/latest - fi -fi - -${install_path}/driver/tools/msnpureport -g error -d 0 -${install_path}/driver/tools/msnpureport -g error -d 1 -${install_path}/driver/tools/msnpureport -g error -d 2 -${install_path}/driver/tools/msnpureport -g error -d 3 -${install_path}/driver/tools/msnpureport -g error -d 4 -${install_path}/driver/tools/msnpureport -g error -d 5 -${install_path}/driver/tools/msnpureport -g error -d 6 -${install_path}/driver/tools/msnpureport -g error -d 7 - -#将Host日志输出到串口,0-关闭/1-开启 -export ASCEND_SLOG_PRINT_TO_STDOUT=0 -#设置默认日志级别,0-debug/1-info/2-warning/3-error -export ASCEND_GLOBAL_LOG_LEVEL=3 -#设置Event日志开启标志,0-关闭/1-开启 -export ASCEND_GLOBAL_EVENT_ENABLE=0 -#设置是否开启taskque,0-关闭/1-开启 -export TASK_QUEUE_ENABLE=1 -#设置是否开启PTCopy,0-关闭/1-开启 -export PTCOPY_ENABLE=1 -#设置是否开启combined标志,0-关闭/1-开启 -export COMBINED_ENABLE=0 -#设置特殊场景是否需要重新编译,不需要修改 -export DYNAMIC_OP="ADD#MUL" -#HCCL白名单开关,1-关闭/0-开启 -export HCCL_WHITELIST_DISABLE=1 - -ulimit -SHn 512000 - -path_lib=$(python3.7 -c """ -import sys -import re -result='' -for index in range(len(sys.path)): - match_sit = re.search('-packages', sys.path[index]) - if match_sit is not None: - match_lib = re.search('lib', sys.path[index]) - - if match_lib is not None: - end=match_lib.span()[1] - result += sys.path[index][0:end] + ':' - - result+=sys.path[index] + '/torch/lib:' -print(result)""" -) - -echo ${path_lib} - -export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib/:${path_lib}:$LD_LIBRARY_PATH +#!/bin/bash +export install_path=/usr/local/Ascend + +if [ -d ${install_path}/toolkit ]; then + export LD_LIBRARY_PATH=${install_path}/fwkacllib/lib64/:/usr/include/hdf5/lib/:/usr/local/:/usr/local/lib/:/usr/lib/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons:${path_lib}:${LD_LIBRARY_PATH} + export PATH=${install_path}/fwkacllib/ccec_compiler/bin:${install_path}/fwkacllib/bin:$PATH + export PYTHONPATH=${install_path}/fwkacllib/python/site-packages:${install_path}/tfplugin/python/site-packages:${install_path}/toolkit/python/site-packages:$PYTHONPATH + export PYTHONPATH=/usr/local/python3.7.5/lib/python3.7/site-packages:$PYTHONPATH + export ASCEND_OPP_PATH=${install_path}/opp +else + if [ -d ${install_path}/nnae/latest ];then + export LD_LIBRARY_PATH=${install_path}/nnae/latest/fwkacllib/lib64/:/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH + export PATH=$PATH:${install_path}/nnae/latest/fwkacllib/ccec_compiler/bin/:${install_path}/nnae/latest/toolkit/tools/ide_daemon/bin/ + export ASCEND_OPP_PATH=${install_path}/nnae/latest/opp/ + export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so + export PYTHONPATH=${install_path}/nnae/latest/fwkacllib/python/site-packages/:${install_path}/nnae/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:${install_path}/nnae/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH + export ASCEND_AICPU_PATH=${install_path}/nnae/latest + else + export LD_LIBRARY_PATH=${install_path}/ascend-toolkit/latest/fwkacllib/lib64/:/usr/local/:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64-linux-gnu:$LD_LIBRARY_PATH + export PATH=$PATH:${install_path}/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin/:${install_path}/ascend-toolkit/latest/toolkit/tools/ide_daemon/bin/ + export ASCEND_OPP_PATH=${install_path}/ascend-toolkit/latest/opp/ + export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so + export PYTHONPATH=${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/:${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:${install_path}/ascend-toolkit/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH + export ASCEND_AICPU_PATH=${install_path}/ascend-toolkit/latest + fi +fi + +${install_path}/driver/tools/msnpureport -g error -d 0 +${install_path}/driver/tools/msnpureport -g error -d 1 +${install_path}/driver/tools/msnpureport -g error -d 2 +${install_path}/driver/tools/msnpureport -g error -d 3 +${install_path}/driver/tools/msnpureport -g error -d 4 +${install_path}/driver/tools/msnpureport -g error -d 5 +${install_path}/driver/tools/msnpureport -g error -d 6 +${install_path}/driver/tools/msnpureport -g error -d 7 + +#将Host日志输出到串口,0-关闭/1-开启 +export ASCEND_SLOG_PRINT_TO_STDOUT=0 +#设置默认日志级别,0-debug/1-info/2-warning/3-error +export ASCEND_GLOBAL_LOG_LEVEL=3 +#设置Event日志开启标志,0-关闭/1-开启 +export ASCEND_GLOBAL_EVENT_ENABLE=0 +#设置是否开启taskque,0-关闭/1-开启 +export TASK_QUEUE_ENABLE=1 +#设置是否开启PTCopy,0-关闭/1-开启 +export PTCOPY_ENABLE=1 +#设置是否开启combined标志,0-关闭/1-开启 +export COMBINED_ENABLE=0 +#设置特殊场景是否需要重新编译,不需要修改 +export DYNAMIC_OP="ADD#MUL" +#HCCL白名单开关,1-关闭/0-开启 +export HCCL_WHITELIST_DISABLE=1 + +ulimit -SHn 512000 + +path_lib=$(python3.7 -c """ +import sys +import re +result='' +for index in range(len(sys.path)): + match_sit = re.search('-packages', sys.path[index]) + if match_sit is not None: + match_lib = re.search('lib', sys.path[index]) + + if match_lib is not None: + end=match_lib.span()[1] + result += sys.path[index][0:end] + ':' + + result+=sys.path[index] + '/torch/lib:' +print(result)""" +) + +echo ${path_lib} + +export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib/:${path_lib}:$LD_LIBRARY_PATH diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_eval_1p.sh b/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_eval_1p.sh index 50a1c105abefe2e5ed5a329ba57827bfe5f176b6..7ec0becd650635034a96579173c81625c1babf6d 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_eval_1p.sh +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_eval_1p.sh @@ -1,141 +1,141 @@ -#!/bin/bash - -################基础配置参数,需要模型审视修改################## -# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE -# 网络名称,同目录名称 -Network="YOLACT-plus" -# 训练batch_size -batch_size=16 -# 推理使用的npu卡数 -export RANK_SIZE=1 -# 数据集路径,保持为空,不需要修改 --data_path=./data/TrainDataset -data_path="" - -# checkpoint文件路径,以实际路径为准 --pth_path=./checkopint.pth.tar -pth_path='' - -# 指定推理所使用的npu device卡id -device_id=0 - -# 参数校验,data_path为必传参数,其他参数的增删由模型自身决定;此处新增参数需在上面有定义并赋值 -for para in $* -do - if [[ $para == --device_id* ]];then - device_id=`echo ${para#*=}` - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --pth_path* ]];then - pth_path=`echo ${para#*=}` - fi -done - -# 校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi -# 校验是否传入 pth_path , 验证脚本需要传入此参数 -if [[ $pth_path == "" ]];then - echo "[Error] para \"pth_path\" must be confing" - exit 1 -fi -# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - -###############指定训练脚本执行路径############### -# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - -#################创建日志输出目录,不需要修改################# - -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - #rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -fi - -#################启动训练(train)脚本################# -#训练开始时间,不需要修改 -start_time=$(date +%s) -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi -export RANK_ID=${ASCEND_DEVICE_ID} -# 获取训练生成的log文件 -TRAIN_LOG_FILE_0=${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log - -##################计算并获取精度################ -LOG_FILE=${test_path_dir}/output/${ASCEND_DEVICE_ID}/eval_${ASCEND_DEVICE_ID}.log - -python3.7 eval.py --trained_model=${pth_path} \ - --data_path=${data_path} > $LOG_FILE 2>&1 & - -wait - -##################计算并获取精度################ -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep -a 'FPS' ${TRAIN_LOG_FILE_0} | awk -F " " '{print $2}'|awk 'END {print}'` -#打印,不需要修改 -echo "Final Performance images/sec : ${FPS}" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a 'mask |' ${LOG_FILE} |awk -F " " '{print $3}'|awk 'END {print}'` -# #打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "||" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |awk -F '[|][|]' '{print $2}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` -echo "train_accuracy: ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +################基础配置参数,需要模型审视修改################## +# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE +# 网络名称,同目录名称 +Network="YOLACT-plus" +# 训练batch_size +batch_size=16 +# 推理使用的npu卡数 +export RANK_SIZE=1 +# 数据集路径,保持为空,不需要修改 --data_path=./data/TrainDataset +data_path="" + +# checkpoint文件路径,以实际路径为准 --pth_path=./checkopint.pth.tar +pth_path='' + +# 指定推理所使用的npu device卡id +device_id=0 + +# 参数校验,data_path为必传参数,其他参数的增删由模型自身决定;此处新增参数需在上面有定义并赋值 +for para in $* +do + if [[ $para == --device_id* ]];then + device_id=`echo ${para#*=}` + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --pth_path* ]];then + pth_path=`echo ${para#*=}` + fi +done + +# 校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi +# 校验是否传入 pth_path , 验证脚本需要传入此参数 +if [[ $pth_path == "" ]];then + echo "[Error] para \"pth_path\" must be confing" + exit 1 +fi +# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + +###############指定训练脚本执行路径############### +# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +#################创建日志输出目录,不需要修改################# + +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + #rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +fi + +#################启动训练(train)脚本################# +#训练开始时间,不需要修改 +start_time=$(date +%s) +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi +export RANK_ID=${ASCEND_DEVICE_ID} +# 获取训练生成的log文件 +TRAIN_LOG_FILE_0=${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log + +##################计算并获取精度################ +LOG_FILE=${test_path_dir}/output/${ASCEND_DEVICE_ID}/eval_${ASCEND_DEVICE_ID}.log + +python3.7 eval.py --trained_model=${pth_path} \ + --data_path=${data_path} > $LOG_FILE 2>&1 & + +wait + +##################计算并获取精度################ +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep -a 'FPS' ${TRAIN_LOG_FILE_0} | awk -F " " '{print $2}'|awk 'END {print}'` +#打印,不需要修改 +echo "Final Performance images/sec : ${FPS}" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a 'mask |' ${LOG_FILE} |awk -F " " '{print $3}'|awk 'END {print}'` +# #打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "||" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |awk -F '[|][|]' '{print $2}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` +echo "train_accuracy: ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_full_1p.sh b/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_full_1p.sh index 09ada4f9ca70d8f80b1ae564439e392fa231a37f..852823749dbdead5e14d50cf460181245de64e61 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_full_1p.sh +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_full_1p.sh @@ -1,152 +1,152 @@ -#!/bin/bash - -################基础配置参数,需要模型审视修改################## -# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE -# 网络名称,同目录名称 -Network="YOLACT-plus" -# 训练batch_size -batch_size=16 -# 训练使用的npu卡数 -export RANK_SIZE=1 -# 数据集路径,保持为空,不需要修改 --data_path=./data/TrainDataset -data_path="" - -# checkpoint文件路径,以实际路径为准 --pth_path=./checkopint.pth.tar -pth_path='' - -# 训练step -max_iter=1250000 -# 指定训练所使用的npu device卡id -device_id=0 -# 加载数据进程数 -workers=8 - -# 参数校验,data_path为必传参数,其他参数的增删由模型自身决定;此处新增参数需在上面有定义并赋值 -for para in $* -do - if [[ $para == --device_id* ]];then - device_id=`echo ${para#*=}` - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --pth_path* ]];then - pth_path=`echo ${para#*=}` - fi -done - -# 校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi -# 校验是否传入 pth_path , 验证脚本需要传入此参数 -#if [[ $pth_path == "" ]];then -# echo "[Error] para \"pth_path\" must be confing" -# exit 1 -#fi - -# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - - - -###############指定训练脚本执行路径############### -# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - - -#################创建日志输出目录,不需要修改################# - if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID - else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID - fi - - -#################启动训练脚本################# -#训练开始时间,不需要修改 -start_time=$(date +%s) -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi -export RANK_ID=${ASCEND_DEVICE_ID} -python3.7 ./train.py \ - --data_path=${data_path} \ - --num_workers=${workers} \ - --lr=2e-3 \ - --config=yolact_plus_resnet50_config \ - --max_iter=${max_iter} \ - --resume=${pth_path} \ - --save_interval=62500 \ - --batch_size=${batch_size} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -wait - -python3.7 eval.py --trained_model=weights/yolact_plus.pth > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/eval_${ASCEND_DEVICE_ID}.log 2>&1 -wait - -##################获取训练数据################ -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F " " '{print $2}'|awk 'END {print}'` -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a 'mask |' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/eval_${ASCEND_DEVICE_ID}.log |awk -F " " '{print $3}'|awk 'END {print}'` -# #打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "||" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |awk -F '[|][|]' '{print $2}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` -echo "train_accuracy: ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +################基础配置参数,需要模型审视修改################## +# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE +# 网络名称,同目录名称 +Network="YOLACT-plus" +# 训练batch_size +batch_size=16 +# 训练使用的npu卡数 +export RANK_SIZE=1 +# 数据集路径,保持为空,不需要修改 --data_path=./data/TrainDataset +data_path="" + +# checkpoint文件路径,以实际路径为准 --pth_path=./checkopint.pth.tar +pth_path='' + +# 训练step +max_iter=1250000 +# 指定训练所使用的npu device卡id +device_id=0 +# 加载数据进程数 +workers=8 + +# 参数校验,data_path为必传参数,其他参数的增删由模型自身决定;此处新增参数需在上面有定义并赋值 +for para in $* +do + if [[ $para == --device_id* ]];then + device_id=`echo ${para#*=}` + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --pth_path* ]];then + pth_path=`echo ${para#*=}` + fi +done + +# 校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi +# 校验是否传入 pth_path , 验证脚本需要传入此参数 +#if [[ $pth_path == "" ]];then +# echo "[Error] para \"pth_path\" must be confing" +# exit 1 +#fi + +# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + + + +###############指定训练脚本执行路径############### +# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + + +#################创建日志输出目录,不需要修改################# + if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID + else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID + fi + + +#################启动训练脚本################# +#训练开始时间,不需要修改 +start_time=$(date +%s) +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi +export RANK_ID=${ASCEND_DEVICE_ID} +python3.7 ./train.py \ + --data_path=${data_path} \ + --num_workers=${workers} \ + --lr=2e-3 \ + --config=yolact_plus_resnet50_config \ + --max_iter=${max_iter} \ + --resume=${pth_path} \ + --save_interval=62500 \ + --batch_size=${batch_size} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +wait + +python3.7 eval.py --trained_model=weights/yolact_plus.pth > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/eval_${ASCEND_DEVICE_ID}.log 2>&1 +wait + +##################获取训练数据################ +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F " " '{print $2}'|awk 'END {print}'` +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a 'mask |' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/eval_${ASCEND_DEVICE_ID}.log |awk -F " " '{print $3}'|awk 'END {print}'` +# #打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "||" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |awk -F '[|][|]' '{print $2}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` +echo "train_accuracy: ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_full_8p.sh b/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_full_8p.sh index 60c34bd048e2658b36c10d5233669831273778ee..2bfef08bce800ad6aef21b3c941a7821650cd48e 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_full_8p.sh +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_full_8p.sh @@ -1,173 +1,173 @@ -#!/bin/bash - -################基础配置参数,需要模型审视修改################## -# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE -# 网络名称,同目录名称 -Network="YOLACT-plus" -# 训练batch_size -batch_size=16 -# 训练使用的npu卡数 -export RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 --data_path=./data/TrainDataset -data_path="" - -# checkpoint文件路径,以实际路径为准 --pth_path=./checkopint.pth.tar -pth_path='' - -# 训练step -max_iter=1250000 -# 指定训练所使用的npu device卡id -device_id=0 -# 加载数据进程数 -workers=8 - -# 参数校验,data_path为必传参数,其他参数的增删由模型自身决定;此处新增参数需在上面有定义并赋值 -for para in $* -do - if [[ $para == --device_id* ]];then - device_id=`echo ${para#*=}` - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --pth_path* ]];then - pth_path=`echo ${para#*=}` - fi -done - -# 校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi -# 校验是否传入 pth_path , 验证脚本需要传入此参数 -#if [[ $pth_path == "" ]];then -# echo "[Error] para \"pth_path\" must be confing" -# exit 1 -#fi - -# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - - - -###############指定训练脚本执行路径############### -# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - - -#################创建日志输出目录,不需要修改################# - if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID - else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID - fi - - -#################启动训练脚本################# -#训练开始时间,不需要修改 -start_time=$(date +%s) -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi - -for((RANK_ID=0;RANK_ID ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & - else - python3.7 -u train.py \ - --data_path=${data_path} \ - --num_workers=${workers} \ - --lr=2e-3 \ - --config=yolact_plus_resnet50_config \ - --max_iter=${max_iter} \ - --resume=${pth_path} \ - --save_interval=62500 \ - --batch_size=${batch_size} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & - fi -done -wait -python3.7 eval.py --trained_model=weights/yolact_plus.pth > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/eval_${ASCEND_DEVICE_ID}.log 2>&1 -wait - -##################获取训练数据################ -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F " " '{print $2}'|awk 'END {print}'` -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a 'mask |' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/eval_${ASCEND_DEVICE_ID}.log |awk -F " " '{print $3}'|awk 'END {print}'` -# #打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "||" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |awk -F '[|][|]' '{print $2}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` -echo "train_accuracy: ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +################基础配置参数,需要模型审视修改################## +# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE +# 网络名称,同目录名称 +Network="YOLACT-plus" +# 训练batch_size +batch_size=16 +# 训练使用的npu卡数 +export RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 --data_path=./data/TrainDataset +data_path="" + +# checkpoint文件路径,以实际路径为准 --pth_path=./checkopint.pth.tar +pth_path='' + +# 训练step +max_iter=1250000 +# 指定训练所使用的npu device卡id +device_id=0 +# 加载数据进程数 +workers=8 + +# 参数校验,data_path为必传参数,其他参数的增删由模型自身决定;此处新增参数需在上面有定义并赋值 +for para in $* +do + if [[ $para == --device_id* ]];then + device_id=`echo ${para#*=}` + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --pth_path* ]];then + pth_path=`echo ${para#*=}` + fi +done + +# 校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi +# 校验是否传入 pth_path , 验证脚本需要传入此参数 +#if [[ $pth_path == "" ]];then +# echo "[Error] para \"pth_path\" must be confing" +# exit 1 +#fi + +# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + + + +###############指定训练脚本执行路径############### +# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + + +#################创建日志输出目录,不需要修改################# + if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID + else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID + fi + + +#################启动训练脚本################# +#训练开始时间,不需要修改 +start_time=$(date +%s) +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi + +for((RANK_ID=0;RANK_ID ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + else + python3.7 -u train.py \ + --data_path=${data_path} \ + --num_workers=${workers} \ + --lr=2e-3 \ + --config=yolact_plus_resnet50_config \ + --max_iter=${max_iter} \ + --resume=${pth_path} \ + --save_interval=62500 \ + --batch_size=${batch_size} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + fi +done +wait +python3.7 eval.py --trained_model=weights/yolact_plus.pth > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/eval_${ASCEND_DEVICE_ID}.log 2>&1 +wait + +##################获取训练数据################ +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F " " '{print $2}'|awk 'END {print}'` +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a 'mask |' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/eval_${ASCEND_DEVICE_ID}.log |awk -F " " '{print $3}'|awk 'END {print}'` +# #打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "||" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |awk -F '[|][|]' '{print $2}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` +echo "train_accuracy: ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_performance_1p.sh b/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_performance_1p.sh index d2d8a4923b5183c89e3a16d645ce0a2e68b91312..62aacb3977d3f38f265b72a834a70593279655fb 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_performance_1p.sh +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/test/train_performance_1p.sh @@ -1,149 +1,149 @@ -#!/bin/bash - -################基础配置参数,需要模型审视修改################## -# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE -# 网络名称,同目录名称 -Network="YOLACT-plus" -# 训练batch_size -batch_size=16 -# 训练使用的npu卡数 -export RANK_SIZE=1 -# 数据集路径,保持为空,不需要修改 --data_path=./data/TrainDataset -data_path="" - -# checkpoint文件路径,以实际路径为准 --pth_path=./checkopint.pth.tar -pth_path='' - -# 训练step -max_iter=1000 -# 指定训练所使用的npu device卡id -device_id=0 -# 加载数据进程数 -workers=8 - -# 参数校验,data_path为必传参数,其他参数的增删由模型自身决定;此处新增参数需在上面有定义并赋值 -for para in $* -do - if [[ $para == --device_id* ]];then - device_id=`echo ${para#*=}` - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --pth_path* ]];then - pth_path=`echo ${para#*=}` - fi -done - -# 校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi -# 校验是否传入 pth_path , 验证脚本需要传入此参数 -#if [[ $pth_path == "" ]];then -# echo "[Error] para \"pth_path\" must be confing" -# exit 1 -#fi - -# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 -if [ $ASCEND_DEVICE_ID ];then - echo "device id is ${ASCEND_DEVICE_ID}" -elif [ ${device_id} ];then - export ASCEND_DEVICE_ID=${device_id} - echo "device id is ${ASCEND_DEVICE_ID}" -else - "[Error] device id must be config" - exit 1 -fi - - - -###############指定训练脚本执行路径############### -# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 -cur_path=`pwd` -cur_path_last_dirname=${cur_path##*/} -if [ x"${cur_path_last_dirname}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - - -#################创建日志输出目录,不需要修改################# - if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID - else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID - fi - - -#################启动训练脚本################# -#训练开始时间,不需要修改 -start_time=$(date +%s) -# 非平台场景时source 环境变量 -check_etp_flag=`env | grep etp_running_flag` -etp_flag=`echo ${check_etp_flag#*=}` -if [ x"${etp_flag}" != x"true" ];then - source ${test_path_dir}/env_npu.sh -fi -export RANK_ID=${ASCEND_DEVICE_ID} -python3.7 ./train.py \ - --data_path=${data_path} \ - --num_workers=${workers} \ - --lr=2e-3 \ - --config=yolact_plus_resnet50_config \ - --max_iter=${max_iter} \ - --resume=${pth_path} \ - --save_interval=1000 \ - --batch_size=${batch_size} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -wait - -##################获取训练数据################ -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F " " '{print $2}'|awk 'END {print}'` -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a 'mask |' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/eval_${ASCEND_DEVICE_ID}.log |awk -F " " '{print $3}'|awk 'END {print}'` -# #打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "||" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |awk -F '[|][|]' '{print $2}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` -echo "train_accuracy: ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +################基础配置参数,需要模型审视修改################## +# 必选字段(必须在此处定义的参数): Network batch_size RANK_SIZE +# 网络名称,同目录名称 +Network="YOLACT-plus" +# 训练batch_size +batch_size=16 +# 训练使用的npu卡数 +export RANK_SIZE=1 +# 数据集路径,保持为空,不需要修改 --data_path=./data/TrainDataset +data_path="" + +# checkpoint文件路径,以实际路径为准 --pth_path=./checkopint.pth.tar +pth_path='' + +# 训练step +max_iter=1000 +# 指定训练所使用的npu device卡id +device_id=0 +# 加载数据进程数 +workers=8 + +# 参数校验,data_path为必传参数,其他参数的增删由模型自身决定;此处新增参数需在上面有定义并赋值 +for para in $* +do + if [[ $para == --device_id* ]];then + device_id=`echo ${para#*=}` + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --pth_path* ]];then + pth_path=`echo ${para#*=}` + fi +done + +# 校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi +# 校验是否传入 pth_path , 验证脚本需要传入此参数 +#if [[ $pth_path == "" ]];then +# echo "[Error] para \"pth_path\" must be confing" +# exit 1 +#fi + +# 校验是否指定了device_id,分动态分配device_id与手动指定device_id,此处不需要修改 +if [ $ASCEND_DEVICE_ID ];then + echo "device id is ${ASCEND_DEVICE_ID}" +elif [ ${device_id} ];then + export ASCEND_DEVICE_ID=${device_id} + echo "device id is ${ASCEND_DEVICE_ID}" +else + "[Error] device id must be config" + exit 1 +fi + + + +###############指定训练脚本执行路径############### +# cd到与test文件夹同层级目录下执行脚本,提高兼容性;test_path_dir为包含test文件夹的路径 +cur_path=`pwd` +cur_path_last_dirname=${cur_path##*/} +if [ x"${cur_path_last_dirname}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + + +#################创建日志输出目录,不需要修改################# + if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID + else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID + fi + + +#################启动训练脚本################# +#训练开始时间,不需要修改 +start_time=$(date +%s) +# 非平台场景时source 环境变量 +check_etp_flag=`env | grep etp_running_flag` +etp_flag=`echo ${check_etp_flag#*=}` +if [ x"${etp_flag}" != x"true" ];then + source ${test_path_dir}/env_npu.sh +fi +export RANK_ID=${ASCEND_DEVICE_ID} +python3.7 ./train.py \ + --data_path=${data_path} \ + --num_workers=${workers} \ + --lr=2e-3 \ + --config=yolact_plus_resnet50_config \ + --max_iter=${max_iter} \ + --resume=${pth_path} \ + --save_interval=1000 \ + --batch_size=${batch_size} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +wait + +##################获取训练数据################ +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F " " '{print $2}'|awk 'END {print}'` +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a 'mask |' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/eval_${ASCEND_DEVICE_ID}.log |awk -F " " '{print $3}'|awk 'END {print}'` +# #打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "||" ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |awk -F '[|][|]' '{print $2}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` +echo "train_accuracy: ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/train.py b/PyTorch/contrib/cv/detection/YOLACT_plus/train.py index 6d1e302204ac7fd3c7dc2c9eecbc6c9099842153..63d430a3d31ea430aca4ebe79d9ae3354d715f39 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/train.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/train.py @@ -1,660 +1,660 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -from data import * -from utils.augmentations import SSDAugmentation, BaseTransform -from utils.functions import MovingAverage, SavePath -from utils.logger import Log -from utils import timer -from layers.modules import MultiBoxLoss -from yolact import Yolact -import os -import sys -import time -import math, random -from pathlib import Path -import torch -from torch.autograd import Variable -import torch.nn as nn -import torch.optim as optim -import torch.backends.cudnn as cudnn -import torch.nn.init as init -import torch.utils.data as data -import numpy as np -import argparse -import datetime -from torch.nn.parallel import DistributedDataParallel as DDP -import torch.multiprocessing as mp -import torch.distributed as dist -# Oof -import eval as eval_script -from apex import amp - -def str2bool(v): - return v.lower() in ("yes", "true", "t", "1") - - -parser = argparse.ArgumentParser( - description='Yolact Training Script') -parser.add_argument('--batch_size', default=8, type=int, - help='Batch size for training') -parser.add_argument('--data_path', default=None, type=str, - help='data path') -parser.add_argument('--resume', default=None, type=str, - help='Checkpoint state_dict file to resume training from. If this is "interrupt"' \ - ', the model will resume training from the interrupt file.') -parser.add_argument('--start_iter', default=-1, type=int, - help='Resume training at this iter. If this is -1, the iteration will be' \ - 'determined from the file name.') -parser.add_argument('--fps_start_iter', default=100, type=int, - help='calculate fps at this iter. If this is -1, the iteration will be' \ - 'determined from the file name.') -parser.add_argument('--num_workers', default=0, type=int, - help='Number of workers used in dataloading') -parser.add_argument('--cuda', default=True, type=str2bool, - help='Use CUDA to train model') -parser.add_argument('--lr', '--learning_rate', default=None, type=float, - help='Initial learning rate. Leave as None to read this from the config.') -parser.add_argument('--momentum', default=None, type=float, - help='Momentum for SGD. Leave as None to read this from the config.') -parser.add_argument('--decay', '--weight_decay', default=None, type=float, - help='Weight decay for SGD. Leave as None to read this from the config.') -parser.add_argument('--gamma', default=None, type=float, - help='For each lr step, what to multiply the lr by. Leave as None to read this from the config.') -parser.add_argument('--save_folder', default='weights/', - help='Directory for saving checkpoint models.') -parser.add_argument('--log_folder', default='logs/', - help='Directory for saving logs.') -parser.add_argument('--config', default='yolact_base_config', - help='The config object to use.') -parser.add_argument('--max_iter', default=-1, type=int, - help='num of iter will train') -parser.add_argument('--save_interval', default=2000, type=int, - help='The number of iterations between saving the model.') -parser.add_argument('--validation_size', default=5000, type=int, - help='The number of images to use for validation.') -parser.add_argument('--validation_epoch', default=-1, type=int, - help='Output validation information every n iterations. If -1, do no validation.') -parser.add_argument('--keep_latest', dest='keep_latest', action='store_true', - help='Only keep the latest checkpoint instead of each one.') -parser.add_argument('--keep_latest_interval', default=100000, type=int, - help='When --keep_latest is on, don\'t delete the latest file at these intervals. This should be a multiple of save_interval or 0.') -parser.add_argument('--dataset', default=None, type=str, - help='If specified, override the dataset specified in the config with this one (example: coco2017_dataset).') -parser.add_argument('--no_log', dest='log', action='store_false', - help='Don\'t log per iteration information into log_folder.') -parser.add_argument('--log_gpu', dest='log_gpu', action='store_true', - help='Include GPU information in the logs. Nvidia-smi tends to be slow, so set this with caution.') -parser.add_argument('--no_interrupt', dest='interrupt', action='store_false', - help='Don\'t save an interrupt when KeyboardInterrupt is caught.') -parser.add_argument('--batch_alloc', default=None, type=str, - help='If using multiple GPUS, you can set this to be a comma separated list detailing which GPUs should get what local batch size (It should add up to your total batch size).') -parser.add_argument('--no_autoscale', dest='autoscale', action='store_false', - help='YOLACT will automatically scale the lr and the number of iterations depending on the batch size. Set this if you want to disable that.') -parser.add_argument('--useDDP', default=True, type=bool, help='use DistributedDataParallel or not') -parser.add_argument('--seed', default=None, type=int, help='set PyTorch seed') - -parser.set_defaults(keep_latest=False, log=True, log_gpu=False, interrupt=True, autoscale=True) -args = parser.parse_args() - -# 设置配置文件,无用 -if args.config is not None: - set_cfg(args.config) - -# 设置项目数据集,无用 -if args.dataset is not None: - set_dataset(args.dataset) - -if args.data_path: - cfg.dataset.train_images = args.data_path + '/train2017/' - cfg.dataset.train_info = args.data_path + '/annotations/instances_train2017.json' - -if args.autoscale and args.batch_size != 8: - factor = args.batch_size / 8 - if __name__ == '__main__': - print('Scaling parameters by %.2f to account for a batch size of %d.' % (factor, args.batch_size)) - - cfg.lr *= factor - cfg.max_iter //= factor - cfg.lr_steps = [x // factor for x in cfg.lr_steps] - -if args.max_iter>0: - cfg.max_iter = args.max_iter - -# Update training parameters from the config if necessary -def replace(name): - if getattr(args, name) == None: setattr(args, name, getattr(cfg, name)) - - -# 将args中参数替换为config中预设的值,便于后续调用 -replace('lr') -replace('decay') -replace('gamma') -replace('momentum') - -# This is managed by set_lr -# 两个学习率都有用,在后续自动更新学习率中,可以使用 -cur_lr = args.lr - -# 检查环境 -if torch.npu.device_count() == 0: - print('No GPUs detected. Exiting...') - exit(-1) - -# 当一块显卡中的图像个数大于等于6时,才启用batch normalization -if args.batch_size // torch.npu.device_count() < 6 and (not args.useDDP): - if __name__ == '__main__': - print('Per-NPU batch size is less than the recommended limit for batch norm. Disabling batch norm.') - cfg.freeze_bn = True - -if args.seed is not None: - seed = args.seed - os.environ['PYTHONHASHSEED'] = str(seed) - torch.manual_seed(seed) - torch.cuda.manual_seed(seed) - torch.npu.manual_seed(seed) - torch.cuda.manual_seed_all(seed) - torch.backends.cudnn.deterministic = True - print('Finish set seed, seed is :', seed) - -loss_types = ['B', 'C', 'M', 'P', 'D', 'E', 'S', 'I'] - -if torch.npu.is_available(): - print("npu environment is okay!, and current device count is", torch.npu.device_count()) - - -# if args.cuda: -# torch.set_default_tensor_type('torch.cuda.FloatTensor') -# if not args.cuda: -# print("WARNING: It looks like you have a CUDA device, but aren't " + -# "using CUDA.\nRun with --cuda for optimal training speed.") -# torch.set_default_tensor_type('torch.FloatTensor') -# else: -# torch.set_default_tensor_type('torch.FloatTensor') - -class NetLoss(nn.Module): - """ - A wrapper for running the network and computing the loss - This is so we can more efficiently use DataParallel. - - 损失函数模块,YOLACT只使用Multibox Loss,但单独封装NetLoss模块的目的是多卡训练 - """ - - def __init__(self, net: Yolact, criterion: MultiBoxLoss): - super().__init__() - - self.net = net - self.criterion = criterion - - def forward(self, images, targets, masks, num_crowds): - preds = self.net(images) - losses = self.criterion(self.net, preds, targets, masks, num_crowds) - return losses - - -class CustomDataParallel(nn.DataParallel): - """ - This is a custom version of DataParallel that works better with our training data. - It should also be faster than the general case. - """ - - def scatter(self, inputs, kwargs, device_ids): - # More like scatter and data prep at the same time. The point is we prep the data in such a way - # that no scatter is necessary, and there's no need to shuffle stuff around different GPUs. - devices = ['cuda:' + str(x) for x in device_ids] - splits = prepare_data(inputs[0], devices, allocation=args.batch_alloc) - - return [[split[device_idx] for split in splits] for device_idx in range(len(devices))], \ - [kwargs] * len(devices) - - def gather(self, outputs, output_device): - out = {} - - for k in outputs[0]: - out[k] = torch.stack([output[k].to(output_device) for output in outputs]) - - return out - - -class ScatterWrapper: - """ Input is any number of lists. This will preserve them through a dataparallel scatter. """ - - def __init__(self, *args): - for arg in args: - if not isinstance(arg, list): - print('Warning: ScatterWrapper got input of non-list type.') - self.args = args - self.batch_size = len(args[0]) - - def make_mask(self): - out = torch.Tensor(list(range(self.batch_size))).long() - if args.cuda: - return out.npu() - else: - return out - - def get_args(self, mask): - device = mask.device - mask = [int(x) for x in mask] - out_args = [[] for _ in self.args] - - for out, arg in zip(out_args, self.args): - for idx in mask: - x = arg[idx] - if isinstance(x, torch.Tensor): - x = x.to(device) - out.append(x) - - return out_args - - -def train(args): - # 创建模型权重文件存储目录 - if not os.path.exists(args.save_folder): - os.mkdir(args.save_folder) - - args.rank_id = int(os.environ['RANK_ID']) - args.world_size = int(os.environ['RANK_SIZE']) - args.device = torch.device(f'npu:{args.rank_id}') - torch.npu.set_device(args.device) - - args.is_master_node = args.world_size == 1 or args.rank_id == 0 - - if args.is_master_node: - print(args) - - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = '83215' - dist.init_process_group(backend='hccl', world_size=args.world_size, rank=args.rank_id) - - # 创建数据集,dataset为训练数据集 - dataset = COCODetection(image_path=cfg.dataset.train_images, - info_file=cfg.dataset.train_info, - transform=SSDAugmentation(MEANS)) - if args.world_size>1: - train_sampler = torch.utils.data.distributed.DistributedSampler(dataset) - else: - train_sampler = None - if args.validation_epoch > 0: - # 调整eval.py脚本对应参数 - setup_eval() - - # 创建数据集,val_dataset为验证数据集,5000张图像 - val_dataset = COCODetection(image_path=cfg.dataset.valid_images, - info_file=cfg.dataset.valid_info, - transform=BaseTransform(MEANS)) - - # Parallel wraps the underlying module, but when saving and loading we don't want that - yolact_net = Yolact() - net = yolact_net - net.train() - - if args.log: - log = Log(cfg.name+'_time_'+time.strftime('%Y-%m-%d-%H-%M'), args.log_folder, - overwrite=(args.resume is None), log_gpu_stats=args.log_gpu) # 构造日志类 - - # I don't use the timer during training (I use a different timing method). - # Apparently there's a race condition with multiple GPUs, so disable it just to be safe. - timer.disable_all() - - # Both of these can set args.resume to None, so do them before the check - if args.resume == 'interrupt': - args.resume = SavePath.get_interrupt(args.save_folder) - elif args.resume == 'latest': - args.resume = SavePath.get_latest(args.save_folder, cfg.name) - - if args.resume is not None and args.resume != '': - print('Resuming training, loading {}...'.format(args.resume)) - yolact_net.load_weights(args.resume) - - if args.start_iter == -1: - args.start_iter = SavePath.from_str(args.resume).iteration - else: - print('Initializing weights...') - yolact_net.init_weights(backbone_path=args.save_folder + cfg.backbone.path) - - # 损失函数,multibox loss - # threshold : 门限阈值 - # pos_threshold 即为 : 高于这个值,那么就说明预测正确足够confident,即可以认为识别正确 - # pos_threshold 即为: 低于这个值,那么就可以自信认为识别错误 - - # ohem_negpos_ratio - criterion = MultiBoxLoss(num_classes=cfg.num_classes, - pos_threshold=cfg.positive_iou_threshold, - neg_threshold=cfg.negative_iou_threshold, - negpos_ratio=cfg.ohem_negpos_ratio) - - if args.batch_alloc is not None: - args.batch_alloc = [int(x) for x in args.batch_alloc.split(',')] - if sum(args.batch_alloc) != args.batch_size: - print('Error: Batch allocation (%s) does not sum to batch size (%s).' % (args.batch_alloc, args.batch_size)) - exit(-1) - - if args.cuda: - net = net.to(args.device) - criterion = criterion.to(args.device) - # 优化器SGD,随机梯度下降法 - optimizer = optim.SGD(net.parameters(), lr=args.lr, momentum=args.momentum, weight_decay=args.decay) - net, optimizer = amp.initialize(net, optimizer, opt_level="O0", loss_scale=16) - net = nn.parallel.DistributedDataParallel(net, device_ids=[args.rank_id]) - else: - net = net.to('cpu') - net.src_device_obj = torch.device('cpu') - - # 优化器SGD,随机梯度下降法 - optimizer = optim.SGD(net.parameters(), lr=args.lr, momentum=args.momentum, weight_decay=args.decay) - - # Initialize everything - if not cfg.freeze_bn: yolact_net.freeze_bn() # Freeze bn so we don't kill our means - if args.cuda: - yolact_net(torch.zeros(1, 3, cfg.max_size, cfg.max_size).npu()) - else: - yolact_net(torch.zeros(1, 3, cfg.max_size, cfg.max_size)) - if not cfg.freeze_bn: yolact_net.freeze_bn(True) - - # loss counters - loc_loss = 0 - conf_loss = 0 - iteration = max(args.start_iter, 0) - last_time = time.time() - - epoch_size = len(dataset) // (args.batch_size * args.world_size) - num_epochs = math.ceil(cfg.max_iter / epoch_size) - - # Which learning rate adjustment step are we on? lr' = lr * gamma ^ step_index - step_index = 0 - if args.world_size>1: - data_loader = data.DataLoader(dataset, args.batch_size, - num_workers=args.num_workers, - shuffle=False, - collate_fn=detection_collate, - pin_memory=True, sampler=train_sampler) - else: - data_loader = data.DataLoader(dataset, args.batch_size, - num_workers=args.num_workers, - shuffle=True, - collate_fn=detection_collate, - pin_memory=True) - - save_path = lambda epoch, iteration: SavePath(cfg.name, epoch, iteration).get_path(root=args.save_folder) - time_avg = MovingAverage() - - global loss_types # Forms the print order - loss_avgs = {k: MovingAverage(100) for k in loss_types} - - print('Begin training! NPU :', args.rank_id, '[', time.time(), ']') - print() - # try-except so you can use ctrl+c to save early and stop training - try: - for epoch in range(num_epochs): - # Resume from start_iter - if (epoch + 1) * epoch_size < iteration: - continue - if train_sampler: - train_sampler.set_epoch(epoch) - for idx, datum in enumerate(data_loader): - # Stop if we've reached an epoch if we're resuming from start_iter - if iteration == (epoch + 1) * epoch_size: - break - - # Stop at the configured number of iterations even if mid-epoch - if iteration == cfg.max_iter / args.world_size: - break - - # Change a config setting if we've reached the specified iteration - changed = False - for change in cfg.delayed_settings: - if iteration >= change[0]: - changed = True - cfg.replace(change[1]) - - # Reset the loss averages because things might have changed - for avg in loss_avgs: - avg.reset() - - # If a config setting was changed, remove it from the list so we don't keep checking - if changed: - cfg.delayed_settings = [x for x in cfg.delayed_settings if x[0] > iteration] - - # Warm up by linearly interpolating the learning rate from some smaller value - if cfg.lr_warmup_until > 0 and iteration <= cfg.lr_warmup_until: - set_lr(optimizer, - (args.lr - cfg.lr_warmup_init) * (iteration / cfg.lr_warmup_until) + cfg.lr_warmup_init) - - # Adjust the learning rate at the given iterations, but also if we resume from past that iteration - while step_index < len(cfg.lr_steps) and iteration >= cfg.lr_steps[step_index]: - step_index += 1 - set_lr(optimizer, args.lr * (args.gamma ** step_index)) - - prep_data_device = ['npu:' + str(args.rank_id)] - datum[0] = [item[1] for item in datum[0]] - images, targets, masks, num_crowds = prepare_data(datum, prep_data_device) - - out = net(images[0]) - optimizer.zero_grad() - wrapper = ScatterWrapper(targets, masks, num_crowds) - losses = criterion(net.module, out, wrapper, wrapper.make_mask()) - - losses = {k: (v).mean() for k, v in losses.items()} # Mean here because Dataparallel - loss = sum([losses[k] for k in losses]) - - # no_inf_mean removes some components from the loss, so make sure to backward through all of it - # all_loss = sum([v.mean() for v in losses.values()]) - - # Backprop - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - if torch.isfinite(loss).item(): - optimizer.step() - print('\t finish one step! NPU :', args.rank_id, '[', time.time(), ']') - - # Add the loss to the moving average for bookkeeping - for k in losses: - loss_avgs[k].add(losses[k].item()) - - cur_time = time.time() - elapsed = cur_time - last_time - last_time = cur_time - - # Exclude graph setup from the timing information - if iteration > args.fps_start_iter: - time_avg.add(elapsed) - - if iteration % 10 == 0: - eta_str = \ - str(datetime.timedelta(seconds=(cfg.max_iter - iteration) * time_avg.get_avg())).split('.')[0] - - total = sum([loss_avgs[k].get_avg() for k in losses]) - loss_labels = sum([[k, loss_avgs[k].get_avg()] for k in loss_types if k in losses], []) - - print(('[%3d] %7d ||' + ( - ' %s: %.3f |' * len(losses)) + ' T: %.3f || ETA: %s || timer: %.3f' + ' || NPU: ' + str( - args.rank_id)) - % tuple([epoch, iteration] + loss_labels + [total, eta_str, elapsed]), flush=True) - if args.log: - precision = 5 - loss_info = {k: round(losses[k].item(), precision) for k in losses} - loss_info['T'] = round(loss.item(), precision) - - if args.log_gpu: - log.log_gpu_stats = (iteration % 10 == 0) # nvidia-smi is sloooow - - log.log('train', loss=loss_info, epoch=epoch, iter=iteration, - lr=round(cur_lr, 10), elapsed=elapsed) - - log.log_gpu_stats = args.log_gpu - - iteration += 1 - - if iteration % args.save_interval == 0 and iteration != args.start_iter: - if args.keep_latest: - latest = SavePath.get_latest(args.save_folder, cfg.name) - - print('Saving state, iter:', iteration) - if args.is_master_node: - yolact_net.save_weights(save_path(epoch, iteration)) - - if args.keep_latest and latest is not None: - if args.keep_latest_interval <= 0 or iteration % args.keep_latest_interval != args.save_interval: - print('Deleting old save...') - os.remove(latest) - - # This is done per epoch - if args.validation_epoch > 0: - if epoch % args.validation_epoch == 0 and epoch > 0: - compute_validation_map(epoch, iteration, yolact_net, val_dataset, log if args.log else None) - - log.log('FPS', fps=args.world_size * args.batch_size / time_avg.get_avg()) - print('FPS', args.world_size * args.batch_size / time_avg.get_avg()) - - # Compute validation mAP after training is finished - # compute_validation_map(epoch, iteration, yolact_net, val_dataset, log if args.log else None) - except KeyboardInterrupt: - if args.interrupt: - print('Stopping early. Saving network...') - - # Delete previous copy of the interrupted network so we don't spam the weights folder - SavePath.remove_interrupt(args.save_folder) - - if args.is_master_node: - yolact_net.save_weights(save_path(epoch, repr(iteration) + '_interrupt')) - exit() - - if args.is_master_node: - yolact_net.save_weights('./weights/yolact_plus.pth') - - -def set_lr(optimizer, new_lr): - for param_group in optimizer.param_groups: - param_group['lr'] = new_lr - - global cur_lr - cur_lr = new_lr - - -def gradinator(x): - x.requires_grad = False - return x - - -def prepare_data(datum, devices: list = None, allocation: list = None): - with torch.no_grad(): - if devices is None: - devices = ['npu:0'] if args.cuda else ['cpu'] - if allocation is None: - allocation = [args.batch_size // len(devices)] * (len(devices) - 1) - allocation.append(args.batch_size - sum(allocation)) # The rest might need more/less - - images, (targets, masks, num_crowds) = datum - - cur_idx = 0 - for device, alloc in zip(devices, allocation): - for _ in range(alloc): - images[cur_idx] = gradinator(images[cur_idx].to(device)) - targets[cur_idx] = gradinator(targets[cur_idx].to(device)) - masks[cur_idx] = gradinator(masks[cur_idx].to(device)) - cur_idx += 1 - - if cfg.preserve_aspect_ratio: - # Choose a random size from the batch - _, h, w = images[random.randint(0, len(images) - 1)].size() - - for idx, (image, target, mask, num_crowd) in enumerate(zip(images, targets, masks, num_crowds)): - images[idx], targets[idx], masks[idx], num_crowds[idx] \ - = enforce_size(image, target, mask, num_crowd, w, h) - - cur_idx = 0 - split_images, split_targets, split_masks, split_numcrowds \ - = [[None for alloc in allocation] for _ in range(4)] - - for device_idx, alloc in enumerate(allocation): - split_images[device_idx] = torch.stack(images[cur_idx:cur_idx + alloc], dim=0) - split_targets[device_idx] = targets[cur_idx:cur_idx + alloc] - split_masks[device_idx] = masks[cur_idx:cur_idx + alloc] - split_numcrowds[device_idx] = num_crowds[cur_idx:cur_idx + alloc] - - cur_idx += alloc - - return split_images, split_targets, split_masks, split_numcrowds - - -def no_inf_mean(x: torch.Tensor): - """ - Computes the mean of a vector, throwing out all inf values. - If there are no non-inf values, this will return inf (i.e., just the normal mean). - """ - - no_inf = [a for a in x if torch.isfinite(a)] - - if len(no_inf) > 0: - return sum(no_inf) / len(no_inf) - else: - return x.mean() - - -def compute_validation_loss(net, data_loader, criterion): - global loss_types - - with torch.no_grad(): - losses = {} - - # Don't switch to eval mode because we want to get losses - iterations = 0 - for datum in data_loader: - images, targets, masks, num_crowds = prepare_data(datum) - out = net(images) - - wrapper = ScatterWrapper(targets, masks, num_crowds) - _losses = criterion(out, wrapper, wrapper.make_mask()) - - for k, v in _losses.items(): - v = v.mean().item() - if k in losses: - losses[k] += v - else: - losses[k] = v - - iterations += 1 - if args.validation_size <= iterations * args.batch_size: - break - - for k in losses: - losses[k] /= iterations - - loss_labels = sum([[k, losses[k]] for k in loss_types if k in losses], []) - print(('Validation ||' + (' %s: %.3f |' * len(losses)) + ')') % tuple(loss_labels), flush=True) - - -def compute_validation_map(epoch, iteration, yolact_net, dataset, log: Log = None): - with torch.no_grad(): - yolact_net.eval() - - start = time.time() - print() - print("Computing validation mAP (this may take a while)...", flush=True) - val_info = eval_script.evaluate(yolact_net, dataset, train_mode=True, trainCuda=args.cuda) - end = time.time() - - if log is not None: - log.log('val', val_info, elapsed=(end - start), epoch=epoch, iter=iteration) - - yolact_net.train() - - -def setup_eval(): - eval_script.parse_args(['--no_bar', '--max_images=' + str(args.validation_size)]) - - -if __name__ == '__main__': - train(args) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +from data import * +from utils.augmentations import SSDAugmentation, BaseTransform +from utils.functions import MovingAverage, SavePath +from utils.logger import Log +from utils import timer +from layers.modules import MultiBoxLoss +from yolact import Yolact +import os +import sys +import time +import math, random +from pathlib import Path +import torch +from torch.autograd import Variable +import torch.nn as nn +import torch.optim as optim +import torch.backends.cudnn as cudnn +import torch.nn.init as init +import torch.utils.data as data +import numpy as np +import argparse +import datetime +from torch.nn.parallel import DistributedDataParallel as DDP +import torch.multiprocessing as mp +import torch.distributed as dist +# Oof +import eval as eval_script +from apex import amp + +def str2bool(v): + return v.lower() in ("yes", "true", "t", "1") + + +parser = argparse.ArgumentParser( + description='Yolact Training Script') +parser.add_argument('--batch_size', default=8, type=int, + help='Batch size for training') +parser.add_argument('--data_path', default=None, type=str, + help='data path') +parser.add_argument('--resume', default=None, type=str, + help='Checkpoint state_dict file to resume training from. If this is "interrupt"' \ + ', the model will resume training from the interrupt file.') +parser.add_argument('--start_iter', default=-1, type=int, + help='Resume training at this iter. If this is -1, the iteration will be' \ + 'determined from the file name.') +parser.add_argument('--fps_start_iter', default=100, type=int, + help='calculate fps at this iter. If this is -1, the iteration will be' \ + 'determined from the file name.') +parser.add_argument('--num_workers', default=0, type=int, + help='Number of workers used in dataloading') +parser.add_argument('--cuda', default=True, type=str2bool, + help='Use CUDA to train model') +parser.add_argument('--lr', '--learning_rate', default=None, type=float, + help='Initial learning rate. Leave as None to read this from the config.') +parser.add_argument('--momentum', default=None, type=float, + help='Momentum for SGD. Leave as None to read this from the config.') +parser.add_argument('--decay', '--weight_decay', default=None, type=float, + help='Weight decay for SGD. Leave as None to read this from the config.') +parser.add_argument('--gamma', default=None, type=float, + help='For each lr step, what to multiply the lr by. Leave as None to read this from the config.') +parser.add_argument('--save_folder', default='weights/', + help='Directory for saving checkpoint models.') +parser.add_argument('--log_folder', default='logs/', + help='Directory for saving logs.') +parser.add_argument('--config', default='yolact_base_config', + help='The config object to use.') +parser.add_argument('--max_iter', default=-1, type=int, + help='num of iter will train') +parser.add_argument('--save_interval', default=2000, type=int, + help='The number of iterations between saving the model.') +parser.add_argument('--validation_size', default=5000, type=int, + help='The number of images to use for validation.') +parser.add_argument('--validation_epoch', default=-1, type=int, + help='Output validation information every n iterations. If -1, do no validation.') +parser.add_argument('--keep_latest', dest='keep_latest', action='store_true', + help='Only keep the latest checkpoint instead of each one.') +parser.add_argument('--keep_latest_interval', default=100000, type=int, + help='When --keep_latest is on, don\'t delete the latest file at these intervals. This should be a multiple of save_interval or 0.') +parser.add_argument('--dataset', default=None, type=str, + help='If specified, override the dataset specified in the config with this one (example: coco2017_dataset).') +parser.add_argument('--no_log', dest='log', action='store_false', + help='Don\'t log per iteration information into log_folder.') +parser.add_argument('--log_gpu', dest='log_gpu', action='store_true', + help='Include GPU information in the logs. Nvidia-smi tends to be slow, so set this with caution.') +parser.add_argument('--no_interrupt', dest='interrupt', action='store_false', + help='Don\'t save an interrupt when KeyboardInterrupt is caught.') +parser.add_argument('--batch_alloc', default=None, type=str, + help='If using multiple GPUS, you can set this to be a comma separated list detailing which GPUs should get what local batch size (It should add up to your total batch size).') +parser.add_argument('--no_autoscale', dest='autoscale', action='store_false', + help='YOLACT will automatically scale the lr and the number of iterations depending on the batch size. Set this if you want to disable that.') +parser.add_argument('--useDDP', default=True, type=bool, help='use DistributedDataParallel or not') +parser.add_argument('--seed', default=None, type=int, help='set PyTorch seed') + +parser.set_defaults(keep_latest=False, log=True, log_gpu=False, interrupt=True, autoscale=True) +args = parser.parse_args() + +# 设置配置文件,无用 +if args.config is not None: + set_cfg(args.config) + +# 设置项目数据集,无用 +if args.dataset is not None: + set_dataset(args.dataset) + +if args.data_path: + cfg.dataset.train_images = args.data_path + '/train2017/' + cfg.dataset.train_info = args.data_path + '/annotations/instances_train2017.json' + +if args.autoscale and args.batch_size != 8: + factor = args.batch_size / 8 + if __name__ == '__main__': + print('Scaling parameters by %.2f to account for a batch size of %d.' % (factor, args.batch_size)) + + cfg.lr *= factor + cfg.max_iter //= factor + cfg.lr_steps = [x // factor for x in cfg.lr_steps] + +if args.max_iter>0: + cfg.max_iter = args.max_iter + +# Update training parameters from the config if necessary +def replace(name): + if getattr(args, name) == None: setattr(args, name, getattr(cfg, name)) + + +# 将args中参数替换为config中预设的值,便于后续调用 +replace('lr') +replace('decay') +replace('gamma') +replace('momentum') + +# This is managed by set_lr +# 两个学习率都有用,在后续自动更新学习率中,可以使用 +cur_lr = args.lr + +# 检查环境 +if torch.npu.device_count() == 0: + print('No GPUs detected. Exiting...') + exit(-1) + +# 当一块显卡中的图像个数大于等于6时,才启用batch normalization +if args.batch_size // torch.npu.device_count() < 6 and (not args.useDDP): + if __name__ == '__main__': + print('Per-NPU batch size is less than the recommended limit for batch norm. Disabling batch norm.') + cfg.freeze_bn = True + +if args.seed is not None: + seed = args.seed + os.environ['PYTHONHASHSEED'] = str(seed) + torch.manual_seed(seed) + torch.cuda.manual_seed(seed) + torch.npu.manual_seed(seed) + torch.cuda.manual_seed_all(seed) + torch.backends.cudnn.deterministic = True + print('Finish set seed, seed is :', seed) + +loss_types = ['B', 'C', 'M', 'P', 'D', 'E', 'S', 'I'] + +if torch.npu.is_available(): + print("npu environment is okay!, and current device count is", torch.npu.device_count()) + + +# if args.cuda: +# torch.set_default_tensor_type('torch.cuda.FloatTensor') +# if not args.cuda: +# print("WARNING: It looks like you have a CUDA device, but aren't " + +# "using CUDA.\nRun with --cuda for optimal training speed.") +# torch.set_default_tensor_type('torch.FloatTensor') +# else: +# torch.set_default_tensor_type('torch.FloatTensor') + +class NetLoss(nn.Module): + """ + A wrapper for running the network and computing the loss + This is so we can more efficiently use DataParallel. + + 损失函数模块,YOLACT只使用Multibox Loss,但单独封装NetLoss模块的目的是多卡训练 + """ + + def __init__(self, net: Yolact, criterion: MultiBoxLoss): + super().__init__() + + self.net = net + self.criterion = criterion + + def forward(self, images, targets, masks, num_crowds): + preds = self.net(images) + losses = self.criterion(self.net, preds, targets, masks, num_crowds) + return losses + + +class CustomDataParallel(nn.DataParallel): + """ + This is a custom version of DataParallel that works better with our training data. + It should also be faster than the general case. + """ + + def scatter(self, inputs, kwargs, device_ids): + # More like scatter and data prep at the same time. The point is we prep the data in such a way + # that no scatter is necessary, and there's no need to shuffle stuff around different GPUs. + devices = ['cuda:' + str(x) for x in device_ids] + splits = prepare_data(inputs[0], devices, allocation=args.batch_alloc) + + return [[split[device_idx] for split in splits] for device_idx in range(len(devices))], \ + [kwargs] * len(devices) + + def gather(self, outputs, output_device): + out = {} + + for k in outputs[0]: + out[k] = torch.stack([output[k].to(output_device) for output in outputs]) + + return out + + +class ScatterWrapper: + """ Input is any number of lists. This will preserve them through a dataparallel scatter. """ + + def __init__(self, *args): + for arg in args: + if not isinstance(arg, list): + print('Warning: ScatterWrapper got input of non-list type.') + self.args = args + self.batch_size = len(args[0]) + + def make_mask(self): + out = torch.Tensor(list(range(self.batch_size))).long() + if args.cuda: + return out.npu() + else: + return out + + def get_args(self, mask): + device = mask.device + mask = [int(x) for x in mask] + out_args = [[] for _ in self.args] + + for out, arg in zip(out_args, self.args): + for idx in mask: + x = arg[idx] + if isinstance(x, torch.Tensor): + x = x.to(device) + out.append(x) + + return out_args + + +def train(args): + # 创建模型权重文件存储目录 + if not os.path.exists(args.save_folder): + os.mkdir(args.save_folder) + + args.rank_id = int(os.environ['RANK_ID']) + args.world_size = int(os.environ['RANK_SIZE']) + args.device = torch.device(f'npu:{args.rank_id}') + torch.npu.set_device(args.device) + + args.is_master_node = args.world_size == 1 or args.rank_id == 0 + + if args.is_master_node: + print(args) + + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '83215' + dist.init_process_group(backend='hccl', world_size=args.world_size, rank=args.rank_id) + + # 创建数据集,dataset为训练数据集 + dataset = COCODetection(image_path=cfg.dataset.train_images, + info_file=cfg.dataset.train_info, + transform=SSDAugmentation(MEANS)) + if args.world_size>1: + train_sampler = torch.utils.data.distributed.DistributedSampler(dataset) + else: + train_sampler = None + if args.validation_epoch > 0: + # 调整eval.py脚本对应参数 + setup_eval() + + # 创建数据集,val_dataset为验证数据集,5000张图像 + val_dataset = COCODetection(image_path=cfg.dataset.valid_images, + info_file=cfg.dataset.valid_info, + transform=BaseTransform(MEANS)) + + # Parallel wraps the underlying module, but when saving and loading we don't want that + yolact_net = Yolact() + net = yolact_net + net.train() + + if args.log: + log = Log(cfg.name+'_time_'+time.strftime('%Y-%m-%d-%H-%M'), args.log_folder, + overwrite=(args.resume is None), log_gpu_stats=args.log_gpu) # 构造日志类 + + # I don't use the timer during training (I use a different timing method). + # Apparently there's a race condition with multiple GPUs, so disable it just to be safe. + timer.disable_all() + + # Both of these can set args.resume to None, so do them before the check + if args.resume == 'interrupt': + args.resume = SavePath.get_interrupt(args.save_folder) + elif args.resume == 'latest': + args.resume = SavePath.get_latest(args.save_folder, cfg.name) + + if args.resume is not None and args.resume != '': + print('Resuming training, loading {}...'.format(args.resume)) + yolact_net.load_weights(args.resume) + + if args.start_iter == -1: + args.start_iter = SavePath.from_str(args.resume).iteration + else: + print('Initializing weights...') + yolact_net.init_weights(backbone_path=args.save_folder + cfg.backbone.path) + + # 损失函数,multibox loss + # threshold : 门限阈值 + # pos_threshold 即为 : 高于这个值,那么就说明预测正确足够confident,即可以认为识别正确 + # pos_threshold 即为: 低于这个值,那么就可以自信认为识别错误 + + # ohem_negpos_ratio + criterion = MultiBoxLoss(num_classes=cfg.num_classes, + pos_threshold=cfg.positive_iou_threshold, + neg_threshold=cfg.negative_iou_threshold, + negpos_ratio=cfg.ohem_negpos_ratio) + + if args.batch_alloc is not None: + args.batch_alloc = [int(x) for x in args.batch_alloc.split(',')] + if sum(args.batch_alloc) != args.batch_size: + print('Error: Batch allocation (%s) does not sum to batch size (%s).' % (args.batch_alloc, args.batch_size)) + exit(-1) + + if args.cuda: + net = net.to(args.device) + criterion = criterion.to(args.device) + # 优化器SGD,随机梯度下降法 + optimizer = optim.SGD(net.parameters(), lr=args.lr, momentum=args.momentum, weight_decay=args.decay) + net, optimizer = amp.initialize(net, optimizer, opt_level="O0", loss_scale=16) + net = nn.parallel.DistributedDataParallel(net, device_ids=[args.rank_id]) + else: + net = net.to('cpu') + net.src_device_obj = torch.device('cpu') + + # 优化器SGD,随机梯度下降法 + optimizer = optim.SGD(net.parameters(), lr=args.lr, momentum=args.momentum, weight_decay=args.decay) + + # Initialize everything + if not cfg.freeze_bn: yolact_net.freeze_bn() # Freeze bn so we don't kill our means + if args.cuda: + yolact_net(torch.zeros(1, 3, cfg.max_size, cfg.max_size).npu()) + else: + yolact_net(torch.zeros(1, 3, cfg.max_size, cfg.max_size)) + if not cfg.freeze_bn: yolact_net.freeze_bn(True) + + # loss counters + loc_loss = 0 + conf_loss = 0 + iteration = max(args.start_iter, 0) + last_time = time.time() + + epoch_size = len(dataset) // (args.batch_size * args.world_size) + num_epochs = math.ceil(cfg.max_iter / epoch_size) + + # Which learning rate adjustment step are we on? lr' = lr * gamma ^ step_index + step_index = 0 + if args.world_size>1: + data_loader = data.DataLoader(dataset, args.batch_size, + num_workers=args.num_workers, + shuffle=False, + collate_fn=detection_collate, + pin_memory=True, sampler=train_sampler) + else: + data_loader = data.DataLoader(dataset, args.batch_size, + num_workers=args.num_workers, + shuffle=True, + collate_fn=detection_collate, + pin_memory=True) + + save_path = lambda epoch, iteration: SavePath(cfg.name, epoch, iteration).get_path(root=args.save_folder) + time_avg = MovingAverage() + + global loss_types # Forms the print order + loss_avgs = {k: MovingAverage(100) for k in loss_types} + + print('Begin training! NPU :', args.rank_id, '[', time.time(), ']') + print() + # try-except so you can use ctrl+c to save early and stop training + try: + for epoch in range(num_epochs): + # Resume from start_iter + if (epoch + 1) * epoch_size < iteration: + continue + if train_sampler: + train_sampler.set_epoch(epoch) + for idx, datum in enumerate(data_loader): + # Stop if we've reached an epoch if we're resuming from start_iter + if iteration == (epoch + 1) * epoch_size: + break + + # Stop at the configured number of iterations even if mid-epoch + if iteration == cfg.max_iter / args.world_size: + break + + # Change a config setting if we've reached the specified iteration + changed = False + for change in cfg.delayed_settings: + if iteration >= change[0]: + changed = True + cfg.replace(change[1]) + + # Reset the loss averages because things might have changed + for avg in loss_avgs: + avg.reset() + + # If a config setting was changed, remove it from the list so we don't keep checking + if changed: + cfg.delayed_settings = [x for x in cfg.delayed_settings if x[0] > iteration] + + # Warm up by linearly interpolating the learning rate from some smaller value + if cfg.lr_warmup_until > 0 and iteration <= cfg.lr_warmup_until: + set_lr(optimizer, + (args.lr - cfg.lr_warmup_init) * (iteration / cfg.lr_warmup_until) + cfg.lr_warmup_init) + + # Adjust the learning rate at the given iterations, but also if we resume from past that iteration + while step_index < len(cfg.lr_steps) and iteration >= cfg.lr_steps[step_index]: + step_index += 1 + set_lr(optimizer, args.lr * (args.gamma ** step_index)) + + prep_data_device = ['npu:' + str(args.rank_id)] + datum[0] = [item[1] for item in datum[0]] + images, targets, masks, num_crowds = prepare_data(datum, prep_data_device) + + out = net(images[0]) + optimizer.zero_grad() + wrapper = ScatterWrapper(targets, masks, num_crowds) + losses = criterion(net.module, out, wrapper, wrapper.make_mask()) + + losses = {k: (v).mean() for k, v in losses.items()} # Mean here because Dataparallel + loss = sum([losses[k] for k in losses]) + + # no_inf_mean removes some components from the loss, so make sure to backward through all of it + # all_loss = sum([v.mean() for v in losses.values()]) + + # Backprop + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + if torch.isfinite(loss).item(): + optimizer.step() + print('\t finish one step! NPU :', args.rank_id, '[', time.time(), ']') + + # Add the loss to the moving average for bookkeeping + for k in losses: + loss_avgs[k].add(losses[k].item()) + + cur_time = time.time() + elapsed = cur_time - last_time + last_time = cur_time + + # Exclude graph setup from the timing information + if iteration > args.fps_start_iter: + time_avg.add(elapsed) + + if iteration % 10 == 0: + eta_str = \ + str(datetime.timedelta(seconds=(cfg.max_iter - iteration) * time_avg.get_avg())).split('.')[0] + + total = sum([loss_avgs[k].get_avg() for k in losses]) + loss_labels = sum([[k, loss_avgs[k].get_avg()] for k in loss_types if k in losses], []) + + print(('[%3d] %7d ||' + ( + ' %s: %.3f |' * len(losses)) + ' T: %.3f || ETA: %s || timer: %.3f' + ' || NPU: ' + str( + args.rank_id)) + % tuple([epoch, iteration] + loss_labels + [total, eta_str, elapsed]), flush=True) + if args.log: + precision = 5 + loss_info = {k: round(losses[k].item(), precision) for k in losses} + loss_info['T'] = round(loss.item(), precision) + + if args.log_gpu: + log.log_gpu_stats = (iteration % 10 == 0) # nvidia-smi is sloooow + + log.log('train', loss=loss_info, epoch=epoch, iter=iteration, + lr=round(cur_lr, 10), elapsed=elapsed) + + log.log_gpu_stats = args.log_gpu + + iteration += 1 + + if iteration % args.save_interval == 0 and iteration != args.start_iter: + if args.keep_latest: + latest = SavePath.get_latest(args.save_folder, cfg.name) + + print('Saving state, iter:', iteration) + if args.is_master_node: + yolact_net.save_weights(save_path(epoch, iteration)) + + if args.keep_latest and latest is not None: + if args.keep_latest_interval <= 0 or iteration % args.keep_latest_interval != args.save_interval: + print('Deleting old save...') + os.remove(latest) + + # This is done per epoch + if args.validation_epoch > 0: + if epoch % args.validation_epoch == 0 and epoch > 0: + compute_validation_map(epoch, iteration, yolact_net, val_dataset, log if args.log else None) + + log.log('FPS', fps=args.world_size * args.batch_size / time_avg.get_avg()) + print('FPS', args.world_size * args.batch_size / time_avg.get_avg()) + + # Compute validation mAP after training is finished + # compute_validation_map(epoch, iteration, yolact_net, val_dataset, log if args.log else None) + except KeyboardInterrupt: + if args.interrupt: + print('Stopping early. Saving network...') + + # Delete previous copy of the interrupted network so we don't spam the weights folder + SavePath.remove_interrupt(args.save_folder) + + if args.is_master_node: + yolact_net.save_weights(save_path(epoch, repr(iteration) + '_interrupt')) + exit() + + if args.is_master_node: + yolact_net.save_weights('./weights/yolact_plus.pth') + + +def set_lr(optimizer, new_lr): + for param_group in optimizer.param_groups: + param_group['lr'] = new_lr + + global cur_lr + cur_lr = new_lr + + +def gradinator(x): + x.requires_grad = False + return x + + +def prepare_data(datum, devices: list = None, allocation: list = None): + with torch.no_grad(): + if devices is None: + devices = ['npu:0'] if args.cuda else ['cpu'] + if allocation is None: + allocation = [args.batch_size // len(devices)] * (len(devices) - 1) + allocation.append(args.batch_size - sum(allocation)) # The rest might need more/less + + images, (targets, masks, num_crowds) = datum + + cur_idx = 0 + for device, alloc in zip(devices, allocation): + for _ in range(alloc): + images[cur_idx] = gradinator(images[cur_idx].to(device)) + targets[cur_idx] = gradinator(targets[cur_idx].to(device)) + masks[cur_idx] = gradinator(masks[cur_idx].to(device)) + cur_idx += 1 + + if cfg.preserve_aspect_ratio: + # Choose a random size from the batch + _, h, w = images[random.randint(0, len(images) - 1)].size() + + for idx, (image, target, mask, num_crowd) in enumerate(zip(images, targets, masks, num_crowds)): + images[idx], targets[idx], masks[idx], num_crowds[idx] \ + = enforce_size(image, target, mask, num_crowd, w, h) + + cur_idx = 0 + split_images, split_targets, split_masks, split_numcrowds \ + = [[None for alloc in allocation] for _ in range(4)] + + for device_idx, alloc in enumerate(allocation): + split_images[device_idx] = torch.stack(images[cur_idx:cur_idx + alloc], dim=0) + split_targets[device_idx] = targets[cur_idx:cur_idx + alloc] + split_masks[device_idx] = masks[cur_idx:cur_idx + alloc] + split_numcrowds[device_idx] = num_crowds[cur_idx:cur_idx + alloc] + + cur_idx += alloc + + return split_images, split_targets, split_masks, split_numcrowds + + +def no_inf_mean(x: torch.Tensor): + """ + Computes the mean of a vector, throwing out all inf values. + If there are no non-inf values, this will return inf (i.e., just the normal mean). + """ + + no_inf = [a for a in x if torch.isfinite(a)] + + if len(no_inf) > 0: + return sum(no_inf) / len(no_inf) + else: + return x.mean() + + +def compute_validation_loss(net, data_loader, criterion): + global loss_types + + with torch.no_grad(): + losses = {} + + # Don't switch to eval mode because we want to get losses + iterations = 0 + for datum in data_loader: + images, targets, masks, num_crowds = prepare_data(datum) + out = net(images) + + wrapper = ScatterWrapper(targets, masks, num_crowds) + _losses = criterion(out, wrapper, wrapper.make_mask()) + + for k, v in _losses.items(): + v = v.mean().item() + if k in losses: + losses[k] += v + else: + losses[k] = v + + iterations += 1 + if args.validation_size <= iterations * args.batch_size: + break + + for k in losses: + losses[k] /= iterations + + loss_labels = sum([[k, losses[k]] for k in loss_types if k in losses], []) + print(('Validation ||' + (' %s: %.3f |' * len(losses)) + ')') % tuple(loss_labels), flush=True) + + +def compute_validation_map(epoch, iteration, yolact_net, dataset, log: Log = None): + with torch.no_grad(): + yolact_net.eval() + + start = time.time() + print() + print("Computing validation mAP (this may take a while)...", flush=True) + val_info = eval_script.evaluate(yolact_net, dataset, train_mode=True, trainCuda=args.cuda) + end = time.time() + + if log is not None: + log.log('val', val_info, elapsed=(end - start), epoch=epoch, iter=iteration) + + yolact_net.train() + + +def setup_eval(): + eval_script.parse_args(['--no_bar', '--max_images=' + str(args.validation_size)]) + + +if __name__ == '__main__': + train(args) diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/utils/augmentations.py b/PyTorch/contrib/cv/detection/YOLACT_plus/utils/augmentations.py index 5f32d182af0fae1b331e98d649c7b5bd05226e83..f18fd70932c38750b1f29247ea7f7aa8300be91b 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/utils/augmentations.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/utils/augmentations.py @@ -1,702 +1,702 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch -from torchvision import transforms -import cv2 -import numpy as np -import types -from numpy import random -from math import sqrt - -from data import cfg, MEANS, STD - - -def intersect(box_a, box_b): - max_xy = np.minimum(box_a[:, 2:], box_b[2:]) - min_xy = np.maximum(box_a[:, :2], box_b[:2]) - inter = np.clip((max_xy - min_xy), a_min=0, a_max=np.inf) - return inter[:, 0] * inter[:, 1] - - -def jaccard_numpy(box_a, box_b): - """Compute the jaccard overlap of two sets of boxes. The jaccard overlap - is simply the intersection over union of two boxes. - E.g.: - A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) - Args: - box_a: Multiple bounding boxes, Shape: [num_boxes,4] - box_b: Single bounding box, Shape: [4] - Return: - jaccard overlap: Shape: [box_a.shape[0], box_a.shape[1]] - """ - inter = intersect(box_a, box_b) - area_a = ((box_a[:, 2]-box_a[:, 0]) * - (box_a[:, 3]-box_a[:, 1])) # [A,B] - area_b = ((box_b[2]-box_b[0]) * - (box_b[3]-box_b[1])) # [A,B] - union = area_a + area_b - inter - return inter / union # [A,B] - - -class Compose(object): - """Composes several augmentations together. - Args: - transforms (List[Transform]): list of transforms to compose. - Example: - >>> augmentations.Compose([ - >>> transforms.CenterCrop(10), - >>> transforms.ToTensor(), - >>> ]) - """ - - def __init__(self, transforms): - self.transforms = transforms - - def __call__(self, img, masks=None, boxes=None, labels=None): - for t in self.transforms: - img, masks, boxes, labels = t(img, masks, boxes, labels) - return img, masks, boxes, labels - - -class Lambda(object): - """Applies a lambda as a transform.""" - - def __init__(self, lambd): - assert isinstance(lambd, types.LambdaType) - self.lambd = lambd - - def __call__(self, img, masks=None, boxes=None, labels=None): - return self.lambd(img, masks, boxes, labels) - - -class ConvertFromInts(object): - def __call__(self, image, masks=None, boxes=None, labels=None): - return image.astype(np.float32), masks, boxes, labels - - - -class ToAbsoluteCoords(object): - def __call__(self, image, masks=None, boxes=None, labels=None): - height, width, channels = image.shape - boxes[:, 0] *= width - boxes[:, 2] *= width - boxes[:, 1] *= height - boxes[:, 3] *= height - - return image, masks, boxes, labels - - -class ToPercentCoords(object): - def __call__(self, image, masks=None, boxes=None, labels=None): - height, width, channels = image.shape - boxes[:, 0] /= width - boxes[:, 2] /= width - boxes[:, 1] /= height - boxes[:, 3] /= height - - return image, masks, boxes, labels - - -class Pad(object): - """ - Pads the image to the input width and height, filling the - background with mean and putting the image in the top-left. - - Note: this expects im_w <= width and im_h <= height - """ - def __init__(self, width, height, mean=MEANS, pad_gt=True): - self.mean = mean - self.width = width - self.height = height - self.pad_gt = pad_gt - - def __call__(self, image, masks, boxes=None, labels=None): - im_h, im_w, depth = image.shape - - expand_image = np.zeros( - (self.height, self.width, depth), - dtype=image.dtype) - expand_image[:, :, :] = self.mean - expand_image[:im_h, :im_w] = image - - if self.pad_gt: - expand_masks = np.zeros( - (masks.shape[0], self.height, self.width), - dtype=masks.dtype) - expand_masks[:,:im_h,:im_w] = masks - masks = expand_masks - - return expand_image, masks, boxes, labels - -class Resize(object): - """ If preserve_aspect_ratio is true, this resizes to an approximate area of max_size * max_size """ - - @staticmethod - def calc_size_preserve_ar(img_w, img_h, max_size): - """ I mathed this one out on the piece of paper. Resulting width*height = approx max_size^2 """ - ratio = sqrt(img_w / img_h) - w = max_size * ratio - h = max_size / ratio - return int(w), int(h) - - def __init__(self, resize_gt=True): - self.resize_gt = resize_gt - self.max_size = cfg.max_size - self.preserve_aspect_ratio = cfg.preserve_aspect_ratio - - def __call__(self, image, masks, boxes, labels=None): - img_h, img_w, _ = image.shape - - if self.preserve_aspect_ratio: - width, height = Resize.calc_size_preserve_ar(img_w, img_h, self.max_size) - else: - width, height = self.max_size, self.max_size - - image = cv2.resize(image, (width, height)) - - if self.resize_gt: - # Act like each object is a color channel - masks = masks.transpose((1, 2, 0)) - masks = cv2.resize(masks, (width, height)) - - # OpenCV resizes a (w,h,1) array to (s,s), so fix that - if len(masks.shape) == 2: - masks = np.expand_dims(masks, 0) - else: - masks = masks.transpose((2, 0, 1)) - - # Scale bounding boxes (which are currently absolute coordinates) - boxes[:, [0, 2]] *= (width / img_w) - boxes[:, [1, 3]] *= (height / img_h) - - # Discard boxes that are smaller than we'd like - w = boxes[:, 2] - boxes[:, 0] - h = boxes[:, 3] - boxes[:, 1] - - keep = (w > cfg.discard_box_width) * (h > cfg.discard_box_height) - masks = masks[keep] - boxes = boxes[keep] - labels['labels'] = labels['labels'][keep] - labels['num_crowds'] = (labels['labels'] < 0).sum() - - return image, masks, boxes, labels - - -class RandomSaturation(object): - def __init__(self, lower=0.5, upper=1.5): - self.lower = lower - self.upper = upper - assert self.upper >= self.lower, "contrast upper must be >= lower." - assert self.lower >= 0, "contrast lower must be non-negative." - - def __call__(self, image, masks=None, boxes=None, labels=None): - if random.randint(2): - image[:, :, 1] *= random.uniform(self.lower, self.upper) - - return image, masks, boxes, labels - - -class RandomHue(object): - def __init__(self, delta=18.0): - assert delta >= 0.0 and delta <= 360.0 - self.delta = delta - - def __call__(self, image, masks=None, boxes=None, labels=None): - if random.randint(2): - image[:, :, 0] += random.uniform(-self.delta, self.delta) - image[:, :, 0][image[:, :, 0] > 360.0] -= 360.0 - image[:, :, 0][image[:, :, 0] < 0.0] += 360.0 - return image, masks, boxes, labels - - -class RandomLightingNoise(object): - def __init__(self): - self.perms = ((0, 1, 2), (0, 2, 1), - (1, 0, 2), (1, 2, 0), - (2, 0, 1), (2, 1, 0)) - - def __call__(self, image, masks=None, boxes=None, labels=None): - # Don't shuffle the channels please, why would you do this - - # if random.randint(2): - # swap = self.perms[random.randint(len(self.perms))] - # shuffle = SwapChannels(swap) # shuffle channels - # image = shuffle(image) - return image, masks, boxes, labels - - -class ConvertColor(object): - def __init__(self, current='BGR', transform='HSV'): - self.transform = transform - self.current = current - - def __call__(self, image, masks=None, boxes=None, labels=None): - if self.current == 'BGR' and self.transform == 'HSV': - image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) - elif self.current == 'HSV' and self.transform == 'BGR': - image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR) - else: - raise NotImplementedError - return image, masks, boxes, labels - - -class RandomContrast(object): - def __init__(self, lower=0.5, upper=1.5): - self.lower = lower - self.upper = upper - assert self.upper >= self.lower, "contrast upper must be >= lower." - assert self.lower >= 0, "contrast lower must be non-negative." - - # expects float image - def __call__(self, image, masks=None, boxes=None, labels=None): - if random.randint(2): - alpha = random.uniform(self.lower, self.upper) - image *= alpha - return image, masks, boxes, labels - - -class RandomBrightness(object): - def __init__(self, delta=32): - assert delta >= 0.0 - assert delta <= 255.0 - self.delta = delta - - def __call__(self, image, masks=None, boxes=None, labels=None): - if random.randint(2): - delta = random.uniform(-self.delta, self.delta) - image += delta - return image, masks, boxes, labels - - -class ToCV2Image(object): - def __call__(self, tensor, masks=None, boxes=None, labels=None): - return tensor.cpu().numpy().astype(np.float32).transpose((1, 2, 0)), masks, boxes, labels - - -class ToTensor(object): - def __call__(self, cvimage, masks=None, boxes=None, labels=None): - return torch.from_numpy(cvimage.astype(np.float32)).permute(2, 0, 1), masks, boxes, labels - - -class RandomSampleCrop(object): - """Crop - Arguments: - img (Image): the image being input during training - boxes (Tensor): the original bounding boxes in pt form - labels (Tensor): the class labels for each bbox - mode (float tuple): the min and max jaccard overlaps - Return: - (img, boxes, classes) - img (Image): the cropped image - boxes (Tensor): the adjusted bounding boxes in pt form - labels (Tensor): the class labels for each bbox - """ - def __init__(self): - self.sample_options = ( - # using entire original input image - None, - # sample a patch s.t. MIN jaccard w/ obj in .1,.3,.4,.7,.9 - (0.1, None), - (0.3, None), - (0.7, None), - (0.9, None), - # randomly sample a patch - (None, None), - ) - - def __call__(self, image, masks, boxes=None, labels=None): - height, width, _ = image.shape - while True: - # randomly choose a mode - mode = random.choice(self.sample_options) - if mode is None: - return image, masks, boxes, labels - - min_iou, max_iou = mode - if min_iou is None: - min_iou = float('-inf') - if max_iou is None: - max_iou = float('inf') - - # max trails (50) - for _ in range(50): - current_image = image - - w = random.uniform(0.3 * width, width) - h = random.uniform(0.3 * height, height) - - # aspect ratio constraint b/t .5 & 2 - if h / w < 0.5 or h / w > 2: - continue - - left = random.uniform(width - w) - top = random.uniform(height - h) - - # convert to integer rect x1,y1,x2,y2 - rect = np.array([int(left), int(top), int(left+w), int(top+h)]) - - # calculate IoU (jaccard overlap) b/t the cropped and gt boxes - overlap = jaccard_numpy(boxes, rect) - - # This piece of code is bugged and does nothing: - # https://github.com/amdegroot/ssd.pytorch/issues/68 - # - # However, when I fixed it with overlap.max() < min_iou, - # it cut the mAP in half (after 8k iterations). So it stays. - # - # is min and max overlap constraint satisfied? if not try again - if overlap.min() < min_iou and max_iou < overlap.max(): - continue - - # cut the crop from the image - current_image = current_image[rect[1]:rect[3], rect[0]:rect[2], - :] - - # keep overlap with gt box IF center in sampled patch - centers = (boxes[:, :2] + boxes[:, 2:]) / 2.0 - - # mask in all gt boxes that above and to the left of centers - m1 = (rect[0] < centers[:, 0]) * (rect[1] < centers[:, 1]) - - # mask in all gt boxes that under and to the right of centers - m2 = (rect[2] > centers[:, 0]) * (rect[3] > centers[:, 1]) - - # mask in that both m1 and m2 are true - mask = m1 * m2 - - # [0 ... 0 for num_gt and then 1 ... 1 for num_crowds] - num_crowds = labels['num_crowds'] - crowd_mask = np.zeros(mask.shape, dtype=np.int32) - - if num_crowds > 0: - crowd_mask[-num_crowds:] = 1 - - # have any valid boxes? try again if not - # Also make sure you have at least one regular gt - if not mask.any() or np.sum(1-crowd_mask[mask]) == 0: - continue - - # take only the matching gt masks - current_masks = masks[mask, :, :].copy() - - # take only matching gt boxes - current_boxes = boxes[mask, :].copy() - - # take only matching gt labels - labels['labels'] = labels['labels'][mask] - current_labels = labels - - # We now might have fewer crowd annotations - if num_crowds > 0: - labels['num_crowds'] = np.sum(crowd_mask[mask]) - - # should we use the box left and top corner or the crop's - current_boxes[:, :2] = np.maximum(current_boxes[:, :2], - rect[:2]) - # adjust to crop (by substracting crop's left,top) - current_boxes[:, :2] -= rect[:2] - - current_boxes[:, 2:] = np.minimum(current_boxes[:, 2:], - rect[2:]) - # adjust to crop (by substracting crop's left,top) - current_boxes[:, 2:] -= rect[:2] - - # crop the current masks to the same dimensions as the image - current_masks = current_masks[:, rect[1]:rect[3], rect[0]:rect[2]] - - return current_image, current_masks, current_boxes, current_labels - - -class Expand(object): - def __init__(self, mean): - self.mean = mean - - def __call__(self, image, masks, boxes, labels): - if random.randint(2): - return image, masks, boxes, labels - - height, width, depth = image.shape - ratio = random.uniform(1, 4) - left = random.uniform(0, width*ratio - width) - top = random.uniform(0, height*ratio - height) - - expand_image = np.zeros( - (int(height*ratio), int(width*ratio), depth), - dtype=image.dtype) - expand_image[:, :, :] = self.mean - expand_image[int(top):int(top + height), - int(left):int(left + width)] = image - image = expand_image - - expand_masks = np.zeros( - (masks.shape[0], int(height*ratio), int(width*ratio)), - dtype=masks.dtype) - expand_masks[:,int(top):int(top + height), - int(left):int(left + width)] = masks - masks = expand_masks - - boxes = boxes.copy() - boxes[:, :2] += (int(left), int(top)) - boxes[:, 2:] += (int(left), int(top)) - - return image, masks, boxes, labels - - -class RandomMirror(object): - def __call__(self, image, masks, boxes, labels): - _, width, _ = image.shape - if random.randint(2): - image = image[:, ::-1] - masks = masks[:, :, ::-1] - boxes = boxes.copy() - boxes[:, 0::2] = width - boxes[:, 2::-2] - return image, masks, boxes, labels - - -class RandomFlip(object): - def __call__(self, image, masks, boxes, labels): - height , _ , _ = image.shape - if random.randint(2): - image = image[::-1, :] - masks = masks[:, ::-1, :] - boxes = boxes.copy() - boxes[:, 1::2] = height - boxes[:, 3::-2] - return image, masks, boxes, labels - - -class RandomRot90(object): - def __call__(self, image, masks, boxes, labels): - old_height , old_width , _ = image.shape - k = random.randint(4) - image = np.rot90(image,k) - masks = np.array([np.rot90(mask,k) for mask in masks]) - boxes = boxes.copy() - for _ in range(k): - boxes = np.array([[box[1], old_width - 1 - box[2], box[3], old_width - 1 - box[0]] for box in boxes]) - old_width, old_height = old_height, old_width - return image, masks, boxes, labels - - -class SwapChannels(object): - """Transforms a tensorized image by swapping the channels in the order - specified in the swap tuple. - Args: - swaps (int triple): final order of channels - eg: (2, 1, 0) - """ - - def __init__(self, swaps): - self.swaps = swaps - - def __call__(self, image): - """ - Args: - image (Tensor): image tensor to be transformed - Return: - a tensor with channels swapped according to swap - """ - # if torch.is_tensor(image): - # image = image.data.cpu().numpy() - # else: - # image = np.array(image) - image = image[:, :, self.swaps] - return image - - -class PhotometricDistort(object): - def __init__(self): - self.pd = [ - RandomContrast(), - ConvertColor(transform='HSV'), - RandomSaturation(), - RandomHue(), - ConvertColor(current='HSV', transform='BGR'), - RandomContrast() - ] - self.rand_brightness = RandomBrightness() - self.rand_light_noise = RandomLightingNoise() - - def __call__(self, image, masks, boxes, labels): - im = image.copy() - im, masks, boxes, labels = self.rand_brightness(im, masks, boxes, labels) - if random.randint(2): - distort = Compose(self.pd[:-1]) - else: - distort = Compose(self.pd[1:]) - im, masks, boxes, labels = distort(im, masks, boxes, labels) - return self.rand_light_noise(im, masks, boxes, labels) - -class PrepareMasks(object): - """ - Prepares the gt masks for use_gt_bboxes by cropping with the gt box - and downsampling the resulting mask to mask_size, mask_size. This - function doesn't do anything if cfg.use_gt_bboxes is False. - """ - - def __init__(self, mask_size, use_gt_bboxes): - self.mask_size = mask_size - self.use_gt_bboxes = use_gt_bboxes - - def __call__(self, image, masks, boxes, labels=None): - if not self.use_gt_bboxes: - return image, masks, boxes, labels - - height, width, _ = image.shape - - new_masks = np.zeros((masks.shape[0], self.mask_size ** 2)) - - for i in range(len(masks)): - x1, y1, x2, y2 = boxes[i, :] - x1 *= width - x2 *= width - y1 *= height - y2 *= height - x1, y1, x2, y2 = (int(x1), int(y1), int(x2), int(y2)) - - # +1 So that if y1=10.6 and y2=10.9 we still have a bounding box - cropped_mask = masks[i, y1:(y2+1), x1:(x2+1)] - scaled_mask = cv2.resize(cropped_mask, (self.mask_size, self.mask_size)) - - new_masks[i, :] = scaled_mask.reshape(1, -1) - - # Binarize - new_masks[new_masks > 0.5] = 1 - new_masks[new_masks <= 0.5] = 0 - - return image, new_masks, boxes, labels - -class BackboneTransform(object): - """ - Transforms a BRG image made of floats in the range [0, 255] to whatever - input the current backbone network needs. - - transform is a transform config object (see config.py). - in_channel_order is probably 'BGR' but you do you, kid. - """ - def __init__(self, transform, mean, std, in_channel_order): - self.mean = np.array(mean, dtype=np.float32) - self.std = np.array(std, dtype=np.float32) - self.transform = transform - - # Here I use "Algorithms and Coding" to convert string permutations to numbers - self.channel_map = {c: idx for idx, c in enumerate(in_channel_order)} - self.channel_permutation = [self.channel_map[c] for c in transform.channel_order] - - def __call__(self, img, masks=None, boxes=None, labels=None): - - img = img.astype(np.float32) - - if self.transform.normalize: - img = (img - self.mean) / self.std - elif self.transform.subtract_means: - img = (img - self.mean) - elif self.transform.to_float: - img = img / 255 - - img = img[:, :, self.channel_permutation] - - return img.astype(np.float32), masks, boxes, labels - - - - -class BaseTransform(object): - """ Transorm to be used when evaluating. """ - - def __init__(self, mean=MEANS, std=STD): - self.augment = Compose([ - ConvertFromInts(), - Resize(resize_gt=False), - BackboneTransform(cfg.backbone.transform, mean, std, 'BGR') - ]) - - def __call__(self, img, masks=None, boxes=None, labels=None): - return self.augment(img, masks, boxes, labels) - -import torch.nn.functional as F - -class FastBaseTransform(torch.nn.Module): - """ - Transform that does all operations on the GPU for super speed. - This doesn't suppport a lot of config settings and should only be used for production. - Maintain this as necessary. - """ - - def __init__(self): - super().__init__() - - self.mean = torch.Tensor(MEANS).float().cuda()[None, :, None, None] - self.std = torch.Tensor( STD ).float().cuda()[None, :, None, None] - self.transform = cfg.backbone.transform - - def forward(self, img): - self.mean = self.mean.to(img.device) - self.std = self.std.to(img.device) - - # img assumed to be a pytorch BGR image with channel order [n, h, w, c] - if cfg.preserve_aspect_ratio: - _, h, w, _ = img.size() - img_size = Resize.calc_size_preserve_ar(w, h, cfg.max_size) - img_size = (img_size[1], img_size[0]) # Pytorch needs h, w - else: - img_size = (cfg.max_size, cfg.max_size) - - img = img.permute(0, 3, 1, 2).contiguous() - img = F.interpolate(img, img_size, mode='bilinear', align_corners=False) - - if self.transform.normalize: - img = (img - self.mean) / self.std - elif self.transform.subtract_means: - img = (img - self.mean) - elif self.transform.to_float: - img = img / 255 - - if self.transform.channel_order != 'RGB': - raise NotImplementedError - - img = img[:, (2, 1, 0), :, :].contiguous() - - # Return value is in channel order [n, c, h, w] and RGB - return img - -def do_nothing(img=None, masks=None, boxes=None, labels=None): - return img, masks, boxes, labels - - -def enable_if(condition, obj): - return obj if condition else do_nothing - -class SSDAugmentation(object): - """ Transform to be used when training. """ - - def __init__(self, mean=MEANS, std=STD): - self.augment = Compose([ - ConvertFromInts(), - ToAbsoluteCoords(), - enable_if(cfg.augment_photometric_distort, PhotometricDistort()), - enable_if(cfg.augment_expand, Expand(mean)), - enable_if(cfg.augment_random_sample_crop, RandomSampleCrop()), - enable_if(cfg.augment_random_mirror, RandomMirror()), - enable_if(cfg.augment_random_flip, RandomFlip()), - enable_if(cfg.augment_random_flip, RandomRot90()), - Resize(), - enable_if(not cfg.preserve_aspect_ratio, Pad(cfg.max_size, cfg.max_size, mean)), - ToPercentCoords(), - PrepareMasks(cfg.mask_size, cfg.use_gt_bboxes), - BackboneTransform(cfg.backbone.transform, mean, std, 'BGR') - ]) - - def __call__(self, img, masks, boxes, labels): - return self.augment(img, masks, boxes, labels) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch +from torchvision import transforms +import cv2 +import numpy as np +import types +from numpy import random +from math import sqrt + +from data import cfg, MEANS, STD + + +def intersect(box_a, box_b): + max_xy = np.minimum(box_a[:, 2:], box_b[2:]) + min_xy = np.maximum(box_a[:, :2], box_b[:2]) + inter = np.clip((max_xy - min_xy), a_min=0, a_max=np.inf) + return inter[:, 0] * inter[:, 1] + + +def jaccard_numpy(box_a, box_b): + """Compute the jaccard overlap of two sets of boxes. The jaccard overlap + is simply the intersection over union of two boxes. + E.g.: + A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B) + Args: + box_a: Multiple bounding boxes, Shape: [num_boxes,4] + box_b: Single bounding box, Shape: [4] + Return: + jaccard overlap: Shape: [box_a.shape[0], box_a.shape[1]] + """ + inter = intersect(box_a, box_b) + area_a = ((box_a[:, 2]-box_a[:, 0]) * + (box_a[:, 3]-box_a[:, 1])) # [A,B] + area_b = ((box_b[2]-box_b[0]) * + (box_b[3]-box_b[1])) # [A,B] + union = area_a + area_b - inter + return inter / union # [A,B] + + +class Compose(object): + """Composes several augmentations together. + Args: + transforms (List[Transform]): list of transforms to compose. + Example: + >>> augmentations.Compose([ + >>> transforms.CenterCrop(10), + >>> transforms.ToTensor(), + >>> ]) + """ + + def __init__(self, transforms): + self.transforms = transforms + + def __call__(self, img, masks=None, boxes=None, labels=None): + for t in self.transforms: + img, masks, boxes, labels = t(img, masks, boxes, labels) + return img, masks, boxes, labels + + +class Lambda(object): + """Applies a lambda as a transform.""" + + def __init__(self, lambd): + assert isinstance(lambd, types.LambdaType) + self.lambd = lambd + + def __call__(self, img, masks=None, boxes=None, labels=None): + return self.lambd(img, masks, boxes, labels) + + +class ConvertFromInts(object): + def __call__(self, image, masks=None, boxes=None, labels=None): + return image.astype(np.float32), masks, boxes, labels + + + +class ToAbsoluteCoords(object): + def __call__(self, image, masks=None, boxes=None, labels=None): + height, width, channels = image.shape + boxes[:, 0] *= width + boxes[:, 2] *= width + boxes[:, 1] *= height + boxes[:, 3] *= height + + return image, masks, boxes, labels + + +class ToPercentCoords(object): + def __call__(self, image, masks=None, boxes=None, labels=None): + height, width, channels = image.shape + boxes[:, 0] /= width + boxes[:, 2] /= width + boxes[:, 1] /= height + boxes[:, 3] /= height + + return image, masks, boxes, labels + + +class Pad(object): + """ + Pads the image to the input width and height, filling the + background with mean and putting the image in the top-left. + + Note: this expects im_w <= width and im_h <= height + """ + def __init__(self, width, height, mean=MEANS, pad_gt=True): + self.mean = mean + self.width = width + self.height = height + self.pad_gt = pad_gt + + def __call__(self, image, masks, boxes=None, labels=None): + im_h, im_w, depth = image.shape + + expand_image = np.zeros( + (self.height, self.width, depth), + dtype=image.dtype) + expand_image[:, :, :] = self.mean + expand_image[:im_h, :im_w] = image + + if self.pad_gt: + expand_masks = np.zeros( + (masks.shape[0], self.height, self.width), + dtype=masks.dtype) + expand_masks[:,:im_h,:im_w] = masks + masks = expand_masks + + return expand_image, masks, boxes, labels + +class Resize(object): + """ If preserve_aspect_ratio is true, this resizes to an approximate area of max_size * max_size """ + + @staticmethod + def calc_size_preserve_ar(img_w, img_h, max_size): + """ I mathed this one out on the piece of paper. Resulting width*height = approx max_size^2 """ + ratio = sqrt(img_w / img_h) + w = max_size * ratio + h = max_size / ratio + return int(w), int(h) + + def __init__(self, resize_gt=True): + self.resize_gt = resize_gt + self.max_size = cfg.max_size + self.preserve_aspect_ratio = cfg.preserve_aspect_ratio + + def __call__(self, image, masks, boxes, labels=None): + img_h, img_w, _ = image.shape + + if self.preserve_aspect_ratio: + width, height = Resize.calc_size_preserve_ar(img_w, img_h, self.max_size) + else: + width, height = self.max_size, self.max_size + + image = cv2.resize(image, (width, height)) + + if self.resize_gt: + # Act like each object is a color channel + masks = masks.transpose((1, 2, 0)) + masks = cv2.resize(masks, (width, height)) + + # OpenCV resizes a (w,h,1) array to (s,s), so fix that + if len(masks.shape) == 2: + masks = np.expand_dims(masks, 0) + else: + masks = masks.transpose((2, 0, 1)) + + # Scale bounding boxes (which are currently absolute coordinates) + boxes[:, [0, 2]] *= (width / img_w) + boxes[:, [1, 3]] *= (height / img_h) + + # Discard boxes that are smaller than we'd like + w = boxes[:, 2] - boxes[:, 0] + h = boxes[:, 3] - boxes[:, 1] + + keep = (w > cfg.discard_box_width) * (h > cfg.discard_box_height) + masks = masks[keep] + boxes = boxes[keep] + labels['labels'] = labels['labels'][keep] + labels['num_crowds'] = (labels['labels'] < 0).sum() + + return image, masks, boxes, labels + + +class RandomSaturation(object): + def __init__(self, lower=0.5, upper=1.5): + self.lower = lower + self.upper = upper + assert self.upper >= self.lower, "contrast upper must be >= lower." + assert self.lower >= 0, "contrast lower must be non-negative." + + def __call__(self, image, masks=None, boxes=None, labels=None): + if random.randint(2): + image[:, :, 1] *= random.uniform(self.lower, self.upper) + + return image, masks, boxes, labels + + +class RandomHue(object): + def __init__(self, delta=18.0): + assert delta >= 0.0 and delta <= 360.0 + self.delta = delta + + def __call__(self, image, masks=None, boxes=None, labels=None): + if random.randint(2): + image[:, :, 0] += random.uniform(-self.delta, self.delta) + image[:, :, 0][image[:, :, 0] > 360.0] -= 360.0 + image[:, :, 0][image[:, :, 0] < 0.0] += 360.0 + return image, masks, boxes, labels + + +class RandomLightingNoise(object): + def __init__(self): + self.perms = ((0, 1, 2), (0, 2, 1), + (1, 0, 2), (1, 2, 0), + (2, 0, 1), (2, 1, 0)) + + def __call__(self, image, masks=None, boxes=None, labels=None): + # Don't shuffle the channels please, why would you do this + + # if random.randint(2): + # swap = self.perms[random.randint(len(self.perms))] + # shuffle = SwapChannels(swap) # shuffle channels + # image = shuffle(image) + return image, masks, boxes, labels + + +class ConvertColor(object): + def __init__(self, current='BGR', transform='HSV'): + self.transform = transform + self.current = current + + def __call__(self, image, masks=None, boxes=None, labels=None): + if self.current == 'BGR' and self.transform == 'HSV': + image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) + elif self.current == 'HSV' and self.transform == 'BGR': + image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR) + else: + raise NotImplementedError + return image, masks, boxes, labels + + +class RandomContrast(object): + def __init__(self, lower=0.5, upper=1.5): + self.lower = lower + self.upper = upper + assert self.upper >= self.lower, "contrast upper must be >= lower." + assert self.lower >= 0, "contrast lower must be non-negative." + + # expects float image + def __call__(self, image, masks=None, boxes=None, labels=None): + if random.randint(2): + alpha = random.uniform(self.lower, self.upper) + image *= alpha + return image, masks, boxes, labels + + +class RandomBrightness(object): + def __init__(self, delta=32): + assert delta >= 0.0 + assert delta <= 255.0 + self.delta = delta + + def __call__(self, image, masks=None, boxes=None, labels=None): + if random.randint(2): + delta = random.uniform(-self.delta, self.delta) + image += delta + return image, masks, boxes, labels + + +class ToCV2Image(object): + def __call__(self, tensor, masks=None, boxes=None, labels=None): + return tensor.cpu().numpy().astype(np.float32).transpose((1, 2, 0)), masks, boxes, labels + + +class ToTensor(object): + def __call__(self, cvimage, masks=None, boxes=None, labels=None): + return torch.from_numpy(cvimage.astype(np.float32)).permute(2, 0, 1), masks, boxes, labels + + +class RandomSampleCrop(object): + """Crop + Arguments: + img (Image): the image being input during training + boxes (Tensor): the original bounding boxes in pt form + labels (Tensor): the class labels for each bbox + mode (float tuple): the min and max jaccard overlaps + Return: + (img, boxes, classes) + img (Image): the cropped image + boxes (Tensor): the adjusted bounding boxes in pt form + labels (Tensor): the class labels for each bbox + """ + def __init__(self): + self.sample_options = ( + # using entire original input image + None, + # sample a patch s.t. MIN jaccard w/ obj in .1,.3,.4,.7,.9 + (0.1, None), + (0.3, None), + (0.7, None), + (0.9, None), + # randomly sample a patch + (None, None), + ) + + def __call__(self, image, masks, boxes=None, labels=None): + height, width, _ = image.shape + while True: + # randomly choose a mode + mode = random.choice(self.sample_options) + if mode is None: + return image, masks, boxes, labels + + min_iou, max_iou = mode + if min_iou is None: + min_iou = float('-inf') + if max_iou is None: + max_iou = float('inf') + + # max trails (50) + for _ in range(50): + current_image = image + + w = random.uniform(0.3 * width, width) + h = random.uniform(0.3 * height, height) + + # aspect ratio constraint b/t .5 & 2 + if h / w < 0.5 or h / w > 2: + continue + + left = random.uniform(width - w) + top = random.uniform(height - h) + + # convert to integer rect x1,y1,x2,y2 + rect = np.array([int(left), int(top), int(left+w), int(top+h)]) + + # calculate IoU (jaccard overlap) b/t the cropped and gt boxes + overlap = jaccard_numpy(boxes, rect) + + # This piece of code is bugged and does nothing: + # https://github.com/amdegroot/ssd.pytorch/issues/68 + # + # However, when I fixed it with overlap.max() < min_iou, + # it cut the mAP in half (after 8k iterations). So it stays. + # + # is min and max overlap constraint satisfied? if not try again + if overlap.min() < min_iou and max_iou < overlap.max(): + continue + + # cut the crop from the image + current_image = current_image[rect[1]:rect[3], rect[0]:rect[2], + :] + + # keep overlap with gt box IF center in sampled patch + centers = (boxes[:, :2] + boxes[:, 2:]) / 2.0 + + # mask in all gt boxes that above and to the left of centers + m1 = (rect[0] < centers[:, 0]) * (rect[1] < centers[:, 1]) + + # mask in all gt boxes that under and to the right of centers + m2 = (rect[2] > centers[:, 0]) * (rect[3] > centers[:, 1]) + + # mask in that both m1 and m2 are true + mask = m1 * m2 + + # [0 ... 0 for num_gt and then 1 ... 1 for num_crowds] + num_crowds = labels['num_crowds'] + crowd_mask = np.zeros(mask.shape, dtype=np.int32) + + if num_crowds > 0: + crowd_mask[-num_crowds:] = 1 + + # have any valid boxes? try again if not + # Also make sure you have at least one regular gt + if not mask.any() or np.sum(1-crowd_mask[mask]) == 0: + continue + + # take only the matching gt masks + current_masks = masks[mask, :, :].copy() + + # take only matching gt boxes + current_boxes = boxes[mask, :].copy() + + # take only matching gt labels + labels['labels'] = labels['labels'][mask] + current_labels = labels + + # We now might have fewer crowd annotations + if num_crowds > 0: + labels['num_crowds'] = np.sum(crowd_mask[mask]) + + # should we use the box left and top corner or the crop's + current_boxes[:, :2] = np.maximum(current_boxes[:, :2], + rect[:2]) + # adjust to crop (by substracting crop's left,top) + current_boxes[:, :2] -= rect[:2] + + current_boxes[:, 2:] = np.minimum(current_boxes[:, 2:], + rect[2:]) + # adjust to crop (by substracting crop's left,top) + current_boxes[:, 2:] -= rect[:2] + + # crop the current masks to the same dimensions as the image + current_masks = current_masks[:, rect[1]:rect[3], rect[0]:rect[2]] + + return current_image, current_masks, current_boxes, current_labels + + +class Expand(object): + def __init__(self, mean): + self.mean = mean + + def __call__(self, image, masks, boxes, labels): + if random.randint(2): + return image, masks, boxes, labels + + height, width, depth = image.shape + ratio = random.uniform(1, 4) + left = random.uniform(0, width*ratio - width) + top = random.uniform(0, height*ratio - height) + + expand_image = np.zeros( + (int(height*ratio), int(width*ratio), depth), + dtype=image.dtype) + expand_image[:, :, :] = self.mean + expand_image[int(top):int(top + height), + int(left):int(left + width)] = image + image = expand_image + + expand_masks = np.zeros( + (masks.shape[0], int(height*ratio), int(width*ratio)), + dtype=masks.dtype) + expand_masks[:,int(top):int(top + height), + int(left):int(left + width)] = masks + masks = expand_masks + + boxes = boxes.copy() + boxes[:, :2] += (int(left), int(top)) + boxes[:, 2:] += (int(left), int(top)) + + return image, masks, boxes, labels + + +class RandomMirror(object): + def __call__(self, image, masks, boxes, labels): + _, width, _ = image.shape + if random.randint(2): + image = image[:, ::-1] + masks = masks[:, :, ::-1] + boxes = boxes.copy() + boxes[:, 0::2] = width - boxes[:, 2::-2] + return image, masks, boxes, labels + + +class RandomFlip(object): + def __call__(self, image, masks, boxes, labels): + height , _ , _ = image.shape + if random.randint(2): + image = image[::-1, :] + masks = masks[:, ::-1, :] + boxes = boxes.copy() + boxes[:, 1::2] = height - boxes[:, 3::-2] + return image, masks, boxes, labels + + +class RandomRot90(object): + def __call__(self, image, masks, boxes, labels): + old_height , old_width , _ = image.shape + k = random.randint(4) + image = np.rot90(image,k) + masks = np.array([np.rot90(mask,k) for mask in masks]) + boxes = boxes.copy() + for _ in range(k): + boxes = np.array([[box[1], old_width - 1 - box[2], box[3], old_width - 1 - box[0]] for box in boxes]) + old_width, old_height = old_height, old_width + return image, masks, boxes, labels + + +class SwapChannels(object): + """Transforms a tensorized image by swapping the channels in the order + specified in the swap tuple. + Args: + swaps (int triple): final order of channels + eg: (2, 1, 0) + """ + + def __init__(self, swaps): + self.swaps = swaps + + def __call__(self, image): + """ + Args: + image (Tensor): image tensor to be transformed + Return: + a tensor with channels swapped according to swap + """ + # if torch.is_tensor(image): + # image = image.data.cpu().numpy() + # else: + # image = np.array(image) + image = image[:, :, self.swaps] + return image + + +class PhotometricDistort(object): + def __init__(self): + self.pd = [ + RandomContrast(), + ConvertColor(transform='HSV'), + RandomSaturation(), + RandomHue(), + ConvertColor(current='HSV', transform='BGR'), + RandomContrast() + ] + self.rand_brightness = RandomBrightness() + self.rand_light_noise = RandomLightingNoise() + + def __call__(self, image, masks, boxes, labels): + im = image.copy() + im, masks, boxes, labels = self.rand_brightness(im, masks, boxes, labels) + if random.randint(2): + distort = Compose(self.pd[:-1]) + else: + distort = Compose(self.pd[1:]) + im, masks, boxes, labels = distort(im, masks, boxes, labels) + return self.rand_light_noise(im, masks, boxes, labels) + +class PrepareMasks(object): + """ + Prepares the gt masks for use_gt_bboxes by cropping with the gt box + and downsampling the resulting mask to mask_size, mask_size. This + function doesn't do anything if cfg.use_gt_bboxes is False. + """ + + def __init__(self, mask_size, use_gt_bboxes): + self.mask_size = mask_size + self.use_gt_bboxes = use_gt_bboxes + + def __call__(self, image, masks, boxes, labels=None): + if not self.use_gt_bboxes: + return image, masks, boxes, labels + + height, width, _ = image.shape + + new_masks = np.zeros((masks.shape[0], self.mask_size ** 2)) + + for i in range(len(masks)): + x1, y1, x2, y2 = boxes[i, :] + x1 *= width + x2 *= width + y1 *= height + y2 *= height + x1, y1, x2, y2 = (int(x1), int(y1), int(x2), int(y2)) + + # +1 So that if y1=10.6 and y2=10.9 we still have a bounding box + cropped_mask = masks[i, y1:(y2+1), x1:(x2+1)] + scaled_mask = cv2.resize(cropped_mask, (self.mask_size, self.mask_size)) + + new_masks[i, :] = scaled_mask.reshape(1, -1) + + # Binarize + new_masks[new_masks > 0.5] = 1 + new_masks[new_masks <= 0.5] = 0 + + return image, new_masks, boxes, labels + +class BackboneTransform(object): + """ + Transforms a BRG image made of floats in the range [0, 255] to whatever + input the current backbone network needs. + + transform is a transform config object (see config.py). + in_channel_order is probably 'BGR' but you do you, kid. + """ + def __init__(self, transform, mean, std, in_channel_order): + self.mean = np.array(mean, dtype=np.float32) + self.std = np.array(std, dtype=np.float32) + self.transform = transform + + # Here I use "Algorithms and Coding" to convert string permutations to numbers + self.channel_map = {c: idx for idx, c in enumerate(in_channel_order)} + self.channel_permutation = [self.channel_map[c] for c in transform.channel_order] + + def __call__(self, img, masks=None, boxes=None, labels=None): + + img = img.astype(np.float32) + + if self.transform.normalize: + img = (img - self.mean) / self.std + elif self.transform.subtract_means: + img = (img - self.mean) + elif self.transform.to_float: + img = img / 255 + + img = img[:, :, self.channel_permutation] + + return img.astype(np.float32), masks, boxes, labels + + + + +class BaseTransform(object): + """ Transorm to be used when evaluating. """ + + def __init__(self, mean=MEANS, std=STD): + self.augment = Compose([ + ConvertFromInts(), + Resize(resize_gt=False), + BackboneTransform(cfg.backbone.transform, mean, std, 'BGR') + ]) + + def __call__(self, img, masks=None, boxes=None, labels=None): + return self.augment(img, masks, boxes, labels) + +import torch.nn.functional as F + +class FastBaseTransform(torch.nn.Module): + """ + Transform that does all operations on the GPU for super speed. + This doesn't suppport a lot of config settings and should only be used for production. + Maintain this as necessary. + """ + + def __init__(self): + super().__init__() + + self.mean = torch.Tensor(MEANS).float().cuda()[None, :, None, None] + self.std = torch.Tensor( STD ).float().cuda()[None, :, None, None] + self.transform = cfg.backbone.transform + + def forward(self, img): + self.mean = self.mean.to(img.device) + self.std = self.std.to(img.device) + + # img assumed to be a pytorch BGR image with channel order [n, h, w, c] + if cfg.preserve_aspect_ratio: + _, h, w, _ = img.size() + img_size = Resize.calc_size_preserve_ar(w, h, cfg.max_size) + img_size = (img_size[1], img_size[0]) # Pytorch needs h, w + else: + img_size = (cfg.max_size, cfg.max_size) + + img = img.permute(0, 3, 1, 2).contiguous() + img = F.interpolate(img, img_size, mode='bilinear', align_corners=False) + + if self.transform.normalize: + img = (img - self.mean) / self.std + elif self.transform.subtract_means: + img = (img - self.mean) + elif self.transform.to_float: + img = img / 255 + + if self.transform.channel_order != 'RGB': + raise NotImplementedError + + img = img[:, (2, 1, 0), :, :].contiguous() + + # Return value is in channel order [n, c, h, w] and RGB + return img + +def do_nothing(img=None, masks=None, boxes=None, labels=None): + return img, masks, boxes, labels + + +def enable_if(condition, obj): + return obj if condition else do_nothing + +class SSDAugmentation(object): + """ Transform to be used when training. """ + + def __init__(self, mean=MEANS, std=STD): + self.augment = Compose([ + ConvertFromInts(), + ToAbsoluteCoords(), + enable_if(cfg.augment_photometric_distort, PhotometricDistort()), + enable_if(cfg.augment_expand, Expand(mean)), + enable_if(cfg.augment_random_sample_crop, RandomSampleCrop()), + enable_if(cfg.augment_random_mirror, RandomMirror()), + enable_if(cfg.augment_random_flip, RandomFlip()), + enable_if(cfg.augment_random_flip, RandomRot90()), + Resize(), + enable_if(not cfg.preserve_aspect_ratio, Pad(cfg.max_size, cfg.max_size, mean)), + ToPercentCoords(), + PrepareMasks(cfg.mask_size, cfg.use_gt_bboxes), + BackboneTransform(cfg.backbone.transform, mean, std, 'BGR') + ]) + + def __call__(self, img, masks, boxes, labels): + return self.augment(img, masks, boxes, labels) diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/utils/cython_nms.pyx b/PyTorch/contrib/cv/detection/YOLACT_plus/utils/cython_nms.pyx index 4a4a5bda8030ec1c2f9ce9e4a2df9dc76ef437a0..892be872edc6b560c1a5b7bff0c6fca18a929b53 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/utils/cython_nms.pyx +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/utils/cython_nms.pyx @@ -1,74 +1,74 @@ -## Note: Figure out the license details later. -# -# Based on: -# -------------------------------------------------------- -# Fast R-CNN -# Copyright (c) 2015 Microsoft -# Licensed under The MIT License [see LICENSE for details] -# Written by Ross Girshick -# -------------------------------------------------------- - -cimport cython -import numpy as np -cimport numpy as np - -cdef inline np.float32_t max(np.float32_t a, np.float32_t b) nogil: - return a if a >= b else b - -cdef inline np.float32_t min(np.float32_t a, np.float32_t b) nogil: - return a if a <= b else b - -@cython.boundscheck(False) -@cython.cdivision(True) -@cython.wraparound(False) -def nms(np.ndarray[np.float32_t, ndim=2] dets, np.float32_t thresh): - cdef np.ndarray[np.float32_t, ndim=1] x1 = dets[:, 0] - cdef np.ndarray[np.float32_t, ndim=1] y1 = dets[:, 1] - cdef np.ndarray[np.float32_t, ndim=1] x2 = dets[:, 2] - cdef np.ndarray[np.float32_t, ndim=1] y2 = dets[:, 3] - cdef np.ndarray[np.float32_t, ndim=1] scores = dets[:, 4] - - cdef np.ndarray[np.float32_t, ndim=1] areas = (x2 - x1 + 1) * (y2 - y1 + 1) - cdef np.ndarray[np.int64_t, ndim=1] order = scores.argsort()[::-1] - - cdef int ndets = dets.shape[0] - cdef np.ndarray[np.int_t, ndim=1] suppressed = \ - np.zeros((ndets), dtype=np.int) - - # nominal indices - cdef int _i, _j - # sorted indices - cdef int i, j - # temp variables for box i's (the box currently under consideration) - cdef np.float32_t ix1, iy1, ix2, iy2, iarea - # variables for computing overlap with box j (lower scoring box) - cdef np.float32_t xx1, yy1, xx2, yy2 - cdef np.float32_t w, h - cdef np.float32_t inter, ovr - - with nogil: - for _i in range(ndets): - i = order[_i] - if suppressed[i] == 1: - continue - ix1 = x1[i] - iy1 = y1[i] - ix2 = x2[i] - iy2 = y2[i] - iarea = areas[i] - for _j in range(_i + 1, ndets): - j = order[_j] - if suppressed[j] == 1: - continue - xx1 = max(ix1, x1[j]) - yy1 = max(iy1, y1[j]) - xx2 = min(ix2, x2[j]) - yy2 = min(iy2, y2[j]) - w = max(0.0, xx2 - xx1 + 1) - h = max(0.0, yy2 - yy1 + 1) - inter = w * h - ovr = inter / (iarea + areas[j] - inter) - if ovr >= thresh: - suppressed[j] = 1 - - return np.where(suppressed == 0)[0] +## Note: Figure out the license details later. +# +# Based on: +# -------------------------------------------------------- +# Fast R-CNN +# Copyright (c) 2015 Microsoft +# Licensed under The MIT License [see LICENSE for details] +# Written by Ross Girshick +# -------------------------------------------------------- + +cimport cython +import numpy as np +cimport numpy as np + +cdef inline np.float32_t max(np.float32_t a, np.float32_t b) nogil: + return a if a >= b else b + +cdef inline np.float32_t min(np.float32_t a, np.float32_t b) nogil: + return a if a <= b else b + +@cython.boundscheck(False) +@cython.cdivision(True) +@cython.wraparound(False) +def nms(np.ndarray[np.float32_t, ndim=2] dets, np.float32_t thresh): + cdef np.ndarray[np.float32_t, ndim=1] x1 = dets[:, 0] + cdef np.ndarray[np.float32_t, ndim=1] y1 = dets[:, 1] + cdef np.ndarray[np.float32_t, ndim=1] x2 = dets[:, 2] + cdef np.ndarray[np.float32_t, ndim=1] y2 = dets[:, 3] + cdef np.ndarray[np.float32_t, ndim=1] scores = dets[:, 4] + + cdef np.ndarray[np.float32_t, ndim=1] areas = (x2 - x1 + 1) * (y2 - y1 + 1) + cdef np.ndarray[np.int64_t, ndim=1] order = scores.argsort()[::-1] + + cdef int ndets = dets.shape[0] + cdef np.ndarray[np.int_t, ndim=1] suppressed = \ + np.zeros((ndets), dtype=np.int) + + # nominal indices + cdef int _i, _j + # sorted indices + cdef int i, j + # temp variables for box i's (the box currently under consideration) + cdef np.float32_t ix1, iy1, ix2, iy2, iarea + # variables for computing overlap with box j (lower scoring box) + cdef np.float32_t xx1, yy1, xx2, yy2 + cdef np.float32_t w, h + cdef np.float32_t inter, ovr + + with nogil: + for _i in range(ndets): + i = order[_i] + if suppressed[i] == 1: + continue + ix1 = x1[i] + iy1 = y1[i] + ix2 = x2[i] + iy2 = y2[i] + iarea = areas[i] + for _j in range(_i + 1, ndets): + j = order[_j] + if suppressed[j] == 1: + continue + xx1 = max(ix1, x1[j]) + yy1 = max(iy1, y1[j]) + xx2 = min(ix2, x2[j]) + yy2 = min(iy2, y2[j]) + w = max(0.0, xx2 - xx1 + 1) + h = max(0.0, yy2 - yy1 + 1) + inter = w * h + ovr = inter / (iarea + areas[j] - inter) + if ovr >= thresh: + suppressed[j] = 1 + + return np.where(suppressed == 0)[0] diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/utils/functions.py b/PyTorch/contrib/cv/detection/YOLACT_plus/utils/functions.py index d9ce98c4f98deed917ef3885611792f2783dce80..6dfeff2d4add5508cae91b2f6442099c514f3eb7 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/utils/functions.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/utils/functions.py @@ -1,227 +1,227 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch -import torch.nn as nn -import os -import math -from collections import deque -from pathlib import Path -from layers.interpolate import InterpolateModule - -class MovingAverage(): - """ Keeps an average window of the specified number of items. """ - - def __init__(self, max_window_size=1000): - self.max_window_size = max_window_size - self.reset() - - def add(self, elem): - """ Adds an element to the window, removing the earliest element if necessary. """ - if not math.isfinite(elem): - print('Warning: Moving average ignored a value of %f' % elem) - return - - self.window.append(elem) - self.sum += elem - - if len(self.window) > self.max_window_size: - self.sum -= self.window.popleft() - - def append(self, elem): - """ Same as add just more pythonic. """ - self.add(elem) - - def reset(self): - """ Resets the MovingAverage to its initial state. """ - self.window = deque() - self.sum = 0 - - def get_avg(self): - """ Returns the average of the elements in the window. """ - return self.sum / max(len(self.window), 1) - - def __str__(self): - return str(self.get_avg()) - - def __repr__(self): - return repr(self.get_avg()) - - def __len__(self): - return len(self.window) - - -class ProgressBar(): - """ A simple progress bar that just outputs a string. """ - - def __init__(self, length, max_val): - self.max_val = max_val - self.length = length - self.cur_val = 0 - - self.cur_num_bars = -1 - self._update_str() - - def set_val(self, new_val): - self.cur_val = new_val - - if self.cur_val > self.max_val: - self.cur_val = self.max_val - if self.cur_val < 0: - self.cur_val = 0 - - self._update_str() - - def is_finished(self): - return self.cur_val == self.max_val - - def _update_str(self): - num_bars = int(self.length * (self.cur_val / self.max_val)) - - if num_bars != self.cur_num_bars: - self.cur_num_bars = num_bars - self.string = '█' * num_bars + '░' * (self.length - num_bars) - - def __repr__(self): - return self.string - - def __str__(self): - return self.string - - -def init_console(): - """ - Initialize the console to be able to use ANSI escape characters on Windows. - """ - if os.name == 'nt': - from colorama import init - init() - - -class SavePath: - """ - Why is this a class? - Why do I have a class for creating and parsing save paths? - What am I doing with my life? - """ - - def __init__(self, model_name:str, epoch:int, iteration:int): - self.model_name = model_name - self.epoch = epoch - self.iteration = iteration - - def get_path(self, root:str=''): - file_name = self.model_name + '_' + str(self.epoch) + '_' + str(self.iteration) + '.pth' - return os.path.join(root, file_name) - - @staticmethod - def from_str(path:str): - file_name = os.path.basename(path) - - if file_name.endswith('.pth'): - file_name = file_name[:-4] - - params = file_name.split('_') - - if file_name.endswith('interrupt'): - params = params[:-1] - - model_name = '_'.join(params[:-2]) - epoch = params[-2] - iteration = params[-1] - - return SavePath(model_name, int(epoch), int(iteration)) - - @staticmethod - def remove_interrupt(save_folder): - for p in Path(save_folder).glob('*_interrupt.pth'): - p.unlink() - - @staticmethod - def get_interrupt(save_folder): - for p in Path(save_folder).glob('*_interrupt.pth'): - return str(p) - return None - - @staticmethod - def get_latest(save_folder, config): - """ Note: config should be config.name. """ - max_iter = -1 - max_name = None - - for p in Path(save_folder).glob(config + '_*'): - path_name = str(p) - - try: - save = SavePath.from_str(path_name) - except: - continue - - if save.model_name == config and save.iteration > max_iter: - max_iter = save.iteration - max_name = path_name - - return max_name - -def make_net(in_channels, conf, include_last_relu=True): - """ - A helper function to take a config setting and turn it into a network. - Used by protonet and extrahead. Returns (network, out_channels) - """ - def make_layer(layer_cfg): - nonlocal in_channels - - # Possible patterns: - # ( 256, 3, {}) -> conv - # ( 256,-2, {}) -> deconv - # (None,-2, {}) -> bilinear interpolate - # ('cat',[],{}) -> concat the subnetworks in the list - # - # You know it would have probably been simpler just to adopt a 'c' 'd' 'u' naming scheme. - # Whatever, it's too late now. - if isinstance(layer_cfg[0], str): - layer_name = layer_cfg[0] - - if layer_name == 'cat': - nets = [make_net(in_channels, x) for x in layer_cfg[1]] - layer = Concat([net[0] for net in nets], layer_cfg[2]) - num_channels = sum([net[1] for net in nets]) - else: - num_channels = layer_cfg[0] - kernel_size = layer_cfg[1] - - if kernel_size > 0: - layer = nn.Conv2d(in_channels, num_channels, kernel_size, **layer_cfg[2]) - else: - if num_channels is None: - layer = InterpolateModule(scale_factor=-kernel_size, mode='bilinear', align_corners=False, **layer_cfg[2]) - else: - layer = nn.ConvTranspose2d(in_channels, num_channels, -kernel_size, **layer_cfg[2]) - - in_channels = num_channels if num_channels is not None else in_channels - - # Don't return a ReLU layer if we're doing an upsample. This probably doesn't affect anything - # output-wise, but there's no need to go through a ReLU here. - # Commented out for backwards compatibility with previous models - # if num_channels is None: - # return [layer] - # else: - return [layer, nn.ReLU(inplace=True)] - - # Use sum to concat together all the component layer lists - net = sum([make_layer(x) for x in conf], []) - if not include_last_relu: - net = net[:-1] - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch +import torch.nn as nn +import os +import math +from collections import deque +from pathlib import Path +from layers.interpolate import InterpolateModule + +class MovingAverage(): + """ Keeps an average window of the specified number of items. """ + + def __init__(self, max_window_size=1000): + self.max_window_size = max_window_size + self.reset() + + def add(self, elem): + """ Adds an element to the window, removing the earliest element if necessary. """ + if not math.isfinite(elem): + print('Warning: Moving average ignored a value of %f' % elem) + return + + self.window.append(elem) + self.sum += elem + + if len(self.window) > self.max_window_size: + self.sum -= self.window.popleft() + + def append(self, elem): + """ Same as add just more pythonic. """ + self.add(elem) + + def reset(self): + """ Resets the MovingAverage to its initial state. """ + self.window = deque() + self.sum = 0 + + def get_avg(self): + """ Returns the average of the elements in the window. """ + return self.sum / max(len(self.window), 1) + + def __str__(self): + return str(self.get_avg()) + + def __repr__(self): + return repr(self.get_avg()) + + def __len__(self): + return len(self.window) + + +class ProgressBar(): + """ A simple progress bar that just outputs a string. """ + + def __init__(self, length, max_val): + self.max_val = max_val + self.length = length + self.cur_val = 0 + + self.cur_num_bars = -1 + self._update_str() + + def set_val(self, new_val): + self.cur_val = new_val + + if self.cur_val > self.max_val: + self.cur_val = self.max_val + if self.cur_val < 0: + self.cur_val = 0 + + self._update_str() + + def is_finished(self): + return self.cur_val == self.max_val + + def _update_str(self): + num_bars = int(self.length * (self.cur_val / self.max_val)) + + if num_bars != self.cur_num_bars: + self.cur_num_bars = num_bars + self.string = '█' * num_bars + '░' * (self.length - num_bars) + + def __repr__(self): + return self.string + + def __str__(self): + return self.string + + +def init_console(): + """ + Initialize the console to be able to use ANSI escape characters on Windows. + """ + if os.name == 'nt': + from colorama import init + init() + + +class SavePath: + """ + Why is this a class? + Why do I have a class for creating and parsing save paths? + What am I doing with my life? + """ + + def __init__(self, model_name:str, epoch:int, iteration:int): + self.model_name = model_name + self.epoch = epoch + self.iteration = iteration + + def get_path(self, root:str=''): + file_name = self.model_name + '_' + str(self.epoch) + '_' + str(self.iteration) + '.pth' + return os.path.join(root, file_name) + + @staticmethod + def from_str(path:str): + file_name = os.path.basename(path) + + if file_name.endswith('.pth'): + file_name = file_name[:-4] + + params = file_name.split('_') + + if file_name.endswith('interrupt'): + params = params[:-1] + + model_name = '_'.join(params[:-2]) + epoch = params[-2] + iteration = params[-1] + + return SavePath(model_name, int(epoch), int(iteration)) + + @staticmethod + def remove_interrupt(save_folder): + for p in Path(save_folder).glob('*_interrupt.pth'): + p.unlink() + + @staticmethod + def get_interrupt(save_folder): + for p in Path(save_folder).glob('*_interrupt.pth'): + return str(p) + return None + + @staticmethod + def get_latest(save_folder, config): + """ Note: config should be config.name. """ + max_iter = -1 + max_name = None + + for p in Path(save_folder).glob(config + '_*'): + path_name = str(p) + + try: + save = SavePath.from_str(path_name) + except: + continue + + if save.model_name == config and save.iteration > max_iter: + max_iter = save.iteration + max_name = path_name + + return max_name + +def make_net(in_channels, conf, include_last_relu=True): + """ + A helper function to take a config setting and turn it into a network. + Used by protonet and extrahead. Returns (network, out_channels) + """ + def make_layer(layer_cfg): + nonlocal in_channels + + # Possible patterns: + # ( 256, 3, {}) -> conv + # ( 256,-2, {}) -> deconv + # (None,-2, {}) -> bilinear interpolate + # ('cat',[],{}) -> concat the subnetworks in the list + # + # You know it would have probably been simpler just to adopt a 'c' 'd' 'u' naming scheme. + # Whatever, it's too late now. + if isinstance(layer_cfg[0], str): + layer_name = layer_cfg[0] + + if layer_name == 'cat': + nets = [make_net(in_channels, x) for x in layer_cfg[1]] + layer = Concat([net[0] for net in nets], layer_cfg[2]) + num_channels = sum([net[1] for net in nets]) + else: + num_channels = layer_cfg[0] + kernel_size = layer_cfg[1] + + if kernel_size > 0: + layer = nn.Conv2d(in_channels, num_channels, kernel_size, **layer_cfg[2]) + else: + if num_channels is None: + layer = InterpolateModule(scale_factor=-kernel_size, mode='bilinear', align_corners=False, **layer_cfg[2]) + else: + layer = nn.ConvTranspose2d(in_channels, num_channels, -kernel_size, **layer_cfg[2]) + + in_channels = num_channels if num_channels is not None else in_channels + + # Don't return a ReLU layer if we're doing an upsample. This probably doesn't affect anything + # output-wise, but there's no need to go through a ReLU here. + # Commented out for backwards compatibility with previous models + # if num_channels is None: + # return [layer] + # else: + return [layer, nn.ReLU(inplace=True)] + + # Use sum to concat together all the component layer lists + net = sum([make_layer(x) for x in conf], []) + if not include_last_relu: + net = net[:-1] + return nn.Sequential(*(net)), in_channels \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/utils/logger.py b/PyTorch/contrib/cv/detection/YOLACT_plus/utils/logger.py index cfc407bad59e34b006d6f2b94af7691f1dbb22eb..7f84f57816ad4166b2f1f9a8dfbdc3c6bf92dc6e 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/utils/logger.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/utils/logger.py @@ -1,503 +1,503 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import os -import json -import time -import sys - -from typing import Union -import datetime - -from collections import defaultdict -import matplotlib.pyplot as plt -import numpy as np - -# Because Python's package heierarchy system sucks -if __name__ == '__main__': - from utils.nvinfo import gpu_info, visible_gpus, nvsmi_available - from utils.functions import MovingAverage -else: - from .nvinfo import gpu_info, visible_gpus, nvsmi_available - from .functions import MovingAverage - -class Log: - """ - A class to log information during training per information and save it out. - It also can include extra debug information like GPU usage / temp automatically. - - Extra args: - - session_data: If you have any data unique to this session, put it here. - - overwrite: Whether or not to overwrite a pre-existing log with this name. - - log_gpu_stats: Whether or not to log gpu information like temp, usage, memory. - Note that this requires nvidia-smi to be present in your PATH. - - log_time: Also log the time in each iteration. - """ - - def __init__(self, log_name:str, log_dir:str='logs/', session_data:dict={}, - overwrite:bool=False, log_gpu_stats:bool=True, log_time:bool=True): - - if log_gpu_stats and not nvsmi_available(): - print('Warning: Log created with log_gpu_stats=True, but nvidia-smi ' \ - 'was not found. Setting log_gpu_stats to False.') - log_gpu_stats = False - - if not os.path.exists(log_dir): - os.makedirs(log_dir) - self.log_path = os.path.join(log_dir, log_name + '.log') - - # if os.path.exists(self.log_path) and overwrite: - # os.unlink(self.log_path) - - if os.path.exists(self.log_path): - # Log already exists, so we're going to add to it. Increment the session counter. - with open(self.log_path, 'r') as f: - for last in f: pass - - if len(last) > 1: - self.session = json.loads(last)['session'] + 1 - else: - self.session = 0 - else: - self.session = 0 - - - self.log_gpu_stats = log_gpu_stats - self.log_time = log_time - - if self.log_gpu_stats: - self.visible_gpus = visible_gpus() - - - self._log_session_header(session_data) - - - def _log_session_header(self, session_data:dict): - """ - Log information that does not change between iterations here. - This is to cut down on the file size so you're not outputing this every iteration. - """ - info = {} - info['type'] = 'session' - info['session'] = self.session - - info['data'] = session_data - - if self.log_gpu_stats: - keys = ['idx', 'name', 'uuid', 'pwr_cap', 'mem_total'] - - gpus = gpu_info() - info['gpus'] = [{k: gpus[i][k] for k in keys} for i in self.visible_gpus] - - if self.log_time: - info['time'] = time.time() - - out = json.dumps(info) + '\n' - - with open(self.log_path, 'a') as f: - f.write(out) - - - def log(self, type:str, data:dict={}, **kwdargs): - """ - Add an iteration to the log with the specified data points. - Type should be the type of information this is (e.g., train, valid, etc.) - - You can either pass data points as kwdargs, or as a dictionary (or both!). - Values should be json-serializable. - """ - info = {} - - info['type'] = type - info['session'] = self.session - - kwdargs.update(data) - info['data'] = kwdargs - - if self.log_gpu_stats: - keys = ['fan_spd', 'temp', 'pwr_used', 'mem_used', 'util'] - - gpus = gpu_info() - info['gpus'] = [{k: gpus[i][k] for k in keys} for i in self.visible_gpus] - - if self.log_time: - info['time'] = time.time() - - - out = json.dumps(info) + '\n' - - with open(self.log_path, 'a') as f: - f.write(out) - - -class LogEntry(): - """ A class that allows you to navigate a dictonary using x.a.b[2].c, etc. """ - - def __init__(self, entry:Union[dict, list]): - self._ = entry - - def __getattr__(self, name): - if name == '_': - return self.__dict__['_'] - - res = self.__dict__['_'][name] - - if type(res) == dict or type(res) == list: - return LogEntry(res) - else: - return res - - def __getitem__(self, name): - return self.__getattr__(name) - - def __len__(self): - return len(self.__dict__['_']) - -class LogVisualizer(): - - COLORS = [ - 'xkcd:azure', - 'xkcd:coral', - 'xkcd:turquoise', - 'xkcd:orchid', - 'xkcd:orange', - - 'xkcd:blue', - 'xkcd:red', - 'xkcd:teal', - 'xkcd:magenta', - 'xkcd:orangered' - ] - - def __init__(self): - self.logs = [] - self.total_logs = [] - self.log_names = [] - - def _decode(self, query:str) -> list: - path, select = (query.split(';') + [''])[:2] - - if select.strip() == '': - select = lambda x, s: True - else: - select = eval('lambda x, s: ' + select) - - if path.strip() == '': - path = lambda x, s: x - else: - path = eval('lambda x, s: ' + path) - - return path, select - - def _follow(self, entry:LogEntry, query:list): - path, select = query - - try: - if select(entry, entry._s): - res = path(entry, entry._s) - - if type(res) == LogEntry: - return res.__dict__['_'] - else: - return res - else: - return None - except (KeyError, IndexError): - return None - - def _color(self, idx:int): - return self.COLORS[idx % len(self.COLORS)] - - def sessions(self, path:str): - """ Prints statistics about the sessions in the file. """ - - if not os.path.exists(path): - print(path + ' doesn\'t exist!') - return - - cur_session = None - cur_time = 0 - last_time = 0 - num_entries = 0 - - def pop_session(): - delta = last_time - cur_time - time_str = str(datetime.timedelta(seconds=delta)).split('.')[0] - print('Session % 3d: % 8d entries | %s elapsed' % (cur_session, num_entries, time_str)) - - with open(path, 'r') as f: - for line in f: - line = line.strip() - if len(line) > 0: - js = json.loads(line) - if js['type'] == 'session': - if cur_session is not None: - pop_session() - cur_time = js['time'] - cur_session = js['session'] - num_entries = 0 - last_time = js['time'] - num_entries += 1 - - pop_session() - - def add(self, path:str, session:Union[int,list]=None): - """ Add a log file to the list of logs being considered. """ - - log = defaultdict(lambda: []) - total_log = [] - - if not os.path.exists(path): - print(path + ' doesn\'t exist!') - return - - session_idx = 0 - ignoring = True - - def valid(idx): - if session is None: - return True - elif type(session) == int: - return (idx == session) - else: - return idx in session - - with open(path, 'r') as f: - for line in f: - line = line.strip() - if len(line) > 0: - js = json.loads(line) - - _type = js['type'] - if _type == 'session': - session_idx = js['session'] - ignoring = not valid(session_idx) - - if not ignoring: - ljs = LogEntry(js) - if _type == 'session': - js['_s'] = ljs - else: - js['_s'] =log['session'][-1] - log[_type].append(ljs) - total_log.append(ljs) - - name = os.path.basename(path) - if session is not None: - name += ' (Session %s)' % session - - self.logs.append(log) - self.total_logs.append(total_log) - self.log_names.append(name) - - def query(self, x:Union[str, list], entry_type:str=None, x_idx:int=None, log_idx:int=None) -> list: - """ - Given a query string (can be already decoded for faster computation), query the entire log - and return all values found by that query. If both log_idx and x_idx is None, this will be - a list of lists in the form [log_idx][result_idx]. If x_idx is not None, then the result - will be a list of [log_idx]. If both are not none, the return value will be a single query - return value. With entry_type=None, this will search the entire log. - """ - - if type(x) is not list: - x = self._decode(x) - - res = [] - - for idx in (range(len(self.logs)) if log_idx is None else [log_idx]): - candidates = [] - log = self.total_logs[idx] if entry_type is None else self.logs[idx][entry_type] - - for entry in log: - candidate = self._follow(entry, x) - if candidate is not None: - candidates.append(candidate) - - if x_idx is not None: - candidates = candidates[x_idx] - res.append(candidates) - - if log_idx is not None: - res = res[0] - return res - - def check(self, entry_type:str, x:str): - """ Checks the log for the valid keys for this input. """ - keys = set() - x = self._decode(x) - - for log in self.logs: - for datum in log[entry_type]: - res = self._follow(datum, x) - - if type(res) == dict: - for key in res.keys(): - keys.add(key) - elif type(res) == list: - keys.add('< %d' % len(res)) - - return list(keys) - - def plot(self, entry_type:str, x:str, y:str, smoothness:int=0): - """ Plot sequential log data. """ - - query_x = self._decode(x) - query_y = self._decode(y) - - for idx, (log, name) in enumerate(zip(self.logs, self.log_names)): - log = log[entry_type] - - if smoothness > 1: - avg = MovingAverage(smoothness) - - _x = [] - _y = [] - - for datum in log: - val_x = self._follow(datum, query_x) - val_y = self._follow(datum, query_y) - - if val_x is not None and val_y is not None: - if smoothness > 1: - avg.append(val_y) - val_y = avg.get_avg() - - if len(avg) < smoothness // 10: - continue - - _x.append(val_x) - _y.append(val_y) - - plt.plot(_x, _y, color=self._color(idx), label=name) - - plt.title(y.replace('x.', entry_type + '.')) - plt.legend() - plt.grid(linestyle=':', linewidth=0.5) - plt.show() - - def bar(self, entry_type:str, x:str, labels:list=None, diff:bool=False, x_idx:int=-1): - """ Plot a bar chart. The result of x should be list or dictionary. """ - - query = self._decode(x) - - data_points = [] - - for idx, (log, name) in enumerate(zip(self.logs, self.log_names)): - log = log[entry_type] - - candidates = [] - - for entry in log: - test = self._follow(entry, query) - - if type(test) == dict: - candidates.append(test) - elif type(test) == list: - candidates.append({idx: v for idx, v in enumerate(test)}) - - if len(candidates) > 0: - data_points.append((name, candidates[x_idx])) - - if len(data_points) == 0: - print('Warning: Nothing to show in bar chart!') - return - - names = [x[0] for x in data_points] - data_points = [x[1] for x in data_points] - - # Construct the labels for the data - if labels is not None: - data_labels = labels - else: - data_labels = set() - for datum in data_points: - for k in datum: - data_labels.add(k) - - data_labels = list(data_labels) - data_labels.sort() - - - data_values = [[(datum[k] if k in datum else None) for k in data_labels] for datum in data_points] - - if diff: - for idx in reversed(range(len(data_values))): - for jdx in range(len(data_labels)): - if data_values[0][jdx] is None or data_values[idx][jdx] is None: - data_values[idx][jdx] = None - else: - data_values[idx][jdx] -= data_values[0][jdx] - - - series_labels = names - - # Plot the graph now - num_bars = len(series_labels) - bar_width = 1 / (num_bars + 1) - - # Set position of bar on X axis - positions = [np.arange(len(data_labels))] - for _ in range(1, num_bars): - positions.append([x + bar_width for x in positions[-1]]) - - # Make the plot - for idx, (series, data, pos) in enumerate(zip(series_labels, data_values, positions)): - plt.bar(pos, data, color=self._color(idx), width=bar_width, edgecolor='white', label=series) - - # Add xticks on the middle of the group bars - plt.title(x.replace('x.', entry_type + '.') + (' diff' if diff else '')) - plt.xticks([r + bar_width for r in range(len(data_labels))], data_labels) - - # Create legend & Show graphic - plt.legend() - plt.show() - - - - def elapsed_time(self, cond1:str='', cond2:str='', legible:bool=True) -> list: - """ - Returns the elapsed time between two entries based on the given conditionals. - If a query isn't specified, the first / last entry will be used. The first query - uses the first value and the second query uses the last value in the results. - - Setting legible to true returns human-readable results, while false returns seconds. - """ - q1 = 'x.time; ' + cond1 - q2 = 'x.time; ' + cond2 - - x1 = self.query(q1, x_idx=0) - x2 = self.query(q2, x_idx=-1) - - diff = (lambda x: str(datetime.timedelta(seconds=x)).split('.')[0]) if legible else lambda x: x - - return [diff(b - a) for a, b in zip(x1, x2)] - - - - - - - - - - - -if __name__ == '__main__': - if len(sys.argv) < 4+1: - print('Usage: python utils/logger.py ') - exit() - - vis = LogVisualizer() - vis.add(sys.argv[1]) - vis.plot(sys.argv[2], sys.argv[3], sys.argv[4]) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import os +import json +import time +import sys + +from typing import Union +import datetime + +from collections import defaultdict +import matplotlib.pyplot as plt +import numpy as np + +# Because Python's package heierarchy system sucks +if __name__ == '__main__': + from utils.nvinfo import gpu_info, visible_gpus, nvsmi_available + from utils.functions import MovingAverage +else: + from .nvinfo import gpu_info, visible_gpus, nvsmi_available + from .functions import MovingAverage + +class Log: + """ + A class to log information during training per information and save it out. + It also can include extra debug information like GPU usage / temp automatically. + + Extra args: + - session_data: If you have any data unique to this session, put it here. + - overwrite: Whether or not to overwrite a pre-existing log with this name. + - log_gpu_stats: Whether or not to log gpu information like temp, usage, memory. + Note that this requires nvidia-smi to be present in your PATH. + - log_time: Also log the time in each iteration. + """ + + def __init__(self, log_name:str, log_dir:str='logs/', session_data:dict={}, + overwrite:bool=False, log_gpu_stats:bool=True, log_time:bool=True): + + if log_gpu_stats and not nvsmi_available(): + print('Warning: Log created with log_gpu_stats=True, but nvidia-smi ' \ + 'was not found. Setting log_gpu_stats to False.') + log_gpu_stats = False + + if not os.path.exists(log_dir): + os.makedirs(log_dir) + self.log_path = os.path.join(log_dir, log_name + '.log') + + # if os.path.exists(self.log_path) and overwrite: + # os.unlink(self.log_path) + + if os.path.exists(self.log_path): + # Log already exists, so we're going to add to it. Increment the session counter. + with open(self.log_path, 'r') as f: + for last in f: pass + + if len(last) > 1: + self.session = json.loads(last)['session'] + 1 + else: + self.session = 0 + else: + self.session = 0 + + + self.log_gpu_stats = log_gpu_stats + self.log_time = log_time + + if self.log_gpu_stats: + self.visible_gpus = visible_gpus() + + + self._log_session_header(session_data) + + + def _log_session_header(self, session_data:dict): + """ + Log information that does not change between iterations here. + This is to cut down on the file size so you're not outputing this every iteration. + """ + info = {} + info['type'] = 'session' + info['session'] = self.session + + info['data'] = session_data + + if self.log_gpu_stats: + keys = ['idx', 'name', 'uuid', 'pwr_cap', 'mem_total'] + + gpus = gpu_info() + info['gpus'] = [{k: gpus[i][k] for k in keys} for i in self.visible_gpus] + + if self.log_time: + info['time'] = time.time() + + out = json.dumps(info) + '\n' + + with open(self.log_path, 'a') as f: + f.write(out) + + + def log(self, type:str, data:dict={}, **kwdargs): + """ + Add an iteration to the log with the specified data points. + Type should be the type of information this is (e.g., train, valid, etc.) + + You can either pass data points as kwdargs, or as a dictionary (or both!). + Values should be json-serializable. + """ + info = {} + + info['type'] = type + info['session'] = self.session + + kwdargs.update(data) + info['data'] = kwdargs + + if self.log_gpu_stats: + keys = ['fan_spd', 'temp', 'pwr_used', 'mem_used', 'util'] + + gpus = gpu_info() + info['gpus'] = [{k: gpus[i][k] for k in keys} for i in self.visible_gpus] + + if self.log_time: + info['time'] = time.time() + + + out = json.dumps(info) + '\n' + + with open(self.log_path, 'a') as f: + f.write(out) + + +class LogEntry(): + """ A class that allows you to navigate a dictonary using x.a.b[2].c, etc. """ + + def __init__(self, entry:Union[dict, list]): + self._ = entry + + def __getattr__(self, name): + if name == '_': + return self.__dict__['_'] + + res = self.__dict__['_'][name] + + if type(res) == dict or type(res) == list: + return LogEntry(res) + else: + return res + + def __getitem__(self, name): + return self.__getattr__(name) + + def __len__(self): + return len(self.__dict__['_']) + +class LogVisualizer(): + + COLORS = [ + 'xkcd:azure', + 'xkcd:coral', + 'xkcd:turquoise', + 'xkcd:orchid', + 'xkcd:orange', + + 'xkcd:blue', + 'xkcd:red', + 'xkcd:teal', + 'xkcd:magenta', + 'xkcd:orangered' + ] + + def __init__(self): + self.logs = [] + self.total_logs = [] + self.log_names = [] + + def _decode(self, query:str) -> list: + path, select = (query.split(';') + [''])[:2] + + if select.strip() == '': + select = lambda x, s: True + else: + select = eval('lambda x, s: ' + select) + + if path.strip() == '': + path = lambda x, s: x + else: + path = eval('lambda x, s: ' + path) + + return path, select + + def _follow(self, entry:LogEntry, query:list): + path, select = query + + try: + if select(entry, entry._s): + res = path(entry, entry._s) + + if type(res) == LogEntry: + return res.__dict__['_'] + else: + return res + else: + return None + except (KeyError, IndexError): + return None + + def _color(self, idx:int): + return self.COLORS[idx % len(self.COLORS)] + + def sessions(self, path:str): + """ Prints statistics about the sessions in the file. """ + + if not os.path.exists(path): + print(path + ' doesn\'t exist!') + return + + cur_session = None + cur_time = 0 + last_time = 0 + num_entries = 0 + + def pop_session(): + delta = last_time - cur_time + time_str = str(datetime.timedelta(seconds=delta)).split('.')[0] + print('Session % 3d: % 8d entries | %s elapsed' % (cur_session, num_entries, time_str)) + + with open(path, 'r') as f: + for line in f: + line = line.strip() + if len(line) > 0: + js = json.loads(line) + if js['type'] == 'session': + if cur_session is not None: + pop_session() + cur_time = js['time'] + cur_session = js['session'] + num_entries = 0 + last_time = js['time'] + num_entries += 1 + + pop_session() + + def add(self, path:str, session:Union[int,list]=None): + """ Add a log file to the list of logs being considered. """ + + log = defaultdict(lambda: []) + total_log = [] + + if not os.path.exists(path): + print(path + ' doesn\'t exist!') + return + + session_idx = 0 + ignoring = True + + def valid(idx): + if session is None: + return True + elif type(session) == int: + return (idx == session) + else: + return idx in session + + with open(path, 'r') as f: + for line in f: + line = line.strip() + if len(line) > 0: + js = json.loads(line) + + _type = js['type'] + if _type == 'session': + session_idx = js['session'] + ignoring = not valid(session_idx) + + if not ignoring: + ljs = LogEntry(js) + if _type == 'session': + js['_s'] = ljs + else: + js['_s'] =log['session'][-1] + log[_type].append(ljs) + total_log.append(ljs) + + name = os.path.basename(path) + if session is not None: + name += ' (Session %s)' % session + + self.logs.append(log) + self.total_logs.append(total_log) + self.log_names.append(name) + + def query(self, x:Union[str, list], entry_type:str=None, x_idx:int=None, log_idx:int=None) -> list: + """ + Given a query string (can be already decoded for faster computation), query the entire log + and return all values found by that query. If both log_idx and x_idx is None, this will be + a list of lists in the form [log_idx][result_idx]. If x_idx is not None, then the result + will be a list of [log_idx]. If both are not none, the return value will be a single query + return value. With entry_type=None, this will search the entire log. + """ + + if type(x) is not list: + x = self._decode(x) + + res = [] + + for idx in (range(len(self.logs)) if log_idx is None else [log_idx]): + candidates = [] + log = self.total_logs[idx] if entry_type is None else self.logs[idx][entry_type] + + for entry in log: + candidate = self._follow(entry, x) + if candidate is not None: + candidates.append(candidate) + + if x_idx is not None: + candidates = candidates[x_idx] + res.append(candidates) + + if log_idx is not None: + res = res[0] + return res + + def check(self, entry_type:str, x:str): + """ Checks the log for the valid keys for this input. """ + keys = set() + x = self._decode(x) + + for log in self.logs: + for datum in log[entry_type]: + res = self._follow(datum, x) + + if type(res) == dict: + for key in res.keys(): + keys.add(key) + elif type(res) == list: + keys.add('< %d' % len(res)) + + return list(keys) + + def plot(self, entry_type:str, x:str, y:str, smoothness:int=0): + """ Plot sequential log data. """ + + query_x = self._decode(x) + query_y = self._decode(y) + + for idx, (log, name) in enumerate(zip(self.logs, self.log_names)): + log = log[entry_type] + + if smoothness > 1: + avg = MovingAverage(smoothness) + + _x = [] + _y = [] + + for datum in log: + val_x = self._follow(datum, query_x) + val_y = self._follow(datum, query_y) + + if val_x is not None and val_y is not None: + if smoothness > 1: + avg.append(val_y) + val_y = avg.get_avg() + + if len(avg) < smoothness // 10: + continue + + _x.append(val_x) + _y.append(val_y) + + plt.plot(_x, _y, color=self._color(idx), label=name) + + plt.title(y.replace('x.', entry_type + '.')) + plt.legend() + plt.grid(linestyle=':', linewidth=0.5) + plt.show() + + def bar(self, entry_type:str, x:str, labels:list=None, diff:bool=False, x_idx:int=-1): + """ Plot a bar chart. The result of x should be list or dictionary. """ + + query = self._decode(x) + + data_points = [] + + for idx, (log, name) in enumerate(zip(self.logs, self.log_names)): + log = log[entry_type] + + candidates = [] + + for entry in log: + test = self._follow(entry, query) + + if type(test) == dict: + candidates.append(test) + elif type(test) == list: + candidates.append({idx: v for idx, v in enumerate(test)}) + + if len(candidates) > 0: + data_points.append((name, candidates[x_idx])) + + if len(data_points) == 0: + print('Warning: Nothing to show in bar chart!') + return + + names = [x[0] for x in data_points] + data_points = [x[1] for x in data_points] + + # Construct the labels for the data + if labels is not None: + data_labels = labels + else: + data_labels = set() + for datum in data_points: + for k in datum: + data_labels.add(k) + + data_labels = list(data_labels) + data_labels.sort() + + + data_values = [[(datum[k] if k in datum else None) for k in data_labels] for datum in data_points] + + if diff: + for idx in reversed(range(len(data_values))): + for jdx in range(len(data_labels)): + if data_values[0][jdx] is None or data_values[idx][jdx] is None: + data_values[idx][jdx] = None + else: + data_values[idx][jdx] -= data_values[0][jdx] + + + series_labels = names + + # Plot the graph now + num_bars = len(series_labels) + bar_width = 1 / (num_bars + 1) + + # Set position of bar on X axis + positions = [np.arange(len(data_labels))] + for _ in range(1, num_bars): + positions.append([x + bar_width for x in positions[-1]]) + + # Make the plot + for idx, (series, data, pos) in enumerate(zip(series_labels, data_values, positions)): + plt.bar(pos, data, color=self._color(idx), width=bar_width, edgecolor='white', label=series) + + # Add xticks on the middle of the group bars + plt.title(x.replace('x.', entry_type + '.') + (' diff' if diff else '')) + plt.xticks([r + bar_width for r in range(len(data_labels))], data_labels) + + # Create legend & Show graphic + plt.legend() + plt.show() + + + + def elapsed_time(self, cond1:str='', cond2:str='', legible:bool=True) -> list: + """ + Returns the elapsed time between two entries based on the given conditionals. + If a query isn't specified, the first / last entry will be used. The first query + uses the first value and the second query uses the last value in the results. + + Setting legible to true returns human-readable results, while false returns seconds. + """ + q1 = 'x.time; ' + cond1 + q2 = 'x.time; ' + cond2 + + x1 = self.query(q1, x_idx=0) + x2 = self.query(q2, x_idx=-1) + + diff = (lambda x: str(datetime.timedelta(seconds=x)).split('.')[0]) if legible else lambda x: x + + return [diff(b - a) for a, b in zip(x1, x2)] + + + + + + + + + + + +if __name__ == '__main__': + if len(sys.argv) < 4+1: + print('Usage: python utils/logger.py ') + exit() + + vis = LogVisualizer() + vis.add(sys.argv[1]) + vis.plot(sys.argv[2], sys.argv[3], sys.argv[4]) diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/utils/nvinfo.py b/PyTorch/contrib/cv/detection/YOLACT_plus/utils/nvinfo.py index 689abc140c4be56e23c044208bcfb7cb1a5e9099..62052d26838ded8ec18b82e484fa7ec05b9a2743 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/utils/nvinfo.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/utils/nvinfo.py @@ -1,77 +1,77 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -# My version of nvgpu because nvgpu didn't have all the information I was looking for. -import re -import subprocess -import shutil -import os - -def gpu_info() -> list: - """ - Returns a dictionary of stats mined from nvidia-smi for each gpu in a list. - Adapted from nvgpu: https://pypi.org/project/nvgpu/, but mine has more info. - """ - gpus = [line for line in _run_cmd(['nvidia-smi', '-L']) if line] - gpu_infos = [re.match('GPU ([0-9]+): ([^(]+) \(UUID: ([^)]+)\)', gpu).groups() for gpu in gpus] - gpu_infos = [dict(zip(['idx', 'name', 'uuid'], info)) for info in gpu_infos] - gpu_count = len(gpus) - - lines = _run_cmd(['nvidia-smi']) - selected_lines = lines[7:7 + 3 * gpu_count] - for i in range(gpu_count): - mem_used, mem_total = [int(m.strip().replace('MiB', '')) for m in - selected_lines[3 * i + 1].split('|')[2].strip().split('/')] - - pw_tmp_info, mem_info, util_info = [x.strip() for x in selected_lines[3 * i + 1].split('|')[1:-1]] - - pw_tmp_info = [x[:-1] for x in pw_tmp_info.split(' ') if len(x) > 0] - fan_speed, temperature, pwr_used, pwr_cap = [int(pw_tmp_info[i]) for i in (0, 1, 3, 5)] - gpu_infos[i]['fan_spd' ] = fan_speed - gpu_infos[i]['temp' ] = temperature - gpu_infos[i]['pwr_used'] = pwr_used - gpu_infos[i]['pwr_cap' ] = pwr_cap - - mem_used, mem_total = [int(x) for x in mem_info.replace('MiB', '').split(' / ')] - gpu_infos[i]['mem_used' ] = mem_used - gpu_infos[i]['mem_total'] = mem_total - - utilization = int(util_info.split(' ')[0][:-1]) - gpu_infos[i]['util'] = utilization - - gpu_infos[i]['idx'] = int(gpu_infos[i]['idx']) - - return gpu_infos - -def nvsmi_available() -> bool: - """ Returns whether or not nvidia-smi is present in this system's PATH. """ - return shutil.which('nvidia-smi') is not None - - -def visible_gpus() -> list: - """ Returns a list of the indexes of all the gpus visible to pytorch. """ - - if 'CUDA_VISIBLE_DEVICES' not in os.environ: - return list(range(len(gpu_info()))) - else: - return [int(x.strip()) for x in os.environ['CUDA_VISIBLE_DEVICES'].split(',')] - - - - -def _run_cmd(cmd:list) -> list: - """ Runs a command and returns a list of output lines. """ - output = subprocess.check_output(cmd) - output = output.decode('UTF-8') +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# My version of nvgpu because nvgpu didn't have all the information I was looking for. +import re +import subprocess +import shutil +import os + +def gpu_info() -> list: + """ + Returns a dictionary of stats mined from nvidia-smi for each gpu in a list. + Adapted from nvgpu: https://pypi.org/project/nvgpu/, but mine has more info. + """ + gpus = [line for line in _run_cmd(['nvidia-smi', '-L']) if line] + gpu_infos = [re.match('GPU ([0-9]+): ([^(]+) \(UUID: ([^)]+)\)', gpu).groups() for gpu in gpus] + gpu_infos = [dict(zip(['idx', 'name', 'uuid'], info)) for info in gpu_infos] + gpu_count = len(gpus) + + lines = _run_cmd(['nvidia-smi']) + selected_lines = lines[7:7 + 3 * gpu_count] + for i in range(gpu_count): + mem_used, mem_total = [int(m.strip().replace('MiB', '')) for m in + selected_lines[3 * i + 1].split('|')[2].strip().split('/')] + + pw_tmp_info, mem_info, util_info = [x.strip() for x in selected_lines[3 * i + 1].split('|')[1:-1]] + + pw_tmp_info = [x[:-1] for x in pw_tmp_info.split(' ') if len(x) > 0] + fan_speed, temperature, pwr_used, pwr_cap = [int(pw_tmp_info[i]) for i in (0, 1, 3, 5)] + gpu_infos[i]['fan_spd' ] = fan_speed + gpu_infos[i]['temp' ] = temperature + gpu_infos[i]['pwr_used'] = pwr_used + gpu_infos[i]['pwr_cap' ] = pwr_cap + + mem_used, mem_total = [int(x) for x in mem_info.replace('MiB', '').split(' / ')] + gpu_infos[i]['mem_used' ] = mem_used + gpu_infos[i]['mem_total'] = mem_total + + utilization = int(util_info.split(' ')[0][:-1]) + gpu_infos[i]['util'] = utilization + + gpu_infos[i]['idx'] = int(gpu_infos[i]['idx']) + + return gpu_infos + +def nvsmi_available() -> bool: + """ Returns whether or not nvidia-smi is present in this system's PATH. """ + return shutil.which('nvidia-smi') is not None + + +def visible_gpus() -> list: + """ Returns a list of the indexes of all the gpus visible to pytorch. """ + + if 'CUDA_VISIBLE_DEVICES' not in os.environ: + return list(range(len(gpu_info()))) + else: + return [int(x.strip()) for x in os.environ['CUDA_VISIBLE_DEVICES'].split(',')] + + + + +def _run_cmd(cmd:list) -> list: + """ Runs a command and returns a list of output lines. """ + output = subprocess.check_output(cmd) + output = output.decode('UTF-8') return output.split('\n') \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/utils/timer.py b/PyTorch/contrib/cv/detection/YOLACT_plus/utils/timer.py index f5f4404a81b5b364c4fb19ccc7a7951a6cc8b56c..2323e97e471c9b3a1fdfe3b90a578bbe35469d09 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/utils/timer.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/utils/timer.py @@ -1,145 +1,145 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import time -from collections import defaultdict - -_total_times = defaultdict(lambda: 0) -_start_times = defaultdict(lambda: -1) -_disabled_names = set() -_timer_stack = [] -_running_timer = None -_disable_all = False - -def disable_all(): - global _disable_all - _disable_all = True - -def enable_all(): - global _disable_all - _disable_all = False - -def disable(fn_name): - """ Disables the given function name fom being considered for the average or outputted in print_stats. """ - _disabled_names.add(fn_name) - -def enable(fn_name): - """ Enables function names disabled by disable. """ - _disabled_names.remove(fn_name) - -def reset(): - """ Resets the current timer. Call this at the start of an iteration. """ - global _running_timer - _total_times.clear() - _start_times.clear() - _timer_stack.clear() - _running_timer = None - -def start(fn_name, use_stack=True): - """ - Start timing the specific function. - Note: If use_stack is True, only one timer can be active at a time. - Once you stop this timer, the previous one will start again. - """ - global _running_timer, _disable_all - - if _disable_all: - return - - if use_stack: - if _running_timer is not None: - stop(_running_timer, use_stack=False) - _timer_stack.append(_running_timer) - start(fn_name, use_stack=False) - _running_timer = fn_name - else: - _start_times[fn_name] = time.perf_counter() - -def stop(fn_name=None, use_stack=True): - """ - If use_stack is True, this will stop the currently running timer and restore - the previous timer on the stack if that exists. Note if use_stack is True, - fn_name will be ignored. - - If use_stack is False, this will just stop timing the timer fn_name. - """ - global _running_timer, _disable_all - - if _disable_all: - return - - if use_stack: - if _running_timer is not None: - stop(_running_timer, use_stack=False) - if len(_timer_stack) > 0: - _running_timer = _timer_stack.pop() - start(_running_timer, use_stack=False) - else: - _running_timer = None - else: - print('Warning: timer stopped with no timer running!') - else: - if _start_times[fn_name] > -1: - _total_times[fn_name] += time.perf_counter() - _start_times[fn_name] - else: - print('Warning: timer for %s stopped before starting!' % fn_name) - - -def print_stats(): - """ Prints the current timing information into a table. """ - print() - - all_fn_names = [k for k in _total_times.keys() if k not in _disabled_names] - - max_name_width = max([len(k) for k in all_fn_names] + [4]) - if max_name_width % 2 == 1: max_name_width += 1 - format_str = ' {:>%d} | {:>10.4f} ' % max_name_width - - header = (' {:^%d} | {:^10} ' % max_name_width).format('Name', 'Time (ms)') - print(header) - - sep_idx = header.find('|') - sep_text = ('-' * sep_idx) + '+' + '-' * (len(header)-sep_idx-1) - print(sep_text) - - for name in all_fn_names: - print(format_str.format(name, _total_times[name]*1000)) - - print(sep_text) - print(format_str.format('Total', total_time()*1000)) - print() - -def total_time(): - """ Returns the total amount accumulated across all functions in seconds. """ - return sum([elapsed_time for name, elapsed_time in _total_times.items() if name not in _disabled_names]) - - -class env(): - """ - A class that lets you go: - with timer.env(fn_name): - # (...) - That automatically manages a timer start and stop for you. - """ - - def __init__(self, fn_name, use_stack=True): - self.fn_name = fn_name - self.use_stack = use_stack - - def __enter__(self): - start(self.fn_name, use_stack=self.use_stack) - - def __exit__(self, e, ev, t): - stop(self.fn_name, use_stack=self.use_stack) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import time +from collections import defaultdict + +_total_times = defaultdict(lambda: 0) +_start_times = defaultdict(lambda: -1) +_disabled_names = set() +_timer_stack = [] +_running_timer = None +_disable_all = False + +def disable_all(): + global _disable_all + _disable_all = True + +def enable_all(): + global _disable_all + _disable_all = False + +def disable(fn_name): + """ Disables the given function name fom being considered for the average or outputted in print_stats. """ + _disabled_names.add(fn_name) + +def enable(fn_name): + """ Enables function names disabled by disable. """ + _disabled_names.remove(fn_name) + +def reset(): + """ Resets the current timer. Call this at the start of an iteration. """ + global _running_timer + _total_times.clear() + _start_times.clear() + _timer_stack.clear() + _running_timer = None + +def start(fn_name, use_stack=True): + """ + Start timing the specific function. + Note: If use_stack is True, only one timer can be active at a time. + Once you stop this timer, the previous one will start again. + """ + global _running_timer, _disable_all + + if _disable_all: + return + + if use_stack: + if _running_timer is not None: + stop(_running_timer, use_stack=False) + _timer_stack.append(_running_timer) + start(fn_name, use_stack=False) + _running_timer = fn_name + else: + _start_times[fn_name] = time.perf_counter() + +def stop(fn_name=None, use_stack=True): + """ + If use_stack is True, this will stop the currently running timer and restore + the previous timer on the stack if that exists. Note if use_stack is True, + fn_name will be ignored. + + If use_stack is False, this will just stop timing the timer fn_name. + """ + global _running_timer, _disable_all + + if _disable_all: + return + + if use_stack: + if _running_timer is not None: + stop(_running_timer, use_stack=False) + if len(_timer_stack) > 0: + _running_timer = _timer_stack.pop() + start(_running_timer, use_stack=False) + else: + _running_timer = None + else: + print('Warning: timer stopped with no timer running!') + else: + if _start_times[fn_name] > -1: + _total_times[fn_name] += time.perf_counter() - _start_times[fn_name] + else: + print('Warning: timer for %s stopped before starting!' % fn_name) + + +def print_stats(): + """ Prints the current timing information into a table. """ + print() + + all_fn_names = [k for k in _total_times.keys() if k not in _disabled_names] + + max_name_width = max([len(k) for k in all_fn_names] + [4]) + if max_name_width % 2 == 1: max_name_width += 1 + format_str = ' {:>%d} | {:>10.4f} ' % max_name_width + + header = (' {:^%d} | {:^10} ' % max_name_width).format('Name', 'Time (ms)') + print(header) + + sep_idx = header.find('|') + sep_text = ('-' * sep_idx) + '+' + '-' * (len(header)-sep_idx-1) + print(sep_text) + + for name in all_fn_names: + print(format_str.format(name, _total_times[name]*1000)) + + print(sep_text) + print(format_str.format('Total', total_time()*1000)) + print() + +def total_time(): + """ Returns the total amount accumulated across all functions in seconds. """ + return sum([elapsed_time for name, elapsed_time in _total_times.items() if name not in _disabled_names]) + + +class env(): + """ + A class that lets you go: + with timer.env(fn_name): + # (...) + That automatically manages a timer start and stop for you. + """ + + def __init__(self, fn_name, use_stack=True): + self.fn_name = fn_name + self.use_stack = use_stack + + def __enter__(self): + start(self.fn_name, use_stack=self.use_stack) + + def __exit__(self, e, ev, t): + stop(self.fn_name, use_stack=self.use_stack) + diff --git a/PyTorch/contrib/cv/detection/YOLACT_plus/yolact.py b/PyTorch/contrib/cv/detection/YOLACT_plus/yolact.py index a59a15bdf4889c6e0841b243bf1ad7a6a7bf1ccd..59490549ed6f4eefee04cf947706bc1bc3eaf26c 100644 --- a/PyTorch/contrib/cv/detection/YOLACT_plus/yolact.py +++ b/PyTorch/contrib/cv/detection/YOLACT_plus/yolact.py @@ -1,739 +1,739 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch, torchvision -import torch.nn as nn -import torch.nn.functional as F -from torchvision.models.resnet import Bottleneck -import numpy as np -from itertools import product -from math import sqrt -from typing import List -from collections import defaultdict - -from data.config import cfg, mask_type -from layers import Detect -from layers.interpolate import InterpolateModule -from backbone import construct_backbone - -import torch.backends.cudnn as cudnn -from utils import timer -from utils.functions import MovingAverage, make_net - -# This is required for Pytorch 1.0.1 on Windows to initialize Cuda on some driver versions. -# See the bug report here: https://github.com/pytorch/pytorch/issues/17108 -#torch.cuda.current_device() - -# As of March 10, 2019, Pytorch DataParallel still doesn't support JIT Script Modules -use_jit = False -if not use_jit: - print('Multiple GPUs detected! Turning off JIT.') - -ScriptModuleWrapper = torch.jit.ScriptModule if use_jit else nn.Module -script_method_wrapper = torch.jit.script_method if use_jit else lambda fn, _rcn=None: fn - - - -class Concat(nn.Module): - def __init__(self, nets, extra_params): - super().__init__() - - self.nets = nn.ModuleList(nets) - self.extra_params = extra_params - - def forward(self, x): - # Concat each along the channel dimension - return torch.cat([net(x) for net in self.nets], dim=1, **self.extra_params) - -prior_cache = defaultdict(lambda: None) - -class PredictionModule(nn.Module): - """ - The (c) prediction module adapted from DSSD: - https://arxiv.org/pdf/1701.06659.pdf - - Note that this is slightly different to the module in the paper - because the Bottleneck block actually has a 3x3 convolution in - the middle instead of a 1x1 convolution. Though, I really can't - be arsed to implement it myself, and, who knows, this might be - better. - - Args: - - in_channels: The input feature size. - - out_channels: The output feature size (must be a multiple of 4). - - aspect_ratios: A list of lists of priorbox aspect ratios (one list per scale). - - scales: A list of priorbox scales relative to this layer's convsize. - For instance: If this layer has convouts of size 30x30 for - an image of size 600x600, the 'default' (scale - of 1) for this layer would produce bounding - boxes with an area of 20x20px. If the scale is - .5 on the other hand, this layer would consider - bounding boxes with area 10x10px, etc. - - parent: If parent is a PredictionModule, this module will use all the layers - from parent instead of from this module. - """ - - def __init__(self, in_channels, out_channels=1024, aspect_ratios=[[1]], scales=[1], parent=None, index=0): - super().__init__() - - self.num_classes = cfg.num_classes - self.mask_dim = cfg.mask_dim # Defined by Yolact - self.num_priors = sum(len(x)*len(scales) for x in aspect_ratios) - self.parent = [parent] # Don't include this in the state dict - self.index = index - self.num_heads = cfg.num_heads # Defined by Yolact - - if cfg.mask_proto_split_prototypes_by_head and cfg.mask_type == mask_type.lincomb: - self.mask_dim = self.mask_dim // self.num_heads - - if cfg.mask_proto_prototypes_as_features: - in_channels += self.mask_dim - - if parent is None: - if cfg.extra_head_net is None: - out_channels = in_channels - else: - self.upfeature, out_channels = make_net(in_channels, cfg.extra_head_net) - - if cfg.use_prediction_module: - self.block = Bottleneck(out_channels, out_channels // 4) - self.conv = nn.Conv2d(out_channels, out_channels, kernel_size=1, bias=True) - self.bn = nn.BatchNorm2d(out_channels) - - self.bbox_layer = nn.Conv2d(out_channels, self.num_priors * 4, **cfg.head_layer_params) - self.conf_layer = nn.Conv2d(out_channels, self.num_priors * self.num_classes, **cfg.head_layer_params) - self.mask_layer = nn.Conv2d(out_channels, self.num_priors * self.mask_dim, **cfg.head_layer_params) - - if cfg.use_mask_scoring: - self.score_layer = nn.Conv2d(out_channels, self.num_priors, **cfg.head_layer_params) - - if cfg.use_instance_coeff: - self.inst_layer = nn.Conv2d(out_channels, self.num_priors * cfg.num_instance_coeffs, **cfg.head_layer_params) - - # What is this ugly lambda doing in the middle of all this clean prediction module code? - def make_extra(num_layers): - if num_layers == 0: - return lambda x: x - else: - # Looks more complicated than it is. This just creates an array of num_layers alternating conv-relu - return nn.Sequential(*sum([[ - nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=1), - nn.ReLU(inplace=True) - ] for _ in range(num_layers)], [])) - - self.bbox_extra, self.conf_extra, self.mask_extra = [make_extra(x) for x in cfg.extra_layers] - - if cfg.mask_type == mask_type.lincomb and cfg.mask_proto_coeff_gate: - self.gate_layer = nn.Conv2d(out_channels, self.num_priors * self.mask_dim, kernel_size=3, padding=1) - - self.aspect_ratios = aspect_ratios - self.scales = scales - - self.priors = None - self.last_conv_size = None - self.last_img_size = None - - def forward(self, x): - """ - Args: - - x: The convOut from a layer in the backbone network - Size: [batch_size, in_channels, conv_h, conv_w]) - - Returns a tuple (bbox_coords, class_confs, mask_output, prior_boxes) with sizes - - bbox_coords: [batch_size, conv_h*conv_w*num_priors, 4] - - class_confs: [batch_size, conv_h*conv_w*num_priors, num_classes] - - mask_output: [batch_size, conv_h*conv_w*num_priors, mask_dim] - - prior_boxes: [conv_h*conv_w*num_priors, 4] - """ - # In case we want to use another module's layers - src = self if self.parent[0] is None else self.parent[0] - - conv_h = x.size(2) - conv_w = x.size(3) - - if cfg.extra_head_net is not None: - x = src.upfeature(x) - - if cfg.use_prediction_module: - # The two branches of PM design (c) - a = src.block(x) - - b = src.conv(x) - b = src.bn(b) - b = F.relu(b) - - # TODO: Possibly switch this out for a product - x = a + b - - bbox_x = src.bbox_extra(x) - conf_x = src.conf_extra(x) - mask_x = src.mask_extra(x) - - bbox = src.bbox_layer(bbox_x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, 4) - conf = src.conf_layer(conf_x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, self.num_classes) - - if cfg.eval_mask_branch: - mask = src.mask_layer(mask_x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, self.mask_dim) - else: - mask = torch.zeros(x.size(0), bbox.size(1), self.mask_dim, device=bbox.device) - - if cfg.use_mask_scoring: - score = src.score_layer(x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, 1) - - if cfg.use_instance_coeff: - inst = src.inst_layer(x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, cfg.num_instance_coeffs) - - # See box_utils.decode for an explanation of this - if cfg.use_yolo_regressors: - bbox[:, :, :2] = torch.sigmoid(bbox[:, :, :2]) - 0.5 - bbox[:, :, 0] /= conv_w - bbox[:, :, 1] /= conv_h - - if cfg.eval_mask_branch: - if cfg.mask_type == mask_type.direct: - mask = torch.sigmoid(mask) - elif cfg.mask_type == mask_type.lincomb: - mask = cfg.mask_proto_coeff_activation(mask) - - if cfg.mask_proto_coeff_gate: - gate = src.gate_layer(x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, self.mask_dim) - mask = mask * torch.sigmoid(gate) - - if cfg.mask_proto_split_prototypes_by_head and cfg.mask_type == mask_type.lincomb: - mask = F.pad(mask, (self.index * self.mask_dim, (self.num_heads - self.index - 1) * self.mask_dim), mode='constant', value=0) - - priors = self.make_priors(conv_h, conv_w, x.device) - - preds = { 'loc': bbox, 'conf': conf, 'mask': mask, 'priors': priors } - - if cfg.use_mask_scoring: - preds['score'] = score - - if cfg.use_instance_coeff: - preds['inst'] = inst - - return preds - - def make_priors(self, conv_h, conv_w, device): - """ Note that priors are [x,y,width,height] where (x,y) is the center of the box. """ - global prior_cache - size = (conv_h, conv_w) - - with timer.env('makepriors'): - if self.last_img_size != (cfg._tmp_img_w, cfg._tmp_img_h): - prior_data = [] - - # Iteration order is important (it has to sync up with the convout) - for j, i in product(range(conv_h), range(conv_w)): - # +0.5 because priors are in center-size notation - x = (i + 0.5) / conv_w - y = (j + 0.5) / conv_h - - for ars in self.aspect_ratios: - for scale in self.scales: - for ar in ars: - if not cfg.backbone.preapply_sqrt: - ar = sqrt(ar) - - if cfg.backbone.use_pixel_scales: - w = scale * ar / cfg.max_size - h = scale / ar / cfg.max_size - else: - w = scale * ar / conv_w - h = scale / ar / conv_h - - # This is for backward compatability with a bug where I made everything square by accident - if cfg.backbone.use_square_anchors: - h = w - - prior_data += [x, y, w, h] - - self.priors = torch.Tensor(prior_data).to(device).view(-1, 4).detach() - self.priors.requires_grad = False - self.last_img_size = (cfg._tmp_img_w, cfg._tmp_img_h) - self.last_conv_size = (conv_w, conv_h) - prior_cache[size] = None - elif self.priors.device != device: - # This whole weird situation is so that DataParalell doesn't copy the priors each iteration - if prior_cache[size] is None: - prior_cache[size] = {} - - if device not in prior_cache[size]: - prior_cache[size][device] = self.priors.to(device) - - self.priors = prior_cache[size][device] - - return self.priors - -class FPN(ScriptModuleWrapper): - """ - Implements a general version of the FPN introduced in - https://arxiv.org/pdf/1612.03144.pdf - - Parameters (in cfg.fpn): - - num_features (int): The number of output features in the fpn layers. - - interpolation_mode (str): The mode to pass to F.interpolate. - - num_downsample (int): The number of downsampled layers to add onto the selected layers. - These extra layers are downsampled from the last selected layer. - - Args: - - in_channels (list): For each conv layer you supply in the forward pass, - how many features will it have? - """ - __constants__ = ['interpolation_mode', 'num_downsample', 'use_conv_downsample', 'relu_pred_layers', - 'lat_layers', 'pred_layers', 'downsample_layers', 'relu_downsample_layers'] - - def __init__(self, in_channels): - super().__init__() - - self.lat_layers = nn.ModuleList([ - nn.Conv2d(x, cfg.fpn.num_features, kernel_size=1) - for x in reversed(in_channels) - ]) - - # This is here for backwards compatability - padding = 1 if cfg.fpn.pad else 0 - self.pred_layers = nn.ModuleList([ - nn.Conv2d(cfg.fpn.num_features, cfg.fpn.num_features, kernel_size=3, padding=padding) - for _ in in_channels - ]) - - if cfg.fpn.use_conv_downsample: - self.downsample_layers = nn.ModuleList([ - nn.Conv2d(cfg.fpn.num_features, cfg.fpn.num_features, kernel_size=3, padding=1, stride=2) - for _ in range(cfg.fpn.num_downsample) - ]) - - self.interpolation_mode = cfg.fpn.interpolation_mode - self.num_downsample = cfg.fpn.num_downsample - self.use_conv_downsample = cfg.fpn.use_conv_downsample - self.relu_downsample_layers = cfg.fpn.relu_downsample_layers - self.relu_pred_layers = cfg.fpn.relu_pred_layers - - @script_method_wrapper - def forward(self, convouts:List[torch.Tensor]): - """ - Args: - - convouts (list): A list of convouts for the corresponding layers in in_channels. - Returns: - - A list of FPN convouts in the same order as x with extra downsample layers if requested. - """ - - out = [] - x = torch.zeros(1, device=convouts[0].device) - for i in range(len(convouts)): - out.append(x) - - # For backward compatability, the conv layers are stored in reverse but the input and output is - # given in the correct order. Thus, use j=-i-1 for the input and output and i for the conv layers. - j = len(convouts) - for lat_layer in self.lat_layers: - j -= 1 - - if j < len(convouts) - 1: - _, _, h, w = convouts[j].size() - x = F.interpolate(x, size=(h, w), mode=self.interpolation_mode, align_corners=False) - - x = x + lat_layer(convouts[j]) - out[j] = x - - # This janky second loop is here because TorchScript. - j = len(convouts) - for pred_layer in self.pred_layers: - j -= 1 - out[j] = pred_layer(out[j]) - - if self.relu_pred_layers: - F.relu(out[j], inplace=True) - - cur_idx = len(out) - - # In the original paper, this takes care of P6 - if self.use_conv_downsample: - for downsample_layer in self.downsample_layers: - out.append(downsample_layer(out[-1])) - else: - for idx in range(self.num_downsample): - # Note: this is an untested alternative to out.append(out[-1][:, :, ::2, ::2]). Thanks TorchScript. - out.append(nn.functional.max_pool2d(out[-1], 1, stride=2)) - - if self.relu_downsample_layers: - for idx in range(len(out) - cur_idx): - out[idx] = F.relu(out[idx + cur_idx], inplace=False) - - return out - -class FastMaskIoUNet(ScriptModuleWrapper): - - def __init__(self): - super().__init__() - input_channels = 1 - last_layer = [(cfg.num_classes-1, 1, {})] - self.maskiou_net, _ = make_net(input_channels, cfg.maskiou_net + last_layer, include_last_relu=True) - - def forward(self, x): - x = self.maskiou_net(x) - maskiou_p = F.max_pool2d(x, kernel_size=x.size()[2:]).squeeze(-1).squeeze(-1) - - return maskiou_p - - - -class Yolact(nn.Module): - """ - - - ██╗ ██╗ ██████╗ ██╗ █████╗ ██████╗████████╗ - ╚██╗ ██╔╝██╔═══██╗██║ ██╔══██╗██╔════╝╚══██╔══╝ - ╚████╔╝ ██║ ██║██║ ███████║██║ ██║ - ╚██╔╝ ██║ ██║██║ ██╔══██║██║ ██║ - ██║ ╚██████╔╝███████╗██║ ██║╚██████╗ ██║ - ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ - - - You can set the arguments by changing them in the backbone config object in config.py. - - Parameters (in cfg.backbone): - - selected_layers: The indices of the conv layers to use for prediction. - - pred_scales: A list with len(selected_layers) containing tuples of scales (see PredictionModule) - - pred_aspect_ratios: A list of lists of aspect ratios with len(selected_layers) (see PredictionModule) - """ - - def __init__(self): - super().__init__() - - self.backbone = construct_backbone(cfg.backbone) #backbone: resnetbackbone. backbone_modules:{list:104}. bn1:{BatchNorm2d} - - if cfg.freeze_bn: # it's true - self.freeze_bn() - - # Compute mask_dim here and add it back to the config. Make sure Yolact's constructor is called early! - if cfg.mask_type == mask_type.direct: - cfg.mask_dim = cfg.mask_size**2 - elif cfg.mask_type == mask_type.lincomb: # the module will execute this branch - if cfg.mask_proto_use_grid: - self.grid = torch.Tensor(np.load(cfg.mask_proto_grid_file)) - self.num_grids = self.grid.size(0) - else: # the module will execute this branch - self.num_grids = 0 - - self.proto_src = cfg.mask_proto_src - - if self.proto_src is None: in_channels = 3 - elif cfg.fpn is not None: in_channels = cfg.fpn.num_features - else: in_channels = self.backbone.channels[self.proto_src] - in_channels += self.num_grids - #in_channels will be 256 - # The include_last_relu=false here is because we might want to change it to another function - self.proto_net, cfg.mask_dim = make_net(in_channels, cfg.mask_proto_net, include_last_relu=False) - - if cfg.mask_proto_bias: - cfg.mask_dim += 1 - - - self.selected_layers = cfg.backbone.selected_layers - src_channels = self.backbone.channels - - if cfg.use_maskiou: #false - self.maskiou_net = FastMaskIoUNet() - - if cfg.fpn is not None: #true - # Some hacky rewiring to accomodate the FPN - self.fpn = FPN([src_channels[i] for i in self.selected_layers]) - self.selected_layers = list(range(len(self.selected_layers) + cfg.fpn.num_downsample)) - src_channels = [cfg.fpn.num_features] * len(self.selected_layers) - - - self.prediction_layers = nn.ModuleList() - cfg.num_heads = len(self.selected_layers) - - for idx, layer_idx in enumerate(self.selected_layers): - # If we're sharing prediction module weights, have every module's parent be the first one - parent = None - if cfg.share_prediction_module and idx > 0: #cfg.share_prediction_module is True - parent = self.prediction_layers[0] - - pred = PredictionModule(src_channels[layer_idx], src_channels[layer_idx], - aspect_ratios = cfg.backbone.pred_aspect_ratios[idx], - scales = cfg.backbone.pred_scales[idx], - parent = parent, - index = idx) - self.prediction_layers.append(pred) - - # Extra parameters for the extra losses - if cfg.use_class_existence_loss: #false - # This comes from the smallest layer selected - # Also note that cfg.num_classes includes background - self.class_existence_fc = nn.Linear(src_channels[-1], cfg.num_classes - 1) - - if cfg.use_semantic_segmentation_loss: #true - self.semantic_seg_conv = nn.Conv2d(src_channels[0], cfg.num_classes-1, kernel_size=1) - - # For use in evaluation - self.detect = Detect(cfg.num_classes, bkg_label=0, top_k=cfg.nms_top_k, - conf_thresh=cfg.nms_conf_thresh, nms_thresh=cfg.nms_thresh) - - def save_weights(self, path): - """ Saves the model's weights using compression because the file sizes were getting too big. """ - torch.save(self.state_dict(), path) - - def load_weights(self, path): - """ Loads weights from a compressed save file. """ - state_dict = torch.load(path, map_location=torch.device('cpu')) - - # For backward compatability, remove these (the new variable is called layers) - for key in list(state_dict.keys()): - if key.startswith('backbone.layer') and not key.startswith('backbone.layers'): - del state_dict[key] - - # Also for backward compatibility with v1.0 weights, do this check - if key.startswith('fpn.downsample_layers.'): - if cfg.fpn is not None and int(key.split('.')[2]) >= cfg.fpn.num_downsample: - del state_dict[key] - self.load_state_dict(state_dict) - - def init_weights(self, backbone_path): - """ Initialize weights for training. """ - # Initialize the backbone with the pretrained weights. - self.backbone.init_backbone(backbone_path) - - conv_constants = getattr(nn.Conv2d(1, 1, 1), '__constants__') - - # Quick lambda to test if one list contains the other - def all_in(x, y): - for _x in x: - if _x not in y: - return False - return True - - # Initialize the rest of the conv layers with xavier - for name, module in self.named_modules(): - # See issue #127 for why we need such a complicated condition if the module is a WeakScriptModuleProxy - # Broke in 1.3 (see issue #175), WeakScriptModuleProxy was turned into just ScriptModule. - # Broke in 1.4 (see issue #292), where RecursiveScriptModule is the new star of the show. - # Note that this might break with future pytorch updates, so let me know if it does - is_script_conv = False - if 'Script' in type(module).__name__: - # 1.4 workaround: now there's an original_name member so just use that - if hasattr(module, 'original_name'): - is_script_conv = 'Conv' in module.original_name - # 1.3 workaround: check if this has the same constants as a conv module - else: - is_script_conv = ( - all_in(module.__dict__['_constants_set'], conv_constants) - and all_in(conv_constants, module.__dict__['_constants_set'])) - - is_conv_layer = isinstance(module, nn.Conv2d) or is_script_conv - - if is_conv_layer and module not in self.backbone.backbone_modules: - nn.init.xavier_uniform_(module.weight.data) - - if module.bias is not None: - if cfg.use_focal_loss and 'conf_layer' in name: - if not cfg.use_sigmoid_focal_loss: - # Initialize the last layer as in the focal loss paper. - # Because we use softmax and not sigmoid, I had to derive an alternate expression - # on a notecard. Define pi to be the probability of outputting a foreground detection. - # Then let z = sum(exp(x)) - exp(x_0). Finally let c be the number of foreground classes. - # Chugging through the math, this gives us - # x_0 = log(z * (1 - pi) / pi) where 0 is the background class - # x_i = log(z / c) for all i > 0 - # For simplicity (and because we have a degree of freedom here), set z = 1. Then we have - # x_0 = log((1 - pi) / pi) note: don't split up the log for numerical stability - # x_i = -log(c) for all i > 0 - module.bias.data[0] = np.log((1 - cfg.focal_loss_init_pi) / cfg.focal_loss_init_pi) - module.bias.data[1:] = -np.log(module.bias.size(0) - 1) - else: - module.bias.data[0] = -np.log(cfg.focal_loss_init_pi / (1 - cfg.focal_loss_init_pi)) - module.bias.data[1:] = -np.log((1 - cfg.focal_loss_init_pi) / cfg.focal_loss_init_pi) - else: - module.bias.data.zero_() - - def train(self, mode=True): - super().train(mode) - - if cfg.freeze_bn: - self.freeze_bn() - - def freeze_bn(self, enable=False): - """ Adapted from https://discuss.pytorch.org/t/how-to-train-with-frozen-batchnorm/12106/8 """ - for module in self.modules(): - if isinstance(module, nn.BatchNorm2d): - module.train() if enable else module.eval() - - module.weight.requires_grad = enable - module.bias.requires_grad = enable - - def forward(self, x): - """ The input should be of size [batch_size, 3, img_h, img_w] """ - _, _, img_h, img_w = x.size() - cfg._tmp_img_h = img_h - cfg._tmp_img_w = img_w - - with timer.env('backbone'): - outs = self.backbone(x) - - if cfg.fpn is not None: - with timer.env('fpn'): - # Use backbone.selected_layers because we overwrote self.selected_layers - outs = [outs[i] for i in cfg.backbone.selected_layers] - outs = self.fpn(outs) - - proto_out = None - if cfg.mask_type == mask_type.lincomb and cfg.eval_mask_branch: - with timer.env('proto'): - proto_x = x if self.proto_src is None else outs[self.proto_src] - - if self.num_grids > 0: - grids = self.grid.repeat(proto_x.size(0), 1, 1, 1) - proto_x = torch.cat([proto_x, grids], dim=1) - - proto_out = self.proto_net(proto_x) - proto_out = cfg.mask_proto_prototype_activation(proto_out) - - if cfg.mask_proto_prototypes_as_features: - # Clone here because we don't want to permute this, though idk if contiguous makes this unnecessary - proto_downsampled = proto_out.clone() - - if cfg.mask_proto_prototypes_as_features_no_grad: - proto_downsampled = proto_out.detach() - - # Move the features last so the multiplication is easy - proto_out = proto_out.permute(0, 2, 3, 1).contiguous() - - if cfg.mask_proto_bias: - bias_shape = [x for x in proto_out.size()] - bias_shape[-1] = 1 - proto_out = torch.cat([proto_out, torch.ones(*bias_shape)], -1) - - - with timer.env('pred_heads'): - pred_outs = { 'loc': [], 'conf': [], 'mask': [], 'priors': [] } - - if cfg.use_mask_scoring: - pred_outs['score'] = [] - - if cfg.use_instance_coeff: - pred_outs['inst'] = [] - - for idx, pred_layer in zip(self.selected_layers, self.prediction_layers): - pred_x = outs[idx] - - if cfg.mask_type == mask_type.lincomb and cfg.mask_proto_prototypes_as_features: - # Scale the prototypes down to the current prediction layer's size and add it as inputs - proto_downsampled = F.interpolate(proto_downsampled, size=outs[idx].size()[2:], mode='bilinear', align_corners=False) - pred_x = torch.cat([pred_x, proto_downsampled], dim=1) - - # A hack for the way dataparallel works - if cfg.share_prediction_module and pred_layer is not self.prediction_layers[0]: - pred_layer.parent = [self.prediction_layers[0]] - - p = pred_layer(pred_x) - - for k, v in p.items(): - pred_outs[k].append(v) - - for k, v in pred_outs.items(): - pred_outs[k] = torch.cat(v, -2) - - if proto_out is not None: - pred_outs['proto'] = proto_out - - if self.training: - # For the extra loss functions - if cfg.use_class_existence_loss: - pred_outs['classes'] = self.class_existence_fc(outs[-1].mean(dim=(2, 3))) - - if cfg.use_semantic_segmentation_loss: - pred_outs['segm'] = self.semantic_seg_conv(outs[0]) - - return pred_outs - else: - if cfg.use_mask_scoring: - pred_outs['score'] = torch.sigmoid(pred_outs['score']) - - if cfg.use_focal_loss: - if cfg.use_sigmoid_focal_loss: - # Note: even though conf[0] exists, this mode doesn't train it so don't use it - pred_outs['conf'] = torch.sigmoid(pred_outs['conf']) - if cfg.use_mask_scoring: - pred_outs['conf'] *= pred_outs['score'] - elif cfg.use_objectness_score: - # See focal_loss_sigmoid in multibox_loss.py for details - objectness = torch.sigmoid(pred_outs['conf'][:, :, 0]) - pred_outs['conf'][:, :, 1:] = objectness[:, :, None] * F.softmax(pred_outs['conf'][:, :, 1:], -1) - pred_outs['conf'][:, :, 0 ] = 1 - objectness - else: - pred_outs['conf'] = F.softmax(pred_outs['conf'], -1) - else: - - if cfg.use_objectness_score: - objectness = torch.sigmoid(pred_outs['conf'][:, :, 0]) - - pred_outs['conf'][:, :, 1:] = (objectness > 0.10)[..., None] \ - * F.softmax(pred_outs['conf'][:, :, 1:], dim=-1) - - else: - pred_outs['conf'] = F.softmax(pred_outs['conf'], -1) - for i in pred_outs.keys(): - pred_outs[i] = pred_outs[i].cpu() - return self.detect(pred_outs) - - - - -# Some testing code -if __name__ == '__main__': - from utils.functions import init_console - init_console() - - # Use the first argument to set the config if you want - import sys - if len(sys.argv) > 1: - from data.config import set_cfg - set_cfg(sys.argv[1]) - - net = Yolact() - net.train() - net.init_weights(backbone_path='weights/' + cfg.backbone.path) - - # GPU - net = net.cuda() - torch.set_default_tensor_type('torch.cuda.FloatTensor') - - x = torch.zeros((1, 3, cfg.max_size, cfg.max_size)) - y = net(x) - - for p in net.prediction_layers: - print(p.last_conv_size) - - print() - for k, a in y.items(): - print(k + ': ', a.size(), torch.sum(a)) - exit() - - net(x) - # timer.disable('pass2') - avg = MovingAverage() - try: - while True: - timer.reset() - with timer.env('everything else'): - net(x) - avg.add(timer.total_time()) - print('\033[2J') # Moves console cursor to 0,0 - timer.print_stats() - print('Avg fps: %.2f\tAvg ms: %.2f ' % (1/avg.get_avg(), avg.get_avg()*1000)) - except KeyboardInterrupt: - pass +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch, torchvision +import torch.nn as nn +import torch.nn.functional as F +from torchvision.models.resnet import Bottleneck +import numpy as np +from itertools import product +from math import sqrt +from typing import List +from collections import defaultdict + +from data.config import cfg, mask_type +from layers import Detect +from layers.interpolate import InterpolateModule +from backbone import construct_backbone + +import torch.backends.cudnn as cudnn +from utils import timer +from utils.functions import MovingAverage, make_net + +# This is required for Pytorch 1.0.1 on Windows to initialize Cuda on some driver versions. +# See the bug report here: https://github.com/pytorch/pytorch/issues/17108 +#torch.cuda.current_device() + +# As of March 10, 2019, Pytorch DataParallel still doesn't support JIT Script Modules +use_jit = False +if not use_jit: + print('Multiple GPUs detected! Turning off JIT.') + +ScriptModuleWrapper = torch.jit.ScriptModule if use_jit else nn.Module +script_method_wrapper = torch.jit.script_method if use_jit else lambda fn, _rcn=None: fn + + + +class Concat(nn.Module): + def __init__(self, nets, extra_params): + super().__init__() + + self.nets = nn.ModuleList(nets) + self.extra_params = extra_params + + def forward(self, x): + # Concat each along the channel dimension + return torch.cat([net(x) for net in self.nets], dim=1, **self.extra_params) + +prior_cache = defaultdict(lambda: None) + +class PredictionModule(nn.Module): + """ + The (c) prediction module adapted from DSSD: + https://arxiv.org/pdf/1701.06659.pdf + + Note that this is slightly different to the module in the paper + because the Bottleneck block actually has a 3x3 convolution in + the middle instead of a 1x1 convolution. Though, I really can't + be arsed to implement it myself, and, who knows, this might be + better. + + Args: + - in_channels: The input feature size. + - out_channels: The output feature size (must be a multiple of 4). + - aspect_ratios: A list of lists of priorbox aspect ratios (one list per scale). + - scales: A list of priorbox scales relative to this layer's convsize. + For instance: If this layer has convouts of size 30x30 for + an image of size 600x600, the 'default' (scale + of 1) for this layer would produce bounding + boxes with an area of 20x20px. If the scale is + .5 on the other hand, this layer would consider + bounding boxes with area 10x10px, etc. + - parent: If parent is a PredictionModule, this module will use all the layers + from parent instead of from this module. + """ + + def __init__(self, in_channels, out_channels=1024, aspect_ratios=[[1]], scales=[1], parent=None, index=0): + super().__init__() + + self.num_classes = cfg.num_classes + self.mask_dim = cfg.mask_dim # Defined by Yolact + self.num_priors = sum(len(x)*len(scales) for x in aspect_ratios) + self.parent = [parent] # Don't include this in the state dict + self.index = index + self.num_heads = cfg.num_heads # Defined by Yolact + + if cfg.mask_proto_split_prototypes_by_head and cfg.mask_type == mask_type.lincomb: + self.mask_dim = self.mask_dim // self.num_heads + + if cfg.mask_proto_prototypes_as_features: + in_channels += self.mask_dim + + if parent is None: + if cfg.extra_head_net is None: + out_channels = in_channels + else: + self.upfeature, out_channels = make_net(in_channels, cfg.extra_head_net) + + if cfg.use_prediction_module: + self.block = Bottleneck(out_channels, out_channels // 4) + self.conv = nn.Conv2d(out_channels, out_channels, kernel_size=1, bias=True) + self.bn = nn.BatchNorm2d(out_channels) + + self.bbox_layer = nn.Conv2d(out_channels, self.num_priors * 4, **cfg.head_layer_params) + self.conf_layer = nn.Conv2d(out_channels, self.num_priors * self.num_classes, **cfg.head_layer_params) + self.mask_layer = nn.Conv2d(out_channels, self.num_priors * self.mask_dim, **cfg.head_layer_params) + + if cfg.use_mask_scoring: + self.score_layer = nn.Conv2d(out_channels, self.num_priors, **cfg.head_layer_params) + + if cfg.use_instance_coeff: + self.inst_layer = nn.Conv2d(out_channels, self.num_priors * cfg.num_instance_coeffs, **cfg.head_layer_params) + + # What is this ugly lambda doing in the middle of all this clean prediction module code? + def make_extra(num_layers): + if num_layers == 0: + return lambda x: x + else: + # Looks more complicated than it is. This just creates an array of num_layers alternating conv-relu + return nn.Sequential(*sum([[ + nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=1), + nn.ReLU(inplace=True) + ] for _ in range(num_layers)], [])) + + self.bbox_extra, self.conf_extra, self.mask_extra = [make_extra(x) for x in cfg.extra_layers] + + if cfg.mask_type == mask_type.lincomb and cfg.mask_proto_coeff_gate: + self.gate_layer = nn.Conv2d(out_channels, self.num_priors * self.mask_dim, kernel_size=3, padding=1) + + self.aspect_ratios = aspect_ratios + self.scales = scales + + self.priors = None + self.last_conv_size = None + self.last_img_size = None + + def forward(self, x): + """ + Args: + - x: The convOut from a layer in the backbone network + Size: [batch_size, in_channels, conv_h, conv_w]) + + Returns a tuple (bbox_coords, class_confs, mask_output, prior_boxes) with sizes + - bbox_coords: [batch_size, conv_h*conv_w*num_priors, 4] + - class_confs: [batch_size, conv_h*conv_w*num_priors, num_classes] + - mask_output: [batch_size, conv_h*conv_w*num_priors, mask_dim] + - prior_boxes: [conv_h*conv_w*num_priors, 4] + """ + # In case we want to use another module's layers + src = self if self.parent[0] is None else self.parent[0] + + conv_h = x.size(2) + conv_w = x.size(3) + + if cfg.extra_head_net is not None: + x = src.upfeature(x) + + if cfg.use_prediction_module: + # The two branches of PM design (c) + a = src.block(x) + + b = src.conv(x) + b = src.bn(b) + b = F.relu(b) + + # TODO: Possibly switch this out for a product + x = a + b + + bbox_x = src.bbox_extra(x) + conf_x = src.conf_extra(x) + mask_x = src.mask_extra(x) + + bbox = src.bbox_layer(bbox_x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, 4) + conf = src.conf_layer(conf_x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, self.num_classes) + + if cfg.eval_mask_branch: + mask = src.mask_layer(mask_x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, self.mask_dim) + else: + mask = torch.zeros(x.size(0), bbox.size(1), self.mask_dim, device=bbox.device) + + if cfg.use_mask_scoring: + score = src.score_layer(x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, 1) + + if cfg.use_instance_coeff: + inst = src.inst_layer(x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, cfg.num_instance_coeffs) + + # See box_utils.decode for an explanation of this + if cfg.use_yolo_regressors: + bbox[:, :, :2] = torch.sigmoid(bbox[:, :, :2]) - 0.5 + bbox[:, :, 0] /= conv_w + bbox[:, :, 1] /= conv_h + + if cfg.eval_mask_branch: + if cfg.mask_type == mask_type.direct: + mask = torch.sigmoid(mask) + elif cfg.mask_type == mask_type.lincomb: + mask = cfg.mask_proto_coeff_activation(mask) + + if cfg.mask_proto_coeff_gate: + gate = src.gate_layer(x).permute(0, 2, 3, 1).contiguous().view(x.size(0), -1, self.mask_dim) + mask = mask * torch.sigmoid(gate) + + if cfg.mask_proto_split_prototypes_by_head and cfg.mask_type == mask_type.lincomb: + mask = F.pad(mask, (self.index * self.mask_dim, (self.num_heads - self.index - 1) * self.mask_dim), mode='constant', value=0) + + priors = self.make_priors(conv_h, conv_w, x.device) + + preds = { 'loc': bbox, 'conf': conf, 'mask': mask, 'priors': priors } + + if cfg.use_mask_scoring: + preds['score'] = score + + if cfg.use_instance_coeff: + preds['inst'] = inst + + return preds + + def make_priors(self, conv_h, conv_w, device): + """ Note that priors are [x,y,width,height] where (x,y) is the center of the box. """ + global prior_cache + size = (conv_h, conv_w) + + with timer.env('makepriors'): + if self.last_img_size != (cfg._tmp_img_w, cfg._tmp_img_h): + prior_data = [] + + # Iteration order is important (it has to sync up with the convout) + for j, i in product(range(conv_h), range(conv_w)): + # +0.5 because priors are in center-size notation + x = (i + 0.5) / conv_w + y = (j + 0.5) / conv_h + + for ars in self.aspect_ratios: + for scale in self.scales: + for ar in ars: + if not cfg.backbone.preapply_sqrt: + ar = sqrt(ar) + + if cfg.backbone.use_pixel_scales: + w = scale * ar / cfg.max_size + h = scale / ar / cfg.max_size + else: + w = scale * ar / conv_w + h = scale / ar / conv_h + + # This is for backward compatability with a bug where I made everything square by accident + if cfg.backbone.use_square_anchors: + h = w + + prior_data += [x, y, w, h] + + self.priors = torch.Tensor(prior_data).to(device).view(-1, 4).detach() + self.priors.requires_grad = False + self.last_img_size = (cfg._tmp_img_w, cfg._tmp_img_h) + self.last_conv_size = (conv_w, conv_h) + prior_cache[size] = None + elif self.priors.device != device: + # This whole weird situation is so that DataParalell doesn't copy the priors each iteration + if prior_cache[size] is None: + prior_cache[size] = {} + + if device not in prior_cache[size]: + prior_cache[size][device] = self.priors.to(device) + + self.priors = prior_cache[size][device] + + return self.priors + +class FPN(ScriptModuleWrapper): + """ + Implements a general version of the FPN introduced in + https://arxiv.org/pdf/1612.03144.pdf + + Parameters (in cfg.fpn): + - num_features (int): The number of output features in the fpn layers. + - interpolation_mode (str): The mode to pass to F.interpolate. + - num_downsample (int): The number of downsampled layers to add onto the selected layers. + These extra layers are downsampled from the last selected layer. + + Args: + - in_channels (list): For each conv layer you supply in the forward pass, + how many features will it have? + """ + __constants__ = ['interpolation_mode', 'num_downsample', 'use_conv_downsample', 'relu_pred_layers', + 'lat_layers', 'pred_layers', 'downsample_layers', 'relu_downsample_layers'] + + def __init__(self, in_channels): + super().__init__() + + self.lat_layers = nn.ModuleList([ + nn.Conv2d(x, cfg.fpn.num_features, kernel_size=1) + for x in reversed(in_channels) + ]) + + # This is here for backwards compatability + padding = 1 if cfg.fpn.pad else 0 + self.pred_layers = nn.ModuleList([ + nn.Conv2d(cfg.fpn.num_features, cfg.fpn.num_features, kernel_size=3, padding=padding) + for _ in in_channels + ]) + + if cfg.fpn.use_conv_downsample: + self.downsample_layers = nn.ModuleList([ + nn.Conv2d(cfg.fpn.num_features, cfg.fpn.num_features, kernel_size=3, padding=1, stride=2) + for _ in range(cfg.fpn.num_downsample) + ]) + + self.interpolation_mode = cfg.fpn.interpolation_mode + self.num_downsample = cfg.fpn.num_downsample + self.use_conv_downsample = cfg.fpn.use_conv_downsample + self.relu_downsample_layers = cfg.fpn.relu_downsample_layers + self.relu_pred_layers = cfg.fpn.relu_pred_layers + + @script_method_wrapper + def forward(self, convouts:List[torch.Tensor]): + """ + Args: + - convouts (list): A list of convouts for the corresponding layers in in_channels. + Returns: + - A list of FPN convouts in the same order as x with extra downsample layers if requested. + """ + + out = [] + x = torch.zeros(1, device=convouts[0].device) + for i in range(len(convouts)): + out.append(x) + + # For backward compatability, the conv layers are stored in reverse but the input and output is + # given in the correct order. Thus, use j=-i-1 for the input and output and i for the conv layers. + j = len(convouts) + for lat_layer in self.lat_layers: + j -= 1 + + if j < len(convouts) - 1: + _, _, h, w = convouts[j].size() + x = F.interpolate(x, size=(h, w), mode=self.interpolation_mode, align_corners=False) + + x = x + lat_layer(convouts[j]) + out[j] = x + + # This janky second loop is here because TorchScript. + j = len(convouts) + for pred_layer in self.pred_layers: + j -= 1 + out[j] = pred_layer(out[j]) + + if self.relu_pred_layers: + F.relu(out[j], inplace=True) + + cur_idx = len(out) + + # In the original paper, this takes care of P6 + if self.use_conv_downsample: + for downsample_layer in self.downsample_layers: + out.append(downsample_layer(out[-1])) + else: + for idx in range(self.num_downsample): + # Note: this is an untested alternative to out.append(out[-1][:, :, ::2, ::2]). Thanks TorchScript. + out.append(nn.functional.max_pool2d(out[-1], 1, stride=2)) + + if self.relu_downsample_layers: + for idx in range(len(out) - cur_idx): + out[idx] = F.relu(out[idx + cur_idx], inplace=False) + + return out + +class FastMaskIoUNet(ScriptModuleWrapper): + + def __init__(self): + super().__init__() + input_channels = 1 + last_layer = [(cfg.num_classes-1, 1, {})] + self.maskiou_net, _ = make_net(input_channels, cfg.maskiou_net + last_layer, include_last_relu=True) + + def forward(self, x): + x = self.maskiou_net(x) + maskiou_p = F.max_pool2d(x, kernel_size=x.size()[2:]).squeeze(-1).squeeze(-1) + + return maskiou_p + + + +class Yolact(nn.Module): + """ + + + ██╗ ██╗ ██████╗ ██╗ █████╗ ██████╗████████╗ + ╚██╗ ██╔╝██╔═══██╗██║ ██╔══██╗██╔════╝╚══██╔══╝ + ╚████╔╝ ██║ ██║██║ ███████║██║ ██║ + ╚██╔╝ ██║ ██║██║ ██╔══██║██║ ██║ + ██║ ╚██████╔╝███████╗██║ ██║╚██████╗ ██║ + ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ + + + You can set the arguments by changing them in the backbone config object in config.py. + + Parameters (in cfg.backbone): + - selected_layers: The indices of the conv layers to use for prediction. + - pred_scales: A list with len(selected_layers) containing tuples of scales (see PredictionModule) + - pred_aspect_ratios: A list of lists of aspect ratios with len(selected_layers) (see PredictionModule) + """ + + def __init__(self): + super().__init__() + + self.backbone = construct_backbone(cfg.backbone) #backbone: resnetbackbone. backbone_modules:{list:104}. bn1:{BatchNorm2d} + + if cfg.freeze_bn: # it's true + self.freeze_bn() + + # Compute mask_dim here and add it back to the config. Make sure Yolact's constructor is called early! + if cfg.mask_type == mask_type.direct: + cfg.mask_dim = cfg.mask_size**2 + elif cfg.mask_type == mask_type.lincomb: # the module will execute this branch + if cfg.mask_proto_use_grid: + self.grid = torch.Tensor(np.load(cfg.mask_proto_grid_file)) + self.num_grids = self.grid.size(0) + else: # the module will execute this branch + self.num_grids = 0 + + self.proto_src = cfg.mask_proto_src + + if self.proto_src is None: in_channels = 3 + elif cfg.fpn is not None: in_channels = cfg.fpn.num_features + else: in_channels = self.backbone.channels[self.proto_src] + in_channels += self.num_grids + #in_channels will be 256 + # The include_last_relu=false here is because we might want to change it to another function + self.proto_net, cfg.mask_dim = make_net(in_channels, cfg.mask_proto_net, include_last_relu=False) + + if cfg.mask_proto_bias: + cfg.mask_dim += 1 + + + self.selected_layers = cfg.backbone.selected_layers + src_channels = self.backbone.channels + + if cfg.use_maskiou: #false + self.maskiou_net = FastMaskIoUNet() + + if cfg.fpn is not None: #true + # Some hacky rewiring to accomodate the FPN + self.fpn = FPN([src_channels[i] for i in self.selected_layers]) + self.selected_layers = list(range(len(self.selected_layers) + cfg.fpn.num_downsample)) + src_channels = [cfg.fpn.num_features] * len(self.selected_layers) + + + self.prediction_layers = nn.ModuleList() + cfg.num_heads = len(self.selected_layers) + + for idx, layer_idx in enumerate(self.selected_layers): + # If we're sharing prediction module weights, have every module's parent be the first one + parent = None + if cfg.share_prediction_module and idx > 0: #cfg.share_prediction_module is True + parent = self.prediction_layers[0] + + pred = PredictionModule(src_channels[layer_idx], src_channels[layer_idx], + aspect_ratios = cfg.backbone.pred_aspect_ratios[idx], + scales = cfg.backbone.pred_scales[idx], + parent = parent, + index = idx) + self.prediction_layers.append(pred) + + # Extra parameters for the extra losses + if cfg.use_class_existence_loss: #false + # This comes from the smallest layer selected + # Also note that cfg.num_classes includes background + self.class_existence_fc = nn.Linear(src_channels[-1], cfg.num_classes - 1) + + if cfg.use_semantic_segmentation_loss: #true + self.semantic_seg_conv = nn.Conv2d(src_channels[0], cfg.num_classes-1, kernel_size=1) + + # For use in evaluation + self.detect = Detect(cfg.num_classes, bkg_label=0, top_k=cfg.nms_top_k, + conf_thresh=cfg.nms_conf_thresh, nms_thresh=cfg.nms_thresh) + + def save_weights(self, path): + """ Saves the model's weights using compression because the file sizes were getting too big. """ + torch.save(self.state_dict(), path) + + def load_weights(self, path): + """ Loads weights from a compressed save file. """ + state_dict = torch.load(path, map_location=torch.device('cpu')) + + # For backward compatability, remove these (the new variable is called layers) + for key in list(state_dict.keys()): + if key.startswith('backbone.layer') and not key.startswith('backbone.layers'): + del state_dict[key] + + # Also for backward compatibility with v1.0 weights, do this check + if key.startswith('fpn.downsample_layers.'): + if cfg.fpn is not None and int(key.split('.')[2]) >= cfg.fpn.num_downsample: + del state_dict[key] + self.load_state_dict(state_dict) + + def init_weights(self, backbone_path): + """ Initialize weights for training. """ + # Initialize the backbone with the pretrained weights. + self.backbone.init_backbone(backbone_path) + + conv_constants = getattr(nn.Conv2d(1, 1, 1), '__constants__') + + # Quick lambda to test if one list contains the other + def all_in(x, y): + for _x in x: + if _x not in y: + return False + return True + + # Initialize the rest of the conv layers with xavier + for name, module in self.named_modules(): + # See issue #127 for why we need such a complicated condition if the module is a WeakScriptModuleProxy + # Broke in 1.3 (see issue #175), WeakScriptModuleProxy was turned into just ScriptModule. + # Broke in 1.4 (see issue #292), where RecursiveScriptModule is the new star of the show. + # Note that this might break with future pytorch updates, so let me know if it does + is_script_conv = False + if 'Script' in type(module).__name__: + # 1.4 workaround: now there's an original_name member so just use that + if hasattr(module, 'original_name'): + is_script_conv = 'Conv' in module.original_name + # 1.3 workaround: check if this has the same constants as a conv module + else: + is_script_conv = ( + all_in(module.__dict__['_constants_set'], conv_constants) + and all_in(conv_constants, module.__dict__['_constants_set'])) + + is_conv_layer = isinstance(module, nn.Conv2d) or is_script_conv + + if is_conv_layer and module not in self.backbone.backbone_modules: + nn.init.xavier_uniform_(module.weight.data) + + if module.bias is not None: + if cfg.use_focal_loss and 'conf_layer' in name: + if not cfg.use_sigmoid_focal_loss: + # Initialize the last layer as in the focal loss paper. + # Because we use softmax and not sigmoid, I had to derive an alternate expression + # on a notecard. Define pi to be the probability of outputting a foreground detection. + # Then let z = sum(exp(x)) - exp(x_0). Finally let c be the number of foreground classes. + # Chugging through the math, this gives us + # x_0 = log(z * (1 - pi) / pi) where 0 is the background class + # x_i = log(z / c) for all i > 0 + # For simplicity (and because we have a degree of freedom here), set z = 1. Then we have + # x_0 = log((1 - pi) / pi) note: don't split up the log for numerical stability + # x_i = -log(c) for all i > 0 + module.bias.data[0] = np.log((1 - cfg.focal_loss_init_pi) / cfg.focal_loss_init_pi) + module.bias.data[1:] = -np.log(module.bias.size(0) - 1) + else: + module.bias.data[0] = -np.log(cfg.focal_loss_init_pi / (1 - cfg.focal_loss_init_pi)) + module.bias.data[1:] = -np.log((1 - cfg.focal_loss_init_pi) / cfg.focal_loss_init_pi) + else: + module.bias.data.zero_() + + def train(self, mode=True): + super().train(mode) + + if cfg.freeze_bn: + self.freeze_bn() + + def freeze_bn(self, enable=False): + """ Adapted from https://discuss.pytorch.org/t/how-to-train-with-frozen-batchnorm/12106/8 """ + for module in self.modules(): + if isinstance(module, nn.BatchNorm2d): + module.train() if enable else module.eval() + + module.weight.requires_grad = enable + module.bias.requires_grad = enable + + def forward(self, x): + """ The input should be of size [batch_size, 3, img_h, img_w] """ + _, _, img_h, img_w = x.size() + cfg._tmp_img_h = img_h + cfg._tmp_img_w = img_w + + with timer.env('backbone'): + outs = self.backbone(x) + + if cfg.fpn is not None: + with timer.env('fpn'): + # Use backbone.selected_layers because we overwrote self.selected_layers + outs = [outs[i] for i in cfg.backbone.selected_layers] + outs = self.fpn(outs) + + proto_out = None + if cfg.mask_type == mask_type.lincomb and cfg.eval_mask_branch: + with timer.env('proto'): + proto_x = x if self.proto_src is None else outs[self.proto_src] + + if self.num_grids > 0: + grids = self.grid.repeat(proto_x.size(0), 1, 1, 1) + proto_x = torch.cat([proto_x, grids], dim=1) + + proto_out = self.proto_net(proto_x) + proto_out = cfg.mask_proto_prototype_activation(proto_out) + + if cfg.mask_proto_prototypes_as_features: + # Clone here because we don't want to permute this, though idk if contiguous makes this unnecessary + proto_downsampled = proto_out.clone() + + if cfg.mask_proto_prototypes_as_features_no_grad: + proto_downsampled = proto_out.detach() + + # Move the features last so the multiplication is easy + proto_out = proto_out.permute(0, 2, 3, 1).contiguous() + + if cfg.mask_proto_bias: + bias_shape = [x for x in proto_out.size()] + bias_shape[-1] = 1 + proto_out = torch.cat([proto_out, torch.ones(*bias_shape)], -1) + + + with timer.env('pred_heads'): + pred_outs = { 'loc': [], 'conf': [], 'mask': [], 'priors': [] } + + if cfg.use_mask_scoring: + pred_outs['score'] = [] + + if cfg.use_instance_coeff: + pred_outs['inst'] = [] + + for idx, pred_layer in zip(self.selected_layers, self.prediction_layers): + pred_x = outs[idx] + + if cfg.mask_type == mask_type.lincomb and cfg.mask_proto_prototypes_as_features: + # Scale the prototypes down to the current prediction layer's size and add it as inputs + proto_downsampled = F.interpolate(proto_downsampled, size=outs[idx].size()[2:], mode='bilinear', align_corners=False) + pred_x = torch.cat([pred_x, proto_downsampled], dim=1) + + # A hack for the way dataparallel works + if cfg.share_prediction_module and pred_layer is not self.prediction_layers[0]: + pred_layer.parent = [self.prediction_layers[0]] + + p = pred_layer(pred_x) + + for k, v in p.items(): + pred_outs[k].append(v) + + for k, v in pred_outs.items(): + pred_outs[k] = torch.cat(v, -2) + + if proto_out is not None: + pred_outs['proto'] = proto_out + + if self.training: + # For the extra loss functions + if cfg.use_class_existence_loss: + pred_outs['classes'] = self.class_existence_fc(outs[-1].mean(dim=(2, 3))) + + if cfg.use_semantic_segmentation_loss: + pred_outs['segm'] = self.semantic_seg_conv(outs[0]) + + return pred_outs + else: + if cfg.use_mask_scoring: + pred_outs['score'] = torch.sigmoid(pred_outs['score']) + + if cfg.use_focal_loss: + if cfg.use_sigmoid_focal_loss: + # Note: even though conf[0] exists, this mode doesn't train it so don't use it + pred_outs['conf'] = torch.sigmoid(pred_outs['conf']) + if cfg.use_mask_scoring: + pred_outs['conf'] *= pred_outs['score'] + elif cfg.use_objectness_score: + # See focal_loss_sigmoid in multibox_loss.py for details + objectness = torch.sigmoid(pred_outs['conf'][:, :, 0]) + pred_outs['conf'][:, :, 1:] = objectness[:, :, None] * F.softmax(pred_outs['conf'][:, :, 1:], -1) + pred_outs['conf'][:, :, 0 ] = 1 - objectness + else: + pred_outs['conf'] = F.softmax(pred_outs['conf'], -1) + else: + + if cfg.use_objectness_score: + objectness = torch.sigmoid(pred_outs['conf'][:, :, 0]) + + pred_outs['conf'][:, :, 1:] = (objectness > 0.10)[..., None] \ + * F.softmax(pred_outs['conf'][:, :, 1:], dim=-1) + + else: + pred_outs['conf'] = F.softmax(pred_outs['conf'], -1) + for i in pred_outs.keys(): + pred_outs[i] = pred_outs[i].cpu() + return self.detect(pred_outs) + + + + +# Some testing code +if __name__ == '__main__': + from utils.functions import init_console + init_console() + + # Use the first argument to set the config if you want + import sys + if len(sys.argv) > 1: + from data.config import set_cfg + set_cfg(sys.argv[1]) + + net = Yolact() + net.train() + net.init_weights(backbone_path='weights/' + cfg.backbone.path) + + # GPU + net = net.cuda() + torch.set_default_tensor_type('torch.cuda.FloatTensor') + + x = torch.zeros((1, 3, cfg.max_size, cfg.max_size)) + y = net(x) + + for p in net.prediction_layers: + print(p.last_conv_size) + + print() + for k, a in y.items(): + print(k + ': ', a.size(), torch.sum(a)) + exit() + + net(x) + # timer.disable('pass2') + avg = MovingAverage() + try: + while True: + timer.reset() + with timer.env('everything else'): + net(x) + avg.add(timer.total_time()) + print('\033[2J') # Moves console cursor to 0,0 + timer.print_stats() + print('Avg fps: %.2f\tAvg ms: %.2f ' % (1/avg.get_avg(), avg.get_avg()*1000)) + except KeyboardInterrupt: + pass diff --git a/PyTorch/contrib/cv/detection/YOLOR/README.md b/PyTorch/contrib/cv/detection/YOLOR/README.md index 5e19e9243b7e8180f11fd502f65905764ea5fafa..cb96fdada6b9bfbdbaa8e397b164bdcec40753a9 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/README.md +++ b/PyTorch/contrib/cv/detection/YOLOR/README.md @@ -1,129 +1,129 @@ -# YOLOR 模型使用说明 - -## Requirements -* NPU配套的run包安装 -* Python 3.7.5 -* PyTorch(NPU版本) -* apex(NPU版本) -* (可选)参考《Pytorch 网络模型移植&训练指南》6.4.2章节,配置cpu为性能模式,以达到模型最佳性能;不开启不影响功能。 - -安装其他依赖(先安装NPU版本的pytorch和apex,再安装其他依赖): -``` -pip install -r requirements.txt -``` - -## Dataset -1. 下载coco数据集,包含图片、annotations、labels图片、annotations: - ``` - cd yolor - bash scripts/get_coco.sh - ``` -2. 将coco数据集放于工程根目录下 - coco目录结构如下: - ``` - coco - |-- LICENSE - |-- README.txt - |-- annotations - | `-- instances_val2017.json - |-- images - | |-- test2017 - | |-- train2017 - | `-- val2017 - |-- labels - | |-- train2017 - | |-- train2017.cache3 - | |-- val2017 - | `-- val2017.cache3 - |-- test-dev2017.txt - |-- train2017.cache - |-- train2017.txt - |-- val2017.cache - `-- val2017.txt - ``` - -注:数据集路径在./yolor/data/coco.yaml中设定,训练前请确认路径无误,如果路径不一致需要修改。 -原coco.yaml文件如图: -![coco_yaml](./figure/coco_yaml.png) - -## Train Model -### GPU 1P:在目录yolor下,运行 ./test/train_gpu_1p.sh -``` -chmod +x ./test/train_gpu_1p.sh -bash ./test/train_gpu_1p.sh -``` -若需要指定训练使用的卡号, 可修改train_gpu_1p.sh文件 "--device 0"配置项,其中卡号为0-7 - -### GPU 8P:在目录yolor下,运行 ./test/train_gpu_8p.sh -``` -chmod +x ./test/train_gpu_8p.sh -bash ./test/train_gpu_8p.sh -``` - -### NPU 1P:在目录yolor下,运行 train_performance_1p.sh -``` -chmod +x ./test/train_performance_1p.sh -bash ./test/train_performance_1p.sh -``` -若需要指定训练使用的卡号, 可修改train_performance_1p.sh文件 "--npu 0"配置项,其中卡号为0-7 - -### NPU 8P:在目录yolor下,运行 train_performance_8p.sh -``` -chmod +x ./test/train_performance_8p.sh -bash ./test/train_performance_8p.sh -``` - -注:在模型训练结束时,程序默认会将save的最后一个模型去除optimizer以减少模型大小,这会load模型,而在8P训练中,save和load的进程可能会不同步导致先load后save而报错,所以train_performance_8p.sh默认训练3个epoch(只要大于1个epoch即可)。 -如果用户只想要训练一个epoch并且保留模型的optimizer,在train_mp.py中注释掉如下部分代码即可: -![strip_optimizer](./figure/strip_optimizer.jpg) - - -### NPU 8P Full:在目录yolor下,运行 train_full_8p.sh -``` -chmod +x ./test/train_full_8p.sh -bash ./test/train_full_8p.sh -``` - -## Evaluation -复制训练好的last.pt到pretrained文件夹下,运行evaluation_npu.sh (npu) / evaluation_gpu.sh (gpu) -``` -chmod +x ./test/evaluation_xxx.sh -bash ./test/evaluation_xxx.sh -``` - -## 迁移学习 -参考https://github.com/WongKinYiu/yolor/issues/103,更改./cfg/yolo_p6.cfg中**对应行**的classes和filters: - -以coco为例,原80类别现在改为81:classes = 81, filters = anchor * (5 + classes) = 3 * (5 + 81) = 258,更改后的.cfg命名为yolor_p6_finetune.cfg,复制训练好的last.pt到pretrained文件夹下,运行train_finetune_1p.sh -``` -chmod +x ./test/train_finetune_1p.sh -bash ./test/train_finetune_1p.sh -``` - -## 白名单 -### Transpose whilte list - -路径:/usr/local/Ascend/ascend-toolkit/latest/opp/op_impl/built-in/ai_core/tbe/impl/dynamic/transpose.py -#120行左右 -``` -[8,3,160,160,85], [8,3,80,80,85], [8,3,40,40,85], [8,3,20,20,85], [8,3,85,160,160], [8,3,85,80,80] -``` -### Slice_d whilte list -路径:/usr/local/Ascend/ascend-toolkit/latest/opp/op_impl/built-in/ai_core/tbe/impl/slice_d.py -#7500行左右 -``` -["float16", [32,3,96,168,85], [32,3,96,168,2]], -["float16", [32,3,96,168,85], [32,3,96,168,4]], -["float16", [32,3,80,168,85], [32,3,80,168,2]], -["float16", [32,3,80,168,85], [32,3,80,168,4]], -["float16", [32,3,48,84,85], [32,3,48,84,2]], -["float16", [32,3,48,84,85], [32,3,48,84,4]], -["float16", [32,3,40,84,85], [32,3,40,84,2]], -["float16", [32,3,40,84,85], [32,3,40,84,4]], -["float16", [32,3,24,42,85], [32,3,24,42,2]], -["float16", [32,3,24,42,85], [32,3,24,42,4]], -["float16", [32,3,20,42,85], [32,3,20,42,2]], -["float16", [32,3,20,42,85], [32,3,20,42,4]], -["float32", [8, 3, 160, 160, 85], [8, 3, 160, 160, 1]], -["float32", [8, 3, 80, 80, 85], [8, 3, 80, 80, 1]], +# YOLOR 模型使用说明 + +## Requirements +* NPU配套的run包安装 +* Python 3.7.5 +* PyTorch(NPU版本) +* apex(NPU版本) +* (可选)参考《Pytorch 网络模型移植&训练指南》6.4.2章节,配置cpu为性能模式,以达到模型最佳性能;不开启不影响功能。 + +安装其他依赖(先安装NPU版本的pytorch和apex,再安装其他依赖): +``` +pip install -r requirements.txt +``` + +## Dataset +1. 下载coco数据集,包含图片、annotations、labels图片、annotations: + ``` + cd yolor + bash scripts/get_coco.sh + ``` +2. 将coco数据集放于工程根目录下 + coco目录结构如下: + ``` + coco + |-- LICENSE + |-- README.txt + |-- annotations + | `-- instances_val2017.json + |-- images + | |-- test2017 + | |-- train2017 + | `-- val2017 + |-- labels + | |-- train2017 + | |-- train2017.cache3 + | |-- val2017 + | `-- val2017.cache3 + |-- test-dev2017.txt + |-- train2017.cache + |-- train2017.txt + |-- val2017.cache + `-- val2017.txt + ``` + +注:数据集路径在./yolor/data/coco.yaml中设定,训练前请确认路径无误,如果路径不一致需要修改。 +原coco.yaml文件如图: +![coco_yaml](./figure/coco_yaml.png) + +## Train Model +### GPU 1P:在目录yolor下,运行 ./test/train_gpu_1p.sh +``` +chmod +x ./test/train_gpu_1p.sh +bash ./test/train_gpu_1p.sh +``` +若需要指定训练使用的卡号, 可修改train_gpu_1p.sh文件 "--device 0"配置项,其中卡号为0-7 + +### GPU 8P:在目录yolor下,运行 ./test/train_gpu_8p.sh +``` +chmod +x ./test/train_gpu_8p.sh +bash ./test/train_gpu_8p.sh +``` + +### NPU 1P:在目录yolor下,运行 train_performance_1p.sh +``` +chmod +x ./test/train_performance_1p.sh +bash ./test/train_performance_1p.sh +``` +若需要指定训练使用的卡号, 可修改train_performance_1p.sh文件 "--npu 0"配置项,其中卡号为0-7 + +### NPU 8P:在目录yolor下,运行 train_performance_8p.sh +``` +chmod +x ./test/train_performance_8p.sh +bash ./test/train_performance_8p.sh +``` + +注:在模型训练结束时,程序默认会将save的最后一个模型去除optimizer以减少模型大小,这会load模型,而在8P训练中,save和load的进程可能会不同步导致先load后save而报错,所以train_performance_8p.sh默认训练3个epoch(只要大于1个epoch即可)。 +如果用户只想要训练一个epoch并且保留模型的optimizer,在train_mp.py中注释掉如下部分代码即可: +![strip_optimizer](./figure/strip_optimizer.jpg) + + +### NPU 8P Full:在目录yolor下,运行 train_full_8p.sh +``` +chmod +x ./test/train_full_8p.sh +bash ./test/train_full_8p.sh +``` + +## Evaluation +复制训练好的last.pt到pretrained文件夹下,运行evaluation_npu.sh (npu) / evaluation_gpu.sh (gpu) +``` +chmod +x ./test/evaluation_xxx.sh +bash ./test/evaluation_xxx.sh +``` + +## 迁移学习 +参考https://github.com/WongKinYiu/yolor/issues/103,更改./cfg/yolo_p6.cfg中**对应行**的classes和filters: + +以coco为例,原80类别现在改为81:classes = 81, filters = anchor * (5 + classes) = 3 * (5 + 81) = 258,更改后的.cfg命名为yolor_p6_finetune.cfg,复制训练好的last.pt到pretrained文件夹下,运行train_finetune_1p.sh +``` +chmod +x ./test/train_finetune_1p.sh +bash ./test/train_finetune_1p.sh +``` + +## 白名单 +### Transpose whilte list + +路径:/usr/local/Ascend/ascend-toolkit/latest/opp/op_impl/built-in/ai_core/tbe/impl/dynamic/transpose.py +#120行左右 +``` +[8,3,160,160,85], [8,3,80,80,85], [8,3,40,40,85], [8,3,20,20,85], [8,3,85,160,160], [8,3,85,80,80] +``` +### Slice_d whilte list +路径:/usr/local/Ascend/ascend-toolkit/latest/opp/op_impl/built-in/ai_core/tbe/impl/slice_d.py +#7500行左右 +``` +["float16", [32,3,96,168,85], [32,3,96,168,2]], +["float16", [32,3,96,168,85], [32,3,96,168,4]], +["float16", [32,3,80,168,85], [32,3,80,168,2]], +["float16", [32,3,80,168,85], [32,3,80,168,4]], +["float16", [32,3,48,84,85], [32,3,48,84,2]], +["float16", [32,3,48,84,85], [32,3,48,84,4]], +["float16", [32,3,40,84,85], [32,3,40,84,2]], +["float16", [32,3,40,84,85], [32,3,40,84,4]], +["float16", [32,3,24,42,85], [32,3,24,42,2]], +["float16", [32,3,24,42,85], [32,3,24,42,4]], +["float16", [32,3,20,42,85], [32,3,20,42,2]], +["float16", [32,3,20,42,85], [32,3,20,42,4]], +["float32", [8, 3, 160, 160, 85], [8, 3, 160, 160, 1]], +["float32", [8, 3, 80, 80, 85], [8, 3, 80, 80, 1]], ``` \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_csp.cfg b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_csp.cfg index 810273b197f2a6f0c099ec54cb993e9ab0ed5d36..9f5f3ab421200036bf5d5c58f9be964f6d2e47a2 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_csp.cfg +++ b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_csp.cfg @@ -1,1376 +1,1376 @@ -[net] -# Testing -#batch=1 -#subdivisions=1 -# Training -batch=64 -subdivisions=8 -width=512 -height=512 -channels=3 -momentum=0.949 -decay=0.0005 -angle=0 -saturation = 1.5 -exposure = 1.5 -hue=.1 - -learning_rate=0.00261 -burn_in=1000 -max_batches = 500500 -policy=steps -steps=400000,450000 -scales=.1,.1 - -#cutmix=1 -mosaic=1 - - -# ============ Backbone ============ # - -# Stem - -# 0 -[convolutional] -batch_normalize=1 -filters=32 -size=3 -stride=1 -pad=1 -activation=silu - -# P1 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=2 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=32 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=silu - -# 4 (previous+1+3k) -[shortcut] -from=-3 -activation=linear - -# P2 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-10 - -# Transition last - -# 17 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -# P3 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1 -(4+3k)] - -[route] -layers = -1,-28 - -# Transition last - -# 48 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -# P4 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1 -(3k+4)] - -[route] -layers = -1,-28 - -# Transition last - -# 79 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# P5 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=1024 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1 -(3k+4)] - -[route] -layers = -1,-16 - -# Transition last - -# 98 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=1024 -size=1 -stride=1 -pad=1 -activation=silu - -# ============ End of Backbone ============ # - -# ============ Neck ============ # - -# CSPSPP - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -### SPP ### -[maxpool] -stride=1 -size=5 - -[route] -layers=-2 - -[maxpool] -stride=1 -size=9 - -[route] -layers=-4 - -[maxpool] -stride=1 -size=13 - -[route] -layers=-1,-3,-5,-6 -### End SPP ### - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[route] -layers = -1, -13 - -# 113 (previous+6+5+2k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# End of CSPSPP - - -# FPN-4 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[upsample] -stride=2 - -[route] -layers = 79 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -6 - -# Transition last - -# 127 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - - -# FPN-3 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[upsample] -stride=2 - -[route] -layers = 48 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=silu - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -6 - -# Transition last - -# 141 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - - -# PAN-4 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=256 -activation=silu - -[route] -layers = -1, 127 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -[route] -layers = -1,-6 - -# Transition last - -# 152 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - - -# PAN-5 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=512 -activation=silu - -[route] -layers = -1, 113 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[route] -layers = -1,-6 - -# Transition last - -# 163 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# ============ End of Neck ============ # - -# 164 -[implicit_add] -filters=256 - -# 165 -[implicit_add] -filters=512 - -# 166 -[implicit_add] -filters=1024 - -# 167 -[implicit_mul] -filters=255 - -# 168 -[implicit_mul] -filters=255 - -# 169 -[implicit_mul] -filters=255 - -# ============ Head ============ # - -# YOLO-3 - -[route] -layers = 141 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -[shift_channels] -from=164 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[control_channels] -from=167 - -[yolo] -mask = 0,1,2 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-4 - -[route] -layers = 152 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[shift_channels] -from=165 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[control_channels] -from=168 - -[yolo] -mask = 3,4,5 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-5 - -[route] -layers = 163 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1024 -activation=silu - -[shift_channels] -from=166 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[control_channels] -from=169 - -[yolo] -mask = 6,7,8 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 +[net] +# Testing +#batch=1 +#subdivisions=1 +# Training +batch=64 +subdivisions=8 +width=512 +height=512 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.00261 +burn_in=1000 +max_batches = 500500 +policy=steps +steps=400000,450000 +scales=.1,.1 + +#cutmix=1 +mosaic=1 + + +# ============ Backbone ============ # + +# Stem + +# 0 +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=silu + +# P1 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=silu + +# 4 (previous+1+3k) +[shortcut] +from=-3 +activation=linear + +# P2 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-10 + +# Transition last + +# 17 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +# P3 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1 -(4+3k)] + +[route] +layers = -1,-28 + +# Transition last + +# 48 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +# P4 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1 -(3k+4)] + +[route] +layers = -1,-28 + +# Transition last + +# 79 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# P5 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1 -(3k+4)] + +[route] +layers = -1,-16 + +# Transition last + +# 98 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=silu + +# ============ End of Backbone ============ # + +# ============ Neck ============ # + +# CSPSPP + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[route] +layers = -1, -13 + +# 113 (previous+6+5+2k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# End of CSPSPP + + +# FPN-4 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[upsample] +stride=2 + +[route] +layers = 79 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -6 + +# Transition last + +# 127 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + + +# FPN-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[upsample] +stride=2 + +[route] +layers = 48 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=silu + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -6 + +# Transition last + +# 141 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + + +# PAN-4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=256 +activation=silu + +[route] +layers = -1, 127 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +[route] +layers = -1,-6 + +# Transition last + +# 152 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + + +# PAN-5 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=512 +activation=silu + +[route] +layers = -1, 113 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[route] +layers = -1,-6 + +# Transition last + +# 163 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# ============ End of Neck ============ # + +# 164 +[implicit_add] +filters=256 + +# 165 +[implicit_add] +filters=512 + +# 166 +[implicit_add] +filters=1024 + +# 167 +[implicit_mul] +filters=255 + +# 168 +[implicit_mul] +filters=255 + +# 169 +[implicit_mul] +filters=255 + +# ============ Head ============ # + +# YOLO-3 + +[route] +layers = 141 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +[shift_channels] +from=164 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[control_channels] +from=167 + +[yolo] +mask = 0,1,2 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-4 + +[route] +layers = 152 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[shift_channels] +from=165 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[control_channels] +from=168 + +[yolo] +mask = 3,4,5 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-5 + +[route] +layers = 163 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=silu + +[shift_channels] +from=166 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[control_channels] +from=169 + +[yolo] +mask = 6,7,8 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 diff --git a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_csp_x.cfg b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_csp_x.cfg index 995aefea61010c1762a681939b4d6d057ab55131..55a54109bf4882055ebc02b5a8688bfd3d618e4d 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_csp_x.cfg +++ b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_csp_x.cfg @@ -1,1576 +1,1576 @@ -[net] -# Testing -#batch=1 -#subdivisions=1 -# Training -batch=64 -subdivisions=8 -width=512 -height=512 -channels=3 -momentum=0.949 -decay=0.0005 -angle=0 -saturation = 1.5 -exposure = 1.5 -hue=.1 - -learning_rate=0.00261 -burn_in=1000 -max_batches = 500500 -policy=steps -steps=400000,450000 -scales=.1,.1 - -#cutmix=1 -mosaic=1 - - -# ============ Backbone ============ # - -# Stem - -# 0 -[convolutional] -batch_normalize=1 -filters=32 -size=3 -stride=1 -pad=1 -activation=silu - -# P1 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=2 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=40 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=silu - -# 4 (previous+1+3k) -[shortcut] -from=-3 -activation=linear - -# P2 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-13 - -# Transition last - -# 20 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -# P3 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1 -(4+3k)] - -[route] -layers = -1,-34 - -# Transition last - -# 57 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -# P4 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1 -(3k+4)] - -[route] -layers = -1,-34 - -# Transition last - -# 94 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -# P5 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=1280 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1 -(3k+4)] - -[route] -layers = -1,-19 - -# Transition last - -# 116 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=1280 -size=1 -stride=1 -pad=1 -activation=silu - -# ============ End of Backbone ============ # - -# ============ Neck ============ # - -# CSPSPP - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -### SPP ### -[maxpool] -stride=1 -size=5 - -[route] -layers=-2 - -[maxpool] -stride=1 -size=9 - -[route] -layers=-4 - -[maxpool] -stride=1 -size=13 - -[route] -layers=-1,-3,-5,-6 -### End SPP ### - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=silu - -[route] -layers = -1, -15 - -# 133 (previous+6+5+2k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -# End of CSPSPP - - -# FPN-4 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[upsample] -stride=2 - -[route] -layers = 94 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=silu - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 149 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - - -# FPN-3 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[upsample] -stride=2 - -[route] -layers = 57 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=160 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=160 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=160 -activation=silu - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 165 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - - -# PAN-4 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=320 -activation=silu - -[route] -layers = -1, 149 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=silu - -[route] -layers = -1,-8 - -# Transition last - -# 178 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - - -# PAN-5 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=640 -activation=silu - -[route] -layers = -1, 133 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=silu - -[route] -layers = -1,-8 - -# Transition last - -# 191 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -# ============ End of Neck ============ # - -# 192 -[implicit_add] -filters=320 - -# 193 -[implicit_add] -filters=640 - -# 194 -[implicit_add] -filters=1280 - -# 195 -[implicit_mul] -filters=255 - -# 196 -[implicit_mul] -filters=255 - -# 197 -[implicit_mul] -filters=255 - -# ============ Head ============ # - -# YOLO-3 - -[route] -layers = 165 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=silu - -[shift_channels] -from=192 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[control_channels] -from=195 - -[yolo] -mask = 0,1,2 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-4 - -[route] -layers = 178 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=silu - -[shift_channels] -from=193 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[control_channels] -from=196 - -[yolo] -mask = 3,4,5 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-5 - -[route] -layers = 191 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1280 -activation=silu - -[shift_channels] -from=194 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[control_channels] -from=197 - -[yolo] -mask = 6,7,8 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 +[net] +# Testing +#batch=1 +#subdivisions=1 +# Training +batch=64 +subdivisions=8 +width=512 +height=512 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.00261 +burn_in=1000 +max_batches = 500500 +policy=steps +steps=400000,450000 +scales=.1,.1 + +#cutmix=1 +mosaic=1 + + +# ============ Backbone ============ # + +# Stem + +# 0 +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=silu + +# P1 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=2 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=40 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=silu + +# 4 (previous+1+3k) +[shortcut] +from=-3 +activation=linear + +# P2 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-13 + +# Transition last + +# 20 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +# P3 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1 -(4+3k)] + +[route] +layers = -1,-34 + +# Transition last + +# 57 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +# P4 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1 -(3k+4)] + +[route] +layers = -1,-34 + +# Transition last + +# 94 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +# P5 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1280 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1 -(3k+4)] + +[route] +layers = -1,-19 + +# Transition last + +# 116 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=1280 +size=1 +stride=1 +pad=1 +activation=silu + +# ============ End of Backbone ============ # + +# ============ Neck ============ # + +# CSPSPP + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=silu + +[route] +layers = -1, -15 + +# 133 (previous+6+5+2k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +# End of CSPSPP + + +# FPN-4 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[upsample] +stride=2 + +[route] +layers = 94 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=silu + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 149 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + + +# FPN-3 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[upsample] +stride=2 + +[route] +layers = 57 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=silu + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 165 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + + +# PAN-4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=320 +activation=silu + +[route] +layers = -1, 149 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=silu + +[route] +layers = -1,-8 + +# Transition last + +# 178 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + + +# PAN-5 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=640 +activation=silu + +[route] +layers = -1, 133 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=silu + +[route] +layers = -1,-8 + +# Transition last + +# 191 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +# ============ End of Neck ============ # + +# 192 +[implicit_add] +filters=320 + +# 193 +[implicit_add] +filters=640 + +# 194 +[implicit_add] +filters=1280 + +# 195 +[implicit_mul] +filters=255 + +# 196 +[implicit_mul] +filters=255 + +# 197 +[implicit_mul] +filters=255 + +# ============ Head ============ # + +# YOLO-3 + +[route] +layers = 165 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=silu + +[shift_channels] +from=192 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[control_channels] +from=195 + +[yolo] +mask = 0,1,2 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-4 + +[route] +layers = 178 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=silu + +[shift_channels] +from=193 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[control_channels] +from=196 + +[yolo] +mask = 3,4,5 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-5 + +[route] +layers = 191 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1280 +activation=silu + +[shift_channels] +from=194 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[control_channels] +from=197 + +[yolo] +mask = 6,7,8 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 diff --git a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_p6.cfg b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_p6.cfg index 62b19e87734c2c45040623f2d0170ef2ae17f871..88ddd686d757636c8e3cc069b195f200600562c4 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_p6.cfg +++ b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_p6.cfg @@ -1,1762 +1,1762 @@ -[net] -batch=64 -subdivisions=8 -width=1280 -height=1280 -channels=3 -momentum=0.949 -decay=0.0005 -angle=0 -saturation = 1.5 -exposure = 1.5 -hue=.1 - - - -learning_rate=0.00261 -burn_in=1000 -max_batches = 500500 -policy=steps -steps=400000,450000 -scales=.1,.1 - -mosaic=1 - - -# ============ Backbone ============ # - -# Stem - -# P1 - -# Downsample - -# 0 -[reorg] - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=swish - - -# P2 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=64 -#size=1 -#stride=1 -#pad=1 -#activation=swish - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-12 - -# Transition last - -# 16 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - - -# P3 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=128 -#size=1 -#stride=1 -#pad=1 -#activation=swish - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-24 - -# Transition last - -# 43 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - - -# P4 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=384 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=192 -#size=1 -#stride=1 -#pad=1 -#activation=swish - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-24 - -# Transition last - -# 70 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=swish - - -# P5 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=256 -#size=1 -#stride=1 -#pad=1 -#activation=swish - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-12 - -# Transition last - -# 85 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - - -# P6 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=320 -#size=1 -#stride=1 -#pad=1 -#activation=swish - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-12 - -# Transition last - -# 100 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -# ============ End of Backbone ============ # - -# ============ Neck ============ # - -# CSPSPP - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -### SPP ### -[maxpool] -stride=1 -size=5 - -[route] -layers=-2 - -[maxpool] -stride=1 -size=9 - -[route] -layers=-4 - -[maxpool] -stride=1 -size=13 - -[route] -layers=-1,-3,-5,-6 -### End SPP ### - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[route] -layers = -1, -13 - -# 115 (previous+6+5+2k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -# End of CSPSPP - - -# FPN-5 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[upsample] -stride=2 - -[route] -layers = 85 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 131 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - - -# FPN-4 - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[upsample] -stride=2 - -[route] -layers = 70 - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=192 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=192 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=192 -activation=swish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 147 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - - -# FPN-3 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[upsample] -stride=2 - -[route] -layers = 43 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=swish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 163 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - - -# PAN-4 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=192 -activation=swish - -[route] -layers = -1, 147 - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=192 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=192 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=192 -activation=swish - -[route] -layers = -1,-8 - -# Transition last - -# 176 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - - -# PAN-5 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=256 -activation=swish - -[route] -layers = -1, 131 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[route] -layers = -1,-8 - -# Transition last - -# 189 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - - -# PAN-6 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=320 -activation=swish - -[route] -layers = -1, 115 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[route] -layers = -1,-8 - -# Transition last - -# 202 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -# ============ End of Neck ============ # - -# 203 -[implicit_add] -filters=256 - -# 204 -[implicit_add] -filters=384 - -# 205 -[implicit_add] -filters=512 - -# 206 -[implicit_add] -filters=640 - -# 207 -[implicit_mul] -filters=255 - -# 208 -[implicit_mul] -filters=255 - -# 209 -[implicit_mul] -filters=255 - -# 210 -[implicit_mul] -filters=255 - -# ============ Head ============ # - -# YOLO-3 - -[route] -layers = 163 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[shift_channels] -from=203 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[control_channels] -from=207 - -[yolo] -mask = 0,1,2 -anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 -classes=80 -num=12 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-4 - -[route] -layers = 176 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=384 -activation=swish - -[shift_channels] -from=204 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[control_channels] -from=208 - -[yolo] -mask = 3,4,5 -anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 -classes=80 -num=12 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-5 - -[route] -layers = 189 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=swish - -[shift_channels] -from=205 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[control_channels] -from=209 - -[yolo] -mask = 6,7,8 -anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 -classes=80 -num=12 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-6 - -[route] -layers = 202 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=swish - -[shift_channels] -from=206 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[control_channels] -from=210 - -[yolo] -mask = 9,10,11 -anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 -classes=80 -num=12 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - +[net] +batch=64 +subdivisions=8 +width=1280 +height=1280 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + + + +learning_rate=0.00261 +burn_in=1000 +max_batches = 500500 +policy=steps +steps=400000,450000 +scales=.1,.1 + +mosaic=1 + + +# ============ Backbone ============ # + +# Stem + +# P1 + +# Downsample + +# 0 +[reorg] + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=swish + + +# P2 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=64 +#size=1 +#stride=1 +#pad=1 +#activation=swish + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-12 + +# Transition last + +# 16 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + + +# P3 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=128 +#size=1 +#stride=1 +#pad=1 +#activation=swish + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-24 + +# Transition last + +# 43 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + + +# P4 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=384 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=192 +#size=1 +#stride=1 +#pad=1 +#activation=swish + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-24 + +# Transition last + +# 70 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=swish + + +# P5 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=256 +#size=1 +#stride=1 +#pad=1 +#activation=swish + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-12 + +# Transition last + +# 85 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + + +# P6 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=320 +#size=1 +#stride=1 +#pad=1 +#activation=swish + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-12 + +# Transition last + +# 100 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +# ============ End of Backbone ============ # + +# ============ Neck ============ # + +# CSPSPP + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[route] +layers = -1, -13 + +# 115 (previous+6+5+2k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +# End of CSPSPP + + +# FPN-5 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[upsample] +stride=2 + +[route] +layers = 85 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 131 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + + +# FPN-4 + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[upsample] +stride=2 + +[route] +layers = 70 + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=192 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=192 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=192 +activation=swish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 147 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + + +# FPN-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[upsample] +stride=2 + +[route] +layers = 43 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=swish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 163 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + + +# PAN-4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=192 +activation=swish + +[route] +layers = -1, 147 + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=192 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=192 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=192 +activation=swish + +[route] +layers = -1,-8 + +# Transition last + +# 176 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + + +# PAN-5 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=256 +activation=swish + +[route] +layers = -1, 131 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[route] +layers = -1,-8 + +# Transition last + +# 189 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + + +# PAN-6 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=320 +activation=swish + +[route] +layers = -1, 115 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[route] +layers = -1,-8 + +# Transition last + +# 202 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +# ============ End of Neck ============ # + +# 203 +[implicit_add] +filters=256 + +# 204 +[implicit_add] +filters=384 + +# 205 +[implicit_add] +filters=512 + +# 206 +[implicit_add] +filters=640 + +# 207 +[implicit_mul] +filters=255 + +# 208 +[implicit_mul] +filters=255 + +# 209 +[implicit_mul] +filters=255 + +# 210 +[implicit_mul] +filters=255 + +# ============ Head ============ # + +# YOLO-3 + +[route] +layers = 163 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[shift_channels] +from=203 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[control_channels] +from=207 + +[yolo] +mask = 0,1,2 +anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +classes=80 +num=12 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-4 + +[route] +layers = 176 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=384 +activation=swish + +[shift_channels] +from=204 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[control_channels] +from=208 + +[yolo] +mask = 3,4,5 +anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +classes=80 +num=12 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-5 + +[route] +layers = 189 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=swish + +[shift_channels] +from=205 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[control_channels] +from=209 + +[yolo] +mask = 6,7,8 +anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +classes=80 +num=12 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-6 + +[route] +layers = 202 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=swish + +[shift_channels] +from=206 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[control_channels] +from=210 + +[yolo] +mask = 9,10,11 +anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +classes=80 +num=12 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + # ============ End of Head ============ # \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_p6_finetune.cfg b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_p6_finetune.cfg index 0869eac0dca717534b73a9078aec113f94c89c07..ab74810f6bb49917e0e5923dc4458bac22e027b4 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_p6_finetune.cfg +++ b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_p6_finetune.cfg @@ -1,1760 +1,1760 @@ -[net] -batch=64 -subdivisions=8 -width=1280 -height=1280 -channels=3 -momentum=0.949 -decay=0.0005 -angle=0 -saturation = 1.5 -exposure = 1.5 -hue=.1 - -learning_rate=0.00261 -burn_in=1000 -max_batches = 500500 -policy=steps -steps=400000,450000 -scales=.1,.1 - -mosaic=1 - - -# ============ Backbone ============ # - -# Stem - -# P1 - -# Downsample - -# 0 -[reorg] - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=swish - - -# P2 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=64 -#size=1 -#stride=1 -#pad=1 -#activation=swish - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-12 - -# Transition last - -# 16 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - - -# P3 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=128 -#size=1 -#stride=1 -#pad=1 -#activation=swish - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-24 - -# Transition last - -# 43 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - - -# P4 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=384 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=192 -#size=1 -#stride=1 -#pad=1 -#activation=swish - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-24 - -# Transition last - -# 70 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=swish - - -# P5 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=256 -#size=1 -#stride=1 -#pad=1 -#activation=swish - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-12 - -# Transition last - -# 85 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - - -# P6 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=320 -#size=1 -#stride=1 -#pad=1 -#activation=swish - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-12 - -# Transition last - -# 100 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -# ============ End of Backbone ============ # - -# ============ Neck ============ # - -# CSPSPP - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -### SPP ### -[maxpool] -stride=1 -size=5 - -[route] -layers=-2 - -[maxpool] -stride=1 -size=9 - -[route] -layers=-4 - -[maxpool] -stride=1 -size=13 - -[route] -layers=-1,-3,-5,-6 -### End SPP ### - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[route] -layers = -1, -13 - -# 115 (previous+6+5+2k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -# End of CSPSPP - - -# FPN-5 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[upsample] -stride=2 - -[route] -layers = 85 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 131 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - - -# FPN-4 - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[upsample] -stride=2 - -[route] -layers = 70 - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=192 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=192 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=192 -activation=swish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 147 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - - -# FPN-3 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[upsample] -stride=2 - -[route] -layers = 43 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=swish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 163 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - - -# PAN-4 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=192 -activation=swish - -[route] -layers = -1, 147 - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=192 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=192 -activation=swish - -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=192 -activation=swish - -[route] -layers = -1,-8 - -# Transition last - -# 176 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=192 -size=1 -stride=1 -pad=1 -activation=swish - - -# PAN-5 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=256 -activation=swish - -[route] -layers = -1, 131 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[route] -layers = -1,-8 - -# Transition last - -# 189 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - - -# PAN-6 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=320 -activation=swish - -[route] -layers = -1, 115 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[route] -layers = -1,-8 - -# Transition last - -# 202 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -# ============ End of Neck ============ # - -# 203 -[implicit_add] -filters=256 - -# 204 -[implicit_add] -filters=384 - -# 205 -[implicit_add] -filters=512 - -# 206 -[implicit_add] -filters=640 - -# 207 -[implicit_mul] -filters=258 - -# 208 -[implicit_mul] -filters=258 - -# 209 -[implicit_mul] -filters=258 - -# 210 -[implicit_mul] -filters=258 - -# ============ Head ============ # - -# YOLO-3 - -[route] -layers = 163 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[shift_channels] -from=203 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=258 -activation=linear - -[control_channels] -from=207 - -[yolo] -mask = 0,1,2 -anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 -classes=81 -num=12 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-4 - -[route] -layers = 176 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=384 -activation=swish - -[shift_channels] -from=204 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=258 -activation=linear - -[control_channels] -from=208 - -[yolo] -mask = 3,4,5 -anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 -classes=81 -num=12 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-5 - -[route] -layers = 189 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=swish - -[shift_channels] -from=205 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=258 -activation=linear - -[control_channels] -from=209 - -[yolo] -mask = 6,7,8 -anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 -classes=81 -num=12 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-6 - -[route] -layers = 202 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=swish - -[shift_channels] -from=206 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=258 -activation=linear - -[control_channels] -from=210 - -[yolo] -mask = 9,10,11 -anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 -classes=81 -num=12 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - +[net] +batch=64 +subdivisions=8 +width=1280 +height=1280 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.00261 +burn_in=1000 +max_batches = 500500 +policy=steps +steps=400000,450000 +scales=.1,.1 + +mosaic=1 + + +# ============ Backbone ============ # + +# Stem + +# P1 + +# Downsample + +# 0 +[reorg] + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=swish + + +# P2 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=64 +#size=1 +#stride=1 +#pad=1 +#activation=swish + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-12 + +# Transition last + +# 16 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + + +# P3 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=128 +#size=1 +#stride=1 +#pad=1 +#activation=swish + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-24 + +# Transition last + +# 43 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + + +# P4 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=384 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=192 +#size=1 +#stride=1 +#pad=1 +#activation=swish + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-24 + +# Transition last + +# 70 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=swish + + +# P5 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=256 +#size=1 +#stride=1 +#pad=1 +#activation=swish + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-12 + +# Transition last + +# 85 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + + +# P6 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=320 +#size=1 +#stride=1 +#pad=1 +#activation=swish + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-12 + +# Transition last + +# 100 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +# ============ End of Backbone ============ # + +# ============ Neck ============ # + +# CSPSPP + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[route] +layers = -1, -13 + +# 115 (previous+6+5+2k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +# End of CSPSPP + + +# FPN-5 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[upsample] +stride=2 + +[route] +layers = 85 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 131 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + + +# FPN-4 + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[upsample] +stride=2 + +[route] +layers = 70 + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=192 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=192 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=192 +activation=swish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 147 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + + +# FPN-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[upsample] +stride=2 + +[route] +layers = 43 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=swish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 163 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + + +# PAN-4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=192 +activation=swish + +[route] +layers = -1, 147 + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=192 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=192 +activation=swish + +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=192 +activation=swish + +[route] +layers = -1,-8 + +# Transition last + +# 176 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=192 +size=1 +stride=1 +pad=1 +activation=swish + + +# PAN-5 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=256 +activation=swish + +[route] +layers = -1, 131 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[route] +layers = -1,-8 + +# Transition last + +# 189 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + + +# PAN-6 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=320 +activation=swish + +[route] +layers = -1, 115 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[route] +layers = -1,-8 + +# Transition last + +# 202 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +# ============ End of Neck ============ # + +# 203 +[implicit_add] +filters=256 + +# 204 +[implicit_add] +filters=384 + +# 205 +[implicit_add] +filters=512 + +# 206 +[implicit_add] +filters=640 + +# 207 +[implicit_mul] +filters=258 + +# 208 +[implicit_mul] +filters=258 + +# 209 +[implicit_mul] +filters=258 + +# 210 +[implicit_mul] +filters=258 + +# ============ Head ============ # + +# YOLO-3 + +[route] +layers = 163 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[shift_channels] +from=203 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=258 +activation=linear + +[control_channels] +from=207 + +[yolo] +mask = 0,1,2 +anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +classes=81 +num=12 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-4 + +[route] +layers = 176 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=384 +activation=swish + +[shift_channels] +from=204 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=258 +activation=linear + +[control_channels] +from=208 + +[yolo] +mask = 3,4,5 +anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +classes=81 +num=12 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-5 + +[route] +layers = 189 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=swish + +[shift_channels] +from=205 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=258 +activation=linear + +[control_channels] +from=209 + +[yolo] +mask = 6,7,8 +anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +classes=81 +num=12 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-6 + +[route] +layers = 202 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=swish + +[shift_channels] +from=206 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=258 +activation=linear + +[control_channels] +from=210 + +[yolo] +mask = 9,10,11 +anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +classes=81 +num=12 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + # ============ End of Head ============ # \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_w6.cfg b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_w6.cfg index 4052603dd2b1e2d2085b78939a84e1b2e3e3ddbe..b91167a2e06a1f0f15d9c88234d9c5971c3ad29c 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_w6.cfg +++ b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolor_w6.cfg @@ -1,1760 +1,1760 @@ -[net] -batch=64 -subdivisions=8 -width=1280 -height=1280 -channels=3 -momentum=0.949 -decay=0.0005 -angle=0 -saturation = 1.5 -exposure = 1.5 -hue=.1 - -learning_rate=0.00261 -burn_in=1000 -max_batches = 500500 -policy=steps -steps=400000,450000 -scales=.1,.1 - -mosaic=1 - - -# ============ Backbone ============ # - -# Stem - -# P1 - -# Downsample - -# 0 -[reorg] - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=silu - - -# P2 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=64 -#size=1 -#stride=1 -#pad=1 -#activation=silu - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-12 - -# Transition last - -# 16 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - - -# P3 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=128 -#size=1 -#stride=1 -#pad=1 -#activation=silu - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-24 - -# Transition last - -# 43 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - - -# P4 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=256 -#size=1 -#stride=1 -#pad=1 -#activation=silu - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-24 - -# Transition last - -# 70 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - - -# P5 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=768 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=384 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=384 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=384 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=384 -#size=1 -#stride=1 -#pad=1 -#activation=silu - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-12 - -# Transition last - -# 85 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=768 -size=1 -stride=1 -pad=1 -activation=silu - - -# P6 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=1024 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first -# -#[convolutional] -#batch_normalize=1 -#filters=512 -#size=1 -#stride=1 -#pad=1 -#activation=silu - -# Merge [-1, -(3k+3)] - -[route] -layers = -1,-12 - -# Transition last - -# 100 (previous+6+3k) -[convolutional] -batch_normalize=1 -filters=1024 -size=1 -stride=1 -pad=1 -activation=silu - -# ============ End of Backbone ============ # - -# ============ Neck ============ # - -# CSPSPP - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -### SPP ### -[maxpool] -stride=1 -size=5 - -[route] -layers=-2 - -[maxpool] -stride=1 -size=9 - -[route] -layers=-4 - -[maxpool] -stride=1 -size=13 - -[route] -layers=-1,-3,-5,-6 -### End SPP ### - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[route] -layers = -1, -13 - -# 115 (previous+6+5+2k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# End of CSPSPP - - -# FPN-5 - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -[upsample] -stride=2 - -[route] -layers = 85 - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=384 -activation=silu - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=384 -activation=silu - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=384 -activation=silu - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 131 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - - -# FPN-4 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[upsample] -stride=2 - -[route] -layers = 70 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 147 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - - -# FPN-3 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[upsample] -stride=2 - -[route] -layers = 43 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=silu - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 163 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - - -# PAN-4 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=256 -activation=silu - -[route] -layers = -1, 147 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -[route] -layers = -1,-8 - -# Transition last - -# 176 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - - -# PAN-5 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=384 -activation=silu - -[route] -layers = -1, 131 - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=384 -activation=silu - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=384 -activation=silu - -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=384 -activation=silu - -[route] -layers = -1,-8 - -# Transition last - -# 189 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=384 -size=1 -stride=1 -pad=1 -activation=silu - - -# PAN-6 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=512 -activation=silu - -[route] -layers = -1, 115 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[route] -layers = -1,-8 - -# Transition last - -# 202 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# ============ End of Neck ============ # - -# 203 -[implicit_add] -filters=256 - -# 204 -[implicit_add] -filters=512 - -# 205 -[implicit_add] -filters=768 - -# 206 -[implicit_add] -filters=1024 - -# 207 -[implicit_mul] -filters=255 - -# 208 -[implicit_mul] -filters=255 - -# 209 -[implicit_mul] -filters=255 - -# 210 -[implicit_mul] -filters=255 - -# ============ Head ============ # - -# YOLO-3 - -[route] -layers = 163 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -[shift_channels] -from=203 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[control_channels] -from=207 - -[yolo] -mask = 0,1,2 -anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 -classes=80 -num=12 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-4 - -[route] -layers = 176 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[shift_channels] -from=204 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[control_channels] -from=208 - -[yolo] -mask = 3,4,5 -anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 -classes=80 -num=12 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-5 - -[route] -layers = 189 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=768 -activation=silu - -[shift_channels] -from=205 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[control_channels] -from=209 - -[yolo] -mask = 6,7,8 -anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 -classes=80 -num=12 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-6 - -[route] -layers = 202 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1024 -activation=silu - -[shift_channels] -from=206 - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[control_channels] -from=210 - -[yolo] -mask = 9,10,11 -anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 -classes=80 -num=12 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - -# ============ End of Head ============ # +[net] +batch=64 +subdivisions=8 +width=1280 +height=1280 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.00261 +burn_in=1000 +max_batches = 500500 +policy=steps +steps=400000,450000 +scales=.1,.1 + +mosaic=1 + + +# ============ Backbone ============ # + +# Stem + +# P1 + +# Downsample + +# 0 +[reorg] + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=silu + + +# P2 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=64 +#size=1 +#stride=1 +#pad=1 +#activation=silu + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-12 + +# Transition last + +# 16 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + + +# P3 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=128 +#size=1 +#stride=1 +#pad=1 +#activation=silu + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-24 + +# Transition last + +# 43 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + + +# P4 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=256 +#size=1 +#stride=1 +#pad=1 +#activation=silu + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-24 + +# Transition last + +# 70 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + + +# P5 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=768 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=384 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=384 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=384 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=384 +#size=1 +#stride=1 +#pad=1 +#activation=silu + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-12 + +# Transition last + +# 85 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=768 +size=1 +stride=1 +pad=1 +activation=silu + + +# P6 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first +# +#[convolutional] +#batch_normalize=1 +#filters=512 +#size=1 +#stride=1 +#pad=1 +#activation=silu + +# Merge [-1, -(3k+3)] + +[route] +layers = -1,-12 + +# Transition last + +# 100 (previous+6+3k) +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=silu + +# ============ End of Backbone ============ # + +# ============ Neck ============ # + +# CSPSPP + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[route] +layers = -1, -13 + +# 115 (previous+6+5+2k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# End of CSPSPP + + +# FPN-5 + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +[upsample] +stride=2 + +[route] +layers = 85 + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=384 +activation=silu + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=384 +activation=silu + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=384 +activation=silu + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 131 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + + +# FPN-4 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[upsample] +stride=2 + +[route] +layers = 70 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 147 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + + +# FPN-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[upsample] +stride=2 + +[route] +layers = 43 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=silu + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 163 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + + +# PAN-4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=256 +activation=silu + +[route] +layers = -1, 147 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +[route] +layers = -1,-8 + +# Transition last + +# 176 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + + +# PAN-5 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=384 +activation=silu + +[route] +layers = -1, 131 + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=384 +activation=silu + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=384 +activation=silu + +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=384 +activation=silu + +[route] +layers = -1,-8 + +# Transition last + +# 189 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=384 +size=1 +stride=1 +pad=1 +activation=silu + + +# PAN-6 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=512 +activation=silu + +[route] +layers = -1, 115 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[route] +layers = -1,-8 + +# Transition last + +# 202 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# ============ End of Neck ============ # + +# 203 +[implicit_add] +filters=256 + +# 204 +[implicit_add] +filters=512 + +# 205 +[implicit_add] +filters=768 + +# 206 +[implicit_add] +filters=1024 + +# 207 +[implicit_mul] +filters=255 + +# 208 +[implicit_mul] +filters=255 + +# 209 +[implicit_mul] +filters=255 + +# 210 +[implicit_mul] +filters=255 + +# ============ Head ============ # + +# YOLO-3 + +[route] +layers = 163 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +[shift_channels] +from=203 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[control_channels] +from=207 + +[yolo] +mask = 0,1,2 +anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +classes=80 +num=12 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-4 + +[route] +layers = 176 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[shift_channels] +from=204 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[control_channels] +from=208 + +[yolo] +mask = 3,4,5 +anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +classes=80 +num=12 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-5 + +[route] +layers = 189 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=768 +activation=silu + +[shift_channels] +from=205 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[control_channels] +from=209 + +[yolo] +mask = 6,7,8 +anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +classes=80 +num=12 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-6 + +[route] +layers = 202 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=silu + +[shift_channels] +from=206 + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[control_channels] +from=210 + +[yolo] +mask = 9,10,11 +anchors = 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 +classes=80 +num=12 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + +# ============ End of Head ============ # diff --git a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_csp.cfg b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_csp.cfg index 487dc48ad6b2bcd52f4cbc32049d964d40bcc076..c387ce968e193fa396e920c40914fb3fa5640df1 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_csp.cfg +++ b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_csp.cfg @@ -1,1334 +1,1334 @@ -[net] -# Testing -#batch=1 -#subdivisions=1 -# Training -batch=64 -subdivisions=8 -width=512 -height=512 -channels=3 -momentum=0.949 -decay=0.0005 -angle=0 -saturation = 1.5 -exposure = 1.5 -hue=.1 - -learning_rate=0.00261 -burn_in=1000 -max_batches = 500500 -policy=steps -steps=400000,450000 -scales=.1,.1 - -#cutmix=1 -mosaic=1 - - -# ============ Backbone ============ # - -# Stem - -# 0 -[convolutional] -batch_normalize=1 -filters=32 -size=3 -stride=1 -pad=1 -activation=silu - -# P1 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=2 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=32 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=silu - -# 4 (previous+1+3k) -[shortcut] -from=-3 -activation=linear - -# P2 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-10 - -# Transition last - -# 17 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -# P3 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1 -(4+3k)] - -[route] -layers = -1,-28 - -# Transition last - -# 48 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -# P4 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1 -(3k+4)] - -[route] -layers = -1,-28 - -# Transition last - -# 79 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# P5 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=1024 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1 -(3k+4)] - -[route] -layers = -1,-16 - -# Transition last - -# 98 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=1024 -size=1 -stride=1 -pad=1 -activation=silu - -# ============ End of Backbone ============ # - -# ============ Neck ============ # - -# CSPSPP - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -### SPP ### -[maxpool] -stride=1 -size=5 - -[route] -layers=-2 - -[maxpool] -stride=1 -size=9 - -[route] -layers=-4 - -[maxpool] -stride=1 -size=13 - -[route] -layers=-1,-3,-5,-6 -### End SPP ### - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[route] -layers = -1, -13 - -# 113 (previous+6+5+2k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# End of CSPSPP - - -# FPN-4 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[upsample] -stride=2 - -[route] -layers = 79 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -6 - -# Transition last - -# 127 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - - -# FPN-3 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[upsample] -stride=2 - -[route] -layers = 48 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=silu - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=silu - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -6 - -# Transition last - -# 141 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=silu - - -# PAN-4 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=256 -activation=silu - -[route] -layers = -1, 127 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -[route] -layers = -1,-6 - -# Transition last - -# 152 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=silu - - -# PAN-5 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=512 -activation=silu - -[route] -layers = -1, 113 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[route] -layers = -1,-6 - -# Transition last - -# 163 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=silu - -# ============ End of Neck ============ # - -# ============ Head ============ # - -# YOLO-3 - -[route] -layers = 141 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=silu - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[yolo] -mask = 0,1,2 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-4 - -[route] -layers = 152 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=silu - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[yolo] -mask = 3,4,5 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-5 - -[route] -layers = 163 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1024 -activation=silu - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[yolo] -mask = 6,7,8 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 +[net] +# Testing +#batch=1 +#subdivisions=1 +# Training +batch=64 +subdivisions=8 +width=512 +height=512 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.00261 +burn_in=1000 +max_batches = 500500 +policy=steps +steps=400000,450000 +scales=.1,.1 + +#cutmix=1 +mosaic=1 + + +# ============ Backbone ============ # + +# Stem + +# 0 +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=silu + +# P1 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=silu + +# 4 (previous+1+3k) +[shortcut] +from=-3 +activation=linear + +# P2 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-10 + +# Transition last + +# 17 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +# P3 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1 -(4+3k)] + +[route] +layers = -1,-28 + +# Transition last + +# 48 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +# P4 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1 -(3k+4)] + +[route] +layers = -1,-28 + +# Transition last + +# 79 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# P5 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1 -(3k+4)] + +[route] +layers = -1,-16 + +# Transition last + +# 98 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=silu + +# ============ End of Backbone ============ # + +# ============ Neck ============ # + +# CSPSPP + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[route] +layers = -1, -13 + +# 113 (previous+6+5+2k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# End of CSPSPP + + +# FPN-4 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[upsample] +stride=2 + +[route] +layers = 79 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -6 + +# Transition last + +# 127 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + + +# FPN-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[upsample] +stride=2 + +[route] +layers = 48 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=silu + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=silu + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -6 + +# Transition last + +# 141 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=silu + + +# PAN-4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=256 +activation=silu + +[route] +layers = -1, 127 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +[route] +layers = -1,-6 + +# Transition last + +# 152 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=silu + + +# PAN-5 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=512 +activation=silu + +[route] +layers = -1, 113 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[route] +layers = -1,-6 + +# Transition last + +# 163 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=silu + +# ============ End of Neck ============ # + +# ============ Head ============ # + +# YOLO-3 + +[route] +layers = 141 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=silu + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[yolo] +mask = 0,1,2 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-4 + +[route] +layers = 152 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=silu + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[yolo] +mask = 3,4,5 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-5 + +[route] +layers = 163 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=silu + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[yolo] +mask = 6,7,8 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 diff --git a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_csp_x.cfg b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_csp_x.cfg index 2816f2a0168322dab6ad5c79d189c94da0f3a5b6..285abc4d871f4313e631fcf6c1d090f2e389d636 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_csp_x.cfg +++ b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_csp_x.cfg @@ -1,1534 +1,1534 @@ -[net] -# Testing -#batch=1 -#subdivisions=1 -# Training -batch=64 -subdivisions=8 -width=512 -height=512 -channels=3 -momentum=0.949 -decay=0.0005 -angle=0 -saturation = 1.5 -exposure = 1.5 -hue=.1 - -learning_rate=0.00261 -burn_in=1000 -max_batches = 500500 -policy=steps -steps=400000,450000 -scales=.1,.1 - -#cutmix=1 -mosaic=1 - - -# ============ Backbone ============ # - -# Stem - -# 0 -[convolutional] -batch_normalize=1 -filters=32 -size=3 -stride=1 -pad=1 -activation=silu - -# P1 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=2 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=40 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=silu - -# 4 (previous+1+3k) -[shortcut] -from=-3 -activation=linear - -# P2 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-13 - -# Transition last - -# 20 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -# P3 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1 -(4+3k)] - -[route] -layers = -1,-34 - -# Transition last - -# 57 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -# P4 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1 -(3k+4)] - -[route] -layers = -1,-34 - -# Transition last - -# 94 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -# P5 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=1280 -size=3 -stride=2 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=silu - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -# Merge [-1 -(3k+4)] - -[route] -layers = -1,-19 - -# Transition last - -# 116 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=1280 -size=1 -stride=1 -pad=1 -activation=silu - -# ============ End of Backbone ============ # - -# ============ Neck ============ # - -# CSPSPP - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -### SPP ### -[maxpool] -stride=1 -size=5 - -[route] -layers=-2 - -[maxpool] -stride=1 -size=9 - -[route] -layers=-4 - -[maxpool] -stride=1 -size=13 - -[route] -layers=-1,-3,-5,-6 -### End SPP ### - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=silu - -[route] -layers = -1, -15 - -# 133 (previous+6+5+2k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -# End of CSPSPP - - -# FPN-4 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[upsample] -stride=2 - -[route] -layers = 94 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=silu - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 149 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - - -# FPN-3 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[upsample] -stride=2 - -[route] -layers = 57 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=160 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=160 -activation=silu - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=160 -activation=silu - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 165 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=silu - - -# PAN-4 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=320 -activation=silu - -[route] -layers = -1, 149 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=silu - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=silu - -[route] -layers = -1,-8 - -# Transition last - -# 178 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=silu - - -# PAN-5 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=640 -activation=silu - -[route] -layers = -1, 133 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -# Split - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=silu - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=silu - -[route] -layers = -1,-8 - -# Transition last - -# 191 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=silu - -# ============ End of Neck ============ # - -# ============ Head ============ # - -# YOLO-3 - -[route] -layers = 165 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=silu - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[yolo] -mask = 0,1,2 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-4 - -[route] -layers = 178 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=silu - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[yolo] -mask = 3,4,5 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-5 - -[route] -layers = 191 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1280 -activation=silu - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=linear - -[yolo] -mask = 6,7,8 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 +[net] +# Testing +#batch=1 +#subdivisions=1 +# Training +batch=64 +subdivisions=8 +width=512 +height=512 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.00261 +burn_in=1000 +max_batches = 500500 +policy=steps +steps=400000,450000 +scales=.1,.1 + +#cutmix=1 +mosaic=1 + + +# ============ Backbone ============ # + +# Stem + +# 0 +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=silu + +# P1 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=2 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=40 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=silu + +# 4 (previous+1+3k) +[shortcut] +from=-3 +activation=linear + +# P2 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-13 + +# Transition last + +# 20 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +# P3 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1 -(4+3k)] + +[route] +layers = -1,-34 + +# Transition last + +# 57 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +# P4 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1 -(3k+4)] + +[route] +layers = -1,-34 + +# Transition last + +# 94 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +# P5 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1280 +size=3 +stride=2 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=silu + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +# Merge [-1 -(3k+4)] + +[route] +layers = -1,-19 + +# Transition last + +# 116 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=1280 +size=1 +stride=1 +pad=1 +activation=silu + +# ============ End of Backbone ============ # + +# ============ Neck ============ # + +# CSPSPP + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=silu + +[route] +layers = -1, -15 + +# 133 (previous+6+5+2k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +# End of CSPSPP + + +# FPN-4 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[upsample] +stride=2 + +[route] +layers = 94 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=silu + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 149 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + + +# FPN-3 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[upsample] +stride=2 + +[route] +layers = 57 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=silu + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=silu + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 165 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=silu + + +# PAN-4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=320 +activation=silu + +[route] +layers = -1, 149 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=silu + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=silu + +[route] +layers = -1,-8 + +# Transition last + +# 178 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=silu + + +# PAN-5 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=640 +activation=silu + +[route] +layers = -1, 133 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +# Split + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=silu + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=silu + +[route] +layers = -1,-8 + +# Transition last + +# 191 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=silu + +# ============ End of Neck ============ # + +# ============ Head ============ # + +# YOLO-3 + +[route] +layers = 165 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=silu + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[yolo] +mask = 0,1,2 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-4 + +[route] +layers = 178 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=silu + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[yolo] +mask = 3,4,5 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-5 + +[route] +layers = 191 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1280 +activation=silu + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[yolo] +mask = 6,7,8 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 diff --git a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_p6.cfg b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_p6.cfg index 3a891329249e9530986be3ad5b0675917d14ae58..1a4088414ba37efa2aca4cf9d20c45aa21458d3d 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_p6.cfg +++ b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_p6.cfg @@ -1,2260 +1,2260 @@ -[net] -batch=64 -subdivisions=8 -width=1280 -height=1280 -channels=3 -momentum=0.949 -decay=0.0005 -angle=0 -saturation = 1.5 -exposure = 1.5 -hue=.1 - -learning_rate=0.00261 -burn_in=1000 -max_batches = 500500 -policy=steps -steps=400000,450000 -scales=.1,.1 - -mosaic=1 - - -# ============ Backbone ============ # - -# Stem - -# 0 -[convolutional] -batch_normalize=1 -filters=32 -size=3 -stride=1 -pad=1 -activation=mish - - -# P1 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=2 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=32 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=32 -size=1 -stride=1 -pad=1 -activation=mish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=32 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=32 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=32 -size=1 -stride=1 -pad=1 -activation=mish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-7 - -# Transition last - -# 10 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=mish - - -# P2 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=2 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=mish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=mish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-13 - -# Transition last - -# 26 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - - -# P3 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=2 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-49 - -# Transition last - -# 78 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - - -# P4 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=2 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-49 - -# Transition last - -# 130 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - - -# P5 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=1024 -size=3 -stride=2 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-25 - -# Transition last - -# 158 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=1024 -size=1 -stride=1 -pad=1 -activation=mish - - -# P6 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=1024 -size=3 -stride=2 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-25 - -# Transition last - -# 186 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=1024 -size=1 -stride=1 -pad=1 -activation=mish - -# ============ End of Backbone ============ # - -# ============ Neck ============ # - -# CSPSPP - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -### SPP ### -[maxpool] -stride=1 -size=5 - -[route] -layers=-2 - -[maxpool] -stride=1 -size=9 - -[route] -layers=-4 - -[maxpool] -stride=1 -size=13 - -[route] -layers=-1,-3,-5,-6 -### End SPP ### - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=mish - -[route] -layers = -1, -13 - -# 201 (previous+6+5+2k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -# End of CSPSPP - - -# FPN-5 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[upsample] -stride=2 - -[route] -layers = 158 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=mish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 217 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - - -# FPN-4 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[upsample] -stride=2 - -[route] -layers = 130 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=mish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 233 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - - -# FPN-3 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[upsample] -stride=2 - -[route] -layers = 78 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=mish - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=mish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 249 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=mish - - -# PAN-4 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=256 -activation=mish - -[route] -layers = -1, 233 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=mish - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=mish - -[route] -layers = -1,-8 - -# Transition last - -# 262 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=mish - - -# PAN-5 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=512 -activation=mish - -[route] -layers = -1, 217 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=mish - -[route] -layers = -1,-8 - -# Transition last - -# 275 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - - -# PAN-6 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=512 -activation=mish - -[route] -layers = -1, 201 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=mish - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=mish - -[route] -layers = -1,-8 - -# Transition last - -# 288 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=mish - -# ============ End of Neck ============ # - -# ============ Head ============ # - -# YOLO-3 - -[route] -layers = 249 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=mish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=340 -activation=linear - -[yolo] -mask = 0,1,2,3 -anchors = 13,17, 31,25, 24,51, 61,45, 61,45, 48,102, 119,96, 97,189, 97,189, 217,184, 171,384, 324,451, 324,451, 545,357, 616,618, 1024,1024 -classes=80 -num=16 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-4 - -[route] -layers = 262 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=mish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=340 -activation=linear - -[yolo] -mask = 4,5,6,7 -anchors = 13,17, 31,25, 24,51, 61,45, 61,45, 48,102, 119,96, 97,189, 97,189, 217,184, 171,384, 324,451, 324,451, 545,357, 616,618, 1024,1024 -classes=80 -num=16 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-5 - -[route] -layers = 275 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1024 -activation=mish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=340 -activation=linear - -[yolo] -mask = 8,9,10,11 -anchors = 13,17, 31,25, 24,51, 61,45, 61,45, 48,102, 119,96, 97,189, 97,189, 217,184, 171,384, 324,451, 324,451, 545,357, 616,618, 1024,1024 -classes=80 -num=16 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-6 - -[route] -layers = 288 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1024 -activation=mish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=340 -activation=linear - -[yolo] -mask = 12,13,14,15 -anchors = 13,17, 31,25, 24,51, 61,45, 61,45, 48,102, 119,96, 97,189, 97,189, 217,184, 171,384, 324,451, 324,451, 545,357, 616,618, 1024,1024 -classes=80 -num=16 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - -# ============ End of Head ============ # +[net] +batch=64 +subdivisions=8 +width=1280 +height=1280 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.00261 +burn_in=1000 +max_batches = 500500 +policy=steps +steps=400000,450000 +scales=.1,.1 + +mosaic=1 + + +# ============ Backbone ============ # + +# Stem + +# 0 +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=mish + + +# P1 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=mish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=mish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-7 + +# Transition last + +# 10 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + + +# P2 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-13 + +# Transition last + +# 26 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + + +# P3 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-49 + +# Transition last + +# 78 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + + +# P4 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-49 + +# Transition last + +# 130 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + + +# P5 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-25 + +# Transition last + +# 158 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=mish + + +# P6 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-25 + +# Transition last + +# 186 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=mish + +# ============ End of Backbone ============ # + +# ============ Neck ============ # + +# CSPSPP + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[route] +layers = -1, -13 + +# 201 (previous+6+5+2k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +# End of CSPSPP + + +# FPN-5 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[upsample] +stride=2 + +[route] +layers = 158 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 217 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + + +# FPN-4 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[upsample] +stride=2 + +[route] +layers = 130 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=mish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 233 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + + +# FPN-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[upsample] +stride=2 + +[route] +layers = 78 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=mish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 249 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + + +# PAN-4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=256 +activation=mish + +[route] +layers = -1, 233 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=mish + +[route] +layers = -1,-8 + +# Transition last + +# 262 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + + +# PAN-5 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=512 +activation=mish + +[route] +layers = -1, 217 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[route] +layers = -1,-8 + +# Transition last + +# 275 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + + +# PAN-6 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=512 +activation=mish + +[route] +layers = -1, 201 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[route] +layers = -1,-8 + +# Transition last + +# 288 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +# ============ End of Neck ============ # + +# ============ Head ============ # + +# YOLO-3 + +[route] +layers = 249 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=340 +activation=linear + +[yolo] +mask = 0,1,2,3 +anchors = 13,17, 31,25, 24,51, 61,45, 61,45, 48,102, 119,96, 97,189, 97,189, 217,184, 171,384, 324,451, 324,451, 545,357, 616,618, 1024,1024 +classes=80 +num=16 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-4 + +[route] +layers = 262 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=340 +activation=linear + +[yolo] +mask = 4,5,6,7 +anchors = 13,17, 31,25, 24,51, 61,45, 61,45, 48,102, 119,96, 97,189, 97,189, 217,184, 171,384, 324,451, 324,451, 545,357, 616,618, 1024,1024 +classes=80 +num=16 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-5 + +[route] +layers = 275 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=340 +activation=linear + +[yolo] +mask = 8,9,10,11 +anchors = 13,17, 31,25, 24,51, 61,45, 61,45, 48,102, 119,96, 97,189, 97,189, 217,184, 171,384, 324,451, 324,451, 545,357, 616,618, 1024,1024 +classes=80 +num=16 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-6 + +[route] +layers = 288 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=340 +activation=linear + +[yolo] +mask = 12,13,14,15 +anchors = 13,17, 31,25, 24,51, 61,45, 61,45, 48,102, 119,96, 97,189, 97,189, 217,184, 171,384, 324,451, 324,451, 545,357, 616,618, 1024,1024 +classes=80 +num=16 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + +# ============ End of Head ============ # diff --git a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_p7.cfg b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_p7.cfg index 18cea793b05235297561dbefa2eba74677d37e6e..10379a0e759265d9cc39c8926e2606f46fa1083b 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_p7.cfg +++ b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov4_p7.cfg @@ -1,2714 +1,2714 @@ -[net] -batch=64 -subdivisions=8 -width=1536 -height=1536 -channels=3 -momentum=0.949 -decay=0.0005 -angle=0 -saturation = 1.5 -exposure = 1.5 -hue=.1 - -learning_rate=0.00261 -burn_in=1000 -max_batches = 500500 -policy=steps -steps=400000,450000 -scales=.1,.1 - -mosaic=1 - - -# ============ Backbone ============ # - -# Stem - -# 0 -[convolutional] -batch_normalize=1 -filters=40 -size=3 -stride=1 -pad=1 -activation=mish - - -# P1 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=2 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=40 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=40 -size=1 -stride=1 -pad=1 -activation=mish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=40 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=40 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=40 -size=1 -stride=1 -pad=1 -activation=mish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-7 - -# Transition last - -# 10 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=mish - - -# P2 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=2 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=mish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=mish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-13 - -# Transition last - -# 26 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - - -# P3 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=2 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-49 - -# Transition last - -# 78 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - - -# P4 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=2 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-49 - -# Transition last - -# 130 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - - -# P5 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=1280 -size=3 -stride=2 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-25 - -# Transition last - -# 158 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=1280 -size=1 -stride=1 -pad=1 -activation=mish - - -# P6 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=1280 -size=3 -stride=2 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-25 - -# Transition last - -# 186 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=1280 -size=1 -stride=1 -pad=1 -activation=mish - - -# P7 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=1280 -size=3 -stride=2 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=mish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-25 - -# Transition last - -# 214 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=1280 -size=1 -stride=1 -pad=1 -activation=mish - -# ============ End of Backbone ============ # - -# ============ Neck ============ # - -# CSPSPP - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -### SPP ### -[maxpool] -stride=1 -size=5 - -[route] -layers=-2 - -[maxpool] -stride=1 -size=9 - -[route] -layers=-4 - -[maxpool] -stride=1 -size=13 - -[route] -layers=-1,-3,-5,-6 -### End SPP ### - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[route] -layers = -1, -13 - -# 229 (previous+6+5+2k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -# End of CSPSPP - - -# FPN-6 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[upsample] -stride=2 - -[route] -layers = 186 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 245 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - - -# FPN-5 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[upsample] -stride=2 - -[route] -layers = 158 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 261 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - - -# FPN-4 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[upsample] -stride=2 - -[route] -layers = 130 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=mish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 277 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - - -# FPN-3 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[upsample] -stride=2 - -[route] -layers = 78 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=160 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=160 -activation=mish - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=160 -activation=mish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 293 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=mish - - -# PAN-4 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=320 -activation=mish - -[route] -layers = -1, 277 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=mish - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=mish - -[route] -layers = -1,-8 - -# Transition last - -# 306 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=mish - - -# PAN-5 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=640 -activation=mish - -[route] -layers = -1, 261 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[route] -layers = -1,-8 - -# Transition last - -# 319 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - - -# PAN-6 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=640 -activation=mish - -[route] -layers = -1, 245 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[route] -layers = -1,-8 - -# Transition last - -# 332 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - - -# PAN-7 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=640 -activation=mish - -[route] -layers = -1, 229 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -# Split - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[route] -layers = -1,-8 - -# Transition last - -# 345 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=mish - -# ============ End of Neck ============ # - -# ============ Head ============ # - -# YOLO-3 - -[route] -layers = 293 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=mish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=340 -activation=linear - -[yolo] -mask = 0,1,2,3 -anchors = 13,17, 22,25, 27,66, 55,41, 57,88, 112,69, 69,177, 136,138, 136,138, 287,114, 134,275, 268,248, 268,248, 232,504, 445,416, 640,640, 812,393, 477,808, 1070,908, 1408,1408 -classes=80 -num=20 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-4 - -[route] -layers = 306 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=mish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=340 -activation=linear - -[yolo] -mask = 4,5,6,7 -anchors = 13,17, 22,25, 27,66, 55,41, 57,88, 112,69, 69,177, 136,138, 136,138, 287,114, 134,275, 268,248, 268,248, 232,504, 445,416, 640,640, 812,393, 477,808, 1070,908, 1408,1408 -classes=80 -num=20 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-5 - -[route] -layers = 319 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1280 -activation=mish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=340 -activation=linear - -[yolo] -mask = 8,9,10,11 -anchors = 13,17, 22,25, 27,66, 55,41, 57,88, 112,69, 69,177, 136,138, 136,138, 287,114, 134,275, 268,248, 268,248, 232,504, 445,416, 640,640, 812,393, 477,808, 1070,908, 1408,1408 -classes=80 -num=20 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-6 - -[route] -layers = 332 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1280 -activation=mish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=340 -activation=linear - -[yolo] -mask = 12,13,14,15 -anchors = 13,17, 22,25, 27,66, 55,41, 57,88, 112,69, 69,177, 136,138, 136,138, 287,114, 134,275, 268,248, 268,248, 232,504, 445,416, 640,640, 812,393, 477,808, 1070,908, 1408,1408 -classes=80 -num=20 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - - -# YOLO-7 - -[route] -layers = 345 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1280 -activation=mish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=340 -activation=linear - -[yolo] -mask = 16,17,18,19 -anchors = 13,17, 22,25, 27,66, 55,41, 57,88, 112,69, 69,177, 136,138, 136,138, 287,114, 134,275, 268,248, 268,248, 232,504, 445,416, 640,640, 812,393, 477,808, 1070,908, 1408,1408 -classes=80 -num=20 -jitter=.3 -ignore_thresh = .7 -truth_thresh = 1 -random=1 -scale_x_y = 1.05 -iou_thresh=0.213 -cls_normalizer=1.0 -iou_normalizer=0.07 -iou_loss=ciou -nms_kind=greedynms -beta_nms=0.6 - -# ============ End of Head ============ # +[net] +batch=64 +subdivisions=8 +width=1536 +height=1536 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.00261 +burn_in=1000 +max_batches = 500500 +policy=steps +steps=400000,450000 +scales=.1,.1 + +mosaic=1 + + +# ============ Backbone ============ # + +# Stem + +# 0 +[convolutional] +batch_normalize=1 +filters=40 +size=3 +stride=1 +pad=1 +activation=mish + + +# P1 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=2 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=40 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=40 +size=1 +stride=1 +pad=1 +activation=mish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=40 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=40 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=40 +size=1 +stride=1 +pad=1 +activation=mish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-7 + +# Transition last + +# 10 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=mish + + +# P2 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=2 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=mish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=mish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-13 + +# Transition last + +# 26 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + + +# P3 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=2 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-49 + +# Transition last + +# 78 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + + +# P4 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=2 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-49 + +# Transition last + +# 130 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + + +# P5 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1280 +size=3 +stride=2 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-25 + +# Transition last + +# 158 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=1280 +size=1 +stride=1 +pad=1 +activation=mish + + +# P6 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1280 +size=3 +stride=2 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-25 + +# Transition last + +# 186 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=1280 +size=1 +stride=1 +pad=1 +activation=mish + + +# P7 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1280 +size=3 +stride=2 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-25 + +# Transition last + +# 214 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=1280 +size=1 +stride=1 +pad=1 +activation=mish + +# ============ End of Backbone ============ # + +# ============ Neck ============ # + +# CSPSPP + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[route] +layers = -1, -13 + +# 229 (previous+6+5+2k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +# End of CSPSPP + + +# FPN-6 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[upsample] +stride=2 + +[route] +layers = 186 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 245 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + + +# FPN-5 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[upsample] +stride=2 + +[route] +layers = 158 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 261 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + + +# FPN-4 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[upsample] +stride=2 + +[route] +layers = 130 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=mish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 277 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + + +# FPN-3 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[upsample] +stride=2 + +[route] +layers = 78 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=mish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 293 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + + +# PAN-4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=320 +activation=mish + +[route] +layers = -1, 277 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=mish + +[route] +layers = -1,-8 + +# Transition last + +# 306 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + + +# PAN-5 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=640 +activation=mish + +[route] +layers = -1, 261 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[route] +layers = -1,-8 + +# Transition last + +# 319 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + + +# PAN-6 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=640 +activation=mish + +[route] +layers = -1, 245 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[route] +layers = -1,-8 + +# Transition last + +# 332 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + + +# PAN-7 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=640 +activation=mish + +[route] +layers = -1, 229 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +# Split + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[route] +layers = -1,-8 + +# Transition last + +# 345 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +# ============ End of Neck ============ # + +# ============ Head ============ # + +# YOLO-3 + +[route] +layers = 293 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=340 +activation=linear + +[yolo] +mask = 0,1,2,3 +anchors = 13,17, 22,25, 27,66, 55,41, 57,88, 112,69, 69,177, 136,138, 136,138, 287,114, 134,275, 268,248, 268,248, 232,504, 445,416, 640,640, 812,393, 477,808, 1070,908, 1408,1408 +classes=80 +num=20 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-4 + +[route] +layers = 306 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=340 +activation=linear + +[yolo] +mask = 4,5,6,7 +anchors = 13,17, 22,25, 27,66, 55,41, 57,88, 112,69, 69,177, 136,138, 136,138, 287,114, 134,275, 268,248, 268,248, 232,504, 445,416, 640,640, 812,393, 477,808, 1070,908, 1408,1408 +classes=80 +num=20 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-5 + +[route] +layers = 319 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1280 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=340 +activation=linear + +[yolo] +mask = 8,9,10,11 +anchors = 13,17, 22,25, 27,66, 55,41, 57,88, 112,69, 69,177, 136,138, 136,138, 287,114, 134,275, 268,248, 268,248, 232,504, 445,416, 640,640, 812,393, 477,808, 1070,908, 1408,1408 +classes=80 +num=20 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-6 + +[route] +layers = 332 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1280 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=340 +activation=linear + +[yolo] +mask = 12,13,14,15 +anchors = 13,17, 22,25, 27,66, 55,41, 57,88, 112,69, 69,177, 136,138, 136,138, 287,114, 134,275, 268,248, 268,248, 232,504, 445,416, 640,640, 812,393, 477,808, 1070,908, 1408,1408 +classes=80 +num=20 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +# YOLO-7 + +[route] +layers = 345 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1280 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=340 +activation=linear + +[yolo] +mask = 16,17,18,19 +anchors = 13,17, 22,25, 27,66, 55,41, 57,88, 112,69, 69,177, 136,138, 136,138, 287,114, 134,275, 268,248, 268,248, 232,504, 445,416, 640,640, 812,393, 477,808, 1070,908, 1408,1408 +classes=80 +num=20 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + +# ============ End of Head ============ # diff --git a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov5x.cfg b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov5x.cfg index 1c62dc4b192ee7bbc74fb039a0022403218b0f38..c06c663f2cde20418cc1c47d9cbdbf871ccbf66c 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov5x.cfg +++ b/PyTorch/contrib/cv/detection/YOLOR/cfg/yolov5x.cfg @@ -1,43 +1,43 @@ -nc: 80 -depth_multiple: 1.33 -width_multiple: 1.25 - -anchors: - - [10,13, 16,30 33,23] - - [30,61, 62,45, 59,119] - - [116,90, 156,198, 373,326] - -backbone: - [[-1, 1, Focus, [64,3]], - [-1, 1, Conv, [128, 3, 2]], - [-1, 3, BottleneckCSP, [128]], - [-1, 1, Conv, [256, 3, 2]], - [-1, 3, BottleneckCSP, [256]], - [-1, 1, Conv, [512, 3, 2]], - [-1, 3, BottleneckCSP, [512]], - [-1, 1, Conv, [1024, 3, 2]], - [-1, 1, SPP, [1024, [5, 9, 13]]], - [-1, 3, BottleneckCSP, [1024, False]], - ] - -head: - [[-1, 1, Conv, [512, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 6], 1, Concat, [1]], - [-1, 3, BottleneckCSP, [512, False]], - - [-1, 1, Conv, [256, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 4], 1, Concat, [1]], - [-1, 3, BottleneckCSP, [256, False]], - - [-1, 1, Conv, [256, 3, 2]], - [[-1, 14], 1, Concat, [1]], - [-1, 3, BottleneckCSP, [512, False]], - - [-1, 1, Conv, [512, 3, 2]], - [[-1, 10], 1, Concat, [1]], - [-1, 3, BottleneckCSP, [1024, False]], - - [[17, 20, 23], 1, Detect, [nc, anchors]], - ] +nc: 80 +depth_multiple: 1.33 +width_multiple: 1.25 + +anchors: + - [10,13, 16,30 33,23] + - [30,61, 62,45, 59,119] + - [116,90, 156,198, 373,326] + +backbone: + [[-1, 1, Focus, [64,3]], + [-1, 1, Conv, [128, 3, 2]], + [-1, 3, BottleneckCSP, [128]], + [-1, 1, Conv, [256, 3, 2]], + [-1, 3, BottleneckCSP, [256]], + [-1, 1, Conv, [512, 3, 2]], + [-1, 3, BottleneckCSP, [512]], + [-1, 1, Conv, [1024, 3, 2]], + [-1, 1, SPP, [1024, [5, 9, 13]]], + [-1, 3, BottleneckCSP, [1024, False]], + ] + +head: + [[-1, 1, Conv, [512, 1, 1]], + [-1, 1, nn.Upsample, [None, 2, 'nearest']], + [[-1, 6], 1, Concat, [1]], + [-1, 3, BottleneckCSP, [512, False]], + + [-1, 1, Conv, [256, 1, 1]], + [-1, 1, nn.Upsample, [None, 2, 'nearest']], + [[-1, 4], 1, Concat, [1]], + [-1, 3, BottleneckCSP, [256, False]], + + [-1, 1, Conv, [256, 3, 2]], + [[-1, 14], 1, Concat, [1]], + [-1, 3, BottleneckCSP, [512, False]], + + [-1, 1, Conv, [512, 3, 2]], + [[-1, 10], 1, Concat, [1]], + [-1, 3, BottleneckCSP, [1024, False]], + + [[17, 20, 23], 1, Detect, [nc, anchors]], + ] diff --git a/PyTorch/contrib/cv/detection/YOLOR/darknet/README.md b/PyTorch/contrib/cv/detection/YOLOR/darknet/README.md index 1d3d11e054d320a1b11ae0ed2a92cbaf10ed302a..d2fc579741572cb0eaa03ca74598eee6da50985f 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/darknet/README.md +++ b/PyTorch/contrib/cv/detection/YOLOR/darknet/README.md @@ -1,63 +1,63 @@ -## Model Zoo - -| Model | Test Size | APval | AP50val | AP75val | APSval | APMval | APLval | batch1 throughput | -| :-- | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | -| **YOLOv4-CSP** | 640 | **49.1%** | **67.7%** | **53.8%** | **32.1%** | **54.4%** | **63.2%** | 76 *fps* | -| **YOLOR-CSP** | 640 | **49.2%** | **67.6%** | **53.7%** | **32.9%** | **54.4%** | **63.0%** | - | -| | | | | | | | -| **YOLOv4-CSP-X** | 640 | **50.9%** | **69.3%** | **55.4%** | **35.3%** | **55.8%** | **64.8%** | 53 *fps* | -| **YOLOR-CSP-X** | 640 | **51.1%** | **69.6%** | **55.7%** | **35.7%** | **56.0%** | **65.2%** | - | -| | | | | | | | - -## Installation - -https://github.com/AlexeyAB/darknet - -Docker environment (recommended) -
Expand - -``` -# get code -git clone https://github.com/AlexeyAB/darknet - -# create the docker container, you can change the share memory size if you have more. -nvidia-docker run --name yolor -it -v your_coco_path/:/coco/ -v your_code_path/:/yolor --shm-size=64g nvcr.io/nvidia/pytorch:21.02-py3 - -# apt install required packages -apt update -apt install -y libopencv-dev - -# edit Makefile -#GPU=1 -#CUDNN=1 -#CUDNN_HALF=1 -#OPENCV=1 -#AVX=1 -#OPENMP=1 -#LIBSO=1 -#ZED_CAMERA=0 -#ZED_CAMERA_v2_8=0 -# -#USE_CPP=0 -#DEBUG=0 -# -#ARCH= -gencode arch=compute_52,code=[sm_70,compute_70] \ -# -gencode arch=compute_61,code=[sm_75,compute_75] \ -# -gencode arch=compute_61,code=[sm_80,compute_80] \ -# -gencode arch=compute_61,code=[sm_86,compute_86] -# -#... - -# build -make -j8 -``` - -
- -## Testing - -To reproduce inference speed, using: - -``` -CUDA_VISIBLE_DEVICES=0 ./darknet detector demo cfg/coco.data cfg/yolov4-csp.cfg weights/yolov4-csp.weights source/test.mp4 -dont_show -benchmark -``` +## Model Zoo + +| Model | Test Size | APval | AP50val | AP75val | APSval | APMval | APLval | batch1 throughput | +| :-- | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | +| **YOLOv4-CSP** | 640 | **49.1%** | **67.7%** | **53.8%** | **32.1%** | **54.4%** | **63.2%** | 76 *fps* | +| **YOLOR-CSP** | 640 | **49.2%** | **67.6%** | **53.7%** | **32.9%** | **54.4%** | **63.0%** | - | +| | | | | | | | +| **YOLOv4-CSP-X** | 640 | **50.9%** | **69.3%** | **55.4%** | **35.3%** | **55.8%** | **64.8%** | 53 *fps* | +| **YOLOR-CSP-X** | 640 | **51.1%** | **69.6%** | **55.7%** | **35.7%** | **56.0%** | **65.2%** | - | +| | | | | | | | + +## Installation + +https://github.com/AlexeyAB/darknet + +Docker environment (recommended) +
Expand + +``` +# get code +git clone https://github.com/AlexeyAB/darknet + +# create the docker container, you can change the share memory size if you have more. +nvidia-docker run --name yolor -it -v your_coco_path/:/coco/ -v your_code_path/:/yolor --shm-size=64g nvcr.io/nvidia/pytorch:21.02-py3 + +# apt install required packages +apt update +apt install -y libopencv-dev + +# edit Makefile +#GPU=1 +#CUDNN=1 +#CUDNN_HALF=1 +#OPENCV=1 +#AVX=1 +#OPENMP=1 +#LIBSO=1 +#ZED_CAMERA=0 +#ZED_CAMERA_v2_8=0 +# +#USE_CPP=0 +#DEBUG=0 +# +#ARCH= -gencode arch=compute_52,code=[sm_70,compute_70] \ +# -gencode arch=compute_61,code=[sm_75,compute_75] \ +# -gencode arch=compute_61,code=[sm_80,compute_80] \ +# -gencode arch=compute_61,code=[sm_86,compute_86] +# +#... + +# build +make -j8 +``` + +
+ +## Testing + +To reproduce inference speed, using: + +``` +CUDA_VISIBLE_DEVICES=0 ./darknet detector demo cfg/coco.data cfg/yolov4-csp.cfg weights/yolov4-csp.weights source/test.mp4 -dont_show -benchmark +``` diff --git a/PyTorch/contrib/cv/detection/YOLOR/darknet/cfg/yolov4-csp-x.cfg b/PyTorch/contrib/cv/detection/YOLOR/darknet/cfg/yolov4-csp-x.cfg index cdb71565ac1cd97d79c0c334da9b3d193a624f09..e7acf9ef4e49aa9d97ddfe41f72447ac033804cf 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/darknet/cfg/yolov4-csp-x.cfg +++ b/PyTorch/contrib/cv/detection/YOLOR/darknet/cfg/yolov4-csp-x.cfg @@ -1,1555 +1,1555 @@ - -[net] -# Testing -#batch=1 -#subdivisions=1 -# Training -batch=64 -subdivisions=8 -width=640 -height=640 -channels=3 -momentum=0.949 -decay=0.0005 -angle=0 -saturation = 1.5 -exposure = 1.5 -hue=.1 - -learning_rate=0.001 -burn_in=1000 -max_batches = 500500 -policy=steps -steps=400000,450000 -scales=.1,.1 - -mosaic=1 - -letter_box=1 - -ema_alpha=0.9998 - -#optimized_memory=1 - - -# ============ Backbone ============ # - -# Stem - -# 0 -[convolutional] -batch_normalize=1 -filters=32 -size=3 -stride=1 -pad=1 -activation=swish - -# P1 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=2 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=40 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=swish - -# 4 (previous+1+3k) -[shortcut] -from=-3 -activation=linear - -# P2 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=80 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=80 -size=1 -stride=1 -pad=1 -activation=swish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-13 - -# Transition last - -# 20 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -# P3 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=160 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -# Merge [-1 -(4+3k)] - -[route] -layers = -1,-34 - -# Transition last - -# 57 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -# P4 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -# Merge [-1 -(3k+4)] - -[route] -layers = -1,-34 - -# Transition last - -# 94 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -# P5 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=1280 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=640 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -# Merge [-1 -(3k+4)] - -[route] -layers = -1,-19 - -# Transition last - -# 116 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=1280 -size=1 -stride=1 -pad=1 -activation=swish - -# ============ End of Backbone ============ # - -# ============ Neck ============ # - -# CSPSPP - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=swish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -### SPP ### -[maxpool] -stride=1 -size=5 - -[route] -layers=-2 - -[maxpool] -stride=1 -size=9 - -[route] -layers=-4 - -[maxpool] -stride=1 -size=13 - -[route] -layers=-1,-3,-5,-6 -### End SPP ### - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=swish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=swish - -[route] -layers = -1, -15 - -# 133 (previous+6+5+2k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -# End of CSPSPP - - -# FPN-4 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[upsample] -stride=2 - -[route] -layers = 94 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 149 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - - -# FPN-3 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[upsample] -stride=2 - -[route] -layers = 57 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=160 -activation=swish - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=160 -activation=swish - -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=160 -activation=swish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -8 - -# Transition last - -# 165 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=160 -size=1 -stride=1 -pad=1 -activation=swish - - -# PAN-4 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=320 -activation=swish - -[route] -layers = -1, 149 - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[route] -layers = -1,-8 - -# Transition last - -# 178 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=320 -size=1 -stride=1 -pad=1 -activation=swish - - -# PAN-5 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=640 -activation=swish - -[route] -layers = -1, 133 - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=swish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=swish - -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=swish - -[route] -layers = -1,-8 - -# Transition last - -# 191 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=640 -size=1 -stride=1 -pad=1 -activation=swish - -# ============ End of Neck ============ # - -# ============ Head ============ # - -# YOLO-3 - -[route] -layers = 165 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=320 -activation=swish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=logistic - -[yolo] -mask = 0,1,2 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.1 -scale_x_y = 2.0 -objectness_smooth=1 -ignore_thresh = .7 -truth_thresh = 1 -#random=1 -resize=1.5 -iou_thresh=0.2 -iou_normalizer=0.05 -cls_normalizer=0.5 -obj_normalizer=0.4 -iou_loss=ciou -nms_kind=diounms -beta_nms=0.6 -new_coords=1 -max_delta=2 - - -# YOLO-4 - -[route] -layers = 178 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=640 -activation=swish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=logistic - -[yolo] -mask = 3,4,5 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.1 -scale_x_y = 2.0 -objectness_smooth=1 -ignore_thresh = .7 -truth_thresh = 1 -#random=1 -resize=1.5 -iou_thresh=0.2 -iou_normalizer=0.05 -cls_normalizer=0.5 -obj_normalizer=0.4 -iou_loss=ciou -nms_kind=diounms -beta_nms=0.6 -new_coords=1 -max_delta=2 - - -# YOLO-5 - -[route] -layers = 191 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1280 -activation=swish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=logistic - -[yolo] -mask = 6,7,8 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.1 -scale_x_y = 2.0 -objectness_smooth=1 -ignore_thresh = .7 -truth_thresh = 1 -#random=1 -resize=1.5 -iou_thresh=0.2 -iou_normalizer=0.05 -cls_normalizer=0.5 -obj_normalizer=0.4 -iou_loss=ciou -nms_kind=diounms -beta_nms=0.6 -new_coords=1 -max_delta=2 + +[net] +# Testing +#batch=1 +#subdivisions=1 +# Training +batch=64 +subdivisions=8 +width=640 +height=640 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.001 +burn_in=1000 +max_batches = 500500 +policy=steps +steps=400000,450000 +scales=.1,.1 + +mosaic=1 + +letter_box=1 + +ema_alpha=0.9998 + +#optimized_memory=1 + + +# ============ Backbone ============ # + +# Stem + +# 0 +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=swish + +# P1 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=2 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=40 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=swish + +# 4 (previous+1+3k) +[shortcut] +from=-3 +activation=linear + +# P2 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=swish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-13 + +# Transition last + +# 20 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +# P3 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +# Merge [-1 -(4+3k)] + +[route] +layers = -1,-34 + +# Transition last + +# 57 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +# P4 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +# Merge [-1 -(3k+4)] + +[route] +layers = -1,-34 + +# Transition last + +# 94 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +# P5 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1280 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +# Merge [-1 -(3k+4)] + +[route] +layers = -1,-19 + +# Transition last + +# 116 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=1280 +size=1 +stride=1 +pad=1 +activation=swish + +# ============ End of Backbone ============ # + +# ============ Neck ============ # + +# CSPSPP + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=swish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=swish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=swish + +[route] +layers = -1, -15 + +# 133 (previous+6+5+2k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +# End of CSPSPP + + +# FPN-4 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[upsample] +stride=2 + +[route] +layers = 94 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 149 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + + +# FPN-3 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[upsample] +stride=2 + +[route] +layers = 57 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=swish + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=swish + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=swish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -8 + +# Transition last + +# 165 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=swish + + +# PAN-4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=320 +activation=swish + +[route] +layers = -1, 149 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[route] +layers = -1,-8 + +# Transition last + +# 178 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=swish + + +# PAN-5 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=640 +activation=swish + +[route] +layers = -1, 133 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=swish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=swish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=swish + +[route] +layers = -1,-8 + +# Transition last + +# 191 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=swish + +# ============ End of Neck ============ # + +# ============ Head ============ # + +# YOLO-3 + +[route] +layers = 165 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=swish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=logistic + +[yolo] +mask = 0,1,2 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.1 +scale_x_y = 2.0 +objectness_smooth=1 +ignore_thresh = .7 +truth_thresh = 1 +#random=1 +resize=1.5 +iou_thresh=0.2 +iou_normalizer=0.05 +cls_normalizer=0.5 +obj_normalizer=0.4 +iou_loss=ciou +nms_kind=diounms +beta_nms=0.6 +new_coords=1 +max_delta=2 + + +# YOLO-4 + +[route] +layers = 178 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=swish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=logistic + +[yolo] +mask = 3,4,5 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.1 +scale_x_y = 2.0 +objectness_smooth=1 +ignore_thresh = .7 +truth_thresh = 1 +#random=1 +resize=1.5 +iou_thresh=0.2 +iou_normalizer=0.05 +cls_normalizer=0.5 +obj_normalizer=0.4 +iou_loss=ciou +nms_kind=diounms +beta_nms=0.6 +new_coords=1 +max_delta=2 + + +# YOLO-5 + +[route] +layers = 191 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1280 +activation=swish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=logistic + +[yolo] +mask = 6,7,8 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.1 +scale_x_y = 2.0 +objectness_smooth=1 +ignore_thresh = .7 +truth_thresh = 1 +#random=1 +resize=1.5 +iou_thresh=0.2 +iou_normalizer=0.05 +cls_normalizer=0.5 +obj_normalizer=0.4 +iou_loss=ciou +nms_kind=diounms +beta_nms=0.6 +new_coords=1 +max_delta=2 diff --git a/PyTorch/contrib/cv/detection/YOLOR/darknet/cfg/yolov4-csp.cfg b/PyTorch/contrib/cv/detection/YOLOR/darknet/cfg/yolov4-csp.cfg index fd1bdc6bdc692106e1cbf810d7be97902cb2129a..a47c9f7160e77e1aea809f5840c93498b2443978 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/darknet/cfg/yolov4-csp.cfg +++ b/PyTorch/contrib/cv/detection/YOLOR/darknet/cfg/yolov4-csp.cfg @@ -1,1354 +1,1354 @@ -[net] -# Testing -#batch=1 -#subdivisions=1 -# Training -batch=64 -subdivisions=8 -width=640 -height=640 -channels=3 -momentum=0.949 -decay=0.0005 -angle=0 -saturation = 1.5 -exposure = 1.5 -hue=.1 - -learning_rate=0.001 -burn_in=1000 -max_batches = 500500 -policy=steps -steps=400000,450000 -scales=.1,.1 - -mosaic=1 - -letter_box=1 - -ema_alpha=0.9998 - -#optimized_memory=1 - - -# ============ Backbone ============ # - -# Stem - -# 0 -[convolutional] -batch_normalize=1 -filters=32 -size=3 -stride=1 -pad=1 -activation=swish - -# P1 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=2 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=32 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=swish - -# 4 (previous+1+3k) -[shortcut] -from=-3 -activation=linear - -# P2 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=swish - -# Merge [-1, -(3k+4)] - -[route] -layers = -1,-10 - -# Transition last - -# 17 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -# P3 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -# Merge [-1 -(4+3k)] - -[route] -layers = -1,-28 - -# Transition last - -# 48 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -# P4 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -# Merge [-1 -(3k+4)] - -[route] -layers = -1,-28 - -# Transition last - -# 79 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -# P5 - -# Downsample - -[convolutional] -batch_normalize=1 -filters=1024 -size=3 -stride=2 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -# Residual Block - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=swish - -[shortcut] -from=-3 -activation=linear - -# Transition first - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -# Merge [-1 -(3k+4)] - -[route] -layers = -1,-16 - -# Transition last - -# 98 (previous+7+3k) -[convolutional] -batch_normalize=1 -filters=1024 -size=1 -stride=1 -pad=1 -activation=swish - -# ============ End of Backbone ============ # - -# ============ Neck ============ # - -# CSPSPP - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=swish - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -### SPP ### -[maxpool] -stride=1 -size=5 - -[route] -layers=-2 - -[maxpool] -stride=1 -size=9 - -[route] -layers=-4 - -[maxpool] -stride=1 -size=13 - -[route] -layers=-1,-3,-5,-6 -### End SPP ### - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=swish - -[route] -layers = -1, -13 - -# 113 (previous+6+5+2k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -# End of CSPSPP - - -# FPN-4 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[upsample] -stride=2 - -[route] -layers = 79 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -6 - -# Transition last - -# 127 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - - -# FPN-3 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[upsample] -stride=2 - -[route] -layers = 48 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -1, -3 - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=swish - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=128 -activation=swish - -# Merge [-1, -(2k+2)] - -[route] -layers = -1, -6 - -# Transition last - -# 141 (previous+6+4+2k) -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=swish - - -# PAN-4 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=256 -activation=swish - -[route] -layers = -1, 127 - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[route] -layers = -1,-6 - -# Transition last - -# 152 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=swish - - -# PAN-5 - -[convolutional] -batch_normalize=1 -size=3 -stride=2 -pad=1 -filters=512 -activation=swish - -[route] -layers = -1, 113 - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -# Split - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -[route] -layers = -2 - -# Plain Block - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=swish - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=swish - -[route] -layers = -1,-6 - -# Transition last - -# 163 (previous+3+4+2k) -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=swish - -# ============ End of Neck ============ # - -# ============ Head ============ # - -# YOLO-3 - -[route] -layers = 141 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=256 -activation=swish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=logistic - -[yolo] -mask = 0,1,2 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.1 -scale_x_y = 2.0 -objectness_smooth=1 -ignore_thresh = .7 -truth_thresh = 1 -#random=1 -resize=1.5 -iou_thresh=0.2 -iou_normalizer=0.05 -cls_normalizer=0.5 -obj_normalizer=0.4 -iou_loss=ciou -nms_kind=diounms -beta_nms=0.6 -new_coords=1 -max_delta=2 - - -# YOLO-4 - -[route] -layers = 152 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=512 -activation=swish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=logistic - -[yolo] -mask = 3,4,5 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.1 -scale_x_y = 2.0 -objectness_smooth=1 -ignore_thresh = .7 -truth_thresh = 1 -#random=1 -resize=1.5 -iou_thresh=0.2 -iou_normalizer=0.05 -cls_normalizer=0.5 -obj_normalizer=0.4 -iou_loss=ciou -nms_kind=diounms -beta_nms=0.6 -new_coords=1 -max_delta=2 - - -# YOLO-5 - -[route] -layers = 163 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1024 -activation=swish - -[convolutional] -size=1 -stride=1 -pad=1 -filters=255 -activation=logistic - -[yolo] -mask = 6,7,8 -anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 -classes=80 -num=9 -jitter=.1 -scale_x_y = 2.0 -objectness_smooth=1 -ignore_thresh = .7 -truth_thresh = 1 -#random=1 -resize=1.5 -iou_thresh=0.2 -iou_normalizer=0.05 -cls_normalizer=0.5 -obj_normalizer=0.4 -iou_loss=ciou -nms_kind=diounms -beta_nms=0.6 -new_coords=1 -max_delta=2 +[net] +# Testing +#batch=1 +#subdivisions=1 +# Training +batch=64 +subdivisions=8 +width=640 +height=640 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.001 +burn_in=1000 +max_batches = 500500 +policy=steps +steps=400000,450000 +scales=.1,.1 + +mosaic=1 + +letter_box=1 + +ema_alpha=0.9998 + +#optimized_memory=1 + + +# ============ Backbone ============ # + +# Stem + +# 0 +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=swish + +# P1 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=swish + +# 4 (previous+1+3k) +[shortcut] +from=-3 +activation=linear + +# P2 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=swish + +# Merge [-1, -(3k+4)] + +[route] +layers = -1,-10 + +# Transition last + +# 17 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +# P3 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +# Merge [-1 -(4+3k)] + +[route] +layers = -1,-28 + +# Transition last + +# 48 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +# P4 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +# Merge [-1 -(3k+4)] + +[route] +layers = -1,-28 + +# Transition last + +# 79 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +# P5 + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +# Residual Block + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=swish + +[shortcut] +from=-3 +activation=linear + +# Transition first + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +# Merge [-1 -(3k+4)] + +[route] +layers = -1,-16 + +# Transition last + +# 98 (previous+7+3k) +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=swish + +# ============ End of Backbone ============ # + +# ============ Neck ============ # + +# CSPSPP + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=swish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=swish + +[route] +layers = -1, -13 + +# 113 (previous+6+5+2k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +# End of CSPSPP + + +# FPN-4 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[upsample] +stride=2 + +[route] +layers = 79 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -6 + +# Transition last + +# 127 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + + +# FPN-3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[upsample] +stride=2 + +[route] +layers = 48 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=swish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=swish + +# Merge [-1, -(2k+2)] + +[route] +layers = -1, -6 + +# Transition last + +# 141 (previous+6+4+2k) +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=swish + + +# PAN-4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=256 +activation=swish + +[route] +layers = -1, 127 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[route] +layers = -1,-6 + +# Transition last + +# 152 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=swish + + +# PAN-5 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=512 +activation=swish + +[route] +layers = -1, 113 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +# Split + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +[route] +layers = -2 + +# Plain Block + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=swish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=swish + +[route] +layers = -1,-6 + +# Transition last + +# 163 (previous+3+4+2k) +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=swish + +# ============ End of Neck ============ # + +# ============ Head ============ # + +# YOLO-3 + +[route] +layers = 141 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=swish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=logistic + +[yolo] +mask = 0,1,2 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.1 +scale_x_y = 2.0 +objectness_smooth=1 +ignore_thresh = .7 +truth_thresh = 1 +#random=1 +resize=1.5 +iou_thresh=0.2 +iou_normalizer=0.05 +cls_normalizer=0.5 +obj_normalizer=0.4 +iou_loss=ciou +nms_kind=diounms +beta_nms=0.6 +new_coords=1 +max_delta=2 + + +# YOLO-4 + +[route] +layers = 152 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=swish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=logistic + +[yolo] +mask = 3,4,5 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.1 +scale_x_y = 2.0 +objectness_smooth=1 +ignore_thresh = .7 +truth_thresh = 1 +#random=1 +resize=1.5 +iou_thresh=0.2 +iou_normalizer=0.05 +cls_normalizer=0.5 +obj_normalizer=0.4 +iou_loss=ciou +nms_kind=diounms +beta_nms=0.6 +new_coords=1 +max_delta=2 + + +# YOLO-5 + +[route] +layers = 163 + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=swish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=logistic + +[yolo] +mask = 6,7,8 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.1 +scale_x_y = 2.0 +objectness_smooth=1 +ignore_thresh = .7 +truth_thresh = 1 +#random=1 +resize=1.5 +iou_thresh=0.2 +iou_normalizer=0.05 +cls_normalizer=0.5 +obj_normalizer=0.4 +iou_loss=ciou +nms_kind=diounms +beta_nms=0.6 +new_coords=1 +max_delta=2 diff --git a/PyTorch/contrib/cv/detection/YOLOR/darknet/new_layers.md b/PyTorch/contrib/cv/detection/YOLOR/darknet/new_layers.md index b9b5fb84a8cb747d608d637fae09ba7a201257e8..9f7a35c02ae6564f35688aab29b3aed0f3ad3a2b 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/darknet/new_layers.md +++ b/PyTorch/contrib/cv/detection/YOLOR/darknet/new_layers.md @@ -1,329 +1,329 @@ -![Implicit Modeling](https://github.com/WongKinYiu/yolor/blob/main/figure/implicit_modeling.png) - -### 1. silence layer - -Usage: - -``` -[silence] -``` - -PyTorch code: - -``` python -class Silence(nn.Module): - def __init__(self): - super(Silence, self).__init__() - def forward(self, x): - return x -``` - - -### 2. implicit_add layer - -Usage: - -``` -[implicit_add] -filters=128 -``` - -PyTorch code: - -``` python -class ImplicitA(nn.Module): - def __init__(self, channel): - super(ImplicitA, self).__init__() - self.channel = channel - self.implicit = nn.Parameter(torch.zeros(1, channel, 1, 1)) - nn.init.normal_(self.implicit, std=.02) - - def forward(self): - return self.implicit -``` - - -### 3. shift_channels layer - -Usage: - -``` -[shift_channels] -from=101 -``` - -PyTorch code: - -``` python -class ShiftChannel(nn.Module): - def __init__(self, layers): - super(ShiftChannel, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]] - return a.expand_as(x) + x -``` - - -### 4. implicit_mul layer - -Usage: - -``` -[implicit_mul] -filters=128 -``` - -PyTorch code: - -``` python -class ImplicitM(nn.Module): - def __init__(self, channel): - super(ImplicitM, self).__init__() - self.channel = channel - self.implicit = nn.Parameter(torch.ones(1, channel, 1, 1)) - nn.init.normal_(self.implicit, mean=1., std=.02) - - def forward(self): - return self.implicit -``` - - -### 5. control_channels layer - -Usage: - -``` -[control_channels] -from=101 -``` - -PyTorch code: - -``` python -class ControlChannel(nn.Module): - def __init__(self, layers): - super(ControlChannel, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]] - return a.expand_as(x) * x -``` - - -### 6. implicit_cat layer - -Usage: - -``` -[implicit_cat] -filters=128 -``` - -PyTorch code: (same as ImplicitA) - -``` python -class ImplicitC(nn.Module): - def __init__(self, channel): - super(ImplicitC, self).__init__() - self.channel = channel - self.implicit = nn.Parameter(torch.zeros(1, channel, 1, 1)) - nn.init.normal_(self.implicit, std=.02) - - def forward(self): - return self.implicit -``` - - -### 7. alternate_channels layer - -Usage: - -``` -[alternate_channels] -from=101 -``` - -PyTorch code: - -``` python -class AlternateChannel(nn.Module): - def __init__(self, layers): - super(AlternateChannel, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]] - return torch.cat([a.expand_as(x), x], dim=1) -``` - - -### 8. implicit_add_2d layer - -Usage: - -``` -[implicit_add_2d] -filters=128 -atoms=128 -``` - -PyTorch code: - -``` python -class Implicit2DA(nn.Module): - def __init__(self, atom, channel): - super(Implicit2DA, self).__init__() - self.channel = channel - self.implicit = nn.Parameter(torch.zeros(1, atom, channel, 1)) - nn.init.normal_(self.implicit, std=.02) - - def forward(self): - return self.implicit -``` - - -### 9. shift_channels_2d layer - -Usage: - -``` -[shift_channels_2d] -from=101 -``` - -PyTorch code: - -``` python -class ShiftChannel2D(nn.Module): - def __init__(self, layers): - super(ShiftChannel2D, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]].view(1,-1,1,1) - return a.expand_as(x) + x -``` - - -### 10. implicit_mul_2d layer - -Usage: - -``` -[implicit_mul_2d] -filters=128 -atoms=128 -``` - -PyTorch code: - -``` python -class Implicit2DM(nn.Module): - def __init__(self, atom, channel): - super(Implicit2DM, self).__init__() - self.channel = channel - self.implicit = nn.Parameter(torch.ones(1, atom, channel, 1)) - nn.init.normal_(self.implicit, mean=1., std=.02) - - def forward(self): - return self.implicit -``` - - -### 11. control_channels_2d layer - -Usage: - -``` -[control_channels_2d] -from=101 -``` - -PyTorch code: - -``` python -class ControlChannel2D(nn.Module): - def __init__(self, layers): - super(ControlChannel2D, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]].view(1,-1,1,1) - return a.expand_as(x) * x -``` - - -### 12. implicit_cat_2d layer - -Usage: - -``` -[implicit_cat_2d] -filters=128 -atoms=128 -``` - -PyTorch code: (same as Implicit2DA) - -``` python -class Implicit2DC(nn.Module): - def __init__(self, atom, channel): - super(Implicit2DC, self).__init__() - self.channel = channel - self.implicit = nn.Parameter(torch.zeros(1, atom, channel, 1)) - nn.init.normal_(self.implicit, std=.02) - - def forward(self): - return self.implicit -``` - - -### 13. alternate_channels_2d layer - -Usage: - -``` -[alternate_channels_2d] -from=101 -``` - -PyTorch code: - -``` python -class AlternateChannel2D(nn.Module): - def __init__(self, layers): - super(AlternateChannel2D, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]].view(1,-1,1,1) - return torch.cat([a.expand_as(x), x], dim=1) -``` - - -### 14. dwt layer - -Usage: - -``` -[dwt] -``` - -PyTorch code: - -``` python -# https://github.com/fbcotter/pytorch_wavelets -from pytorch_wavelets import DWTForward, DWTInverse -class DWT(nn.Module): - def __init__(self): - super(DWT, self).__init__() - self.xfm = DWTForward(J=1, wave='db1', mode='zero') - - def forward(self, x): - b,c,w,h = x.shape - yl, yh = self.xfm(x) - return torch.cat([yl/2., yh[0].view(b,-1,w//2,h//2)/2.+.5], 1) -``` +![Implicit Modeling](https://github.com/WongKinYiu/yolor/blob/main/figure/implicit_modeling.png) + +### 1. silence layer + +Usage: + +``` +[silence] +``` + +PyTorch code: + +``` python +class Silence(nn.Module): + def __init__(self): + super(Silence, self).__init__() + def forward(self, x): + return x +``` + + +### 2. implicit_add layer + +Usage: + +``` +[implicit_add] +filters=128 +``` + +PyTorch code: + +``` python +class ImplicitA(nn.Module): + def __init__(self, channel): + super(ImplicitA, self).__init__() + self.channel = channel + self.implicit = nn.Parameter(torch.zeros(1, channel, 1, 1)) + nn.init.normal_(self.implicit, std=.02) + + def forward(self): + return self.implicit +``` + + +### 3. shift_channels layer + +Usage: + +``` +[shift_channels] +from=101 +``` + +PyTorch code: + +``` python +class ShiftChannel(nn.Module): + def __init__(self, layers): + super(ShiftChannel, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]] + return a.expand_as(x) + x +``` + + +### 4. implicit_mul layer + +Usage: + +``` +[implicit_mul] +filters=128 +``` + +PyTorch code: + +``` python +class ImplicitM(nn.Module): + def __init__(self, channel): + super(ImplicitM, self).__init__() + self.channel = channel + self.implicit = nn.Parameter(torch.ones(1, channel, 1, 1)) + nn.init.normal_(self.implicit, mean=1., std=.02) + + def forward(self): + return self.implicit +``` + + +### 5. control_channels layer + +Usage: + +``` +[control_channels] +from=101 +``` + +PyTorch code: + +``` python +class ControlChannel(nn.Module): + def __init__(self, layers): + super(ControlChannel, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]] + return a.expand_as(x) * x +``` + + +### 6. implicit_cat layer + +Usage: + +``` +[implicit_cat] +filters=128 +``` + +PyTorch code: (same as ImplicitA) + +``` python +class ImplicitC(nn.Module): + def __init__(self, channel): + super(ImplicitC, self).__init__() + self.channel = channel + self.implicit = nn.Parameter(torch.zeros(1, channel, 1, 1)) + nn.init.normal_(self.implicit, std=.02) + + def forward(self): + return self.implicit +``` + + +### 7. alternate_channels layer + +Usage: + +``` +[alternate_channels] +from=101 +``` + +PyTorch code: + +``` python +class AlternateChannel(nn.Module): + def __init__(self, layers): + super(AlternateChannel, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]] + return torch.cat([a.expand_as(x), x], dim=1) +``` + + +### 8. implicit_add_2d layer + +Usage: + +``` +[implicit_add_2d] +filters=128 +atoms=128 +``` + +PyTorch code: + +``` python +class Implicit2DA(nn.Module): + def __init__(self, atom, channel): + super(Implicit2DA, self).__init__() + self.channel = channel + self.implicit = nn.Parameter(torch.zeros(1, atom, channel, 1)) + nn.init.normal_(self.implicit, std=.02) + + def forward(self): + return self.implicit +``` + + +### 9. shift_channels_2d layer + +Usage: + +``` +[shift_channels_2d] +from=101 +``` + +PyTorch code: + +``` python +class ShiftChannel2D(nn.Module): + def __init__(self, layers): + super(ShiftChannel2D, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]].view(1,-1,1,1) + return a.expand_as(x) + x +``` + + +### 10. implicit_mul_2d layer + +Usage: + +``` +[implicit_mul_2d] +filters=128 +atoms=128 +``` + +PyTorch code: + +``` python +class Implicit2DM(nn.Module): + def __init__(self, atom, channel): + super(Implicit2DM, self).__init__() + self.channel = channel + self.implicit = nn.Parameter(torch.ones(1, atom, channel, 1)) + nn.init.normal_(self.implicit, mean=1., std=.02) + + def forward(self): + return self.implicit +``` + + +### 11. control_channels_2d layer + +Usage: + +``` +[control_channels_2d] +from=101 +``` + +PyTorch code: + +``` python +class ControlChannel2D(nn.Module): + def __init__(self, layers): + super(ControlChannel2D, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]].view(1,-1,1,1) + return a.expand_as(x) * x +``` + + +### 12. implicit_cat_2d layer + +Usage: + +``` +[implicit_cat_2d] +filters=128 +atoms=128 +``` + +PyTorch code: (same as Implicit2DA) + +``` python +class Implicit2DC(nn.Module): + def __init__(self, atom, channel): + super(Implicit2DC, self).__init__() + self.channel = channel + self.implicit = nn.Parameter(torch.zeros(1, atom, channel, 1)) + nn.init.normal_(self.implicit, std=.02) + + def forward(self): + return self.implicit +``` + + +### 13. alternate_channels_2d layer + +Usage: + +``` +[alternate_channels_2d] +from=101 +``` + +PyTorch code: + +``` python +class AlternateChannel2D(nn.Module): + def __init__(self, layers): + super(AlternateChannel2D, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]].view(1,-1,1,1) + return torch.cat([a.expand_as(x), x], dim=1) +``` + + +### 14. dwt layer + +Usage: + +``` +[dwt] +``` + +PyTorch code: + +``` python +# https://github.com/fbcotter/pytorch_wavelets +from pytorch_wavelets import DWTForward, DWTInverse +class DWT(nn.Module): + def __init__(self): + super(DWT, self).__init__() + self.xfm = DWTForward(J=1, wave='db1', mode='zero') + + def forward(self, x): + b,c,w,h = x.shape + yl, yh = self.xfm(x) + return torch.cat([yl/2., yh[0].view(b,-1,w//2,h//2)/2.+.5], 1) +``` diff --git a/PyTorch/contrib/cv/detection/YOLOR/data/coco.names b/PyTorch/contrib/cv/detection/YOLOR/data/coco.names index a1a11c4e116132d374a6e399b4716f1ec6da5bf2..941cb4e1392266f6a6c09b1fdc5f79503b2e5df6 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/data/coco.names +++ b/PyTorch/contrib/cv/detection/YOLOR/data/coco.names @@ -1,80 +1,80 @@ -person -bicycle -car -motorcycle -airplane -bus -train -truck -boat -traffic light -fire hydrant -stop sign -parking meter -bench -bird -cat -dog -horse -sheep -cow -elephant -bear -zebra -giraffe -backpack -umbrella -handbag -tie -suitcase -frisbee -skis -snowboard -sports ball -kite -baseball bat -baseball glove -skateboard -surfboard -tennis racket -bottle -wine glass -cup -fork -knife -spoon -bowl -banana -apple -sandwich -orange -broccoli -carrot -hot dog -pizza -donut -cake -chair -couch -potted plant -bed -dining table -toilet -tv -laptop -mouse -remote -keyboard -cell phone -microwave -oven -toaster -sink -refrigerator -book -clock -vase -scissors -teddy bear -hair drier -toothbrush +person +bicycle +car +motorcycle +airplane +bus +train +truck +boat +traffic light +fire hydrant +stop sign +parking meter +bench +bird +cat +dog +horse +sheep +cow +elephant +bear +zebra +giraffe +backpack +umbrella +handbag +tie +suitcase +frisbee +skis +snowboard +sports ball +kite +baseball bat +baseball glove +skateboard +surfboard +tennis racket +bottle +wine glass +cup +fork +knife +spoon +bowl +banana +apple +sandwich +orange +broccoli +carrot +hot dog +pizza +donut +cake +chair +couch +potted plant +bed +dining table +toilet +tv +laptop +mouse +remote +keyboard +cell phone +microwave +oven +toaster +sink +refrigerator +book +clock +vase +scissors +teddy bear +hair drier +toothbrush diff --git a/PyTorch/contrib/cv/detection/YOLOR/data/coco.yaml b/PyTorch/contrib/cv/detection/YOLOR/data/coco.yaml index 6b34a4e99a4b45d9e97439aeabfc7ded409605e7..b0e6bd4baec07854ed2b69dd240e4e74bc0ac8ca 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/data/coco.yaml +++ b/PyTorch/contrib/cv/detection/YOLOR/data/coco.yaml @@ -1,18 +1,18 @@ -# train and val datasets (image directory or *.txt file with image paths) -train: /npu/traindata/yolov5_data/train2017.txt # 118k images -val: /npu/traindata/yolov5_data/val2017.txt # 5k images -test: /npu/traindata/yolov5_data/test-dev2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794 - -# number of classes -nc: 80 - -# class names -names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', - 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', - 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', - 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', - 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', - 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', - 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', - 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', - 'hair drier', 'toothbrush'] +# train and val datasets (image directory or *.txt file with image paths) +train: /npu/traindata/yolov5_data/train2017.txt # 118k images +val: /npu/traindata/yolov5_data/val2017.txt # 5k images +test: /npu/traindata/yolov5_data/test-dev2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794 + +# number of classes +nc: 80 + +# class names +names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', + 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', + 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', + 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', + 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', + 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', + 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', + 'hair drier', 'toothbrush'] diff --git a/PyTorch/contrib/cv/detection/YOLOR/data/hyp.finetune.1280.yaml b/PyTorch/contrib/cv/detection/YOLOR/data/hyp.finetune.1280.yaml index 4cef10c4f53aaa5c0c83e09f6c4d458ab5384ae4..d3ebbe10f1e6c70007eed0d38d31afba3c0348aa 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/data/hyp.finetune.1280.yaml +++ b/PyTorch/contrib/cv/detection/YOLOR/data/hyp.finetune.1280.yaml @@ -1,28 +1,28 @@ -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.5 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 1.0 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.5 # image translation (+/- fraction) -scale: 0.8 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.2 # image mixup (probability) +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.5 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 1.0 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.5 # image translation (+/- fraction) +scale: 0.8 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.2 # image mixup (probability) diff --git a/PyTorch/contrib/cv/detection/YOLOR/data/hyp.scratch.1280.yaml b/PyTorch/contrib/cv/detection/YOLOR/data/hyp.scratch.1280.yaml index ece2c96e5dee39d5dc8d53b31f130914b3c442b7..3b0f84b96ade2d97bb91ab6e6e4765cb5a64606b 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/data/hyp.scratch.1280.yaml +++ b/PyTorch/contrib/cv/detection/YOLOR/data/hyp.scratch.1280.yaml @@ -1,28 +1,28 @@ -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.5 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 1.0 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.5 # image translation (+/- fraction) -scale: 0.5 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.0 # image mixup (probability) +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.5 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 1.0 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.5 # image translation (+/- fraction) +scale: 0.5 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.0 # image mixup (probability) diff --git a/PyTorch/contrib/cv/detection/YOLOR/data/hyp.scratch.640.yaml b/PyTorch/contrib/cv/detection/YOLOR/data/hyp.scratch.640.yaml index 336fa526e4420cb02bfc30f869c062546013d43c..00e458ae3a562bb1b03e832ca8d31703c7c24c4f 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/data/hyp.scratch.640.yaml +++ b/PyTorch/contrib/cv/detection/YOLOR/data/hyp.scratch.640.yaml @@ -1,28 +1,28 @@ -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 -weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) -warmup_momentum: 0.8 # warmup initial momentum -warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain -cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.7 # obj loss gain (scale with pixels) -obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold -anchor_t: 4.0 # anchor-multiple threshold -# anchors: 3 # anchors per output layer (0 to ignore) -fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) -hsv_h: 0.015 # image HSV-Hue augmentation (fraction) -hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) -hsv_v: 0.4 # image HSV-Value augmentation (fraction) -degrees: 0.0 # image rotation (+/- deg) -translate: 0.1 # image translation (+/- fraction) -scale: 0.9 # image scale (+/- gain) -shear: 0.0 # image shear (+/- deg) -perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) -fliplr: 0.5 # image flip left-right (probability) -mosaic: 1.0 # image mosaic (probability) -mixup: 0.0 # image mixup (probability) +lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.937 # SGD momentum/Adam beta1 +weight_decay: 0.0005 # optimizer weight decay 5e-4 +warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_momentum: 0.8 # warmup initial momentum +warmup_bias_lr: 0.1 # warmup initial bias lr +box: 0.05 # box loss gain +cls: 0.3 # cls loss gain +cls_pw: 1.0 # cls BCELoss positive_weight +obj: 0.7 # obj loss gain (scale with pixels) +obj_pw: 1.0 # obj BCELoss positive_weight +iou_t: 0.20 # IoU training threshold +anchor_t: 4.0 # anchor-multiple threshold +# anchors: 3 # anchors per output layer (0 to ignore) +fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) +hsv_h: 0.015 # image HSV-Hue augmentation (fraction) +hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) +hsv_v: 0.4 # image HSV-Value augmentation (fraction) +degrees: 0.0 # image rotation (+/- deg) +translate: 0.1 # image translation (+/- fraction) +scale: 0.9 # image scale (+/- gain) +shear: 0.0 # image shear (+/- deg) +perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 +flipud: 0.0 # image flip up-down (probability) +fliplr: 0.5 # image flip left-right (probability) +mosaic: 1.0 # image mosaic (probability) +mixup: 0.0 # image mixup (probability) diff --git a/PyTorch/contrib/cv/detection/YOLOR/models/__init__.py b/PyTorch/contrib/cv/detection/YOLOR/models/__init__.py index d3f5a12faa99758192ecc4ed3fc22c9249232e86..8b137891791fe96927ad78e64b0aad7bded08bdc 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/models/__init__.py +++ b/PyTorch/contrib/cv/detection/YOLOR/models/__init__.py @@ -1 +1 @@ - + diff --git a/PyTorch/contrib/cv/detection/YOLOR/models/export.py b/PyTorch/contrib/cv/detection/YOLOR/models/export.py index 43651c4e8a2a88d555351ef05c552f3b4edfc057..0816faccf2c80eea96072d95ccc0163ed35a0b45 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/models/export.py +++ b/PyTorch/contrib/cv/detection/YOLOR/models/export.py @@ -1,82 +1,82 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse - -import torch - -from utils.google_utils import attempt_download - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--weights', type=str, default='./yolov4.pt', help='weights path') - parser.add_argument('--img-size', nargs='+', type=int, default=[640, 640], help='image size') - parser.add_argument('--batch-size', type=int, default=1, help='batch size') - opt = parser.parse_args() - opt.img_size *= 2 if len(opt.img_size) == 1 else 1 # expand - print(opt) - - # Input - img = torch.zeros((opt.batch_size, 3, *opt.img_size)) # image size(1,3,320,192) iDetection - - # Load PyTorch model - attempt_download(opt.weights) - model = torch.load(opt.weights, map_location=torch.device('cpu'))['model'].float() - model.eval() - model.model[-1].export = True # set Detect() layer export=True - y = model(img) # dry run - - # TorchScript export - try: - print('\nStarting TorchScript export with torch %s...' % torch.__version__) - f = opt.weights.replace('.pt', '.torchscript.pt') # filename - ts = torch.jit.trace(model, img) - ts.save(f) - print('TorchScript export success, saved as %s' % f) - except Exception as e: - print('TorchScript export failure: %s' % e) - - # ONNX export - try: - import onnx - - print('\nStarting ONNX export with onnx %s...' % onnx.__version__) - f = opt.weights.replace('.pt', '.onnx') # filename - model.fuse() # only for ONNX - torch.onnx.export(model, img, f, verbose=False, opset_version=12, input_names=['images'], - output_names=['classes', 'boxes'] if y is None else ['output']) - - # Checks - onnx_model = onnx.load(f) # load onnx model - onnx.checker.check_model(onnx_model) # check onnx model - print(onnx.helper.printable_graph(onnx_model.graph)) # print a human readable model - print('ONNX export success, saved as %s' % f) - except Exception as e: - print('ONNX export failure: %s' % e) - - # CoreML export - try: - import coremltools as ct - - print('\nStarting CoreML export with coremltools %s...' % ct.__version__) - # convert model from torchscript and apply pixel scaling as per detect.py - model = ct.convert(ts, inputs=[ct.ImageType(name='images', shape=img.shape, scale=1 / 255.0, bias=[0, 0, 0])]) - f = opt.weights.replace('.pt', '.mlmodel') # filename - model.save(f) - print('CoreML export success, saved as %s' % f) - except Exception as e: - print('CoreML export failure: %s' % e) - - # Finish - print('\nExport complete. Visualize with https://github.com/lutzroeder/netron.') +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse + +import torch + +from utils.google_utils import attempt_download + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--weights', type=str, default='./yolov4.pt', help='weights path') + parser.add_argument('--img-size', nargs='+', type=int, default=[640, 640], help='image size') + parser.add_argument('--batch-size', type=int, default=1, help='batch size') + opt = parser.parse_args() + opt.img_size *= 2 if len(opt.img_size) == 1 else 1 # expand + print(opt) + + # Input + img = torch.zeros((opt.batch_size, 3, *opt.img_size)) # image size(1,3,320,192) iDetection + + # Load PyTorch model + attempt_download(opt.weights) + model = torch.load(opt.weights, map_location=torch.device('cpu'))['model'].float() + model.eval() + model.model[-1].export = True # set Detect() layer export=True + y = model(img) # dry run + + # TorchScript export + try: + print('\nStarting TorchScript export with torch %s...' % torch.__version__) + f = opt.weights.replace('.pt', '.torchscript.pt') # filename + ts = torch.jit.trace(model, img) + ts.save(f) + print('TorchScript export success, saved as %s' % f) + except Exception as e: + print('TorchScript export failure: %s' % e) + + # ONNX export + try: + import onnx + + print('\nStarting ONNX export with onnx %s...' % onnx.__version__) + f = opt.weights.replace('.pt', '.onnx') # filename + model.fuse() # only for ONNX + torch.onnx.export(model, img, f, verbose=False, opset_version=12, input_names=['images'], + output_names=['classes', 'boxes'] if y is None else ['output']) + + # Checks + onnx_model = onnx.load(f) # load onnx model + onnx.checker.check_model(onnx_model) # check onnx model + print(onnx.helper.printable_graph(onnx_model.graph)) # print a human readable model + print('ONNX export success, saved as %s' % f) + except Exception as e: + print('ONNX export failure: %s' % e) + + # CoreML export + try: + import coremltools as ct + + print('\nStarting CoreML export with coremltools %s...' % ct.__version__) + # convert model from torchscript and apply pixel scaling as per detect.py + model = ct.convert(ts, inputs=[ct.ImageType(name='images', shape=img.shape, scale=1 / 255.0, bias=[0, 0, 0])]) + f = opt.weights.replace('.pt', '.mlmodel') # filename + model.save(f) + print('CoreML export success, saved as %s' % f) + except Exception as e: + print('CoreML export failure: %s' % e) + + # Finish + print('\nExport complete. Visualize with https://github.com/lutzroeder/netron.') diff --git a/PyTorch/contrib/cv/detection/YOLOR/models/models.py b/PyTorch/contrib/cv/detection/YOLOR/models/models.py index 7a532e283fed103eafe66fe9d727f2ebc1d87b3f..47b0dce49576c002192aa19275ef3d2461e06bbb 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/models/models.py +++ b/PyTorch/contrib/cv/detection/YOLOR/models/models.py @@ -1,775 +1,775 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from utils.google_utils import * -from utils.layers import * -from utils.parse_config import * -from utils import torch_utils - -ONNX_EXPORT = False - - -def create_modules(module_defs, img_size, cfg): - # Constructs module list of layer blocks from module configuration in module_defs - - img_size = [img_size] * 2 if isinstance(img_size, int) else img_size # expand if necessary - _ = module_defs.pop(0) # cfg training hyperparams (unused) - output_filters = [3] # input channels - module_list = nn.ModuleList() - routs = [] # list of layers which rout to deeper layers - yolo_index = -1 - - for i, mdef in enumerate(module_defs): - modules = nn.Sequential() - - if mdef['type'] == 'convolutional': - bn = mdef['batch_normalize'] - filters = mdef['filters'] - k = mdef['size'] # kernel size - stride = mdef['stride'] if 'stride' in mdef else (mdef['stride_y'], mdef['stride_x']) - if isinstance(k, int): # single-size conv - modules.add_module('Conv2d', nn.Conv2d(in_channels=output_filters[-1], - out_channels=filters, - kernel_size=k, - stride=stride, - padding=k // 2 if mdef['pad'] else 0, - groups=mdef['groups'] if 'groups' in mdef else 1, - bias=not bn)) - else: # multiple-size conv - modules.add_module('MixConv2d', MixConv2d(in_ch=output_filters[-1], - out_ch=filters, - k=k, - stride=stride, - bias=not bn)) - - if bn: - modules.add_module('BatchNorm2d', nn.BatchNorm2d(filters, momentum=0.03, eps=1E-4)) - else: - routs.append(i) # detection output (goes into yolo layer) - - if mdef['activation'] == 'leaky': # activation study https://github.com/ultralytics/yolov3/issues/441 - modules.add_module('activation', nn.LeakyReLU(0.1, inplace=True)) - elif mdef['activation'] == 'swish': - modules.add_module('activation', Swish()) - elif mdef['activation'] == 'mish': - modules.add_module('activation', Mish()) - elif mdef['activation'] == 'emb': - modules.add_module('activation', F.normalize()) - elif mdef['activation'] == 'logistic': - modules.add_module('activation', nn.Sigmoid()) - elif mdef['activation'] == 'silu': - modules.add_module('activation', nn.SiLU()) - - elif mdef['type'] == 'deformableconvolutional': - bn = mdef['batch_normalize'] - filters = mdef['filters'] - k = mdef['size'] # kernel size - stride = mdef['stride'] if 'stride' in mdef else (mdef['stride_y'], mdef['stride_x']) - if isinstance(k, int): # single-size conv - modules.add_module('DeformConv2d', DeformConv2d(output_filters[-1], - filters, - kernel_size=k, - padding=k // 2 if mdef['pad'] else 0, - stride=stride, - bias=not bn, - modulation=True)) - else: # multiple-size conv - modules.add_module('MixConv2d', MixConv2d(in_ch=output_filters[-1], - out_ch=filters, - k=k, - stride=stride, - bias=not bn)) - - if bn: - modules.add_module('BatchNorm2d', nn.BatchNorm2d(filters, momentum=0.03, eps=1E-4)) - else: - routs.append(i) # detection output (goes into yolo layer) - - if mdef['activation'] == 'leaky': # activation study https://github.com/ultralytics/yolov3/issues/441 - modules.add_module('activation', nn.LeakyReLU(0.1, inplace=True)) - elif mdef['activation'] == 'swish': - modules.add_module('activation', Swish()) - elif mdef['activation'] == 'mish': - modules.add_module('activation', Mish()) - elif mdef['activation'] == 'silu': - modules.add_module('activation', nn.SiLU()) - - elif mdef['type'] == 'dropout': - p = mdef['probability'] - modules = nn.Dropout(p) - - elif mdef['type'] == 'avgpool': - modules = GAP() - - elif mdef['type'] == 'silence': - filters = output_filters[-1] - modules = Silence() - - elif mdef['type'] == 'scale_channels': # nn.Sequential() placeholder for 'shortcut' layer - layers = mdef['from'] - filters = output_filters[-1] - routs.extend([i + l if l < 0 else l for l in layers]) - modules = ScaleChannel(layers=layers) - - elif mdef['type'] == 'shift_channels': # nn.Sequential() placeholder for 'shortcut' layer - layers = mdef['from'] - filters = output_filters[-1] - routs.extend([i + l if l < 0 else l for l in layers]) - modules = ShiftChannel(layers=layers) - - elif mdef['type'] == 'shift_channels_2d': # nn.Sequential() placeholder for 'shortcut' layer - layers = mdef['from'] - filters = output_filters[-1] - routs.extend([i + l if l < 0 else l for l in layers]) - modules = ShiftChannel2D(layers=layers) - - elif mdef['type'] == 'control_channels': # nn.Sequential() placeholder for 'shortcut' layer - layers = mdef['from'] - filters = output_filters[-1] - routs.extend([i + l if l < 0 else l for l in layers]) - modules = ControlChannel(layers=layers) - - elif mdef['type'] == 'control_channels_2d': # nn.Sequential() placeholder for 'shortcut' layer - layers = mdef['from'] - filters = output_filters[-1] - routs.extend([i + l if l < 0 else l for l in layers]) - modules = ControlChannel2D(layers=layers) - - elif mdef['type'] == 'alternate_channels': # nn.Sequential() placeholder for 'shortcut' layer - layers = mdef['from'] - filters = output_filters[-1] * 2 - routs.extend([i + l if l < 0 else l for l in layers]) - modules = AlternateChannel(layers=layers) - - elif mdef['type'] == 'alternate_channels_2d': # nn.Sequential() placeholder for 'shortcut' layer - layers = mdef['from'] - filters = output_filters[-1] * 2 - routs.extend([i + l if l < 0 else l for l in layers]) - modules = AlternateChannel2D(layers=layers) - - elif mdef['type'] == 'select_channels': # nn.Sequential() placeholder for 'shortcut' layer - layers = mdef['from'] - filters = output_filters[-1] - routs.extend([i + l if l < 0 else l for l in layers]) - modules = SelectChannel(layers=layers) - - elif mdef['type'] == 'select_channels_2d': # nn.Sequential() placeholder for 'shortcut' layer - layers = mdef['from'] - filters = output_filters[-1] - routs.extend([i + l if l < 0 else l for l in layers]) - modules = SelectChannel2D(layers=layers) - - elif mdef['type'] == 'sam': # nn.Sequential() placeholder for 'shortcut' layer - layers = mdef['from'] - filters = output_filters[-1] - routs.extend([i + l if l < 0 else l for l in layers]) - modules = ScaleSpatial(layers=layers) - - elif mdef['type'] == 'BatchNorm2d': - filters = output_filters[-1] - modules = nn.BatchNorm2d(filters, momentum=0.03, eps=1E-4) - if i == 0 and filters == 3: # normalize RGB image - # imagenet mean and var https://pytorch.org/docs/stable/torchvision/models.html#classification - modules.running_mean = torch.tensor([0.485, 0.456, 0.406]) - modules.running_var = torch.tensor([0.0524, 0.0502, 0.0506]) - - elif mdef['type'] == 'maxpool': - k = mdef['size'] # kernel size - stride = mdef['stride'] - maxpool = nn.MaxPool2d(kernel_size=k, stride=stride, padding=(k - 1) // 2) - if k == 2 and stride == 1: # yolov3-tiny - modules.add_module('ZeroPad2d', nn.ZeroPad2d((0, 1, 0, 1))) - modules.add_module('MaxPool2d', maxpool) - else: - modules = maxpool - - elif mdef['type'] == 'local_avgpool': - k = mdef['size'] # kernel size - stride = mdef['stride'] - avgpool = nn.AvgPool2d(kernel_size=k, stride=stride, padding=(k - 1) // 2) - if k == 2 and stride == 1: # yolov3-tiny - modules.add_module('ZeroPad2d', nn.ZeroPad2d((0, 1, 0, 1))) - modules.add_module('AvgPool2d', avgpool) - else: - modules = avgpool - - elif mdef['type'] == 'upsample': - if ONNX_EXPORT: # explicitly state size, avoid scale_factor - g = (yolo_index + 1) * 2 / 32 # gain - modules = nn.Upsample(size=tuple(int(x * g) for x in img_size)) # img_size = (320, 192) - else: - modules = nn.Upsample(scale_factor=mdef['stride']) - - elif mdef['type'] == 'route': # nn.Sequential() placeholder for 'route' layer - layers = mdef['layers'] - filters = sum([output_filters[l + 1 if l > 0 else l] for l in layers]) - routs.extend([i + l if l < 0 else l for l in layers]) - modules = FeatureConcat(layers=layers) - - elif mdef['type'] == 'route2': # nn.Sequential() placeholder for 'route' layer - layers = mdef['layers'] - filters = sum([output_filters[l + 1 if l > 0 else l] for l in layers]) - routs.extend([i + l if l < 0 else l for l in layers]) - modules = FeatureConcat2(layers=layers) - - elif mdef['type'] == 'route3': # nn.Sequential() placeholder for 'route' layer - layers = mdef['layers'] - filters = sum([output_filters[l + 1 if l > 0 else l] for l in layers]) - routs.extend([i + l if l < 0 else l for l in layers]) - modules = FeatureConcat3(layers=layers) - - elif mdef['type'] == 'route_lhalf': # nn.Sequential() placeholder for 'route' layer - layers = mdef['layers'] - filters = sum([output_filters[l + 1 if l > 0 else l] for l in layers])//2 - routs.extend([i + l if l < 0 else l for l in layers]) - modules = FeatureConcat_l(layers=layers) - - elif mdef['type'] == 'shortcut': # nn.Sequential() placeholder for 'shortcut' layer - layers = mdef['from'] - filters = output_filters[-1] - routs.extend([i + l if l < 0 else l for l in layers]) - modules = WeightedFeatureFusion(layers=layers, weight='weights_type' in mdef) - - elif mdef['type'] == 'reorg3d': # yolov3-spp-pan-scale - pass - - elif mdef['type'] == 'reorg': # yolov3-spp-pan-scale - filters = 4 * output_filters[-1] - modules.add_module('Reorg', Reorg()) - - elif mdef['type'] == 'dwt': # yolov3-spp-pan-scale - filters = 4 * output_filters[-1] - modules.add_module('DWT', DWT()) - - elif mdef['type'] == 'implicit_add': # yolov3-spp-pan-scale - filters = mdef['filters'] - modules = ImplicitA(channel=filters) - - elif mdef['type'] == 'implicit_mul': # yolov3-spp-pan-scale - filters = mdef['filters'] - modules = ImplicitM(channel=filters) - - elif mdef['type'] == 'implicit_cat': # yolov3-spp-pan-scale - filters = mdef['filters'] - modules = ImplicitC(channel=filters) - - elif mdef['type'] == 'implicit_add_2d': # yolov3-spp-pan-scale - channels = mdef['filters'] - filters = mdef['atoms'] - modules = Implicit2DA(atom=filters, channel=channels) - - elif mdef['type'] == 'implicit_mul_2d': # yolov3-spp-pan-scale - channels = mdef['filters'] - filters = mdef['atoms'] - modules = Implicit2DM(atom=filters, channel=channels) - - elif mdef['type'] == 'implicit_cat_2d': # yolov3-spp-pan-scale - channels = mdef['filters'] - filters = mdef['atoms'] - modules = Implicit2DC(atom=filters, channel=channels) - - elif mdef['type'] == 'yolo': - yolo_index += 1 - stride = [8, 16, 32, 64, 128] # P3, P4, P5, P6, P7 strides - if any(x in cfg for x in ['yolov4-tiny', 'fpn', 'yolov3']): # P5, P4, P3 strides - stride = [32, 16, 8] - layers = mdef['from'] if 'from' in mdef else [] - modules = YOLOLayer(anchors=mdef['anchors'][mdef['mask']], # anchor list - nc=mdef['classes'], # number of classes - img_size=img_size, # (416, 416) - yolo_index=yolo_index, # 0, 1, 2... - layers=layers, # output layers - stride=stride[yolo_index]) - - # Initialize preceding Conv2d() bias (https://arxiv.org/pdf/1708.02002.pdf section 3.3) - try: - j = layers[yolo_index] if 'from' in mdef else -2 - bias_ = module_list[j][0].bias # shape(255,) - bias = bias_[:modules.no * modules.na].view(modules.na, -1) # shape(3,85) - #bias[:, 4] += -4.5 # obj - bias.data[:, 4] += math.log(8 / (640 / stride[yolo_index]) ** 2) # obj (8 objects per 640 image) - bias.data[:, 5:] += math.log(0.6 / (modules.nc - 0.99)) # cls (sigmoid(p) = 1/nc) - module_list[j][0].bias = torch.nn.Parameter(bias_, requires_grad=bias_.requires_grad) - - #j = [-2, -5, -8] - #for sj in j: - # bias_ = module_list[sj][0].bias - # bias = bias_[:modules.no * 1].view(1, -1) - # bias.data[:, 4] += math.log(8 / (640 / stride[yolo_index]) ** 2) - # bias.data[:, 5:] += math.log(0.6 / (modules.nc - 0.99)) - # module_list[sj][0].bias = torch.nn.Parameter(bias_, requires_grad=bias_.requires_grad) - except: - print('WARNING: smart bias initialization failure.') - - elif mdef['type'] == 'jde': - yolo_index += 1 - stride = [8, 16, 32, 64, 128] # P3, P4, P5, P6, P7 strides - if any(x in cfg for x in ['yolov4-tiny', 'fpn', 'yolov3']): # P5, P4, P3 strides - stride = [32, 16, 8] - layers = mdef['from'] if 'from' in mdef else [] - modules = JDELayer(anchors=mdef['anchors'][mdef['mask']], # anchor list - nc=mdef['classes'], # number of classes - img_size=img_size, # (416, 416) - yolo_index=yolo_index, # 0, 1, 2... - layers=layers, # output layers - stride=stride[yolo_index]) - - # Initialize preceding Conv2d() bias (https://arxiv.org/pdf/1708.02002.pdf section 3.3) - try: - j = layers[yolo_index] if 'from' in mdef else -1 - bias_ = module_list[j][0].bias # shape(255,) - bias = bias_[:modules.no * modules.na].view(modules.na, -1) # shape(3,85) - #bias[:, 4] += -4.5 # obj - bias.data[:, 4] += math.log(8 / (640 / stride[yolo_index]) ** 2) # obj (8 objects per 640 image) - bias.data[:, 5:] += math.log(0.6 / (modules.nc - 0.99)) # cls (sigmoid(p) = 1/nc) - module_list[j][0].bias = torch.nn.Parameter(bias_, requires_grad=bias_.requires_grad) - except: - print('WARNING: smart bias initialization failure.') - - else: - print('Warning: Unrecognized Layer Type: ' + mdef['type']) - - # Register module list and number of output filters - module_list.append(modules) - output_filters.append(filters) - - routs_binary = [False] * (i + 1) - for i in routs: - routs_binary[i] = True - return module_list, routs_binary - - -class YOLOLayer(nn.Module): - def __init__(self, anchors, nc, img_size, yolo_index, layers, stride): - super(YOLOLayer, self).__init__() - self.anchors = torch.Tensor(anchors) - self.index = yolo_index # index of this layer in layers - self.layers = layers # model output layer indices - self.stride = stride # layer stride - self.nl = len(layers) # number of output layers (3) - self.na = len(anchors) # number of anchors (3) - self.nc = nc # number of classes (80) - self.no = nc + 5 # number of outputs (85) - self.nx, self.ny, self.ng = 0, 0, 0 # initialize number of x, y gridpoints - self.anchor_vec = self.anchors / self.stride - self.anchor_wh = self.anchor_vec.view(1, self.na, 1, 1, 2) - - if ONNX_EXPORT: - self.training = False - self.create_grids((img_size[1] // stride, img_size[0] // stride)) # number x, y grid points - - def create_grids(self, ng=(13, 13), device='cpu'): - self.nx, self.ny = ng # x and y grid size - self.ng = torch.tensor(ng, dtype=torch.float) - - # build xy offsets - if not self.training: - yv, xv = torch.meshgrid([torch.arange(self.ny, device=device), torch.arange(self.nx, device=device)]) - self.grid = torch.stack((xv, yv), 2).view((1, 1, self.ny, self.nx, 2)).float() - - if self.anchor_vec.device != device: - self.anchor_vec = self.anchor_vec.to(device) - self.anchor_wh = self.anchor_wh.to(device) - - def forward(self, p, out): - ASFF = False # https://arxiv.org/abs/1911.09516 - if ASFF: - i, n = self.index, self.nl # index in layers, number of layers - p = out[self.layers[i]] - bs, _, ny, nx = p.shape # bs, 255, 13, 13 - if (self.nx, self.ny) != (nx, ny): - self.create_grids((nx, ny), p.device) - - # outputs and weights - # w = F.softmax(p[:, -n:], 1) # normalized weights - w = torch.sigmoid(p[:, -n:]) * (2 / n) # sigmoid weights (faster) - # w = w / w.sum(1).unsqueeze(1) # normalize across layer dimension - - # weighted ASFF sum - p = out[self.layers[i]][:, :-n] * w[:, i:i + 1] - for j in range(n): - if j != i: - p += w[:, j:j + 1] * \ - F.interpolate(out[self.layers[j]][:, :-n], size=[ny, nx], mode='bilinear', align_corners=False) - - elif ONNX_EXPORT: - bs = 1 # batch size - else: - bs, _, ny, nx = p.shape # bs, 255, 13, 13 - if (self.nx, self.ny) != (nx, ny): - self.create_grids((nx, ny), p.device) - - # p.view(bs, 255, 13, 13) -- > (bs, 3, 13, 13, 85) # (bs, anchors, grid, grid, classes + xywh) - p = p.view(bs, self.na, self.no, self.ny, self.nx).permute(0, 1, 3, 4, 2).contiguous() # prediction - - if self.training: - return p - - elif ONNX_EXPORT: - # Avoid broadcasting for ANE operations - m = self.na * self.nx * self.ny - ng = 1. / self.ng.repeat(m, 1) - grid = self.grid.repeat(1, self.na, 1, 1, 1).view(m, 2) - anchor_wh = self.anchor_wh.repeat(1, 1, self.nx, self.ny, 1).view(m, 2) * ng - - p = p.view(m, self.no) - xy = torch.sigmoid(p[:, 0:2]) + grid # x, y - wh = torch.exp(p[:, 2:4]) * anchor_wh # width, height - p_cls = torch.sigmoid(p[:, 4:5]) if self.nc == 1 else \ - torch.sigmoid(p[:, 5:self.no]) * torch.sigmoid(p[:, 4:5]) # conf - return p_cls, xy * ng, wh - - else: # inference - io = p.sigmoid() - io[..., :2] = (io[..., :2] * 2. - 0.5 + self.grid) - io[..., 2:4] = (io[..., 2:4] * 2) ** 2 * self.anchor_wh - io[..., :4] *= self.stride - #io = p.clone() # inference output - #io[..., :2] = torch.sigmoid(io[..., :2]) + self.grid # xy - #io[..., 2:4] = torch.exp(io[..., 2:4]) * self.anchor_wh # wh yolo method - #io[..., :4] *= self.stride - #torch.sigmoid_(io[..., 4:]) - return io.view(bs, -1, self.no), p # view [1, 3, 13, 13, 85] as [1, 507, 85] - - -class JDELayer(nn.Module): - def __init__(self, anchors, nc, img_size, yolo_index, layers, stride): - super(JDELayer, self).__init__() - self.anchors = torch.Tensor(anchors) - self.index = yolo_index # index of this layer in layers - self.layers = layers # model output layer indices - self.stride = stride # layer stride - self.nl = len(layers) # number of output layers (3) - self.na = len(anchors) # number of anchors (3) - self.nc = nc # number of classes (80) - self.no = nc + 5 # number of outputs (85) - self.nx, self.ny, self.ng = 0, 0, 0 # initialize number of x, y gridpoints - self.anchor_vec = self.anchors / self.stride - self.anchor_wh = self.anchor_vec.view(1, self.na, 1, 1, 2) - - if ONNX_EXPORT: - self.training = False - self.create_grids((img_size[1] // stride, img_size[0] // stride)) # number x, y grid points - - def create_grids(self, ng=(13, 13), device='cpu'): - self.nx, self.ny = ng # x and y grid size - self.ng = torch.tensor(ng, dtype=torch.float) - - # build xy offsets - if not self.training: - yv, xv = torch.meshgrid([torch.arange(self.ny, device=device), torch.arange(self.nx, device=device)]) - self.grid = torch.stack((xv, yv), 2).view((1, 1, self.ny, self.nx, 2)).float() - - if self.anchor_vec.device != device: - self.anchor_vec = self.anchor_vec.to(device) - self.anchor_wh = self.anchor_wh.to(device) - - def forward(self, p, out): - ASFF = False # https://arxiv.org/abs/1911.09516 - if ASFF: - i, n = self.index, self.nl # index in layers, number of layers - p = out[self.layers[i]] - bs, _, ny, nx = p.shape # bs, 255, 13, 13 - if (self.nx, self.ny) != (nx, ny): - self.create_grids((nx, ny), p.device) - - # outputs and weights - # w = F.softmax(p[:, -n:], 1) # normalized weights - w = torch.sigmoid(p[:, -n:]) * (2 / n) # sigmoid weights (faster) - # w = w / w.sum(1).unsqueeze(1) # normalize across layer dimension - - # weighted ASFF sum - p = out[self.layers[i]][:, :-n] * w[:, i:i + 1] - for j in range(n): - if j != i: - p += w[:, j:j + 1] * \ - F.interpolate(out[self.layers[j]][:, :-n], size=[ny, nx], mode='bilinear', align_corners=False) - - elif ONNX_EXPORT: - bs = 1 # batch size - else: - bs, _, ny, nx = p.shape # bs, 255, 13, 13 - if (self.nx, self.ny) != (nx, ny): - self.create_grids((nx, ny), p.device) - - # p.view(bs, 255, 13, 13) -- > (bs, 3, 13, 13, 85) # (bs, anchors, grid, grid, classes + xywh) - p = p.view(bs, self.na, self.no, self.ny, self.nx).permute(0, 1, 3, 4, 2).contiguous() # prediction - - if self.training: - return p - - elif ONNX_EXPORT: - # Avoid broadcasting for ANE operations - m = self.na * self.nx * self.ny - ng = 1. / self.ng.repeat(m, 1) - grid = self.grid.repeat(1, self.na, 1, 1, 1).view(m, 2) - anchor_wh = self.anchor_wh.repeat(1, 1, self.nx, self.ny, 1).view(m, 2) * ng - - p = p.view(m, self.no) - xy = torch.sigmoid(p[:, 0:2]) + grid # x, y - wh = torch.exp(p[:, 2:4]) * anchor_wh # width, height - p_cls = torch.sigmoid(p[:, 4:5]) if self.nc == 1 else \ - torch.sigmoid(p[:, 5:self.no]) * torch.sigmoid(p[:, 4:5]) # conf - return p_cls, xy * ng, wh - - else: # inference - #io = p.sigmoid() - #io[..., :2] = (io[..., :2] * 2. - 0.5 + self.grid) - #io[..., 2:4] = (io[..., 2:4] * 2) ** 2 * self.anchor_wh - #io[..., :4] *= self.stride - io = p.clone() # inference output - io[..., :2] = torch.sigmoid(io[..., :2]) * 2. - 0.5 + self.grid # xy - io[..., 2:4] = (torch.sigmoid(io[..., 2:4]) * 2) ** 2 * self.anchor_wh # wh yolo method - io[..., :4] *= self.stride - io[..., 4:] = F.softmax(io[..., 4:]) - return io.view(bs, -1, self.no), p # view [1, 3, 13, 13, 85] as [1, 507, 85] - -class Darknet(nn.Module): - # YOLOv3 object detection model - - def __init__(self, cfg, img_size=(416, 416), verbose=False): - super(Darknet, self).__init__() - - self.module_defs = parse_model_cfg(cfg) - self.module_list, self.routs = create_modules(self.module_defs, img_size, cfg) - self.yolo_layers = get_yolo_layers(self) - # torch_utils.initialize_weights(self) - - # Darknet Header https://github.com/AlexeyAB/darknet/issues/2914#issuecomment-496675346 - self.version = np.array([0, 2, 5], dtype=np.int32) # (int32) version info: major, minor, revision - self.seen = np.array([0], dtype=np.int64) # (int64) number of images seen during training - self.info(verbose) if not ONNX_EXPORT else None # print model description - - def forward(self, x, augment=False, verbose=False): - - if not augment: - return self.forward_once(x) - else: # Augment images (inference and test only) https://github.com/ultralytics/yolov3/issues/931 - img_size = x.shape[-2:] # height, width - s = [0.83, 0.67] # scales - y = [] - for i, xi in enumerate((x, - torch_utils.scale_img(x.flip(3), s[0], same_shape=False), # flip-lr and scale - torch_utils.scale_img(x, s[1], same_shape=False), # scale - )): - # cv2.imwrite('img%g.jpg' % i, 255 * xi[0].numpy().transpose((1, 2, 0))[:, :, ::-1]) - y.append(self.forward_once(xi)[0]) - - y[1][..., :4] /= s[0] # scale - y[1][..., 0] = img_size[1] - y[1][..., 0] # flip lr - y[2][..., :4] /= s[1] # scale - - # for i, yi in enumerate(y): # coco small, medium, large = < 32**2 < 96**2 < - # area = yi[..., 2:4].prod(2)[:, :, None] - # if i == 1: - # yi *= (area < 96. ** 2).float() - # elif i == 2: - # yi *= (area > 32. ** 2).float() - # y[i] = yi - - y = torch.cat(y, 1) - return y, None - - def forward_once(self, x, augment=False, verbose=False): - img_size = x.shape[-2:] # height, width - yolo_out, out = [], [] - if verbose: - print('0', x.shape) - str = '' - - # Augment images (inference and test only) - if augment: # https://github.com/ultralytics/yolov3/issues/931 - nb = x.shape[0] # batch size - s = [0.83, 0.67] # scales - x = torch.cat((x, - torch_utils.scale_img(x.flip(3), s[0]), # flip-lr and scale - torch_utils.scale_img(x, s[1]), # scale - ), 0) - - for i, module in enumerate(self.module_list): - name = module.__class__.__name__ - #print(name) - if name in ['WeightedFeatureFusion', 'FeatureConcat', 'FeatureConcat2', 'FeatureConcat3', 'FeatureConcat_l', 'ScaleChannel', 'ShiftChannel', 'ShiftChannel2D', 'ControlChannel', 'ControlChannel2D', 'AlternateChannel', 'AlternateChannel2D', 'SelectChannel', 'SelectChannel2D', 'ScaleSpatial']: # sum, concat - if verbose: - l = [i - 1] + module.layers # layers - sh = [list(x.shape)] + [list(out[i].shape) for i in module.layers] # shapes - str = ' >> ' + ' + '.join(['layer %g %s' % x for x in zip(l, sh)]) - x = module(x, out) # WeightedFeatureFusion(), FeatureConcat() - elif name in ['ImplicitA', 'ImplicitM', 'ImplicitC', 'Implicit2DA', 'Implicit2DM', 'Implicit2DC']: - x = module() - elif name == 'YOLOLayer': - yolo_out.append(module(x, out)) - elif name == 'JDELayer': - yolo_out.append(module(x, out)) - else: # run module directly, i.e. mtype = 'convolutional', 'upsample', 'maxpool', 'batchnorm2d' etc. - #print(module) - #print(x.shape) - x = module(x) - - out.append(x if self.routs[i] else []) - if verbose: - print('%g/%g %s -' % (i, len(self.module_list), name), list(x.shape), str) - str = '' - - if self.training: # train - return yolo_out - elif ONNX_EXPORT: # export - x = [torch.cat(x, 0) for x in zip(*yolo_out)] - return x[0], torch.cat(x[1:3], 1) # scores, boxes: 3780x80, 3780x4 - else: # inference or test - x, p = zip(*yolo_out) # inference output, training output - x = torch.cat(x, 1) # cat yolo outputs - if augment: # de-augment results - x = torch.split(x, nb, dim=0) - x[1][..., :4] /= s[0] # scale - x[1][..., 0] = img_size[1] - x[1][..., 0] # flip lr - x[2][..., :4] /= s[1] # scale - x = torch.cat(x, 1) - return x, p - - def fuse(self): - # Fuse Conv2d + BatchNorm2d layers throughout model - print('Fusing layers...') - fused_list = nn.ModuleList() - for a in list(self.children())[0]: - if isinstance(a, nn.Sequential): - for i, b in enumerate(a): - if isinstance(b, nn.modules.batchnorm.BatchNorm2d): - # fuse this bn layer with the previous conv2d layer - conv = a[i - 1] - fused = torch_utils.fuse_conv_and_bn(conv, b) - a = nn.Sequential(fused, *list(a.children())[i + 1:]) - break - fused_list.append(a) - self.module_list = fused_list - self.info() if not ONNX_EXPORT else None # yolov3-spp reduced from 225 to 152 layers - - def info(self, verbose=False): - torch_utils.model_info(self, verbose) - - -def get_yolo_layers(model): - return [i for i, m in enumerate(model.module_list) if m.__class__.__name__ in ['YOLOLayer', 'JDELayer']] # [89, 101, 113] - - -def load_darknet_weights(self, weights, cutoff=-1): - # Parses and loads the weights stored in 'weights' - - # Establish cutoffs (load layers between 0 and cutoff. if cutoff = -1 all are loaded) - file = Path(weights).name - if file == 'darknet53.conv.74': - cutoff = 75 - elif file == 'yolov3-tiny.conv.15': - cutoff = 15 - - # Read weights file - with open(weights, 'rb') as f: - # Read Header https://github.com/AlexeyAB/darknet/issues/2914#issuecomment-496675346 - self.version = np.fromfile(f, dtype=np.int32, count=3) # (int32) version info: major, minor, revision - self.seen = np.fromfile(f, dtype=np.int64, count=1) # (int64) number of images seen during training - - weights = np.fromfile(f, dtype=np.float32) # the rest are weights - - ptr = 0 - for i, (mdef, module) in enumerate(zip(self.module_defs[:cutoff], self.module_list[:cutoff])): - if mdef['type'] == 'convolutional': - conv = module[0] - if mdef['batch_normalize']: - # Load BN bias, weights, running mean and running variance - bn = module[1] - nb = bn.bias.numel() # number of biases - # Bias - bn.bias.data.copy_(torch.from_numpy(weights[ptr:ptr + nb]).view_as(bn.bias)) - ptr += nb - # Weight - bn.weight.data.copy_(torch.from_numpy(weights[ptr:ptr + nb]).view_as(bn.weight)) - ptr += nb - # Running Mean - bn.running_mean.data.copy_(torch.from_numpy(weights[ptr:ptr + nb]).view_as(bn.running_mean)) - ptr += nb - # Running Var - bn.running_var.data.copy_(torch.from_numpy(weights[ptr:ptr + nb]).view_as(bn.running_var)) - ptr += nb - else: - # Load conv. bias - nb = conv.bias.numel() - conv_b = torch.from_numpy(weights[ptr:ptr + nb]).view_as(conv.bias) - conv.bias.data.copy_(conv_b) - ptr += nb - # Load conv. weights - nw = conv.weight.numel() # number of weights - conv.weight.data.copy_(torch.from_numpy(weights[ptr:ptr + nw]).view_as(conv.weight)) - ptr += nw - - -def save_weights(self, path='model.weights', cutoff=-1): - # Converts a PyTorch model to Darket format (*.pt to *.weights) - # Note: Does not work if model.fuse() is applied - with open(path, 'wb') as f: - # Write Header https://github.com/AlexeyAB/darknet/issues/2914#issuecomment-496675346 - self.version.tofile(f) # (int32) version info: major, minor, revision - self.seen.tofile(f) # (int64) number of images seen during training - - # Iterate through layers - for i, (mdef, module) in enumerate(zip(self.module_defs[:cutoff], self.module_list[:cutoff])): - if mdef['type'] == 'convolutional': - conv_layer = module[0] - # If batch norm, load bn first - if mdef['batch_normalize']: - bn_layer = module[1] - bn_layer.bias.data.cpu().numpy().tofile(f) - bn_layer.weight.data.cpu().numpy().tofile(f) - bn_layer.running_mean.data.cpu().numpy().tofile(f) - bn_layer.running_var.data.cpu().numpy().tofile(f) - # Load conv bias - else: - conv_layer.bias.data.cpu().numpy().tofile(f) - # Load conv weights - conv_layer.weight.data.cpu().numpy().tofile(f) - - -def convert(cfg='cfg/yolov3-spp.cfg', weights='weights/yolov3-spp.weights', saveto='converted.weights'): - # Converts between PyTorch and Darknet format per extension (i.e. *.weights convert to *.pt and vice versa) - # from models import *; convert('cfg/yolov3-spp.cfg', 'weights/yolov3-spp.weights') - - # Initialize model - model = Darknet(cfg) - ckpt = torch.load(weights) # load checkpoint - try: - ckpt['model'] = {k: v for k, v in ckpt['model'].items() if model.state_dict()[k].numel() == v.numel()} - model.load_state_dict(ckpt['model'], strict=False) - save_weights(model, path=saveto, cutoff=-1) - except KeyError as e: - print(e) - -def attempt_download(weights): - # Attempt to download pretrained weights if not found locally - weights = weights.strip() - msg = weights + ' missing, try downloading from https://drive.google.com/open?id=1LezFG5g3BCW6iYaV89B2i64cqEUZD7e0' - - if len(weights) > 0 and not os.path.isfile(weights): - d = {''} - - file = Path(weights).name - if file in d: - r = gdrive_download(id=d[file], name=weights) - else: # download from pjreddie.com - url = 'https://pjreddie.com/media/files/' + file - print('Downloading ' + url) - r = os.system('curl -f ' + url + ' -o ' + weights) - - # Error check - if not (r == 0 and os.path.exists(weights) and os.path.getsize(weights) > 1E6): # weights exist and > 1MB - os.system('rm ' + weights) # remove partial downloads - raise Exception(msg) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from utils.google_utils import * +from utils.layers import * +from utils.parse_config import * +from utils import torch_utils + +ONNX_EXPORT = False + + +def create_modules(module_defs, img_size, cfg): + # Constructs module list of layer blocks from module configuration in module_defs + + img_size = [img_size] * 2 if isinstance(img_size, int) else img_size # expand if necessary + _ = module_defs.pop(0) # cfg training hyperparams (unused) + output_filters = [3] # input channels + module_list = nn.ModuleList() + routs = [] # list of layers which rout to deeper layers + yolo_index = -1 + + for i, mdef in enumerate(module_defs): + modules = nn.Sequential() + + if mdef['type'] == 'convolutional': + bn = mdef['batch_normalize'] + filters = mdef['filters'] + k = mdef['size'] # kernel size + stride = mdef['stride'] if 'stride' in mdef else (mdef['stride_y'], mdef['stride_x']) + if isinstance(k, int): # single-size conv + modules.add_module('Conv2d', nn.Conv2d(in_channels=output_filters[-1], + out_channels=filters, + kernel_size=k, + stride=stride, + padding=k // 2 if mdef['pad'] else 0, + groups=mdef['groups'] if 'groups' in mdef else 1, + bias=not bn)) + else: # multiple-size conv + modules.add_module('MixConv2d', MixConv2d(in_ch=output_filters[-1], + out_ch=filters, + k=k, + stride=stride, + bias=not bn)) + + if bn: + modules.add_module('BatchNorm2d', nn.BatchNorm2d(filters, momentum=0.03, eps=1E-4)) + else: + routs.append(i) # detection output (goes into yolo layer) + + if mdef['activation'] == 'leaky': # activation study https://github.com/ultralytics/yolov3/issues/441 + modules.add_module('activation', nn.LeakyReLU(0.1, inplace=True)) + elif mdef['activation'] == 'swish': + modules.add_module('activation', Swish()) + elif mdef['activation'] == 'mish': + modules.add_module('activation', Mish()) + elif mdef['activation'] == 'emb': + modules.add_module('activation', F.normalize()) + elif mdef['activation'] == 'logistic': + modules.add_module('activation', nn.Sigmoid()) + elif mdef['activation'] == 'silu': + modules.add_module('activation', nn.SiLU()) + + elif mdef['type'] == 'deformableconvolutional': + bn = mdef['batch_normalize'] + filters = mdef['filters'] + k = mdef['size'] # kernel size + stride = mdef['stride'] if 'stride' in mdef else (mdef['stride_y'], mdef['stride_x']) + if isinstance(k, int): # single-size conv + modules.add_module('DeformConv2d', DeformConv2d(output_filters[-1], + filters, + kernel_size=k, + padding=k // 2 if mdef['pad'] else 0, + stride=stride, + bias=not bn, + modulation=True)) + else: # multiple-size conv + modules.add_module('MixConv2d', MixConv2d(in_ch=output_filters[-1], + out_ch=filters, + k=k, + stride=stride, + bias=not bn)) + + if bn: + modules.add_module('BatchNorm2d', nn.BatchNorm2d(filters, momentum=0.03, eps=1E-4)) + else: + routs.append(i) # detection output (goes into yolo layer) + + if mdef['activation'] == 'leaky': # activation study https://github.com/ultralytics/yolov3/issues/441 + modules.add_module('activation', nn.LeakyReLU(0.1, inplace=True)) + elif mdef['activation'] == 'swish': + modules.add_module('activation', Swish()) + elif mdef['activation'] == 'mish': + modules.add_module('activation', Mish()) + elif mdef['activation'] == 'silu': + modules.add_module('activation', nn.SiLU()) + + elif mdef['type'] == 'dropout': + p = mdef['probability'] + modules = nn.Dropout(p) + + elif mdef['type'] == 'avgpool': + modules = GAP() + + elif mdef['type'] == 'silence': + filters = output_filters[-1] + modules = Silence() + + elif mdef['type'] == 'scale_channels': # nn.Sequential() placeholder for 'shortcut' layer + layers = mdef['from'] + filters = output_filters[-1] + routs.extend([i + l if l < 0 else l for l in layers]) + modules = ScaleChannel(layers=layers) + + elif mdef['type'] == 'shift_channels': # nn.Sequential() placeholder for 'shortcut' layer + layers = mdef['from'] + filters = output_filters[-1] + routs.extend([i + l if l < 0 else l for l in layers]) + modules = ShiftChannel(layers=layers) + + elif mdef['type'] == 'shift_channels_2d': # nn.Sequential() placeholder for 'shortcut' layer + layers = mdef['from'] + filters = output_filters[-1] + routs.extend([i + l if l < 0 else l for l in layers]) + modules = ShiftChannel2D(layers=layers) + + elif mdef['type'] == 'control_channels': # nn.Sequential() placeholder for 'shortcut' layer + layers = mdef['from'] + filters = output_filters[-1] + routs.extend([i + l if l < 0 else l for l in layers]) + modules = ControlChannel(layers=layers) + + elif mdef['type'] == 'control_channels_2d': # nn.Sequential() placeholder for 'shortcut' layer + layers = mdef['from'] + filters = output_filters[-1] + routs.extend([i + l if l < 0 else l for l in layers]) + modules = ControlChannel2D(layers=layers) + + elif mdef['type'] == 'alternate_channels': # nn.Sequential() placeholder for 'shortcut' layer + layers = mdef['from'] + filters = output_filters[-1] * 2 + routs.extend([i + l if l < 0 else l for l in layers]) + modules = AlternateChannel(layers=layers) + + elif mdef['type'] == 'alternate_channels_2d': # nn.Sequential() placeholder for 'shortcut' layer + layers = mdef['from'] + filters = output_filters[-1] * 2 + routs.extend([i + l if l < 0 else l for l in layers]) + modules = AlternateChannel2D(layers=layers) + + elif mdef['type'] == 'select_channels': # nn.Sequential() placeholder for 'shortcut' layer + layers = mdef['from'] + filters = output_filters[-1] + routs.extend([i + l if l < 0 else l for l in layers]) + modules = SelectChannel(layers=layers) + + elif mdef['type'] == 'select_channels_2d': # nn.Sequential() placeholder for 'shortcut' layer + layers = mdef['from'] + filters = output_filters[-1] + routs.extend([i + l if l < 0 else l for l in layers]) + modules = SelectChannel2D(layers=layers) + + elif mdef['type'] == 'sam': # nn.Sequential() placeholder for 'shortcut' layer + layers = mdef['from'] + filters = output_filters[-1] + routs.extend([i + l if l < 0 else l for l in layers]) + modules = ScaleSpatial(layers=layers) + + elif mdef['type'] == 'BatchNorm2d': + filters = output_filters[-1] + modules = nn.BatchNorm2d(filters, momentum=0.03, eps=1E-4) + if i == 0 and filters == 3: # normalize RGB image + # imagenet mean and var https://pytorch.org/docs/stable/torchvision/models.html#classification + modules.running_mean = torch.tensor([0.485, 0.456, 0.406]) + modules.running_var = torch.tensor([0.0524, 0.0502, 0.0506]) + + elif mdef['type'] == 'maxpool': + k = mdef['size'] # kernel size + stride = mdef['stride'] + maxpool = nn.MaxPool2d(kernel_size=k, stride=stride, padding=(k - 1) // 2) + if k == 2 and stride == 1: # yolov3-tiny + modules.add_module('ZeroPad2d', nn.ZeroPad2d((0, 1, 0, 1))) + modules.add_module('MaxPool2d', maxpool) + else: + modules = maxpool + + elif mdef['type'] == 'local_avgpool': + k = mdef['size'] # kernel size + stride = mdef['stride'] + avgpool = nn.AvgPool2d(kernel_size=k, stride=stride, padding=(k - 1) // 2) + if k == 2 and stride == 1: # yolov3-tiny + modules.add_module('ZeroPad2d', nn.ZeroPad2d((0, 1, 0, 1))) + modules.add_module('AvgPool2d', avgpool) + else: + modules = avgpool + + elif mdef['type'] == 'upsample': + if ONNX_EXPORT: # explicitly state size, avoid scale_factor + g = (yolo_index + 1) * 2 / 32 # gain + modules = nn.Upsample(size=tuple(int(x * g) for x in img_size)) # img_size = (320, 192) + else: + modules = nn.Upsample(scale_factor=mdef['stride']) + + elif mdef['type'] == 'route': # nn.Sequential() placeholder for 'route' layer + layers = mdef['layers'] + filters = sum([output_filters[l + 1 if l > 0 else l] for l in layers]) + routs.extend([i + l if l < 0 else l for l in layers]) + modules = FeatureConcat(layers=layers) + + elif mdef['type'] == 'route2': # nn.Sequential() placeholder for 'route' layer + layers = mdef['layers'] + filters = sum([output_filters[l + 1 if l > 0 else l] for l in layers]) + routs.extend([i + l if l < 0 else l for l in layers]) + modules = FeatureConcat2(layers=layers) + + elif mdef['type'] == 'route3': # nn.Sequential() placeholder for 'route' layer + layers = mdef['layers'] + filters = sum([output_filters[l + 1 if l > 0 else l] for l in layers]) + routs.extend([i + l if l < 0 else l for l in layers]) + modules = FeatureConcat3(layers=layers) + + elif mdef['type'] == 'route_lhalf': # nn.Sequential() placeholder for 'route' layer + layers = mdef['layers'] + filters = sum([output_filters[l + 1 if l > 0 else l] for l in layers])//2 + routs.extend([i + l if l < 0 else l for l in layers]) + modules = FeatureConcat_l(layers=layers) + + elif mdef['type'] == 'shortcut': # nn.Sequential() placeholder for 'shortcut' layer + layers = mdef['from'] + filters = output_filters[-1] + routs.extend([i + l if l < 0 else l for l in layers]) + modules = WeightedFeatureFusion(layers=layers, weight='weights_type' in mdef) + + elif mdef['type'] == 'reorg3d': # yolov3-spp-pan-scale + pass + + elif mdef['type'] == 'reorg': # yolov3-spp-pan-scale + filters = 4 * output_filters[-1] + modules.add_module('Reorg', Reorg()) + + elif mdef['type'] == 'dwt': # yolov3-spp-pan-scale + filters = 4 * output_filters[-1] + modules.add_module('DWT', DWT()) + + elif mdef['type'] == 'implicit_add': # yolov3-spp-pan-scale + filters = mdef['filters'] + modules = ImplicitA(channel=filters) + + elif mdef['type'] == 'implicit_mul': # yolov3-spp-pan-scale + filters = mdef['filters'] + modules = ImplicitM(channel=filters) + + elif mdef['type'] == 'implicit_cat': # yolov3-spp-pan-scale + filters = mdef['filters'] + modules = ImplicitC(channel=filters) + + elif mdef['type'] == 'implicit_add_2d': # yolov3-spp-pan-scale + channels = mdef['filters'] + filters = mdef['atoms'] + modules = Implicit2DA(atom=filters, channel=channels) + + elif mdef['type'] == 'implicit_mul_2d': # yolov3-spp-pan-scale + channels = mdef['filters'] + filters = mdef['atoms'] + modules = Implicit2DM(atom=filters, channel=channels) + + elif mdef['type'] == 'implicit_cat_2d': # yolov3-spp-pan-scale + channels = mdef['filters'] + filters = mdef['atoms'] + modules = Implicit2DC(atom=filters, channel=channels) + + elif mdef['type'] == 'yolo': + yolo_index += 1 + stride = [8, 16, 32, 64, 128] # P3, P4, P5, P6, P7 strides + if any(x in cfg for x in ['yolov4-tiny', 'fpn', 'yolov3']): # P5, P4, P3 strides + stride = [32, 16, 8] + layers = mdef['from'] if 'from' in mdef else [] + modules = YOLOLayer(anchors=mdef['anchors'][mdef['mask']], # anchor list + nc=mdef['classes'], # number of classes + img_size=img_size, # (416, 416) + yolo_index=yolo_index, # 0, 1, 2... + layers=layers, # output layers + stride=stride[yolo_index]) + + # Initialize preceding Conv2d() bias (https://arxiv.org/pdf/1708.02002.pdf section 3.3) + try: + j = layers[yolo_index] if 'from' in mdef else -2 + bias_ = module_list[j][0].bias # shape(255,) + bias = bias_[:modules.no * modules.na].view(modules.na, -1) # shape(3,85) + #bias[:, 4] += -4.5 # obj + bias.data[:, 4] += math.log(8 / (640 / stride[yolo_index]) ** 2) # obj (8 objects per 640 image) + bias.data[:, 5:] += math.log(0.6 / (modules.nc - 0.99)) # cls (sigmoid(p) = 1/nc) + module_list[j][0].bias = torch.nn.Parameter(bias_, requires_grad=bias_.requires_grad) + + #j = [-2, -5, -8] + #for sj in j: + # bias_ = module_list[sj][0].bias + # bias = bias_[:modules.no * 1].view(1, -1) + # bias.data[:, 4] += math.log(8 / (640 / stride[yolo_index]) ** 2) + # bias.data[:, 5:] += math.log(0.6 / (modules.nc - 0.99)) + # module_list[sj][0].bias = torch.nn.Parameter(bias_, requires_grad=bias_.requires_grad) + except: + print('WARNING: smart bias initialization failure.') + + elif mdef['type'] == 'jde': + yolo_index += 1 + stride = [8, 16, 32, 64, 128] # P3, P4, P5, P6, P7 strides + if any(x in cfg for x in ['yolov4-tiny', 'fpn', 'yolov3']): # P5, P4, P3 strides + stride = [32, 16, 8] + layers = mdef['from'] if 'from' in mdef else [] + modules = JDELayer(anchors=mdef['anchors'][mdef['mask']], # anchor list + nc=mdef['classes'], # number of classes + img_size=img_size, # (416, 416) + yolo_index=yolo_index, # 0, 1, 2... + layers=layers, # output layers + stride=stride[yolo_index]) + + # Initialize preceding Conv2d() bias (https://arxiv.org/pdf/1708.02002.pdf section 3.3) + try: + j = layers[yolo_index] if 'from' in mdef else -1 + bias_ = module_list[j][0].bias # shape(255,) + bias = bias_[:modules.no * modules.na].view(modules.na, -1) # shape(3,85) + #bias[:, 4] += -4.5 # obj + bias.data[:, 4] += math.log(8 / (640 / stride[yolo_index]) ** 2) # obj (8 objects per 640 image) + bias.data[:, 5:] += math.log(0.6 / (modules.nc - 0.99)) # cls (sigmoid(p) = 1/nc) + module_list[j][0].bias = torch.nn.Parameter(bias_, requires_grad=bias_.requires_grad) + except: + print('WARNING: smart bias initialization failure.') + + else: + print('Warning: Unrecognized Layer Type: ' + mdef['type']) + + # Register module list and number of output filters + module_list.append(modules) + output_filters.append(filters) + + routs_binary = [False] * (i + 1) + for i in routs: + routs_binary[i] = True + return module_list, routs_binary + + +class YOLOLayer(nn.Module): + def __init__(self, anchors, nc, img_size, yolo_index, layers, stride): + super(YOLOLayer, self).__init__() + self.anchors = torch.Tensor(anchors) + self.index = yolo_index # index of this layer in layers + self.layers = layers # model output layer indices + self.stride = stride # layer stride + self.nl = len(layers) # number of output layers (3) + self.na = len(anchors) # number of anchors (3) + self.nc = nc # number of classes (80) + self.no = nc + 5 # number of outputs (85) + self.nx, self.ny, self.ng = 0, 0, 0 # initialize number of x, y gridpoints + self.anchor_vec = self.anchors / self.stride + self.anchor_wh = self.anchor_vec.view(1, self.na, 1, 1, 2) + + if ONNX_EXPORT: + self.training = False + self.create_grids((img_size[1] // stride, img_size[0] // stride)) # number x, y grid points + + def create_grids(self, ng=(13, 13), device='cpu'): + self.nx, self.ny = ng # x and y grid size + self.ng = torch.tensor(ng, dtype=torch.float) + + # build xy offsets + if not self.training: + yv, xv = torch.meshgrid([torch.arange(self.ny, device=device), torch.arange(self.nx, device=device)]) + self.grid = torch.stack((xv, yv), 2).view((1, 1, self.ny, self.nx, 2)).float() + + if self.anchor_vec.device != device: + self.anchor_vec = self.anchor_vec.to(device) + self.anchor_wh = self.anchor_wh.to(device) + + def forward(self, p, out): + ASFF = False # https://arxiv.org/abs/1911.09516 + if ASFF: + i, n = self.index, self.nl # index in layers, number of layers + p = out[self.layers[i]] + bs, _, ny, nx = p.shape # bs, 255, 13, 13 + if (self.nx, self.ny) != (nx, ny): + self.create_grids((nx, ny), p.device) + + # outputs and weights + # w = F.softmax(p[:, -n:], 1) # normalized weights + w = torch.sigmoid(p[:, -n:]) * (2 / n) # sigmoid weights (faster) + # w = w / w.sum(1).unsqueeze(1) # normalize across layer dimension + + # weighted ASFF sum + p = out[self.layers[i]][:, :-n] * w[:, i:i + 1] + for j in range(n): + if j != i: + p += w[:, j:j + 1] * \ + F.interpolate(out[self.layers[j]][:, :-n], size=[ny, nx], mode='bilinear', align_corners=False) + + elif ONNX_EXPORT: + bs = 1 # batch size + else: + bs, _, ny, nx = p.shape # bs, 255, 13, 13 + if (self.nx, self.ny) != (nx, ny): + self.create_grids((nx, ny), p.device) + + # p.view(bs, 255, 13, 13) -- > (bs, 3, 13, 13, 85) # (bs, anchors, grid, grid, classes + xywh) + p = p.view(bs, self.na, self.no, self.ny, self.nx).permute(0, 1, 3, 4, 2).contiguous() # prediction + + if self.training: + return p + + elif ONNX_EXPORT: + # Avoid broadcasting for ANE operations + m = self.na * self.nx * self.ny + ng = 1. / self.ng.repeat(m, 1) + grid = self.grid.repeat(1, self.na, 1, 1, 1).view(m, 2) + anchor_wh = self.anchor_wh.repeat(1, 1, self.nx, self.ny, 1).view(m, 2) * ng + + p = p.view(m, self.no) + xy = torch.sigmoid(p[:, 0:2]) + grid # x, y + wh = torch.exp(p[:, 2:4]) * anchor_wh # width, height + p_cls = torch.sigmoid(p[:, 4:5]) if self.nc == 1 else \ + torch.sigmoid(p[:, 5:self.no]) * torch.sigmoid(p[:, 4:5]) # conf + return p_cls, xy * ng, wh + + else: # inference + io = p.sigmoid() + io[..., :2] = (io[..., :2] * 2. - 0.5 + self.grid) + io[..., 2:4] = (io[..., 2:4] * 2) ** 2 * self.anchor_wh + io[..., :4] *= self.stride + #io = p.clone() # inference output + #io[..., :2] = torch.sigmoid(io[..., :2]) + self.grid # xy + #io[..., 2:4] = torch.exp(io[..., 2:4]) * self.anchor_wh # wh yolo method + #io[..., :4] *= self.stride + #torch.sigmoid_(io[..., 4:]) + return io.view(bs, -1, self.no), p # view [1, 3, 13, 13, 85] as [1, 507, 85] + + +class JDELayer(nn.Module): + def __init__(self, anchors, nc, img_size, yolo_index, layers, stride): + super(JDELayer, self).__init__() + self.anchors = torch.Tensor(anchors) + self.index = yolo_index # index of this layer in layers + self.layers = layers # model output layer indices + self.stride = stride # layer stride + self.nl = len(layers) # number of output layers (3) + self.na = len(anchors) # number of anchors (3) + self.nc = nc # number of classes (80) + self.no = nc + 5 # number of outputs (85) + self.nx, self.ny, self.ng = 0, 0, 0 # initialize number of x, y gridpoints + self.anchor_vec = self.anchors / self.stride + self.anchor_wh = self.anchor_vec.view(1, self.na, 1, 1, 2) + + if ONNX_EXPORT: + self.training = False + self.create_grids((img_size[1] // stride, img_size[0] // stride)) # number x, y grid points + + def create_grids(self, ng=(13, 13), device='cpu'): + self.nx, self.ny = ng # x and y grid size + self.ng = torch.tensor(ng, dtype=torch.float) + + # build xy offsets + if not self.training: + yv, xv = torch.meshgrid([torch.arange(self.ny, device=device), torch.arange(self.nx, device=device)]) + self.grid = torch.stack((xv, yv), 2).view((1, 1, self.ny, self.nx, 2)).float() + + if self.anchor_vec.device != device: + self.anchor_vec = self.anchor_vec.to(device) + self.anchor_wh = self.anchor_wh.to(device) + + def forward(self, p, out): + ASFF = False # https://arxiv.org/abs/1911.09516 + if ASFF: + i, n = self.index, self.nl # index in layers, number of layers + p = out[self.layers[i]] + bs, _, ny, nx = p.shape # bs, 255, 13, 13 + if (self.nx, self.ny) != (nx, ny): + self.create_grids((nx, ny), p.device) + + # outputs and weights + # w = F.softmax(p[:, -n:], 1) # normalized weights + w = torch.sigmoid(p[:, -n:]) * (2 / n) # sigmoid weights (faster) + # w = w / w.sum(1).unsqueeze(1) # normalize across layer dimension + + # weighted ASFF sum + p = out[self.layers[i]][:, :-n] * w[:, i:i + 1] + for j in range(n): + if j != i: + p += w[:, j:j + 1] * \ + F.interpolate(out[self.layers[j]][:, :-n], size=[ny, nx], mode='bilinear', align_corners=False) + + elif ONNX_EXPORT: + bs = 1 # batch size + else: + bs, _, ny, nx = p.shape # bs, 255, 13, 13 + if (self.nx, self.ny) != (nx, ny): + self.create_grids((nx, ny), p.device) + + # p.view(bs, 255, 13, 13) -- > (bs, 3, 13, 13, 85) # (bs, anchors, grid, grid, classes + xywh) + p = p.view(bs, self.na, self.no, self.ny, self.nx).permute(0, 1, 3, 4, 2).contiguous() # prediction + + if self.training: + return p + + elif ONNX_EXPORT: + # Avoid broadcasting for ANE operations + m = self.na * self.nx * self.ny + ng = 1. / self.ng.repeat(m, 1) + grid = self.grid.repeat(1, self.na, 1, 1, 1).view(m, 2) + anchor_wh = self.anchor_wh.repeat(1, 1, self.nx, self.ny, 1).view(m, 2) * ng + + p = p.view(m, self.no) + xy = torch.sigmoid(p[:, 0:2]) + grid # x, y + wh = torch.exp(p[:, 2:4]) * anchor_wh # width, height + p_cls = torch.sigmoid(p[:, 4:5]) if self.nc == 1 else \ + torch.sigmoid(p[:, 5:self.no]) * torch.sigmoid(p[:, 4:5]) # conf + return p_cls, xy * ng, wh + + else: # inference + #io = p.sigmoid() + #io[..., :2] = (io[..., :2] * 2. - 0.5 + self.grid) + #io[..., 2:4] = (io[..., 2:4] * 2) ** 2 * self.anchor_wh + #io[..., :4] *= self.stride + io = p.clone() # inference output + io[..., :2] = torch.sigmoid(io[..., :2]) * 2. - 0.5 + self.grid # xy + io[..., 2:4] = (torch.sigmoid(io[..., 2:4]) * 2) ** 2 * self.anchor_wh # wh yolo method + io[..., :4] *= self.stride + io[..., 4:] = F.softmax(io[..., 4:]) + return io.view(bs, -1, self.no), p # view [1, 3, 13, 13, 85] as [1, 507, 85] + +class Darknet(nn.Module): + # YOLOv3 object detection model + + def __init__(self, cfg, img_size=(416, 416), verbose=False): + super(Darknet, self).__init__() + + self.module_defs = parse_model_cfg(cfg) + self.module_list, self.routs = create_modules(self.module_defs, img_size, cfg) + self.yolo_layers = get_yolo_layers(self) + # torch_utils.initialize_weights(self) + + # Darknet Header https://github.com/AlexeyAB/darknet/issues/2914#issuecomment-496675346 + self.version = np.array([0, 2, 5], dtype=np.int32) # (int32) version info: major, minor, revision + self.seen = np.array([0], dtype=np.int64) # (int64) number of images seen during training + self.info(verbose) if not ONNX_EXPORT else None # print model description + + def forward(self, x, augment=False, verbose=False): + + if not augment: + return self.forward_once(x) + else: # Augment images (inference and test only) https://github.com/ultralytics/yolov3/issues/931 + img_size = x.shape[-2:] # height, width + s = [0.83, 0.67] # scales + y = [] + for i, xi in enumerate((x, + torch_utils.scale_img(x.flip(3), s[0], same_shape=False), # flip-lr and scale + torch_utils.scale_img(x, s[1], same_shape=False), # scale + )): + # cv2.imwrite('img%g.jpg' % i, 255 * xi[0].numpy().transpose((1, 2, 0))[:, :, ::-1]) + y.append(self.forward_once(xi)[0]) + + y[1][..., :4] /= s[0] # scale + y[1][..., 0] = img_size[1] - y[1][..., 0] # flip lr + y[2][..., :4] /= s[1] # scale + + # for i, yi in enumerate(y): # coco small, medium, large = < 32**2 < 96**2 < + # area = yi[..., 2:4].prod(2)[:, :, None] + # if i == 1: + # yi *= (area < 96. ** 2).float() + # elif i == 2: + # yi *= (area > 32. ** 2).float() + # y[i] = yi + + y = torch.cat(y, 1) + return y, None + + def forward_once(self, x, augment=False, verbose=False): + img_size = x.shape[-2:] # height, width + yolo_out, out = [], [] + if verbose: + print('0', x.shape) + str = '' + + # Augment images (inference and test only) + if augment: # https://github.com/ultralytics/yolov3/issues/931 + nb = x.shape[0] # batch size + s = [0.83, 0.67] # scales + x = torch.cat((x, + torch_utils.scale_img(x.flip(3), s[0]), # flip-lr and scale + torch_utils.scale_img(x, s[1]), # scale + ), 0) + + for i, module in enumerate(self.module_list): + name = module.__class__.__name__ + #print(name) + if name in ['WeightedFeatureFusion', 'FeatureConcat', 'FeatureConcat2', 'FeatureConcat3', 'FeatureConcat_l', 'ScaleChannel', 'ShiftChannel', 'ShiftChannel2D', 'ControlChannel', 'ControlChannel2D', 'AlternateChannel', 'AlternateChannel2D', 'SelectChannel', 'SelectChannel2D', 'ScaleSpatial']: # sum, concat + if verbose: + l = [i - 1] + module.layers # layers + sh = [list(x.shape)] + [list(out[i].shape) for i in module.layers] # shapes + str = ' >> ' + ' + '.join(['layer %g %s' % x for x in zip(l, sh)]) + x = module(x, out) # WeightedFeatureFusion(), FeatureConcat() + elif name in ['ImplicitA', 'ImplicitM', 'ImplicitC', 'Implicit2DA', 'Implicit2DM', 'Implicit2DC']: + x = module() + elif name == 'YOLOLayer': + yolo_out.append(module(x, out)) + elif name == 'JDELayer': + yolo_out.append(module(x, out)) + else: # run module directly, i.e. mtype = 'convolutional', 'upsample', 'maxpool', 'batchnorm2d' etc. + #print(module) + #print(x.shape) + x = module(x) + + out.append(x if self.routs[i] else []) + if verbose: + print('%g/%g %s -' % (i, len(self.module_list), name), list(x.shape), str) + str = '' + + if self.training: # train + return yolo_out + elif ONNX_EXPORT: # export + x = [torch.cat(x, 0) for x in zip(*yolo_out)] + return x[0], torch.cat(x[1:3], 1) # scores, boxes: 3780x80, 3780x4 + else: # inference or test + x, p = zip(*yolo_out) # inference output, training output + x = torch.cat(x, 1) # cat yolo outputs + if augment: # de-augment results + x = torch.split(x, nb, dim=0) + x[1][..., :4] /= s[0] # scale + x[1][..., 0] = img_size[1] - x[1][..., 0] # flip lr + x[2][..., :4] /= s[1] # scale + x = torch.cat(x, 1) + return x, p + + def fuse(self): + # Fuse Conv2d + BatchNorm2d layers throughout model + print('Fusing layers...') + fused_list = nn.ModuleList() + for a in list(self.children())[0]: + if isinstance(a, nn.Sequential): + for i, b in enumerate(a): + if isinstance(b, nn.modules.batchnorm.BatchNorm2d): + # fuse this bn layer with the previous conv2d layer + conv = a[i - 1] + fused = torch_utils.fuse_conv_and_bn(conv, b) + a = nn.Sequential(fused, *list(a.children())[i + 1:]) + break + fused_list.append(a) + self.module_list = fused_list + self.info() if not ONNX_EXPORT else None # yolov3-spp reduced from 225 to 152 layers + + def info(self, verbose=False): + torch_utils.model_info(self, verbose) + + +def get_yolo_layers(model): + return [i for i, m in enumerate(model.module_list) if m.__class__.__name__ in ['YOLOLayer', 'JDELayer']] # [89, 101, 113] + + +def load_darknet_weights(self, weights, cutoff=-1): + # Parses and loads the weights stored in 'weights' + + # Establish cutoffs (load layers between 0 and cutoff. if cutoff = -1 all are loaded) + file = Path(weights).name + if file == 'darknet53.conv.74': + cutoff = 75 + elif file == 'yolov3-tiny.conv.15': + cutoff = 15 + + # Read weights file + with open(weights, 'rb') as f: + # Read Header https://github.com/AlexeyAB/darknet/issues/2914#issuecomment-496675346 + self.version = np.fromfile(f, dtype=np.int32, count=3) # (int32) version info: major, minor, revision + self.seen = np.fromfile(f, dtype=np.int64, count=1) # (int64) number of images seen during training + + weights = np.fromfile(f, dtype=np.float32) # the rest are weights + + ptr = 0 + for i, (mdef, module) in enumerate(zip(self.module_defs[:cutoff], self.module_list[:cutoff])): + if mdef['type'] == 'convolutional': + conv = module[0] + if mdef['batch_normalize']: + # Load BN bias, weights, running mean and running variance + bn = module[1] + nb = bn.bias.numel() # number of biases + # Bias + bn.bias.data.copy_(torch.from_numpy(weights[ptr:ptr + nb]).view_as(bn.bias)) + ptr += nb + # Weight + bn.weight.data.copy_(torch.from_numpy(weights[ptr:ptr + nb]).view_as(bn.weight)) + ptr += nb + # Running Mean + bn.running_mean.data.copy_(torch.from_numpy(weights[ptr:ptr + nb]).view_as(bn.running_mean)) + ptr += nb + # Running Var + bn.running_var.data.copy_(torch.from_numpy(weights[ptr:ptr + nb]).view_as(bn.running_var)) + ptr += nb + else: + # Load conv. bias + nb = conv.bias.numel() + conv_b = torch.from_numpy(weights[ptr:ptr + nb]).view_as(conv.bias) + conv.bias.data.copy_(conv_b) + ptr += nb + # Load conv. weights + nw = conv.weight.numel() # number of weights + conv.weight.data.copy_(torch.from_numpy(weights[ptr:ptr + nw]).view_as(conv.weight)) + ptr += nw + + +def save_weights(self, path='model.weights', cutoff=-1): + # Converts a PyTorch model to Darket format (*.pt to *.weights) + # Note: Does not work if model.fuse() is applied + with open(path, 'wb') as f: + # Write Header https://github.com/AlexeyAB/darknet/issues/2914#issuecomment-496675346 + self.version.tofile(f) # (int32) version info: major, minor, revision + self.seen.tofile(f) # (int64) number of images seen during training + + # Iterate through layers + for i, (mdef, module) in enumerate(zip(self.module_defs[:cutoff], self.module_list[:cutoff])): + if mdef['type'] == 'convolutional': + conv_layer = module[0] + # If batch norm, load bn first + if mdef['batch_normalize']: + bn_layer = module[1] + bn_layer.bias.data.cpu().numpy().tofile(f) + bn_layer.weight.data.cpu().numpy().tofile(f) + bn_layer.running_mean.data.cpu().numpy().tofile(f) + bn_layer.running_var.data.cpu().numpy().tofile(f) + # Load conv bias + else: + conv_layer.bias.data.cpu().numpy().tofile(f) + # Load conv weights + conv_layer.weight.data.cpu().numpy().tofile(f) + + +def convert(cfg='cfg/yolov3-spp.cfg', weights='weights/yolov3-spp.weights', saveto='converted.weights'): + # Converts between PyTorch and Darknet format per extension (i.e. *.weights convert to *.pt and vice versa) + # from models import *; convert('cfg/yolov3-spp.cfg', 'weights/yolov3-spp.weights') + + # Initialize model + model = Darknet(cfg) + ckpt = torch.load(weights) # load checkpoint + try: + ckpt['model'] = {k: v for k, v in ckpt['model'].items() if model.state_dict()[k].numel() == v.numel()} + model.load_state_dict(ckpt['model'], strict=False) + save_weights(model, path=saveto, cutoff=-1) + except KeyError as e: + print(e) + +def attempt_download(weights): + # Attempt to download pretrained weights if not found locally + weights = weights.strip() + msg = weights + ' missing, try downloading from https://drive.google.com/open?id=1LezFG5g3BCW6iYaV89B2i64cqEUZD7e0' + + if len(weights) > 0 and not os.path.isfile(weights): + d = {''} + + file = Path(weights).name + if file in d: + r = gdrive_download(id=d[file], name=weights) + else: # download from pjreddie.com + url = 'https://pjreddie.com/media/files/' + file + print('Downloading ' + url) + r = os.system('curl -f ' + url + ' -o ' + weights) + + # Error check + if not (r == 0 and os.path.exists(weights) and os.path.getsize(weights) > 1E6): # weights exist and > 1MB + os.system('rm ' + weights) # remove partial downloads + raise Exception(msg) diff --git a/PyTorch/contrib/cv/detection/YOLOR/requirements-GPU.txt b/PyTorch/contrib/cv/detection/YOLOR/requirements-GPU.txt index d62e7d20ea2daacbcfa8dbc4c075570ff3d8d57c..c98049d8777db49aabe488b79aab92b6d0ba6a4a 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/requirements-GPU.txt +++ b/PyTorch/contrib/cv/detection/YOLOR/requirements-GPU.txt @@ -1,43 +1,43 @@ -# pip install -U -r requirements-GPU.txt - -# base ---------------------------------------- -Cython -numpy -opencv-python -torch>=1.5.0 -matplotlib -pillow -tensorboard -PyYAML>=5.3 -torchvision>=0.6 -scipy -tqdm -pycocotools>=2.0 - -# extras -------------------------------------- -# thop # FLOPS computation - -# logging ------------------------------------- -# wandb - -# plotting ------------------------------------ -# seaborn>=0.11.0 -# pandas - -# export -------------------------------------- -# coremltools>=4.1 -# onnx>=1.8.1 -# scikit-learn==0.19.2 # for coreml quantization - -# Nvidia Apex for mixed precision training -------------------------- -# git clone https://github.com/NVIDIA/apex && cd apex && pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" . --user && cd .. && rm -rf apex - -# Conda commands (in place of pip) --------------------------------------------- -# conda update -yn base -c defaults conda -# conda install -yc anaconda numpy opencv matplotlib tqdm pillow ipython -# conda install -yc conda-forge scikit-image pycocotools tensorboard -# conda install -yc spyder-ide spyder-line-profiler -# conda install -yc pytorch pytorch torchvision -# conda install -yc conda-forge protobuf numpy && pip install onnx==1.6.0 # https://github.com/onnx/onnx#linux-and-macos - - +# pip install -U -r requirements-GPU.txt + +# base ---------------------------------------- +Cython +numpy +opencv-python +torch>=1.5.0 +matplotlib +pillow +tensorboard +PyYAML>=5.3 +torchvision>=0.6 +scipy +tqdm +pycocotools>=2.0 + +# extras -------------------------------------- +# thop # FLOPS computation + +# logging ------------------------------------- +# wandb + +# plotting ------------------------------------ +# seaborn>=0.11.0 +# pandas + +# export -------------------------------------- +# coremltools>=4.1 +# onnx>=1.8.1 +# scikit-learn==0.19.2 # for coreml quantization + +# Nvidia Apex for mixed precision training -------------------------- +# git clone https://github.com/NVIDIA/apex && cd apex && pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" . --user && cd .. && rm -rf apex + +# Conda commands (in place of pip) --------------------------------------------- +# conda update -yn base -c defaults conda +# conda install -yc anaconda numpy opencv matplotlib tqdm pillow ipython +# conda install -yc conda-forge scikit-image pycocotools tensorboard +# conda install -yc spyder-ide spyder-line-profiler +# conda install -yc pytorch pytorch torchvision +# conda install -yc conda-forge protobuf numpy && pip install onnx==1.6.0 # https://github.com/onnx/onnx#linux-and-macos + + diff --git a/PyTorch/contrib/cv/detection/YOLOR/requirements.txt b/PyTorch/contrib/cv/detection/YOLOR/requirements.txt index 3e444758361d798ad0024955f6f3e2744fa4c6c5..da9cc83a5ab95b9de1ff0da6c210f0e702ff84a2 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/requirements.txt +++ b/PyTorch/contrib/cv/detection/YOLOR/requirements.txt @@ -1,30 +1,30 @@ -# pip install -qr requirements.txt - -# base ---------------------------------------- -Cython -matplotlib -numpy -opencv-python -Pillow -PyYAML -scipy -tensorboard -tqdm -sympy>=1.8 -decorator>=5.0.9 -pycocotools>=2.0 # COCO mAP - -# extras -------------------------------------- -# thop # FLOPS computation - -# logging ------------------------------------- -# wandb - -# plotting ------------------------------------ -# seaborn>=0.11.0 -# pandas - -# export -------------------------------------- -# coremltools>=4.1 -# onnx>=1.8.1 -# scikit-learn==0.19.2 # for coreml quantization +# pip install -qr requirements.txt + +# base ---------------------------------------- +Cython +matplotlib +numpy +opencv-python +Pillow +PyYAML +scipy +tensorboard +tqdm +sympy>=1.8 +decorator>=5.0.9 +pycocotools>=2.0 # COCO mAP + +# extras -------------------------------------- +# thop # FLOPS computation + +# logging ------------------------------------- +# wandb + +# plotting ------------------------------------ +# seaborn>=0.11.0 +# pandas + +# export -------------------------------------- +# coremltools>=4.1 +# onnx>=1.8.1 +# scikit-learn==0.19.2 # for coreml quantization diff --git a/PyTorch/contrib/cv/detection/YOLOR/test.py b/PyTorch/contrib/cv/detection/YOLOR/test.py index 614f167330029a45e8b01901d3cc77931f974cc5..4fe2c17ef7ebf8534e09e264fe42dc6f5f6d4e32 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/test.py +++ b/PyTorch/contrib/cv/detection/YOLOR/test.py @@ -1,378 +1,378 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import glob -import json -import os -from pathlib import Path - -import numpy as np -import torch -import yaml -from tqdm import tqdm - -from utils.datasets import create_dataloader -from utils.general import coco80_to_coco91_class, check_dataset, check_file, check_img_size, box_iou, \ - non_max_suppression, scale_coords, xyxy2xywh, xywh2xyxy, clip_coords, set_logging, increment_path -from utils.loss import compute_loss -from utils.metrics import ap_per_class -from utils.plots import plot_images, output_to_target -from utils.torch_utils import select_device, time_synchronized - -from models.models import * -from apex import amp - -def load_classes(path): - # Loads *.names file at 'path' - with open(path, 'r') as f: - names = f.read().split('\n') - return list(filter(None, names)) # filter removes empty strings (such as last line) - - -def set_seed_everything(seed): - random.seed(seed) - os.environ['PYTHONHASHSEED'] = str(seed) - np.random.seed(seed) - torch.manual_seed(seed) - torch.cuda.manual_seed(seed) - torch.cuda.manual_seed_all(seed) - torch.backends.cudnn.deterministic = True - torch.backends.cudnn.benchmark = False - - -def test(data, - weights=None, - batch_size=16, - imgsz=640, - conf_thres=0.001, - iou_thres=0.6, # for NMS - save_json=False, - single_cls=False, - augment=False, - verbose=False, - model=None, - dataloader=None, - save_dir=Path(''), # for saving images - save_txt=False, # for auto-labelling - save_conf=False, - plots=True, - log_imgs=0): # number of logged images - - # Initialize/load model and set device - # set_seed_everything(1234) - training = model is not None - if training: # called by train.py - device = next(model.parameters()).device # get model device - else: # called directly - set_logging() - device = select_device(opt.device, opt.npu, batch_size=batch_size) - save_txt = opt.save_txt # save *.txt labels - - # Directories - save_dir = Path(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok)) # increment run - (save_dir / 'labels' if save_txt else save_dir).mkdir(parents=True, exist_ok=True) # make dir - - # Load model - model = Darknet(opt.cfg).to(device) - - # load model - try: - ckpt = torch.load(weights[0], map_location=device) # load checkpoint - ckpt['model'] = {k: v for k, v in ckpt['model'].items() if model.state_dict()[k].numel() == v.numel()} - model.load_state_dict(ckpt['model'], strict=False) - except: - load_darknet_weights(model, weights[0]) - - imgsz = check_img_size(imgsz, s=64) # check img_size - - model = amp.initialize(model, opt_level='O1', verbosity=0, loss_scale=64) - - # Half - half = device.type != 'cpu' # half precision only supported on CUDA - if half: - model.half() - - # Configure - model.eval() - is_coco = data.endswith('coco.yaml') # is COCO dataset - with open(data) as f: - data = yaml.load(f, Loader=yaml.FullLoader) # model dict - check_dataset(data) # check - nc = 1 if single_cls else int(data['nc']) # number of classes - iouv = torch.linspace(0.5, 0.95, 10) # iou vector for mAP@0.5:0.95 - niou = iouv.numel() - - # ---------------------------------not using wandb--------------------------------- - # Logging - log_imgs, wandb = min(log_imgs, 100), None # ceil - # try: - # import wandb # Weights & Biases - # except ImportError: - log_imgs = 0 - # ---------------------------------not using wandb--------------------------------- - - # Dataloader - if not training: - img = torch.zeros((1, 3, imgsz, imgsz), device=device) # init img - _ = model(img.half() if half else img) if device.type != 'cpu' else None # run once - path = data['test'] if opt.task == 'test' else data['val'] # path to val/test images - dataloader = create_dataloader(path, imgsz, batch_size, 64, opt, - hyp=None, augment=False, cache=False, pad=0.5, rect=True)[0] - - seen = 0 - try: - names = model.names if hasattr(model, 'names') else model.module.names - except: - names = load_classes(opt.names) - coco91class = coco80_to_coco91_class() - s = ('%20s' + '%12s' * 6) % ('Class', 'Images', 'Targets', 'P', 'R', 'mAP@.5', 'mAP@.5:.95') - p, r, f1, mp, mr, map50, map, t0, t1 = 0., 0., 0., 0., 0., 0., 0., 0., 0. - loss = torch.zeros(3, device=device) - jdict, stats, ap, ap_class, wandb_images = [], [], [], [], [] - - pbar = tqdm(dataloader) - for batch_i, (img, targets, paths, shapes) in enumerate(pbar): - img = img.to(device, non_blocking=True) - img = img.half() if half else img.float() # uint8 to fp16/32 - img /= 255.0 # 0 - 255 to 0.0 - 1.0 - targets = targets.to(device) - nb, _, height, width = img.shape # batch size, channels, height, width - whwh = torch.Tensor([width, height, width, height]) - - # Disable gradients - with torch.no_grad(): - # Run model - t = time_synchronized() - inf_out, _ = model(img, augment=augment) # inference and training outputs - t0 += time_synchronized() - t - - # Compute loss / no test during training - # if training: # if model has loss hyperparameters - # loss += compute_loss([x.float() for x in train_out], targets, model)[1][:3] # box, obj, cls - - # Run NMS - t = time_synchronized() - output = non_max_suppression(inf_out, conf_thres=conf_thres, iou_thres=iou_thres) - t1 += time_synchronized() - t - targets = targets.cpu() - - # Statistics per image - for si, pred in enumerate(output): - labels = targets[targets[:, 0] == si, 1:] - nl = len(labels) - tcls = labels[:, 0].tolist() if nl else [] # target class - seen += 1 - - if len(pred) == 0: - if nl: - stats.append((torch.zeros(0, niou, dtype=torch.bool), torch.Tensor(), torch.Tensor(), tcls)) - continue - - # Append to text file - path = Path(paths[si]) - if save_txt: - gn = torch.tensor(shapes[si][0])[[1, 0, 1, 0]] # normalization gain whwh - x = pred.clone() - x[:, :4] = scale_coords(img[si].shape[1:], x[:, :4], shapes[si][0], shapes[si][1]) # to original - for *xyxy, conf, cls in x: - xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh - line = (cls, *xywh, conf) if save_conf else (cls, *xywh) # label format - with open(save_dir / 'labels' / (path.stem + '.txt'), 'a') as f: - f.write(('%g ' * len(line)).rstrip() % line + '\n') - - # W&B logging - if plots and len(wandb_images) < log_imgs: - box_data = [{"position": {"minX": xyxy[0], "minY": xyxy[1], "maxX": xyxy[2], "maxY": xyxy[3]}, - "class_id": int(cls), - "box_caption": "%s %.3f" % (names[cls], conf), - "scores": {"class_score": conf}, - "domain": "pixel"} for *xyxy, conf, cls in pred.tolist()] - boxes = {"predictions": {"box_data": box_data, "class_labels": names}} - wandb_images.append(wandb.Image(img[si], boxes=boxes, caption=path.name)) - - # Clip boxes to image bounds - clip_coords(pred, (height, width)) - - # Append to pycocotools JSON dictionary - if save_json: - # [{"image_id": 42, "category_id": 18, "bbox": [258.15, 41.29, 348.26, 243.78], "score": 0.236}, ... - image_id = int(path.stem) if path.stem.isnumeric() else path.stem - box = pred[:, :4].clone() # xyxy - scale_coords(img[si].shape[1:], box, shapes[si][0], shapes[si][1]) # to original shape - box = xyxy2xywh(box) # xywh - box[:, :2] -= box[:, 2:] / 2 # xy center to top-left corner - for p, b in zip(pred.tolist(), box.tolist()): - jdict.append({'image_id': image_id, - 'category_id': coco91class[int(p[5])] if is_coco else int(p[5]), - 'bbox': [round(x, 3) for x in b], - 'score': round(p[4], 5)}) - - # Assign all predictions as incorrect - correct = torch.zeros(pred.shape[0], niou, dtype=torch.bool) - if nl: - detected = [] # target indices - tcls_tensor = labels[:, 0] - - # target boxes - tbox = xywh2xyxy(labels[:, 1:5]) * whwh - - # Per target class - for cls in torch.unique(tcls_tensor): - ti = (cls == tcls_tensor).nonzero(as_tuple=False).view(-1) # prediction indices - pi = (cls == pred[:, 5]).nonzero(as_tuple=False).view(-1) # target indices - - # Search for detections - if pi.shape[0]: - # Prediction to target ious - ious, i = box_iou(pred[pi, :4], tbox[ti]).max(1) # best ious, indices - - # Append detections - temp_nonzero_idx = (ious > iouv[0]).nonzero(as_tuple=False) - for j in temp_nonzero_idx: - d = ti[i[j]] # detected target - if d not in detected: - detected.append(d) - correct[pi[j]] = ious[j] > iouv # iou_thres is 1xn - if len(detected) == nl: # all targets already located in image - break - - # Append statistics (correct, conf, pcls, tcls) - stats.append((correct.cpu(), pred[:, 4].cpu(), pred[:, 5].cpu(), tcls)) - - # Plot images - if plots and batch_i < 3: - f = save_dir / f'{batch_i}_labels.jpg' # filename - plot_images(img, targets, paths, f, names) # labels - f = save_dir / f'{batch_i}_pred.jpg' - plot_images(img, output_to_target(output, width, height), paths, f, names) # predictions - - # Compute statistics - stats = [np.concatenate(x, 0) for x in zip(*stats)] # to numpy - if len(stats) and stats[0].any(): - p, r, ap, f1, ap_class = ap_per_class(*stats, plot=plots, fname=save_dir / 'precision-recall_curve.png') - p, r, ap50, ap = p[:, 0], r[:, 0], ap[:, 0], ap.mean(1) # [P, R, AP@0.5, AP@0.5:0.95] - mp, mr, map50, map = p.mean(), r.mean(), ap50.mean(), ap.mean() - nt = np.bincount(stats[3].astype(np.int64), minlength=nc) # number of targets per class - else: - nt = torch.zeros(1) - - # W&B logging - if plots and wandb: - wandb.log({"Images": wandb_images}) - wandb.log({"Validation": [wandb.Image(str(x), caption=x.name) for x in sorted(save_dir.glob('test*.jpg'))]}) - - # Print results - pf = '%20s' + '%12.3g' * 6 # print format - print(pf % ('all', seen, nt.sum(), mp, mr, map50, map)) - - # Print results per class - if verbose and nc > 1 and len(stats): - for i, c in enumerate(ap_class): - print(pf % (names[c], seen, nt[c], p[i], r[i], ap50[i], ap[i])) - - # Print speeds - t = tuple(x / seen * 1E3 for x in (t0, t1, t0 + t1)) + (imgsz, imgsz, batch_size) # tuple - if not training: - print('Speed: %.1f/%.1f/%.1f ms inference/NMS/total per %gx%g image at batch-size %g' % t) - - # Save JSON - if save_json and len(jdict): - w = Path(weights[0] if isinstance(weights, list) else weights).stem if weights is not None else '' # weights - anno_json = glob.glob('../data/coco/annotations/instances_val*.json')[0] # annotations json - pred_json = str(save_dir / f"{w}_predictions.json") # predictions json - print('\nEvaluating pycocotools mAP... saving %s...' % pred_json) - with open(pred_json, 'w') as f: - json.dump(jdict, f) - - try: # https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocoEvalDemo.ipynb - from pycocotools.coco import COCO - from pycocotools.cocoeval import COCOeval - - anno = COCO(anno_json) # init annotations api - pred = anno.loadRes(pred_json) # init predictions api - eval = COCOeval(anno, pred, 'bbox') - if is_coco: - eval.params.imgIds = [int(Path(x).stem) for x in dataloader.dataset.img_files] # image IDs to evaluate - eval.evaluate() - eval.accumulate() - eval.summarize() - map, map50 = eval.stats[:2] # update results (mAP@0.5:0.95, mAP@0.5) - except Exception as e: - print('ERROR: pycocotools unable to run: %s' % e) - - # Return results - if not training: - print('Results saved to %s' % save_dir) - model.float() # for training - maps = np.zeros(nc) + map - for i, c in enumerate(ap_class): - maps[c] = ap[i] - return (mp, mr, map50, map, *(loss.cpu() / len(dataloader)).tolist()), maps, t - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(prog='test.py') - parser.add_argument('--weights', nargs='+', type=str, default='yolor_p6.pt', help='model.pt path(s)') - parser.add_argument('--data', type=str, default='data/coco.yaml', help='*.data path') - parser.add_argument('--batch-size', type=int, default=32, help='size of each image batch') - parser.add_argument('--img-size', type=int, default=1280, help='inference size (pixels)') - parser.add_argument('--conf-thres', type=float, default=0.001, help='object confidence threshold') - parser.add_argument('--iou-thres', type=float, default=0.65, help='IOU threshold for NMS') - parser.add_argument('--task', default='val', help="'val', 'test', 'study'") - parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') - parser.add_argument('--single-cls', action='store_true', help='treat as single-class dataset') - parser.add_argument('--augment', action='store_true', help='augmented inference') - parser.add_argument('--verbose', action='store_true', help='report mAP by class') - parser.add_argument('--save-txt', action='store_true', help='save results to *.txt') - parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels') - parser.add_argument('--save-json', action='store_true', help='save a cocoapi-compatible JSON results file') - parser.add_argument('--project', default='runs/test', help='save to project/name') - parser.add_argument('--name', default='exp', help='save to project/name') - parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') - parser.add_argument('--cfg', type=str, default='cfg/yolor_p6.cfg', help='*.cfg path') - parser.add_argument('--names', type=str, default='data/coco.names', help='*.cfg path') - parser.add_argument('--npu', default=None, type=int, help='NPU id to use.') - opt = parser.parse_args() - opt.save_json |= opt.data.endswith('coco.yaml') - opt.data = check_file(opt.data) # check file - print(opt) - - if opt.task in ['val', 'test']: # run normally - test(opt.data, - opt.weights, - opt.batch_size, - opt.img_size, - opt.conf_thres, - opt.iou_thres, - opt.save_json, - opt.single_cls, - opt.augment, - opt.verbose, - save_txt=opt.save_txt, - save_conf=opt.save_conf, - ) - - elif opt.task == 'study': # run over a range of settings and save/plot - for weights in ['yolor_p6.pt', 'yolor_w6.pt']: - f = 'study_%s_%s.txt' % (Path(opt.data).stem, Path(weights).stem) # filename to save to - x = list(range(320, 800, 64)) # x axis - y = [] # y axis - for i in x: # img-size - print('\nRunning %s point %s...' % (f, i)) - r, _, t = test(opt.data, weights, opt.batch_size, i, opt.conf_thres, opt.iou_thres, opt.save_json) - y.append(r + t) # results and times - np.savetxt(f, y, fmt='%10.4g') # save - os.system('zip -r study.zip study_*.txt') - # utils.general.plot_study_txt(f, x) # plot +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import glob +import json +import os +from pathlib import Path + +import numpy as np +import torch +import yaml +from tqdm import tqdm + +from utils.datasets import create_dataloader +from utils.general import coco80_to_coco91_class, check_dataset, check_file, check_img_size, box_iou, \ + non_max_suppression, scale_coords, xyxy2xywh, xywh2xyxy, clip_coords, set_logging, increment_path +from utils.loss import compute_loss +from utils.metrics import ap_per_class +from utils.plots import plot_images, output_to_target +from utils.torch_utils import select_device, time_synchronized + +from models.models import * +from apex import amp + +def load_classes(path): + # Loads *.names file at 'path' + with open(path, 'r') as f: + names = f.read().split('\n') + return list(filter(None, names)) # filter removes empty strings (such as last line) + + +def set_seed_everything(seed): + random.seed(seed) + os.environ['PYTHONHASHSEED'] = str(seed) + np.random.seed(seed) + torch.manual_seed(seed) + torch.cuda.manual_seed(seed) + torch.cuda.manual_seed_all(seed) + torch.backends.cudnn.deterministic = True + torch.backends.cudnn.benchmark = False + + +def test(data, + weights=None, + batch_size=16, + imgsz=640, + conf_thres=0.001, + iou_thres=0.6, # for NMS + save_json=False, + single_cls=False, + augment=False, + verbose=False, + model=None, + dataloader=None, + save_dir=Path(''), # for saving images + save_txt=False, # for auto-labelling + save_conf=False, + plots=True, + log_imgs=0): # number of logged images + + # Initialize/load model and set device + # set_seed_everything(1234) + training = model is not None + if training: # called by train.py + device = next(model.parameters()).device # get model device + else: # called directly + set_logging() + device = select_device(opt.device, opt.npu, batch_size=batch_size) + save_txt = opt.save_txt # save *.txt labels + + # Directories + save_dir = Path(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok)) # increment run + (save_dir / 'labels' if save_txt else save_dir).mkdir(parents=True, exist_ok=True) # make dir + + # Load model + model = Darknet(opt.cfg).to(device) + + # load model + try: + ckpt = torch.load(weights[0], map_location=device) # load checkpoint + ckpt['model'] = {k: v for k, v in ckpt['model'].items() if model.state_dict()[k].numel() == v.numel()} + model.load_state_dict(ckpt['model'], strict=False) + except: + load_darknet_weights(model, weights[0]) + + imgsz = check_img_size(imgsz, s=64) # check img_size + + model = amp.initialize(model, opt_level='O1', verbosity=0, loss_scale=64) + + # Half + half = device.type != 'cpu' # half precision only supported on CUDA + if half: + model.half() + + # Configure + model.eval() + is_coco = data.endswith('coco.yaml') # is COCO dataset + with open(data) as f: + data = yaml.load(f, Loader=yaml.FullLoader) # model dict + check_dataset(data) # check + nc = 1 if single_cls else int(data['nc']) # number of classes + iouv = torch.linspace(0.5, 0.95, 10) # iou vector for mAP@0.5:0.95 + niou = iouv.numel() + + # ---------------------------------not using wandb--------------------------------- + # Logging + log_imgs, wandb = min(log_imgs, 100), None # ceil + # try: + # import wandb # Weights & Biases + # except ImportError: + log_imgs = 0 + # ---------------------------------not using wandb--------------------------------- + + # Dataloader + if not training: + img = torch.zeros((1, 3, imgsz, imgsz), device=device) # init img + _ = model(img.half() if half else img) if device.type != 'cpu' else None # run once + path = data['test'] if opt.task == 'test' else data['val'] # path to val/test images + dataloader = create_dataloader(path, imgsz, batch_size, 64, opt, + hyp=None, augment=False, cache=False, pad=0.5, rect=True)[0] + + seen = 0 + try: + names = model.names if hasattr(model, 'names') else model.module.names + except: + names = load_classes(opt.names) + coco91class = coco80_to_coco91_class() + s = ('%20s' + '%12s' * 6) % ('Class', 'Images', 'Targets', 'P', 'R', 'mAP@.5', 'mAP@.5:.95') + p, r, f1, mp, mr, map50, map, t0, t1 = 0., 0., 0., 0., 0., 0., 0., 0., 0. + loss = torch.zeros(3, device=device) + jdict, stats, ap, ap_class, wandb_images = [], [], [], [], [] + + pbar = tqdm(dataloader) + for batch_i, (img, targets, paths, shapes) in enumerate(pbar): + img = img.to(device, non_blocking=True) + img = img.half() if half else img.float() # uint8 to fp16/32 + img /= 255.0 # 0 - 255 to 0.0 - 1.0 + targets = targets.to(device) + nb, _, height, width = img.shape # batch size, channels, height, width + whwh = torch.Tensor([width, height, width, height]) + + # Disable gradients + with torch.no_grad(): + # Run model + t = time_synchronized() + inf_out, _ = model(img, augment=augment) # inference and training outputs + t0 += time_synchronized() - t + + # Compute loss / no test during training + # if training: # if model has loss hyperparameters + # loss += compute_loss([x.float() for x in train_out], targets, model)[1][:3] # box, obj, cls + + # Run NMS + t = time_synchronized() + output = non_max_suppression(inf_out, conf_thres=conf_thres, iou_thres=iou_thres) + t1 += time_synchronized() - t + targets = targets.cpu() + + # Statistics per image + for si, pred in enumerate(output): + labels = targets[targets[:, 0] == si, 1:] + nl = len(labels) + tcls = labels[:, 0].tolist() if nl else [] # target class + seen += 1 + + if len(pred) == 0: + if nl: + stats.append((torch.zeros(0, niou, dtype=torch.bool), torch.Tensor(), torch.Tensor(), tcls)) + continue + + # Append to text file + path = Path(paths[si]) + if save_txt: + gn = torch.tensor(shapes[si][0])[[1, 0, 1, 0]] # normalization gain whwh + x = pred.clone() + x[:, :4] = scale_coords(img[si].shape[1:], x[:, :4], shapes[si][0], shapes[si][1]) # to original + for *xyxy, conf, cls in x: + xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh + line = (cls, *xywh, conf) if save_conf else (cls, *xywh) # label format + with open(save_dir / 'labels' / (path.stem + '.txt'), 'a') as f: + f.write(('%g ' * len(line)).rstrip() % line + '\n') + + # W&B logging + if plots and len(wandb_images) < log_imgs: + box_data = [{"position": {"minX": xyxy[0], "minY": xyxy[1], "maxX": xyxy[2], "maxY": xyxy[3]}, + "class_id": int(cls), + "box_caption": "%s %.3f" % (names[cls], conf), + "scores": {"class_score": conf}, + "domain": "pixel"} for *xyxy, conf, cls in pred.tolist()] + boxes = {"predictions": {"box_data": box_data, "class_labels": names}} + wandb_images.append(wandb.Image(img[si], boxes=boxes, caption=path.name)) + + # Clip boxes to image bounds + clip_coords(pred, (height, width)) + + # Append to pycocotools JSON dictionary + if save_json: + # [{"image_id": 42, "category_id": 18, "bbox": [258.15, 41.29, 348.26, 243.78], "score": 0.236}, ... + image_id = int(path.stem) if path.stem.isnumeric() else path.stem + box = pred[:, :4].clone() # xyxy + scale_coords(img[si].shape[1:], box, shapes[si][0], shapes[si][1]) # to original shape + box = xyxy2xywh(box) # xywh + box[:, :2] -= box[:, 2:] / 2 # xy center to top-left corner + for p, b in zip(pred.tolist(), box.tolist()): + jdict.append({'image_id': image_id, + 'category_id': coco91class[int(p[5])] if is_coco else int(p[5]), + 'bbox': [round(x, 3) for x in b], + 'score': round(p[4], 5)}) + + # Assign all predictions as incorrect + correct = torch.zeros(pred.shape[0], niou, dtype=torch.bool) + if nl: + detected = [] # target indices + tcls_tensor = labels[:, 0] + + # target boxes + tbox = xywh2xyxy(labels[:, 1:5]) * whwh + + # Per target class + for cls in torch.unique(tcls_tensor): + ti = (cls == tcls_tensor).nonzero(as_tuple=False).view(-1) # prediction indices + pi = (cls == pred[:, 5]).nonzero(as_tuple=False).view(-1) # target indices + + # Search for detections + if pi.shape[0]: + # Prediction to target ious + ious, i = box_iou(pred[pi, :4], tbox[ti]).max(1) # best ious, indices + + # Append detections + temp_nonzero_idx = (ious > iouv[0]).nonzero(as_tuple=False) + for j in temp_nonzero_idx: + d = ti[i[j]] # detected target + if d not in detected: + detected.append(d) + correct[pi[j]] = ious[j] > iouv # iou_thres is 1xn + if len(detected) == nl: # all targets already located in image + break + + # Append statistics (correct, conf, pcls, tcls) + stats.append((correct.cpu(), pred[:, 4].cpu(), pred[:, 5].cpu(), tcls)) + + # Plot images + if plots and batch_i < 3: + f = save_dir / f'{batch_i}_labels.jpg' # filename + plot_images(img, targets, paths, f, names) # labels + f = save_dir / f'{batch_i}_pred.jpg' + plot_images(img, output_to_target(output, width, height), paths, f, names) # predictions + + # Compute statistics + stats = [np.concatenate(x, 0) for x in zip(*stats)] # to numpy + if len(stats) and stats[0].any(): + p, r, ap, f1, ap_class = ap_per_class(*stats, plot=plots, fname=save_dir / 'precision-recall_curve.png') + p, r, ap50, ap = p[:, 0], r[:, 0], ap[:, 0], ap.mean(1) # [P, R, AP@0.5, AP@0.5:0.95] + mp, mr, map50, map = p.mean(), r.mean(), ap50.mean(), ap.mean() + nt = np.bincount(stats[3].astype(np.int64), minlength=nc) # number of targets per class + else: + nt = torch.zeros(1) + + # W&B logging + if plots and wandb: + wandb.log({"Images": wandb_images}) + wandb.log({"Validation": [wandb.Image(str(x), caption=x.name) for x in sorted(save_dir.glob('test*.jpg'))]}) + + # Print results + pf = '%20s' + '%12.3g' * 6 # print format + print(pf % ('all', seen, nt.sum(), mp, mr, map50, map)) + + # Print results per class + if verbose and nc > 1 and len(stats): + for i, c in enumerate(ap_class): + print(pf % (names[c], seen, nt[c], p[i], r[i], ap50[i], ap[i])) + + # Print speeds + t = tuple(x / seen * 1E3 for x in (t0, t1, t0 + t1)) + (imgsz, imgsz, batch_size) # tuple + if not training: + print('Speed: %.1f/%.1f/%.1f ms inference/NMS/total per %gx%g image at batch-size %g' % t) + + # Save JSON + if save_json and len(jdict): + w = Path(weights[0] if isinstance(weights, list) else weights).stem if weights is not None else '' # weights + anno_json = glob.glob('../data/coco/annotations/instances_val*.json')[0] # annotations json + pred_json = str(save_dir / f"{w}_predictions.json") # predictions json + print('\nEvaluating pycocotools mAP... saving %s...' % pred_json) + with open(pred_json, 'w') as f: + json.dump(jdict, f) + + try: # https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocoEvalDemo.ipynb + from pycocotools.coco import COCO + from pycocotools.cocoeval import COCOeval + + anno = COCO(anno_json) # init annotations api + pred = anno.loadRes(pred_json) # init predictions api + eval = COCOeval(anno, pred, 'bbox') + if is_coco: + eval.params.imgIds = [int(Path(x).stem) for x in dataloader.dataset.img_files] # image IDs to evaluate + eval.evaluate() + eval.accumulate() + eval.summarize() + map, map50 = eval.stats[:2] # update results (mAP@0.5:0.95, mAP@0.5) + except Exception as e: + print('ERROR: pycocotools unable to run: %s' % e) + + # Return results + if not training: + print('Results saved to %s' % save_dir) + model.float() # for training + maps = np.zeros(nc) + map + for i, c in enumerate(ap_class): + maps[c] = ap[i] + return (mp, mr, map50, map, *(loss.cpu() / len(dataloader)).tolist()), maps, t + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(prog='test.py') + parser.add_argument('--weights', nargs='+', type=str, default='yolor_p6.pt', help='model.pt path(s)') + parser.add_argument('--data', type=str, default='data/coco.yaml', help='*.data path') + parser.add_argument('--batch-size', type=int, default=32, help='size of each image batch') + parser.add_argument('--img-size', type=int, default=1280, help='inference size (pixels)') + parser.add_argument('--conf-thres', type=float, default=0.001, help='object confidence threshold') + parser.add_argument('--iou-thres', type=float, default=0.65, help='IOU threshold for NMS') + parser.add_argument('--task', default='val', help="'val', 'test', 'study'") + parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') + parser.add_argument('--single-cls', action='store_true', help='treat as single-class dataset') + parser.add_argument('--augment', action='store_true', help='augmented inference') + parser.add_argument('--verbose', action='store_true', help='report mAP by class') + parser.add_argument('--save-txt', action='store_true', help='save results to *.txt') + parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels') + parser.add_argument('--save-json', action='store_true', help='save a cocoapi-compatible JSON results file') + parser.add_argument('--project', default='runs/test', help='save to project/name') + parser.add_argument('--name', default='exp', help='save to project/name') + parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') + parser.add_argument('--cfg', type=str, default='cfg/yolor_p6.cfg', help='*.cfg path') + parser.add_argument('--names', type=str, default='data/coco.names', help='*.cfg path') + parser.add_argument('--npu', default=None, type=int, help='NPU id to use.') + opt = parser.parse_args() + opt.save_json |= opt.data.endswith('coco.yaml') + opt.data = check_file(opt.data) # check file + print(opt) + + if opt.task in ['val', 'test']: # run normally + test(opt.data, + opt.weights, + opt.batch_size, + opt.img_size, + opt.conf_thres, + opt.iou_thres, + opt.save_json, + opt.single_cls, + opt.augment, + opt.verbose, + save_txt=opt.save_txt, + save_conf=opt.save_conf, + ) + + elif opt.task == 'study': # run over a range of settings and save/plot + for weights in ['yolor_p6.pt', 'yolor_w6.pt']: + f = 'study_%s_%s.txt' % (Path(opt.data).stem, Path(weights).stem) # filename to save to + x = list(range(320, 800, 64)) # x axis + y = [] # y axis + for i in x: # img-size + print('\nRunning %s point %s...' % (f, i)) + r, _, t = test(opt.data, weights, opt.batch_size, i, opt.conf_thres, opt.iou_thres, opt.save_json) + y.append(r + t) # results and times + np.savetxt(f, y, fmt='%10.4g') # save + os.system('zip -r study.zip study_*.txt') + # utils.general.plot_study_txt(f, x) # plot diff --git a/PyTorch/contrib/cv/detection/YOLOR/train.py b/PyTorch/contrib/cv/detection/YOLOR/train.py index 8f59aeea094002d9fafddd53f52bedc4daf32276..75329751e2daa8cae9c54af80b3fdfe5d7b7ebf4 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/train.py +++ b/PyTorch/contrib/cv/detection/YOLOR/train.py @@ -1,739 +1,739 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import logging -import math -import os -import random -import time -from pathlib import Path -from warnings import warn - -import numpy as np -import torch.distributed as dist -import torch.nn.functional as F -import torch.optim as optim -import torch.optim.lr_scheduler as lr_scheduler -import torch.utils.data -import yaml -from torch.nn.parallel import DistributedDataParallel as DDP -from torch.utils.tensorboard import SummaryWriter -import torch.multiprocessing as mp - -import test # import test.py to get mAP after each epoch -#from models.yolo import Model -from models.models import * -from utils.autoanchor import check_anchors -from utils.datasets import create_dataloader -from utils.general import labels_to_class_weights, increment_path, labels_to_image_weights, init_seeds, \ - fitness, fitness_p, fitness_r, fitness_ap50, fitness_ap, fitness_f, strip_optimizer, get_latest_run,\ - check_dataset, check_file, check_git_status, check_img_size, print_mutation, set_logging -from utils.google_utils import attempt_download -from utils.loss import compute_loss -from utils.plots import plot_images, plot_labels, plot_results, plot_evolution, output_to_target -from utils.torch_utils import ModelEMA, select_device, intersect_dicts, torch_distributed_zero_first - -logger = logging.getLogger(__name__) - -mixed_precision = True -try: - import apex - from apex import amp -except: - print('Apex recommended for faster mixed precision training: https://github.com/NVIDIA/apex') - mixed_precision = False # not installed - -use_wandb = False -if use_wandb: - try: - import wandb - except: - print("Install Weights & Biases for experiment logging via 'pip install wandb' (recommended)") -else: - wandb = None - - -def train(hyp, opt, device, tb_writer=None, wandb=None): - print(f'Hyperparameters {hyp}') - save_dir, epochs, batch_size, total_batch_size, weights, rank = \ - Path(opt.save_dir), opt.epochs, opt.batch_size, opt.total_batch_size, opt.weights, opt.local_rank - - # Directories - wdir = save_dir / 'weights' - wdir.mkdir(parents=True, exist_ok=True) # make dir - last = wdir / 'last.pt' - best = wdir / 'best.pt' - results_file = save_dir / 'results.txt' - - # Save run settings - with open(save_dir / 'hyp.yaml', 'w') as f: - yaml.dump(hyp, f, sort_keys=False) - with open(save_dir / 'opt.yaml', 'w') as f: - yaml.dump(vars(opt), f, sort_keys=False) - - # Configure - plots = not opt.evolve # create plots - cuda = device.type != 'cpu' - init_seeds(2 + rank) - with open(opt.data) as f: - data_dict = yaml.load(f, Loader=yaml.FullLoader) # data dict - with torch_distributed_zero_first(rank): - check_dataset(data_dict) # check - train_path = data_dict['train'] - test_path = data_dict['val'] - nc, names = (1, ['item']) if opt.single_cls else (int(data_dict['nc']), data_dict['names']) # number classes, names - assert len(names) == nc, '%g names found for nc=%g dataset in %s' % (len(names), nc, opt.data) # check - - # Model - pretrained = weights.endswith('.pt') - if pretrained: - with torch_distributed_zero_first(rank): - attempt_download(weights) # download if not found locally - ckpt = torch.load(weights, map_location=device) # load checkpoint - model = Darknet(opt.cfg).to(device) # create - state_dict = {k: v for k, v in ckpt['model'].items() if model.state_dict()[k].numel() == v.numel()} - model.load_state_dict(state_dict, strict=False) - print('Transferred %g/%g items from %s' % (len(state_dict), len(model.state_dict()), weights)) # report - else: - model = Darknet(opt.cfg).to(device) # create - - # Image sizes - gs = 64 #int(max(model.stride)) # grid size (max stride) - imgsz, imgsz_test = [check_img_size(x, gs) for x in opt.img_size] # verify imgsz are gs-multiples - - # Optimizer - nbs = 64 # nominal batch size - accumulate = max(round(nbs / total_batch_size), 1) # accumulate loss before optimizing - hyp['weight_decay'] *= total_batch_size * accumulate / nbs # scale weight_decay - - pg0, pg1, pg2 = [], [], [] # optimizer parameter groups - for k, v in dict(model.named_parameters()).items(): - if '.bias' in k: - pg2.append(v) # biases - elif 'Conv2d.weight' in k: - pg1.append(v) # apply weight_decay - elif 'm.weight' in k: - pg1.append(v) # apply weight_decay - elif 'w.weight' in k: - pg1.append(v) # apply weight_decay - else: - pg0.append(v) # all else - - if opt.adam: - optimizer = optim.Adam(pg0, lr=hyp['lr0'], betas=(hyp['momentum'], 0.999)) # adjust beta1 to momentum - else: - if device.type == 'npu': - optimizer = apex.optimizers.NpuFusedSGD(pg0, lr=hyp['lr0'], momentum=hyp['momentum'], nesterov=True) - else: - optimizer = optim.SGD(pg0, lr=hyp['lr0'], momentum=hyp['momentum'], nesterov=True) - - optimizer.add_param_group({'params': pg1, 'weight_decay': hyp['weight_decay']}) # add pg1 with weight_decay - optimizer.add_param_group({'params': pg2}) # add pg2 (biases) - print('Optimizer groups: %g .bias, %g conv.weight, %g other' % (len(pg2), len(pg1), len(pg0))) - del pg0, pg1, pg2 - - # Logging - if wandb and wandb.run is None: - opt.hyp = hyp # add hyperparameters - wandb_run = wandb.init(config=opt, resume="allow", - project='YOLOR' if opt.project == 'runs/train' else Path(opt.project).stem, - name=save_dir.stem, - id=ckpt.get('wandb_id') if 'ckpt' in locals() else None) - - # Resume - start_epoch = 0 - # best_fitness, best_fitness_p, best_fitness_r, best_fitness_ap50, best_fitness_ap, best_fitness_f = 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 - if pretrained: - # Optimizer - if ckpt['optimizer'] is not None: - optimizer.load_state_dict(ckpt['optimizer']) - # best_fitness = ckpt['best_fitness'] - # best_fitness_p = ckpt['best_fitness_p'] - # best_fitness_r = ckpt['best_fitness_r'] - # best_fitness_ap50 = ckpt['best_fitness_ap50'] - # best_fitness_ap = ckpt['best_fitness_ap'] - # best_fitness_f = ckpt['best_fitness_f'] - - # Results - if ckpt.get('training_results') is not None: - with open(results_file, 'w') as file: - file.write(ckpt['training_results']) # write results.txt - - # Epochs - start_epoch = ckpt['epoch'] + 1 - if opt.resume: - assert start_epoch > 0, '%s training to %g epochs is finished, nothing to resume.' % (weights, epochs) - if epochs < start_epoch: - print('%s has been trained for %g epochs. Fine-tuning for %g additional epochs.' % - (weights, ckpt['epoch'], epochs)) - epochs += ckpt['epoch'] # finetune additional epochs - - del ckpt, state_dict - - # Mixed precision training https://github.com/NVIDIA/apex - if mixed_precision: - if device.type == 'npu': - model, optimizer = amp.initialize(model, optimizer, opt_level='O1', verbosity=0, loss_scale=64, combine_grad=True) - else: - model, optimizer = amp.initialize(model, optimizer, opt_level='O1', verbosity=0, loss_scale=64) - - # Scheduler https://arxiv.org/pdf/1812.01187.pdf - # https://pytorch.org/docs/stable/_modules/torch/optim/lr_scheduler.html#OneCycleLR - lf = lambda x: ((1 + math.cos(x * math.pi / epochs)) / 2) * (1 - hyp['lrf']) + hyp['lrf'] # cosine - scheduler = lr_scheduler.LambdaLR(optimizer, lr_lambda=lf) - # plot_lr_scheduler(optimizer, scheduler, epochs) - - - # SyncBatchNorm - if opt.sync_bn and cuda and rank != -1: - model = torch.nn.SyncBatchNorm.convert_sync_batchnorm(model).to(device) - print('Using SyncBatchNorm()') - - # EMA - ema = ModelEMA(model) if rank in [-1, 0] else None - - # DDP mode - if device.type == 'cuda' and rank != -1: - model = DDP(model, device_ids=[rank], output_device=rank) - elif device.type == 'npu' and rank != -1: - model = DDP(model, device_ids=[rank], broadcast_buffers=False) - - # Trainloader - dataloader, dataset = create_dataloader(train_path, imgsz, batch_size, gs, opt, - hyp=hyp, augment=True, cache=opt.cache_images, rect=opt.rect, - rank=rank, world_size=opt.world_size, workers=opt.workers) - mlc = np.concatenate(dataset.labels, 0)[:, 0].max() # max label class - nb = len(dataloader) # number of batches - assert mlc < nc, 'Label class %g exceeds nc=%g in %s. Possible class labels are 0-%g' % (mlc, nc, opt.data, nc - 1) - - # Model parameters - hyp['cls'] *= nc / 80. # scale coco-tuned hyp['cls'] to current dataset - model.nc = nc # attach number of classes to model - model.hyp = hyp # attach hyperparameters to model - model.gr = 1.0 # iou loss ratio (obj_loss = 1.0 or iou) - model.class_weights = labels_to_class_weights(dataset.labels, nc).to(device) # attach class weights - model.names = names - - # Process 0 - if rank in [-1, 0]: - ema.updates = start_epoch * nb // accumulate # set EMA updates - testloader = create_dataloader(test_path, imgsz_test, batch_size*2, gs, opt, - hyp=hyp, cache=opt.cache_images and not opt.notest, rect=True, - rank=-1, world_size=opt.world_size, workers=opt.workers)[0] # testloader - - if not opt.resume: - labels = np.concatenate(dataset.labels, 0) - c = torch.tensor(labels[:, 0]) # classes - # cf = torch.bincount(c.long(), minlength=nc) + 1. # frequency - # model._initialize_biases(cf.to(device)) - if plots: - plot_labels(labels, save_dir=save_dir) - if tb_writer: - tb_writer.add_histogram('classes', c, 0) - if wandb: - wandb.log({"Labels": [wandb.Image(str(x), caption=x.name) for x in save_dir.glob('*labels*.png')]}) - - # Anchors - # if not opt.noautoanchor: - # check_anchors(dataset, model=model, thr=hyp['anchor_t'], imgsz=imgsz) - - - # Start training - t0 = time.time() - nw = max(round(hyp['warmup_epochs'] * nb), 1000) # number of warmup iterations, max(3 epochs, 1k iterations) - # nw = min(nw, (epochs - start_epoch) / 2 * nb) # limit warmup to < 1/2 of training - maps = np.zeros(nc) # mAP per class - results = (0, 0, 0, 0, 0, 0, 0) # P, R, mAP@.5, mAP@.5-.95, val_loss(box, obj, cls) - scheduler.last_epoch = start_epoch - 1 # do not move - if rank in [0, -1]: - print('Image sizes %g train, %g test\n' - 'Using %g dataloader workers\nLogging results to %s\n' - 'Starting training for %g epochs...' % (imgsz, imgsz_test, dataloader.num_workers, save_dir, epochs)) - - for epoch in range(start_epoch, epochs): # epoch ------------------------------------------------------------------ - model.train() - - # Update image weights (optional) - # When in DDP mode, the generated indices will be broadcasted to synchronize dataset. - if opt.image_weights: - # Generate indices - if rank in [-1, 0]: - cw = model.class_weights.cpu().numpy() * (1 - maps) ** 2 # class weights - iw = labels_to_image_weights(dataset.labels, nc=nc, class_weights=cw) # image weights - dataset.indices = random.choices(range(dataset.n), weights=iw, k=dataset.n) # rand weighted idx - # Broadcast if DDP - if rank != -1: - indices = (torch.tensor(dataset.indices) if rank == 0 else torch.zeros(dataset.n)).int() - dist.broadcast(indices, 0) - if rank != 0: - dataset.indices = indices.cpu().numpy() - - # Update mosaic border - # b = int(random.uniform(0.25 * imgsz, 0.75 * imgsz + gs) // gs * gs) - # dataset.mosaic_border = [b - imgsz, -b] # height, width borders - - mloss = torch.zeros(4, device=device) # mean losses - if rank != -1: - dataloader.sampler.set_epoch(epoch) - optimizer.zero_grad() - start_time = time.time() - d_1 = time.time() - - for i, (imgs, targets, paths, _) in enumerate(dataloader): # batch ------------------------------------------------------------- - t_time = time.time() - d_time = t_time - d_1 - ni = i + nb * epoch # number integrated batches (since train start) - imgs = imgs.to(device, non_blocking=True).float() / 255.0 # uint8 to float32, 0-255 to 0.0-1.0 - - # Warmup - if ni <= nw: - xi = [0, nw] # x interp - # model.gr = np.interp(ni, xi, [0.0, 1.0]) # iou loss ratio (obj_loss = 1.0 or iou) - accumulate = max(1, np.interp(ni, xi, [1, nbs / total_batch_size]).round()) - for j, x in enumerate(optimizer.param_groups): - # bias lr falls from 0.1 to lr0, all other lrs rise from 0.0 to lr0 - x['lr'] = np.interp(ni, xi, [hyp['warmup_bias_lr'] if j == 2 else 0.0, x['initial_lr'] * lf(epoch)]) - if 'momentum' in x: - x['momentum'] = np.interp(ni, xi, [hyp['warmup_momentum'], hyp['momentum']]) - - # Multi-scale - if opt.multi_scale: - sz = random.randrange(imgsz * 0.5, imgsz * 1.5 + gs) // gs * gs # size - sf = sz / max(imgs.shape[2:]) # scale factor - if sf != 1: - ns = [math.ceil(x * sf / gs) * gs for x in imgs.shape[2:]] # new shape (stretched to gs-multiple) - imgs = F.interpolate(imgs, size=ns, mode='bilinear', align_corners=False) - - # Forward - pred = model(imgs) - - # Loss - loss, loss_items = compute_loss(pred, targets.to(device), model) # scaled by batch_size - if rank != -1: - loss *= opt.world_size # gradient averaged between devices in DDP mode - if not torch.isfinite(loss): - print('WARNING: non-finite loss, ending training ', loss_items) - return results - - # Backward - if mixed_precision: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - - # Optimize - if ni % accumulate == 0: - optimizer.step() - optimizer.zero_grad() - if ema is not None: - x = torch.tensor([1.]).to(device) - if device.type == 'npu': - params_fp32_fused = optimizer.get_model_combined_params() - ema.update(model, x, params_fp32_fused[0]) - else: - ema.update(model, x) - - if i <= 10: - sum_time = (time.time() - start_time) / (i + 1) - if i == 10: - start_time = time.time() - else: - sum_time = (time.time() - start_time) / (i - 10) - ptime = time.time() - d_1 - # Print - if rank in [-1, 0]: - mloss = (mloss * i + loss_items) / (i + 1) # update mean losses - mem = '%.3gG' % (torch.cuda.memory_cached() / 1E9 if torch.cuda.is_available() else 0) # (GB) - s = ('%10s' * 2 + '%10.4g' * 6) % ( - '%g/%g' % (epoch, epochs - 1), mem, *mloss, targets.shape[0], imgs.shape[-1]) - print( - 'Epoch:[%2g][%4g/%4g][%s][FPS:%3.1f][mTime:%3.3f][pTime:%3.3f][dTime:%3.3f] GIoU:%.3f objectness:%.3f classfication:%.3f totalLoss:%.3f' % ( - epoch, i, nb, device, opt.total_batch_size / sum_time, sum_time, ptime, d_time, *mloss)) - - # Plot - if plots and ni < 3: - f = save_dir / f'train_batch{ni}.jpg' # filename - plot_images(images=imgs, targets=targets, paths=paths, fname=f) - # if tb_writer: - # tb_writer.add_image(f, result, dataformats='HWC', global_step=epoch) - # tb_writer.add_graph(model, imgs) # add model to tensorboard - elif plots and ni == 3 and wandb: - wandb.log({"Mosaics": [wandb.Image(str(x), caption=x.name) for x in save_dir.glob('train*.jpg')]}) - if i > 170: - break - d_1 = time.time() - # end batch ------------------------------------------------------------------------------------------------ - # end epoch ---------------------------------------------------------------------------------------------------- - - # Scheduler - lr = [x['lr'] for x in optimizer.param_groups] # for tensorboard - scheduler.step() - - # DDP process 0 or single-GPU - if rank in [-1, 0]: - # mAP - if ema: - ema.update_attr(model) - final_epoch = epoch + 1 == epochs - if False: # No test during training - results, maps, _ = test.test(opt.data, - batch_size=batch_size*2, - imgsz=imgsz_test, - model=ema.ema.module if hasattr(ema.ema, 'module') else ema.ema, - single_cls=opt.single_cls, - dataloader=testloader, - save_dir=save_dir, - plots=True) - - # Write - with open(results_file, 'a') as f: - f.write(s + '%10.4g' * 7 % results + '\n') # P, R, mAP@.5, mAP@.5-.95, val_loss(box, obj, cls) - if len(opt.name) and opt.bucket: - os.system('gsutil cp %s gs://%s/results/results%s.txt' % (results_file, opt.bucket, opt.name)) - - # Log - tags = ['train/box_loss', 'train/obj_loss', 'train/cls_loss', # train loss - 'metrics/precision', 'metrics/recall', 'metrics/mAP_0.5', 'metrics/mAP_0.5:0.95', - 'val/box_loss', 'val/obj_loss', 'val/cls_loss', # val loss - 'x/lr0', 'x/lr1', 'x/lr2'] # params - for x, tag in zip(list(mloss[:-1]) + list(results) + lr, tags): - if tb_writer: - tb_writer.add_scalar(tag, x, epoch) # tensorboard - if wandb: - wandb.log({tag: x}) # W&B - - # # Update best mAP - # fi = fitness(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] - # fi_p = fitness_p(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] - # fi_r = fitness_r(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] - # fi_ap50 = fitness_ap50(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] - # fi_ap = fitness_ap(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] - # if (fi_p > 0.0) or (fi_r > 0.0): - # fi_f = fitness_f(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] - # else: - # fi_f = 0.0 - # if fi > best_fitness: - # best_fitness = fi - # if fi_p > best_fitness_p: - # best_fitness_p = fi_p - # if fi_r > best_fitness_r: - # best_fitness_r = fi_r - # if fi_ap50 > best_fitness_ap50: - # best_fitness_ap50 = fi_ap50 - # if fi_ap > best_fitness_ap: - # best_fitness_ap = fi_ap - # if fi_f > best_fitness_f: - # best_fitness_f = fi_f - - # Save model - save = (not opt.nosave) or (final_epoch and not opt.evolve) - if save: - with open(results_file, 'r') as f: # create checkpoint - ckpt = {'epoch': epoch, - # 'best_fitness': best_fitness, - # 'best_fitness_p': best_fitness_p, - # 'best_fitness_r': best_fitness_r, - # 'best_fitness_ap50': best_fitness_ap50, - # 'best_fitness_ap': best_fitness_ap, - # 'best_fitness_f': best_fitness_f, - 'training_results': f.read(), - 'model': ema.ema.module.state_dict() if hasattr(ema, 'module') else ema.ema.state_dict(), - 'optimizer': None if final_epoch else optimizer.state_dict(), - 'wandb_id': wandb_run.id if wandb else None} - - # Save last, best and delete - torch.save(ckpt, last) - # if best_fitness == fi: - # torch.save(ckpt, best) - # if (best_fitness == fi) and (epoch >= 200): - # torch.save(ckpt, wdir / 'best_{:03d}.pt'.format(epoch)) - # if best_fitness == fi: - # torch.save(ckpt, wdir / 'best_overall.pt') - # if best_fitness_p == fi_p: - # torch.save(ckpt, wdir / 'best_p.pt') - # if best_fitness_r == fi_r: - # torch.save(ckpt, wdir / 'best_r.pt') - # if best_fitness_ap50 == fi_ap50: - # torch.save(ckpt, wdir / 'best_ap50.pt') - # if best_fitness_ap == fi_ap: - # torch.save(ckpt, wdir / 'best_ap.pt') - # if best_fitness_f == fi_f: - # torch.save(ckpt, wdir / 'best_f.pt') - if epoch == 0: - torch.save(ckpt, wdir / 'epoch_{:03d}.pt'.format(epoch)) - if ((epoch+1) % 25) == 0: - torch.save(ckpt, wdir / 'epoch_{:03d}.pt'.format(epoch)) - if epoch >= (epochs-5): - torch.save(ckpt, wdir / 'last_{:03d}.pt'.format(epoch)) - elif epoch >= 420: - torch.save(ckpt, wdir / 'last_{:03d}.pt'.format(epoch)) - del ckpt - # end epoch ---------------------------------------------------------------------------------------------------- - # end training - - if rank in [-1, 0]: - # Strip optimizers - n = opt.name if opt.name.isnumeric() else '' - fresults, flast, fbest = save_dir / f'results{n}.txt', wdir / f'last{n}.pt', wdir / f'best{n}.pt' - for f1, f2 in zip([wdir / 'last.pt', wdir / 'best.pt', results_file], [flast, fbest, fresults]): - if f1.exists(): - os.rename(f1, f2) # rename - if str(f2).endswith('.pt'): # is *.pt - strip_optimizer(f2) # strip optimizer - os.system('gsutil cp %s gs://%s/weights' % (f2, opt.bucket)) if opt.bucket else None # upload - # Finish - if plots: - plot_results(save_dir=save_dir) # save as results.png - if wandb: - wandb.log({"Results": [wandb.Image(str(save_dir / x), caption=x) for x in - ['results.png', 'precision-recall_curve.png']]}) - print('%g epochs completed in %.3f hours.\n' % (epoch - start_epoch + 1, (time.time() - t0) / 3600)) - - else: - dist.destroy_process_group() - - wandb.run.finish() if wandb and wandb.run else None - torch.cuda.empty_cache() - - return results - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('--weights', type=str, default='yolor_p6.pt', help='initial weights path') - parser.add_argument('--cfg', type=str, default='', help='model.yaml path') - parser.add_argument('--data', type=str, default='data/coco.yaml', help='data.yaml path') - parser.add_argument('--hyp', type=str, default='data/hyp.scratch.1280.yaml', help='hyperparameters path') - parser.add_argument('--epochs', type=int, default=300) - parser.add_argument('--batch-size', type=int, default=8, help='total batch size for all GPUs') - parser.add_argument('--img-size', nargs='+', type=int, default=[1280, 1280], help='[train, test] image sizes') - parser.add_argument('--rect', action='store_true', help='rectangular training') - parser.add_argument('--resume', nargs='?', const=True, default=False, help='resume most recent training') - parser.add_argument('--nosave', action='store_true', help='only save final checkpoint') - parser.add_argument('--notest', action='store_true', help='only test final epoch') - parser.add_argument('--noautoanchor', action='store_true', help='disable autoanchor check') - parser.add_argument('--evolve', action='store_true', help='evolve hyperparameters') - parser.add_argument('--bucket', type=str, default='', help='gsutil bucket') - parser.add_argument('--cache-images', action='store_true', help='cache images for faster training') - parser.add_argument('--image-weights', action='store_true', help='use weighted image selection for training') - parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu or npu') - parser.add_argument('--multi-scale', action='store_true', help='vary img-size +/- 50%%') - parser.add_argument('--single-cls', action='store_true', help='train as single-class dataset') - parser.add_argument('--adam', action='store_true', help='use torch.optim.Adam() optimizer') - parser.add_argument('--sync-bn', action='store_true', help='use SyncBatchNorm, only available in DDP mode') - parser.add_argument('--full', action='store_true', help='full mode') - parser.add_argument('--local_rank', type=int, default=-1, help='DDP parameter, do not modify') - parser.add_argument('--log-imgs', type=int, default=16, help='number of images for W&B logging, max 100') - parser.add_argument('--workers', type=int, default=8, help='maximum number of dataloader workers') - parser.add_argument('--project', default='runs/train', help='save to project/name') - parser.add_argument('--name', default='exp', help='save to project/name') - parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') - parser.add_argument('--npu', default=-1, type=int, help='NPU id to use.') - - # NPU DDP mode - parser.add_argument('--world-size', default=1, type=int, help='number of nodes for distributed training') - parser.add_argument('--device-num', default=1, type=int, help='multi NPU parameter, GPU or CPU do not modify') - parser.add_argument('--addr', default='127.0.0.1', type=str, help='DDP master node IP') - parser.add_argument('--dist-url', default='tcp://127.0.0.1:29501', type=str, - help='url used to set up distributed training') - opt = parser.parse_args() - - if opt.dist_url == "env://": - opt.world_size = int(os.environ["WORLD_SIZE"]) - ngpus_per_node = opt.device_num - opt.npu_ddp = (opt.device_num > 1 or opt.world_size > 1) - if opt.npu_ddp: - print('multi npu training') - os.environ['MASTER_ADDR'] = opt.addr # master ip - os.environ['MASTER_PORT'] = '29501' - os.environ['KERNEL_NAME_ID'] = str(0) - opt.world_size = ngpus_per_node * opt.world_size # the sum of GPU or NPU in all the nodes - mp.spawn(main_worker, nprocs=ngpus_per_node, args=(ngpus_per_node, opt)) - else: - print('1p training') - main_worker(opt.npu, ngpus_per_node, opt) - - # # Set DDP variables - # opt.total_batch_size = opt.batch_size - # opt.world_size = int(os.environ['WORLD_SIZE']) if 'WORLD_SIZE' in os.environ else 1 - # opt.global_rank = int(os.environ['RANK']) if 'RANK' in os.environ else -1 - # set_logging(opt.global_rank) - # if opt.global_rank in [-1, 0]: - # check_git_status() - - # # DDP mode - # device = select_device(opt.device, batch_size=opt.batch_size) - # if opt.local_rank != -1: - # assert torch.cuda.device_count() > opt.local_rank - # torch.cuda.set_device(opt.local_rank) - # device = torch.device('cuda', opt.local_rank) - # dist.init_process_group(backend='nccl', init_method='env://') # distributed backend - # assert opt.batch_size % opt.world_size == 0, '--batch-size must be multiple of CUDA device count' - # opt.batch_size = opt.total_batch_size // opt.world_size - - -def main_worker(npu, ngpus_per_node, opt): - # Resume - if opt.resume: # resume an interrupted run - ckpt = opt.resume if isinstance(opt.resume, str) else get_latest_run() # specified or most recent path - assert os.path.isfile(ckpt), 'ERROR: --resume checkpoint does not exist' - with open(Path(ckpt).parent.parent / 'opt.yaml') as f: - opt = argparse.Namespace(**yaml.load(f, Loader=yaml.FullLoader)) # replace - opt.cfg, opt.weights, opt.resume = '', ckpt, True - print('Resuming training from %s' % ckpt) - else: - # opt.hyp = opt.hyp or ('hyp.finetune.yaml' if opt.weights else 'hyp.scratch.yaml') - opt.data, opt.cfg, opt.hyp = check_file(opt.data), check_file(opt.cfg), check_file(opt.hyp) # check files - assert len(opt.cfg) or len(opt.weights), 'either --cfg or --weights must be specified' - opt.img_size.extend([opt.img_size[-1]] * (2 - len(opt.img_size))) # extend to 2 sizes (train, test) - opt.name = 'evolve' if opt.evolve else opt.name - opt.save_dir = increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok | opt.evolve) # increment run - - # Hyperparameters - with open(opt.hyp) as f: - hyp = yaml.load(f, Loader=yaml.FullLoader) # load hyps - if 'box' not in hyp: - warn('Compatibility: %s missing "box" which was renamed from "giou" in %s' % - (opt.hyp, 'https://github.com/ultralytics/yolov5/pull/1120')) - hyp['box'] = hyp.pop('giou') - - # npu DDP - if opt.npu_ddp: - opt.npu = npu - os.environ['KERNEL_NAME_ID'] = str(npu) - print("[npu id:", opt.npu, "]", "+++++++++++++++++++++++++++KERNEL_NAME_ID:", os.environ['KERNEL_NAME_ID']) - opt.local_rank = opt.local_rank * ngpus_per_node + npu - global mixed_precision - device = torch_utils.select_device(opt.device, opt.npu, apex=mixed_precision, batch_size=opt.batch_size) - opt.total_batch_size = opt.batch_size - if device.type == 'cpu': - mixed_precision = False - elif opt.local_rank != -1 and device.type == 'cuda': - # DDP mode - assert torch.cuda.device_count() > opt.local_rank - torch.cuda.set_device(opt.local_rank) - device = torch.device("cuda", opt.local_rank) - dist.init_process_group(backend='nccl', init_method='env://') # distributed backend - - opt.world_size = dist.get_world_size() - assert opt.batch_size % opt.world_size == 0, "Batch size is not a multiple of the number of devices given!" - opt.batch_size = opt.total_batch_size // opt.world_size - elif opt.local_rank != -1 and device.type == 'npu': - dist.init_process_group(backend='hccl', world_size=opt.world_size, rank=opt.local_rank) - assert opt.batch_size % opt.world_size == 0, "Batch size is not a multiple of the number of devices given!" - opt.batch_size = opt.total_batch_size // opt.world_size - - # Train - print(opt) - if not opt.evolve: - tb_writer = None # init loggers - if opt.local_rank in [-1, 0]: - print(f'Start Tensorboard with "tensorboard --logdir {opt.project}", view at http://localhost:6006/') - tb_writer = SummaryWriter(opt.save_dir) # Tensorboard - train(hyp, opt, device, tb_writer, wandb) - - # Evolve hyperparameters (optional) - else: - # Hyperparameter evolution metadata (mutation scale 0-1, lower_limit, upper_limit) - meta = {'lr0': (1, 1e-5, 1e-1), # initial learning rate (SGD=1E-2, Adam=1E-3) - 'lrf': (1, 0.01, 1.0), # final OneCycleLR learning rate (lr0 * lrf) - 'momentum': (0.3, 0.6, 0.98), # SGD momentum/Adam beta1 - 'weight_decay': (1, 0.0, 0.001), # optimizer weight decay - 'warmup_epochs': (1, 0.0, 5.0), # warmup epochs (fractions ok) - 'warmup_momentum': (1, 0.0, 0.95), # warmup initial momentum - 'warmup_bias_lr': (1, 0.0, 0.2), # warmup initial bias lr - 'box': (1, 0.02, 0.2), # box loss gain - 'cls': (1, 0.2, 4.0), # cls loss gain - 'cls_pw': (1, 0.5, 2.0), # cls BCELoss positive_weight - 'obj': (1, 0.2, 4.0), # obj loss gain (scale with pixels) - 'obj_pw': (1, 0.5, 2.0), # obj BCELoss positive_weight - 'iou_t': (0, 0.1, 0.7), # IoU training threshold - 'anchor_t': (1, 2.0, 8.0), # anchor-multiple threshold - 'anchors': (2, 2.0, 10.0), # anchors per output grid (0 to ignore) - 'fl_gamma': (0, 0.0, 2.0), # focal loss gamma (efficientDet default gamma=1.5) - 'hsv_h': (1, 0.0, 0.1), # image HSV-Hue augmentation (fraction) - 'hsv_s': (1, 0.0, 0.9), # image HSV-Saturation augmentation (fraction) - 'hsv_v': (1, 0.0, 0.9), # image HSV-Value augmentation (fraction) - 'degrees': (1, 0.0, 45.0), # image rotation (+/- deg) - 'translate': (1, 0.0, 0.9), # image translation (+/- fraction) - 'scale': (1, 0.0, 0.9), # image scale (+/- gain) - 'shear': (1, 0.0, 10.0), # image shear (+/- deg) - 'perspective': (0, 0.0, 0.001), # image perspective (+/- fraction), range 0-0.001 - 'flipud': (1, 0.0, 1.0), # image flip up-down (probability) - 'fliplr': (0, 0.0, 1.0), # image flip left-right (probability) - 'mosaic': (1, 0.0, 1.0), # image mixup (probability) - 'mixup': (1, 0.0, 1.0)} # image mixup (probability) - - assert opt.local_rank == -1, 'DDP mode not implemented for --evolve' - opt.notest, opt.nosave = True, True # only test/save final epoch - # ei = [isinstance(x, (int, float)) for x in hyp.values()] # evolvable indices - yaml_file = Path(opt.save_dir) / 'hyp_evolved.yaml' # save best result here - if opt.bucket: - os.system('gsutil cp gs://%s/evolve.txt .' % opt.bucket) # download evolve.txt if exists - - for _ in range(300): # generations to evolve - if Path('evolve.txt').exists(): # if evolve.txt exists: select best hyps and mutate - # Select parent(s) - parent = 'single' # parent selection method: 'single' or 'weighted' - x = np.loadtxt('evolve.txt', ndmin=2) - n = min(5, len(x)) # number of previous results to consider - x = x[np.argsort(-fitness(x))][:n] # top n mutations - w = fitness(x) - fitness(x).min() # weights - if parent == 'single' or len(x) == 1: - # x = x[random.randint(0, n - 1)] # random selection - x = x[random.choices(range(n), weights=w)[0]] # weighted selection - elif parent == 'weighted': - x = (x * w.reshape(n, 1)).sum(0) / w.sum() # weighted combination - - # Mutate - mp, s = 0.8, 0.2 # mutation probability, sigma - npr = np.random - npr.seed(int(time.time())) - g = np.array([x[0] for x in meta.values()]) # gains 0-1 - ng = len(meta) - v = np.ones(ng) - while all(v == 1): # mutate until a change occurs (prevent duplicates) - v = (g * (npr.random(ng) < mp) * npr.randn(ng) * npr.random() * s + 1).clip(0.3, 3.0) - for i, k in enumerate(hyp.keys()): # plt.hist(v.ravel(), 300) - hyp[k] = float(x[i + 7] * v[i]) # mutate - - # Constrain to limits - for k, v in meta.items(): - hyp[k] = max(hyp[k], v[1]) # lower limit - hyp[k] = min(hyp[k], v[2]) # upper limit - hyp[k] = round(hyp[k], 5) # significant digits - - # Train mutation - results = train(hyp.copy(), opt, device, wandb=wandb) - - # Write mutation results - print_mutation(hyp.copy(), results, yaml_file, opt.bucket) - - # Plot results - plot_evolution(yaml_file) - print(f'Hyperparameter evolution complete. Best results saved as: {yaml_file}\n' - f'Command to train a new model with these hyperparameters: $ python train.py --hyp {yaml_file}') - - -if __name__ == '__main__': - # option = {} - # option["ACL_OP_DEBUG_LEVEL"] = 3 # 算子debug功能,暂不开启 - # option["ACL_DEBUG_DIR"] = "debug_file" # 算子debug功能对应文件夹,暂不开启 - # option["ACL_OP_COMPILER_CACHE_MODE"] = "enable" # cache功能启用 - # option["ACL_OP_COMPILER_CACHE_DIR"] = "./kernel_meta" # cache所在文件夹 - # print("option:",option) - # torch.npu.set_option(option) - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import logging +import math +import os +import random +import time +from pathlib import Path +from warnings import warn + +import numpy as np +import torch.distributed as dist +import torch.nn.functional as F +import torch.optim as optim +import torch.optim.lr_scheduler as lr_scheduler +import torch.utils.data +import yaml +from torch.nn.parallel import DistributedDataParallel as DDP +from torch.utils.tensorboard import SummaryWriter +import torch.multiprocessing as mp + +import test # import test.py to get mAP after each epoch +#from models.yolo import Model +from models.models import * +from utils.autoanchor import check_anchors +from utils.datasets import create_dataloader +from utils.general import labels_to_class_weights, increment_path, labels_to_image_weights, init_seeds, \ + fitness, fitness_p, fitness_r, fitness_ap50, fitness_ap, fitness_f, strip_optimizer, get_latest_run,\ + check_dataset, check_file, check_git_status, check_img_size, print_mutation, set_logging +from utils.google_utils import attempt_download +from utils.loss import compute_loss +from utils.plots import plot_images, plot_labels, plot_results, plot_evolution, output_to_target +from utils.torch_utils import ModelEMA, select_device, intersect_dicts, torch_distributed_zero_first + +logger = logging.getLogger(__name__) + +mixed_precision = True +try: + import apex + from apex import amp +except: + print('Apex recommended for faster mixed precision training: https://github.com/NVIDIA/apex') + mixed_precision = False # not installed + +use_wandb = False +if use_wandb: + try: + import wandb + except: + print("Install Weights & Biases for experiment logging via 'pip install wandb' (recommended)") +else: + wandb = None + + +def train(hyp, opt, device, tb_writer=None, wandb=None): + print(f'Hyperparameters {hyp}') + save_dir, epochs, batch_size, total_batch_size, weights, rank = \ + Path(opt.save_dir), opt.epochs, opt.batch_size, opt.total_batch_size, opt.weights, opt.local_rank + + # Directories + wdir = save_dir / 'weights' + wdir.mkdir(parents=True, exist_ok=True) # make dir + last = wdir / 'last.pt' + best = wdir / 'best.pt' + results_file = save_dir / 'results.txt' + + # Save run settings + with open(save_dir / 'hyp.yaml', 'w') as f: + yaml.dump(hyp, f, sort_keys=False) + with open(save_dir / 'opt.yaml', 'w') as f: + yaml.dump(vars(opt), f, sort_keys=False) + + # Configure + plots = not opt.evolve # create plots + cuda = device.type != 'cpu' + init_seeds(2 + rank) + with open(opt.data) as f: + data_dict = yaml.load(f, Loader=yaml.FullLoader) # data dict + with torch_distributed_zero_first(rank): + check_dataset(data_dict) # check + train_path = data_dict['train'] + test_path = data_dict['val'] + nc, names = (1, ['item']) if opt.single_cls else (int(data_dict['nc']), data_dict['names']) # number classes, names + assert len(names) == nc, '%g names found for nc=%g dataset in %s' % (len(names), nc, opt.data) # check + + # Model + pretrained = weights.endswith('.pt') + if pretrained: + with torch_distributed_zero_first(rank): + attempt_download(weights) # download if not found locally + ckpt = torch.load(weights, map_location=device) # load checkpoint + model = Darknet(opt.cfg).to(device) # create + state_dict = {k: v for k, v in ckpt['model'].items() if model.state_dict()[k].numel() == v.numel()} + model.load_state_dict(state_dict, strict=False) + print('Transferred %g/%g items from %s' % (len(state_dict), len(model.state_dict()), weights)) # report + else: + model = Darknet(opt.cfg).to(device) # create + + # Image sizes + gs = 64 #int(max(model.stride)) # grid size (max stride) + imgsz, imgsz_test = [check_img_size(x, gs) for x in opt.img_size] # verify imgsz are gs-multiples + + # Optimizer + nbs = 64 # nominal batch size + accumulate = max(round(nbs / total_batch_size), 1) # accumulate loss before optimizing + hyp['weight_decay'] *= total_batch_size * accumulate / nbs # scale weight_decay + + pg0, pg1, pg2 = [], [], [] # optimizer parameter groups + for k, v in dict(model.named_parameters()).items(): + if '.bias' in k: + pg2.append(v) # biases + elif 'Conv2d.weight' in k: + pg1.append(v) # apply weight_decay + elif 'm.weight' in k: + pg1.append(v) # apply weight_decay + elif 'w.weight' in k: + pg1.append(v) # apply weight_decay + else: + pg0.append(v) # all else + + if opt.adam: + optimizer = optim.Adam(pg0, lr=hyp['lr0'], betas=(hyp['momentum'], 0.999)) # adjust beta1 to momentum + else: + if device.type == 'npu': + optimizer = apex.optimizers.NpuFusedSGD(pg0, lr=hyp['lr0'], momentum=hyp['momentum'], nesterov=True) + else: + optimizer = optim.SGD(pg0, lr=hyp['lr0'], momentum=hyp['momentum'], nesterov=True) + + optimizer.add_param_group({'params': pg1, 'weight_decay': hyp['weight_decay']}) # add pg1 with weight_decay + optimizer.add_param_group({'params': pg2}) # add pg2 (biases) + print('Optimizer groups: %g .bias, %g conv.weight, %g other' % (len(pg2), len(pg1), len(pg0))) + del pg0, pg1, pg2 + + # Logging + if wandb and wandb.run is None: + opt.hyp = hyp # add hyperparameters + wandb_run = wandb.init(config=opt, resume="allow", + project='YOLOR' if opt.project == 'runs/train' else Path(opt.project).stem, + name=save_dir.stem, + id=ckpt.get('wandb_id') if 'ckpt' in locals() else None) + + # Resume + start_epoch = 0 + # best_fitness, best_fitness_p, best_fitness_r, best_fitness_ap50, best_fitness_ap, best_fitness_f = 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 + if pretrained: + # Optimizer + if ckpt['optimizer'] is not None: + optimizer.load_state_dict(ckpt['optimizer']) + # best_fitness = ckpt['best_fitness'] + # best_fitness_p = ckpt['best_fitness_p'] + # best_fitness_r = ckpt['best_fitness_r'] + # best_fitness_ap50 = ckpt['best_fitness_ap50'] + # best_fitness_ap = ckpt['best_fitness_ap'] + # best_fitness_f = ckpt['best_fitness_f'] + + # Results + if ckpt.get('training_results') is not None: + with open(results_file, 'w') as file: + file.write(ckpt['training_results']) # write results.txt + + # Epochs + start_epoch = ckpt['epoch'] + 1 + if opt.resume: + assert start_epoch > 0, '%s training to %g epochs is finished, nothing to resume.' % (weights, epochs) + if epochs < start_epoch: + print('%s has been trained for %g epochs. Fine-tuning for %g additional epochs.' % + (weights, ckpt['epoch'], epochs)) + epochs += ckpt['epoch'] # finetune additional epochs + + del ckpt, state_dict + + # Mixed precision training https://github.com/NVIDIA/apex + if mixed_precision: + if device.type == 'npu': + model, optimizer = amp.initialize(model, optimizer, opt_level='O1', verbosity=0, loss_scale=64, combine_grad=True) + else: + model, optimizer = amp.initialize(model, optimizer, opt_level='O1', verbosity=0, loss_scale=64) + + # Scheduler https://arxiv.org/pdf/1812.01187.pdf + # https://pytorch.org/docs/stable/_modules/torch/optim/lr_scheduler.html#OneCycleLR + lf = lambda x: ((1 + math.cos(x * math.pi / epochs)) / 2) * (1 - hyp['lrf']) + hyp['lrf'] # cosine + scheduler = lr_scheduler.LambdaLR(optimizer, lr_lambda=lf) + # plot_lr_scheduler(optimizer, scheduler, epochs) + + + # SyncBatchNorm + if opt.sync_bn and cuda and rank != -1: + model = torch.nn.SyncBatchNorm.convert_sync_batchnorm(model).to(device) + print('Using SyncBatchNorm()') + + # EMA + ema = ModelEMA(model) if rank in [-1, 0] else None + + # DDP mode + if device.type == 'cuda' and rank != -1: + model = DDP(model, device_ids=[rank], output_device=rank) + elif device.type == 'npu' and rank != -1: + model = DDP(model, device_ids=[rank], broadcast_buffers=False) + + # Trainloader + dataloader, dataset = create_dataloader(train_path, imgsz, batch_size, gs, opt, + hyp=hyp, augment=True, cache=opt.cache_images, rect=opt.rect, + rank=rank, world_size=opt.world_size, workers=opt.workers) + mlc = np.concatenate(dataset.labels, 0)[:, 0].max() # max label class + nb = len(dataloader) # number of batches + assert mlc < nc, 'Label class %g exceeds nc=%g in %s. Possible class labels are 0-%g' % (mlc, nc, opt.data, nc - 1) + + # Model parameters + hyp['cls'] *= nc / 80. # scale coco-tuned hyp['cls'] to current dataset + model.nc = nc # attach number of classes to model + model.hyp = hyp # attach hyperparameters to model + model.gr = 1.0 # iou loss ratio (obj_loss = 1.0 or iou) + model.class_weights = labels_to_class_weights(dataset.labels, nc).to(device) # attach class weights + model.names = names + + # Process 0 + if rank in [-1, 0]: + ema.updates = start_epoch * nb // accumulate # set EMA updates + testloader = create_dataloader(test_path, imgsz_test, batch_size*2, gs, opt, + hyp=hyp, cache=opt.cache_images and not opt.notest, rect=True, + rank=-1, world_size=opt.world_size, workers=opt.workers)[0] # testloader + + if not opt.resume: + labels = np.concatenate(dataset.labels, 0) + c = torch.tensor(labels[:, 0]) # classes + # cf = torch.bincount(c.long(), minlength=nc) + 1. # frequency + # model._initialize_biases(cf.to(device)) + if plots: + plot_labels(labels, save_dir=save_dir) + if tb_writer: + tb_writer.add_histogram('classes', c, 0) + if wandb: + wandb.log({"Labels": [wandb.Image(str(x), caption=x.name) for x in save_dir.glob('*labels*.png')]}) + + # Anchors + # if not opt.noautoanchor: + # check_anchors(dataset, model=model, thr=hyp['anchor_t'], imgsz=imgsz) + + + # Start training + t0 = time.time() + nw = max(round(hyp['warmup_epochs'] * nb), 1000) # number of warmup iterations, max(3 epochs, 1k iterations) + # nw = min(nw, (epochs - start_epoch) / 2 * nb) # limit warmup to < 1/2 of training + maps = np.zeros(nc) # mAP per class + results = (0, 0, 0, 0, 0, 0, 0) # P, R, mAP@.5, mAP@.5-.95, val_loss(box, obj, cls) + scheduler.last_epoch = start_epoch - 1 # do not move + if rank in [0, -1]: + print('Image sizes %g train, %g test\n' + 'Using %g dataloader workers\nLogging results to %s\n' + 'Starting training for %g epochs...' % (imgsz, imgsz_test, dataloader.num_workers, save_dir, epochs)) + + for epoch in range(start_epoch, epochs): # epoch ------------------------------------------------------------------ + model.train() + + # Update image weights (optional) + # When in DDP mode, the generated indices will be broadcasted to synchronize dataset. + if opt.image_weights: + # Generate indices + if rank in [-1, 0]: + cw = model.class_weights.cpu().numpy() * (1 - maps) ** 2 # class weights + iw = labels_to_image_weights(dataset.labels, nc=nc, class_weights=cw) # image weights + dataset.indices = random.choices(range(dataset.n), weights=iw, k=dataset.n) # rand weighted idx + # Broadcast if DDP + if rank != -1: + indices = (torch.tensor(dataset.indices) if rank == 0 else torch.zeros(dataset.n)).int() + dist.broadcast(indices, 0) + if rank != 0: + dataset.indices = indices.cpu().numpy() + + # Update mosaic border + # b = int(random.uniform(0.25 * imgsz, 0.75 * imgsz + gs) // gs * gs) + # dataset.mosaic_border = [b - imgsz, -b] # height, width borders + + mloss = torch.zeros(4, device=device) # mean losses + if rank != -1: + dataloader.sampler.set_epoch(epoch) + optimizer.zero_grad() + start_time = time.time() + d_1 = time.time() + + for i, (imgs, targets, paths, _) in enumerate(dataloader): # batch ------------------------------------------------------------- + t_time = time.time() + d_time = t_time - d_1 + ni = i + nb * epoch # number integrated batches (since train start) + imgs = imgs.to(device, non_blocking=True).float() / 255.0 # uint8 to float32, 0-255 to 0.0-1.0 + + # Warmup + if ni <= nw: + xi = [0, nw] # x interp + # model.gr = np.interp(ni, xi, [0.0, 1.0]) # iou loss ratio (obj_loss = 1.0 or iou) + accumulate = max(1, np.interp(ni, xi, [1, nbs / total_batch_size]).round()) + for j, x in enumerate(optimizer.param_groups): + # bias lr falls from 0.1 to lr0, all other lrs rise from 0.0 to lr0 + x['lr'] = np.interp(ni, xi, [hyp['warmup_bias_lr'] if j == 2 else 0.0, x['initial_lr'] * lf(epoch)]) + if 'momentum' in x: + x['momentum'] = np.interp(ni, xi, [hyp['warmup_momentum'], hyp['momentum']]) + + # Multi-scale + if opt.multi_scale: + sz = random.randrange(imgsz * 0.5, imgsz * 1.5 + gs) // gs * gs # size + sf = sz / max(imgs.shape[2:]) # scale factor + if sf != 1: + ns = [math.ceil(x * sf / gs) * gs for x in imgs.shape[2:]] # new shape (stretched to gs-multiple) + imgs = F.interpolate(imgs, size=ns, mode='bilinear', align_corners=False) + + # Forward + pred = model(imgs) + + # Loss + loss, loss_items = compute_loss(pred, targets.to(device), model) # scaled by batch_size + if rank != -1: + loss *= opt.world_size # gradient averaged between devices in DDP mode + if not torch.isfinite(loss): + print('WARNING: non-finite loss, ending training ', loss_items) + return results + + # Backward + if mixed_precision: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + + # Optimize + if ni % accumulate == 0: + optimizer.step() + optimizer.zero_grad() + if ema is not None: + x = torch.tensor([1.]).to(device) + if device.type == 'npu': + params_fp32_fused = optimizer.get_model_combined_params() + ema.update(model, x, params_fp32_fused[0]) + else: + ema.update(model, x) + + if i <= 10: + sum_time = (time.time() - start_time) / (i + 1) + if i == 10: + start_time = time.time() + else: + sum_time = (time.time() - start_time) / (i - 10) + ptime = time.time() - d_1 + # Print + if rank in [-1, 0]: + mloss = (mloss * i + loss_items) / (i + 1) # update mean losses + mem = '%.3gG' % (torch.cuda.memory_cached() / 1E9 if torch.cuda.is_available() else 0) # (GB) + s = ('%10s' * 2 + '%10.4g' * 6) % ( + '%g/%g' % (epoch, epochs - 1), mem, *mloss, targets.shape[0], imgs.shape[-1]) + print( + 'Epoch:[%2g][%4g/%4g][%s][FPS:%3.1f][mTime:%3.3f][pTime:%3.3f][dTime:%3.3f] GIoU:%.3f objectness:%.3f classfication:%.3f totalLoss:%.3f' % ( + epoch, i, nb, device, opt.total_batch_size / sum_time, sum_time, ptime, d_time, *mloss)) + + # Plot + if plots and ni < 3: + f = save_dir / f'train_batch{ni}.jpg' # filename + plot_images(images=imgs, targets=targets, paths=paths, fname=f) + # if tb_writer: + # tb_writer.add_image(f, result, dataformats='HWC', global_step=epoch) + # tb_writer.add_graph(model, imgs) # add model to tensorboard + elif plots and ni == 3 and wandb: + wandb.log({"Mosaics": [wandb.Image(str(x), caption=x.name) for x in save_dir.glob('train*.jpg')]}) + if i > 170: + break + d_1 = time.time() + # end batch ------------------------------------------------------------------------------------------------ + # end epoch ---------------------------------------------------------------------------------------------------- + + # Scheduler + lr = [x['lr'] for x in optimizer.param_groups] # for tensorboard + scheduler.step() + + # DDP process 0 or single-GPU + if rank in [-1, 0]: + # mAP + if ema: + ema.update_attr(model) + final_epoch = epoch + 1 == epochs + if False: # No test during training + results, maps, _ = test.test(opt.data, + batch_size=batch_size*2, + imgsz=imgsz_test, + model=ema.ema.module if hasattr(ema.ema, 'module') else ema.ema, + single_cls=opt.single_cls, + dataloader=testloader, + save_dir=save_dir, + plots=True) + + # Write + with open(results_file, 'a') as f: + f.write(s + '%10.4g' * 7 % results + '\n') # P, R, mAP@.5, mAP@.5-.95, val_loss(box, obj, cls) + if len(opt.name) and opt.bucket: + os.system('gsutil cp %s gs://%s/results/results%s.txt' % (results_file, opt.bucket, opt.name)) + + # Log + tags = ['train/box_loss', 'train/obj_loss', 'train/cls_loss', # train loss + 'metrics/precision', 'metrics/recall', 'metrics/mAP_0.5', 'metrics/mAP_0.5:0.95', + 'val/box_loss', 'val/obj_loss', 'val/cls_loss', # val loss + 'x/lr0', 'x/lr1', 'x/lr2'] # params + for x, tag in zip(list(mloss[:-1]) + list(results) + lr, tags): + if tb_writer: + tb_writer.add_scalar(tag, x, epoch) # tensorboard + if wandb: + wandb.log({tag: x}) # W&B + + # # Update best mAP + # fi = fitness(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] + # fi_p = fitness_p(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] + # fi_r = fitness_r(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] + # fi_ap50 = fitness_ap50(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] + # fi_ap = fitness_ap(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] + # if (fi_p > 0.0) or (fi_r > 0.0): + # fi_f = fitness_f(np.array(results).reshape(1, -1)) # weighted combination of [P, R, mAP@.5, mAP@.5-.95] + # else: + # fi_f = 0.0 + # if fi > best_fitness: + # best_fitness = fi + # if fi_p > best_fitness_p: + # best_fitness_p = fi_p + # if fi_r > best_fitness_r: + # best_fitness_r = fi_r + # if fi_ap50 > best_fitness_ap50: + # best_fitness_ap50 = fi_ap50 + # if fi_ap > best_fitness_ap: + # best_fitness_ap = fi_ap + # if fi_f > best_fitness_f: + # best_fitness_f = fi_f + + # Save model + save = (not opt.nosave) or (final_epoch and not opt.evolve) + if save: + with open(results_file, 'r') as f: # create checkpoint + ckpt = {'epoch': epoch, + # 'best_fitness': best_fitness, + # 'best_fitness_p': best_fitness_p, + # 'best_fitness_r': best_fitness_r, + # 'best_fitness_ap50': best_fitness_ap50, + # 'best_fitness_ap': best_fitness_ap, + # 'best_fitness_f': best_fitness_f, + 'training_results': f.read(), + 'model': ema.ema.module.state_dict() if hasattr(ema, 'module') else ema.ema.state_dict(), + 'optimizer': None if final_epoch else optimizer.state_dict(), + 'wandb_id': wandb_run.id if wandb else None} + + # Save last, best and delete + torch.save(ckpt, last) + # if best_fitness == fi: + # torch.save(ckpt, best) + # if (best_fitness == fi) and (epoch >= 200): + # torch.save(ckpt, wdir / 'best_{:03d}.pt'.format(epoch)) + # if best_fitness == fi: + # torch.save(ckpt, wdir / 'best_overall.pt') + # if best_fitness_p == fi_p: + # torch.save(ckpt, wdir / 'best_p.pt') + # if best_fitness_r == fi_r: + # torch.save(ckpt, wdir / 'best_r.pt') + # if best_fitness_ap50 == fi_ap50: + # torch.save(ckpt, wdir / 'best_ap50.pt') + # if best_fitness_ap == fi_ap: + # torch.save(ckpt, wdir / 'best_ap.pt') + # if best_fitness_f == fi_f: + # torch.save(ckpt, wdir / 'best_f.pt') + if epoch == 0: + torch.save(ckpt, wdir / 'epoch_{:03d}.pt'.format(epoch)) + if ((epoch+1) % 25) == 0: + torch.save(ckpt, wdir / 'epoch_{:03d}.pt'.format(epoch)) + if epoch >= (epochs-5): + torch.save(ckpt, wdir / 'last_{:03d}.pt'.format(epoch)) + elif epoch >= 420: + torch.save(ckpt, wdir / 'last_{:03d}.pt'.format(epoch)) + del ckpt + # end epoch ---------------------------------------------------------------------------------------------------- + # end training + + if rank in [-1, 0]: + # Strip optimizers + n = opt.name if opt.name.isnumeric() else '' + fresults, flast, fbest = save_dir / f'results{n}.txt', wdir / f'last{n}.pt', wdir / f'best{n}.pt' + for f1, f2 in zip([wdir / 'last.pt', wdir / 'best.pt', results_file], [flast, fbest, fresults]): + if f1.exists(): + os.rename(f1, f2) # rename + if str(f2).endswith('.pt'): # is *.pt + strip_optimizer(f2) # strip optimizer + os.system('gsutil cp %s gs://%s/weights' % (f2, opt.bucket)) if opt.bucket else None # upload + # Finish + if plots: + plot_results(save_dir=save_dir) # save as results.png + if wandb: + wandb.log({"Results": [wandb.Image(str(save_dir / x), caption=x) for x in + ['results.png', 'precision-recall_curve.png']]}) + print('%g epochs completed in %.3f hours.\n' % (epoch - start_epoch + 1, (time.time() - t0) / 3600)) + + else: + dist.destroy_process_group() + + wandb.run.finish() if wandb and wandb.run else None + torch.cuda.empty_cache() + + return results + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--weights', type=str, default='yolor_p6.pt', help='initial weights path') + parser.add_argument('--cfg', type=str, default='', help='model.yaml path') + parser.add_argument('--data', type=str, default='data/coco.yaml', help='data.yaml path') + parser.add_argument('--hyp', type=str, default='data/hyp.scratch.1280.yaml', help='hyperparameters path') + parser.add_argument('--epochs', type=int, default=300) + parser.add_argument('--batch-size', type=int, default=8, help='total batch size for all GPUs') + parser.add_argument('--img-size', nargs='+', type=int, default=[1280, 1280], help='[train, test] image sizes') + parser.add_argument('--rect', action='store_true', help='rectangular training') + parser.add_argument('--resume', nargs='?', const=True, default=False, help='resume most recent training') + parser.add_argument('--nosave', action='store_true', help='only save final checkpoint') + parser.add_argument('--notest', action='store_true', help='only test final epoch') + parser.add_argument('--noautoanchor', action='store_true', help='disable autoanchor check') + parser.add_argument('--evolve', action='store_true', help='evolve hyperparameters') + parser.add_argument('--bucket', type=str, default='', help='gsutil bucket') + parser.add_argument('--cache-images', action='store_true', help='cache images for faster training') + parser.add_argument('--image-weights', action='store_true', help='use weighted image selection for training') + parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu or npu') + parser.add_argument('--multi-scale', action='store_true', help='vary img-size +/- 50%%') + parser.add_argument('--single-cls', action='store_true', help='train as single-class dataset') + parser.add_argument('--adam', action='store_true', help='use torch.optim.Adam() optimizer') + parser.add_argument('--sync-bn', action='store_true', help='use SyncBatchNorm, only available in DDP mode') + parser.add_argument('--full', action='store_true', help='full mode') + parser.add_argument('--local_rank', type=int, default=-1, help='DDP parameter, do not modify') + parser.add_argument('--log-imgs', type=int, default=16, help='number of images for W&B logging, max 100') + parser.add_argument('--workers', type=int, default=8, help='maximum number of dataloader workers') + parser.add_argument('--project', default='runs/train', help='save to project/name') + parser.add_argument('--name', default='exp', help='save to project/name') + parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') + parser.add_argument('--npu', default=-1, type=int, help='NPU id to use.') + + # NPU DDP mode + parser.add_argument('--world-size', default=1, type=int, help='number of nodes for distributed training') + parser.add_argument('--device-num', default=1, type=int, help='multi NPU parameter, GPU or CPU do not modify') + parser.add_argument('--addr', default='127.0.0.1', type=str, help='DDP master node IP') + parser.add_argument('--dist-url', default='tcp://127.0.0.1:29501', type=str, + help='url used to set up distributed training') + opt = parser.parse_args() + + if opt.dist_url == "env://": + opt.world_size = int(os.environ["WORLD_SIZE"]) + ngpus_per_node = opt.device_num + opt.npu_ddp = (opt.device_num > 1 or opt.world_size > 1) + if opt.npu_ddp: + print('multi npu training') + os.environ['MASTER_ADDR'] = opt.addr # master ip + os.environ['MASTER_PORT'] = '29501' + os.environ['KERNEL_NAME_ID'] = str(0) + opt.world_size = ngpus_per_node * opt.world_size # the sum of GPU or NPU in all the nodes + mp.spawn(main_worker, nprocs=ngpus_per_node, args=(ngpus_per_node, opt)) + else: + print('1p training') + main_worker(opt.npu, ngpus_per_node, opt) + + # # Set DDP variables + # opt.total_batch_size = opt.batch_size + # opt.world_size = int(os.environ['WORLD_SIZE']) if 'WORLD_SIZE' in os.environ else 1 + # opt.global_rank = int(os.environ['RANK']) if 'RANK' in os.environ else -1 + # set_logging(opt.global_rank) + # if opt.global_rank in [-1, 0]: + # check_git_status() + + # # DDP mode + # device = select_device(opt.device, batch_size=opt.batch_size) + # if opt.local_rank != -1: + # assert torch.cuda.device_count() > opt.local_rank + # torch.cuda.set_device(opt.local_rank) + # device = torch.device('cuda', opt.local_rank) + # dist.init_process_group(backend='nccl', init_method='env://') # distributed backend + # assert opt.batch_size % opt.world_size == 0, '--batch-size must be multiple of CUDA device count' + # opt.batch_size = opt.total_batch_size // opt.world_size + + +def main_worker(npu, ngpus_per_node, opt): + # Resume + if opt.resume: # resume an interrupted run + ckpt = opt.resume if isinstance(opt.resume, str) else get_latest_run() # specified or most recent path + assert os.path.isfile(ckpt), 'ERROR: --resume checkpoint does not exist' + with open(Path(ckpt).parent.parent / 'opt.yaml') as f: + opt = argparse.Namespace(**yaml.load(f, Loader=yaml.FullLoader)) # replace + opt.cfg, opt.weights, opt.resume = '', ckpt, True + print('Resuming training from %s' % ckpt) + else: + # opt.hyp = opt.hyp or ('hyp.finetune.yaml' if opt.weights else 'hyp.scratch.yaml') + opt.data, opt.cfg, opt.hyp = check_file(opt.data), check_file(opt.cfg), check_file(opt.hyp) # check files + assert len(opt.cfg) or len(opt.weights), 'either --cfg or --weights must be specified' + opt.img_size.extend([opt.img_size[-1]] * (2 - len(opt.img_size))) # extend to 2 sizes (train, test) + opt.name = 'evolve' if opt.evolve else opt.name + opt.save_dir = increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok | opt.evolve) # increment run + + # Hyperparameters + with open(opt.hyp) as f: + hyp = yaml.load(f, Loader=yaml.FullLoader) # load hyps + if 'box' not in hyp: + warn('Compatibility: %s missing "box" which was renamed from "giou" in %s' % + (opt.hyp, 'https://github.com/ultralytics/yolov5/pull/1120')) + hyp['box'] = hyp.pop('giou') + + # npu DDP + if opt.npu_ddp: + opt.npu = npu + os.environ['KERNEL_NAME_ID'] = str(npu) + print("[npu id:", opt.npu, "]", "+++++++++++++++++++++++++++KERNEL_NAME_ID:", os.environ['KERNEL_NAME_ID']) + opt.local_rank = opt.local_rank * ngpus_per_node + npu + global mixed_precision + device = torch_utils.select_device(opt.device, opt.npu, apex=mixed_precision, batch_size=opt.batch_size) + opt.total_batch_size = opt.batch_size + if device.type == 'cpu': + mixed_precision = False + elif opt.local_rank != -1 and device.type == 'cuda': + # DDP mode + assert torch.cuda.device_count() > opt.local_rank + torch.cuda.set_device(opt.local_rank) + device = torch.device("cuda", opt.local_rank) + dist.init_process_group(backend='nccl', init_method='env://') # distributed backend + + opt.world_size = dist.get_world_size() + assert opt.batch_size % opt.world_size == 0, "Batch size is not a multiple of the number of devices given!" + opt.batch_size = opt.total_batch_size // opt.world_size + elif opt.local_rank != -1 and device.type == 'npu': + dist.init_process_group(backend='hccl', world_size=opt.world_size, rank=opt.local_rank) + assert opt.batch_size % opt.world_size == 0, "Batch size is not a multiple of the number of devices given!" + opt.batch_size = opt.total_batch_size // opt.world_size + + # Train + print(opt) + if not opt.evolve: + tb_writer = None # init loggers + if opt.local_rank in [-1, 0]: + print(f'Start Tensorboard with "tensorboard --logdir {opt.project}", view at http://localhost:6006/') + tb_writer = SummaryWriter(opt.save_dir) # Tensorboard + train(hyp, opt, device, tb_writer, wandb) + + # Evolve hyperparameters (optional) + else: + # Hyperparameter evolution metadata (mutation scale 0-1, lower_limit, upper_limit) + meta = {'lr0': (1, 1e-5, 1e-1), # initial learning rate (SGD=1E-2, Adam=1E-3) + 'lrf': (1, 0.01, 1.0), # final OneCycleLR learning rate (lr0 * lrf) + 'momentum': (0.3, 0.6, 0.98), # SGD momentum/Adam beta1 + 'weight_decay': (1, 0.0, 0.001), # optimizer weight decay + 'warmup_epochs': (1, 0.0, 5.0), # warmup epochs (fractions ok) + 'warmup_momentum': (1, 0.0, 0.95), # warmup initial momentum + 'warmup_bias_lr': (1, 0.0, 0.2), # warmup initial bias lr + 'box': (1, 0.02, 0.2), # box loss gain + 'cls': (1, 0.2, 4.0), # cls loss gain + 'cls_pw': (1, 0.5, 2.0), # cls BCELoss positive_weight + 'obj': (1, 0.2, 4.0), # obj loss gain (scale with pixels) + 'obj_pw': (1, 0.5, 2.0), # obj BCELoss positive_weight + 'iou_t': (0, 0.1, 0.7), # IoU training threshold + 'anchor_t': (1, 2.0, 8.0), # anchor-multiple threshold + 'anchors': (2, 2.0, 10.0), # anchors per output grid (0 to ignore) + 'fl_gamma': (0, 0.0, 2.0), # focal loss gamma (efficientDet default gamma=1.5) + 'hsv_h': (1, 0.0, 0.1), # image HSV-Hue augmentation (fraction) + 'hsv_s': (1, 0.0, 0.9), # image HSV-Saturation augmentation (fraction) + 'hsv_v': (1, 0.0, 0.9), # image HSV-Value augmentation (fraction) + 'degrees': (1, 0.0, 45.0), # image rotation (+/- deg) + 'translate': (1, 0.0, 0.9), # image translation (+/- fraction) + 'scale': (1, 0.0, 0.9), # image scale (+/- gain) + 'shear': (1, 0.0, 10.0), # image shear (+/- deg) + 'perspective': (0, 0.0, 0.001), # image perspective (+/- fraction), range 0-0.001 + 'flipud': (1, 0.0, 1.0), # image flip up-down (probability) + 'fliplr': (0, 0.0, 1.0), # image flip left-right (probability) + 'mosaic': (1, 0.0, 1.0), # image mixup (probability) + 'mixup': (1, 0.0, 1.0)} # image mixup (probability) + + assert opt.local_rank == -1, 'DDP mode not implemented for --evolve' + opt.notest, opt.nosave = True, True # only test/save final epoch + # ei = [isinstance(x, (int, float)) for x in hyp.values()] # evolvable indices + yaml_file = Path(opt.save_dir) / 'hyp_evolved.yaml' # save best result here + if opt.bucket: + os.system('gsutil cp gs://%s/evolve.txt .' % opt.bucket) # download evolve.txt if exists + + for _ in range(300): # generations to evolve + if Path('evolve.txt').exists(): # if evolve.txt exists: select best hyps and mutate + # Select parent(s) + parent = 'single' # parent selection method: 'single' or 'weighted' + x = np.loadtxt('evolve.txt', ndmin=2) + n = min(5, len(x)) # number of previous results to consider + x = x[np.argsort(-fitness(x))][:n] # top n mutations + w = fitness(x) - fitness(x).min() # weights + if parent == 'single' or len(x) == 1: + # x = x[random.randint(0, n - 1)] # random selection + x = x[random.choices(range(n), weights=w)[0]] # weighted selection + elif parent == 'weighted': + x = (x * w.reshape(n, 1)).sum(0) / w.sum() # weighted combination + + # Mutate + mp, s = 0.8, 0.2 # mutation probability, sigma + npr = np.random + npr.seed(int(time.time())) + g = np.array([x[0] for x in meta.values()]) # gains 0-1 + ng = len(meta) + v = np.ones(ng) + while all(v == 1): # mutate until a change occurs (prevent duplicates) + v = (g * (npr.random(ng) < mp) * npr.randn(ng) * npr.random() * s + 1).clip(0.3, 3.0) + for i, k in enumerate(hyp.keys()): # plt.hist(v.ravel(), 300) + hyp[k] = float(x[i + 7] * v[i]) # mutate + + # Constrain to limits + for k, v in meta.items(): + hyp[k] = max(hyp[k], v[1]) # lower limit + hyp[k] = min(hyp[k], v[2]) # upper limit + hyp[k] = round(hyp[k], 5) # significant digits + + # Train mutation + results = train(hyp.copy(), opt, device, wandb=wandb) + + # Write mutation results + print_mutation(hyp.copy(), results, yaml_file, opt.bucket) + + # Plot results + plot_evolution(yaml_file) + print(f'Hyperparameter evolution complete. Best results saved as: {yaml_file}\n' + f'Command to train a new model with these hyperparameters: $ python train.py --hyp {yaml_file}') + + +if __name__ == '__main__': + # option = {} + # option["ACL_OP_DEBUG_LEVEL"] = 3 # 算子debug功能,暂不开启 + # option["ACL_DEBUG_DIR"] = "debug_file" # 算子debug功能对应文件夹,暂不开启 + # option["ACL_OP_COMPILER_CACHE_MODE"] = "enable" # cache功能启用 + # option["ACL_OP_COMPILER_CACHE_DIR"] = "./kernel_meta" # cache所在文件夹 + # print("option:",option) + # torch.npu.set_option(option) + main() diff --git a/PyTorch/contrib/cv/detection/YOLOR/utils/__init__.py b/PyTorch/contrib/cv/detection/YOLOR/utils/__init__.py index d3f5a12faa99758192ecc4ed3fc22c9249232e86..8b137891791fe96927ad78e64b0aad7bded08bdc 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/utils/__init__.py +++ b/PyTorch/contrib/cv/detection/YOLOR/utils/__init__.py @@ -1 +1 @@ - + diff --git a/PyTorch/contrib/cv/detection/YOLOR/utils/activations.py b/PyTorch/contrib/cv/detection/YOLOR/utils/activations.py index 8b64eae41c5ac8763562785deabf7947d6248457..8bf1e62efbd623a784f99191cb9577fbe2541f5a 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/utils/activations.py +++ b/PyTorch/contrib/cv/detection/YOLOR/utils/activations.py @@ -1,85 +1,85 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Activation functions - -import torch -import torch.nn as nn -import torch.nn.functional as F - -# Swish https://arxiv.org/pdf/1905.02244.pdf --------------------------------------------------------------------------- -class Swish(nn.Module): # - @staticmethod - def forward(x): - return x * torch.sigmoid(x) - - -class Hardswish(nn.Module): # export-friendly version of nn.Hardswish() - @staticmethod - def forward(x): - # return x * F.hardsigmoid(x) # for torchscript and CoreML - return x * F.hardtanh(x + 3, 0., 6.) / 6. # for torchscript, CoreML and ONNX - - -class MemoryEfficientSwish(nn.Module): - class F(torch.autograd.Function): - @staticmethod - def forward(ctx, x): - ctx.save_for_backward(x) - return x * torch.sigmoid(x) - - @staticmethod - def backward(ctx, grad_output): - x = ctx.saved_tensors[0] - sx = torch.sigmoid(x) - return grad_output * (sx * (1 + x * (1 - sx))) - - def forward(self, x): - return self.F.apply(x) - - -# Mish https://github.com/digantamisra98/Mish -------------------------------------------------------------------------- -class Mish(nn.Module): - @staticmethod - def forward(x): - return x * F.softplus(x).tanh() - - -class MemoryEfficientMish(nn.Module): - class F(torch.autograd.Function): - @staticmethod - def forward(ctx, x): - ctx.save_for_backward(x) - return x.mul(torch.tanh(F.softplus(x))) # x * tanh(ln(1 + exp(x))) - - @staticmethod - def backward(ctx, grad_output): - x = ctx.saved_tensors[0] - sx = torch.sigmoid(x) - fx = F.softplus(x).tanh() - return grad_output * (fx + x * sx * (1 - fx * fx)) - - def forward(self, x): - return self.F.apply(x) - - -# FReLU https://arxiv.org/abs/2007.11824 ------------------------------------------------------------------------------- -class FReLU(nn.Module): - def __init__(self, c1, k=3): # ch_in, kernel - super().__init__() - self.conv = nn.Conv2d(c1, c1, k, 1, 1, groups=c1) - self.bn = nn.BatchNorm2d(c1) - - def forward(self, x): - return torch.max(x, self.bn(self.conv(x))) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Activation functions + +import torch +import torch.nn as nn +import torch.nn.functional as F + +# Swish https://arxiv.org/pdf/1905.02244.pdf --------------------------------------------------------------------------- +class Swish(nn.Module): # + @staticmethod + def forward(x): + return x * torch.sigmoid(x) + + +class Hardswish(nn.Module): # export-friendly version of nn.Hardswish() + @staticmethod + def forward(x): + # return x * F.hardsigmoid(x) # for torchscript and CoreML + return x * F.hardtanh(x + 3, 0., 6.) / 6. # for torchscript, CoreML and ONNX + + +class MemoryEfficientSwish(nn.Module): + class F(torch.autograd.Function): + @staticmethod + def forward(ctx, x): + ctx.save_for_backward(x) + return x * torch.sigmoid(x) + + @staticmethod + def backward(ctx, grad_output): + x = ctx.saved_tensors[0] + sx = torch.sigmoid(x) + return grad_output * (sx * (1 + x * (1 - sx))) + + def forward(self, x): + return self.F.apply(x) + + +# Mish https://github.com/digantamisra98/Mish -------------------------------------------------------------------------- +class Mish(nn.Module): + @staticmethod + def forward(x): + return x * F.softplus(x).tanh() + + +class MemoryEfficientMish(nn.Module): + class F(torch.autograd.Function): + @staticmethod + def forward(ctx, x): + ctx.save_for_backward(x) + return x.mul(torch.tanh(F.softplus(x))) # x * tanh(ln(1 + exp(x))) + + @staticmethod + def backward(ctx, grad_output): + x = ctx.saved_tensors[0] + sx = torch.sigmoid(x) + fx = F.softplus(x).tanh() + return grad_output * (fx + x * sx * (1 - fx * fx)) + + def forward(self, x): + return self.F.apply(x) + + +# FReLU https://arxiv.org/abs/2007.11824 ------------------------------------------------------------------------------- +class FReLU(nn.Module): + def __init__(self, c1, k=3): # ch_in, kernel + super().__init__() + self.conv = nn.Conv2d(c1, c1, k, 1, 1, groups=c1) + self.bn = nn.BatchNorm2d(c1) + + def forward(self, x): + return torch.max(x, self.bn(self.conv(x))) diff --git a/PyTorch/contrib/cv/detection/YOLOR/utils/autoanchor.py b/PyTorch/contrib/cv/detection/YOLOR/utils/autoanchor.py index 2fd6d56da54e6fc7072b337a75236ce7105043e8..709b00f4b1e9e6b3bb9dfc93962fa60ec68ad56f 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/utils/autoanchor.py +++ b/PyTorch/contrib/cv/detection/YOLOR/utils/autoanchor.py @@ -1,166 +1,166 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Auto-anchor utils - -import numpy as np -import torch -import yaml -from scipy.cluster.vq import kmeans -from tqdm import tqdm - - -def check_anchor_order(m): - # Check anchor order against stride order for YOLOv5 Detect() module m, and correct if necessary - a = m.anchor_grid.prod(-1).view(-1) # anchor area - da = a[-1] - a[0] # delta a - ds = m.stride[-1] - m.stride[0] # delta s - if da.sign() != ds.sign(): # same order - print('Reversing anchor order') - m.anchors[:] = m.anchors.flip(0) - m.anchor_grid[:] = m.anchor_grid.flip(0) - - -def check_anchors(dataset, model, thr=4.0, imgsz=640): - # Check anchor fit to data, recompute if necessary - print('\nAnalyzing anchors... ', end='') - m = model.module.model[-1] if hasattr(model, 'module') else model.model[-1] # Detect() - shapes = imgsz * dataset.shapes / dataset.shapes.max(1, keepdims=True) - scale = np.random.uniform(0.9, 1.1, size=(shapes.shape[0], 1)) # augment scale - wh = torch.tensor(np.concatenate([l[:, 3:5] * s for s, l in zip(shapes * scale, dataset.labels)])).float() # wh - - def metric(k): # compute metric - r = wh[:, None] / k[None] - x = torch.min(r, 1. / r).min(2)[0] # ratio metric - best = x.max(1)[0] # best_x - aat = (x > 1. / thr).float().sum(1).mean() # anchors above threshold - bpr = (best > 1. / thr).float().mean() # best possible recall - return bpr, aat - - bpr, aat = metric(m.anchor_grid.clone().cpu().view(-1, 2)) - print('anchors/target = %.2f, Best Possible Recall (BPR) = %.4f' % (aat, bpr), end='') - if bpr < 0.98: # threshold to recompute - print('. Attempting to improve anchors, please wait...') - na = m.anchor_grid.numel() // 2 # number of anchors - new_anchors = kmean_anchors(dataset, n=na, img_size=imgsz, thr=thr, gen=1000, verbose=False) - new_bpr = metric(new_anchors.reshape(-1, 2))[0] - if new_bpr > bpr: # replace anchors - new_anchors = torch.tensor(new_anchors, device=m.anchors.device).type_as(m.anchors) - m.anchor_grid[:] = new_anchors.clone().view_as(m.anchor_grid) # for inference - m.anchors[:] = new_anchors.clone().view_as(m.anchors) / m.stride.to(m.anchors.device).view(-1, 1, 1) # loss - check_anchor_order(m) - print('New anchors saved to model. Update model *.yaml to use these anchors in the future.') - else: - print('Original anchors better than new anchors. Proceeding with original anchors.') - print('') # newline - - -def kmean_anchors(path='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen=1000, verbose=True): - """ Creates kmeans-evolved anchors from training dataset - - Arguments: - path: path to dataset *.yaml, or a loaded dataset - n: number of anchors - img_size: image size used for training - thr: anchor-label wh ratio threshold hyperparameter hyp['anchor_t'] used for training, default=4.0 - gen: generations to evolve anchors using genetic algorithm - verbose: print all results - - Return: - k: kmeans evolved anchors - - Usage: - from utils.general import *; _ = kmean_anchors() - """ - thr = 1. / thr - - def metric(k, wh): # compute metrics - r = wh[:, None] / k[None] - x = torch.min(r, 1. / r).min(2)[0] # ratio metric - # x = wh_iou(wh, torch.tensor(k)) # iou metric - return x, x.max(1)[0] # x, best_x - - def anchor_fitness(k): # mutation fitness - _, best = metric(torch.tensor(k, dtype=torch.float32), wh) - return (best * (best > thr).float()).mean() # fitness - - def print_results(k): - k = k[np.argsort(k.prod(1))] # sort small to large - x, best = metric(k, wh0) - bpr, aat = (best > thr).float().mean(), (x > thr).float().mean() * n # best possible recall, anch > thr - print('thr=%.2f: %.4f best possible recall, %.2f anchors past thr' % (thr, bpr, aat)) - print('n=%g, img_size=%s, metric_all=%.3f/%.3f-mean/best, past_thr=%.3f-mean: ' % - (n, img_size, x.mean(), best.mean(), x[x > thr].mean()), end='') - for i, x in enumerate(k): - print('%i,%i' % (round(x[0]), round(x[1])), end=', ' if i < len(k) - 1 else '\n') # use in *.cfg - return k - - if isinstance(path, str): # *.yaml file - with open(path) as f: - data_dict = yaml.load(f, Loader=yaml.FullLoader) # model dict - from utils.datasets import LoadImagesAndLabels - dataset = LoadImagesAndLabels(data_dict['train'], augment=True, rect=True) - else: - dataset = path # dataset - - # Get label wh - shapes = img_size * dataset.shapes / dataset.shapes.max(1, keepdims=True) - wh0 = np.concatenate([l[:, 3:5] * s for s, l in zip(shapes, dataset.labels)]) # wh - - # Filter - i = (wh0 < 3.0).any(1).sum() - if i: - print('WARNING: Extremely small objects found. ' - '%g of %g labels are < 3 pixels in width or height.' % (i, len(wh0))) - wh = wh0[(wh0 >= 2.0).any(1)] # filter > 2 pixels - - # Kmeans calculation - print('Running kmeans for %g anchors on %g points...' % (n, len(wh))) - s = wh.std(0) # sigmas for whitening - k, dist = kmeans(wh / s, n, iter=30) # points, mean distance - k *= s - wh = torch.tensor(wh, dtype=torch.float32) # filtered - wh0 = torch.tensor(wh0, dtype=torch.float32) # unfiltered - k = print_results(k) - - # Plot - # k, d = [None] * 20, [None] * 20 - # for i in tqdm(range(1, 21)): - # k[i-1], d[i-1] = kmeans(wh / s, i) # points, mean distance - # fig, ax = plt.subplots(1, 2, figsize=(14, 7)) - # ax = ax.ravel() - # ax[0].plot(np.arange(1, 21), np.array(d) ** 2, marker='.') - # fig, ax = plt.subplots(1, 2, figsize=(14, 7)) # plot wh - # ax[0].hist(wh[wh[:, 0]<100, 0],400) - # ax[1].hist(wh[wh[:, 1]<100, 1],400) - # fig.tight_layout() - # fig.savefig('wh.png', dpi=200) - - # Evolve - npr = np.random - f, sh, mp, s = anchor_fitness(k), k.shape, 0.9, 0.1 # fitness, generations, mutation prob, sigma - pbar = tqdm(range(gen), desc='Evolving anchors with Genetic Algorithm') # progress bar - for _ in pbar: - v = np.ones(sh) - while (v == 1).all(): # mutate until a change occurs (prevent duplicates) - v = ((npr.random(sh) < mp) * npr.random() * npr.randn(*sh) * s + 1).clip(0.3, 3.0) - kg = (k.copy() * v).clip(min=2.0) - fg = anchor_fitness(kg) - if fg > f: - f, k = fg, kg.copy() - pbar.desc = 'Evolving anchors with Genetic Algorithm: fitness = %.4f' % f - if verbose: - print_results(k) - - return print_results(k) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Auto-anchor utils + +import numpy as np +import torch +import yaml +from scipy.cluster.vq import kmeans +from tqdm import tqdm + + +def check_anchor_order(m): + # Check anchor order against stride order for YOLOv5 Detect() module m, and correct if necessary + a = m.anchor_grid.prod(-1).view(-1) # anchor area + da = a[-1] - a[0] # delta a + ds = m.stride[-1] - m.stride[0] # delta s + if da.sign() != ds.sign(): # same order + print('Reversing anchor order') + m.anchors[:] = m.anchors.flip(0) + m.anchor_grid[:] = m.anchor_grid.flip(0) + + +def check_anchors(dataset, model, thr=4.0, imgsz=640): + # Check anchor fit to data, recompute if necessary + print('\nAnalyzing anchors... ', end='') + m = model.module.model[-1] if hasattr(model, 'module') else model.model[-1] # Detect() + shapes = imgsz * dataset.shapes / dataset.shapes.max(1, keepdims=True) + scale = np.random.uniform(0.9, 1.1, size=(shapes.shape[0], 1)) # augment scale + wh = torch.tensor(np.concatenate([l[:, 3:5] * s for s, l in zip(shapes * scale, dataset.labels)])).float() # wh + + def metric(k): # compute metric + r = wh[:, None] / k[None] + x = torch.min(r, 1. / r).min(2)[0] # ratio metric + best = x.max(1)[0] # best_x + aat = (x > 1. / thr).float().sum(1).mean() # anchors above threshold + bpr = (best > 1. / thr).float().mean() # best possible recall + return bpr, aat + + bpr, aat = metric(m.anchor_grid.clone().cpu().view(-1, 2)) + print('anchors/target = %.2f, Best Possible Recall (BPR) = %.4f' % (aat, bpr), end='') + if bpr < 0.98: # threshold to recompute + print('. Attempting to improve anchors, please wait...') + na = m.anchor_grid.numel() // 2 # number of anchors + new_anchors = kmean_anchors(dataset, n=na, img_size=imgsz, thr=thr, gen=1000, verbose=False) + new_bpr = metric(new_anchors.reshape(-1, 2))[0] + if new_bpr > bpr: # replace anchors + new_anchors = torch.tensor(new_anchors, device=m.anchors.device).type_as(m.anchors) + m.anchor_grid[:] = new_anchors.clone().view_as(m.anchor_grid) # for inference + m.anchors[:] = new_anchors.clone().view_as(m.anchors) / m.stride.to(m.anchors.device).view(-1, 1, 1) # loss + check_anchor_order(m) + print('New anchors saved to model. Update model *.yaml to use these anchors in the future.') + else: + print('Original anchors better than new anchors. Proceeding with original anchors.') + print('') # newline + + +def kmean_anchors(path='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen=1000, verbose=True): + """ Creates kmeans-evolved anchors from training dataset + + Arguments: + path: path to dataset *.yaml, or a loaded dataset + n: number of anchors + img_size: image size used for training + thr: anchor-label wh ratio threshold hyperparameter hyp['anchor_t'] used for training, default=4.0 + gen: generations to evolve anchors using genetic algorithm + verbose: print all results + + Return: + k: kmeans evolved anchors + + Usage: + from utils.general import *; _ = kmean_anchors() + """ + thr = 1. / thr + + def metric(k, wh): # compute metrics + r = wh[:, None] / k[None] + x = torch.min(r, 1. / r).min(2)[0] # ratio metric + # x = wh_iou(wh, torch.tensor(k)) # iou metric + return x, x.max(1)[0] # x, best_x + + def anchor_fitness(k): # mutation fitness + _, best = metric(torch.tensor(k, dtype=torch.float32), wh) + return (best * (best > thr).float()).mean() # fitness + + def print_results(k): + k = k[np.argsort(k.prod(1))] # sort small to large + x, best = metric(k, wh0) + bpr, aat = (best > thr).float().mean(), (x > thr).float().mean() * n # best possible recall, anch > thr + print('thr=%.2f: %.4f best possible recall, %.2f anchors past thr' % (thr, bpr, aat)) + print('n=%g, img_size=%s, metric_all=%.3f/%.3f-mean/best, past_thr=%.3f-mean: ' % + (n, img_size, x.mean(), best.mean(), x[x > thr].mean()), end='') + for i, x in enumerate(k): + print('%i,%i' % (round(x[0]), round(x[1])), end=', ' if i < len(k) - 1 else '\n') # use in *.cfg + return k + + if isinstance(path, str): # *.yaml file + with open(path) as f: + data_dict = yaml.load(f, Loader=yaml.FullLoader) # model dict + from utils.datasets import LoadImagesAndLabels + dataset = LoadImagesAndLabels(data_dict['train'], augment=True, rect=True) + else: + dataset = path # dataset + + # Get label wh + shapes = img_size * dataset.shapes / dataset.shapes.max(1, keepdims=True) + wh0 = np.concatenate([l[:, 3:5] * s for s, l in zip(shapes, dataset.labels)]) # wh + + # Filter + i = (wh0 < 3.0).any(1).sum() + if i: + print('WARNING: Extremely small objects found. ' + '%g of %g labels are < 3 pixels in width or height.' % (i, len(wh0))) + wh = wh0[(wh0 >= 2.0).any(1)] # filter > 2 pixels + + # Kmeans calculation + print('Running kmeans for %g anchors on %g points...' % (n, len(wh))) + s = wh.std(0) # sigmas for whitening + k, dist = kmeans(wh / s, n, iter=30) # points, mean distance + k *= s + wh = torch.tensor(wh, dtype=torch.float32) # filtered + wh0 = torch.tensor(wh0, dtype=torch.float32) # unfiltered + k = print_results(k) + + # Plot + # k, d = [None] * 20, [None] * 20 + # for i in tqdm(range(1, 21)): + # k[i-1], d[i-1] = kmeans(wh / s, i) # points, mean distance + # fig, ax = plt.subplots(1, 2, figsize=(14, 7)) + # ax = ax.ravel() + # ax[0].plot(np.arange(1, 21), np.array(d) ** 2, marker='.') + # fig, ax = plt.subplots(1, 2, figsize=(14, 7)) # plot wh + # ax[0].hist(wh[wh[:, 0]<100, 0],400) + # ax[1].hist(wh[wh[:, 1]<100, 1],400) + # fig.tight_layout() + # fig.savefig('wh.png', dpi=200) + + # Evolve + npr = np.random + f, sh, mp, s = anchor_fitness(k), k.shape, 0.9, 0.1 # fitness, generations, mutation prob, sigma + pbar = tqdm(range(gen), desc='Evolving anchors with Genetic Algorithm') # progress bar + for _ in pbar: + v = np.ones(sh) + while (v == 1).all(): # mutate until a change occurs (prevent duplicates) + v = ((npr.random(sh) < mp) * npr.random() * npr.randn(*sh) * s + 1).clip(0.3, 3.0) + kg = (k.copy() * v).clip(min=2.0) + fg = anchor_fitness(kg) + if fg > f: + f, k = fg, kg.copy() + pbar.desc = 'Evolving anchors with Genetic Algorithm: fitness = %.4f' % f + if verbose: + print_results(k) + + return print_results(k) diff --git a/PyTorch/contrib/cv/detection/YOLOR/utils/datasets.py b/PyTorch/contrib/cv/detection/YOLOR/utils/datasets.py index 8b9be1318b11a9df6d296db65f848da03d5ab3f2..35b509d37e4c88f7e707a69459fffea3e5b5033d 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/utils/datasets.py +++ b/PyTorch/contrib/cv/detection/YOLOR/utils/datasets.py @@ -1,1311 +1,1311 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Dataset utils and dataloaders - -import glob -import math -import os -import random -import shutil -import time -from itertools import repeat -from multiprocessing.pool import ThreadPool -from pathlib import Path -from threading import Thread - -import cv2 -import numpy as np -import torch -from PIL import Image, ExifTags -from torch.utils.data import Dataset -from tqdm import tqdm - -import pickle -from copy import deepcopy -from pycocotools import mask as maskUtils -from torchvision.utils import save_image - -from utils.general import xyxy2xywh, xywh2xyxy -from utils.torch_utils import torch_distributed_zero_first - -# Parameters -help_url = 'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data' -img_formats = ['bmp', 'jpg', 'jpeg', 'png', 'tif', 'tiff', 'dng'] # acceptable image suffixes -vid_formats = ['mov', 'avi', 'mp4', 'mpg', 'mpeg', 'm4v', 'wmv', 'mkv'] # acceptable video suffixes - -# Get orientation exif tag -for orientation in ExifTags.TAGS.keys(): - if ExifTags.TAGS[orientation] == 'Orientation': - break - - -def get_hash(files): - # Returns a single hash value of a list of files - return sum(os.path.getsize(f) for f in files if os.path.isfile(f)) - - -def exif_size(img): - # Returns exif-corrected PIL size - s = img.size # (width, height) - try: - rotation = dict(img._getexif().items())[orientation] - if rotation == 6: # rotation 270 - s = (s[1], s[0]) - elif rotation == 8: # rotation 90 - s = (s[1], s[0]) - except: - pass - - return s - - -def create_dataloader(path, imgsz, batch_size, stride, opt, hyp=None, augment=False, cache=False, pad=0.0, rect=False, - rank=-1, world_size=1, workers=8): - # Make sure only the first process in DDP process the dataset first, and the following others can use the cache - with torch_distributed_zero_first(rank): - dataset = LoadImagesAndLabels(path, imgsz, batch_size, - augment=augment, # augment images - hyp=hyp, # augmentation hyperparameters - rect=rect, # rectangular training - cache_images=cache, - single_cls=opt.single_cls, - stride=int(stride), - pad=pad, - rank=rank) - - batch_size = min(batch_size, len(dataset)) - nw = min([os.cpu_count() // world_size, batch_size if batch_size > 1 else 0, workers]) # number of workers - sampler = torch.utils.data.distributed.DistributedSampler(dataset) if rank != -1 else None - dataloader = InfiniteDataLoader(dataset, - batch_size=batch_size, - num_workers=nw, - sampler=sampler, - pin_memory=True, - collate_fn=LoadImagesAndLabels.collate_fn) # torch.utils.data.DataLoader() - return dataloader, dataset - - -def create_dataloader9(path, imgsz, batch_size, stride, opt, hyp=None, augment=False, cache=False, pad=0.0, rect=False, - rank=-1, world_size=1, workers=8): - # Make sure only the first process in DDP process the dataset first, and the following others can use the cache - with torch_distributed_zero_first(rank): - dataset = LoadImagesAndLabels9(path, imgsz, batch_size, - augment=augment, # augment images - hyp=hyp, # augmentation hyperparameters - rect=rect, # rectangular training - cache_images=cache, - single_cls=opt.single_cls, - stride=int(stride), - pad=pad, - rank=rank) - - batch_size = min(batch_size, len(dataset)) - nw = min([os.cpu_count() // world_size, batch_size if batch_size > 1 else 0, workers]) # number of workers - sampler = torch.utils.data.distributed.DistributedSampler(dataset) if rank != -1 else None - dataloader = InfiniteDataLoader(dataset, - batch_size=batch_size, - num_workers=nw, - sampler=sampler, - pin_memory=True, - collate_fn=LoadImagesAndLabels9.collate_fn) # torch.utils.data.DataLoader() - return dataloader, dataset - - -class InfiniteDataLoader(torch.utils.data.dataloader.DataLoader): - """ Dataloader that reuses workers - - Uses same syntax as vanilla DataLoader - """ - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - object.__setattr__(self, 'batch_sampler', _RepeatSampler(self.batch_sampler)) - self.iterator = super().__iter__() - - def __len__(self): - return len(self.batch_sampler.sampler) - - def __iter__(self): - for i in range(len(self)): - yield next(self.iterator) - - -class _RepeatSampler(object): - """ Sampler that repeats forever - - Args: - sampler (Sampler) - """ - - def __init__(self, sampler): - self.sampler = sampler - - def __iter__(self): - while True: - yield from iter(self.sampler) - - -class LoadImages: # for inference - def __init__(self, path, img_size=640, auto_size=32): - p = str(Path(path)) # os-agnostic - p = os.path.abspath(p) # absolute path - if '*' in p: - files = sorted(glob.glob(p, recursive=True)) # glob - elif os.path.isdir(p): - files = sorted(glob.glob(os.path.join(p, '*.*'))) # dir - elif os.path.isfile(p): - files = [p] # files - else: - raise Exception('ERROR: %s does not exist' % p) - - images = [x for x in files if x.split('.')[-1].lower() in img_formats] - videos = [x for x in files if x.split('.')[-1].lower() in vid_formats] - ni, nv = len(images), len(videos) - - self.img_size = img_size - self.auto_size = auto_size - self.files = images + videos - self.nf = ni + nv # number of files - self.video_flag = [False] * ni + [True] * nv - self.mode = 'images' - if any(videos): - self.new_video(videos[0]) # new video - else: - self.cap = None - assert self.nf > 0, 'No images or videos found in %s. Supported formats are:\nimages: %s\nvideos: %s' % \ - (p, img_formats, vid_formats) - - def __iter__(self): - self.count = 0 - return self - - def __next__(self): - if self.count == self.nf: - raise StopIteration - path = self.files[self.count] - - if self.video_flag[self.count]: - # Read video - self.mode = 'video' - ret_val, img0 = self.cap.read() - if not ret_val: - self.count += 1 - self.cap.release() - if self.count == self.nf: # last video - raise StopIteration - else: - path = self.files[self.count] - self.new_video(path) - ret_val, img0 = self.cap.read() - - self.frame += 1 - print('video %g/%g (%g/%g) %s: ' % (self.count + 1, self.nf, self.frame, self.nframes, path), end='') - - else: - # Read image - self.count += 1 - img0 = cv2.imread(path) # BGR - assert img0 is not None, 'Image Not Found ' + path - print('image %g/%g %s: ' % (self.count, self.nf, path), end='') - - # Padded resize - img = letterbox(img0, new_shape=self.img_size, auto_size=self.auto_size)[0] - - # Convert - img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x416x416 - img = np.ascontiguousarray(img) - - return path, img, img0, self.cap - - def new_video(self, path): - self.frame = 0 - self.cap = cv2.VideoCapture(path) - self.nframes = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT)) - - def __len__(self): - return self.nf # number of files - - -class LoadWebcam: # for inference - def __init__(self, pipe='0', img_size=640): - self.img_size = img_size - - if pipe.isnumeric(): - pipe = eval(pipe) # local camera - # pipe = 'rtsp://192.168.1.64/1' # IP camera - # pipe = 'rtsp://username:password@192.168.1.64/1' # IP camera with login - # pipe = 'http://wmccpinetop.axiscam.net/mjpg/video.mjpg' # IP golf camera - - self.pipe = pipe - self.cap = cv2.VideoCapture(pipe) # video capture object - self.cap.set(cv2.CAP_PROP_BUFFERSIZE, 3) # set buffer size - - def __iter__(self): - self.count = -1 - return self - - def __next__(self): - self.count += 1 - if cv2.waitKey(1) == ord('q'): # q to quit - self.cap.release() - cv2.destroyAllWindows() - raise StopIteration - - # Read frame - if self.pipe == 0: # local camera - ret_val, img0 = self.cap.read() - img0 = cv2.flip(img0, 1) # flip left-right - else: # IP camera - n = 0 - while True: - n += 1 - self.cap.grab() - if n % 30 == 0: # skip frames - ret_val, img0 = self.cap.retrieve() - if ret_val: - break - - # Print - assert ret_val, 'Camera Error %s' % self.pipe - img_path = 'webcam.jpg' - print('webcam %g: ' % self.count, end='') - - # Padded resize - img = letterbox(img0, new_shape=self.img_size)[0] - - # Convert - img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x416x416 - img = np.ascontiguousarray(img) - - return img_path, img, img0, None - - def __len__(self): - return 0 - - -class LoadStreams: # multiple IP or RTSP cameras - def __init__(self, sources='streams.txt', img_size=640): - self.mode = 'images' - self.img_size = img_size - - if os.path.isfile(sources): - with open(sources, 'r') as f: - sources = [x.strip() for x in f.read().splitlines() if len(x.strip())] - else: - sources = [sources] - - n = len(sources) - self.imgs = [None] * n - self.sources = sources - for i, s in enumerate(sources): - # Start the thread to read frames from the video stream - print('%g/%g: %s... ' % (i + 1, n, s), end='') - cap = cv2.VideoCapture(eval(s) if s.isnumeric() else s) - assert cap.isOpened(), 'Failed to open %s' % s - w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) - h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) - fps = cap.get(cv2.CAP_PROP_FPS) % 100 - _, self.imgs[i] = cap.read() # guarantee first frame - thread = Thread(target=self.update, args=([i, cap]), daemon=True) - print(' success (%gx%g at %.2f FPS).' % (w, h, fps)) - thread.start() - print('') # newline - - # check for common shapes - s = np.stack([letterbox(x, new_shape=self.img_size)[0].shape for x in self.imgs], 0) # inference shapes - self.rect = np.unique(s, axis=0).shape[0] == 1 # rect inference if all shapes equal - if not self.rect: - print('WARNING: Different stream shapes detected. For optimal performance supply similarly-shaped streams.') - - def update(self, index, cap): - # Read next stream frame in a daemon thread - n = 0 - while cap.isOpened(): - n += 1 - # _, self.imgs[index] = cap.read() - cap.grab() - if n == 4: # read every 4th frame - _, self.imgs[index] = cap.retrieve() - n = 0 - time.sleep(0.01) # wait time - - def __iter__(self): - self.count = -1 - return self - - def __next__(self): - self.count += 1 - img0 = self.imgs.copy() - if cv2.waitKey(1) == ord('q'): # q to quit - cv2.destroyAllWindows() - raise StopIteration - - # Letterbox - img = [letterbox(x, new_shape=self.img_size, auto=self.rect)[0] for x in img0] - - # Stack - img = np.stack(img, 0) - - # Convert - img = img[:, :, :, ::-1].transpose(0, 3, 1, 2) # BGR to RGB, to bsx3x416x416 - img = np.ascontiguousarray(img) - - return self.sources, img, img0, None - - def __len__(self): - return 0 # 1E12 frames = 32 streams at 30 FPS for 30 years - - -class LoadImagesAndLabels(Dataset): # for training/testing - def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, rect=False, image_weights=False, - cache_images=False, single_cls=False, stride=32, pad=0.0, rank=-1): - self.img_size = img_size - self.augment = augment - self.hyp = hyp - self.image_weights = image_weights - self.rect = False if image_weights else rect - self.mosaic = self.augment and not self.rect # load 4 images at a time into a mosaic (only during training) - self.mosaic_border = [-img_size // 2, -img_size // 2] - self.stride = stride - - def img2label_paths(img_paths): - # Define label paths as a function of image paths - sa, sb = os.sep + 'images' + os.sep, os.sep + 'labels' + os.sep # /images/, /labels/ substrings - return [x.replace(sa, sb, 1).replace(x.split('.')[-1], 'txt') for x in img_paths] - - try: - f = [] # image files - for p in path if isinstance(path, list) else [path]: - p = Path(p) # os-agnostic - if p.is_dir(): # dir - f += glob.glob(str(p / '**' / '*.*'), recursive=True) - elif p.is_file(): # file - with open(p, 'r') as t: - t = t.read().splitlines() - parent = str(p.parent) + os.sep - f += [x.replace('./', parent) if x.startswith('./') else x for x in t] # local to global path - else: - raise Exception('%s does not exist' % p) - self.img_files = sorted([x.replace('/', os.sep) for x in f if x.split('.')[-1].lower() in img_formats]) - assert self.img_files, 'No images found' - except Exception as e: - raise Exception('Error loading data from %s: %s\nSee %s' % (path, e, help_url)) - - # Check cache - self.label_files = img2label_paths(self.img_files) # labels - cache_path = str(Path(self.label_files[0]).parent) + '.cache3' # cached labels - if os.path.isfile(cache_path): - cache = torch.load(cache_path) # load - if cache['hash'] != get_hash(self.label_files + self.img_files): # dataset changed - cache = self.cache_labels(cache_path) # re-cache - else: - cache = self.cache_labels(cache_path) # cache - - # Read cache - cache.pop('hash') # remove hash - labels, shapes = zip(*cache.values()) - self.labels = list(labels) - self.shapes = np.array(shapes, dtype=np.float64) - self.img_files = list(cache.keys()) # update - self.label_files = img2label_paths(cache.keys()) # update - - n = len(shapes) # number of images - bi = np.floor(np.arange(n) / batch_size).astype(np.int) # batch index - nb = bi[-1] + 1 # number of batches - self.batch = bi # batch index of image - self.n = n - - # Rectangular Training - if self.rect: - # Sort by aspect ratio - s = self.shapes # wh - ar = s[:, 1] / s[:, 0] # aspect ratio - irect = ar.argsort() - self.img_files = [self.img_files[i] for i in irect] - self.label_files = [self.label_files[i] for i in irect] - self.labels = [self.labels[i] for i in irect] - self.shapes = s[irect] # wh - ar = ar[irect] - - # Set training image shapes - shapes = [[1, 1]] * nb - for i in range(nb): - ari = ar[bi == i] - mini, maxi = ari.min(), ari.max() - if maxi < 1: - shapes[i] = [maxi, 1] - elif mini > 1: - shapes[i] = [1, 1 / mini] - - self.batch_shapes = np.ceil(np.array(shapes) * img_size / stride + pad).astype(np.int) * stride - - # Check labels - create_datasubset, extract_bounding_boxes, labels_loaded = False, False, False - nm, nf, ne, ns, nd = 0, 0, 0, 0, 0 # number missing, found, empty, datasubset, duplicate - pbar = enumerate(self.label_files) - if rank in [-1, 0]: - pbar = tqdm(pbar) - for i, file in pbar: - l = self.labels[i] # label - if l is not None and l.shape[0]: - assert l.shape[1] == 5, '> 5 label columns: %s' % file - assert (l >= 0).all(), 'negative labels: %s' % file - assert (l[:, 1:] <= 1).all(), 'non-normalized or out of bounds coordinate labels: %s' % file - if np.unique(l, axis=0).shape[0] < l.shape[0]: # duplicate rows - nd += 1 # print('WARNING: duplicate rows in %s' % self.label_files[i]) # duplicate rows - if single_cls: - l[:, 0] = 0 # force dataset into single-class mode - self.labels[i] = l - nf += 1 # file found - - # Create subdataset (a smaller dataset) - if create_datasubset and ns < 1E4: - if ns == 0: - create_folder(path='./datasubset') - os.makedirs('./datasubset/images') - exclude_classes = 43 - if exclude_classes not in l[:, 0]: - ns += 1 - # shutil.copy(src=self.img_files[i], dst='./datasubset/images/') # copy image - with open('./datasubset/images.txt', 'a') as f: - f.write(self.img_files[i] + '\n') - - # Extract object detection boxes for a second stage classifier - if extract_bounding_boxes: - p = Path(self.img_files[i]) - img = cv2.imread(str(p)) - h, w = img.shape[:2] - for j, x in enumerate(l): - f = '%s%sclassifier%s%g_%g_%s' % (p.parent.parent, os.sep, os.sep, x[0], j, p.name) - if not os.path.exists(Path(f).parent): - os.makedirs(Path(f).parent) # make new output folder - - b = x[1:] * [w, h, w, h] # box - b[2:] = b[2:].max() # rectangle to square - b[2:] = b[2:] * 1.3 + 30 # pad - b = xywh2xyxy(b.reshape(-1, 4)).ravel().astype(np.int) - - b[[0, 2]] = np.clip(b[[0, 2]], 0, w) # clip boxes outside of image - b[[1, 3]] = np.clip(b[[1, 3]], 0, h) - assert cv2.imwrite(f, img[b[1]:b[3], b[0]:b[2]]), 'Failure extracting classifier boxes' - else: - ne += 1 # print('empty labels for image %s' % self.img_files[i]) # file empty - # os.system("rm '%s' '%s'" % (self.img_files[i], self.label_files[i])) # remove - - if rank in [-1, 0]: - pbar.desc = 'Scanning labels %s (%g found, %g missing, %g empty, %g duplicate, for %g images)' % ( - cache_path, nf, nm, ne, nd, n) - if nf == 0: - s = 'WARNING: No labels found in %s. See %s' % (os.path.dirname(file) + os.sep, help_url) - print(s) - assert not augment, '%s. Can not train without labels.' % s - - # Cache images into memory for faster training (WARNING: large datasets may exceed system RAM) - self.imgs = [None] * n - if cache_images: - gb = 0 # Gigabytes of cached images - self.img_hw0, self.img_hw = [None] * n, [None] * n - results = ThreadPool(8).imap(lambda x: load_image(*x), zip(repeat(self), range(n))) # 8 threads - pbar = tqdm(enumerate(results), total=n) - for i, x in pbar: - self.imgs[i], self.img_hw0[i], self.img_hw[i] = x # img, hw_original, hw_resized = load_image(self, i) - gb += self.imgs[i].nbytes - pbar.desc = 'Caching images (%.1fGB)' % (gb / 1E9) - - def cache_labels(self, path='labels.cache3'): - # Cache dataset labels, check images and read shapes - x = {} # dict - pbar = tqdm(zip(self.img_files, self.label_files), desc='Scanning images', total=len(self.img_files)) - for (img, label) in pbar: - try: - l = [] - im = Image.open(img) - im.verify() # PIL verify - shape = exif_size(im) # image size - assert (shape[0] > 9) & (shape[1] > 9), 'image size <10 pixels' - if os.path.isfile(label): - with open(label, 'r') as f: - l = np.array([x.split() for x in f.read().splitlines()], dtype=np.float32) # labels - if len(l) == 0: - l = np.zeros((0, 5), dtype=np.float32) - x[img] = [l, shape] - except Exception as e: - print('WARNING: Ignoring corrupted image and/or label %s: %s' % (img, e)) - - x['hash'] = get_hash(self.label_files + self.img_files) - torch.save(x, path) # save for next time - return x - - def __len__(self): - return len(self.img_files) - - # def __iter__(self): - # self.count = -1 - # print('ran dataset iter') - # #self.shuffled_vector = np.random.permutation(self.nF) if self.augment else np.arange(self.nF) - # return self - - def __getitem__(self, index): - if self.image_weights: - index = self.indices[index] - - hyp = self.hyp - mosaic = self.mosaic and random.random() < hyp['mosaic'] - if mosaic: - # Load mosaic - img, labels = load_mosaic(self, index) - #img, labels = load_mosaic9(self, index) - shapes = None - - # MixUp https://arxiv.org/pdf/1710.09412.pdf - if random.random() < hyp['mixup']: - img2, labels2 = load_mosaic(self, random.randint(0, len(self.labels) - 1)) - #img2, labels2 = load_mosaic9(self, random.randint(0, len(self.labels) - 1)) - r = np.random.beta(8.0, 8.0) # mixup ratio, alpha=beta=8.0 - img = (img * r + img2 * (1 - r)).astype(np.uint8) - labels = np.concatenate((labels, labels2), 0) - - else: - # Load image - img, (h0, w0), (h, w) = load_image(self, index) - - # Letterbox - shape = self.batch_shapes[self.batch[index]] if self.rect else self.img_size # final letterboxed shape - img, ratio, pad = letterbox(img, shape, auto=False, scaleup=self.augment) - shapes = (h0, w0), ((h / h0, w / w0), pad) # for COCO mAP rescaling - - # Load labels - labels = [] - x = self.labels[index] - if x.size > 0: - # Normalized xywh to pixel xyxy format - labels = x.copy() - labels[:, 1] = ratio[0] * w * (x[:, 1] - x[:, 3] / 2) + pad[0] # pad width - labels[:, 2] = ratio[1] * h * (x[:, 2] - x[:, 4] / 2) + pad[1] # pad height - labels[:, 3] = ratio[0] * w * (x[:, 1] + x[:, 3] / 2) + pad[0] - labels[:, 4] = ratio[1] * h * (x[:, 2] + x[:, 4] / 2) + pad[1] - - if self.augment: - # Augment imagespace - if not mosaic: - img, labels = random_perspective(img, labels, - degrees=hyp['degrees'], - translate=hyp['translate'], - scale=hyp['scale'], - shear=hyp['shear'], - perspective=hyp['perspective']) - - # Augment colorspace - augment_hsv(img, hgain=hyp['hsv_h'], sgain=hyp['hsv_s'], vgain=hyp['hsv_v']) - - # Apply cutouts - # if random.random() < 0.9: - # labels = cutout(img, labels) - - nL = len(labels) # number of labels - if nL: - labels[:, 1:5] = xyxy2xywh(labels[:, 1:5]) # convert xyxy to xywh - labels[:, [2, 4]] /= img.shape[0] # normalized height 0-1 - labels[:, [1, 3]] /= img.shape[1] # normalized width 0-1 - - if self.augment: - # flip up-down - if random.random() < hyp['flipud']: - img = np.flipud(img) - if nL: - labels[:, 2] = 1 - labels[:, 2] - - # flip left-right - if random.random() < hyp['fliplr']: - img = np.fliplr(img) - if nL: - labels[:, 1] = 1 - labels[:, 1] - - labels_out = torch.zeros((nL, 6)) - if nL: - labels_out[:, 1:] = torch.from_numpy(labels) - - # Convert - img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x416x416 - img = np.ascontiguousarray(img) - - return torch.from_numpy(img), labels_out, self.img_files[index], shapes - - @staticmethod - def collate_fn(batch): - img, label, path, shapes = zip(*batch) # transposed - for i, l in enumerate(label): - l[:, 0] = i # add target image index for build_targets() - return torch.stack(img, 0), torch.cat(label, 0), path, shapes - - -class LoadImagesAndLabels9(Dataset): # for training/testing - def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, rect=False, image_weights=False, - cache_images=False, single_cls=False, stride=32, pad=0.0, rank=-1): - self.img_size = img_size - self.augment = augment - self.hyp = hyp - self.image_weights = image_weights - self.rect = False if image_weights else rect - self.mosaic = self.augment and not self.rect # load 4 images at a time into a mosaic (only during training) - self.mosaic_border = [-img_size // 2, -img_size // 2] - self.stride = stride - - def img2label_paths(img_paths): - # Define label paths as a function of image paths - sa, sb = os.sep + 'images' + os.sep, os.sep + 'labels' + os.sep # /images/, /labels/ substrings - return [x.replace(sa, sb, 1).replace(x.split('.')[-1], 'txt') for x in img_paths] - - try: - f = [] # image files - for p in path if isinstance(path, list) else [path]: - p = Path(p) # os-agnostic - if p.is_dir(): # dir - f += glob.glob(str(p / '**' / '*.*'), recursive=True) - elif p.is_file(): # file - with open(p, 'r') as t: - t = t.read().splitlines() - parent = str(p.parent) + os.sep - f += [x.replace('./', parent) if x.startswith('./') else x for x in t] # local to global path - else: - raise Exception('%s does not exist' % p) - self.img_files = sorted([x.replace('/', os.sep) for x in f if x.split('.')[-1].lower() in img_formats]) - assert self.img_files, 'No images found' - except Exception as e: - raise Exception('Error loading data from %s: %s\nSee %s' % (path, e, help_url)) - - # Check cache - self.label_files = img2label_paths(self.img_files) # labels - cache_path = str(Path(self.label_files[0]).parent) + '.cache3' # cached labels - if os.path.isfile(cache_path): - cache = torch.load(cache_path) # load - if cache['hash'] != get_hash(self.label_files + self.img_files): # dataset changed - cache = self.cache_labels(cache_path) # re-cache - else: - cache = self.cache_labels(cache_path) # cache - - # Read cache - cache.pop('hash') # remove hash - labels, shapes = zip(*cache.values()) - self.labels = list(labels) - self.shapes = np.array(shapes, dtype=np.float64) - self.img_files = list(cache.keys()) # update - self.label_files = img2label_paths(cache.keys()) # update - - n = len(shapes) # number of images - bi = np.floor(np.arange(n) / batch_size).astype(np.int) # batch index - nb = bi[-1] + 1 # number of batches - self.batch = bi # batch index of image - self.n = n - - # Rectangular Training - if self.rect: - # Sort by aspect ratio - s = self.shapes # wh - ar = s[:, 1] / s[:, 0] # aspect ratio - irect = ar.argsort() - self.img_files = [self.img_files[i] for i in irect] - self.label_files = [self.label_files[i] for i in irect] - self.labels = [self.labels[i] for i in irect] - self.shapes = s[irect] # wh - ar = ar[irect] - - # Set training image shapes - shapes = [[1, 1]] * nb - for i in range(nb): - ari = ar[bi == i] - mini, maxi = ari.min(), ari.max() - if maxi < 1: - shapes[i] = [maxi, 1] - elif mini > 1: - shapes[i] = [1, 1 / mini] - - self.batch_shapes = np.ceil(np.array(shapes) * img_size / stride + pad).astype(np.int) * stride - - # Check labels - create_datasubset, extract_bounding_boxes, labels_loaded = False, False, False - nm, nf, ne, ns, nd = 0, 0, 0, 0, 0 # number missing, found, empty, datasubset, duplicate - pbar = enumerate(self.label_files) - if rank in [-1, 0]: - pbar = tqdm(pbar) - for i, file in pbar: - l = self.labels[i] # label - if l is not None and l.shape[0]: - assert l.shape[1] == 5, '> 5 label columns: %s' % file - assert (l >= 0).all(), 'negative labels: %s' % file - assert (l[:, 1:] <= 1).all(), 'non-normalized or out of bounds coordinate labels: %s' % file - if np.unique(l, axis=0).shape[0] < l.shape[0]: # duplicate rows - nd += 1 # print('WARNING: duplicate rows in %s' % self.label_files[i]) # duplicate rows - if single_cls: - l[:, 0] = 0 # force dataset into single-class mode - self.labels[i] = l - nf += 1 # file found - - # Create subdataset (a smaller dataset) - if create_datasubset and ns < 1E4: - if ns == 0: - create_folder(path='./datasubset') - os.makedirs('./datasubset/images') - exclude_classes = 43 - if exclude_classes not in l[:, 0]: - ns += 1 - # shutil.copy(src=self.img_files[i], dst='./datasubset/images/') # copy image - with open('./datasubset/images.txt', 'a') as f: - f.write(self.img_files[i] + '\n') - - # Extract object detection boxes for a second stage classifier - if extract_bounding_boxes: - p = Path(self.img_files[i]) - img = cv2.imread(str(p)) - h, w = img.shape[:2] - for j, x in enumerate(l): - f = '%s%sclassifier%s%g_%g_%s' % (p.parent.parent, os.sep, os.sep, x[0], j, p.name) - if not os.path.exists(Path(f).parent): - os.makedirs(Path(f).parent) # make new output folder - - b = x[1:] * [w, h, w, h] # box - b[2:] = b[2:].max() # rectangle to square - b[2:] = b[2:] * 1.3 + 30 # pad - b = xywh2xyxy(b.reshape(-1, 4)).ravel().astype(np.int) - - b[[0, 2]] = np.clip(b[[0, 2]], 0, w) # clip boxes outside of image - b[[1, 3]] = np.clip(b[[1, 3]], 0, h) - assert cv2.imwrite(f, img[b[1]:b[3], b[0]:b[2]]), 'Failure extracting classifier boxes' - else: - ne += 1 # print('empty labels for image %s' % self.img_files[i]) # file empty - # os.system("rm '%s' '%s'" % (self.img_files[i], self.label_files[i])) # remove - - if rank in [-1, 0]: - pbar.desc = 'Scanning labels %s (%g found, %g missing, %g empty, %g duplicate, for %g images)' % ( - cache_path, nf, nm, ne, nd, n) - if nf == 0: - s = 'WARNING: No labels found in %s. See %s' % (os.path.dirname(file) + os.sep, help_url) - print(s) - assert not augment, '%s. Can not train without labels.' % s - - # Cache images into memory for faster training (WARNING: large datasets may exceed system RAM) - self.imgs = [None] * n - if cache_images: - gb = 0 # Gigabytes of cached images - self.img_hw0, self.img_hw = [None] * n, [None] * n - results = ThreadPool(8).imap(lambda x: load_image(*x), zip(repeat(self), range(n))) # 8 threads - pbar = tqdm(enumerate(results), total=n) - for i, x in pbar: - self.imgs[i], self.img_hw0[i], self.img_hw[i] = x # img, hw_original, hw_resized = load_image(self, i) - gb += self.imgs[i].nbytes - pbar.desc = 'Caching images (%.1fGB)' % (gb / 1E9) - - def cache_labels(self, path='labels.cache3'): - # Cache dataset labels, check images and read shapes - x = {} # dict - pbar = tqdm(zip(self.img_files, self.label_files), desc='Scanning images', total=len(self.img_files)) - for (img, label) in pbar: - try: - l = [] - im = Image.open(img) - im.verify() # PIL verify - shape = exif_size(im) # image size - assert (shape[0] > 9) & (shape[1] > 9), 'image size <10 pixels' - if os.path.isfile(label): - with open(label, 'r') as f: - l = np.array([x.split() for x in f.read().splitlines()], dtype=np.float32) # labels - if len(l) == 0: - l = np.zeros((0, 5), dtype=np.float32) - x[img] = [l, shape] - except Exception as e: - print('WARNING: Ignoring corrupted image and/or label %s: %s' % (img, e)) - - x['hash'] = get_hash(self.label_files + self.img_files) - torch.save(x, path) # save for next time - return x - - def __len__(self): - return len(self.img_files) - - # def __iter__(self): - # self.count = -1 - # print('ran dataset iter') - # #self.shuffled_vector = np.random.permutation(self.nF) if self.augment else np.arange(self.nF) - # return self - - def __getitem__(self, index): - if self.image_weights: - index = self.indices[index] - - hyp = self.hyp - mosaic = self.mosaic and random.random() < hyp['mosaic'] - if mosaic: - # Load mosaic - #img, labels = load_mosaic(self, index) - img, labels = load_mosaic9(self, index) - shapes = None - - # MixUp https://arxiv.org/pdf/1710.09412.pdf - if random.random() < hyp['mixup']: - #img2, labels2 = load_mosaic(self, random.randint(0, len(self.labels) - 1)) - img2, labels2 = load_mosaic9(self, random.randint(0, len(self.labels) - 1)) - r = np.random.beta(8.0, 8.0) # mixup ratio, alpha=beta=8.0 - img = (img * r + img2 * (1 - r)).astype(np.uint8) - labels = np.concatenate((labels, labels2), 0) - - else: - # Load image - img, (h0, w0), (h, w) = load_image(self, index) - - # Letterbox - shape = self.batch_shapes[self.batch[index]] if self.rect else self.img_size # final letterboxed shape - img, ratio, pad = letterbox(img, shape, auto=False, scaleup=self.augment) - shapes = (h0, w0), ((h / h0, w / w0), pad) # for COCO mAP rescaling - - # Load labels - labels = [] - x = self.labels[index] - if x.size > 0: - # Normalized xywh to pixel xyxy format - labels = x.copy() - labels[:, 1] = ratio[0] * w * (x[:, 1] - x[:, 3] / 2) + pad[0] # pad width - labels[:, 2] = ratio[1] * h * (x[:, 2] - x[:, 4] / 2) + pad[1] # pad height - labels[:, 3] = ratio[0] * w * (x[:, 1] + x[:, 3] / 2) + pad[0] - labels[:, 4] = ratio[1] * h * (x[:, 2] + x[:, 4] / 2) + pad[1] - - if self.augment: - # Augment imagespace - if not mosaic: - img, labels = random_perspective(img, labels, - degrees=hyp['degrees'], - translate=hyp['translate'], - scale=hyp['scale'], - shear=hyp['shear'], - perspective=hyp['perspective']) - - # Augment colorspace - augment_hsv(img, hgain=hyp['hsv_h'], sgain=hyp['hsv_s'], vgain=hyp['hsv_v']) - - # Apply cutouts - # if random.random() < 0.9: - # labels = cutout(img, labels) - - nL = len(labels) # number of labels - if nL: - labels[:, 1:5] = xyxy2xywh(labels[:, 1:5]) # convert xyxy to xywh - labels[:, [2, 4]] /= img.shape[0] # normalized height 0-1 - labels[:, [1, 3]] /= img.shape[1] # normalized width 0-1 - - if self.augment: - # flip up-down - if random.random() < hyp['flipud']: - img = np.flipud(img) - if nL: - labels[:, 2] = 1 - labels[:, 2] - - # flip left-right - if random.random() < hyp['fliplr']: - img = np.fliplr(img) - if nL: - labels[:, 1] = 1 - labels[:, 1] - - labels_out = torch.zeros((nL, 6)) - if nL: - labels_out[:, 1:] = torch.from_numpy(labels) - - # Convert - img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x416x416 - img = np.ascontiguousarray(img) - - return torch.from_numpy(img), labels_out, self.img_files[index], shapes - - @staticmethod - def collate_fn(batch): - img, label, path, shapes = zip(*batch) # transposed - for i, l in enumerate(label): - l[:, 0] = i # add target image index for build_targets() - return torch.stack(img, 0), torch.cat(label, 0), path, shapes - - -# Ancillary functions -------------------------------------------------------------------------------------------------- -def load_image(self, index): - # loads 1 image from dataset, returns img, original hw, resized hw - img = self.imgs[index] - if img is None: # not cached - path = self.img_files[index] - img = cv2.imread(path) # BGR - assert img is not None, 'Image Not Found ' + path - h0, w0 = img.shape[:2] # orig hw - r = self.img_size / max(h0, w0) # resize image to img_size - if r != 1: # always resize down, only resize up if training with augmentation - interp = cv2.INTER_AREA if r < 1 and not self.augment else cv2.INTER_LINEAR - img = cv2.resize(img, (int(w0 * r), int(h0 * r)), interpolation=interp) - return img, (h0, w0), img.shape[:2] # img, hw_original, hw_resized - else: - return self.imgs[index], self.img_hw0[index], self.img_hw[index] # img, hw_original, hw_resized - - -def augment_hsv(img, hgain=0.5, sgain=0.5, vgain=0.5): - r = np.random.uniform(-1, 1, 3) * [hgain, sgain, vgain] + 1 # random gains - hue, sat, val = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV)) - dtype = img.dtype # uint8 - - x = np.arange(0, 256, dtype=np.int16) - lut_hue = ((x * r[0]) % 180).astype(dtype) - lut_sat = np.clip(x * r[1], 0, 255).astype(dtype) - lut_val = np.clip(x * r[2], 0, 255).astype(dtype) - - img_hsv = cv2.merge((cv2.LUT(hue, lut_hue), cv2.LUT(sat, lut_sat), cv2.LUT(val, lut_val))).astype(dtype) - cv2.cvtColor(img_hsv, cv2.COLOR_HSV2BGR, dst=img) # no return needed - - # Histogram equalization - # if random.random() < 0.2: - # for i in range(3): - # img[:, :, i] = cv2.equalizeHist(img[:, :, i]) - - -def load_mosaic(self, index): - # loads images in a mosaic - - labels4 = [] - s = self.img_size - yc, xc = [int(random.uniform(-x, 2 * s + x)) for x in self.mosaic_border] # mosaic center x, y - indices = [index] + [random.randint(0, len(self.labels) - 1) for _ in range(3)] # 3 additional image indices - for i, index in enumerate(indices): - # Load image - img, _, (h, w) = load_image(self, index) - - # place img in img4 - if i == 0: # top left - img4 = np.full((s * 2, s * 2, img.shape[2]), 114, dtype=np.uint8) # base image with 4 tiles - x1a, y1a, x2a, y2a = max(xc - w, 0), max(yc - h, 0), xc, yc # xmin, ymin, xmax, ymax (large image) - x1b, y1b, x2b, y2b = w - (x2a - x1a), h - (y2a - y1a), w, h # xmin, ymin, xmax, ymax (small image) - elif i == 1: # top right - x1a, y1a, x2a, y2a = xc, max(yc - h, 0), min(xc + w, s * 2), yc - x1b, y1b, x2b, y2b = 0, h - (y2a - y1a), min(w, x2a - x1a), h - elif i == 2: # bottom left - x1a, y1a, x2a, y2a = max(xc - w, 0), yc, xc, min(s * 2, yc + h) - x1b, y1b, x2b, y2b = w - (x2a - x1a), 0, w, min(y2a - y1a, h) - elif i == 3: # bottom right - x1a, y1a, x2a, y2a = xc, yc, min(xc + w, s * 2), min(s * 2, yc + h) - x1b, y1b, x2b, y2b = 0, 0, min(w, x2a - x1a), min(y2a - y1a, h) - - img4[y1a:y2a, x1a:x2a] = img[y1b:y2b, x1b:x2b] # img4[ymin:ymax, xmin:xmax] - padw = x1a - x1b - padh = y1a - y1b - - # Labels - x = self.labels[index] - labels = x.copy() - if x.size > 0: # Normalized xywh to pixel xyxy format - labels[:, 1] = w * (x[:, 1] - x[:, 3] / 2) + padw - labels[:, 2] = h * (x[:, 2] - x[:, 4] / 2) + padh - labels[:, 3] = w * (x[:, 1] + x[:, 3] / 2) + padw - labels[:, 4] = h * (x[:, 2] + x[:, 4] / 2) + padh - labels4.append(labels) - - # Concat/clip labels - if len(labels4): - labels4 = np.concatenate(labels4, 0) - np.clip(labels4[:, 1:], 0, 2 * s, out=labels4[:, 1:]) # use with random_perspective - # img4, labels4 = replicate(img4, labels4) # replicate - - # Augment - img4, labels4 = random_perspective(img4, labels4, - degrees=self.hyp['degrees'], - translate=self.hyp['translate'], - scale=self.hyp['scale'], - shear=self.hyp['shear'], - perspective=self.hyp['perspective'], - border=self.mosaic_border) # border to remove - - return img4, labels4 - - -def load_mosaic9(self, index): - # loads images in a 9-mosaic - - labels9 = [] - s = self.img_size - indices = [index] + [random.randint(0, len(self.labels) - 1) for _ in range(8)] # 8 additional image indices - for i, index in enumerate(indices): - # Load image - img, _, (h, w) = load_image(self, index) - - # place img in img9 - if i == 0: # center - img9 = np.full((s * 3, s * 3, img.shape[2]), 114, dtype=np.uint8) # base image with 4 tiles - h0, w0 = h, w - c = s, s, s + w, s + h # xmin, ymin, xmax, ymax (base) coordinates - elif i == 1: # top - c = s, s - h, s + w, s - elif i == 2: # top right - c = s + wp, s - h, s + wp + w, s - elif i == 3: # right - c = s + w0, s, s + w0 + w, s + h - elif i == 4: # bottom right - c = s + w0, s + hp, s + w0 + w, s + hp + h - elif i == 5: # bottom - c = s + w0 - w, s + h0, s + w0, s + h0 + h - elif i == 6: # bottom left - c = s + w0 - wp - w, s + h0, s + w0 - wp, s + h0 + h - elif i == 7: # left - c = s - w, s + h0 - h, s, s + h0 - elif i == 8: # top left - c = s - w, s + h0 - hp - h, s, s + h0 - hp - - padx, pady = c[:2] - x1, y1, x2, y2 = [max(x, 0) for x in c] # allocate coords - - # Labels - x = self.labels[index] - labels = x.copy() - if x.size > 0: # Normalized xywh to pixel xyxy format - labels[:, 1] = w * (x[:, 1] - x[:, 3] / 2) + padx - labels[:, 2] = h * (x[:, 2] - x[:, 4] / 2) + pady - labels[:, 3] = w * (x[:, 1] + x[:, 3] / 2) + padx - labels[:, 4] = h * (x[:, 2] + x[:, 4] / 2) + pady - labels9.append(labels) - - # Image - img9[y1:y2, x1:x2] = img[y1 - pady:, x1 - padx:] # img9[ymin:ymax, xmin:xmax] - hp, wp = h, w # height, width previous - - # Offset - yc, xc = [int(random.uniform(0, s)) for x in self.mosaic_border] # mosaic center x, y - img9 = img9[yc:yc + 2 * s, xc:xc + 2 * s] - - # Concat/clip labels - if len(labels9): - labels9 = np.concatenate(labels9, 0) - labels9[:, [1, 3]] -= xc - labels9[:, [2, 4]] -= yc - - np.clip(labels9[:, 1:], 0, 2 * s, out=labels9[:, 1:]) # use with random_perspective - # img9, labels9 = replicate(img9, labels9) # replicate - - # Augment - img9, labels9 = random_perspective(img9, labels9, - degrees=self.hyp['degrees'], - translate=self.hyp['translate'], - scale=self.hyp['scale'], - shear=self.hyp['shear'], - perspective=self.hyp['perspective'], - border=self.mosaic_border) # border to remove - - return img9, labels9 - - -def replicate(img, labels): - # Replicate labels - h, w = img.shape[:2] - boxes = labels[:, 1:].astype(int) - x1, y1, x2, y2 = boxes.T - s = ((x2 - x1) + (y2 - y1)) / 2 # side length (pixels) - for i in s.argsort()[:round(s.size * 0.5)]: # smallest indices - x1b, y1b, x2b, y2b = boxes[i] - bh, bw = y2b - y1b, x2b - x1b - yc, xc = int(random.uniform(0, h - bh)), int(random.uniform(0, w - bw)) # offset x, y - x1a, y1a, x2a, y2a = [xc, yc, xc + bw, yc + bh] - img[y1a:y2a, x1a:x2a] = img[y1b:y2b, x1b:x2b] # img4[ymin:ymax, xmin:xmax] - labels = np.append(labels, [[labels[i, 0], x1a, y1a, x2a, y2a]], axis=0) - - return img, labels - - -def letterbox(img, new_shape=(640, 640), color=(114, 114, 114), auto=True, scaleFill=False, scaleup=True, auto_size=32): - # Resize image to a 32-pixel-multiple rectangle https://github.com/ultralytics/yolov3/issues/232 - shape = img.shape[:2] # current shape [height, width] - if isinstance(new_shape, int): - new_shape = (new_shape, new_shape) - - # Scale ratio (new / old) - r = min(new_shape[0] / shape[0], new_shape[1] / shape[1]) - if not scaleup: # only scale down, do not scale up (for better test mAP) - r = min(r, 1.0) - - # Compute padding - ratio = r, r # width, height ratios - new_unpad = int(round(shape[1] * r)), int(round(shape[0] * r)) - dw, dh = new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1] # wh padding - if auto: # minimum rectangle - dw, dh = np.mod(dw, auto_size), np.mod(dh, auto_size) # wh padding - elif scaleFill: # stretch - dw, dh = 0.0, 0.0 - new_unpad = (new_shape[1], new_shape[0]) - ratio = new_shape[1] / shape[1], new_shape[0] / shape[0] # width, height ratios - - dw /= 2 # divide padding into 2 sides - dh /= 2 - - if shape[::-1] != new_unpad: # resize - img = cv2.resize(img, new_unpad, interpolation=cv2.INTER_LINEAR) - top, bottom = int(round(dh - 0.1)), int(round(dh + 0.1)) - left, right = int(round(dw - 0.1)), int(round(dw + 0.1)) - img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color) # add border - return img, ratio, (dw, dh) - - -def random_perspective(img, targets=(), degrees=10, translate=.1, scale=.1, shear=10, perspective=0.0, border=(0, 0)): - # torchvision.transforms.RandomAffine(degrees=(-10, 10), translate=(.1, .1), scale=(.9, 1.1), shear=(-10, 10)) - # targets = [cls, xyxy] - - height = img.shape[0] + border[0] * 2 # shape(h,w,c) - width = img.shape[1] + border[1] * 2 - - # Center - C = np.eye(3) - C[0, 2] = -img.shape[1] / 2 # x translation (pixels) - C[1, 2] = -img.shape[0] / 2 # y translation (pixels) - - # Perspective - P = np.eye(3) - P[2, 0] = random.uniform(-perspective, perspective) # x perspective (about y) - P[2, 1] = random.uniform(-perspective, perspective) # y perspective (about x) - - # Rotation and Scale - R = np.eye(3) - a = random.uniform(-degrees, degrees) - # a += random.choice([-180, -90, 0, 90]) # add 90deg rotations to small rotations - s = random.uniform(1 - scale, 1 + scale) - # s = 2 ** random.uniform(-scale, scale) - R[:2] = cv2.getRotationMatrix2D(angle=a, center=(0, 0), scale=s) - - # Shear - S = np.eye(3) - S[0, 1] = math.tan(random.uniform(-shear, shear) * math.pi / 180) # x shear (deg) - S[1, 0] = math.tan(random.uniform(-shear, shear) * math.pi / 180) # y shear (deg) - - # Translation - T = np.eye(3) - T[0, 2] = random.uniform(0.5 - translate, 0.5 + translate) * width # x translation (pixels) - T[1, 2] = random.uniform(0.5 - translate, 0.5 + translate) * height # y translation (pixels) - - # Combined rotation matrix - M = T @ S @ R @ P @ C # order of operations (right to left) is IMPORTANT - if (border[0] != 0) or (border[1] != 0) or (M != np.eye(3)).any(): # image changed - if perspective: - img = cv2.warpPerspective(img, M, dsize=(width, height), borderValue=(114, 114, 114)) - else: # affine - img = cv2.warpAffine(img, M[:2], dsize=(width, height), borderValue=(114, 114, 114)) - - # Visualize - # import matplotlib.pyplot as plt - # ax = plt.subplots(1, 2, figsize=(12, 6))[1].ravel() - # ax[0].imshow(img[:, :, ::-1]) # base - # ax[1].imshow(img2[:, :, ::-1]) # warped - - # Transform label coordinates - n = len(targets) - if n: - # warp points - xy = np.ones((n * 4, 3)) - xy[:, :2] = targets[:, [1, 2, 3, 4, 1, 4, 3, 2]].reshape(n * 4, 2) # x1y1, x2y2, x1y2, x2y1 - xy = xy @ M.T # transform - if perspective: - xy = (xy[:, :2] / xy[:, 2:3]).reshape(n, 8) # rescale - else: # affine - xy = xy[:, :2].reshape(n, 8) - - # create new boxes - x = xy[:, [0, 2, 4, 6]] - y = xy[:, [1, 3, 5, 7]] - xy = np.concatenate((x.min(1), y.min(1), x.max(1), y.max(1))).reshape(4, n).T - - # # apply angle-based reduction of bounding boxes - # radians = a * math.pi / 180 - # reduction = max(abs(math.sin(radians)), abs(math.cos(radians))) ** 0.5 - # x = (xy[:, 2] + xy[:, 0]) / 2 - # y = (xy[:, 3] + xy[:, 1]) / 2 - # w = (xy[:, 2] - xy[:, 0]) * reduction - # h = (xy[:, 3] - xy[:, 1]) * reduction - # xy = np.concatenate((x - w / 2, y - h / 2, x + w / 2, y + h / 2)).reshape(4, n).T - - # clip boxes - xy[:, [0, 2]] = xy[:, [0, 2]].clip(0, width) - xy[:, [1, 3]] = xy[:, [1, 3]].clip(0, height) - - # filter candidates - i = box_candidates(box1=targets[:, 1:5].T * s, box2=xy.T) - targets = targets[i] - targets[:, 1:5] = xy[i] - - return img, targets - - -def box_candidates(box1, box2, wh_thr=2, ar_thr=20, area_thr=0.1): # box1(4,n), box2(4,n) - # Compute candidate boxes: box1 before augment, box2 after augment, wh_thr (pixels), aspect_ratio_thr, area_ratio - w1, h1 = box1[2] - box1[0], box1[3] - box1[1] - w2, h2 = box2[2] - box2[0], box2[3] - box2[1] - ar = np.maximum(w2 / (h2 + 1e-16), h2 / (w2 + 1e-16)) # aspect ratio - return (w2 > wh_thr) & (h2 > wh_thr) & (w2 * h2 / (w1 * h1 + 1e-16) > area_thr) & (ar < ar_thr) # candidates - - -def cutout(image, labels): - # Applies image cutout augmentation https://arxiv.org/abs/1708.04552 - h, w = image.shape[:2] - - def bbox_ioa(box1, box2): - # Returns the intersection over box2 area given box1, box2. box1 is 4, box2 is nx4. boxes are x1y1x2y2 - box2 = box2.transpose() - - # Get the coordinates of bounding boxes - b1_x1, b1_y1, b1_x2, b1_y2 = box1[0], box1[1], box1[2], box1[3] - b2_x1, b2_y1, b2_x2, b2_y2 = box2[0], box2[1], box2[2], box2[3] - - # Intersection area - inter_area = (np.minimum(b1_x2, b2_x2) - np.maximum(b1_x1, b2_x1)).clip(0) * \ - (np.minimum(b1_y2, b2_y2) - np.maximum(b1_y1, b2_y1)).clip(0) - - # box2 area - box2_area = (b2_x2 - b2_x1) * (b2_y2 - b2_y1) + 1e-16 - - # Intersection over box2 area - return inter_area / box2_area - - # create random masks - scales = [0.5] * 1 + [0.25] * 2 + [0.125] * 4 + [0.0625] * 8 + [0.03125] * 16 # image size fraction - for s in scales: - mask_h = random.randint(1, int(h * s)) - mask_w = random.randint(1, int(w * s)) - - # box - xmin = max(0, random.randint(0, w) - mask_w // 2) - ymin = max(0, random.randint(0, h) - mask_h // 2) - xmax = min(w, xmin + mask_w) - ymax = min(h, ymin + mask_h) - - # apply random color mask - image[ymin:ymax, xmin:xmax] = [random.randint(64, 191) for _ in range(3)] - - # return unobscured labels - if len(labels) and s > 0.03: - box = np.array([xmin, ymin, xmax, ymax], dtype=np.float32) - ioa = bbox_ioa(box, labels[:, 1:5]) # intersection over area - labels = labels[ioa < 0.60] # remove >60% obscured labels - - return labels - - -def create_folder(path='./new'): - # Create folder - if os.path.exists(path): - shutil.rmtree(path) # delete output folder - os.makedirs(path) # make new output folder - - -def flatten_recursive(path='../coco128'): - # Flatten a recursive directory by bringing all files to top level - new_path = Path(path + '_flat') - create_folder(new_path) - for file in tqdm(glob.glob(str(Path(path)) + '/**/*.*', recursive=True)): - shutil.copyfile(file, new_path / Path(file).name) - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Dataset utils and dataloaders + +import glob +import math +import os +import random +import shutil +import time +from itertools import repeat +from multiprocessing.pool import ThreadPool +from pathlib import Path +from threading import Thread + +import cv2 +import numpy as np +import torch +from PIL import Image, ExifTags +from torch.utils.data import Dataset +from tqdm import tqdm + +import pickle +from copy import deepcopy +from pycocotools import mask as maskUtils +from torchvision.utils import save_image + +from utils.general import xyxy2xywh, xywh2xyxy +from utils.torch_utils import torch_distributed_zero_first + +# Parameters +help_url = 'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data' +img_formats = ['bmp', 'jpg', 'jpeg', 'png', 'tif', 'tiff', 'dng'] # acceptable image suffixes +vid_formats = ['mov', 'avi', 'mp4', 'mpg', 'mpeg', 'm4v', 'wmv', 'mkv'] # acceptable video suffixes + +# Get orientation exif tag +for orientation in ExifTags.TAGS.keys(): + if ExifTags.TAGS[orientation] == 'Orientation': + break + + +def get_hash(files): + # Returns a single hash value of a list of files + return sum(os.path.getsize(f) for f in files if os.path.isfile(f)) + + +def exif_size(img): + # Returns exif-corrected PIL size + s = img.size # (width, height) + try: + rotation = dict(img._getexif().items())[orientation] + if rotation == 6: # rotation 270 + s = (s[1], s[0]) + elif rotation == 8: # rotation 90 + s = (s[1], s[0]) + except: + pass + + return s + + +def create_dataloader(path, imgsz, batch_size, stride, opt, hyp=None, augment=False, cache=False, pad=0.0, rect=False, + rank=-1, world_size=1, workers=8): + # Make sure only the first process in DDP process the dataset first, and the following others can use the cache + with torch_distributed_zero_first(rank): + dataset = LoadImagesAndLabels(path, imgsz, batch_size, + augment=augment, # augment images + hyp=hyp, # augmentation hyperparameters + rect=rect, # rectangular training + cache_images=cache, + single_cls=opt.single_cls, + stride=int(stride), + pad=pad, + rank=rank) + + batch_size = min(batch_size, len(dataset)) + nw = min([os.cpu_count() // world_size, batch_size if batch_size > 1 else 0, workers]) # number of workers + sampler = torch.utils.data.distributed.DistributedSampler(dataset) if rank != -1 else None + dataloader = InfiniteDataLoader(dataset, + batch_size=batch_size, + num_workers=nw, + sampler=sampler, + pin_memory=True, + collate_fn=LoadImagesAndLabels.collate_fn) # torch.utils.data.DataLoader() + return dataloader, dataset + + +def create_dataloader9(path, imgsz, batch_size, stride, opt, hyp=None, augment=False, cache=False, pad=0.0, rect=False, + rank=-1, world_size=1, workers=8): + # Make sure only the first process in DDP process the dataset first, and the following others can use the cache + with torch_distributed_zero_first(rank): + dataset = LoadImagesAndLabels9(path, imgsz, batch_size, + augment=augment, # augment images + hyp=hyp, # augmentation hyperparameters + rect=rect, # rectangular training + cache_images=cache, + single_cls=opt.single_cls, + stride=int(stride), + pad=pad, + rank=rank) + + batch_size = min(batch_size, len(dataset)) + nw = min([os.cpu_count() // world_size, batch_size if batch_size > 1 else 0, workers]) # number of workers + sampler = torch.utils.data.distributed.DistributedSampler(dataset) if rank != -1 else None + dataloader = InfiniteDataLoader(dataset, + batch_size=batch_size, + num_workers=nw, + sampler=sampler, + pin_memory=True, + collate_fn=LoadImagesAndLabels9.collate_fn) # torch.utils.data.DataLoader() + return dataloader, dataset + + +class InfiniteDataLoader(torch.utils.data.dataloader.DataLoader): + """ Dataloader that reuses workers + + Uses same syntax as vanilla DataLoader + """ + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + object.__setattr__(self, 'batch_sampler', _RepeatSampler(self.batch_sampler)) + self.iterator = super().__iter__() + + def __len__(self): + return len(self.batch_sampler.sampler) + + def __iter__(self): + for i in range(len(self)): + yield next(self.iterator) + + +class _RepeatSampler(object): + """ Sampler that repeats forever + + Args: + sampler (Sampler) + """ + + def __init__(self, sampler): + self.sampler = sampler + + def __iter__(self): + while True: + yield from iter(self.sampler) + + +class LoadImages: # for inference + def __init__(self, path, img_size=640, auto_size=32): + p = str(Path(path)) # os-agnostic + p = os.path.abspath(p) # absolute path + if '*' in p: + files = sorted(glob.glob(p, recursive=True)) # glob + elif os.path.isdir(p): + files = sorted(glob.glob(os.path.join(p, '*.*'))) # dir + elif os.path.isfile(p): + files = [p] # files + else: + raise Exception('ERROR: %s does not exist' % p) + + images = [x for x in files if x.split('.')[-1].lower() in img_formats] + videos = [x for x in files if x.split('.')[-1].lower() in vid_formats] + ni, nv = len(images), len(videos) + + self.img_size = img_size + self.auto_size = auto_size + self.files = images + videos + self.nf = ni + nv # number of files + self.video_flag = [False] * ni + [True] * nv + self.mode = 'images' + if any(videos): + self.new_video(videos[0]) # new video + else: + self.cap = None + assert self.nf > 0, 'No images or videos found in %s. Supported formats are:\nimages: %s\nvideos: %s' % \ + (p, img_formats, vid_formats) + + def __iter__(self): + self.count = 0 + return self + + def __next__(self): + if self.count == self.nf: + raise StopIteration + path = self.files[self.count] + + if self.video_flag[self.count]: + # Read video + self.mode = 'video' + ret_val, img0 = self.cap.read() + if not ret_val: + self.count += 1 + self.cap.release() + if self.count == self.nf: # last video + raise StopIteration + else: + path = self.files[self.count] + self.new_video(path) + ret_val, img0 = self.cap.read() + + self.frame += 1 + print('video %g/%g (%g/%g) %s: ' % (self.count + 1, self.nf, self.frame, self.nframes, path), end='') + + else: + # Read image + self.count += 1 + img0 = cv2.imread(path) # BGR + assert img0 is not None, 'Image Not Found ' + path + print('image %g/%g %s: ' % (self.count, self.nf, path), end='') + + # Padded resize + img = letterbox(img0, new_shape=self.img_size, auto_size=self.auto_size)[0] + + # Convert + img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x416x416 + img = np.ascontiguousarray(img) + + return path, img, img0, self.cap + + def new_video(self, path): + self.frame = 0 + self.cap = cv2.VideoCapture(path) + self.nframes = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT)) + + def __len__(self): + return self.nf # number of files + + +class LoadWebcam: # for inference + def __init__(self, pipe='0', img_size=640): + self.img_size = img_size + + if pipe.isnumeric(): + pipe = eval(pipe) # local camera + # pipe = 'rtsp://192.168.1.64/1' # IP camera + # pipe = 'rtsp://username:password@192.168.1.64/1' # IP camera with login + # pipe = 'http://wmccpinetop.axiscam.net/mjpg/video.mjpg' # IP golf camera + + self.pipe = pipe + self.cap = cv2.VideoCapture(pipe) # video capture object + self.cap.set(cv2.CAP_PROP_BUFFERSIZE, 3) # set buffer size + + def __iter__(self): + self.count = -1 + return self + + def __next__(self): + self.count += 1 + if cv2.waitKey(1) == ord('q'): # q to quit + self.cap.release() + cv2.destroyAllWindows() + raise StopIteration + + # Read frame + if self.pipe == 0: # local camera + ret_val, img0 = self.cap.read() + img0 = cv2.flip(img0, 1) # flip left-right + else: # IP camera + n = 0 + while True: + n += 1 + self.cap.grab() + if n % 30 == 0: # skip frames + ret_val, img0 = self.cap.retrieve() + if ret_val: + break + + # Print + assert ret_val, 'Camera Error %s' % self.pipe + img_path = 'webcam.jpg' + print('webcam %g: ' % self.count, end='') + + # Padded resize + img = letterbox(img0, new_shape=self.img_size)[0] + + # Convert + img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x416x416 + img = np.ascontiguousarray(img) + + return img_path, img, img0, None + + def __len__(self): + return 0 + + +class LoadStreams: # multiple IP or RTSP cameras + def __init__(self, sources='streams.txt', img_size=640): + self.mode = 'images' + self.img_size = img_size + + if os.path.isfile(sources): + with open(sources, 'r') as f: + sources = [x.strip() for x in f.read().splitlines() if len(x.strip())] + else: + sources = [sources] + + n = len(sources) + self.imgs = [None] * n + self.sources = sources + for i, s in enumerate(sources): + # Start the thread to read frames from the video stream + print('%g/%g: %s... ' % (i + 1, n, s), end='') + cap = cv2.VideoCapture(eval(s) if s.isnumeric() else s) + assert cap.isOpened(), 'Failed to open %s' % s + w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) + h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) + fps = cap.get(cv2.CAP_PROP_FPS) % 100 + _, self.imgs[i] = cap.read() # guarantee first frame + thread = Thread(target=self.update, args=([i, cap]), daemon=True) + print(' success (%gx%g at %.2f FPS).' % (w, h, fps)) + thread.start() + print('') # newline + + # check for common shapes + s = np.stack([letterbox(x, new_shape=self.img_size)[0].shape for x in self.imgs], 0) # inference shapes + self.rect = np.unique(s, axis=0).shape[0] == 1 # rect inference if all shapes equal + if not self.rect: + print('WARNING: Different stream shapes detected. For optimal performance supply similarly-shaped streams.') + + def update(self, index, cap): + # Read next stream frame in a daemon thread + n = 0 + while cap.isOpened(): + n += 1 + # _, self.imgs[index] = cap.read() + cap.grab() + if n == 4: # read every 4th frame + _, self.imgs[index] = cap.retrieve() + n = 0 + time.sleep(0.01) # wait time + + def __iter__(self): + self.count = -1 + return self + + def __next__(self): + self.count += 1 + img0 = self.imgs.copy() + if cv2.waitKey(1) == ord('q'): # q to quit + cv2.destroyAllWindows() + raise StopIteration + + # Letterbox + img = [letterbox(x, new_shape=self.img_size, auto=self.rect)[0] for x in img0] + + # Stack + img = np.stack(img, 0) + + # Convert + img = img[:, :, :, ::-1].transpose(0, 3, 1, 2) # BGR to RGB, to bsx3x416x416 + img = np.ascontiguousarray(img) + + return self.sources, img, img0, None + + def __len__(self): + return 0 # 1E12 frames = 32 streams at 30 FPS for 30 years + + +class LoadImagesAndLabels(Dataset): # for training/testing + def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, rect=False, image_weights=False, + cache_images=False, single_cls=False, stride=32, pad=0.0, rank=-1): + self.img_size = img_size + self.augment = augment + self.hyp = hyp + self.image_weights = image_weights + self.rect = False if image_weights else rect + self.mosaic = self.augment and not self.rect # load 4 images at a time into a mosaic (only during training) + self.mosaic_border = [-img_size // 2, -img_size // 2] + self.stride = stride + + def img2label_paths(img_paths): + # Define label paths as a function of image paths + sa, sb = os.sep + 'images' + os.sep, os.sep + 'labels' + os.sep # /images/, /labels/ substrings + return [x.replace(sa, sb, 1).replace(x.split('.')[-1], 'txt') for x in img_paths] + + try: + f = [] # image files + for p in path if isinstance(path, list) else [path]: + p = Path(p) # os-agnostic + if p.is_dir(): # dir + f += glob.glob(str(p / '**' / '*.*'), recursive=True) + elif p.is_file(): # file + with open(p, 'r') as t: + t = t.read().splitlines() + parent = str(p.parent) + os.sep + f += [x.replace('./', parent) if x.startswith('./') else x for x in t] # local to global path + else: + raise Exception('%s does not exist' % p) + self.img_files = sorted([x.replace('/', os.sep) for x in f if x.split('.')[-1].lower() in img_formats]) + assert self.img_files, 'No images found' + except Exception as e: + raise Exception('Error loading data from %s: %s\nSee %s' % (path, e, help_url)) + + # Check cache + self.label_files = img2label_paths(self.img_files) # labels + cache_path = str(Path(self.label_files[0]).parent) + '.cache3' # cached labels + if os.path.isfile(cache_path): + cache = torch.load(cache_path) # load + if cache['hash'] != get_hash(self.label_files + self.img_files): # dataset changed + cache = self.cache_labels(cache_path) # re-cache + else: + cache = self.cache_labels(cache_path) # cache + + # Read cache + cache.pop('hash') # remove hash + labels, shapes = zip(*cache.values()) + self.labels = list(labels) + self.shapes = np.array(shapes, dtype=np.float64) + self.img_files = list(cache.keys()) # update + self.label_files = img2label_paths(cache.keys()) # update + + n = len(shapes) # number of images + bi = np.floor(np.arange(n) / batch_size).astype(np.int) # batch index + nb = bi[-1] + 1 # number of batches + self.batch = bi # batch index of image + self.n = n + + # Rectangular Training + if self.rect: + # Sort by aspect ratio + s = self.shapes # wh + ar = s[:, 1] / s[:, 0] # aspect ratio + irect = ar.argsort() + self.img_files = [self.img_files[i] for i in irect] + self.label_files = [self.label_files[i] for i in irect] + self.labels = [self.labels[i] for i in irect] + self.shapes = s[irect] # wh + ar = ar[irect] + + # Set training image shapes + shapes = [[1, 1]] * nb + for i in range(nb): + ari = ar[bi == i] + mini, maxi = ari.min(), ari.max() + if maxi < 1: + shapes[i] = [maxi, 1] + elif mini > 1: + shapes[i] = [1, 1 / mini] + + self.batch_shapes = np.ceil(np.array(shapes) * img_size / stride + pad).astype(np.int) * stride + + # Check labels + create_datasubset, extract_bounding_boxes, labels_loaded = False, False, False + nm, nf, ne, ns, nd = 0, 0, 0, 0, 0 # number missing, found, empty, datasubset, duplicate + pbar = enumerate(self.label_files) + if rank in [-1, 0]: + pbar = tqdm(pbar) + for i, file in pbar: + l = self.labels[i] # label + if l is not None and l.shape[0]: + assert l.shape[1] == 5, '> 5 label columns: %s' % file + assert (l >= 0).all(), 'negative labels: %s' % file + assert (l[:, 1:] <= 1).all(), 'non-normalized or out of bounds coordinate labels: %s' % file + if np.unique(l, axis=0).shape[0] < l.shape[0]: # duplicate rows + nd += 1 # print('WARNING: duplicate rows in %s' % self.label_files[i]) # duplicate rows + if single_cls: + l[:, 0] = 0 # force dataset into single-class mode + self.labels[i] = l + nf += 1 # file found + + # Create subdataset (a smaller dataset) + if create_datasubset and ns < 1E4: + if ns == 0: + create_folder(path='./datasubset') + os.makedirs('./datasubset/images') + exclude_classes = 43 + if exclude_classes not in l[:, 0]: + ns += 1 + # shutil.copy(src=self.img_files[i], dst='./datasubset/images/') # copy image + with open('./datasubset/images.txt', 'a') as f: + f.write(self.img_files[i] + '\n') + + # Extract object detection boxes for a second stage classifier + if extract_bounding_boxes: + p = Path(self.img_files[i]) + img = cv2.imread(str(p)) + h, w = img.shape[:2] + for j, x in enumerate(l): + f = '%s%sclassifier%s%g_%g_%s' % (p.parent.parent, os.sep, os.sep, x[0], j, p.name) + if not os.path.exists(Path(f).parent): + os.makedirs(Path(f).parent) # make new output folder + + b = x[1:] * [w, h, w, h] # box + b[2:] = b[2:].max() # rectangle to square + b[2:] = b[2:] * 1.3 + 30 # pad + b = xywh2xyxy(b.reshape(-1, 4)).ravel().astype(np.int) + + b[[0, 2]] = np.clip(b[[0, 2]], 0, w) # clip boxes outside of image + b[[1, 3]] = np.clip(b[[1, 3]], 0, h) + assert cv2.imwrite(f, img[b[1]:b[3], b[0]:b[2]]), 'Failure extracting classifier boxes' + else: + ne += 1 # print('empty labels for image %s' % self.img_files[i]) # file empty + # os.system("rm '%s' '%s'" % (self.img_files[i], self.label_files[i])) # remove + + if rank in [-1, 0]: + pbar.desc = 'Scanning labels %s (%g found, %g missing, %g empty, %g duplicate, for %g images)' % ( + cache_path, nf, nm, ne, nd, n) + if nf == 0: + s = 'WARNING: No labels found in %s. See %s' % (os.path.dirname(file) + os.sep, help_url) + print(s) + assert not augment, '%s. Can not train without labels.' % s + + # Cache images into memory for faster training (WARNING: large datasets may exceed system RAM) + self.imgs = [None] * n + if cache_images: + gb = 0 # Gigabytes of cached images + self.img_hw0, self.img_hw = [None] * n, [None] * n + results = ThreadPool(8).imap(lambda x: load_image(*x), zip(repeat(self), range(n))) # 8 threads + pbar = tqdm(enumerate(results), total=n) + for i, x in pbar: + self.imgs[i], self.img_hw0[i], self.img_hw[i] = x # img, hw_original, hw_resized = load_image(self, i) + gb += self.imgs[i].nbytes + pbar.desc = 'Caching images (%.1fGB)' % (gb / 1E9) + + def cache_labels(self, path='labels.cache3'): + # Cache dataset labels, check images and read shapes + x = {} # dict + pbar = tqdm(zip(self.img_files, self.label_files), desc='Scanning images', total=len(self.img_files)) + for (img, label) in pbar: + try: + l = [] + im = Image.open(img) + im.verify() # PIL verify + shape = exif_size(im) # image size + assert (shape[0] > 9) & (shape[1] > 9), 'image size <10 pixels' + if os.path.isfile(label): + with open(label, 'r') as f: + l = np.array([x.split() for x in f.read().splitlines()], dtype=np.float32) # labels + if len(l) == 0: + l = np.zeros((0, 5), dtype=np.float32) + x[img] = [l, shape] + except Exception as e: + print('WARNING: Ignoring corrupted image and/or label %s: %s' % (img, e)) + + x['hash'] = get_hash(self.label_files + self.img_files) + torch.save(x, path) # save for next time + return x + + def __len__(self): + return len(self.img_files) + + # def __iter__(self): + # self.count = -1 + # print('ran dataset iter') + # #self.shuffled_vector = np.random.permutation(self.nF) if self.augment else np.arange(self.nF) + # return self + + def __getitem__(self, index): + if self.image_weights: + index = self.indices[index] + + hyp = self.hyp + mosaic = self.mosaic and random.random() < hyp['mosaic'] + if mosaic: + # Load mosaic + img, labels = load_mosaic(self, index) + #img, labels = load_mosaic9(self, index) + shapes = None + + # MixUp https://arxiv.org/pdf/1710.09412.pdf + if random.random() < hyp['mixup']: + img2, labels2 = load_mosaic(self, random.randint(0, len(self.labels) - 1)) + #img2, labels2 = load_mosaic9(self, random.randint(0, len(self.labels) - 1)) + r = np.random.beta(8.0, 8.0) # mixup ratio, alpha=beta=8.0 + img = (img * r + img2 * (1 - r)).astype(np.uint8) + labels = np.concatenate((labels, labels2), 0) + + else: + # Load image + img, (h0, w0), (h, w) = load_image(self, index) + + # Letterbox + shape = self.batch_shapes[self.batch[index]] if self.rect else self.img_size # final letterboxed shape + img, ratio, pad = letterbox(img, shape, auto=False, scaleup=self.augment) + shapes = (h0, w0), ((h / h0, w / w0), pad) # for COCO mAP rescaling + + # Load labels + labels = [] + x = self.labels[index] + if x.size > 0: + # Normalized xywh to pixel xyxy format + labels = x.copy() + labels[:, 1] = ratio[0] * w * (x[:, 1] - x[:, 3] / 2) + pad[0] # pad width + labels[:, 2] = ratio[1] * h * (x[:, 2] - x[:, 4] / 2) + pad[1] # pad height + labels[:, 3] = ratio[0] * w * (x[:, 1] + x[:, 3] / 2) + pad[0] + labels[:, 4] = ratio[1] * h * (x[:, 2] + x[:, 4] / 2) + pad[1] + + if self.augment: + # Augment imagespace + if not mosaic: + img, labels = random_perspective(img, labels, + degrees=hyp['degrees'], + translate=hyp['translate'], + scale=hyp['scale'], + shear=hyp['shear'], + perspective=hyp['perspective']) + + # Augment colorspace + augment_hsv(img, hgain=hyp['hsv_h'], sgain=hyp['hsv_s'], vgain=hyp['hsv_v']) + + # Apply cutouts + # if random.random() < 0.9: + # labels = cutout(img, labels) + + nL = len(labels) # number of labels + if nL: + labels[:, 1:5] = xyxy2xywh(labels[:, 1:5]) # convert xyxy to xywh + labels[:, [2, 4]] /= img.shape[0] # normalized height 0-1 + labels[:, [1, 3]] /= img.shape[1] # normalized width 0-1 + + if self.augment: + # flip up-down + if random.random() < hyp['flipud']: + img = np.flipud(img) + if nL: + labels[:, 2] = 1 - labels[:, 2] + + # flip left-right + if random.random() < hyp['fliplr']: + img = np.fliplr(img) + if nL: + labels[:, 1] = 1 - labels[:, 1] + + labels_out = torch.zeros((nL, 6)) + if nL: + labels_out[:, 1:] = torch.from_numpy(labels) + + # Convert + img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x416x416 + img = np.ascontiguousarray(img) + + return torch.from_numpy(img), labels_out, self.img_files[index], shapes + + @staticmethod + def collate_fn(batch): + img, label, path, shapes = zip(*batch) # transposed + for i, l in enumerate(label): + l[:, 0] = i # add target image index for build_targets() + return torch.stack(img, 0), torch.cat(label, 0), path, shapes + + +class LoadImagesAndLabels9(Dataset): # for training/testing + def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, rect=False, image_weights=False, + cache_images=False, single_cls=False, stride=32, pad=0.0, rank=-1): + self.img_size = img_size + self.augment = augment + self.hyp = hyp + self.image_weights = image_weights + self.rect = False if image_weights else rect + self.mosaic = self.augment and not self.rect # load 4 images at a time into a mosaic (only during training) + self.mosaic_border = [-img_size // 2, -img_size // 2] + self.stride = stride + + def img2label_paths(img_paths): + # Define label paths as a function of image paths + sa, sb = os.sep + 'images' + os.sep, os.sep + 'labels' + os.sep # /images/, /labels/ substrings + return [x.replace(sa, sb, 1).replace(x.split('.')[-1], 'txt') for x in img_paths] + + try: + f = [] # image files + for p in path if isinstance(path, list) else [path]: + p = Path(p) # os-agnostic + if p.is_dir(): # dir + f += glob.glob(str(p / '**' / '*.*'), recursive=True) + elif p.is_file(): # file + with open(p, 'r') as t: + t = t.read().splitlines() + parent = str(p.parent) + os.sep + f += [x.replace('./', parent) if x.startswith('./') else x for x in t] # local to global path + else: + raise Exception('%s does not exist' % p) + self.img_files = sorted([x.replace('/', os.sep) for x in f if x.split('.')[-1].lower() in img_formats]) + assert self.img_files, 'No images found' + except Exception as e: + raise Exception('Error loading data from %s: %s\nSee %s' % (path, e, help_url)) + + # Check cache + self.label_files = img2label_paths(self.img_files) # labels + cache_path = str(Path(self.label_files[0]).parent) + '.cache3' # cached labels + if os.path.isfile(cache_path): + cache = torch.load(cache_path) # load + if cache['hash'] != get_hash(self.label_files + self.img_files): # dataset changed + cache = self.cache_labels(cache_path) # re-cache + else: + cache = self.cache_labels(cache_path) # cache + + # Read cache + cache.pop('hash') # remove hash + labels, shapes = zip(*cache.values()) + self.labels = list(labels) + self.shapes = np.array(shapes, dtype=np.float64) + self.img_files = list(cache.keys()) # update + self.label_files = img2label_paths(cache.keys()) # update + + n = len(shapes) # number of images + bi = np.floor(np.arange(n) / batch_size).astype(np.int) # batch index + nb = bi[-1] + 1 # number of batches + self.batch = bi # batch index of image + self.n = n + + # Rectangular Training + if self.rect: + # Sort by aspect ratio + s = self.shapes # wh + ar = s[:, 1] / s[:, 0] # aspect ratio + irect = ar.argsort() + self.img_files = [self.img_files[i] for i in irect] + self.label_files = [self.label_files[i] for i in irect] + self.labels = [self.labels[i] for i in irect] + self.shapes = s[irect] # wh + ar = ar[irect] + + # Set training image shapes + shapes = [[1, 1]] * nb + for i in range(nb): + ari = ar[bi == i] + mini, maxi = ari.min(), ari.max() + if maxi < 1: + shapes[i] = [maxi, 1] + elif mini > 1: + shapes[i] = [1, 1 / mini] + + self.batch_shapes = np.ceil(np.array(shapes) * img_size / stride + pad).astype(np.int) * stride + + # Check labels + create_datasubset, extract_bounding_boxes, labels_loaded = False, False, False + nm, nf, ne, ns, nd = 0, 0, 0, 0, 0 # number missing, found, empty, datasubset, duplicate + pbar = enumerate(self.label_files) + if rank in [-1, 0]: + pbar = tqdm(pbar) + for i, file in pbar: + l = self.labels[i] # label + if l is not None and l.shape[0]: + assert l.shape[1] == 5, '> 5 label columns: %s' % file + assert (l >= 0).all(), 'negative labels: %s' % file + assert (l[:, 1:] <= 1).all(), 'non-normalized or out of bounds coordinate labels: %s' % file + if np.unique(l, axis=0).shape[0] < l.shape[0]: # duplicate rows + nd += 1 # print('WARNING: duplicate rows in %s' % self.label_files[i]) # duplicate rows + if single_cls: + l[:, 0] = 0 # force dataset into single-class mode + self.labels[i] = l + nf += 1 # file found + + # Create subdataset (a smaller dataset) + if create_datasubset and ns < 1E4: + if ns == 0: + create_folder(path='./datasubset') + os.makedirs('./datasubset/images') + exclude_classes = 43 + if exclude_classes not in l[:, 0]: + ns += 1 + # shutil.copy(src=self.img_files[i], dst='./datasubset/images/') # copy image + with open('./datasubset/images.txt', 'a') as f: + f.write(self.img_files[i] + '\n') + + # Extract object detection boxes for a second stage classifier + if extract_bounding_boxes: + p = Path(self.img_files[i]) + img = cv2.imread(str(p)) + h, w = img.shape[:2] + for j, x in enumerate(l): + f = '%s%sclassifier%s%g_%g_%s' % (p.parent.parent, os.sep, os.sep, x[0], j, p.name) + if not os.path.exists(Path(f).parent): + os.makedirs(Path(f).parent) # make new output folder + + b = x[1:] * [w, h, w, h] # box + b[2:] = b[2:].max() # rectangle to square + b[2:] = b[2:] * 1.3 + 30 # pad + b = xywh2xyxy(b.reshape(-1, 4)).ravel().astype(np.int) + + b[[0, 2]] = np.clip(b[[0, 2]], 0, w) # clip boxes outside of image + b[[1, 3]] = np.clip(b[[1, 3]], 0, h) + assert cv2.imwrite(f, img[b[1]:b[3], b[0]:b[2]]), 'Failure extracting classifier boxes' + else: + ne += 1 # print('empty labels for image %s' % self.img_files[i]) # file empty + # os.system("rm '%s' '%s'" % (self.img_files[i], self.label_files[i])) # remove + + if rank in [-1, 0]: + pbar.desc = 'Scanning labels %s (%g found, %g missing, %g empty, %g duplicate, for %g images)' % ( + cache_path, nf, nm, ne, nd, n) + if nf == 0: + s = 'WARNING: No labels found in %s. See %s' % (os.path.dirname(file) + os.sep, help_url) + print(s) + assert not augment, '%s. Can not train without labels.' % s + + # Cache images into memory for faster training (WARNING: large datasets may exceed system RAM) + self.imgs = [None] * n + if cache_images: + gb = 0 # Gigabytes of cached images + self.img_hw0, self.img_hw = [None] * n, [None] * n + results = ThreadPool(8).imap(lambda x: load_image(*x), zip(repeat(self), range(n))) # 8 threads + pbar = tqdm(enumerate(results), total=n) + for i, x in pbar: + self.imgs[i], self.img_hw0[i], self.img_hw[i] = x # img, hw_original, hw_resized = load_image(self, i) + gb += self.imgs[i].nbytes + pbar.desc = 'Caching images (%.1fGB)' % (gb / 1E9) + + def cache_labels(self, path='labels.cache3'): + # Cache dataset labels, check images and read shapes + x = {} # dict + pbar = tqdm(zip(self.img_files, self.label_files), desc='Scanning images', total=len(self.img_files)) + for (img, label) in pbar: + try: + l = [] + im = Image.open(img) + im.verify() # PIL verify + shape = exif_size(im) # image size + assert (shape[0] > 9) & (shape[1] > 9), 'image size <10 pixels' + if os.path.isfile(label): + with open(label, 'r') as f: + l = np.array([x.split() for x in f.read().splitlines()], dtype=np.float32) # labels + if len(l) == 0: + l = np.zeros((0, 5), dtype=np.float32) + x[img] = [l, shape] + except Exception as e: + print('WARNING: Ignoring corrupted image and/or label %s: %s' % (img, e)) + + x['hash'] = get_hash(self.label_files + self.img_files) + torch.save(x, path) # save for next time + return x + + def __len__(self): + return len(self.img_files) + + # def __iter__(self): + # self.count = -1 + # print('ran dataset iter') + # #self.shuffled_vector = np.random.permutation(self.nF) if self.augment else np.arange(self.nF) + # return self + + def __getitem__(self, index): + if self.image_weights: + index = self.indices[index] + + hyp = self.hyp + mosaic = self.mosaic and random.random() < hyp['mosaic'] + if mosaic: + # Load mosaic + #img, labels = load_mosaic(self, index) + img, labels = load_mosaic9(self, index) + shapes = None + + # MixUp https://arxiv.org/pdf/1710.09412.pdf + if random.random() < hyp['mixup']: + #img2, labels2 = load_mosaic(self, random.randint(0, len(self.labels) - 1)) + img2, labels2 = load_mosaic9(self, random.randint(0, len(self.labels) - 1)) + r = np.random.beta(8.0, 8.0) # mixup ratio, alpha=beta=8.0 + img = (img * r + img2 * (1 - r)).astype(np.uint8) + labels = np.concatenate((labels, labels2), 0) + + else: + # Load image + img, (h0, w0), (h, w) = load_image(self, index) + + # Letterbox + shape = self.batch_shapes[self.batch[index]] if self.rect else self.img_size # final letterboxed shape + img, ratio, pad = letterbox(img, shape, auto=False, scaleup=self.augment) + shapes = (h0, w0), ((h / h0, w / w0), pad) # for COCO mAP rescaling + + # Load labels + labels = [] + x = self.labels[index] + if x.size > 0: + # Normalized xywh to pixel xyxy format + labels = x.copy() + labels[:, 1] = ratio[0] * w * (x[:, 1] - x[:, 3] / 2) + pad[0] # pad width + labels[:, 2] = ratio[1] * h * (x[:, 2] - x[:, 4] / 2) + pad[1] # pad height + labels[:, 3] = ratio[0] * w * (x[:, 1] + x[:, 3] / 2) + pad[0] + labels[:, 4] = ratio[1] * h * (x[:, 2] + x[:, 4] / 2) + pad[1] + + if self.augment: + # Augment imagespace + if not mosaic: + img, labels = random_perspective(img, labels, + degrees=hyp['degrees'], + translate=hyp['translate'], + scale=hyp['scale'], + shear=hyp['shear'], + perspective=hyp['perspective']) + + # Augment colorspace + augment_hsv(img, hgain=hyp['hsv_h'], sgain=hyp['hsv_s'], vgain=hyp['hsv_v']) + + # Apply cutouts + # if random.random() < 0.9: + # labels = cutout(img, labels) + + nL = len(labels) # number of labels + if nL: + labels[:, 1:5] = xyxy2xywh(labels[:, 1:5]) # convert xyxy to xywh + labels[:, [2, 4]] /= img.shape[0] # normalized height 0-1 + labels[:, [1, 3]] /= img.shape[1] # normalized width 0-1 + + if self.augment: + # flip up-down + if random.random() < hyp['flipud']: + img = np.flipud(img) + if nL: + labels[:, 2] = 1 - labels[:, 2] + + # flip left-right + if random.random() < hyp['fliplr']: + img = np.fliplr(img) + if nL: + labels[:, 1] = 1 - labels[:, 1] + + labels_out = torch.zeros((nL, 6)) + if nL: + labels_out[:, 1:] = torch.from_numpy(labels) + + # Convert + img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x416x416 + img = np.ascontiguousarray(img) + + return torch.from_numpy(img), labels_out, self.img_files[index], shapes + + @staticmethod + def collate_fn(batch): + img, label, path, shapes = zip(*batch) # transposed + for i, l in enumerate(label): + l[:, 0] = i # add target image index for build_targets() + return torch.stack(img, 0), torch.cat(label, 0), path, shapes + + +# Ancillary functions -------------------------------------------------------------------------------------------------- +def load_image(self, index): + # loads 1 image from dataset, returns img, original hw, resized hw + img = self.imgs[index] + if img is None: # not cached + path = self.img_files[index] + img = cv2.imread(path) # BGR + assert img is not None, 'Image Not Found ' + path + h0, w0 = img.shape[:2] # orig hw + r = self.img_size / max(h0, w0) # resize image to img_size + if r != 1: # always resize down, only resize up if training with augmentation + interp = cv2.INTER_AREA if r < 1 and not self.augment else cv2.INTER_LINEAR + img = cv2.resize(img, (int(w0 * r), int(h0 * r)), interpolation=interp) + return img, (h0, w0), img.shape[:2] # img, hw_original, hw_resized + else: + return self.imgs[index], self.img_hw0[index], self.img_hw[index] # img, hw_original, hw_resized + + +def augment_hsv(img, hgain=0.5, sgain=0.5, vgain=0.5): + r = np.random.uniform(-1, 1, 3) * [hgain, sgain, vgain] + 1 # random gains + hue, sat, val = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV)) + dtype = img.dtype # uint8 + + x = np.arange(0, 256, dtype=np.int16) + lut_hue = ((x * r[0]) % 180).astype(dtype) + lut_sat = np.clip(x * r[1], 0, 255).astype(dtype) + lut_val = np.clip(x * r[2], 0, 255).astype(dtype) + + img_hsv = cv2.merge((cv2.LUT(hue, lut_hue), cv2.LUT(sat, lut_sat), cv2.LUT(val, lut_val))).astype(dtype) + cv2.cvtColor(img_hsv, cv2.COLOR_HSV2BGR, dst=img) # no return needed + + # Histogram equalization + # if random.random() < 0.2: + # for i in range(3): + # img[:, :, i] = cv2.equalizeHist(img[:, :, i]) + + +def load_mosaic(self, index): + # loads images in a mosaic + + labels4 = [] + s = self.img_size + yc, xc = [int(random.uniform(-x, 2 * s + x)) for x in self.mosaic_border] # mosaic center x, y + indices = [index] + [random.randint(0, len(self.labels) - 1) for _ in range(3)] # 3 additional image indices + for i, index in enumerate(indices): + # Load image + img, _, (h, w) = load_image(self, index) + + # place img in img4 + if i == 0: # top left + img4 = np.full((s * 2, s * 2, img.shape[2]), 114, dtype=np.uint8) # base image with 4 tiles + x1a, y1a, x2a, y2a = max(xc - w, 0), max(yc - h, 0), xc, yc # xmin, ymin, xmax, ymax (large image) + x1b, y1b, x2b, y2b = w - (x2a - x1a), h - (y2a - y1a), w, h # xmin, ymin, xmax, ymax (small image) + elif i == 1: # top right + x1a, y1a, x2a, y2a = xc, max(yc - h, 0), min(xc + w, s * 2), yc + x1b, y1b, x2b, y2b = 0, h - (y2a - y1a), min(w, x2a - x1a), h + elif i == 2: # bottom left + x1a, y1a, x2a, y2a = max(xc - w, 0), yc, xc, min(s * 2, yc + h) + x1b, y1b, x2b, y2b = w - (x2a - x1a), 0, w, min(y2a - y1a, h) + elif i == 3: # bottom right + x1a, y1a, x2a, y2a = xc, yc, min(xc + w, s * 2), min(s * 2, yc + h) + x1b, y1b, x2b, y2b = 0, 0, min(w, x2a - x1a), min(y2a - y1a, h) + + img4[y1a:y2a, x1a:x2a] = img[y1b:y2b, x1b:x2b] # img4[ymin:ymax, xmin:xmax] + padw = x1a - x1b + padh = y1a - y1b + + # Labels + x = self.labels[index] + labels = x.copy() + if x.size > 0: # Normalized xywh to pixel xyxy format + labels[:, 1] = w * (x[:, 1] - x[:, 3] / 2) + padw + labels[:, 2] = h * (x[:, 2] - x[:, 4] / 2) + padh + labels[:, 3] = w * (x[:, 1] + x[:, 3] / 2) + padw + labels[:, 4] = h * (x[:, 2] + x[:, 4] / 2) + padh + labels4.append(labels) + + # Concat/clip labels + if len(labels4): + labels4 = np.concatenate(labels4, 0) + np.clip(labels4[:, 1:], 0, 2 * s, out=labels4[:, 1:]) # use with random_perspective + # img4, labels4 = replicate(img4, labels4) # replicate + + # Augment + img4, labels4 = random_perspective(img4, labels4, + degrees=self.hyp['degrees'], + translate=self.hyp['translate'], + scale=self.hyp['scale'], + shear=self.hyp['shear'], + perspective=self.hyp['perspective'], + border=self.mosaic_border) # border to remove + + return img4, labels4 + + +def load_mosaic9(self, index): + # loads images in a 9-mosaic + + labels9 = [] + s = self.img_size + indices = [index] + [random.randint(0, len(self.labels) - 1) for _ in range(8)] # 8 additional image indices + for i, index in enumerate(indices): + # Load image + img, _, (h, w) = load_image(self, index) + + # place img in img9 + if i == 0: # center + img9 = np.full((s * 3, s * 3, img.shape[2]), 114, dtype=np.uint8) # base image with 4 tiles + h0, w0 = h, w + c = s, s, s + w, s + h # xmin, ymin, xmax, ymax (base) coordinates + elif i == 1: # top + c = s, s - h, s + w, s + elif i == 2: # top right + c = s + wp, s - h, s + wp + w, s + elif i == 3: # right + c = s + w0, s, s + w0 + w, s + h + elif i == 4: # bottom right + c = s + w0, s + hp, s + w0 + w, s + hp + h + elif i == 5: # bottom + c = s + w0 - w, s + h0, s + w0, s + h0 + h + elif i == 6: # bottom left + c = s + w0 - wp - w, s + h0, s + w0 - wp, s + h0 + h + elif i == 7: # left + c = s - w, s + h0 - h, s, s + h0 + elif i == 8: # top left + c = s - w, s + h0 - hp - h, s, s + h0 - hp + + padx, pady = c[:2] + x1, y1, x2, y2 = [max(x, 0) for x in c] # allocate coords + + # Labels + x = self.labels[index] + labels = x.copy() + if x.size > 0: # Normalized xywh to pixel xyxy format + labels[:, 1] = w * (x[:, 1] - x[:, 3] / 2) + padx + labels[:, 2] = h * (x[:, 2] - x[:, 4] / 2) + pady + labels[:, 3] = w * (x[:, 1] + x[:, 3] / 2) + padx + labels[:, 4] = h * (x[:, 2] + x[:, 4] / 2) + pady + labels9.append(labels) + + # Image + img9[y1:y2, x1:x2] = img[y1 - pady:, x1 - padx:] # img9[ymin:ymax, xmin:xmax] + hp, wp = h, w # height, width previous + + # Offset + yc, xc = [int(random.uniform(0, s)) for x in self.mosaic_border] # mosaic center x, y + img9 = img9[yc:yc + 2 * s, xc:xc + 2 * s] + + # Concat/clip labels + if len(labels9): + labels9 = np.concatenate(labels9, 0) + labels9[:, [1, 3]] -= xc + labels9[:, [2, 4]] -= yc + + np.clip(labels9[:, 1:], 0, 2 * s, out=labels9[:, 1:]) # use with random_perspective + # img9, labels9 = replicate(img9, labels9) # replicate + + # Augment + img9, labels9 = random_perspective(img9, labels9, + degrees=self.hyp['degrees'], + translate=self.hyp['translate'], + scale=self.hyp['scale'], + shear=self.hyp['shear'], + perspective=self.hyp['perspective'], + border=self.mosaic_border) # border to remove + + return img9, labels9 + + +def replicate(img, labels): + # Replicate labels + h, w = img.shape[:2] + boxes = labels[:, 1:].astype(int) + x1, y1, x2, y2 = boxes.T + s = ((x2 - x1) + (y2 - y1)) / 2 # side length (pixels) + for i in s.argsort()[:round(s.size * 0.5)]: # smallest indices + x1b, y1b, x2b, y2b = boxes[i] + bh, bw = y2b - y1b, x2b - x1b + yc, xc = int(random.uniform(0, h - bh)), int(random.uniform(0, w - bw)) # offset x, y + x1a, y1a, x2a, y2a = [xc, yc, xc + bw, yc + bh] + img[y1a:y2a, x1a:x2a] = img[y1b:y2b, x1b:x2b] # img4[ymin:ymax, xmin:xmax] + labels = np.append(labels, [[labels[i, 0], x1a, y1a, x2a, y2a]], axis=0) + + return img, labels + + +def letterbox(img, new_shape=(640, 640), color=(114, 114, 114), auto=True, scaleFill=False, scaleup=True, auto_size=32): + # Resize image to a 32-pixel-multiple rectangle https://github.com/ultralytics/yolov3/issues/232 + shape = img.shape[:2] # current shape [height, width] + if isinstance(new_shape, int): + new_shape = (new_shape, new_shape) + + # Scale ratio (new / old) + r = min(new_shape[0] / shape[0], new_shape[1] / shape[1]) + if not scaleup: # only scale down, do not scale up (for better test mAP) + r = min(r, 1.0) + + # Compute padding + ratio = r, r # width, height ratios + new_unpad = int(round(shape[1] * r)), int(round(shape[0] * r)) + dw, dh = new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1] # wh padding + if auto: # minimum rectangle + dw, dh = np.mod(dw, auto_size), np.mod(dh, auto_size) # wh padding + elif scaleFill: # stretch + dw, dh = 0.0, 0.0 + new_unpad = (new_shape[1], new_shape[0]) + ratio = new_shape[1] / shape[1], new_shape[0] / shape[0] # width, height ratios + + dw /= 2 # divide padding into 2 sides + dh /= 2 + + if shape[::-1] != new_unpad: # resize + img = cv2.resize(img, new_unpad, interpolation=cv2.INTER_LINEAR) + top, bottom = int(round(dh - 0.1)), int(round(dh + 0.1)) + left, right = int(round(dw - 0.1)), int(round(dw + 0.1)) + img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color) # add border + return img, ratio, (dw, dh) + + +def random_perspective(img, targets=(), degrees=10, translate=.1, scale=.1, shear=10, perspective=0.0, border=(0, 0)): + # torchvision.transforms.RandomAffine(degrees=(-10, 10), translate=(.1, .1), scale=(.9, 1.1), shear=(-10, 10)) + # targets = [cls, xyxy] + + height = img.shape[0] + border[0] * 2 # shape(h,w,c) + width = img.shape[1] + border[1] * 2 + + # Center + C = np.eye(3) + C[0, 2] = -img.shape[1] / 2 # x translation (pixels) + C[1, 2] = -img.shape[0] / 2 # y translation (pixels) + + # Perspective + P = np.eye(3) + P[2, 0] = random.uniform(-perspective, perspective) # x perspective (about y) + P[2, 1] = random.uniform(-perspective, perspective) # y perspective (about x) + + # Rotation and Scale + R = np.eye(3) + a = random.uniform(-degrees, degrees) + # a += random.choice([-180, -90, 0, 90]) # add 90deg rotations to small rotations + s = random.uniform(1 - scale, 1 + scale) + # s = 2 ** random.uniform(-scale, scale) + R[:2] = cv2.getRotationMatrix2D(angle=a, center=(0, 0), scale=s) + + # Shear + S = np.eye(3) + S[0, 1] = math.tan(random.uniform(-shear, shear) * math.pi / 180) # x shear (deg) + S[1, 0] = math.tan(random.uniform(-shear, shear) * math.pi / 180) # y shear (deg) + + # Translation + T = np.eye(3) + T[0, 2] = random.uniform(0.5 - translate, 0.5 + translate) * width # x translation (pixels) + T[1, 2] = random.uniform(0.5 - translate, 0.5 + translate) * height # y translation (pixels) + + # Combined rotation matrix + M = T @ S @ R @ P @ C # order of operations (right to left) is IMPORTANT + if (border[0] != 0) or (border[1] != 0) or (M != np.eye(3)).any(): # image changed + if perspective: + img = cv2.warpPerspective(img, M, dsize=(width, height), borderValue=(114, 114, 114)) + else: # affine + img = cv2.warpAffine(img, M[:2], dsize=(width, height), borderValue=(114, 114, 114)) + + # Visualize + # import matplotlib.pyplot as plt + # ax = plt.subplots(1, 2, figsize=(12, 6))[1].ravel() + # ax[0].imshow(img[:, :, ::-1]) # base + # ax[1].imshow(img2[:, :, ::-1]) # warped + + # Transform label coordinates + n = len(targets) + if n: + # warp points + xy = np.ones((n * 4, 3)) + xy[:, :2] = targets[:, [1, 2, 3, 4, 1, 4, 3, 2]].reshape(n * 4, 2) # x1y1, x2y2, x1y2, x2y1 + xy = xy @ M.T # transform + if perspective: + xy = (xy[:, :2] / xy[:, 2:3]).reshape(n, 8) # rescale + else: # affine + xy = xy[:, :2].reshape(n, 8) + + # create new boxes + x = xy[:, [0, 2, 4, 6]] + y = xy[:, [1, 3, 5, 7]] + xy = np.concatenate((x.min(1), y.min(1), x.max(1), y.max(1))).reshape(4, n).T + + # # apply angle-based reduction of bounding boxes + # radians = a * math.pi / 180 + # reduction = max(abs(math.sin(radians)), abs(math.cos(radians))) ** 0.5 + # x = (xy[:, 2] + xy[:, 0]) / 2 + # y = (xy[:, 3] + xy[:, 1]) / 2 + # w = (xy[:, 2] - xy[:, 0]) * reduction + # h = (xy[:, 3] - xy[:, 1]) * reduction + # xy = np.concatenate((x - w / 2, y - h / 2, x + w / 2, y + h / 2)).reshape(4, n).T + + # clip boxes + xy[:, [0, 2]] = xy[:, [0, 2]].clip(0, width) + xy[:, [1, 3]] = xy[:, [1, 3]].clip(0, height) + + # filter candidates + i = box_candidates(box1=targets[:, 1:5].T * s, box2=xy.T) + targets = targets[i] + targets[:, 1:5] = xy[i] + + return img, targets + + +def box_candidates(box1, box2, wh_thr=2, ar_thr=20, area_thr=0.1): # box1(4,n), box2(4,n) + # Compute candidate boxes: box1 before augment, box2 after augment, wh_thr (pixels), aspect_ratio_thr, area_ratio + w1, h1 = box1[2] - box1[0], box1[3] - box1[1] + w2, h2 = box2[2] - box2[0], box2[3] - box2[1] + ar = np.maximum(w2 / (h2 + 1e-16), h2 / (w2 + 1e-16)) # aspect ratio + return (w2 > wh_thr) & (h2 > wh_thr) & (w2 * h2 / (w1 * h1 + 1e-16) > area_thr) & (ar < ar_thr) # candidates + + +def cutout(image, labels): + # Applies image cutout augmentation https://arxiv.org/abs/1708.04552 + h, w = image.shape[:2] + + def bbox_ioa(box1, box2): + # Returns the intersection over box2 area given box1, box2. box1 is 4, box2 is nx4. boxes are x1y1x2y2 + box2 = box2.transpose() + + # Get the coordinates of bounding boxes + b1_x1, b1_y1, b1_x2, b1_y2 = box1[0], box1[1], box1[2], box1[3] + b2_x1, b2_y1, b2_x2, b2_y2 = box2[0], box2[1], box2[2], box2[3] + + # Intersection area + inter_area = (np.minimum(b1_x2, b2_x2) - np.maximum(b1_x1, b2_x1)).clip(0) * \ + (np.minimum(b1_y2, b2_y2) - np.maximum(b1_y1, b2_y1)).clip(0) + + # box2 area + box2_area = (b2_x2 - b2_x1) * (b2_y2 - b2_y1) + 1e-16 + + # Intersection over box2 area + return inter_area / box2_area + + # create random masks + scales = [0.5] * 1 + [0.25] * 2 + [0.125] * 4 + [0.0625] * 8 + [0.03125] * 16 # image size fraction + for s in scales: + mask_h = random.randint(1, int(h * s)) + mask_w = random.randint(1, int(w * s)) + + # box + xmin = max(0, random.randint(0, w) - mask_w // 2) + ymin = max(0, random.randint(0, h) - mask_h // 2) + xmax = min(w, xmin + mask_w) + ymax = min(h, ymin + mask_h) + + # apply random color mask + image[ymin:ymax, xmin:xmax] = [random.randint(64, 191) for _ in range(3)] + + # return unobscured labels + if len(labels) and s > 0.03: + box = np.array([xmin, ymin, xmax, ymax], dtype=np.float32) + ioa = bbox_ioa(box, labels[:, 1:5]) # intersection over area + labels = labels[ioa < 0.60] # remove >60% obscured labels + + return labels + + +def create_folder(path='./new'): + # Create folder + if os.path.exists(path): + shutil.rmtree(path) # delete output folder + os.makedirs(path) # make new output folder + + +def flatten_recursive(path='../coco128'): + # Flatten a recursive directory by bringing all files to top level + new_path = Path(path + '_flat') + create_folder(new_path) + for file in tqdm(glob.glob(str(Path(path)) + '/**/*.*', recursive=True)): + shutil.copyfile(file, new_path / Path(file).name) + + diff --git a/PyTorch/contrib/cv/detection/YOLOR/utils/google_utils.py b/PyTorch/contrib/cv/detection/YOLOR/utils/google_utils.py index 7cd3e8a2f4167f3db779b6e487be83575b4dd3fd..b69abe710b472e748fa3766a7ee702299806ea3e 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/utils/google_utils.py +++ b/PyTorch/contrib/cv/detection/YOLOR/utils/google_utils.py @@ -1,134 +1,134 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Google utils: https://cloud.google.com/storage/docs/reference/libraries - -import os -import platform -import subprocess -import time -from pathlib import Path - -import torch - - -def gsutil_getsize(url=''): - # gs://bucket/file size https://cloud.google.com/storage/docs/gsutil/commands/du - s = subprocess.check_output('gsutil du %s' % url, shell=True).decode('utf-8') - return eval(s.split(' ')[0]) if len(s) else 0 # bytes - - -def attempt_download(weights): - # Attempt to download pretrained weights if not found locally - weights = weights.strip().replace("'", '') - file = Path(weights).name - - msg = weights + ' missing, try downloading from https://github.com/WongKinYiu/yolor/releases/' - models = ['yolor_p6.pt', 'yolor_w6.pt'] # available models - - if file in models and not os.path.isfile(weights): - - try: # GitHub - url = 'https://github.com/WongKinYiu/yolor/releases/download/v1.0/' + file - print('Downloading %s to %s...' % (url, weights)) - torch.hub.download_url_to_file(url, weights) - assert os.path.exists(weights) and os.path.getsize(weights) > 1E6 # check - except Exception as e: # GCP - print('ERROR: Download failure.') - print('') - - -def attempt_load(weights, map_location=None): - # Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a - model = Ensemble() - for w in weights if isinstance(weights, list) else [weights]: - attempt_download(w) - model.append(torch.load(w, map_location=map_location)['model'].float().fuse().eval()) # load FP32 model - - if len(model) == 1: - return model[-1] # return model - else: - print('Ensemble created with %s\n' % weights) - for k in ['names', 'stride']: - setattr(model, k, getattr(model[-1], k)) - return model # return ensemble - - -def gdrive_download(id='1n_oKgR81BJtqk75b00eAjdv03qVCQn2f', name='coco128.zip'): - # Downloads a file from Google Drive. from utils.google_utils import *; gdrive_download() - t = time.time() - - print('Downloading https://drive.google.com/uc?export=download&id=%s as %s... ' % (id, name), end='') - os.remove(name) if os.path.exists(name) else None # remove existing - os.remove('cookie') if os.path.exists('cookie') else None - - # Attempt file download - out = "NUL" if platform.system() == "Windows" else "/dev/null" - os.system('curl -c ./cookie -s -L "drive.google.com/uc?export=download&id=%s" > %s ' % (id, out)) - if os.path.exists('cookie'): # large file - s = 'curl -Lb ./cookie "drive.google.com/uc?export=download&confirm=%s&id=%s" -o %s' % (get_token(), id, name) - else: # small file - s = 'curl -s -L -o %s "drive.google.com/uc?export=download&id=%s"' % (name, id) - r = os.system(s) # execute, capture return - os.remove('cookie') if os.path.exists('cookie') else None - - # Error check - if r != 0: - os.remove(name) if os.path.exists(name) else None # remove partial - print('Download error ') # raise Exception('Download error') - return r - - # Unzip if archive - if name.endswith('.zip'): - print('unzipping... ', end='') - os.system('unzip -q %s' % name) # unzip - os.remove(name) # remove zip to free space - - print('Done (%.1fs)' % (time.time() - t)) - return r - - -def get_token(cookie="./cookie"): - with open(cookie) as f: - for line in f: - if "download" in line: - return line.split()[-1] - return "" - -# def upload_blob(bucket_name, source_file_name, destination_blob_name): -# # Uploads a file to a bucket -# # https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-python -# -# storage_client = storage.Client() -# bucket = storage_client.get_bucket(bucket_name) -# blob = bucket.blob(destination_blob_name) -# -# blob.upload_from_filename(source_file_name) -# -# print('File {} uploaded to {}.'.format( -# source_file_name, -# destination_blob_name)) -# -# -# def download_blob(bucket_name, source_blob_name, destination_file_name): -# # Uploads a blob from a bucket -# storage_client = storage.Client() -# bucket = storage_client.get_bucket(bucket_name) -# blob = bucket.blob(source_blob_name) -# -# blob.download_to_filename(destination_file_name) -# -# print('Blob {} downloaded to {}.'.format( -# source_blob_name, -# destination_file_name)) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Google utils: https://cloud.google.com/storage/docs/reference/libraries + +import os +import platform +import subprocess +import time +from pathlib import Path + +import torch + + +def gsutil_getsize(url=''): + # gs://bucket/file size https://cloud.google.com/storage/docs/gsutil/commands/du + s = subprocess.check_output('gsutil du %s' % url, shell=True).decode('utf-8') + return eval(s.split(' ')[0]) if len(s) else 0 # bytes + + +def attempt_download(weights): + # Attempt to download pretrained weights if not found locally + weights = weights.strip().replace("'", '') + file = Path(weights).name + + msg = weights + ' missing, try downloading from https://github.com/WongKinYiu/yolor/releases/' + models = ['yolor_p6.pt', 'yolor_w6.pt'] # available models + + if file in models and not os.path.isfile(weights): + + try: # GitHub + url = 'https://github.com/WongKinYiu/yolor/releases/download/v1.0/' + file + print('Downloading %s to %s...' % (url, weights)) + torch.hub.download_url_to_file(url, weights) + assert os.path.exists(weights) and os.path.getsize(weights) > 1E6 # check + except Exception as e: # GCP + print('ERROR: Download failure.') + print('') + + +def attempt_load(weights, map_location=None): + # Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a + model = Ensemble() + for w in weights if isinstance(weights, list) else [weights]: + attempt_download(w) + model.append(torch.load(w, map_location=map_location)['model'].float().fuse().eval()) # load FP32 model + + if len(model) == 1: + return model[-1] # return model + else: + print('Ensemble created with %s\n' % weights) + for k in ['names', 'stride']: + setattr(model, k, getattr(model[-1], k)) + return model # return ensemble + + +def gdrive_download(id='1n_oKgR81BJtqk75b00eAjdv03qVCQn2f', name='coco128.zip'): + # Downloads a file from Google Drive. from utils.google_utils import *; gdrive_download() + t = time.time() + + print('Downloading https://drive.google.com/uc?export=download&id=%s as %s... ' % (id, name), end='') + os.remove(name) if os.path.exists(name) else None # remove existing + os.remove('cookie') if os.path.exists('cookie') else None + + # Attempt file download + out = "NUL" if platform.system() == "Windows" else "/dev/null" + os.system('curl -c ./cookie -s -L "drive.google.com/uc?export=download&id=%s" > %s ' % (id, out)) + if os.path.exists('cookie'): # large file + s = 'curl -Lb ./cookie "drive.google.com/uc?export=download&confirm=%s&id=%s" -o %s' % (get_token(), id, name) + else: # small file + s = 'curl -s -L -o %s "drive.google.com/uc?export=download&id=%s"' % (name, id) + r = os.system(s) # execute, capture return + os.remove('cookie') if os.path.exists('cookie') else None + + # Error check + if r != 0: + os.remove(name) if os.path.exists(name) else None # remove partial + print('Download error ') # raise Exception('Download error') + return r + + # Unzip if archive + if name.endswith('.zip'): + print('unzipping... ', end='') + os.system('unzip -q %s' % name) # unzip + os.remove(name) # remove zip to free space + + print('Done (%.1fs)' % (time.time() - t)) + return r + + +def get_token(cookie="./cookie"): + with open(cookie) as f: + for line in f: + if "download" in line: + return line.split()[-1] + return "" + +# def upload_blob(bucket_name, source_file_name, destination_blob_name): +# # Uploads a file to a bucket +# # https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-python +# +# storage_client = storage.Client() +# bucket = storage_client.get_bucket(bucket_name) +# blob = bucket.blob(destination_blob_name) +# +# blob.upload_from_filename(source_file_name) +# +# print('File {} uploaded to {}.'.format( +# source_file_name, +# destination_blob_name)) +# +# +# def download_blob(bucket_name, source_blob_name, destination_file_name): +# # Uploads a blob from a bucket +# storage_client = storage.Client() +# bucket = storage_client.get_bucket(bucket_name) +# blob = bucket.blob(source_blob_name) +# +# blob.download_to_filename(destination_file_name) +# +# print('Blob {} downloaded to {}.'.format( +# source_blob_name, +# destination_file_name)) diff --git a/PyTorch/contrib/cv/detection/YOLOR/utils/layers.py b/PyTorch/contrib/cv/detection/YOLOR/utils/layers.py index a0dfadae460ca7134e07c0f6aceb3828fad0d8ac..de842fc4aa349c56fec29adcbf4d29cb0d451266 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/utils/layers.py +++ b/PyTorch/contrib/cv/detection/YOLOR/utils/layers.py @@ -1,548 +1,548 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch.nn.functional as F - -from utils.general import * - -import torch -from torch import nn - -try: - from mish_cuda import MishCuda as Mish - -except: - class Mish(nn.Module): # https://github.com/digantamisra98/Mish - def forward(self, x): - return x * F.softplus(x).tanh() - -try: - from pytorch_wavelets import DWTForward, DWTInverse - - class DWT(nn.Module): - def __init__(self): - super(DWT, self).__init__() - self.xfm = DWTForward(J=1, wave='db1', mode='zero') - - def forward(self, x): - b,c,w,h = x.shape - yl, yh = self.xfm(x) - return torch.cat([yl/2., yh[0].view(b,-1,w//2,h//2)/2.+.5], 1) - -except: # using Reorg instead - class DWT(nn.Module): - def forward(self, x): - return torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1) - - -class Reorg(nn.Module): - def forward(self, x): - return torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1) - - -def make_divisible(v, divisor): - # Function ensures all layers have a channel number that is divisible by 8 - # https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py - return math.ceil(v / divisor) * divisor - - -class Flatten(nn.Module): - # Use after nn.AdaptiveAvgPool2d(1) to remove last 2 dimensions - def forward(self, x): - return x.view(x.size(0), -1) - - -class Concat(nn.Module): - # Concatenate a list of tensors along dimension - def __init__(self, dimension=1): - super(Concat, self).__init__() - self.d = dimension - - def forward(self, x): - return torch.cat(x, self.d) - - -class FeatureConcat(nn.Module): - def __init__(self, layers): - super(FeatureConcat, self).__init__() - self.layers = layers # layer indices - self.multiple = len(layers) > 1 # multiple layers flag - - def forward(self, x, outputs): - return torch.cat([outputs[i] for i in self.layers], 1) if self.multiple else outputs[self.layers[0]] - - -class FeatureConcat2(nn.Module): - def __init__(self, layers): - super(FeatureConcat2, self).__init__() - self.layers = layers # layer indices - self.multiple = len(layers) > 1 # multiple layers flag - - def forward(self, x, outputs): - return torch.cat([outputs[self.layers[0]], outputs[self.layers[1]].detach()], 1) - - -class FeatureConcat3(nn.Module): - def __init__(self, layers): - super(FeatureConcat3, self).__init__() - self.layers = layers # layer indices - self.multiple = len(layers) > 1 # multiple layers flag - - def forward(self, x, outputs): - return torch.cat([outputs[self.layers[0]], outputs[self.layers[1]].detach(), outputs[self.layers[2]].detach()], 1) - - -class FeatureConcat_l(nn.Module): - def __init__(self, layers): - super(FeatureConcat_l, self).__init__() - self.layers = layers # layer indices - self.multiple = len(layers) > 1 # multiple layers flag - - def forward(self, x, outputs): - return torch.cat([outputs[i][:,:outputs[i].shape[1]//2,:,:] for i in self.layers], 1) if self.multiple else outputs[self.layers[0]][:,:outputs[self.layers[0]].shape[1]//2,:,:] - - -class WeightedFeatureFusion(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 - def __init__(self, layers, weight=False): - super(WeightedFeatureFusion, self).__init__() - self.layers = layers # layer indices - self.weight = weight # apply weights boolean - self.n = len(layers) + 1 # number of layers - if weight: - self.w = nn.Parameter(torch.zeros(self.n), requires_grad=True) # layer weights - - def forward(self, x, outputs): - # Weights - if self.weight: - w = torch.sigmoid(self.w) * (2 / self.n) # sigmoid weights (0-1) - x = x * w[0] - - # Fusion - nx = x.shape[1] # input channels - for i in range(self.n - 1): - a = outputs[self.layers[i]] * w[i + 1] if self.weight else outputs[self.layers[i]] # feature to add - na = a.shape[1] # feature channels - - # Adjust channels - if nx == na: # same shape - x = x + a - elif nx > na: # slice input - x[:, :na] = x[:, :na] + a # or a = nn.ZeroPad2d((0, 0, 0, 0, 0, dc))(a); x = x + a - else: # slice feature - x = x + a[:, :nx] - - return x - - -class MixConv2d(nn.Module): # MixConv: Mixed Depthwise Convolutional Kernels https://arxiv.org/abs/1907.09595 - def __init__(self, in_ch, out_ch, k=(3, 5, 7), stride=1, dilation=1, bias=True, method='equal_params'): - super(MixConv2d, self).__init__() - - groups = len(k) - if method == 'equal_ch': # equal channels per group - i = torch.linspace(0, groups - 1E-6, out_ch).floor() # out_ch indices - ch = [(i == g).sum() for g in range(groups)] - else: # 'equal_params': equal parameter count per group - b = [out_ch] + [0] * groups - a = np.eye(groups + 1, groups, k=-1) - a -= np.roll(a, 1, axis=1) - a *= np.array(k) ** 2 - a[0] = 1 - ch = np.linalg.lstsq(a, b, rcond=None)[0].round().astype(int) # solve for equal weight indices, ax = b - - self.m = nn.ModuleList([nn.Conv2d(in_channels=in_ch, - out_channels=ch[g], - kernel_size=k[g], - stride=stride, - padding=k[g] // 2, # 'same' pad - dilation=dilation, - bias=bias) for g in range(groups)]) - - def forward(self, x): - return torch.cat([m(x) for m in self.m], 1) - - -# Activation functions below ------------------------------------------------------------------------------------------- -class SwishImplementation(torch.autograd.Function): - @staticmethod - def forward(ctx, x): - ctx.save_for_backward(x) - return x * torch.sigmoid(x) - - @staticmethod - def backward(ctx, grad_output): - x = ctx.saved_tensors[0] - sx = torch.sigmoid(x) # sigmoid(ctx) - return grad_output * (sx * (1 + x * (1 - sx))) - - -class MishImplementation(torch.autograd.Function): - @staticmethod - def forward(ctx, x): - ctx.save_for_backward(x) - return x.mul(torch.tanh(F.softplus(x))) # x * tanh(ln(1 + exp(x))) - - @staticmethod - def backward(ctx, grad_output): - x = ctx.saved_tensors[0] - sx = torch.sigmoid(x) - fx = F.softplus(x).tanh() - return grad_output * (fx + x * sx * (1 - fx * fx)) - - -class MemoryEfficientSwish(nn.Module): - def forward(self, x): - return SwishImplementation.apply(x) - - -class MemoryEfficientMish(nn.Module): - def forward(self, x): - return MishImplementation.apply(x) - - -class Swish(nn.Module): - def forward(self, x): - return x * torch.sigmoid(x) - - -class HardSwish(nn.Module): # https://arxiv.org/pdf/1905.02244.pdf - def forward(self, x): - return x * F.hardtanh(x + 3, 0., 6., True) / 6. - - -class DeformConv2d(nn.Module): - def __init__(self, inc, outc, kernel_size=3, padding=1, stride=1, bias=None, modulation=False): - """ - Args: - modulation (bool, optional): If True, Modulated Defomable Convolution (Deformable ConvNets v2). - """ - super(DeformConv2d, self).__init__() - self.kernel_size = kernel_size - self.padding = padding - self.stride = stride - self.zero_padding = nn.ZeroPad2d(padding) - self.conv = nn.Conv2d(inc, outc, kernel_size=kernel_size, stride=kernel_size, bias=bias) - - self.p_conv = nn.Conv2d(inc, 2*kernel_size*kernel_size, kernel_size=3, padding=1, stride=stride) - nn.init.constant_(self.p_conv.weight, 0) - self.p_conv.register_backward_hook(self._set_lr) - - self.modulation = modulation - if modulation: - self.m_conv = nn.Conv2d(inc, kernel_size*kernel_size, kernel_size=3, padding=1, stride=stride) - nn.init.constant_(self.m_conv.weight, 0) - self.m_conv.register_backward_hook(self._set_lr) - - @staticmethod - def _set_lr(module, grad_input, grad_output): - grad_input = (grad_input[i] * 0.1 for i in range(len(grad_input))) - grad_output = (grad_output[i] * 0.1 for i in range(len(grad_output))) - - def forward(self, x): - offset = self.p_conv(x) - if self.modulation: - m = torch.sigmoid(self.m_conv(x)) - - dtype = offset.data.type() - ks = self.kernel_size - N = offset.size(1) // 2 - - if self.padding: - x = self.zero_padding(x) - - # (b, 2N, h, w) - p = self._get_p(offset, dtype) - - # (b, h, w, 2N) - p = p.contiguous().permute(0, 2, 3, 1) - q_lt = p.detach().floor() - q_rb = q_lt + 1 - - q_lt = torch.cat([torch.clamp(q_lt[..., :N], 0, x.size(2)-1), torch.clamp(q_lt[..., N:], 0, x.size(3)-1)], dim=-1).long() - q_rb = torch.cat([torch.clamp(q_rb[..., :N], 0, x.size(2)-1), torch.clamp(q_rb[..., N:], 0, x.size(3)-1)], dim=-1).long() - q_lb = torch.cat([q_lt[..., :N], q_rb[..., N:]], dim=-1) - q_rt = torch.cat([q_rb[..., :N], q_lt[..., N:]], dim=-1) - - # clip p - p = torch.cat([torch.clamp(p[..., :N], 0, x.size(2)-1), torch.clamp(p[..., N:], 0, x.size(3)-1)], dim=-1) - - # bilinear kernel (b, h, w, N) - g_lt = (1 + (q_lt[..., :N].type_as(p) - p[..., :N])) * (1 + (q_lt[..., N:].type_as(p) - p[..., N:])) - g_rb = (1 - (q_rb[..., :N].type_as(p) - p[..., :N])) * (1 - (q_rb[..., N:].type_as(p) - p[..., N:])) - g_lb = (1 + (q_lb[..., :N].type_as(p) - p[..., :N])) * (1 - (q_lb[..., N:].type_as(p) - p[..., N:])) - g_rt = (1 - (q_rt[..., :N].type_as(p) - p[..., :N])) * (1 + (q_rt[..., N:].type_as(p) - p[..., N:])) - - # (b, c, h, w, N) - x_q_lt = self._get_x_q(x, q_lt, N) - x_q_rb = self._get_x_q(x, q_rb, N) - x_q_lb = self._get_x_q(x, q_lb, N) - x_q_rt = self._get_x_q(x, q_rt, N) - - # (b, c, h, w, N) - x_offset = g_lt.unsqueeze(dim=1) * x_q_lt + \ - g_rb.unsqueeze(dim=1) * x_q_rb + \ - g_lb.unsqueeze(dim=1) * x_q_lb + \ - g_rt.unsqueeze(dim=1) * x_q_rt - - # modulation - if self.modulation: - m = m.contiguous().permute(0, 2, 3, 1) - m = m.unsqueeze(dim=1) - m = torch.cat([m for _ in range(x_offset.size(1))], dim=1) - x_offset *= m - - x_offset = self._reshape_x_offset(x_offset, ks) - out = self.conv(x_offset) - - return out - - def _get_p_n(self, N, dtype): - p_n_x, p_n_y = torch.meshgrid( - torch.arange(-(self.kernel_size-1)//2, (self.kernel_size-1)//2+1), - torch.arange(-(self.kernel_size-1)//2, (self.kernel_size-1)//2+1)) - # (2N, 1) - p_n = torch.cat([torch.flatten(p_n_x), torch.flatten(p_n_y)], 0) - p_n = p_n.view(1, 2*N, 1, 1).type(dtype) - - return p_n - - def _get_p_0(self, h, w, N, dtype): - p_0_x, p_0_y = torch.meshgrid( - torch.arange(1, h*self.stride+1, self.stride), - torch.arange(1, w*self.stride+1, self.stride)) - p_0_x = torch.flatten(p_0_x).view(1, 1, h, w).repeat(1, N, 1, 1) - p_0_y = torch.flatten(p_0_y).view(1, 1, h, w).repeat(1, N, 1, 1) - p_0 = torch.cat([p_0_x, p_0_y], 1).type(dtype) - - return p_0 - - def _get_p(self, offset, dtype): - N, h, w = offset.size(1)//2, offset.size(2), offset.size(3) - - # (1, 2N, 1, 1) - p_n = self._get_p_n(N, dtype) - # (1, 2N, h, w) - p_0 = self._get_p_0(h, w, N, dtype) - p = p_0 + p_n + offset - return p - - def _get_x_q(self, x, q, N): - b, h, w, _ = q.size() - padded_w = x.size(3) - c = x.size(1) - # (b, c, h*w) - x = x.contiguous().view(b, c, -1) - - # (b, h, w, N) - index = q[..., :N]*padded_w + q[..., N:] # offset_x*w + offset_y - # (b, c, h*w*N) - index = index.contiguous().unsqueeze(dim=1).expand(-1, c, -1, -1, -1).contiguous().view(b, c, -1) - - x_offset = x.gather(dim=-1, index=index).contiguous().view(b, c, h, w, N) - - return x_offset - - @staticmethod - def _reshape_x_offset(x_offset, ks): - b, c, h, w, N = x_offset.size() - x_offset = torch.cat([x_offset[..., s:s+ks].contiguous().view(b, c, h, w*ks) for s in range(0, N, ks)], dim=-1) - x_offset = x_offset.contiguous().view(b, c, h*ks, w*ks) - - return x_offset - - -class GAP(nn.Module): - def __init__(self): - super(GAP, self).__init__() - self.avg_pool = nn.AdaptiveAvgPool2d(1) - def forward(self, x): - #b, c, _, _ = x.size() - return self.avg_pool(x)#.view(b, c) - - -class Silence(nn.Module): - def __init__(self): - super(Silence, self).__init__() - def forward(self, x): - return x - - -class ScaleChannel(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 - def __init__(self, layers): - super(ScaleChannel, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]] - return x.expand_as(a) * a - - -class ShiftChannel(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 - def __init__(self, layers): - super(ShiftChannel, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]] - return a.expand_as(x) + x - - -class ShiftChannel2D(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 - def __init__(self, layers): - super(ShiftChannel2D, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]].view(1,-1,1,1) - return a.expand_as(x) + x - - -class ControlChannel(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 - def __init__(self, layers): - super(ControlChannel, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]] - return a.expand_as(x) * x - - -class ControlChannel2D(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 - def __init__(self, layers): - super(ControlChannel2D, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]].view(1,-1,1,1) - return a.expand_as(x) * x - - -class AlternateChannel(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 - def __init__(self, layers): - super(AlternateChannel, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]] - return torch.cat([a.expand_as(x), x], dim=1) - - -class AlternateChannel2D(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 - def __init__(self, layers): - super(AlternateChannel2D, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]].view(1,-1,1,1) - return torch.cat([a.expand_as(x), x], dim=1) - - -class SelectChannel(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 - def __init__(self, layers): - super(SelectChannel, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]] - return a.sigmoid().expand_as(x) * x - - -class SelectChannel2D(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 - def __init__(self, layers): - super(SelectChannel2D, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]].view(1,-1,1,1) - return a.sigmoid().expand_as(x) * x - - -class ScaleSpatial(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 - def __init__(self, layers): - super(ScaleSpatial, self).__init__() - self.layers = layers # layer indices - - def forward(self, x, outputs): - a = outputs[self.layers[0]] - return x * a - - -class ImplicitA(nn.Module): - def __init__(self, channel): - super(ImplicitA, self).__init__() - self.channel = channel - self.implicit = nn.Parameter(torch.zeros(1, channel, 1, 1)) - nn.init.normal_(self.implicit, std=.02) - - def forward(self): - return self.implicit - - -class ImplicitC(nn.Module): - def __init__(self, channel): - super(ImplicitC, self).__init__() - self.channel = channel - self.implicit = nn.Parameter(torch.zeros(1, channel, 1, 1)) - nn.init.normal_(self.implicit, std=.02) - - def forward(self): - return self.implicit - - -class ImplicitM(nn.Module): - def __init__(self, channel): - super(ImplicitM, self).__init__() - self.channel = channel - self.implicit = nn.Parameter(torch.ones(1, channel, 1, 1)) - nn.init.normal_(self.implicit, mean=1., std=.02) - - def forward(self): - return self.implicit - - - -class Implicit2DA(nn.Module): - def __init__(self, atom, channel): - super(Implicit2DA, self).__init__() - self.channel = channel - self.implicit = nn.Parameter(torch.zeros(1, atom, channel, 1)) - nn.init.normal_(self.implicit, std=.02) - - def forward(self): - return self.implicit - - -class Implicit2DC(nn.Module): - def __init__(self, atom, channel): - super(Implicit2DC, self).__init__() - self.channel = channel - self.implicit = nn.Parameter(torch.zeros(1, atom, channel, 1)) - nn.init.normal_(self.implicit, std=.02) - - def forward(self): - return self.implicit - - -class Implicit2DM(nn.Module): - def __init__(self, atom, channel): - super(Implicit2DM, self).__init__() - self.channel = channel - self.implicit = nn.Parameter(torch.ones(1, atom, channel, 1)) - nn.init.normal_(self.implicit, mean=1., std=.02) - - def forward(self): - return self.implicit - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch.nn.functional as F + +from utils.general import * + +import torch +from torch import nn + +try: + from mish_cuda import MishCuda as Mish + +except: + class Mish(nn.Module): # https://github.com/digantamisra98/Mish + def forward(self, x): + return x * F.softplus(x).tanh() + +try: + from pytorch_wavelets import DWTForward, DWTInverse + + class DWT(nn.Module): + def __init__(self): + super(DWT, self).__init__() + self.xfm = DWTForward(J=1, wave='db1', mode='zero') + + def forward(self, x): + b,c,w,h = x.shape + yl, yh = self.xfm(x) + return torch.cat([yl/2., yh[0].view(b,-1,w//2,h//2)/2.+.5], 1) + +except: # using Reorg instead + class DWT(nn.Module): + def forward(self, x): + return torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1) + + +class Reorg(nn.Module): + def forward(self, x): + return torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1) + + +def make_divisible(v, divisor): + # Function ensures all layers have a channel number that is divisible by 8 + # https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py + return math.ceil(v / divisor) * divisor + + +class Flatten(nn.Module): + # Use after nn.AdaptiveAvgPool2d(1) to remove last 2 dimensions + def forward(self, x): + return x.view(x.size(0), -1) + + +class Concat(nn.Module): + # Concatenate a list of tensors along dimension + def __init__(self, dimension=1): + super(Concat, self).__init__() + self.d = dimension + + def forward(self, x): + return torch.cat(x, self.d) + + +class FeatureConcat(nn.Module): + def __init__(self, layers): + super(FeatureConcat, self).__init__() + self.layers = layers # layer indices + self.multiple = len(layers) > 1 # multiple layers flag + + def forward(self, x, outputs): + return torch.cat([outputs[i] for i in self.layers], 1) if self.multiple else outputs[self.layers[0]] + + +class FeatureConcat2(nn.Module): + def __init__(self, layers): + super(FeatureConcat2, self).__init__() + self.layers = layers # layer indices + self.multiple = len(layers) > 1 # multiple layers flag + + def forward(self, x, outputs): + return torch.cat([outputs[self.layers[0]], outputs[self.layers[1]].detach()], 1) + + +class FeatureConcat3(nn.Module): + def __init__(self, layers): + super(FeatureConcat3, self).__init__() + self.layers = layers # layer indices + self.multiple = len(layers) > 1 # multiple layers flag + + def forward(self, x, outputs): + return torch.cat([outputs[self.layers[0]], outputs[self.layers[1]].detach(), outputs[self.layers[2]].detach()], 1) + + +class FeatureConcat_l(nn.Module): + def __init__(self, layers): + super(FeatureConcat_l, self).__init__() + self.layers = layers # layer indices + self.multiple = len(layers) > 1 # multiple layers flag + + def forward(self, x, outputs): + return torch.cat([outputs[i][:,:outputs[i].shape[1]//2,:,:] for i in self.layers], 1) if self.multiple else outputs[self.layers[0]][:,:outputs[self.layers[0]].shape[1]//2,:,:] + + +class WeightedFeatureFusion(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 + def __init__(self, layers, weight=False): + super(WeightedFeatureFusion, self).__init__() + self.layers = layers # layer indices + self.weight = weight # apply weights boolean + self.n = len(layers) + 1 # number of layers + if weight: + self.w = nn.Parameter(torch.zeros(self.n), requires_grad=True) # layer weights + + def forward(self, x, outputs): + # Weights + if self.weight: + w = torch.sigmoid(self.w) * (2 / self.n) # sigmoid weights (0-1) + x = x * w[0] + + # Fusion + nx = x.shape[1] # input channels + for i in range(self.n - 1): + a = outputs[self.layers[i]] * w[i + 1] if self.weight else outputs[self.layers[i]] # feature to add + na = a.shape[1] # feature channels + + # Adjust channels + if nx == na: # same shape + x = x + a + elif nx > na: # slice input + x[:, :na] = x[:, :na] + a # or a = nn.ZeroPad2d((0, 0, 0, 0, 0, dc))(a); x = x + a + else: # slice feature + x = x + a[:, :nx] + + return x + + +class MixConv2d(nn.Module): # MixConv: Mixed Depthwise Convolutional Kernels https://arxiv.org/abs/1907.09595 + def __init__(self, in_ch, out_ch, k=(3, 5, 7), stride=1, dilation=1, bias=True, method='equal_params'): + super(MixConv2d, self).__init__() + + groups = len(k) + if method == 'equal_ch': # equal channels per group + i = torch.linspace(0, groups - 1E-6, out_ch).floor() # out_ch indices + ch = [(i == g).sum() for g in range(groups)] + else: # 'equal_params': equal parameter count per group + b = [out_ch] + [0] * groups + a = np.eye(groups + 1, groups, k=-1) + a -= np.roll(a, 1, axis=1) + a *= np.array(k) ** 2 + a[0] = 1 + ch = np.linalg.lstsq(a, b, rcond=None)[0].round().astype(int) # solve for equal weight indices, ax = b + + self.m = nn.ModuleList([nn.Conv2d(in_channels=in_ch, + out_channels=ch[g], + kernel_size=k[g], + stride=stride, + padding=k[g] // 2, # 'same' pad + dilation=dilation, + bias=bias) for g in range(groups)]) + + def forward(self, x): + return torch.cat([m(x) for m in self.m], 1) + + +# Activation functions below ------------------------------------------------------------------------------------------- +class SwishImplementation(torch.autograd.Function): + @staticmethod + def forward(ctx, x): + ctx.save_for_backward(x) + return x * torch.sigmoid(x) + + @staticmethod + def backward(ctx, grad_output): + x = ctx.saved_tensors[0] + sx = torch.sigmoid(x) # sigmoid(ctx) + return grad_output * (sx * (1 + x * (1 - sx))) + + +class MishImplementation(torch.autograd.Function): + @staticmethod + def forward(ctx, x): + ctx.save_for_backward(x) + return x.mul(torch.tanh(F.softplus(x))) # x * tanh(ln(1 + exp(x))) + + @staticmethod + def backward(ctx, grad_output): + x = ctx.saved_tensors[0] + sx = torch.sigmoid(x) + fx = F.softplus(x).tanh() + return grad_output * (fx + x * sx * (1 - fx * fx)) + + +class MemoryEfficientSwish(nn.Module): + def forward(self, x): + return SwishImplementation.apply(x) + + +class MemoryEfficientMish(nn.Module): + def forward(self, x): + return MishImplementation.apply(x) + + +class Swish(nn.Module): + def forward(self, x): + return x * torch.sigmoid(x) + + +class HardSwish(nn.Module): # https://arxiv.org/pdf/1905.02244.pdf + def forward(self, x): + return x * F.hardtanh(x + 3, 0., 6., True) / 6. + + +class DeformConv2d(nn.Module): + def __init__(self, inc, outc, kernel_size=3, padding=1, stride=1, bias=None, modulation=False): + """ + Args: + modulation (bool, optional): If True, Modulated Defomable Convolution (Deformable ConvNets v2). + """ + super(DeformConv2d, self).__init__() + self.kernel_size = kernel_size + self.padding = padding + self.stride = stride + self.zero_padding = nn.ZeroPad2d(padding) + self.conv = nn.Conv2d(inc, outc, kernel_size=kernel_size, stride=kernel_size, bias=bias) + + self.p_conv = nn.Conv2d(inc, 2*kernel_size*kernel_size, kernel_size=3, padding=1, stride=stride) + nn.init.constant_(self.p_conv.weight, 0) + self.p_conv.register_backward_hook(self._set_lr) + + self.modulation = modulation + if modulation: + self.m_conv = nn.Conv2d(inc, kernel_size*kernel_size, kernel_size=3, padding=1, stride=stride) + nn.init.constant_(self.m_conv.weight, 0) + self.m_conv.register_backward_hook(self._set_lr) + + @staticmethod + def _set_lr(module, grad_input, grad_output): + grad_input = (grad_input[i] * 0.1 for i in range(len(grad_input))) + grad_output = (grad_output[i] * 0.1 for i in range(len(grad_output))) + + def forward(self, x): + offset = self.p_conv(x) + if self.modulation: + m = torch.sigmoid(self.m_conv(x)) + + dtype = offset.data.type() + ks = self.kernel_size + N = offset.size(1) // 2 + + if self.padding: + x = self.zero_padding(x) + + # (b, 2N, h, w) + p = self._get_p(offset, dtype) + + # (b, h, w, 2N) + p = p.contiguous().permute(0, 2, 3, 1) + q_lt = p.detach().floor() + q_rb = q_lt + 1 + + q_lt = torch.cat([torch.clamp(q_lt[..., :N], 0, x.size(2)-1), torch.clamp(q_lt[..., N:], 0, x.size(3)-1)], dim=-1).long() + q_rb = torch.cat([torch.clamp(q_rb[..., :N], 0, x.size(2)-1), torch.clamp(q_rb[..., N:], 0, x.size(3)-1)], dim=-1).long() + q_lb = torch.cat([q_lt[..., :N], q_rb[..., N:]], dim=-1) + q_rt = torch.cat([q_rb[..., :N], q_lt[..., N:]], dim=-1) + + # clip p + p = torch.cat([torch.clamp(p[..., :N], 0, x.size(2)-1), torch.clamp(p[..., N:], 0, x.size(3)-1)], dim=-1) + + # bilinear kernel (b, h, w, N) + g_lt = (1 + (q_lt[..., :N].type_as(p) - p[..., :N])) * (1 + (q_lt[..., N:].type_as(p) - p[..., N:])) + g_rb = (1 - (q_rb[..., :N].type_as(p) - p[..., :N])) * (1 - (q_rb[..., N:].type_as(p) - p[..., N:])) + g_lb = (1 + (q_lb[..., :N].type_as(p) - p[..., :N])) * (1 - (q_lb[..., N:].type_as(p) - p[..., N:])) + g_rt = (1 - (q_rt[..., :N].type_as(p) - p[..., :N])) * (1 + (q_rt[..., N:].type_as(p) - p[..., N:])) + + # (b, c, h, w, N) + x_q_lt = self._get_x_q(x, q_lt, N) + x_q_rb = self._get_x_q(x, q_rb, N) + x_q_lb = self._get_x_q(x, q_lb, N) + x_q_rt = self._get_x_q(x, q_rt, N) + + # (b, c, h, w, N) + x_offset = g_lt.unsqueeze(dim=1) * x_q_lt + \ + g_rb.unsqueeze(dim=1) * x_q_rb + \ + g_lb.unsqueeze(dim=1) * x_q_lb + \ + g_rt.unsqueeze(dim=1) * x_q_rt + + # modulation + if self.modulation: + m = m.contiguous().permute(0, 2, 3, 1) + m = m.unsqueeze(dim=1) + m = torch.cat([m for _ in range(x_offset.size(1))], dim=1) + x_offset *= m + + x_offset = self._reshape_x_offset(x_offset, ks) + out = self.conv(x_offset) + + return out + + def _get_p_n(self, N, dtype): + p_n_x, p_n_y = torch.meshgrid( + torch.arange(-(self.kernel_size-1)//2, (self.kernel_size-1)//2+1), + torch.arange(-(self.kernel_size-1)//2, (self.kernel_size-1)//2+1)) + # (2N, 1) + p_n = torch.cat([torch.flatten(p_n_x), torch.flatten(p_n_y)], 0) + p_n = p_n.view(1, 2*N, 1, 1).type(dtype) + + return p_n + + def _get_p_0(self, h, w, N, dtype): + p_0_x, p_0_y = torch.meshgrid( + torch.arange(1, h*self.stride+1, self.stride), + torch.arange(1, w*self.stride+1, self.stride)) + p_0_x = torch.flatten(p_0_x).view(1, 1, h, w).repeat(1, N, 1, 1) + p_0_y = torch.flatten(p_0_y).view(1, 1, h, w).repeat(1, N, 1, 1) + p_0 = torch.cat([p_0_x, p_0_y], 1).type(dtype) + + return p_0 + + def _get_p(self, offset, dtype): + N, h, w = offset.size(1)//2, offset.size(2), offset.size(3) + + # (1, 2N, 1, 1) + p_n = self._get_p_n(N, dtype) + # (1, 2N, h, w) + p_0 = self._get_p_0(h, w, N, dtype) + p = p_0 + p_n + offset + return p + + def _get_x_q(self, x, q, N): + b, h, w, _ = q.size() + padded_w = x.size(3) + c = x.size(1) + # (b, c, h*w) + x = x.contiguous().view(b, c, -1) + + # (b, h, w, N) + index = q[..., :N]*padded_w + q[..., N:] # offset_x*w + offset_y + # (b, c, h*w*N) + index = index.contiguous().unsqueeze(dim=1).expand(-1, c, -1, -1, -1).contiguous().view(b, c, -1) + + x_offset = x.gather(dim=-1, index=index).contiguous().view(b, c, h, w, N) + + return x_offset + + @staticmethod + def _reshape_x_offset(x_offset, ks): + b, c, h, w, N = x_offset.size() + x_offset = torch.cat([x_offset[..., s:s+ks].contiguous().view(b, c, h, w*ks) for s in range(0, N, ks)], dim=-1) + x_offset = x_offset.contiguous().view(b, c, h*ks, w*ks) + + return x_offset + + +class GAP(nn.Module): + def __init__(self): + super(GAP, self).__init__() + self.avg_pool = nn.AdaptiveAvgPool2d(1) + def forward(self, x): + #b, c, _, _ = x.size() + return self.avg_pool(x)#.view(b, c) + + +class Silence(nn.Module): + def __init__(self): + super(Silence, self).__init__() + def forward(self, x): + return x + + +class ScaleChannel(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 + def __init__(self, layers): + super(ScaleChannel, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]] + return x.expand_as(a) * a + + +class ShiftChannel(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 + def __init__(self, layers): + super(ShiftChannel, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]] + return a.expand_as(x) + x + + +class ShiftChannel2D(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 + def __init__(self, layers): + super(ShiftChannel2D, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]].view(1,-1,1,1) + return a.expand_as(x) + x + + +class ControlChannel(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 + def __init__(self, layers): + super(ControlChannel, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]] + return a.expand_as(x) * x + + +class ControlChannel2D(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 + def __init__(self, layers): + super(ControlChannel2D, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]].view(1,-1,1,1) + return a.expand_as(x) * x + + +class AlternateChannel(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 + def __init__(self, layers): + super(AlternateChannel, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]] + return torch.cat([a.expand_as(x), x], dim=1) + + +class AlternateChannel2D(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 + def __init__(self, layers): + super(AlternateChannel2D, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]].view(1,-1,1,1) + return torch.cat([a.expand_as(x), x], dim=1) + + +class SelectChannel(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 + def __init__(self, layers): + super(SelectChannel, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]] + return a.sigmoid().expand_as(x) * x + + +class SelectChannel2D(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 + def __init__(self, layers): + super(SelectChannel2D, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]].view(1,-1,1,1) + return a.sigmoid().expand_as(x) * x + + +class ScaleSpatial(nn.Module): # weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 + def __init__(self, layers): + super(ScaleSpatial, self).__init__() + self.layers = layers # layer indices + + def forward(self, x, outputs): + a = outputs[self.layers[0]] + return x * a + + +class ImplicitA(nn.Module): + def __init__(self, channel): + super(ImplicitA, self).__init__() + self.channel = channel + self.implicit = nn.Parameter(torch.zeros(1, channel, 1, 1)) + nn.init.normal_(self.implicit, std=.02) + + def forward(self): + return self.implicit + + +class ImplicitC(nn.Module): + def __init__(self, channel): + super(ImplicitC, self).__init__() + self.channel = channel + self.implicit = nn.Parameter(torch.zeros(1, channel, 1, 1)) + nn.init.normal_(self.implicit, std=.02) + + def forward(self): + return self.implicit + + +class ImplicitM(nn.Module): + def __init__(self, channel): + super(ImplicitM, self).__init__() + self.channel = channel + self.implicit = nn.Parameter(torch.ones(1, channel, 1, 1)) + nn.init.normal_(self.implicit, mean=1., std=.02) + + def forward(self): + return self.implicit + + + +class Implicit2DA(nn.Module): + def __init__(self, atom, channel): + super(Implicit2DA, self).__init__() + self.channel = channel + self.implicit = nn.Parameter(torch.zeros(1, atom, channel, 1)) + nn.init.normal_(self.implicit, std=.02) + + def forward(self): + return self.implicit + + +class Implicit2DC(nn.Module): + def __init__(self, atom, channel): + super(Implicit2DC, self).__init__() + self.channel = channel + self.implicit = nn.Parameter(torch.zeros(1, atom, channel, 1)) + nn.init.normal_(self.implicit, std=.02) + + def forward(self): + return self.implicit + + +class Implicit2DM(nn.Module): + def __init__(self, atom, channel): + super(Implicit2DM, self).__init__() + self.channel = channel + self.implicit = nn.Parameter(torch.ones(1, atom, channel, 1)) + nn.init.normal_(self.implicit, mean=1., std=.02) + + def forward(self): + return self.implicit + + \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/YOLOR/utils/loss.py b/PyTorch/contrib/cv/detection/YOLOR/utils/loss.py index 9d2d3db08723ecf26ccc3f80675018a3ae487a3f..b3f75fb94de682168b1b728f398470860f7be04a 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/utils/loss.py +++ b/PyTorch/contrib/cv/detection/YOLOR/utils/loss.py @@ -1,356 +1,356 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Loss functions - -import torch -import torch.nn as nn - -from utils.general import bbox_iou -from utils.torch_utils import is_parallel - - -def smooth_BCE(eps=0.1): # https://github.com/ultralytics/yolov3/issues/238#issuecomment-598028441 - # return positive, negative label smoothing BCE targets - return 1.0 - 0.5 * eps, 0.5 * eps - - -class BCEBlurWithLogitsLoss(nn.Module): - # BCEwithLogitLoss() with reduced missing label effects. - def __init__(self, alpha=0.05): - super(BCEBlurWithLogitsLoss, self).__init__() - self.loss_fcn = nn.BCEWithLogitsLoss(reduction='none') # must be nn.BCEWithLogitsLoss() - self.alpha = alpha - - def forward(self, pred, true): - loss = self.loss_fcn(pred, true) - pred = torch.sigmoid(pred) # prob from logits - dx = pred - true # reduce only missing label effects - # dx = (pred - true).abs() # reduce missing label and false label effects - alpha_factor = 1 - torch.exp((dx - 1) / (self.alpha + 1e-4)) - loss *= alpha_factor - return loss.mean() - -class FocalLoss(nn.Module): - # Wraps focal loss around existing loss_fcn(), i.e. criteria = FocalLoss(nn.BCEWithLogitsLoss(), gamma=1.5) - def __init__(self, loss_fcn, gamma=1.5, alpha=0.25): - super(FocalLoss, self).__init__() - self.loss_fcn = loss_fcn # must be nn.BCEWithLogitsLoss() - self.gamma = gamma - self.alpha = alpha - self.reduction = loss_fcn.reduction - self.loss_fcn.reduction = 'none' # required to apply FL to each element - - def forward(self, pred, true): - loss = self.loss_fcn(pred, true) - # p_t = torch.exp(-loss) - # loss *= self.alpha * (1.000001 - p_t) ** self.gamma # non-zero power for gradient stability - - # TF implementation https://github.com/tensorflow/addons/blob/v0.7.1/tensorflow_addons/losses/focal_loss.py - pred_prob = torch.sigmoid(pred) # prob from logits - p_t = true * pred_prob + (1 - true) * (1 - pred_prob) - alpha_factor = true * self.alpha + (1 - true) * (1 - self.alpha) - modulating_factor = (1.0 - p_t) ** self.gamma - loss *= alpha_factor * modulating_factor - - if self.reduction == 'mean': - return loss.mean() - elif self.reduction == 'sum': - return loss.sum() - else: # 'none' - return loss - - -class DeterministicIndex(torch.autograd.Function): - @staticmethod - def forward(ctx, x, indices_list): - ctx.x = x - ctx.indices_list = indices_list - return x[indices_list[0], indices_list[1], :, indices_list[2], indices_list[3]] - - @staticmethod - def backward(ctx, grad_output): - tmp = torch.zeros_like(ctx.x) - ind0, ind1, ind2, ind3 = ctx.indices_list - tmp[ind0, ind1, :, ind2, ind3] = grad_output - return tmp, None - - -# @torchsnooper.snoop(output='/data/wyh/yolor/yolorDebug_1P640.txt') -def compute_loss(p, targets, model): # predictions, targets, model - device = targets.device - - targets = targets.T - for i in range(len(p)): - p[i] = p[i].permute(0, 1, 4, 2, 3) #(6, 3, 80, 80, 85)->(6, 3, 85, 80, 80) - - ft = torch.cuda.FloatTensor if p[0].is_cuda else torch.Tensor - lcls, lbox, lobj = ft([0]).to(device), ft([0]).to(device), ft([0]).to(device) - tcls, tbox, indices, anchors, targets_mask, targets_sum_mask = build_targets(p, targets, model) # targets - h = model.hyp # hyperparameters - - # Define criteria - BCEcls = nn.BCEWithLogitsLoss(pos_weight=ft([h['cls_pw']]), reduction='sum').to(device) - BCEobj = nn.BCEWithLogitsLoss(pos_weight=ft([h['obj_pw']]), reduction='mean').to(device) - - # class label smoothing https://arxiv.org/pdf/1902.04103.pdf eqn 3 - cp, cn = smooth_BCE(eps=0.0) - - # Focal loss - g = h['fl_gamma'] # focal loss gamma - if g > 0: - BCEcls, BCEobj = FocalLoss(BCEcls, g), FocalLoss(BCEobj, g) - - # per output - nt = 0 # number of targets - np = len(p) # number of outputs - balance = [4.0, 1.0, 0.4] if np == 3 else [4.0, 1.0, 0.4, 0.1] # P3-5 or P3-6 - balance = [4.0, 1.0, 0.5, 0.4, 0.1] if np == 5 else balance - for i, pi in enumerate(p): # layer index, layer predictions - b, a, gj, gi = indices[i] # image, anchor, gridy, gridx - allmask = targets_mask[i] - sum_mask = targets_sum_mask[i] - # tobj = torch.zeros_like(pi[..., 0], device=device) # target obj - tobj = torch.zeros_like(pi[:, :, 0, :, :]).to(device) # target obj - - nb = b.shape[0] # number of targets - if sum_mask.item() > 0: - nt += nb # cumulative targets - # ps = pi[b, a,:, gj, gi] # prediction subset corresponding to targets - ps = DeterministicIndex.apply(pi, (b, a, gj, gi)).permute(1, 0).contiguous() - # GIoU - pxy = ps.index_select(0, torch.tensor([0, 1], device=device)) - pwh = ps.index_select(0, torch.tensor([2, 3], device=device)) - - pxy = pxy.sigmoid() * 2. - 0.5 - pwh = (pwh.sigmoid() * 2) ** 2 * (anchors[i].T) - pbox = torch.cat((pxy, pwh), 0) # predicted box - giou = bbox_iou(pbox, tbox[i], x1y1x2y2=False, GIoU=True) - giou = giou * (allmask) + (1. - allmask) - lbox += (1.0 - giou).sum() / (sum_mask) # giou loss - # Obj - giou = giou * (allmask) - tobj[b, a, gj, gi] = (1.0 - model.gr) + model.gr * giou.detach().clamp(0).type(tobj.dtype) # giou ratio - - # Class - if model.nc > 1: # cls loss (only if multiple classes) - tmp = ps[5:, :] - tmp = tmp * (allmask) - (1.- allmask) * 50. - t = torch.full_like(tmp, cn).to(device) # targets - range_nb = torch.arange(nb, device=device).long() - t[tcls[i], range_nb] = cp - - t = t * (allmask) - lcls += (BCEcls(tmp, t) / (sum_mask * t.shape[0]).float()) # BCE - - # Append targets to text file - # with open('targets.txt', 'a') as file: - # [file.write('%11.5g ' * 4 % tuple(x) + '\n') for x in torch.cat((txy[i], twh[i]), 1)] - - # lobj += BCEobj(pi[..., 4], tobj) * balance[i] # obj loss - lobj += BCEobj(pi[:, :, 4, :, :], tobj) * balance[i] # obj loss - - s = 3 / np # output count scaling - lbox *= h['box'] * s - lobj *= h['obj'] * s * (1.4 if np >= 4 else 1.) - lcls *= h['cls'] * s - bs = tobj.shape[0] # batch size - - loss = lbox + lobj + lcls - return loss * bs, torch.cat((lbox, lobj, lcls, loss)).detach() - - -def build_targets(p, targets, model): - # Build targets for compute_loss(), input targets(image,class,x,y,w,h) - na, nt, device, batch_size = 3, targets.shape[1], targets.device, p[0].shape[0] - - # align targets in batch size - nt_max = 32 * batch_size - while nt > nt_max: - nt_max *= 2 - print('**************** nt max=', nt_max) - max_target = torch.zeros(6, nt_max, device=device) # (6, nt) - for i in range(6): - try: - max_target[i, :nt] = targets[i, :] - # print('Check------', max_target.shape, max_target.device, device) - # print('Check------', targets.shape, targets.device, device) - except Exception as e: - print(e) - # print('Check------', max_target.shape, max_target.device, device) - # print('Check------', targets.shape, targets.device, device) - - tcls, tbox, indices, anch, targets_mask, targets_sum_mask = [], [], [], [], [], [] - gain = torch.ones(6, device=device) # normalized to gridspace gain - off_list = [ - torch.tensor([[1.], [0.]], device=device), - torch.tensor([[0.], [1.]], device=device), - torch.tensor([[-1.], [0.]], device=device), - torch.tensor([[0.], [-1.]], device=device) - ] - # # create indices with anchor and max_target - # # anchor tensor, same as .repeat_interleave(nt) (x, 3) - at = torch.arange(na).view(na, 1).repeat(1, nt_max) - a = at.view(-1) - a = torch.cat((a, a, a, a, a), 0) - - g = 0.5 # offset - # multi_gpu = type(model) in (nn.parallel.DataParallel, nn.parallel.DistributedDataParallel) - multi_gpu = is_parallel(model) - for i, j in enumerate(model.module.yolo_layers if multi_gpu else model.yolo_layers): - # get number of grid points and anchor vec for this yolo layer - anchors = model.module.module_list[j].anchor_vec if multi_gpu else model.module_list[j].anchor_vec - # iou of targets-anchors b,a,c,y,x-> b,a,y,x,c - # gain[2:] = torch.tensor(p[i].shape)[[3, 2, 3, 2]].float() # xyxy gain - gain[2:] = torch.tensor(p[i].shape)[[4, 3, 4, 3]].float() # xyxy gain - - # Match targets to anchors - t, offsets = max_target * gain[:, None], 0 - allmask = torch.zeros((na * nt_max)).to(device) - sum_mask = torch.zeros((1)).to(device) - if nt: - r = t[None, 4:6, :] / anchors[..., None] # wh ratio - fmask = torch.max(r, 1. / r).max(1)[0] < model.hyp['anchor_t'] # compare - fmask = fmask.view(1, -1) - # j = wh_iou(anchors, t[:, 4:6]) > model.hyp['iou_t'] # iou(3,n) = wh_iou(anchors(3,2), gwh(n,2)) - t = t.repeat(1, 1, na).view(6, -1) # filter - - # overlaps - gxy = t.index_select(0, torch.tensor([2, 3], device=device)) - z = torch.zeros_like(gxy) - - jk = (gxy % 1. < g) & (gxy > 1.) - lm = (gxy % 1. > (1 - g)) & (gxy < (gain[[2, 3]][:, None] - 1.)) - jk, lm = jk&fmask, lm&fmask - allmask = torch.cat((fmask, jk, lm), 0).view(1, -1).float() - t = torch.cat((t, t, t, t, t), 1) - offsets = torch.cat((z, z + off_list[0], z + off_list[1], z + off_list[2], z + off_list[3]), 1) * g - - # print('----------------------------------------------------------------------------------') - # print('a.shape, t.shape:') - # print(a.shape, t.shape) - # print('gxy.shape, offsets.shape') - # print(gxy.shape, offsets.shape) - # print('fmask.shape, allmask.shape, jk, lm:') - # print(fmask.shape, allmask.shape, jk.shape, lm.shape) - # print('----------------------------------------------------------------------------------') - - sum_mask = allmask.sum() - t = t * allmask - - # Define - b = t.index_select(0, torch.tensor([0], device=device)).long().view(-1) #(3072 * 5) - c = t.index_select(0, torch.tensor([1], device=device)).long().view(-1) #(3072 * 5) - gxy = t.index_select(0, torch.tensor([2, 3], device=device)) #(2, 3072 * 5) - gwh = t.index_select(0, torch.tensor([4, 5], device=device)) #(2, 3072 * 5) - gij = gxy - offsets - gij2 = gij.long() - gi = gij2.index_select(0, torch.tensor([0], device=device)).view(-1) #(2, 3072 * 5) - gj = gij2.index_select(0, torch.tensor([1], device=device)).view(-1) #(2, 3072 * 5) - - # Append - # indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices - indices.append((b, a, gj, gi)) # image, anchor, grid indices - tbox.append(torch.cat((gxy - gij2.float(), gwh), 0)) # box - anch.append(anchors[a]) # anchors - tcls.append(c) # class - targets_mask.append(allmask) - targets_sum_mask.append(sum_mask) - - return tcls, tbox, indices, anch, targets_mask, targets_sum_mask - -# def build_targets(p, targets, model): -# nt = targets.shape[0] # number of anchors, targets -# tcls, tbox, indices, anch, targets_mask, targets_sum_mask = [], [], [], [], [], [] -# gain = torch.ones(6, device=targets.device) # normalized to gridspace gain -# off = torch.tensor([[1, 0], [0, 1], [-1, 0], [0, -1]], device=targets.device).float() # overlap offsets - -# # align targets in batch size -# batch_size = p[0].shape[0] -# nt_max = 32 * batch_size -# while nt > nt_max: -# nt_max *= 2 -# print('**************** nt max=', nt_max) -# max_target = torch.zeros(nt_max, 6, device=targets.device) # (nt,6) -# for i in range(6): -# max_target[:nt, i] = targets[:, i] - -# g = 0.5 # offset -# multi_gpu = is_parallel(model) -# for i, jj in enumerate(model.module.yolo_layers if multi_gpu else model.yolo_layers): -# # get number of grid points and anchor vec for this yolo layer -# anchors = model.module.module_list[jj].anchor_vec if multi_gpu else model.module_list[jj].anchor_vec -# gain[2:] = torch.tensor(p[i].shape)[[3, 2, 3, 2]] # xyxy gain - -# # Match targets to anchors -# a, t, offsets = [], max_target * gain, 0 - -# if nt: -# na = anchors.shape[0] # number of anchors -# allmask = torch.zeros((na * nt_max)).to(targets.device) -# sum_mask = torch.zeros((1)).to(targets.device) -# at = torch.arange(na).view(na, 1).repeat(1, nt_max) # anchor tensor, same as .repeat_interleave(nt) -# r = t[None, :, 4:6] / anchors[:, None] # wh ratio -# fmask = torch.max(r, 1. / r).max(2)[0] < model.hyp['anchor_t'] # compare -# # j = wh_iou(anchors, t[:, 4:6]) > model.hyp['iou_t'] # iou(3,n) = wh_iou(anchors(3,2), gwh(n,2)) -# a, t = at[fmask], t.repeat(na, 1, 1)[fmask] # filter - -# print('----------------------------------------------------------------------------------') -# print('a.shape, at.shape, t.shape:') -# print(a.shape, at.shape, t.shape) -# print('----------------------------------------------------------------------------------') - -# # overlaps -# gxy = t[:, 2:4] # grid xy -# z = torch.zeros_like(gxy) -# j, k = ((gxy % 1. < g) & (gxy > 1.)).T -# l, m = ((gxy % 1. > (1 - g)) & (gxy < (gain[[2, 3]] - 1.))).T - -# print(a.shape, a[j].shape, a[k].shape, a[l].shape, a[m].shape) -# print(t.shape, t[j].shape, t[k].shape, t[l].shape, t[m].shape) - -# a, t = torch.cat((a, a[j], a[k], a[l], a[m]), 0), torch.cat((t, t[j], t[k], t[l], t[m]), 0) -# offsets = torch.cat((z, z[j] + off[0], z[k] + off[1], z[l] + off[2], z[m] + off[3]), 0) * g - -# allmask = torch.cat((j, k, l, m), 1).float() -# sum_mask = allmask.sum() - -# print('----------------------------------------------------------------------------------') -# print('a.shape, t.shape:') -# print(a.shape, t.shape) -# print('gxy.shape, offsets.shape') -# print(gxy.shape, offsets.shape) -# print('fmask.shape, allmask.shape, j, k, l, m:') -# print(fmask.shape, allmask.shape, j.shape, k.shape, l.shape, m.shape) -# print('----------------------------------------------------------------------------------') - -# t = t * allmask - -# # Define -# b, c = t[:, :2].long().T # image, class -# gxy = t[:, 2:4] # grid xy -# gwh = t[:, 4:6] # grid wh -# gij = (gxy - offsets).long() -# gi, gj = gij.T # grid xy indices - -# # Append -# #indices.append((b, a, gj, gi)) # image, anchor, grid indices -# indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices -# tbox.append(torch.cat((gxy - gij, gwh), 1)) # box -# anch.append(anchors[a]) # anchors -# tcls.append(c) # class -# targets_mask.append(allmask) -# targets_sum_mask.append(sum_mask) - -# return tcls, tbox, indices, anch, targets_mask, targets_sum_mask +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Loss functions + +import torch +import torch.nn as nn + +from utils.general import bbox_iou +from utils.torch_utils import is_parallel + + +def smooth_BCE(eps=0.1): # https://github.com/ultralytics/yolov3/issues/238#issuecomment-598028441 + # return positive, negative label smoothing BCE targets + return 1.0 - 0.5 * eps, 0.5 * eps + + +class BCEBlurWithLogitsLoss(nn.Module): + # BCEwithLogitLoss() with reduced missing label effects. + def __init__(self, alpha=0.05): + super(BCEBlurWithLogitsLoss, self).__init__() + self.loss_fcn = nn.BCEWithLogitsLoss(reduction='none') # must be nn.BCEWithLogitsLoss() + self.alpha = alpha + + def forward(self, pred, true): + loss = self.loss_fcn(pred, true) + pred = torch.sigmoid(pred) # prob from logits + dx = pred - true # reduce only missing label effects + # dx = (pred - true).abs() # reduce missing label and false label effects + alpha_factor = 1 - torch.exp((dx - 1) / (self.alpha + 1e-4)) + loss *= alpha_factor + return loss.mean() + +class FocalLoss(nn.Module): + # Wraps focal loss around existing loss_fcn(), i.e. criteria = FocalLoss(nn.BCEWithLogitsLoss(), gamma=1.5) + def __init__(self, loss_fcn, gamma=1.5, alpha=0.25): + super(FocalLoss, self).__init__() + self.loss_fcn = loss_fcn # must be nn.BCEWithLogitsLoss() + self.gamma = gamma + self.alpha = alpha + self.reduction = loss_fcn.reduction + self.loss_fcn.reduction = 'none' # required to apply FL to each element + + def forward(self, pred, true): + loss = self.loss_fcn(pred, true) + # p_t = torch.exp(-loss) + # loss *= self.alpha * (1.000001 - p_t) ** self.gamma # non-zero power for gradient stability + + # TF implementation https://github.com/tensorflow/addons/blob/v0.7.1/tensorflow_addons/losses/focal_loss.py + pred_prob = torch.sigmoid(pred) # prob from logits + p_t = true * pred_prob + (1 - true) * (1 - pred_prob) + alpha_factor = true * self.alpha + (1 - true) * (1 - self.alpha) + modulating_factor = (1.0 - p_t) ** self.gamma + loss *= alpha_factor * modulating_factor + + if self.reduction == 'mean': + return loss.mean() + elif self.reduction == 'sum': + return loss.sum() + else: # 'none' + return loss + + +class DeterministicIndex(torch.autograd.Function): + @staticmethod + def forward(ctx, x, indices_list): + ctx.x = x + ctx.indices_list = indices_list + return x[indices_list[0], indices_list[1], :, indices_list[2], indices_list[3]] + + @staticmethod + def backward(ctx, grad_output): + tmp = torch.zeros_like(ctx.x) + ind0, ind1, ind2, ind3 = ctx.indices_list + tmp[ind0, ind1, :, ind2, ind3] = grad_output + return tmp, None + + +# @torchsnooper.snoop(output='/data/wyh/yolor/yolorDebug_1P640.txt') +def compute_loss(p, targets, model): # predictions, targets, model + device = targets.device + + targets = targets.T + for i in range(len(p)): + p[i] = p[i].permute(0, 1, 4, 2, 3) #(6, 3, 80, 80, 85)->(6, 3, 85, 80, 80) + + ft = torch.cuda.FloatTensor if p[0].is_cuda else torch.Tensor + lcls, lbox, lobj = ft([0]).to(device), ft([0]).to(device), ft([0]).to(device) + tcls, tbox, indices, anchors, targets_mask, targets_sum_mask = build_targets(p, targets, model) # targets + h = model.hyp # hyperparameters + + # Define criteria + BCEcls = nn.BCEWithLogitsLoss(pos_weight=ft([h['cls_pw']]), reduction='sum').to(device) + BCEobj = nn.BCEWithLogitsLoss(pos_weight=ft([h['obj_pw']]), reduction='mean').to(device) + + # class label smoothing https://arxiv.org/pdf/1902.04103.pdf eqn 3 + cp, cn = smooth_BCE(eps=0.0) + + # Focal loss + g = h['fl_gamma'] # focal loss gamma + if g > 0: + BCEcls, BCEobj = FocalLoss(BCEcls, g), FocalLoss(BCEobj, g) + + # per output + nt = 0 # number of targets + np = len(p) # number of outputs + balance = [4.0, 1.0, 0.4] if np == 3 else [4.0, 1.0, 0.4, 0.1] # P3-5 or P3-6 + balance = [4.0, 1.0, 0.5, 0.4, 0.1] if np == 5 else balance + for i, pi in enumerate(p): # layer index, layer predictions + b, a, gj, gi = indices[i] # image, anchor, gridy, gridx + allmask = targets_mask[i] + sum_mask = targets_sum_mask[i] + # tobj = torch.zeros_like(pi[..., 0], device=device) # target obj + tobj = torch.zeros_like(pi[:, :, 0, :, :]).to(device) # target obj + + nb = b.shape[0] # number of targets + if sum_mask.item() > 0: + nt += nb # cumulative targets + # ps = pi[b, a,:, gj, gi] # prediction subset corresponding to targets + ps = DeterministicIndex.apply(pi, (b, a, gj, gi)).permute(1, 0).contiguous() + # GIoU + pxy = ps.index_select(0, torch.tensor([0, 1], device=device)) + pwh = ps.index_select(0, torch.tensor([2, 3], device=device)) + + pxy = pxy.sigmoid() * 2. - 0.5 + pwh = (pwh.sigmoid() * 2) ** 2 * (anchors[i].T) + pbox = torch.cat((pxy, pwh), 0) # predicted box + giou = bbox_iou(pbox, tbox[i], x1y1x2y2=False, GIoU=True) + giou = giou * (allmask) + (1. - allmask) + lbox += (1.0 - giou).sum() / (sum_mask) # giou loss + # Obj + giou = giou * (allmask) + tobj[b, a, gj, gi] = (1.0 - model.gr) + model.gr * giou.detach().clamp(0).type(tobj.dtype) # giou ratio + + # Class + if model.nc > 1: # cls loss (only if multiple classes) + tmp = ps[5:, :] + tmp = tmp * (allmask) - (1.- allmask) * 50. + t = torch.full_like(tmp, cn).to(device) # targets + range_nb = torch.arange(nb, device=device).long() + t[tcls[i], range_nb] = cp + + t = t * (allmask) + lcls += (BCEcls(tmp, t) / (sum_mask * t.shape[0]).float()) # BCE + + # Append targets to text file + # with open('targets.txt', 'a') as file: + # [file.write('%11.5g ' * 4 % tuple(x) + '\n') for x in torch.cat((txy[i], twh[i]), 1)] + + # lobj += BCEobj(pi[..., 4], tobj) * balance[i] # obj loss + lobj += BCEobj(pi[:, :, 4, :, :], tobj) * balance[i] # obj loss + + s = 3 / np # output count scaling + lbox *= h['box'] * s + lobj *= h['obj'] * s * (1.4 if np >= 4 else 1.) + lcls *= h['cls'] * s + bs = tobj.shape[0] # batch size + + loss = lbox + lobj + lcls + return loss * bs, torch.cat((lbox, lobj, lcls, loss)).detach() + + +def build_targets(p, targets, model): + # Build targets for compute_loss(), input targets(image,class,x,y,w,h) + na, nt, device, batch_size = 3, targets.shape[1], targets.device, p[0].shape[0] + + # align targets in batch size + nt_max = 32 * batch_size + while nt > nt_max: + nt_max *= 2 + print('**************** nt max=', nt_max) + max_target = torch.zeros(6, nt_max, device=device) # (6, nt) + for i in range(6): + try: + max_target[i, :nt] = targets[i, :] + # print('Check------', max_target.shape, max_target.device, device) + # print('Check------', targets.shape, targets.device, device) + except Exception as e: + print(e) + # print('Check------', max_target.shape, max_target.device, device) + # print('Check------', targets.shape, targets.device, device) + + tcls, tbox, indices, anch, targets_mask, targets_sum_mask = [], [], [], [], [], [] + gain = torch.ones(6, device=device) # normalized to gridspace gain + off_list = [ + torch.tensor([[1.], [0.]], device=device), + torch.tensor([[0.], [1.]], device=device), + torch.tensor([[-1.], [0.]], device=device), + torch.tensor([[0.], [-1.]], device=device) + ] + # # create indices with anchor and max_target + # # anchor tensor, same as .repeat_interleave(nt) (x, 3) + at = torch.arange(na).view(na, 1).repeat(1, nt_max) + a = at.view(-1) + a = torch.cat((a, a, a, a, a), 0) + + g = 0.5 # offset + # multi_gpu = type(model) in (nn.parallel.DataParallel, nn.parallel.DistributedDataParallel) + multi_gpu = is_parallel(model) + for i, j in enumerate(model.module.yolo_layers if multi_gpu else model.yolo_layers): + # get number of grid points and anchor vec for this yolo layer + anchors = model.module.module_list[j].anchor_vec if multi_gpu else model.module_list[j].anchor_vec + # iou of targets-anchors b,a,c,y,x-> b,a,y,x,c + # gain[2:] = torch.tensor(p[i].shape)[[3, 2, 3, 2]].float() # xyxy gain + gain[2:] = torch.tensor(p[i].shape)[[4, 3, 4, 3]].float() # xyxy gain + + # Match targets to anchors + t, offsets = max_target * gain[:, None], 0 + allmask = torch.zeros((na * nt_max)).to(device) + sum_mask = torch.zeros((1)).to(device) + if nt: + r = t[None, 4:6, :] / anchors[..., None] # wh ratio + fmask = torch.max(r, 1. / r).max(1)[0] < model.hyp['anchor_t'] # compare + fmask = fmask.view(1, -1) + # j = wh_iou(anchors, t[:, 4:6]) > model.hyp['iou_t'] # iou(3,n) = wh_iou(anchors(3,2), gwh(n,2)) + t = t.repeat(1, 1, na).view(6, -1) # filter + + # overlaps + gxy = t.index_select(0, torch.tensor([2, 3], device=device)) + z = torch.zeros_like(gxy) + + jk = (gxy % 1. < g) & (gxy > 1.) + lm = (gxy % 1. > (1 - g)) & (gxy < (gain[[2, 3]][:, None] - 1.)) + jk, lm = jk&fmask, lm&fmask + allmask = torch.cat((fmask, jk, lm), 0).view(1, -1).float() + t = torch.cat((t, t, t, t, t), 1) + offsets = torch.cat((z, z + off_list[0], z + off_list[1], z + off_list[2], z + off_list[3]), 1) * g + + # print('----------------------------------------------------------------------------------') + # print('a.shape, t.shape:') + # print(a.shape, t.shape) + # print('gxy.shape, offsets.shape') + # print(gxy.shape, offsets.shape) + # print('fmask.shape, allmask.shape, jk, lm:') + # print(fmask.shape, allmask.shape, jk.shape, lm.shape) + # print('----------------------------------------------------------------------------------') + + sum_mask = allmask.sum() + t = t * allmask + + # Define + b = t.index_select(0, torch.tensor([0], device=device)).long().view(-1) #(3072 * 5) + c = t.index_select(0, torch.tensor([1], device=device)).long().view(-1) #(3072 * 5) + gxy = t.index_select(0, torch.tensor([2, 3], device=device)) #(2, 3072 * 5) + gwh = t.index_select(0, torch.tensor([4, 5], device=device)) #(2, 3072 * 5) + gij = gxy - offsets + gij2 = gij.long() + gi = gij2.index_select(0, torch.tensor([0], device=device)).view(-1) #(2, 3072 * 5) + gj = gij2.index_select(0, torch.tensor([1], device=device)).view(-1) #(2, 3072 * 5) + + # Append + # indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices + indices.append((b, a, gj, gi)) # image, anchor, grid indices + tbox.append(torch.cat((gxy - gij2.float(), gwh), 0)) # box + anch.append(anchors[a]) # anchors + tcls.append(c) # class + targets_mask.append(allmask) + targets_sum_mask.append(sum_mask) + + return tcls, tbox, indices, anch, targets_mask, targets_sum_mask + +# def build_targets(p, targets, model): +# nt = targets.shape[0] # number of anchors, targets +# tcls, tbox, indices, anch, targets_mask, targets_sum_mask = [], [], [], [], [], [] +# gain = torch.ones(6, device=targets.device) # normalized to gridspace gain +# off = torch.tensor([[1, 0], [0, 1], [-1, 0], [0, -1]], device=targets.device).float() # overlap offsets + +# # align targets in batch size +# batch_size = p[0].shape[0] +# nt_max = 32 * batch_size +# while nt > nt_max: +# nt_max *= 2 +# print('**************** nt max=', nt_max) +# max_target = torch.zeros(nt_max, 6, device=targets.device) # (nt,6) +# for i in range(6): +# max_target[:nt, i] = targets[:, i] + +# g = 0.5 # offset +# multi_gpu = is_parallel(model) +# for i, jj in enumerate(model.module.yolo_layers if multi_gpu else model.yolo_layers): +# # get number of grid points and anchor vec for this yolo layer +# anchors = model.module.module_list[jj].anchor_vec if multi_gpu else model.module_list[jj].anchor_vec +# gain[2:] = torch.tensor(p[i].shape)[[3, 2, 3, 2]] # xyxy gain + +# # Match targets to anchors +# a, t, offsets = [], max_target * gain, 0 + +# if nt: +# na = anchors.shape[0] # number of anchors +# allmask = torch.zeros((na * nt_max)).to(targets.device) +# sum_mask = torch.zeros((1)).to(targets.device) +# at = torch.arange(na).view(na, 1).repeat(1, nt_max) # anchor tensor, same as .repeat_interleave(nt) +# r = t[None, :, 4:6] / anchors[:, None] # wh ratio +# fmask = torch.max(r, 1. / r).max(2)[0] < model.hyp['anchor_t'] # compare +# # j = wh_iou(anchors, t[:, 4:6]) > model.hyp['iou_t'] # iou(3,n) = wh_iou(anchors(3,2), gwh(n,2)) +# a, t = at[fmask], t.repeat(na, 1, 1)[fmask] # filter + +# print('----------------------------------------------------------------------------------') +# print('a.shape, at.shape, t.shape:') +# print(a.shape, at.shape, t.shape) +# print('----------------------------------------------------------------------------------') + +# # overlaps +# gxy = t[:, 2:4] # grid xy +# z = torch.zeros_like(gxy) +# j, k = ((gxy % 1. < g) & (gxy > 1.)).T +# l, m = ((gxy % 1. > (1 - g)) & (gxy < (gain[[2, 3]] - 1.))).T + +# print(a.shape, a[j].shape, a[k].shape, a[l].shape, a[m].shape) +# print(t.shape, t[j].shape, t[k].shape, t[l].shape, t[m].shape) + +# a, t = torch.cat((a, a[j], a[k], a[l], a[m]), 0), torch.cat((t, t[j], t[k], t[l], t[m]), 0) +# offsets = torch.cat((z, z[j] + off[0], z[k] + off[1], z[l] + off[2], z[m] + off[3]), 0) * g + +# allmask = torch.cat((j, k, l, m), 1).float() +# sum_mask = allmask.sum() + +# print('----------------------------------------------------------------------------------') +# print('a.shape, t.shape:') +# print(a.shape, t.shape) +# print('gxy.shape, offsets.shape') +# print(gxy.shape, offsets.shape) +# print('fmask.shape, allmask.shape, j, k, l, m:') +# print(fmask.shape, allmask.shape, j.shape, k.shape, l.shape, m.shape) +# print('----------------------------------------------------------------------------------') + +# t = t * allmask + +# # Define +# b, c = t[:, :2].long().T # image, class +# gxy = t[:, 2:4] # grid xy +# gwh = t[:, 4:6] # grid wh +# gij = (gxy - offsets).long() +# gi, gj = gij.T # grid xy indices + +# # Append +# #indices.append((b, a, gj, gi)) # image, anchor, grid indices +# indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices +# tbox.append(torch.cat((gxy - gij, gwh), 1)) # box +# anch.append(anchors[a]) # anchors +# tcls.append(c) # class +# targets_mask.append(allmask) +# targets_sum_mask.append(sum_mask) + +# return tcls, tbox, indices, anch, targets_mask, targets_sum_mask diff --git a/PyTorch/contrib/cv/detection/YOLOR/utils/metrics.py b/PyTorch/contrib/cv/detection/YOLOR/utils/metrics.py index fc4fa4f77d897f0c93debcad4cb26eb253c632eb..51622cb73d8ea438157f73bce771bfe25c00452f 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/utils/metrics.py +++ b/PyTorch/contrib/cv/detection/YOLOR/utils/metrics.py @@ -1,154 +1,154 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Model validation metrics - -import matplotlib.pyplot as plt -import numpy as np - - -def fitness(x): - # Model fitness as a weighted combination of metrics - w = [0.0, 0.0, 0.1, 0.9] # weights for [P, R, mAP@0.5, mAP@0.5:0.95] - return (x[:, :4] * w).sum(1) - - -def fitness_p(x): - # Model fitness as a weighted combination of metrics - w = [1.0, 0.0, 0.0, 0.0] # weights for [P, R, mAP@0.5, mAP@0.5:0.95] - return (x[:, :4] * w).sum(1) - - -def fitness_r(x): - # Model fitness as a weighted combination of metrics - w = [0.0, 1.0, 0.0, 0.0] # weights for [P, R, mAP@0.5, mAP@0.5:0.95] - return (x[:, :4] * w).sum(1) - - -def fitness_ap50(x): - # Model fitness as a weighted combination of metrics - w = [0.0, 0.0, 1.0, 0.0] # weights for [P, R, mAP@0.5, mAP@0.5:0.95] - return (x[:, :4] * w).sum(1) - - -def fitness_ap(x): - # Model fitness as a weighted combination of metrics - w = [0.0, 0.0, 0.0, 1.0] # weights for [P, R, mAP@0.5, mAP@0.5:0.95] - return (x[:, :4] * w).sum(1) - - -def fitness_f(x): - # Model fitness as a weighted combination of metrics - #w = [0.0, 0.0, 0.0, 1.0] # weights for [P, R, mAP@0.5, mAP@0.5:0.95] - return ((x[:, 0]*x[:, 1])/(x[:, 0]+x[:, 1])) - - -def ap_per_class(tp, conf, pred_cls, target_cls, plot=False, fname='precision-recall_curve.png'): - """ Compute the average precision, given the recall and precision curves. - Source: https://github.com/rafaelpadilla/Object-Detection-Metrics. - # Arguments - tp: True positives (nparray, nx1 or nx10). - conf: Objectness value from 0-1 (nparray). - pred_cls: Predicted object classes (nparray). - target_cls: True object classes (nparray). - plot: Plot precision-recall curve at mAP@0.5 - fname: Plot filename - # Returns - The average precision as computed in py-faster-rcnn. - """ - - # Sort by objectness - i = np.argsort(-conf) - tp, conf, pred_cls = tp[i], conf[i], pred_cls[i] - - # Find unique classes - unique_classes = np.unique(target_cls) - - # Create Precision-Recall curve and compute AP for each class - px, py = np.linspace(0, 1, 1000), [] # for plotting - pr_score = 0.1 # score to evaluate P and R https://github.com/ultralytics/yolov3/issues/898 - s = [unique_classes.shape[0], tp.shape[1]] # number class, number iou thresholds (i.e. 10 for mAP0.5...0.95) - ap, p, r = np.zeros(s), np.zeros(s), np.zeros(s) - for ci, c in enumerate(unique_classes): - i = pred_cls == c - n_l = (target_cls == c).sum() # number of labels - n_p = i.sum() # number of predictions - - if n_p == 0 or n_l == 0: - continue - else: - # Accumulate FPs and TPs - fpc = (1 - tp[i]).cumsum(0) - tpc = tp[i].cumsum(0) - - # Recall - recall = tpc / (n_l + 1e-16) # recall curve - r[ci] = np.interp(-pr_score, -conf[i], recall[:, 0]) # r at pr_score, negative x, xp because xp decreases - - # Precision - precision = tpc / (tpc + fpc) # precision curve - p[ci] = np.interp(-pr_score, -conf[i], precision[:, 0]) # p at pr_score - - # AP from recall-precision curve - for j in range(tp.shape[1]): - ap[ci, j], mpre, mrec = compute_ap(recall[:, j], precision[:, j]) - if j == 0: - py.append(np.interp(px, mrec, mpre)) # precision at mAP@0.5 - - # Compute F1 score (harmonic mean of precision and recall) - f1 = 2 * p * r / (p + r + 1e-16) - - if plot: - py = np.stack(py, axis=1) - fig, ax = plt.subplots(1, 1, figsize=(5, 5)) - ax.plot(px, py, linewidth=0.5, color='grey') # plot(recall, precision) - ax.plot(px, py.mean(1), linewidth=2, color='blue', label='all classes %.3f mAP@0.5' % ap[:, 0].mean()) - ax.set_xlabel('Recall') - ax.set_ylabel('Precision') - ax.set_xlim(0, 1) - ax.set_ylim(0, 1) - plt.legend() - fig.tight_layout() - fig.savefig(fname, dpi=200) - - return p, r, ap, f1, unique_classes.astype('int32') - - -def compute_ap(recall, precision): - """ Compute the average precision, given the recall and precision curves. - Source: https://github.com/rbgirshick/py-faster-rcnn. - # Arguments - recall: The recall curve (list). - precision: The precision curve (list). - # Returns - The average precision as computed in py-faster-rcnn. - """ - - # Append sentinel values to beginning and end - mrec = np.concatenate(([0.0], recall, [1.0])) - mpre = np.concatenate(([1.0], precision, [0.0])) - - # Compute the precision envelope - mpre = np.flip(np.maximum.accumulate(np.flip(mpre))) - - # Integrate area under curve - method = 'interp' # methods: 'continuous', 'interp' - if method == 'interp': - x = np.linspace(0, 1, 101) # 101-point interp (COCO) - ap = np.trapz(np.interp(x, mrec, mpre), x) # integrate - else: # 'continuous' - i = np.where(mrec[1:] != mrec[:-1])[0] # points where x axis (recall) changes - ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1]) # area under curve - - return ap, mpre, mrec +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Model validation metrics + +import matplotlib.pyplot as plt +import numpy as np + + +def fitness(x): + # Model fitness as a weighted combination of metrics + w = [0.0, 0.0, 0.1, 0.9] # weights for [P, R, mAP@0.5, mAP@0.5:0.95] + return (x[:, :4] * w).sum(1) + + +def fitness_p(x): + # Model fitness as a weighted combination of metrics + w = [1.0, 0.0, 0.0, 0.0] # weights for [P, R, mAP@0.5, mAP@0.5:0.95] + return (x[:, :4] * w).sum(1) + + +def fitness_r(x): + # Model fitness as a weighted combination of metrics + w = [0.0, 1.0, 0.0, 0.0] # weights for [P, R, mAP@0.5, mAP@0.5:0.95] + return (x[:, :4] * w).sum(1) + + +def fitness_ap50(x): + # Model fitness as a weighted combination of metrics + w = [0.0, 0.0, 1.0, 0.0] # weights for [P, R, mAP@0.5, mAP@0.5:0.95] + return (x[:, :4] * w).sum(1) + + +def fitness_ap(x): + # Model fitness as a weighted combination of metrics + w = [0.0, 0.0, 0.0, 1.0] # weights for [P, R, mAP@0.5, mAP@0.5:0.95] + return (x[:, :4] * w).sum(1) + + +def fitness_f(x): + # Model fitness as a weighted combination of metrics + #w = [0.0, 0.0, 0.0, 1.0] # weights for [P, R, mAP@0.5, mAP@0.5:0.95] + return ((x[:, 0]*x[:, 1])/(x[:, 0]+x[:, 1])) + + +def ap_per_class(tp, conf, pred_cls, target_cls, plot=False, fname='precision-recall_curve.png'): + """ Compute the average precision, given the recall and precision curves. + Source: https://github.com/rafaelpadilla/Object-Detection-Metrics. + # Arguments + tp: True positives (nparray, nx1 or nx10). + conf: Objectness value from 0-1 (nparray). + pred_cls: Predicted object classes (nparray). + target_cls: True object classes (nparray). + plot: Plot precision-recall curve at mAP@0.5 + fname: Plot filename + # Returns + The average precision as computed in py-faster-rcnn. + """ + + # Sort by objectness + i = np.argsort(-conf) + tp, conf, pred_cls = tp[i], conf[i], pred_cls[i] + + # Find unique classes + unique_classes = np.unique(target_cls) + + # Create Precision-Recall curve and compute AP for each class + px, py = np.linspace(0, 1, 1000), [] # for plotting + pr_score = 0.1 # score to evaluate P and R https://github.com/ultralytics/yolov3/issues/898 + s = [unique_classes.shape[0], tp.shape[1]] # number class, number iou thresholds (i.e. 10 for mAP0.5...0.95) + ap, p, r = np.zeros(s), np.zeros(s), np.zeros(s) + for ci, c in enumerate(unique_classes): + i = pred_cls == c + n_l = (target_cls == c).sum() # number of labels + n_p = i.sum() # number of predictions + + if n_p == 0 or n_l == 0: + continue + else: + # Accumulate FPs and TPs + fpc = (1 - tp[i]).cumsum(0) + tpc = tp[i].cumsum(0) + + # Recall + recall = tpc / (n_l + 1e-16) # recall curve + r[ci] = np.interp(-pr_score, -conf[i], recall[:, 0]) # r at pr_score, negative x, xp because xp decreases + + # Precision + precision = tpc / (tpc + fpc) # precision curve + p[ci] = np.interp(-pr_score, -conf[i], precision[:, 0]) # p at pr_score + + # AP from recall-precision curve + for j in range(tp.shape[1]): + ap[ci, j], mpre, mrec = compute_ap(recall[:, j], precision[:, j]) + if j == 0: + py.append(np.interp(px, mrec, mpre)) # precision at mAP@0.5 + + # Compute F1 score (harmonic mean of precision and recall) + f1 = 2 * p * r / (p + r + 1e-16) + + if plot: + py = np.stack(py, axis=1) + fig, ax = plt.subplots(1, 1, figsize=(5, 5)) + ax.plot(px, py, linewidth=0.5, color='grey') # plot(recall, precision) + ax.plot(px, py.mean(1), linewidth=2, color='blue', label='all classes %.3f mAP@0.5' % ap[:, 0].mean()) + ax.set_xlabel('Recall') + ax.set_ylabel('Precision') + ax.set_xlim(0, 1) + ax.set_ylim(0, 1) + plt.legend() + fig.tight_layout() + fig.savefig(fname, dpi=200) + + return p, r, ap, f1, unique_classes.astype('int32') + + +def compute_ap(recall, precision): + """ Compute the average precision, given the recall and precision curves. + Source: https://github.com/rbgirshick/py-faster-rcnn. + # Arguments + recall: The recall curve (list). + precision: The precision curve (list). + # Returns + The average precision as computed in py-faster-rcnn. + """ + + # Append sentinel values to beginning and end + mrec = np.concatenate(([0.0], recall, [1.0])) + mpre = np.concatenate(([1.0], precision, [0.0])) + + # Compute the precision envelope + mpre = np.flip(np.maximum.accumulate(np.flip(mpre))) + + # Integrate area under curve + method = 'interp' # methods: 'continuous', 'interp' + if method == 'interp': + x = np.linspace(0, 1, 101) # 101-point interp (COCO) + ap = np.trapz(np.interp(x, mrec, mpre), x) # integrate + else: # 'continuous' + i = np.where(mrec[1:] != mrec[:-1])[0] # points where x axis (recall) changes + ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1]) # area under curve + + return ap, mpre, mrec diff --git a/PyTorch/contrib/cv/detection/YOLOR/utils/parse_config.py b/PyTorch/contrib/cv/detection/YOLOR/utils/parse_config.py index 8315f86a19f752c906fad8791e408f582b5fb1af..f8bfcb5f3abb182c66aa4de042372ac3ab68fee1 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/utils/parse_config.py +++ b/PyTorch/contrib/cv/detection/YOLOR/utils/parse_config.py @@ -1,85 +1,85 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os - -import numpy as np - - -def parse_model_cfg(path): - # Parse the yolo *.cfg file and return module definitions path may be 'cfg/yolov3.cfg', 'yolov3.cfg', or 'yolov3' - if not path.endswith('.cfg'): # add .cfg suffix if omitted - path += '.cfg' - if not os.path.exists(path) and os.path.exists('cfg' + os.sep + path): # add cfg/ prefix if omitted - path = 'cfg' + os.sep + path - - with open(path, 'r') as f: - lines = f.read().split('\n') - lines = [x for x in lines if x and not x.startswith('#')] - lines = [x.rstrip().lstrip() for x in lines] # get rid of fringe whitespaces - mdefs = [] # module definitions - for line in lines: - if line.startswith('['): # This marks the start of a new block - mdefs.append({}) - mdefs[-1]['type'] = line[1:-1].rstrip() - if mdefs[-1]['type'] == 'convolutional': - mdefs[-1]['batch_normalize'] = 0 # pre-populate with zeros (may be overwritten later) - - else: - key, val = line.split("=") - key = key.rstrip() - - if key == 'anchors': # return nparray - mdefs[-1][key] = np.array([float(x) for x in val.split(',')]).reshape((-1, 2)) # np anchors - elif (key in ['from', 'layers', 'mask']) or (key == 'size' and ',' in val): # return array - mdefs[-1][key] = [int(x) for x in val.split(',')] - else: - val = val.strip() - if val.isnumeric(): # return int or float - mdefs[-1][key] = int(val) if (int(val) - float(val)) == 0 else float(val) - else: - mdefs[-1][key] = val # return string - - # Check all fields are supported - supported = ['type', 'batch_normalize', 'filters', 'size', 'stride', 'pad', 'activation', 'layers', 'groups', - 'from', 'mask', 'anchors', 'classes', 'num', 'jitter', 'ignore_thresh', 'truth_thresh', 'random', - 'stride_x', 'stride_y', 'weights_type', 'weights_normalization', 'scale_x_y', 'beta_nms', 'nms_kind', - 'iou_loss', 'iou_normalizer', 'cls_normalizer', 'iou_thresh', 'atoms', 'na', 'nc'] - - f = [] # fields - for x in mdefs[1:]: - [f.append(k) for k in x if k not in f] - u = [x for x in f if x not in supported] # unsupported fields - assert not any(u), "Unsupported fields %s in %s. See https://github.com/ultralytics/yolov3/issues/631" % (u, path) - - return mdefs - - -def parse_data_cfg(path): - # Parses the data configuration file - if not os.path.exists(path) and os.path.exists('data' + os.sep + path): # add data/ prefix if omitted - path = 'data' + os.sep + path - - with open(path, 'r') as f: - lines = f.readlines() - - options = dict() - for line in lines: - line = line.strip() - if line == '' or line.startswith('#'): - continue - key, val = line.split('=') - options[key.strip()] = val.strip() - - return options +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import numpy as np + + +def parse_model_cfg(path): + # Parse the yolo *.cfg file and return module definitions path may be 'cfg/yolov3.cfg', 'yolov3.cfg', or 'yolov3' + if not path.endswith('.cfg'): # add .cfg suffix if omitted + path += '.cfg' + if not os.path.exists(path) and os.path.exists('cfg' + os.sep + path): # add cfg/ prefix if omitted + path = 'cfg' + os.sep + path + + with open(path, 'r') as f: + lines = f.read().split('\n') + lines = [x for x in lines if x and not x.startswith('#')] + lines = [x.rstrip().lstrip() for x in lines] # get rid of fringe whitespaces + mdefs = [] # module definitions + for line in lines: + if line.startswith('['): # This marks the start of a new block + mdefs.append({}) + mdefs[-1]['type'] = line[1:-1].rstrip() + if mdefs[-1]['type'] == 'convolutional': + mdefs[-1]['batch_normalize'] = 0 # pre-populate with zeros (may be overwritten later) + + else: + key, val = line.split("=") + key = key.rstrip() + + if key == 'anchors': # return nparray + mdefs[-1][key] = np.array([float(x) for x in val.split(',')]).reshape((-1, 2)) # np anchors + elif (key in ['from', 'layers', 'mask']) or (key == 'size' and ',' in val): # return array + mdefs[-1][key] = [int(x) for x in val.split(',')] + else: + val = val.strip() + if val.isnumeric(): # return int or float + mdefs[-1][key] = int(val) if (int(val) - float(val)) == 0 else float(val) + else: + mdefs[-1][key] = val # return string + + # Check all fields are supported + supported = ['type', 'batch_normalize', 'filters', 'size', 'stride', 'pad', 'activation', 'layers', 'groups', + 'from', 'mask', 'anchors', 'classes', 'num', 'jitter', 'ignore_thresh', 'truth_thresh', 'random', + 'stride_x', 'stride_y', 'weights_type', 'weights_normalization', 'scale_x_y', 'beta_nms', 'nms_kind', + 'iou_loss', 'iou_normalizer', 'cls_normalizer', 'iou_thresh', 'atoms', 'na', 'nc'] + + f = [] # fields + for x in mdefs[1:]: + [f.append(k) for k in x if k not in f] + u = [x for x in f if x not in supported] # unsupported fields + assert not any(u), "Unsupported fields %s in %s. See https://github.com/ultralytics/yolov3/issues/631" % (u, path) + + return mdefs + + +def parse_data_cfg(path): + # Parses the data configuration file + if not os.path.exists(path) and os.path.exists('data' + os.sep + path): # add data/ prefix if omitted + path = 'data' + os.sep + path + + with open(path, 'r') as f: + lines = f.readlines() + + options = dict() + for line in lines: + line = line.strip() + if line == '' or line.startswith('#'): + continue + key, val = line.split('=') + options[key.strip()] = val.strip() + + return options diff --git a/PyTorch/contrib/cv/detection/YOLOR/utils/plots.py b/PyTorch/contrib/cv/detection/YOLOR/utils/plots.py index af98b973bbd214fc48d62277d608467ba20afc71..dff7b2c63f9c9063e12c56cb895072e007747167 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/utils/plots.py +++ b/PyTorch/contrib/cv/detection/YOLOR/utils/plots.py @@ -1,394 +1,394 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Plotting utils - -import glob -import math -import os -import random -from copy import copy -from pathlib import Path - -import cv2 -import matplotlib -import matplotlib.pyplot as plt -import numpy as np -import torch -import yaml -from PIL import Image -from scipy.signal import butter, filtfilt - -from utils.general import xywh2xyxy, xyxy2xywh -from utils.metrics import fitness - -# Settings -matplotlib.use('Agg') # for writing to files only - - -def color_list(): - # Return first 10 plt colors as (r,g,b) https://stackoverflow.com/questions/51350872/python-from-color-name-to-rgb - def hex2rgb(h): - return tuple(int(h[1 + i:1 + i + 2], 16) for i in (0, 2, 4)) - - return [hex2rgb(h) for h in plt.rcParams['axes.prop_cycle'].by_key()['color']] - - -def hist2d(x, y, n=100): - # 2d histogram used in labels.png and evolve.png - xedges, yedges = np.linspace(x.min(), x.max(), n), np.linspace(y.min(), y.max(), n) - hist, xedges, yedges = np.histogram2d(x, y, (xedges, yedges)) - xidx = np.clip(np.digitize(x, xedges) - 1, 0, hist.shape[0] - 1) - yidx = np.clip(np.digitize(y, yedges) - 1, 0, hist.shape[1] - 1) - return np.log(hist[xidx, yidx]) - - -def butter_lowpass_filtfilt(data, cutoff=1500, fs=50000, order=5): - # https://stackoverflow.com/questions/28536191/how-to-filter-smooth-with-scipy-numpy - def butter_lowpass(cutoff, fs, order): - nyq = 0.5 * fs - normal_cutoff = cutoff / nyq - return butter(order, normal_cutoff, btype='low', analog=False) - - b, a = butter_lowpass(cutoff, fs, order=order) - return filtfilt(b, a, data) # forward-backward filter - - -def plot_one_box(x, img, color=None, label=None, line_thickness=None): - # Plots one bounding box on image img - tl = line_thickness or round(0.002 * (img.shape[0] + img.shape[1]) / 2) + 1 # line/font thickness - color = color or [random.randint(0, 255) for _ in range(3)] - c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3])) - cv2.rectangle(img, c1, c2, color, thickness=tl, lineType=cv2.LINE_AA) - if label: - tf = max(tl - 1, 1) # font thickness - t_size = cv2.getTextSize(label, 0, fontScale=tl / 3, thickness=tf)[0] - c2 = c1[0] + t_size[0], c1[1] - t_size[1] - 3 - cv2.rectangle(img, c1, c2, color, -1, cv2.LINE_AA) # filled - cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA) - - -def plot_wh_methods(): # from utils.general import *; plot_wh_methods() - # Compares the two methods for width-height anchor multiplication - # https://github.com/ultralytics/yolov3/issues/168 - x = np.arange(-4.0, 4.0, .1) - ya = np.exp(x) - yb = torch.sigmoid(torch.from_numpy(x)).numpy() * 2 - - fig = plt.figure(figsize=(6, 3), dpi=150) - plt.plot(x, ya, '.-', label='YOLO') - plt.plot(x, yb ** 2, '.-', label='YOLO ^2') - plt.plot(x, yb ** 1.6, '.-', label='YOLO ^1.6') - plt.xlim(left=-4, right=4) - plt.ylim(bottom=0, top=6) - plt.xlabel('input') - plt.ylabel('output') - plt.grid() - plt.legend() - fig.tight_layout() - fig.savefig('comparison.png', dpi=200) - - -def output_to_target(output, width, height): - # Convert model output to target format [batch_id, class_id, x, y, w, h, conf] - if isinstance(output, torch.Tensor): - output = output.cpu().numpy() - - targets = [] - for i, o in enumerate(output): - if o is not None: - for pred in o: - box = pred[:4] - w = (box[2] - box[0]) / width - h = (box[3] - box[1]) / height - x = box[0] / width + w / 2 - y = box[1] / height + h / 2 - conf = pred[4] - cls = int(pred[5]) - - targets.append([item.cpu() if isinstance(item, torch.Tensor) else item for item in [i, cls, x, y, w, h, conf]]) - - return np.array(targets) - - -def plot_images(images, targets, paths=None, fname='images.jpg', names=None, max_size=640, max_subplots=16): - # Plot image grid with labels - - if isinstance(images, torch.Tensor): - images = images.cpu().float().numpy() - if isinstance(targets, torch.Tensor): - targets = targets.cpu().numpy() - - # un-normalise - if np.max(images[0]) <= 1: - images *= 255 - - tl = 3 # line thickness - tf = max(tl - 1, 1) # font thickness - bs, _, h, w = images.shape # batch size, _, height, width - bs = min(bs, max_subplots) # limit plot images - ns = np.ceil(bs ** 0.5) # number of subplots (square) - - # Check if we should resize - scale_factor = max_size / max(h, w) - if scale_factor < 1: - h = math.ceil(scale_factor * h) - w = math.ceil(scale_factor * w) - - colors = color_list() # list of colors - mosaic = np.full((int(ns * h), int(ns * w), 3), 255, dtype=np.uint8) # init - for i, img in enumerate(images): - if i == max_subplots: # if last batch has fewer images than we expect - break - - block_x = int(w * (i // ns)) - block_y = int(h * (i % ns)) - - img = img.transpose(1, 2, 0) - if scale_factor < 1: - img = cv2.resize(img, (w, h)) - - mosaic[block_y:block_y + h, block_x:block_x + w, :] = img - if len(targets) > 0: - image_targets = targets[targets[:, 0] == i] - boxes = xywh2xyxy(image_targets[:, 2:6]).T - classes = image_targets[:, 1].astype('int') - labels = image_targets.shape[1] == 6 # labels if no conf column - conf = None if labels else image_targets[:, 6] # check for confidence presence (label vs pred) - - boxes[[0, 2]] *= w - boxes[[0, 2]] += block_x - boxes[[1, 3]] *= h - boxes[[1, 3]] += block_y - for j, box in enumerate(boxes.T): - cls = int(classes[j]) - color = colors[cls % len(colors)] - cls = names[cls] if names else cls - if labels or conf[j] > 0.25: # 0.25 conf thresh - label = '%s' % cls if labels else '%s %.1f' % (cls, conf[j]) - plot_one_box(box, mosaic, label=label, color=color, line_thickness=tl) - - # Draw image filename labels - if paths: - label = Path(paths[i]).name[:40] # trim to 40 char - t_size = cv2.getTextSize(label, 0, fontScale=tl / 3, thickness=tf)[0] - cv2.putText(mosaic, label, (block_x + 5, block_y + t_size[1] + 5), 0, tl / 3, [220, 220, 220], thickness=tf, - lineType=cv2.LINE_AA) - - # Image border - cv2.rectangle(mosaic, (block_x, block_y), (block_x + w, block_y + h), (255, 255, 255), thickness=3) - - if fname: - r = min(1280. / max(h, w) / ns, 1.0) # ratio to limit image size - mosaic = cv2.resize(mosaic, (int(ns * w * r), int(ns * h * r)), interpolation=cv2.INTER_AREA) - # cv2.imwrite(fname, cv2.cvtColor(mosaic, cv2.COLOR_BGR2RGB)) # cv2 save - Image.fromarray(mosaic).save(fname) # PIL save - return mosaic - - -def plot_lr_scheduler(optimizer, scheduler, epochs=300, save_dir=''): - # Plot LR simulating training for full epochs - optimizer, scheduler = copy(optimizer), copy(scheduler) # do not modify originals - y = [] - for _ in range(epochs): - scheduler.step() - y.append(optimizer.param_groups[0]['lr']) - plt.plot(y, '.-', label='LR') - plt.xlabel('epoch') - plt.ylabel('LR') - plt.grid() - plt.xlim(0, epochs) - plt.ylim(0) - plt.tight_layout() - plt.savefig(Path(save_dir) / 'LR.png', dpi=200) - - -def plot_test_txt(): # from utils.general import *; plot_test() - # Plot test.txt histograms - x = np.loadtxt('test.txt', dtype=np.float32) - box = xyxy2xywh(x[:, :4]) - cx, cy = box[:, 0], box[:, 1] - - fig, ax = plt.subplots(1, 1, figsize=(6, 6), tight_layout=True) - ax.hist2d(cx, cy, bins=600, cmax=10, cmin=0) - ax.set_aspect('equal') - plt.savefig('hist2d.png', dpi=300) - - fig, ax = plt.subplots(1, 2, figsize=(12, 6), tight_layout=True) - ax[0].hist(cx, bins=600) - ax[1].hist(cy, bins=600) - plt.savefig('hist1d.png', dpi=200) - - -def plot_targets_txt(): # from utils.general import *; plot_targets_txt() - # Plot targets.txt histograms - x = np.loadtxt('targets.txt', dtype=np.float32).T - s = ['x targets', 'y targets', 'width targets', 'height targets'] - fig, ax = plt.subplots(2, 2, figsize=(8, 8), tight_layout=True) - ax = ax.ravel() - for i in range(4): - ax[i].hist(x[i], bins=100, label='%.3g +/- %.3g' % (x[i].mean(), x[i].std())) - ax[i].legend() - ax[i].set_title(s[i]) - plt.savefig('targets.jpg', dpi=200) - - -def plot_study_txt(f='study.txt', x=None): # from utils.general import *; plot_study_txt() - # Plot study.txt generated by test.py - fig, ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True) - ax = ax.ravel() - - fig2, ax2 = plt.subplots(1, 1, figsize=(8, 4), tight_layout=True) - for f in ['study/study_coco_yolo%s.txt' % x for x in ['s', 'm', 'l', 'x']]: - y = np.loadtxt(f, dtype=np.float32, usecols=[0, 1, 2, 3, 7, 8, 9], ndmin=2).T - x = np.arange(y.shape[1]) if x is None else np.array(x) - s = ['P', 'R', 'mAP@.5', 'mAP@.5:.95', 't_inference (ms/img)', 't_NMS (ms/img)', 't_total (ms/img)'] - for i in range(7): - ax[i].plot(x, y[i], '.-', linewidth=2, markersize=8) - ax[i].set_title(s[i]) - - j = y[3].argmax() + 1 - ax2.plot(y[6, :j], y[3, :j] * 1E2, '.-', linewidth=2, markersize=8, - label=Path(f).stem.replace('study_coco_', '').replace('yolo', 'YOLO')) - - ax2.plot(1E3 / np.array([209, 140, 97, 58, 35, 18]), [34.6, 40.5, 43.0, 47.5, 49.7, 51.5], - 'k.-', linewidth=2, markersize=8, alpha=.25, label='EfficientDet') - - ax2.grid() - ax2.set_xlim(0, 30) - ax2.set_ylim(28, 50) - ax2.set_yticks(np.arange(30, 55, 5)) - ax2.set_xlabel('GPU Speed (ms/img)') - ax2.set_ylabel('COCO AP val') - ax2.legend(loc='lower right') - plt.savefig('study_mAP_latency.png', dpi=300) - plt.savefig(f.replace('.txt', '.png'), dpi=300) - - -def plot_labels(labels, save_dir=''): - # plot dataset labels - c, b = labels[:, 0], labels[:, 1:].transpose() # classes, boxes - nc = int(c.max() + 1) # number of classes - - fig, ax = plt.subplots(2, 2, figsize=(8, 8), tight_layout=True) - ax = ax.ravel() - ax[0].hist(c, bins=np.linspace(0, nc, nc + 1) - 0.5, rwidth=0.8) - ax[0].set_xlabel('classes') - ax[1].scatter(b[0], b[1], c=hist2d(b[0], b[1], 90), cmap='jet') - ax[1].set_xlabel('x') - ax[1].set_ylabel('y') - ax[2].scatter(b[2], b[3], c=hist2d(b[2], b[3], 90), cmap='jet') - ax[2].set_xlabel('width') - ax[2].set_ylabel('height') - plt.savefig(Path(save_dir) / 'labels.png', dpi=200) - plt.close() - - # seaborn correlogram - try: - import seaborn as sns - import pandas as pd - x = pd.DataFrame(b.transpose(), columns=['x', 'y', 'width', 'height']) - sns.pairplot(x, corner=True, diag_kind='hist', kind='scatter', markers='o', - plot_kws=dict(s=3, edgecolor=None, linewidth=1, alpha=0.02), - diag_kws=dict(bins=50)) - plt.savefig(Path(save_dir) / 'labels_correlogram.png', dpi=200) - plt.close() - except Exception as e: - pass - - -def plot_evolution(yaml_file='data/hyp.finetune.yaml'): # from utils.general import *; plot_evolution() - # Plot hyperparameter evolution results in evolve.txt - with open(yaml_file) as f: - hyp = yaml.load(f, Loader=yaml.FullLoader) - x = np.loadtxt('evolve.txt', ndmin=2) - f = fitness(x) - # weights = (f - f.min()) ** 2 # for weighted results - plt.figure(figsize=(10, 12), tight_layout=True) - matplotlib.rc('font', **{'size': 8}) - for i, (k, v) in enumerate(hyp.items()): - y = x[:, i + 7] - # mu = (y * weights).sum() / weights.sum() # best weighted result - mu = y[f.argmax()] # best single result - plt.subplot(6, 5, i + 1) - plt.scatter(y, f, c=hist2d(y, f, 20), cmap='viridis', alpha=.8, edgecolors='none') - plt.plot(mu, f.max(), 'k+', markersize=15) - plt.title('%s = %.3g' % (k, mu), fontdict={'size': 9}) # limit to 40 characters - if i % 5 != 0: - plt.yticks([]) - print('%15s: %.3g' % (k, mu)) - plt.savefig('evolve.png', dpi=200) - print('\nPlot saved as evolve.png') - - -def plot_results_overlay(start=0, stop=0): # from utils.general import *; plot_results_overlay() - # Plot training 'results*.txt', overlaying train and val losses - s = ['train', 'train', 'train', 'Precision', 'mAP@0.5', 'val', 'val', 'val', 'Recall', 'mAP@0.5:0.95'] # legends - t = ['Box', 'Objectness', 'Classification', 'P-R', 'mAP-F1'] # titles - for f in sorted(glob.glob('results*.txt') + glob.glob('../../Downloads/results*.txt')): - results = np.loadtxt(f, usecols=[2, 3, 4, 8, 9, 12, 13, 14, 10, 11], ndmin=2).T - n = results.shape[1] # number of rows - x = range(start, min(stop, n) if stop else n) - fig, ax = plt.subplots(1, 5, figsize=(14, 3.5), tight_layout=True) - ax = ax.ravel() - for i in range(5): - for j in [i, i + 5]: - y = results[j, x] - ax[i].plot(x, y, marker='.', label=s[j]) - # y_smooth = butter_lowpass_filtfilt(y) - # ax[i].plot(x, np.gradient(y_smooth), marker='.', label=s[j]) - - ax[i].set_title(t[i]) - ax[i].legend() - ax[i].set_ylabel(f) if i == 0 else None # add filename - fig.savefig(f.replace('.txt', '.png'), dpi=200) - - -def plot_results(start=0, stop=0, bucket='', id=(), labels=(), save_dir=''): - # from utils.general import *; plot_results(save_dir='runs/train/exp0') - # Plot training 'results*.txt' - fig, ax = plt.subplots(2, 5, figsize=(12, 6)) - ax = ax.ravel() - s = ['Box', 'Objectness', 'Classification', 'Precision', 'Recall', - 'val Box', 'val Objectness', 'val Classification', 'mAP@0.5', 'mAP@0.5:0.95'] - if bucket: - # os.system('rm -rf storage.googleapis.com') - # files = ['https://storage.googleapis.com/%s/results%g.txt' % (bucket, x) for x in id] - files = ['%g.txt' % x for x in id] - c = ('gsutil cp ' + '%s ' * len(files) + '.') % tuple('gs://%s/%g.txt' % (bucket, x) for x in id) - os.system(c) - else: - files = glob.glob(str(Path(save_dir) / '*.txt')) + glob.glob('../../Downloads/results*.txt') - assert len(files), 'No results.txt files found in %s, nothing to plot.' % os.path.abspath(save_dir) - for fi, f in enumerate(files): - try: - results = np.loadtxt(f, usecols=[2, 3, 4, 8, 9, 12, 13, 14, 10, 11], ndmin=2).T - n = results.shape[1] # number of rows - x = range(start, min(stop, n) if stop else n) - for i in range(10): - y = results[i, x] - if i in [0, 1, 2, 5, 6, 7]: - y[y == 0] = np.nan # don't show zero loss values - # y /= y[0] # normalize - label = labels[fi] if len(labels) else Path(f).stem - ax[i].plot(x, y, marker='.', label=label, linewidth=1, markersize=6) - ax[i].set_title(s[i]) - # if i in [5, 6, 7]: # share train and val loss y axes - # ax[i].get_shared_y_axes().join(ax[i], ax[i - 5]) - except Exception as e: - print('Warning: Plotting error for %s; %s' % (f, e)) - - fig.tight_layout() - ax[1].legend() - fig.savefig(Path(save_dir) / 'results.png', dpi=200) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Plotting utils + +import glob +import math +import os +import random +from copy import copy +from pathlib import Path + +import cv2 +import matplotlib +import matplotlib.pyplot as plt +import numpy as np +import torch +import yaml +from PIL import Image +from scipy.signal import butter, filtfilt + +from utils.general import xywh2xyxy, xyxy2xywh +from utils.metrics import fitness + +# Settings +matplotlib.use('Agg') # for writing to files only + + +def color_list(): + # Return first 10 plt colors as (r,g,b) https://stackoverflow.com/questions/51350872/python-from-color-name-to-rgb + def hex2rgb(h): + return tuple(int(h[1 + i:1 + i + 2], 16) for i in (0, 2, 4)) + + return [hex2rgb(h) for h in plt.rcParams['axes.prop_cycle'].by_key()['color']] + + +def hist2d(x, y, n=100): + # 2d histogram used in labels.png and evolve.png + xedges, yedges = np.linspace(x.min(), x.max(), n), np.linspace(y.min(), y.max(), n) + hist, xedges, yedges = np.histogram2d(x, y, (xedges, yedges)) + xidx = np.clip(np.digitize(x, xedges) - 1, 0, hist.shape[0] - 1) + yidx = np.clip(np.digitize(y, yedges) - 1, 0, hist.shape[1] - 1) + return np.log(hist[xidx, yidx]) + + +def butter_lowpass_filtfilt(data, cutoff=1500, fs=50000, order=5): + # https://stackoverflow.com/questions/28536191/how-to-filter-smooth-with-scipy-numpy + def butter_lowpass(cutoff, fs, order): + nyq = 0.5 * fs + normal_cutoff = cutoff / nyq + return butter(order, normal_cutoff, btype='low', analog=False) + + b, a = butter_lowpass(cutoff, fs, order=order) + return filtfilt(b, a, data) # forward-backward filter + + +def plot_one_box(x, img, color=None, label=None, line_thickness=None): + # Plots one bounding box on image img + tl = line_thickness or round(0.002 * (img.shape[0] + img.shape[1]) / 2) + 1 # line/font thickness + color = color or [random.randint(0, 255) for _ in range(3)] + c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3])) + cv2.rectangle(img, c1, c2, color, thickness=tl, lineType=cv2.LINE_AA) + if label: + tf = max(tl - 1, 1) # font thickness + t_size = cv2.getTextSize(label, 0, fontScale=tl / 3, thickness=tf)[0] + c2 = c1[0] + t_size[0], c1[1] - t_size[1] - 3 + cv2.rectangle(img, c1, c2, color, -1, cv2.LINE_AA) # filled + cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA) + + +def plot_wh_methods(): # from utils.general import *; plot_wh_methods() + # Compares the two methods for width-height anchor multiplication + # https://github.com/ultralytics/yolov3/issues/168 + x = np.arange(-4.0, 4.0, .1) + ya = np.exp(x) + yb = torch.sigmoid(torch.from_numpy(x)).numpy() * 2 + + fig = plt.figure(figsize=(6, 3), dpi=150) + plt.plot(x, ya, '.-', label='YOLO') + plt.plot(x, yb ** 2, '.-', label='YOLO ^2') + plt.plot(x, yb ** 1.6, '.-', label='YOLO ^1.6') + plt.xlim(left=-4, right=4) + plt.ylim(bottom=0, top=6) + plt.xlabel('input') + plt.ylabel('output') + plt.grid() + plt.legend() + fig.tight_layout() + fig.savefig('comparison.png', dpi=200) + + +def output_to_target(output, width, height): + # Convert model output to target format [batch_id, class_id, x, y, w, h, conf] + if isinstance(output, torch.Tensor): + output = output.cpu().numpy() + + targets = [] + for i, o in enumerate(output): + if o is not None: + for pred in o: + box = pred[:4] + w = (box[2] - box[0]) / width + h = (box[3] - box[1]) / height + x = box[0] / width + w / 2 + y = box[1] / height + h / 2 + conf = pred[4] + cls = int(pred[5]) + + targets.append([item.cpu() if isinstance(item, torch.Tensor) else item for item in [i, cls, x, y, w, h, conf]]) + + return np.array(targets) + + +def plot_images(images, targets, paths=None, fname='images.jpg', names=None, max_size=640, max_subplots=16): + # Plot image grid with labels + + if isinstance(images, torch.Tensor): + images = images.cpu().float().numpy() + if isinstance(targets, torch.Tensor): + targets = targets.cpu().numpy() + + # un-normalise + if np.max(images[0]) <= 1: + images *= 255 + + tl = 3 # line thickness + tf = max(tl - 1, 1) # font thickness + bs, _, h, w = images.shape # batch size, _, height, width + bs = min(bs, max_subplots) # limit plot images + ns = np.ceil(bs ** 0.5) # number of subplots (square) + + # Check if we should resize + scale_factor = max_size / max(h, w) + if scale_factor < 1: + h = math.ceil(scale_factor * h) + w = math.ceil(scale_factor * w) + + colors = color_list() # list of colors + mosaic = np.full((int(ns * h), int(ns * w), 3), 255, dtype=np.uint8) # init + for i, img in enumerate(images): + if i == max_subplots: # if last batch has fewer images than we expect + break + + block_x = int(w * (i // ns)) + block_y = int(h * (i % ns)) + + img = img.transpose(1, 2, 0) + if scale_factor < 1: + img = cv2.resize(img, (w, h)) + + mosaic[block_y:block_y + h, block_x:block_x + w, :] = img + if len(targets) > 0: + image_targets = targets[targets[:, 0] == i] + boxes = xywh2xyxy(image_targets[:, 2:6]).T + classes = image_targets[:, 1].astype('int') + labels = image_targets.shape[1] == 6 # labels if no conf column + conf = None if labels else image_targets[:, 6] # check for confidence presence (label vs pred) + + boxes[[0, 2]] *= w + boxes[[0, 2]] += block_x + boxes[[1, 3]] *= h + boxes[[1, 3]] += block_y + for j, box in enumerate(boxes.T): + cls = int(classes[j]) + color = colors[cls % len(colors)] + cls = names[cls] if names else cls + if labels or conf[j] > 0.25: # 0.25 conf thresh + label = '%s' % cls if labels else '%s %.1f' % (cls, conf[j]) + plot_one_box(box, mosaic, label=label, color=color, line_thickness=tl) + + # Draw image filename labels + if paths: + label = Path(paths[i]).name[:40] # trim to 40 char + t_size = cv2.getTextSize(label, 0, fontScale=tl / 3, thickness=tf)[0] + cv2.putText(mosaic, label, (block_x + 5, block_y + t_size[1] + 5), 0, tl / 3, [220, 220, 220], thickness=tf, + lineType=cv2.LINE_AA) + + # Image border + cv2.rectangle(mosaic, (block_x, block_y), (block_x + w, block_y + h), (255, 255, 255), thickness=3) + + if fname: + r = min(1280. / max(h, w) / ns, 1.0) # ratio to limit image size + mosaic = cv2.resize(mosaic, (int(ns * w * r), int(ns * h * r)), interpolation=cv2.INTER_AREA) + # cv2.imwrite(fname, cv2.cvtColor(mosaic, cv2.COLOR_BGR2RGB)) # cv2 save + Image.fromarray(mosaic).save(fname) # PIL save + return mosaic + + +def plot_lr_scheduler(optimizer, scheduler, epochs=300, save_dir=''): + # Plot LR simulating training for full epochs + optimizer, scheduler = copy(optimizer), copy(scheduler) # do not modify originals + y = [] + for _ in range(epochs): + scheduler.step() + y.append(optimizer.param_groups[0]['lr']) + plt.plot(y, '.-', label='LR') + plt.xlabel('epoch') + plt.ylabel('LR') + plt.grid() + plt.xlim(0, epochs) + plt.ylim(0) + plt.tight_layout() + plt.savefig(Path(save_dir) / 'LR.png', dpi=200) + + +def plot_test_txt(): # from utils.general import *; plot_test() + # Plot test.txt histograms + x = np.loadtxt('test.txt', dtype=np.float32) + box = xyxy2xywh(x[:, :4]) + cx, cy = box[:, 0], box[:, 1] + + fig, ax = plt.subplots(1, 1, figsize=(6, 6), tight_layout=True) + ax.hist2d(cx, cy, bins=600, cmax=10, cmin=0) + ax.set_aspect('equal') + plt.savefig('hist2d.png', dpi=300) + + fig, ax = plt.subplots(1, 2, figsize=(12, 6), tight_layout=True) + ax[0].hist(cx, bins=600) + ax[1].hist(cy, bins=600) + plt.savefig('hist1d.png', dpi=200) + + +def plot_targets_txt(): # from utils.general import *; plot_targets_txt() + # Plot targets.txt histograms + x = np.loadtxt('targets.txt', dtype=np.float32).T + s = ['x targets', 'y targets', 'width targets', 'height targets'] + fig, ax = plt.subplots(2, 2, figsize=(8, 8), tight_layout=True) + ax = ax.ravel() + for i in range(4): + ax[i].hist(x[i], bins=100, label='%.3g +/- %.3g' % (x[i].mean(), x[i].std())) + ax[i].legend() + ax[i].set_title(s[i]) + plt.savefig('targets.jpg', dpi=200) + + +def plot_study_txt(f='study.txt', x=None): # from utils.general import *; plot_study_txt() + # Plot study.txt generated by test.py + fig, ax = plt.subplots(2, 4, figsize=(10, 6), tight_layout=True) + ax = ax.ravel() + + fig2, ax2 = plt.subplots(1, 1, figsize=(8, 4), tight_layout=True) + for f in ['study/study_coco_yolo%s.txt' % x for x in ['s', 'm', 'l', 'x']]: + y = np.loadtxt(f, dtype=np.float32, usecols=[0, 1, 2, 3, 7, 8, 9], ndmin=2).T + x = np.arange(y.shape[1]) if x is None else np.array(x) + s = ['P', 'R', 'mAP@.5', 'mAP@.5:.95', 't_inference (ms/img)', 't_NMS (ms/img)', 't_total (ms/img)'] + for i in range(7): + ax[i].plot(x, y[i], '.-', linewidth=2, markersize=8) + ax[i].set_title(s[i]) + + j = y[3].argmax() + 1 + ax2.plot(y[6, :j], y[3, :j] * 1E2, '.-', linewidth=2, markersize=8, + label=Path(f).stem.replace('study_coco_', '').replace('yolo', 'YOLO')) + + ax2.plot(1E3 / np.array([209, 140, 97, 58, 35, 18]), [34.6, 40.5, 43.0, 47.5, 49.7, 51.5], + 'k.-', linewidth=2, markersize=8, alpha=.25, label='EfficientDet') + + ax2.grid() + ax2.set_xlim(0, 30) + ax2.set_ylim(28, 50) + ax2.set_yticks(np.arange(30, 55, 5)) + ax2.set_xlabel('GPU Speed (ms/img)') + ax2.set_ylabel('COCO AP val') + ax2.legend(loc='lower right') + plt.savefig('study_mAP_latency.png', dpi=300) + plt.savefig(f.replace('.txt', '.png'), dpi=300) + + +def plot_labels(labels, save_dir=''): + # plot dataset labels + c, b = labels[:, 0], labels[:, 1:].transpose() # classes, boxes + nc = int(c.max() + 1) # number of classes + + fig, ax = plt.subplots(2, 2, figsize=(8, 8), tight_layout=True) + ax = ax.ravel() + ax[0].hist(c, bins=np.linspace(0, nc, nc + 1) - 0.5, rwidth=0.8) + ax[0].set_xlabel('classes') + ax[1].scatter(b[0], b[1], c=hist2d(b[0], b[1], 90), cmap='jet') + ax[1].set_xlabel('x') + ax[1].set_ylabel('y') + ax[2].scatter(b[2], b[3], c=hist2d(b[2], b[3], 90), cmap='jet') + ax[2].set_xlabel('width') + ax[2].set_ylabel('height') + plt.savefig(Path(save_dir) / 'labels.png', dpi=200) + plt.close() + + # seaborn correlogram + try: + import seaborn as sns + import pandas as pd + x = pd.DataFrame(b.transpose(), columns=['x', 'y', 'width', 'height']) + sns.pairplot(x, corner=True, diag_kind='hist', kind='scatter', markers='o', + plot_kws=dict(s=3, edgecolor=None, linewidth=1, alpha=0.02), + diag_kws=dict(bins=50)) + plt.savefig(Path(save_dir) / 'labels_correlogram.png', dpi=200) + plt.close() + except Exception as e: + pass + + +def plot_evolution(yaml_file='data/hyp.finetune.yaml'): # from utils.general import *; plot_evolution() + # Plot hyperparameter evolution results in evolve.txt + with open(yaml_file) as f: + hyp = yaml.load(f, Loader=yaml.FullLoader) + x = np.loadtxt('evolve.txt', ndmin=2) + f = fitness(x) + # weights = (f - f.min()) ** 2 # for weighted results + plt.figure(figsize=(10, 12), tight_layout=True) + matplotlib.rc('font', **{'size': 8}) + for i, (k, v) in enumerate(hyp.items()): + y = x[:, i + 7] + # mu = (y * weights).sum() / weights.sum() # best weighted result + mu = y[f.argmax()] # best single result + plt.subplot(6, 5, i + 1) + plt.scatter(y, f, c=hist2d(y, f, 20), cmap='viridis', alpha=.8, edgecolors='none') + plt.plot(mu, f.max(), 'k+', markersize=15) + plt.title('%s = %.3g' % (k, mu), fontdict={'size': 9}) # limit to 40 characters + if i % 5 != 0: + plt.yticks([]) + print('%15s: %.3g' % (k, mu)) + plt.savefig('evolve.png', dpi=200) + print('\nPlot saved as evolve.png') + + +def plot_results_overlay(start=0, stop=0): # from utils.general import *; plot_results_overlay() + # Plot training 'results*.txt', overlaying train and val losses + s = ['train', 'train', 'train', 'Precision', 'mAP@0.5', 'val', 'val', 'val', 'Recall', 'mAP@0.5:0.95'] # legends + t = ['Box', 'Objectness', 'Classification', 'P-R', 'mAP-F1'] # titles + for f in sorted(glob.glob('results*.txt') + glob.glob('../../Downloads/results*.txt')): + results = np.loadtxt(f, usecols=[2, 3, 4, 8, 9, 12, 13, 14, 10, 11], ndmin=2).T + n = results.shape[1] # number of rows + x = range(start, min(stop, n) if stop else n) + fig, ax = plt.subplots(1, 5, figsize=(14, 3.5), tight_layout=True) + ax = ax.ravel() + for i in range(5): + for j in [i, i + 5]: + y = results[j, x] + ax[i].plot(x, y, marker='.', label=s[j]) + # y_smooth = butter_lowpass_filtfilt(y) + # ax[i].plot(x, np.gradient(y_smooth), marker='.', label=s[j]) + + ax[i].set_title(t[i]) + ax[i].legend() + ax[i].set_ylabel(f) if i == 0 else None # add filename + fig.savefig(f.replace('.txt', '.png'), dpi=200) + + +def plot_results(start=0, stop=0, bucket='', id=(), labels=(), save_dir=''): + # from utils.general import *; plot_results(save_dir='runs/train/exp0') + # Plot training 'results*.txt' + fig, ax = plt.subplots(2, 5, figsize=(12, 6)) + ax = ax.ravel() + s = ['Box', 'Objectness', 'Classification', 'Precision', 'Recall', + 'val Box', 'val Objectness', 'val Classification', 'mAP@0.5', 'mAP@0.5:0.95'] + if bucket: + # os.system('rm -rf storage.googleapis.com') + # files = ['https://storage.googleapis.com/%s/results%g.txt' % (bucket, x) for x in id] + files = ['%g.txt' % x for x in id] + c = ('gsutil cp ' + '%s ' * len(files) + '.') % tuple('gs://%s/%g.txt' % (bucket, x) for x in id) + os.system(c) + else: + files = glob.glob(str(Path(save_dir) / '*.txt')) + glob.glob('../../Downloads/results*.txt') + assert len(files), 'No results.txt files found in %s, nothing to plot.' % os.path.abspath(save_dir) + for fi, f in enumerate(files): + try: + results = np.loadtxt(f, usecols=[2, 3, 4, 8, 9, 12, 13, 14, 10, 11], ndmin=2).T + n = results.shape[1] # number of rows + x = range(start, min(stop, n) if stop else n) + for i in range(10): + y = results[i, x] + if i in [0, 1, 2, 5, 6, 7]: + y[y == 0] = np.nan # don't show zero loss values + # y /= y[0] # normalize + label = labels[fi] if len(labels) else Path(f).stem + ax[i].plot(x, y, marker='.', label=label, linewidth=1, markersize=6) + ax[i].set_title(s[i]) + # if i in [5, 6, 7]: # share train and val loss y axes + # ax[i].get_shared_y_axes().join(ax[i], ax[i - 5]) + except Exception as e: + print('Warning: Plotting error for %s; %s' % (f, e)) + + fig.tight_layout() + ax[1].legend() + fig.savefig(Path(save_dir) / 'results.png', dpi=200) diff --git a/PyTorch/contrib/cv/detection/YOLOR/utils/torch_utils.py b/PyTorch/contrib/cv/detection/YOLOR/utils/torch_utils.py index 229bb26bc200dd7f4bc57794be7d246529bf66f8..707a4f5496c660785d475383797736029c238665 100644 --- a/PyTorch/contrib/cv/detection/YOLOR/utils/torch_utils.py +++ b/PyTorch/contrib/cv/detection/YOLOR/utils/torch_utils.py @@ -1,313 +1,313 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# PyTorch utils - -import logging -import math -import os -import time -from contextlib import contextmanager -from copy import deepcopy - -import torch -import torch.backends.cudnn as cudnn -import torch.nn as nn -import torch.nn.functional as F -import torchvision - -logger = logging.getLogger(__name__) - - -@contextmanager -def torch_distributed_zero_first(local_rank: int): - """ - Decorator to make all processes in distributed training wait for each local_master to do something. - """ - if local_rank not in [-1, 0]: - torch.distributed.barrier() - yield - if local_rank == 0: - torch.distributed.barrier() - - -def init_torch_seeds(seed=0): - # Speed-reproducibility tradeoff https://pytorch.org/docs/stable/notes/randomness.html - torch.manual_seed(seed) - if seed == 0: # slower, more reproducible - cudnn.deterministic = True - cudnn.benchmark = False - else: # faster, less reproducible - cudnn.deterministic = False - cudnn.benchmark = True - - -def select_device(device='', npu='', apex=False, batch_size=None): - npu_request = device.lower() == 'npu' - if npu_request and npu != -1: - torch.npu.set_device("npu:%d" % npu) - print('Using NPU %d to train' % npu) - return torch.device("npu:%d" % npu) - # device = 'cpu' or '0' or '0,1,2,3' - cpu_request = device.lower() == 'cpu' - if device and not cpu_request: # if device requested other than 'cpu' - os.environ['CUDA_VISIBLE_DEVICES'] = device # set environment variable - assert torch.cuda.is_available(), 'CUDA unavailable, invalid device %s requested' % device # check availablity - - cuda = False if cpu_request else torch.cuda.is_available() - if cuda: - c = 1024 ** 2 # bytes to MB - ng = torch.cuda.device_count() - if ng > 1 and batch_size: # check that batch_size is compatible with device_count - assert batch_size % ng == 0, 'batch-size %g not multiple of GPU count %g' % (batch_size, ng) - x = [torch.cuda.get_device_properties(i) for i in range(ng)] - s = 'Using CUDA ' + ('Apex ' if apex else '') # apex for mixed precision https://github.com/NVIDIA/apex - for i in range(0, ng): - if i == 1: - s = ' ' * len(s) - print("%sdevice%g _CudaDeviceProperties(name='%s', total_memory=%dMB)" % - (s, i, x[i].name, x[i].total_memory / c)) - else: - print('Using CPU') - - print('') # skip a line - return torch.device('cuda:0' if cuda else 'cpu') - - -def time_synchronized(): - torch.cuda.synchronize() if torch.cuda.is_available() else None - return time.time() - - -def is_parallel(model): - return type(model) in (nn.parallel.DataParallel, nn.parallel.DistributedDataParallel) - - -def intersect_dicts(da, db, exclude=()): - # Dictionary intersection of matching keys and shapes, omitting 'exclude' keys, using da values - return {k: v for k, v in da.items() if k in db and not any(x in k for x in exclude) and v.shape == db[k].shape} - - -def initialize_weights(model): - for m in model.modules(): - t = type(m) - if t is nn.Conv2d: - pass # nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu') - elif t is nn.BatchNorm2d: - m.eps = 1e-3 - m.momentum = 0.03 - elif t in [nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6]: - m.inplace = True - - -def find_modules(model, mclass=nn.Conv2d): - # Finds layer indices matching module class 'mclass' - return [i for i, m in enumerate(model.module_list) if isinstance(m, mclass)] - - -def sparsity(model): - # Return global model sparsity - a, b = 0., 0. - for p in model.parameters(): - a += p.numel() - b += (p == 0).sum() - return b / a - - -def prune(model, amount=0.3): - # Prune model to requested global sparsity - import torch.nn.utils.prune as prune - print('Pruning model... ', end='') - for name, m in model.named_modules(): - if isinstance(m, nn.Conv2d): - prune.l1_unstructured(m, name='weight', amount=amount) # prune - prune.remove(m, 'weight') # make permanent - print(' %.3g global sparsity' % sparsity(model)) - - -def fuse_conv_and_bn(conv, bn): - # Fuse convolution and batchnorm layers https://tehnokv.com/posts/fusing-batchnorm-and-conv/ - fusedconv = nn.Conv2d(conv.in_channels, - conv.out_channels, - kernel_size=conv.kernel_size, - stride=conv.stride, - padding=conv.padding, - groups=conv.groups, - bias=True).requires_grad_(False).to(conv.weight.device) - - # prepare filters - w_conv = conv.weight.clone().view(conv.out_channels, -1) - w_bn = torch.diag(bn.weight.div(torch.sqrt(bn.eps + bn.running_var))) - fusedconv.weight.copy_(torch.mm(w_bn, w_conv).view(fusedconv.weight.size())) - - # prepare spatial bias - b_conv = torch.zeros(conv.weight.size(0), device=conv.weight.device) if conv.bias is None else conv.bias - b_bn = bn.bias - bn.weight.mul(bn.running_mean).div(torch.sqrt(bn.running_var + bn.eps)) - fusedconv.bias.copy_(torch.mm(w_bn, b_conv.reshape(-1, 1)).reshape(-1) + b_bn) - - return fusedconv - - -def model_info(model, verbose=False, img_size=640): - # Model information. img_size may be int or list, i.e. img_size=640 or img_size=[640, 320] - n_p = sum(x.numel() for x in model.parameters()) # number parameters - n_g = sum(x.numel() for x in model.parameters() if x.requires_grad) # number gradients - if verbose: - print('%5s %40s %9s %12s %20s %10s %10s' % ('layer', 'name', 'gradient', 'parameters', 'shape', 'mu', 'sigma')) - for i, (name, p) in enumerate(model.named_parameters()): - name = name.replace('module_list.', '') - print('%5g %40s %9s %12g %20s %10.3g %10.3g' % - (i, name, p.requires_grad, p.numel(), list(p.shape), p.mean(), p.std())) - - try: # FLOPS - from thop import profile - flops = profile(deepcopy(model), inputs=(torch.zeros(1, 3, img_size, img_size),), verbose=False)[0] / 1E9 * 2 - img_size = img_size if isinstance(img_size, list) else [img_size, img_size] # expand if int/float - fs = ', %.9f GFLOPS' % (flops) # 640x640 FLOPS - except (ImportError, Exception): - fs = '' - - logger.info(f"Model Summary: {len(list(model.modules()))} layers, {n_p} parameters, {n_g} gradients{fs}") - - -def load_classifier(name='resnet101', n=2): - # Loads a pretrained model reshaped to n-class output - model = torchvision.models.__dict__[name](pretrained=True) - - # ResNet model properties - # input_size = [3, 224, 224] - # input_space = 'RGB' - # input_range = [0, 1] - # mean = [0.485, 0.456, 0.406] - # std = [0.229, 0.224, 0.225] - - # Reshape output to n classes - filters = model.fc.weight.shape[1] - model.fc.bias = nn.Parameter(torch.zeros(n), requires_grad=True) - model.fc.weight = nn.Parameter(torch.zeros(n, filters), requires_grad=True) - model.fc.out_features = n - return model - - -def scale_img(img, ratio=1.0, same_shape=False): # img(16,3,256,416), r=ratio - # scales img(bs,3,y,x) by ratio - if ratio == 1.0: - return img - else: - h, w = img.shape[2:] - s = (int(h * ratio), int(w * ratio)) # new size - img = F.interpolate(img, size=s, mode='bilinear', align_corners=False) # resize - if not same_shape: # pad/crop img - gs = 64 # (pixels) grid size - h, w = [math.ceil(x * ratio / gs) * gs for x in (h, w)] - return F.pad(img, [0, w - s[1], 0, h - s[0]], value=0.447) # value = imagenet mean - - -def copy_attr(a, b, include=(), exclude=()): - # Copy attributes from b to a, options to only include [...] and to exclude [...] - for k, v in b.__dict__.items(): - if (len(include) and k not in include) or k.startswith('_') or k in exclude: - continue - else: - setattr(a, k, v) - - -class ModelEMA: - """ Model Exponential Moving Average from https://github.com/rwightman/pytorch-image-models - Keep a moving average of everything in the model state_dict (parameters and buffers). - This is intended to allow functionality like - https://www.tensorflow.org/api_docs/python/tf/train/ExponentialMovingAverage - A smoothed version of the weights is necessary for some training schemes to perform well. - This class is sensitive where it is initialized in the sequence of model init, - GPU assignment and distributed training wrappers. - """ - - def __init__(self, model, decay=0.9999, updates=0): - # Create EMA - self.ema = deepcopy(model.module if is_parallel(model) else model).eval() # FP32 EMA - # if next(model.parameters()).device.type != 'cpu': - # self.ema.half() # FP16 EMA - self.updates = updates # number of EMA updates - self.decay = lambda x: decay * (1 - math.exp(-x / 2000)) # decay exponential ramp (to help early epochs) - for p in self.ema.parameters(): - p.requires_grad_(False) - - self.is_fused = False - - - def update(self, model, x, model_params_fused=None): - # Update EMA parameters - with torch.no_grad(): - self.updates += 1 - d = self.decay(self.updates) - - if x.device.type == 'npu': - # if False: - from apex.contrib.combine_tensors import combine_npu - d_inv = 1. - d - d = torch.tensor([d], device=x.device) - - if not self.is_fused: - pg0, pg1, pg2 = [], [], [] # optimizer parameters groups - - # this process needs special attention, the order of params should be identical to model - for name, p in self.ema.named_parameters(): - if p.dtype.is_floating_point: - if '.bias' in name: - pg2.append(p) # biases - elif 'Conv2d.weight' in name: - pg1.append(p) # apply weight_decay - elif 'm.weight' in name: - pg1.append(p) # apply weight_decay - elif 'w.weight' in name: - pg1.append(p) # apply weight_decay - else: - pg0.append(p) # all else - ema_all_params = pg0 + pg1 + pg2 - self.ema_params_fused = combine_npu(ema_all_params) - - ema_all_buffers = [] - for name, b in self.ema.named_buffers(): - if b.dtype.is_floating_point: - ema_all_buffers.append(b) - else: - continue - self.ema_buffers_fused = combine_npu(ema_all_buffers) - - model_all_buffers = [] - for name, b in model.named_buffers(): - if b.dtype.is_floating_point: - model_all_buffers.append(b) - else: - continue - self.model_buffers_fused = combine_npu(model_all_buffers) - - self.is_fused = True - - self.ema_params_fused *= d - self.ema_params_fused.add_(model_params_fused, alpha=d_inv) - - self.ema_buffers_fused *= d - self.ema_buffers_fused.add_(self.model_buffers_fused, alpha=d_inv) - - else: - msd = model.module.state_dict() if is_parallel(model) else model.state_dict() # model state_dict - for k, v in self.ema.state_dict().items(): - if v.dtype.is_floating_point: - v *= d - v += (1. - d) * msd[k].detach() - - def update_attr(self, model, include=(), exclude=('process_group', 'reducer')): - # Update EMA attributes - copy_attr(self.ema, model, include, exclude) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# PyTorch utils + +import logging +import math +import os +import time +from contextlib import contextmanager +from copy import deepcopy + +import torch +import torch.backends.cudnn as cudnn +import torch.nn as nn +import torch.nn.functional as F +import torchvision + +logger = logging.getLogger(__name__) + + +@contextmanager +def torch_distributed_zero_first(local_rank: int): + """ + Decorator to make all processes in distributed training wait for each local_master to do something. + """ + if local_rank not in [-1, 0]: + torch.distributed.barrier() + yield + if local_rank == 0: + torch.distributed.barrier() + + +def init_torch_seeds(seed=0): + # Speed-reproducibility tradeoff https://pytorch.org/docs/stable/notes/randomness.html + torch.manual_seed(seed) + if seed == 0: # slower, more reproducible + cudnn.deterministic = True + cudnn.benchmark = False + else: # faster, less reproducible + cudnn.deterministic = False + cudnn.benchmark = True + + +def select_device(device='', npu='', apex=False, batch_size=None): + npu_request = device.lower() == 'npu' + if npu_request and npu != -1: + torch.npu.set_device("npu:%d" % npu) + print('Using NPU %d to train' % npu) + return torch.device("npu:%d" % npu) + # device = 'cpu' or '0' or '0,1,2,3' + cpu_request = device.lower() == 'cpu' + if device and not cpu_request: # if device requested other than 'cpu' + os.environ['CUDA_VISIBLE_DEVICES'] = device # set environment variable + assert torch.cuda.is_available(), 'CUDA unavailable, invalid device %s requested' % device # check availablity + + cuda = False if cpu_request else torch.cuda.is_available() + if cuda: + c = 1024 ** 2 # bytes to MB + ng = torch.cuda.device_count() + if ng > 1 and batch_size: # check that batch_size is compatible with device_count + assert batch_size % ng == 0, 'batch-size %g not multiple of GPU count %g' % (batch_size, ng) + x = [torch.cuda.get_device_properties(i) for i in range(ng)] + s = 'Using CUDA ' + ('Apex ' if apex else '') # apex for mixed precision https://github.com/NVIDIA/apex + for i in range(0, ng): + if i == 1: + s = ' ' * len(s) + print("%sdevice%g _CudaDeviceProperties(name='%s', total_memory=%dMB)" % + (s, i, x[i].name, x[i].total_memory / c)) + else: + print('Using CPU') + + print('') # skip a line + return torch.device('cuda:0' if cuda else 'cpu') + + +def time_synchronized(): + torch.cuda.synchronize() if torch.cuda.is_available() else None + return time.time() + + +def is_parallel(model): + return type(model) in (nn.parallel.DataParallel, nn.parallel.DistributedDataParallel) + + +def intersect_dicts(da, db, exclude=()): + # Dictionary intersection of matching keys and shapes, omitting 'exclude' keys, using da values + return {k: v for k, v in da.items() if k in db and not any(x in k for x in exclude) and v.shape == db[k].shape} + + +def initialize_weights(model): + for m in model.modules(): + t = type(m) + if t is nn.Conv2d: + pass # nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu') + elif t is nn.BatchNorm2d: + m.eps = 1e-3 + m.momentum = 0.03 + elif t in [nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6]: + m.inplace = True + + +def find_modules(model, mclass=nn.Conv2d): + # Finds layer indices matching module class 'mclass' + return [i for i, m in enumerate(model.module_list) if isinstance(m, mclass)] + + +def sparsity(model): + # Return global model sparsity + a, b = 0., 0. + for p in model.parameters(): + a += p.numel() + b += (p == 0).sum() + return b / a + + +def prune(model, amount=0.3): + # Prune model to requested global sparsity + import torch.nn.utils.prune as prune + print('Pruning model... ', end='') + for name, m in model.named_modules(): + if isinstance(m, nn.Conv2d): + prune.l1_unstructured(m, name='weight', amount=amount) # prune + prune.remove(m, 'weight') # make permanent + print(' %.3g global sparsity' % sparsity(model)) + + +def fuse_conv_and_bn(conv, bn): + # Fuse convolution and batchnorm layers https://tehnokv.com/posts/fusing-batchnorm-and-conv/ + fusedconv = nn.Conv2d(conv.in_channels, + conv.out_channels, + kernel_size=conv.kernel_size, + stride=conv.stride, + padding=conv.padding, + groups=conv.groups, + bias=True).requires_grad_(False).to(conv.weight.device) + + # prepare filters + w_conv = conv.weight.clone().view(conv.out_channels, -1) + w_bn = torch.diag(bn.weight.div(torch.sqrt(bn.eps + bn.running_var))) + fusedconv.weight.copy_(torch.mm(w_bn, w_conv).view(fusedconv.weight.size())) + + # prepare spatial bias + b_conv = torch.zeros(conv.weight.size(0), device=conv.weight.device) if conv.bias is None else conv.bias + b_bn = bn.bias - bn.weight.mul(bn.running_mean).div(torch.sqrt(bn.running_var + bn.eps)) + fusedconv.bias.copy_(torch.mm(w_bn, b_conv.reshape(-1, 1)).reshape(-1) + b_bn) + + return fusedconv + + +def model_info(model, verbose=False, img_size=640): + # Model information. img_size may be int or list, i.e. img_size=640 or img_size=[640, 320] + n_p = sum(x.numel() for x in model.parameters()) # number parameters + n_g = sum(x.numel() for x in model.parameters() if x.requires_grad) # number gradients + if verbose: + print('%5s %40s %9s %12s %20s %10s %10s' % ('layer', 'name', 'gradient', 'parameters', 'shape', 'mu', 'sigma')) + for i, (name, p) in enumerate(model.named_parameters()): + name = name.replace('module_list.', '') + print('%5g %40s %9s %12g %20s %10.3g %10.3g' % + (i, name, p.requires_grad, p.numel(), list(p.shape), p.mean(), p.std())) + + try: # FLOPS + from thop import profile + flops = profile(deepcopy(model), inputs=(torch.zeros(1, 3, img_size, img_size),), verbose=False)[0] / 1E9 * 2 + img_size = img_size if isinstance(img_size, list) else [img_size, img_size] # expand if int/float + fs = ', %.9f GFLOPS' % (flops) # 640x640 FLOPS + except (ImportError, Exception): + fs = '' + + logger.info(f"Model Summary: {len(list(model.modules()))} layers, {n_p} parameters, {n_g} gradients{fs}") + + +def load_classifier(name='resnet101', n=2): + # Loads a pretrained model reshaped to n-class output + model = torchvision.models.__dict__[name](pretrained=True) + + # ResNet model properties + # input_size = [3, 224, 224] + # input_space = 'RGB' + # input_range = [0, 1] + # mean = [0.485, 0.456, 0.406] + # std = [0.229, 0.224, 0.225] + + # Reshape output to n classes + filters = model.fc.weight.shape[1] + model.fc.bias = nn.Parameter(torch.zeros(n), requires_grad=True) + model.fc.weight = nn.Parameter(torch.zeros(n, filters), requires_grad=True) + model.fc.out_features = n + return model + + +def scale_img(img, ratio=1.0, same_shape=False): # img(16,3,256,416), r=ratio + # scales img(bs,3,y,x) by ratio + if ratio == 1.0: + return img + else: + h, w = img.shape[2:] + s = (int(h * ratio), int(w * ratio)) # new size + img = F.interpolate(img, size=s, mode='bilinear', align_corners=False) # resize + if not same_shape: # pad/crop img + gs = 64 # (pixels) grid size + h, w = [math.ceil(x * ratio / gs) * gs for x in (h, w)] + return F.pad(img, [0, w - s[1], 0, h - s[0]], value=0.447) # value = imagenet mean + + +def copy_attr(a, b, include=(), exclude=()): + # Copy attributes from b to a, options to only include [...] and to exclude [...] + for k, v in b.__dict__.items(): + if (len(include) and k not in include) or k.startswith('_') or k in exclude: + continue + else: + setattr(a, k, v) + + +class ModelEMA: + """ Model Exponential Moving Average from https://github.com/rwightman/pytorch-image-models + Keep a moving average of everything in the model state_dict (parameters and buffers). + This is intended to allow functionality like + https://www.tensorflow.org/api_docs/python/tf/train/ExponentialMovingAverage + A smoothed version of the weights is necessary for some training schemes to perform well. + This class is sensitive where it is initialized in the sequence of model init, + GPU assignment and distributed training wrappers. + """ + + def __init__(self, model, decay=0.9999, updates=0): + # Create EMA + self.ema = deepcopy(model.module if is_parallel(model) else model).eval() # FP32 EMA + # if next(model.parameters()).device.type != 'cpu': + # self.ema.half() # FP16 EMA + self.updates = updates # number of EMA updates + self.decay = lambda x: decay * (1 - math.exp(-x / 2000)) # decay exponential ramp (to help early epochs) + for p in self.ema.parameters(): + p.requires_grad_(False) + + self.is_fused = False + + + def update(self, model, x, model_params_fused=None): + # Update EMA parameters + with torch.no_grad(): + self.updates += 1 + d = self.decay(self.updates) + + if x.device.type == 'npu': + # if False: + from apex.contrib.combine_tensors import combine_npu + d_inv = 1. - d + d = torch.tensor([d], device=x.device) + + if not self.is_fused: + pg0, pg1, pg2 = [], [], [] # optimizer parameters groups + + # this process needs special attention, the order of params should be identical to model + for name, p in self.ema.named_parameters(): + if p.dtype.is_floating_point: + if '.bias' in name: + pg2.append(p) # biases + elif 'Conv2d.weight' in name: + pg1.append(p) # apply weight_decay + elif 'm.weight' in name: + pg1.append(p) # apply weight_decay + elif 'w.weight' in name: + pg1.append(p) # apply weight_decay + else: + pg0.append(p) # all else + ema_all_params = pg0 + pg1 + pg2 + self.ema_params_fused = combine_npu(ema_all_params) + + ema_all_buffers = [] + for name, b in self.ema.named_buffers(): + if b.dtype.is_floating_point: + ema_all_buffers.append(b) + else: + continue + self.ema_buffers_fused = combine_npu(ema_all_buffers) + + model_all_buffers = [] + for name, b in model.named_buffers(): + if b.dtype.is_floating_point: + model_all_buffers.append(b) + else: + continue + self.model_buffers_fused = combine_npu(model_all_buffers) + + self.is_fused = True + + self.ema_params_fused *= d + self.ema_params_fused.add_(model_params_fused, alpha=d_inv) + + self.ema_buffers_fused *= d + self.ema_buffers_fused.add_(self.model_buffers_fused, alpha=d_inv) + + else: + msd = model.module.state_dict() if is_parallel(model) else model.state_dict() # model state_dict + for k, v in self.ema.state_dict().items(): + if v.dtype.is_floating_point: + v *= d + v += (1. - d) * msd[k].detach() + + def update_attr(self, model, include=(), exclude=('process_group', 'reducer')): + # Update EMA attributes + copy_attr(self.ema, model, include, exclude) diff --git a/PyTorch/contrib/cv/detection/centernet2/README.CN.md b/PyTorch/contrib/cv/detection/centernet2/README.CN.md index 0737bf97bf23e4285ff96e505a0e245e2ea2015f..45a8eb89e79d1a7bc4ceff35acf3d0333dd4fff1 100644 --- a/PyTorch/contrib/cv/detection/centernet2/README.CN.md +++ b/PyTorch/contrib/cv/detection/centernet2/README.CN.md @@ -1,120 +1,120 @@ -# CenterNet2 - -本项目实现了 CenterNet2 在 NPU 上的训练. -[CenterNet2 github链接](https://github.com/xingyizhou/CenterNet2) - -## 1.CenterNet2 Detail - -本项目对 CenterNet2 做了如下更改: -1. 迁移到 NPU 上 -2. 使用混合精度训练、测试 -3. 对于一些操作,固定动态 shape 、使用 NPU 算子优化性能、同时将一些操作转移到 CPU 上进行 - - -## 2.Requirements -### 2.1 安装NPU软件 - -* NPU配套的run包安装 -* PyTorch(NPU版本) -* apex(NPU版本) - -### 2.2 安装第三方软件 - -(1) 通过pip 安装部分第三方软件: - -``` -pip3 install -r requirements.txt -``` - -(2) 安装opencv - -``` -pip install opencv-python -``` - -(3) 编译安装torchvision - -``` -git clone https://github.com/pytorch/vision -cd vision -git checkout v0.6.0 -python3 setup.py install -``` - -**注:您必须编译安装torchvision,直接使用pip安装训练将无法启动** - -(4) 编译detectron2 - -进入模型脚本根目录,编译detectron2 - -``` -python3 setup.py build develop -``` - - -(5) 下载预训练模型 R-50.pkl ,projects/CenterNet2/configs/Base-CenterNet2.yaml配置文件中MODEL.WEIGHTS 设置为R-101.pkl的绝对路径 -## 3.Dataset - -(1) 下载coco2017数据集; - -(2) 解压数据集,解压后的目录结构如下 -``` -│ ├── coco -│ ├── annotations -│ ├── train2017 -│ ├── val2017 -``` -(3) 通过设置环境变量DETECTRON2_DATASETS=“coco 所在数据集路径”进行设置,如 export DETECTRON2_DATASETS=/home/,则 coco 数据集放在 /home/ 目录中 - -## 4.Training - -### 4.1 NPU 1P - -在模型根目录下,运行 train_full_1p.sh,同时传入参数--data_path,指定为coco数据集的路径父路径(例如数据集路径为/home/coco,则--data_path=/home) - -``` -bash ./test/train_full_1p.sh --data_path=/home -``` -模型训练结束后,会在result/CenterNet2/CenterNet2_R50_1x目录下保存模型文件model_final.pth,训练结束后若要评估精度需运行eval脚本,参考第6节 - -### 4.2 NPU 8P - -在模型根目录下,运行 train_full_8p.sh,同时传入参数--data_path,指定为coco数据集的路径父路径(例如数据集路径为/home/coco,则--data_path=/home) - -``` -bash ./test/train_full_8p.sh --data_path=/home -``` - -模型训练结束后,会在result/CenterNet2/CenterNet2_R50_1x目录下保存模型文件model_final.pth,训练结束后若要评估精度需运行eval脚本,参考第6节 - -## 5.Finetune - -请将projects/CenterNet2/configs/Base-CenterNet2.yaml中的字段WEIGHTS修改为第3节中model_final.pth的绝对路径,如修改为 -``` -WEIGHTS: "/home/CenterNet2/result/CenterNet2/CenterNet2_R50_1x/model_final.pth" -``` -然后启动评估脚本 - -``` -bash ./test/train_finetune_1p.sh --data_path=/home -``` - -## 6.评估 -训练结束后,需要手动启动评估程序。请将projects/CenterNet2/configs/Base-CenterNet2.yaml中的字段WEIGHTS修改为第3节中model_final.pth的绝对路径,如修改为 -``` -WEIGHTS: "/home/CenterNet2/result/CenterNet2/CenterNet2_R50_1x/model_final.pth" -``` - -然后启动评估脚本 - -``` -bash ./test/train_eval_1p.sh --data_path=/home -``` -## CenterNet2 Result - -| 名称 | 精度 | 性能 | -| ------ | ----- | -------- | -| GPU-1p | - | 12.3fps | -| NPU-1p | - | 2.86 fps | -| GPU-8p | 43.68 | 90.5fps | +# CenterNet2 + +本项目实现了 CenterNet2 在 NPU 上的训练. +[CenterNet2 github链接](https://github.com/xingyizhou/CenterNet2) + +## 1.CenterNet2 Detail + +本项目对 CenterNet2 做了如下更改: +1. 迁移到 NPU 上 +2. 使用混合精度训练、测试 +3. 对于一些操作,固定动态 shape 、使用 NPU 算子优化性能、同时将一些操作转移到 CPU 上进行 + + +## 2.Requirements +### 2.1 安装NPU软件 + +* NPU配套的run包安装 +* PyTorch(NPU版本) +* apex(NPU版本) + +### 2.2 安装第三方软件 + +(1) 通过pip 安装部分第三方软件: + +``` +pip3 install -r requirements.txt +``` + +(2) 安装opencv + +``` +pip install opencv-python +``` + +(3) 编译安装torchvision + +``` +git clone https://github.com/pytorch/vision +cd vision +git checkout v0.6.0 +python3 setup.py install +``` + +**注:您必须编译安装torchvision,直接使用pip安装训练将无法启动** + +(4) 编译detectron2 + +进入模型脚本根目录,编译detectron2 + +``` +python3 setup.py build develop +``` + + +(5) 下载预训练模型 R-50.pkl ,projects/CenterNet2/configs/Base-CenterNet2.yaml配置文件中MODEL.WEIGHTS 设置为R-101.pkl的绝对路径 +## 3.Dataset + +(1) 下载coco2017数据集; + +(2) 解压数据集,解压后的目录结构如下 +``` +│ ├── coco +│ ├── annotations +│ ├── train2017 +│ ├── val2017 +``` +(3) 通过设置环境变量DETECTRON2_DATASETS=“coco 所在数据集路径”进行设置,如 export DETECTRON2_DATASETS=/home/,则 coco 数据集放在 /home/ 目录中 + +## 4.Training + +### 4.1 NPU 1P + +在模型根目录下,运行 train_full_1p.sh,同时传入参数--data_path,指定为coco数据集的路径父路径(例如数据集路径为/home/coco,则--data_path=/home) + +``` +bash ./test/train_full_1p.sh --data_path=/home +``` +模型训练结束后,会在result/CenterNet2/CenterNet2_R50_1x目录下保存模型文件model_final.pth,训练结束后若要评估精度需运行eval脚本,参考第6节 + +### 4.2 NPU 8P + +在模型根目录下,运行 train_full_8p.sh,同时传入参数--data_path,指定为coco数据集的路径父路径(例如数据集路径为/home/coco,则--data_path=/home) + +``` +bash ./test/train_full_8p.sh --data_path=/home +``` + +模型训练结束后,会在result/CenterNet2/CenterNet2_R50_1x目录下保存模型文件model_final.pth,训练结束后若要评估精度需运行eval脚本,参考第6节 + +## 5.Finetune + +请将projects/CenterNet2/configs/Base-CenterNet2.yaml中的字段WEIGHTS修改为第3节中model_final.pth的绝对路径,如修改为 +``` +WEIGHTS: "/home/CenterNet2/result/CenterNet2/CenterNet2_R50_1x/model_final.pth" +``` +然后启动评估脚本 + +``` +bash ./test/train_finetune_1p.sh --data_path=/home +``` + +## 6.评估 +训练结束后,需要手动启动评估程序。请将projects/CenterNet2/configs/Base-CenterNet2.yaml中的字段WEIGHTS修改为第3节中model_final.pth的绝对路径,如修改为 +``` +WEIGHTS: "/home/CenterNet2/result/CenterNet2/CenterNet2_R50_1x/model_final.pth" +``` + +然后启动评估脚本 + +``` +bash ./test/train_eval_1p.sh --data_path=/home +``` +## CenterNet2 Result + +| 名称 | 精度 | 性能 | +| ------ | ----- | -------- | +| GPU-1p | - | 12.3fps | +| NPU-1p | - | 2.86 fps | +| GPU-8p | 43.68 | 90.5fps | | NPU-8p | 43.5 | 18.7fps | \ No newline at end of file diff --git a/PyTorch/contrib/cv/detection/centernet2/requirements.txt b/PyTorch/contrib/cv/detection/centernet2/requirements.txt index f2e8ae6b481a2272fa00156d4acb1f88367ee105..5642e4abe9102eb7e666f5dcffe1a23f5165d466 100644 --- a/PyTorch/contrib/cv/detection/centernet2/requirements.txt +++ b/PyTorch/contrib/cv/detection/centernet2/requirements.txt @@ -1,17 +1,17 @@ -numpy -decorator==5.1.0 -sympy==1.9 -termcolor>=1.1 -Pillow>=8.4.0 -yacs>=0.1.6 -tabulate -cloudpickle -matplotlib -tqdm>4.29.0 -tensorboard -fvcore -iopath>=0.1.2 -pycocotools>=2.0.2 -future -pydot -omegaconf +numpy +decorator==5.1.0 +sympy==1.9 +termcolor>=1.1 +Pillow>=8.4.0 +yacs>=0.1.6 +tabulate +cloudpickle +matplotlib +tqdm>4.29.0 +tensorboard +fvcore +iopath>=0.1.2 +pycocotools>=2.0.2 +future +pydot +omegaconf diff --git a/PyTorch/contrib/cv/others/ADNet/LICENSE b/PyTorch/contrib/cv/others/ADNet/LICENSE index 29f81d812f3e768fa89638d1f72920dbfd1413a8..261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64 100644 --- a/PyTorch/contrib/cv/others/ADNet/LICENSE +++ b/PyTorch/contrib/cv/others/ADNet/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/PyTorch/contrib/cv/others/ADNet/README.md b/PyTorch/contrib/cv/others/ADNet/README.md index a2bc84b397231468d55dc83b15379465445b78b5..9fd16c6d627786829d148b6899f3bbb68ac90b90 100644 --- a/PyTorch/contrib/cv/others/ADNet/README.md +++ b/PyTorch/contrib/cv/others/ADNet/README.md @@ -1,167 +1,167 @@ -# ADNet训练 - -``` -## Atention-guided CNN for image denoising(ADNet)by Chunwei Tian, Yong Xu, Zuoyong Li, Wangmeng Zuo, Lunke Fei and Hong Liu is publised by Neural Networks (IF:8.05), 2020 (https://www.sciencedirect.com/science/article/pii/S0893608019304241) and it is implemented by Pytorch. - - -## This paper is pushed on home page of the Nueral Networks. Also, it is reported by wechat public accounts at https://mp.weixin.qq.com/s/Debh7PZSFTBtOVxpFh9yfQ and https://wx.zsxq.com/mweb/views/topicdetail/topicdetail.html?topic_id=548112815452544&group_id=142181451122&user_id=28514284588581&from=timeline. - -## This paper is the first paper via deep network properties for addressing image denoising with complex background. - -## Absract -#### Deep convolutional neural networks (CNNs) have attracted considerable interest in low-level computer vision. Researches are usually devoted to improving the performance via very deep CNNs. However, as the depth increases, influences of the shallow layers on deep layers are weakened. Inspired by the fact, we propose an attention-guided denoising convolutional neural network (ADNet), mainly including a sparse block (SB), a feature enhancement block (FEB), an attention block (AB) and a reconstruction block (RB) for image denoising. Specifically, the SB makes a tradeoff between performance and efficiency by using dilated and common convolutions to remove the noise. The FEB integrates global and local features information via a long path to enhance the expressive ability of the denoising model. The AB is used to finely extract the noise information hidden in the complex background, which is very effective for complex noisy images, especially real noisy images and bind denoising. Also, the FEB is integrated with the AB to improve the efficiency and reduce the complexity for training a denoising model. Finally, a RB aims to construct the clean image through the obtained noise mapping and the given noisy image. Additionally, comprehensive experiments show that the proposed ADNet performs very well in three tasks (i.e., synthetic and real noisy images, and blind denoising) in terms of both quantitative and qualitative evaluations. The code of ADNet is accessible at https://github.com/hellloxiaotian/ADNet. -``` - -For more detail:https://www.sciencedirect.com/science/article/abs/pii/S0893608019304241 - - - -## Requirements - -use pytorch, you can use pip or conda to install the requirements - -``` -# for pip -cd $project -pip3.7 install -r requirements.txt -CANN 5.0.3.alpha001 -torchvision==0.6.0 -``` - - - -## 数据集准备 - -1.从以下网址获取pristine_images_gray.tar.gz作为训练集 - -https://pan.baidu.com/s/1nkY-b5_mdzliL7Y7N9JQRQ - -2.从以下网址获取BSD68作为标签 - -暂时没有在网上找到免费资源,可以从以下网址付费下载。 - -https://download.csdn.net/download/iteapoy/10902860 - -文件结构如下: - - -``` -ADNET -|-- data -| |-- BSD68 -| |-- pristine_images_gray -| |-- demo_img -| |--result -|-- test -|-- dataset.py -|-- demo.py -|-- models.py -|-- preprocess.py -|-- test.py -|-- train.py -|-- utils.py - -``` - -将数据集按照以上结构放在代码目录下 - -## 处理数据 - -source环境变量 - -``` -source ./test/env.sh -``` - -执行数据预处理脚本,将训练集图片裁剪成50*50的图片用与训练,运行成功会生成train.h5和val.h5文件,预处理需要h5py环境,请自行安装。 - -``` -python3.7.5 preprocess.py --preprocess True --mode S -``` - - - -## TRAIN - -### 单p训练 - -source 环境变量 - -``` -source ./test/env.sh -``` - -性能脚本: - -``` -bash ./test/train_performance_1p.sh -``` - -精度脚本: - -``` -bash ./test/train_full_1p.sh -``` - - - -### 多p训练 - -source 环境变量 - -``` -source ./test/env.sh -``` - -性能脚本: - -``` -bash ./test/train_performance_8p.sh -``` - -精度脚本: - -``` -bash ./test/train_full_8p.sh -``` - -模型保存在 - -运行日志保存至./logssigma25.0_2021-09-05-19-23-13目录下(2021-09-05-19-23-13是运行train.py的时间,会根据当前时间自动更新),其中best_model.pth是在验证集上精度最高的模型。 - -## TEST - -测试精度 - -使用sh文件 - -``` -bash test/eval_1p.sh -``` - -测试之前请指定测试的模型路径。打开./test/eval.sh文件,如下所示: - -``` -python3.7.5 test.py --is_distributed 0 --DeviceID 0 --num_gpus 1 --num_of_layers 17 --logdir logssigma25.0_2021-08-31-19-13-09 --test_data BSD68 --test_noiseL 25 | tee -a eval_1p.log -``` - -请指定需要测试的模型路径,将--logdir参数设置为需要测试的模型目录。 - -## Demo -将一张图片放在./data/demo_img中,将--demo_pth_path设置为训练好的pth文件目录,执行以下程序。模型的运行结果保存在./data/demo_img/result文件夹里。 -``` -python3.7.5 demo.py --DeviceID 0 --num_of_layers 17 --test_noiseL 25 --demo_pth_path logssigma25.0_2021-09-03-10-39-34 -``` - -### 精度对比 - -由于NPU上使用torch.optim.Adam出现loss极大的情况,在使用apex.optimizers.NpuFusedSGD优化器后,loss正常,但是精度会有所损失。 - -| | opt_level | loss_scale | optimizer | PSNR | -| ------ | --------- | ---------- | -------------------------------------------------------- | ----- | -| GPU-8p | o2 | 128 | optim.Adam | 28.98 | -| GPU-8p | o2 | 128 | optim.SGD | 27.83 | -| NPU-8p | 02 | 64 | apex.optimizers.NpuFusedAdam(不稳定,不能稳定复现精度) | 28.92 | -| NPU-8p | o2 | 8 | apex.optimizers.NpuFusedSGD | 28.49 | - +# ADNet训练 + +``` +## Atention-guided CNN for image denoising(ADNet)by Chunwei Tian, Yong Xu, Zuoyong Li, Wangmeng Zuo, Lunke Fei and Hong Liu is publised by Neural Networks (IF:8.05), 2020 (https://www.sciencedirect.com/science/article/pii/S0893608019304241) and it is implemented by Pytorch. + + +## This paper is pushed on home page of the Nueral Networks. Also, it is reported by wechat public accounts at https://mp.weixin.qq.com/s/Debh7PZSFTBtOVxpFh9yfQ and https://wx.zsxq.com/mweb/views/topicdetail/topicdetail.html?topic_id=548112815452544&group_id=142181451122&user_id=28514284588581&from=timeline. + +## This paper is the first paper via deep network properties for addressing image denoising with complex background. + +## Absract +#### Deep convolutional neural networks (CNNs) have attracted considerable interest in low-level computer vision. Researches are usually devoted to improving the performance via very deep CNNs. However, as the depth increases, influences of the shallow layers on deep layers are weakened. Inspired by the fact, we propose an attention-guided denoising convolutional neural network (ADNet), mainly including a sparse block (SB), a feature enhancement block (FEB), an attention block (AB) and a reconstruction block (RB) for image denoising. Specifically, the SB makes a tradeoff between performance and efficiency by using dilated and common convolutions to remove the noise. The FEB integrates global and local features information via a long path to enhance the expressive ability of the denoising model. The AB is used to finely extract the noise information hidden in the complex background, which is very effective for complex noisy images, especially real noisy images and bind denoising. Also, the FEB is integrated with the AB to improve the efficiency and reduce the complexity for training a denoising model. Finally, a RB aims to construct the clean image through the obtained noise mapping and the given noisy image. Additionally, comprehensive experiments show that the proposed ADNet performs very well in three tasks (i.e., synthetic and real noisy images, and blind denoising) in terms of both quantitative and qualitative evaluations. The code of ADNet is accessible at https://github.com/hellloxiaotian/ADNet. +``` + +For more detail:https://www.sciencedirect.com/science/article/abs/pii/S0893608019304241 + + + +## Requirements + +use pytorch, you can use pip or conda to install the requirements + +``` +# for pip +cd $project +pip3.7 install -r requirements.txt +CANN 5.0.3.alpha001 +torchvision==0.6.0 +``` + + + +## 数据集准备 + +1.从以下网址获取pristine_images_gray.tar.gz作为训练集 + +https://pan.baidu.com/s/1nkY-b5_mdzliL7Y7N9JQRQ + +2.从以下网址获取BSD68作为标签 + +暂时没有在网上找到免费资源,可以从以下网址付费下载。 + +https://download.csdn.net/download/iteapoy/10902860 + +文件结构如下: + + +``` +ADNET +|-- data +| |-- BSD68 +| |-- pristine_images_gray +| |-- demo_img +| |--result +|-- test +|-- dataset.py +|-- demo.py +|-- models.py +|-- preprocess.py +|-- test.py +|-- train.py +|-- utils.py + +``` + +将数据集按照以上结构放在代码目录下 + +## 处理数据 + +source环境变量 + +``` +source ./test/env.sh +``` + +执行数据预处理脚本,将训练集图片裁剪成50*50的图片用与训练,运行成功会生成train.h5和val.h5文件,预处理需要h5py环境,请自行安装。 + +``` +python3.7.5 preprocess.py --preprocess True --mode S +``` + + + +## TRAIN + +### 单p训练 + +source 环境变量 + +``` +source ./test/env.sh +``` + +性能脚本: + +``` +bash ./test/train_performance_1p.sh +``` + +精度脚本: + +``` +bash ./test/train_full_1p.sh +``` + + + +### 多p训练 + +source 环境变量 + +``` +source ./test/env.sh +``` + +性能脚本: + +``` +bash ./test/train_performance_8p.sh +``` + +精度脚本: + +``` +bash ./test/train_full_8p.sh +``` + +模型保存在 + +运行日志保存至./logssigma25.0_2021-09-05-19-23-13目录下(2021-09-05-19-23-13是运行train.py的时间,会根据当前时间自动更新),其中best_model.pth是在验证集上精度最高的模型。 + +## TEST + +测试精度 + +使用sh文件 + +``` +bash test/eval_1p.sh +``` + +测试之前请指定测试的模型路径。打开./test/eval.sh文件,如下所示: + +``` +python3.7.5 test.py --is_distributed 0 --DeviceID 0 --num_gpus 1 --num_of_layers 17 --logdir logssigma25.0_2021-08-31-19-13-09 --test_data BSD68 --test_noiseL 25 | tee -a eval_1p.log +``` + +请指定需要测试的模型路径,将--logdir参数设置为需要测试的模型目录。 + +## Demo +将一张图片放在./data/demo_img中,将--demo_pth_path设置为训练好的pth文件目录,执行以下程序。模型的运行结果保存在./data/demo_img/result文件夹里。 +``` +python3.7.5 demo.py --DeviceID 0 --num_of_layers 17 --test_noiseL 25 --demo_pth_path logssigma25.0_2021-09-03-10-39-34 +``` + +### 精度对比 + +由于NPU上使用torch.optim.Adam出现loss极大的情况,在使用apex.optimizers.NpuFusedSGD优化器后,loss正常,但是精度会有所损失。 + +| | opt_level | loss_scale | optimizer | PSNR | +| ------ | --------- | ---------- | -------------------------------------------------------- | ----- | +| GPU-8p | o2 | 128 | optim.Adam | 28.98 | +| GPU-8p | o2 | 128 | optim.SGD | 27.83 | +| NPU-8p | 02 | 64 | apex.optimizers.NpuFusedAdam(不稳定,不能稳定复现精度) | 28.92 | +| NPU-8p | o2 | 8 | apex.optimizers.NpuFusedSGD | 28.49 | + 在NPU上使用apex.optimizers.NpuFusedAdam不能稳定复现精度,有时候会出现loss极大的情况,导致训练失败。 \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/ADNet/demo.py b/PyTorch/contrib/cv/others/ADNet/demo.py index 41907621c32437fee82e418c689a09d451d69cdc..3403781dcc2cc0e67c2e54ecb07cb43dbf1f3ee9 100644 --- a/PyTorch/contrib/cv/others/ADNet/demo.py +++ b/PyTorch/contrib/cv/others/ADNet/demo.py @@ -1,111 +1,111 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import cv2 -import os -import argparse -import glob -import numpy as np -from PIL import Image -import torch -import torch.nn as nn -from torch.autograd import Variable -from models import ADNet -from utils import * -from collections import OrderedDict -import torch.distributed as dist - -parser = argparse.ArgumentParser(description="ADNet_Test") -parser.add_argument("--num_of_layers", type=int, default=17, help="Number of total layers") -parser.add_argument("--logdir", type=str, default="logs", help='path of log files') -parser.add_argument("--test_data", type=str, default='BSD68', help='test on Set12 or Set68') -parser.add_argument("--test_noiseL", type=float, default=25, help='noise level used on test set') -parser.add_argument("--DeviceID", type=int, default=0, help='choose a device id to use') -parser.add_argument("--demo_img_path", type=str, default='demo_img') -parser.add_argument("--demo_pth_path", type=str, default='data') -opt = parser.parse_args() - - -def normalize(data): - return data / 255. -def proc_nodes_module(checkpoint): - new_state_dict = OrderedDict() - for k, v in checkpoint.items(): - if "module." in k: - name = k.replace("module.", "") - else: - name = k - new_state_dict[name] = v - return new_state_dict - -def main(): - # Build model - local_device = torch.device(f'npu:{opt.DeviceID}') - torch.npu.set_device(local_device) - print("using npu :{}".format(opt.DeviceID)) - print('Loading model ...\n') - net = ADNet(channels=1, num_of_layers=17) - model = net #model = nn.DataParallel(net, device_ids=device_ids).cuda() - checkpoint = torch.load(os.path.join(opt.demo_pth_path, 'best_model.pth'), map_location=local_device) - checkpoint = proc_nodes_module(checkpoint) - model.load_state_dict(checkpoint) - model = model.npu() - model.eval() - # load data info - print('Loading data info ...\n') - files_source = glob.glob(os.path.join('data', opt.demo_img_path, '*.png')) - files_source.sort() - # process data - psnr_test = 0 - for f in files_source: - # image - Img = cv2.imread(f) - Img = normalize(np.float32(Img[:, :, 0])) - Img = np.expand_dims(Img, 0) - Img = np.expand_dims(Img, 1) - ISource = torch.Tensor(Img) - # noise - torch.manual_seed(0) # set the seed - noise = torch.FloatTensor(ISource.size()).normal_(mean=0, std=opt.test_noiseL / 255.) - # noisy image - INoisy = ISource + noise - ISource = Variable(ISource) - INoisy = Variable(INoisy) - ISource = ISource.npu() - INoisy = INoisy.npu() - with torch.no_grad(): # this can save much memory - Out = torch.clamp(model(INoisy), 0., 1.) - psnr = batch_PSNR(Out, ISource, 1.) - psnr_test += psnr - print("%s PSNR %f" % (f, psnr)) - INoisy = INoisy*255 - INoisy = INoisy.data.cpu().numpy() - INoisy = np.squeeze(INoisy) - Imag_noise = Image.fromarray(INoisy.astype('uint8')) - if not os.path.exists('./data/demo_img/result'): - os.mkdir('./data/demo_img/result') - Imag_noise.save(os.path.join('data', opt.demo_img_path, 'result', 'image_add_noise.png')) - print('original image stored in:', os.path.join('data', opt.demo_img_path)) - print('image added noise stored in:', os.path.join('data', opt.demo_img_path, 'result', 'image_add_noise.png')) - result = Out*255 - result = result.data.cpu().numpy() - result = np.squeeze(result) - result = Image.fromarray(result.astype('uint8')) - result.save(os.path.join('data', opt.demo_img_path, 'result', 'image_after_processing.png')) - print('image denoised stored in:', os.path.join('data', opt.demo_img_path, 'result', 'image_after_processing.png')) - psnr_test /= len(files_source) - print("\nPSNR on demo image %f" % psnr_test) - - -if __name__ == "__main__": - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import cv2 +import os +import argparse +import glob +import numpy as np +from PIL import Image +import torch +import torch.nn as nn +from torch.autograd import Variable +from models import ADNet +from utils import * +from collections import OrderedDict +import torch.distributed as dist + +parser = argparse.ArgumentParser(description="ADNet_Test") +parser.add_argument("--num_of_layers", type=int, default=17, help="Number of total layers") +parser.add_argument("--logdir", type=str, default="logs", help='path of log files') +parser.add_argument("--test_data", type=str, default='BSD68', help='test on Set12 or Set68') +parser.add_argument("--test_noiseL", type=float, default=25, help='noise level used on test set') +parser.add_argument("--DeviceID", type=int, default=0, help='choose a device id to use') +parser.add_argument("--demo_img_path", type=str, default='demo_img') +parser.add_argument("--demo_pth_path", type=str, default='data') +opt = parser.parse_args() + + +def normalize(data): + return data / 255. +def proc_nodes_module(checkpoint): + new_state_dict = OrderedDict() + for k, v in checkpoint.items(): + if "module." in k: + name = k.replace("module.", "") + else: + name = k + new_state_dict[name] = v + return new_state_dict + +def main(): + # Build model + local_device = torch.device(f'npu:{opt.DeviceID}') + torch.npu.set_device(local_device) + print("using npu :{}".format(opt.DeviceID)) + print('Loading model ...\n') + net = ADNet(channels=1, num_of_layers=17) + model = net #model = nn.DataParallel(net, device_ids=device_ids).cuda() + checkpoint = torch.load(os.path.join(opt.demo_pth_path, 'best_model.pth'), map_location=local_device) + checkpoint = proc_nodes_module(checkpoint) + model.load_state_dict(checkpoint) + model = model.npu() + model.eval() + # load data info + print('Loading data info ...\n') + files_source = glob.glob(os.path.join('data', opt.demo_img_path, '*.png')) + files_source.sort() + # process data + psnr_test = 0 + for f in files_source: + # image + Img = cv2.imread(f) + Img = normalize(np.float32(Img[:, :, 0])) + Img = np.expand_dims(Img, 0) + Img = np.expand_dims(Img, 1) + ISource = torch.Tensor(Img) + # noise + torch.manual_seed(0) # set the seed + noise = torch.FloatTensor(ISource.size()).normal_(mean=0, std=opt.test_noiseL / 255.) + # noisy image + INoisy = ISource + noise + ISource = Variable(ISource) + INoisy = Variable(INoisy) + ISource = ISource.npu() + INoisy = INoisy.npu() + with torch.no_grad(): # this can save much memory + Out = torch.clamp(model(INoisy), 0., 1.) + psnr = batch_PSNR(Out, ISource, 1.) + psnr_test += psnr + print("%s PSNR %f" % (f, psnr)) + INoisy = INoisy*255 + INoisy = INoisy.data.cpu().numpy() + INoisy = np.squeeze(INoisy) + Imag_noise = Image.fromarray(INoisy.astype('uint8')) + if not os.path.exists('./data/demo_img/result'): + os.mkdir('./data/demo_img/result') + Imag_noise.save(os.path.join('data', opt.demo_img_path, 'result', 'image_add_noise.png')) + print('original image stored in:', os.path.join('data', opt.demo_img_path)) + print('image added noise stored in:', os.path.join('data', opt.demo_img_path, 'result', 'image_add_noise.png')) + result = Out*255 + result = result.data.cpu().numpy() + result = np.squeeze(result) + result = Image.fromarray(result.astype('uint8')) + result.save(os.path.join('data', opt.demo_img_path, 'result', 'image_after_processing.png')) + print('image denoised stored in:', os.path.join('data', opt.demo_img_path, 'result', 'image_after_processing.png')) + psnr_test /= len(files_source) + print("\nPSNR on demo image %f" % psnr_test) + + +if __name__ == "__main__": + main() diff --git a/PyTorch/contrib/cv/others/ADNet/modelzoo_level.txt b/PyTorch/contrib/cv/others/ADNet/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/others/ADNet/modelzoo_level.txt +++ b/PyTorch/contrib/cv/others/ADNet/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/ADNet/preprocess.py b/PyTorch/contrib/cv/others/ADNet/preprocess.py index 906b8a58a2c593e7110bc612746876558454f6da..f6328b1aa6c093a94566123d4f64190ff148739f 100644 --- a/PyTorch/contrib/cv/others/ADNet/preprocess.py +++ b/PyTorch/contrib/cv/others/ADNet/preprocess.py @@ -1,64 +1,64 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import argparse - -import torch -import sys -import torch.nn as nn -import torch.optim as optim -import apex.amp as amp -import apex -import logging -from torch.nn.parallel import DistributedDataParallel as DDP -from torch.utils.data.distributed import DistributedSampler -import torch.distributed as dist -import time -from torch.autograd import Variable -from torch.utils.data import DataLoader - -from torch.nn.modules.loss import _Loss -from models import ADNet -from dataset import prepare_data, Dataset -from utils import * - - -parser = argparse.ArgumentParser(description="DnCNN") -parser.add_argument("--preprocess", type=bool, default=False, help='run prepare_data or not') -parser.add_argument("--batchSize", type=int, default=128, help="Training batch size") -parser.add_argument("--num_of_layers", type=int, default=17, help="Number of total layers") -parser.add_argument("--epochs", type=int, default=70, help="Number of training epochs") -parser.add_argument("--milestone", type=int, default=30, help="When to decay learning rate; should be less than epochs") -parser.add_argument("--lr", type=float, default=1e-3, help="Initial learning rate") -parser.add_argument("--outf", type=str, default="logs", help='path of log files') -parser.add_argument("--mode", type=str, default="S", help='with known noise level (S) or blind training (B)') -parser.add_argument("--noiseL", type=float, default=15, help='noise level; ignored when mode=B') -parser.add_argument("--val_noiseL", type=float, default=15, help='noise level used on validation set') -parser.add_argument("--is_distributed", type=int, default=0, help='choose ddp or not') -parser.add_argument('--world_size', default=-1, type=int, help='number of nodes for distributed training') -parser.add_argument('--local_rank', type=int, default=0) -parser.add_argument('--DeviceID', type=str, default="0") -parser.add_argument("--num_gpus", default=1, type=int) -''' -parser.add_argument("--clip",type=float,default=0.005,help='Clipping Gradients. Default=0.4') #tcw201809131446tcw -parser.add_argument("--momentum",default=0.9,type='float',help = 'Momentum, Default:0.9') #tcw201809131447tcw -parser.add_argument("--weight-decay","-wd",default=1e-3,type=float,help='Weight decay, Default:1e-4') #tcw20180913347tcw -''' -opt = parser.parse_args() -if __name__ == "__main__": - if opt.preprocess: - if opt.mode == 'S': - prepare_data(data_path='data', patch_size=50, stride=40, aug_times=1) - if opt.mode == 'B': - prepare_data(data_path='data', patch_size=50, stride=10, aug_times=2) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import argparse + +import torch +import sys +import torch.nn as nn +import torch.optim as optim +import apex.amp as amp +import apex +import logging +from torch.nn.parallel import DistributedDataParallel as DDP +from torch.utils.data.distributed import DistributedSampler +import torch.distributed as dist +import time +from torch.autograd import Variable +from torch.utils.data import DataLoader + +from torch.nn.modules.loss import _Loss +from models import ADNet +from dataset import prepare_data, Dataset +from utils import * + + +parser = argparse.ArgumentParser(description="DnCNN") +parser.add_argument("--preprocess", type=bool, default=False, help='run prepare_data or not') +parser.add_argument("--batchSize", type=int, default=128, help="Training batch size") +parser.add_argument("--num_of_layers", type=int, default=17, help="Number of total layers") +parser.add_argument("--epochs", type=int, default=70, help="Number of training epochs") +parser.add_argument("--milestone", type=int, default=30, help="When to decay learning rate; should be less than epochs") +parser.add_argument("--lr", type=float, default=1e-3, help="Initial learning rate") +parser.add_argument("--outf", type=str, default="logs", help='path of log files') +parser.add_argument("--mode", type=str, default="S", help='with known noise level (S) or blind training (B)') +parser.add_argument("--noiseL", type=float, default=15, help='noise level; ignored when mode=B') +parser.add_argument("--val_noiseL", type=float, default=15, help='noise level used on validation set') +parser.add_argument("--is_distributed", type=int, default=0, help='choose ddp or not') +parser.add_argument('--world_size', default=-1, type=int, help='number of nodes for distributed training') +parser.add_argument('--local_rank', type=int, default=0) +parser.add_argument('--DeviceID', type=str, default="0") +parser.add_argument("--num_gpus", default=1, type=int) +''' +parser.add_argument("--clip",type=float,default=0.005,help='Clipping Gradients. Default=0.4') #tcw201809131446tcw +parser.add_argument("--momentum",default=0.9,type='float',help = 'Momentum, Default:0.9') #tcw201809131447tcw +parser.add_argument("--weight-decay","-wd",default=1e-3,type=float,help='Weight decay, Default:1e-4') #tcw20180913347tcw +''' +opt = parser.parse_args() +if __name__ == "__main__": + if opt.preprocess: + if opt.mode == 'S': + prepare_data(data_path='data', patch_size=50, stride=40, aug_times=1) + if opt.mode == 'B': + prepare_data(data_path='data', patch_size=50, stride=10, aug_times=2) diff --git a/PyTorch/contrib/cv/others/BigGAN/LICENSE b/PyTorch/contrib/cv/others/BigGAN/LICENSE index 753842b6720f7980d411ecf2c78eb4ef220b9df8..f49a4e16e68b128803cc2dcea614603632b04eac 100644 --- a/PyTorch/contrib/cv/others/BigGAN/LICENSE +++ b/PyTorch/contrib/cv/others/BigGAN/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/BigGAN/datasets.py b/PyTorch/contrib/cv/others/BigGAN/datasets.py index 378f1b336ffbb413c298153b51a0d7989b98a065..751bd97941571e391a664123e65ecf334812e94c 100644 --- a/PyTorch/contrib/cv/others/BigGAN/datasets.py +++ b/PyTorch/contrib/cv/others/BigGAN/datasets.py @@ -1,378 +1,378 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -""" Datasets - This file contains definitions for our CIFAR, ImageFolder, and HDF5 datasets -""" -import os -import os.path -import sys -import numpy as np -import torch.utils.data as data -import torchvision.datasets as dset -from PIL import Image -from tqdm import tqdm - -IMG_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.ppm', '.bmp', '.pgm'] - - -def is_image_file(filename): - """Checks if a file is an image. - - Args: - filename (string): path to a file - - Returns: - bool: True if the filename ends with a known image extension - """ - filename_lower = filename.lower() - return any(filename_lower.endswith(ext) for ext in IMG_EXTENSIONS) - - -def find_classes(dir): - classes = [d for d in os.listdir(dir) if os.path.isdir(os.path.join(dir, d))] - classes.sort() - class_to_idx = {classes[i]: i for i in range(len(classes))} - return classes, class_to_idx - - -def make_dataset(dir, class_to_idx): - images = [] - dir = os.path.expanduser(dir) - for target in tqdm(sorted(os.listdir(dir))): - d = os.path.join(dir, target) - if not os.path.isdir(d): - continue - - for root, _, fnames in sorted(os.walk(d)): - for fname in sorted(fnames): - if is_image_file(fname): - path = os.path.join(root, fname) - item = (path, class_to_idx[target]) - images.append(item) - - return images - - -def pil_loader(path): - # open path as file to avoid ResourceWarning (https://github.com/python-pillow/Pillow/issues/835) - with open(path, 'rb') as f: - img = Image.open(f) - return img.convert('RGB') - - -def accimage_loader(path): - import accimage - try: - return accimage.Image(path) - except IOError: - # Potentially a decoding problem, fall back to PIL.Image - return pil_loader(path) - - -def default_loader(path): - from torchvision import get_image_backend - if get_image_backend() == 'accimage': - return accimage_loader(path) - else: - return pil_loader(path) - - -class ImageFolder(data.Dataset): - """A generic data loader where the images are arranged in this way: :: - - root/dogball/xxx.png - root/dogball/xxy.png - root/dogball/xxz.png - - root/cat/123.png - root/cat/nsdf3.png - root/cat/asd932_.png - - Args: - root (string): Root directory path. - transform (callable, optional): A function/transform that takes in an PIL image - and returns a transformed version. E.g, ``transforms.RandomCrop`` - target_transform (callable, optional): A function/transform that takes in the - target and transforms it. - loader (callable, optional): A function to load an image given its path. - - Attributes: - classes (list): List of the class names. - class_to_idx (dict): Dict with items (class_name, class_index). - imgs (list): List of (image path, class_index) tuples - """ - - def __init__(self, root, transform=None, target_transform=None, - loader=default_loader, load_in_mem=False, - index_filename='imagenet_imgs.npz', **kwargs): - classes, class_to_idx = find_classes(root) - # Load pre-computed image directory walk - if os.path.exists(index_filename): - print('Loading pre-saved Index file %s...' % index_filename) - imgs = np.load(index_filename)['imgs'] - # If first time, walk the folder directory and save the - # results to a pre-computed file. - else: - print('Generating Index file %s...' % index_filename) - imgs = make_dataset(root, class_to_idx) - np.savez_compressed(index_filename, **{'imgs': imgs}) - if len(imgs) == 0: - raise (RuntimeError("Found 0 images in subfolders of: " + root + "\n" - "Supported image extensions are: " + ",".join( - IMG_EXTENSIONS))) - - self.root = root - self.imgs = imgs - self.classes = classes - self.class_to_idx = class_to_idx - self.transform = transform - self.target_transform = target_transform - self.loader = loader - self.load_in_mem = load_in_mem - - if self.load_in_mem: - print('Loading all images into memory...') - self.data, self.labels = [], [] - for index in tqdm(range(len(self.imgs))): - path, target = imgs[index][0], imgs[index][1] - self.data.append(self.transform(self.loader(path))) - self.labels.append(target) - - def __getitem__(self, index): - """ - Args: - index (int): Index - - Returns: - tuple: (image, target) where target is class_index of the target class. - """ - if self.load_in_mem: - img = self.data[index] - target = self.labels[index] - else: - path, target = self.imgs[index] - img = self.loader(str(path)) - if self.transform is not None: - img = self.transform(img) - - if self.target_transform is not None: - target = self.target_transform(target) - - # print(img.size(), target) - return img, int(target) - - def __len__(self): - return len(self.imgs) - - def __repr__(self): - fmt_str = 'Dataset ' + self.__class__.__name__ + '\n' - fmt_str += ' Number of datapoints: {}\n'.format(self.__len__()) - fmt_str += ' Root Location: {}\n'.format(self.root) - tmp = ' Transforms (if any): ' - fmt_str += '{0}{1}\n'.format(tmp, self.transform.__repr__().replace('\n', '\n' + ' ' * len(tmp))) - tmp = ' Target Transforms (if any): ' - fmt_str += '{0}{1}'.format(tmp, self.target_transform.__repr__().replace('\n', '\n' + ' ' * len(tmp))) - return fmt_str - - -''' ILSVRC_HDF5: A dataset to support I/O from an HDF5 to avoid - having to load individual images all the time. ''' -import h5py as h5 -import torch - - -class ILSVRC_HDF5(data.Dataset): - def __init__(self, root, transform=None, target_transform=None, - load_in_mem=False, train=True, download=False, validate_seed=0, - val_split=0, **kwargs): # last four are dummies - - self.root = root - self.num_imgs = len(h5.File(root, 'r')['labels']) - - # self.transform = transform - self.target_transform = target_transform - - # Set the transform here - self.transform = transform - - # load the entire dataset into memory? - self.load_in_mem = load_in_mem - - # If loading into memory, do so now - if self.load_in_mem: - print('Loading %s into memory...' % root) - with h5.File(root, 'r') as f: - self.data = f['imgs'][:] - self.labels = f['labels'][:] - - def __getitem__(self, index): - """ - Args: - index (int): Index - - Returns: - tuple: (image, target) where target is class_index of the target class. - """ - # If loaded the entire dataset in RAM, get image from memory - if self.load_in_mem: - img = self.data[index] - target = self.labels[index] - - # Else load it from disk - else: - with h5.File(self.root, 'r') as f: - img = f['imgs'][index] - target = f['labels'][index] - - # if self.transform is not None: - # img = self.transform(img) - # Apply my own transform - img = ((torch.from_numpy(img).float() / 255) - 0.5) * 2 - - if self.target_transform is not None: - target = self.target_transform(target) - - return img, int(target) - - def __len__(self): - return self.num_imgs - # return len(self.f['imgs']) - - -import pickle - - -class CIFAR10(dset.CIFAR10): - - def __init__(self, root, train=True, - transform=None, target_transform=None, - download=True, validate_seed=0, - val_split=0, load_in_mem=True, **kwargs): - self.root = os.path.expanduser(root) - self.transform = transform - self.target_transform = target_transform - self.train = train # training set or test set - self.val_split = val_split - - if download: - self.download() - - if not self._check_integrity(): - raise RuntimeError('Dataset not found or corrupted.' + - ' You can use download=True to download it') - - # now load the picked numpy arrays - self.data = [] - self.labels = [] - for fentry in self.train_list: - f = fentry[0] - file = os.path.join(self.root, self.base_folder, f) - fo = open(file, 'rb') - if sys.version_info[0] == 2: - entry = pickle.load(fo) - else: - entry = pickle.load(fo, encoding='latin1') - self.data.append(entry['data']) - if 'labels' in entry: - self.labels += entry['labels'] - else: - self.labels += entry['fine_labels'] - fo.close() - - self.data = np.concatenate(self.data) - # Randomly select indices for validation - if self.val_split > 0: - label_indices = [[] for _ in range(max(self.labels) + 1)] - for i, l in enumerate(self.labels): - label_indices[l] += [i] - label_indices = np.asarray(label_indices) - - # randomly grab 500 elements of each class - np.random.seed(validate_seed) - self.val_indices = [] - for l_i in label_indices: - self.val_indices += list(l_i[np.random.choice(len(l_i), - int(len(self.data) * val_split) // (max(self.labels) + 1), - replace=False)]) - - if self.train == 'validate': - self.data = self.data[self.val_indices] - self.labels = list(np.asarray(self.labels)[self.val_indices]) - - self.data = self.data.reshape((int(50e3 * self.val_split), 3, 32, 32)) - self.data = self.data.transpose((0, 2, 3, 1)) # convert to HWC - - elif self.train: - print(np.shape(self.data)) - if self.val_split > 0: - self.data = np.delete(self.data, self.val_indices, axis=0) - self.labels = list(np.delete(np.asarray(self.labels), self.val_indices, axis=0)) - - self.data = self.data.reshape((int(50e3 * (1. - self.val_split)), 3, 32, 32)) - self.data = self.data.transpose((0, 2, 3, 1)) # convert to HWC - else: - f = self.test_list[0][0] - file = os.path.join(self.root, self.base_folder, f) - fo = open(file, 'rb') - if sys.version_info[0] == 2: - entry = pickle.load(fo) - else: - entry = pickle.load(fo, encoding='latin1') - self.data = entry['data'] - if 'labels' in entry: - self.labels = entry['labels'] - else: - self.labels = entry['fine_labels'] - fo.close() - self.data = self.data.reshape((10000, 3, 32, 32)) - self.data = self.data.transpose((0, 2, 3, 1)) # convert to HWC - - def __getitem__(self, index): - """ - Args: - index (int): Index - Returns: - tuple: (image, target) where target is index of the target class. - """ - img, target = self.data[index], self.labels[index] - - # doing this so that it is consistent with all other datasets - # to return a PIL Image - img = Image.fromarray(img) - - if self.transform is not None: - img = self.transform(img) - - if self.target_transform is not None: - target = self.target_transform(target) - - return img, target - - def __len__(self): - return len(self.data) - - -class CIFAR100(CIFAR10): - base_folder = 'cifar-100-python' - url = "http://www.cs.toronto.edu/~kriz/cifar-100-python.tar.gz" - filename = "cifar-100-python.tar.gz" - tgz_md5 = 'eb9058c3a382ffc7106e4002c42a8d85' - train_list = [ - ['train', '16019d7e3df5f24257cddd939b257f8d'], - ] - - test_list = [ - ['test', 'f0ef6b0ae62326f3e7ffdfab6717acfc'], - ] +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +""" Datasets + This file contains definitions for our CIFAR, ImageFolder, and HDF5 datasets +""" +import os +import os.path +import sys +import numpy as np +import torch.utils.data as data +import torchvision.datasets as dset +from PIL import Image +from tqdm import tqdm + +IMG_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.ppm', '.bmp', '.pgm'] + + +def is_image_file(filename): + """Checks if a file is an image. + + Args: + filename (string): path to a file + + Returns: + bool: True if the filename ends with a known image extension + """ + filename_lower = filename.lower() + return any(filename_lower.endswith(ext) for ext in IMG_EXTENSIONS) + + +def find_classes(dir): + classes = [d for d in os.listdir(dir) if os.path.isdir(os.path.join(dir, d))] + classes.sort() + class_to_idx = {classes[i]: i for i in range(len(classes))} + return classes, class_to_idx + + +def make_dataset(dir, class_to_idx): + images = [] + dir = os.path.expanduser(dir) + for target in tqdm(sorted(os.listdir(dir))): + d = os.path.join(dir, target) + if not os.path.isdir(d): + continue + + for root, _, fnames in sorted(os.walk(d)): + for fname in sorted(fnames): + if is_image_file(fname): + path = os.path.join(root, fname) + item = (path, class_to_idx[target]) + images.append(item) + + return images + + +def pil_loader(path): + # open path as file to avoid ResourceWarning (https://github.com/python-pillow/Pillow/issues/835) + with open(path, 'rb') as f: + img = Image.open(f) + return img.convert('RGB') + + +def accimage_loader(path): + import accimage + try: + return accimage.Image(path) + except IOError: + # Potentially a decoding problem, fall back to PIL.Image + return pil_loader(path) + + +def default_loader(path): + from torchvision import get_image_backend + if get_image_backend() == 'accimage': + return accimage_loader(path) + else: + return pil_loader(path) + + +class ImageFolder(data.Dataset): + """A generic data loader where the images are arranged in this way: :: + + root/dogball/xxx.png + root/dogball/xxy.png + root/dogball/xxz.png + + root/cat/123.png + root/cat/nsdf3.png + root/cat/asd932_.png + + Args: + root (string): Root directory path. + transform (callable, optional): A function/transform that takes in an PIL image + and returns a transformed version. E.g, ``transforms.RandomCrop`` + target_transform (callable, optional): A function/transform that takes in the + target and transforms it. + loader (callable, optional): A function to load an image given its path. + + Attributes: + classes (list): List of the class names. + class_to_idx (dict): Dict with items (class_name, class_index). + imgs (list): List of (image path, class_index) tuples + """ + + def __init__(self, root, transform=None, target_transform=None, + loader=default_loader, load_in_mem=False, + index_filename='imagenet_imgs.npz', **kwargs): + classes, class_to_idx = find_classes(root) + # Load pre-computed image directory walk + if os.path.exists(index_filename): + print('Loading pre-saved Index file %s...' % index_filename) + imgs = np.load(index_filename)['imgs'] + # If first time, walk the folder directory and save the + # results to a pre-computed file. + else: + print('Generating Index file %s...' % index_filename) + imgs = make_dataset(root, class_to_idx) + np.savez_compressed(index_filename, **{'imgs': imgs}) + if len(imgs) == 0: + raise (RuntimeError("Found 0 images in subfolders of: " + root + "\n" + "Supported image extensions are: " + ",".join( + IMG_EXTENSIONS))) + + self.root = root + self.imgs = imgs + self.classes = classes + self.class_to_idx = class_to_idx + self.transform = transform + self.target_transform = target_transform + self.loader = loader + self.load_in_mem = load_in_mem + + if self.load_in_mem: + print('Loading all images into memory...') + self.data, self.labels = [], [] + for index in tqdm(range(len(self.imgs))): + path, target = imgs[index][0], imgs[index][1] + self.data.append(self.transform(self.loader(path))) + self.labels.append(target) + + def __getitem__(self, index): + """ + Args: + index (int): Index + + Returns: + tuple: (image, target) where target is class_index of the target class. + """ + if self.load_in_mem: + img = self.data[index] + target = self.labels[index] + else: + path, target = self.imgs[index] + img = self.loader(str(path)) + if self.transform is not None: + img = self.transform(img) + + if self.target_transform is not None: + target = self.target_transform(target) + + # print(img.size(), target) + return img, int(target) + + def __len__(self): + return len(self.imgs) + + def __repr__(self): + fmt_str = 'Dataset ' + self.__class__.__name__ + '\n' + fmt_str += ' Number of datapoints: {}\n'.format(self.__len__()) + fmt_str += ' Root Location: {}\n'.format(self.root) + tmp = ' Transforms (if any): ' + fmt_str += '{0}{1}\n'.format(tmp, self.transform.__repr__().replace('\n', '\n' + ' ' * len(tmp))) + tmp = ' Target Transforms (if any): ' + fmt_str += '{0}{1}'.format(tmp, self.target_transform.__repr__().replace('\n', '\n' + ' ' * len(tmp))) + return fmt_str + + +''' ILSVRC_HDF5: A dataset to support I/O from an HDF5 to avoid + having to load individual images all the time. ''' +import h5py as h5 +import torch + + +class ILSVRC_HDF5(data.Dataset): + def __init__(self, root, transform=None, target_transform=None, + load_in_mem=False, train=True, download=False, validate_seed=0, + val_split=0, **kwargs): # last four are dummies + + self.root = root + self.num_imgs = len(h5.File(root, 'r')['labels']) + + # self.transform = transform + self.target_transform = target_transform + + # Set the transform here + self.transform = transform + + # load the entire dataset into memory? + self.load_in_mem = load_in_mem + + # If loading into memory, do so now + if self.load_in_mem: + print('Loading %s into memory...' % root) + with h5.File(root, 'r') as f: + self.data = f['imgs'][:] + self.labels = f['labels'][:] + + def __getitem__(self, index): + """ + Args: + index (int): Index + + Returns: + tuple: (image, target) where target is class_index of the target class. + """ + # If loaded the entire dataset in RAM, get image from memory + if self.load_in_mem: + img = self.data[index] + target = self.labels[index] + + # Else load it from disk + else: + with h5.File(self.root, 'r') as f: + img = f['imgs'][index] + target = f['labels'][index] + + # if self.transform is not None: + # img = self.transform(img) + # Apply my own transform + img = ((torch.from_numpy(img).float() / 255) - 0.5) * 2 + + if self.target_transform is not None: + target = self.target_transform(target) + + return img, int(target) + + def __len__(self): + return self.num_imgs + # return len(self.f['imgs']) + + +import pickle + + +class CIFAR10(dset.CIFAR10): + + def __init__(self, root, train=True, + transform=None, target_transform=None, + download=True, validate_seed=0, + val_split=0, load_in_mem=True, **kwargs): + self.root = os.path.expanduser(root) + self.transform = transform + self.target_transform = target_transform + self.train = train # training set or test set + self.val_split = val_split + + if download: + self.download() + + if not self._check_integrity(): + raise RuntimeError('Dataset not found or corrupted.' + + ' You can use download=True to download it') + + # now load the picked numpy arrays + self.data = [] + self.labels = [] + for fentry in self.train_list: + f = fentry[0] + file = os.path.join(self.root, self.base_folder, f) + fo = open(file, 'rb') + if sys.version_info[0] == 2: + entry = pickle.load(fo) + else: + entry = pickle.load(fo, encoding='latin1') + self.data.append(entry['data']) + if 'labels' in entry: + self.labels += entry['labels'] + else: + self.labels += entry['fine_labels'] + fo.close() + + self.data = np.concatenate(self.data) + # Randomly select indices for validation + if self.val_split > 0: + label_indices = [[] for _ in range(max(self.labels) + 1)] + for i, l in enumerate(self.labels): + label_indices[l] += [i] + label_indices = np.asarray(label_indices) + + # randomly grab 500 elements of each class + np.random.seed(validate_seed) + self.val_indices = [] + for l_i in label_indices: + self.val_indices += list(l_i[np.random.choice(len(l_i), + int(len(self.data) * val_split) // (max(self.labels) + 1), + replace=False)]) + + if self.train == 'validate': + self.data = self.data[self.val_indices] + self.labels = list(np.asarray(self.labels)[self.val_indices]) + + self.data = self.data.reshape((int(50e3 * self.val_split), 3, 32, 32)) + self.data = self.data.transpose((0, 2, 3, 1)) # convert to HWC + + elif self.train: + print(np.shape(self.data)) + if self.val_split > 0: + self.data = np.delete(self.data, self.val_indices, axis=0) + self.labels = list(np.delete(np.asarray(self.labels), self.val_indices, axis=0)) + + self.data = self.data.reshape((int(50e3 * (1. - self.val_split)), 3, 32, 32)) + self.data = self.data.transpose((0, 2, 3, 1)) # convert to HWC + else: + f = self.test_list[0][0] + file = os.path.join(self.root, self.base_folder, f) + fo = open(file, 'rb') + if sys.version_info[0] == 2: + entry = pickle.load(fo) + else: + entry = pickle.load(fo, encoding='latin1') + self.data = entry['data'] + if 'labels' in entry: + self.labels = entry['labels'] + else: + self.labels = entry['fine_labels'] + fo.close() + self.data = self.data.reshape((10000, 3, 32, 32)) + self.data = self.data.transpose((0, 2, 3, 1)) # convert to HWC + + def __getitem__(self, index): + """ + Args: + index (int): Index + Returns: + tuple: (image, target) where target is index of the target class. + """ + img, target = self.data[index], self.labels[index] + + # doing this so that it is consistent with all other datasets + # to return a PIL Image + img = Image.fromarray(img) + + if self.transform is not None: + img = self.transform(img) + + if self.target_transform is not None: + target = self.target_transform(target) + + return img, target + + def __len__(self): + return len(self.data) + + +class CIFAR100(CIFAR10): + base_folder = 'cifar-100-python' + url = "http://www.cs.toronto.edu/~kriz/cifar-100-python.tar.gz" + filename = "cifar-100-python.tar.gz" + tgz_md5 = 'eb9058c3a382ffc7106e4002c42a8d85' + train_list = [ + ['train', '16019d7e3df5f24257cddd939b257f8d'], + ] + + test_list = [ + ['test', 'f0ef6b0ae62326f3e7ffdfab6717acfc'], + ] diff --git a/PyTorch/contrib/cv/others/BigGAN/evaluation.py b/PyTorch/contrib/cv/others/BigGAN/evaluation.py index f08855891eabeab6713acdc00306f2cfcc8dcd72..4c6032cc362b831f6b77f2292d5b82ec71af0d4b 100644 --- a/PyTorch/contrib/cv/others/BigGAN/evaluation.py +++ b/PyTorch/contrib/cv/others/BigGAN/evaluation.py @@ -1,86 +1,86 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import functools -import torch -import inception_utils -import utils -from train import get_device_name - - -def evaluation(config): - config['resolution'] = utils.imsize_dict[config['dataset']] - config['n_classes'] = utils.nclass_dict[config['dataset']] - config['G_activation'] = utils.activation_dict[config['G_nl']] - config['D_activation'] = utils.activation_dict[config['D_nl']] - config = utils.update_config_roots(config) - # Seed RNG - utils.seed_rng(config['seed']) - - # By default, skip init if resuming training. - if config['resume']: - print('Skipping initialization for training resumption...') - config['skip_init'] = True - - # init device - device_loc = get_device_name(config['device'], config['gpu']) - config['loc'] = device_loc - # set device - print('set_device ', device_loc) - if config['device'] == 'npu': - torch.npu.set_device(device_loc) - else: - torch.cuda.set_device(config['gpu']) - - # model - # Import the model--this line allows us to dynamically select different files. - model = __import__(config['model']) - # Next, build the model - G = model.Generator(**config).to(device_loc) - - state_dict = {'itr': 0, 'epoch': 0, 'save_num': 0, 'save_best_num': 0, - 'best_IS': 0, 'best_FID': 999999, 'config': config} - - # If loading from a pre-trained model, load weights - if config['resume']: - print('Loading weights...gpu id : ', config['gpu']) - utils.load_weights(G, None, state_dict, - config['weights_root'], config['experiment_name'], - config['load_weights'] if config['load_weights'] else None, - None, root=config['weights_path'], load_optim=False) - print("load weights ok") - - # prepare input - G_batch_size = max(config['G_batch_size'], config['batch_size']) - z_, y_ = utils.prepare_z_y(G_batch_size, G.dim_z, config['n_classes'], device=device_loc) - # Prepare Sample function for use with inception metrics - sample = functools.partial(utils.sample, G=G, z_=z_, y_=y_, config=config) - # Prepare inception metrics: FID and IS - get_inception_metrics = inception_utils.prepare_inception_metrics(config['dataset'], config['parallel'], - config['no_fid'], config['loc'], - config['use_fp16'], config['opt_level']) - if config['G_eval_mode']: - G.eval() - IS_mean, IS_std, FID = get_inception_metrics(sample, config['num_inception_images'], num_splits=10) - log_string = "IS_mean: {:.5f}, IS_std: {:.5f}, FID: {:.5f}".format(IS_mean, IS_std, FID) - print(log_string) - with open("evaluation_log.log", "a+") as f: - f.write("itr: {} , {:s}\n".format(state_dict['itr'], log_string)) - - -if __name__ == "__main__": - # parse command line and run - parser = utils.prepare_parser() - config = vars(parser.parse_args()) - evaluation(config) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import functools +import torch +import inception_utils +import utils +from train import get_device_name + + +def evaluation(config): + config['resolution'] = utils.imsize_dict[config['dataset']] + config['n_classes'] = utils.nclass_dict[config['dataset']] + config['G_activation'] = utils.activation_dict[config['G_nl']] + config['D_activation'] = utils.activation_dict[config['D_nl']] + config = utils.update_config_roots(config) + # Seed RNG + utils.seed_rng(config['seed']) + + # By default, skip init if resuming training. + if config['resume']: + print('Skipping initialization for training resumption...') + config['skip_init'] = True + + # init device + device_loc = get_device_name(config['device'], config['gpu']) + config['loc'] = device_loc + # set device + print('set_device ', device_loc) + if config['device'] == 'npu': + torch.npu.set_device(device_loc) + else: + torch.cuda.set_device(config['gpu']) + + # model + # Import the model--this line allows us to dynamically select different files. + model = __import__(config['model']) + # Next, build the model + G = model.Generator(**config).to(device_loc) + + state_dict = {'itr': 0, 'epoch': 0, 'save_num': 0, 'save_best_num': 0, + 'best_IS': 0, 'best_FID': 999999, 'config': config} + + # If loading from a pre-trained model, load weights + if config['resume']: + print('Loading weights...gpu id : ', config['gpu']) + utils.load_weights(G, None, state_dict, + config['weights_root'], config['experiment_name'], + config['load_weights'] if config['load_weights'] else None, + None, root=config['weights_path'], load_optim=False) + print("load weights ok") + + # prepare input + G_batch_size = max(config['G_batch_size'], config['batch_size']) + z_, y_ = utils.prepare_z_y(G_batch_size, G.dim_z, config['n_classes'], device=device_loc) + # Prepare Sample function for use with inception metrics + sample = functools.partial(utils.sample, G=G, z_=z_, y_=y_, config=config) + # Prepare inception metrics: FID and IS + get_inception_metrics = inception_utils.prepare_inception_metrics(config['dataset'], config['parallel'], + config['no_fid'], config['loc'], + config['use_fp16'], config['opt_level']) + if config['G_eval_mode']: + G.eval() + IS_mean, IS_std, FID = get_inception_metrics(sample, config['num_inception_images'], num_splits=10) + log_string = "IS_mean: {:.5f}, IS_std: {:.5f}, FID: {:.5f}".format(IS_mean, IS_std, FID) + print(log_string) + with open("evaluation_log.log", "a+") as f: + f.write("itr: {} , {:s}\n".format(state_dict['itr'], log_string)) + + +if __name__ == "__main__": + # parse command line and run + parser = utils.prepare_parser() + config = vars(parser.parse_args()) + evaluation(config) diff --git a/PyTorch/contrib/cv/others/BigGAN/modelzoo_level.txt b/PyTorch/contrib/cv/others/BigGAN/modelzoo_level.txt index 5afcef9188bf9d39f1e34b45bd91324c6093137a..3117fffc3be7f5c479f10f09ba38a25c47739a00 100644 --- a/PyTorch/contrib/cv/others/BigGAN/modelzoo_level.txt +++ b/PyTorch/contrib/cv/others/BigGAN/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/BigGAN/requirements.txt b/PyTorch/contrib/cv/others/BigGAN/requirements.txt index 5648e61754231c103062dc569331e32788ecad6e..3b0b6a7bb2cb26830dd313a999fed8b0eb02ec71 100644 --- a/PyTorch/contrib/cv/others/BigGAN/requirements.txt +++ b/PyTorch/contrib/cv/others/BigGAN/requirements.txt @@ -1,8 +1,8 @@ -numpy -torchvision -tqdm -h5py -pillow -six -scipy +numpy +torchvision +tqdm +h5py +pillow +six +scipy torch \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/CGAN/LICENSE b/PyTorch/contrib/cv/others/CGAN/LICENSE index 29f81d812f3e768fa89638d1f72920dbfd1413a8..261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64 100644 --- a/PyTorch/contrib/cv/others/CGAN/LICENSE +++ b/PyTorch/contrib/cv/others/CGAN/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/PyTorch/contrib/cv/others/CGAN/README.md b/PyTorch/contrib/cv/others/CGAN/README.md index aa146c4a2cb09c088c2174855be3211995c7a8e1..2a14c1b90f5be0fcf9c212bf536faf867d7cfd30 100644 --- a/PyTorch/contrib/cv/others/CGAN/README.md +++ b/PyTorch/contrib/cv/others/CGAN/README.md @@ -1,130 +1,130 @@ -CGAN训练 - -``` -Generative adversarial nets can be extended to a conditional model if both the generator and discriminator are conditioned on some extra information y. y could be any kind of auxiliary information,such as class labels or data from other modalities. The author perform the conditioning by feeding y into the both the discriminator and generator as additional input layer.In the generator the prior input noise pz(z), and y are combined in joint hidden representation, and the adversarial training framework allows for considerable flexibility in how this hidden representation is composed. In the discriminator x and y are presented as inputs and to a discriminative function. -``` - -For more detail:https://arxiv.org/abs/1411.1784 - -The original gpu code:https://github.com/znxlwm/pytorch-generative-model-collections/ - -## Requirements - -use pytorch, you can use pip or conda to install the requirements - -``` -# for pip -cd $project -pip3.7 install -r requirements.txt -CANN 5.0.3 -torchvision==0.6.0 -``` - - - -## 数据集准备 - -1.下载mnist数据集作为训练集,dataloader.py中有自动下载mnist数据集的代码,执行训练命令会自动调用dataloader.py下载数据集,并保存在“./data/mnist“目录下。(请保持网络通畅) - -文件结构如下: - - -``` -CGAN -|-- data /数据集文件夹 -| |-- mnist /验证集,测试集 -|-- demo /demo.py的输出 -|--models /生成器和判别器模型保存目录 -|-- test /脚本文件夹 -| |--env.sh /环境配置文件 -| |--eval_1p.sh /单卡测试脚本 -| |--train_full_1p.sh /单卡精度测试脚本 -| |--train_full_8p.sh /8卡精度测试脚本 -| |--train_performance_1p.sh /单卡性能测试脚本 -| |--train_performance_8p.sh /8卡性能测试脚本 -|--results /生成器生成图片保存路径 -|-- CGAN.py /模型定义脚本 -|-- demo.py /例子脚本 -|-- dataloaderpy /数据预处理文件 -|-- main.py /主函数,训练启动脚本 -|-- utils.py /其它需要调用的函数脚本 -``` - - - -## TRAIN - -### 单p训练 - -source 环境变量 - -``` -source ./test/env_npu.sh -``` - -性能脚本: - -``` -bash ./test/train_performance_1p.sh -``` - -精度脚本: - -``` -bash ./test/train_full_1p.sh -``` - - - -### 多p训练 - -source 环境变量 - -``` -source ./test/env_npu.sh -``` - -性能脚本: - -``` -bash ./test/train_performance_8p.sh -``` - -精度脚本: - -``` -bash ./test/train_full_8p.sh -``` - -模型保存在”./models“目录下,模型生成的图片保存在”./result“目录下 - -模型训练的loss曲线保存在”./models"目录下。 - -## TEST - -对比GPU和NPU模型生成的图片和训练loss曲线,两者大致一致。 - -| name | Epoch 50 | GIF | Loss | -| :---------- | --------------------------------------------------- | ------------------------------------------------------------ | ----------------------------------------------- | -| CGAN on GPU | ![](README.assets/CGAN_epoch050-16371345386081.png) | ![](README.assets/CGAN_generate_animation-16371345738152.gif) | ![](README.assets/CGAN_loss-16371346002224.png) | -| CGAN on NPU | ![](README.assets/CGAN_epoch050-16371346136555.png) | ![](README.assets/CGAN_generate_animation-16371346226546.gif) | ![](README.assets/CGAN_loss-16371346305157.png) | - -## Pth2onnx - -执行以下命令,完成pth到onnx模型的转换 - -``` -python3.7 pth2onnx.py --pth_path ./models/mnist/CGAN/CGAN_G.pth --onnx_path ./CGAN.onnx -``` - -## Demo - -执行以下命令,程序会自动生成输入并经过网络产生输出,将输出保存在"demo/demo_result.png"中 -``` -python3.7 demo.py --pth_path ./models/mnist/CGAN/CGAN_G.pth --save_path ./demo -``` - -### 精度对比 - -对比GPU和NPU生成的图片和loss曲线,两者差异不大,精度达标。 - +CGAN训练 + +``` +Generative adversarial nets can be extended to a conditional model if both the generator and discriminator are conditioned on some extra information y. y could be any kind of auxiliary information,such as class labels or data from other modalities. The author perform the conditioning by feeding y into the both the discriminator and generator as additional input layer.In the generator the prior input noise pz(z), and y are combined in joint hidden representation, and the adversarial training framework allows for considerable flexibility in how this hidden representation is composed. In the discriminator x and y are presented as inputs and to a discriminative function. +``` + +For more detail:https://arxiv.org/abs/1411.1784 + +The original gpu code:https://github.com/znxlwm/pytorch-generative-model-collections/ + +## Requirements + +use pytorch, you can use pip or conda to install the requirements + +``` +# for pip +cd $project +pip3.7 install -r requirements.txt +CANN 5.0.3 +torchvision==0.6.0 +``` + + + +## 数据集准备 + +1.下载mnist数据集作为训练集,dataloader.py中有自动下载mnist数据集的代码,执行训练命令会自动调用dataloader.py下载数据集,并保存在“./data/mnist“目录下。(请保持网络通畅) + +文件结构如下: + + +``` +CGAN +|-- data /数据集文件夹 +| |-- mnist /验证集,测试集 +|-- demo /demo.py的输出 +|--models /生成器和判别器模型保存目录 +|-- test /脚本文件夹 +| |--env.sh /环境配置文件 +| |--eval_1p.sh /单卡测试脚本 +| |--train_full_1p.sh /单卡精度测试脚本 +| |--train_full_8p.sh /8卡精度测试脚本 +| |--train_performance_1p.sh /单卡性能测试脚本 +| |--train_performance_8p.sh /8卡性能测试脚本 +|--results /生成器生成图片保存路径 +|-- CGAN.py /模型定义脚本 +|-- demo.py /例子脚本 +|-- dataloaderpy /数据预处理文件 +|-- main.py /主函数,训练启动脚本 +|-- utils.py /其它需要调用的函数脚本 +``` + + + +## TRAIN + +### 单p训练 + +source 环境变量 + +``` +source ./test/env_npu.sh +``` + +性能脚本: + +``` +bash ./test/train_performance_1p.sh +``` + +精度脚本: + +``` +bash ./test/train_full_1p.sh +``` + + + +### 多p训练 + +source 环境变量 + +``` +source ./test/env_npu.sh +``` + +性能脚本: + +``` +bash ./test/train_performance_8p.sh +``` + +精度脚本: + +``` +bash ./test/train_full_8p.sh +``` + +模型保存在”./models“目录下,模型生成的图片保存在”./result“目录下 + +模型训练的loss曲线保存在”./models"目录下。 + +## TEST + +对比GPU和NPU模型生成的图片和训练loss曲线,两者大致一致。 + +| name | Epoch 50 | GIF | Loss | +| :---------- | --------------------------------------------------- | ------------------------------------------------------------ | ----------------------------------------------- | +| CGAN on GPU | ![](README.assets/CGAN_epoch050-16371345386081.png) | ![](README.assets/CGAN_generate_animation-16371345738152.gif) | ![](README.assets/CGAN_loss-16371346002224.png) | +| CGAN on NPU | ![](README.assets/CGAN_epoch050-16371346136555.png) | ![](README.assets/CGAN_generate_animation-16371346226546.gif) | ![](README.assets/CGAN_loss-16371346305157.png) | + +## Pth2onnx + +执行以下命令,完成pth到onnx模型的转换 + +``` +python3.7 pth2onnx.py --pth_path ./models/mnist/CGAN/CGAN_G.pth --onnx_path ./CGAN.onnx +``` + +## Demo + +执行以下命令,程序会自动生成输入并经过网络产生输出,将输出保存在"demo/demo_result.png"中 +``` +python3.7 demo.py --pth_path ./models/mnist/CGAN/CGAN_G.pth --save_path ./demo +``` + +### 精度对比 + +对比GPU和NPU生成的图片和loss曲线,两者差异不大,精度达标。 + diff --git a/PyTorch/contrib/cv/others/CGAN/demo.py b/PyTorch/contrib/cv/others/CGAN/demo.py index ee8acb635e61a7096aa5aefecd67cb479c80680d..e2f24d669021e1bc5d6cc4ccbec41651a6bf221e 100644 --- a/PyTorch/contrib/cv/others/CGAN/demo.py +++ b/PyTorch/contrib/cv/others/CGAN/demo.py @@ -1,103 +1,103 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -from collections import OrderedDict -import torch -import torch.nn as nn -from CGAN import generator -import argparse -import os -import numpy as np -import utils - - -def proc_nodes_module(checkpoint): - new_state_dict = OrderedDict() - for k, v in checkpoint.items(): - if "module." in k: - name = k.replace("module.", "") - else: - name = k - new_state_dict[name] = v - return new_state_dict - - -def parse_args(): - desc = "Pytorch implementation of CGAN collections" - parser = argparse.ArgumentParser(description=desc) - parser.add_argument('--input_dim', type=int, default=62, help="The input_dim") - parser.add_argument('--output_dim', type=int, default=3, help="The output_dim") - parser.add_argument('--input_size', type=int, default=28, help="The image size of MNIST") - parser.add_argument('--class_num', type=int, default=10, help="The num of classes of MNIST") - parser.add_argument('--pth_path', type=str, default='CGAN_G.pth', help='pth model path') - parser.add_argument('--onnx_path', type=str, default="CGAN.onnx", help='onnx model path') - parser.add_argument('--save_path', type=str, default='demo', help="the generated image path") - return parser.parse_args() - - -def prep_preocess(args): - sample_num = args.class_num**2 - z_dim = args.input_dim - sample_z_ = torch.zeros((sample_num, z_dim)) - for i in range(args.class_num): - sample_z_[i * args.class_num] = torch.rand(1,z_dim) - for j in range(1, args.class_num): - sample_z_[i * args.class_num + j] = sample_z_[i * args.class_num] - - if not os.path.exists(os.path.join(args.save_path)): - os.makedirs(os.path.join(args.save_path)) - - temp = torch.zeros((args.class_num, 1)) - for i in range(args.class_num): - temp[i, 0] = i - - temp_y = torch.zeros((sample_num, 1)) - for i in range(args.class_num): - temp_y[i * args.class_num: (i + 1) * args.class_num] = temp - - sample_y_ = torch.zeros((sample_num, args.class_num)).scatter_(1, temp_y.type(torch.LongTensor), 1) - - return sample_z_, sample_y_ - - -def main(): - args = parse_args() - # Build model - local_device = torch.device("npu:0") - torch.npu.set_device(local_device) - print("using npu :{}".format(local_device)) - print('Loading model ...\n') - net = generator(input_dim=args.input_dim, output_dim=args.output_dim, - input_size=args.input_size, class_num=args.class_num) - model = net - checkpoint = torch.load(args.pth_path, map_location='cpu') - checkpoint = proc_nodes_module(checkpoint) - model.load_state_dict(checkpoint) - model.eval() - z,y=prep_preocess(args) - result = model(z,y) - result = result.cpu().data.numpy().transpose(0, 2, 3, 1) - result = (result + 1)/2 - sample_num = args.class_num**2 - image_frame_dim = int(np.floor(np.sqrt(sample_num))) - if not os.path.exists(os.path.join(args.save_path)): - os.makedirs(os.path.join(args.save_path)) - utils.save_images(result[:image_frame_dim * image_frame_dim, :, :, :], [image_frame_dim, image_frame_dim], - os.path.join(args.save_path,'demo_result.png')) - print("demo image stored in:", os.path.join(args.save_path,'demo_result.png')) - - -if __name__ == "__main__": +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +from collections import OrderedDict +import torch +import torch.nn as nn +from CGAN import generator +import argparse +import os +import numpy as np +import utils + + +def proc_nodes_module(checkpoint): + new_state_dict = OrderedDict() + for k, v in checkpoint.items(): + if "module." in k: + name = k.replace("module.", "") + else: + name = k + new_state_dict[name] = v + return new_state_dict + + +def parse_args(): + desc = "Pytorch implementation of CGAN collections" + parser = argparse.ArgumentParser(description=desc) + parser.add_argument('--input_dim', type=int, default=62, help="The input_dim") + parser.add_argument('--output_dim', type=int, default=3, help="The output_dim") + parser.add_argument('--input_size', type=int, default=28, help="The image size of MNIST") + parser.add_argument('--class_num', type=int, default=10, help="The num of classes of MNIST") + parser.add_argument('--pth_path', type=str, default='CGAN_G.pth', help='pth model path') + parser.add_argument('--onnx_path', type=str, default="CGAN.onnx", help='onnx model path') + parser.add_argument('--save_path', type=str, default='demo', help="the generated image path") + return parser.parse_args() + + +def prep_preocess(args): + sample_num = args.class_num**2 + z_dim = args.input_dim + sample_z_ = torch.zeros((sample_num, z_dim)) + for i in range(args.class_num): + sample_z_[i * args.class_num] = torch.rand(1,z_dim) + for j in range(1, args.class_num): + sample_z_[i * args.class_num + j] = sample_z_[i * args.class_num] + + if not os.path.exists(os.path.join(args.save_path)): + os.makedirs(os.path.join(args.save_path)) + + temp = torch.zeros((args.class_num, 1)) + for i in range(args.class_num): + temp[i, 0] = i + + temp_y = torch.zeros((sample_num, 1)) + for i in range(args.class_num): + temp_y[i * args.class_num: (i + 1) * args.class_num] = temp + + sample_y_ = torch.zeros((sample_num, args.class_num)).scatter_(1, temp_y.type(torch.LongTensor), 1) + + return sample_z_, sample_y_ + + +def main(): + args = parse_args() + # Build model + local_device = torch.device("npu:0") + torch.npu.set_device(local_device) + print("using npu :{}".format(local_device)) + print('Loading model ...\n') + net = generator(input_dim=args.input_dim, output_dim=args.output_dim, + input_size=args.input_size, class_num=args.class_num) + model = net + checkpoint = torch.load(args.pth_path, map_location='cpu') + checkpoint = proc_nodes_module(checkpoint) + model.load_state_dict(checkpoint) + model.eval() + z,y=prep_preocess(args) + result = model(z,y) + result = result.cpu().data.numpy().transpose(0, 2, 3, 1) + result = (result + 1)/2 + sample_num = args.class_num**2 + image_frame_dim = int(np.floor(np.sqrt(sample_num))) + if not os.path.exists(os.path.join(args.save_path)): + os.makedirs(os.path.join(args.save_path)) + utils.save_images(result[:image_frame_dim * image_frame_dim, :, :, :], [image_frame_dim, image_frame_dim], + os.path.join(args.save_path,'demo_result.png')) + print("demo image stored in:", os.path.join(args.save_path,'demo_result.png')) + + +if __name__ == "__main__": main() \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/CGAN/modelzoo_level.txt b/PyTorch/contrib/cv/others/CGAN/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/others/CGAN/modelzoo_level.txt +++ b/PyTorch/contrib/cv/others/CGAN/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/CGAN/pth2onnx.py b/PyTorch/contrib/cv/others/CGAN/pth2onnx.py index 43cad179c3a2ce08168afdb97b885d1f4384788a..cf793675995efd5667fa458cde704fd6e4a81bc5 100644 --- a/PyTorch/contrib/cv/others/CGAN/pth2onnx.py +++ b/PyTorch/contrib/cv/others/CGAN/pth2onnx.py @@ -1,67 +1,67 @@ - -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -from CGAN import generator -import torch -import torch.onnx -import sys -from collections import OrderedDict -import argparse - - -def parse_args(): - desc = "Pytorch implementation of CGAN collections" - parser = argparse.ArgumentParser(description=desc) - parser.add_argument('--input_dim', type=int, default=62, help="The input_dim") - parser.add_argument('--output_dim', type=int, default=3, help="The output_dim") - parser.add_argument('--input_size', type=int, default=28, help="The image size of MNIST") - parser.add_argument('--class_num', type=int, default=10, help="The num of classes of MNIST") - parser.add_argument('--pth_path', type=str, default='CGAN_G.pth', help='pth model path') - parser.add_argument('--onnx_path', type=str, default="CGAN.onnx", help='onnx model path') - return parser.parse_args() - - -def proc_nodes_module(checkpoint): - new_state_dict = OrderedDict() - for k, v in checkpoint.items(): - if "module." in k: - name = k.replace("module.", "") - else: - name = k - new_state_dict[name] = v - return new_state_dict - -def pth2onnx(): - args = parse_args() - net = generator(input_dim=args.input_dim, output_dim=args.output_dim, - input_size=args.input_size, class_num=args.class_num) - model = net - checkpoint = torch.load(args.pth_path, map_location='cpu') - checkpoint = proc_nodes_module(checkpoint) - model.load_state_dict(checkpoint) - model.eval() - input_names = ["image"] - output_names = ["output1"] - #dynamic_axes = {'image': {0: '-1'}, 'output1': {0: '-1'}} - dummy_input1 = torch.randn(100, 62) - dummy_input2 = torch.randn(100, 10) - torch.onnx.export(model, (dummy_input1,dummy_input2), args.onnx_path, input_names=input_names, - output_names=output_names, opset_version=11, verbose=True) - print("this model could generete pictures, specifically digits") - print('onnx export done.') - - -if __name__ == "__main__": + +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +from CGAN import generator +import torch +import torch.onnx +import sys +from collections import OrderedDict +import argparse + + +def parse_args(): + desc = "Pytorch implementation of CGAN collections" + parser = argparse.ArgumentParser(description=desc) + parser.add_argument('--input_dim', type=int, default=62, help="The input_dim") + parser.add_argument('--output_dim', type=int, default=3, help="The output_dim") + parser.add_argument('--input_size', type=int, default=28, help="The image size of MNIST") + parser.add_argument('--class_num', type=int, default=10, help="The num of classes of MNIST") + parser.add_argument('--pth_path', type=str, default='CGAN_G.pth', help='pth model path') + parser.add_argument('--onnx_path', type=str, default="CGAN.onnx", help='onnx model path') + return parser.parse_args() + + +def proc_nodes_module(checkpoint): + new_state_dict = OrderedDict() + for k, v in checkpoint.items(): + if "module." in k: + name = k.replace("module.", "") + else: + name = k + new_state_dict[name] = v + return new_state_dict + +def pth2onnx(): + args = parse_args() + net = generator(input_dim=args.input_dim, output_dim=args.output_dim, + input_size=args.input_size, class_num=args.class_num) + model = net + checkpoint = torch.load(args.pth_path, map_location='cpu') + checkpoint = proc_nodes_module(checkpoint) + model.load_state_dict(checkpoint) + model.eval() + input_names = ["image"] + output_names = ["output1"] + #dynamic_axes = {'image': {0: '-1'}, 'output1': {0: '-1'}} + dummy_input1 = torch.randn(100, 62) + dummy_input2 = torch.randn(100, 10) + torch.onnx.export(model, (dummy_input1,dummy_input2), args.onnx_path, input_names=input_names, + output_names=output_names, opset_version=11, verbose=True) + print("this model could generete pictures, specifically digits") + print('onnx export done.') + + +if __name__ == "__main__": pth2onnx() \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/CycleGAN/CycleGAN_NetLoad.py b/PyTorch/contrib/cv/others/CycleGAN/CycleGAN_NetLoad.py index eb500107040c180a59742c8137b383ecb0bb91e9..2effb5f2ba84a07b38b3ccb38c9bb517368e14f9 100644 --- a/PyTorch/contrib/cv/others/CycleGAN/CycleGAN_NetLoad.py +++ b/PyTorch/contrib/cv/others/CycleGAN/CycleGAN_NetLoad.py @@ -1,92 +1,92 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -from collections import OrderedDict -import torch -from models import networks_adapt as networks - - -class load_networks(): - def __init__(self, opt): - self.opt = opt - self.gpu = 0 - self.netG_A = networks.define_G(self.opt.input_nc, self.opt.output_nc, self.opt.ngf, self.opt.netG, - self.opt.norm, not self.opt.no_dropout, self.opt.init_type, self.opt.init_gain, - self.gpu) - self.netG_B = networks.define_G(self.opt.output_nc, self.opt.input_nc, self.opt.ngf, self.opt.netG, - self.opt.norm, not self.opt.no_dropout, self.opt.init_type, self.opt.init_gain, - self.gpu) - if (opt.npu >= 1): - self.device = torch.device('npu:{}'.format(self.gpu)) - if (opt.npu == 0): - self.device = torch.device('cuda:{}'.format(self.gpu)) - else: - self.device = torch.device("cpu") - - def __patch_instance_norm_state_dict(self, state_dict, module, keys, i=0): - """Fix InstanceNorm checkpoints incompatibility (prior to 0.4)""" - key = keys[i] - if i + 1 == len(keys): # at the end, pointing to a parameter/buffer - if module.__class__.__name__.startswith('InstanceNorm') and \ - (key == 'running_mean' or key == 'running_var'): - if getattr(module, key) is None: - state_dict.pop('.'.join(keys)) - if module.__class__.__name__.startswith('InstanceNorm') and \ - (key == 'num_batches_tracked'): - state_dict.pop('.'.join(keys)) - else: - self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) - - def proc_nodes_module(self, checkpoint): - new_state_dict = OrderedDict() - for k, v in checkpoint.items(): - if "module." in k: - name = k.replace("module.", "") - else: - name = k - new_state_dict[name] = v - return new_state_dict - - def loadnetworks(self, net, load_path): - state_dict = torch.load(load_path, map_location=torch.device('cpu')) - state_dict = self.proc_nodes_module(state_dict) - if hasattr(state_dict, '_metadata'): - del state_dict._metadata - # patch InstanceNorm checkpoints prior to 0.4 - for key in list(state_dict.keys()): # need to copy keys here because we mutate in loop - self.__patch_instance_norm_state_dict(state_dict, net, key.split('.')) - net.load_state_dict(state_dict) - return net - - def get_networks(self, load_patha, load_pathb): - model_Ga = self.loadnetworks(self.netG_A, load_patha) - model_Gb = self.loadnetworks(self.netG_B, load_pathb) - return model_Ga, model_Gb +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +from collections import OrderedDict +import torch +from models import networks_adapt as networks + + +class load_networks(): + def __init__(self, opt): + self.opt = opt + self.gpu = 0 + self.netG_A = networks.define_G(self.opt.input_nc, self.opt.output_nc, self.opt.ngf, self.opt.netG, + self.opt.norm, not self.opt.no_dropout, self.opt.init_type, self.opt.init_gain, + self.gpu) + self.netG_B = networks.define_G(self.opt.output_nc, self.opt.input_nc, self.opt.ngf, self.opt.netG, + self.opt.norm, not self.opt.no_dropout, self.opt.init_type, self.opt.init_gain, + self.gpu) + if (opt.npu >= 1): + self.device = torch.device('npu:{}'.format(self.gpu)) + if (opt.npu == 0): + self.device = torch.device('cuda:{}'.format(self.gpu)) + else: + self.device = torch.device("cpu") + + def __patch_instance_norm_state_dict(self, state_dict, module, keys, i=0): + """Fix InstanceNorm checkpoints incompatibility (prior to 0.4)""" + key = keys[i] + if i + 1 == len(keys): # at the end, pointing to a parameter/buffer + if module.__class__.__name__.startswith('InstanceNorm') and \ + (key == 'running_mean' or key == 'running_var'): + if getattr(module, key) is None: + state_dict.pop('.'.join(keys)) + if module.__class__.__name__.startswith('InstanceNorm') and \ + (key == 'num_batches_tracked'): + state_dict.pop('.'.join(keys)) + else: + self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) + + def proc_nodes_module(self, checkpoint): + new_state_dict = OrderedDict() + for k, v in checkpoint.items(): + if "module." in k: + name = k.replace("module.", "") + else: + name = k + new_state_dict[name] = v + return new_state_dict + + def loadnetworks(self, net, load_path): + state_dict = torch.load(load_path, map_location=torch.device('cpu')) + state_dict = self.proc_nodes_module(state_dict) + if hasattr(state_dict, '_metadata'): + del state_dict._metadata + # patch InstanceNorm checkpoints prior to 0.4 + for key in list(state_dict.keys()): # need to copy keys here because we mutate in loop + self.__patch_instance_norm_state_dict(state_dict, net, key.split('.')) + net.load_state_dict(state_dict) + return net + + def get_networks(self, load_patha, load_pathb): + model_Ga = self.loadnetworks(self.netG_A, load_patha) + model_Gb = self.loadnetworks(self.netG_B, load_pathb) + return model_Ga, model_Gb diff --git a/PyTorch/contrib/cv/others/CycleGAN/LICENSE b/PyTorch/contrib/cv/others/CycleGAN/LICENSE index 4e1ad12a819e98036586f198d3873933f1892331..eb1309d6c1e79cfb4dad830ae04bfca945f5568e 100644 --- a/PyTorch/contrib/cv/others/CycleGAN/LICENSE +++ b/PyTorch/contrib/cv/others/CycleGAN/LICENSE @@ -1,31 +1,31 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ============================================================================ \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/CycleGAN/Readme.md b/PyTorch/contrib/cv/others/CycleGAN/Readme.md index 6eece9b767c2489f4a548198b61d069bde48b925..f3e1aa0e9acf1979f819df0174ed48d1da8d66c8 100644 --- a/PyTorch/contrib/cv/others/CycleGAN/Readme.md +++ b/PyTorch/contrib/cv/others/CycleGAN/Readme.md @@ -1,172 +1,172 @@ -# CycleGAN 训练 - -## Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks - -it's an approach for learning to translate an image from a source domain $X$ to a target domain $Y$ in the absence of paired examples - -For more detail:https://arxiv.org/abs/1703.10593v6 - -## - -## Requirements - - **You need to install CNN5.0.3 to ensure the normal training of the model!!** -and use pytorch, you can use pip or conda to install the requirements - -``` -# for pip -torch>=1.5.0 -torchvision>=0.5.0 -dominate>=2.4.0 -visdom>=0.1.8.8 -``` - -## 数据集准备 - -1.从以下网址获取maps.zip作为训练集 - -http://efrosgans.eecs.berkeley.edu/cyclegan/datasets/ - -文件结构如下: - - -``` -CycleGAN -|-- datasets -| |-- maps -| | |-- testA -| | |-- testB -| | |--trainA -| | |--trainB -| | |--valA -| | |--valB -|-- test - |--train_full_1p.sh - |--train_full_8p.sh - |--train_performance_1p.sh - |--train_performance_8p.sh -|-- models - |--cycle_gan_model_adapt.py - |--networks_adapt.py -|--util - |--html.py - |--visualizer_adapt.py - |--util.py - |--visualizer_adapt.py -|-- dataloader.py -|-- parse.py -|-- train.py -|--env_npu.sh - -``` - -将数据集按照以上结构放在代码目录下 - -## 安装 - -请注意,本模型使用了新版本的pytorch以及CANN包,具体版本为:torch-1.5.0+ascend.post3.20210930-cp37-cp37m-linux_aarch64.whl,Ascend-cann-toolkit_5.0.3_linux-aarch64.run; - -source 环境变量 - -``` -bash ./env_npu.sh -``` - - -## TRAIN - -### 单p训练 - -source 环境变量 - -``` -bash./env_npu.sh -``` - -运行单p脚本 - -``` -bash ./test/train_full_1p.sh -``` - - - -### 多p训练 - -source 环境变量 - -``` -source ./env_npu.sh -``` - -运行8p脚本 - -``` -bash ./test/train_full_8p.sh -``` - -模型保存在./checkpoints目录下,以数字命名的pth文件是当前epoch训练得到的权重文件,可用来恢复训练; - -运行日志保存至./目录下 - -## TEST - -测试精度 - - - -``` -由于论文为人眼观察生成效果的真假,所以这里省略,不过下面的demon提供将生成结果以网页的形式更为直观的展现出来 -``` - - - - -## Demo -然后运行以下脚本,执行demo.py: - -``` -python3.7.5 demon.py --pu_ids='0' \ - --prof=0 \ - --multiprocessing_distributed=0 \ - --distributed=1 \ - --npu=1 \ - --dataroot=./datasets/maps \ - --checkpoints_dir=./checkpoints_1pbs1_O1_sacle_1024_torchadam \ - --model_ga_path=./checkpoints_8pbs1/maps_cycle_gan/175_pu0_net_G_A.pth \ - --model_gb_path=./checkpoints_8pbs1/maps_cycle_gan/175_pu0_net_G_B.pth >>npu8pbs1_demon.log 2>&1 & -``` - -请指定需要测试的模型路径,将--checkpoints_dir、--model_ga_path、--model_gb_path所指向的参数替换掉既可替换掉即可,最后的输出结果存放在根目录的result目录下,点击index.html既可查看,结果展示请在支持浏览器的系统查看。 - -## 注意事项 -1、超参说明 -``` ---pu_ids='0,1,2,3,4,5,6,7'------------------------------------------指定几张卡训练,必须使用连续的卡号 ---prof=0------------------------------------------------------------是否测试性能,当为0时,不测试性能,为1则在大于等于10个epoch后输出prof文件 ---multiprocessing_distributed=1-------------------------------------是否执行多核训练,多卡必须为1,单卡设置为0既可 ---distributed=1-----------------------------------------------------该参数不可更改 ---npu=1-------------------------------------------------------------是否使用Npu开始训练,如果在Npu平台训练则必须使用1,GPU平台则必须为0 ---dataroot=./datasets/maps------------------------------------------数据集的目录 ---checkpoints_dir=./checkpoints_8pbs1_O1_sacle_1024_torchadam-------存放训练权重的目录 ---batch_size=1------------------------------------------------------指定训练时每个step输入多少样本,多卡训练不建议调高,单卡可适当调高为2。bs过大, - 会导致判别器过早收敛,进而造成生辰效果不佳 ---isapex=True-------------------------------------------------------是否开启混合精度进行训练,一般是开启的 ---apex_type="O1"----------------------------------------------------如果开启混合精度训练,建议使用O1模式,O2模式不收敛。当然O0也是可以的 ---loss_scale=1024---------------------------------------------------指定混合精度训练时的loss放大倍数,loss放大倍数也可以被指定为dynamic ---log_path="npu8pbs1.txt"-------------------------------------------只存放与模型有关的日志,不存放与后台输出有关的其他调试日志 ---num_epoch_start=0-------------------------------------------------从第几个epoch开始训练,如果开启继续训练,则需要指定该参数 ---num_epoch=200-----------------------------------------------------默认训练200个epoch,不可调高,但可以调低 ---n_epochs=100------------------------------------------------------权重衰减参数,默认前100个epoch保持学习率不变,后面开始慢慢线性衰减 ---lr=1e-4-----------------------------------------------------------baseline的学习率 ---line_scale=1------------------------------------------------------baseline的学习率的放大倍数,单卡为1,8卡训练建议设为2,其他卡酌情调参 ---n_epochs=100------------------------------------------------------与n_epochs保持一致 ---n_epochs_decay=100------------------------------------------------与n_epochs保持一致 ---pool_size=50-------------------------------------------------------该参数如果为单卡,使用50既可,如果为8卡,建议设置为16,其他卡酌情调参,一般多卡要调低且数 - 值为4的倍数 ---lambda_A=10--------------------------------------------------------论文超参 ---lambda_B=10--------------------------------------------------------论文超参 ---loadweight=199_pu0-----------------------------------------------------指定多少个epoch开始继续训练,重新训练默认参数既可 ---model_ga_path=./checkpoints_8pbs1/maps_cycle_gan/175_pu0_net_G_A.pth--存放权重的目录,运行demon的时候需要 ---model_gb_path=./checkpoints_8pbs1/maps_cycle_gan/175_pu0_net_G_B.pth--存放权重的目录,运行demon的时候需要_ -``` +# CycleGAN 训练 + +## Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks + +it's an approach for learning to translate an image from a source domain $X$ to a target domain $Y$ in the absence of paired examples + +For more detail:https://arxiv.org/abs/1703.10593v6 + +## + +## Requirements + + **You need to install CNN5.0.3 to ensure the normal training of the model!!** +and use pytorch, you can use pip or conda to install the requirements + +``` +# for pip +torch>=1.5.0 +torchvision>=0.5.0 +dominate>=2.4.0 +visdom>=0.1.8.8 +``` + +## 数据集准备 + +1.从以下网址获取maps.zip作为训练集 + +http://efrosgans.eecs.berkeley.edu/cyclegan/datasets/ + +文件结构如下: + + +``` +CycleGAN +|-- datasets +| |-- maps +| | |-- testA +| | |-- testB +| | |--trainA +| | |--trainB +| | |--valA +| | |--valB +|-- test + |--train_full_1p.sh + |--train_full_8p.sh + |--train_performance_1p.sh + |--train_performance_8p.sh +|-- models + |--cycle_gan_model_adapt.py + |--networks_adapt.py +|--util + |--html.py + |--visualizer_adapt.py + |--util.py + |--visualizer_adapt.py +|-- dataloader.py +|-- parse.py +|-- train.py +|--env_npu.sh + +``` + +将数据集按照以上结构放在代码目录下 + +## 安装 + +请注意,本模型使用了新版本的pytorch以及CANN包,具体版本为:torch-1.5.0+ascend.post3.20210930-cp37-cp37m-linux_aarch64.whl,Ascend-cann-toolkit_5.0.3_linux-aarch64.run; + +source 环境变量 + +``` +bash ./env_npu.sh +``` + + +## TRAIN + +### 单p训练 + +source 环境变量 + +``` +bash./env_npu.sh +``` + +运行单p脚本 + +``` +bash ./test/train_full_1p.sh +``` + + + +### 多p训练 + +source 环境变量 + +``` +source ./env_npu.sh +``` + +运行8p脚本 + +``` +bash ./test/train_full_8p.sh +``` + +模型保存在./checkpoints目录下,以数字命名的pth文件是当前epoch训练得到的权重文件,可用来恢复训练; + +运行日志保存至./目录下 + +## TEST + +测试精度 + + + +``` +由于论文为人眼观察生成效果的真假,所以这里省略,不过下面的demon提供将生成结果以网页的形式更为直观的展现出来 +``` + + + + +## Demo +然后运行以下脚本,执行demo.py: + +``` +python3.7.5 demon.py --pu_ids='0' \ + --prof=0 \ + --multiprocessing_distributed=0 \ + --distributed=1 \ + --npu=1 \ + --dataroot=./datasets/maps \ + --checkpoints_dir=./checkpoints_1pbs1_O1_sacle_1024_torchadam \ + --model_ga_path=./checkpoints_8pbs1/maps_cycle_gan/175_pu0_net_G_A.pth \ + --model_gb_path=./checkpoints_8pbs1/maps_cycle_gan/175_pu0_net_G_B.pth >>npu8pbs1_demon.log 2>&1 & +``` + +请指定需要测试的模型路径,将--checkpoints_dir、--model_ga_path、--model_gb_path所指向的参数替换掉既可替换掉即可,最后的输出结果存放在根目录的result目录下,点击index.html既可查看,结果展示请在支持浏览器的系统查看。 + +## 注意事项 +1、超参说明 +``` +--pu_ids='0,1,2,3,4,5,6,7'------------------------------------------指定几张卡训练,必须使用连续的卡号 +--prof=0------------------------------------------------------------是否测试性能,当为0时,不测试性能,为1则在大于等于10个epoch后输出prof文件 +--multiprocessing_distributed=1-------------------------------------是否执行多核训练,多卡必须为1,单卡设置为0既可 +--distributed=1-----------------------------------------------------该参数不可更改 +--npu=1-------------------------------------------------------------是否使用Npu开始训练,如果在Npu平台训练则必须使用1,GPU平台则必须为0 +--dataroot=./datasets/maps------------------------------------------数据集的目录 +--checkpoints_dir=./checkpoints_8pbs1_O1_sacle_1024_torchadam-------存放训练权重的目录 +--batch_size=1------------------------------------------------------指定训练时每个step输入多少样本,多卡训练不建议调高,单卡可适当调高为2。bs过大, + 会导致判别器过早收敛,进而造成生辰效果不佳 +--isapex=True-------------------------------------------------------是否开启混合精度进行训练,一般是开启的 +--apex_type="O1"----------------------------------------------------如果开启混合精度训练,建议使用O1模式,O2模式不收敛。当然O0也是可以的 +--loss_scale=1024---------------------------------------------------指定混合精度训练时的loss放大倍数,loss放大倍数也可以被指定为dynamic +--log_path="npu8pbs1.txt"-------------------------------------------只存放与模型有关的日志,不存放与后台输出有关的其他调试日志 +--num_epoch_start=0-------------------------------------------------从第几个epoch开始训练,如果开启继续训练,则需要指定该参数 +--num_epoch=200-----------------------------------------------------默认训练200个epoch,不可调高,但可以调低 +--n_epochs=100------------------------------------------------------权重衰减参数,默认前100个epoch保持学习率不变,后面开始慢慢线性衰减 +--lr=1e-4-----------------------------------------------------------baseline的学习率 +--line_scale=1------------------------------------------------------baseline的学习率的放大倍数,单卡为1,8卡训练建议设为2,其他卡酌情调参 +--n_epochs=100------------------------------------------------------与n_epochs保持一致 +--n_epochs_decay=100------------------------------------------------与n_epochs保持一致 +--pool_size=50-------------------------------------------------------该参数如果为单卡,使用50既可,如果为8卡,建议设置为16,其他卡酌情调参,一般多卡要调低且数 + 值为4的倍数 +--lambda_A=10--------------------------------------------------------论文超参 +--lambda_B=10--------------------------------------------------------论文超参 +--loadweight=199_pu0-----------------------------------------------------指定多少个epoch开始继续训练,重新训练默认参数既可 +--model_ga_path=./checkpoints_8pbs1/maps_cycle_gan/175_pu0_net_G_A.pth--存放权重的目录,运行demon的时候需要 +--model_gb_path=./checkpoints_8pbs1/maps_cycle_gan/175_pu0_net_G_B.pth--存放权重的目录,运行demon的时候需要_ +``` diff --git a/PyTorch/contrib/cv/others/CycleGAN/dataloader.py b/PyTorch/contrib/cv/others/CycleGAN/dataloader.py index 4cdc1e610cf9d470aea1a020dcfd7d52b55c2e05..71b12c2f9f127ecc567273443ae0d52e0f81fd8e 100644 --- a/PyTorch/contrib/cv/others/CycleGAN/dataloader.py +++ b/PyTorch/contrib/cv/others/CycleGAN/dataloader.py @@ -1,128 +1,128 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import importlib -import torch.utils.data -#from data.base_dataset import BaseDataset - - -def find_dataset_using_name(dataset_name): - """Import the module "data/[dataset_name]_dataset.py". - - In the file, the class called DatasetNameDataset() will - be instantiated. It has to be a subclass of BaseDataset, - and it is case-insensitive. - """ - dataset_filename = "data." + dataset_name + "_dataset" - datasetlib = importlib.import_module(dataset_filename) - - dataset = None - target_dataset_name = dataset_name.replace('_', '') + 'dataset' - for name, cls in datasetlib.__dict__.items(): - if name.lower() == target_dataset_name.lower(): - dataset = cls - - if dataset is None: - raise NotImplementedError("In %s.py, there should be a subclass of BaseDataset with class name that matches %s in lowercase." % (dataset_filename, target_dataset_name)) - - return dataset - - -def get_option_setter(dataset_name): - """Return the static method of the dataset class.""" - dataset_class = find_dataset_using_name(dataset_name) - return dataset_class.modify_commandline_options - - -def create_dataset(opt): - """Create a dataset given the option. - - This function wraps the class CustomDatasetDataLoader. - This is the main interface between this package and 'train.py'/'test.py' - """ - dataset_class = find_dataset_using_name(opt.dataset_mode) - datasets = dataset_class(opt) - train_sampler = torch.utils.data.distributed.DistributedSampler(datasets) - data_loader = CustomDatasetDataLoader(opt,datasets,train_sampler) - dataset = data_loader.load_data() - return dataset,train_sampler - - -class CustomDatasetDataLoader(): - """Wrapper class of Dataset class that performs multi-threaded data loading""" - - def __init__(self, opt,dataset,train_sampler): - """Initialize this class - - Step 1: create a dataset instance given the name [dataset_mode] - Step 2: create a multi-threaded data loader. - """ - self.opt = opt - - self.dataset=dataset - - print("dataset [%s] was created" % type(self.dataset).__name__) - if(opt.ngpus_per_node>1 and opt.multiprocessing_distributed>=1): - self.dataloader = torch.utils.data.DataLoader( - self.dataset, - batch_size=opt.batch_size, - shuffle=(train_sampler is None), - pin_memory=False, - num_workers=int(opt.num_threads), - sampler=train_sampler, - drop_last=True) - #self.dataloader = torch.utils.data.DataLoader( - # self.dataset, - # batch_size=opt.batch_size, - # shuffle=not opt.serial_batches, - # num_workers=int(opt.num_threads), - # ) - else: - self.dataloader = torch.utils.data.DataLoader( - self.dataset, - batch_size=opt.batch_size, - shuffle=not opt.serial_batches, - num_workers=int(opt.num_threads), - ) - - def load_data(self): - return self - - def __len__(self): - """Return the number of data in the dataset""" - return min(len(self.dataset), self.opt.max_dataset_size) - - def __iter__(self): - """Return a batch of data""" - for i, data in enumerate(self.dataloader): - if i * self.opt.batch_size >= self.opt.max_dataset_size: - break - yield data +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import importlib +import torch.utils.data +#from data.base_dataset import BaseDataset + + +def find_dataset_using_name(dataset_name): + """Import the module "data/[dataset_name]_dataset.py". + + In the file, the class called DatasetNameDataset() will + be instantiated. It has to be a subclass of BaseDataset, + and it is case-insensitive. + """ + dataset_filename = "data." + dataset_name + "_dataset" + datasetlib = importlib.import_module(dataset_filename) + + dataset = None + target_dataset_name = dataset_name.replace('_', '') + 'dataset' + for name, cls in datasetlib.__dict__.items(): + if name.lower() == target_dataset_name.lower(): + dataset = cls + + if dataset is None: + raise NotImplementedError("In %s.py, there should be a subclass of BaseDataset with class name that matches %s in lowercase." % (dataset_filename, target_dataset_name)) + + return dataset + + +def get_option_setter(dataset_name): + """Return the static method of the dataset class.""" + dataset_class = find_dataset_using_name(dataset_name) + return dataset_class.modify_commandline_options + + +def create_dataset(opt): + """Create a dataset given the option. + + This function wraps the class CustomDatasetDataLoader. + This is the main interface between this package and 'train.py'/'test.py' + """ + dataset_class = find_dataset_using_name(opt.dataset_mode) + datasets = dataset_class(opt) + train_sampler = torch.utils.data.distributed.DistributedSampler(datasets) + data_loader = CustomDatasetDataLoader(opt,datasets,train_sampler) + dataset = data_loader.load_data() + return dataset,train_sampler + + +class CustomDatasetDataLoader(): + """Wrapper class of Dataset class that performs multi-threaded data loading""" + + def __init__(self, opt,dataset,train_sampler): + """Initialize this class + + Step 1: create a dataset instance given the name [dataset_mode] + Step 2: create a multi-threaded data loader. + """ + self.opt = opt + + self.dataset=dataset + + print("dataset [%s] was created" % type(self.dataset).__name__) + if(opt.ngpus_per_node>1 and opt.multiprocessing_distributed>=1): + self.dataloader = torch.utils.data.DataLoader( + self.dataset, + batch_size=opt.batch_size, + shuffle=(train_sampler is None), + pin_memory=False, + num_workers=int(opt.num_threads), + sampler=train_sampler, + drop_last=True) + #self.dataloader = torch.utils.data.DataLoader( + # self.dataset, + # batch_size=opt.batch_size, + # shuffle=not opt.serial_batches, + # num_workers=int(opt.num_threads), + # ) + else: + self.dataloader = torch.utils.data.DataLoader( + self.dataset, + batch_size=opt.batch_size, + shuffle=not opt.serial_batches, + num_workers=int(opt.num_threads), + ) + + def load_data(self): + return self + + def __len__(self): + """Return the number of data in the dataset""" + return min(len(self.dataset), self.opt.max_dataset_size) + + def __iter__(self): + """Return a batch of data""" + for i, data in enumerate(self.dataloader): + if i * self.opt.batch_size >= self.opt.max_dataset_size: + break + yield data diff --git a/PyTorch/contrib/cv/others/CycleGAN/demon.py b/PyTorch/contrib/cv/others/CycleGAN/demon.py index 1090328622f263aaf2a4bc0f89bc9b1ce45dff8f..cbcff3e5542702c29d21089ae167bce2241af40f 100644 --- a/PyTorch/contrib/cv/others/CycleGAN/demon.py +++ b/PyTorch/contrib/cv/others/CycleGAN/demon.py @@ -1,189 +1,189 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import os -import torchvision.transforms as transforms -from PIL import Image -import torch.onnx -from torch.utils.data import Dataset -from torchvision.datasets.folder import IMG_EXTENSIONS -from parse import parse_args -from CycleGAN_NetLoad import load_networks - - -def make_power(img, base): - ow, oh = img.size - h = int(round(oh / base) * base) - w = int(round(ow / base) * base) - if h == oh and w == ow: - return img - - -def preprocess(image_shape): - process = transforms.Compose([ - transforms.Lambda(lambda img: make_power(img, base=4)), - transforms.Resize(image_shape), - transforms.ToTensor(), - transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))]) - return process - - -def postprocess(img_tensor): - inv_normalize = transforms.Normalize( - mean=(-1, -1, -1), - std=(2.0, 2.0, 2.0)) - to_PIL_image = transforms.ToPILImage() - return to_PIL_image(inv_normalize(img_tensor[0]).clamp(0, 1)) - - -def make_dataset(dir, max_dataset_size=float("inf")): - images = [] - assert os.path.isdir(dir), '%s is not a valid directory' % dir - - for root, _, fnames in sorted(os.walk(dir)): - for fname in fnames: - path = os.path.join(root, fname) - images.append(path) - return images[:min(max_dataset_size, len(images))] - - -def default_loader(path): - return Image.open(path).convert('RGB') - - -class ImageFolder(Dataset): - def __init__(self, root, transform=None, return_paths=True, - loader=default_loader): - imgs = make_dataset(root + '/testA') - if len(imgs) == 0: - raise (RuntimeError("Found 0 images in: " + root + "\n" + - "Supported image extensions are: " + ",".join(IMG_EXTENSIONS))) - self.root = root - self.imgs = imgs - self.transform = transform - self.return_paths = return_paths - self.loader = loader - - def __getitem__(self, index): - path = self.imgs[index] - img = self.loader(path) - if self.transform is not None: - img = self.transform(img) - if self.return_paths: - return img, path - else: - return img - - def __len__(self): - return len(self.imgs) - - -def deal_tensor(datas, outputs): - res_img = postprocess(datas) - res_gimg = postprocess(outputs) - - -def main(): - paser = parse_args(True, True) - opt = paser.initialize() - htmlres = '' - - pathroot = './result/' - images_name = 'img' - if (os.path.exists(pathroot + images_name) == False): - os.makedirs(pathroot + images_name) - f = open(pathroot + 'index.html', 'w') - lnetworks = load_networks(opt) - bachsize = opt.batch_size - loc_cpu = 'cpu' - loc = 'npu:1' - transform = preprocess((256, 256)) - model_Ga, _ = lnetworks.get_networks(opt.model_ga_path, opt.model_gb_path) - model_Ga.eval() - datasets = ImageFolder(opt.dataroot, transform) - dataloader = torch.utils.data.DataLoader(datasets, batch_size=bachsize, shuffle=True, num_workers=4) - - count = 0 - for i, (x, x_path) in enumerate(dataloader): - count += 1 - if (count > 10): - break - temp = str(x_path).split('/') - img_name = temp[4].split(',')[0].split('\'')[0] - src_real = temp[3] - src_g = temp[3] + 'G' - if (os.path.exists(pathroot + images_name + '/' + src_real) == False): - os.makedirs(pathroot + images_name + '/' + src_real) - if (os.path.exists(pathroot + images_name + '/' + src_g) == False): - os.makedirs(pathroot + images_name + '/' + src_g) - x1 = postprocess(x) - realsrc = images_name + '/' + src_real + '/' + img_name - fakesrc = images_name + '/' + src_g + '/' + img_name - y = model_Ga(x.to(loc)) - y = postprocess(y.to(loc_cpu)) - x1.save(pathroot + realsrc) - y.save(pathroot + fakesrc) - htmlres += ''' -
-
-

%s

- -
-
-

%s

- -
-
- ''' % (img_name.split('.')[0], realsrc, img_name.split('.')[0] + '_fake', fakesrc) - - htmlshow = """ - - - %s - - """ % (htmlres) - f.write(htmlshow) - f.close() - - -if __name__ == '__main__': - main() +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import os +import torchvision.transforms as transforms +from PIL import Image +import torch.onnx +from torch.utils.data import Dataset +from torchvision.datasets.folder import IMG_EXTENSIONS +from parse import parse_args +from CycleGAN_NetLoad import load_networks + + +def make_power(img, base): + ow, oh = img.size + h = int(round(oh / base) * base) + w = int(round(ow / base) * base) + if h == oh and w == ow: + return img + + +def preprocess(image_shape): + process = transforms.Compose([ + transforms.Lambda(lambda img: make_power(img, base=4)), + transforms.Resize(image_shape), + transforms.ToTensor(), + transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))]) + return process + + +def postprocess(img_tensor): + inv_normalize = transforms.Normalize( + mean=(-1, -1, -1), + std=(2.0, 2.0, 2.0)) + to_PIL_image = transforms.ToPILImage() + return to_PIL_image(inv_normalize(img_tensor[0]).clamp(0, 1)) + + +def make_dataset(dir, max_dataset_size=float("inf")): + images = [] + assert os.path.isdir(dir), '%s is not a valid directory' % dir + + for root, _, fnames in sorted(os.walk(dir)): + for fname in fnames: + path = os.path.join(root, fname) + images.append(path) + return images[:min(max_dataset_size, len(images))] + + +def default_loader(path): + return Image.open(path).convert('RGB') + + +class ImageFolder(Dataset): + def __init__(self, root, transform=None, return_paths=True, + loader=default_loader): + imgs = make_dataset(root + '/testA') + if len(imgs) == 0: + raise (RuntimeError("Found 0 images in: " + root + "\n" + + "Supported image extensions are: " + ",".join(IMG_EXTENSIONS))) + self.root = root + self.imgs = imgs + self.transform = transform + self.return_paths = return_paths + self.loader = loader + + def __getitem__(self, index): + path = self.imgs[index] + img = self.loader(path) + if self.transform is not None: + img = self.transform(img) + if self.return_paths: + return img, path + else: + return img + + def __len__(self): + return len(self.imgs) + + +def deal_tensor(datas, outputs): + res_img = postprocess(datas) + res_gimg = postprocess(outputs) + + +def main(): + paser = parse_args(True, True) + opt = paser.initialize() + htmlres = '' + + pathroot = './result/' + images_name = 'img' + if (os.path.exists(pathroot + images_name) == False): + os.makedirs(pathroot + images_name) + f = open(pathroot + 'index.html', 'w') + lnetworks = load_networks(opt) + bachsize = opt.batch_size + loc_cpu = 'cpu' + loc = 'npu:1' + transform = preprocess((256, 256)) + model_Ga, _ = lnetworks.get_networks(opt.model_ga_path, opt.model_gb_path) + model_Ga.eval() + datasets = ImageFolder(opt.dataroot, transform) + dataloader = torch.utils.data.DataLoader(datasets, batch_size=bachsize, shuffle=True, num_workers=4) + + count = 0 + for i, (x, x_path) in enumerate(dataloader): + count += 1 + if (count > 10): + break + temp = str(x_path).split('/') + img_name = temp[4].split(',')[0].split('\'')[0] + src_real = temp[3] + src_g = temp[3] + 'G' + if (os.path.exists(pathroot + images_name + '/' + src_real) == False): + os.makedirs(pathroot + images_name + '/' + src_real) + if (os.path.exists(pathroot + images_name + '/' + src_g) == False): + os.makedirs(pathroot + images_name + '/' + src_g) + x1 = postprocess(x) + realsrc = images_name + '/' + src_real + '/' + img_name + fakesrc = images_name + '/' + src_g + '/' + img_name + y = model_Ga(x.to(loc)) + y = postprocess(y.to(loc_cpu)) + x1.save(pathroot + realsrc) + y.save(pathroot + fakesrc) + htmlres += ''' +
+
+

%s

+ +
+
+

%s

+ +
+
+ ''' % (img_name.split('.')[0], realsrc, img_name.split('.')[0] + '_fake', fakesrc) + + htmlshow = """ + + + %s + + """ % (htmlres) + f.write(htmlshow) + f.close() + + +if __name__ == '__main__': + main() diff --git a/PyTorch/contrib/cv/others/CycleGAN/models/cycle_gan_model_adapt.py b/PyTorch/contrib/cv/others/CycleGAN/models/cycle_gan_model_adapt.py index 56a9fe915730b1dcaf702ecfa76dfdcaacdb0768..a5c1e39cae4bad192af8de9a3fbc3597a1ab0c09 100644 --- a/PyTorch/contrib/cv/others/CycleGAN/models/cycle_gan_model_adapt.py +++ b/PyTorch/contrib/cv/others/CycleGAN/models/cycle_gan_model_adapt.py @@ -1,421 +1,421 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import os -import sys -from collections import OrderedDict -import torch -import itertools -from util.image_pool import ImagePool -from . import networks_adapt as networks -from torch.nn.parallel import DistributedDataParallel as DDP -# from .npu_fused_adam import NpuFusedAdam as adam -from torch.optim import Adam as adam - -if sys.version_info < (3, 0): - raise RuntimeError("Apex currently only supports Python 3. Aborting.") -try: - import apex - from apex import amp -except ImportError: - amp = None - - -class CycleGANModel(): - """ - This class implements the CycleGAN model, for learning image-to-image translation without paired data. - - The model training requires '--dataset_mode unaligned' dataset. - By default, it uses a '--netG resnet_9blocks' ResNet generator, - a '--netD basic' discriminator (PatchGAN introduced by pix2pix), - and a least-square GANs objective ('--gan_mode lsgan'). - - CycleGAN paper: https://arxiv.org/pdf/1703.10593.pdf - """ - - @staticmethod - def modify_commandline_options(parser, is_train=True): - """Add new dataset-specific options, and rewrite default values for existing options. - - Parameters: - parser -- original option parser - is_train (bool) -- whether training phase or test phase. You can use this flag to add training-specific or test-specific options. - - Returns: - the modified parser. - - For CycleGAN, in addition to GAN losses, we introduce lambda_A, lambda_B, and lambda_identity for the following losses. - A (source domain), B (target domain). - Generators: G_A: A -> B; G_B: B -> A. - Discriminators: D_A: G_A(A) vs. B; D_B: G_B(B) vs. A. - Forward cycle loss: lambda_A * ||G_B(G_A(A)) - A|| (Eqn. (2) in the paper) - Backward cycle loss: lambda_B * ||G_A(G_B(B)) - B|| (Eqn. (2) in the paper) - Identity loss (optional): lambda_identity * (||G_A(B) - B|| * lambda_B + ||G_B(A) - A|| * lambda_A) (Sec 5.2 "Photo generation from paintings" in the paper) - Dropout is not used in the original CycleGAN paper. - """ - parser.set_defaults(no_dropout=True) # default CycleGAN did not use dropout - if is_train: - parser.add_argument('--lambda_A', type=float, default=10.0, help='weight for cycle loss (A -> B -> A)') - parser.add_argument('--lambda_B', type=float, default=10.0, help='weight for cycle loss (B -> A -> B)') - parser.add_argument('--lambda_identity', type=float, default=0.5, - help='use identity mapping. Setting lambda_identity other than 0 has an effect of' - ' scaling the weight of the identity mapping loss. For example, if the weight of ' - 'the identity loss should be 10 times smaller than the weight of the reconstruction' - ' loss, please set lambda_identity = 0.1') - - return parser - - def __init__(self, opt): - """Initialize the CycleGAN class. - - Parameters: - opt (Option class)-- stores all the experiment flags; needs to be a subclass of BaseOptions - """ - # specify the training losses you want to print out. The training/test scripts will call - self.opt = opt - self.isTrain = opt.isTrain - self.optimizers = [] - if (opt.npu < 1): - self.device = torch.device('cuda:{}'.format(self.opt.gpu)) # get device name: CPU or GPU - # self.device = torch.device('cuda:{}'.format(self.gpu_ids[0])) # get device name: CPU or GPU - else: - # self.device = torch.device('npu:{}'.format(self.gpu_ids)) if self.gpu_ids else torch.device( 'cpu') # get device name: CPU or GPU - self.device = torch.device('npu:{}'.format(self.opt.gpu)) # get device name: CPU or GPU - self.save_dir = os.path.join(opt.checkpoints_dir, opt.name) # save all the checkpoints to save_dir - self.loss_names = ['D_A', 'G_A', 'cycle_A', 'idt_A', 'D_B', 'G_B', 'cycle_B', 'idt_B'] - # specify the images you want to save/display. The training/test scripts will call - - visual_names_A = ['real_A', 'fake_B', 'rec_A'] - visual_names_B = ['real_B', 'fake_A', 'rec_B'] - if self.isTrain and self.opt.lambda_identity > 0.0: # if identity loss is used, we also visualize idt_B=G_A(B) ad idt_A=G_A(B) - visual_names_A.append('idt_B') - visual_names_B.append('idt_A') - - self.visual_names = visual_names_A + visual_names_B # combine visualizations for A and B - # specify the models you want to save to the disk. The training/test scripts - # will call and . - if self.isTrain: - self.model_names = ['G_A', 'G_B', 'D_A', 'D_B'] - else: # during test time, only load Gs - self.model_names = ['G_A', 'G_B'] - - # define networks (both Generators and discriminators) - # The naming is different from those used in the paper. - # Code (vs. paper): G_A (G), G_B (F), D_A (D_Y), D_B (D_X) - self.netG_A = networks.define_G(opt.input_nc, opt.output_nc, opt.ngf, opt.netG, opt.norm, - not opt.no_dropout, opt.init_type, opt.init_gain, self.opt.gpu) - self.netG_B = networks.define_G(opt.output_nc, opt.input_nc, opt.ngf, opt.netG, opt.norm, - not opt.no_dropout, opt.init_type, opt.init_gain, self.opt.gpu) - if self.isTrain: # define discriminators - self.netD_A = networks.define_D(opt.output_nc, opt.ndf, opt.netD, - opt.n_layers_D, opt.norm, opt.init_type, opt.init_gain, self.opt.gpu) - self.netD_B = networks.define_D(opt.input_nc, opt.ndf, opt.netD, - opt.n_layers_D, opt.norm, opt.init_type, opt.init_gain, self.opt.gpu) - - if self.isTrain: - if opt.lambda_identity > 0.0: # only works when input and output images have the same number of channels - assert (opt.input_nc == opt.output_nc) - self.fake_A_pool = ImagePool(opt.pool_size) # create image buffer to store previously generated images - self.fake_B_pool = ImagePool(opt.pool_size) # create image buffer to store previously generated images - # define loss functions - self.criterionGAN = networks.GANLoss(opt.gan_mode).to(self.device) # define GAN loss. - self.criterionCycle = torch.nn.L1Loss() - self.criterionIdt = torch.nn.L1Loss() - # initialize optimizers; schedulers will be automatically created by function . - self.optimizer_G = adam(itertools.chain(self.netG_A.parameters(), self.netG_B.parameters()), - lr=opt.lr, betas=(opt.beta1, 0.999)) - self.optimizer_D = adam(itertools.chain(self.netD_A.parameters(), self.netD_B.parameters()), - lr=opt.lr, betas=(opt.beta1, 0.999)) - self.optimizers.append(self.optimizer_G) - self.optimizers.append(self.optimizer_D) - self.lr_scheduler_G = networks.get_scheduler(self.optimizer_G, self.opt) - self.lr_scheduler_D = networks.get_scheduler(self.optimizer_D, self.opt) - # self.scaler = GradScaler() - amp.register_float_function(torch, 'sigmoid') - amp.register_float_function(torch, 'softmax') - amp.register_float_function(torch, 'tanh') - if (self.opt.isapex): - [self.netG_A, self.netG_B, self.netD_A, self.netD_B], [self.optimizer_G, self.optimizer_D] = \ - amp.initialize([self.netG_A, self.netG_B, self.netD_A, self.netD_B], - [self.optimizer_G, self.optimizer_D], opt_level=self.opt.apex_type, - loss_scale=self.opt.loss_scale) - if (self.opt.distributed >= 1): - temp = bool(1 - opt.npu) - self.netG_A = DDP(self.netG_A, [self.opt.gpu], broadcast_buffers=temp) - self.netG_B = DDP(self.netG_B, [self.opt.gpu], broadcast_buffers=temp) - self.netD_A = DDP(self.netD_A, [self.opt.gpu], broadcast_buffers=temp) - self.netD_B = DDP(self.netD_B, [self.opt.gpu], broadcast_buffers=temp) - - def setup(self, opt): - """Load and print networks; create schedulers - - Parameters: - opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions - """ - if self.isTrain: - self.schedulers = [networks.get_scheduler(optimizer, opt) for optimizer in self.optimizers] - if not self.isTrain or opt.continue_train: - load_suffix = 'iter_%d' % opt.load_iter if opt.load_iter > 0 else opt.epoch - self.load_networks(load_suffix) - self.print_networks(opt.verbose) - - def update_learning_rate(self): - old_lr = self.optimizers[0].param_groups[0]['lr'] - for scheduler in self.schedulers: - if self.opt.lr_policy == 'plateau': - scheduler.step(self.metric) - else: - scheduler.step() - self.lr_scheduler_G.step() - self.lr_scheduler_D.step() - - def set_input(self, input): - """Unpack input data from the dataloader and perform necessary pre-processing steps. - - Parameters: - input (dict): include the data itself and its metadata information. - - The option 'direction' can be used to swap domain A and domain B. - """ - AtoB = self.opt.direction == 'AtoB' - - self.real_A = input['A' if AtoB else 'B'].to(self.device) - self.real_B = input['B' if AtoB else 'A'].to(self.device) - self.image_paths = input['A_paths' if AtoB else 'B_paths'] - - def forward(self): - """Run forward pass; called by both functions and .""" - self.fake_B = self.netG_A(self.real_A) # G_A(A) - self.rec_A = self.netG_B(self.fake_B) # G_B(G_A(A)) - self.fake_A = self.netG_B(self.real_B) # G_B(B) - self.rec_B = self.netG_A(self.fake_A) # G_A(G_B(B)) - - def backward_D_basic(self, netD, real, fake): - """Calculate GAN loss for the discriminator - - Parameters: - netD (network) -- the discriminator D - real (tensor array) -- real images - fake (tensor array) -- images generated by a generator - - Return the discriminator loss. - We also call loss_D.backward() to calculate the gradients. - """ - # Real - pred_real = netD(real) - loss_D_real = self.criterionGAN(pred_real, True) - # Fake - pred_fake = netD(fake.detach()) - loss_D_fake = self.criterionGAN(pred_fake, False) - # Combined loss and calculate gradients - loss_D = (loss_D_real + loss_D_fake) * 0.5 - if (self.opt.isapex): - with amp.scale_loss(loss_D, self.optimizer_D) as scaled_lossd: - scaled_lossd.backward() - else: - loss_D.backward() - return loss_D - - def backward_D_A(self): - """Calculate GAN loss for discriminator D_A""" - fake_B = self.fake_B_pool.query(self.fake_B) - self.loss_D_A = self.backward_D_basic(self.netD_A, self.real_B, fake_B) - - def backward_D_B(self): - """Calculate GAN loss for discriminator D_B""" - fake_A = self.fake_A_pool.query(self.fake_A) - self.loss_D_B = self.backward_D_basic(self.netD_B, self.real_A, fake_A) - - def backward_G(self): - """Calculate the loss for generators G_A and G_B""" - lambda_idt = self.opt.lambda_identity - lambda_A = self.opt.lambda_A - lambda_B = self.opt.lambda_B - # Identity loss - if lambda_idt > 0: - # G_A should be identity if real_B is fed: ||G_A(B) - B|| - self.idt_A = self.netG_A(self.real_B) - self.loss_idt_A = self.criterionIdt(self.idt_A, self.real_B) * lambda_B * lambda_idt - # G_B should be identity if real_A is fed: ||G_B(A) - A|| - self.idt_B = self.netG_B(self.real_A) - self.loss_idt_B = self.criterionIdt(self.idt_B, self.real_A) * lambda_A * lambda_idt - else: - self.loss_idt_A = 0 - self.loss_idt_B = 0 - - # GAN loss D_A(G_A(A)) - self.loss_G_A = self.criterionGAN(self.netD_A(self.fake_B), True) - # GAN loss D_B(G_B(B)) - self.loss_G_B = self.criterionGAN(self.netD_B(self.fake_A), True) - # Forward cycle loss || G_B(G_A(A)) - A|| - self.loss_cycle_A = self.criterionCycle(self.rec_A, self.real_A) * lambda_A - # Backward cycle loss || G_A(G_B(B)) - B|| - self.loss_cycle_B = self.criterionCycle(self.rec_B, self.real_B) * lambda_B - # combined loss and calculate gradients - self.loss_G = self.loss_G_A + self.loss_G_B + self.loss_cycle_A + self.loss_cycle_B + self.loss_idt_A + self.loss_idt_B - if (self.opt.isapex == True): - with amp.scale_loss(self.loss_G, self.optimizer_G) as scaled_lossg: - scaled_lossg.backward() - else: - self.loss_G.backward() - - def optimize_parameters(self): - """Calculate losses, gradients, and update network weights; called in every training iteration""" - # forwar - self.forward() # compute fake images and reconstruction images. - # G_A and G_B - self.set_requires_grad([self.netD_A, self.netD_B], False) # Ds require no gradients when optimizing Gs - self.optimizer_G.zero_grad() # set G_A and G_B's gradients to zero - self.backward_G() # calculate gradients for G_A and G_B - self.optimizer_G.step() # update G_A and G_B's weights - # D_A and D_B - self.set_requires_grad([self.netD_A, self.netD_B], True) - self.optimizer_D.zero_grad() # set D_A and D_B's gradients to zero - self.backward_D_A() # calculate gradients for D_A - self.backward_D_B() # calculate graidents for D_B - self.optimizer_D.step() # update D_A and D_B's weights - - def get_current_visuals(self): - """Return visualization images. train.py will display these images with visdom, and save the images to a HTML""" - visual_ret = OrderedDict() - for name in self.visual_names: - if isinstance(name, str): - visual_ret[name] = getattr(self, name) - return visual_ret - - def get_current_losses(self): - """Return traning losses / errors. train.py will print out these errors on console, and save them to a file""" - errors_ret = OrderedDict() - for name in self.loss_names: - if isinstance(name, str): - errors_ret[name] = float( - getattr(self, 'loss_' + name)) # float(...) works for both scalar tensor and float number - return errors_ret - - def save_networks(self, epoch): - """Save all the networks to the disk. - - Parameters: - epoch (int) -- current epoch; used in the file name '%s_net_%s.pth' % (epoch, name) - """ - for name in self.model_names: - if isinstance(name, str): - save_filename = '%s_net_%s.pth' % (epoch, name) - save_path = os.path.join(self.save_dir, save_filename) - save_path1 = os.path.join(self.save_dir, 'a' + save_filename) - net = getattr(self, 'net' + name) - - if self.opt.distributed >= 1 and torch.cuda.is_available(): - torch.save(net.cpu().module.state_dict(), save_path) - if (self.opt.npu >= 1): - net.npu(self.opt.gpu) - else: - net.cuda(self.opt.gpu) - else: - torch.save(net.cpu().state_dict(), save_path) - if (self.opt.npu >= 1): - net.npu(self.opt.gpu) - else: - net.cuda(self.opt.gpu) - - def __patch_instance_norm_state_dict(self, state_dict, module, keys, i=0): - """Fix InstanceNorm checkpoints incompatibility (prior to 0.4)""" - key = keys[i] - if i + 1 == len(keys): # at the end, pointing to a parameter/buffer - if module.__class__.__name__.startswith('InstanceNorm') and \ - (key == 'running_mean' or key == 'running_var'): - if getattr(module, key) is None: - state_dict.pop('.'.join(keys)) - if module.__class__.__name__.startswith('InstanceNorm') and \ - (key == 'num_batches_tracked'): - state_dict.pop('.'.join(keys)) - else: - self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) - - def load_networks(self, epoch): - """Load all the networks from the disk. - - Parameters: - epoch (int) -- current epoch; used in the file name '%s_net_%s.pth' % (epoch, name) - """ - for name in self.model_names: - if isinstance(name, str): - load_filename = '%s_net_%s.pth' % (epoch, name) - load_path = os.path.join(self.save_dir, load_filename) - net = getattr(self, 'net' + name) - if isinstance(net, torch.nn.DataParallel): - net = net.module - print('loading the model from %s' % load_path) - # if you are using PyTorch newer than 0.4 (e.g., built from - # GitHub source), you can remove str() on self.device - state_dict = torch.load(load_path, map_location=str(self.device)) - if hasattr(state_dict, '_metadata'): - del state_dict._metadata - - # patch InstanceNorm checkpoints prior to 0.4 - for key in list(state_dict.keys()): # need to copy keys here because we mutate in loop - self.__patch_instance_norm_state_dict(state_dict, net, key.split('.')) - net.load_state_dict(state_dict) - - def print_networks(self, verbose): - """Print the total number of parameters in the network and (if verbose) network architecture - - Parameters: - verbose (bool) -- if verbose: print the network architecture - """ - print('---------- Networks initialized -------------') - for name in self.model_names: - if isinstance(name, str): - net = getattr(self, 'net' + name) - num_params = 0 - for param in net.parameters(): - num_params += param.numel() - if verbose: - print(net) - print('[Network %s] Total number of parameters : %.3f M' % (name, num_params / 1e6)) - print('-----------------------------------------------') - - def set_requires_grad(self, nets, requires_grad=False): - """Set requies_grad=Fasle for all the networks to avoid unnecessary computations - Parameters: - nets (network list) -- a list of networks - requires_grad (bool) -- whether the networks require gradients or not - """ - if not isinstance(nets, list): - nets = [nets] - for net in nets: - if net is not None: - for param in net.parameters(): - param.requires_grad = requires_grad - - def compute_visuals(self): - """Calculate additional output images for visdom and HTML visualization""" - pass +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import os +import sys +from collections import OrderedDict +import torch +import itertools +from util.image_pool import ImagePool +from . import networks_adapt as networks +from torch.nn.parallel import DistributedDataParallel as DDP +# from .npu_fused_adam import NpuFusedAdam as adam +from torch.optim import Adam as adam + +if sys.version_info < (3, 0): + raise RuntimeError("Apex currently only supports Python 3. Aborting.") +try: + import apex + from apex import amp +except ImportError: + amp = None + + +class CycleGANModel(): + """ + This class implements the CycleGAN model, for learning image-to-image translation without paired data. + + The model training requires '--dataset_mode unaligned' dataset. + By default, it uses a '--netG resnet_9blocks' ResNet generator, + a '--netD basic' discriminator (PatchGAN introduced by pix2pix), + and a least-square GANs objective ('--gan_mode lsgan'). + + CycleGAN paper: https://arxiv.org/pdf/1703.10593.pdf + """ + + @staticmethod + def modify_commandline_options(parser, is_train=True): + """Add new dataset-specific options, and rewrite default values for existing options. + + Parameters: + parser -- original option parser + is_train (bool) -- whether training phase or test phase. You can use this flag to add training-specific or test-specific options. + + Returns: + the modified parser. + + For CycleGAN, in addition to GAN losses, we introduce lambda_A, lambda_B, and lambda_identity for the following losses. + A (source domain), B (target domain). + Generators: G_A: A -> B; G_B: B -> A. + Discriminators: D_A: G_A(A) vs. B; D_B: G_B(B) vs. A. + Forward cycle loss: lambda_A * ||G_B(G_A(A)) - A|| (Eqn. (2) in the paper) + Backward cycle loss: lambda_B * ||G_A(G_B(B)) - B|| (Eqn. (2) in the paper) + Identity loss (optional): lambda_identity * (||G_A(B) - B|| * lambda_B + ||G_B(A) - A|| * lambda_A) (Sec 5.2 "Photo generation from paintings" in the paper) + Dropout is not used in the original CycleGAN paper. + """ + parser.set_defaults(no_dropout=True) # default CycleGAN did not use dropout + if is_train: + parser.add_argument('--lambda_A', type=float, default=10.0, help='weight for cycle loss (A -> B -> A)') + parser.add_argument('--lambda_B', type=float, default=10.0, help='weight for cycle loss (B -> A -> B)') + parser.add_argument('--lambda_identity', type=float, default=0.5, + help='use identity mapping. Setting lambda_identity other than 0 has an effect of' + ' scaling the weight of the identity mapping loss. For example, if the weight of ' + 'the identity loss should be 10 times smaller than the weight of the reconstruction' + ' loss, please set lambda_identity = 0.1') + + return parser + + def __init__(self, opt): + """Initialize the CycleGAN class. + + Parameters: + opt (Option class)-- stores all the experiment flags; needs to be a subclass of BaseOptions + """ + # specify the training losses you want to print out. The training/test scripts will call + self.opt = opt + self.isTrain = opt.isTrain + self.optimizers = [] + if (opt.npu < 1): + self.device = torch.device('cuda:{}'.format(self.opt.gpu)) # get device name: CPU or GPU + # self.device = torch.device('cuda:{}'.format(self.gpu_ids[0])) # get device name: CPU or GPU + else: + # self.device = torch.device('npu:{}'.format(self.gpu_ids)) if self.gpu_ids else torch.device( 'cpu') # get device name: CPU or GPU + self.device = torch.device('npu:{}'.format(self.opt.gpu)) # get device name: CPU or GPU + self.save_dir = os.path.join(opt.checkpoints_dir, opt.name) # save all the checkpoints to save_dir + self.loss_names = ['D_A', 'G_A', 'cycle_A', 'idt_A', 'D_B', 'G_B', 'cycle_B', 'idt_B'] + # specify the images you want to save/display. The training/test scripts will call + + visual_names_A = ['real_A', 'fake_B', 'rec_A'] + visual_names_B = ['real_B', 'fake_A', 'rec_B'] + if self.isTrain and self.opt.lambda_identity > 0.0: # if identity loss is used, we also visualize idt_B=G_A(B) ad idt_A=G_A(B) + visual_names_A.append('idt_B') + visual_names_B.append('idt_A') + + self.visual_names = visual_names_A + visual_names_B # combine visualizations for A and B + # specify the models you want to save to the disk. The training/test scripts + # will call and . + if self.isTrain: + self.model_names = ['G_A', 'G_B', 'D_A', 'D_B'] + else: # during test time, only load Gs + self.model_names = ['G_A', 'G_B'] + + # define networks (both Generators and discriminators) + # The naming is different from those used in the paper. + # Code (vs. paper): G_A (G), G_B (F), D_A (D_Y), D_B (D_X) + self.netG_A = networks.define_G(opt.input_nc, opt.output_nc, opt.ngf, opt.netG, opt.norm, + not opt.no_dropout, opt.init_type, opt.init_gain, self.opt.gpu) + self.netG_B = networks.define_G(opt.output_nc, opt.input_nc, opt.ngf, opt.netG, opt.norm, + not opt.no_dropout, opt.init_type, opt.init_gain, self.opt.gpu) + if self.isTrain: # define discriminators + self.netD_A = networks.define_D(opt.output_nc, opt.ndf, opt.netD, + opt.n_layers_D, opt.norm, opt.init_type, opt.init_gain, self.opt.gpu) + self.netD_B = networks.define_D(opt.input_nc, opt.ndf, opt.netD, + opt.n_layers_D, opt.norm, opt.init_type, opt.init_gain, self.opt.gpu) + + if self.isTrain: + if opt.lambda_identity > 0.0: # only works when input and output images have the same number of channels + assert (opt.input_nc == opt.output_nc) + self.fake_A_pool = ImagePool(opt.pool_size) # create image buffer to store previously generated images + self.fake_B_pool = ImagePool(opt.pool_size) # create image buffer to store previously generated images + # define loss functions + self.criterionGAN = networks.GANLoss(opt.gan_mode).to(self.device) # define GAN loss. + self.criterionCycle = torch.nn.L1Loss() + self.criterionIdt = torch.nn.L1Loss() + # initialize optimizers; schedulers will be automatically created by function . + self.optimizer_G = adam(itertools.chain(self.netG_A.parameters(), self.netG_B.parameters()), + lr=opt.lr, betas=(opt.beta1, 0.999)) + self.optimizer_D = adam(itertools.chain(self.netD_A.parameters(), self.netD_B.parameters()), + lr=opt.lr, betas=(opt.beta1, 0.999)) + self.optimizers.append(self.optimizer_G) + self.optimizers.append(self.optimizer_D) + self.lr_scheduler_G = networks.get_scheduler(self.optimizer_G, self.opt) + self.lr_scheduler_D = networks.get_scheduler(self.optimizer_D, self.opt) + # self.scaler = GradScaler() + amp.register_float_function(torch, 'sigmoid') + amp.register_float_function(torch, 'softmax') + amp.register_float_function(torch, 'tanh') + if (self.opt.isapex): + [self.netG_A, self.netG_B, self.netD_A, self.netD_B], [self.optimizer_G, self.optimizer_D] = \ + amp.initialize([self.netG_A, self.netG_B, self.netD_A, self.netD_B], + [self.optimizer_G, self.optimizer_D], opt_level=self.opt.apex_type, + loss_scale=self.opt.loss_scale) + if (self.opt.distributed >= 1): + temp = bool(1 - opt.npu) + self.netG_A = DDP(self.netG_A, [self.opt.gpu], broadcast_buffers=temp) + self.netG_B = DDP(self.netG_B, [self.opt.gpu], broadcast_buffers=temp) + self.netD_A = DDP(self.netD_A, [self.opt.gpu], broadcast_buffers=temp) + self.netD_B = DDP(self.netD_B, [self.opt.gpu], broadcast_buffers=temp) + + def setup(self, opt): + """Load and print networks; create schedulers + + Parameters: + opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions + """ + if self.isTrain: + self.schedulers = [networks.get_scheduler(optimizer, opt) for optimizer in self.optimizers] + if not self.isTrain or opt.continue_train: + load_suffix = 'iter_%d' % opt.load_iter if opt.load_iter > 0 else opt.epoch + self.load_networks(load_suffix) + self.print_networks(opt.verbose) + + def update_learning_rate(self): + old_lr = self.optimizers[0].param_groups[0]['lr'] + for scheduler in self.schedulers: + if self.opt.lr_policy == 'plateau': + scheduler.step(self.metric) + else: + scheduler.step() + self.lr_scheduler_G.step() + self.lr_scheduler_D.step() + + def set_input(self, input): + """Unpack input data from the dataloader and perform necessary pre-processing steps. + + Parameters: + input (dict): include the data itself and its metadata information. + + The option 'direction' can be used to swap domain A and domain B. + """ + AtoB = self.opt.direction == 'AtoB' + + self.real_A = input['A' if AtoB else 'B'].to(self.device) + self.real_B = input['B' if AtoB else 'A'].to(self.device) + self.image_paths = input['A_paths' if AtoB else 'B_paths'] + + def forward(self): + """Run forward pass; called by both functions and .""" + self.fake_B = self.netG_A(self.real_A) # G_A(A) + self.rec_A = self.netG_B(self.fake_B) # G_B(G_A(A)) + self.fake_A = self.netG_B(self.real_B) # G_B(B) + self.rec_B = self.netG_A(self.fake_A) # G_A(G_B(B)) + + def backward_D_basic(self, netD, real, fake): + """Calculate GAN loss for the discriminator + + Parameters: + netD (network) -- the discriminator D + real (tensor array) -- real images + fake (tensor array) -- images generated by a generator + + Return the discriminator loss. + We also call loss_D.backward() to calculate the gradients. + """ + # Real + pred_real = netD(real) + loss_D_real = self.criterionGAN(pred_real, True) + # Fake + pred_fake = netD(fake.detach()) + loss_D_fake = self.criterionGAN(pred_fake, False) + # Combined loss and calculate gradients + loss_D = (loss_D_real + loss_D_fake) * 0.5 + if (self.opt.isapex): + with amp.scale_loss(loss_D, self.optimizer_D) as scaled_lossd: + scaled_lossd.backward() + else: + loss_D.backward() + return loss_D + + def backward_D_A(self): + """Calculate GAN loss for discriminator D_A""" + fake_B = self.fake_B_pool.query(self.fake_B) + self.loss_D_A = self.backward_D_basic(self.netD_A, self.real_B, fake_B) + + def backward_D_B(self): + """Calculate GAN loss for discriminator D_B""" + fake_A = self.fake_A_pool.query(self.fake_A) + self.loss_D_B = self.backward_D_basic(self.netD_B, self.real_A, fake_A) + + def backward_G(self): + """Calculate the loss for generators G_A and G_B""" + lambda_idt = self.opt.lambda_identity + lambda_A = self.opt.lambda_A + lambda_B = self.opt.lambda_B + # Identity loss + if lambda_idt > 0: + # G_A should be identity if real_B is fed: ||G_A(B) - B|| + self.idt_A = self.netG_A(self.real_B) + self.loss_idt_A = self.criterionIdt(self.idt_A, self.real_B) * lambda_B * lambda_idt + # G_B should be identity if real_A is fed: ||G_B(A) - A|| + self.idt_B = self.netG_B(self.real_A) + self.loss_idt_B = self.criterionIdt(self.idt_B, self.real_A) * lambda_A * lambda_idt + else: + self.loss_idt_A = 0 + self.loss_idt_B = 0 + + # GAN loss D_A(G_A(A)) + self.loss_G_A = self.criterionGAN(self.netD_A(self.fake_B), True) + # GAN loss D_B(G_B(B)) + self.loss_G_B = self.criterionGAN(self.netD_B(self.fake_A), True) + # Forward cycle loss || G_B(G_A(A)) - A|| + self.loss_cycle_A = self.criterionCycle(self.rec_A, self.real_A) * lambda_A + # Backward cycle loss || G_A(G_B(B)) - B|| + self.loss_cycle_B = self.criterionCycle(self.rec_B, self.real_B) * lambda_B + # combined loss and calculate gradients + self.loss_G = self.loss_G_A + self.loss_G_B + self.loss_cycle_A + self.loss_cycle_B + self.loss_idt_A + self.loss_idt_B + if (self.opt.isapex == True): + with amp.scale_loss(self.loss_G, self.optimizer_G) as scaled_lossg: + scaled_lossg.backward() + else: + self.loss_G.backward() + + def optimize_parameters(self): + """Calculate losses, gradients, and update network weights; called in every training iteration""" + # forwar + self.forward() # compute fake images and reconstruction images. + # G_A and G_B + self.set_requires_grad([self.netD_A, self.netD_B], False) # Ds require no gradients when optimizing Gs + self.optimizer_G.zero_grad() # set G_A and G_B's gradients to zero + self.backward_G() # calculate gradients for G_A and G_B + self.optimizer_G.step() # update G_A and G_B's weights + # D_A and D_B + self.set_requires_grad([self.netD_A, self.netD_B], True) + self.optimizer_D.zero_grad() # set D_A and D_B's gradients to zero + self.backward_D_A() # calculate gradients for D_A + self.backward_D_B() # calculate graidents for D_B + self.optimizer_D.step() # update D_A and D_B's weights + + def get_current_visuals(self): + """Return visualization images. train.py will display these images with visdom, and save the images to a HTML""" + visual_ret = OrderedDict() + for name in self.visual_names: + if isinstance(name, str): + visual_ret[name] = getattr(self, name) + return visual_ret + + def get_current_losses(self): + """Return traning losses / errors. train.py will print out these errors on console, and save them to a file""" + errors_ret = OrderedDict() + for name in self.loss_names: + if isinstance(name, str): + errors_ret[name] = float( + getattr(self, 'loss_' + name)) # float(...) works for both scalar tensor and float number + return errors_ret + + def save_networks(self, epoch): + """Save all the networks to the disk. + + Parameters: + epoch (int) -- current epoch; used in the file name '%s_net_%s.pth' % (epoch, name) + """ + for name in self.model_names: + if isinstance(name, str): + save_filename = '%s_net_%s.pth' % (epoch, name) + save_path = os.path.join(self.save_dir, save_filename) + save_path1 = os.path.join(self.save_dir, 'a' + save_filename) + net = getattr(self, 'net' + name) + + if self.opt.distributed >= 1 and torch.cuda.is_available(): + torch.save(net.cpu().module.state_dict(), save_path) + if (self.opt.npu >= 1): + net.npu(self.opt.gpu) + else: + net.cuda(self.opt.gpu) + else: + torch.save(net.cpu().state_dict(), save_path) + if (self.opt.npu >= 1): + net.npu(self.opt.gpu) + else: + net.cuda(self.opt.gpu) + + def __patch_instance_norm_state_dict(self, state_dict, module, keys, i=0): + """Fix InstanceNorm checkpoints incompatibility (prior to 0.4)""" + key = keys[i] + if i + 1 == len(keys): # at the end, pointing to a parameter/buffer + if module.__class__.__name__.startswith('InstanceNorm') and \ + (key == 'running_mean' or key == 'running_var'): + if getattr(module, key) is None: + state_dict.pop('.'.join(keys)) + if module.__class__.__name__.startswith('InstanceNorm') and \ + (key == 'num_batches_tracked'): + state_dict.pop('.'.join(keys)) + else: + self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) + + def load_networks(self, epoch): + """Load all the networks from the disk. + + Parameters: + epoch (int) -- current epoch; used in the file name '%s_net_%s.pth' % (epoch, name) + """ + for name in self.model_names: + if isinstance(name, str): + load_filename = '%s_net_%s.pth' % (epoch, name) + load_path = os.path.join(self.save_dir, load_filename) + net = getattr(self, 'net' + name) + if isinstance(net, torch.nn.DataParallel): + net = net.module + print('loading the model from %s' % load_path) + # if you are using PyTorch newer than 0.4 (e.g., built from + # GitHub source), you can remove str() on self.device + state_dict = torch.load(load_path, map_location=str(self.device)) + if hasattr(state_dict, '_metadata'): + del state_dict._metadata + + # patch InstanceNorm checkpoints prior to 0.4 + for key in list(state_dict.keys()): # need to copy keys here because we mutate in loop + self.__patch_instance_norm_state_dict(state_dict, net, key.split('.')) + net.load_state_dict(state_dict) + + def print_networks(self, verbose): + """Print the total number of parameters in the network and (if verbose) network architecture + + Parameters: + verbose (bool) -- if verbose: print the network architecture + """ + print('---------- Networks initialized -------------') + for name in self.model_names: + if isinstance(name, str): + net = getattr(self, 'net' + name) + num_params = 0 + for param in net.parameters(): + num_params += param.numel() + if verbose: + print(net) + print('[Network %s] Total number of parameters : %.3f M' % (name, num_params / 1e6)) + print('-----------------------------------------------') + + def set_requires_grad(self, nets, requires_grad=False): + """Set requies_grad=Fasle for all the networks to avoid unnecessary computations + Parameters: + nets (network list) -- a list of networks + requires_grad (bool) -- whether the networks require gradients or not + """ + if not isinstance(nets, list): + nets = [nets] + for net in nets: + if net is not None: + for param in net.parameters(): + param.requires_grad = requires_grad + + def compute_visuals(self): + """Calculate additional output images for visdom and HTML visualization""" + pass diff --git a/PyTorch/contrib/cv/others/CycleGAN/modelzoo_level.txt b/PyTorch/contrib/cv/others/CycleGAN/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/others/CycleGAN/modelzoo_level.txt +++ b/PyTorch/contrib/cv/others/CycleGAN/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/CycleGAN/parse.py b/PyTorch/contrib/cv/others/CycleGAN/parse.py index 64e6560084a0b19548d46c13b90079560c73e5dd..a58d344312f5af5e8bfe2f52826d19c5864e00e9 100644 --- a/PyTorch/contrib/cv/others/CycleGAN/parse.py +++ b/PyTorch/contrib/cv/others/CycleGAN/parse.py @@ -1,236 +1,236 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import argparse -import torch - - -class parse_args(): - def __init__(self, isTrain=True, isTest=False): - self.isTrain = isTrain - self.isTest = isTest - self.parser = argparse.ArgumentParser(description='Pytorch CycleGAN training') - - def initialize(self): - parser = self.parser - parser.add_argument('--model_ga_path', type=str, - default='./checkpoints_8pbs1/maps_cycle_gan/175_pu0_net_G_A.pth', - help='path for modelga') - parser.add_argument('--model_gb_path', type=str, - default='./checkpoints_8pbs1/maps_cycle_gan/175_pu0_net_G_B.pth', - help='path for modelga') - parser.add_argument('--prof', type=int, default=1, help='whether to get prof file') - parser.add_argument('--num_epoch', type=int, default=240, help='whether to get prof file1') - parser.add_argument('--line_scale', type=float, default=2, help='whether to get prof file1') - parser.add_argument('--num_epoch_start', type=int, default=0, help='whether to get prof file1') - parser.add_argument('--loadweight', default='latest', help='whether to get prof file1') - parser.add_argument('--prof_file', type=str, default='./output.prof', help='whether to get prof file') - parser.add_argument('--log_path', type=str, default='gpu1p.txt', help='whether to get prof file') - parser.add_argument('--multiprocessing_distributed', type=int, default=1, - help='Use multi-processing distributed training to launch,if it is eaqul to 1 or more than ,start to npu/gpu Multi-card training ') - parser.add_argument('--world_size', type=int, default=1, help='word__size') - parser.add_argument('--distributed', type=int, default=1, - help='whether to use distributed to fastern training,if it is eaqul to 1 or more than ,start to npu/gpu Multi-card training') - parser.add_argument('--rank', default=0, type=int, help='rank') - parser.add_argument('--gpu', default=None, type=int, help='GPU id to use.') - parser.add_argument('--npu', type=int, default=0, help='whether to use npu to fastern training') - parser.add_argument('--pu_ids', type=str, default='0,1', - help='gpu ids(npu ids): e.g. 0 0,1,2, 0,2. use -1 for CPU') - - parser.add_argument('--isapex', default=True, help='whether to use apex to fastern training') - parser.add_argument('--apex_type', type=str, default="O1", help='O0,O1,O2,O3') - parser.add_argument('--loss_scale', default=None, help='loss_scale:1,128,dynamic') - parser.add_argument('--dataroot', type=str, default='./datasets/maps', - help='path to images (should have subfolders trainA, trainB, valA, valB, etc)') - parser.add_argument('--name', type=str, default='maps_cycle_gan', - help='name of the experiment. It decides where to store samples and models') - - parser.add_argument('--checkpoints_dir', type=str, default='./re_checkpoints2p_bs1', - help='models are saved here') - # model parameters - parser.add_argument('--model', type=str, default='cycle_gan', - help='chooses which model to use. [cycle_gan| pix2pix | test | colorization]') - parser.add_argument('--input_nc', type=int, default=3, - help='# of input image channels: 3 for RGB and 1 for grayscale') - parser.add_argument('--output_nc', type=int, default=3, - help='# of output image channels: 3 for RGB and 1 for grayscale') - parser.add_argument('--ngf', type=int, default=64, help='# of gen filters in the last conv layer') - parser.add_argument('--ndf', type=int, default=64, help='# of discrim filters in the first conv layer') - parser.add_argument('--netD', type=str, default='basic', - help='specify discriminator architecture [basic | n_layers | pixel].' - ' The basic model is a 70x70 PatchGAN. n_layers allows you to ' - 'specify the layers in the discriminator') - parser.add_argument('--netG', type=str, default='resnet_9blocks', - help='specify generator architecture [resnet_9blocks | resnet_6blocks | ' - 'unet_256 | unet_128]') - parser.add_argument('--n_layers_D', type=int, default=3, help='only used if netD==n_layers') - parser.add_argument('--norm', type=str, default='instance', - help='instance normalization or batch normalization [instance | batch | none]') - parser.add_argument('--init_type', type=str, default='normal', - help='network initialization [normal | xavier | kaiming | orthogonal]') - parser.add_argument('--init_gain', type=float, default=0.02, - help='scaling factor for normal, xavier and orthogonal.') - parser.add_argument('--no_dropout', action='store_true', help='no dropout for the generator') - # dataset parameters - parser.add_argument('--dataset_mode', type=str, default='unaligned', - help='chooses how datasets are loaded. [unaligned | aligned | single | colorization]') - parser.add_argument('--direction', type=str, default='AtoB', help='AtoB or BtoA') - parser.add_argument('--serial_batches', action='store_true', - help='if true, takes images in order to make batches, otherwise takes them randomly') - parser.add_argument('--num_threads', default=8, type=int, help='# threads for loading data') - parser.add_argument('--batch_size', type=int, default=4, help='input batch size') - parser.add_argument('--load_size', type=int, default=286, help='scale images to this size') - parser.add_argument('--crop_size', type=int, default=256, help='then crop to this size') - parser.add_argument('--max_dataset_size', type=int, default=float("inf"), - help='Maximum number of samples allowed per dataset. If the dataset directory ' - 'contains more than max_dataset_size, only a subset is loaded.') - parser.add_argument('--preprocess', type=str, default='resize_and_crop', - help='scaling and cropping of images at load time [resize_and_crop | crop | ' - 'scale_width | scale_width_and_crop | none]') - parser.add_argument('--no_flip', action='store_true', - help='if specified, do not flip the images for data augmentation') - parser.add_argument('--display_winsize', type=int, default=256, - help='display window size for both visdom and HTML') - # additional parameters - parser.add_argument('--epoch', type=str, default='latest', - help='which epoch to load? set to latest to use latest cached model') - parser.add_argument('--load_iter', type=int, default='0', - help='which iteration to load? if load_iter > 0, the code will load models by iter_' - '[load_iter]; otherwise, the code will load models by [epoch]') - parser.add_argument('--verbose', action='store_true', help='if specified, print more debugging information') - parser.add_argument('--suffix', default='', type=str, - help='customized suffix: opt.name = opt.name + suffix: e.g., {model}_{netG}_size{load_size}') - parser.add_argument( - "--cache-dataset", - dest="cache_dataset", - help="Cache the datasets for quicker initialization. It also serializes the transforms", - action="store_true", - ) - parser.set_defaults(no_dropout=True) # default CycleGAN did not use dropout - if (self.isTrain): - # network saving and loading parameters - parser.add_argument('--display_freq', type=int, default=400, - help='frequency of showing training results on screen') - parser.add_argument('--display_ncols', type=int, default=4, - help='if positive, display all images in a single visdom web panel with ' - 'certain number of images per row.') - parser.add_argument('--display_id', type=int, default=-1, help='window id of the web display') - parser.add_argument('--display_server', type=str, default="http://localhost", - help='visdom server of the web display') - parser.add_argument('--display_env', type=str, default='main', - help='visdom display environment name (default is "main")') - parser.add_argument('--display_port', type=int, default=8097, help='visdom port of the web display') - parser.add_argument('--update_html_freq', type=int, default=1000, - help='frequency of saving training results to html') - parser.add_argument('--print_freq', type=int, default=100, - help='frequency of showing training results on console') - parser.add_argument('--no_html', action='store_true', - help='do not save intermediate training results to [' - 'opt.checkpoints_dir]/[opt.name]/web/') - # network saving and loading parameters - parser.add_argument('--save_latest_freq', type=int, default=5000, - help='frequency of saving the latest results') - parser.add_argument('--save_epoch_freq', type=int, default=5, - help='frequency of saving checkpoints at the end of epochs') - parser.add_argument('--save_by_iter', action='store_true', help='whether saves model by iteration') - parser.add_argument('--continue_train', action='store_true', - help='continue training: load the latest model') - parser.add_argument('--epoch_count', type=int, default=1, - help='the starting epoch count, we save the model ' - 'by , +, ...') - parser.add_argument('--phase', type=str, default='train', help='train, val, test, etc') - # training parameters - parser.add_argument('--n_epochs', type=int, default=100, - help='number of epochs with the initial learning rate') - parser.add_argument('--n_epochs_decay', type=int, default=100, - help='number of epochs to linearly decay learning rate to zero') - parser.add_argument('--beta1', type=float, default=0.5, help='momentum term of adam') - parser.add_argument('--lr', type=float, default=0.0002, help='initial learning rate for adam') - parser.add_argument('--gan_mode', type=str, default='lsgan', - help='the type of GAN objective. [vanilla| lsgan | wgangp]. vanilla GAN loss is' - ' the cross-entropy objective used in the original GAN paper.') - parser.add_argument('--pool_size', type=int, default=50, - help='the size of image buffer that stores previously generated images') - parser.add_argument('--lr_policy', type=str, default='linear', - help='learning rate policy. [linear | step | plateau | cosine]') - parser.add_argument('--lr_decay_iters', type=int, default=50, - help='multiply by a gamma every lr_decay_iters iterations') - parser.add_argument('--lambda_A', type=float, default=10.0, help='weight for cycle loss (A -> B -> A)') - parser.add_argument('--lambda_B', type=float, default=10.0, help='weight for cycle loss (B -> A -> B)') - parser.add_argument('--lambda_identity', type=float, default=0.5, - help='use identity mapping. Setting lambda_identity other than 0 has an effect of' - ' scaling the weight of the identity mapping loss. For example, if the weight of' - ' the identity loss should be 10 times smaller than the weight of the ' - 'reconstruction loss, please set lambda_identity = 0.1') - parser = parser.parse_args() - parser.process_device_map = self.device_id_to_process_device_map(parser.pu_ids) - return parser - - def device_id_to_process_device_map(self, device_list): - devices = device_list.split(",") - devices = [int(x) for x in devices] - devices.sort() - - process_device_map = dict() - for process_id, device_id in enumerate(devices): - process_device_map[process_id] = device_id - return process_device_map - - def change_parser(self, isTrain=True, isTest=False): - self.isTest = isTest - self.isTrain = isTrain - self.parser = None - return self.initialize() - - def printParser(self): - pasers = self.parser.parse_args() - message = '' - message += '----------------- Options ---------------\n' - for k, v in sorted(vars(pasers).items()): - comment = '' - default = self.parser.get_default(k) - # if v != default: - # comment = '\t[default: %s]' % str(default) - message += '{:>25}: {:<30}{}\n'.format(str(k), str(v), comment) - message += '----------------- End -------------------' - print(message) - - def init_distributed_mode(self, ngpus_per_node, gpu): - opt = self.parser.parse_args() - if opt.multiprocessing_distributed >= 1: - # For multiprocessing distributed training, rank needs to be the - # global rank among all the processes - opt.rank = opt.rank * ngpus_per_node + gpu - if (opt.npu < 1): - torch.distributed.init_process_group(backend='nccl', init_method='env://', world_size=opt.world_size, - rank=opt.rank) - elif (opt.npu >= 1): - torch.distributed.init_process_group(backend='hccl', world_size=opt.world_size, rank=opt.rank) +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import argparse +import torch + + +class parse_args(): + def __init__(self, isTrain=True, isTest=False): + self.isTrain = isTrain + self.isTest = isTest + self.parser = argparse.ArgumentParser(description='Pytorch CycleGAN training') + + def initialize(self): + parser = self.parser + parser.add_argument('--model_ga_path', type=str, + default='./checkpoints_8pbs1/maps_cycle_gan/175_pu0_net_G_A.pth', + help='path for modelga') + parser.add_argument('--model_gb_path', type=str, + default='./checkpoints_8pbs1/maps_cycle_gan/175_pu0_net_G_B.pth', + help='path for modelga') + parser.add_argument('--prof', type=int, default=1, help='whether to get prof file') + parser.add_argument('--num_epoch', type=int, default=240, help='whether to get prof file1') + parser.add_argument('--line_scale', type=float, default=2, help='whether to get prof file1') + parser.add_argument('--num_epoch_start', type=int, default=0, help='whether to get prof file1') + parser.add_argument('--loadweight', default='latest', help='whether to get prof file1') + parser.add_argument('--prof_file', type=str, default='./output.prof', help='whether to get prof file') + parser.add_argument('--log_path', type=str, default='gpu1p.txt', help='whether to get prof file') + parser.add_argument('--multiprocessing_distributed', type=int, default=1, + help='Use multi-processing distributed training to launch,if it is eaqul to 1 or more than ,start to npu/gpu Multi-card training ') + parser.add_argument('--world_size', type=int, default=1, help='word__size') + parser.add_argument('--distributed', type=int, default=1, + help='whether to use distributed to fastern training,if it is eaqul to 1 or more than ,start to npu/gpu Multi-card training') + parser.add_argument('--rank', default=0, type=int, help='rank') + parser.add_argument('--gpu', default=None, type=int, help='GPU id to use.') + parser.add_argument('--npu', type=int, default=0, help='whether to use npu to fastern training') + parser.add_argument('--pu_ids', type=str, default='0,1', + help='gpu ids(npu ids): e.g. 0 0,1,2, 0,2. use -1 for CPU') + + parser.add_argument('--isapex', default=True, help='whether to use apex to fastern training') + parser.add_argument('--apex_type', type=str, default="O1", help='O0,O1,O2,O3') + parser.add_argument('--loss_scale', default=None, help='loss_scale:1,128,dynamic') + parser.add_argument('--dataroot', type=str, default='./datasets/maps', + help='path to images (should have subfolders trainA, trainB, valA, valB, etc)') + parser.add_argument('--name', type=str, default='maps_cycle_gan', + help='name of the experiment. It decides where to store samples and models') + + parser.add_argument('--checkpoints_dir', type=str, default='./re_checkpoints2p_bs1', + help='models are saved here') + # model parameters + parser.add_argument('--model', type=str, default='cycle_gan', + help='chooses which model to use. [cycle_gan| pix2pix | test | colorization]') + parser.add_argument('--input_nc', type=int, default=3, + help='# of input image channels: 3 for RGB and 1 for grayscale') + parser.add_argument('--output_nc', type=int, default=3, + help='# of output image channels: 3 for RGB and 1 for grayscale') + parser.add_argument('--ngf', type=int, default=64, help='# of gen filters in the last conv layer') + parser.add_argument('--ndf', type=int, default=64, help='# of discrim filters in the first conv layer') + parser.add_argument('--netD', type=str, default='basic', + help='specify discriminator architecture [basic | n_layers | pixel].' + ' The basic model is a 70x70 PatchGAN. n_layers allows you to ' + 'specify the layers in the discriminator') + parser.add_argument('--netG', type=str, default='resnet_9blocks', + help='specify generator architecture [resnet_9blocks | resnet_6blocks | ' + 'unet_256 | unet_128]') + parser.add_argument('--n_layers_D', type=int, default=3, help='only used if netD==n_layers') + parser.add_argument('--norm', type=str, default='instance', + help='instance normalization or batch normalization [instance | batch | none]') + parser.add_argument('--init_type', type=str, default='normal', + help='network initialization [normal | xavier | kaiming | orthogonal]') + parser.add_argument('--init_gain', type=float, default=0.02, + help='scaling factor for normal, xavier and orthogonal.') + parser.add_argument('--no_dropout', action='store_true', help='no dropout for the generator') + # dataset parameters + parser.add_argument('--dataset_mode', type=str, default='unaligned', + help='chooses how datasets are loaded. [unaligned | aligned | single | colorization]') + parser.add_argument('--direction', type=str, default='AtoB', help='AtoB or BtoA') + parser.add_argument('--serial_batches', action='store_true', + help='if true, takes images in order to make batches, otherwise takes them randomly') + parser.add_argument('--num_threads', default=8, type=int, help='# threads for loading data') + parser.add_argument('--batch_size', type=int, default=4, help='input batch size') + parser.add_argument('--load_size', type=int, default=286, help='scale images to this size') + parser.add_argument('--crop_size', type=int, default=256, help='then crop to this size') + parser.add_argument('--max_dataset_size', type=int, default=float("inf"), + help='Maximum number of samples allowed per dataset. If the dataset directory ' + 'contains more than max_dataset_size, only a subset is loaded.') + parser.add_argument('--preprocess', type=str, default='resize_and_crop', + help='scaling and cropping of images at load time [resize_and_crop | crop | ' + 'scale_width | scale_width_and_crop | none]') + parser.add_argument('--no_flip', action='store_true', + help='if specified, do not flip the images for data augmentation') + parser.add_argument('--display_winsize', type=int, default=256, + help='display window size for both visdom and HTML') + # additional parameters + parser.add_argument('--epoch', type=str, default='latest', + help='which epoch to load? set to latest to use latest cached model') + parser.add_argument('--load_iter', type=int, default='0', + help='which iteration to load? if load_iter > 0, the code will load models by iter_' + '[load_iter]; otherwise, the code will load models by [epoch]') + parser.add_argument('--verbose', action='store_true', help='if specified, print more debugging information') + parser.add_argument('--suffix', default='', type=str, + help='customized suffix: opt.name = opt.name + suffix: e.g., {model}_{netG}_size{load_size}') + parser.add_argument( + "--cache-dataset", + dest="cache_dataset", + help="Cache the datasets for quicker initialization. It also serializes the transforms", + action="store_true", + ) + parser.set_defaults(no_dropout=True) # default CycleGAN did not use dropout + if (self.isTrain): + # network saving and loading parameters + parser.add_argument('--display_freq', type=int, default=400, + help='frequency of showing training results on screen') + parser.add_argument('--display_ncols', type=int, default=4, + help='if positive, display all images in a single visdom web panel with ' + 'certain number of images per row.') + parser.add_argument('--display_id', type=int, default=-1, help='window id of the web display') + parser.add_argument('--display_server', type=str, default="http://localhost", + help='visdom server of the web display') + parser.add_argument('--display_env', type=str, default='main', + help='visdom display environment name (default is "main")') + parser.add_argument('--display_port', type=int, default=8097, help='visdom port of the web display') + parser.add_argument('--update_html_freq', type=int, default=1000, + help='frequency of saving training results to html') + parser.add_argument('--print_freq', type=int, default=100, + help='frequency of showing training results on console') + parser.add_argument('--no_html', action='store_true', + help='do not save intermediate training results to [' + 'opt.checkpoints_dir]/[opt.name]/web/') + # network saving and loading parameters + parser.add_argument('--save_latest_freq', type=int, default=5000, + help='frequency of saving the latest results') + parser.add_argument('--save_epoch_freq', type=int, default=5, + help='frequency of saving checkpoints at the end of epochs') + parser.add_argument('--save_by_iter', action='store_true', help='whether saves model by iteration') + parser.add_argument('--continue_train', action='store_true', + help='continue training: load the latest model') + parser.add_argument('--epoch_count', type=int, default=1, + help='the starting epoch count, we save the model ' + 'by , +, ...') + parser.add_argument('--phase', type=str, default='train', help='train, val, test, etc') + # training parameters + parser.add_argument('--n_epochs', type=int, default=100, + help='number of epochs with the initial learning rate') + parser.add_argument('--n_epochs_decay', type=int, default=100, + help='number of epochs to linearly decay learning rate to zero') + parser.add_argument('--beta1', type=float, default=0.5, help='momentum term of adam') + parser.add_argument('--lr', type=float, default=0.0002, help='initial learning rate for adam') + parser.add_argument('--gan_mode', type=str, default='lsgan', + help='the type of GAN objective. [vanilla| lsgan | wgangp]. vanilla GAN loss is' + ' the cross-entropy objective used in the original GAN paper.') + parser.add_argument('--pool_size', type=int, default=50, + help='the size of image buffer that stores previously generated images') + parser.add_argument('--lr_policy', type=str, default='linear', + help='learning rate policy. [linear | step | plateau | cosine]') + parser.add_argument('--lr_decay_iters', type=int, default=50, + help='multiply by a gamma every lr_decay_iters iterations') + parser.add_argument('--lambda_A', type=float, default=10.0, help='weight for cycle loss (A -> B -> A)') + parser.add_argument('--lambda_B', type=float, default=10.0, help='weight for cycle loss (B -> A -> B)') + parser.add_argument('--lambda_identity', type=float, default=0.5, + help='use identity mapping. Setting lambda_identity other than 0 has an effect of' + ' scaling the weight of the identity mapping loss. For example, if the weight of' + ' the identity loss should be 10 times smaller than the weight of the ' + 'reconstruction loss, please set lambda_identity = 0.1') + parser = parser.parse_args() + parser.process_device_map = self.device_id_to_process_device_map(parser.pu_ids) + return parser + + def device_id_to_process_device_map(self, device_list): + devices = device_list.split(",") + devices = [int(x) for x in devices] + devices.sort() + + process_device_map = dict() + for process_id, device_id in enumerate(devices): + process_device_map[process_id] = device_id + return process_device_map + + def change_parser(self, isTrain=True, isTest=False): + self.isTest = isTest + self.isTrain = isTrain + self.parser = None + return self.initialize() + + def printParser(self): + pasers = self.parser.parse_args() + message = '' + message += '----------------- Options ---------------\n' + for k, v in sorted(vars(pasers).items()): + comment = '' + default = self.parser.get_default(k) + # if v != default: + # comment = '\t[default: %s]' % str(default) + message += '{:>25}: {:<30}{}\n'.format(str(k), str(v), comment) + message += '----------------- End -------------------' + print(message) + + def init_distributed_mode(self, ngpus_per_node, gpu): + opt = self.parser.parse_args() + if opt.multiprocessing_distributed >= 1: + # For multiprocessing distributed training, rank needs to be the + # global rank among all the processes + opt.rank = opt.rank * ngpus_per_node + gpu + if (opt.npu < 1): + torch.distributed.init_process_group(backend='nccl', init_method='env://', world_size=opt.world_size, + rank=opt.rank) + elif (opt.npu >= 1): + torch.distributed.init_process_group(backend='hccl', world_size=opt.world_size, rank=opt.rank) diff --git a/PyTorch/contrib/cv/others/CycleGAN/requirements.txt b/PyTorch/contrib/cv/others/CycleGAN/requirements.txt index 4038ca0bc4742f5fd062ff7a7456ff8cf01fdcd7..8a81295f99d9675b70c8644abaa5efbe4daa9e13 100644 --- a/PyTorch/contrib/cv/others/CycleGAN/requirements.txt +++ b/PyTorch/contrib/cv/others/CycleGAN/requirements.txt @@ -1,4 +1,4 @@ -torch>=1.4.0 -torchvision>=0.5.0 -dominate>=2.4.0 +torch>=1.4.0 +torchvision>=0.5.0 +dominate>=2.4.0 visdom>=0.1.8.8 \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/CycleGAN/train.py b/PyTorch/contrib/cv/others/CycleGAN/train.py index 4396d1904c452ae9be682aaccaf8f27313e57a28..0e54494a621b9cc00b8e37b01a57c6d1ba1bde87 100644 --- a/PyTorch/contrib/cv/others/CycleGAN/train.py +++ b/PyTorch/contrib/cv/others/CycleGAN/train.py @@ -1,130 +1,130 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import os -import time -import torch -from dataloader import create_dataset -from parse import parse_args -from util.visualizer_adapt import Visualizer -import torch.multiprocessing as mp -from models.cycle_gan_model_adapt import CycleGANModel as create_model -from torch import distributed as dist - - -def main(opt): - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = '23112' - if opt.distributed >= 1: - ngpus_per_node = len(opt.process_device_map) - opt.ngpus_per_node = ngpus_per_node - if (ngpus_per_node == 1): - ngpus_per_node = 0 - opt.total_iters = 0 - if opt.multiprocessing_distributed >= 1: - opt.world_size = ngpus_per_node * opt.world_size - mp.spawn(main_worker, nprocs=ngpus_per_node, args=(ngpus_per_node, opt)) - else: - main_worker(ngpus_per_node, opt, opt) - - -def main_worker(gpu, ngpus_per_node, args): - opt = args - print([args.process_device_map, gpu]) - opt.gpu = args.process_device_map[gpu] - if (opt.distributed >= 1): - opt.rank = gpu - if opt.multiprocessing_distributed >= 1: - opt.rank = gpu - if (opt.npu < 1): - torch.distributed.init_process_group(backend='nccl', init_method='env://', world_size=opt.world_size, - rank=opt.rank) - elif (opt.npu >= 1): - torch.npu.set_device(gpu) - torch.distributed.init_process_group(backend='hccl', world_size=opt.world_size, rank=opt.rank) - dataset, train_sampler = create_dataset(opt) # create a dataset given opt.dataset_mode and other options - dataset_size = len(dataset) # get the number of images in the dataset. - print('The number of training images = %d' % dataset_size) - opt.isTrain = True - model = create_model(opt) # create a model given opt.model and other options - model.setup(opt) - visualizer = Visualizer(opt) # create a visualizer that display/save images and plots - for epoch in range(opt.num_epoch_start, opt.num_epoch): - visualizer.reset() # reset the visualizer: make sure it saves the results to HTML at least once every epoch - if (opt.ngpus_per_node > 1): - train_sampler.set_epoch(epoch) - for i, data in enumerate(dataset): # inner loop within one epoch - iter_start_time = time.time() # timer for computation per iteration - opt.total_iters += (opt.batch_size * opt.ngpus_per_node) - if (opt.prof >= 1 and i > 10): - if (opt.npu == False): - with torch.autograd.profiler.profile(use_cuda=True) as prof: - model.set_input(data) - model.optimize_parameters() - print(prof.key_averages().table()) - prof.export_chrome_trace(opt.prof_file) # "output.prof" - opt.prof = False - else: - with torch.autograd.profiler.profile(use_npu=True) as prof: - model.set_input(data) - model.optimize_parameters() - print(prof.key_averages().table()) - prof.export_chrome_trace(opt.prof_file) # - opt.prof = False - else: - model.set_input(data) - model.optimize_parameters() - if opt.total_iters % opt.save_latest_freq == 0: # print training losses and save logging information to the disk - model.save_networks(epoch) - # model.save_networks(epoch) - if opt.total_iters % opt.display_freq == 0: # display images on visdom and save images to a HTML file - t_comp = (time.time() - iter_start_time) / opt.batch_size - fps = opt.batch_size * opt.ngpus_per_node / t_comp - losses = model.get_current_losses() - visualizer.print_current_losses(epoch, fps, losses, t_comp) - # print_current_losses(opt, epoch, fps, losses, t_comp) - save_result = opt.total_iters % opt.update_html_freq == 0 - model.compute_visuals() - visualizer.display_current_results(model.get_current_visuals(), epoch, save_result) - model.update_learning_rate() # Update learning rates - - if epoch % opt.save_epoch_freq == 0: # cache our model every epochs - print('saving the model at the end of epoch %d, iters %d' % (epoch, opt.total_iters)) - model.save_networks('latest_pu' + str(opt.gpu)) - model.save_networks(str(epoch) + '_pu' + str(opt.gpu)) - dist.barrier() - - -if __name__ == '__main__': - paser = parse_args(True, False) - opt = paser.initialize() - paser.printParser() - main(opt) +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import os +import time +import torch +from dataloader import create_dataset +from parse import parse_args +from util.visualizer_adapt import Visualizer +import torch.multiprocessing as mp +from models.cycle_gan_model_adapt import CycleGANModel as create_model +from torch import distributed as dist + + +def main(opt): + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '23112' + if opt.distributed >= 1: + ngpus_per_node = len(opt.process_device_map) + opt.ngpus_per_node = ngpus_per_node + if (ngpus_per_node == 1): + ngpus_per_node = 0 + opt.total_iters = 0 + if opt.multiprocessing_distributed >= 1: + opt.world_size = ngpus_per_node * opt.world_size + mp.spawn(main_worker, nprocs=ngpus_per_node, args=(ngpus_per_node, opt)) + else: + main_worker(ngpus_per_node, opt, opt) + + +def main_worker(gpu, ngpus_per_node, args): + opt = args + print([args.process_device_map, gpu]) + opt.gpu = args.process_device_map[gpu] + if (opt.distributed >= 1): + opt.rank = gpu + if opt.multiprocessing_distributed >= 1: + opt.rank = gpu + if (opt.npu < 1): + torch.distributed.init_process_group(backend='nccl', init_method='env://', world_size=opt.world_size, + rank=opt.rank) + elif (opt.npu >= 1): + torch.npu.set_device(gpu) + torch.distributed.init_process_group(backend='hccl', world_size=opt.world_size, rank=opt.rank) + dataset, train_sampler = create_dataset(opt) # create a dataset given opt.dataset_mode and other options + dataset_size = len(dataset) # get the number of images in the dataset. + print('The number of training images = %d' % dataset_size) + opt.isTrain = True + model = create_model(opt) # create a model given opt.model and other options + model.setup(opt) + visualizer = Visualizer(opt) # create a visualizer that display/save images and plots + for epoch in range(opt.num_epoch_start, opt.num_epoch): + visualizer.reset() # reset the visualizer: make sure it saves the results to HTML at least once every epoch + if (opt.ngpus_per_node > 1): + train_sampler.set_epoch(epoch) + for i, data in enumerate(dataset): # inner loop within one epoch + iter_start_time = time.time() # timer for computation per iteration + opt.total_iters += (opt.batch_size * opt.ngpus_per_node) + if (opt.prof >= 1 and i > 10): + if (opt.npu == False): + with torch.autograd.profiler.profile(use_cuda=True) as prof: + model.set_input(data) + model.optimize_parameters() + print(prof.key_averages().table()) + prof.export_chrome_trace(opt.prof_file) # "output.prof" + opt.prof = False + else: + with torch.autograd.profiler.profile(use_npu=True) as prof: + model.set_input(data) + model.optimize_parameters() + print(prof.key_averages().table()) + prof.export_chrome_trace(opt.prof_file) # + opt.prof = False + else: + model.set_input(data) + model.optimize_parameters() + if opt.total_iters % opt.save_latest_freq == 0: # print training losses and save logging information to the disk + model.save_networks(epoch) + # model.save_networks(epoch) + if opt.total_iters % opt.display_freq == 0: # display images on visdom and save images to a HTML file + t_comp = (time.time() - iter_start_time) / opt.batch_size + fps = opt.batch_size * opt.ngpus_per_node / t_comp + losses = model.get_current_losses() + visualizer.print_current_losses(epoch, fps, losses, t_comp) + # print_current_losses(opt, epoch, fps, losses, t_comp) + save_result = opt.total_iters % opt.update_html_freq == 0 + model.compute_visuals() + visualizer.display_current_results(model.get_current_visuals(), epoch, save_result) + model.update_learning_rate() # Update learning rates + + if epoch % opt.save_epoch_freq == 0: # cache our model every epochs + print('saving the model at the end of epoch %d, iters %d' % (epoch, opt.total_iters)) + model.save_networks('latest_pu' + str(opt.gpu)) + model.save_networks(str(epoch) + '_pu' + str(opt.gpu)) + dist.barrier() + + +if __name__ == '__main__': + paser = parse_args(True, False) + opt = paser.initialize() + paser.printParser() + main(opt) diff --git a/PyTorch/contrib/cv/others/DCGAN/LICENSE b/PyTorch/contrib/cv/others/DCGAN/LICENSE index 753842b6720f7980d411ecf2c78eb4ef220b9df8..f49a4e16e68b128803cc2dcea614603632b04eac 100644 --- a/PyTorch/contrib/cv/others/DCGAN/LICENSE +++ b/PyTorch/contrib/cv/others/DCGAN/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/DCGAN/dcgan.py b/PyTorch/contrib/cv/others/DCGAN/dcgan.py index e130984cedbe4368913fd927cd3fefdea50df582..e486b5863eef079ab85b2816fd8a327cb7551132 100644 --- a/PyTorch/contrib/cv/others/DCGAN/dcgan.py +++ b/PyTorch/contrib/cv/others/DCGAN/dcgan.py @@ -1,82 +1,82 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch -import torch.nn as nn - - -def weights_init_normal(m): - class_name = m.__class__.__name__ - if class_name.find("Conv") != -1: - torch.nn.init.normal_(m.weight.data, 0.0, 0.02) - elif class_name.find("BatchNorm2d") != -1: - torch.nn.init.normal_(m.weight.data, 1.0, 0.02) - torch.nn.init.constant_(m.bias.data, 0.0) - - -class Generator(nn.Module): - def __init__(self, img_size, latent_dim, channels): - super(Generator, self).__init__() - - self.init_size = img_size // 4 - self.l1 = nn.Sequential(nn.Linear(latent_dim, 128 * self.init_size ** 2)) - - self.conv_blocks = nn.Sequential( - nn.BatchNorm2d(128), - nn.Upsample(scale_factor=2), - nn.Conv2d(128, 128, 3, stride=1, padding=1), - nn.BatchNorm2d(128, 0.8), - nn.LeakyReLU(0.2, inplace=True), - nn.Upsample(scale_factor=2), - nn.Conv2d(128, 32, 3, stride=1, padding=1), - nn.BatchNorm2d(32, 0.8), - nn.LeakyReLU(0.2, inplace=True), - nn.Conv2d(32, channels, 3, stride=1, padding=1), - nn.Tanh() - ) - - def forward(self, z): - out = self.l1(z) - out = out.view(out.shape[0], 128, self.init_size, self.init_size) - img = self.conv_blocks(out) - return img - - -class Discriminator(nn.Module): - def __init__(self, img_size, channels): - super(Discriminator, self).__init__() - - def discriminator_block(in_filters, out_filters, bn=True): - block = [nn.Conv2d(in_filters, out_filters, 3, 2, 1), nn.LeakyReLU(0.2, inplace=True), nn.Dropout2d(0.25)] - if bn: - block.append(nn.BatchNorm2d(out_filters, 0.8)) - return block - - self.model = nn.Sequential( - *discriminator_block(channels, 16, bn=False), - *discriminator_block(16, 32), - *discriminator_block(32, 64), - *discriminator_block(64, 128) - ) - - # The height and width of down_sampled image - ds_size = img_size // 2 ** 4 - self.adv_layer = nn.Sequential(nn.Linear(128 * ds_size ** 2, 1)) - - def forward(self, img): - out = self.model(img) - out = out.view(out.shape[0], -1) - validity = self.adv_layer(out) - - return validity +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch +import torch.nn as nn + + +def weights_init_normal(m): + class_name = m.__class__.__name__ + if class_name.find("Conv") != -1: + torch.nn.init.normal_(m.weight.data, 0.0, 0.02) + elif class_name.find("BatchNorm2d") != -1: + torch.nn.init.normal_(m.weight.data, 1.0, 0.02) + torch.nn.init.constant_(m.bias.data, 0.0) + + +class Generator(nn.Module): + def __init__(self, img_size, latent_dim, channels): + super(Generator, self).__init__() + + self.init_size = img_size // 4 + self.l1 = nn.Sequential(nn.Linear(latent_dim, 128 * self.init_size ** 2)) + + self.conv_blocks = nn.Sequential( + nn.BatchNorm2d(128), + nn.Upsample(scale_factor=2), + nn.Conv2d(128, 128, 3, stride=1, padding=1), + nn.BatchNorm2d(128, 0.8), + nn.LeakyReLU(0.2, inplace=True), + nn.Upsample(scale_factor=2), + nn.Conv2d(128, 32, 3, stride=1, padding=1), + nn.BatchNorm2d(32, 0.8), + nn.LeakyReLU(0.2, inplace=True), + nn.Conv2d(32, channels, 3, stride=1, padding=1), + nn.Tanh() + ) + + def forward(self, z): + out = self.l1(z) + out = out.view(out.shape[0], 128, self.init_size, self.init_size) + img = self.conv_blocks(out) + return img + + +class Discriminator(nn.Module): + def __init__(self, img_size, channels): + super(Discriminator, self).__init__() + + def discriminator_block(in_filters, out_filters, bn=True): + block = [nn.Conv2d(in_filters, out_filters, 3, 2, 1), nn.LeakyReLU(0.2, inplace=True), nn.Dropout2d(0.25)] + if bn: + block.append(nn.BatchNorm2d(out_filters, 0.8)) + return block + + self.model = nn.Sequential( + *discriminator_block(channels, 16, bn=False), + *discriminator_block(16, 32), + *discriminator_block(32, 64), + *discriminator_block(64, 128) + ) + + # The height and width of down_sampled image + ds_size = img_size // 2 ** 4 + self.adv_layer = nn.Sequential(nn.Linear(128 * ds_size ** 2, 1)) + + def forward(self, img): + out = self.model(img) + out = out.view(out.shape[0], -1) + validity = self.adv_layer(out) + + return validity diff --git a/PyTorch/contrib/cv/others/DCGAN/get_mnist.py b/PyTorch/contrib/cv/others/DCGAN/get_mnist.py index 443b0bd63be4669b5f8402d2f23c8ac7466adb67..6e3a45b7ac555f781ed9103d3f3b4d437f6a61e1 100644 --- a/PyTorch/contrib/cv/others/DCGAN/get_mnist.py +++ b/PyTorch/contrib/cv/others/DCGAN/get_mnist.py @@ -1,30 +1,30 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torchvision.datasets as datasets -import argparse - -parser = argparse.ArgumentParser(description="MNIST dataset") -parser.add_argument('--data_path', metavar='DIR', type=str, default="./data", - help='path to dataset') - -if __name__ == "__main__": - args = parser.parse_args() - print("MNIST target folder : ", args.data_path) - print("start download...") - train_dataset = datasets.MNIST( - args.data_path, - train=True, - download=True) - print("download done...") +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torchvision.datasets as datasets +import argparse + +parser = argparse.ArgumentParser(description="MNIST dataset") +parser.add_argument('--data_path', metavar='DIR', type=str, default="./data", + help='path to dataset') + +if __name__ == "__main__": + args = parser.parse_args() + print("MNIST target folder : ", args.data_path) + print("start download...") + train_dataset = datasets.MNIST( + args.data_path, + train=True, + download=True) + print("download done...") diff --git a/PyTorch/contrib/cv/others/DCGAN/main.py b/PyTorch/contrib/cv/others/DCGAN/main.py index 0abc7517f0f4adba9cb11ae3d510268bac8f7c4f..a1c157ca33df01ef63f6a6ade01b1d0499f618e2 100644 --- a/PyTorch/contrib/cv/others/DCGAN/main.py +++ b/PyTorch/contrib/cv/others/DCGAN/main.py @@ -1,510 +1,510 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import argparse -import os -import time -import apex -from apex import amp -import torch -import torch.nn as nn -import torch.nn.parallel -import torch.backends.cudnn as cudnn -import torch.distributed as dist -import torch.optim -import torch.utils.data -import torch.utils.data.distributed -import torchvision.transforms as transforms -import torchvision.datasets as datasets -from torchvision.utils import save_image - -from dcgan import Generator, Discriminator, weights_init_normal - -parser = argparse.ArgumentParser(description="pytorch DCGAN implementation") -## dcgan parameters -parser.add_argument('--data', metavar='DIR', type=str, default="./data", - help='path to dataset') -parser.add_argument("--n-epochs", type=int, default=200, - help="number of epochs of training") -parser.add_argument("--batch-size", type=int, default=64, - help="size of the batches") -parser.add_argument("--lr", type=float, default=0.0002, - help="adam: learning rate") -parser.add_argument("--b1", type=float, default=0.5, - help="adam: decay of first order momentum of gradient") -parser.add_argument("--b2", type=float, default=0.999, - help="adam: decay of first order momentum of gradient") -parser.add_argument("--n-cpu", type=int, default=8, - help="number of cpu threads to use during batch generation") -parser.add_argument("--latent_dim", type=int, default=100, - help="dimensionality of the latent space") -parser.add_argument("--img_size", type=int, default=32, - help="size of each image dimension") -parser.add_argument("--channels", type=int, default=1, - help="number of image channels") -parser.add_argument("--sample_interval", type=int, default=400, - help="interval between image sampling") -## add useful parameters : such as resume,evaluate -parser.add_argument('--checkpoint-path', default=None, type=str, metavar='PATH', - help='path to latest checkpoint (default: none)') -parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', default=False, - help='evaluate model : generate (n_samples) samples,saved in dir(validate)') -parser.add_argument('--n-samples', type=int, default=10, - help="amount of samples in function(validate)") -parser.add_argument('-p', '--print-freq', default=10, type=int, metavar='N', - help='print frequency (default 10)') -## parameters for distribute training -parser.add_argument('--world-size', default=-1, type=int, - help='number of nodes for distributed training') -parser.add_argument('--rank', default=-1, type=int, - help='node rank for distributed training') -parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str, - help='url used to set up distributed training') -parser.add_argument('--dist-backend', default='nccl', type=str, - help='distributed backend') -parser.add_argument('--gpu', default=None, type=int, - help='GPU id to use.') -## for ascend 910 -parser.add_argument('--device', default='npu', type=str, help='npu or gpu') -parser.add_argument('--addr', default='10.136.181.115', - type=str, help='master addr') -parser.add_argument('--device-list', default='0,1,2,3,4,5,6,7', - type=str, help='device id list') -parser.add_argument('--amp', default=False, action='store_true', - help='use amp to train the model') -parser.add_argument('--loss-scale', default=None, type=float, - help='loss scale using in amp, default None means dynamic') -parser.add_argument('--opt-level', default='O2', type=str, - help='loss scale using in amp, default -1 means dynamic') -parser.add_argument('--prof', default=False, action='store_true', - help='use profiling to evaluate the performance of model') - - -def device_id_to_process_device_map(device_list): - devices = device_list.split(",") - devices = [int(x) for x in devices] - devices.sort() - - process_device_map = dict() - for process_id, device_id in enumerate(devices): - process_device_map[process_id] = device_id - - return process_device_map - - -def get_device_name(device_type, device_order): - if device_type == 'npu': - device_name = 'npu:{}'.format(device_order) - else: - device_name = 'cuda:{}'.format(device_order) - - return device_name - - -def main(): - args = parser.parse_args() - print(args.device_list) - args.process_device_map = device_id_to_process_device_map(args.device_list) - - # add start_epoch - args.start_epoch = 0 - - os.environ['MASTER_ADDR'] = args.addr - os.environ['MASTER_PORT'] = '29688' - - if args.device == 'npu': - ngpus_per_node = len(args.process_device_map) - else: - if args.gpu is None: - ngpus_per_node = len(args.process_device_map) - else: - ngpus_per_node = 1 - print('ngpus_per_node:', ngpus_per_node) - - args.world_size = ngpus_per_node * args.world_size - args.distributed = args.world_size > 1 - - # create folders - if not args.distributed or (args.distributed and args.rank == args.process_device_map[0]): - if not os.path.exists("./images/"): - os.makedirs("./images/") - if not os.path.exists("./samples/"): - os.makedirs("./samples/") - - main_worker(args.rank, ngpus_per_node, args) - - -def main_worker(gpu, ngpus_per_node, args): - args.gpu = args.process_device_map[gpu] - if args.distributed: - if args.device == 'npu': - dist.init_process_group(backend=args.dist_backend, - # init_method=args.dist_url, - world_size=args.world_size, - rank=args.rank) - else: - dist.init_process_group(backend=args.dist_backend, - init_method=args.dist_url, - world_size=args.world_size, - rank=args.rank) - - print('rank: {} / {}'.format(args.rank, args.world_size)) - - # init device - device_loc = get_device_name(args.device, args.gpu) - args.loc = device_loc - - # set device - print('set_device ', device_loc) - if args.device == 'npu': - torch.npu.set_device(device_loc) - else: - torch.cuda.set_device(args.gpu) - - # create model - G = Generator(args.img_size, args.latent_dim, args.channels) - D = Discriminator(args.img_size, args.channels) - # initialize weights - G.apply(weights_init_normal) - D.apply(weights_init_normal) - if args.checkpoint_path: - print("=> using pre-trained model dcgan,device(%d)" % args.gpu) - print("loading model of yours...,device(%d)" % args.gpu) - checkpoint = torch.load(args.checkpoint_path, map_location="cpu") - G.load_state_dict({k.replace('module.', ''): v for k, v in checkpoint["G"].items()}) - D.load_state_dict({k.replace('module.', ''): v for k, v in checkpoint["D"].items()}) - else: - print("=> creating model dcgan,device(%d)" % args.gpu) - - print('model to device_loc(%s)...' % device_loc) - G = G.to(device_loc) - D = D.to(device_loc) - - if args.distributed: - args.batch_size = int(args.batch_size / args.world_size) - args.n_cpu = int((args.n_cpu + ngpus_per_node - 1) / ngpus_per_node) - args.sample_interval = int(args.sample_interval / ngpus_per_node) - - # define optimizer, apply apex - optimizer_G = apex.optimizers.NpuFusedAdam(G.parameters(), lr=args.lr, betas=(args.b1, args.b2)) - optimizer_D = apex.optimizers.NpuFusedAdam(D.parameters(), lr=args.lr, betas=(args.b1, args.b2)) - - if args.amp: - [D, G], [optimizer_D, optimizer_G] = amp.initialize( - [D, G], [optimizer_D, optimizer_G], opt_level=args.opt_level, loss_scale=args.loss_scale, num_losses=3, - combine_grad=True) - - if args.evaluate: - print("evaluate mode...", " device(%d)," % args.gpu) - validate(G, args) - return - - if args.checkpoint_path: - args.start_epoch = checkpoint['epoch'] - optimizer_G.load_state_dict(checkpoint['optimizer_G']) - optimizer_D.load_state_dict(checkpoint['optimizer_D']) - if args.amp: - amp.load_state_dict(checkpoint['amp']) - print("=> loaded checkpoint '{}' (epoch {})".format(args.resume, checkpoint['epoch'])) - - if args.distributed: - G = torch.nn.parallel.DistributedDataParallel(G, device_ids=[args.gpu], broadcast_buffers=False) - D = torch.nn.parallel.DistributedDataParallel(D, device_ids=[args.gpu], broadcast_buffers=False) - - # Loss function - adversarial_loss = nn.BCEWithLogitsLoss().to(device_loc) - - cudnn.benchmark = True - - # Data loading code - data_path = args.data - print("dataset path : %s" % data_path) - train_dataset = datasets.MNIST( - data_path, - train=True, - download=False, - transform=transforms.Compose( - [transforms.Resize(args.img_size), transforms.ToTensor(), transforms.Normalize([0.5], [0.5])] - )) - - if args.distributed: - train_sampler = torch.utils.data.distributed.DistributedSampler( - train_dataset) - else: - train_sampler = None - - train_loader = torch.utils.data.DataLoader( - train_dataset, batch_size=args.batch_size, shuffle=(train_sampler is None), - num_workers=args.n_cpu, pin_memory=False, sampler=train_sampler, drop_last=True) - - if args.prof: - print("profiling mode...", " device(%d)," % args.gpu) - profiling(train_loader, G, D, optimizer_G, optimizer_D, adversarial_loss, args) - return - - # start training - print("train mode...", " device(%d)," % args.gpu) - fixed_z = torch.randn((5, args.latent_dim), dtype=torch.float32) - # Configure input - fixed_z = fixed_z.to(device_loc, non_blocking=True).to(torch.float) - for epoch in range(args.start_epoch, args.n_epochs): - if args.distributed: - train_sampler.set_epoch(epoch) - # train for one epoch - train(train_loader, - G, D, - optimizer_G, optimizer_D, - adversarial_loss, - epoch, args, - ngpus_per_node) - - if not args.distributed or (args.distributed and args.gpu == args.process_device_map[0]): - # save fixed imgs - G.eval() - fixed_imgs = G(fixed_z) - save_image(fixed_imgs[:5], "samples/fixed_images-epoch_%03d.png" % epoch, nrow=5, normalize=True) - ############## npu modify begin ############# - if args.amp: - torch.save({ - 'epoch': epoch + 1, - 'arch': 'dcgan', - 'G': G.state_dict(), - 'D': D.state_dict(), - 'optimizer_G': optimizer_G.state_dict(), - 'optimizer_D': optimizer_D.state_dict(), - 'amp': amp.state_dict(), - }, "checkpoint-amp-epoch_%d.pth" % (epoch + 1)) - - if os.path.exists("checkpoint-amp-epoch_%d.pth" % epoch): - os.remove("checkpoint-amp-epoch_%d.pth" % epoch) - else: - torch.save({ - 'epoch': epoch + 1, - 'arch': 'dcgan', - 'G': G.state_dict(), - 'D': D.state_dict(), - 'optimizer_G': optimizer_G.state_dict(), - 'optimizer_D': optimizer_D.state_dict(), - }, "checkpoint-epoch_%d.pth" % (epoch + 1)) - if os.path.exists("checkpoint-epoch_%d.pth" % epoch): - os.remove("checkpoint-epoch_%d.pth" % epoch) - ############## npu modify end ############# - # train loop done - - -def profiling(train_loader, generator, discriminator, optimizer_G, optimizer_D, loss, args): - generator.train() - discriminator.train() - - def update(step=None): - start_time = time.time() - valid = torch.ones(imgs.size(0), 1, requires_grad=False) - fake = torch.zeros(imgs.size(0), 1, requires_grad=False) - # Sample noise as generator input - z = torch.randn((imgs.size(0), args.latent_dim), dtype=torch.float32) - # Configure input - real_imgs = imgs.to(args.loc, non_blocking=True).to(torch.float) - valid = valid.to(args.loc, non_blocking=True).to(torch.float) - fake = fake.to(args.loc, non_blocking=True).to(torch.float) - z = z.to(args.loc, non_blocking=True).to(torch.float) - # update D - discriminator.zero_grad() - output = discriminator(real_imgs) - errD_real = loss(output, valid) - with amp.scale_loss(errD_real, optimizer_D, loss_id=0) as errD_real_scaled: - errD_real_scaled.backward() - gen_imgs = generator(z) - output = discriminator(gen_imgs.detach()) - errD_fake = loss(output, fake) - with amp.scale_loss(errD_fake, optimizer_D, loss_id=1) as errD_fake_scaled: - errD_fake_scaled.backward() - errD = errD_real + errD_fake - optimizer_D.step() - # update G - generator.zero_grad() - output = discriminator(gen_imgs) - errG = loss(output, valid) - with amp.scale_loss(errG, optimizer_G, loss_id=2) as errG_scaled: - errG_scaled.backward() - optimizer_G.step() - if step is not None: - print('iter: %d, loss: %.2f, time: %.2f' % (step, errG.item(), (time.time() - start_time))) - - for i, (imgs, _) in enumerate(train_loader): - if i < 20: - update(step=i) - else: - if args.device == 'npu': - with torch.autograd.profiler.profile(use_npu=True) as prof: - update() - else: - with torch.autograd.profiler.profile(use_cuda=True) as prof: - update() - break - prof.export_chrome_trace("dcgan.prof") - - -def train(train_loader, generator, discriminator, optimizer_G, optimizer_D, loss, epoch, args, ngpus_per_node): - batch_time = AverageMeter('Time', ':6.3f') - data_time = AverageMeter('Data', ':6.3f') - G_loss = AverageMeter('G_Loss', ':.4e') - D_loss = AverageMeter('D_Loss', ':.4e') - D_real = AverageMeter('D_real', ':.4e') - D_fake = AverageMeter('D_fake', ':.4e') - progress = ProgressMeter( - len(train_loader), - [batch_time, data_time, G_loss, D_loss, D_real, D_fake], - prefix="Epoch: [{}]".format(epoch)) - - # switch to train mode - generator.train() - discriminator.train() - - end = time.time() - for i, (imgs, _) in enumerate(train_loader): - # measure data loading time - data_time.update(time.time() - end) - - valid = torch.ones(imgs.size(0), 1, requires_grad=False) - fake = torch.zeros(imgs.size(0), 1, requires_grad=False) - # Sample noise as generator input - z = torch.randn((imgs.size(0), args.latent_dim), dtype=torch.float32) - # Configure input - real_imgs = imgs.to(args.loc, non_blocking=True).to(torch.float) - valid = valid.to(args.loc, non_blocking=True).to(torch.float) - fake = fake.to(args.loc, non_blocking=True).to(torch.float) - z = z.to(args.loc, non_blocking=True).to(torch.float) - - # update D - discriminator.zero_grad() - output = discriminator(real_imgs) - errD_real = loss(output, valid) - with amp.scale_loss(errD_real, optimizer_D, loss_id=0) as errD_real_scaled: - errD_real_scaled.backward() - - gen_imgs = generator(z) - output = discriminator(gen_imgs.detach()) - errD_fake = loss(output, fake) - with amp.scale_loss(errD_fake, optimizer_D, loss_id=1) as errD_fake_scaled: - errD_fake_scaled.backward() - errD = errD_real + errD_fake - optimizer_D.step() - - # update G - generator.zero_grad() - output = discriminator(gen_imgs) - errG = loss(output, valid) - with amp.scale_loss(errG, optimizer_G, loss_id=2) as errG_scaled: - errG_scaled.backward() - optimizer_G.step() - - D_loss.update(errD.item(), real_imgs.size(0)) - D_fake.update(errD_fake.item(), real_imgs.size(0)) - D_real.update(errD_real.item(), real_imgs.size(0)) - G_loss.update(errG.item(), real_imgs.size(0)) - - # measure elapsed time - cost_time = time.time() - end - batch_time.update(cost_time) - end = time.time() - - if not args.distributed or (args.distributed and args.gpu == args.process_device_map[0]): - if i % args.print_freq == 0: - progress.display(i) - - batches_done = epoch * len(train_loader) + i - if batches_done % args.sample_interval == 0: - save_image(gen_imgs.data[:25], "images/%06d.png" % batches_done, nrow=5, normalize=True) - - if batch_time.avg: - print("[npu id:", args.gpu, "]", "batch_size:", args.world_size * args.batch_size, - 'Time: {:.3f}'.format(batch_time.avg), '* FPS@all {:.3f}'.format( - args.batch_size * args.world_size / batch_time.avg)) - # train loop done - - -def validate(generator, args): - batch_time = AverageMeter('Time', ':6.3f') - print("start generate random image...(validate mode)") - generator.eval() - - if not os.path.exists("./validate/"): - os.makedirs("validate") - end = time.time() - with torch.no_grad(): - for i in range(args.n_samples): - z = torch.randn((25, args.latent_dim), dtype=torch.float32) - z = z.to(args.loc, non_blocking=True) - # gen images - images = generator(z) - batch_time.update(time.time() - end) - end = time.time() - save_image(images.data[:25], "validate/%03d.jpg" % i, nrow=5, normalize=True) - if batch_time.avg: - print("[npu id:", args.gpu, "]", "batch_size:", 25, - 'Time: {:.3f}'.format(batch_time.avg), '* FPS@all {:.3f}'.format( - 25 / batch_time.avg)) - # train loop done - - -class AverageMeter(object): - """Computes and stores the average and current value""" - - def __init__(self, name, fmt=':f', start_count_index=2): - self.name = name - self.fmt = fmt - self.reset() - self.start_count_index = start_count_index - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - - def update(self, val, n=1): - if self.count == 0: - self.N = n - - self.val = val - self.count += n - if self.count > (self.start_count_index * self.N): - self.sum += val * n - self.avg = self.sum / (self.count - self.start_count_index * self.N) - - def __str__(self): - fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' - return fmtstr.format(**self.__dict__) - - -class ProgressMeter(object): - - def __init__(self, num_batches, meters, prefix=""): - self.batch_fmtstr = self._get_batch_fmtstr(num_batches) - self.meters = meters - self.prefix = prefix - - def display(self, batch): - entries = [self.prefix + self.batch_fmtstr.format(batch)] - entries += [str(meter) for meter in self.meters] - print('\t'.join(entries)) - - def _get_batch_fmtstr(self, num_batches): - num_digits = len(str(num_batches // 1)) - fmt = '{:' + str(num_digits) + 'd}' - return '[' + fmt + '/' + fmt.format(num_batches) + ']' - - -if __name__ == "__main__": - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import argparse +import os +import time +import apex +from apex import amp +import torch +import torch.nn as nn +import torch.nn.parallel +import torch.backends.cudnn as cudnn +import torch.distributed as dist +import torch.optim +import torch.utils.data +import torch.utils.data.distributed +import torchvision.transforms as transforms +import torchvision.datasets as datasets +from torchvision.utils import save_image + +from dcgan import Generator, Discriminator, weights_init_normal + +parser = argparse.ArgumentParser(description="pytorch DCGAN implementation") +## dcgan parameters +parser.add_argument('--data', metavar='DIR', type=str, default="./data", + help='path to dataset') +parser.add_argument("--n-epochs", type=int, default=200, + help="number of epochs of training") +parser.add_argument("--batch-size", type=int, default=64, + help="size of the batches") +parser.add_argument("--lr", type=float, default=0.0002, + help="adam: learning rate") +parser.add_argument("--b1", type=float, default=0.5, + help="adam: decay of first order momentum of gradient") +parser.add_argument("--b2", type=float, default=0.999, + help="adam: decay of first order momentum of gradient") +parser.add_argument("--n-cpu", type=int, default=8, + help="number of cpu threads to use during batch generation") +parser.add_argument("--latent_dim", type=int, default=100, + help="dimensionality of the latent space") +parser.add_argument("--img_size", type=int, default=32, + help="size of each image dimension") +parser.add_argument("--channels", type=int, default=1, + help="number of image channels") +parser.add_argument("--sample_interval", type=int, default=400, + help="interval between image sampling") +## add useful parameters : such as resume,evaluate +parser.add_argument('--checkpoint-path', default=None, type=str, metavar='PATH', + help='path to latest checkpoint (default: none)') +parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', default=False, + help='evaluate model : generate (n_samples) samples,saved in dir(validate)') +parser.add_argument('--n-samples', type=int, default=10, + help="amount of samples in function(validate)") +parser.add_argument('-p', '--print-freq', default=10, type=int, metavar='N', + help='print frequency (default 10)') +## parameters for distribute training +parser.add_argument('--world-size', default=-1, type=int, + help='number of nodes for distributed training') +parser.add_argument('--rank', default=-1, type=int, + help='node rank for distributed training') +parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str, + help='url used to set up distributed training') +parser.add_argument('--dist-backend', default='nccl', type=str, + help='distributed backend') +parser.add_argument('--gpu', default=None, type=int, + help='GPU id to use.') +## for ascend 910 +parser.add_argument('--device', default='npu', type=str, help='npu or gpu') +parser.add_argument('--addr', default='10.136.181.115', + type=str, help='master addr') +parser.add_argument('--device-list', default='0,1,2,3,4,5,6,7', + type=str, help='device id list') +parser.add_argument('--amp', default=False, action='store_true', + help='use amp to train the model') +parser.add_argument('--loss-scale', default=None, type=float, + help='loss scale using in amp, default None means dynamic') +parser.add_argument('--opt-level', default='O2', type=str, + help='loss scale using in amp, default -1 means dynamic') +parser.add_argument('--prof', default=False, action='store_true', + help='use profiling to evaluate the performance of model') + + +def device_id_to_process_device_map(device_list): + devices = device_list.split(",") + devices = [int(x) for x in devices] + devices.sort() + + process_device_map = dict() + for process_id, device_id in enumerate(devices): + process_device_map[process_id] = device_id + + return process_device_map + + +def get_device_name(device_type, device_order): + if device_type == 'npu': + device_name = 'npu:{}'.format(device_order) + else: + device_name = 'cuda:{}'.format(device_order) + + return device_name + + +def main(): + args = parser.parse_args() + print(args.device_list) + args.process_device_map = device_id_to_process_device_map(args.device_list) + + # add start_epoch + args.start_epoch = 0 + + os.environ['MASTER_ADDR'] = args.addr + os.environ['MASTER_PORT'] = '29688' + + if args.device == 'npu': + ngpus_per_node = len(args.process_device_map) + else: + if args.gpu is None: + ngpus_per_node = len(args.process_device_map) + else: + ngpus_per_node = 1 + print('ngpus_per_node:', ngpus_per_node) + + args.world_size = ngpus_per_node * args.world_size + args.distributed = args.world_size > 1 + + # create folders + if not args.distributed or (args.distributed and args.rank == args.process_device_map[0]): + if not os.path.exists("./images/"): + os.makedirs("./images/") + if not os.path.exists("./samples/"): + os.makedirs("./samples/") + + main_worker(args.rank, ngpus_per_node, args) + + +def main_worker(gpu, ngpus_per_node, args): + args.gpu = args.process_device_map[gpu] + if args.distributed: + if args.device == 'npu': + dist.init_process_group(backend=args.dist_backend, + # init_method=args.dist_url, + world_size=args.world_size, + rank=args.rank) + else: + dist.init_process_group(backend=args.dist_backend, + init_method=args.dist_url, + world_size=args.world_size, + rank=args.rank) + + print('rank: {} / {}'.format(args.rank, args.world_size)) + + # init device + device_loc = get_device_name(args.device, args.gpu) + args.loc = device_loc + + # set device + print('set_device ', device_loc) + if args.device == 'npu': + torch.npu.set_device(device_loc) + else: + torch.cuda.set_device(args.gpu) + + # create model + G = Generator(args.img_size, args.latent_dim, args.channels) + D = Discriminator(args.img_size, args.channels) + # initialize weights + G.apply(weights_init_normal) + D.apply(weights_init_normal) + if args.checkpoint_path: + print("=> using pre-trained model dcgan,device(%d)" % args.gpu) + print("loading model of yours...,device(%d)" % args.gpu) + checkpoint = torch.load(args.checkpoint_path, map_location="cpu") + G.load_state_dict({k.replace('module.', ''): v for k, v in checkpoint["G"].items()}) + D.load_state_dict({k.replace('module.', ''): v for k, v in checkpoint["D"].items()}) + else: + print("=> creating model dcgan,device(%d)" % args.gpu) + + print('model to device_loc(%s)...' % device_loc) + G = G.to(device_loc) + D = D.to(device_loc) + + if args.distributed: + args.batch_size = int(args.batch_size / args.world_size) + args.n_cpu = int((args.n_cpu + ngpus_per_node - 1) / ngpus_per_node) + args.sample_interval = int(args.sample_interval / ngpus_per_node) + + # define optimizer, apply apex + optimizer_G = apex.optimizers.NpuFusedAdam(G.parameters(), lr=args.lr, betas=(args.b1, args.b2)) + optimizer_D = apex.optimizers.NpuFusedAdam(D.parameters(), lr=args.lr, betas=(args.b1, args.b2)) + + if args.amp: + [D, G], [optimizer_D, optimizer_G] = amp.initialize( + [D, G], [optimizer_D, optimizer_G], opt_level=args.opt_level, loss_scale=args.loss_scale, num_losses=3, + combine_grad=True) + + if args.evaluate: + print("evaluate mode...", " device(%d)," % args.gpu) + validate(G, args) + return + + if args.checkpoint_path: + args.start_epoch = checkpoint['epoch'] + optimizer_G.load_state_dict(checkpoint['optimizer_G']) + optimizer_D.load_state_dict(checkpoint['optimizer_D']) + if args.amp: + amp.load_state_dict(checkpoint['amp']) + print("=> loaded checkpoint '{}' (epoch {})".format(args.resume, checkpoint['epoch'])) + + if args.distributed: + G = torch.nn.parallel.DistributedDataParallel(G, device_ids=[args.gpu], broadcast_buffers=False) + D = torch.nn.parallel.DistributedDataParallel(D, device_ids=[args.gpu], broadcast_buffers=False) + + # Loss function + adversarial_loss = nn.BCEWithLogitsLoss().to(device_loc) + + cudnn.benchmark = True + + # Data loading code + data_path = args.data + print("dataset path : %s" % data_path) + train_dataset = datasets.MNIST( + data_path, + train=True, + download=False, + transform=transforms.Compose( + [transforms.Resize(args.img_size), transforms.ToTensor(), transforms.Normalize([0.5], [0.5])] + )) + + if args.distributed: + train_sampler = torch.utils.data.distributed.DistributedSampler( + train_dataset) + else: + train_sampler = None + + train_loader = torch.utils.data.DataLoader( + train_dataset, batch_size=args.batch_size, shuffle=(train_sampler is None), + num_workers=args.n_cpu, pin_memory=False, sampler=train_sampler, drop_last=True) + + if args.prof: + print("profiling mode...", " device(%d)," % args.gpu) + profiling(train_loader, G, D, optimizer_G, optimizer_D, adversarial_loss, args) + return + + # start training + print("train mode...", " device(%d)," % args.gpu) + fixed_z = torch.randn((5, args.latent_dim), dtype=torch.float32) + # Configure input + fixed_z = fixed_z.to(device_loc, non_blocking=True).to(torch.float) + for epoch in range(args.start_epoch, args.n_epochs): + if args.distributed: + train_sampler.set_epoch(epoch) + # train for one epoch + train(train_loader, + G, D, + optimizer_G, optimizer_D, + adversarial_loss, + epoch, args, + ngpus_per_node) + + if not args.distributed or (args.distributed and args.gpu == args.process_device_map[0]): + # save fixed imgs + G.eval() + fixed_imgs = G(fixed_z) + save_image(fixed_imgs[:5], "samples/fixed_images-epoch_%03d.png" % epoch, nrow=5, normalize=True) + ############## npu modify begin ############# + if args.amp: + torch.save({ + 'epoch': epoch + 1, + 'arch': 'dcgan', + 'G': G.state_dict(), + 'D': D.state_dict(), + 'optimizer_G': optimizer_G.state_dict(), + 'optimizer_D': optimizer_D.state_dict(), + 'amp': amp.state_dict(), + }, "checkpoint-amp-epoch_%d.pth" % (epoch + 1)) + + if os.path.exists("checkpoint-amp-epoch_%d.pth" % epoch): + os.remove("checkpoint-amp-epoch_%d.pth" % epoch) + else: + torch.save({ + 'epoch': epoch + 1, + 'arch': 'dcgan', + 'G': G.state_dict(), + 'D': D.state_dict(), + 'optimizer_G': optimizer_G.state_dict(), + 'optimizer_D': optimizer_D.state_dict(), + }, "checkpoint-epoch_%d.pth" % (epoch + 1)) + if os.path.exists("checkpoint-epoch_%d.pth" % epoch): + os.remove("checkpoint-epoch_%d.pth" % epoch) + ############## npu modify end ############# + # train loop done + + +def profiling(train_loader, generator, discriminator, optimizer_G, optimizer_D, loss, args): + generator.train() + discriminator.train() + + def update(step=None): + start_time = time.time() + valid = torch.ones(imgs.size(0), 1, requires_grad=False) + fake = torch.zeros(imgs.size(0), 1, requires_grad=False) + # Sample noise as generator input + z = torch.randn((imgs.size(0), args.latent_dim), dtype=torch.float32) + # Configure input + real_imgs = imgs.to(args.loc, non_blocking=True).to(torch.float) + valid = valid.to(args.loc, non_blocking=True).to(torch.float) + fake = fake.to(args.loc, non_blocking=True).to(torch.float) + z = z.to(args.loc, non_blocking=True).to(torch.float) + # update D + discriminator.zero_grad() + output = discriminator(real_imgs) + errD_real = loss(output, valid) + with amp.scale_loss(errD_real, optimizer_D, loss_id=0) as errD_real_scaled: + errD_real_scaled.backward() + gen_imgs = generator(z) + output = discriminator(gen_imgs.detach()) + errD_fake = loss(output, fake) + with amp.scale_loss(errD_fake, optimizer_D, loss_id=1) as errD_fake_scaled: + errD_fake_scaled.backward() + errD = errD_real + errD_fake + optimizer_D.step() + # update G + generator.zero_grad() + output = discriminator(gen_imgs) + errG = loss(output, valid) + with amp.scale_loss(errG, optimizer_G, loss_id=2) as errG_scaled: + errG_scaled.backward() + optimizer_G.step() + if step is not None: + print('iter: %d, loss: %.2f, time: %.2f' % (step, errG.item(), (time.time() - start_time))) + + for i, (imgs, _) in enumerate(train_loader): + if i < 20: + update(step=i) + else: + if args.device == 'npu': + with torch.autograd.profiler.profile(use_npu=True) as prof: + update() + else: + with torch.autograd.profiler.profile(use_cuda=True) as prof: + update() + break + prof.export_chrome_trace("dcgan.prof") + + +def train(train_loader, generator, discriminator, optimizer_G, optimizer_D, loss, epoch, args, ngpus_per_node): + batch_time = AverageMeter('Time', ':6.3f') + data_time = AverageMeter('Data', ':6.3f') + G_loss = AverageMeter('G_Loss', ':.4e') + D_loss = AverageMeter('D_Loss', ':.4e') + D_real = AverageMeter('D_real', ':.4e') + D_fake = AverageMeter('D_fake', ':.4e') + progress = ProgressMeter( + len(train_loader), + [batch_time, data_time, G_loss, D_loss, D_real, D_fake], + prefix="Epoch: [{}]".format(epoch)) + + # switch to train mode + generator.train() + discriminator.train() + + end = time.time() + for i, (imgs, _) in enumerate(train_loader): + # measure data loading time + data_time.update(time.time() - end) + + valid = torch.ones(imgs.size(0), 1, requires_grad=False) + fake = torch.zeros(imgs.size(0), 1, requires_grad=False) + # Sample noise as generator input + z = torch.randn((imgs.size(0), args.latent_dim), dtype=torch.float32) + # Configure input + real_imgs = imgs.to(args.loc, non_blocking=True).to(torch.float) + valid = valid.to(args.loc, non_blocking=True).to(torch.float) + fake = fake.to(args.loc, non_blocking=True).to(torch.float) + z = z.to(args.loc, non_blocking=True).to(torch.float) + + # update D + discriminator.zero_grad() + output = discriminator(real_imgs) + errD_real = loss(output, valid) + with amp.scale_loss(errD_real, optimizer_D, loss_id=0) as errD_real_scaled: + errD_real_scaled.backward() + + gen_imgs = generator(z) + output = discriminator(gen_imgs.detach()) + errD_fake = loss(output, fake) + with amp.scale_loss(errD_fake, optimizer_D, loss_id=1) as errD_fake_scaled: + errD_fake_scaled.backward() + errD = errD_real + errD_fake + optimizer_D.step() + + # update G + generator.zero_grad() + output = discriminator(gen_imgs) + errG = loss(output, valid) + with amp.scale_loss(errG, optimizer_G, loss_id=2) as errG_scaled: + errG_scaled.backward() + optimizer_G.step() + + D_loss.update(errD.item(), real_imgs.size(0)) + D_fake.update(errD_fake.item(), real_imgs.size(0)) + D_real.update(errD_real.item(), real_imgs.size(0)) + G_loss.update(errG.item(), real_imgs.size(0)) + + # measure elapsed time + cost_time = time.time() - end + batch_time.update(cost_time) + end = time.time() + + if not args.distributed or (args.distributed and args.gpu == args.process_device_map[0]): + if i % args.print_freq == 0: + progress.display(i) + + batches_done = epoch * len(train_loader) + i + if batches_done % args.sample_interval == 0: + save_image(gen_imgs.data[:25], "images/%06d.png" % batches_done, nrow=5, normalize=True) + + if batch_time.avg: + print("[npu id:", args.gpu, "]", "batch_size:", args.world_size * args.batch_size, + 'Time: {:.3f}'.format(batch_time.avg), '* FPS@all {:.3f}'.format( + args.batch_size * args.world_size / batch_time.avg)) + # train loop done + + +def validate(generator, args): + batch_time = AverageMeter('Time', ':6.3f') + print("start generate random image...(validate mode)") + generator.eval() + + if not os.path.exists("./validate/"): + os.makedirs("validate") + end = time.time() + with torch.no_grad(): + for i in range(args.n_samples): + z = torch.randn((25, args.latent_dim), dtype=torch.float32) + z = z.to(args.loc, non_blocking=True) + # gen images + images = generator(z) + batch_time.update(time.time() - end) + end = time.time() + save_image(images.data[:25], "validate/%03d.jpg" % i, nrow=5, normalize=True) + if batch_time.avg: + print("[npu id:", args.gpu, "]", "batch_size:", 25, + 'Time: {:.3f}'.format(batch_time.avg), '* FPS@all {:.3f}'.format( + 25 / batch_time.avg)) + # train loop done + + +class AverageMeter(object): + """Computes and stores the average and current value""" + + def __init__(self, name, fmt=':f', start_count_index=2): + self.name = name + self.fmt = fmt + self.reset() + self.start_count_index = start_count_index + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + if self.count == 0: + self.N = n + + self.val = val + self.count += n + if self.count > (self.start_count_index * self.N): + self.sum += val * n + self.avg = self.sum / (self.count - self.start_count_index * self.N) + + def __str__(self): + fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' + return fmtstr.format(**self.__dict__) + + +class ProgressMeter(object): + + def __init__(self, num_batches, meters, prefix=""): + self.batch_fmtstr = self._get_batch_fmtstr(num_batches) + self.meters = meters + self.prefix = prefix + + def display(self, batch): + entries = [self.prefix + self.batch_fmtstr.format(batch)] + entries += [str(meter) for meter in self.meters] + print('\t'.join(entries)) + + def _get_batch_fmtstr(self, num_batches): + num_digits = len(str(num_batches // 1)) + fmt = '{:' + str(num_digits) + 'd}' + return '[' + fmt + '/' + fmt.format(num_batches) + ']' + + +if __name__ == "__main__": + main() diff --git a/PyTorch/contrib/cv/others/DCGAN/modelzoo_level.txt b/PyTorch/contrib/cv/others/DCGAN/modelzoo_level.txt index 405b26618a0c92027927a9c583a4b47f640bcf7b..c45626e398eabe6022fe7b2e148f0ffce6400d6e 100644 --- a/PyTorch/contrib/cv/others/DCGAN/modelzoo_level.txt +++ b/PyTorch/contrib/cv/others/DCGAN/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:POK +FuncStatus:OK +PerfStatus:POK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/DCGAN/requirements.txt b/PyTorch/contrib/cv/others/DCGAN/requirements.txt index dd1af6e127fb102fc10d031b41231ea42cff0387..ea5a8512c14e2f7cdbf5a5b0b46f485f1a032afc 100644 --- a/PyTorch/contrib/cv/others/DCGAN/requirements.txt +++ b/PyTorch/contrib/cv/others/DCGAN/requirements.txt @@ -1,3 +1,3 @@ -torch -apex +torch +apex torchvision \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/GAN_Pytorch/Dockerfile b/PyTorch/contrib/cv/others/GAN_Pytorch/Dockerfile index 7e712fe1a166790798f57a2f2762c47394beb625..30a31af55804dd79571d2a36e6107a844cb7e549 100644 --- a/PyTorch/contrib/cv/others/GAN_Pytorch/Dockerfile +++ b/PyTorch/contrib/cv/others/GAN_Pytorch/Dockerfile @@ -1,5 +1,5 @@ -ARG FROM_IMAGE_NAME -FROM $FROM_IMAGE_NAME - -COPY requirements.txt . +ARG FROM_IMAGE_NAME +FROM $FROM_IMAGE_NAME + +COPY requirements.txt . RUN pip3.7 install -r requirements.txt \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/GAN_Pytorch/README.md b/PyTorch/contrib/cv/others/GAN_Pytorch/README.md index 96151c3e2174db8b1ca7fb5c1813ded4b0930bb7..be1d95ec6e43049d93d20d7716bd64dfd7a22fb5 100644 --- a/PyTorch/contrib/cv/others/GAN_Pytorch/README.md +++ b/PyTorch/contrib/cv/others/GAN_Pytorch/README.md @@ -1,46 +1,46 @@ -# GAN 训练 -This implements training of RDN on the DIV2K_x2 dataset. -- Reference implementation: -``` -url=https://github.com/eriklindernoren/PyTorch-GAN/blob/master/implementations/gan/gan.py -``` - - - -## Requirements # - -- Install PyTorch ([pytorch.org](http://pytorch.org)) -- `pip install -r requirements.txt` -- The MNIST Dataset can be downloaded from the links below.Move the datasets to directory ./data . - - Train Set : [Download Mnist](https://wwr.lanzoui.com/iSBOeu43dkf) - -## Training # -To train a model, change the working directory to `./test`,then run: - -```bash -# 1p train perf -bash train_performance_1p.sh - -# 8p train perf -bash train_performance_8p.sh - -# 8p train full -bash train_full_8p.sh - -# 8p eval -bash train_eval_8p.sh - -# finetuning -bash train_finetune_1p.sh -``` -After running,you can see the results in `./output` - -## GAN training result # - -| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | -| :------: | :------: | :------: | :------: | :------: | -| - | 997 | 1 | 200 | O1 | -| - | 11795 | 8 | 200 | O1 | - - - +# GAN 训练 +This implements training of RDN on the DIV2K_x2 dataset. +- Reference implementation: +``` +url=https://github.com/eriklindernoren/PyTorch-GAN/blob/master/implementations/gan/gan.py +``` + + + +## Requirements # + +- Install PyTorch ([pytorch.org](http://pytorch.org)) +- `pip install -r requirements.txt` +- The MNIST Dataset can be downloaded from the links below.Move the datasets to directory ./data . + - Train Set : [Download Mnist](https://wwr.lanzoui.com/iSBOeu43dkf) + +## Training # +To train a model, change the working directory to `./test`,then run: + +```bash +# 1p train perf +bash train_performance_1p.sh + +# 8p train perf +bash train_performance_8p.sh + +# 8p train full +bash train_full_8p.sh + +# 8p eval +bash train_eval_8p.sh + +# finetuning +bash train_finetune_1p.sh +``` +After running,you can see the results in `./output` + +## GAN training result # + +| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | +| :------: | :------: | :------: | :------: | :------: | +| - | 997 | 1 | 200 | O1 | +| - | 11795 | 8 | 200 | O1 | + + + diff --git a/PyTorch/contrib/cv/others/GAN_Pytorch/docker_start.sh b/PyTorch/contrib/cv/others/GAN_Pytorch/docker_start.sh index 46ce9a02ec0532d6db324beaee7f7eab501b4565..944bca3cdac8e3f2d47ceb0e2b6eb181a405de11 100644 --- a/PyTorch/contrib/cv/others/GAN_Pytorch/docker_start.sh +++ b/PyTorch/contrib/cv/others/GAN_Pytorch/docker_start.sh @@ -1,25 +1,25 @@ -#!/bin/bash - -docker_image=$1 -data_dir=$2 -model_dir=$3 - -docker run -it --ipc=host \ - --device=/dev/davinci0 \ - --device=/dev/davinci1 \ - --device=/dev/davinci2 \ - --device=/dev/davinci3 \ - --device=/dev/davinci4 \ - --device=/dev/davinci5 \ - --device=/dev/davinci6 \ - --device=/dev/davinci7 \ - --device=/dev/davinci_manager \ - --device=/dev/devmm_svm --device=/dev/hisi_hdc \ - -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ - -v /usr/local/Ascend/add-ons/:/usr/local/Ascend/add-ons/ \ - -v ${model_dir}:${model_dir} \ - -v ${data_dir}:${data_dir} \ - -v /var/log/npu/conf/slog/slog.conf:/var/log/npu/conf/slog/slog.conf \ - -v /var/log/npu/slog/:/var/log/npu/slog -v /var/log/npu/profiling/:/var/log/npu/profiling \ - -v /var/log/npu/dump/:/var/log/npu/dump -v /var/log/npu/:/usr/slog ${docker_image} \ +#!/bin/bash + +docker_image=$1 +data_dir=$2 +model_dir=$3 + +docker run -it --ipc=host \ + --device=/dev/davinci0 \ + --device=/dev/davinci1 \ + --device=/dev/davinci2 \ + --device=/dev/davinci3 \ + --device=/dev/davinci4 \ + --device=/dev/davinci5 \ + --device=/dev/davinci6 \ + --device=/dev/davinci7 \ + --device=/dev/davinci_manager \ + --device=/dev/devmm_svm --device=/dev/hisi_hdc \ + -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ + -v /usr/local/Ascend/add-ons/:/usr/local/Ascend/add-ons/ \ + -v ${model_dir}:${model_dir} \ + -v ${data_dir}:${data_dir} \ + -v /var/log/npu/conf/slog/slog.conf:/var/log/npu/conf/slog/slog.conf \ + -v /var/log/npu/slog/:/var/log/npu/slog -v /var/log/npu/profiling/:/var/log/npu/profiling \ + -v /var/log/npu/dump/:/var/log/npu/dump -v /var/log/npu/:/usr/slog ${docker_image} \ /bin/bash \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/GAN_Pytorch/main.py b/PyTorch/contrib/cv/others/GAN_Pytorch/main.py index 87b96cdccb4ff7e9a845418bd5f1632bd2c33c53..892cbad98135c15dc82a2db870f15d12590ceafa 100644 --- a/PyTorch/contrib/cv/others/GAN_Pytorch/main.py +++ b/PyTorch/contrib/cv/others/GAN_Pytorch/main.py @@ -1,387 +1,387 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import argparse -import os -import sys -import numpy as np -import time -import matplotlib.pyplot as plt -import datetime - -import torchvision.transforms as transforms -from torchvision.utils import save_image -from torchvision import datasets - -import torch -from torch.autograd import Variable -import torch.nn as nn -import torch.multiprocessing as mp -from torch.nn.parallel import DistributedDataParallel as DDP -from torch.utils.data import DataLoader - -from models import Generator, Discriminator - -try: - import apex - from apex import amp -except ImportError: - amp = None - -def flush_print(func): - def new_print(*args, **kwargs): - func(*args, **kwargs) - sys.stdout.flush() - return new_print - -print = flush_print(print) - - -def train_one_epoch(generator, discriminator, optimizer_G, optimizer_D, adversarial_loss, - epoch, args, dataloader, Tensor,LOSS_G,LOSS_D,device): - batch_time = AverageMeter('Time', ':6.3f', start_count_index=5) - G_loss = AverageMeter('g_loss', ':6.3f', start_count_index=0) - D_loss = AverageMeter('d_loss', ':6. 3f', start_count_index=0) - - for i, (imgs,_) in enumerate(dataloader): - - start_time = time.time() - valid = Variable(Tensor(imgs.size(0), 1).fill_(1.0), requires_grad=False) - fake = Variable(Tensor(imgs.size(0), 1).fill_(0.0), requires_grad=False) - - # Configure input - real_imgs = Variable(imgs.type(Tensor)).to(device) - - # ----------------- - # Train Generator - # ----------------- - - optimizer_G.zero_grad() - - # Sample noise as generator input - z = Variable(Tensor(np.random.normal(0, 1, (imgs.shape[0], args.latent_dim)))).to(device) - - # Generate a batch of images - gen_imgs = generator(z) - - # Loss measures generator's ability to fool the discriminator - g_loss = adversarial_loss(discriminator(gen_imgs), valid) - - G_loss.update(g_loss.item(), len(gen_imgs)) - if args.apex: - with amp.scale_loss(g_loss, optimizer_G) as scaled_loss: - scaled_loss.backward() - else: - G_loss.backward() - optimizer_G.step() - - # --------------------- - # Train Discriminator - # --------------------- - - optimizer_D.zero_grad() - - # Measure discriminator's ability to classify real from generated samples - real_loss = adversarial_loss(discriminator(real_imgs), valid) - fake_loss = adversarial_loss(discriminator(gen_imgs.detach()), fake) - d_loss = (real_loss + fake_loss) / 2 - - D_loss.update(d_loss.item(), len(real_imgs)) - if args.apex: - with amp.scale_loss(d_loss, optimizer_D) as scaled_loss: - scaled_loss.backward() - else: - d_loss.backward() - optimizer_D.step() - batch_time.update(time.time() - start_time) - if args.n_epochs == 1: - print( - "[Epoch %d] [step %d] [D loss: %f] [G loss: %f]" - % (epoch, i, D_loss.avg, G_loss.avg) - ) - batches_done = epoch * len(dataloader)+ i - if batches_done % args.sample_interval == 0 and args.is_master_node and args.n_epochs != 1: - save_image(gen_imgs.data[:25], "training_images/%d.png" % batches_done, nrow=5, normalize=True) - if args.is_master_node: - print( - "[Epoch %d] [D loss: %f] [G loss: %f] FPS:%.3f" - % (epoch, D_loss.avg,G_loss.avg,args.batch_size*args.gpus/batch_time.avg) - ) - LOSS_G.append(G_loss.avg) - LOSS_D.append(D_loss.avg) - - - -def main(args): - - os.environ['MASTER_ADDR'] = args.addr - os.environ['MASTER_PORT'] = '29688' - - if args.apex: - if sys.version_info < (3, 0): - raise RuntimeError("Apex currently only supports Python 3. Aborting.") - if amp is None: - raise RuntimeError("Failed to import apex. Please install apex from https://www.github.com/nvidia/apex " - "to enable mixed-precision training.") - # if args.output_dir: - # os.mkdir(args.output_dir) - - if args.distributed: - - mp.spawn(main_worker, nprocs=args.gpus, - args=(args,)) - else: - main_worker(args.gpus, args) - -def main_worker(nprocs, args): - local_rank = 0 - if args.distributed: - torch.distributed.init_process_group(backend="hccl", - init_method='env://', - world_size=args.nodes * args.gpus, - rank=nprocs) - local_rank = torch.distributed.get_rank() - args.is_master_node = not args.distributed or local_rank == 0 - if args.is_master_node: - print(args) - args.device_id = args.device_id + local_rank - print('device_id=', args.device_id) - device = torch.device(f'npu:{args.device_id}') # npu - torch.npu.set_device(device) # for npu - print("Downloading dataset...") - # Configure data loader - os.makedirs("../data/mnist", exist_ok=True) - train_dataset = datasets.MNIST( - "../../data/mnist", - train=True, - download=True, - transform=transforms.Compose( - [transforms.Resize(args.img_size), transforms.ToTensor(), transforms.Normalize([0.5], [0.5])] - )) - - print("Creating dataloader") - - if args.distributed: - train_sampler = torch.utils.data.distributed.DistributedSampler( - train_dataset) - else: - train_sampler = None - dataloader = torch.utils.data.DataLoader( - train_dataset, batch_size=args.batch_size, shuffle=( - train_sampler is None), - num_workers=args.workers, pin_memory=True, sampler=train_sampler) - - if args.is_master_node: - print("Creating model") - # create model - Tensor = torch.npu.FloatTensor - LOSS_G=[] - LOSS_D=[] - os.makedirs("../output", exist_ok=True) - os.chdir("../output") - generator = Generator() - discriminator = Discriminator() - if args.pretrained: - print("=> using pre-trained model GAN") - generator = Generator() - discriminator = Discriminator() - print("loading model of yours...") - checkpoint = torch.load(r'./checkpoint.pth.tar',map_location='cpu') - from collections import OrderedDict - new_state_dict_g = OrderedDict() - new_state_dict_d = OrderedDict() - for k, v in checkpoint['state_dict_G'].items(): - name = k.replace("module.", "") # remove `module.` - new_state_dict_g[name] = v - for k, v in checkpoint['state_dict_D'].items(): - name = k.replace("module.", "") # remove `module.` - new_state_dict_d[name] = v - # load params - generator.load_state_dict(new_state_dict_g) - discriminator.load_state_dict(new_state_dict_d) - LOSS_D = checkpoint['loss_d'] - LOSS_G = checkpoint['loss_g'] - args.start_epoch = checkpoint['epoch'] - - generator = generator.to(device) - discriminator = discriminator.to(device) - - adversarial_loss = nn.BCELoss().to(device) - - optimizer_G = apex.optimizers.NpuFusedAdam(generator.parameters(), lr=args.lr, betas=(args.b1, args.b2)) - optimizer_D = apex.optimizers.NpuFusedAdam(discriminator.parameters(), lr=args.lr, betas=(args.b1, args.b2)) - - if args.apex: - amp.register_float_function(torch, 'sigmoid') - amp.register_half_function(torch, 'addmm') - generator, optimizer_G = amp.initialize(generator, optimizer_G, - opt_level='O1', loss_scale=128,combine_grad=True) - - discriminator, optimizer_D = amp.initialize(discriminator, optimizer_D, - opt_level='O1', loss_scale=128,combine_grad=True) - - if args.distributed: - generator = DDP(generator, device_ids=[local_rank], broadcast_buffers=False) - discriminator = DDP(discriminator, device_ids=[local_rank], broadcast_buffers=False) - - if args.test_only : - Tensor = torch.npu.FloatTensor - generator = Generator().npu() - checkpoint = torch.load(r'./checkpoint.pth.tar', map_location='cpu') - - loss_d = checkpoint['loss_d'] - loss_g = checkpoint['loss_g'] - x = range(len(loss_d)) - plt.figure() - - plt.plot(x, loss_d, color='r', label="loss_d") - plt.plot(x, loss_g, color='g', label="loss_g") - plt.legend() - plt.xlabel('epoch') - plt.ylabel('value') - plt.savefig('LOSS_{}p_{}_{}.jpg'.format(args.gpus, args.lr, args.batch_size)) - - # create new OrderedDict that does not contain `module.` - from collections import OrderedDict - new_state_dict = OrderedDict() - for k, v in checkpoint['state_dict_G'].items(): - name = k.replace("module.", "") # remove `module.` - new_state_dict[name] = v - # load params - generator.load_state_dict(new_state_dict) - os.makedirs("image", exist_ok=True) - for i in range(200): - z = Variable(Tensor(np.random.normal(0, 1, (64, 100)))).npu() - - # Generate a batch of images - gen_imgs = generator(z) - - save_image(gen_imgs.data[:25], "image/%d.png" % i, nrow=5, normalize=True) - print("Generate done!") - return - - if args.is_master_node: - print("Start training") - start_time = time.time() - os.makedirs("training_images",exist_ok=True) - for epoch in range(args.start_epoch, args.n_epochs): - if args.distributed: - train_sampler.set_epoch(epoch) - - # train for one epoch - train_one_epoch(generator, discriminator, optimizer_G, optimizer_D, adversarial_loss, - epoch, args, dataloader,Tensor, LOSS_G,LOSS_D,device) - - if epoch == 50 or epoch == 199: - if args.apex and args.is_master_node: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': 'GAN', - 'state_dict_G': generator.state_dict(), - 'state_dict_D': discriminator.state_dict(), - 'optimizer_G': optimizer_G.state_dict(), - 'optimizer_D': optimizer_D.state_dict(), - 'loss_g': LOSS_G, - 'loss_d': LOSS_D, - 'apex': amp.state_dict() - }) - elif args.is_master_node: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': 'GAN', - 'state_dict_G': generator.state_dict(), - 'state_dict_D': discriminator.state_dict(), - 'optimizer_G': optimizer_G.state_dict(), - 'optimizer_D': optimizer_D.state_dict(), - 'loss_g': LOSS_G, - 'loss_d': LOSS_D - }) - total_time = time.time() - start_time - total_time_str = str(datetime.timedelta(seconds=int(total_time))) - if args.is_master_node: - print('Training time {}'.format(total_time_str)) - -def save_checkpoint(state, filename='./checkpoint.pth.tar'): - torch.save(state, filename) - - -class AverageMeter(object): - """Computes and stores the average and current value""" - - def __init__(self, name, fmt=':f', start_count_index=10): - self.name = name - self.fmt = fmt - self.reset() - self.start_count_index = start_count_index - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - - def update(self, val, n=1): - if self.count == 0: - self.N = n - - self.val = val - self.count += n - if self.count > (self.start_count_index * self.N): - self.sum += val * n - self.avg = self.sum / (self.count - self.start_count_index * self.N) - - def __str__(self): - fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' - return fmtstr.format(**self.__dict__) - -def parse_args(): - parser = argparse.ArgumentParser(description='PyTorch GAN Training') - parser.add_argument("--n_epochs", type=int, default=200, help="number of epochs of training") - parser.add_argument("--batch_size", type=int, default=128, help="size of the batches") - parser.add_argument("--lr", type=float, default=0.0008, help="adam: learning rate") - parser.add_argument("--b1", type=float, default=0.5, help="adam: decay of first order momentum of gradient") - parser.add_argument("--b2", type=float, default=0.999, help="adam: decay of first order momentum of gradient") - parser.add_argument("--sample_interval", type=int, default=400, help="interval betwen image samples") - parser.add_argument("--latent_dim", type=int, default=100, help="dimensionality of the latent space") - parser.add_argument("--img_size", type=int, default=28, help="size of each image dimension") - parser.add_argument("--channels", type=int, default=1, help="number of image channels") - parser.add_argument("--gpus", type=int, default=8, help="num of gpus of per node") - parser.add_argument("--nodes", type=int, default=1) - parser.add_argument('--device_id', default=0, type=int, help='device id') - parser.add_argument("--test_only", type=int, default=None, help="only generate images") - parser.add_argument('--start_epoch', default=0, type=int, metavar='N', - help='manual epoch number (useful on restarts)') - parser.add_argument('--resume', default='', type=str, metavar='PATH', - help='path to latest checkpoint (default: none)') - parser.add_argument('--pretrained', dest='pretrained', action='store_true', - help='use pre-trained model') - - parser.add_argument('--distributed', action='store_true', - help='Use multi-processing distributed training to launch ' - 'N processes per node, which has N GPUs. This is the ' - 'fastest way to use PyTorch for either single node or ' - 'multi node data parallel training') - ## for ascend 910 - parser.add_argument('--addr', default='127.0.0.1', - type=str, help='master addr') - parser.add_argument('--workers', default=16, type=int, - help='numbers of worker') - parser.add_argument('--apex', default=False, action='store_true', - help='use apex to train the model') - args = parser.parse_args() - return args -if __name__ == '__main__': - args = parse_args() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import argparse +import os +import sys +import numpy as np +import time +import matplotlib.pyplot as plt +import datetime + +import torchvision.transforms as transforms +from torchvision.utils import save_image +from torchvision import datasets + +import torch +from torch.autograd import Variable +import torch.nn as nn +import torch.multiprocessing as mp +from torch.nn.parallel import DistributedDataParallel as DDP +from torch.utils.data import DataLoader + +from models import Generator, Discriminator + +try: + import apex + from apex import amp +except ImportError: + amp = None + +def flush_print(func): + def new_print(*args, **kwargs): + func(*args, **kwargs) + sys.stdout.flush() + return new_print + +print = flush_print(print) + + +def train_one_epoch(generator, discriminator, optimizer_G, optimizer_D, adversarial_loss, + epoch, args, dataloader, Tensor,LOSS_G,LOSS_D,device): + batch_time = AverageMeter('Time', ':6.3f', start_count_index=5) + G_loss = AverageMeter('g_loss', ':6.3f', start_count_index=0) + D_loss = AverageMeter('d_loss', ':6. 3f', start_count_index=0) + + for i, (imgs,_) in enumerate(dataloader): + + start_time = time.time() + valid = Variable(Tensor(imgs.size(0), 1).fill_(1.0), requires_grad=False) + fake = Variable(Tensor(imgs.size(0), 1).fill_(0.0), requires_grad=False) + + # Configure input + real_imgs = Variable(imgs.type(Tensor)).to(device) + + # ----------------- + # Train Generator + # ----------------- + + optimizer_G.zero_grad() + + # Sample noise as generator input + z = Variable(Tensor(np.random.normal(0, 1, (imgs.shape[0], args.latent_dim)))).to(device) + + # Generate a batch of images + gen_imgs = generator(z) + + # Loss measures generator's ability to fool the discriminator + g_loss = adversarial_loss(discriminator(gen_imgs), valid) + + G_loss.update(g_loss.item(), len(gen_imgs)) + if args.apex: + with amp.scale_loss(g_loss, optimizer_G) as scaled_loss: + scaled_loss.backward() + else: + G_loss.backward() + optimizer_G.step() + + # --------------------- + # Train Discriminator + # --------------------- + + optimizer_D.zero_grad() + + # Measure discriminator's ability to classify real from generated samples + real_loss = adversarial_loss(discriminator(real_imgs), valid) + fake_loss = adversarial_loss(discriminator(gen_imgs.detach()), fake) + d_loss = (real_loss + fake_loss) / 2 + + D_loss.update(d_loss.item(), len(real_imgs)) + if args.apex: + with amp.scale_loss(d_loss, optimizer_D) as scaled_loss: + scaled_loss.backward() + else: + d_loss.backward() + optimizer_D.step() + batch_time.update(time.time() - start_time) + if args.n_epochs == 1: + print( + "[Epoch %d] [step %d] [D loss: %f] [G loss: %f]" + % (epoch, i, D_loss.avg, G_loss.avg) + ) + batches_done = epoch * len(dataloader)+ i + if batches_done % args.sample_interval == 0 and args.is_master_node and args.n_epochs != 1: + save_image(gen_imgs.data[:25], "training_images/%d.png" % batches_done, nrow=5, normalize=True) + if args.is_master_node: + print( + "[Epoch %d] [D loss: %f] [G loss: %f] FPS:%.3f" + % (epoch, D_loss.avg,G_loss.avg,args.batch_size*args.gpus/batch_time.avg) + ) + LOSS_G.append(G_loss.avg) + LOSS_D.append(D_loss.avg) + + + +def main(args): + + os.environ['MASTER_ADDR'] = args.addr + os.environ['MASTER_PORT'] = '29688' + + if args.apex: + if sys.version_info < (3, 0): + raise RuntimeError("Apex currently only supports Python 3. Aborting.") + if amp is None: + raise RuntimeError("Failed to import apex. Please install apex from https://www.github.com/nvidia/apex " + "to enable mixed-precision training.") + # if args.output_dir: + # os.mkdir(args.output_dir) + + if args.distributed: + + mp.spawn(main_worker, nprocs=args.gpus, + args=(args,)) + else: + main_worker(args.gpus, args) + +def main_worker(nprocs, args): + local_rank = 0 + if args.distributed: + torch.distributed.init_process_group(backend="hccl", + init_method='env://', + world_size=args.nodes * args.gpus, + rank=nprocs) + local_rank = torch.distributed.get_rank() + args.is_master_node = not args.distributed or local_rank == 0 + if args.is_master_node: + print(args) + args.device_id = args.device_id + local_rank + print('device_id=', args.device_id) + device = torch.device(f'npu:{args.device_id}') # npu + torch.npu.set_device(device) # for npu + print("Downloading dataset...") + # Configure data loader + os.makedirs("../data/mnist", exist_ok=True) + train_dataset = datasets.MNIST( + "../../data/mnist", + train=True, + download=True, + transform=transforms.Compose( + [transforms.Resize(args.img_size), transforms.ToTensor(), transforms.Normalize([0.5], [0.5])] + )) + + print("Creating dataloader") + + if args.distributed: + train_sampler = torch.utils.data.distributed.DistributedSampler( + train_dataset) + else: + train_sampler = None + dataloader = torch.utils.data.DataLoader( + train_dataset, batch_size=args.batch_size, shuffle=( + train_sampler is None), + num_workers=args.workers, pin_memory=True, sampler=train_sampler) + + if args.is_master_node: + print("Creating model") + # create model + Tensor = torch.npu.FloatTensor + LOSS_G=[] + LOSS_D=[] + os.makedirs("../output", exist_ok=True) + os.chdir("../output") + generator = Generator() + discriminator = Discriminator() + if args.pretrained: + print("=> using pre-trained model GAN") + generator = Generator() + discriminator = Discriminator() + print("loading model of yours...") + checkpoint = torch.load(r'./checkpoint.pth.tar',map_location='cpu') + from collections import OrderedDict + new_state_dict_g = OrderedDict() + new_state_dict_d = OrderedDict() + for k, v in checkpoint['state_dict_G'].items(): + name = k.replace("module.", "") # remove `module.` + new_state_dict_g[name] = v + for k, v in checkpoint['state_dict_D'].items(): + name = k.replace("module.", "") # remove `module.` + new_state_dict_d[name] = v + # load params + generator.load_state_dict(new_state_dict_g) + discriminator.load_state_dict(new_state_dict_d) + LOSS_D = checkpoint['loss_d'] + LOSS_G = checkpoint['loss_g'] + args.start_epoch = checkpoint['epoch'] + + generator = generator.to(device) + discriminator = discriminator.to(device) + + adversarial_loss = nn.BCELoss().to(device) + + optimizer_G = apex.optimizers.NpuFusedAdam(generator.parameters(), lr=args.lr, betas=(args.b1, args.b2)) + optimizer_D = apex.optimizers.NpuFusedAdam(discriminator.parameters(), lr=args.lr, betas=(args.b1, args.b2)) + + if args.apex: + amp.register_float_function(torch, 'sigmoid') + amp.register_half_function(torch, 'addmm') + generator, optimizer_G = amp.initialize(generator, optimizer_G, + opt_level='O1', loss_scale=128,combine_grad=True) + + discriminator, optimizer_D = amp.initialize(discriminator, optimizer_D, + opt_level='O1', loss_scale=128,combine_grad=True) + + if args.distributed: + generator = DDP(generator, device_ids=[local_rank], broadcast_buffers=False) + discriminator = DDP(discriminator, device_ids=[local_rank], broadcast_buffers=False) + + if args.test_only : + Tensor = torch.npu.FloatTensor + generator = Generator().npu() + checkpoint = torch.load(r'./checkpoint.pth.tar', map_location='cpu') + + loss_d = checkpoint['loss_d'] + loss_g = checkpoint['loss_g'] + x = range(len(loss_d)) + plt.figure() + + plt.plot(x, loss_d, color='r', label="loss_d") + plt.plot(x, loss_g, color='g', label="loss_g") + plt.legend() + plt.xlabel('epoch') + plt.ylabel('value') + plt.savefig('LOSS_{}p_{}_{}.jpg'.format(args.gpus, args.lr, args.batch_size)) + + # create new OrderedDict that does not contain `module.` + from collections import OrderedDict + new_state_dict = OrderedDict() + for k, v in checkpoint['state_dict_G'].items(): + name = k.replace("module.", "") # remove `module.` + new_state_dict[name] = v + # load params + generator.load_state_dict(new_state_dict) + os.makedirs("image", exist_ok=True) + for i in range(200): + z = Variable(Tensor(np.random.normal(0, 1, (64, 100)))).npu() + + # Generate a batch of images + gen_imgs = generator(z) + + save_image(gen_imgs.data[:25], "image/%d.png" % i, nrow=5, normalize=True) + print("Generate done!") + return + + if args.is_master_node: + print("Start training") + start_time = time.time() + os.makedirs("training_images",exist_ok=True) + for epoch in range(args.start_epoch, args.n_epochs): + if args.distributed: + train_sampler.set_epoch(epoch) + + # train for one epoch + train_one_epoch(generator, discriminator, optimizer_G, optimizer_D, adversarial_loss, + epoch, args, dataloader,Tensor, LOSS_G,LOSS_D,device) + + if epoch == 50 or epoch == 199: + if args.apex and args.is_master_node: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': 'GAN', + 'state_dict_G': generator.state_dict(), + 'state_dict_D': discriminator.state_dict(), + 'optimizer_G': optimizer_G.state_dict(), + 'optimizer_D': optimizer_D.state_dict(), + 'loss_g': LOSS_G, + 'loss_d': LOSS_D, + 'apex': amp.state_dict() + }) + elif args.is_master_node: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': 'GAN', + 'state_dict_G': generator.state_dict(), + 'state_dict_D': discriminator.state_dict(), + 'optimizer_G': optimizer_G.state_dict(), + 'optimizer_D': optimizer_D.state_dict(), + 'loss_g': LOSS_G, + 'loss_d': LOSS_D + }) + total_time = time.time() - start_time + total_time_str = str(datetime.timedelta(seconds=int(total_time))) + if args.is_master_node: + print('Training time {}'.format(total_time_str)) + +def save_checkpoint(state, filename='./checkpoint.pth.tar'): + torch.save(state, filename) + + +class AverageMeter(object): + """Computes and stores the average and current value""" + + def __init__(self, name, fmt=':f', start_count_index=10): + self.name = name + self.fmt = fmt + self.reset() + self.start_count_index = start_count_index + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + if self.count == 0: + self.N = n + + self.val = val + self.count += n + if self.count > (self.start_count_index * self.N): + self.sum += val * n + self.avg = self.sum / (self.count - self.start_count_index * self.N) + + def __str__(self): + fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' + return fmtstr.format(**self.__dict__) + +def parse_args(): + parser = argparse.ArgumentParser(description='PyTorch GAN Training') + parser.add_argument("--n_epochs", type=int, default=200, help="number of epochs of training") + parser.add_argument("--batch_size", type=int, default=128, help="size of the batches") + parser.add_argument("--lr", type=float, default=0.0008, help="adam: learning rate") + parser.add_argument("--b1", type=float, default=0.5, help="adam: decay of first order momentum of gradient") + parser.add_argument("--b2", type=float, default=0.999, help="adam: decay of first order momentum of gradient") + parser.add_argument("--sample_interval", type=int, default=400, help="interval betwen image samples") + parser.add_argument("--latent_dim", type=int, default=100, help="dimensionality of the latent space") + parser.add_argument("--img_size", type=int, default=28, help="size of each image dimension") + parser.add_argument("--channels", type=int, default=1, help="number of image channels") + parser.add_argument("--gpus", type=int, default=8, help="num of gpus of per node") + parser.add_argument("--nodes", type=int, default=1) + parser.add_argument('--device_id', default=0, type=int, help='device id') + parser.add_argument("--test_only", type=int, default=None, help="only generate images") + parser.add_argument('--start_epoch', default=0, type=int, metavar='N', + help='manual epoch number (useful on restarts)') + parser.add_argument('--resume', default='', type=str, metavar='PATH', + help='path to latest checkpoint (default: none)') + parser.add_argument('--pretrained', dest='pretrained', action='store_true', + help='use pre-trained model') + + parser.add_argument('--distributed', action='store_true', + help='Use multi-processing distributed training to launch ' + 'N processes per node, which has N GPUs. This is the ' + 'fastest way to use PyTorch for either single node or ' + 'multi node data parallel training') + ## for ascend 910 + parser.add_argument('--addr', default='127.0.0.1', + type=str, help='master addr') + parser.add_argument('--workers', default=16, type=int, + help='numbers of worker') + parser.add_argument('--apex', default=False, action='store_true', + help='use apex to train the model') + args = parser.parse_args() + return args +if __name__ == '__main__': + args = parse_args() main(args) \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/GAN_Pytorch/models.py b/PyTorch/contrib/cv/others/GAN_Pytorch/models.py index 6e6f1a998465dd292d956195ce630082f74df933..f04632ce980380e4a1060658946c11c4b323847b 100644 --- a/PyTorch/contrib/cv/others/GAN_Pytorch/models.py +++ b/PyTorch/contrib/cv/others/GAN_Pytorch/models.py @@ -1,68 +1,68 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import torch.nn as nn -import numpy as np - -channels = 1 -image_size = 28 -img_shape =(channels,image_size,image_size) -latent_dim = 100 - -class Generator(nn.Module): - def __init__(self): - super(Generator, self).__init__() - - def block(in_feat, out_feat, normalize=True): - layers = [nn.Linear(in_feat, out_feat)] - if normalize: - layers.append(nn.BatchNorm1d(out_feat, 0.8)) - layers.append(nn.LeakyReLU(0.2, inplace=True)) - return layers - - self.model = nn.Sequential( - *block(latent_dim, 128, normalize=False), - *block(128, 256), - *block(256, 512), - *block(512, 1024), - nn.Linear(1024, int(np.prod(img_shape))), - nn.Tanh() - ) - - def forward(self, z): - img = self.model(z) - img = img.view(img.size(0), *img_shape) - return img - -class Discriminator(nn.Module): - def __init__(self): - super(Discriminator, self).__init__() - - self.model = nn.Sequential( - nn.Linear(int(np.prod(img_shape)), 512), - nn.LeakyReLU(0.2, inplace=True), - nn.Linear(512, 256), - nn.LeakyReLU(0.2, inplace=True), - nn.Linear(256, 1), - nn.Sigmoid(), - ) - - def forward(self, img): - img_flat = img.view(img.size(0), -1) - validity = self.model(img_flat) - - return validity - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import torch.nn as nn +import numpy as np + +channels = 1 +image_size = 28 +img_shape =(channels,image_size,image_size) +latent_dim = 100 + +class Generator(nn.Module): + def __init__(self): + super(Generator, self).__init__() + + def block(in_feat, out_feat, normalize=True): + layers = [nn.Linear(in_feat, out_feat)] + if normalize: + layers.append(nn.BatchNorm1d(out_feat, 0.8)) + layers.append(nn.LeakyReLU(0.2, inplace=True)) + return layers + + self.model = nn.Sequential( + *block(latent_dim, 128, normalize=False), + *block(128, 256), + *block(256, 512), + *block(512, 1024), + nn.Linear(1024, int(np.prod(img_shape))), + nn.Tanh() + ) + + def forward(self, z): + img = self.model(z) + img = img.view(img.size(0), *img_shape) + return img + +class Discriminator(nn.Module): + def __init__(self): + super(Discriminator, self).__init__() + + self.model = nn.Sequential( + nn.Linear(int(np.prod(img_shape)), 512), + nn.LeakyReLU(0.2, inplace=True), + nn.Linear(512, 256), + nn.LeakyReLU(0.2, inplace=True), + nn.Linear(256, 1), + nn.Sigmoid(), + ) + + def forward(self, img): + img_flat = img.view(img.size(0), -1) + validity = self.model(img_flat) + + return validity + + diff --git a/PyTorch/contrib/cv/others/GAN_Pytorch/modelzoo_level.txt b/PyTorch/contrib/cv/others/GAN_Pytorch/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/others/GAN_Pytorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/others/GAN_Pytorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/Pix2Pix/README.md b/PyTorch/contrib/cv/others/Pix2Pix/README.md index f1b3173677ba3fe268fecba18ca2ac5fb7df269a..c76a5fa338a64b429b1698e01e7631aa3c700494 100644 --- a/PyTorch/contrib/cv/others/Pix2Pix/README.md +++ b/PyTorch/contrib/cv/others/Pix2Pix/README.md @@ -1,38 +1,38 @@ -# Pix2Pix - url=https://gitee.com/iiiimp/modelzoo/tree/master/contrib/PyTorch/Research/cv/gan/Pix2Pix - branch=master - -# 精度性能 - - | 名称 | 精度 | 性能 | - | :------: | :------: | :------: | - | GPU-1p | - | 15 | - | GPU-8p | - | 31 | - | NPU-1p | - | 8 | - | NPU-8p | - | 8 | -# 自验报告 - - # 1p train perf - # 是否正确输出了性能log文件 - bash ./test/train_performance_1p.sh\ --data_path=./datasets/facades - # 验收结果: OK - # 备注: 目标性能8FPS;验收测试性能8FPS; - - # 8p train perf - # 是否正确输出了性能log文件 - bash ./test/train_performance_8p.sh\ --data_path=./datasets/facades - # 验收结果: OK - # 备注: 目标性能15FPS;验收测试性能8PS; - - # 8p train full - # 是否正确输出了性能精度log文件,是否正确保存了模型文件 - bash ./test/train_full_8p.sh\ --data_path=./datasets/facades - # 验收结果: OK - # 备注:直接看图片效果 - - # 8p eval - # 是否正确输出了性能精度log文件 - bash ./test/train_eval_8p.sh\ --data_path=./datasets/facades --pth_path=./checkpoints/facades_pix2pix_npu_8p_full - # 验收结果: OK - # 备注:直接看图片效果 - +# Pix2Pix + url=https://gitee.com/iiiimp/modelzoo/tree/master/contrib/PyTorch/Research/cv/gan/Pix2Pix + branch=master + +# 精度性能 + + | 名称 | 精度 | 性能 | + | :------: | :------: | :------: | + | GPU-1p | - | 15 | + | GPU-8p | - | 31 | + | NPU-1p | - | 8 | + | NPU-8p | - | 8 | +# 自验报告 + + # 1p train perf + # 是否正确输出了性能log文件 + bash ./test/train_performance_1p.sh\ --data_path=./datasets/facades + # 验收结果: OK + # 备注: 目标性能8FPS;验收测试性能8FPS; + + # 8p train perf + # 是否正确输出了性能log文件 + bash ./test/train_performance_8p.sh\ --data_path=./datasets/facades + # 验收结果: OK + # 备注: 目标性能15FPS;验收测试性能8PS; + + # 8p train full + # 是否正确输出了性能精度log文件,是否正确保存了模型文件 + bash ./test/train_full_8p.sh\ --data_path=./datasets/facades + # 验收结果: OK + # 备注:直接看图片效果 + + # 8p eval + # 是否正确输出了性能精度log文件 + bash ./test/train_eval_8p.sh\ --data_path=./datasets/facades --pth_path=./checkpoints/facades_pix2pix_npu_8p_full + # 验收结果: OK + # 备注:直接看图片效果 + diff --git a/PyTorch/contrib/cv/others/Pix2Pix/modelzoo_level.txt b/PyTorch/contrib/cv/others/Pix2Pix/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/others/Pix2Pix/modelzoo_level.txt +++ b/PyTorch/contrib/cv/others/Pix2Pix/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/Pix2Pix/precision.py b/PyTorch/contrib/cv/others/Pix2Pix/precision.py index c14e8e8abc80d21f8af8667757ddafbdc0e3623f..99dc5002230f276cde25dc3bf83c514a26bb4c6e 100644 --- a/PyTorch/contrib/cv/others/Pix2Pix/precision.py +++ b/PyTorch/contrib/cv/others/Pix2Pix/precision.py @@ -1,198 +1,198 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Copyright (c) Soumith Chintala 2016, -# All rights reserved -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -*- coding: utf-8 -*- -"""用于精度比对 -""" - -import torch -import torch.nn as nn -import torchvision -import apex -from apex import amp -import copy -from models import networks - -##### 需自行改写部分 start ##### -# 获得模型 -def get_model(): - model = networks.define_G(3, 3, 64, 'unet_256', 'instance', - True, 'normal', 0.02, '[0]') - # model = networks.define_D(6, 64, 'basic', - # 3, 'instance','normal', 0.02, '[0]') - # 用于避免BN或者Dropout带来的影响,如果遇到无法evalbackward的现象,请注掉该行 - # model.eval() - - return model - -# 获得输入tensor -input_tensor = torch.randn(1, 3, 256, 256) -# input_tensor = torch.randn(1, 6, 256, 256) - -# 设置npu_device -npu_device = 'npu:0' - -# 设置amp -AMP_MODE = True - -# 设置NPU prof 文件输出 -NPU_PROF = True - -##### 需自行改写部分 end ##### - -def cri_func(x): - base_func = nn.CrossEntropyLoss() - shape_list = x.shape - N = shape_list[0] - R = 1 - if len(shape_list) > 1: - for r in shape_list[1:]: - R *= r - T = torch.randint(0,R, size=(N,)).to(x.device) - if str(T.device).startswith('npu'): - T = T.int() - return base_func(x.reshape(N, -1), T) - -# 设置hook -def hook_func(name, save_dict, module): - def hook_function(module, inputs, outputs): - inputs_key = name + '_inputs' - idx = 0 - while inputs_key in save_dict: - inputs_key = inputs_key.split('-')[0] + '-%d'%idx - idx +=1 - save_dict[inputs_key] = inputs - - outputs_key = name + '_outputs' - idx = 0 - while outputs_key in save_dict: - outputs_key = outputs_key.split('-')[0] + '-%d'%idx - idx +=1 - save_dict[outputs_key] = outputs - return hook_function - -##### CPU ##### -# CPU固定输入和权重 -model = get_model() -optimizer = torch.optim.SGD(model.parameters(), 0.1) -state_dict = copy.deepcopy(model.state_dict()) - -# CPU注册hook,cpu_dict用于存储对比对象 -cpu_dict = {} -for name, module in model.named_modules(): - module.register_forward_hook(hook_func('[forward]:' + name, cpu_dict, module)) - module.register_backward_hook(hook_func('[backward]:' + name, cpu_dict, module)) - -# CPU运行正反向,获取正反向每个module的输入输出和所有参数的grad -out = model(input_tensor) -loss = cri_func(out) -optimizer.zero_grad() -loss.backward() -optimizer.step() -for name, param in model.named_parameters(): - cpu_dict["[grad]:" + name] = param.grad - -##### NPU ##### -# 重新定义模型,清理模型状态,并加装权重,保持初始化一致 -model = get_model() -optimizer = torch.optim.SGD(model.parameters(), 0.1) -model.load_state_dict(state_dict) - -# NPU注册hook,npu_dict用于存储对比对象 -npu_dict = {} -for name, module in model.named_modules(): - module.register_forward_hook(hook_func('[forward]:' + name, npu_dict, module)) - module.register_backward_hook(hook_func('[backward]:' + name, npu_dict, module)) - -# 将model和input_tensor放到npu -torch.npu.set_device(npu_device) -model = model.npu() -input_tensor = input_tensor.npu() - -# amp可选项,不适用请注释 -if AMP_MODE: - optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), 0.1) - model, optimizer = amp.initialize(model, optimizer, opt_level='O2', loss_scale=1.0, combine_grad=True) - -# NPU运行正反向,获取正反向每个module的输入输出和所有参数的grad -out = model(input_tensor) -loss = cri_func(out) -optimizer.zero_grad() -if AMP_MODE: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() -else: - loss.backward() -optimizer.step() -for name, param in model.named_parameters(): - npu_dict["[grad]:" + name] = param.grad - - -##### ComPare ##### -# 递归得到对比值 -def compare(x1, x2, prefix=''): - if isinstance(x1, tuple): - if x1: - for idx in range(len(x1)): - try: - compare(x1[idx], x2[idx], prefix=prefix + '.%d' % idx) - except Exception as e: - # print(str(e)) - print(prefix, 'failed.') - elif isinstance(x1, torch.Tensor) and isinstance(x2, torch.Tensor): - try: - l1_error = (x1.half().float() - x2.cpu()).abs().mean() - rel_error = l1_error / (x1.abs().mean()) - print(prefix, 'l1_error: ', l1_error, 'rel_error', rel_error) - if l1_error * rel_error > 10 : - print('\n###\n',prefix, 'should checked!','\n###\n') - except Exception as e: - # print(str(e)) - print(prefix, 'failed.') - -for k in cpu_dict: - compare(cpu_dict[k], npu_dict[k], prefix=k) - -# 需要profiling的时候额外输出一次 -if NPU_PROF: - with torch.autograd.profiler.profile(use_npu=True) as prof: - out = model(input_tensor) - loss = cri_func(out) - optimizer.zero_grad() - if AMP_MODE: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - prof.export_chrome_trace("netD output.prof") # "output.prof"为输出文件地址 - - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Copyright (c) Soumith Chintala 2016, +# All rights reserved +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -*- coding: utf-8 -*- +"""用于精度比对 +""" + +import torch +import torch.nn as nn +import torchvision +import apex +from apex import amp +import copy +from models import networks + +##### 需自行改写部分 start ##### +# 获得模型 +def get_model(): + model = networks.define_G(3, 3, 64, 'unet_256', 'instance', + True, 'normal', 0.02, '[0]') + # model = networks.define_D(6, 64, 'basic', + # 3, 'instance','normal', 0.02, '[0]') + # 用于避免BN或者Dropout带来的影响,如果遇到无法evalbackward的现象,请注掉该行 + # model.eval() + + return model + +# 获得输入tensor +input_tensor = torch.randn(1, 3, 256, 256) +# input_tensor = torch.randn(1, 6, 256, 256) + +# 设置npu_device +npu_device = 'npu:0' + +# 设置amp +AMP_MODE = True + +# 设置NPU prof 文件输出 +NPU_PROF = True + +##### 需自行改写部分 end ##### + +def cri_func(x): + base_func = nn.CrossEntropyLoss() + shape_list = x.shape + N = shape_list[0] + R = 1 + if len(shape_list) > 1: + for r in shape_list[1:]: + R *= r + T = torch.randint(0,R, size=(N,)).to(x.device) + if str(T.device).startswith('npu'): + T = T.int() + return base_func(x.reshape(N, -1), T) + +# 设置hook +def hook_func(name, save_dict, module): + def hook_function(module, inputs, outputs): + inputs_key = name + '_inputs' + idx = 0 + while inputs_key in save_dict: + inputs_key = inputs_key.split('-')[0] + '-%d'%idx + idx +=1 + save_dict[inputs_key] = inputs + + outputs_key = name + '_outputs' + idx = 0 + while outputs_key in save_dict: + outputs_key = outputs_key.split('-')[0] + '-%d'%idx + idx +=1 + save_dict[outputs_key] = outputs + return hook_function + +##### CPU ##### +# CPU固定输入和权重 +model = get_model() +optimizer = torch.optim.SGD(model.parameters(), 0.1) +state_dict = copy.deepcopy(model.state_dict()) + +# CPU注册hook,cpu_dict用于存储对比对象 +cpu_dict = {} +for name, module in model.named_modules(): + module.register_forward_hook(hook_func('[forward]:' + name, cpu_dict, module)) + module.register_backward_hook(hook_func('[backward]:' + name, cpu_dict, module)) + +# CPU运行正反向,获取正反向每个module的输入输出和所有参数的grad +out = model(input_tensor) +loss = cri_func(out) +optimizer.zero_grad() +loss.backward() +optimizer.step() +for name, param in model.named_parameters(): + cpu_dict["[grad]:" + name] = param.grad + +##### NPU ##### +# 重新定义模型,清理模型状态,并加装权重,保持初始化一致 +model = get_model() +optimizer = torch.optim.SGD(model.parameters(), 0.1) +model.load_state_dict(state_dict) + +# NPU注册hook,npu_dict用于存储对比对象 +npu_dict = {} +for name, module in model.named_modules(): + module.register_forward_hook(hook_func('[forward]:' + name, npu_dict, module)) + module.register_backward_hook(hook_func('[backward]:' + name, npu_dict, module)) + +# 将model和input_tensor放到npu +torch.npu.set_device(npu_device) +model = model.npu() +input_tensor = input_tensor.npu() + +# amp可选项,不适用请注释 +if AMP_MODE: + optimizer = apex.optimizers.NpuFusedSGD(model.parameters(), 0.1) + model, optimizer = amp.initialize(model, optimizer, opt_level='O2', loss_scale=1.0, combine_grad=True) + +# NPU运行正反向,获取正反向每个module的输入输出和所有参数的grad +out = model(input_tensor) +loss = cri_func(out) +optimizer.zero_grad() +if AMP_MODE: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() +else: + loss.backward() +optimizer.step() +for name, param in model.named_parameters(): + npu_dict["[grad]:" + name] = param.grad + + +##### ComPare ##### +# 递归得到对比值 +def compare(x1, x2, prefix=''): + if isinstance(x1, tuple): + if x1: + for idx in range(len(x1)): + try: + compare(x1[idx], x2[idx], prefix=prefix + '.%d' % idx) + except Exception as e: + # print(str(e)) + print(prefix, 'failed.') + elif isinstance(x1, torch.Tensor) and isinstance(x2, torch.Tensor): + try: + l1_error = (x1.half().float() - x2.cpu()).abs().mean() + rel_error = l1_error / (x1.abs().mean()) + print(prefix, 'l1_error: ', l1_error, 'rel_error', rel_error) + if l1_error * rel_error > 10 : + print('\n###\n',prefix, 'should checked!','\n###\n') + except Exception as e: + # print(str(e)) + print(prefix, 'failed.') + +for k in cpu_dict: + compare(cpu_dict[k], npu_dict[k], prefix=k) + +# 需要profiling的时候额外输出一次 +if NPU_PROF: + with torch.autograd.profiler.profile(use_npu=True) as prof: + out = model(input_tensor) + loss = cri_func(out) + optimizer.zero_grad() + if AMP_MODE: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + prof.export_chrome_trace("netD output.prof") # "output.prof"为输出文件地址 + + diff --git a/PyTorch/contrib/cv/others/Pix2Pix/pytorch_prof.py b/PyTorch/contrib/cv/others/Pix2Pix/pytorch_prof.py index afb06b4b978436cd03d61ba2f71e041e20d7dba7..d79a619de98089f04918148bd6f1d14c2b1eaa02 100644 --- a/PyTorch/contrib/cv/others/Pix2Pix/pytorch_prof.py +++ b/PyTorch/contrib/cv/others/Pix2Pix/pytorch_prof.py @@ -1,141 +1,141 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Copyright (c) Soumith Chintala 2016, -# All rights reserved -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://spdx.org/licenses/BSD-3-Clause.html -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -*- coding: utf-8 -*- -"""pytorch_prof.py -""" - -import torch -import torch.optim as optim -import torch.nn as nn -import time -import argparse -from models import networks - -def build_model(): - # 请自定义模型并加载预训练模型 - # import torchvision - # model = torchvision.models.resnet50(pretrained=True) - model = networks.define_G(3, 3, 64, 'unet_256', 'instance', - True, 'normal', 0.02, '[0]') - return model - - -def get_raw_data(): - # input_tensor = torch.randn(2, 3, 224, 224) - input_tensor = torch.randn(1, 3, 256, 256) - return input_tensor - - -def criterion(x): - base_func = nn.CrossEntropyLoss() - shape_list = x.shape - N = shape_list[0] - R = 1 - if len(shape_list) > 1: - for r in shape_list[1:]: - R *= r - T = torch.randint(0,R, size=(N,)).to(x.device) - if str(T.device).startswith('npu'): - T = T.int() - return base_func(x.reshape(N, -1), T) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='PyTorch Prof') - parser.add_argument('--device', type=str, default='cpu', - help='set which type of device used. Support cuda:0(device_id), npu:0(device_id).') - parser.add_argument('--amp', default=False, action='store_true', - help='use amp during prof') - parser.add_argument('--loss-scale', default=64.0, type=float, - help='loss scale using in amp, default 64.0, -1 means dynamic') - parser.add_argument('--opt-level', default='O2', type=str, - help='opt-level using in amp, default O2') - parser.add_argument('--FusedSGD', default=False, action='store_true', - help='use FusedSGD during prof') - - args = parser.parse_args() - - # 1.准备工作 - if args.device.startswith('cuda'): - torch.cuda.set_device(args.device) - prof_kwargs = {'use_cuda': True} - elif args.device.startswith('npu'): - torch.npu.set_device(args.device) - prof_kwargs = {'use_npu': True} - else: - prof_kwargs = {} - - # 2.构建模型 - model = build_model() - if args.FusedSGD: - from apex.optimizers import NpuFusedSGD - optimizer = NpuFusedSGD(model.parameters(), lr=0.01) - model = model.to(args.device) - if args.amp: - from apex import amp - model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, - loss_scale=None if args.loss_scale == -1 else args.loss_scale, - combine_grad=True) - else: - optimizer = optim.SGD(model.parameters(), lr=0.01) - model = model.to(args.device) - if args.amp: - from apex import amp - model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, - loss_scale=None if args.loss_scale == -1 else args.loss_scale) - - # 3.生成input - input_tensor = get_raw_data() - input_tensor = input_tensor.to(args.device) - - # 先运行一次,保证prof得到的性能是正确的 - def run(): - output_tensor = model(input_tensor) - loss = criterion(output_tensor) - optimizer.zero_grad() - if args.amp: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - return loss - for i in range(5): - start_time = time.time() - loss = run() - print('iter: %d, loss: %.2f, time: %.2f'%(i, loss, (time.time() - start_time)*1000)) - - # 4. 执行forward+profiling - with torch.autograd.profiler.profile(**prof_kwargs) as prof: - run() - print(prof.key_averages().table()) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Copyright (c) Soumith Chintala 2016, +# All rights reserved +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://spdx.org/licenses/BSD-3-Clause.html +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -*- coding: utf-8 -*- +"""pytorch_prof.py +""" + +import torch +import torch.optim as optim +import torch.nn as nn +import time +import argparse +from models import networks + +def build_model(): + # 请自定义模型并加载预训练模型 + # import torchvision + # model = torchvision.models.resnet50(pretrained=True) + model = networks.define_G(3, 3, 64, 'unet_256', 'instance', + True, 'normal', 0.02, '[0]') + return model + + +def get_raw_data(): + # input_tensor = torch.randn(2, 3, 224, 224) + input_tensor = torch.randn(1, 3, 256, 256) + return input_tensor + + +def criterion(x): + base_func = nn.CrossEntropyLoss() + shape_list = x.shape + N = shape_list[0] + R = 1 + if len(shape_list) > 1: + for r in shape_list[1:]: + R *= r + T = torch.randint(0,R, size=(N,)).to(x.device) + if str(T.device).startswith('npu'): + T = T.int() + return base_func(x.reshape(N, -1), T) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='PyTorch Prof') + parser.add_argument('--device', type=str, default='cpu', + help='set which type of device used. Support cuda:0(device_id), npu:0(device_id).') + parser.add_argument('--amp', default=False, action='store_true', + help='use amp during prof') + parser.add_argument('--loss-scale', default=64.0, type=float, + help='loss scale using in amp, default 64.0, -1 means dynamic') + parser.add_argument('--opt-level', default='O2', type=str, + help='opt-level using in amp, default O2') + parser.add_argument('--FusedSGD', default=False, action='store_true', + help='use FusedSGD during prof') + + args = parser.parse_args() + + # 1.准备工作 + if args.device.startswith('cuda'): + torch.cuda.set_device(args.device) + prof_kwargs = {'use_cuda': True} + elif args.device.startswith('npu'): + torch.npu.set_device(args.device) + prof_kwargs = {'use_npu': True} + else: + prof_kwargs = {} + + # 2.构建模型 + model = build_model() + if args.FusedSGD: + from apex.optimizers import NpuFusedSGD + optimizer = NpuFusedSGD(model.parameters(), lr=0.01) + model = model.to(args.device) + if args.amp: + from apex import amp + model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, + loss_scale=None if args.loss_scale == -1 else args.loss_scale, + combine_grad=True) + else: + optimizer = optim.SGD(model.parameters(), lr=0.01) + model = model.to(args.device) + if args.amp: + from apex import amp + model, optimizer = amp.initialize(model, optimizer, opt_level=args.opt_level, + loss_scale=None if args.loss_scale == -1 else args.loss_scale) + + # 3.生成input + input_tensor = get_raw_data() + input_tensor = input_tensor.to(args.device) + + # 先运行一次,保证prof得到的性能是正确的 + def run(): + output_tensor = model(input_tensor) + loss = criterion(output_tensor) + optimizer.zero_grad() + if args.amp: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + return loss + for i in range(5): + start_time = time.time() + loss = run() + print('iter: %d, loss: %.2f, time: %.2f'%(i, loss, (time.time() - start_time)*1000)) + + # 4. 执行forward+profiling + with torch.autograd.profiler.profile(**prof_kwargs) as prof: + run() + print(prof.key_averages().table()) prof.export_chrome_trace("pytorch_prof_%s.prof" % args.device) \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/RDN/Dockerfile b/PyTorch/contrib/cv/others/RDN/Dockerfile index 7e712fe1a166790798f57a2f2762c47394beb625..30a31af55804dd79571d2a36e6107a844cb7e549 100644 --- a/PyTorch/contrib/cv/others/RDN/Dockerfile +++ b/PyTorch/contrib/cv/others/RDN/Dockerfile @@ -1,5 +1,5 @@ -ARG FROM_IMAGE_NAME -FROM $FROM_IMAGE_NAME - -COPY requirements.txt . +ARG FROM_IMAGE_NAME +FROM $FROM_IMAGE_NAME + +COPY requirements.txt . RUN pip3.7 install -r requirements.txt \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/RDN/README.md b/PyTorch/contrib/cv/others/RDN/README.md index 6a58d58d887d38860d71c58b8523425e8ae603f8..bbda601483f9461c50c3d758fdd7efee9f99010e 100644 --- a/PyTorch/contrib/cv/others/RDN/README.md +++ b/PyTorch/contrib/cv/others/RDN/README.md @@ -1,51 +1,51 @@ -# RDN 训练 -# Residual Dense Network for Image Super-Resolution -This implements training of RDN on the DIV2K_x2 dataset. -- Reference implementation: -``` -url=https://github.com/yjn870/RDN-pytorch -``` - -## RDN Detail # - -As of the current date, Ascend-Pytorch is still inefficient for contiguous operations. -Therefore, RDN is re-implemented using semantics such as custom OP. - - -## Requirements # - -- Install PyTorch ([pytorch.org](http://pytorch.org)) -- `pip install -r requirements.txt` -- The DIV2k, Set5 Dataset can be downloaded from the links below.Move the datasets to directory ./data . - - Train Set : [Download DIV2k](https://www.dropbox.com/s/41sn4eie37hp6rh/DIV2K_x2.h5?dl=0) - - Test Set : [Download Set5](https://www.dropbox.com/s/pd52pkmaik1ri0h/rdn_x2.pth?dl=0) - -## Training # -To train a model, run `main.py` with the desired model architecture and the path to the ImageNet dataset: - -```bash -# 1p train perf -bash test/train_performance_1p.sh - -# 8p train perf -bash test/train_performance_8p.sh - -# 8p train full -bash test/train_full_8p.sh - -# 8p eval -bash test/train_eval_8p.sh - -# finetuning -bash test/train_finetune_1p.sh -``` - -## RDN training result # - -| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | -| :------: | :------: | :------: | :------: | :------: | -| - | 240 | 1 | 800 | O1 | -| 37.95 | 1716 | 8 | 800 | O1 | - - - +# RDN 训练 +# Residual Dense Network for Image Super-Resolution +This implements training of RDN on the DIV2K_x2 dataset. +- Reference implementation: +``` +url=https://github.com/yjn870/RDN-pytorch +``` + +## RDN Detail # + +As of the current date, Ascend-Pytorch is still inefficient for contiguous operations. +Therefore, RDN is re-implemented using semantics such as custom OP. + + +## Requirements # + +- Install PyTorch ([pytorch.org](http://pytorch.org)) +- `pip install -r requirements.txt` +- The DIV2k, Set5 Dataset can be downloaded from the links below.Move the datasets to directory ./data . + - Train Set : [Download DIV2k](https://www.dropbox.com/s/41sn4eie37hp6rh/DIV2K_x2.h5?dl=0) + - Test Set : [Download Set5](https://www.dropbox.com/s/pd52pkmaik1ri0h/rdn_x2.pth?dl=0) + +## Training # +To train a model, run `main.py` with the desired model architecture and the path to the ImageNet dataset: + +```bash +# 1p train perf +bash test/train_performance_1p.sh + +# 8p train perf +bash test/train_performance_8p.sh + +# 8p train full +bash test/train_full_8p.sh + +# 8p eval +bash test/train_eval_8p.sh + +# finetuning +bash test/train_finetune_1p.sh +``` + +## RDN training result # + +| Acc@1 | FPS | Npu_nums | Epochs | AMP_Type | +| :------: | :------: | :------: | :------: | :------: | +| - | 240 | 1 | 800 | O1 | +| 37.95 | 1716 | 8 | 800 | O1 | + + + diff --git a/PyTorch/contrib/cv/others/RDN/docker_start.sh b/PyTorch/contrib/cv/others/RDN/docker_start.sh index 46ce9a02ec0532d6db324beaee7f7eab501b4565..944bca3cdac8e3f2d47ceb0e2b6eb181a405de11 100644 --- a/PyTorch/contrib/cv/others/RDN/docker_start.sh +++ b/PyTorch/contrib/cv/others/RDN/docker_start.sh @@ -1,25 +1,25 @@ -#!/bin/bash - -docker_image=$1 -data_dir=$2 -model_dir=$3 - -docker run -it --ipc=host \ - --device=/dev/davinci0 \ - --device=/dev/davinci1 \ - --device=/dev/davinci2 \ - --device=/dev/davinci3 \ - --device=/dev/davinci4 \ - --device=/dev/davinci5 \ - --device=/dev/davinci6 \ - --device=/dev/davinci7 \ - --device=/dev/davinci_manager \ - --device=/dev/devmm_svm --device=/dev/hisi_hdc \ - -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ - -v /usr/local/Ascend/add-ons/:/usr/local/Ascend/add-ons/ \ - -v ${model_dir}:${model_dir} \ - -v ${data_dir}:${data_dir} \ - -v /var/log/npu/conf/slog/slog.conf:/var/log/npu/conf/slog/slog.conf \ - -v /var/log/npu/slog/:/var/log/npu/slog -v /var/log/npu/profiling/:/var/log/npu/profiling \ - -v /var/log/npu/dump/:/var/log/npu/dump -v /var/log/npu/:/usr/slog ${docker_image} \ +#!/bin/bash + +docker_image=$1 +data_dir=$2 +model_dir=$3 + +docker run -it --ipc=host \ + --device=/dev/davinci0 \ + --device=/dev/davinci1 \ + --device=/dev/davinci2 \ + --device=/dev/davinci3 \ + --device=/dev/davinci4 \ + --device=/dev/davinci5 \ + --device=/dev/davinci6 \ + --device=/dev/davinci7 \ + --device=/dev/davinci_manager \ + --device=/dev/devmm_svm --device=/dev/hisi_hdc \ + -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ + -v /usr/local/Ascend/add-ons/:/usr/local/Ascend/add-ons/ \ + -v ${model_dir}:${model_dir} \ + -v ${data_dir}:${data_dir} \ + -v /var/log/npu/conf/slog/slog.conf:/var/log/npu/conf/slog/slog.conf \ + -v /var/log/npu/slog/:/var/log/npu/slog -v /var/log/npu/profiling/:/var/log/npu/profiling \ + -v /var/log/npu/dump/:/var/log/npu/dump -v /var/log/npu/:/usr/slog ${docker_image} \ /bin/bash \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/RDN/modelzoo_level.txt b/PyTorch/contrib/cv/others/RDN/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/others/RDN/modelzoo_level.txt +++ b/PyTorch/contrib/cv/others/RDN/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/Srcnn_x2_for_Pytorch/modelzoo_level.txt b/PyTorch/contrib/cv/others/Srcnn_x2_for_Pytorch/modelzoo_level.txt index 4987c1069692fa42cf124e9045a3d42b733b2a79..0c22703439d27ef96518c74688e17502e7209c62 100644 --- a/PyTorch/contrib/cv/others/Srcnn_x2_for_Pytorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/others/Srcnn_x2_for_Pytorch/modelzoo_level.txt @@ -1,6 +1,6 @@ -GPUStatus:OK -NPUMigrationStatus:OK -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +GPUStatus:OK +NPUMigrationStatus:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/Srcnn_x2_for_Pytorch/requirements.txt b/PyTorch/contrib/cv/others/Srcnn_x2_for_Pytorch/requirements.txt index 148f855f4f1b3d43fc499cd9ebae3f404561dcee..7cd93126a9ce5ff9a38a4a4e2c6da87a34d0d968 100644 --- a/PyTorch/contrib/cv/others/Srcnn_x2_for_Pytorch/requirements.txt +++ b/PyTorch/contrib/cv/others/Srcnn_x2_for_Pytorch/requirements.txt @@ -1,5 +1,5 @@ -h5py==3.3.0 -numpy==1.20.2 -Pillow==8.2.0 -tqdm==4.19.9 +h5py==3.3.0 +numpy==1.20.2 +Pillow==8.2.0 +tqdm==4.19.9 scikit-image==0.16.2 \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/edsr_x2/loss.py b/PyTorch/contrib/cv/others/edsr_x2/loss.py index 98219c473cdc2215f0f8c4547006fa0c288375d7..c89c9ce15945db2b5c897a737726e607cc30ee23 100644 --- a/PyTorch/contrib/cv/others/edsr_x2/loss.py +++ b/PyTorch/contrib/cv/others/edsr_x2/loss.py @@ -1,152 +1,152 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import os -from importlib import import_module - -import numpy as np - -import torch -import torch.nn as nn -import torch.nn.functional as F - - -class Loss(nn.modules.loss._Loss): - def __init__(self, args, ckp): - super(Loss, self).__init__() - print("Preparing loss function:") - - self.n_GPUs = args.n_GPUs - self.loss = [] - self.loss_module = nn.ModuleList() - for loss in args.loss.split("+"): - weight, loss_type = loss.split("*") - if loss_type == "MSE": - loss_function = nn.MSELoss() - elif loss_type == "L1": - loss_function = nn.L1Loss() - elif loss_type.find("VGG") >= 0: - module = import_module("loss.vgg") - loss_function = getattr(module, "VGG")( - loss_type[3:], rgb_range=args.rgb_range - ) - elif loss_type.find("GAN") >= 0: - module = import_module("loss.adversarial") - loss_function = getattr(module, "Adversarial")(args, loss_type) - - self.loss.append( - {"type": loss_type, "weight": float( - weight), "function": loss_function} - ) - if loss_type.find("GAN") >= 0: - self.loss.append( - {"type": "DIS", "weight": 1, "function": None}) - - if len(self.loss) > 1: - self.loss.append({"type": "Total", "weight": 0, "function": None}) - - for l in self.loss: - if l["function"] is not None: - print("{:.3f} * {}".format(l["weight"], l["type"])) - self.loss_module.append(l["function"]) - - self.log = torch.Tensor() - - device = torch.device("cpu" if args.cpu else "cuda") - if args.use_npu: - device = args.device - self.loss_module.to(device) - if not args.cpu and args.n_GPUs > 1: - self.loss_module = nn.DataParallel( - self.loss_module, range(args.n_GPUs)) - - if args.load != "": - self.load(ckp.dir, cpu=args.cpu) - - def forward(self, sr, hr): - losses = [] - for i, l in enumerate(self.loss): - if l["function"] is not None: - loss = l["function"](sr, hr) - effective_loss = l["weight"] * loss - losses.append(effective_loss) - self.log[-1, i] += effective_loss.item() - elif l["type"] == "DIS": - self.log[-1, i] += self.loss[i - 1]["function"].loss - - loss_sum = sum(losses) - if len(self.loss) > 1: - self.log[-1, -1] += loss_sum.item() - - return loss_sum - - def step(self): - for l in self.get_loss_module(): - if hasattr(l, "scheduler"): - l.scheduler.step() - - def start_log(self): - self.log = torch.cat((self.log, torch.zeros(1, len(self.loss)))) - - def end_log(self, n_batches): - self.log[-1].div_(n_batches) - - def display_loss(self, batch): - n_samples = batch + 1 - log = [] - for l, c in zip(self.loss, self.log[-1]): - log.append("[{}: {:.4f}]".format(l["type"], c / n_samples)) - - return "".join(log) - - def get_loss_module(self): - if self.n_GPUs == 1: - return self.loss_module - else: - return self.loss_module.module - - def save(self, apath): - torch.save(self.state_dict(), os.path.join(apath, "loss.pt")) - torch.save(self.log, os.path.join(apath, "loss_log.pt")) - - def load(self, apath, cpu=False): - if cpu: - kwargs = {"map_location": lambda storage, loc: storage} - else: - kwargs = {} - - self.load_state_dict(torch.load( - os.path.join(apath, "loss.pt"), **kwargs)) - self.log = torch.load(os.path.join(apath, "loss_log.pt")) - for l in self.get_loss_module(): - if hasattr(l, "scheduler"): - for _ in range(len(self.log)): - l.scheduler.step() +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import os +from importlib import import_module + +import numpy as np + +import torch +import torch.nn as nn +import torch.nn.functional as F + + +class Loss(nn.modules.loss._Loss): + def __init__(self, args, ckp): + super(Loss, self).__init__() + print("Preparing loss function:") + + self.n_GPUs = args.n_GPUs + self.loss = [] + self.loss_module = nn.ModuleList() + for loss in args.loss.split("+"): + weight, loss_type = loss.split("*") + if loss_type == "MSE": + loss_function = nn.MSELoss() + elif loss_type == "L1": + loss_function = nn.L1Loss() + elif loss_type.find("VGG") >= 0: + module = import_module("loss.vgg") + loss_function = getattr(module, "VGG")( + loss_type[3:], rgb_range=args.rgb_range + ) + elif loss_type.find("GAN") >= 0: + module = import_module("loss.adversarial") + loss_function = getattr(module, "Adversarial")(args, loss_type) + + self.loss.append( + {"type": loss_type, "weight": float( + weight), "function": loss_function} + ) + if loss_type.find("GAN") >= 0: + self.loss.append( + {"type": "DIS", "weight": 1, "function": None}) + + if len(self.loss) > 1: + self.loss.append({"type": "Total", "weight": 0, "function": None}) + + for l in self.loss: + if l["function"] is not None: + print("{:.3f} * {}".format(l["weight"], l["type"])) + self.loss_module.append(l["function"]) + + self.log = torch.Tensor() + + device = torch.device("cpu" if args.cpu else "cuda") + if args.use_npu: + device = args.device + self.loss_module.to(device) + if not args.cpu and args.n_GPUs > 1: + self.loss_module = nn.DataParallel( + self.loss_module, range(args.n_GPUs)) + + if args.load != "": + self.load(ckp.dir, cpu=args.cpu) + + def forward(self, sr, hr): + losses = [] + for i, l in enumerate(self.loss): + if l["function"] is not None: + loss = l["function"](sr, hr) + effective_loss = l["weight"] * loss + losses.append(effective_loss) + self.log[-1, i] += effective_loss.item() + elif l["type"] == "DIS": + self.log[-1, i] += self.loss[i - 1]["function"].loss + + loss_sum = sum(losses) + if len(self.loss) > 1: + self.log[-1, -1] += loss_sum.item() + + return loss_sum + + def step(self): + for l in self.get_loss_module(): + if hasattr(l, "scheduler"): + l.scheduler.step() + + def start_log(self): + self.log = torch.cat((self.log, torch.zeros(1, len(self.loss)))) + + def end_log(self, n_batches): + self.log[-1].div_(n_batches) + + def display_loss(self, batch): + n_samples = batch + 1 + log = [] + for l, c in zip(self.loss, self.log[-1]): + log.append("[{}: {:.4f}]".format(l["type"], c / n_samples)) + + return "".join(log) + + def get_loss_module(self): + if self.n_GPUs == 1: + return self.loss_module + else: + return self.loss_module.module + + def save(self, apath): + torch.save(self.state_dict(), os.path.join(apath, "loss.pt")) + torch.save(self.log, os.path.join(apath, "loss_log.pt")) + + def load(self, apath, cpu=False): + if cpu: + kwargs = {"map_location": lambda storage, loc: storage} + else: + kwargs = {} + + self.load_state_dict(torch.load( + os.path.join(apath, "loss.pt"), **kwargs)) + self.log = torch.load(os.path.join(apath, "loss_log.pt")) + for l in self.get_loss_module(): + if hasattr(l, "scheduler"): + for _ in range(len(self.log)): + l.scheduler.step() diff --git a/PyTorch/contrib/cv/others/stargan/Dockerfile b/PyTorch/contrib/cv/others/stargan/Dockerfile index 7e712fe1a166790798f57a2f2762c47394beb625..30a31af55804dd79571d2a36e6107a844cb7e549 100644 --- a/PyTorch/contrib/cv/others/stargan/Dockerfile +++ b/PyTorch/contrib/cv/others/stargan/Dockerfile @@ -1,5 +1,5 @@ -ARG FROM_IMAGE_NAME -FROM $FROM_IMAGE_NAME - -COPY requirements.txt . +ARG FROM_IMAGE_NAME +FROM $FROM_IMAGE_NAME + +COPY requirements.txt . RUN pip3.7 install -r requirements.txt \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/stargan/README.md b/PyTorch/contrib/cv/others/stargan/README.md index 90ce46ed16e3bf2047a58d4f2434057875aa16c0..54be720a4bd1d865c8526a480a4ae3989c46a830 100644 --- a/PyTorch/contrib/cv/others/stargan/README.md +++ b/PyTorch/contrib/cv/others/stargan/README.md @@ -1,55 +1,55 @@ -# StarGAN 训练 -This implements training of StarGAN on the CelebA dataset. -- Reference implementation: -``` -url=https://github.com/yunjey/stargan -``` - - - -## Requirements # - -- Install Packages -- `pip install -r requirements.txt` -- The CelebA dataset can be downloaded from the [link](https://www.dropbox.com/s/d1kjpkqklf0uw77/celeba.zip?dl=0). You can use `wget` to download as well. - - `wget -N https://www.dropbox.com/s/d1kjpkqklf0uw77/celeba.zip?dl=0` -- Move the datasets to root directory and run the script `unzip_dataset.sh`. - - `bash ./unzip_dataset.sh` - - - -## Training # -To train a model, change the working directory to `./NPU`,then run: - -```bash -# 1p train perf -bash ./test/train_performance_1p.sh '[your_dataset_path]' - -# 8p train perf -bash ./test/train_performance_8p.sh '[your_dataset_path]' - -# 1p train full -bash ./test/train_full_1p.sh '[your_dataset_path]' - -# 8p train full -bash ./test/train_full_8p.sh '[your_dataset_path]' - -# finetuning -bash ./test/train_finetune_1p.sh '[your_dataset_path]' -``` -After running,you can see the results in `./NPU/stargan_full_8p/samples` or `./NPU/stargan_full_1p/samples` - - - - -## GAN training result # - -| Type | FPS | Epochs | AMP_Type | -| :------: | :------: | :------: | :------: | -| NPU-1p | 95 | 1 | O1 | -| NPU-8p | 615 | 50 | O1 | -| GPU-1p | 62 | 1 | O1 | -| GPU-8p | 517 | 50 | O1 | - - - +# StarGAN 训练 +This implements training of StarGAN on the CelebA dataset. +- Reference implementation: +``` +url=https://github.com/yunjey/stargan +``` + + + +## Requirements # + +- Install Packages +- `pip install -r requirements.txt` +- The CelebA dataset can be downloaded from the [link](https://www.dropbox.com/s/d1kjpkqklf0uw77/celeba.zip?dl=0). You can use `wget` to download as well. + - `wget -N https://www.dropbox.com/s/d1kjpkqklf0uw77/celeba.zip?dl=0` +- Move the datasets to root directory and run the script `unzip_dataset.sh`. + - `bash ./unzip_dataset.sh` + + + +## Training # +To train a model, change the working directory to `./NPU`,then run: + +```bash +# 1p train perf +bash ./test/train_performance_1p.sh '[your_dataset_path]' + +# 8p train perf +bash ./test/train_performance_8p.sh '[your_dataset_path]' + +# 1p train full +bash ./test/train_full_1p.sh '[your_dataset_path]' + +# 8p train full +bash ./test/train_full_8p.sh '[your_dataset_path]' + +# finetuning +bash ./test/train_finetune_1p.sh '[your_dataset_path]' +``` +After running,you can see the results in `./NPU/stargan_full_8p/samples` or `./NPU/stargan_full_1p/samples` + + + + +## GAN training result # + +| Type | FPS | Epochs | AMP_Type | +| :------: | :------: | :------: | :------: | +| NPU-1p | 95 | 1 | O1 | +| NPU-8p | 615 | 50 | O1 | +| GPU-1p | 62 | 1 | O1 | +| GPU-8p | 517 | 50 | O1 | + + + diff --git a/PyTorch/contrib/cv/others/stargan/docker_start.sh b/PyTorch/contrib/cv/others/stargan/docker_start.sh index 46ce9a02ec0532d6db324beaee7f7eab501b4565..944bca3cdac8e3f2d47ceb0e2b6eb181a405de11 100644 --- a/PyTorch/contrib/cv/others/stargan/docker_start.sh +++ b/PyTorch/contrib/cv/others/stargan/docker_start.sh @@ -1,25 +1,25 @@ -#!/bin/bash - -docker_image=$1 -data_dir=$2 -model_dir=$3 - -docker run -it --ipc=host \ - --device=/dev/davinci0 \ - --device=/dev/davinci1 \ - --device=/dev/davinci2 \ - --device=/dev/davinci3 \ - --device=/dev/davinci4 \ - --device=/dev/davinci5 \ - --device=/dev/davinci6 \ - --device=/dev/davinci7 \ - --device=/dev/davinci_manager \ - --device=/dev/devmm_svm --device=/dev/hisi_hdc \ - -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ - -v /usr/local/Ascend/add-ons/:/usr/local/Ascend/add-ons/ \ - -v ${model_dir}:${model_dir} \ - -v ${data_dir}:${data_dir} \ - -v /var/log/npu/conf/slog/slog.conf:/var/log/npu/conf/slog/slog.conf \ - -v /var/log/npu/slog/:/var/log/npu/slog -v /var/log/npu/profiling/:/var/log/npu/profiling \ - -v /var/log/npu/dump/:/var/log/npu/dump -v /var/log/npu/:/usr/slog ${docker_image} \ +#!/bin/bash + +docker_image=$1 +data_dir=$2 +model_dir=$3 + +docker run -it --ipc=host \ + --device=/dev/davinci0 \ + --device=/dev/davinci1 \ + --device=/dev/davinci2 \ + --device=/dev/davinci3 \ + --device=/dev/davinci4 \ + --device=/dev/davinci5 \ + --device=/dev/davinci6 \ + --device=/dev/davinci7 \ + --device=/dev/davinci_manager \ + --device=/dev/devmm_svm --device=/dev/hisi_hdc \ + -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ + -v /usr/local/Ascend/add-ons/:/usr/local/Ascend/add-ons/ \ + -v ${model_dir}:${model_dir} \ + -v ${data_dir}:${data_dir} \ + -v /var/log/npu/conf/slog/slog.conf:/var/log/npu/conf/slog/slog.conf \ + -v /var/log/npu/slog/:/var/log/npu/slog -v /var/log/npu/profiling/:/var/log/npu/profiling \ + -v /var/log/npu/dump/:/var/log/npu/dump -v /var/log/npu/:/usr/slog ${docker_image} \ /bin/bash \ No newline at end of file diff --git a/PyTorch/contrib/cv/others/stargan/modelzoo_level.txt b/PyTorch/contrib/cv/others/stargan/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/others/stargan/modelzoo_level.txt +++ b/PyTorch/contrib/cv/others/stargan/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/README_ch.md b/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/README_ch.md index 0b511652cb6e16ad0fe9b3c6e1a806cb726ba7a1..c52f043e2768c6411556e7d03dfae58b3ad5b437 100644 --- a/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/README_ch.md +++ b/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/README_ch.md @@ -56,8 +56,8 @@ ${3DMPPE_ROOTNET} ## 训练模型 - 注意,`test`目录下的`output`文件夹也会保存代码运行的日志。 -- 运行 `train_1p.py` 或 `train_8p.py` 进行模型训练: - +- 运行 `train_1p.py` 或 `train_8p.py` 进行模型训练: + ``` # 1p train perf @@ -85,7 +85,7 @@ bash test/train_full_8p.sh --data_path=xxx # 其它说明 # -- 运行 `demo.py`: +- 运行 `demo.py`: 进入 `demo` 文件夹。运行demo的输入文件已经提供(`input.jpg`),运行结束后会在该目录下得到输出的图片。将 `snapshot_XX.pth` 放置在 `./output/model_dump/` 目录下。 修改 `run_demo.sh` 中 `test_epoch` 的参数为 `XX` ,与刚才的 `.pth` 文件的数字对应。最后,运行指令: ``` diff --git a/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/README_en.md b/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/README_en.md index c8d3de5dcea4b91ba1bea185c36f5b4a1477b559..677449b5bb9ee3e49b8506547bef6a8c301eb1b9 100644 --- a/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/README_en.md +++ b/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/README_en.md @@ -41,7 +41,7 @@ ${3DMPPE_ROOTNET} | | | | |-- ... ## image files | | | |-- MuPoTS-3D.json ``` -- You need to follow directory structure of the `output` as below. +- You need to follow directory structure of the `output` as below. ``` ${3DMPPE_ROOTNET} |-- output @@ -56,7 +56,7 @@ ${3DMPPE_ROOTNET} ## Training # -- Note that the `output` folder under the `test` directory will also save the code running log. +- Note that the `output` folder under the `test` directory will also save the code running log. - To train a model, run `train_1p.py` or `train_8p.py`: ```bash @@ -85,7 +85,7 @@ bash test/train_full_8p.sh --data_path=xxx # Else # -- run `demo.py`: +- run `demo.py`: Enter the demo folder. The input file for running the demo has been provided(`input.jpg`). After running, the output pictures will be obtained in this directory. First, place `snapshot_XX.pth` in directory `./output/model_dump/`. Then, Change the parameter `test_epoch` of `run_demo.sh` to `XX` ,which corresponds to the number of `.pth` file just now. Finally, run the command: ``` diff --git a/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/common/timer.py b/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/common/timer.py index 994424e9862d51ca78ec23174bfb41dbb8a18896..3653f621de41911c573c55ae61affe375d52423e 100644 --- a/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/common/timer.py +++ b/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/common/timer.py @@ -1,53 +1,53 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -# -------------------------------------------------------- -# Fast R-CNN -# Copyright (c) 2015 Microsoft -# Licensed under The MIT License [see LICENSE for details] -# Written by Ross Girshick -# -------------------------------------------------------- - -import time - -class Timer(object): - """A simple timer.""" - def __init__(self): - self.total_time = 0. - self.calls = 0 - self.start_time = 0. - self.diff = 0. - self.average_time = 0. - self.warm_up = 0 - - def tic(self): - # using time.time instead of time.clock because time time.clock - # does not normalize for multithreading - self.start_time = time.time() - - def toc(self, average=True): - self.diff = time.time() - self.start_time - if self.warm_up < 10: - self.warm_up += 1 - return self.diff - else: - self.total_time += self.diff - self.calls += 1 - self.average_time = self.total_time / self.calls - - if average: - return self.average_time - else: - return self.diff +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +# -------------------------------------------------------- +# Fast R-CNN +# Copyright (c) 2015 Microsoft +# Licensed under The MIT License [see LICENSE for details] +# Written by Ross Girshick +# -------------------------------------------------------- + +import time + +class Timer(object): + """A simple timer.""" + def __init__(self): + self.total_time = 0. + self.calls = 0 + self.start_time = 0. + self.diff = 0. + self.average_time = 0. + self.warm_up = 0 + + def tic(self): + # using time.time instead of time.clock because time time.clock + # does not normalize for multithreading + self.start_time = time.time() + + def toc(self, average=True): + self.diff = time.time() - self.start_time + if self.warm_up < 10: + self.warm_up += 1 + return self.diff + else: + self.total_time += self.diff + self.calls += 1 + self.average_time = self.total_time / self.calls + + if average: + return self.average_time + else: + return self.diff diff --git a/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/modelzoo_level.txt b/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/modelzoo_level.txt +++ b/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/requirements.txt b/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/requirements.txt index 5655d0ed6729f55249b51c2f156d01a1689ab29c..0865b11eec36034a3bc5cf747759e41b490e8c47 100644 --- a/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/requirements.txt +++ b/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet/requirements.txt @@ -1,14 +1,14 @@ -torch==1.5.0+ascend.post3.20210930 -apex==0.1+ascend.20210930 -torchvision==0.2.2.post3 -cycler==0.10.0 -Cpython==0.29.24 -matplotlib==3.4.3 -numpy==1.21.1 -opencv-python==4.5.3.56 -Pillow==8.2.0 -pycocotools==2.0.2 -future==0.18.2 -scikit-learn==1.0 -scipy==1.7.1 +torch==1.5.0+ascend.post3.20210930 +apex==0.1+ascend.20210930 +torchvision==0.2.2.post3 +cycler==0.10.0 +Cpython==0.29.24 +matplotlib==3.4.3 +numpy==1.21.1 +opencv-python==4.5.3.56 +Pillow==8.2.0 +pycocotools==2.0.2 +future==0.18.2 +scikit-learn==1.0 +scipy==1.7.1 tqdm==4.62.3 \ No newline at end of file diff --git a/PyTorch/contrib/cv/pose_estimation/HigherHRNet/README.md b/PyTorch/contrib/cv/pose_estimation/HigherHRNet/README.md index 5faa89a351fd80dc14556f619b2cabe6ece7bcd9..4d9e9f6805eea5fe4ae5842e501e93f04f0f7b86 100644 --- a/PyTorch/contrib/cv/pose_estimation/HigherHRNet/README.md +++ b/PyTorch/contrib/cv/pose_estimation/HigherHRNet/README.md @@ -1,93 +1,93 @@ -# HigherHRNet - -This implements training of HigherHRNet on the COCO dataset, mainly modified from GitHub - HRNet/HigherHRNet-Human-Pose-Estimation - -1. Install package dependencies. Make sure the python environment >=3.7 - - ```bash - pip install -r requirements.txt - ``` -2. Install COCOAPI: - -``` -# COCOAPI=/path/to/clone/cocoapi - -git clone https://github.com/cocodataset/cocoapi.git $COCOAPI -cd $COCOAPI/PythonAPI - -# Install into global site-packages - -make install - -# Alternatively, if you do not have permissions or prefer - -# not to install the COCO API into global site-packages - -python3 setup.py install --user -Note that instructions like # COCOAPI=/path/to/install/cocoapi indicate that you should pick a path where you'd like to have the software cloned and then set an environment variable (COCOAPI in this case) accordingly. -``` - - - -3. Download pretrained models from the releases of HigherHRNet-Human-Pose-Estimation to the specified directory - - ```txt - ${POSE_ROOT} - `-- models - `-- pytorch - |-- imagenet - | `-- hrnet_w32-36af842e.pth - `-- pose_coco - `-- pose_higher_hrnet_w32_512.pth - ``` - -### Data Preparation - -Please download or link COCO to ${POSE_ROOT}/data/coco/, and make them look like this: - -```txt -${POSE_ROOT}/data/coco/ -|-- annotations -| |-- person_keypoints_train2017.json -| `-- person_keypoints_val2017.json -|-- person_detection_results -| |-- COCO_val2017_detections_AP_H_56_person.json -| `-- COCO_test-dev2017_detections_AP_H_609_person.json -`-- images - |-- train2017 - | |-- 000000000009.jpg - | |-- ... - `-- val2017 - |-- 000000000139.jpg - |-- ... -``` -## Training - -To train a model, run `main.py` with the desired model architecture and the path to the ImageNet dataset: - -```bash -# training 1p accuracy -bash ./test/train_full_1p.sh --data_path=real_data_path - -# training 1p performance -bash ./test/train_performance_1p.sh --data_path=real_data_path - -# training 8p accuracy -bash ./test/train_full_8p.sh --data_path=real_data_path - -# training 8p performance -bash ./test/train_performance_8p.sh --data_path=real_data_path - -#test 8p accuracy -bash test/train_eval_8p.sh --data_path=real_data_path --pth_path=real_pre_train_model_path - -``` - -## HigherHRNet training result - -| 名称 | 精度 | 性能 | -| :----: | :--: | :------: | -| NPU-8p | 66.9 | 2.2s/step | -| GPU-8p | 67.1 | 1.2s/step | -| NPU-1p | | 1.1s/step | +# HigherHRNet + +This implements training of HigherHRNet on the COCO dataset, mainly modified from GitHub - HRNet/HigherHRNet-Human-Pose-Estimation + +1. Install package dependencies. Make sure the python environment >=3.7 + + ```bash + pip install -r requirements.txt + ``` +2. Install COCOAPI: + +``` +# COCOAPI=/path/to/clone/cocoapi + +git clone https://github.com/cocodataset/cocoapi.git $COCOAPI +cd $COCOAPI/PythonAPI + +# Install into global site-packages + +make install + +# Alternatively, if you do not have permissions or prefer + +# not to install the COCO API into global site-packages + +python3 setup.py install --user +Note that instructions like # COCOAPI=/path/to/install/cocoapi indicate that you should pick a path where you'd like to have the software cloned and then set an environment variable (COCOAPI in this case) accordingly. +``` + + + +3. Download pretrained models from the releases of HigherHRNet-Human-Pose-Estimation to the specified directory + + ```txt + ${POSE_ROOT} + `-- models + `-- pytorch + |-- imagenet + | `-- hrnet_w32-36af842e.pth + `-- pose_coco + `-- pose_higher_hrnet_w32_512.pth + ``` + +### Data Preparation + +Please download or link COCO to ${POSE_ROOT}/data/coco/, and make them look like this: + +```txt +${POSE_ROOT}/data/coco/ +|-- annotations +| |-- person_keypoints_train2017.json +| `-- person_keypoints_val2017.json +|-- person_detection_results +| |-- COCO_val2017_detections_AP_H_56_person.json +| `-- COCO_test-dev2017_detections_AP_H_609_person.json +`-- images + |-- train2017 + | |-- 000000000009.jpg + | |-- ... + `-- val2017 + |-- 000000000139.jpg + |-- ... +``` +## Training + +To train a model, run `main.py` with the desired model architecture and the path to the ImageNet dataset: + +```bash +# training 1p accuracy +bash ./test/train_full_1p.sh --data_path=real_data_path + +# training 1p performance +bash ./test/train_performance_1p.sh --data_path=real_data_path + +# training 8p accuracy +bash ./test/train_full_8p.sh --data_path=real_data_path + +# training 8p performance +bash ./test/train_performance_8p.sh --data_path=real_data_path + +#test 8p accuracy +bash test/train_eval_8p.sh --data_path=real_data_path --pth_path=real_pre_train_model_path + +``` + +## HigherHRNet training result + +| 名称 | 精度 | 性能 | +| :----: | :--: | :------: | +| NPU-8p | 66.9 | 2.2s/step | +| GPU-8p | 67.1 | 1.2s/step | +| NPU-1p | | 1.1s/step | | GPU-1p | | 0.7s/step| \ No newline at end of file diff --git a/PyTorch/contrib/cv/pose_estimation/HigherHRNet/modelzoo_level.txt b/PyTorch/contrib/cv/pose_estimation/HigherHRNet/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/pose_estimation/HigherHRNet/modelzoo_level.txt +++ b/PyTorch/contrib/cv/pose_estimation/HigherHRNet/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/pose_estimation/HigherHRNet/requirements.txt b/PyTorch/contrib/cv/pose_estimation/HigherHRNet/requirements.txt index 720188a90e23c475b75d763a66bd651a64793194..03bc1448f394f5f5dbd929e8b7a198425b58acfe 100644 --- a/PyTorch/contrib/cv/pose_estimation/HigherHRNet/requirements.txt +++ b/PyTorch/contrib/cv/pose_estimation/HigherHRNet/requirements.txt @@ -1,13 +1,13 @@ -EasyDict==1.7 -opencv-python -Cython -scipy -pandas -pyyaml -json_tricks -scikit-image -tensorboardX -yacs -cffi -munkres +EasyDict==1.7 +opencv-python +Cython +scipy +pandas +pyyaml +json_tricks +scikit-image +tensorboardX +yacs +cffi +munkres tqdm \ No newline at end of file diff --git a/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch/mmpose-master/docs/merge_docs.sh b/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch/mmpose-master/docs/merge_docs.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch/mmpose-master/tests/data/interhand2d/test_interhand2d_camera.json b/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch/mmpose-master/tests/data/interhand2d/test_interhand2d_camera.json old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch/mmpose-master/tests/data/interhand2d/test_interhand2d_data.json b/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch/mmpose-master/tests/data/interhand2d/test_interhand2d_data.json old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch/mmpose-master/tests/data/interhand2d/test_interhand2d_joint_3d.json b/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch/mmpose-master/tests/data/interhand2d/test_interhand2d_joint_3d.json old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch/mmpose-master/tests/data/panoptic/test_panoptic.json b/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch/mmpose-master/tests/data/panoptic/test_panoptic.json old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch/mmpose-master/tools/dist_test.sh b/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch/mmpose-master/tools/dist_test.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch/mmpose-master/tools/dist_train.sh b/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch/mmpose-master/tools/dist_train.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/LICENSE b/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/LICENSE index 753842b6720f7980d411ecf2c78eb4ef220b9df8..f49a4e16e68b128803cc2dcea614603632b04eac 100644 --- a/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/LICENSE +++ b/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/datasets/__init__.py b/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/datasets/__init__.py index 453a036caaabcd54ddbca118df386e4268f6574f..6147909dea67fb89ce7466da833d27c97062e5c3 100644 --- a/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/datasets/__init__.py +++ b/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/datasets/__init__.py @@ -1,14 +1,14 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # ============================================================================ \ No newline at end of file diff --git a/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/models/__init__.py b/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/models/__init__.py index 453a036caaabcd54ddbca118df386e4268f6574f..6147909dea67fb89ce7466da833d27c97062e5c3 100644 --- a/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/models/__init__.py +++ b/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/models/__init__.py @@ -1,14 +1,14 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # ============================================================================ \ No newline at end of file diff --git a/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/modelzoo_level.txt b/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/modelzoo_level.txt +++ b/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/modules/__init__.py b/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/modules/__init__.py index 453a036caaabcd54ddbca118df386e4268f6574f..6147909dea67fb89ce7466da833d27c97062e5c3 100644 --- a/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/modules/__init__.py +++ b/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/modules/__init__.py @@ -1,14 +1,14 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # ============================================================================ \ No newline at end of file diff --git a/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/multi_epochs_dataloaders.py b/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/multi_epochs_dataloaders.py index 49b9ae910a987752af23c44d4235d54e1a74334d..256ccca3c96ab7e44d267217f714a3b8d7228522 100644 --- a/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/multi_epochs_dataloaders.py +++ b/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/multi_epochs_dataloaders.py @@ -1,46 +1,46 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import torch - - -class MultiEpochsDataLoader(torch.utils.data.DataLoader): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self._DataLoader__initialized = False - self.batch_sampler = _RepeatSampler(self.batch_sampler) - self._DataLoader__initialized = True - self.iterator = super().__iter__() - - def __len__(self): - return len(self.batch_sampler.sampler) - - def __iter__(self): - for _ in range(len(self)): - yield next(self.iterator) - - -class _RepeatSampler(object): - """ Sampler that repeats forever. - Args: - sampler (Sampler) - """ - - def __init__(self, sampler): - self.sampler = sampler - - def __iter__(self): - while True: - yield from iter(self.sampler) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import torch + + +class MultiEpochsDataLoader(torch.utils.data.DataLoader): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self._DataLoader__initialized = False + self.batch_sampler = _RepeatSampler(self.batch_sampler) + self._DataLoader__initialized = True + self.iterator = super().__iter__() + + def __len__(self): + return len(self.batch_sampler.sampler) + + def __iter__(self): + for _ in range(len(self)): + yield next(self.iterator) + + +class _RepeatSampler(object): + """ Sampler that repeats forever. + Args: + sampler (Sampler) + """ + + def __init__(self, sampler): + self.sampler = sampler + + def __iter__(self): + while True: + yield from iter(self.sampler) diff --git a/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/requirements.txt b/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/requirements.txt index 279fbeb14a7d2d6eb23261c89567549beb078bed..aa1d3fb15f1c63aa0f1b11501b354d4770b42da3 100644 --- a/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/requirements.txt +++ b/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose/requirements.txt @@ -1,2 +1,2 @@ -opencv-python -pycocotools==2.0.2 +opencv-python +pycocotools==2.0.2 diff --git a/PyTorch/contrib/cv/pose_estimation/MSPN/dataset/MPII/mpii.py b/PyTorch/contrib/cv/pose_estimation/MSPN/dataset/MPII/mpii.py index 58f7422a2617f27af3f7c0ffc195cda5480ff2d7..42d224cdb8b3019f0892b90494a464085667e443 100644 --- a/PyTorch/contrib/cv/pose_estimation/MSPN/dataset/MPII/mpii.py +++ b/PyTorch/contrib/cv/pose_estimation/MSPN/dataset/MPII/mpii.py @@ -1,198 +1,198 @@ -# encoding: utf-8 -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -""" -@author: Wenbo Li -@contact: fenglinglwb@gmail.com -""" - -import cv2 -import json -import numpy as np -import os -from scipy.io import loadmat -from collections import OrderedDict - -from dataset.JointsDataset import JointsDataset - -class MPIIDataset(JointsDataset): - - def __init__(self, DATASET, stage, transform=None): - super().__init__(DATASET, stage, transform) - self.cur_dir = os.path.split(os.path.realpath(__file__))[0] - - self.train_gt_file = 'train.json' - self.train_gt_path = os.path.join(self.cur_dir, 'gt_json', - self.train_gt_file) - - self.val_gt_file = 'valid.json' - self.val_gt_path = os.path.join(self.cur_dir, 'gt_json', - self.val_gt_file) - self.val_gt_mat = os.path.join(self.cur_dir, 'gt_json', 'valid.mat') - - self.test_det_file = 'test.json' - self.test_det_path = os.path.join(self.cur_dir, 'det_json', - self.test_det_file) - - self.data = self._get_data() - self.data_num = len(self.data) - - def _get_data(self): - data = list() - - if self.stage == 'train': - mpii = json.load(open(self.train_gt_path)) - elif self.stage == 'val': - mpii = json.load(open(self.val_gt_path)) - else: - mpii = json.load(open(self.test_det_path)) - - for d in mpii: - img_name = d['image'] - img_id = img_name.split('.')[0] - img_path = os.path.join(self.cur_dir, 'images', img_name) - - center = np.array(d['center'], dtype=np.float32) - scale = np.array([d['scale'], d['scale']], dtype=np.float32) - - if center[0] != -1: - center[1] = center[1] + 15 * scale[1] - center -= 1 - - if self.stage == 'test': - joints = np.zeros((self.keypoint_num, 3), dtype=np.float32) - else: - joints = np.array(d['joints'], dtype=np.float32) - joints -= 1 - joints_vis = np.array(d['joints_vis'], dtype=np.float32) - joints_vis = joints_vis.reshape(-1, 1) * 2 - joints = np.concatenate((joints, joints_vis), axis=1) - - data.append(dict(center=center, - img_id=img_id, - img_path=img_path, - img_name=img_name, - joints=joints, - scale=scale)) - - return data - - # referring msra high resolution - def evaluate(self, preds): - preds = preds[:, :, 0:2] + 1.0 - - SC_BIAS = 0.6 - threshold = 0.5 - - gt_file = os.path.join(self.val_gt_mat) - gt_dict = loadmat(gt_file) - dataset_joints = gt_dict['dataset_joints'] - jnt_missing = gt_dict['jnt_missing'] - pos_gt_src = gt_dict['pos_gt_src'] - headboxes_src = gt_dict['headboxes_src'] - - pos_pred_src = np.transpose(preds, [1, 2, 0]) - - head = np.where(dataset_joints == 'head')[1][0] - lsho = np.where(dataset_joints == 'lsho')[1][0] - lelb = np.where(dataset_joints == 'lelb')[1][0] - lwri = np.where(dataset_joints == 'lwri')[1][0] - lhip = np.where(dataset_joints == 'lhip')[1][0] - lkne = np.where(dataset_joints == 'lkne')[1][0] - lank = np.where(dataset_joints == 'lank')[1][0] - - rsho = np.where(dataset_joints == 'rsho')[1][0] - relb = np.where(dataset_joints == 'relb')[1][0] - rwri = np.where(dataset_joints == 'rwri')[1][0] - rkne = np.where(dataset_joints == 'rkne')[1][0] - rank = np.where(dataset_joints == 'rank')[1][0] - rhip = np.where(dataset_joints == 'rhip')[1][0] - - jnt_visible = 1 - jnt_missing - uv_error = pos_pred_src - pos_gt_src - uv_err = np.linalg.norm(uv_error, axis=1) - headsizes = headboxes_src[1, :, :] - headboxes_src[0, :, :] - headsizes = np.linalg.norm(headsizes, axis=0) - headsizes *= SC_BIAS - scale = np.multiply(headsizes, np.ones((len(uv_err), 1))) - scaled_uv_err = np.divide(uv_err, scale) - scaled_uv_err = np.multiply(scaled_uv_err, jnt_visible) - jnt_count = np.sum(jnt_visible, axis=1) - less_than_threshold = np.multiply((scaled_uv_err <= threshold), - jnt_visible) - PCKh = np.divide(100.*np.sum(less_than_threshold, axis=1), jnt_count) - - rng = np.arange(0, 0.5+0.01, 0.01) - pckAll = np.zeros((len(rng), 16)) - - for r in range(len(rng)): - threshold = rng[r] - less_than_threshold = np.multiply(scaled_uv_err <= threshold, - jnt_visible) - pckAll[r, :] = np.divide(100.*np.sum(less_than_threshold, axis=1), - jnt_count) - - PCKh = np.ma.array(PCKh, mask=False) - PCKh.mask[6:8] = True - - jnt_count = np.ma.array(jnt_count, mask=False) - jnt_count.mask[6:8] = True - jnt_ratio = jnt_count / np.sum(jnt_count).astype(np.float64) - - name_value = [ - ('Head', PCKh[head]), - ('Shoulder', 0.5 * (PCKh[lsho] + PCKh[rsho])), - ('Elbow', 0.5 * (PCKh[lelb] + PCKh[relb])), - ('Wrist', 0.5 * (PCKh[lwri] + PCKh[rwri])), - ('Hip', 0.5 * (PCKh[lhip] + PCKh[rhip])), - ('Knee', 0.5 * (PCKh[lkne] + PCKh[rkne])), - ('Ankle', 0.5 * (PCKh[lank] + PCKh[rank])), - ('Mean', np.sum(PCKh * jnt_ratio)), - ('Mean@0.1', np.sum(pckAll[11, :] * jnt_ratio)) - ] - name_value = OrderedDict(name_value) - - print(name_value) - - def visualize(self, img, joints, score=None): - pairs = [[0, 1], [1, 2], [2, 6], [3, 4], [3, 6], [4, 5], [6, 7], - [7, 8], [8, 9], [8, 12], [8, 13], [10, 11], [11, 12], - [13, 14], [14, 15]] - color = np.random.randint(0, 256, (self.keypoint_num, 3)).tolist() - - for i in range(self.keypoint_num): - if joints[i, 0] > 0 and joints[i, 1] > 0: - cv2.circle(img, tuple(joints[i, :2]), 2, tuple(color[i]), 2) - if score: - cv2.putText(img, score, (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1.2, - (128, 255, 0), 2) - - def draw_line(img, p1, p2): - c = (0, 0, 255) - if p1[0] > 0 and p1[1] > 0 and p2[0] > 0 and p2[1] > 0: - cv2.line(img, tuple(p1), tuple(p2), c, 2) - - for pair in pairs: - draw_line(img, joints[pair[0] - 1], joints[pair[1] - 1]) - - return img - - -if __name__ == '__main__': - from dataset.attribute import load_dataset - dataset = load_dataset('MPII') - mpii = MPIIDataset(dataset, 'val') - print(mpii.data_num) - +# encoding: utf-8 +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +""" +@author: Wenbo Li +@contact: fenglinglwb@gmail.com +""" + +import cv2 +import json +import numpy as np +import os +from scipy.io import loadmat +from collections import OrderedDict + +from dataset.JointsDataset import JointsDataset + +class MPIIDataset(JointsDataset): + + def __init__(self, DATASET, stage, transform=None): + super().__init__(DATASET, stage, transform) + self.cur_dir = os.path.split(os.path.realpath(__file__))[0] + + self.train_gt_file = 'train.json' + self.train_gt_path = os.path.join(self.cur_dir, 'gt_json', + self.train_gt_file) + + self.val_gt_file = 'valid.json' + self.val_gt_path = os.path.join(self.cur_dir, 'gt_json', + self.val_gt_file) + self.val_gt_mat = os.path.join(self.cur_dir, 'gt_json', 'valid.mat') + + self.test_det_file = 'test.json' + self.test_det_path = os.path.join(self.cur_dir, 'det_json', + self.test_det_file) + + self.data = self._get_data() + self.data_num = len(self.data) + + def _get_data(self): + data = list() + + if self.stage == 'train': + mpii = json.load(open(self.train_gt_path)) + elif self.stage == 'val': + mpii = json.load(open(self.val_gt_path)) + else: + mpii = json.load(open(self.test_det_path)) + + for d in mpii: + img_name = d['image'] + img_id = img_name.split('.')[0] + img_path = os.path.join(self.cur_dir, 'images', img_name) + + center = np.array(d['center'], dtype=np.float32) + scale = np.array([d['scale'], d['scale']], dtype=np.float32) + + if center[0] != -1: + center[1] = center[1] + 15 * scale[1] + center -= 1 + + if self.stage == 'test': + joints = np.zeros((self.keypoint_num, 3), dtype=np.float32) + else: + joints = np.array(d['joints'], dtype=np.float32) + joints -= 1 + joints_vis = np.array(d['joints_vis'], dtype=np.float32) + joints_vis = joints_vis.reshape(-1, 1) * 2 + joints = np.concatenate((joints, joints_vis), axis=1) + + data.append(dict(center=center, + img_id=img_id, + img_path=img_path, + img_name=img_name, + joints=joints, + scale=scale)) + + return data + + # referring msra high resolution + def evaluate(self, preds): + preds = preds[:, :, 0:2] + 1.0 + + SC_BIAS = 0.6 + threshold = 0.5 + + gt_file = os.path.join(self.val_gt_mat) + gt_dict = loadmat(gt_file) + dataset_joints = gt_dict['dataset_joints'] + jnt_missing = gt_dict['jnt_missing'] + pos_gt_src = gt_dict['pos_gt_src'] + headboxes_src = gt_dict['headboxes_src'] + + pos_pred_src = np.transpose(preds, [1, 2, 0]) + + head = np.where(dataset_joints == 'head')[1][0] + lsho = np.where(dataset_joints == 'lsho')[1][0] + lelb = np.where(dataset_joints == 'lelb')[1][0] + lwri = np.where(dataset_joints == 'lwri')[1][0] + lhip = np.where(dataset_joints == 'lhip')[1][0] + lkne = np.where(dataset_joints == 'lkne')[1][0] + lank = np.where(dataset_joints == 'lank')[1][0] + + rsho = np.where(dataset_joints == 'rsho')[1][0] + relb = np.where(dataset_joints == 'relb')[1][0] + rwri = np.where(dataset_joints == 'rwri')[1][0] + rkne = np.where(dataset_joints == 'rkne')[1][0] + rank = np.where(dataset_joints == 'rank')[1][0] + rhip = np.where(dataset_joints == 'rhip')[1][0] + + jnt_visible = 1 - jnt_missing + uv_error = pos_pred_src - pos_gt_src + uv_err = np.linalg.norm(uv_error, axis=1) + headsizes = headboxes_src[1, :, :] - headboxes_src[0, :, :] + headsizes = np.linalg.norm(headsizes, axis=0) + headsizes *= SC_BIAS + scale = np.multiply(headsizes, np.ones((len(uv_err), 1))) + scaled_uv_err = np.divide(uv_err, scale) + scaled_uv_err = np.multiply(scaled_uv_err, jnt_visible) + jnt_count = np.sum(jnt_visible, axis=1) + less_than_threshold = np.multiply((scaled_uv_err <= threshold), + jnt_visible) + PCKh = np.divide(100.*np.sum(less_than_threshold, axis=1), jnt_count) + + rng = np.arange(0, 0.5+0.01, 0.01) + pckAll = np.zeros((len(rng), 16)) + + for r in range(len(rng)): + threshold = rng[r] + less_than_threshold = np.multiply(scaled_uv_err <= threshold, + jnt_visible) + pckAll[r, :] = np.divide(100.*np.sum(less_than_threshold, axis=1), + jnt_count) + + PCKh = np.ma.array(PCKh, mask=False) + PCKh.mask[6:8] = True + + jnt_count = np.ma.array(jnt_count, mask=False) + jnt_count.mask[6:8] = True + jnt_ratio = jnt_count / np.sum(jnt_count).astype(np.float64) + + name_value = [ + ('Head', PCKh[head]), + ('Shoulder', 0.5 * (PCKh[lsho] + PCKh[rsho])), + ('Elbow', 0.5 * (PCKh[lelb] + PCKh[relb])), + ('Wrist', 0.5 * (PCKh[lwri] + PCKh[rwri])), + ('Hip', 0.5 * (PCKh[lhip] + PCKh[rhip])), + ('Knee', 0.5 * (PCKh[lkne] + PCKh[rkne])), + ('Ankle', 0.5 * (PCKh[lank] + PCKh[rank])), + ('Mean', np.sum(PCKh * jnt_ratio)), + ('Mean@0.1', np.sum(pckAll[11, :] * jnt_ratio)) + ] + name_value = OrderedDict(name_value) + + print(name_value) + + def visualize(self, img, joints, score=None): + pairs = [[0, 1], [1, 2], [2, 6], [3, 4], [3, 6], [4, 5], [6, 7], + [7, 8], [8, 9], [8, 12], [8, 13], [10, 11], [11, 12], + [13, 14], [14, 15]] + color = np.random.randint(0, 256, (self.keypoint_num, 3)).tolist() + + for i in range(self.keypoint_num): + if joints[i, 0] > 0 and joints[i, 1] > 0: + cv2.circle(img, tuple(joints[i, :2]), 2, tuple(color[i]), 2) + if score: + cv2.putText(img, score, (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1.2, + (128, 255, 0), 2) + + def draw_line(img, p1, p2): + c = (0, 0, 255) + if p1[0] > 0 and p1[1] > 0 and p2[0] > 0 and p2[1] > 0: + cv2.line(img, tuple(p1), tuple(p2), c, 2) + + for pair in pairs: + draw_line(img, joints[pair[0] - 1], joints[pair[1] - 1]) + + return img + + +if __name__ == '__main__': + from dataset.attribute import load_dataset + dataset = load_dataset('MPII') + mpii = MPIIDataset(dataset, 'val') + print(mpii.data_num) + diff --git a/PyTorch/contrib/cv/semantic_segmentation/3DUNet/docker/r.txt b/PyTorch/contrib/cv/semantic_segmentation/3DUNet/docker/r.txt index 37416fff58f8fc989cc253859dd432f9a15e7a4e..ad452c9c59521eaaf81944da89a56925871f6413 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/3DUNet/docker/r.txt +++ b/PyTorch/contrib/cv/semantic_segmentation/3DUNet/docker/r.txt @@ -1,10 +1,10 @@ -scipy>=1.4.1 -numpy>=1.18.2 - -nibabel>=3.0.2 -tensorboard>=2.2.0 -torchsummary>=1.5.1 -torchnet>=0.0.4 -matplotlib>=3.2.1 -Pillow>=7.0.0 - +scipy>=1.4.1 +numpy>=1.18.2 + +nibabel>=3.0.2 +tensorboard>=2.2.0 +torchsummary>=1.5.1 +torchnet>=0.0.4 +matplotlib>=3.2.1 +Pillow>=7.0.0 + diff --git a/PyTorch/contrib/cv/semantic_segmentation/3DUNet/lib/medloaders/multi_epochs_dataloader.py b/PyTorch/contrib/cv/semantic_segmentation/3DUNet/lib/medloaders/multi_epochs_dataloader.py index 49b9ae910a987752af23c44d4235d54e1a74334d..256ccca3c96ab7e44d267217f714a3b8d7228522 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/3DUNet/lib/medloaders/multi_epochs_dataloader.py +++ b/PyTorch/contrib/cv/semantic_segmentation/3DUNet/lib/medloaders/multi_epochs_dataloader.py @@ -1,46 +1,46 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -import torch - - -class MultiEpochsDataLoader(torch.utils.data.DataLoader): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self._DataLoader__initialized = False - self.batch_sampler = _RepeatSampler(self.batch_sampler) - self._DataLoader__initialized = True - self.iterator = super().__iter__() - - def __len__(self): - return len(self.batch_sampler.sampler) - - def __iter__(self): - for _ in range(len(self)): - yield next(self.iterator) - - -class _RepeatSampler(object): - """ Sampler that repeats forever. - Args: - sampler (Sampler) - """ - - def __init__(self, sampler): - self.sampler = sampler - - def __iter__(self): - while True: - yield from iter(self.sampler) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +import torch + + +class MultiEpochsDataLoader(torch.utils.data.DataLoader): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self._DataLoader__initialized = False + self.batch_sampler = _RepeatSampler(self.batch_sampler) + self._DataLoader__initialized = True + self.iterator = super().__iter__() + + def __len__(self): + return len(self.batch_sampler.sampler) + + def __iter__(self): + for _ in range(len(self)): + yield next(self.iterator) + + +class _RepeatSampler(object): + """ Sampler that repeats forever. + Args: + sampler (Sampler) + """ + + def __init__(self, sampler): + self.sampler = sampler + + def __iter__(self): + while True: + yield from iter(self.sampler) diff --git a/PyTorch/contrib/cv/semantic_segmentation/DeeplabV3_for_Pytorch/Dockerfile b/PyTorch/contrib/cv/semantic_segmentation/DeeplabV3_for_Pytorch/Dockerfile index 46016ca43f6b7760b2fa65a87361c1fb13ece2bc..95d754fbec64997ceb0c1c1176641d3b115217dc 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/DeeplabV3_for_Pytorch/Dockerfile +++ b/PyTorch/contrib/cv/semantic_segmentation/DeeplabV3_for_Pytorch/Dockerfile @@ -1,21 +1,21 @@ -ARG FROM_IMAGE_NAME -FROM $FROM_IMAGE_NAME -RUN mkdir ./deeplabv3_requirement -WORKDIR ./deeplabv3_requirement -COPY requirements.txt . -RUN mkdir requirements -COPY requirements/* ./requirements/ -RUN pip3.7 install -r requirements.txt -RUN apt-get update && apt-get install -y git 2to3 libgl1-mesa-glx -RUN git config --global http.sslverify false -RUN git clone -b v1.3.9 --depth=1 https://github.com/open-mmlab/mmcv.git -WORKDIR ./mmcv -ENV MMCV_WITH_OPS=1 -ENV MAX_JOBS=8 -RUN python3.7 setup.py build_ext -RUN python3.7 setup.py develop -RUN pip3.7 uninstall opencv-python -RUN pip3.7 install opencv-python-headless -COPY mmcv_need/_functions.py ./mmcv/parallel/ -COPY mmcv_need/scatter_gather.py ./mmcv/parallel/ -COPY mmcv_need/dist_utils.py ./mmcv/runner/ +ARG FROM_IMAGE_NAME +FROM $FROM_IMAGE_NAME +RUN mkdir ./deeplabv3_requirement +WORKDIR ./deeplabv3_requirement +COPY requirements.txt . +RUN mkdir requirements +COPY requirements/* ./requirements/ +RUN pip3.7 install -r requirements.txt +RUN apt-get update && apt-get install -y git 2to3 libgl1-mesa-glx +RUN git config --global http.sslverify false +RUN git clone -b v1.3.9 --depth=1 https://github.com/open-mmlab/mmcv.git +WORKDIR ./mmcv +ENV MMCV_WITH_OPS=1 +ENV MAX_JOBS=8 +RUN python3.7 setup.py build_ext +RUN python3.7 setup.py develop +RUN pip3.7 uninstall opencv-python +RUN pip3.7 install opencv-python-headless +COPY mmcv_need/_functions.py ./mmcv/parallel/ +COPY mmcv_need/scatter_gather.py ./mmcv/parallel/ +COPY mmcv_need/dist_utils.py ./mmcv/runner/ diff --git a/PyTorch/contrib/cv/semantic_segmentation/DeeplabV3_for_Pytorch/README.md b/PyTorch/contrib/cv/semantic_segmentation/DeeplabV3_for_Pytorch/README.md index d05d1035196d1290a6d8399e9168247b1db01699..c22e463aeb8484652f80fb64ae599124d2265f2a 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/DeeplabV3_for_Pytorch/README.md +++ b/PyTorch/contrib/cv/semantic_segmentation/DeeplabV3_for_Pytorch/README.md @@ -1,108 +1,108 @@ -# DeeplabV3模型使用说明 - -## Requirements -* NPU配套的run包安装 -* Python 3.7.5 -* PyTorch(NPU版本) -* apex(NPU版本) -* mmcv-full 1.3.9 - -### Dataset Prepare -1. 下载cityscapes数据集 - -2. 新建文件夹data - -3. 将cityscas数据集放于data目录下 - - ```shell - ln -s /path/to/cityscapes/ ./data - ``` - -4. 处理数据集,`**labelTrainIds.png` 被用来训练 - - ```shell - python3 tools/convert_datasets/cityscapes.py data/cityscapes --nproc 8 - # python3 tools/convert_datasets/cityscapes.py /path/to/cityscapes --nproc 8 - ``` - -### 预训练模型下载 -* 若无法自动下载,可手动下载resnet50_v1c.pth,并放到/root/.cache/torch/checkpoints/文件夹下。 - -### 脚本环境安装 -#### 运行env_set.sh脚本,进行MMCV和mmsegmentation的安装 -```shell -bash env_set.sh -``` -编译mmcv耗时较长,请耐心等待 - -### 手动环境安装 -#### Build MMSEG from source - -1. 下载项目zip文件并解压 -3. 于npu服务器解压DeeplabV3_for_PyTorch压缩包 -4. 执行以下命令,安装mmsegmentation -```shell -cd DeeplabV3_for_PyTorch -pip3.7 install -r requirements.txt -pip3.7 install -e . -pip3.7 list | grep mm -``` - - -#### Build MMCV - -##### MMCV full version with cpu -```shell -source ./test/env_npu.sh -cd .. -git clone -b v1.3.9 --depth=1 https://github.com/open-mmlab/mmcv.git -export MMCV_WITH_OPS=1 -export MAX_JOBS=8 - -cd mmcv -python3.7 setup.py build_ext -python3.7 setup.py develop -pip3.7 list | grep mmcv -# 安装opencv-python-headless, 规避cv2引入错误 -pip3.7 uninstall opencv-python -pip3.7 install opencv-python-headless -``` - -##### Modified MMCV -将mmcv_need目录下的文件替换到mmcv的安装目录下。 - -```shell -cd ../DeeplabV3_for_PyTorch -/bin/cp -f mmcv_need/_functions.py ../mmcv/mmcv/parallel/ -/bin/cp -f mmcv_need/scatter_gather.py ../mmcv/parallel/ -/bin/cp -f mmcv_need/dist_utils.py ../mmcv/mmcv/runner/ -``` - -## Training - -```shell -# training 1p accuracy -bash ./test/train_full_1p.sh --data_path=real_data_path - -# training 1p performance -bash ./test/train_performance_1p.sh --data_path=real_data_path - -# training 8p accuracy -bash ./test/train_full_8p.sh --data_path=real_data_path - -# training 8p performance -bash ./test/train_performance_8p.sh --data_path=real_data_path -``` - - -## hipcc检查问题 -若在训练模型时,有报"which: no hipcc in (/usr/local/sbin:..." 的日志打印问题, -而hipcc是amd和nvidia平台需要的,npu并不需要。 -建议在torch/utils/cpp_extension.py文件中修改代码,当检查hipcc时,抑制输出。 -将 hipcc = subprocess.check_output(['which', 'hipcc']).decode().rstrip('\r\n')修改为 -hipcc = subprocess.check_output(['which', 'hipcc'], stderr=subporcess.DEVNULL).decode().rstrip('\r\n') - -## 报No module named 'mmcv._ext'问题 -在宿主机上训练模型,有时会报No module named 'mmcv._ext'问题(按照setup.py build_ext安装一般不会遇到此问题),或者别的带有mmcv的报错。 -解决方法:这一般是因为宿主机上安装了多个版本的mmcv,而训练脚本调用到了不匹配DeeplabV3模型使用的mmcv,因此报mmcv的错误。 +# DeeplabV3模型使用说明 + +## Requirements +* NPU配套的run包安装 +* Python 3.7.5 +* PyTorch(NPU版本) +* apex(NPU版本) +* mmcv-full 1.3.9 + +### Dataset Prepare +1. 下载cityscapes数据集 + +2. 新建文件夹data + +3. 将cityscas数据集放于data目录下 + + ```shell + ln -s /path/to/cityscapes/ ./data + ``` + +4. 处理数据集,`**labelTrainIds.png` 被用来训练 + + ```shell + python3 tools/convert_datasets/cityscapes.py data/cityscapes --nproc 8 + # python3 tools/convert_datasets/cityscapes.py /path/to/cityscapes --nproc 8 + ``` + +### 预训练模型下载 +* 若无法自动下载,可手动下载resnet50_v1c.pth,并放到/root/.cache/torch/checkpoints/文件夹下。 + +### 脚本环境安装 +#### 运行env_set.sh脚本,进行MMCV和mmsegmentation的安装 +```shell +bash env_set.sh +``` +编译mmcv耗时较长,请耐心等待 + +### 手动环境安装 +#### Build MMSEG from source + +1. 下载项目zip文件并解压 +3. 于npu服务器解压DeeplabV3_for_PyTorch压缩包 +4. 执行以下命令,安装mmsegmentation +```shell +cd DeeplabV3_for_PyTorch +pip3.7 install -r requirements.txt +pip3.7 install -e . +pip3.7 list | grep mm +``` + + +#### Build MMCV + +##### MMCV full version with cpu +```shell +source ./test/env_npu.sh +cd .. +git clone -b v1.3.9 --depth=1 https://github.com/open-mmlab/mmcv.git +export MMCV_WITH_OPS=1 +export MAX_JOBS=8 + +cd mmcv +python3.7 setup.py build_ext +python3.7 setup.py develop +pip3.7 list | grep mmcv +# 安装opencv-python-headless, 规避cv2引入错误 +pip3.7 uninstall opencv-python +pip3.7 install opencv-python-headless +``` + +##### Modified MMCV +将mmcv_need目录下的文件替换到mmcv的安装目录下。 + +```shell +cd ../DeeplabV3_for_PyTorch +/bin/cp -f mmcv_need/_functions.py ../mmcv/mmcv/parallel/ +/bin/cp -f mmcv_need/scatter_gather.py ../mmcv/parallel/ +/bin/cp -f mmcv_need/dist_utils.py ../mmcv/mmcv/runner/ +``` + +## Training + +```shell +# training 1p accuracy +bash ./test/train_full_1p.sh --data_path=real_data_path + +# training 1p performance +bash ./test/train_performance_1p.sh --data_path=real_data_path + +# training 8p accuracy +bash ./test/train_full_8p.sh --data_path=real_data_path + +# training 8p performance +bash ./test/train_performance_8p.sh --data_path=real_data_path +``` + + +## hipcc检查问题 +若在训练模型时,有报"which: no hipcc in (/usr/local/sbin:..." 的日志打印问题, +而hipcc是amd和nvidia平台需要的,npu并不需要。 +建议在torch/utils/cpp_extension.py文件中修改代码,当检查hipcc时,抑制输出。 +将 hipcc = subprocess.check_output(['which', 'hipcc']).decode().rstrip('\r\n')修改为 +hipcc = subprocess.check_output(['which', 'hipcc'], stderr=subporcess.DEVNULL).decode().rstrip('\r\n') + +## 报No module named 'mmcv._ext'问题 +在宿主机上训练模型,有时会报No module named 'mmcv._ext'问题(按照setup.py build_ext安装一般不会遇到此问题),或者别的带有mmcv的报错。 +解决方法:这一般是因为宿主机上安装了多个版本的mmcv,而训练脚本调用到了不匹配DeeplabV3模型使用的mmcv,因此报mmcv的错误。 为了解决这个问题,建议在启动训练脚本前,先导入已经安装的符合DeeplabV3模型需要的mmcv路径的环境变量。export PYTHONPATH=mmcv的路径:$PYTHONPATH \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/DeeplabV3_for_Pytorch/modelzoo_level.txt b/PyTorch/contrib/cv/semantic_segmentation/DeeplabV3_for_Pytorch/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/DeeplabV3_for_Pytorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/semantic_segmentation/DeeplabV3_for_Pytorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/ENet/README.md b/PyTorch/contrib/cv/semantic_segmentation/ENet/README.md index 0299b55f7e6ce51e547e5c5b132bd2c69a5198ed..69cd3ae9a1ca69d85fd41155382641917b3be654 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/ENet/README.md +++ b/PyTorch/contrib/cv/semantic_segmentation/ENet/README.md @@ -1,52 +1,52 @@ -# ENet 训练 -This implements training of ENet on the Cityscapes dataset. -- Reference implementation: -``` -url=https://github.com/Tramac/awesome-semantic-segmentation-pytorch -``` - - - -## Requirements # - -- Install Packages -- `pip install -r requirements.txt` -- The Cityscapes dataset can be downloaded from the [link](https://www.cityscapes-dataset.com/). -- Move the datasets to root directory and run the script `unzip.sh`. - - `bash ./unzip.sh` - - - -## Training # -To train a model, change the working directory to `./NPU`,then run: - -```bash -# 1p train perf -bash ./test/train_performance_1p.sh '[your_dataset_path]' - -# 8p train perf -bash ./test/train_performance_8p.sh '[your_dataset_path]' - -# 1p train full -bash ./test/train_full_1p.sh '[your_dataset_path]' - -# 8p train full -bash ./test/train_full_8p.sh '[your_dataset_path]' - -# finetuning -bash ./test/train_finetune_1p.sh '[your_dataset_path]' -``` -After running,you can see the results in `./NPU/stargan_full_8p/samples` or `./NPU/stargan_full_1p/samples` - - - - -## GAN training result # - -| Type | FPS | Epochs | AMP_Type | -| :----: | :-----: | :----: | :------: | -| NPU-1p | 14.398 | 400 | O2 | -| NPU-8p | 74.310 | 400 | O2 | -| GPU-1p | 21.885 | 400 | O2 | -| GPU-8p | 161.495 | 400 | O2 | - +# ENet 训练 +This implements training of ENet on the Cityscapes dataset. +- Reference implementation: +``` +url=https://github.com/Tramac/awesome-semantic-segmentation-pytorch +``` + + + +## Requirements # + +- Install Packages +- `pip install -r requirements.txt` +- The Cityscapes dataset can be downloaded from the [link](https://www.cityscapes-dataset.com/). +- Move the datasets to root directory and run the script `unzip.sh`. + - `bash ./unzip.sh` + + + +## Training # +To train a model, change the working directory to `./NPU`,then run: + +```bash +# 1p train perf +bash ./test/train_performance_1p.sh '[your_dataset_path]' + +# 8p train perf +bash ./test/train_performance_8p.sh '[your_dataset_path]' + +# 1p train full +bash ./test/train_full_1p.sh '[your_dataset_path]' + +# 8p train full +bash ./test/train_full_8p.sh '[your_dataset_path]' + +# finetuning +bash ./test/train_finetune_1p.sh '[your_dataset_path]' +``` +After running,you can see the results in `./NPU/stargan_full_8p/samples` or `./NPU/stargan_full_1p/samples` + + + + +## GAN training result # + +| Type | FPS | Epochs | AMP_Type | +| :----: | :-----: | :----: | :------: | +| NPU-1p | 14.398 | 400 | O2 | +| NPU-8p | 74.310 | 400 | O2 | +| GPU-1p | 21.885 | 400 | O2 | +| GPU-8p | 161.495 | 400 | O2 | + diff --git a/PyTorch/contrib/cv/semantic_segmentation/ENet/core/__init__.py b/PyTorch/contrib/cv/semantic_segmentation/ENet/core/__init__.py index abca8fd29e3cfef8d9892aa3818a80fb7a0e110d..ee12af033180db2f910f67edba7c79891c0650f3 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/ENet/core/__init__.py +++ b/PyTorch/contrib/cv/semantic_segmentation/ENet/core/__init__.py @@ -1,15 +1,15 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from . import nn, models, utils, data \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/ENet/core/data/__init__.py b/PyTorch/contrib/cv/semantic_segmentation/ENet/core/data/__init__.py index a5f8598aa44dc6b32162d43ee60c98a1725037ef..89552b1d3f5f6255840161c8c17cf314ab3fedff 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/ENet/core/data/__init__.py +++ b/PyTorch/contrib/cv/semantic_segmentation/ENet/core/data/__init__.py @@ -1,13 +1,13 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/ENet/core/data/downloader/__init__.py b/PyTorch/contrib/cv/semantic_segmentation/ENet/core/data/downloader/__init__.py index a5f8598aa44dc6b32162d43ee60c98a1725037ef..89552b1d3f5f6255840161c8c17cf314ab3fedff 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/ENet/core/data/downloader/__init__.py +++ b/PyTorch/contrib/cv/semantic_segmentation/ENet/core/data/downloader/__init__.py @@ -1,13 +1,13 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/ENet/core/models/avg_enet.py b/PyTorch/contrib/cv/semantic_segmentation/ENet/core/models/avg_enet.py index 8a8b6838768d6f97bec0b40c112cfdba24de38e0..6a6d5c6399ed35c953450a8fd03bafcde7237cfc 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/ENet/core/models/avg_enet.py +++ b/PyTorch/contrib/cv/semantic_segmentation/ENet/core/models/avg_enet.py @@ -1,550 +1,550 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Efficient Neural Network""" -import torch -import torch.nn as nn - -__all__ = ['ENet', 'get_enet', 'get_enet_citys'] - - -class ENet(nn.Module): - """Efficient Neural Network""" - - def __init__(self, nclass, backbone='', aux=False, jpu=False, pretrained_base=None, **kwargs): - super(ENet, self).__init__() - self.initial = InitialBlock(13, **kwargs) - - self.bottleneck1_0 = Bottleneck(16, 16, 64, downsampling=True, **kwargs) - self.bottleneck1_1 = Bottleneck(64, 16, 64, **kwargs) - self.bottleneck1_2 = Bottleneck(64, 16, 64, **kwargs) - self.bottleneck1_3 = Bottleneck(64, 16, 64, **kwargs) - self.bottleneck1_4 = Bottleneck(64, 16, 64, **kwargs) - - self.bottleneck2_0 = Bottleneck(64, 32, 128, downsampling=True, **kwargs) - self.bottleneck2_1 = Bottleneck(128, 32, 128, **kwargs) - self.bottleneck2_2 = Bottleneck(128, 32, 128, dilation=2, **kwargs) - self.bottleneck2_3 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) - self.bottleneck2_4 = Bottleneck(128, 32, 128, dilation=4, **kwargs) - self.bottleneck2_5 = Bottleneck(128, 32, 128, **kwargs) - self.bottleneck2_6 = Bottleneck(128, 32, 128, dilation=8, **kwargs) - self.bottleneck2_7 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) - self.bottleneck2_8 = Bottleneck(128, 32, 128, dilation=16, **kwargs) - - self.bottleneck3_1 = Bottleneck(128, 32, 128, **kwargs) - self.bottleneck3_2 = Bottleneck(128, 32, 128, dilation=2, **kwargs) - self.bottleneck3_3 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) - self.bottleneck3_4 = Bottleneck(128, 32, 128, dilation=4, **kwargs) - self.bottleneck3_5 = Bottleneck(128, 32, 128, **kwargs) - self.bottleneck3_6 = Bottleneck(128, 32, 128, dilation=8, **kwargs) - self.bottleneck3_7 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) - self.bottleneck3_8 = Bottleneck(128, 32, 128, dilation=16, **kwargs) - - self.bottleneck4_0 = UpsamplingBottleneck(128, 16, 64, **kwargs) - self.bottleneck4_1 = Bottleneck(64, 16, 64, **kwargs) - self.bottleneck4_2 = Bottleneck(64, 16, 64, **kwargs) - - self.bottleneck5_0 = UpsamplingBottleneck(64, 4, 16, **kwargs) - self.bottleneck5_1 = Bottleneck(16, 4, 16, **kwargs) - - self.fullconv = nn.ConvTranspose2d(16, nclass, 2, 2, bias=False) - - self.__setattr__('exclusive', ['bottleneck1_0', 'bottleneck1_1', 'bottleneck1_2', 'bottleneck1_3', - 'bottleneck1_4', 'bottleneck2_0', 'bottleneck2_1', 'bottleneck2_2', - 'bottleneck2_3', 'bottleneck2_4', 'bottleneck2_5', 'bottleneck2_6', - 'bottleneck2_7', 'bottleneck2_8', 'bottleneck3_1', 'bottleneck3_2', - 'bottleneck3_3', 'bottleneck3_4', 'bottleneck3_5', 'bottleneck3_6', - 'bottleneck3_7', 'bottleneck3_8', 'bottleneck4_0', 'bottleneck4_1', - 'bottleneck4_2', 'bottleneck5_0', 'bottleneck5_1', 'fullconv']) - - def forward(self, x): - # init - x = self.initial(x) - - # stage 1 - #x, max_indices1 = self.bottleneck1_0(x) - x = self.bottleneck1_0(x) - x = self.bottleneck1_1(x) - x = self.bottleneck1_2(x) - x = self.bottleneck1_3(x) - x = self.bottleneck1_4(x) - - # stage 2 - #x, max_indices2 = self.bottleneck2_0(x) - x = self.bottleneck2_0(x) - x = self.bottleneck2_1(x) - x = self.bottleneck2_2(x) - x = self.bottleneck2_3(x) - x = self.bottleneck2_4(x) - x = self.bottleneck2_5(x) - x = self.bottleneck2_6(x) - x = self.bottleneck2_7(x) - x = self.bottleneck2_8(x) - - # stage 3 - x = self.bottleneck3_1(x) - x = self.bottleneck3_2(x) - x = self.bottleneck3_3(x) - x = self.bottleneck3_4(x) - x = self.bottleneck3_6(x) - x = self.bottleneck3_7(x) - x = self.bottleneck3_8(x) - - # stage 4 - #x = self.bottleneck4_0(x, max_indices2) - x = self.bottleneck4_0(x) - x = self.bottleneck4_1(x) - x = self.bottleneck4_2(x) - - # stage 5 - #x = self.bottleneck5_0(x, max_indices1) - x = self.bottleneck5_0(x) - x = self.bottleneck5_1(x) - - # out - x = self.fullconv(x) - return tuple([x]) - - -class InitialBlock(nn.Module): - """ENet initial block""" - - def __init__(self, out_channels, norm_layer=nn.BatchNorm2d, **kwargs): - super(InitialBlock, self).__init__() - self.conv = nn.Conv2d(3, out_channels, 3, 2, 1, bias=False) - self.maxpool = nn.MaxPool2d(2, 2) - self.bn = norm_layer(out_channels + 3) - self.act = nn.PReLU() - - def forward(self, x): - x_conv = self.conv(x) - x_pool = self.maxpool(x) - x = torch.cat([x_conv, x_pool], dim=1) - x = self.bn(x) - x = self.act(x) - return x - - -class Bottleneck(nn.Module): - """Bottlenecks include regular, asymmetric, downsampling, dilated""" - - def __init__(self, in_channels, inter_channels, out_channels, dilation=1, asymmetric=False, - downsampling=False, norm_layer=nn.BatchNorm2d, **kwargs): - self.npu = kwargs['npu'] - - super(Bottleneck, self).__init__() - self.downsamping = downsampling - if downsampling: - #self.maxpool = nn.MaxPool2d(2, 2, return_indices=True) - self.avgpool = nn.AvgPool2d((2, 2), stride=(2,2)) - self.conv_down = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 1, bias=False), - norm_layer(out_channels) - ) - - self.conv1 = nn.Sequential( - nn.Conv2d(in_channels, inter_channels, 1, bias=False), - norm_layer(inter_channels), - nn.PReLU() - ) - - if downsampling: - self.conv2 = nn.Sequential( - nn.Conv2d(inter_channels, inter_channels, 2, stride=2, bias=False), - norm_layer(inter_channels), - nn.PReLU() - ) - else: - if asymmetric: - self.conv2 = nn.Sequential( - nn.Conv2d(inter_channels, inter_channels, (5, 1), padding=(2, 0), bias=False), - nn.Conv2d(inter_channels, inter_channels, (1, 5), padding=(0, 2), bias=False), - norm_layer(inter_channels), - nn.PReLU() - ) - else: - self.conv2 = nn.Sequential( - nn.Conv2d(inter_channels, inter_channels, 3, dilation=dilation, padding=dilation, bias=False), - norm_layer(inter_channels), - nn.PReLU() - ) - self.conv3 = nn.Sequential( - nn.Conv2d(inter_channels, out_channels, 1, bias=False), - norm_layer(out_channels), - nn.Dropout2d(0.1) - ) - self.act = nn.PReLU() - - def forward(self, x): - identity = x - if self.downsamping: - ''' - if self.npu: - identity = x.cpu().to(torch.float32) - identity, max_indices = self.maxpool(identity) - identity = identity.npu().to(torch.float16) - else: - identity, max_indices = self.maxpool(identity) - ''' - identity = self.avgpool(identity) - identity = self.conv_down(identity) - - out = self.conv1(x) - out = self.conv2(out) - out = self.conv3(out) - out = self.act(out + identity) - - if self.downsamping: - return out#, max_indices - else: - return out - - -class UpsamplingBottleneck(nn.Module): - """upsampling Block""" - - def __init__(self, in_channels, inter_channels, out_channels, norm_layer=nn.BatchNorm2d, **kwargs): - self.npu = kwargs['npu'] - - super(UpsamplingBottleneck, self).__init__() - self.conv = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 1, bias=False), - norm_layer(out_channels) - ) - #self.upsampling = nn.MaxUnpool2d(2) - self.upsampling = nn.Upsample(scale_factor=2, mode='nearest') - - self.block = nn.Sequential( - nn.Conv2d(in_channels, inter_channels, 1, bias=False), - norm_layer(inter_channels), - nn.PReLU(), - nn.ConvTranspose2d(inter_channels, inter_channels, 2, 2, bias=False), - norm_layer(inter_channels), - nn.PReLU(), - nn.Conv2d(inter_channels, out_channels, 1, bias=False), - norm_layer(out_channels), - nn.Dropout2d(0.1) - ) - self.act = nn.PReLU() - - def forward(self, x):#, max_indices): - out_up = self.conv(x) - ''' - if self.npu: - out_up = out_up.to(torch.float32) - max_indices = max_indices.to(torch.int64).npu() - out_up = self.upsampling(out_up, max_indices).to(torch.half) - else: - out_up = self.upsampling(out_up, max_indices) - ''' - out_up = self.upsampling(out_up) - out_ext = self.block(x) - out = self.act(out_up + out_ext) - return out - - -def get_enet(dataset='citys', backbone='', pretrained=False, root='~/.torch/models', pretrained_base=True, **kwargs): - acronyms = { - 'pascal_voc': 'pascal_voc', - 'pascal_aug': 'pascal_aug', - 'ade20k': 'ade', - 'coco': 'coco', - 'citys': 'citys', - } - from core.data.dataloader import datasets - model = ENet(datasets[dataset].NUM_CLASS, backbone=backbone, pretrained_base=pretrained_base, **kwargs) - if pretrained: - from .model_store import get_model_file - device = torch.device(kwargs['local_rank']) - model.load_state_dict(torch.load(get_model_file('enet_%s' % (acronyms[dataset]), root=root), - map_location=device)) - return model - - -def get_enet_citys(**kwargs): - return get_enet('citys', '', **kwargs) - - -if __name__ == '__main__': - img = torch.randn(1, 3, 512, 512) - model = get_enet_citys() - output = model(img) - - -"""Efficient Neural Network""" -import torch -import torch.nn as nn - -__all__ = ['ENet', 'get_enet', 'get_enet_citys'] - - -class ENet(nn.Module): - """Efficient Neural Network""" - - def __init__(self, nclass, backbone='', aux=False, jpu=False, pretrained_base=None, **kwargs): - super(ENet, self).__init__() - self.initial = InitialBlock(13, **kwargs) - - self.bottleneck1_0 = Bottleneck(16, 16, 64, downsampling=True, **kwargs) - self.bottleneck1_1 = Bottleneck(64, 16, 64, **kwargs) - self.bottleneck1_2 = Bottleneck(64, 16, 64, **kwargs) - self.bottleneck1_3 = Bottleneck(64, 16, 64, **kwargs) - self.bottleneck1_4 = Bottleneck(64, 16, 64, **kwargs) - - self.bottleneck2_0 = Bottleneck(64, 32, 128, downsampling=True, **kwargs) - self.bottleneck2_1 = Bottleneck(128, 32, 128, **kwargs) - self.bottleneck2_2 = Bottleneck(128, 32, 128, dilation=2, **kwargs) - self.bottleneck2_3 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) - self.bottleneck2_4 = Bottleneck(128, 32, 128, dilation=4, **kwargs) - self.bottleneck2_5 = Bottleneck(128, 32, 128, **kwargs) - self.bottleneck2_6 = Bottleneck(128, 32, 128, dilation=8, **kwargs) - self.bottleneck2_7 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) - self.bottleneck2_8 = Bottleneck(128, 32, 128, dilation=16, **kwargs) - - self.bottleneck3_1 = Bottleneck(128, 32, 128, **kwargs) - self.bottleneck3_2 = Bottleneck(128, 32, 128, dilation=2, **kwargs) - self.bottleneck3_3 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) - self.bottleneck3_4 = Bottleneck(128, 32, 128, dilation=4, **kwargs) - self.bottleneck3_5 = Bottleneck(128, 32, 128, **kwargs) - self.bottleneck3_6 = Bottleneck(128, 32, 128, dilation=8, **kwargs) - self.bottleneck3_7 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) - self.bottleneck3_8 = Bottleneck(128, 32, 128, dilation=16, **kwargs) - - self.bottleneck4_0 = UpsamplingBottleneck(128, 16, 64, **kwargs) - self.bottleneck4_1 = Bottleneck(64, 16, 64, **kwargs) - self.bottleneck4_2 = Bottleneck(64, 16, 64, **kwargs) - - self.bottleneck5_0 = UpsamplingBottleneck(64, 4, 16, **kwargs) - self.bottleneck5_1 = Bottleneck(16, 4, 16, **kwargs) - - self.fullconv = nn.ConvTranspose2d(16, nclass, 2, 2, bias=False) - - self.__setattr__('exclusive', ['bottleneck1_0', 'bottleneck1_1', 'bottleneck1_2', 'bottleneck1_3', - 'bottleneck1_4', 'bottleneck2_0', 'bottleneck2_1', 'bottleneck2_2', - 'bottleneck2_3', 'bottleneck2_4', 'bottleneck2_5', 'bottleneck2_6', - 'bottleneck2_7', 'bottleneck2_8', 'bottleneck3_1', 'bottleneck3_2', - 'bottleneck3_3', 'bottleneck3_4', 'bottleneck3_5', 'bottleneck3_6', - 'bottleneck3_7', 'bottleneck3_8', 'bottleneck4_0', 'bottleneck4_1', - 'bottleneck4_2', 'bottleneck5_0', 'bottleneck5_1', 'fullconv']) - - def forward(self, x): - # init - x = self.initial(x) - - # stage 1 - x, max_indices1 = self.bottleneck1_0(x) - #x = self.bottleneck1_0(x) - x = self.bottleneck1_1(x) - x = self.bottleneck1_2(x) - x = self.bottleneck1_3(x) - x = self.bottleneck1_4(x) - - # stage 2 - x, max_indices2 = self.bottleneck2_0(x) - #x = self.bottleneck2_0(x) - x = self.bottleneck2_1(x) - x = self.bottleneck2_2(x) - x = self.bottleneck2_3(x) - x = self.bottleneck2_4(x) - x = self.bottleneck2_5(x) - x = self.bottleneck2_6(x) - x = self.bottleneck2_7(x) - x = self.bottleneck2_8(x) - - # stage 3 - x = self.bottleneck3_1(x) - x = self.bottleneck3_2(x) - x = self.bottleneck3_3(x) - x = self.bottleneck3_4(x) - x = self.bottleneck3_6(x) - x = self.bottleneck3_7(x) - x = self.bottleneck3_8(x) - - # stage 4 - x = self.bottleneck4_0(x, max_indices2) - #x = self.bottleneck4_0(x) - x = self.bottleneck4_1(x) - x = self.bottleneck4_2(x) - - # stage 5 - x = self.bottleneck5_0(x, max_indices1) - #x = self.bottleneck5_0(x) - x = self.bottleneck5_1(x) - - # out - x = self.fullconv(x) - return tuple([x]) - - -class InitialBlock(nn.Module): - """ENet initial block""" - - def __init__(self, out_channels, norm_layer=nn.BatchNorm2d, **kwargs): - super(InitialBlock, self).__init__() - self.conv = nn.Conv2d(3, out_channels, 3, 2, 1, bias=False) - self.maxpool = nn.MaxPool2d(2, 2) - self.bn = norm_layer(out_channels + 3) - self.act = nn.PReLU() - - def forward(self, x): - x_conv = self.conv(x) - x_pool = self.maxpool(x) - x = torch.cat([x_conv, x_pool], dim=1) - x = self.bn(x) - x = self.act(x) - return x - - -class Bottleneck(nn.Module): - """Bottlenecks include regular, asymmetric, downsampling, dilated""" - - def __init__(self, in_channels, inter_channels, out_channels, dilation=1, asymmetric=False, - downsampling=False, norm_layer=nn.BatchNorm2d, **kwargs): - self.npu = kwargs['npu'] - - super(Bottleneck, self).__init__() - self.downsamping = downsampling - if downsampling: - self.maxpool = nn.MaxPool2d(2, 2, return_indices=True) - #self.avgpool = nn.AvgPool2d((2, 2), stride=(2,2)) - self.conv_down = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 1, bias=False), - norm_layer(out_channels) - ) - - self.conv1 = nn.Sequential( - nn.Conv2d(in_channels, inter_channels, 1, bias=False), - norm_layer(inter_channels), - nn.PReLU() - ) - - if downsampling: - self.conv2 = nn.Sequential( - nn.Conv2d(inter_channels, inter_channels, 2, stride=2, bias=False), - norm_layer(inter_channels), - nn.PReLU() - ) - else: - if asymmetric: - self.conv2 = nn.Sequential( - nn.Conv2d(inter_channels, inter_channels, (5, 1), padding=(2, 0), bias=False), - nn.Conv2d(inter_channels, inter_channels, (1, 5), padding=(0, 2), bias=False), - norm_layer(inter_channels), - nn.PReLU() - ) - else: - self.conv2 = nn.Sequential( - nn.Conv2d(inter_channels, inter_channels, 3, dilation=dilation, padding=dilation, bias=False), - norm_layer(inter_channels), - nn.PReLU() - ) - self.conv3 = nn.Sequential( - nn.Conv2d(inter_channels, out_channels, 1, bias=False), - norm_layer(out_channels), - nn.Dropout2d(0.1) - ) - self.act = nn.PReLU() - - def forward(self, x): - identity = x - if self.downsamping: - if self.npu: - identity = x.cpu().to(torch.float32) - identity, max_indices = self.maxpool(identity) - identity = identity.npu().to(torch.float16) - else: - identity, max_indices = self.maxpool(identity) - #identity = self.avgpool(identity) - identity = self.conv_down(identity) - - out = self.conv1(x) - out = self.conv2(out) - out = self.conv3(out) - out = self.act(out + identity) - - if self.downsamping: - return out, max_indices - else: - return out - - -class UpsamplingBottleneck(nn.Module): - """upsampling Block""" - - def __init__(self, in_channels, inter_channels, out_channels, norm_layer=nn.BatchNorm2d, **kwargs): - self.npu = kwargs['npu'] - - super(UpsamplingBottleneck, self).__init__() - self.conv = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 1, bias=False), - norm_layer(out_channels) - ) - self.upsampling = nn.MaxUnpool2d(2) - #self.upsampling = nn.Upsample(scale_factor=2, mode='nearest') - - self.block = nn.Sequential( - nn.Conv2d(in_channels, inter_channels, 1, bias=False), - norm_layer(inter_channels), - nn.PReLU(), - nn.ConvTranspose2d(inter_channels, inter_channels, 2, 2, bias=False), - norm_layer(inter_channels), - nn.PReLU(), - nn.Conv2d(inter_channels, out_channels, 1, bias=False), - norm_layer(out_channels), - nn.Dropout2d(0.1) - ) - self.act = nn.PReLU() - - def forward(self, x, max_indices): - out_up = self.conv(x) - - if self.npu: - out_up = out_up.to(torch.float32) - max_indices = max_indices.to(torch.int64).npu() - out_up = self.upsampling(out_up, max_indices).to(torch.half) - else: - out_up = self.upsampling(out_up, max_indices) - - #out_up = self.upsampling(out_up) - out_ext = self.block(x) - out = self.act(out_up + out_ext) - return out - - -def get_enet(dataset='citys', backbone='', pretrained=False, root='~/.torch/models', pretrained_base=True, **kwargs): - acronyms = { - 'pascal_voc': 'pascal_voc', - 'pascal_aug': 'pascal_aug', - 'ade20k': 'ade', - 'coco': 'coco', - 'citys': 'citys', - } - from core.data.dataloader import datasets - model = ENet(datasets[dataset].NUM_CLASS, backbone=backbone, pretrained_base=pretrained_base, **kwargs) - if pretrained: - from .model_store import get_model_file - device = torch.device(kwargs['local_rank']) - model.load_state_dict(torch.load(get_model_file('enet_%s' % (acronyms[dataset]), root=root), - map_location=device)) - return model - - -def get_enet_citys(**kwargs): - return get_enet('citys', '', **kwargs) - - -if __name__ == '__main__': - img = torch.randn(1, 3, 512, 512) - model = get_enet_citys() - output = model(img) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Efficient Neural Network""" +import torch +import torch.nn as nn + +__all__ = ['ENet', 'get_enet', 'get_enet_citys'] + + +class ENet(nn.Module): + """Efficient Neural Network""" + + def __init__(self, nclass, backbone='', aux=False, jpu=False, pretrained_base=None, **kwargs): + super(ENet, self).__init__() + self.initial = InitialBlock(13, **kwargs) + + self.bottleneck1_0 = Bottleneck(16, 16, 64, downsampling=True, **kwargs) + self.bottleneck1_1 = Bottleneck(64, 16, 64, **kwargs) + self.bottleneck1_2 = Bottleneck(64, 16, 64, **kwargs) + self.bottleneck1_3 = Bottleneck(64, 16, 64, **kwargs) + self.bottleneck1_4 = Bottleneck(64, 16, 64, **kwargs) + + self.bottleneck2_0 = Bottleneck(64, 32, 128, downsampling=True, **kwargs) + self.bottleneck2_1 = Bottleneck(128, 32, 128, **kwargs) + self.bottleneck2_2 = Bottleneck(128, 32, 128, dilation=2, **kwargs) + self.bottleneck2_3 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) + self.bottleneck2_4 = Bottleneck(128, 32, 128, dilation=4, **kwargs) + self.bottleneck2_5 = Bottleneck(128, 32, 128, **kwargs) + self.bottleneck2_6 = Bottleneck(128, 32, 128, dilation=8, **kwargs) + self.bottleneck2_7 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) + self.bottleneck2_8 = Bottleneck(128, 32, 128, dilation=16, **kwargs) + + self.bottleneck3_1 = Bottleneck(128, 32, 128, **kwargs) + self.bottleneck3_2 = Bottleneck(128, 32, 128, dilation=2, **kwargs) + self.bottleneck3_3 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) + self.bottleneck3_4 = Bottleneck(128, 32, 128, dilation=4, **kwargs) + self.bottleneck3_5 = Bottleneck(128, 32, 128, **kwargs) + self.bottleneck3_6 = Bottleneck(128, 32, 128, dilation=8, **kwargs) + self.bottleneck3_7 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) + self.bottleneck3_8 = Bottleneck(128, 32, 128, dilation=16, **kwargs) + + self.bottleneck4_0 = UpsamplingBottleneck(128, 16, 64, **kwargs) + self.bottleneck4_1 = Bottleneck(64, 16, 64, **kwargs) + self.bottleneck4_2 = Bottleneck(64, 16, 64, **kwargs) + + self.bottleneck5_0 = UpsamplingBottleneck(64, 4, 16, **kwargs) + self.bottleneck5_1 = Bottleneck(16, 4, 16, **kwargs) + + self.fullconv = nn.ConvTranspose2d(16, nclass, 2, 2, bias=False) + + self.__setattr__('exclusive', ['bottleneck1_0', 'bottleneck1_1', 'bottleneck1_2', 'bottleneck1_3', + 'bottleneck1_4', 'bottleneck2_0', 'bottleneck2_1', 'bottleneck2_2', + 'bottleneck2_3', 'bottleneck2_4', 'bottleneck2_5', 'bottleneck2_6', + 'bottleneck2_7', 'bottleneck2_8', 'bottleneck3_1', 'bottleneck3_2', + 'bottleneck3_3', 'bottleneck3_4', 'bottleneck3_5', 'bottleneck3_6', + 'bottleneck3_7', 'bottleneck3_8', 'bottleneck4_0', 'bottleneck4_1', + 'bottleneck4_2', 'bottleneck5_0', 'bottleneck5_1', 'fullconv']) + + def forward(self, x): + # init + x = self.initial(x) + + # stage 1 + #x, max_indices1 = self.bottleneck1_0(x) + x = self.bottleneck1_0(x) + x = self.bottleneck1_1(x) + x = self.bottleneck1_2(x) + x = self.bottleneck1_3(x) + x = self.bottleneck1_4(x) + + # stage 2 + #x, max_indices2 = self.bottleneck2_0(x) + x = self.bottleneck2_0(x) + x = self.bottleneck2_1(x) + x = self.bottleneck2_2(x) + x = self.bottleneck2_3(x) + x = self.bottleneck2_4(x) + x = self.bottleneck2_5(x) + x = self.bottleneck2_6(x) + x = self.bottleneck2_7(x) + x = self.bottleneck2_8(x) + + # stage 3 + x = self.bottleneck3_1(x) + x = self.bottleneck3_2(x) + x = self.bottleneck3_3(x) + x = self.bottleneck3_4(x) + x = self.bottleneck3_6(x) + x = self.bottleneck3_7(x) + x = self.bottleneck3_8(x) + + # stage 4 + #x = self.bottleneck4_0(x, max_indices2) + x = self.bottleneck4_0(x) + x = self.bottleneck4_1(x) + x = self.bottleneck4_2(x) + + # stage 5 + #x = self.bottleneck5_0(x, max_indices1) + x = self.bottleneck5_0(x) + x = self.bottleneck5_1(x) + + # out + x = self.fullconv(x) + return tuple([x]) + + +class InitialBlock(nn.Module): + """ENet initial block""" + + def __init__(self, out_channels, norm_layer=nn.BatchNorm2d, **kwargs): + super(InitialBlock, self).__init__() + self.conv = nn.Conv2d(3, out_channels, 3, 2, 1, bias=False) + self.maxpool = nn.MaxPool2d(2, 2) + self.bn = norm_layer(out_channels + 3) + self.act = nn.PReLU() + + def forward(self, x): + x_conv = self.conv(x) + x_pool = self.maxpool(x) + x = torch.cat([x_conv, x_pool], dim=1) + x = self.bn(x) + x = self.act(x) + return x + + +class Bottleneck(nn.Module): + """Bottlenecks include regular, asymmetric, downsampling, dilated""" + + def __init__(self, in_channels, inter_channels, out_channels, dilation=1, asymmetric=False, + downsampling=False, norm_layer=nn.BatchNorm2d, **kwargs): + self.npu = kwargs['npu'] + + super(Bottleneck, self).__init__() + self.downsamping = downsampling + if downsampling: + #self.maxpool = nn.MaxPool2d(2, 2, return_indices=True) + self.avgpool = nn.AvgPool2d((2, 2), stride=(2,2)) + self.conv_down = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 1, bias=False), + norm_layer(out_channels) + ) + + self.conv1 = nn.Sequential( + nn.Conv2d(in_channels, inter_channels, 1, bias=False), + norm_layer(inter_channels), + nn.PReLU() + ) + + if downsampling: + self.conv2 = nn.Sequential( + nn.Conv2d(inter_channels, inter_channels, 2, stride=2, bias=False), + norm_layer(inter_channels), + nn.PReLU() + ) + else: + if asymmetric: + self.conv2 = nn.Sequential( + nn.Conv2d(inter_channels, inter_channels, (5, 1), padding=(2, 0), bias=False), + nn.Conv2d(inter_channels, inter_channels, (1, 5), padding=(0, 2), bias=False), + norm_layer(inter_channels), + nn.PReLU() + ) + else: + self.conv2 = nn.Sequential( + nn.Conv2d(inter_channels, inter_channels, 3, dilation=dilation, padding=dilation, bias=False), + norm_layer(inter_channels), + nn.PReLU() + ) + self.conv3 = nn.Sequential( + nn.Conv2d(inter_channels, out_channels, 1, bias=False), + norm_layer(out_channels), + nn.Dropout2d(0.1) + ) + self.act = nn.PReLU() + + def forward(self, x): + identity = x + if self.downsamping: + ''' + if self.npu: + identity = x.cpu().to(torch.float32) + identity, max_indices = self.maxpool(identity) + identity = identity.npu().to(torch.float16) + else: + identity, max_indices = self.maxpool(identity) + ''' + identity = self.avgpool(identity) + identity = self.conv_down(identity) + + out = self.conv1(x) + out = self.conv2(out) + out = self.conv3(out) + out = self.act(out + identity) + + if self.downsamping: + return out#, max_indices + else: + return out + + +class UpsamplingBottleneck(nn.Module): + """upsampling Block""" + + def __init__(self, in_channels, inter_channels, out_channels, norm_layer=nn.BatchNorm2d, **kwargs): + self.npu = kwargs['npu'] + + super(UpsamplingBottleneck, self).__init__() + self.conv = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 1, bias=False), + norm_layer(out_channels) + ) + #self.upsampling = nn.MaxUnpool2d(2) + self.upsampling = nn.Upsample(scale_factor=2, mode='nearest') + + self.block = nn.Sequential( + nn.Conv2d(in_channels, inter_channels, 1, bias=False), + norm_layer(inter_channels), + nn.PReLU(), + nn.ConvTranspose2d(inter_channels, inter_channels, 2, 2, bias=False), + norm_layer(inter_channels), + nn.PReLU(), + nn.Conv2d(inter_channels, out_channels, 1, bias=False), + norm_layer(out_channels), + nn.Dropout2d(0.1) + ) + self.act = nn.PReLU() + + def forward(self, x):#, max_indices): + out_up = self.conv(x) + ''' + if self.npu: + out_up = out_up.to(torch.float32) + max_indices = max_indices.to(torch.int64).npu() + out_up = self.upsampling(out_up, max_indices).to(torch.half) + else: + out_up = self.upsampling(out_up, max_indices) + ''' + out_up = self.upsampling(out_up) + out_ext = self.block(x) + out = self.act(out_up + out_ext) + return out + + +def get_enet(dataset='citys', backbone='', pretrained=False, root='~/.torch/models', pretrained_base=True, **kwargs): + acronyms = { + 'pascal_voc': 'pascal_voc', + 'pascal_aug': 'pascal_aug', + 'ade20k': 'ade', + 'coco': 'coco', + 'citys': 'citys', + } + from core.data.dataloader import datasets + model = ENet(datasets[dataset].NUM_CLASS, backbone=backbone, pretrained_base=pretrained_base, **kwargs) + if pretrained: + from .model_store import get_model_file + device = torch.device(kwargs['local_rank']) + model.load_state_dict(torch.load(get_model_file('enet_%s' % (acronyms[dataset]), root=root), + map_location=device)) + return model + + +def get_enet_citys(**kwargs): + return get_enet('citys', '', **kwargs) + + +if __name__ == '__main__': + img = torch.randn(1, 3, 512, 512) + model = get_enet_citys() + output = model(img) + + +"""Efficient Neural Network""" +import torch +import torch.nn as nn + +__all__ = ['ENet', 'get_enet', 'get_enet_citys'] + + +class ENet(nn.Module): + """Efficient Neural Network""" + + def __init__(self, nclass, backbone='', aux=False, jpu=False, pretrained_base=None, **kwargs): + super(ENet, self).__init__() + self.initial = InitialBlock(13, **kwargs) + + self.bottleneck1_0 = Bottleneck(16, 16, 64, downsampling=True, **kwargs) + self.bottleneck1_1 = Bottleneck(64, 16, 64, **kwargs) + self.bottleneck1_2 = Bottleneck(64, 16, 64, **kwargs) + self.bottleneck1_3 = Bottleneck(64, 16, 64, **kwargs) + self.bottleneck1_4 = Bottleneck(64, 16, 64, **kwargs) + + self.bottleneck2_0 = Bottleneck(64, 32, 128, downsampling=True, **kwargs) + self.bottleneck2_1 = Bottleneck(128, 32, 128, **kwargs) + self.bottleneck2_2 = Bottleneck(128, 32, 128, dilation=2, **kwargs) + self.bottleneck2_3 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) + self.bottleneck2_4 = Bottleneck(128, 32, 128, dilation=4, **kwargs) + self.bottleneck2_5 = Bottleneck(128, 32, 128, **kwargs) + self.bottleneck2_6 = Bottleneck(128, 32, 128, dilation=8, **kwargs) + self.bottleneck2_7 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) + self.bottleneck2_8 = Bottleneck(128, 32, 128, dilation=16, **kwargs) + + self.bottleneck3_1 = Bottleneck(128, 32, 128, **kwargs) + self.bottleneck3_2 = Bottleneck(128, 32, 128, dilation=2, **kwargs) + self.bottleneck3_3 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) + self.bottleneck3_4 = Bottleneck(128, 32, 128, dilation=4, **kwargs) + self.bottleneck3_5 = Bottleneck(128, 32, 128, **kwargs) + self.bottleneck3_6 = Bottleneck(128, 32, 128, dilation=8, **kwargs) + self.bottleneck3_7 = Bottleneck(128, 32, 128, asymmetric=True, **kwargs) + self.bottleneck3_8 = Bottleneck(128, 32, 128, dilation=16, **kwargs) + + self.bottleneck4_0 = UpsamplingBottleneck(128, 16, 64, **kwargs) + self.bottleneck4_1 = Bottleneck(64, 16, 64, **kwargs) + self.bottleneck4_2 = Bottleneck(64, 16, 64, **kwargs) + + self.bottleneck5_0 = UpsamplingBottleneck(64, 4, 16, **kwargs) + self.bottleneck5_1 = Bottleneck(16, 4, 16, **kwargs) + + self.fullconv = nn.ConvTranspose2d(16, nclass, 2, 2, bias=False) + + self.__setattr__('exclusive', ['bottleneck1_0', 'bottleneck1_1', 'bottleneck1_2', 'bottleneck1_3', + 'bottleneck1_4', 'bottleneck2_0', 'bottleneck2_1', 'bottleneck2_2', + 'bottleneck2_3', 'bottleneck2_4', 'bottleneck2_5', 'bottleneck2_6', + 'bottleneck2_7', 'bottleneck2_8', 'bottleneck3_1', 'bottleneck3_2', + 'bottleneck3_3', 'bottleneck3_4', 'bottleneck3_5', 'bottleneck3_6', + 'bottleneck3_7', 'bottleneck3_8', 'bottleneck4_0', 'bottleneck4_1', + 'bottleneck4_2', 'bottleneck5_0', 'bottleneck5_1', 'fullconv']) + + def forward(self, x): + # init + x = self.initial(x) + + # stage 1 + x, max_indices1 = self.bottleneck1_0(x) + #x = self.bottleneck1_0(x) + x = self.bottleneck1_1(x) + x = self.bottleneck1_2(x) + x = self.bottleneck1_3(x) + x = self.bottleneck1_4(x) + + # stage 2 + x, max_indices2 = self.bottleneck2_0(x) + #x = self.bottleneck2_0(x) + x = self.bottleneck2_1(x) + x = self.bottleneck2_2(x) + x = self.bottleneck2_3(x) + x = self.bottleneck2_4(x) + x = self.bottleneck2_5(x) + x = self.bottleneck2_6(x) + x = self.bottleneck2_7(x) + x = self.bottleneck2_8(x) + + # stage 3 + x = self.bottleneck3_1(x) + x = self.bottleneck3_2(x) + x = self.bottleneck3_3(x) + x = self.bottleneck3_4(x) + x = self.bottleneck3_6(x) + x = self.bottleneck3_7(x) + x = self.bottleneck3_8(x) + + # stage 4 + x = self.bottleneck4_0(x, max_indices2) + #x = self.bottleneck4_0(x) + x = self.bottleneck4_1(x) + x = self.bottleneck4_2(x) + + # stage 5 + x = self.bottleneck5_0(x, max_indices1) + #x = self.bottleneck5_0(x) + x = self.bottleneck5_1(x) + + # out + x = self.fullconv(x) + return tuple([x]) + + +class InitialBlock(nn.Module): + """ENet initial block""" + + def __init__(self, out_channels, norm_layer=nn.BatchNorm2d, **kwargs): + super(InitialBlock, self).__init__() + self.conv = nn.Conv2d(3, out_channels, 3, 2, 1, bias=False) + self.maxpool = nn.MaxPool2d(2, 2) + self.bn = norm_layer(out_channels + 3) + self.act = nn.PReLU() + + def forward(self, x): + x_conv = self.conv(x) + x_pool = self.maxpool(x) + x = torch.cat([x_conv, x_pool], dim=1) + x = self.bn(x) + x = self.act(x) + return x + + +class Bottleneck(nn.Module): + """Bottlenecks include regular, asymmetric, downsampling, dilated""" + + def __init__(self, in_channels, inter_channels, out_channels, dilation=1, asymmetric=False, + downsampling=False, norm_layer=nn.BatchNorm2d, **kwargs): + self.npu = kwargs['npu'] + + super(Bottleneck, self).__init__() + self.downsamping = downsampling + if downsampling: + self.maxpool = nn.MaxPool2d(2, 2, return_indices=True) + #self.avgpool = nn.AvgPool2d((2, 2), stride=(2,2)) + self.conv_down = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 1, bias=False), + norm_layer(out_channels) + ) + + self.conv1 = nn.Sequential( + nn.Conv2d(in_channels, inter_channels, 1, bias=False), + norm_layer(inter_channels), + nn.PReLU() + ) + + if downsampling: + self.conv2 = nn.Sequential( + nn.Conv2d(inter_channels, inter_channels, 2, stride=2, bias=False), + norm_layer(inter_channels), + nn.PReLU() + ) + else: + if asymmetric: + self.conv2 = nn.Sequential( + nn.Conv2d(inter_channels, inter_channels, (5, 1), padding=(2, 0), bias=False), + nn.Conv2d(inter_channels, inter_channels, (1, 5), padding=(0, 2), bias=False), + norm_layer(inter_channels), + nn.PReLU() + ) + else: + self.conv2 = nn.Sequential( + nn.Conv2d(inter_channels, inter_channels, 3, dilation=dilation, padding=dilation, bias=False), + norm_layer(inter_channels), + nn.PReLU() + ) + self.conv3 = nn.Sequential( + nn.Conv2d(inter_channels, out_channels, 1, bias=False), + norm_layer(out_channels), + nn.Dropout2d(0.1) + ) + self.act = nn.PReLU() + + def forward(self, x): + identity = x + if self.downsamping: + if self.npu: + identity = x.cpu().to(torch.float32) + identity, max_indices = self.maxpool(identity) + identity = identity.npu().to(torch.float16) + else: + identity, max_indices = self.maxpool(identity) + #identity = self.avgpool(identity) + identity = self.conv_down(identity) + + out = self.conv1(x) + out = self.conv2(out) + out = self.conv3(out) + out = self.act(out + identity) + + if self.downsamping: + return out, max_indices + else: + return out + + +class UpsamplingBottleneck(nn.Module): + """upsampling Block""" + + def __init__(self, in_channels, inter_channels, out_channels, norm_layer=nn.BatchNorm2d, **kwargs): + self.npu = kwargs['npu'] + + super(UpsamplingBottleneck, self).__init__() + self.conv = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 1, bias=False), + norm_layer(out_channels) + ) + self.upsampling = nn.MaxUnpool2d(2) + #self.upsampling = nn.Upsample(scale_factor=2, mode='nearest') + + self.block = nn.Sequential( + nn.Conv2d(in_channels, inter_channels, 1, bias=False), + norm_layer(inter_channels), + nn.PReLU(), + nn.ConvTranspose2d(inter_channels, inter_channels, 2, 2, bias=False), + norm_layer(inter_channels), + nn.PReLU(), + nn.Conv2d(inter_channels, out_channels, 1, bias=False), + norm_layer(out_channels), + nn.Dropout2d(0.1) + ) + self.act = nn.PReLU() + + def forward(self, x, max_indices): + out_up = self.conv(x) + + if self.npu: + out_up = out_up.to(torch.float32) + max_indices = max_indices.to(torch.int64).npu() + out_up = self.upsampling(out_up, max_indices).to(torch.half) + else: + out_up = self.upsampling(out_up, max_indices) + + #out_up = self.upsampling(out_up) + out_ext = self.block(x) + out = self.act(out_up + out_ext) + return out + + +def get_enet(dataset='citys', backbone='', pretrained=False, root='~/.torch/models', pretrained_base=True, **kwargs): + acronyms = { + 'pascal_voc': 'pascal_voc', + 'pascal_aug': 'pascal_aug', + 'ade20k': 'ade', + 'coco': 'coco', + 'citys': 'citys', + } + from core.data.dataloader import datasets + model = ENet(datasets[dataset].NUM_CLASS, backbone=backbone, pretrained_base=pretrained_base, **kwargs) + if pretrained: + from .model_store import get_model_file + device = torch.device(kwargs['local_rank']) + model.load_state_dict(torch.load(get_model_file('enet_%s' % (acronyms[dataset]), root=root), + map_location=device)) + return model + + +def get_enet_citys(**kwargs): + return get_enet('citys', '', **kwargs) + + +if __name__ == '__main__': + img = torch.randn(1, 3, 512, 512) + model = get_enet_citys() + output = model(img) diff --git a/PyTorch/contrib/cv/semantic_segmentation/ENet/core/models/ocnet.py b/PyTorch/contrib/cv/semantic_segmentation/ENet/core/models/ocnet.py index e59df3ce96908439cb3f860af8ff9f43153c7026..4eea5bd8d9b6e0ab6beed1952f715b07204a2328 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/ENet/core/models/ocnet.py +++ b/PyTorch/contrib/cv/semantic_segmentation/ENet/core/models/ocnet.py @@ -1,359 +1,359 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -""" Object Context Network for Scene Parsing""" -import torch -import torch.nn as nn -import torch.nn.functional as F - -from .segbase import SegBaseModel -from .fcn import _FCNHead - -__all__ = ['OCNet', 'get_ocnet', 'get_base_ocnet_resnet101_citys', - 'get_pyramid_ocnet_resnet101_citys', 'get_asp_ocnet_resnet101_citys'] - - -class OCNet(SegBaseModel): - r"""OCNet - - Parameters - ---------- - nclass : int - Number of categories for the training dataset. - backbone : string - Pre-trained dilated backbone network type (default:'resnet50'; 'resnet50', - 'resnet101' or 'resnet152'). - norm_layer : object - Normalization layer used in backbone network (default: :class:`nn.BatchNorm`; - for Synchronized Cross-GPU BachNormalization). - aux : bool - Auxiliary loss. - Reference: - Yuhui Yuan, Jingdong Wang. "OCNet: Object Context Network for Scene Parsing." - arXiv preprint arXiv:1809.00916 (2018). - """ - - def __init__(self, nclass, backbone='resnet101', oc_arch='base', aux=False, pretrained_base=True, **kwargs): - super(OCNet, self).__init__(nclass, aux, backbone, pretrained_base=pretrained_base, **kwargs) - self.head = _OCHead(nclass, oc_arch, **kwargs) - if self.aux: - self.auxlayer = _FCNHead(1024, nclass, **kwargs) - - self.__setattr__('exclusive', ['head', 'auxlayer'] if aux else ['head']) - - def forward(self, x): - size = x.size()[2:] - _, _, c3, c4 = self.base_forward(x) - outputs = [] - x = self.head(c4) - x = F.interpolate(x, size, mode='bilinear', align_corners=True) - outputs.append(x) - - if self.aux: - auxout = self.auxlayer(c3) - auxout = F.interpolate(auxout, size, mode='bilinear', align_corners=True) - outputs.append(auxout) - return tuple(outputs) - - -class _OCHead(nn.Module): - def __init__(self, nclass, oc_arch, norm_layer=nn.BatchNorm2d, **kwargs): - super(_OCHead, self).__init__() - if oc_arch == 'base': - self.context = nn.Sequential( - nn.Conv2d(2048, 512, 3, 1, padding=1, bias=False), - norm_layer(512), - nn.ReLU(True), - BaseOCModule(512, 512, 256, 256, scales=([1]), norm_layer=norm_layer, **kwargs)) - elif oc_arch == 'pyramid': - self.context = nn.Sequential( - nn.Conv2d(2048, 512, 3, 1, padding=1, bias=False), - norm_layer(512), - nn.ReLU(True), - PyramidOCModule(512, 512, 256, 512, scales=([1, 2, 3, 6]), norm_layer=norm_layer, **kwargs)) - elif oc_arch == 'asp': - self.context = ASPOCModule(2048, 512, 256, 512, norm_layer=norm_layer, **kwargs) - else: - raise ValueError("Unknown OC architecture!") - - self.out = nn.Conv2d(512, nclass, 1) - - def forward(self, x): - x = self.context(x) - return self.out(x) - - -class BaseAttentionBlock(nn.Module): - """The basic implementation for self-attention block/non-local block.""" - - def __init__(self, in_channels, out_channels, key_channels, value_channels, - scale=1, norm_layer=nn.BatchNorm2d, **kwargs): - super(BaseAttentionBlock, self).__init__() - self.scale = scale - self.key_channels = key_channels - self.value_channels = value_channels - if scale > 1: - self.pool = nn.MaxPool2d(scale) - - self.f_value = nn.Conv2d(in_channels, value_channels, 1) - self.f_key = nn.Sequential( - nn.Conv2d(in_channels, key_channels, 1), - norm_layer(key_channels), - nn.ReLU(True) - ) - self.f_query = self.f_key - self.W = nn.Conv2d(value_channels, out_channels, 1) - nn.init.constant_(self.W.weight, 0) - nn.init.constant_(self.W.bias, 0) - - def forward(self, x): - batch_size, c, w, h = x.size() - if self.scale > 1: - x = self.pool(x) - - value = self.f_value(x).view(batch_size, self.value_channels, -1).permute(0, 2, 1) - query = self.f_query(x).view(batch_size, self.key_channels, -1).permute(0, 2, 1) - key = self.f_key(x).view(batch_size, self.key_channels, -1) - - sim_map = torch.bmm(query, key) * (self.key_channels ** -.5) - sim_map = F.softmax(sim_map, dim=-1) - - context = torch.bmm(sim_map, value).permute(0, 2, 1).contiguous() - context = context.view(batch_size, self.value_channels, *x.size()[2:]) - context = self.W(context) - if self.scale > 1: - context = F.interpolate(context, size=(w, h), mode='bilinear', align_corners=True) - - return context - - -class BaseOCModule(nn.Module): - """Base-OC""" - - def __init__(self, in_channels, out_channels, key_channels, value_channels, - scales=([1]), norm_layer=nn.BatchNorm2d, concat=True, **kwargs): - super(BaseOCModule, self).__init__() - self.stages = nn.ModuleList([ - BaseAttentionBlock(in_channels, out_channels, key_channels, value_channels, scale, norm_layer, **kwargs) - for scale in scales]) - in_channels = in_channels * 2 if concat else in_channels - self.project = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 1), - norm_layer(out_channels), - nn.ReLU(True), - nn.Dropout2d(0.05) - ) - self.concat = concat - - def forward(self, x): - priors = [stage(x) for stage in self.stages] - context = priors[0] - for i in range(1, len(priors)): - context += priors[i] - if self.concat: - context = torch.cat([context, x], 1) - out = self.project(context) - return out - - -class PyramidAttentionBlock(nn.Module): - """The basic implementation for pyramid self-attention block/non-local block""" - - def __init__(self, in_channels, out_channels, key_channels, value_channels, - scale=1, norm_layer=nn.BatchNorm2d, **kwargs): - super(PyramidAttentionBlock, self).__init__() - self.scale = scale - self.value_channels = value_channels - self.key_channels = key_channels - - self.f_value = nn.Conv2d(in_channels, value_channels, 1) - self.f_key = nn.Sequential( - nn.Conv2d(in_channels, key_channels, 1), - norm_layer(key_channels), - nn.ReLU(True) - ) - self.f_query = self.f_key - self.W = nn.Conv2d(value_channels, out_channels, 1) - nn.init.constant_(self.W.weight, 0) - nn.init.constant_(self.W.bias, 0) - - def forward(self, x): - batch_size, c, w, h = x.size() - - local_x = list() - local_y = list() - step_w, step_h = w // self.scale, h // self.scale - for i in range(self.scale): - for j in range(self.scale): - start_x, start_y = step_w * i, step_h * j - end_x, end_y = min(start_x + step_w, w), min(start_y + step_h, h) - if i == (self.scale - 1): - end_x = w - if j == (self.scale - 1): - end_y = h - local_x += [start_x, end_x] - local_y += [start_y, end_y] - - value = self.f_value(x) - query = self.f_query(x) - key = self.f_key(x) - - local_list = list() - local_block_cnt = (self.scale ** 2) * 2 - for i in range(0, local_block_cnt, 2): - value_local = value[:, :, local_x[i]:local_x[i + 1], local_y[i]:local_y[i + 1]] - query_local = query[:, :, local_x[i]:local_x[i + 1], local_y[i]:local_y[i + 1]] - key_local = key[:, :, local_x[i]:local_x[i + 1], local_y[i]:local_y[i + 1]] - - w_local, h_local = value_local.size(2), value_local.size(3) - value_local = value_local.contiguous().view(batch_size, self.value_channels, -1).permute(0, 2, 1) - query_local = query_local.contiguous().view(batch_size, self.key_channels, -1).permute(0, 2, 1) - key_local = key_local.contiguous().view(batch_size, self.key_channels, -1) - - sim_map = torch.bmm(query_local, key_local) * (self.key_channels ** -.5) - sim_map = F.softmax(sim_map, dim=-1) - - context_local = torch.bmm(sim_map, value_local).permute(0, 2, 1).contiguous() - context_local = context_local.view(batch_size, self.value_channels, w_local, h_local) - local_list.append(context_local) - - context_list = list() - for i in range(0, self.scale): - row_tmp = list() - for j in range(self.scale): - row_tmp.append(local_list[j + i * self.scale]) - context_list.append(torch.cat(row_tmp, 3)) - - context = torch.cat(context_list, 2) - context = self.W(context) - - return context - - -class PyramidOCModule(nn.Module): - """Pyramid-OC""" - - def __init__(self, in_channels, out_channels, key_channels, value_channels, - scales=([1]), norm_layer=nn.BatchNorm2d, **kwargs): - super(PyramidOCModule, self).__init__() - self.stages = nn.ModuleList([ - PyramidAttentionBlock(in_channels, out_channels, key_channels, value_channels, scale, norm_layer, **kwargs) - for scale in scales]) - self.up_dr = nn.Sequential( - nn.Conv2d(in_channels, in_channels * len(scales), 1), - norm_layer(in_channels * len(scales)), - nn.ReLU(True) - ) - self.project = nn.Sequential( - nn.Conv2d(in_channels * len(scales) * 2, out_channels, 1), - norm_layer(out_channels), - nn.ReLU(True), - nn.Dropout2d(0.05) - ) - - def forward(self, x): - priors = [stage(x) for stage in self.stages] - context = [self.up_dr(x)] - for i in range(len(priors)): - context += [priors[i]] - context = torch.cat(context, 1) - out = self.project(context) - return out - - -class ASPOCModule(nn.Module): - """ASP-OC""" - - def __init__(self, in_channels, out_channels, key_channels, value_channels, - atrous_rates=(12, 24, 36), norm_layer=nn.BatchNorm2d, **kwargs): - super(ASPOCModule, self).__init__() - self.context = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 3, padding=1), - norm_layer(out_channels), - nn.ReLU(True), - BaseOCModule(out_channels, out_channels, key_channels, value_channels, ([2]), norm_layer, False, **kwargs)) - - rate1, rate2, rate3 = tuple(atrous_rates) - self.b1 = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 3, padding=rate1, dilation=rate1, bias=False), - norm_layer(out_channels), - nn.ReLU(True)) - self.b2 = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 3, padding=rate2, dilation=rate2, bias=False), - norm_layer(out_channels), - nn.ReLU(True)) - self.b3 = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 3, padding=rate3, dilation=rate3, bias=False), - norm_layer(out_channels), - nn.ReLU(True)) - self.b4 = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 1, bias=False), - norm_layer(out_channels), - nn.ReLU(True)) - - self.project = nn.Sequential( - nn.Conv2d(out_channels * 5, out_channels, 1, bias=False), - norm_layer(out_channels), - nn.ReLU(True), - nn.Dropout2d(0.1) - ) - - def forward(self, x): - feat1 = self.context(x) - feat2 = self.b1(x) - feat3 = self.b2(x) - feat4 = self.b3(x) - feat5 = self.b4(x) - out = torch.cat((feat1, feat2, feat3, feat4, feat5), dim=1) - out = self.project(out) - return out - - -def get_ocnet(dataset='citys', backbone='resnet50', oc_arch='base', pretrained=False, root='~/.torch/models', - pretrained_base=True, **kwargs): - acronyms = { - 'pascal_voc': 'pascal_voc', - 'pascal_aug': 'pascal_aug', - 'ade20k': 'ade', - 'coco': 'coco', - 'citys': 'citys', - } - from ..data.dataloader import datasets - model = OCNet(datasets[dataset].NUM_CLASS, backbone=backbone, oc_arch=oc_arch, - pretrained_base=pretrained_base, **kwargs) - if pretrained: - from .model_store import get_model_file - device = torch.device(kwargs['local_rank']) - model.load_state_dict(torch.load(get_model_file('%s_ocnet_%s_%s' % ( - oc_arch, backbone, acronyms[dataset]), root=root), - map_location=device)) - return model - - -def get_base_ocnet_resnet101_citys(**kwargs): - return get_ocnet('citys', 'resnet101', 'base', **kwargs) - - -def get_pyramid_ocnet_resnet101_citys(**kwargs): - return get_ocnet('citys', 'resnet101', 'pyramid', **kwargs) - - -def get_asp_ocnet_resnet101_citys(**kwargs): - return get_ocnet('citys', 'resnet101', 'asp', **kwargs) - - -if __name__ == '__main__': - img = torch.randn(1, 3, 256, 256) - model = get_asp_ocnet_resnet101_citys() - outputs = model(img) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" Object Context Network for Scene Parsing""" +import torch +import torch.nn as nn +import torch.nn.functional as F + +from .segbase import SegBaseModel +from .fcn import _FCNHead + +__all__ = ['OCNet', 'get_ocnet', 'get_base_ocnet_resnet101_citys', + 'get_pyramid_ocnet_resnet101_citys', 'get_asp_ocnet_resnet101_citys'] + + +class OCNet(SegBaseModel): + r"""OCNet + + Parameters + ---------- + nclass : int + Number of categories for the training dataset. + backbone : string + Pre-trained dilated backbone network type (default:'resnet50'; 'resnet50', + 'resnet101' or 'resnet152'). + norm_layer : object + Normalization layer used in backbone network (default: :class:`nn.BatchNorm`; + for Synchronized Cross-GPU BachNormalization). + aux : bool + Auxiliary loss. + Reference: + Yuhui Yuan, Jingdong Wang. "OCNet: Object Context Network for Scene Parsing." + arXiv preprint arXiv:1809.00916 (2018). + """ + + def __init__(self, nclass, backbone='resnet101', oc_arch='base', aux=False, pretrained_base=True, **kwargs): + super(OCNet, self).__init__(nclass, aux, backbone, pretrained_base=pretrained_base, **kwargs) + self.head = _OCHead(nclass, oc_arch, **kwargs) + if self.aux: + self.auxlayer = _FCNHead(1024, nclass, **kwargs) + + self.__setattr__('exclusive', ['head', 'auxlayer'] if aux else ['head']) + + def forward(self, x): + size = x.size()[2:] + _, _, c3, c4 = self.base_forward(x) + outputs = [] + x = self.head(c4) + x = F.interpolate(x, size, mode='bilinear', align_corners=True) + outputs.append(x) + + if self.aux: + auxout = self.auxlayer(c3) + auxout = F.interpolate(auxout, size, mode='bilinear', align_corners=True) + outputs.append(auxout) + return tuple(outputs) + + +class _OCHead(nn.Module): + def __init__(self, nclass, oc_arch, norm_layer=nn.BatchNorm2d, **kwargs): + super(_OCHead, self).__init__() + if oc_arch == 'base': + self.context = nn.Sequential( + nn.Conv2d(2048, 512, 3, 1, padding=1, bias=False), + norm_layer(512), + nn.ReLU(True), + BaseOCModule(512, 512, 256, 256, scales=([1]), norm_layer=norm_layer, **kwargs)) + elif oc_arch == 'pyramid': + self.context = nn.Sequential( + nn.Conv2d(2048, 512, 3, 1, padding=1, bias=False), + norm_layer(512), + nn.ReLU(True), + PyramidOCModule(512, 512, 256, 512, scales=([1, 2, 3, 6]), norm_layer=norm_layer, **kwargs)) + elif oc_arch == 'asp': + self.context = ASPOCModule(2048, 512, 256, 512, norm_layer=norm_layer, **kwargs) + else: + raise ValueError("Unknown OC architecture!") + + self.out = nn.Conv2d(512, nclass, 1) + + def forward(self, x): + x = self.context(x) + return self.out(x) + + +class BaseAttentionBlock(nn.Module): + """The basic implementation for self-attention block/non-local block.""" + + def __init__(self, in_channels, out_channels, key_channels, value_channels, + scale=1, norm_layer=nn.BatchNorm2d, **kwargs): + super(BaseAttentionBlock, self).__init__() + self.scale = scale + self.key_channels = key_channels + self.value_channels = value_channels + if scale > 1: + self.pool = nn.MaxPool2d(scale) + + self.f_value = nn.Conv2d(in_channels, value_channels, 1) + self.f_key = nn.Sequential( + nn.Conv2d(in_channels, key_channels, 1), + norm_layer(key_channels), + nn.ReLU(True) + ) + self.f_query = self.f_key + self.W = nn.Conv2d(value_channels, out_channels, 1) + nn.init.constant_(self.W.weight, 0) + nn.init.constant_(self.W.bias, 0) + + def forward(self, x): + batch_size, c, w, h = x.size() + if self.scale > 1: + x = self.pool(x) + + value = self.f_value(x).view(batch_size, self.value_channels, -1).permute(0, 2, 1) + query = self.f_query(x).view(batch_size, self.key_channels, -1).permute(0, 2, 1) + key = self.f_key(x).view(batch_size, self.key_channels, -1) + + sim_map = torch.bmm(query, key) * (self.key_channels ** -.5) + sim_map = F.softmax(sim_map, dim=-1) + + context = torch.bmm(sim_map, value).permute(0, 2, 1).contiguous() + context = context.view(batch_size, self.value_channels, *x.size()[2:]) + context = self.W(context) + if self.scale > 1: + context = F.interpolate(context, size=(w, h), mode='bilinear', align_corners=True) + + return context + + +class BaseOCModule(nn.Module): + """Base-OC""" + + def __init__(self, in_channels, out_channels, key_channels, value_channels, + scales=([1]), norm_layer=nn.BatchNorm2d, concat=True, **kwargs): + super(BaseOCModule, self).__init__() + self.stages = nn.ModuleList([ + BaseAttentionBlock(in_channels, out_channels, key_channels, value_channels, scale, norm_layer, **kwargs) + for scale in scales]) + in_channels = in_channels * 2 if concat else in_channels + self.project = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 1), + norm_layer(out_channels), + nn.ReLU(True), + nn.Dropout2d(0.05) + ) + self.concat = concat + + def forward(self, x): + priors = [stage(x) for stage in self.stages] + context = priors[0] + for i in range(1, len(priors)): + context += priors[i] + if self.concat: + context = torch.cat([context, x], 1) + out = self.project(context) + return out + + +class PyramidAttentionBlock(nn.Module): + """The basic implementation for pyramid self-attention block/non-local block""" + + def __init__(self, in_channels, out_channels, key_channels, value_channels, + scale=1, norm_layer=nn.BatchNorm2d, **kwargs): + super(PyramidAttentionBlock, self).__init__() + self.scale = scale + self.value_channels = value_channels + self.key_channels = key_channels + + self.f_value = nn.Conv2d(in_channels, value_channels, 1) + self.f_key = nn.Sequential( + nn.Conv2d(in_channels, key_channels, 1), + norm_layer(key_channels), + nn.ReLU(True) + ) + self.f_query = self.f_key + self.W = nn.Conv2d(value_channels, out_channels, 1) + nn.init.constant_(self.W.weight, 0) + nn.init.constant_(self.W.bias, 0) + + def forward(self, x): + batch_size, c, w, h = x.size() + + local_x = list() + local_y = list() + step_w, step_h = w // self.scale, h // self.scale + for i in range(self.scale): + for j in range(self.scale): + start_x, start_y = step_w * i, step_h * j + end_x, end_y = min(start_x + step_w, w), min(start_y + step_h, h) + if i == (self.scale - 1): + end_x = w + if j == (self.scale - 1): + end_y = h + local_x += [start_x, end_x] + local_y += [start_y, end_y] + + value = self.f_value(x) + query = self.f_query(x) + key = self.f_key(x) + + local_list = list() + local_block_cnt = (self.scale ** 2) * 2 + for i in range(0, local_block_cnt, 2): + value_local = value[:, :, local_x[i]:local_x[i + 1], local_y[i]:local_y[i + 1]] + query_local = query[:, :, local_x[i]:local_x[i + 1], local_y[i]:local_y[i + 1]] + key_local = key[:, :, local_x[i]:local_x[i + 1], local_y[i]:local_y[i + 1]] + + w_local, h_local = value_local.size(2), value_local.size(3) + value_local = value_local.contiguous().view(batch_size, self.value_channels, -1).permute(0, 2, 1) + query_local = query_local.contiguous().view(batch_size, self.key_channels, -1).permute(0, 2, 1) + key_local = key_local.contiguous().view(batch_size, self.key_channels, -1) + + sim_map = torch.bmm(query_local, key_local) * (self.key_channels ** -.5) + sim_map = F.softmax(sim_map, dim=-1) + + context_local = torch.bmm(sim_map, value_local).permute(0, 2, 1).contiguous() + context_local = context_local.view(batch_size, self.value_channels, w_local, h_local) + local_list.append(context_local) + + context_list = list() + for i in range(0, self.scale): + row_tmp = list() + for j in range(self.scale): + row_tmp.append(local_list[j + i * self.scale]) + context_list.append(torch.cat(row_tmp, 3)) + + context = torch.cat(context_list, 2) + context = self.W(context) + + return context + + +class PyramidOCModule(nn.Module): + """Pyramid-OC""" + + def __init__(self, in_channels, out_channels, key_channels, value_channels, + scales=([1]), norm_layer=nn.BatchNorm2d, **kwargs): + super(PyramidOCModule, self).__init__() + self.stages = nn.ModuleList([ + PyramidAttentionBlock(in_channels, out_channels, key_channels, value_channels, scale, norm_layer, **kwargs) + for scale in scales]) + self.up_dr = nn.Sequential( + nn.Conv2d(in_channels, in_channels * len(scales), 1), + norm_layer(in_channels * len(scales)), + nn.ReLU(True) + ) + self.project = nn.Sequential( + nn.Conv2d(in_channels * len(scales) * 2, out_channels, 1), + norm_layer(out_channels), + nn.ReLU(True), + nn.Dropout2d(0.05) + ) + + def forward(self, x): + priors = [stage(x) for stage in self.stages] + context = [self.up_dr(x)] + for i in range(len(priors)): + context += [priors[i]] + context = torch.cat(context, 1) + out = self.project(context) + return out + + +class ASPOCModule(nn.Module): + """ASP-OC""" + + def __init__(self, in_channels, out_channels, key_channels, value_channels, + atrous_rates=(12, 24, 36), norm_layer=nn.BatchNorm2d, **kwargs): + super(ASPOCModule, self).__init__() + self.context = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 3, padding=1), + norm_layer(out_channels), + nn.ReLU(True), + BaseOCModule(out_channels, out_channels, key_channels, value_channels, ([2]), norm_layer, False, **kwargs)) + + rate1, rate2, rate3 = tuple(atrous_rates) + self.b1 = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 3, padding=rate1, dilation=rate1, bias=False), + norm_layer(out_channels), + nn.ReLU(True)) + self.b2 = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 3, padding=rate2, dilation=rate2, bias=False), + norm_layer(out_channels), + nn.ReLU(True)) + self.b3 = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 3, padding=rate3, dilation=rate3, bias=False), + norm_layer(out_channels), + nn.ReLU(True)) + self.b4 = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 1, bias=False), + norm_layer(out_channels), + nn.ReLU(True)) + + self.project = nn.Sequential( + nn.Conv2d(out_channels * 5, out_channels, 1, bias=False), + norm_layer(out_channels), + nn.ReLU(True), + nn.Dropout2d(0.1) + ) + + def forward(self, x): + feat1 = self.context(x) + feat2 = self.b1(x) + feat3 = self.b2(x) + feat4 = self.b3(x) + feat5 = self.b4(x) + out = torch.cat((feat1, feat2, feat3, feat4, feat5), dim=1) + out = self.project(out) + return out + + +def get_ocnet(dataset='citys', backbone='resnet50', oc_arch='base', pretrained=False, root='~/.torch/models', + pretrained_base=True, **kwargs): + acronyms = { + 'pascal_voc': 'pascal_voc', + 'pascal_aug': 'pascal_aug', + 'ade20k': 'ade', + 'coco': 'coco', + 'citys': 'citys', + } + from ..data.dataloader import datasets + model = OCNet(datasets[dataset].NUM_CLASS, backbone=backbone, oc_arch=oc_arch, + pretrained_base=pretrained_base, **kwargs) + if pretrained: + from .model_store import get_model_file + device = torch.device(kwargs['local_rank']) + model.load_state_dict(torch.load(get_model_file('%s_ocnet_%s_%s' % ( + oc_arch, backbone, acronyms[dataset]), root=root), + map_location=device)) + return model + + +def get_base_ocnet_resnet101_citys(**kwargs): + return get_ocnet('citys', 'resnet101', 'base', **kwargs) + + +def get_pyramid_ocnet_resnet101_citys(**kwargs): + return get_ocnet('citys', 'resnet101', 'pyramid', **kwargs) + + +def get_asp_ocnet_resnet101_citys(**kwargs): + return get_ocnet('citys', 'resnet101', 'asp', **kwargs) + + +if __name__ == '__main__': + img = torch.randn(1, 3, 256, 256) + model = get_asp_ocnet_resnet101_citys() + outputs = model(img) diff --git a/PyTorch/contrib/cv/semantic_segmentation/ENet/scripts/eval.py b/PyTorch/contrib/cv/semantic_segmentation/ENet/scripts/eval.py index 0633c0615df2c223f219a6ef44b1b8d92588bb75..0bbb7efdd2f5e70e7d1ecfb9174dc7ca460650c6 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/ENet/scripts/eval.py +++ b/PyTorch/contrib/cv/semantic_segmentation/ENet/scripts/eval.py @@ -1,143 +1,143 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import print_function - -import os -import sys - -cur_path = os.path.abspath(os.path.dirname(__file__)) -root_path = os.path.split(cur_path)[0] -sys.path.append(root_path) - -import torch -import torch.nn as nn -import torch.utils.data as data -import torch.backends.cudnn as cudnn - -from torchvision import transforms -from core.data.dataloader import get_segmentation_dataset -from core.models.model_zoo import get_segmentation_model -from core.utils.score import SegmentationMetric -from core.utils.visualize import get_color_pallete -from core.utils.logger import setup_logger -from core.utils.distributed import synchronize, get_rank, make_data_sampler, make_batch_data_sampler - -from train import parse_args - - -class Evaluator(object): - def __init__(self, args): - self.args = args - loc = 'npu:{}'.format(self.args.local_rank) - #self.device = torch.device(args.device) - if args.device == 'npu': - self.device = torch.npu.set_device(loc) - else: - self.device = torch.device(args.device) - - # image transform - input_transform = transforms.Compose([ - transforms.ToTensor(), - transforms.Normalize([.485, .456, .406], [.229, .224, .225]), - ]) - - # dataset and dataloader - val_dataset = get_segmentation_dataset(args.dataset, split='val', mode='testval', transform=input_transform) - val_sampler = make_data_sampler(val_dataset, False, args.distributed) - val_batch_sampler = make_batch_data_sampler(val_sampler, images_per_batch=1) - self.val_loader = data.DataLoader(dataset=val_dataset, - batch_sampler=val_batch_sampler, - num_workers=args.workers, - pin_memory=True) - - # create network - BatchNorm2d = nn.BatchNorm2d#nn.SyncBatchNorm if args.distributed else nn.BatchNorm2d - self.model = get_segmentation_model(model=args.model, dataset=args.dataset, backbone=args.backbone, - aux=args.aux, pretrained=True, pretrained_base=False, - local_rank=args.local_rank, - norm_layer=BatchNorm2d).to(loc) - if args.distributed: - self.model = nn.parallel.DistributedDataParallel(self.model, - device_ids=[args.local_rank], output_device=args.local_rank) - self.model.to(loc) - - self.metric = SegmentationMetric(val_dataset.num_class) - - def eval(self): - loc = 'npu:{}'.format(self.args.local_rank) - self.metric.reset() - self.model.eval() - if self.args.distributed: - model = self.model.module - else: - model = self.model - logger.info("Start validation, Total sample: {:d}".format(len(self.val_loader))) - for i, (image, target, filename) in enumerate(self.val_loader): - image = image.to(loc) - target = target.to(loc) - target = target.to(torch.int32) - - with torch.no_grad(): - outputs = model(image) - self.metric.update(outputs[0], target) - pixAcc, mIoU = self.metric.get() - logger.info("Sample: {:d}, validation pixAcc: {:.3f}, mIoU: {:.3f}".format( - i + 1, pixAcc * 100, mIoU * 100)) - - if self.args.save_pred: - pred = torch.argmax(outputs[0], 1) - pred = pred.cpu().data.numpy() - - predict = pred.squeeze(0) - mask = get_color_pallete(predict, self.args.dataset) - mask.save(os.path.join(outdir, os.path.splitext(filename[0])[0] + '.png')) - synchronize() - - -if __name__ == '__main__': - args = parse_args() - num_gpus = int(os.environ["WORLD_SIZE"]) if "WORLD_SIZE" in os.environ else 1 - args.distributed = num_gpus > 1 - if args.device == "npu": - args.device = "npu" - elif not args.no_cuda and torch.cuda.is_available(): - cudnn.benchmark = True - args.device = "cuda" - else: - args.distributed = False - args.device = "cpu" - if args.distributed: - torch.npu.set_device(args.local_rank) - torch.distributed.init_process_group(backend=args.dist_backend, init_method="env://") - synchronize() - - # TODO: optim code - args.save_pred = True - if args.save_pred: - outdir = '../runs/pred_pic/{}_{}_{}'.format(args.model, args.backbone, args.dataset) - if args.model == "enet": - outdir = '../runs/pred_pic/{}_{}'.format(args.model, args.dataset) - if not os.path.exists(outdir): - os.makedirs(outdir) - - log_filename = '{}_{}_{}_log.txt'.format(args.model, args.backbone, args.dataset) - if args.model == "enet": - log_filename = '{}_{}_log.txt'.format(args.model, args.dataset) - logger = setup_logger("semantic_segmentation", args.log_dir, get_rank(), - filename=log_filename, mode='a+') - - evaluator = Evaluator(args) - evaluator.eval() - torch.npu.empty_cache() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import print_function + +import os +import sys + +cur_path = os.path.abspath(os.path.dirname(__file__)) +root_path = os.path.split(cur_path)[0] +sys.path.append(root_path) + +import torch +import torch.nn as nn +import torch.utils.data as data +import torch.backends.cudnn as cudnn + +from torchvision import transforms +from core.data.dataloader import get_segmentation_dataset +from core.models.model_zoo import get_segmentation_model +from core.utils.score import SegmentationMetric +from core.utils.visualize import get_color_pallete +from core.utils.logger import setup_logger +from core.utils.distributed import synchronize, get_rank, make_data_sampler, make_batch_data_sampler + +from train import parse_args + + +class Evaluator(object): + def __init__(self, args): + self.args = args + loc = 'npu:{}'.format(self.args.local_rank) + #self.device = torch.device(args.device) + if args.device == 'npu': + self.device = torch.npu.set_device(loc) + else: + self.device = torch.device(args.device) + + # image transform + input_transform = transforms.Compose([ + transforms.ToTensor(), + transforms.Normalize([.485, .456, .406], [.229, .224, .225]), + ]) + + # dataset and dataloader + val_dataset = get_segmentation_dataset(args.dataset, split='val', mode='testval', transform=input_transform) + val_sampler = make_data_sampler(val_dataset, False, args.distributed) + val_batch_sampler = make_batch_data_sampler(val_sampler, images_per_batch=1) + self.val_loader = data.DataLoader(dataset=val_dataset, + batch_sampler=val_batch_sampler, + num_workers=args.workers, + pin_memory=True) + + # create network + BatchNorm2d = nn.BatchNorm2d#nn.SyncBatchNorm if args.distributed else nn.BatchNorm2d + self.model = get_segmentation_model(model=args.model, dataset=args.dataset, backbone=args.backbone, + aux=args.aux, pretrained=True, pretrained_base=False, + local_rank=args.local_rank, + norm_layer=BatchNorm2d).to(loc) + if args.distributed: + self.model = nn.parallel.DistributedDataParallel(self.model, + device_ids=[args.local_rank], output_device=args.local_rank) + self.model.to(loc) + + self.metric = SegmentationMetric(val_dataset.num_class) + + def eval(self): + loc = 'npu:{}'.format(self.args.local_rank) + self.metric.reset() + self.model.eval() + if self.args.distributed: + model = self.model.module + else: + model = self.model + logger.info("Start validation, Total sample: {:d}".format(len(self.val_loader))) + for i, (image, target, filename) in enumerate(self.val_loader): + image = image.to(loc) + target = target.to(loc) + target = target.to(torch.int32) + + with torch.no_grad(): + outputs = model(image) + self.metric.update(outputs[0], target) + pixAcc, mIoU = self.metric.get() + logger.info("Sample: {:d}, validation pixAcc: {:.3f}, mIoU: {:.3f}".format( + i + 1, pixAcc * 100, mIoU * 100)) + + if self.args.save_pred: + pred = torch.argmax(outputs[0], 1) + pred = pred.cpu().data.numpy() + + predict = pred.squeeze(0) + mask = get_color_pallete(predict, self.args.dataset) + mask.save(os.path.join(outdir, os.path.splitext(filename[0])[0] + '.png')) + synchronize() + + +if __name__ == '__main__': + args = parse_args() + num_gpus = int(os.environ["WORLD_SIZE"]) if "WORLD_SIZE" in os.environ else 1 + args.distributed = num_gpus > 1 + if args.device == "npu": + args.device = "npu" + elif not args.no_cuda and torch.cuda.is_available(): + cudnn.benchmark = True + args.device = "cuda" + else: + args.distributed = False + args.device = "cpu" + if args.distributed: + torch.npu.set_device(args.local_rank) + torch.distributed.init_process_group(backend=args.dist_backend, init_method="env://") + synchronize() + + # TODO: optim code + args.save_pred = True + if args.save_pred: + outdir = '../runs/pred_pic/{}_{}_{}'.format(args.model, args.backbone, args.dataset) + if args.model == "enet": + outdir = '../runs/pred_pic/{}_{}'.format(args.model, args.dataset) + if not os.path.exists(outdir): + os.makedirs(outdir) + + log_filename = '{}_{}_{}_log.txt'.format(args.model, args.backbone, args.dataset) + if args.model == "enet": + log_filename = '{}_{}_log.txt'.format(args.model, args.dataset) + logger = setup_logger("semantic_segmentation", args.log_dir, get_rank(), + filename=log_filename, mode='a+') + + evaluator = Evaluator(args) + evaluator.eval() + torch.npu.empty_cache() diff --git a/PyTorch/contrib/cv/semantic_segmentation/ENet/scripts/proc_node_module.py b/PyTorch/contrib/cv/semantic_segmentation/ENet/scripts/proc_node_module.py index c139998dc9a92d2570632335540867dca6e5ee57..31cf2b16c7245ef358776030c28149440dda1cbb 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/ENet/scripts/proc_node_module.py +++ b/PyTorch/contrib/cv/semantic_segmentation/ENet/scripts/proc_node_module.py @@ -1,40 +1,40 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -from collections import OrderedDict -import os - -def proc_nodes_module(checkpoint): - new_state_dict = OrderedDict() - for k, v in checkpoint.items(): - if "module." in k: - name = k.replace("module.", "") - else: - name = k - new_state_dict[name] = v - return new_state_dict - -root ='~/.torch/models' -root = os.path.expanduser(root) -file_path = os.path.join(root, 'enet_citys.pth') -checkpoint = torch.load(file_path, map_location='cpu') -checkpoint = proc_nodes_module(checkpoint) - - -#directory = os.path.expanduser(args.save_dir) -directory = os.path.expanduser(root) -filename = 'enet_citys.pth' -filename = os.path.join(directory, filename) -torch.save(checkpoint, filename) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +from collections import OrderedDict +import os + +def proc_nodes_module(checkpoint): + new_state_dict = OrderedDict() + for k, v in checkpoint.items(): + if "module." in k: + name = k.replace("module.", "") + else: + name = k + new_state_dict[name] = v + return new_state_dict + +root ='~/.torch/models' +root = os.path.expanduser(root) +file_path = os.path.join(root, 'enet_citys.pth') +checkpoint = torch.load(file_path, map_location='cpu') +checkpoint = proc_nodes_module(checkpoint) + + +#directory = os.path.expanduser(args.save_dir) +directory = os.path.expanduser(root) +filename = 'enet_citys.pth' +filename = os.path.join(directory, filename) +torch.save(checkpoint, filename) diff --git a/PyTorch/contrib/cv/semantic_segmentation/ENet/scripts/train.py b/PyTorch/contrib/cv/semantic_segmentation/ENet/scripts/train.py index e4e27aa58c51a83e371d7e047e60c51f622cacb5..137742ca7019d80dd551ea01cb659fbfc2b41d00 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/ENet/scripts/train.py +++ b/PyTorch/contrib/cv/semantic_segmentation/ENet/scripts/train.py @@ -1,449 +1,449 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -*- coding: utf-8 -*- - -import argparse -import time -import datetime -import os -import shutil -import sys - -cur_path = os.path.abspath(os.path.dirname(__file__)) -root_path = os.path.split(cur_path)[0] -sys.path.append(root_path) - -CALCULATE_DEVICE = "npu:0" - -import torch -import torch.nn as nn -import torch.utils.data as data -import torch.backends.cudnn as cudnn - -import torch.npu - -from torchvision import transforms -from core.data.dataloader import get_segmentation_dataset -from core.models.model_zoo import get_segmentation_model -from core.utils.loss import get_segmentation_loss -from core.utils.distributed import * -from core.utils.logger import setup_logger -from core.utils.lr_scheduler import WarmupPolyLR -from core.utils.score import SegmentationMetric -from apex import amp - - -def parse_args(): - parser = argparse.ArgumentParser(description='Semantic Segmentation Training With Pytorch') - # model and dataset - parser.add_argument('--model', type=str, default='fcn', - choices=['fcn32s', 'fcn16s', 'fcn8s', 'fcn', 'psp', 'deeplabv3', - 'deeplabv3_plus', 'danet', 'denseaspp', 'bisenet', 'encnet', - 'dunet', 'icnet', 'enet', 'ocnet', 'psanet', 'cgnet', 'espnet', - 'lednet', 'dfanet'], - help='model name (default: fcn32s)') - parser.add_argument('--backbone', type=str, default='resnet50', - choices=['vgg16', 'resnet18', 'resnet50', 'resnet101', 'resnet152', - 'densenet121', 'densenet161', 'densenet169', 'densenet201'], - help='backbone name (default: vgg16)') - parser.add_argument('--dataset', type=str, default='pascal_voc', - choices=['pascal_voc', 'pascal_aug', 'ade20k', 'citys', 'sbu'], - help='dataset name (default: pascal_voc)') - parser.add_argument('--base-size', type=int, default=520, - help='base image size') - parser.add_argument('--crop-size', type=int, default=480, - help='crop image size') - parser.add_argument('--workers', '-j', type=int, default=4, - metavar='N', help='dataloader threads') - # training hyper params - parser.add_argument('--jpu', action='store_true', default=False, - help='JPU') - parser.add_argument('--use-ohem', type=bool, default=False, - help='OHEM Loss for cityscapes dataset') - parser.add_argument('--aux', action='store_true', default=False, - help='Auxiliary loss') - parser.add_argument('--aux-weight', type=float, default=0.4, - help='auxiliary loss weight') - parser.add_argument('--batch-size', type=int, default=4, metavar='N', - help='input batch size for training (default: 8)') - parser.add_argument('--start_epoch', type=int, default=0, - metavar='N', help='start epochs (default:0)') - parser.add_argument('--epochs', type=int, default=50, metavar='N', - help='number of epochs to train (default: 50)') - parser.add_argument('--lr', type=float, default=1e-4, metavar='LR', - help='learning rate (default: 1e-4)') - parser.add_argument('--momentum', type=float, default=0.9, metavar='M', - help='momentum (default: 0.9)') - parser.add_argument('--weight-decay', type=float, default=1e-4, metavar='M', - help='w-decay (default: 5e-4)') - parser.add_argument('--warmup-iters', type=int, default=0, - help='warmup iters') - parser.add_argument('--warmup-factor', type=float, default=1.0 / 3, - help='lr = warmup_factor * lr') - parser.add_argument('--warmup-method', type=str, default='linear', - help='method of warmup') - # cuda setting - parser.add_argument('--no-cuda', action='store_true', default=False, - help='disables CUDA training') - parser.add_argument('--local_rank', type=int, default=0) - # checkpoint and log - parser.add_argument('--resume', type=str, default=None, - help='put the path to resuming file if needed') - parser.add_argument('--save-dir', default='~/.torch/models', - help='Directory for saving checkpoint models') - parser.add_argument('--save-epoch', type=int, default=10, - help='save model every checkpoint-epoch') - parser.add_argument('--log-dir', default='../runs/logs/', - help='Directory for saving checkpoint models') - parser.add_argument('--log-iter', type=int, default=10, - help='print log every log-iter') - # evaluation only - parser.add_argument('--val-epoch', type=int, default=1, - help='run validation every val-epoch') - parser.add_argument('--skip-val', action='store_true', default=False, - help='skip validation during training') - # apex - parser.add_argument('--amp', default=False, action='store_true', - help='use amp to train the model') - parser.add_argument('--loss-scale', default=128.0, type=float, - help='loss scale using in amp, default -1 means dynamic') - parser.add_argument('--opt-level', default='O2', type=str, - help='loss scale using in amp, default -1 means dynamic') - - # npu setting - parser.add_argument('--device', default='npu', type=str, - help='npu or gpu') - parser.add_argument('--dist-backend', default='hccl', type=str, - help='distributed backend') - - args = parser.parse_args() - - # default settings for epochs, batch_size and lr - if args.epochs is None: - epoches = { - 'coco': 30, - 'pascal_aug': 80, - 'pascal_voc': 50, - 'pcontext': 80, - 'ade20k': 160, - 'citys': 120, - 'sbu': 160, - } - args.epochs = epoches[args.dataset.lower()] - if args.lr is None: - lrs = { - 'coco': 0.004, - 'pascal_aug': 0.001, - 'pascal_voc': 0.0001, - 'pcontext': 0.001, - 'ade20k': 0.01, - 'citys': 0.01, - 'sbu': 0.001, - } - args.lr = lrs[args.dataset.lower()] / 8 * args.batch_size - return args - - -class Trainer(object): - def __init__(self, args): - self.args = args - # self.device = torch.device(args.device) - - loc = 'npu:{}'.format(args.local_rank) - if args.device == "npu": - self.device = torch.npu.set_device(loc) - else: - self.device = torch.device(args.device) - - # image transform - input_transform = transforms.Compose([ - transforms.ToTensor(), - transforms.Normalize([.485, .456, .406], [.229, .224, .225]), - ]) - # dataset and dataloader - data_kwargs = {'transform': input_transform, 'base_size': args.base_size, 'crop_size': args.crop_size} - train_dataset = get_segmentation_dataset(args.dataset, split='train', mode='train', **data_kwargs) - val_dataset = get_segmentation_dataset(args.dataset, split='val', mode='val', **data_kwargs) - args.iters_per_epoch = len(train_dataset) // (args.num_gpus * args.batch_size) - args.max_iters = args.epochs * args.iters_per_epoch - - train_sampler = make_data_sampler(train_dataset, shuffle=True, distributed=args.distributed) - train_batch_sampler = make_batch_data_sampler(train_sampler, args.batch_size, args.max_iters) - val_sampler = make_data_sampler(val_dataset, False, args.distributed) - val_batch_sampler = make_batch_data_sampler(val_sampler, args.batch_size) - - self.train_loader = data.DataLoader(dataset=train_dataset, - batch_sampler=train_batch_sampler, - num_workers=args.workers, - pin_memory=True) - self.val_loader = data.DataLoader(dataset=val_dataset, - batch_sampler=val_batch_sampler, - num_workers=args.workers, - pin_memory=True) - - # create network - BatchNorm2d = nn.BatchNorm2d#nn.SyncBatchNorm if args.distributed else nn.BatchNorm2d - self.model = get_segmentation_model(model=args.model, dataset=args.dataset, backbone=args.backbone, - aux=args.aux, jpu=args.jpu, norm_layer=BatchNorm2d).to(loc) - - # resume checkpoint if needed - if args.resume: - if os.path.isfile(args.resume): - name, ext = os.path.splitext(args.resume) - assert ext == '.pkl' or '.pth', 'Sorry only .pth and .pkl files supported.' - print('Resuming training, loading {}...'.format(args.resume)) - self.model.load_state_dict(torch.load(args.resume, map_location=lambda storage, loc: storage)) - - # create criterion - self.criterion = get_segmentation_loss(args.model, use_ohem=args.use_ohem, aux=args.aux, - aux_weight=args.aux_weight, ignore_index=-1).to(loc) # (args.device) - - # optimizer, for model just includes pretrained, head and auxlayer - params_list = list() - if hasattr(self.model, 'pretrained'): - params_list.append({'params': self.model.pretrained.parameters(), 'lr': args.lr}) - if hasattr(self.model, 'exclusive'): - for module in self.model.exclusive: - params_list.append({'params': getattr(self.model, module).parameters(), 'lr': args.lr * 10}) - self.optimizer = torch.optim.SGD(params_list, - lr=args.lr, - momentum=args.momentum, - weight_decay=args.weight_decay) - - if args.amp: - self.model, self.optimizer = amp.initialize(self.model, self.optimizer, opt_level=args.opt_level, - loss_scale=args.loss_scale) - - # lr scheduling - self.lr_scheduler = WarmupPolyLR(self.optimizer, - max_iters=args.max_iters, - power=0.9, - warmup_factor=args.warmup_factor, - warmup_iters=args.warmup_iters, - warmup_method=args.warmup_method) - - if args.distributed: - self.model = nn.parallel.DistributedDataParallel(self.model, device_ids=[args.local_rank], - output_device=args.local_rank, find_unused_parameters=True, broadcast_buffers=False) - - # evaluation metrics - self.metric = SegmentationMetric(train_dataset.num_class) - - self.best_pred = 0.0 - - def train(self): - batch_time = AverageMeter('Time', ':6.3f', start_count_index=5) - - loc = 'npu:{}'.format(self.args.local_rank) - - save_to_disk = get_rank() == 0 - epochs, max_iters = self.args.epochs, self.args.max_iters - log_per_iters, val_per_iters = self.args.log_iter, self.args.val_epoch * self.args.iters_per_epoch - save_per_iters = self.args.save_epoch * self.args.iters_per_epoch - start_time = time.time() - logger.info('Start training, Total Epochs: {:d} = Total Iterations {:d}'.format(epochs, max_iters)) - - end = time.time() - - self.model.train() - for iteration, (images, targets, _) in enumerate(self.train_loader): - iteration = iteration + 1 - self.lr_scheduler.step() - - # if 'npu' in CALCULATE_DEVICE: - targets = targets.to(torch.int32) - images = images.to(loc) - targets = targets.to(loc) - - # with torch.autograd.profiler.profile(use_npu=True) as prof: - outputs = self.model(images) - - loss_dict = self.criterion(outputs, targets) - - losses = sum(loss for loss in loss_dict.values()) - - # reduce losses over all GPUs for logging purposes - loss_dict_reduced = reduce_loss_dict(loss_dict) - losses_reduced = sum(loss for loss in loss_dict_reduced.values()) - - self.optimizer.zero_grad() - - # losses.backward() - if self.args.amp: - with amp.scale_loss(losses, self.optimizer) as scaled_loss: - scaled_loss.backward() - else: - losses.backward() - - self.optimizer.step() - - # print(prof.key_averages().table(sort_by="self_cpu_time_total")) - # prof.export_chrome_trace("output.prof") # "output.prof"为输出文件地址 - - eta_seconds = ((time.time() - start_time) / iteration) * (max_iters - iteration) - eta_string = str(datetime.timedelta(seconds=int(eta_seconds))) - - if iteration % log_per_iters == 0 and save_to_disk: - logger.info( - "Iters: {:d}/{:d} || Lr: {:.6f} || Loss: {:.4f} || Cost Time: {} || Estimated Time: {}".format( - iteration, max_iters, self.optimizer.param_groups[0]['lr'], losses_reduced.item(), - str(datetime.timedelta(seconds=int(time.time() - start_time))), eta_string)) - - if iteration % self.args.iters_per_epoch == 0 and batch_time.avg > 0: - logger.info("Epoch: {:d}/{:d} || FPS img/s: {:.3f}".format( - iteration // self.args.iters_per_epoch, epochs, - args.num_gpus * self.args.batch_size / batch_time.avg)) - - if iteration % save_per_iters == 0 and save_to_disk and self.args.local_rank == 0: - save_checkpoint(self.model, self.args, is_best=False) - - batch_time.update(time.time() - end) - - if not self.args.skip_val and iteration % val_per_iters == 0: - self.validation() - self.model.train() - - end = time.time() - - if self.args.local_rank == 0: - save_checkpoint(self.model, self.args, is_best=False) - total_training_time = time.time() - start_time - total_training_str = str(datetime.timedelta(seconds=total_training_time)) - logger.info( - "Total training time: {} ({:.4f}s / it)".format( - total_training_str, total_training_time / max_iters)) - - def validation(self): - loc = 'npu:{}'.format(self.args.local_rank) - - # total_inter, total_union, total_correct, total_label = 0, 0, 0, 0 - is_best = False - self.metric.reset() - #if self.args.distributed: - #model = self.model.module - #else: - model = self.model - torch.npu.empty_cache() # TODO check if it helps - model.eval() - for i, (image, target, filename) in enumerate(self.val_loader): - # if 'npu' in CALCULATE_DEVICE: - # target = target.to(torch.int32) - target = target.to(torch.int32) - image = image.to(loc) - target = target.to(loc) - with torch.no_grad(): - outputs = model(image) - self.metric.update(outputs[0], target) - pixAcc, mIoU = self.metric.get() - logger.info("Sample: {:d}, Validation pixAcc: {:.3f}, mIoU: {:.3f}".format(i + 1, pixAcc, mIoU)) - - new_pred = (pixAcc + mIoU) / 2 - if new_pred > self.best_pred: - is_best = True - self.best_pred = new_pred - if self.args.local_rank == 0: - save_checkpoint(self.model, self.args, is_best) - synchronize() - - -class AverageMeter(object): - """Computes and stores the average and current value""" - - def __init__(self, name, fmt=':f', start_count_index=10): - self.name = name - self.fmt = fmt - self.reset() - self.start_count_index = start_count_index - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - - def update(self, val, n=1): - if self.count == 0: - self.N = n - - self.val = val - self.count += n - if self.count > (self.start_count_index * self.N): - self.sum += val * n - self.avg = self.sum / (self.count - self.start_count_index * self.N) - - def __str__(self): - fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' - return fmtstr.format(**self.__dict__) - -def save_checkpoint(model, args, is_best=False): - """Save Checkpoint""" - directory = os.path.expanduser(args.save_dir) - if not os.path.exists(directory): - os.makedirs(directory) - - filename = '{}_{}_{}.pth'.format(args.model, args.backbone, args.dataset) - if args.model == "enet": - filename = '{}_{}.pth'.format(args.model, args.dataset) - filename = os.path.join(directory, filename) - - #if args.distributed: - #model = model.module - torch.save(model.state_dict(), filename) - if is_best: - best_filename = '{}_{}_{}_best_model.pth'.format(args.model, args.backbone, args.dataset) - if args.model == "enet": - best_filename = '{}_{}_best_model.pth'.format(args.model, args.dataset) - best_filename = os.path.join(directory, best_filename) - shutil.copyfile(filename, best_filename) - - -if __name__ == '__main__': - args = parse_args() - - os.environ['MASTER_ADDR'] = '127.0.0.1' # 可以使用当前真实ip或者'127.0.0.1' - os.environ['MASTER_PORT'] = '29688' # 随意一个可使用的port即可 - - # reference maskrcnn-benchmark - num_gpus = int(os.environ["WORLD_SIZE"]) if "WORLD_SIZE" in os.environ else 1 - args.num_gpus = num_gpus - #args.num_gpus = 1 - args.distributed = num_gpus > 1 - - if args.device == "npu": - args.device = "npu" - elif not args.no_cuda and torch.cuda.is_available(): - cudnn.benchmark = True - args.device = "cuda" - else: - args.distributed = False - args.device = "cpu" - if args.distributed: - loc = 'npu:{}'.format(args.local_rank) - torch.npu.set_device(loc) - torch.distributed.init_process_group(backend=args.dist_backend, init_method="env://") - synchronize() - args.lr = args.lr * num_gpus - - logger_filename = '{}_{}_{}_log.txt'.format(args.model, args.backbone, args.dataset) - if args.model == "enet": - logger_filename = '{}_{}_log.txt'.format(args.model, args.dataset) - logger = setup_logger("semantic_segmentation", args.log_dir, get_rank(), filename=logger_filename) - logger.info("Using {} GPUs".format(num_gpus)) - logger.info(args) - - trainer = Trainer(args) - trainer.train() - torch.npu.empty_cache() - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -*- coding: utf-8 -*- + +import argparse +import time +import datetime +import os +import shutil +import sys + +cur_path = os.path.abspath(os.path.dirname(__file__)) +root_path = os.path.split(cur_path)[0] +sys.path.append(root_path) + +CALCULATE_DEVICE = "npu:0" + +import torch +import torch.nn as nn +import torch.utils.data as data +import torch.backends.cudnn as cudnn + +import torch.npu + +from torchvision import transforms +from core.data.dataloader import get_segmentation_dataset +from core.models.model_zoo import get_segmentation_model +from core.utils.loss import get_segmentation_loss +from core.utils.distributed import * +from core.utils.logger import setup_logger +from core.utils.lr_scheduler import WarmupPolyLR +from core.utils.score import SegmentationMetric +from apex import amp + + +def parse_args(): + parser = argparse.ArgumentParser(description='Semantic Segmentation Training With Pytorch') + # model and dataset + parser.add_argument('--model', type=str, default='fcn', + choices=['fcn32s', 'fcn16s', 'fcn8s', 'fcn', 'psp', 'deeplabv3', + 'deeplabv3_plus', 'danet', 'denseaspp', 'bisenet', 'encnet', + 'dunet', 'icnet', 'enet', 'ocnet', 'psanet', 'cgnet', 'espnet', + 'lednet', 'dfanet'], + help='model name (default: fcn32s)') + parser.add_argument('--backbone', type=str, default='resnet50', + choices=['vgg16', 'resnet18', 'resnet50', 'resnet101', 'resnet152', + 'densenet121', 'densenet161', 'densenet169', 'densenet201'], + help='backbone name (default: vgg16)') + parser.add_argument('--dataset', type=str, default='pascal_voc', + choices=['pascal_voc', 'pascal_aug', 'ade20k', 'citys', 'sbu'], + help='dataset name (default: pascal_voc)') + parser.add_argument('--base-size', type=int, default=520, + help='base image size') + parser.add_argument('--crop-size', type=int, default=480, + help='crop image size') + parser.add_argument('--workers', '-j', type=int, default=4, + metavar='N', help='dataloader threads') + # training hyper params + parser.add_argument('--jpu', action='store_true', default=False, + help='JPU') + parser.add_argument('--use-ohem', type=bool, default=False, + help='OHEM Loss for cityscapes dataset') + parser.add_argument('--aux', action='store_true', default=False, + help='Auxiliary loss') + parser.add_argument('--aux-weight', type=float, default=0.4, + help='auxiliary loss weight') + parser.add_argument('--batch-size', type=int, default=4, metavar='N', + help='input batch size for training (default: 8)') + parser.add_argument('--start_epoch', type=int, default=0, + metavar='N', help='start epochs (default:0)') + parser.add_argument('--epochs', type=int, default=50, metavar='N', + help='number of epochs to train (default: 50)') + parser.add_argument('--lr', type=float, default=1e-4, metavar='LR', + help='learning rate (default: 1e-4)') + parser.add_argument('--momentum', type=float, default=0.9, metavar='M', + help='momentum (default: 0.9)') + parser.add_argument('--weight-decay', type=float, default=1e-4, metavar='M', + help='w-decay (default: 5e-4)') + parser.add_argument('--warmup-iters', type=int, default=0, + help='warmup iters') + parser.add_argument('--warmup-factor', type=float, default=1.0 / 3, + help='lr = warmup_factor * lr') + parser.add_argument('--warmup-method', type=str, default='linear', + help='method of warmup') + # cuda setting + parser.add_argument('--no-cuda', action='store_true', default=False, + help='disables CUDA training') + parser.add_argument('--local_rank', type=int, default=0) + # checkpoint and log + parser.add_argument('--resume', type=str, default=None, + help='put the path to resuming file if needed') + parser.add_argument('--save-dir', default='~/.torch/models', + help='Directory for saving checkpoint models') + parser.add_argument('--save-epoch', type=int, default=10, + help='save model every checkpoint-epoch') + parser.add_argument('--log-dir', default='../runs/logs/', + help='Directory for saving checkpoint models') + parser.add_argument('--log-iter', type=int, default=10, + help='print log every log-iter') + # evaluation only + parser.add_argument('--val-epoch', type=int, default=1, + help='run validation every val-epoch') + parser.add_argument('--skip-val', action='store_true', default=False, + help='skip validation during training') + # apex + parser.add_argument('--amp', default=False, action='store_true', + help='use amp to train the model') + parser.add_argument('--loss-scale', default=128.0, type=float, + help='loss scale using in amp, default -1 means dynamic') + parser.add_argument('--opt-level', default='O2', type=str, + help='loss scale using in amp, default -1 means dynamic') + + # npu setting + parser.add_argument('--device', default='npu', type=str, + help='npu or gpu') + parser.add_argument('--dist-backend', default='hccl', type=str, + help='distributed backend') + + args = parser.parse_args() + + # default settings for epochs, batch_size and lr + if args.epochs is None: + epoches = { + 'coco': 30, + 'pascal_aug': 80, + 'pascal_voc': 50, + 'pcontext': 80, + 'ade20k': 160, + 'citys': 120, + 'sbu': 160, + } + args.epochs = epoches[args.dataset.lower()] + if args.lr is None: + lrs = { + 'coco': 0.004, + 'pascal_aug': 0.001, + 'pascal_voc': 0.0001, + 'pcontext': 0.001, + 'ade20k': 0.01, + 'citys': 0.01, + 'sbu': 0.001, + } + args.lr = lrs[args.dataset.lower()] / 8 * args.batch_size + return args + + +class Trainer(object): + def __init__(self, args): + self.args = args + # self.device = torch.device(args.device) + + loc = 'npu:{}'.format(args.local_rank) + if args.device == "npu": + self.device = torch.npu.set_device(loc) + else: + self.device = torch.device(args.device) + + # image transform + input_transform = transforms.Compose([ + transforms.ToTensor(), + transforms.Normalize([.485, .456, .406], [.229, .224, .225]), + ]) + # dataset and dataloader + data_kwargs = {'transform': input_transform, 'base_size': args.base_size, 'crop_size': args.crop_size} + train_dataset = get_segmentation_dataset(args.dataset, split='train', mode='train', **data_kwargs) + val_dataset = get_segmentation_dataset(args.dataset, split='val', mode='val', **data_kwargs) + args.iters_per_epoch = len(train_dataset) // (args.num_gpus * args.batch_size) + args.max_iters = args.epochs * args.iters_per_epoch + + train_sampler = make_data_sampler(train_dataset, shuffle=True, distributed=args.distributed) + train_batch_sampler = make_batch_data_sampler(train_sampler, args.batch_size, args.max_iters) + val_sampler = make_data_sampler(val_dataset, False, args.distributed) + val_batch_sampler = make_batch_data_sampler(val_sampler, args.batch_size) + + self.train_loader = data.DataLoader(dataset=train_dataset, + batch_sampler=train_batch_sampler, + num_workers=args.workers, + pin_memory=True) + self.val_loader = data.DataLoader(dataset=val_dataset, + batch_sampler=val_batch_sampler, + num_workers=args.workers, + pin_memory=True) + + # create network + BatchNorm2d = nn.BatchNorm2d#nn.SyncBatchNorm if args.distributed else nn.BatchNorm2d + self.model = get_segmentation_model(model=args.model, dataset=args.dataset, backbone=args.backbone, + aux=args.aux, jpu=args.jpu, norm_layer=BatchNorm2d).to(loc) + + # resume checkpoint if needed + if args.resume: + if os.path.isfile(args.resume): + name, ext = os.path.splitext(args.resume) + assert ext == '.pkl' or '.pth', 'Sorry only .pth and .pkl files supported.' + print('Resuming training, loading {}...'.format(args.resume)) + self.model.load_state_dict(torch.load(args.resume, map_location=lambda storage, loc: storage)) + + # create criterion + self.criterion = get_segmentation_loss(args.model, use_ohem=args.use_ohem, aux=args.aux, + aux_weight=args.aux_weight, ignore_index=-1).to(loc) # (args.device) + + # optimizer, for model just includes pretrained, head and auxlayer + params_list = list() + if hasattr(self.model, 'pretrained'): + params_list.append({'params': self.model.pretrained.parameters(), 'lr': args.lr}) + if hasattr(self.model, 'exclusive'): + for module in self.model.exclusive: + params_list.append({'params': getattr(self.model, module).parameters(), 'lr': args.lr * 10}) + self.optimizer = torch.optim.SGD(params_list, + lr=args.lr, + momentum=args.momentum, + weight_decay=args.weight_decay) + + if args.amp: + self.model, self.optimizer = amp.initialize(self.model, self.optimizer, opt_level=args.opt_level, + loss_scale=args.loss_scale) + + # lr scheduling + self.lr_scheduler = WarmupPolyLR(self.optimizer, + max_iters=args.max_iters, + power=0.9, + warmup_factor=args.warmup_factor, + warmup_iters=args.warmup_iters, + warmup_method=args.warmup_method) + + if args.distributed: + self.model = nn.parallel.DistributedDataParallel(self.model, device_ids=[args.local_rank], + output_device=args.local_rank, find_unused_parameters=True, broadcast_buffers=False) + + # evaluation metrics + self.metric = SegmentationMetric(train_dataset.num_class) + + self.best_pred = 0.0 + + def train(self): + batch_time = AverageMeter('Time', ':6.3f', start_count_index=5) + + loc = 'npu:{}'.format(self.args.local_rank) + + save_to_disk = get_rank() == 0 + epochs, max_iters = self.args.epochs, self.args.max_iters + log_per_iters, val_per_iters = self.args.log_iter, self.args.val_epoch * self.args.iters_per_epoch + save_per_iters = self.args.save_epoch * self.args.iters_per_epoch + start_time = time.time() + logger.info('Start training, Total Epochs: {:d} = Total Iterations {:d}'.format(epochs, max_iters)) + + end = time.time() + + self.model.train() + for iteration, (images, targets, _) in enumerate(self.train_loader): + iteration = iteration + 1 + self.lr_scheduler.step() + + # if 'npu' in CALCULATE_DEVICE: + targets = targets.to(torch.int32) + images = images.to(loc) + targets = targets.to(loc) + + # with torch.autograd.profiler.profile(use_npu=True) as prof: + outputs = self.model(images) + + loss_dict = self.criterion(outputs, targets) + + losses = sum(loss for loss in loss_dict.values()) + + # reduce losses over all GPUs for logging purposes + loss_dict_reduced = reduce_loss_dict(loss_dict) + losses_reduced = sum(loss for loss in loss_dict_reduced.values()) + + self.optimizer.zero_grad() + + # losses.backward() + if self.args.amp: + with amp.scale_loss(losses, self.optimizer) as scaled_loss: + scaled_loss.backward() + else: + losses.backward() + + self.optimizer.step() + + # print(prof.key_averages().table(sort_by="self_cpu_time_total")) + # prof.export_chrome_trace("output.prof") # "output.prof"为输出文件地址 + + eta_seconds = ((time.time() - start_time) / iteration) * (max_iters - iteration) + eta_string = str(datetime.timedelta(seconds=int(eta_seconds))) + + if iteration % log_per_iters == 0 and save_to_disk: + logger.info( + "Iters: {:d}/{:d} || Lr: {:.6f} || Loss: {:.4f} || Cost Time: {} || Estimated Time: {}".format( + iteration, max_iters, self.optimizer.param_groups[0]['lr'], losses_reduced.item(), + str(datetime.timedelta(seconds=int(time.time() - start_time))), eta_string)) + + if iteration % self.args.iters_per_epoch == 0 and batch_time.avg > 0: + logger.info("Epoch: {:d}/{:d} || FPS img/s: {:.3f}".format( + iteration // self.args.iters_per_epoch, epochs, + args.num_gpus * self.args.batch_size / batch_time.avg)) + + if iteration % save_per_iters == 0 and save_to_disk and self.args.local_rank == 0: + save_checkpoint(self.model, self.args, is_best=False) + + batch_time.update(time.time() - end) + + if not self.args.skip_val and iteration % val_per_iters == 0: + self.validation() + self.model.train() + + end = time.time() + + if self.args.local_rank == 0: + save_checkpoint(self.model, self.args, is_best=False) + total_training_time = time.time() - start_time + total_training_str = str(datetime.timedelta(seconds=total_training_time)) + logger.info( + "Total training time: {} ({:.4f}s / it)".format( + total_training_str, total_training_time / max_iters)) + + def validation(self): + loc = 'npu:{}'.format(self.args.local_rank) + + # total_inter, total_union, total_correct, total_label = 0, 0, 0, 0 + is_best = False + self.metric.reset() + #if self.args.distributed: + #model = self.model.module + #else: + model = self.model + torch.npu.empty_cache() # TODO check if it helps + model.eval() + for i, (image, target, filename) in enumerate(self.val_loader): + # if 'npu' in CALCULATE_DEVICE: + # target = target.to(torch.int32) + target = target.to(torch.int32) + image = image.to(loc) + target = target.to(loc) + with torch.no_grad(): + outputs = model(image) + self.metric.update(outputs[0], target) + pixAcc, mIoU = self.metric.get() + logger.info("Sample: {:d}, Validation pixAcc: {:.3f}, mIoU: {:.3f}".format(i + 1, pixAcc, mIoU)) + + new_pred = (pixAcc + mIoU) / 2 + if new_pred > self.best_pred: + is_best = True + self.best_pred = new_pred + if self.args.local_rank == 0: + save_checkpoint(self.model, self.args, is_best) + synchronize() + + +class AverageMeter(object): + """Computes and stores the average and current value""" + + def __init__(self, name, fmt=':f', start_count_index=10): + self.name = name + self.fmt = fmt + self.reset() + self.start_count_index = start_count_index + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + if self.count == 0: + self.N = n + + self.val = val + self.count += n + if self.count > (self.start_count_index * self.N): + self.sum += val * n + self.avg = self.sum / (self.count - self.start_count_index * self.N) + + def __str__(self): + fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' + return fmtstr.format(**self.__dict__) + +def save_checkpoint(model, args, is_best=False): + """Save Checkpoint""" + directory = os.path.expanduser(args.save_dir) + if not os.path.exists(directory): + os.makedirs(directory) + + filename = '{}_{}_{}.pth'.format(args.model, args.backbone, args.dataset) + if args.model == "enet": + filename = '{}_{}.pth'.format(args.model, args.dataset) + filename = os.path.join(directory, filename) + + #if args.distributed: + #model = model.module + torch.save(model.state_dict(), filename) + if is_best: + best_filename = '{}_{}_{}_best_model.pth'.format(args.model, args.backbone, args.dataset) + if args.model == "enet": + best_filename = '{}_{}_best_model.pth'.format(args.model, args.dataset) + best_filename = os.path.join(directory, best_filename) + shutil.copyfile(filename, best_filename) + + +if __name__ == '__main__': + args = parse_args() + + os.environ['MASTER_ADDR'] = '127.0.0.1' # 可以使用当前真实ip或者'127.0.0.1' + os.environ['MASTER_PORT'] = '29688' # 随意一个可使用的port即可 + + # reference maskrcnn-benchmark + num_gpus = int(os.environ["WORLD_SIZE"]) if "WORLD_SIZE" in os.environ else 1 + args.num_gpus = num_gpus + #args.num_gpus = 1 + args.distributed = num_gpus > 1 + + if args.device == "npu": + args.device = "npu" + elif not args.no_cuda and torch.cuda.is_available(): + cudnn.benchmark = True + args.device = "cuda" + else: + args.distributed = False + args.device = "cpu" + if args.distributed: + loc = 'npu:{}'.format(args.local_rank) + torch.npu.set_device(loc) + torch.distributed.init_process_group(backend=args.dist_backend, init_method="env://") + synchronize() + args.lr = args.lr * num_gpus + + logger_filename = '{}_{}_{}_log.txt'.format(args.model, args.backbone, args.dataset) + if args.model == "enet": + logger_filename = '{}_{}_log.txt'.format(args.model, args.dataset) + logger = setup_logger("semantic_segmentation", args.log_dir, get_rank(), filename=logger_filename) + logger.info("Using {} GPUs".format(num_gpus)) + logger.info(args) + + trainer = Trainer(args) + trainer.train() + torch.npu.empty_cache() + diff --git a/PyTorch/contrib/cv/semantic_segmentation/FCN8s/modelzoo_level.txt b/PyTorch/contrib/cv/semantic_segmentation/FCN8s/modelzoo_level.txt index 4987c1069692fa42cf124e9045a3d42b733b2a79..0c22703439d27ef96518c74688e17502e7209c62 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/FCN8s/modelzoo_level.txt +++ b/PyTorch/contrib/cv/semantic_segmentation/FCN8s/modelzoo_level.txt @@ -1,6 +1,6 @@ -GPUStatus:OK -NPUMigrationStatus:OK -FuncStatus:OK -PrecisionStatus:OK -AutoTune:OK +GPUStatus:OK +NPUMigrationStatus:OK +FuncStatus:OK +PrecisionStatus:OK +AutoTune:OK PerfStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/FastSCNN/README.md b/PyTorch/contrib/cv/semantic_segmentation/FastSCNN/README.md index ffa398f6d6bc8d251cbfb79fdefb9fcc70d4c6c7..56198279ee2050d91657bfbe5a17c73600ae331f 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/FastSCNN/README.md +++ b/PyTorch/contrib/cv/semantic_segmentation/FastSCNN/README.md @@ -1,140 +1,140 @@ -# FastSCNN 训练 - -# the real-time image segmentation FastSCNN - -Fast segmentation convolutional neural network (Fast-SCNN), an above real-time semantic segmentation model on high resolution image data (1024x2048px) suits to efficient computation on embedded devices with low memory. Building on existing two-branch methods for fast segmentation, the 'learning to downsample' module computes low-level features for multiple resolution branches simultaneously. FastSCNN combines spatial detail at high resolution with deep features extracted at lower resolution, yielding an accuracy of 68.0% mean intersection over union at 123.5 frames per second on Cityscapes. - -For more detail:https://arxiv.org/abs/1902.04502 - -## - -## Requirements - -use pytorch, you can use pip or conda to install the requirements - -``` -# for pip -cd $project -pip install -r requirements.txt -CANN 20210617_5.0.T205 -torchvision==0.6.0 -``` - - - -## 数据集准备 - -1.从以下网址获取leftImg8bit_trainvaltest.zip作为训练集 - -https://www.cityscapes-dataset.com/downloads/ - -2.从以往网址获取gtFine_trainvaltest.zip作为标签 - -https://www.cityscapes-dataset.com/downloads/ - -文件结构如下: - - -``` -FastSCNN -|-- configs -|-- datasets -| |-- cityscapes -| | |-- gtFine -| | | |-- test -| | | |-- train -| | | `-- val -| | `-- leftImg8bit -| | |-- test -| | |-- train -| | `-- val -|-- docs -|-- test -|-- segmentron -|-- tools - -``` - -将数据集按照以上结构放在代码目录下 - -## 安装 - -请注意,本模型使用了新版本的pytorch以及CANN包,具体版本为:20210617_5.0.T205; - -![](C:\Users\dilig\Pictures\image-20210824164049265 (2).png) - -source 环境变量 - -``` -source ./test/env.sh -``` - -安装 - -``` -python3.7.5 setup.py develop -``` - -或使用sh脚本安装 - -``` -bash ./test/setup.sh -``` - - - -## TRAIN - -### 单p训练 - -source 环境变量 - -``` -source ./test/env.sh -``` - -运行单p脚本 - -``` -bash ./test/run1p.sh -``` - - - -### 多p训练 - -source 环境变量 - -``` -source ./test/env.sh -``` - -运行8p脚本 - -``` -bash ./test/run8p.sh -``` - -模型保存在./runs/checkpoints目录下,以数字命名的pth文件是当前epoch训练得到的权重文件,可用来恢复训练,best_model.pth是当前训练出的最优模型; - -运行日志保存至./runs/logs目录下 - -## TEST - -测试精度 - -使用sh文件 - -``` -bash test/eval.sh -``` - -### 精度对比 - -GPU8p loss scale使用O1 128混合精度获得的结果为:mIoU:64.46 - -NPU8p loss scale使用O1 128混合精度获得的结果为: mIoU:63.914 - -## 注意事项 - -由于在./FastSCNN/segmentron/modules/csrc/vision.cpp中添加了Licence,可能会导致程序在调用此文件时报错,只需要删除Licence就可以使用 +# FastSCNN 训练 + +# the real-time image segmentation FastSCNN + +Fast segmentation convolutional neural network (Fast-SCNN), an above real-time semantic segmentation model on high resolution image data (1024x2048px) suits to efficient computation on embedded devices with low memory. Building on existing two-branch methods for fast segmentation, the 'learning to downsample' module computes low-level features for multiple resolution branches simultaneously. FastSCNN combines spatial detail at high resolution with deep features extracted at lower resolution, yielding an accuracy of 68.0% mean intersection over union at 123.5 frames per second on Cityscapes. + +For more detail:https://arxiv.org/abs/1902.04502 + +## + +## Requirements + +use pytorch, you can use pip or conda to install the requirements + +``` +# for pip +cd $project +pip install -r requirements.txt +CANN 20210617_5.0.T205 +torchvision==0.6.0 +``` + + + +## 数据集准备 + +1.从以下网址获取leftImg8bit_trainvaltest.zip作为训练集 + +https://www.cityscapes-dataset.com/downloads/ + +2.从以往网址获取gtFine_trainvaltest.zip作为标签 + +https://www.cityscapes-dataset.com/downloads/ + +文件结构如下: + + +``` +FastSCNN +|-- configs +|-- datasets +| |-- cityscapes +| | |-- gtFine +| | | |-- test +| | | |-- train +| | | `-- val +| | `-- leftImg8bit +| | |-- test +| | |-- train +| | `-- val +|-- docs +|-- test +|-- segmentron +|-- tools + +``` + +将数据集按照以上结构放在代码目录下 + +## 安装 + +请注意,本模型使用了新版本的pytorch以及CANN包,具体版本为:20210617_5.0.T205; + +![](C:\Users\dilig\Pictures\image-20210824164049265 (2).png) + +source 环境变量 + +``` +source ./test/env.sh +``` + +安装 + +``` +python3.7.5 setup.py develop +``` + +或使用sh脚本安装 + +``` +bash ./test/setup.sh +``` + + + +## TRAIN + +### 单p训练 + +source 环境变量 + +``` +source ./test/env.sh +``` + +运行单p脚本 + +``` +bash ./test/run1p.sh +``` + + + +### 多p训练 + +source 环境变量 + +``` +source ./test/env.sh +``` + +运行8p脚本 + +``` +bash ./test/run8p.sh +``` + +模型保存在./runs/checkpoints目录下,以数字命名的pth文件是当前epoch训练得到的权重文件,可用来恢复训练,best_model.pth是当前训练出的最优模型; + +运行日志保存至./runs/logs目录下 + +## TEST + +测试精度 + +使用sh文件 + +``` +bash test/eval.sh +``` + +### 精度对比 + +GPU8p loss scale使用O1 128混合精度获得的结果为:mIoU:64.46 + +NPU8p loss scale使用O1 128混合精度获得的结果为: mIoU:63.914 + +## 注意事项 + +由于在./FastSCNN/segmentron/modules/csrc/vision.cpp中添加了Licence,可能会导致程序在调用此文件时报错,只需要删除Licence就可以使用 diff --git a/PyTorch/contrib/cv/semantic_segmentation/FastSCNN/modelzoo_level.txt b/PyTorch/contrib/cv/semantic_segmentation/FastSCNN/modelzoo_level.txt index 0673c9bd59b5838ddfddd72ee5f4c355afb112c0..05a5423b13b33ed85d11be6e57b361f5039249be 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/FastSCNN/modelzoo_level.txt +++ b/PyTorch/contrib/cv/semantic_segmentation/FastSCNN/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK,but performance on npu less than performance on gpu +FuncStatus:OK +PerfStatus:OK,but performance on npu less than performance on gpu PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/FastSCNN/segmentron/models/ocnet.py b/PyTorch/contrib/cv/semantic_segmentation/FastSCNN/segmentron/models/ocnet.py index ecd42b5f76306229804a4c6f65be90dee7f95ff4..942039eddfa3e7e800c4b71d22833f2c7742d332 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/FastSCNN/segmentron/models/ocnet.py +++ b/PyTorch/contrib/cv/semantic_segmentation/FastSCNN/segmentron/models/ocnet.py @@ -1,308 +1,308 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import torch -import torch.nn as nn -import torch.nn.functional as F - -from .segbase import SegBaseModel -from .model_zoo import MODEL_REGISTRY -from ..modules import _FCNHead -from ..config import cfg - -__all__ = ['OCNet'] - - -@MODEL_REGISTRY.register() -class OCNet(SegBaseModel): - r"""OCNet - Reference: - Yuhui Yuan, Jingdong Wang. "OCNet: Object Context Network for Scene Parsing." - arXiv preprint arXiv:1809.00916 (2018). - """ - - def __init__(self): - super(OCNet, self).__init__() - oc_arch = cfg.MODEL.OCNet.OC_ARCH - self.head = _OCHead(self.nclass, oc_arch, norm_layer=self.norm_layer) - if self.aux: - self.auxlayer = _FCNHead(1024, self.nclass, norm_layer=self.norm_layer) - - self.__setattr__('decoder', ['head', 'auxlayer'] if self.aux else ['head']) - - def forward(self, x): - size = x.size()[2:] - _, _, c3, c4 = self.base_forward(x) - outputs = [] - x = self.head(c4) - x = F.interpolate(x, size, mode='bilinear', align_corners=True) - outputs.append(x) - - if self.aux: - auxout = self.auxlayer(c3) - auxout = F.interpolate(auxout, size, mode='bilinear', align_corners=True) - outputs.append(auxout) - return tuple(outputs) - - -class _OCHead(nn.Module): - def __init__(self, nclass, oc_arch, norm_layer=nn.BatchNorm2d, **kwargs): - super(_OCHead, self).__init__() - if oc_arch == 'base': - self.context = nn.Sequential( - nn.Conv2d(2048, 512, 3, 1, padding=1, bias=False), - norm_layer(512), - nn.ReLU(True), - BaseOCModule(512, 512, 256, 256, scales=([1]), norm_layer=norm_layer, **kwargs)) - elif oc_arch == 'pyramid': - self.context = nn.Sequential( - nn.Conv2d(2048, 512, 3, 1, padding=1, bias=False), - norm_layer(512), - nn.ReLU(True), - PyramidOCModule(512, 512, 256, 512, scales=([1, 2, 3, 6]), norm_layer=norm_layer, **kwargs)) - elif oc_arch == 'asp': - self.context = ASPOCModule(2048, 512, 256, 512, norm_layer=norm_layer, **kwargs) - else: - raise ValueError("Unknown OC architecture!") - - self.out = nn.Conv2d(512, nclass, 1) - - def forward(self, x): - x = self.context(x) - return self.out(x) - - -class BaseAttentionBlock(nn.Module): - """The basic implementation for self-attention block/non-local block.""" - - def __init__(self, in_channels, out_channels, key_channels, value_channels, - scale=1, norm_layer=nn.BatchNorm2d, **kwargs): - super(BaseAttentionBlock, self).__init__() - self.scale = scale - self.key_channels = key_channels - self.value_channels = value_channels - if scale > 1: - self.pool = nn.MaxPool2d(scale) - - self.f_value = nn.Conv2d(in_channels, value_channels, 1) - self.f_key = nn.Sequential( - nn.Conv2d(in_channels, key_channels, 1), - norm_layer(key_channels), - nn.ReLU(True) - ) - self.f_query = self.f_key - self.W = nn.Conv2d(value_channels, out_channels, 1) - nn.init.constant_(self.W.weight, 0) - nn.init.constant_(self.W.bias, 0) - - def forward(self, x): - batch_size, c, w, h = x.size() - if self.scale > 1: - x = self.pool(x) - - value = self.f_value(x).view(batch_size, self.value_channels, -1).permute(0, 2, 1) - query = self.f_query(x).view(batch_size, self.key_channels, -1).permute(0, 2, 1) - key = self.f_key(x).view(batch_size, self.key_channels, -1) - - sim_map = torch.bmm(query, key) * (self.key_channels ** -.5) - sim_map = F.softmax(sim_map, dim=-1) - - context = torch.bmm(sim_map, value).permute(0, 2, 1).contiguous() - context = context.view(batch_size, self.value_channels, *x.size()[2:]) - context = self.W(context) - if self.scale > 1: - context = F.interpolate(context, size=(w, h), mode='bilinear', align_corners=True) - - return context - - -class BaseOCModule(nn.Module): - """Base-OC""" - - def __init__(self, in_channels, out_channels, key_channels, value_channels, - scales=([1]), norm_layer=nn.BatchNorm2d, concat=True, **kwargs): - super(BaseOCModule, self).__init__() - self.stages = nn.ModuleList([ - BaseAttentionBlock(in_channels, out_channels, key_channels, value_channels, scale, norm_layer, **kwargs) - for scale in scales]) - in_channels = in_channels * 2 if concat else in_channels - self.project = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 1), - norm_layer(out_channels), - nn.ReLU(True), - nn.Dropout2d(0.05) - ) - self.concat = concat - - def forward(self, x): - priors = [stage(x) for stage in self.stages] - context = priors[0] - for i in range(1, len(priors)): - context += priors[i] - if self.concat: - context = torch.cat([context, x], 1) - out = self.project(context) - return out - - -class PyramidAttentionBlock(nn.Module): - """The basic implementation for pyramid self-attention block/non-local block""" - - def __init__(self, in_channels, out_channels, key_channels, value_channels, - scale=1, norm_layer=nn.BatchNorm2d, **kwargs): - super(PyramidAttentionBlock, self).__init__() - self.scale = scale - self.value_channels = value_channels - self.key_channels = key_channels - - self.f_value = nn.Conv2d(in_channels, value_channels, 1) - self.f_key = nn.Sequential( - nn.Conv2d(in_channels, key_channels, 1), - norm_layer(key_channels), - nn.ReLU(True) - ) - self.f_query = self.f_key - self.W = nn.Conv2d(value_channels, out_channels, 1) - nn.init.constant_(self.W.weight, 0) - nn.init.constant_(self.W.bias, 0) - - def forward(self, x): - batch_size, c, w, h = x.size() - - local_x = list() - local_y = list() - step_w, step_h = w // self.scale, h // self.scale - for i in range(self.scale): - for j in range(self.scale): - start_x, start_y = step_w * i, step_h * j - end_x, end_y = min(start_x + step_w, w), min(start_y + step_h, h) - if i == (self.scale - 1): - end_x = w - if j == (self.scale - 1): - end_y = h - local_x += [start_x, end_x] - local_y += [start_y, end_y] - - value = self.f_value(x) - query = self.f_query(x) - key = self.f_key(x) - - local_list = list() - local_block_cnt = (self.scale ** 2) * 2 - for i in range(0, local_block_cnt, 2): - value_local = value[:, :, local_x[i]:local_x[i + 1], local_y[i]:local_y[i + 1]] - query_local = query[:, :, local_x[i]:local_x[i + 1], local_y[i]:local_y[i + 1]] - key_local = key[:, :, local_x[i]:local_x[i + 1], local_y[i]:local_y[i + 1]] - - w_local, h_local = value_local.size(2), value_local.size(3) - value_local = value_local.contiguous().view(batch_size, self.value_channels, -1).permute(0, 2, 1) - query_local = query_local.contiguous().view(batch_size, self.key_channels, -1).permute(0, 2, 1) - key_local = key_local.contiguous().view(batch_size, self.key_channels, -1) - - sim_map = torch.bmm(query_local, key_local) * (self.key_channels ** -.5) - sim_map = F.softmax(sim_map, dim=-1) - - context_local = torch.bmm(sim_map, value_local).permute(0, 2, 1).contiguous() - context_local = context_local.view(batch_size, self.value_channels, w_local, h_local) - local_list.append(context_local) - - context_list = list() - for i in range(0, self.scale): - row_tmp = list() - for j in range(self.scale): - row_tmp.append(local_list[j + i * self.scale]) - context_list.append(torch.cat(row_tmp, 3)) - - context = torch.cat(context_list, 2) - context = self.W(context) - - return context - - -class PyramidOCModule(nn.Module): - """Pyramid-OC""" - - def __init__(self, in_channels, out_channels, key_channels, value_channels, - scales=([1]), norm_layer=nn.BatchNorm2d, **kwargs): - super(PyramidOCModule, self).__init__() - self.stages = nn.ModuleList([ - PyramidAttentionBlock(in_channels, out_channels, key_channels, value_channels, scale, norm_layer, **kwargs) - for scale in scales]) - self.up_dr = nn.Sequential( - nn.Conv2d(in_channels, in_channels * len(scales), 1), - norm_layer(in_channels * len(scales)), - nn.ReLU(True) - ) - self.project = nn.Sequential( - nn.Conv2d(in_channels * len(scales) * 2, out_channels, 1), - norm_layer(out_channels), - nn.ReLU(True), - nn.Dropout2d(0.05) - ) - - def forward(self, x): - priors = [stage(x) for stage in self.stages] - context = [self.up_dr(x)] - for i in range(len(priors)): - context += [priors[i]] - context = torch.cat(context, 1) - out = self.project(context) - return out - - -class ASPOCModule(nn.Module): - """ASP-OC""" - - def __init__(self, in_channels, out_channels, key_channels, value_channels, - atrous_rates=(12, 24, 36), norm_layer=nn.BatchNorm2d, **kwargs): - super(ASPOCModule, self).__init__() - self.context = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 3, padding=1), - norm_layer(out_channels), - nn.ReLU(True), - BaseOCModule(out_channels, out_channels, key_channels, value_channels, ([2]), norm_layer, False, **kwargs)) - - rate1, rate2, rate3 = tuple(atrous_rates) - self.b1 = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 3, padding=rate1, dilation=rate1, bias=False), - norm_layer(out_channels), - nn.ReLU(True)) - self.b2 = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 3, padding=rate2, dilation=rate2, bias=False), - norm_layer(out_channels), - nn.ReLU(True)) - self.b3 = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 3, padding=rate3, dilation=rate3, bias=False), - norm_layer(out_channels), - nn.ReLU(True)) - self.b4 = nn.Sequential( - nn.Conv2d(in_channels, out_channels, 1, bias=False), - norm_layer(out_channels), - nn.ReLU(True)) - - self.project = nn.Sequential( - nn.Conv2d(out_channels * 5, out_channels, 1, bias=False), - norm_layer(out_channels), - nn.ReLU(True), - nn.Dropout2d(0.1) - ) - - def forward(self, x): - feat1 = self.context(x) - feat2 = self.b1(x) - feat3 = self.b2(x) - feat4 = self.b3(x) - feat5 = self.b4(x) - out = torch.cat((feat1, feat2, feat3, feat4, feat5), dim=1) - out = self.project(out) - return out +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import torch +import torch.nn as nn +import torch.nn.functional as F + +from .segbase import SegBaseModel +from .model_zoo import MODEL_REGISTRY +from ..modules import _FCNHead +from ..config import cfg + +__all__ = ['OCNet'] + + +@MODEL_REGISTRY.register() +class OCNet(SegBaseModel): + r"""OCNet + Reference: + Yuhui Yuan, Jingdong Wang. "OCNet: Object Context Network for Scene Parsing." + arXiv preprint arXiv:1809.00916 (2018). + """ + + def __init__(self): + super(OCNet, self).__init__() + oc_arch = cfg.MODEL.OCNet.OC_ARCH + self.head = _OCHead(self.nclass, oc_arch, norm_layer=self.norm_layer) + if self.aux: + self.auxlayer = _FCNHead(1024, self.nclass, norm_layer=self.norm_layer) + + self.__setattr__('decoder', ['head', 'auxlayer'] if self.aux else ['head']) + + def forward(self, x): + size = x.size()[2:] + _, _, c3, c4 = self.base_forward(x) + outputs = [] + x = self.head(c4) + x = F.interpolate(x, size, mode='bilinear', align_corners=True) + outputs.append(x) + + if self.aux: + auxout = self.auxlayer(c3) + auxout = F.interpolate(auxout, size, mode='bilinear', align_corners=True) + outputs.append(auxout) + return tuple(outputs) + + +class _OCHead(nn.Module): + def __init__(self, nclass, oc_arch, norm_layer=nn.BatchNorm2d, **kwargs): + super(_OCHead, self).__init__() + if oc_arch == 'base': + self.context = nn.Sequential( + nn.Conv2d(2048, 512, 3, 1, padding=1, bias=False), + norm_layer(512), + nn.ReLU(True), + BaseOCModule(512, 512, 256, 256, scales=([1]), norm_layer=norm_layer, **kwargs)) + elif oc_arch == 'pyramid': + self.context = nn.Sequential( + nn.Conv2d(2048, 512, 3, 1, padding=1, bias=False), + norm_layer(512), + nn.ReLU(True), + PyramidOCModule(512, 512, 256, 512, scales=([1, 2, 3, 6]), norm_layer=norm_layer, **kwargs)) + elif oc_arch == 'asp': + self.context = ASPOCModule(2048, 512, 256, 512, norm_layer=norm_layer, **kwargs) + else: + raise ValueError("Unknown OC architecture!") + + self.out = nn.Conv2d(512, nclass, 1) + + def forward(self, x): + x = self.context(x) + return self.out(x) + + +class BaseAttentionBlock(nn.Module): + """The basic implementation for self-attention block/non-local block.""" + + def __init__(self, in_channels, out_channels, key_channels, value_channels, + scale=1, norm_layer=nn.BatchNorm2d, **kwargs): + super(BaseAttentionBlock, self).__init__() + self.scale = scale + self.key_channels = key_channels + self.value_channels = value_channels + if scale > 1: + self.pool = nn.MaxPool2d(scale) + + self.f_value = nn.Conv2d(in_channels, value_channels, 1) + self.f_key = nn.Sequential( + nn.Conv2d(in_channels, key_channels, 1), + norm_layer(key_channels), + nn.ReLU(True) + ) + self.f_query = self.f_key + self.W = nn.Conv2d(value_channels, out_channels, 1) + nn.init.constant_(self.W.weight, 0) + nn.init.constant_(self.W.bias, 0) + + def forward(self, x): + batch_size, c, w, h = x.size() + if self.scale > 1: + x = self.pool(x) + + value = self.f_value(x).view(batch_size, self.value_channels, -1).permute(0, 2, 1) + query = self.f_query(x).view(batch_size, self.key_channels, -1).permute(0, 2, 1) + key = self.f_key(x).view(batch_size, self.key_channels, -1) + + sim_map = torch.bmm(query, key) * (self.key_channels ** -.5) + sim_map = F.softmax(sim_map, dim=-1) + + context = torch.bmm(sim_map, value).permute(0, 2, 1).contiguous() + context = context.view(batch_size, self.value_channels, *x.size()[2:]) + context = self.W(context) + if self.scale > 1: + context = F.interpolate(context, size=(w, h), mode='bilinear', align_corners=True) + + return context + + +class BaseOCModule(nn.Module): + """Base-OC""" + + def __init__(self, in_channels, out_channels, key_channels, value_channels, + scales=([1]), norm_layer=nn.BatchNorm2d, concat=True, **kwargs): + super(BaseOCModule, self).__init__() + self.stages = nn.ModuleList([ + BaseAttentionBlock(in_channels, out_channels, key_channels, value_channels, scale, norm_layer, **kwargs) + for scale in scales]) + in_channels = in_channels * 2 if concat else in_channels + self.project = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 1), + norm_layer(out_channels), + nn.ReLU(True), + nn.Dropout2d(0.05) + ) + self.concat = concat + + def forward(self, x): + priors = [stage(x) for stage in self.stages] + context = priors[0] + for i in range(1, len(priors)): + context += priors[i] + if self.concat: + context = torch.cat([context, x], 1) + out = self.project(context) + return out + + +class PyramidAttentionBlock(nn.Module): + """The basic implementation for pyramid self-attention block/non-local block""" + + def __init__(self, in_channels, out_channels, key_channels, value_channels, + scale=1, norm_layer=nn.BatchNorm2d, **kwargs): + super(PyramidAttentionBlock, self).__init__() + self.scale = scale + self.value_channels = value_channels + self.key_channels = key_channels + + self.f_value = nn.Conv2d(in_channels, value_channels, 1) + self.f_key = nn.Sequential( + nn.Conv2d(in_channels, key_channels, 1), + norm_layer(key_channels), + nn.ReLU(True) + ) + self.f_query = self.f_key + self.W = nn.Conv2d(value_channels, out_channels, 1) + nn.init.constant_(self.W.weight, 0) + nn.init.constant_(self.W.bias, 0) + + def forward(self, x): + batch_size, c, w, h = x.size() + + local_x = list() + local_y = list() + step_w, step_h = w // self.scale, h // self.scale + for i in range(self.scale): + for j in range(self.scale): + start_x, start_y = step_w * i, step_h * j + end_x, end_y = min(start_x + step_w, w), min(start_y + step_h, h) + if i == (self.scale - 1): + end_x = w + if j == (self.scale - 1): + end_y = h + local_x += [start_x, end_x] + local_y += [start_y, end_y] + + value = self.f_value(x) + query = self.f_query(x) + key = self.f_key(x) + + local_list = list() + local_block_cnt = (self.scale ** 2) * 2 + for i in range(0, local_block_cnt, 2): + value_local = value[:, :, local_x[i]:local_x[i + 1], local_y[i]:local_y[i + 1]] + query_local = query[:, :, local_x[i]:local_x[i + 1], local_y[i]:local_y[i + 1]] + key_local = key[:, :, local_x[i]:local_x[i + 1], local_y[i]:local_y[i + 1]] + + w_local, h_local = value_local.size(2), value_local.size(3) + value_local = value_local.contiguous().view(batch_size, self.value_channels, -1).permute(0, 2, 1) + query_local = query_local.contiguous().view(batch_size, self.key_channels, -1).permute(0, 2, 1) + key_local = key_local.contiguous().view(batch_size, self.key_channels, -1) + + sim_map = torch.bmm(query_local, key_local) * (self.key_channels ** -.5) + sim_map = F.softmax(sim_map, dim=-1) + + context_local = torch.bmm(sim_map, value_local).permute(0, 2, 1).contiguous() + context_local = context_local.view(batch_size, self.value_channels, w_local, h_local) + local_list.append(context_local) + + context_list = list() + for i in range(0, self.scale): + row_tmp = list() + for j in range(self.scale): + row_tmp.append(local_list[j + i * self.scale]) + context_list.append(torch.cat(row_tmp, 3)) + + context = torch.cat(context_list, 2) + context = self.W(context) + + return context + + +class PyramidOCModule(nn.Module): + """Pyramid-OC""" + + def __init__(self, in_channels, out_channels, key_channels, value_channels, + scales=([1]), norm_layer=nn.BatchNorm2d, **kwargs): + super(PyramidOCModule, self).__init__() + self.stages = nn.ModuleList([ + PyramidAttentionBlock(in_channels, out_channels, key_channels, value_channels, scale, norm_layer, **kwargs) + for scale in scales]) + self.up_dr = nn.Sequential( + nn.Conv2d(in_channels, in_channels * len(scales), 1), + norm_layer(in_channels * len(scales)), + nn.ReLU(True) + ) + self.project = nn.Sequential( + nn.Conv2d(in_channels * len(scales) * 2, out_channels, 1), + norm_layer(out_channels), + nn.ReLU(True), + nn.Dropout2d(0.05) + ) + + def forward(self, x): + priors = [stage(x) for stage in self.stages] + context = [self.up_dr(x)] + for i in range(len(priors)): + context += [priors[i]] + context = torch.cat(context, 1) + out = self.project(context) + return out + + +class ASPOCModule(nn.Module): + """ASP-OC""" + + def __init__(self, in_channels, out_channels, key_channels, value_channels, + atrous_rates=(12, 24, 36), norm_layer=nn.BatchNorm2d, **kwargs): + super(ASPOCModule, self).__init__() + self.context = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 3, padding=1), + norm_layer(out_channels), + nn.ReLU(True), + BaseOCModule(out_channels, out_channels, key_channels, value_channels, ([2]), norm_layer, False, **kwargs)) + + rate1, rate2, rate3 = tuple(atrous_rates) + self.b1 = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 3, padding=rate1, dilation=rate1, bias=False), + norm_layer(out_channels), + nn.ReLU(True)) + self.b2 = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 3, padding=rate2, dilation=rate2, bias=False), + norm_layer(out_channels), + nn.ReLU(True)) + self.b3 = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 3, padding=rate3, dilation=rate3, bias=False), + norm_layer(out_channels), + nn.ReLU(True)) + self.b4 = nn.Sequential( + nn.Conv2d(in_channels, out_channels, 1, bias=False), + norm_layer(out_channels), + nn.ReLU(True)) + + self.project = nn.Sequential( + nn.Conv2d(out_channels * 5, out_channels, 1, bias=False), + norm_layer(out_channels), + nn.ReLU(True), + nn.Dropout2d(0.1) + ) + + def forward(self, x): + feat1 = self.context(x) + feat2 = self.b1(x) + feat3 = self.b2(x) + feat4 = self.b3(x) + feat5 = self.b4(x) + out = torch.cat((feat1, feat2, feat3, feat4, feat5), dim=1) + out = self.project(out) + return out diff --git a/PyTorch/contrib/cv/semantic_segmentation/HRNet_SEG_for_Pytorch/figures/OCR.PNG b/PyTorch/contrib/cv/semantic_segmentation/HRNet_SEG_for_Pytorch/figures/OCR.PNG deleted file mode 100644 index 4b72e990fd559ff19bd91756b08475cff30b5aa9..0000000000000000000000000000000000000000 Binary files a/PyTorch/contrib/cv/semantic_segmentation/HRNet_SEG_for_Pytorch/figures/OCR.PNG and /dev/null differ diff --git a/PyTorch/contrib/cv/semantic_segmentation/HRnet-OCR/README.md b/PyTorch/contrib/cv/semantic_segmentation/HRnet-OCR/README.md index f1a53a63d9a35f55e20506591c29765b79e70292..f31f065a189498710654ba793117f6a27b7353ba 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/HRnet-OCR/README.md +++ b/PyTorch/contrib/cv/semantic_segmentation/HRnet-OCR/README.md @@ -1,65 +1,65 @@ -# HRnet-OCR - -## 模型简介 - -- 参考实现: - -``` -url=https:https://github.com/NVIDIA/semantic-segmentation -branch=master -commit_id=7726b144c2cc0b8e09c67eabb78f027efdf3f0fa -``` - -- 模型原理:HRnet-OCR模型为图像分割网络,通过将注意力机制和多尺度预测的方法结合,实现了更快速的训练模型并保持更高精度。 - -## Requirements - -- CANN 5.0.3.1 -- torch 1.5.0+ascend.post3.20210930 -- apex 0.1+ascend.20210930 -- tensor-fused-plugin 0.1+ascend -- te 0.4.0 -- python 3.7.5 -- runx 0.0.11 -- torchvision 0.6.0 - -## 配置数据集路径 - -采用Cityscapes数据集 - -参考源码仓的方式获取数据集:https://github.com/NVIDIA/semantic-segmentation - -获取数据集后需按照源代码仓Download/Prepare Data指示配置数据集路径 - -## 配置预训练模型 - -预训练模型权重在作者源代码仓中均已给出,配置路径请参照源代码仓Download Weights进行配置 - -## NPU 单卡训练命令 - -- 训练(注:训练结束后模型将自动打印评估结果): - -``` -nohup bash test/train_full_1p.sh --data_path=./large_asset_dir/ & -``` - -- 性能: - -``` -nohup bash test/train_performance_1p.sh --data_path=./large_asset_dir/ & -``` - -## NPU 8卡训练命令 - -- 训练(注:训练结束后模型将自动打印评估结果): - -``` -nohup bash test/train_full_8p.sh --data_path=./large_asset_dir/ & -``` - -- 性能: - -``` -nohup bash test/train_performance_8p.sh --data_path=./large_asset_dir/ & -``` - +# HRnet-OCR + +## 模型简介 + +- 参考实现: + +``` +url=https:https://github.com/NVIDIA/semantic-segmentation +branch=master +commit_id=7726b144c2cc0b8e09c67eabb78f027efdf3f0fa +``` + +- 模型原理:HRnet-OCR模型为图像分割网络,通过将注意力机制和多尺度预测的方法结合,实现了更快速的训练模型并保持更高精度。 + +## Requirements + +- CANN 5.0.3.1 +- torch 1.5.0+ascend.post3.20210930 +- apex 0.1+ascend.20210930 +- tensor-fused-plugin 0.1+ascend +- te 0.4.0 +- python 3.7.5 +- runx 0.0.11 +- torchvision 0.6.0 + +## 配置数据集路径 + +采用Cityscapes数据集 + +参考源码仓的方式获取数据集:https://github.com/NVIDIA/semantic-segmentation + +获取数据集后需按照源代码仓Download/Prepare Data指示配置数据集路径 + +## 配置预训练模型 + +预训练模型权重在作者源代码仓中均已给出,配置路径请参照源代码仓Download Weights进行配置 + +## NPU 单卡训练命令 + +- 训练(注:训练结束后模型将自动打印评估结果): + +``` +nohup bash test/train_full_1p.sh --data_path=./large_asset_dir/ & +``` + +- 性能: + +``` +nohup bash test/train_performance_1p.sh --data_path=./large_asset_dir/ & +``` + +## NPU 8卡训练命令 + +- 训练(注:训练结束后模型将自动打印评估结果): + +``` +nohup bash test/train_full_8p.sh --data_path=./large_asset_dir/ & +``` + +- 性能: + +``` +nohup bash test/train_performance_8p.sh --data_path=./large_asset_dir/ & +``` + diff --git a/PyTorch/contrib/cv/semantic_segmentation/HRnet-OCR/modelzoo_level.txt b/PyTorch/contrib/cv/semantic_segmentation/HRnet-OCR/modelzoo_level.txt index 405b26618a0c92027927a9c583a4b47f640bcf7b..c45626e398eabe6022fe7b2e148f0ffce6400d6e 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/HRnet-OCR/modelzoo_level.txt +++ b/PyTorch/contrib/cv/semantic_segmentation/HRnet-OCR/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:POK +FuncStatus:OK +PerfStatus:POK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/HRnet-OCR/utils/results_page.py b/PyTorch/contrib/cv/semantic_segmentation/HRnet-OCR/utils/results_page.py index 80c7ad5529d95a7f7c17574e6d9ede44abf2581c..840902241107847a14328eda5aca3c051483d685 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/HRnet-OCR/utils/results_page.py +++ b/PyTorch/contrib/cv/semantic_segmentation/HRnet-OCR/utils/results_page.py @@ -1,276 +1,276 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -""" -Copyright 2020 Nvidia Corporation - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. -""" - -import glob -import os -import numpy as np - -id2cat = { - 0: 'road', - 1: 'sidewalk', - 2: 'building', - 3: 'wall', - 4: 'fence', - 5: 'pole', - 6: 'traffic_light', - 7: 'traffic_sign', - 8: 'vegetation', - 9: 'terrain', - 10: 'sky', - 11: 'person', - 12: 'rider', - 13: 'car', - 14: 'truck', - 15: 'bus', - 16: 'train', - 17: 'motorcycle', - 18: 'bicycle'} - -# Leaderboard mapillary -sota_iu_results = { - 0: 98.4046, - 1: 85.0224, - 2: 93.6462, - 3: 61.7487, - 4: 63.8885, - 5: 67.6745, - 6: 77.43, - 7: 80.8351, - 8: 93.7341, - 9: 71.8774, - 10: 95.6122, - 11: 86.7228, - 12: 72.7778, - 13: 95.7033, - 14: 79.9019, - 15: 93.0954, - 16: 89.7196, - 17: 72.5731, - 18: 78.2172, - 255: 0} - - -class ResultsPage(object): - ''' - This creates an HTML page of embedded images, useful for showing evaluation results. - - Usage: - ip = ImagePage(html_fn) - - # Add a table with N images ... - ip.add_table((img, descr), (img, descr), ...) - - # Generate html page - ip.write_page() - ''' - - def __init__(self, experiment_name, html_filename): - self.experiment_name = experiment_name - self.html_filename = html_filename - self.outfile = open(self.html_filename, 'w') - self.items = [] - - def _print_header(self): - header = ''' - - - Experiment = {} - - '''.format(self.experiment_name) - self.outfile.write(header) - - def _print_footer(self): - self.outfile.write(''' -''') - - def _print_table_header(self, table_name): - table_hdr = '''

{}

- - '''.format(table_name) - self.outfile.write(table_hdr) - - def _print_table_footer(self): - table_ftr = ''' -
''' - self.outfile.write(table_ftr) - - def _print_table_guts(self, img_fn, descr): - table = ''' -

- - -
-

{descr}

-

- '''.format(img_fn=img_fn, descr=descr) - self.outfile.write(table) - - def add_table(self, img_label_pairs, table_heading=''): - """ - :img_label_pairs: A list of pairs of [img,label] - """ - self.items.append([img_label_pairs, table_heading]) - - def _write_table(self, table, heading): - img, _descr = table[0] - self._print_table_header(heading) - for img, descr in table: - self._print_table_guts(img, descr) - self._print_table_footer() - - def write_page(self): - self._print_header() - - for table, heading in self.items: - self._write_table(table, heading) - - self._print_footer() - - def _print_page_start(self): - page_start = ''' - - -Experiment = EXP_NAME - - -''' - self.outfile.write(page_start) - - def _print_table_start(self, caption, hdr): - self.outfile.write(''' - - '''.format(caption)) - for hdr_col in hdr: - self.outfile.write(' '.format(hdr_col)) - self.outfile.write(' ') - - def _print_table_row(self, row): - self.outfile.write(' ') - for i in row: - self.outfile.write(' '.format(i)) - # Create Links - fp_link = 'false positive Top N'.format(row[ - 1]) - fn_link = 'false_negative Top N'.format(row[ - 1]) - self.outfile.write(' '.format(fp_link)) - self.outfile.write(' '.format(fn_link)) - self.outfile.write(' ') - - def _print_table_end(self): - self.outfile.write('
{}
{}
{}{}{}
') - - def _print_page_end(self): - self.outfile.write(''' - -''') - - def create_main(self, iu, hist): - self._print_page_start() - #_print_table_style() - # Calculate all of the terms: - iu_false_positive = hist.sum(axis=1) - np.diag(hist) - iu_false_negative = hist.sum(axis=0) - np.diag(hist) - iu_true_positive = np.diag(hist) - - hdr = ("Class ID", "Class", "IoU", "Sota-IU", "TP", - "FP", "FN", "precision", "recall", "", "") - self._print_table_start("Mean IoU Results", hdr) - for iu_score, index in iu: - class_name = id2cat[index] - iu_string = '{:5.2f}'.format(iu_score * 100) - total_pixels = hist.sum() - tp = '{:5.2f}'.format(100 * iu_true_positive[index] / total_pixels) - fp = '{:5.2f}'.format( - iu_false_positive[index] / iu_true_positive[index]) - fn = '{:5.2f}'.format( - iu_false_negative[index] / iu_true_positive[index]) - precision = '{:5.2f}'.format( - iu_true_positive[index] / (iu_true_positive[index] + iu_false_positive[index])) - recall = '{:5.2f}'.format( - iu_true_positive[index] / (iu_true_positive[index] + iu_false_negative[index])) - sota = '{:5.2f}'.format(sota_iu_results[index]) - row = (index, class_name, iu_string, sota, - tp, fp, fn, precision, recall) - self._print_table_row(row) - self._print_table_end() - self._print_page_end() - - -def main(): - images = glob.glob('dump_imgs_train/*.png') - images = [i for i in images if 'mask' not in i] - - ip = ResultsPage('test page', 'dd.html') - for img in images: - basename = os.path.splitext(img)[0] - mask_img = basename + '_mask.png' - ip.add_table(((img, 'image'), (mask_img, 'mask'))) - ip.write_page() +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +""" +Copyright 2020 Nvidia Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +""" + +import glob +import os +import numpy as np + +id2cat = { + 0: 'road', + 1: 'sidewalk', + 2: 'building', + 3: 'wall', + 4: 'fence', + 5: 'pole', + 6: 'traffic_light', + 7: 'traffic_sign', + 8: 'vegetation', + 9: 'terrain', + 10: 'sky', + 11: 'person', + 12: 'rider', + 13: 'car', + 14: 'truck', + 15: 'bus', + 16: 'train', + 17: 'motorcycle', + 18: 'bicycle'} + +# Leaderboard mapillary +sota_iu_results = { + 0: 98.4046, + 1: 85.0224, + 2: 93.6462, + 3: 61.7487, + 4: 63.8885, + 5: 67.6745, + 6: 77.43, + 7: 80.8351, + 8: 93.7341, + 9: 71.8774, + 10: 95.6122, + 11: 86.7228, + 12: 72.7778, + 13: 95.7033, + 14: 79.9019, + 15: 93.0954, + 16: 89.7196, + 17: 72.5731, + 18: 78.2172, + 255: 0} + + +class ResultsPage(object): + ''' + This creates an HTML page of embedded images, useful for showing evaluation results. + + Usage: + ip = ImagePage(html_fn) + + # Add a table with N images ... + ip.add_table((img, descr), (img, descr), ...) + + # Generate html page + ip.write_page() + ''' + + def __init__(self, experiment_name, html_filename): + self.experiment_name = experiment_name + self.html_filename = html_filename + self.outfile = open(self.html_filename, 'w') + self.items = [] + + def _print_header(self): + header = ''' + + + Experiment = {} + + '''.format(self.experiment_name) + self.outfile.write(header) + + def _print_footer(self): + self.outfile.write(''' +''') + + def _print_table_header(self, table_name): + table_hdr = '''

{}

+ + '''.format(table_name) + self.outfile.write(table_hdr) + + def _print_table_footer(self): + table_ftr = ''' +
''' + self.outfile.write(table_ftr) + + def _print_table_guts(self, img_fn, descr): + table = ''' +

+ + +
+

{descr}

+

+ '''.format(img_fn=img_fn, descr=descr) + self.outfile.write(table) + + def add_table(self, img_label_pairs, table_heading=''): + """ + :img_label_pairs: A list of pairs of [img,label] + """ + self.items.append([img_label_pairs, table_heading]) + + def _write_table(self, table, heading): + img, _descr = table[0] + self._print_table_header(heading) + for img, descr in table: + self._print_table_guts(img, descr) + self._print_table_footer() + + def write_page(self): + self._print_header() + + for table, heading in self.items: + self._write_table(table, heading) + + self._print_footer() + + def _print_page_start(self): + page_start = ''' + + +Experiment = EXP_NAME + + +''' + self.outfile.write(page_start) + + def _print_table_start(self, caption, hdr): + self.outfile.write(''' + + '''.format(caption)) + for hdr_col in hdr: + self.outfile.write(' '.format(hdr_col)) + self.outfile.write(' ') + + def _print_table_row(self, row): + self.outfile.write(' ') + for i in row: + self.outfile.write(' '.format(i)) + # Create Links + fp_link = 'false positive Top N'.format(row[ + 1]) + fn_link = 'false_negative Top N'.format(row[ + 1]) + self.outfile.write(' '.format(fp_link)) + self.outfile.write(' '.format(fn_link)) + self.outfile.write(' ') + + def _print_table_end(self): + self.outfile.write('
{}
{}
{}{}{}
') + + def _print_page_end(self): + self.outfile.write(''' + +''') + + def create_main(self, iu, hist): + self._print_page_start() + #_print_table_style() + # Calculate all of the terms: + iu_false_positive = hist.sum(axis=1) - np.diag(hist) + iu_false_negative = hist.sum(axis=0) - np.diag(hist) + iu_true_positive = np.diag(hist) + + hdr = ("Class ID", "Class", "IoU", "Sota-IU", "TP", + "FP", "FN", "precision", "recall", "", "") + self._print_table_start("Mean IoU Results", hdr) + for iu_score, index in iu: + class_name = id2cat[index] + iu_string = '{:5.2f}'.format(iu_score * 100) + total_pixels = hist.sum() + tp = '{:5.2f}'.format(100 * iu_true_positive[index] / total_pixels) + fp = '{:5.2f}'.format( + iu_false_positive[index] / iu_true_positive[index]) + fn = '{:5.2f}'.format( + iu_false_negative[index] / iu_true_positive[index]) + precision = '{:5.2f}'.format( + iu_true_positive[index] / (iu_true_positive[index] + iu_false_positive[index])) + recall = '{:5.2f}'.format( + iu_true_positive[index] / (iu_true_positive[index] + iu_false_negative[index])) + sota = '{:5.2f}'.format(sota_iu_results[index]) + row = (index, class_name, iu_string, sota, + tp, fp, fn, precision, recall) + self._print_table_row(row) + self._print_table_end() + self._print_page_end() + + +def main(): + images = glob.glob('dump_imgs_train/*.png') + images = [i for i in images if 'mask' not in i] + + ip = ResultsPage('test page', 'dd.html') + for img in images: + basename = os.path.splitext(img)[0] + mask_img = basename + '_mask.png' + ip.add_table(((img, 'image'), (mask_img, 'mask'))) + ip.write_page() diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/__init__.py b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/__init__.py index 55887fca321859e7fe8df0054b4761e83a7b4210..945cb920d49428f81bc1c2597ffa7a2a61e8ef81 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/__init__.py +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/__init__.py @@ -1,13 +1,13 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/dataset/__init__.py b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/dataset/__init__.py index 55887fca321859e7fe8df0054b4761e83a7b4210..945cb920d49428f81bc1c2597ffa7a2a61e8ef81 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/dataset/__init__.py +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/dataset/__init__.py @@ -1,13 +1,13 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/__init__.py b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/__init__.py index 55887fca321859e7fe8df0054b4761e83a7b4210..945cb920d49428f81bc1c2597ffa7a2a61e8ef81 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/__init__.py +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/__init__.py @@ -1,13 +1,13 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/config.py b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/config.py index f9a2ffbacd4e577cbd4bd3df4f9dd8a7ec8e3805..49411a50bc9ac37bf956900db07b396858660c51 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/config.py +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/config.py @@ -1,156 +1,156 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -------------------------------------------------------- -# Configurations for domain adaptation -# Copyright (c) 2019 valeo.ai -# -# Written by Tuan-Hung Vu -# Adapted from https://github.com/rbgirshick/py-faster-rcnn/blob/master/lib/fast_rcnn/config.py -# -------------------------------------------------------- - -import os.path as osp - -import numpy as np -from easydict import EasyDict - -from advent.utils import project_root -from advent.utils.serialization import yaml_load - - -cfg = EasyDict() - -# COMMON CONFIGS -# source domain -cfg.SOURCE = 'GTA' -# target domain -cfg.TARGET = 'Cityscapes' -# Number of workers for dataloading -cfg.NUM_WORKERS = 4 -# List of training images -cfg.DATA_LIST_SOURCE = str(project_root / 'advent/dataset/gta5_list/{}.txt') -cfg.DATA_LIST_TARGET = str(project_root / 'advent/dataset/cityscapes_list/{}.txt') -# Directories -cfg.DATA_DIRECTORY_SOURCE = str(project_root / 'data/GTA5') -cfg.DATA_DIRECTORY_TARGET = str(project_root / 'data/Cityscapes') -# Number of object classes -cfg.NUM_CLASSES = 19 -# Exp dirs -cfg.EXP_NAME = '' -cfg.EXP_ROOT = project_root / 'experiments' -cfg.EXP_ROOT_SNAPSHOT = osp.join(cfg.EXP_ROOT, 'snapshots') -cfg.EXP_ROOT_LOGS = osp.join(cfg.EXP_ROOT, 'logs') -# CUDA -cfg.GPU_ID = 0 - -# TRAIN CONFIGS -cfg.TRAIN = EasyDict() -cfg.TRAIN.SET_SOURCE = 'all' -cfg.TRAIN.SET_TARGET = 'train' -cfg.TRAIN.BATCH_SIZE_SOURCE = 1 -cfg.TRAIN.BATCH_SIZE_TARGET = 1 -cfg.TRAIN.IGNORE_LABEL = 255 -cfg.TRAIN.INPUT_SIZE_SOURCE = (1280, 720) -cfg.TRAIN.INPUT_SIZE_TARGET = (1024, 512) -# Class info -cfg.TRAIN.INFO_SOURCE = '' -cfg.TRAIN.INFO_TARGET = str(project_root / 'advent/dataset/cityscapes_list/info.json') -# Segmentation network params -cfg.TRAIN.MODEL = 'DeepLabv2' -cfg.TRAIN.MULTI_LEVEL = True -cfg.TRAIN.RESTORE_FROM = '' -cfg.TRAIN.IMG_MEAN = np.array((104.00698793, 116.66876762, 122.67891434), dtype=np.float32) -cfg.TRAIN.LEARNING_RATE = 2.5e-4 -cfg.TRAIN.MOMENTUM = 0.9 -cfg.TRAIN.WEIGHT_DECAY = 0.0005 -cfg.TRAIN.POWER = 0.9 -cfg.TRAIN.LAMBDA_SEG_MAIN = 1.0 -cfg.TRAIN.LAMBDA_SEG_AUX = 0.1 # weight of conv4 prediction. Used in multi-level setting. -# Domain adaptation -cfg.TRAIN.DA_METHOD = 'AdvEnt' -# Adversarial training params -cfg.TRAIN.LEARNING_RATE_D = 1e-4 -cfg.TRAIN.LAMBDA_ADV_MAIN = 0.001 -cfg.TRAIN.LAMBDA_ADV_AUX = 0.0002 -# MinEnt params -cfg.TRAIN.LAMBDA_ENT_MAIN = 0.001 -cfg.TRAIN.LAMBDA_ENT_AUX = 0.0002 -# Other params -cfg.TRAIN.MAX_ITERS = 250000 -cfg.TRAIN.EARLY_STOP = 120000 -cfg.TRAIN.SAVE_PRED_EVERY = 2000 -cfg.TRAIN.SNAPSHOT_DIR = '' -cfg.TRAIN.RANDOM_SEED = 1234 -cfg.TRAIN.TENSORBOARD_LOGDIR = '' -cfg.TRAIN.TENSORBOARD_VIZRATE = 100 - -# TEST CONFIGS -cfg.TEST = EasyDict() -cfg.TEST.MODE = 'best' # {'single', 'best'} -# model -cfg.TEST.MODEL = ('DeepLabv2',) -cfg.TEST.MODEL_WEIGHT = (1.0,) -cfg.TEST.MULTI_LEVEL = (True,) -cfg.TEST.IMG_MEAN = np.array((104.00698793, 116.66876762, 122.67891434), dtype=np.float32) -cfg.TEST.RESTORE_FROM = ('',) -cfg.TEST.SNAPSHOT_DIR = ('',) # used in 'best' mode -cfg.TEST.SNAPSHOT_STEP = 2000 # used in 'best' mode -cfg.TEST.SNAPSHOT_MAXITER = 120000 # used in 'best' mode -# Test sets -cfg.TEST.SET_TARGET = 'val' -cfg.TEST.BATCH_SIZE_TARGET = 1 -cfg.TEST.INPUT_SIZE_TARGET = (1024, 512) -cfg.TEST.OUTPUT_SIZE_TARGET = (2048, 1024) -cfg.TEST.INFO_TARGET = str(project_root / 'advent/dataset/cityscapes_list/info.json') -cfg.TEST.WAIT_MODEL = True - - -def _merge_a_into_b(a, b): - """Merge config dictionary a into config dictionary b, clobbering the - options in b whenever they are also specified in a. - """ - if type(a) is not EasyDict: - return - - for k, v in a.items(): - # a must specify keys that are in b - # if not b.has_key(k): - if k not in b: - raise KeyError(f'{k} is not a valid config key') - - # the types must match, too - old_type = type(b[k]) - if old_type is not type(v): - if isinstance(b[k], np.ndarray): - v = np.array(v, dtype=b[k].dtype) - else: - raise ValueError(f'Type mismatch ({type(b[k])} vs. {type(v)}) ' - f'for config key: {k}') - - # recursively merge dicts - if type(v) is EasyDict: - try: - _merge_a_into_b(a[k], b[k]) - except Exception: - print(f'Error under config key: {k}') - raise - else: - b[k] = v - - -def cfg_from_file(filename): - """Load a config file and merge it into the default options. - """ - yaml_cfg = EasyDict(yaml_load(filename)) - _merge_a_into_b(yaml_cfg, cfg) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -------------------------------------------------------- +# Configurations for domain adaptation +# Copyright (c) 2019 valeo.ai +# +# Written by Tuan-Hung Vu +# Adapted from https://github.com/rbgirshick/py-faster-rcnn/blob/master/lib/fast_rcnn/config.py +# -------------------------------------------------------- + +import os.path as osp + +import numpy as np +from easydict import EasyDict + +from advent.utils import project_root +from advent.utils.serialization import yaml_load + + +cfg = EasyDict() + +# COMMON CONFIGS +# source domain +cfg.SOURCE = 'GTA' +# target domain +cfg.TARGET = 'Cityscapes' +# Number of workers for dataloading +cfg.NUM_WORKERS = 4 +# List of training images +cfg.DATA_LIST_SOURCE = str(project_root / 'advent/dataset/gta5_list/{}.txt') +cfg.DATA_LIST_TARGET = str(project_root / 'advent/dataset/cityscapes_list/{}.txt') +# Directories +cfg.DATA_DIRECTORY_SOURCE = str(project_root / 'data/GTA5') +cfg.DATA_DIRECTORY_TARGET = str(project_root / 'data/Cityscapes') +# Number of object classes +cfg.NUM_CLASSES = 19 +# Exp dirs +cfg.EXP_NAME = '' +cfg.EXP_ROOT = project_root / 'experiments' +cfg.EXP_ROOT_SNAPSHOT = osp.join(cfg.EXP_ROOT, 'snapshots') +cfg.EXP_ROOT_LOGS = osp.join(cfg.EXP_ROOT, 'logs') +# CUDA +cfg.GPU_ID = 0 + +# TRAIN CONFIGS +cfg.TRAIN = EasyDict() +cfg.TRAIN.SET_SOURCE = 'all' +cfg.TRAIN.SET_TARGET = 'train' +cfg.TRAIN.BATCH_SIZE_SOURCE = 1 +cfg.TRAIN.BATCH_SIZE_TARGET = 1 +cfg.TRAIN.IGNORE_LABEL = 255 +cfg.TRAIN.INPUT_SIZE_SOURCE = (1280, 720) +cfg.TRAIN.INPUT_SIZE_TARGET = (1024, 512) +# Class info +cfg.TRAIN.INFO_SOURCE = '' +cfg.TRAIN.INFO_TARGET = str(project_root / 'advent/dataset/cityscapes_list/info.json') +# Segmentation network params +cfg.TRAIN.MODEL = 'DeepLabv2' +cfg.TRAIN.MULTI_LEVEL = True +cfg.TRAIN.RESTORE_FROM = '' +cfg.TRAIN.IMG_MEAN = np.array((104.00698793, 116.66876762, 122.67891434), dtype=np.float32) +cfg.TRAIN.LEARNING_RATE = 2.5e-4 +cfg.TRAIN.MOMENTUM = 0.9 +cfg.TRAIN.WEIGHT_DECAY = 0.0005 +cfg.TRAIN.POWER = 0.9 +cfg.TRAIN.LAMBDA_SEG_MAIN = 1.0 +cfg.TRAIN.LAMBDA_SEG_AUX = 0.1 # weight of conv4 prediction. Used in multi-level setting. +# Domain adaptation +cfg.TRAIN.DA_METHOD = 'AdvEnt' +# Adversarial training params +cfg.TRAIN.LEARNING_RATE_D = 1e-4 +cfg.TRAIN.LAMBDA_ADV_MAIN = 0.001 +cfg.TRAIN.LAMBDA_ADV_AUX = 0.0002 +# MinEnt params +cfg.TRAIN.LAMBDA_ENT_MAIN = 0.001 +cfg.TRAIN.LAMBDA_ENT_AUX = 0.0002 +# Other params +cfg.TRAIN.MAX_ITERS = 250000 +cfg.TRAIN.EARLY_STOP = 120000 +cfg.TRAIN.SAVE_PRED_EVERY = 2000 +cfg.TRAIN.SNAPSHOT_DIR = '' +cfg.TRAIN.RANDOM_SEED = 1234 +cfg.TRAIN.TENSORBOARD_LOGDIR = '' +cfg.TRAIN.TENSORBOARD_VIZRATE = 100 + +# TEST CONFIGS +cfg.TEST = EasyDict() +cfg.TEST.MODE = 'best' # {'single', 'best'} +# model +cfg.TEST.MODEL = ('DeepLabv2',) +cfg.TEST.MODEL_WEIGHT = (1.0,) +cfg.TEST.MULTI_LEVEL = (True,) +cfg.TEST.IMG_MEAN = np.array((104.00698793, 116.66876762, 122.67891434), dtype=np.float32) +cfg.TEST.RESTORE_FROM = ('',) +cfg.TEST.SNAPSHOT_DIR = ('',) # used in 'best' mode +cfg.TEST.SNAPSHOT_STEP = 2000 # used in 'best' mode +cfg.TEST.SNAPSHOT_MAXITER = 120000 # used in 'best' mode +# Test sets +cfg.TEST.SET_TARGET = 'val' +cfg.TEST.BATCH_SIZE_TARGET = 1 +cfg.TEST.INPUT_SIZE_TARGET = (1024, 512) +cfg.TEST.OUTPUT_SIZE_TARGET = (2048, 1024) +cfg.TEST.INFO_TARGET = str(project_root / 'advent/dataset/cityscapes_list/info.json') +cfg.TEST.WAIT_MODEL = True + + +def _merge_a_into_b(a, b): + """Merge config dictionary a into config dictionary b, clobbering the + options in b whenever they are also specified in a. + """ + if type(a) is not EasyDict: + return + + for k, v in a.items(): + # a must specify keys that are in b + # if not b.has_key(k): + if k not in b: + raise KeyError(f'{k} is not a valid config key') + + # the types must match, too + old_type = type(b[k]) + if old_type is not type(v): + if isinstance(b[k], np.ndarray): + v = np.array(v, dtype=b[k].dtype) + else: + raise ValueError(f'Type mismatch ({type(b[k])} vs. {type(v)}) ' + f'for config key: {k}') + + # recursively merge dicts + if type(v) is EasyDict: + try: + _merge_a_into_b(a[k], b[k]) + except Exception: + print(f'Error under config key: {k}') + raise + else: + b[k] = v + + +def cfg_from_file(filename): + """Load a config file and merge it into the default options. + """ + yaml_cfg = EasyDict(yaml_load(filename)) + _merge_a_into_b(yaml_cfg, cfg) diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/eval_UDA.py b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/eval_UDA.py index caff904345384ab98e11f02ea9baabb25a3e73a7..11a700a2f8c94f40d7bc654fd9b46c048a3137e9 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/eval_UDA.py +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/eval_UDA.py @@ -1,157 +1,157 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -------------------------------------------------------- -# Domain adpatation evaluation -# Copyright (c) 2019 valeo.ai -# -# Written by Tuan-Hung Vu -# -------------------------------------------------------- - -import os.path as osp -import time - -import numpy as np -import torch -from torch import nn -from tqdm import tqdm - -from advent.utils.func import per_class_iu, fast_hist -from advent.utils.serialization import pickle_dump, pickle_load - - -def evaluate_domain_adaptation( models, test_loader, cfg, - fixed_test_size=True, - verbose=True): - device = cfg.GPU_ID - interp = None - if fixed_test_size: - interp = nn.Upsample(size=(cfg.TEST.OUTPUT_SIZE_TARGET[1], cfg.TEST.OUTPUT_SIZE_TARGET[0]), mode='bilinear', align_corners=True) - # eval - if cfg.TEST.MODE == 'single': - eval_single(cfg, models, - device, test_loader, interp, fixed_test_size, - verbose) - elif cfg.TEST.MODE == 'best': - eval_best(cfg, models, - device, test_loader, interp, fixed_test_size, - verbose) - else: - raise NotImplementedError(f"Not yet supported test mode {cfg.TEST.MODE}") - - -def eval_single(cfg, models, - device, test_loader, interp, - fixed_test_size, verbose): - assert len(cfg.TEST.RESTORE_FROM) == len(models), 'Number of models are not matched' - for checkpoint, model in zip(cfg.TEST.RESTORE_FROM, models): - load_checkpoint_for_evaluation(model, checkpoint, device) - # eval - hist = np.zeros((cfg.NUM_CLASSES, cfg.NUM_CLASSES)) - for index, batch in tqdm(enumerate(test_loader)): - image, label, _, name = batch - if not fixed_test_size: - interp = nn.Upsample(size=(label.shape[1], label.shape[2]), mode='bilinear', align_corners=True) - with torch.no_grad(): - output = None - for model, model_weight in zip(models, cfg.TEST.MODEL_WEIGHT): - pred_main = model(image.cuda(device))[1] - output_ = interp(pred_main).cpu().data[0].numpy() - if output is None: - output = model_weight * output_ - else: - output += model_weight * output_ - assert output is not None, 'Output is None' - output = output.transpose(1, 2, 0) - output = np.argmax(output, axis=2) - label = label.numpy()[0] - hist += fast_hist(label.flatten(), output.flatten(), cfg.NUM_CLASSES) - inters_over_union_classes = per_class_iu(hist) - print(f'mIoU = \t{round(np.nanmean(inters_over_union_classes) * 100, 2)}') - if verbose: - display_stats(cfg, test_loader.dataset.class_names, inters_over_union_classes) - - -def eval_best(cfg, models, - device, test_loader, interp, - fixed_test_size, verbose): - assert len(models) == 1, 'Not yet supported multi models in this mode' - assert osp.exists(cfg.TEST.SNAPSHOT_DIR[0]), 'SNAPSHOT_DIR is not found' - start_iter = cfg.TEST.SNAPSHOT_STEP - step = cfg.TEST.SNAPSHOT_STEP - max_iter = cfg.TEST.SNAPSHOT_MAXITER - cache_path = osp.join(cfg.TEST.SNAPSHOT_DIR[0], 'all_res.pkl') - if osp.exists(cache_path): - all_res = pickle_load(cache_path) - else: - all_res = {} - cur_best_miou = -1 - cur_best_model = '' - for i_iter in range(start_iter, max_iter + 1, step): - restore_from = osp.join(cfg.TEST.SNAPSHOT_DIR[0], f'model_{i_iter}.pth') - if not osp.exists(restore_from): - # continue - if cfg.TEST.WAIT_MODEL: - print('Waiting for model..!') - while not osp.exists(restore_from): - time.sleep(5) - print("Evaluating model", restore_from) - if i_iter not in all_res.keys(): - load_checkpoint_for_evaluation(models[0], restore_from, device) - # eval - hist = np.zeros((cfg.NUM_CLASSES, cfg.NUM_CLASSES)) - # for index, batch in enumerate(test_loader): - # image, _, _, name = batch - test_iter = iter(test_loader) - for index in tqdm(range(len(test_loader))): - image, label, _, name = next(test_iter) - if not fixed_test_size: - interp = nn.Upsample(size=(label.shape[1], label.shape[2]), mode='bilinear', align_corners=True) - with torch.no_grad(): - pred_main = models[0](image.cuda(device))[1] - output = interp(pred_main).cpu().data[0].numpy() - output = output.transpose(1, 2, 0) - output = np.argmax(output, axis=2) - label = label.numpy()[0] - hist += fast_hist(label.flatten(), output.flatten(), cfg.NUM_CLASSES) - if verbose and index > 0 and index % 100 == 0: - print('{:d} / {:d}: {:0.2f}'.format( - index, len(test_loader), 100 * np.nanmean(per_class_iu(hist)))) - inters_over_union_classes = per_class_iu(hist) - all_res[i_iter] = inters_over_union_classes - pickle_dump(all_res, cache_path) - else: - inters_over_union_classes = all_res[i_iter] - computed_miou = round(np.nanmean(inters_over_union_classes) * 100, 2) - if cur_best_miou < computed_miou: - cur_best_miou = computed_miou - cur_best_model = restore_from - print('\tCurrent mIoU:', computed_miou) - print('\tCurrent best model:', cur_best_model) - print('\tCurrent best mIoU:', cur_best_miou) - if verbose: - display_stats(cfg, test_loader.dataset.class_names, inters_over_union_classes) - - -def load_checkpoint_for_evaluation(model, checkpoint, device): - saved_state_dict = torch.load(checkpoint) - model.load_state_dict(saved_state_dict) - model.eval() - model.cuda(device) - - -def display_stats(cfg, name_classes, inters_over_union_classes): - for ind_class in range(cfg.NUM_CLASSES): - print(name_classes[ind_class] - + '\t' + str(round(inters_over_union_classes[ind_class] * 100, 2))) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -------------------------------------------------------- +# Domain adpatation evaluation +# Copyright (c) 2019 valeo.ai +# +# Written by Tuan-Hung Vu +# -------------------------------------------------------- + +import os.path as osp +import time + +import numpy as np +import torch +from torch import nn +from tqdm import tqdm + +from advent.utils.func import per_class_iu, fast_hist +from advent.utils.serialization import pickle_dump, pickle_load + + +def evaluate_domain_adaptation( models, test_loader, cfg, + fixed_test_size=True, + verbose=True): + device = cfg.GPU_ID + interp = None + if fixed_test_size: + interp = nn.Upsample(size=(cfg.TEST.OUTPUT_SIZE_TARGET[1], cfg.TEST.OUTPUT_SIZE_TARGET[0]), mode='bilinear', align_corners=True) + # eval + if cfg.TEST.MODE == 'single': + eval_single(cfg, models, + device, test_loader, interp, fixed_test_size, + verbose) + elif cfg.TEST.MODE == 'best': + eval_best(cfg, models, + device, test_loader, interp, fixed_test_size, + verbose) + else: + raise NotImplementedError(f"Not yet supported test mode {cfg.TEST.MODE}") + + +def eval_single(cfg, models, + device, test_loader, interp, + fixed_test_size, verbose): + assert len(cfg.TEST.RESTORE_FROM) == len(models), 'Number of models are not matched' + for checkpoint, model in zip(cfg.TEST.RESTORE_FROM, models): + load_checkpoint_for_evaluation(model, checkpoint, device) + # eval + hist = np.zeros((cfg.NUM_CLASSES, cfg.NUM_CLASSES)) + for index, batch in tqdm(enumerate(test_loader)): + image, label, _, name = batch + if not fixed_test_size: + interp = nn.Upsample(size=(label.shape[1], label.shape[2]), mode='bilinear', align_corners=True) + with torch.no_grad(): + output = None + for model, model_weight in zip(models, cfg.TEST.MODEL_WEIGHT): + pred_main = model(image.cuda(device))[1] + output_ = interp(pred_main).cpu().data[0].numpy() + if output is None: + output = model_weight * output_ + else: + output += model_weight * output_ + assert output is not None, 'Output is None' + output = output.transpose(1, 2, 0) + output = np.argmax(output, axis=2) + label = label.numpy()[0] + hist += fast_hist(label.flatten(), output.flatten(), cfg.NUM_CLASSES) + inters_over_union_classes = per_class_iu(hist) + print(f'mIoU = \t{round(np.nanmean(inters_over_union_classes) * 100, 2)}') + if verbose: + display_stats(cfg, test_loader.dataset.class_names, inters_over_union_classes) + + +def eval_best(cfg, models, + device, test_loader, interp, + fixed_test_size, verbose): + assert len(models) == 1, 'Not yet supported multi models in this mode' + assert osp.exists(cfg.TEST.SNAPSHOT_DIR[0]), 'SNAPSHOT_DIR is not found' + start_iter = cfg.TEST.SNAPSHOT_STEP + step = cfg.TEST.SNAPSHOT_STEP + max_iter = cfg.TEST.SNAPSHOT_MAXITER + cache_path = osp.join(cfg.TEST.SNAPSHOT_DIR[0], 'all_res.pkl') + if osp.exists(cache_path): + all_res = pickle_load(cache_path) + else: + all_res = {} + cur_best_miou = -1 + cur_best_model = '' + for i_iter in range(start_iter, max_iter + 1, step): + restore_from = osp.join(cfg.TEST.SNAPSHOT_DIR[0], f'model_{i_iter}.pth') + if not osp.exists(restore_from): + # continue + if cfg.TEST.WAIT_MODEL: + print('Waiting for model..!') + while not osp.exists(restore_from): + time.sleep(5) + print("Evaluating model", restore_from) + if i_iter not in all_res.keys(): + load_checkpoint_for_evaluation(models[0], restore_from, device) + # eval + hist = np.zeros((cfg.NUM_CLASSES, cfg.NUM_CLASSES)) + # for index, batch in enumerate(test_loader): + # image, _, _, name = batch + test_iter = iter(test_loader) + for index in tqdm(range(len(test_loader))): + image, label, _, name = next(test_iter) + if not fixed_test_size: + interp = nn.Upsample(size=(label.shape[1], label.shape[2]), mode='bilinear', align_corners=True) + with torch.no_grad(): + pred_main = models[0](image.cuda(device))[1] + output = interp(pred_main).cpu().data[0].numpy() + output = output.transpose(1, 2, 0) + output = np.argmax(output, axis=2) + label = label.numpy()[0] + hist += fast_hist(label.flatten(), output.flatten(), cfg.NUM_CLASSES) + if verbose and index > 0 and index % 100 == 0: + print('{:d} / {:d}: {:0.2f}'.format( + index, len(test_loader), 100 * np.nanmean(per_class_iu(hist)))) + inters_over_union_classes = per_class_iu(hist) + all_res[i_iter] = inters_over_union_classes + pickle_dump(all_res, cache_path) + else: + inters_over_union_classes = all_res[i_iter] + computed_miou = round(np.nanmean(inters_over_union_classes) * 100, 2) + if cur_best_miou < computed_miou: + cur_best_miou = computed_miou + cur_best_model = restore_from + print('\tCurrent mIoU:', computed_miou) + print('\tCurrent best model:', cur_best_model) + print('\tCurrent best mIoU:', cur_best_miou) + if verbose: + display_stats(cfg, test_loader.dataset.class_names, inters_over_union_classes) + + +def load_checkpoint_for_evaluation(model, checkpoint, device): + saved_state_dict = torch.load(checkpoint) + model.load_state_dict(saved_state_dict) + model.eval() + model.cuda(device) + + +def display_stats(cfg, name_classes, inters_over_union_classes): + for ind_class in range(cfg.NUM_CLASSES): + print(name_classes[ind_class] + + '\t' + str(round(inters_over_union_classes[ind_class] * 100, 2))) diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/train_UDA.py b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/train_UDA.py index e7266b67933cb6c778d932c0e53d9c021393aa90..899fc87bdcc0ddcb46feec1b74f5001d1edd9eb3 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/train_UDA.py +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/domain_adaptation/train_UDA.py @@ -1,356 +1,356 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -------------------------------------------------------- -# Domain adpatation training -# Copyright (c) 2019 valeo.ai -# -# Written by Tuan-Hung Vu -# -------------------------------------------------------- -import os -import sys -from pathlib import Path - -import os.path as osp -import numpy as np -import torch -import torch.backends.cudnn as cudnn -import torch.nn.functional as F -import torch.optim as optim -from tensorboardX import SummaryWriter -from torch import nn -from torchvision.utils import make_grid -from tqdm import tqdm - -from advent.model.discriminator import get_fc_discriminator -from advent.utils.func import adjust_learning_rate, adjust_learning_rate_discriminator -from advent.utils.func import loss_calc, bce_loss -from advent.utils.loss import entropy_loss -from advent.utils.func import prob_2_entropy -from advent.utils.viz_segmask import colorize_mask - - -def train_advent(model, trainloader, targetloader, cfg): - ''' UDA training with advent - ''' - # Create the model and start the training. - input_size_source = cfg.TRAIN.INPUT_SIZE_SOURCE - input_size_target = cfg.TRAIN.INPUT_SIZE_TARGET - device = cfg.GPU_ID - num_classes = cfg.NUM_CLASSES - viz_tensorboard = os.path.exists(cfg.TRAIN.TENSORBOARD_LOGDIR) - if viz_tensorboard: - writer = SummaryWriter(log_dir=cfg.TRAIN.TENSORBOARD_LOGDIR) - - # SEGMNETATION NETWORK - model.train() - model.to(device) - cudnn.benchmark = True - cudnn.enabled = True - - # DISCRIMINATOR NETWORK - # feature-level - d_aux = get_fc_discriminator(num_classes=num_classes) - d_aux.train() - d_aux.to(device) - - # seg maps, i.e. output, level - d_main = get_fc_discriminator(num_classes=num_classes) - d_main.train() - d_main.to(device) - - # OPTIMIZERS - # segnet's optimizer - optimizer = optim.SGD(model.optim_parameters(cfg.TRAIN.LEARNING_RATE), - lr=cfg.TRAIN.LEARNING_RATE, - momentum=cfg.TRAIN.MOMENTUM, - weight_decay=cfg.TRAIN.WEIGHT_DECAY) - - # discriminators' optimizers - optimizer_d_aux = optim.Adam(d_aux.parameters(), lr=cfg.TRAIN.LEARNING_RATE_D, - betas=(0.9, 0.99)) - optimizer_d_main = optim.Adam(d_main.parameters(), lr=cfg.TRAIN.LEARNING_RATE_D, - betas=(0.9, 0.99)) - - # interpolate output segmaps - interp = nn.Upsample(size=(input_size_source[1], input_size_source[0]), mode='bilinear', - align_corners=True) - interp_target = nn.Upsample(size=(input_size_target[1], input_size_target[0]), mode='bilinear', - align_corners=True) - - # labels for adversarial training - source_label = 0 - target_label = 1 - trainloader_iter = enumerate(trainloader) - targetloader_iter = enumerate(targetloader) - for i_iter in tqdm(range(cfg.TRAIN.EARLY_STOP + 1)): - - # reset optimizers - optimizer.zero_grad() - optimizer_d_aux.zero_grad() - optimizer_d_main.zero_grad() - # adapt LR if needed - adjust_learning_rate(optimizer, i_iter, cfg) - adjust_learning_rate_discriminator(optimizer_d_aux, i_iter, cfg) - adjust_learning_rate_discriminator(optimizer_d_main, i_iter, cfg) - - # UDA Training - # only train segnet. Don't accumulate grads in disciminators - for param in d_aux.parameters(): - param.requires_grad = False - for param in d_main.parameters(): - param.requires_grad = False - # train on source - _, batch = trainloader_iter.__next__() - images_source, labels, _, _ = batch - pred_src_aux, pred_src_main = model(images_source.cuda(device)) - if cfg.TRAIN.MULTI_LEVEL: - pred_src_aux = interp(pred_src_aux) - loss_seg_src_aux = loss_calc(pred_src_aux, labels, device) - else: - loss_seg_src_aux = 0 - pred_src_main = interp(pred_src_main) - loss_seg_src_main = loss_calc(pred_src_main, labels, device) - loss = (cfg.TRAIN.LAMBDA_SEG_MAIN * loss_seg_src_main - + cfg.TRAIN.LAMBDA_SEG_AUX * loss_seg_src_aux) - loss.backward() - - # adversarial training ot fool the discriminator - _, batch = targetloader_iter.__next__() - images, _, _, _ = batch - pred_trg_aux, pred_trg_main = model(images.cuda(device)) - if cfg.TRAIN.MULTI_LEVEL: - pred_trg_aux = interp_target(pred_trg_aux) - d_out_aux = d_aux(prob_2_entropy(F.softmax(pred_trg_aux))) - loss_adv_trg_aux = bce_loss(d_out_aux, source_label) - else: - loss_adv_trg_aux = 0 - pred_trg_main = interp_target(pred_trg_main) - d_out_main = d_main(prob_2_entropy(F.softmax(pred_trg_main))) - loss_adv_trg_main = bce_loss(d_out_main, source_label) - loss = (cfg.TRAIN.LAMBDA_ADV_MAIN * loss_adv_trg_main - + cfg.TRAIN.LAMBDA_ADV_AUX * loss_adv_trg_aux) - loss = loss - loss.backward() - - # Train discriminator networks - # enable training mode on discriminator networks - for param in d_aux.parameters(): - param.requires_grad = True - for param in d_main.parameters(): - param.requires_grad = True - # train with source - if cfg.TRAIN.MULTI_LEVEL: - pred_src_aux = pred_src_aux.detach() - d_out_aux = d_aux(prob_2_entropy(F.softmax(pred_src_aux))) - loss_d_aux = bce_loss(d_out_aux, source_label) - loss_d_aux = loss_d_aux / 2 - loss_d_aux.backward() - pred_src_main = pred_src_main.detach() - d_out_main = d_main(prob_2_entropy(F.softmax(pred_src_main))) - loss_d_main = bce_loss(d_out_main, source_label) - loss_d_main = loss_d_main / 2 - loss_d_main.backward() - - # train with target - if cfg.TRAIN.MULTI_LEVEL: - pred_trg_aux = pred_trg_aux.detach() - d_out_aux = d_aux(prob_2_entropy(F.softmax(pred_trg_aux))) - loss_d_aux = bce_loss(d_out_aux, target_label) - loss_d_aux = loss_d_aux / 2 - loss_d_aux.backward() - else: - loss_d_aux = 0 - pred_trg_main = pred_trg_main.detach() - d_out_main = d_main(prob_2_entropy(F.softmax(pred_trg_main))) - loss_d_main = bce_loss(d_out_main, target_label) - loss_d_main = loss_d_main / 2 - loss_d_main.backward() - - optimizer.step() - if cfg.TRAIN.MULTI_LEVEL: - optimizer_d_aux.step() - optimizer_d_main.step() - - current_losses = {'loss_seg_src_aux': loss_seg_src_aux, - 'loss_seg_src_main': loss_seg_src_main, - 'loss_adv_trg_aux': loss_adv_trg_aux, - 'loss_adv_trg_main': loss_adv_trg_main, - 'loss_d_aux': loss_d_aux, - 'loss_d_main': loss_d_main} - print_losses(current_losses, i_iter) - - if i_iter % cfg.TRAIN.SAVE_PRED_EVERY == 0 and i_iter != 0: - print('taking snapshot ...') - print('exp =', cfg.TRAIN.SNAPSHOT_DIR) - snapshot_dir = Path(cfg.TRAIN.SNAPSHOT_DIR) - torch.save(model.state_dict(), snapshot_dir / f'model_{i_iter}.pth') - torch.save(d_aux.state_dict(), snapshot_dir / f'model_{i_iter}_D_aux.pth') - torch.save(d_main.state_dict(), snapshot_dir / f'model_{i_iter}_D_main.pth') - if i_iter >= cfg.TRAIN.EARLY_STOP - 1: - break - sys.stdout.flush() - - # Visualize with tensorboard - if viz_tensorboard: - log_losses_tensorboard(writer, current_losses, i_iter) - - if i_iter % cfg.TRAIN.TENSORBOARD_VIZRATE == cfg.TRAIN.TENSORBOARD_VIZRATE - 1: - draw_in_tensorboard(writer, images, i_iter, pred_trg_main, num_classes, 'T') - draw_in_tensorboard(writer, images_source, i_iter, pred_src_main, num_classes, 'S') - - -def draw_in_tensorboard(writer, images, i_iter, pred_main, num_classes, type_): - grid_image = make_grid(images[:3].clone().cpu().data, 3, normalize=True) - writer.add_image(f'Image - {type_}', grid_image, i_iter) - - grid_image = make_grid(torch.from_numpy(np.array(colorize_mask(np.asarray( - np.argmax(F.softmax(pred_main).cpu().data[0].numpy().transpose(1, 2, 0), - axis=2), dtype=np.uint8)).convert('RGB')).transpose(2, 0, 1)), 3, - normalize=False, range=(0, 255)) - writer.add_image(f'Prediction - {type_}', grid_image, i_iter) - - output_sm = F.softmax(pred_main).cpu().data[0].numpy().transpose(1, 2, 0) - output_ent = np.sum(-np.multiply(output_sm, np.log2(output_sm)), axis=2, - keepdims=False) - grid_image = make_grid(torch.from_numpy(output_ent), 3, normalize=True, - range=(0, np.log2(num_classes))) - writer.add_image(f'Entropy - {type_}', grid_image, i_iter) - - -def train_minent(model, trainloader, targetloader, cfg): - ''' UDA training with minEnt - ''' - # Create the model and start the training. - input_size_source = cfg.TRAIN.INPUT_SIZE_SOURCE - input_size_target = cfg.TRAIN.INPUT_SIZE_TARGET - device = cfg.GPU_ID - num_classes = cfg.NUM_CLASSES - viz_tensorboard = os.path.exists(cfg.TRAIN.TENSORBOARD_LOGDIR) - if viz_tensorboard: - writer = SummaryWriter(log_dir=cfg.TRAIN.TENSORBOARD_LOGDIR) - - # SEGMNETATION NETWORK - model.train() - model.to(device) - cudnn.benchmark = True - cudnn.enabled = True - - # OPTIMIZERS - # segnet's optimizer - optimizer = optim.SGD(model.optim_parameters(cfg.TRAIN.LEARNING_RATE), - lr=cfg.TRAIN.LEARNING_RATE, - momentum=cfg.TRAIN.MOMENTUM, - weight_decay=cfg.TRAIN.WEIGHT_DECAY) - - # interpolate output segmaps - interp = nn.Upsample(size=(input_size_source[1], input_size_source[0]), mode='bilinear', - align_corners=True) - interp_target = nn.Upsample(size=(input_size_target[1], input_size_target[0]), mode='bilinear', - align_corners=True) - - trainloader_iter = enumerate(trainloader) - targetloader_iter = enumerate(targetloader) - for i_iter in tqdm(range(cfg.TRAIN.EARLY_STOP)): - - # reset optimizers - optimizer.zero_grad() - - # adapt LR if needed - adjust_learning_rate(optimizer, i_iter, cfg) - - # UDA Training - # train on source - _, batch = trainloader_iter.__next__() - images_source, labels, _, _ = batch - pred_src_aux, pred_src_main = model(images_source.cuda(device)) - if cfg.TRAIN.MULTI_LEVEL: - pred_src_aux = interp(pred_src_aux) - loss_seg_src_aux = loss_calc(pred_src_aux, labels, device) - else: - loss_seg_src_aux = 0 - pred_src_main = interp(pred_src_main) - loss_seg_src_main = loss_calc(pred_src_main, labels, device) - loss = (cfg.TRAIN.LAMBDA_SEG_MAIN * loss_seg_src_main - + cfg.TRAIN.LAMBDA_SEG_AUX * loss_seg_src_aux) - loss.backward() - - # adversarial training with minent - _, batch = targetloader_iter.__next__() - images, _, _, _ = batch - pred_trg_aux, pred_trg_main = model(images.cuda(device)) - pred_trg_aux = interp_target(pred_trg_aux) - pred_trg_main = interp_target(pred_trg_main) - pred_prob_trg_aux = F.softmax(pred_trg_aux) - pred_prob_trg_main = F.softmax(pred_trg_main) - - loss_target_entp_aux = entropy_loss(pred_prob_trg_aux) - loss_target_entp_main = entropy_loss(pred_prob_trg_main) - loss = (cfg.TRAIN.LAMBDA_ENT_AUX * loss_target_entp_aux - + cfg.TRAIN.LAMBDA_ENT_MAIN * loss_target_entp_main) - loss.backward() - optimizer.step() - - current_losses = {'loss_seg_src_aux': loss_seg_src_aux, - 'loss_seg_src_main': loss_seg_src_main, - 'loss_ent_aux': loss_target_entp_aux, - 'loss_ent_main': loss_target_entp_main} - - print_losses(current_losses, i_iter) - - if i_iter % cfg.TRAIN.SAVE_PRED_EVERY == 0 and i_iter != 0: - print('taking snapshot ...') - print('exp =', cfg.TRAIN.SNAPSHOT_DIR) - torch.save(model.state_dict(), - osp.join(cfg.TRAIN.SNAPSHOT_DIR, f'model_{i_iter}.pth')) - if i_iter >= cfg.TRAIN.EARLY_STOP - 1: - break - sys.stdout.flush() - - # Visualize with tensorboard - if viz_tensorboard: - log_losses_tensorboard(writer, current_losses, i_iter) - - if i_iter % cfg.TRAIN.TENSORBOARD_VIZRATE == cfg.TRAIN.TENSORBOARD_VIZRATE - 1: - draw_in_tensorboard(writer, images, i_iter, pred_trg_main, num_classes, 'T') - draw_in_tensorboard(writer, images_source, i_iter, pred_src_main, num_classes, 'S') - - -def print_losses(current_losses, i_iter): - list_strings = [] - for loss_name, loss_value in current_losses.items(): - list_strings.append(f'{loss_name} = {to_numpy(loss_value):.3f} ') - full_string = ' '.join(list_strings) - tqdm.write(f'iter = {i_iter} {full_string}') - - -def log_losses_tensorboard(writer, current_losses, i_iter): - for loss_name, loss_value in current_losses.items(): - writer.add_scalar(f'data/{loss_name}', to_numpy(loss_value), i_iter) - - -def to_numpy(tensor): - if isinstance(tensor, (int, float)): - return tensor - else: - return tensor.data.cpu().numpy() - - -def train_domain_adaptation(model, trainloader, targetloader, cfg): - if cfg.TRAIN.DA_METHOD == 'MinEnt': - train_minent(model, trainloader, targetloader, cfg) - elif cfg.TRAIN.DA_METHOD == 'AdvEnt': - train_advent(model, trainloader, targetloader, cfg) - else: - raise NotImplementedError(f"Not yet supported DA method {cfg.TRAIN.DA_METHOD}") +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -------------------------------------------------------- +# Domain adpatation training +# Copyright (c) 2019 valeo.ai +# +# Written by Tuan-Hung Vu +# -------------------------------------------------------- +import os +import sys +from pathlib import Path + +import os.path as osp +import numpy as np +import torch +import torch.backends.cudnn as cudnn +import torch.nn.functional as F +import torch.optim as optim +from tensorboardX import SummaryWriter +from torch import nn +from torchvision.utils import make_grid +from tqdm import tqdm + +from advent.model.discriminator import get_fc_discriminator +from advent.utils.func import adjust_learning_rate, adjust_learning_rate_discriminator +from advent.utils.func import loss_calc, bce_loss +from advent.utils.loss import entropy_loss +from advent.utils.func import prob_2_entropy +from advent.utils.viz_segmask import colorize_mask + + +def train_advent(model, trainloader, targetloader, cfg): + ''' UDA training with advent + ''' + # Create the model and start the training. + input_size_source = cfg.TRAIN.INPUT_SIZE_SOURCE + input_size_target = cfg.TRAIN.INPUT_SIZE_TARGET + device = cfg.GPU_ID + num_classes = cfg.NUM_CLASSES + viz_tensorboard = os.path.exists(cfg.TRAIN.TENSORBOARD_LOGDIR) + if viz_tensorboard: + writer = SummaryWriter(log_dir=cfg.TRAIN.TENSORBOARD_LOGDIR) + + # SEGMNETATION NETWORK + model.train() + model.to(device) + cudnn.benchmark = True + cudnn.enabled = True + + # DISCRIMINATOR NETWORK + # feature-level + d_aux = get_fc_discriminator(num_classes=num_classes) + d_aux.train() + d_aux.to(device) + + # seg maps, i.e. output, level + d_main = get_fc_discriminator(num_classes=num_classes) + d_main.train() + d_main.to(device) + + # OPTIMIZERS + # segnet's optimizer + optimizer = optim.SGD(model.optim_parameters(cfg.TRAIN.LEARNING_RATE), + lr=cfg.TRAIN.LEARNING_RATE, + momentum=cfg.TRAIN.MOMENTUM, + weight_decay=cfg.TRAIN.WEIGHT_DECAY) + + # discriminators' optimizers + optimizer_d_aux = optim.Adam(d_aux.parameters(), lr=cfg.TRAIN.LEARNING_RATE_D, + betas=(0.9, 0.99)) + optimizer_d_main = optim.Adam(d_main.parameters(), lr=cfg.TRAIN.LEARNING_RATE_D, + betas=(0.9, 0.99)) + + # interpolate output segmaps + interp = nn.Upsample(size=(input_size_source[1], input_size_source[0]), mode='bilinear', + align_corners=True) + interp_target = nn.Upsample(size=(input_size_target[1], input_size_target[0]), mode='bilinear', + align_corners=True) + + # labels for adversarial training + source_label = 0 + target_label = 1 + trainloader_iter = enumerate(trainloader) + targetloader_iter = enumerate(targetloader) + for i_iter in tqdm(range(cfg.TRAIN.EARLY_STOP + 1)): + + # reset optimizers + optimizer.zero_grad() + optimizer_d_aux.zero_grad() + optimizer_d_main.zero_grad() + # adapt LR if needed + adjust_learning_rate(optimizer, i_iter, cfg) + adjust_learning_rate_discriminator(optimizer_d_aux, i_iter, cfg) + adjust_learning_rate_discriminator(optimizer_d_main, i_iter, cfg) + + # UDA Training + # only train segnet. Don't accumulate grads in disciminators + for param in d_aux.parameters(): + param.requires_grad = False + for param in d_main.parameters(): + param.requires_grad = False + # train on source + _, batch = trainloader_iter.__next__() + images_source, labels, _, _ = batch + pred_src_aux, pred_src_main = model(images_source.cuda(device)) + if cfg.TRAIN.MULTI_LEVEL: + pred_src_aux = interp(pred_src_aux) + loss_seg_src_aux = loss_calc(pred_src_aux, labels, device) + else: + loss_seg_src_aux = 0 + pred_src_main = interp(pred_src_main) + loss_seg_src_main = loss_calc(pred_src_main, labels, device) + loss = (cfg.TRAIN.LAMBDA_SEG_MAIN * loss_seg_src_main + + cfg.TRAIN.LAMBDA_SEG_AUX * loss_seg_src_aux) + loss.backward() + + # adversarial training ot fool the discriminator + _, batch = targetloader_iter.__next__() + images, _, _, _ = batch + pred_trg_aux, pred_trg_main = model(images.cuda(device)) + if cfg.TRAIN.MULTI_LEVEL: + pred_trg_aux = interp_target(pred_trg_aux) + d_out_aux = d_aux(prob_2_entropy(F.softmax(pred_trg_aux))) + loss_adv_trg_aux = bce_loss(d_out_aux, source_label) + else: + loss_adv_trg_aux = 0 + pred_trg_main = interp_target(pred_trg_main) + d_out_main = d_main(prob_2_entropy(F.softmax(pred_trg_main))) + loss_adv_trg_main = bce_loss(d_out_main, source_label) + loss = (cfg.TRAIN.LAMBDA_ADV_MAIN * loss_adv_trg_main + + cfg.TRAIN.LAMBDA_ADV_AUX * loss_adv_trg_aux) + loss = loss + loss.backward() + + # Train discriminator networks + # enable training mode on discriminator networks + for param in d_aux.parameters(): + param.requires_grad = True + for param in d_main.parameters(): + param.requires_grad = True + # train with source + if cfg.TRAIN.MULTI_LEVEL: + pred_src_aux = pred_src_aux.detach() + d_out_aux = d_aux(prob_2_entropy(F.softmax(pred_src_aux))) + loss_d_aux = bce_loss(d_out_aux, source_label) + loss_d_aux = loss_d_aux / 2 + loss_d_aux.backward() + pred_src_main = pred_src_main.detach() + d_out_main = d_main(prob_2_entropy(F.softmax(pred_src_main))) + loss_d_main = bce_loss(d_out_main, source_label) + loss_d_main = loss_d_main / 2 + loss_d_main.backward() + + # train with target + if cfg.TRAIN.MULTI_LEVEL: + pred_trg_aux = pred_trg_aux.detach() + d_out_aux = d_aux(prob_2_entropy(F.softmax(pred_trg_aux))) + loss_d_aux = bce_loss(d_out_aux, target_label) + loss_d_aux = loss_d_aux / 2 + loss_d_aux.backward() + else: + loss_d_aux = 0 + pred_trg_main = pred_trg_main.detach() + d_out_main = d_main(prob_2_entropy(F.softmax(pred_trg_main))) + loss_d_main = bce_loss(d_out_main, target_label) + loss_d_main = loss_d_main / 2 + loss_d_main.backward() + + optimizer.step() + if cfg.TRAIN.MULTI_LEVEL: + optimizer_d_aux.step() + optimizer_d_main.step() + + current_losses = {'loss_seg_src_aux': loss_seg_src_aux, + 'loss_seg_src_main': loss_seg_src_main, + 'loss_adv_trg_aux': loss_adv_trg_aux, + 'loss_adv_trg_main': loss_adv_trg_main, + 'loss_d_aux': loss_d_aux, + 'loss_d_main': loss_d_main} + print_losses(current_losses, i_iter) + + if i_iter % cfg.TRAIN.SAVE_PRED_EVERY == 0 and i_iter != 0: + print('taking snapshot ...') + print('exp =', cfg.TRAIN.SNAPSHOT_DIR) + snapshot_dir = Path(cfg.TRAIN.SNAPSHOT_DIR) + torch.save(model.state_dict(), snapshot_dir / f'model_{i_iter}.pth') + torch.save(d_aux.state_dict(), snapshot_dir / f'model_{i_iter}_D_aux.pth') + torch.save(d_main.state_dict(), snapshot_dir / f'model_{i_iter}_D_main.pth') + if i_iter >= cfg.TRAIN.EARLY_STOP - 1: + break + sys.stdout.flush() + + # Visualize with tensorboard + if viz_tensorboard: + log_losses_tensorboard(writer, current_losses, i_iter) + + if i_iter % cfg.TRAIN.TENSORBOARD_VIZRATE == cfg.TRAIN.TENSORBOARD_VIZRATE - 1: + draw_in_tensorboard(writer, images, i_iter, pred_trg_main, num_classes, 'T') + draw_in_tensorboard(writer, images_source, i_iter, pred_src_main, num_classes, 'S') + + +def draw_in_tensorboard(writer, images, i_iter, pred_main, num_classes, type_): + grid_image = make_grid(images[:3].clone().cpu().data, 3, normalize=True) + writer.add_image(f'Image - {type_}', grid_image, i_iter) + + grid_image = make_grid(torch.from_numpy(np.array(colorize_mask(np.asarray( + np.argmax(F.softmax(pred_main).cpu().data[0].numpy().transpose(1, 2, 0), + axis=2), dtype=np.uint8)).convert('RGB')).transpose(2, 0, 1)), 3, + normalize=False, range=(0, 255)) + writer.add_image(f'Prediction - {type_}', grid_image, i_iter) + + output_sm = F.softmax(pred_main).cpu().data[0].numpy().transpose(1, 2, 0) + output_ent = np.sum(-np.multiply(output_sm, np.log2(output_sm)), axis=2, + keepdims=False) + grid_image = make_grid(torch.from_numpy(output_ent), 3, normalize=True, + range=(0, np.log2(num_classes))) + writer.add_image(f'Entropy - {type_}', grid_image, i_iter) + + +def train_minent(model, trainloader, targetloader, cfg): + ''' UDA training with minEnt + ''' + # Create the model and start the training. + input_size_source = cfg.TRAIN.INPUT_SIZE_SOURCE + input_size_target = cfg.TRAIN.INPUT_SIZE_TARGET + device = cfg.GPU_ID + num_classes = cfg.NUM_CLASSES + viz_tensorboard = os.path.exists(cfg.TRAIN.TENSORBOARD_LOGDIR) + if viz_tensorboard: + writer = SummaryWriter(log_dir=cfg.TRAIN.TENSORBOARD_LOGDIR) + + # SEGMNETATION NETWORK + model.train() + model.to(device) + cudnn.benchmark = True + cudnn.enabled = True + + # OPTIMIZERS + # segnet's optimizer + optimizer = optim.SGD(model.optim_parameters(cfg.TRAIN.LEARNING_RATE), + lr=cfg.TRAIN.LEARNING_RATE, + momentum=cfg.TRAIN.MOMENTUM, + weight_decay=cfg.TRAIN.WEIGHT_DECAY) + + # interpolate output segmaps + interp = nn.Upsample(size=(input_size_source[1], input_size_source[0]), mode='bilinear', + align_corners=True) + interp_target = nn.Upsample(size=(input_size_target[1], input_size_target[0]), mode='bilinear', + align_corners=True) + + trainloader_iter = enumerate(trainloader) + targetloader_iter = enumerate(targetloader) + for i_iter in tqdm(range(cfg.TRAIN.EARLY_STOP)): + + # reset optimizers + optimizer.zero_grad() + + # adapt LR if needed + adjust_learning_rate(optimizer, i_iter, cfg) + + # UDA Training + # train on source + _, batch = trainloader_iter.__next__() + images_source, labels, _, _ = batch + pred_src_aux, pred_src_main = model(images_source.cuda(device)) + if cfg.TRAIN.MULTI_LEVEL: + pred_src_aux = interp(pred_src_aux) + loss_seg_src_aux = loss_calc(pred_src_aux, labels, device) + else: + loss_seg_src_aux = 0 + pred_src_main = interp(pred_src_main) + loss_seg_src_main = loss_calc(pred_src_main, labels, device) + loss = (cfg.TRAIN.LAMBDA_SEG_MAIN * loss_seg_src_main + + cfg.TRAIN.LAMBDA_SEG_AUX * loss_seg_src_aux) + loss.backward() + + # adversarial training with minent + _, batch = targetloader_iter.__next__() + images, _, _, _ = batch + pred_trg_aux, pred_trg_main = model(images.cuda(device)) + pred_trg_aux = interp_target(pred_trg_aux) + pred_trg_main = interp_target(pred_trg_main) + pred_prob_trg_aux = F.softmax(pred_trg_aux) + pred_prob_trg_main = F.softmax(pred_trg_main) + + loss_target_entp_aux = entropy_loss(pred_prob_trg_aux) + loss_target_entp_main = entropy_loss(pred_prob_trg_main) + loss = (cfg.TRAIN.LAMBDA_ENT_AUX * loss_target_entp_aux + + cfg.TRAIN.LAMBDA_ENT_MAIN * loss_target_entp_main) + loss.backward() + optimizer.step() + + current_losses = {'loss_seg_src_aux': loss_seg_src_aux, + 'loss_seg_src_main': loss_seg_src_main, + 'loss_ent_aux': loss_target_entp_aux, + 'loss_ent_main': loss_target_entp_main} + + print_losses(current_losses, i_iter) + + if i_iter % cfg.TRAIN.SAVE_PRED_EVERY == 0 and i_iter != 0: + print('taking snapshot ...') + print('exp =', cfg.TRAIN.SNAPSHOT_DIR) + torch.save(model.state_dict(), + osp.join(cfg.TRAIN.SNAPSHOT_DIR, f'model_{i_iter}.pth')) + if i_iter >= cfg.TRAIN.EARLY_STOP - 1: + break + sys.stdout.flush() + + # Visualize with tensorboard + if viz_tensorboard: + log_losses_tensorboard(writer, current_losses, i_iter) + + if i_iter % cfg.TRAIN.TENSORBOARD_VIZRATE == cfg.TRAIN.TENSORBOARD_VIZRATE - 1: + draw_in_tensorboard(writer, images, i_iter, pred_trg_main, num_classes, 'T') + draw_in_tensorboard(writer, images_source, i_iter, pred_src_main, num_classes, 'S') + + +def print_losses(current_losses, i_iter): + list_strings = [] + for loss_name, loss_value in current_losses.items(): + list_strings.append(f'{loss_name} = {to_numpy(loss_value):.3f} ') + full_string = ' '.join(list_strings) + tqdm.write(f'iter = {i_iter} {full_string}') + + +def log_losses_tensorboard(writer, current_losses, i_iter): + for loss_name, loss_value in current_losses.items(): + writer.add_scalar(f'data/{loss_name}', to_numpy(loss_value), i_iter) + + +def to_numpy(tensor): + if isinstance(tensor, (int, float)): + return tensor + else: + return tensor.data.cpu().numpy() + + +def train_domain_adaptation(model, trainloader, targetloader, cfg): + if cfg.TRAIN.DA_METHOD == 'MinEnt': + train_minent(model, trainloader, targetloader, cfg) + elif cfg.TRAIN.DA_METHOD == 'AdvEnt': + train_advent(model, trainloader, targetloader, cfg) + else: + raise NotImplementedError(f"Not yet supported DA method {cfg.TRAIN.DA_METHOD}") diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/model/__init__.py b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/model/__init__.py index 55887fca321859e7fe8df0054b4761e83a7b4210..945cb920d49428f81bc1c2597ffa7a2a61e8ef81 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/model/__init__.py +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/model/__init__.py @@ -1,13 +1,13 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/advent+minent_pretrained.yml b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/advent+minent_pretrained.yml index 7e274313c576a26dc1bab94889b2134713162ddf..a423a0b559a7cd13b2d126e2bc5aebe4cccdddf6 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/advent+minent_pretrained.yml +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/advent+minent_pretrained.yml @@ -1,18 +1,18 @@ -SOURCE: GTA -TARGET: Cityscapes -EXP_NAME: GTA2Cityscapes_AdvEnt_MinEnt -NUM_WORKERS: 4 -TEST: - MODE: single - MODEL: - - DeepLabv2 - - DeepLabv2 - MULTI_LEVEL: - - True - - True - RESTORE_FROM: - - ../../pretrained_models/gta2cityscapes_advent.pth - - ../../pretrained_models/gta2cityscapes_minent_ER.pth - MODEL_WEIGHT: - - 0.5 +SOURCE: GTA +TARGET: Cityscapes +EXP_NAME: GTA2Cityscapes_AdvEnt_MinEnt +NUM_WORKERS: 4 +TEST: + MODE: single + MODEL: + - DeepLabv2 + - DeepLabv2 + MULTI_LEVEL: + - True + - True + RESTORE_FROM: + - ../../pretrained_models/gta2cityscapes_advent.pth + - ../../pretrained_models/gta2cityscapes_minent_ER.pth + MODEL_WEIGHT: + - 0.5 - 0.5 \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/advent_cyclegan_pretrained.yml b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/advent_cyclegan_pretrained.yml index 881a9defef166e82c2560b6a3d78c66db23153be..3840244b80109421bb2519e94d78615cbbe48c66 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/advent_cyclegan_pretrained.yml +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/advent_cyclegan_pretrained.yml @@ -1,8 +1,8 @@ -SOURCE: GTA -TARGET: Cityscapes -EXP_NAME: GTA2Cityscapes_AdvEnt_CycleGAN -NUM_WORKERS: 4 -TEST: - MODE: single - RESTORE_FROM: +SOURCE: GTA +TARGET: Cityscapes +EXP_NAME: GTA2Cityscapes_AdvEnt_CycleGAN +NUM_WORKERS: 4 +TEST: + MODE: single + RESTORE_FROM: - ../../pretrained_models/gta2cityscapes_advent_cyclegan.pth \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/advent_pretrained.yml b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/advent_pretrained.yml index 85a2f7ac4d8a216b820d5dcb0a42ee7cb1fd2041..2e35e98857835f39081fa1c63fa70630f75c9796 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/advent_pretrained.yml +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/advent_pretrained.yml @@ -1,8 +1,8 @@ -SOURCE: GTA -TARGET: Cityscapes -EXP_NAME: GTA2Cityscapes_AdvEnt -NUM_WORKERS: 4 -TEST: - MODE: single - RESTORE_FROM: +SOURCE: GTA +TARGET: Cityscapes +EXP_NAME: GTA2Cityscapes_AdvEnt +NUM_WORKERS: 4 +TEST: + MODE: single + RESTORE_FROM: - ../../pretrained_models/gta2cityscapes_advent.pth \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/minent.yml b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/minent.yml index 3ddef6dc8fcfa1044ff5fc2d676c48482cb7c12c..6c85e845459d45ac98e1a19fd55a32176e95d300 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/minent.yml +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/minent.yml @@ -1,12 +1,12 @@ -SOURCE: GTA -TARGET: Cityscapes -NUM_WORKERS: 4 -TRAIN: - DA_METHOD: MinEnt - MODEL: DeepLabv2 - RESTORE_FROM: ../../pretrained_models/DeepLab_resnet_pretrained_imagenet.pth - MULTI_LEVEL: True - LAMBDA_ENT_MAIN: 0.001 - LAMBDA_ENT_AUX: 0.0002 -TEST: +SOURCE: GTA +TARGET: Cityscapes +NUM_WORKERS: 4 +TRAIN: + DA_METHOD: MinEnt + MODEL: DeepLabv2 + RESTORE_FROM: ../../pretrained_models/DeepLab_resnet_pretrained_imagenet.pth + MULTI_LEVEL: True + LAMBDA_ENT_MAIN: 0.001 + LAMBDA_ENT_AUX: 0.0002 +TEST: MODE: best \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/minent_pretrained.yml b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/minent_pretrained.yml index 7385d864837661ce7e7fda6f5e79db87c83e3015..5ccf3a3c17916983435c5ca0dca6fcfd86209ace 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/minent_pretrained.yml +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/configs/minent_pretrained.yml @@ -1,9 +1,9 @@ -SOURCE: GTA -TARGET: Cityscapes -EXP_NAME: GTA2Cityscapes_MinEnt -NUM_WORKERS: 4 -TEST: - MODE: single - RESTORE_FROM: - - ../../pretrained_models/gta2cityscapes_minent_ER.pth +SOURCE: GTA +TARGET: Cityscapes +EXP_NAME: GTA2Cityscapes_MinEnt +NUM_WORKERS: 4 +TEST: + MODE: single + RESTORE_FROM: + - ../../pretrained_models/gta2cityscapes_minent_ER.pth # - ../../pretrained_models/gta2cityscapes_minent.pth \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/test.py b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/test.py index d6545bbdc329cf8ebfcd0504a7eeeda59435bf9f..f88cfed0c9805e8a37c20594740f4d94e77960f0 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/test.py +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/test.py @@ -1,109 +1,109 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -------------------------------------------------------- -# AdvEnt training -# Copyright (c) 2019 valeo.ai -# -# Written by Tuan-Hung Vu -# -------------------------------------------------------- -import sys -sys.path.append('/home/feipan/IntraDA/ADVENT') -import pdb - -import argparse -import os -import os.path as osp -import pprint -import warnings - -from torch.utils import data - -from advent.model.deeplabv2 import get_deeplab_v2 -from advent.dataset.cityscapes import CityscapesDataSet -from advent.domain_adaptation.config import cfg, cfg_from_file -from advent.domain_adaptation.eval_UDA import evaluate_domain_adaptation - -warnings.filterwarnings("ignore", message="numpy.dtype size changed") -warnings.filterwarnings("ignore") - - - -def get_arguments(): - """ - Parse input arguments - """ - parser = argparse.ArgumentParser(description="Code for evaluation") - parser.add_argument('--cfg', type=str, default=None, - help='optional config file', ) - parser.add_argument("--exp-suffix", type=str, default=None, - help="optional experiment suffix") - return parser.parse_args() - - -def main(config_file, exp_suffix): - # LOAD ARGS - assert config_file is not None, 'Missing cfg file' - cfg_from_file(config_file) - # auto-generate exp name if not specified - if cfg.EXP_NAME == '': - cfg.EXP_NAME = f'{cfg.SOURCE}2{cfg.TARGET}_{cfg.TRAIN.MODEL}_{cfg.TRAIN.DA_METHOD}' - if exp_suffix: - cfg.EXP_NAME += f'_{exp_suffix}' - # auto-generate snapshot path if not specified - if cfg.TEST.SNAPSHOT_DIR[0] == '': - cfg.TEST.SNAPSHOT_DIR[0] = osp.join(cfg.EXP_ROOT_SNAPSHOT, cfg.EXP_NAME) - os.makedirs(cfg.TEST.SNAPSHOT_DIR[0], exist_ok=True) - - print('Using config:') - pprint.pprint(cfg) - # load models - models = [] - n_models = len(cfg.TEST.MODEL) - if cfg.TEST.MODE == 'best': - assert n_models == 1, 'Not yet supported' - for i in range(n_models): - if cfg.TEST.MODEL[i] == 'DeepLabv2': - model = get_deeplab_v2(num_classes=cfg.NUM_CLASSES, - multi_level=cfg.TEST.MULTI_LEVEL[i]) - else: - raise NotImplementedError(f"Not yet supported {cfg.TEST.MODEL[i]}") - models.append(model) - - if os.environ.get('ADVENT_DRY_RUN', '0') == '1': - return - - # dataloaders - pdb.set_trace() - test_dataset = CityscapesDataSet(root=cfg.DATA_DIRECTORY_TARGET, - list_path=cfg.DATA_LIST_TARGET, - set=cfg.TEST.SET_TARGET, - info_path=cfg.TEST.INFO_TARGET, - crop_size=cfg.TEST.INPUT_SIZE_TARGET, - mean=cfg.TEST.IMG_MEAN, - labels_size=cfg.TEST.OUTPUT_SIZE_TARGET) - test_loader = data.DataLoader(test_dataset, - batch_size=cfg.TEST.BATCH_SIZE_TARGET, - num_workers=cfg.NUM_WORKERS, - shuffle=False, - pin_memory=True) - # eval - evaluate_domain_adaptation(models, test_loader, cfg) - - -if __name__ == '__main__': - args = get_arguments() - print('Called with args:') - print(args) - main(args.cfg, args.exp_suffix) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -------------------------------------------------------- +# AdvEnt training +# Copyright (c) 2019 valeo.ai +# +# Written by Tuan-Hung Vu +# -------------------------------------------------------- +import sys +sys.path.append('/home/feipan/IntraDA/ADVENT') +import pdb + +import argparse +import os +import os.path as osp +import pprint +import warnings + +from torch.utils import data + +from advent.model.deeplabv2 import get_deeplab_v2 +from advent.dataset.cityscapes import CityscapesDataSet +from advent.domain_adaptation.config import cfg, cfg_from_file +from advent.domain_adaptation.eval_UDA import evaluate_domain_adaptation + +warnings.filterwarnings("ignore", message="numpy.dtype size changed") +warnings.filterwarnings("ignore") + + + +def get_arguments(): + """ + Parse input arguments + """ + parser = argparse.ArgumentParser(description="Code for evaluation") + parser.add_argument('--cfg', type=str, default=None, + help='optional config file', ) + parser.add_argument("--exp-suffix", type=str, default=None, + help="optional experiment suffix") + return parser.parse_args() + + +def main(config_file, exp_suffix): + # LOAD ARGS + assert config_file is not None, 'Missing cfg file' + cfg_from_file(config_file) + # auto-generate exp name if not specified + if cfg.EXP_NAME == '': + cfg.EXP_NAME = f'{cfg.SOURCE}2{cfg.TARGET}_{cfg.TRAIN.MODEL}_{cfg.TRAIN.DA_METHOD}' + if exp_suffix: + cfg.EXP_NAME += f'_{exp_suffix}' + # auto-generate snapshot path if not specified + if cfg.TEST.SNAPSHOT_DIR[0] == '': + cfg.TEST.SNAPSHOT_DIR[0] = osp.join(cfg.EXP_ROOT_SNAPSHOT, cfg.EXP_NAME) + os.makedirs(cfg.TEST.SNAPSHOT_DIR[0], exist_ok=True) + + print('Using config:') + pprint.pprint(cfg) + # load models + models = [] + n_models = len(cfg.TEST.MODEL) + if cfg.TEST.MODE == 'best': + assert n_models == 1, 'Not yet supported' + for i in range(n_models): + if cfg.TEST.MODEL[i] == 'DeepLabv2': + model = get_deeplab_v2(num_classes=cfg.NUM_CLASSES, + multi_level=cfg.TEST.MULTI_LEVEL[i]) + else: + raise NotImplementedError(f"Not yet supported {cfg.TEST.MODEL[i]}") + models.append(model) + + if os.environ.get('ADVENT_DRY_RUN', '0') == '1': + return + + # dataloaders + pdb.set_trace() + test_dataset = CityscapesDataSet(root=cfg.DATA_DIRECTORY_TARGET, + list_path=cfg.DATA_LIST_TARGET, + set=cfg.TEST.SET_TARGET, + info_path=cfg.TEST.INFO_TARGET, + crop_size=cfg.TEST.INPUT_SIZE_TARGET, + mean=cfg.TEST.IMG_MEAN, + labels_size=cfg.TEST.OUTPUT_SIZE_TARGET) + test_loader = data.DataLoader(test_dataset, + batch_size=cfg.TEST.BATCH_SIZE_TARGET, + num_workers=cfg.NUM_WORKERS, + shuffle=False, + pin_memory=True) + # eval + evaluate_domain_adaptation(models, test_loader, cfg) + + +if __name__ == '__main__': + args = get_arguments() + print('Called with args:') + print(args) + main(args.cfg, args.exp_suffix) diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/train.py b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/train.py index 80a915ab207ca3fa3820ae08f94b2a61146449ab..3109bd535d9fb0aee80d3ec8b9e4e11224c95b0a 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/train.py +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/scripts/train.py @@ -1,159 +1,159 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -------------------------------------------------------- -# AdvEnt training -# Copyright (c) 2019 valeo.ai -# -# Written by Tuan-Hung Vu -# -------------------------------------------------------- -import argparse -import os -import os.path as osp -import pprint -import random -import warnings - -import numpy as np -import yaml -import torch -from torch.utils import data - -from advent.model.deeplabv2 import get_deeplab_v2 -from advent.dataset.gta5 import GTA5DataSet -from advent.dataset.cityscapes import CityscapesDataSet -from advent.domain_adaptation.config import cfg, cfg_from_file -from advent.domain_adaptation.train_UDA import train_domain_adaptation - -warnings.filterwarnings("ignore", message="numpy.dtype size changed") -warnings.filterwarnings("ignore") - - -def get_arguments(): - """ - Parse input arguments - """ - parser = argparse.ArgumentParser(description="Code for domain adaptation (DA) training") - parser.add_argument('--cfg', type=str, default=None, - help='optional config file', ) - parser.add_argument("--random-train", action="store_true", - help="not fixing random seed.") - parser.add_argument("--tensorboard", action="store_true", - help="visualize training loss with tensorboardX.") - parser.add_argument("--viz-every-iter", type=int, default=None, - help="visualize results.") - parser.add_argument("--exp-suffix", type=str, default=None, - help="optional experiment suffix") - return parser.parse_args() - - -def main(): - # LOAD ARGS - args = get_arguments() - print('Called with args:') - print(args) - - assert args.cfg is not None, 'Missing cfg file' - cfg_from_file(args.cfg) - # auto-generate exp name if not specified - if cfg.EXP_NAME == '': - cfg.EXP_NAME = f'{cfg.SOURCE}2{cfg.TARGET}_{cfg.TRAIN.MODEL}_{cfg.TRAIN.DA_METHOD}' - - if args.exp_suffix: - cfg.EXP_NAME += f'_{args.exp_suffix}' - # auto-generate snapshot path if not specified - if cfg.TRAIN.SNAPSHOT_DIR == '': - cfg.TRAIN.SNAPSHOT_DIR = osp.join(cfg.EXP_ROOT_SNAPSHOT, cfg.EXP_NAME) - os.makedirs(cfg.TRAIN.SNAPSHOT_DIR, exist_ok=True) - # tensorboard - if args.tensorboard: - if cfg.TRAIN.TENSORBOARD_LOGDIR == '': - cfg.TRAIN.TENSORBOARD_LOGDIR = osp.join(cfg.EXP_ROOT_LOGS, 'tensorboard', cfg.EXP_NAME) - os.makedirs(cfg.TRAIN.TENSORBOARD_LOGDIR, exist_ok=True) - if args.viz_every_iter is not None: - cfg.TRAIN.TENSORBOARD_VIZRATE = args.viz_every_iter - else: - cfg.TRAIN.TENSORBOARD_LOGDIR = '' - print('Using config:') - pprint.pprint(cfg) - - # INIT - _init_fn = None - if not args.random_train: - torch.manual_seed(cfg.TRAIN.RANDOM_SEED) - torch.cuda.manual_seed(cfg.TRAIN.RANDOM_SEED) - np.random.seed(cfg.TRAIN.RANDOM_SEED) - random.seed(cfg.TRAIN.RANDOM_SEED) - - def _init_fn(worker_id): - np.random.seed(cfg.TRAIN.RANDOM_SEED + worker_id) - - if os.environ.get('ADVENT_DRY_RUN', '0') == '1': - return - - # LOAD SEGMENTATION NET - assert osp.exists(cfg.TRAIN.RESTORE_FROM), f'Missing init model {cfg.TRAIN.RESTORE_FROM}' - if cfg.TRAIN.MODEL == 'DeepLabv2': - model = get_deeplab_v2(num_classes=cfg.NUM_CLASSES, multi_level=cfg.TRAIN.MULTI_LEVEL) - saved_state_dict = torch.load(cfg.TRAIN.RESTORE_FROM) - if 'DeepLab_resnet_pretrained_imagenet' in cfg.TRAIN.RESTORE_FROM: - new_params = model.state_dict().copy() - for i in saved_state_dict: - i_parts = i.split('.') - if not i_parts[1] == 'layer5': - new_params['.'.join(i_parts[1:])] = saved_state_dict[i] - model.load_state_dict(new_params) - else: - model.load_state_dict(saved_state_dict) - else: - raise NotImplementedError(f"Not yet supported {cfg.TRAIN.MODEL}") - print('Model loaded') - - # DATALOADERS - source_dataset = GTA5DataSet(root=cfg.DATA_DIRECTORY_SOURCE, - list_path=cfg.DATA_LIST_SOURCE, - set=cfg.TRAIN.SET_SOURCE, - max_iters=cfg.TRAIN.MAX_ITERS * cfg.TRAIN.BATCH_SIZE_SOURCE, - crop_size=cfg.TRAIN.INPUT_SIZE_SOURCE, - mean=cfg.TRAIN.IMG_MEAN) - source_loader = data.DataLoader(source_dataset, - batch_size=cfg.TRAIN.BATCH_SIZE_SOURCE, - num_workers=cfg.NUM_WORKERS, - shuffle=True, - pin_memory=True, - worker_init_fn=_init_fn) - - target_dataset = CityscapesDataSet(root=cfg.DATA_DIRECTORY_TARGET, - list_path=cfg.DATA_LIST_TARGET, - set=cfg.TRAIN.SET_TARGET, - info_path=cfg.TRAIN.INFO_TARGET, - max_iters=cfg.TRAIN.MAX_ITERS * cfg.TRAIN.BATCH_SIZE_TARGET, - crop_size=cfg.TRAIN.INPUT_SIZE_TARGET, - mean=cfg.TRAIN.IMG_MEAN) - target_loader = data.DataLoader(target_dataset, - batch_size=cfg.TRAIN.BATCH_SIZE_TARGET, - num_workers=cfg.NUM_WORKERS, - shuffle=True, - pin_memory=True, - worker_init_fn=_init_fn) - - with open(osp.join(cfg.TRAIN.SNAPSHOT_DIR, 'train_cfg.yml'), 'w') as yaml_file: - yaml.dump(cfg, yaml_file, default_flow_style=False) - - # UDA TRAINING - train_domain_adaptation(model, source_loader, target_loader, cfg) - - -if __name__ == '__main__': - main() +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# -------------------------------------------------------- +# AdvEnt training +# Copyright (c) 2019 valeo.ai +# +# Written by Tuan-Hung Vu +# -------------------------------------------------------- +import argparse +import os +import os.path as osp +import pprint +import random +import warnings + +import numpy as np +import yaml +import torch +from torch.utils import data + +from advent.model.deeplabv2 import get_deeplab_v2 +from advent.dataset.gta5 import GTA5DataSet +from advent.dataset.cityscapes import CityscapesDataSet +from advent.domain_adaptation.config import cfg, cfg_from_file +from advent.domain_adaptation.train_UDA import train_domain_adaptation + +warnings.filterwarnings("ignore", message="numpy.dtype size changed") +warnings.filterwarnings("ignore") + + +def get_arguments(): + """ + Parse input arguments + """ + parser = argparse.ArgumentParser(description="Code for domain adaptation (DA) training") + parser.add_argument('--cfg', type=str, default=None, + help='optional config file', ) + parser.add_argument("--random-train", action="store_true", + help="not fixing random seed.") + parser.add_argument("--tensorboard", action="store_true", + help="visualize training loss with tensorboardX.") + parser.add_argument("--viz-every-iter", type=int, default=None, + help="visualize results.") + parser.add_argument("--exp-suffix", type=str, default=None, + help="optional experiment suffix") + return parser.parse_args() + + +def main(): + # LOAD ARGS + args = get_arguments() + print('Called with args:') + print(args) + + assert args.cfg is not None, 'Missing cfg file' + cfg_from_file(args.cfg) + # auto-generate exp name if not specified + if cfg.EXP_NAME == '': + cfg.EXP_NAME = f'{cfg.SOURCE}2{cfg.TARGET}_{cfg.TRAIN.MODEL}_{cfg.TRAIN.DA_METHOD}' + + if args.exp_suffix: + cfg.EXP_NAME += f'_{args.exp_suffix}' + # auto-generate snapshot path if not specified + if cfg.TRAIN.SNAPSHOT_DIR == '': + cfg.TRAIN.SNAPSHOT_DIR = osp.join(cfg.EXP_ROOT_SNAPSHOT, cfg.EXP_NAME) + os.makedirs(cfg.TRAIN.SNAPSHOT_DIR, exist_ok=True) + # tensorboard + if args.tensorboard: + if cfg.TRAIN.TENSORBOARD_LOGDIR == '': + cfg.TRAIN.TENSORBOARD_LOGDIR = osp.join(cfg.EXP_ROOT_LOGS, 'tensorboard', cfg.EXP_NAME) + os.makedirs(cfg.TRAIN.TENSORBOARD_LOGDIR, exist_ok=True) + if args.viz_every_iter is not None: + cfg.TRAIN.TENSORBOARD_VIZRATE = args.viz_every_iter + else: + cfg.TRAIN.TENSORBOARD_LOGDIR = '' + print('Using config:') + pprint.pprint(cfg) + + # INIT + _init_fn = None + if not args.random_train: + torch.manual_seed(cfg.TRAIN.RANDOM_SEED) + torch.cuda.manual_seed(cfg.TRAIN.RANDOM_SEED) + np.random.seed(cfg.TRAIN.RANDOM_SEED) + random.seed(cfg.TRAIN.RANDOM_SEED) + + def _init_fn(worker_id): + np.random.seed(cfg.TRAIN.RANDOM_SEED + worker_id) + + if os.environ.get('ADVENT_DRY_RUN', '0') == '1': + return + + # LOAD SEGMENTATION NET + assert osp.exists(cfg.TRAIN.RESTORE_FROM), f'Missing init model {cfg.TRAIN.RESTORE_FROM}' + if cfg.TRAIN.MODEL == 'DeepLabv2': + model = get_deeplab_v2(num_classes=cfg.NUM_CLASSES, multi_level=cfg.TRAIN.MULTI_LEVEL) + saved_state_dict = torch.load(cfg.TRAIN.RESTORE_FROM) + if 'DeepLab_resnet_pretrained_imagenet' in cfg.TRAIN.RESTORE_FROM: + new_params = model.state_dict().copy() + for i in saved_state_dict: + i_parts = i.split('.') + if not i_parts[1] == 'layer5': + new_params['.'.join(i_parts[1:])] = saved_state_dict[i] + model.load_state_dict(new_params) + else: + model.load_state_dict(saved_state_dict) + else: + raise NotImplementedError(f"Not yet supported {cfg.TRAIN.MODEL}") + print('Model loaded') + + # DATALOADERS + source_dataset = GTA5DataSet(root=cfg.DATA_DIRECTORY_SOURCE, + list_path=cfg.DATA_LIST_SOURCE, + set=cfg.TRAIN.SET_SOURCE, + max_iters=cfg.TRAIN.MAX_ITERS * cfg.TRAIN.BATCH_SIZE_SOURCE, + crop_size=cfg.TRAIN.INPUT_SIZE_SOURCE, + mean=cfg.TRAIN.IMG_MEAN) + source_loader = data.DataLoader(source_dataset, + batch_size=cfg.TRAIN.BATCH_SIZE_SOURCE, + num_workers=cfg.NUM_WORKERS, + shuffle=True, + pin_memory=True, + worker_init_fn=_init_fn) + + target_dataset = CityscapesDataSet(root=cfg.DATA_DIRECTORY_TARGET, + list_path=cfg.DATA_LIST_TARGET, + set=cfg.TRAIN.SET_TARGET, + info_path=cfg.TRAIN.INFO_TARGET, + max_iters=cfg.TRAIN.MAX_ITERS * cfg.TRAIN.BATCH_SIZE_TARGET, + crop_size=cfg.TRAIN.INPUT_SIZE_TARGET, + mean=cfg.TRAIN.IMG_MEAN) + target_loader = data.DataLoader(target_dataset, + batch_size=cfg.TRAIN.BATCH_SIZE_TARGET, + num_workers=cfg.NUM_WORKERS, + shuffle=True, + pin_memory=True, + worker_init_fn=_init_fn) + + with open(osp.join(cfg.TRAIN.SNAPSHOT_DIR, 'train_cfg.yml'), 'w') as yaml_file: + yaml.dump(cfg, yaml_file, default_flow_style=False) + + # UDA TRAINING + train_domain_adaptation(model, source_loader, target_loader, cfg) + + +if __name__ == '__main__': + main() diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/utils/func.py b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/utils/func.py index a57a26d522c9e169ccad5c561b297dbccb5b4cfe..0ff54adcd3010608be3cfd0b58478b9da322feaa 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/utils/func.py +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/utils/func.py @@ -1,75 +1,75 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import numpy as np -import torch -import torch.nn as nn - -from advent.utils.loss import cross_entropy_2d - - -def bce_loss(y_pred, y_label): - y_truth_tensor = torch.FloatTensor(y_pred.size()) - y_truth_tensor.fill_(y_label) - y_truth_tensor = y_truth_tensor.to(y_pred.get_device()) - return nn.BCEWithLogitsLoss()(y_pred, y_truth_tensor) - - -def loss_calc(pred, label, device): - """ - This function returns cross entropy loss for semantic segmentation - """ - # out shape batch_size x channels x h x w -> batch_size x channels x h x w - # label shape h x w x 1 x batch_size -> batch_size x 1 x h x w - label = label.long().to(device) - return cross_entropy_2d(pred, label) - - -def lr_poly(base_lr, iter, max_iter, power): - """ Poly_LR scheduler - """ - return base_lr * ((1 - float(iter) / max_iter) ** power) - - -def _adjust_learning_rate(optimizer, i_iter, cfg, learning_rate): - lr = lr_poly(learning_rate, i_iter, cfg.TRAIN.MAX_ITERS, cfg.TRAIN.POWER) - optimizer.param_groups[0]['lr'] = lr - if len(optimizer.param_groups) > 1: - optimizer.param_groups[1]['lr'] = lr * 10 - - -def adjust_learning_rate(optimizer, i_iter, cfg): - """ adject learning rate for main segnet - """ - _adjust_learning_rate(optimizer, i_iter, cfg, cfg.TRAIN.LEARNING_RATE) - - -def adjust_learning_rate_discriminator(optimizer, i_iter, cfg): - _adjust_learning_rate(optimizer, i_iter, cfg, cfg.TRAIN.LEARNING_RATE_D) - - -def prob_2_entropy(prob): - """ convert probabilistic prediction maps to weighted self-information maps - """ - n, c, h, w = prob.size() - return -torch.mul(prob, torch.log2(prob + 1e-30)) / np.log2(c) - - -def fast_hist(a, b, n): - k = (a >= 0) & (a < n) - return np.bincount(n * a[k].astype(int) + b[k], minlength=n ** 2).reshape(n, n) - - -def per_class_iu(hist): - return np.diag(hist) / (hist.sum(1) + hist.sum(0) - np.diag(hist)) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +import torch +import torch.nn as nn + +from advent.utils.loss import cross_entropy_2d + + +def bce_loss(y_pred, y_label): + y_truth_tensor = torch.FloatTensor(y_pred.size()) + y_truth_tensor.fill_(y_label) + y_truth_tensor = y_truth_tensor.to(y_pred.get_device()) + return nn.BCEWithLogitsLoss()(y_pred, y_truth_tensor) + + +def loss_calc(pred, label, device): + """ + This function returns cross entropy loss for semantic segmentation + """ + # out shape batch_size x channels x h x w -> batch_size x channels x h x w + # label shape h x w x 1 x batch_size -> batch_size x 1 x h x w + label = label.long().to(device) + return cross_entropy_2d(pred, label) + + +def lr_poly(base_lr, iter, max_iter, power): + """ Poly_LR scheduler + """ + return base_lr * ((1 - float(iter) / max_iter) ** power) + + +def _adjust_learning_rate(optimizer, i_iter, cfg, learning_rate): + lr = lr_poly(learning_rate, i_iter, cfg.TRAIN.MAX_ITERS, cfg.TRAIN.POWER) + optimizer.param_groups[0]['lr'] = lr + if len(optimizer.param_groups) > 1: + optimizer.param_groups[1]['lr'] = lr * 10 + + +def adjust_learning_rate(optimizer, i_iter, cfg): + """ adject learning rate for main segnet + """ + _adjust_learning_rate(optimizer, i_iter, cfg, cfg.TRAIN.LEARNING_RATE) + + +def adjust_learning_rate_discriminator(optimizer, i_iter, cfg): + _adjust_learning_rate(optimizer, i_iter, cfg, cfg.TRAIN.LEARNING_RATE_D) + + +def prob_2_entropy(prob): + """ convert probabilistic prediction maps to weighted self-information maps + """ + n, c, h, w = prob.size() + return -torch.mul(prob, torch.log2(prob + 1e-30)) / np.log2(c) + + +def fast_hist(a, b, n): + k = (a >= 0) & (a < n) + return np.bincount(n * a[k].astype(int) + b[k], minlength=n ** 2).reshape(n, n) + + +def per_class_iu(hist): + return np.diag(hist) / (hist.sum(1) + hist.sum(0) - np.diag(hist)) diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/utils/viz_segmask.py b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/utils/viz_segmask.py index 0fc82ad3ec2aa717de7fb257324bda28c830b9b2..949396b6c78c9a95e2e6a8f5bdf78df3a137b9fd 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/utils/viz_segmask.py +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/advent/utils/viz_segmask.py @@ -1,34 +1,34 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import numpy as np -from PIL import Image - -palette = [128, 64, 128, 244, 35, 232, 70, 70, 70, 102, 102, 156, - 190, 153, 153, 153, 153, 153, 250, - 170, 30, - 220, 220, 0, 107, 142, 35, 152, 251, 152, - 70, 130, 180, 220, 20, 60, 255, 0, 0, 0, 0, - 142, 0, 0, 70, - 0, 60, 100, 0, 80, 100, 0, 0, 230, 119, 11, 32] -zero_pad = 256 * 3 - len(palette) -for i in range(zero_pad): - palette.append(0) - - -def colorize_mask(mask): - # mask: numpy array of the mask - new_mask = Image.fromarray(mask.astype(np.uint8)).convert('P') - new_mask.putpalette(palette) - return new_mask +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +from PIL import Image + +palette = [128, 64, 128, 244, 35, 232, 70, 70, 70, 102, 102, 156, + 190, 153, 153, 153, 153, 153, 250, + 170, 30, + 220, 220, 0, 107, 142, 35, 152, 251, 152, + 70, 130, 180, 220, 20, 60, 255, 0, 0, 0, 0, + 142, 0, 0, 70, + 0, 60, 100, 0, 80, 100, 0, 0, 230, 119, 11, 32] +zero_pad = 256 * 3 - len(palette) +for i in range(zero_pad): + palette.append(0) + + +def colorize_mask(mask): + # mask: numpy array of the mask + new_mask = Image.fromarray(mask.astype(np.uint8)).convert('P') + new_mask.putpalette(palette) + return new_mask diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/modelzoo_level.txt b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/modelzoo_level.txt +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/requirements.txt b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/requirements.txt index fa5371544150086c29001df6fadecfcffe27b5ee..e03d22e457e28db0000e1ea2235adb1a432521c3 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/requirements.txt +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/ADVENT/requirements.txt @@ -1,2 +1,2 @@ -torch==1.5.0 -torchvision==0.6.0 +torch==1.5.0 +torchvision==0.6.0 diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/LICENSE b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/LICENSE index eeac88fb9dc15a1427b41173cf5f136327230c49..56ee3c8c4cc2b4b32e0975d17258f9ba515fdbcc 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/LICENSE +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/README.md b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/README.md index 2de9b5ac6a87e095d9b9e79e1ae48e90c4129058..22445b46eb4b62dfdfec1fcec6d784886d66950f 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/README.md +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/README.md @@ -1,77 +1,77 @@ -# IntraDA - -- 参考实现: -``` -url=https://github.com/feipan664/IntraDA.git -branch=master -commit_id=070b0b702fe94a34288eba4ca990410b5aaadc4a -``` - -## IntraDA Detail - -- 增加了混合精度训练 -- 增加了多卡分布式训练 -- 优化了loss在NPU上的计算效率 - -## Requirements - -- CANN 5.0.2 -- torch 1.5.0+ascend.post3.20210824 -- apex 0.1+ascend.20210824 -- 安装ADVENT - ``` - cd IntraDA/ADVENT - pip3 install -e . - ``` -- 下载[CityScapes数据集](https://www.cityscapes-dataset.com/downloads/) - 在IntraDA/ADVENT目录下创建data文件夹,将数据集按照如下结构放入data目录: - ``` - |-- ADVENT - | |-- data - | | `-- Cityscapes - | | |-- gtFine - | | `-- leftImg8bit - ``` -- 下载以下两个预训练模型: - ImageNet预训练模型: - https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/semantic_segmentation/IntraDA/DeepLab_resnet_pretrained_imagenet.pth - ADVENT warmup模型: - https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/semantic_segmentation/IntraDA/gta2cityscapes_advent.pth - 在IntraDA/ADVENT目录下创建pretrained_models文件夹,将以上2个模型放入改文件夹,目录结构如下: - ``` - |-- ADVENT - | |-- pretrained_models - | | |-- DeepLab_resnet_pretrained_imagenet.pth - | | `-- gta2cityscapes_advent.pth - ``` -- 生成训练用的伪标签及数据集分组文件: - ``` - cd IntraDA/entropy_rank/ - bash gen_color_mask_npu.sh - ``` - - -## Training - -```bash -cd IntraDA/intrada - -# 1p train perf 运行 500 step, 输出 performance_1p.log 文件 -bash test/train_performance_1p.sh - -# 8p train perf 运行 500 step, 输出 performance_8p.log 文件 -bash test/train_performance_8p.sh - -# 8p train full 完整训练并保存checkpoints,中间不会测试 -bash test/train_full_8p.sh - -# eval 测试8p训练保存的 checkpoints 得到精度信息 -bash test/train_eval_8p.sh -``` - -## IntraDA training result - -| mIoU | FPS | Npu_nums | Epochs | AMP_Type | -| :------: | :------: | :------: | :------: | :------: | -| | 2.7 | 1 | - | O2 | -| 42.55 | 21 | 8 | - | O2 | +# IntraDA + +- 参考实现: +``` +url=https://github.com/feipan664/IntraDA.git +branch=master +commit_id=070b0b702fe94a34288eba4ca990410b5aaadc4a +``` + +## IntraDA Detail + +- 增加了混合精度训练 +- 增加了多卡分布式训练 +- 优化了loss在NPU上的计算效率 + +## Requirements + +- CANN 5.0.2 +- torch 1.5.0+ascend.post3.20210824 +- apex 0.1+ascend.20210824 +- 安装ADVENT + ``` + cd IntraDA/ADVENT + pip3 install -e . + ``` +- 下载[CityScapes数据集](https://www.cityscapes-dataset.com/downloads/) + 在IntraDA/ADVENT目录下创建data文件夹,将数据集按照如下结构放入data目录: + ``` + |-- ADVENT + | |-- data + | | `-- Cityscapes + | | |-- gtFine + | | `-- leftImg8bit + ``` +- 下载以下两个预训练模型: + ImageNet预训练模型: + https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/semantic_segmentation/IntraDA/DeepLab_resnet_pretrained_imagenet.pth + ADVENT warmup模型: + https://ascend-pytorch-model-file.obs.cn-north-4.myhuaweicloud.com/%E4%BA%A4%E4%BB%98%E4%BB%B6/cv/semantic_segmentation/IntraDA/gta2cityscapes_advent.pth + 在IntraDA/ADVENT目录下创建pretrained_models文件夹,将以上2个模型放入改文件夹,目录结构如下: + ``` + |-- ADVENT + | |-- pretrained_models + | | |-- DeepLab_resnet_pretrained_imagenet.pth + | | `-- gta2cityscapes_advent.pth + ``` +- 生成训练用的伪标签及数据集分组文件: + ``` + cd IntraDA/entropy_rank/ + bash gen_color_mask_npu.sh + ``` + + +## Training + +```bash +cd IntraDA/intrada + +# 1p train perf 运行 500 step, 输出 performance_1p.log 文件 +bash test/train_performance_1p.sh + +# 8p train perf 运行 500 step, 输出 performance_8p.log 文件 +bash test/train_performance_8p.sh + +# 8p train full 完整训练并保存checkpoints,中间不会测试 +bash test/train_full_8p.sh + +# eval 测试8p训练保存的 checkpoints 得到精度信息 +bash test/train_eval_8p.sh +``` + +## IntraDA training result + +| mIoU | FPS | Npu_nums | Epochs | AMP_Type | +| :------: | :------: | :------: | :------: | :------: | +| | 2.7 | 1 | - | O2 | +| 42.55 | 21 | 8 | - | O2 | diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/figure/adaptsegnet.PNG b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/figure/adaptsegnet.PNG deleted file mode 100644 index a9267aadc430b587f9641ab9820d4c9d3e35be2e..0000000000000000000000000000000000000000 Binary files a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/figure/adaptsegnet.PNG and /dev/null differ diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/figure/advent.PNG b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/figure/advent.PNG deleted file mode 100644 index d737e14f12538b08e715becc5e1b95e6ed19fa20..0000000000000000000000000000000000000000 Binary files a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/figure/advent.PNG and /dev/null differ diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/intrada/test.py b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/intrada/test.py index 77bf700ab35061280ad6277fac340b3941714b8d..9830c7b3a3bf490403e642d7a99b4723be3c1f5b 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/intrada/test.py +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/intrada/test.py @@ -1,114 +1,114 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#-------------------------------------------------------------------- -# modified from "ADVENT/advent/scripts/test.py" by Tuan-Hung Vu -#-------------------------------------------------------------------- -import argparse -import os -import os.path as osp -import pprint -import warnings -import torch - -from torch.utils import data - -from advent.model.deeplabv2 import get_deeplab_v2 -from advent.dataset.cityscapes import CityscapesDataSet -from advent.domain_adaptation.config import cfg, cfg_from_file -# from advent.domain_adaptation.eval_UDA import evaluate_domain_adaptation -from eval_UDA import evaluate_domain_adaptation - -warnings.filterwarnings("ignore", message="numpy.dtype size changed") -warnings.filterwarnings("ignore") - - -def get_arguments(): - """ - Parse input arguments - """ - parser = argparse.ArgumentParser(description="Code for evaluation") - parser.add_argument('--cfg', type=str, default=None, - help='optional config file', ) - parser.add_argument("--exp-suffix", type=str, default=None, - help="optional experiment suffix") - parser.add_argument('--device_type', type=str, default='npu') - parser.add_argument('--device_id', type=int, ) - return parser.parse_args() - - -def main(config_file, exp_suffix): - # LOAD ARGS - assert config_file is not None, 'Missing cfg file' - cfg_from_file(config_file) - # auto-generate exp name if not specified - # pdb.set_trace() - if cfg.EXP_NAME == '': - cfg.EXP_NAME = f'{cfg.SOURCE}2{cfg.TARGET}_{cfg.TRAIN.MODEL}_{cfg.TRAIN.DA_METHOD}' - if exp_suffix: - cfg.EXP_NAME += f'_{exp_suffix}' - # auto-generate snapshot path if not specified - # pdb.set_trace() - if cfg.TEST.SNAPSHOT_DIR[0] == '': - cfg.TEST.SNAPSHOT_DIR[0] = osp.join(cfg.EXP_ROOT_SNAPSHOT, cfg.EXP_NAME) - os.makedirs(cfg.TEST.SNAPSHOT_DIR[0], exist_ok=True) - - device = torch.device("{}:{}".format(args.device_type, args.device_id)) - if args.device_type == 'npu': - torch.npu.set_device(args.device_id) - elif args.device_type == 'cuda': - torch.cuda.set_device(args.device_id) - - print('Using config:') - pprint.pprint(cfg) - # load models - models = [] - n_models = len(cfg.TEST.MODEL) - if cfg.TEST.MODE == 'best': - assert n_models == 1, 'Not yet supported' - for i in range(n_models): - if cfg.TEST.MODEL[i] == 'DeepLabv2': - model = get_deeplab_v2(num_classes=cfg.NUM_CLASSES, - multi_level=cfg.TEST.MULTI_LEVEL[i]) - else: - raise NotImplementedError(f"Not yet supported {cfg.TEST.MODEL[i]}") - models.append(model) - - if os.environ.get('ADVENT_DRY_RUN', '0') == '1': - return - - # dataloaders - # pdb.set_trace() - test_dataset = CityscapesDataSet(root=cfg.DATA_DIRECTORY_TARGET, - list_path='../ADVENT/advent/dataset/cityscapes_list/{}.txt', - set=cfg.TEST.SET_TARGET, - info_path=cfg.TEST.INFO_TARGET, - crop_size=cfg.TEST.INPUT_SIZE_TARGET, - mean=cfg.TEST.IMG_MEAN, - labels_size=cfg.TEST.OUTPUT_SIZE_TARGET) - test_loader = data.DataLoader(test_dataset, - batch_size=cfg.TEST.BATCH_SIZE_TARGET, - num_workers=cfg.NUM_WORKERS, - shuffle=False, - pin_memory=True) - # eval - # pdb.set_trace() - evaluate_domain_adaptation(models, test_loader, cfg, device) - - -if __name__ == '__main__': - args = get_arguments() - print('Called with args:') - print(args) - main(args.cfg, args.exp_suffix) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#-------------------------------------------------------------------- +# modified from "ADVENT/advent/scripts/test.py" by Tuan-Hung Vu +#-------------------------------------------------------------------- +import argparse +import os +import os.path as osp +import pprint +import warnings +import torch + +from torch.utils import data + +from advent.model.deeplabv2 import get_deeplab_v2 +from advent.dataset.cityscapes import CityscapesDataSet +from advent.domain_adaptation.config import cfg, cfg_from_file +# from advent.domain_adaptation.eval_UDA import evaluate_domain_adaptation +from eval_UDA import evaluate_domain_adaptation + +warnings.filterwarnings("ignore", message="numpy.dtype size changed") +warnings.filterwarnings("ignore") + + +def get_arguments(): + """ + Parse input arguments + """ + parser = argparse.ArgumentParser(description="Code for evaluation") + parser.add_argument('--cfg', type=str, default=None, + help='optional config file', ) + parser.add_argument("--exp-suffix", type=str, default=None, + help="optional experiment suffix") + parser.add_argument('--device_type', type=str, default='npu') + parser.add_argument('--device_id', type=int, ) + return parser.parse_args() + + +def main(config_file, exp_suffix): + # LOAD ARGS + assert config_file is not None, 'Missing cfg file' + cfg_from_file(config_file) + # auto-generate exp name if not specified + # pdb.set_trace() + if cfg.EXP_NAME == '': + cfg.EXP_NAME = f'{cfg.SOURCE}2{cfg.TARGET}_{cfg.TRAIN.MODEL}_{cfg.TRAIN.DA_METHOD}' + if exp_suffix: + cfg.EXP_NAME += f'_{exp_suffix}' + # auto-generate snapshot path if not specified + # pdb.set_trace() + if cfg.TEST.SNAPSHOT_DIR[0] == '': + cfg.TEST.SNAPSHOT_DIR[0] = osp.join(cfg.EXP_ROOT_SNAPSHOT, cfg.EXP_NAME) + os.makedirs(cfg.TEST.SNAPSHOT_DIR[0], exist_ok=True) + + device = torch.device("{}:{}".format(args.device_type, args.device_id)) + if args.device_type == 'npu': + torch.npu.set_device(args.device_id) + elif args.device_type == 'cuda': + torch.cuda.set_device(args.device_id) + + print('Using config:') + pprint.pprint(cfg) + # load models + models = [] + n_models = len(cfg.TEST.MODEL) + if cfg.TEST.MODE == 'best': + assert n_models == 1, 'Not yet supported' + for i in range(n_models): + if cfg.TEST.MODEL[i] == 'DeepLabv2': + model = get_deeplab_v2(num_classes=cfg.NUM_CLASSES, + multi_level=cfg.TEST.MULTI_LEVEL[i]) + else: + raise NotImplementedError(f"Not yet supported {cfg.TEST.MODEL[i]}") + models.append(model) + + if os.environ.get('ADVENT_DRY_RUN', '0') == '1': + return + + # dataloaders + # pdb.set_trace() + test_dataset = CityscapesDataSet(root=cfg.DATA_DIRECTORY_TARGET, + list_path='../ADVENT/advent/dataset/cityscapes_list/{}.txt', + set=cfg.TEST.SET_TARGET, + info_path=cfg.TEST.INFO_TARGET, + crop_size=cfg.TEST.INPUT_SIZE_TARGET, + mean=cfg.TEST.IMG_MEAN, + labels_size=cfg.TEST.OUTPUT_SIZE_TARGET) + test_loader = data.DataLoader(test_dataset, + batch_size=cfg.TEST.BATCH_SIZE_TARGET, + num_workers=cfg.NUM_WORKERS, + shuffle=False, + pin_memory=True) + # eval + # pdb.set_trace() + evaluate_domain_adaptation(models, test_loader, cfg, device) + + +if __name__ == '__main__': + args = get_arguments() + print('Called with args:') + print(args) + main(args.cfg, args.exp_suffix) diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/intrada/train.py b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/intrada/train.py index ce51c5899142a38ff2be0330976f2dedc43b9cdc..89fbde254ae220ad769d69e1201c06e60f3fb0cb 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/intrada/train.py +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/intrada/train.py @@ -1,197 +1,197 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#-------------------------------------------------------------------- -# modified from "ADVENT/advent/scripts/train.py" by Tuan-Hung Vu -#-------------------------------------------------------------------- -import argparse -import os -import os.path as osp -import pprint -import random -import warnings - -import numpy as np -import yaml -import torch -from torch.utils import data - -from advent.model.deeplabv2 import get_deeplab_v2 -from advent.dataset.gta5 import GTA5DataSet -from advent.dataset.cityscapes import CityscapesDataSet as CityscapesDataSet_hard -from cityscapes import CityscapesDataSet as CityscapesDataSet_easy -from advent.domain_adaptation.config import cfg, cfg_from_file -from train_UDA import train_domain_adaptation - - -warnings.filterwarnings("ignore", message="numpy.dtype size changed") -warnings.filterwarnings("ignore") - - -def get_arguments(): - """ - Parse input arguments - """ - parser = argparse.ArgumentParser(description="Code for domain adaptation (DA) training") - parser.add_argument('--cfg', type=str, default=None, - help='optional config file', ) - parser.add_argument("--random-train", action="store_true", - help="not fixing random seed.") - parser.add_argument("--tensorboard", action="store_true", - help="visualize training loss with tensorboardX.") - parser.add_argument("--viz_every_iter", type=int, default=None, - help="visualize results.") - parser.add_argument("--exp-suffix", type=str, default=None, - help="optional experiment suffix") - parser.add_argument('--rank', type=int, default=0) - parser.add_argument('--device_type', type=str, default='npu') - parser.add_argument('--device_id', type=int, ) - parser.add_argument('--world_size', type=int, default=1) - parser.add_argument('--distributed', action='store_true', default=False) - parser.add_argument('--performance_log', action='store_true', default=False) - return parser.parse_args() - - -def main(): - # LOAD ARGS - args = get_arguments() - print('Called with args:') - print(args) - - # pdb.set_trace() - - assert args.cfg is not None, 'Missing cfg file' - cfg_from_file(args.cfg) - cfg.distributed = args.distributed - ddp_backend = "hccl" if args.device_type == "npu" else "nccl" - - if cfg.distributed: - torch.distributed.init_process_group(backend=ddp_backend, world_size=args.world_size, rank=args.rank) - device = torch.device("{}:{}".format(args.device_type ,args.device_id)) - cfg.device_id = args.device_id - cfg.rank = args.rank - cfg.world_size = args.world_size - cfg.device_type = args.device_type - cfg.performance_log = args.performance_log - if args.device_type == 'cuda': - torch.cuda.set_device(args.device_id) - elif args.device_type == 'npu': - torch.npu.set_device(args.device_id) - - cfg.is_master_node = args.world_size == 1 or args.device_id == 0 - - # auto-generate exp name if not specified - if cfg.EXP_NAME == '': - cfg.EXP_NAME = f'{cfg.SOURCE}2{cfg.TARGET}_{cfg.TRAIN.MODEL}_{cfg.TRAIN.DA_METHOD}' - - if args.exp_suffix: - cfg.EXP_NAME += f'_{args.exp_suffix}' - # auto-generate snapshot path if not specified - if cfg.TRAIN.SNAPSHOT_DIR == '': - cfg.TRAIN.SNAPSHOT_DIR = osp.join(cfg.EXP_ROOT_SNAPSHOT, cfg.EXP_NAME) - os.makedirs(cfg.TRAIN.SNAPSHOT_DIR, exist_ok=True) - # tensorboard - if args.tensorboard: - if cfg.TRAIN.TENSORBOARD_LOGDIR == '': - cfg.TRAIN.TENSORBOARD_LOGDIR = osp.join(cfg.EXP_ROOT_LOGS, 'tensorboard', cfg.EXP_NAME) - os.makedirs(cfg.TRAIN.TENSORBOARD_LOGDIR, exist_ok=True) - if args.viz_every_iter is not None: - cfg.TRAIN.TENSORBOARD_VIZRATE = args.viz_every_iter - else: - cfg.TRAIN.TENSORBOARD_LOGDIR = '' - if cfg.is_master_node: - print('Using config:') - pprint.pprint(cfg) - - # INIT - _init_fn = None - if not args.random_train: - torch.manual_seed(cfg.TRAIN.RANDOM_SEED) - if args.device_type == 'cuda': - torch.cuda.manual_seed(cfg.TRAIN.RANDOM_SEED) - elif args.device_type == 'npu': - torch.npu.manual_seed(cfg.TRAIN.RANDOM_SEED) - np.random.seed(cfg.TRAIN.RANDOM_SEED) - random.seed(cfg.TRAIN.RANDOM_SEED) - - def _init_fn(worker_id): - np.random.seed(cfg.TRAIN.RANDOM_SEED + worker_id) - - if os.environ.get('ADVENT_DRY_RUN', '0') == '1': - return - - # LOAD SEGMENTATION NET - assert osp.exists(cfg.TRAIN.RESTORE_FROM), f'Missing init model {cfg.TRAIN.RESTORE_FROM}' - if cfg.TRAIN.MODEL == 'DeepLabv2': - model = get_deeplab_v2(num_classes=cfg.NUM_CLASSES, multi_level=cfg.TRAIN.MULTI_LEVEL) - saved_state_dict = torch.load(cfg.TRAIN.RESTORE_FROM) - if 'DeepLab_resnet_pretrained_imagenet' in cfg.TRAIN.RESTORE_FROM: - new_params = model.state_dict().copy() - for i in saved_state_dict: - i_parts = i.split('.') - if not i_parts[1] == 'layer5': - new_params['.'.join(i_parts[1:])] = saved_state_dict[i] - model.load_state_dict(new_params) - else: - model.load_state_dict(saved_state_dict) - else: - raise NotImplementedError(f"Not yet supported {cfg.TRAIN.MODEL}") - print('Model loaded') - - # DATALOADERS - # pdb.set_trace() - easy_dataset = CityscapesDataSet_easy(root=cfg.DATA_DIRECTORY_SOURCE, - list_path=cfg.DATA_LIST_SOURCE, - max_iters=cfg.TRAIN.MAX_ITERS * cfg.TRAIN.BATCH_SIZE_SOURCE * args.world_size, - crop_size=cfg.TRAIN.INPUT_SIZE_SOURCE, - mean=cfg.TRAIN.IMG_MEAN) - if cfg.distributed: - easy_sampler = torch.utils.data.distributed.DistributedSampler(easy_dataset) - easy_loader = data.DataLoader(easy_dataset, - batch_size=cfg.TRAIN.BATCH_SIZE_SOURCE, - num_workers=cfg.NUM_WORKERS, - shuffle=(not cfg.distributed), - pin_memory=False, - sampler=easy_sampler if cfg.distributed else None, - worker_init_fn=_init_fn) - - # pdb.set_trace() - hard_dataset = CityscapesDataSet_hard(root=cfg.DATA_DIRECTORY_TARGET, - list_path=cfg.DATA_LIST_TARGET, - set=cfg.TRAIN.SET_TARGET, - info_path=cfg.TRAIN.INFO_TARGET, - max_iters=cfg.TRAIN.MAX_ITERS * cfg.TRAIN.BATCH_SIZE_TARGET * args.world_size, - crop_size=cfg.TRAIN.INPUT_SIZE_TARGET, - mean=cfg.TRAIN.IMG_MEAN) - if cfg.distributed: - hard_sampler = torch.utils.data.distributed.DistributedSampler(hard_dataset) - hard_loader = data.DataLoader(hard_dataset, - batch_size=cfg.TRAIN.BATCH_SIZE_TARGET, - num_workers=cfg.NUM_WORKERS, - shuffle=(not cfg.distributed), - pin_memory=False, - sampler=hard_sampler if cfg.distributed else None, - worker_init_fn=_init_fn) - - with open(osp.join(cfg.TRAIN.SNAPSHOT_DIR, 'train_cfg.yml'), 'w') as yaml_file: - yaml.dump(cfg, yaml_file, default_flow_style=False) - - # pdb.set_trace() - train_domain_adaptation(model, easy_loader, hard_loader, device, cfg) - - -if __name__ == '__main__': - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = '29688' - main() +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#-------------------------------------------------------------------- +# modified from "ADVENT/advent/scripts/train.py" by Tuan-Hung Vu +#-------------------------------------------------------------------- +import argparse +import os +import os.path as osp +import pprint +import random +import warnings + +import numpy as np +import yaml +import torch +from torch.utils import data + +from advent.model.deeplabv2 import get_deeplab_v2 +from advent.dataset.gta5 import GTA5DataSet +from advent.dataset.cityscapes import CityscapesDataSet as CityscapesDataSet_hard +from cityscapes import CityscapesDataSet as CityscapesDataSet_easy +from advent.domain_adaptation.config import cfg, cfg_from_file +from train_UDA import train_domain_adaptation + + +warnings.filterwarnings("ignore", message="numpy.dtype size changed") +warnings.filterwarnings("ignore") + + +def get_arguments(): + """ + Parse input arguments + """ + parser = argparse.ArgumentParser(description="Code for domain adaptation (DA) training") + parser.add_argument('--cfg', type=str, default=None, + help='optional config file', ) + parser.add_argument("--random-train", action="store_true", + help="not fixing random seed.") + parser.add_argument("--tensorboard", action="store_true", + help="visualize training loss with tensorboardX.") + parser.add_argument("--viz_every_iter", type=int, default=None, + help="visualize results.") + parser.add_argument("--exp-suffix", type=str, default=None, + help="optional experiment suffix") + parser.add_argument('--rank', type=int, default=0) + parser.add_argument('--device_type', type=str, default='npu') + parser.add_argument('--device_id', type=int, ) + parser.add_argument('--world_size', type=int, default=1) + parser.add_argument('--distributed', action='store_true', default=False) + parser.add_argument('--performance_log', action='store_true', default=False) + return parser.parse_args() + + +def main(): + # LOAD ARGS + args = get_arguments() + print('Called with args:') + print(args) + + # pdb.set_trace() + + assert args.cfg is not None, 'Missing cfg file' + cfg_from_file(args.cfg) + cfg.distributed = args.distributed + ddp_backend = "hccl" if args.device_type == "npu" else "nccl" + + if cfg.distributed: + torch.distributed.init_process_group(backend=ddp_backend, world_size=args.world_size, rank=args.rank) + device = torch.device("{}:{}".format(args.device_type ,args.device_id)) + cfg.device_id = args.device_id + cfg.rank = args.rank + cfg.world_size = args.world_size + cfg.device_type = args.device_type + cfg.performance_log = args.performance_log + if args.device_type == 'cuda': + torch.cuda.set_device(args.device_id) + elif args.device_type == 'npu': + torch.npu.set_device(args.device_id) + + cfg.is_master_node = args.world_size == 1 or args.device_id == 0 + + # auto-generate exp name if not specified + if cfg.EXP_NAME == '': + cfg.EXP_NAME = f'{cfg.SOURCE}2{cfg.TARGET}_{cfg.TRAIN.MODEL}_{cfg.TRAIN.DA_METHOD}' + + if args.exp_suffix: + cfg.EXP_NAME += f'_{args.exp_suffix}' + # auto-generate snapshot path if not specified + if cfg.TRAIN.SNAPSHOT_DIR == '': + cfg.TRAIN.SNAPSHOT_DIR = osp.join(cfg.EXP_ROOT_SNAPSHOT, cfg.EXP_NAME) + os.makedirs(cfg.TRAIN.SNAPSHOT_DIR, exist_ok=True) + # tensorboard + if args.tensorboard: + if cfg.TRAIN.TENSORBOARD_LOGDIR == '': + cfg.TRAIN.TENSORBOARD_LOGDIR = osp.join(cfg.EXP_ROOT_LOGS, 'tensorboard', cfg.EXP_NAME) + os.makedirs(cfg.TRAIN.TENSORBOARD_LOGDIR, exist_ok=True) + if args.viz_every_iter is not None: + cfg.TRAIN.TENSORBOARD_VIZRATE = args.viz_every_iter + else: + cfg.TRAIN.TENSORBOARD_LOGDIR = '' + if cfg.is_master_node: + print('Using config:') + pprint.pprint(cfg) + + # INIT + _init_fn = None + if not args.random_train: + torch.manual_seed(cfg.TRAIN.RANDOM_SEED) + if args.device_type == 'cuda': + torch.cuda.manual_seed(cfg.TRAIN.RANDOM_SEED) + elif args.device_type == 'npu': + torch.npu.manual_seed(cfg.TRAIN.RANDOM_SEED) + np.random.seed(cfg.TRAIN.RANDOM_SEED) + random.seed(cfg.TRAIN.RANDOM_SEED) + + def _init_fn(worker_id): + np.random.seed(cfg.TRAIN.RANDOM_SEED + worker_id) + + if os.environ.get('ADVENT_DRY_RUN', '0') == '1': + return + + # LOAD SEGMENTATION NET + assert osp.exists(cfg.TRAIN.RESTORE_FROM), f'Missing init model {cfg.TRAIN.RESTORE_FROM}' + if cfg.TRAIN.MODEL == 'DeepLabv2': + model = get_deeplab_v2(num_classes=cfg.NUM_CLASSES, multi_level=cfg.TRAIN.MULTI_LEVEL) + saved_state_dict = torch.load(cfg.TRAIN.RESTORE_FROM) + if 'DeepLab_resnet_pretrained_imagenet' in cfg.TRAIN.RESTORE_FROM: + new_params = model.state_dict().copy() + for i in saved_state_dict: + i_parts = i.split('.') + if not i_parts[1] == 'layer5': + new_params['.'.join(i_parts[1:])] = saved_state_dict[i] + model.load_state_dict(new_params) + else: + model.load_state_dict(saved_state_dict) + else: + raise NotImplementedError(f"Not yet supported {cfg.TRAIN.MODEL}") + print('Model loaded') + + # DATALOADERS + # pdb.set_trace() + easy_dataset = CityscapesDataSet_easy(root=cfg.DATA_DIRECTORY_SOURCE, + list_path=cfg.DATA_LIST_SOURCE, + max_iters=cfg.TRAIN.MAX_ITERS * cfg.TRAIN.BATCH_SIZE_SOURCE * args.world_size, + crop_size=cfg.TRAIN.INPUT_SIZE_SOURCE, + mean=cfg.TRAIN.IMG_MEAN) + if cfg.distributed: + easy_sampler = torch.utils.data.distributed.DistributedSampler(easy_dataset) + easy_loader = data.DataLoader(easy_dataset, + batch_size=cfg.TRAIN.BATCH_SIZE_SOURCE, + num_workers=cfg.NUM_WORKERS, + shuffle=(not cfg.distributed), + pin_memory=False, + sampler=easy_sampler if cfg.distributed else None, + worker_init_fn=_init_fn) + + # pdb.set_trace() + hard_dataset = CityscapesDataSet_hard(root=cfg.DATA_DIRECTORY_TARGET, + list_path=cfg.DATA_LIST_TARGET, + set=cfg.TRAIN.SET_TARGET, + info_path=cfg.TRAIN.INFO_TARGET, + max_iters=cfg.TRAIN.MAX_ITERS * cfg.TRAIN.BATCH_SIZE_TARGET * args.world_size, + crop_size=cfg.TRAIN.INPUT_SIZE_TARGET, + mean=cfg.TRAIN.IMG_MEAN) + if cfg.distributed: + hard_sampler = torch.utils.data.distributed.DistributedSampler(hard_dataset) + hard_loader = data.DataLoader(hard_dataset, + batch_size=cfg.TRAIN.BATCH_SIZE_TARGET, + num_workers=cfg.NUM_WORKERS, + shuffle=(not cfg.distributed), + pin_memory=False, + sampler=hard_sampler if cfg.distributed else None, + worker_init_fn=_init_fn) + + with open(osp.join(cfg.TRAIN.SNAPSHOT_DIR, 'train_cfg.yml'), 'w') as yaml_file: + yaml.dump(cfg, yaml_file, default_flow_style=False) + + # pdb.set_trace() + train_domain_adaptation(model, easy_loader, hard_loader, device, cfg) + + +if __name__ == '__main__': + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '29688' + main() diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/intrada/train_UDA.py b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/intrada/train_UDA.py index 417abb8798ca32446db271efc7433a4b4844304e..a27de683550f4d570430b737918c8449eabe3b27 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/intrada/train_UDA.py +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/intrada/train_UDA.py @@ -1,469 +1,469 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#-------------------------------------------------------------------- -# modified from "ADVENT/advent/domain_adaptation/train_UDA.py" by Tuan-Hung Vu -#-------------------------------------------------------------------- -import os -import sys -import time -from pathlib import Path - -import os.path as osp -import numpy as np -import torch -#import torch.backends.cudnn as cudnn -import torch.nn.functional as F -import torch.optim as optim -from tensorboardX import SummaryWriter -from torch import nn -from torchvision.utils import make_grid -from tqdm import tqdm -from collections import OrderedDict - -from advent.model.discriminator import get_fc_discriminator -from advent.utils.func import adjust_learning_rate, adjust_learning_rate_discriminator -from advent.utils.func import loss_calc, bce_loss -from advent.utils.loss import entropy_loss -from advent.utils.func import prob_2_entropy -from advent.utils.viz_segmask import colorize_mask - -import apex -from apex import amp - -def load_checkpoint_for_evaluation(model, checkpoint, device): - saved_state_dict = torch.load(checkpoint, map_location="cpu") - new_state_dict = OrderedDict() - for k,v in saved_state_dict.items(): - if k[:7] != "module.": - name = k - else: - name = k[7:] - new_state_dict[name] = v - model.load_state_dict(new_state_dict) - model.eval() - model.to(device) - - -def train_advent(model, trainloader, targetloader, device, cfg): - ''' UDA training with advent - ''' - # Create the model and start the training. - # pdb.set_trace() - input_size_source = cfg.TRAIN.INPUT_SIZE_SOURCE - input_size_target = cfg.TRAIN.INPUT_SIZE_TARGET - # device = cfg.GPU_ID - num_classes = cfg.NUM_CLASSES - viz_tensorboard = os.path.exists(cfg.TRAIN.TENSORBOARD_LOGDIR) - if viz_tensorboard: - writer = SummaryWriter(log_dir=cfg.TRAIN.TENSORBOARD_LOGDIR) - - print(device) - # SEGMNETATION NETWORK - model.train() - model.to(device) - # cudnn.benchmark = True - # cudnn.enabled = True - - # DISCRIMINATOR NETWORK - # feature-level - d_aux = get_fc_discriminator(num_classes=num_classes) - d_aux.train() - d_aux.to(device) - # restore_from = cfg.TRAIN.RESTORE_FROM_aux - # print("Load Discriminator:", restore_from) - # load_checkpoint_for_evaluation(d_aux, restore_from, device) - - - # seg maps, i.e. output, level - d_main = get_fc_discriminator(num_classes=num_classes) - d_main.train() - d_main.to(device) - - # restore_from = cfg.TRAIN.RESTORE_FROM_main - # print("Load Discriminator:", restore_from) - # load_checkpoint_for_evaluation(d_main, restore_from, device) - - # OPTIMIZERS - # segnet's optimizer - optimizer = optim.SGD(model.optim_parameters(cfg.TRAIN.LEARNING_RATE), - lr=cfg.TRAIN.LEARNING_RATE, - momentum=cfg.TRAIN.MOMENTUM, - weight_decay=cfg.TRAIN.WEIGHT_DECAY) - model, optimizer = amp.initialize(model, optimizer, opt_level="O0",loss_scale=128.0) - if cfg.distributed: - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[cfg.device_id], find_unused_parameters=True) - - # discriminators' optimizers - optimizer_d_aux = optim.Adam(d_aux.parameters(), lr=cfg.TRAIN.LEARNING_RATE_D, - betas=(0.9, 0.99)) - optimizer_d_main = optim.Adam(d_main.parameters(), lr=cfg.TRAIN.LEARNING_RATE_D, - betas=(0.9, 0.99)) - d_aux, optimizer_d_aux = amp.initialize(d_aux, optimizer_d_aux, opt_level="O0",loss_scale=128.0) - d_main, optimizer_d_main = amp.initialize(d_main, optimizer_d_main, opt_level="O0",loss_scale=128.0) - if cfg.distributed: - d_aux = torch.nn.parallel.DistributedDataParallel(d_aux, device_ids=[cfg.device_id],find_unused_parameters=True) - d_main = torch.nn.parallel.DistributedDataParallel(d_main, device_ids=[cfg.device_id], find_unused_parameters=True) - - # interpolate output segmaps - interp = nn.Upsample(size=(input_size_source[1], input_size_source[0]), mode='bilinear', - align_corners=True) - interp_target = nn.Upsample(size=(input_size_target[1], input_size_target[0]), mode='bilinear', - align_corners=True) - - # labels for adversarial training - source_label = 0 - target_label = 1 - trainloader_iter = enumerate(trainloader) - targetloader_iter = enumerate(targetloader) - for i_iter in tqdm(range(cfg.TRAIN.EARLY_STOP)): - - # reset optimizers - optimizer.zero_grad() - optimizer_d_aux.zero_grad() - optimizer_d_main.zero_grad() - # adapt LR if needed - adjust_learning_rate(optimizer, i_iter, cfg) - adjust_learning_rate_discriminator(optimizer_d_aux, i_iter, cfg) - adjust_learning_rate_discriminator(optimizer_d_main, i_iter, cfg) - - # UDA Training - # only train segnet. Don't accumulate grads in disciminators - for param in d_aux.parameters(): - param.requires_grad = False - for param in d_main.parameters(): - param.requires_grad = False - # train on source - _, batch = trainloader_iter.__next__() - images_source, labels, _, _ = batch - images_source, labels = images_source.to(device), labels.to(device) - # debug: - # labels=labels.numpy() - # from matplotlib import pyplot as plt - # import numpy as np - # plt.figure(1), plt.imshow(labels[0]), plt.ion(), plt.colorbar(), plt.show() - pred_src_aux, pred_src_main = model(images_source) - if cfg.TRAIN.MULTI_LEVEL: - pred_src_aux = interp(pred_src_aux) - loss_seg_src_aux = loss_calc(pred_src_aux, labels, device) - else: - loss_seg_src_aux = 0 - pred_src_main = interp(pred_src_main) - loss_seg_src_main = loss_calc(pred_src_main, labels, device) - # pdb.set_trace() - loss = (cfg.TRAIN.LAMBDA_SEG_MAIN * loss_seg_src_main - + cfg.TRAIN.LAMBDA_SEG_AUX * loss_seg_src_aux) - #loss.backward() - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - - # adversarial training ot fool the discriminator - _, batch = targetloader_iter.__next__() - images, _, _, _ = batch - images = images.to(device) - pred_trg_aux, pred_trg_main = model(images) - if cfg.TRAIN.MULTI_LEVEL: - pred_trg_aux = interp_target(pred_trg_aux) - d_out_aux = d_aux(prob_2_entropy(F.softmax(pred_trg_aux))) - loss_adv_trg_aux = bce_loss(d_out_aux, source_label) - else: - loss_adv_trg_aux = 0 - pred_trg_main = interp_target(pred_trg_main) - d_out_main = d_main(prob_2_entropy(F.softmax(pred_trg_main))) - loss_adv_trg_main = bce_loss(d_out_main, source_label) - loss = (cfg.TRAIN.LAMBDA_ADV_MAIN * loss_adv_trg_main - + cfg.TRAIN.LAMBDA_ADV_AUX * loss_adv_trg_aux) - loss = loss - #loss.backward() - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - - # Train discriminator networks - # enable training mode on discriminator networks - for param in d_aux.parameters(): - param.requires_grad = True - for param in d_main.parameters(): - param.requires_grad = True - # train with source - if cfg.TRAIN.MULTI_LEVEL: - pred_src_aux = pred_src_aux.detach() - d_out_aux = d_aux(prob_2_entropy(F.softmax(pred_src_aux))) - loss_d_aux = bce_loss(d_out_aux, source_label) - loss_d_aux = loss_d_aux / 2 - with amp.scale_loss(loss_d_aux, optimizer_d_aux) as scaled_loss: - scaled_loss.backward() - # loss_d_aux.backward() - pred_src_main = pred_src_main.detach() - d_out_main = d_main(prob_2_entropy(F.softmax(pred_src_main))) - loss_d_main = bce_loss(d_out_main, source_label) - loss_d_main = loss_d_main / 2 - #loss_d_main.backward() - with amp.scale_loss(loss_d_main, optimizer_d_main) as scaled_loss: - scaled_loss.backward() - - # train with target - if cfg.TRAIN.MULTI_LEVEL: - pred_trg_aux = pred_trg_aux.detach() - d_out_aux = d_aux(prob_2_entropy(F.softmax(pred_trg_aux))) - loss_d_aux = bce_loss(d_out_aux, target_label) - loss_d_aux = loss_d_aux / 2 - #loss_d_aux.backward() - with amp.scale_loss(loss_d_aux, optimizer_d_aux) as scaled_loss: - scaled_loss.backward() - else: - loss_d_aux = 0 - pred_trg_main = pred_trg_main.detach() - d_out_main = d_main(prob_2_entropy(F.softmax(pred_trg_main))) - loss_d_main = bce_loss(d_out_main, target_label) - loss_d_main = loss_d_main / 2 - #loss_d_main.backward() - with amp.scale_loss(loss_d_main, optimizer_d_main) as scaled_loss: - scaled_loss.backward() - - optimizer.step() - if cfg.TRAIN.MULTI_LEVEL: - optimizer_d_aux.step() - optimizer_d_main.step() - - current_losses = {'loss_seg_src_aux': loss_seg_src_aux, - 'loss_seg_src_main': loss_seg_src_main, - 'loss_adv_trg_aux': loss_adv_trg_aux, - 'loss_adv_trg_main': loss_adv_trg_main, - 'loss_d_aux': loss_d_aux, - 'loss_d_main': loss_d_main} - print_losses(current_losses, i_iter) - - if i_iter % cfg.TRAIN.SAVE_PRED_EVERY == 0 and i_iter != 0 and cfg.rank == 0: - print('taking snapshot ...') - print('exp =', cfg.TRAIN.SNAPSHOT_DIR) - snapshot_dir = Path(cfg.TRAIN.SNAPSHOT_DIR) - torch.save(model.state_dict(), snapshot_dir / f'model_{i_iter}.pth') - torch.save(d_aux.state_dict(), snapshot_dir / f'model_{i_iter}_D_aux.pth') - torch.save(d_main.state_dict(), snapshot_dir / f'model_{i_iter}_D_main.pth') - if i_iter >= cfg.TRAIN.EARLY_STOP - 1: - break - sys.stdout.flush() - - # Visualize with tensorboard - if viz_tensorboard: - log_losses_tensorboard(writer, current_losses, i_iter) - - if i_iter % cfg.TRAIN.TENSORBOARD_VIZRATE == cfg.TRAIN.TENSORBOARD_VIZRATE - 1: - draw_in_tensorboard(writer, images, i_iter, pred_trg_main, num_classes, 'T') - draw_in_tensorboard(writer, images_source, i_iter, pred_src_main, num_classes, 'S') - - -def draw_in_tensorboard(writer, images, i_iter, pred_main, num_classes, type_): - grid_image = make_grid(images[:3].clone().cpu().data, 3, normalize=True) - writer.add_image(f'Image - {type_}', grid_image, i_iter) - - grid_image = make_grid(torch.from_numpy(np.array(colorize_mask(np.asarray( - np.argmax(F.softmax(pred_main).cpu().data[0].numpy().transpose(1, 2, 0), - axis=2), dtype=np.uint8)).convert('RGB')).transpose(2, 0, 1)), 3, - normalize=False, range=(0, 255)) - writer.add_image(f'Prediction - {type_}', grid_image, i_iter) - - output_sm = F.softmax(pred_main).cpu().data[0].numpy().transpose(1, 2, 0) - output_ent = np.sum(-np.multiply(output_sm, np.log2(output_sm)), axis=2, - keepdims=False) - grid_image = make_grid(torch.from_numpy(output_ent), 3, normalize=True, - range=(0, np.log2(num_classes))) - writer.add_image(f'Entropy - {type_}', grid_image, i_iter) - - -def train_minent(model, trainloader, targetloader, device, cfg): - ''' UDA training with minEnt - ''' - # Create the model and start the training. - input_size_source = cfg.TRAIN.INPUT_SIZE_SOURCE - input_size_target = cfg.TRAIN.INPUT_SIZE_TARGET - # device = cfg.GPU_ID - num_classes = cfg.NUM_CLASSES - viz_tensorboard = os.path.exists(cfg.TRAIN.TENSORBOARD_LOGDIR) - if viz_tensorboard: - writer = SummaryWriter(log_dir=cfg.TRAIN.TENSORBOARD_LOGDIR) - - # SEGMNETATION NETWORK - model.train() - model.to(device) - # cudnn.benchmark = True - # cudnn.enabled = True - - # OPTIMIZERS - # segnet's optimizer - # optimizer_fn = apex.optimizers.NpuFusedSGD if cfg.device_type == 'npu' else optim.SGD - optimizer_fn = optim.SGD - optimizer = optimizer_fn(model.optim_parameters(cfg.TRAIN.LEARNING_RATE), - lr=cfg.TRAIN.LEARNING_RATE, - momentum=cfg.TRAIN.MOMENTUM, - weight_decay=cfg.TRAIN.WEIGHT_DECAY) - - model, optimizer = amp.initialize(model, optimizer, opt_level='O2',loss_scale=128.0) - - if cfg.distributed: - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[cfg.device_id]) - - # interpolate output segmaps - interp = nn.Upsample(size=(input_size_source[1], input_size_source[0]), mode='bilinear', - align_corners=True) - interp_target = nn.Upsample(size=(input_size_target[1], input_size_target[0]), mode='bilinear', - align_corners=True) - - trainloader_iter = enumerate(trainloader) - targetloader_iter = enumerate(targetloader) - - # FPS statistics - time_meter = AverageMeter(name='time_avg') - num_devices = cfg.world_size - batch_size = cfg.TRAIN.BATCH_SIZE_SOURCE - - for i_iter in tqdm(range(cfg.TRAIN.EARLY_STOP)): - - # time start - time_start = time.time() - - # reset optimizers - optimizer.zero_grad() - - # adapt LR if needed - adjust_learning_rate(optimizer, i_iter, cfg) - - # UDA Training - # train on source - _, batch = trainloader_iter.__next__() - images_source, labels, _, _ = batch - images_source, labels = images_source.to(device), labels.to(device) - pred_src_aux, pred_src_main = model(images_source) - if cfg.TRAIN.MULTI_LEVEL: - pred_src_aux = interp(pred_src_aux) - loss_seg_src_aux = loss_calc(pred_src_aux, labels, device) - else: - loss_seg_src_aux = 0 - pred_src_main = interp(pred_src_main) - loss_seg_src_main = loss_calc(pred_src_main, labels, device) - loss = (cfg.TRAIN.LAMBDA_SEG_MAIN * loss_seg_src_main - + cfg.TRAIN.LAMBDA_SEG_AUX * loss_seg_src_aux) - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - # loss.backward() - - # adversarial training with minent - _, batch = targetloader_iter.__next__() - images, _, _, _ = batch - images = images.to(device) - pred_trg_aux, pred_trg_main = model(images) - pred_trg_aux = interp_target(pred_trg_aux) - pred_trg_main = interp_target(pred_trg_main) - pred_prob_trg_aux = F.softmax(pred_trg_aux) - pred_prob_trg_main = F.softmax(pred_trg_main) - - loss_target_entp_aux = entropy_loss(pred_prob_trg_aux) - loss_target_entp_main = entropy_loss(pred_prob_trg_main) - loss = (cfg.TRAIN.LAMBDA_ENT_AUX * loss_target_entp_aux - + cfg.TRAIN.LAMBDA_ENT_MAIN * loss_target_entp_main) - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - # loss.backward() - optimizer.step() - - # update time statistics - time_cost = time.time() - time_start - time_meter.update(time_cost) - - current_losses = {'loss_seg_src_aux': loss_seg_src_aux, - 'loss_seg_src_main': loss_seg_src_main, - 'loss_ent_aux': loss_target_entp_aux, - 'loss_ent_main': loss_target_entp_main, - 'FPS': num_devices * batch_size / time_meter.avg if time_meter.avg > 1e-6 else -1} - - if cfg.is_master_node: - print_losses(current_losses, i_iter) - - if i_iter % cfg.TRAIN.SAVE_PRED_EVERY == 0 and i_iter != 0 and cfg.is_master_node: - print('taking snapshot ...') - print('exp =', cfg.TRAIN.SNAPSHOT_DIR) - torch.save(model.state_dict(), - osp.join(cfg.TRAIN.SNAPSHOT_DIR, f'model_{i_iter}.pth')) - if i_iter >= cfg.TRAIN.EARLY_STOP - 1: - break - sys.stdout.flush() - - # Visualize with tensorboard - if viz_tensorboard: - log_losses_tensorboard(writer, current_losses, i_iter) - - if i_iter % cfg.TRAIN.TENSORBOARD_VIZRATE == cfg.TRAIN.TENSORBOARD_VIZRATE - 1: - draw_in_tensorboard(writer, images, i_iter, pred_trg_main, num_classes, 'T') - draw_in_tensorboard(writer, images_source, i_iter, pred_src_main, num_classes, 'S') - - -def print_losses(current_losses, i_iter): - list_strings = [] - for loss_name, loss_value in current_losses.items(): - list_strings.append(f'{loss_name} = {to_numpy(loss_value):.3f} ') - full_string = ' '.join(list_strings) - tqdm.write(f'iter = {i_iter} {full_string}') - - -def log_losses_tensorboard(writer, current_losses, i_iter): - for loss_name, loss_value in current_losses.items(): - writer.add_scalar(f'data/{loss_name}', to_numpy(loss_value), i_iter) - - -def to_numpy(tensor): - if isinstance(tensor, (int, float)): - return tensor - else: - return tensor.data.cpu().numpy() - - -def train_domain_adaptation(model, trainloader, targetloader, device, cfg): - if cfg.TRAIN.DA_METHOD == 'MinEnt': - if cfg.performance_log: - cfg.TRAIN.EARLY_STOP = 500 - train_minent(model, trainloader, targetloader, device, cfg) - elif cfg.TRAIN.DA_METHOD == 'AdvEnt': - train_advent(model, trainloader, targetloader, device, cfg) - else: - raise NotImplementedError(f"Not yet supported DA method {cfg.TRAIN.DA_METHOD}") - - -class AverageMeter(object): - """Computes and stores the average and current value""" - - def __init__(self, name, fmt=':f', start_count_index=10): - self.name = name - self.fmt = fmt - self.reset() - self.start_count_index = start_count_index - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - - def update(self, val, n=1): - if self.count == 0: - self.N = n - - self.val = val - self.count += n - if self.count > (self.start_count_index * self.N): - self.sum += val * n - self.avg = self.sum / (self.count - self.start_count_index * self.N) - - def __str__(self): - fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' - return fmtstr.format(**self.__dict__) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#-------------------------------------------------------------------- +# modified from "ADVENT/advent/domain_adaptation/train_UDA.py" by Tuan-Hung Vu +#-------------------------------------------------------------------- +import os +import sys +import time +from pathlib import Path + +import os.path as osp +import numpy as np +import torch +#import torch.backends.cudnn as cudnn +import torch.nn.functional as F +import torch.optim as optim +from tensorboardX import SummaryWriter +from torch import nn +from torchvision.utils import make_grid +from tqdm import tqdm +from collections import OrderedDict + +from advent.model.discriminator import get_fc_discriminator +from advent.utils.func import adjust_learning_rate, adjust_learning_rate_discriminator +from advent.utils.func import loss_calc, bce_loss +from advent.utils.loss import entropy_loss +from advent.utils.func import prob_2_entropy +from advent.utils.viz_segmask import colorize_mask + +import apex +from apex import amp + +def load_checkpoint_for_evaluation(model, checkpoint, device): + saved_state_dict = torch.load(checkpoint, map_location="cpu") + new_state_dict = OrderedDict() + for k,v in saved_state_dict.items(): + if k[:7] != "module.": + name = k + else: + name = k[7:] + new_state_dict[name] = v + model.load_state_dict(new_state_dict) + model.eval() + model.to(device) + + +def train_advent(model, trainloader, targetloader, device, cfg): + ''' UDA training with advent + ''' + # Create the model and start the training. + # pdb.set_trace() + input_size_source = cfg.TRAIN.INPUT_SIZE_SOURCE + input_size_target = cfg.TRAIN.INPUT_SIZE_TARGET + # device = cfg.GPU_ID + num_classes = cfg.NUM_CLASSES + viz_tensorboard = os.path.exists(cfg.TRAIN.TENSORBOARD_LOGDIR) + if viz_tensorboard: + writer = SummaryWriter(log_dir=cfg.TRAIN.TENSORBOARD_LOGDIR) + + print(device) + # SEGMNETATION NETWORK + model.train() + model.to(device) + # cudnn.benchmark = True + # cudnn.enabled = True + + # DISCRIMINATOR NETWORK + # feature-level + d_aux = get_fc_discriminator(num_classes=num_classes) + d_aux.train() + d_aux.to(device) + # restore_from = cfg.TRAIN.RESTORE_FROM_aux + # print("Load Discriminator:", restore_from) + # load_checkpoint_for_evaluation(d_aux, restore_from, device) + + + # seg maps, i.e. output, level + d_main = get_fc_discriminator(num_classes=num_classes) + d_main.train() + d_main.to(device) + + # restore_from = cfg.TRAIN.RESTORE_FROM_main + # print("Load Discriminator:", restore_from) + # load_checkpoint_for_evaluation(d_main, restore_from, device) + + # OPTIMIZERS + # segnet's optimizer + optimizer = optim.SGD(model.optim_parameters(cfg.TRAIN.LEARNING_RATE), + lr=cfg.TRAIN.LEARNING_RATE, + momentum=cfg.TRAIN.MOMENTUM, + weight_decay=cfg.TRAIN.WEIGHT_DECAY) + model, optimizer = amp.initialize(model, optimizer, opt_level="O0",loss_scale=128.0) + if cfg.distributed: + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[cfg.device_id], find_unused_parameters=True) + + # discriminators' optimizers + optimizer_d_aux = optim.Adam(d_aux.parameters(), lr=cfg.TRAIN.LEARNING_RATE_D, + betas=(0.9, 0.99)) + optimizer_d_main = optim.Adam(d_main.parameters(), lr=cfg.TRAIN.LEARNING_RATE_D, + betas=(0.9, 0.99)) + d_aux, optimizer_d_aux = amp.initialize(d_aux, optimizer_d_aux, opt_level="O0",loss_scale=128.0) + d_main, optimizer_d_main = amp.initialize(d_main, optimizer_d_main, opt_level="O0",loss_scale=128.0) + if cfg.distributed: + d_aux = torch.nn.parallel.DistributedDataParallel(d_aux, device_ids=[cfg.device_id],find_unused_parameters=True) + d_main = torch.nn.parallel.DistributedDataParallel(d_main, device_ids=[cfg.device_id], find_unused_parameters=True) + + # interpolate output segmaps + interp = nn.Upsample(size=(input_size_source[1], input_size_source[0]), mode='bilinear', + align_corners=True) + interp_target = nn.Upsample(size=(input_size_target[1], input_size_target[0]), mode='bilinear', + align_corners=True) + + # labels for adversarial training + source_label = 0 + target_label = 1 + trainloader_iter = enumerate(trainloader) + targetloader_iter = enumerate(targetloader) + for i_iter in tqdm(range(cfg.TRAIN.EARLY_STOP)): + + # reset optimizers + optimizer.zero_grad() + optimizer_d_aux.zero_grad() + optimizer_d_main.zero_grad() + # adapt LR if needed + adjust_learning_rate(optimizer, i_iter, cfg) + adjust_learning_rate_discriminator(optimizer_d_aux, i_iter, cfg) + adjust_learning_rate_discriminator(optimizer_d_main, i_iter, cfg) + + # UDA Training + # only train segnet. Don't accumulate grads in disciminators + for param in d_aux.parameters(): + param.requires_grad = False + for param in d_main.parameters(): + param.requires_grad = False + # train on source + _, batch = trainloader_iter.__next__() + images_source, labels, _, _ = batch + images_source, labels = images_source.to(device), labels.to(device) + # debug: + # labels=labels.numpy() + # from matplotlib import pyplot as plt + # import numpy as np + # plt.figure(1), plt.imshow(labels[0]), plt.ion(), plt.colorbar(), plt.show() + pred_src_aux, pred_src_main = model(images_source) + if cfg.TRAIN.MULTI_LEVEL: + pred_src_aux = interp(pred_src_aux) + loss_seg_src_aux = loss_calc(pred_src_aux, labels, device) + else: + loss_seg_src_aux = 0 + pred_src_main = interp(pred_src_main) + loss_seg_src_main = loss_calc(pred_src_main, labels, device) + # pdb.set_trace() + loss = (cfg.TRAIN.LAMBDA_SEG_MAIN * loss_seg_src_main + + cfg.TRAIN.LAMBDA_SEG_AUX * loss_seg_src_aux) + #loss.backward() + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + + # adversarial training ot fool the discriminator + _, batch = targetloader_iter.__next__() + images, _, _, _ = batch + images = images.to(device) + pred_trg_aux, pred_trg_main = model(images) + if cfg.TRAIN.MULTI_LEVEL: + pred_trg_aux = interp_target(pred_trg_aux) + d_out_aux = d_aux(prob_2_entropy(F.softmax(pred_trg_aux))) + loss_adv_trg_aux = bce_loss(d_out_aux, source_label) + else: + loss_adv_trg_aux = 0 + pred_trg_main = interp_target(pred_trg_main) + d_out_main = d_main(prob_2_entropy(F.softmax(pred_trg_main))) + loss_adv_trg_main = bce_loss(d_out_main, source_label) + loss = (cfg.TRAIN.LAMBDA_ADV_MAIN * loss_adv_trg_main + + cfg.TRAIN.LAMBDA_ADV_AUX * loss_adv_trg_aux) + loss = loss + #loss.backward() + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + + # Train discriminator networks + # enable training mode on discriminator networks + for param in d_aux.parameters(): + param.requires_grad = True + for param in d_main.parameters(): + param.requires_grad = True + # train with source + if cfg.TRAIN.MULTI_LEVEL: + pred_src_aux = pred_src_aux.detach() + d_out_aux = d_aux(prob_2_entropy(F.softmax(pred_src_aux))) + loss_d_aux = bce_loss(d_out_aux, source_label) + loss_d_aux = loss_d_aux / 2 + with amp.scale_loss(loss_d_aux, optimizer_d_aux) as scaled_loss: + scaled_loss.backward() + # loss_d_aux.backward() + pred_src_main = pred_src_main.detach() + d_out_main = d_main(prob_2_entropy(F.softmax(pred_src_main))) + loss_d_main = bce_loss(d_out_main, source_label) + loss_d_main = loss_d_main / 2 + #loss_d_main.backward() + with amp.scale_loss(loss_d_main, optimizer_d_main) as scaled_loss: + scaled_loss.backward() + + # train with target + if cfg.TRAIN.MULTI_LEVEL: + pred_trg_aux = pred_trg_aux.detach() + d_out_aux = d_aux(prob_2_entropy(F.softmax(pred_trg_aux))) + loss_d_aux = bce_loss(d_out_aux, target_label) + loss_d_aux = loss_d_aux / 2 + #loss_d_aux.backward() + with amp.scale_loss(loss_d_aux, optimizer_d_aux) as scaled_loss: + scaled_loss.backward() + else: + loss_d_aux = 0 + pred_trg_main = pred_trg_main.detach() + d_out_main = d_main(prob_2_entropy(F.softmax(pred_trg_main))) + loss_d_main = bce_loss(d_out_main, target_label) + loss_d_main = loss_d_main / 2 + #loss_d_main.backward() + with amp.scale_loss(loss_d_main, optimizer_d_main) as scaled_loss: + scaled_loss.backward() + + optimizer.step() + if cfg.TRAIN.MULTI_LEVEL: + optimizer_d_aux.step() + optimizer_d_main.step() + + current_losses = {'loss_seg_src_aux': loss_seg_src_aux, + 'loss_seg_src_main': loss_seg_src_main, + 'loss_adv_trg_aux': loss_adv_trg_aux, + 'loss_adv_trg_main': loss_adv_trg_main, + 'loss_d_aux': loss_d_aux, + 'loss_d_main': loss_d_main} + print_losses(current_losses, i_iter) + + if i_iter % cfg.TRAIN.SAVE_PRED_EVERY == 0 and i_iter != 0 and cfg.rank == 0: + print('taking snapshot ...') + print('exp =', cfg.TRAIN.SNAPSHOT_DIR) + snapshot_dir = Path(cfg.TRAIN.SNAPSHOT_DIR) + torch.save(model.state_dict(), snapshot_dir / f'model_{i_iter}.pth') + torch.save(d_aux.state_dict(), snapshot_dir / f'model_{i_iter}_D_aux.pth') + torch.save(d_main.state_dict(), snapshot_dir / f'model_{i_iter}_D_main.pth') + if i_iter >= cfg.TRAIN.EARLY_STOP - 1: + break + sys.stdout.flush() + + # Visualize with tensorboard + if viz_tensorboard: + log_losses_tensorboard(writer, current_losses, i_iter) + + if i_iter % cfg.TRAIN.TENSORBOARD_VIZRATE == cfg.TRAIN.TENSORBOARD_VIZRATE - 1: + draw_in_tensorboard(writer, images, i_iter, pred_trg_main, num_classes, 'T') + draw_in_tensorboard(writer, images_source, i_iter, pred_src_main, num_classes, 'S') + + +def draw_in_tensorboard(writer, images, i_iter, pred_main, num_classes, type_): + grid_image = make_grid(images[:3].clone().cpu().data, 3, normalize=True) + writer.add_image(f'Image - {type_}', grid_image, i_iter) + + grid_image = make_grid(torch.from_numpy(np.array(colorize_mask(np.asarray( + np.argmax(F.softmax(pred_main).cpu().data[0].numpy().transpose(1, 2, 0), + axis=2), dtype=np.uint8)).convert('RGB')).transpose(2, 0, 1)), 3, + normalize=False, range=(0, 255)) + writer.add_image(f'Prediction - {type_}', grid_image, i_iter) + + output_sm = F.softmax(pred_main).cpu().data[0].numpy().transpose(1, 2, 0) + output_ent = np.sum(-np.multiply(output_sm, np.log2(output_sm)), axis=2, + keepdims=False) + grid_image = make_grid(torch.from_numpy(output_ent), 3, normalize=True, + range=(0, np.log2(num_classes))) + writer.add_image(f'Entropy - {type_}', grid_image, i_iter) + + +def train_minent(model, trainloader, targetloader, device, cfg): + ''' UDA training with minEnt + ''' + # Create the model and start the training. + input_size_source = cfg.TRAIN.INPUT_SIZE_SOURCE + input_size_target = cfg.TRAIN.INPUT_SIZE_TARGET + # device = cfg.GPU_ID + num_classes = cfg.NUM_CLASSES + viz_tensorboard = os.path.exists(cfg.TRAIN.TENSORBOARD_LOGDIR) + if viz_tensorboard: + writer = SummaryWriter(log_dir=cfg.TRAIN.TENSORBOARD_LOGDIR) + + # SEGMNETATION NETWORK + model.train() + model.to(device) + # cudnn.benchmark = True + # cudnn.enabled = True + + # OPTIMIZERS + # segnet's optimizer + # optimizer_fn = apex.optimizers.NpuFusedSGD if cfg.device_type == 'npu' else optim.SGD + optimizer_fn = optim.SGD + optimizer = optimizer_fn(model.optim_parameters(cfg.TRAIN.LEARNING_RATE), + lr=cfg.TRAIN.LEARNING_RATE, + momentum=cfg.TRAIN.MOMENTUM, + weight_decay=cfg.TRAIN.WEIGHT_DECAY) + + model, optimizer = amp.initialize(model, optimizer, opt_level='O2',loss_scale=128.0) + + if cfg.distributed: + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[cfg.device_id]) + + # interpolate output segmaps + interp = nn.Upsample(size=(input_size_source[1], input_size_source[0]), mode='bilinear', + align_corners=True) + interp_target = nn.Upsample(size=(input_size_target[1], input_size_target[0]), mode='bilinear', + align_corners=True) + + trainloader_iter = enumerate(trainloader) + targetloader_iter = enumerate(targetloader) + + # FPS statistics + time_meter = AverageMeter(name='time_avg') + num_devices = cfg.world_size + batch_size = cfg.TRAIN.BATCH_SIZE_SOURCE + + for i_iter in tqdm(range(cfg.TRAIN.EARLY_STOP)): + + # time start + time_start = time.time() + + # reset optimizers + optimizer.zero_grad() + + # adapt LR if needed + adjust_learning_rate(optimizer, i_iter, cfg) + + # UDA Training + # train on source + _, batch = trainloader_iter.__next__() + images_source, labels, _, _ = batch + images_source, labels = images_source.to(device), labels.to(device) + pred_src_aux, pred_src_main = model(images_source) + if cfg.TRAIN.MULTI_LEVEL: + pred_src_aux = interp(pred_src_aux) + loss_seg_src_aux = loss_calc(pred_src_aux, labels, device) + else: + loss_seg_src_aux = 0 + pred_src_main = interp(pred_src_main) + loss_seg_src_main = loss_calc(pred_src_main, labels, device) + loss = (cfg.TRAIN.LAMBDA_SEG_MAIN * loss_seg_src_main + + cfg.TRAIN.LAMBDA_SEG_AUX * loss_seg_src_aux) + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + # loss.backward() + + # adversarial training with minent + _, batch = targetloader_iter.__next__() + images, _, _, _ = batch + images = images.to(device) + pred_trg_aux, pred_trg_main = model(images) + pred_trg_aux = interp_target(pred_trg_aux) + pred_trg_main = interp_target(pred_trg_main) + pred_prob_trg_aux = F.softmax(pred_trg_aux) + pred_prob_trg_main = F.softmax(pred_trg_main) + + loss_target_entp_aux = entropy_loss(pred_prob_trg_aux) + loss_target_entp_main = entropy_loss(pred_prob_trg_main) + loss = (cfg.TRAIN.LAMBDA_ENT_AUX * loss_target_entp_aux + + cfg.TRAIN.LAMBDA_ENT_MAIN * loss_target_entp_main) + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + # loss.backward() + optimizer.step() + + # update time statistics + time_cost = time.time() - time_start + time_meter.update(time_cost) + + current_losses = {'loss_seg_src_aux': loss_seg_src_aux, + 'loss_seg_src_main': loss_seg_src_main, + 'loss_ent_aux': loss_target_entp_aux, + 'loss_ent_main': loss_target_entp_main, + 'FPS': num_devices * batch_size / time_meter.avg if time_meter.avg > 1e-6 else -1} + + if cfg.is_master_node: + print_losses(current_losses, i_iter) + + if i_iter % cfg.TRAIN.SAVE_PRED_EVERY == 0 and i_iter != 0 and cfg.is_master_node: + print('taking snapshot ...') + print('exp =', cfg.TRAIN.SNAPSHOT_DIR) + torch.save(model.state_dict(), + osp.join(cfg.TRAIN.SNAPSHOT_DIR, f'model_{i_iter}.pth')) + if i_iter >= cfg.TRAIN.EARLY_STOP - 1: + break + sys.stdout.flush() + + # Visualize with tensorboard + if viz_tensorboard: + log_losses_tensorboard(writer, current_losses, i_iter) + + if i_iter % cfg.TRAIN.TENSORBOARD_VIZRATE == cfg.TRAIN.TENSORBOARD_VIZRATE - 1: + draw_in_tensorboard(writer, images, i_iter, pred_trg_main, num_classes, 'T') + draw_in_tensorboard(writer, images_source, i_iter, pred_src_main, num_classes, 'S') + + +def print_losses(current_losses, i_iter): + list_strings = [] + for loss_name, loss_value in current_losses.items(): + list_strings.append(f'{loss_name} = {to_numpy(loss_value):.3f} ') + full_string = ' '.join(list_strings) + tqdm.write(f'iter = {i_iter} {full_string}') + + +def log_losses_tensorboard(writer, current_losses, i_iter): + for loss_name, loss_value in current_losses.items(): + writer.add_scalar(f'data/{loss_name}', to_numpy(loss_value), i_iter) + + +def to_numpy(tensor): + if isinstance(tensor, (int, float)): + return tensor + else: + return tensor.data.cpu().numpy() + + +def train_domain_adaptation(model, trainloader, targetloader, device, cfg): + if cfg.TRAIN.DA_METHOD == 'MinEnt': + if cfg.performance_log: + cfg.TRAIN.EARLY_STOP = 500 + train_minent(model, trainloader, targetloader, device, cfg) + elif cfg.TRAIN.DA_METHOD == 'AdvEnt': + train_advent(model, trainloader, targetloader, device, cfg) + else: + raise NotImplementedError(f"Not yet supported DA method {cfg.TRAIN.DA_METHOD}") + + +class AverageMeter(object): + """Computes and stores the average and current value""" + + def __init__(self, name, fmt=':f', start_count_index=10): + self.name = name + self.fmt = fmt + self.reset() + self.start_count_index = start_count_index + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + if self.count == 0: + self.N = n + + self.val = val + self.count += n + if self.count > (self.start_count_index * self.N): + self.sum += val * n + self.avg = self.sum / (self.count - self.start_count_index * self.N) + + def __str__(self): + fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' + return fmtstr.format(**self.__dict__) diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/modelzoo_level.txt b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/modelzoo_level.txt +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/requirements.txt b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/requirements.txt index e427e81e69ce3e849d80fbc605484a8b3b48471e..5abfd47cd40ccd92fff6a47601041a14052295ae 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/IntraDA/requirements.txt +++ b/PyTorch/contrib/cv/semantic_segmentation/IntraDA/requirements.txt @@ -1,4 +1,4 @@ -#torch==1.5.0 -#torchvision==0.6.0 - - +#torch==1.5.0 +#torchvision==0.6.0 + + diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/createTrainIdLabelImgs.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/createTrainIdLabelImgs.py index dc521ade892a8ec2f995ebc923144965eb3160b9..d9b7bde86c12c00613634cfb76cff3c9530634a2 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/PointRend/createTrainIdLabelImgs.py +++ b/PyTorch/contrib/cv/semantic_segmentation/PointRend/createTrainIdLabelImgs.py @@ -1,71 +1,71 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import print_function, absolute_import, division -import os, glob, sys - -# cityscapes imports -from cityscapesscripts.helpers.csHelpers import printError -from cityscapesscripts.preparation.json2instanceImg import json2instanceImg - - -# The main method -def main(data_path): - # Where to look for Cityscapes - cityscapesPath = data_path - # how to search for all ground truth - searchFine = os.path.join( cityscapesPath , "gtFine" , "*" , "*" , "*_gt*_polygons.json" ) - searchCoarse = os.path.join( cityscapesPath , "gtCoarse" , "*" , "*" , "*_gt*_polygons.json" ) - - # search files - filesFine = glob.glob( searchFine ) - filesFine.sort() - filesCoarse = glob.glob( searchCoarse ) - filesCoarse.sort() - - # concatenate fine and coarse - files = filesFine + filesCoarse - # files = filesFine # use this line if fine is enough for now. - - # quit if we did not find anything - if not files: - printError( "Did not find any files. Please consult the README." ) - - # a bit verbose - print("Processing {} annotation files".format(len(files))) - - # iterate through files - progress = 0 - print("Progress: {:>3} %".format( progress * 100 / len(files) ), end=' ') - for f in files: - # create the output filename - dst = f.replace( "_polygons.json" , "_instanceTrainIds.png" ) - - # do the conversion - try: - json2instanceImg( f , dst , "trainIds" ) - except: - print("Failed to convert: {}".format(f)) - raise - - # status - progress += 1 - print("\rProgress: {:>3} %".format( progress * 100 / len(files) ), end=' ') - sys.stdout.flush() - - -# call the main -if __name__ == "__main__": - data_path = sys.argv[1] +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import print_function, absolute_import, division +import os, glob, sys + +# cityscapes imports +from cityscapesscripts.helpers.csHelpers import printError +from cityscapesscripts.preparation.json2instanceImg import json2instanceImg + + +# The main method +def main(data_path): + # Where to look for Cityscapes + cityscapesPath = data_path + # how to search for all ground truth + searchFine = os.path.join( cityscapesPath , "gtFine" , "*" , "*" , "*_gt*_polygons.json" ) + searchCoarse = os.path.join( cityscapesPath , "gtCoarse" , "*" , "*" , "*_gt*_polygons.json" ) + + # search files + filesFine = glob.glob( searchFine ) + filesFine.sort() + filesCoarse = glob.glob( searchCoarse ) + filesCoarse.sort() + + # concatenate fine and coarse + files = filesFine + filesCoarse + # files = filesFine # use this line if fine is enough for now. + + # quit if we did not find anything + if not files: + printError( "Did not find any files. Please consult the README." ) + + # a bit verbose + print("Processing {} annotation files".format(len(files))) + + # iterate through files + progress = 0 + print("Progress: {:>3} %".format( progress * 100 / len(files) ), end=' ') + for f in files: + # create the output filename + dst = f.replace( "_polygons.json" , "_instanceTrainIds.png" ) + + # do the conversion + try: + json2instanceImg( f , dst , "trainIds" ) + except: + print("Failed to convert: {}".format(f)) + raise + + # status + progress += 1 + print("\rProgress: {:>3} %".format( progress * 100 / len(files) ), end=' ') + sys.stdout.flush() + + +# call the main +if __name__ == "__main__": + data_path = sys.argv[1] main(data_path) \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/datasets/prepare_ade20k_sem_seg.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/datasets/prepare_ade20k_sem_seg.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/datasets/prepare_cocofied_lvis.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/datasets/prepare_cocofied_lvis.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/datasets/prepare_for_tests.sh b/PyTorch/contrib/cv/semantic_segmentation/PointRend/datasets/prepare_for_tests.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/datasets/prepare_panoptic_fpn.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/datasets/prepare_panoptic_fpn.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/demo/demo.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/demo/demo.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/linter.sh b/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/linter.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/packaging/build_all_wheels.sh b/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/packaging/build_all_wheels.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/packaging/build_wheel.sh b/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/packaging/build_wheel.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/packaging/gen_install_table.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/packaging/gen_install_table.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/packaging/gen_wheel_index.sh b/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/packaging/gen_wheel_index.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/packaging/pkg_helpers.bash b/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/packaging/pkg_helpers.bash old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/parse_results.sh b/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/parse_results.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/run_inference_tests.sh b/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/run_inference_tests.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/run_instant_tests.sh b/PyTorch/contrib/cv/semantic_segmentation/PointRend/dev/run_instant_tests.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/projects/PointRend/train_net.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/projects/PointRend/train_net.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/analyze_model.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/analyze_model.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/benchmark.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/benchmark.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/convert-torchvision-to-d2.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/convert-torchvision-to-d2.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/deploy/export_model.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/deploy/export_model.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/lazyconfig_train_net.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/lazyconfig_train_net.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/plain_train_net.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/plain_train_net.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/train_net.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/train_net.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/visualize_data.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/visualize_data.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/visualize_json_results.py b/PyTorch/contrib/cv/semantic_segmentation/PointRend/tools/visualize_json_results.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/RCAN/dataset.py b/PyTorch/contrib/cv/semantic_segmentation/RCAN/dataset.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/RCAN/main.py b/PyTorch/contrib/cv/semantic_segmentation/RCAN/main.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/RCAN/model.py b/PyTorch/contrib/cv/semantic_segmentation/RCAN/model.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/RCAN/test.py b/PyTorch/contrib/cv/semantic_segmentation/RCAN/test.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/run_1p_prof.sh b/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/run_1p_prof.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/run_test.sh b/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/run_test.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/set_npu_env.sh b/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/set_npu_env.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/train_finetuning_1p.sh b/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/train_finetuning_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/train_full_1p.sh b/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/train_full_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/train_full_8p.sh b/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/train_full_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/train_performance_1p.sh b/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/train_performance_1p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/train_performance_8p.sh b/PyTorch/contrib/cv/semantic_segmentation/RCAN/test/train_performance_8p.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/RCAN/utils.py b/PyTorch/contrib/cv/semantic_segmentation/RCAN/utils.py old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/RefineNet/Dockerfile b/PyTorch/contrib/cv/semantic_segmentation/RefineNet/Dockerfile index 7e712fe1a166790798f57a2f2762c47394beb625..30a31af55804dd79571d2a36e6107a844cb7e549 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/RefineNet/Dockerfile +++ b/PyTorch/contrib/cv/semantic_segmentation/RefineNet/Dockerfile @@ -1,5 +1,5 @@ -ARG FROM_IMAGE_NAME -FROM $FROM_IMAGE_NAME - -COPY requirements.txt . +ARG FROM_IMAGE_NAME +FROM $FROM_IMAGE_NAME + +COPY requirements.txt . RUN pip3.7 install -r requirements.txt \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/RefineNet/README.md b/PyTorch/contrib/cv/semantic_segmentation/RefineNet/README.md index c76ab910ec220273414e18a1f0b6a4a2a31ec338..00f9295deaf325e57e3ef421789d60fdaac86ba9 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/RefineNet/README.md +++ b/PyTorch/contrib/cv/semantic_segmentation/RefineNet/README.md @@ -1,79 +1,79 @@ -# RefineNet - -This repository is an NPU implementation of the ["RefineNet: Multi-Path Refinement Networks for High-Resolution Semantic Segmentation"](https://arxiv.org/abs/1611.06612), referring to https://github.com/DrSleep/refinenet-pytorch - - - -## Requirements - -See requirements.txt - -- PyTorch 1.5.0 -- torchvision 0.6.0 -- Numpy 1.15.1 -- Pillow 5.3.0 -- h5py 2.8.0 -- tqdm 4.28.1 -- h5py 3.4.0 -- opencv-python 3.4.4.19 -- albumentations 0.4.5 -- install densetorch as follow: - -```bash - git clone https://github.com/DrSleep/DenseTorch - cd ./DenseTorch - python setup.py install -``` - -## Training - -The processed VOC dataset can be downloaded from [Download](https://pan.baidu.com/s/12wHGhby5vEcG6isQpnpcMQ) with extraction code: vnhb (about 9 G), put it in ./VOC. Or, you can download it by: -```bash -bash load_data.sh -``` - -The training common: - -```bash -# 1p train perf -bash test/train_performance_1p.sh - -# 8p train perf -bash test/train_performance_8p.sh - -# 8p train full -bash test/train_full_8p.sh - -# finetuning -bash test/train_finetune_1p.sh -``` - -In the first running, it requires time to downloaded the model pre-trained on ImageNet. Or you can manually download it by: -```shell -cd ~ -mkdir .torch -mkdir .torch/models -cd .torch/models -wget https://download.pytorch.org/models/resnet101-5d3b4d8f.pth -mv resnet101-5d3b4d8f.pth 101_imagenet.pth.tar -``` -Log path: ./log/ - -Saved model path: ./model/ - -## Training result - -| IOU | FPS | NPU_nums | BS/NPU | AMP_type | -|-----------|-------|-------|-----------------|-----------| -| 78.56 | 25.56 | 1 | 16 | O2 | -| 77.34 | 159.46| 8 | 8 | O2 | - - - - -## Citation -``` -RefineNet: Multi-Path Refinement Networks for High-Resolution Semantic Segmentation -Guosheng Lin, Anton Milan, Chunhua Shen, Ian Reid -In CVPR 2017 -``` +# RefineNet + +This repository is an NPU implementation of the ["RefineNet: Multi-Path Refinement Networks for High-Resolution Semantic Segmentation"](https://arxiv.org/abs/1611.06612), referring to https://github.com/DrSleep/refinenet-pytorch + + + +## Requirements + +See requirements.txt + +- PyTorch 1.5.0 +- torchvision 0.6.0 +- Numpy 1.15.1 +- Pillow 5.3.0 +- h5py 2.8.0 +- tqdm 4.28.1 +- h5py 3.4.0 +- opencv-python 3.4.4.19 +- albumentations 0.4.5 +- install densetorch as follow: + +```bash + git clone https://github.com/DrSleep/DenseTorch + cd ./DenseTorch + python setup.py install +``` + +## Training + +The processed VOC dataset can be downloaded from [Download](https://pan.baidu.com/s/12wHGhby5vEcG6isQpnpcMQ) with extraction code: vnhb (about 9 G), put it in ./VOC. Or, you can download it by: +```bash +bash load_data.sh +``` + +The training common: + +```bash +# 1p train perf +bash test/train_performance_1p.sh + +# 8p train perf +bash test/train_performance_8p.sh + +# 8p train full +bash test/train_full_8p.sh + +# finetuning +bash test/train_finetune_1p.sh +``` + +In the first running, it requires time to downloaded the model pre-trained on ImageNet. Or you can manually download it by: +```shell +cd ~ +mkdir .torch +mkdir .torch/models +cd .torch/models +wget https://download.pytorch.org/models/resnet101-5d3b4d8f.pth +mv resnet101-5d3b4d8f.pth 101_imagenet.pth.tar +``` +Log path: ./log/ + +Saved model path: ./model/ + +## Training result + +| IOU | FPS | NPU_nums | BS/NPU | AMP_type | +|-----------|-------|-------|-----------------|-----------| +| 78.56 | 25.56 | 1 | 16 | O2 | +| 77.34 | 159.46| 8 | 8 | O2 | + + + + +## Citation +``` +RefineNet: Multi-Path Refinement Networks for High-Resolution Semantic Segmentation +Guosheng Lin, Anton Milan, Chunhua Shen, Ian Reid +In CVPR 2017 +``` diff --git a/PyTorch/contrib/cv/semantic_segmentation/RefineNet/models/refinenet.py b/PyTorch/contrib/cv/semantic_segmentation/RefineNet/models/refinenet.py index 07027e25da303fc3fde829db22b93929cfc8b35e..64eafea2b3dcb0cb29f646ea37afdaebf9341502 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/RefineNet/models/refinenet.py +++ b/PyTorch/contrib/cv/semantic_segmentation/RefineNet/models/refinenet.py @@ -1,336 +1,336 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch.nn as nn -import torch.nn.functional as F -import torch - -import numpy as np - -IMG_SCALE = 1./255 -IMG_MEAN = np.array([0.485, 0.456, 0.406]).reshape((1, 1, 3)) -IMG_STD = np.array([0.229, 0.224, 0.225]).reshape((1, 1, 3)) - -def maybe_download(model_name, model_url, model_dir=None, map_location=None): - import os, sys - from six.moves import urllib - if model_dir is None: - torch_home = os.path.expanduser(os.getenv('TORCH_HOME', '~/.torch')) - model_dir = os.getenv('TORCH_MODEL_ZOO', os.path.join(torch_home, 'models')) - if not os.path.exists(model_dir): - os.makedirs(model_dir) - filename = '{}.pth.tar'.format(model_name) - cached_file = os.path.join(model_dir, filename) - if not os.path.exists(cached_file): - url = model_url - sys.stderr.write('Downloading: "{}" to {}\n'.format(url, cached_file)) - urllib.request.urlretrieve(url, cached_file) - return torch.load(cached_file, map_location=map_location) - -def prepare_img(img): - return (img * IMG_SCALE - IMG_MEAN) / IMG_STD - -def batchnorm(in_planes): - "batch norm 2d" - return nn.BatchNorm2d(in_planes, affine=True, eps=1e-5, momentum=0.1) - -def conv3x3(in_planes, out_planes, stride=1, bias=False): - "3x3 convolution with padding" - return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, - padding=1, bias=bias) - -def conv1x1(in_planes, out_planes, stride=1, bias=False): - "1x1 convolution" - return nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride, - padding=0, bias=bias) - -def convbnrelu(in_planes, out_planes, kernel_size, stride=1, groups=1, act=True): - "conv-batchnorm-relu" - if act: - return nn.Sequential(nn.Conv2d(in_planes, out_planes, kernel_size, stride=stride, padding=int(kernel_size / 2.), groups=groups, bias=False), - batchnorm(out_planes), - nn.ReLU6(inplace=True)) - else: - return nn.Sequential(nn.Conv2d(in_planes, out_planes, kernel_size, stride=stride, padding=int(kernel_size / 2.), groups=groups, bias=False), - batchnorm(out_planes)) - -class CRPBlock(nn.Module): - - def __init__(self, in_planes, out_planes, n_stages, max_pooling=True): - super(CRPBlock, self).__init__() - for i in range(n_stages): - setattr(self, '{}_{}'.format(i + 1, 'outvar_dimred'), - conv3x3(in_planes if (i == 0) else out_planes, - out_planes, stride=1, - bias=False)) - self.stride = 1 - self.n_stages = n_stages - if max_pooling: self.maxpool = nn.MaxPool2d(kernel_size=5, stride=1, padding=2) - else: self.maxpool = nn.MaxPool2d(kernel_size=1, stride=1, padding=0) - - def forward(self, x): - top = x - for i in range(self.n_stages): - top = self.maxpool(top) - top = getattr(self, '{}_{}'.format(i + 1, 'outvar_dimred'))(top) - x = top + x - return x - -stages_suffixes = {0 : '_conv', - 1 : '_conv_relu_varout_dimred'} - -class RCUBlock(nn.Module): - - def __init__(self, in_planes, out_planes, n_blocks, n_stages): - super(RCUBlock, self).__init__() - for i in range(n_blocks): - for j in range(n_stages): - setattr(self, '{}{}'.format(i + 1, stages_suffixes[j]), - conv3x3(in_planes if (i == 0) and (j == 0) else out_planes, - out_planes, stride=1, - bias=(j == 0))) - self.stride = 1 - self.n_blocks = n_blocks - self.n_stages = n_stages - - def forward(self, x): - for i in range(self.n_blocks): - residual = x - for j in range(self.n_stages): - x = F.relu(x) - x = getattr(self, '{}{}'.format(i + 1, stages_suffixes[j]))(x) - x += residual - return x - -data_info = { - 21: 'VOC', - } - -models_urls = { - '101_voc' : 'https://cloudstor.aarnet.edu.au/plus/s/Owmttk9bdPROwc6/download', - - '101_imagenet': 'https://download.pytorch.org/models/resnet101-5d3b4d8f.pth', - } - -class BasicBlock(nn.Module): - expansion = 1 - - def __init__(self, inplanes, planes, stride=1, downsample=None): - super(BasicBlock, self).__init__() - self.conv1 = conv3x3(inplanes, planes, stride) - self.bn1 = nn.BatchNorm2d(planes) - self.relu = nn.ReLU(inplace=True) - self.conv2 = conv3x3(planes, planes) - self.bn2 = nn.BatchNorm2d(planes) - self.downsample = downsample - self.stride = stride - - def forward(self, x): - residual = x - - out = self.conv1(x) - out = self.bn1(out) - out = self.relu(out) - - out = self.conv2(out) - out = self.bn2(out) - - if self.downsample is not None: - residual = self.downsample(x) - - out += residual - out = self.relu(out) - - return out - - -class Bottleneck(nn.Module): - expansion = 4 - - def __init__(self, inplanes, planes, stride=1, downsample=None): - super(Bottleneck, self).__init__() - self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False) - self.bn1 = nn.BatchNorm2d(planes) - self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, - padding=1, bias=False) - self.bn2 = nn.BatchNorm2d(planes) - self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False) - self.bn3 = nn.BatchNorm2d(planes * 4) - self.relu = nn.ReLU(inplace=True) - self.downsample = downsample - self.stride = stride - - def forward(self, x): - residual = x - - out = self.conv1(x) - out = self.bn1(out) - out = self.relu(out) - - out = self.conv2(out) - out = self.bn2(out) - out = self.relu(out) - - out = self.conv3(out) - out = self.bn3(out) - - if self.downsample is not None: - residual = self.downsample(x) - - out += residual - out = self.relu(out) - - return out - - -class RefineNet(nn.Module): - - def __init__(self, block, layers, num_classes=21): - self.inplanes = 64 - super(RefineNet, self).__init__() - self.do = nn.Dropout(p=0.5) - self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, - bias=False) - self.bn1 = nn.BatchNorm2d(64) - self.relu = nn.ReLU(inplace=True) - self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) - self.layer1 = self._make_layer(block, 64, layers[0]) - self.layer2 = self._make_layer(block, 128, layers[1], stride=2) - self.layer3 = self._make_layer(block, 256, layers[2], stride=2) - self.layer4 = self._make_layer(block, 512, layers[3], stride=2) - self.p_ims1d2_outl1_dimred = conv3x3(2048, 512, bias=False) - self.adapt_stage1_b = self._make_rcu(512, 512, 2, 2) - self.mflow_conv_g1_pool = self._make_crp(512, 512, 4) - self.mflow_conv_g1_b = self._make_rcu(512, 512, 3, 2) - self.mflow_conv_g1_b3_joint_varout_dimred = conv3x3(512, 256, bias=False) - self.p_ims1d2_outl2_dimred = conv3x3(1024, 256, bias=False) - self.adapt_stage2_b = self._make_rcu(256, 256, 2, 2) - self.adapt_stage2_b2_joint_varout_dimred = conv3x3(256, 256, bias=False) - self.mflow_conv_g2_pool = self._make_crp(256, 256, 4) - self.mflow_conv_g2_b = self._make_rcu(256, 256, 3, 2) - self.mflow_conv_g2_b3_joint_varout_dimred = conv3x3(256, 256, bias=False) - - self.p_ims1d2_outl3_dimred = conv3x3(512, 256, bias=False) - self.adapt_stage3_b = self._make_rcu(256, 256, 2, 2) - self.adapt_stage3_b2_joint_varout_dimred = conv3x3(256, 256, bias=False) - self.mflow_conv_g3_pool = self._make_crp(256, 256, 4) - self.mflow_conv_g3_b = self._make_rcu(256, 256, 3, 2) - self.mflow_conv_g3_b3_joint_varout_dimred = conv3x3(256, 256, bias=False) - - self.p_ims1d2_outl4_dimred = conv3x3(256, 256, bias=False) - self.adapt_stage4_b = self._make_rcu(256, 256, 2, 2) - self.adapt_stage4_b2_joint_varout_dimred = conv3x3(256, 256, bias=False) - self.mflow_conv_g4_pool = self._make_crp(256, 256, 4, max_pooling=False) - self.mflow_conv_g4_b = self._make_rcu(256, 256, 3, 2) - - self.clf_conv = nn.Conv2d(256, num_classes, kernel_size=3, stride=1, - padding=1, bias=True) - - def _make_crp(self, in_planes, out_planes, stages, max_pooling=True): - layers = [CRPBlock(in_planes, out_planes, stages, max_pooling)] - return nn.Sequential(*layers) - - def _make_rcu(self, in_planes, out_planes, blocks, stages): - layers = [RCUBlock(in_planes, out_planes, blocks, stages)] - return nn.Sequential(*layers) - - def _make_layer(self, block, planes, blocks, stride=1): - downsample = None - if stride != 1 or self.inplanes != planes * block.expansion: - downsample = nn.Sequential( - nn.Conv2d(self.inplanes, planes * block.expansion, - kernel_size=1, stride=stride, bias=False), - nn.BatchNorm2d(planes * block.expansion), - ) - - layers = [] - layers.append(block(self.inplanes, planes, stride, downsample)) - self.inplanes = planes * block.expansion - for i in range(1, blocks): - layers.append(block(self.inplanes, planes)) - - return nn.Sequential(*layers) - - def forward(self, x): - x = self.conv1(x) - x = self.bn1(x) - x = self.relu(x) - x = self.maxpool(x) - - l1 = self.layer1(x) - l2 = self.layer2(l1) - l3 = self.layer3(l2) - l4 = self.layer4(l3) - - l4 = self.do(l4) - l3 = self.do(l3) - - - x4 = self.p_ims1d2_outl1_dimred(l4) - x4 = self.adapt_stage1_b(x4) - x4 = self.relu(x4) - x4 = self.mflow_conv_g1_pool(x4) - x4 = self.mflow_conv_g1_b(x4) - x4 = self.mflow_conv_g1_b3_joint_varout_dimred(x4) - x4 = nn.Upsample(size=l3.size()[2:], mode='bilinear', align_corners=True)(x4) - - x3 = self.p_ims1d2_outl2_dimred(l3) - x3 = self.adapt_stage2_b(x3) - x3 = self.adapt_stage2_b2_joint_varout_dimred(x3) - x3 = x3 + x4 - x3 = F.relu(x3) - x3 = self.mflow_conv_g2_pool(x3) - x3 = self.mflow_conv_g2_b(x3) - x3 = self.mflow_conv_g2_b3_joint_varout_dimred(x3) - x3 = nn.Upsample(size=l2.size()[2:], mode='bilinear', align_corners=True)(x3) - - x2 = self.p_ims1d2_outl3_dimred(l2) - x2 = self.adapt_stage3_b(x2) - x2 = self.adapt_stage3_b2_joint_varout_dimred(x2) - x2 = x2 + x3 - x2 = F.relu(x2) - x2 = self.mflow_conv_g3_pool(x2) - x2 = self.mflow_conv_g3_b(x2) - x2 = self.mflow_conv_g3_b3_joint_varout_dimred(x2) - x2 = nn.Upsample(size=l1.size()[2:], mode='bilinear', align_corners=True)(x2) - - - x1 = self.p_ims1d2_outl4_dimred(l1) - x1 = self.adapt_stage4_b(x1) - x1 = self.adapt_stage4_b2_joint_varout_dimred(x1) - x1 = x1 + x2 - x1 = F.relu(x1) - - x1 = self.mflow_conv_g4_pool(x1) - x1 = self.mflow_conv_g4_b(x1) - x1 = self.do(x1) - - out = self.clf_conv(x1) - return out - - -def rf101(num_classes, imagenet=False, pretrained=True, **kwargs): - model = RefineNet(Bottleneck, [3, 4, 23, 3], num_classes=num_classes, **kwargs) - if imagenet: - key = '101_imagenet' - url = models_urls[key] - model.load_state_dict(maybe_download(key, url), strict=False) - elif pretrained: - dataset = data_info.get(num_classes, None) - if dataset: - bname = '101_' + dataset.lower() - key = 'rf' + bname - url = models_urls[bname] - model.load_state_dict(maybe_download(key, url), strict=False) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch.nn as nn +import torch.nn.functional as F +import torch + +import numpy as np + +IMG_SCALE = 1./255 +IMG_MEAN = np.array([0.485, 0.456, 0.406]).reshape((1, 1, 3)) +IMG_STD = np.array([0.229, 0.224, 0.225]).reshape((1, 1, 3)) + +def maybe_download(model_name, model_url, model_dir=None, map_location=None): + import os, sys + from six.moves import urllib + if model_dir is None: + torch_home = os.path.expanduser(os.getenv('TORCH_HOME', '~/.torch')) + model_dir = os.getenv('TORCH_MODEL_ZOO', os.path.join(torch_home, 'models')) + if not os.path.exists(model_dir): + os.makedirs(model_dir) + filename = '{}.pth.tar'.format(model_name) + cached_file = os.path.join(model_dir, filename) + if not os.path.exists(cached_file): + url = model_url + sys.stderr.write('Downloading: "{}" to {}\n'.format(url, cached_file)) + urllib.request.urlretrieve(url, cached_file) + return torch.load(cached_file, map_location=map_location) + +def prepare_img(img): + return (img * IMG_SCALE - IMG_MEAN) / IMG_STD + +def batchnorm(in_planes): + "batch norm 2d" + return nn.BatchNorm2d(in_planes, affine=True, eps=1e-5, momentum=0.1) + +def conv3x3(in_planes, out_planes, stride=1, bias=False): + "3x3 convolution with padding" + return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, + padding=1, bias=bias) + +def conv1x1(in_planes, out_planes, stride=1, bias=False): + "1x1 convolution" + return nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride, + padding=0, bias=bias) + +def convbnrelu(in_planes, out_planes, kernel_size, stride=1, groups=1, act=True): + "conv-batchnorm-relu" + if act: + return nn.Sequential(nn.Conv2d(in_planes, out_planes, kernel_size, stride=stride, padding=int(kernel_size / 2.), groups=groups, bias=False), + batchnorm(out_planes), + nn.ReLU6(inplace=True)) + else: + return nn.Sequential(nn.Conv2d(in_planes, out_planes, kernel_size, stride=stride, padding=int(kernel_size / 2.), groups=groups, bias=False), + batchnorm(out_planes)) + +class CRPBlock(nn.Module): + + def __init__(self, in_planes, out_planes, n_stages, max_pooling=True): + super(CRPBlock, self).__init__() + for i in range(n_stages): + setattr(self, '{}_{}'.format(i + 1, 'outvar_dimred'), + conv3x3(in_planes if (i == 0) else out_planes, + out_planes, stride=1, + bias=False)) + self.stride = 1 + self.n_stages = n_stages + if max_pooling: self.maxpool = nn.MaxPool2d(kernel_size=5, stride=1, padding=2) + else: self.maxpool = nn.MaxPool2d(kernel_size=1, stride=1, padding=0) + + def forward(self, x): + top = x + for i in range(self.n_stages): + top = self.maxpool(top) + top = getattr(self, '{}_{}'.format(i + 1, 'outvar_dimred'))(top) + x = top + x + return x + +stages_suffixes = {0 : '_conv', + 1 : '_conv_relu_varout_dimred'} + +class RCUBlock(nn.Module): + + def __init__(self, in_planes, out_planes, n_blocks, n_stages): + super(RCUBlock, self).__init__() + for i in range(n_blocks): + for j in range(n_stages): + setattr(self, '{}{}'.format(i + 1, stages_suffixes[j]), + conv3x3(in_planes if (i == 0) and (j == 0) else out_planes, + out_planes, stride=1, + bias=(j == 0))) + self.stride = 1 + self.n_blocks = n_blocks + self.n_stages = n_stages + + def forward(self, x): + for i in range(self.n_blocks): + residual = x + for j in range(self.n_stages): + x = F.relu(x) + x = getattr(self, '{}{}'.format(i + 1, stages_suffixes[j]))(x) + x += residual + return x + +data_info = { + 21: 'VOC', + } + +models_urls = { + '101_voc' : 'https://cloudstor.aarnet.edu.au/plus/s/Owmttk9bdPROwc6/download', + + '101_imagenet': 'https://download.pytorch.org/models/resnet101-5d3b4d8f.pth', + } + +class BasicBlock(nn.Module): + expansion = 1 + + def __init__(self, inplanes, planes, stride=1, downsample=None): + super(BasicBlock, self).__init__() + self.conv1 = conv3x3(inplanes, planes, stride) + self.bn1 = nn.BatchNorm2d(planes) + self.relu = nn.ReLU(inplace=True) + self.conv2 = conv3x3(planes, planes) + self.bn2 = nn.BatchNorm2d(planes) + self.downsample = downsample + self.stride = stride + + def forward(self, x): + residual = x + + out = self.conv1(x) + out = self.bn1(out) + out = self.relu(out) + + out = self.conv2(out) + out = self.bn2(out) + + if self.downsample is not None: + residual = self.downsample(x) + + out += residual + out = self.relu(out) + + return out + + +class Bottleneck(nn.Module): + expansion = 4 + + def __init__(self, inplanes, planes, stride=1, downsample=None): + super(Bottleneck, self).__init__() + self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False) + self.bn1 = nn.BatchNorm2d(planes) + self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, + padding=1, bias=False) + self.bn2 = nn.BatchNorm2d(planes) + self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False) + self.bn3 = nn.BatchNorm2d(planes * 4) + self.relu = nn.ReLU(inplace=True) + self.downsample = downsample + self.stride = stride + + def forward(self, x): + residual = x + + out = self.conv1(x) + out = self.bn1(out) + out = self.relu(out) + + out = self.conv2(out) + out = self.bn2(out) + out = self.relu(out) + + out = self.conv3(out) + out = self.bn3(out) + + if self.downsample is not None: + residual = self.downsample(x) + + out += residual + out = self.relu(out) + + return out + + +class RefineNet(nn.Module): + + def __init__(self, block, layers, num_classes=21): + self.inplanes = 64 + super(RefineNet, self).__init__() + self.do = nn.Dropout(p=0.5) + self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, + bias=False) + self.bn1 = nn.BatchNorm2d(64) + self.relu = nn.ReLU(inplace=True) + self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) + self.layer1 = self._make_layer(block, 64, layers[0]) + self.layer2 = self._make_layer(block, 128, layers[1], stride=2) + self.layer3 = self._make_layer(block, 256, layers[2], stride=2) + self.layer4 = self._make_layer(block, 512, layers[3], stride=2) + self.p_ims1d2_outl1_dimred = conv3x3(2048, 512, bias=False) + self.adapt_stage1_b = self._make_rcu(512, 512, 2, 2) + self.mflow_conv_g1_pool = self._make_crp(512, 512, 4) + self.mflow_conv_g1_b = self._make_rcu(512, 512, 3, 2) + self.mflow_conv_g1_b3_joint_varout_dimred = conv3x3(512, 256, bias=False) + self.p_ims1d2_outl2_dimred = conv3x3(1024, 256, bias=False) + self.adapt_stage2_b = self._make_rcu(256, 256, 2, 2) + self.adapt_stage2_b2_joint_varout_dimred = conv3x3(256, 256, bias=False) + self.mflow_conv_g2_pool = self._make_crp(256, 256, 4) + self.mflow_conv_g2_b = self._make_rcu(256, 256, 3, 2) + self.mflow_conv_g2_b3_joint_varout_dimred = conv3x3(256, 256, bias=False) + + self.p_ims1d2_outl3_dimred = conv3x3(512, 256, bias=False) + self.adapt_stage3_b = self._make_rcu(256, 256, 2, 2) + self.adapt_stage3_b2_joint_varout_dimred = conv3x3(256, 256, bias=False) + self.mflow_conv_g3_pool = self._make_crp(256, 256, 4) + self.mflow_conv_g3_b = self._make_rcu(256, 256, 3, 2) + self.mflow_conv_g3_b3_joint_varout_dimred = conv3x3(256, 256, bias=False) + + self.p_ims1d2_outl4_dimred = conv3x3(256, 256, bias=False) + self.adapt_stage4_b = self._make_rcu(256, 256, 2, 2) + self.adapt_stage4_b2_joint_varout_dimred = conv3x3(256, 256, bias=False) + self.mflow_conv_g4_pool = self._make_crp(256, 256, 4, max_pooling=False) + self.mflow_conv_g4_b = self._make_rcu(256, 256, 3, 2) + + self.clf_conv = nn.Conv2d(256, num_classes, kernel_size=3, stride=1, + padding=1, bias=True) + + def _make_crp(self, in_planes, out_planes, stages, max_pooling=True): + layers = [CRPBlock(in_planes, out_planes, stages, max_pooling)] + return nn.Sequential(*layers) + + def _make_rcu(self, in_planes, out_planes, blocks, stages): + layers = [RCUBlock(in_planes, out_planes, blocks, stages)] + return nn.Sequential(*layers) + + def _make_layer(self, block, planes, blocks, stride=1): + downsample = None + if stride != 1 or self.inplanes != planes * block.expansion: + downsample = nn.Sequential( + nn.Conv2d(self.inplanes, planes * block.expansion, + kernel_size=1, stride=stride, bias=False), + nn.BatchNorm2d(planes * block.expansion), + ) + + layers = [] + layers.append(block(self.inplanes, planes, stride, downsample)) + self.inplanes = planes * block.expansion + for i in range(1, blocks): + layers.append(block(self.inplanes, planes)) + + return nn.Sequential(*layers) + + def forward(self, x): + x = self.conv1(x) + x = self.bn1(x) + x = self.relu(x) + x = self.maxpool(x) + + l1 = self.layer1(x) + l2 = self.layer2(l1) + l3 = self.layer3(l2) + l4 = self.layer4(l3) + + l4 = self.do(l4) + l3 = self.do(l3) + + + x4 = self.p_ims1d2_outl1_dimred(l4) + x4 = self.adapt_stage1_b(x4) + x4 = self.relu(x4) + x4 = self.mflow_conv_g1_pool(x4) + x4 = self.mflow_conv_g1_b(x4) + x4 = self.mflow_conv_g1_b3_joint_varout_dimred(x4) + x4 = nn.Upsample(size=l3.size()[2:], mode='bilinear', align_corners=True)(x4) + + x3 = self.p_ims1d2_outl2_dimred(l3) + x3 = self.adapt_stage2_b(x3) + x3 = self.adapt_stage2_b2_joint_varout_dimred(x3) + x3 = x3 + x4 + x3 = F.relu(x3) + x3 = self.mflow_conv_g2_pool(x3) + x3 = self.mflow_conv_g2_b(x3) + x3 = self.mflow_conv_g2_b3_joint_varout_dimred(x3) + x3 = nn.Upsample(size=l2.size()[2:], mode='bilinear', align_corners=True)(x3) + + x2 = self.p_ims1d2_outl3_dimred(l2) + x2 = self.adapt_stage3_b(x2) + x2 = self.adapt_stage3_b2_joint_varout_dimred(x2) + x2 = x2 + x3 + x2 = F.relu(x2) + x2 = self.mflow_conv_g3_pool(x2) + x2 = self.mflow_conv_g3_b(x2) + x2 = self.mflow_conv_g3_b3_joint_varout_dimred(x2) + x2 = nn.Upsample(size=l1.size()[2:], mode='bilinear', align_corners=True)(x2) + + + x1 = self.p_ims1d2_outl4_dimred(l1) + x1 = self.adapt_stage4_b(x1) + x1 = self.adapt_stage4_b2_joint_varout_dimred(x1) + x1 = x1 + x2 + x1 = F.relu(x1) + + x1 = self.mflow_conv_g4_pool(x1) + x1 = self.mflow_conv_g4_b(x1) + x1 = self.do(x1) + + out = self.clf_conv(x1) + return out + + +def rf101(num_classes, imagenet=False, pretrained=True, **kwargs): + model = RefineNet(Bottleneck, [3, 4, 23, 3], num_classes=num_classes, **kwargs) + if imagenet: + key = '101_imagenet' + url = models_urls[key] + model.load_state_dict(maybe_download(key, url), strict=False) + elif pretrained: + dataset = data_info.get(num_classes, None) + if dataset: + bname = '101_' + dataset.lower() + key = 'rf' + bname + url = models_urls[bname] + model.load_state_dict(maybe_download(key, url), strict=False) return model \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/RefineNet/modelzoo_level.txt b/PyTorch/contrib/cv/semantic_segmentation/RefineNet/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/RefineNet/modelzoo_level.txt +++ b/PyTorch/contrib/cv/semantic_segmentation/RefineNet/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/RefineNet/src/load_dataset.py b/PyTorch/contrib/cv/semantic_segmentation/RefineNet/src/load_dataset.py index c011e1f9f3b61b059fa419cf134ec46adfe77913..b74edc85e57013c4bcd2d598b79bb731ad8bf5e5 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/RefineNet/src/load_dataset.py +++ b/PyTorch/contrib/cv/semantic_segmentation/RefineNet/src/load_dataset.py @@ -1,73 +1,73 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import os -import re -import sys -from tqdm import tqdm -from time import time -sys.path.append('./') -# general libs -import logging -import numpy as np - -# pytorch libs -import torch -import torch.nn as nn -import torch.nn.functional as F -from torch.utils.data import DataLoader - -# densetorch wrapper -import densetorch as dt - -# configuration for light-weight refinenet -from arguments import get_arguments -from data import get_datasets, get_transforms -from network import get_segmenter -from optimisers import get_optimisers, get_lr_schedulers -from apex import amp -import torch.multiprocessing as mp - -def setup_data_loaders(args): - train_transforms, val_transforms = get_transforms( - crop_size=args.crop_size, - shorter_side=args.shorter_side, - low_scale=args.low_scale, - high_scale=args.high_scale, - img_mean=args.img_mean, - img_std=args.img_std, - img_scale=args.img_scale, - ignore_label=args.ignore_label, - num_stages=args.num_stages, - augmentations_type=args.augmentations_type, - dataset_type=args.dataset_type, - ) - train_sets, val_set = get_datasets( - train_dir=args.train_dir, - val_dir=args.val_dir, - train_list_path=args.train_list_path, - val_list_path=args.val_list_path, - train_transforms=train_transforms, - val_transforms=val_transforms, - masks_names=("segm",), - dataset_type=args.dataset_type, - stage_names=args.stage_names, - train_download=args.train_download, - val_download=args.val_download, - ) - - -args = get_arguments() -setup_data_loaders(args) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import os +import re +import sys +from tqdm import tqdm +from time import time +sys.path.append('./') +# general libs +import logging +import numpy as np + +# pytorch libs +import torch +import torch.nn as nn +import torch.nn.functional as F +from torch.utils.data import DataLoader + +# densetorch wrapper +import densetorch as dt + +# configuration for light-weight refinenet +from arguments import get_arguments +from data import get_datasets, get_transforms +from network import get_segmenter +from optimisers import get_optimisers, get_lr_schedulers +from apex import amp +import torch.multiprocessing as mp + +def setup_data_loaders(args): + train_transforms, val_transforms = get_transforms( + crop_size=args.crop_size, + shorter_side=args.shorter_side, + low_scale=args.low_scale, + high_scale=args.high_scale, + img_mean=args.img_mean, + img_std=args.img_std, + img_scale=args.img_scale, + ignore_label=args.ignore_label, + num_stages=args.num_stages, + augmentations_type=args.augmentations_type, + dataset_type=args.dataset_type, + ) + train_sets, val_set = get_datasets( + train_dir=args.train_dir, + val_dir=args.val_dir, + train_list_path=args.train_list_path, + val_list_path=args.val_list_path, + train_transforms=train_transforms, + val_transforms=val_transforms, + masks_names=("segm",), + dataset_type=args.dataset_type, + stage_names=args.stage_names, + train_download=args.train_download, + val_download=args.val_download, + ) + + +args = get_arguments() +setup_data_loaders(args) + diff --git a/PyTorch/contrib/cv/semantic_segmentation/SETR/env_npu.sh b/PyTorch/contrib/cv/semantic_segmentation/SETR/env_npu.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/SETR/mmcv-need/fp16_utils.py b/PyTorch/contrib/cv/semantic_segmentation/SETR/mmcv-need/fp16_utils.py index 44d1bdd7d86e9736bb2afde0d6fd01a4d35bbee2..b1bd4a135221e28ecda9e955c111ce9c6ed6eaf2 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/SETR/mmcv-need/fp16_utils.py +++ b/PyTorch/contrib/cv/semantic_segmentation/SETR/mmcv-need/fp16_utils.py @@ -1,381 +1,381 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -import functools -import warnings -from collections import abc -from inspect import getfullargspec - -import numpy as np -import torch -import torch.nn as nn - -from .dist_utils import allreduce_grads as _allreduce_grads - - -def cast_tensor_type(inputs, src_type, dst_type): - """Recursively convert Tensor in inputs from src_type to dst_type. - - Args: - inputs: Inputs that to be casted. - src_type (torch.dtype): Source type.. - dst_type (torch.dtype): Destination type. - - Returns: - The same type with inputs, but all contained Tensors have been cast. - """ - if isinstance(inputs, torch.Tensor): - return inputs.to(dst_type) - elif isinstance(inputs, str): - return inputs - elif isinstance(inputs, np.ndarray): - return inputs - elif isinstance(inputs, abc.Mapping): - return type(inputs)({ - k: cast_tensor_type(v, src_type, dst_type) - for k, v in inputs.items() - }) - elif isinstance(inputs, abc.Iterable): - return type(inputs)( - cast_tensor_type(item, src_type, dst_type) for item in inputs) - else: - return inputs - - -def auto_fp16(apply_to=None, out_fp32=False): - """Decorator to enable fp16 training automatically. - - This decorator is useful when you write custom modules and want to support - mixed precision training. If inputs arguments are fp32 tensors, they will - be converted to fp16 automatically. Arguments other than fp32 tensors are - ignored. - - Args: - apply_to (Iterable, optional): The argument names to be converted. - `None` indicates all arguments. - out_fp32 (bool): Whether to convert the output back to fp32. - - Example: - - >>> import torch.nn as nn - >>> class MyModule1(nn.Module): - >>> - >>> # Convert x and y to fp16 - >>> @auto_fp16() - >>> def forward(self, x, y): - >>> pass - - >>> import torch.nn as nn - >>> class MyModule2(nn.Module): - >>> - >>> # convert pred to fp16 - >>> @auto_fp16(apply_to=('pred', )) - >>> def do_something(self, pred, others): - >>> pass - """ - - def auto_fp16_wrapper(old_func): - - @functools.wraps(old_func) - def new_func(*args, **kwargs): - # check if the module has set the attribute `fp16_enabled`, if not, - # just fallback to the original method. - if not isinstance(args[0], torch.nn.Module): - raise TypeError('@auto_fp16 can only be used to decorate the ' - 'method of nn.Module') - if not (hasattr(args[0], 'fp16_enabled') and args[0].fp16_enabled): - return old_func(*args, **kwargs) - # get the arg spec of the decorated method - args_info = getfullargspec(old_func) - # get the argument names to be casted - args_to_cast = args_info.args if apply_to is None else apply_to - # convert the args that need to be processed - new_args = [] - # NOTE: default args are not taken into consideration - if args: - arg_names = args_info.args[:len(args)] - for i, arg_name in enumerate(arg_names): - if arg_name in args_to_cast: - new_args.append( - cast_tensor_type(args[i], torch.float, torch.half)) - else: - new_args.append(args[i]) - # convert the kwargs that need to be processed - new_kwargs = {} - if kwargs: - for arg_name, arg_value in kwargs.items(): - if arg_name in args_to_cast: - new_kwargs[arg_name] = cast_tensor_type( - arg_value, torch.float, torch.half) - else: - new_kwargs[arg_name] = arg_value - # apply converted arguments to the decorated method - output = old_func(*new_args, **new_kwargs) - # cast the results back to fp32 if necessary - if out_fp32: - output = cast_tensor_type(output, torch.half, torch.float) - return output - - return new_func - - return auto_fp16_wrapper - - -def force_fp32(apply_to=None, out_fp16=False): - """Decorator to convert input arguments to fp32 in force. - - This decorator is useful when you write custom modules and want to support - mixed precision training. If there are some inputs that must be processed - in fp32 mode, then this decorator can handle it. If inputs arguments are - fp16 tensors, they will be converted to fp32 automatically. Arguments other - than fp16 tensors are ignored. - - Args: - apply_to (Iterable, optional): The argument names to be converted. - `None` indicates all arguments. - out_fp16 (bool): Whether to convert the output back to fp16. - - Example: - - >>> import torch.nn as nn - >>> class MyModule1(nn.Module): - >>> - >>> # Convert x and y to fp32 - >>> @force_fp32() - >>> def loss(self, x, y): - >>> pass - - >>> import torch.nn as nn - >>> class MyModule2(nn.Module): - >>> - >>> # convert pred to fp32 - >>> @force_fp32(apply_to=('pred', )) - >>> def post_process(self, pred, others): - >>> pass - """ - - def force_fp32_wrapper(old_func): - - @functools.wraps(old_func) - def new_func(*args, **kwargs): - # check if the module has set the attribute `fp16_enabled`, if not, - # just fallback to the original method. - if not isinstance(args[0], torch.nn.Module): - raise TypeError('@force_fp32 can only be used to decorate the ' - 'method of nn.Module') - if not (hasattr(args[0], 'fp16_enabled') and args[0].fp16_enabled): - return old_func(*args, **kwargs) - # get the arg spec of the decorated method - args_info = getfullargspec(old_func) - # get the argument names to be casted - args_to_cast = args_info.args if apply_to is None else apply_to - # convert the args that need to be processed - new_args = [] - if args: - arg_names = args_info.args[:len(args)] - for i, arg_name in enumerate(arg_names): - if arg_name in args_to_cast: - new_args.append( - cast_tensor_type(args[i], torch.half, torch.float)) - else: - new_args.append(args[i]) - # convert the kwargs that need to be processed - new_kwargs = dict() - if kwargs: - for arg_name, arg_value in kwargs.items(): - if arg_name in args_to_cast: - new_kwargs[arg_name] = cast_tensor_type( - arg_value, torch.half, torch.float) - else: - new_kwargs[arg_name] = arg_value - # apply converted arguments to the decorated method - output = old_func(*new_args, **new_kwargs) - # cast the results back to fp32 if necessary - if out_fp16: - output = cast_tensor_type(output, torch.float, torch.half) - return output - - return new_func - - return force_fp32_wrapper - - -def allreduce_grads(params, coalesce=True, bucket_size_mb=-1): - warnings.warning( - '"mmcv.runner.fp16_utils.allreduce_grads" is deprecated, and will be ' - 'removed in v2.8. Please switch to "mmcv.runner.allreduce_grads') - _allreduce_grads(params, coalesce=coalesce, bucket_size_mb=bucket_size_mb) - - -def wrap_fp16_model(model): - """Wrap the FP32 model to FP16. - - 1. Convert FP32 model to FP16. - 2. Remain some necessary layers to be FP32, e.g., normalization layers. - - Args: - model (nn.Module): Model in FP32. - """ - # convert model to fp16 - model.half() - # patch the normalization layers to make it work in fp32 mode - patch_norm_fp32(model) - # set `fp16_enabled` flag - for m in model.modules(): - if hasattr(m, 'fp16_enabled'): - m.fp16_enabled = True - - -def patch_norm_fp32(module): - """Recursively convert normalization layers from FP16 to FP32. - - Args: - module (nn.Module): The modules to be converted in FP16. - - Returns: - nn.Module: The converted module, the normalization layers have been - converted to FP32. - """ - if isinstance(module, (nn.modules.batchnorm._BatchNorm, nn.GroupNorm, nn.LayerNorm)): - module.float() - # if isinstance(module, nn.GroupNorm) or torch.__version__ < '1.3': - module.forward = patch_forward_method(module.forward, torch.half, - torch.float) - for child in module.children(): - patch_norm_fp32(child) - return module - - -def patch_forward_method(func, src_type, dst_type, convert_output=True): - """Patch the forward method of a module. - - Args: - func (callable): The original forward method. - src_type (torch.dtype): Type of input arguments to be converted from. - dst_type (torch.dtype): Type of input arguments to be converted to. - convert_output (bool): Whether to convert the output back to src_type. - - Returns: - callable: The patched forward method. - """ - - def new_forward(*args, **kwargs): - output = func(*cast_tensor_type(args, src_type, dst_type), - **cast_tensor_type(kwargs, src_type, dst_type)) - if convert_output: - output = cast_tensor_type(output, dst_type, src_type) - return output - - return new_forward - - -class LossScaler: - """Class that manages loss scaling in mixed precision training which - supports both dynamic or static mode. - - The implementation refers to - https://github.com/NVIDIA/apex/blob/master/apex/fp16_utils/loss_scaler.py. - Indirectly, by supplying ``mode='dynamic'`` for dynamic loss scaling. - It's important to understand how :class:`LossScaler` operates. - Loss scaling is designed to combat the problem of underflowing - gradients encountered at long times when training fp16 networks. - Dynamic loss scaling begins by attempting a very high loss - scale. Ironically, this may result in OVERflowing gradients. - If overflowing gradients are encountered, :class:`FP16_Optimizer` then - skips the update step for this particular iteration/minibatch, - and :class:`LossScaler` adjusts the loss scale to a lower value. - If a certain number of iterations occur without overflowing gradients - detected,:class:`LossScaler` increases the loss scale once more. - In this way :class:`LossScaler` attempts to "ride the edge" of always - using the highest loss scale possible without incurring overflow. - - Args: - init_scale (float): Initial loss scale value, default: 2**32. - scale_factor (float): Factor used when adjusting the loss scale. - Default: 2. - mode (str): Loss scaling mode. 'dynamic' or 'static' - scale_window (int): Number of consecutive iterations without an - overflow to wait before increasing the loss scale. Default: 1000. - """ - - def __init__(self, - init_scale=2**32, - mode='dynamic', - scale_factor=2., - scale_window=1000): - self.cur_scale = init_scale - self.cur_iter = 0 - assert mode in ('dynamic', - 'static'), 'mode can only be dynamic or static' - self.mode = mode - self.last_overflow_iter = -1 - self.scale_factor = scale_factor - self.scale_window = scale_window - - def has_overflow(self, params): - """Check if params contain overflow.""" - if self.mode != 'dynamic': - return False - for p in params: - if p.grad is not None and LossScaler._has_inf_or_nan(p.grad.data): - return True - return False - - def _has_inf_or_nan(x): - """Check if params contain NaN.""" - try: - cpu_sum = float(x.float().sum()) - except RuntimeError as instance: - if 'value cannot be converted' not in instance.args[0]: - raise - return True - else: - if cpu_sum == float('inf') or cpu_sum == -float('inf') \ - or cpu_sum != cpu_sum: - return True - return False - - def update_scale(self, overflow): - """update the current loss scale value when overflow happens.""" - if self.mode != 'dynamic': - return - if overflow: - self.cur_scale = max(self.cur_scale / self.scale_factor, 1) - self.last_overflow_iter = self.cur_iter - else: - if (self.cur_iter - self.last_overflow_iter) % \ - self.scale_window == 0: - self.cur_scale *= self.scale_factor - self.cur_iter += 1 - - @property - def loss_scale(self): - return self.cur_scale +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +import functools +import warnings +from collections import abc +from inspect import getfullargspec + +import numpy as np +import torch +import torch.nn as nn + +from .dist_utils import allreduce_grads as _allreduce_grads + + +def cast_tensor_type(inputs, src_type, dst_type): + """Recursively convert Tensor in inputs from src_type to dst_type. + + Args: + inputs: Inputs that to be casted. + src_type (torch.dtype): Source type.. + dst_type (torch.dtype): Destination type. + + Returns: + The same type with inputs, but all contained Tensors have been cast. + """ + if isinstance(inputs, torch.Tensor): + return inputs.to(dst_type) + elif isinstance(inputs, str): + return inputs + elif isinstance(inputs, np.ndarray): + return inputs + elif isinstance(inputs, abc.Mapping): + return type(inputs)({ + k: cast_tensor_type(v, src_type, dst_type) + for k, v in inputs.items() + }) + elif isinstance(inputs, abc.Iterable): + return type(inputs)( + cast_tensor_type(item, src_type, dst_type) for item in inputs) + else: + return inputs + + +def auto_fp16(apply_to=None, out_fp32=False): + """Decorator to enable fp16 training automatically. + + This decorator is useful when you write custom modules and want to support + mixed precision training. If inputs arguments are fp32 tensors, they will + be converted to fp16 automatically. Arguments other than fp32 tensors are + ignored. + + Args: + apply_to (Iterable, optional): The argument names to be converted. + `None` indicates all arguments. + out_fp32 (bool): Whether to convert the output back to fp32. + + Example: + + >>> import torch.nn as nn + >>> class MyModule1(nn.Module): + >>> + >>> # Convert x and y to fp16 + >>> @auto_fp16() + >>> def forward(self, x, y): + >>> pass + + >>> import torch.nn as nn + >>> class MyModule2(nn.Module): + >>> + >>> # convert pred to fp16 + >>> @auto_fp16(apply_to=('pred', )) + >>> def do_something(self, pred, others): + >>> pass + """ + + def auto_fp16_wrapper(old_func): + + @functools.wraps(old_func) + def new_func(*args, **kwargs): + # check if the module has set the attribute `fp16_enabled`, if not, + # just fallback to the original method. + if not isinstance(args[0], torch.nn.Module): + raise TypeError('@auto_fp16 can only be used to decorate the ' + 'method of nn.Module') + if not (hasattr(args[0], 'fp16_enabled') and args[0].fp16_enabled): + return old_func(*args, **kwargs) + # get the arg spec of the decorated method + args_info = getfullargspec(old_func) + # get the argument names to be casted + args_to_cast = args_info.args if apply_to is None else apply_to + # convert the args that need to be processed + new_args = [] + # NOTE: default args are not taken into consideration + if args: + arg_names = args_info.args[:len(args)] + for i, arg_name in enumerate(arg_names): + if arg_name in args_to_cast: + new_args.append( + cast_tensor_type(args[i], torch.float, torch.half)) + else: + new_args.append(args[i]) + # convert the kwargs that need to be processed + new_kwargs = {} + if kwargs: + for arg_name, arg_value in kwargs.items(): + if arg_name in args_to_cast: + new_kwargs[arg_name] = cast_tensor_type( + arg_value, torch.float, torch.half) + else: + new_kwargs[arg_name] = arg_value + # apply converted arguments to the decorated method + output = old_func(*new_args, **new_kwargs) + # cast the results back to fp32 if necessary + if out_fp32: + output = cast_tensor_type(output, torch.half, torch.float) + return output + + return new_func + + return auto_fp16_wrapper + + +def force_fp32(apply_to=None, out_fp16=False): + """Decorator to convert input arguments to fp32 in force. + + This decorator is useful when you write custom modules and want to support + mixed precision training. If there are some inputs that must be processed + in fp32 mode, then this decorator can handle it. If inputs arguments are + fp16 tensors, they will be converted to fp32 automatically. Arguments other + than fp16 tensors are ignored. + + Args: + apply_to (Iterable, optional): The argument names to be converted. + `None` indicates all arguments. + out_fp16 (bool): Whether to convert the output back to fp16. + + Example: + + >>> import torch.nn as nn + >>> class MyModule1(nn.Module): + >>> + >>> # Convert x and y to fp32 + >>> @force_fp32() + >>> def loss(self, x, y): + >>> pass + + >>> import torch.nn as nn + >>> class MyModule2(nn.Module): + >>> + >>> # convert pred to fp32 + >>> @force_fp32(apply_to=('pred', )) + >>> def post_process(self, pred, others): + >>> pass + """ + + def force_fp32_wrapper(old_func): + + @functools.wraps(old_func) + def new_func(*args, **kwargs): + # check if the module has set the attribute `fp16_enabled`, if not, + # just fallback to the original method. + if not isinstance(args[0], torch.nn.Module): + raise TypeError('@force_fp32 can only be used to decorate the ' + 'method of nn.Module') + if not (hasattr(args[0], 'fp16_enabled') and args[0].fp16_enabled): + return old_func(*args, **kwargs) + # get the arg spec of the decorated method + args_info = getfullargspec(old_func) + # get the argument names to be casted + args_to_cast = args_info.args if apply_to is None else apply_to + # convert the args that need to be processed + new_args = [] + if args: + arg_names = args_info.args[:len(args)] + for i, arg_name in enumerate(arg_names): + if arg_name in args_to_cast: + new_args.append( + cast_tensor_type(args[i], torch.half, torch.float)) + else: + new_args.append(args[i]) + # convert the kwargs that need to be processed + new_kwargs = dict() + if kwargs: + for arg_name, arg_value in kwargs.items(): + if arg_name in args_to_cast: + new_kwargs[arg_name] = cast_tensor_type( + arg_value, torch.half, torch.float) + else: + new_kwargs[arg_name] = arg_value + # apply converted arguments to the decorated method + output = old_func(*new_args, **new_kwargs) + # cast the results back to fp32 if necessary + if out_fp16: + output = cast_tensor_type(output, torch.float, torch.half) + return output + + return new_func + + return force_fp32_wrapper + + +def allreduce_grads(params, coalesce=True, bucket_size_mb=-1): + warnings.warning( + '"mmcv.runner.fp16_utils.allreduce_grads" is deprecated, and will be ' + 'removed in v2.8. Please switch to "mmcv.runner.allreduce_grads') + _allreduce_grads(params, coalesce=coalesce, bucket_size_mb=bucket_size_mb) + + +def wrap_fp16_model(model): + """Wrap the FP32 model to FP16. + + 1. Convert FP32 model to FP16. + 2. Remain some necessary layers to be FP32, e.g., normalization layers. + + Args: + model (nn.Module): Model in FP32. + """ + # convert model to fp16 + model.half() + # patch the normalization layers to make it work in fp32 mode + patch_norm_fp32(model) + # set `fp16_enabled` flag + for m in model.modules(): + if hasattr(m, 'fp16_enabled'): + m.fp16_enabled = True + + +def patch_norm_fp32(module): + """Recursively convert normalization layers from FP16 to FP32. + + Args: + module (nn.Module): The modules to be converted in FP16. + + Returns: + nn.Module: The converted module, the normalization layers have been + converted to FP32. + """ + if isinstance(module, (nn.modules.batchnorm._BatchNorm, nn.GroupNorm, nn.LayerNorm)): + module.float() + # if isinstance(module, nn.GroupNorm) or torch.__version__ < '1.3': + module.forward = patch_forward_method(module.forward, torch.half, + torch.float) + for child in module.children(): + patch_norm_fp32(child) + return module + + +def patch_forward_method(func, src_type, dst_type, convert_output=True): + """Patch the forward method of a module. + + Args: + func (callable): The original forward method. + src_type (torch.dtype): Type of input arguments to be converted from. + dst_type (torch.dtype): Type of input arguments to be converted to. + convert_output (bool): Whether to convert the output back to src_type. + + Returns: + callable: The patched forward method. + """ + + def new_forward(*args, **kwargs): + output = func(*cast_tensor_type(args, src_type, dst_type), + **cast_tensor_type(kwargs, src_type, dst_type)) + if convert_output: + output = cast_tensor_type(output, dst_type, src_type) + return output + + return new_forward + + +class LossScaler: + """Class that manages loss scaling in mixed precision training which + supports both dynamic or static mode. + + The implementation refers to + https://github.com/NVIDIA/apex/blob/master/apex/fp16_utils/loss_scaler.py. + Indirectly, by supplying ``mode='dynamic'`` for dynamic loss scaling. + It's important to understand how :class:`LossScaler` operates. + Loss scaling is designed to combat the problem of underflowing + gradients encountered at long times when training fp16 networks. + Dynamic loss scaling begins by attempting a very high loss + scale. Ironically, this may result in OVERflowing gradients. + If overflowing gradients are encountered, :class:`FP16_Optimizer` then + skips the update step for this particular iteration/minibatch, + and :class:`LossScaler` adjusts the loss scale to a lower value. + If a certain number of iterations occur without overflowing gradients + detected,:class:`LossScaler` increases the loss scale once more. + In this way :class:`LossScaler` attempts to "ride the edge" of always + using the highest loss scale possible without incurring overflow. + + Args: + init_scale (float): Initial loss scale value, default: 2**32. + scale_factor (float): Factor used when adjusting the loss scale. + Default: 2. + mode (str): Loss scaling mode. 'dynamic' or 'static' + scale_window (int): Number of consecutive iterations without an + overflow to wait before increasing the loss scale. Default: 1000. + """ + + def __init__(self, + init_scale=2**32, + mode='dynamic', + scale_factor=2., + scale_window=1000): + self.cur_scale = init_scale + self.cur_iter = 0 + assert mode in ('dynamic', + 'static'), 'mode can only be dynamic or static' + self.mode = mode + self.last_overflow_iter = -1 + self.scale_factor = scale_factor + self.scale_window = scale_window + + def has_overflow(self, params): + """Check if params contain overflow.""" + if self.mode != 'dynamic': + return False + for p in params: + if p.grad is not None and LossScaler._has_inf_or_nan(p.grad.data): + return True + return False + + def _has_inf_or_nan(x): + """Check if params contain NaN.""" + try: + cpu_sum = float(x.float().sum()) + except RuntimeError as instance: + if 'value cannot be converted' not in instance.args[0]: + raise + return True + else: + if cpu_sum == float('inf') or cpu_sum == -float('inf') \ + or cpu_sum != cpu_sum: + return True + return False + + def update_scale(self, overflow): + """update the current loss scale value when overflow happens.""" + if self.mode != 'dynamic': + return + if overflow: + self.cur_scale = max(self.cur_scale / self.scale_factor, 1) + self.last_overflow_iter = self.cur_iter + else: + if (self.cur_iter - self.last_overflow_iter) % \ + self.scale_window == 0: + self.cur_scale *= self.scale_factor + self.cur_iter += 1 + + @property + def loss_scale(self): + return self.cur_scale diff --git a/PyTorch/contrib/cv/semantic_segmentation/SETR/tools/dist_train.sh b/PyTorch/contrib/cv/semantic_segmentation/SETR/tools/dist_train.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/semantic_segmentation/UNet_for_PyTorch/modelzoo_level.txt b/PyTorch/contrib/cv/semantic_segmentation/UNet_for_PyTorch/modelzoo_level.txt index a17c8f95fa388fbc6d253e2cd7cfd0b73b734073..a829ab59b97a1022dd6fc33b59b7ae0d55009432 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/UNet_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/contrib/cv/semantic_segmentation/UNet_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/semantic_segmentation/Wseg/configs/voc_resnet38.yaml b/PyTorch/contrib/cv/semantic_segmentation/Wseg/configs/voc_resnet38.yaml index 7870288e6fe79fbd17946c4e5ee5036bba63a379..b89a2dd6539132dca08fc3a7dc7efc953974fe61 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/Wseg/configs/voc_resnet38.yaml +++ b/PyTorch/contrib/cv/semantic_segmentation/Wseg/configs/voc_resnet38.yaml @@ -1,32 +1,32 @@ -NUM_GPUS: 1 -DATASET: - CROP_SIZE: 321 - SCALE_FROM: 0.9 - SCALE_TO: 1.0 -TRAIN: - BATCH_SIZE: 16 - NUM_EPOCHS: 24 - NUM_WORKERS: 8 - PRETRAIN: 5 -NET: - BACKBONE: "resnet38" - MODEL: "ae" - PRE_WEIGHTS_PATH: "./models/weights/ilsvrc-cls_rna-a1_cls1000_ep-0001.pth" - LR: 0.001 - OPT: "SGD" - LOSS: "SoftMargin" - WEIGHT_DECAY: 0.0005 - PAMR_ITER: 10 - FOCAL_LAMBDA: 0.01 - FOCAL_P: 3 - SG_PSI: 0.3 -TEST: - METHOD: "multiscale" - DATA_ROOT: "./data" - FLIP: True - BATCH_SIZE: 8 - PAD_SIZE: [1024, 1024] - SCALES: [1, 0.5, 1.5, 2.0] - FP_CUT_SCORE: 0.1 - BG_POW: 3 - USE_GT_LABELS: False +NUM_GPUS: 1 +DATASET: + CROP_SIZE: 321 + SCALE_FROM: 0.9 + SCALE_TO: 1.0 +TRAIN: + BATCH_SIZE: 16 + NUM_EPOCHS: 24 + NUM_WORKERS: 8 + PRETRAIN: 5 +NET: + BACKBONE: "resnet38" + MODEL: "ae" + PRE_WEIGHTS_PATH: "./models/weights/ilsvrc-cls_rna-a1_cls1000_ep-0001.pth" + LR: 0.001 + OPT: "SGD" + LOSS: "SoftMargin" + WEIGHT_DECAY: 0.0005 + PAMR_ITER: 10 + FOCAL_LAMBDA: 0.01 + FOCAL_P: 3 + SG_PSI: 0.3 +TEST: + METHOD: "multiscale" + DATA_ROOT: "./data" + FLIP: True + BATCH_SIZE: 8 + PAD_SIZE: [1024, 1024] + SCALES: [1, 0.5, 1.5, 2.0] + FP_CUT_SCORE: 0.1 + BG_POW: 3 + USE_GT_LABELS: False diff --git a/PyTorch/contrib/cv/semantic_segmentation/Wseg/core/config.py b/PyTorch/contrib/cv/semantic_segmentation/Wseg/core/config.py index dee2341357703ac9083ef5869b11ce6d4c2cb9e8..fcc5d5b80853e824835467cd836e03aba16ea6f4 100644 --- a/PyTorch/contrib/cv/semantic_segmentation/Wseg/core/config.py +++ b/PyTorch/contrib/cv/semantic_segmentation/Wseg/core/config.py @@ -1,261 +1,261 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals - - -import yaml -import six -import os -import os.path as osp -import copy -from ast import literal_eval - -import numpy as np -from packaging import version - -from utils.collections import AttrDict - -__C = AttrDict() -# Consumers can get config by: -# from fast_rcnn_config import cfg -cfg = __C - -__C.NUM_GPUS = 1 -# Random note: avoid using '.ON' as a config key since yaml converts it to True; -# prefer 'ENABLED' instead - -# ---------------------------------------------------------------------------- # -# Training options -# ---------------------------------------------------------------------------- # -__C.TRAIN = AttrDict() -__C.TRAIN.BATCH_SIZE = 20 -__C.TRAIN.NUM_EPOCHS = 15 -__C.TRAIN.NUM_WORKERS = 4 -__C.TRAIN.MASK_LOSS = 0.0 -__C.TRAIN.PRETRAIN = 5 - -# ---------------------------------------------------------------------------- # -# Inference options -# ---------------------------------------------------------------------------- # -__C.TEST = AttrDict() -__C.TEST.METHOD = "multiscale" # multiscale | crop -__C.TEST.DATA_ROOT = "/data/your_directory" -__C.TEST.SCALES = [1, 0.5, 1.5, 2.0] -__C.TEST.FLIP = True -__C.TEST.PAD_SIZE = [1024, 1024] -__C.TEST.CROP_SIZE = [448, 448] -__C.TEST.CROP_GRID_SIZE = [2, 2] -__C.TEST.BATCH_SIZE = 8 -__C.TEST.BG_POW = 3 -__C.TEST.NUM_CLASSES = 21 - -# use ground-truth labels to remove -# false positive masks -__C.TEST.USE_GT_LABELS = False - -# if class confidence does not exceed this threshold -# the mask is removed (count as false positive) -# used only if MASKS.USE_GT_LABELS is False -__C.TEST.FP_CUT_SCORE = 0.1 - -# ---------------------------------------------------------------------------- # -# Dataset options -# ---------------------------------------------------------------------------- # -__C.DATASET = AttrDict() - -__C.DATASET.CROP_SIZE = 321 -__C.DATASET.SCALE_FROM = 0.9 -__C.DATASET.SCALE_TO = 1.0 -__C.DATASET.PATH = "data/images" - -# ---------------------------------------------------------------------------- # -# Network options -# ---------------------------------------------------------------------------- # -__C.NET = AttrDict() -__C.NET.MODEL = 'vgg16' -__C.NET.BACKBONE = 'resnet50' -__C.NET.PRE_WEIGHTS_PATH = "" -__C.NET.OPT = 'SGD' -__C.NET.LR = 0.001 -__C.NET.BETA1 = 0.5 -__C.NET.MOMENTUM = 0.9 -__C.NET.WEIGHT_DECAY = 1e-5 -__C.NET.LOSS = 'SoftMargin' -__C.NET.MASK_LOSS_BCE = 1.0 -__C.NET.BG_SCORE = 0.1 # background score (only for CAM) -__C.NET.FOCAL_P = 3 -__C.NET.FOCAL_LAMBDA = 0.01 -__C.NET.PAMR_KERNEL = [1, 2, 4, 8, 12, 24] -__C.NET.PAMR_ITER = 10 -__C.NET.SG_PSI = 0.3 - -# Mask Inference -__C.MASKS = AttrDict() - -# CRF options -__C.MASKS.CRF = AttrDict() -__C.MASKS.CRF.ALPHA_LOW = 4 -__C.MASKS.CRF.ALPHA_HIGH = 32 - -# [Infered value] -__C.CUDA = False - -__C.DEBUG = False - -# [Infered value] -__C.PYTORCH_VERSION_LESS_THAN_040 = False - -def assert_and_infer_cfg(make_immutable=True): - """Call this function in your script after you have finished setting all cfg - values that are necessary (e.g., merging a config from a file, merging - command line config options, etc.). By default, this function will also - mark the global cfg as immutable to prevent changing the global cfg settings - during script execution (which can lead to hard to debug errors or code - that's harder to understand than is necessary). - """ - if make_immutable: - cfg.immutable(True) - - -def merge_cfg_from_file(cfg_filename): - """Load a yaml config file and merge it into the global config.""" - with open(cfg_filename, 'r') as f: - if hasattr(yaml, "FullLoader"): - yaml_cfg = AttrDict(yaml.load(f, Loader=yaml.FullLoader)) - else: - yaml_cfg = AttrDict(yaml.load(f)) - - _merge_a_into_b(yaml_cfg, __C) - -cfg_from_file = merge_cfg_from_file - - -def merge_cfg_from_cfg(cfg_other): - """Merge `cfg_other` into the global config.""" - _merge_a_into_b(cfg_other, __C) - - -def merge_cfg_from_list(cfg_list): - """Merge config keys, values in a list (e.g., from command line) into the - global config. For example, `cfg_list = ['TEST.NMS', 0.5]`. - """ - assert len(cfg_list) % 2 == 0 - for full_key, v in zip(cfg_list[0::2], cfg_list[1::2]): - key_list = full_key.split('.') - d = __C - for subkey in key_list[:-1]: - assert subkey in d, 'Non-existent key: {}'.format(full_key) - d = d[subkey] - subkey = key_list[-1] - assert subkey in d, 'Non-existent key: {}'.format(full_key) - value = _decode_cfg_value(v) - value = _check_and_coerce_cfg_value_type( - value, d[subkey], subkey, full_key - ) - d[subkey] = value - -cfg_from_list = merge_cfg_from_list - - -def _merge_a_into_b(a, b, stack=None): - """Merge config dictionary a into config dictionary b, clobbering the - options in b whenever they are also specified in a. - """ - assert isinstance(a, AttrDict), 'Argument `a` must be an AttrDict' - assert isinstance(b, AttrDict), 'Argument `b` must be an AttrDict' - - for k, v_ in a.items(): - full_key = '.'.join(stack) + '.' + k if stack is not None else k - # a must specify keys that are in b - if k not in b: - raise KeyError('Non-existent config key: {}'.format(full_key)) - - v = copy.deepcopy(v_) - v = _decode_cfg_value(v) - v = _check_and_coerce_cfg_value_type(v, b[k], k, full_key) - - # Recursively merge dicts - if isinstance(v, AttrDict): - try: - stack_push = [k] if stack is None else stack + [k] - _merge_a_into_b(v, b[k], stack=stack_push) - except BaseException: - raise - else: - b[k] = v - - -def _decode_cfg_value(v): - """Decodes a raw config value (e.g., from a yaml config files or command - line argument) into a Python object. - """ - # Configs parsed from raw yaml will contain dictionary keys that need to be - # converted to AttrDict objects - if isinstance(v, dict): - return AttrDict(v) - # All remaining processing is only applied to strings - if not isinstance(v, six.string_types): - return v - # Try to interpret `v` as a: - # string, number, tuple, list, dict, boolean, or None - try: - v = literal_eval(v) - # The following two excepts allow v to pass through when it represents a - # string. - # - # Longer explanation: - # The type of v is always a string (before calling literal_eval), but - # sometimes it *represents* a string and other times a data structure, like - # a list. In the case that v represents a string, what we got back from the - # yaml parser is 'foo' *without quotes* (so, not '"foo"'). literal_eval is - # ok with '"foo"', but will raise a ValueError if given 'foo'. In other - # cases, like paths (v = 'foo/bar' and not v = '"foo/bar"'), literal_eval - # will raise a SyntaxError. - except ValueError: - pass - except SyntaxError: - pass - return v - - -def _check_and_coerce_cfg_value_type(value_a, value_b, key, full_key): - """Checks that `value_a`, which is intended to replace `value_b` is of the - right type. The type is correct if it matches exactly or is one of a few - cases in which the type can be easily coerced. - """ - # The types must match (with some exceptions) - type_b = type(value_b) - type_a = type(value_a) - if type_a is type_b: - return value_a - - # Exceptions: numpy arrays, strings, tuple<->list - if isinstance(value_b, np.ndarray): - value_a = np.array(value_a, dtype=value_b.dtype) - elif isinstance(value_b, six.string_types): - value_a = str(value_a) - elif isinstance(value_a, tuple) and isinstance(value_b, list): - value_a = list(value_a) - elif isinstance(value_a, list) and isinstance(value_b, tuple): - value_a = tuple(value_a) - else: - raise ValueError( - 'Type mismatch ({} vs. {}) with values ({} vs. {}) for config ' - 'key: {}'.format(type_b, type_a, value_b, value_a, full_key) - ) - return value_a +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + + +import yaml +import six +import os +import os.path as osp +import copy +from ast import literal_eval + +import numpy as np +from packaging import version + +from utils.collections import AttrDict + +__C = AttrDict() +# Consumers can get config by: +# from fast_rcnn_config import cfg +cfg = __C + +__C.NUM_GPUS = 1 +# Random note: avoid using '.ON' as a config key since yaml converts it to True; +# prefer 'ENABLED' instead + +# ---------------------------------------------------------------------------- # +# Training options +# ---------------------------------------------------------------------------- # +__C.TRAIN = AttrDict() +__C.TRAIN.BATCH_SIZE = 20 +__C.TRAIN.NUM_EPOCHS = 15 +__C.TRAIN.NUM_WORKERS = 4 +__C.TRAIN.MASK_LOSS = 0.0 +__C.TRAIN.PRETRAIN = 5 + +# ---------------------------------------------------------------------------- # +# Inference options +# ---------------------------------------------------------------------------- # +__C.TEST = AttrDict() +__C.TEST.METHOD = "multiscale" # multiscale | crop +__C.TEST.DATA_ROOT = "/data/your_directory" +__C.TEST.SCALES = [1, 0.5, 1.5, 2.0] +__C.TEST.FLIP = True +__C.TEST.PAD_SIZE = [1024, 1024] +__C.TEST.CROP_SIZE = [448, 448] +__C.TEST.CROP_GRID_SIZE = [2, 2] +__C.TEST.BATCH_SIZE = 8 +__C.TEST.BG_POW = 3 +__C.TEST.NUM_CLASSES = 21 + +# use ground-truth labels to remove +# false positive masks +__C.TEST.USE_GT_LABELS = False + +# if class confidence does not exceed this threshold +# the mask is removed (count as false positive) +# used only if MASKS.USE_GT_LABELS is False +__C.TEST.FP_CUT_SCORE = 0.1 + +# ---------------------------------------------------------------------------- # +# Dataset options +# ---------------------------------------------------------------------------- # +__C.DATASET = AttrDict() + +__C.DATASET.CROP_SIZE = 321 +__C.DATASET.SCALE_FROM = 0.9 +__C.DATASET.SCALE_TO = 1.0 +__C.DATASET.PATH = "data/images" + +# ---------------------------------------------------------------------------- # +# Network options +# ---------------------------------------------------------------------------- # +__C.NET = AttrDict() +__C.NET.MODEL = 'vgg16' +__C.NET.BACKBONE = 'resnet50' +__C.NET.PRE_WEIGHTS_PATH = "" +__C.NET.OPT = 'SGD' +__C.NET.LR = 0.001 +__C.NET.BETA1 = 0.5 +__C.NET.MOMENTUM = 0.9 +__C.NET.WEIGHT_DECAY = 1e-5 +__C.NET.LOSS = 'SoftMargin' +__C.NET.MASK_LOSS_BCE = 1.0 +__C.NET.BG_SCORE = 0.1 # background score (only for CAM) +__C.NET.FOCAL_P = 3 +__C.NET.FOCAL_LAMBDA = 0.01 +__C.NET.PAMR_KERNEL = [1, 2, 4, 8, 12, 24] +__C.NET.PAMR_ITER = 10 +__C.NET.SG_PSI = 0.3 + +# Mask Inference +__C.MASKS = AttrDict() + +# CRF options +__C.MASKS.CRF = AttrDict() +__C.MASKS.CRF.ALPHA_LOW = 4 +__C.MASKS.CRF.ALPHA_HIGH = 32 + +# [Infered value] +__C.CUDA = False + +__C.DEBUG = False + +# [Infered value] +__C.PYTORCH_VERSION_LESS_THAN_040 = False + +def assert_and_infer_cfg(make_immutable=True): + """Call this function in your script after you have finished setting all cfg + values that are necessary (e.g., merging a config from a file, merging + command line config options, etc.). By default, this function will also + mark the global cfg as immutable to prevent changing the global cfg settings + during script execution (which can lead to hard to debug errors or code + that's harder to understand than is necessary). + """ + if make_immutable: + cfg.immutable(True) + + +def merge_cfg_from_file(cfg_filename): + """Load a yaml config file and merge it into the global config.""" + with open(cfg_filename, 'r') as f: + if hasattr(yaml, "FullLoader"): + yaml_cfg = AttrDict(yaml.load(f, Loader=yaml.FullLoader)) + else: + yaml_cfg = AttrDict(yaml.load(f)) + + _merge_a_into_b(yaml_cfg, __C) + +cfg_from_file = merge_cfg_from_file + + +def merge_cfg_from_cfg(cfg_other): + """Merge `cfg_other` into the global config.""" + _merge_a_into_b(cfg_other, __C) + + +def merge_cfg_from_list(cfg_list): + """Merge config keys, values in a list (e.g., from command line) into the + global config. For example, `cfg_list = ['TEST.NMS', 0.5]`. + """ + assert len(cfg_list) % 2 == 0 + for full_key, v in zip(cfg_list[0::2], cfg_list[1::2]): + key_list = full_key.split('.') + d = __C + for subkey in key_list[:-1]: + assert subkey in d, 'Non-existent key: {}'.format(full_key) + d = d[subkey] + subkey = key_list[-1] + assert subkey in d, 'Non-existent key: {}'.format(full_key) + value = _decode_cfg_value(v) + value = _check_and_coerce_cfg_value_type( + value, d[subkey], subkey, full_key + ) + d[subkey] = value + +cfg_from_list = merge_cfg_from_list + + +def _merge_a_into_b(a, b, stack=None): + """Merge config dictionary a into config dictionary b, clobbering the + options in b whenever they are also specified in a. + """ + assert isinstance(a, AttrDict), 'Argument `a` must be an AttrDict' + assert isinstance(b, AttrDict), 'Argument `b` must be an AttrDict' + + for k, v_ in a.items(): + full_key = '.'.join(stack) + '.' + k if stack is not None else k + # a must specify keys that are in b + if k not in b: + raise KeyError('Non-existent config key: {}'.format(full_key)) + + v = copy.deepcopy(v_) + v = _decode_cfg_value(v) + v = _check_and_coerce_cfg_value_type(v, b[k], k, full_key) + + # Recursively merge dicts + if isinstance(v, AttrDict): + try: + stack_push = [k] if stack is None else stack + [k] + _merge_a_into_b(v, b[k], stack=stack_push) + except BaseException: + raise + else: + b[k] = v + + +def _decode_cfg_value(v): + """Decodes a raw config value (e.g., from a yaml config files or command + line argument) into a Python object. + """ + # Configs parsed from raw yaml will contain dictionary keys that need to be + # converted to AttrDict objects + if isinstance(v, dict): + return AttrDict(v) + # All remaining processing is only applied to strings + if not isinstance(v, six.string_types): + return v + # Try to interpret `v` as a: + # string, number, tuple, list, dict, boolean, or None + try: + v = literal_eval(v) + # The following two excepts allow v to pass through when it represents a + # string. + # + # Longer explanation: + # The type of v is always a string (before calling literal_eval), but + # sometimes it *represents* a string and other times a data structure, like + # a list. In the case that v represents a string, what we got back from the + # yaml parser is 'foo' *without quotes* (so, not '"foo"'). literal_eval is + # ok with '"foo"', but will raise a ValueError if given 'foo'. In other + # cases, like paths (v = 'foo/bar' and not v = '"foo/bar"'), literal_eval + # will raise a SyntaxError. + except ValueError: + pass + except SyntaxError: + pass + return v + + +def _check_and_coerce_cfg_value_type(value_a, value_b, key, full_key): + """Checks that `value_a`, which is intended to replace `value_b` is of the + right type. The type is correct if it matches exactly or is one of a few + cases in which the type can be easily coerced. + """ + # The types must match (with some exceptions) + type_b = type(value_b) + type_a = type(value_a) + if type_a is type_b: + return value_a + + # Exceptions: numpy arrays, strings, tuple<->list + if isinstance(value_b, np.ndarray): + value_a = np.array(value_a, dtype=value_b.dtype) + elif isinstance(value_b, six.string_types): + value_a = str(value_a) + elif isinstance(value_a, tuple) and isinstance(value_b, list): + value_a = list(value_a) + elif isinstance(value_a, list) and isinstance(value_b, tuple): + value_a = tuple(value_a) + else: + raise ValueError( + 'Type mismatch ({} vs. {}) with values ({} vs. {}) for config ' + 'key: {}'.format(type_b, type_a, value_b, value_a, full_key) + ) + return value_a diff --git a/PyTorch/contrib/cv/video/C3D/additional_need/mmcv/dist_utils.py b/PyTorch/contrib/cv/video/C3D/additional_need/mmcv/dist_utils.py index 91346643e8f70fb97a407de4b6fda417cd9fa6ee..9e3f2b072b230c45b051270b5730c30822c74a2c 100644 --- a/PyTorch/contrib/cv/video/C3D/additional_need/mmcv/dist_utils.py +++ b/PyTorch/contrib/cv/video/C3D/additional_need/mmcv/dist_utils.py @@ -1,185 +1,185 @@ -# Copyright (c) Open-MMLab. All rights reserved. -# -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import functools -import os -import subprocess -from collections import OrderedDict - -import torch -import torch.multiprocessing as mp -from torch import distributed as dist -from torch._utils import (_flatten_dense_tensors, _take_tensors, - _unflatten_dense_tensors) - -from mmcv.utils import TORCH_VERSION - - -def init_dist(launcher, backend='nccl', **kwargs): - if mp.get_start_method(allow_none=True) is None: - mp.set_start_method('spawn') - if launcher == 'pytorch': - _init_dist_pytorch(backend, **kwargs) - elif launcher == 'mpi': - _init_dist_mpi(backend, **kwargs) - elif launcher == 'slurm': - _init_dist_slurm(backend, **kwargs) - else: - raise ValueError(f'Invalid launcher type: {launcher}') - - -def _init_dist_pytorch(backend, **kwargs): - # TODO: use local_rank instead of rank % num_gpus - rank = int(os.environ['RANK']) - offset = 0 if os.getenv('NPUID', None) is None else int(os.environ['NPUID']) - num_gpus = torch.npu.device_count() - torch.npu.set_device((rank + offset) % num_gpus) - dist.init_process_group(backend=backend, **kwargs) - - -def _init_dist_mpi(backend, **kwargs): - # TODO: use local_rank instead of rank % num_gpus - rank = int(os.environ['OMPI_COMM_WORLD_RANK']) - num_gpus = torch.cuda.device_count() - torch.cuda.set_device(rank % num_gpus) - dist.init_process_group(backend=backend, **kwargs) - - -def _init_dist_slurm(backend, port=None): - """Initialize slurm distributed training environment. - If argument ``port`` is not specified, then the master port will be system - environment variable ``MASTER_PORT``. If ``MASTER_PORT`` is not in system - environment variable, then a default port ``29500`` will be used. - Args: - backend (str): Backend of torch.distributed. - port (int, optional): Master port. Defaults to None. - """ - proc_id = int(os.environ['SLURM_PROCID']) - ntasks = int(os.environ['SLURM_NTASKS']) - node_list = os.environ['SLURM_NODELIST'] - num_gpus = torch.cuda.device_count() - torch.cuda.set_device(proc_id % num_gpus) - addr = subprocess.getoutput( - f'scontrol show hostname {node_list} | head -n1') - # specify master port - if port is not None: - os.environ['MASTER_PORT'] = str(port) - elif 'MASTER_PORT' in os.environ: - pass # use MASTER_PORT in the environment variable - else: - # 29500 is torch.distributed default port - os.environ['MASTER_PORT'] = '29500' - # use MASTER_ADDR in the environment variable if it already exists - if 'MASTER_ADDR' not in os.environ: - os.environ['MASTER_ADDR'] = addr - os.environ['WORLD_SIZE'] = str(ntasks) - os.environ['LOCAL_RANK'] = str(proc_id % num_gpus) - os.environ['RANK'] = str(proc_id) - dist.init_process_group(backend=backend) - - -def get_dist_info(): - if TORCH_VERSION < '1.0': - initialized = dist._initialized - else: - if dist.is_available(): - initialized = dist.is_initialized() - else: - initialized = False - if initialized: - rank = dist.get_rank() - world_size = dist.get_world_size() - else: - rank = 0 - world_size = 1 - return rank, world_size - - -def master_only(func): - - @functools.wraps(func) - def wrapper(*args, **kwargs): - rank, _ = get_dist_info() - if rank == 0: - return func(*args, **kwargs) - - return wrapper - - -def allreduce_params(params, coalesce=True, bucket_size_mb=-1): - """Allreduce parameters. - Args: - params (list[torch.Parameters]): List of parameters or buffers of a - model. - coalesce (bool, optional): Whether allreduce parameters as a whole. - Defaults to True. - bucket_size_mb (int, optional): Size of bucket, the unit is MB. - Defaults to -1. - """ - _, world_size = get_dist_info() - if world_size == 1: - return - params = [param.data for param in params] - if coalesce: - _allreduce_coalesced(params, world_size, bucket_size_mb) - else: - for tensor in params: - dist.all_reduce(tensor.div_(world_size)) - - -def allreduce_grads(params, coalesce=True, bucket_size_mb=-1): - """Allreduce gradients. - Args: - params (list[torch.Parameters]): List of parameters of a model - coalesce (bool, optional): Whether allreduce parameters as a whole. - Defaults to True. - bucket_size_mb (int, optional): Size of bucket, the unit is MB. - Defaults to -1. - """ - grads = [ - param.grad.data for param in params - if param.requires_grad and param.grad is not None - ] - _, world_size = get_dist_info() - if world_size == 1: - return - if coalesce: - _allreduce_coalesced(grads, world_size, bucket_size_mb) - else: - for tensor in grads: - dist.all_reduce(tensor.div_(world_size)) - - -def _allreduce_coalesced(tensors, world_size, bucket_size_mb=-1): - if bucket_size_mb > 0: - bucket_size_bytes = bucket_size_mb * 1024 * 1024 - buckets = _take_tensors(tensors, bucket_size_bytes) - else: - buckets = OrderedDict() - for tensor in tensors: - tp = tensor.type() - if tp not in buckets: - buckets[tp] = [] - buckets[tp].append(tensor) - buckets = buckets.values() - - for bucket in buckets: - flat_tensors = _flatten_dense_tensors(bucket) - dist.all_reduce(flat_tensors) - flat_tensors.div_(world_size) - for tensor, synced in zip( - bucket, _unflatten_dense_tensors(flat_tensors, bucket)): +# Copyright (c) Open-MMLab. All rights reserved. +# +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import functools +import os +import subprocess +from collections import OrderedDict + +import torch +import torch.multiprocessing as mp +from torch import distributed as dist +from torch._utils import (_flatten_dense_tensors, _take_tensors, + _unflatten_dense_tensors) + +from mmcv.utils import TORCH_VERSION + + +def init_dist(launcher, backend='nccl', **kwargs): + if mp.get_start_method(allow_none=True) is None: + mp.set_start_method('spawn') + if launcher == 'pytorch': + _init_dist_pytorch(backend, **kwargs) + elif launcher == 'mpi': + _init_dist_mpi(backend, **kwargs) + elif launcher == 'slurm': + _init_dist_slurm(backend, **kwargs) + else: + raise ValueError(f'Invalid launcher type: {launcher}') + + +def _init_dist_pytorch(backend, **kwargs): + # TODO: use local_rank instead of rank % num_gpus + rank = int(os.environ['RANK']) + offset = 0 if os.getenv('NPUID', None) is None else int(os.environ['NPUID']) + num_gpus = torch.npu.device_count() + torch.npu.set_device((rank + offset) % num_gpus) + dist.init_process_group(backend=backend, **kwargs) + + +def _init_dist_mpi(backend, **kwargs): + # TODO: use local_rank instead of rank % num_gpus + rank = int(os.environ['OMPI_COMM_WORLD_RANK']) + num_gpus = torch.cuda.device_count() + torch.cuda.set_device(rank % num_gpus) + dist.init_process_group(backend=backend, **kwargs) + + +def _init_dist_slurm(backend, port=None): + """Initialize slurm distributed training environment. + If argument ``port`` is not specified, then the master port will be system + environment variable ``MASTER_PORT``. If ``MASTER_PORT`` is not in system + environment variable, then a default port ``29500`` will be used. + Args: + backend (str): Backend of torch.distributed. + port (int, optional): Master port. Defaults to None. + """ + proc_id = int(os.environ['SLURM_PROCID']) + ntasks = int(os.environ['SLURM_NTASKS']) + node_list = os.environ['SLURM_NODELIST'] + num_gpus = torch.cuda.device_count() + torch.cuda.set_device(proc_id % num_gpus) + addr = subprocess.getoutput( + f'scontrol show hostname {node_list} | head -n1') + # specify master port + if port is not None: + os.environ['MASTER_PORT'] = str(port) + elif 'MASTER_PORT' in os.environ: + pass # use MASTER_PORT in the environment variable + else: + # 29500 is torch.distributed default port + os.environ['MASTER_PORT'] = '29500' + # use MASTER_ADDR in the environment variable if it already exists + if 'MASTER_ADDR' not in os.environ: + os.environ['MASTER_ADDR'] = addr + os.environ['WORLD_SIZE'] = str(ntasks) + os.environ['LOCAL_RANK'] = str(proc_id % num_gpus) + os.environ['RANK'] = str(proc_id) + dist.init_process_group(backend=backend) + + +def get_dist_info(): + if TORCH_VERSION < '1.0': + initialized = dist._initialized + else: + if dist.is_available(): + initialized = dist.is_initialized() + else: + initialized = False + if initialized: + rank = dist.get_rank() + world_size = dist.get_world_size() + else: + rank = 0 + world_size = 1 + return rank, world_size + + +def master_only(func): + + @functools.wraps(func) + def wrapper(*args, **kwargs): + rank, _ = get_dist_info() + if rank == 0: + return func(*args, **kwargs) + + return wrapper + + +def allreduce_params(params, coalesce=True, bucket_size_mb=-1): + """Allreduce parameters. + Args: + params (list[torch.Parameters]): List of parameters or buffers of a + model. + coalesce (bool, optional): Whether allreduce parameters as a whole. + Defaults to True. + bucket_size_mb (int, optional): Size of bucket, the unit is MB. + Defaults to -1. + """ + _, world_size = get_dist_info() + if world_size == 1: + return + params = [param.data for param in params] + if coalesce: + _allreduce_coalesced(params, world_size, bucket_size_mb) + else: + for tensor in params: + dist.all_reduce(tensor.div_(world_size)) + + +def allreduce_grads(params, coalesce=True, bucket_size_mb=-1): + """Allreduce gradients. + Args: + params (list[torch.Parameters]): List of parameters of a model + coalesce (bool, optional): Whether allreduce parameters as a whole. + Defaults to True. + bucket_size_mb (int, optional): Size of bucket, the unit is MB. + Defaults to -1. + """ + grads = [ + param.grad.data for param in params + if param.requires_grad and param.grad is not None + ] + _, world_size = get_dist_info() + if world_size == 1: + return + if coalesce: + _allreduce_coalesced(grads, world_size, bucket_size_mb) + else: + for tensor in grads: + dist.all_reduce(tensor.div_(world_size)) + + +def _allreduce_coalesced(tensors, world_size, bucket_size_mb=-1): + if bucket_size_mb > 0: + bucket_size_bytes = bucket_size_mb * 1024 * 1024 + buckets = _take_tensors(tensors, bucket_size_bytes) + else: + buckets = OrderedDict() + for tensor in tensors: + tp = tensor.type() + if tp not in buckets: + buckets[tp] = [] + buckets[tp].append(tensor) + buckets = buckets.values() + + for bucket in buckets: + flat_tensors = _flatten_dense_tensors(bucket) + dist.all_reduce(flat_tensors) + flat_tensors.div_(world_size) + for tensor, synced in zip( + bucket, _unflatten_dense_tensors(flat_tensors, bucket)): tensor.copy_(synced) \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/C3D/additional_need/mmcv/distributed.py b/PyTorch/contrib/cv/video/C3D/additional_need/mmcv/distributed.py index fb2bae922930929dc6fa46ad612463cc335dc208..4c89d09fc490488789ce565a7bad43ce7ded1568 100644 --- a/PyTorch/contrib/cv/video/C3D/additional_need/mmcv/distributed.py +++ b/PyTorch/contrib/cv/video/C3D/additional_need/mmcv/distributed.py @@ -1,119 +1,119 @@ -# Copyright (c) Open-MMLab. All rights reserved. -# -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -from torch.nn.parallel.distributed import (DistributedDataParallel, - _find_tensors) - -from mmcv import print_log -from mmcv.utils import TORCH_VERSION -from .scatter_gather import scatter_kwargs - - -class MMDistributedDataParallel(DistributedDataParallel): - """The DDP module that supports DataContainer. - - MMDDP has two main differences with PyTorch DDP: - - - It supports a custom type :class:`DataContainer` which allows more - flexible control of input data. - - It implement two APIs ``train_step()`` and ``val_step()``. - """ - - def scatter(self, inputs, kwargs, device_ids): - return scatter_kwargs(inputs, kwargs, device_ids, dim=self.dim) - - def train_step(self, *inputs, **kwargs): - """train_step() API for module wrapped by DistributedDataParallel. - - This method is basically the same as - ``DistributedDataParallel.forward()``, while replacing - ``self.module.forward()`` with ``self.module.train_step()``. - It is compatible with PyTorch 1.1 - 1.5. - """ - - # In PyTorch >= 1.7, ``reducer._rebuild_buckets()`` is moved from the - # end of backward to the beginning of forward. - if (TORCH_VERSION >= '1.7' and 'parrots' - not in TORCH_VERSION) and self.reducer._rebuild_buckets(): - print_log( - 'Reducer buckets have been rebuilt in this iteration.', - logger='mmcv') - - if getattr(self, 'require_forward_param_sync', True): - self._sync_params() - if self.device_ids and False: - inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) - if len(self.device_ids) == 1: - output = self.module.train_step(*inputs[0], **kwargs[0]) - else: - outputs = self.parallel_apply( - self._module_copies[:len(inputs)], inputs, kwargs) - output = self.gather(outputs, self.output_device) - else: - inputs, kwargs = self.scatter(inputs, kwargs, [-1]) - output = self.module.train_step(*inputs[0], **kwargs[0]) - - if torch.is_grad_enabled() and getattr( - self, 'require_backward_grad_sync', True): - if self.find_unused_parameters: - self.reducer.prepare_for_backward(list(_find_tensors(output))) - else: - self.reducer.prepare_for_backward([]) - else: - if TORCH_VERSION > '1.2': - self.require_forward_param_sync = False - return output - - def val_step(self, *inputs, **kwargs): - """val_step() API for module wrapped by DistributedDataParallel. - - This method is basically the same as - ``DistributedDataParallel.forward()``, while replacing - ``self.module.forward()`` with ``self.module.val_step()``. - It is compatible with PyTorch 1.1 - 1.5. - """ - # In PyTorch >= 1.7, ``reducer._rebuild_buckets()`` is moved from the - # end of backward to the beginning of forward. - if (TORCH_VERSION >= '1.7' and 'parrots' - not in TORCH_VERSION) and self.reducer._rebuild_buckets(): - print_log( - 'Reducer buckets have been rebuilt in this iteration.', - logger='mmcv') - - if getattr(self, 'require_forward_param_sync', True): - self._sync_params() - if self.device_ids: - inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) - if len(self.device_ids) == 1: - output = self.module.val_step(*inputs[0], **kwargs[0]) - else: - outputs = self.parallel_apply( - self._module_copies[:len(inputs)], inputs, kwargs) - output = self.gather(outputs, self.output_device) - else: - output = self.module.val_step(*inputs, **kwargs) - - if torch.is_grad_enabled() and getattr( - self, 'require_backward_grad_sync', True): - if self.find_unused_parameters: - self.reducer.prepare_for_backward(list(_find_tensors(output))) - else: - self.reducer.prepare_for_backward([]) - else: - if TORCH_VERSION > '1.2': - self.require_forward_param_sync = False - return output +# Copyright (c) Open-MMLab. All rights reserved. +# +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +from torch.nn.parallel.distributed import (DistributedDataParallel, + _find_tensors) + +from mmcv import print_log +from mmcv.utils import TORCH_VERSION +from .scatter_gather import scatter_kwargs + + +class MMDistributedDataParallel(DistributedDataParallel): + """The DDP module that supports DataContainer. + + MMDDP has two main differences with PyTorch DDP: + + - It supports a custom type :class:`DataContainer` which allows more + flexible control of input data. + - It implement two APIs ``train_step()`` and ``val_step()``. + """ + + def scatter(self, inputs, kwargs, device_ids): + return scatter_kwargs(inputs, kwargs, device_ids, dim=self.dim) + + def train_step(self, *inputs, **kwargs): + """train_step() API for module wrapped by DistributedDataParallel. + + This method is basically the same as + ``DistributedDataParallel.forward()``, while replacing + ``self.module.forward()`` with ``self.module.train_step()``. + It is compatible with PyTorch 1.1 - 1.5. + """ + + # In PyTorch >= 1.7, ``reducer._rebuild_buckets()`` is moved from the + # end of backward to the beginning of forward. + if (TORCH_VERSION >= '1.7' and 'parrots' + not in TORCH_VERSION) and self.reducer._rebuild_buckets(): + print_log( + 'Reducer buckets have been rebuilt in this iteration.', + logger='mmcv') + + if getattr(self, 'require_forward_param_sync', True): + self._sync_params() + if self.device_ids and False: + inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) + if len(self.device_ids) == 1: + output = self.module.train_step(*inputs[0], **kwargs[0]) + else: + outputs = self.parallel_apply( + self._module_copies[:len(inputs)], inputs, kwargs) + output = self.gather(outputs, self.output_device) + else: + inputs, kwargs = self.scatter(inputs, kwargs, [-1]) + output = self.module.train_step(*inputs[0], **kwargs[0]) + + if torch.is_grad_enabled() and getattr( + self, 'require_backward_grad_sync', True): + if self.find_unused_parameters: + self.reducer.prepare_for_backward(list(_find_tensors(output))) + else: + self.reducer.prepare_for_backward([]) + else: + if TORCH_VERSION > '1.2': + self.require_forward_param_sync = False + return output + + def val_step(self, *inputs, **kwargs): + """val_step() API for module wrapped by DistributedDataParallel. + + This method is basically the same as + ``DistributedDataParallel.forward()``, while replacing + ``self.module.forward()`` with ``self.module.val_step()``. + It is compatible with PyTorch 1.1 - 1.5. + """ + # In PyTorch >= 1.7, ``reducer._rebuild_buckets()`` is moved from the + # end of backward to the beginning of forward. + if (TORCH_VERSION >= '1.7' and 'parrots' + not in TORCH_VERSION) and self.reducer._rebuild_buckets(): + print_log( + 'Reducer buckets have been rebuilt in this iteration.', + logger='mmcv') + + if getattr(self, 'require_forward_param_sync', True): + self._sync_params() + if self.device_ids: + inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) + if len(self.device_ids) == 1: + output = self.module.val_step(*inputs[0], **kwargs[0]) + else: + outputs = self.parallel_apply( + self._module_copies[:len(inputs)], inputs, kwargs) + output = self.gather(outputs, self.output_device) + else: + output = self.module.val_step(*inputs, **kwargs) + + if torch.is_grad_enabled() and getattr( + self, 'require_backward_grad_sync', True): + if self.find_unused_parameters: + self.reducer.prepare_for_backward(list(_find_tensors(output))) + else: + self.reducer.prepare_for_backward([]) + else: + if TORCH_VERSION > '1.2': + self.require_forward_param_sync = False + return output diff --git a/PyTorch/contrib/cv/video/C3D/additional_need/mmcv/optimizer.py b/PyTorch/contrib/cv/video/C3D/additional_need/mmcv/optimizer.py index 59eff597b8c798f9189b569b970778be1335dfd5..4219fcf100e49d5f49f9c3fa05959cfbb53601fa 100644 --- a/PyTorch/contrib/cv/video/C3D/additional_need/mmcv/optimizer.py +++ b/PyTorch/contrib/cv/video/C3D/additional_need/mmcv/optimizer.py @@ -1,182 +1,182 @@ -# Copyright (c) Open-MMLab. All rights reserved. -# -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import copy -from collections import defaultdict -from itertools import chain - -from torch.nn.utils import clip_grad - -from ..dist_utils import allreduce_grads -from ..fp16_utils import LossScaler, wrap_fp16_model -from .hook import HOOKS, Hook -from apex import amp +# Copyright (c) Open-MMLab. All rights reserved. +# +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import copy +from collections import defaultdict +from itertools import chain + +from torch.nn.utils import clip_grad + +from ..dist_utils import allreduce_grads +from ..fp16_utils import LossScaler, wrap_fp16_model +from .hook import HOOKS, Hook +from apex import amp import time - -@HOOKS.register_module() -class OptimizerHook(Hook): - - def __init__(self, grad_clip=None): - self.grad_clip = grad_clip - - def clip_grads(self, params): - params = list( - filter(lambda p: p.requires_grad and p.grad is not None, params)) - #todo add a line - if len(params) > 0: - return clip_grad.clip_grad_norm_(params, **self.grad_clip) - - def after_train_iter(self, runner): - runner.optimizer.zero_grad() - with amp.scale_loss(runner.outputs['loss'], runner.optimizer ) as scaled_loss: - scaled_loss.backward() - if self.grad_clip is not None: - grad_norm = self.clip_grads(runner.model.npu().parameters()) - if grad_norm is not None: - # Add grad norm to the logger - runner.log_buffer.update({'grad_norm': float(grad_norm)}, - runner.outputs['num_samples']) + +@HOOKS.register_module() +class OptimizerHook(Hook): + + def __init__(self, grad_clip=None): + self.grad_clip = grad_clip + + def clip_grads(self, params): + params = list( + filter(lambda p: p.requires_grad and p.grad is not None, params)) + #todo add a line + if len(params) > 0: + return clip_grad.clip_grad_norm_(params, **self.grad_clip) + + def after_train_iter(self, runner): + runner.optimizer.zero_grad() + with amp.scale_loss(runner.outputs['loss'], runner.optimizer ) as scaled_loss: + scaled_loss.backward() + if self.grad_clip is not None: + grad_norm = self.clip_grads(runner.model.npu().parameters()) + if grad_norm is not None: + # Add grad norm to the logger + runner.log_buffer.update({'grad_norm': float(grad_norm)}, + runner.outputs['num_samples']) runner.optimizer.step() runner.batch_time.update(time.time()-runner.end) - runner.end = time.time() - - - -@HOOKS.register_module() -class Fp16OptimizerHook(OptimizerHook): - """FP16 optimizer hook. - - The steps of fp16 optimizer is as follows. - 1. Scale the loss value. - 2. BP in the fp16 model. - 2. Copy gradients from fp16 model to fp32 weights. - 3. Update fp32 weights. - 4. Copy updated parameters from fp32 weights to fp16 model. - - Refer to https://arxiv.org/abs/1710.03740 for more details. - - Args: - loss_scale (float | str | dict): Scale factor multiplied with loss. - If loss_scale is a float, static loss scaling will be used with - the specified scale. If loss_scale is a string, it must be - 'dynamic', then dynamic loss scaling will be used. - It can also be a dict containing arguments of LossScaler. - Defaults to 512. - """ - - def __init__(self, - grad_clip=None, - coalesce=True, - bucket_size_mb=-1, - loss_scale=512., - distributed=True): - self.grad_clip = grad_clip - self.coalesce = coalesce - self.bucket_size_mb = bucket_size_mb - self.distributed = distributed - if loss_scale == 'dynamic': - self.loss_scaler = LossScaler(mode='dynamic') - elif isinstance(loss_scale, float): - self.loss_scaler = LossScaler(init_scale=loss_scale, mode='static') - elif isinstance(loss_scale, dict): - self.loss_scaler = LossScaler(**loss_scale) - else: - raise ValueError('loss_scale must be of type float, dict, or ' - f'"dynamic", got {loss_scale}') - - def before_run(self, runner): - """Preparing steps before Mixed Precision Training. - - 1. Make a master copy of fp32 weights for optimization. - 2. Convert the main model from fp32 to fp16. - """ - # keep a copy of fp32 weights - old_groups = runner.optimizer.param_groups - runner.optimizer.param_groups = copy.deepcopy( - runner.optimizer.param_groups) - state = defaultdict(dict) - p_map = { - old_p: p - for old_p, p in zip( - chain(*(g['params'] for g in old_groups)), - chain(*(g['params'] for g in runner.optimizer.param_groups))) - } - for k, v in runner.optimizer.state.items(): - state[p_map[k]] = v - runner.optimizer.state = state - # convert model to fp16 - wrap_fp16_model(runner.model) - - def copy_grads_to_fp32(self, fp16_net, fp32_weights): - """Copy gradients from fp16 model to fp32 weight copy.""" - for fp32_param, fp16_param in zip(fp32_weights, fp16_net.parameters()): - if fp16_param.grad is not None: - if fp32_param.grad is None: - fp32_param.grad = fp32_param.data.new(fp32_param.size()) - fp32_param.grad.copy_(fp16_param.grad) - - def copy_params_to_fp16(self, fp16_net, fp32_weights): - """Copy updated params from fp32 weight copy to fp16 model.""" - for fp16_param, fp32_param in zip(fp16_net.parameters(), fp32_weights): - fp16_param.data.copy_(fp32_param.data) - - def after_train_iter(self, runner): - """Backward optimization steps for Mixed Precision Training. For - dynamic loss scaling, please refer `loss_scalar.py` - - 1. Scale the loss by a scale factor. - 2. Backward the loss to obtain the gradients (fp16). - 3. Copy gradients from the model to the fp32 weight copy. - 4. Scale the gradients back and update the fp32 weight copy. - 5. Copy back the params from fp32 weight copy to the fp16 model. - """ - # clear grads of last iteration - runner.model.zero_grad() - runner.optimizer.zero_grad() - # scale the loss value - scaled_loss = runner.outputs['loss'] * self.loss_scaler.loss_scale - scaled_loss.backward() - # copy fp16 grads in the model to fp32 params in the optimizer - - fp32_weights = [] - for param_group in runner.optimizer.param_groups: - fp32_weights += param_group['params'] - self.copy_grads_to_fp32(runner.model, fp32_weights) - # allreduce grads - if self.distributed: - allreduce_grads(fp32_weights, self.coalesce, self.bucket_size_mb) - - has_overflow = self.loss_scaler.has_overflow(fp32_weights) - # if has overflow, skip this iteration - if not has_overflow: - # scale the gradients back - for param in fp32_weights: - if param.grad is not None: - param.grad.div_(self.loss_scaler.loss_scale) - if self.grad_clip is not None: - grad_norm = self.clip_grads(fp32_weights) - if grad_norm is not None: - # Add grad norm to the logger - runner.log_buffer.update({'grad_norm': float(grad_norm)}, - runner.outputs['num_samples']) - # update fp32 params - runner.optimizer.step() - # copy fp32 params to the fp16 model - self.copy_params_to_fp16(runner.model, fp32_weights) - self.loss_scaler.update_scale(has_overflow) - if has_overflow: - runner.logger.warning('Check overflow, downscale loss scale ' - f'to {self.loss_scaler.cur_scale}') + runner.end = time.time() + + + +@HOOKS.register_module() +class Fp16OptimizerHook(OptimizerHook): + """FP16 optimizer hook. + + The steps of fp16 optimizer is as follows. + 1. Scale the loss value. + 2. BP in the fp16 model. + 2. Copy gradients from fp16 model to fp32 weights. + 3. Update fp32 weights. + 4. Copy updated parameters from fp32 weights to fp16 model. + + Refer to https://arxiv.org/abs/1710.03740 for more details. + + Args: + loss_scale (float | str | dict): Scale factor multiplied with loss. + If loss_scale is a float, static loss scaling will be used with + the specified scale. If loss_scale is a string, it must be + 'dynamic', then dynamic loss scaling will be used. + It can also be a dict containing arguments of LossScaler. + Defaults to 512. + """ + + def __init__(self, + grad_clip=None, + coalesce=True, + bucket_size_mb=-1, + loss_scale=512., + distributed=True): + self.grad_clip = grad_clip + self.coalesce = coalesce + self.bucket_size_mb = bucket_size_mb + self.distributed = distributed + if loss_scale == 'dynamic': + self.loss_scaler = LossScaler(mode='dynamic') + elif isinstance(loss_scale, float): + self.loss_scaler = LossScaler(init_scale=loss_scale, mode='static') + elif isinstance(loss_scale, dict): + self.loss_scaler = LossScaler(**loss_scale) + else: + raise ValueError('loss_scale must be of type float, dict, or ' + f'"dynamic", got {loss_scale}') + + def before_run(self, runner): + """Preparing steps before Mixed Precision Training. + + 1. Make a master copy of fp32 weights for optimization. + 2. Convert the main model from fp32 to fp16. + """ + # keep a copy of fp32 weights + old_groups = runner.optimizer.param_groups + runner.optimizer.param_groups = copy.deepcopy( + runner.optimizer.param_groups) + state = defaultdict(dict) + p_map = { + old_p: p + for old_p, p in zip( + chain(*(g['params'] for g in old_groups)), + chain(*(g['params'] for g in runner.optimizer.param_groups))) + } + for k, v in runner.optimizer.state.items(): + state[p_map[k]] = v + runner.optimizer.state = state + # convert model to fp16 + wrap_fp16_model(runner.model) + + def copy_grads_to_fp32(self, fp16_net, fp32_weights): + """Copy gradients from fp16 model to fp32 weight copy.""" + for fp32_param, fp16_param in zip(fp32_weights, fp16_net.parameters()): + if fp16_param.grad is not None: + if fp32_param.grad is None: + fp32_param.grad = fp32_param.data.new(fp32_param.size()) + fp32_param.grad.copy_(fp16_param.grad) + + def copy_params_to_fp16(self, fp16_net, fp32_weights): + """Copy updated params from fp32 weight copy to fp16 model.""" + for fp16_param, fp32_param in zip(fp16_net.parameters(), fp32_weights): + fp16_param.data.copy_(fp32_param.data) + + def after_train_iter(self, runner): + """Backward optimization steps for Mixed Precision Training. For + dynamic loss scaling, please refer `loss_scalar.py` + + 1. Scale the loss by a scale factor. + 2. Backward the loss to obtain the gradients (fp16). + 3. Copy gradients from the model to the fp32 weight copy. + 4. Scale the gradients back and update the fp32 weight copy. + 5. Copy back the params from fp32 weight copy to the fp16 model. + """ + # clear grads of last iteration + runner.model.zero_grad() + runner.optimizer.zero_grad() + # scale the loss value + scaled_loss = runner.outputs['loss'] * self.loss_scaler.loss_scale + scaled_loss.backward() + # copy fp16 grads in the model to fp32 params in the optimizer + + fp32_weights = [] + for param_group in runner.optimizer.param_groups: + fp32_weights += param_group['params'] + self.copy_grads_to_fp32(runner.model, fp32_weights) + # allreduce grads + if self.distributed: + allreduce_grads(fp32_weights, self.coalesce, self.bucket_size_mb) + + has_overflow = self.loss_scaler.has_overflow(fp32_weights) + # if has overflow, skip this iteration + if not has_overflow: + # scale the gradients back + for param in fp32_weights: + if param.grad is not None: + param.grad.div_(self.loss_scaler.loss_scale) + if self.grad_clip is not None: + grad_norm = self.clip_grads(fp32_weights) + if grad_norm is not None: + # Add grad norm to the logger + runner.log_buffer.update({'grad_norm': float(grad_norm)}, + runner.outputs['num_samples']) + # update fp32 params + runner.optimizer.step() + # copy fp32 params to the fp16 model + self.copy_params_to_fp16(runner.model, fp32_weights) + self.loss_scaler.update_scale(has_overflow) + if has_overflow: + runner.logger.warning('Check overflow, downscale loss scale ' + f'to {self.loss_scaler.cur_scale}') diff --git a/PyTorch/contrib/cv/video/C3D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_1p.py b/PyTorch/contrib/cv/video/C3D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_1p.py index a2efdbe74322f30057214c44af9804bd7ae93c19..f5475765077c996f0a54187b24a09986a57851d7 100644 --- a/PyTorch/contrib/cv/video/C3D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_1p.py +++ b/PyTorch/contrib/cv/video/C3D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_1p.py @@ -1,113 +1,113 @@ -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -_base_ = [ - '../../_base_/models/r2plus1d_r34.py', - '../../_base_/default_runtime.py' -] - -# dataset settings -dataset_type = 'RawframeDataset' -data_root = 'data/ucf101/rawframes/' -data_root_val = 'data/ucf101/rawframes/' -split = 1 # official train/test splits. valid numbers: 1, 2, 3 -ann_file_train = f'data/ucf101/ucf101_train_split_{split}_rawframes.txt' -ann_file_val = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' -ann_file_test = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' -img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) -train_pipeline = [ - dict(type='SampleFrames', clip_len=8, frame_interval=8, num_clips=1), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='RandomResizedCrop'), - dict(type='Resize', scale=(224, 224), keep_ratio=False), - dict(type='Flip', flip_ratio=0.5), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs', 'label']) -] -val_pipeline = [ - dict( - type='SampleFrames', - clip_len=8, - frame_interval=8, - num_clips=1, - test_mode=True), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='CenterCrop', crop_size=224), - dict(type='Flip', flip_ratio=0), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs']) -] -test_pipeline = [ - dict( - type='SampleFrames', - clip_len=8, - frame_interval=8, - num_clips=10, - test_mode=True), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='ThreeCrop', crop_size=256), - dict(type='Flip', flip_ratio=0), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs']) -] -data = dict( - videos_per_gpu=16, - workers_per_gpu=4, - train=dict( - type=dataset_type, - ann_file=ann_file_train, - data_prefix=data_root, - pipeline=train_pipeline), - val=dict( - type=dataset_type, - ann_file=ann_file_val, - data_prefix=data_root_val, - pipeline=val_pipeline), - test=dict( - type=dataset_type, - ann_file=ann_file_val, - data_prefix=data_root_val, - pipeline=test_pipeline)) -# optimizer -optimizer = dict( - type='SGD', lr=0.0025, momentum=0.9, - weight_decay=0.0001) # this lr is used for 8 gpus -optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) -# learning policy -# lr_config = dict(policy='step', steps=[1,2,3], lrs=[1e-3,1e-4,1e-5]) -lr_config = dict(policy='CosineAnnealing', min_lr=0) -total_epochs = 60 -# total_epochs = 90 - -# runtime settings -checkpoint_config = dict(interval=5) -evaluation = dict( - interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) -#work_dir = './work_dirs/r2plus1d_r34_8x8x1_180e_ucf101_rgb3/' -find_unused_parameters = True -load_from = 'https://download.openmmlab.com/mmaction/recognition/r2plus1d/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb_20200729-aa94765e.pth' -resume_from = None - +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +_base_ = [ + '../../_base_/models/r2plus1d_r34.py', + '../../_base_/default_runtime.py' +] + +# dataset settings +dataset_type = 'RawframeDataset' +data_root = 'data/ucf101/rawframes/' +data_root_val = 'data/ucf101/rawframes/' +split = 1 # official train/test splits. valid numbers: 1, 2, 3 +ann_file_train = f'data/ucf101/ucf101_train_split_{split}_rawframes.txt' +ann_file_val = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' +ann_file_test = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) +train_pipeline = [ + dict(type='SampleFrames', clip_len=8, frame_interval=8, num_clips=1), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='RandomResizedCrop'), + dict(type='Resize', scale=(224, 224), keep_ratio=False), + dict(type='Flip', flip_ratio=0.5), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs', 'label']) +] +val_pipeline = [ + dict( + type='SampleFrames', + clip_len=8, + frame_interval=8, + num_clips=1, + test_mode=True), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='CenterCrop', crop_size=224), + dict(type='Flip', flip_ratio=0), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs']) +] +test_pipeline = [ + dict( + type='SampleFrames', + clip_len=8, + frame_interval=8, + num_clips=10, + test_mode=True), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='ThreeCrop', crop_size=256), + dict(type='Flip', flip_ratio=0), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs']) +] +data = dict( + videos_per_gpu=16, + workers_per_gpu=4, + train=dict( + type=dataset_type, + ann_file=ann_file_train, + data_prefix=data_root, + pipeline=train_pipeline), + val=dict( + type=dataset_type, + ann_file=ann_file_val, + data_prefix=data_root_val, + pipeline=val_pipeline), + test=dict( + type=dataset_type, + ann_file=ann_file_val, + data_prefix=data_root_val, + pipeline=test_pipeline)) +# optimizer +optimizer = dict( + type='SGD', lr=0.0025, momentum=0.9, + weight_decay=0.0001) # this lr is used for 8 gpus +optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) +# learning policy +# lr_config = dict(policy='step', steps=[1,2,3], lrs=[1e-3,1e-4,1e-5]) +lr_config = dict(policy='CosineAnnealing', min_lr=0) +total_epochs = 60 +# total_epochs = 90 + +# runtime settings +checkpoint_config = dict(interval=5) +evaluation = dict( + interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) +#work_dir = './work_dirs/r2plus1d_r34_8x8x1_180e_ucf101_rgb3/' +find_unused_parameters = True +load_from = 'https://download.openmmlab.com/mmaction/recognition/r2plus1d/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb_20200729-aa94765e.pth' +resume_from = None + work_dir = './work_dirs/r2plus1d-1p-npu/' \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/C3D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_8p.py b/PyTorch/contrib/cv/video/C3D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_8p.py index 7afb668be6e510b5e9fcf7e0165cb2b036068a97..7f68a5166d8d438584c147721985f6d136581b00 100644 --- a/PyTorch/contrib/cv/video/C3D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_8p.py +++ b/PyTorch/contrib/cv/video/C3D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_8p.py @@ -1,113 +1,113 @@ -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -_base_ = [ - '../../_base_/models/r2plus1d_r34.py', - '../../_base_/default_runtime.py' -] - -# dataset settings -dataset_type = 'RawframeDataset' -data_root = '/home/linus/rawframes/' -data_root_val = '/home/linus/rawframes/' -split = 1 # official train/test splits. valid numbers: 1, 2, 3 -ann_file_train = f'data/ucf101/ucf101_train_split_{split}_rawframes.txt' -ann_file_val = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' -ann_file_test = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' -img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) -train_pipeline = [ - dict(type='SampleFrames', clip_len=8, frame_interval=8, num_clips=1), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='RandomResizedCrop'), - dict(type='Resize', scale=(224, 224), keep_ratio=False), - dict(type='Flip', flip_ratio=0.5), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs', 'label']) -] -val_pipeline = [ - dict( - type='SampleFrames', - clip_len=8, - frame_interval=8, - num_clips=1, - test_mode=True), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='CenterCrop', crop_size=224), - dict(type='Flip', flip_ratio=0), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs']) -] -test_pipeline = [ - dict( - type='SampleFrames', - clip_len=8, - frame_interval=8, - num_clips=10, - test_mode=True), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='ThreeCrop', crop_size=256), - dict(type='Flip', flip_ratio=0), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs']) -] -data = dict( - videos_per_gpu=42, - workers_per_gpu=4, - train=dict( - type=dataset_type, - ann_file=ann_file_train, - data_prefix=data_root, - pipeline=train_pipeline), - val=dict( - type=dataset_type, - ann_file=ann_file_val, - data_prefix=data_root_val, - pipeline=val_pipeline), - test=dict( - type=dataset_type, - ann_file=ann_file_val, - data_prefix=data_root_val, - pipeline=test_pipeline)) -# optimizer -optimizer = dict( - type='SGD', lr=0.008, momentum=0.9, - weight_decay=0.0001) # this lr is used for 8 gpus -optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) -# learning policy -# lr_config = dict(policy='step', teps=[1,2,3], lrs=[1e-3,1e-4,1e-5]) -lr_config = dict(policy='CosineAnnealing', min_lr=0) -total_epochs = 70 -# total_epochs = 90 - -# runtime settings -checkpoint_config = dict(interval=5) -evaluation = dict( - interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) -#work_dir = './work_dirs/r2plus1d_r34_8x8x1_180e_ucf101_rgb3/' -find_unused_parameters = True -load_from = 'https://download.openmmlab.com/mmaction/recognition/r2plus1d/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb_20200729-aa94765e.pth' -resume_from = None - +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +_base_ = [ + '../../_base_/models/r2plus1d_r34.py', + '../../_base_/default_runtime.py' +] + +# dataset settings +dataset_type = 'RawframeDataset' +data_root = '/home/linus/rawframes/' +data_root_val = '/home/linus/rawframes/' +split = 1 # official train/test splits. valid numbers: 1, 2, 3 +ann_file_train = f'data/ucf101/ucf101_train_split_{split}_rawframes.txt' +ann_file_val = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' +ann_file_test = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) +train_pipeline = [ + dict(type='SampleFrames', clip_len=8, frame_interval=8, num_clips=1), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='RandomResizedCrop'), + dict(type='Resize', scale=(224, 224), keep_ratio=False), + dict(type='Flip', flip_ratio=0.5), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs', 'label']) +] +val_pipeline = [ + dict( + type='SampleFrames', + clip_len=8, + frame_interval=8, + num_clips=1, + test_mode=True), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='CenterCrop', crop_size=224), + dict(type='Flip', flip_ratio=0), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs']) +] +test_pipeline = [ + dict( + type='SampleFrames', + clip_len=8, + frame_interval=8, + num_clips=10, + test_mode=True), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='ThreeCrop', crop_size=256), + dict(type='Flip', flip_ratio=0), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs']) +] +data = dict( + videos_per_gpu=42, + workers_per_gpu=4, + train=dict( + type=dataset_type, + ann_file=ann_file_train, + data_prefix=data_root, + pipeline=train_pipeline), + val=dict( + type=dataset_type, + ann_file=ann_file_val, + data_prefix=data_root_val, + pipeline=val_pipeline), + test=dict( + type=dataset_type, + ann_file=ann_file_val, + data_prefix=data_root_val, + pipeline=test_pipeline)) +# optimizer +optimizer = dict( + type='SGD', lr=0.008, momentum=0.9, + weight_decay=0.0001) # this lr is used for 8 gpus +optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) +# learning policy +# lr_config = dict(policy='step', teps=[1,2,3], lrs=[1e-3,1e-4,1e-5]) +lr_config = dict(policy='CosineAnnealing', min_lr=0) +total_epochs = 70 +# total_epochs = 90 + +# runtime settings +checkpoint_config = dict(interval=5) +evaluation = dict( + interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) +#work_dir = './work_dirs/r2plus1d_r34_8x8x1_180e_ucf101_rgb3/' +find_unused_parameters = True +load_from = 'https://download.openmmlab.com/mmaction/recognition/r2plus1d/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb_20200729-aa94765e.pth' +resume_from = None + work_dir = './work_dirs/r2plus1d-8p-npu/' diff --git a/PyTorch/contrib/cv/video/C3D/tools/dist_train.sh b/PyTorch/contrib/cv/video/C3D/tools/dist_train.sh old mode 100755 new mode 100644 diff --git a/PyTorch/contrib/cv/video/GloRe/README.md b/PyTorch/contrib/cv/video/GloRe/README.md index f26ecfaec3fe7082f5c32c1a3386bf4e4b40e0b3..3b6e55924a976142ff69d48b4cef8ddd65031949 100644 --- a/PyTorch/contrib/cv/video/GloRe/README.md +++ b/PyTorch/contrib/cv/video/GloRe/README.md @@ -1,50 +1,50 @@ -# GloRe 训练 -# Graph-Based Global Reasoning Networks -This implements training of GloRe on the UCF-101 dataset. -- Reference implementation: -``` -url=https: https://github.com/facebookresearch/GloRe -``` - -## GloRe Detail # - -As of the current date, Ascend-Pytorch is still inefficient for contiguous operations. -Therefore, GloRe is re-implemented using semantics such as custom OP. - - -## Requirements # - -- Install PyTorch ([pytorch.org](http://pytorch.org)) -- `pip install -r requirements.txt` -- The UCF-101 Dataset can be downloaded from the links below.Move the datasets to directory ./dataset/UCF101/raw/data . - - Train Set : [Download UCF-101](https://www.crcv.ucf.edu/data/UCF101/UCF101.rar) - - Test Set : [Download UCF-101](https://www.crcv.ucf.edu/data/UCF101/UCF101.rar) -- The pretrained model can be downloaded from the links below. Move the datasets to directory ./network/pretrain . - - Pretrained model : [Download pth](https://dl.fbaipublicfiles.com/glore/kinetics/resnet50-lite_3d_8x8_w-glore_2-3_ep-0000.pth). Create directory ./network/pretrained/ and place pretrained model under directory ./network/pretrained/ - -## Training # -To train a model, run `train_kinetics.py`: - -```bash -# 1p train perf -bash test/train_performance_1p.sh - -# 8p train perf -bash test/train_performance_8p.sh - -# 8p train full -bash test/train_full_8p.sh - -# finetuning -bash test/train_finetune_1p.sh -``` - -## GloRe training result # - -| ACC@1 | FPS | Npu_nums | Epochs | AMP_Type | -| :------: | :------: | :------: | :------: | :------: | -| - | 11.647 | 1 | 90 | O2 | -| 92.39 | 141.31 | 8 | 90 | O2 | - - - +# GloRe 训练 +# Graph-Based Global Reasoning Networks +This implements training of GloRe on the UCF-101 dataset. +- Reference implementation: +``` +url=https: https://github.com/facebookresearch/GloRe +``` + +## GloRe Detail # + +As of the current date, Ascend-Pytorch is still inefficient for contiguous operations. +Therefore, GloRe is re-implemented using semantics such as custom OP. + + +## Requirements # + +- Install PyTorch ([pytorch.org](http://pytorch.org)) +- `pip install -r requirements.txt` +- The UCF-101 Dataset can be downloaded from the links below.Move the datasets to directory ./dataset/UCF101/raw/data . + - Train Set : [Download UCF-101](https://www.crcv.ucf.edu/data/UCF101/UCF101.rar) + - Test Set : [Download UCF-101](https://www.crcv.ucf.edu/data/UCF101/UCF101.rar) +- The pretrained model can be downloaded from the links below. Move the datasets to directory ./network/pretrain . + - Pretrained model : [Download pth](https://dl.fbaipublicfiles.com/glore/kinetics/resnet50-lite_3d_8x8_w-glore_2-3_ep-0000.pth). Create directory ./network/pretrained/ and place pretrained model under directory ./network/pretrained/ + +## Training # +To train a model, run `train_kinetics.py`: + +```bash +# 1p train perf +bash test/train_performance_1p.sh + +# 8p train perf +bash test/train_performance_8p.sh + +# 8p train full +bash test/train_full_8p.sh + +# finetuning +bash test/train_finetune_1p.sh +``` + +## GloRe training result # + +| ACC@1 | FPS | Npu_nums | Epochs | AMP_Type | +| :------: | :------: | :------: | :------: | :------: | +| - | 11.647 | 1 | 90 | O2 | +| 92.39 | 141.31 | 8 | 90 | O2 | + + + diff --git a/PyTorch/contrib/cv/video/GloRe/modelzoo_level.txt b/PyTorch/contrib/cv/video/GloRe/modelzoo_level.txt index a17c8f95fa388fbc6d253e2cd7cfd0b73b734073..a829ab59b97a1022dd6fc33b59b7ae0d55009432 100644 --- a/PyTorch/contrib/cv/video/GloRe/modelzoo_level.txt +++ b/PyTorch/contrib/cv/video/GloRe/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/NonLocal/config/default_runtime.py b/PyTorch/contrib/cv/video/NonLocal/config/default_runtime.py index 41329bf37107afc6238c8360bc11dd80efd93324..7652836b33c6b6c3927a2e0bea18322d4cc13788 100644 --- a/PyTorch/contrib/cv/video/NonLocal/config/default_runtime.py +++ b/PyTorch/contrib/cv/video/NonLocal/config/default_runtime.py @@ -1,27 +1,27 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -checkpoint_config = dict(interval=5) -log_config = dict( - interval=1, - hooks=[ - dict(type='TextLoggerHook'), - # dict(type='TensorboardLoggerHook'), - ]) -# runtime settings -dist_params = dict(backend='nccl') -log_level = 'INFO' -load_from = None -resume_from = None -workflow = [('train', 1)] +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +checkpoint_config = dict(interval=5) +log_config = dict( + interval=1, + hooks=[ + dict(type='TextLoggerHook'), + # dict(type='TensorboardLoggerHook'), + ]) +# runtime settings +dist_params = dict(backend='nccl') +log_level = 'INFO' +load_from = None +resume_from = None +workflow = [('train', 1)] diff --git a/PyTorch/contrib/cv/video/NonLocal/config/tsm_r50.py b/PyTorch/contrib/cv/video/NonLocal/config/tsm_r50.py index d7124c2e442bf4ce8cddfa80f30a3a0d080d2f96..6015b73cb2f4abfd05a31ac3e7cc532243f58879 100644 --- a/PyTorch/contrib/cv/video/NonLocal/config/tsm_r50.py +++ b/PyTorch/contrib/cv/video/NonLocal/config/tsm_r50.py @@ -1,35 +1,35 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -# model settings -model = dict( - type='Recognizer2D', - backbone=dict( - type='ResNetTSM', - pretrained='torchvision://resnet50', - depth=50, - norm_eval=False, - shift_div=8), - cls_head=dict( - type='TSMHead', - num_classes=400, - in_channels=2048, - spatial_type='avg', - consensus=dict(type='AvgConsensus', dim=1), - dropout_ratio=0.5, - init_std=0.001, - is_shift=True), - # model training and testing settings - train_cfg=None, - test_cfg=dict(average_clips='prob')) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# model settings +model = dict( + type='Recognizer2D', + backbone=dict( + type='ResNetTSM', + pretrained='torchvision://resnet50', + depth=50, + norm_eval=False, + shift_div=8), + cls_head=dict( + type='TSMHead', + num_classes=400, + in_channels=2048, + spatial_type='avg', + consensus=dict(type='AvgConsensus', dim=1), + dropout_ratio=0.5, + init_std=0.001, + is_shift=True), + # model training and testing settings + train_cfg=None, + test_cfg=dict(average_clips='prob')) diff --git a/PyTorch/contrib/cv/video/NonLocal/mmaction/apis/train.py b/PyTorch/contrib/cv/video/NonLocal/mmaction/apis/train.py index 59f1bc0a8ab759f36a0485076f0585add1bd384e..d50c7f7e6ae9f8487dea82a33bb3351356bbaaf8 100644 --- a/PyTorch/contrib/cv/video/NonLocal/mmaction/apis/train.py +++ b/PyTorch/contrib/cv/video/NonLocal/mmaction/apis/train.py @@ -1,267 +1,267 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import copy as cp -import os.path as osp - -from apex import amp - -import torch -from mmcv.parallel import MMDataParallel, MMDistributedDataParallel -from mmcv.runner import (DistSamplerSeedHook, EpochBasedRunner, OptimizerHook, - build_optimizer, get_dist_info) -from mmcv.runner.hooks import Fp16OptimizerHook - -from ..core import (DistEvalHook, EvalHook, OmniSourceDistSamplerSeedHook, - OmniSourceRunner) -from ..datasets import build_dataloader, build_dataset -from ..utils import PreciseBNHook, get_root_logger -from .test import multi_gpu_test - - -def train_model(model, - dataset, - cfg, - distributed=False, - validate=False, - test=dict(test_best=False, test_last=False), - timestamp=None, - meta=None): - """Train model entry function. - - Args: - model (nn.Module): The model to be trained. - dataset (:obj:`Dataset`): Train dataset. - cfg (dict): The config dict for training. - distributed (bool): Whether to use distributed training. - Default: False. - validate (bool): Whether to do evaluation. Default: False. - test (dict): The testing option, with two keys: test_last & test_best. - The value is True or False, indicating whether to test the - corresponding checkpoint. - Default: dict(test_best=False, test_last=False). - timestamp (str | None): Local time for runner. Default: None. - meta (dict | None): Meta dict to record some important information. - Default: None - """ - logger = get_root_logger(log_level=cfg.log_level) - - # prepare data loaders - dataset = dataset if isinstance(dataset, (list, tuple)) else [dataset] - - dataloader_setting = dict(videos_per_gpu=cfg.data.get('videos_per_gpu', 1), - workers_per_gpu=cfg.data.get( - 'workers_per_gpu', 1), - num_gpus=len(cfg.gpu_ids), - dist=distributed, - seed=cfg.seed) - dataloader_setting = dict(dataloader_setting, - **cfg.data.get('train_dataloader', {})) - - if cfg.omnisource: - # The option can override videos_per_gpu - train_ratio = cfg.data.get('train_ratio', [1] * len(dataset)) - omni_videos_per_gpu = cfg.data.get('omni_videos_per_gpu', None) - if omni_videos_per_gpu is None: - dataloader_settings = [dataloader_setting] * len(dataset) - else: - dataloader_settings = [] - for videos_per_gpu in omni_videos_per_gpu: - this_setting = cp.deepcopy(dataloader_setting) - this_setting['videos_per_gpu'] = videos_per_gpu - dataloader_settings.append(this_setting) - data_loaders = [ - build_dataloader(ds, **setting) - for ds, setting in zip(dataset, dataloader_settings) - ] - - else: - data_loaders = [ - build_dataloader(ds, **dataloader_setting) for ds in dataset - ] - - # build runner - optimizer = build_optimizer(model, cfg.optimizer) - - # Allow Amp to perform casts as required by the opt_level - if cfg.AMP: - # model, optimizer = amp.initialize(model.cuda(), - # optimizer, - # opt_level=cfg.OPT_LEVEL, - # loss_scale=cfg.LOSS_SCALE) - model, optimizer = amp.initialize(model.npu(), - optimizer, - opt_level=cfg.OPT_LEVEL, - loss_scale=cfg.LOSS_SCALE, - combine_grad=True) - - # put model on gpus - if distributed: - find_unused_parameters = cfg.get('find_unused_parameters', False) - # Sets the `find_unused_parameters` parameter in - # torch.nn.parallel.DistributedDataParallel - model = MMDistributedDataParallel( - model, - device_ids=[torch.npu.current_device()], - broadcast_buffers=False, - find_unused_parameters=find_unused_parameters) - # model = MMDistributedDataParallel( - # model, - # device_ids=[torch.cuda.current_device()], - # broadcast_buffers=False, - # find_unused_parameters=find_unused_parameters) - - else: - # In 1-p training, we don't use Dataparallel - # model = MMDataParallel(model.cuda(cfg.gpu_ids[0]), - # device_ids=cfg.gpu_ids) - model = model.npu() - - Runner = OmniSourceRunner if cfg.omnisource else EpochBasedRunner - runner = Runner(model, - optimizer=optimizer, - work_dir=cfg.work_dir, - logger=logger, - meta=meta, - distributed=distributed) - # an ugly workaround to make .log and .log.json filenames the same - runner.timestamp = timestamp - - # fp16 setting - fp16_cfg = cfg.get('fp16', None) - if fp16_cfg is not None: - optimizer_config = Fp16OptimizerHook(**cfg.optimizer_config, - **fp16_cfg, - distributed=distributed) - elif distributed and 'type' not in cfg.optimizer_config: - optimizer_config = OptimizerHook(**cfg.optimizer_config) - else: - optimizer_config = cfg.optimizer_config - - # register hooks - runner.register_training_hooks(cfg.lr_config, optimizer_config, - cfg.checkpoint_config, cfg.log_config, - cfg.get('momentum_config', None)) - if distributed: - if cfg.omnisource: - runner.register_hook(OmniSourceDistSamplerSeedHook()) - else: - runner.register_hook(DistSamplerSeedHook()) - - # precise bn setting - if cfg.get('precise_bn', False): - precise_bn_dataset = build_dataset(cfg.data.train) - dataloader_setting = dict( - videos_per_gpu=cfg.data.get('videos_per_gpu', 1), - workers_per_gpu=0, # save memory and time - num_gpus=len(cfg.gpu_ids), - dist=distributed, - seed=cfg.seed) - data_loader_precise_bn = build_dataloader(precise_bn_dataset, - **dataloader_setting) - precise_bn_hook = PreciseBNHook(data_loader_precise_bn, - **cfg.get('precise_bn')) - runner.register_hook(precise_bn_hook) - - if validate: - eval_cfg = cfg.get('evaluation', {}) - val_dataset = build_dataset(cfg.data.val, dict(test_mode=True)) - dataloader_setting = dict( - videos_per_gpu=cfg.data.get('videos_per_gpu', 1), - workers_per_gpu=cfg.data.get('workers_per_gpu', 1), - # cfg.gpus will be ignored if distributed - num_gpus=len(cfg.gpu_ids), - dist=distributed, - shuffle=False) - dataloader_setting = dict(dataloader_setting, - **cfg.data.get('val_dataloader', {})) - val_dataloader = build_dataloader(val_dataset, **dataloader_setting) - eval_hook = DistEvalHook(val_dataloader, **eval_cfg) if distributed \ - else EvalHook(val_dataloader, **eval_cfg) - runner.register_hook(eval_hook) - - if cfg.resume_from: - runner.resume(cfg.resume_from) - elif cfg.load_from: - runner.load_checkpoint(cfg.load_from) - runner_kwargs = dict() - if cfg.omnisource: - runner_kwargs = dict(train_ratio=train_ratio) - runner.run(data_loaders, cfg.workflow, cfg.total_epochs, **runner_kwargs) - - if test['test_last'] or test['test_best']: - best_ckpt_path = None - if test['test_best']: - if hasattr(eval_hook, 'best_ckpt_path'): - best_ckpt_path = eval_hook.best_ckpt_path - - if best_ckpt_path is None or not osp.exists(best_ckpt_path): - test['test_best'] = False - if best_ckpt_path is None: - runner.logger.info('Warning: test_best set as True, but ' - 'is not applicable ' - '(eval_hook.best_ckpt_path is None)') - else: - runner.logger.info('Warning: test_best set as True, but ' - 'is not applicable (best_ckpt ' - f'{best_ckpt_path} not found)') - if not test['test_last']: - return - - test_dataset = build_dataset(cfg.data.test, dict(test_mode=True)) - gpu_collect = cfg.get('evaluation', {}).get('gpu_collect', False) - tmpdir = cfg.get('evaluation', {}).get('tmpdir', - osp.join(cfg.work_dir, 'tmp')) - dataloader_setting = dict( - videos_per_gpu=cfg.data.get('videos_per_gpu', 1), - workers_per_gpu=cfg.data.get('workers_per_gpu', 1), - num_gpus=len(cfg.gpu_ids), - dist=distributed, - shuffle=False) - dataloader_setting = dict(dataloader_setting, - **cfg.data.get('test_dataloader', {})) - - test_dataloader = build_dataloader(test_dataset, **dataloader_setting) - - names, ckpts = [], [] - - if test['test_last']: - names.append('last') - ckpts.append(None) - if test['test_best']: - names.append('best') - ckpts.append(best_ckpt_path) - - for name, ckpt in zip(names, ckpts): - if ckpt is not None: - runner.load_checkpoint(ckpt) - - outputs = multi_gpu_test(runner.model, test_dataloader, tmpdir, - gpu_collect) - rank, _ = get_dist_info() - if rank == 0: - out = osp.join(cfg.work_dir, f'{name}_pred.pkl') - test_dataset.dump_results(outputs, out) - - eval_cfg = cfg.get('evaluation', {}) - for key in [ - 'interval', 'tmpdir', 'start', 'gpu_collect', - 'save_best', 'rule', 'by_epoch', 'broadcast_bn_buffers' - ]: - eval_cfg.pop(key, None) - - eval_res = test_dataset.evaluate(outputs, **eval_cfg) - runner.logger.info(f'Testing results of the {name} checkpoint') - for metric_name, val in eval_res.items(): - runner.logger.info(f'{metric_name}: {val:.04f}') +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import copy as cp +import os.path as osp + +from apex import amp + +import torch +from mmcv.parallel import MMDataParallel, MMDistributedDataParallel +from mmcv.runner import (DistSamplerSeedHook, EpochBasedRunner, OptimizerHook, + build_optimizer, get_dist_info) +from mmcv.runner.hooks import Fp16OptimizerHook + +from ..core import (DistEvalHook, EvalHook, OmniSourceDistSamplerSeedHook, + OmniSourceRunner) +from ..datasets import build_dataloader, build_dataset +from ..utils import PreciseBNHook, get_root_logger +from .test import multi_gpu_test + + +def train_model(model, + dataset, + cfg, + distributed=False, + validate=False, + test=dict(test_best=False, test_last=False), + timestamp=None, + meta=None): + """Train model entry function. + + Args: + model (nn.Module): The model to be trained. + dataset (:obj:`Dataset`): Train dataset. + cfg (dict): The config dict for training. + distributed (bool): Whether to use distributed training. + Default: False. + validate (bool): Whether to do evaluation. Default: False. + test (dict): The testing option, with two keys: test_last & test_best. + The value is True or False, indicating whether to test the + corresponding checkpoint. + Default: dict(test_best=False, test_last=False). + timestamp (str | None): Local time for runner. Default: None. + meta (dict | None): Meta dict to record some important information. + Default: None + """ + logger = get_root_logger(log_level=cfg.log_level) + + # prepare data loaders + dataset = dataset if isinstance(dataset, (list, tuple)) else [dataset] + + dataloader_setting = dict(videos_per_gpu=cfg.data.get('videos_per_gpu', 1), + workers_per_gpu=cfg.data.get( + 'workers_per_gpu', 1), + num_gpus=len(cfg.gpu_ids), + dist=distributed, + seed=cfg.seed) + dataloader_setting = dict(dataloader_setting, + **cfg.data.get('train_dataloader', {})) + + if cfg.omnisource: + # The option can override videos_per_gpu + train_ratio = cfg.data.get('train_ratio', [1] * len(dataset)) + omni_videos_per_gpu = cfg.data.get('omni_videos_per_gpu', None) + if omni_videos_per_gpu is None: + dataloader_settings = [dataloader_setting] * len(dataset) + else: + dataloader_settings = [] + for videos_per_gpu in omni_videos_per_gpu: + this_setting = cp.deepcopy(dataloader_setting) + this_setting['videos_per_gpu'] = videos_per_gpu + dataloader_settings.append(this_setting) + data_loaders = [ + build_dataloader(ds, **setting) + for ds, setting in zip(dataset, dataloader_settings) + ] + + else: + data_loaders = [ + build_dataloader(ds, **dataloader_setting) for ds in dataset + ] + + # build runner + optimizer = build_optimizer(model, cfg.optimizer) + + # Allow Amp to perform casts as required by the opt_level + if cfg.AMP: + # model, optimizer = amp.initialize(model.cuda(), + # optimizer, + # opt_level=cfg.OPT_LEVEL, + # loss_scale=cfg.LOSS_SCALE) + model, optimizer = amp.initialize(model.npu(), + optimizer, + opt_level=cfg.OPT_LEVEL, + loss_scale=cfg.LOSS_SCALE, + combine_grad=True) + + # put model on gpus + if distributed: + find_unused_parameters = cfg.get('find_unused_parameters', False) + # Sets the `find_unused_parameters` parameter in + # torch.nn.parallel.DistributedDataParallel + model = MMDistributedDataParallel( + model, + device_ids=[torch.npu.current_device()], + broadcast_buffers=False, + find_unused_parameters=find_unused_parameters) + # model = MMDistributedDataParallel( + # model, + # device_ids=[torch.cuda.current_device()], + # broadcast_buffers=False, + # find_unused_parameters=find_unused_parameters) + + else: + # In 1-p training, we don't use Dataparallel + # model = MMDataParallel(model.cuda(cfg.gpu_ids[0]), + # device_ids=cfg.gpu_ids) + model = model.npu() + + Runner = OmniSourceRunner if cfg.omnisource else EpochBasedRunner + runner = Runner(model, + optimizer=optimizer, + work_dir=cfg.work_dir, + logger=logger, + meta=meta, + distributed=distributed) + # an ugly workaround to make .log and .log.json filenames the same + runner.timestamp = timestamp + + # fp16 setting + fp16_cfg = cfg.get('fp16', None) + if fp16_cfg is not None: + optimizer_config = Fp16OptimizerHook(**cfg.optimizer_config, + **fp16_cfg, + distributed=distributed) + elif distributed and 'type' not in cfg.optimizer_config: + optimizer_config = OptimizerHook(**cfg.optimizer_config) + else: + optimizer_config = cfg.optimizer_config + + # register hooks + runner.register_training_hooks(cfg.lr_config, optimizer_config, + cfg.checkpoint_config, cfg.log_config, + cfg.get('momentum_config', None)) + if distributed: + if cfg.omnisource: + runner.register_hook(OmniSourceDistSamplerSeedHook()) + else: + runner.register_hook(DistSamplerSeedHook()) + + # precise bn setting + if cfg.get('precise_bn', False): + precise_bn_dataset = build_dataset(cfg.data.train) + dataloader_setting = dict( + videos_per_gpu=cfg.data.get('videos_per_gpu', 1), + workers_per_gpu=0, # save memory and time + num_gpus=len(cfg.gpu_ids), + dist=distributed, + seed=cfg.seed) + data_loader_precise_bn = build_dataloader(precise_bn_dataset, + **dataloader_setting) + precise_bn_hook = PreciseBNHook(data_loader_precise_bn, + **cfg.get('precise_bn')) + runner.register_hook(precise_bn_hook) + + if validate: + eval_cfg = cfg.get('evaluation', {}) + val_dataset = build_dataset(cfg.data.val, dict(test_mode=True)) + dataloader_setting = dict( + videos_per_gpu=cfg.data.get('videos_per_gpu', 1), + workers_per_gpu=cfg.data.get('workers_per_gpu', 1), + # cfg.gpus will be ignored if distributed + num_gpus=len(cfg.gpu_ids), + dist=distributed, + shuffle=False) + dataloader_setting = dict(dataloader_setting, + **cfg.data.get('val_dataloader', {})) + val_dataloader = build_dataloader(val_dataset, **dataloader_setting) + eval_hook = DistEvalHook(val_dataloader, **eval_cfg) if distributed \ + else EvalHook(val_dataloader, **eval_cfg) + runner.register_hook(eval_hook) + + if cfg.resume_from: + runner.resume(cfg.resume_from) + elif cfg.load_from: + runner.load_checkpoint(cfg.load_from) + runner_kwargs = dict() + if cfg.omnisource: + runner_kwargs = dict(train_ratio=train_ratio) + runner.run(data_loaders, cfg.workflow, cfg.total_epochs, **runner_kwargs) + + if test['test_last'] or test['test_best']: + best_ckpt_path = None + if test['test_best']: + if hasattr(eval_hook, 'best_ckpt_path'): + best_ckpt_path = eval_hook.best_ckpt_path + + if best_ckpt_path is None or not osp.exists(best_ckpt_path): + test['test_best'] = False + if best_ckpt_path is None: + runner.logger.info('Warning: test_best set as True, but ' + 'is not applicable ' + '(eval_hook.best_ckpt_path is None)') + else: + runner.logger.info('Warning: test_best set as True, but ' + 'is not applicable (best_ckpt ' + f'{best_ckpt_path} not found)') + if not test['test_last']: + return + + test_dataset = build_dataset(cfg.data.test, dict(test_mode=True)) + gpu_collect = cfg.get('evaluation', {}).get('gpu_collect', False) + tmpdir = cfg.get('evaluation', {}).get('tmpdir', + osp.join(cfg.work_dir, 'tmp')) + dataloader_setting = dict( + videos_per_gpu=cfg.data.get('videos_per_gpu', 1), + workers_per_gpu=cfg.data.get('workers_per_gpu', 1), + num_gpus=len(cfg.gpu_ids), + dist=distributed, + shuffle=False) + dataloader_setting = dict(dataloader_setting, + **cfg.data.get('test_dataloader', {})) + + test_dataloader = build_dataloader(test_dataset, **dataloader_setting) + + names, ckpts = [], [] + + if test['test_last']: + names.append('last') + ckpts.append(None) + if test['test_best']: + names.append('best') + ckpts.append(best_ckpt_path) + + for name, ckpt in zip(names, ckpts): + if ckpt is not None: + runner.load_checkpoint(ckpt) + + outputs = multi_gpu_test(runner.model, test_dataloader, tmpdir, + gpu_collect) + rank, _ = get_dist_info() + if rank == 0: + out = osp.join(cfg.work_dir, f'{name}_pred.pkl') + test_dataset.dump_results(outputs, out) + + eval_cfg = cfg.get('evaluation', {}) + for key in [ + 'interval', 'tmpdir', 'start', 'gpu_collect', + 'save_best', 'rule', 'by_epoch', 'broadcast_bn_buffers' + ]: + eval_cfg.pop(key, None) + + eval_res = test_dataset.evaluate(outputs, **eval_cfg) + runner.logger.info(f'Testing results of the {name} checkpoint') + for metric_name, val in eval_res.items(): + runner.logger.info(f'{metric_name}: {val:.04f}') diff --git a/PyTorch/contrib/cv/video/NonLocal/mmaction/datasets/pipelines/formating.py b/PyTorch/contrib/cv/video/NonLocal/mmaction/datasets/pipelines/formating.py index a7d0876a040cc435060f9056c6343fc0fd9f7b3c..3811c61addc5060784cf69acc2613b9b33567ea9 100644 --- a/PyTorch/contrib/cv/video/NonLocal/mmaction/datasets/pipelines/formating.py +++ b/PyTorch/contrib/cv/video/NonLocal/mmaction/datasets/pipelines/formating.py @@ -1,378 +1,378 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -from collections.abc import Sequence - -import mmcv -import numpy as np -import torch -from mmcv.parallel import DataContainer as DC - -from ..builder import PIPELINES - - -def to_tensor(data): - """Convert objects of various python types to :obj:`torch.Tensor`. - - Supported types are: :class:`numpy.ndarray`, :class:`torch.Tensor`, - :class:`Sequence`, :class:`int` and :class:`float`. - """ - if isinstance(data, torch.Tensor): - return data - if isinstance(data, np.ndarray): - return torch.from_numpy(data) - if isinstance(data, Sequence) and not mmcv.is_str(data): - return torch.tensor(data) - if isinstance(data, int): - return torch.LongTensor([data]) - if isinstance(data, float): - return torch.FloatTensor([data]) - raise TypeError(f'type {type(data)} cannot be converted to tensor.') - - -@PIPELINES.register_module() -class ToTensor: - """Convert some values in results dict to `torch.Tensor` type in data - loader pipeline. - - Args: - keys (Sequence[str]): Required keys to be converted. - """ - def __init__(self, keys): - self.keys = keys - - def __call__(self, results): - """Performs the ToTensor formating. - - Args: - results (dict): The resulting dict to be modified and passed - to the next transform in pipeline. - """ - for key in self.keys: - results[key] = to_tensor(results[key]) - return results - - def __repr__(self): - return f'{self.__class__.__name__}(keys={self.keys})' - - -@PIPELINES.register_module() -class Rename: - """Rename the key in results. - - Args: - mapping (dict): The keys in results that need to be renamed. The key of - the dict is the original name, while the value is the new name. If - the original name not found in results, do nothing. - Default: dict(). - """ - def __init__(self, mapping): - self.mapping = mapping - - def __call__(self, results): - for key, value in self.mapping.items(): - if key in results: - assert isinstance(key, str) and isinstance(value, str) - assert value not in results, ('the new name already exists in ' - 'results') - results[value] = results[key] - results.pop(key) - return results - - -@PIPELINES.register_module() -class ToDataContainer: - """Convert the data to DataContainer. - - Args: - fields (Sequence[dict]): Required fields to be converted - with keys and attributes. E.g. - fields=(dict(key='gt_bbox', stack=False),). - Note that key can also be a list of keys, if so, every tensor in - the list will be converted to DataContainer. - """ - def __init__(self, fields): - self.fields = fields - - def __call__(self, results): - """Performs the ToDataContainer formating. - - Args: - results (dict): The resulting dict to be modified and passed - to the next transform in pipeline. - """ - for field in self.fields: - _field = field.copy() - key = _field.pop('key') - if isinstance(key, list): - for item in key: - results[item] = DC(results[item], **_field) - else: - results[key] = DC(results[key], **_field) - return results - - def __repr__(self): - return self.__class__.__name__ + f'(fields={self.fields})' - - -@PIPELINES.register_module() -class ImageToTensor: - """Convert image type to `torch.Tensor` type. - - Args: - keys (Sequence[str]): Required keys to be converted. - """ - def __init__(self, keys): - self.keys = keys - - def __call__(self, results): - """Performs the ImageToTensor formating. - - Args: - results (dict): The resulting dict to be modified and passed - to the next transform in pipeline. - """ - for key in self.keys: - results[key] = to_tensor(results[key].transpose(2, 0, 1)) - return results - - def __repr__(self): - return f'{self.__class__.__name__}(keys={self.keys})' - - -@PIPELINES.register_module() -class Transpose: - """Transpose image channels to a given order. - - Args: - keys (Sequence[str]): Required keys to be converted. - order (Sequence[int]): Image channel order. - """ - def __init__(self, keys, order): - self.keys = keys - self.order = order - - def __call__(self, results): - """Performs the Transpose formatting. - - Args: - results (dict): The resulting dict to be modified and passed - to the next transform in pipeline. - """ - for key in self.keys: - results[key] = results[key].transpose(self.order) - return results - - def __repr__(self): - return (f'{self.__class__.__name__}(' - f'keys={self.keys}, order={self.order})') - - -@PIPELINES.register_module() -class Collect: - """Collect data from the loader relevant to the specific task. - - This keeps the items in ``keys`` as it is, and collect items in - ``meta_keys`` into a meta item called ``meta_name``.This is usually - the last stage of the data loader pipeline. - For example, when keys='imgs', meta_keys=('filename', 'label', - 'original_shape'), meta_name='img_metas', the results will be a dict with - keys 'imgs' and 'img_metas', where 'img_metas' is a DataContainer of - another dict with keys 'filename', 'label', 'original_shape'. - - Args: - keys (Sequence[str]): Required keys to be collected. - meta_name (str): The name of the key that contains meta infomation. - This key is always populated. Default: "img_metas". - meta_keys (Sequence[str]): Keys that are collected under meta_name. - The contents of the ``meta_name`` dictionary depends on - ``meta_keys``. - By default this includes: - - - "filename": path to the image file - - "label": label of the image file - - "original_shape": original shape of the image as a tuple - (h, w, c) - - "img_shape": shape of the image input to the network as a tuple - (h, w, c). Note that images may be zero padded on the - bottom/right, if the batch tensor is larger than this shape. - - "pad_shape": image shape after padding - - "flip_direction": a str in ("horiziontal", "vertival") to - indicate if the image is fliped horizontally or vertically. - - "img_norm_cfg": a dict of normalization information: - - mean - per channel mean subtraction - - std - per channel std divisor - - to_rgb - bool indicating if bgr was converted to rgb - nested (bool): If set as True, will apply data[x] = [data[x]] to all - items in data. The arg is added for compatibility. Default: False. - """ - def __init__(self, - keys, - meta_keys=('filename', 'label', 'original_shape', 'img_shape', - 'pad_shape', 'flip_direction', 'img_norm_cfg'), - meta_name='img_metas', - nested=False): - self.keys = keys - self.meta_keys = meta_keys - self.meta_name = meta_name - self.nested = nested - - def __call__(self, results): - """Performs the Collect formating. - - Args: - results (dict): The resulting dict to be modified and passed - to the next transform in pipeline. - """ - data = {} - for key in self.keys: - data[key] = results[key] - - if len(self.meta_keys) != 0: - meta = {} - for key in self.meta_keys: - meta[key] = results[key] - data[self.meta_name] = DC(meta, cpu_only=True) - if self.nested: - for k in data: - data[k] = [data[k]] - - return data - - def __repr__(self): - return (f'{self.__class__.__name__}(' - f'keys={self.keys}, meta_keys={self.meta_keys}, ' - f'nested={self.nested})') - - -@PIPELINES.register_module() -class FormatShape: - """Format final imgs shape to the given input_format. - - Required keys are "imgs", "num_clips" and "clip_len", added or modified - keys are "imgs" and "input_shape". - - Args: - input_format (str): Define the final imgs format. - collapse (bool): To collpase input_format N... to ... (NCTHW to CTHW, - etc.) if N is 1. Should be set as True when training and testing - detectors. Default: False. - """ - def __init__(self, input_format, collapse=False): - self.input_format = input_format - self.collapse = collapse - if self.input_format not in ['NCTHW', 'NCHW', 'NCHW_Flow', 'NPTCHW']: - raise ValueError( - f'The input format {self.input_format} is invalid.') - - def __call__(self, results): - """Performs the FormatShape formating. - - Args: - results (dict): The resulting dict to be modified and passed - to the next transform in pipeline. - """ - if not isinstance(results['imgs'], np.ndarray): - results['imgs'] = np.array(results['imgs']) - imgs = results['imgs'] - # [M x H x W x C] - # M = 1 * N_crops * N_clips * L - if self.collapse: - assert results['num_clips'] == 1 - - if self.input_format == 'NCTHW': - num_clips = results['num_clips'] - clip_len = results['clip_len'] - - imgs = imgs.reshape((-1, num_clips, clip_len) + imgs.shape[1:]) - # N_crops x N_clips x L x H x W x C - imgs = np.transpose(imgs, (0, 1, 5, 2, 3, 4)) - # N_crops x N_clips x C x L x H x W - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - # M' x C x L x H x W - # M' = N_crops x N_clips - elif self.input_format == 'NCHW': - imgs = np.transpose(imgs, (0, 3, 1, 2)) - # M x C x H x W - elif self.input_format == 'NCHW_Flow': - num_clips = results['num_clips'] - clip_len = results['clip_len'] - imgs = imgs.reshape((-1, num_clips, clip_len) + imgs.shape[1:]) - # N_crops x N_clips x L x H x W x C - imgs = np.transpose(imgs, (0, 1, 2, 5, 3, 4)) - # N_crops x N_clips x L x C x H x W - imgs = imgs.reshape((-1, imgs.shape[2] * imgs.shape[3]) + - imgs.shape[4:]) - # M' x C' x H x W - # M' = N_crops x N_clips - # C' = L x C - elif self.input_format == 'NPTCHW': - num_proposals = results['num_proposals'] - num_clips = results['num_clips'] - clip_len = results['clip_len'] - imgs = imgs.reshape((num_proposals, num_clips * clip_len) + - imgs.shape[1:]) - # P x M x H x W x C - # M = N_clips x L - imgs = np.transpose(imgs, (0, 1, 4, 2, 3)) - # P x M x C x H x W - if self.collapse: - assert imgs.shape[0] == 1 - imgs = imgs.squeeze(0) - - results['imgs'] = imgs - results['input_shape'] = imgs.shape - return results - - def __repr__(self): - repr_str = self.__class__.__name__ - repr_str += f"(input_format='{self.input_format}')" - return repr_str - - -@PIPELINES.register_module() -class FormatAudioShape: - """Format final audio shape to the given input_format. - - Required keys are "imgs", "num_clips" and "clip_len", added or modified - keys are "imgs" and "input_shape". - - Args: - input_format (str): Define the final imgs format. - """ - def __init__(self, input_format): - self.input_format = input_format - if self.input_format not in ['NCTF']: - raise ValueError( - f'The input format {self.input_format} is invalid.') - - def __call__(self, results): - """Performs the FormatShape formatting. - - Args: - results (dict): The resulting dict to be modified and passed - to the next transform in pipeline. - """ - audios = results['audios'] - # clip x sample x freq -> clip x channel x sample x freq - clip, sample, freq = audios.shape - audios = audios.reshape(clip, 1, sample, freq) - results['audios'] = audios - results['input_shape'] = audios.shape - return results - - def __repr__(self): - repr_str = self.__class__.__name__ - repr_str += f"(input_format='{self.input_format}')" - return repr_str +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +from collections.abc import Sequence + +import mmcv +import numpy as np +import torch +from mmcv.parallel import DataContainer as DC + +from ..builder import PIPELINES + + +def to_tensor(data): + """Convert objects of various python types to :obj:`torch.Tensor`. + + Supported types are: :class:`numpy.ndarray`, :class:`torch.Tensor`, + :class:`Sequence`, :class:`int` and :class:`float`. + """ + if isinstance(data, torch.Tensor): + return data + if isinstance(data, np.ndarray): + return torch.from_numpy(data) + if isinstance(data, Sequence) and not mmcv.is_str(data): + return torch.tensor(data) + if isinstance(data, int): + return torch.LongTensor([data]) + if isinstance(data, float): + return torch.FloatTensor([data]) + raise TypeError(f'type {type(data)} cannot be converted to tensor.') + + +@PIPELINES.register_module() +class ToTensor: + """Convert some values in results dict to `torch.Tensor` type in data + loader pipeline. + + Args: + keys (Sequence[str]): Required keys to be converted. + """ + def __init__(self, keys): + self.keys = keys + + def __call__(self, results): + """Performs the ToTensor formating. + + Args: + results (dict): The resulting dict to be modified and passed + to the next transform in pipeline. + """ + for key in self.keys: + results[key] = to_tensor(results[key]) + return results + + def __repr__(self): + return f'{self.__class__.__name__}(keys={self.keys})' + + +@PIPELINES.register_module() +class Rename: + """Rename the key in results. + + Args: + mapping (dict): The keys in results that need to be renamed. The key of + the dict is the original name, while the value is the new name. If + the original name not found in results, do nothing. + Default: dict(). + """ + def __init__(self, mapping): + self.mapping = mapping + + def __call__(self, results): + for key, value in self.mapping.items(): + if key in results: + assert isinstance(key, str) and isinstance(value, str) + assert value not in results, ('the new name already exists in ' + 'results') + results[value] = results[key] + results.pop(key) + return results + + +@PIPELINES.register_module() +class ToDataContainer: + """Convert the data to DataContainer. + + Args: + fields (Sequence[dict]): Required fields to be converted + with keys and attributes. E.g. + fields=(dict(key='gt_bbox', stack=False),). + Note that key can also be a list of keys, if so, every tensor in + the list will be converted to DataContainer. + """ + def __init__(self, fields): + self.fields = fields + + def __call__(self, results): + """Performs the ToDataContainer formating. + + Args: + results (dict): The resulting dict to be modified and passed + to the next transform in pipeline. + """ + for field in self.fields: + _field = field.copy() + key = _field.pop('key') + if isinstance(key, list): + for item in key: + results[item] = DC(results[item], **_field) + else: + results[key] = DC(results[key], **_field) + return results + + def __repr__(self): + return self.__class__.__name__ + f'(fields={self.fields})' + + +@PIPELINES.register_module() +class ImageToTensor: + """Convert image type to `torch.Tensor` type. + + Args: + keys (Sequence[str]): Required keys to be converted. + """ + def __init__(self, keys): + self.keys = keys + + def __call__(self, results): + """Performs the ImageToTensor formating. + + Args: + results (dict): The resulting dict to be modified and passed + to the next transform in pipeline. + """ + for key in self.keys: + results[key] = to_tensor(results[key].transpose(2, 0, 1)) + return results + + def __repr__(self): + return f'{self.__class__.__name__}(keys={self.keys})' + + +@PIPELINES.register_module() +class Transpose: + """Transpose image channels to a given order. + + Args: + keys (Sequence[str]): Required keys to be converted. + order (Sequence[int]): Image channel order. + """ + def __init__(self, keys, order): + self.keys = keys + self.order = order + + def __call__(self, results): + """Performs the Transpose formatting. + + Args: + results (dict): The resulting dict to be modified and passed + to the next transform in pipeline. + """ + for key in self.keys: + results[key] = results[key].transpose(self.order) + return results + + def __repr__(self): + return (f'{self.__class__.__name__}(' + f'keys={self.keys}, order={self.order})') + + +@PIPELINES.register_module() +class Collect: + """Collect data from the loader relevant to the specific task. + + This keeps the items in ``keys`` as it is, and collect items in + ``meta_keys`` into a meta item called ``meta_name``.This is usually + the last stage of the data loader pipeline. + For example, when keys='imgs', meta_keys=('filename', 'label', + 'original_shape'), meta_name='img_metas', the results will be a dict with + keys 'imgs' and 'img_metas', where 'img_metas' is a DataContainer of + another dict with keys 'filename', 'label', 'original_shape'. + + Args: + keys (Sequence[str]): Required keys to be collected. + meta_name (str): The name of the key that contains meta infomation. + This key is always populated. Default: "img_metas". + meta_keys (Sequence[str]): Keys that are collected under meta_name. + The contents of the ``meta_name`` dictionary depends on + ``meta_keys``. + By default this includes: + + - "filename": path to the image file + - "label": label of the image file + - "original_shape": original shape of the image as a tuple + (h, w, c) + - "img_shape": shape of the image input to the network as a tuple + (h, w, c). Note that images may be zero padded on the + bottom/right, if the batch tensor is larger than this shape. + - "pad_shape": image shape after padding + - "flip_direction": a str in ("horiziontal", "vertival") to + indicate if the image is fliped horizontally or vertically. + - "img_norm_cfg": a dict of normalization information: + - mean - per channel mean subtraction + - std - per channel std divisor + - to_rgb - bool indicating if bgr was converted to rgb + nested (bool): If set as True, will apply data[x] = [data[x]] to all + items in data. The arg is added for compatibility. Default: False. + """ + def __init__(self, + keys, + meta_keys=('filename', 'label', 'original_shape', 'img_shape', + 'pad_shape', 'flip_direction', 'img_norm_cfg'), + meta_name='img_metas', + nested=False): + self.keys = keys + self.meta_keys = meta_keys + self.meta_name = meta_name + self.nested = nested + + def __call__(self, results): + """Performs the Collect formating. + + Args: + results (dict): The resulting dict to be modified and passed + to the next transform in pipeline. + """ + data = {} + for key in self.keys: + data[key] = results[key] + + if len(self.meta_keys) != 0: + meta = {} + for key in self.meta_keys: + meta[key] = results[key] + data[self.meta_name] = DC(meta, cpu_only=True) + if self.nested: + for k in data: + data[k] = [data[k]] + + return data + + def __repr__(self): + return (f'{self.__class__.__name__}(' + f'keys={self.keys}, meta_keys={self.meta_keys}, ' + f'nested={self.nested})') + + +@PIPELINES.register_module() +class FormatShape: + """Format final imgs shape to the given input_format. + + Required keys are "imgs", "num_clips" and "clip_len", added or modified + keys are "imgs" and "input_shape". + + Args: + input_format (str): Define the final imgs format. + collapse (bool): To collpase input_format N... to ... (NCTHW to CTHW, + etc.) if N is 1. Should be set as True when training and testing + detectors. Default: False. + """ + def __init__(self, input_format, collapse=False): + self.input_format = input_format + self.collapse = collapse + if self.input_format not in ['NCTHW', 'NCHW', 'NCHW_Flow', 'NPTCHW']: + raise ValueError( + f'The input format {self.input_format} is invalid.') + + def __call__(self, results): + """Performs the FormatShape formating. + + Args: + results (dict): The resulting dict to be modified and passed + to the next transform in pipeline. + """ + if not isinstance(results['imgs'], np.ndarray): + results['imgs'] = np.array(results['imgs']) + imgs = results['imgs'] + # [M x H x W x C] + # M = 1 * N_crops * N_clips * L + if self.collapse: + assert results['num_clips'] == 1 + + if self.input_format == 'NCTHW': + num_clips = results['num_clips'] + clip_len = results['clip_len'] + + imgs = imgs.reshape((-1, num_clips, clip_len) + imgs.shape[1:]) + # N_crops x N_clips x L x H x W x C + imgs = np.transpose(imgs, (0, 1, 5, 2, 3, 4)) + # N_crops x N_clips x C x L x H x W + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + # M' x C x L x H x W + # M' = N_crops x N_clips + elif self.input_format == 'NCHW': + imgs = np.transpose(imgs, (0, 3, 1, 2)) + # M x C x H x W + elif self.input_format == 'NCHW_Flow': + num_clips = results['num_clips'] + clip_len = results['clip_len'] + imgs = imgs.reshape((-1, num_clips, clip_len) + imgs.shape[1:]) + # N_crops x N_clips x L x H x W x C + imgs = np.transpose(imgs, (0, 1, 2, 5, 3, 4)) + # N_crops x N_clips x L x C x H x W + imgs = imgs.reshape((-1, imgs.shape[2] * imgs.shape[3]) + + imgs.shape[4:]) + # M' x C' x H x W + # M' = N_crops x N_clips + # C' = L x C + elif self.input_format == 'NPTCHW': + num_proposals = results['num_proposals'] + num_clips = results['num_clips'] + clip_len = results['clip_len'] + imgs = imgs.reshape((num_proposals, num_clips * clip_len) + + imgs.shape[1:]) + # P x M x H x W x C + # M = N_clips x L + imgs = np.transpose(imgs, (0, 1, 4, 2, 3)) + # P x M x C x H x W + if self.collapse: + assert imgs.shape[0] == 1 + imgs = imgs.squeeze(0) + + results['imgs'] = imgs + results['input_shape'] = imgs.shape + return results + + def __repr__(self): + repr_str = self.__class__.__name__ + repr_str += f"(input_format='{self.input_format}')" + return repr_str + + +@PIPELINES.register_module() +class FormatAudioShape: + """Format final audio shape to the given input_format. + + Required keys are "imgs", "num_clips" and "clip_len", added or modified + keys are "imgs" and "input_shape". + + Args: + input_format (str): Define the final imgs format. + """ + def __init__(self, input_format): + self.input_format = input_format + if self.input_format not in ['NCTF']: + raise ValueError( + f'The input format {self.input_format} is invalid.') + + def __call__(self, results): + """Performs the FormatShape formatting. + + Args: + results (dict): The resulting dict to be modified and passed + to the next transform in pipeline. + """ + audios = results['audios'] + # clip x sample x freq -> clip x channel x sample x freq + clip, sample, freq = audios.shape + audios = audios.reshape(clip, 1, sample, freq) + results['audios'] = audios + results['input_shape'] = audios.shape + return results + + def __repr__(self): + repr_str = self.__class__.__name__ + repr_str += f"(input_format='{self.input_format}')" + return repr_str diff --git a/PyTorch/contrib/cv/video/NonLocal/mmaction/models/backbones/resnet3d_slowfast.py b/PyTorch/contrib/cv/video/NonLocal/mmaction/models/backbones/resnet3d_slowfast.py index a5d23bb38eddec07ec89262f4e7a446a17b429fa..e61842a2bab64177f4f1b83b30430833911ee16a 100644 --- a/PyTorch/contrib/cv/video/NonLocal/mmaction/models/backbones/resnet3d_slowfast.py +++ b/PyTorch/contrib/cv/video/NonLocal/mmaction/models/backbones/resnet3d_slowfast.py @@ -1,531 +1,531 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import warnings - -import torch -import torch.nn as nn -from mmcv.cnn import ConvModule, kaiming_init -from mmcv.runner import _load_checkpoint, load_checkpoint -from mmcv.utils import print_log - -from ...utils import get_root_logger -from ..builder import BACKBONES -from .resnet3d import ResNet3d - -mmdet_imported = False - - -class ResNet3dPathway(ResNet3d): - """A pathway of Slowfast based on ResNet3d. - - Args: - *args (arguments): Arguments same as :class:``ResNet3d``. - lateral (bool): Determines whether to enable the lateral connection - from another pathway. Default: False. - speed_ratio (int): Speed ratio indicating the ratio between time - dimension of the fast and slow pathway, corresponding to the - ``alpha`` in the paper. Default: 8. - channel_ratio (int): Reduce the channel number of fast pathway - by ``channel_ratio``, corresponding to ``beta`` in the paper. - Default: 8. - fusion_kernel (int): The kernel size of lateral fusion. - Default: 5. - **kwargs (keyword arguments): Keywords arguments for ResNet3d. - """ - def __init__(self, - *args, - lateral=False, - speed_ratio=8, - channel_ratio=8, - fusion_kernel=5, - **kwargs): - self.lateral = lateral - self.speed_ratio = speed_ratio - self.channel_ratio = channel_ratio - self.fusion_kernel = fusion_kernel - super().__init__(*args, **kwargs) - self.inplanes = self.base_channels - if self.lateral: - self.conv1_lateral = ConvModule( - self.inplanes // self.channel_ratio, - # https://arxiv.org/abs/1812.03982, the - # third type of lateral connection has out_channel: - # 2 * \beta * C - self.inplanes * 2 // self.channel_ratio, - kernel_size=(fusion_kernel, 1, 1), - stride=(self.speed_ratio, 1, 1), - padding=((fusion_kernel - 1) // 2, 0, 0), - bias=False, - conv_cfg=self.conv_cfg, - norm_cfg=self.norm_cfg, - act_cfg=None) - - self.lateral_connections = [] - for i in range(len(self.stage_blocks)): - planes = self.base_channels * 2**i - self.inplanes = planes * self.block.expansion - - if lateral and i != self.num_stages - 1: - # no lateral connection needed in final stage - lateral_name = f'layer{(i + 1)}_lateral' - setattr( - self, lateral_name, - ConvModule(self.inplanes // self.channel_ratio, - self.inplanes * 2 // self.channel_ratio, - kernel_size=(fusion_kernel, 1, 1), - stride=(self.speed_ratio, 1, 1), - padding=((fusion_kernel - 1) // 2, 0, 0), - bias=False, - conv_cfg=self.conv_cfg, - norm_cfg=self.norm_cfg, - act_cfg=None)) - self.lateral_connections.append(lateral_name) - - def make_res_layer(self, - block, - inplanes, - planes, - blocks, - spatial_stride=1, - temporal_stride=1, - dilation=1, - style='pytorch', - inflate=1, - inflate_style='3x1x1', - non_local=0, - non_local_cfg=dict(), - conv_cfg=None, - norm_cfg=None, - act_cfg=None, - with_cp=False): - """Build residual layer for Slowfast. - - Args: - block (nn.Module): Residual module to be built. - inplanes (int): Number of channels for the input - feature in each block. - planes (int): Number of channels for the output - feature in each block. - blocks (int): Number of residual blocks. - spatial_stride (int | Sequence[int]): Spatial strides - in residual and conv layers. Default: 1. - temporal_stride (int | Sequence[int]): Temporal strides in - residual and conv layers. Default: 1. - dilation (int): Spacing between kernel elements. Default: 1. - style (str): ``pytorch`` or ``caffe``. If set to ``pytorch``, - the stride-two layer is the 3x3 conv layer, - otherwise the stride-two layer is the first 1x1 conv layer. - Default: ``pytorch``. - inflate (int | Sequence[int]): Determine whether to inflate - for each block. Default: 1. - inflate_style (str): ``3x1x1`` or ``3x3x3``. which determines - the kernel sizes and padding strides for conv1 and - conv2 in each block. Default: ``3x1x1``. - non_local (int | Sequence[int]): Determine whether to apply - non-local module in the corresponding block of each stages. - Default: 0. - non_local_cfg (dict): Config for non-local module. - Default: ``dict()``. - conv_cfg (dict | None): Config for conv layers. Default: None. - norm_cfg (dict | None): Config for norm layers. Default: None. - act_cfg (dict | None): Config for activate layers. Default: None. - with_cp (bool): Use checkpoint or not. Using checkpoint will save - some memory while slowing down the training speed. - Default: False. - - Returns: - nn.Module: A residual layer for the given config. - """ - inflate = inflate if not isinstance(inflate, - int) else (inflate, ) * blocks - non_local = non_local if not isinstance( - non_local, int) else (non_local, ) * blocks - assert len(inflate) == blocks and len(non_local) == blocks - if self.lateral: - lateral_inplanes = inplanes * 2 // self.channel_ratio - else: - lateral_inplanes = 0 - if (spatial_stride != 1 - or (inplanes + lateral_inplanes) != planes * block.expansion): - downsample = ConvModule(inplanes + lateral_inplanes, - planes * block.expansion, - kernel_size=1, - stride=(temporal_stride, spatial_stride, - spatial_stride), - bias=False, - conv_cfg=conv_cfg, - norm_cfg=norm_cfg, - act_cfg=None) - else: - downsample = None - - layers = [] - layers.append( - block(inplanes + lateral_inplanes, - planes, - spatial_stride, - temporal_stride, - dilation, - downsample, - style=style, - inflate=(inflate[0] == 1), - inflate_style=inflate_style, - non_local=(non_local[0] == 1), - non_local_cfg=non_local_cfg, - conv_cfg=conv_cfg, - norm_cfg=norm_cfg, - act_cfg=act_cfg, - with_cp=with_cp)) - inplanes = planes * block.expansion - - for i in range(1, blocks): - layers.append( - block(inplanes, - planes, - 1, - 1, - dilation, - style=style, - inflate=(inflate[i] == 1), - inflate_style=inflate_style, - non_local=(non_local[i] == 1), - non_local_cfg=non_local_cfg, - conv_cfg=conv_cfg, - norm_cfg=norm_cfg, - act_cfg=act_cfg, - with_cp=with_cp)) - - return nn.Sequential(*layers) - - def inflate_weights(self, logger): - """Inflate the resnet2d parameters to resnet3d pathway. - - The differences between resnet3d and resnet2d mainly lie in an extra - axis of conv kernel. To utilize the pretrained parameters in 2d model, - the weight of conv2d models should be inflated to fit in the shapes of - the 3d counterpart. For pathway the ``lateral_connection`` part should - not be inflated from 2d weights. - - Args: - logger (logging.Logger): The logger used to print - debugging infomation. - """ - - state_dict_r2d = _load_checkpoint(self.pretrained) - if 'state_dict' in state_dict_r2d: - state_dict_r2d = state_dict_r2d['state_dict'] - - inflated_param_names = [] - for name, module in self.named_modules(): - if 'lateral' in name: - continue - if isinstance(module, ConvModule): - # we use a ConvModule to wrap conv+bn+relu layers, thus the - # name mapping is needed - if 'downsample' in name: - # layer{X}.{Y}.downsample.conv->layer{X}.{Y}.downsample.0 - original_conv_name = name + '.0' - # layer{X}.{Y}.downsample.bn->layer{X}.{Y}.downsample.1 - original_bn_name = name + '.1' - else: - # layer{X}.{Y}.conv{n}.conv->layer{X}.{Y}.conv{n} - original_conv_name = name - # layer{X}.{Y}.conv{n}.bn->layer{X}.{Y}.bn{n} - original_bn_name = name.replace('conv', 'bn') - if original_conv_name + '.weight' not in state_dict_r2d: - logger.warning(f'Module not exist in the state_dict_r2d' - f': {original_conv_name}') - else: - self._inflate_conv_params(module.conv, state_dict_r2d, - original_conv_name, - inflated_param_names) - if original_bn_name + '.weight' not in state_dict_r2d: - logger.warning(f'Module not exist in the state_dict_r2d' - f': {original_bn_name}') - else: - self._inflate_bn_params(module.bn, state_dict_r2d, - original_bn_name, - inflated_param_names) - - # check if any parameters in the 2d checkpoint are not loaded - remaining_names = set( - state_dict_r2d.keys()) - set(inflated_param_names) - if remaining_names: - logger.info(f'These parameters in the 2d checkpoint are not loaded' - f': {remaining_names}') - - def _inflate_conv_params(self, conv3d, state_dict_2d, module_name_2d, - inflated_param_names): - """Inflate a conv module from 2d to 3d. - - The differences of conv modules betweene 2d and 3d in Pathway - mainly lie in the inplanes due to lateral connections. To fit the - shapes of the lateral connection counterpart, it will expand - parameters by concatting conv2d parameters and extra zero paddings. - - Args: - conv3d (nn.Module): The destination conv3d module. - state_dict_2d (OrderedDict): The state dict of pretrained 2d model. - module_name_2d (str): The name of corresponding conv module in the - 2d model. - inflated_param_names (list[str]): List of parameters that have been - inflated. - """ - weight_2d_name = module_name_2d + '.weight' - conv2d_weight = state_dict_2d[weight_2d_name] - old_shape = conv2d_weight.shape - new_shape = conv3d.weight.data.shape - kernel_t = new_shape[2] - - if new_shape[1] != old_shape[1]: - if new_shape[1] < old_shape[1]: - warnings.warn(f'The parameter of {module_name_2d} is not' - 'loaded due to incompatible shapes. ') - return - # Inplanes may be different due to lateral connections - new_channels = new_shape[1] - old_shape[1] - pad_shape = old_shape - pad_shape = pad_shape[:1] + (new_channels, ) + pad_shape[2:] - # Expand parameters by concat extra channels - conv2d_weight = torch.cat( - (conv2d_weight, - torch.zeros(pad_shape).type_as(conv2d_weight).to( - conv2d_weight.device)), - dim=1) - - new_weight = conv2d_weight.data.unsqueeze(2).expand_as( - conv3d.weight) / kernel_t - conv3d.weight.data.copy_(new_weight) - inflated_param_names.append(weight_2d_name) - - if getattr(conv3d, 'bias') is not None: - bias_2d_name = module_name_2d + '.bias' - conv3d.bias.data.copy_(state_dict_2d[bias_2d_name]) - inflated_param_names.append(bias_2d_name) - - def _freeze_stages(self): - """Prevent all the parameters from being optimized before - `self.frozen_stages`.""" - if self.frozen_stages >= 0: - self.conv1.eval() - for param in self.conv1.parameters(): - param.requires_grad = False - - for i in range(1, self.frozen_stages + 1): - m = getattr(self, f'layer{i}') - m.eval() - for param in m.parameters(): - param.requires_grad = False - - if i != len(self.res_layers) and self.lateral: - # No fusion needed in the final stage - lateral_name = self.lateral_connections[i - 1] - conv_lateral = getattr(self, lateral_name) - conv_lateral.eval() - for param in conv_lateral.parameters(): - param.requires_grad = False - - def init_weights(self, pretrained=None): - """Initiate the parameters either from existing checkpoint or from - scratch.""" - if pretrained: - self.pretrained = pretrained - - # Override the init_weights of i3d - super().init_weights() - for module_name in self.lateral_connections: - layer = getattr(self, module_name) - for m in layer.modules(): - if isinstance(m, (nn.Conv3d, nn.Conv2d)): - kaiming_init(m) - - -pathway_cfg = { - 'resnet3d': ResNet3dPathway, - # TODO: BNInceptionPathway -} - - -def build_pathway(cfg, *args, **kwargs): - """Build pathway. - - Args: - cfg (None or dict): cfg should contain: - - type (str): identify conv layer type. - - Returns: - nn.Module: Created pathway. - """ - if not (isinstance(cfg, dict) and 'type' in cfg): - raise TypeError('cfg must be a dict containing the key "type"') - cfg_ = cfg.copy() - - pathway_type = cfg_.pop('type') - if pathway_type not in pathway_cfg: - raise KeyError(f'Unrecognized pathway type {pathway_type}') - - pathway_cls = pathway_cfg[pathway_type] - pathway = pathway_cls(*args, **kwargs, **cfg_) - - return pathway - - -@BACKBONES.register_module() -class ResNet3dSlowFast(nn.Module): - """Slowfast backbone. - - This module is proposed in `SlowFast Networks for Video Recognition - `_ - - Args: - pretrained (str): The file path to a pretrained model. - resample_rate (int): A large temporal stride ``resample_rate`` - on input frames. The actual resample rate is calculated by - multipling the ``interval`` in ``SampleFrames`` in the - pipeline with ``resample_rate``, equivalent to the :math:`\\tau` - in the paper, i.e. it processes only one out of - ``resample_rate * interval`` frames. Default: 8. - speed_ratio (int): Speed ratio indicating the ratio between time - dimension of the fast and slow pathway, corresponding to the - :math:`\\alpha` in the paper. Default: 8. - channel_ratio (int): Reduce the channel number of fast pathway - by ``channel_ratio``, corresponding to :math:`\\beta` in the paper. - Default: 8. - slow_pathway (dict): Configuration of slow branch, should contain - necessary arguments for building the specific type of pathway - and: - type (str): type of backbone the pathway bases on. - lateral (bool): determine whether to build lateral connection - for the pathway.Default: - - .. code-block:: Python - - dict(type='ResNetPathway', - lateral=True, depth=50, pretrained=None, - conv1_kernel=(1, 7, 7), dilations=(1, 1, 1, 1), - conv1_stride_t=1, pool1_stride_t=1, inflate=(0, 0, 1, 1)) - - fast_pathway (dict): Configuration of fast branch, similar to - `slow_pathway`. Default: - - .. code-block:: Python - - dict(type='ResNetPathway', - lateral=False, depth=50, pretrained=None, base_channels=8, - conv1_kernel=(5, 7, 7), conv1_stride_t=1, pool1_stride_t=1) - """ - def __init__(self, - pretrained, - resample_rate=8, - speed_ratio=8, - channel_ratio=8, - slow_pathway=dict(type='resnet3d', - depth=50, - pretrained=None, - lateral=True, - conv1_kernel=(1, 7, 7), - dilations=(1, 1, 1, 1), - conv1_stride_t=1, - pool1_stride_t=1, - inflate=(0, 0, 1, 1)), - fast_pathway=dict(type='resnet3d', - depth=50, - pretrained=None, - lateral=False, - base_channels=8, - conv1_kernel=(5, 7, 7), - conv1_stride_t=1, - pool1_stride_t=1)): - super().__init__() - self.pretrained = pretrained - self.resample_rate = resample_rate - self.speed_ratio = speed_ratio - self.channel_ratio = channel_ratio - - if slow_pathway['lateral']: - slow_pathway['speed_ratio'] = speed_ratio - slow_pathway['channel_ratio'] = channel_ratio - - self.slow_path = build_pathway(slow_pathway) - self.fast_path = build_pathway(fast_pathway) - - def init_weights(self, pretrained=None): - """Initiate the parameters either from existing checkpoint or from - scratch.""" - if pretrained: - self.pretrained = pretrained - - if isinstance(self.pretrained, str): - logger = get_root_logger() - msg = f'load model from: {self.pretrained}' - print_log(msg, logger=logger) - # Directly load 3D model. - load_checkpoint(self, self.pretrained, strict=True, logger=logger) - elif self.pretrained is None: - # Init two branch seperately. - self.fast_path.init_weights() - self.slow_path.init_weights() - else: - raise TypeError('pretrained must be a str or None') - - def forward(self, x): - """Defines the computation performed at every call. - - Args: - x (torch.Tensor): The input data. - - Returns: - tuple[torch.Tensor]: The feature of the input samples extracted - by the backbone. - """ - x_slow = nn.functional.interpolate( - x, - mode='nearest', - scale_factor=(1.0 / self.resample_rate, 1.0, 1.0)) - x_slow = self.slow_path.conv1(x_slow) - x_slow = self.slow_path.maxpool(x_slow) - - x_fast = nn.functional.interpolate( - x, - mode='nearest', - scale_factor=(1.0 / (self.resample_rate // self.speed_ratio), 1.0, - 1.0)) - x_fast = self.fast_path.conv1(x_fast) - x_fast = self.fast_path.maxpool(x_fast) - - if self.slow_path.lateral: - x_fast_lateral = self.slow_path.conv1_lateral(x_fast) - x_slow = torch.cat((x_slow, x_fast_lateral), dim=1) - - for i, layer_name in enumerate(self.slow_path.res_layers): - res_layer = getattr(self.slow_path, layer_name) - x_slow = res_layer(x_slow) - res_layer_fast = getattr(self.fast_path, layer_name) - x_fast = res_layer_fast(x_fast) - if (i != len(self.slow_path.res_layers) - 1 - and self.slow_path.lateral): - # No fusion needed in the final stage - lateral_name = self.slow_path.lateral_connections[i] - conv_lateral = getattr(self.slow_path, lateral_name) - x_fast_lateral = conv_lateral(x_fast) - x_slow = torch.cat((x_slow, x_fast_lateral), dim=1) - - out = (x_slow, x_fast) - - return out - - -if mmdet_imported: - MMDET_BACKBONES.register_module()(ResNet3dSlowFast) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import warnings + +import torch +import torch.nn as nn +from mmcv.cnn import ConvModule, kaiming_init +from mmcv.runner import _load_checkpoint, load_checkpoint +from mmcv.utils import print_log + +from ...utils import get_root_logger +from ..builder import BACKBONES +from .resnet3d import ResNet3d + +mmdet_imported = False + + +class ResNet3dPathway(ResNet3d): + """A pathway of Slowfast based on ResNet3d. + + Args: + *args (arguments): Arguments same as :class:``ResNet3d``. + lateral (bool): Determines whether to enable the lateral connection + from another pathway. Default: False. + speed_ratio (int): Speed ratio indicating the ratio between time + dimension of the fast and slow pathway, corresponding to the + ``alpha`` in the paper. Default: 8. + channel_ratio (int): Reduce the channel number of fast pathway + by ``channel_ratio``, corresponding to ``beta`` in the paper. + Default: 8. + fusion_kernel (int): The kernel size of lateral fusion. + Default: 5. + **kwargs (keyword arguments): Keywords arguments for ResNet3d. + """ + def __init__(self, + *args, + lateral=False, + speed_ratio=8, + channel_ratio=8, + fusion_kernel=5, + **kwargs): + self.lateral = lateral + self.speed_ratio = speed_ratio + self.channel_ratio = channel_ratio + self.fusion_kernel = fusion_kernel + super().__init__(*args, **kwargs) + self.inplanes = self.base_channels + if self.lateral: + self.conv1_lateral = ConvModule( + self.inplanes // self.channel_ratio, + # https://arxiv.org/abs/1812.03982, the + # third type of lateral connection has out_channel: + # 2 * \beta * C + self.inplanes * 2 // self.channel_ratio, + kernel_size=(fusion_kernel, 1, 1), + stride=(self.speed_ratio, 1, 1), + padding=((fusion_kernel - 1) // 2, 0, 0), + bias=False, + conv_cfg=self.conv_cfg, + norm_cfg=self.norm_cfg, + act_cfg=None) + + self.lateral_connections = [] + for i in range(len(self.stage_blocks)): + planes = self.base_channels * 2**i + self.inplanes = planes * self.block.expansion + + if lateral and i != self.num_stages - 1: + # no lateral connection needed in final stage + lateral_name = f'layer{(i + 1)}_lateral' + setattr( + self, lateral_name, + ConvModule(self.inplanes // self.channel_ratio, + self.inplanes * 2 // self.channel_ratio, + kernel_size=(fusion_kernel, 1, 1), + stride=(self.speed_ratio, 1, 1), + padding=((fusion_kernel - 1) // 2, 0, 0), + bias=False, + conv_cfg=self.conv_cfg, + norm_cfg=self.norm_cfg, + act_cfg=None)) + self.lateral_connections.append(lateral_name) + + def make_res_layer(self, + block, + inplanes, + planes, + blocks, + spatial_stride=1, + temporal_stride=1, + dilation=1, + style='pytorch', + inflate=1, + inflate_style='3x1x1', + non_local=0, + non_local_cfg=dict(), + conv_cfg=None, + norm_cfg=None, + act_cfg=None, + with_cp=False): + """Build residual layer for Slowfast. + + Args: + block (nn.Module): Residual module to be built. + inplanes (int): Number of channels for the input + feature in each block. + planes (int): Number of channels for the output + feature in each block. + blocks (int): Number of residual blocks. + spatial_stride (int | Sequence[int]): Spatial strides + in residual and conv layers. Default: 1. + temporal_stride (int | Sequence[int]): Temporal strides in + residual and conv layers. Default: 1. + dilation (int): Spacing between kernel elements. Default: 1. + style (str): ``pytorch`` or ``caffe``. If set to ``pytorch``, + the stride-two layer is the 3x3 conv layer, + otherwise the stride-two layer is the first 1x1 conv layer. + Default: ``pytorch``. + inflate (int | Sequence[int]): Determine whether to inflate + for each block. Default: 1. + inflate_style (str): ``3x1x1`` or ``3x3x3``. which determines + the kernel sizes and padding strides for conv1 and + conv2 in each block. Default: ``3x1x1``. + non_local (int | Sequence[int]): Determine whether to apply + non-local module in the corresponding block of each stages. + Default: 0. + non_local_cfg (dict): Config for non-local module. + Default: ``dict()``. + conv_cfg (dict | None): Config for conv layers. Default: None. + norm_cfg (dict | None): Config for norm layers. Default: None. + act_cfg (dict | None): Config for activate layers. Default: None. + with_cp (bool): Use checkpoint or not. Using checkpoint will save + some memory while slowing down the training speed. + Default: False. + + Returns: + nn.Module: A residual layer for the given config. + """ + inflate = inflate if not isinstance(inflate, + int) else (inflate, ) * blocks + non_local = non_local if not isinstance( + non_local, int) else (non_local, ) * blocks + assert len(inflate) == blocks and len(non_local) == blocks + if self.lateral: + lateral_inplanes = inplanes * 2 // self.channel_ratio + else: + lateral_inplanes = 0 + if (spatial_stride != 1 + or (inplanes + lateral_inplanes) != planes * block.expansion): + downsample = ConvModule(inplanes + lateral_inplanes, + planes * block.expansion, + kernel_size=1, + stride=(temporal_stride, spatial_stride, + spatial_stride), + bias=False, + conv_cfg=conv_cfg, + norm_cfg=norm_cfg, + act_cfg=None) + else: + downsample = None + + layers = [] + layers.append( + block(inplanes + lateral_inplanes, + planes, + spatial_stride, + temporal_stride, + dilation, + downsample, + style=style, + inflate=(inflate[0] == 1), + inflate_style=inflate_style, + non_local=(non_local[0] == 1), + non_local_cfg=non_local_cfg, + conv_cfg=conv_cfg, + norm_cfg=norm_cfg, + act_cfg=act_cfg, + with_cp=with_cp)) + inplanes = planes * block.expansion + + for i in range(1, blocks): + layers.append( + block(inplanes, + planes, + 1, + 1, + dilation, + style=style, + inflate=(inflate[i] == 1), + inflate_style=inflate_style, + non_local=(non_local[i] == 1), + non_local_cfg=non_local_cfg, + conv_cfg=conv_cfg, + norm_cfg=norm_cfg, + act_cfg=act_cfg, + with_cp=with_cp)) + + return nn.Sequential(*layers) + + def inflate_weights(self, logger): + """Inflate the resnet2d parameters to resnet3d pathway. + + The differences between resnet3d and resnet2d mainly lie in an extra + axis of conv kernel. To utilize the pretrained parameters in 2d model, + the weight of conv2d models should be inflated to fit in the shapes of + the 3d counterpart. For pathway the ``lateral_connection`` part should + not be inflated from 2d weights. + + Args: + logger (logging.Logger): The logger used to print + debugging infomation. + """ + + state_dict_r2d = _load_checkpoint(self.pretrained) + if 'state_dict' in state_dict_r2d: + state_dict_r2d = state_dict_r2d['state_dict'] + + inflated_param_names = [] + for name, module in self.named_modules(): + if 'lateral' in name: + continue + if isinstance(module, ConvModule): + # we use a ConvModule to wrap conv+bn+relu layers, thus the + # name mapping is needed + if 'downsample' in name: + # layer{X}.{Y}.downsample.conv->layer{X}.{Y}.downsample.0 + original_conv_name = name + '.0' + # layer{X}.{Y}.downsample.bn->layer{X}.{Y}.downsample.1 + original_bn_name = name + '.1' + else: + # layer{X}.{Y}.conv{n}.conv->layer{X}.{Y}.conv{n} + original_conv_name = name + # layer{X}.{Y}.conv{n}.bn->layer{X}.{Y}.bn{n} + original_bn_name = name.replace('conv', 'bn') + if original_conv_name + '.weight' not in state_dict_r2d: + logger.warning(f'Module not exist in the state_dict_r2d' + f': {original_conv_name}') + else: + self._inflate_conv_params(module.conv, state_dict_r2d, + original_conv_name, + inflated_param_names) + if original_bn_name + '.weight' not in state_dict_r2d: + logger.warning(f'Module not exist in the state_dict_r2d' + f': {original_bn_name}') + else: + self._inflate_bn_params(module.bn, state_dict_r2d, + original_bn_name, + inflated_param_names) + + # check if any parameters in the 2d checkpoint are not loaded + remaining_names = set( + state_dict_r2d.keys()) - set(inflated_param_names) + if remaining_names: + logger.info(f'These parameters in the 2d checkpoint are not loaded' + f': {remaining_names}') + + def _inflate_conv_params(self, conv3d, state_dict_2d, module_name_2d, + inflated_param_names): + """Inflate a conv module from 2d to 3d. + + The differences of conv modules betweene 2d and 3d in Pathway + mainly lie in the inplanes due to lateral connections. To fit the + shapes of the lateral connection counterpart, it will expand + parameters by concatting conv2d parameters and extra zero paddings. + + Args: + conv3d (nn.Module): The destination conv3d module. + state_dict_2d (OrderedDict): The state dict of pretrained 2d model. + module_name_2d (str): The name of corresponding conv module in the + 2d model. + inflated_param_names (list[str]): List of parameters that have been + inflated. + """ + weight_2d_name = module_name_2d + '.weight' + conv2d_weight = state_dict_2d[weight_2d_name] + old_shape = conv2d_weight.shape + new_shape = conv3d.weight.data.shape + kernel_t = new_shape[2] + + if new_shape[1] != old_shape[1]: + if new_shape[1] < old_shape[1]: + warnings.warn(f'The parameter of {module_name_2d} is not' + 'loaded due to incompatible shapes. ') + return + # Inplanes may be different due to lateral connections + new_channels = new_shape[1] - old_shape[1] + pad_shape = old_shape + pad_shape = pad_shape[:1] + (new_channels, ) + pad_shape[2:] + # Expand parameters by concat extra channels + conv2d_weight = torch.cat( + (conv2d_weight, + torch.zeros(pad_shape).type_as(conv2d_weight).to( + conv2d_weight.device)), + dim=1) + + new_weight = conv2d_weight.data.unsqueeze(2).expand_as( + conv3d.weight) / kernel_t + conv3d.weight.data.copy_(new_weight) + inflated_param_names.append(weight_2d_name) + + if getattr(conv3d, 'bias') is not None: + bias_2d_name = module_name_2d + '.bias' + conv3d.bias.data.copy_(state_dict_2d[bias_2d_name]) + inflated_param_names.append(bias_2d_name) + + def _freeze_stages(self): + """Prevent all the parameters from being optimized before + `self.frozen_stages`.""" + if self.frozen_stages >= 0: + self.conv1.eval() + for param in self.conv1.parameters(): + param.requires_grad = False + + for i in range(1, self.frozen_stages + 1): + m = getattr(self, f'layer{i}') + m.eval() + for param in m.parameters(): + param.requires_grad = False + + if i != len(self.res_layers) and self.lateral: + # No fusion needed in the final stage + lateral_name = self.lateral_connections[i - 1] + conv_lateral = getattr(self, lateral_name) + conv_lateral.eval() + for param in conv_lateral.parameters(): + param.requires_grad = False + + def init_weights(self, pretrained=None): + """Initiate the parameters either from existing checkpoint or from + scratch.""" + if pretrained: + self.pretrained = pretrained + + # Override the init_weights of i3d + super().init_weights() + for module_name in self.lateral_connections: + layer = getattr(self, module_name) + for m in layer.modules(): + if isinstance(m, (nn.Conv3d, nn.Conv2d)): + kaiming_init(m) + + +pathway_cfg = { + 'resnet3d': ResNet3dPathway, + # TODO: BNInceptionPathway +} + + +def build_pathway(cfg, *args, **kwargs): + """Build pathway. + + Args: + cfg (None or dict): cfg should contain: + - type (str): identify conv layer type. + + Returns: + nn.Module: Created pathway. + """ + if not (isinstance(cfg, dict) and 'type' in cfg): + raise TypeError('cfg must be a dict containing the key "type"') + cfg_ = cfg.copy() + + pathway_type = cfg_.pop('type') + if pathway_type not in pathway_cfg: + raise KeyError(f'Unrecognized pathway type {pathway_type}') + + pathway_cls = pathway_cfg[pathway_type] + pathway = pathway_cls(*args, **kwargs, **cfg_) + + return pathway + + +@BACKBONES.register_module() +class ResNet3dSlowFast(nn.Module): + """Slowfast backbone. + + This module is proposed in `SlowFast Networks for Video Recognition + `_ + + Args: + pretrained (str): The file path to a pretrained model. + resample_rate (int): A large temporal stride ``resample_rate`` + on input frames. The actual resample rate is calculated by + multipling the ``interval`` in ``SampleFrames`` in the + pipeline with ``resample_rate``, equivalent to the :math:`\\tau` + in the paper, i.e. it processes only one out of + ``resample_rate * interval`` frames. Default: 8. + speed_ratio (int): Speed ratio indicating the ratio between time + dimension of the fast and slow pathway, corresponding to the + :math:`\\alpha` in the paper. Default: 8. + channel_ratio (int): Reduce the channel number of fast pathway + by ``channel_ratio``, corresponding to :math:`\\beta` in the paper. + Default: 8. + slow_pathway (dict): Configuration of slow branch, should contain + necessary arguments for building the specific type of pathway + and: + type (str): type of backbone the pathway bases on. + lateral (bool): determine whether to build lateral connection + for the pathway.Default: + + .. code-block:: Python + + dict(type='ResNetPathway', + lateral=True, depth=50, pretrained=None, + conv1_kernel=(1, 7, 7), dilations=(1, 1, 1, 1), + conv1_stride_t=1, pool1_stride_t=1, inflate=(0, 0, 1, 1)) + + fast_pathway (dict): Configuration of fast branch, similar to + `slow_pathway`. Default: + + .. code-block:: Python + + dict(type='ResNetPathway', + lateral=False, depth=50, pretrained=None, base_channels=8, + conv1_kernel=(5, 7, 7), conv1_stride_t=1, pool1_stride_t=1) + """ + def __init__(self, + pretrained, + resample_rate=8, + speed_ratio=8, + channel_ratio=8, + slow_pathway=dict(type='resnet3d', + depth=50, + pretrained=None, + lateral=True, + conv1_kernel=(1, 7, 7), + dilations=(1, 1, 1, 1), + conv1_stride_t=1, + pool1_stride_t=1, + inflate=(0, 0, 1, 1)), + fast_pathway=dict(type='resnet3d', + depth=50, + pretrained=None, + lateral=False, + base_channels=8, + conv1_kernel=(5, 7, 7), + conv1_stride_t=1, + pool1_stride_t=1)): + super().__init__() + self.pretrained = pretrained + self.resample_rate = resample_rate + self.speed_ratio = speed_ratio + self.channel_ratio = channel_ratio + + if slow_pathway['lateral']: + slow_pathway['speed_ratio'] = speed_ratio + slow_pathway['channel_ratio'] = channel_ratio + + self.slow_path = build_pathway(slow_pathway) + self.fast_path = build_pathway(fast_pathway) + + def init_weights(self, pretrained=None): + """Initiate the parameters either from existing checkpoint or from + scratch.""" + if pretrained: + self.pretrained = pretrained + + if isinstance(self.pretrained, str): + logger = get_root_logger() + msg = f'load model from: {self.pretrained}' + print_log(msg, logger=logger) + # Directly load 3D model. + load_checkpoint(self, self.pretrained, strict=True, logger=logger) + elif self.pretrained is None: + # Init two branch seperately. + self.fast_path.init_weights() + self.slow_path.init_weights() + else: + raise TypeError('pretrained must be a str or None') + + def forward(self, x): + """Defines the computation performed at every call. + + Args: + x (torch.Tensor): The input data. + + Returns: + tuple[torch.Tensor]: The feature of the input samples extracted + by the backbone. + """ + x_slow = nn.functional.interpolate( + x, + mode='nearest', + scale_factor=(1.0 / self.resample_rate, 1.0, 1.0)) + x_slow = self.slow_path.conv1(x_slow) + x_slow = self.slow_path.maxpool(x_slow) + + x_fast = nn.functional.interpolate( + x, + mode='nearest', + scale_factor=(1.0 / (self.resample_rate // self.speed_ratio), 1.0, + 1.0)) + x_fast = self.fast_path.conv1(x_fast) + x_fast = self.fast_path.maxpool(x_fast) + + if self.slow_path.lateral: + x_fast_lateral = self.slow_path.conv1_lateral(x_fast) + x_slow = torch.cat((x_slow, x_fast_lateral), dim=1) + + for i, layer_name in enumerate(self.slow_path.res_layers): + res_layer = getattr(self.slow_path, layer_name) + x_slow = res_layer(x_slow) + res_layer_fast = getattr(self.fast_path, layer_name) + x_fast = res_layer_fast(x_fast) + if (i != len(self.slow_path.res_layers) - 1 + and self.slow_path.lateral): + # No fusion needed in the final stage + lateral_name = self.slow_path.lateral_connections[i] + conv_lateral = getattr(self.slow_path, lateral_name) + x_fast_lateral = conv_lateral(x_fast) + x_slow = torch.cat((x_slow, x_fast_lateral), dim=1) + + out = (x_slow, x_fast) + + return out + + +if mmdet_imported: + MMDET_BACKBONES.register_module()(ResNet3dSlowFast) diff --git a/PyTorch/contrib/cv/video/NonLocal/mmaction/models/heads/base.py b/PyTorch/contrib/cv/video/NonLocal/mmaction/models/heads/base.py index 8d165096e1f96749bdab7f9b31f07ce000794d94..6343b3dd0f60cf7183183ff14f024b143a0bf138 100644 --- a/PyTorch/contrib/cv/video/NonLocal/mmaction/models/heads/base.py +++ b/PyTorch/contrib/cv/video/NonLocal/mmaction/models/heads/base.py @@ -1,122 +1,122 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -from abc import ABCMeta, abstractmethod - -import torch -import torch.nn as nn - -from ...core import top_k_accuracy -from ..builder import build_loss - - -class AvgConsensus(nn.Module): - """Average consensus module. - - Args: - dim (int): Decide which dim consensus function to apply. - Default: 1. - """ - def __init__(self, dim=1): - super().__init__() - self.dim = dim - - def forward(self, x): - """Defines the computation performed at every call.""" - return x.mean(dim=self.dim, keepdim=True) - - -class BaseHead(nn.Module, metaclass=ABCMeta): - """Base class for head. - - All Head should subclass it. - All subclass should overwrite: - - Methods:``init_weights``, initializing weights in some modules. - - Methods:``forward``, supporting to forward both for training and testing. - - Args: - num_classes (int): Number of classes to be classified. - in_channels (int): Number of channels in input feature. - loss_cls (dict): Config for building loss. - Default: dict(type='CrossEntropyLoss', loss_weight=1.0). - multi_class (bool): Determines whether it is a multi-class - recognition task. Default: False. - label_smooth_eps (float): Epsilon used in label smooth. - Reference: arxiv.org/abs/1906.02629. Default: 0. - """ - def __init__(self, - num_classes, - in_channels, - loss_cls=dict(type='CrossEntropyLoss', loss_weight=1.0), - multi_class=False, - label_smooth_eps=0.0): - super().__init__() - self.num_classes = num_classes - self.in_channels = in_channels - self.loss_cls = build_loss(loss_cls) - self.multi_class = multi_class - self.label_smooth_eps = label_smooth_eps - - @abstractmethod - def init_weights(self): - """Initiate the parameters either from existing checkpoint or from - scratch.""" - - @abstractmethod - def forward(self, x): - """Defines the computation performed at every call.""" - - def loss(self, cls_score, labels, **kwargs): - """Calculate the loss given output ``cls_score``, target ``labels``. - - Args: - cls_score (torch.Tensor): The output of the model. - labels (torch.Tensor): The target output of the model. - - Returns: - dict: A dict containing field 'loss_cls'(mandatory) - and 'top1_acc', 'top5_acc'(optional). - """ - losses = dict() - if labels.shape == torch.Size([]): - labels = labels.unsqueeze(0) - elif labels.dim() == 1 and labels.size()[0] == self.num_classes \ - and cls_score.size()[0] == 1: - # Fix a bug when training with soft labels and batch size is 1. - # When using soft labels, `labels` and `cls_socre` share the same - # shape. - labels = labels.unsqueeze(0) - - if not self.multi_class and cls_score.size() != labels.size(): - top_k_acc = top_k_accuracy(cls_score.detach().cpu().numpy(), - labels.detach().cpu().numpy(), (1, 5)) - losses['top1_acc'] = torch.tensor(top_k_acc[0], - device=cls_score.device, - dtype=torch.float32) - losses['top5_acc'] = torch.tensor(top_k_acc[1], - device=cls_score.device, - dtype=torch.float32) - - elif self.multi_class and self.label_smooth_eps != 0: - labels = ((1 - self.label_smooth_eps) * labels + - self.label_smooth_eps / self.num_classes) - - loss_cls = self.loss_cls(cls_score, labels, **kwargs) - # loss_cls may be dictionary or single tensor - if isinstance(loss_cls, dict): - losses.update(loss_cls) - else: - losses['loss_cls'] = loss_cls - - return losses +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +from abc import ABCMeta, abstractmethod + +import torch +import torch.nn as nn + +from ...core import top_k_accuracy +from ..builder import build_loss + + +class AvgConsensus(nn.Module): + """Average consensus module. + + Args: + dim (int): Decide which dim consensus function to apply. + Default: 1. + """ + def __init__(self, dim=1): + super().__init__() + self.dim = dim + + def forward(self, x): + """Defines the computation performed at every call.""" + return x.mean(dim=self.dim, keepdim=True) + + +class BaseHead(nn.Module, metaclass=ABCMeta): + """Base class for head. + + All Head should subclass it. + All subclass should overwrite: + - Methods:``init_weights``, initializing weights in some modules. + - Methods:``forward``, supporting to forward both for training and testing. + + Args: + num_classes (int): Number of classes to be classified. + in_channels (int): Number of channels in input feature. + loss_cls (dict): Config for building loss. + Default: dict(type='CrossEntropyLoss', loss_weight=1.0). + multi_class (bool): Determines whether it is a multi-class + recognition task. Default: False. + label_smooth_eps (float): Epsilon used in label smooth. + Reference: arxiv.org/abs/1906.02629. Default: 0. + """ + def __init__(self, + num_classes, + in_channels, + loss_cls=dict(type='CrossEntropyLoss', loss_weight=1.0), + multi_class=False, + label_smooth_eps=0.0): + super().__init__() + self.num_classes = num_classes + self.in_channels = in_channels + self.loss_cls = build_loss(loss_cls) + self.multi_class = multi_class + self.label_smooth_eps = label_smooth_eps + + @abstractmethod + def init_weights(self): + """Initiate the parameters either from existing checkpoint or from + scratch.""" + + @abstractmethod + def forward(self, x): + """Defines the computation performed at every call.""" + + def loss(self, cls_score, labels, **kwargs): + """Calculate the loss given output ``cls_score``, target ``labels``. + + Args: + cls_score (torch.Tensor): The output of the model. + labels (torch.Tensor): The target output of the model. + + Returns: + dict: A dict containing field 'loss_cls'(mandatory) + and 'top1_acc', 'top5_acc'(optional). + """ + losses = dict() + if labels.shape == torch.Size([]): + labels = labels.unsqueeze(0) + elif labels.dim() == 1 and labels.size()[0] == self.num_classes \ + and cls_score.size()[0] == 1: + # Fix a bug when training with soft labels and batch size is 1. + # When using soft labels, `labels` and `cls_socre` share the same + # shape. + labels = labels.unsqueeze(0) + + if not self.multi_class and cls_score.size() != labels.size(): + top_k_acc = top_k_accuracy(cls_score.detach().cpu().numpy(), + labels.detach().cpu().numpy(), (1, 5)) + losses['top1_acc'] = torch.tensor(top_k_acc[0], + device=cls_score.device, + dtype=torch.float32) + losses['top5_acc'] = torch.tensor(top_k_acc[1], + device=cls_score.device, + dtype=torch.float32) + + elif self.multi_class and self.label_smooth_eps != 0: + labels = ((1 - self.label_smooth_eps) * labels + + self.label_smooth_eps / self.num_classes) + + loss_cls = self.loss_cls(cls_score, labels, **kwargs) + # loss_cls may be dictionary or single tensor + if isinstance(loss_cls, dict): + losses.update(loss_cls) + else: + losses['loss_cls'] = loss_cls + + return losses diff --git a/PyTorch/contrib/cv/video/NonLocal/mmaction/models/heads/slowfast_head.py b/PyTorch/contrib/cv/video/NonLocal/mmaction/models/heads/slowfast_head.py index 30c3590fa96398b7282c3c47415a31e5e4b7c858..31de953e262024feb99fab0e3809fc96d2791d6a 100644 --- a/PyTorch/contrib/cv/video/NonLocal/mmaction/models/heads/slowfast_head.py +++ b/PyTorch/contrib/cv/video/NonLocal/mmaction/models/heads/slowfast_head.py @@ -1,92 +1,92 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch -import torch.nn as nn -from mmcv.cnn import normal_init - -from ..builder import HEADS -from .base import BaseHead - - -@HEADS.register_module() -class SlowFastHead(BaseHead): - """The classification head for SlowFast. - - Args: - num_classes (int): Number of classes to be classified. - in_channels (int): Number of channels in input feature. - loss_cls (dict): Config for building loss. - Default: dict(type='CrossEntropyLoss'). - spatial_type (str): Pooling type in spatial dimension. Default: 'avg'. - dropout_ratio (float): Probability of dropout layer. Default: 0.8. - init_std (float): Std value for Initiation. Default: 0.01. - kwargs (dict, optional): Any keyword argument to be used to initialize - the head. - """ - def __init__(self, - num_classes, - in_channels, - loss_cls=dict(type='CrossEntropyLoss'), - spatial_type='avg', - dropout_ratio=0.8, - init_std=0.01, - **kwargs): - - super().__init__(num_classes, in_channels, loss_cls, **kwargs) - self.spatial_type = spatial_type - self.dropout_ratio = dropout_ratio - self.init_std = init_std - - if self.dropout_ratio != 0: - self.dropout = nn.Dropout(p=self.dropout_ratio) - else: - self.dropout = None - self.fc_cls = nn.Linear(in_channels, num_classes) - - if self.spatial_type == 'avg': - self.avg_pool = nn.AdaptiveAvgPool3d((1, 1, 1)) - else: - self.avg_pool = None - - def init_weights(self): - """Initiate the parameters from scratch.""" - normal_init(self.fc_cls, std=self.init_std) - - def forward(self, x): - """Defines the computation performed at every call. - - Args: - x (torch.Tensor): The input data. - - Returns: - torch.Tensor: The classification scores for input samples. - """ - # ([N, channel_fast, T, H, W], [(N, channel_slow, T, H, W)]) - x_fast, x_slow = x - # ([N, channel_fast, 1, 1, 1], [N, channel_slow, 1, 1, 1]) - x_fast = self.avg_pool(x_fast) - x_slow = self.avg_pool(x_slow) - # [N, channel_fast + channel_slow, 1, 1, 1] - x = torch.cat((x_slow, x_fast), dim=1) - - if self.dropout is not None: - x = self.dropout(x) - - # [N x C] - x = x.view(x.size(0), -1) - # [N x num_classes] - cls_score = self.fc_cls(x) - - return cls_score.npu_format_cast(0) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch +import torch.nn as nn +from mmcv.cnn import normal_init + +from ..builder import HEADS +from .base import BaseHead + + +@HEADS.register_module() +class SlowFastHead(BaseHead): + """The classification head for SlowFast. + + Args: + num_classes (int): Number of classes to be classified. + in_channels (int): Number of channels in input feature. + loss_cls (dict): Config for building loss. + Default: dict(type='CrossEntropyLoss'). + spatial_type (str): Pooling type in spatial dimension. Default: 'avg'. + dropout_ratio (float): Probability of dropout layer. Default: 0.8. + init_std (float): Std value for Initiation. Default: 0.01. + kwargs (dict, optional): Any keyword argument to be used to initialize + the head. + """ + def __init__(self, + num_classes, + in_channels, + loss_cls=dict(type='CrossEntropyLoss'), + spatial_type='avg', + dropout_ratio=0.8, + init_std=0.01, + **kwargs): + + super().__init__(num_classes, in_channels, loss_cls, **kwargs) + self.spatial_type = spatial_type + self.dropout_ratio = dropout_ratio + self.init_std = init_std + + if self.dropout_ratio != 0: + self.dropout = nn.Dropout(p=self.dropout_ratio) + else: + self.dropout = None + self.fc_cls = nn.Linear(in_channels, num_classes) + + if self.spatial_type == 'avg': + self.avg_pool = nn.AdaptiveAvgPool3d((1, 1, 1)) + else: + self.avg_pool = None + + def init_weights(self): + """Initiate the parameters from scratch.""" + normal_init(self.fc_cls, std=self.init_std) + + def forward(self, x): + """Defines the computation performed at every call. + + Args: + x (torch.Tensor): The input data. + + Returns: + torch.Tensor: The classification scores for input samples. + """ + # ([N, channel_fast, T, H, W], [(N, channel_slow, T, H, W)]) + x_fast, x_slow = x + # ([N, channel_fast, 1, 1, 1], [N, channel_slow, 1, 1, 1]) + x_fast = self.avg_pool(x_fast) + x_slow = self.avg_pool(x_slow) + # [N, channel_fast + channel_slow, 1, 1, 1] + x = torch.cat((x_slow, x_fast), dim=1) + + if self.dropout is not None: + x = self.dropout(x) + + # [N x C] + x = x.view(x.size(0), -1) + # [N x num_classes] + cls_score = self.fc_cls(x) + + return cls_score.npu_format_cast(0) diff --git a/PyTorch/contrib/cv/video/NonLocal/mmaction/models/losses/cross_entropy_loss.py b/PyTorch/contrib/cv/video/NonLocal/mmaction/models/losses/cross_entropy_loss.py index 11c9bfd4ddc109784c8a48a77286ed9663c7c53f..a0afe4232c36c25b3735f3efd9caa8de24e081e0 100644 --- a/PyTorch/contrib/cv/video/NonLocal/mmaction/models/losses/cross_entropy_loss.py +++ b/PyTorch/contrib/cv/video/NonLocal/mmaction/models/losses/cross_entropy_loss.py @@ -1,133 +1,133 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch -import torch.nn.functional as F - -from ..builder import LOSSES -from .base import BaseWeightedLoss - - -@LOSSES.register_module() -class CrossEntropyLoss(BaseWeightedLoss): - """Cross Entropy Loss. - - Support two kinds of labels and their corresponding loss type. It's worth - mentioning that loss type will be detected by the shape of ``cls_score`` - and ``label``. - 1) Hard label: This label is an integer array and all of the elements are - in the range [0, num_classes - 1]. This label's shape should be - ``cls_score``'s shape with the `num_classes` dimension removed. - 2) Soft label(probablity distribution over classes): This label is a - probability distribution and all of the elements are in the range - [0, 1]. This label's shape must be the same as ``cls_score``. For now, - only 2-dim soft label is supported. - - Args: - loss_weight (float): Factor scalar multiplied on the loss. - Default: 1.0. - class_weight (list[float] | None): Loss weight for each class. If set - as None, use the same weight 1 for all classes. Only applies - to CrossEntropyLoss and BCELossWithLogits (should not be set when - using other losses). Default: None. - """ - def __init__(self, loss_weight=1.0, class_weight=None): - super().__init__(loss_weight=loss_weight) - self.class_weight = None - if class_weight is not None: - self.class_weight = torch.Tensor(class_weight) - - def _forward(self, cls_score, label, **kwargs): - """Forward function. - - Args: - cls_score (torch.Tensor): The class score. - label (torch.Tensor): The ground truth label. - kwargs: Any keyword argument to be used to calculate - CrossEntropy loss. - - Returns: - torch.Tensor: The returned CrossEntropy loss. - """ - if cls_score.size() == label.size(): - # calculate loss for soft label - - assert cls_score.dim() == 2, 'Only support 2-dim soft label' - assert len(kwargs) == 0, \ - ('For now, no extra args are supported for soft label, ' - f'but get {kwargs}') - - lsm = F.log_softmax(cls_score, 1) - if self.class_weight is not None: - lsm = lsm * self.class_weight.unsqueeze(0) - loss_cls = -(label * lsm).sum(1) - - # default reduction 'mean' - if self.class_weight is not None: - # Use weighted average as pytorch CrossEntropyLoss does. - # For more information, please visit https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html # noqa - loss_cls = loss_cls.sum() / torch.sum( - self.class_weight.unsqueeze(0) * label) - else: - loss_cls = loss_cls.mean() - else: - # calculate loss for hard label - - if self.class_weight is not None: - assert 'weight' not in kwargs, \ - "The key 'weight' already exists." - kwargs['weight'] = self.class_weight.to(cls_score.device) - # cls_score = cls_score.type(torch.float32) - # label = label.type(torch.int32) - loss_cls = F.cross_entropy(cls_score, label, **kwargs) - - return loss_cls - - -@LOSSES.register_module() -class BCELossWithLogits(BaseWeightedLoss): - """Binary Cross Entropy Loss with logits. - - Args: - loss_weight (float): Factor scalar multiplied on the loss. - Default: 1.0. - class_weight (list[float] | None): Loss weight for each class. If set - as None, use the same weight 1 for all classes. Only applies - to CrossEntropyLoss and BCELossWithLogits (should not be set when - using other losses). Default: None. - """ - def __init__(self, loss_weight=1.0, class_weight=None): - super().__init__(loss_weight=loss_weight) - self.class_weight = None - if class_weight is not None: - self.class_weight = torch.Tensor(class_weight) - - def _forward(self, cls_score, label, **kwargs): - """Forward function. - - Args: - cls_score (torch.Tensor): The class score. - label (torch.Tensor): The ground truth label. - kwargs: Any keyword argument to be used to calculate - bce loss with logits. - - Returns: - torch.Tensor: The returned bce loss with logits. - """ - if self.class_weight is not None: - assert 'weight' not in kwargs, "The key 'weight' already exists." - kwargs['weight'] = self.class_weight.to(cls_score.device) - loss_cls = F.binary_cross_entropy_with_logits(cls_score, label, - **kwargs) - return loss_cls +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch +import torch.nn.functional as F + +from ..builder import LOSSES +from .base import BaseWeightedLoss + + +@LOSSES.register_module() +class CrossEntropyLoss(BaseWeightedLoss): + """Cross Entropy Loss. + + Support two kinds of labels and their corresponding loss type. It's worth + mentioning that loss type will be detected by the shape of ``cls_score`` + and ``label``. + 1) Hard label: This label is an integer array and all of the elements are + in the range [0, num_classes - 1]. This label's shape should be + ``cls_score``'s shape with the `num_classes` dimension removed. + 2) Soft label(probablity distribution over classes): This label is a + probability distribution and all of the elements are in the range + [0, 1]. This label's shape must be the same as ``cls_score``. For now, + only 2-dim soft label is supported. + + Args: + loss_weight (float): Factor scalar multiplied on the loss. + Default: 1.0. + class_weight (list[float] | None): Loss weight for each class. If set + as None, use the same weight 1 for all classes. Only applies + to CrossEntropyLoss and BCELossWithLogits (should not be set when + using other losses). Default: None. + """ + def __init__(self, loss_weight=1.0, class_weight=None): + super().__init__(loss_weight=loss_weight) + self.class_weight = None + if class_weight is not None: + self.class_weight = torch.Tensor(class_weight) + + def _forward(self, cls_score, label, **kwargs): + """Forward function. + + Args: + cls_score (torch.Tensor): The class score. + label (torch.Tensor): The ground truth label. + kwargs: Any keyword argument to be used to calculate + CrossEntropy loss. + + Returns: + torch.Tensor: The returned CrossEntropy loss. + """ + if cls_score.size() == label.size(): + # calculate loss for soft label + + assert cls_score.dim() == 2, 'Only support 2-dim soft label' + assert len(kwargs) == 0, \ + ('For now, no extra args are supported for soft label, ' + f'but get {kwargs}') + + lsm = F.log_softmax(cls_score, 1) + if self.class_weight is not None: + lsm = lsm * self.class_weight.unsqueeze(0) + loss_cls = -(label * lsm).sum(1) + + # default reduction 'mean' + if self.class_weight is not None: + # Use weighted average as pytorch CrossEntropyLoss does. + # For more information, please visit https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html # noqa + loss_cls = loss_cls.sum() / torch.sum( + self.class_weight.unsqueeze(0) * label) + else: + loss_cls = loss_cls.mean() + else: + # calculate loss for hard label + + if self.class_weight is not None: + assert 'weight' not in kwargs, \ + "The key 'weight' already exists." + kwargs['weight'] = self.class_weight.to(cls_score.device) + # cls_score = cls_score.type(torch.float32) + # label = label.type(torch.int32) + loss_cls = F.cross_entropy(cls_score, label, **kwargs) + + return loss_cls + + +@LOSSES.register_module() +class BCELossWithLogits(BaseWeightedLoss): + """Binary Cross Entropy Loss with logits. + + Args: + loss_weight (float): Factor scalar multiplied on the loss. + Default: 1.0. + class_weight (list[float] | None): Loss weight for each class. If set + as None, use the same weight 1 for all classes. Only applies + to CrossEntropyLoss and BCELossWithLogits (should not be set when + using other losses). Default: None. + """ + def __init__(self, loss_weight=1.0, class_weight=None): + super().__init__(loss_weight=loss_weight) + self.class_weight = None + if class_weight is not None: + self.class_weight = torch.Tensor(class_weight) + + def _forward(self, cls_score, label, **kwargs): + """Forward function. + + Args: + cls_score (torch.Tensor): The class score. + label (torch.Tensor): The ground truth label. + kwargs: Any keyword argument to be used to calculate + bce loss with logits. + + Returns: + torch.Tensor: The returned bce loss with logits. + """ + if self.class_weight is not None: + assert 'weight' not in kwargs, "The key 'weight' already exists." + kwargs['weight'] = self.class_weight.to(cls_score.device) + loss_cls = F.binary_cross_entropy_with_logits(cls_score, label, + **kwargs) + return loss_cls diff --git a/PyTorch/contrib/cv/video/NonLocal/mmaction/models/recognizers/base.py b/PyTorch/contrib/cv/video/NonLocal/mmaction/models/recognizers/base.py index 35603218baa99c3f8caa13bfd76f1e46fbc1e117..b7a0c527ec36b603f98961b7c0d6b511d99f1f6d 100644 --- a/PyTorch/contrib/cv/video/NonLocal/mmaction/models/recognizers/base.py +++ b/PyTorch/contrib/cv/video/NonLocal/mmaction/models/recognizers/base.py @@ -1,339 +1,339 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import warnings -from abc import ABCMeta, abstractmethod -from collections import OrderedDict - -import torch -import torch.distributed as dist -import torch.nn as nn -import torch.nn.functional as F -from mmcv.runner import auto_fp16 - -from .. import builder - - -class BaseRecognizer(nn.Module, metaclass=ABCMeta): - """Base class for recognizers. - - All recognizers should subclass it. - All subclass should overwrite: - - - Methods:``forward_train``, supporting to forward when training. - - Methods:``forward_test``, supporting to forward when testing. - - Args: - backbone (dict): Backbone modules to extract feature. - cls_head (dict | None): Classification head to process feature. - Default: None. - neck (dict | None): Neck for feature fusion. Default: None. - train_cfg (dict | None): Config for training. Default: None. - test_cfg (dict | None): Config for testing. Default: None. - """ - def __init__(self, - backbone, - cls_head=None, - neck=None, - train_cfg=None, - test_cfg=None): - super().__init__() - # record the source of the backbone - self.backbone_from = 'mmaction2' - - if backbone['type'].startswith('mmcls.'): - try: - import mmcls.models.builder as mmcls_builder - except (ImportError, ModuleNotFoundError): - raise ImportError('Please install mmcls to use this backbone.') - backbone['type'] = backbone['type'][6:] - self.backbone = mmcls_builder.build_backbone(backbone) - self.backbone_from = 'mmcls' - elif backbone['type'].startswith('torchvision.'): - try: - import torchvision.models - except (ImportError, ModuleNotFoundError): - raise ImportError('Please install torchvision to use this ' - 'backbone.') - backbone_type = backbone.pop('type')[12:] - self.backbone = torchvision.models.__dict__[backbone_type]( - **backbone) - # disable the classifier - self.backbone.classifier = nn.Identity() - self.backbone.fc = nn.Identity() - self.backbone_from = 'torchvision' - elif backbone['type'].startswith('timm.'): - try: - import timm - except (ImportError, ModuleNotFoundError): - raise ImportError('Please install timm to use this ' - 'backbone.') - backbone_type = backbone.pop('type')[5:] - # disable the classifier - backbone['num_classes'] = 0 - self.backbone = timm.create_model(backbone_type, **backbone) - self.backbone_from = 'timm' - else: - self.backbone = builder.build_backbone(backbone) - - if neck is not None: - self.neck = builder.build_neck(neck) - - self.cls_head = builder.build_head(cls_head) if cls_head else None - - self.train_cfg = train_cfg - self.test_cfg = test_cfg - - # aux_info is the list of tensor names beyond 'imgs' and 'label' which - # will be used in train_step and val_step, data_batch should contain - # these tensors - self.aux_info = [] - if train_cfg is not None and 'aux_info' in train_cfg: - self.aux_info = train_cfg['aux_info'] - # max_testing_views should be int - self.max_testing_views = None - if test_cfg is not None and 'max_testing_views' in test_cfg: - self.max_testing_views = test_cfg['max_testing_views'] - assert isinstance(self.max_testing_views, int) - - if test_cfg is not None and 'feature_extraction' in test_cfg: - self.feature_extraction = test_cfg['feature_extraction'] - else: - self.feature_extraction = False - - # mini-batch blending, e.g. mixup, cutmix, etc. - self.blending = None - if train_cfg is not None and 'blending' in train_cfg: - from mmcv.utils import build_from_cfg - from mmaction.datasets.builder import BLENDINGS - self.blending = build_from_cfg(train_cfg['blending'], BLENDINGS) - - self.init_weights() - - self.fp16_enabled = False - - @property - def with_neck(self): - """bool: whether the recognizer has a neck""" - return hasattr(self, 'neck') and self.neck is not None - - @property - def with_cls_head(self): - """bool: whether the recognizer has a cls_head""" - return hasattr(self, 'cls_head') and self.cls_head is not None - - def init_weights(self): - """Initialize the model network weights.""" - if self.backbone_from in ['mmcls', 'mmaction2']: - self.backbone.init_weights() - elif self.backbone_from in ['torchvision', 'timm']: - warnings.warn('We do not initialize weights for backbones in ' - f'{self.backbone_from}, since the weights for ' - f'backbones in {self.backbone_from} are initialized' - 'in their __init__ functions.') - else: - raise NotImplementedError('Unsupported backbone source ' - f'{self.backbone_from}!') - - if self.with_cls_head: - self.cls_head.init_weights() - if self.with_neck: - self.neck.init_weights() - - @auto_fp16() - def extract_feat(self, imgs): - """Extract features through a backbone. - - Args: - imgs (torch.Tensor): The input images. - - Returns: - torch.tensor: The extracted features. - """ - if (hasattr(self.backbone, 'features') - and self.backbone_from == 'torchvision'): - x = self.backbone.features(imgs) - elif self.backbone_from == 'timm': - x = self.backbone.forward_features(imgs) - else: - x = self.backbone(imgs) - return x - - def average_clip(self, cls_score, num_segs=1): - """Averaging class score over multiple clips. - - Using different averaging types ('score' or 'prob' or None, - which defined in test_cfg) to computed the final averaged - class score. Only called in test mode. - - Args: - cls_score (torch.Tensor): Class score to be averaged. - num_segs (int): Number of clips for each input sample. - - Returns: - torch.Tensor: Averaged class score. - """ - if 'average_clips' not in self.test_cfg.keys(): - raise KeyError('"average_clips" must defined in test_cfg\'s keys') - - average_clips = self.test_cfg['average_clips'] - if average_clips not in ['score', 'prob', None]: - raise ValueError(f'{average_clips} is not supported. ' - f'Currently supported ones are ' - f'["score", "prob", None]') - - if average_clips is None: - return cls_score - - batch_size = cls_score.shape[0] - cls_score = cls_score.view(batch_size // num_segs, num_segs, -1) - - if average_clips == 'prob': - cls_score = F.softmax(cls_score, dim=2).mean(dim=1) - elif average_clips == 'score': - cls_score = cls_score.mean(dim=1) - - return cls_score - - @abstractmethod - def forward_train(self, imgs, labels, **kwargs): - """Defines the computation performed at every call when training.""" - - @abstractmethod - def forward_test(self, imgs): - """Defines the computation performed at every call when evaluation and - testing.""" - - @abstractmethod - def forward_gradcam(self, imgs): - """Defines the computation performed at every all when using gradcam - utils.""" - - @staticmethod - def _parse_losses(losses): - """Parse the raw outputs (losses) of the network. - - Args: - losses (dict): Raw output of the network, which usually contain - losses and other necessary information. - - Returns: - tuple[Tensor, dict]: (loss, log_vars), loss is the loss tensor - which may be a weighted sum of all losses, log_vars contains - all the variables to be sent to the logger. - """ - log_vars = OrderedDict() - for loss_name, loss_value in losses.items(): - if isinstance(loss_value, torch.Tensor): - log_vars[loss_name] = loss_value.mean() - elif isinstance(loss_value, list): - log_vars[loss_name] = sum(_loss.mean() for _loss in loss_value) - else: - raise TypeError( - f'{loss_name} is not a tensor or list of tensors') - - loss = sum(_value for _key, _value in log_vars.items() - if 'loss' in _key) - - log_vars['loss'] = loss - for loss_name, loss_value in log_vars.items(): - # reduce loss when distributed training - if dist.is_available() and dist.is_initialized(): - loss_value = loss_value.data.clone() - dist.all_reduce(loss_value.div_(dist.get_world_size())) - log_vars[loss_name] = loss_value.item() - - return loss, log_vars - - def forward(self, imgs, label=None, return_loss=True, **kwargs): - """Define the computation performed at every call.""" - if kwargs.get('gradcam', False): - del kwargs['gradcam'] - return self.forward_gradcam(imgs, **kwargs) - if return_loss: - if label is None: - raise ValueError('Label should not be None.') - if self.blending is not None: - imgs, label = self.blending(imgs, label) - return self.forward_train(imgs, label, **kwargs) - - return self.forward_test(imgs, **kwargs) - - def train_step(self, data_batch, optimizer, **kwargs): - """The iteration step during training. - - This method defines an iteration step during training, except for the - back propagation and optimizer updating, which are done in an optimizer - hook. Note that in some complicated cases or models, the whole process - including back propagation and optimizer updating is also defined in - this method, such as GAN. - - Args: - data_batch (dict): The output of dataloader. - optimizer (:obj:`torch.optim.Optimizer` | dict): The optimizer of - runner is passed to ``train_step()``. This argument is unused - and reserved. - - Returns: - dict: It should contain at least 3 keys: ``loss``, ``log_vars``, - ``num_samples``. - ``loss`` is a tensor for back propagation, which can be a - weighted sum of multiple losses. - ``log_vars`` contains all the variables to be sent to the - logger. - ``num_samples`` indicates the batch size (when the model is - DDP, it means the batch size on each GPU), which is used for - averaging the logs. - """ - imgs = data_batch['imgs'].npu().type(torch.float32) - label = data_batch['label'].npu().type(torch.int32) - - aux_info = {} - for item in self.aux_info: - assert item in data_batch - aux_info[item] = data_batch[item] - - losses = self(imgs, label, return_loss=True, **aux_info) - - loss, log_vars = self._parse_losses(losses) - - outputs = dict(loss=loss, - log_vars=log_vars, - num_samples=len(next(iter(data_batch.values())))) - - return outputs - - def val_step(self, data_batch, optimizer, **kwargs): - """The iteration step during validation. - - This method shares the same signature as :func:`train_step`, but used - during val epochs. Note that the evaluation after training epochs is - not implemented with this method, but an evaluation hook. - """ - imgs = data_batch['imgs'].npu().type(torch.float32) - label = data_batch['label'].npu().type(torch.int32) - - aux_info = {} - for item in self.aux_info: - aux_info[item] = data_batch[item] - - losses = self(imgs, label, return_loss=True, **aux_info) - - loss, log_vars = self._parse_losses(losses) - - outputs = dict(loss=loss, - log_vars=log_vars, - num_samples=len(next(iter(data_batch.values())))) - - return outputs +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import warnings +from abc import ABCMeta, abstractmethod +from collections import OrderedDict + +import torch +import torch.distributed as dist +import torch.nn as nn +import torch.nn.functional as F +from mmcv.runner import auto_fp16 + +from .. import builder + + +class BaseRecognizer(nn.Module, metaclass=ABCMeta): + """Base class for recognizers. + + All recognizers should subclass it. + All subclass should overwrite: + + - Methods:``forward_train``, supporting to forward when training. + - Methods:``forward_test``, supporting to forward when testing. + + Args: + backbone (dict): Backbone modules to extract feature. + cls_head (dict | None): Classification head to process feature. + Default: None. + neck (dict | None): Neck for feature fusion. Default: None. + train_cfg (dict | None): Config for training. Default: None. + test_cfg (dict | None): Config for testing. Default: None. + """ + def __init__(self, + backbone, + cls_head=None, + neck=None, + train_cfg=None, + test_cfg=None): + super().__init__() + # record the source of the backbone + self.backbone_from = 'mmaction2' + + if backbone['type'].startswith('mmcls.'): + try: + import mmcls.models.builder as mmcls_builder + except (ImportError, ModuleNotFoundError): + raise ImportError('Please install mmcls to use this backbone.') + backbone['type'] = backbone['type'][6:] + self.backbone = mmcls_builder.build_backbone(backbone) + self.backbone_from = 'mmcls' + elif backbone['type'].startswith('torchvision.'): + try: + import torchvision.models + except (ImportError, ModuleNotFoundError): + raise ImportError('Please install torchvision to use this ' + 'backbone.') + backbone_type = backbone.pop('type')[12:] + self.backbone = torchvision.models.__dict__[backbone_type]( + **backbone) + # disable the classifier + self.backbone.classifier = nn.Identity() + self.backbone.fc = nn.Identity() + self.backbone_from = 'torchvision' + elif backbone['type'].startswith('timm.'): + try: + import timm + except (ImportError, ModuleNotFoundError): + raise ImportError('Please install timm to use this ' + 'backbone.') + backbone_type = backbone.pop('type')[5:] + # disable the classifier + backbone['num_classes'] = 0 + self.backbone = timm.create_model(backbone_type, **backbone) + self.backbone_from = 'timm' + else: + self.backbone = builder.build_backbone(backbone) + + if neck is not None: + self.neck = builder.build_neck(neck) + + self.cls_head = builder.build_head(cls_head) if cls_head else None + + self.train_cfg = train_cfg + self.test_cfg = test_cfg + + # aux_info is the list of tensor names beyond 'imgs' and 'label' which + # will be used in train_step and val_step, data_batch should contain + # these tensors + self.aux_info = [] + if train_cfg is not None and 'aux_info' in train_cfg: + self.aux_info = train_cfg['aux_info'] + # max_testing_views should be int + self.max_testing_views = None + if test_cfg is not None and 'max_testing_views' in test_cfg: + self.max_testing_views = test_cfg['max_testing_views'] + assert isinstance(self.max_testing_views, int) + + if test_cfg is not None and 'feature_extraction' in test_cfg: + self.feature_extraction = test_cfg['feature_extraction'] + else: + self.feature_extraction = False + + # mini-batch blending, e.g. mixup, cutmix, etc. + self.blending = None + if train_cfg is not None and 'blending' in train_cfg: + from mmcv.utils import build_from_cfg + from mmaction.datasets.builder import BLENDINGS + self.blending = build_from_cfg(train_cfg['blending'], BLENDINGS) + + self.init_weights() + + self.fp16_enabled = False + + @property + def with_neck(self): + """bool: whether the recognizer has a neck""" + return hasattr(self, 'neck') and self.neck is not None + + @property + def with_cls_head(self): + """bool: whether the recognizer has a cls_head""" + return hasattr(self, 'cls_head') and self.cls_head is not None + + def init_weights(self): + """Initialize the model network weights.""" + if self.backbone_from in ['mmcls', 'mmaction2']: + self.backbone.init_weights() + elif self.backbone_from in ['torchvision', 'timm']: + warnings.warn('We do not initialize weights for backbones in ' + f'{self.backbone_from}, since the weights for ' + f'backbones in {self.backbone_from} are initialized' + 'in their __init__ functions.') + else: + raise NotImplementedError('Unsupported backbone source ' + f'{self.backbone_from}!') + + if self.with_cls_head: + self.cls_head.init_weights() + if self.with_neck: + self.neck.init_weights() + + @auto_fp16() + def extract_feat(self, imgs): + """Extract features through a backbone. + + Args: + imgs (torch.Tensor): The input images. + + Returns: + torch.tensor: The extracted features. + """ + if (hasattr(self.backbone, 'features') + and self.backbone_from == 'torchvision'): + x = self.backbone.features(imgs) + elif self.backbone_from == 'timm': + x = self.backbone.forward_features(imgs) + else: + x = self.backbone(imgs) + return x + + def average_clip(self, cls_score, num_segs=1): + """Averaging class score over multiple clips. + + Using different averaging types ('score' or 'prob' or None, + which defined in test_cfg) to computed the final averaged + class score. Only called in test mode. + + Args: + cls_score (torch.Tensor): Class score to be averaged. + num_segs (int): Number of clips for each input sample. + + Returns: + torch.Tensor: Averaged class score. + """ + if 'average_clips' not in self.test_cfg.keys(): + raise KeyError('"average_clips" must defined in test_cfg\'s keys') + + average_clips = self.test_cfg['average_clips'] + if average_clips not in ['score', 'prob', None]: + raise ValueError(f'{average_clips} is not supported. ' + f'Currently supported ones are ' + f'["score", "prob", None]') + + if average_clips is None: + return cls_score + + batch_size = cls_score.shape[0] + cls_score = cls_score.view(batch_size // num_segs, num_segs, -1) + + if average_clips == 'prob': + cls_score = F.softmax(cls_score, dim=2).mean(dim=1) + elif average_clips == 'score': + cls_score = cls_score.mean(dim=1) + + return cls_score + + @abstractmethod + def forward_train(self, imgs, labels, **kwargs): + """Defines the computation performed at every call when training.""" + + @abstractmethod + def forward_test(self, imgs): + """Defines the computation performed at every call when evaluation and + testing.""" + + @abstractmethod + def forward_gradcam(self, imgs): + """Defines the computation performed at every all when using gradcam + utils.""" + + @staticmethod + def _parse_losses(losses): + """Parse the raw outputs (losses) of the network. + + Args: + losses (dict): Raw output of the network, which usually contain + losses and other necessary information. + + Returns: + tuple[Tensor, dict]: (loss, log_vars), loss is the loss tensor + which may be a weighted sum of all losses, log_vars contains + all the variables to be sent to the logger. + """ + log_vars = OrderedDict() + for loss_name, loss_value in losses.items(): + if isinstance(loss_value, torch.Tensor): + log_vars[loss_name] = loss_value.mean() + elif isinstance(loss_value, list): + log_vars[loss_name] = sum(_loss.mean() for _loss in loss_value) + else: + raise TypeError( + f'{loss_name} is not a tensor or list of tensors') + + loss = sum(_value for _key, _value in log_vars.items() + if 'loss' in _key) + + log_vars['loss'] = loss + for loss_name, loss_value in log_vars.items(): + # reduce loss when distributed training + if dist.is_available() and dist.is_initialized(): + loss_value = loss_value.data.clone() + dist.all_reduce(loss_value.div_(dist.get_world_size())) + log_vars[loss_name] = loss_value.item() + + return loss, log_vars + + def forward(self, imgs, label=None, return_loss=True, **kwargs): + """Define the computation performed at every call.""" + if kwargs.get('gradcam', False): + del kwargs['gradcam'] + return self.forward_gradcam(imgs, **kwargs) + if return_loss: + if label is None: + raise ValueError('Label should not be None.') + if self.blending is not None: + imgs, label = self.blending(imgs, label) + return self.forward_train(imgs, label, **kwargs) + + return self.forward_test(imgs, **kwargs) + + def train_step(self, data_batch, optimizer, **kwargs): + """The iteration step during training. + + This method defines an iteration step during training, except for the + back propagation and optimizer updating, which are done in an optimizer + hook. Note that in some complicated cases or models, the whole process + including back propagation and optimizer updating is also defined in + this method, such as GAN. + + Args: + data_batch (dict): The output of dataloader. + optimizer (:obj:`torch.optim.Optimizer` | dict): The optimizer of + runner is passed to ``train_step()``. This argument is unused + and reserved. + + Returns: + dict: It should contain at least 3 keys: ``loss``, ``log_vars``, + ``num_samples``. + ``loss`` is a tensor for back propagation, which can be a + weighted sum of multiple losses. + ``log_vars`` contains all the variables to be sent to the + logger. + ``num_samples`` indicates the batch size (when the model is + DDP, it means the batch size on each GPU), which is used for + averaging the logs. + """ + imgs = data_batch['imgs'].npu().type(torch.float32) + label = data_batch['label'].npu().type(torch.int32) + + aux_info = {} + for item in self.aux_info: + assert item in data_batch + aux_info[item] = data_batch[item] + + losses = self(imgs, label, return_loss=True, **aux_info) + + loss, log_vars = self._parse_losses(losses) + + outputs = dict(loss=loss, + log_vars=log_vars, + num_samples=len(next(iter(data_batch.values())))) + + return outputs + + def val_step(self, data_batch, optimizer, **kwargs): + """The iteration step during validation. + + This method shares the same signature as :func:`train_step`, but used + during val epochs. Note that the evaluation after training epochs is + not implemented with this method, but an evaluation hook. + """ + imgs = data_batch['imgs'].npu().type(torch.float32) + label = data_batch['label'].npu().type(torch.int32) + + aux_info = {} + for item in self.aux_info: + aux_info[item] = data_batch[item] + + losses = self(imgs, label, return_loss=True, **aux_info) + + loss, log_vars = self._parse_losses(losses) + + outputs = dict(loss=loss, + log_vars=log_vars, + num_samples=len(next(iter(data_batch.values())))) + + return outputs diff --git a/PyTorch/contrib/cv/video/NonLocal/mmaction/models/recognizers/recognizer2d.py b/PyTorch/contrib/cv/video/NonLocal/mmaction/models/recognizers/recognizer2d.py index 7d145f6dd83cab07d056cb40ce712c0ab9485c5c..3d9a755a5a53ebe1432ac413ee6ab85566d07b06 100644 --- a/PyTorch/contrib/cv/video/NonLocal/mmaction/models/recognizers/recognizer2d.py +++ b/PyTorch/contrib/cv/video/NonLocal/mmaction/models/recognizers/recognizer2d.py @@ -1,195 +1,195 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch -from torch import nn - -from ..builder import RECOGNIZERS -from .base import BaseRecognizer - - -@RECOGNIZERS.register_module() -class Recognizer2D(BaseRecognizer): - """2D recognizer model framework.""" - def forward_train(self, imgs, labels, **kwargs): - """Defines the computation performed at every call when training.""" - - assert self.with_cls_head - batches = imgs.shape[0] - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - num_segs = imgs.shape[0] // batches - - losses = dict() - - x = self.extract_feat(imgs) - - if self.backbone_from in ['torchvision', 'timm']: - if len(x.shape) == 4 and (x.shape[2] > 1 or x.shape[3] > 1): - # apply adaptive avg pooling - x = nn.AdaptiveAvgPool2d(1)(x) - x = x.reshape((x.shape[0], -1)) - x = x.reshape(x.shape + (1, 1)) - - if self.with_neck: - x = [ - each.reshape((-1, num_segs) + each.shape[1:]).transpose( - 1, 2).contiguous() for each in x - ] - x, loss_aux = self.neck(x, labels.squeeze()) - x = x.squeeze(2) - num_segs = 1 - losses.update(loss_aux) - - cls_score = self.cls_head(x, num_segs) - gt_labels = labels.squeeze() - loss_cls = self.cls_head.loss(cls_score, gt_labels, **kwargs) - losses.update(loss_cls) - - return losses - - def _do_test(self, imgs): - """Defines the computation performed at every call when evaluation, - testing and gradcam.""" - batches = imgs.shape[0] - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - num_segs = imgs.shape[0] // batches - - x = self.extract_feat(imgs) - - if self.backbone_from in ['torchvision', 'timm']: - if len(x.shape) == 4 and (x.shape[2] > 1 or x.shape[3] > 1): - # apply adaptive avg pooling - x = nn.AdaptiveAvgPool2d(1)(x) - x = x.reshape((x.shape[0], -1)) - x = x.reshape(x.shape + (1, 1)) - - if self.with_neck: - x = [ - each.reshape((-1, num_segs) + each.shape[1:]).transpose( - 1, 2).contiguous() for each in x - ] - x, _ = self.neck(x) - x = x.squeeze(2) - num_segs = 1 - - if self.feature_extraction: - # perform spatial pooling - avg_pool = nn.AdaptiveAvgPool2d(1) - x = avg_pool(x) - # squeeze dimensions - x = x.reshape((batches, num_segs, -1)) - # temporal average pooling - x = x.mean(axis=1) - return x - - # When using `TSNHead` or `TPNHead`, shape is [batch_size, num_classes] - # When using `TSMHead`, shape is [batch_size * num_crops, num_classes] - # `num_crops` is calculated by: - # 1) `twice_sample` in `SampleFrames` - # 2) `num_sample_positions` in `DenseSampleFrames` - # 3) `ThreeCrop/TenCrop/MultiGroupCrop` in `test_pipeline` - # 4) `num_clips` in `SampleFrames` or its subclass if `clip_len != 1` - - # should have cls_head if not extracting features - cls_score = self.cls_head(x, num_segs) - - assert cls_score.size()[0] % batches == 0 - # calculate num_crops automatically - cls_score = self.average_clip(cls_score, - cls_score.size()[0] // batches) - return cls_score - - def _do_fcn_test(self, imgs): - # [N, num_crops * num_segs, C, H, W] -> - # [N * num_crops * num_segs, C, H, W] - batches = imgs.shape[0] - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - num_segs = self.test_cfg.get('num_segs', self.backbone.num_segments) - - if self.test_cfg.get('flip', False): - imgs = torch.flip(imgs, [-1]) - x = self.extract_feat(imgs) - - if self.with_neck: - x = [ - each.reshape((-1, num_segs) + each.shape[1:]).transpose( - 1, 2).contiguous() for each in x - ] - x, _ = self.neck(x) - else: - x = x.reshape((-1, num_segs) + x.shape[1:]).transpose( - 1, 2).contiguous() - - # When using `TSNHead` or `TPNHead`, shape is [batch_size, num_classes] - # When using `TSMHead`, shape is [batch_size * num_crops, num_classes] - # `num_crops` is calculated by: - # 1) `twice_sample` in `SampleFrames` - # 2) `num_sample_positions` in `DenseSampleFrames` - # 3) `ThreeCrop/TenCrop/MultiGroupCrop` in `test_pipeline` - # 4) `num_clips` in `SampleFrames` or its subclass if `clip_len != 1` - cls_score = self.cls_head(x, fcn_test=True) - - assert cls_score.size()[0] % batches == 0 - # calculate num_crops automatically - cls_score = self.average_clip(cls_score, - cls_score.size()[0] // batches) - return cls_score - - def forward_test(self, imgs): - """Defines the computation performed at every call when evaluation and - testing.""" - imgs = imgs.npu().type(torch.float16) - if self.test_cfg.get('fcn_test', False): - # If specified, spatially fully-convolutional testing is performed - assert not self.feature_extraction - assert self.with_cls_head - return self._do_fcn_test(imgs).cpu().numpy() - return self._do_test(imgs).cpu().numpy() - - def forward_dummy(self, imgs, softmax=False): - """Used for computing network FLOPs. - - See ``tools/analysis/get_flops.py``. - - Args: - imgs (torch.Tensor): Input images. - - Returns: - Tensor: Class score. - """ - assert self.with_cls_head - batches = imgs.shape[0] - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - num_segs = imgs.shape[0] // batches - - x = self.extract_feat(imgs) - if self.with_neck: - x = [ - each.reshape((-1, num_segs) + each.shape[1:]).transpose( - 1, 2).contiguous() for each in x - ] - x, _ = self.neck(x) - x = x.squeeze(2) - num_segs = 1 - - outs = self.cls_head(x, num_segs) - if softmax: - outs = nn.functional.softmax(outs) - return (outs, ) - - def forward_gradcam(self, imgs): - """Defines the computation performed at every call when using gradcam - utils.""" - assert self.with_cls_head - return self._do_test(imgs) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch +from torch import nn + +from ..builder import RECOGNIZERS +from .base import BaseRecognizer + + +@RECOGNIZERS.register_module() +class Recognizer2D(BaseRecognizer): + """2D recognizer model framework.""" + def forward_train(self, imgs, labels, **kwargs): + """Defines the computation performed at every call when training.""" + + assert self.with_cls_head + batches = imgs.shape[0] + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + num_segs = imgs.shape[0] // batches + + losses = dict() + + x = self.extract_feat(imgs) + + if self.backbone_from in ['torchvision', 'timm']: + if len(x.shape) == 4 and (x.shape[2] > 1 or x.shape[3] > 1): + # apply adaptive avg pooling + x = nn.AdaptiveAvgPool2d(1)(x) + x = x.reshape((x.shape[0], -1)) + x = x.reshape(x.shape + (1, 1)) + + if self.with_neck: + x = [ + each.reshape((-1, num_segs) + each.shape[1:]).transpose( + 1, 2).contiguous() for each in x + ] + x, loss_aux = self.neck(x, labels.squeeze()) + x = x.squeeze(2) + num_segs = 1 + losses.update(loss_aux) + + cls_score = self.cls_head(x, num_segs) + gt_labels = labels.squeeze() + loss_cls = self.cls_head.loss(cls_score, gt_labels, **kwargs) + losses.update(loss_cls) + + return losses + + def _do_test(self, imgs): + """Defines the computation performed at every call when evaluation, + testing and gradcam.""" + batches = imgs.shape[0] + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + num_segs = imgs.shape[0] // batches + + x = self.extract_feat(imgs) + + if self.backbone_from in ['torchvision', 'timm']: + if len(x.shape) == 4 and (x.shape[2] > 1 or x.shape[3] > 1): + # apply adaptive avg pooling + x = nn.AdaptiveAvgPool2d(1)(x) + x = x.reshape((x.shape[0], -1)) + x = x.reshape(x.shape + (1, 1)) + + if self.with_neck: + x = [ + each.reshape((-1, num_segs) + each.shape[1:]).transpose( + 1, 2).contiguous() for each in x + ] + x, _ = self.neck(x) + x = x.squeeze(2) + num_segs = 1 + + if self.feature_extraction: + # perform spatial pooling + avg_pool = nn.AdaptiveAvgPool2d(1) + x = avg_pool(x) + # squeeze dimensions + x = x.reshape((batches, num_segs, -1)) + # temporal average pooling + x = x.mean(axis=1) + return x + + # When using `TSNHead` or `TPNHead`, shape is [batch_size, num_classes] + # When using `TSMHead`, shape is [batch_size * num_crops, num_classes] + # `num_crops` is calculated by: + # 1) `twice_sample` in `SampleFrames` + # 2) `num_sample_positions` in `DenseSampleFrames` + # 3) `ThreeCrop/TenCrop/MultiGroupCrop` in `test_pipeline` + # 4) `num_clips` in `SampleFrames` or its subclass if `clip_len != 1` + + # should have cls_head if not extracting features + cls_score = self.cls_head(x, num_segs) + + assert cls_score.size()[0] % batches == 0 + # calculate num_crops automatically + cls_score = self.average_clip(cls_score, + cls_score.size()[0] // batches) + return cls_score + + def _do_fcn_test(self, imgs): + # [N, num_crops * num_segs, C, H, W] -> + # [N * num_crops * num_segs, C, H, W] + batches = imgs.shape[0] + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + num_segs = self.test_cfg.get('num_segs', self.backbone.num_segments) + + if self.test_cfg.get('flip', False): + imgs = torch.flip(imgs, [-1]) + x = self.extract_feat(imgs) + + if self.with_neck: + x = [ + each.reshape((-1, num_segs) + each.shape[1:]).transpose( + 1, 2).contiguous() for each in x + ] + x, _ = self.neck(x) + else: + x = x.reshape((-1, num_segs) + x.shape[1:]).transpose( + 1, 2).contiguous() + + # When using `TSNHead` or `TPNHead`, shape is [batch_size, num_classes] + # When using `TSMHead`, shape is [batch_size * num_crops, num_classes] + # `num_crops` is calculated by: + # 1) `twice_sample` in `SampleFrames` + # 2) `num_sample_positions` in `DenseSampleFrames` + # 3) `ThreeCrop/TenCrop/MultiGroupCrop` in `test_pipeline` + # 4) `num_clips` in `SampleFrames` or its subclass if `clip_len != 1` + cls_score = self.cls_head(x, fcn_test=True) + + assert cls_score.size()[0] % batches == 0 + # calculate num_crops automatically + cls_score = self.average_clip(cls_score, + cls_score.size()[0] // batches) + return cls_score + + def forward_test(self, imgs): + """Defines the computation performed at every call when evaluation and + testing.""" + imgs = imgs.npu().type(torch.float16) + if self.test_cfg.get('fcn_test', False): + # If specified, spatially fully-convolutional testing is performed + assert not self.feature_extraction + assert self.with_cls_head + return self._do_fcn_test(imgs).cpu().numpy() + return self._do_test(imgs).cpu().numpy() + + def forward_dummy(self, imgs, softmax=False): + """Used for computing network FLOPs. + + See ``tools/analysis/get_flops.py``. + + Args: + imgs (torch.Tensor): Input images. + + Returns: + Tensor: Class score. + """ + assert self.with_cls_head + batches = imgs.shape[0] + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + num_segs = imgs.shape[0] // batches + + x = self.extract_feat(imgs) + if self.with_neck: + x = [ + each.reshape((-1, num_segs) + each.shape[1:]).transpose( + 1, 2).contiguous() for each in x + ] + x, _ = self.neck(x) + x = x.squeeze(2) + num_segs = 1 + + outs = self.cls_head(x, num_segs) + if softmax: + outs = nn.functional.softmax(outs) + return (outs, ) + + def forward_gradcam(self, imgs): + """Defines the computation performed at every call when using gradcam + utils.""" + assert self.with_cls_head + return self._do_test(imgs) diff --git a/PyTorch/contrib/cv/video/NonLocal/mmaction/models/recognizers/recognizer3d.py b/PyTorch/contrib/cv/video/NonLocal/mmaction/models/recognizers/recognizer3d.py index fe1a61ef2bad97c0c35ee9c97b7fd66373381585..9a1b70449dfdaf5b598586a98d91a1fbcdd057dc 100644 --- a/PyTorch/contrib/cv/video/NonLocal/mmaction/models/recognizers/recognizer3d.py +++ b/PyTorch/contrib/cv/video/NonLocal/mmaction/models/recognizers/recognizer3d.py @@ -1,133 +1,133 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch -from torch import nn - -from ..builder import RECOGNIZERS -from .base import BaseRecognizer - - -@RECOGNIZERS.register_module() -class Recognizer3D(BaseRecognizer): - """3D recognizer model framework.""" - def forward_train(self, imgs, labels, **kwargs): - """Defines the computation performed at every call when training.""" - - assert self.with_cls_head - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - losses = dict() - - x = self.extract_feat(imgs) - if self.with_neck: - x, loss_aux = self.neck(x, labels.squeeze()) - losses.update(loss_aux) - - cls_score = self.cls_head(x) - gt_labels = labels.squeeze() - loss_cls = self.cls_head.loss(cls_score, gt_labels, **kwargs) - losses.update(loss_cls) - - return losses - - def _do_test(self, imgs): - """Defines the computation performed at every call when evaluation, - testing and gradcam.""" - batches = imgs.shape[0] - num_segs = imgs.shape[1] - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - - if self.max_testing_views is not None: - total_views = imgs.shape[0] - assert num_segs == total_views, ( - 'max_testing_views is only compatible ' - 'with batch_size == 1') - view_ptr = 0 - feats = [] - while view_ptr < total_views: - batch_imgs = imgs[view_ptr:view_ptr + self.max_testing_views] - x = self.extract_feat(batch_imgs) - if self.with_neck: - x, _ = self.neck(x) - feats.append(x) - view_ptr += self.max_testing_views - # should consider the case that feat is a tuple - if isinstance(feats[0], tuple): - len_tuple = len(feats[0]) - feat = [ - torch.cat([x[i] for x in feats]) for i in range(len_tuple) - ] - feat = tuple(feat) - else: - feat = torch.cat(feats) - else: - feat = self.extract_feat(imgs) - if self.with_neck: - feat, _ = self.neck(feat) - - if self.feature_extraction: - # perform spatio-temporal pooling - avg_pool = nn.AdaptiveAvgPool3d(1) - if isinstance(feat, tuple): - feat = [avg_pool(x) for x in feat] - # concat them - feat = torch.cat(feat, axis=1) - else: - feat = avg_pool(feat) - # squeeze dimensions - feat = feat.reshape((batches, num_segs, -1)) - # temporal average pooling - feat = feat.mean(axis=1) - return feat - - # should have cls_head if not extracting features - assert self.with_cls_head - cls_score = self.cls_head(feat) - cls_score = self.average_clip(cls_score, num_segs) - return cls_score - - def forward_test(self, imgs): - """Defines the computation performed at every call when evaluation and - testing.""" - imgs = imgs.npu().type(torch.float16) - return self._do_test(imgs).cpu().numpy() - - def forward_dummy(self, imgs, softmax=False): - """Used for computing network FLOPs. - - See ``tools/analysis/get_flops.py``. - - Args: - imgs (torch.Tensor): Input images. - - Returns: - Tensor: Class score. - """ - assert self.with_cls_head - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - x = self.extract_feat(imgs) - - if self.with_neck: - x, _ = self.neck(x) - - outs = self.cls_head(x) - if softmax: - outs = nn.functional.softmax(outs) - return (outs, ) - - def forward_gradcam(self, imgs): - """Defines the computation performed at every call when using gradcam - utils.""" - assert self.with_cls_head - return self._do_test(imgs) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch +from torch import nn + +from ..builder import RECOGNIZERS +from .base import BaseRecognizer + + +@RECOGNIZERS.register_module() +class Recognizer3D(BaseRecognizer): + """3D recognizer model framework.""" + def forward_train(self, imgs, labels, **kwargs): + """Defines the computation performed at every call when training.""" + + assert self.with_cls_head + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + losses = dict() + + x = self.extract_feat(imgs) + if self.with_neck: + x, loss_aux = self.neck(x, labels.squeeze()) + losses.update(loss_aux) + + cls_score = self.cls_head(x) + gt_labels = labels.squeeze() + loss_cls = self.cls_head.loss(cls_score, gt_labels, **kwargs) + losses.update(loss_cls) + + return losses + + def _do_test(self, imgs): + """Defines the computation performed at every call when evaluation, + testing and gradcam.""" + batches = imgs.shape[0] + num_segs = imgs.shape[1] + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + + if self.max_testing_views is not None: + total_views = imgs.shape[0] + assert num_segs == total_views, ( + 'max_testing_views is only compatible ' + 'with batch_size == 1') + view_ptr = 0 + feats = [] + while view_ptr < total_views: + batch_imgs = imgs[view_ptr:view_ptr + self.max_testing_views] + x = self.extract_feat(batch_imgs) + if self.with_neck: + x, _ = self.neck(x) + feats.append(x) + view_ptr += self.max_testing_views + # should consider the case that feat is a tuple + if isinstance(feats[0], tuple): + len_tuple = len(feats[0]) + feat = [ + torch.cat([x[i] for x in feats]) for i in range(len_tuple) + ] + feat = tuple(feat) + else: + feat = torch.cat(feats) + else: + feat = self.extract_feat(imgs) + if self.with_neck: + feat, _ = self.neck(feat) + + if self.feature_extraction: + # perform spatio-temporal pooling + avg_pool = nn.AdaptiveAvgPool3d(1) + if isinstance(feat, tuple): + feat = [avg_pool(x) for x in feat] + # concat them + feat = torch.cat(feat, axis=1) + else: + feat = avg_pool(feat) + # squeeze dimensions + feat = feat.reshape((batches, num_segs, -1)) + # temporal average pooling + feat = feat.mean(axis=1) + return feat + + # should have cls_head if not extracting features + assert self.with_cls_head + cls_score = self.cls_head(feat) + cls_score = self.average_clip(cls_score, num_segs) + return cls_score + + def forward_test(self, imgs): + """Defines the computation performed at every call when evaluation and + testing.""" + imgs = imgs.npu().type(torch.float16) + return self._do_test(imgs).cpu().numpy() + + def forward_dummy(self, imgs, softmax=False): + """Used for computing network FLOPs. + + See ``tools/analysis/get_flops.py``. + + Args: + imgs (torch.Tensor): Input images. + + Returns: + Tensor: Class score. + """ + assert self.with_cls_head + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + x = self.extract_feat(imgs) + + if self.with_neck: + x, _ = self.neck(x) + + outs = self.cls_head(x) + if softmax: + outs = nn.functional.softmax(outs) + return (outs, ) + + def forward_gradcam(self, imgs): + """Defines the computation performed at every call when using gradcam + utils.""" + assert self.with_cls_head + return self._do_test(imgs) diff --git a/PyTorch/contrib/cv/video/R(2+1)D/additional_need/mmcv/dist_utils.py b/PyTorch/contrib/cv/video/R(2+1)D/additional_need/mmcv/dist_utils.py index 91346643e8f70fb97a407de4b6fda417cd9fa6ee..9e3f2b072b230c45b051270b5730c30822c74a2c 100644 --- a/PyTorch/contrib/cv/video/R(2+1)D/additional_need/mmcv/dist_utils.py +++ b/PyTorch/contrib/cv/video/R(2+1)D/additional_need/mmcv/dist_utils.py @@ -1,185 +1,185 @@ -# Copyright (c) Open-MMLab. All rights reserved. -# -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import functools -import os -import subprocess -from collections import OrderedDict - -import torch -import torch.multiprocessing as mp -from torch import distributed as dist -from torch._utils import (_flatten_dense_tensors, _take_tensors, - _unflatten_dense_tensors) - -from mmcv.utils import TORCH_VERSION - - -def init_dist(launcher, backend='nccl', **kwargs): - if mp.get_start_method(allow_none=True) is None: - mp.set_start_method('spawn') - if launcher == 'pytorch': - _init_dist_pytorch(backend, **kwargs) - elif launcher == 'mpi': - _init_dist_mpi(backend, **kwargs) - elif launcher == 'slurm': - _init_dist_slurm(backend, **kwargs) - else: - raise ValueError(f'Invalid launcher type: {launcher}') - - -def _init_dist_pytorch(backend, **kwargs): - # TODO: use local_rank instead of rank % num_gpus - rank = int(os.environ['RANK']) - offset = 0 if os.getenv('NPUID', None) is None else int(os.environ['NPUID']) - num_gpus = torch.npu.device_count() - torch.npu.set_device((rank + offset) % num_gpus) - dist.init_process_group(backend=backend, **kwargs) - - -def _init_dist_mpi(backend, **kwargs): - # TODO: use local_rank instead of rank % num_gpus - rank = int(os.environ['OMPI_COMM_WORLD_RANK']) - num_gpus = torch.cuda.device_count() - torch.cuda.set_device(rank % num_gpus) - dist.init_process_group(backend=backend, **kwargs) - - -def _init_dist_slurm(backend, port=None): - """Initialize slurm distributed training environment. - If argument ``port`` is not specified, then the master port will be system - environment variable ``MASTER_PORT``. If ``MASTER_PORT`` is not in system - environment variable, then a default port ``29500`` will be used. - Args: - backend (str): Backend of torch.distributed. - port (int, optional): Master port. Defaults to None. - """ - proc_id = int(os.environ['SLURM_PROCID']) - ntasks = int(os.environ['SLURM_NTASKS']) - node_list = os.environ['SLURM_NODELIST'] - num_gpus = torch.cuda.device_count() - torch.cuda.set_device(proc_id % num_gpus) - addr = subprocess.getoutput( - f'scontrol show hostname {node_list} | head -n1') - # specify master port - if port is not None: - os.environ['MASTER_PORT'] = str(port) - elif 'MASTER_PORT' in os.environ: - pass # use MASTER_PORT in the environment variable - else: - # 29500 is torch.distributed default port - os.environ['MASTER_PORT'] = '29500' - # use MASTER_ADDR in the environment variable if it already exists - if 'MASTER_ADDR' not in os.environ: - os.environ['MASTER_ADDR'] = addr - os.environ['WORLD_SIZE'] = str(ntasks) - os.environ['LOCAL_RANK'] = str(proc_id % num_gpus) - os.environ['RANK'] = str(proc_id) - dist.init_process_group(backend=backend) - - -def get_dist_info(): - if TORCH_VERSION < '1.0': - initialized = dist._initialized - else: - if dist.is_available(): - initialized = dist.is_initialized() - else: - initialized = False - if initialized: - rank = dist.get_rank() - world_size = dist.get_world_size() - else: - rank = 0 - world_size = 1 - return rank, world_size - - -def master_only(func): - - @functools.wraps(func) - def wrapper(*args, **kwargs): - rank, _ = get_dist_info() - if rank == 0: - return func(*args, **kwargs) - - return wrapper - - -def allreduce_params(params, coalesce=True, bucket_size_mb=-1): - """Allreduce parameters. - Args: - params (list[torch.Parameters]): List of parameters or buffers of a - model. - coalesce (bool, optional): Whether allreduce parameters as a whole. - Defaults to True. - bucket_size_mb (int, optional): Size of bucket, the unit is MB. - Defaults to -1. - """ - _, world_size = get_dist_info() - if world_size == 1: - return - params = [param.data for param in params] - if coalesce: - _allreduce_coalesced(params, world_size, bucket_size_mb) - else: - for tensor in params: - dist.all_reduce(tensor.div_(world_size)) - - -def allreduce_grads(params, coalesce=True, bucket_size_mb=-1): - """Allreduce gradients. - Args: - params (list[torch.Parameters]): List of parameters of a model - coalesce (bool, optional): Whether allreduce parameters as a whole. - Defaults to True. - bucket_size_mb (int, optional): Size of bucket, the unit is MB. - Defaults to -1. - """ - grads = [ - param.grad.data for param in params - if param.requires_grad and param.grad is not None - ] - _, world_size = get_dist_info() - if world_size == 1: - return - if coalesce: - _allreduce_coalesced(grads, world_size, bucket_size_mb) - else: - for tensor in grads: - dist.all_reduce(tensor.div_(world_size)) - - -def _allreduce_coalesced(tensors, world_size, bucket_size_mb=-1): - if bucket_size_mb > 0: - bucket_size_bytes = bucket_size_mb * 1024 * 1024 - buckets = _take_tensors(tensors, bucket_size_bytes) - else: - buckets = OrderedDict() - for tensor in tensors: - tp = tensor.type() - if tp not in buckets: - buckets[tp] = [] - buckets[tp].append(tensor) - buckets = buckets.values() - - for bucket in buckets: - flat_tensors = _flatten_dense_tensors(bucket) - dist.all_reduce(flat_tensors) - flat_tensors.div_(world_size) - for tensor, synced in zip( - bucket, _unflatten_dense_tensors(flat_tensors, bucket)): +# Copyright (c) Open-MMLab. All rights reserved. +# +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import functools +import os +import subprocess +from collections import OrderedDict + +import torch +import torch.multiprocessing as mp +from torch import distributed as dist +from torch._utils import (_flatten_dense_tensors, _take_tensors, + _unflatten_dense_tensors) + +from mmcv.utils import TORCH_VERSION + + +def init_dist(launcher, backend='nccl', **kwargs): + if mp.get_start_method(allow_none=True) is None: + mp.set_start_method('spawn') + if launcher == 'pytorch': + _init_dist_pytorch(backend, **kwargs) + elif launcher == 'mpi': + _init_dist_mpi(backend, **kwargs) + elif launcher == 'slurm': + _init_dist_slurm(backend, **kwargs) + else: + raise ValueError(f'Invalid launcher type: {launcher}') + + +def _init_dist_pytorch(backend, **kwargs): + # TODO: use local_rank instead of rank % num_gpus + rank = int(os.environ['RANK']) + offset = 0 if os.getenv('NPUID', None) is None else int(os.environ['NPUID']) + num_gpus = torch.npu.device_count() + torch.npu.set_device((rank + offset) % num_gpus) + dist.init_process_group(backend=backend, **kwargs) + + +def _init_dist_mpi(backend, **kwargs): + # TODO: use local_rank instead of rank % num_gpus + rank = int(os.environ['OMPI_COMM_WORLD_RANK']) + num_gpus = torch.cuda.device_count() + torch.cuda.set_device(rank % num_gpus) + dist.init_process_group(backend=backend, **kwargs) + + +def _init_dist_slurm(backend, port=None): + """Initialize slurm distributed training environment. + If argument ``port`` is not specified, then the master port will be system + environment variable ``MASTER_PORT``. If ``MASTER_PORT`` is not in system + environment variable, then a default port ``29500`` will be used. + Args: + backend (str): Backend of torch.distributed. + port (int, optional): Master port. Defaults to None. + """ + proc_id = int(os.environ['SLURM_PROCID']) + ntasks = int(os.environ['SLURM_NTASKS']) + node_list = os.environ['SLURM_NODELIST'] + num_gpus = torch.cuda.device_count() + torch.cuda.set_device(proc_id % num_gpus) + addr = subprocess.getoutput( + f'scontrol show hostname {node_list} | head -n1') + # specify master port + if port is not None: + os.environ['MASTER_PORT'] = str(port) + elif 'MASTER_PORT' in os.environ: + pass # use MASTER_PORT in the environment variable + else: + # 29500 is torch.distributed default port + os.environ['MASTER_PORT'] = '29500' + # use MASTER_ADDR in the environment variable if it already exists + if 'MASTER_ADDR' not in os.environ: + os.environ['MASTER_ADDR'] = addr + os.environ['WORLD_SIZE'] = str(ntasks) + os.environ['LOCAL_RANK'] = str(proc_id % num_gpus) + os.environ['RANK'] = str(proc_id) + dist.init_process_group(backend=backend) + + +def get_dist_info(): + if TORCH_VERSION < '1.0': + initialized = dist._initialized + else: + if dist.is_available(): + initialized = dist.is_initialized() + else: + initialized = False + if initialized: + rank = dist.get_rank() + world_size = dist.get_world_size() + else: + rank = 0 + world_size = 1 + return rank, world_size + + +def master_only(func): + + @functools.wraps(func) + def wrapper(*args, **kwargs): + rank, _ = get_dist_info() + if rank == 0: + return func(*args, **kwargs) + + return wrapper + + +def allreduce_params(params, coalesce=True, bucket_size_mb=-1): + """Allreduce parameters. + Args: + params (list[torch.Parameters]): List of parameters or buffers of a + model. + coalesce (bool, optional): Whether allreduce parameters as a whole. + Defaults to True. + bucket_size_mb (int, optional): Size of bucket, the unit is MB. + Defaults to -1. + """ + _, world_size = get_dist_info() + if world_size == 1: + return + params = [param.data for param in params] + if coalesce: + _allreduce_coalesced(params, world_size, bucket_size_mb) + else: + for tensor in params: + dist.all_reduce(tensor.div_(world_size)) + + +def allreduce_grads(params, coalesce=True, bucket_size_mb=-1): + """Allreduce gradients. + Args: + params (list[torch.Parameters]): List of parameters of a model + coalesce (bool, optional): Whether allreduce parameters as a whole. + Defaults to True. + bucket_size_mb (int, optional): Size of bucket, the unit is MB. + Defaults to -1. + """ + grads = [ + param.grad.data for param in params + if param.requires_grad and param.grad is not None + ] + _, world_size = get_dist_info() + if world_size == 1: + return + if coalesce: + _allreduce_coalesced(grads, world_size, bucket_size_mb) + else: + for tensor in grads: + dist.all_reduce(tensor.div_(world_size)) + + +def _allreduce_coalesced(tensors, world_size, bucket_size_mb=-1): + if bucket_size_mb > 0: + bucket_size_bytes = bucket_size_mb * 1024 * 1024 + buckets = _take_tensors(tensors, bucket_size_bytes) + else: + buckets = OrderedDict() + for tensor in tensors: + tp = tensor.type() + if tp not in buckets: + buckets[tp] = [] + buckets[tp].append(tensor) + buckets = buckets.values() + + for bucket in buckets: + flat_tensors = _flatten_dense_tensors(bucket) + dist.all_reduce(flat_tensors) + flat_tensors.div_(world_size) + for tensor, synced in zip( + bucket, _unflatten_dense_tensors(flat_tensors, bucket)): tensor.copy_(synced) \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/R(2+1)D/additional_need/mmcv/distributed.py b/PyTorch/contrib/cv/video/R(2+1)D/additional_need/mmcv/distributed.py index fb2bae922930929dc6fa46ad612463cc335dc208..4c89d09fc490488789ce565a7bad43ce7ded1568 100644 --- a/PyTorch/contrib/cv/video/R(2+1)D/additional_need/mmcv/distributed.py +++ b/PyTorch/contrib/cv/video/R(2+1)D/additional_need/mmcv/distributed.py @@ -1,119 +1,119 @@ -# Copyright (c) Open-MMLab. All rights reserved. -# -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -from torch.nn.parallel.distributed import (DistributedDataParallel, - _find_tensors) - -from mmcv import print_log -from mmcv.utils import TORCH_VERSION -from .scatter_gather import scatter_kwargs - - -class MMDistributedDataParallel(DistributedDataParallel): - """The DDP module that supports DataContainer. - - MMDDP has two main differences with PyTorch DDP: - - - It supports a custom type :class:`DataContainer` which allows more - flexible control of input data. - - It implement two APIs ``train_step()`` and ``val_step()``. - """ - - def scatter(self, inputs, kwargs, device_ids): - return scatter_kwargs(inputs, kwargs, device_ids, dim=self.dim) - - def train_step(self, *inputs, **kwargs): - """train_step() API for module wrapped by DistributedDataParallel. - - This method is basically the same as - ``DistributedDataParallel.forward()``, while replacing - ``self.module.forward()`` with ``self.module.train_step()``. - It is compatible with PyTorch 1.1 - 1.5. - """ - - # In PyTorch >= 1.7, ``reducer._rebuild_buckets()`` is moved from the - # end of backward to the beginning of forward. - if (TORCH_VERSION >= '1.7' and 'parrots' - not in TORCH_VERSION) and self.reducer._rebuild_buckets(): - print_log( - 'Reducer buckets have been rebuilt in this iteration.', - logger='mmcv') - - if getattr(self, 'require_forward_param_sync', True): - self._sync_params() - if self.device_ids and False: - inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) - if len(self.device_ids) == 1: - output = self.module.train_step(*inputs[0], **kwargs[0]) - else: - outputs = self.parallel_apply( - self._module_copies[:len(inputs)], inputs, kwargs) - output = self.gather(outputs, self.output_device) - else: - inputs, kwargs = self.scatter(inputs, kwargs, [-1]) - output = self.module.train_step(*inputs[0], **kwargs[0]) - - if torch.is_grad_enabled() and getattr( - self, 'require_backward_grad_sync', True): - if self.find_unused_parameters: - self.reducer.prepare_for_backward(list(_find_tensors(output))) - else: - self.reducer.prepare_for_backward([]) - else: - if TORCH_VERSION > '1.2': - self.require_forward_param_sync = False - return output - - def val_step(self, *inputs, **kwargs): - """val_step() API for module wrapped by DistributedDataParallel. - - This method is basically the same as - ``DistributedDataParallel.forward()``, while replacing - ``self.module.forward()`` with ``self.module.val_step()``. - It is compatible with PyTorch 1.1 - 1.5. - """ - # In PyTorch >= 1.7, ``reducer._rebuild_buckets()`` is moved from the - # end of backward to the beginning of forward. - if (TORCH_VERSION >= '1.7' and 'parrots' - not in TORCH_VERSION) and self.reducer._rebuild_buckets(): - print_log( - 'Reducer buckets have been rebuilt in this iteration.', - logger='mmcv') - - if getattr(self, 'require_forward_param_sync', True): - self._sync_params() - if self.device_ids: - inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) - if len(self.device_ids) == 1: - output = self.module.val_step(*inputs[0], **kwargs[0]) - else: - outputs = self.parallel_apply( - self._module_copies[:len(inputs)], inputs, kwargs) - output = self.gather(outputs, self.output_device) - else: - output = self.module.val_step(*inputs, **kwargs) - - if torch.is_grad_enabled() and getattr( - self, 'require_backward_grad_sync', True): - if self.find_unused_parameters: - self.reducer.prepare_for_backward(list(_find_tensors(output))) - else: - self.reducer.prepare_for_backward([]) - else: - if TORCH_VERSION > '1.2': - self.require_forward_param_sync = False - return output +# Copyright (c) Open-MMLab. All rights reserved. +# +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +from torch.nn.parallel.distributed import (DistributedDataParallel, + _find_tensors) + +from mmcv import print_log +from mmcv.utils import TORCH_VERSION +from .scatter_gather import scatter_kwargs + + +class MMDistributedDataParallel(DistributedDataParallel): + """The DDP module that supports DataContainer. + + MMDDP has two main differences with PyTorch DDP: + + - It supports a custom type :class:`DataContainer` which allows more + flexible control of input data. + - It implement two APIs ``train_step()`` and ``val_step()``. + """ + + def scatter(self, inputs, kwargs, device_ids): + return scatter_kwargs(inputs, kwargs, device_ids, dim=self.dim) + + def train_step(self, *inputs, **kwargs): + """train_step() API for module wrapped by DistributedDataParallel. + + This method is basically the same as + ``DistributedDataParallel.forward()``, while replacing + ``self.module.forward()`` with ``self.module.train_step()``. + It is compatible with PyTorch 1.1 - 1.5. + """ + + # In PyTorch >= 1.7, ``reducer._rebuild_buckets()`` is moved from the + # end of backward to the beginning of forward. + if (TORCH_VERSION >= '1.7' and 'parrots' + not in TORCH_VERSION) and self.reducer._rebuild_buckets(): + print_log( + 'Reducer buckets have been rebuilt in this iteration.', + logger='mmcv') + + if getattr(self, 'require_forward_param_sync', True): + self._sync_params() + if self.device_ids and False: + inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) + if len(self.device_ids) == 1: + output = self.module.train_step(*inputs[0], **kwargs[0]) + else: + outputs = self.parallel_apply( + self._module_copies[:len(inputs)], inputs, kwargs) + output = self.gather(outputs, self.output_device) + else: + inputs, kwargs = self.scatter(inputs, kwargs, [-1]) + output = self.module.train_step(*inputs[0], **kwargs[0]) + + if torch.is_grad_enabled() and getattr( + self, 'require_backward_grad_sync', True): + if self.find_unused_parameters: + self.reducer.prepare_for_backward(list(_find_tensors(output))) + else: + self.reducer.prepare_for_backward([]) + else: + if TORCH_VERSION > '1.2': + self.require_forward_param_sync = False + return output + + def val_step(self, *inputs, **kwargs): + """val_step() API for module wrapped by DistributedDataParallel. + + This method is basically the same as + ``DistributedDataParallel.forward()``, while replacing + ``self.module.forward()`` with ``self.module.val_step()``. + It is compatible with PyTorch 1.1 - 1.5. + """ + # In PyTorch >= 1.7, ``reducer._rebuild_buckets()`` is moved from the + # end of backward to the beginning of forward. + if (TORCH_VERSION >= '1.7' and 'parrots' + not in TORCH_VERSION) and self.reducer._rebuild_buckets(): + print_log( + 'Reducer buckets have been rebuilt in this iteration.', + logger='mmcv') + + if getattr(self, 'require_forward_param_sync', True): + self._sync_params() + if self.device_ids: + inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids) + if len(self.device_ids) == 1: + output = self.module.val_step(*inputs[0], **kwargs[0]) + else: + outputs = self.parallel_apply( + self._module_copies[:len(inputs)], inputs, kwargs) + output = self.gather(outputs, self.output_device) + else: + output = self.module.val_step(*inputs, **kwargs) + + if torch.is_grad_enabled() and getattr( + self, 'require_backward_grad_sync', True): + if self.find_unused_parameters: + self.reducer.prepare_for_backward(list(_find_tensors(output))) + else: + self.reducer.prepare_for_backward([]) + else: + if TORCH_VERSION > '1.2': + self.require_forward_param_sync = False + return output diff --git a/PyTorch/contrib/cv/video/R(2+1)D/additional_need/mmcv/optimizer.py b/PyTorch/contrib/cv/video/R(2+1)D/additional_need/mmcv/optimizer.py index 385978353dfebd6f7d24d3ce37ffafe63591563e..5956d430e829d63867f1a460cfe1e9f80c81ccc0 100644 --- a/PyTorch/contrib/cv/video/R(2+1)D/additional_need/mmcv/optimizer.py +++ b/PyTorch/contrib/cv/video/R(2+1)D/additional_need/mmcv/optimizer.py @@ -1,182 +1,182 @@ -# Copyright (c) Open-MMLab. All rights reserved. -# -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import copy -from collections import defaultdict -from itertools import chain - -from torch.nn.utils import clip_grad - -from ..dist_utils import allreduce_grads -from ..fp16_utils import LossScaler, wrap_fp16_model -from .hook import HOOKS, Hook -from apex import amp - -@HOOKS.register_module() -class OptimizerHook(Hook): - - def __init__(self, grad_clip=None): - self.grad_clip = grad_clip - - def clip_grads(self, params): - params = list( - filter(lambda p: p.requires_grad and p.grad is not None, params)) - #todo add a line - if len(params) > 0: - return clip_grad.clip_grad_norm_(params, **self.grad_clip) - - def after_train_iter(self, runner): - runner.optimizer.zero_grad() - with amp.scale_loss(runner.outputs['loss'], runner.optimizer ) as scaled_loss: - scaled_loss.backward() - #print('run wan with amp') - if self.grad_clip is not None: - grad_norm = self.clip_grads(runner.model.npu().parameters()) - if grad_norm is not None: - # Add grad norm to the logger - runner.log_buffer.update({'grad_norm': float(grad_norm)}, - runner.outputs['num_samples']) - #print('before optimizer step') - runner.optimizer.step() - #print('after optimizer step') - - - -@HOOKS.register_module() -class Fp16OptimizerHook(OptimizerHook): - """FP16 optimizer hook. - - The steps of fp16 optimizer is as follows. - 1. Scale the loss value. - 2. BP in the fp16 model. - 2. Copy gradients from fp16 model to fp32 weights. - 3. Update fp32 weights. - 4. Copy updated parameters from fp32 weights to fp16 model. - - Refer to https://arxiv.org/abs/1710.03740 for more details. - - Args: - loss_scale (float | str | dict): Scale factor multiplied with loss. - If loss_scale is a float, static loss scaling will be used with - the specified scale. If loss_scale is a string, it must be - 'dynamic', then dynamic loss scaling will be used. - It can also be a dict containing arguments of LossScaler. - Defaults to 512. - """ - - def __init__(self, - grad_clip=None, - coalesce=True, - bucket_size_mb=-1, - loss_scale=512., - distributed=True): - self.grad_clip = grad_clip - self.coalesce = coalesce - self.bucket_size_mb = bucket_size_mb - self.distributed = distributed - if loss_scale == 'dynamic': - self.loss_scaler = LossScaler(mode='dynamic') - elif isinstance(loss_scale, float): - self.loss_scaler = LossScaler(init_scale=loss_scale, mode='static') - elif isinstance(loss_scale, dict): - self.loss_scaler = LossScaler(**loss_scale) - else: - raise ValueError('loss_scale must be of type float, dict, or ' - f'"dynamic", got {loss_scale}') - - def before_run(self, runner): - """Preparing steps before Mixed Precision Training. - - 1. Make a master copy of fp32 weights for optimization. - 2. Convert the main model from fp32 to fp16. - """ - # keep a copy of fp32 weights - old_groups = runner.optimizer.param_groups - runner.optimizer.param_groups = copy.deepcopy( - runner.optimizer.param_groups) - state = defaultdict(dict) - p_map = { - old_p: p - for old_p, p in zip( - chain(*(g['params'] for g in old_groups)), - chain(*(g['params'] for g in runner.optimizer.param_groups))) - } - for k, v in runner.optimizer.state.items(): - state[p_map[k]] = v - runner.optimizer.state = state - # convert model to fp16 - wrap_fp16_model(runner.model) - - def copy_grads_to_fp32(self, fp16_net, fp32_weights): - """Copy gradients from fp16 model to fp32 weight copy.""" - for fp32_param, fp16_param in zip(fp32_weights, fp16_net.parameters()): - if fp16_param.grad is not None: - if fp32_param.grad is None: - fp32_param.grad = fp32_param.data.new(fp32_param.size()) - fp32_param.grad.copy_(fp16_param.grad) - - def copy_params_to_fp16(self, fp16_net, fp32_weights): - """Copy updated params from fp32 weight copy to fp16 model.""" - for fp16_param, fp32_param in zip(fp16_net.parameters(), fp32_weights): - fp16_param.data.copy_(fp32_param.data) - - def after_train_iter(self, runner): - """Backward optimization steps for Mixed Precision Training. For - dynamic loss scaling, please refer `loss_scalar.py` - - 1. Scale the loss by a scale factor. - 2. Backward the loss to obtain the gradients (fp16). - 3. Copy gradients from the model to the fp32 weight copy. - 4. Scale the gradients back and update the fp32 weight copy. - 5. Copy back the params from fp32 weight copy to the fp16 model. - """ - # clear grads of last iteration - runner.model.zero_grad() - runner.optimizer.zero_grad() - # scale the loss value - scaled_loss = runner.outputs['loss'] * self.loss_scaler.loss_scale - scaled_loss.backward() - # copy fp16 grads in the model to fp32 params in the optimizer - - fp32_weights = [] - for param_group in runner.optimizer.param_groups: - fp32_weights += param_group['params'] - self.copy_grads_to_fp32(runner.model, fp32_weights) - # allreduce grads - if self.distributed: - allreduce_grads(fp32_weights, self.coalesce, self.bucket_size_mb) - - has_overflow = self.loss_scaler.has_overflow(fp32_weights) - # if has overflow, skip this iteration - if not has_overflow: - # scale the gradients back - for param in fp32_weights: - if param.grad is not None: - param.grad.div_(self.loss_scaler.loss_scale) - if self.grad_clip is not None: - grad_norm = self.clip_grads(fp32_weights) - if grad_norm is not None: - # Add grad norm to the logger - runner.log_buffer.update({'grad_norm': float(grad_norm)}, - runner.outputs['num_samples']) - # update fp32 params - runner.optimizer.step() - # copy fp32 params to the fp16 model - self.copy_params_to_fp16(runner.model, fp32_weights) - self.loss_scaler.update_scale(has_overflow) - if has_overflow: - runner.logger.warning('Check overflow, downscale loss scale ' - f'to {self.loss_scaler.cur_scale}') +# Copyright (c) Open-MMLab. All rights reserved. +# +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import copy +from collections import defaultdict +from itertools import chain + +from torch.nn.utils import clip_grad + +from ..dist_utils import allreduce_grads +from ..fp16_utils import LossScaler, wrap_fp16_model +from .hook import HOOKS, Hook +from apex import amp + +@HOOKS.register_module() +class OptimizerHook(Hook): + + def __init__(self, grad_clip=None): + self.grad_clip = grad_clip + + def clip_grads(self, params): + params = list( + filter(lambda p: p.requires_grad and p.grad is not None, params)) + #todo add a line + if len(params) > 0: + return clip_grad.clip_grad_norm_(params, **self.grad_clip) + + def after_train_iter(self, runner): + runner.optimizer.zero_grad() + with amp.scale_loss(runner.outputs['loss'], runner.optimizer ) as scaled_loss: + scaled_loss.backward() + #print('run wan with amp') + if self.grad_clip is not None: + grad_norm = self.clip_grads(runner.model.npu().parameters()) + if grad_norm is not None: + # Add grad norm to the logger + runner.log_buffer.update({'grad_norm': float(grad_norm)}, + runner.outputs['num_samples']) + #print('before optimizer step') + runner.optimizer.step() + #print('after optimizer step') + + + +@HOOKS.register_module() +class Fp16OptimizerHook(OptimizerHook): + """FP16 optimizer hook. + + The steps of fp16 optimizer is as follows. + 1. Scale the loss value. + 2. BP in the fp16 model. + 2. Copy gradients from fp16 model to fp32 weights. + 3. Update fp32 weights. + 4. Copy updated parameters from fp32 weights to fp16 model. + + Refer to https://arxiv.org/abs/1710.03740 for more details. + + Args: + loss_scale (float | str | dict): Scale factor multiplied with loss. + If loss_scale is a float, static loss scaling will be used with + the specified scale. If loss_scale is a string, it must be + 'dynamic', then dynamic loss scaling will be used. + It can also be a dict containing arguments of LossScaler. + Defaults to 512. + """ + + def __init__(self, + grad_clip=None, + coalesce=True, + bucket_size_mb=-1, + loss_scale=512., + distributed=True): + self.grad_clip = grad_clip + self.coalesce = coalesce + self.bucket_size_mb = bucket_size_mb + self.distributed = distributed + if loss_scale == 'dynamic': + self.loss_scaler = LossScaler(mode='dynamic') + elif isinstance(loss_scale, float): + self.loss_scaler = LossScaler(init_scale=loss_scale, mode='static') + elif isinstance(loss_scale, dict): + self.loss_scaler = LossScaler(**loss_scale) + else: + raise ValueError('loss_scale must be of type float, dict, or ' + f'"dynamic", got {loss_scale}') + + def before_run(self, runner): + """Preparing steps before Mixed Precision Training. + + 1. Make a master copy of fp32 weights for optimization. + 2. Convert the main model from fp32 to fp16. + """ + # keep a copy of fp32 weights + old_groups = runner.optimizer.param_groups + runner.optimizer.param_groups = copy.deepcopy( + runner.optimizer.param_groups) + state = defaultdict(dict) + p_map = { + old_p: p + for old_p, p in zip( + chain(*(g['params'] for g in old_groups)), + chain(*(g['params'] for g in runner.optimizer.param_groups))) + } + for k, v in runner.optimizer.state.items(): + state[p_map[k]] = v + runner.optimizer.state = state + # convert model to fp16 + wrap_fp16_model(runner.model) + + def copy_grads_to_fp32(self, fp16_net, fp32_weights): + """Copy gradients from fp16 model to fp32 weight copy.""" + for fp32_param, fp16_param in zip(fp32_weights, fp16_net.parameters()): + if fp16_param.grad is not None: + if fp32_param.grad is None: + fp32_param.grad = fp32_param.data.new(fp32_param.size()) + fp32_param.grad.copy_(fp16_param.grad) + + def copy_params_to_fp16(self, fp16_net, fp32_weights): + """Copy updated params from fp32 weight copy to fp16 model.""" + for fp16_param, fp32_param in zip(fp16_net.parameters(), fp32_weights): + fp16_param.data.copy_(fp32_param.data) + + def after_train_iter(self, runner): + """Backward optimization steps for Mixed Precision Training. For + dynamic loss scaling, please refer `loss_scalar.py` + + 1. Scale the loss by a scale factor. + 2. Backward the loss to obtain the gradients (fp16). + 3. Copy gradients from the model to the fp32 weight copy. + 4. Scale the gradients back and update the fp32 weight copy. + 5. Copy back the params from fp32 weight copy to the fp16 model. + """ + # clear grads of last iteration + runner.model.zero_grad() + runner.optimizer.zero_grad() + # scale the loss value + scaled_loss = runner.outputs['loss'] * self.loss_scaler.loss_scale + scaled_loss.backward() + # copy fp16 grads in the model to fp32 params in the optimizer + + fp32_weights = [] + for param_group in runner.optimizer.param_groups: + fp32_weights += param_group['params'] + self.copy_grads_to_fp32(runner.model, fp32_weights) + # allreduce grads + if self.distributed: + allreduce_grads(fp32_weights, self.coalesce, self.bucket_size_mb) + + has_overflow = self.loss_scaler.has_overflow(fp32_weights) + # if has overflow, skip this iteration + if not has_overflow: + # scale the gradients back + for param in fp32_weights: + if param.grad is not None: + param.grad.div_(self.loss_scaler.loss_scale) + if self.grad_clip is not None: + grad_norm = self.clip_grads(fp32_weights) + if grad_norm is not None: + # Add grad norm to the logger + runner.log_buffer.update({'grad_norm': float(grad_norm)}, + runner.outputs['num_samples']) + # update fp32 params + runner.optimizer.step() + # copy fp32 params to the fp16 model + self.copy_params_to_fp16(runner.model, fp32_weights) + self.loss_scaler.update_scale(has_overflow) + if has_overflow: + runner.logger.warning('Check overflow, downscale loss scale ' + f'to {self.loss_scaler.cur_scale}') diff --git a/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_1p.py b/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_1p.py index a2efdbe74322f30057214c44af9804bd7ae93c19..f5475765077c996f0a54187b24a09986a57851d7 100644 --- a/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_1p.py +++ b/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_1p.py @@ -1,113 +1,113 @@ -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -_base_ = [ - '../../_base_/models/r2plus1d_r34.py', - '../../_base_/default_runtime.py' -] - -# dataset settings -dataset_type = 'RawframeDataset' -data_root = 'data/ucf101/rawframes/' -data_root_val = 'data/ucf101/rawframes/' -split = 1 # official train/test splits. valid numbers: 1, 2, 3 -ann_file_train = f'data/ucf101/ucf101_train_split_{split}_rawframes.txt' -ann_file_val = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' -ann_file_test = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' -img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) -train_pipeline = [ - dict(type='SampleFrames', clip_len=8, frame_interval=8, num_clips=1), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='RandomResizedCrop'), - dict(type='Resize', scale=(224, 224), keep_ratio=False), - dict(type='Flip', flip_ratio=0.5), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs', 'label']) -] -val_pipeline = [ - dict( - type='SampleFrames', - clip_len=8, - frame_interval=8, - num_clips=1, - test_mode=True), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='CenterCrop', crop_size=224), - dict(type='Flip', flip_ratio=0), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs']) -] -test_pipeline = [ - dict( - type='SampleFrames', - clip_len=8, - frame_interval=8, - num_clips=10, - test_mode=True), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='ThreeCrop', crop_size=256), - dict(type='Flip', flip_ratio=0), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs']) -] -data = dict( - videos_per_gpu=16, - workers_per_gpu=4, - train=dict( - type=dataset_type, - ann_file=ann_file_train, - data_prefix=data_root, - pipeline=train_pipeline), - val=dict( - type=dataset_type, - ann_file=ann_file_val, - data_prefix=data_root_val, - pipeline=val_pipeline), - test=dict( - type=dataset_type, - ann_file=ann_file_val, - data_prefix=data_root_val, - pipeline=test_pipeline)) -# optimizer -optimizer = dict( - type='SGD', lr=0.0025, momentum=0.9, - weight_decay=0.0001) # this lr is used for 8 gpus -optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) -# learning policy -# lr_config = dict(policy='step', steps=[1,2,3], lrs=[1e-3,1e-4,1e-5]) -lr_config = dict(policy='CosineAnnealing', min_lr=0) -total_epochs = 60 -# total_epochs = 90 - -# runtime settings -checkpoint_config = dict(interval=5) -evaluation = dict( - interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) -#work_dir = './work_dirs/r2plus1d_r34_8x8x1_180e_ucf101_rgb3/' -find_unused_parameters = True -load_from = 'https://download.openmmlab.com/mmaction/recognition/r2plus1d/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb_20200729-aa94765e.pth' -resume_from = None - +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +_base_ = [ + '../../_base_/models/r2plus1d_r34.py', + '../../_base_/default_runtime.py' +] + +# dataset settings +dataset_type = 'RawframeDataset' +data_root = 'data/ucf101/rawframes/' +data_root_val = 'data/ucf101/rawframes/' +split = 1 # official train/test splits. valid numbers: 1, 2, 3 +ann_file_train = f'data/ucf101/ucf101_train_split_{split}_rawframes.txt' +ann_file_val = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' +ann_file_test = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) +train_pipeline = [ + dict(type='SampleFrames', clip_len=8, frame_interval=8, num_clips=1), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='RandomResizedCrop'), + dict(type='Resize', scale=(224, 224), keep_ratio=False), + dict(type='Flip', flip_ratio=0.5), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs', 'label']) +] +val_pipeline = [ + dict( + type='SampleFrames', + clip_len=8, + frame_interval=8, + num_clips=1, + test_mode=True), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='CenterCrop', crop_size=224), + dict(type='Flip', flip_ratio=0), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs']) +] +test_pipeline = [ + dict( + type='SampleFrames', + clip_len=8, + frame_interval=8, + num_clips=10, + test_mode=True), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='ThreeCrop', crop_size=256), + dict(type='Flip', flip_ratio=0), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs']) +] +data = dict( + videos_per_gpu=16, + workers_per_gpu=4, + train=dict( + type=dataset_type, + ann_file=ann_file_train, + data_prefix=data_root, + pipeline=train_pipeline), + val=dict( + type=dataset_type, + ann_file=ann_file_val, + data_prefix=data_root_val, + pipeline=val_pipeline), + test=dict( + type=dataset_type, + ann_file=ann_file_val, + data_prefix=data_root_val, + pipeline=test_pipeline)) +# optimizer +optimizer = dict( + type='SGD', lr=0.0025, momentum=0.9, + weight_decay=0.0001) # this lr is used for 8 gpus +optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) +# learning policy +# lr_config = dict(policy='step', steps=[1,2,3], lrs=[1e-3,1e-4,1e-5]) +lr_config = dict(policy='CosineAnnealing', min_lr=0) +total_epochs = 60 +# total_epochs = 90 + +# runtime settings +checkpoint_config = dict(interval=5) +evaluation = dict( + interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) +#work_dir = './work_dirs/r2plus1d_r34_8x8x1_180e_ucf101_rgb3/' +find_unused_parameters = True +load_from = 'https://download.openmmlab.com/mmaction/recognition/r2plus1d/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb_20200729-aa94765e.pth' +resume_from = None + work_dir = './work_dirs/r2plus1d-1p-npu/' \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_1p_perf.py b/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_1p_perf.py index bde3e578dd5ffd7106e9fa96bb11b9ed233308a8..829d7bb6f9ea901814e479e931e2a99397dabf1d 100644 --- a/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_1p_perf.py +++ b/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_1p_perf.py @@ -1,113 +1,113 @@ -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -_base_ = [ - '../../_base_/models/r2plus1d_r34.py', - '../../_base_/default_runtime.py' -] - -# dataset settings -dataset_type = 'RawframeDataset' -data_root = 'data/ucf101/rawframes/' -data_root_val = 'data/ucf101/rawframes/' -split = 1 # official train/test splits. valid numbers: 1, 2, 3 -ann_file_train = f'data/ucf101/ucf101_train_split_{split}_rawframes.txt' -ann_file_val = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' -ann_file_test = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' -img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) -train_pipeline = [ - dict(type='SampleFrames', clip_len=8, frame_interval=8, num_clips=1), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='RandomResizedCrop'), - dict(type='Resize', scale=(224, 224), keep_ratio=False), - dict(type='Flip', flip_ratio=0.5), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs', 'label']) -] -val_pipeline = [ - dict( - type='SampleFrames', - clip_len=8, - frame_interval=8, - num_clips=1, - test_mode=True), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='CenterCrop', crop_size=224), - dict(type='Flip', flip_ratio=0), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs']) -] -test_pipeline = [ - dict( - type='SampleFrames', - clip_len=8, - frame_interval=8, - num_clips=10, - test_mode=True), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='ThreeCrop', crop_size=256), - dict(type='Flip', flip_ratio=0), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs']) -] -data = dict( - videos_per_gpu=16, - workers_per_gpu=4, - train=dict( - type=dataset_type, - ann_file=ann_file_train, - data_prefix=data_root, - pipeline=train_pipeline), - val=dict( - type=dataset_type, - ann_file=ann_file_val, - data_prefix=data_root_val, - pipeline=val_pipeline), - test=dict( - type=dataset_type, - ann_file=ann_file_val, - data_prefix=data_root_val, - pipeline=test_pipeline)) -# optimizer -optimizer = dict( - type='SGD', lr=0.0025, momentum=0.9, - weight_decay=0.0001) # this lr is used for 8 gpus -optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) -# learning policy -# lr_config = dict(policy='step', steps=[1,2,3], lrs=[1e-3,1e-4,1e-5]) -lr_config = dict(policy='CosineAnnealing', min_lr=0) -total_epochs = 1 -# total_epochs = 90 - -# runtime settings -checkpoint_config = dict(interval=5) -evaluation = dict( - interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) -#work_dir = './work_dirs/r2plus1d_r34_8x8x1_180e_ucf101_rgb3/' -find_unused_parameters = True -load_from = 'https://download.openmmlab.com/mmaction/recognition/r2plus1d/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb_20200729-aa94765e.pth' -resume_from = None - +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +_base_ = [ + '../../_base_/models/r2plus1d_r34.py', + '../../_base_/default_runtime.py' +] + +# dataset settings +dataset_type = 'RawframeDataset' +data_root = 'data/ucf101/rawframes/' +data_root_val = 'data/ucf101/rawframes/' +split = 1 # official train/test splits. valid numbers: 1, 2, 3 +ann_file_train = f'data/ucf101/ucf101_train_split_{split}_rawframes.txt' +ann_file_val = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' +ann_file_test = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) +train_pipeline = [ + dict(type='SampleFrames', clip_len=8, frame_interval=8, num_clips=1), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='RandomResizedCrop'), + dict(type='Resize', scale=(224, 224), keep_ratio=False), + dict(type='Flip', flip_ratio=0.5), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs', 'label']) +] +val_pipeline = [ + dict( + type='SampleFrames', + clip_len=8, + frame_interval=8, + num_clips=1, + test_mode=True), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='CenterCrop', crop_size=224), + dict(type='Flip', flip_ratio=0), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs']) +] +test_pipeline = [ + dict( + type='SampleFrames', + clip_len=8, + frame_interval=8, + num_clips=10, + test_mode=True), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='ThreeCrop', crop_size=256), + dict(type='Flip', flip_ratio=0), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs']) +] +data = dict( + videos_per_gpu=16, + workers_per_gpu=4, + train=dict( + type=dataset_type, + ann_file=ann_file_train, + data_prefix=data_root, + pipeline=train_pipeline), + val=dict( + type=dataset_type, + ann_file=ann_file_val, + data_prefix=data_root_val, + pipeline=val_pipeline), + test=dict( + type=dataset_type, + ann_file=ann_file_val, + data_prefix=data_root_val, + pipeline=test_pipeline)) +# optimizer +optimizer = dict( + type='SGD', lr=0.0025, momentum=0.9, + weight_decay=0.0001) # this lr is used for 8 gpus +optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) +# learning policy +# lr_config = dict(policy='step', steps=[1,2,3], lrs=[1e-3,1e-4,1e-5]) +lr_config = dict(policy='CosineAnnealing', min_lr=0) +total_epochs = 1 +# total_epochs = 90 + +# runtime settings +checkpoint_config = dict(interval=5) +evaluation = dict( + interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) +#work_dir = './work_dirs/r2plus1d_r34_8x8x1_180e_ucf101_rgb3/' +find_unused_parameters = True +load_from = 'https://download.openmmlab.com/mmaction/recognition/r2plus1d/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb_20200729-aa94765e.pth' +resume_from = None + work_dir = './work_dirs/r2plus1d-1p-npu/' \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_8p.py b/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_8p.py index edf87d1e4bac895dfd7a21e77f8f1194dd1b4984..d67fd10c1aa2c00eca331a248fa6b9676bbf64b2 100644 --- a/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_8p.py +++ b/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_8p.py @@ -1,113 +1,113 @@ -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -_base_ = [ - '../../_base_/models/r2plus1d_r34.py', - '../../_base_/default_runtime.py' -] - -# dataset settings -dataset_type = 'RawframeDataset' -data_root = 'data/ucf101/rawframes/' -data_root_val = 'data/ucf101/rawframes/' -split = 1 # official train/test splits. valid numbers: 1, 2, 3 -ann_file_train = f'data/ucf101/ucf101_train_split_{split}_rawframes.txt' -ann_file_val = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' -ann_file_test = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' -img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) -train_pipeline = [ - dict(type='SampleFrames', clip_len=8, frame_interval=8, num_clips=1), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='RandomResizedCrop'), - dict(type='Resize', scale=(224, 224), keep_ratio=False), - dict(type='Flip', flip_ratio=0.5), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs', 'label']) -] -val_pipeline = [ - dict( - type='SampleFrames', - clip_len=8, - frame_interval=8, - num_clips=1, - test_mode=True), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='CenterCrop', crop_size=224), - dict(type='Flip', flip_ratio=0), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs']) -] -test_pipeline = [ - dict( - type='SampleFrames', - clip_len=8, - frame_interval=8, - num_clips=10, - test_mode=True), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='ThreeCrop', crop_size=256), - dict(type='Flip', flip_ratio=0), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs']) -] -data = dict( - videos_per_gpu=42, - workers_per_gpu=4, - train=dict( - type=dataset_type, - ann_file=ann_file_train, - data_prefix=data_root, - pipeline=train_pipeline), - val=dict( - type=dataset_type, - ann_file=ann_file_val, - data_prefix=data_root_val, - pipeline=val_pipeline), - test=dict( - type=dataset_type, - ann_file=ann_file_val, - data_prefix=data_root_val, - pipeline=test_pipeline)) -# optimizer -optimizer = dict( - type='SGD', lr=0.008, momentum=0.9, - weight_decay=0.0001) # this lr is used for 8 gpus -optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) -# learning policy -# lr_config = dict(policy='step', steps=[1,2,3], lrs=[1e-3,1e-4,1e-5]) -lr_config = dict(policy='CosineAnnealing', min_lr=0) -total_epochs = 70 -# total_epochs = 90 - -# runtime settings -checkpoint_config = dict(interval=5) -evaluation = dict( - interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) -#work_dir = './work_dirs/r2plus1d_r34_8x8x1_180e_ucf101_rgb3/' -find_unused_parameters = True -load_from = 'https://download.openmmlab.com/mmaction/recognition/r2plus1d/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb_20200729-aa94765e.pth' -resume_from = None - +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +_base_ = [ + '../../_base_/models/r2plus1d_r34.py', + '../../_base_/default_runtime.py' +] + +# dataset settings +dataset_type = 'RawframeDataset' +data_root = 'data/ucf101/rawframes/' +data_root_val = 'data/ucf101/rawframes/' +split = 1 # official train/test splits. valid numbers: 1, 2, 3 +ann_file_train = f'data/ucf101/ucf101_train_split_{split}_rawframes.txt' +ann_file_val = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' +ann_file_test = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) +train_pipeline = [ + dict(type='SampleFrames', clip_len=8, frame_interval=8, num_clips=1), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='RandomResizedCrop'), + dict(type='Resize', scale=(224, 224), keep_ratio=False), + dict(type='Flip', flip_ratio=0.5), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs', 'label']) +] +val_pipeline = [ + dict( + type='SampleFrames', + clip_len=8, + frame_interval=8, + num_clips=1, + test_mode=True), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='CenterCrop', crop_size=224), + dict(type='Flip', flip_ratio=0), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs']) +] +test_pipeline = [ + dict( + type='SampleFrames', + clip_len=8, + frame_interval=8, + num_clips=10, + test_mode=True), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='ThreeCrop', crop_size=256), + dict(type='Flip', flip_ratio=0), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs']) +] +data = dict( + videos_per_gpu=42, + workers_per_gpu=4, + train=dict( + type=dataset_type, + ann_file=ann_file_train, + data_prefix=data_root, + pipeline=train_pipeline), + val=dict( + type=dataset_type, + ann_file=ann_file_val, + data_prefix=data_root_val, + pipeline=val_pipeline), + test=dict( + type=dataset_type, + ann_file=ann_file_val, + data_prefix=data_root_val, + pipeline=test_pipeline)) +# optimizer +optimizer = dict( + type='SGD', lr=0.008, momentum=0.9, + weight_decay=0.0001) # this lr is used for 8 gpus +optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) +# learning policy +# lr_config = dict(policy='step', steps=[1,2,3], lrs=[1e-3,1e-4,1e-5]) +lr_config = dict(policy='CosineAnnealing', min_lr=0) +total_epochs = 70 +# total_epochs = 90 + +# runtime settings +checkpoint_config = dict(interval=5) +evaluation = dict( + interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) +#work_dir = './work_dirs/r2plus1d_r34_8x8x1_180e_ucf101_rgb3/' +find_unused_parameters = True +load_from = 'https://download.openmmlab.com/mmaction/recognition/r2plus1d/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb_20200729-aa94765e.pth' +resume_from = None + work_dir = './work_dirs/r2plus1d-8p-npu/' \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_8p_perf.py b/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_8p_perf.py index b0d83a2679cfe62835e0596ea7a7e8e55d78ced1..35f1356e12d9de0ae3c4a94b235062ff903822c3 100644 --- a/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_8p_perf.py +++ b/PyTorch/contrib/cv/video/R(2+1)D/configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_8p_perf.py @@ -1,113 +1,113 @@ -# -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -_base_ = [ - '../../_base_/models/r2plus1d_r34.py', - '../../_base_/default_runtime.py' -] - -# dataset settings -dataset_type = 'RawframeDataset' -data_root = 'data/ucf101/rawframes/' -data_root_val = 'data/ucf101/rawframes/' -split = 1 # official train/test splits. valid numbers: 1, 2, 3 -ann_file_train = f'data/ucf101/ucf101_train_split_{split}_rawframes.txt' -ann_file_val = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' -ann_file_test = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' -img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) -train_pipeline = [ - dict(type='SampleFrames', clip_len=8, frame_interval=8, num_clips=1), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='RandomResizedCrop'), - dict(type='Resize', scale=(224, 224), keep_ratio=False), - dict(type='Flip', flip_ratio=0.5), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs', 'label']) -] -val_pipeline = [ - dict( - type='SampleFrames', - clip_len=8, - frame_interval=8, - num_clips=1, - test_mode=True), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='CenterCrop', crop_size=224), - dict(type='Flip', flip_ratio=0), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs']) -] -test_pipeline = [ - dict( - type='SampleFrames', - clip_len=8, - frame_interval=8, - num_clips=10, - test_mode=True), - dict(type='RawFrameDecode'), - dict(type='Resize', scale=(-1, 256)), - dict(type='ThreeCrop', crop_size=256), - dict(type='Flip', flip_ratio=0), - dict(type='Normalize', **img_norm_cfg), - dict(type='FormatShape', input_format='NCTHW'), - dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), - dict(type='ToTensor', keys=['imgs']) -] -data = dict( - videos_per_gpu=42, - workers_per_gpu=4, - train=dict( - type=dataset_type, - ann_file=ann_file_train, - data_prefix=data_root, - pipeline=train_pipeline), - val=dict( - type=dataset_type, - ann_file=ann_file_val, - data_prefix=data_root_val, - pipeline=val_pipeline), - test=dict( - type=dataset_type, - ann_file=ann_file_val, - data_prefix=data_root_val, - pipeline=test_pipeline)) -# optimizer -optimizer = dict( - type='SGD', lr=0.008, momentum=0.9, - weight_decay=0.0001) # this lr is used for 8 gpus -optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) -# learning policy -# lr_config = dict(policy='step', steps=[1,2,3], lrs=[1e-3,1e-4,1e-5]) -lr_config = dict(policy='CosineAnnealing', min_lr=0) -total_epochs = 1 -# total_epochs = 90 - -# runtime settings -checkpoint_config = dict(interval=5) -evaluation = dict( - interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) -#work_dir = './work_dirs/r2plus1d_r34_8x8x1_180e_ucf101_rgb3/' -find_unused_parameters = True -load_from = 'https://download.openmmlab.com/mmaction/recognition/r2plus1d/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb_20200729-aa94765e.pth' -resume_from = None - +# +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +_base_ = [ + '../../_base_/models/r2plus1d_r34.py', + '../../_base_/default_runtime.py' +] + +# dataset settings +dataset_type = 'RawframeDataset' +data_root = 'data/ucf101/rawframes/' +data_root_val = 'data/ucf101/rawframes/' +split = 1 # official train/test splits. valid numbers: 1, 2, 3 +ann_file_train = f'data/ucf101/ucf101_train_split_{split}_rawframes.txt' +ann_file_val = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' +ann_file_test = f'data/ucf101/ucf101_val_split_{split}_rawframes.txt' +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_bgr=False) +train_pipeline = [ + dict(type='SampleFrames', clip_len=8, frame_interval=8, num_clips=1), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='RandomResizedCrop'), + dict(type='Resize', scale=(224, 224), keep_ratio=False), + dict(type='Flip', flip_ratio=0.5), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs', 'label']) +] +val_pipeline = [ + dict( + type='SampleFrames', + clip_len=8, + frame_interval=8, + num_clips=1, + test_mode=True), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='CenterCrop', crop_size=224), + dict(type='Flip', flip_ratio=0), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs']) +] +test_pipeline = [ + dict( + type='SampleFrames', + clip_len=8, + frame_interval=8, + num_clips=10, + test_mode=True), + dict(type='RawFrameDecode'), + dict(type='Resize', scale=(-1, 256)), + dict(type='ThreeCrop', crop_size=256), + dict(type='Flip', flip_ratio=0), + dict(type='Normalize', **img_norm_cfg), + dict(type='FormatShape', input_format='NCTHW'), + dict(type='Collect', keys=['imgs', 'label'], meta_keys=[]), + dict(type='ToTensor', keys=['imgs']) +] +data = dict( + videos_per_gpu=42, + workers_per_gpu=4, + train=dict( + type=dataset_type, + ann_file=ann_file_train, + data_prefix=data_root, + pipeline=train_pipeline), + val=dict( + type=dataset_type, + ann_file=ann_file_val, + data_prefix=data_root_val, + pipeline=val_pipeline), + test=dict( + type=dataset_type, + ann_file=ann_file_val, + data_prefix=data_root_val, + pipeline=test_pipeline)) +# optimizer +optimizer = dict( + type='SGD', lr=0.008, momentum=0.9, + weight_decay=0.0001) # this lr is used for 8 gpus +optimizer_config = dict(grad_clip=dict(max_norm=40, norm_type=2)) +# learning policy +# lr_config = dict(policy='step', steps=[1,2,3], lrs=[1e-3,1e-4,1e-5]) +lr_config = dict(policy='CosineAnnealing', min_lr=0) +total_epochs = 1 +# total_epochs = 90 + +# runtime settings +checkpoint_config = dict(interval=5) +evaluation = dict( + interval=5, metrics=['top_k_accuracy', 'mean_class_accuracy']) +#work_dir = './work_dirs/r2plus1d_r34_8x8x1_180e_ucf101_rgb3/' +find_unused_parameters = True +load_from = 'https://download.openmmlab.com/mmaction/recognition/r2plus1d/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb/r2plus1d_r34_256p_8x8x1_180e_kinetics400_rgb_20200729-aa94765e.pth' +resume_from = None + work_dir = './work_dirs/r2plus1d-8p-npu/' \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/R(2+1)D/modelzoo_level.txt b/PyTorch/contrib/cv/video/R(2+1)D/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/cv/video/R(2+1)D/modelzoo_level.txt +++ b/PyTorch/contrib/cv/video/R(2+1)D/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/R(2+1)D/test/onnx.sh b/PyTorch/contrib/cv/video/R(2+1)D/test/onnx.sh index 4b04b49017fff5085d927c2c1d152faad664842d..c9272a2993fd9fca51c0bd2033027aaf3e0851bf 100644 --- a/PyTorch/contrib/cv/video/R(2+1)D/test/onnx.sh +++ b/PyTorch/contrib/cv/video/R(2+1)D/test/onnx.sh @@ -1,10 +1,10 @@ -#!/bin/bash - -python3.7 ./tools/deployment/pytorch2onnx.py \ - ./configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_1p.py ./work_dirs/r2plus1d-1p-npu/best_top1_acc_epoch_35.pth \ - --verify --output-file=r2plus1d.onnx --shape 1 3 3 8 256 256 - -#简化onnx。 -python3.7 -m onnxsim --input-shape="1,3,3,8,256,256" --dynamic-input-shape r2plus1d.onnx r2plus1d_sim.onnx - +#!/bin/bash + +python3.7 ./tools/deployment/pytorch2onnx.py \ + ./configs/recognition/r2plus1d/r2plus1d_ucf101_rgb_1p.py ./work_dirs/r2plus1d-1p-npu/best_top1_acc_epoch_35.pth \ + --verify --output-file=r2plus1d.onnx --shape 1 3 3 8 256 256 + +#简化onnx。 +python3.7 -m onnxsim --input-shape="1,3,3,8,256,256" --dynamic-input-shape r2plus1d.onnx r2plus1d_sim.onnx + \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/__init__.py b/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/__init__.py index a5f8598aa44dc6b32162d43ee60c98a1725037ef..89552b1d3f5f6255840161c8c17cf314ab3fedff 100644 --- a/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/__init__.py +++ b/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/__init__.py @@ -1,13 +1,13 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/models/__init__.py b/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/models/__init__.py index a5f8598aa44dc6b32162d43ee60c98a1725037ef..89552b1d3f5f6255840161c8c17cf314ab3fedff 100644 --- a/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/models/__init__.py +++ b/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/models/__init__.py @@ -1,13 +1,13 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/tracker/__init__.py b/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/tracker/__init__.py index a5f8598aa44dc6b32162d43ee60c98a1725037ef..89552b1d3f5f6255840161c8c17cf314ab3fedff 100644 --- a/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/tracker/__init__.py +++ b/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/tracker/__init__.py @@ -1,13 +1,13 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/utils/__init__.py b/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/utils/__init__.py index a5f8598aa44dc6b32162d43ee60c98a1725037ef..89552b1d3f5f6255840161c8c17cf314ab3fedff 100644 --- a/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/utils/__init__.py +++ b/PyTorch/contrib/cv/video/SiamRPN/pysot-master/pysot/utils/__init__.py @@ -1,13 +1,13 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/SiamRPN/pysot-master/toolkit/__init__.py b/PyTorch/contrib/cv/video/SiamRPN/pysot-master/toolkit/__init__.py index a5f8598aa44dc6b32162d43ee60c98a1725037ef..89552b1d3f5f6255840161c8c17cf314ab3fedff 100644 --- a/PyTorch/contrib/cv/video/SiamRPN/pysot-master/toolkit/__init__.py +++ b/PyTorch/contrib/cv/video/SiamRPN/pysot-master/toolkit/__init__.py @@ -1,13 +1,13 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/SiamRPN/pysot-master/vot_iter/__init__.py b/PyTorch/contrib/cv/video/SiamRPN/pysot-master/vot_iter/__init__.py index a5f8598aa44dc6b32162d43ee60c98a1725037ef..89552b1d3f5f6255840161c8c17cf314ab3fedff 100644 --- a/PyTorch/contrib/cv/video/SiamRPN/pysot-master/vot_iter/__init__.py +++ b/PyTorch/contrib/cv/video/SiamRPN/pysot-master/vot_iter/__init__.py @@ -1,13 +1,13 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/SlowFast/config/default_runtime.py b/PyTorch/contrib/cv/video/SlowFast/config/default_runtime.py index 41329bf37107afc6238c8360bc11dd80efd93324..7652836b33c6b6c3927a2e0bea18322d4cc13788 100644 --- a/PyTorch/contrib/cv/video/SlowFast/config/default_runtime.py +++ b/PyTorch/contrib/cv/video/SlowFast/config/default_runtime.py @@ -1,27 +1,27 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -checkpoint_config = dict(interval=5) -log_config = dict( - interval=1, - hooks=[ - dict(type='TextLoggerHook'), - # dict(type='TensorboardLoggerHook'), - ]) -# runtime settings -dist_params = dict(backend='nccl') -log_level = 'INFO' -load_from = None -resume_from = None -workflow = [('train', 1)] +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +checkpoint_config = dict(interval=5) +log_config = dict( + interval=1, + hooks=[ + dict(type='TextLoggerHook'), + # dict(type='TensorboardLoggerHook'), + ]) +# runtime settings +dist_params = dict(backend='nccl') +log_level = 'INFO' +load_from = None +resume_from = None +workflow = [('train', 1)] diff --git a/PyTorch/contrib/cv/video/SlowFast/mmaction/apis/train.py b/PyTorch/contrib/cv/video/SlowFast/mmaction/apis/train.py index 59f1bc0a8ab759f36a0485076f0585add1bd384e..d50c7f7e6ae9f8487dea82a33bb3351356bbaaf8 100644 --- a/PyTorch/contrib/cv/video/SlowFast/mmaction/apis/train.py +++ b/PyTorch/contrib/cv/video/SlowFast/mmaction/apis/train.py @@ -1,267 +1,267 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import copy as cp -import os.path as osp - -from apex import amp - -import torch -from mmcv.parallel import MMDataParallel, MMDistributedDataParallel -from mmcv.runner import (DistSamplerSeedHook, EpochBasedRunner, OptimizerHook, - build_optimizer, get_dist_info) -from mmcv.runner.hooks import Fp16OptimizerHook - -from ..core import (DistEvalHook, EvalHook, OmniSourceDistSamplerSeedHook, - OmniSourceRunner) -from ..datasets import build_dataloader, build_dataset -from ..utils import PreciseBNHook, get_root_logger -from .test import multi_gpu_test - - -def train_model(model, - dataset, - cfg, - distributed=False, - validate=False, - test=dict(test_best=False, test_last=False), - timestamp=None, - meta=None): - """Train model entry function. - - Args: - model (nn.Module): The model to be trained. - dataset (:obj:`Dataset`): Train dataset. - cfg (dict): The config dict for training. - distributed (bool): Whether to use distributed training. - Default: False. - validate (bool): Whether to do evaluation. Default: False. - test (dict): The testing option, with two keys: test_last & test_best. - The value is True or False, indicating whether to test the - corresponding checkpoint. - Default: dict(test_best=False, test_last=False). - timestamp (str | None): Local time for runner. Default: None. - meta (dict | None): Meta dict to record some important information. - Default: None - """ - logger = get_root_logger(log_level=cfg.log_level) - - # prepare data loaders - dataset = dataset if isinstance(dataset, (list, tuple)) else [dataset] - - dataloader_setting = dict(videos_per_gpu=cfg.data.get('videos_per_gpu', 1), - workers_per_gpu=cfg.data.get( - 'workers_per_gpu', 1), - num_gpus=len(cfg.gpu_ids), - dist=distributed, - seed=cfg.seed) - dataloader_setting = dict(dataloader_setting, - **cfg.data.get('train_dataloader', {})) - - if cfg.omnisource: - # The option can override videos_per_gpu - train_ratio = cfg.data.get('train_ratio', [1] * len(dataset)) - omni_videos_per_gpu = cfg.data.get('omni_videos_per_gpu', None) - if omni_videos_per_gpu is None: - dataloader_settings = [dataloader_setting] * len(dataset) - else: - dataloader_settings = [] - for videos_per_gpu in omni_videos_per_gpu: - this_setting = cp.deepcopy(dataloader_setting) - this_setting['videos_per_gpu'] = videos_per_gpu - dataloader_settings.append(this_setting) - data_loaders = [ - build_dataloader(ds, **setting) - for ds, setting in zip(dataset, dataloader_settings) - ] - - else: - data_loaders = [ - build_dataloader(ds, **dataloader_setting) for ds in dataset - ] - - # build runner - optimizer = build_optimizer(model, cfg.optimizer) - - # Allow Amp to perform casts as required by the opt_level - if cfg.AMP: - # model, optimizer = amp.initialize(model.cuda(), - # optimizer, - # opt_level=cfg.OPT_LEVEL, - # loss_scale=cfg.LOSS_SCALE) - model, optimizer = amp.initialize(model.npu(), - optimizer, - opt_level=cfg.OPT_LEVEL, - loss_scale=cfg.LOSS_SCALE, - combine_grad=True) - - # put model on gpus - if distributed: - find_unused_parameters = cfg.get('find_unused_parameters', False) - # Sets the `find_unused_parameters` parameter in - # torch.nn.parallel.DistributedDataParallel - model = MMDistributedDataParallel( - model, - device_ids=[torch.npu.current_device()], - broadcast_buffers=False, - find_unused_parameters=find_unused_parameters) - # model = MMDistributedDataParallel( - # model, - # device_ids=[torch.cuda.current_device()], - # broadcast_buffers=False, - # find_unused_parameters=find_unused_parameters) - - else: - # In 1-p training, we don't use Dataparallel - # model = MMDataParallel(model.cuda(cfg.gpu_ids[0]), - # device_ids=cfg.gpu_ids) - model = model.npu() - - Runner = OmniSourceRunner if cfg.omnisource else EpochBasedRunner - runner = Runner(model, - optimizer=optimizer, - work_dir=cfg.work_dir, - logger=logger, - meta=meta, - distributed=distributed) - # an ugly workaround to make .log and .log.json filenames the same - runner.timestamp = timestamp - - # fp16 setting - fp16_cfg = cfg.get('fp16', None) - if fp16_cfg is not None: - optimizer_config = Fp16OptimizerHook(**cfg.optimizer_config, - **fp16_cfg, - distributed=distributed) - elif distributed and 'type' not in cfg.optimizer_config: - optimizer_config = OptimizerHook(**cfg.optimizer_config) - else: - optimizer_config = cfg.optimizer_config - - # register hooks - runner.register_training_hooks(cfg.lr_config, optimizer_config, - cfg.checkpoint_config, cfg.log_config, - cfg.get('momentum_config', None)) - if distributed: - if cfg.omnisource: - runner.register_hook(OmniSourceDistSamplerSeedHook()) - else: - runner.register_hook(DistSamplerSeedHook()) - - # precise bn setting - if cfg.get('precise_bn', False): - precise_bn_dataset = build_dataset(cfg.data.train) - dataloader_setting = dict( - videos_per_gpu=cfg.data.get('videos_per_gpu', 1), - workers_per_gpu=0, # save memory and time - num_gpus=len(cfg.gpu_ids), - dist=distributed, - seed=cfg.seed) - data_loader_precise_bn = build_dataloader(precise_bn_dataset, - **dataloader_setting) - precise_bn_hook = PreciseBNHook(data_loader_precise_bn, - **cfg.get('precise_bn')) - runner.register_hook(precise_bn_hook) - - if validate: - eval_cfg = cfg.get('evaluation', {}) - val_dataset = build_dataset(cfg.data.val, dict(test_mode=True)) - dataloader_setting = dict( - videos_per_gpu=cfg.data.get('videos_per_gpu', 1), - workers_per_gpu=cfg.data.get('workers_per_gpu', 1), - # cfg.gpus will be ignored if distributed - num_gpus=len(cfg.gpu_ids), - dist=distributed, - shuffle=False) - dataloader_setting = dict(dataloader_setting, - **cfg.data.get('val_dataloader', {})) - val_dataloader = build_dataloader(val_dataset, **dataloader_setting) - eval_hook = DistEvalHook(val_dataloader, **eval_cfg) if distributed \ - else EvalHook(val_dataloader, **eval_cfg) - runner.register_hook(eval_hook) - - if cfg.resume_from: - runner.resume(cfg.resume_from) - elif cfg.load_from: - runner.load_checkpoint(cfg.load_from) - runner_kwargs = dict() - if cfg.omnisource: - runner_kwargs = dict(train_ratio=train_ratio) - runner.run(data_loaders, cfg.workflow, cfg.total_epochs, **runner_kwargs) - - if test['test_last'] or test['test_best']: - best_ckpt_path = None - if test['test_best']: - if hasattr(eval_hook, 'best_ckpt_path'): - best_ckpt_path = eval_hook.best_ckpt_path - - if best_ckpt_path is None or not osp.exists(best_ckpt_path): - test['test_best'] = False - if best_ckpt_path is None: - runner.logger.info('Warning: test_best set as True, but ' - 'is not applicable ' - '(eval_hook.best_ckpt_path is None)') - else: - runner.logger.info('Warning: test_best set as True, but ' - 'is not applicable (best_ckpt ' - f'{best_ckpt_path} not found)') - if not test['test_last']: - return - - test_dataset = build_dataset(cfg.data.test, dict(test_mode=True)) - gpu_collect = cfg.get('evaluation', {}).get('gpu_collect', False) - tmpdir = cfg.get('evaluation', {}).get('tmpdir', - osp.join(cfg.work_dir, 'tmp')) - dataloader_setting = dict( - videos_per_gpu=cfg.data.get('videos_per_gpu', 1), - workers_per_gpu=cfg.data.get('workers_per_gpu', 1), - num_gpus=len(cfg.gpu_ids), - dist=distributed, - shuffle=False) - dataloader_setting = dict(dataloader_setting, - **cfg.data.get('test_dataloader', {})) - - test_dataloader = build_dataloader(test_dataset, **dataloader_setting) - - names, ckpts = [], [] - - if test['test_last']: - names.append('last') - ckpts.append(None) - if test['test_best']: - names.append('best') - ckpts.append(best_ckpt_path) - - for name, ckpt in zip(names, ckpts): - if ckpt is not None: - runner.load_checkpoint(ckpt) - - outputs = multi_gpu_test(runner.model, test_dataloader, tmpdir, - gpu_collect) - rank, _ = get_dist_info() - if rank == 0: - out = osp.join(cfg.work_dir, f'{name}_pred.pkl') - test_dataset.dump_results(outputs, out) - - eval_cfg = cfg.get('evaluation', {}) - for key in [ - 'interval', 'tmpdir', 'start', 'gpu_collect', - 'save_best', 'rule', 'by_epoch', 'broadcast_bn_buffers' - ]: - eval_cfg.pop(key, None) - - eval_res = test_dataset.evaluate(outputs, **eval_cfg) - runner.logger.info(f'Testing results of the {name} checkpoint') - for metric_name, val in eval_res.items(): - runner.logger.info(f'{metric_name}: {val:.04f}') +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import copy as cp +import os.path as osp + +from apex import amp + +import torch +from mmcv.parallel import MMDataParallel, MMDistributedDataParallel +from mmcv.runner import (DistSamplerSeedHook, EpochBasedRunner, OptimizerHook, + build_optimizer, get_dist_info) +from mmcv.runner.hooks import Fp16OptimizerHook + +from ..core import (DistEvalHook, EvalHook, OmniSourceDistSamplerSeedHook, + OmniSourceRunner) +from ..datasets import build_dataloader, build_dataset +from ..utils import PreciseBNHook, get_root_logger +from .test import multi_gpu_test + + +def train_model(model, + dataset, + cfg, + distributed=False, + validate=False, + test=dict(test_best=False, test_last=False), + timestamp=None, + meta=None): + """Train model entry function. + + Args: + model (nn.Module): The model to be trained. + dataset (:obj:`Dataset`): Train dataset. + cfg (dict): The config dict for training. + distributed (bool): Whether to use distributed training. + Default: False. + validate (bool): Whether to do evaluation. Default: False. + test (dict): The testing option, with two keys: test_last & test_best. + The value is True or False, indicating whether to test the + corresponding checkpoint. + Default: dict(test_best=False, test_last=False). + timestamp (str | None): Local time for runner. Default: None. + meta (dict | None): Meta dict to record some important information. + Default: None + """ + logger = get_root_logger(log_level=cfg.log_level) + + # prepare data loaders + dataset = dataset if isinstance(dataset, (list, tuple)) else [dataset] + + dataloader_setting = dict(videos_per_gpu=cfg.data.get('videos_per_gpu', 1), + workers_per_gpu=cfg.data.get( + 'workers_per_gpu', 1), + num_gpus=len(cfg.gpu_ids), + dist=distributed, + seed=cfg.seed) + dataloader_setting = dict(dataloader_setting, + **cfg.data.get('train_dataloader', {})) + + if cfg.omnisource: + # The option can override videos_per_gpu + train_ratio = cfg.data.get('train_ratio', [1] * len(dataset)) + omni_videos_per_gpu = cfg.data.get('omni_videos_per_gpu', None) + if omni_videos_per_gpu is None: + dataloader_settings = [dataloader_setting] * len(dataset) + else: + dataloader_settings = [] + for videos_per_gpu in omni_videos_per_gpu: + this_setting = cp.deepcopy(dataloader_setting) + this_setting['videos_per_gpu'] = videos_per_gpu + dataloader_settings.append(this_setting) + data_loaders = [ + build_dataloader(ds, **setting) + for ds, setting in zip(dataset, dataloader_settings) + ] + + else: + data_loaders = [ + build_dataloader(ds, **dataloader_setting) for ds in dataset + ] + + # build runner + optimizer = build_optimizer(model, cfg.optimizer) + + # Allow Amp to perform casts as required by the opt_level + if cfg.AMP: + # model, optimizer = amp.initialize(model.cuda(), + # optimizer, + # opt_level=cfg.OPT_LEVEL, + # loss_scale=cfg.LOSS_SCALE) + model, optimizer = amp.initialize(model.npu(), + optimizer, + opt_level=cfg.OPT_LEVEL, + loss_scale=cfg.LOSS_SCALE, + combine_grad=True) + + # put model on gpus + if distributed: + find_unused_parameters = cfg.get('find_unused_parameters', False) + # Sets the `find_unused_parameters` parameter in + # torch.nn.parallel.DistributedDataParallel + model = MMDistributedDataParallel( + model, + device_ids=[torch.npu.current_device()], + broadcast_buffers=False, + find_unused_parameters=find_unused_parameters) + # model = MMDistributedDataParallel( + # model, + # device_ids=[torch.cuda.current_device()], + # broadcast_buffers=False, + # find_unused_parameters=find_unused_parameters) + + else: + # In 1-p training, we don't use Dataparallel + # model = MMDataParallel(model.cuda(cfg.gpu_ids[0]), + # device_ids=cfg.gpu_ids) + model = model.npu() + + Runner = OmniSourceRunner if cfg.omnisource else EpochBasedRunner + runner = Runner(model, + optimizer=optimizer, + work_dir=cfg.work_dir, + logger=logger, + meta=meta, + distributed=distributed) + # an ugly workaround to make .log and .log.json filenames the same + runner.timestamp = timestamp + + # fp16 setting + fp16_cfg = cfg.get('fp16', None) + if fp16_cfg is not None: + optimizer_config = Fp16OptimizerHook(**cfg.optimizer_config, + **fp16_cfg, + distributed=distributed) + elif distributed and 'type' not in cfg.optimizer_config: + optimizer_config = OptimizerHook(**cfg.optimizer_config) + else: + optimizer_config = cfg.optimizer_config + + # register hooks + runner.register_training_hooks(cfg.lr_config, optimizer_config, + cfg.checkpoint_config, cfg.log_config, + cfg.get('momentum_config', None)) + if distributed: + if cfg.omnisource: + runner.register_hook(OmniSourceDistSamplerSeedHook()) + else: + runner.register_hook(DistSamplerSeedHook()) + + # precise bn setting + if cfg.get('precise_bn', False): + precise_bn_dataset = build_dataset(cfg.data.train) + dataloader_setting = dict( + videos_per_gpu=cfg.data.get('videos_per_gpu', 1), + workers_per_gpu=0, # save memory and time + num_gpus=len(cfg.gpu_ids), + dist=distributed, + seed=cfg.seed) + data_loader_precise_bn = build_dataloader(precise_bn_dataset, + **dataloader_setting) + precise_bn_hook = PreciseBNHook(data_loader_precise_bn, + **cfg.get('precise_bn')) + runner.register_hook(precise_bn_hook) + + if validate: + eval_cfg = cfg.get('evaluation', {}) + val_dataset = build_dataset(cfg.data.val, dict(test_mode=True)) + dataloader_setting = dict( + videos_per_gpu=cfg.data.get('videos_per_gpu', 1), + workers_per_gpu=cfg.data.get('workers_per_gpu', 1), + # cfg.gpus will be ignored if distributed + num_gpus=len(cfg.gpu_ids), + dist=distributed, + shuffle=False) + dataloader_setting = dict(dataloader_setting, + **cfg.data.get('val_dataloader', {})) + val_dataloader = build_dataloader(val_dataset, **dataloader_setting) + eval_hook = DistEvalHook(val_dataloader, **eval_cfg) if distributed \ + else EvalHook(val_dataloader, **eval_cfg) + runner.register_hook(eval_hook) + + if cfg.resume_from: + runner.resume(cfg.resume_from) + elif cfg.load_from: + runner.load_checkpoint(cfg.load_from) + runner_kwargs = dict() + if cfg.omnisource: + runner_kwargs = dict(train_ratio=train_ratio) + runner.run(data_loaders, cfg.workflow, cfg.total_epochs, **runner_kwargs) + + if test['test_last'] or test['test_best']: + best_ckpt_path = None + if test['test_best']: + if hasattr(eval_hook, 'best_ckpt_path'): + best_ckpt_path = eval_hook.best_ckpt_path + + if best_ckpt_path is None or not osp.exists(best_ckpt_path): + test['test_best'] = False + if best_ckpt_path is None: + runner.logger.info('Warning: test_best set as True, but ' + 'is not applicable ' + '(eval_hook.best_ckpt_path is None)') + else: + runner.logger.info('Warning: test_best set as True, but ' + 'is not applicable (best_ckpt ' + f'{best_ckpt_path} not found)') + if not test['test_last']: + return + + test_dataset = build_dataset(cfg.data.test, dict(test_mode=True)) + gpu_collect = cfg.get('evaluation', {}).get('gpu_collect', False) + tmpdir = cfg.get('evaluation', {}).get('tmpdir', + osp.join(cfg.work_dir, 'tmp')) + dataloader_setting = dict( + videos_per_gpu=cfg.data.get('videos_per_gpu', 1), + workers_per_gpu=cfg.data.get('workers_per_gpu', 1), + num_gpus=len(cfg.gpu_ids), + dist=distributed, + shuffle=False) + dataloader_setting = dict(dataloader_setting, + **cfg.data.get('test_dataloader', {})) + + test_dataloader = build_dataloader(test_dataset, **dataloader_setting) + + names, ckpts = [], [] + + if test['test_last']: + names.append('last') + ckpts.append(None) + if test['test_best']: + names.append('best') + ckpts.append(best_ckpt_path) + + for name, ckpt in zip(names, ckpts): + if ckpt is not None: + runner.load_checkpoint(ckpt) + + outputs = multi_gpu_test(runner.model, test_dataloader, tmpdir, + gpu_collect) + rank, _ = get_dist_info() + if rank == 0: + out = osp.join(cfg.work_dir, f'{name}_pred.pkl') + test_dataset.dump_results(outputs, out) + + eval_cfg = cfg.get('evaluation', {}) + for key in [ + 'interval', 'tmpdir', 'start', 'gpu_collect', + 'save_best', 'rule', 'by_epoch', 'broadcast_bn_buffers' + ]: + eval_cfg.pop(key, None) + + eval_res = test_dataset.evaluate(outputs, **eval_cfg) + runner.logger.info(f'Testing results of the {name} checkpoint') + for metric_name, val in eval_res.items(): + runner.logger.info(f'{metric_name}: {val:.04f}') diff --git a/PyTorch/contrib/cv/video/SlowFast/mmaction/datasets/pipelines/formating.py b/PyTorch/contrib/cv/video/SlowFast/mmaction/datasets/pipelines/formating.py index a7d0876a040cc435060f9056c6343fc0fd9f7b3c..3811c61addc5060784cf69acc2613b9b33567ea9 100644 --- a/PyTorch/contrib/cv/video/SlowFast/mmaction/datasets/pipelines/formating.py +++ b/PyTorch/contrib/cv/video/SlowFast/mmaction/datasets/pipelines/formating.py @@ -1,378 +1,378 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -from collections.abc import Sequence - -import mmcv -import numpy as np -import torch -from mmcv.parallel import DataContainer as DC - -from ..builder import PIPELINES - - -def to_tensor(data): - """Convert objects of various python types to :obj:`torch.Tensor`. - - Supported types are: :class:`numpy.ndarray`, :class:`torch.Tensor`, - :class:`Sequence`, :class:`int` and :class:`float`. - """ - if isinstance(data, torch.Tensor): - return data - if isinstance(data, np.ndarray): - return torch.from_numpy(data) - if isinstance(data, Sequence) and not mmcv.is_str(data): - return torch.tensor(data) - if isinstance(data, int): - return torch.LongTensor([data]) - if isinstance(data, float): - return torch.FloatTensor([data]) - raise TypeError(f'type {type(data)} cannot be converted to tensor.') - - -@PIPELINES.register_module() -class ToTensor: - """Convert some values in results dict to `torch.Tensor` type in data - loader pipeline. - - Args: - keys (Sequence[str]): Required keys to be converted. - """ - def __init__(self, keys): - self.keys = keys - - def __call__(self, results): - """Performs the ToTensor formating. - - Args: - results (dict): The resulting dict to be modified and passed - to the next transform in pipeline. - """ - for key in self.keys: - results[key] = to_tensor(results[key]) - return results - - def __repr__(self): - return f'{self.__class__.__name__}(keys={self.keys})' - - -@PIPELINES.register_module() -class Rename: - """Rename the key in results. - - Args: - mapping (dict): The keys in results that need to be renamed. The key of - the dict is the original name, while the value is the new name. If - the original name not found in results, do nothing. - Default: dict(). - """ - def __init__(self, mapping): - self.mapping = mapping - - def __call__(self, results): - for key, value in self.mapping.items(): - if key in results: - assert isinstance(key, str) and isinstance(value, str) - assert value not in results, ('the new name already exists in ' - 'results') - results[value] = results[key] - results.pop(key) - return results - - -@PIPELINES.register_module() -class ToDataContainer: - """Convert the data to DataContainer. - - Args: - fields (Sequence[dict]): Required fields to be converted - with keys and attributes. E.g. - fields=(dict(key='gt_bbox', stack=False),). - Note that key can also be a list of keys, if so, every tensor in - the list will be converted to DataContainer. - """ - def __init__(self, fields): - self.fields = fields - - def __call__(self, results): - """Performs the ToDataContainer formating. - - Args: - results (dict): The resulting dict to be modified and passed - to the next transform in pipeline. - """ - for field in self.fields: - _field = field.copy() - key = _field.pop('key') - if isinstance(key, list): - for item in key: - results[item] = DC(results[item], **_field) - else: - results[key] = DC(results[key], **_field) - return results - - def __repr__(self): - return self.__class__.__name__ + f'(fields={self.fields})' - - -@PIPELINES.register_module() -class ImageToTensor: - """Convert image type to `torch.Tensor` type. - - Args: - keys (Sequence[str]): Required keys to be converted. - """ - def __init__(self, keys): - self.keys = keys - - def __call__(self, results): - """Performs the ImageToTensor formating. - - Args: - results (dict): The resulting dict to be modified and passed - to the next transform in pipeline. - """ - for key in self.keys: - results[key] = to_tensor(results[key].transpose(2, 0, 1)) - return results - - def __repr__(self): - return f'{self.__class__.__name__}(keys={self.keys})' - - -@PIPELINES.register_module() -class Transpose: - """Transpose image channels to a given order. - - Args: - keys (Sequence[str]): Required keys to be converted. - order (Sequence[int]): Image channel order. - """ - def __init__(self, keys, order): - self.keys = keys - self.order = order - - def __call__(self, results): - """Performs the Transpose formatting. - - Args: - results (dict): The resulting dict to be modified and passed - to the next transform in pipeline. - """ - for key in self.keys: - results[key] = results[key].transpose(self.order) - return results - - def __repr__(self): - return (f'{self.__class__.__name__}(' - f'keys={self.keys}, order={self.order})') - - -@PIPELINES.register_module() -class Collect: - """Collect data from the loader relevant to the specific task. - - This keeps the items in ``keys`` as it is, and collect items in - ``meta_keys`` into a meta item called ``meta_name``.This is usually - the last stage of the data loader pipeline. - For example, when keys='imgs', meta_keys=('filename', 'label', - 'original_shape'), meta_name='img_metas', the results will be a dict with - keys 'imgs' and 'img_metas', where 'img_metas' is a DataContainer of - another dict with keys 'filename', 'label', 'original_shape'. - - Args: - keys (Sequence[str]): Required keys to be collected. - meta_name (str): The name of the key that contains meta infomation. - This key is always populated. Default: "img_metas". - meta_keys (Sequence[str]): Keys that are collected under meta_name. - The contents of the ``meta_name`` dictionary depends on - ``meta_keys``. - By default this includes: - - - "filename": path to the image file - - "label": label of the image file - - "original_shape": original shape of the image as a tuple - (h, w, c) - - "img_shape": shape of the image input to the network as a tuple - (h, w, c). Note that images may be zero padded on the - bottom/right, if the batch tensor is larger than this shape. - - "pad_shape": image shape after padding - - "flip_direction": a str in ("horiziontal", "vertival") to - indicate if the image is fliped horizontally or vertically. - - "img_norm_cfg": a dict of normalization information: - - mean - per channel mean subtraction - - std - per channel std divisor - - to_rgb - bool indicating if bgr was converted to rgb - nested (bool): If set as True, will apply data[x] = [data[x]] to all - items in data. The arg is added for compatibility. Default: False. - """ - def __init__(self, - keys, - meta_keys=('filename', 'label', 'original_shape', 'img_shape', - 'pad_shape', 'flip_direction', 'img_norm_cfg'), - meta_name='img_metas', - nested=False): - self.keys = keys - self.meta_keys = meta_keys - self.meta_name = meta_name - self.nested = nested - - def __call__(self, results): - """Performs the Collect formating. - - Args: - results (dict): The resulting dict to be modified and passed - to the next transform in pipeline. - """ - data = {} - for key in self.keys: - data[key] = results[key] - - if len(self.meta_keys) != 0: - meta = {} - for key in self.meta_keys: - meta[key] = results[key] - data[self.meta_name] = DC(meta, cpu_only=True) - if self.nested: - for k in data: - data[k] = [data[k]] - - return data - - def __repr__(self): - return (f'{self.__class__.__name__}(' - f'keys={self.keys}, meta_keys={self.meta_keys}, ' - f'nested={self.nested})') - - -@PIPELINES.register_module() -class FormatShape: - """Format final imgs shape to the given input_format. - - Required keys are "imgs", "num_clips" and "clip_len", added or modified - keys are "imgs" and "input_shape". - - Args: - input_format (str): Define the final imgs format. - collapse (bool): To collpase input_format N... to ... (NCTHW to CTHW, - etc.) if N is 1. Should be set as True when training and testing - detectors. Default: False. - """ - def __init__(self, input_format, collapse=False): - self.input_format = input_format - self.collapse = collapse - if self.input_format not in ['NCTHW', 'NCHW', 'NCHW_Flow', 'NPTCHW']: - raise ValueError( - f'The input format {self.input_format} is invalid.') - - def __call__(self, results): - """Performs the FormatShape formating. - - Args: - results (dict): The resulting dict to be modified and passed - to the next transform in pipeline. - """ - if not isinstance(results['imgs'], np.ndarray): - results['imgs'] = np.array(results['imgs']) - imgs = results['imgs'] - # [M x H x W x C] - # M = 1 * N_crops * N_clips * L - if self.collapse: - assert results['num_clips'] == 1 - - if self.input_format == 'NCTHW': - num_clips = results['num_clips'] - clip_len = results['clip_len'] - - imgs = imgs.reshape((-1, num_clips, clip_len) + imgs.shape[1:]) - # N_crops x N_clips x L x H x W x C - imgs = np.transpose(imgs, (0, 1, 5, 2, 3, 4)) - # N_crops x N_clips x C x L x H x W - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - # M' x C x L x H x W - # M' = N_crops x N_clips - elif self.input_format == 'NCHW': - imgs = np.transpose(imgs, (0, 3, 1, 2)) - # M x C x H x W - elif self.input_format == 'NCHW_Flow': - num_clips = results['num_clips'] - clip_len = results['clip_len'] - imgs = imgs.reshape((-1, num_clips, clip_len) + imgs.shape[1:]) - # N_crops x N_clips x L x H x W x C - imgs = np.transpose(imgs, (0, 1, 2, 5, 3, 4)) - # N_crops x N_clips x L x C x H x W - imgs = imgs.reshape((-1, imgs.shape[2] * imgs.shape[3]) + - imgs.shape[4:]) - # M' x C' x H x W - # M' = N_crops x N_clips - # C' = L x C - elif self.input_format == 'NPTCHW': - num_proposals = results['num_proposals'] - num_clips = results['num_clips'] - clip_len = results['clip_len'] - imgs = imgs.reshape((num_proposals, num_clips * clip_len) + - imgs.shape[1:]) - # P x M x H x W x C - # M = N_clips x L - imgs = np.transpose(imgs, (0, 1, 4, 2, 3)) - # P x M x C x H x W - if self.collapse: - assert imgs.shape[0] == 1 - imgs = imgs.squeeze(0) - - results['imgs'] = imgs - results['input_shape'] = imgs.shape - return results - - def __repr__(self): - repr_str = self.__class__.__name__ - repr_str += f"(input_format='{self.input_format}')" - return repr_str - - -@PIPELINES.register_module() -class FormatAudioShape: - """Format final audio shape to the given input_format. - - Required keys are "imgs", "num_clips" and "clip_len", added or modified - keys are "imgs" and "input_shape". - - Args: - input_format (str): Define the final imgs format. - """ - def __init__(self, input_format): - self.input_format = input_format - if self.input_format not in ['NCTF']: - raise ValueError( - f'The input format {self.input_format} is invalid.') - - def __call__(self, results): - """Performs the FormatShape formatting. - - Args: - results (dict): The resulting dict to be modified and passed - to the next transform in pipeline. - """ - audios = results['audios'] - # clip x sample x freq -> clip x channel x sample x freq - clip, sample, freq = audios.shape - audios = audios.reshape(clip, 1, sample, freq) - results['audios'] = audios - results['input_shape'] = audios.shape - return results - - def __repr__(self): - repr_str = self.__class__.__name__ - repr_str += f"(input_format='{self.input_format}')" - return repr_str +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +from collections.abc import Sequence + +import mmcv +import numpy as np +import torch +from mmcv.parallel import DataContainer as DC + +from ..builder import PIPELINES + + +def to_tensor(data): + """Convert objects of various python types to :obj:`torch.Tensor`. + + Supported types are: :class:`numpy.ndarray`, :class:`torch.Tensor`, + :class:`Sequence`, :class:`int` and :class:`float`. + """ + if isinstance(data, torch.Tensor): + return data + if isinstance(data, np.ndarray): + return torch.from_numpy(data) + if isinstance(data, Sequence) and not mmcv.is_str(data): + return torch.tensor(data) + if isinstance(data, int): + return torch.LongTensor([data]) + if isinstance(data, float): + return torch.FloatTensor([data]) + raise TypeError(f'type {type(data)} cannot be converted to tensor.') + + +@PIPELINES.register_module() +class ToTensor: + """Convert some values in results dict to `torch.Tensor` type in data + loader pipeline. + + Args: + keys (Sequence[str]): Required keys to be converted. + """ + def __init__(self, keys): + self.keys = keys + + def __call__(self, results): + """Performs the ToTensor formating. + + Args: + results (dict): The resulting dict to be modified and passed + to the next transform in pipeline. + """ + for key in self.keys: + results[key] = to_tensor(results[key]) + return results + + def __repr__(self): + return f'{self.__class__.__name__}(keys={self.keys})' + + +@PIPELINES.register_module() +class Rename: + """Rename the key in results. + + Args: + mapping (dict): The keys in results that need to be renamed. The key of + the dict is the original name, while the value is the new name. If + the original name not found in results, do nothing. + Default: dict(). + """ + def __init__(self, mapping): + self.mapping = mapping + + def __call__(self, results): + for key, value in self.mapping.items(): + if key in results: + assert isinstance(key, str) and isinstance(value, str) + assert value not in results, ('the new name already exists in ' + 'results') + results[value] = results[key] + results.pop(key) + return results + + +@PIPELINES.register_module() +class ToDataContainer: + """Convert the data to DataContainer. + + Args: + fields (Sequence[dict]): Required fields to be converted + with keys and attributes. E.g. + fields=(dict(key='gt_bbox', stack=False),). + Note that key can also be a list of keys, if so, every tensor in + the list will be converted to DataContainer. + """ + def __init__(self, fields): + self.fields = fields + + def __call__(self, results): + """Performs the ToDataContainer formating. + + Args: + results (dict): The resulting dict to be modified and passed + to the next transform in pipeline. + """ + for field in self.fields: + _field = field.copy() + key = _field.pop('key') + if isinstance(key, list): + for item in key: + results[item] = DC(results[item], **_field) + else: + results[key] = DC(results[key], **_field) + return results + + def __repr__(self): + return self.__class__.__name__ + f'(fields={self.fields})' + + +@PIPELINES.register_module() +class ImageToTensor: + """Convert image type to `torch.Tensor` type. + + Args: + keys (Sequence[str]): Required keys to be converted. + """ + def __init__(self, keys): + self.keys = keys + + def __call__(self, results): + """Performs the ImageToTensor formating. + + Args: + results (dict): The resulting dict to be modified and passed + to the next transform in pipeline. + """ + for key in self.keys: + results[key] = to_tensor(results[key].transpose(2, 0, 1)) + return results + + def __repr__(self): + return f'{self.__class__.__name__}(keys={self.keys})' + + +@PIPELINES.register_module() +class Transpose: + """Transpose image channels to a given order. + + Args: + keys (Sequence[str]): Required keys to be converted. + order (Sequence[int]): Image channel order. + """ + def __init__(self, keys, order): + self.keys = keys + self.order = order + + def __call__(self, results): + """Performs the Transpose formatting. + + Args: + results (dict): The resulting dict to be modified and passed + to the next transform in pipeline. + """ + for key in self.keys: + results[key] = results[key].transpose(self.order) + return results + + def __repr__(self): + return (f'{self.__class__.__name__}(' + f'keys={self.keys}, order={self.order})') + + +@PIPELINES.register_module() +class Collect: + """Collect data from the loader relevant to the specific task. + + This keeps the items in ``keys`` as it is, and collect items in + ``meta_keys`` into a meta item called ``meta_name``.This is usually + the last stage of the data loader pipeline. + For example, when keys='imgs', meta_keys=('filename', 'label', + 'original_shape'), meta_name='img_metas', the results will be a dict with + keys 'imgs' and 'img_metas', where 'img_metas' is a DataContainer of + another dict with keys 'filename', 'label', 'original_shape'. + + Args: + keys (Sequence[str]): Required keys to be collected. + meta_name (str): The name of the key that contains meta infomation. + This key is always populated. Default: "img_metas". + meta_keys (Sequence[str]): Keys that are collected under meta_name. + The contents of the ``meta_name`` dictionary depends on + ``meta_keys``. + By default this includes: + + - "filename": path to the image file + - "label": label of the image file + - "original_shape": original shape of the image as a tuple + (h, w, c) + - "img_shape": shape of the image input to the network as a tuple + (h, w, c). Note that images may be zero padded on the + bottom/right, if the batch tensor is larger than this shape. + - "pad_shape": image shape after padding + - "flip_direction": a str in ("horiziontal", "vertival") to + indicate if the image is fliped horizontally or vertically. + - "img_norm_cfg": a dict of normalization information: + - mean - per channel mean subtraction + - std - per channel std divisor + - to_rgb - bool indicating if bgr was converted to rgb + nested (bool): If set as True, will apply data[x] = [data[x]] to all + items in data. The arg is added for compatibility. Default: False. + """ + def __init__(self, + keys, + meta_keys=('filename', 'label', 'original_shape', 'img_shape', + 'pad_shape', 'flip_direction', 'img_norm_cfg'), + meta_name='img_metas', + nested=False): + self.keys = keys + self.meta_keys = meta_keys + self.meta_name = meta_name + self.nested = nested + + def __call__(self, results): + """Performs the Collect formating. + + Args: + results (dict): The resulting dict to be modified and passed + to the next transform in pipeline. + """ + data = {} + for key in self.keys: + data[key] = results[key] + + if len(self.meta_keys) != 0: + meta = {} + for key in self.meta_keys: + meta[key] = results[key] + data[self.meta_name] = DC(meta, cpu_only=True) + if self.nested: + for k in data: + data[k] = [data[k]] + + return data + + def __repr__(self): + return (f'{self.__class__.__name__}(' + f'keys={self.keys}, meta_keys={self.meta_keys}, ' + f'nested={self.nested})') + + +@PIPELINES.register_module() +class FormatShape: + """Format final imgs shape to the given input_format. + + Required keys are "imgs", "num_clips" and "clip_len", added or modified + keys are "imgs" and "input_shape". + + Args: + input_format (str): Define the final imgs format. + collapse (bool): To collpase input_format N... to ... (NCTHW to CTHW, + etc.) if N is 1. Should be set as True when training and testing + detectors. Default: False. + """ + def __init__(self, input_format, collapse=False): + self.input_format = input_format + self.collapse = collapse + if self.input_format not in ['NCTHW', 'NCHW', 'NCHW_Flow', 'NPTCHW']: + raise ValueError( + f'The input format {self.input_format} is invalid.') + + def __call__(self, results): + """Performs the FormatShape formating. + + Args: + results (dict): The resulting dict to be modified and passed + to the next transform in pipeline. + """ + if not isinstance(results['imgs'], np.ndarray): + results['imgs'] = np.array(results['imgs']) + imgs = results['imgs'] + # [M x H x W x C] + # M = 1 * N_crops * N_clips * L + if self.collapse: + assert results['num_clips'] == 1 + + if self.input_format == 'NCTHW': + num_clips = results['num_clips'] + clip_len = results['clip_len'] + + imgs = imgs.reshape((-1, num_clips, clip_len) + imgs.shape[1:]) + # N_crops x N_clips x L x H x W x C + imgs = np.transpose(imgs, (0, 1, 5, 2, 3, 4)) + # N_crops x N_clips x C x L x H x W + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + # M' x C x L x H x W + # M' = N_crops x N_clips + elif self.input_format == 'NCHW': + imgs = np.transpose(imgs, (0, 3, 1, 2)) + # M x C x H x W + elif self.input_format == 'NCHW_Flow': + num_clips = results['num_clips'] + clip_len = results['clip_len'] + imgs = imgs.reshape((-1, num_clips, clip_len) + imgs.shape[1:]) + # N_crops x N_clips x L x H x W x C + imgs = np.transpose(imgs, (0, 1, 2, 5, 3, 4)) + # N_crops x N_clips x L x C x H x W + imgs = imgs.reshape((-1, imgs.shape[2] * imgs.shape[3]) + + imgs.shape[4:]) + # M' x C' x H x W + # M' = N_crops x N_clips + # C' = L x C + elif self.input_format == 'NPTCHW': + num_proposals = results['num_proposals'] + num_clips = results['num_clips'] + clip_len = results['clip_len'] + imgs = imgs.reshape((num_proposals, num_clips * clip_len) + + imgs.shape[1:]) + # P x M x H x W x C + # M = N_clips x L + imgs = np.transpose(imgs, (0, 1, 4, 2, 3)) + # P x M x C x H x W + if self.collapse: + assert imgs.shape[0] == 1 + imgs = imgs.squeeze(0) + + results['imgs'] = imgs + results['input_shape'] = imgs.shape + return results + + def __repr__(self): + repr_str = self.__class__.__name__ + repr_str += f"(input_format='{self.input_format}')" + return repr_str + + +@PIPELINES.register_module() +class FormatAudioShape: + """Format final audio shape to the given input_format. + + Required keys are "imgs", "num_clips" and "clip_len", added or modified + keys are "imgs" and "input_shape". + + Args: + input_format (str): Define the final imgs format. + """ + def __init__(self, input_format): + self.input_format = input_format + if self.input_format not in ['NCTF']: + raise ValueError( + f'The input format {self.input_format} is invalid.') + + def __call__(self, results): + """Performs the FormatShape formatting. + + Args: + results (dict): The resulting dict to be modified and passed + to the next transform in pipeline. + """ + audios = results['audios'] + # clip x sample x freq -> clip x channel x sample x freq + clip, sample, freq = audios.shape + audios = audios.reshape(clip, 1, sample, freq) + results['audios'] = audios + results['input_shape'] = audios.shape + return results + + def __repr__(self): + repr_str = self.__class__.__name__ + repr_str += f"(input_format='{self.input_format}')" + return repr_str diff --git a/PyTorch/contrib/cv/video/SlowFast/mmaction/models/backbones/resnet3d_slowfast.py b/PyTorch/contrib/cv/video/SlowFast/mmaction/models/backbones/resnet3d_slowfast.py index a5d23bb38eddec07ec89262f4e7a446a17b429fa..e61842a2bab64177f4f1b83b30430833911ee16a 100644 --- a/PyTorch/contrib/cv/video/SlowFast/mmaction/models/backbones/resnet3d_slowfast.py +++ b/PyTorch/contrib/cv/video/SlowFast/mmaction/models/backbones/resnet3d_slowfast.py @@ -1,531 +1,531 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import warnings - -import torch -import torch.nn as nn -from mmcv.cnn import ConvModule, kaiming_init -from mmcv.runner import _load_checkpoint, load_checkpoint -from mmcv.utils import print_log - -from ...utils import get_root_logger -from ..builder import BACKBONES -from .resnet3d import ResNet3d - -mmdet_imported = False - - -class ResNet3dPathway(ResNet3d): - """A pathway of Slowfast based on ResNet3d. - - Args: - *args (arguments): Arguments same as :class:``ResNet3d``. - lateral (bool): Determines whether to enable the lateral connection - from another pathway. Default: False. - speed_ratio (int): Speed ratio indicating the ratio between time - dimension of the fast and slow pathway, corresponding to the - ``alpha`` in the paper. Default: 8. - channel_ratio (int): Reduce the channel number of fast pathway - by ``channel_ratio``, corresponding to ``beta`` in the paper. - Default: 8. - fusion_kernel (int): The kernel size of lateral fusion. - Default: 5. - **kwargs (keyword arguments): Keywords arguments for ResNet3d. - """ - def __init__(self, - *args, - lateral=False, - speed_ratio=8, - channel_ratio=8, - fusion_kernel=5, - **kwargs): - self.lateral = lateral - self.speed_ratio = speed_ratio - self.channel_ratio = channel_ratio - self.fusion_kernel = fusion_kernel - super().__init__(*args, **kwargs) - self.inplanes = self.base_channels - if self.lateral: - self.conv1_lateral = ConvModule( - self.inplanes // self.channel_ratio, - # https://arxiv.org/abs/1812.03982, the - # third type of lateral connection has out_channel: - # 2 * \beta * C - self.inplanes * 2 // self.channel_ratio, - kernel_size=(fusion_kernel, 1, 1), - stride=(self.speed_ratio, 1, 1), - padding=((fusion_kernel - 1) // 2, 0, 0), - bias=False, - conv_cfg=self.conv_cfg, - norm_cfg=self.norm_cfg, - act_cfg=None) - - self.lateral_connections = [] - for i in range(len(self.stage_blocks)): - planes = self.base_channels * 2**i - self.inplanes = planes * self.block.expansion - - if lateral and i != self.num_stages - 1: - # no lateral connection needed in final stage - lateral_name = f'layer{(i + 1)}_lateral' - setattr( - self, lateral_name, - ConvModule(self.inplanes // self.channel_ratio, - self.inplanes * 2 // self.channel_ratio, - kernel_size=(fusion_kernel, 1, 1), - stride=(self.speed_ratio, 1, 1), - padding=((fusion_kernel - 1) // 2, 0, 0), - bias=False, - conv_cfg=self.conv_cfg, - norm_cfg=self.norm_cfg, - act_cfg=None)) - self.lateral_connections.append(lateral_name) - - def make_res_layer(self, - block, - inplanes, - planes, - blocks, - spatial_stride=1, - temporal_stride=1, - dilation=1, - style='pytorch', - inflate=1, - inflate_style='3x1x1', - non_local=0, - non_local_cfg=dict(), - conv_cfg=None, - norm_cfg=None, - act_cfg=None, - with_cp=False): - """Build residual layer for Slowfast. - - Args: - block (nn.Module): Residual module to be built. - inplanes (int): Number of channels for the input - feature in each block. - planes (int): Number of channels for the output - feature in each block. - blocks (int): Number of residual blocks. - spatial_stride (int | Sequence[int]): Spatial strides - in residual and conv layers. Default: 1. - temporal_stride (int | Sequence[int]): Temporal strides in - residual and conv layers. Default: 1. - dilation (int): Spacing between kernel elements. Default: 1. - style (str): ``pytorch`` or ``caffe``. If set to ``pytorch``, - the stride-two layer is the 3x3 conv layer, - otherwise the stride-two layer is the first 1x1 conv layer. - Default: ``pytorch``. - inflate (int | Sequence[int]): Determine whether to inflate - for each block. Default: 1. - inflate_style (str): ``3x1x1`` or ``3x3x3``. which determines - the kernel sizes and padding strides for conv1 and - conv2 in each block. Default: ``3x1x1``. - non_local (int | Sequence[int]): Determine whether to apply - non-local module in the corresponding block of each stages. - Default: 0. - non_local_cfg (dict): Config for non-local module. - Default: ``dict()``. - conv_cfg (dict | None): Config for conv layers. Default: None. - norm_cfg (dict | None): Config for norm layers. Default: None. - act_cfg (dict | None): Config for activate layers. Default: None. - with_cp (bool): Use checkpoint or not. Using checkpoint will save - some memory while slowing down the training speed. - Default: False. - - Returns: - nn.Module: A residual layer for the given config. - """ - inflate = inflate if not isinstance(inflate, - int) else (inflate, ) * blocks - non_local = non_local if not isinstance( - non_local, int) else (non_local, ) * blocks - assert len(inflate) == blocks and len(non_local) == blocks - if self.lateral: - lateral_inplanes = inplanes * 2 // self.channel_ratio - else: - lateral_inplanes = 0 - if (spatial_stride != 1 - or (inplanes + lateral_inplanes) != planes * block.expansion): - downsample = ConvModule(inplanes + lateral_inplanes, - planes * block.expansion, - kernel_size=1, - stride=(temporal_stride, spatial_stride, - spatial_stride), - bias=False, - conv_cfg=conv_cfg, - norm_cfg=norm_cfg, - act_cfg=None) - else: - downsample = None - - layers = [] - layers.append( - block(inplanes + lateral_inplanes, - planes, - spatial_stride, - temporal_stride, - dilation, - downsample, - style=style, - inflate=(inflate[0] == 1), - inflate_style=inflate_style, - non_local=(non_local[0] == 1), - non_local_cfg=non_local_cfg, - conv_cfg=conv_cfg, - norm_cfg=norm_cfg, - act_cfg=act_cfg, - with_cp=with_cp)) - inplanes = planes * block.expansion - - for i in range(1, blocks): - layers.append( - block(inplanes, - planes, - 1, - 1, - dilation, - style=style, - inflate=(inflate[i] == 1), - inflate_style=inflate_style, - non_local=(non_local[i] == 1), - non_local_cfg=non_local_cfg, - conv_cfg=conv_cfg, - norm_cfg=norm_cfg, - act_cfg=act_cfg, - with_cp=with_cp)) - - return nn.Sequential(*layers) - - def inflate_weights(self, logger): - """Inflate the resnet2d parameters to resnet3d pathway. - - The differences between resnet3d and resnet2d mainly lie in an extra - axis of conv kernel. To utilize the pretrained parameters in 2d model, - the weight of conv2d models should be inflated to fit in the shapes of - the 3d counterpart. For pathway the ``lateral_connection`` part should - not be inflated from 2d weights. - - Args: - logger (logging.Logger): The logger used to print - debugging infomation. - """ - - state_dict_r2d = _load_checkpoint(self.pretrained) - if 'state_dict' in state_dict_r2d: - state_dict_r2d = state_dict_r2d['state_dict'] - - inflated_param_names = [] - for name, module in self.named_modules(): - if 'lateral' in name: - continue - if isinstance(module, ConvModule): - # we use a ConvModule to wrap conv+bn+relu layers, thus the - # name mapping is needed - if 'downsample' in name: - # layer{X}.{Y}.downsample.conv->layer{X}.{Y}.downsample.0 - original_conv_name = name + '.0' - # layer{X}.{Y}.downsample.bn->layer{X}.{Y}.downsample.1 - original_bn_name = name + '.1' - else: - # layer{X}.{Y}.conv{n}.conv->layer{X}.{Y}.conv{n} - original_conv_name = name - # layer{X}.{Y}.conv{n}.bn->layer{X}.{Y}.bn{n} - original_bn_name = name.replace('conv', 'bn') - if original_conv_name + '.weight' not in state_dict_r2d: - logger.warning(f'Module not exist in the state_dict_r2d' - f': {original_conv_name}') - else: - self._inflate_conv_params(module.conv, state_dict_r2d, - original_conv_name, - inflated_param_names) - if original_bn_name + '.weight' not in state_dict_r2d: - logger.warning(f'Module not exist in the state_dict_r2d' - f': {original_bn_name}') - else: - self._inflate_bn_params(module.bn, state_dict_r2d, - original_bn_name, - inflated_param_names) - - # check if any parameters in the 2d checkpoint are not loaded - remaining_names = set( - state_dict_r2d.keys()) - set(inflated_param_names) - if remaining_names: - logger.info(f'These parameters in the 2d checkpoint are not loaded' - f': {remaining_names}') - - def _inflate_conv_params(self, conv3d, state_dict_2d, module_name_2d, - inflated_param_names): - """Inflate a conv module from 2d to 3d. - - The differences of conv modules betweene 2d and 3d in Pathway - mainly lie in the inplanes due to lateral connections. To fit the - shapes of the lateral connection counterpart, it will expand - parameters by concatting conv2d parameters and extra zero paddings. - - Args: - conv3d (nn.Module): The destination conv3d module. - state_dict_2d (OrderedDict): The state dict of pretrained 2d model. - module_name_2d (str): The name of corresponding conv module in the - 2d model. - inflated_param_names (list[str]): List of parameters that have been - inflated. - """ - weight_2d_name = module_name_2d + '.weight' - conv2d_weight = state_dict_2d[weight_2d_name] - old_shape = conv2d_weight.shape - new_shape = conv3d.weight.data.shape - kernel_t = new_shape[2] - - if new_shape[1] != old_shape[1]: - if new_shape[1] < old_shape[1]: - warnings.warn(f'The parameter of {module_name_2d} is not' - 'loaded due to incompatible shapes. ') - return - # Inplanes may be different due to lateral connections - new_channels = new_shape[1] - old_shape[1] - pad_shape = old_shape - pad_shape = pad_shape[:1] + (new_channels, ) + pad_shape[2:] - # Expand parameters by concat extra channels - conv2d_weight = torch.cat( - (conv2d_weight, - torch.zeros(pad_shape).type_as(conv2d_weight).to( - conv2d_weight.device)), - dim=1) - - new_weight = conv2d_weight.data.unsqueeze(2).expand_as( - conv3d.weight) / kernel_t - conv3d.weight.data.copy_(new_weight) - inflated_param_names.append(weight_2d_name) - - if getattr(conv3d, 'bias') is not None: - bias_2d_name = module_name_2d + '.bias' - conv3d.bias.data.copy_(state_dict_2d[bias_2d_name]) - inflated_param_names.append(bias_2d_name) - - def _freeze_stages(self): - """Prevent all the parameters from being optimized before - `self.frozen_stages`.""" - if self.frozen_stages >= 0: - self.conv1.eval() - for param in self.conv1.parameters(): - param.requires_grad = False - - for i in range(1, self.frozen_stages + 1): - m = getattr(self, f'layer{i}') - m.eval() - for param in m.parameters(): - param.requires_grad = False - - if i != len(self.res_layers) and self.lateral: - # No fusion needed in the final stage - lateral_name = self.lateral_connections[i - 1] - conv_lateral = getattr(self, lateral_name) - conv_lateral.eval() - for param in conv_lateral.parameters(): - param.requires_grad = False - - def init_weights(self, pretrained=None): - """Initiate the parameters either from existing checkpoint or from - scratch.""" - if pretrained: - self.pretrained = pretrained - - # Override the init_weights of i3d - super().init_weights() - for module_name in self.lateral_connections: - layer = getattr(self, module_name) - for m in layer.modules(): - if isinstance(m, (nn.Conv3d, nn.Conv2d)): - kaiming_init(m) - - -pathway_cfg = { - 'resnet3d': ResNet3dPathway, - # TODO: BNInceptionPathway -} - - -def build_pathway(cfg, *args, **kwargs): - """Build pathway. - - Args: - cfg (None or dict): cfg should contain: - - type (str): identify conv layer type. - - Returns: - nn.Module: Created pathway. - """ - if not (isinstance(cfg, dict) and 'type' in cfg): - raise TypeError('cfg must be a dict containing the key "type"') - cfg_ = cfg.copy() - - pathway_type = cfg_.pop('type') - if pathway_type not in pathway_cfg: - raise KeyError(f'Unrecognized pathway type {pathway_type}') - - pathway_cls = pathway_cfg[pathway_type] - pathway = pathway_cls(*args, **kwargs, **cfg_) - - return pathway - - -@BACKBONES.register_module() -class ResNet3dSlowFast(nn.Module): - """Slowfast backbone. - - This module is proposed in `SlowFast Networks for Video Recognition - `_ - - Args: - pretrained (str): The file path to a pretrained model. - resample_rate (int): A large temporal stride ``resample_rate`` - on input frames. The actual resample rate is calculated by - multipling the ``interval`` in ``SampleFrames`` in the - pipeline with ``resample_rate``, equivalent to the :math:`\\tau` - in the paper, i.e. it processes only one out of - ``resample_rate * interval`` frames. Default: 8. - speed_ratio (int): Speed ratio indicating the ratio between time - dimension of the fast and slow pathway, corresponding to the - :math:`\\alpha` in the paper. Default: 8. - channel_ratio (int): Reduce the channel number of fast pathway - by ``channel_ratio``, corresponding to :math:`\\beta` in the paper. - Default: 8. - slow_pathway (dict): Configuration of slow branch, should contain - necessary arguments for building the specific type of pathway - and: - type (str): type of backbone the pathway bases on. - lateral (bool): determine whether to build lateral connection - for the pathway.Default: - - .. code-block:: Python - - dict(type='ResNetPathway', - lateral=True, depth=50, pretrained=None, - conv1_kernel=(1, 7, 7), dilations=(1, 1, 1, 1), - conv1_stride_t=1, pool1_stride_t=1, inflate=(0, 0, 1, 1)) - - fast_pathway (dict): Configuration of fast branch, similar to - `slow_pathway`. Default: - - .. code-block:: Python - - dict(type='ResNetPathway', - lateral=False, depth=50, pretrained=None, base_channels=8, - conv1_kernel=(5, 7, 7), conv1_stride_t=1, pool1_stride_t=1) - """ - def __init__(self, - pretrained, - resample_rate=8, - speed_ratio=8, - channel_ratio=8, - slow_pathway=dict(type='resnet3d', - depth=50, - pretrained=None, - lateral=True, - conv1_kernel=(1, 7, 7), - dilations=(1, 1, 1, 1), - conv1_stride_t=1, - pool1_stride_t=1, - inflate=(0, 0, 1, 1)), - fast_pathway=dict(type='resnet3d', - depth=50, - pretrained=None, - lateral=False, - base_channels=8, - conv1_kernel=(5, 7, 7), - conv1_stride_t=1, - pool1_stride_t=1)): - super().__init__() - self.pretrained = pretrained - self.resample_rate = resample_rate - self.speed_ratio = speed_ratio - self.channel_ratio = channel_ratio - - if slow_pathway['lateral']: - slow_pathway['speed_ratio'] = speed_ratio - slow_pathway['channel_ratio'] = channel_ratio - - self.slow_path = build_pathway(slow_pathway) - self.fast_path = build_pathway(fast_pathway) - - def init_weights(self, pretrained=None): - """Initiate the parameters either from existing checkpoint or from - scratch.""" - if pretrained: - self.pretrained = pretrained - - if isinstance(self.pretrained, str): - logger = get_root_logger() - msg = f'load model from: {self.pretrained}' - print_log(msg, logger=logger) - # Directly load 3D model. - load_checkpoint(self, self.pretrained, strict=True, logger=logger) - elif self.pretrained is None: - # Init two branch seperately. - self.fast_path.init_weights() - self.slow_path.init_weights() - else: - raise TypeError('pretrained must be a str or None') - - def forward(self, x): - """Defines the computation performed at every call. - - Args: - x (torch.Tensor): The input data. - - Returns: - tuple[torch.Tensor]: The feature of the input samples extracted - by the backbone. - """ - x_slow = nn.functional.interpolate( - x, - mode='nearest', - scale_factor=(1.0 / self.resample_rate, 1.0, 1.0)) - x_slow = self.slow_path.conv1(x_slow) - x_slow = self.slow_path.maxpool(x_slow) - - x_fast = nn.functional.interpolate( - x, - mode='nearest', - scale_factor=(1.0 / (self.resample_rate // self.speed_ratio), 1.0, - 1.0)) - x_fast = self.fast_path.conv1(x_fast) - x_fast = self.fast_path.maxpool(x_fast) - - if self.slow_path.lateral: - x_fast_lateral = self.slow_path.conv1_lateral(x_fast) - x_slow = torch.cat((x_slow, x_fast_lateral), dim=1) - - for i, layer_name in enumerate(self.slow_path.res_layers): - res_layer = getattr(self.slow_path, layer_name) - x_slow = res_layer(x_slow) - res_layer_fast = getattr(self.fast_path, layer_name) - x_fast = res_layer_fast(x_fast) - if (i != len(self.slow_path.res_layers) - 1 - and self.slow_path.lateral): - # No fusion needed in the final stage - lateral_name = self.slow_path.lateral_connections[i] - conv_lateral = getattr(self.slow_path, lateral_name) - x_fast_lateral = conv_lateral(x_fast) - x_slow = torch.cat((x_slow, x_fast_lateral), dim=1) - - out = (x_slow, x_fast) - - return out - - -if mmdet_imported: - MMDET_BACKBONES.register_module()(ResNet3dSlowFast) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import warnings + +import torch +import torch.nn as nn +from mmcv.cnn import ConvModule, kaiming_init +from mmcv.runner import _load_checkpoint, load_checkpoint +from mmcv.utils import print_log + +from ...utils import get_root_logger +from ..builder import BACKBONES +from .resnet3d import ResNet3d + +mmdet_imported = False + + +class ResNet3dPathway(ResNet3d): + """A pathway of Slowfast based on ResNet3d. + + Args: + *args (arguments): Arguments same as :class:``ResNet3d``. + lateral (bool): Determines whether to enable the lateral connection + from another pathway. Default: False. + speed_ratio (int): Speed ratio indicating the ratio between time + dimension of the fast and slow pathway, corresponding to the + ``alpha`` in the paper. Default: 8. + channel_ratio (int): Reduce the channel number of fast pathway + by ``channel_ratio``, corresponding to ``beta`` in the paper. + Default: 8. + fusion_kernel (int): The kernel size of lateral fusion. + Default: 5. + **kwargs (keyword arguments): Keywords arguments for ResNet3d. + """ + def __init__(self, + *args, + lateral=False, + speed_ratio=8, + channel_ratio=8, + fusion_kernel=5, + **kwargs): + self.lateral = lateral + self.speed_ratio = speed_ratio + self.channel_ratio = channel_ratio + self.fusion_kernel = fusion_kernel + super().__init__(*args, **kwargs) + self.inplanes = self.base_channels + if self.lateral: + self.conv1_lateral = ConvModule( + self.inplanes // self.channel_ratio, + # https://arxiv.org/abs/1812.03982, the + # third type of lateral connection has out_channel: + # 2 * \beta * C + self.inplanes * 2 // self.channel_ratio, + kernel_size=(fusion_kernel, 1, 1), + stride=(self.speed_ratio, 1, 1), + padding=((fusion_kernel - 1) // 2, 0, 0), + bias=False, + conv_cfg=self.conv_cfg, + norm_cfg=self.norm_cfg, + act_cfg=None) + + self.lateral_connections = [] + for i in range(len(self.stage_blocks)): + planes = self.base_channels * 2**i + self.inplanes = planes * self.block.expansion + + if lateral and i != self.num_stages - 1: + # no lateral connection needed in final stage + lateral_name = f'layer{(i + 1)}_lateral' + setattr( + self, lateral_name, + ConvModule(self.inplanes // self.channel_ratio, + self.inplanes * 2 // self.channel_ratio, + kernel_size=(fusion_kernel, 1, 1), + stride=(self.speed_ratio, 1, 1), + padding=((fusion_kernel - 1) // 2, 0, 0), + bias=False, + conv_cfg=self.conv_cfg, + norm_cfg=self.norm_cfg, + act_cfg=None)) + self.lateral_connections.append(lateral_name) + + def make_res_layer(self, + block, + inplanes, + planes, + blocks, + spatial_stride=1, + temporal_stride=1, + dilation=1, + style='pytorch', + inflate=1, + inflate_style='3x1x1', + non_local=0, + non_local_cfg=dict(), + conv_cfg=None, + norm_cfg=None, + act_cfg=None, + with_cp=False): + """Build residual layer for Slowfast. + + Args: + block (nn.Module): Residual module to be built. + inplanes (int): Number of channels for the input + feature in each block. + planes (int): Number of channels for the output + feature in each block. + blocks (int): Number of residual blocks. + spatial_stride (int | Sequence[int]): Spatial strides + in residual and conv layers. Default: 1. + temporal_stride (int | Sequence[int]): Temporal strides in + residual and conv layers. Default: 1. + dilation (int): Spacing between kernel elements. Default: 1. + style (str): ``pytorch`` or ``caffe``. If set to ``pytorch``, + the stride-two layer is the 3x3 conv layer, + otherwise the stride-two layer is the first 1x1 conv layer. + Default: ``pytorch``. + inflate (int | Sequence[int]): Determine whether to inflate + for each block. Default: 1. + inflate_style (str): ``3x1x1`` or ``3x3x3``. which determines + the kernel sizes and padding strides for conv1 and + conv2 in each block. Default: ``3x1x1``. + non_local (int | Sequence[int]): Determine whether to apply + non-local module in the corresponding block of each stages. + Default: 0. + non_local_cfg (dict): Config for non-local module. + Default: ``dict()``. + conv_cfg (dict | None): Config for conv layers. Default: None. + norm_cfg (dict | None): Config for norm layers. Default: None. + act_cfg (dict | None): Config for activate layers. Default: None. + with_cp (bool): Use checkpoint or not. Using checkpoint will save + some memory while slowing down the training speed. + Default: False. + + Returns: + nn.Module: A residual layer for the given config. + """ + inflate = inflate if not isinstance(inflate, + int) else (inflate, ) * blocks + non_local = non_local if not isinstance( + non_local, int) else (non_local, ) * blocks + assert len(inflate) == blocks and len(non_local) == blocks + if self.lateral: + lateral_inplanes = inplanes * 2 // self.channel_ratio + else: + lateral_inplanes = 0 + if (spatial_stride != 1 + or (inplanes + lateral_inplanes) != planes * block.expansion): + downsample = ConvModule(inplanes + lateral_inplanes, + planes * block.expansion, + kernel_size=1, + stride=(temporal_stride, spatial_stride, + spatial_stride), + bias=False, + conv_cfg=conv_cfg, + norm_cfg=norm_cfg, + act_cfg=None) + else: + downsample = None + + layers = [] + layers.append( + block(inplanes + lateral_inplanes, + planes, + spatial_stride, + temporal_stride, + dilation, + downsample, + style=style, + inflate=(inflate[0] == 1), + inflate_style=inflate_style, + non_local=(non_local[0] == 1), + non_local_cfg=non_local_cfg, + conv_cfg=conv_cfg, + norm_cfg=norm_cfg, + act_cfg=act_cfg, + with_cp=with_cp)) + inplanes = planes * block.expansion + + for i in range(1, blocks): + layers.append( + block(inplanes, + planes, + 1, + 1, + dilation, + style=style, + inflate=(inflate[i] == 1), + inflate_style=inflate_style, + non_local=(non_local[i] == 1), + non_local_cfg=non_local_cfg, + conv_cfg=conv_cfg, + norm_cfg=norm_cfg, + act_cfg=act_cfg, + with_cp=with_cp)) + + return nn.Sequential(*layers) + + def inflate_weights(self, logger): + """Inflate the resnet2d parameters to resnet3d pathway. + + The differences between resnet3d and resnet2d mainly lie in an extra + axis of conv kernel. To utilize the pretrained parameters in 2d model, + the weight of conv2d models should be inflated to fit in the shapes of + the 3d counterpart. For pathway the ``lateral_connection`` part should + not be inflated from 2d weights. + + Args: + logger (logging.Logger): The logger used to print + debugging infomation. + """ + + state_dict_r2d = _load_checkpoint(self.pretrained) + if 'state_dict' in state_dict_r2d: + state_dict_r2d = state_dict_r2d['state_dict'] + + inflated_param_names = [] + for name, module in self.named_modules(): + if 'lateral' in name: + continue + if isinstance(module, ConvModule): + # we use a ConvModule to wrap conv+bn+relu layers, thus the + # name mapping is needed + if 'downsample' in name: + # layer{X}.{Y}.downsample.conv->layer{X}.{Y}.downsample.0 + original_conv_name = name + '.0' + # layer{X}.{Y}.downsample.bn->layer{X}.{Y}.downsample.1 + original_bn_name = name + '.1' + else: + # layer{X}.{Y}.conv{n}.conv->layer{X}.{Y}.conv{n} + original_conv_name = name + # layer{X}.{Y}.conv{n}.bn->layer{X}.{Y}.bn{n} + original_bn_name = name.replace('conv', 'bn') + if original_conv_name + '.weight' not in state_dict_r2d: + logger.warning(f'Module not exist in the state_dict_r2d' + f': {original_conv_name}') + else: + self._inflate_conv_params(module.conv, state_dict_r2d, + original_conv_name, + inflated_param_names) + if original_bn_name + '.weight' not in state_dict_r2d: + logger.warning(f'Module not exist in the state_dict_r2d' + f': {original_bn_name}') + else: + self._inflate_bn_params(module.bn, state_dict_r2d, + original_bn_name, + inflated_param_names) + + # check if any parameters in the 2d checkpoint are not loaded + remaining_names = set( + state_dict_r2d.keys()) - set(inflated_param_names) + if remaining_names: + logger.info(f'These parameters in the 2d checkpoint are not loaded' + f': {remaining_names}') + + def _inflate_conv_params(self, conv3d, state_dict_2d, module_name_2d, + inflated_param_names): + """Inflate a conv module from 2d to 3d. + + The differences of conv modules betweene 2d and 3d in Pathway + mainly lie in the inplanes due to lateral connections. To fit the + shapes of the lateral connection counterpart, it will expand + parameters by concatting conv2d parameters and extra zero paddings. + + Args: + conv3d (nn.Module): The destination conv3d module. + state_dict_2d (OrderedDict): The state dict of pretrained 2d model. + module_name_2d (str): The name of corresponding conv module in the + 2d model. + inflated_param_names (list[str]): List of parameters that have been + inflated. + """ + weight_2d_name = module_name_2d + '.weight' + conv2d_weight = state_dict_2d[weight_2d_name] + old_shape = conv2d_weight.shape + new_shape = conv3d.weight.data.shape + kernel_t = new_shape[2] + + if new_shape[1] != old_shape[1]: + if new_shape[1] < old_shape[1]: + warnings.warn(f'The parameter of {module_name_2d} is not' + 'loaded due to incompatible shapes. ') + return + # Inplanes may be different due to lateral connections + new_channels = new_shape[1] - old_shape[1] + pad_shape = old_shape + pad_shape = pad_shape[:1] + (new_channels, ) + pad_shape[2:] + # Expand parameters by concat extra channels + conv2d_weight = torch.cat( + (conv2d_weight, + torch.zeros(pad_shape).type_as(conv2d_weight).to( + conv2d_weight.device)), + dim=1) + + new_weight = conv2d_weight.data.unsqueeze(2).expand_as( + conv3d.weight) / kernel_t + conv3d.weight.data.copy_(new_weight) + inflated_param_names.append(weight_2d_name) + + if getattr(conv3d, 'bias') is not None: + bias_2d_name = module_name_2d + '.bias' + conv3d.bias.data.copy_(state_dict_2d[bias_2d_name]) + inflated_param_names.append(bias_2d_name) + + def _freeze_stages(self): + """Prevent all the parameters from being optimized before + `self.frozen_stages`.""" + if self.frozen_stages >= 0: + self.conv1.eval() + for param in self.conv1.parameters(): + param.requires_grad = False + + for i in range(1, self.frozen_stages + 1): + m = getattr(self, f'layer{i}') + m.eval() + for param in m.parameters(): + param.requires_grad = False + + if i != len(self.res_layers) and self.lateral: + # No fusion needed in the final stage + lateral_name = self.lateral_connections[i - 1] + conv_lateral = getattr(self, lateral_name) + conv_lateral.eval() + for param in conv_lateral.parameters(): + param.requires_grad = False + + def init_weights(self, pretrained=None): + """Initiate the parameters either from existing checkpoint or from + scratch.""" + if pretrained: + self.pretrained = pretrained + + # Override the init_weights of i3d + super().init_weights() + for module_name in self.lateral_connections: + layer = getattr(self, module_name) + for m in layer.modules(): + if isinstance(m, (nn.Conv3d, nn.Conv2d)): + kaiming_init(m) + + +pathway_cfg = { + 'resnet3d': ResNet3dPathway, + # TODO: BNInceptionPathway +} + + +def build_pathway(cfg, *args, **kwargs): + """Build pathway. + + Args: + cfg (None or dict): cfg should contain: + - type (str): identify conv layer type. + + Returns: + nn.Module: Created pathway. + """ + if not (isinstance(cfg, dict) and 'type' in cfg): + raise TypeError('cfg must be a dict containing the key "type"') + cfg_ = cfg.copy() + + pathway_type = cfg_.pop('type') + if pathway_type not in pathway_cfg: + raise KeyError(f'Unrecognized pathway type {pathway_type}') + + pathway_cls = pathway_cfg[pathway_type] + pathway = pathway_cls(*args, **kwargs, **cfg_) + + return pathway + + +@BACKBONES.register_module() +class ResNet3dSlowFast(nn.Module): + """Slowfast backbone. + + This module is proposed in `SlowFast Networks for Video Recognition + `_ + + Args: + pretrained (str): The file path to a pretrained model. + resample_rate (int): A large temporal stride ``resample_rate`` + on input frames. The actual resample rate is calculated by + multipling the ``interval`` in ``SampleFrames`` in the + pipeline with ``resample_rate``, equivalent to the :math:`\\tau` + in the paper, i.e. it processes only one out of + ``resample_rate * interval`` frames. Default: 8. + speed_ratio (int): Speed ratio indicating the ratio between time + dimension of the fast and slow pathway, corresponding to the + :math:`\\alpha` in the paper. Default: 8. + channel_ratio (int): Reduce the channel number of fast pathway + by ``channel_ratio``, corresponding to :math:`\\beta` in the paper. + Default: 8. + slow_pathway (dict): Configuration of slow branch, should contain + necessary arguments for building the specific type of pathway + and: + type (str): type of backbone the pathway bases on. + lateral (bool): determine whether to build lateral connection + for the pathway.Default: + + .. code-block:: Python + + dict(type='ResNetPathway', + lateral=True, depth=50, pretrained=None, + conv1_kernel=(1, 7, 7), dilations=(1, 1, 1, 1), + conv1_stride_t=1, pool1_stride_t=1, inflate=(0, 0, 1, 1)) + + fast_pathway (dict): Configuration of fast branch, similar to + `slow_pathway`. Default: + + .. code-block:: Python + + dict(type='ResNetPathway', + lateral=False, depth=50, pretrained=None, base_channels=8, + conv1_kernel=(5, 7, 7), conv1_stride_t=1, pool1_stride_t=1) + """ + def __init__(self, + pretrained, + resample_rate=8, + speed_ratio=8, + channel_ratio=8, + slow_pathway=dict(type='resnet3d', + depth=50, + pretrained=None, + lateral=True, + conv1_kernel=(1, 7, 7), + dilations=(1, 1, 1, 1), + conv1_stride_t=1, + pool1_stride_t=1, + inflate=(0, 0, 1, 1)), + fast_pathway=dict(type='resnet3d', + depth=50, + pretrained=None, + lateral=False, + base_channels=8, + conv1_kernel=(5, 7, 7), + conv1_stride_t=1, + pool1_stride_t=1)): + super().__init__() + self.pretrained = pretrained + self.resample_rate = resample_rate + self.speed_ratio = speed_ratio + self.channel_ratio = channel_ratio + + if slow_pathway['lateral']: + slow_pathway['speed_ratio'] = speed_ratio + slow_pathway['channel_ratio'] = channel_ratio + + self.slow_path = build_pathway(slow_pathway) + self.fast_path = build_pathway(fast_pathway) + + def init_weights(self, pretrained=None): + """Initiate the parameters either from existing checkpoint or from + scratch.""" + if pretrained: + self.pretrained = pretrained + + if isinstance(self.pretrained, str): + logger = get_root_logger() + msg = f'load model from: {self.pretrained}' + print_log(msg, logger=logger) + # Directly load 3D model. + load_checkpoint(self, self.pretrained, strict=True, logger=logger) + elif self.pretrained is None: + # Init two branch seperately. + self.fast_path.init_weights() + self.slow_path.init_weights() + else: + raise TypeError('pretrained must be a str or None') + + def forward(self, x): + """Defines the computation performed at every call. + + Args: + x (torch.Tensor): The input data. + + Returns: + tuple[torch.Tensor]: The feature of the input samples extracted + by the backbone. + """ + x_slow = nn.functional.interpolate( + x, + mode='nearest', + scale_factor=(1.0 / self.resample_rate, 1.0, 1.0)) + x_slow = self.slow_path.conv1(x_slow) + x_slow = self.slow_path.maxpool(x_slow) + + x_fast = nn.functional.interpolate( + x, + mode='nearest', + scale_factor=(1.0 / (self.resample_rate // self.speed_ratio), 1.0, + 1.0)) + x_fast = self.fast_path.conv1(x_fast) + x_fast = self.fast_path.maxpool(x_fast) + + if self.slow_path.lateral: + x_fast_lateral = self.slow_path.conv1_lateral(x_fast) + x_slow = torch.cat((x_slow, x_fast_lateral), dim=1) + + for i, layer_name in enumerate(self.slow_path.res_layers): + res_layer = getattr(self.slow_path, layer_name) + x_slow = res_layer(x_slow) + res_layer_fast = getattr(self.fast_path, layer_name) + x_fast = res_layer_fast(x_fast) + if (i != len(self.slow_path.res_layers) - 1 + and self.slow_path.lateral): + # No fusion needed in the final stage + lateral_name = self.slow_path.lateral_connections[i] + conv_lateral = getattr(self.slow_path, lateral_name) + x_fast_lateral = conv_lateral(x_fast) + x_slow = torch.cat((x_slow, x_fast_lateral), dim=1) + + out = (x_slow, x_fast) + + return out + + +if mmdet_imported: + MMDET_BACKBONES.register_module()(ResNet3dSlowFast) diff --git a/PyTorch/contrib/cv/video/SlowFast/mmaction/models/heads/base.py b/PyTorch/contrib/cv/video/SlowFast/mmaction/models/heads/base.py index 8d165096e1f96749bdab7f9b31f07ce000794d94..6343b3dd0f60cf7183183ff14f024b143a0bf138 100644 --- a/PyTorch/contrib/cv/video/SlowFast/mmaction/models/heads/base.py +++ b/PyTorch/contrib/cv/video/SlowFast/mmaction/models/heads/base.py @@ -1,122 +1,122 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -from abc import ABCMeta, abstractmethod - -import torch -import torch.nn as nn - -from ...core import top_k_accuracy -from ..builder import build_loss - - -class AvgConsensus(nn.Module): - """Average consensus module. - - Args: - dim (int): Decide which dim consensus function to apply. - Default: 1. - """ - def __init__(self, dim=1): - super().__init__() - self.dim = dim - - def forward(self, x): - """Defines the computation performed at every call.""" - return x.mean(dim=self.dim, keepdim=True) - - -class BaseHead(nn.Module, metaclass=ABCMeta): - """Base class for head. - - All Head should subclass it. - All subclass should overwrite: - - Methods:``init_weights``, initializing weights in some modules. - - Methods:``forward``, supporting to forward both for training and testing. - - Args: - num_classes (int): Number of classes to be classified. - in_channels (int): Number of channels in input feature. - loss_cls (dict): Config for building loss. - Default: dict(type='CrossEntropyLoss', loss_weight=1.0). - multi_class (bool): Determines whether it is a multi-class - recognition task. Default: False. - label_smooth_eps (float): Epsilon used in label smooth. - Reference: arxiv.org/abs/1906.02629. Default: 0. - """ - def __init__(self, - num_classes, - in_channels, - loss_cls=dict(type='CrossEntropyLoss', loss_weight=1.0), - multi_class=False, - label_smooth_eps=0.0): - super().__init__() - self.num_classes = num_classes - self.in_channels = in_channels - self.loss_cls = build_loss(loss_cls) - self.multi_class = multi_class - self.label_smooth_eps = label_smooth_eps - - @abstractmethod - def init_weights(self): - """Initiate the parameters either from existing checkpoint or from - scratch.""" - - @abstractmethod - def forward(self, x): - """Defines the computation performed at every call.""" - - def loss(self, cls_score, labels, **kwargs): - """Calculate the loss given output ``cls_score``, target ``labels``. - - Args: - cls_score (torch.Tensor): The output of the model. - labels (torch.Tensor): The target output of the model. - - Returns: - dict: A dict containing field 'loss_cls'(mandatory) - and 'top1_acc', 'top5_acc'(optional). - """ - losses = dict() - if labels.shape == torch.Size([]): - labels = labels.unsqueeze(0) - elif labels.dim() == 1 and labels.size()[0] == self.num_classes \ - and cls_score.size()[0] == 1: - # Fix a bug when training with soft labels and batch size is 1. - # When using soft labels, `labels` and `cls_socre` share the same - # shape. - labels = labels.unsqueeze(0) - - if not self.multi_class and cls_score.size() != labels.size(): - top_k_acc = top_k_accuracy(cls_score.detach().cpu().numpy(), - labels.detach().cpu().numpy(), (1, 5)) - losses['top1_acc'] = torch.tensor(top_k_acc[0], - device=cls_score.device, - dtype=torch.float32) - losses['top5_acc'] = torch.tensor(top_k_acc[1], - device=cls_score.device, - dtype=torch.float32) - - elif self.multi_class and self.label_smooth_eps != 0: - labels = ((1 - self.label_smooth_eps) * labels + - self.label_smooth_eps / self.num_classes) - - loss_cls = self.loss_cls(cls_score, labels, **kwargs) - # loss_cls may be dictionary or single tensor - if isinstance(loss_cls, dict): - losses.update(loss_cls) - else: - losses['loss_cls'] = loss_cls - - return losses +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +from abc import ABCMeta, abstractmethod + +import torch +import torch.nn as nn + +from ...core import top_k_accuracy +from ..builder import build_loss + + +class AvgConsensus(nn.Module): + """Average consensus module. + + Args: + dim (int): Decide which dim consensus function to apply. + Default: 1. + """ + def __init__(self, dim=1): + super().__init__() + self.dim = dim + + def forward(self, x): + """Defines the computation performed at every call.""" + return x.mean(dim=self.dim, keepdim=True) + + +class BaseHead(nn.Module, metaclass=ABCMeta): + """Base class for head. + + All Head should subclass it. + All subclass should overwrite: + - Methods:``init_weights``, initializing weights in some modules. + - Methods:``forward``, supporting to forward both for training and testing. + + Args: + num_classes (int): Number of classes to be classified. + in_channels (int): Number of channels in input feature. + loss_cls (dict): Config for building loss. + Default: dict(type='CrossEntropyLoss', loss_weight=1.0). + multi_class (bool): Determines whether it is a multi-class + recognition task. Default: False. + label_smooth_eps (float): Epsilon used in label smooth. + Reference: arxiv.org/abs/1906.02629. Default: 0. + """ + def __init__(self, + num_classes, + in_channels, + loss_cls=dict(type='CrossEntropyLoss', loss_weight=1.0), + multi_class=False, + label_smooth_eps=0.0): + super().__init__() + self.num_classes = num_classes + self.in_channels = in_channels + self.loss_cls = build_loss(loss_cls) + self.multi_class = multi_class + self.label_smooth_eps = label_smooth_eps + + @abstractmethod + def init_weights(self): + """Initiate the parameters either from existing checkpoint or from + scratch.""" + + @abstractmethod + def forward(self, x): + """Defines the computation performed at every call.""" + + def loss(self, cls_score, labels, **kwargs): + """Calculate the loss given output ``cls_score``, target ``labels``. + + Args: + cls_score (torch.Tensor): The output of the model. + labels (torch.Tensor): The target output of the model. + + Returns: + dict: A dict containing field 'loss_cls'(mandatory) + and 'top1_acc', 'top5_acc'(optional). + """ + losses = dict() + if labels.shape == torch.Size([]): + labels = labels.unsqueeze(0) + elif labels.dim() == 1 and labels.size()[0] == self.num_classes \ + and cls_score.size()[0] == 1: + # Fix a bug when training with soft labels and batch size is 1. + # When using soft labels, `labels` and `cls_socre` share the same + # shape. + labels = labels.unsqueeze(0) + + if not self.multi_class and cls_score.size() != labels.size(): + top_k_acc = top_k_accuracy(cls_score.detach().cpu().numpy(), + labels.detach().cpu().numpy(), (1, 5)) + losses['top1_acc'] = torch.tensor(top_k_acc[0], + device=cls_score.device, + dtype=torch.float32) + losses['top5_acc'] = torch.tensor(top_k_acc[1], + device=cls_score.device, + dtype=torch.float32) + + elif self.multi_class and self.label_smooth_eps != 0: + labels = ((1 - self.label_smooth_eps) * labels + + self.label_smooth_eps / self.num_classes) + + loss_cls = self.loss_cls(cls_score, labels, **kwargs) + # loss_cls may be dictionary or single tensor + if isinstance(loss_cls, dict): + losses.update(loss_cls) + else: + losses['loss_cls'] = loss_cls + + return losses diff --git a/PyTorch/contrib/cv/video/SlowFast/mmaction/models/heads/slowfast_head.py b/PyTorch/contrib/cv/video/SlowFast/mmaction/models/heads/slowfast_head.py index 30c3590fa96398b7282c3c47415a31e5e4b7c858..31de953e262024feb99fab0e3809fc96d2791d6a 100644 --- a/PyTorch/contrib/cv/video/SlowFast/mmaction/models/heads/slowfast_head.py +++ b/PyTorch/contrib/cv/video/SlowFast/mmaction/models/heads/slowfast_head.py @@ -1,92 +1,92 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch -import torch.nn as nn -from mmcv.cnn import normal_init - -from ..builder import HEADS -from .base import BaseHead - - -@HEADS.register_module() -class SlowFastHead(BaseHead): - """The classification head for SlowFast. - - Args: - num_classes (int): Number of classes to be classified. - in_channels (int): Number of channels in input feature. - loss_cls (dict): Config for building loss. - Default: dict(type='CrossEntropyLoss'). - spatial_type (str): Pooling type in spatial dimension. Default: 'avg'. - dropout_ratio (float): Probability of dropout layer. Default: 0.8. - init_std (float): Std value for Initiation. Default: 0.01. - kwargs (dict, optional): Any keyword argument to be used to initialize - the head. - """ - def __init__(self, - num_classes, - in_channels, - loss_cls=dict(type='CrossEntropyLoss'), - spatial_type='avg', - dropout_ratio=0.8, - init_std=0.01, - **kwargs): - - super().__init__(num_classes, in_channels, loss_cls, **kwargs) - self.spatial_type = spatial_type - self.dropout_ratio = dropout_ratio - self.init_std = init_std - - if self.dropout_ratio != 0: - self.dropout = nn.Dropout(p=self.dropout_ratio) - else: - self.dropout = None - self.fc_cls = nn.Linear(in_channels, num_classes) - - if self.spatial_type == 'avg': - self.avg_pool = nn.AdaptiveAvgPool3d((1, 1, 1)) - else: - self.avg_pool = None - - def init_weights(self): - """Initiate the parameters from scratch.""" - normal_init(self.fc_cls, std=self.init_std) - - def forward(self, x): - """Defines the computation performed at every call. - - Args: - x (torch.Tensor): The input data. - - Returns: - torch.Tensor: The classification scores for input samples. - """ - # ([N, channel_fast, T, H, W], [(N, channel_slow, T, H, W)]) - x_fast, x_slow = x - # ([N, channel_fast, 1, 1, 1], [N, channel_slow, 1, 1, 1]) - x_fast = self.avg_pool(x_fast) - x_slow = self.avg_pool(x_slow) - # [N, channel_fast + channel_slow, 1, 1, 1] - x = torch.cat((x_slow, x_fast), dim=1) - - if self.dropout is not None: - x = self.dropout(x) - - # [N x C] - x = x.view(x.size(0), -1) - # [N x num_classes] - cls_score = self.fc_cls(x) - - return cls_score.npu_format_cast(0) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch +import torch.nn as nn +from mmcv.cnn import normal_init + +from ..builder import HEADS +from .base import BaseHead + + +@HEADS.register_module() +class SlowFastHead(BaseHead): + """The classification head for SlowFast. + + Args: + num_classes (int): Number of classes to be classified. + in_channels (int): Number of channels in input feature. + loss_cls (dict): Config for building loss. + Default: dict(type='CrossEntropyLoss'). + spatial_type (str): Pooling type in spatial dimension. Default: 'avg'. + dropout_ratio (float): Probability of dropout layer. Default: 0.8. + init_std (float): Std value for Initiation. Default: 0.01. + kwargs (dict, optional): Any keyword argument to be used to initialize + the head. + """ + def __init__(self, + num_classes, + in_channels, + loss_cls=dict(type='CrossEntropyLoss'), + spatial_type='avg', + dropout_ratio=0.8, + init_std=0.01, + **kwargs): + + super().__init__(num_classes, in_channels, loss_cls, **kwargs) + self.spatial_type = spatial_type + self.dropout_ratio = dropout_ratio + self.init_std = init_std + + if self.dropout_ratio != 0: + self.dropout = nn.Dropout(p=self.dropout_ratio) + else: + self.dropout = None + self.fc_cls = nn.Linear(in_channels, num_classes) + + if self.spatial_type == 'avg': + self.avg_pool = nn.AdaptiveAvgPool3d((1, 1, 1)) + else: + self.avg_pool = None + + def init_weights(self): + """Initiate the parameters from scratch.""" + normal_init(self.fc_cls, std=self.init_std) + + def forward(self, x): + """Defines the computation performed at every call. + + Args: + x (torch.Tensor): The input data. + + Returns: + torch.Tensor: The classification scores for input samples. + """ + # ([N, channel_fast, T, H, W], [(N, channel_slow, T, H, W)]) + x_fast, x_slow = x + # ([N, channel_fast, 1, 1, 1], [N, channel_slow, 1, 1, 1]) + x_fast = self.avg_pool(x_fast) + x_slow = self.avg_pool(x_slow) + # [N, channel_fast + channel_slow, 1, 1, 1] + x = torch.cat((x_slow, x_fast), dim=1) + + if self.dropout is not None: + x = self.dropout(x) + + # [N x C] + x = x.view(x.size(0), -1) + # [N x num_classes] + cls_score = self.fc_cls(x) + + return cls_score.npu_format_cast(0) diff --git a/PyTorch/contrib/cv/video/SlowFast/mmaction/models/losses/cross_entropy_loss.py b/PyTorch/contrib/cv/video/SlowFast/mmaction/models/losses/cross_entropy_loss.py index 11c9bfd4ddc109784c8a48a77286ed9663c7c53f..a0afe4232c36c25b3735f3efd9caa8de24e081e0 100644 --- a/PyTorch/contrib/cv/video/SlowFast/mmaction/models/losses/cross_entropy_loss.py +++ b/PyTorch/contrib/cv/video/SlowFast/mmaction/models/losses/cross_entropy_loss.py @@ -1,133 +1,133 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch -import torch.nn.functional as F - -from ..builder import LOSSES -from .base import BaseWeightedLoss - - -@LOSSES.register_module() -class CrossEntropyLoss(BaseWeightedLoss): - """Cross Entropy Loss. - - Support two kinds of labels and their corresponding loss type. It's worth - mentioning that loss type will be detected by the shape of ``cls_score`` - and ``label``. - 1) Hard label: This label is an integer array and all of the elements are - in the range [0, num_classes - 1]. This label's shape should be - ``cls_score``'s shape with the `num_classes` dimension removed. - 2) Soft label(probablity distribution over classes): This label is a - probability distribution and all of the elements are in the range - [0, 1]. This label's shape must be the same as ``cls_score``. For now, - only 2-dim soft label is supported. - - Args: - loss_weight (float): Factor scalar multiplied on the loss. - Default: 1.0. - class_weight (list[float] | None): Loss weight for each class. If set - as None, use the same weight 1 for all classes. Only applies - to CrossEntropyLoss and BCELossWithLogits (should not be set when - using other losses). Default: None. - """ - def __init__(self, loss_weight=1.0, class_weight=None): - super().__init__(loss_weight=loss_weight) - self.class_weight = None - if class_weight is not None: - self.class_weight = torch.Tensor(class_weight) - - def _forward(self, cls_score, label, **kwargs): - """Forward function. - - Args: - cls_score (torch.Tensor): The class score. - label (torch.Tensor): The ground truth label. - kwargs: Any keyword argument to be used to calculate - CrossEntropy loss. - - Returns: - torch.Tensor: The returned CrossEntropy loss. - """ - if cls_score.size() == label.size(): - # calculate loss for soft label - - assert cls_score.dim() == 2, 'Only support 2-dim soft label' - assert len(kwargs) == 0, \ - ('For now, no extra args are supported for soft label, ' - f'but get {kwargs}') - - lsm = F.log_softmax(cls_score, 1) - if self.class_weight is not None: - lsm = lsm * self.class_weight.unsqueeze(0) - loss_cls = -(label * lsm).sum(1) - - # default reduction 'mean' - if self.class_weight is not None: - # Use weighted average as pytorch CrossEntropyLoss does. - # For more information, please visit https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html # noqa - loss_cls = loss_cls.sum() / torch.sum( - self.class_weight.unsqueeze(0) * label) - else: - loss_cls = loss_cls.mean() - else: - # calculate loss for hard label - - if self.class_weight is not None: - assert 'weight' not in kwargs, \ - "The key 'weight' already exists." - kwargs['weight'] = self.class_weight.to(cls_score.device) - # cls_score = cls_score.type(torch.float32) - # label = label.type(torch.int32) - loss_cls = F.cross_entropy(cls_score, label, **kwargs) - - return loss_cls - - -@LOSSES.register_module() -class BCELossWithLogits(BaseWeightedLoss): - """Binary Cross Entropy Loss with logits. - - Args: - loss_weight (float): Factor scalar multiplied on the loss. - Default: 1.0. - class_weight (list[float] | None): Loss weight for each class. If set - as None, use the same weight 1 for all classes. Only applies - to CrossEntropyLoss and BCELossWithLogits (should not be set when - using other losses). Default: None. - """ - def __init__(self, loss_weight=1.0, class_weight=None): - super().__init__(loss_weight=loss_weight) - self.class_weight = None - if class_weight is not None: - self.class_weight = torch.Tensor(class_weight) - - def _forward(self, cls_score, label, **kwargs): - """Forward function. - - Args: - cls_score (torch.Tensor): The class score. - label (torch.Tensor): The ground truth label. - kwargs: Any keyword argument to be used to calculate - bce loss with logits. - - Returns: - torch.Tensor: The returned bce loss with logits. - """ - if self.class_weight is not None: - assert 'weight' not in kwargs, "The key 'weight' already exists." - kwargs['weight'] = self.class_weight.to(cls_score.device) - loss_cls = F.binary_cross_entropy_with_logits(cls_score, label, - **kwargs) - return loss_cls +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch +import torch.nn.functional as F + +from ..builder import LOSSES +from .base import BaseWeightedLoss + + +@LOSSES.register_module() +class CrossEntropyLoss(BaseWeightedLoss): + """Cross Entropy Loss. + + Support two kinds of labels and their corresponding loss type. It's worth + mentioning that loss type will be detected by the shape of ``cls_score`` + and ``label``. + 1) Hard label: This label is an integer array and all of the elements are + in the range [0, num_classes - 1]. This label's shape should be + ``cls_score``'s shape with the `num_classes` dimension removed. + 2) Soft label(probablity distribution over classes): This label is a + probability distribution and all of the elements are in the range + [0, 1]. This label's shape must be the same as ``cls_score``. For now, + only 2-dim soft label is supported. + + Args: + loss_weight (float): Factor scalar multiplied on the loss. + Default: 1.0. + class_weight (list[float] | None): Loss weight for each class. If set + as None, use the same weight 1 for all classes. Only applies + to CrossEntropyLoss and BCELossWithLogits (should not be set when + using other losses). Default: None. + """ + def __init__(self, loss_weight=1.0, class_weight=None): + super().__init__(loss_weight=loss_weight) + self.class_weight = None + if class_weight is not None: + self.class_weight = torch.Tensor(class_weight) + + def _forward(self, cls_score, label, **kwargs): + """Forward function. + + Args: + cls_score (torch.Tensor): The class score. + label (torch.Tensor): The ground truth label. + kwargs: Any keyword argument to be used to calculate + CrossEntropy loss. + + Returns: + torch.Tensor: The returned CrossEntropy loss. + """ + if cls_score.size() == label.size(): + # calculate loss for soft label + + assert cls_score.dim() == 2, 'Only support 2-dim soft label' + assert len(kwargs) == 0, \ + ('For now, no extra args are supported for soft label, ' + f'but get {kwargs}') + + lsm = F.log_softmax(cls_score, 1) + if self.class_weight is not None: + lsm = lsm * self.class_weight.unsqueeze(0) + loss_cls = -(label * lsm).sum(1) + + # default reduction 'mean' + if self.class_weight is not None: + # Use weighted average as pytorch CrossEntropyLoss does. + # For more information, please visit https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html # noqa + loss_cls = loss_cls.sum() / torch.sum( + self.class_weight.unsqueeze(0) * label) + else: + loss_cls = loss_cls.mean() + else: + # calculate loss for hard label + + if self.class_weight is not None: + assert 'weight' not in kwargs, \ + "The key 'weight' already exists." + kwargs['weight'] = self.class_weight.to(cls_score.device) + # cls_score = cls_score.type(torch.float32) + # label = label.type(torch.int32) + loss_cls = F.cross_entropy(cls_score, label, **kwargs) + + return loss_cls + + +@LOSSES.register_module() +class BCELossWithLogits(BaseWeightedLoss): + """Binary Cross Entropy Loss with logits. + + Args: + loss_weight (float): Factor scalar multiplied on the loss. + Default: 1.0. + class_weight (list[float] | None): Loss weight for each class. If set + as None, use the same weight 1 for all classes. Only applies + to CrossEntropyLoss and BCELossWithLogits (should not be set when + using other losses). Default: None. + """ + def __init__(self, loss_weight=1.0, class_weight=None): + super().__init__(loss_weight=loss_weight) + self.class_weight = None + if class_weight is not None: + self.class_weight = torch.Tensor(class_weight) + + def _forward(self, cls_score, label, **kwargs): + """Forward function. + + Args: + cls_score (torch.Tensor): The class score. + label (torch.Tensor): The ground truth label. + kwargs: Any keyword argument to be used to calculate + bce loss with logits. + + Returns: + torch.Tensor: The returned bce loss with logits. + """ + if self.class_weight is not None: + assert 'weight' not in kwargs, "The key 'weight' already exists." + kwargs['weight'] = self.class_weight.to(cls_score.device) + loss_cls = F.binary_cross_entropy_with_logits(cls_score, label, + **kwargs) + return loss_cls diff --git a/PyTorch/contrib/cv/video/SlowFast/mmaction/models/recognizers/base.py b/PyTorch/contrib/cv/video/SlowFast/mmaction/models/recognizers/base.py index 35603218baa99c3f8caa13bfd76f1e46fbc1e117..b7a0c527ec36b603f98961b7c0d6b511d99f1f6d 100644 --- a/PyTorch/contrib/cv/video/SlowFast/mmaction/models/recognizers/base.py +++ b/PyTorch/contrib/cv/video/SlowFast/mmaction/models/recognizers/base.py @@ -1,339 +1,339 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import warnings -from abc import ABCMeta, abstractmethod -from collections import OrderedDict - -import torch -import torch.distributed as dist -import torch.nn as nn -import torch.nn.functional as F -from mmcv.runner import auto_fp16 - -from .. import builder - - -class BaseRecognizer(nn.Module, metaclass=ABCMeta): - """Base class for recognizers. - - All recognizers should subclass it. - All subclass should overwrite: - - - Methods:``forward_train``, supporting to forward when training. - - Methods:``forward_test``, supporting to forward when testing. - - Args: - backbone (dict): Backbone modules to extract feature. - cls_head (dict | None): Classification head to process feature. - Default: None. - neck (dict | None): Neck for feature fusion. Default: None. - train_cfg (dict | None): Config for training. Default: None. - test_cfg (dict | None): Config for testing. Default: None. - """ - def __init__(self, - backbone, - cls_head=None, - neck=None, - train_cfg=None, - test_cfg=None): - super().__init__() - # record the source of the backbone - self.backbone_from = 'mmaction2' - - if backbone['type'].startswith('mmcls.'): - try: - import mmcls.models.builder as mmcls_builder - except (ImportError, ModuleNotFoundError): - raise ImportError('Please install mmcls to use this backbone.') - backbone['type'] = backbone['type'][6:] - self.backbone = mmcls_builder.build_backbone(backbone) - self.backbone_from = 'mmcls' - elif backbone['type'].startswith('torchvision.'): - try: - import torchvision.models - except (ImportError, ModuleNotFoundError): - raise ImportError('Please install torchvision to use this ' - 'backbone.') - backbone_type = backbone.pop('type')[12:] - self.backbone = torchvision.models.__dict__[backbone_type]( - **backbone) - # disable the classifier - self.backbone.classifier = nn.Identity() - self.backbone.fc = nn.Identity() - self.backbone_from = 'torchvision' - elif backbone['type'].startswith('timm.'): - try: - import timm - except (ImportError, ModuleNotFoundError): - raise ImportError('Please install timm to use this ' - 'backbone.') - backbone_type = backbone.pop('type')[5:] - # disable the classifier - backbone['num_classes'] = 0 - self.backbone = timm.create_model(backbone_type, **backbone) - self.backbone_from = 'timm' - else: - self.backbone = builder.build_backbone(backbone) - - if neck is not None: - self.neck = builder.build_neck(neck) - - self.cls_head = builder.build_head(cls_head) if cls_head else None - - self.train_cfg = train_cfg - self.test_cfg = test_cfg - - # aux_info is the list of tensor names beyond 'imgs' and 'label' which - # will be used in train_step and val_step, data_batch should contain - # these tensors - self.aux_info = [] - if train_cfg is not None and 'aux_info' in train_cfg: - self.aux_info = train_cfg['aux_info'] - # max_testing_views should be int - self.max_testing_views = None - if test_cfg is not None and 'max_testing_views' in test_cfg: - self.max_testing_views = test_cfg['max_testing_views'] - assert isinstance(self.max_testing_views, int) - - if test_cfg is not None and 'feature_extraction' in test_cfg: - self.feature_extraction = test_cfg['feature_extraction'] - else: - self.feature_extraction = False - - # mini-batch blending, e.g. mixup, cutmix, etc. - self.blending = None - if train_cfg is not None and 'blending' in train_cfg: - from mmcv.utils import build_from_cfg - from mmaction.datasets.builder import BLENDINGS - self.blending = build_from_cfg(train_cfg['blending'], BLENDINGS) - - self.init_weights() - - self.fp16_enabled = False - - @property - def with_neck(self): - """bool: whether the recognizer has a neck""" - return hasattr(self, 'neck') and self.neck is not None - - @property - def with_cls_head(self): - """bool: whether the recognizer has a cls_head""" - return hasattr(self, 'cls_head') and self.cls_head is not None - - def init_weights(self): - """Initialize the model network weights.""" - if self.backbone_from in ['mmcls', 'mmaction2']: - self.backbone.init_weights() - elif self.backbone_from in ['torchvision', 'timm']: - warnings.warn('We do not initialize weights for backbones in ' - f'{self.backbone_from}, since the weights for ' - f'backbones in {self.backbone_from} are initialized' - 'in their __init__ functions.') - else: - raise NotImplementedError('Unsupported backbone source ' - f'{self.backbone_from}!') - - if self.with_cls_head: - self.cls_head.init_weights() - if self.with_neck: - self.neck.init_weights() - - @auto_fp16() - def extract_feat(self, imgs): - """Extract features through a backbone. - - Args: - imgs (torch.Tensor): The input images. - - Returns: - torch.tensor: The extracted features. - """ - if (hasattr(self.backbone, 'features') - and self.backbone_from == 'torchvision'): - x = self.backbone.features(imgs) - elif self.backbone_from == 'timm': - x = self.backbone.forward_features(imgs) - else: - x = self.backbone(imgs) - return x - - def average_clip(self, cls_score, num_segs=1): - """Averaging class score over multiple clips. - - Using different averaging types ('score' or 'prob' or None, - which defined in test_cfg) to computed the final averaged - class score. Only called in test mode. - - Args: - cls_score (torch.Tensor): Class score to be averaged. - num_segs (int): Number of clips for each input sample. - - Returns: - torch.Tensor: Averaged class score. - """ - if 'average_clips' not in self.test_cfg.keys(): - raise KeyError('"average_clips" must defined in test_cfg\'s keys') - - average_clips = self.test_cfg['average_clips'] - if average_clips not in ['score', 'prob', None]: - raise ValueError(f'{average_clips} is not supported. ' - f'Currently supported ones are ' - f'["score", "prob", None]') - - if average_clips is None: - return cls_score - - batch_size = cls_score.shape[0] - cls_score = cls_score.view(batch_size // num_segs, num_segs, -1) - - if average_clips == 'prob': - cls_score = F.softmax(cls_score, dim=2).mean(dim=1) - elif average_clips == 'score': - cls_score = cls_score.mean(dim=1) - - return cls_score - - @abstractmethod - def forward_train(self, imgs, labels, **kwargs): - """Defines the computation performed at every call when training.""" - - @abstractmethod - def forward_test(self, imgs): - """Defines the computation performed at every call when evaluation and - testing.""" - - @abstractmethod - def forward_gradcam(self, imgs): - """Defines the computation performed at every all when using gradcam - utils.""" - - @staticmethod - def _parse_losses(losses): - """Parse the raw outputs (losses) of the network. - - Args: - losses (dict): Raw output of the network, which usually contain - losses and other necessary information. - - Returns: - tuple[Tensor, dict]: (loss, log_vars), loss is the loss tensor - which may be a weighted sum of all losses, log_vars contains - all the variables to be sent to the logger. - """ - log_vars = OrderedDict() - for loss_name, loss_value in losses.items(): - if isinstance(loss_value, torch.Tensor): - log_vars[loss_name] = loss_value.mean() - elif isinstance(loss_value, list): - log_vars[loss_name] = sum(_loss.mean() for _loss in loss_value) - else: - raise TypeError( - f'{loss_name} is not a tensor or list of tensors') - - loss = sum(_value for _key, _value in log_vars.items() - if 'loss' in _key) - - log_vars['loss'] = loss - for loss_name, loss_value in log_vars.items(): - # reduce loss when distributed training - if dist.is_available() and dist.is_initialized(): - loss_value = loss_value.data.clone() - dist.all_reduce(loss_value.div_(dist.get_world_size())) - log_vars[loss_name] = loss_value.item() - - return loss, log_vars - - def forward(self, imgs, label=None, return_loss=True, **kwargs): - """Define the computation performed at every call.""" - if kwargs.get('gradcam', False): - del kwargs['gradcam'] - return self.forward_gradcam(imgs, **kwargs) - if return_loss: - if label is None: - raise ValueError('Label should not be None.') - if self.blending is not None: - imgs, label = self.blending(imgs, label) - return self.forward_train(imgs, label, **kwargs) - - return self.forward_test(imgs, **kwargs) - - def train_step(self, data_batch, optimizer, **kwargs): - """The iteration step during training. - - This method defines an iteration step during training, except for the - back propagation and optimizer updating, which are done in an optimizer - hook. Note that in some complicated cases or models, the whole process - including back propagation and optimizer updating is also defined in - this method, such as GAN. - - Args: - data_batch (dict): The output of dataloader. - optimizer (:obj:`torch.optim.Optimizer` | dict): The optimizer of - runner is passed to ``train_step()``. This argument is unused - and reserved. - - Returns: - dict: It should contain at least 3 keys: ``loss``, ``log_vars``, - ``num_samples``. - ``loss`` is a tensor for back propagation, which can be a - weighted sum of multiple losses. - ``log_vars`` contains all the variables to be sent to the - logger. - ``num_samples`` indicates the batch size (when the model is - DDP, it means the batch size on each GPU), which is used for - averaging the logs. - """ - imgs = data_batch['imgs'].npu().type(torch.float32) - label = data_batch['label'].npu().type(torch.int32) - - aux_info = {} - for item in self.aux_info: - assert item in data_batch - aux_info[item] = data_batch[item] - - losses = self(imgs, label, return_loss=True, **aux_info) - - loss, log_vars = self._parse_losses(losses) - - outputs = dict(loss=loss, - log_vars=log_vars, - num_samples=len(next(iter(data_batch.values())))) - - return outputs - - def val_step(self, data_batch, optimizer, **kwargs): - """The iteration step during validation. - - This method shares the same signature as :func:`train_step`, but used - during val epochs. Note that the evaluation after training epochs is - not implemented with this method, but an evaluation hook. - """ - imgs = data_batch['imgs'].npu().type(torch.float32) - label = data_batch['label'].npu().type(torch.int32) - - aux_info = {} - for item in self.aux_info: - aux_info[item] = data_batch[item] - - losses = self(imgs, label, return_loss=True, **aux_info) - - loss, log_vars = self._parse_losses(losses) - - outputs = dict(loss=loss, - log_vars=log_vars, - num_samples=len(next(iter(data_batch.values())))) - - return outputs +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import warnings +from abc import ABCMeta, abstractmethod +from collections import OrderedDict + +import torch +import torch.distributed as dist +import torch.nn as nn +import torch.nn.functional as F +from mmcv.runner import auto_fp16 + +from .. import builder + + +class BaseRecognizer(nn.Module, metaclass=ABCMeta): + """Base class for recognizers. + + All recognizers should subclass it. + All subclass should overwrite: + + - Methods:``forward_train``, supporting to forward when training. + - Methods:``forward_test``, supporting to forward when testing. + + Args: + backbone (dict): Backbone modules to extract feature. + cls_head (dict | None): Classification head to process feature. + Default: None. + neck (dict | None): Neck for feature fusion. Default: None. + train_cfg (dict | None): Config for training. Default: None. + test_cfg (dict | None): Config for testing. Default: None. + """ + def __init__(self, + backbone, + cls_head=None, + neck=None, + train_cfg=None, + test_cfg=None): + super().__init__() + # record the source of the backbone + self.backbone_from = 'mmaction2' + + if backbone['type'].startswith('mmcls.'): + try: + import mmcls.models.builder as mmcls_builder + except (ImportError, ModuleNotFoundError): + raise ImportError('Please install mmcls to use this backbone.') + backbone['type'] = backbone['type'][6:] + self.backbone = mmcls_builder.build_backbone(backbone) + self.backbone_from = 'mmcls' + elif backbone['type'].startswith('torchvision.'): + try: + import torchvision.models + except (ImportError, ModuleNotFoundError): + raise ImportError('Please install torchvision to use this ' + 'backbone.') + backbone_type = backbone.pop('type')[12:] + self.backbone = torchvision.models.__dict__[backbone_type]( + **backbone) + # disable the classifier + self.backbone.classifier = nn.Identity() + self.backbone.fc = nn.Identity() + self.backbone_from = 'torchvision' + elif backbone['type'].startswith('timm.'): + try: + import timm + except (ImportError, ModuleNotFoundError): + raise ImportError('Please install timm to use this ' + 'backbone.') + backbone_type = backbone.pop('type')[5:] + # disable the classifier + backbone['num_classes'] = 0 + self.backbone = timm.create_model(backbone_type, **backbone) + self.backbone_from = 'timm' + else: + self.backbone = builder.build_backbone(backbone) + + if neck is not None: + self.neck = builder.build_neck(neck) + + self.cls_head = builder.build_head(cls_head) if cls_head else None + + self.train_cfg = train_cfg + self.test_cfg = test_cfg + + # aux_info is the list of tensor names beyond 'imgs' and 'label' which + # will be used in train_step and val_step, data_batch should contain + # these tensors + self.aux_info = [] + if train_cfg is not None and 'aux_info' in train_cfg: + self.aux_info = train_cfg['aux_info'] + # max_testing_views should be int + self.max_testing_views = None + if test_cfg is not None and 'max_testing_views' in test_cfg: + self.max_testing_views = test_cfg['max_testing_views'] + assert isinstance(self.max_testing_views, int) + + if test_cfg is not None and 'feature_extraction' in test_cfg: + self.feature_extraction = test_cfg['feature_extraction'] + else: + self.feature_extraction = False + + # mini-batch blending, e.g. mixup, cutmix, etc. + self.blending = None + if train_cfg is not None and 'blending' in train_cfg: + from mmcv.utils import build_from_cfg + from mmaction.datasets.builder import BLENDINGS + self.blending = build_from_cfg(train_cfg['blending'], BLENDINGS) + + self.init_weights() + + self.fp16_enabled = False + + @property + def with_neck(self): + """bool: whether the recognizer has a neck""" + return hasattr(self, 'neck') and self.neck is not None + + @property + def with_cls_head(self): + """bool: whether the recognizer has a cls_head""" + return hasattr(self, 'cls_head') and self.cls_head is not None + + def init_weights(self): + """Initialize the model network weights.""" + if self.backbone_from in ['mmcls', 'mmaction2']: + self.backbone.init_weights() + elif self.backbone_from in ['torchvision', 'timm']: + warnings.warn('We do not initialize weights for backbones in ' + f'{self.backbone_from}, since the weights for ' + f'backbones in {self.backbone_from} are initialized' + 'in their __init__ functions.') + else: + raise NotImplementedError('Unsupported backbone source ' + f'{self.backbone_from}!') + + if self.with_cls_head: + self.cls_head.init_weights() + if self.with_neck: + self.neck.init_weights() + + @auto_fp16() + def extract_feat(self, imgs): + """Extract features through a backbone. + + Args: + imgs (torch.Tensor): The input images. + + Returns: + torch.tensor: The extracted features. + """ + if (hasattr(self.backbone, 'features') + and self.backbone_from == 'torchvision'): + x = self.backbone.features(imgs) + elif self.backbone_from == 'timm': + x = self.backbone.forward_features(imgs) + else: + x = self.backbone(imgs) + return x + + def average_clip(self, cls_score, num_segs=1): + """Averaging class score over multiple clips. + + Using different averaging types ('score' or 'prob' or None, + which defined in test_cfg) to computed the final averaged + class score. Only called in test mode. + + Args: + cls_score (torch.Tensor): Class score to be averaged. + num_segs (int): Number of clips for each input sample. + + Returns: + torch.Tensor: Averaged class score. + """ + if 'average_clips' not in self.test_cfg.keys(): + raise KeyError('"average_clips" must defined in test_cfg\'s keys') + + average_clips = self.test_cfg['average_clips'] + if average_clips not in ['score', 'prob', None]: + raise ValueError(f'{average_clips} is not supported. ' + f'Currently supported ones are ' + f'["score", "prob", None]') + + if average_clips is None: + return cls_score + + batch_size = cls_score.shape[0] + cls_score = cls_score.view(batch_size // num_segs, num_segs, -1) + + if average_clips == 'prob': + cls_score = F.softmax(cls_score, dim=2).mean(dim=1) + elif average_clips == 'score': + cls_score = cls_score.mean(dim=1) + + return cls_score + + @abstractmethod + def forward_train(self, imgs, labels, **kwargs): + """Defines the computation performed at every call when training.""" + + @abstractmethod + def forward_test(self, imgs): + """Defines the computation performed at every call when evaluation and + testing.""" + + @abstractmethod + def forward_gradcam(self, imgs): + """Defines the computation performed at every all when using gradcam + utils.""" + + @staticmethod + def _parse_losses(losses): + """Parse the raw outputs (losses) of the network. + + Args: + losses (dict): Raw output of the network, which usually contain + losses and other necessary information. + + Returns: + tuple[Tensor, dict]: (loss, log_vars), loss is the loss tensor + which may be a weighted sum of all losses, log_vars contains + all the variables to be sent to the logger. + """ + log_vars = OrderedDict() + for loss_name, loss_value in losses.items(): + if isinstance(loss_value, torch.Tensor): + log_vars[loss_name] = loss_value.mean() + elif isinstance(loss_value, list): + log_vars[loss_name] = sum(_loss.mean() for _loss in loss_value) + else: + raise TypeError( + f'{loss_name} is not a tensor or list of tensors') + + loss = sum(_value for _key, _value in log_vars.items() + if 'loss' in _key) + + log_vars['loss'] = loss + for loss_name, loss_value in log_vars.items(): + # reduce loss when distributed training + if dist.is_available() and dist.is_initialized(): + loss_value = loss_value.data.clone() + dist.all_reduce(loss_value.div_(dist.get_world_size())) + log_vars[loss_name] = loss_value.item() + + return loss, log_vars + + def forward(self, imgs, label=None, return_loss=True, **kwargs): + """Define the computation performed at every call.""" + if kwargs.get('gradcam', False): + del kwargs['gradcam'] + return self.forward_gradcam(imgs, **kwargs) + if return_loss: + if label is None: + raise ValueError('Label should not be None.') + if self.blending is not None: + imgs, label = self.blending(imgs, label) + return self.forward_train(imgs, label, **kwargs) + + return self.forward_test(imgs, **kwargs) + + def train_step(self, data_batch, optimizer, **kwargs): + """The iteration step during training. + + This method defines an iteration step during training, except for the + back propagation and optimizer updating, which are done in an optimizer + hook. Note that in some complicated cases or models, the whole process + including back propagation and optimizer updating is also defined in + this method, such as GAN. + + Args: + data_batch (dict): The output of dataloader. + optimizer (:obj:`torch.optim.Optimizer` | dict): The optimizer of + runner is passed to ``train_step()``. This argument is unused + and reserved. + + Returns: + dict: It should contain at least 3 keys: ``loss``, ``log_vars``, + ``num_samples``. + ``loss`` is a tensor for back propagation, which can be a + weighted sum of multiple losses. + ``log_vars`` contains all the variables to be sent to the + logger. + ``num_samples`` indicates the batch size (when the model is + DDP, it means the batch size on each GPU), which is used for + averaging the logs. + """ + imgs = data_batch['imgs'].npu().type(torch.float32) + label = data_batch['label'].npu().type(torch.int32) + + aux_info = {} + for item in self.aux_info: + assert item in data_batch + aux_info[item] = data_batch[item] + + losses = self(imgs, label, return_loss=True, **aux_info) + + loss, log_vars = self._parse_losses(losses) + + outputs = dict(loss=loss, + log_vars=log_vars, + num_samples=len(next(iter(data_batch.values())))) + + return outputs + + def val_step(self, data_batch, optimizer, **kwargs): + """The iteration step during validation. + + This method shares the same signature as :func:`train_step`, but used + during val epochs. Note that the evaluation after training epochs is + not implemented with this method, but an evaluation hook. + """ + imgs = data_batch['imgs'].npu().type(torch.float32) + label = data_batch['label'].npu().type(torch.int32) + + aux_info = {} + for item in self.aux_info: + aux_info[item] = data_batch[item] + + losses = self(imgs, label, return_loss=True, **aux_info) + + loss, log_vars = self._parse_losses(losses) + + outputs = dict(loss=loss, + log_vars=log_vars, + num_samples=len(next(iter(data_batch.values())))) + + return outputs diff --git a/PyTorch/contrib/cv/video/SlowFast/mmaction/models/recognizers/recognizer2d.py b/PyTorch/contrib/cv/video/SlowFast/mmaction/models/recognizers/recognizer2d.py index 7d145f6dd83cab07d056cb40ce712c0ab9485c5c..3d9a755a5a53ebe1432ac413ee6ab85566d07b06 100644 --- a/PyTorch/contrib/cv/video/SlowFast/mmaction/models/recognizers/recognizer2d.py +++ b/PyTorch/contrib/cv/video/SlowFast/mmaction/models/recognizers/recognizer2d.py @@ -1,195 +1,195 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch -from torch import nn - -from ..builder import RECOGNIZERS -from .base import BaseRecognizer - - -@RECOGNIZERS.register_module() -class Recognizer2D(BaseRecognizer): - """2D recognizer model framework.""" - def forward_train(self, imgs, labels, **kwargs): - """Defines the computation performed at every call when training.""" - - assert self.with_cls_head - batches = imgs.shape[0] - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - num_segs = imgs.shape[0] // batches - - losses = dict() - - x = self.extract_feat(imgs) - - if self.backbone_from in ['torchvision', 'timm']: - if len(x.shape) == 4 and (x.shape[2] > 1 or x.shape[3] > 1): - # apply adaptive avg pooling - x = nn.AdaptiveAvgPool2d(1)(x) - x = x.reshape((x.shape[0], -1)) - x = x.reshape(x.shape + (1, 1)) - - if self.with_neck: - x = [ - each.reshape((-1, num_segs) + each.shape[1:]).transpose( - 1, 2).contiguous() for each in x - ] - x, loss_aux = self.neck(x, labels.squeeze()) - x = x.squeeze(2) - num_segs = 1 - losses.update(loss_aux) - - cls_score = self.cls_head(x, num_segs) - gt_labels = labels.squeeze() - loss_cls = self.cls_head.loss(cls_score, gt_labels, **kwargs) - losses.update(loss_cls) - - return losses - - def _do_test(self, imgs): - """Defines the computation performed at every call when evaluation, - testing and gradcam.""" - batches = imgs.shape[0] - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - num_segs = imgs.shape[0] // batches - - x = self.extract_feat(imgs) - - if self.backbone_from in ['torchvision', 'timm']: - if len(x.shape) == 4 and (x.shape[2] > 1 or x.shape[3] > 1): - # apply adaptive avg pooling - x = nn.AdaptiveAvgPool2d(1)(x) - x = x.reshape((x.shape[0], -1)) - x = x.reshape(x.shape + (1, 1)) - - if self.with_neck: - x = [ - each.reshape((-1, num_segs) + each.shape[1:]).transpose( - 1, 2).contiguous() for each in x - ] - x, _ = self.neck(x) - x = x.squeeze(2) - num_segs = 1 - - if self.feature_extraction: - # perform spatial pooling - avg_pool = nn.AdaptiveAvgPool2d(1) - x = avg_pool(x) - # squeeze dimensions - x = x.reshape((batches, num_segs, -1)) - # temporal average pooling - x = x.mean(axis=1) - return x - - # When using `TSNHead` or `TPNHead`, shape is [batch_size, num_classes] - # When using `TSMHead`, shape is [batch_size * num_crops, num_classes] - # `num_crops` is calculated by: - # 1) `twice_sample` in `SampleFrames` - # 2) `num_sample_positions` in `DenseSampleFrames` - # 3) `ThreeCrop/TenCrop/MultiGroupCrop` in `test_pipeline` - # 4) `num_clips` in `SampleFrames` or its subclass if `clip_len != 1` - - # should have cls_head if not extracting features - cls_score = self.cls_head(x, num_segs) - - assert cls_score.size()[0] % batches == 0 - # calculate num_crops automatically - cls_score = self.average_clip(cls_score, - cls_score.size()[0] // batches) - return cls_score - - def _do_fcn_test(self, imgs): - # [N, num_crops * num_segs, C, H, W] -> - # [N * num_crops * num_segs, C, H, W] - batches = imgs.shape[0] - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - num_segs = self.test_cfg.get('num_segs', self.backbone.num_segments) - - if self.test_cfg.get('flip', False): - imgs = torch.flip(imgs, [-1]) - x = self.extract_feat(imgs) - - if self.with_neck: - x = [ - each.reshape((-1, num_segs) + each.shape[1:]).transpose( - 1, 2).contiguous() for each in x - ] - x, _ = self.neck(x) - else: - x = x.reshape((-1, num_segs) + x.shape[1:]).transpose( - 1, 2).contiguous() - - # When using `TSNHead` or `TPNHead`, shape is [batch_size, num_classes] - # When using `TSMHead`, shape is [batch_size * num_crops, num_classes] - # `num_crops` is calculated by: - # 1) `twice_sample` in `SampleFrames` - # 2) `num_sample_positions` in `DenseSampleFrames` - # 3) `ThreeCrop/TenCrop/MultiGroupCrop` in `test_pipeline` - # 4) `num_clips` in `SampleFrames` or its subclass if `clip_len != 1` - cls_score = self.cls_head(x, fcn_test=True) - - assert cls_score.size()[0] % batches == 0 - # calculate num_crops automatically - cls_score = self.average_clip(cls_score, - cls_score.size()[0] // batches) - return cls_score - - def forward_test(self, imgs): - """Defines the computation performed at every call when evaluation and - testing.""" - imgs = imgs.npu().type(torch.float16) - if self.test_cfg.get('fcn_test', False): - # If specified, spatially fully-convolutional testing is performed - assert not self.feature_extraction - assert self.with_cls_head - return self._do_fcn_test(imgs).cpu().numpy() - return self._do_test(imgs).cpu().numpy() - - def forward_dummy(self, imgs, softmax=False): - """Used for computing network FLOPs. - - See ``tools/analysis/get_flops.py``. - - Args: - imgs (torch.Tensor): Input images. - - Returns: - Tensor: Class score. - """ - assert self.with_cls_head - batches = imgs.shape[0] - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - num_segs = imgs.shape[0] // batches - - x = self.extract_feat(imgs) - if self.with_neck: - x = [ - each.reshape((-1, num_segs) + each.shape[1:]).transpose( - 1, 2).contiguous() for each in x - ] - x, _ = self.neck(x) - x = x.squeeze(2) - num_segs = 1 - - outs = self.cls_head(x, num_segs) - if softmax: - outs = nn.functional.softmax(outs) - return (outs, ) - - def forward_gradcam(self, imgs): - """Defines the computation performed at every call when using gradcam - utils.""" - assert self.with_cls_head - return self._do_test(imgs) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch +from torch import nn + +from ..builder import RECOGNIZERS +from .base import BaseRecognizer + + +@RECOGNIZERS.register_module() +class Recognizer2D(BaseRecognizer): + """2D recognizer model framework.""" + def forward_train(self, imgs, labels, **kwargs): + """Defines the computation performed at every call when training.""" + + assert self.with_cls_head + batches = imgs.shape[0] + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + num_segs = imgs.shape[0] // batches + + losses = dict() + + x = self.extract_feat(imgs) + + if self.backbone_from in ['torchvision', 'timm']: + if len(x.shape) == 4 and (x.shape[2] > 1 or x.shape[3] > 1): + # apply adaptive avg pooling + x = nn.AdaptiveAvgPool2d(1)(x) + x = x.reshape((x.shape[0], -1)) + x = x.reshape(x.shape + (1, 1)) + + if self.with_neck: + x = [ + each.reshape((-1, num_segs) + each.shape[1:]).transpose( + 1, 2).contiguous() for each in x + ] + x, loss_aux = self.neck(x, labels.squeeze()) + x = x.squeeze(2) + num_segs = 1 + losses.update(loss_aux) + + cls_score = self.cls_head(x, num_segs) + gt_labels = labels.squeeze() + loss_cls = self.cls_head.loss(cls_score, gt_labels, **kwargs) + losses.update(loss_cls) + + return losses + + def _do_test(self, imgs): + """Defines the computation performed at every call when evaluation, + testing and gradcam.""" + batches = imgs.shape[0] + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + num_segs = imgs.shape[0] // batches + + x = self.extract_feat(imgs) + + if self.backbone_from in ['torchvision', 'timm']: + if len(x.shape) == 4 and (x.shape[2] > 1 or x.shape[3] > 1): + # apply adaptive avg pooling + x = nn.AdaptiveAvgPool2d(1)(x) + x = x.reshape((x.shape[0], -1)) + x = x.reshape(x.shape + (1, 1)) + + if self.with_neck: + x = [ + each.reshape((-1, num_segs) + each.shape[1:]).transpose( + 1, 2).contiguous() for each in x + ] + x, _ = self.neck(x) + x = x.squeeze(2) + num_segs = 1 + + if self.feature_extraction: + # perform spatial pooling + avg_pool = nn.AdaptiveAvgPool2d(1) + x = avg_pool(x) + # squeeze dimensions + x = x.reshape((batches, num_segs, -1)) + # temporal average pooling + x = x.mean(axis=1) + return x + + # When using `TSNHead` or `TPNHead`, shape is [batch_size, num_classes] + # When using `TSMHead`, shape is [batch_size * num_crops, num_classes] + # `num_crops` is calculated by: + # 1) `twice_sample` in `SampleFrames` + # 2) `num_sample_positions` in `DenseSampleFrames` + # 3) `ThreeCrop/TenCrop/MultiGroupCrop` in `test_pipeline` + # 4) `num_clips` in `SampleFrames` or its subclass if `clip_len != 1` + + # should have cls_head if not extracting features + cls_score = self.cls_head(x, num_segs) + + assert cls_score.size()[0] % batches == 0 + # calculate num_crops automatically + cls_score = self.average_clip(cls_score, + cls_score.size()[0] // batches) + return cls_score + + def _do_fcn_test(self, imgs): + # [N, num_crops * num_segs, C, H, W] -> + # [N * num_crops * num_segs, C, H, W] + batches = imgs.shape[0] + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + num_segs = self.test_cfg.get('num_segs', self.backbone.num_segments) + + if self.test_cfg.get('flip', False): + imgs = torch.flip(imgs, [-1]) + x = self.extract_feat(imgs) + + if self.with_neck: + x = [ + each.reshape((-1, num_segs) + each.shape[1:]).transpose( + 1, 2).contiguous() for each in x + ] + x, _ = self.neck(x) + else: + x = x.reshape((-1, num_segs) + x.shape[1:]).transpose( + 1, 2).contiguous() + + # When using `TSNHead` or `TPNHead`, shape is [batch_size, num_classes] + # When using `TSMHead`, shape is [batch_size * num_crops, num_classes] + # `num_crops` is calculated by: + # 1) `twice_sample` in `SampleFrames` + # 2) `num_sample_positions` in `DenseSampleFrames` + # 3) `ThreeCrop/TenCrop/MultiGroupCrop` in `test_pipeline` + # 4) `num_clips` in `SampleFrames` or its subclass if `clip_len != 1` + cls_score = self.cls_head(x, fcn_test=True) + + assert cls_score.size()[0] % batches == 0 + # calculate num_crops automatically + cls_score = self.average_clip(cls_score, + cls_score.size()[0] // batches) + return cls_score + + def forward_test(self, imgs): + """Defines the computation performed at every call when evaluation and + testing.""" + imgs = imgs.npu().type(torch.float16) + if self.test_cfg.get('fcn_test', False): + # If specified, spatially fully-convolutional testing is performed + assert not self.feature_extraction + assert self.with_cls_head + return self._do_fcn_test(imgs).cpu().numpy() + return self._do_test(imgs).cpu().numpy() + + def forward_dummy(self, imgs, softmax=False): + """Used for computing network FLOPs. + + See ``tools/analysis/get_flops.py``. + + Args: + imgs (torch.Tensor): Input images. + + Returns: + Tensor: Class score. + """ + assert self.with_cls_head + batches = imgs.shape[0] + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + num_segs = imgs.shape[0] // batches + + x = self.extract_feat(imgs) + if self.with_neck: + x = [ + each.reshape((-1, num_segs) + each.shape[1:]).transpose( + 1, 2).contiguous() for each in x + ] + x, _ = self.neck(x) + x = x.squeeze(2) + num_segs = 1 + + outs = self.cls_head(x, num_segs) + if softmax: + outs = nn.functional.softmax(outs) + return (outs, ) + + def forward_gradcam(self, imgs): + """Defines the computation performed at every call when using gradcam + utils.""" + assert self.with_cls_head + return self._do_test(imgs) diff --git a/PyTorch/contrib/cv/video/SlowFast/mmaction/models/recognizers/recognizer3d.py b/PyTorch/contrib/cv/video/SlowFast/mmaction/models/recognizers/recognizer3d.py index fe1a61ef2bad97c0c35ee9c97b7fd66373381585..9a1b70449dfdaf5b598586a98d91a1fbcdd057dc 100644 --- a/PyTorch/contrib/cv/video/SlowFast/mmaction/models/recognizers/recognizer3d.py +++ b/PyTorch/contrib/cv/video/SlowFast/mmaction/models/recognizers/recognizer3d.py @@ -1,133 +1,133 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -import torch -from torch import nn - -from ..builder import RECOGNIZERS -from .base import BaseRecognizer - - -@RECOGNIZERS.register_module() -class Recognizer3D(BaseRecognizer): - """3D recognizer model framework.""" - def forward_train(self, imgs, labels, **kwargs): - """Defines the computation performed at every call when training.""" - - assert self.with_cls_head - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - losses = dict() - - x = self.extract_feat(imgs) - if self.with_neck: - x, loss_aux = self.neck(x, labels.squeeze()) - losses.update(loss_aux) - - cls_score = self.cls_head(x) - gt_labels = labels.squeeze() - loss_cls = self.cls_head.loss(cls_score, gt_labels, **kwargs) - losses.update(loss_cls) - - return losses - - def _do_test(self, imgs): - """Defines the computation performed at every call when evaluation, - testing and gradcam.""" - batches = imgs.shape[0] - num_segs = imgs.shape[1] - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - - if self.max_testing_views is not None: - total_views = imgs.shape[0] - assert num_segs == total_views, ( - 'max_testing_views is only compatible ' - 'with batch_size == 1') - view_ptr = 0 - feats = [] - while view_ptr < total_views: - batch_imgs = imgs[view_ptr:view_ptr + self.max_testing_views] - x = self.extract_feat(batch_imgs) - if self.with_neck: - x, _ = self.neck(x) - feats.append(x) - view_ptr += self.max_testing_views - # should consider the case that feat is a tuple - if isinstance(feats[0], tuple): - len_tuple = len(feats[0]) - feat = [ - torch.cat([x[i] for x in feats]) for i in range(len_tuple) - ] - feat = tuple(feat) - else: - feat = torch.cat(feats) - else: - feat = self.extract_feat(imgs) - if self.with_neck: - feat, _ = self.neck(feat) - - if self.feature_extraction: - # perform spatio-temporal pooling - avg_pool = nn.AdaptiveAvgPool3d(1) - if isinstance(feat, tuple): - feat = [avg_pool(x) for x in feat] - # concat them - feat = torch.cat(feat, axis=1) - else: - feat = avg_pool(feat) - # squeeze dimensions - feat = feat.reshape((batches, num_segs, -1)) - # temporal average pooling - feat = feat.mean(axis=1) - return feat - - # should have cls_head if not extracting features - assert self.with_cls_head - cls_score = self.cls_head(feat) - cls_score = self.average_clip(cls_score, num_segs) - return cls_score - - def forward_test(self, imgs): - """Defines the computation performed at every call when evaluation and - testing.""" - imgs = imgs.npu().type(torch.float16) - return self._do_test(imgs).cpu().numpy() - - def forward_dummy(self, imgs, softmax=False): - """Used for computing network FLOPs. - - See ``tools/analysis/get_flops.py``. - - Args: - imgs (torch.Tensor): Input images. - - Returns: - Tensor: Class score. - """ - assert self.with_cls_head - imgs = imgs.reshape((-1, ) + imgs.shape[2:]) - x = self.extract_feat(imgs) - - if self.with_neck: - x, _ = self.neck(x) - - outs = self.cls_head(x) - if softmax: - outs = nn.functional.softmax(outs) - return (outs, ) - - def forward_gradcam(self, imgs): - """Defines the computation performed at every call when using gradcam - utils.""" - assert self.with_cls_head - return self._do_test(imgs) +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +import torch +from torch import nn + +from ..builder import RECOGNIZERS +from .base import BaseRecognizer + + +@RECOGNIZERS.register_module() +class Recognizer3D(BaseRecognizer): + """3D recognizer model framework.""" + def forward_train(self, imgs, labels, **kwargs): + """Defines the computation performed at every call when training.""" + + assert self.with_cls_head + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + losses = dict() + + x = self.extract_feat(imgs) + if self.with_neck: + x, loss_aux = self.neck(x, labels.squeeze()) + losses.update(loss_aux) + + cls_score = self.cls_head(x) + gt_labels = labels.squeeze() + loss_cls = self.cls_head.loss(cls_score, gt_labels, **kwargs) + losses.update(loss_cls) + + return losses + + def _do_test(self, imgs): + """Defines the computation performed at every call when evaluation, + testing and gradcam.""" + batches = imgs.shape[0] + num_segs = imgs.shape[1] + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + + if self.max_testing_views is not None: + total_views = imgs.shape[0] + assert num_segs == total_views, ( + 'max_testing_views is only compatible ' + 'with batch_size == 1') + view_ptr = 0 + feats = [] + while view_ptr < total_views: + batch_imgs = imgs[view_ptr:view_ptr + self.max_testing_views] + x = self.extract_feat(batch_imgs) + if self.with_neck: + x, _ = self.neck(x) + feats.append(x) + view_ptr += self.max_testing_views + # should consider the case that feat is a tuple + if isinstance(feats[0], tuple): + len_tuple = len(feats[0]) + feat = [ + torch.cat([x[i] for x in feats]) for i in range(len_tuple) + ] + feat = tuple(feat) + else: + feat = torch.cat(feats) + else: + feat = self.extract_feat(imgs) + if self.with_neck: + feat, _ = self.neck(feat) + + if self.feature_extraction: + # perform spatio-temporal pooling + avg_pool = nn.AdaptiveAvgPool3d(1) + if isinstance(feat, tuple): + feat = [avg_pool(x) for x in feat] + # concat them + feat = torch.cat(feat, axis=1) + else: + feat = avg_pool(feat) + # squeeze dimensions + feat = feat.reshape((batches, num_segs, -1)) + # temporal average pooling + feat = feat.mean(axis=1) + return feat + + # should have cls_head if not extracting features + assert self.with_cls_head + cls_score = self.cls_head(feat) + cls_score = self.average_clip(cls_score, num_segs) + return cls_score + + def forward_test(self, imgs): + """Defines the computation performed at every call when evaluation and + testing.""" + imgs = imgs.npu().type(torch.float16) + return self._do_test(imgs).cpu().numpy() + + def forward_dummy(self, imgs, softmax=False): + """Used for computing network FLOPs. + + See ``tools/analysis/get_flops.py``. + + Args: + imgs (torch.Tensor): Input images. + + Returns: + Tensor: Class score. + """ + assert self.with_cls_head + imgs = imgs.reshape((-1, ) + imgs.shape[2:]) + x = self.extract_feat(imgs) + + if self.with_neck: + x, _ = self.neck(x) + + outs = self.cls_head(x) + if softmax: + outs = nn.functional.softmax(outs) + return (outs, ) + + def forward_gradcam(self, imgs): + """Defines the computation performed at every call when using gradcam + utils.""" + assert self.with_cls_head + return self._do_test(imgs) diff --git a/PyTorch/contrib/cv/video/VideoPose3D/run.py b/PyTorch/contrib/cv/video/VideoPose3D/run.py index dea000f7c6f929fb8f9b126470e74efc5e56a671..c252af15642db549f167c2eb88d0b5b3f148170f 100644 --- a/PyTorch/contrib/cv/video/VideoPose3D/run.py +++ b/PyTorch/contrib/cv/video/VideoPose3D/run.py @@ -1,699 +1,699 @@ -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ - -# Copyright (c) 2018-present, Facebook, Inc. -# All rights reserved. -# -# This source code is licensed under the license found in the -# LICENSE file in the root directory of this source tree. - - -import numpy as np - -from common.arguments import parse_args -import torch - -import torch.nn as nn -import torch.nn.functional as F -import torch.optim as optim -import torch.distributed as dist -import torch.multiprocessing as mp -import os -import sys -import errno -import math -import logging - -from common.camera import * -from common.model import * -from common.loss import * -from common.generators import ChunkedGenerator, UnchunkedGenerator -from time import time -from common.utils import deterministic_random, fetch, run_evaluation -from common.structure import AverageMeter, time_format_convert, device_id_to_process_device_map - -from tensorboardX import SummaryWriter -from apex import amp -# from apex.optimizers import NpuFusedAdam - - -def main(): - args = parse_args() - # print(args) - - try: - # Create checkpoint directory if it does not exist - os.makedirs(args.checkpoint) - except OSError as e: - if e.errno != errno.EEXIST: - raise RuntimeError('Unable to create checkpoint directory:', args.checkpoint) - - if not os.path.exists(args.output): - os.makedirs(args.output) - print(f"args.output:{args.output}") - - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = '27005' - - process_device_map = device_id_to_process_device_map(args.device_list) - - if args.device == 'npu': - ngpus_per_node = len(process_device_map) - else: - ngpus_per_node = args.num_gpus - - args.num_gpus = ngpus_per_node - args.world_size = args.world_size * ngpus_per_node - - # npu = int(os.environ['RANK_ID']) - mp.spawn(main_worker, nprocs=ngpus_per_node, args=(ngpus_per_node, args)) - - -def setup_logger(final_output_dir, rank, phase): - # time_str = time.strftime('%Y-%m-%d-%H-%M') - log_file = '{}_rank{}.log'.format(phase, rank) - final_log_file = os.path.join(final_output_dir, log_file) - head = '%(asctime)-15s %(message)s' - # logging.basicConfig(format=head) - logging.basicConfig(filename=str(final_log_file), - format=head) - logger = logging.getLogger() - logger.setLevel(logging.INFO) - console = logging.StreamHandler() - logging.getLogger('').addHandler(console) - - return logger - - -def main_worker(gpu, ngpus_per_node, args): - process_device_map = device_id_to_process_device_map(args.device_list) - log_dir = args.output - logger = setup_logger(log_dir, gpu, 'train') - - # args.gpu = gpu - args.gpu = process_device_map[gpu] - # logger.info(f"args.gpu is {args.gpu}") - - args.rank = args.rank * ngpus_per_node + gpu - - # print(f'args.print_feq:{args.print_feq}') - if args.rank % ngpus_per_node == 0: - log_path = args.log - writer_dict = { - 'writer': SummaryWriter(logdir=log_path), - 'train_global_steps': 0, - 'valid_global_steps': 0, - } - - if args.device == 'npu': - print("args.rank:",args.rank) - dist.init_process_group(backend=args.dist_backend, # init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - else: - dist.init_process_group(backend='nccl', init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - - logger.info(f'Loading dataset for rank:{args.rank}...') - dataset_path = 'data/data_3d_' + args.dataset + '.npz' - if args.dataset == 'h36m': - from common.h36m_dataset import Human36mDataset - dataset = Human36mDataset(dataset_path) - elif args.dataset.startswith('humaneva'): - from common.humaneva_dataset import HumanEvaDataset - dataset = HumanEvaDataset(dataset_path) - elif args.dataset.startswith('custom'): - from common.custom_dataset import CustomDataset - dataset = CustomDataset('data/data_2d_' + args.dataset + '_' + args.keypoints + '.npz') - else: - raise KeyError('Invalid dataset') - - logger.info(f'Preparing data for rank:{args.rank}...') - for subject in dataset.subjects(): - for action in dataset[subject].keys(): - anim = dataset[subject][action] - - if 'positions' in anim: - positions_3d = [] - for cam in anim['cameras']: - pos_3d = world_to_camera(anim['positions'], R=cam['orientation'], t=cam['translation']) - pos_3d[:, 1:] -= pos_3d[:, :1] # Remove global offset, but keep trajectory in first position - positions_3d.append(pos_3d) - anim['positions_3d'] = positions_3d - - logger.info(f'Loading 2D detections for rank:{args.rank}...') - keypoints = np.load('data/data_2d_' + args.dataset + '_' + args.keypoints + '.npz', allow_pickle=True) - keypoints_metadata = keypoints['metadata'].item() - keypoints_symmetry = keypoints_metadata['keypoints_symmetry'] - kps_left, kps_right = list(keypoints_symmetry[0]), list(keypoints_symmetry[1]) - joints_left, joints_right = list(dataset.skeleton().joints_left()), list(dataset.skeleton().joints_right()) - keypoints = keypoints['positions_2d'].item() - - for subject in dataset.subjects(): - assert subject in keypoints, 'Subject {} is missing from the 2D detections dataset'.format(subject) - for action in dataset[subject].keys(): - assert action in keypoints[subject], 'Action {} of subject {} is missing from the 2D detections dataset'.format(action, subject) - if 'positions_3d' not in dataset[subject][action]: - continue - - for cam_idx in range(len(keypoints[subject][action])): - - # We check for >= instead of == because some videos in H3.6M contain extra frames - mocap_length = dataset[subject][action]['positions_3d'][cam_idx].shape[0] - assert keypoints[subject][action][cam_idx].shape[0] >= mocap_length - - if keypoints[subject][action][cam_idx].shape[0] > mocap_length: - # Shorten sequence - keypoints[subject][action][cam_idx] = keypoints[subject][action][cam_idx][:mocap_length] - - assert len(keypoints[subject][action]) == len(dataset[subject][action]['positions_3d']) - - for subject in keypoints.keys(): - for action in keypoints[subject]: - for cam_idx, kps in enumerate(keypoints[subject][action]): - # Normalize camera frame - cam = dataset.cameras()[subject][cam_idx] - kps[..., :2] = normalize_screen_coordinates(kps[..., :2], w=cam['res_w'], h=cam['res_h']) - keypoints[subject][action][cam_idx] = kps - - subjects_train = args.subjects_train.split(',') - subjects_semi = [] if not args.subjects_unlabeled else args.subjects_unlabeled.split(',') - if not args.render: - subjects_test = args.subjects_test.split(',') - else: - subjects_test = [args.viz_subject] - - semi_supervised = len(subjects_semi) > 0 - if semi_supervised and not dataset.supports_semi_supervised(): - raise RuntimeError('Semi-supervised training is not implemented for this dataset') - - # moved fatch to utils.py - - action_filter = None if args.actions == '*' else args.actions.split(',') - if action_filter is not None: - print('Selected actions:', action_filter) - - cameras_valid, poses_valid, poses_valid_2d = fetch(subjects_test, keypoints=keypoints, dataset=dataset, args=args ,action_filter=action_filter) - - filter_widths = [int(x) for x in args.architecture.split(',')] - if not args.disable_optimizations and not args.dense and args.stride == 1: - # Use optimized model for single-frame predictions - model_pos_train = TemporalModelOptimized1f(poses_valid_2d[0].shape[-2], poses_valid_2d[0].shape[-1], dataset.skeleton().num_joints(), - filter_widths=filter_widths, causal=args.causal, dropout=args.dropout, channels=args.channels) - else: - # When incompatible settings are detected (stride > 1, dense filters, or disabled optimization) fall back to normal model - model_pos_train = TemporalModel(poses_valid_2d[0].shape[-2], poses_valid_2d[0].shape[-1], dataset.skeleton().num_joints(), - filter_widths=filter_widths, causal=args.causal, dropout=args.dropout, channels=args.channels, - dense=args.dense) - - model_pos = TemporalModel(poses_valid_2d[0].shape[-2], poses_valid_2d[0].shape[-1], dataset.skeleton().num_joints(), - filter_widths=filter_widths, causal=args.causal, dropout=args.dropout, channels=args.channels, - dense=args.dense) - - receptive_field = model_pos.receptive_field() - logger.info('INFO: Receptive field: {} frames'.format(receptive_field)) - pad = (receptive_field - 1) // 2 # Padding on each side - if args.causal: - logger.info('INFO: Using causal convolutions') - causal_shift = pad - else: - causal_shift = 0 - - model_params = 0 - for parameter in model_pos.parameters(): - model_params += parameter.numel() - print('INFO: Trainable parameter count:', model_params) - - assert args.gpu is not None, "Something wrong about args.gpu, it shouldn't be None." - - if not torch.npu.is_available(): - print("We only implemented for GPUs") - raise NotImplementedError - else: - loc = f'npu:{args.gpu}' - torch.npu.set_device(loc) - model_pos = model_pos.to(loc) - model_pos_train = model_pos_train.to(loc) - model_pos = torch.nn.parallel.DistributedDataParallel(model_pos, device_ids=[args.gpu], broadcast_buffers=False) - - - - if args.evaluate: - assert args.resume is '' - chk_filename = os.path.join(args.checkpoint, args.evaluate) - logger.info(f'Loading checkpoint {chk_filename}') - checkpoint = torch.load(chk_filename, map_location=lambda storage, loc: storage) - model_pos.load_state_dict(checkpoint['model_pos']) - model_traj = None - - - test_generator = UnchunkedGenerator(args, cameras_valid, poses_valid, poses_valid_2d, - pad=pad, causal_shift=causal_shift, augment=False, - kps_left=kps_left, kps_right=kps_right, joints_left=joints_left, joints_right=joints_right) - logger.info('INFO: Testing on {} frames'.format(test_generator.num_frames())) - - if not args.evaluate: - cameras_train, poses_train, poses_train_2d = fetch(subjects_train, keypoints=keypoints, dataset=dataset, args=args, action_filter=action_filter, subset=args.subset) - - lr = args.learning_rate - if args.rank % args.num_gpus == 0: - logger.info(f"inital learning rate is:{lr}") - if semi_supervised: - print("Not Implement semi_supervised version for DDP") - raise NotImplementedError - else: - optimizer = optim.Adam(model_pos_train.parameters(), lr=lr) #, amsgrad=True) - # optimizer = NpuFusedAdam(model_pos_train.parameters(), lr=lr) - print(f"Use Apex:{args.apex}") - print(f"Sampler:{args.sampler}") - if args.apex: - model_pos_train, optimizer = amp.initialize(model_pos_train, optimizer, opt_level="O1", loss_scale=128.0) #, combine_grad=True) - model_pos_train = torch.nn.parallel.DistributedDataParallel(model_pos_train, device_ids=[args.gpu], broadcast_buffers=False) - - lr_decay = args.lr_decay - - losses_3d_train = [] - losses_3d_train_eval = [] - losses_3d_valid = [] - - epoch = 0 - initial_momentum = 0.1 - final_momentum = 0.001 - - - train_generator = ChunkedGenerator(args, args.batch_size//args.stride, cameras_train, poses_train, poses_train_2d, args.stride, - pad=pad, causal_shift=causal_shift, shuffle=True, random_seed=args.random_seed, augment=args.data_augmentation, - kps_left=kps_left, kps_right=kps_right, joints_left=joints_left, joints_right=joints_right) - train_generator_eval = UnchunkedGenerator(args, cameras_train, poses_train, poses_train_2d, - pad=pad, causal_shift=causal_shift, augment=False) - print('INFO: Training on {} frames'.format(train_generator_eval.num_frames())) - if semi_supervised: - print("Not Implement semi_supervised version for DDP") - raise NotImplementedError - - if args.resume: - chk_filename = os.path.join(args.checkpoint, args.resume) - print("resuming the training...") - print('Loading checkpoint', chk_filename) - checkpoint = torch.load(chk_filename, map_location=loc) - epoch = checkpoint['epoch'] - model_pos_train.load_state_dict(checkpoint['model_pos']) - if 'optimizer' in checkpoint and checkpoint['optimizer'] is not None: - optimizer.load_state_dict(checkpoint['optimizer']) - # train_generator.set_random_state(checkpoint['random_state']) - else: - print('WARNING: this checkpoint does not contain an optimizer state. The optimizer will be reinitialized.') - if checkpoint['amp'] is not None: - amp.load_state_dict(checkpoint['amp']) - if args.rank % ngpus_per_node == 0: - if 'train_global_steps' in checkpoint and 'valid_global_steps' in checkpoint: - writer_dict['train_global_steps'] = checkpoint['train_global_steps'] - writer_dict['valid_global_steps'] = checkpoint['valid_global_steps'] - lr = checkpoint['lr'] - if semi_supervised: - print("Not Implement semi_supervised version for DDP") - raise NotImplementedError - # model_traj_train.load_state_dict(checkpoint['model_traj']) - # model_traj.load_state_dict(checkpoint['model_traj']) - # semi_generator.set_random_state(checkpoint['random_state_semi']) - - logger.info('** Note: reported losses are averaged over all frames and test-time augmentation is not used here.') - logger.info('** The final evaluation will be carried out after the last training epoch.') - - myend = time() - mytime = AverageMeter() - best_valid = 50.0 - prof_flag = args.prof - while epoch < args.epochs: - start_time = time() - epoch_loss = AverageMeter() - epoch_loss_val = AverageMeter() - train_generator.set_epoch(epoch) - epoch_loss_3d_train = 0 - # epoch_loss_traj_train = 0 - # epoch_loss_2d_train_unlabeled = 0 - epoch_fps = AverageMeter() - N = 0 - N_semi = 0 - model_pos_train.train() - if semi_supervised: - print("Not Implement semi_supervised version for DDP") - raise NotImplementedError - else: - # Regular supervised scenario - count = 0 - for _, batch_3d, batch_2d in train_generator.next_epoch(): - if count >= 2: - my_epoch_start = time() - if batch_2d.shape[0] == 0: - continue - # print(f"batch_3d.shape:{batch_3d.shape} for rank:{args.rank}") - bz = batch_2d.shape[0] - assert batch_3d.shape[0] == bz - inputs_3d = torch.from_numpy(batch_3d.astype('float32')) - inputs_2d = torch.from_numpy(batch_2d.astype('float32')) - if torch.npu.is_available(): - inputs_3d = inputs_3d.to(loc, non_blocking=False) - inputs_2d = inputs_2d.to(loc, non_blocking=False) - inputs_3d[:, :, 0] = 0 - - if prof_flag and count==10 and args.rank==0: - with torch.autograd.profiler.profile(use_npu=True) as prof: - optimizer.zero_grad() - - # Predict 3D poses - predicted_3d_pos = model_pos_train(inputs_2d) - loss_3d_pos = mpjpe(predicted_3d_pos, inputs_3d) - - loss_total = loss_3d_pos - if args.apex: - with amp.scale_loss(loss_total, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss_total.backward() - - optimizer.step() - print(prof.key_averages().table(sort_by='self_cpu_time_total')) - prof.export_chrome_trace(os.path.join(args.checkpoint,'out.prof')) - prof_flag = False - print(f"prof has been saved as {os.path.join(args.checkpoint,'out.prof')}") - else: - optimizer.zero_grad() - - # Predict 3D poses - predicted_3d_pos = model_pos_train(inputs_2d) - loss_3d_pos = mpjpe(predicted_3d_pos, inputs_3d) - - loss_total = loss_3d_pos - if args.apex: - with amp.scale_loss(loss_total, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss_total.backward() - - optimizer.step() - - dist.all_reduce(loss_total) - loss_total = loss_total / ngpus_per_node - epoch_loss.update(loss_total.item(), bz) - - epoch_loss_3d_train += inputs_3d.shape[0]*inputs_3d.shape[1] * loss_total.item() - N += inputs_3d.shape[0]*inputs_3d.shape[1] - - if count >= 2: - batch_time = time()-my_epoch_start - fps = bz * ngpus_per_node / batch_time - epoch_fps.update(fps) - if args.rank % ngpus_per_node == 0: - writer = writer_dict['writer'] - train_step = writer_dict['train_global_steps'] - writer.add_scalar('total_loss',epoch_loss.avg,train_step) - writer_dict['train_global_steps'] = train_step + 1 - - - if count % args.print_freq == 0 and args.rank % ngpus_per_node == 0: - logger.info("({batch}/{size})| loss:{loss.val:.5f} ({loss.avg:.5f})| FPS:{fps.val:.3f} ({fps.avg:.3f})".format( - batch=count, size=math.ceil(train_generator.num_frames()/(args.batch_size*ngpus_per_node)), loss=epoch_loss, - fps=epoch_fps - )) - count +=1 - if args.rank % ngpus_per_node == 0: - writer.add_scalar('loss_3d/train', epoch_loss_3d_train / N, epoch) - - losses_3d_train.append(epoch_loss_3d_train / N) - - - # End-of-epoch evaluation - if args.rank == 0 and not args.no_eval: - print("End of epoch evaluation start ....") - with torch.no_grad(): - model_pos.load_state_dict(model_pos_train.state_dict()) - model_pos.eval() - if semi_supervised: - print("Not Implement semi_supervised version for DDP") - raise NotImplementedError - # model_traj.load_state_dict(model_traj_train.state_dict()) - # model_traj.eval() - - epoch_loss_3d_valid = 0 - epoch_loss_traj_valid = 0 - epoch_loss_2d_valid = 0 - N = 0 - - if not args.no_eval: - # Evaluate on test set - for cam, batch, batch_2d in test_generator.next_epoch(): - inputs_3d = torch.from_numpy(batch.astype('float32')) - inputs_2d = torch.from_numpy(batch_2d.astype('float32')) - if torch.npu.is_available(): - inputs_3d = inputs_3d.to(loc, non_blocking=False) - inputs_2d = inputs_2d.to(loc, non_blocking=False) - inputs_traj = inputs_3d[:, :, :1].clone() - inputs_3d[:, :, 0] = 0 - - # Predict 3D poses - predicted_3d_pos = model_pos(inputs_2d) - loss_3d_pos = mpjpe(predicted_3d_pos, inputs_3d) - - bz = inputs_2d.shape[0] - assert bz == inputs_3d.shape[0] - - dist.all_reduce(loss_3d_pos) - loss_3d_pos = loss_3d_pos / ngpus_per_node - - epoch_loss_val.update(loss_3d_pos, bz) - - epoch_loss_3d_valid += inputs_3d.shape[0]*inputs_3d.shape[1] * loss_3d_pos.item() - N += inputs_3d.shape[0]*inputs_3d.shape[1] - - if args.rank % ngpus_per_node == 0: - val_step = writer_dict['valid_global_steps'] - writer.add_scalar("val_loss",epoch_loss_val.avg, val_step) - writer_dict['valid_global_steps'] = val_step + 1 - if semi_supervised: - print("Not Implement semi_supervised version for DDP") - raise NotImplementedError - if args.rank % ngpus_per_node == 0: - writer.add_scalar("loss_3d/valid", epoch_loss_3d_valid / N, epoch) - print("out of end-of-epoch evaluation loop.") - losses_3d_valid.append(epoch_loss_3d_valid / N) - if semi_supervised: - print("Not Implement semi_supervised version for DDP") - raise NotImplementedError - # losses_traj_valid.append(epoch_loss_traj_valid / N) - # losses_2d_valid.append(epoch_loss_2d_valid / N) - - - # Evaluate on training set, this time in evaluation mode - epoch_loss_3d_train_eval = 0 - # epoch_loss_traj_train_eval = 0 - # epoch_loss_2d_train_labeled_eval = 0 - N = 0 - for cam, batch, batch_2d in train_generator_eval.next_epoch(): - if batch_2d.shape[1] == 0: - # This can only happen when downsampling the dataset - continue - - inputs_3d = torch.from_numpy(batch.astype('float32')) - inputs_2d = torch.from_numpy(batch_2d.astype('float32')) - if torch.npu.is_available(): - inputs_3d = inputs_3d.npu() - inputs_2d = inputs_2d.npu() - inputs_traj = inputs_3d[:, :, :1].clone() - inputs_3d[:, :, 0] = 0 - - # Compute 3D poses - predicted_3d_pos = model_pos(inputs_2d) - loss_3d_pos = mpjpe(predicted_3d_pos, inputs_3d) - - dist.all_reduce(loss_3d_pos) - loss_3d_pos = loss_3d_pos / ngpus_per_node - epoch_loss_3d_train_eval += inputs_3d.shape[0]*inputs_3d.shape[1] * loss_3d_pos.item() - N += inputs_3d.shape[0]*inputs_3d.shape[1] - - if semi_supervised: - print("Not Implement semi_supervised version for DDP") - raise NotImplementedError - - if args.rank % ngpus_per_node == 0: - writer.add_scalar('loss_3d/train_eval', epoch_loss_3d_train_eval / N, epoch) - losses_3d_train_eval.append(epoch_loss_3d_train_eval / N) - if semi_supervised: - print("Not Implement semi_supervised version for DDP") - raise NotImplementedError - # losses_traj_train_eval.append(epoch_loss_traj_train_eval / N) - # losses_2d_train_labeled_eval.append(epoch_loss_2d_train_labeled_eval / N) - - # Evaluate 2D loss on unlabeled training set (in evaluation mode) - epoch_loss_2d_train_unlabeled_eval = 0 - N_semi = 0 - if semi_supervised: - print("Not Implement semi_supervised version for DDP") - raise NotImplementedError - - elapsed = (time() - start_time)/60 - - if args.rank % ngpus_per_node == 0: - if args.no_eval: - logger.info('[%d] time %.2f lr %f 3d_train %f FPS %d' % ( - epoch + 1, - elapsed, - lr, - losses_3d_train[-1] * 1000, - int(epoch_fps.avg))) - else: - if semi_supervised: - print("Not Implement semi_supervised version for DDP") - raise NotImplementedError - else: - logger.info('[%d] time %.2f lr %f 3d_train %f 3d_eval %f 3d_valid %f FPS %d' % ( - epoch + 1, - elapsed, - lr, - losses_3d_train[-1] * 1000, - losses_3d_train_eval[-1] * 1000, - losses_3d_valid[-1] *1000, - int(epoch_fps.avg)) - ) - - # Decay learning rate exponentially - lr *= lr_decay - for param_group in optimizer.param_groups: - param_group['lr'] *= lr_decay - epoch += 1 - - # Decay BatchNorm momentum - momentum = initial_momentum * np.exp(-epoch/args.epochs * np.log(initial_momentum/final_momentum)) - model_pos_train.module.set_bn_momentum(momentum) - if semi_supervised: - print("Not Implement semi_supervised version for DDP") - raise NotImplementedError - # model_traj_train.set_bn_momentum(momentum) - - # Save best valid - if args.no_eval: - valid = 0 - else: - valid = losses_3d_valid[-1] *1000 - if args.rank % ngpus_per_node == 0 and valid < best_valid: - best_valid = valid - bst_path = os.path.join(args.checkpoint, 'model_best.bin') - logger.info(f'Saving best model up to epoch:{epoch} to {bst_path}') - torch.save({ - 'model_pos':model_pos_train.state_dict() - }, bst_path) - - # Save checkpoint if necessary - if epoch % args.checkpoint_frequency == 0 and args.rank % ngpus_per_node == 0: - chk_path = os.path.join(args.checkpoint, 'epoch_{}.bin'.format(epoch)) - logger.info(f'Saving checkpoint to {chk_path}') - - torch.save({ - 'epoch': epoch, - 'lr': lr, - # 'random_state': train_generator.random_state(), - 'optimizer': optimizer.state_dict(), - 'model_pos': model_pos_train.state_dict(), - # 'model_traj': None, # model_traj_train.state_dict() if semi_supervised else None, - 'amp': amp.state_dict() if args.apex else None, - 'random_state_semi': None, #semi_generator.random_state() if semi_supervised else None, - 'train_global_steps': writer_dict['train_global_steps'], - 'valid_global_steps': writer_dict['valid_global_steps'] - }, chk_path) - - - # Save training curves after every epoch, as .png images (if requested) - if args.export_training_curves and epoch > 3 and args.rank % ngpus_per_node == 0: - if 'matplotlib' not in sys.modules: - import matplotlib - matplotlib.use('Agg') - import matplotlib.pyplot as plt - - plt.figure() - epoch_x = np.arange(3, len(losses_3d_train)) + 1 - plt.plot(epoch_x, losses_3d_train[3:], '--', color='C0') - plt.plot(epoch_x, losses_3d_train_eval[3:], color='C0') - plt.plot(epoch_x, losses_3d_valid[3:], color='C1') - plt.legend(['3d train', '3d train (eval)', '3d valid (eval)']) - plt.ylabel('MPJPE (m)') - plt.xlabel('Epoch') - plt.xlim((3, epoch)) - plt.savefig(os.path.join(args.checkpoint, 'loss_3d.png')) - - if semi_supervised: - print("Not Implement semi_supervised version for DDP") - raise NotImplementedError - plt.close('all') - - mytime.update(time()-myend) - myend = time() - if args.rank % ngpus_per_node == 0: - print(f"In average, it takes {time_format_convert(mytime.avg)} per epoch.") - print(f"Time has elapsed {time_format_convert(mytime.sum)}") - print(f"It still need {time_format_convert(mytime.avg*(args.epochs-epoch))}") - print("****************************************************************************") - if args.rank % ngpus_per_node == 0: - writer_dict['writer'].close() - # Evaluate - if args.evaluate: - logger.info('Evaluating...') - # chk_filename = os.path.join(args.checkpoint, 'model_best.bin') - # if (not args.evaluate) and (os.path.exists(chk_filename)): - # checkpoint = torch.load(chk_filename, map_location='cpu') - # model_pos.load_state_dict(checkpoint['model_pos']) - all_actions = {} - all_actions_by_subject = {} - for subject in subjects_test: - if subject not in all_actions_by_subject: - all_actions_by_subject[subject] = {} - - for action in dataset[subject].keys(): - action_name = action.split(' ')[0] - if action_name not in all_actions: - all_actions[action_name] = [] - if action_name not in all_actions_by_subject[subject]: - all_actions_by_subject[subject][action_name] = [] - all_actions[action_name].append((subject, action)) - all_actions_by_subject[subject][action_name].append((subject, action)) - - if not args.by_subject: - run_evaluation(args, all_actions, model_pos, None, keypoints, dataset, pad, causal_shift, kps_left, kps_right, joints_left, joints_right, action_filter) - else: - for subject in all_actions_by_subject.keys(): - if args.rank % ngpus_per_node == 0: - print('Evaluating on subject', subject) - run_evaluation(args, all_actions_by_subject[subject], model_pos, None, keypoints, dataset, pad, causal_shift, kps_left, kps_right, joints_left, joints_right, action_filter) - if args.rank % ngpus_per_node == 0: - print('') - dist.destroy_process_group() - -if __name__ == "__main__": - main() +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ + +# Copyright (c) 2018-present, Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the license found in the +# LICENSE file in the root directory of this source tree. + + +import numpy as np + +from common.arguments import parse_args +import torch + +import torch.nn as nn +import torch.nn.functional as F +import torch.optim as optim +import torch.distributed as dist +import torch.multiprocessing as mp +import os +import sys +import errno +import math +import logging + +from common.camera import * +from common.model import * +from common.loss import * +from common.generators import ChunkedGenerator, UnchunkedGenerator +from time import time +from common.utils import deterministic_random, fetch, run_evaluation +from common.structure import AverageMeter, time_format_convert, device_id_to_process_device_map + +from tensorboardX import SummaryWriter +from apex import amp +# from apex.optimizers import NpuFusedAdam + + +def main(): + args = parse_args() + # print(args) + + try: + # Create checkpoint directory if it does not exist + os.makedirs(args.checkpoint) + except OSError as e: + if e.errno != errno.EEXIST: + raise RuntimeError('Unable to create checkpoint directory:', args.checkpoint) + + if not os.path.exists(args.output): + os.makedirs(args.output) + print(f"args.output:{args.output}") + + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '27005' + + process_device_map = device_id_to_process_device_map(args.device_list) + + if args.device == 'npu': + ngpus_per_node = len(process_device_map) + else: + ngpus_per_node = args.num_gpus + + args.num_gpus = ngpus_per_node + args.world_size = args.world_size * ngpus_per_node + + # npu = int(os.environ['RANK_ID']) + mp.spawn(main_worker, nprocs=ngpus_per_node, args=(ngpus_per_node, args)) + + +def setup_logger(final_output_dir, rank, phase): + # time_str = time.strftime('%Y-%m-%d-%H-%M') + log_file = '{}_rank{}.log'.format(phase, rank) + final_log_file = os.path.join(final_output_dir, log_file) + head = '%(asctime)-15s %(message)s' + # logging.basicConfig(format=head) + logging.basicConfig(filename=str(final_log_file), + format=head) + logger = logging.getLogger() + logger.setLevel(logging.INFO) + console = logging.StreamHandler() + logging.getLogger('').addHandler(console) + + return logger + + +def main_worker(gpu, ngpus_per_node, args): + process_device_map = device_id_to_process_device_map(args.device_list) + log_dir = args.output + logger = setup_logger(log_dir, gpu, 'train') + + # args.gpu = gpu + args.gpu = process_device_map[gpu] + # logger.info(f"args.gpu is {args.gpu}") + + args.rank = args.rank * ngpus_per_node + gpu + + # print(f'args.print_feq:{args.print_feq}') + if args.rank % ngpus_per_node == 0: + log_path = args.log + writer_dict = { + 'writer': SummaryWriter(logdir=log_path), + 'train_global_steps': 0, + 'valid_global_steps': 0, + } + + if args.device == 'npu': + print("args.rank:",args.rank) + dist.init_process_group(backend=args.dist_backend, # init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + else: + dist.init_process_group(backend='nccl', init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + + logger.info(f'Loading dataset for rank:{args.rank}...') + dataset_path = 'data/data_3d_' + args.dataset + '.npz' + if args.dataset == 'h36m': + from common.h36m_dataset import Human36mDataset + dataset = Human36mDataset(dataset_path) + elif args.dataset.startswith('humaneva'): + from common.humaneva_dataset import HumanEvaDataset + dataset = HumanEvaDataset(dataset_path) + elif args.dataset.startswith('custom'): + from common.custom_dataset import CustomDataset + dataset = CustomDataset('data/data_2d_' + args.dataset + '_' + args.keypoints + '.npz') + else: + raise KeyError('Invalid dataset') + + logger.info(f'Preparing data for rank:{args.rank}...') + for subject in dataset.subjects(): + for action in dataset[subject].keys(): + anim = dataset[subject][action] + + if 'positions' in anim: + positions_3d = [] + for cam in anim['cameras']: + pos_3d = world_to_camera(anim['positions'], R=cam['orientation'], t=cam['translation']) + pos_3d[:, 1:] -= pos_3d[:, :1] # Remove global offset, but keep trajectory in first position + positions_3d.append(pos_3d) + anim['positions_3d'] = positions_3d + + logger.info(f'Loading 2D detections for rank:{args.rank}...') + keypoints = np.load('data/data_2d_' + args.dataset + '_' + args.keypoints + '.npz', allow_pickle=True) + keypoints_metadata = keypoints['metadata'].item() + keypoints_symmetry = keypoints_metadata['keypoints_symmetry'] + kps_left, kps_right = list(keypoints_symmetry[0]), list(keypoints_symmetry[1]) + joints_left, joints_right = list(dataset.skeleton().joints_left()), list(dataset.skeleton().joints_right()) + keypoints = keypoints['positions_2d'].item() + + for subject in dataset.subjects(): + assert subject in keypoints, 'Subject {} is missing from the 2D detections dataset'.format(subject) + for action in dataset[subject].keys(): + assert action in keypoints[subject], 'Action {} of subject {} is missing from the 2D detections dataset'.format(action, subject) + if 'positions_3d' not in dataset[subject][action]: + continue + + for cam_idx in range(len(keypoints[subject][action])): + + # We check for >= instead of == because some videos in H3.6M contain extra frames + mocap_length = dataset[subject][action]['positions_3d'][cam_idx].shape[0] + assert keypoints[subject][action][cam_idx].shape[0] >= mocap_length + + if keypoints[subject][action][cam_idx].shape[0] > mocap_length: + # Shorten sequence + keypoints[subject][action][cam_idx] = keypoints[subject][action][cam_idx][:mocap_length] + + assert len(keypoints[subject][action]) == len(dataset[subject][action]['positions_3d']) + + for subject in keypoints.keys(): + for action in keypoints[subject]: + for cam_idx, kps in enumerate(keypoints[subject][action]): + # Normalize camera frame + cam = dataset.cameras()[subject][cam_idx] + kps[..., :2] = normalize_screen_coordinates(kps[..., :2], w=cam['res_w'], h=cam['res_h']) + keypoints[subject][action][cam_idx] = kps + + subjects_train = args.subjects_train.split(',') + subjects_semi = [] if not args.subjects_unlabeled else args.subjects_unlabeled.split(',') + if not args.render: + subjects_test = args.subjects_test.split(',') + else: + subjects_test = [args.viz_subject] + + semi_supervised = len(subjects_semi) > 0 + if semi_supervised and not dataset.supports_semi_supervised(): + raise RuntimeError('Semi-supervised training is not implemented for this dataset') + + # moved fatch to utils.py + + action_filter = None if args.actions == '*' else args.actions.split(',') + if action_filter is not None: + print('Selected actions:', action_filter) + + cameras_valid, poses_valid, poses_valid_2d = fetch(subjects_test, keypoints=keypoints, dataset=dataset, args=args ,action_filter=action_filter) + + filter_widths = [int(x) for x in args.architecture.split(',')] + if not args.disable_optimizations and not args.dense and args.stride == 1: + # Use optimized model for single-frame predictions + model_pos_train = TemporalModelOptimized1f(poses_valid_2d[0].shape[-2], poses_valid_2d[0].shape[-1], dataset.skeleton().num_joints(), + filter_widths=filter_widths, causal=args.causal, dropout=args.dropout, channels=args.channels) + else: + # When incompatible settings are detected (stride > 1, dense filters, or disabled optimization) fall back to normal model + model_pos_train = TemporalModel(poses_valid_2d[0].shape[-2], poses_valid_2d[0].shape[-1], dataset.skeleton().num_joints(), + filter_widths=filter_widths, causal=args.causal, dropout=args.dropout, channels=args.channels, + dense=args.dense) + + model_pos = TemporalModel(poses_valid_2d[0].shape[-2], poses_valid_2d[0].shape[-1], dataset.skeleton().num_joints(), + filter_widths=filter_widths, causal=args.causal, dropout=args.dropout, channels=args.channels, + dense=args.dense) + + receptive_field = model_pos.receptive_field() + logger.info('INFO: Receptive field: {} frames'.format(receptive_field)) + pad = (receptive_field - 1) // 2 # Padding on each side + if args.causal: + logger.info('INFO: Using causal convolutions') + causal_shift = pad + else: + causal_shift = 0 + + model_params = 0 + for parameter in model_pos.parameters(): + model_params += parameter.numel() + print('INFO: Trainable parameter count:', model_params) + + assert args.gpu is not None, "Something wrong about args.gpu, it shouldn't be None." + + if not torch.npu.is_available(): + print("We only implemented for GPUs") + raise NotImplementedError + else: + loc = f'npu:{args.gpu}' + torch.npu.set_device(loc) + model_pos = model_pos.to(loc) + model_pos_train = model_pos_train.to(loc) + model_pos = torch.nn.parallel.DistributedDataParallel(model_pos, device_ids=[args.gpu], broadcast_buffers=False) + + + + if args.evaluate: + assert args.resume is '' + chk_filename = os.path.join(args.checkpoint, args.evaluate) + logger.info(f'Loading checkpoint {chk_filename}') + checkpoint = torch.load(chk_filename, map_location=lambda storage, loc: storage) + model_pos.load_state_dict(checkpoint['model_pos']) + model_traj = None + + + test_generator = UnchunkedGenerator(args, cameras_valid, poses_valid, poses_valid_2d, + pad=pad, causal_shift=causal_shift, augment=False, + kps_left=kps_left, kps_right=kps_right, joints_left=joints_left, joints_right=joints_right) + logger.info('INFO: Testing on {} frames'.format(test_generator.num_frames())) + + if not args.evaluate: + cameras_train, poses_train, poses_train_2d = fetch(subjects_train, keypoints=keypoints, dataset=dataset, args=args, action_filter=action_filter, subset=args.subset) + + lr = args.learning_rate + if args.rank % args.num_gpus == 0: + logger.info(f"inital learning rate is:{lr}") + if semi_supervised: + print("Not Implement semi_supervised version for DDP") + raise NotImplementedError + else: + optimizer = optim.Adam(model_pos_train.parameters(), lr=lr) #, amsgrad=True) + # optimizer = NpuFusedAdam(model_pos_train.parameters(), lr=lr) + print(f"Use Apex:{args.apex}") + print(f"Sampler:{args.sampler}") + if args.apex: + model_pos_train, optimizer = amp.initialize(model_pos_train, optimizer, opt_level="O1", loss_scale=128.0) #, combine_grad=True) + model_pos_train = torch.nn.parallel.DistributedDataParallel(model_pos_train, device_ids=[args.gpu], broadcast_buffers=False) + + lr_decay = args.lr_decay + + losses_3d_train = [] + losses_3d_train_eval = [] + losses_3d_valid = [] + + epoch = 0 + initial_momentum = 0.1 + final_momentum = 0.001 + + + train_generator = ChunkedGenerator(args, args.batch_size//args.stride, cameras_train, poses_train, poses_train_2d, args.stride, + pad=pad, causal_shift=causal_shift, shuffle=True, random_seed=args.random_seed, augment=args.data_augmentation, + kps_left=kps_left, kps_right=kps_right, joints_left=joints_left, joints_right=joints_right) + train_generator_eval = UnchunkedGenerator(args, cameras_train, poses_train, poses_train_2d, + pad=pad, causal_shift=causal_shift, augment=False) + print('INFO: Training on {} frames'.format(train_generator_eval.num_frames())) + if semi_supervised: + print("Not Implement semi_supervised version for DDP") + raise NotImplementedError + + if args.resume: + chk_filename = os.path.join(args.checkpoint, args.resume) + print("resuming the training...") + print('Loading checkpoint', chk_filename) + checkpoint = torch.load(chk_filename, map_location=loc) + epoch = checkpoint['epoch'] + model_pos_train.load_state_dict(checkpoint['model_pos']) + if 'optimizer' in checkpoint and checkpoint['optimizer'] is not None: + optimizer.load_state_dict(checkpoint['optimizer']) + # train_generator.set_random_state(checkpoint['random_state']) + else: + print('WARNING: this checkpoint does not contain an optimizer state. The optimizer will be reinitialized.') + if checkpoint['amp'] is not None: + amp.load_state_dict(checkpoint['amp']) + if args.rank % ngpus_per_node == 0: + if 'train_global_steps' in checkpoint and 'valid_global_steps' in checkpoint: + writer_dict['train_global_steps'] = checkpoint['train_global_steps'] + writer_dict['valid_global_steps'] = checkpoint['valid_global_steps'] + lr = checkpoint['lr'] + if semi_supervised: + print("Not Implement semi_supervised version for DDP") + raise NotImplementedError + # model_traj_train.load_state_dict(checkpoint['model_traj']) + # model_traj.load_state_dict(checkpoint['model_traj']) + # semi_generator.set_random_state(checkpoint['random_state_semi']) + + logger.info('** Note: reported losses are averaged over all frames and test-time augmentation is not used here.') + logger.info('** The final evaluation will be carried out after the last training epoch.') + + myend = time() + mytime = AverageMeter() + best_valid = 50.0 + prof_flag = args.prof + while epoch < args.epochs: + start_time = time() + epoch_loss = AverageMeter() + epoch_loss_val = AverageMeter() + train_generator.set_epoch(epoch) + epoch_loss_3d_train = 0 + # epoch_loss_traj_train = 0 + # epoch_loss_2d_train_unlabeled = 0 + epoch_fps = AverageMeter() + N = 0 + N_semi = 0 + model_pos_train.train() + if semi_supervised: + print("Not Implement semi_supervised version for DDP") + raise NotImplementedError + else: + # Regular supervised scenario + count = 0 + for _, batch_3d, batch_2d in train_generator.next_epoch(): + if count >= 2: + my_epoch_start = time() + if batch_2d.shape[0] == 0: + continue + # print(f"batch_3d.shape:{batch_3d.shape} for rank:{args.rank}") + bz = batch_2d.shape[0] + assert batch_3d.shape[0] == bz + inputs_3d = torch.from_numpy(batch_3d.astype('float32')) + inputs_2d = torch.from_numpy(batch_2d.astype('float32')) + if torch.npu.is_available(): + inputs_3d = inputs_3d.to(loc, non_blocking=False) + inputs_2d = inputs_2d.to(loc, non_blocking=False) + inputs_3d[:, :, 0] = 0 + + if prof_flag and count==10 and args.rank==0: + with torch.autograd.profiler.profile(use_npu=True) as prof: + optimizer.zero_grad() + + # Predict 3D poses + predicted_3d_pos = model_pos_train(inputs_2d) + loss_3d_pos = mpjpe(predicted_3d_pos, inputs_3d) + + loss_total = loss_3d_pos + if args.apex: + with amp.scale_loss(loss_total, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss_total.backward() + + optimizer.step() + print(prof.key_averages().table(sort_by='self_cpu_time_total')) + prof.export_chrome_trace(os.path.join(args.checkpoint,'out.prof')) + prof_flag = False + print(f"prof has been saved as {os.path.join(args.checkpoint,'out.prof')}") + else: + optimizer.zero_grad() + + # Predict 3D poses + predicted_3d_pos = model_pos_train(inputs_2d) + loss_3d_pos = mpjpe(predicted_3d_pos, inputs_3d) + + loss_total = loss_3d_pos + if args.apex: + with amp.scale_loss(loss_total, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss_total.backward() + + optimizer.step() + + dist.all_reduce(loss_total) + loss_total = loss_total / ngpus_per_node + epoch_loss.update(loss_total.item(), bz) + + epoch_loss_3d_train += inputs_3d.shape[0]*inputs_3d.shape[1] * loss_total.item() + N += inputs_3d.shape[0]*inputs_3d.shape[1] + + if count >= 2: + batch_time = time()-my_epoch_start + fps = bz * ngpus_per_node / batch_time + epoch_fps.update(fps) + if args.rank % ngpus_per_node == 0: + writer = writer_dict['writer'] + train_step = writer_dict['train_global_steps'] + writer.add_scalar('total_loss',epoch_loss.avg,train_step) + writer_dict['train_global_steps'] = train_step + 1 + + + if count % args.print_freq == 0 and args.rank % ngpus_per_node == 0: + logger.info("({batch}/{size})| loss:{loss.val:.5f} ({loss.avg:.5f})| FPS:{fps.val:.3f} ({fps.avg:.3f})".format( + batch=count, size=math.ceil(train_generator.num_frames()/(args.batch_size*ngpus_per_node)), loss=epoch_loss, + fps=epoch_fps + )) + count +=1 + if args.rank % ngpus_per_node == 0: + writer.add_scalar('loss_3d/train', epoch_loss_3d_train / N, epoch) + + losses_3d_train.append(epoch_loss_3d_train / N) + + + # End-of-epoch evaluation + if args.rank == 0 and not args.no_eval: + print("End of epoch evaluation start ....") + with torch.no_grad(): + model_pos.load_state_dict(model_pos_train.state_dict()) + model_pos.eval() + if semi_supervised: + print("Not Implement semi_supervised version for DDP") + raise NotImplementedError + # model_traj.load_state_dict(model_traj_train.state_dict()) + # model_traj.eval() + + epoch_loss_3d_valid = 0 + epoch_loss_traj_valid = 0 + epoch_loss_2d_valid = 0 + N = 0 + + if not args.no_eval: + # Evaluate on test set + for cam, batch, batch_2d in test_generator.next_epoch(): + inputs_3d = torch.from_numpy(batch.astype('float32')) + inputs_2d = torch.from_numpy(batch_2d.astype('float32')) + if torch.npu.is_available(): + inputs_3d = inputs_3d.to(loc, non_blocking=False) + inputs_2d = inputs_2d.to(loc, non_blocking=False) + inputs_traj = inputs_3d[:, :, :1].clone() + inputs_3d[:, :, 0] = 0 + + # Predict 3D poses + predicted_3d_pos = model_pos(inputs_2d) + loss_3d_pos = mpjpe(predicted_3d_pos, inputs_3d) + + bz = inputs_2d.shape[0] + assert bz == inputs_3d.shape[0] + + dist.all_reduce(loss_3d_pos) + loss_3d_pos = loss_3d_pos / ngpus_per_node + + epoch_loss_val.update(loss_3d_pos, bz) + + epoch_loss_3d_valid += inputs_3d.shape[0]*inputs_3d.shape[1] * loss_3d_pos.item() + N += inputs_3d.shape[0]*inputs_3d.shape[1] + + if args.rank % ngpus_per_node == 0: + val_step = writer_dict['valid_global_steps'] + writer.add_scalar("val_loss",epoch_loss_val.avg, val_step) + writer_dict['valid_global_steps'] = val_step + 1 + if semi_supervised: + print("Not Implement semi_supervised version for DDP") + raise NotImplementedError + if args.rank % ngpus_per_node == 0: + writer.add_scalar("loss_3d/valid", epoch_loss_3d_valid / N, epoch) + print("out of end-of-epoch evaluation loop.") + losses_3d_valid.append(epoch_loss_3d_valid / N) + if semi_supervised: + print("Not Implement semi_supervised version for DDP") + raise NotImplementedError + # losses_traj_valid.append(epoch_loss_traj_valid / N) + # losses_2d_valid.append(epoch_loss_2d_valid / N) + + + # Evaluate on training set, this time in evaluation mode + epoch_loss_3d_train_eval = 0 + # epoch_loss_traj_train_eval = 0 + # epoch_loss_2d_train_labeled_eval = 0 + N = 0 + for cam, batch, batch_2d in train_generator_eval.next_epoch(): + if batch_2d.shape[1] == 0: + # This can only happen when downsampling the dataset + continue + + inputs_3d = torch.from_numpy(batch.astype('float32')) + inputs_2d = torch.from_numpy(batch_2d.astype('float32')) + if torch.npu.is_available(): + inputs_3d = inputs_3d.npu() + inputs_2d = inputs_2d.npu() + inputs_traj = inputs_3d[:, :, :1].clone() + inputs_3d[:, :, 0] = 0 + + # Compute 3D poses + predicted_3d_pos = model_pos(inputs_2d) + loss_3d_pos = mpjpe(predicted_3d_pos, inputs_3d) + + dist.all_reduce(loss_3d_pos) + loss_3d_pos = loss_3d_pos / ngpus_per_node + epoch_loss_3d_train_eval += inputs_3d.shape[0]*inputs_3d.shape[1] * loss_3d_pos.item() + N += inputs_3d.shape[0]*inputs_3d.shape[1] + + if semi_supervised: + print("Not Implement semi_supervised version for DDP") + raise NotImplementedError + + if args.rank % ngpus_per_node == 0: + writer.add_scalar('loss_3d/train_eval', epoch_loss_3d_train_eval / N, epoch) + losses_3d_train_eval.append(epoch_loss_3d_train_eval / N) + if semi_supervised: + print("Not Implement semi_supervised version for DDP") + raise NotImplementedError + # losses_traj_train_eval.append(epoch_loss_traj_train_eval / N) + # losses_2d_train_labeled_eval.append(epoch_loss_2d_train_labeled_eval / N) + + # Evaluate 2D loss on unlabeled training set (in evaluation mode) + epoch_loss_2d_train_unlabeled_eval = 0 + N_semi = 0 + if semi_supervised: + print("Not Implement semi_supervised version for DDP") + raise NotImplementedError + + elapsed = (time() - start_time)/60 + + if args.rank % ngpus_per_node == 0: + if args.no_eval: + logger.info('[%d] time %.2f lr %f 3d_train %f FPS %d' % ( + epoch + 1, + elapsed, + lr, + losses_3d_train[-1] * 1000, + int(epoch_fps.avg))) + else: + if semi_supervised: + print("Not Implement semi_supervised version for DDP") + raise NotImplementedError + else: + logger.info('[%d] time %.2f lr %f 3d_train %f 3d_eval %f 3d_valid %f FPS %d' % ( + epoch + 1, + elapsed, + lr, + losses_3d_train[-1] * 1000, + losses_3d_train_eval[-1] * 1000, + losses_3d_valid[-1] *1000, + int(epoch_fps.avg)) + ) + + # Decay learning rate exponentially + lr *= lr_decay + for param_group in optimizer.param_groups: + param_group['lr'] *= lr_decay + epoch += 1 + + # Decay BatchNorm momentum + momentum = initial_momentum * np.exp(-epoch/args.epochs * np.log(initial_momentum/final_momentum)) + model_pos_train.module.set_bn_momentum(momentum) + if semi_supervised: + print("Not Implement semi_supervised version for DDP") + raise NotImplementedError + # model_traj_train.set_bn_momentum(momentum) + + # Save best valid + if args.no_eval: + valid = 0 + else: + valid = losses_3d_valid[-1] *1000 + if args.rank % ngpus_per_node == 0 and valid < best_valid: + best_valid = valid + bst_path = os.path.join(args.checkpoint, 'model_best.bin') + logger.info(f'Saving best model up to epoch:{epoch} to {bst_path}') + torch.save({ + 'model_pos':model_pos_train.state_dict() + }, bst_path) + + # Save checkpoint if necessary + if epoch % args.checkpoint_frequency == 0 and args.rank % ngpus_per_node == 0: + chk_path = os.path.join(args.checkpoint, 'epoch_{}.bin'.format(epoch)) + logger.info(f'Saving checkpoint to {chk_path}') + + torch.save({ + 'epoch': epoch, + 'lr': lr, + # 'random_state': train_generator.random_state(), + 'optimizer': optimizer.state_dict(), + 'model_pos': model_pos_train.state_dict(), + # 'model_traj': None, # model_traj_train.state_dict() if semi_supervised else None, + 'amp': amp.state_dict() if args.apex else None, + 'random_state_semi': None, #semi_generator.random_state() if semi_supervised else None, + 'train_global_steps': writer_dict['train_global_steps'], + 'valid_global_steps': writer_dict['valid_global_steps'] + }, chk_path) + + + # Save training curves after every epoch, as .png images (if requested) + if args.export_training_curves and epoch > 3 and args.rank % ngpus_per_node == 0: + if 'matplotlib' not in sys.modules: + import matplotlib + matplotlib.use('Agg') + import matplotlib.pyplot as plt + + plt.figure() + epoch_x = np.arange(3, len(losses_3d_train)) + 1 + plt.plot(epoch_x, losses_3d_train[3:], '--', color='C0') + plt.plot(epoch_x, losses_3d_train_eval[3:], color='C0') + plt.plot(epoch_x, losses_3d_valid[3:], color='C1') + plt.legend(['3d train', '3d train (eval)', '3d valid (eval)']) + plt.ylabel('MPJPE (m)') + plt.xlabel('Epoch') + plt.xlim((3, epoch)) + plt.savefig(os.path.join(args.checkpoint, 'loss_3d.png')) + + if semi_supervised: + print("Not Implement semi_supervised version for DDP") + raise NotImplementedError + plt.close('all') + + mytime.update(time()-myend) + myend = time() + if args.rank % ngpus_per_node == 0: + print(f"In average, it takes {time_format_convert(mytime.avg)} per epoch.") + print(f"Time has elapsed {time_format_convert(mytime.sum)}") + print(f"It still need {time_format_convert(mytime.avg*(args.epochs-epoch))}") + print("****************************************************************************") + if args.rank % ngpus_per_node == 0: + writer_dict['writer'].close() + # Evaluate + if args.evaluate: + logger.info('Evaluating...') + # chk_filename = os.path.join(args.checkpoint, 'model_best.bin') + # if (not args.evaluate) and (os.path.exists(chk_filename)): + # checkpoint = torch.load(chk_filename, map_location='cpu') + # model_pos.load_state_dict(checkpoint['model_pos']) + all_actions = {} + all_actions_by_subject = {} + for subject in subjects_test: + if subject not in all_actions_by_subject: + all_actions_by_subject[subject] = {} + + for action in dataset[subject].keys(): + action_name = action.split(' ')[0] + if action_name not in all_actions: + all_actions[action_name] = [] + if action_name not in all_actions_by_subject[subject]: + all_actions_by_subject[subject][action_name] = [] + all_actions[action_name].append((subject, action)) + all_actions_by_subject[subject][action_name].append((subject, action)) + + if not args.by_subject: + run_evaluation(args, all_actions, model_pos, None, keypoints, dataset, pad, causal_shift, kps_left, kps_right, joints_left, joints_right, action_filter) + else: + for subject in all_actions_by_subject.keys(): + if args.rank % ngpus_per_node == 0: + print('Evaluating on subject', subject) + run_evaluation(args, all_actions_by_subject[subject], model_pos, None, keypoints, dataset, pad, causal_shift, kps_left, kps_right, joints_left, joints_right, action_filter) + if args.rank % ngpus_per_node == 0: + print('') + dist.destroy_process_group() + +if __name__ == "__main__": + main() diff --git a/PyTorch/contrib/cv/video/VideoPose3D/test/eval_full_8p.sh b/PyTorch/contrib/cv/video/VideoPose3D/test/eval_full_8p.sh index bd38f9fdc596b024a9e50ac3e572a6172d991f40..5c6235ba8cc8e175e26a20b31e75aa0d1506f815 100644 --- a/PyTorch/contrib/cv/video/VideoPose3D/test/eval_full_8p.sh +++ b/PyTorch/contrib/cv/video/VideoPose3D/test/eval_full_8p.sh @@ -1,100 +1,100 @@ -#!/bin/sh - -source /usr/local/Ascend/ascend-toolkit/set_env.sh -export HCCL_WHITELIST_DISABLE=1 -export ASCEND_SLOG_PRINT_TO_STDOUT=1 -export ASCEND_GLOBAL_LOG_LEVEL=3 -export ASCEND_GLOBAL_EVENT_ENABLE=0 -export PTCOPY_ENABLE=1 - -################ Basic Training Settings ################## -# "Must Have" Settings: Network batch_size RANK_SIZE -# Network Name, the same with dir -Network="VideoPose3D" -# training batch_size per GPU -batch_size=8192 -# num of NPUs -export RANK_SIZE=8 -# train epochs -# train_epochs=80 - -############# Specify Training Directory ############# -cur_path=`pwd` -cur_path_last_diename=${cur_path##*/} -if [ x"${cur_path_last_diename}" == x"test" ];then - test_path_dir=${cur_path} - cd .. - cur_path=`pwd` -else - test_path_dir=${cur_path}/test -fi - -############# Create Log output directory ############## -ASCEND_DEVICE_ID=0 -if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -else - mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID -fi - -#################### Start Training ################# -# start time, no modification needed -start_time=$(date +%s) - -python run.py \ - -k cpn_ft_h36m_dbb \ - -arc 3,3,3,3,3 \ - -c checkpoint/8p_lr2.2e-3 \ - -o test/output/8p_lr2.2e-3_eval \ - --evaluate model_best.bin & -wait - -################# Gain Training Data #################### -# end training time, no modification needed -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -# print results, no modification needed -echo "------------------ Final result ------------------" -# output FPS -FPS=`grep -a 'FPS' ${test_path_dir}/output/8p_lr2.2e-3/train_rank0.log|awk -F " " '{print $15}'|awk 'END {print}'` -# print -echo "Final Performance images/sec : $FPS" - -# train-accuracy -acc=`grep -a 'Protocol #1' ${test_path_dir}/output/8p_lr2.2e-3_eval/train_rank0.log|awk 'END {print}'|awk -F " " '{print $7}'` -# print -echo "Final Train Accuracy (mm) : ${acc:8:5}" -echo "E2E Eval Duration sec : $e2e_time" -train_accuracy=${acc:8:5} - -# Performance Summary -# Train-related information, no modification needed -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -## Acquire performance data -# Throughput -ActualFPS=${FPS} -# time of single loop -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -# Extract loss to train_${CaseName}_loss.txt -grep -a 'FPS' ${test_path_dir}/output/8p_lr2.2e-3/train_rank0.log|awk -F " " '{print $3,$4,$5}'|awk -F "loss:" '{print $NF}'|awk -F "time" '{print $1}'|awk -F "(" '{print $NF}'|awk -F ")" '{print $1}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -# loss from the last loop -ActualLoss=`awk -F: '{if($1!="[80] ")print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt|awk 'END {print}'` - -# Key information print -echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/sh + +source /usr/local/Ascend/ascend-toolkit/set_env.sh +export HCCL_WHITELIST_DISABLE=1 +export ASCEND_SLOG_PRINT_TO_STDOUT=1 +export ASCEND_GLOBAL_LOG_LEVEL=3 +export ASCEND_GLOBAL_EVENT_ENABLE=0 +export PTCOPY_ENABLE=1 + +################ Basic Training Settings ################## +# "Must Have" Settings: Network batch_size RANK_SIZE +# Network Name, the same with dir +Network="VideoPose3D" +# training batch_size per GPU +batch_size=8192 +# num of NPUs +export RANK_SIZE=8 +# train epochs +# train_epochs=80 + +############# Specify Training Directory ############# +cur_path=`pwd` +cur_path_last_diename=${cur_path##*/} +if [ x"${cur_path_last_diename}" == x"test" ];then + test_path_dir=${cur_path} + cd .. + cur_path=`pwd` +else + test_path_dir=${cur_path}/test +fi + +############# Create Log output directory ############## +ASCEND_DEVICE_ID=0 +if [ -d ${test_path_dir}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${test_path_dir}/output/${ASCEND_DEVICE_ID} + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +else + mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID +fi + +#################### Start Training ################# +# start time, no modification needed +start_time=$(date +%s) + +python run.py \ + -k cpn_ft_h36m_dbb \ + -arc 3,3,3,3,3 \ + -c checkpoint/8p_lr2.2e-3 \ + -o test/output/8p_lr2.2e-3_eval \ + --evaluate model_best.bin & +wait + +################# Gain Training Data #################### +# end training time, no modification needed +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +# print results, no modification needed +echo "------------------ Final result ------------------" +# output FPS +FPS=`grep -a 'FPS' ${test_path_dir}/output/8p_lr2.2e-3/train_rank0.log|awk -F " " '{print $15}'|awk 'END {print}'` +# print +echo "Final Performance images/sec : $FPS" + +# train-accuracy +acc=`grep -a 'Protocol #1' ${test_path_dir}/output/8p_lr2.2e-3_eval/train_rank0.log|awk 'END {print}'|awk -F " " '{print $7}'` +# print +echo "Final Train Accuracy (mm) : ${acc:8:5}" +echo "E2E Eval Duration sec : $e2e_time" +train_accuracy=${acc:8:5} + +# Performance Summary +# Train-related information, no modification needed +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +## Acquire performance data +# Throughput +ActualFPS=${FPS} +# time of single loop +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +# Extract loss to train_${CaseName}_loss.txt +grep -a 'FPS' ${test_path_dir}/output/8p_lr2.2e-3/train_rank0.log|awk -F " " '{print $3,$4,$5}'|awk -F "loss:" '{print $NF}'|awk -F "time" '{print $1}'|awk -F "(" '{print $NF}'|awk -F ")" '{print $1}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +# loss from the last loop +ActualLoss=`awk -F: '{if($1!="[80] ")print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt|awk 'END {print}'` + +# Key information print +echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log # echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/contrib/cv/video/X3D/README.md b/PyTorch/contrib/cv/video/X3D/README.md index 6c0dcffc318ef886e076dc3d806a8c15c413dba0..8e3949ec65bac43d667c40d0abc6c83b4da3de5d 100644 --- a/PyTorch/contrib/cv/video/X3D/README.md +++ b/PyTorch/contrib/cv/video/X3D/README.md @@ -1,212 +1,212 @@ -# X3D-S - -Implements training of X3D-S on the Kinetics-400 dataset - -## Detail - -Most of codes are modified according to [here](https://gitee.com/ascend/modelzoo/wikis/Pytorch%E8%AE%AD%E7%BB%83%E6%8C%87%E5%AF%BC?sort_id=4208869#21-%E8%BF%81%E7%A7%BB%E6%B5%81%E7%A8%8B%E8%AF%B4%E6%98%8E) - -There are some special modification of [source repository](https://github.com/facebookresearch/SlowFast) : - -##### NPU & GPU - -- Add some customized yaml configuration items, such as APEX.ENABLE、DIST_BACKEND... -- Ascend-Pytorch-1.5 is not supported `torch.nn.init.trunc_normal` , using `torch.nn.init.normal_` instead -- Adjusted the order of dependency import to prevent some unknown bugs (`scikit-learn`) - -##### NPU - -- Group conv3D of Ascend-Pytorch is not supported, so we canceled all group operations in the model -- Remove some irrelevant codes to prevent some unknown bugs (`Segmentation fault (core dumped)`) - - -## Requirements - -##### Base Environment - -- Python == 3.7.5 -- GCC >= 4.9 - -##### Python Environment - -1. Installing these error-prone dependencies first: - -- PyTorch (raw==1.5 or ascend) - - Ascend-Pytorch Version after August 24 be installed -- torchvision == 0.6.0 - - If on Centos arm, please build the source code from [here](https://gitee.com/azureology/torchvision/tree/v0.6.0/) -- PyAV - - If the installation fails on Centos arm, following this [issue](https://gitee.com/ascend/modelzoo/issues/I48AP3?from=project-issue) -- Detectron2 - - According to the CUDA version and Pytorch version, build from [source code](https://github.com/facebookresearch/detectron2) - -2. Then, you can use `pip3 install -r requirements.txt` to install some simple dependencies - - - -3. Building source code - -```shell -cd X3D # into source code root - -# Switch to your prepared environment - -python3.7 setup.py build develop # build slowfast and install the remaining dependencies -``` - - - -##### Modify Ascend-tookit - -```shell -cd /usr/local -find / -name fractal_z_3d_2_ncdhw.py -vi path_to_fractal_z_3d_2_ncdhw.py - -located method: - 1. def fractal_z_3d_2_ncdhw(src, dst, src_format, dst_format,kernel_name="fractal_z_3d_2_ncdhw") - 2. modify it according this picture: - 2.1. remove `if list(dst_shape) in ....` - 2.2. Align the next two lines like this -``` - -![image-20210909203603647](meta\bug-opt.png) - - - -##### Dataset - -- Download the Kinetics-400 dataset from [here](https://github.com/PaddlePaddle/PaddleVideo/blob/develop/docs/zh-CN/dataset/k400.md) - - 1. unzip the all packages and merge all folders - - 2. we get two sets , train set (used to train) and val set (used to test). And each of both has 400 folders - - ```markdown - # format of data folder - - |-data - |-train - |- video type 1 - |- video 1 - |- video 2 - ... - |- video type 2 - ... - |- video type 400 - |-val - |- video type 1 - |- video type 2 - ... - |- video type 400 - ``` - - - - 3. build train.csv, val.csv, test.csv, and put them in the same folder - - ```markdown - # format of data path folder - |- data_path - |- train.csv - |- val.csv - |- test.csv - ``` - - train.csv consists of train set - - val.csv is same as test.csv, and consists of test set - - ```markdown - # format of data path csv is: - - path_to_video_1 label_1 - path_to_video_2 label_2 - ... - path_to_video_N label_N - ``` - - 4. check if the all videos are lossless according to the scripts provided by project [mmaction2](https://github.com/open-mmlab/mmaction2) . Here, we provide the [list](mytest\Vinput\error_video) of corrupted videos that have been checked out -5. remove the those corrupted videos from the three csv - -## Training - -To train a model, run `main.py` with the desired model architecture and the path to the ImageNet dataset: - -> Note:the `real_data_path` is path of csv folder mentioned above - -```bash -# training 1p (300 epoch) -bash ./test/train_full_1p.sh --data_path=real_data_path - -# training 8p (300 epoch) -bash ./test/train_full_8p.sh --data_path=real_data_path - -# training performance 1p (1 epoch) -bash ./test/train_performance_1p.sh --data_path=real_data_path - -# training performance 8p (3 epoch) -bash ./test/train_performance_8p.sh --data_path=real_data_path - -# testing 8p -bash test/train_eval_8p.sh --data_path=real_data_path --pth_path=real_pre_train_model_path - -# train_finetune_1p.sh -bash test/train_finetune_1p.sh --data_path=real_data_path --pth_path=real_pre_train_model_path --num_classes=default_400 -``` - -> Log path: ./stdout.log - - - -## Training Result - -> Due to the calculation cast a long time, we choose to run the full data, and the NPU-ACC is aligned with the GPU-ACC (as many epochs as possible). - - -| Device | FPS | Top1-ACC 10-view | Batch Size | Epochs | AMP | -| :-------------: | :-----: | :--------------: | :--------: | :----: | :------: | -| 1P-GPU | 10.39 | 6.67% | 96 | 1/300 | O2-128.0 | -| 1P-NPU | 5.38 | 6.18% | 96 | 1/300 | O2-128.0 | -| 1P-NPU-白名单 | 5.35 | 6.36% | 96 | 1/300 | O2-128.0 | -| 8P-GPU | 1137.49 | 37.56% | 256 | 30/300 | O2-128.0 | -| 8P-NPU | 529.24 | 39.67% | 256 | 30/300 | O2-128.0 | -| 8P-NPU-fusedSGD | 510.66 | 5.80% | 256 | 2/300 | O2-128.0 | - - - -- Testing result: Top1-ACC of 8P-NPU and 8P-GPU training (30 epochs) - -![img](meta\8P-GPU & 8P-NPU.png) - -## Performance Optimization - -According to the above, it can be concluded that the accuracy(Top1-ACC 10-view) of 8P-GPU and 8P-NPU is little different. But performance(FPS) of 8P-NPU is 50% of 8P-GPU's. - -So we made the following analysis and improvement: - -- find the dynamic operators following [here](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/blob/master/pytorch-train-guide/%E6%A8%A1%E5%9E%8B%E7%AE%97%E5%AD%90%E6%8F%90%E5%8F%96%E6%8C%87%E5%8D%97.md), but the operators is very basic, and we can not identify them from our big model. - -![img](meta\dynamic_ops.png) - -- check the profile of NPU through chrome tracing - - image-20210913190836215 - -- In order to improve the low perfomance of Transpose, we first generate the `cann profiling` following [here](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/blob/master/pytorch-train-guide/CANNProfiling%E5%B7%A5%E5%85%B7%E4%BD%BF%E7%94%A8%E6%8C%87%E5%AF%BC%E4%B9%A6.md), then we extract the two operators, TransposeD and TransData. - - if TransposeD `Consuming time > 10s`, add its Input Shapes to White List (/usr/local/Ascend/ascend-toolkit/5.0.2/x86_64-linux/opp/op_impl/built-in/ai_core/tbe/impl/dynamic/transpose.py) - - if TransData `Consuming time > 10s & Input Formats == 'NCHW' & Output Formats == 'NC1HWC0'`, add its Input Shapes to White List (/usr/local/Ascend/ascend-toolkit/5.0.2/x86_64-linux/opp/op_impl/built-in/ai_core/tbe/impl/four_2_five.py) - - if TransData `Consuming time > 10s & Input Formats == 'NC1HWC0' & Output Formats == 'NCHW'`, add its Input Shapes to White List (/usr/local/Ascend/ascend-toolkit/5.0.2/x86_64-linux/opp/op_impl/built-in/ai_core/tbe/impl/five_2_four.py) - -**After Optimization** - -![image-20210918103240921](meta\profile-2.png) - -## ELSE - -Iessues and PRs about this project - -- invalid gradient https://gitee.com/ascend/modelzoo/issues/I452ZB https://gitee.com/ascend/pytorch-develop/pulls/2438 -- optimizer error https://gitee.com/ascend/pytorch-develop/pulls/2438 -- pyav install on CentOS arm https://gitee.com/ascend/modelzoo/issues/I48AP3 -- scikit-learn cannot allocate memory in static TLS https://gitee.com/ascend/modelzoo/issues/I48QNY +# X3D-S + +Implements training of X3D-S on the Kinetics-400 dataset + +## Detail + +Most of codes are modified according to [here](https://gitee.com/ascend/modelzoo/wikis/Pytorch%E8%AE%AD%E7%BB%83%E6%8C%87%E5%AF%BC?sort_id=4208869#21-%E8%BF%81%E7%A7%BB%E6%B5%81%E7%A8%8B%E8%AF%B4%E6%98%8E) + +There are some special modification of [source repository](https://github.com/facebookresearch/SlowFast) : + +##### NPU & GPU + +- Add some customized yaml configuration items, such as APEX.ENABLE、DIST_BACKEND... +- Ascend-Pytorch-1.5 is not supported `torch.nn.init.trunc_normal` , using `torch.nn.init.normal_` instead +- Adjusted the order of dependency import to prevent some unknown bugs (`scikit-learn`) + +##### NPU + +- Group conv3D of Ascend-Pytorch is not supported, so we canceled all group operations in the model +- Remove some irrelevant codes to prevent some unknown bugs (`Segmentation fault (core dumped)`) + + +## Requirements + +##### Base Environment + +- Python == 3.7.5 +- GCC >= 4.9 + +##### Python Environment + +1. Installing these error-prone dependencies first: + +- PyTorch (raw==1.5 or ascend) + - Ascend-Pytorch Version after August 24 be installed +- torchvision == 0.6.0 + - If on Centos arm, please build the source code from [here](https://gitee.com/azureology/torchvision/tree/v0.6.0/) +- PyAV + - If the installation fails on Centos arm, following this [issue](https://gitee.com/ascend/modelzoo/issues/I48AP3?from=project-issue) +- Detectron2 + - According to the CUDA version and Pytorch version, build from [source code](https://github.com/facebookresearch/detectron2) + +2. Then, you can use `pip3 install -r requirements.txt` to install some simple dependencies + + + +3. Building source code + +```shell +cd X3D # into source code root + +# Switch to your prepared environment + +python3.7 setup.py build develop # build slowfast and install the remaining dependencies +``` + + + +##### Modify Ascend-tookit + +```shell +cd /usr/local +find / -name fractal_z_3d_2_ncdhw.py +vi path_to_fractal_z_3d_2_ncdhw.py + +located method: + 1. def fractal_z_3d_2_ncdhw(src, dst, src_format, dst_format,kernel_name="fractal_z_3d_2_ncdhw") + 2. modify it according this picture: + 2.1. remove `if list(dst_shape) in ....` + 2.2. Align the next two lines like this +``` + +![image-20210909203603647](meta\bug-opt.png) + + + +##### Dataset + +- Download the Kinetics-400 dataset from [here](https://github.com/PaddlePaddle/PaddleVideo/blob/develop/docs/zh-CN/dataset/k400.md) + + 1. unzip the all packages and merge all folders + + 2. we get two sets , train set (used to train) and val set (used to test). And each of both has 400 folders + + ```markdown + # format of data folder + + |-data + |-train + |- video type 1 + |- video 1 + |- video 2 + ... + |- video type 2 + ... + |- video type 400 + |-val + |- video type 1 + |- video type 2 + ... + |- video type 400 + ``` + + + + 3. build train.csv, val.csv, test.csv, and put them in the same folder + + ```markdown + # format of data path folder + |- data_path + |- train.csv + |- val.csv + |- test.csv + ``` + + train.csv consists of train set + + val.csv is same as test.csv, and consists of test set + + ```markdown + # format of data path csv is: + + path_to_video_1 label_1 + path_to_video_2 label_2 + ... + path_to_video_N label_N + ``` + + 4. check if the all videos are lossless according to the scripts provided by project [mmaction2](https://github.com/open-mmlab/mmaction2) . Here, we provide the [list](mytest\Vinput\error_video) of corrupted videos that have been checked out +5. remove the those corrupted videos from the three csv + +## Training + +To train a model, run `main.py` with the desired model architecture and the path to the ImageNet dataset: + +> Note:the `real_data_path` is path of csv folder mentioned above + +```bash +# training 1p (300 epoch) +bash ./test/train_full_1p.sh --data_path=real_data_path + +# training 8p (300 epoch) +bash ./test/train_full_8p.sh --data_path=real_data_path + +# training performance 1p (1 epoch) +bash ./test/train_performance_1p.sh --data_path=real_data_path + +# training performance 8p (3 epoch) +bash ./test/train_performance_8p.sh --data_path=real_data_path + +# testing 8p +bash test/train_eval_8p.sh --data_path=real_data_path --pth_path=real_pre_train_model_path + +# train_finetune_1p.sh +bash test/train_finetune_1p.sh --data_path=real_data_path --pth_path=real_pre_train_model_path --num_classes=default_400 +``` + +> Log path: ./stdout.log + + + +## Training Result + +> Due to the calculation cast a long time, we choose to run the full data, and the NPU-ACC is aligned with the GPU-ACC (as many epochs as possible). + + +| Device | FPS | Top1-ACC 10-view | Batch Size | Epochs | AMP | +| :-------------: | :-----: | :--------------: | :--------: | :----: | :------: | +| 1P-GPU | 10.39 | 6.67% | 96 | 1/300 | O2-128.0 | +| 1P-NPU | 5.38 | 6.18% | 96 | 1/300 | O2-128.0 | +| 1P-NPU-白名单 | 5.35 | 6.36% | 96 | 1/300 | O2-128.0 | +| 8P-GPU | 1137.49 | 37.56% | 256 | 30/300 | O2-128.0 | +| 8P-NPU | 529.24 | 39.67% | 256 | 30/300 | O2-128.0 | +| 8P-NPU-fusedSGD | 510.66 | 5.80% | 256 | 2/300 | O2-128.0 | + + + +- Testing result: Top1-ACC of 8P-NPU and 8P-GPU training (30 epochs) + +![img](meta\8P-GPU & 8P-NPU.png) + +## Performance Optimization + +According to the above, it can be concluded that the accuracy(Top1-ACC 10-view) of 8P-GPU and 8P-NPU is little different. But performance(FPS) of 8P-NPU is 50% of 8P-GPU's. + +So we made the following analysis and improvement: + +- find the dynamic operators following [here](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/blob/master/pytorch-train-guide/%E6%A8%A1%E5%9E%8B%E7%AE%97%E5%AD%90%E6%8F%90%E5%8F%96%E6%8C%87%E5%8D%97.md), but the operators is very basic, and we can not identify them from our big model. + +![img](meta\dynamic_ops.png) + +- check the profile of NPU through chrome tracing + + image-20210913190836215 + +- In order to improve the low perfomance of Transpose, we first generate the `cann profiling` following [here](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/blob/master/pytorch-train-guide/CANNProfiling%E5%B7%A5%E5%85%B7%E4%BD%BF%E7%94%A8%E6%8C%87%E5%AF%BC%E4%B9%A6.md), then we extract the two operators, TransposeD and TransData. + - if TransposeD `Consuming time > 10s`, add its Input Shapes to White List (/usr/local/Ascend/ascend-toolkit/5.0.2/x86_64-linux/opp/op_impl/built-in/ai_core/tbe/impl/dynamic/transpose.py) + - if TransData `Consuming time > 10s & Input Formats == 'NCHW' & Output Formats == 'NC1HWC0'`, add its Input Shapes to White List (/usr/local/Ascend/ascend-toolkit/5.0.2/x86_64-linux/opp/op_impl/built-in/ai_core/tbe/impl/four_2_five.py) + - if TransData `Consuming time > 10s & Input Formats == 'NC1HWC0' & Output Formats == 'NCHW'`, add its Input Shapes to White List (/usr/local/Ascend/ascend-toolkit/5.0.2/x86_64-linux/opp/op_impl/built-in/ai_core/tbe/impl/five_2_four.py) + +**After Optimization** + +![image-20210918103240921](meta\profile-2.png) + +## ELSE + +Iessues and PRs about this project + +- invalid gradient https://gitee.com/ascend/modelzoo/issues/I452ZB https://gitee.com/ascend/pytorch-develop/pulls/2438 +- optimizer error https://gitee.com/ascend/pytorch-develop/pulls/2438 +- pyav install on CentOS arm https://gitee.com/ascend/modelzoo/issues/I48AP3 +- scikit-learn cannot allocate memory in static TLS https://gitee.com/ascend/modelzoo/issues/I48QNY diff --git a/PyTorch/contrib/cv/video/X3D/slowfast/utils/ava_evaluation/__init__.py b/PyTorch/contrib/cv/video/X3D/slowfast/utils/ava_evaluation/__init__.py index 919b0579077e1ca4dc63cedb7ae3a1a3e0134283..6228b7132697d24157a4052193061e9913f031c4 100644 --- a/PyTorch/contrib/cv/video/X3D/slowfast/utils/ava_evaluation/__init__.py +++ b/PyTorch/contrib/cv/video/X3D/slowfast/utils/ava_evaluation/__init__.py @@ -1,14 +1,14 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ diff --git a/PyTorch/contrib/nlp/Bertsum_for_PyTorch/modelzoo_level.txt b/PyTorch/contrib/nlp/Bertsum_for_PyTorch/modelzoo_level.txt index 0ea38b69c9f5b7594cdb9bec28a2b3a74bf82420..ceafe5b115be8b8b1cc908ab00c3d274b684821e 100644 --- a/PyTorch/contrib/nlp/Bertsum_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/contrib/nlp/Bertsum_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:PERFECT:NOK +FuncStatus:OK +PerfStatus:PERFECT:NOK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/nlp/TextCNN/LICENSE b/PyTorch/contrib/nlp/TextCNN/LICENSE index 185404d5515c393add9ecfbdd7cd83596e8a4b26..5b4cf39445b7b24f2e5d38062c3b9cca89ad8a90 100644 --- a/PyTorch/contrib/nlp/TextCNN/LICENSE +++ b/PyTorch/contrib/nlp/TextCNN/LICENSE @@ -1,204 +1,204 @@ -Copyright 2018-2019 Open-MMLab. All rights reserved. -Copyright 2021 Huawei Technologies Co., Ltd - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2018-2019 Open-MMLab. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Copyright 2018-2019 Open-MMLab. All rights reserved. +Copyright 2021 Huawei Technologies Co., Ltd + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2019 Open-MMLab. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/PyTorch/contrib/nlp/TextCNN/modelzoo_level.txt b/PyTorch/contrib/nlp/TextCNN/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/contrib/nlp/TextCNN/modelzoo_level.txt +++ b/PyTorch/contrib/nlp/TextCNN/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/nlp/tinybert/demo.py b/PyTorch/contrib/nlp/tinybert/demo.py index 2ce50832af94bbf34b70676a500afb33bb607200..3311302206a623f4e3b29a302fab8e30b3d06f40 100644 --- a/PyTorch/contrib/nlp/tinybert/demo.py +++ b/PyTorch/contrib/nlp/tinybert/demo.py @@ -1,89 +1,89 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -"""TinyBERT finetuning runner specifically for SST-2 dataset.""" - -################## import libraries ################## - -#standard libraries -from __future__ import absolute_import, division, print_function -import argparse -import random - -#third-party libraries -import numpy as np -import torch - -#local libraries -from transformer.modeling import TinyBertForSequenceClassification - -################## end import libraries ################## - -def random_int_list(start, stop, length): - start, stop = (int(start), int(stop)) if start <= stop else (int(stop), int(start)) - length = int(abs(length)) if length else 0 - random_list = [] - for i in range(length): - random_list.append(random.randint(start, stop)) - return random_list - -def is_same(a,b,i): - result = (a == b).mean() - if result == 1: - print("step {} = step {}: {}".format(i-1,i,'True')) - else: - print("step {} = step {}: {}".format(i - 1, i, 'False')) - -def main(): - - ################## set args ################## - parser = argparse.ArgumentParser() - - # 1.file and model - parser.add_argument("--model", - default=None, - type=str, - help="The model dir.") - parser.add_argument("--max_seq_length", - default=64, - type=int, - help="The maximum total input sequence length after WordPiece tokenization. \n" - "Sequences longer than this will be truncated, and sequences shorter \n" - "than this will be padded.") - args = parser.parse_args() - - # create model - model = TinyBertForSequenceClassification.from_pretrained(args.model, num_labels=2) - model.eval() - # test - input_ids = torch.tensor(random_int_list(0,9999,args.max_seq_length), dtype=torch.long).view(1,-1) - print(input_ids) - segment_ids = torch.tensor(random_int_list(0,1,args.max_seq_length), dtype=torch.long).view(1,-1) - input_mask = torch.tensor(random_int_list(0,1,args.max_seq_length), dtype=torch.long).view(1,-1) - repeat_time = 20 - for i in range(1,repeat_time+1): - logits, _, _ = model(input_ids, segment_ids, input_mask) - logits = logits.squeeze() - print("step {}, logits = {}".format(i,logits)) - if i == 1: - a = logits - elif i == 2: - b = logits - is_same(a.detach().numpy(),b.detach().numpy(),i) - else: - a = b - b = logits - is_same(a.detach().numpy(),b.detach().numpy(),i) - -if __name__ == "__main__": - main() +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""TinyBERT finetuning runner specifically for SST-2 dataset.""" + +################## import libraries ################## + +#standard libraries +from __future__ import absolute_import, division, print_function +import argparse +import random + +#third-party libraries +import numpy as np +import torch + +#local libraries +from transformer.modeling import TinyBertForSequenceClassification + +################## end import libraries ################## + +def random_int_list(start, stop, length): + start, stop = (int(start), int(stop)) if start <= stop else (int(stop), int(start)) + length = int(abs(length)) if length else 0 + random_list = [] + for i in range(length): + random_list.append(random.randint(start, stop)) + return random_list + +def is_same(a,b,i): + result = (a == b).mean() + if result == 1: + print("step {} = step {}: {}".format(i-1,i,'True')) + else: + print("step {} = step {}: {}".format(i - 1, i, 'False')) + +def main(): + + ################## set args ################## + parser = argparse.ArgumentParser() + + # 1.file and model + parser.add_argument("--model", + default=None, + type=str, + help="The model dir.") + parser.add_argument("--max_seq_length", + default=64, + type=int, + help="The maximum total input sequence length after WordPiece tokenization. \n" + "Sequences longer than this will be truncated, and sequences shorter \n" + "than this will be padded.") + args = parser.parse_args() + + # create model + model = TinyBertForSequenceClassification.from_pretrained(args.model, num_labels=2) + model.eval() + # test + input_ids = torch.tensor(random_int_list(0,9999,args.max_seq_length), dtype=torch.long).view(1,-1) + print(input_ids) + segment_ids = torch.tensor(random_int_list(0,1,args.max_seq_length), dtype=torch.long).view(1,-1) + input_mask = torch.tensor(random_int_list(0,1,args.max_seq_length), dtype=torch.long).view(1,-1) + repeat_time = 20 + for i in range(1,repeat_time+1): + logits, _, _ = model(input_ids, segment_ids, input_mask) + logits = logits.squeeze() + print("step {}, logits = {}".format(i,logits)) + if i == 1: + a = logits + elif i == 2: + b = logits + is_same(a.detach().numpy(),b.detach().numpy(),i) + else: + a = b + b = logits + is_same(a.detach().numpy(),b.detach().numpy(),i) + +if __name__ == "__main__": + main() diff --git a/PyTorch/contrib/nlp/tinybert/modelzoo_level.txt b/PyTorch/contrib/nlp/tinybert/modelzoo_level.txt index 66713332410061acecd3de873bf802dc52a017c4..c33e5e547967cbd6ca4ea0e4e5a2ee2f54150268 100644 --- a/PyTorch/contrib/nlp/tinybert/modelzoo_level.txt +++ b/PyTorch/contrib/nlp/tinybert/modelzoo_level.txt @@ -1,6 +1,6 @@ -FuncStatus:OK -PerfStatus:NOK -PrecisionStatus:OK -GPUStatus:OK -AutoTune:POK +FuncStatus:OK +PerfStatus:NOK +PrecisionStatus:OK +GPUStatus:OK +AutoTune:POK NPUMigrationStatus:OK \ No newline at end of file diff --git a/PyTorch/contrib/nlp/tinybert/transformer/modeling_for_finetune.py b/PyTorch/contrib/nlp/tinybert/transformer/modeling_for_finetune.py index d3f480d2ee257550698493bc541a87ceba3d4d52..8a0204692c6b9073f1eb82520c40633c834acf84 100644 --- a/PyTorch/contrib/nlp/tinybert/transformer/modeling_for_finetune.py +++ b/PyTorch/contrib/nlp/tinybert/transformer/modeling_for_finetune.py @@ -1,1144 +1,1144 @@ -# coding=utf-8 -# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. -# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -"""PyTorch BERT model.""" - -from __future__ import absolute_import, division, print_function, unicode_literals - -import copy -import json -import logging -import math -import os -import shutil -import tarfile -import tempfile -import sys -from io import open - -import torch -import torch.nn.functional as F -from torch import nn -from torch.nn import CrossEntropyLoss -from torch.autograd import Variable -from torch.nn.parameter import Parameter - -from .file_utils import WEIGHTS_NAME, CONFIG_NAME - -logger = logging.getLogger(__name__) - -PRETRAINED_MODEL_ARCHIVE_MAP = { - 'bert-base-uncased': "https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-uncased.tar.gz", - 'bert-large-uncased': "https://s3.amazonaws.com/models.huggingface.co/bert/bert-large-uncased.tar.gz", - 'bert-base-cased': "https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-cased.tar.gz", - 'bert-large-cased': "https://s3.amazonaws.com/models.huggingface.co/bert/bert-large-cased.tar.gz", - 'bert-base-multilingual-uncased': "https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-multilingual-uncased.tar.gz", - 'bert-base-multilingual-cased': "https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-multilingual-cased.tar.gz", - 'bert-base-chinese': "", -} - -BERT_CONFIG_NAME = 'bert_config.json' -TF_WEIGHTS_NAME = 'model.ckpt' - - -def load_tf_weights_in_bert(model, tf_checkpoint_path): - """ Load tf checkpoints in a pytorch model - """ - try: - import re - import numpy as np - import tensorflow as tf - except ImportError: - print("Loading a TensorFlow models in PyTorch, requires TensorFlow to be installed. Please see " - "https://www.tensorflow.org/install/ for installation instructions.") - raise - tf_path = os.path.abspath(tf_checkpoint_path) - print("Converting TensorFlow checkpoint from {}".format(tf_path)) - # Load weights from TF model - init_vars = tf.train.list_variables(tf_path) - names = [] - arrays = [] - for name, shape in init_vars: - print("Loading TF weight {} with shape {}".format(name, shape)) - array = tf.train.load_variable(tf_path, name) - names.append(name) - arrays.append(array) - - for name, array in zip(names, arrays): - name = name.split('/') - # adam_v and adam_m are variables used in AdamWeightDecayOptimizer to calculated m and v - # which are not required for using pretrained model - if any(n in ["adam_v", "adam_m", "global_step"] for n in name): - print("Skipping {}".format("/".join(name))) - continue - pointer = model - for m_name in name: - if re.fullmatch(r'[A-Za-z]+_\d+', m_name): - l = re.split(r'_(\d+)', m_name) - else: - l = [m_name] - if l[0] == 'kernel' or l[0] == 'gamma': - pointer = getattr(pointer, 'weight') - elif l[0] == 'output_bias' or l[0] == 'beta': - try: - pointer = getattr(pointer, 'bias') - except AttributeError: - print("Skipping {}".format("/".join(name))) - continue - elif l[0] == 'output_weights': - pointer = getattr(pointer, 'weight') - elif l[0] == 'squad': - pointer = getattr(pointer, 'classifier') - else: - try: - pointer = getattr(pointer, l[0]) - except AttributeError: - print("Skipping {}".format("/".join(name))) - continue - if len(l) >= 2: - num = int(l[1]) - pointer = pointer[num] - if m_name[-11:] == '_embeddings': - pointer = getattr(pointer, 'weight') - elif m_name == 'kernel': - array = np.transpose(array) - try: - assert pointer.shape == array.shape - except AssertionError as e: - e.args += (pointer.shape, array.shape) - raise - print("Initialize PyTorch weight {}".format(name)) - pointer.data = torch.from_numpy(array) - return model - - -def gelu(x): - """Implementation of the gelu activation function. - For information: OpenAI GPT's gelu is slightly different (and gives slightly different results): - 0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) - Also see https://arxiv.org/abs/1606.08415 - """ - return x * 0.5 * (1.0 + torch.erf(x / math.sqrt(2.0))) - - -def swish(x): - return x * torch.sigmoid(x) - -''' - -try: - from apex.normalization.fused_layer_norm import FusedLayerNorm as BertLayerNorm -except ImportError: - logger.info( - "Better speed can be achieved with apex installed from https://www.github.com/nvidia/apex .") -''' -class BertLayerNorm(nn.Module): - def __init__(self, hidden_size, eps=1e-12): - """Construct a layernorm module in the TF style (epsilon inside the square root). - """ - super(BertLayerNorm, self).__init__() - self.weight = nn.Parameter(torch.ones(hidden_size)) - self.bias = nn.Parameter(torch.zeros(hidden_size)) - self.variance_epsilon = eps - - def forward(self, x): - u = x.mean(-1, keepdim=True) - s = (x - u).pow(2).mean(-1, keepdim=True) - x = (x - u) / torch.sqrt(s + self.variance_epsilon) - return self.weight * x + self.bias - - -class HeadAttention(nn.Module): - def __init__(self, config, hidden_size, head_num, head_used): - super(HeadAttention, self).__init__() - self.head_num = head_num - self.head_used = head_used - self.hidden_size = hidden_size - if self.hidden_size % self.head_num != 0: - raise ValueError( - "The hidden size (%d) is not a multiple of the number of attention " - "heads (%d)" % (self.hidden_size, self.head_num)) - - self.attention_head_size = int(self.hidden_size / self.head_num) - self.all_head_size = self.num_heads_used * self.attention_head_size - - self.query = nn.Linear(self.hidden_size, self.all_head_size) - self.key = nn.Linear(self.hidden_size, self.all_head_size) - self.value = nn.Linear(self.hidden_size, self.all_head_size) - - self.dropout = nn.Dropout(config.attention_probs_dropout_prob) - - def transpose_for_scores(self, x): - new_x_shape = x.size()[:-1] + (self.num_heads_used, - self.attention_head_size) - x = x.view(*new_x_shape) - return x.permute(0, 2, 1, 3) - - def forward(self, hidden_states, attention_mask): - mixed_query_layer = self.query(hidden_states) - mixed_key_layer = self.key(hidden_states) - mixed_value_layer = self.value(hidden_states) - - query_layer = self.transpose_for_scores(mixed_query_layer) - key_layer = self.transpose_for_scores(mixed_key_layer) - value_layer = self.transpose_for_scores(mixed_value_layer) - - # Take the dot product between "query" and "key" to get the raw attention scores. - attention_scores = torch.matmul( - query_layer, key_layer.transpose(-1, -2)) - attention_scores = attention_scores / \ - math.sqrt(self.attention_head_size) - # Apply the attention mask is (precomputed for all layers in BertModel forward() function) - attention_scores = attention_scores + attention_mask - - # Normalize the attention scores to probabilities. - attention_probs = nn.Softmax(dim=-1)(attention_scores) - - # This is actually dropping out entire tokens to attend to, which might - # seem a bit unusual, but is taken from the original Transformer paper. - attention_probs = self.dropout(attention_probs) - - context_layer = torch.matmul(attention_probs, value_layer) - context_layer = context_layer.permute(0, 2, 1, 3).contiguous() - new_context_layer_shape = context_layer.size()[ - :-2] + (self.all_head_size,) - context_layer = context_layer.view(*new_context_layer_shape) - - if self.num_heads_used != self.num_attention_heads: - pad_shape = context_layer.size()[:-1] + \ - ((self.num_attention_heads - self.num_heads_used) - * self.attention_head_size, ) - - pad_layer = torch.zeros(*pad_shape).to(context_layer.device) - context_layer = torch.cat((context_layer, pad_layer), -1) - return context_layer - - -ACT2FN = {"gelu": gelu, "relu": torch.nn.functional.relu} -NORM = {'layer_norm': BertLayerNorm} - - -class BertConfig(object): - """Configuration class to store the configuration of a `BertModel`. - """ - - def __init__(self, - vocab_size_or_config_json_file, - hidden_size=768, - num_hidden_layers=12, - num_attention_heads=12, - intermediate_size=3072, - hidden_act="gelu", - hidden_dropout_prob=0.1, - attention_probs_dropout_prob=0.1, - max_position_embeddings=512, - type_vocab_size=2, - initializer_range=0.02, - pre_trained='', - training=''): - """Constructs BertConfig. - - Args: - vocab_size_or_config_json_file: Vocabulary size of `inputs_ids` in `BertModel`. - hidden_size: Size of the encoder layers and the pooler layer. - num_hidden_layers: Number of hidden layers in the Transformer encoder. - num_attention_heads: Number of attention heads for each attention layer in - the Transformer encoder. - intermediate_size: The size of the "intermediate" (i.e., feed-forward) - layer in the Transformer encoder. - hidden_act: The non-linear activation function (function or string) in the - encoder and pooler. If string, "gelu", "relu" and "swish" are supported. - hidden_dropout_prob: The dropout probabilitiy for all fully connected - layers in the embeddings, encoder, and pooler. - attention_probs_dropout_prob: The dropout ratio for the attention - probabilities. - max_position_embeddings: The maximum sequence length that this model might - ever be used with. Typically set this to something large just in case - (e.g., 512 or 1024 or 2048). - type_vocab_size: The vocabulary size of the `token_type_ids` passed into - `BertModel`. - initializer_range: The sttdev of the truncated_normal_initializer for - initializing all weight matrices. - """ - if isinstance(vocab_size_or_config_json_file, str) or (sys.version_info[0] == 2 - and isinstance(vocab_size_or_config_json_file, unicode)): - with open(vocab_size_or_config_json_file, "r", encoding='utf-8') as reader: - json_config = json.loads(reader.read()) - for key, value in json_config.items(): - self.__dict__[key] = value - elif isinstance(vocab_size_or_config_json_file, int): - self.vocab_size = vocab_size_or_config_json_file - self.hidden_size = hidden_size - self.num_hidden_layers = num_hidden_layers - self.num_attention_heads = num_attention_heads - self.hidden_act = hidden_act - self.intermediate_size = intermediate_size - self.hidden_dropout_prob = hidden_dropout_prob - self.attention_probs_dropout_prob = attention_probs_dropout_prob - self.max_position_embeddings = max_position_embeddings - self.type_vocab_size = type_vocab_size - self.initializer_range = initializer_range - self.pre_trained = pre_trained - self.training = training - else: - raise ValueError("First argument must be either a vocabulary size (int)" - "or the path to a pretrained model config file (str)") - - @classmethod - def from_dict(cls, json_object): - """Constructs a `BertConfig` from a Python dictionary of parameters.""" - config = BertConfig(vocab_size_or_config_json_file=-1) - for key, value in json_object.items(): - config.__dict__[key] = value - return config - - @classmethod - def from_json_file(cls, json_file): - """Constructs a `BertConfig` from a json file of parameters.""" - with open(json_file, "r", encoding='utf-8') as reader: - text = reader.read() - return cls.from_dict(json.loads(text)) - - def __repr__(self): - return str(self.to_json_string()) - - def to_dict(self): - """Serializes this instance to a Python dictionary.""" - output = copy.deepcopy(self.__dict__) - return output - - def to_json_string(self): - """Serializes this instance to a JSON string.""" - return json.dumps(self.to_dict(), indent=2, sort_keys=True) + "\n" - - def to_json_file(self, json_file_path): - """ Save this instance to a json file.""" - with open(json_file_path, "w", encoding='utf-8') as writer: - writer.write(self.to_json_string()) - - -class BertEmbeddings(nn.Module): - """Construct the embeddings from word, position and token_type embeddings. - """ - - def __init__(self, config): - super(BertEmbeddings, self).__init__() - self.word_embeddings = nn.Embedding( - config.vocab_size, config.hidden_size, padding_idx=0) - self.position_embeddings = nn.Embedding( - config.max_position_embeddings, config.hidden_size) - self.token_type_embeddings = nn.Embedding( - config.type_vocab_size, config.hidden_size) - - # self.LayerNorm is not snake-cased to stick with TensorFlow model variable name and be able to load - # any TensorFlow checkpoint file - self.LayerNorm = BertLayerNorm(config.hidden_size, eps=1e-12) - self.dropout = nn.Dropout(config.hidden_dropout_prob) - - def forward(self, input_ids, token_type_ids=None): - seq_length = input_ids.size(1) - position_ids = torch.arange( - seq_length, dtype=torch.long, device=input_ids.device) - position_ids = position_ids.unsqueeze(0).expand_as(input_ids) - if token_type_ids is None: - token_type_ids = torch.zeros_like(input_ids) - - words_embeddings = self.word_embeddings(input_ids) - position_embeddings = self.position_embeddings(position_ids) - token_type_embeddings = self.token_type_embeddings(token_type_ids) - - embeddings = words_embeddings + position_embeddings + token_type_embeddings - embeddings = self.LayerNorm(embeddings) - embeddings = self.dropout(embeddings) - return embeddings - - -class BertSelfAttention(nn.Module): - def __init__(self, config): - super(BertSelfAttention, self).__init__() - if config.hidden_size % config.num_attention_heads != 0: - raise ValueError( - "The hidden size (%d) is not a multiple of the number of attention " - "heads (%d)" % (config.hidden_size, config.num_attention_heads)) - self.num_attention_heads = config.num_attention_heads - self.attention_head_size = int( - config.hidden_size / config.num_attention_heads) - self.all_head_size = self.num_attention_heads * self.attention_head_size - - self.query = nn.Linear(config.hidden_size, self.all_head_size) - self.key = nn.Linear(config.hidden_size, self.all_head_size) - self.value = nn.Linear(config.hidden_size, self.all_head_size) - - self.dropout = nn.Dropout(config.attention_probs_dropout_prob) - - def transpose_for_scores(self, x): - new_x_shape = x.size()[ - :-1] + (self.num_attention_heads, self.attention_head_size) - x = x.view(*new_x_shape) - return x.permute(0, 2, 1, 3) - - def forward(self, hidden_states, attention_mask, output_att=False): - mixed_query_layer = self.query(hidden_states) - mixed_key_layer = self.key(hidden_states) - mixed_value_layer = self.value(hidden_states) - - query_layer = self.transpose_for_scores(mixed_query_layer) - key_layer = self.transpose_for_scores(mixed_key_layer) - value_layer = self.transpose_for_scores(mixed_value_layer) - - # Take the dot product between "query" and "key" to get the raw attention scores. - attention_scores = torch.matmul( - query_layer, key_layer.transpose(-1, -2)) - attention_scores = attention_scores / \ - math.sqrt(self.attention_head_size) - # Apply the attention mask is (precomputed for all layers in BertModel forward() function) - attention_scores = attention_scores + attention_mask - - # Normalize the attention scores to probabilities. - attention_probs = nn.Softmax(dim=-1)(attention_scores) - - # This is actually dropping out entire tokens to attend to, which might - # seem a bit unusual, but is taken from the original Transformer paper. - attention_probs = self.dropout(attention_probs) - - context_layer = torch.matmul(attention_probs, value_layer) - context_layer = context_layer.permute(0, 2, 1, 3).contiguous() - new_context_layer_shape = context_layer.size()[ - :-2] + (self.all_head_size,) - context_layer = context_layer.view(*new_context_layer_shape) - return context_layer, attention_scores - - -class BertAttention(nn.Module): - def __init__(self, config): - super(BertAttention, self).__init__() - - self.self = BertSelfAttention(config) - self.output = BertSelfOutput(config) - - def forward(self, input_tensor, attention_mask): - self_output, layer_att = self.self(input_tensor, attention_mask) - attention_output = self.output(self_output, input_tensor) - return attention_output, layer_att - - -class BertSelfOutput(nn.Module): - def __init__(self, config): - super(BertSelfOutput, self).__init__() - self.dense = nn.Linear(config.hidden_size, config.hidden_size) - self.LayerNorm = BertLayerNorm(config.hidden_size, eps=1e-12) - self.dropout = nn.Dropout(config.hidden_dropout_prob) - - def forward(self, hidden_states, input_tensor): - hidden_states = self.dense(hidden_states) - hidden_states = self.dropout(hidden_states) - hidden_states = self.LayerNorm(hidden_states + input_tensor) - return hidden_states - - -class BertIntermediate(nn.Module): - def __init__(self, config, intermediate_size=-1): - super(BertIntermediate, self).__init__() - if intermediate_size < 0: - self.dense = nn.Linear( - config.hidden_size, config.intermediate_size) - else: - self.dense = nn.Linear(config.hidden_size, intermediate_size) - if isinstance(config.hidden_act, str) or (sys.version_info[0] == 2 and isinstance(config.hidden_act, unicode)): - self.intermediate_act_fn = ACT2FN[config.hidden_act] - else: - self.intermediate_act_fn = config.hidden_act - - def forward(self, hidden_states): - hidden_states = self.dense(hidden_states) - hidden_states = self.intermediate_act_fn(hidden_states) - return hidden_states - - -class BertOutput(nn.Module): - def __init__(self, config, intermediate_size=-1): - super(BertOutput, self).__init__() - if intermediate_size < 0: - self.dense = nn.Linear( - config.intermediate_size, config.hidden_size) - else: - self.dense = nn.Linear(intermediate_size, config.hidden_size) - self.LayerNorm = BertLayerNorm(config.hidden_size, eps=1e-12) - self.dropout = nn.Dropout(config.hidden_dropout_prob) - - def forward(self, hidden_states, input_tensor): - hidden_states = self.dense(hidden_states) - hidden_states = self.dropout(hidden_states) - hidden_states = self.LayerNorm(hidden_states + input_tensor) - return hidden_states - - -class BertLayer(nn.Module): - def __init__(self, config): - super(BertLayer, self).__init__() - self.attention = BertAttention(config) - self.intermediate = BertIntermediate(config) - self.output = BertOutput(config) - - def forward(self, hidden_states, attention_mask): - attention_output, layer_att = self.attention( - hidden_states, attention_mask) - intermediate_output = self.intermediate(attention_output) - layer_output = self.output(intermediate_output, attention_output) - - return layer_output, layer_att - - -class BertEncoder(nn.Module): - def __init__(self, config): - super(BertEncoder, self).__init__() - self.layer = nn.ModuleList([BertLayer(config) - for _ in range(config.num_hidden_layers)]) - - def forward(self, hidden_states, attention_mask): - all_encoder_layers = [] - all_encoder_atts = [] - for _, layer_module in enumerate(self.layer): - all_encoder_layers.append(hidden_states) - hidden_states, layer_att = layer_module( - hidden_states, attention_mask) - all_encoder_atts.append(layer_att) - - all_encoder_layers.append(hidden_states) - return all_encoder_layers, all_encoder_atts - - -class BertPooler(nn.Module): - def __init__(self, config, recurs=None): - super(BertPooler, self).__init__() - self.dense = nn.Linear(config.hidden_size, config.hidden_size) - self.activation = nn.Tanh() - self.config = config - - def forward(self, hidden_states): - # We "pool" the model by simply taking the hidden state corresponding - # to the first token. "-1" refers to last layer - pooled_output = hidden_states[-1][:, 0] - - pooled_output = self.dense(pooled_output) - pooled_output = self.activation(pooled_output) - - return pooled_output - - -class BertPredictionHeadTransform(nn.Module): - def __init__(self, config): - super(BertPredictionHeadTransform, self).__init__() - # Need to unty it when we separate the dimensions of hidden and emb - self.dense = nn.Linear(config.hidden_size, config.hidden_size) - if isinstance(config.hidden_act, str) or (sys.version_info[0] == 2 and isinstance(config.hidden_act, unicode)): - self.transform_act_fn = ACT2FN[config.hidden_act] - else: - self.transform_act_fn = config.hidden_act - self.LayerNorm = BertLayerNorm(config.hidden_size, eps=1e-12) - - def forward(self, hidden_states): - hidden_states = self.dense(hidden_states) - hidden_states = self.transform_act_fn(hidden_states) - hidden_states = self.LayerNorm(hidden_states) - return hidden_states - - -class BertLMPredictionHead(nn.Module): - def __init__(self, config, bert_model_embedding_weights): - super(BertLMPredictionHead, self).__init__() - self.transform = BertPredictionHeadTransform(config) - - # The output weights are the same as the input embeddings, but there is - # an output-only bias for each token. - self.decoder = nn.Linear(bert_model_embedding_weights.size(1), - bert_model_embedding_weights.size(0), - bias=False) - self.decoder.weight = bert_model_embedding_weights - self.bias = nn.Parameter(torch.zeros( - bert_model_embedding_weights.size(0))) - - def forward(self, hidden_states): - hidden_states = self.transform(hidden_states) - hidden_states = self.decoder(hidden_states) + self.bias - return hidden_states - - -class BertOnlyMLMHead(nn.Module): - def __init__(self, config, bert_model_embedding_weights): - super(BertOnlyMLMHead, self).__init__() - self.predictions = BertLMPredictionHead( - config, bert_model_embedding_weights) - - def forward(self, sequence_output): - prediction_scores = self.predictions(sequence_output) - return prediction_scores - - -class BertOnlyNSPHead(nn.Module): - def __init__(self, config): - super(BertOnlyNSPHead, self).__init__() - self.seq_relationship = nn.Linear(config.hidden_size, 2) - - def forward(self, pooled_output): - seq_relationship_score = self.seq_relationship(pooled_output) - return seq_relationship_score - - -class BertPreTrainingHeads(nn.Module): - def __init__(self, config, bert_model_embedding_weights): - super(BertPreTrainingHeads, self).__init__() - self.predictions = BertLMPredictionHead( - config, bert_model_embedding_weights) - self.seq_relationship = nn.Linear(config.hidden_size, 2) - - def forward(self, sequence_output, pooled_output): - prediction_scores = self.predictions(sequence_output) - seq_relationship_score = self.seq_relationship(pooled_output) - return prediction_scores, seq_relationship_score - - -class BertPreTrainedModel(nn.Module): - """ An abstract class to handle weights initialization and - a simple interface for dowloading and loading pretrained models. - """ - - def __init__(self, config, *inputs, **kwargs): - super(BertPreTrainedModel, self).__init__() - if not isinstance(config, BertConfig): - raise ValueError( - "Parameter config in `{}(config)` should be an instance of class `BertConfig`. " - "To create a model from a Google pretrained model use " - "`model = {}.from_pretrained(PRETRAINED_MODEL_NAME)`".format( - self.__class__.__name__, self.__class__.__name__ - )) - self.config = config - - def init_bert_weights(self, module): - """ Initialize the weights. - """ - if isinstance(module, (nn.Linear, nn.Embedding)): - # Slightly different from the TF version which uses truncated_normal for initialization - # cf https://github.com/pytorch/pytorch/pull/5617 - module.weight.data.normal_( - mean=0.0, std=self.config.initializer_range) - elif isinstance(module, BertLayerNorm): - module.bias.data.zero_() - module.weight.data.fill_(1.0) - if isinstance(module, nn.Linear) and module.bias is not None: - module.bias.data.zero_() - - @classmethod - def from_scratch(cls, pretrained_model_name_or_path, *inputs, **kwargs): - resolved_config_file = os.path.join( - pretrained_model_name_or_path, CONFIG_NAME) - config = BertConfig.from_json_file(resolved_config_file) - - logger.info("Model config {}".format(config)) - model = cls(config, *inputs, **kwargs) - return model - - @classmethod - def from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs): - """ - Instantiate a BertPreTrainedModel from a pre-trained model file or a pytorch state dict. - Download and cache the pre-trained model file if needed. - - Params: - pretrained_model_name_or_path: either: - - a str with the name of a pre-trained model to load selected in the list of: - . `bert-base-uncased` - . `bert-large-uncased` - . `bert-base-cased` - . `bert-large-cased` - . `bert-base-multilingual-uncased` - . `bert-base-multilingual-cased` - . `bert-base-chinese` - - a path or url to a pretrained model archive containing: - . `bert_config.json` a configuration file for the model - . `pytorch_model.bin` a PyTorch dump of a BertForPreTraining instance - - a path or url to a pretrained model archive containing: - . `bert_config.json` a configuration file for the model - . `model.chkpt` a TensorFlow checkpoint - from_tf: should we load the weights from a locally saved TensorFlow checkpoint - cache_dir: an optional path to a folder in which the pre-trained models will be cached. - state_dict: an optional state dictionnary (collections.OrderedDict object) to use instead of Google pre-trained models - *inputs, **kwargs: additional input for the specific Bert class - (ex: num_labels for BertForSequenceClassification) - """ - state_dict = kwargs.get('state_dict', None) - kwargs.pop('state_dict', None) - from_tf = kwargs.get('from_tf', False) - kwargs.pop('from_tf', None) - - # Load config - config_file = os.path.join(pretrained_model_name_or_path, CONFIG_NAME) - config = BertConfig.from_json_file(config_file) - logger.info("Model config {}".format(config)) - # Instantiate model. - - model = cls(config, *inputs, **kwargs) - if state_dict is None and not from_tf: - weights_path = os.path.join( - pretrained_model_name_or_path, WEIGHTS_NAME) - logger.info("Loading model {}".format(weights_path)) - state_dict = torch.load(weights_path, map_location='cpu') - state_dict.pop('classifier.weight') - state_dict.pop('classifier.bias') - if from_tf: - # Directly load from a TensorFlow checkpoint - weights_path = os.path.join( - pretrained_model_name_or_path, TF_WEIGHTS_NAME) - return load_tf_weights_in_bert(model, weights_path) - # Load from a PyTorch state_dict - old_keys = [] - new_keys = [] - for key in state_dict.keys(): - new_key = None - if 'gamma' in key: - new_key = key.replace('gamma', 'weight') - if 'beta' in key: - new_key = key.replace('beta', 'bias') - if new_key: - old_keys.append(key) - new_keys.append(new_key) - for old_key, new_key in zip(old_keys, new_keys): - state_dict[new_key] = state_dict.pop(old_key) - - missing_keys = [] - unexpected_keys = [] - error_msgs = [] - # copy state_dict so _load_from_state_dict can modify it - metadata = getattr(state_dict, '_metadata', None) - state_dict = state_dict.copy() - if metadata is not None: - state_dict._metadata = metadata - - def load(module, prefix=''): - local_metadata = {} if metadata is None else metadata.get( - prefix[:-1], {}) - module._load_from_state_dict( - state_dict, prefix, local_metadata, True, missing_keys, unexpected_keys, error_msgs) - for name, child in module._modules.items(): - if child is not None: - load(child, prefix + name + '.') - - start_prefix = '' - if not hasattr(model, 'bert') and any(s.startswith('bert.') for s in state_dict.keys()): - start_prefix = 'bert.' - - logger.info('loading model...') - load(model, prefix=start_prefix) - logger.info('done!') - if len(missing_keys) > 0: - logger.info("Weights of {} not initialized from pretrained model: {}".format( - model.__class__.__name__, missing_keys)) - if len(unexpected_keys) > 0: - logger.info("Weights from pretrained model not used in {}: {}".format( - model.__class__.__name__, unexpected_keys)) - if len(error_msgs) > 0: - raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( - model.__class__.__name__, "\n\t".join(error_msgs))) - - return model - - -class BertModel(BertPreTrainedModel): - """BERT model ("Bidirectional Embedding Representations from a Transformer"). - - Params: - config: a BertConfig class instance with the configuration to build a new model - - Inputs: - `input_ids`: a torch.LongTensor of shape [batch_size, sequence_length] - with the word token indices in the vocabulary(see the tokens preprocessing logic in the scripts - `extract_features.py`, `run_classifier.py` and `run_squad.py`) - `token_type_ids`: an optional torch.LongTensor of shape [batch_size, sequence_length] with the token - types indices selected in [0, 1]. Type 0 corresponds to a `sentence A` and type 1 corresponds to - a `sentence B` token (see BERT paper for more details). - `attention_mask`: an optional torch.LongTensor of shape [batch_size, sequence_length] with indices - selected in [0, 1]. It's a mask to be used if the input sequence length is smaller than the max - input sequence length in the current batch. It's the mask that we typically use for attention when - a batch has varying length sentences. - `output_all_encoded_layers`: boolean which controls the content of the `encoded_layers` output as described below. Default: `True`. - - Outputs: Tuple of (encoded_layers, pooled_output) - `encoded_layers`: controled by `output_all_encoded_layers` argument: - - `output_all_encoded_layers=True`: outputs a list of the full sequences of encoded-hidden-states at the end - of each attention block (i.e. 12 full sequences for BERT-base, 24 for BERT-large), each - encoded-hidden-state is a torch.FloatTensor of size [batch_size, sequence_length, hidden_size], - - `output_all_encoded_layers=False`: outputs only the full sequence of hidden-states corresponding - to the last attention block of shape [batch_size, sequence_length, hidden_size], - `pooled_output`: a torch.FloatTensor of size [batch_size, hidden_size] which is the output of a - classifier pretrained on top of the hidden state associated to the first character of the - input (`CLS`) to train on the Next-Sentence task (see BERT's paper). - - Example usage: - ```python - # Already been converted into WordPiece token ids - input_ids = torch.LongTensor([[31, 51, 99], [15, 5, 0]]) - input_mask = torch.LongTensor([[1, 1, 1], [1, 1, 0]]) - token_type_ids = torch.LongTensor([[0, 0, 1], [0, 1, 0]]) - - config = modeling.BertConfig(vocab_size_or_config_json_file=32000, hidden_size=768, - num_hidden_layers=12, num_attention_heads=12, intermediate_size=3072) - - model = modeling.BertModel(config=config) - all_encoder_layers, pooled_output = model(input_ids, token_type_ids, input_mask) - ``` - """ - - def __init__(self, config): - super(BertModel, self).__init__(config) - self.embeddings = BertEmbeddings(config) - self.encoder = BertEncoder(config) - self.pooler = BertPooler(config) - self.apply(self.init_bert_weights) - - def forward(self, input_ids, token_type_ids=None, attention_mask=None, - output_all_encoded_layers=True, output_att=True): - - if attention_mask is None: - attention_mask = torch.ones_like(input_ids) - if token_type_ids is None: - token_type_ids = torch.zeros_like(input_ids) - - # We create a 3D attention mask from a 2D tensor mask. - # Sizes are [batch_size, 1, 1, to_seq_length] - # So we can broadcast to [batch_size, num_heads, from_seq_length, to_seq_length] - # this attention mask is more simple than the triangular masking of causal attention - # used in OpenAI GPT, we just need to prepare the broadcast dimension here. - extended_attention_mask = attention_mask.unsqueeze(1).unsqueeze(2) - - # Since attention_mask is 1.0 for positions we want to attend and 0.0 for - # masked positions, this operation will create a tensor which is 0.0 for - # positions we want to attend and -10000.0 for masked positions. - # Since we are adding it to the raw scores before the softmax, this is - # effectively the same as removing these entirely. - extended_attention_mask = extended_attention_mask.to( - dtype=next(self.parameters()).dtype) # fp16 compatibility - extended_attention_mask = (1.0 - extended_attention_mask) * -10000.0 - - embedding_output = self.embeddings(input_ids, token_type_ids) - encoded_layers, layer_atts = self.encoder(embedding_output, - extended_attention_mask) - - pooled_output = self.pooler(encoded_layers) - if not output_all_encoded_layers: - encoded_layers = encoded_layers[-1] - - if not output_att: - return encoded_layers, pooled_output - - return encoded_layers, layer_atts, pooled_output - - -class BertForPreTraining(BertPreTrainedModel): - """BERT model with pre-training heads. - This module comprises the BERT model followed by the two pre-training heads: - - the masked language modeling head, and - - the next sentence classification head. - - Params: - config: a BertConfig class instance with the configuration to build a new model. - - Inputs: - `input_ids`: a torch.LongTensor of shape [batch_size, sequence_length] - with the word token indices in the vocabulary(see the tokens preprocessing logic in the scripts - `extract_features.py`, `run_classifier.py` and `run_squad.py`) - `token_type_ids`: an optional torch.LongTensor of shape [batch_size, sequence_length] with the token - types indices selected in [0, 1]. Type 0 corresponds to a `sentence A` and type 1 corresponds to - a `sentence B` token (see BERT paper for more details). - `attention_mask`: an optional torch.LongTensor of shape [batch_size, sequence_length] with indices - selected in [0, 1]. It's a mask to be used if the input sequence length is smaller than the max - input sequence length in the current batch. It's the mask that we typically use for attention when - a batch has varying length sentences. - `masked_lm_labels`: optional masked language modeling labels: torch.LongTensor of shape [batch_size, sequence_length] - with indices selected in [-1, 0, ..., vocab_size]. All labels set to -1 are ignored (masked), the loss - is only computed for the labels set in [0, ..., vocab_size] - `next_sentence_label`: optional next sentence classification loss: torch.LongTensor of shape [batch_size] - with indices selected in [0, 1]. - 0 => next sentence is the continuation, 1 => next sentence is a random sentence. - - Outputs: - if `masked_lm_labels` and `next_sentence_label` are not `None`: - Outputs the total_loss which is the sum of the masked language modeling loss and the next - sentence classification loss. - if `masked_lm_labels` or `next_sentence_label` is `None`: - Outputs a tuple comprising - - the masked language modeling logits of shape [batch_size, sequence_length, vocab_size], and - - the next sentence classification logits of shape [batch_size, 2]. - - Example usage: - ```python - # Already been converted into WordPiece token ids - input_ids = torch.LongTensor([[31, 51, 99], [15, 5, 0]]) - input_mask = torch.LongTensor([[1, 1, 1], [1, 1, 0]]) - token_type_ids = torch.LongTensor([[0, 0, 1], [0, 1, 0]]) - - config = BertConfig(vocab_size_or_config_json_file=32000, hidden_size=768, - num_hidden_layers=12, num_attention_heads=12, intermediate_size=3072) - - model = BertForPreTraining(config) - masked_lm_logits_scores, seq_relationship_logits = model(input_ids, token_type_ids, input_mask) - ``` - """ - - def __init__(self, config): - super(BertForPreTraining, self).__init__(config) - self.bert = BertModel(config) - self.cls = BertPreTrainingHeads( - config, self.bert.embeddings.word_embeddings.weight) - self.apply(self.init_bert_weights) - - def forward(self, input_ids, token_type_ids=None, attention_mask=None, - masked_lm_labels=None, next_sentence_label=None): - sequence_output, pooled_output = self.bert(input_ids, token_type_ids, attention_mask, - output_all_encoded_layers=False) - prediction_scores, seq_relationship_score = self.cls( - sequence_output, pooled_output) - - if masked_lm_labels is not None and next_sentence_label is not None: - loss_fct = CrossEntropyLoss(ignore_index=-1) - masked_lm_loss = loss_fct( - prediction_scores.view(-1, self.config.vocab_size), masked_lm_labels.view(-1)) - next_sentence_loss = loss_fct( - seq_relationship_score.view(-1, 2), next_sentence_label.view(-1)) - total_loss = masked_lm_loss + next_sentence_loss - return total_loss - elif masked_lm_labels is not None: - loss_fct = CrossEntropyLoss(ignore_index=-1) - masked_lm_loss = loss_fct( - prediction_scores.view(-1, self.config.vocab_size), masked_lm_labels.view(-1)) - total_loss = masked_lm_loss - return total_loss - else: - return prediction_scores, seq_relationship_score - - -class TinyBertForPreTraining(BertPreTrainedModel): - def __init__(self, config, fit_size=768): - super(TinyBertForPreTraining, self).__init__(config) - self.bert = BertModel(config) - self.cls = BertPreTrainingHeads( - config, self.bert.embeddings.word_embeddings.weight) - self.fit_dense = nn.Linear(config.hidden_size, fit_size) - self.apply(self.init_bert_weights) - - def forward(self, input_ids, token_type_ids=None, - attention_mask=None, masked_lm_labels=None, - next_sentence_label=None, labels=None): - sequence_output, att_output, pooled_output = self.bert( - input_ids, token_type_ids, attention_mask) - tmp = [] - for s_id, sequence_layer in enumerate(sequence_output): - tmp.append(self.fit_dense(sequence_layer)) - sequence_output = tmp - - return att_output, sequence_output - - -class BertForMaskedLM(BertPreTrainedModel): - """BERT model with the masked language modeling head. - This module comprises the BERT model followed by the masked language modeling head. - - Params: - config: a BertConfig class instance with the configuration to build a new model. - - Inputs: - `input_ids`: a torch.LongTensor of shape [batch_size, sequence_length] - with the word token indices in the vocabulary(see the tokens preprocessing logic in the scripts - `extract_features.py`, `run_classifier.py` and `run_squad.py`) - `token_type_ids`: an optional torch.LongTensor of shape [batch_size, sequence_length] with the token - types indices selected in [0, 1]. Type 0 corresponds to a `sentence A` and type 1 corresponds to - a `sentence B` token (see BERT paper for more details). - `attention_mask`: an optional torch.LongTensor of shape [batch_size, sequence_length] with indices - selected in [0, 1]. It's a mask to be used if the input sequence length is smaller than the max - input sequence length in the current batch. It's the mask that we typically use for attention when - a batch has varying length sentences. - `masked_lm_labels`: masked language modeling labels: torch.LongTensor of shape [batch_size, sequence_length] - with indices selected in [-1, 0, ..., vocab_size]. All labels set to -1 are ignored (masked), the loss - is only computed for the labels set in [0, ..., vocab_size] - - Outputs: - if `masked_lm_labels` is not `None`: - Outputs the masked language modeling loss. - if `masked_lm_labels` is `None`: - Outputs the masked language modeling logits of shape [batch_size, sequence_length, vocab_size]. - - Example usage: - ```python - # Already been converted into WordPiece token ids - input_ids = torch.LongTensor([[31, 51, 99], [15, 5, 0]]) - input_mask = torch.LongTensor([[1, 1, 1], [1, 1, 0]]) - token_type_ids = torch.LongTensor([[0, 0, 1], [0, 1, 0]]) - - config = BertConfig(vocab_size_or_config_json_file=32000, hidden_size=768, - num_hidden_layers=12, num_attention_heads=12, intermediate_size=3072) - - model = BertForMaskedLM(config) - masked_lm_logits_scores = model(input_ids, token_type_ids, input_mask) - ``` - """ - - def __init__(self, config): - super(BertForMaskedLM, self).__init__(config) - self.bert = BertModel(config) - self.cls = BertOnlyMLMHead( - config, self.bert.embeddings.word_embeddings.weight) - self.apply(self.init_bert_weights) - - def forward(self, input_ids, token_type_ids=None, attention_mask=None, masked_lm_labels=None, - output_att=False, infer=False): - sequence_output, _ = self.bert(input_ids, token_type_ids, attention_mask, - output_all_encoded_layers=True, output_att=output_att) - - if output_att: - sequence_output, att_output = sequence_output - prediction_scores = self.cls(sequence_output[-1]) - - if masked_lm_labels is not None: - loss_fct = CrossEntropyLoss(ignore_index=-1) - masked_lm_loss = loss_fct( - prediction_scores.view(-1, self.config.vocab_size), masked_lm_labels.view(-1)) - if not output_att: - return masked_lm_loss - else: - return masked_lm_loss, att_output - else: - if not output_att: - return prediction_scores - else: - return prediction_scores, att_output - - -class BertForNextSentencePrediction(BertPreTrainedModel): - """BERT model with next sentence prediction head. - This module comprises the BERT model followed by the next sentence classification head. - - Params: - config: a BertConfig class instance with the configuration to build a new model. - - Inputs: - `input_ids`: a torch.LongTensor of shape [batch_size, sequence_length] - with the word token indices in the vocabulary(see the tokens preprocessing logic in the scripts - `extract_features.py`, `run_classifier.py` and `run_squad.py`) - `token_type_ids`: an optional torch.LongTensor of shape [batch_size, sequence_length] with the token - types indices selected in [0, 1]. Type 0 corresponds to a `sentence A` and type 1 corresponds to - a `sentence B` token (see BERT paper for more details). - `attention_mask`: an optional torch.LongTensor of shape [batch_size, sequence_length] with indices - selected in [0, 1]. It's a mask to be used if the input sequence length is smaller than the max - input sequence length in the current batch. It's the mask that we typically use for attention when - a batch has varying length sentences. - `next_sentence_label`: next sentence classification loss: torch.LongTensor of shape [batch_size] - with indices selected in [0, 1]. - 0 => next sentence is the continuation, 1 => next sentence is a random sentence. - - Outputs: - if `next_sentence_label` is not `None`: - Outputs the total_loss which is the sum of the masked language modeling loss and the next - sentence classification loss. - if `next_sentence_label` is `None`: - Outputs the next sentence classification logits of shape [batch_size, 2]. - - Example usage: - ```python - # Already been converted into WordPiece token ids - input_ids = torch.LongTensor([[31, 51, 99], [15, 5, 0]]) - input_mask = torch.LongTensor([[1, 1, 1], [1, 1, 0]]) - token_type_ids = torch.LongTensor([[0, 0, 1], [0, 1, 0]]) - - config = BertConfig(vocab_size_or_config_json_file=32000, hidden_size=768, - num_hidden_layers=12, num_attention_heads=12, intermediate_size=3072) - - model = BertForNextSentencePrediction(config) - seq_relationship_logits = model(input_ids, token_type_ids, input_mask) - ``` - """ - - def __init__(self, config): - super(BertForNextSentencePrediction, self).__init__(config) - self.bert = BertModel(config) - self.cls = BertOnlyNSPHead(config) - self.apply(self.init_bert_weights) - - def forward(self, input_ids, token_type_ids=None, attention_mask=None, next_sentence_label=None): - _, pooled_output = self.bert(input_ids, token_type_ids, attention_mask, - output_all_encoded_layers=False) - seq_relationship_score = self.cls(pooled_output) - - if next_sentence_label is not None: - loss_fct = CrossEntropyLoss(ignore_index=-1) - next_sentence_loss = loss_fct( - seq_relationship_score.view(-1, 2), next_sentence_label.view(-1)) - return next_sentence_loss - else: - return seq_relationship_score - - -class BertForSentencePairClassification(BertPreTrainedModel): - def __init__(self, config, num_labels): - super(BertForSentencePairClassification, self).__init__(config) - self.num_labels = num_labels - self.bert = BertModel(config) - self.dropout = nn.Dropout(config.hidden_dropout_prob) - self.classifier = nn.Linear(config.hidden_size * 3, num_labels) - self.apply(self.init_bert_weights) - - def forward(self, a_input_ids, b_input_ids, a_token_type_ids=None, b_token_type_ids=None, - a_attention_mask=None, b_attention_mask=None, labels=None): - _, a_pooled_output = self.bert( - a_input_ids, a_token_type_ids, a_attention_mask, output_all_encoded_layers=False) - # a_pooled_output = self.dropout(a_pooled_output) - - _, b_pooled_output = self.bert( - b_input_ids, b_token_type_ids, b_attention_mask, output_all_encoded_layers=False) - # b_pooled_output = self.dropout(b_pooled_output) - - logits = self.classifier(torch.relu(torch.cat((a_pooled_output, b_pooled_output, - torch.abs(a_pooled_output - b_pooled_output)), -1))) - - if labels is not None: - loss_fct = CrossEntropyLoss() - loss = loss_fct(logits.view(-1, self.num_labels), labels.view(-1)) - return loss - else: - return logits - - -class TinyBertForSequenceClassification_for_finetune(BertPreTrainedModel): - def __init__(self, config, num_labels, fit_size=768): - super(TinyBertForSequenceClassification_for_finetune, self).__init__(config) - self.num_labels = num_labels - self.bert = BertModel(config) - self.dropout = nn.Dropout(config.hidden_dropout_prob) - self.classifier = nn.Linear(config.hidden_size, num_labels) - self.fit_dense = nn.Linear(config.hidden_size, fit_size) - self.apply(self.init_bert_weights) - - def forward(self, input_ids, token_type_ids=None, attention_mask=None, - labels=None, is_student=False): - - sequence_output, att_output, pooled_output = self.bert(input_ids, token_type_ids, attention_mask, - output_all_encoded_layers=True, output_att=True) - - logits = self.classifier(torch.relu(pooled_output)) - - tmp = [] - if is_student: - for s_id, sequence_layer in enumerate(sequence_output): - tmp.append(self.fit_dense(sequence_layer)) - sequence_output = tmp - return logits, att_output, sequence_output +# coding=utf-8 +# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. +# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""PyTorch BERT model.""" + +from __future__ import absolute_import, division, print_function, unicode_literals + +import copy +import json +import logging +import math +import os +import shutil +import tarfile +import tempfile +import sys +from io import open + +import torch +import torch.nn.functional as F +from torch import nn +from torch.nn import CrossEntropyLoss +from torch.autograd import Variable +from torch.nn.parameter import Parameter + +from .file_utils import WEIGHTS_NAME, CONFIG_NAME + +logger = logging.getLogger(__name__) + +PRETRAINED_MODEL_ARCHIVE_MAP = { + 'bert-base-uncased': "https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-uncased.tar.gz", + 'bert-large-uncased': "https://s3.amazonaws.com/models.huggingface.co/bert/bert-large-uncased.tar.gz", + 'bert-base-cased': "https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-cased.tar.gz", + 'bert-large-cased': "https://s3.amazonaws.com/models.huggingface.co/bert/bert-large-cased.tar.gz", + 'bert-base-multilingual-uncased': "https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-multilingual-uncased.tar.gz", + 'bert-base-multilingual-cased': "https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-multilingual-cased.tar.gz", + 'bert-base-chinese': "", +} + +BERT_CONFIG_NAME = 'bert_config.json' +TF_WEIGHTS_NAME = 'model.ckpt' + + +def load_tf_weights_in_bert(model, tf_checkpoint_path): + """ Load tf checkpoints in a pytorch model + """ + try: + import re + import numpy as np + import tensorflow as tf + except ImportError: + print("Loading a TensorFlow models in PyTorch, requires TensorFlow to be installed. Please see " + "https://www.tensorflow.org/install/ for installation instructions.") + raise + tf_path = os.path.abspath(tf_checkpoint_path) + print("Converting TensorFlow checkpoint from {}".format(tf_path)) + # Load weights from TF model + init_vars = tf.train.list_variables(tf_path) + names = [] + arrays = [] + for name, shape in init_vars: + print("Loading TF weight {} with shape {}".format(name, shape)) + array = tf.train.load_variable(tf_path, name) + names.append(name) + arrays.append(array) + + for name, array in zip(names, arrays): + name = name.split('/') + # adam_v and adam_m are variables used in AdamWeightDecayOptimizer to calculated m and v + # which are not required for using pretrained model + if any(n in ["adam_v", "adam_m", "global_step"] for n in name): + print("Skipping {}".format("/".join(name))) + continue + pointer = model + for m_name in name: + if re.fullmatch(r'[A-Za-z]+_\d+', m_name): + l = re.split(r'_(\d+)', m_name) + else: + l = [m_name] + if l[0] == 'kernel' or l[0] == 'gamma': + pointer = getattr(pointer, 'weight') + elif l[0] == 'output_bias' or l[0] == 'beta': + try: + pointer = getattr(pointer, 'bias') + except AttributeError: + print("Skipping {}".format("/".join(name))) + continue + elif l[0] == 'output_weights': + pointer = getattr(pointer, 'weight') + elif l[0] == 'squad': + pointer = getattr(pointer, 'classifier') + else: + try: + pointer = getattr(pointer, l[0]) + except AttributeError: + print("Skipping {}".format("/".join(name))) + continue + if len(l) >= 2: + num = int(l[1]) + pointer = pointer[num] + if m_name[-11:] == '_embeddings': + pointer = getattr(pointer, 'weight') + elif m_name == 'kernel': + array = np.transpose(array) + try: + assert pointer.shape == array.shape + except AssertionError as e: + e.args += (pointer.shape, array.shape) + raise + print("Initialize PyTorch weight {}".format(name)) + pointer.data = torch.from_numpy(array) + return model + + +def gelu(x): + """Implementation of the gelu activation function. + For information: OpenAI GPT's gelu is slightly different (and gives slightly different results): + 0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) + Also see https://arxiv.org/abs/1606.08415 + """ + return x * 0.5 * (1.0 + torch.erf(x / math.sqrt(2.0))) + + +def swish(x): + return x * torch.sigmoid(x) + +''' + +try: + from apex.normalization.fused_layer_norm import FusedLayerNorm as BertLayerNorm +except ImportError: + logger.info( + "Better speed can be achieved with apex installed from https://www.github.com/nvidia/apex .") +''' +class BertLayerNorm(nn.Module): + def __init__(self, hidden_size, eps=1e-12): + """Construct a layernorm module in the TF style (epsilon inside the square root). + """ + super(BertLayerNorm, self).__init__() + self.weight = nn.Parameter(torch.ones(hidden_size)) + self.bias = nn.Parameter(torch.zeros(hidden_size)) + self.variance_epsilon = eps + + def forward(self, x): + u = x.mean(-1, keepdim=True) + s = (x - u).pow(2).mean(-1, keepdim=True) + x = (x - u) / torch.sqrt(s + self.variance_epsilon) + return self.weight * x + self.bias + + +class HeadAttention(nn.Module): + def __init__(self, config, hidden_size, head_num, head_used): + super(HeadAttention, self).__init__() + self.head_num = head_num + self.head_used = head_used + self.hidden_size = hidden_size + if self.hidden_size % self.head_num != 0: + raise ValueError( + "The hidden size (%d) is not a multiple of the number of attention " + "heads (%d)" % (self.hidden_size, self.head_num)) + + self.attention_head_size = int(self.hidden_size / self.head_num) + self.all_head_size = self.num_heads_used * self.attention_head_size + + self.query = nn.Linear(self.hidden_size, self.all_head_size) + self.key = nn.Linear(self.hidden_size, self.all_head_size) + self.value = nn.Linear(self.hidden_size, self.all_head_size) + + self.dropout = nn.Dropout(config.attention_probs_dropout_prob) + + def transpose_for_scores(self, x): + new_x_shape = x.size()[:-1] + (self.num_heads_used, + self.attention_head_size) + x = x.view(*new_x_shape) + return x.permute(0, 2, 1, 3) + + def forward(self, hidden_states, attention_mask): + mixed_query_layer = self.query(hidden_states) + mixed_key_layer = self.key(hidden_states) + mixed_value_layer = self.value(hidden_states) + + query_layer = self.transpose_for_scores(mixed_query_layer) + key_layer = self.transpose_for_scores(mixed_key_layer) + value_layer = self.transpose_for_scores(mixed_value_layer) + + # Take the dot product between "query" and "key" to get the raw attention scores. + attention_scores = torch.matmul( + query_layer, key_layer.transpose(-1, -2)) + attention_scores = attention_scores / \ + math.sqrt(self.attention_head_size) + # Apply the attention mask is (precomputed for all layers in BertModel forward() function) + attention_scores = attention_scores + attention_mask + + # Normalize the attention scores to probabilities. + attention_probs = nn.Softmax(dim=-1)(attention_scores) + + # This is actually dropping out entire tokens to attend to, which might + # seem a bit unusual, but is taken from the original Transformer paper. + attention_probs = self.dropout(attention_probs) + + context_layer = torch.matmul(attention_probs, value_layer) + context_layer = context_layer.permute(0, 2, 1, 3).contiguous() + new_context_layer_shape = context_layer.size()[ + :-2] + (self.all_head_size,) + context_layer = context_layer.view(*new_context_layer_shape) + + if self.num_heads_used != self.num_attention_heads: + pad_shape = context_layer.size()[:-1] + \ + ((self.num_attention_heads - self.num_heads_used) + * self.attention_head_size, ) + + pad_layer = torch.zeros(*pad_shape).to(context_layer.device) + context_layer = torch.cat((context_layer, pad_layer), -1) + return context_layer + + +ACT2FN = {"gelu": gelu, "relu": torch.nn.functional.relu} +NORM = {'layer_norm': BertLayerNorm} + + +class BertConfig(object): + """Configuration class to store the configuration of a `BertModel`. + """ + + def __init__(self, + vocab_size_or_config_json_file, + hidden_size=768, + num_hidden_layers=12, + num_attention_heads=12, + intermediate_size=3072, + hidden_act="gelu", + hidden_dropout_prob=0.1, + attention_probs_dropout_prob=0.1, + max_position_embeddings=512, + type_vocab_size=2, + initializer_range=0.02, + pre_trained='', + training=''): + """Constructs BertConfig. + + Args: + vocab_size_or_config_json_file: Vocabulary size of `inputs_ids` in `BertModel`. + hidden_size: Size of the encoder layers and the pooler layer. + num_hidden_layers: Number of hidden layers in the Transformer encoder. + num_attention_heads: Number of attention heads for each attention layer in + the Transformer encoder. + intermediate_size: The size of the "intermediate" (i.e., feed-forward) + layer in the Transformer encoder. + hidden_act: The non-linear activation function (function or string) in the + encoder and pooler. If string, "gelu", "relu" and "swish" are supported. + hidden_dropout_prob: The dropout probabilitiy for all fully connected + layers in the embeddings, encoder, and pooler. + attention_probs_dropout_prob: The dropout ratio for the attention + probabilities. + max_position_embeddings: The maximum sequence length that this model might + ever be used with. Typically set this to something large just in case + (e.g., 512 or 1024 or 2048). + type_vocab_size: The vocabulary size of the `token_type_ids` passed into + `BertModel`. + initializer_range: The sttdev of the truncated_normal_initializer for + initializing all weight matrices. + """ + if isinstance(vocab_size_or_config_json_file, str) or (sys.version_info[0] == 2 + and isinstance(vocab_size_or_config_json_file, unicode)): + with open(vocab_size_or_config_json_file, "r", encoding='utf-8') as reader: + json_config = json.loads(reader.read()) + for key, value in json_config.items(): + self.__dict__[key] = value + elif isinstance(vocab_size_or_config_json_file, int): + self.vocab_size = vocab_size_or_config_json_file + self.hidden_size = hidden_size + self.num_hidden_layers = num_hidden_layers + self.num_attention_heads = num_attention_heads + self.hidden_act = hidden_act + self.intermediate_size = intermediate_size + self.hidden_dropout_prob = hidden_dropout_prob + self.attention_probs_dropout_prob = attention_probs_dropout_prob + self.max_position_embeddings = max_position_embeddings + self.type_vocab_size = type_vocab_size + self.initializer_range = initializer_range + self.pre_trained = pre_trained + self.training = training + else: + raise ValueError("First argument must be either a vocabulary size (int)" + "or the path to a pretrained model config file (str)") + + @classmethod + def from_dict(cls, json_object): + """Constructs a `BertConfig` from a Python dictionary of parameters.""" + config = BertConfig(vocab_size_or_config_json_file=-1) + for key, value in json_object.items(): + config.__dict__[key] = value + return config + + @classmethod + def from_json_file(cls, json_file): + """Constructs a `BertConfig` from a json file of parameters.""" + with open(json_file, "r", encoding='utf-8') as reader: + text = reader.read() + return cls.from_dict(json.loads(text)) + + def __repr__(self): + return str(self.to_json_string()) + + def to_dict(self): + """Serializes this instance to a Python dictionary.""" + output = copy.deepcopy(self.__dict__) + return output + + def to_json_string(self): + """Serializes this instance to a JSON string.""" + return json.dumps(self.to_dict(), indent=2, sort_keys=True) + "\n" + + def to_json_file(self, json_file_path): + """ Save this instance to a json file.""" + with open(json_file_path, "w", encoding='utf-8') as writer: + writer.write(self.to_json_string()) + + +class BertEmbeddings(nn.Module): + """Construct the embeddings from word, position and token_type embeddings. + """ + + def __init__(self, config): + super(BertEmbeddings, self).__init__() + self.word_embeddings = nn.Embedding( + config.vocab_size, config.hidden_size, padding_idx=0) + self.position_embeddings = nn.Embedding( + config.max_position_embeddings, config.hidden_size) + self.token_type_embeddings = nn.Embedding( + config.type_vocab_size, config.hidden_size) + + # self.LayerNorm is not snake-cased to stick with TensorFlow model variable name and be able to load + # any TensorFlow checkpoint file + self.LayerNorm = BertLayerNorm(config.hidden_size, eps=1e-12) + self.dropout = nn.Dropout(config.hidden_dropout_prob) + + def forward(self, input_ids, token_type_ids=None): + seq_length = input_ids.size(1) + position_ids = torch.arange( + seq_length, dtype=torch.long, device=input_ids.device) + position_ids = position_ids.unsqueeze(0).expand_as(input_ids) + if token_type_ids is None: + token_type_ids = torch.zeros_like(input_ids) + + words_embeddings = self.word_embeddings(input_ids) + position_embeddings = self.position_embeddings(position_ids) + token_type_embeddings = self.token_type_embeddings(token_type_ids) + + embeddings = words_embeddings + position_embeddings + token_type_embeddings + embeddings = self.LayerNorm(embeddings) + embeddings = self.dropout(embeddings) + return embeddings + + +class BertSelfAttention(nn.Module): + def __init__(self, config): + super(BertSelfAttention, self).__init__() + if config.hidden_size % config.num_attention_heads != 0: + raise ValueError( + "The hidden size (%d) is not a multiple of the number of attention " + "heads (%d)" % (config.hidden_size, config.num_attention_heads)) + self.num_attention_heads = config.num_attention_heads + self.attention_head_size = int( + config.hidden_size / config.num_attention_heads) + self.all_head_size = self.num_attention_heads * self.attention_head_size + + self.query = nn.Linear(config.hidden_size, self.all_head_size) + self.key = nn.Linear(config.hidden_size, self.all_head_size) + self.value = nn.Linear(config.hidden_size, self.all_head_size) + + self.dropout = nn.Dropout(config.attention_probs_dropout_prob) + + def transpose_for_scores(self, x): + new_x_shape = x.size()[ + :-1] + (self.num_attention_heads, self.attention_head_size) + x = x.view(*new_x_shape) + return x.permute(0, 2, 1, 3) + + def forward(self, hidden_states, attention_mask, output_att=False): + mixed_query_layer = self.query(hidden_states) + mixed_key_layer = self.key(hidden_states) + mixed_value_layer = self.value(hidden_states) + + query_layer = self.transpose_for_scores(mixed_query_layer) + key_layer = self.transpose_for_scores(mixed_key_layer) + value_layer = self.transpose_for_scores(mixed_value_layer) + + # Take the dot product between "query" and "key" to get the raw attention scores. + attention_scores = torch.matmul( + query_layer, key_layer.transpose(-1, -2)) + attention_scores = attention_scores / \ + math.sqrt(self.attention_head_size) + # Apply the attention mask is (precomputed for all layers in BertModel forward() function) + attention_scores = attention_scores + attention_mask + + # Normalize the attention scores to probabilities. + attention_probs = nn.Softmax(dim=-1)(attention_scores) + + # This is actually dropping out entire tokens to attend to, which might + # seem a bit unusual, but is taken from the original Transformer paper. + attention_probs = self.dropout(attention_probs) + + context_layer = torch.matmul(attention_probs, value_layer) + context_layer = context_layer.permute(0, 2, 1, 3).contiguous() + new_context_layer_shape = context_layer.size()[ + :-2] + (self.all_head_size,) + context_layer = context_layer.view(*new_context_layer_shape) + return context_layer, attention_scores + + +class BertAttention(nn.Module): + def __init__(self, config): + super(BertAttention, self).__init__() + + self.self = BertSelfAttention(config) + self.output = BertSelfOutput(config) + + def forward(self, input_tensor, attention_mask): + self_output, layer_att = self.self(input_tensor, attention_mask) + attention_output = self.output(self_output, input_tensor) + return attention_output, layer_att + + +class BertSelfOutput(nn.Module): + def __init__(self, config): + super(BertSelfOutput, self).__init__() + self.dense = nn.Linear(config.hidden_size, config.hidden_size) + self.LayerNorm = BertLayerNorm(config.hidden_size, eps=1e-12) + self.dropout = nn.Dropout(config.hidden_dropout_prob) + + def forward(self, hidden_states, input_tensor): + hidden_states = self.dense(hidden_states) + hidden_states = self.dropout(hidden_states) + hidden_states = self.LayerNorm(hidden_states + input_tensor) + return hidden_states + + +class BertIntermediate(nn.Module): + def __init__(self, config, intermediate_size=-1): + super(BertIntermediate, self).__init__() + if intermediate_size < 0: + self.dense = nn.Linear( + config.hidden_size, config.intermediate_size) + else: + self.dense = nn.Linear(config.hidden_size, intermediate_size) + if isinstance(config.hidden_act, str) or (sys.version_info[0] == 2 and isinstance(config.hidden_act, unicode)): + self.intermediate_act_fn = ACT2FN[config.hidden_act] + else: + self.intermediate_act_fn = config.hidden_act + + def forward(self, hidden_states): + hidden_states = self.dense(hidden_states) + hidden_states = self.intermediate_act_fn(hidden_states) + return hidden_states + + +class BertOutput(nn.Module): + def __init__(self, config, intermediate_size=-1): + super(BertOutput, self).__init__() + if intermediate_size < 0: + self.dense = nn.Linear( + config.intermediate_size, config.hidden_size) + else: + self.dense = nn.Linear(intermediate_size, config.hidden_size) + self.LayerNorm = BertLayerNorm(config.hidden_size, eps=1e-12) + self.dropout = nn.Dropout(config.hidden_dropout_prob) + + def forward(self, hidden_states, input_tensor): + hidden_states = self.dense(hidden_states) + hidden_states = self.dropout(hidden_states) + hidden_states = self.LayerNorm(hidden_states + input_tensor) + return hidden_states + + +class BertLayer(nn.Module): + def __init__(self, config): + super(BertLayer, self).__init__() + self.attention = BertAttention(config) + self.intermediate = BertIntermediate(config) + self.output = BertOutput(config) + + def forward(self, hidden_states, attention_mask): + attention_output, layer_att = self.attention( + hidden_states, attention_mask) + intermediate_output = self.intermediate(attention_output) + layer_output = self.output(intermediate_output, attention_output) + + return layer_output, layer_att + + +class BertEncoder(nn.Module): + def __init__(self, config): + super(BertEncoder, self).__init__() + self.layer = nn.ModuleList([BertLayer(config) + for _ in range(config.num_hidden_layers)]) + + def forward(self, hidden_states, attention_mask): + all_encoder_layers = [] + all_encoder_atts = [] + for _, layer_module in enumerate(self.layer): + all_encoder_layers.append(hidden_states) + hidden_states, layer_att = layer_module( + hidden_states, attention_mask) + all_encoder_atts.append(layer_att) + + all_encoder_layers.append(hidden_states) + return all_encoder_layers, all_encoder_atts + + +class BertPooler(nn.Module): + def __init__(self, config, recurs=None): + super(BertPooler, self).__init__() + self.dense = nn.Linear(config.hidden_size, config.hidden_size) + self.activation = nn.Tanh() + self.config = config + + def forward(self, hidden_states): + # We "pool" the model by simply taking the hidden state corresponding + # to the first token. "-1" refers to last layer + pooled_output = hidden_states[-1][:, 0] + + pooled_output = self.dense(pooled_output) + pooled_output = self.activation(pooled_output) + + return pooled_output + + +class BertPredictionHeadTransform(nn.Module): + def __init__(self, config): + super(BertPredictionHeadTransform, self).__init__() + # Need to unty it when we separate the dimensions of hidden and emb + self.dense = nn.Linear(config.hidden_size, config.hidden_size) + if isinstance(config.hidden_act, str) or (sys.version_info[0] == 2 and isinstance(config.hidden_act, unicode)): + self.transform_act_fn = ACT2FN[config.hidden_act] + else: + self.transform_act_fn = config.hidden_act + self.LayerNorm = BertLayerNorm(config.hidden_size, eps=1e-12) + + def forward(self, hidden_states): + hidden_states = self.dense(hidden_states) + hidden_states = self.transform_act_fn(hidden_states) + hidden_states = self.LayerNorm(hidden_states) + return hidden_states + + +class BertLMPredictionHead(nn.Module): + def __init__(self, config, bert_model_embedding_weights): + super(BertLMPredictionHead, self).__init__() + self.transform = BertPredictionHeadTransform(config) + + # The output weights are the same as the input embeddings, but there is + # an output-only bias for each token. + self.decoder = nn.Linear(bert_model_embedding_weights.size(1), + bert_model_embedding_weights.size(0), + bias=False) + self.decoder.weight = bert_model_embedding_weights + self.bias = nn.Parameter(torch.zeros( + bert_model_embedding_weights.size(0))) + + def forward(self, hidden_states): + hidden_states = self.transform(hidden_states) + hidden_states = self.decoder(hidden_states) + self.bias + return hidden_states + + +class BertOnlyMLMHead(nn.Module): + def __init__(self, config, bert_model_embedding_weights): + super(BertOnlyMLMHead, self).__init__() + self.predictions = BertLMPredictionHead( + config, bert_model_embedding_weights) + + def forward(self, sequence_output): + prediction_scores = self.predictions(sequence_output) + return prediction_scores + + +class BertOnlyNSPHead(nn.Module): + def __init__(self, config): + super(BertOnlyNSPHead, self).__init__() + self.seq_relationship = nn.Linear(config.hidden_size, 2) + + def forward(self, pooled_output): + seq_relationship_score = self.seq_relationship(pooled_output) + return seq_relationship_score + + +class BertPreTrainingHeads(nn.Module): + def __init__(self, config, bert_model_embedding_weights): + super(BertPreTrainingHeads, self).__init__() + self.predictions = BertLMPredictionHead( + config, bert_model_embedding_weights) + self.seq_relationship = nn.Linear(config.hidden_size, 2) + + def forward(self, sequence_output, pooled_output): + prediction_scores = self.predictions(sequence_output) + seq_relationship_score = self.seq_relationship(pooled_output) + return prediction_scores, seq_relationship_score + + +class BertPreTrainedModel(nn.Module): + """ An abstract class to handle weights initialization and + a simple interface for dowloading and loading pretrained models. + """ + + def __init__(self, config, *inputs, **kwargs): + super(BertPreTrainedModel, self).__init__() + if not isinstance(config, BertConfig): + raise ValueError( + "Parameter config in `{}(config)` should be an instance of class `BertConfig`. " + "To create a model from a Google pretrained model use " + "`model = {}.from_pretrained(PRETRAINED_MODEL_NAME)`".format( + self.__class__.__name__, self.__class__.__name__ + )) + self.config = config + + def init_bert_weights(self, module): + """ Initialize the weights. + """ + if isinstance(module, (nn.Linear, nn.Embedding)): + # Slightly different from the TF version which uses truncated_normal for initialization + # cf https://github.com/pytorch/pytorch/pull/5617 + module.weight.data.normal_( + mean=0.0, std=self.config.initializer_range) + elif isinstance(module, BertLayerNorm): + module.bias.data.zero_() + module.weight.data.fill_(1.0) + if isinstance(module, nn.Linear) and module.bias is not None: + module.bias.data.zero_() + + @classmethod + def from_scratch(cls, pretrained_model_name_or_path, *inputs, **kwargs): + resolved_config_file = os.path.join( + pretrained_model_name_or_path, CONFIG_NAME) + config = BertConfig.from_json_file(resolved_config_file) + + logger.info("Model config {}".format(config)) + model = cls(config, *inputs, **kwargs) + return model + + @classmethod + def from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs): + """ + Instantiate a BertPreTrainedModel from a pre-trained model file or a pytorch state dict. + Download and cache the pre-trained model file if needed. + + Params: + pretrained_model_name_or_path: either: + - a str with the name of a pre-trained model to load selected in the list of: + . `bert-base-uncased` + . `bert-large-uncased` + . `bert-base-cased` + . `bert-large-cased` + . `bert-base-multilingual-uncased` + . `bert-base-multilingual-cased` + . `bert-base-chinese` + - a path or url to a pretrained model archive containing: + . `bert_config.json` a configuration file for the model + . `pytorch_model.bin` a PyTorch dump of a BertForPreTraining instance + - a path or url to a pretrained model archive containing: + . `bert_config.json` a configuration file for the model + . `model.chkpt` a TensorFlow checkpoint + from_tf: should we load the weights from a locally saved TensorFlow checkpoint + cache_dir: an optional path to a folder in which the pre-trained models will be cached. + state_dict: an optional state dictionnary (collections.OrderedDict object) to use instead of Google pre-trained models + *inputs, **kwargs: additional input for the specific Bert class + (ex: num_labels for BertForSequenceClassification) + """ + state_dict = kwargs.get('state_dict', None) + kwargs.pop('state_dict', None) + from_tf = kwargs.get('from_tf', False) + kwargs.pop('from_tf', None) + + # Load config + config_file = os.path.join(pretrained_model_name_or_path, CONFIG_NAME) + config = BertConfig.from_json_file(config_file) + logger.info("Model config {}".format(config)) + # Instantiate model. + + model = cls(config, *inputs, **kwargs) + if state_dict is None and not from_tf: + weights_path = os.path.join( + pretrained_model_name_or_path, WEIGHTS_NAME) + logger.info("Loading model {}".format(weights_path)) + state_dict = torch.load(weights_path, map_location='cpu') + state_dict.pop('classifier.weight') + state_dict.pop('classifier.bias') + if from_tf: + # Directly load from a TensorFlow checkpoint + weights_path = os.path.join( + pretrained_model_name_or_path, TF_WEIGHTS_NAME) + return load_tf_weights_in_bert(model, weights_path) + # Load from a PyTorch state_dict + old_keys = [] + new_keys = [] + for key in state_dict.keys(): + new_key = None + if 'gamma' in key: + new_key = key.replace('gamma', 'weight') + if 'beta' in key: + new_key = key.replace('beta', 'bias') + if new_key: + old_keys.append(key) + new_keys.append(new_key) + for old_key, new_key in zip(old_keys, new_keys): + state_dict[new_key] = state_dict.pop(old_key) + + missing_keys = [] + unexpected_keys = [] + error_msgs = [] + # copy state_dict so _load_from_state_dict can modify it + metadata = getattr(state_dict, '_metadata', None) + state_dict = state_dict.copy() + if metadata is not None: + state_dict._metadata = metadata + + def load(module, prefix=''): + local_metadata = {} if metadata is None else metadata.get( + prefix[:-1], {}) + module._load_from_state_dict( + state_dict, prefix, local_metadata, True, missing_keys, unexpected_keys, error_msgs) + for name, child in module._modules.items(): + if child is not None: + load(child, prefix + name + '.') + + start_prefix = '' + if not hasattr(model, 'bert') and any(s.startswith('bert.') for s in state_dict.keys()): + start_prefix = 'bert.' + + logger.info('loading model...') + load(model, prefix=start_prefix) + logger.info('done!') + if len(missing_keys) > 0: + logger.info("Weights of {} not initialized from pretrained model: {}".format( + model.__class__.__name__, missing_keys)) + if len(unexpected_keys) > 0: + logger.info("Weights from pretrained model not used in {}: {}".format( + model.__class__.__name__, unexpected_keys)) + if len(error_msgs) > 0: + raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( + model.__class__.__name__, "\n\t".join(error_msgs))) + + return model + + +class BertModel(BertPreTrainedModel): + """BERT model ("Bidirectional Embedding Representations from a Transformer"). + + Params: + config: a BertConfig class instance with the configuration to build a new model + + Inputs: + `input_ids`: a torch.LongTensor of shape [batch_size, sequence_length] + with the word token indices in the vocabulary(see the tokens preprocessing logic in the scripts + `extract_features.py`, `run_classifier.py` and `run_squad.py`) + `token_type_ids`: an optional torch.LongTensor of shape [batch_size, sequence_length] with the token + types indices selected in [0, 1]. Type 0 corresponds to a `sentence A` and type 1 corresponds to + a `sentence B` token (see BERT paper for more details). + `attention_mask`: an optional torch.LongTensor of shape [batch_size, sequence_length] with indices + selected in [0, 1]. It's a mask to be used if the input sequence length is smaller than the max + input sequence length in the current batch. It's the mask that we typically use for attention when + a batch has varying length sentences. + `output_all_encoded_layers`: boolean which controls the content of the `encoded_layers` output as described below. Default: `True`. + + Outputs: Tuple of (encoded_layers, pooled_output) + `encoded_layers`: controled by `output_all_encoded_layers` argument: + - `output_all_encoded_layers=True`: outputs a list of the full sequences of encoded-hidden-states at the end + of each attention block (i.e. 12 full sequences for BERT-base, 24 for BERT-large), each + encoded-hidden-state is a torch.FloatTensor of size [batch_size, sequence_length, hidden_size], + - `output_all_encoded_layers=False`: outputs only the full sequence of hidden-states corresponding + to the last attention block of shape [batch_size, sequence_length, hidden_size], + `pooled_output`: a torch.FloatTensor of size [batch_size, hidden_size] which is the output of a + classifier pretrained on top of the hidden state associated to the first character of the + input (`CLS`) to train on the Next-Sentence task (see BERT's paper). + + Example usage: + ```python + # Already been converted into WordPiece token ids + input_ids = torch.LongTensor([[31, 51, 99], [15, 5, 0]]) + input_mask = torch.LongTensor([[1, 1, 1], [1, 1, 0]]) + token_type_ids = torch.LongTensor([[0, 0, 1], [0, 1, 0]]) + + config = modeling.BertConfig(vocab_size_or_config_json_file=32000, hidden_size=768, + num_hidden_layers=12, num_attention_heads=12, intermediate_size=3072) + + model = modeling.BertModel(config=config) + all_encoder_layers, pooled_output = model(input_ids, token_type_ids, input_mask) + ``` + """ + + def __init__(self, config): + super(BertModel, self).__init__(config) + self.embeddings = BertEmbeddings(config) + self.encoder = BertEncoder(config) + self.pooler = BertPooler(config) + self.apply(self.init_bert_weights) + + def forward(self, input_ids, token_type_ids=None, attention_mask=None, + output_all_encoded_layers=True, output_att=True): + + if attention_mask is None: + attention_mask = torch.ones_like(input_ids) + if token_type_ids is None: + token_type_ids = torch.zeros_like(input_ids) + + # We create a 3D attention mask from a 2D tensor mask. + # Sizes are [batch_size, 1, 1, to_seq_length] + # So we can broadcast to [batch_size, num_heads, from_seq_length, to_seq_length] + # this attention mask is more simple than the triangular masking of causal attention + # used in OpenAI GPT, we just need to prepare the broadcast dimension here. + extended_attention_mask = attention_mask.unsqueeze(1).unsqueeze(2) + + # Since attention_mask is 1.0 for positions we want to attend and 0.0 for + # masked positions, this operation will create a tensor which is 0.0 for + # positions we want to attend and -10000.0 for masked positions. + # Since we are adding it to the raw scores before the softmax, this is + # effectively the same as removing these entirely. + extended_attention_mask = extended_attention_mask.to( + dtype=next(self.parameters()).dtype) # fp16 compatibility + extended_attention_mask = (1.0 - extended_attention_mask) * -10000.0 + + embedding_output = self.embeddings(input_ids, token_type_ids) + encoded_layers, layer_atts = self.encoder(embedding_output, + extended_attention_mask) + + pooled_output = self.pooler(encoded_layers) + if not output_all_encoded_layers: + encoded_layers = encoded_layers[-1] + + if not output_att: + return encoded_layers, pooled_output + + return encoded_layers, layer_atts, pooled_output + + +class BertForPreTraining(BertPreTrainedModel): + """BERT model with pre-training heads. + This module comprises the BERT model followed by the two pre-training heads: + - the masked language modeling head, and + - the next sentence classification head. + + Params: + config: a BertConfig class instance with the configuration to build a new model. + + Inputs: + `input_ids`: a torch.LongTensor of shape [batch_size, sequence_length] + with the word token indices in the vocabulary(see the tokens preprocessing logic in the scripts + `extract_features.py`, `run_classifier.py` and `run_squad.py`) + `token_type_ids`: an optional torch.LongTensor of shape [batch_size, sequence_length] with the token + types indices selected in [0, 1]. Type 0 corresponds to a `sentence A` and type 1 corresponds to + a `sentence B` token (see BERT paper for more details). + `attention_mask`: an optional torch.LongTensor of shape [batch_size, sequence_length] with indices + selected in [0, 1]. It's a mask to be used if the input sequence length is smaller than the max + input sequence length in the current batch. It's the mask that we typically use for attention when + a batch has varying length sentences. + `masked_lm_labels`: optional masked language modeling labels: torch.LongTensor of shape [batch_size, sequence_length] + with indices selected in [-1, 0, ..., vocab_size]. All labels set to -1 are ignored (masked), the loss + is only computed for the labels set in [0, ..., vocab_size] + `next_sentence_label`: optional next sentence classification loss: torch.LongTensor of shape [batch_size] + with indices selected in [0, 1]. + 0 => next sentence is the continuation, 1 => next sentence is a random sentence. + + Outputs: + if `masked_lm_labels` and `next_sentence_label` are not `None`: + Outputs the total_loss which is the sum of the masked language modeling loss and the next + sentence classification loss. + if `masked_lm_labels` or `next_sentence_label` is `None`: + Outputs a tuple comprising + - the masked language modeling logits of shape [batch_size, sequence_length, vocab_size], and + - the next sentence classification logits of shape [batch_size, 2]. + + Example usage: + ```python + # Already been converted into WordPiece token ids + input_ids = torch.LongTensor([[31, 51, 99], [15, 5, 0]]) + input_mask = torch.LongTensor([[1, 1, 1], [1, 1, 0]]) + token_type_ids = torch.LongTensor([[0, 0, 1], [0, 1, 0]]) + + config = BertConfig(vocab_size_or_config_json_file=32000, hidden_size=768, + num_hidden_layers=12, num_attention_heads=12, intermediate_size=3072) + + model = BertForPreTraining(config) + masked_lm_logits_scores, seq_relationship_logits = model(input_ids, token_type_ids, input_mask) + ``` + """ + + def __init__(self, config): + super(BertForPreTraining, self).__init__(config) + self.bert = BertModel(config) + self.cls = BertPreTrainingHeads( + config, self.bert.embeddings.word_embeddings.weight) + self.apply(self.init_bert_weights) + + def forward(self, input_ids, token_type_ids=None, attention_mask=None, + masked_lm_labels=None, next_sentence_label=None): + sequence_output, pooled_output = self.bert(input_ids, token_type_ids, attention_mask, + output_all_encoded_layers=False) + prediction_scores, seq_relationship_score = self.cls( + sequence_output, pooled_output) + + if masked_lm_labels is not None and next_sentence_label is not None: + loss_fct = CrossEntropyLoss(ignore_index=-1) + masked_lm_loss = loss_fct( + prediction_scores.view(-1, self.config.vocab_size), masked_lm_labels.view(-1)) + next_sentence_loss = loss_fct( + seq_relationship_score.view(-1, 2), next_sentence_label.view(-1)) + total_loss = masked_lm_loss + next_sentence_loss + return total_loss + elif masked_lm_labels is not None: + loss_fct = CrossEntropyLoss(ignore_index=-1) + masked_lm_loss = loss_fct( + prediction_scores.view(-1, self.config.vocab_size), masked_lm_labels.view(-1)) + total_loss = masked_lm_loss + return total_loss + else: + return prediction_scores, seq_relationship_score + + +class TinyBertForPreTraining(BertPreTrainedModel): + def __init__(self, config, fit_size=768): + super(TinyBertForPreTraining, self).__init__(config) + self.bert = BertModel(config) + self.cls = BertPreTrainingHeads( + config, self.bert.embeddings.word_embeddings.weight) + self.fit_dense = nn.Linear(config.hidden_size, fit_size) + self.apply(self.init_bert_weights) + + def forward(self, input_ids, token_type_ids=None, + attention_mask=None, masked_lm_labels=None, + next_sentence_label=None, labels=None): + sequence_output, att_output, pooled_output = self.bert( + input_ids, token_type_ids, attention_mask) + tmp = [] + for s_id, sequence_layer in enumerate(sequence_output): + tmp.append(self.fit_dense(sequence_layer)) + sequence_output = tmp + + return att_output, sequence_output + + +class BertForMaskedLM(BertPreTrainedModel): + """BERT model with the masked language modeling head. + This module comprises the BERT model followed by the masked language modeling head. + + Params: + config: a BertConfig class instance with the configuration to build a new model. + + Inputs: + `input_ids`: a torch.LongTensor of shape [batch_size, sequence_length] + with the word token indices in the vocabulary(see the tokens preprocessing logic in the scripts + `extract_features.py`, `run_classifier.py` and `run_squad.py`) + `token_type_ids`: an optional torch.LongTensor of shape [batch_size, sequence_length] with the token + types indices selected in [0, 1]. Type 0 corresponds to a `sentence A` and type 1 corresponds to + a `sentence B` token (see BERT paper for more details). + `attention_mask`: an optional torch.LongTensor of shape [batch_size, sequence_length] with indices + selected in [0, 1]. It's a mask to be used if the input sequence length is smaller than the max + input sequence length in the current batch. It's the mask that we typically use for attention when + a batch has varying length sentences. + `masked_lm_labels`: masked language modeling labels: torch.LongTensor of shape [batch_size, sequence_length] + with indices selected in [-1, 0, ..., vocab_size]. All labels set to -1 are ignored (masked), the loss + is only computed for the labels set in [0, ..., vocab_size] + + Outputs: + if `masked_lm_labels` is not `None`: + Outputs the masked language modeling loss. + if `masked_lm_labels` is `None`: + Outputs the masked language modeling logits of shape [batch_size, sequence_length, vocab_size]. + + Example usage: + ```python + # Already been converted into WordPiece token ids + input_ids = torch.LongTensor([[31, 51, 99], [15, 5, 0]]) + input_mask = torch.LongTensor([[1, 1, 1], [1, 1, 0]]) + token_type_ids = torch.LongTensor([[0, 0, 1], [0, 1, 0]]) + + config = BertConfig(vocab_size_or_config_json_file=32000, hidden_size=768, + num_hidden_layers=12, num_attention_heads=12, intermediate_size=3072) + + model = BertForMaskedLM(config) + masked_lm_logits_scores = model(input_ids, token_type_ids, input_mask) + ``` + """ + + def __init__(self, config): + super(BertForMaskedLM, self).__init__(config) + self.bert = BertModel(config) + self.cls = BertOnlyMLMHead( + config, self.bert.embeddings.word_embeddings.weight) + self.apply(self.init_bert_weights) + + def forward(self, input_ids, token_type_ids=None, attention_mask=None, masked_lm_labels=None, + output_att=False, infer=False): + sequence_output, _ = self.bert(input_ids, token_type_ids, attention_mask, + output_all_encoded_layers=True, output_att=output_att) + + if output_att: + sequence_output, att_output = sequence_output + prediction_scores = self.cls(sequence_output[-1]) + + if masked_lm_labels is not None: + loss_fct = CrossEntropyLoss(ignore_index=-1) + masked_lm_loss = loss_fct( + prediction_scores.view(-1, self.config.vocab_size), masked_lm_labels.view(-1)) + if not output_att: + return masked_lm_loss + else: + return masked_lm_loss, att_output + else: + if not output_att: + return prediction_scores + else: + return prediction_scores, att_output + + +class BertForNextSentencePrediction(BertPreTrainedModel): + """BERT model with next sentence prediction head. + This module comprises the BERT model followed by the next sentence classification head. + + Params: + config: a BertConfig class instance with the configuration to build a new model. + + Inputs: + `input_ids`: a torch.LongTensor of shape [batch_size, sequence_length] + with the word token indices in the vocabulary(see the tokens preprocessing logic in the scripts + `extract_features.py`, `run_classifier.py` and `run_squad.py`) + `token_type_ids`: an optional torch.LongTensor of shape [batch_size, sequence_length] with the token + types indices selected in [0, 1]. Type 0 corresponds to a `sentence A` and type 1 corresponds to + a `sentence B` token (see BERT paper for more details). + `attention_mask`: an optional torch.LongTensor of shape [batch_size, sequence_length] with indices + selected in [0, 1]. It's a mask to be used if the input sequence length is smaller than the max + input sequence length in the current batch. It's the mask that we typically use for attention when + a batch has varying length sentences. + `next_sentence_label`: next sentence classification loss: torch.LongTensor of shape [batch_size] + with indices selected in [0, 1]. + 0 => next sentence is the continuation, 1 => next sentence is a random sentence. + + Outputs: + if `next_sentence_label` is not `None`: + Outputs the total_loss which is the sum of the masked language modeling loss and the next + sentence classification loss. + if `next_sentence_label` is `None`: + Outputs the next sentence classification logits of shape [batch_size, 2]. + + Example usage: + ```python + # Already been converted into WordPiece token ids + input_ids = torch.LongTensor([[31, 51, 99], [15, 5, 0]]) + input_mask = torch.LongTensor([[1, 1, 1], [1, 1, 0]]) + token_type_ids = torch.LongTensor([[0, 0, 1], [0, 1, 0]]) + + config = BertConfig(vocab_size_or_config_json_file=32000, hidden_size=768, + num_hidden_layers=12, num_attention_heads=12, intermediate_size=3072) + + model = BertForNextSentencePrediction(config) + seq_relationship_logits = model(input_ids, token_type_ids, input_mask) + ``` + """ + + def __init__(self, config): + super(BertForNextSentencePrediction, self).__init__(config) + self.bert = BertModel(config) + self.cls = BertOnlyNSPHead(config) + self.apply(self.init_bert_weights) + + def forward(self, input_ids, token_type_ids=None, attention_mask=None, next_sentence_label=None): + _, pooled_output = self.bert(input_ids, token_type_ids, attention_mask, + output_all_encoded_layers=False) + seq_relationship_score = self.cls(pooled_output) + + if next_sentence_label is not None: + loss_fct = CrossEntropyLoss(ignore_index=-1) + next_sentence_loss = loss_fct( + seq_relationship_score.view(-1, 2), next_sentence_label.view(-1)) + return next_sentence_loss + else: + return seq_relationship_score + + +class BertForSentencePairClassification(BertPreTrainedModel): + def __init__(self, config, num_labels): + super(BertForSentencePairClassification, self).__init__(config) + self.num_labels = num_labels + self.bert = BertModel(config) + self.dropout = nn.Dropout(config.hidden_dropout_prob) + self.classifier = nn.Linear(config.hidden_size * 3, num_labels) + self.apply(self.init_bert_weights) + + def forward(self, a_input_ids, b_input_ids, a_token_type_ids=None, b_token_type_ids=None, + a_attention_mask=None, b_attention_mask=None, labels=None): + _, a_pooled_output = self.bert( + a_input_ids, a_token_type_ids, a_attention_mask, output_all_encoded_layers=False) + # a_pooled_output = self.dropout(a_pooled_output) + + _, b_pooled_output = self.bert( + b_input_ids, b_token_type_ids, b_attention_mask, output_all_encoded_layers=False) + # b_pooled_output = self.dropout(b_pooled_output) + + logits = self.classifier(torch.relu(torch.cat((a_pooled_output, b_pooled_output, + torch.abs(a_pooled_output - b_pooled_output)), -1))) + + if labels is not None: + loss_fct = CrossEntropyLoss() + loss = loss_fct(logits.view(-1, self.num_labels), labels.view(-1)) + return loss + else: + return logits + + +class TinyBertForSequenceClassification_for_finetune(BertPreTrainedModel): + def __init__(self, config, num_labels, fit_size=768): + super(TinyBertForSequenceClassification_for_finetune, self).__init__(config) + self.num_labels = num_labels + self.bert = BertModel(config) + self.dropout = nn.Dropout(config.hidden_dropout_prob) + self.classifier = nn.Linear(config.hidden_size, num_labels) + self.fit_dense = nn.Linear(config.hidden_size, fit_size) + self.apply(self.init_bert_weights) + + def forward(self, input_ids, token_type_ids=None, attention_mask=None, + labels=None, is_student=False): + + sequence_output, att_output, pooled_output = self.bert(input_ids, token_type_ids, attention_mask, + output_all_encoded_layers=True, output_att=True) + + logits = self.classifier(torch.relu(pooled_output)) + + tmp = [] + if is_student: + for s_id, sequence_layer in enumerate(sequence_output): + tmp.append(self.fit_dense(sequence_layer)) + sequence_output = tmp + return logits, att_output, sequence_output diff --git a/PyTorch/contrib/others/DQN/train_dqn.py b/PyTorch/contrib/others/DQN/train_dqn.py index 06d1210a1e96f0da05cd29d1bcdcfff82e54c4a6..feca5641edf8f358e8e31801f3d6ca811bef1f30 100644 --- a/PyTorch/contrib/others/DQN/train_dqn.py +++ b/PyTorch/contrib/others/DQN/train_dqn.py @@ -1,38 +1,38 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from examples import * - -if __name__ == '__main__': - cf = Config() - cf.add_argument('--game', type=str, default='BreakoutNoFrameskip-v4') - cf.add_argument('--use_device', type=str, default='use_npu') - cf.add_argument('--device_id', type=int, default=0) - cf.add_argument('--max_steps', type=int, default=2e7) - cf.add_argument('--save_interval', type=int, default=0) - cf.add_argument('--eval_interval', type=int, default=0) - cf.add_argument('--log_interval', type=int, default=1e3) - cf.add_argument('--tag', type=str, default=None) - cf.add_argument('--pth_path', type=str, default='null') - cf.add_argument('--status_path', type=str, default='null') - cf.merge() - - param = dict(game=cf.game, max_steps=cf.max_steps, save_interval=cf.save_interval, eval_interval=cf.eval_interval, - log_interval=cf.log_interval, pth_path=cf.pth_path, status_path=cf.status_path, tag=cf.tag, device_id=cf.device_id,maxremark=dqn_pixel.__name__) - - mkdir('data') - random_seed() - select_device(cf.use_device, cf.device_id) - dqn_pixel(**param) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from examples import * + +if __name__ == '__main__': + cf = Config() + cf.add_argument('--game', type=str, default='BreakoutNoFrameskip-v4') + cf.add_argument('--use_device', type=str, default='use_npu') + cf.add_argument('--device_id', type=int, default=0) + cf.add_argument('--max_steps', type=int, default=2e7) + cf.add_argument('--save_interval', type=int, default=0) + cf.add_argument('--eval_interval', type=int, default=0) + cf.add_argument('--log_interval', type=int, default=1e3) + cf.add_argument('--tag', type=str, default=None) + cf.add_argument('--pth_path', type=str, default='null') + cf.add_argument('--status_path', type=str, default='null') + cf.merge() + + param = dict(game=cf.game, max_steps=cf.max_steps, save_interval=cf.save_interval, eval_interval=cf.eval_interval, + log_interval=cf.log_interval, pth_path=cf.pth_path, status_path=cf.status_path, tag=cf.tag, device_id=cf.device_id,maxremark=dqn_pixel.__name__) + + mkdir('data') + random_seed() + select_device(cf.use_device, cf.device_id) + dqn_pixel(**param) exit() \ No newline at end of file diff --git a/PyTorch/dev/cv/detection/FasterRCNN-Resnet50-FPN_ID1552_for_PyTorch/README.md b/PyTorch/dev/cv/detection/FasterRCNN-Resnet50-FPN_ID1552_for_PyTorch/README.md index 9ce0995753e74a1de90b678c774bdcebe428a022..83e71bddbacfe2862060d86786a70460aa47a6ae 100644 --- a/PyTorch/dev/cv/detection/FasterRCNN-Resnet50-FPN_ID1552_for_PyTorch/README.md +++ b/PyTorch/dev/cv/detection/FasterRCNN-Resnet50-FPN_ID1552_for_PyTorch/README.md @@ -1,102 +1,102 @@ -- [基本信息](#基本信息.md) -- [概述](#概述.md) -- [训练环境准备](#训练环境准备.md) -- [快速上手](#快速上手.md) - -

基本信息

- -**发布者(Publisher):huawei** - -**应用领域(Application Domain):Object Detection** - -**版本(Version):1.0** - -**修改时间(Modified) :2021.05.20** - -_**大小(Size)**_**:318M** - -**框架(Framework):PyTorch1.5** - -**模型格式(Model Format):pth** - -**精度(Precision):Mixed** - -**处理器(Processor):昇腾910** - -**应用级别(Categories):Research** - -**描述(Description):基于PyTorch框架的FasterRCNN目标检测网络** - -

概述

-Faster R-CNN是截至目前,RCNN系列算法的最杰出产物,two-stage中最为经典的物体检测算法。推理第一阶段先找出图片中待检测物体的anchor矩形框(对背景、待检测物体进行二分类),第二阶段对anchor框内待检测物体进行分类。R-CNN系列物体检测算法的思路都是先产生一些待检测框,再对检测框进行分类。Faster R-CNN使用神经网络生成待检测框,替代了其他R-CNN算法中通过规则等产生候选框的方法,从而实现了端到端训练,并且大幅提速。本文档描述的Faster R-CNN是基于PyTorch实现的版本。 - -- 参考实现: - - https://github.com/facebookresearch/detectron2 - -- 适配昇腾 AI 处理器的实现: - - https://gitee.com/ascend/modelzoo/tree/master/built-in/PyTorch/Research/cv/detection/Faster_Mask_RCNN_for_PyTorch - -

训练环境准备

- -硬件环境准备请参见[各硬件产品文档](https://ascend.huawei.com/#/document?tag=developer)。需要在硬件设备上安装固件与驱动。 - -关键依赖请获取NPU适配版本: - -PyTorch - -apex - -tensor-fused-plugin - -另外该代码运行需要从源编译库: - - cd Faster_Mask_RCNN_for_PyTorch - python3 -m pip install -e ./ -## 默认配置 - -- 训练超参(8卡): - - Batch size: 16(2 per device) - - Momentum: 0.9 - - LR scheduler: step - - Learning rate\(LR\): 0.02 - - Weight decay: 0.0001 - - Label smoothing: 0.1 - - Train epoch: 12 - - -## 混合精度训练 - -昇腾910 AI处理器提供自动混合精度功能,可以针对全网中float32数据类型的算子,按照内置的优化策略,自动将部分float32的算子降低精度到float16,从而在精度损失很小的情况下提升系统性能并减少内存使用。 - -## 开启混合精度 -在启动脚本中执行训练脚本处配置命令行参数 AMP 1 即可开启NPU上混合精度训练模式。 - - -## 数据集准备 - -默认使用coco2017数据集,请用户自行获取。数据集路径通过启动脚本的命令行参数--data_path配置。应有如下目录结构 - -/path/to/dataset/coco - -## 快速上手 - -1.下载预训练模型。 - -以resnet50为例: - -wget https://dl.fbaipublicfiles.com/detectron2/ImageNetPretrained/MSRA/R-50.pkl - -将其置于数据集所在目录下 - -另附resnet101[下载地址](https://dl.fbaipublicfiles.com/detectron2/ImageNetPretrained/MSRA/R-101.pkl) - -2.开始训练。 -- 单机单卡 - - cd test && bash ./train_full_1p.sh --data_path=/path/to/dataset - -- 单机8卡 - - cd test && bash ./train_full_8p.sh --data_path=/path/to/dataset +- [基本信息](#基本信息.md) +- [概述](#概述.md) +- [训练环境准备](#训练环境准备.md) +- [快速上手](#快速上手.md) + +

基本信息

+ +**发布者(Publisher):huawei** + +**应用领域(Application Domain):Object Detection** + +**版本(Version):1.0** + +**修改时间(Modified) :2021.05.20** + +_**大小(Size)**_**:318M** + +**框架(Framework):PyTorch1.5** + +**模型格式(Model Format):pth** + +**精度(Precision):Mixed** + +**处理器(Processor):昇腾910** + +**应用级别(Categories):Research** + +**描述(Description):基于PyTorch框架的FasterRCNN目标检测网络** + +

概述

+Faster R-CNN是截至目前,RCNN系列算法的最杰出产物,two-stage中最为经典的物体检测算法。推理第一阶段先找出图片中待检测物体的anchor矩形框(对背景、待检测物体进行二分类),第二阶段对anchor框内待检测物体进行分类。R-CNN系列物体检测算法的思路都是先产生一些待检测框,再对检测框进行分类。Faster R-CNN使用神经网络生成待检测框,替代了其他R-CNN算法中通过规则等产生候选框的方法,从而实现了端到端训练,并且大幅提速。本文档描述的Faster R-CNN是基于PyTorch实现的版本。 + +- 参考实现: + + https://github.com/facebookresearch/detectron2 + +- 适配昇腾 AI 处理器的实现: + + https://gitee.com/ascend/modelzoo/tree/master/built-in/PyTorch/Research/cv/detection/Faster_Mask_RCNN_for_PyTorch + +

训练环境准备

+ +硬件环境准备请参见[各硬件产品文档](https://ascend.huawei.com/#/document?tag=developer)。需要在硬件设备上安装固件与驱动。 + +关键依赖请获取NPU适配版本: + +PyTorch + +apex + +tensor-fused-plugin + +另外该代码运行需要从源编译库: + + cd Faster_Mask_RCNN_for_PyTorch + python3 -m pip install -e ./ +## 默认配置 + +- 训练超参(8卡): + - Batch size: 16(2 per device) + - Momentum: 0.9 + - LR scheduler: step + - Learning rate\(LR\): 0.02 + - Weight decay: 0.0001 + - Label smoothing: 0.1 + - Train epoch: 12 + + +## 混合精度训练 + +昇腾910 AI处理器提供自动混合精度功能,可以针对全网中float32数据类型的算子,按照内置的优化策略,自动将部分float32的算子降低精度到float16,从而在精度损失很小的情况下提升系统性能并减少内存使用。 + +## 开启混合精度 +在启动脚本中执行训练脚本处配置命令行参数 AMP 1 即可开启NPU上混合精度训练模式。 + + +## 数据集准备 + +默认使用coco2017数据集,请用户自行获取。数据集路径通过启动脚本的命令行参数--data_path配置。应有如下目录结构 + +/path/to/dataset/coco + +## 快速上手 + +1.下载预训练模型。 + +以resnet50为例: + +wget https://dl.fbaipublicfiles.com/detectron2/ImageNetPretrained/MSRA/R-50.pkl + +将其置于数据集所在目录下 + +另附resnet101[下载地址](https://dl.fbaipublicfiles.com/detectron2/ImageNetPretrained/MSRA/R-101.pkl) + +2.开始训练。 +- 单机单卡 + + cd test && bash ./train_full_1p.sh --data_path=/path/to/dataset + +- 单机8卡 + + cd test && bash ./train_full_8p.sh --data_path=/path/to/dataset diff --git a/PyTorch/dev/cv/image_classification/2D_Unet_ID0624_for_PyTorch/test/train_full_8p.sh b/PyTorch/dev/cv/image_classification/2D_Unet_ID0624_for_PyTorch/test/train_full_8p.sh index 504e63730482fa99c7f893e1fa66f635d6015aa0..0456da4f2275cf70ebe7dfc537c409cdb2e0e814 100644 --- a/PyTorch/dev/cv/image_classification/2D_Unet_ID0624_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/dev/cv/image_classification/2D_Unet_ID0624_for_PyTorch/test/train_full_8p.sh @@ -1,125 +1,125 @@ -#!/bin/bash - -cur_path=`pwd`/../ -#失败用例打屏 -export ASCEND_SLOG_PRINT_TO_STDOUT=0 - -#基础参数,需要模型审视修改 -#Batch Size -batch_size=1 -#网络名称,同目录名称 -Network="2D_Unet_ID0624_for_PyTorch" -#Device数量,单卡默认为1 -RANK_SIZE=8 -#训练epoch,可选 -train_epochs=5 -#训练step -train_steps= -#学习率 -learning_rate=1e-3 -#参数配置 -data_path="" - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_accormance_1p.sh " - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be config" - exit 1 -fi -##############执行训练########## -cd $cur_path -if [ -d $cur_path/test/output ];then - rm -rf $cur_path/test/output/* - mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID -fi -wait - -export HCCL_WHITELIST_DISABLE=1 -export MASTER_ADDR=127.0.0.1 -export MASTER_PORT=23456 - - -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID -sed -i "s|data/imgs/|$data_path/imgs/|g" $cur_path/train.py -sed -i "s|data/masks/|$data_path/masks/|g" $cur_path/train.py -start=$(date +%s) -#nohup python3 train.py -e $train_epochs > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & - - -NPUS=($(seq 0 7)) -export NPU_WORLD_SIZE=${#NPUS[@]} -rank=0 -for i in ${NPUS[@]} -do - mkdir -p $cur_path/test/output/${i}/ - export NPU_CALCULATE_DEVICE=${i} - export ASCEND_DEVICE_ID=${i} - export RANK=${rank} - echo run process ${rank} - nohup python3 train.py -e $train_epochs -l 0.0001 --distributed True > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & - let rank++ -done -wait -end=$(date +%s) -e2e_time=$(( $end - $start )) - - - -#输出训练精度,需要模型审视修改 -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -sed -i "s|\r|\n|g" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log -TrainingTime=0 -FPS=`grep img/s $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |grep -v 0% | awk -F "," '{print$2}' | awk '{print$1}' | awk -F "i" '{print$1}' | awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` -FPS=$(awk 'BEGIN{print '$FPS'*8}') -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${FPS}'}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -ActualFPS=${FPS} - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| awk -F "," '{print$3}' | awk -F "=" '{print$2}' | awk -F "]" '{print$1}'| awk '{if(length !=0)print $0}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - - -#精度值 -train_accuracy=`grep "Validation Dice" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $NF}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log - +#!/bin/bash + +cur_path=`pwd`/../ +#失败用例打屏 +export ASCEND_SLOG_PRINT_TO_STDOUT=0 + +#基础参数,需要模型审视修改 +#Batch Size +batch_size=1 +#网络名称,同目录名称 +Network="2D_Unet_ID0624_for_PyTorch" +#Device数量,单卡默认为1 +RANK_SIZE=8 +#训练epoch,可选 +train_epochs=5 +#训练step +train_steps= +#学习率 +learning_rate=1e-3 +#参数配置 +data_path="" + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_accormance_1p.sh " + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be config" + exit 1 +fi +##############执行训练########## +cd $cur_path +if [ -d $cur_path/test/output ];then + rm -rf $cur_path/test/output/* + mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID +fi +wait + +export HCCL_WHITELIST_DISABLE=1 +export MASTER_ADDR=127.0.0.1 +export MASTER_PORT=23456 + + +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID +sed -i "s|data/imgs/|$data_path/imgs/|g" $cur_path/train.py +sed -i "s|data/masks/|$data_path/masks/|g" $cur_path/train.py +start=$(date +%s) +#nohup python3 train.py -e $train_epochs > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & + + +NPUS=($(seq 0 7)) +export NPU_WORLD_SIZE=${#NPUS[@]} +rank=0 +for i in ${NPUS[@]} +do + mkdir -p $cur_path/test/output/${i}/ + export NPU_CALCULATE_DEVICE=${i} + export ASCEND_DEVICE_ID=${i} + export RANK=${rank} + echo run process ${rank} + nohup python3 train.py -e $train_epochs -l 0.0001 --distributed True > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & + let rank++ +done +wait +end=$(date +%s) +e2e_time=$(( $end - $start )) + + + +#输出训练精度,需要模型审视修改 +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +sed -i "s|\r|\n|g" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log +TrainingTime=0 +FPS=`grep img/s $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log |grep -v 0% | awk -F "," '{print$2}' | awk '{print$1}' | awk -F "i" '{print$1}' | awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` +FPS=$(awk 'BEGIN{print '$FPS'*8}') +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${FPS}'}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +ActualFPS=${FPS} + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| awk -F "," '{print$3}' | awk -F "=" '{print$2}' | awk -F "]" '{print$1}'| awk '{if(length !=0)print $0}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + + +#精度值 +train_accuracy=`grep "Validation Dice" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk '{print $NF}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log + diff --git a/PyTorch/dev/cv/image_classification/2D_Unet_ID0624_for_PyTorch/test/train_performance_16p.sh b/PyTorch/dev/cv/image_classification/2D_Unet_ID0624_for_PyTorch/test/train_performance_16p.sh index cff304ed2b1e884cd43873500eb8a05e552d8112..6c6f6681d92bef47bf582890d7bfb1d1057d5ce8 100644 --- a/PyTorch/dev/cv/image_classification/2D_Unet_ID0624_for_PyTorch/test/train_performance_16p.sh +++ b/PyTorch/dev/cv/image_classification/2D_Unet_ID0624_for_PyTorch/test/train_performance_16p.sh @@ -1,149 +1,149 @@ -#!/bin/bash - -cur_path=`pwd`/../ -#失败用例打屏 -export ASCEND_SLOG_PRINT_TO_STDOUT=0 - -source /usr/local/Ascend/bin/setenv.bash - -export PATH=/usr/local/hdf5/bin:$PATH -export LD_LIBRARY_PATH=/usr/local/hdf5/lib:$LD_LIBRARY_PATH -export LIBRARY_PATH=/usr/local/hdf5/lib:$LIBRARY_PATH -export CPATH=/usr/local/hdf5/include:$CPATH - -#基础参数,需要模型审视修改 -#Batch Size -batch_size=1 -#网络名称,同目录名称 -Network="2D_Unet_ID0624_for_PyTorch" -#Device数量,单卡默认为1 -RANK_SIZE=16 -#训练epoch,可选 -train_epochs=1 -#训练step -train_steps= -#学习率 -learning_rate=1e-3 -#参数配置 -data_path="" -conf_path="" -server_index="" -fix_node_ip="" - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh " - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --conf_path* ]];then - conf_path=`echo ${para#*=}` - elif [[ $para == --server_index* ]];then - server_index=`echo ${para#*=}` - elif [[ $para == --fix_node_ip* ]];then - fix_node_ip=`echo ${para#*=}` - fi -done - -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be config" - exit 1 -fi - -one_node_ip=`find $conf_path -name "server_*0.info"|awk -F "server_" '{print $2}'|awk -F "_" '{print $1}'` -linux_num=`find $conf_path -name "server_*.info" |wc -l` - -export HCCL_IF_IP=$fix_node_ip -export MASTER_ADDR=$one_node_ip - -##############执行训练########## -cd $cur_path -if [ -d $cur_path/test/output ];then - rm -rf $cur_path/test/output/* - mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID -fi -wait - - -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID -sed -i "s|data/imgs/|$data_path/imgs/|g" $cur_path/train.py -sed -i "s|data/masks/|$data_path/masks/|g" $cur_path/train.py -#sed -i "s|if global_step == 100: pass|if global_step == 100: break|g" $cur_path/train.py -start=$(date +%s) -#nohup python3 train.py -e $train_epochs > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & - - -export HCCL_WHITELIST_DISABLE=1 -export MASTER_PORT=23456 -NPUS=($(seq 0 7)) -rank_server=`awk 'BEGIN{printf "%.0f\n",8*'${server_index}'}'` -export NPU_WORLD_SIZE=`awk 'BEGIN{printf "%.0f\n",8*'${linux_num}'}'` -rank=0 -for i in ${NPUS[@]} -do - mkdir -p $cur_path/test/output/${i}/ - export NPU_CALCULATE_DEVICE=${i} - export ASCEND_DEVICE_ID=${i} - export RANK=`awk 'BEGIN{printf "%.0f\n",'${rank}'+'${rank_server}'}'` - echo run process ${rank} - nohup python3 train.py -e $train_epochs --distributed True > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & - let rank++ -done -wait -end=$(date +%s) -e2e_time=$(( $end - $start )) - - -#sed -i "s|if global_step == 100: break|if global_step == 100: pass|g" $cur_path/train.py - -#输出训练精度,需要模型审视修改 -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -sed -i "s|\r|\n|g" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log -TrainingTime=0 -FPS=`grep img/s $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 0% | awk -F "," '{print$2}' | awk '{print$1}' | awk -F "i" '{print$1}' | awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` -FPS=$(awk 'BEGIN{print '$FPS'*16}') - -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${FPS}'}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -ActualFPS=${FPS} - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| awk -F "," '{print$3}' | awk -F "=" '{print$2}' | awk -F "]" '{print$1}'| awk '{if(length !=0)print $0}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - - -#精度值 -#train_accuracy=`grep "loss" $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss_2.txt|awk -F " " '{print $8}'|awk 'END {print}'` - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +cur_path=`pwd`/../ +#失败用例打屏 +export ASCEND_SLOG_PRINT_TO_STDOUT=0 + +source /usr/local/Ascend/bin/setenv.bash + +export PATH=/usr/local/hdf5/bin:$PATH +export LD_LIBRARY_PATH=/usr/local/hdf5/lib:$LD_LIBRARY_PATH +export LIBRARY_PATH=/usr/local/hdf5/lib:$LIBRARY_PATH +export CPATH=/usr/local/hdf5/include:$CPATH + +#基础参数,需要模型审视修改 +#Batch Size +batch_size=1 +#网络名称,同目录名称 +Network="2D_Unet_ID0624_for_PyTorch" +#Device数量,单卡默认为1 +RANK_SIZE=16 +#训练epoch,可选 +train_epochs=1 +#训练step +train_steps= +#学习率 +learning_rate=1e-3 +#参数配置 +data_path="" +conf_path="" +server_index="" +fix_node_ip="" + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh " + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --conf_path* ]];then + conf_path=`echo ${para#*=}` + elif [[ $para == --server_index* ]];then + server_index=`echo ${para#*=}` + elif [[ $para == --fix_node_ip* ]];then + fix_node_ip=`echo ${para#*=}` + fi +done + +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be config" + exit 1 +fi + +one_node_ip=`find $conf_path -name "server_*0.info"|awk -F "server_" '{print $2}'|awk -F "_" '{print $1}'` +linux_num=`find $conf_path -name "server_*.info" |wc -l` + +export HCCL_IF_IP=$fix_node_ip +export MASTER_ADDR=$one_node_ip + +##############执行训练########## +cd $cur_path +if [ -d $cur_path/test/output ];then + rm -rf $cur_path/test/output/* + mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID +fi +wait + + +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID +sed -i "s|data/imgs/|$data_path/imgs/|g" $cur_path/train.py +sed -i "s|data/masks/|$data_path/masks/|g" $cur_path/train.py +#sed -i "s|if global_step == 100: pass|if global_step == 100: break|g" $cur_path/train.py +start=$(date +%s) +#nohup python3 train.py -e $train_epochs > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & + + +export HCCL_WHITELIST_DISABLE=1 +export MASTER_PORT=23456 +NPUS=($(seq 0 7)) +rank_server=`awk 'BEGIN{printf "%.0f\n",8*'${server_index}'}'` +export NPU_WORLD_SIZE=`awk 'BEGIN{printf "%.0f\n",8*'${linux_num}'}'` +rank=0 +for i in ${NPUS[@]} +do + mkdir -p $cur_path/test/output/${i}/ + export NPU_CALCULATE_DEVICE=${i} + export ASCEND_DEVICE_ID=${i} + export RANK=`awk 'BEGIN{printf "%.0f\n",'${rank}'+'${rank_server}'}'` + echo run process ${rank} + nohup python3 train.py -e $train_epochs --distributed True > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & + let rank++ +done +wait +end=$(date +%s) +e2e_time=$(( $end - $start )) + + +#sed -i "s|if global_step == 100: break|if global_step == 100: pass|g" $cur_path/train.py + +#输出训练精度,需要模型审视修改 +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +sed -i "s|\r|\n|g" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log +TrainingTime=0 +FPS=`grep img/s $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 0% | awk -F "," '{print$2}' | awk '{print$1}' | awk -F "i" '{print$1}' | awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` +FPS=$(awk 'BEGIN{print '$FPS'*16}') + +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${FPS}'}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +ActualFPS=${FPS} + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| awk -F "," '{print$3}' | awk -F "=" '{print$2}' | awk -F "]" '{print$1}'| awk '{if(length !=0)print $0}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + + +#精度值 +#train_accuracy=`grep "loss" $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss_2.txt|awk -F " " '{print $8}'|awk 'END {print}'` + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/dev/cv/image_classification/2D_Unet_ID0624_for_PyTorch/test/train_performance_8p.sh b/PyTorch/dev/cv/image_classification/2D_Unet_ID0624_for_PyTorch/test/train_performance_8p.sh index 9876a9c467e0446b45a6123ccb96f8318f8613f1..472d0c48a9af98eeffdf19d4a8bbfe6011564713 100644 --- a/PyTorch/dev/cv/image_classification/2D_Unet_ID0624_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/dev/cv/image_classification/2D_Unet_ID0624_for_PyTorch/test/train_performance_8p.sh @@ -1,128 +1,128 @@ -#!/bin/bash - -cur_path=`pwd`/../ -#失败用例打屏 -export ASCEND_SLOG_PRINT_TO_STDOUT=0 - -#基础参数,需要模型审视修改 -#Batch Size -batch_size=1 -#网络名称,同目录名称 -Network="2D_Unet_ID0624_for_PyTorch" -#Device数量,单卡默认为1 -RANK_SIZE=8 -#训练epoch,可选 -train_epochs=1 -#训练step -train_steps= -#学习率 -learning_rate=1e-3 -#参数配置 -data_path="" - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh " - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be config" - exit 1 -fi -##############执行训练########## -cd $cur_path -if [ -d $cur_path/test/output ];then - rm -rf $cur_path/test/output/* - mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID -fi -wait - - -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID -sed -i "s|data/imgs/|$data_path/imgs/|g" $cur_path/train.py -sed -i "s|data/masks/|$data_path/masks/|g" $cur_path/train.py -sed -i "s|if global_step == 100: pass|if global_step == 100: break|g" $cur_path/train.py -start=$(date +%s) -#nohup python3 train.py -e $train_epochs > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & - - -export HCCL_WHITELIST_DISABLE=1 -export MASTER_ADDR=127.0.0.1 -export MASTER_PORT=23456 - -NPUS=($(seq 0 7)) -export NPU_WORLD_SIZE=${#NPUS[@]} -rank=0 -for i in ${NPUS[@]} -do - mkdir -p $cur_path/test/output/${i}/ - export NPU_CALCULATE_DEVICE=${i} - export ASCEND_DEVICE_ID=${i} - export RANK=${rank} - echo run process ${rank} - nohup python3 train.py -e $train_epochs --distributed True > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & - let rank++ -done -wait -end=$(date +%s) -e2e_time=$(( $end - $start )) - - -sed -i "s|if global_step == 100: break|if global_step == 100: pass|g" $cur_path/train.py - -#输出训练精度,需要模型审视修改 -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -sed -i "s|\r|\n|g" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log -TrainingTime=0 -FPS=`grep img/s $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 0% | awk -F "," '{print$2}' | awk '{print$1}' | awk -F "i" '{print$1}' | awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` -FPS=$(awk 'BEGIN{print '$FPS'*8}') - -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${FPS}'}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -ActualFPS=${FPS} - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| awk -F "," '{print$3}' | awk -F "=" '{print$2}' | awk -F "]" '{print$1}'| awk '{if(length !=0)print $0}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - - -#精度值 -#train_accuracy=`grep "loss" $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss_2.txt|awk -F " " '{print $8}'|awk 'END {print}'` - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log - +#!/bin/bash + +cur_path=`pwd`/../ +#失败用例打屏 +export ASCEND_SLOG_PRINT_TO_STDOUT=0 + +#基础参数,需要模型审视修改 +#Batch Size +batch_size=1 +#网络名称,同目录名称 +Network="2D_Unet_ID0624_for_PyTorch" +#Device数量,单卡默认为1 +RANK_SIZE=8 +#训练epoch,可选 +train_epochs=1 +#训练step +train_steps= +#学习率 +learning_rate=1e-3 +#参数配置 +data_path="" + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh " + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be config" + exit 1 +fi +##############执行训练########## +cd $cur_path +if [ -d $cur_path/test/output ];then + rm -rf $cur_path/test/output/* + mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID +fi +wait + + +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID +sed -i "s|data/imgs/|$data_path/imgs/|g" $cur_path/train.py +sed -i "s|data/masks/|$data_path/masks/|g" $cur_path/train.py +sed -i "s|if global_step == 100: pass|if global_step == 100: break|g" $cur_path/train.py +start=$(date +%s) +#nohup python3 train.py -e $train_epochs > $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & + + +export HCCL_WHITELIST_DISABLE=1 +export MASTER_ADDR=127.0.0.1 +export MASTER_PORT=23456 + +NPUS=($(seq 0 7)) +export NPU_WORLD_SIZE=${#NPUS[@]} +rank=0 +for i in ${NPUS[@]} +do + mkdir -p $cur_path/test/output/${i}/ + export NPU_CALCULATE_DEVICE=${i} + export ASCEND_DEVICE_ID=${i} + export RANK=${rank} + echo run process ${rank} + nohup python3 train.py -e $train_epochs --distributed True > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & + let rank++ +done +wait +end=$(date +%s) +e2e_time=$(( $end - $start )) + + +sed -i "s|if global_step == 100: break|if global_step == 100: pass|g" $cur_path/train.py + +#输出训练精度,需要模型审视修改 +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +sed -i "s|\r|\n|g" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log +TrainingTime=0 +FPS=`grep img/s $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | grep -v 0% | awk -F "," '{print$2}' | awk '{print$1}' | awk -F "i" '{print$1}' | awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` +FPS=$(awk 'BEGIN{print '$FPS'*8}') + +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${FPS}'}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +ActualFPS=${FPS} + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log| awk -F "," '{print$3}' | awk -F "=" '{print$2}' | awk -F "]" '{print$1}'| awk '{if(length !=0)print $0}' > $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + + +#精度值 +#train_accuracy=`grep "loss" $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss_2.txt|awk -F " " '{print $8}'|awk 'END {print}'` + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/test/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/test/output/$ASCEND_DEVICE_ID/${CaseName}.log + diff --git a/PyTorch/dev/cv/image_classification/3D_Nest_Unet_ID0476_for_PyTorch/README_ori.md b/PyTorch/dev/cv/image_classification/3D_Nest_Unet_ID0476_for_PyTorch/README_ori.md index 82e051e68c24117f10850fdf1fd6ac93f04c22e4..1d803ac37c7a4278bdf0895b04232b2a53660d5b 100644 --- a/PyTorch/dev/cv/image_classification/3D_Nest_Unet_ID0476_for_PyTorch/README_ori.md +++ b/PyTorch/dev/cv/image_classification/3D_Nest_Unet_ID0476_for_PyTorch/README_ori.md @@ -1,109 +1,109 @@ -# PyTorch implementation of UNet++ (Nested U-Net) -[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) - -This repository contains code for a image segmentation model based on [UNet++: A Nested U-Net Architecture for Medical Image Segmentation](https://arxiv.org/abs/1807.10165) implemented in PyTorch. - -[**NEW**] Add support for multi-class segmentation dataset. - -[**NEW**] Add support for PyTorch 1.x. - - -## Requirements -- PyTorch 1.x or 0.41 - -## Installation -1. Create an anaconda environment. -```sh -conda create -n= python=3.6 anaconda -conda activate -``` -2. Install PyTorch. -```sh -conda install pytorch torchvision cudatoolkit=10.1 -c pytorch -``` -3. Install pip packages. -```sh -pip install -r requirements.txt -``` - -## Training on [2018 Data Science Bowl](https://www.kaggle.com/c/data-science-bowl-2018) dataset -1. Download dataset from [here](https://www.kaggle.com/c/data-science-bowl-2018/data) to inputs/ and unzip. The file structure is the following: -``` -inputs -└── data-science-bowl-2018 - ├── stage1_train - | ├── 00ae65... - │ │ ├── images - │ │ │ └── 00ae65... - │ │ └── masks - │ │ └── 00ae65... - │ ├── ... - | - ... -``` -2. Preprocess. -```sh -python preprocess_dsb2018.py -``` -3. Train the model. -```sh -python train.py --dataset dsb2018_96 --arch NestedUNet -``` -4. Evaluate. -```sh -python val.py --name dsb2018_96_NestedUNet_woDS -``` -### (Optional) Using LovaszHingeLoss -1. Clone LovaszSoftmax from [bermanmaxim/LovaszSoftmax](https://github.com/bermanmaxim/LovaszSoftmax). -``` -git clone https://github.com/bermanmaxim/LovaszSoftmax.git -``` -2. Train the model with LovaszHingeLoss. -``` -python train.py --dataset dsb2018_96 --arch NestedUNet --loss LovaszHingeLoss -``` - -## Training on original dataset -Make sure to put the files as the following structure (e.g. the number of classes is 2): -``` -inputs -└── - ├── images - | ├── 0a7e06.jpg - │ ├── 0aab0a.jpg - │ ├── 0b1761.jpg - │ ├── ... - | - └── masks - ├── 0 - | ├── 0a7e06.png - | ├── 0aab0a.png - | ├── 0b1761.png - | ├── ... - | - └── 1 - ├── 0a7e06.png - ├── 0aab0a.png - ├── 0b1761.png - ├── ... -``` - -1. Train the model. -``` -python train.py --dataset --arch NestedUNet --img_ext .jpg --mask_ext .png -``` -2. Evaluate. -``` -python val.py --name _NestedUNet_woDS -``` - -## Results -### DSB2018 (96x96) - -Here is the results on DSB2018 dataset (96x96) with LovaszHingeLoss. - -| Model | IoU | Loss | -|:------------------------------- |:-------:|:-------:| -| U-Net | 0.839 | 0.365 | -| Nested U-Net | 0.842 |**0.354**| -| Nested U-Net w/ Deepsupervision |**0.843**| 0.362 | +# PyTorch implementation of UNet++ (Nested U-Net) +[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) + +This repository contains code for a image segmentation model based on [UNet++: A Nested U-Net Architecture for Medical Image Segmentation](https://arxiv.org/abs/1807.10165) implemented in PyTorch. + +[**NEW**] Add support for multi-class segmentation dataset. + +[**NEW**] Add support for PyTorch 1.x. + + +## Requirements +- PyTorch 1.x or 0.41 + +## Installation +1. Create an anaconda environment. +```sh +conda create -n= python=3.6 anaconda +conda activate +``` +2. Install PyTorch. +```sh +conda install pytorch torchvision cudatoolkit=10.1 -c pytorch +``` +3. Install pip packages. +```sh +pip install -r requirements.txt +``` + +## Training on [2018 Data Science Bowl](https://www.kaggle.com/c/data-science-bowl-2018) dataset +1. Download dataset from [here](https://www.kaggle.com/c/data-science-bowl-2018/data) to inputs/ and unzip. The file structure is the following: +``` +inputs +└── data-science-bowl-2018 + ├── stage1_train + | ├── 00ae65... + │ │ ├── images + │ │ │ └── 00ae65... + │ │ └── masks + │ │ └── 00ae65... + │ ├── ... + | + ... +``` +2. Preprocess. +```sh +python preprocess_dsb2018.py +``` +3. Train the model. +```sh +python train.py --dataset dsb2018_96 --arch NestedUNet +``` +4. Evaluate. +```sh +python val.py --name dsb2018_96_NestedUNet_woDS +``` +### (Optional) Using LovaszHingeLoss +1. Clone LovaszSoftmax from [bermanmaxim/LovaszSoftmax](https://github.com/bermanmaxim/LovaszSoftmax). +``` +git clone https://github.com/bermanmaxim/LovaszSoftmax.git +``` +2. Train the model with LovaszHingeLoss. +``` +python train.py --dataset dsb2018_96 --arch NestedUNet --loss LovaszHingeLoss +``` + +## Training on original dataset +Make sure to put the files as the following structure (e.g. the number of classes is 2): +``` +inputs +└── + ├── images + | ├── 0a7e06.jpg + │ ├── 0aab0a.jpg + │ ├── 0b1761.jpg + │ ├── ... + | + └── masks + ├── 0 + | ├── 0a7e06.png + | ├── 0aab0a.png + | ├── 0b1761.png + | ├── ... + | + └── 1 + ├── 0a7e06.png + ├── 0aab0a.png + ├── 0b1761.png + ├── ... +``` + +1. Train the model. +``` +python train.py --dataset --arch NestedUNet --img_ext .jpg --mask_ext .png +``` +2. Evaluate. +``` +python val.py --name _NestedUNet_woDS +``` + +## Results +### DSB2018 (96x96) + +Here is the results on DSB2018 dataset (96x96) with LovaszHingeLoss. + +| Model | IoU | Loss | +|:------------------------------- |:-------:|:-------:| +| U-Net | 0.839 | 0.365 | +| Nested U-Net | 0.842 |**0.354**| +| Nested U-Net w/ Deepsupervision |**0.843**| 0.362 | diff --git a/PyTorch/dev/cv/image_classification/AUTOAUGMENT_ID0792_for_PyTorch/modelzoo_level.txt b/PyTorch/dev/cv/image_classification/AUTOAUGMENT_ID0792_for_PyTorch/modelzoo_level.txt index 405b26618a0c92027927a9c583a4b47f640bcf7b..c45626e398eabe6022fe7b2e148f0ffce6400d6e 100644 --- a/PyTorch/dev/cv/image_classification/AUTOAUGMENT_ID0792_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/dev/cv/image_classification/AUTOAUGMENT_ID0792_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:POK +FuncStatus:OK +PerfStatus:POK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/AdvancedEast_ID0473_for_PyTorch/README_ori.md b/PyTorch/dev/cv/image_classification/AdvancedEast_ID0473_for_PyTorch/README_ori.md index 1a712c230e09778f6ca4136d03a972ac022631e4..32d36760cb26edc2a4329ddc29373a9e8e4aa9ba 100644 --- a/PyTorch/dev/cv/image_classification/AdvancedEast_ID0473_for_PyTorch/README_ori.md +++ b/PyTorch/dev/cv/image_classification/AdvancedEast_ID0473_for_PyTorch/README_ori.md @@ -1,14 +1,14 @@ -# pytorch_AdvancedEast -pytorch实现AdvancedEast+mobilenetv3 - -# 参考https://github.com/huoyijie/AdvancedEAST -# training -## tianchi ICPR dataset download 链接: https://pan.baidu.com/s/1NSyc-cHKV3IwDo6qojIrKA 密码: ye9y -### 1.modify config params in cfg.py, see default values. -### 2.python preprocess.py, resize image to 256256,384384,512512,640640,736*736, and train respectively could speed up training process. -### 3.python label.py -### 4.python train.py -### 5.python predict.py -图片: -![demo](https://github.com/corleonechensiyu/pytorch_AdvancedEast/blob/master/012.png_predict.jpg) - +# pytorch_AdvancedEast +pytorch实现AdvancedEast+mobilenetv3 + +# 参考https://github.com/huoyijie/AdvancedEAST +# training +## tianchi ICPR dataset download 链接: https://pan.baidu.com/s/1NSyc-cHKV3IwDo6qojIrKA 密码: ye9y +### 1.modify config params in cfg.py, see default values. +### 2.python preprocess.py, resize image to 256256,384384,512512,640640,736*736, and train respectively could speed up training process. +### 3.python label.py +### 4.python train.py +### 5.python predict.py +图片: +![demo](https://github.com/corleonechensiyu/pytorch_AdvancedEast/blob/master/012.png_predict.jpg) + diff --git a/PyTorch/dev/cv/image_classification/AdvancedEast_ID0473_for_PyTorch/modelzoo_level.txt b/PyTorch/dev/cv/image_classification/AdvancedEast_ID0473_for_PyTorch/modelzoo_level.txt index 484664c2399ae4109859a67aba6cb9facff03cf1..55a9add9fa74832ca908108d73946cd76281a9cd 100644 --- a/PyTorch/dev/cv/image_classification/AdvancedEast_ID0473_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/dev/cv/image_classification/AdvancedEast_ID0473_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/AlexNet_ID0472_for_PyTorch/modelzoo_level.txt b/PyTorch/dev/cv/image_classification/AlexNet_ID0472_for_PyTorch/modelzoo_level.txt index 82f29898a44e5414055c4a4dbb4f0998260f9809..2963c766cbc04c7ed4092aced23b5376029e98ac 100644 --- a/PyTorch/dev/cv/image_classification/AlexNet_ID0472_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/dev/cv/image_classification/AlexNet_ID0472_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:POK +FuncStatus:OK +PerfStatus:POK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/BASNET_ID1134_for_PyTorch/iou_tmp.py b/PyTorch/dev/cv/image_classification/BASNET_ID1134_for_PyTorch/iou_tmp.py index 17db3508e1e9d13b2d03a83f8637ec2ae36dac40..f3298c8c96030abb20d943faa0ed90e39e9d65ed 100644 --- a/PyTorch/dev/cv/image_classification/BASNET_ID1134_for_PyTorch/iou_tmp.py +++ b/PyTorch/dev/cv/image_classification/BASNET_ID1134_for_PyTorch/iou_tmp.py @@ -1,82 +1,82 @@ -# -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -# -import torch -import torch.nn.functional as F -from torch.autograd import Variable -import numpy as np - - -def iiou(pred, target, size_average = True): - - combination = target[:,:,:,:]*pred[:,:,:,:] - sumlist_combination = torch.sum(combination,[-1,2]).npu() #compute SG - sumlist_pred = torch.sum(pred,[-1,2]).npu() # compute S - sumlist_target = torch.sum(target,[-1,2]).npu() # compute G - #print('compression matrix',sumlist_target) - - - iou0 = 1-(sumlist_combination[0]/(sumlist_pred[0]+sumlist_target[0]-sumlist_combination[0])) - iou1 = 1-(sumlist_combination[1]/(sumlist_pred[1]+sumlist_target[1]-sumlist_combination[1])) - iou2 = 1-(sumlist_combination[2]/(sumlist_pred[2]+sumlist_target[2]-sumlist_combination[2])) - iou3 = 1-(sumlist_combination[3]/(sumlist_pred[3]+sumlist_target[3]-sumlist_combination[3])) - iou4 = 1-(sumlist_combination[4]/(sumlist_pred[4]+sumlist_target[4]-sumlist_combination[4])) - iou5 = 1-(sumlist_combination[5]/(sumlist_pred[5]+sumlist_target[5]-sumlist_combination[5])) - iou6 = 1-(sumlist_combination[6]/(sumlist_pred[6]+sumlist_target[6]-sumlist_combination[6])) - iou7 = 1-(sumlist_combination[7]/(sumlist_pred[7]+sumlist_target[7]-sumlist_combination[7])) - - IoU = (iou0+iou1+iou2+iou3+iou4+iou5+iou6+iou7)/8 - - - - #b = pred.shape[0] - #i=0 - #IoU = 0.0 - - - #Iand1 = torch.sum(target[:,:,:,:]*pred[:,:,:,:]) - - - #Ior1 = torch.sum(target[:,:,:,:]) + torch.sum(pred[:,:,:,:])-Iand1 - - - #IoU1 = Iand1/Ior1 - - - - #IoU loss is (1-IoU1) - #IoU = IoU + (1-IoU1) - - return IoU - - +# +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +# +import torch +import torch.nn.functional as F +from torch.autograd import Variable +import numpy as np + + +def iiou(pred, target, size_average = True): + + combination = target[:,:,:,:]*pred[:,:,:,:] + sumlist_combination = torch.sum(combination,[-1,2]).npu() #compute SG + sumlist_pred = torch.sum(pred,[-1,2]).npu() # compute S + sumlist_target = torch.sum(target,[-1,2]).npu() # compute G + #print('compression matrix',sumlist_target) + + + iou0 = 1-(sumlist_combination[0]/(sumlist_pred[0]+sumlist_target[0]-sumlist_combination[0])) + iou1 = 1-(sumlist_combination[1]/(sumlist_pred[1]+sumlist_target[1]-sumlist_combination[1])) + iou2 = 1-(sumlist_combination[2]/(sumlist_pred[2]+sumlist_target[2]-sumlist_combination[2])) + iou3 = 1-(sumlist_combination[3]/(sumlist_pred[3]+sumlist_target[3]-sumlist_combination[3])) + iou4 = 1-(sumlist_combination[4]/(sumlist_pred[4]+sumlist_target[4]-sumlist_combination[4])) + iou5 = 1-(sumlist_combination[5]/(sumlist_pred[5]+sumlist_target[5]-sumlist_combination[5])) + iou6 = 1-(sumlist_combination[6]/(sumlist_pred[6]+sumlist_target[6]-sumlist_combination[6])) + iou7 = 1-(sumlist_combination[7]/(sumlist_pred[7]+sumlist_target[7]-sumlist_combination[7])) + + IoU = (iou0+iou1+iou2+iou3+iou4+iou5+iou6+iou7)/8 + + + + #b = pred.shape[0] + #i=0 + #IoU = 0.0 + + + #Iand1 = torch.sum(target[:,:,:,:]*pred[:,:,:,:]) + + + #Ior1 = torch.sum(target[:,:,:,:]) + torch.sum(pred[:,:,:,:])-Iand1 + + + #IoU1 = Iand1/Ior1 + + + + #IoU loss is (1-IoU1) + #IoU = IoU + (1-IoU1) + + return IoU + + diff --git a/PyTorch/dev/cv/image_classification/BASNET_ID1134_for_PyTorch/prefetcher.py b/PyTorch/dev/cv/image_classification/BASNET_ID1134_for_PyTorch/prefetcher.py index 485463e8aa3c3f7de7f6b86d2300f3989c9a1b77..1d8b0c8087719cefc905c13186f4d80bbd402f82 100644 --- a/PyTorch/dev/cv/image_classification/BASNET_ID1134_for_PyTorch/prefetcher.py +++ b/PyTorch/dev/cv/image_classification/BASNET_ID1134_for_PyTorch/prefetcher.py @@ -1,71 +1,71 @@ -# -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -# - - -import torch - -class DataPrefetcher(): - def __init__(self, loader, steam=None): - self.loader = iter(loader) - self.stream = torch.npu.Stream() - # With Amp, it isn't necessary to manually convert data to half. - # if args.fp16: - # self.mean = self.mean.half() - # self.std = self.std.half() - self.preload() - - def preload(self): - try: - self.next_input,self.next_label = next(self.loader) - except StopIteration: - self.next_input = None - self.next_label = None - return - with torch.npu.stream(self.stream): - self.next_input = self.next_input.npu(non_blocking=True) - self.next_label = self.next_label.npu(non_blocking=True) - - # With Amp, it isn't necessary to manually convert data to half. - # if args.fp16: - # self.next_input = self.next_input.half() - # else: - # self.next_input = self.next_input.float() - - def next(self): - torch.npu.current_stream().wait_stream(self.stream) - next_input = self.next_input - next_label = self.next_label - if next_label is not None: - self.preload() +# +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +# + + +import torch + +class DataPrefetcher(): + def __init__(self, loader, steam=None): + self.loader = iter(loader) + self.stream = torch.npu.Stream() + # With Amp, it isn't necessary to manually convert data to half. + # if args.fp16: + # self.mean = self.mean.half() + # self.std = self.std.half() + self.preload() + + def preload(self): + try: + self.next_input,self.next_label = next(self.loader) + except StopIteration: + self.next_input = None + self.next_label = None + return + with torch.npu.stream(self.stream): + self.next_input = self.next_input.npu(non_blocking=True) + self.next_label = self.next_label.npu(non_blocking=True) + + # With Amp, it isn't necessary to manually convert data to half. + # if args.fp16: + # self.next_input = self.next_input.half() + # else: + # self.next_input = self.next_input.float() + + def next(self): + torch.npu.current_stream().wait_stream(self.stream) + next_input = self.next_input + next_label = self.next_label + if next_label is not None: + self.preload() return next_input,next_label \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/BertBase_ID0490_for_PyTorch/test/train_performance_16p.sh b/PyTorch/dev/cv/image_classification/BertBase_ID0490_for_PyTorch/test/train_performance_16p.sh index 0c7e241fbf5607d3fbbf57e1554d387d3839a4cd..0346feb92ff2f6173580eacbed682f3c1bd9c0ab 100644 --- a/PyTorch/dev/cv/image_classification/BertBase_ID0490_for_PyTorch/test/train_performance_16p.sh +++ b/PyTorch/dev/cv/image_classification/BertBase_ID0490_for_PyTorch/test/train_performance_16p.sh @@ -1,221 +1,221 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#source ../env_npu.sh - -data_path="" -conf_path="" -server_index="" -fix_node_ip="" -#集合通信参数,不需要修改 - -export RANK_SIZE=16 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="BertBase_ID0490_for_PyTorch" -#训练batch_size -batch_size=80 - - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --ckpt_path* ]];then - ckpt_path=`echo ${para#*=}` - elif [[ $para == --conf_path* ]];then - conf_path=`echo ${para#*=}` - elif [[ $para == --server_index* ]];then - server_index=`echo ${para#*=}` - elif [[ $para == --fix_node_ip* ]];then - fix_node_ip=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -one_node_ip=`find $conf_path -name "server_*0.info"|awk -F "server_" '{print $2}'|awk -F "_" '{print $1}'` -linux_num=`find $conf_path -name "server_*.info" |wc -l` - -export HCCL_IF_IP=$fix_node_ip -export MASTER_ADDR=$one_node_ip - -rank_server=`awk 'BEGIN{printf "%.0f\n",8*'${server_index}'}'` -export NPU_WORLD_SIZE=`awk 'BEGIN{printf "%.0f\n",8*'${linux_num}'}'` - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path/../ -cur_1=${1:-"1"} -cur_2=${2:-"2"} -cur_3=${3:-"3"} -cur_4=${4:-"4"} -init_checkpoint=${5:-"`${data_path}/pretrained/bert_base_pretrain.pt`"} -epochs=${6:-"1.0"} -batch_size=${7:-"80"} -learning_rate=${8:-"2e-4"} -precision=${9:-"fp16"} -num_npu=${10:-"16"} -seed=${11:-"1"} -squad_dir=${12:-"`${data_path}/squad/v1.1`"} -vocab_file=${13:-"data/uncased_L-24_H-1024_A-16/vocab.txt"} -OUT_DIR=${14:-"results/SQuAD"} -mode=${15:-"train eval"} -CONFIG_FILE=${16:-"bert_base_config.json"} -max_steps=${17:-"-1"} - -echo "out dir is $OUT_DIR" -mkdir -p $OUT_DIR -if [ ! -d "$OUT_DIR" ]; then - echo "ERROR: non existing $OUT_DIR" - exit 1 -fi - -use_fp16="" -if [ "$precision" = "fp16" ] ; then - echo "fp16 activated!" - use_fp16=" --fp16 " -fi - -CMD="python3.7 run_squad.py " -CMD+="--init_checkpoint=${data_path}/pretrained/bert_base_pretrain.pt " -if [ "$mode" = "train" ] ; then - CMD+="--do_train " - CMD+="--train_file=${data_path}/squad/v1.1/train-v1.1.json " - CMD+="--train_batch_size=$batch_size " -elif [ "$mode" = "eval" ] ; then - CMD+="--do_predict " - CMD+="--predict_file=${data_path}/squad/v1.1/dev-v1.1.json " - CMD+="--predict_batch_size=$batch_size " - CMD+="--eval_script=${data_path}/squad/v1.1/evaluate-v1.1.py " - CMD+="--do_eval " -elif [ "$mode" = "prediction" ] ; then - CMD+="--do_predict " - CMD+="--predict_file=${data_path}/squad/v1.1/dev-v1.1.json " - CMD+="--predict_batch_size=$batch_size " -else - CMD+=" --do_train " - CMD+=" --train_file=${data_path}/squad/v1.1/train-v1.1.json " - CMD+=" --train_batch_size=$batch_size " - CMD+="--do_predict " - CMD+="--predict_file=${data_path}/squad/v1.1/dev-v1.1.json " - CMD+="--predict_batch_size=$batch_size " - CMD+="--eval_script=${data_path}/squad/v1.1/evaluate-v1.1.py " - CMD+="--do_eval " -fi - -CMD+=" --do_lower_case " -CMD+=" --bert_model=bert-large-uncased " -CMD+=" --learning_rate=$learning_rate " -CMD+=" --seed=$seed " -CMD+=" --num_train_epochs=$epochs " -CMD+=" --max_seq_length=384 " -CMD+=" --doc_stride=128 " -CMD+=" --output_dir=$OUT_DIR " -CMD+=" --vocab_file=$vocab_file " -CMD+=" --config_file=$CONFIG_FILE " -CMD+=" --max_steps=$max_steps " -CMD+=" $use_fp16" -CMD+=" --use_npu" -CMD+=" --num_npu=$num_npu" -CMD+=" --loss_scale=4096" -CMD+=" --addr=$one_node_ip" - -if [ $(uname -m) = "aarch64" ] -then - for i in $(seq 0 7) - do - let p_start=0+24*i - let p_end=23+24*i - export RANK=`awk 'BEGIN{printf "%.0f\n",'${i}'+'${rank_server}'}'` - if [ -d ${cur_path}/output/${i} ];then - rm -rf ${cur_path}/output/${i} - mkdir -p ${cur_path}/output/$i - else - mkdir -p ${cur_path}/output/$i - fi - taskset -c $p_start-$p_end $CMD --local_rank=$i > ${cur_path}/output/${i}/train_${i}.log 2>&1 & - done -else - for i in $(seq 0 7) - do - export RANK=`awk 'BEGIN{printf "%.0f\n",'${i}'+'${rank_server}'}'` - if [ -d ${cur_path}/output/${i} ];then - rm -rf ${cur_path}/output/${i} - mkdir -p ${cur_path}/output/$i - else - mkdir -p ${cur_path}/output/$i - fi - $CMD --local_rank=$i > ${cur_path}/output/${i}/train_${i}.log 2>&1 & - done -fi -wait - -ASCEND_DEVICE_ID=0 -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -iter=`grep 'Epoch: ' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "iter/s :" '{print $NF}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` -FPS=`awk 'BEGIN{printf "%.2f\n",'${iter}'*16*'${batch_size}'}'` -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep -r "step_loss :" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk '{print $19}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#source ../env_npu.sh + +data_path="" +conf_path="" +server_index="" +fix_node_ip="" +#集合通信参数,不需要修改 + +export RANK_SIZE=16 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="BertBase_ID0490_for_PyTorch" +#训练batch_size +batch_size=80 + + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --ckpt_path* ]];then + ckpt_path=`echo ${para#*=}` + elif [[ $para == --conf_path* ]];then + conf_path=`echo ${para#*=}` + elif [[ $para == --server_index* ]];then + server_index=`echo ${para#*=}` + elif [[ $para == --fix_node_ip* ]];then + fix_node_ip=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +one_node_ip=`find $conf_path -name "server_*0.info"|awk -F "server_" '{print $2}'|awk -F "_" '{print $1}'` +linux_num=`find $conf_path -name "server_*.info" |wc -l` + +export HCCL_IF_IP=$fix_node_ip +export MASTER_ADDR=$one_node_ip + +rank_server=`awk 'BEGIN{printf "%.0f\n",8*'${server_index}'}'` +export NPU_WORLD_SIZE=`awk 'BEGIN{printf "%.0f\n",8*'${linux_num}'}'` + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path/../ +cur_1=${1:-"1"} +cur_2=${2:-"2"} +cur_3=${3:-"3"} +cur_4=${4:-"4"} +init_checkpoint=${5:-"`${data_path}/pretrained/bert_base_pretrain.pt`"} +epochs=${6:-"1.0"} +batch_size=${7:-"80"} +learning_rate=${8:-"2e-4"} +precision=${9:-"fp16"} +num_npu=${10:-"16"} +seed=${11:-"1"} +squad_dir=${12:-"`${data_path}/squad/v1.1`"} +vocab_file=${13:-"data/uncased_L-24_H-1024_A-16/vocab.txt"} +OUT_DIR=${14:-"results/SQuAD"} +mode=${15:-"train eval"} +CONFIG_FILE=${16:-"bert_base_config.json"} +max_steps=${17:-"-1"} + +echo "out dir is $OUT_DIR" +mkdir -p $OUT_DIR +if [ ! -d "$OUT_DIR" ]; then + echo "ERROR: non existing $OUT_DIR" + exit 1 +fi + +use_fp16="" +if [ "$precision" = "fp16" ] ; then + echo "fp16 activated!" + use_fp16=" --fp16 " +fi + +CMD="python3.7 run_squad.py " +CMD+="--init_checkpoint=${data_path}/pretrained/bert_base_pretrain.pt " +if [ "$mode" = "train" ] ; then + CMD+="--do_train " + CMD+="--train_file=${data_path}/squad/v1.1/train-v1.1.json " + CMD+="--train_batch_size=$batch_size " +elif [ "$mode" = "eval" ] ; then + CMD+="--do_predict " + CMD+="--predict_file=${data_path}/squad/v1.1/dev-v1.1.json " + CMD+="--predict_batch_size=$batch_size " + CMD+="--eval_script=${data_path}/squad/v1.1/evaluate-v1.1.py " + CMD+="--do_eval " +elif [ "$mode" = "prediction" ] ; then + CMD+="--do_predict " + CMD+="--predict_file=${data_path}/squad/v1.1/dev-v1.1.json " + CMD+="--predict_batch_size=$batch_size " +else + CMD+=" --do_train " + CMD+=" --train_file=${data_path}/squad/v1.1/train-v1.1.json " + CMD+=" --train_batch_size=$batch_size " + CMD+="--do_predict " + CMD+="--predict_file=${data_path}/squad/v1.1/dev-v1.1.json " + CMD+="--predict_batch_size=$batch_size " + CMD+="--eval_script=${data_path}/squad/v1.1/evaluate-v1.1.py " + CMD+="--do_eval " +fi + +CMD+=" --do_lower_case " +CMD+=" --bert_model=bert-large-uncased " +CMD+=" --learning_rate=$learning_rate " +CMD+=" --seed=$seed " +CMD+=" --num_train_epochs=$epochs " +CMD+=" --max_seq_length=384 " +CMD+=" --doc_stride=128 " +CMD+=" --output_dir=$OUT_DIR " +CMD+=" --vocab_file=$vocab_file " +CMD+=" --config_file=$CONFIG_FILE " +CMD+=" --max_steps=$max_steps " +CMD+=" $use_fp16" +CMD+=" --use_npu" +CMD+=" --num_npu=$num_npu" +CMD+=" --loss_scale=4096" +CMD+=" --addr=$one_node_ip" + +if [ $(uname -m) = "aarch64" ] +then + for i in $(seq 0 7) + do + let p_start=0+24*i + let p_end=23+24*i + export RANK=`awk 'BEGIN{printf "%.0f\n",'${i}'+'${rank_server}'}'` + if [ -d ${cur_path}/output/${i} ];then + rm -rf ${cur_path}/output/${i} + mkdir -p ${cur_path}/output/$i + else + mkdir -p ${cur_path}/output/$i + fi + taskset -c $p_start-$p_end $CMD --local_rank=$i > ${cur_path}/output/${i}/train_${i}.log 2>&1 & + done +else + for i in $(seq 0 7) + do + export RANK=`awk 'BEGIN{printf "%.0f\n",'${i}'+'${rank_server}'}'` + if [ -d ${cur_path}/output/${i} ];then + rm -rf ${cur_path}/output/${i} + mkdir -p ${cur_path}/output/$i + else + mkdir -p ${cur_path}/output/$i + fi + $CMD --local_rank=$i > ${cur_path}/output/${i}/train_${i}.log 2>&1 & + done +fi +wait + +ASCEND_DEVICE_ID=0 +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +iter=`grep 'Epoch: ' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "iter/s :" '{print $NF}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` +FPS=`awk 'BEGIN{printf "%.2f\n",'${iter}'*16*'${batch_size}'}'` +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep -r "step_loss :" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk '{print $19}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log rm -rf ${data_path}/squad/v1.1/train-v1.1.json_bert-large-uncased_384_128_64 \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/ConvLSTM_ID1772_for_PyTorch/requirements.txt b/PyTorch/dev/cv/image_classification/ConvLSTM_ID1772_for_PyTorch/requirements.txt old mode 100755 new mode 100644 diff --git a/PyTorch/dev/cv/image_classification/DBPN_ID2917_for_PyTorch/test/train_full_8p.sh b/PyTorch/dev/cv/image_classification/DBPN_ID2917_for_PyTorch/test/train_full_8p.sh index b61b7c26b86a4d70ddc8a1d7d2471c1e4f2cd906..14ffa068d838e044e1fec77ab6eada6fa1c5e40f 100644 --- a/PyTorch/dev/cv/image_classification/DBPN_ID2917_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/dev/cv/image_classification/DBPN_ID2917_for_PyTorch/test/train_full_8p.sh @@ -1,190 +1,190 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID - -#集合通信参数,不需要修改 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 - -RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="DBPN_ID2917_for_PyTorch" -#训练epoch -train_epochs=400 -#训练batch_size -batch_size=1 -#训练step -#train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.0008 - -#TF2.X独有,不需要修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False - -# 帮助信息,不h需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_1p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path/../ -mkdir weights - -#sed -i "s|./data|$data_path|g" mmoe.py -#sed -i "s|n_epochs = 80|n_epochs = 1|g" mmoe.py -#sed -i "s|pass|break|g" main.py - -#python3 setup.py install -#mkdir -p checkpoints -#mkdir -p /root/.cache/torch/hub/checkpoints -#cp $data_path/fcn_* /root/.cache/torch/hub/checkpoints - -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - export NPU_CALCULATE_DEVICE=$RANK_ID - ASCEND_DEVICE_ID=$RANK_ID - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - - #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 - #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` - #cpustep=`expr $cpucount / 8` - #echo "taskset c steps:" $cpustep - #let a=RANK_ID*$cpustep - #let b=RANK_ID+1 - #let c=b*$cpustep-1 - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - nohup python3 main.py --data_dir $data_path --batchSize $batch_size --nEpochs $train_epochs \ - --distributed --lr=$learning_rate --input_dir $data_path > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & - -done -wait - -#恢复参数 -#sed -i "s|$data_path|./data|g" mmoe.py -#sed -i "s|n_epochs = 1|n_epochs = 80|g" mmoe.py -#sed -i "s|break|pass|g" main.py - -#conda deactivate -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "FPS:" '{print $2}'|tail -n +2|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` -#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${time}'}'` - - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep "PSNR" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "PSNR:" '{print $2}'|awk '{print $1}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - - -##获取性能数据 -#吞吐量,不需要修改 -ActualFPS=${FPS} -#单迭代训练时长,不需要修改 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "FPS" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss: " '{print $2}'|awk -F "|" '{print $1}' >> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID + +#集合通信参数,不需要修改 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 + +RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="DBPN_ID2917_for_PyTorch" +#训练epoch +train_epochs=400 +#训练batch_size +batch_size=1 +#训练step +#train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.0008 + +#TF2.X独有,不需要修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False + +# 帮助信息,不h需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_1p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path/../ +mkdir weights + +#sed -i "s|./data|$data_path|g" mmoe.py +#sed -i "s|n_epochs = 80|n_epochs = 1|g" mmoe.py +#sed -i "s|pass|break|g" main.py + +#python3 setup.py install +#mkdir -p checkpoints +#mkdir -p /root/.cache/torch/hub/checkpoints +#cp $data_path/fcn_* /root/.cache/torch/hub/checkpoints + +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + export NPU_CALCULATE_DEVICE=$RANK_ID + ASCEND_DEVICE_ID=$RANK_ID + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + + #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 + #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` + #cpustep=`expr $cpucount / 8` + #echo "taskset c steps:" $cpustep + #let a=RANK_ID*$cpustep + #let b=RANK_ID+1 + #let c=b*$cpustep-1 + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + nohup python3 main.py --data_dir $data_path --batchSize $batch_size --nEpochs $train_epochs \ + --distributed --lr=$learning_rate --input_dir $data_path > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + +done +wait + +#恢复参数 +#sed -i "s|$data_path|./data|g" mmoe.py +#sed -i "s|n_epochs = 1|n_epochs = 80|g" mmoe.py +#sed -i "s|break|pass|g" main.py + +#conda deactivate +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "FPS:" '{print $2}'|tail -n +2|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` +#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${time}'}'` + + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep "PSNR" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "PSNR:" '{print $2}'|awk '{print $1}'|awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + + +##获取性能数据 +#吞吐量,不需要修改 +ActualFPS=${FPS} +#单迭代训练时长,不需要修改 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "FPS" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss: " '{print $2}'|awk -F "|" '{print $1}' >> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/dev/cv/image_classification/DBPN_ID2917_for_PyTorch/test/train_performance_8p.sh b/PyTorch/dev/cv/image_classification/DBPN_ID2917_for_PyTorch/test/train_performance_8p.sh index 7796e7c60e343467d36d3e551614abf6a1fc6660..b7e118bff6867a8127e4c88dad46d24686fed762 100644 --- a/PyTorch/dev/cv/image_classification/DBPN_ID2917_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/dev/cv/image_classification/DBPN_ID2917_for_PyTorch/test/train_performance_8p.sh @@ -1,189 +1,189 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID - -#集合通信参数,不需要修改 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 - -RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="DBPN_ID2917_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=1 -#训练step -#train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.0008 - -#TF2.X独有,不需要修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False - -# 帮助信息,不h需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_1p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path/../ - - -#sed -i "s|./data|$data_path|g" mmoe.py -#sed -i "s|n_epochs = 80|n_epochs = 1|g" mmoe.py -#sed -i "s|pass|break|g" main.py - -#python3 setup.py install -#mkdir -p checkpoints -#mkdir -p /root/.cache/torch/hub/checkpoints -#cp $data_path/fcn_* /root/.cache/torch/hub/checkpoints - -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - export NPU_CALCULATE_DEVICE=$RANK_ID - ASCEND_DEVICE_ID=$RANK_ID - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - - #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 - #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` - #cpustep=`expr $cpucount / 8` - #echo "taskset c steps:" $cpustep - #let a=RANK_ID*$cpustep - #let b=RANK_ID+1 - #let c=b*$cpustep-1 - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - nohup python3 main.py --data_dir $data_path --batchSize $batch_size --nEpochs $train_epochs \ - --distributed --lr=$learning_rate --input_dir $data_path > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & - -done -wait - -#恢复参数 -#sed -i "s|$data_path|./data|g" mmoe.py -#sed -i "s|n_epochs = 1|n_epochs = 80|g" mmoe.py -#sed -i "s|break|pass|g" main.py - -#conda deactivate -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "FPS:" '{print $2}'|tail -n +2|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` -#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${time}'}'` - - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep eval_accuracy $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v mlp_log|awk 'END {print $5}'| sed 's/,//g' |cut -c 1-5` -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -#echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据 -#吞吐量,不需要修改 -ActualFPS=${FPS} -#单迭代训练时长,不需要修改 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "FPS" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss: " '{print $2}'|awk -F "|" '{print $1}' >> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID + +#集合通信参数,不需要修改 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 + +RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="DBPN_ID2917_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=1 +#训练step +#train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.0008 + +#TF2.X独有,不需要修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False + +# 帮助信息,不h需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_1p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path/../ + + +#sed -i "s|./data|$data_path|g" mmoe.py +#sed -i "s|n_epochs = 80|n_epochs = 1|g" mmoe.py +#sed -i "s|pass|break|g" main.py + +#python3 setup.py install +#mkdir -p checkpoints +#mkdir -p /root/.cache/torch/hub/checkpoints +#cp $data_path/fcn_* /root/.cache/torch/hub/checkpoints + +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + export NPU_CALCULATE_DEVICE=$RANK_ID + ASCEND_DEVICE_ID=$RANK_ID + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + + #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 + #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` + #cpustep=`expr $cpucount / 8` + #echo "taskset c steps:" $cpustep + #let a=RANK_ID*$cpustep + #let b=RANK_ID+1 + #let c=b*$cpustep-1 + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + nohup python3 main.py --data_dir $data_path --batchSize $batch_size --nEpochs $train_epochs \ + --distributed --lr=$learning_rate --input_dir $data_path > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & + +done +wait + +#恢复参数 +#sed -i "s|$data_path|./data|g" mmoe.py +#sed -i "s|n_epochs = 1|n_epochs = 80|g" mmoe.py +#sed -i "s|break|pass|g" main.py + +#conda deactivate +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "FPS:" '{print $2}'|tail -n +2|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` +#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${time}'}'` + + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep eval_accuracy $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v mlp_log|awk 'END {print $5}'| sed 's/,//g' |cut -c 1-5` +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +#echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据 +#吞吐量,不需要修改 +ActualFPS=${FPS} +#单迭代训练时长,不需要修改 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "FPS" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "Loss: " '{print $2}'|awk -F "|" '{print $1}' >> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/dev/cv/image_classification/DCAP_ID2836_for_PyTorch/prefetcher.py b/PyTorch/dev/cv/image_classification/DCAP_ID2836_for_PyTorch/prefetcher.py index a02e80d661454670a1eefb1ccb5e351bf2b7e923..efc4a37ec1b9d9389f740f45c6deb71c30b9de59 100644 --- a/PyTorch/dev/cv/image_classification/DCAP_ID2836_for_PyTorch/prefetcher.py +++ b/PyTorch/dev/cv/image_classification/DCAP_ID2836_for_PyTorch/prefetcher.py @@ -1,63 +1,63 @@ -# Copyright (c) 2020 Huawei Technologies Co., Ltd -# Copyright (c) 2019, Facebook CORPORATION. -# All rights reserved. -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch - - -class Prefetcher(object): - """Prefetcher using on npu device. - - Origin Code URL: - https://github.com/implus/PytorchInsight/blob/master/classification/imagenet_fast.py#L280 - - Args: - loder (torch.utils.data.DataLoader or DataLoader like iterator): - Using to generate inputs after preprocessing. - stream (torch.npu.Stream): Default None. - Because of the limitation of NPU's memory mechanism, - if prefetcher is initialized repeatedly during training, - a defined stream should be introduced to prevent memory leakage; - if prefetcher is initialized only once during training, - a defined stream is not necessary. - - Returns: - float: tensors of shape (k, 5) and (k, 1). Labels are 0-based. - """ - - def __init__(self, loader, stream=None): - self.loader = iter(loader) - self.stream = stream if stream is not None else torch.npu.Stream() - self.preload() - - def preload(self): - try: - self.next_input, self.next_target = next(self.loader) - except StopIteration: - self.user = None - self.item = None - return - - with torch.npu.stream(self.stream): - self.next_input, self.next_target = self.next_input.to(torch.float), self.next_target.to(torch.float) - self.next_input, self.next_target = self.next_input.npu(non_blocking=True), self.next_target.npu(non_blocking=True) - - def next(self): - torch.npu.current_stream().wait_stream(self.stream) - next_input = self.next_input - next_target = self.next_target - if next_input is not None: - self.preload() +# Copyright (c) 2020 Huawei Technologies Co., Ltd +# Copyright (c) 2019, Facebook CORPORATION. +# All rights reserved. +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch + + +class Prefetcher(object): + """Prefetcher using on npu device. + + Origin Code URL: + https://github.com/implus/PytorchInsight/blob/master/classification/imagenet_fast.py#L280 + + Args: + loder (torch.utils.data.DataLoader or DataLoader like iterator): + Using to generate inputs after preprocessing. + stream (torch.npu.Stream): Default None. + Because of the limitation of NPU's memory mechanism, + if prefetcher is initialized repeatedly during training, + a defined stream should be introduced to prevent memory leakage; + if prefetcher is initialized only once during training, + a defined stream is not necessary. + + Returns: + float: tensors of shape (k, 5) and (k, 1). Labels are 0-based. + """ + + def __init__(self, loader, stream=None): + self.loader = iter(loader) + self.stream = stream if stream is not None else torch.npu.Stream() + self.preload() + + def preload(self): + try: + self.next_input, self.next_target = next(self.loader) + except StopIteration: + self.user = None + self.item = None + return + + with torch.npu.stream(self.stream): + self.next_input, self.next_target = self.next_input.to(torch.float), self.next_target.to(torch.float) + self.next_input, self.next_target = self.next_input.npu(non_blocking=True), self.next_target.npu(non_blocking=True) + + def next(self): + torch.npu.current_stream().wait_stream(self.stream) + next_input = self.next_input + next_target = self.next_target + if next_input is not None: + self.preload() return next_input, next_target \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/README_ori.md b/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/README_ori.md index 2cf3d2a82106d3e10156ce42e0cb5cc404686b73..e89c9b3ea08691210046fbb9184bf8e44e88f29e 100644 --- a/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/README_ori.md +++ b/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/README_ori.md @@ -1,3 +1,3 @@ -# Deep Sort - +# Deep Sort + This is the implemention of deep sort with pytorch. \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/requirements.txt b/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/requirements.txt index 848ebde50e69db701f64332fea0b153a362100ed..f9b2aa91e4a9024db31af76e55e7a5b7fa4350b7 100644 --- a/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/requirements.txt +++ b/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/requirements.txt @@ -1,2 +1,2 @@ -torch +torch numpy \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/test/train_full_8p.sh b/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/test/train_full_8p.sh index 49ef461403e0611e7244f27e90276faf46b7744b..6d473004a5fcd1b6ef9c5532d67e792ce2ad00ed 100644 --- a/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/test/train_full_8p.sh @@ -1,201 +1,201 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` - -#集合通信参数,不需要修改 - -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 - - - - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -export ASCEND_GLOBAL_LOG_LEVEL=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="DeepSort_ID0654_for_PyTorch" -#训练epoch -train_epochs=10 -#训练batch_size -batch_size=64 -#训练step -train_steps= -#学习率 -learning_rate=0.8 - -#TF2.X独有,需要模型审视修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_performance_1P.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--apex" -fi -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -# 解压数据集 -if [ ! -e "$data_path/data/train/1499/1499C5T0007F050.jpg" ];then - tar -xvf $data_path/data.tar -C $data_path/ -else - echo "NO NEED UNTAR" -fi -wait - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -#cd $cur_path/../tensorflow -cd $cur_path/../ - -sed -i "s|for epoch in range(start_epoch, start_epoch + 40):|for epoch in range(start_epoch, start_epoch + $train_epochs):|g" $cur_path/../deep/train.py - -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path - export MASTER_ADDR=localhost - export MASTER_PORT=29688 - export HCCL_WHITELIST_DISABLE=1 - - NPUS=($(seq 0 7)) - export NPU_WORLD_SIZE=${#NPUS[@]} - rank=0 - for i in ${NPUS[@]} - do - mkdir -p $cur_path/output/${i}/ - export NPU_CALCULATE_DEVICE=${i} - export RANK=${rank} - export ASCEND_DEVICE_ID=${i} - echo run process ${rank} - python3 deep/train.py --ddp \ - --data-dir $data_path/data \ - --lr 0.8 \ - $PREC > $cur_path/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & - let rank++ - done -done -wait -sed -i "s|for epoch in range(start_epoch, start_epoch + $train_epochs):|for epoch in range(start_epoch, start_epoch + 40):|g" $cur_path/../deep/train.py -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -#FPS=`grep "]time" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F":" 'NR>26{print $3}' | awk -F"s" '{print $1}' | head -n -1 | awk '{sum+=$1} END {print 64*NR/sum}'` -FPS=`grep -rn "progress:" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F "time:" '{print $2}'| awk -F "s" '{print $1}'|awk '{if (NR>1){print $1}}'|awk '{if(length !=0) print $0}'|awk '{sum+=$1} END {print 64*NR/sum}'` -FPS=$(awk 'BEGIN{print '$FPS'*8}') -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep train_accuracy $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $8}'|cut -c 1-5` -train_accuracy=`grep "Acc" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "Acc:" '{print$2}' | sed 's/%//g' |awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "Loss:" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk -F "Loss:" '{print$2}' | awk '{print$1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` + +#集合通信参数,不需要修改 + +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 + + + + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +export ASCEND_GLOBAL_LOG_LEVEL=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="DeepSort_ID0654_for_PyTorch" +#训练epoch +train_epochs=10 +#训练batch_size +batch_size=64 +#训练step +train_steps= +#学习率 +learning_rate=0.8 + +#TF2.X独有,需要模型审视修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_performance_1P.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--apex" +fi +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +# 解压数据集 +if [ ! -e "$data_path/data/train/1499/1499C5T0007F050.jpg" ];then + tar -xvf $data_path/data.tar -C $data_path/ +else + echo "NO NEED UNTAR" +fi +wait + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +#cd $cur_path/../tensorflow +cd $cur_path/../ + +sed -i "s|for epoch in range(start_epoch, start_epoch + 40):|for epoch in range(start_epoch, start_epoch + $train_epochs):|g" $cur_path/../deep/train.py + +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path + export MASTER_ADDR=localhost + export MASTER_PORT=29688 + export HCCL_WHITELIST_DISABLE=1 + + NPUS=($(seq 0 7)) + export NPU_WORLD_SIZE=${#NPUS[@]} + rank=0 + for i in ${NPUS[@]} + do + mkdir -p $cur_path/output/${i}/ + export NPU_CALCULATE_DEVICE=${i} + export RANK=${rank} + export ASCEND_DEVICE_ID=${i} + echo run process ${rank} + python3 deep/train.py --ddp \ + --data-dir $data_path/data \ + --lr 0.8 \ + $PREC > $cur_path/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & + let rank++ + done +done +wait +sed -i "s|for epoch in range(start_epoch, start_epoch + $train_epochs):|for epoch in range(start_epoch, start_epoch + 40):|g" $cur_path/../deep/train.py +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +#FPS=`grep "]time" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F":" 'NR>26{print $3}' | awk -F"s" '{print $1}' | head -n -1 | awk '{sum+=$1} END {print 64*NR/sum}'` +FPS=`grep -rn "progress:" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F "time:" '{print $2}'| awk -F "s" '{print $1}'|awk '{if (NR>1){print $1}}'|awk '{if(length !=0) print $0}'|awk '{sum+=$1} END {print 64*NR/sum}'` +FPS=$(awk 'BEGIN{print '$FPS'*8}') +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep train_accuracy $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $8}'|cut -c 1-5` +train_accuracy=`grep "Acc" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "Acc:" '{print$2}' | sed 's/%//g' |awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'` +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "Loss:" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk -F "Loss:" '{print$2}' | awk '{print$1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/test/train_performance_8p.sh b/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/test/train_performance_8p.sh index 1caa51cfe889539996085e509bb8d388b90b885c..55612613f3c52376433bc96e1d938fb498ef6e38 100644 --- a/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch/test/train_performance_8p.sh @@ -1,198 +1,198 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` - -#集合通信参数,不需要修改 - -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 - - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -export ASCEND_GLOBAL_LOG_LEVEL=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="DeepSort_ID0654_for_PyTorch" -#训练epoch -train_epochs=2 -#训练batch_size -#batch_size=256 -batch_size=64 -#训练step -train_steps= -#学习率 -learning_rate=0.1 - -#TF2.X独有,需要模型审视修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_performance_1P.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--apex" -fi -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -# 解压数据集 -if [ ! -e "$data_path/data/train/1499/1499C5T0007F050.jpg" ];then - tar -xvf $data_path/data.tar -C $data_path/ -else - echo "NO NEED UNTAR" -fi -wait - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -#cd $cur_path/../tensorflow -cd $cur_path/../ - -sed -i "s|for epoch in range(start_epoch, start_epoch + 40):|for epoch in range(start_epoch, start_epoch + $train_epochs):|g" $cur_path/../deep/train.py - -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path - export MASTER_ADDR=localhost - export MASTER_PORT=29688 - export HCCL_WHITELIST_DISABLE=1 - - NPUS=($(seq 0 7)) - export NPU_WORLD_SIZE=${#NPUS[@]} - rank=0 - for i in ${NPUS[@]} - do - mkdir -p $cur_path/output/${i}/ - export NPU_CALCULATE_DEVICE=${i} - export RANK=${rank} - export ASCEND_DEVICE_ID=${i} - echo run process ${rank} - python3 deep/train.py --ddp \ - --data-dir $data_path/data \ - --max_steps 200 \ - $PREC > $cur_path/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & - let rank++ - done -done -wait -sed -i "s|for epoch in range(start_epoch, start_epoch + $train_epochs):|for epoch in range(start_epoch, start_epoch + 40):|g" $cur_path/../deep/train.py -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -#FPS=`grep "]time" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F":" 'NR>1{print $3}' | awk -F"s" '{print $1}' | head -n -1 | awk '{sum+=$1} END {print 64*NR/sum}'` -FPS=`grep -rn "progress:" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F "time:" '{print $2}'| awk -F "s" '{print $1}'|awk '{if (NR>1){print $1}}'|awk '{if(length !=0) print $0}'|awk '{sum+=$1} END {print 64*NR/sum}'` -FPS=$(awk 'BEGIN{print '$FPS'*8}') -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep train_accuracy $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $8}'|cut -c 1-5` -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "Loss:" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk -F "Loss:" '{print$2}' | awk '{print$1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` + +#集合通信参数,不需要修改 + +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 + + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +export ASCEND_GLOBAL_LOG_LEVEL=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="DeepSort_ID0654_for_PyTorch" +#训练epoch +train_epochs=2 +#训练batch_size +#batch_size=256 +batch_size=64 +#训练step +train_steps= +#学习率 +learning_rate=0.1 + +#TF2.X独有,需要模型审视修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_performance_1P.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--apex" +fi +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +# 解压数据集 +if [ ! -e "$data_path/data/train/1499/1499C5T0007F050.jpg" ];then + tar -xvf $data_path/data.tar -C $data_path/ +else + echo "NO NEED UNTAR" +fi +wait + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +#cd $cur_path/../tensorflow +cd $cur_path/../ + +sed -i "s|for epoch in range(start_epoch, start_epoch + 40):|for epoch in range(start_epoch, start_epoch + $train_epochs):|g" $cur_path/../deep/train.py + +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path + export MASTER_ADDR=localhost + export MASTER_PORT=29688 + export HCCL_WHITELIST_DISABLE=1 + + NPUS=($(seq 0 7)) + export NPU_WORLD_SIZE=${#NPUS[@]} + rank=0 + for i in ${NPUS[@]} + do + mkdir -p $cur_path/output/${i}/ + export NPU_CALCULATE_DEVICE=${i} + export RANK=${rank} + export ASCEND_DEVICE_ID=${i} + echo run process ${rank} + python3 deep/train.py --ddp \ + --data-dir $data_path/data \ + --max_steps 200 \ + $PREC > $cur_path/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & + let rank++ + done +done +wait +sed -i "s|for epoch in range(start_epoch, start_epoch + $train_epochs):|for epoch in range(start_epoch, start_epoch + 40):|g" $cur_path/../deep/train.py +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +#FPS=`grep "]time" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F":" 'NR>1{print $3}' | awk -F"s" '{print $1}' | head -n -1 | awk '{sum+=$1} END {print 64*NR/sum}'` +FPS=`grep -rn "progress:" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F "time:" '{print $2}'| awk -F "s" '{print $1}'|awk '{if (NR>1){print $1}}'|awk '{if(length !=0) print $0}'|awk '{sum+=$1} END {print 64*NR/sum}'` +FPS=$(awk 'BEGIN{print '$FPS'*8}') +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep train_accuracy $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print $8}'|cut -c 1-5` +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "Loss:" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk -F "Loss:" '{print$2}' | awk '{print$1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/dev/cv/image_classification/ESMM_ID2839_for_PyTorch/modelzoo_level b/PyTorch/dev/cv/image_classification/ESMM_ID2839_for_PyTorch/modelzoo_level index 405b26618a0c92027927a9c583a4b47f640bcf7b..c45626e398eabe6022fe7b2e148f0ffce6400d6e 100644 --- a/PyTorch/dev/cv/image_classification/ESMM_ID2839_for_PyTorch/modelzoo_level +++ b/PyTorch/dev/cv/image_classification/ESMM_ID2839_for_PyTorch/modelzoo_level @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:POK +FuncStatus:OK +PerfStatus:POK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/ESRGAN_ID1813_for_PyTorch/modelzoo_level.txt b/PyTorch/dev/cv/image_classification/ESRGAN_ID1813_for_PyTorch/modelzoo_level.txt index a17c8f95fa388fbc6d253e2cd7cfd0b73b734073..a829ab59b97a1022dd6fc33b59b7ae0d55009432 100644 --- a/PyTorch/dev/cv/image_classification/ESRGAN_ID1813_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/dev/cv/image_classification/ESRGAN_ID1813_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/Hourglass_ID1809_for_PyTorch/test/train_performance_8p.sh b/PyTorch/dev/cv/image_classification/Hourglass_ID1809_for_PyTorch/test/train_performance_8p.sh index ebdab5ffd443e06a27116df579ba0d8515a33310..b3d6682684d90412a80609da641767cf8c11f594 100644 --- a/PyTorch/dev/cv/image_classification/Hourglass_ID1809_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/dev/cv/image_classification/Hourglass_ID1809_for_PyTorch/test/train_performance_8p.sh @@ -1,207 +1,207 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -export ASCEND_SLOG_PRINT_TO_STDOUT=0 -#export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID -#集合通信参数,不需要修改 - -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 - - - - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="Hourglass_ID1809_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=16 -#训练step -train_steps=10 -#学习率 -learning_rate=1e-3 - -#TF2.X独有,不需要修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_1p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path/../ -sed -i "s|'batchsize': 16|'batchsize': $batch_size|g" $cur_path/../task/pose.py -sed -i "s|'learning_rate': 1e-3|'learning_rate': $learning_rate|g" $cur_path/../task/pose.py -sed -i "s|'epoch_num': 200|'epoch_num': $train_epochs|g" $cur_path/../task/pose.py -sed -i "s|'train_iters': 1000|'train_iters': $train_steps|g" $cur_path/../task/pose.py -sed -i "s|annot_dir = 'data/MPII/annot'|annot_dir = '$data_path/data/MPII/annot'|g" $cur_path/../datat/MPII/ref.py -sed -i "s|img_dir = 'data/MPII/images'|img_dir = '$data_path/data/MPII/images'|g" $cur_path/../datat/MPII/ref.py -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - - #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 - #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` - #cpustep=`expr $cpucount / 8` - #echo "taskset c steps:" $cpustep - #let a=RANK_ID*$cpustep - #let b=RANK_ID+1 - #let c=b*$cpustep-1 - - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 -done -wait - - - -export HCCL_WHITELIST_DISABLE=1 -export MASTER_ADDR=127.0.0.1 -export MASTER_PORT=23456 - -NPUS=($(seq 0 7)) -export NPU_WORLD_SIZE=${#NPUS[@]} -rank=0 -for i in ${NPUS[@]} -do - mkdir -p $cur_path/output/${i}/ - export NPU_CALCULATE_DEVICE=${i} - export ASCEND_DEVICE_ID=${i} - export RANK=${rank} - echo run process ${rank} - - nohup python3 train.py -e test_run_001 --ddp True > $cur_path/output/${i}/train_${i}.log 2>&1 & - let rank++ -done -wait - - -sed -i "s|'batchsize': $batch_size|'batchsize': 16|g" $cur_path/../task/pose.py -sed -i "s|'learning_rate': $learning_rate|'learning_rate': 1e-3|g" $cur_path/../task/pose.py -sed -i "s|'epoch_num': $train_epochs|'epoch_num': 200|g" $cur_path/../task/pose.py -sed -i "s|'train_iters': $train_steps|'train_iters': 1000|g" $cur_path/../task/pose.py -sed -i "s|annot_dir = '$data_path/data/MPII/annot'|annot_dir = 'data/MPII/annot'|g" $cur_path/../datat/MPII/ref.py -sed -i "s|img_dir = '$data_path/data/MPII/images'|img_dir = 'data/MPII/images'|g" $cur_path/../datat/MPII/ref.py -#conda deactivate -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -sed -i "s|\r|\n|g" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep "fps:" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "fps: " '{print $2}'|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` -FPS=$(awk 'BEGIN{print '$FPS'*8}') - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep eval_accuracy $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v mlp_log|awk 'END {print $5}'| sed 's/,//g' |cut -c 1-5` -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据 -#吞吐量,不需要修改 -ActualFPS=${FPS} -#单迭代训练时长,不需要修改 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "the loss is: " $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "the loss is: " '{print $2}'|sed s/[[:space:]]//g > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +export ASCEND_SLOG_PRINT_TO_STDOUT=0 +#export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID +#集合通信参数,不需要修改 + +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 + + + + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="Hourglass_ID1809_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=16 +#训练step +train_steps=10 +#学习率 +learning_rate=1e-3 + +#TF2.X独有,不需要修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_1p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path/../ +sed -i "s|'batchsize': 16|'batchsize': $batch_size|g" $cur_path/../task/pose.py +sed -i "s|'learning_rate': 1e-3|'learning_rate': $learning_rate|g" $cur_path/../task/pose.py +sed -i "s|'epoch_num': 200|'epoch_num': $train_epochs|g" $cur_path/../task/pose.py +sed -i "s|'train_iters': 1000|'train_iters': $train_steps|g" $cur_path/../task/pose.py +sed -i "s|annot_dir = 'data/MPII/annot'|annot_dir = '$data_path/data/MPII/annot'|g" $cur_path/../datat/MPII/ref.py +sed -i "s|img_dir = 'data/MPII/images'|img_dir = '$data_path/data/MPII/images'|g" $cur_path/../datat/MPII/ref.py +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + + #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 + #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` + #cpustep=`expr $cpucount / 8` + #echo "taskset c steps:" $cpustep + #let a=RANK_ID*$cpustep + #let b=RANK_ID+1 + #let c=b*$cpustep-1 + + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 +done +wait + + + +export HCCL_WHITELIST_DISABLE=1 +export MASTER_ADDR=127.0.0.1 +export MASTER_PORT=23456 + +NPUS=($(seq 0 7)) +export NPU_WORLD_SIZE=${#NPUS[@]} +rank=0 +for i in ${NPUS[@]} +do + mkdir -p $cur_path/output/${i}/ + export NPU_CALCULATE_DEVICE=${i} + export ASCEND_DEVICE_ID=${i} + export RANK=${rank} + echo run process ${rank} + + nohup python3 train.py -e test_run_001 --ddp True > $cur_path/output/${i}/train_${i}.log 2>&1 & + let rank++ +done +wait + + +sed -i "s|'batchsize': $batch_size|'batchsize': 16|g" $cur_path/../task/pose.py +sed -i "s|'learning_rate': $learning_rate|'learning_rate': 1e-3|g" $cur_path/../task/pose.py +sed -i "s|'epoch_num': $train_epochs|'epoch_num': 200|g" $cur_path/../task/pose.py +sed -i "s|'train_iters': $train_steps|'train_iters': 1000|g" $cur_path/../task/pose.py +sed -i "s|annot_dir = '$data_path/data/MPII/annot'|annot_dir = 'data/MPII/annot'|g" $cur_path/../datat/MPII/ref.py +sed -i "s|img_dir = '$data_path/data/MPII/images'|img_dir = 'data/MPII/images'|g" $cur_path/../datat/MPII/ref.py +#conda deactivate +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +sed -i "s|\r|\n|g" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep "fps:" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "fps: " '{print $2}'|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` +FPS=$(awk 'BEGIN{print '$FPS'*8}') + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep eval_accuracy $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v mlp_log|awk 'END {print $5}'| sed 's/,//g' |cut -c 1-5` +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据 +#吞吐量,不需要修改 +ActualFPS=${FPS} +#单迭代训练时长,不需要修改 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "the loss is: " $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "the loss is: " '{print $2}'|sed s/[[:space:]]//g > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/dev/cv/image_classification/Hourglass_ID1809_for_PyTorch/utils/__init__.py b/PyTorch/dev/cv/image_classification/Hourglass_ID1809_for_PyTorch/utils/__init__.py index 475a7da6fc12869078b4a38eed08047e6b06c130..2fcb3d2f55c539cb2454a25da4a272a83e3faa44 100644 --- a/PyTorch/dev/cv/image_classification/Hourglass_ID1809_for_PyTorch/utils/__init__.py +++ b/PyTorch/dev/cv/image_classification/Hourglass_ID1809_for_PyTorch/utils/__init__.py @@ -1,33 +1,33 @@ -# -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ +# +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ # \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/test/train_full_8p.sh b/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/test/train_full_8p.sh index 8563d37ef64f2abf016ca59090ec540ce3a94b62..76482f090613e3757932212b06a93dafa73695cd 100644 --- a/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/test/train_full_8p.sh @@ -1,152 +1,152 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` - -#集合通信参数,不需要修改 - -export RANK_SIZE=8 - -RANK_ID_START=0 - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -export ASCEND_GLOBAL_LOG_LEVEL=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="InceptionV3_ID0445_for_PyTorch" -#训练epoch -train_epochs=90 -#训练batch_size -batch_size=256 -#训练step -train_steps= -#学习率 -learning_rate=0.1 - -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--apex" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path - - -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $RANK_ID" - export RANK_ID=$RANK_ID - export ASCEND_DEVICE_ID=$RANK_ID - ASCEND_DEVICE_ID=$RANK_ID - - if [ -d $cur_path/output/$ASCEND_DEVICE_ID ];then - rm -rf $cur_path/output/$ASCEND_DEVICE_ID - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID - else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID - fi - - - #训练开始时间,不需要修改 - start_time=$(date +%s) - - nohup python3.7 $cur_path/../train_8p_aux.py \ - --model inception_v3 \ - --epochs ${train_epochs} \ - --workers 192 \ - --data-path=${data_path} \ - --batch-size ${batch_size} $PREC \ - --lr ${learning_rate} \ - --distributed \ - --apex \ - --output-dir=$cur_path/output/$ASCEND_DEVICE_ID \ - --momentum 0.9 \ - --weight-decay 1e-4 \ - --seed 49 \ - --print-freq 10 > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & -done -wait - - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep -a 'img/s' $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk -F "img/s" '{print $2}'|awk '{print$2}' |awk '{sum+=$1} END {print sum/NR}'|sed s/[[:space:]]//g` -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a '* Acc@1' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "Acc@1" '{print $2}'|cut -c 2-6|awk 'BEGIN {max = 0} {if ($1+0>max+0) max=$1 fi} END {print max}'` - -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep img/s $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk -F "img/s" '{print$2}' | awk '{print$4}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` + +#集合通信参数,不需要修改 + +export RANK_SIZE=8 + +RANK_ID_START=0 + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +export ASCEND_GLOBAL_LOG_LEVEL=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="InceptionV3_ID0445_for_PyTorch" +#训练epoch +train_epochs=90 +#训练batch_size +batch_size=256 +#训练step +train_steps= +#学习率 +learning_rate=0.1 + +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--apex" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path + + +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $RANK_ID" + export RANK_ID=$RANK_ID + export ASCEND_DEVICE_ID=$RANK_ID + ASCEND_DEVICE_ID=$RANK_ID + + if [ -d $cur_path/output/$ASCEND_DEVICE_ID ];then + rm -rf $cur_path/output/$ASCEND_DEVICE_ID + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID + else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID + fi + + + #训练开始时间,不需要修改 + start_time=$(date +%s) + + nohup python3.7 $cur_path/../train_8p_aux.py \ + --model inception_v3 \ + --epochs ${train_epochs} \ + --workers 192 \ + --data-path=${data_path} \ + --batch-size ${batch_size} $PREC \ + --lr ${learning_rate} \ + --distributed \ + --apex \ + --output-dir=$cur_path/output/$ASCEND_DEVICE_ID \ + --momentum 0.9 \ + --weight-decay 1e-4 \ + --seed 49 \ + --print-freq 10 > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & +done +wait + + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep -a 'img/s' $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk -F "img/s" '{print $2}'|awk '{print$2}' |awk '{sum+=$1} END {print sum/NR}'|sed s/[[:space:]]//g` +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a '* Acc@1' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "Acc@1" '{print $2}'|cut -c 2-6|awk 'BEGIN {max = 0} {if ($1+0>max+0) max=$1 fi} END {print max}'` + +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep img/s $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log | awk -F "img/s" '{print$2}' | awk '{print$4}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/train_8p.py b/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/train_8p.py index 14585e31408ef52e636f85fa03e735b462bc9ac7..59c6158dd2092a5c9131c514cd35ac137c960669 100644 --- a/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/train_8p.py +++ b/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/train_8p.py @@ -1,395 +1,395 @@ -# -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -from __future__ import print_function -import datetime -import os -import time -import sys -sys.path.insert(1,os.path.abspath('..')+ "/..") -import apex -import random -import torch -import torch.utils.data -from torch import nn -import torchvision -from torchvision import transforms -import torch.npu -import numpy as np -import inception -import torch.optim -import utils - -try: - from apex import amp -except ImportError: - amp = None - - -def train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, print_freq, apex=False): - model.train() - metric_logger = utils.MetricLogger(delimiter=" ") - metric_logger.add_meter('lr', utils.SmoothedValue(window_size=1, fmt='{value}')) - metric_logger.add_meter('img/s', utils.SmoothedValue(window_size=10, fmt='{value}')) - - header = 'Epoch: [{}]'.format(epoch) - cnt = 0 - n = 0 - for image, target in metric_logger.log_every(data_loader, print_freq, header): - n = n + 1 - if n >= 100: - pass - start_time = time.time() - image, target = image.to(device), target.to(torch.int).to(device) - output = model(image) - loss = criterion(output, target) - - optimizer.zero_grad() - if apex: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - - acc1, acc5 = utils.accuracy(output, target, topk=(1, 5)) - batch_size = image.shape[0] - metric_logger.update(loss=loss.item(), lr=optimizer.param_groups[0]["lr"]) - metric_logger.meters['acc1'].update(acc1.item(), n=batch_size) - metric_logger.meters['acc5'].update(acc5.item(), n=batch_size) - metric_logger.meters['img/s'].update(batch_size / (time.time() - start_time)) - cnt = cnt + 1 - - if args.max_steps and cnt > args.max_steps: - break - n = 0 - - -def evaluate(model, criterion, data_loader, device): - model.eval() - metric_logger = utils.MetricLogger(delimiter=" ") - header = 'Test:' - with torch.no_grad(): - n = 0 - for image, target in metric_logger.log_every(data_loader, 10, header): - n = n + 1 - if n >= 200: - pass - image = image.to(device, non_blocking=True) - target = target.to(torch.int).to(device, non_blocking=True) - output = model(image) - loss = criterion(output, target) - - acc1, acc5 = utils.accuracy(output, target, topk=(1, 5)) - # FIXME need to take into account that the datasets - # could have been padded in distributed setup - batch_size = image.shape[0] - metric_logger.update(loss=loss.item()) - metric_logger.meters['acc1'].update(acc1.item(), n=batch_size) - metric_logger.meters['acc5'].update(acc5.item(), n=batch_size) - n = 0 - # gather the stats from all processes - print(device) - metric_logger.synchronize_between_processes(device) - - print(' * Acc@1 {top1.global_avg:.3f} Acc@5 {top5.global_avg:.3f}' - .format(top1=metric_logger.acc1, top5=metric_logger.acc5)) - return metric_logger.acc1.global_avg - - -def _get_cache_path(filepath): - import hashlib - h = hashlib.sha1(filepath.encode()).hexdigest() - cache_path = os.path.join("~", ".torch", "vision", "datasets", "imagefolder", h[:10] + ".pt") - cache_path = os.path.expanduser(cache_path) - return cache_path - - -def main(args): - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = '29688' - args.device = os.environ['RANK_ID'] - - - rad = random.randint(0,50) - args.seed = args.seed + rad - random.seed(args.seed) - np.random.seed(args.seed) - torch.manual_seed(args.seed) - os.environ['PYTHONHASHSEED'] = str(args.seed) - if args.apex: - if sys.version_info < (3, 0): - raise RuntimeError("Apex currently only supports Python 3. Aborting.") - if amp is None: - raise RuntimeError("Failed to import apex. Please install apex from https://www.github.com/nvidia/apex " - "to enable mixed-precision training.") - - if args.output_dir: - utils.mkdir(args.output_dir) - - if args.distributed: - utils.init_distributed_mode(args) - - device = torch.device(f'npu:{args.device}') - torch.npu.set_device(device) - - #torch.backends.cudnn.benchmark = True - - # Data loading code - print("Loading data") - traindir = os.path.join(args.data_path, 'train') - valdir = os.path.join(args.data_path, 'val') - normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], - std=[0.229, 0.224, 0.225]) - - print("Loading training data") - st = time.time() - cache_path = _get_cache_path(traindir) - if args.cache_dataset and os.path.exists(cache_path): - # Attention, as the transforms are also cached! - print("Loading dataset_train from {}".format(cache_path)) - dataset, _ = torch.load(cache_path) - else: - dataset = torchvision.datasets.ImageFolder( - traindir, - transforms.Compose([ - transforms.RandomResizedCrop(299), - transforms.RandomHorizontalFlip(), - transforms.ToTensor(), - normalize, - ])) - if args.cache_dataset: - print("Saving dataset_train to {}".format(cache_path)) - utils.mkdir(os.path.dirname(cache_path)) - utils.save_on_master((dataset, traindir), cache_path) - print("Took", time.time() - st) - - print("Loading validation data") - cache_path = _get_cache_path(valdir) - if args.cache_dataset and os.path.exists(cache_path): - # Attention, as the transforms are also cached! - print("Loading dataset_test from {}".format(cache_path)) - dataset_test, _ = torch.load(cache_path) - else: - dataset_test = torchvision.datasets.ImageFolder( - valdir, - transforms.Compose([ - transforms.Resize(342), - transforms.CenterCrop(299), - transforms.ToTensor(), - normalize, - ])) - if args.cache_dataset: - print("Saving dataset_test to {}".format(cache_path)) - utils.mkdir(os.path.dirname(cache_path)) - utils.save_on_master((dataset_test, valdir), cache_path) - - print("Creating data loaders") - if args.distributed: - print(len(dataset)) - train_sampler = torch.utils.data.distributed.DistributedSampler(dataset) - print(len(train_sampler)) - test_sampler = torch.utils.data.distributed.DistributedSampler(dataset_test) - else: - train_sampler = torch.utils.data.RandomSampler(dataset) - test_sampler = torch.utils.data.SequentialSampler(dataset_test) - - print(len(train_sampler),args.batch_size,args.workers) - data_loader = torch.utils.data.DataLoader( - dataset, batch_size=args.batch_size, - sampler=train_sampler, num_workers=args.workers,drop_last=True) # pin_memory=True - print(len(data_loader)) - - data_loader_test = torch.utils.data.DataLoader( - dataset_test, batch_size=args.batch_size, - sampler=test_sampler, num_workers=args.workers, drop_last=True) - - print("Creating model") - print(torchvision.models.__dict__) - #model = torchvision.models.__dict__[args.model](pretrained=args.pretrained) - model = inception.inception_v3(pretrained=args.pretrained) - model.to(device) - if args.distributed and args.sync_bn: - model = torch.nn.SyncBatchNorm.convert_sync_batchnorm(model) - - - #criterion = nn.CrossEntropyLoss().to(device) - criterion = nn.CrossEntropyLoss() - - if args.apex: - optimizer = apex.optimizers.NpuFusedSGD( - model.parameters(), lr=args.lr, momentum=args.momentum, weight_decay=args.weight_decay) - - - if args.apex: - model, optimizer = amp.initialize(model, optimizer, - opt_level=args.apex_opt_level, - combine_grad=True - ) #loss_scale=args.loss_scale, - - lr_scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=args.lr_step_size, gamma=args.lr_gamma) - - model_without_ddp = model - if args.distributed: - print(args.device) - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.device],broadcast_buffers=False,find_unused_parameters=True) - model_without_ddp = model.module - - #optimizer = torch.optim.SGD( - #model.parameters(), lr=args.lr, momentum=args.momentum, weight_decay=args.weight_decay) - - if args.resume: - checkpoint = torch.load(args.resume, map_location='cpu') - model_without_ddp.load_state_dict(checkpoint['model']) - optimizer.load_state_dict(checkpoint['optimizer']) - lr_scheduler.load_state_dict(checkpoint['lr_scheduler']) - args.start_epoch = checkpoint['epoch'] + 1 - - if args.test_only: - evaluate(model, criterion, data_loader_test, device=device) - return - - print("Start training") - start_time = time.time() - for epoch in range(args.start_epoch, args.epochs): - if args.distributed: - train_sampler.set_epoch(epoch) - train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, args.print_freq, args.apex) - lr_scheduler.step() - evaluate(model, criterion, data_loader_test, device=device) - if args.output_dir: - checkpoint = { - 'model': model_without_ddp.state_dict(), - 'optimizer': optimizer.state_dict(), - 'lr_scheduler': lr_scheduler.state_dict(), - 'epoch': epoch, - 'args': args} - utils.save_on_master( - checkpoint, - os.path.join(args.output_dir, 'model_{}.pth'.format(epoch))) - utils.save_on_master( - checkpoint, - os.path.join(args.output_dir, 'checkpoint.pth')) - - total_time = time.time() - start_time - total_time_str = str(datetime.timedelta(seconds=int(total_time))) - print('Training time {}'.format(total_time_str)) - - -def parse_args(): - import argparse - parser = argparse.ArgumentParser(description='PyTorch Classification Training') - - parser.add_argument('--data-path', default='/datasets01/imagenet_full_size/061417/', help='dataset') - parser.add_argument('--model', default='resnet18', help='model') - parser.add_argument('--device', default='6', help='device') - parser.add_argument('-b', '--batch-size', default=32, type=int) - parser.add_argument('--epochs', default=90, type=int, metavar='N', - help='number of total epochs to run') - parser.add_argument('--max_steps', default=None, type=int, metavar='N', - help='number of total steps to run') - parser.add_argument('-j', '--workers', default=32, type=int, metavar='N', - help='number of data loading workers (default: 16)') - parser.add_argument('--lr', default=0.1, type=float, help='initial learning rate') - parser.add_argument('--momentum', default=0.9, type=float, metavar='M', - help='momentum') - parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, - metavar='W', help='weight decay (default: 1e-4)', - dest='weight_decay') - parser.add_argument('--lr-step-size', default=30, type=int, help='decrease lr every step-size epochs') - parser.add_argument('--lr-gamma', default=0.1, type=float, help='decrease lr by a factor of lr-gamma') - parser.add_argument('--print-freq', default=10, type=int, help='print frequency') - parser.add_argument('--output-dir', default='.', help='path where to save') - parser.add_argument('--resume', default='', help='resume from checkpoint') - parser.add_argument('--start-epoch', default=0, type=int, metavar='N', - help='start epoch') - parser.add_argument( - "--cache-dataset", - dest="cache_dataset", - help="Cache the datasets for quicker initialization. It also serializes the transforms", - action="store_true", - ) - parser.add_argument( - "--sync-bn", - dest="sync_bn", - help="Use sync batch norm", - action="store_true", - ) - parser.add_argument( - "--test-only", - dest="test_only", - help="Only test the model", - action="store_true", - ) - parser.add_argument( - "--pretrained", - dest="pretrained", - help="Use pre-trained models from the modelzoo", - action="store_true", - ) - - # Mixed precision training parameters - parser.add_argument('--apex', action='store_true', - help='Use apex for mixed precision training') - parser.add_argument('--apex-opt-level', default='O1', type=str, - help='For apex mixed precision training' - 'O0 for FP32 training, O1 for mixed precision training.' - 'For further detail, see https://github.com/NVIDIA/apex/tree/master/examples/imagenet' - ) - parser.add_argument('--loss_scale', default=1024., type=float, - help='loss scale using in amp, default -1 means dynamic') - - # distributed training parameters - parser.add_argument('--world-size', default=1, type=int, - help='number of distributed processes') - parser.add_argument('--dist-url', default='env://', help='url used to set up distributed training') - parser.add_argument('--distributed', - action='store_true', - help='Use multi-processing distributed training to launch ' - 'N processes per node, which has N GPUs.') - parser.add_argument('--dist_rank', - default=0, - type=int, - help='node rank for distributed training') - parser.add_argument('--seed', - default=1, - type=int, - help='Manually set random seed') - - args = parser.parse_args() - - return args - - -if __name__ == "__main__": - args = parse_args() - main(args) +# +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +from __future__ import print_function +import datetime +import os +import time +import sys +sys.path.insert(1,os.path.abspath('..')+ "/..") +import apex +import random +import torch +import torch.utils.data +from torch import nn +import torchvision +from torchvision import transforms +import torch.npu +import numpy as np +import inception +import torch.optim +import utils + +try: + from apex import amp +except ImportError: + amp = None + + +def train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, print_freq, apex=False): + model.train() + metric_logger = utils.MetricLogger(delimiter=" ") + metric_logger.add_meter('lr', utils.SmoothedValue(window_size=1, fmt='{value}')) + metric_logger.add_meter('img/s', utils.SmoothedValue(window_size=10, fmt='{value}')) + + header = 'Epoch: [{}]'.format(epoch) + cnt = 0 + n = 0 + for image, target in metric_logger.log_every(data_loader, print_freq, header): + n = n + 1 + if n >= 100: + pass + start_time = time.time() + image, target = image.to(device), target.to(torch.int).to(device) + output = model(image) + loss = criterion(output, target) + + optimizer.zero_grad() + if apex: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + + acc1, acc5 = utils.accuracy(output, target, topk=(1, 5)) + batch_size = image.shape[0] + metric_logger.update(loss=loss.item(), lr=optimizer.param_groups[0]["lr"]) + metric_logger.meters['acc1'].update(acc1.item(), n=batch_size) + metric_logger.meters['acc5'].update(acc5.item(), n=batch_size) + metric_logger.meters['img/s'].update(batch_size / (time.time() - start_time)) + cnt = cnt + 1 + + if args.max_steps and cnt > args.max_steps: + break + n = 0 + + +def evaluate(model, criterion, data_loader, device): + model.eval() + metric_logger = utils.MetricLogger(delimiter=" ") + header = 'Test:' + with torch.no_grad(): + n = 0 + for image, target in metric_logger.log_every(data_loader, 10, header): + n = n + 1 + if n >= 200: + pass + image = image.to(device, non_blocking=True) + target = target.to(torch.int).to(device, non_blocking=True) + output = model(image) + loss = criterion(output, target) + + acc1, acc5 = utils.accuracy(output, target, topk=(1, 5)) + # FIXME need to take into account that the datasets + # could have been padded in distributed setup + batch_size = image.shape[0] + metric_logger.update(loss=loss.item()) + metric_logger.meters['acc1'].update(acc1.item(), n=batch_size) + metric_logger.meters['acc5'].update(acc5.item(), n=batch_size) + n = 0 + # gather the stats from all processes + print(device) + metric_logger.synchronize_between_processes(device) + + print(' * Acc@1 {top1.global_avg:.3f} Acc@5 {top5.global_avg:.3f}' + .format(top1=metric_logger.acc1, top5=metric_logger.acc5)) + return metric_logger.acc1.global_avg + + +def _get_cache_path(filepath): + import hashlib + h = hashlib.sha1(filepath.encode()).hexdigest() + cache_path = os.path.join("~", ".torch", "vision", "datasets", "imagefolder", h[:10] + ".pt") + cache_path = os.path.expanduser(cache_path) + return cache_path + + +def main(args): + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '29688' + args.device = os.environ['RANK_ID'] + + + rad = random.randint(0,50) + args.seed = args.seed + rad + random.seed(args.seed) + np.random.seed(args.seed) + torch.manual_seed(args.seed) + os.environ['PYTHONHASHSEED'] = str(args.seed) + if args.apex: + if sys.version_info < (3, 0): + raise RuntimeError("Apex currently only supports Python 3. Aborting.") + if amp is None: + raise RuntimeError("Failed to import apex. Please install apex from https://www.github.com/nvidia/apex " + "to enable mixed-precision training.") + + if args.output_dir: + utils.mkdir(args.output_dir) + + if args.distributed: + utils.init_distributed_mode(args) + + device = torch.device(f'npu:{args.device}') + torch.npu.set_device(device) + + #torch.backends.cudnn.benchmark = True + + # Data loading code + print("Loading data") + traindir = os.path.join(args.data_path, 'train') + valdir = os.path.join(args.data_path, 'val') + normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]) + + print("Loading training data") + st = time.time() + cache_path = _get_cache_path(traindir) + if args.cache_dataset and os.path.exists(cache_path): + # Attention, as the transforms are also cached! + print("Loading dataset_train from {}".format(cache_path)) + dataset, _ = torch.load(cache_path) + else: + dataset = torchvision.datasets.ImageFolder( + traindir, + transforms.Compose([ + transforms.RandomResizedCrop(299), + transforms.RandomHorizontalFlip(), + transforms.ToTensor(), + normalize, + ])) + if args.cache_dataset: + print("Saving dataset_train to {}".format(cache_path)) + utils.mkdir(os.path.dirname(cache_path)) + utils.save_on_master((dataset, traindir), cache_path) + print("Took", time.time() - st) + + print("Loading validation data") + cache_path = _get_cache_path(valdir) + if args.cache_dataset and os.path.exists(cache_path): + # Attention, as the transforms are also cached! + print("Loading dataset_test from {}".format(cache_path)) + dataset_test, _ = torch.load(cache_path) + else: + dataset_test = torchvision.datasets.ImageFolder( + valdir, + transforms.Compose([ + transforms.Resize(342), + transforms.CenterCrop(299), + transforms.ToTensor(), + normalize, + ])) + if args.cache_dataset: + print("Saving dataset_test to {}".format(cache_path)) + utils.mkdir(os.path.dirname(cache_path)) + utils.save_on_master((dataset_test, valdir), cache_path) + + print("Creating data loaders") + if args.distributed: + print(len(dataset)) + train_sampler = torch.utils.data.distributed.DistributedSampler(dataset) + print(len(train_sampler)) + test_sampler = torch.utils.data.distributed.DistributedSampler(dataset_test) + else: + train_sampler = torch.utils.data.RandomSampler(dataset) + test_sampler = torch.utils.data.SequentialSampler(dataset_test) + + print(len(train_sampler),args.batch_size,args.workers) + data_loader = torch.utils.data.DataLoader( + dataset, batch_size=args.batch_size, + sampler=train_sampler, num_workers=args.workers,drop_last=True) # pin_memory=True + print(len(data_loader)) + + data_loader_test = torch.utils.data.DataLoader( + dataset_test, batch_size=args.batch_size, + sampler=test_sampler, num_workers=args.workers, drop_last=True) + + print("Creating model") + print(torchvision.models.__dict__) + #model = torchvision.models.__dict__[args.model](pretrained=args.pretrained) + model = inception.inception_v3(pretrained=args.pretrained) + model.to(device) + if args.distributed and args.sync_bn: + model = torch.nn.SyncBatchNorm.convert_sync_batchnorm(model) + + + #criterion = nn.CrossEntropyLoss().to(device) + criterion = nn.CrossEntropyLoss() + + if args.apex: + optimizer = apex.optimizers.NpuFusedSGD( + model.parameters(), lr=args.lr, momentum=args.momentum, weight_decay=args.weight_decay) + + + if args.apex: + model, optimizer = amp.initialize(model, optimizer, + opt_level=args.apex_opt_level, + combine_grad=True + ) #loss_scale=args.loss_scale, + + lr_scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=args.lr_step_size, gamma=args.lr_gamma) + + model_without_ddp = model + if args.distributed: + print(args.device) + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.device],broadcast_buffers=False,find_unused_parameters=True) + model_without_ddp = model.module + + #optimizer = torch.optim.SGD( + #model.parameters(), lr=args.lr, momentum=args.momentum, weight_decay=args.weight_decay) + + if args.resume: + checkpoint = torch.load(args.resume, map_location='cpu') + model_without_ddp.load_state_dict(checkpoint['model']) + optimizer.load_state_dict(checkpoint['optimizer']) + lr_scheduler.load_state_dict(checkpoint['lr_scheduler']) + args.start_epoch = checkpoint['epoch'] + 1 + + if args.test_only: + evaluate(model, criterion, data_loader_test, device=device) + return + + print("Start training") + start_time = time.time() + for epoch in range(args.start_epoch, args.epochs): + if args.distributed: + train_sampler.set_epoch(epoch) + train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, args.print_freq, args.apex) + lr_scheduler.step() + evaluate(model, criterion, data_loader_test, device=device) + if args.output_dir: + checkpoint = { + 'model': model_without_ddp.state_dict(), + 'optimizer': optimizer.state_dict(), + 'lr_scheduler': lr_scheduler.state_dict(), + 'epoch': epoch, + 'args': args} + utils.save_on_master( + checkpoint, + os.path.join(args.output_dir, 'model_{}.pth'.format(epoch))) + utils.save_on_master( + checkpoint, + os.path.join(args.output_dir, 'checkpoint.pth')) + + total_time = time.time() - start_time + total_time_str = str(datetime.timedelta(seconds=int(total_time))) + print('Training time {}'.format(total_time_str)) + + +def parse_args(): + import argparse + parser = argparse.ArgumentParser(description='PyTorch Classification Training') + + parser.add_argument('--data-path', default='/datasets01/imagenet_full_size/061417/', help='dataset') + parser.add_argument('--model', default='resnet18', help='model') + parser.add_argument('--device', default='6', help='device') + parser.add_argument('-b', '--batch-size', default=32, type=int) + parser.add_argument('--epochs', default=90, type=int, metavar='N', + help='number of total epochs to run') + parser.add_argument('--max_steps', default=None, type=int, metavar='N', + help='number of total steps to run') + parser.add_argument('-j', '--workers', default=32, type=int, metavar='N', + help='number of data loading workers (default: 16)') + parser.add_argument('--lr', default=0.1, type=float, help='initial learning rate') + parser.add_argument('--momentum', default=0.9, type=float, metavar='M', + help='momentum') + parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, + metavar='W', help='weight decay (default: 1e-4)', + dest='weight_decay') + parser.add_argument('--lr-step-size', default=30, type=int, help='decrease lr every step-size epochs') + parser.add_argument('--lr-gamma', default=0.1, type=float, help='decrease lr by a factor of lr-gamma') + parser.add_argument('--print-freq', default=10, type=int, help='print frequency') + parser.add_argument('--output-dir', default='.', help='path where to save') + parser.add_argument('--resume', default='', help='resume from checkpoint') + parser.add_argument('--start-epoch', default=0, type=int, metavar='N', + help='start epoch') + parser.add_argument( + "--cache-dataset", + dest="cache_dataset", + help="Cache the datasets for quicker initialization. It also serializes the transforms", + action="store_true", + ) + parser.add_argument( + "--sync-bn", + dest="sync_bn", + help="Use sync batch norm", + action="store_true", + ) + parser.add_argument( + "--test-only", + dest="test_only", + help="Only test the model", + action="store_true", + ) + parser.add_argument( + "--pretrained", + dest="pretrained", + help="Use pre-trained models from the modelzoo", + action="store_true", + ) + + # Mixed precision training parameters + parser.add_argument('--apex', action='store_true', + help='Use apex for mixed precision training') + parser.add_argument('--apex-opt-level', default='O1', type=str, + help='For apex mixed precision training' + 'O0 for FP32 training, O1 for mixed precision training.' + 'For further detail, see https://github.com/NVIDIA/apex/tree/master/examples/imagenet' + ) + parser.add_argument('--loss_scale', default=1024., type=float, + help='loss scale using in amp, default -1 means dynamic') + + # distributed training parameters + parser.add_argument('--world-size', default=1, type=int, + help='number of distributed processes') + parser.add_argument('--dist-url', default='env://', help='url used to set up distributed training') + parser.add_argument('--distributed', + action='store_true', + help='Use multi-processing distributed training to launch ' + 'N processes per node, which has N GPUs.') + parser.add_argument('--dist_rank', + default=0, + type=int, + help='node rank for distributed training') + parser.add_argument('--seed', + default=1, + type=int, + help='Manually set random seed') + + args = parser.parse_args() + + return args + + +if __name__ == "__main__": + args = parse_args() + main(args) diff --git a/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/train_8p_aux.py b/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/train_8p_aux.py index d86c45d9878e587ca08a6f6452825fd3321d3814..220ea58448446cc33cc29c496207cdcdcbfca488 100644 --- a/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/train_8p_aux.py +++ b/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/train_8p_aux.py @@ -1,394 +1,394 @@ -# -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -from __future__ import print_function -import datetime -import os -import time -import sys -sys.path.insert(1,os.path.abspath('..')+ "/..") -import apex -import random -import torch -import torch.utils.data -from torch import nn -import torchvision -from torchvision import transforms -import torch.npu -import numpy as np -import inception - -import utils - -try: - from apex import amp -except ImportError: - amp = None - - -def train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, print_freq, apex=False): - model.train() - metric_logger = utils.MetricLogger(delimiter=" ") - metric_logger.add_meter('lr', utils.SmoothedValue(window_size=1, fmt='{value}')) - metric_logger.add_meter('img/s', utils.SmoothedValue(window_size=10, fmt='{value}')) - - header = 'Epoch: [{}]'.format(epoch) - cnt = 0 - n = 0 - for image, target in metric_logger.log_every(data_loader, print_freq, header): - n = n + 1 - if n >= 100: - pass - start_time = time.time() - image, target = image.to(device), target.to(torch.int).to(device) - output,aux = model(image) - loss1 = criterion(output, target) - loss2 = criterion(aux, target) - loss = loss1 + 0.4*loss2 - - optimizer.zero_grad() - if apex: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - - acc1, acc5 = utils.accuracy(output, target, topk=(1, 5)) - batch_size = image.shape[0] - metric_logger.update(loss=loss.item(), lr=optimizer.param_groups[0]["lr"]) - metric_logger.meters['acc1'].update(acc1.item(), n=batch_size) - metric_logger.meters['acc5'].update(acc5.item(), n=batch_size) - metric_logger.meters['img/s'].update(batch_size / (time.time() - start_time)) - cnt = cnt + 1 - - if args.max_steps and cnt > args.max_steps: - break - n = 0 - - -def evaluate(model, criterion, data_loader, device): - model.eval() - metric_logger = utils.MetricLogger(delimiter=" ") - header = 'Test:' - with torch.no_grad(): - n = 0 - for image, target in metric_logger.log_every(data_loader, 100, header): - n = n + 1 - if n >= 200: - pass - image = image.to(device, non_blocking=True) - target = target.to(torch.int).to(device, non_blocking=True) - output= model(image) - loss1 = criterion(output, target) - - loss = loss1 - - acc1, acc5 = utils.accuracy(output, target, topk=(1, 5)) - # FIXME need to take into account that the datasets - # could have been padded in distributed setup - batch_size = image.shape[0] - metric_logger.update(loss=loss.item()) - metric_logger.meters['acc1'].update(acc1.item(), n=batch_size) - metric_logger.meters['acc5'].update(acc5.item(), n=batch_size) - n = 0 - # gather the stats from all processes - print(device) - metric_logger.synchronize_between_processes(device) - - print(' * Acc@1 {top1.global_avg:.3f} Acc@5 {top5.global_avg:.3f}' - .format(top1=metric_logger.acc1, top5=metric_logger.acc5)) - return metric_logger.acc1.global_avg - - -def _get_cache_path(filepath): - import hashlib - h = hashlib.sha1(filepath.encode()).hexdigest() - cache_path = os.path.join("~", ".torch", "vision", "datasets", "imagefolder", h[:10] + ".pt") - cache_path = os.path.expanduser(cache_path) - return cache_path - - -def main(args): - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = '29688' - args.device = os.environ['RANK_ID'] - - rad = random.randint(0,50) - args.seed = args.seed + rad - random.seed(args.seed) - np.random.seed(args.seed) - torch.manual_seed(args.seed) - os.environ['PYTHONHASHSEED'] = str(args.seed) - if args.apex: - if sys.version_info < (3, 0): - raise RuntimeError("Apex currently only supports Python 3. Aborting.") - if amp is None: - raise RuntimeError("Failed to import apex. Please install apex from https://www.github.com/nvidia/apex " - "to enable mixed-precision training.") - - if args.output_dir: - utils.mkdir(args.output_dir) - - if args.distributed: - utils.init_distributed_mode(args) - - device = torch.device(f'npu:{args.device}') - torch.npu.set_device(device) - - torch.backends.cudnn.benchmark = True - - # Data loading code - print("Loading data") - traindir = os.path.join(args.data_path, 'train') - valdir = os.path.join(args.data_path, 'val') - normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], - std=[0.229, 0.224, 0.225]) - - print("Loading training data") - st = time.time() - cache_path = _get_cache_path(traindir) - if args.cache_dataset and os.path.exists(cache_path): - # Attention, as the transforms are also cached! - print("Loading dataset_train from {}".format(cache_path)) - dataset, _ = torch.load(cache_path) - else: - dataset = torchvision.datasets.ImageFolder( - traindir, - transforms.Compose([ - transforms.RandomResizedCrop(299), - transforms.RandomHorizontalFlip(), - transforms.ToTensor(), - normalize, - ])) - if args.cache_dataset: - print("Saving dataset_train to {}".format(cache_path)) - utils.mkdir(os.path.dirname(cache_path)) - utils.save_on_master((dataset, traindir), cache_path) - print("Took", time.time() - st) - - print("Loading validation data") - cache_path = _get_cache_path(valdir) - if args.cache_dataset and os.path.exists(cache_path): - # Attention, as the transforms are also cached! - print("Loading dataset_test from {}".format(cache_path)) - dataset_test, _ = torch.load(cache_path) - else: - dataset_test = torchvision.datasets.ImageFolder( - valdir, - transforms.Compose([ - transforms.Resize(342), - transforms.CenterCrop(299), - transforms.ToTensor(), - normalize, - ])) - if args.cache_dataset: - print("Saving dataset_test to {}".format(cache_path)) - utils.mkdir(os.path.dirname(cache_path)) - utils.save_on_master((dataset_test, valdir), cache_path) - - print("Creating data loaders") - if args.distributed: - print(len(dataset)) - train_sampler = torch.utils.data.distributed.DistributedSampler(dataset) - print(len(train_sampler)) - test_sampler = torch.utils.data.distributed.DistributedSampler(dataset_test) - else: - train_sampler = torch.utils.data.RandomSampler(dataset) - test_sampler = torch.utils.data.SequentialSampler(dataset_test) - - print(len(train_sampler),args.batch_size,args.workers) - data_loader = torch.utils.data.DataLoader( - dataset, batch_size=args.batch_size, - sampler=train_sampler, num_workers=args.workers,drop_last=True) # pin_memory=True - print(len(data_loader)) - - data_loader_test = torch.utils.data.DataLoader( - dataset_test, batch_size=args.batch_size, - sampler=test_sampler, num_workers=args.workers, drop_last=True) - - print("Creating model") - print(torchvision.models.__dict__) - model = torchvision.models.__dict__[args.model](pretrained=args.pretrained) - #model = inception.inception_v3(pretrained=args.pretrained) - model.to(device) - - - - criterion = nn.CrossEntropyLoss().to(device) - #criterion = nn.CrossEntropyLoss() - - optimizer = apex.optimizers.NpuFusedSGD( - model.parameters(), lr=args.lr, momentum=args.momentum, weight_decay=args.weight_decay) - - if args.apex: - model, optimizer = amp.initialize(model, optimizer, - opt_level=args.apex_opt_level, - loss_scale=args.loss_scale, - combine_grad=True - ) #loss_scale=args.loss_scale, - - lr_scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=args.lr_step_size, gamma=args.lr_gamma) - - model_without_ddp = model - - if args.distributed: - print(args.device) - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.device],find_unused_parameters=True) # output_device=args.device, - model_without_ddp = model.module - - if args.resume: - checkpoint = torch.load(args.resume, map_location='cpu') - model_without_ddp.load_state_dict(checkpoint['model']) - optimizer.load_state_dict(checkpoint['optimizer']) - lr_scheduler.load_state_dict(checkpoint['lr_scheduler']) - args.start_epoch = checkpoint['epoch'] + 1 - - if args.test_only: - evaluate(model, criterion, data_loader_test, device=device) - return - - print("Start training") - start_time = time.time() - for epoch in range(args.start_epoch, args.epochs): - if args.distributed: - train_sampler.set_epoch(epoch) - train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, args.print_freq, args.apex) - lr_scheduler.step() - evaluate(model, criterion, data_loader_test, device=device) - if args.output_dir: - checkpoint = { - 'model': model_without_ddp.state_dict(), - 'optimizer': optimizer.state_dict(), - 'lr_scheduler': lr_scheduler.state_dict(), - 'epoch': epoch, - 'args': args} - utils.save_on_master( - checkpoint, - os.path.join(args.output_dir, 'model_{}.pth'.format(epoch))) - utils.save_on_master( - checkpoint, - os.path.join(args.output_dir, 'checkpoint.pth')) - - total_time = time.time() - start_time - total_time_str = str(datetime.timedelta(seconds=int(total_time))) - print('Training time {}'.format(total_time_str)) - - -def parse_args(): - import argparse - parser = argparse.ArgumentParser(description='PyTorch Classification Training') - - parser.add_argument('--data-path', default='/datasets01/imagenet_full_size/061417/', help='dataset') - parser.add_argument('--model', default='resnet18', help='model') - parser.add_argument('--device', default='6', help='device') - parser.add_argument('-b', '--batch-size', default=32, type=int) - parser.add_argument('--epochs', default=90, type=int, metavar='N', - help='number of total epochs to run') - parser.add_argument('--max_steps', default=None, type=int, metavar='N', - help='number of total steps to run') - parser.add_argument('-j', '--workers', default=32, type=int, metavar='N', - help='number of data loading workers (default: 16)') - parser.add_argument('--lr', default=0.1, type=float, help='initial learning rate') - parser.add_argument('--momentum', default=0.9, type=float, metavar='M', - help='momentum') - parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, - metavar='W', help='weight decay (default: 1e-4)', - dest='weight_decay') - parser.add_argument('--lr-step-size', default=30, type=int, help='decrease lr every step-size epochs') - parser.add_argument('--lr-gamma', default=0.1, type=float, help='decrease lr by a factor of lr-gamma') - parser.add_argument('--print-freq', default=10, type=int, help='print frequency') - parser.add_argument('--output-dir', default='.', help='path where to save') - parser.add_argument('--resume', default='', help='resume from checkpoint') - parser.add_argument('--start-epoch', default=0, type=int, metavar='N', - help='start epoch') - parser.add_argument( - "--cache-dataset", - dest="cache_dataset", - help="Cache the datasets for quicker initialization. It also serializes the transforms", - action="store_true", - ) - parser.add_argument( - "--sync-bn", - dest="sync_bn", - help="Use sync batch norm", - action="store_true", - ) - parser.add_argument( - "--test-only", - dest="test_only", - help="Only test the model", - action="store_true", - ) - parser.add_argument( - "--pretrained", - dest="pretrained", - help="Use pre-trained models from the modelzoo", - action="store_true", - ) - - # Mixed precision training parameters - parser.add_argument('--apex', action='store_true', - help='Use apex for mixed precision training') - parser.add_argument('--apex-opt-level', default='O1', type=str, - help='For apex mixed precision training' - 'O0 for FP32 training, O1 for mixed precision training.' - 'For further detail, see https://github.com/NVIDIA/apex/tree/master/examples/imagenet' - ) - parser.add_argument('--loss_scale', default=1024., type=float, - help='loss scale using in amp, default -1 means dynamic') - - # distributed training parameters - parser.add_argument('--world-size', default=1, type=int, - help='number of distributed processes') - parser.add_argument('--dist-url', default='env://', help='url used to set up distributed training') - parser.add_argument('--distributed', - action='store_true', - help='Use multi-processing distributed training to launch ' - 'N processes per node, which has N GPUs.') - parser.add_argument('--dist_rank', - default=0, - type=int, - help='node rank for distributed training') - parser.add_argument('--seed', - default=1, - type=int, - help='Manually set random seed') - - args = parser.parse_args() - - return args - - -if __name__ == "__main__": - args = parse_args() - main(args) +# +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +from __future__ import print_function +import datetime +import os +import time +import sys +sys.path.insert(1,os.path.abspath('..')+ "/..") +import apex +import random +import torch +import torch.utils.data +from torch import nn +import torchvision +from torchvision import transforms +import torch.npu +import numpy as np +import inception + +import utils + +try: + from apex import amp +except ImportError: + amp = None + + +def train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, print_freq, apex=False): + model.train() + metric_logger = utils.MetricLogger(delimiter=" ") + metric_logger.add_meter('lr', utils.SmoothedValue(window_size=1, fmt='{value}')) + metric_logger.add_meter('img/s', utils.SmoothedValue(window_size=10, fmt='{value}')) + + header = 'Epoch: [{}]'.format(epoch) + cnt = 0 + n = 0 + for image, target in metric_logger.log_every(data_loader, print_freq, header): + n = n + 1 + if n >= 100: + pass + start_time = time.time() + image, target = image.to(device), target.to(torch.int).to(device) + output,aux = model(image) + loss1 = criterion(output, target) + loss2 = criterion(aux, target) + loss = loss1 + 0.4*loss2 + + optimizer.zero_grad() + if apex: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + + acc1, acc5 = utils.accuracy(output, target, topk=(1, 5)) + batch_size = image.shape[0] + metric_logger.update(loss=loss.item(), lr=optimizer.param_groups[0]["lr"]) + metric_logger.meters['acc1'].update(acc1.item(), n=batch_size) + metric_logger.meters['acc5'].update(acc5.item(), n=batch_size) + metric_logger.meters['img/s'].update(batch_size / (time.time() - start_time)) + cnt = cnt + 1 + + if args.max_steps and cnt > args.max_steps: + break + n = 0 + + +def evaluate(model, criterion, data_loader, device): + model.eval() + metric_logger = utils.MetricLogger(delimiter=" ") + header = 'Test:' + with torch.no_grad(): + n = 0 + for image, target in metric_logger.log_every(data_loader, 100, header): + n = n + 1 + if n >= 200: + pass + image = image.to(device, non_blocking=True) + target = target.to(torch.int).to(device, non_blocking=True) + output= model(image) + loss1 = criterion(output, target) + + loss = loss1 + + acc1, acc5 = utils.accuracy(output, target, topk=(1, 5)) + # FIXME need to take into account that the datasets + # could have been padded in distributed setup + batch_size = image.shape[0] + metric_logger.update(loss=loss.item()) + metric_logger.meters['acc1'].update(acc1.item(), n=batch_size) + metric_logger.meters['acc5'].update(acc5.item(), n=batch_size) + n = 0 + # gather the stats from all processes + print(device) + metric_logger.synchronize_between_processes(device) + + print(' * Acc@1 {top1.global_avg:.3f} Acc@5 {top5.global_avg:.3f}' + .format(top1=metric_logger.acc1, top5=metric_logger.acc5)) + return metric_logger.acc1.global_avg + + +def _get_cache_path(filepath): + import hashlib + h = hashlib.sha1(filepath.encode()).hexdigest() + cache_path = os.path.join("~", ".torch", "vision", "datasets", "imagefolder", h[:10] + ".pt") + cache_path = os.path.expanduser(cache_path) + return cache_path + + +def main(args): + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '29688' + args.device = os.environ['RANK_ID'] + + rad = random.randint(0,50) + args.seed = args.seed + rad + random.seed(args.seed) + np.random.seed(args.seed) + torch.manual_seed(args.seed) + os.environ['PYTHONHASHSEED'] = str(args.seed) + if args.apex: + if sys.version_info < (3, 0): + raise RuntimeError("Apex currently only supports Python 3. Aborting.") + if amp is None: + raise RuntimeError("Failed to import apex. Please install apex from https://www.github.com/nvidia/apex " + "to enable mixed-precision training.") + + if args.output_dir: + utils.mkdir(args.output_dir) + + if args.distributed: + utils.init_distributed_mode(args) + + device = torch.device(f'npu:{args.device}') + torch.npu.set_device(device) + + torch.backends.cudnn.benchmark = True + + # Data loading code + print("Loading data") + traindir = os.path.join(args.data_path, 'train') + valdir = os.path.join(args.data_path, 'val') + normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]) + + print("Loading training data") + st = time.time() + cache_path = _get_cache_path(traindir) + if args.cache_dataset and os.path.exists(cache_path): + # Attention, as the transforms are also cached! + print("Loading dataset_train from {}".format(cache_path)) + dataset, _ = torch.load(cache_path) + else: + dataset = torchvision.datasets.ImageFolder( + traindir, + transforms.Compose([ + transforms.RandomResizedCrop(299), + transforms.RandomHorizontalFlip(), + transforms.ToTensor(), + normalize, + ])) + if args.cache_dataset: + print("Saving dataset_train to {}".format(cache_path)) + utils.mkdir(os.path.dirname(cache_path)) + utils.save_on_master((dataset, traindir), cache_path) + print("Took", time.time() - st) + + print("Loading validation data") + cache_path = _get_cache_path(valdir) + if args.cache_dataset and os.path.exists(cache_path): + # Attention, as the transforms are also cached! + print("Loading dataset_test from {}".format(cache_path)) + dataset_test, _ = torch.load(cache_path) + else: + dataset_test = torchvision.datasets.ImageFolder( + valdir, + transforms.Compose([ + transforms.Resize(342), + transforms.CenterCrop(299), + transforms.ToTensor(), + normalize, + ])) + if args.cache_dataset: + print("Saving dataset_test to {}".format(cache_path)) + utils.mkdir(os.path.dirname(cache_path)) + utils.save_on_master((dataset_test, valdir), cache_path) + + print("Creating data loaders") + if args.distributed: + print(len(dataset)) + train_sampler = torch.utils.data.distributed.DistributedSampler(dataset) + print(len(train_sampler)) + test_sampler = torch.utils.data.distributed.DistributedSampler(dataset_test) + else: + train_sampler = torch.utils.data.RandomSampler(dataset) + test_sampler = torch.utils.data.SequentialSampler(dataset_test) + + print(len(train_sampler),args.batch_size,args.workers) + data_loader = torch.utils.data.DataLoader( + dataset, batch_size=args.batch_size, + sampler=train_sampler, num_workers=args.workers,drop_last=True) # pin_memory=True + print(len(data_loader)) + + data_loader_test = torch.utils.data.DataLoader( + dataset_test, batch_size=args.batch_size, + sampler=test_sampler, num_workers=args.workers, drop_last=True) + + print("Creating model") + print(torchvision.models.__dict__) + model = torchvision.models.__dict__[args.model](pretrained=args.pretrained) + #model = inception.inception_v3(pretrained=args.pretrained) + model.to(device) + + + + criterion = nn.CrossEntropyLoss().to(device) + #criterion = nn.CrossEntropyLoss() + + optimizer = apex.optimizers.NpuFusedSGD( + model.parameters(), lr=args.lr, momentum=args.momentum, weight_decay=args.weight_decay) + + if args.apex: + model, optimizer = amp.initialize(model, optimizer, + opt_level=args.apex_opt_level, + loss_scale=args.loss_scale, + combine_grad=True + ) #loss_scale=args.loss_scale, + + lr_scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=args.lr_step_size, gamma=args.lr_gamma) + + model_without_ddp = model + + if args.distributed: + print(args.device) + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.device],find_unused_parameters=True) # output_device=args.device, + model_without_ddp = model.module + + if args.resume: + checkpoint = torch.load(args.resume, map_location='cpu') + model_without_ddp.load_state_dict(checkpoint['model']) + optimizer.load_state_dict(checkpoint['optimizer']) + lr_scheduler.load_state_dict(checkpoint['lr_scheduler']) + args.start_epoch = checkpoint['epoch'] + 1 + + if args.test_only: + evaluate(model, criterion, data_loader_test, device=device) + return + + print("Start training") + start_time = time.time() + for epoch in range(args.start_epoch, args.epochs): + if args.distributed: + train_sampler.set_epoch(epoch) + train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, args.print_freq, args.apex) + lr_scheduler.step() + evaluate(model, criterion, data_loader_test, device=device) + if args.output_dir: + checkpoint = { + 'model': model_without_ddp.state_dict(), + 'optimizer': optimizer.state_dict(), + 'lr_scheduler': lr_scheduler.state_dict(), + 'epoch': epoch, + 'args': args} + utils.save_on_master( + checkpoint, + os.path.join(args.output_dir, 'model_{}.pth'.format(epoch))) + utils.save_on_master( + checkpoint, + os.path.join(args.output_dir, 'checkpoint.pth')) + + total_time = time.time() - start_time + total_time_str = str(datetime.timedelta(seconds=int(total_time))) + print('Training time {}'.format(total_time_str)) + + +def parse_args(): + import argparse + parser = argparse.ArgumentParser(description='PyTorch Classification Training') + + parser.add_argument('--data-path', default='/datasets01/imagenet_full_size/061417/', help='dataset') + parser.add_argument('--model', default='resnet18', help='model') + parser.add_argument('--device', default='6', help='device') + parser.add_argument('-b', '--batch-size', default=32, type=int) + parser.add_argument('--epochs', default=90, type=int, metavar='N', + help='number of total epochs to run') + parser.add_argument('--max_steps', default=None, type=int, metavar='N', + help='number of total steps to run') + parser.add_argument('-j', '--workers', default=32, type=int, metavar='N', + help='number of data loading workers (default: 16)') + parser.add_argument('--lr', default=0.1, type=float, help='initial learning rate') + parser.add_argument('--momentum', default=0.9, type=float, metavar='M', + help='momentum') + parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, + metavar='W', help='weight decay (default: 1e-4)', + dest='weight_decay') + parser.add_argument('--lr-step-size', default=30, type=int, help='decrease lr every step-size epochs') + parser.add_argument('--lr-gamma', default=0.1, type=float, help='decrease lr by a factor of lr-gamma') + parser.add_argument('--print-freq', default=10, type=int, help='print frequency') + parser.add_argument('--output-dir', default='.', help='path where to save') + parser.add_argument('--resume', default='', help='resume from checkpoint') + parser.add_argument('--start-epoch', default=0, type=int, metavar='N', + help='start epoch') + parser.add_argument( + "--cache-dataset", + dest="cache_dataset", + help="Cache the datasets for quicker initialization. It also serializes the transforms", + action="store_true", + ) + parser.add_argument( + "--sync-bn", + dest="sync_bn", + help="Use sync batch norm", + action="store_true", + ) + parser.add_argument( + "--test-only", + dest="test_only", + help="Only test the model", + action="store_true", + ) + parser.add_argument( + "--pretrained", + dest="pretrained", + help="Use pre-trained models from the modelzoo", + action="store_true", + ) + + # Mixed precision training parameters + parser.add_argument('--apex', action='store_true', + help='Use apex for mixed precision training') + parser.add_argument('--apex-opt-level', default='O1', type=str, + help='For apex mixed precision training' + 'O0 for FP32 training, O1 for mixed precision training.' + 'For further detail, see https://github.com/NVIDIA/apex/tree/master/examples/imagenet' + ) + parser.add_argument('--loss_scale', default=1024., type=float, + help='loss scale using in amp, default -1 means dynamic') + + # distributed training parameters + parser.add_argument('--world-size', default=1, type=int, + help='number of distributed processes') + parser.add_argument('--dist-url', default='env://', help='url used to set up distributed training') + parser.add_argument('--distributed', + action='store_true', + help='Use multi-processing distributed training to launch ' + 'N processes per node, which has N GPUs.') + parser.add_argument('--dist_rank', + default=0, + type=int, + help='node rank for distributed training') + parser.add_argument('--seed', + default=1, + type=int, + help='Manually set random seed') + + args = parser.parse_args() + + return args + + +if __name__ == "__main__": + args = parse_args() + main(args) diff --git a/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/utils3.py b/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/utils3.py index 3ac42e9b7b763e06e8d5d1bcde192b308c44f1a1..b41e2d90abea88f9393a588a82a03a882d0989a7 100644 --- a/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/utils3.py +++ b/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch/utils3.py @@ -1,288 +1,288 @@ -# -# BSD 3-Clause License -# -# Copyright (c) 2017 xxxx -# All rights reserved. -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ============================================================================ -#from __future__ import print_function -from collections import defaultdict, deque -import datetime -import time -import torch -import torch.distributed as dist - -import errno -import os - - -class SmoothedValue(object): - """Track a series of values and provide access to smoothed values over a - window or the global series average. - """ - - def __init__(self, window_size=20, fmt=None): - if fmt is None: - fmt = "{median:.4f} ({global_avg:.4f})" - self.deque = deque(maxlen=window_size) - self.total = 0.0 - self.count = 0.0 - self.fmt = fmt - - def update(self, value, n=1): - self.deque.append(value) - self.count += n - self.total += value * n - - def synchronize_between_processes(self,npu_device): - """ - Warning: does not synchronize the deque! - """ - if not is_dist_avail_and_initialized(): - return - t = torch.as_tensor([self.count, self.total], dtype=torch.float32, device=npu_device) - print(t,t.dtype) - dist.barrier() - dist.all_reduce(t) - t = t.tolist() - self.count = int(t[0]) - self.total = t[1] - - @property - def median(self): - d = torch.tensor(list(self.deque)) - return d.median().item() - - @property - def avg(self): - d = torch.tensor(list(self.deque), dtype=torch.float32) - return d.mean().item() - - @property - def global_avg(self): - return self.total / self.count - - @property - def max(self): - return max(self.deque) - - @property - def value(self): - return self.deque[-1] - - def __str__(self): - return self.fmt.format( - median=self.median, - avg=self.avg, - global_avg=self.global_avg, - max=self.max, - value=self.value) - - -class MetricLogger(object): - def __init__(self, delimiter="\t"): - self.meters = defaultdict(SmoothedValue) - self.delimiter = delimiter - - def update(self, **kwargs): - for k, v in kwargs.items(): - if isinstance(v, torch.Tensor): - v = v.item() - assert isinstance(v, (float, int)) - self.meters[k].update(v) - - def __getattr__(self, attr): - if attr in self.meters: - return self.meters[attr] - if attr in self.__dict__: - return self.__dict__[attr] - raise AttributeError("'{}' object has no attribute '{}'".format( - type(self).__name__, attr)) - - def __str__(self): - loss_str = [] - for name, meter in self.meters.items(): - loss_str.append( - "{}: {}".format(name, str(meter)) - ) - return self.delimiter.join(loss_str) - - def synchronize_between_processes(self,device): - for meter in self.meters.values(): - meter.synchronize_between_processes(device) - - def add_meter(self, name, meter): - self.meters[name] = meter - - def log_every(self, iterable, print_freq, header=None): - i = 0 - if not header: - header = '' - start_time = time.time() - end = time.time() - iter_time = SmoothedValue(fmt='{avg:.4f}') - data_time = SmoothedValue(fmt='{avg:.4f}') - space_fmt = ':' + str(len(str(len(iterable)))) + 'd' - if torch.npu.is_available(): - log_msg = self.delimiter.join([ - header, - '[{0' + space_fmt + '}/{1}]', - 'eta: {eta}', - '{meters}', - 'time: {time}', - 'data: {data}', - 'max mem: {memory:.0f}' - ]) - else: - log_msg = self.delimiter.join([ - header, - '[{0' + space_fmt + '}/{1}]', - 'eta: {eta}', - '{meters}', - 'time: {time}', - 'data: {data}' - ]) - MB = 1024.0 * 1024.0 - for obj in iterable: - data_time.update(time.time() - end) - yield obj - iter_time.update(time.time() - end) - if i % print_freq == 0: - eta_seconds = iter_time.global_avg * (len(iterable) - i) - eta_string = str(datetime.timedelta(seconds=int(eta_seconds))) - if torch.npu.is_available(): - print(log_msg.format( - i, len(iterable), eta=eta_string, - meters=str(self), - time=str(iter_time), data=str(data_time), - memory=0)) - #memory=torch.cuda.max_memory_allocated() / MB)) - else: - print(log_msg.format( - i, len(iterable), eta=eta_string, - meters=str(self), - time=str(iter_time), data=str(data_time))) - i += 1 - end = time.time() - total_time = time.time() - start_time - total_time_str = str(datetime.timedelta(seconds=int(total_time))) - print('{} Total time: {}'.format(header, total_time_str)) - - -def accuracy(output, target, topk=(1,)): - """Computes the accuracy over the k top predictions for the specified values of k""" - with torch.no_grad(): - maxk = max(topk) - batch_size = target.size(0) - - _, pred = output.topk(maxk, 1, True, True) - pred = pred.t() - correct = pred.eq(target[None]) - - res = [] - for k in topk: - correct_k = correct[:k].flatten().sum(dtype=torch.float32) - res.append(correct_k * (100.0 / batch_size)) - return res - - -def mkdir(path): - try: - os.makedirs(path) - except OSError as e: - if e.errno != errno.EEXIST: - raise - - -def setup_for_distributed(is_master): - """ - This function disables printing when not in master process - """ - import builtins as __builtin__ - builtin_print = __builtin__.print - - def print(*args, **kwargs): - force = kwargs.pop('force', False) - if is_master or force: - builtin_print(*args, **kwargs) - - __builtin__.print = print - - -def is_dist_avail_and_initialized(): - if not dist.is_available(): - return False - if not dist.is_initialized(): - return False - return True - - -def get_world_size(): - if not is_dist_avail_and_initialized(): - return 1 - return dist.get_world_size() - - -def get_rank(): - if not is_dist_avail_and_initialized(): - return 0 - return dist.get_rank() - - -def is_main_process(): - return get_rank() == 0 - - -def save_on_master(*args, **kwargs): - torch.save(*args, **kwargs) - - -def init_distributed_mode(args): - if 'RANK' in os.environ and 'WORLD_SIZE' in os.environ: - args.rank = int(os.environ["RANK"]) - args.world_size = int(os.environ['WORLD_SIZE']) - args.gpu = int(os.environ['LOCAL_RANK']) - elif 'SLURM_PROCID' in os.environ: - args.rank = int(os.environ['SLURM_PROCID']) - args.gpu = args.rank % torch.cuda.device_count() - elif hasattr(args, "rank"): - pass - else: - print('Not using distributed mode') - args.distributed = False - return - - args.distributed = True - - torch.npu.set_device(args.gpu) - args.dist_backend = 'nccl' - print('| distributed init (rank {}): {}'.format( - args.rank, args.dist_url), flush=True) - torch.distributed.init_process_group(backend=args.dist_backend, init_method=args.dist_url, - world_size=args.world_size, rank=args.rank) - setup_for_distributed(args.rank == 0) +# +# BSD 3-Clause License +# +# Copyright (c) 2017 xxxx +# All rights reserved. +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ============================================================================ +#from __future__ import print_function +from collections import defaultdict, deque +import datetime +import time +import torch +import torch.distributed as dist + +import errno +import os + + +class SmoothedValue(object): + """Track a series of values and provide access to smoothed values over a + window or the global series average. + """ + + def __init__(self, window_size=20, fmt=None): + if fmt is None: + fmt = "{median:.4f} ({global_avg:.4f})" + self.deque = deque(maxlen=window_size) + self.total = 0.0 + self.count = 0.0 + self.fmt = fmt + + def update(self, value, n=1): + self.deque.append(value) + self.count += n + self.total += value * n + + def synchronize_between_processes(self,npu_device): + """ + Warning: does not synchronize the deque! + """ + if not is_dist_avail_and_initialized(): + return + t = torch.as_tensor([self.count, self.total], dtype=torch.float32, device=npu_device) + print(t,t.dtype) + dist.barrier() + dist.all_reduce(t) + t = t.tolist() + self.count = int(t[0]) + self.total = t[1] + + @property + def median(self): + d = torch.tensor(list(self.deque)) + return d.median().item() + + @property + def avg(self): + d = torch.tensor(list(self.deque), dtype=torch.float32) + return d.mean().item() + + @property + def global_avg(self): + return self.total / self.count + + @property + def max(self): + return max(self.deque) + + @property + def value(self): + return self.deque[-1] + + def __str__(self): + return self.fmt.format( + median=self.median, + avg=self.avg, + global_avg=self.global_avg, + max=self.max, + value=self.value) + + +class MetricLogger(object): + def __init__(self, delimiter="\t"): + self.meters = defaultdict(SmoothedValue) + self.delimiter = delimiter + + def update(self, **kwargs): + for k, v in kwargs.items(): + if isinstance(v, torch.Tensor): + v = v.item() + assert isinstance(v, (float, int)) + self.meters[k].update(v) + + def __getattr__(self, attr): + if attr in self.meters: + return self.meters[attr] + if attr in self.__dict__: + return self.__dict__[attr] + raise AttributeError("'{}' object has no attribute '{}'".format( + type(self).__name__, attr)) + + def __str__(self): + loss_str = [] + for name, meter in self.meters.items(): + loss_str.append( + "{}: {}".format(name, str(meter)) + ) + return self.delimiter.join(loss_str) + + def synchronize_between_processes(self,device): + for meter in self.meters.values(): + meter.synchronize_between_processes(device) + + def add_meter(self, name, meter): + self.meters[name] = meter + + def log_every(self, iterable, print_freq, header=None): + i = 0 + if not header: + header = '' + start_time = time.time() + end = time.time() + iter_time = SmoothedValue(fmt='{avg:.4f}') + data_time = SmoothedValue(fmt='{avg:.4f}') + space_fmt = ':' + str(len(str(len(iterable)))) + 'd' + if torch.npu.is_available(): + log_msg = self.delimiter.join([ + header, + '[{0' + space_fmt + '}/{1}]', + 'eta: {eta}', + '{meters}', + 'time: {time}', + 'data: {data}', + 'max mem: {memory:.0f}' + ]) + else: + log_msg = self.delimiter.join([ + header, + '[{0' + space_fmt + '}/{1}]', + 'eta: {eta}', + '{meters}', + 'time: {time}', + 'data: {data}' + ]) + MB = 1024.0 * 1024.0 + for obj in iterable: + data_time.update(time.time() - end) + yield obj + iter_time.update(time.time() - end) + if i % print_freq == 0: + eta_seconds = iter_time.global_avg * (len(iterable) - i) + eta_string = str(datetime.timedelta(seconds=int(eta_seconds))) + if torch.npu.is_available(): + print(log_msg.format( + i, len(iterable), eta=eta_string, + meters=str(self), + time=str(iter_time), data=str(data_time), + memory=0)) + #memory=torch.cuda.max_memory_allocated() / MB)) + else: + print(log_msg.format( + i, len(iterable), eta=eta_string, + meters=str(self), + time=str(iter_time), data=str(data_time))) + i += 1 + end = time.time() + total_time = time.time() - start_time + total_time_str = str(datetime.timedelta(seconds=int(total_time))) + print('{} Total time: {}'.format(header, total_time_str)) + + +def accuracy(output, target, topk=(1,)): + """Computes the accuracy over the k top predictions for the specified values of k""" + with torch.no_grad(): + maxk = max(topk) + batch_size = target.size(0) + + _, pred = output.topk(maxk, 1, True, True) + pred = pred.t() + correct = pred.eq(target[None]) + + res = [] + for k in topk: + correct_k = correct[:k].flatten().sum(dtype=torch.float32) + res.append(correct_k * (100.0 / batch_size)) + return res + + +def mkdir(path): + try: + os.makedirs(path) + except OSError as e: + if e.errno != errno.EEXIST: + raise + + +def setup_for_distributed(is_master): + """ + This function disables printing when not in master process + """ + import builtins as __builtin__ + builtin_print = __builtin__.print + + def print(*args, **kwargs): + force = kwargs.pop('force', False) + if is_master or force: + builtin_print(*args, **kwargs) + + __builtin__.print = print + + +def is_dist_avail_and_initialized(): + if not dist.is_available(): + return False + if not dist.is_initialized(): + return False + return True + + +def get_world_size(): + if not is_dist_avail_and_initialized(): + return 1 + return dist.get_world_size() + + +def get_rank(): + if not is_dist_avail_and_initialized(): + return 0 + return dist.get_rank() + + +def is_main_process(): + return get_rank() == 0 + + +def save_on_master(*args, **kwargs): + torch.save(*args, **kwargs) + + +def init_distributed_mode(args): + if 'RANK' in os.environ and 'WORLD_SIZE' in os.environ: + args.rank = int(os.environ["RANK"]) + args.world_size = int(os.environ['WORLD_SIZE']) + args.gpu = int(os.environ['LOCAL_RANK']) + elif 'SLURM_PROCID' in os.environ: + args.rank = int(os.environ['SLURM_PROCID']) + args.gpu = args.rank % torch.cuda.device_count() + elif hasattr(args, "rank"): + pass + else: + print('Not using distributed mode') + args.distributed = False + return + + args.distributed = True + + torch.npu.set_device(args.gpu) + args.dist_backend = 'nccl' + print('| distributed init (rank {}): {}'.format( + args.rank, args.dist_url), flush=True) + torch.distributed.init_process_group(backend=args.dist_backend, init_method=args.dist_url, + world_size=args.world_size, rank=args.rank) + setup_for_distributed(args.rank == 0) diff --git a/PyTorch/dev/cv/image_classification/MaskRCNN_ID0101_for_PyTorch/test/train_full_8p.sh b/PyTorch/dev/cv/image_classification/MaskRCNN_ID0101_for_PyTorch/test/train_full_8p.sh index db18df5704fd5ab20dbb6135f1e4fdf751c735ec..73da34f89ed0c03f627a270345768878e37c9882 100644 --- a/PyTorch/dev/cv/image_classification/MaskRCNN_ID0101_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/dev/cv/image_classification/MaskRCNN_ID0101_for_PyTorch/test/train_full_8p.sh @@ -1,230 +1,230 @@ -#!/bin/bash -export HCCL_WHITELIST_DISABLE=1 -export MASTER_ADDR=127.0.0.1 -export MASTER_PORT=23456 -#当前路径,不需要修改 -cur_path=`pwd` -#ASCEND_DEVICE_ID=1 -export ASCEND_SLOG_PRINT_TO_STDOUT=0 -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID - -#集合通信参数,不需要修改 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 - - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="MaskRCNN_ID0101_for_PyTorch" -#训练epoch -train_epochs=82000 -#训练batch_size -batch_size=8 -#训练step -train_steps= -#学习率 -learning_rate= - -#TF2.X独有,不需要修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_1p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --conda_name* ]];then - conda_name=`echo ${para#*=}` - source set_conda.sh --conda_name=$conda_name - source activate $conda_name - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path/../ - -sed -i "s|\"coco_2017_train\": (\"coco/train2017\", \"coco/annotations/instances_train2017.json\")|\"coco_2017_train\": (\"$data_path/coco/train2017\", \"$data_path/coco/annotations/instances_train2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py -sed -i "s|\"coco_2017_val\": (\"coco/val2017\", \"coco/annotations/instances_val2017.json\")|\"coco_2017_val\": (\"$data_path/coco/val2017\", \"$data_path/coco/annotations/instances_val2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py -sed -i "s|WEIGHTS: \"detectron2://ImageNetPretrained/MSRA/R-101.pkl\"|WEIGHTS: \"$data_path/R-101.pkl\"|g" $cur_path/../configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml - -python3 setup.py build develop > $cur_path/../log.txt - - -#训练开始时间,不需要修改 -start_time=$(date +%s) -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - export ASCEND_DEVICE_ID=$RANK_ID - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - - - - #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 - #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` - #cpustep=`expr $cpucount / 8` - #echo "taskset c steps:" $cpustep - #let a=RANK_ID*$cpustep - #let b=RANK_ID+1 - #let c=b*$cpustep-1 - - - - #SOLVER.MAX_ITER 82000 \ - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - - -done -wait - - - - - -NPUS=($(seq 0 7)) -export NPU_WORLD_SIZE=${#NPUS[@]} -rank=0 -for i in ${NPUS[@]} -do - export NPU_CALCULATE_DEVICE=${i} - mkdir -p $cur_path/output/${i}/ - export ASCEND_DEVICE_ID=${i} - export RANK=${rank} - echo run process ${rank} - python3 tools/train_net.py \ - --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml \ - --num-gpus 8 \ - AMP 1\ - OPT_LEVEL O2 \ - LOSS_SCALE_VALUE 64 \ - SOLVER.IMS_PER_BATCH $batch_size \ - SOLVER.MAX_ITER 82000 \ - SEED 1234 \ - MODEL.RPN.NMS_THRESH 0.8 \ - MODEL.ROI_BOX_HEAD.POOLER_SAMPLING_RATIO 2 \ - MODEL.ROI_MASK_HEAD.POOLER_SAMPLING_RATIO 2 \ - DATALOADER.NUM_WORKERS 4 \ - SOLVER.BASE_LR 0.0025 > $cur_path/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & - let rank++ -done -wait - - -#conda deactivate -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -export ASCEND_DEVICE_ID=0 - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -Time=`grep total_loss $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'time: ' '{print $2}'|awk '{print $1}'|tail -n +3|awk '{sum+=$1} END {print sum/NR}'|sed s/[[:space:]]//g` -FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${Time}'}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -a=`grep -A 2 'Task: bbox' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |awk '{print $5}'` -array=(${a// / }) -b=${array[2]} -array1=(${b//,/ }) -train_accuracy=${array1[0]} -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据 -#吞吐量,不需要修改 -ActualFPS=${FPS} -#单迭代训练时长,不需要修改 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep total_loss $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'total_loss: ' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash +export HCCL_WHITELIST_DISABLE=1 +export MASTER_ADDR=127.0.0.1 +export MASTER_PORT=23456 +#当前路径,不需要修改 +cur_path=`pwd` +#ASCEND_DEVICE_ID=1 +export ASCEND_SLOG_PRINT_TO_STDOUT=0 +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID + +#集合通信参数,不需要修改 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 + + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="MaskRCNN_ID0101_for_PyTorch" +#训练epoch +train_epochs=82000 +#训练batch_size +batch_size=8 +#训练step +train_steps= +#学习率 +learning_rate= + +#TF2.X独有,不需要修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_1p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --conda_name* ]];then + conda_name=`echo ${para#*=}` + source set_conda.sh --conda_name=$conda_name + source activate $conda_name + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path/../ + +sed -i "s|\"coco_2017_train\": (\"coco/train2017\", \"coco/annotations/instances_train2017.json\")|\"coco_2017_train\": (\"$data_path/coco/train2017\", \"$data_path/coco/annotations/instances_train2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py +sed -i "s|\"coco_2017_val\": (\"coco/val2017\", \"coco/annotations/instances_val2017.json\")|\"coco_2017_val\": (\"$data_path/coco/val2017\", \"$data_path/coco/annotations/instances_val2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py +sed -i "s|WEIGHTS: \"detectron2://ImageNetPretrained/MSRA/R-101.pkl\"|WEIGHTS: \"$data_path/R-101.pkl\"|g" $cur_path/../configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml + +python3 setup.py build develop > $cur_path/../log.txt + + +#训练开始时间,不需要修改 +start_time=$(date +%s) +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + export ASCEND_DEVICE_ID=$RANK_ID + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + + + + #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 + #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` + #cpustep=`expr $cpucount / 8` + #echo "taskset c steps:" $cpustep + #let a=RANK_ID*$cpustep + #let b=RANK_ID+1 + #let c=b*$cpustep-1 + + + + #SOLVER.MAX_ITER 82000 \ + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + + +done +wait + + + + + +NPUS=($(seq 0 7)) +export NPU_WORLD_SIZE=${#NPUS[@]} +rank=0 +for i in ${NPUS[@]} +do + export NPU_CALCULATE_DEVICE=${i} + mkdir -p $cur_path/output/${i}/ + export ASCEND_DEVICE_ID=${i} + export RANK=${rank} + echo run process ${rank} + python3 tools/train_net.py \ + --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml \ + --num-gpus 8 \ + AMP 1\ + OPT_LEVEL O2 \ + LOSS_SCALE_VALUE 64 \ + SOLVER.IMS_PER_BATCH $batch_size \ + SOLVER.MAX_ITER 82000 \ + SEED 1234 \ + MODEL.RPN.NMS_THRESH 0.8 \ + MODEL.ROI_BOX_HEAD.POOLER_SAMPLING_RATIO 2 \ + MODEL.ROI_MASK_HEAD.POOLER_SAMPLING_RATIO 2 \ + DATALOADER.NUM_WORKERS 4 \ + SOLVER.BASE_LR 0.0025 > $cur_path/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & + let rank++ +done +wait + + +#conda deactivate +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +export ASCEND_DEVICE_ID=0 + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +Time=`grep total_loss $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'time: ' '{print $2}'|awk '{print $1}'|tail -n +3|awk '{sum+=$1} END {print sum/NR}'|sed s/[[:space:]]//g` +FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${Time}'}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +a=`grep -A 2 'Task: bbox' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |awk '{print $5}'` +array=(${a// / }) +b=${array[2]} +array1=(${b//,/ }) +train_accuracy=${array1[0]} +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据 +#吞吐量,不需要修改 +ActualFPS=${FPS} +#单迭代训练时长,不需要修改 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep total_loss $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'total_loss: ' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/dev/cv/image_classification/MaskRCNN_ID0101_for_PyTorch/test/train_performance_8p.sh b/PyTorch/dev/cv/image_classification/MaskRCNN_ID0101_for_PyTorch/test/train_performance_8p.sh index e35123e027322d68234548c3ab891400966479d6..0373df8202b65c0a0b59729f19339af95965c171 100644 --- a/PyTorch/dev/cv/image_classification/MaskRCNN_ID0101_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/dev/cv/image_classification/MaskRCNN_ID0101_for_PyTorch/test/train_performance_8p.sh @@ -1,224 +1,224 @@ -#!/bin/bash -export HCCL_WHITELIST_DISABLE=1 -export MASTER_ADDR=127.0.0.1 -export MASTER_PORT=23456 -#当前路径,不需要修改 -cur_path=`pwd` -#ASCEND_DEVICE_ID=1 -export ASCEND_SLOG_PRINT_TO_STDOUT=0 -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID - -#集合通信参数,不需要修改 -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 - - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="MaskRCNN_ID0101_for_PyTorch" -#训练epoch -train_epochs=100 -#训练batch_size -batch_size=8 -#训练step -train_steps= -#学习率 -learning_rate= - -#TF2.X独有,不需要修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_1p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --conda_name* ]];then - conda_name=`echo ${para#*=}` - source set_conda.sh --conda_name=$conda_name - source activate $conda_name - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path/../ - -sed -i "s|\"coco_2017_train\": (\"coco/train2017\", \"coco/annotations/instances_train2017.json\")|\"coco_2017_train\": (\"$data_path/coco/train2017\", \"$data_path/coco/annotations/instances_train2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py -sed -i "s|\"coco_2017_val\": (\"coco/val2017\", \"coco/annotations/instances_val2017.json\")|\"coco_2017_val\": (\"$data_path/coco/val2017\", \"$data_path/coco/annotations/instances_val2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py -sed -i "s|WEIGHTS: \"detectron2://ImageNetPretrained/MSRA/R-101.pkl\"|WEIGHTS: \"$data_path/R-101.pkl\"|g" $cur_path/../configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml - -python3 setup.py build develop > $cur_path/../log.txt - - -#训练开始时间,不需要修改 -start_time=$(date +%s) -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - - #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 - #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` - #cpustep=`expr $cpucount / 8` - #echo "taskset c steps:" $cpustep - #let a=RANK_ID*$cpustep - #let b=RANK_ID+1 - #let c=b*$cpustep-1 - - - - #SOLVER.MAX_ITER 82000 \ - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 -done -wait - - - - - -NPUS=($(seq 0 7)) -export NPU_WORLD_SIZE=${#NPUS[@]} -rank=0 -for i in ${NPUS[@]} -do - export NPU_CALCULATE_DEVICE=${i} - mkdir -p $cur_path/output/${i}/ - export ASCEND_DEVICE_ID=${i} - export RANK=${rank} - echo run process ${rank} - python3 tools/train_net.py \ - --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml \ - --num-gpus 8 \ - AMP 1\ - OPT_LEVEL O2 \ - LOSS_SCALE_VALUE 64 \ - SOLVER.IMS_PER_BATCH $batch_size \ - SOLVER.MAX_ITER 100 \ - SEED 1234 \ - MODEL.RPN.NMS_THRESH 0.8 \ - MODEL.ROI_BOX_HEAD.POOLER_SAMPLING_RATIO 2 \ - MODEL.ROI_MASK_HEAD.POOLER_SAMPLING_RATIO 2 \ - DATALOADER.NUM_WORKERS 4 \ - SOLVER.BASE_LR 0.0025 > $cur_path/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & - let rank++ -done - - - -wait - - -#conda deactivate -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - - - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -Time=`grep total_loss $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'time: ' '{print $2}'|awk '{print $1}'|tail -n +3|awk '{sum+=$1} END {print sum/NR}'|sed s/[[:space:]]//g` -FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${Time}'}'` - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=None -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据 -#吞吐量,不需要修改 -ActualFPS=${FPS} -#单迭代训练时长,不需要修改 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep total_loss $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'total_loss: ' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash +export HCCL_WHITELIST_DISABLE=1 +export MASTER_ADDR=127.0.0.1 +export MASTER_PORT=23456 +#当前路径,不需要修改 +cur_path=`pwd` +#ASCEND_DEVICE_ID=1 +export ASCEND_SLOG_PRINT_TO_STDOUT=0 +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID + +#集合通信参数,不需要修改 +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 + + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="MaskRCNN_ID0101_for_PyTorch" +#训练epoch +train_epochs=100 +#训练batch_size +batch_size=8 +#训练step +train_steps= +#学习率 +learning_rate= + +#TF2.X独有,不需要修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_1p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --conda_name* ]];then + conda_name=`echo ${para#*=}` + source set_conda.sh --conda_name=$conda_name + source activate $conda_name + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path/../ + +sed -i "s|\"coco_2017_train\": (\"coco/train2017\", \"coco/annotations/instances_train2017.json\")|\"coco_2017_train\": (\"$data_path/coco/train2017\", \"$data_path/coco/annotations/instances_train2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py +sed -i "s|\"coco_2017_val\": (\"coco/val2017\", \"coco/annotations/instances_val2017.json\")|\"coco_2017_val\": (\"$data_path/coco/val2017\", \"$data_path/coco/annotations/instances_val2017.json\")|g" $cur_path/../detectron2/data/datasets/builtin.py +sed -i "s|WEIGHTS: \"detectron2://ImageNetPretrained/MSRA/R-101.pkl\"|WEIGHTS: \"$data_path/R-101.pkl\"|g" $cur_path/../configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml + +python3 setup.py build develop > $cur_path/../log.txt + + +#训练开始时间,不需要修改 +start_time=$(date +%s) +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + + #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 + #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` + #cpustep=`expr $cpucount / 8` + #echo "taskset c steps:" $cpustep + #let a=RANK_ID*$cpustep + #let b=RANK_ID+1 + #let c=b*$cpustep-1 + + + + #SOLVER.MAX_ITER 82000 \ + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 +done +wait + + + + + +NPUS=($(seq 0 7)) +export NPU_WORLD_SIZE=${#NPUS[@]} +rank=0 +for i in ${NPUS[@]} +do + export NPU_CALCULATE_DEVICE=${i} + mkdir -p $cur_path/output/${i}/ + export ASCEND_DEVICE_ID=${i} + export RANK=${rank} + echo run process ${rank} + python3 tools/train_net.py \ + --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml \ + --num-gpus 8 \ + AMP 1\ + OPT_LEVEL O2 \ + LOSS_SCALE_VALUE 64 \ + SOLVER.IMS_PER_BATCH $batch_size \ + SOLVER.MAX_ITER 100 \ + SEED 1234 \ + MODEL.RPN.NMS_THRESH 0.8 \ + MODEL.ROI_BOX_HEAD.POOLER_SAMPLING_RATIO 2 \ + MODEL.ROI_MASK_HEAD.POOLER_SAMPLING_RATIO 2 \ + DATALOADER.NUM_WORKERS 4 \ + SOLVER.BASE_LR 0.0025 > $cur_path/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & + let rank++ +done + + + +wait + + +#conda deactivate +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + + + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +Time=`grep total_loss $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'time: ' '{print $2}'|awk '{print $1}'|tail -n +3|awk '{sum+=$1} END {print sum/NR}'|sed s/[[:space:]]//g` +FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${Time}'}'` + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=None +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据 +#吞吐量,不需要修改 +ActualFPS=${FPS} +#单迭代训练时长,不需要修改 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep total_loss $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F 'total_loss: ' '{print $2}'|awk '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/dev/cv/image_classification/NeuMF_ID0351_for_PyTorch/LICENSE b/PyTorch/dev/cv/image_classification/NeuMF_ID0351_for_PyTorch/LICENSE index db05a35866f7f1e2bc78bdfe9e7048e779552d8c..09d493bf1fc257505c1336f3f87425568ab9da3c 100644 --- a/PyTorch/dev/cv/image_classification/NeuMF_ID0351_for_PyTorch/LICENSE +++ b/PyTorch/dev/cv/image_classification/NeuMF_ID0351_for_PyTorch/LICENSE @@ -1,29 +1,29 @@ -BSD 3-Clause License - -Copyright (c) 2017, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +BSD 3-Clause License + +Copyright (c) 2017, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/PyTorch/dev/cv/image_classification/NeuMF_ID0351_for_PyTorch/src/prefetcher.py b/PyTorch/dev/cv/image_classification/NeuMF_ID0351_for_PyTorch/src/prefetcher.py index 5e05ead50092cc817ea11c9a17e4a724d0e0deb8..c0c8310c60e099859f4e6cce206ad940d2c14ef7 100644 --- a/PyTorch/dev/cv/image_classification/NeuMF_ID0351_for_PyTorch/src/prefetcher.py +++ b/PyTorch/dev/cv/image_classification/NeuMF_ID0351_for_PyTorch/src/prefetcher.py @@ -1,67 +1,67 @@ -# Copyright (c) 2020 Huawei Technologies Co., Ltd -# Copyright (c) 2019, Facebook CORPORATION. -# All rights reserved. -# -# Licensed under the BSD 3-Clause License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/BSD-3-Clause -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch - - -class Prefetcher(object): - """Prefetcher using on npu device. - - Origin Code URL: - https://github.com/implus/PytorchInsight/blob/master/classification/imagenet_fast.py#L280 - - Args: - loder (torch.utils.data.DataLoader or DataLoader like iterator): - Using to generate inputs after preprocessing. - stream (torch.npu.Stream): Default None. - Because of the limitation of NPU's memory mechanism, - if prefetcher is initialized repeatedly during training, - a defined stream should be introduced to prevent memory leakage; - if prefetcher is initialized only once during training, - a defined stream is not necessary. - - Returns: - float: tensors of shape (k, 5) and (k, 1). Labels are 0-based. - """ - - def __init__(self, loader, stream=None): - self.loader = iter(loader) - self.stream = stream if stream is not None else torch.npu.Stream() - self.preload() - - def preload(self): - try: - self.user, self.item, self.rating = next(self.loader) - assert isinstance(self.user, torch.IntTensor) - self.rating = self.rating.float() - except StopIteration: - self.user = None - self.item = None - return - - with torch.npu.stream(self.stream): - self.user = self.user.npu(non_blocking=True) - self.item = self.item.npu(non_blocking=True) - self.rating = self.rating.npu(non_blocking=True) - - def next(self): - torch.npu.current_stream().wait_stream(self.stream) - user = self.user - item = self.item - rating = self.rating - if user is not None: - self.preload() - return user, item, rating +# Copyright (c) 2020 Huawei Technologies Co., Ltd +# Copyright (c) 2019, Facebook CORPORATION. +# All rights reserved. +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch + + +class Prefetcher(object): + """Prefetcher using on npu device. + + Origin Code URL: + https://github.com/implus/PytorchInsight/blob/master/classification/imagenet_fast.py#L280 + + Args: + loder (torch.utils.data.DataLoader or DataLoader like iterator): + Using to generate inputs after preprocessing. + stream (torch.npu.Stream): Default None. + Because of the limitation of NPU's memory mechanism, + if prefetcher is initialized repeatedly during training, + a defined stream should be introduced to prevent memory leakage; + if prefetcher is initialized only once during training, + a defined stream is not necessary. + + Returns: + float: tensors of shape (k, 5) and (k, 1). Labels are 0-based. + """ + + def __init__(self, loader, stream=None): + self.loader = iter(loader) + self.stream = stream if stream is not None else torch.npu.Stream() + self.preload() + + def preload(self): + try: + self.user, self.item, self.rating = next(self.loader) + assert isinstance(self.user, torch.IntTensor) + self.rating = self.rating.float() + except StopIteration: + self.user = None + self.item = None + return + + with torch.npu.stream(self.stream): + self.user = self.user.npu(non_blocking=True) + self.item = self.item.npu(non_blocking=True) + self.rating = self.rating.npu(non_blocking=True) + + def next(self): + torch.npu.current_stream().wait_stream(self.stream) + user = self.user + item = self.item + rating = self.rating + if user is not None: + self.preload() + return user, item, rating diff --git a/PyTorch/dev/cv/image_classification/RUC_ID2470_for_PyTorch/figure/additonal_result.PNG b/PyTorch/dev/cv/image_classification/RUC_ID2470_for_PyTorch/figure/additonal_result.PNG deleted file mode 100644 index f352f7933c8fa3583fe21006a0e3f747e5a3e66b..0000000000000000000000000000000000000000 Binary files a/PyTorch/dev/cv/image_classification/RUC_ID2470_for_PyTorch/figure/additonal_result.PNG and /dev/null differ diff --git a/PyTorch/dev/cv/image_classification/RUC_ID2470_for_PyTorch/figure/model_arch.PNG b/PyTorch/dev/cv/image_classification/RUC_ID2470_for_PyTorch/figure/model_arch.PNG deleted file mode 100644 index 126039f2766b81d68a69277d02c4b37308d045bc..0000000000000000000000000000000000000000 Binary files a/PyTorch/dev/cv/image_classification/RUC_ID2470_for_PyTorch/figure/model_arch.PNG and /dev/null differ diff --git a/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/main_8p.py b/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/main_8p.py index c62e6ae659bac007b63025cf87c6e8a52e2cd16f..1790b4a24da775ef65de4848599f3d7ef24f7cc2 100644 --- a/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/main_8p.py +++ b/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/main_8p.py @@ -1,478 +1,478 @@ -import argparse -import os -import random -import shutil -import time -import warnings -from enum import Enum - -import torch -import torch.nn as nn -import torch.nn.parallel -import torch.backends.cudnn as cudnn -import torch.distributed as dist -import torch.optim -import torch.multiprocessing as mp -import torch.utils.data -import torch.utils.data.distributed -import torchvision.transforms as transforms -import torchvision.datasets as datasets -import torchvision.models as models -import torch.npu -import os -from apex import amp - - -NPU_CALCULATE_DEVICE = 0 -if os.getenv('NPU_CALCULATE_DEVICE') and str.isdigit(os.getenv('NPU_CALCULATE_DEVICE')): - NPU_CALCULATE_DEVICE = int(os.getenv('NPU_CALCULATE_DEVICE')) -if torch.npu.current_device() != NPU_CALCULATE_DEVICE: - torch.npu.set_device(f'npu:{NPU_CALCULATE_DEVICE}') -NPU_WORLD_SIZE = int(os.getenv('NPU_WORLD_SIZE')) -RANK = int(os.getenv('RANK')) -torch.distributed.init_process_group('hccl', rank=RANK, world_size=NPU_WORLD_SIZE) - -model_names = sorted(name for name in models.__dict__ - if name.islower() and not name.startswith("__") - and callable(models.__dict__[name])) - -parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') -parser.add_argument('data', metavar='DIR', - help='path to dataset') -parser.add_argument('-a', '--arch', metavar='ARCH', default='resnet18', - choices=model_names, - help='model architecture: ' + - ' | '.join(model_names) + - ' (default: resnet18)') -parser.add_argument('-j', '--workers', default=4, type=int, metavar='N', - help='number of data loading workers (default: 4)') -parser.add_argument('--epochs', default=90, type=int, metavar='N', - help='number of total epochs to run') -parser.add_argument('--start-epoch', default=0, type=int, metavar='N', - help='manual epoch number (useful on restarts)') -parser.add_argument('-b', '--batch-size', default=256, type=int, - metavar='N', - help='mini-batch size (default: 256), this is the total ' - 'batch size of all GPUs on the current node when ' - 'using Data Parallel or Distributed Data Parallel') -parser.add_argument('--lr', '--learning-rate', default=0.1, type=float, - metavar='LR', help='initial learning rate', dest='lr') -parser.add_argument('--momentum', default=0.9, type=float, metavar='M', - help='momentum') -parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, - metavar='W', help='weight decay (default: 1e-4)', - dest='weight_decay') -parser.add_argument('-p', '--print-freq', default=10, type=int, - metavar='N', help='print frequency (default: 10)') -parser.add_argument('--resume', default='', type=str, metavar='PATH', - help='path to latest checkpoint (default: none)') -parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', - help='evaluate model on validation set') -parser.add_argument('--pretrained', dest='pretrained', action='store_true', - help='use pre-trained model') -parser.add_argument('--world-size', default=-1, type=int, - help='number of nodes for distributed training') -parser.add_argument('--rank', default=-1, type=int, - help='node rank for distributed training') -parser.add_argument('--dist-url', default='', type=str, - help='url used to set up distributed training') -parser.add_argument('--dist-backend', default='hccl', type=str, - help='distributed backend') -parser.add_argument('--seed', default=None, type=int, - help='seed for initializing training. ') -parser.add_argument('--gpu', default=None, type=int, - help='GPU id to use.') -parser.add_argument('--multiprocessing-distributed', action='store_true', - help='Use multi-processing distributed training to launch ' - 'N processes per node, which has N GPUs. This is the ' - 'fastest way to use PyTorch for either single node or ' - 'multi node data parallel training') -## for ascend 910 - -parser.add_argument('--amp', default=False, action='store_true', - help='use amp to train the model') -parser.add_argument('--loss-scale', default=1024., type=float, - help='loss scale using in amp, default -1 means dynamic') -parser.add_argument('--opt-level', default='O2', type=str, - help='loss scale using in amp, default -1 means dynamic') -parser.add_argument('--FusedSGD', default=False, action='store_true', - help='use FusedSGD') -parser.add_argument('--stop-step-num', default=None, type=int, - help='after the stop-step, killing the training task') - -best_acc1 = 0 - - -def main(): - global best_acc1 - args = parser.parse_args() - - if args.seed is not None: - random.seed(args.seed) - torch.manual_seed(args.seed) - cudnn.deterministic = True - warnings.warn('You have chosen to seed training. ' - 'This will turn on the CUDNN deterministic setting, ' - 'which can slow down your training considerably! ' - 'You may see unexpected behavior when restarting ' - 'from checkpoints.') - - if args.gpu is not None: - warnings.warn('You have chosen a specific GPU. This will completely ' - 'disable data parallelism.') - - - - - - - - - # create model - if args.pretrained: - print("=> using pre-trained model '{}'".format(args.arch)) - model = models.__dict__[args.arch](pretrained=True) - model = model.to(f'npu:{NPU_CALCULATE_DEVICE}') - #if not isinstance(model, torch.nn.parallel.DistributedDataParallel): - #model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[NPU_CALCULATE_DEVICE], broadcast_buffers=False) - else: - print("=> creating model '{}'".format(args.arch)) - model = models.__dict__[args.arch]() - model = model.to(f'npu:{NPU_CALCULATE_DEVICE}') - #if not isinstance(model, torch.nn.parallel.DistributedDataParallel): - #model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[NPU_CALCULATE_DEVICE], broadcast_buffers=False) - - if not torch.npu.is_available(): - print('using CPU, this will be slow') - - - elif args.gpu is not None: - torch.npu.set_device(f'npu:{NPU_CALCULATE_DEVICE}') - model = model.npu(f'npu:{NPU_CALCULATE_DEVICE}') - model = model.to(f'npu:{NPU_CALCULATE_DEVICE}') - #if not isinstance(model, torch.nn.parallel.DistributedDataParallel): - #model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[NPU_CALCULATE_DEVICE], broadcast_buffers=False) - else: - # DataParallel will divide and allocate batch_size to all available GPUs - if args.arch.startswith('alexnet') or args.arch.startswith('vgg'): - model.features = torch.nn.DataParallel(model.features) - model.npu() - - - # define loss function (criterion) and optimizer - if args.FusedSGD: - from apex.optimizers import NpuFusedSGD - optimizer = NpuFusedSGD(model.parameters(), args.lr, - momentum=args.momentum, - weight_decay=args.weight_decay) - - else: - optimizer = torch.optim.SGD(model.parameters(), args.lr, - momentum=args.momentum, - weight_decay=args.weight_decay) - - if args.amp: - model, optimizer = amp.initialize( - model, optimizer, opt_level=args.opt_level, loss_scale=args.loss_scale,combine_grad=True) - if not isinstance(model, torch.nn.parallel.DistributedDataParallel): - model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[NPU_CALCULATE_DEVICE], broadcast_buffers=False) - # optionally resume from a checkpoint - loc = 'npu:{}'.format(NPU_CALCULATE_DEVICE) - criterion = nn.CrossEntropyLoss().to(loc) - if args.resume: - if os.path.isfile(args.resume): - print("=> loading checkpoint '{}'".format(args.resume)) - if args.gpu is None: - checkpoint = torch.load(args.resume) - else: - # Map model to be loaded to specified single gpu. - loc = 'npu:{}'.format(args.gpu) - checkpoint = torch.load(args.resume, map_location=f'npu:{NPU_CALCULATE_DEVICE}') - args.start_epoch = checkpoint['epoch'] - best_acc1 = checkpoint['best_acc1'] - if args.gpu is not None: - # best_acc1 may be from a checkpoint from a different GPU - best_acc1 = best_acc1.to(f'npu:{NPU_CALCULATE_DEVICE}') - model.load_state_dict(checkpoint['state_dict']) - optimizer.load_state_dict(checkpoint['optimizer']) - if args.amp: - amp.load_state_dict(checkpoint['amp']) - print("=> loaded checkpoint '{}' (epoch {})" - .format(args.resume, checkpoint['epoch'])) - else: - print("=> no checkpoint found at '{}'".format(args.resume)) - - cudnn.benchmark = True - - # Data loading code - traindir = os.path.join(args.data, 'train') - valdir = os.path.join(args.data, 'val') - normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], - std=[0.229, 0.224, 0.225]) - - train_dataset = datasets.ImageFolder( - traindir, - transforms.Compose([ - transforms.RandomResizedCrop(224), - transforms.RandomHorizontalFlip(), - transforms.ToTensor(), - normalize, - ])) - - - #train_sampler = None - train_loader_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) - train_loader_batch_size = args.batch_size - - train_loader = torch.utils.data.DataLoader( - train_dataset, batch_size=train_loader_batch_size, shuffle=False, - num_workers=args.workers, pin_memory=True, sampler=train_loader_sampler, drop_last = True) - - val_loader = torch.utils.data.DataLoader( - datasets.ImageFolder(valdir, transforms.Compose([ - transforms.Resize(256), - transforms.CenterCrop(224), - transforms.ToTensor(), - normalize, - ])), - batch_size=args.batch_size, shuffle=True, - num_workers=args.workers, pin_memory=False, drop_last=True) - - if args.evaluate: - validate(val_loader, model, criterion, args) - return - - for epoch in range(args.start_epoch, args.epochs): - train_loader.sampler.set_epoch(epoch) - - - adjust_learning_rate(optimizer, epoch, args) - - # train for one epoch - train(train_loader, model, criterion, optimizer, epoch, args) - - # evaluate on validation set - acc1 = validate(val_loader, model, criterion, args) - - # remember best acc@1 and save checkpoint - is_best = acc1 > best_acc1 - best_acc1 = max(acc1, best_acc1) - - if not args.multiprocessing_distributed or (args.multiprocessing_distributed - and args.rank % ngpus_per_node == 0): - if args.amp: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': args.arch, - 'state_dict': model.state_dict(), - 'best_acc1': best_acc1, - 'optimizer': optimizer.state_dict(), - 'amp': amp.state_dict(), - }, is_best) - else: - save_checkpoint({ - 'epoch': epoch + 1, - 'arch': args.arch, - 'state_dict': model.state_dict(), - 'best_acc1': best_acc1, - 'optimizer': optimizer.state_dict(), - }, is_best) - - -def train(train_loader, model, criterion, optimizer, epoch, args): - batch_time = AverageMeter('Time', ':6.3f') - data_time = AverageMeter('Data', ':6.3f') - losses = AverageMeter('Loss', ':.4e') - top1 = AverageMeter('Acc@1', ':6.2f') - top5 = AverageMeter('Acc@5', ':6.2f') - progress = ProgressMeter( - len(train_loader), - [batch_time, data_time, losses, top1, top5], - prefix="Epoch: [{}]".format(epoch)) - - # switch to train mode - model.train() - - end = time.time() - for i, (images, target) in enumerate(train_loader): - # measure data loading time - data_time.update(time.time() - end) - - if args.gpu is not None: - images = images.npu(f'npu:{NPU_CALCULATE_DEVICE}', non_blocking=True) - if torch.npu.is_available(): - target = target.npu(f'npu:{NPU_CALCULATE_DEVICE}', non_blocking=True) - - # compute output - output = model(images) - loss = criterion(output, target) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # compute gradient and do SGD step - optimizer.zero_grad() - if args.amp: - with amp.scale_loss(loss, optimizer) as scaled_loss: - scaled_loss.backward() - else: - loss.backward() - optimizer.step() - - # measure elapsed time - batch_time.update(time.time() - end) - end = time.time() - - if i % args.print_freq == 0: - progress.display(i) - - -def validate(val_loader, model, criterion, args): - batch_time = AverageMeter('Time', ':6.3f', Summary.NONE) - losses = AverageMeter('Loss', ':.4e', Summary.NONE) - top1 = AverageMeter('Acc@1', ':6.2f', Summary.AVERAGE) - top5 = AverageMeter('Acc@5', ':6.2f', Summary.AVERAGE) - progress = ProgressMeter( - len(val_loader), - [batch_time, losses, top1, top5], - prefix='Test: ') - - # switch to evaluate mode - model.eval() - - with torch.no_grad(): - end = time.time() - for i, (images, target) in enumerate(val_loader): - if args.gpu is not None: - images = images.npu(f'npu:{NPU_CALCULATE_DEVICE}', non_blocking=True) - if torch.npu.is_available(): - target = target.npu(f'npu:{NPU_CALCULATE_DEVICE}', non_blocking=True) - - # compute output - output = model(images) - loss = criterion(output, target) - - # measure accuracy and record loss - acc1, acc5 = accuracy(output, target, topk=(1, 5)) - losses.update(loss.item(), images.size(0)) - top1.update(acc1[0], images.size(0)) - top5.update(acc5[0], images.size(0)) - - # measure elapsed time - batch_time.update(time.time() - end) - end = time.time() - - if i % args.print_freq == 0: - progress.display(i) - - progress.display_summary() - - return top1.avg - - -def save_checkpoint(state, is_best, filename='checkpoint.pth.tar'): - torch.save(state, filename) - if is_best: - shutil.copyfile(filename, 'model_best.pth.tar') - - -class Summary(Enum): - NONE = 0 - AVERAGE = 1 - SUM = 2 - COUNT = 3 - - -class AverageMeter(object): - """Computes and stores the average and current value""" - - def __init__(self, name, fmt=':f', summary_type=Summary.AVERAGE): - self.name = name - self.fmt = fmt - self.summary_type = summary_type - self.reset() - - def reset(self): - self.val = 0 - self.avg = 0 - self.sum = 0 - self.count = 0 - - def update(self, val, n=1): - self.val = val - self.sum += val * n - self.count += n - self.avg = self.sum / self.count - - def __str__(self): - fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' - return fmtstr.format(**self.__dict__) - - def summary(self): - fmtstr = '' - if self.summary_type is Summary.NONE: - fmtstr = '' - elif self.summary_type is Summary.AVERAGE: - fmtstr = '{name} {avg:.3f}' - elif self.summary_type is Summary.SUM: - fmtstr = '{name} {sum:.3f}' - elif self.summary_type is Summary.COUNT: - fmtstr = '{name} {count:.3f}' - else: - raise ValueError('invalid summary type %r' % self.summary_type) - - return fmtstr.format(**self.__dict__) - - -class ProgressMeter(object): - def __init__(self, num_batches, meters, prefix=""): - self.batch_fmtstr = self._get_batch_fmtstr(num_batches) - self.meters = meters - self.prefix = prefix - - def display(self, batch): - entries = [self.prefix + self.batch_fmtstr.format(batch)] - entries += [str(meter) for meter in self.meters] - print('\t'.join(entries)) - - def display_summary(self): - entries = [" *"] - entries += [meter.summary() for meter in self.meters] - print(' '.join(entries)) - - def _get_batch_fmtstr(self, num_batches): - num_digits = len(str(num_batches // 1)) - fmt = '{:' + str(num_digits) + 'd}' - return '[' + fmt + '/' + fmt.format(num_batches) + ']' - - -def adjust_learning_rate(optimizer, epoch, args): - """Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" - lr = args.lr * (0.1 ** (epoch // 30)) - for param_group in optimizer.param_groups: - param_group['lr'] = lr - - -def accuracy(output, target, topk=(1,)): - """Computes the accuracy over the k top predictions for the specified values of k""" - with torch.no_grad(): - maxk = max(topk) - batch_size = target.size(0) - - _, pred = output.topk(maxk, 1, True, True) - pred = pred.t() - correct = pred.eq(target.view(1, -1).expand_as(pred)) - - res = [] - for k in topk: - correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True) - res.append(correct_k.mul_(100.0 / batch_size)) - return res - - -if __name__ == '__main__': - main() - +import argparse +import os +import random +import shutil +import time +import warnings +from enum import Enum + +import torch +import torch.nn as nn +import torch.nn.parallel +import torch.backends.cudnn as cudnn +import torch.distributed as dist +import torch.optim +import torch.multiprocessing as mp +import torch.utils.data +import torch.utils.data.distributed +import torchvision.transforms as transforms +import torchvision.datasets as datasets +import torchvision.models as models +import torch.npu +import os +from apex import amp + + +NPU_CALCULATE_DEVICE = 0 +if os.getenv('NPU_CALCULATE_DEVICE') and str.isdigit(os.getenv('NPU_CALCULATE_DEVICE')): + NPU_CALCULATE_DEVICE = int(os.getenv('NPU_CALCULATE_DEVICE')) +if torch.npu.current_device() != NPU_CALCULATE_DEVICE: + torch.npu.set_device(f'npu:{NPU_CALCULATE_DEVICE}') +NPU_WORLD_SIZE = int(os.getenv('NPU_WORLD_SIZE')) +RANK = int(os.getenv('RANK')) +torch.distributed.init_process_group('hccl', rank=RANK, world_size=NPU_WORLD_SIZE) + +model_names = sorted(name for name in models.__dict__ + if name.islower() and not name.startswith("__") + and callable(models.__dict__[name])) + +parser = argparse.ArgumentParser(description='PyTorch ImageNet Training') +parser.add_argument('data', metavar='DIR', + help='path to dataset') +parser.add_argument('-a', '--arch', metavar='ARCH', default='resnet18', + choices=model_names, + help='model architecture: ' + + ' | '.join(model_names) + + ' (default: resnet18)') +parser.add_argument('-j', '--workers', default=4, type=int, metavar='N', + help='number of data loading workers (default: 4)') +parser.add_argument('--epochs', default=90, type=int, metavar='N', + help='number of total epochs to run') +parser.add_argument('--start-epoch', default=0, type=int, metavar='N', + help='manual epoch number (useful on restarts)') +parser.add_argument('-b', '--batch-size', default=256, type=int, + metavar='N', + help='mini-batch size (default: 256), this is the total ' + 'batch size of all GPUs on the current node when ' + 'using Data Parallel or Distributed Data Parallel') +parser.add_argument('--lr', '--learning-rate', default=0.1, type=float, + metavar='LR', help='initial learning rate', dest='lr') +parser.add_argument('--momentum', default=0.9, type=float, metavar='M', + help='momentum') +parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float, + metavar='W', help='weight decay (default: 1e-4)', + dest='weight_decay') +parser.add_argument('-p', '--print-freq', default=10, type=int, + metavar='N', help='print frequency (default: 10)') +parser.add_argument('--resume', default='', type=str, metavar='PATH', + help='path to latest checkpoint (default: none)') +parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', + help='evaluate model on validation set') +parser.add_argument('--pretrained', dest='pretrained', action='store_true', + help='use pre-trained model') +parser.add_argument('--world-size', default=-1, type=int, + help='number of nodes for distributed training') +parser.add_argument('--rank', default=-1, type=int, + help='node rank for distributed training') +parser.add_argument('--dist-url', default='', type=str, + help='url used to set up distributed training') +parser.add_argument('--dist-backend', default='hccl', type=str, + help='distributed backend') +parser.add_argument('--seed', default=None, type=int, + help='seed for initializing training. ') +parser.add_argument('--gpu', default=None, type=int, + help='GPU id to use.') +parser.add_argument('--multiprocessing-distributed', action='store_true', + help='Use multi-processing distributed training to launch ' + 'N processes per node, which has N GPUs. This is the ' + 'fastest way to use PyTorch for either single node or ' + 'multi node data parallel training') +## for ascend 910 + +parser.add_argument('--amp', default=False, action='store_true', + help='use amp to train the model') +parser.add_argument('--loss-scale', default=1024., type=float, + help='loss scale using in amp, default -1 means dynamic') +parser.add_argument('--opt-level', default='O2', type=str, + help='loss scale using in amp, default -1 means dynamic') +parser.add_argument('--FusedSGD', default=False, action='store_true', + help='use FusedSGD') +parser.add_argument('--stop-step-num', default=None, type=int, + help='after the stop-step, killing the training task') + +best_acc1 = 0 + + +def main(): + global best_acc1 + args = parser.parse_args() + + if args.seed is not None: + random.seed(args.seed) + torch.manual_seed(args.seed) + cudnn.deterministic = True + warnings.warn('You have chosen to seed training. ' + 'This will turn on the CUDNN deterministic setting, ' + 'which can slow down your training considerably! ' + 'You may see unexpected behavior when restarting ' + 'from checkpoints.') + + if args.gpu is not None: + warnings.warn('You have chosen a specific GPU. This will completely ' + 'disable data parallelism.') + + + + + + + + + # create model + if args.pretrained: + print("=> using pre-trained model '{}'".format(args.arch)) + model = models.__dict__[args.arch](pretrained=True) + model = model.to(f'npu:{NPU_CALCULATE_DEVICE}') + #if not isinstance(model, torch.nn.parallel.DistributedDataParallel): + #model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[NPU_CALCULATE_DEVICE], broadcast_buffers=False) + else: + print("=> creating model '{}'".format(args.arch)) + model = models.__dict__[args.arch]() + model = model.to(f'npu:{NPU_CALCULATE_DEVICE}') + #if not isinstance(model, torch.nn.parallel.DistributedDataParallel): + #model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[NPU_CALCULATE_DEVICE], broadcast_buffers=False) + + if not torch.npu.is_available(): + print('using CPU, this will be slow') + + + elif args.gpu is not None: + torch.npu.set_device(f'npu:{NPU_CALCULATE_DEVICE}') + model = model.npu(f'npu:{NPU_CALCULATE_DEVICE}') + model = model.to(f'npu:{NPU_CALCULATE_DEVICE}') + #if not isinstance(model, torch.nn.parallel.DistributedDataParallel): + #model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[NPU_CALCULATE_DEVICE], broadcast_buffers=False) + else: + # DataParallel will divide and allocate batch_size to all available GPUs + if args.arch.startswith('alexnet') or args.arch.startswith('vgg'): + model.features = torch.nn.DataParallel(model.features) + model.npu() + + + # define loss function (criterion) and optimizer + if args.FusedSGD: + from apex.optimizers import NpuFusedSGD + optimizer = NpuFusedSGD(model.parameters(), args.lr, + momentum=args.momentum, + weight_decay=args.weight_decay) + + else: + optimizer = torch.optim.SGD(model.parameters(), args.lr, + momentum=args.momentum, + weight_decay=args.weight_decay) + + if args.amp: + model, optimizer = amp.initialize( + model, optimizer, opt_level=args.opt_level, loss_scale=args.loss_scale,combine_grad=True) + if not isinstance(model, torch.nn.parallel.DistributedDataParallel): + model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[NPU_CALCULATE_DEVICE], broadcast_buffers=False) + # optionally resume from a checkpoint + loc = 'npu:{}'.format(NPU_CALCULATE_DEVICE) + criterion = nn.CrossEntropyLoss().to(loc) + if args.resume: + if os.path.isfile(args.resume): + print("=> loading checkpoint '{}'".format(args.resume)) + if args.gpu is None: + checkpoint = torch.load(args.resume) + else: + # Map model to be loaded to specified single gpu. + loc = 'npu:{}'.format(args.gpu) + checkpoint = torch.load(args.resume, map_location=f'npu:{NPU_CALCULATE_DEVICE}') + args.start_epoch = checkpoint['epoch'] + best_acc1 = checkpoint['best_acc1'] + if args.gpu is not None: + # best_acc1 may be from a checkpoint from a different GPU + best_acc1 = best_acc1.to(f'npu:{NPU_CALCULATE_DEVICE}') + model.load_state_dict(checkpoint['state_dict']) + optimizer.load_state_dict(checkpoint['optimizer']) + if args.amp: + amp.load_state_dict(checkpoint['amp']) + print("=> loaded checkpoint '{}' (epoch {})" + .format(args.resume, checkpoint['epoch'])) + else: + print("=> no checkpoint found at '{}'".format(args.resume)) + + cudnn.benchmark = True + + # Data loading code + traindir = os.path.join(args.data, 'train') + valdir = os.path.join(args.data, 'val') + normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225]) + + train_dataset = datasets.ImageFolder( + traindir, + transforms.Compose([ + transforms.RandomResizedCrop(224), + transforms.RandomHorizontalFlip(), + transforms.ToTensor(), + normalize, + ])) + + + #train_sampler = None + train_loader_sampler = torch.utils.data.distributed.DistributedSampler(train_dataset) + train_loader_batch_size = args.batch_size + + train_loader = torch.utils.data.DataLoader( + train_dataset, batch_size=train_loader_batch_size, shuffle=False, + num_workers=args.workers, pin_memory=True, sampler=train_loader_sampler, drop_last = True) + + val_loader = torch.utils.data.DataLoader( + datasets.ImageFolder(valdir, transforms.Compose([ + transforms.Resize(256), + transforms.CenterCrop(224), + transforms.ToTensor(), + normalize, + ])), + batch_size=args.batch_size, shuffle=True, + num_workers=args.workers, pin_memory=False, drop_last=True) + + if args.evaluate: + validate(val_loader, model, criterion, args) + return + + for epoch in range(args.start_epoch, args.epochs): + train_loader.sampler.set_epoch(epoch) + + + adjust_learning_rate(optimizer, epoch, args) + + # train for one epoch + train(train_loader, model, criterion, optimizer, epoch, args) + + # evaluate on validation set + acc1 = validate(val_loader, model, criterion, args) + + # remember best acc@1 and save checkpoint + is_best = acc1 > best_acc1 + best_acc1 = max(acc1, best_acc1) + + if not args.multiprocessing_distributed or (args.multiprocessing_distributed + and args.rank % ngpus_per_node == 0): + if args.amp: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': args.arch, + 'state_dict': model.state_dict(), + 'best_acc1': best_acc1, + 'optimizer': optimizer.state_dict(), + 'amp': amp.state_dict(), + }, is_best) + else: + save_checkpoint({ + 'epoch': epoch + 1, + 'arch': args.arch, + 'state_dict': model.state_dict(), + 'best_acc1': best_acc1, + 'optimizer': optimizer.state_dict(), + }, is_best) + + +def train(train_loader, model, criterion, optimizer, epoch, args): + batch_time = AverageMeter('Time', ':6.3f') + data_time = AverageMeter('Data', ':6.3f') + losses = AverageMeter('Loss', ':.4e') + top1 = AverageMeter('Acc@1', ':6.2f') + top5 = AverageMeter('Acc@5', ':6.2f') + progress = ProgressMeter( + len(train_loader), + [batch_time, data_time, losses, top1, top5], + prefix="Epoch: [{}]".format(epoch)) + + # switch to train mode + model.train() + + end = time.time() + for i, (images, target) in enumerate(train_loader): + # measure data loading time + data_time.update(time.time() - end) + + if args.gpu is not None: + images = images.npu(f'npu:{NPU_CALCULATE_DEVICE}', non_blocking=True) + if torch.npu.is_available(): + target = target.npu(f'npu:{NPU_CALCULATE_DEVICE}', non_blocking=True) + + # compute output + output = model(images) + loss = criterion(output, target) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # compute gradient and do SGD step + optimizer.zero_grad() + if args.amp: + with amp.scale_loss(loss, optimizer) as scaled_loss: + scaled_loss.backward() + else: + loss.backward() + optimizer.step() + + # measure elapsed time + batch_time.update(time.time() - end) + end = time.time() + + if i % args.print_freq == 0: + progress.display(i) + + +def validate(val_loader, model, criterion, args): + batch_time = AverageMeter('Time', ':6.3f', Summary.NONE) + losses = AverageMeter('Loss', ':.4e', Summary.NONE) + top1 = AverageMeter('Acc@1', ':6.2f', Summary.AVERAGE) + top5 = AverageMeter('Acc@5', ':6.2f', Summary.AVERAGE) + progress = ProgressMeter( + len(val_loader), + [batch_time, losses, top1, top5], + prefix='Test: ') + + # switch to evaluate mode + model.eval() + + with torch.no_grad(): + end = time.time() + for i, (images, target) in enumerate(val_loader): + if args.gpu is not None: + images = images.npu(f'npu:{NPU_CALCULATE_DEVICE}', non_blocking=True) + if torch.npu.is_available(): + target = target.npu(f'npu:{NPU_CALCULATE_DEVICE}', non_blocking=True) + + # compute output + output = model(images) + loss = criterion(output, target) + + # measure accuracy and record loss + acc1, acc5 = accuracy(output, target, topk=(1, 5)) + losses.update(loss.item(), images.size(0)) + top1.update(acc1[0], images.size(0)) + top5.update(acc5[0], images.size(0)) + + # measure elapsed time + batch_time.update(time.time() - end) + end = time.time() + + if i % args.print_freq == 0: + progress.display(i) + + progress.display_summary() + + return top1.avg + + +def save_checkpoint(state, is_best, filename='checkpoint.pth.tar'): + torch.save(state, filename) + if is_best: + shutil.copyfile(filename, 'model_best.pth.tar') + + +class Summary(Enum): + NONE = 0 + AVERAGE = 1 + SUM = 2 + COUNT = 3 + + +class AverageMeter(object): + """Computes and stores the average and current value""" + + def __init__(self, name, fmt=':f', summary_type=Summary.AVERAGE): + self.name = name + self.fmt = fmt + self.summary_type = summary_type + self.reset() + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + self.val = val + self.sum += val * n + self.count += n + self.avg = self.sum / self.count + + def __str__(self): + fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})' + return fmtstr.format(**self.__dict__) + + def summary(self): + fmtstr = '' + if self.summary_type is Summary.NONE: + fmtstr = '' + elif self.summary_type is Summary.AVERAGE: + fmtstr = '{name} {avg:.3f}' + elif self.summary_type is Summary.SUM: + fmtstr = '{name} {sum:.3f}' + elif self.summary_type is Summary.COUNT: + fmtstr = '{name} {count:.3f}' + else: + raise ValueError('invalid summary type %r' % self.summary_type) + + return fmtstr.format(**self.__dict__) + + +class ProgressMeter(object): + def __init__(self, num_batches, meters, prefix=""): + self.batch_fmtstr = self._get_batch_fmtstr(num_batches) + self.meters = meters + self.prefix = prefix + + def display(self, batch): + entries = [self.prefix + self.batch_fmtstr.format(batch)] + entries += [str(meter) for meter in self.meters] + print('\t'.join(entries)) + + def display_summary(self): + entries = [" *"] + entries += [meter.summary() for meter in self.meters] + print(' '.join(entries)) + + def _get_batch_fmtstr(self, num_batches): + num_digits = len(str(num_batches // 1)) + fmt = '{:' + str(num_digits) + 'd}' + return '[' + fmt + '/' + fmt.format(num_batches) + ']' + + +def adjust_learning_rate(optimizer, epoch, args): + """Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" + lr = args.lr * (0.1 ** (epoch // 30)) + for param_group in optimizer.param_groups: + param_group['lr'] = lr + + +def accuracy(output, target, topk=(1,)): + """Computes the accuracy over the k top predictions for the specified values of k""" + with torch.no_grad(): + maxk = max(topk) + batch_size = target.size(0) + + _, pred = output.topk(maxk, 1, True, True) + pred = pred.t() + correct = pred.eq(target.view(1, -1).expand_as(pred)) + + res = [] + for k in topk: + correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True) + res.append(correct_k.mul_(100.0 / batch_size)) + return res + + +if __name__ == '__main__': + main() + diff --git a/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/modelzoo_level.txt b/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/modelzoo_level.txt index 484664c2399ae4109859a67aba6cb9facff03cf1..55a9add9fa74832ca908108d73946cd76281a9cd 100644 --- a/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/test/train_full_8pt.sh b/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/test/train_full_8pt.sh index e73115f70f335a809bd3185ac6ebb64beeec9a14..5474eb332c6e039c814e7e1e96d6a8436eec31d4 100644 --- a/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/test/train_full_8pt.sh +++ b/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/test/train_full_8pt.sh @@ -1,197 +1,197 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#source env.sh -#集合通信参数,不需要修改 - -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 - - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="ResNet152_ID0424_for_PyTorch" -#训练epoch -train_epochs=110 -#训练batch_size -batch_size=2048 -#训练step -#train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.5 - -#TF2.X独有,需要模型审视修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -#precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_performance_1P.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path/.. -for((RANK_ID=$RANK_ID_START;RANK_ID<1;RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - #export RANK_ID=$RANK_ID - #export ASCEND_DEVICE_ID=$RANK_ID - ASCEND_DEVICE_ID=$RANK_ID - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - # 绑核,不需要的绑核的模型删除,需要的模型审视修改 - #let a=RANK_ID*12 - #let b=RANK_ID+1 - #let c=b*12-1 - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path - -done -wait - - - -export MASTER_ADDR=localhost -export MASTER_PORT=29688 -export HCCL_WHITELIST_DISABLE=1 - -NPUS=($(seq 0 7)) -export NPU_WORLD_SIZE=${#NPUS[@]} -rank=0 -for i in ${NPUS[@]} -do - export NPU_CALCULATE_DEVICE=${i} - export RANK=${rank} - echo run process ${rank} - python3 main_8p.py \ - ${data_path} \ - -a resnet152 \ - --seed=49 \ - --learning-rate=0.8 \ - --mom=0.9 \ - --weight-decay=1.0e-04 \ - --print-freq=1 \ - --epochs=1 \ - --batch-size=256 \ - --gpu ${i} \ - --FusedSGD \ - --loss-scale=1024 \ - --amp > $cur_path/output/${ASCEND_DEVICE_ID}/train_${i}.log 2>&1 & - let rank++ -done -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep -a 'FPS' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a '* Acc@1' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch: $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v Test|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#source env.sh +#集合通信参数,不需要修改 + +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 + + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="ResNet152_ID0424_for_PyTorch" +#训练epoch +train_epochs=110 +#训练batch_size +batch_size=2048 +#训练step +#train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.5 + +#TF2.X独有,需要模型审视修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +#precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_performance_1P.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path/.. +for((RANK_ID=$RANK_ID_START;RANK_ID<1;RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + #export RANK_ID=$RANK_ID + #export ASCEND_DEVICE_ID=$RANK_ID + ASCEND_DEVICE_ID=$RANK_ID + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + # 绑核,不需要的绑核的模型删除,需要的模型审视修改 + #let a=RANK_ID*12 + #let b=RANK_ID+1 + #let c=b*12-1 + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path + +done +wait + + + +export MASTER_ADDR=localhost +export MASTER_PORT=29688 +export HCCL_WHITELIST_DISABLE=1 + +NPUS=($(seq 0 7)) +export NPU_WORLD_SIZE=${#NPUS[@]} +rank=0 +for i in ${NPUS[@]} +do + export NPU_CALCULATE_DEVICE=${i} + export RANK=${rank} + echo run process ${rank} + python3 main_8p.py \ + ${data_path} \ + -a resnet152 \ + --seed=49 \ + --learning-rate=0.8 \ + --mom=0.9 \ + --weight-decay=1.0e-04 \ + --print-freq=1 \ + --epochs=1 \ + --batch-size=256 \ + --gpu ${i} \ + --FusedSGD \ + --loss-scale=1024 \ + --amp > $cur_path/output/${ASCEND_DEVICE_ID}/train_${i}.log 2>&1 & + let rank++ +done +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep -a 'FPS' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a '* Acc@1' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch: $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v Test|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/test/train_performance_16p.sh b/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/test/train_performance_16p.sh index e713468687efbd9f4806d8af1d987a3379ed8619..061b47e07b883992129e854b59f1f677043c631a 100644 --- a/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/test/train_performance_16p.sh +++ b/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch/test/train_performance_16p.sh @@ -1,213 +1,213 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#source env.sh -#集合通信参数,不需要修改 - -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 - - -# 数据集路径,保持为空,不需要修改 -data_path="" -conf_path="" -server_index="" -fix_node_ip="" -devicesnum="" - -#设置默认日志级别,不需要修改 -export ASCEND_GLOBAL_LOG_LEVEL=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="ResNet152_ID0424_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=4096 -#训练step -#train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.5 - -#TF2.X独有,需要模型审视修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -#precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_performance_1P.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --fix_node_ip* ]];then - fix_node_ip=`echo ${para#*=}` - elif [[ $para == --devicesnum* ]];then - devicesnum=`echo ${para#*=}` - elif [[ $para == --conf_path* ]];then - conf_path=`echo ${para#*=}` - elif [[ $para == --server_index* ]];then - server_index=`echo ${para#*=}` - fi -done - -one_node_ip=`find $conf_path -name "server_*0.info"|awk -F "server_" '{print $2}'|awk -F "_" '{print $1}'` -linux_num=`find $conf_path -name "server_*.info" |wc -l` - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -export HCCL_IF_IP=$fix_node_ip -export MASTER_ADDR=$one_node_ip -export MASTER_PORT=29688 -export HCCL_WHITELIST_DISABLE=1 -device_num=${#devicesnum} -devices_num=`awk 'BEGIN{printf "%.0f\n",'${device_num}'-1}'` - -NPUS=($(seq 0 $devices_num)) -rank_server=`awk 'BEGIN{printf "%.0f\n",'${device_num}'*'${server_index}'}'` -export NPU_WORLD_SIZE=`awk 'BEGIN{printf "%.0f\n",'${device_num}'*'${linux_num}'}'` - - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path/.. -rank=0 -for((RANK_ID=$RANK_ID_START;RANK_ID<1;RANK_ID++)); -do - #设置环境变量,不需要修改 - ASCEND_DEVICE_ID=$RANK_ID - echo "Device ID: $ASCEND_DEVICE_ID" - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - # 绑核,不需要的绑核的模型删除,需要的模型审视修改 - #let a=RANK_ID*12 - #let b=RANK_ID+1 - #let c=b*12-1 - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path - nohup python3 ${cur_path}/../main.py \ - ${data_path} \ - -a resnet152 \ - --addr=$one_node_ip \ - --seed=49 \ - --workers=$(nproc) \ - --learning-rate=${learning_rate} \ - --mom=0.9 \ - --weight-decay=1.0e-04 \ - --print-freq=1 \ - --dist-url='tcp://127.0.0.1:50000' \ - --multiprocessing-distributed \ - --world-size=2 \ - --rank=${server_index} \ - --device='npu' \ - --dist-backend='hccl' \ - --epochs=${train_epochs} \ - --batch-size=${batch_size} \ - --amp \ - --device_list=0,1,2,3,4,5,6,7 \ - --FusedSGD \ - --stop-step-num=128 \ - --loss-scale=1024 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -done -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -fps=`grep -a 'FPS' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` -FPS=`awk 'BEGIN{printf "%.2f\n",'${fps}'*2}'` -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a '* Acc@1' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Epoch: $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v Test|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#source env.sh +#集合通信参数,不需要修改 + +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 + + +# 数据集路径,保持为空,不需要修改 +data_path="" +conf_path="" +server_index="" +fix_node_ip="" +devicesnum="" + +#设置默认日志级别,不需要修改 +export ASCEND_GLOBAL_LOG_LEVEL=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="ResNet152_ID0424_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=4096 +#训练step +#train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.5 + +#TF2.X独有,需要模型审视修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +#precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_performance_1P.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --fix_node_ip* ]];then + fix_node_ip=`echo ${para#*=}` + elif [[ $para == --devicesnum* ]];then + devicesnum=`echo ${para#*=}` + elif [[ $para == --conf_path* ]];then + conf_path=`echo ${para#*=}` + elif [[ $para == --server_index* ]];then + server_index=`echo ${para#*=}` + fi +done + +one_node_ip=`find $conf_path -name "server_*0.info"|awk -F "server_" '{print $2}'|awk -F "_" '{print $1}'` +linux_num=`find $conf_path -name "server_*.info" |wc -l` + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +export HCCL_IF_IP=$fix_node_ip +export MASTER_ADDR=$one_node_ip +export MASTER_PORT=29688 +export HCCL_WHITELIST_DISABLE=1 +device_num=${#devicesnum} +devices_num=`awk 'BEGIN{printf "%.0f\n",'${device_num}'-1}'` + +NPUS=($(seq 0 $devices_num)) +rank_server=`awk 'BEGIN{printf "%.0f\n",'${device_num}'*'${server_index}'}'` +export NPU_WORLD_SIZE=`awk 'BEGIN{printf "%.0f\n",'${device_num}'*'${linux_num}'}'` + + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path/.. +rank=0 +for((RANK_ID=$RANK_ID_START;RANK_ID<1;RANK_ID++)); +do + #设置环境变量,不需要修改 + ASCEND_DEVICE_ID=$RANK_ID + echo "Device ID: $ASCEND_DEVICE_ID" + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + # 绑核,不需要的绑核的模型删除,需要的模型审视修改 + #let a=RANK_ID*12 + #let b=RANK_ID+1 + #let c=b*12-1 + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path + nohup python3 ${cur_path}/../main.py \ + ${data_path} \ + -a resnet152 \ + --addr=$one_node_ip \ + --seed=49 \ + --workers=$(nproc) \ + --learning-rate=${learning_rate} \ + --mom=0.9 \ + --weight-decay=1.0e-04 \ + --print-freq=1 \ + --dist-url='tcp://127.0.0.1:50000' \ + --multiprocessing-distributed \ + --world-size=2 \ + --rank=${server_index} \ + --device='npu' \ + --dist-backend='hccl' \ + --epochs=${train_epochs} \ + --batch-size=${batch_size} \ + --amp \ + --device_list=0,1,2,3,4,5,6,7 \ + --FusedSGD \ + --stop-step-num=128 \ + --loss-scale=1024 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +done +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +fps=`grep -a 'FPS' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $NF}'|awk 'END {print}'` +FPS=`awk 'BEGIN{printf "%.2f\n",'${fps}'*2}'` +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a '* Acc@1' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk 'END {print}'|awk -F "Acc@1" '{print $NF}'|awk -F " " '{print $1}'` +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Epoch: $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v Test|awk -F "Loss" '{print $NF}' | awk -F " " '{print $1}' >> $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/SEResNext_ID0415_for_PyTorch/README_ori.md b/PyTorch/dev/cv/image_classification/SEResNext_ID0415_for_PyTorch/README_ori.md index dc0d40de7e7698b34ccbf7eba07d61628d13f9f2..3847a5f095590b08fbcfafed32022ac8229647e0 100644 --- a/PyTorch/dev/cv/image_classification/SEResNext_ID0415_for_PyTorch/README_ori.md +++ b/PyTorch/dev/cv/image_classification/SEResNext_ID0415_for_PyTorch/README_ori.md @@ -1,118 +1,118 @@ -# Convolutional Networks for Image Classification in PyTorch - -In this repository you will find implementations of various image classification models. - -Detailed information on each model can be found here: - -## Table Of Contents - -* [Models](#models) -* [Validation accuracy results](#validation-accuracy-results) -* [Training performance results](#training-performance-results) - * [Training performance: NVIDIA DGX A100 (8x A100 40GB)](#training-performance-nvidia-dgx-a100-8x-a100-40gb) - * [Training performance: NVIDIA DGX-1 16GB (8x V100 16GB)](#training-performance-nvidia-dgx-1-16gb-8x-v100-16gb) - * [Training performance: NVIDIA DGX-2 (16x V100 32GB)](#training-performance-nvidia-dgx-2-16x-v100-32gb) -* [Model comparison](#model-comparison) - * [Accuracy vs FLOPS](#accuracy-vs-flops) - * [Latency vs Throughput on different batch sizes](#latency-vs-throughput-on-different-batch-sizes) - -## Models - -The following table provides links to where you can find additional information on each model: - -| **Model** | **Link**| -|:-:|:-:| -| resnet50 | [README](./resnet50v1.5/README.md) | -| resnext101-32x4d | [README](./resnext101-32x4d/README.md) | -| se-resnext101-32x4d | [README](./se-resnext101-32x4d/README.md) | - -## Validation accuracy results - -Our results were obtained by running the applicable -training scripts in the [framework-container-name] NGC container -on NVIDIA DGX-1 with (8x V100 16GB) GPUs. -The specific training script that was run is documented -in the corresponding model's README. - - -The following table shows the validation accuracy results of the -three classification models side-by-side. - - -| **arch** | **AMP Top1** | **AMP Top5** | **FP32 Top1** | **FP32 Top5** | -|:-:|:-:|:-:|:-:|:-:| -| resnet50 | 78.46 | 94.15 | 78.50 | 94.11 | -| resnext101-32x4d | 80.08 | 94.89 | 80.14 | 95.02 | -| se-resnext101-32x4d | 81.01 | 95.52 | 81.12 | 95.54 | - - -## Training performance results - -### Training performance: NVIDIA DGX A100 (8x A100 40GB) - - -Our results were obtained by running the applicable -training scripts in the pytorch-20.06 NGC container -on NVIDIA DGX A100 with (8x A100 40GB) GPUs. -Performance numbers (in images per second) -were averaged over an entire training epoch. -The specific training script that was run is documented -in the corresponding model's README. - -The following table shows the training accuracy results of the -three classification models side-by-side. - - -| **arch** | **Mixed Precision** | **TF32** | **Mixed Precision Speedup** | -|:-------------------:|:-------------------:|:-------------:|:---------------------------:| -| resnet50 | 9488.39 img/s | 5322.10 img/s | 1.78x | -| resnext101-32x4d | 6758.98 img/s | 2353.25 img/s | 2.87x | -| se-resnext101-32x4d | 4670.72 img/s | 2011.21 img/s | 2.32x | - -ResNeXt and SE-ResNeXt use [NHWC data layout](https://pytorch.org/tutorials/intermediate/memory_format_tutorial.html) when training using Mixed Precision, -which improves the model performance. We are currently working on adding it for ResNet. - - -### Training performance: NVIDIA DGX-1 16G (8x V100 16GB) - - -Our results were obtained by running the applicable -training scripts in the pytorch-20.06 NGC container -on NVIDIA DGX-1 with (8x V100 16GB) GPUs. -Performance numbers (in images per second) -were averaged over an entire training epoch. -The specific training script that was run is documented -in the corresponding model's README. - -The following table shows the training accuracy results of the -three classification models side-by-side. - - -| **arch** | **Mixed Precision** | **FP32** | **Mixed Precision Speedup** | -|:-------------------:|:-------------------:|:-------------:|:---------------------------:| -| resnet50 | 6565.61 img/s | 2869.19 img/s | 2.29x | -| resnext101-32x4d | 3922.74 img/s | 1136.30 img/s | 3.45x | -| se-resnext101-32x4d | 2651.13 img/s | 982.78 img/s | 2.70x | - -ResNeXt and SE-ResNeXt use [NHWC data layout](https://pytorch.org/tutorials/intermediate/memory_format_tutorial.html) when training using Mixed Precision, -which improves the model performance. We are currently working on adding it for ResNet. - - -## Model Comparison - -### Accuracy vs FLOPS -![ACCvsFLOPS](./img/ACCvsFLOPS.png) - -Plot describes relationship between floating point operations -needed for computing forward pass on a 224px x 224px image, -for the implemented models. -Dot size indicates number of trainable parameters. - -### Latency vs Throughput on different batch sizes -![LATvsTHR](./img/LATvsTHR.png) - -Plot describes relationship between -inference latency, throughput and batch size -for the implemented models. - - +# Convolutional Networks for Image Classification in PyTorch + +In this repository you will find implementations of various image classification models. + +Detailed information on each model can be found here: + +## Table Of Contents + +* [Models](#models) +* [Validation accuracy results](#validation-accuracy-results) +* [Training performance results](#training-performance-results) + * [Training performance: NVIDIA DGX A100 (8x A100 40GB)](#training-performance-nvidia-dgx-a100-8x-a100-40gb) + * [Training performance: NVIDIA DGX-1 16GB (8x V100 16GB)](#training-performance-nvidia-dgx-1-16gb-8x-v100-16gb) + * [Training performance: NVIDIA DGX-2 (16x V100 32GB)](#training-performance-nvidia-dgx-2-16x-v100-32gb) +* [Model comparison](#model-comparison) + * [Accuracy vs FLOPS](#accuracy-vs-flops) + * [Latency vs Throughput on different batch sizes](#latency-vs-throughput-on-different-batch-sizes) + +## Models + +The following table provides links to where you can find additional information on each model: + +| **Model** | **Link**| +|:-:|:-:| +| resnet50 | [README](./resnet50v1.5/README.md) | +| resnext101-32x4d | [README](./resnext101-32x4d/README.md) | +| se-resnext101-32x4d | [README](./se-resnext101-32x4d/README.md) | + +## Validation accuracy results + +Our results were obtained by running the applicable +training scripts in the [framework-container-name] NGC container +on NVIDIA DGX-1 with (8x V100 16GB) GPUs. +The specific training script that was run is documented +in the corresponding model's README. + + +The following table shows the validation accuracy results of the +three classification models side-by-side. + + +| **arch** | **AMP Top1** | **AMP Top5** | **FP32 Top1** | **FP32 Top5** | +|:-:|:-:|:-:|:-:|:-:| +| resnet50 | 78.46 | 94.15 | 78.50 | 94.11 | +| resnext101-32x4d | 80.08 | 94.89 | 80.14 | 95.02 | +| se-resnext101-32x4d | 81.01 | 95.52 | 81.12 | 95.54 | + + +## Training performance results + +### Training performance: NVIDIA DGX A100 (8x A100 40GB) + + +Our results were obtained by running the applicable +training scripts in the pytorch-20.06 NGC container +on NVIDIA DGX A100 with (8x A100 40GB) GPUs. +Performance numbers (in images per second) +were averaged over an entire training epoch. +The specific training script that was run is documented +in the corresponding model's README. + +The following table shows the training accuracy results of the +three classification models side-by-side. + + +| **arch** | **Mixed Precision** | **TF32** | **Mixed Precision Speedup** | +|:-------------------:|:-------------------:|:-------------:|:---------------------------:| +| resnet50 | 9488.39 img/s | 5322.10 img/s | 1.78x | +| resnext101-32x4d | 6758.98 img/s | 2353.25 img/s | 2.87x | +| se-resnext101-32x4d | 4670.72 img/s | 2011.21 img/s | 2.32x | + +ResNeXt and SE-ResNeXt use [NHWC data layout](https://pytorch.org/tutorials/intermediate/memory_format_tutorial.html) when training using Mixed Precision, +which improves the model performance. We are currently working on adding it for ResNet. + + +### Training performance: NVIDIA DGX-1 16G (8x V100 16GB) + + +Our results were obtained by running the applicable +training scripts in the pytorch-20.06 NGC container +on NVIDIA DGX-1 with (8x V100 16GB) GPUs. +Performance numbers (in images per second) +were averaged over an entire training epoch. +The specific training script that was run is documented +in the corresponding model's README. + +The following table shows the training accuracy results of the +three classification models side-by-side. + + +| **arch** | **Mixed Precision** | **FP32** | **Mixed Precision Speedup** | +|:-------------------:|:-------------------:|:-------------:|:---------------------------:| +| resnet50 | 6565.61 img/s | 2869.19 img/s | 2.29x | +| resnext101-32x4d | 3922.74 img/s | 1136.30 img/s | 3.45x | +| se-resnext101-32x4d | 2651.13 img/s | 982.78 img/s | 2.70x | + +ResNeXt and SE-ResNeXt use [NHWC data layout](https://pytorch.org/tutorials/intermediate/memory_format_tutorial.html) when training using Mixed Precision, +which improves the model performance. We are currently working on adding it for ResNet. + + +## Model Comparison + +### Accuracy vs FLOPS +![ACCvsFLOPS](./img/ACCvsFLOPS.png) + +Plot describes relationship between floating point operations +needed for computing forward pass on a 224px x 224px image, +for the implemented models. +Dot size indicates number of trainable parameters. + +### Latency vs Throughput on different batch sizes +![LATvsTHR](./img/LATvsTHR.png) + +Plot describes relationship between +inference latency, throughput and batch size +for the implemented models. + + diff --git a/PyTorch/dev/cv/image_classification/SINGLESHOTPOSE_ID0869_for_PyTorch/requirements.txt b/PyTorch/dev/cv/image_classification/SINGLESHOTPOSE_ID0869_for_PyTorch/requirements.txt index 8367c68c70bbf939fb99178b36a63a04bfef92ae..b0b3b089fc4edf671c91f863d00f3b09251a0cd8 100644 --- a/PyTorch/dev/cv/image_classification/SINGLESHOTPOSE_ID0869_for_PyTorch/requirements.txt +++ b/PyTorch/dev/cv/image_classification/SINGLESHOTPOSE_ID0869_for_PyTorch/requirements.txt @@ -1,3 +1,3 @@ -torch==1.5.0 -apex +torch==1.5.0 +apex torchvision \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/SRCNN_ID1770_for_PyTorch/test/train_full_8p.sh b/PyTorch/dev/cv/image_classification/SRCNN_ID1770_for_PyTorch/test/train_full_8p.sh index cf17a4a0925eeaadf5c4a227ed504509338de3d8..e7cca923a2f61445802ca6471b313364d50aa3b7 100644 --- a/PyTorch/dev/cv/image_classification/SRCNN_ID1770_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/dev/cv/image_classification/SRCNN_ID1770_for_PyTorch/test/train_full_8p.sh @@ -1,141 +1,141 @@ -#!/bin/bash - -cur_path=`pwd`/../ -path=`pwd` -#失败用例打屏 - -export HDF5_DISABLE_VERSION_CHECK=1 - -export PATH=/usr/local/hdf5/bin:$PATH -export LD_LIBRARY_PATH=/usr/local/hdf5/lib:$LD_LIBRARY_PATH -export LIBRARY_PATH=/usr/local/hdf5/lib:$LIBRARY_PATH -export CPATH=/usr/local/hdf5/include:$CPATH - -#基础参数,需要模型审视修改 -#Batch Size -batch_size=160 -#网络名称,同目录名称 -Network="SRCNN_ID1770_for_PyTorch" -#Device数量,单卡默认为1 -RankSize=8 -#训练epoch,可选 -train_epochs=400 -#训练step -train_steps= -#学习率 -learning_rate=1e-3 - -num_workers=192 - -#参数配置 -data_path="/npu/traindata/ID1770_CarPeting_Pytorch_SRCNN" -PREC="--apex --apex_opt_level O2" - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh " - exit 1 -fi - -for para in $* -do - if [[ $para == --precision_mode* ]];then - apex_opt_level=`echo ${para#*=}` - if [[ $apex_opt_level != "O1" ]] && [[ $apex_opt_level != "O2" ]] && [[ $apex_opt_level != "O3" ]]; then - echo "[ERROR] para \"precision_mode\" must be config O1 or O2 or O3" - exit 1 - fi - PREC="--apex --apex-opt-level "$apex_opt_level - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be config" - exit 1 -fi -##############执行训练########## -cd $cur_path -if [ -d $cur_path/test/output ];then - rm -rf $cur_path/test/output/* - mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID -fi -wait - -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID - -start=$(date +%s) -export MASTER_ADDR=localhost -export MASTER_PORT=29688 -export HCCL_WHITELIST_DISABLE=1 - -NPUS=($(seq 0 7)) -export NPU_WORLD_SIZE=${#NPUS[@]} -rank=0 -for i in ${NPUS[@]} -do - mkdir -p $path/output/${i}/ - export NPU_CALCULATE_DEVICE=${i} - export RANK=${rank} - export ASCEND_DEVICE_ID=${i} - echo run process ${rank} - python3 train.py $PREC --ddp --train-file "$data_path/SRCNN/91-image_x2.h5" \ - --eval-file "$data_path/SRCNN/Set5_x2.h5" \ - --outputs-dir "outputs" \ - --scale 3 \ - --lr $learning_rate \ - --batch-size $batch_size \ - --num-epochs $train_epochs \ - --num-workers $num_workers \ - --seed 123 > $path/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & - let rank++ -done -wait -end=$(date +%s) -e2e_time=$(( $end - $start )) -sed -i "s|\r|\n|g" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep "FPS" $path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F ", loss" '{print$1}' | awk '{print$NF}' |awk '{sum+=$1} END {print"",sum*8/NR}'` -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep "best epoch" $path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk '{print$NF}'` -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -#打印,不需要修改 -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RankSize}'p'_'acc' - -##获取性能数据,不需要修改 -ActualFPS=${FPS} - -#单迭代训练时长 -TrainingTime=`echo "${BatchSize} ${FPS}"|awk '{printf("%.4f\n", $1*1000/$2)}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "FPS" $path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log| awk '{print$NF}' > $path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RankSize}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +cur_path=`pwd`/../ +path=`pwd` +#失败用例打屏 + +export HDF5_DISABLE_VERSION_CHECK=1 + +export PATH=/usr/local/hdf5/bin:$PATH +export LD_LIBRARY_PATH=/usr/local/hdf5/lib:$LD_LIBRARY_PATH +export LIBRARY_PATH=/usr/local/hdf5/lib:$LIBRARY_PATH +export CPATH=/usr/local/hdf5/include:$CPATH + +#基础参数,需要模型审视修改 +#Batch Size +batch_size=160 +#网络名称,同目录名称 +Network="SRCNN_ID1770_for_PyTorch" +#Device数量,单卡默认为1 +RankSize=8 +#训练epoch,可选 +train_epochs=400 +#训练step +train_steps= +#学习率 +learning_rate=1e-3 + +num_workers=192 + +#参数配置 +data_path="/npu/traindata/ID1770_CarPeting_Pytorch_SRCNN" +PREC="--apex --apex_opt_level O2" + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh " + exit 1 +fi + +for para in $* +do + if [[ $para == --precision_mode* ]];then + apex_opt_level=`echo ${para#*=}` + if [[ $apex_opt_level != "O1" ]] && [[ $apex_opt_level != "O2" ]] && [[ $apex_opt_level != "O3" ]]; then + echo "[ERROR] para \"precision_mode\" must be config O1 or O2 or O3" + exit 1 + fi + PREC="--apex --apex-opt-level "$apex_opt_level + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be config" + exit 1 +fi +##############执行训练########## +cd $cur_path +if [ -d $cur_path/test/output ];then + rm -rf $cur_path/test/output/* + mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID +fi +wait + +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID + +start=$(date +%s) +export MASTER_ADDR=localhost +export MASTER_PORT=29688 +export HCCL_WHITELIST_DISABLE=1 + +NPUS=($(seq 0 7)) +export NPU_WORLD_SIZE=${#NPUS[@]} +rank=0 +for i in ${NPUS[@]} +do + mkdir -p $path/output/${i}/ + export NPU_CALCULATE_DEVICE=${i} + export RANK=${rank} + export ASCEND_DEVICE_ID=${i} + echo run process ${rank} + python3 train.py $PREC --ddp --train-file "$data_path/SRCNN/91-image_x2.h5" \ + --eval-file "$data_path/SRCNN/Set5_x2.h5" \ + --outputs-dir "outputs" \ + --scale 3 \ + --lr $learning_rate \ + --batch-size $batch_size \ + --num-epochs $train_epochs \ + --num-workers $num_workers \ + --seed 123 > $path/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & + let rank++ +done +wait +end=$(date +%s) +e2e_time=$(( $end - $start )) +sed -i "s|\r|\n|g" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep "FPS" $path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F ", loss" '{print$1}' | awk '{print$NF}' |awk '{sum+=$1} END {print"",sum*8/NR}'` +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep "best epoch" $path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk '{print$NF}'` +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +#打印,不需要修改 +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RankSize}'p'_'acc' + +##获取性能数据,不需要修改 +ActualFPS=${FPS} + +#单迭代训练时长 +TrainingTime=`echo "${BatchSize} ${FPS}"|awk '{printf("%.4f\n", $1*1000/$2)}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "FPS" $path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log| awk '{print$NF}' > $path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RankSize}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "TrainAccuracy = ${train_accuracy}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/SRCNN_ID1770_for_PyTorch/test/train_performance_8p.sh b/PyTorch/dev/cv/image_classification/SRCNN_ID1770_for_PyTorch/test/train_performance_8p.sh index 5d88cb8a1765a4901752913a6f1f879ed971e0cf..80c42e5f2164131f33634a1649c35fb00ed5f0a1 100644 --- a/PyTorch/dev/cv/image_classification/SRCNN_ID1770_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/dev/cv/image_classification/SRCNN_ID1770_for_PyTorch/test/train_performance_8p.sh @@ -1,136 +1,136 @@ -#!/bin/bash - -cur_path=`pwd`/../ -path=`pwd` -#失败用例打屏 - -export HDF5_DISABLE_VERSION_CHECK=1 - -export PATH=/usr/local/hdf5/bin:$PATH -export LD_LIBRARY_PATH=/usr/local/hdf5/lib:$LD_LIBRARY_PATH -export LIBRARY_PATH=/usr/local/hdf5/lib:$LIBRARY_PATH -export CPATH=/usr/local/hdf5/include:$CPATH - -#基础参数,需要模型审视修改 -#Batch Size -batch_size=160 -#网络名称,同目录名称 -Network="SRCNN_ID1770_for_PyTorch" -#Device数量,单卡默认为1 -RankSize=8 -#训练epoch,可选 -train_epochs=10 -#训练step -train_steps= -#学习率 -learning_rate=1e-3 - -num_workers=192 - -#参数配置 -data_path="/npu/traindata/ID1770_CarPeting_Pytorch_SRCNN" -PREC="--apex --apex_opt_level O2" - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh " - exit 1 -fi - -for para in $* -do - if [[ $para == --precision_mode* ]];then - apex_opt_level=`echo ${para#*=}` - if [[ $apex_opt_level != "O1" ]] && [[ $apex_opt_level != "O2" ]] && [[ $apex_opt_level != "O3" ]]; then - echo "[ERROR] para \"precision_mode\" must be config O1 or O2 or O3" - exit 1 - fi - PREC="--apex --apex-opt-level "$apex_opt_level - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be config" - exit 1 -fi -##############执行训练########## -cd $cur_path -if [ -d $cur_path/test/output ];then - rm -rf $cur_path/test/output/* - mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID -fi -wait - -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID - -start=$(date +%s) -export MASTER_ADDR=localhost -export MASTER_PORT=29688 -export HCCL_WHITELIST_DISABLE=1 - -NPUS=($(seq 0 7)) -export NPU_WORLD_SIZE=${#NPUS[@]} -rank=0 -for i in ${NPUS[@]} -do - mkdir -p $path/output/${i}/ - export NPU_CALCULATE_DEVICE=${i} - export RANK=${rank} - export ASCEND_DEVICE_ID=${i} - echo run process ${rank} - python3 train.py $PREC --ddp --train-file "$data_path/SRCNN/91-image_x2.h5" \ - --eval-file "$data_path/SRCNN/Set5_x2.h5" \ - --outputs-dir "outputs" \ - --scale 3 \ - --lr $learning_rate \ - --batch-size $batch_size \ - --num-epochs $train_epochs \ - --num-workers $num_workers \ - --seed 123 > $path/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & - let rank++ -done -wait -end=$(date +%s) -e2e_time=$(( $end - $start )) -sed -i "s|\r|\n|g" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep "FPS" $path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F ", loss" '{print$1}' | awk '{print$NF}' |awk '{sum+=$1} END {print"",sum*8/NR}'` -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#打印,不需要修改 -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RankSize}'p'_'perf' - -#获取性能数据,不需要修改 -ActualFPS=${FPS} - -#单迭代训练时长 -TrainingTime=`echo "${BatchSize} ${FPS}"|awk '{printf("%.4f\n", $1*1000/$2)}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "FPS" $path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log| awk '{print$NF}' > $path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RankSize}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +cur_path=`pwd`/../ +path=`pwd` +#失败用例打屏 + +export HDF5_DISABLE_VERSION_CHECK=1 + +export PATH=/usr/local/hdf5/bin:$PATH +export LD_LIBRARY_PATH=/usr/local/hdf5/lib:$LD_LIBRARY_PATH +export LIBRARY_PATH=/usr/local/hdf5/lib:$LIBRARY_PATH +export CPATH=/usr/local/hdf5/include:$CPATH + +#基础参数,需要模型审视修改 +#Batch Size +batch_size=160 +#网络名称,同目录名称 +Network="SRCNN_ID1770_for_PyTorch" +#Device数量,单卡默认为1 +RankSize=8 +#训练epoch,可选 +train_epochs=10 +#训练step +train_steps= +#学习率 +learning_rate=1e-3 + +num_workers=192 + +#参数配置 +data_path="/npu/traindata/ID1770_CarPeting_Pytorch_SRCNN" +PREC="--apex --apex_opt_level O2" + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh " + exit 1 +fi + +for para in $* +do + if [[ $para == --precision_mode* ]];then + apex_opt_level=`echo ${para#*=}` + if [[ $apex_opt_level != "O1" ]] && [[ $apex_opt_level != "O2" ]] && [[ $apex_opt_level != "O3" ]]; then + echo "[ERROR] para \"precision_mode\" must be config O1 or O2 or O3" + exit 1 + fi + PREC="--apex --apex-opt-level "$apex_opt_level + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be config" + exit 1 +fi +##############执行训练########## +cd $cur_path +if [ -d $cur_path/test/output ];then + rm -rf $cur_path/test/output/* + mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/test/output/$ASCEND_DEVICE_ID +fi +wait + +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID + +start=$(date +%s) +export MASTER_ADDR=localhost +export MASTER_PORT=29688 +export HCCL_WHITELIST_DISABLE=1 + +NPUS=($(seq 0 7)) +export NPU_WORLD_SIZE=${#NPUS[@]} +rank=0 +for i in ${NPUS[@]} +do + mkdir -p $path/output/${i}/ + export NPU_CALCULATE_DEVICE=${i} + export RANK=${rank} + export ASCEND_DEVICE_ID=${i} + echo run process ${rank} + python3 train.py $PREC --ddp --train-file "$data_path/SRCNN/91-image_x2.h5" \ + --eval-file "$data_path/SRCNN/Set5_x2.h5" \ + --outputs-dir "outputs" \ + --scale 3 \ + --lr $learning_rate \ + --batch-size $batch_size \ + --num-epochs $train_epochs \ + --num-workers $num_workers \ + --seed 123 > $path/output/$ASCEND_DEVICE_ID/train_${i}.log 2>&1 & + let rank++ +done +wait +end=$(date +%s) +e2e_time=$(( $end - $start )) +sed -i "s|\r|\n|g" $cur_path/test/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep "FPS" $path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F ", loss" '{print$1}' | awk '{print$NF}' |awk '{sum+=$1} END {print"",sum*8/NR}'` +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#打印,不需要修改 +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RankSize}'p'_'perf' + +#获取性能数据,不需要修改 +ActualFPS=${FPS} + +#单迭代训练时长 +TrainingTime=`echo "${BatchSize} ${FPS}"|awk '{printf("%.4f\n", $1*1000/$2)}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "FPS" $path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log| awk '{print$NF}' > $path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RankSize}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/SlowFast_ID0646_for_PyTorch/detectron2/projects/Panoptic-DeepLab/configs/COCO-PanopticSegmentation/panoptic_deeplab_R_52_os16_mg124_poly_200k_bs64_crop_640_640_coco_dsconv.yaml b/PyTorch/dev/cv/image_classification/SlowFast_ID0646_for_PyTorch/detectron2/projects/Panoptic-DeepLab/configs/COCO-PanopticSegmentation/panoptic_deeplab_R_52_os16_mg124_poly_200k_bs64_crop_640_640_coco_dsconv.yaml deleted file mode 100644 index 6944c6fdf3dcaafdc0a740188610fe604cb7d3be..0000000000000000000000000000000000000000 --- a/PyTorch/dev/cv/image_classification/SlowFast_ID0646_for_PyTorch/detectron2/projects/Panoptic-DeepLab/configs/COCO-PanopticSegmentation/panoptic_deeplab_R_52_os16_mg124_poly_200k_bs64_crop_640_640_coco_dsconv.yaml +++ /dev/null @@ -1,42 +0,0 @@ -_BASE_: ../Cityscapes-PanopticSegmentation/Base-PanopticDeepLab-OS16.yaml -MODEL: - WEIGHTS: "detectron2://DeepLab/R-52.pkl" - PIXEL_MEAN: [123.675, 116.280, 103.530] - PIXEL_STD: [58.395, 57.120, 57.375] - BACKBONE: - NAME: "build_resnet_deeplab_backbone" - RESNETS: - DEPTH: 50 - NORM: "SyncBN" - RES5_MULTI_GRID: [1, 2, 4] - STEM_TYPE: "deeplab" - STEM_OUT_CHANNELS: 128 - STRIDE_IN_1X1: False - SEM_SEG_HEAD: - NUM_CLASSES: 133 - LOSS_TOP_K: 1.0 - USE_DEPTHWISE_SEPARABLE_CONV: True - PANOPTIC_DEEPLAB: - STUFF_AREA: 4096 - NMS_KERNEL: 41 - SIZE_DIVISIBILITY: 640 - USE_DEPTHWISE_SEPARABLE_CONV: True -DATASETS: - TRAIN: ("coco_2017_train_panoptic",) - TEST: ("coco_2017_val_panoptic",) -SOLVER: - BASE_LR: 0.0005 - MAX_ITER: 200000 - IMS_PER_BATCH: 64 -INPUT: - FORMAT: "RGB" - GAUSSIAN_SIGMA: 8 - MIN_SIZE_TRAIN: !!python/object/apply:eval ["[int(x * 0.1 * 640) for x in range(5, 16)]"] - MIN_SIZE_TRAIN_SAMPLING: "choice" - MIN_SIZE_TEST: 640 - MAX_SIZE_TRAIN: 960 - MAX_SIZE_TEST: 640 - CROP: - ENABLED: True - TYPE: "absolute" - SIZE: (640, 640) diff --git a/PyTorch/dev/cv/image_classification/SlowFast_ID0646_for_PyTorch/detectron2/projects/Panoptic-DeepLab/configs/Cityscapes-PanopticSegmentation/panoptic_deeplab_R_52_os16_mg124_poly_90k_bs32_crop_512_1024_dsconv.yaml b/PyTorch/dev/cv/image_classification/SlowFast_ID0646_for_PyTorch/detectron2/projects/Panoptic-DeepLab/configs/Cityscapes-PanopticSegmentation/panoptic_deeplab_R_52_os16_mg124_poly_90k_bs32_crop_512_1024_dsconv.yaml deleted file mode 100644 index 8e314204c9b464993d92d3b4d95e2aa9b287b938..0000000000000000000000000000000000000000 --- a/PyTorch/dev/cv/image_classification/SlowFast_ID0646_for_PyTorch/detectron2/projects/Panoptic-DeepLab/configs/Cityscapes-PanopticSegmentation/panoptic_deeplab_R_52_os16_mg124_poly_90k_bs32_crop_512_1024_dsconv.yaml +++ /dev/null @@ -1,24 +0,0 @@ -_BASE_: Base-PanopticDeepLab-OS16.yaml -MODEL: - WEIGHTS: "detectron2://DeepLab/R-52.pkl" - PIXEL_MEAN: [123.675, 116.280, 103.530] - PIXEL_STD: [58.395, 57.120, 57.375] - BACKBONE: - NAME: "build_resnet_deeplab_backbone" - RESNETS: - DEPTH: 50 - NORM: "SyncBN" - RES5_MULTI_GRID: [1, 2, 4] - STEM_TYPE: "deeplab" - STEM_OUT_CHANNELS: 128 - STRIDE_IN_1X1: False - PANOPTIC_DEEPLAB: - USE_DEPTHWISE_SEPARABLE_CONV: True - SEM_SEG_HEAD: - USE_DEPTHWISE_SEPARABLE_CONV: True -SOLVER: - MAX_ITER: 90000 -INPUT: - FORMAT: "RGB" - CROP: - SIZE: (512, 1024) diff --git a/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/ README.md b/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/ README.md index 5e97ad0585242345f611406fef5e1bb48e6c2b56..acca051a72e6f147c271bb78ac493151bceb1fe5 100644 --- a/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/ README.md +++ b/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/ README.md @@ -1,262 +1,262 @@ -# VGGNet-PyTorch - -### Update (Feb 14, 2020) - -The update is for ease of use and deployment. - - * [Example: Export to ONNX](#example-export-to-onnx) - * [Example: Extract features](#example-feature-extraction) - * [Example: Visual](#example-visual) - -It is also now incredibly simple to load a pretrained model with a new number of classes for transfer learning: - -```python -from vgg_pytorch import VGG -model = VGG.from_pretrained('vgg11', num_classes=10) -``` - -### Update (January 15, 2020) - -This update allows you to use NVIDIA's Apex tool for accelerated training. By default choice `hybrid training precision` + `dynamic loss amplified` version, if you need to learn more and details about `apex` tools, please visit https://github.com/NVIDIA/apex. - -### Update (January 9, 2020) - -This update adds a visual interface for testing, which is developed by pyqt5. At present, it has realized basic functions, and other functions will be gradually improved in the future. - -### Update (January 6, 2020) - -This update adds a modular neural network, making it more flexible in use. It can be deployed to many common dataset classification tasks. Of course, it can also be used in your products. - -### Overview -This repository contains an op-for-op PyTorch reimplementation of [VGGNet](https://arxiv.org/pdf/1409.1556.pdf). - -The goal of this implementation is to be simple, highly extensible, and easy to integrate into your own projects. This implementation is a work in progress -- new features are currently being implemented. - -At the moment, you can easily: - * Load pretrained VGGNet models - * Use VGGNet models for classification or feature extraction - -_Upcoming features_: In the next few days, you will be able to: - * Quickly finetune an VGGNet on your own dataset - * Export VGGNet models for production - -### Table of contents -1. [About VGG](#about-vgg) -2. [Installation](#installation) -3. [Usage](#usage) - * [Load pretrained models](#loading-pretrained-models) - * [Example: Classify](#example-classification) - * [Example: Extract features](#example-feature-extraction) - * [Example: Export to ONNX](#example-export-to-onnx) - * [Example: Visual](#example-visual) -4. [Contributing](#contributing) - -### About VGG - -If you're new to VGGNets, here is an explanation straight from the official PyTorch implementation: - -In this work we investigate the effect of the convolutional network depth on its -accuracy in the large-scale image recognition setting. Our main contribution is -a thorough evaluation of networks of increasing depth using an architecture with -very small (3 × 3) convolution filters, which shows that a significant improvement -on the prior-art configurations can be achieved by pushing the depth to 16–19 -weight layers. These findings were the basis of our ImageNet Challenge 2014 -submission, where our team secured the first and the second places in the localisation and classification tracks respectively. We also show that our representations -generalise well to other datasets, where they achieve state-of-the-art results. We -have made our two best-performing ConvNet models publicly available to facilitate further research on the use of deep visual representations in computer vision. - -### Installation - -Install from pypi: -```bash -$ pip3 install vgg_pytorch -``` - -Install from source: -```bash -$ git clone https://github.com/Lornatang/VGGNet-PyTorch.git -$ cd VGGNet-PyTorch -$ pip3 install -e . -``` - -### Usage - -#### Loading pretrained models - -Load an vgg11 network: -```python -from vgg_pytorch import VGG -model = VGG.from_name("vgg11") -``` - -Load a pretrained vgg11: -```python -from vgg_pytorch import VGG -model = VGG.from_pretrained("vgg11") -``` - -Their 1-crop error rates on imagenet dataset with pretrained models are listed below. - -| Model structure | Top-1 error | Top-5 error | -| --------------- | ----------- | ----------- | -| vgg11 | 30.98 | 11.37 | -| vgg11_bn | 29.70 | 10.19 | -| vgg13 | 30.07 | 10.75 | -| vgg13_bn | 28.45 | 9.63 | -| vgg16 | 28.41 | 9.62 | -| vgg16_bn | 26.63 | 8.50 | -| vgg19 | 27.62 | 9.12 | -| vgg19_bn | 25.76 | 8.15 | - -Details about the models are below (for CIFAR10 dataset): - -| *Name* |*# Params*|*Top-1 Acc.*|*Pretrained?*| -|:-----------------:|:--------:|:----------:|:-----------:| -| `vgg11` | 132.9M | 91.1 | √ | -| `vgg13` | 133M | 92.8 | √ | -| `vgg16` | 138.4M | 92.6 | √ | -| `vgg19` | 143.7M | 92.3 | √ | -|-------------------|----------|------------|-------------| -| `vgg11_bn` | 132.9M | 92.2 | √ | -| `vgg13_bn` | 133M | 94.2 | √ | -| `vgg16_bn` | 138.4M | 93.9 | √ | -| `vgg19_bn` | 143.7M | 93.7 | √ | - - -#### Example: Classification - -We assume that in your current directory, there is a `img.jpg` file and a `labels_map.txt` file (ImageNet class names). These are both included in `examples/simple`. - -All pre-trained models expect input images normalized in the same way, -i.e. mini-batches of 3-channel RGB images of shape `(3 x H x W)`, where `H` and `W` are expected to be at least `224`. -The images have to be loaded in to a range of `[0, 1]` and then normalized using `mean = [0.485, 0.456, 0.406]` -and `std = [0.229, 0.224, 0.225]`. - -Here's a sample execution. - -```python -import json - -import torch -import torchvision.transforms as transforms -from PIL import Image - -from vgg_pytorch import VGG - -# Open image -input_image = Image.open("img.jpg") - -# Preprocess image -preprocess = transforms.Compose([ - transforms.Resize(256), - transforms.CenterCrop(224), - transforms.ToTensor(), - transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), -]) -input_tensor = preprocess(input_image) -input_batch = input_tensor.unsqueeze(0) # create a mini-batch as expected by the model - -# Load class names -labels_map = json.load(open("labels_map.txt")) -labels_map = [labels_map[str(i)] for i in range(1000)] - -# Classify with VGG11 -model = VGG.from_pretrained("vgg11") -model.eval() - -# move the input and model to GPU for speed if available -if torch.cuda.is_available(): - input_batch = input_batch.to("cuda") - model.to("cuda") - -with torch.no_grad(): - logits = model(input_batch) -preds = torch.topk(logits, k=5).indices.squeeze(0).tolist() - -print("-----") -for idx in preds: - label = labels_map[idx] - prob = torch.softmax(logits, dim=1)[0, idx].item() - print(f"{label:<75} ({prob * 100:.2f}%)") -``` - -#### Example: Feature Extraction - -You can easily extract features with `model.extract_features`: -```python -import torch -from vgg_pytorch import VGG -model = VGG.from_pretrained('vgg11') - -# ... image preprocessing as in the classification example ... -inputs = torch.randn(1, 3, 224, 224) -print(inputs.shape) # torch.Size([1, 3, 224, 224]) - -features = model.extract_features(inputs) -print(features.shape) # torch.Size([1, 512, 7, 7]) -``` - -#### Example: Export to ONNX - -Exporting to ONNX for deploying to production is now simple: -```python -import torch -from vgg_pytorch import VGG - -model = VGG.from_pretrained('vgg11') -dummy_input = torch.randn(16, 3, 224, 224) - -torch.onnx.export(model, dummy_input, "demo.onnx", verbose=True) -``` - -#### Example: Visual - -```text -cd $REPO$/framework -sh start.sh -``` - -Then open the browser and type in the browser address [http://127.0.0.1:8000/](http://127.0.0.1:8000/). - -Enjoy it. - -#### ImageNet - -See `examples/imagenet` for details about evaluating on ImageNet. - -For more datasets result. Please see `research/README.md`. - -### Contributing - -If you find a bug, create a GitHub issue, or even better, submit a pull request. Similarly, if you have questions, simply post them as GitHub issues. - -I look forward to seeing what the community does with these models! - -### Credit - -#### Very Deep Convolutional Networks for Large-Scale Image Recognition - -*Karen Simonyan, Andrew Zisserman* - -##### Abstract - -In this work we investigate the effect of the convolutional network depth on its accuracy in the -large-scale image recognition setting. Our main contribution is a thorough evaluation of networks -of increasing depth using an architecture with very small (3x3) convolution filters, which shows -that a significant improvement on the prior-art configurations can be achieved by pushing the depth -to 16-19 weight layers. These findings were the basis of our ImageNet Challenge 2014 submission, -where our team secured the first and the second places in the localisation and classification tracks -respectively. We also show that our representations generalise well to other datasets, where they -achieve state-of-the-art results. We have made our two best-performing ConvNet models publicly -available to facilitate further research on the use of deep visual representations in computer vision. - -[paper](https://arxiv.org/abs/1409.1556) - -```text -@article{VGG, -title:{Very Deep Convolutional Networks for Large-Scale Image Recognition}, -author:{Karen Simonyan, Andrew Zisserman}, -journal={iclr}, -year={2015} -} +# VGGNet-PyTorch + +### Update (Feb 14, 2020) + +The update is for ease of use and deployment. + + * [Example: Export to ONNX](#example-export-to-onnx) + * [Example: Extract features](#example-feature-extraction) + * [Example: Visual](#example-visual) + +It is also now incredibly simple to load a pretrained model with a new number of classes for transfer learning: + +```python +from vgg_pytorch import VGG +model = VGG.from_pretrained('vgg11', num_classes=10) +``` + +### Update (January 15, 2020) + +This update allows you to use NVIDIA's Apex tool for accelerated training. By default choice `hybrid training precision` + `dynamic loss amplified` version, if you need to learn more and details about `apex` tools, please visit https://github.com/NVIDIA/apex. + +### Update (January 9, 2020) + +This update adds a visual interface for testing, which is developed by pyqt5. At present, it has realized basic functions, and other functions will be gradually improved in the future. + +### Update (January 6, 2020) + +This update adds a modular neural network, making it more flexible in use. It can be deployed to many common dataset classification tasks. Of course, it can also be used in your products. + +### Overview +This repository contains an op-for-op PyTorch reimplementation of [VGGNet](https://arxiv.org/pdf/1409.1556.pdf). + +The goal of this implementation is to be simple, highly extensible, and easy to integrate into your own projects. This implementation is a work in progress -- new features are currently being implemented. + +At the moment, you can easily: + * Load pretrained VGGNet models + * Use VGGNet models for classification or feature extraction + +_Upcoming features_: In the next few days, you will be able to: + * Quickly finetune an VGGNet on your own dataset + * Export VGGNet models for production + +### Table of contents +1. [About VGG](#about-vgg) +2. [Installation](#installation) +3. [Usage](#usage) + * [Load pretrained models](#loading-pretrained-models) + * [Example: Classify](#example-classification) + * [Example: Extract features](#example-feature-extraction) + * [Example: Export to ONNX](#example-export-to-onnx) + * [Example: Visual](#example-visual) +4. [Contributing](#contributing) + +### About VGG + +If you're new to VGGNets, here is an explanation straight from the official PyTorch implementation: + +In this work we investigate the effect of the convolutional network depth on its +accuracy in the large-scale image recognition setting. Our main contribution is +a thorough evaluation of networks of increasing depth using an architecture with +very small (3 × 3) convolution filters, which shows that a significant improvement +on the prior-art configurations can be achieved by pushing the depth to 16–19 +weight layers. These findings were the basis of our ImageNet Challenge 2014 +submission, where our team secured the first and the second places in the localisation and classification tracks respectively. We also show that our representations +generalise well to other datasets, where they achieve state-of-the-art results. We +have made our two best-performing ConvNet models publicly available to facilitate further research on the use of deep visual representations in computer vision. + +### Installation + +Install from pypi: +```bash +$ pip3 install vgg_pytorch +``` + +Install from source: +```bash +$ git clone https://github.com/Lornatang/VGGNet-PyTorch.git +$ cd VGGNet-PyTorch +$ pip3 install -e . +``` + +### Usage + +#### Loading pretrained models + +Load an vgg11 network: +```python +from vgg_pytorch import VGG +model = VGG.from_name("vgg11") +``` + +Load a pretrained vgg11: +```python +from vgg_pytorch import VGG +model = VGG.from_pretrained("vgg11") +``` + +Their 1-crop error rates on imagenet dataset with pretrained models are listed below. + +| Model structure | Top-1 error | Top-5 error | +| --------------- | ----------- | ----------- | +| vgg11 | 30.98 | 11.37 | +| vgg11_bn | 29.70 | 10.19 | +| vgg13 | 30.07 | 10.75 | +| vgg13_bn | 28.45 | 9.63 | +| vgg16 | 28.41 | 9.62 | +| vgg16_bn | 26.63 | 8.50 | +| vgg19 | 27.62 | 9.12 | +| vgg19_bn | 25.76 | 8.15 | + +Details about the models are below (for CIFAR10 dataset): + +| *Name* |*# Params*|*Top-1 Acc.*|*Pretrained?*| +|:-----------------:|:--------:|:----------:|:-----------:| +| `vgg11` | 132.9M | 91.1 | √ | +| `vgg13` | 133M | 92.8 | √ | +| `vgg16` | 138.4M | 92.6 | √ | +| `vgg19` | 143.7M | 92.3 | √ | +|-------------------|----------|------------|-------------| +| `vgg11_bn` | 132.9M | 92.2 | √ | +| `vgg13_bn` | 133M | 94.2 | √ | +| `vgg16_bn` | 138.4M | 93.9 | √ | +| `vgg19_bn` | 143.7M | 93.7 | √ | + + +#### Example: Classification + +We assume that in your current directory, there is a `img.jpg` file and a `labels_map.txt` file (ImageNet class names). These are both included in `examples/simple`. + +All pre-trained models expect input images normalized in the same way, +i.e. mini-batches of 3-channel RGB images of shape `(3 x H x W)`, where `H` and `W` are expected to be at least `224`. +The images have to be loaded in to a range of `[0, 1]` and then normalized using `mean = [0.485, 0.456, 0.406]` +and `std = [0.229, 0.224, 0.225]`. + +Here's a sample execution. + +```python +import json + +import torch +import torchvision.transforms as transforms +from PIL import Image + +from vgg_pytorch import VGG + +# Open image +input_image = Image.open("img.jpg") + +# Preprocess image +preprocess = transforms.Compose([ + transforms.Resize(256), + transforms.CenterCrop(224), + transforms.ToTensor(), + transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), +]) +input_tensor = preprocess(input_image) +input_batch = input_tensor.unsqueeze(0) # create a mini-batch as expected by the model + +# Load class names +labels_map = json.load(open("labels_map.txt")) +labels_map = [labels_map[str(i)] for i in range(1000)] + +# Classify with VGG11 +model = VGG.from_pretrained("vgg11") +model.eval() + +# move the input and model to GPU for speed if available +if torch.cuda.is_available(): + input_batch = input_batch.to("cuda") + model.to("cuda") + +with torch.no_grad(): + logits = model(input_batch) +preds = torch.topk(logits, k=5).indices.squeeze(0).tolist() + +print("-----") +for idx in preds: + label = labels_map[idx] + prob = torch.softmax(logits, dim=1)[0, idx].item() + print(f"{label:<75} ({prob * 100:.2f}%)") +``` + +#### Example: Feature Extraction + +You can easily extract features with `model.extract_features`: +```python +import torch +from vgg_pytorch import VGG +model = VGG.from_pretrained('vgg11') + +# ... image preprocessing as in the classification example ... +inputs = torch.randn(1, 3, 224, 224) +print(inputs.shape) # torch.Size([1, 3, 224, 224]) + +features = model.extract_features(inputs) +print(features.shape) # torch.Size([1, 512, 7, 7]) +``` + +#### Example: Export to ONNX + +Exporting to ONNX for deploying to production is now simple: +```python +import torch +from vgg_pytorch import VGG + +model = VGG.from_pretrained('vgg11') +dummy_input = torch.randn(16, 3, 224, 224) + +torch.onnx.export(model, dummy_input, "demo.onnx", verbose=True) +``` + +#### Example: Visual + +```text +cd $REPO$/framework +sh start.sh +``` + +Then open the browser and type in the browser address [http://127.0.0.1:8000/](http://127.0.0.1:8000/). + +Enjoy it. + +#### ImageNet + +See `examples/imagenet` for details about evaluating on ImageNet. + +For more datasets result. Please see `research/README.md`. + +### Contributing + +If you find a bug, create a GitHub issue, or even better, submit a pull request. Similarly, if you have questions, simply post them as GitHub issues. + +I look forward to seeing what the community does with these models! + +### Credit + +#### Very Deep Convolutional Networks for Large-Scale Image Recognition + +*Karen Simonyan, Andrew Zisserman* + +##### Abstract + +In this work we investigate the effect of the convolutional network depth on its accuracy in the +large-scale image recognition setting. Our main contribution is a thorough evaluation of networks +of increasing depth using an architecture with very small (3x3) convolution filters, which shows +that a significant improvement on the prior-art configurations can be achieved by pushing the depth +to 16-19 weight layers. These findings were the basis of our ImageNet Challenge 2014 submission, +where our team secured the first and the second places in the localisation and classification tracks +respectively. We also show that our representations generalise well to other datasets, where they +achieve state-of-the-art results. We have made our two best-performing ConvNet models publicly +available to facilitate further research on the use of deep visual representations in computer vision. + +[paper](https://arxiv.org/abs/1409.1556) + +```text +@article{VGG, +title:{Very Deep Convolutional Networks for Large-Scale Image Recognition}, +author:{Karen Simonyan, Andrew Zisserman}, +journal={iclr}, +year={2015} +} ``` \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/LICENSE b/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/LICENSE index deeea2d8ccdb1354f351a6ea02ed456849d51422..b09cd7856d58590578ee1a4f3ad45d1310a97f87 100644 --- a/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/LICENSE +++ b/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/LICENSE @@ -1,201 +1,201 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/VGGNet_for_PyTorch/modelzoo_level.txt b/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/VGGNet_for_PyTorch/modelzoo_level.txt index 5afcef9188bf9d39f1e34b45bd91324c6093137a..3117fffc3be7f5c479f10f09ba38a25c47739a00 100644 --- a/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/VGGNet_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/VGGNet_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/VGGNet_for_PyTorch/requirements.txt b/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/VGGNet_for_PyTorch/requirements.txt index 420b1d1f4aac66daaa4f127fb4954bf98af238d6..a9df0d18fc5856758e7a4736738fc8a7415b484c 100644 --- a/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/VGGNet_for_PyTorch/requirements.txt +++ b/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/VGGNet_for_PyTorch/requirements.txt @@ -1,16 +1,16 @@ -# progress bars in model download and training scripts -tqdm -# Accessing files from S3 directly. -boto3 -# Used for downloading models over HTTP -requests -six -ipdb -#Data processing -h5py -html2text -nltk -progressbar -#Others -onnxruntime +# progress bars in model download and training scripts +tqdm +# Accessing files from S3 directly. +boto3 +# Used for downloading models over HTTP +requests +six +ipdb +#Data processing +h5py +html2text +nltk +progressbar +#Others +onnxruntime git+https://github.com/NVIDIA/dllogger \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/VGGNet_for_PyTorch/test/train_performance_1p.sh b/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/VGGNet_for_PyTorch/test/train_performance_1p.sh index a75708d7e2ee83ef84d0a0a3fa3b51d4bfae6958..58a96bba3198252a5907e92ab575c019e317de3d 100644 --- a/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/VGGNet_for_PyTorch/test/train_performance_1p.sh +++ b/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/VGGNet_for_PyTorch/test/train_performance_1p.sh @@ -1,166 +1,166 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` - -#集合通信参数,不需要修改 - -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 - - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -export ASCEND_GLOBAL_LOG_LEVEL=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="VGGNet_ID0400_for_PyTorch" -#训练epoch -epoch=2 -#训练batch_size -RANK_SIZE=1 -batch_size=64 -#迭代数iteration -iteration=100 -#训练step -#train_steps=1000 -#学习率 -#learning_rate=3.96 - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_1p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --autotune whether to enable autotune, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --autotune* ]];then - autotune=`echo ${para#*=}` - #开autotune特有环境变量 - autotune=True - export autotune=True - export REPEAT_TUNE=True - export ASCEND_DEVICE_ID=0 - export ENABLE_TUNE_BANK=True - export TE_PARALLEL_COMPILER=32 - mv $install_path/fwkacllib/data/rl/Ascend910/custom $install_path/fwkacllib/data/rl/Ascend910/custom_bak - mv $install_path/fwkacllib/data/tiling/Ascend910/custom $install_path/fwkacllib/data/tiling/Ascend910/custom_bak - autotune_dump_path=${cur_path}/output/autotune_dump - mkdir -p ${autotune_dump_path}/GA - mkdir -p ${autotune_dump_path}/rl - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path/../examples/simple/ -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - export DEVICE_ID=$RANK_ID - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - nohup python3 test.py \ - > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -done -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -grep "Training //" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log > traintime.log -sed -i '1d' traintime.log -traintime=`cat traintime.log | grep "Training //" | awk '{sum+=$13} END {print sum/NR}'` - -#traintime=`grep "Training //" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk 'END {print $13}'` -TrainingTime=`echo "scale=3;${traintime} / 1000"|bc |awk '{printf "%0.3f",$0}'` - -ActualFPS=`echo "scale=2;${batch_size} / ${TrainingTime}"|bc` - -echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -#ActualLoss=`grep "loss =" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log| awk 'END {print $6}' |tr -d ,` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -#echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -#echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -#echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` + +#集合通信参数,不需要修改 + +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 + + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +export ASCEND_GLOBAL_LOG_LEVEL=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="VGGNet_ID0400_for_PyTorch" +#训练epoch +epoch=2 +#训练batch_size +RANK_SIZE=1 +batch_size=64 +#迭代数iteration +iteration=100 +#训练step +#train_steps=1000 +#学习率 +#learning_rate=3.96 + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_1p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --autotune whether to enable autotune, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --autotune* ]];then + autotune=`echo ${para#*=}` + #开autotune特有环境变量 + autotune=True + export autotune=True + export REPEAT_TUNE=True + export ASCEND_DEVICE_ID=0 + export ENABLE_TUNE_BANK=True + export TE_PARALLEL_COMPILER=32 + mv $install_path/fwkacllib/data/rl/Ascend910/custom $install_path/fwkacllib/data/rl/Ascend910/custom_bak + mv $install_path/fwkacllib/data/tiling/Ascend910/custom $install_path/fwkacllib/data/tiling/Ascend910/custom_bak + autotune_dump_path=${cur_path}/output/autotune_dump + mkdir -p ${autotune_dump_path}/GA + mkdir -p ${autotune_dump_path}/rl + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path/../examples/simple/ +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + export DEVICE_ID=$RANK_ID + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + nohup python3 test.py \ + > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +done +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +grep "Training //" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log > traintime.log +sed -i '1d' traintime.log +traintime=`cat traintime.log | grep "Training //" | awk '{sum+=$13} END {print sum/NR}'` + +#traintime=`grep "Training //" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk 'END {print $13}'` +TrainingTime=`echo "scale=3;${traintime} / 1000"|bc |awk '{printf "%0.3f",$0}'` + +ActualFPS=`echo "scale=2;${batch_size} / ${TrainingTime}"|bc` + +echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +#ActualLoss=`grep "loss =" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log| awk 'END {print $6}' |tr -d ,` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/modelzoo_level.txt b/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/modelzoo_level.txt index 5afcef9188bf9d39f1e34b45bd91324c6093137a..3117fffc3be7f5c479f10f09ba38a25c47739a00 100644 --- a/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/modelzoo_level.txt +++ b/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:POK \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/requirements.txt b/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/requirements.txt index 420b1d1f4aac66daaa4f127fb4954bf98af238d6..a9df0d18fc5856758e7a4736738fc8a7415b484c 100644 --- a/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/requirements.txt +++ b/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch/requirements.txt @@ -1,16 +1,16 @@ -# progress bars in model download and training scripts -tqdm -# Accessing files from S3 directly. -boto3 -# Used for downloading models over HTTP -requests -six -ipdb -#Data processing -h5py -html2text -nltk -progressbar -#Others -onnxruntime +# progress bars in model download and training scripts +tqdm +# Accessing files from S3 directly. +boto3 +# Used for downloading models over HTTP +requests +six +ipdb +#Data processing +h5py +html2text +nltk +progressbar +#Others +onnxruntime git+https://github.com/NVIDIA/dllogger \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/mBART_ID1550_for_PyTorch/modelzoo_level.txt b/PyTorch/dev/cv/image_classification/mBART_ID1550_for_PyTorch/modelzoo_level.txt index a17c8f95fa388fbc6d253e2cd7cfd0b73b734073..a829ab59b97a1022dd6fc33b59b7ae0d55009432 100644 --- a/PyTorch/dev/cv/image_classification/mBART_ID1550_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/dev/cv/image_classification/mBART_ID1550_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:NOK +FuncStatus:OK +PerfStatus:NOK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/dev/cv/image_classification/vit-base_ID0492_for_PyTorch/test/train_full_8p.sh b/PyTorch/dev/cv/image_classification/vit-base_ID0492_for_PyTorch/test/train_full_8p.sh index 8b5edcbaa7c7840fb2adfa18a130e68f9c0b546a..053b27b30d58db6900654d457f600d6a77c5050f 100644 --- a/PyTorch/dev/cv/image_classification/vit-base_ID0492_for_PyTorch/test/train_full_8p.sh +++ b/PyTorch/dev/cv/image_classification/vit-base_ID0492_for_PyTorch/test/train_full_8p.sh @@ -1,230 +1,230 @@ -#!/bin/bash - -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 - -#当前路径,不需要修改 -cur_path=`pwd` - -#集合通信参数,不需要修改 - -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 - - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="vit-base_ID0492_for_PyTorch" -#训练epoch -train_epochs=10000 -#训练batch_size -batch_size=64 -#训练step -train_steps= -#学习率 -learning_rate=0.1 - -#TF2.X独有,需要模型审视修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -PREC="" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_performance_1P.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(O0/O1/O2/O3) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - apex_opt_level=`echo ${para#*=}` - if [[ $apex_opt_level != "O1" ]] && [[ $apex_opt_level != "O2" ]] && [[ $apex_opt_level != "O3" ]]; then - echo "[Error] para \"precision_mode\" must be config O1 or O2 or O3" - exit 1 - fi - PREC="--apex --apex-opt-level "$apex_opt_level - elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --ckpt_path* ]];then - ckpt_path=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path - -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - # 绑核,不需要的绑核的模型删除,需要的模型审视修改 - #let a=RANK_ID*12 - #let b=RANK_ID+1 - #let c=b*12-1 - - #网络特有 拷贝预训练模型到root路径下 - if [ -d /root/.cache/torch/checkpoints/ ];then - echo "File_path exist" - else - mkdir -p /root/.cache/torch/checkpoints/ - fi - cp ${data_path}/mobilenet_v2-b0353104.pth /root/.cache/torch/checkpoints/ - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path - #python3 $cur_path/../train.py \ - #--name cifar10-100_500 \ - #--dataset cifar10 \ - #--model_type ViT-B_16 \ - #--pretrained_dir ${ckpt_path}/ViT-B_16.npz \ - #--addr=127.0.0.1 \ - #--train_batch_size=64 \ - #--num_steps=10000 \ - #--npu-fused-sgd \ - #--fp16 \ - #--data_dir ${data_path} \ - #--fp16_opt_level O2 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -done -wait - -export MASTER_ADDR=localhost -export MASTER_PORT=29688 -export HCCL_WHITELIST_DISABLE=1 - -NPUS=($(seq 0 7)) -export NPU_WORLD_SIZE=${#NPUS[@]} -rank=0 -for i in ${NPUS[@]} -do - mkdir -p $cur_path/output/${i}/ - export NPU_CALCULATE_DEVICE=${i} - export ASCEND_DEVICE_ID=${i} - export RANK=${rank} - echo run process ${rank} - python3 $cur_path/../train.py \ - --name cifar10-100_500 \ - --dataset cifar10 \ - --model_type ViT-B_16 \ - --pretrained_dir ${ckpt_path}/ViT-B_16.npz \ - --addr=127.0.0.1 \ - --train_batch_size=64 \ - --num_steps=1000 \ - --npu-fused-sgd \ - --fp16 \ - --learning_rate 0.24 \ - --data_dir ${data_path} \ - --ddp True \ - --fp16_opt_level O2 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${i}.log 2>&1 & - let rank++ -done -wait - - - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -sed -i "s|\r|\n|g" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "FPS=" '{print$2}' | awk -F ")" '{print$1}' |tail -n +5 |awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` -FPS=$(awk 'BEGIN{print '$FPS'*8}') -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep "Prec@5:" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F ":" 'END {print $8}'|cut -c 1-6` -train_accuracy=`grep -a "Best Accuracy:" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk '{print$NF}'` - -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -#echo "Final Train Accuracy(top5) : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${ActualFPS}'}'` - - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -#grep "Training" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk '{print$2,$6}'|awk -F "(" '{print$2,$3}'|sort -k 1,1 -u -n |awk -F '=' '{print$2}'|awk -F ')' '{print$1}'|awk '{if(length !=0) print $0}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt -grep "Steps" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v X |awk -F "loss=" '{print$2}' | awk -F ")" '{print$1}'|sed '/^$/d' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 + +#当前路径,不需要修改 +cur_path=`pwd` + +#集合通信参数,不需要修改 + +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 + + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="vit-base_ID0492_for_PyTorch" +#训练epoch +train_epochs=10000 +#训练batch_size +batch_size=64 +#训练step +train_steps= +#学习率 +learning_rate=0.1 + +#TF2.X独有,需要模型审视修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +PREC="" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_performance_1P.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(O0/O1/O2/O3) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + apex_opt_level=`echo ${para#*=}` + if [[ $apex_opt_level != "O1" ]] && [[ $apex_opt_level != "O2" ]] && [[ $apex_opt_level != "O3" ]]; then + echo "[Error] para \"precision_mode\" must be config O1 or O2 or O3" + exit 1 + fi + PREC="--apex --apex-opt-level "$apex_opt_level + elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --ckpt_path* ]];then + ckpt_path=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path + +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + # 绑核,不需要的绑核的模型删除,需要的模型审视修改 + #let a=RANK_ID*12 + #let b=RANK_ID+1 + #let c=b*12-1 + + #网络特有 拷贝预训练模型到root路径下 + if [ -d /root/.cache/torch/checkpoints/ ];then + echo "File_path exist" + else + mkdir -p /root/.cache/torch/checkpoints/ + fi + cp ${data_path}/mobilenet_v2-b0353104.pth /root/.cache/torch/checkpoints/ + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + #--data_dir, --model_dir, --precision_mode, --over_dump, --over_dump_path,--data_dump_flag,--data_dump_step,--data_dump_path,--profiling,--profiling_dump_path + #python3 $cur_path/../train.py \ + #--name cifar10-100_500 \ + #--dataset cifar10 \ + #--model_type ViT-B_16 \ + #--pretrained_dir ${ckpt_path}/ViT-B_16.npz \ + #--addr=127.0.0.1 \ + #--train_batch_size=64 \ + #--num_steps=10000 \ + #--npu-fused-sgd \ + #--fp16 \ + #--data_dir ${data_path} \ + #--fp16_opt_level O2 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +done +wait + +export MASTER_ADDR=localhost +export MASTER_PORT=29688 +export HCCL_WHITELIST_DISABLE=1 + +NPUS=($(seq 0 7)) +export NPU_WORLD_SIZE=${#NPUS[@]} +rank=0 +for i in ${NPUS[@]} +do + mkdir -p $cur_path/output/${i}/ + export NPU_CALCULATE_DEVICE=${i} + export ASCEND_DEVICE_ID=${i} + export RANK=${rank} + echo run process ${rank} + python3 $cur_path/../train.py \ + --name cifar10-100_500 \ + --dataset cifar10 \ + --model_type ViT-B_16 \ + --pretrained_dir ${ckpt_path}/ViT-B_16.npz \ + --addr=127.0.0.1 \ + --train_batch_size=64 \ + --num_steps=1000 \ + --npu-fused-sgd \ + --fp16 \ + --learning_rate 0.24 \ + --data_dir ${data_path} \ + --ddp True \ + --fp16_opt_level O2 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${i}.log 2>&1 & + let rank++ +done +wait + + + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +sed -i "s|\r|\n|g" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "FPS=" '{print$2}' | awk -F ")" '{print$1}' |tail -n +5 |awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` +FPS=$(awk 'BEGIN{print '$FPS'*8}') +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep "Prec@5:" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F ":" 'END {print $8}'|cut -c 1-6` +train_accuracy=`grep -a "Best Accuracy:" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk '{print$NF}'` + +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +#echo "Final Train Accuracy(top5) : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${ActualFPS}'}'` + + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +#grep "Training" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk '{print$2,$6}'|awk -F "(" '{print$2,$3}'|sort -k 1,1 -u -n |awk -F '=' '{print$2}'|awk -F ')' '{print$1}'|awk '{if(length !=0) print $0}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +grep "Steps" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v X |awk -F "loss=" '{print$2}' | awk -F ")" '{print$1}'|sed '/^$/d' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/PyTorch/dev/cv/image_classification/vit-base_ID0492_for_PyTorch/test/train_performance_8p.sh b/PyTorch/dev/cv/image_classification/vit-base_ID0492_for_PyTorch/test/train_performance_8p.sh index 417f5471895b94c6d2bb6b5639664b28983dd774..c7fa78bc46ce9bc10570896f407e61e5d66f7680 100644 --- a/PyTorch/dev/cv/image_classification/vit-base_ID0492_for_PyTorch/test/train_performance_8p.sh +++ b/PyTorch/dev/cv/image_classification/vit-base_ID0492_for_PyTorch/test/train_performance_8p.sh @@ -1,184 +1,184 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` - -#集合通信参数,不需要修改 - -export RANK_SIZE=8 -export JOB_ID=10087 -RANK_ID_START=0 - -RANK_SIZE=8 -# 数据集路径,保持为空,不需要修改 -data_path="" - -#设置默认日志级别,不需要修改 -export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="vit-base_ID0492_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=64 -#训练step -train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.1 - -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False - - -if [[ $1 == --help || $1 == --h ]];then - echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" - exit 1 -fi - -for para in $* -do - if [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --ckpt_path* ]];then - ckpt_path=`echo ${para#*=}` - elif [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` - elif [[ $para == --batch_size* ]];then - batch_size=`echo ${para#*=}` - elif [[ $para == --learning_rate* ]];then - learning_rate=`echo ${para#*=}` - fi -done - -PREC="" -if [[ $precision_mode == "amp" ]];then - PREC="--apex" -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -cd $cur_path -#设置环境变量,不需要修改 -echo "Device ID: $ASCEND_DEVICE_ID" -export RANK_ID=$RANK_ID - -if [ -d $cur_path/output ];then - rm -rf $cur_path/output/* - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -else - mkdir -p $cur_path/output/$ASCEND_DEVICE_ID -fi -wait - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#nohup python3 $cur_path/../train.py \ -# --name cifar10-100_500 \ -# --dataset cifar10 \ -# --model_type ViT-B_16 \ -# --pretrained_dir ${ckpt_path}/ViT-B_16.npz \ -# --addr=127.0.0.1 \ -# --train_batch_size=64 \ -# --num_steps=100 \ -# --npu-fused-sgd \ -# --fp16 \ -# --data_dir ${data_path} \ -# --fp16_opt_level O2 > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & - - - - - - -export MASTER_ADDR=localhost -export MASTER_PORT=29688 -export HCCL_WHITELIST_DISABLE=1 - -NPUS=($(seq 0 7)) -export NPU_WORLD_SIZE=${#NPUS[@]} -rank=0 -for i in ${NPUS[@]} -do - mkdir -p $cur_path/output/${i}/ - export NPU_CALCULATE_DEVICE=${i} - export ASCEND_DEVICE_ID=${i} - export RANK=${rank} - echo run process ${rank} - python3 $cur_path/../train.py \ - --name cifar10-100_500 \ - --dataset cifar10 \ - --model_type ViT-B_16 \ - --pretrained_dir ${ckpt_path}/ViT-B_16.npz \ - --addr=127.0.0.1 \ - --train_batch_size=64 \ - --num_steps=100 \ - --npu-fused-sgd \ - --fp16 \ - --ddp True \ - --data_dir ${data_path} \ - --fp16_opt_level O2 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${i}.log 2>&1 & - let rank++ -done -wait - -wait - -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -sed -i "s|\r|\n|g" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -FPS=`grep FPS $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "FPS=" '{print$2}' | awk -F ")" '{print$1}' |tail -n +5 |awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` -FPS=$(awk 'BEGIN{print '$FPS'*8}') -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -train_accuracy=`grep -a "Best Accuracy:" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk '{print $3}'| awk '{print$NF}'` - -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#性能看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据,不需要修改 -#吞吐量 -ActualFPS=${FPS} -#单迭代训练时长 -TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -#grep /781 $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "loss=" '{print$2}' | awk -F ")" '{print$1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt -grep "Steps" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v X |awk -F "loss=" '{print$2}' | awk -F ")" '{print$1}'|sed '/^$/d' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -sed -i "s/ModuleNotFoundError: No module named "impl.lp_norm_reduce"/ /g" `grep ModuleNotFoundError -rl $cur_path/output/$ASCEND_DEVICE_ID/train_*.log` +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` + +#集合通信参数,不需要修改 + +export RANK_SIZE=8 +export JOB_ID=10087 +RANK_ID_START=0 + +RANK_SIZE=8 +# 数据集路径,保持为空,不需要修改 +data_path="" + +#设置默认日志级别,不需要修改 +export ASCEND_GLOBAL_LOG_LEVEL_ETP=3 + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="vit-base_ID0492_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=64 +#训练step +train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.1 + +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False + + +if [[ $1 == --help || $1 == --h ]];then + echo "usage:./train_performance_1p.sh --data_path=data_dir --batch_size=1024 --learning_rate=0.04" + exit 1 +fi + +for para in $* +do + if [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --ckpt_path* ]];then + ckpt_path=`echo ${para#*=}` + elif [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` + elif [[ $para == --batch_size* ]];then + batch_size=`echo ${para#*=}` + elif [[ $para == --learning_rate* ]];then + learning_rate=`echo ${para#*=}` + fi +done + +PREC="" +if [[ $precision_mode == "amp" ]];then + PREC="--apex" +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +cd $cur_path +#设置环境变量,不需要修改 +echo "Device ID: $ASCEND_DEVICE_ID" +export RANK_ID=$RANK_ID + +if [ -d $cur_path/output ];then + rm -rf $cur_path/output/* + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +else + mkdir -p $cur_path/output/$ASCEND_DEVICE_ID +fi +wait + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#nohup python3 $cur_path/../train.py \ +# --name cifar10-100_500 \ +# --dataset cifar10 \ +# --model_type ViT-B_16 \ +# --pretrained_dir ${ckpt_path}/ViT-B_16.npz \ +# --addr=127.0.0.1 \ +# --train_batch_size=64 \ +# --num_steps=100 \ +# --npu-fused-sgd \ +# --fp16 \ +# --data_dir ${data_path} \ +# --fp16_opt_level O2 > $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log 2>&1 & + + + + + + +export MASTER_ADDR=localhost +export MASTER_PORT=29688 +export HCCL_WHITELIST_DISABLE=1 + +NPUS=($(seq 0 7)) +export NPU_WORLD_SIZE=${#NPUS[@]} +rank=0 +for i in ${NPUS[@]} +do + mkdir -p $cur_path/output/${i}/ + export NPU_CALCULATE_DEVICE=${i} + export ASCEND_DEVICE_ID=${i} + export RANK=${rank} + echo run process ${rank} + python3 $cur_path/../train.py \ + --name cifar10-100_500 \ + --dataset cifar10 \ + --model_type ViT-B_16 \ + --pretrained_dir ${ckpt_path}/ViT-B_16.npz \ + --addr=127.0.0.1 \ + --train_batch_size=64 \ + --num_steps=100 \ + --npu-fused-sgd \ + --fp16 \ + --ddp True \ + --data_dir ${data_path} \ + --fp16_opt_level O2 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${i}.log 2>&1 & + let rank++ +done +wait + +wait + +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +sed -i "s|\r|\n|g" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +FPS=`grep FPS $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "FPS=" '{print$2}' | awk -F ")" '{print$1}' |tail -n +5 |awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` +FPS=$(awk 'BEGIN{print '$FPS'*8}') +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +train_accuracy=`grep -a "Best Accuracy:" $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk '{print $3}'| awk '{print$NF}'` + +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#性能看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据,不需要修改 +#吞吐量 +ActualFPS=${FPS} +#单迭代训练时长 +TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +#grep /781 $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "loss=" '{print$2}' | awk -F ")" '{print$1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +grep "Steps" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v X |awk -F "loss=" '{print$2}' | awk -F ")" '{print$1}'|sed '/^$/d' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +sed -i "s/ModuleNotFoundError: No module named "impl.lp_norm_reduce"/ /g" `grep ModuleNotFoundError -rl $cur_path/output/$ASCEND_DEVICE_ID/train_*.log` diff --git a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/Dockerfile b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/Dockerfile index 49cbba285f5f05e1af2d734fc9a01bfc5288b0d8..d7deb4196beeb755e9ed5bf77d80a24af2c69365 100644 --- a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/Dockerfile +++ b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/Dockerfile @@ -1,5 +1,5 @@ -ARG FROM_IMAGE_NAME=ascend-pytorch-arm:20.1.0 -FROM ${FROM_IMAGE_NAME} - -COPY requirements.txt . +ARG FROM_IMAGE_NAME=ascend-pytorch-arm:20.1.0 +FROM ${FROM_IMAGE_NAME} + +COPY requirements.txt . RUN pip3.7 install -r requirements.txt \ No newline at end of file diff --git a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/LICENSE b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/LICENSE index 6c4f543d1529bd48135a0be11f3d79592b5f8219..56cd05a13bf21d1cdb2b4deac546f38d4009d5ff 100644 --- a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/LICENSE +++ b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/LICENSE @@ -1,23 +1,23 @@ -MIT License - -Copyright (c) 2019 Microsoft Corporation -Copyright (c) 2017 Jieru Mei meijieru@gmail.com -Copyright 2020 Huawei Technologies Co., Ltd - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +MIT License + +Copyright (c) 2019 Microsoft Corporation +Copyright (c) 2017 Jieru Mei meijieru@gmail.com +Copyright 2020 Huawei Technologies Co., Ltd + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/README.md b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/README.md index 913d6916c8790926d161357e9926200962ba2518..d04156bd7bd70ac487e247c9c4dd2dc0ef940997 100644 --- a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/README.md +++ b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/README.md @@ -1,25 +1,25 @@ -环境 ----------- - pytorch 1.5 - torchvision 0.5.0 - apex 0.1 - numpy - Pillow 8.1.0 - -Host侧训练步骤 ----------- -1.准备数据集
-2.修改run1p.sh,设置训练参数。device_id是用哪张卡,train_data_path是训练网络输入数据,label_data_path是label数据,lr是学习率,model_save_dir是模型保存目录,epoch是训练多少epoch,batch_size是batchsize
-3.执行bash run1p.sh开启单p训练
- - -Docker侧训练步骤 ----------- - -1.导入镜像二进制包docker import ubuntuarmpytorch.tar REPOSITORY:TAG, 比如: - - docker import ubuntuarmpytorch.tar pytorch:b020 - -2.执行docker_start.sh后带三个参数:步骤1生成的REPOSITORY:TAG;数据集路径(训练和评测数据集都放到该路径下);模型执行路径;比如: - - ./docker_start.sh pytorch:b020 /train/imagenet /home/CRNN_for_Pytorch +环境 +---------- + pytorch 1.5 + torchvision 0.5.0 + apex 0.1 + numpy + Pillow 8.1.0 + +Host侧训练步骤 +---------- +1.准备数据集
+2.修改run1p.sh,设置训练参数。device_id是用哪张卡,train_data_path是训练网络输入数据,label_data_path是label数据,lr是学习率,model_save_dir是模型保存目录,epoch是训练多少epoch,batch_size是batchsize
+3.执行bash run1p.sh开启单p训练
+ + +Docker侧训练步骤 +---------- + +1.导入镜像二进制包docker import ubuntuarmpytorch.tar REPOSITORY:TAG, 比如: + + docker import ubuntuarmpytorch.tar pytorch:b020 + +2.执行docker_start.sh后带三个参数:步骤1生成的REPOSITORY:TAG;数据集路径(训练和评测数据集都放到该路径下);模型执行路径;比如: + + ./docker_start.sh pytorch:b020 /train/imagenet /home/CRNN_for_Pytorch diff --git a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/docker_start.sh b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/docker_start.sh index 46ce9a02ec0532d6db324beaee7f7eab501b4565..944bca3cdac8e3f2d47ceb0e2b6eb181a405de11 100644 --- a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/docker_start.sh +++ b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/docker_start.sh @@ -1,25 +1,25 @@ -#!/bin/bash - -docker_image=$1 -data_dir=$2 -model_dir=$3 - -docker run -it --ipc=host \ - --device=/dev/davinci0 \ - --device=/dev/davinci1 \ - --device=/dev/davinci2 \ - --device=/dev/davinci3 \ - --device=/dev/davinci4 \ - --device=/dev/davinci5 \ - --device=/dev/davinci6 \ - --device=/dev/davinci7 \ - --device=/dev/davinci_manager \ - --device=/dev/devmm_svm --device=/dev/hisi_hdc \ - -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ - -v /usr/local/Ascend/add-ons/:/usr/local/Ascend/add-ons/ \ - -v ${model_dir}:${model_dir} \ - -v ${data_dir}:${data_dir} \ - -v /var/log/npu/conf/slog/slog.conf:/var/log/npu/conf/slog/slog.conf \ - -v /var/log/npu/slog/:/var/log/npu/slog -v /var/log/npu/profiling/:/var/log/npu/profiling \ - -v /var/log/npu/dump/:/var/log/npu/dump -v /var/log/npu/:/usr/slog ${docker_image} \ +#!/bin/bash + +docker_image=$1 +data_dir=$2 +model_dir=$3 + +docker run -it --ipc=host \ + --device=/dev/davinci0 \ + --device=/dev/davinci1 \ + --device=/dev/davinci2 \ + --device=/dev/davinci3 \ + --device=/dev/davinci4 \ + --device=/dev/davinci5 \ + --device=/dev/davinci6 \ + --device=/dev/davinci7 \ + --device=/dev/davinci_manager \ + --device=/dev/devmm_svm --device=/dev/hisi_hdc \ + -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ + -v /usr/local/Ascend/add-ons/:/usr/local/Ascend/add-ons/ \ + -v ${model_dir}:${model_dir} \ + -v ${data_dir}:${data_dir} \ + -v /var/log/npu/conf/slog/slog.conf:/var/log/npu/conf/slog/slog.conf \ + -v /var/log/npu/slog/:/var/log/npu/slog -v /var/log/npu/profiling/:/var/log/npu/profiling \ + -v /var/log/npu/dump/:/var/log/npu/dump -v /var/log/npu/:/usr/slog ${docker_image} \ /bin/bash \ No newline at end of file diff --git a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/dscnn_train_pytorch.py b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/dscnn_train_pytorch.py index 2ee8d5ca873cd0e9aceaafb7e3a4dd1e1df491cd..d825d0c0657bc46695ccae2e6738af0f0ea96113 100644 --- a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/dscnn_train_pytorch.py +++ b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/dscnn_train_pytorch.py @@ -1,139 +1,139 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the MIT License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/MIT -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import argparse - -import numpy as np -import torch -from torch.autograd import Variable -from torch.utils.data import DataLoader -import random -import torch.nn as nn -import torch.nn.functional as F - -from PIL import Image -import torch.npu - - -class DataLoad(): - def __init__(self, src_data_root, label_path): - self.images_list = [] - self.label_list = [] - self.num = 0 - - for img_name in os.listdir(src_data_root): - if img_name.endswith(".png"): - src_img_path = os.path.join(src_data_root, img_name) - label_img_path = os.path.join(label_path, img_name) - assert os.path.exists(label_img_path) - self.images_list.append([src_img_path]) - self.label_list.append([label_img_path]) - self.num += 1 - print('train image num: ', self.num) - - def __getitem__(self, index): - - src_image = Image.open(self.images_list[index][0]) - src_image = np.asarray(src_image).astype(np.float32) / 255. - label_image = Image.open(self.label_list[index][0]) - label_image = np.asarray(label_image).astype(np.float32) / 255. - - - src_image = torch.from_numpy(src_image.transpose(2, 0, 1)) - label_image = torch.from_numpy(label_image.transpose(2, 0, 1)) - - return src_image, label_image - - def __len__(self): - return self.num - - -class downsample_net(nn.Module): - def __init__(self): - super(downsample_net, self).__init__() - - self.conv1 = nn.Conv2d(3, 16, 3, 2, 1) - self.conv2 = nn.Conv2d(16, 3, 3, 1, 1) - self.relu = nn.ReLU() - - - def forward(self, x): - x = self.relu(self.conv1(x)) - return self.conv2(x) - - - -def train(src_data_root, label_path, batch_size, model_dir, epoch, lr, device, model_path=None): - dn = downsample_net() - dn = dn.to(device) - - if model_path is not None: - dn.load_state_dict(torch.load(model_path)) - - l1loss = torch.nn.L1Loss().to(device) - - opt = torch.optim.Adam(dn.parameters(), lr=lr) - - dataset = DataLoad(src_data_root, label_path) - train_loader = DataLoader(dataset=dataset, - batch_size=batch_size, - shuffle=True, - num_workers=16) - - all_loss = [] - for ep in range(epoch): - for step, (sample, label) in enumerate(train_loader): - src_image = Variable(sample).to(device) - label_image = Variable(label).to(device) - out = dn(src_image) - - out = nn.functional.interpolate(out, size=[1080, 1920], mode="bilinear") - loss = l1loss(out, label_image) - opt.zero_grad() - loss.backward() - opt.step() - - if step % 50 == 0: - print("epoch {} step {} loss {}".format(ep, step, loss.detach())) - - - - model_path = os.path.join(model_dir, "DSCNN_pytorch_l1_" + str(ep) + ".pkl") - torch.save(dn.state_dict(), model_path) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--device_id', type=int, default=0) - parser.add_argument('--train_data_path', type=str, default='') - parser.add_argument('--label_data_path', type=str, default='') - parser.add_argument('--batch_size', type=int, default=4) - parser.add_argument('--epoch', type=int, default=60) - parser.add_argument('--lr', type=float, default=0.00001) - parser.add_argument('--model_save_dir', type=str, default='') - parser.add_argument('--pre_trained_model_path', type=str, default=None) - args = parser.parse_args() - - device_str = 'npu:' + str(args.device_id) - torch.npu.set_device(device_str) - - train(device=device_str, - src_data_root=args.train_data_path, - batch_size=args.batch_size, - model_dir=args.model_save_dir, - label_path=args.label_data_path, - model_path=args.pre_trained_model_path, - epoch=args.epoch, - lr=args.lr) +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the MIT License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/MIT +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import argparse + +import numpy as np +import torch +from torch.autograd import Variable +from torch.utils.data import DataLoader +import random +import torch.nn as nn +import torch.nn.functional as F + +from PIL import Image +import torch.npu + + +class DataLoad(): + def __init__(self, src_data_root, label_path): + self.images_list = [] + self.label_list = [] + self.num = 0 + + for img_name in os.listdir(src_data_root): + if img_name.endswith(".png"): + src_img_path = os.path.join(src_data_root, img_name) + label_img_path = os.path.join(label_path, img_name) + assert os.path.exists(label_img_path) + self.images_list.append([src_img_path]) + self.label_list.append([label_img_path]) + self.num += 1 + print('train image num: ', self.num) + + def __getitem__(self, index): + + src_image = Image.open(self.images_list[index][0]) + src_image = np.asarray(src_image).astype(np.float32) / 255. + label_image = Image.open(self.label_list[index][0]) + label_image = np.asarray(label_image).astype(np.float32) / 255. + + + src_image = torch.from_numpy(src_image.transpose(2, 0, 1)) + label_image = torch.from_numpy(label_image.transpose(2, 0, 1)) + + return src_image, label_image + + def __len__(self): + return self.num + + +class downsample_net(nn.Module): + def __init__(self): + super(downsample_net, self).__init__() + + self.conv1 = nn.Conv2d(3, 16, 3, 2, 1) + self.conv2 = nn.Conv2d(16, 3, 3, 1, 1) + self.relu = nn.ReLU() + + + def forward(self, x): + x = self.relu(self.conv1(x)) + return self.conv2(x) + + + +def train(src_data_root, label_path, batch_size, model_dir, epoch, lr, device, model_path=None): + dn = downsample_net() + dn = dn.to(device) + + if model_path is not None: + dn.load_state_dict(torch.load(model_path)) + + l1loss = torch.nn.L1Loss().to(device) + + opt = torch.optim.Adam(dn.parameters(), lr=lr) + + dataset = DataLoad(src_data_root, label_path) + train_loader = DataLoader(dataset=dataset, + batch_size=batch_size, + shuffle=True, + num_workers=16) + + all_loss = [] + for ep in range(epoch): + for step, (sample, label) in enumerate(train_loader): + src_image = Variable(sample).to(device) + label_image = Variable(label).to(device) + out = dn(src_image) + + out = nn.functional.interpolate(out, size=[1080, 1920], mode="bilinear") + loss = l1loss(out, label_image) + opt.zero_grad() + loss.backward() + opt.step() + + if step % 50 == 0: + print("epoch {} step {} loss {}".format(ep, step, loss.detach())) + + + + model_path = os.path.join(model_dir, "DSCNN_pytorch_l1_" + str(ep) + ".pkl") + torch.save(dn.state_dict(), model_path) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--device_id', type=int, default=0) + parser.add_argument('--train_data_path', type=str, default='') + parser.add_argument('--label_data_path', type=str, default='') + parser.add_argument('--batch_size', type=int, default=4) + parser.add_argument('--epoch', type=int, default=60) + parser.add_argument('--lr', type=float, default=0.00001) + parser.add_argument('--model_save_dir', type=str, default='') + parser.add_argument('--pre_trained_model_path', type=str, default=None) + args = parser.parse_args() + + device_str = 'npu:' + str(args.device_id) + torch.npu.set_device(device_str) + + train(device=device_str, + src_data_root=args.train_data_path, + batch_size=args.batch_size, + model_dir=args.model_save_dir, + label_path=args.label_data_path, + model_path=args.pre_trained_model_path, + epoch=args.epoch, + lr=args.lr) diff --git a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/npu_set_env.sh b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/npu_set_env.sh index bf52cfcb774356cfd97a4d9244352cc44e4bcaf0..cda0d6f857fecc2a7168498062c7e1275abee6a7 100644 --- a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/npu_set_env.sh +++ b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/npu_set_env.sh @@ -1,30 +1,30 @@ -############## toolkit situation ################ -#export LD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/:/usr/local/Ascend/driver/lib64/common/:/usr/local/Ascend/driver/lib64/driver/:/usr/local/Ascend/add-ons/:/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH -#export PATH=$PATH:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin/:/usr/local/Ascend/ascend-toolkit/latest/toolkit/tools/ide_daemon/bin/ -#export ASCEND_OPP_PATH=/usr/local/Ascend/ascend-toolkit/latest/opp/ -#export OPTION_EXEC_EXTERN_PLUGIN_PATH=/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so -#export PYTHONPATH=/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH - - -############## nnae situation ################ - - -if [ -d /usr/local/Ascend/nnae/latest ];then - export LD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/Ascend/nnae/latest/fwkacllib/lib64/:/usr/local/Ascend/driver/lib64/common/:/usr/local/Ascend/driver/lib64/driver/:/usr/local/Ascend/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH - export PATH=$PATH:/usr/local/Ascend/nnae/latest/fwkacllib/ccec_compiler/bin/:/usr/local/Ascend/nnae/latest/toolkit/tools/ide_daemon/bin/ - export ASCEND_OPP_PATH=/usr/local/Ascend/nnae/latest/opp/ - export OPTION_EXEC_EXTERN_PLUGIN_PATH=/usr/local/Ascend/nnae/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:/usr/local/Ascend/nnae/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:/usr/local/Ascend/nnae/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so - export PYTHONPATH=/usr/local/Ascend/nnae/latest/fwkacllib/python/site-packages/:/usr/local/Ascend/nnae/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:/usr/local/Ascend/nnae/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH -else - export LD_LIBRARY_PATH=/usr/local/:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/:/usr/local/Ascend/driver/lib64/common/:/usr/local/Ascend/driver/lib64/driver/:/usr/local/Ascend/add-ons/:/usr/lib/aarch64-linux-gnu:$LD_LIBRARY_PATH - export PATH=$PATH:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin/:/usr/local/Ascend/ascend-toolkit/latest/toolkit/tools/ide_daemon/bin/ - export ASCEND_OPP_PATH=/usr/local/Ascend/ascend-toolkit/latest/opp/ - export OPTION_EXEC_EXTERN_PLUGIN_PATH=/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so - export PYTHONPATH=/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH -fi - -# ln -s /usr/local/Ascend/ascend-toolkit/latest/toolkit/bin/adc /usr/local/bin/ - -export SLOG_PRINT_TO_STDOUT=0 - +############## toolkit situation ################ +#export LD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/:/usr/local/Ascend/driver/lib64/common/:/usr/local/Ascend/driver/lib64/driver/:/usr/local/Ascend/add-ons/:/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH +#export PATH=$PATH:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin/:/usr/local/Ascend/ascend-toolkit/latest/toolkit/tools/ide_daemon/bin/ +#export ASCEND_OPP_PATH=/usr/local/Ascend/ascend-toolkit/latest/opp/ +#export OPTION_EXEC_EXTERN_PLUGIN_PATH=/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so +#export PYTHONPATH=/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH + + +############## nnae situation ################ + + +if [ -d /usr/local/Ascend/nnae/latest ];then + export LD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/Ascend/nnae/latest/fwkacllib/lib64/:/usr/local/Ascend/driver/lib64/common/:/usr/local/Ascend/driver/lib64/driver/:/usr/local/Ascend/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH + export PATH=$PATH:/usr/local/Ascend/nnae/latest/fwkacllib/ccec_compiler/bin/:/usr/local/Ascend/nnae/latest/toolkit/tools/ide_daemon/bin/ + export ASCEND_OPP_PATH=/usr/local/Ascend/nnae/latest/opp/ + export OPTION_EXEC_EXTERN_PLUGIN_PATH=/usr/local/Ascend/nnae/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:/usr/local/Ascend/nnae/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:/usr/local/Ascend/nnae/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so + export PYTHONPATH=/usr/local/Ascend/nnae/latest/fwkacllib/python/site-packages/:/usr/local/Ascend/nnae/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:/usr/local/Ascend/nnae/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH +else + export LD_LIBRARY_PATH=/usr/local/:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/:/usr/local/Ascend/driver/lib64/common/:/usr/local/Ascend/driver/lib64/driver/:/usr/local/Ascend/add-ons/:/usr/lib/aarch64-linux-gnu:$LD_LIBRARY_PATH + export PATH=$PATH:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin/:/usr/local/Ascend/ascend-toolkit/latest/toolkit/tools/ide_daemon/bin/ + export ASCEND_OPP_PATH=/usr/local/Ascend/ascend-toolkit/latest/opp/ + export OPTION_EXEC_EXTERN_PLUGIN_PATH=/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so + export PYTHONPATH=/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH +fi + +# ln -s /usr/local/Ascend/ascend-toolkit/latest/toolkit/bin/adc /usr/local/bin/ + +export SLOG_PRINT_TO_STDOUT=0 + export TASK_QUEUE_ENABLE=1 \ No newline at end of file diff --git a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/pkltar2onnx.py b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/pkltar2onnx.py index ee7c9af5911167f7d425ef216f53601bd0602508..475d1dbf7c0fce6f94019951b9553dd8274c7a6d 100644 --- a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/pkltar2onnx.py +++ b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/pkltar2onnx.py @@ -1,104 +1,104 @@ -# Copyright 2021 Huawei Technologies Co., Ltd -# -# Licensed under the MIT License (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://opensource.org/licenses/MIT -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import torch -import torch.nn as nn -import torch.nn.functional as F -import numpy as np -from torch.autograd import Variable - -class downsample_net(nn.Module): - def __init__(self): - super(downsample_net, self).__init__() - self.conv1 = nn.Conv2d(3, 16, 3, 2, 1) - self.conv2 = nn.Conv2d(16, 3, 3, 1, 1) - self.relu = nn.ReLU() - weight_list = [ - [ - [ - [ - 0.257 - ] - ], - [ - [ - 0.504 - ] - ], - [ - [ - 0.098 - ] - ] - ], - - [ - [ - [ - -0.148 - ] - ], - [ - [ - -0.291 - ] - ], - [ - [ - 0.439 - - ] - ] - ], - - [ - [ - [ - 0.439 - ] - ], - [ - [ - -0.368 - ] - ], - [ - [ - -0.071 - ] - ] - ] -] - bias_list = [0.0627450980392157, 0.5019607843137255, 0.5019607843137255] - self.weight = Variable(torch.from_numpy(np.array(weight_list, dtype = 'float32'))) - self.bias = Variable(torch.from_numpy(np.array(bias_list, dtype = 'float32'))) - self.conv_define = nn.Conv2d(3, 3, 1, 1) - self.conv_define.weight.data = self.weight - self.conv_define.bias.data = self.bias - - def forward(self, x): - x = self.relu(self.conv1(x)) - out = self.conv2(x) - out = self.conv_define(out) - out = torch.mul(out, 255.) - return out - - -model_path = "/path/to/pkl" -dn = downsample_net() -dn.load_state_dict(torch.load(model_path, map_location=torch.device('cpu')), strict = False) -print(dn) -dummy_input = torch.randn(1, 3, 1152, 1440) -torch.onnx.export(dn, dummy_input, "/path/to/onnx", verbose=True, keep_initializers_as_inputs=True) - +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the MIT License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/MIT +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import torch +import torch.nn as nn +import torch.nn.functional as F +import numpy as np +from torch.autograd import Variable + +class downsample_net(nn.Module): + def __init__(self): + super(downsample_net, self).__init__() + self.conv1 = nn.Conv2d(3, 16, 3, 2, 1) + self.conv2 = nn.Conv2d(16, 3, 3, 1, 1) + self.relu = nn.ReLU() + weight_list = [ + [ + [ + [ + 0.257 + ] + ], + [ + [ + 0.504 + ] + ], + [ + [ + 0.098 + ] + ] + ], + + [ + [ + [ + -0.148 + ] + ], + [ + [ + -0.291 + ] + ], + [ + [ + 0.439 + + ] + ] + ], + + [ + [ + [ + 0.439 + ] + ], + [ + [ + -0.368 + ] + ], + [ + [ + -0.071 + ] + ] + ] +] + bias_list = [0.0627450980392157, 0.5019607843137255, 0.5019607843137255] + self.weight = Variable(torch.from_numpy(np.array(weight_list, dtype = 'float32'))) + self.bias = Variable(torch.from_numpy(np.array(bias_list, dtype = 'float32'))) + self.conv_define = nn.Conv2d(3, 3, 1, 1) + self.conv_define.weight.data = self.weight + self.conv_define.bias.data = self.bias + + def forward(self, x): + x = self.relu(self.conv1(x)) + out = self.conv2(x) + out = self.conv_define(out) + out = torch.mul(out, 255.) + return out + + +model_path = "/path/to/pkl" +dn = downsample_net() +dn.load_state_dict(torch.load(model_path, map_location=torch.device('cpu')), strict = False) +print(dn) +dummy_input = torch.randn(1, 3, 1152, 1440) +torch.onnx.export(dn, dummy_input, "/path/to/onnx", verbose=True, keep_initializers_as_inputs=True) + diff --git a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/requirements.txt b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/requirements.txt index 43aa6450fcd048e0b6ebe1dbc69ffff278649394..628efc0d6d4c6d836e8b64c5541ed0c1d3eee1d2 100644 --- a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/requirements.txt +++ b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/requirements.txt @@ -1,5 +1,5 @@ -torch==1.5.0 -apex -torchvision -numpy -Pillow==8.1.0 +torch==1.5.0 +apex +torchvision +numpy +Pillow==8.1.0 diff --git a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/run1p.sh b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/run1p.sh index 1c59be0db2dbe4755545fcb95708b2da7dd86296..b7755c03137c9aff8cddd09bfb3bc9fbfae28550 100644 --- a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/run1p.sh +++ b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/run1p.sh @@ -1,15 +1,15 @@ -#!/usr/bin/env bash -source npu_set_env.sh -export SLOG_PRINT_TO_STDOUT=0 -export TASK_QUEUE_ENABLE=1 -export PTCOPY_ENABLE=1 - - -python dscnn_train_pytorch.py --device_id=0 \ - --train_data_path=../datasets/train_data \ - --label_data_path=../datasets/label_data \ - --batch_size=8 \ - --epoch=60 \ - --lr=0.00001 \ - --model_save_dir=./models \ +#!/usr/bin/env bash +source npu_set_env.sh +export SLOG_PRINT_TO_STDOUT=0 +export TASK_QUEUE_ENABLE=1 +export PTCOPY_ENABLE=1 + + +python dscnn_train_pytorch.py --device_id=0 \ + --train_data_path=../datasets/train_data \ + --label_data_path=../datasets/label_data \ + --batch_size=8 \ + --epoch=60 \ + --lr=0.00001 \ + --model_save_dir=./models \ # --pre_trained_model_path=./models/DCNN_bilinear_0226_l1_0.025154941563113792_99.pkl \ No newline at end of file diff --git a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/run_to_onnx.sh b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/run_to_onnx.sh index a610204ae523947a9681ca84cdb4e4fe672186d5..f667562759653a231678bb505ff9693e5d4f1317 100644 --- a/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/run_to_onnx.sh +++ b/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch/run_to_onnx.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash -source npu_set_env.sh - +#!/usr/bin/env bash +source npu_set_env.sh + python3.7 pkltar2onnx.py \ No newline at end of file diff --git a/PyTorch/dev/nlp/FairSeq_Transformer_ID0496_for_PyTorch/test/train_full_1p_bs512.sh b/PyTorch/dev/nlp/FairSeq_Transformer_ID0496_for_PyTorch/test/train_full_1p_bs512.sh index ca3f13a1021391cfdfad69efa42a479095088d33..6f0a63d0133c14cb755866978db76c99bcbb3aed 100644 --- a/PyTorch/dev/nlp/FairSeq_Transformer_ID0496_for_PyTorch/test/train_full_1p_bs512.sh +++ b/PyTorch/dev/nlp/FairSeq_Transformer_ID0496_for_PyTorch/test/train_full_1p_bs512.sh @@ -1,214 +1,214 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID -#集合通信参数,不需要修改 - -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 - -#进入到conda环境 -#source activate py8 - - - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="FairSeq_Transformer_ID0496_for_PyTorch" -#训练epoch -train_epochs=2000 -#训练batch_size -batch_size=512 -#训练step -#train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.495 - -#TF2.X独有,不需要修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_1p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` -elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path/../ - -#python3 setup.py build_ext --inplace -pip3 install --editable . -#sed -i "s|pass|break|g" train.py -#sed -i "s|data/LibriSpeech|$data_path/LibriSpeech|g" config/libri/asr_example.yaml - -#修改epoch参数 - - -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - - #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 - #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` - #cpustep=`expr $cpucount / 8` - #echo "taskset c steps:" $cpustep - #let a=RANK_ID*$cpustep - #let b=RANK_ID+1 - #let c=b*$cpustep-1 - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - nohup python3 train.py $data_path/iwslt14.tokenized.de-en \ - --arch transformer \ - --optimizer adam \ - --adam-betas '(0.9, 0.98)' \ - --clip-norm 0.0 \ - --lr 0.00006 \ - --lr-scheduler inverse_sqrt \ - --warmup-updates 4000 \ - --dropout 0.00 \ - --weight-decay 0.0001 \ - --source-lang de \ - --target-lang en \ - --decoder-attention-heads 4 \ - --decoder-ffn-embed-dim 1024 \ - --encoder-attention-heads 4 \ - --encoder-ffn-embed-dim 1024 \ - --seed 12345 \ - --fp16 \ - --fp16-scale-window 1500 \ - --ddp-backend no_c10d \ - --disable-validation \ - --distributed-no-spawn \ - --required-batch-size-multiple 512 \ - --batch-size 512 \ - --max-epoch 2000 \ - --max-source-positions 1024 \ - --max-target-positions 1024 \ - --num-workers 1 \ - --log-interval 1 \ - --save-interval 1 \ - --share-decoder-input-output-embed > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -done -wait - -#conda deactivate -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -Time=`grep "iteration" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |awk -F "time =" '{print $2}'|awk -F "ms" '{print $1}'|tail -n +6|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` -FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${Time}'}'` - - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep eval_accuracy $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v mlp_log|awk 'END {print $5}'| sed 's/,//g' |cut -c 1-5` -#打印,不需要修改 -train_accuracy="Loss" -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' - -##获取性能数据 -#吞吐量,不需要修改 -ActualFPS=${FPS} -#单迭代训练时长,不需要修改 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "loss=" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "loss=" '{print $2}'|awk -F "," '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID +#集合通信参数,不需要修改 + +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 + +#进入到conda环境 +#source activate py8 + + + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="FairSeq_Transformer_ID0496_for_PyTorch" +#训练epoch +train_epochs=2000 +#训练batch_size +batch_size=512 +#训练step +#train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.495 + +#TF2.X独有,不需要修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_1p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` +elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path/../ + +#python3 setup.py build_ext --inplace +pip3 install --editable . +#sed -i "s|pass|break|g" train.py +#sed -i "s|data/LibriSpeech|$data_path/LibriSpeech|g" config/libri/asr_example.yaml + +#修改epoch参数 + + +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + + #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 + #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` + #cpustep=`expr $cpucount / 8` + #echo "taskset c steps:" $cpustep + #let a=RANK_ID*$cpustep + #let b=RANK_ID+1 + #let c=b*$cpustep-1 + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + nohup python3 train.py $data_path/iwslt14.tokenized.de-en \ + --arch transformer \ + --optimizer adam \ + --adam-betas '(0.9, 0.98)' \ + --clip-norm 0.0 \ + --lr 0.00006 \ + --lr-scheduler inverse_sqrt \ + --warmup-updates 4000 \ + --dropout 0.00 \ + --weight-decay 0.0001 \ + --source-lang de \ + --target-lang en \ + --decoder-attention-heads 4 \ + --decoder-ffn-embed-dim 1024 \ + --encoder-attention-heads 4 \ + --encoder-ffn-embed-dim 1024 \ + --seed 12345 \ + --fp16 \ + --fp16-scale-window 1500 \ + --ddp-backend no_c10d \ + --disable-validation \ + --distributed-no-spawn \ + --required-batch-size-multiple 512 \ + --batch-size 512 \ + --max-epoch 2000 \ + --max-source-positions 1024 \ + --max-target-positions 1024 \ + --num-workers 1 \ + --log-interval 1 \ + --save-interval 1 \ + --share-decoder-input-output-embed > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +done +wait + +#conda deactivate +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +Time=`grep "iteration" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |awk -F "time =" '{print $2}'|awk -F "ms" '{print $1}'|tail -n +6|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` +FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${Time}'}'` + + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep eval_accuracy $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v mlp_log|awk 'END {print $5}'| sed 's/,//g' |cut -c 1-5` +#打印,不需要修改 +train_accuracy="Loss" +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' + +##获取性能数据 +#吞吐量,不需要修改 +ActualFPS=${FPS} +#单迭代训练时长,不需要修改 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "loss=" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "loss=" '{print $2}'|awk -F "," '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/dev/nlp/FairSeq_Transformer_ID0496_for_PyTorch/test/train_performance_1p_bs512.sh b/PyTorch/dev/nlp/FairSeq_Transformer_ID0496_for_PyTorch/test/train_performance_1p_bs512.sh index 460f1e01fcfa105f0cd938570bde10dd13f55991..9649fd43445861bfab2cd7c399dc2f7c80276a58 100644 --- a/PyTorch/dev/nlp/FairSeq_Transformer_ID0496_for_PyTorch/test/train_performance_1p_bs512.sh +++ b/PyTorch/dev/nlp/FairSeq_Transformer_ID0496_for_PyTorch/test/train_performance_1p_bs512.sh @@ -1,214 +1,214 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID -#集合通信参数,不需要修改 - -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 - -#进入到conda环境 -#source activate py8 - - - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="FairSeq_Transformer_ID0496_for_PyTorch" -#训练epoch -train_epochs=1 -#训练batch_size -batch_size=512 -#训练step -#train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.495 - -#TF2.X独有,不需要修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_1p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` -elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - fi -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path/../ - -#python3 setup.py build_ext --inplace -pip3 install --editable . -#sed -i "s|pass|break|g" train.py -#sed -i "s|data/LibriSpeech|$data_path/LibriSpeech|g" config/libri/asr_example.yaml - -#修改epoch参数 - - -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - - #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 - #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` - #cpustep=`expr $cpucount / 8` - #echo "taskset c steps:" $cpustep - #let a=RANK_ID*$cpustep - #let b=RANK_ID+1 - #let c=b*$cpustep-1 - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - nohup python3 train.py $data_path/iwslt14.tokenized.de-en \ - --arch transformer \ - --optimizer adam \ - --adam-betas '(0.9, 0.98)' \ - --clip-norm 0.0 \ - --lr 0.00006 \ - --lr-scheduler inverse_sqrt \ - --warmup-updates 4000 \ - --dropout 0.00 \ - --weight-decay 0.0001 \ - --source-lang de \ - --target-lang en \ - --decoder-attention-heads 4 \ - --decoder-ffn-embed-dim 1024 \ - --encoder-attention-heads 4 \ - --encoder-ffn-embed-dim 1024 \ - --seed 12345 \ - --fp16 \ - --fp16-scale-window 1500 \ - --ddp-backend no_c10d \ - --disable-validation \ - --distributed-no-spawn \ - --required-batch-size-multiple 512 \ - --batch-size 512 \ - --max-epoch 1 \ - --max-source-positions 1024 \ - --max-target-positions 1024 \ - --num-workers 1 \ - --log-interval 1 \ - --save-interval 1 \ - --share-decoder-input-output-embed > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -done -wait - -#conda deactivate -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -#Time=`grep "iteration" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |awk -F "time =" '{print $2}'|awk -F "ms" '{print $1}'|tail -n +6|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` -Time=`grep "iteration" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |awk -F "time =" '{print $2}'|awk -F "ms" '{print $1}'| grep -v "^$" |tail -n +6|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` -FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${Time}'}'` - - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep eval_accuracy $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v mlp_log|awk 'END {print $5}'| sed 's/,//g' |cut -c 1-5` -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -#echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据 -#吞吐量,不需要修改 -ActualFPS=${FPS} -#单迭代训练时长,不需要修改 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "loss=" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "loss=" '{print $2}'|awk -F "," '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID +#集合通信参数,不需要修改 + +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 + +#进入到conda环境 +#source activate py8 + + + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="FairSeq_Transformer_ID0496_for_PyTorch" +#训练epoch +train_epochs=1 +#训练batch_size +batch_size=512 +#训练step +#train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.495 + +#TF2.X独有,不需要修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_1p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` +elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + fi +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path/../ + +#python3 setup.py build_ext --inplace +pip3 install --editable . +#sed -i "s|pass|break|g" train.py +#sed -i "s|data/LibriSpeech|$data_path/LibriSpeech|g" config/libri/asr_example.yaml + +#修改epoch参数 + + +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + + #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 + #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` + #cpustep=`expr $cpucount / 8` + #echo "taskset c steps:" $cpustep + #let a=RANK_ID*$cpustep + #let b=RANK_ID+1 + #let c=b*$cpustep-1 + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + nohup python3 train.py $data_path/iwslt14.tokenized.de-en \ + --arch transformer \ + --optimizer adam \ + --adam-betas '(0.9, 0.98)' \ + --clip-norm 0.0 \ + --lr 0.00006 \ + --lr-scheduler inverse_sqrt \ + --warmup-updates 4000 \ + --dropout 0.00 \ + --weight-decay 0.0001 \ + --source-lang de \ + --target-lang en \ + --decoder-attention-heads 4 \ + --decoder-ffn-embed-dim 1024 \ + --encoder-attention-heads 4 \ + --encoder-ffn-embed-dim 1024 \ + --seed 12345 \ + --fp16 \ + --fp16-scale-window 1500 \ + --ddp-backend no_c10d \ + --disable-validation \ + --distributed-no-spawn \ + --required-batch-size-multiple 512 \ + --batch-size 512 \ + --max-epoch 1 \ + --max-source-positions 1024 \ + --max-target-positions 1024 \ + --num-workers 1 \ + --log-interval 1 \ + --save-interval 1 \ + --share-decoder-input-output-embed > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +done +wait + +#conda deactivate +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +#Time=`grep "iteration" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |awk -F "time =" '{print $2}'|awk -F "ms" '{print $1}'|tail -n +6|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` +Time=`grep "iteration" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |awk -F "time =" '{print $2}'|awk -F "ms" '{print $1}'| grep -v "^$" |tail -n +6|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` +FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${Time}'}'` + + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep eval_accuracy $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v mlp_log|awk 'END {print $5}'| sed 's/,//g' |cut -c 1-5` +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +#echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据 +#吞吐量,不需要修改 +ActualFPS=${FPS} +#单迭代训练时长,不需要修改 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "loss=" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "loss=" '{print $2}'|awk -F "," '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log \ No newline at end of file diff --git a/PyTorch/dev/nlp/FairSeq_Transformer_ID0496_for_PyTorch/test/train_performance_1p_dynamic.sh b/PyTorch/dev/nlp/FairSeq_Transformer_ID0496_for_PyTorch/test/train_performance_1p_dynamic.sh index f5beb70f66954438f1a301f03e1b6259b32ffe8c..76d0a44ef727a5c3e3e4fd53b0ad13cf90692fc7 100644 --- a/PyTorch/dev/nlp/FairSeq_Transformer_ID0496_for_PyTorch/test/train_performance_1p_dynamic.sh +++ b/PyTorch/dev/nlp/FairSeq_Transformer_ID0496_for_PyTorch/test/train_performance_1p_dynamic.sh @@ -1,326 +1,326 @@ -1#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -#export ASCEND_SLOG_PRINT_TO_STDOUT=1 -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID -#集合通信参数,不需要修改 - -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 - -#进入到conda环境 -#source activate py8 - - - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="FairSeq_Transformer_ID0496_for_PyTorch" -#训练epoch -train_epochs=4 -#训练batch_size -batch_size=32 -#训练step -#train_steps=`expr 1281167 / ${batch_size}` -#学习率 -learning_rate=0.495 - -#TF2.X独有,不需要修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False -bin_mode=False -bin_analysis=False - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_1p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - precision_mode=`echo ${para#*=}` -elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --bin_mode* ]];then - bin_mode="True" - elif [[ $para == --bin_analysis* ]];then - bin_analysis="True" - fi -done - -#设置二进制变量 -if [ $bin_mode == "True" ];then - line=`grep "torch.npu.set_option" ${cur_path}/../train.py -n | awk -F ':' '{print $1}'` - sed -i "${line}ioption['ACL_OP_COMPILER_CACHE_MODE'] = 'disable'" ${cur_path}/../train.py - sed -i "${line}s/^/ /" ${cur_path}/../train.py -fi - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" - exit 1 -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path/../ - -#python3 setup.py build_ext --inplace -pip3 install --editable . -#sed -i "s|pass|break|g" train.py -#sed -i "s|data/LibriSpeech|$data_path/LibriSpeech|g" config/libri/asr_example.yaml - -#修改epoch参数 - - -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - - #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 - #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` - #cpustep=`expr $cpucount / 8` - #echo "taskset c steps:" $cpustep - #let a=RANK_ID*$cpustep - #let b=RANK_ID+1 - #let c=b*$cpustep-1 - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - nohup python3 train.py $data_path/iwslt14.tokenized.de-en \ - --arch transformer \ - --optimizer adam \ - --adam-betas '(0.9, 0.98)' \ - --clip-norm 0.0 \ - --lr 0.00006 \ - --lr-scheduler inverse_sqrt \ - --warmup-updates 4000 \ - --device-id $ASCEND_DEVICE_ID \ - --weight-decay 0.0001 \ - --source-lang de \ - --target-lang en \ - --decoder-attention-heads 4 \ - --decoder-ffn-embed-dim 1024 \ - --encoder-attention-heads 4 \ - --encoder-ffn-embed-dim 1024 \ - --seed 12345 \ - --fp16 \ - --fp16-scale-window 1500 \ - --ddp-backend no_c10d \ - --disable-validation \ - --distributed-no-spawn \ - --max-tokens 15000 \ - --required-batch-size-multiple 32 \ - --max-epoch ${train_epochs} \ - --max-source-positions 1024 \ - --max-target-positions 1024 \ - --num-workers 1 \ - --log-interval 1 \ - --save-interval 1 \ - --share-decoder-input-output-embed > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -done -wait - -#conda deactivate -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -#Time=`grep "iteration" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |awk -F "time =" '{print $2}'|awk -F "ms" '{print $1}'| grep -v "^$" |tail -n +6|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` -FPS=`grep -rn "wps=" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F "wps=" '{print $2}' | awk -F "," '{print $1}' | awk '{if(NR>=325){print}}' | awk 'END {print}' |sed s/[[:space:]]//g` -#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${Time}'}'` - - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep eval_accuracy $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v mlp_log|awk 'END {print $5}'| sed 's/,//g' |cut -c 1-5` -#打印,不需要修改 -#echo "Final Train Accuracy : ${train_accuracy}" -#echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' -if [ $bin_mode == "True" ];then - CaseName=$CaseName"_binary" -fi - -##获取性能数据 -#吞吐量,不需要修改 -ActualFPS=${FPS} -#单迭代训练时长,不需要修改 -#TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` -TrainingTime=`grep "iteration" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |awk -F "time =" '{print $2}'|awk -F "ms" '{print $1}'| grep -v "^$" |tail -n +6|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep "loss=" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "loss=" '{print $2}'|awk -F "," '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log - -#获取二进制算子信息 -if [ $bin_analysis == "True" ];then - echo "========start bin analysis========" - #1、版本已支持二进制的算子清单: - cmd1=`ls -l /usr/local/Ascend/CANN-1.82/opp/op_impl/built-in/ai_core/tbe/kernel/config/ascend910|grep -v total|awk -F " " '{print $9}'|awk -F "." '{print $1}'` - cmd1_num=`ls -l /usr/local/Ascend/CANN-1.82/opp/op_impl/built-in/ai_core/tbe/kernel/config/ascend910|grep -v total|awk -F " " '{print $9}'|awk -F "." '{print $1}'|wc -l` - - - #2、模型中所有编译的算子及次数 - cmd2=`grep -rn "The compile strategy of task" $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "First node is " '{print $2}'|awk -F "." '{print $1}'|awk -F "/" ' {print $NF}'` - cmd2_num=`grep -rn "The compile strategy of task" $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "First node is " '{print $2}'|awk -F "." '{print $1}'|awk -F "/" ' {print $NF}'|wc -l` - - - #3、成功复用二进制的算子及次数: - cmd3=`grep -rn "json) can be reused. No need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "/" '{print $14}'|awk -F "_" '{print $1}'` - cmd3_num=`grep -rn "json) can be reused. No need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "/" '{print $14}'|awk -F "_" '{print $1}'|wc -l` - - #4、二进制未发布的二进制算子及次数 - cmd4=`grep -rn "json) does not exist. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F ".json" '{print $1}'|awk -F "/" ' {print $NF}'` - cmd4_num=`grep -rn "json) does not exist. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F ".json" '{print $1}'|awk -F "/" ' {print $NF}'|wc -l` - - - #5、未匹配模糊编译或者属于高性能模式,导致无法复用二进制的算子及数量 - cmd5=`grep -rn "not fuzzy or performance mode() is not normal. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "(" '{print $3}'|awk -F ")" '{print $1}'` - cmd5_num=`grep -rn "not fuzzy or performance mode() is not normal. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "(" '{print $3}'|awk -F ")" '{print $1}'|wc -l` - - - #6、static key不匹配,导致无法复用二进制的算子及数量 - cmd6=`grep -rn "does not match in binary file. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "The node " '{print $2}'|awk '{print $1}'` - cmd6_num=`grep -rn "does not match in binary file. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "The node " '{print $2}'|awk '{print $1}'|wc -l` - - - #7、动态参数范围不匹配,导致无法复用二进制的算子及数量 - cmd7=`grep -rn "match attrs failed. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "(" '{print $3}'|awk -F ")" '{print $1}'` - cmd7_num=`grep -rn "match attrs failed. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "(" '{print $3}'|awk -F ")" '{print $1}'|wc -l` - - - #8、匹配到编译缓存,不需要复用二进制算子及数量 - cmd8=`grep -rn "don't need to compile" $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "te_" '{print $2}'|awk -F "_" '{print $1}'` - cmd8_num=`grep -rn "don't need to compile" $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "te_" '{print $2}'|awk -F "_" '{print $1}'|wc -l` - - - count_name="$cur_path/output/$ASCEND_DEVICE_ID/bin_op_summay.csv" - - title="网络名称 ,用例名称 ,1-已发布二进制的算子数量 ,2-模型中所有编译的算子及次数 ,3-成功复用二进制的算子及次数 ,4-二进制未发布的算子及次数, 5-未匹配模糊编译或者属于高性能模式,导致无法复用二进制的算子及数量,6-static key不匹配,导致无法复用二进制的算子及数量 ,7-动态参数范围不匹配,导致无法复用二进制的算子及数量 ,8-匹配到编译缓存,不需要复用二进制算子及数量" - printf "\xEF\xBB\xBF" > $count_name - echo $title >> $count_name - echo "$Network,$CaseName,$cmd1_num,$cmd2_num,$cmd3_num,$cmd4_num,$cmd5_num,$cmd6_num,$cmd7_num,$cmd8_num" >> $count_name - - - str="$cmd1,$cmd2,$cmd3,$cmd4,$cmd5,$cmd6,$cmd7,$cmd8" - - - oldIFS=${IFS} - IFS="," - num=1 - dot_num="" - touch $cur_path/output/$ASCEND_DEVICE_ID/$num.csv - for i in ${str[@]}; - do - IFS=$oldIFS - if [[ $i == "" ]];then - dot_num=",${dot_num}" - else - if (( $num == 1 ));then - dot="" - else - dot=",${dot_num}" - fi - - for j in $i; - do - echo "${dot}$j" >>$cur_path/output/$ASCEND_DEVICE_ID/a.csv - dot_num= - done - - fi - if [ ! -f "$cur_path/output/$ASCEND_DEVICE_ID/a.csv" ];then - cp $cur_path/output/$ASCEND_DEVICE_ID/$num.csv $cur_path/output/$ASCEND_DEVICE_ID/$(($num+1)).csv - else - paste $cur_path/output/$ASCEND_DEVICE_ID/$num.csv $cur_path/output/$ASCEND_DEVICE_ID/a.csv > $cur_path/output/$ASCEND_DEVICE_ID/$(($num+1)).csv - fi - - num=$(($num+1)) - rm -f $cur_path/output/$ASCEND_DEVICE_ID/a.csv - rm -f $cur_path/output/$ASCEND_DEVICE_ID/$(($num-1)).csv - IFS="," - done - printf "\xEF\xBB\xBF" > $cur_path/output/$ASCEND_DEVICE_ID/bin_op_details.csv - sed -i '1i1-已发布二进制的算子清单 ,2-模型中所有编译的算子及次数 ,3-成功复用二进制的算子及次数 ,4-二进制未发布的算子及次数 ,5-未匹配模糊编译或者属于高性能模式,导致无法复用二进制的算子及数量,6-static key不匹配,导致无法复用二进制的算子及数量 ,7-动态参数范围不匹配,导致无法复用二进制的算子及数量 ,8-匹配到编译缓存,不需要复用二进制算子及数量' $cur_path/output/$ASCEND_DEVICE_ID/$num.csv - cat $cur_path/output/$ASCEND_DEVICE_ID/$num.csv >> $cur_path/output/$ASCEND_DEVICE_ID/bin_op_details.csv - rm -f $cur_path/output/$ASCEND_DEVICE_ID/$num.csv - echo "========end bin analysis========" +1#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +#export ASCEND_SLOG_PRINT_TO_STDOUT=1 +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID +#集合通信参数,不需要修改 + +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 + +#进入到conda环境 +#source activate py8 + + + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="FairSeq_Transformer_ID0496_for_PyTorch" +#训练epoch +train_epochs=4 +#训练batch_size +batch_size=32 +#训练step +#train_steps=`expr 1281167 / ${batch_size}` +#学习率 +learning_rate=0.495 + +#TF2.X独有,不需要修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False +bin_mode=False +bin_analysis=False + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_1p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + precision_mode=`echo ${para#*=}` +elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --bin_mode* ]];then + bin_mode="True" + elif [[ $para == --bin_analysis* ]];then + bin_analysis="True" + fi +done + +#设置二进制变量 +if [ $bin_mode == "True" ];then + line=`grep "torch.npu.set_option" ${cur_path}/../train.py -n | awk -F ':' '{print $1}'` + sed -i "${line}ioption['ACL_OP_COMPILER_CACHE_MODE'] = 'disable'" ${cur_path}/../train.py + sed -i "${line}s/^/ /" ${cur_path}/../train.py +fi + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" + exit 1 +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path/../ + +#python3 setup.py build_ext --inplace +pip3 install --editable . +#sed -i "s|pass|break|g" train.py +#sed -i "s|data/LibriSpeech|$data_path/LibriSpeech|g" config/libri/asr_example.yaml + +#修改epoch参数 + + +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + + #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 + #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` + #cpustep=`expr $cpucount / 8` + #echo "taskset c steps:" $cpustep + #let a=RANK_ID*$cpustep + #let b=RANK_ID+1 + #let c=b*$cpustep-1 + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + nohup python3 train.py $data_path/iwslt14.tokenized.de-en \ + --arch transformer \ + --optimizer adam \ + --adam-betas '(0.9, 0.98)' \ + --clip-norm 0.0 \ + --lr 0.00006 \ + --lr-scheduler inverse_sqrt \ + --warmup-updates 4000 \ + --device-id $ASCEND_DEVICE_ID \ + --weight-decay 0.0001 \ + --source-lang de \ + --target-lang en \ + --decoder-attention-heads 4 \ + --decoder-ffn-embed-dim 1024 \ + --encoder-attention-heads 4 \ + --encoder-ffn-embed-dim 1024 \ + --seed 12345 \ + --fp16 \ + --fp16-scale-window 1500 \ + --ddp-backend no_c10d \ + --disable-validation \ + --distributed-no-spawn \ + --max-tokens 15000 \ + --required-batch-size-multiple 32 \ + --max-epoch ${train_epochs} \ + --max-source-positions 1024 \ + --max-target-positions 1024 \ + --num-workers 1 \ + --log-interval 1 \ + --save-interval 1 \ + --share-decoder-input-output-embed > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +done +wait + +#conda deactivate +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +#Time=`grep "iteration" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |awk -F "time =" '{print $2}'|awk -F "ms" '{print $1}'| grep -v "^$" |tail -n +6|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` +FPS=`grep -rn "wps=" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | awk -F "wps=" '{print $2}' | awk -F "," '{print $1}' | awk '{if(NR>=325){print}}' | awk 'END {print}' |sed s/[[:space:]]//g` +#FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'*1000/'${Time}'}'` + + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep eval_accuracy $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -v mlp_log|awk 'END {print $5}'| sed 's/,//g' |cut -c 1-5` +#打印,不需要修改 +#echo "Final Train Accuracy : ${train_accuracy}" +#echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' +if [ $bin_mode == "True" ];then + CaseName=$CaseName"_binary" +fi + +##获取性能数据 +#吞吐量,不需要修改 +ActualFPS=${FPS} +#单迭代训练时长,不需要修改 +#TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` +TrainingTime=`grep "iteration" ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |awk -F "time =" '{print $2}'|awk -F "ms" '{print $1}'| grep -v "^$" |tail -n +6|awk '{sum+=$1} END {print"",sum/NR}'|sed s/[[:space:]]//g` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep "loss=" $cur_path/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|awk -F "loss=" '{print $2}'|awk -F "," '{print $1}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log + +#获取二进制算子信息 +if [ $bin_analysis == "True" ];then + echo "========start bin analysis========" + #1、版本已支持二进制的算子清单: + cmd1=`ls -l /usr/local/Ascend/CANN-1.82/opp/op_impl/built-in/ai_core/tbe/kernel/config/ascend910|grep -v total|awk -F " " '{print $9}'|awk -F "." '{print $1}'` + cmd1_num=`ls -l /usr/local/Ascend/CANN-1.82/opp/op_impl/built-in/ai_core/tbe/kernel/config/ascend910|grep -v total|awk -F " " '{print $9}'|awk -F "." '{print $1}'|wc -l` + + + #2、模型中所有编译的算子及次数 + cmd2=`grep -rn "The compile strategy of task" $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "First node is " '{print $2}'|awk -F "." '{print $1}'|awk -F "/" ' {print $NF}'` + cmd2_num=`grep -rn "The compile strategy of task" $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "First node is " '{print $2}'|awk -F "." '{print $1}'|awk -F "/" ' {print $NF}'|wc -l` + + + #3、成功复用二进制的算子及次数: + cmd3=`grep -rn "json) can be reused. No need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "/" '{print $14}'|awk -F "_" '{print $1}'` + cmd3_num=`grep -rn "json) can be reused. No need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "/" '{print $14}'|awk -F "_" '{print $1}'|wc -l` + + #4、二进制未发布的二进制算子及次数 + cmd4=`grep -rn "json) does not exist. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F ".json" '{print $1}'|awk -F "/" ' {print $NF}'` + cmd4_num=`grep -rn "json) does not exist. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F ".json" '{print $1}'|awk -F "/" ' {print $NF}'|wc -l` + + + #5、未匹配模糊编译或者属于高性能模式,导致无法复用二进制的算子及数量 + cmd5=`grep -rn "not fuzzy or performance mode() is not normal. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "(" '{print $3}'|awk -F ")" '{print $1}'` + cmd5_num=`grep -rn "not fuzzy or performance mode() is not normal. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "(" '{print $3}'|awk -F ")" '{print $1}'|wc -l` + + + #6、static key不匹配,导致无法复用二进制的算子及数量 + cmd6=`grep -rn "does not match in binary file. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "The node " '{print $2}'|awk '{print $1}'` + cmd6_num=`grep -rn "does not match in binary file. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "The node " '{print $2}'|awk '{print $1}'|wc -l` + + + #7、动态参数范围不匹配,导致无法复用二进制的算子及数量 + cmd7=`grep -rn "match attrs failed. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "(" '{print $3}'|awk -F ")" '{print $1}'` + cmd7_num=`grep -rn "match attrs failed. Need to compile." $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "(" '{print $3}'|awk -F ")" '{print $1}'|wc -l` + + + #8、匹配到编译缓存,不需要复用二进制算子及数量 + cmd8=`grep -rn "don't need to compile" $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "te_" '{print $2}'|awk -F "_" '{print $1}'` + cmd8_num=`grep -rn "don't need to compile" $cur_path/output/$ASCEND_DEVICE_ID/train*log|awk -F "te_" '{print $2}'|awk -F "_" '{print $1}'|wc -l` + + + count_name="$cur_path/output/$ASCEND_DEVICE_ID/bin_op_summay.csv" + + title="网络名称 ,用例名称 ,1-已发布二进制的算子数量 ,2-模型中所有编译的算子及次数 ,3-成功复用二进制的算子及次数 ,4-二进制未发布的算子及次数, 5-未匹配模糊编译或者属于高性能模式,导致无法复用二进制的算子及数量,6-static key不匹配,导致无法复用二进制的算子及数量 ,7-动态参数范围不匹配,导致无法复用二进制的算子及数量 ,8-匹配到编译缓存,不需要复用二进制算子及数量" + printf "\xEF\xBB\xBF" > $count_name + echo $title >> $count_name + echo "$Network,$CaseName,$cmd1_num,$cmd2_num,$cmd3_num,$cmd4_num,$cmd5_num,$cmd6_num,$cmd7_num,$cmd8_num" >> $count_name + + + str="$cmd1,$cmd2,$cmd3,$cmd4,$cmd5,$cmd6,$cmd7,$cmd8" + + + oldIFS=${IFS} + IFS="," + num=1 + dot_num="" + touch $cur_path/output/$ASCEND_DEVICE_ID/$num.csv + for i in ${str[@]}; + do + IFS=$oldIFS + if [[ $i == "" ]];then + dot_num=",${dot_num}" + else + if (( $num == 1 ));then + dot="" + else + dot=",${dot_num}" + fi + + for j in $i; + do + echo "${dot}$j" >>$cur_path/output/$ASCEND_DEVICE_ID/a.csv + dot_num= + done + + fi + if [ ! -f "$cur_path/output/$ASCEND_DEVICE_ID/a.csv" ];then + cp $cur_path/output/$ASCEND_DEVICE_ID/$num.csv $cur_path/output/$ASCEND_DEVICE_ID/$(($num+1)).csv + else + paste $cur_path/output/$ASCEND_DEVICE_ID/$num.csv $cur_path/output/$ASCEND_DEVICE_ID/a.csv > $cur_path/output/$ASCEND_DEVICE_ID/$(($num+1)).csv + fi + + num=$(($num+1)) + rm -f $cur_path/output/$ASCEND_DEVICE_ID/a.csv + rm -f $cur_path/output/$ASCEND_DEVICE_ID/$(($num-1)).csv + IFS="," + done + printf "\xEF\xBB\xBF" > $cur_path/output/$ASCEND_DEVICE_ID/bin_op_details.csv + sed -i '1i1-已发布二进制的算子清单 ,2-模型中所有编译的算子及次数 ,3-成功复用二进制的算子及次数 ,4-二进制未发布的算子及次数 ,5-未匹配模糊编译或者属于高性能模式,导致无法复用二进制的算子及数量,6-static key不匹配,导致无法复用二进制的算子及数量 ,7-动态参数范围不匹配,导致无法复用二进制的算子及数量 ,8-匹配到编译缓存,不需要复用二进制算子及数量' $cur_path/output/$ASCEND_DEVICE_ID/$num.csv + cat $cur_path/output/$ASCEND_DEVICE_ID/$num.csv >> $cur_path/output/$ASCEND_DEVICE_ID/bin_op_details.csv + rm -f $cur_path/output/$ASCEND_DEVICE_ID/$num.csv + echo "========end bin analysis========" fi \ No newline at end of file diff --git a/PyTorch/dev/nlp/Speech_Transformer_ID0487_for_PyTorch/modelzoo_level.txt b/PyTorch/dev/nlp/Speech_Transformer_ID0487_for_PyTorch/modelzoo_level.txt index 405b26618a0c92027927a9c583a4b47f640bcf7b..c45626e398eabe6022fe7b2e148f0ffce6400d6e 100644 --- a/PyTorch/dev/nlp/Speech_Transformer_ID0487_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/dev/nlp/Speech_Transformer_ID0487_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:POK +FuncStatus:OK +PerfStatus:POK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/dev/others/RecVAE_ID0347_for_PyTorch/modelzoo_level.txt b/PyTorch/dev/others/RecVAE_ID0347_for_PyTorch/modelzoo_level.txt index 0b49b4fb26c2694a86567bea1b462e7dcb03cc31..31529da2e68f25b61e2a3e698a07537281443c03 100644 --- a/PyTorch/dev/others/RecVAE_ID0347_for_PyTorch/modelzoo_level.txt +++ b/PyTorch/dev/others/RecVAE_ID0347_for_PyTorch/modelzoo_level.txt @@ -1,3 +1,3 @@ -FuncStatus:OK -PerfStatus:OK +FuncStatus:OK +PerfStatus:OK PrecisionStatus:OK \ No newline at end of file diff --git a/PyTorch/dev/others/Widedeep_ID2866_for_PyTorch/test/train_ID3080_Widedeep_performance_1p.sh b/PyTorch/dev/others/Widedeep_ID2866_for_PyTorch/test/train_ID3080_Widedeep_performance_1p.sh index 101b98fcdab28181baa84450308bea55d86ad094..27648b40740aca6c8f159c1b9c88b3b5ee2e4514 100644 --- a/PyTorch/dev/others/Widedeep_ID2866_for_PyTorch/test/train_ID3080_Widedeep_performance_1p.sh +++ b/PyTorch/dev/others/Widedeep_ID2866_for_PyTorch/test/train_ID3080_Widedeep_performance_1p.sh @@ -1,188 +1,188 @@ -#!/bin/bash - -#当前路径,不需要修改 -cur_path=`pwd` -export ASCEND_SLOG_PRINT_TO_STDOUT=0 -export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID -#集合通信参数,不需要修改 - -export RANK_SIZE=1 -export JOB_ID=10087 -RANK_ID_START=0 - -#进入到conda环境 - -#export PATH=/usr/local/python3.7.5/bin:/home/anaconda3/bin:$PATH -#export LD_LIBRARY_PATH=/home/anaconda3/lib:$LD_LIBRARY_PATH -#source activate py8 - -# 数据集路径,保持为空,不需要修改 -data_path="" - -#基础参数,需要模型审视修改 -#网络名称,同目录名称 -Network="Widedeep_ID3080_for_PyTorch" -#训练epoch -epoch=1 -#训练batch_size -train_batch_size=16 -batch_size=${train_batch_size} -#训练step -#train_steps=`expr 1281167 / ${batch_size}` -#学习率 -#learning_rate=0.495 -PREC="" -#TF2.X独有,不需要修改 -#export NPU_LOOP_SIZE=${train_steps} - -#维测参数,precision_mode需要模型审视修改 -precision_mode="allow_mix_precision" -#维持参数,以下不需要修改 -over_dump=False -data_dump_flag=False -data_dump_step="10" -profiling=False -autotune=False -data_path=./data/criteo_sampled_data.csv - -# 帮助信息,不需要修改 -if [[ $1 == --help || $1 == -h ]];then - echo"usage:./train_full_1p.sh " - echo " " - echo "parameter explain: - --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) - --over_dump if or not over detection, default is False - --data_dump_flag data dump flag, default is False - --data_dump_step data dump step, default is 10 - --profiling if or not profiling for performance debug, default is False - --data_path source data of training - -h/--help show help message - " - exit 1 -fi - -#参数校验,不需要修改 -for para in $* -do - if [[ $para == --precision_mode* ]];then - apex_opt_level=`echo ${para#*=}` - if [[ $apex_opt_level != "O1" ]] && [[ $apex_opt_level != "O2" ]] && [[ $apex_opt_level != "O3" ]]; then - echo "[ERROR] para \"precision_mode\" must be config O1 or O2 or O3" - exit 1 - fi - PREC="--apex --apex-opt-level "$apex_opt_level - -elif [[ $para == --over_dump* ]];then - over_dump=`echo ${para#*=}` - over_dump_path=${cur_path}/output/overflow_dump - mkdir -p ${over_dump_path} - elif [[ $para == --data_dump_flag* ]];then - data_dump_flag=`echo ${para#*=}` - data_dump_path=${cur_path}/output/data_dump - mkdir -p ${data_dump_path} - elif [[ $para == --data_dump_step* ]];then - data_dump_step=`echo ${para#*=}` - elif [[ $para == --profiling* ]];then - profiling=`echo ${para#*=}` - profiling_dump_path=${cur_path}/output/profiling - mkdir -p ${profiling_dump_path} - elif [[ $para == --data_path* ]];then - data_path=`echo ${para#*=}` - elif [[ $para == --conda_name* ]];then - conda_name=`echo ${para#*=}` - source set_conda.sh - source activate $conda_name -fi - -done - -#校验是否传入data_path,不需要修改 -if [[ $data_path == "" ]];then - echo "[Error] para \"data_path\" must be confing" -# exit 1 -fi - -#训练开始时间,不需要修改 -start_time=$(date +%s) - -#进入训练脚本目录,需要模型审视修改 -cd $cur_path/../ -for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); -do - #设置环境变量,不需要修改 - echo "Device ID: $ASCEND_DEVICE_ID" - export RANK_ID=$RANK_ID - - - - #创建DeviceID输出目录,不需要修改 - if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then - rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - else - mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt - fi - - #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 - #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` - #cpustep=`expr $cpucount / 8` - #echo "taskset c steps:" $cpustep - #let a=RANK_ID*$cpustep - #let b=RANK_ID+1 - #let c=b*$cpustep-1 - - #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 - python3 WideDeep/train.py --train_batch_size=${batch_size} --Epochs=${epoch} --graph_mode > $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & -done -wait - -#conda deactivate -#训练结束时间,不需要修改 -end_time=$(date +%s) -e2e_time=$(( $end_time - $start_time )) - -#结果打印,不需要修改 -echo "------------------ Final result ------------------" -#输出性能FPS,需要模型审视修改 -Time=`grep Time $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "Time" '{print $2}' |tail -n +3 | awk '{sum+=$1} END {print"", sum/NR}'|sed s/[[:space:]]//g` -FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${Time}'}'` - - -#打印,不需要修改 -echo "Final Performance images/sec : $FPS" - -#输出训练精度,需要模型审视修改 -#train_accuracy=`grep Loss $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log| awk -F " " '{print $10}'` -#打印,不需要修改 -echo "Final Train Accuracy : ${train_accuracy}" -echo "E2E Training Duration sec : $e2e_time" - -#稳定性精度看护结果汇总 -#训练用例信息,不需要修改 -BatchSize=${batch_size} -DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' - -##获取性能数据 -#吞吐量,不需要修改 -ActualFPS=${FPS} -#单迭代训练时长,不需要修改 -TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` - -#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 -grep Time $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "Time" '{print $2}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt - -#最后一个迭代loss值,不需要修改 -ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` - -#关键信息打印到${CaseName}.log中,不需要修改 -echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log -echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#!/bin/bash + +#当前路径,不需要修改 +cur_path=`pwd` +export ASCEND_SLOG_PRINT_TO_STDOUT=0 +export NPU_CALCULATE_DEVICE=$ASCEND_DEVICE_ID +#集合通信参数,不需要修改 + +export RANK_SIZE=1 +export JOB_ID=10087 +RANK_ID_START=0 + +#进入到conda环境 + +#export PATH=/usr/local/python3.7.5/bin:/home/anaconda3/bin:$PATH +#export LD_LIBRARY_PATH=/home/anaconda3/lib:$LD_LIBRARY_PATH +#source activate py8 + +# 数据集路径,保持为空,不需要修改 +data_path="" + +#基础参数,需要模型审视修改 +#网络名称,同目录名称 +Network="Widedeep_ID3080_for_PyTorch" +#训练epoch +epoch=1 +#训练batch_size +train_batch_size=16 +batch_size=${train_batch_size} +#训练step +#train_steps=`expr 1281167 / ${batch_size}` +#学习率 +#learning_rate=0.495 +PREC="" +#TF2.X独有,不需要修改 +#export NPU_LOOP_SIZE=${train_steps} + +#维测参数,precision_mode需要模型审视修改 +precision_mode="allow_mix_precision" +#维持参数,以下不需要修改 +over_dump=False +data_dump_flag=False +data_dump_step="10" +profiling=False +autotune=False +data_path=./data/criteo_sampled_data.csv + +# 帮助信息,不需要修改 +if [[ $1 == --help || $1 == -h ]];then + echo"usage:./train_full_1p.sh " + echo " " + echo "parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message + " + exit 1 +fi + +#参数校验,不需要修改 +for para in $* +do + if [[ $para == --precision_mode* ]];then + apex_opt_level=`echo ${para#*=}` + if [[ $apex_opt_level != "O1" ]] && [[ $apex_opt_level != "O2" ]] && [[ $apex_opt_level != "O3" ]]; then + echo "[ERROR] para \"precision_mode\" must be config O1 or O2 or O3" + exit 1 + fi + PREC="--apex --apex-opt-level "$apex_opt_level + +elif [[ $para == --over_dump* ]];then + over_dump=`echo ${para#*=}` + over_dump_path=${cur_path}/output/overflow_dump + mkdir -p ${over_dump_path} + elif [[ $para == --data_dump_flag* ]];then + data_dump_flag=`echo ${para#*=}` + data_dump_path=${cur_path}/output/data_dump + mkdir -p ${data_dump_path} + elif [[ $para == --data_dump_step* ]];then + data_dump_step=`echo ${para#*=}` + elif [[ $para == --profiling* ]];then + profiling=`echo ${para#*=}` + profiling_dump_path=${cur_path}/output/profiling + mkdir -p ${profiling_dump_path} + elif [[ $para == --data_path* ]];then + data_path=`echo ${para#*=}` + elif [[ $para == --conda_name* ]];then + conda_name=`echo ${para#*=}` + source set_conda.sh + source activate $conda_name +fi + +done + +#校验是否传入data_path,不需要修改 +if [[ $data_path == "" ]];then + echo "[Error] para \"data_path\" must be confing" +# exit 1 +fi + +#训练开始时间,不需要修改 +start_time=$(date +%s) + +#进入训练脚本目录,需要模型审视修改 +cd $cur_path/../ +for((RANK_ID=$RANK_ID_START;RANK_ID<$((RANK_SIZE+RANK_ID_START));RANK_ID++)); +do + #设置环境变量,不需要修改 + echo "Device ID: $ASCEND_DEVICE_ID" + export RANK_ID=$RANK_ID + + + + #创建DeviceID输出目录,不需要修改 + if [ -d ${cur_path}/output/${ASCEND_DEVICE_ID} ];then + rm -rf ${cur_path}/output/${ASCEND_DEVICE_ID} + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + else + mkdir -p ${cur_path}/output/$ASCEND_DEVICE_ID/ckpt + fi + + #绑核,不需要绑核的模型删除,需要绑核的模型根据实际修改 + #cpucount=`lscpu | grep "CPU(s):" | head -n 1 | awk '{print $2}'` + #cpustep=`expr $cpucount / 8` + #echo "taskset c steps:" $cpustep + #let a=RANK_ID*$cpustep + #let b=RANK_ID+1 + #let c=b*$cpustep-1 + + #执行训练脚本,以下传参不需要修改,其他需要模型审视修改 + python3 WideDeep/train.py --train_batch_size=${batch_size} --Epochs=${epoch} --graph_mode > $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & +done +wait + +#conda deactivate +#训练结束时间,不需要修改 +end_time=$(date +%s) +e2e_time=$(( $end_time - $start_time )) + +#结果打印,不需要修改 +echo "------------------ Final result ------------------" +#输出性能FPS,需要模型审视修改 +Time=`grep Time $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "Time" '{print $2}' |tail -n +3 | awk '{sum+=$1} END {print"", sum/NR}'|sed s/[[:space:]]//g` +FPS=`awk 'BEGIN{printf "%.2f\n",'${batch_size}'/'${Time}'}'` + + +#打印,不需要修改 +echo "Final Performance images/sec : $FPS" + +#输出训练精度,需要模型审视修改 +#train_accuracy=`grep Loss $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log| awk -F " " '{print $10}'` +#打印,不需要修改 +echo "Final Train Accuracy : ${train_accuracy}" +echo "E2E Training Duration sec : $e2e_time" + +#稳定性精度看护结果汇总 +#训练用例信息,不需要修改 +BatchSize=${batch_size} +DeviceType=`uname -m` +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' + +##获取性能数据 +#吞吐量,不需要修改 +ActualFPS=${FPS} +#单迭代训练时长,不需要修改 +TrainingTime=`awk 'BEGIN{printf "%.2f\n",'${BatchSize}'*1000/'${FPS}'}'` + +#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视 +grep Time $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "Time" '{print $2}' > $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt + +#最后一个迭代loss值,不需要修改 +ActualLoss=`awk 'END {print}' $cur_path/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt` + +#关键信息打印到${CaseName}.log中,不需要修改 +echo "Network = ${Network}" > $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "RankSize = ${RANK_SIZE}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "BatchSize = ${BatchSize}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "DeviceType = ${DeviceType}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "CaseName = ${CaseName}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualFPS = ${ActualFPS}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "TrainingTime = ${TrainingTime}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +#echo "TrainAccuracy = ${train_accuracy}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "ActualLoss = ${ActualLoss}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log +echo "E2ETrainingTime = ${e2e_time}" >> $cur_path/output/$ASCEND_DEVICE_ID/${CaseName}.log diff --git a/README.CN.md b/README.CN.md index 059ea029af2f2f2b180cca984a55883a648a1ff3..d02f2d6226360c4016fc6fc38d0d795d0beb61b8 100644 --- a/README.CN.md +++ b/README.CN.md @@ -1,621 +1,621 @@ -# 欢迎使用Ascend ModelZoo - -为方便更多开发者使用Ascend ModelZoo,我们将持续增加典型网络和相关预训练模型。如果您有任何需求,请在[modelzoo/issues](https://gitee.com/ascend/modelzoo/issues)提交issue,我们会及时处理。 - -## 如何贡献 - -在开始贡献之前,请先阅读[CONTRIBUTING](https://gitee.com/ascend/modelzoo/blob/master/CONTRIBUTING.md)。 -谢谢! - -## 目录 - - -### PyTorch - -#### built-in - -- [3D_ResNet_ID0421_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/3D_ResNet_ID0421_for_PyTorch) -- [CRNN_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/CRNN_for_PyTorch) -- [DeepMar_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/DeepMar_for_PyTorch) -- [Densenet121_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch) -- [DenseNet161_ID0455_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/DenseNet161_ID0455_for_PyTorch) -- [DenseNet169_ID0454_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/DenseNet169_ID0454_for_PyTorch) -- [DenseNet201_ID0453_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/DenseNet201_ID0453_for_PyTorch) -- [EfficientNet-B1_ID1713_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/EfficientNet-B1_ID1713_for_PyTorch) -- [EfficientNet-B2_ID1714_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/EfficientNet-B2_ID1714_for_PyTorch) -- [EfficientNet-B3_ID0450_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/EfficientNet-B3_ID0450_for_PyTorch) -- [EfficientNet-B4_ID1632_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch) -- [EfficientNet-B5_ID1633_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch) -- [EfficientNet_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch) -- [FaceNet_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch) -- [Gluon_ResNet50_v1b_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1b_for_PyTorch) -- [Gluon_ResNet50_v1c_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch) -- [Gluon_ResNet50_v1d_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch) -- [Googlenet_ID0447_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/Googlenet_ID0447_for_PyTorch) -- [MobileNetV1_ID0094_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/MobileNetV1_ID0094_for_PyTorch) -- [MobileNetV2_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/MobileNetV2_for_PyTorch) -- [MobileNetV3-Large_ID1784_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/MobileNetV3-Large_ID1784_for_PyTorch) -- [ResNest_ID0426_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/ResNest_ID0426_for_PyTorch) -- [ResNet50_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch) -- [Shufflenetv2_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/Shufflenetv2_for_PyTorch) -- [DAL_ID2732_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/DAL_ID2732_for_PyTorch) -- [DB_ID0706_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch) -- [Faster_Mask_RCNN_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch) -- [PSENet_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/PSENet_for_PyTorch) -- [RetinaNet_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch) -- [RFCN_ID0418_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/RFCN_ID0418_for_PyTorch) -- [YoloV3_ID1790_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/YoloV3_ID1790_for_PyTorch) -- [YOLOV4_ID0396_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch) -- [Attention_R2U_Net_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch) -- [AttU_Net_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/semantic_segmentation/AttU_Net_for_PyTorch) -- [DeepLabv3+_ID1695_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/semantic_segmentation/DeepLabv3+_ID1695_for_PyTorch) -- [R2U_Net_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch) -- [Bert-Squad_ID0470_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/Bert-Squad_ID0470_for_PyTorch) -- [CPM_Finetune_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/CPM_Finetune_for_PyTorch) -- [FOTS_ID0338_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/FOTS_ID0338_for_PyTorch) -- [GRU_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/GRU_for_PyTorch) -- [LSTM_ID0468_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch) -- [mBART_ID2372_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/mBART_ID2372_for_PyTorch) -- [Transformer_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/Transformer_for_PyTorch) -- [XLM_ID0740_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/XLM_ID0740_for_PyTorch) -- [DCN_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/others/DCN_for_PyTorch) -- [DeepFM_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/others/DeepFM_for_PyTorch) -- [WDL_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/others/WDL_for_PyTorch) - -#### contrib - -- [baseline-rawnet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/audio/baseline-rawnet) -- [deepspeech](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/audio/deepspeech) -- [FastPitch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/audio/FastPitch) -- [speech-transformer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/audio/speech-transformer) -- [Tacotron2_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/audio/Tacotron2_for_PyTorch) -- [tdnn](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/audio/tdnn) -- [WaveGlow](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/audio/WaveGlow) -- [3d_attention_net](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/3d_attention_net) -- [AlexNet_ID2663_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/AlexNet_ID2663_for_PyTorch) -- [AlignedReID](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/AlignedReID) -- [csp_resnext50-mish](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/csp_resnext50-mish) -- [Deit_Small](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Deit_Small) -- [DnCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/DnCNN) -- [DPN-131_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/DPN-131_for_PyTorch) -- [Efficient-3DCNNs_ID1230_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Efficient-3DCNNs_ID1230_for_PyTorch) -- [EfficientNet-B1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/EfficientNet-B1) -- [EfficientNet-B3](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/EfficientNet-B3) -- [EfficientNet-B5_ID1621_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch) -- [FixRes](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/FixRes) -- [GaitSet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/GaitSet) -- [GENet_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/GENet_for_Pytorch) -- [GhostNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/GhostNet) -- [GoogleNet_ID1623_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/GoogleNet_ID1623_for_PyTorch) -- [HRNet_ID1780_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/HRNet_ID1780_for_PyTorch) -- [InceptionResNetV2_ID1779_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/InceptionResNetV2_ID1779_for_PyTorch) -- [InceptionV3_ID1596_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/InceptionV3_ID1596_for_PyTorch) -- [InceptionV4_ID1778_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/InceptionV4_ID1778_for_PyTorch) -- [LResNet100E-IR](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/LResNet100E-IR) -- [MGN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/MGN) -- [MnasNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/MnasNet) -- [MobileNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/MobileNet) -- [MobileNetV3_large_100_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/MobileNetV3_large_100_for_PyTorch) -- [Moco-v2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Moco-v2) -- [NASNet-A-Mobile](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/NASNet-A-Mobile) -- [OSNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/OSNet) -- [PCB](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/PCB) -- [PnasNet5Large](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/PnasNet5Large) -- [PointNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/PointNet) -- [pointnetCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/pointnetCNN) -- [RegNetX](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/RegNetX) -- [RegNetY-1.6GF](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/RegNetY-1.6GF) -- [ReidStrongBaseline](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ReidStrongBaseline) -- [RepVGG](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/RepVGG) -- [Res2Net101_v1b](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Res2Net101_v1b) -- [ResNeSt50_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ResNeSt50_for_PyTorch) -- [ResNet101_ID1595_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ResNet101_ID1595_for_PyTorch) -- [ResNet152](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ResNet152) -- [ResNet18_ID1593_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ResNet18_ID1593_for_PyTorch) -- [ResNet34_ID1594_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ResNet34_ID1594_for_PyTorch) -- [ResNeXt-50-32x4d_ID1624_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ResNeXt-50-32x4d_ID1624_for_PyTorch) -- [ResNeXt101_32x8d_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch) -- [SE-ResNet-50](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/SE-ResNet-50) -- [SE-ResNext-101-32x4d](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/SE-ResNext-101-32x4d) -- [Se-ResNext-50-32x4d](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d) -- [SENet154](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/SENet154) -- [ShuffleNetV1_ID1625_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ShuffleNetV1_ID1625_for_PyTorch) -- [ShuffleNetV2Plus_ID1626_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ShuffleNetV2Plus_ID1626_for_PyTorch) -- [SkresNet50](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/SkresNet50) -- [SPNASNet_100_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/SPNASNet_100_for_PyTorch) -- [SqueezeNet1_1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/SqueezeNet1_1) -- [Swin-Transformer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Swin-Transformer) -- [TNT](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/TNT) -- [TResNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/TResNet) -- [Vehicle_Re-Identification](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Vehicle_Re-Identification) -- [Vgg16_ID1630_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Vgg16_ID1630_for_PyTorch) -- [Vgg19_ID1631_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Vgg19_ID1631_for_PyTorch) -- [vit_base_patch32_224](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/vit_base_patch32_224) -- [Vit_small_patch16_224](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Vit_small_patch16_224) -- [VOLO](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/VOLO) -- [VoVNet39](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/VoVNet39) -- [WideResNet101_2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/WideResNet101_2_for_Pytorch) -- [WideResNet50_2_ID1627_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/WideResNet50_2_ID1627_for_PyTorch) -- [Xception_ID1777_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch) -- [xcit](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/xcit) -- [AdvancedEAST](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/AdvancedEAST) -- [CascadedMaskRCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/CascadedMaskRCNN) -- [Cascade_RCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/Cascade_RCNN) -- [CenterFace](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/CenterFace) -- [CenterNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/CenterNet) -- [DSFD](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/DSFD) -- [EfficientDetD0](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/EfficientDetD0) -- [FaceBoxes](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/FaceBoxes) -- [FairMOT](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/FairMOT) -- [FCOS](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/FCOS) -- [FOTS](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/FOTS) -- [FSAF_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/FSAF_for_Pytorch) -- [GFocalV2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/GFocalV2) -- [M2Det](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/M2Det) -- [NasFPN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/NasFPN) -- [Pointnetplus](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/Pointnetplus) -- [Pyramidbox](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/Pyramidbox) -- [RCF](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/RCF) -- [RefineDet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/RefineDet) -- [Retinaface](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/Retinaface) -- [RetinaNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/RetinaNet) -- [SimCLR_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch) -- [SOLOv1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/SOLOv1) -- [SOLOv2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/SOLOv2) -- [SSD](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/SSD) -- [SSD-MobileNetV1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/SSD-MobileNetV1) -- [SSD-MobilenetV2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/SSD-MobilenetV2) -- [SSD-Resnet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/SSD-Resnet) -- [StyleGAN2-ADA](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/StyleGAN2-ADA) -- [TextSnake](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/TextSnake) -- [YOLACT](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/YOLACT) -- [YOLACT_plus](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/YOLACT_plus) -- [YOLOR](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/YOLOR) -- [YOLOX](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/YOLOX) -- [ADNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/ADNet) -- [BigGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/BigGAN) -- [CGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/CGAN) -- [Cross-Scale-Non-Local-Attention](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/Cross-Scale-Non-Local-Attention) -- [CycleGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/CycleGAN) -- [DCGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/DCGAN) -- [edsr_x2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/edsr_x2) -- [GAN_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/GAN_Pytorch) -- [Pix2Pix](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/Pix2Pix) -- [RDN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/RDN) -- [Srcnn_x2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/Srcnn_x2_for_Pytorch) -- [SRFlow](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/SRFlow) -- [SRGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/SRGAN) -- [stargan](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/stargan) -- [wdsr](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/wdsr) -- [3Dmppe_RootNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet) -- [AlphaPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/AlphaPose) -- [DeepPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/DeepPose) -- [HigherHRNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/HigherHRNet) -- [Hourglass_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch) -- [Lightweight_OpenPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose) -- [MSPN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/MSPN) -- [ST-GCN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/ST-GCN) -- [TransPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/TransPose) -- [VoxelPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/VoxelPose) -- [3DUNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/3DUNet) -- [DeeplabV3_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/DeeplabV3_for_Pytorch) -- [ENet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/ENet) -- [ErfNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/ErfNet) -- [FastSCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/FastSCNN) -- [FCN8s](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/FCN8s) -- [HRnet-OCR](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/HRnet-OCR) -- [HRNet_SEG_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/HRNet_SEG_for_Pytorch) -- [ICNet_ID1781_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/ICNet_ID1781_for_PyTorch) -- [IntraDA](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/IntraDA) -- [PointRend](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/PointRend) -- [PraNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/PraNet) -- [PSPNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/PSPNet) -- [RCAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/RCAN) -- [RefineNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/RefineNet) -- [SETR](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/SETR) -- [Ultra-Fast-Lane-Detection](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/Ultra-Fast-Lane-Detection) -- [UNet++](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/UNet++) -- [UNet_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/UNet_for_PyTorch) -- [VNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/VNet) -- [Wseg](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/Wseg) -- [BMN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/BMN) -- [BSN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/BSN) -- [C3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/C3D) -- [GloRe](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/GloRe) -- [I3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/I3D) -- [NonLocal](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/NonLocal) -- [R(2+1)D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/R(2+1)D) -- [SiamFC](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/SiamFC) -- [SiamRPN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/SiamRPN) -- [SlowFast](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/SlowFast) -- [TSM](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/TSM) -- [TSN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/TSN) -- [VideoPose3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/VideoPose3D) -- [X3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/X3D) -- [albert](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/nlp/albert) -- [Bertsum_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/nlp/Bertsum_for_PyTorch) -- [roberta](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/nlp/roberta) -- [TextCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/nlp/TextCNN) -- [tinybert](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/nlp/tinybert) -- [C51](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/others/C51) -- [DLRM](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/others/DLRM) -- [DQN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/others/DQN) -- [RotatE](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/others/RotatE) - -#### dev - -- [tacotron2_ID0406_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/audio/tacotron2_ID0406_for_PyTorch) -- [3D_attentionnet_ID0478_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/detection/3D_attentionnet_ID0478_for_PyTorch) -- [FasterRCNN-Resnet50-FPN_ID1552_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/detection/FasterRCNN-Resnet50-FPN_ID1552_for_PyTorch) -- [HRNet_ID0446_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/detection/HRNet_ID0446_for_PyTorch) -- [PointNet_ID0430_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/detection/PointNet_ID0430_for_PyTorch) -- [SSD-ResNet34_ID0411_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/detection/SSD-ResNet34_ID0411_for_PyTorch) -- [2D_Unet_ID0624_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/2D_Unet_ID0624_for_PyTorch) -- [2S-AGCN_ID0909_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/2S-AGCN_ID0909_for_PyTorch) -- [3D_Nest_Unet_ID0476_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/3D_Nest_Unet_ID0476_for_PyTorch) -- [ADACOS_ID1082_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ADACOS_ID1082_for_PyTorch) -- [AdaFM-Net_ID1101_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/AdaFM-Net_ID1101_for_PyTorch) -- [ADLayer_ID1087_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ADLayer_ID1087_for_PyTorch) -- [AdvancedEast_ID0473_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/AdvancedEast_ID0473_for_PyTorch) -- [AlexNet_ID0472_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/AlexNet_ID0472_for_PyTorch) -- [ANN_ID2370_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ANN_ID2370_for_PyTorch) -- [ArcFace_ID0852_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ArcFace_ID0852_for_PyTorch) -- [ATS_ID2682_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ATS_ID2682_for_PyTorch) -- [AUTOAUGMENT_ID0792_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/AUTOAUGMENT_ID0792_for_PyTorch) -- [BASNET_ID1134_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/BASNET_ID1134_for_PyTorch) -- [BertBase_ID0490_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/BertBase_ID0490_for_PyTorch) -- [CDAR_ID2747_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/CDAR_ID2747_for_PyTorch) -- [ConvLSTM_ID1772_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ConvLSTM_ID1772_for_PyTorch) -- [coral-cnn_ID1064_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/coral-cnn_ID1064_for_PyTorch) -- [CrossFormer_ID2449_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/CrossFormer_ID2449_for_PyTorch) -- [CycleGAN_ID0521_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/CycleGAN_ID0521_for_PyTorch) -- [DBPN_ID2917_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/DBPN_ID2917_for_PyTorch) -- [DCAP_ID2836_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/DCAP_ID2836_for_PyTorch) -- [DEEP-HEAD-POSE_ID0796_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/DEEP-HEAD-POSE_ID0796_for_PyTorch) -- [DeepLab-CRF_ID1873_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/DeepLab-CRF_ID1873_for_PyTorch) -- [DeepSort_ID0654_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch) -- [deit_ID2467_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/deit_ID2467_for_PyTorch) -- [DGMS_ID2460_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/DGMS_ID2460_for_PyTorch) -- [EfficientNet-B6_ID1715_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/EfficientNet-B6_ID1715_for_PyTorch) -- [EfficientNet-B7_ID1716_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/EfficientNet-B7_ID1716_for_PyTorch) -- [ESPCN_ID2919_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ESPCN_ID2919_for_PyTorch) -- [ESPCN_ID3002_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ESPCN_ID3002_for_PyTorch) -- [ESRGAN_ID1813_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ESRGAN_ID1813_for_PyTorch) -- [FasterRCNN_ID0100_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/FasterRCNN_ID0100_for_PyTorch) -- [FFDNet_ID0970_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/FFDNet_ID0970_for_PyTorch) -- [FixMatch_ID0989_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/FixMatch_ID0989_for_PyTorch) -- [GENet_ID0671_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/GENet_ID0671_for_PyTorch) -- [GhostNet_ID1622_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/GhostNet_ID1622_for_PyTorch) -- [Hourglass_ID1809_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Hourglass_ID1809_for_PyTorch) -- [ICT_ID1179_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ICT_ID1179_for_PyTorch) -- [InceptionV1_ID1568_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/InceptionV1_ID1568_for_PyTorch) -- [InceptionV2_ID0698_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/InceptionV2_ID0698_for_PyTorch) -- [InceptionV3_ID0445_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch) -- [InceptionV4_ID0444_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/InceptionV4_ID0444_for_PyTorch) -- [InceptionV4_ID2473_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/InceptionV4_ID2473_for_PyTorch) -- [Keyword-MLP_ID2441_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Keyword-MLP_ID2441_for_PyTorch) -- [LADE_ID2445_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/LADE_ID2445_for_PyTorch) -- [MaskRCNN_ID0101_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/MaskRCNN_ID0101_for_PyTorch) -- [mBART_ID1550_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/mBART_ID1550_for_PyTorch) -- [MMAL-NET_ID1116_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/MMAL-NET_ID1116_for_PyTorch) -- [MMOE_ID2865_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/MMOE_ID2865_for_PyTorch) -- [Mnasnet0_75_ID0439_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Mnasnet0_75_ID0439_for_PyTorch) -- [Mnasnet1_0_ID0438_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Mnasnet1_0_ID0438_for_PyTorch) -- [Mnasnet1_3_ID0437_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Mnasnet1_3_ID0437_for_PyTorch) -- [mobilenetv2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/mobilenetv2_for_Pytorch) -- [MobileNetV3-Small_ID1785_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/MobileNetV3-Small_ID1785_for_PyTorch) -- [MSPN_ID0960_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/MSPN_ID0960_for_PyTorch) -- [MTCNN_ID0435_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/MTCNN_ID0435_for_PyTorch) -- [Mutual-Channel-Loss_ID1113_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Mutual-Channel-Loss_ID1113_for_PyTorch) -- [NeuMF_ID0351_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/NeuMF_ID0351_for_PyTorch) -- [PASSRnet_ID0986_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/PASSRnet_ID0986_for_PyTorch) -- [pFedMe_ID1597_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/pFedMe_ID1597_for_PyTorch) -- [PFF_ID1128_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/PFF_ID1128_for_PyTorch) -- [PiT_ID2671_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/PiT_ID2671_for_PyTorch) -- [Pix2Pix_ID0331_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Pix2Pix_ID0331_for_PyTorch) -- [POOLNET_ID0875_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/POOLNET_ID0875_for_PyTorch) -- [Pysot_ID0428_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Pysot_ID0428_for_PyTorch) -- [RAFT_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/RAFT_for_PyTorch) -- [RANet_ID0994_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/RANet_ID0994_for_PyTorch) -- [RES2NET_ID0824_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/RES2NET_ID0824_for_PyTorch) -- [residual_adapters_ID1598_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/residual_adapters_ID1598_for_PyTorch) -- [Resnet101_ID0425_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Resnet101_ID0425_for_PyTorch) -- [ResNet152_ID0424_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch) -- [Resnet152_ID1592_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Resnet152_ID1592_for_PyTorch) -- [Resnet18_ID0423_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Resnet18_ID0423_for_PyTorch) -- [Resnet34_ID0422_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Resnet34_ID0422_for_PyTorch) -- [Resnext101_32x8d_ID0420_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Resnext101_32x8d_ID0420_for_PyTorch) -- [ResNeXt101_ID1717_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ResNeXt101_ID1717_for_PyTorch) -- [ResNeXt50_ID0419_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ResNeXt50_ID0419_for_PyTorch) -- [RRN_ID1182_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/RRN_ID1182_for_PyTorch) -- [RUC_ID2470_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/RUC_ID2470_for_PyTorch) -- [SEResNext_ID0415_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SEResNext_ID0415_for_PyTorch) -- [SG2IM_ID0786_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SG2IM_ID0786_for_PyTorch) -- [SimplePose_ID1038_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SimplePose_ID1038_for_PyTorch) -- [SINGLESHOTPOSE_ID0869_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SINGLESHOTPOSE_ID0869_for_PyTorch) -- [SlowFast_ID0646_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SlowFast_ID0646_for_PyTorch) -- [SmartSketch_ID1046_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SmartSketch_ID1046_for_PyTorch) -- [SqueezeNet_ID0413_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SqueezeNet_ID0413_for_PyTorch) -- [SRCNN_ID1770_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SRCNN_ID1770_for_PyTorch) -- [SRGAN_ID2956_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SRGAN_ID2956_for_PyTorch) -- [SSD-MobileNet_ID1936_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SSD-MobileNet_ID1936_for_PyTorch) -- [STARGAN_ID0725_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/STARGAN_ID0725_for_PyTorch) -- [Swin-Transformer_ID2377_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Swin-Transformer_ID2377_for_PyTorch) -- [TabNet_ID2862_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/TabNet_ID2862_for_PyTorch) -- [Token-to-Token-ViT_ID2668_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Token-to-Token-ViT_ID2668_for_PyTorch) -- [TransformerXL_ID0699_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/TransformerXL_ID0699_for_PyTorch) -- [VAE+GAN_ID0401_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/VAE+GAN_ID0401_for_PyTorch) -- [VGG16_ID0467_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/VGG16_ID0467_for_PyTorch) -- [VGG19_ID0244_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/VGG19_ID0244_for_PyTorch) -- [VGGNet_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch) -- [VGGNet_ID0400_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/VGGNet_ID0400_for_PyTorch) -- [vit-base_ID0492_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/vit-base_ID0492_for_PyTorch) -- [VIT_ID2381_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/VIT_ID2381_for_PyTorch) -- [Wide_resnet101_2_ID0398_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Wide_resnet101_2_ID0398_for_PyTorch) -- [Wide_resnet50_2_ID0397_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Wide_resnet50_2_ID0397_for_PyTorch) -- [Xception_ID1454_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Xception_ID1454_for_PyTorch) -- [ZERO-DCE_ID1040_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ZERO-DCE_ID1040_for_PyTorch) -- [deeplabv3+_ID0326_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_segmentation/deeplabv3+_ID0326_for_PyTorch) -- [DeepLabV3+_ID0458_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch) -- [DeepLabV3_ID0621_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_segmentation/DeepLabV3_ID0621_for_PyTorch) -- [SETR_ID1572_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_segmentation/SETR_ID1572_for_PyTorch) -- [GAN_ID1931_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_synthesis/GAN_ID1931_for_PyTorch) -- [DSCNN_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch) -- [FFA-NET_ID1043_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/quality_enhancement/FFA-NET_ID1043_for_PyTorch) -- [BERT-ITPT-FiT_ID0340_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/BERT-ITPT-FiT_ID0340_for_PyTorch) -- [BERT_base_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/BERT_base_for_PyTorch) -- [FairSeq_Transformer_ID0496_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/FairSeq_Transformer_ID0496_for_PyTorch) -- [Retinanet_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/Retinanet_for_PyTorch) -- [Speech_Transformer_ID0487_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/Speech_Transformer_ID0487_for_PyTorch) -- [Swin-Transformer_ID2375_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/Swin-Transformer_ID2375_for_PyTorch) -- [Swin-Transformer_ID2379_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/Swin-Transformer_ID2379_for_PyTorch) -- [Textcnn_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/Textcnn_for_PyTorch) -- [Transformer_ID0105_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/Transformer_ID0105_for_PyTorch) -- [Multi-Gradient_Descent_ID0349_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/others/Multi-Gradient_Descent_ID0349_for_PyTorch) -- [Widedeep_ID2866_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/others/Widedeep_ID2866_for_PyTorch) - -### ACL_PyTorch - -#### built-in - -- [EspNet_for_Pytoch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/audio/EspNet_for_Pytoch) -- [Jasper_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/audio/Jasper_for_PyTorch) -- [LSTM](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/audio/LSTM) -- [RawNet2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch) -- [Tacotron2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/audio/Tacotron2_for_Pytorch) -- [TDNN_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch) -- [Wenet_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch) -- [3DUnet_for_PTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/3DUnet_for_PTorch) -- [CascadeRCNN-DCN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/CascadeRCNN-DCN) -- [CascadeRCNN-DCN-101_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/CascadeRCNN-DCN-101_for_Pytorch) -- [CenterNet_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch) -- [CRNN_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch) -- [DB_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/DB_for_PyTorch) -- [Deepmar_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch) -- [Deepsort_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Deepsort_for_Pytorch) -- [Densenet121_Pytorch_Infer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Densenet121_Pytorch_Infer) -- [DPN131_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/DPN131_for_Pytorch) -- [EfficientNet_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch) -- [FasterRCNN-DCN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/FasterRCNN-DCN) -- [Flownet2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Flownet2_for_Pytorch) -- [GoogleNet_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/GoogleNet_for_Pytorch) -- [I3D_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/I3D_for_Pytorch) -- [InceptionV3_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch) -- [InceptionV4_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/InceptionV4_for_Pytorch) -- [MobileNetV2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch) -- [Pelee_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Pelee_for_Pytorch) -- [PSENet_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch) -- [Res2Net_v1b_101_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch) -- [Resnet101_Pytorch_Infer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer) -- [Resnet18_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch) -- [Resnet34_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Resnet34_for_Pytorch) -- [Resnet50_Pytorch_Infer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Resnet50_Pytorch_Infer) -- [ResNeXt50_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/ResNeXt50_for_Pytorch) -- [SE_ResNet50_Pytorch_Infer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer) -- [Shufflenetv2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch) -- [STGCN_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/STGCN_for_Pytorch) -- [U2-Net_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/U2-Net_for_PyTorch) -- [Vgg16_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch) -- [VGG16_SSD_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/VGG16_SSD_for_PyTorch) -- [Vgg19_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch) -- [Wide_ResNet50_2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Wide_ResNet50_2_for_Pytorch) -- [YolactEdge_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch) -- [Yolov3_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch) -- [Yolov4_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch) -- [Yolov5_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Yolov5_for_Pytorch) -- [Bert_Base_Uncased](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased) -- [CNN_Transformer_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch) -- [textcnn](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/nlp/textcnn) -- [TransformerXL_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/nlp/TransformerXL_for_Pytorch) -- [VilBert_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/nlp/VilBert_for_Pytorch) - -#### contrib - -- [FastPitch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/audio/FastPitch) -- [Jasper](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/audio/Jasper) -- [Speech-Transformer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/audio/Speech-Transformer) -- [tdnn](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/audio/tdnn) -- [3d_attention_net](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/3d_attention_net) -- [AlexNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/AlexNet) -- [baseline_dino_resnet50](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50) -- [BMN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/BMN) -- [C3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/C3D) -- [CSPResneXt50](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/CSPResneXt50) -- [Deit_Small](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Deit_Small) -- [DPN131](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/DPN131) -- [Efficient-3DCNNs](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs) -- [EfficientNet-B1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1) -- [EfficientNet-B3](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B3) -- [EfficientNet-B5](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B5) -- [FixRes](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/FixRes) -- [GaitSet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/GaitSet) -- [GENet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/GENet) -- [GhostNet1.0x](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x) -- [GloRe](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/GloRe) -- [HRNet-Image-Classification](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification) -- [InceptionResnetV2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/InceptionResnetV2) -- [LResNet100E-IR](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/LResNet100E-IR) -- [LV-Vit](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/LV-Vit) -- [Mnasnet1_0](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Mnasnet1_0) -- [MobileNet-v1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/MobileNet-v1) -- [MobileNetV3_large_100](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/MobileNetV3_large_100) -- [Moco-v2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Moco-v2) -- [OSNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/OSNet) -- [PAMTRI](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/PAMTRI) -- [pnasnet5large](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/pnasnet5large) -- [PointNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/PointNet) -- [PointNetCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/PointNetCNN) -- [Pointnetplus](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Pointnetplus) -- [R(2+1)D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/R(2+1)D) -- [RegNetX-1.6GF](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/RegNetX-1.6GF) -- [RegNetY-1.6GF](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/RegNetY-1.6GF) -- [ReID_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/ReID_for_Pytorch) -- [RepVGG](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/RepVGG) -- [Res2Net101_v1b](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b) -- [ResNeSt50](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/ResNeSt50) -- [ResNet101](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/ResNet101) -- [ResNet152](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/ResNet152) -- [ResNet18](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/ResNet18) -- [ResNet34](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/ResNet34) -- [ResNext101_32x8d](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/ResNext101_32x8d) -- [Se-Resnext101](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Se-Resnext101) -- [SENet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/SENet) -- [Shufflenetv1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1) -- [Shufflenetv2+](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+) -- [SimCLR_inference](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/SimCLR_inference) -- [Sknet50](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Sknet50) -- [spnasnet_100](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/spnasnet_100) -- [Squeezenet1_1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Squeezenet1_1) -- [Swin-Transformer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Swin-Transformer) -- [TNT](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/TNT) -- [TResNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/TResNet) -- [vit-small](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/vit-small) -- [vit_base_patch32_224](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224) -- [vovnet39](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/vovnet39) -- [Wide_ResNet101_2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2) -- [X3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/X3D) -- [xception](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/xception) -- [xcit](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/xcit) -- [3DUnet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/3DUnet) -- [AdvancedEAST](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/AdvancedEAST) -- [AlphaPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/AlphaPose) -- [BSN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/BSN) -- [Cascade-RCNN-Resnet101-FPN-DCN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN) -- [Cascade_RCNN_R101](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101) -- [CenterFace](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/CenterFace) -- [CenterNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/CenterNet) -- [CTPN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/CTPN) -- [Deepspeech](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Deepspeech) -- [Detr](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Detr) -- [DSFD](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/DSFD) -- [EfficientDetD0](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/EfficientDetD0) -- [EfficientDetD7](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/EfficientDetD7) -- [FairMOT](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/FairMOT) -- [FasterRCNN_FPN_DCN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/FasterRCNN_FPN_DCN) -- [Fcos](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Fcos) -- [FOTS](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/FOTS) -- [Fsaf](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Fsaf) -- [GFocalV2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/GFocalV2) -- [M2Det](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/M2Det) -- [Nasnetlarge](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Nasnetlarge) -- [NAS_FPN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/NAS_FPN) -- [OpenPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/OpenPose) -- [pyramidbox](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/pyramidbox) -- [RCF](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/RCF) -- [RefineDet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/RefineDet) -- [Retinanet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Retinanet) -- [RFCN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/RFCN) -- [SSD](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/SSD) -- [SSD-MobileNetV1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV1) -- [SSD-MobileNetV2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV2) -- [SSD-Resnet34](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/SSD-Resnet34) -- [TextSnake](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/TextSnake) -- [yolor](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/yolor) -- [YOLOX](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/YOLOX) -- [AlignedReID](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/face/AlignedReID) -- [FaceBoxes](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/face/FaceBoxes) -- [FaceNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/face/FaceNet) -- [ReId-MGN-master](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/face/ReId-MGN-master) -- [reid_PCB_baseline](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline) -- [Retinaface](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/face/Retinaface) -- [BigGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/BigGAN) -- [CGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/CGAN) -- [CycleGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/CycleGAN) -- [DCGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/DCGAN) -- [GAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/GAN) -- [Pix2Pix](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/Pix2Pix) -- [Pix2pixHD](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/Pix2pixHD) -- [StarGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/StarGAN) -- [Cross-Scale-Non-Local-Attention](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention) -- [DnCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/image_process/DnCNN) -- [SRFlow](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/image_process/SRFlow) -- [wdsr](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/image_process/wdsr) -- [3DMPPE-ROOTNET](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET) -- [HigherHRNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/pose_estimation/HigherHRNet) -- [MSPN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/pose_estimation/MSPN) -- [TransPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/pose_estimation/TransPose) -- [VideoPose3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/pose_estimation/VideoPose3D) -- [ADNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet) -- [SRGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/quality_enhancement/SRGAN) -- [3D_HRNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/3D_HRNet) -- [Cascade_Mask_RCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/Cascade_Mask_RCNN) -- [Cascade_RCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/Cascade_RCNN) -- [DeeplabV3](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3) -- [ENet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/ENet) -- [ErfNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/ErfNet) -- [FastSCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/FastSCNN) -- [FCN-8s](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/FCN-8s) -- [GCNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/GCNet) -- [ICNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/ICNet) -- [IntraDA](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/IntraDA) -- [Nested_UNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/Nested_UNet) -- [PointRend](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/PointRend) -- [PraNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/PraNet) -- [PSPnet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/PSPnet) -- [RefineNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/RefineNet) -- [SETR](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/SETR) -- [SiamMask](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/SiamMask) -- [SOLOV1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/SOLOV1) -- [SOLOV2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/SOLOV2) -- [Ultra-Fast-Lane-Detection](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/Ultra-Fast-Lane-Detection) -- [VNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/VNet) -- [Wseg](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/Wseg) -- [YOLACT](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/YOLACT) -- [YOLACT_plus](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus) -- [EDSR](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/super_resolution/EDSR) -- [RCAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/super_resolution/RCAN) -- [RDN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/super_resolution/RDN) -- [Real-ESRGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN) -- [SRCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/super_resolution/SRCNN) -- [SiamFC](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/tracking/SiamFC) -- [SiamRPN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/tracking/SiamRPN) -- [I3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/video_understanding/I3D) -- [NonLocal](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/video_understanding/NonLocal) -- [SlowFast](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/video_understanding/SlowFast) -- [TSM](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/video_understanding/TSM) -- [TSN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/video_understanding/TSN) -- [RotatE](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/knowledge/RotatE) -- [albert](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/nlp/albert) -- [BertSum](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/nlp/BertSum) -- [CNN_Transformer_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/nlp/CNN_Transformer_for_Pytorch) -- [roberta](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/nlp/roberta) -- [TextCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/nlp/TextCNN) -- [tinybert](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/nlp/tinybert) -- [c51](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/rl/c51) -- [DQN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/rl/DQN) - - - - - - - -## 免责声明 - -Ascend ModelZoo仅提供公共数据集下载和预处理脚本。这些数据集不属于ModelZoo,ModelZoo也不对其质量或维护负责。请确保您具有这些数据集的使用许可。基于这些数据集训练的模型仅可用于非商业研究和教育。 - -致数据集所有者: - -如果您不希望您的数据集公布在ModelZoo上或希望更新ModelZoo中属于您的数据集,请在Github/Gitee提交issue,我们将根据您的issue删除或更新您的数据集。衷心感谢您对我们社区的理解和贡献。 - -Ascend ModelZoo的license是Apache 2.0.具体内容,请参见LICENSE文件。 +# 欢迎使用Ascend ModelZoo + +为方便更多开发者使用Ascend ModelZoo,我们将持续增加典型网络和相关预训练模型。如果您有任何需求,请在[modelzoo/issues](https://gitee.com/ascend/modelzoo/issues)提交issue,我们会及时处理。 + +## 如何贡献 + +在开始贡献之前,请先阅读[CONTRIBUTING](https://gitee.com/ascend/modelzoo/blob/master/CONTRIBUTING.md)。 +谢谢! + +## 目录 + + +### PyTorch + +#### built-in + +- [3D_ResNet_ID0421_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/3D_ResNet_ID0421_for_PyTorch) +- [CRNN_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/CRNN_for_PyTorch) +- [DeepMar_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/DeepMar_for_PyTorch) +- [Densenet121_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/Densenet121_for_PyTorch) +- [DenseNet161_ID0455_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/DenseNet161_ID0455_for_PyTorch) +- [DenseNet169_ID0454_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/DenseNet169_ID0454_for_PyTorch) +- [DenseNet201_ID0453_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/DenseNet201_ID0453_for_PyTorch) +- [EfficientNet-B1_ID1713_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/EfficientNet-B1_ID1713_for_PyTorch) +- [EfficientNet-B2_ID1714_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/EfficientNet-B2_ID1714_for_PyTorch) +- [EfficientNet-B3_ID0450_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/EfficientNet-B3_ID0450_for_PyTorch) +- [EfficientNet-B4_ID1632_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/EfficientNet-B4_ID1632_for_PyTorch) +- [EfficientNet-B5_ID1633_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/EfficientNet-B5_ID1633_for_PyTorch) +- [EfficientNet_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/EfficientNet_for_PyTorch) +- [FaceNet_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/FaceNet_for_PyTorch) +- [Gluon_ResNet50_v1b_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1b_for_PyTorch) +- [Gluon_ResNet50_v1c_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1c_for_PyTorch) +- [Gluon_ResNet50_v1d_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/Gluon_ResNet50_v1d_for_PyTorch) +- [Googlenet_ID0447_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/Googlenet_ID0447_for_PyTorch) +- [MobileNetV1_ID0094_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/MobileNetV1_ID0094_for_PyTorch) +- [MobileNetV2_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/MobileNetV2_for_PyTorch) +- [MobileNetV3-Large_ID1784_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/MobileNetV3-Large_ID1784_for_PyTorch) +- [ResNest_ID0426_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/ResNest_ID0426_for_PyTorch) +- [ResNet50_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/ResNet50_for_PyTorch) +- [Shufflenetv2_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/classification/Shufflenetv2_for_PyTorch) +- [DAL_ID2732_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/DAL_ID2732_for_PyTorch) +- [DB_ID0706_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch) +- [Faster_Mask_RCNN_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch) +- [PSENet_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/PSENet_for_PyTorch) +- [RetinaNet_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/RetinaNet_for_PyTorch) +- [RFCN_ID0418_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/RFCN_ID0418_for_PyTorch) +- [YoloV3_ID1790_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/YoloV3_ID1790_for_PyTorch) +- [YOLOV4_ID0396_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/detection/YOLOV4_ID0396_for_PyTorch) +- [Attention_R2U_Net_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/semantic_segmentation/Attention_R2U_Net_for_PyTorch) +- [AttU_Net_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/semantic_segmentation/AttU_Net_for_PyTorch) +- [DeepLabv3+_ID1695_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/semantic_segmentation/DeepLabv3+_ID1695_for_PyTorch) +- [R2U_Net_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/cv/semantic_segmentation/R2U_Net_for_PyTorch) +- [Bert-Squad_ID0470_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/Bert-Squad_ID0470_for_PyTorch) +- [CPM_Finetune_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/CPM_Finetune_for_PyTorch) +- [FOTS_ID0338_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/FOTS_ID0338_for_PyTorch) +- [GRU_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/GRU_for_PyTorch) +- [LSTM_ID0468_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch) +- [mBART_ID2372_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/mBART_ID2372_for_PyTorch) +- [Transformer_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/Transformer_for_PyTorch) +- [XLM_ID0740_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/nlp/XLM_ID0740_for_PyTorch) +- [DCN_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/others/DCN_for_PyTorch) +- [DeepFM_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/others/DeepFM_for_PyTorch) +- [WDL_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/built-in/others/WDL_for_PyTorch) + +#### contrib + +- [baseline-rawnet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/audio/baseline-rawnet) +- [deepspeech](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/audio/deepspeech) +- [FastPitch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/audio/FastPitch) +- [speech-transformer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/audio/speech-transformer) +- [Tacotron2_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/audio/Tacotron2_for_PyTorch) +- [tdnn](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/audio/tdnn) +- [WaveGlow](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/audio/WaveGlow) +- [3d_attention_net](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/3d_attention_net) +- [AlexNet_ID2663_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/AlexNet_ID2663_for_PyTorch) +- [AlignedReID](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/AlignedReID) +- [csp_resnext50-mish](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/csp_resnext50-mish) +- [Deit_Small](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Deit_Small) +- [DnCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/DnCNN) +- [DPN-131_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/DPN-131_for_PyTorch) +- [Efficient-3DCNNs_ID1230_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Efficient-3DCNNs_ID1230_for_PyTorch) +- [EfficientNet-B1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/EfficientNet-B1) +- [EfficientNet-B3](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/EfficientNet-B3) +- [EfficientNet-B5_ID1621_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/EfficientNet-B5_ID1621_for_PyTorch) +- [FixRes](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/FixRes) +- [GaitSet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/GaitSet) +- [GENet_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/GENet_for_Pytorch) +- [GhostNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/GhostNet) +- [GoogleNet_ID1623_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/GoogleNet_ID1623_for_PyTorch) +- [HRNet_ID1780_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/HRNet_ID1780_for_PyTorch) +- [InceptionResNetV2_ID1779_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/InceptionResNetV2_ID1779_for_PyTorch) +- [InceptionV3_ID1596_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/InceptionV3_ID1596_for_PyTorch) +- [InceptionV4_ID1778_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/InceptionV4_ID1778_for_PyTorch) +- [LResNet100E-IR](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/LResNet100E-IR) +- [MGN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/MGN) +- [MnasNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/MnasNet) +- [MobileNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/MobileNet) +- [MobileNetV3_large_100_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/MobileNetV3_large_100_for_PyTorch) +- [Moco-v2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Moco-v2) +- [NASNet-A-Mobile](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/NASNet-A-Mobile) +- [OSNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/OSNet) +- [PCB](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/PCB) +- [PnasNet5Large](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/PnasNet5Large) +- [PointNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/PointNet) +- [pointnetCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/pointnetCNN) +- [RegNetX](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/RegNetX) +- [RegNetY-1.6GF](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/RegNetY-1.6GF) +- [ReidStrongBaseline](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ReidStrongBaseline) +- [RepVGG](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/RepVGG) +- [Res2Net101_v1b](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Res2Net101_v1b) +- [ResNeSt50_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ResNeSt50_for_PyTorch) +- [ResNet101_ID1595_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ResNet101_ID1595_for_PyTorch) +- [ResNet152](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ResNet152) +- [ResNet18_ID1593_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ResNet18_ID1593_for_PyTorch) +- [ResNet34_ID1594_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ResNet34_ID1594_for_PyTorch) +- [ResNeXt-50-32x4d_ID1624_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ResNeXt-50-32x4d_ID1624_for_PyTorch) +- [ResNeXt101_32x8d_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ResNeXt101_32x8d_for_PyTorch) +- [SE-ResNet-50](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/SE-ResNet-50) +- [SE-ResNext-101-32x4d](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/SE-ResNext-101-32x4d) +- [Se-ResNext-50-32x4d](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Se-ResNext-50-32x4d) +- [SENet154](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/SENet154) +- [ShuffleNetV1_ID1625_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ShuffleNetV1_ID1625_for_PyTorch) +- [ShuffleNetV2Plus_ID1626_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/ShuffleNetV2Plus_ID1626_for_PyTorch) +- [SkresNet50](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/SkresNet50) +- [SPNASNet_100_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/SPNASNet_100_for_PyTorch) +- [SqueezeNet1_1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/SqueezeNet1_1) +- [Swin-Transformer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Swin-Transformer) +- [TNT](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/TNT) +- [TResNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/TResNet) +- [Vehicle_Re-Identification](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Vehicle_Re-Identification) +- [Vgg16_ID1630_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Vgg16_ID1630_for_PyTorch) +- [Vgg19_ID1631_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Vgg19_ID1631_for_PyTorch) +- [vit_base_patch32_224](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/vit_base_patch32_224) +- [Vit_small_patch16_224](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Vit_small_patch16_224) +- [VOLO](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/VOLO) +- [VoVNet39](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/VoVNet39) +- [WideResNet101_2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/WideResNet101_2_for_Pytorch) +- [WideResNet50_2_ID1627_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/WideResNet50_2_ID1627_for_PyTorch) +- [Xception_ID1777_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/Xception_ID1777_for_PyTorch) +- [xcit](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/classification/xcit) +- [AdvancedEAST](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/AdvancedEAST) +- [CascadedMaskRCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/CascadedMaskRCNN) +- [Cascade_RCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/Cascade_RCNN) +- [CenterFace](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/CenterFace) +- [CenterNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/CenterNet) +- [DSFD](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/DSFD) +- [EfficientDetD0](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/EfficientDetD0) +- [FaceBoxes](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/FaceBoxes) +- [FairMOT](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/FairMOT) +- [FCOS](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/FCOS) +- [FOTS](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/FOTS) +- [FSAF_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/FSAF_for_Pytorch) +- [GFocalV2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/GFocalV2) +- [M2Det](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/M2Det) +- [NasFPN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/NasFPN) +- [Pointnetplus](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/Pointnetplus) +- [Pyramidbox](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/Pyramidbox) +- [RCF](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/RCF) +- [RefineDet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/RefineDet) +- [Retinaface](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/Retinaface) +- [RetinaNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/RetinaNet) +- [SimCLR_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/SimCLR_for_Pytorch) +- [SOLOv1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/SOLOv1) +- [SOLOv2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/SOLOv2) +- [SSD](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/SSD) +- [SSD-MobileNetV1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/SSD-MobileNetV1) +- [SSD-MobilenetV2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/SSD-MobilenetV2) +- [SSD-Resnet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/SSD-Resnet) +- [StyleGAN2-ADA](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/StyleGAN2-ADA) +- [TextSnake](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/TextSnake) +- [YOLACT](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/YOLACT) +- [YOLACT_plus](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/YOLACT_plus) +- [YOLOR](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/YOLOR) +- [YOLOX](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/detection/YOLOX) +- [ADNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/ADNet) +- [BigGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/BigGAN) +- [CGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/CGAN) +- [Cross-Scale-Non-Local-Attention](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/Cross-Scale-Non-Local-Attention) +- [CycleGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/CycleGAN) +- [DCGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/DCGAN) +- [edsr_x2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/edsr_x2) +- [GAN_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/GAN_Pytorch) +- [Pix2Pix](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/Pix2Pix) +- [RDN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/RDN) +- [Srcnn_x2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/Srcnn_x2_for_Pytorch) +- [SRFlow](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/SRFlow) +- [SRGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/SRGAN) +- [stargan](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/stargan) +- [wdsr](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/others/wdsr) +- [3Dmppe_RootNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/3Dmppe_RootNet) +- [AlphaPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/AlphaPose) +- [DeepPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/DeepPose) +- [HigherHRNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/HigherHRNet) +- [Hourglass_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/Hourglass_for_PyTorch) +- [Lightweight_OpenPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/Lightweight_OpenPose) +- [MSPN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/MSPN) +- [ST-GCN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/ST-GCN) +- [TransPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/TransPose) +- [VoxelPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/pose_estimation/VoxelPose) +- [3DUNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/3DUNet) +- [DeeplabV3_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/DeeplabV3_for_Pytorch) +- [ENet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/ENet) +- [ErfNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/ErfNet) +- [FastSCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/FastSCNN) +- [FCN8s](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/FCN8s) +- [HRnet-OCR](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/HRnet-OCR) +- [HRNet_SEG_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/HRNet_SEG_for_Pytorch) +- [ICNet_ID1781_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/ICNet_ID1781_for_PyTorch) +- [IntraDA](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/IntraDA) +- [PointRend](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/PointRend) +- [PraNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/PraNet) +- [PSPNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/PSPNet) +- [RCAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/RCAN) +- [RefineNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/RefineNet) +- [SETR](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/SETR) +- [Ultra-Fast-Lane-Detection](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/Ultra-Fast-Lane-Detection) +- [UNet++](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/UNet++) +- [UNet_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/UNet_for_PyTorch) +- [VNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/VNet) +- [Wseg](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/semantic_segmentation/Wseg) +- [BMN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/BMN) +- [BSN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/BSN) +- [C3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/C3D) +- [GloRe](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/GloRe) +- [I3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/I3D) +- [NonLocal](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/NonLocal) +- [R(2+1)D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/R(2+1)D) +- [SiamFC](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/SiamFC) +- [SiamRPN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/SiamRPN) +- [SlowFast](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/SlowFast) +- [TSM](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/TSM) +- [TSN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/TSN) +- [VideoPose3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/VideoPose3D) +- [X3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/cv/video/X3D) +- [albert](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/nlp/albert) +- [Bertsum_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/nlp/Bertsum_for_PyTorch) +- [roberta](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/nlp/roberta) +- [TextCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/nlp/TextCNN) +- [tinybert](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/nlp/tinybert) +- [C51](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/others/C51) +- [DLRM](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/others/DLRM) +- [DQN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/others/DQN) +- [RotatE](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/contrib/others/RotatE) + +#### dev + +- [tacotron2_ID0406_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/audio/tacotron2_ID0406_for_PyTorch) +- [3D_attentionnet_ID0478_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/detection/3D_attentionnet_ID0478_for_PyTorch) +- [FasterRCNN-Resnet50-FPN_ID1552_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/detection/FasterRCNN-Resnet50-FPN_ID1552_for_PyTorch) +- [HRNet_ID0446_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/detection/HRNet_ID0446_for_PyTorch) +- [PointNet_ID0430_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/detection/PointNet_ID0430_for_PyTorch) +- [SSD-ResNet34_ID0411_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/detection/SSD-ResNet34_ID0411_for_PyTorch) +- [2D_Unet_ID0624_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/2D_Unet_ID0624_for_PyTorch) +- [2S-AGCN_ID0909_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/2S-AGCN_ID0909_for_PyTorch) +- [3D_Nest_Unet_ID0476_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/3D_Nest_Unet_ID0476_for_PyTorch) +- [ADACOS_ID1082_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ADACOS_ID1082_for_PyTorch) +- [AdaFM-Net_ID1101_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/AdaFM-Net_ID1101_for_PyTorch) +- [ADLayer_ID1087_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ADLayer_ID1087_for_PyTorch) +- [AdvancedEast_ID0473_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/AdvancedEast_ID0473_for_PyTorch) +- [AlexNet_ID0472_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/AlexNet_ID0472_for_PyTorch) +- [ANN_ID2370_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ANN_ID2370_for_PyTorch) +- [ArcFace_ID0852_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ArcFace_ID0852_for_PyTorch) +- [ATS_ID2682_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ATS_ID2682_for_PyTorch) +- [AUTOAUGMENT_ID0792_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/AUTOAUGMENT_ID0792_for_PyTorch) +- [BASNET_ID1134_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/BASNET_ID1134_for_PyTorch) +- [BertBase_ID0490_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/BertBase_ID0490_for_PyTorch) +- [CDAR_ID2747_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/CDAR_ID2747_for_PyTorch) +- [ConvLSTM_ID1772_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ConvLSTM_ID1772_for_PyTorch) +- [coral-cnn_ID1064_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/coral-cnn_ID1064_for_PyTorch) +- [CrossFormer_ID2449_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/CrossFormer_ID2449_for_PyTorch) +- [CycleGAN_ID0521_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/CycleGAN_ID0521_for_PyTorch) +- [DBPN_ID2917_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/DBPN_ID2917_for_PyTorch) +- [DCAP_ID2836_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/DCAP_ID2836_for_PyTorch) +- [DEEP-HEAD-POSE_ID0796_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/DEEP-HEAD-POSE_ID0796_for_PyTorch) +- [DeepLab-CRF_ID1873_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/DeepLab-CRF_ID1873_for_PyTorch) +- [DeepSort_ID0654_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/DeepSort_ID0654_for_PyTorch) +- [deit_ID2467_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/deit_ID2467_for_PyTorch) +- [DGMS_ID2460_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/DGMS_ID2460_for_PyTorch) +- [EfficientNet-B6_ID1715_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/EfficientNet-B6_ID1715_for_PyTorch) +- [EfficientNet-B7_ID1716_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/EfficientNet-B7_ID1716_for_PyTorch) +- [ESPCN_ID2919_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ESPCN_ID2919_for_PyTorch) +- [ESPCN_ID3002_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ESPCN_ID3002_for_PyTorch) +- [ESRGAN_ID1813_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ESRGAN_ID1813_for_PyTorch) +- [FasterRCNN_ID0100_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/FasterRCNN_ID0100_for_PyTorch) +- [FFDNet_ID0970_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/FFDNet_ID0970_for_PyTorch) +- [FixMatch_ID0989_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/FixMatch_ID0989_for_PyTorch) +- [GENet_ID0671_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/GENet_ID0671_for_PyTorch) +- [GhostNet_ID1622_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/GhostNet_ID1622_for_PyTorch) +- [Hourglass_ID1809_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Hourglass_ID1809_for_PyTorch) +- [ICT_ID1179_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ICT_ID1179_for_PyTorch) +- [InceptionV1_ID1568_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/InceptionV1_ID1568_for_PyTorch) +- [InceptionV2_ID0698_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/InceptionV2_ID0698_for_PyTorch) +- [InceptionV3_ID0445_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/InceptionV3_ID0445_for_PyTorch) +- [InceptionV4_ID0444_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/InceptionV4_ID0444_for_PyTorch) +- [InceptionV4_ID2473_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/InceptionV4_ID2473_for_PyTorch) +- [Keyword-MLP_ID2441_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Keyword-MLP_ID2441_for_PyTorch) +- [LADE_ID2445_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/LADE_ID2445_for_PyTorch) +- [MaskRCNN_ID0101_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/MaskRCNN_ID0101_for_PyTorch) +- [mBART_ID1550_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/mBART_ID1550_for_PyTorch) +- [MMAL-NET_ID1116_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/MMAL-NET_ID1116_for_PyTorch) +- [MMOE_ID2865_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/MMOE_ID2865_for_PyTorch) +- [Mnasnet0_75_ID0439_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Mnasnet0_75_ID0439_for_PyTorch) +- [Mnasnet1_0_ID0438_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Mnasnet1_0_ID0438_for_PyTorch) +- [Mnasnet1_3_ID0437_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Mnasnet1_3_ID0437_for_PyTorch) +- [mobilenetv2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/mobilenetv2_for_Pytorch) +- [MobileNetV3-Small_ID1785_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/MobileNetV3-Small_ID1785_for_PyTorch) +- [MSPN_ID0960_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/MSPN_ID0960_for_PyTorch) +- [MTCNN_ID0435_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/MTCNN_ID0435_for_PyTorch) +- [Mutual-Channel-Loss_ID1113_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Mutual-Channel-Loss_ID1113_for_PyTorch) +- [NeuMF_ID0351_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/NeuMF_ID0351_for_PyTorch) +- [PASSRnet_ID0986_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/PASSRnet_ID0986_for_PyTorch) +- [pFedMe_ID1597_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/pFedMe_ID1597_for_PyTorch) +- [PFF_ID1128_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/PFF_ID1128_for_PyTorch) +- [PiT_ID2671_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/PiT_ID2671_for_PyTorch) +- [Pix2Pix_ID0331_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Pix2Pix_ID0331_for_PyTorch) +- [POOLNET_ID0875_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/POOLNET_ID0875_for_PyTorch) +- [Pysot_ID0428_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Pysot_ID0428_for_PyTorch) +- [RAFT_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/RAFT_for_PyTorch) +- [RANet_ID0994_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/RANet_ID0994_for_PyTorch) +- [RES2NET_ID0824_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/RES2NET_ID0824_for_PyTorch) +- [residual_adapters_ID1598_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/residual_adapters_ID1598_for_PyTorch) +- [Resnet101_ID0425_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Resnet101_ID0425_for_PyTorch) +- [ResNet152_ID0424_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ResNet152_ID0424_for_PyTorch) +- [Resnet152_ID1592_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Resnet152_ID1592_for_PyTorch) +- [Resnet18_ID0423_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Resnet18_ID0423_for_PyTorch) +- [Resnet34_ID0422_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Resnet34_ID0422_for_PyTorch) +- [Resnext101_32x8d_ID0420_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Resnext101_32x8d_ID0420_for_PyTorch) +- [ResNeXt101_ID1717_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ResNeXt101_ID1717_for_PyTorch) +- [ResNeXt50_ID0419_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ResNeXt50_ID0419_for_PyTorch) +- [RRN_ID1182_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/RRN_ID1182_for_PyTorch) +- [RUC_ID2470_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/RUC_ID2470_for_PyTorch) +- [SEResNext_ID0415_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SEResNext_ID0415_for_PyTorch) +- [SG2IM_ID0786_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SG2IM_ID0786_for_PyTorch) +- [SimplePose_ID1038_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SimplePose_ID1038_for_PyTorch) +- [SINGLESHOTPOSE_ID0869_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SINGLESHOTPOSE_ID0869_for_PyTorch) +- [SlowFast_ID0646_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SlowFast_ID0646_for_PyTorch) +- [SmartSketch_ID1046_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SmartSketch_ID1046_for_PyTorch) +- [SqueezeNet_ID0413_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SqueezeNet_ID0413_for_PyTorch) +- [SRCNN_ID1770_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SRCNN_ID1770_for_PyTorch) +- [SRGAN_ID2956_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SRGAN_ID2956_for_PyTorch) +- [SSD-MobileNet_ID1936_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/SSD-MobileNet_ID1936_for_PyTorch) +- [STARGAN_ID0725_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/STARGAN_ID0725_for_PyTorch) +- [Swin-Transformer_ID2377_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Swin-Transformer_ID2377_for_PyTorch) +- [TabNet_ID2862_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/TabNet_ID2862_for_PyTorch) +- [Token-to-Token-ViT_ID2668_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Token-to-Token-ViT_ID2668_for_PyTorch) +- [TransformerXL_ID0699_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/TransformerXL_ID0699_for_PyTorch) +- [VAE+GAN_ID0401_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/VAE+GAN_ID0401_for_PyTorch) +- [VGG16_ID0467_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/VGG16_ID0467_for_PyTorch) +- [VGG19_ID0244_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/VGG19_ID0244_for_PyTorch) +- [VGGNet_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/VGGNet_for_Pytorch) +- [VGGNet_ID0400_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/VGGNet_ID0400_for_PyTorch) +- [vit-base_ID0492_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/vit-base_ID0492_for_PyTorch) +- [VIT_ID2381_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/VIT_ID2381_for_PyTorch) +- [Wide_resnet101_2_ID0398_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Wide_resnet101_2_ID0398_for_PyTorch) +- [Wide_resnet50_2_ID0397_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Wide_resnet50_2_ID0397_for_PyTorch) +- [Xception_ID1454_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/Xception_ID1454_for_PyTorch) +- [ZERO-DCE_ID1040_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_classification/ZERO-DCE_ID1040_for_PyTorch) +- [deeplabv3+_ID0326_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_segmentation/deeplabv3+_ID0326_for_PyTorch) +- [DeepLabV3+_ID0458_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch) +- [DeepLabV3_ID0621_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_segmentation/DeepLabV3_ID0621_for_PyTorch) +- [SETR_ID1572_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_segmentation/SETR_ID1572_for_PyTorch) +- [GAN_ID1931_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/image_synthesis/GAN_ID1931_for_PyTorch) +- [DSCNN_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/quality_enhancement/DSCNN_for_PyTorch) +- [FFA-NET_ID1043_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/cv/quality_enhancement/FFA-NET_ID1043_for_PyTorch) +- [BERT-ITPT-FiT_ID0340_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/BERT-ITPT-FiT_ID0340_for_PyTorch) +- [BERT_base_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/BERT_base_for_PyTorch) +- [FairSeq_Transformer_ID0496_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/FairSeq_Transformer_ID0496_for_PyTorch) +- [Retinanet_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/Retinanet_for_PyTorch) +- [Speech_Transformer_ID0487_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/Speech_Transformer_ID0487_for_PyTorch) +- [Swin-Transformer_ID2375_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/Swin-Transformer_ID2375_for_PyTorch) +- [Swin-Transformer_ID2379_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/Swin-Transformer_ID2379_for_PyTorch) +- [Textcnn_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/Textcnn_for_PyTorch) +- [Transformer_ID0105_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/nlp/Transformer_ID0105_for_PyTorch) +- [Multi-Gradient_Descent_ID0349_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/others/Multi-Gradient_Descent_ID0349_for_PyTorch) +- [Widedeep_ID2866_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/PyTorch/dev/others/Widedeep_ID2866_for_PyTorch) + +### ACL_PyTorch + +#### built-in + +- [EspNet_for_Pytoch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/audio/EspNet_for_Pytoch) +- [Jasper_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/audio/Jasper_for_PyTorch) +- [LSTM](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/audio/LSTM) +- [RawNet2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/audio/RawNet2_for_Pytorch) +- [Tacotron2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/audio/Tacotron2_for_Pytorch) +- [TDNN_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/audio/TDNN_for_Pytorch) +- [Wenet_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch) +- [3DUnet_for_PTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/3DUnet_for_PTorch) +- [CascadeRCNN-DCN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/CascadeRCNN-DCN) +- [CascadeRCNN-DCN-101_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/CascadeRCNN-DCN-101_for_Pytorch) +- [CenterNet_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/CenterNet_for_Pytorch) +- [CRNN_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/CRNN_for_Pytorch) +- [DB_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/DB_for_PyTorch) +- [Deepmar_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Deepmar_for_Pytorch) +- [Deepsort_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Deepsort_for_Pytorch) +- [Densenet121_Pytorch_Infer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Densenet121_Pytorch_Infer) +- [DPN131_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/DPN131_for_Pytorch) +- [EfficientNet_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/EfficientNet_for_Pytorch) +- [FasterRCNN-DCN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/FasterRCNN-DCN) +- [Flownet2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Flownet2_for_Pytorch) +- [GoogleNet_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/GoogleNet_for_Pytorch) +- [I3D_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/I3D_for_Pytorch) +- [InceptionV3_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/InceptionV3_for_Pytorch) +- [InceptionV4_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/InceptionV4_for_Pytorch) +- [MobileNetV2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/MobileNetV2_for_Pytorch) +- [Pelee_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Pelee_for_Pytorch) +- [PSENet_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/PSENet_for_Pytorch) +- [Res2Net_v1b_101_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Res2Net_v1b_101_for_PyTorch) +- [Resnet101_Pytorch_Infer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Resnet101_Pytorch_Infer) +- [Resnet18_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Resnet18_for_PyTorch) +- [Resnet34_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Resnet34_for_Pytorch) +- [Resnet50_Pytorch_Infer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Resnet50_Pytorch_Infer) +- [ResNeXt50_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/ResNeXt50_for_Pytorch) +- [SE_ResNet50_Pytorch_Infer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/SE_ResNet50_Pytorch_Infer) +- [Shufflenetv2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Shufflenetv2_for_Pytorch) +- [STGCN_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/STGCN_for_Pytorch) +- [U2-Net_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/U2-Net_for_PyTorch) +- [Vgg16_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Vgg16_for_Pytorch) +- [VGG16_SSD_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/VGG16_SSD_for_PyTorch) +- [Vgg19_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Vgg19_for_Pytorch) +- [Wide_ResNet50_2_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Wide_ResNet50_2_for_Pytorch) +- [YolactEdge_for_PyTorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/YolactEdge_for_PyTorch) +- [Yolov3_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Yolov3_for_Pytorch) +- [Yolov4_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Yolov4_for_Pytorch) +- [Yolov5_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/cv/Yolov5_for_Pytorch) +- [Bert_Base_Uncased](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased) +- [CNN_Transformer_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/nlp/CNN_Transformer_for_Pytorch) +- [textcnn](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/nlp/textcnn) +- [TransformerXL_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/nlp/TransformerXL_for_Pytorch) +- [VilBert_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/built-in/nlp/VilBert_for_Pytorch) + +#### contrib + +- [FastPitch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/audio/FastPitch) +- [Jasper](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/audio/Jasper) +- [Speech-Transformer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/audio/Speech-Transformer) +- [tdnn](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/audio/tdnn) +- [3d_attention_net](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/3d_attention_net) +- [AlexNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/AlexNet) +- [baseline_dino_resnet50](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/baseline_dino_resnet50) +- [BMN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/BMN) +- [C3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/C3D) +- [CSPResneXt50](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/CSPResneXt50) +- [Deit_Small](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Deit_Small) +- [DPN131](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/DPN131) +- [Efficient-3DCNNs](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Efficient-3DCNNs) +- [EfficientNet-B1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B1) +- [EfficientNet-B3](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B3) +- [EfficientNet-B5](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/EfficientNet-B5) +- [FixRes](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/FixRes) +- [GaitSet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/GaitSet) +- [GENet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/GENet) +- [GhostNet1.0x](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/GhostNet1.0x) +- [GloRe](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/GloRe) +- [HRNet-Image-Classification](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/HRNet-Image-Classification) +- [InceptionResnetV2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/InceptionResnetV2) +- [LResNet100E-IR](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/LResNet100E-IR) +- [LV-Vit](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/LV-Vit) +- [Mnasnet1_0](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Mnasnet1_0) +- [MobileNet-v1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/MobileNet-v1) +- [MobileNetV3_large_100](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/MobileNetV3_large_100) +- [Moco-v2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Moco-v2) +- [OSNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/OSNet) +- [PAMTRI](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/PAMTRI) +- [pnasnet5large](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/pnasnet5large) +- [PointNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/PointNet) +- [PointNetCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/PointNetCNN) +- [Pointnetplus](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Pointnetplus) +- [R(2+1)D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/R(2+1)D) +- [RegNetX-1.6GF](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/RegNetX-1.6GF) +- [RegNetY-1.6GF](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/RegNetY-1.6GF) +- [ReID_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/ReID_for_Pytorch) +- [RepVGG](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/RepVGG) +- [Res2Net101_v1b](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Res2Net101_v1b) +- [ResNeSt50](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/ResNeSt50) +- [ResNet101](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/ResNet101) +- [ResNet152](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/ResNet152) +- [ResNet18](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/ResNet18) +- [ResNet34](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/ResNet34) +- [ResNext101_32x8d](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/ResNext101_32x8d) +- [Se-Resnext101](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Se-Resnext101) +- [SENet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/SENet) +- [Shufflenetv1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Shufflenetv1) +- [Shufflenetv2+](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Shufflenetv2+) +- [SimCLR_inference](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/SimCLR_inference) +- [Sknet50](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Sknet50) +- [spnasnet_100](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/spnasnet_100) +- [Squeezenet1_1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Squeezenet1_1) +- [Swin-Transformer](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Swin-Transformer) +- [TNT](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/TNT) +- [TResNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/TResNet) +- [vit-small](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/vit-small) +- [vit_base_patch32_224](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/vit_base_patch32_224) +- [vovnet39](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/vovnet39) +- [Wide_ResNet101_2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/Wide_ResNet101_2) +- [X3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/X3D) +- [xception](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/xception) +- [xcit](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/classfication/xcit) +- [3DUnet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/3DUnet) +- [AdvancedEAST](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/AdvancedEAST) +- [AlphaPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/AlphaPose) +- [BSN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/BSN) +- [Cascade-RCNN-Resnet101-FPN-DCN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Cascade-RCNN-Resnet101-FPN-DCN) +- [Cascade_RCNN_R101](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Cascade_RCNN_R101) +- [CenterFace](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/CenterFace) +- [CenterNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/CenterNet) +- [CTPN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/CTPN) +- [Deepspeech](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Deepspeech) +- [Detr](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Detr) +- [DSFD](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/DSFD) +- [EfficientDetD0](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/EfficientDetD0) +- [EfficientDetD7](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/EfficientDetD7) +- [FairMOT](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/FairMOT) +- [FasterRCNN_FPN_DCN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/FasterRCNN_FPN_DCN) +- [Fcos](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Fcos) +- [FOTS](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/FOTS) +- [Fsaf](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Fsaf) +- [GFocalV2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/GFocalV2) +- [M2Det](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/M2Det) +- [Nasnetlarge](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Nasnetlarge) +- [NAS_FPN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/NAS_FPN) +- [OpenPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/OpenPose) +- [pyramidbox](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/pyramidbox) +- [RCF](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/RCF) +- [RefineDet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/RefineDet) +- [Retinanet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/Retinanet) +- [RFCN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/RFCN) +- [SSD](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/SSD) +- [SSD-MobileNetV1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV1) +- [SSD-MobileNetV2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/SSD-MobileNetV2) +- [SSD-Resnet34](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/SSD-Resnet34) +- [TextSnake](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/TextSnake) +- [yolor](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/yolor) +- [YOLOX](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/detection/YOLOX) +- [AlignedReID](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/face/AlignedReID) +- [FaceBoxes](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/face/FaceBoxes) +- [FaceNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/face/FaceNet) +- [ReId-MGN-master](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/face/ReId-MGN-master) +- [reid_PCB_baseline](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/face/reid_PCB_baseline) +- [Retinaface](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/face/Retinaface) +- [BigGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/BigGAN) +- [CGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/CGAN) +- [CycleGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/CycleGAN) +- [DCGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/DCGAN) +- [GAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/GAN) +- [Pix2Pix](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/Pix2Pix) +- [Pix2pixHD](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/Pix2pixHD) +- [StarGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/gan/StarGAN) +- [Cross-Scale-Non-Local-Attention](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/image_process/Cross-Scale-Non-Local-Attention) +- [DnCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/image_process/DnCNN) +- [SRFlow](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/image_process/SRFlow) +- [wdsr](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/image_process/wdsr) +- [3DMPPE-ROOTNET](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/pose_estimation/3DMPPE-ROOTNET) +- [HigherHRNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/pose_estimation/HigherHRNet) +- [MSPN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/pose_estimation/MSPN) +- [TransPose](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/pose_estimation/TransPose) +- [VideoPose3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/pose_estimation/VideoPose3D) +- [ADNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/quality_enhancement/ADNet) +- [SRGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/quality_enhancement/SRGAN) +- [3D_HRNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/3D_HRNet) +- [Cascade_Mask_RCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/Cascade_Mask_RCNN) +- [Cascade_RCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/Cascade_RCNN) +- [DeeplabV3](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/DeeplabV3) +- [ENet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/ENet) +- [ErfNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/ErfNet) +- [FastSCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/FastSCNN) +- [FCN-8s](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/FCN-8s) +- [GCNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/GCNet) +- [ICNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/ICNet) +- [IntraDA](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/IntraDA) +- [Nested_UNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/Nested_UNet) +- [PointRend](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/PointRend) +- [PraNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/PraNet) +- [PSPnet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/PSPnet) +- [RefineNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/RefineNet) +- [SETR](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/SETR) +- [SiamMask](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/SiamMask) +- [SOLOV1](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/SOLOV1) +- [SOLOV2](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/SOLOV2) +- [Ultra-Fast-Lane-Detection](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/Ultra-Fast-Lane-Detection) +- [VNet](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/VNet) +- [Wseg](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/Wseg) +- [YOLACT](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/YOLACT) +- [YOLACT_plus](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/segmentation/YOLACT_plus) +- [EDSR](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/super_resolution/EDSR) +- [RCAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/super_resolution/RCAN) +- [RDN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/super_resolution/RDN) +- [Real-ESRGAN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/super_resolution/Real-ESRGAN) +- [SRCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/super_resolution/SRCNN) +- [SiamFC](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/tracking/SiamFC) +- [SiamRPN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/tracking/SiamRPN) +- [I3D](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/video_understanding/I3D) +- [NonLocal](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/video_understanding/NonLocal) +- [SlowFast](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/video_understanding/SlowFast) +- [TSM](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/video_understanding/TSM) +- [TSN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/cv/video_understanding/TSN) +- [RotatE](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/knowledge/RotatE) +- [albert](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/nlp/albert) +- [BertSum](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/nlp/BertSum) +- [CNN_Transformer_for_Pytorch](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/nlp/CNN_Transformer_for_Pytorch) +- [roberta](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/nlp/roberta) +- [TextCNN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/nlp/TextCNN) +- [tinybert](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/nlp/tinybert) +- [c51](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/rl/c51) +- [DQN](https://gitee.com/ascend/ModelZoo-PyTorch/tree/master/ACL_PyTorch/contrib/rl/DQN) + + + + + + + +## 免责声明 + +Ascend ModelZoo仅提供公共数据集下载和预处理脚本。这些数据集不属于ModelZoo,ModelZoo也不对其质量或维护负责。请确保您具有这些数据集的使用许可。基于这些数据集训练的模型仅可用于非商业研究和教育。 + +致数据集所有者: + +如果您不希望您的数据集公布在ModelZoo上或希望更新ModelZoo中属于您的数据集,请在Github/Gitee提交issue,我们将根据您的issue删除或更新您的数据集。衷心感谢您对我们社区的理解和贡献。 + +Ascend ModelZoo的license是Apache 2.0.具体内容,请参见LICENSE文件。 diff --git a/Third_Party_Open_Source_Software_Notice b/Third_Party_Open_Source_Software_Notice index e4ddc09e7ff052826027986fbaebcf54a104c5b3..d6cdc5aec11c9d761c049143c884f5ca86ffb355 100644 --- a/Third_Party_Open_Source_Software_Notice +++ b/Third_Party_Open_Source_Software_Notice @@ -1,1975 +1,1975 @@ -OPEN SOURCE SOFTWARE NOTICE - -Please note we provide an open source software notice along with this product and/or this product firmware (in the following just “this product”). The open source software licenses are granted by the respective right holders. And the open source licenses prevail all other license information with regard to the respective open source software contained in the product, including but not limited to End User Software Licensing Agreement. This notice is provided on behalf of Huawei Technologies Co. Ltd. and any of its local subsidiaries which may have provided this product to you in your local country. - -Warranty Disclaimer -THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. - -Copyright Notice and License Texts - -Software: Eigen 3.3.7 -Copyright notice: -Copyright (C) 2014 Benoit Steiner -Copyright (C) 2013 Christian Seiler -Copyright (C) 2015 Eugene Brevdo -Copyright (C) 2014-2015 Benoit Steiner -Copyright (C) 2015 Navdeep Jaitly -Copyright (C) 2014 Eric Martin -Copyright (C) 2015 Benoit Steiner -Copyright (C) 2016 Rasmus Munk Larsen -Copyright (C) 2016 Benoit Steiner -Copyright (C) 2015 Jianwei Cui -Copyright (C) 2016 Eugene Brevdo -Copyright (C) 2015 Ke Yang -Copyright (C) 2016 Mehdi Goli, Codeplay Software Ltd -Copyright (C) 2014 Navdeep Jaitly -Copyright (C) 2016 Igor Babuschkin -Copyright (C) 2016 Dmitry Vyukov -Copyright (C) EDF R&D, lun sep 30 14:23:30 CEST 2002 -Copyright (C) 2008 Gael Guennebaud -Copyright (C) EDF R&D, lun sep 30 14:23:31 CEST 2002 -Copyright (C) 2008-2010 Gael Guennebaud -Copyright (C) 2008-2016 Gael Guennebaud -Copyright (C) 2009 Mark Borgerding mark a borgerding net -Copyright (C) 2008-2009 Gael Guennebaud -Copyright (C) 2013 Desire Nuentsa -Copyright (C) 2013 Gael Guennebaud -Copyright (C) 2011 Gael Guennebaud -Copyright (C) 2012 Desire NUENTSA WAKAM -Copyright (C) 2009 Benoit Jacob -Copyright (C) 2009 Gael Guennebaud -Copyright (C) 2006-2010 Benoit Jacob -Copyright (C) 2006-2008 Benoit Jacob -Copyright (C) EDF R&D, lun sep 30 14:23:28 CEST 2002 -Copyright (C) 2010 Manuel Yguel -Copyright (C) 2009 Claire Maurice -Copyright (C) 2010,2012 Jitse Niesen -Copyright (c) 2011, Intel Corporation. All rights reserved. -Copyright (C) 2012-2016 Gael Guennebaud -Copyright (C) 2016 Tobias Wood -Copyright (C) 2010 Jitse Niesen -Copyright (C) 2012 Alexey Korepanov -Copyright (C) 2010 Vincent Lejeune -Copyright (C) 2010 Gael Guennebaud -Copyright (C) 2010 Benoit Jacob -Copyright (C) 2017 Gael Guennebaud -Copyright (C) 2009-2010 Gael Guennebaud -Copyright (C) 2008 Benoit Jacob -Copyright (C) 2009 Mathieu Gautier -Copyright (C) 2010 Hauke Heibel -Copyright (C) 2009 Hauke Heibel -Copyright (C) 2008-2015 Gael Guennebaud -Copyright (C) EDF R&D, mar déc 3 18:59:36 CET 2002 -Copyright (C) EDF R&D, lun sep 30 14:23:17 CEST 2002 -Copyright (C) EDF R&D, mar déc 3 18:59:35 CET 2002 -Copyright (C) 2016 Konstantinos Margaritis -Copyright (C) 2007 Julien Pommier -Copyright (C) 2008-2011 Gael Guennebaud -Copyright (C) 2009 Keir Mierle -Copyright (C) 2011 Timothy E. Holy -Copyright (C) 2009 Hauke Heibel -Copyright (C) 2012 Desire Nuentsa -Copyright (C) 2014 Gael Guennebaud -Copyright (C) 2015 Tal Hadad -@copyright (c) 2009-2014 The University of Tennessee and The University of Tennessee Research Foundation. -@copyright (c) 2012-2016 Inria. All rights reserved. -@copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved. -Copyright 2007-2009 Kitware, Inc. -Copyright 2012-2013 Inria -Copyright 2012-2013 Emmanuel Agullo -Copyright 2012-2013 Mathieu Faverge -Copyright 2012 Cedric Castagnede -Copyright 2013-2016 Florent Pruvost -Copyright 2016 Codeplay Software Ltd. -Copyright (c) 2006, 2007 Montel Laurent, -Copyright (c) 2008, 2009 Gael Guennebaud, -Copyright (c) 2009 Boudewijn Rempt -@copyright (c) 2012-2014 Inria. All rights reserved. -Copyright 2013 Florent Pruvost -Copyright (c) 2010 Jitse Niesen, -Copyright (C) 2009 Benjamin Schindler -Copyright (C) 2016 Pedro Gonnet (pedro.gonnet@gmail.com) -Copyright (C) 2016 Benoit Steiner (benoit.steiner.goog@gmail.com) -Copyright (C) 2009 Thomas Capricelli -Copyright (C) 2012-2013 Desire Nuentsa -Copyright (C) 2012-2014 Gael Guennebaud -Copyright Jorge More - Argonne National Laboratory -Copyright Burt Garbow - Argonne National Laboratory -Copyright Ken Hillstrom - Argonne National Laboratory -Copyright (C) 2009 Ilya Baran -Copyright (c) 2010, Intel Corp. -Copyright (C) 2009-2010 Benoit Jacob -Copyright (C) 2013-2016 Gael Guennebaud -Copyright (C) 2013 Gauthier Brun -Copyright (C) 2013 Nicolas Carre -Copyright (C) 2013 Jean Ceccato -Copyright (C) 2013 Pierre Zoppitelli -Copyright (C) 2013 Jitse Niesen -Copyright (C) 2014-2017 Gael Guennebaud -Copyright (C) 2013-2014 Gael Guennebaud -Copyright (C) 2011-2014 Gael Guennebaud -Copyright (C) 2012 Désiré Nuentsa-Wakam -Copyright (C) 2015 Gael Guennebaud -Copyright (C) 2012 Gael Guennebaud -Copyright (c) 1994 by Xerox Corporation. All rights reserved. -Copyright (C) 2001 Intel Corporation -Copyright (c) 2001 Intel Corporation. -Copyright (C) 2009 Gael Guennebaud -Copyright (C) 2013 Christoph Hertzberg -Copyright (C) 2015 Eugene Brevdo -Copyright (C) 2016 -Mehdi Goli Codeplay Software Ltd. -Ralph Potter Codeplay Software Ltd. -Luke Iwanski Codeplay Software Ltd. -Copyright (C) 2014 Jianwei Cui -Copyright (C) 2015 Vijay Vasudevan -Copyright (C) 2015 -Mehdi Goli Codeplay Software Ltd. -Ralph Potter Codeplay Software Ltd. -Luke Iwanski Codeplay Software Ltd. -Copyright (C) 2014 Navdeep Jaitly -Copyright (C) 2011 Gael Guennebaud -Copyright (C) 2012 desire Nuentsa -Copyright (C) 2012 Kolja Brix -Copyright (C) 2011 Kolja Brix -Copyright (C) 2011 Andreas Platen -Copyright (C) 2012 Chen-Pang He -Copyright (C) 2009 Jitse Niesen -Copyright (C) 2009-2011 Jitse Niesen -Copyright (C) 2012, 2013 Chen-Pang He -Copyright (C) 2011 Jitse Niesen -Copyright (C) 2012 Giacomo Po -Copyright (C) 2008-2010 Gael Guennebaud -Copyright (C) 2016 Gael Guennebaud -Copyright (C) 2010-2011 Hauke Heibel -Copyright (C) 2012 David Harmon -Copyright (C) 2007-2009 Benoit Jacob -Copyright (C) 2007-2010 Benoit Jacob -Copyright (C) 2008-2009 Benoit Jacob -Copyright (C) 2009 Kenneth Riddile -Copyright (C) 2010 Thomas Capricelli -Copyright (C) 2013 Pavel Holoborodko -Copyright (C) EDF R&D, lun sep 30 14:23:16 CEST 2002 -Copyright (C) EDF R&D, mar déc 3 18:59:37 CET 2002 -Copyright (C) 2006-2009 Benoit Jacob -Copyright (C) 2008-2010 Benoit Jacob -Copyright (c) 2008-2015 Pavel Holoborodko -Copyright (C) 20010-2011 Hauke Heibel -Copyright (c) 2006, Montel Laurent, -Copyright (c) 2007, Allen Winter, -Copyright (c) 2007, Alexander Neundorf, -Copyright (C) 2008 Guillaume Saupin -Copyright (C) 2008-2009 Guillaume Saupin -Copyright (C) 2009 Guillaume Saupin -Copyright (C) 2010-2016 Konstantinos Margaritis -Copyright (C) 2008-2016 Konstantinos Margaritis -Copyright (C) 2014 Benoit Steiner (benoit.steiner.goog@gmail.com) -Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com) -Copyright (c) Fabian Giesen, 2016 -Copyright (C) 2010 Konstantinos Margaritis -Copyright (C) 2007 Michael Olbrich -Copyright (C) 2011 Benoit Jacob -Copyright (C) 2011-2012 Jitse Niesen -Copyright (C) 2016 Rasmus Munk Larsen (rmlarsen@google.com) -Copyright (C) 2008-2014 Gael Guennebaud -Copyright (C) 2010-2013 Hauke Heibel -Copyright (C) 2006-2008, 2010 Benoit Jacob -Copyright (C) 2010-2016 Gael Guennebaud -Copyright (C) 2009-2015 Gael Guennebaud -Copyright (C) 2009 Ricard Marxer -Copyright (C) 2009-2014 Gael Guennebaud -Copyright (C) 2010-2011 Gael Guennebaud -Copyright (C) 2009 Rohit Garg -Copyright (c) 2006, Timothy A. Davis. -Copyright (c) 1998-2003 by the University of Florida. -Copyright (C) 2012 Désiré Nuentsa-Wakam -Copyright (C) 2008-2012 Gael Guennebaud -LDL Copyright (c) 2005 by Timothy A. Davis. All Rights Reserved. -Copyright (C) 2010 Daniel Lowengrub -Copyright (C) EDF R&D, lun sep 30 14:23:20 CEST 2002 -Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002 -Copyright (C) 2009, 2010, 2013 Jitse Niesen -Copyright (C) 2011, 2013 Chen-Pang He -Copyright (C) 2009-2011, 2013 Jitse Niesen -Copyright (C) 2011, 2013 Jitse Niesen -Copyright (C) 2011 Chen-Pang He -Copyright (C) 2010, 2013 Jitse Niesen -Copyright (C) 2010-2014 Gael Guennebaud -Copyright (C) 2012 The Android Open Source Project -(C) Desire NUENTSA WAKAM, INRIA -Copyright (C) EDF R&D, lun sep 30 14:23:18 CEST 2002 -Copyright (C) 2012 Keir Mierle -Copyright (C) 1989, 1991 Free Software Foundation, Inc. -Copyright (C) EDF R&D, lun sep 30 14:23:23 CEST 2002 -Copyright (C) EDF R&D, lun sep 30 14:23:24 CEST 2002 -Copyright (C) EDF R&D, lun sep 30 14:23:27 CEST 2002 -Copyright (C) 2007 Free Software Foundation, Inc. -Copyright (C) 1991, 1999 Free Software Foundation, Inc. -Copyright (C) 2015 Benoit Jacob -Geometric Tools, LLC Copyright (c) 1998-2010 -Copyright (C) EDF R&D, lun sep 30 14:23:15 CEST 2002 -Copyright (C) 2002-2007 Yves Renard -Copyright (C) 2012, 2014 Kolja Brix -Copyright (C) 1997-2001 Andrew Lumsdaine Lie-Quan Lee -Copyright (C) 2012 Desire NUENTSA WAKAM -Copyright (C) 2013 Hauke Heibel -Copyright (C) 2010-2011 Jitse Niesen -Intel Copyright (C) .... -Copyright (C) 2010-2017 Gael Guennebaud -Copyright (C) 20013 Gael Guennebaud -Copyright (C) 2008 Daniel Gomez Ferro -Copyright (C) 2013 Désiré Nuentsa-Wakam -Copyright (C) 2011-2015 Gael Guennebaud -Copyright (C) 20015 Gael Guennebaud -Copyright (C) 2014-2015 Gael Guennebaud - -Copyright 2019 The TensorFlow Authors. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - -From PyTorch: - -Copyright (c) 2016- Facebook, Inc (Adam Paszke) -Copyright (c) 2014- Facebook, Inc (Soumith Chintala) -Copyright (c) 2011-2014 Idiap Research Institute (Ronan Collobert) -Copyright (c) 2012-2014 Deepmind Technologies (Koray Kavukcuoglu) -Copyright (c) 2011-2012 NEC Laboratories America (Koray Kavukcuoglu) -Copyright (c) 2011-2013 NYU (Clement Farabet) -Copyright (c) 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston) -Copyright (c) 2006 Idiap Research Institute (Samy Bengio) -Copyright (c) 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz) - -From Caffe2: - -Copyright (c) 2016-present, Facebook Inc. All rights reserved. - -All contributions by Facebook: -Copyright (c) 2016 Facebook Inc. - -All contributions by Google: -Copyright (c) 2015 Google Inc. -All rights reserved. - -All contributions by Yangqing Jia: -Copyright (c) 2015 Yangqing Jia -All rights reserved. - -All contributions by Kakao Brain: -Copyright 2019-2020 Kakao Brain - -All contributions from Caffe: -Copyright(c) 2013, 2014, 2015, the respective contributors -All rights reserved. - -All other contributions: -Copyright(c) 2015, 2016 the respective contributors -All rights reserved. - -Caffe2 uses a copyright model similar to Caffe: each contributor holds -copyright over their contributions to Caffe2. The project versioning records -all such contribution and copyright details. If a contributor wants to further -mark their specific copyright on a particular contribution, they should -indicate their copyright solely in the commit message of the change when it is -committed. - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -3. Neither the names of Facebook, Deepmind Technologies, NYU, NEC Laboratories America - and IDIAP Research Institute nor the names of its contributors may be - used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - -Software: crnn e78bb7d -Copyright notice: -Copyright (c) 2017 Jieru Mei meijieru@gmail.com - -License: MIT License (MIT) -MIT License -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - - -Software: pytorch-deeplab-xception b7cbf5a -Copyright notice: -Copyright (c) 2018 Pyjcsx - -License: MIT License (MIT) -MIT License -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - - - -Software: version 1.0.1 -Copyright notice: -Copyright (c) Soumith Chintala 2016 - -License: BSD 3-Clause License -BSD 3-Clause License -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - - -Software: EfficientNet-PyTorch 1.0 -Copyright notice: -Copyright Copyright [yyyy] [name of copyright owner] - -License: Apache License - - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - -Software: PSENet cec7e6 -Copyright notice: -Copyright [yyyy] [name of copyright owner] - -License: Apache License - - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - -Software: examples v1.22.1 -Copyright notice: -Copyright (c) 2017, All rights reserved. - -License: BSD 3-Clause License -BSD 3-Clause License - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - - -Software: pytorch-image-models 0.1-regnet -Copyright notice: -Copyright Copyright [yyyy] [name of copyright owner] - -License: Apache License - - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - -Software: DeepCTR-Torch 0.2.1 -Copyright notice: -Copyright Copyright [yyyy] [name of copyright owner] - -License: Apache License -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -Software:Wizyoung 8776cf7 - -The MIT License (MIT) - -Copyright (c) 2020 Wizyoung - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - - -Software:PyTorch -BSD 3-Clause License - -Copyright (c) Soumith Chintala 2016, -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -Software:tpu r1.15 -Software:tensorflow master -Software:NVIDIA master -Software:Tensorflow-densenet -Software:Training v0.7 results -Software:AWS - -Copyright 2017 The TensorFlow Authors. All rights reserved. -Copyright 2016 The TensorFlow Authors. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -## Some of TensorFlow's code is derived from Caffe, which is subject to the following copyright notice: - -COPYRIGHT - -All contributions by the University of California: - -Copyright (c) 2014, The Regents of the University of California (Regents) -All rights reserved. - -All other contributions: - -Copyright (c) 2014, the respective contributors -All rights reserved. - -Caffe uses a shared copyright model: each contributor holds copyright over -their contributions to Caffe. The project versioning records all such -contribution and copyright details. If a contributor wants to further mark -their specific copyright on a particular contribution, they should indicate -their copyright solely in the commit message of the change when it is -committed. - -LICENSE - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -CONTRIBUTION AGREEMENT - -By contributing to the BVLC/caffe repository through pull-request, comment, -or otherwise, the contributor releases their content to the +OPEN SOURCE SOFTWARE NOTICE + +Please note we provide an open source software notice along with this product and/or this product firmware (in the following just “this product”). The open source software licenses are granted by the respective right holders. And the open source licenses prevail all other license information with regard to the respective open source software contained in the product, including but not limited to End User Software Licensing Agreement. This notice is provided on behalf of Huawei Technologies Co. Ltd. and any of its local subsidiaries which may have provided this product to you in your local country. + +Warranty Disclaimer +THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. + +Copyright Notice and License Texts + +Software: Eigen 3.3.7 +Copyright notice: +Copyright (C) 2014 Benoit Steiner +Copyright (C) 2013 Christian Seiler +Copyright (C) 2015 Eugene Brevdo +Copyright (C) 2014-2015 Benoit Steiner +Copyright (C) 2015 Navdeep Jaitly +Copyright (C) 2014 Eric Martin +Copyright (C) 2015 Benoit Steiner +Copyright (C) 2016 Rasmus Munk Larsen +Copyright (C) 2016 Benoit Steiner +Copyright (C) 2015 Jianwei Cui +Copyright (C) 2016 Eugene Brevdo +Copyright (C) 2015 Ke Yang +Copyright (C) 2016 Mehdi Goli, Codeplay Software Ltd +Copyright (C) 2014 Navdeep Jaitly +Copyright (C) 2016 Igor Babuschkin +Copyright (C) 2016 Dmitry Vyukov +Copyright (C) EDF R&D, lun sep 30 14:23:30 CEST 2002 +Copyright (C) 2008 Gael Guennebaud +Copyright (C) EDF R&D, lun sep 30 14:23:31 CEST 2002 +Copyright (C) 2008-2010 Gael Guennebaud +Copyright (C) 2008-2016 Gael Guennebaud +Copyright (C) 2009 Mark Borgerding mark a borgerding net +Copyright (C) 2008-2009 Gael Guennebaud +Copyright (C) 2013 Desire Nuentsa +Copyright (C) 2013 Gael Guennebaud +Copyright (C) 2011 Gael Guennebaud +Copyright (C) 2012 Desire NUENTSA WAKAM +Copyright (C) 2009 Benoit Jacob +Copyright (C) 2009 Gael Guennebaud +Copyright (C) 2006-2010 Benoit Jacob +Copyright (C) 2006-2008 Benoit Jacob +Copyright (C) EDF R&D, lun sep 30 14:23:28 CEST 2002 +Copyright (C) 2010 Manuel Yguel +Copyright (C) 2009 Claire Maurice +Copyright (C) 2010,2012 Jitse Niesen +Copyright (c) 2011, Intel Corporation. All rights reserved. +Copyright (C) 2012-2016 Gael Guennebaud +Copyright (C) 2016 Tobias Wood +Copyright (C) 2010 Jitse Niesen +Copyright (C) 2012 Alexey Korepanov +Copyright (C) 2010 Vincent Lejeune +Copyright (C) 2010 Gael Guennebaud +Copyright (C) 2010 Benoit Jacob +Copyright (C) 2017 Gael Guennebaud +Copyright (C) 2009-2010 Gael Guennebaud +Copyright (C) 2008 Benoit Jacob +Copyright (C) 2009 Mathieu Gautier +Copyright (C) 2010 Hauke Heibel +Copyright (C) 2009 Hauke Heibel +Copyright (C) 2008-2015 Gael Guennebaud +Copyright (C) EDF R&D, mar déc 3 18:59:36 CET 2002 +Copyright (C) EDF R&D, lun sep 30 14:23:17 CEST 2002 +Copyright (C) EDF R&D, mar déc 3 18:59:35 CET 2002 +Copyright (C) 2016 Konstantinos Margaritis +Copyright (C) 2007 Julien Pommier +Copyright (C) 2008-2011 Gael Guennebaud +Copyright (C) 2009 Keir Mierle +Copyright (C) 2011 Timothy E. Holy +Copyright (C) 2009 Hauke Heibel +Copyright (C) 2012 Desire Nuentsa +Copyright (C) 2014 Gael Guennebaud +Copyright (C) 2015 Tal Hadad +@copyright (c) 2009-2014 The University of Tennessee and The University of Tennessee Research Foundation. +@copyright (c) 2012-2016 Inria. All rights reserved. +@copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved. +Copyright 2007-2009 Kitware, Inc. +Copyright 2012-2013 Inria +Copyright 2012-2013 Emmanuel Agullo +Copyright 2012-2013 Mathieu Faverge +Copyright 2012 Cedric Castagnede +Copyright 2013-2016 Florent Pruvost +Copyright 2016 Codeplay Software Ltd. +Copyright (c) 2006, 2007 Montel Laurent, +Copyright (c) 2008, 2009 Gael Guennebaud, +Copyright (c) 2009 Boudewijn Rempt +@copyright (c) 2012-2014 Inria. All rights reserved. +Copyright 2013 Florent Pruvost +Copyright (c) 2010 Jitse Niesen, +Copyright (C) 2009 Benjamin Schindler +Copyright (C) 2016 Pedro Gonnet (pedro.gonnet@gmail.com) +Copyright (C) 2016 Benoit Steiner (benoit.steiner.goog@gmail.com) +Copyright (C) 2009 Thomas Capricelli +Copyright (C) 2012-2013 Desire Nuentsa +Copyright (C) 2012-2014 Gael Guennebaud +Copyright Jorge More - Argonne National Laboratory +Copyright Burt Garbow - Argonne National Laboratory +Copyright Ken Hillstrom - Argonne National Laboratory +Copyright (C) 2009 Ilya Baran +Copyright (c) 2010, Intel Corp. +Copyright (C) 2009-2010 Benoit Jacob +Copyright (C) 2013-2016 Gael Guennebaud +Copyright (C) 2013 Gauthier Brun +Copyright (C) 2013 Nicolas Carre +Copyright (C) 2013 Jean Ceccato +Copyright (C) 2013 Pierre Zoppitelli +Copyright (C) 2013 Jitse Niesen +Copyright (C) 2014-2017 Gael Guennebaud +Copyright (C) 2013-2014 Gael Guennebaud +Copyright (C) 2011-2014 Gael Guennebaud +Copyright (C) 2012 Désiré Nuentsa-Wakam +Copyright (C) 2015 Gael Guennebaud +Copyright (C) 2012 Gael Guennebaud +Copyright (c) 1994 by Xerox Corporation. All rights reserved. +Copyright (C) 2001 Intel Corporation +Copyright (c) 2001 Intel Corporation. +Copyright (C) 2009 Gael Guennebaud +Copyright (C) 2013 Christoph Hertzberg +Copyright (C) 2015 Eugene Brevdo +Copyright (C) 2016 +Mehdi Goli Codeplay Software Ltd. +Ralph Potter Codeplay Software Ltd. +Luke Iwanski Codeplay Software Ltd. +Copyright (C) 2014 Jianwei Cui +Copyright (C) 2015 Vijay Vasudevan +Copyright (C) 2015 +Mehdi Goli Codeplay Software Ltd. +Ralph Potter Codeplay Software Ltd. +Luke Iwanski Codeplay Software Ltd. +Copyright (C) 2014 Navdeep Jaitly +Copyright (C) 2011 Gael Guennebaud +Copyright (C) 2012 desire Nuentsa +Copyright (C) 2012 Kolja Brix +Copyright (C) 2011 Kolja Brix +Copyright (C) 2011 Andreas Platen +Copyright (C) 2012 Chen-Pang He +Copyright (C) 2009 Jitse Niesen +Copyright (C) 2009-2011 Jitse Niesen +Copyright (C) 2012, 2013 Chen-Pang He +Copyright (C) 2011 Jitse Niesen +Copyright (C) 2012 Giacomo Po +Copyright (C) 2008-2010 Gael Guennebaud +Copyright (C) 2016 Gael Guennebaud +Copyright (C) 2010-2011 Hauke Heibel +Copyright (C) 2012 David Harmon +Copyright (C) 2007-2009 Benoit Jacob +Copyright (C) 2007-2010 Benoit Jacob +Copyright (C) 2008-2009 Benoit Jacob +Copyright (C) 2009 Kenneth Riddile +Copyright (C) 2010 Thomas Capricelli +Copyright (C) 2013 Pavel Holoborodko +Copyright (C) EDF R&D, lun sep 30 14:23:16 CEST 2002 +Copyright (C) EDF R&D, mar déc 3 18:59:37 CET 2002 +Copyright (C) 2006-2009 Benoit Jacob +Copyright (C) 2008-2010 Benoit Jacob +Copyright (c) 2008-2015 Pavel Holoborodko +Copyright (C) 20010-2011 Hauke Heibel +Copyright (c) 2006, Montel Laurent, +Copyright (c) 2007, Allen Winter, +Copyright (c) 2007, Alexander Neundorf, +Copyright (C) 2008 Guillaume Saupin +Copyright (C) 2008-2009 Guillaume Saupin +Copyright (C) 2009 Guillaume Saupin +Copyright (C) 2010-2016 Konstantinos Margaritis +Copyright (C) 2008-2016 Konstantinos Margaritis +Copyright (C) 2014 Benoit Steiner (benoit.steiner.goog@gmail.com) +Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com) +Copyright (c) Fabian Giesen, 2016 +Copyright (C) 2010 Konstantinos Margaritis +Copyright (C) 2007 Michael Olbrich +Copyright (C) 2011 Benoit Jacob +Copyright (C) 2011-2012 Jitse Niesen +Copyright (C) 2016 Rasmus Munk Larsen (rmlarsen@google.com) +Copyright (C) 2008-2014 Gael Guennebaud +Copyright (C) 2010-2013 Hauke Heibel +Copyright (C) 2006-2008, 2010 Benoit Jacob +Copyright (C) 2010-2016 Gael Guennebaud +Copyright (C) 2009-2015 Gael Guennebaud +Copyright (C) 2009 Ricard Marxer +Copyright (C) 2009-2014 Gael Guennebaud +Copyright (C) 2010-2011 Gael Guennebaud +Copyright (C) 2009 Rohit Garg +Copyright (c) 2006, Timothy A. Davis. +Copyright (c) 1998-2003 by the University of Florida. +Copyright (C) 2012 Désiré Nuentsa-Wakam +Copyright (C) 2008-2012 Gael Guennebaud +LDL Copyright (c) 2005 by Timothy A. Davis. All Rights Reserved. +Copyright (C) 2010 Daniel Lowengrub +Copyright (C) EDF R&D, lun sep 30 14:23:20 CEST 2002 +Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002 +Copyright (C) 2009, 2010, 2013 Jitse Niesen +Copyright (C) 2011, 2013 Chen-Pang He +Copyright (C) 2009-2011, 2013 Jitse Niesen +Copyright (C) 2011, 2013 Jitse Niesen +Copyright (C) 2011 Chen-Pang He +Copyright (C) 2010, 2013 Jitse Niesen +Copyright (C) 2010-2014 Gael Guennebaud +Copyright (C) 2012 The Android Open Source Project +(C) Desire NUENTSA WAKAM, INRIA +Copyright (C) EDF R&D, lun sep 30 14:23:18 CEST 2002 +Copyright (C) 2012 Keir Mierle +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +Copyright (C) EDF R&D, lun sep 30 14:23:23 CEST 2002 +Copyright (C) EDF R&D, lun sep 30 14:23:24 CEST 2002 +Copyright (C) EDF R&D, lun sep 30 14:23:27 CEST 2002 +Copyright (C) 2007 Free Software Foundation, Inc. +Copyright (C) 1991, 1999 Free Software Foundation, Inc. +Copyright (C) 2015 Benoit Jacob +Geometric Tools, LLC Copyright (c) 1998-2010 +Copyright (C) EDF R&D, lun sep 30 14:23:15 CEST 2002 +Copyright (C) 2002-2007 Yves Renard +Copyright (C) 2012, 2014 Kolja Brix +Copyright (C) 1997-2001 Andrew Lumsdaine Lie-Quan Lee +Copyright (C) 2012 Desire NUENTSA WAKAM +Copyright (C) 2013 Hauke Heibel +Copyright (C) 2010-2011 Jitse Niesen +Intel Copyright (C) .... +Copyright (C) 2010-2017 Gael Guennebaud +Copyright (C) 20013 Gael Guennebaud +Copyright (C) 2008 Daniel Gomez Ferro +Copyright (C) 2013 Désiré Nuentsa-Wakam +Copyright (C) 2011-2015 Gael Guennebaud +Copyright (C) 20015 Gael Guennebaud +Copyright (C) 2014-2015 Gael Guennebaud + +Copyright 2019 The TensorFlow Authors. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +From PyTorch: + +Copyright (c) 2016- Facebook, Inc (Adam Paszke) +Copyright (c) 2014- Facebook, Inc (Soumith Chintala) +Copyright (c) 2011-2014 Idiap Research Institute (Ronan Collobert) +Copyright (c) 2012-2014 Deepmind Technologies (Koray Kavukcuoglu) +Copyright (c) 2011-2012 NEC Laboratories America (Koray Kavukcuoglu) +Copyright (c) 2011-2013 NYU (Clement Farabet) +Copyright (c) 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston) +Copyright (c) 2006 Idiap Research Institute (Samy Bengio) +Copyright (c) 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz) + +From Caffe2: + +Copyright (c) 2016-present, Facebook Inc. All rights reserved. + +All contributions by Facebook: +Copyright (c) 2016 Facebook Inc. + +All contributions by Google: +Copyright (c) 2015 Google Inc. +All rights reserved. + +All contributions by Yangqing Jia: +Copyright (c) 2015 Yangqing Jia +All rights reserved. + +All contributions by Kakao Brain: +Copyright 2019-2020 Kakao Brain + +All contributions from Caffe: +Copyright(c) 2013, 2014, 2015, the respective contributors +All rights reserved. + +All other contributions: +Copyright(c) 2015, 2016 the respective contributors +All rights reserved. + +Caffe2 uses a copyright model similar to Caffe: each contributor holds +copyright over their contributions to Caffe2. The project versioning records +all such contribution and copyright details. If a contributor wants to further +mark their specific copyright on a particular contribution, they should +indicate their copyright solely in the commit message of the change when it is +committed. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the names of Facebook, Deepmind Technologies, NYU, NEC Laboratories America + and IDIAP Research Institute nor the names of its contributors may be + used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + +Software: crnn e78bb7d +Copyright notice: +Copyright (c) 2017 Jieru Mei meijieru@gmail.com + +License: MIT License (MIT) +MIT License +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + + +Software: pytorch-deeplab-xception b7cbf5a +Copyright notice: +Copyright (c) 2018 Pyjcsx + +License: MIT License (MIT) +MIT License +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + + +Software: version 1.0.1 +Copyright notice: +Copyright (c) Soumith Chintala 2016 + +License: BSD 3-Clause License +BSD 3-Clause License +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +Software: EfficientNet-PyTorch 1.0 +Copyright notice: +Copyright Copyright [yyyy] [name of copyright owner] + +License: Apache License + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + +Software: PSENet cec7e6 +Copyright notice: +Copyright [yyyy] [name of copyright owner] + +License: Apache License + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + +Software: examples v1.22.1 +Copyright notice: +Copyright (c) 2017, All rights reserved. + +License: BSD 3-Clause License +BSD 3-Clause License + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +Software: pytorch-image-models 0.1-regnet +Copyright notice: +Copyright Copyright [yyyy] [name of copyright owner] + +License: Apache License + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + +Software: DeepCTR-Torch 0.2.1 +Copyright notice: +Copyright Copyright [yyyy] [name of copyright owner] + +License: Apache License +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +Software:Wizyoung 8776cf7 + +The MIT License (MIT) + +Copyright (c) 2020 Wizyoung + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +Software:PyTorch +BSD 3-Clause License + +Copyright (c) Soumith Chintala 2016, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Software:tpu r1.15 +Software:tensorflow master +Software:NVIDIA master +Software:Tensorflow-densenet +Software:Training v0.7 results +Software:AWS + +Copyright 2017 The TensorFlow Authors. All rights reserved. +Copyright 2016 The TensorFlow Authors. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +## Some of TensorFlow's code is derived from Caffe, which is subject to the following copyright notice: + +COPYRIGHT + +All contributions by the University of California: + +Copyright (c) 2014, The Regents of the University of California (Regents) +All rights reserved. + +All other contributions: + +Copyright (c) 2014, the respective contributors +All rights reserved. + +Caffe uses a shared copyright model: each contributor holds copyright over +their contributions to Caffe. The project versioning records all such +contribution and copyright details. If a contributor wants to further mark +their specific copyright on a particular contribution, they should indicate +their copyright solely in the commit message of the change when it is +committed. + +LICENSE + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +CONTRIBUTION AGREEMENT + +By contributing to the BVLC/caffe repository through pull-request, comment, +or otherwise, the contributor releases their content to the license and copyright terms herein. \ No newline at end of file